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
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"""SQLite state helpers for the Robert daemon."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timedelta, timezone
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import sqlite3
|
|
7
|
+
from uuid import uuid4
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _id(prefix):
|
|
11
|
+
return f"{prefix}-{uuid4().hex[:12]}"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def utc_now():
|
|
15
|
+
return datetime.now(timezone.utc).isoformat()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _parse_time(value):
|
|
19
|
+
if isinstance(value, datetime):
|
|
20
|
+
return value
|
|
21
|
+
if value.endswith("Z"):
|
|
22
|
+
value = value[:-1] + "+00:00"
|
|
23
|
+
return datetime.fromisoformat(value)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _decode_json(value, default=None):
|
|
27
|
+
if not value:
|
|
28
|
+
return default
|
|
29
|
+
try:
|
|
30
|
+
return json.loads(value)
|
|
31
|
+
except (TypeError, ValueError):
|
|
32
|
+
return default
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def connect(db_path):
|
|
36
|
+
conn = sqlite3.connect(Path(db_path).expanduser())
|
|
37
|
+
conn.row_factory = sqlite3.Row
|
|
38
|
+
conn.execute("PRAGMA foreign_keys = ON")
|
|
39
|
+
conn.execute("PRAGMA busy_timeout = 5000")
|
|
40
|
+
return conn
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def start_daemon_run(conn, *, config_path, owner_id, now=None):
|
|
44
|
+
now = now or utc_now()
|
|
45
|
+
daemon_run_id = owner_id
|
|
46
|
+
conn.execute(
|
|
47
|
+
"""
|
|
48
|
+
INSERT INTO daemon_runs(
|
|
49
|
+
daemon_run_id, status, owner_id, config_path, started_at
|
|
50
|
+
)
|
|
51
|
+
VALUES (?, 'running', ?, ?, ?)
|
|
52
|
+
""",
|
|
53
|
+
(daemon_run_id, owner_id, str(config_path), now),
|
|
54
|
+
)
|
|
55
|
+
return {
|
|
56
|
+
"daemon_run_id": daemon_run_id,
|
|
57
|
+
"status": "running",
|
|
58
|
+
"owner_id": owner_id,
|
|
59
|
+
"config_path": str(config_path),
|
|
60
|
+
"started_at": now,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def finish_daemon_run(conn, daemon_run_id, status, *, summary=None, error=None, now=None):
|
|
65
|
+
now = now or utc_now()
|
|
66
|
+
conn.execute(
|
|
67
|
+
"""
|
|
68
|
+
UPDATE daemon_runs
|
|
69
|
+
SET status = ?,
|
|
70
|
+
finished_at = ?,
|
|
71
|
+
summary_json = ?,
|
|
72
|
+
error_json = ?
|
|
73
|
+
WHERE daemon_run_id = ?
|
|
74
|
+
""",
|
|
75
|
+
(
|
|
76
|
+
status,
|
|
77
|
+
now,
|
|
78
|
+
json.dumps(summary or {}, ensure_ascii=False, sort_keys=True),
|
|
79
|
+
json.dumps(error, ensure_ascii=False, sort_keys=True) if error else None,
|
|
80
|
+
daemon_run_id,
|
|
81
|
+
),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def record_event(conn, daemon_run_id, event_type, status, metadata=None, now=None):
|
|
86
|
+
now = now or utc_now()
|
|
87
|
+
daemon_event_id = _id("daemon-event")
|
|
88
|
+
conn.execute(
|
|
89
|
+
"""
|
|
90
|
+
INSERT INTO daemon_events(
|
|
91
|
+
daemon_event_id, daemon_run_id, event_type, status, created_at, metadata_json
|
|
92
|
+
)
|
|
93
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
94
|
+
""",
|
|
95
|
+
(
|
|
96
|
+
daemon_event_id,
|
|
97
|
+
daemon_run_id,
|
|
98
|
+
event_type,
|
|
99
|
+
status,
|
|
100
|
+
now,
|
|
101
|
+
json.dumps(metadata or {}, ensure_ascii=False, sort_keys=True),
|
|
102
|
+
),
|
|
103
|
+
)
|
|
104
|
+
return {
|
|
105
|
+
"daemon_event_id": daemon_event_id,
|
|
106
|
+
"daemon_run_id": daemon_run_id,
|
|
107
|
+
"event_type": event_type,
|
|
108
|
+
"status": status,
|
|
109
|
+
"created_at": now,
|
|
110
|
+
"metadata": metadata or {},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _row_payload(row):
|
|
115
|
+
if not row:
|
|
116
|
+
return None
|
|
117
|
+
payload = dict(row)
|
|
118
|
+
if "summary_json" in payload:
|
|
119
|
+
payload["summary"] = _decode_json(payload.pop("summary_json"), {}) or {}
|
|
120
|
+
if "error_json" in payload:
|
|
121
|
+
payload["error"] = _decode_json(payload.pop("error_json"), None)
|
|
122
|
+
if "metadata_json" in payload:
|
|
123
|
+
payload["metadata"] = _decode_json(payload.pop("metadata_json"), {}) or {}
|
|
124
|
+
return payload
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def latest_daemon_summary(conn, event_limit=8):
|
|
128
|
+
run = conn.execute(
|
|
129
|
+
"""
|
|
130
|
+
SELECT daemon_run_id, status, owner_id, config_path, started_at, finished_at,
|
|
131
|
+
summary_json, error_json
|
|
132
|
+
FROM daemon_runs
|
|
133
|
+
ORDER BY started_at DESC, daemon_run_id DESC
|
|
134
|
+
LIMIT 1
|
|
135
|
+
"""
|
|
136
|
+
).fetchone()
|
|
137
|
+
event = conn.execute(
|
|
138
|
+
"""
|
|
139
|
+
SELECT daemon_event_id, daemon_run_id, event_type, status, created_at,
|
|
140
|
+
metadata_json
|
|
141
|
+
FROM daemon_events
|
|
142
|
+
ORDER BY created_at DESC, daemon_event_id DESC
|
|
143
|
+
LIMIT 1
|
|
144
|
+
"""
|
|
145
|
+
).fetchone()
|
|
146
|
+
lease = conn.execute(
|
|
147
|
+
"""
|
|
148
|
+
SELECT lease_id, resource_key, owner_id, status, acquired_at, expires_at,
|
|
149
|
+
heartbeat_at, released_at, metadata_json
|
|
150
|
+
FROM leases
|
|
151
|
+
WHERE resource_type = 'daemon'
|
|
152
|
+
ORDER BY CASE WHEN status = 'active' THEN 0 ELSE 1 END,
|
|
153
|
+
acquired_at DESC, lease_id DESC
|
|
154
|
+
LIMIT 1
|
|
155
|
+
"""
|
|
156
|
+
).fetchone()
|
|
157
|
+
events = conn.execute(
|
|
158
|
+
"""
|
|
159
|
+
SELECT daemon_event_id, daemon_run_id, event_type, status, created_at,
|
|
160
|
+
metadata_json
|
|
161
|
+
FROM daemon_events
|
|
162
|
+
ORDER BY created_at DESC, daemon_event_id DESC
|
|
163
|
+
LIMIT ?
|
|
164
|
+
""",
|
|
165
|
+
(event_limit,),
|
|
166
|
+
).fetchall()
|
|
167
|
+
return {
|
|
168
|
+
"available": True,
|
|
169
|
+
"latest_run": _row_payload(run),
|
|
170
|
+
"latest_event": _row_payload(event),
|
|
171
|
+
"latest_lease": _row_payload(lease),
|
|
172
|
+
"recent_events": [_row_payload(row) for row in events],
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def acquire_daemon_lease(conn, *, resource_key, owner_id, ttl_seconds, now=None):
|
|
177
|
+
now = now or utc_now()
|
|
178
|
+
now_dt = _parse_time(now)
|
|
179
|
+
expires_at = (now_dt + timedelta(seconds=ttl_seconds)).isoformat()
|
|
180
|
+
conn.execute(
|
|
181
|
+
"""
|
|
182
|
+
UPDATE leases
|
|
183
|
+
SET status = 'expired'
|
|
184
|
+
WHERE resource_type = 'daemon'
|
|
185
|
+
AND resource_key = ?
|
|
186
|
+
AND status = 'active'
|
|
187
|
+
AND expires_at <= ?
|
|
188
|
+
""",
|
|
189
|
+
(resource_key, now),
|
|
190
|
+
)
|
|
191
|
+
active = conn.execute(
|
|
192
|
+
"""
|
|
193
|
+
SELECT lease_id, owner_id, expires_at
|
|
194
|
+
FROM leases
|
|
195
|
+
WHERE resource_type = 'daemon'
|
|
196
|
+
AND resource_key = ?
|
|
197
|
+
AND status = 'active'
|
|
198
|
+
""",
|
|
199
|
+
(resource_key,),
|
|
200
|
+
).fetchone()
|
|
201
|
+
if active:
|
|
202
|
+
return {
|
|
203
|
+
"ok": False,
|
|
204
|
+
"status": "skipped_active_daemon",
|
|
205
|
+
"lease_id": active["lease_id"],
|
|
206
|
+
"owner_id": active["owner_id"],
|
|
207
|
+
"expires_at": active["expires_at"],
|
|
208
|
+
}
|
|
209
|
+
lease_id = _id("lease")
|
|
210
|
+
conn.execute(
|
|
211
|
+
"""
|
|
212
|
+
INSERT INTO leases(
|
|
213
|
+
lease_id, resource_type, resource_key, owner_id, status,
|
|
214
|
+
acquired_at, expires_at, heartbeat_at
|
|
215
|
+
)
|
|
216
|
+
VALUES (?, 'daemon', ?, ?, 'active', ?, ?, ?)
|
|
217
|
+
""",
|
|
218
|
+
(lease_id, resource_key, owner_id, now, expires_at, now),
|
|
219
|
+
)
|
|
220
|
+
return {
|
|
221
|
+
"ok": True,
|
|
222
|
+
"status": "acquired",
|
|
223
|
+
"lease_id": lease_id,
|
|
224
|
+
"expires_at": expires_at,
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def heartbeat_daemon_lease(conn, lease_id, ttl_seconds, now=None):
|
|
229
|
+
now = now or utc_now()
|
|
230
|
+
expires_at = (_parse_time(now) + timedelta(seconds=ttl_seconds)).isoformat()
|
|
231
|
+
conn.execute(
|
|
232
|
+
"""
|
|
233
|
+
UPDATE leases
|
|
234
|
+
SET heartbeat_at = ?,
|
|
235
|
+
expires_at = ?
|
|
236
|
+
WHERE lease_id = ?
|
|
237
|
+
AND status = 'active'
|
|
238
|
+
""",
|
|
239
|
+
(now, expires_at, lease_id),
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def release_daemon_lease(conn, lease_id, now=None):
|
|
244
|
+
now = now or utc_now()
|
|
245
|
+
conn.execute(
|
|
246
|
+
"""
|
|
247
|
+
UPDATE leases
|
|
248
|
+
SET status = 'released',
|
|
249
|
+
released_at = ?,
|
|
250
|
+
heartbeat_at = ?
|
|
251
|
+
WHERE lease_id = ?
|
|
252
|
+
AND status = 'active'
|
|
253
|
+
""",
|
|
254
|
+
(now, now, lease_id),
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def cleanup_old_events(conn, retention_days, now=None):
|
|
259
|
+
now = now or utc_now()
|
|
260
|
+
cutoff = (_parse_time(now) - timedelta(days=retention_days)).isoformat()
|
|
261
|
+
cur = conn.execute(
|
|
262
|
+
"""
|
|
263
|
+
DELETE FROM daemon_events
|
|
264
|
+
WHERE created_at < ?
|
|
265
|
+
""",
|
|
266
|
+
(cutoff,),
|
|
267
|
+
)
|
|
268
|
+
return cur.rowcount
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def running_attempt_count(conn, repo_id):
|
|
272
|
+
return conn.execute(
|
|
273
|
+
"""
|
|
274
|
+
SELECT COUNT(*)
|
|
275
|
+
FROM attempts a
|
|
276
|
+
JOIN tasks t ON t.task_id = a.task_id
|
|
277
|
+
JOIN workstreams w ON w.workstream_id = t.workstream_id
|
|
278
|
+
WHERE w.repo_id = ?
|
|
279
|
+
AND a.status IN ('running', 'stale')
|
|
280
|
+
AND t.lifecycle IN ('queued', 'running')
|
|
281
|
+
""",
|
|
282
|
+
(repo_id,),
|
|
283
|
+
).fetchone()[0]
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def running_attempt_count_for_repos(conn, repo_ids):
|
|
287
|
+
repo_ids = [repo_id for repo_id in repo_ids if repo_id]
|
|
288
|
+
if not repo_ids:
|
|
289
|
+
return 0
|
|
290
|
+
placeholders = ",".join("?" for _repo_id in repo_ids)
|
|
291
|
+
return conn.execute(
|
|
292
|
+
f"""
|
|
293
|
+
SELECT COUNT(*)
|
|
294
|
+
FROM attempts a
|
|
295
|
+
JOIN tasks t ON t.task_id = a.task_id
|
|
296
|
+
JOIN workstreams w ON w.workstream_id = t.workstream_id
|
|
297
|
+
WHERE w.repo_id IN ({placeholders})
|
|
298
|
+
AND a.status IN ('running', 'stale')
|
|
299
|
+
AND t.lifecycle IN ('queued', 'running')
|
|
300
|
+
""",
|
|
301
|
+
repo_ids,
|
|
302
|
+
).fetchone()[0]
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def capacity_full(conn, repo_id, max_concurrency):
|
|
306
|
+
return running_attempt_count(conn, repo_id) >= max_concurrency
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def capacity_full_for_repos(conn, repo_ids, max_concurrency):
|
|
310
|
+
return running_attempt_count_for_repos(conn, repo_ids) >= max_concurrency
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def repo_id_for_full_name(full_name):
|
|
314
|
+
return f"repo:{full_name}"
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def repo_id_for_config(config_result):
|
|
318
|
+
repo_names = sorted(repo["full_name"] for repo in config_result.get("repos", []))
|
|
319
|
+
return "config:" + ",".join(repo_names)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
from contextlib import closing
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import sqlite3
|
|
6
|
+
import zipfile
|
|
7
|
+
|
|
8
|
+
import yaml
|
|
9
|
+
|
|
10
|
+
from robert_agent import redaction
|
|
11
|
+
from robert_agent import status
|
|
12
|
+
from robert_agent import validate_config
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _safe_json(payload):
|
|
16
|
+
text = json.dumps(
|
|
17
|
+
payload,
|
|
18
|
+
ensure_ascii=False,
|
|
19
|
+
indent=2,
|
|
20
|
+
sort_keys=True,
|
|
21
|
+
)
|
|
22
|
+
redacted = redaction.redact_text(text)
|
|
23
|
+
if not redacted["ok"]:
|
|
24
|
+
return json.dumps(
|
|
25
|
+
{"status": "omitted_sensitive"},
|
|
26
|
+
sort_keys=True,
|
|
27
|
+
)
|
|
28
|
+
return redacted["text"]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _config_summary(config_path):
|
|
32
|
+
try:
|
|
33
|
+
raw = yaml.safe_load(
|
|
34
|
+
Path(config_path).read_text(encoding="utf-8")
|
|
35
|
+
)
|
|
36
|
+
except (OSError, ValueError, yaml.YAMLError):
|
|
37
|
+
raw = {}
|
|
38
|
+
github = raw.get("github") if isinstance(raw, dict) else {}
|
|
39
|
+
repos = raw.get("repos") if isinstance(raw, dict) else []
|
|
40
|
+
workers = raw.get("workers") if isinstance(raw, dict) else {}
|
|
41
|
+
return {
|
|
42
|
+
"version": raw.get("version") if isinstance(raw, dict) else None,
|
|
43
|
+
"github_account": (
|
|
44
|
+
github.get("account")
|
|
45
|
+
if isinstance(github, dict)
|
|
46
|
+
else None
|
|
47
|
+
),
|
|
48
|
+
"repositories": [
|
|
49
|
+
repo.get("full_name")
|
|
50
|
+
for repo in repos or []
|
|
51
|
+
if isinstance(repo, dict)
|
|
52
|
+
],
|
|
53
|
+
"workers": (
|
|
54
|
+
list(workers)
|
|
55
|
+
if isinstance(workers, dict)
|
|
56
|
+
else []
|
|
57
|
+
),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _database_payloads(config_path):
|
|
62
|
+
validated = validate_config.validate_config(
|
|
63
|
+
config_path,
|
|
64
|
+
skip_external=True,
|
|
65
|
+
)
|
|
66
|
+
if not validated.get("ok"):
|
|
67
|
+
return {}, [], "unknown"
|
|
68
|
+
db_path = Path(validated["db_path"])
|
|
69
|
+
if not db_path.is_file():
|
|
70
|
+
return {}, [], "unknown"
|
|
71
|
+
with closing(sqlite3.connect(db_path)) as conn:
|
|
72
|
+
status_payload = status.build_status(db_path)
|
|
73
|
+
runs_payload = status.build_runs(conn, limit=5)
|
|
74
|
+
row = conn.execute(
|
|
75
|
+
"SELECT MAX(version) FROM schema_migrations"
|
|
76
|
+
).fetchone()
|
|
77
|
+
return status_payload, runs_payload, str(row[0] or "unknown")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def export_diagnostics(config_path, output_path):
|
|
81
|
+
output = Path(output_path).expanduser()
|
|
82
|
+
status_payload, runs_payload, schema_version = _database_payloads(
|
|
83
|
+
config_path
|
|
84
|
+
)
|
|
85
|
+
files = {
|
|
86
|
+
"manifest.json": _safe_json(
|
|
87
|
+
{
|
|
88
|
+
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
89
|
+
"files": [
|
|
90
|
+
"config-summary.json",
|
|
91
|
+
"status.json",
|
|
92
|
+
"recent-runs.json",
|
|
93
|
+
"schema-version.txt",
|
|
94
|
+
],
|
|
95
|
+
}
|
|
96
|
+
),
|
|
97
|
+
"config-summary.json": _safe_json(
|
|
98
|
+
_config_summary(config_path)
|
|
99
|
+
),
|
|
100
|
+
"status.json": _safe_json(status_payload),
|
|
101
|
+
"recent-runs.json": _safe_json(runs_payload),
|
|
102
|
+
"schema-version.txt": schema_version,
|
|
103
|
+
}
|
|
104
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
105
|
+
temporary = output.with_suffix(output.suffix + ".tmp")
|
|
106
|
+
with zipfile.ZipFile(
|
|
107
|
+
temporary,
|
|
108
|
+
"w",
|
|
109
|
+
compression=zipfile.ZIP_DEFLATED,
|
|
110
|
+
) as archive:
|
|
111
|
+
for name, content in files.items():
|
|
112
|
+
archive.writestr(name, content)
|
|
113
|
+
temporary.replace(output)
|
|
114
|
+
return {
|
|
115
|
+
"ok": True,
|
|
116
|
+
"status": "exported",
|
|
117
|
+
"output_path": str(output),
|
|
118
|
+
"files": sorted(files),
|
|
119
|
+
}
|