-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_plane.py
More file actions
2402 lines (2220 loc) · 96.4 KB
/
control_plane.py
File metadata and controls
2402 lines (2220 loc) · 96.4 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
import json
import re
import sqlite3
from datetime import UTC, datetime, timedelta
from pathlib import Path
from typing import Any
import httpx
from .config import (
ACTIVE_PROJECTS_PATH,
DOCS_DIR,
INVENTORY_DB_PATH,
OLLARMA_BASE_URL,
OLLARMA_TIMEOUT_SECONDS,
OVERWATCH_ROOT,
RESOURCE_REGISTRY_PATH,
ROOT,
SEEDGRAPH_BASE_URL,
SEEDGRAPH_TIMEOUT_SECONDS,
SEEDGRAPH_ROOT,
)
from .hackathon_demo import (
build_demo_package as build_agenthon_demo_package,
build_demo_project_detail,
get_demo_project,
get_provider_presence,
get_sample_run,
list_demo_projects,
)
PLANNING_DIR = ROOT / ".planning"
STATE_PATH = PLANNING_DIR / "STATE.md"
ROADMAP_PATH = PLANNING_DIR / "ROADMAP.md"
MILESTONE_AUDIT_PATH = PLANNING_DIR / "v0.1-MILESTONE-AUDIT.md"
PENDING_TODOS_DIR = PLANNING_DIR / "todos" / "pending"
DEMO_VERIFICATION_FRESHNESS = timedelta(days=3)
AGENTHON_PROJECT_ID = "agenthon-001"
DEMO_PRIORITY_PROJECTS = (
AGENTHON_PROJECT_ID,
"watchtower",
"ollarma",
"seedgraph",
"overwatch",
"gettingsciencedone",
"antigence",
)
PROJECT_DEMO_HINTS: dict[str, dict[str, Any]] = {
AGENTHON_PROJECT_ID: {
"dashboard_url": f"/projects/{AGENTHON_PROJECT_ID}",
"dashboard_label": "Agenthon project page",
"kb_candidates": [],
"howto_candidates": ["docs/AGENTHON_001.md", "docs/AGENTHON_001_DEMO_SCRIPT.md"],
"launch_command": (
"curl -X POST http://127.0.0.1:8000/api/demo-projects/agenthon-001/run "
"-H 'Content-Type: application/json' "
"-d '{\"task_request\":\"Find public sources on low-cost biological age biomarkers and produce a public-safe shortlist.\"}'"
),
"launch_source_candidates": ["docs/AGENTHON_001.md", "docs/AGENTHON_001_DEMO_SCRIPT.md"],
"probe": {
"url": "http://127.0.0.1:8000/api/demo-projects/agenthon-001",
"expected_status": 200,
"expected_text": AGENTHON_PROJECT_ID,
"method": "live_probe:GET /api/demo-projects/agenthon-001",
},
"dependencies": [
"OPENAI_API_KEY for review synthesis",
"TAVILY_API_KEY for live public-source retrieval",
"DAYTONA_API_KEY and DAYTONA_API_URL for live sandbox execution",
],
"limitations": [
"Bundled sample output is public-safe fixture data, not a persisted live run.",
"SeedGraph and Antigence remain supporting lanes in this slice.",
],
"artifact_candidates": [
"demo/agenthon-001/sample-request.json",
"demo/agenthon-001/sample-run.json",
"docs/AGENTHON_001.md",
],
"escalation_candidates": [
"docs/HUMAN_AI_INTERVENTION_POLICY.md",
"docs/CONTROL_PLANE_BOUNDARY.md",
],
},
"watchtower": {
"dashboard_url": "http://127.0.0.1:8000",
"dashboard_label": "Watchtower dashboard",
"kb_candidates": ["docs/KB_HOME.md"],
"howto_candidates": ["docs/KB_HOWTO_RUN_WATCHTOWER_2026-04-10.md", "README.md"],
"launch_command": (
"uv run --no-project --python 3.13 --with fastapi --with httpx --with jinja2 "
"--with pydantic --with uvicorn uvicorn watchtower.api:app --reload"
),
"launch_source_candidates": ["docs/KB_HOWTO_RUN_WATCHTOWER_2026-04-10.md", "README.md"],
"probe": {
"url": "http://127.0.0.1:8000/healthz",
"expected_status": 200,
"expected_text": "ok",
"method": "live_probe:GET /healthz",
},
"dependencies": [
"WATCHTOWER_OVERWATCH_ROOT points at Overwatch exports",
"WATCHTOWER_OLLARMA_URL points at local Ollarma",
"WATCHTOWER_SEEDGRAPH_URL is optional for provenance reads",
],
"limitations": [
"Downstream-only surface; no canonical writes",
"SeedGraph visibility depends on configured service URL",
],
"artifact_candidates": [
".planning/STATE.md",
"tests/test_api.py",
"tests/test_control_plane.py",
],
"escalation_candidates": [
"docs/HUMAN_AI_INTERVENTION_POLICY.md",
"AGENTS.md",
],
},
"ollarma": {
"dashboard_url": "http://127.0.0.1:8484/dashboard",
"dashboard_label": "Ollarma dashboard",
"kb_candidates": ["docs/OLLARMA_KB_CONTRACT.md"],
"howto_candidates": ["docs/LOCAL_ADOPTION.md", "docs/OLLARMA_DASHBOARD.md", "README.md"],
"launch_command": "ollarma serve",
"launch_source_candidates": ["README.md", "docs/OLLARMA_DASHBOARD.md"],
"probe": {
"url": "http://127.0.0.1:8484/dashboard/overview",
"expected_status": 200,
"expected_text": "generated_at",
"method": "live_probe:GET /dashboard/overview",
},
"dependencies": [
"Local Ollama runtime",
"Validated model selection artifact",
"Repo-local KB artifacts",
],
"limitations": [
"Bounded helper lane only; no arbitrary shell execution",
"KB gaps should block routed help instead of falling back silently",
],
"artifact_candidates": [
"results/run-2026-04-11T15:45:32Z.json",
"results/run-2026-04-11T15:45:32Z.jsonl",
"results/model_selection.md",
],
"escalation_candidates": [
"docs/DETERMINISTIC_EXECUTION_BOUNDARY.md",
"src/ollarma/escalation.py",
],
},
"seedgraph": {
"dashboard_url": "http://127.0.0.1:8011/triage/publication-batches/pubbatch-724017d6090c4c15",
"dashboard_label": "SeedGraph accepted-run dashboard",
"kb_candidates": [],
"howto_candidates": [".planning/artifacts/v6.2/agenthon-001-science-ops-demo/HANDOFF.md"],
"launch_command": (
"bash /Users/byron/projects/active/seedgraph/.planning/artifacts/v6.2/"
"agenthon-001-science-ops-demo/run-demo.sh"
),
"launch_source_candidates": [
".planning/artifacts/v6.2/agenthon-001-science-ops-demo/HANDOFF.md",
".planning/quick/260411-cs8-demo-launcher-and-verification-for-accep/260411-cs8-SUMMARY.md",
],
"probe": {
"url": "http://127.0.0.1:8012/api/v1/publication-families/pubfam-a71de205cf71abea/provenance",
"expected_status": 200,
"expected_text": "publication-family-provenance-v1",
"method": "live_probe:accepted family provenance",
},
"dependencies": [
"Accepted v6.2 artifacts under .planning/artifacts/v6.2",
"Repo .venv for triage and service APIs",
],
"limitations": [
"Read-focused accepted-run demo only",
"No review mutation or canonical truth writeback",
],
"artifact_candidates": [
".planning/artifacts/v6.2/phase-63-final.scorecard.json",
".planning/artifacts/v6.2/phase-64-final.drift.json",
".planning/quick/260411-cs8-demo-launcher-and-verification-for-accep/260411-cs8-SUMMARY.md",
],
"escalation_candidates": [
"src/seedgraph/review/ui.py",
"src/seedgraph/triage/ui.py",
],
},
"overwatch": {
"dashboard_url": "http://127.0.0.1:8484/dashboard",
"dashboard_label": "Overwatch dashboard route from README",
"kb_candidates": ["docs/governance/kb/KB_HOME.md", "KB_INDEX.md"],
"howto_candidates": ["docs/governance/KB_HOWTO_OVERWATCH_MCP_DATABASE_2026-03-07.md", "README.md"],
"launch_command": "python scripts/control_plane_dashboard_web.py",
"launch_source_candidates": ["README.md"],
"probe": {
"url": "http://127.0.0.1:8484/api/dashboard",
"expected_status": 200,
"expected_text": "projects",
"method": "live_probe:GET /api/dashboard",
},
"dependencies": [
"Overwatch local environment and database stack",
"Canonical control-plane exports",
],
"limitations": [
"README dashboard port conflicts with live Ollarma service in this environment",
"Treat stale or conflicting local dashboard docs as demo blockers",
],
"artifact_candidates": [
"results/exp001_20260410T192943Z_bootstrap_smoke.json",
"data/control_plane/active_projects.json",
"data/control_plane/control_plane_resource_registry.json",
],
"escalation_candidates": [
"scripts/antigence_review.py",
"README.md",
],
},
"gettingsciencedone": {
"dashboard_url": None,
"dashboard_label": "No browser dashboard documented",
"kb_candidates": [],
"howto_candidates": ["pyproject.toml", ".planning/STATE.md", "homebrew/README.md"],
"launch_command": "gsigmad serve",
"launch_source_candidates": ["pyproject.toml", ".planning/STATE.md"],
"dependencies": [
"Python 3.11+",
"gsigmad CLI installed from the local package",
],
"limitations": [
"CLI or MCP surface only in current repo evidence",
"No repo-local browser dashboard documented",
],
"artifact_candidates": [
".planning/STATE.md",
".planning/research/SUMMARY.md",
],
"escalation_candidates": [
"src/gsigmad/commands/redteam.py",
"src/gsigmad/commands/review.py",
],
},
"antigence": {
"dashboard_url": "http://127.0.0.1:5055/",
"dashboard_label": "Antigence dashboard",
"kb_candidates": ["docs/kb/README.md"],
"howto_candidates": ["docs/ANTIGENCE_STARTUP.md", "INSTALL.md", "README.md"],
"launch_command": "antigence start",
"launch_source_candidates": ["README.md", "INSTALL.md"],
"probe": {
"url": "http://127.0.0.1:5055/",
"expected_status": 200,
"expected_text": "Antigence",
"method": "live_probe:GET /",
},
"dependencies": [
'Package installed with the "web" extra',
"Optional Ollama improves analysis quality",
],
"limitations": [
"Web UI is optional and may not be running by default",
"Verification remains review-oriented, not canonical truth",
],
"artifact_candidates": [
"results/release/public-docs-alignment.json",
"results/review_backfill_20260220T022549Z",
],
"escalation_candidates": [
"docs/portfolio/antigence-escalation-bundle.schema.json",
"src/antigence/upstream/variant_review.py",
],
},
}
def _read_json(path: Path) -> dict[str, Any]:
return json.loads(path.read_text())
def _read_text(path: Path) -> str:
return path.read_text() if path.exists() else ""
def load_active_project_register() -> dict[str, Any]:
return _read_json(ACTIVE_PROJECTS_PATH)
def load_resource_registry() -> dict[str, Any]:
return _read_json(RESOURCE_REGISTRY_PATH)
def build_agenthon_live_readiness() -> dict[str, Any]:
provider_presence = get_provider_presence()
blockers = [
item["env_var"]
for item in provider_presence.values()
if item.get("required") and not item.get("configured")
]
next_steps = [
f"Configure required env vars: {', '.join(blockers)}"
if blockers
else "Run the sample demo from the project page."
]
return {
"status": "ready_for_live_run" if not blockers else "provider_env_missing",
"blockers": blockers,
"next_steps": next_steps,
}
def build_agenthon_project_record() -> dict[str, Any]:
project = get_demo_project(AGENTHON_PROJECT_ID)
sample_run = get_sample_run(AGENTHON_PROJECT_ID)
readiness = build_agenthon_live_readiness()
if project is None:
raise FileNotFoundError(f"Missing demo project config for {AGENTHON_PROJECT_ID}")
return {
"project_id": project["project_id"],
"name": project.get("public_title") or project["project_id"],
"repo_path": str(ROOT),
"project_type": "watchtower-local-demo",
"mutation_scope": "watchtower-local-derived",
"current_status": readiness["status"],
"next_action": readiness["next_steps"][0],
"notes": [project.get("summary") or "Public-safe Watchtower hackathon demo."],
"direction_contract": {
"primary_role": "hackathon-demo",
"owner_lane": "watchtower",
"operating_posture": "active" if not readiness["blockers"] else "staged",
"direction": project.get("summary"),
"boundary_notes": "Watchtower-local derived demo record; not canonical Overwatch truth.",
},
"state_metadata": {
"status": readiness["status"],
"milestone": project.get("version"),
"last_activity": None,
},
"gaps": {
"provider_env": "ok" if not readiness["blockers"] else "blocked",
"seedgraph": "waived-by-type",
"antigence": "waived-by-type",
},
"drift_items": [],
"remediation_items": readiness["next_steps"],
"evidence_sources": [
f"/api/demo-projects/{AGENTHON_PROJECT_ID}",
f"/api/demo-projects/{AGENTHON_PROJECT_ID}/sample-run",
],
"surfaces": {
"project_page": {"path": f"/projects/{AGENTHON_PROJECT_ID}", "status": "observed", "required": True},
"project_json": {"path": f"/api/demo-projects/{AGENTHON_PROJECT_ID}", "status": "observed", "required": True},
"run_api": {"path": f"/api/demo-projects/{AGENTHON_PROJECT_ID}/run", "status": "observed", "required": True},
},
"ownership_contract": {
"owned_surface": {
"surface_name": project.get("public_title") or AGENTHON_PROJECT_ID,
"notes": "Public-safe Watchtower-owned hackathon demo surface.",
"export_status": "derived_local",
"scientific_authority": "watchtower-demo-only",
},
"imported_surfaces": [],
},
}
def _derived_project_records() -> list[dict[str, Any]]:
return [build_agenthon_project_record()]
def list_projects() -> list[dict[str, Any]]:
register = load_active_project_register()
items: list[dict[str, Any]] = []
for record in [*register.get("projects", []), *_derived_project_records()]:
direction = record.get("direction_contract", {})
ownership = record.get("ownership_contract", {})
state_metadata = record.get("state_metadata", {})
gaps = record.get("gaps", {})
imported_surfaces = ownership.get("imported_surfaces", [])
items.append(
{
"project_id": record.get("project_id"),
"name": record.get("name"),
"repo_path": record.get("repo_path"),
"project_type": record.get("project_type"),
"mutation_scope": record.get("mutation_scope"),
"current_status": record.get("current_status"),
"status": state_metadata.get("status"),
"milestone": state_metadata.get("milestone"),
"last_activity": state_metadata.get("last_activity"),
"primary_role": direction.get("primary_role"),
"owner_lane": direction.get("owner_lane"),
"operating_posture": direction.get("operating_posture"),
"direction": direction.get("direction"),
"boundary_notes": direction.get("boundary_notes"),
"next_action": record.get("next_action"),
"notes": record.get("notes"),
"gaps": gaps,
"gap_count": sum(1 for value in gaps.values() if value not in {"ok", "waived-by-type"}),
"imported_surface_count": len(imported_surfaces),
"drift_items": record.get("drift_items", []),
"remediation_items": record.get("remediation_items", []),
"evidence_sources": record.get("evidence_sources", []),
"surfaces": record.get("surfaces", {}),
}
)
return sorted(items, key=lambda item: (item["project_id"] or "").lower())
def build_project_overview() -> dict[str, Any]:
projects = list_projects()
blocked = sum(1 for item in projects if item.get("operating_posture") == "blocked")
active = sum(1 for item in projects if item.get("operating_posture") == "active")
staged = sum(1 for item in projects if item.get("operating_posture") in {"staged", "adjacent"})
return {
"project_count": len(projects),
"blocked_count": blocked,
"active_count": active,
"staged_count": staged,
}
def list_resources(*, resource_class: str | None = None, owner: str | None = None) -> list[dict[str, Any]]:
registry = load_resource_registry()
items = registry.get("resources", [])
if resource_class:
items = [item for item in items if item.get("resource_class") == resource_class]
if owner:
items = [item for item in items if item.get("owner") == owner]
return items
def build_resource_overview() -> dict[str, Any]:
registry = load_resource_registry()
return registry.get("summary", {})
def inventory_db_available() -> bool:
return INVENTORY_DB_PATH.exists()
def _connect_inventory() -> sqlite3.Connection:
connection = sqlite3.connect(f"file:{INVENTORY_DB_PATH}?mode=ro", uri=True)
connection.row_factory = sqlite3.Row
return connection
def _rows(query: str, params: tuple[Any, ...] = ()) -> list[dict[str, Any]]:
if not inventory_db_available():
return []
with _connect_inventory() as connection:
cursor = connection.execute(query, params)
return [dict(row) for row in cursor.fetchall()]
def inventory_overview() -> dict[str, Any]:
if not inventory_db_available():
return {
"available": False,
"db_path": str(INVENTORY_DB_PATH),
"root_count": 0,
"complete_root_count": 0,
"node_count": 0,
"file_count": 0,
"dir_count": 0,
"symlink_count": 0,
}
with _connect_inventory() as connection:
row = connection.execute(
"""
SELECT
COUNT(*) AS root_count,
SUM(CASE WHEN scan_status = 'complete' THEN 1 ELSE 0 END) AS complete_root_count,
COALESCE(SUM(node_count), 0) AS node_count,
COALESCE(SUM(file_count), 0) AS file_count,
COALESCE(SUM(dir_count), 0) AS dir_count,
COALESCE(SUM(symlink_count), 0) AS symlink_count,
MAX(updated_at) AS updated_at
FROM root_scan_state
"""
).fetchone()
return {
"available": True,
"db_path": str(INVENTORY_DB_PATH),
"root_count": int(row["root_count"] or 0),
"complete_root_count": int(row["complete_root_count"] or 0),
"node_count": int(row["node_count"] or 0),
"file_count": int(row["file_count"] or 0),
"dir_count": int(row["dir_count"] or 0),
"symlink_count": int(row["symlink_count"] or 0),
"updated_at": row["updated_at"],
}
def list_inventory_roots() -> list[dict[str, Any]]:
rows = _rows(
"""
SELECT
root_id,
label,
path,
scan_status,
authority_source,
file_count,
dir_count,
symlink_count,
hidden_count,
git_marker_count,
error_count,
total_file_bytes,
node_count,
updated_at
FROM root_scan_state
ORDER BY label COLLATE NOCASE
"""
)
return rows
def search_inventory_nodes(
query: str | None = None,
*,
root_id: str | None = None,
entry_type: str | None = None,
include_hidden: bool = False,
limit: int = 50,
) -> list[dict[str, Any]]:
sql = """
SELECT
node_key,
root_id,
path,
rel_path,
name,
depth,
entry_type,
extension,
size_bytes,
mtime_utc,
is_hidden,
is_symlink,
symlink_target,
scan_error
FROM nodes
WHERE 1 = 1
"""
params: list[Any] = []
if query:
like = f"%{query}%"
sql += " AND (path LIKE ? OR rel_path LIKE ? OR name LIKE ?)"
params.extend([like, like, like])
if root_id:
sql += " AND root_id = ?"
params.append(root_id)
if entry_type:
sql += " AND entry_type = ?"
params.append(entry_type)
if not include_hidden:
sql += " AND is_hidden = 0"
sql += " ORDER BY depth ASC, path ASC LIMIT ?"
params.append(max(1, min(limit, 500)))
return _rows(sql, tuple(params))
def build_watchtower_overview() -> dict[str, Any]:
projects = list_projects()
hackathon_projects = build_hackathon_projects()
operator_contract = build_operator_contract()
planning = build_planning_overview()
active_blockers = build_active_blockers(operator_contract)
next_actions = build_next_actions(projects, planning, active_blockers)
tasks = build_task_feed(projects, planning)
opportunities = build_opportunity_feed(planning)
opportunity_lanes = build_opportunity_lanes()
operator_queue = build_operator_queue(tasks, active_blockers, opportunities)
helper_lane = next(
(lane for lane in operator_contract["lanes"] if lane["lane_id"] == "ollarma-bounded-helper"),
None,
)
seedgraph_lane = next(
(lane for lane in operator_contract["lanes"] if lane["lane_id"] == "seedgraph-provenance-identity"),
None,
)
ollarma_dashboard = _ollarma_dashboard_surface()
readiness = build_operator_readiness(operator_contract, opportunity_lanes)
approved_actions = build_approved_actions(operator_contract)
demo_contracts = build_demo_contracts(
projects,
helper_lane=helper_lane,
seedgraph_lane=seedgraph_lane,
ollarma_dashboard=ollarma_dashboard,
)
demo_summary = build_demo_portfolio_summary(demo_contracts)
operator_summary = build_operator_summary_rows(
projects,
helper_lane=helper_lane,
seedgraph_lane=seedgraph_lane,
ollarma_dashboard=ollarma_dashboard,
next_actions=next_actions,
)
return {
"projects": build_project_overview(),
"resources": build_resource_overview(),
"inventory": inventory_overview(),
"operator_contract": operator_contract,
"planning": planning,
"active_blockers": active_blockers,
"next_actions": next_actions,
"tasks": tasks,
"opportunities": opportunities,
"opportunity_lanes": opportunity_lanes,
"operator_queue": operator_queue,
"readiness": readiness,
"approved_actions": approved_actions,
"helper_lane": helper_lane,
"seedgraph_lane": seedgraph_lane,
"ollarma_dashboard": ollarma_dashboard,
"demo_contracts": demo_contracts,
"demo_summary": demo_summary,
"operator_summary": operator_summary,
"hackathon_projects": hackathon_projects,
}
def build_hackathon_projects() -> list[dict[str, Any]]:
items: list[dict[str, Any]] = []
for project in list_demo_projects():
detail = build_demo_project_detail(project["project_id"])
if detail is None:
continue
blockers = list(detail.get("live_blockers", []))
sample_run = detail.get("sample_run", {})
items.append(
{
"project_id": project["project_id"],
"title": project.get("public_title") or project["project_id"],
"summary": project.get("summary"),
"version": project.get("version"),
"status": "live_ready" if not blockers else "fixture_ready",
"blockers": blockers,
"next_step": (
"Run the sample demo from the project page."
if not blockers
else f"Configure required env vars: {', '.join(blockers)}"
),
"tracks": {
"active": list(project.get("active_tracks", [])),
"supporting": list(project.get("supporting_lanes", [])),
"optional": list(project.get("optional_lanes", [])),
},
"project_page": f"/projects/{project['project_id']}",
"project_json": f"/api/demo-projects/{project['project_id']}",
"sample_run_status": sample_run.get("status"),
}
)
return items
def _repo_root_for_project(project: dict[str, Any]) -> Path | None:
repo_path = project.get("repo_path")
if not isinstance(repo_path, str):
return None
repo_root = Path(repo_path)
return repo_root if repo_root.exists() else None
def _resolve_candidates(repo_root: Path | None, candidates: list[str]) -> list[Path]:
if repo_root is None:
return []
return [repo_root / candidate for candidate in candidates if (repo_root / candidate).exists()]
def _find_first_path(repo_root: Path | None, candidates: list[str]) -> Path | None:
resolved = _resolve_candidates(repo_root, candidates)
return resolved[0] if resolved else None
def _collect_artifacts(repo_root: Path | None, candidates: list[str]) -> list[dict[str, str]]:
items: list[dict[str, str]] = []
for path in _resolve_candidates(repo_root, candidates):
items.append({"label": path.name, "path": str(path)})
return items
def _isoformat_timestamp(value: float | None) -> str | None:
if value is None:
return None
return datetime.fromtimestamp(value, tz=UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
def _path_timestamp(path: Path | None) -> str | None:
if path is None or not path.exists():
return None
return _isoformat_timestamp(path.stat().st_mtime)
def _latest_verification_path(repo_root: Path | None) -> Path | None:
if repo_root is None:
return None
phase_root = repo_root / ".planning" / "phases"
if not phase_root.exists():
return None
candidates = sorted(phase_root.glob("*/**/*VERIFICATION*.md"), key=lambda path: path.stat().st_mtime)
return candidates[-1] if candidates else None
def _parse_repo_state(path: Path | None) -> dict[str, Any]:
text = _read_text(path) if path else ""
if not text:
return {
"milestone": None,
"status": None,
"phase": None,
"next_commands": [],
"last_updated": None,
"last_activity": None,
}
milestone = (
_extract_backtick_value(r"Current milestone:\s*`([^`]+)`", text)
or _extract_backtick_value(r"Milestone:\s*`([^`]+)`", text)
or re.search(r"^milestone:\s*(.+)$", text, flags=re.MULTILINE).group(1).strip()
if re.search(r"^milestone:\s*(.+)$", text, flags=re.MULTILINE)
else None
)
status = (
_extract_backtick_value(r"Status:\s*`([^`]+)`", text)
or re.search(r"^status:\s*(.+)$", text, flags=re.MULTILINE).group(1).strip()
if re.search(r"^status:\s*(.+)$", text, flags=re.MULTILINE)
else None
)
phase = (
_extract_backtick_value(r"Current phase:\s*`([^`]+)`", text)
or re.search(r"^Phase:\s*(.+)$", text, flags=re.MULTILINE).group(1).strip()
if re.search(r"^Phase:\s*(.+)$", text, flags=re.MULTILINE)
else None
)
last_updated_match = re.search(r"^last_updated:\s*\"?([^\n\"]+)\"?$", text, flags=re.MULTILINE)
last_activity_match = re.search(r"^last_activity:\s*(.+)$", text, flags=re.MULTILINE)
return {
"milestone": milestone,
"status": status,
"phase": phase,
"next_commands": _parse_bullet_block(text, "Next command:"),
"last_updated": last_updated_match.group(1).strip() if last_updated_match else _path_timestamp(path),
"last_activity": last_activity_match.group(1).strip() if last_activity_match else None,
}
def _run_demo_probe(spec: dict[str, Any] | None) -> dict[str, Any] | None:
if not isinstance(spec, dict):
return None
url = spec.get("url")
if not isinstance(url, str):
return None
try:
with httpx.Client(timeout=2.0) as client:
response = client.get(url)
except httpx.HTTPError as exc:
return {
"ok": False,
"url": url,
"status_code": None,
"detail": str(exc),
"checked_at": datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ"),
"method": spec.get("method") or "live_probe",
}
text = response.text
expected_status = spec.get("expected_status")
expected_text = spec.get("expected_text")
ok = True
if isinstance(expected_status, int):
ok = ok and response.status_code == expected_status
if isinstance(expected_text, str):
ok = ok and expected_text in text
return {
"ok": ok,
"url": url,
"status_code": response.status_code,
"detail": None if ok else f"Unexpected response for {url}",
"checked_at": datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ"),
"method": spec.get("method") or "live_probe",
}
def _verification_status_from(probe: dict[str, Any] | None, artifact_path: Path | None) -> tuple[str, str | None, str]:
if probe and probe.get("ok"):
return "pass", probe.get("checked_at"), probe.get("method") or "live_probe"
artifact_timestamp = _path_timestamp(artifact_path)
if artifact_timestamp:
artifact_dt = datetime.strptime(artifact_timestamp, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=UTC)
freshness = "pass" if datetime.now(UTC) - artifact_dt <= DEMO_VERIFICATION_FRESHNESS else "stale"
return freshness, artifact_timestamp, f"artifact:{artifact_path.name}"
if probe:
return "fail", probe.get("checked_at"), probe.get("method") or "live_probe"
return "missing", None, "no_verification_evidence"
def _classify_demo_status(
*,
has_launch: bool,
probe_ok: bool,
verification_status: str,
blockers: list[str],
) -> str:
if not has_launch:
return "unknown"
if blockers and not probe_ok:
return "blocked"
if verification_status == "stale":
return "stale"
if probe_ok and verification_status == "pass" and not blockers:
return "runnable_now"
if verification_status == "fail":
return "blocked"
return "partial"
def _trust_level_for_status(demo_status: str, verification_status: str) -> str:
if demo_status == "runnable_now" and verification_status == "pass":
return "production-demo-safe"
if demo_status in {"runnable_now", "partial"} and verification_status in {"pass", "stale"}:
return "verified"
return "exploratory"
def _demo_docs(repo_root: Path | None, hint: dict[str, Any]) -> dict[str, Any]:
kb_path = _find_first_path(repo_root, hint.get("kb_candidates", []))
howto_path = _find_first_path(repo_root, hint.get("howto_candidates", []))
return {
"kb_link": str(kb_path) if kb_path else None,
"howto_link": str(howto_path) if howto_path else None,
}
def _demo_contract_for_project(
project: dict[str, Any],
*,
helper_lane: dict[str, Any] | None,
seedgraph_lane: dict[str, Any] | None,
ollarma_dashboard: dict[str, Any] | None,
) -> dict[str, Any]:
project_id = project.get("project_id")
repo_root = _repo_root_for_project(project)
hint = PROJECT_DEMO_HINTS.get(project_id, {})
state_path = repo_root / ".planning" / "STATE.md" if repo_root else None
state = _parse_repo_state(state_path)
docs = _demo_docs(repo_root, hint)
artifact_candidates = list(hint.get("artifact_candidates", []))
verification_artifact = _find_first_path(repo_root, artifact_candidates) or _latest_verification_path(repo_root)
probe = _run_demo_probe(hint.get("probe"))
blockers: list[str] = []
dashboard_url = hint.get("dashboard_url")
if dashboard_url is None:
blockers.append("DASHBOARD_LINK_MISSING")
if docs["kb_link"] is None:
blockers.append("KB_DOC_MISSING")
if docs["howto_link"] is None:
blockers.append("HOWTO_DOC_MISSING")
launch_command = hint.get("launch_command")
if not isinstance(launch_command, str):
blockers.append("LAUNCH_PATH_UNKNOWN")
if probe and not probe.get("ok"):
blockers.append("LIVE_PROBE_FAILED")
if project.get("operating_posture") == "blocked":
blockers.append("PROJECT_BLOCKED")
if project_id == "ollarma" and helper_lane and helper_lane.get("status") != "ready":
if helper_lane.get("blocked_reason"):
blockers.append(str(helper_lane["blocked_reason"]))
if project_id == "seedgraph" and seedgraph_lane and seedgraph_lane.get("status") != "ready":
if seedgraph_lane.get("blocked_reason"):
blockers.append(str(seedgraph_lane["blocked_reason"]))
if project_id == AGENTHON_PROJECT_ID:
blockers.extend(build_agenthon_live_readiness().get("blockers", []))
verification_status, verified_at, verification_method = _verification_status_from(probe, verification_artifact)
demo_status = _classify_demo_status(
has_launch=isinstance(launch_command, str),
probe_ok=bool(probe and probe.get("ok")),
verification_status=verification_status,
blockers=blockers,
)
trust_level = _trust_level_for_status(demo_status, verification_status)
source_of_truth = [str(ACTIVE_PROJECTS_PATH)]
if state_path and state_path.exists():
source_of_truth.append(str(state_path))
launch_source_path = _find_first_path(repo_root, hint.get("launch_source_candidates", []))
if launch_source_path:
source_of_truth.append(str(launch_source_path))
if docs["kb_link"]:
source_of_truth.append(str(docs["kb_link"]))
if docs["howto_link"] and docs["howto_link"] not in source_of_truth:
source_of_truth.append(str(docs["howto_link"]))
if verification_artifact:
source_of_truth.append(str(verification_artifact))
if project_id == AGENTHON_PROJECT_ID:
source_of_truth = [
f"/api/demo-projects/{AGENTHON_PROJECT_ID}",
f"/api/demo-projects/{AGENTHON_PROJECT_ID}/sample-run",
]
next_steps = project.get("next_action") or "No next action exported."
if "LAUNCH_PATH_UNKNOWN" in blockers:
next_steps = "Document an exact launch path before presenting this project as demo-ready."
elif "LIVE_PROBE_FAILED" in blockers and launch_command:
next_steps = f"Run the documented launch path and re-verify: {launch_command}"
dashboard_links = _project_links(
project,
helper_lane=helper_lane,
seedgraph_lane=seedgraph_lane,
ollarma_dashboard=ollarma_dashboard,
)
if dashboard_url and not any(link["href"] == dashboard_url for link in dashboard_links):
dashboard_links.insert(0, {"label": hint.get("dashboard_label") or "Dashboard", "href": dashboard_url})
if project_id == AGENTHON_PROJECT_ID:
dashboard_links.extend(
[
{"label": "Demo project JSON", "href": f"/api/demo-projects/{AGENTHON_PROJECT_ID}"},
{"label": "Sample run JSON", "href": f"/api/demo-projects/{AGENTHON_PROJECT_ID}/sample-run"},
]
)
last_updated = (
state.get("last_updated")
or project.get("last_activity")
or _path_timestamp(state_path)
)
known_limitations = list(hint.get("limitations", []))
if "DASHBOARD_LINK_MISSING" in blockers:
known_limitations.append("No dedicated dashboard surface is documented in the repo.")
if verification_status in {"stale", "missing"}:
known_limitations.append("Verification is stale or absent; do not present as fully demo-ready.")
escalation_paths = [
{"label": path.name, "path": str(path)}
for path in _resolve_candidates(repo_root, hint.get("escalation_candidates", []))
]
key_artifacts = _collect_artifacts(repo_root, hint.get("artifact_candidates", []))
if project_id == AGENTHON_PROJECT_ID:
key_artifacts = [
{"label": "Sample request JSON", "path": f"/api/demo-projects/{AGENTHON_PROJECT_ID}"},
{"label": "Sample run JSON", "path": f"/api/demo-projects/{AGENTHON_PROJECT_ID}/sample-run"},
{"label": "Demo overview doc", "path": f"/demo-projects/{AGENTHON_PROJECT_ID}/docs/overview"},
]
escalation_paths = [
{"label": "Human/AI intervention policy", "path": "/api/operator/contracts"},
{"label": "Demo project JSON", "path": f"/api/demo-projects/{AGENTHON_PROJECT_ID}"},
]
return {
"project_id": project_id,
"project_name": project.get("name"),
"owner_system": project_id,
"owner_repo": str(repo_root) if repo_root else project.get("repo_path"),
"dashboard_link": dashboard_url,
"kb_link": docs["kb_link"],
"howto_link": docs["howto_link"],
"project_status": project.get("current_status") or project.get("status"),
"milestone_status": state.get("milestone") or project.get("milestone"),
"blockers": list(dict.fromkeys(blockers)),
"next_steps": next_steps,
"demo_status": demo_status,
"launch_path": launch_command,
"verification_status": verification_status,
"verified_at": verified_at,
"verification_method": verification_method,
"source_of_truth": source_of_truth,
"last_updated": last_updated,
"dependencies": list(hint.get("dependencies", [])),
"known_limitations": list(dict.fromkeys(known_limitations)),
"key_artifacts": key_artifacts,
"escalation_paths": escalation_paths,
"trust_level": trust_level,
"dashboard_links": dashboard_links,
"probe": probe,
}
def build_demo_contracts(
projects: list[dict[str, Any]],
*,
helper_lane: dict[str, Any] | None,
seedgraph_lane: dict[str, Any] | None,
ollarma_dashboard: dict[str, Any] | None,
) -> list[dict[str, Any]]:
keyed = {project.get("project_id"): project for project in projects}
ordered_ids = list(DEMO_PRIORITY_PROJECTS) + sorted(
project_id for project_id in keyed if project_id not in DEMO_PRIORITY_PROJECTS
)
contracts = [
_demo_contract_for_project(
keyed[project_id],
helper_lane=helper_lane,