-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathdeepcode.py
More file actions
executable file
·262 lines (229 loc) · 10.3 KB
/
Copy pathdeepcode.py
File metadata and controls
executable file
·262 lines (229 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/env python3
"""DeepCode command-line entry point."""
import os
import subprocess
import sys
from pathlib import Path
# Console entrypoints generated by setuptools run from the environment's
# Scripts/bin directory, so imports like ``from core...`` are not guaranteed
# to see this source checkout even when the project is installed editable.
# Bootstrap the repository root ahead of everything else on sys.path.
PROJECT_ROOT = str(Path(__file__).resolve().parent)
if PROJECT_ROOT in sys.path:
sys.path.remove(PROJECT_ROOT)
sys.path.insert(0, PROJECT_ROOT)
# The top-level package name ``cli`` is generic and is shadowed in some
# environments by a third-party ``cli`` distribution in site-packages. If one
# was already imported (cached in sys.modules) before us, ``cli.tui`` /
# ``cli.mcp_server`` would resolve into it and fail. Evict any ``cli`` that does
# not live under this checkout so our submodules import from the repo.
_cached_cli = sys.modules.get("cli")
if _cached_cli is not None and not (
getattr(_cached_cli, "__file__", "") or ""
).startswith(PROJECT_ROOT):
for _name in [n for n in list(sys.modules) if n == "cli" or n.startswith("cli.")]:
del sys.modules[_name]
from core.platform_compat import (
configure_utf8_stdio,
subprocess_env,
)
from core.version import __version__
configure_utf8_stdio()
def print_banner():
"""Display startup banner."""
width = 62
lines = [
"",
" DeepCode — Open Agentic Coding",
"",
" Agentic code generation with multi-agent LLM systems",
"",
]
top = "╔" + "═" * width + "╗"
bottom = "╚" + "═" * width + "╝"
body = "\n".join("║" + ln.ljust(width)[:width] + "║" for ln in lines)
print("\n" + top + "\n" + body + "\n" + bottom + "\n")
def launch_paper_test(paper_name: str, fast_mode: bool = False):
"""Launch paper testing mode"""
try:
print("\nLaunching Paper Test Mode")
print(f"Paper: {paper_name}")
print(f"Fast mode: {'enabled' if fast_mode else 'disabled'}")
print("=" * 60)
# Run the test setup
setup_cmd = [sys.executable, "test_paper.py", paper_name]
if fast_mode:
setup_cmd.append("--fast")
result = subprocess.run(setup_cmd, check=True, env=subprocess_env())
if result.returncode == 0:
print("\n[ok] Paper test setup completed successfully!")
print("Files are ready in deepcode_lab/papers/")
print("\nNext steps:")
print(" 1. Install MCP dependencies: pip install -r requirements.txt")
print(
f" 2. Run full pipeline: python -m workflows.paper_test_engine --paper {paper_name}"
+ (" --fast" if fast_mode else "")
)
except subprocess.CalledProcessError as e:
print(f"\n[x] Paper test setup failed: {e}")
sys.exit(1)
except Exception as e: # noqa: BLE001 - top-level CLI error boundary
print(f"\n[x] Unexpected error: {e}")
sys.exit(1)
def main():
"""Main function"""
# Parse command line arguments
if len(sys.argv) > 1:
if sys.argv[1] in {"--version", "-V"}:
print(f"DeepCode {__version__}")
return
if sys.argv[1] == "test" and len(sys.argv) >= 3:
# Paper testing mode: python deepcode.py test rice [--fast]
paper_name = sys.argv[2]
fast_mode = "--fast" in sys.argv or "-f" in sys.argv
print_banner()
launch_paper_test(paper_name, fast_mode)
return
elif sys.argv[1] == "init":
# One-time setup: create the user-level config base (~/.deepcode) so
# `deepcode` runs in any directory. Cross-platform (Win/mac/Linux).
from cli.init_config import run as init_run
raise SystemExit(init_run(sys.argv[2:]))
elif sys.argv[1] == "mcp":
# Expose DeepCode as an MCP server over stdio (no banner — stdout is
# the JSON-RPC channel).
from cli.mcp_server import main as mcp_main
raise SystemExit(mcp_main(sys.argv[2:]))
elif sys.argv[1] in {"skill", "skills"}:
from cli.skill_cli import run as skill_run
raise SystemExit(skill_run(sys.argv[2:]))
elif sys.argv[1] in {"provider", "providers"}:
from cli.provider_cli import run as provider_run
raise SystemExit(provider_run(sys.argv[2:]))
elif sys.argv[1] in {"session", "sessions"}:
from cli.session_cli import run as session_run
raise SystemExit(session_run(sys.argv[2:]))
elif sys.argv[1] in {"chat", "tui"}:
from cli.tui.app import main as tui_main
raise SystemExit(tui_main(sys.argv[2:]))
elif sys.argv[1] == "exec":
from cli.exec_cli import main as exec_main
raise SystemExit(exec_main(sys.argv[2:]))
elif sys.argv[1] == "loop":
from cli.loop_cli import main as loop_main
raise SystemExit(loop_main(sys.argv[2:]))
elif sys.argv[1] == "schedule":
from cli.schedule_cli import main as schedule_main
raise SystemExit(schedule_main(sys.argv[2:]))
elif sys.argv[1] in {"automation", "automations"}:
from cli.automation_cli import run as automation_run
raise SystemExit(automation_run(sys.argv[2:]))
elif sys.argv[1] in ["--help", "-h", "help"]:
print_banner()
def row(cmd, desc):
return f" {cmd:<48}{desc}"
print(
"\n".join(
[
"",
"Usage:",
row("deepcode", "Interactive coding agent (TUI, default)"),
row(
"deepcode init",
"Set up ~/.deepcode so deepcode runs anywhere",
),
row("deepcode test <paper>", "Test paper reproduction"),
row("deepcode test <paper> --fast", "Test paper (fast mode)"),
row("deepcode mcp", "Expose DeepCode as an MCP server (stdio)"),
row(
"deepcode skill <command>",
"List, inspect, import, and manage Agent Skills",
),
row(
"deepcode provider <command>",
"Configure LLM connections and models",
),
row(
"deepcode session delete <id>",
"Permanently delete a conversation Session",
),
row(
"deepcode exec <task>",
"Run one headless coding task",
),
row(
"deepcode loop <goal>",
"Run a durable Goal on the shared Turn runtime",
),
row(
"deepcode loop --resume <session-id>",
"Continue the same durable Goal and Session",
),
row(
"deepcode schedule ...",
"Run loop or memory maintenance on a schedule",
),
row(
"deepcode automation <command>",
"Manage durable Agent Automations",
),
"",
" More agent entry points:",
row(
'python -m cli.exec_cli "<task>" -w .',
"Headless one-shot run",
),
row(
'python -m cli.loop_cli "<goal>"',
"Headless durable Goal",
),
row(
"python -m cli.loop_cli --resume <session-id>",
"Resume a durable Goal without replacing history",
),
row(
"python -m cli.schedule_cli ...",
"Scheduled / keepalive runs",
),
"",
"Examples:",
row("deepcode", "Drop into the interactive agent"),
row("deepcode test rice", "Test RICE paper reproduction"),
row("deepcode test rice --fast", "Test RICE paper (fast mode)"),
"",
"Available papers:",
]
)
)
# List available papers
papers_dir = "papers"
if os.path.exists(papers_dir):
for item in os.listdir(papers_dir):
item_path = os.path.join(papers_dir, item)
if os.path.isdir(item_path):
paper_md = os.path.join(item_path, "paper.md")
addendum_md = os.path.join(item_path, "addendum.md")
status = "ok" if os.path.exists(paper_md) else "--"
addendum = " (+addendum)" if os.path.exists(addendum_md) else ""
print(f" [{status}] {item}{addendum}")
print(
"\n Legend: [ok] = paper.md exists, (+addendum) = addendum.md exists"
)
return
elif sys.argv[1].startswith("-"):
# Agent flags belong to the default interactive surface, so
# `deepcode -c team -m model` behaves exactly like
# `python -m cli.tui -c team -m model`.
from cli.tui.app import main as tui_main
raise SystemExit(tui_main(sys.argv[1:]))
else:
# Unknown argument — show help hint
print(f"Unknown option: {sys.argv[1]}")
print("Run 'deepcode --help' for usage information.")
sys.exit(1)
else:
# Default (no arguments) -> interactive coding agent (multi-turn TUI).
from cli.tui.app import main as tui_main
raise SystemExit(tui_main())
if __name__ == "__main__":
main()