@heretek-ai/epistemic-swarm 0.7.13 → 0.7.15

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 (84) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +6 -2
  3. package/package.json +2 -1
  4. package/plugins/factory/skills/factory/scripts/factory.py +68 -14
  5. package/plugins/opencode/index.js +21 -0
  6. package/plugins/socratic-grilling/skills/grilling/SKILL.md +14 -1
  7. package/plugins/socratic-grilling/skills/grilling/socratic_tree.py +88 -16
  8. package/runner/__pycache__/__init__.cpython-311.pyc +0 -0
  9. package/runner/__pycache__/auctioneer.cpython-311.pyc +0 -0
  10. package/runner/__pycache__/auditor_engine.cpython-311.pyc +0 -0
  11. package/runner/__pycache__/claim_store.cpython-311.pyc +0 -0
  12. package/runner/__pycache__/claim_witness.cpython-311.pyc +0 -0
  13. package/runner/__pycache__/darkharvest_claims.cpython-311.pyc +0 -0
  14. package/runner/__pycache__/errors.cpython-311.pyc +0 -0
  15. package/runner/__pycache__/living_dossiers.cpython-311.pyc +0 -0
  16. package/runner/__pycache__/mcp_protocol.cpython-311.pyc +0 -0
  17. package/runner/__pycache__/mcp_server.cpython-311.pyc +0 -0
  18. package/runner/__pycache__/path_safety.cpython-311.pyc +0 -0
  19. package/runner/__pycache__/pcrb.cpython-311.pyc +0 -0
  20. package/runner/__pycache__/pcrb_verify.cpython-311.pyc +0 -0
  21. package/runner/__pycache__/preflight.cpython-311.pyc +0 -0
  22. package/runner/__pycache__/refinement.cpython-311.pyc +0 -0
  23. package/runner/__pycache__/research_swarm.cpython-311.pyc +0 -0
  24. package/runner/__pycache__/retrieval_log.cpython-311.pyc +0 -0
  25. package/runner/__pycache__/schema_validate.cpython-311.pyc +0 -0
  26. package/runner/__pycache__/schemas.cpython-311.pyc +0 -0
  27. package/runner/__pycache__/state_machine.cpython-311.pyc +0 -0
  28. package/runner/errors.py +51 -0
  29. package/runner/mcp_server.py +132 -8
  30. package/runner/preflight.py +157 -0
  31. package/runner/research_swarm.py +148 -4
  32. package/runner/schema_validate.py +93 -0
  33. package/runner/schemas.py +270 -0
  34. package/runner/state_machine.py +96 -10
  35. package/runner/tests/__pycache__/test_auction_order.cpython-311.pyc +0 -0
  36. package/runner/tests/__pycache__/test_backends.cpython-311.pyc +0 -0
  37. package/runner/tests/__pycache__/test_bet1_spike.cpython-311.pyc +0 -0
  38. package/runner/tests/__pycache__/test_claim_store.cpython-311.pyc +0 -0
  39. package/runner/tests/__pycache__/test_claim_witness.cpython-311.pyc +0 -0
  40. package/runner/tests/__pycache__/test_claude_plugin.cpython-311.pyc +0 -0
  41. package/runner/tests/__pycache__/test_contract_tooling.cpython-311.pyc +0 -0
  42. package/runner/tests/__pycache__/test_darkharvest_audit.cpython-311.pyc +0 -0
  43. package/runner/tests/__pycache__/test_domain_packs.cpython-311.pyc +0 -0
  44. package/runner/tests/__pycache__/test_dossier_contract.cpython-311.pyc +0 -0
  45. package/runner/tests/__pycache__/test_factory.cpython-311.pyc +0 -0
  46. package/runner/tests/__pycache__/test_fleet_seam.cpython-311.pyc +0 -0
  47. package/runner/tests/__pycache__/test_grounding.cpython-311.pyc +0 -0
  48. package/runner/tests/__pycache__/test_living_dossiers.cpython-311.pyc +0 -0
  49. package/runner/tests/__pycache__/test_manifest_concurrency.cpython-311.pyc +0 -0
  50. package/runner/tests/__pycache__/test_mcp_server.cpython-311.pyc +0 -0
  51. package/runner/tests/__pycache__/test_opencode_ux.cpython-311.pyc +0 -0
  52. package/runner/tests/__pycache__/test_opencode_v2_registrars.cpython-311.pyc +0 -0
  53. package/runner/tests/__pycache__/test_pcrb.cpython-311.pyc +0 -0
  54. package/runner/tests/__pycache__/test_refinement.cpython-311.pyc +0 -0
  55. package/runner/tests/__pycache__/test_swarm.cpython-311.pyc +0 -0
  56. package/runner/tests/__pycache__/test_swarm_config.cpython-311.pyc +0 -0
  57. package/runner/tests/__pycache__/test_sweep_regressions.cpython-311.pyc +0 -0
  58. package/runner/tests/__pycache__/test_webcache.cpython-311.pyc +0 -0
  59. package/runner/tests/test_contract_tooling.py +312 -0
  60. package/runner/tests/test_mcp_server.py +2 -0
  61. package/runner/tests/test_opencode_ux.py +4 -2
  62. package/schemas/alpha_dossier.schema.json +204 -0
  63. package/schemas/audit_report.schema.json +76 -0
  64. package/schemas/beta_dossier.schema.json +214 -0
  65. package/schemas/frontier.schema.json +61 -0
  66. package/schemas/manifest.schema.json +43 -0
  67. package/schemas/scope_manifest.schema.json +47 -0
  68. package/scripts/__pycache__/bet1_advisory_spike.cpython-311.pyc +0 -0
  69. package/scripts/__pycache__/build_adapters.cpython-311.pyc +0 -0
  70. package/scripts/__pycache__/check_docs.cpython-311.pyc +0 -0
  71. package/scripts/__pycache__/divergence_experiment.cpython-311.pyc +0 -0
  72. package/scripts/__pycache__/gen_schemas.cpython-311.pyc +0 -0
  73. package/scripts/check_docs.py +66 -0
  74. package/scripts/gen_schemas.py +69 -0
  75. package/skills/epistemic_search/scripts/__pycache__/search.cpython-311.pyc +0 -0
  76. package/skills/factory/scripts/factory.py +68 -14
  77. package/skills/grilling/SKILL.md +14 -1
  78. package/skills/grilling/__pycache__/__init__.cpython-311.pyc +0 -0
  79. package/skills/grilling/__pycache__/socratic_tree.cpython-311.pyc +0 -0
  80. package/skills/grilling/socratic_tree.py +88 -16
  81. package/skills/research_cache/__pycache__/__init__.cpython-311.pyc +0 -0
  82. package/skills/research_cache/__pycache__/hasher.cpython-311.pyc +0 -0
  83. package/skills/swarm_config/__pycache__/__init__.cpython-311.pyc +0 -0
  84. package/skills/swarm_config/__pycache__/configure.cpython-311.pyc +0 -0
