robert-github-agent 0.1.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robert_agent/__init__.py +1 -0
- robert_agent/acceptance.py +394 -0
- robert_agent/acceptance_suite.py +287 -0
- robert_agent/audit_result.py +501 -0
- robert_agent/authorize.py +117 -0
- robert_agent/board.py +538 -0
- robert_agent/chat_status.py +338 -0
- robert_agent/cli/__init__.py +1 -0
- robert_agent/cli/exit_codes.py +5 -0
- robert_agent/cli/main.py +535 -0
- robert_agent/cli/output.py +20 -0
- robert_agent/common.py +6 -0
- robert_agent/controlled_e2e_acceptance.py +394 -0
- robert_agent/daemon.py +607 -0
- robert_agent/daemon_state.py +319 -0
- robert_agent/diagnostics.py +119 -0
- robert_agent/discover.py +775 -0
- robert_agent/dispatch.py +217 -0
- robert_agent/doctor.py +94 -0
- robert_agent/github_api.py +12 -0
- robert_agent/init_config.py +126 -0
- robert_agent/integrations/__init__.py +1 -0
- robert_agent/integrations/openclaw.py +285 -0
- robert_agent/live_discovery_acceptance.py +70 -0
- robert_agent/live_worker_acceptance.py +363 -0
- robert_agent/live_worktree_acceptance.py +344 -0
- robert_agent/loop_engine.py +285 -0
- robert_agent/memory_curator.py +105 -0
- robert_agent/migrate.py +157 -0
- robert_agent/notify.py +74 -0
- robert_agent/paths.py +16 -0
- robert_agent/production_write_canary.py +254 -0
- robert_agent/project_memory.py +503 -0
- robert_agent/publish.py +743 -0
- robert_agent/publish_dedupe_acceptance.py +270 -0
- robert_agent/redaction.py +41 -0
- robert_agent/render_prompt.py +544 -0
- robert_agent/resource_files.py +8 -0
- robert_agent/resources/__init__.py +1 -0
- robert_agent/resources/acceptance-matrix.md +120 -0
- robert_agent/resources/classifier.md +19 -0
- robert_agent/resources/command-matrix.md +38 -0
- robert_agent/resources/config.example.yml +20 -0
- robert_agent/resources/db/migrations/001_legacy_dd_to_robert.sql +14 -0
- robert_agent/resources/db/schema.sql +479 -0
- robert_agent/resources/failure-modes.md +36 -0
- robert_agent/resources/fixtures/actor-permission.json +1 -0
- robert_agent/resources/fixtures/discovery.json +1 -0
- robert_agent/resources/fixtures/redaction.json +1 -0
- robert_agent/resources/fixtures/review-followup.json +1 -0
- robert_agent/resources/fixtures/worker-results.json +1 -0
- robert_agent/resources/fixtures/workstreams.json +1 -0
- robert_agent/resources/github-events.md +77 -0
- robert_agent/resources/kanban-control.md +165 -0
- robert_agent/resources/redaction.md +29 -0
- robert_agent/resources/result-contract.md +56 -0
- robert_agent/resources/routes.yml +82 -0
- robert_agent/resources/schemas/config.schema.json +123 -0
- robert_agent/resources/schemas/event.schema.json +18 -0
- robert_agent/resources/schemas/result.schema.json +99 -0
- robert_agent/resources/schemas/route.schema.json +23 -0
- robert_agent/resources/schemas/snapshot.schema.json +17 -0
- robert_agent/resources/schemas/task.schema.json +15 -0
- robert_agent/resources/trust-model.md +16 -0
- robert_agent/resources/worker-prompt.md +121 -0
- robert_agent/resources/worker-protocol.md +47 -0
- robert_agent/resources/workflow.yml +50 -0
- robert_agent/resources/workstream-model.md +17 -0
- robert_agent/route.py +232 -0
- robert_agent/route_config.py +64 -0
- robert_agent/run_once.py +5375 -0
- robert_agent/runtime_knowledge.py +392 -0
- robert_agent/service.py +161 -0
- robert_agent/skills.py +28 -0
- robert_agent/status.py +1051 -0
- robert_agent/storage.py +376 -0
- robert_agent/summarize.py +100 -0
- robert_agent/supervise.py +72 -0
- robert_agent/usage.py +192 -0
- robert_agent/validate_config.py +616 -0
- robert_agent/wakeup.py +261 -0
- robert_agent/web.py +2893 -0
- robert_agent/web_assets/board.css +255 -0
- robert_agent/web_assets/board.html +165 -0
- robert_agent/web_assets/board.js +660 -0
- robert_agent/web_assets/github-shell.css +122 -0
- robert_agent/web_assets/index.html +103 -0
- robert_agent/web_assets/operations.css +168 -0
- robert_agent/web_assets/workbench.css +131 -0
- robert_agent/web_assets/workbench.js +581 -0
- robert_agent/work_items.py +1016 -0
- robert_agent/workbench.py +701 -0
- robert_agent/worker/__init__.py +1 -0
- robert_agent/worker/heartbeat.py +190 -0
- robert_agent/worker/result.py +321 -0
- robert_agent/worker/snapshot.py +98 -0
- robert_agent/worker_adapters/__init__.py +138 -0
- robert_agent/worker_adapters/cbc.py +68 -0
- robert_agent/worker_adapters/codex.py +56 -0
- robert_agent/worker_adapters/command.py +33 -0
- robert_agent/worker_adapters/tcodex.py +56 -0
- robert_agent/worker_heartbeat.py +6 -0
- robert_agent/worker_result.py +6 -0
- robert_agent/worker_snapshot.py +6 -0
- robert_agent/workstream.py +55 -0
- robert_agent/worktree.py +297 -0
- robert_github_agent-0.1.0b1.dist-info/METADATA +217 -0
- robert_github_agent-0.1.0b1.dist-info/RECORD +111 -0
- robert_github_agent-0.1.0b1.dist-info/WHEEL +4 -0
- robert_github_agent-0.1.0b1.dist-info/entry_points.txt +2 -0
- robert_github_agent-0.1.0b1.dist-info/licenses/LICENSE +201 -0
robert_agent/cli/main.py
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from collections.abc import Sequence
|
|
3
|
+
from contextlib import redirect_stdout
|
|
4
|
+
import io
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import shutil
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from robert_agent import __version__
|
|
11
|
+
from robert_agent import daemon
|
|
12
|
+
from robert_agent import diagnostics
|
|
13
|
+
from robert_agent import migrate
|
|
14
|
+
from robert_agent import run_once
|
|
15
|
+
from robert_agent import status
|
|
16
|
+
from robert_agent import service
|
|
17
|
+
from robert_agent import validate_config
|
|
18
|
+
from robert_agent import web
|
|
19
|
+
from robert_agent.cli import exit_codes
|
|
20
|
+
from robert_agent.cli.output import emit_result
|
|
21
|
+
from robert_agent.doctor import doctor
|
|
22
|
+
from robert_agent.init_config import init_config
|
|
23
|
+
from robert_agent.integrations import openclaw
|
|
24
|
+
from robert_agent.paths import default_config_path, default_data_dir
|
|
25
|
+
from robert_agent.resource_files import resource
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _add_config_argument(parser: argparse.ArgumentParser) -> None:
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"--config",
|
|
31
|
+
default=str(default_config_path()),
|
|
32
|
+
help="Robert configuration path.",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _add_output_argument(parser: argparse.ArgumentParser) -> None:
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--output",
|
|
39
|
+
choices=["text", "json"],
|
|
40
|
+
default="text",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
45
|
+
parser = argparse.ArgumentParser(
|
|
46
|
+
prog="robert",
|
|
47
|
+
description="Robert — Your Repo Teammate",
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
"--version",
|
|
51
|
+
action="version",
|
|
52
|
+
version=f"robert {__version__}",
|
|
53
|
+
)
|
|
54
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
55
|
+
|
|
56
|
+
init_parser = subparsers.add_parser(
|
|
57
|
+
"init",
|
|
58
|
+
help="Create a Robert configuration.",
|
|
59
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
60
|
+
epilog=(
|
|
61
|
+
"Example:\n"
|
|
62
|
+
" robert init --non-interactive "
|
|
63
|
+
"--repo example/backend --repo-path /srv/repos/backend "
|
|
64
|
+
"--worker codex --github-account robert-bot "
|
|
65
|
+
"--trusted-actor maintainer"
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
_add_config_argument(init_parser)
|
|
69
|
+
init_parser.add_argument("--non-interactive", action="store_true")
|
|
70
|
+
init_parser.add_argument("--repo")
|
|
71
|
+
init_parser.add_argument("--repo-path")
|
|
72
|
+
init_parser.add_argument("--worker")
|
|
73
|
+
init_parser.add_argument("--github-account")
|
|
74
|
+
init_parser.add_argument("--trusted-actor")
|
|
75
|
+
init_parser.add_argument("--force", action="store_true")
|
|
76
|
+
_add_output_argument(init_parser)
|
|
77
|
+
|
|
78
|
+
doctor_parser = subparsers.add_parser(
|
|
79
|
+
"doctor",
|
|
80
|
+
help="Validate runtime readiness.",
|
|
81
|
+
)
|
|
82
|
+
_add_config_argument(doctor_parser)
|
|
83
|
+
doctor_parser.add_argument("--skip-external", action="store_true")
|
|
84
|
+
_add_output_argument(doctor_parser)
|
|
85
|
+
|
|
86
|
+
status_parser = subparsers.add_parser(
|
|
87
|
+
"status",
|
|
88
|
+
help="Show control-plane status.",
|
|
89
|
+
)
|
|
90
|
+
_add_config_argument(status_parser)
|
|
91
|
+
_add_output_argument(status_parser)
|
|
92
|
+
|
|
93
|
+
run_parser = subparsers.add_parser("run", help="Run or inspect cycles.")
|
|
94
|
+
run_subparsers = run_parser.add_subparsers(
|
|
95
|
+
dest="run_command",
|
|
96
|
+
required=True,
|
|
97
|
+
)
|
|
98
|
+
run_once_parser = run_subparsers.add_parser(
|
|
99
|
+
"once",
|
|
100
|
+
help="Execute one bounded Robert cycle.",
|
|
101
|
+
)
|
|
102
|
+
_add_config_argument(run_once_parser)
|
|
103
|
+
run_once_parser.add_argument("--dry-run", action="store_true")
|
|
104
|
+
run_once_parser.add_argument("--skip-external", action="store_true")
|
|
105
|
+
run_once_parser.add_argument("--skip-publish", action="store_true")
|
|
106
|
+
run_show_parser = run_subparsers.add_parser(
|
|
107
|
+
"show",
|
|
108
|
+
help="Show one recorded run.",
|
|
109
|
+
)
|
|
110
|
+
_add_config_argument(run_show_parser)
|
|
111
|
+
_add_output_argument(run_show_parser)
|
|
112
|
+
run_show_parser.add_argument("run_id")
|
|
113
|
+
|
|
114
|
+
task_parser = subparsers.add_parser("task", help="Inspect tasks.")
|
|
115
|
+
task_show_parser = task_parser.add_subparsers(
|
|
116
|
+
dest="task_command",
|
|
117
|
+
required=True,
|
|
118
|
+
).add_parser("show")
|
|
119
|
+
_add_config_argument(task_show_parser)
|
|
120
|
+
_add_output_argument(task_show_parser)
|
|
121
|
+
task_show_parser.add_argument("task_id")
|
|
122
|
+
|
|
123
|
+
artifact_parser = subparsers.add_parser(
|
|
124
|
+
"artifact",
|
|
125
|
+
help="Inspect registered artifacts.",
|
|
126
|
+
)
|
|
127
|
+
artifact_show_parser = artifact_parser.add_subparsers(
|
|
128
|
+
dest="artifact_command",
|
|
129
|
+
required=True,
|
|
130
|
+
).add_parser("show")
|
|
131
|
+
_add_config_argument(artifact_show_parser)
|
|
132
|
+
_add_output_argument(artifact_show_parser)
|
|
133
|
+
artifact_show_parser.add_argument("task_id")
|
|
134
|
+
artifact_show_parser.add_argument("artifact_type")
|
|
135
|
+
|
|
136
|
+
config_parser = subparsers.add_parser(
|
|
137
|
+
"config",
|
|
138
|
+
help="Inspect configuration.",
|
|
139
|
+
)
|
|
140
|
+
config_subparsers = config_parser.add_subparsers(
|
|
141
|
+
dest="config_command",
|
|
142
|
+
required=True,
|
|
143
|
+
)
|
|
144
|
+
for name in ["validate", "show", "path"]:
|
|
145
|
+
command_parser = config_subparsers.add_parser(name)
|
|
146
|
+
_add_config_argument(command_parser)
|
|
147
|
+
_add_output_argument(command_parser)
|
|
148
|
+
|
|
149
|
+
daemon_parser = subparsers.add_parser("daemon", help="Run the daemon.")
|
|
150
|
+
daemon_run_parser = daemon_parser.add_subparsers(
|
|
151
|
+
dest="daemon_command",
|
|
152
|
+
required=True,
|
|
153
|
+
).add_parser("run")
|
|
154
|
+
_add_config_argument(daemon_run_parser)
|
|
155
|
+
daemon_run_parser.add_argument("--dry-run", action="store_true")
|
|
156
|
+
daemon_run_parser.add_argument("--once", action="store_true")
|
|
157
|
+
|
|
158
|
+
migrate_parser = subparsers.add_parser(
|
|
159
|
+
"migrate",
|
|
160
|
+
help="Migrate legacy Robert state.",
|
|
161
|
+
)
|
|
162
|
+
migrate_command = migrate_parser.add_subparsers(
|
|
163
|
+
dest="migrate_command",
|
|
164
|
+
required=True,
|
|
165
|
+
).add_parser("dd-github-agent")
|
|
166
|
+
migrate_command.add_argument(
|
|
167
|
+
"--source",
|
|
168
|
+
default="~/.agents/data/dd-github-agent",
|
|
169
|
+
)
|
|
170
|
+
migrate_command.add_argument(
|
|
171
|
+
"--target",
|
|
172
|
+
default=str(default_data_dir()),
|
|
173
|
+
)
|
|
174
|
+
migrate_command.add_argument("--dry-run", action="store_true")
|
|
175
|
+
_add_output_argument(migrate_command)
|
|
176
|
+
|
|
177
|
+
service_parser = subparsers.add_parser(
|
|
178
|
+
"service",
|
|
179
|
+
help="Manage the Robert user service.",
|
|
180
|
+
)
|
|
181
|
+
service_subparsers = service_parser.add_subparsers(
|
|
182
|
+
dest="service_command",
|
|
183
|
+
required=True,
|
|
184
|
+
)
|
|
185
|
+
for name in [
|
|
186
|
+
"install",
|
|
187
|
+
"uninstall",
|
|
188
|
+
"start",
|
|
189
|
+
"stop",
|
|
190
|
+
"restart",
|
|
191
|
+
"status",
|
|
192
|
+
]:
|
|
193
|
+
command_parser = service_subparsers.add_parser(name)
|
|
194
|
+
command_parser.add_argument("--dry-run", action="store_true")
|
|
195
|
+
_add_output_argument(command_parser)
|
|
196
|
+
if name == "install":
|
|
197
|
+
_add_config_argument(command_parser)
|
|
198
|
+
|
|
199
|
+
diagnostics_parser = subparsers.add_parser(
|
|
200
|
+
"diagnostics",
|
|
201
|
+
help="Export safe diagnostics.",
|
|
202
|
+
)
|
|
203
|
+
diagnostics_export = diagnostics_parser.add_subparsers(
|
|
204
|
+
dest="diagnostics_command",
|
|
205
|
+
required=True,
|
|
206
|
+
).add_parser("export")
|
|
207
|
+
_add_config_argument(diagnostics_export)
|
|
208
|
+
diagnostics_export.add_argument(
|
|
209
|
+
"--output",
|
|
210
|
+
dest="output_path",
|
|
211
|
+
default="robert-diagnostics.zip",
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
web_parser = subparsers.add_parser(
|
|
215
|
+
"web",
|
|
216
|
+
help="Run the local Robert web UI.",
|
|
217
|
+
)
|
|
218
|
+
web_run = web_parser.add_subparsers(
|
|
219
|
+
dest="web_command",
|
|
220
|
+
required=True,
|
|
221
|
+
).add_parser("run")
|
|
222
|
+
_add_config_argument(web_run)
|
|
223
|
+
web_run.add_argument("--db")
|
|
224
|
+
web_run.add_argument("--host", default="127.0.0.1")
|
|
225
|
+
web_run.add_argument("--port", type=int, default=8765)
|
|
226
|
+
web_run.add_argument("--operator", default="local-operator")
|
|
227
|
+
web_run.add_argument("--writable", action="store_true")
|
|
228
|
+
web_run.add_argument("--allow-remote", action="store_true")
|
|
229
|
+
web_run.add_argument("--json", action="store_true")
|
|
230
|
+
|
|
231
|
+
openclaw_parser = subparsers.add_parser(
|
|
232
|
+
"openclaw",
|
|
233
|
+
help="Manage the optional OpenClaw integration.",
|
|
234
|
+
)
|
|
235
|
+
openclaw_subparsers = openclaw_parser.add_subparsers(
|
|
236
|
+
dest="openclaw_command",
|
|
237
|
+
required=True,
|
|
238
|
+
)
|
|
239
|
+
openclaw_install = openclaw_subparsers.add_parser("install")
|
|
240
|
+
openclaw_install.add_argument(
|
|
241
|
+
"--plugin-dir",
|
|
242
|
+
default=str(openclaw.DEFAULT_PLUGIN_DIR),
|
|
243
|
+
)
|
|
244
|
+
openclaw_install.add_argument("--dry-run", action="store_true")
|
|
245
|
+
openclaw_install.add_argument("--force", action="store_true")
|
|
246
|
+
openclaw_install.add_argument("--skip-restart", action="store_true")
|
|
247
|
+
_add_output_argument(openclaw_install)
|
|
248
|
+
for name in ["uninstall", "status"]:
|
|
249
|
+
command_parser = openclaw_subparsers.add_parser(name)
|
|
250
|
+
command_parser.add_argument("--dry-run", action="store_true")
|
|
251
|
+
_add_output_argument(command_parser)
|
|
252
|
+
|
|
253
|
+
return parser
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _validated_config(args):
|
|
257
|
+
result = validate_config.validate_config(
|
|
258
|
+
args.config,
|
|
259
|
+
skip_external=getattr(args, "skip_external", False),
|
|
260
|
+
)
|
|
261
|
+
if not result["ok"]:
|
|
262
|
+
raise ValueError(result["safe_error"])
|
|
263
|
+
return result
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _run_once_argv(args):
|
|
267
|
+
argv = [
|
|
268
|
+
"--config",
|
|
269
|
+
str(args.config),
|
|
270
|
+
"--workflow",
|
|
271
|
+
str(resource("workflow.yml")),
|
|
272
|
+
]
|
|
273
|
+
if args.dry_run:
|
|
274
|
+
argv.append("--dry-run")
|
|
275
|
+
if args.skip_external:
|
|
276
|
+
argv.append("--skip-external")
|
|
277
|
+
if args.skip_publish:
|
|
278
|
+
argv.append("--skip-publish")
|
|
279
|
+
return argv
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _daemon_argv(args):
|
|
283
|
+
argv = [
|
|
284
|
+
"--config",
|
|
285
|
+
str(args.config),
|
|
286
|
+
"--workflow",
|
|
287
|
+
str(resource("workflow.yml")),
|
|
288
|
+
]
|
|
289
|
+
if args.dry_run:
|
|
290
|
+
argv.append("--dry-run")
|
|
291
|
+
if args.once:
|
|
292
|
+
argv.append("--once")
|
|
293
|
+
return argv
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _status_argv(args, suffix):
|
|
297
|
+
validated = _validated_config(args)
|
|
298
|
+
return ["--db", validated["db_path"], *suffix]
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _init_values(args):
|
|
302
|
+
fields = {
|
|
303
|
+
"repo": args.repo,
|
|
304
|
+
"repo_path": args.repo_path,
|
|
305
|
+
"worker": args.worker,
|
|
306
|
+
"github_account": args.github_account,
|
|
307
|
+
"trusted_actor": args.trusted_actor,
|
|
308
|
+
}
|
|
309
|
+
if args.non_interactive:
|
|
310
|
+
return {key: value for key, value in fields.items() if value}
|
|
311
|
+
prompts = {
|
|
312
|
+
"repo": "GitHub repository (owner/name): ",
|
|
313
|
+
"repo_path": "Local repository checkout: ",
|
|
314
|
+
"worker": "Worker command: ",
|
|
315
|
+
"github_account": "GitHub bot account: ",
|
|
316
|
+
"trusted_actor": "Trusted GitHub actor: ",
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
key: value or input(prompts[key]).strip()
|
|
320
|
+
for key, value in fields.items()
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _emit_and_code(result, output):
|
|
325
|
+
emit_result(result, output=output)
|
|
326
|
+
return exit_codes.SUCCESS if result.get("ok") else exit_codes.INVALID_INPUT
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def _run_read_only_command(command, argv, output):
|
|
330
|
+
captured = io.StringIO()
|
|
331
|
+
with redirect_stdout(captured):
|
|
332
|
+
code = command(argv)
|
|
333
|
+
text = captured.getvalue().strip()
|
|
334
|
+
try:
|
|
335
|
+
result = json.loads(text)
|
|
336
|
+
except ValueError:
|
|
337
|
+
result = {
|
|
338
|
+
"ok": False,
|
|
339
|
+
"status": "failed",
|
|
340
|
+
"safe_error": "read-only command returned invalid output",
|
|
341
|
+
}
|
|
342
|
+
code = exit_codes.STATE_FAILURE
|
|
343
|
+
emit_result(result, output=output)
|
|
344
|
+
return code
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
348
|
+
parser = build_parser()
|
|
349
|
+
args = parser.parse_args(argv)
|
|
350
|
+
try:
|
|
351
|
+
if args.command == "init":
|
|
352
|
+
result = init_config(
|
|
353
|
+
args.config,
|
|
354
|
+
_init_values(args),
|
|
355
|
+
non_interactive=args.non_interactive,
|
|
356
|
+
force=args.force,
|
|
357
|
+
)
|
|
358
|
+
return _emit_and_code(result, args.output)
|
|
359
|
+
if args.command == "doctor":
|
|
360
|
+
return _emit_and_code(
|
|
361
|
+
doctor(args.config, skip_external=args.skip_external),
|
|
362
|
+
args.output,
|
|
363
|
+
)
|
|
364
|
+
if (
|
|
365
|
+
args.command == "migrate"
|
|
366
|
+
and args.migrate_command == "dd-github-agent"
|
|
367
|
+
):
|
|
368
|
+
return _emit_and_code(
|
|
369
|
+
migrate.migrate_legacy(
|
|
370
|
+
args.source,
|
|
371
|
+
args.target,
|
|
372
|
+
dry_run=args.dry_run,
|
|
373
|
+
),
|
|
374
|
+
args.output,
|
|
375
|
+
)
|
|
376
|
+
if args.command == "service":
|
|
377
|
+
platform_name = (
|
|
378
|
+
"darwin"
|
|
379
|
+
if sys.platform == "darwin"
|
|
380
|
+
else ("linux" if sys.platform.startswith("linux") else sys.platform)
|
|
381
|
+
)
|
|
382
|
+
if args.service_command == "install":
|
|
383
|
+
executable = Path(
|
|
384
|
+
shutil.which("robert") or sys.argv[0]
|
|
385
|
+
).resolve()
|
|
386
|
+
result = service.install_service(
|
|
387
|
+
platform_name,
|
|
388
|
+
executable,
|
|
389
|
+
args.config,
|
|
390
|
+
dry_run=args.dry_run,
|
|
391
|
+
)
|
|
392
|
+
elif args.service_command == "uninstall":
|
|
393
|
+
result = service.uninstall_service(
|
|
394
|
+
platform_name,
|
|
395
|
+
dry_run=args.dry_run,
|
|
396
|
+
)
|
|
397
|
+
else:
|
|
398
|
+
result = service.control_service(
|
|
399
|
+
platform_name,
|
|
400
|
+
args.service_command,
|
|
401
|
+
dry_run=args.dry_run,
|
|
402
|
+
)
|
|
403
|
+
return _emit_and_code(result, args.output)
|
|
404
|
+
if (
|
|
405
|
+
args.command == "diagnostics"
|
|
406
|
+
and args.diagnostics_command == "export"
|
|
407
|
+
):
|
|
408
|
+
result = diagnostics.export_diagnostics(
|
|
409
|
+
args.config,
|
|
410
|
+
args.output_path,
|
|
411
|
+
)
|
|
412
|
+
emit_result(result, output="text")
|
|
413
|
+
return (
|
|
414
|
+
exit_codes.SUCCESS
|
|
415
|
+
if result.get("ok")
|
|
416
|
+
else exit_codes.STATE_FAILURE
|
|
417
|
+
)
|
|
418
|
+
if args.command == "web" and args.web_command == "run":
|
|
419
|
+
web_argv = [
|
|
420
|
+
"--host",
|
|
421
|
+
args.host,
|
|
422
|
+
"--port",
|
|
423
|
+
str(args.port),
|
|
424
|
+
"--operator",
|
|
425
|
+
args.operator,
|
|
426
|
+
]
|
|
427
|
+
if args.db:
|
|
428
|
+
web_argv.extend(["--db", args.db])
|
|
429
|
+
else:
|
|
430
|
+
web_argv.extend(["--config", args.config])
|
|
431
|
+
if args.writable:
|
|
432
|
+
web_argv.append("--writable")
|
|
433
|
+
if args.allow_remote:
|
|
434
|
+
web_argv.append("--allow-remote")
|
|
435
|
+
if args.json:
|
|
436
|
+
web_argv.append("--json")
|
|
437
|
+
return web.main(web_argv)
|
|
438
|
+
if args.command == "openclaw":
|
|
439
|
+
if args.openclaw_command == "install":
|
|
440
|
+
written = openclaw.write_plugin(
|
|
441
|
+
args.plugin_dir,
|
|
442
|
+
force=args.force,
|
|
443
|
+
)
|
|
444
|
+
if not written["ok"]:
|
|
445
|
+
return _emit_and_code(written, args.output)
|
|
446
|
+
installed = openclaw.install_plugin(
|
|
447
|
+
args.plugin_dir,
|
|
448
|
+
dry_run=args.dry_run,
|
|
449
|
+
)
|
|
450
|
+
steps = [written, installed]
|
|
451
|
+
if not args.skip_restart:
|
|
452
|
+
steps.append(
|
|
453
|
+
openclaw.restart_gateway(
|
|
454
|
+
dry_run=args.dry_run,
|
|
455
|
+
)
|
|
456
|
+
)
|
|
457
|
+
result = {
|
|
458
|
+
"ok": all(step.get("ok") for step in steps),
|
|
459
|
+
"status": (
|
|
460
|
+
"planned"
|
|
461
|
+
if args.dry_run
|
|
462
|
+
else "installed"
|
|
463
|
+
),
|
|
464
|
+
"plugin_dir": str(args.plugin_dir),
|
|
465
|
+
"steps": steps,
|
|
466
|
+
}
|
|
467
|
+
elif args.openclaw_command == "uninstall":
|
|
468
|
+
result = openclaw.uninstall_plugin(
|
|
469
|
+
dry_run=args.dry_run,
|
|
470
|
+
)
|
|
471
|
+
else:
|
|
472
|
+
result = openclaw.plugin_status(
|
|
473
|
+
dry_run=args.dry_run,
|
|
474
|
+
)
|
|
475
|
+
return _emit_and_code(result, args.output)
|
|
476
|
+
if args.command == "config":
|
|
477
|
+
if args.config_command == "path":
|
|
478
|
+
return _emit_and_code(
|
|
479
|
+
{
|
|
480
|
+
"ok": True,
|
|
481
|
+
"status": "ready",
|
|
482
|
+
"config_path": str(args.config),
|
|
483
|
+
},
|
|
484
|
+
args.output,
|
|
485
|
+
)
|
|
486
|
+
validated = _validated_config(args)
|
|
487
|
+
return _emit_and_code(validated, args.output)
|
|
488
|
+
if args.command == "run" and args.run_command == "once":
|
|
489
|
+
return run_once.main(_run_once_argv(args))
|
|
490
|
+
if args.command == "daemon" and args.daemon_command == "run":
|
|
491
|
+
return daemon.main(_daemon_argv(args))
|
|
492
|
+
if args.command == "status":
|
|
493
|
+
return _run_read_only_command(
|
|
494
|
+
status.main,
|
|
495
|
+
_status_argv(args, ["status"]),
|
|
496
|
+
args.output,
|
|
497
|
+
)
|
|
498
|
+
if args.command == "task" and args.task_command == "show":
|
|
499
|
+
return _run_read_only_command(
|
|
500
|
+
status.main,
|
|
501
|
+
_status_argv(args, ["task", args.task_id]),
|
|
502
|
+
args.output,
|
|
503
|
+
)
|
|
504
|
+
if args.command == "run" and args.run_command == "show":
|
|
505
|
+
return _run_read_only_command(
|
|
506
|
+
status.main,
|
|
507
|
+
_status_argv(args, ["run", args.run_id]),
|
|
508
|
+
args.output,
|
|
509
|
+
)
|
|
510
|
+
if args.command == "artifact" and args.artifact_command == "show":
|
|
511
|
+
return _run_read_only_command(
|
|
512
|
+
status.main,
|
|
513
|
+
_status_argv(
|
|
514
|
+
args,
|
|
515
|
+
["artifact", args.task_id, args.artifact_type],
|
|
516
|
+
),
|
|
517
|
+
args.output,
|
|
518
|
+
)
|
|
519
|
+
parser.error(f"command is not wired yet: {args.command}")
|
|
520
|
+
except (OSError, TypeError, ValueError) as exc:
|
|
521
|
+
output = getattr(args, "output", "text")
|
|
522
|
+
emit_result(
|
|
523
|
+
{
|
|
524
|
+
"ok": False,
|
|
525
|
+
"status": "failed",
|
|
526
|
+
"safe_error": str(exc),
|
|
527
|
+
},
|
|
528
|
+
output=output,
|
|
529
|
+
)
|
|
530
|
+
return exit_codes.INVALID_INPUT
|
|
531
|
+
return exit_codes.INVALID_INPUT
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
if __name__ == "__main__":
|
|
535
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import sys
|
|
3
|
+
from typing import TextIO
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def emit_result(
|
|
7
|
+
result: dict,
|
|
8
|
+
output: str = "text",
|
|
9
|
+
stream: TextIO | None = None,
|
|
10
|
+
) -> None:
|
|
11
|
+
target = stream or sys.stdout
|
|
12
|
+
if output == "json":
|
|
13
|
+
print(json.dumps(result, ensure_ascii=False, sort_keys=True), file=target)
|
|
14
|
+
return
|
|
15
|
+
message = result.get("message") or result.get("status") or ""
|
|
16
|
+
print(str(message), file=target)
|
|
17
|
+
for key in sorted(result):
|
|
18
|
+
if key in {"message", "status", "ok"}:
|
|
19
|
+
continue
|
|
20
|
+
print(f"{key}: {result[key]}", file=target)
|