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.
Files changed (111) hide show
  1. robert_agent/__init__.py +1 -0
  2. robert_agent/acceptance.py +394 -0
  3. robert_agent/acceptance_suite.py +287 -0
  4. robert_agent/audit_result.py +501 -0
  5. robert_agent/authorize.py +117 -0
  6. robert_agent/board.py +538 -0
  7. robert_agent/chat_status.py +338 -0
  8. robert_agent/cli/__init__.py +1 -0
  9. robert_agent/cli/exit_codes.py +5 -0
  10. robert_agent/cli/main.py +535 -0
  11. robert_agent/cli/output.py +20 -0
  12. robert_agent/common.py +6 -0
  13. robert_agent/controlled_e2e_acceptance.py +394 -0
  14. robert_agent/daemon.py +607 -0
  15. robert_agent/daemon_state.py +319 -0
  16. robert_agent/diagnostics.py +119 -0
  17. robert_agent/discover.py +775 -0
  18. robert_agent/dispatch.py +217 -0
  19. robert_agent/doctor.py +94 -0
  20. robert_agent/github_api.py +12 -0
  21. robert_agent/init_config.py +126 -0
  22. robert_agent/integrations/__init__.py +1 -0
  23. robert_agent/integrations/openclaw.py +285 -0
  24. robert_agent/live_discovery_acceptance.py +70 -0
  25. robert_agent/live_worker_acceptance.py +363 -0
  26. robert_agent/live_worktree_acceptance.py +344 -0
  27. robert_agent/loop_engine.py +285 -0
  28. robert_agent/memory_curator.py +105 -0
  29. robert_agent/migrate.py +157 -0
  30. robert_agent/notify.py +74 -0
  31. robert_agent/paths.py +16 -0
  32. robert_agent/production_write_canary.py +254 -0
  33. robert_agent/project_memory.py +503 -0
  34. robert_agent/publish.py +743 -0
  35. robert_agent/publish_dedupe_acceptance.py +270 -0
  36. robert_agent/redaction.py +41 -0
  37. robert_agent/render_prompt.py +544 -0
  38. robert_agent/resource_files.py +8 -0
  39. robert_agent/resources/__init__.py +1 -0
  40. robert_agent/resources/acceptance-matrix.md +120 -0
  41. robert_agent/resources/classifier.md +19 -0
  42. robert_agent/resources/command-matrix.md +38 -0
  43. robert_agent/resources/config.example.yml +20 -0
  44. robert_agent/resources/db/migrations/001_legacy_dd_to_robert.sql +14 -0
  45. robert_agent/resources/db/schema.sql +479 -0
  46. robert_agent/resources/failure-modes.md +36 -0
  47. robert_agent/resources/fixtures/actor-permission.json +1 -0
  48. robert_agent/resources/fixtures/discovery.json +1 -0
  49. robert_agent/resources/fixtures/redaction.json +1 -0
  50. robert_agent/resources/fixtures/review-followup.json +1 -0
  51. robert_agent/resources/fixtures/worker-results.json +1 -0
  52. robert_agent/resources/fixtures/workstreams.json +1 -0
  53. robert_agent/resources/github-events.md +77 -0
  54. robert_agent/resources/kanban-control.md +165 -0
  55. robert_agent/resources/redaction.md +29 -0
  56. robert_agent/resources/result-contract.md +56 -0
  57. robert_agent/resources/routes.yml +82 -0
  58. robert_agent/resources/schemas/config.schema.json +123 -0
  59. robert_agent/resources/schemas/event.schema.json +18 -0
  60. robert_agent/resources/schemas/result.schema.json +99 -0
  61. robert_agent/resources/schemas/route.schema.json +23 -0
  62. robert_agent/resources/schemas/snapshot.schema.json +17 -0
  63. robert_agent/resources/schemas/task.schema.json +15 -0
  64. robert_agent/resources/trust-model.md +16 -0
  65. robert_agent/resources/worker-prompt.md +121 -0
  66. robert_agent/resources/worker-protocol.md +47 -0
  67. robert_agent/resources/workflow.yml +50 -0
  68. robert_agent/resources/workstream-model.md +17 -0
  69. robert_agent/route.py +232 -0
  70. robert_agent/route_config.py +64 -0
  71. robert_agent/run_once.py +5375 -0
  72. robert_agent/runtime_knowledge.py +392 -0
  73. robert_agent/service.py +161 -0
  74. robert_agent/skills.py +28 -0
  75. robert_agent/status.py +1051 -0
  76. robert_agent/storage.py +376 -0
  77. robert_agent/summarize.py +100 -0
  78. robert_agent/supervise.py +72 -0
  79. robert_agent/usage.py +192 -0
  80. robert_agent/validate_config.py +616 -0
  81. robert_agent/wakeup.py +261 -0
  82. robert_agent/web.py +2893 -0
  83. robert_agent/web_assets/board.css +255 -0
  84. robert_agent/web_assets/board.html +165 -0
  85. robert_agent/web_assets/board.js +660 -0
  86. robert_agent/web_assets/github-shell.css +122 -0
  87. robert_agent/web_assets/index.html +103 -0
  88. robert_agent/web_assets/operations.css +168 -0
  89. robert_agent/web_assets/workbench.css +131 -0
  90. robert_agent/web_assets/workbench.js +581 -0
  91. robert_agent/work_items.py +1016 -0
  92. robert_agent/workbench.py +701 -0
  93. robert_agent/worker/__init__.py +1 -0
  94. robert_agent/worker/heartbeat.py +190 -0
  95. robert_agent/worker/result.py +321 -0
  96. robert_agent/worker/snapshot.py +98 -0
  97. robert_agent/worker_adapters/__init__.py +138 -0
  98. robert_agent/worker_adapters/cbc.py +68 -0
  99. robert_agent/worker_adapters/codex.py +56 -0
  100. robert_agent/worker_adapters/command.py +33 -0
  101. robert_agent/worker_adapters/tcodex.py +56 -0
  102. robert_agent/worker_heartbeat.py +6 -0
  103. robert_agent/worker_result.py +6 -0
  104. robert_agent/worker_snapshot.py +6 -0
  105. robert_agent/workstream.py +55 -0
  106. robert_agent/worktree.py +297 -0
  107. robert_github_agent-0.1.0b1.dist-info/METADATA +217 -0
  108. robert_github_agent-0.1.0b1.dist-info/RECORD +111 -0
  109. robert_github_agent-0.1.0b1.dist-info/WHEEL +4 -0
  110. robert_github_agent-0.1.0b1.dist-info/entry_points.txt +2 -0
  111. robert_github_agent-0.1.0b1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,392 @@