@@ -0,0 +1,270 @@
1
+ #!/usr/bin/env python3
2
+ """Canonical IUMBTEMS contracts, as data.
3
+
4
+ These are the single source of truth for the on-disk formats (Heretek-AI/IUMBTEMS#6
5
+ item 2.1: the agent had to reverse-engineer the contract). `scripts/gen_schemas.py`
6
+ renders them to `schemas/*.schema.json`; `runner/schema_validate.py` enforces them
7
+ warn-on-load. Keep this module in sync with what the runner actually reads and
8
+ writes — a test asserts the generated files match.
9
+ """
10
+
11
+ from typing import Any, Dict
12
+
13
+ _DRAFT = "http://json-schema.org/draft-07/schema#"
14
+
15
+ CLAIM: Dict[str, Any] = {
16
+ "type": "object",
17
+ "required": ["claim_id", "statement"],
18
+ "properties": {
19
+ "claim_id": {"type": "string"},
20
+ "tag": {
21
+ "type": "string",
22
+ "enum": ["VERIFIED", "INFERRED", "HYPOTHESIS", "NEGATIVE_KNOWLEDGE"],
23
+ },
24
+ "statement": {"type": "string"},
25
+ "source_hash": {"type": "string"},
26
+ "source_url": {"type": "string"},
27
+ "verbatim_quote": {"type": "string"},
28
+ "severity": {"type": "string"},
29
+ },
30
+ }
31
+
32
+ INFERENCE: Dict[str, Any] = {
33
+ "type": "object",
34
+ "required": ["inference_id", "statement"],
35
+ "properties": {
36
+ "inference_id": {"type": "string"},
37
+ "tag": {"type": "string"},
38
+ "statement": {"type": "string"},
39
+ "parent_claims": {"type": "array", "items": {"type": "string"}},
40
+ "deductive_logic": {"type": "string"},
41
+ "falsification": {"type": "string"},
42
+ },
43
+ }
44
+
45
+ HYPOTHESIS: Dict[str, Any] = {
46
+ "type": "object",
47
+ "required": ["statement"],
48
+ "properties": {
49
+ "hypothesis_id": {"type": "string"},
50
+ "claim_id": {"type": "string"},
51
+ "tag": {"type": "string"},
52
+ "statement": {"type": "string"},
53
+ "falsification": {"type": "string"},
54
+ },
55
+ }
56
+
57
+ NEGATIVE_KNOWLEDGE: Dict[str, Any] = {
58
+ "type": "object",
59
+ "required": ["query", "finding"],
60
+ "properties": {
61
+ "query": {"type": "string"},
62
+ "finding": {"type": "string"},
63
+ },
64
+ }
65
+
66
+ CANDIDATE_REPO: Dict[str, Any] = {
67
+ "type": "object",
68
+ "required": ["name"],
69
+ "properties": {
70
+ "repo_id": {"type": "string"},
71
+ "name": {"type": "string"},
72
+ "url": {"type": "string"},
73
+ "source_hash": {"type": "string"},
74
+ "verbatim_quote": {"type": "string"},
75
+ "license": {"type": "string"},
76
+ "license_risk": {
77
+ "type": "string",
78
+ "enum": ["SAFE", "COPYLEFT_WARNING", "PROHIBITIVE"],
79
+ },
80
+ "harvest_policy": {
81
+ "type": "string",
82
+ "enum": ["depend-or-vendor", "clean-room-rebuild-only"],
83
+ },
84
+ "verdicts": {
85
+ "type": "array",
86
+ "items": {
87
+ "type": "object",
88
+ "required": ["feature", "verdict"],
89
+ "properties": {
90
+ "feature": {"type": "string"},
91
+ "verdict": {
92
+ "type": "string",
93
+ "enum": ["depend", "vendor", "clean-room-rebuild", "skip"],
94
+ },
95
+ "reason": {"type": "string"},
96
+ "verbatim_quote": {"type": "string"},
97
+ "effort": {"type": "string"},
98
+ "impact": {"type": "integer"},
99
+ "differentiation": {"type": "integer"},
100
+ },
101
+ },
102
+ },
103
+ "warnings": {"type": "array", "items": {"type": "string"}},
104
+ "attribution": {"type": "object"},
105
+ },
106
+ }
107
+
108
+ _COMMON_DOSSIER: Dict[str, Any] = {
109
+ "scope_id": {"type": "string"},
110
+ "agent": {"type": "string"},
111
+ "mode": {"type": "string"},
112
+ "timestamp": {"type": "string"},
113
+ "negative_knowledge": {"type": "array", "items": NEGATIVE_KNOWLEDGE},
114
+ "candidate_repositories": {"type": "array", "items": CANDIDATE_REPO},
115
+ }
116
+
117
+
118
+ def _dossier(role: str, extra: Dict[str, Any]) -> Dict[str, Any]:
119
+ props = dict(_COMMON_DOSSIER)
120
+ props.update(extra)
121
+ return {
122
+ "$schema": _DRAFT,
123
+ "title": f"{role}_dossier",
124
+ "type": "object",
125
+ "required": ["scope_id"],
126
+ "properties": props,
127
+ }
128
+
129
+
130
+ ALPHA_DOSSIER = _dossier(
131
+ "alpha",
132
+ {
133
+ "affirmative_claims": {"type": "array", "items": CLAIM},
134
+ "inferred_implications": {"type": "array", "items": INFERENCE},
135
+ },
136
+ )
137
+
138
+ BETA_DOSSIER = _dossier(
139
+ "beta",
140
+ {
141
+ "falsification_claims": {"type": "array", "items": CLAIM},
142
+ "methodological_critiques": {
143
+ "type": "array",
144
+ "items": {
145
+ "type": "object",
146
+ "properties": {
147
+ "target_assertion": {"type": "string"},
148
+ "critique": {"type": "string"},
149
+ "evidence_hash": {"type": "string"},
150
+ },
151
+ },
152
+ },
153
+ "hypotheses": {"type": "array", "items": HYPOTHESIS},
154
+ },
155
+ )
156
+
157
+ AUDIT_REPORT: Dict[str, Any] = {
158
+ "$schema": _DRAFT,
159
+ "title": "audit_report",
160
+ "type": "object",
161
+ "required": ["scope_id", "summary"],
162
+ "properties": {
163
+ "auditor": {"type": "string"},
164
+ "scope_id": {"type": "string"},
165
+ "audited_at": {"type": "string"},
166
+ "summary": {
167
+ "type": "object",
168
+ "required": [
169
+ "verified_passed",
170
+ "unverified_rejected",
171
+ "divergence_score",
172
+ "verdict",
173
+ ],
174
+ "properties": {
175
+ "total_claims_audited": {"type": "integer"},
176
+ "verified_passed": {"type": "integer"},
177
+ "unverified_rejected": {"type": "integer"},
178
+ "negative_knowledge_count": {"type": "integer"},
179
+ "epistemic_score": {"type": "number"},
180
+ "divergence_score": {"type": "number"},
181
+ "mode": {"type": ["string", "null"]},
182
+ "blocking_findings": {"type": "integer"},
183
+ "verdict": {"type": "string"},
184
+ },
185
+ },
186
+ "alpha_claims_audit": {"type": "array"},
187
+ "beta_claims_audit": {"type": "array"},
188
+ "divergence_matrix": {"type": "array"},
189
+ "harvest_findings": {"type": "array"},
190
+ "degradation": {"type": "object"},
191
+ },
192
+ }
193
+
194
+ SCOPE_MANIFEST: Dict[str, Any] = {
195
+ "$schema": _DRAFT,
196
+ "title": "scope_manifest",
197
+ "type": "object",
198
+ "required": ["scope_id", "status"],
199
+ "properties": {
200
+ "scope_id": {"type": "string"},
201
+ "title": {"type": "string"},
202
+ "objective": {"type": "string"},
203
+ "dependencies": {"type": "array", "items": {"type": "string"}},
204
+ "status": {"type": "string"},
205
+ "alpha_completed": {"type": "boolean"},
206
+ "beta_completed": {"type": "boolean"},
207
+ "audit_completed": {"type": "boolean"},
208
+ "created_at": {"type": "string"},
209
+ "outputs": {"type": "array"},
210
+ # Agent-authored (renamed on load); allowed but never authoritative.
211
+ "self_reported_epistemic_audit": {"type": "object"},
212
+ },
213
+ }
214
+
215
+ MANIFEST: Dict[str, Any] = {
216
+ "$schema": _DRAFT,
217
+ "title": "manifest",
218
+ "type": "object",
219
+ "required": ["session_id", "objective", "status", "scopes"],
220
+ "properties": {
221
+ "session_id": {"type": "string"},
222
+ "objective": {"type": "string"},
223
+ "status": {"type": "string"},
224
+ "created_at": {"type": "string"},
225
+ "updated_at": {"type": "string"},
226
+ "plugin_version": {"type": "string"},
227
+ "backend": {"type": "string"},
228
+ "preflight": {"type": "object"},
229
+ "scopes": {"type": "array"},
230
+ "telemetry": {"type": "object"},
231
+ },
232
+ }
233
+
234
+ FRONTIER: Dict[str, Any] = {
235
+ "$schema": _DRAFT,
236
+ "title": "frontier",
237
+ "type": "object",
238
+ "required": ["objective"],
239
+ "properties": {
240
+ "objective": {"type": "string"},
241
+ "is_complete": {"type": "boolean"},
242
+ # Nodes are keyed by node_id (see skills/grilling/socratic_tree.py).
243
+ "nodes": {
244
+ "type": "object",
245
+ "additionalProperties": {
246
+ "type": "object",
247
+ "required": ["node_id", "question"],
248
+ "properties": {
249
+ "node_id": {"type": "string"},
250
+ "title": {"type": "string"},
251
+ "question": {"type": "string"},
252
+ "recommended": {"type": "string"},
253
+ "options": {"type": "array", "items": {"type": "string"}},
254
+ "prerequisites": {"type": "array", "items": {"type": "string"}},
255
+ "settled_answer": {"type": ["string", "null"]},
256
+ },
257
+ },
258
+ },
259
+ "settled_constraints": {"type": "object"},
260
+ },
261
+ }
262
+
263
+ SCHEMAS: Dict[str, Dict[str, Any]] = {
264
+ "alpha_dossier": ALPHA_DOSSIER,
265
+ "beta_dossier": BETA_DOSSIER,
266
+ "audit_report": AUDIT_REPORT,
267
+ "manifest": MANIFEST,
268
+ "scope_manifest": SCOPE_MANIFEST,
269
+ "frontier": FRONTIER,
270
+ }
@@ -44,6 +44,36 @@ class ScopeStatus(str, Enum):
44
44
 
