MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / main

Function main

src/cli.py:35–165  ·  view source on GitHub ↗

CLI main entry point.

()

Source from the content-addressed store, hash-verified

33
34
35def main():
36 """CLI main entry point."""
37 # WI-0.1 (ch17 Phase 0): instrument cold-start phases. Env-gated by
38 # ``CLAUDE_CODE_PROFILE_STARTUP``; a no-op import + no-op call when
39 # disabled (~ns overhead). On exit the profiler writes a Markdown
40 # report to ``$CLAUDE_CONFIG_DIR/startup-perf/{session_id}.txt``.
41 from src.utils.startup_profiler import profile_checkpoint
42 profile_checkpoint("cli_main_entry")
43
44 import os
45 if os.environ.get("CLAWCODEX_DEBUG", "").lower() in ("1", "true", "yes"):
46 import logging
47 logging.basicConfig(
48 level=logging.WARNING,
49 format="%(asctime)s %(name)s %(message)s",
50 stream=sys.stderr,
51 )
52
53 if len(sys.argv) == 2 and sys.argv[1] in ['--version', '-v', '-V']:
54 from src import __version__
55 print(f"claw-codex version {__version__} (Python)")
56 return 0
57
58 # Subcommands are matched BEFORE the main parser to avoid argparse treating
59 # a free-form prompt (e.g. ``clawcodex -p "hello"``) as an unknown
60 # subcommand.
61 #
62 # WI-4.3: ``mcp``, ``daemon``, and ``doctor`` are fast-path subcommands
63 # — they get a thin handler that imports only what it needs, skipping
64 # the TUI/REPL/full-tool-registry load. Mirrors TS ``main.tsx``'s
65 # specialized-subcommand early-returns.
66 #
67 # Sieve looks at ``argv[0]`` ONLY so flag values that happen to equal a
68 # subcommand name don't mis-route (e.g. ``clawcodex --model mcp`` or
69 # ``clawcodex -p "doctor"``). The TS reference also positions
70 # specialized subcommands at argv[0]; global flags don't precede them.
71 argv = sys.argv[1:]
72 if argv and not argv[0].startswith('-'):
73 token = argv[0]
74 rest = argv[1:]
75 if token == 'login':
76 return handle_login()
77 if token == 'config':
78 return show_config()
79 if token == 'mcp':
80 from src.entrypoints.mcp import run_mcp_subcommand
81 return run_mcp_subcommand(rest)
82 if token == 'daemon':
83 from src.entrypoints.daemon import run_daemon_subcommand
84 return run_daemon_subcommand(rest)
85 if token == 'doctor':
86 from src.entrypoints.doctor import run_doctor
87 return run_doctor()
88 if token == 'agent-server':
89 from src.entrypoints.agent_server_cli import run_agent_server_subcommand
90 return run_agent_server_subcommand(rest)
91 if token == 'tui':
92 return _run_tui_subcommand(rest)

Calls 15

profile_checkpointFunction · 0.90
run_mcp_subcommandFunction · 0.90
run_daemon_subcommandFunction · 0.90
run_doctorFunction · 0.90
run_pre_actionFunction · 0.90
launch_ink_tuiFunction · 0.90
handle_loginFunction · 0.85
show_configFunction · 0.85
_run_tui_subcommandFunction · 0.85
_build_parserFunction · 0.85