1
+ """Human-approved runtime knowledge helpers for DD GitHub agent."""
2
+
3
+ import json
4
+ import re
5
+ from uuid import uuid4
6
+
7
+
8
+ VALID_SCOPE_TYPES = {"global", "route", "path", "symbol", "workstream"}
9
+ TOKEN_RE = re.compile(r"[A-Za-z0-9_./#!-]+")
10
+
11
+
12
+ def _id(prefix):
13
+ return f"{prefix}-{uuid4().hex[:12]}"
14
+
15
+
16
+ def _text(value):
17
+ return value.strip() if isinstance(value, str) else ""
18
+
19
+
20
+ def _json_list(value):
21
+ return value if isinstance(value, list) else []
22
+
23
+
24
+ def _json_object(value):
25
+ return value if isinstance(value, dict) else {}
26
+
27
+
28
+ def _decode_json(value, default):
29
+ if not value:
30
+ return default
31
+ try:
32
+ parsed = json.loads(value)
33
+ except (TypeError, ValueError):
34
+ return default
35
+ if isinstance(default, list) and isinstance(parsed, list):
36
+ return parsed
37
+ if isinstance(default, dict) and isinstance(parsed, dict):
38
+ return parsed
39
+ return default
40
+
41
+
42
+ def _terms_from_text(value):
43
+ terms = set()
44
+ for token in TOKEN_RE.findall(value or ""):
45
+ normalized = token.strip(".,:;()[]{}<>\"'`").lower()
46
+ if not normalized:
47
+ continue
48
+ terms.add(normalized)
49
+ if "-" in normalized:
50
+ terms.update(part for part in normalized.split("-") if part)
51
+ if "/" in normalized:
52
+ terms.update(part for part in normalized.split("/") if part)
53
+ return terms
54
+
55
+
56
+ def _candidate_type(kind):
57
+ if kind == "anti_pattern":
58
+ return "anti_pattern"
59
+ if kind in {"verification", "test"}:
60
+ return "verification_hint"
61
+ return "rule"
62
+
63
+
64
+ def _candidate_prompt_text(row, metadata):
65
+ paths = metadata.get("paths") or []
66
+ symbols = metadata.get("symbols") or []
67
+ suffix = []
68
+ if paths:
69
+ suffix.append("Paths: " + ", ".join(paths[:3]))
70
+ if symbols:
71
+ suffix.append("Symbols: " + ", ".join(symbols[:3]))
72
+ prompt = f"{row['title']}: {row['short_summary']}"
73
+ if suffix:
74
+ prompt += " (" + "; ".join(suffix) + ")"
75
+ return prompt
76
+
77
+
78
+ def _candidate_retrieval_boost(metadata):
79
+ return {
80
+ "keywords": metadata.get("keywords") or [],
81
+ "paths": metadata.get("paths") or [],
82
+ "symbols": metadata.get("symbols") or [],
83
+ }
84
+
85
+
86
+ def propose_candidates(conn, repo_id, run_now):
87
+ rows = conn.execute(
88
+ """
89
+ SELECT memory_id, kind, title, short_summary, confidence, metadata_json
90
+ FROM project_memory_entries
91
+ WHERE repo_id = ?
92
+ ORDER BY updated_at DESC, memory_id
93
+ """,
94
+ (repo_id,),
95
+ ).fetchall()
96
+ proposed = []
97
+ for row in rows:
98
+ row = {
99
+ "memory_id": row[0],
100
+ "kind": row[1],
101
+ "title": row[2],
102
+ "short_summary": row[3],
103
+ "confidence": row[4],
104
+ "metadata_json": row[5],
105
+ }
106
+ source_memory_ids = [row["memory_id"]]
107
+ source_json = json.dumps(source_memory_ids, sort_keys=True)
108
+ exists = conn.execute(
109
+ """
110
+ SELECT candidate_id
111
+ FROM knowledge_candidates
112
+ WHERE repo_id = ?
113
+ AND title = ?
114
+ AND source_memory_ids_json = ?
115
+ """,
116
+ (repo_id, row["title"], source_json),
117
+ ).fetchone()
118
+ if exists:
119
+ continue
120
+ metadata = _decode_json(row["metadata_json"], {})
121
+ candidate_id = _id("kc")
122
+ retrieval_boost = _candidate_retrieval_boost(metadata)
123
+ conn.execute(
124
+ """
125
+ INSERT INTO knowledge_candidates(
126
+ candidate_id, repo_id, title, summary, prompt_text, candidate_type,
127
+ source_memory_ids_json, evidence_json, confidence, status,
128
+ created_at, metadata_json
129
+ )
130
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?)
131
+ """,
132
+ (
133
+ candidate_id,
134
+ repo_id,
135
+ row["title"],
136
+ row["short_summary"],
137
+ _candidate_prompt_text(row, metadata),
138
+ _candidate_type(row["kind"]),
139
+ source_json,
140
+ json.dumps(metadata.get("evidence") or [], ensure_ascii=False, sort_keys=True),
141
+ row["confidence"],
142
+ run_now,
143
+ json.dumps(
144
+ {"retrieval_boost": retrieval_boost},
145
+ ensure_ascii=False,
146
+ sort_keys=True,
147
+ ),
148
+ ),
149
+ )
150
+ proposed.append(candidate_id)
151
+ return {"ok": True, "status": "proposed", "candidate_count": len(proposed), "candidate_ids": proposed}
152
+
153
+
154
+ def approve_candidate(conn, candidate_id, scope_type, scope_value, approved_by, run_now):
155
+ scope_type = _text(scope_type)
156
+ if scope_type not in VALID_SCOPE_TYPES:
157
+ return {"ok": False, "status": "failed_validation", "safe_error": f"invalid scope_type: {scope_type}"}
158
+ if scope_type == "global":
159
+ scope_value = ""
160
+ else:
161
+ scope_value = _text(scope_value)
162
+ if not scope_value:
163
+ return {"ok": False, "status": "failed_validation", "safe_error": "scope_value is required"}
164
+ approved_by = _text(approved_by)
165
+ if not approved_by:
166
+ return {"ok": False, "status": "failed_validation", "safe_error": "approved_by is required"}
167
+ row = conn.execute(
168
+ """
169
+ SELECT repo_id, title, prompt_text, metadata_json, status
170
+ FROM knowledge_candidates
171
+ WHERE candidate_id = ?
172
+ """,
173
+ (candidate_id,),
174
+ ).fetchone()
175
+ if not row:
176
+ return {"ok": False, "status": "not_found", "safe_error": f"candidate not found: {candidate_id}"}
177
+ repo_id, title, prompt_text, metadata_json, status = row
178
+ if status != "pending":
179
+ return {"ok": False, "status": "not_pending", "safe_error": f"candidate is {status}"}
180
+ metadata = _decode_json(metadata_json, {})
181
+ knowledge_id = _id("rk")
182
+ conn.execute(
183
+ """
184
+ INSERT INTO runtime_knowledge(
185
+ knowledge_id, candidate_id, repo_id, scope_type, scope_value,
186
+ title, prompt_text, retrieval_boost_json, active,
187
+ approved_by, approved_at, created_at, updated_at, metadata_json
188
+ )
189
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?)
190
+ """,
191
+ (
192
+ knowledge_id,
193
+ candidate_id,
194
+ repo_id,
195
+ scope_type,
196
+ scope_value,
197
+ title,
198
+ prompt_text,
199
+ json.dumps(
200
+ _json_object(metadata.get("retrieval_boost")),
201
+ ensure_ascii=False,
202
+ sort_keys=True,
203
+ ),
204
+ approved_by,
205
+ run_now,
206
+ run_now,
207
+ run_now,
208
+ "{}",
209
+ ),
210
+ )
211
+ conn.execute(
212
+ """
213
+ UPDATE knowledge_candidates
214
+ SET status = 'approved',
215
+ reviewed_at = ?,
216
+ reviewer = ?
217
+ WHERE candidate_id = ?
218
+ """,
219
+ (run_now, approved_by, candidate_id),
220
+ )
221
+ return {
222
+ "ok": True,
223
+ "status": "approved",
224
+ "candidate_id": candidate_id,
225
+ "knowledge_id": knowledge_id,
226
+ }
227
+
228
+
229
+ def reject_candidate(conn, candidate_id, reviewer, review_note, run_now):
230
+ reviewer = _text(reviewer)
231
+ if not reviewer:
232
+ return {"ok": False, "status": "failed_validation", "safe_error": "reviewer is required"}
233
+ row = conn.execute(
234
+ "SELECT status FROM knowledge_candidates WHERE candidate_id = ?",
235
+ (candidate_id,),
236
+ ).fetchone()
237
+ if not row:
238
+ return {"ok": False, "status": "not_found", "safe_error": f"candidate not found: {candidate_id}"}
239
+ if row[0] != "pending":
240
+ return {"ok": False, "status": "not_pending", "safe_error": f"candidate is {row[0]}"}
241
+ conn.execute(
242
+ """
243
+ UPDATE knowledge_candidates
244
+ SET status = 'rejected',
245
+ reviewed_at = ?,
246
+ reviewer = ?,
247
+ review_note = ?
248
+ WHERE candidate_id = ?
249
+ """,
250
+ (run_now, reviewer, _text(review_note), candidate_id),
251
+ )
252
+ return {"ok": True, "status": "rejected", "candidate_id": candidate_id}
253
+
254
+
255
+ def _event_terms(events):
256
+ terms = set()
257
+ for event in events or []:
258
+ if not isinstance(event, dict):
259
+ continue
260
+ for key in ["title", "body", "intent", "source_key", "source_type"]:
261
+ terms.update(_terms_from_text(_text(event.get(key))))
262
+ metadata = event.get("metadata")
263
+ if isinstance(metadata, dict):
264
+ for value in metadata.values():
265
+ if isinstance(value, str):
266
+ terms.update(_terms_from_text(value))
267
+ return terms
268
+
269
+
270
+ def _knowledge_score(row, route_result, event_terms, workstream_id):
271
+ scope_type = row["scope_type"]
272
+ scope_value = row["scope_value"]
273
+ if scope_type == "global":
274
+ return 1
275
+ if scope_type == "route":
276
+ if scope_value in {
277
+ _text(route_result.get("route_id")),
278
+ _text(route_result.get("expected_output")),
279
+ }:
280
+ return 50
281
+ return 0
282
+ if scope_type == "workstream":
283
+ return 60 if scope_value and scope_value == workstream_id else 0
284
+ if scope_type in {"path", "symbol"}:
285
+ return 35 if scope_value.lower() in event_terms else 0
286
+ return 0
287
+
288
+
289
+ def load_runtime_knowledge(conn, repo_id, route_result, events, workstream_id=None, limit=5):
290
+ rows = conn.execute(
291
+ """
292
+ SELECT knowledge_id, candidate_id, repo_id, scope_type, scope_value,
293
+ title, prompt_text, retrieval_boost_json, approved_by, approved_at
294
+ FROM runtime_knowledge
295
+ WHERE repo_id = ?
296
+ AND active = 1
297
+ ORDER BY approved_at DESC, knowledge_id
298
+ """,
299
+ (repo_id,),
300
+ ).fetchall()
301
+ terms = _event_terms(events)
302
+ matched = []
303
+ for row in rows:
304
+ item = {
305
+ "knowledge_id": row[0],
306
+ "candidate_id": row[1],
307
+ "repo_id": row[2],
308
+ "scope_type": row[3],
309
+ "scope_value": row[4],
310
+ "title": row[5],
311
+ "prompt_text": row[6],
312
+ "retrieval_boost": _decode_json(row[7], {}),
313
+ "approved_by": row[8],
314
+ "approved_at": row[9],
315
+ }
316
+ score = _knowledge_score(item, route_result or {}, terms, workstream_id)
317
+ if score <= 0:
318
+ continue
319
+ item["score"] = score
320
+ matched.append(item)
321
+ matched.sort(key=lambda item: (-item["score"], item["approved_at"], item["knowledge_id"]))
322
+ return matched[:limit]
323
+
324
+
325
+ def list_candidates(conn, repo_id=None, status=None):
326
+ clauses = []
327
+ params = []
328
+ if repo_id:
329
+ clauses.append("repo_id = ?")
330
+ params.append(repo_id)
331
+ if status:
332
+ clauses.append("status = ?")
333
+ params.append(status)
334
+ where = "WHERE " + " AND ".join(clauses) if clauses else ""
335
+ rows = conn.execute(
336
+ f"""
337
+ SELECT candidate_id, repo_id, title, summary, candidate_type,
338
+ confidence, status, created_at, reviewed_at, reviewer
339
+ FROM knowledge_candidates
340
+ {where}
341
+ ORDER BY created_at DESC, candidate_id
342
+ """,
343
+ params,
344
+ ).fetchall()
345
+ return [
346
+ {
347
+ "candidate_id": row[0],
348
+ "repo_id": row[1],
349
+ "title": row[2],
350
+ "summary": row[3],
351
+ "candidate_type": row[4],
352
+ "confidence": row[5],
353
+ "status": row[6],
354
+ "created_at": row[7],
355
+ "reviewed_at": row[8],
356
+ "reviewer": row[9],
357
+ }
358
+ for row in rows
359
+ ]
360
+
361
+
362
+ def show_candidate(conn, candidate_id):
363
+ row = conn.execute(
364
+ """
365
+ SELECT candidate_id, repo_id, title, summary, prompt_text,
366
+ candidate_type, source_memory_ids_json, evidence_json,
367
+ confidence, status, created_at, reviewed_at, reviewer,
368
+ review_note, metadata_json
369
+ FROM knowledge_candidates
370
+ WHERE candidate_id = ?
371
+ """,
372
+ (candidate_id,),
373
+ ).fetchone()
374
+ if not row:
375
+ return None
376
+ return {
377
+ "candidate_id": row[0],
378
+ "repo_id": row[1],
379
+ "title": row[2],
380
+ "summary": row[3],
381
+ "prompt_text": row[4],
382
+ "candidate_type": row[5],
383
+ "source_memory_ids": _decode_json(row[6], []),
384
+ "evidence": _decode_json(row[7], []),
385
+ "confidence": row[8],
386
+ "status": row[9],
387
+ "created_at": row[10],
388
+ "reviewed_at": row[11],
389
+ "reviewer": row[12],
390
+ "review_note": row[13],
391
+ "metadata": _decode_json(row[14], {}),
392
+ }
@@ -0,0 +1,161 @@
1
+ import os
2
+ from pathlib import Path
3
+ import plistlib
4
+ import shlex
5
+ import subprocess
6
+
7
+
8
+ def render_systemd_unit(executable: Path, config_path: Path) -> str:
9
+ command = " ".join(
10
+ shlex.quote(str(part))
11
+ for part in [
12
+ executable,
13
+ "daemon",
14
+ "run",
15
+ "--config",
16
+ config_path,
17
+ ]
18
+ )
19
+ return (
20
+ "[Unit]\n"
21
+ "Description=Robert — Your Repo Teammate\n"
22
+ "After=network-online.target\n\n"
23
+ "[Service]\n"
24
+ f"ExecStart={command}\n"
25
+ "Restart=on-failure\n"
26
+ "RestartSec=5\n\n"
27
+ "[Install]\n"
28
+ "WantedBy=default.target\n"
29
+ )
30
+
31
+
32
+ def render_launch_agent(executable: Path, config_path: Path) -> str:
33
+ payload = {
34
+ "Label": "dev.robert.agent",
35
+ "ProgramArguments": [
36
+ str(executable),
37
+ "daemon",
38
+ "run",
39
+ "--config",
40
+ str(config_path),
41
+ ],
42
+ "RunAtLoad": True,
43
+ "KeepAlive": True,
44
+ "ProcessType": "Background",
45
+ }
46
+ return plistlib.dumps(
47
+ payload,
48
+ fmt=plistlib.FMT_XML,
49
+ ).decode("utf-8")
50
+
51
+
52
+ def _service_definition(platform_name, executable, config_path):
53
+ home = Path.home()
54
+ if platform_name == "linux":
55
+ return (
56
+ home / ".config" / "systemd" / "user" / "robert.service",
57
+ render_systemd_unit(executable, config_path),
58
+ )
59
+ if platform_name == "darwin":
60
+ return (
61
+ home / "Library" / "LaunchAgents" / "dev.robert.agent.plist",
62
+ render_launch_agent(executable, config_path),
63
+ )
64
+ raise ValueError(f"unsupported service platform: {platform_name}")
65
+
66
+
67
+ def install_service(
68
+ platform_name,
69
+ executable,
70
+ config_path,
71
+ dry_run=False,
72
+ ):
73
+ path, content = _service_definition(
74
+ platform_name,
75
+ Path(executable),
76
+ Path(config_path),
77
+ )
78
+ result = {
79
+ "ok": True,
80
+ "status": "planned" if dry_run else "installed",
81
+ "path": str(path),
82
+ "content": content,
83
+ }
84
+ if dry_run:
85
+ return result
86
+ path.parent.mkdir(parents=True, exist_ok=True)
87
+ temporary = path.with_suffix(path.suffix + ".tmp")
88
+ temporary.write_text(content, encoding="utf-8")
89
+ temporary.replace(path)
90
+ return result
91
+
92
+
93
+ def uninstall_service(platform_name, dry_run=False):
94
+ path, _ = _service_definition(
95
+ platform_name,
96
+ Path("robert"),
97
+ Path("~/.config/robert/config.yml"),
98
+ )
99
+ if dry_run:
100
+ return {
101
+ "ok": True,
102
+ "status": "planned",
103
+ "path": str(path),
104
+ }
105
+ path.unlink(missing_ok=True)
106
+ return {
107
+ "ok": True,
108
+ "status": "uninstalled",
109
+ "path": str(path),
110
+ }
111
+
112
+
113
+ def _service_command(platform_name, action):
114
+ if platform_name == "linux":
115
+ return ["systemctl", "--user", action, "robert.service"]
116
+ if platform_name == "darwin":
117
+ domain = f"gui/{os.getuid()}"
118
+ label = f"{domain}/dev.robert.agent"
119
+ path, _ = _service_definition(
120
+ platform_name,
121
+ Path("robert"),
122
+ Path("~/.config/robert/config.yml"),
123
+ )
124
+ commands = {
125
+ "start": ["launchctl", "bootstrap", domain, str(path)],
126
+ "stop": ["launchctl", "bootout", label],
127
+ "restart": ["launchctl", "kickstart", "-k", label],
128
+ "status": ["launchctl", "print", label],
129
+ }
130
+ return commands[action]
131
+ raise ValueError(f"unsupported service platform: {platform_name}")
132
+
133
+
134
+ def control_service(platform_name, action, dry_run=False):
135
+ if action not in {"start", "stop", "restart", "status"}:
136
+ raise ValueError(f"unsupported service action: {action}")
137
+ command = _service_command(platform_name, action)
138
+ if dry_run:
139
+ return {
140
+ "ok": True,
141
+ "status": "planned",
142
+ "command": command,
143
+ }
144
+ completed = subprocess.run(
145
+ command,
146
+ text=True,
147
+ capture_output=True,
148
+ check=False,
149
+ )
150
+ return {
151
+ "ok": completed.returncode == 0,
152
+ "status": (
153
+ "completed"
154
+ if completed.returncode == 0
155
+ else "failed"
156
+ ),
157
+ "command": command,
158
+ "returncode": completed.returncode,
159
+ "stdout": completed.stdout.strip(),
160
+ "safe_error": completed.stderr.strip(),
161
+ }
robert_agent/skills.py ADDED
@@ -0,0 +1,28 @@
1
+ from pathlib import Path
2
+ import re
3
+
4
+
5
+ NAME_RE = re.compile(r"^name:\s*(?P<name>.+?)\s*$", re.MULTILINE)
6
+
7
+
8
+ def discover_skill_names(search_paths):
9
+ names = set()
10
+ for raw_path in search_paths:
11
+ root = Path(raw_path).expanduser()
12
+ if not root.exists():
13
+ continue
14
+ for manifest in root.rglob("SKILL.md"):
15
+ match = NAME_RE.search(manifest.read_text(encoding="utf-8"))
16
+ if match:
17
+ names.add(match.group("name").strip())
18
+ return names
19
+
20
+
21
+ def route_skill_status(required, recommended, installed):
22
+ missing_required = sorted(set(required) - installed)
23
+ missing_recommended = sorted(set(recommended) - installed)
24
+ return {
25
+ "runnable": not missing_required,
26
+ "missing_required": missing_required,
27
+ "missing_recommended": missing_recommended,
28
+ }