45
45
 
46
46
  MANIFEST_FILENAME = "manifest.json"
47
+ RUNS_DIRNAME = "runs"
48
+ LATEST_POINTER = "latest.json"
49
+
50
+
51
+ def run_scoped_enabled() -> bool:
52
+ """Opt-in run-scoped layout (`.research/runs/<id>/`). Default: flat.
53
+
54
+ The capability ships behind `IUMBTEMS_RUN_SCOPED=1` rather than flipped by
55
+ default: it changes every artifact path and deserves a live end-to-end run
56
+ before it becomes the default (see issue #6 item 3.9).
57
+ """
58
+ return os.environ.get("IUMBTEMS_RUN_SCOPED", "").strip().lower() in (
59
+ "1",
60
+ "true",
61
+ "yes",
62
+ "on",
63
+ )
64
+
65
+
66
+ def latest_run_dir(workspace: Path) -> Optional[Path]:
67
+ """The run dir a `latest.json` pointer refers to, if any."""
68
+ try:
69
+ data = json.loads((workspace / LATEST_POINTER).read_text(encoding="utf-8"))
70
+ run_id = data.get("run_id")
71
+ except (OSError, ValueError):
72
+ return None
73
+ if not run_id:
74
+ return None
75
+ candidate = workspace / RUNS_DIRNAME / str(run_id)
76
+ return candidate if candidate.is_dir() else None
47
77
 
48
78
 
49
79
  def manifest_name_for_mode(mode: Optional[str]) -> str:
@@ -68,19 +98,29 @@ def resolve_manifest_path(base_dir, mode: Optional[str] = None) -> Path:
68
98
  def find_any_manifest(base_dir) -> Optional[Path]:
69
99
  """Newest manifest in the workspace, preferring the canonical name.
70
100
 
71
- Lets mode-agnostic readers (e.g. PCRB export) find whichever session last
72
- wrote a manifest.
101
+ Understands both layouts: flat (`manifest.json`, `manifest.<mode>.json`) and
102
+ run-scoped (`runs/<id>/manifest*.json`, resolved via `latest.json`).
73
103
  """
74
104
  base = Path(os.path.realpath(str(base_dir)))
105
+ candidates = []
75
106
  canonical = base / MANIFEST_FILENAME
76
107
  if canonical.exists():
77
108
  return canonical
78
- candidates = sorted(
79
- base.glob("manifest.*.json"),
80
- key=lambda p: p.stat().st_mtime,
81
- reverse=True,
82
- )
83
- return candidates[0] if candidates else None
109
+ candidates.extend(base.glob("manifest.*.json"))
110
+
111
+ run_dir = latest_run_dir(base)
112
+ if run_dir is not None:
113
+ run_manifest = run_dir / MANIFEST_FILENAME
114
+ if run_manifest.exists():
115
+ return run_manifest
116
+ candidates.extend(run_dir.glob("manifest.*.json"))
117
+ if (base / RUNS_DIRNAME).is_dir():
118
+ candidates.extend((base / RUNS_DIRNAME).glob("*/manifest*.json"))
119
+
120
+ existing = [c for c in candidates if c.exists()]
121
+ if not existing:
122
+ return None
123
+ return max(existing, key=lambda p: p.stat().st_mtime)
84
124
 
85
125
 
86
126
  @contextmanager
@@ -122,8 +162,26 @@ def _atomic_write_json(path: Path, data: Any) -> None:
122
162
 
123
163
 
124
164
  class ResearchStateMachine:
125
- def __init__(self, base_dir: Optional[Path] = None, mode: Optional[str] = None):
126
- self.base_dir = Path(os.path.realpath(str(base_dir or ".research")))
165
+ def __init__(
166
+ self,
167
+ base_dir: Optional[Path] = None,
168
+ mode: Optional[str] = None,
169
+ run_scoped: Optional[bool] = None,
170
+ run_id: Optional[str] = None,
171
+ ):
172
+ workspace = Path(os.path.realpath(str(base_dir or ".research")))
173
+ if run_scoped is None:
174
+ run_scoped = run_scoped_enabled()
175
+ self.workspace = workspace
176
+ self.run_scoped = bool(run_scoped)
177
+ if self.run_scoped:
178
+ self.run_id = run_id or (
179
+ f"{mode or 'run'}-{datetime.now(timezone.utc).strftime('%Y%m%d-%H%M%S')}"
180
+ )
181
+ self.base_dir = workspace / RUNS_DIRNAME / self.run_id
182
+ else:
183
+ self.run_id = None
184
+ self.base_dir = workspace
127
185
  self.scratchpads_dir = self.base_dir / "scratchpads"
128
186
  self.sources_dir = self.base_dir / "sources"
129
187
  self.manifest_file = self.base_dir / manifest_name_for_mode(mode)
@@ -133,6 +191,16 @@ class ResearchStateMachine:
133
191
  # Ensure directories exist
134
192
  self.scratchpads_dir.mkdir(parents=True, exist_ok=True)
135
193
  self.sources_dir.mkdir(parents=True, exist_ok=True)
194
+ if self.run_scoped:
195
+ self._write_latest_pointer(mode)
196
+
197
+ def _write_latest_pointer(self, mode: Optional[str]) -> None:
198
+ try:
199
+ (self.workspace / LATEST_POINTER).write_text(
200
+ json.dumps({"run_id": self.run_id, "mode": mode}), encoding="utf-8"
201
+ )
202
+ except OSError:
203
+ pass
136
204
 
137
205
  def init_session(
138
206
  self, objective: str, session_id: Optional[str] = None
@@ -162,6 +230,24 @@ class ResearchStateMachine:
162
230
  self.save_global_manifest(manifest)
163
231
  return manifest
164
232
 
233
+ def record_preflight(
234
+ self, report: Dict[str, Any], backend: Optional[str] = None
235
+ ) -> None:
236
+ """Persist the preflight report + plugin version into the manifest."""
237
+ with self._lock, _file_lock(self._lock_file):
238
+ try:
239
+ manifest = self._read_manifest_unlocked()
240
+ except FileNotFoundError:
241
+ # Dry runs / pre-orchestration: keep the report rather than fail.
242
+ manifest = {"preflight": report}
243
+ manifest["preflight"] = report
244
+ version = report.get("plugin_version")
245
+ if version:
246
+ manifest["plugin_version"] = version
247
+ if backend:
248
+ manifest["backend"] = backend
249
+ self._write_manifest_unlocked(manifest)
250
+
165
251
  def _read_manifest_unlocked(self) -> Dict[str, Any]:
166
252
  if not self.manifest_file.exists():
167
253
  raise FileNotFoundError(