@iowarp/clio-coder 0.3.6 → 0.3.7

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 (258) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +16 -5
  3. package/dist/{acp-2BEHC4DL.js → acp-SK4MD6MM.js} +10 -10
  4. package/dist/{agents-LNNFTM53.js → agents-2FN2K6ME.js} +30 -25
  5. package/dist/assets/codewiki.json +1 -1
  6. package/dist/{auth-KXXFI2VS.js → auth-QIYZWM5I.js} +13 -13
  7. package/dist/{chunk-KHSFENX2.js → chunk-3HAPLH5M.js} +10 -10
  8. package/dist/{chunk-24I7BN55.js → chunk-465YSENW.js} +2 -2
  9. package/dist/{chunk-4OC57DA6.js → chunk-4DGYLA73.js} +53 -2
  10. package/dist/{chunk-CYQKWTG3.js → chunk-4DWFMQDR.js} +4 -4
  11. package/dist/{chunk-E2ER4LJF.js → chunk-5C3AQNDW.js} +25 -1
  12. package/dist/{chunk-22NAGB7X.js → chunk-5C77SEEY.js} +5 -94
  13. package/dist/{chunk-43AOLP7E.js → chunk-5FR74PWO.js} +2 -1
  14. package/dist/{chunk-K7T3E2SR.js → chunk-5UJ6ECTS.js} +10 -9
  15. package/dist/{chunk-6US73PDB.js → chunk-6M7VS3J3.js} +5 -5
  16. package/dist/{chunk-CJUB2JJ2.js → chunk-6TUKSZVF.js} +5 -5
  17. package/dist/{chunk-5JGRAMKL.js → chunk-AB4XIIVB.js} +8 -6
  18. package/dist/{chunk-R46L2BIR.js → chunk-BMWK7ZIZ.js} +14 -20
  19. package/dist/{chunk-4BPJXDWC.js → chunk-C4JBQ5SR.js} +30 -14
  20. package/dist/{chunk-XXQNGV4M.js → chunk-CEYBNUGC.js} +243 -63
  21. package/dist/{chunk-VEZEGCGW.js → chunk-D4MDIG46.js} +20 -18
  22. package/dist/chunk-DJNLUABN.js +843 -0
  23. package/dist/{chunk-RY3LY4J5.js → chunk-DMD2AGVS.js} +5 -4
  24. package/dist/{chunk-KOHPCX4K.js → chunk-DOOEX22V.js} +2 -2
  25. package/dist/chunk-DQA7QLMD.js +123 -0
  26. package/dist/chunk-DR52UMZW.js +21 -0
  27. package/dist/{chunk-XF5N4U5A.js → chunk-EBEFWSGL.js} +6 -5
  28. package/dist/{chunk-EYPA3EGJ.js → chunk-EELBMBT6.js} +120 -13
  29. package/dist/{chunk-CKXWIANG.js → chunk-EOOQZZDE.js} +16 -14
  30. package/dist/{chunk-WR67VIZY.js → chunk-FOT2FX5J.js} +63 -5
  31. package/dist/{chunk-FYYLNIL5.js → chunk-GH5622CP.js} +2 -2
  32. package/dist/chunk-GWS3VEIW.js +195 -0
  33. package/dist/{chunk-LYF7OHWH.js → chunk-J7PIKKWC.js} +8 -463
  34. package/dist/{chunk-NILBFAPG.js → chunk-JNXPYBB4.js} +2 -2
  35. package/dist/{chunk-4VP4KH3K.js → chunk-JRIO5UD2.js} +4 -4
  36. package/dist/{chunk-6XXKFVSN.js → chunk-JTSEDYVQ.js} +7 -7
  37. package/dist/{chunk-QKMUKYO7.js → chunk-KCMKRQX4.js} +236 -84
  38. package/dist/chunk-KZ2H5X4G.js +1026 -0
  39. package/dist/{chunk-QNQHSOLF.js → chunk-LADCF22A.js} +12 -12
  40. package/dist/chunk-M4AKACEO.js +382 -0
  41. package/dist/{chunk-XYDYPRZI.js → chunk-MXI6J5JF.js} +7 -7
  42. package/dist/{chunk-G7MUEIGA.js → chunk-OB5HIGJY.js} +1 -1
  43. package/dist/{chunk-EKY57CSP.js → chunk-OBMAI2DP.js} +61 -767
  44. package/dist/chunk-PD3MESLB.js +242 -0
  45. package/dist/{chunk-ZRGEBJ4T.js → chunk-QCTRSGHQ.js} +21 -21
  46. package/dist/chunk-RVG5JXAL.js +41 -0
  47. package/dist/{chunk-RD5U66HV.js → chunk-SROCI7ZU.js} +7 -7
  48. package/dist/{chunk-MFFY33HR.js → chunk-THKY7CD7.js} +466 -205
  49. package/dist/{chunk-PCZJO5TI.js → chunk-UFQ3F4FW.js} +13 -178
  50. package/dist/{chunk-AD2SYQYC.js → chunk-UHXRNZ2J.js} +121 -3
  51. package/dist/chunk-UND3GU2L.js +103 -0
  52. package/dist/{chunk-QM3F2GKX.js → chunk-UUANF5CR.js} +2247 -2096
  53. package/dist/chunk-UVDSQ6LW.js +472 -0
  54. package/dist/{chunk-DJVECN66.js → chunk-VQNODYQ4.js} +14 -14
  55. package/dist/{chunk-3BPUFZDL.js → chunk-VREKEFLL.js} +3 -3
  56. package/dist/{chunk-PBTHKCPN.js → chunk-WJHBC77E.js} +6 -6
  57. package/dist/{chunk-XE2VEJHX.js → chunk-X2KV5FXT.js} +2 -2
  58. package/dist/{chunk-ZXF4XRKW.js → chunk-XEGB6BCN.js} +157 -7
  59. package/dist/{chunk-E25LMLRW.js → chunk-YD734TPH.js} +2 -2
  60. package/dist/{verifiers-NCBTHHN2.js → chunk-YTYFXUI3.js} +65 -322
  61. package/dist/{chunk-OH3TOQTB.js → chunk-ZGH7FGS5.js} +13 -7
  62. package/dist/cli/index.js +32 -30
  63. package/dist/{clio-M2KGYUFZ.js → clio-WBVQEBKO.js} +7 -7
  64. package/dist/{code-nav-GQNL7XA6.js → code-nav-FGGFIE7L.js} +3 -3
  65. package/dist/{components-5TTYYX6G.js → components-F7OEATSO.js} +4 -4
  66. package/dist/{config-XUUYQIWO.js → config-TRBL3RCF.js} +34 -29
  67. package/dist/{configure-IHJ7YOMV.js → configure-OLCVPHNM.js} +15 -15
  68. package/dist/{context-74JLXAWD.js → context-MJIJ6GOX.js} +11 -11
  69. package/dist/{context-ZQ7SIFJV.js → context-WFPKQSM6.js} +19 -3
  70. package/dist/{context-75MIWW3U.js → context-XEWE3MOJ.js} +31 -26
  71. package/dist/{context-clear-GYKWNUML.js → context-clear-KNOS2JPB.js} +31 -26
  72. package/dist/{context-working-set-UX5KEP4J.js → context-working-set-EUXAZI6N.js} +8 -8
  73. package/dist/{dispatch-runner-GIJBHNFL.js → dispatch-runner-B7MTOVKL.js} +313 -53
  74. package/dist/{docs-6FZSCG5B.js → docs-FLJTIDSE.js} +4 -4
  75. package/dist/{doctor-SVJ5BZCW.js → doctor-RN4YKO2X.js} +14 -14
  76. package/dist/{eval-CG6LLBLD.js → eval-RUBJVSNQ.js} +8 -7
  77. package/dist/{evidence-ZYFIEN42.js → evidence-JZNBUOQZ.js} +30 -25
  78. package/dist/{evolve-QGEXEMDW.js → evolve-FJVC4KKI.js} +30 -25
  79. package/dist/{extensions-ADGNCJJD.js → extensions-IQL36S7K.js} +4 -4
  80. package/dist/{fleet-S5R4ZOQY.js → fleet-BDKYJFCP.js} +214 -360
  81. package/dist/fleet-commands-ZFIWZSB3.js +70 -0
  82. package/dist/fleet-graph-Y6HPXIVF.js +125 -0
  83. package/dist/fleet-new-RDVJLHHH.js +48 -0
  84. package/dist/fleet-validate-BIYREGIK.js +79 -0
  85. package/dist/{init-5DRU55YR.js → init-LQUB5COQ.js} +44 -37
  86. package/dist/library-NJAHIGG4.js +217 -0
  87. package/dist/{memory-7YKKR6UC.js → memory-OG6HOYKM.js} +31 -26
  88. package/dist/{models-ZPOLRU2C.js → models-5ZG5XY7J.js} +21 -20
  89. package/dist/{monitor-US5F5YGZ.js → monitor-TJ7AMTGB.js} +49 -30
  90. package/dist/{orchestrator-E2AL4T5N.js → orchestrator-WZYB54DM.js} +3827 -581
  91. package/dist/{paths-E7KYAQWE.js → paths-XUC7GS6E.js} +4 -4
  92. package/dist/{reset-KZ652EK6.js → reset-PXQT45IY.js} +7 -7
  93. package/dist/{run-SRNBKDWD.js → run-FQ74YF62.js} +53 -45
  94. package/dist/{share-CGZE33UP.js → share-FW7SVCL3.js} +33 -9
  95. package/dist/{skills-S2X4DLY5.js → skills-7E7IRB3R.js} +24 -8
  96. package/dist/{skills-eval-W2GGIC4R.js → skills-eval-LI75W6OK.js} +34 -27
  97. package/dist/{targets-54SWINWB.js → targets-4CIFKCTW.js} +23 -22
  98. package/dist/{terminal-lease-SAIF2OGY.js → terminal-lease-WUZY7ZV5.js} +4 -4
  99. package/dist/{uninstall-BVLWXKBT.js → uninstall-7FV7IP4E.js} +4 -4
  100. package/dist/{upgrade-JKAR27XC.js → upgrade-K2HVIVMQ.js} +20 -19
  101. package/dist/{usage-MSAWCLX4.js → usage-GTZELZQX.js} +116 -49
  102. package/dist/verifiers-RLAHT27O.js +336 -0
  103. package/dist/{verify-X5HDROLA.js → verify-BX3BRKH5.js} +7 -6
  104. package/dist/{wiki-generate-GUSOQ6ZP.js → wiki-generate-ASIFASCN.js} +45 -37
  105. package/dist/worker/entry.js +38 -35
  106. package/docs/README.md +3 -2
  107. package/docs/acp.md +1 -1
  108. package/docs/alcf-provider.md +1 -1
  109. package/docs/architecture.md +2 -2
  110. package/docs/artifact-versions.md +10 -6
  111. package/docs/built-in-agents.md +26 -2
  112. package/docs/capacity-and-scheduling.md +1 -1
  113. package/docs/commands-and-modes.md +82 -2
  114. package/docs/configuration-and-targets.md +79 -2
  115. package/docs/context-engine.md +1 -1
  116. package/docs/development-pipeline.md +1 -1
  117. package/docs/dispatch-architecture-rationale.md +1 -1
  118. package/docs/documentation-coverage.md +3 -3
  119. package/docs/documentation-guide.md +3 -3
  120. package/docs/eval-runner.md +1 -1
  121. package/docs/evals-internal.md +1 -1
  122. package/docs/evidence-and-memory.md +5 -5
  123. package/docs/evolution.md +1 -1
  124. package/docs/exit-codes-and-output.md +4 -1
  125. package/docs/extensions-and-sharing.md +6 -2
  126. package/docs/fleet-demo-runbook.md +2 -2
  127. package/docs/fleet-dispatch.md +197 -10
  128. package/docs/git-commit-provenance.md +2 -2
  129. package/docs/glossary.md +1 -1
  130. package/docs/installation-and-lifecycle.md +2 -2
  131. package/docs/middleware-and-components.md +2 -1
  132. package/docs/model-catalog.md +1 -1
  133. package/docs/observability.md +55 -8
  134. package/docs/proactive-memory.md +1 -1
  135. package/docs/prompt-envelope-and-tools.md +1 -1
  136. package/docs/provider-adapter-cookbook.md +1 -1
  137. package/docs/release-cut-checklist.md +79 -64
  138. package/docs/resource-library.md +59 -0
  139. package/docs/safety-model.md +2 -2
  140. package/docs/scientific-validation.md +3 -3
  141. package/docs/session-lifecycle.md +37 -1
  142. package/docs/skills-marketplace.md +16 -3
  143. package/docs/tool-usage.md +14 -7
  144. package/docs/trace-store.md +1 -1
  145. package/docs/troubleshooting.md +1 -1
  146. package/docs/tui-design.md +1 -1
  147. package/docs/worker-dispatch-mechanics.md +3 -3
  148. package/package.json +1 -1
  149. package/src/cli/fleet-commands.ts +37 -0
  150. package/src/cli/fleet-graph.ts +102 -0
  151. package/src/cli/fleet-new.ts +36 -0
  152. package/src/cli/fleet-preflight.ts +121 -0
  153. package/src/cli/fleet-validate.ts +30 -0
  154. package/src/cli/fleet.ts +173 -335
  155. package/src/cli/index.ts +3 -1
  156. package/src/cli/library.ts +190 -0
  157. package/src/cli/share.ts +13 -1
  158. package/src/cli/usage.ts +111 -19
  159. package/src/core/bus-events.ts +4 -0
  160. package/src/core/commit-attribution.ts +4 -4
  161. package/src/core/config.ts +130 -0
  162. package/src/core/defaults.ts +81 -0
  163. package/src/domains/agents/builtins/architect.md +1 -0
  164. package/src/domains/agents/builtins/oracle.md +33 -0
  165. package/src/domains/agents/catalog.ts +13 -1
  166. package/src/domains/agents/fleet-contract.ts +278 -16
  167. package/src/domains/agents/index.ts +14 -0
  168. package/src/domains/agents/result-contract.ts +235 -1
  169. package/src/domains/config/classify.ts +4 -0
  170. package/src/domains/dispatch/active-route-planner.ts +14 -0
  171. package/src/domains/dispatch/backoff.ts +2 -1
  172. package/src/domains/dispatch/capability-match.ts +1 -0
  173. package/src/domains/dispatch/checkout-writer-lease.ts +175 -0
  174. package/src/domains/dispatch/contract.ts +34 -0
  175. package/src/domains/dispatch/delegation-plan.ts +167 -0
  176. package/src/domains/dispatch/execution-plan.ts +76 -5
  177. package/src/domains/dispatch/execution-role.ts +3 -1
  178. package/src/domains/dispatch/execution-scheduler.ts +183 -67
  179. package/src/domains/dispatch/extension.ts +258 -9
  180. package/src/domains/dispatch/fleet-gate.ts +14 -0
  181. package/src/domains/dispatch/fleet-plan.ts +63 -3
  182. package/src/domains/dispatch/fleet-run.ts +737 -0
  183. package/src/domains/dispatch/gate-role-prompts.ts +9 -0
  184. package/src/domains/dispatch/host-verification.ts +178 -0
  185. package/src/domains/dispatch/index.ts +38 -0
  186. package/src/domains/dispatch/intent.ts +159 -0
  187. package/src/domains/dispatch/receipt-integrity.ts +8 -4
  188. package/src/domains/dispatch/state.ts +36 -3
  189. package/src/domains/dispatch/types.ts +51 -6
  190. package/src/domains/dispatch/validation.ts +66 -6
  191. package/src/domains/evidence/trust-status.ts +10 -1
  192. package/src/domains/middleware/index.ts +15 -0
  193. package/src/domains/middleware/watchdog.ts +281 -0
  194. package/src/domains/observability/contract.ts +3 -1
  195. package/src/domains/observability/cost.ts +12 -1
  196. package/src/domains/observability/extension.ts +2 -2
  197. package/src/domains/observability/index.ts +10 -0
  198. package/src/domains/observability/out-of-turn-usage.ts +223 -0
  199. package/src/domains/resources/index.ts +20 -0
  200. package/src/domains/resources/library.ts +326 -0
  201. package/src/domains/resources/skills/marketplace.ts +37 -12
  202. package/src/domains/session/handoff.ts +629 -0
  203. package/src/domains/share/archive.ts +67 -2
  204. package/src/entry/orchestrator.ts +37 -0
  205. package/src/interactive/bus-notices.ts +26 -0
  206. package/src/interactive/chat-loop.ts +235 -1
  207. package/src/interactive/chat-renderer.ts +22 -0
  208. package/src/interactive/cost-overlay.ts +31 -3
  209. package/src/interactive/council-dispatch.ts +30 -0
  210. package/src/interactive/council-grid.ts +213 -0
  211. package/src/interactive/council.ts +99 -0
  212. package/src/interactive/dispatch-board.ts +260 -16
  213. package/src/interactive/fleet-run-preview.ts +307 -0
  214. package/src/interactive/footer/notifications.ts +219 -0
  215. package/src/interactive/handoff-round.ts +56 -0
  216. package/src/interactive/interactive-application.ts +43 -1
  217. package/src/interactive/interactive-event-projection.ts +9 -1
  218. package/src/interactive/interactive-slash-runtime.ts +52 -2
  219. package/src/interactive/interactive-subscriptions.ts +14 -2
  220. package/src/interactive/oracle.ts +179 -0
  221. package/src/interactive/overlay-ask-user-lifecycle.ts +6 -0
  222. package/src/interactive/overlay-general-openers.ts +190 -1
  223. package/src/interactive/overlay-key-routing.ts +17 -1
  224. package/src/interactive/overlay-lifecycle.ts +41 -1
  225. package/src/interactive/overlay-permission-lifecycle.ts +10 -0
  226. package/src/interactive/overlay-resource-openers.ts +11 -3
  227. package/src/interactive/overlay-session-lifecycle.ts +234 -2
  228. package/src/interactive/overlays/fleet-run-approval.ts +208 -0
  229. package/src/interactive/overlays/handoff-review.ts +185 -0
  230. package/src/interactive/overlays/library-install-confirm.ts +151 -0
  231. package/src/interactive/overlays/list-overlay.ts +168 -2
  232. package/src/interactive/overlays/settings.ts +101 -4
  233. package/src/interactive/overlays/side-question.ts +139 -0
  234. package/src/interactive/overlays/skills-hub.ts +401 -15
  235. package/src/interactive/side-question.ts +171 -0
  236. package/src/interactive/slash-commands.ts +432 -5
  237. package/src/interactive/slash-spec.ts +19 -6
  238. package/src/interactive/theme/tokens.ts +30 -0
  239. package/src/interactive/turn-middleware.ts +15 -1
  240. package/src/interactive/watchdog-run.ts +75 -0
  241. package/src/interactive/worker-share.ts +56 -1
  242. package/src/interactive/worker-stream.ts +7 -0
  243. package/src/tools/bootstrap.ts +3 -0
  244. package/src/tools/compete-worktrees.ts +13 -79
  245. package/src/tools/dispatch-admission.ts +242 -8
  246. package/src/tools/dispatch-arguments.ts +57 -1
  247. package/src/tools/dispatch-plan.ts +136 -6
  248. package/src/tools/dispatch-runner.ts +319 -13
  249. package/src/tools/dispatch-types.ts +20 -1
  250. package/src/tools/dispatch.ts +72 -2
  251. package/src/tools/monitor.ts +16 -0
  252. package/src/tools/profiles.ts +18 -4
  253. package/src/tools/task-worktree.ts +238 -0
  254. package/src/tools/verify/authoring.ts +61 -1
  255. package/src/tools/verify/scripts.ts +62 -0
  256. package/src/tools/worker-evidence.ts +2 -1
  257. package/src/worker/spec-contract.ts +1 -0
  258. package/dist/chunk-HC4CLZ2Y.js +0 -68
@@ -0,0 +1,843 @@
1
+ import { createRequire as __clioCreateRequire } from "node:module"; const require = __clioCreateRequire(import.meta.url);
2
+ import {
3
+ AGENT_AUTOMATION_AUTHORITIES
4
+ } from "./chunk-AOCYTWAV.js";
5
+ import {
6
+ init_esm_shims
7
+ } from "./chunk-3R73A4XB.js";
8
+
9
+ // src/core/json-payload.ts
10
+ init_esm_shims();
11
+ function jsonPayloadCandidates(text) {
12
+ const trimmed = text.trim();
13
+ const candidates = [trimmed];
14
+ const fenced = /```[A-Za-z0-9_-]*\s*\n?([\s\S]*?)```/.exec(trimmed)?.[1]?.trim();
15
+ if (fenced !== void 0 && fenced.length > 0) candidates.push(fenced);
16
+ const start = trimmed.indexOf("{");
17
+ const end = trimmed.lastIndexOf("}");
18
+ if (start >= 0 && end > start) candidates.push(trimmed.slice(start, end + 1));
19
+ return candidates;
20
+ }
21
+ function parseJsonObjectPayload(text) {
22
+ let parsedSomething = false;
23
+ for (const candidate of jsonPayloadCandidates(text)) {
24
+ let value;
25
+ try {
26
+ value = JSON.parse(candidate);
27
+ } catch {
28
+ continue;
29
+ }
30
+ parsedSomething = true;
31
+ if (value === null || typeof value !== "object" || Array.isArray(value)) continue;
32
+ return { ok: true, value };
33
+ }
34
+ return { ok: false, reason: parsedSomething ? "not-object" : "not-json" };
35
+ }
36
+
37
+ // src/domains/agents/result-contract.ts
38
+ init_esm_shims();
39
+ import { createHash } from "node:crypto";
40
+ import path from "node:path";
41
+ function parseDelegationPlanResult(output) {
42
+ const parsed = parseJson(output);
43
+ if (!parsed.ok || !hasOnlyKeys(parsed.value, ["tasks"]) || !Array.isArray(parsed.value.tasks) || parsed.value.tasks.length === 0)
44
+ return null;
45
+ const tasks = [];
46
+ for (const raw of parsed.value.tasks) {
47
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
48
+ const task = raw;
49
+ if (!hasOnlyKeys(task, ["id", "agent", "description", "depends_on", "writes", "mode"]) || !string(task.id) || !string(task.agent) || !string(task.description) || !Array.isArray(task.depends_on) || task.depends_on.some((entry) => !string(entry)) || !Array.isArray(task.writes) || task.writes.some((entry) => !string(entry)) || task.mode !== void 0 && task.mode !== "sequential" && task.mode !== "parallel")
50
+ return null;
51
+ tasks.push({
52
+ id: task.id,
53
+ agent: task.agent,
54
+ description: task.description,
55
+ depends_on: [...task.depends_on],
56
+ writes: [...task.writes],
57
+ ...task.mode !== void 0 ? { mode: task.mode } : {}
58
+ });
59
+ }
60
+ return { tasks };
61
+ }
62
+ function parseCouncilReport(output) {
63
+ if (output === null) return null;
64
+ const parsed = parseJsonObjectPayload(output);
65
+ if (!parsed.ok) return null;
66
+ const value = parsed.value;
67
+ if (!hasOnlyKeys(value, ["members", "synthesis"]) || !Array.isArray(value.members) || value.members.length === 0) {
68
+ return null;
69
+ }
70
+ const members = [];
71
+ for (const raw of value.members) {
72
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
73
+ const member = raw;
74
+ if (!hasOnlyKeys(member, ["label", "runId", "round", "answer", "verdict", "failed"]) || !string(member.label) || !string(member.runId) || !Number.isInteger(member.round) || Number(member.round) < 1 || typeof member.answer !== "string" || member.verdict !== void 0 && !string(member.verdict))
75
+ return null;
76
+ let failed;
77
+ if (member.failed !== void 0) {
78
+ if (member.failed === null || typeof member.failed !== "object" || Array.isArray(member.failed) || !hasOnlyKeys(member.failed, ["reason"]) || !string(member.failed.reason))
79
+ return null;
80
+ failed = { reason: member.failed.reason };
81
+ }
82
+ members.push({
83
+ label: member.label,
84
+ runId: member.runId,
85
+ round: Number(member.round),
86
+ answer: member.answer,
87
+ ...member.verdict !== void 0 ? { verdict: member.verdict } : {},
88
+ ...failed !== void 0 ? { failed } : {}
89
+ });
90
+ }
91
+ if (value.synthesis === null || typeof value.synthesis !== "object" || Array.isArray(value.synthesis)) return null;
92
+ const rawSynthesis = value.synthesis;
93
+ if (!hasOnlyKeys(rawSynthesis, ["kind", "text", "verdict", "tally", "judgeRunId"])) return null;
94
+ if (rawSynthesis.kind !== "none" && rawSynthesis.kind !== "judge" && rawSynthesis.kind !== "vote") return null;
95
+ for (const key of ["text", "verdict", "judgeRunId"]) {
96
+ if (rawSynthesis[key] !== void 0 && !string(rawSynthesis[key])) return null;
97
+ }
98
+ let tally;
99
+ if (rawSynthesis.tally !== void 0) {
100
+ if (rawSynthesis.tally === null || typeof rawSynthesis.tally !== "object" || Array.isArray(rawSynthesis.tally))
101
+ return null;
102
+ tally = {};
103
+ for (const [key, count] of Object.entries(rawSynthesis.tally)) {
104
+ if (!key || !Number.isInteger(count) || Number(count) < 0) return null;
105
+ tally[key] = Number(count);
106
+ }
107
+ }
108
+ return {
109
+ members,
110
+ synthesis: {
111
+ kind: rawSynthesis.kind,
112
+ ...rawSynthesis.text !== void 0 ? { text: rawSynthesis.text } : {},
113
+ ...rawSynthesis.verdict !== void 0 ? { verdict: rawSynthesis.verdict } : {},
114
+ ...tally !== void 0 ? { tally } : {},
115
+ ...rawSynthesis.judgeRunId !== void 0 ? { judgeRunId: rawSynthesis.judgeRunId } : {}
116
+ }
117
+ };
118
+ }
119
+ function canonical(value) {
120
+ if (value === null) return "null";
121
+ if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
122
+ if (typeof value === "number") {
123
+ if (!Number.isFinite(value)) throw new Error("result contract cannot digest non-finite numbers");
124
+ return JSON.stringify(value);
125
+ }
126
+ if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
127
+ if (typeof value === "object") {
128
+ const record = value;
129
+ return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonical(record[key])}`).join(",")}}`;
130
+ }
131
+ throw new Error(`result contract cannot digest ${typeof value}`);
132
+ }
133
+ function digest(value) {
134
+ return createHash("sha256").update(canonical(value), "utf8").digest("hex");
135
+ }
136
+ function resultContractDigest(contract) {
137
+ return digest(contract);
138
+ }
139
+ function resultContractSourceId(contract) {
140
+ return `agent-result-contract:${contract.kind}:${resultContractDigest(contract)}`;
141
+ }
142
+ function failure(contract, quality, reason) {
143
+ return {
144
+ conformance: "fail",
145
+ quality,
146
+ sourceId: resultContractSourceId(contract),
147
+ validatorDigest: digest({ contract, reason }),
148
+ reason
149
+ };
150
+ }
151
+ function success(contract, quality, value, extra = {}) {
152
+ return {
153
+ conformance: "pass",
154
+ quality,
155
+ sourceId: resultContractSourceId(contract),
156
+ validatorDigest: digest({ contract, value }),
157
+ ...extra
158
+ };
159
+ }
160
+ function parseJson(output) {
161
+ if (output === null || output.trim().length === 0) return { ok: false, reason: "missing final result" };
162
+ const parsed = parseJsonObjectPayload(output);
163
+ if (parsed.ok) return parsed;
164
+ return {
165
+ ok: false,
166
+ reason: parsed.reason === "not-object" ? "result must be a JSON object" : "result must be valid JSON"
167
+ };
168
+ }
169
+ function hasOnlyKeys(value, keys) {
170
+ const allowed = new Set(keys);
171
+ return Object.keys(value).every((key) => allowed.has(key));
172
+ }
173
+ function string(value) {
174
+ return typeof value === "string" && value.trim().length > 0;
175
+ }
176
+ function parseFindings(value) {
177
+ if (!Array.isArray(value)) return null;
178
+ const findings = [];
179
+ for (const entry of value) {
180
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return null;
181
+ const finding = entry;
182
+ const line = finding.line;
183
+ if (!hasOnlyKeys(finding, ["claim", "path", "line"]) || !string(finding.claim) || !string(finding.path) || typeof line !== "number" || !Number.isSafeInteger(line) || line < 1) {
184
+ return null;
185
+ }
186
+ findings.push({ claim: finding.claim, path: finding.path, line });
187
+ }
188
+ return findings;
189
+ }
190
+ var RESULT_CONTRACT_KINDS = [
191
+ "architect-plan",
192
+ "scout-report",
193
+ "verifier-report",
194
+ "council-report",
195
+ "debugger-report",
196
+ "research-report",
197
+ "mutation-report",
198
+ "provenance-report",
199
+ "external-delegation"
200
+ ];
201
+ function parseSubtasks(value) {
202
+ if (!Array.isArray(value) || value.length > 4) return null;
203
+ const subtasks = [];
204
+ const ids = /* @__PURE__ */ new Set();
205
+ for (const entry of value) {
206
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return null;
207
+ const subtask = entry;
208
+ if (!hasOnlyKeys(subtask, ["id", "task", "dependencies", "expectedResultContract", "requestedAuthority"]) || !string(subtask.id) || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u.test(subtask.id) || ids.has(subtask.id) || !string(subtask.task) || Buffer.byteLength(subtask.task, "utf8") > 4096 || !Array.isArray(subtask.dependencies) || subtask.dependencies.length > 4 || subtask.dependencies.some((dependency) => !string(dependency)) || new Set(subtask.dependencies).size !== subtask.dependencies.length || !RESULT_CONTRACT_KINDS.includes(subtask.expectedResultContract) || !AGENT_AUTOMATION_AUTHORITIES.includes(subtask.requestedAuthority)) {
209
+ return null;
210
+ }
211
+ ids.add(subtask.id);
212
+ subtasks.push({
213
+ id: subtask.id,
214
+ task: subtask.task,
215
+ dependencies: [...subtask.dependencies],
216
+ expectedResultContract: subtask.expectedResultContract,
217
+ requestedAuthority: subtask.requestedAuthority
218
+ });
219
+ }
220
+ for (const subtask of subtasks) {
221
+ if (subtask.dependencies.some((dependency) => dependency === subtask.id || !ids.has(dependency))) return null;
222
+ }
223
+ const remaining = new Set(ids);
224
+ const completed = /* @__PURE__ */ new Set();
225
+ while (remaining.size > 0) {
226
+ const ready = subtasks.filter(
227
+ (subtask) => remaining.has(subtask.id) && subtask.dependencies.every((dependency) => completed.has(dependency))
228
+ );
229
+ if (ready.length === 0) return null;
230
+ for (const subtask of ready) {
231
+ remaining.delete(subtask.id);
232
+ completed.add(subtask.id);
233
+ }
234
+ }
235
+ return subtasks;
236
+ }
237
+ function isContextHandbookResult(value) {
238
+ if (!hasOnlyKeys(value, ["projectName", "identity", "conventions", "invariants", "sections"])) return false;
239
+ if (!string(value.projectName) || !string(value.identity)) return false;
240
+ if (!Array.isArray(value.conventions) || value.conventions.some((entry) => !string(entry))) return false;
241
+ if (!Array.isArray(value.invariants) || value.invariants.some((entry) => !string(entry))) return false;
242
+ if (!Array.isArray(value.sections)) return false;
243
+ return value.sections.every((entry) => {
244
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return false;
245
+ const section = entry;
246
+ return hasOnlyKeys(section, ["title", "body"]) && string(section.title) && string(section.body);
247
+ });
248
+ }
249
+ function validateContextHandbook(contract, output) {
250
+ const parsed = parseJson(output);
251
+ if (!parsed.ok) return failure(contract, "fail", parsed.reason);
252
+ if (!isContextHandbookResult(parsed.value)) {
253
+ return failure(
254
+ contract,
255
+ "fail",
256
+ "context handbook result must carry projectName, identity, conventions[], invariants[], and sections[{title, body}] and nothing else"
257
+ );
258
+ }
259
+ return success(contract, "unmeasured", parsed.value);
260
+ }
261
+ function salvageScoutClaims(value) {
262
+ const grounded = [];
263
+ const ungrounded = [];
264
+ if (!Array.isArray(value)) return { grounded, ungrounded };
265
+ for (const entry of value) {
266
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) continue;
267
+ const finding = entry;
268
+ if (!string(finding.claim)) continue;
269
+ const line = finding.line;
270
+ if (string(finding.path) && typeof line === "number" && Number.isSafeInteger(line) && line >= 1) {
271
+ grounded.push({ claim: finding.claim, path: finding.path, line });
272
+ continue;
273
+ }
274
+ ungrounded.push(finding.claim);
275
+ }
276
+ return { grounded, ungrounded };
277
+ }
278
+ function degradedScout(contract, value, reason) {
279
+ const salvaged = salvageScoutClaims(value.findings);
280
+ if (salvaged.grounded.length === 0 && salvaged.ungrounded.length === 0) return null;
281
+ const degradedReason = `${reason} (accepted as a degraded reconnaissance result; findings are leads, not validation evidence)`;
282
+ const scout = {
283
+ findings: salvaged.grounded,
284
+ citations: salvaged.grounded.map(({ path: citedPath, line }) => ({ path: citedPath, line })),
285
+ needsSplit: false,
286
+ proposedSubtasks: [],
287
+ ungroundedClaims: salvaged.ungrounded,
288
+ degradedReason
289
+ };
290
+ return success(contract, "unmeasured", scout, { scout, reason: degradedReason });
291
+ }
292
+ function validateScout(contract, output) {
293
+ const parsed = parseJson(output);
294
+ if (!parsed.ok) return failure(contract, "fail", parsed.reason);
295
+ const value = parsed.value;
296
+ const degrade = (reason) => degradedScout(contract, value, reason) ?? failure(contract, "fail", reason);
297
+ if (!hasOnlyKeys(value, ["findings", "needsSplit", "proposedSubtasks"])) {
298
+ return degrade("Scout result has unknown fields");
299
+ }
300
+ const findings = parseFindings(value.findings);
301
+ const proposedSubtasks = parseSubtasks(value.proposedSubtasks);
302
+ if (findings === null || typeof value.needsSplit !== "boolean" || proposedSubtasks === null) {
303
+ return degrade(
304
+ "Scout result must carry findings as {claim, path, line} objects, needsSplit, and 0..4 typed proposed subtasks"
305
+ );
306
+ }
307
+ if (value.needsSplit !== proposedSubtasks.length > 0) {
308
+ return degrade("Scout needsSplit must agree with proposedSubtasks");
309
+ }
310
+ if (findings.length === 0 && !value.needsSplit) {
311
+ return degrade("Scout result must carry at least one cited finding, or set needsSplit");
312
+ }
313
+ if (value.needsSplit && findings.length > 0) {
314
+ return degrade("Scout split recommendations carry typed subtasks instead of findings");
315
+ }
316
+ const scout = {
317
+ findings,
318
+ citations: findings.map(({ path: citedPath, line }) => ({ path: citedPath, line })),
319
+ needsSplit: value.needsSplit,
320
+ proposedSubtasks
321
+ };
322
+ return success(contract, "pass", scout, { scout });
323
+ }
324
+ function parseChecks(value) {
325
+ if (!Array.isArray(value) || value.length === 0) return null;
326
+ const checks = [];
327
+ for (const entry of value) {
328
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return null;
329
+ const check = entry;
330
+ if (!hasOnlyKeys(check, ["name", "passed", "evidence"]) || !string(check.name) || typeof check.passed !== "boolean" || !string(check.evidence)) {
331
+ return null;
332
+ }
333
+ checks.push({ name: check.name, passed: check.passed, evidence: check.evidence });
334
+ }
335
+ return checks;
336
+ }
337
+ function validateScoutCitation(input, citation) {
338
+ const cwd = path.resolve(input.cwd);
339
+ const citedPath = path.resolve(cwd, citation.path);
340
+ const relative = path.relative(cwd, citedPath);
341
+ if (relative === "" || relative.startsWith(`..${path.sep}`) || relative === ".." || path.isAbsolute(relative)) {
342
+ return { ok: false, reason: `Scout citation path escapes the workspace: ${citation.path}` };
343
+ }
344
+ const content = input.filesystem.readFile(citedPath);
345
+ if (content === null) return { ok: false, reason: `Scout citation cannot be read: ${citation.path}` };
346
+ const lineCount = content.split(/\r\n|\r|\n/u).length;
347
+ if (citation.line > lineCount) {
348
+ return { ok: false, reason: `Scout citation is past end of file: ${citation.path}:${citation.line}` };
349
+ }
350
+ if (input.observedReadRanges !== void 0) {
351
+ const spans = input.observedReadRanges.get(citedPath) ?? [];
352
+ if (!spans.some(([start, end]) => citation.line >= start && citation.line <= end)) {
353
+ const observed = spans.length === 0 ? "this run never read that file" : `this run read only ${spans.map(([start, end]) => `${start}-${end}`).join(", ")}`;
354
+ return {
355
+ ok: false,
356
+ reason: `Scout citation is not grounded in a live read: ${citation.path}:${citation.line} (${observed})`
357
+ };
358
+ }
359
+ }
360
+ return {
361
+ ok: true,
362
+ evidence: { ...citation, contentDigest: createHash("sha256").update(content, "utf8").digest("hex") }
363
+ };
364
+ }
365
+ function validateScoutCitations(input, citations) {
366
+ const evidence = [];
367
+ for (const citation of citations) {
368
+ const checked = validateScoutCitation(input, citation);
369
+ if (!checked.ok) return checked;
370
+ evidence.push(checked.evidence);
371
+ }
372
+ return { ok: true, evidence };
373
+ }
374
+ function groundDegradedScout(contract, input, scout, degradedReason) {
375
+ const grounded = [];
376
+ const evidence = [];
377
+ const demoted = [];
378
+ for (const finding of scout.findings) {
379
+ const checked = validateScoutCitation(input, { path: finding.path, line: finding.line });
380
+ if (checked.ok) {
381
+ grounded.push(finding);
382
+ evidence.push(checked.evidence);
383
+ continue;
384
+ }
385
+ demoted.push(finding.claim);
386
+ }
387
+ const degraded = {
388
+ findings: grounded,
389
+ citations: grounded.map(({ path: citedPath, line }) => ({ path: citedPath, line })),
390
+ needsSplit: false,
391
+ proposedSubtasks: [],
392
+ ungroundedClaims: [...scout.ungroundedClaims ?? [], ...demoted],
393
+ degradedReason
394
+ };
395
+ return success(contract, "unmeasured", { scout: degraded, evidence }, { scout: degraded, reason: degradedReason });
396
+ }
397
+ function validateVerifier(contract, output) {
398
+ const parsed = parseJson(output);
399
+ if (!parsed.ok) return failure(contract, "fail", parsed.reason);
400
+ const value = parsed.value;
401
+ if (!hasOnlyKeys(value, ["verdict", "checks"]) || value.verdict !== "pass" && value.verdict !== "fail") {
402
+ return failure(contract, "fail", "Verifier result must carry pass or fail verdict and checks");
403
+ }
404
+ const checks = parseChecks(value.checks);
405
+ if (checks === null || value.verdict === "pass" !== checks.every((check) => check.passed)) {
406
+ return failure(contract, "fail", "Verifier verdict must agree with every typed check");
407
+ }
408
+ const verifier = { verdict: value.verdict, checks };
409
+ return success(contract, value.verdict, verifier, { verifier });
410
+ }
411
+ function parseVerifierResult(output) {
412
+ const validation = validateVerifier({ kind: "verifier-report" }, output);
413
+ return validation.verifier ?? null;
414
+ }
415
+ function validateOracle(contract, output) {
416
+ const parsed = parseJson(output);
417
+ if (!parsed.ok) return failure(contract, "unmeasured", parsed.reason);
418
+ const value = parsed.value;
419
+ if (!hasOnlyKeys(value, ["verdict", "challenge", "changesMyMind", "citedDecisions"]) || !string(value.verdict) || !string(value.challenge) || !string(value.changesMyMind) || !Array.isArray(value.citedDecisions) || value.citedDecisions.some((entry) => !string(entry))) {
420
+ return failure(
421
+ contract,
422
+ "unmeasured",
423
+ 'Oracle result must carry verdict, challenge, changesMyMind, and a citedDecisions array of strings, for example {"verdict":"consistent with decision routing.target","challenge":"...","changesMyMind":"...","citedDecisions":["routing.target"]}'
424
+ );
425
+ }
426
+ return success(contract, "unmeasured", value);
427
+ }
428
+ function parseOracleResult(output) {
429
+ const validation = validateOracle({ kind: "oracle-report" }, output);
430
+ if (validation.conformance !== "pass") return null;
431
+ const parsed = parseJson(output);
432
+ if (!parsed.ok) return null;
433
+ return {
434
+ verdict: String(parsed.value.verdict),
435
+ challenge: String(parsed.value.challenge),
436
+ changesMyMind: String(parsed.value.changesMyMind),
437
+ citedDecisions: parsed.value.citedDecisions.map((entry) => String(entry))
438
+ };
439
+ }
440
+ function validateCodeReport(contract, output) {
441
+ const parsed = parseJson(output);
442
+ if (!parsed.ok) return failure(contract, "unmeasured", parsed.reason);
443
+ const value = parsed.value;
444
+ if (!hasOnlyKeys(value, ["passed", "exitCode", "checks", "artifactPaths", "outputExcerpt"]) || typeof value.passed !== "boolean" || typeof value.exitCode !== "number" || !Number.isSafeInteger(value.exitCode) || typeof value.outputExcerpt !== "string" || !Array.isArray(value.artifactPaths) || value.artifactPaths.some((entry) => !string(entry))) {
445
+ return failure(
446
+ contract,
447
+ "unmeasured",
448
+ "Code result must carry passed, integer exitCode, checks, artifactPaths, and outputExcerpt"
449
+ );
450
+ }
451
+ const checks = parseChecks(value.checks);
452
+ if (checks === null) return failure(contract, "unmeasured", "Code result must carry typed checks");
453
+ if (value.passed !== (value.exitCode === 0) || value.passed !== checks.every((check) => check.passed)) {
454
+ return failure(contract, "unmeasured", "Code result passed must agree with its exit code and every check");
455
+ }
456
+ return success(contract, "unmeasured", value);
457
+ }
458
+ var RESULT_COMMIT_MESSAGE_MAX_BYTES = 1e3;
459
+ var AUTHORSHIP_FIELDS = ["commitMessage", "summary"];
460
+ function hasControlCharacters(value) {
461
+ for (const character of value) {
462
+ const code = character.codePointAt(0) ?? 0;
463
+ if (code === 127) return true;
464
+ if (code < 32 && character !== "\n" && character !== "\r" && character !== " ") return true;
465
+ }
466
+ return false;
467
+ }
468
+ function normalizeAuthored(value) {
469
+ return value.replace(/\r\n/gu, "\n").replace(/\r/gu, "\n").trim();
470
+ }
471
+ function validateAuthorship(value) {
472
+ for (const field of AUTHORSHIP_FIELDS) {
473
+ const raw = value[field];
474
+ if (raw === void 0 || raw === null) continue;
475
+ if (typeof raw !== "string") return `${field} must be a string when present`;
476
+ if (raw.trim().length === 0) continue;
477
+ if (Buffer.byteLength(raw, "utf8") > RESULT_COMMIT_MESSAGE_MAX_BYTES) {
478
+ return `${field} must be at most ${RESULT_COMMIT_MESSAGE_MAX_BYTES} bytes`;
479
+ }
480
+ if (hasControlCharacters(raw)) return `${field} must not contain control characters`;
481
+ }
482
+ return null;
483
+ }
484
+ function resultContractAuthorship(contract, output) {
485
+ const empty = { commitMessage: null, summary: null };
486
+ if (contract.kind !== "mutation-report" && contract.kind !== "architect-plan") return empty;
487
+ const parsed = parseJson(output);
488
+ if (!parsed.ok || validateAuthorship(parsed.value) !== null) return empty;
489
+ const read = (field) => {
490
+ const raw = parsed.value[field];
491
+ if (typeof raw !== "string") return null;
492
+ const normalized = normalizeAuthored(raw);
493
+ return normalized.length === 0 ? null : normalized;
494
+ };
495
+ return { commitMessage: read("commitMessage"), summary: read("summary") };
496
+ }
497
+ function validateDebugger(contract, output) {
498
+ const parsed = parseJson(output);
499
+ if (!parsed.ok) return failure(contract, "unmeasured", parsed.reason);
500
+ const value = parsed.value;
501
+ if (!hasOnlyKeys(value, ["diagnosis", "reproduction", "evidence"]) || !string(value.diagnosis) || value.reproduction !== "reproduced" && value.reproduction !== "not-reproduced" && value.reproduction !== "unknown" || !Array.isArray(value.evidence) || value.evidence.some((entry) => !string(entry))) {
502
+ return failure(
503
+ contract,
504
+ "unmeasured",
505
+ "Debugger result must carry diagnosis, reproduction status, and evidence without a verdict"
506
+ );
507
+ }
508
+ return success(contract, "unmeasured", value);
509
+ }
510
+ function validateResearch(contract, output, networkAllowed) {
511
+ const parsed = parseJson(output);
512
+ if (!parsed.ok) return failure(contract, "unmeasured", parsed.reason);
513
+ const value = parsed.value;
514
+ if (!hasOnlyKeys(value, ["source", "findings"]) || value.source !== "local" && value.source !== "external" || !Array.isArray(value.findings)) {
515
+ return failure(
516
+ contract,
517
+ "unmeasured",
518
+ "Research result must distinguish local or external sources and carry findings"
519
+ );
520
+ }
521
+ if (value.source === "external" && !networkAllowed) {
522
+ return failure(contract, "unmeasured", "external research requires an allowed network posture");
523
+ }
524
+ for (const finding of value.findings) {
525
+ if (finding === null || typeof finding !== "object" || Array.isArray(finding)) {
526
+ return failure(contract, "unmeasured", "Research findings must be objects");
527
+ }
528
+ const record = finding;
529
+ if (!hasOnlyKeys(record, ["claim", "evidence"]) || !string(record.claim) || !string(record.evidence)) {
530
+ return failure(contract, "unmeasured", "Research findings must carry claim and evidence");
531
+ }
532
+ }
533
+ return success(contract, "unmeasured", value);
534
+ }
535
+ function describeWriteSet(effects, cwd) {
536
+ if (effects.mutatedPaths.size === 0) return "this run wrote nothing";
537
+ const written = [...effects.mutatedPaths].map((target) => path.relative(cwd, target) || target).sort().slice(0, MUTATION_WRITE_SET_REASON_LIMIT);
538
+ const more = effects.mutatedPaths.size - written.length;
539
+ return `this run wrote ${written.join(", ")}${more > 0 ? ` (+${more} more)` : ""}`;
540
+ }
541
+ var MUTATION_WRITE_SET_REASON_LIMIT = 8;
542
+ function pathIsPresent(filesystem, target) {
543
+ if (filesystem.pathExists === void 0) return true;
544
+ return filesystem.pathExists(target);
545
+ }
546
+ var MUTATION_VALIDATION_EXAMPLE = '{"name":"npm test","passed":true,"evidence":"exit 0"}';
547
+ function mutationValidationsReason(value) {
548
+ const empty = Array.isArray(value) && value.length === 0;
549
+ if (empty) {
550
+ return `Mutation result must carry typed validation results: validations was empty. Emit one entry per check this run actually made, each shaped like ${MUTATION_VALIDATION_EXAMPLE}. A run that only read files still names the read and cites what it saw.`;
551
+ }
552
+ return `Mutation result must carry typed validation results: every validations entry is shaped like ${MUTATION_VALIDATION_EXAMPLE}, with a string name, a boolean passed, a string evidence, and no other keys.`;
553
+ }
554
+ function validateMutation(contract, input) {
555
+ const parsed = parseJson(input.output);
556
+ if (!parsed.ok) return failure(contract, "unmeasured", parsed.reason);
557
+ const value = parsed.value;
558
+ if (!hasOnlyKeys(value, ["mutatedPaths", "validations", "commitMessage", "summary"]) || !Array.isArray(value.mutatedPaths) || value.mutatedPaths.some((entry) => !string(entry))) {
559
+ return failure(contract, "unmeasured", "Mutation result must carry mutatedPaths and validations");
560
+ }
561
+ const authorship = validateAuthorship(value);
562
+ if (authorship !== null) return failure(contract, "unmeasured", authorship);
563
+ const validations = parseChecks(value.validations);
564
+ if (validations === null) return failure(contract, "unmeasured", mutationValidationsReason(value.validations));
565
+ const reportedFailure = !validations.every((check) => check.passed);
566
+ const effects = input.observedRunEffects;
567
+ if (effects === void 0) return success(contract, reportedFailure ? "fail" : "pass", value);
568
+ const cwd = path.resolve(input.cwd);
569
+ let unverifiedMutation = false;
570
+ for (const reported of value.mutatedPaths) {
571
+ const target = path.resolve(cwd, reported);
572
+ if (effects.mutatedPaths.has(target)) continue;
573
+ if (effects.failedMutationPaths.has(target)) {
574
+ return failure(
575
+ contract,
576
+ "unmeasured",
577
+ `Mutation result names a path whose only write this run attempted was refused: ${reported} (${describeWriteSet(effects, cwd)})`
578
+ );
579
+ }
580
+ if (pathIsPresent(input.filesystem, target)) {
581
+ unverifiedMutation = true;
582
+ continue;
583
+ }
584
+ return failure(
585
+ contract,
586
+ "unmeasured",
587
+ `Mutation result names a path this run never wrote and that does not exist: ${reported} (${describeWriteSet(effects, cwd)})`
588
+ );
589
+ }
590
+ if (reportedFailure) return success(contract, "fail", value);
591
+ const measured = !unverifiedMutation && effects.validationCommands.size > 0;
592
+ return success(contract, measured ? "pass" : "unmeasured", value);
593
+ }
594
+ function validateProvenance(contract, output) {
595
+ const parsed = parseJson(output);
596
+ if (!parsed.ok) return failure(contract, "unmeasured", parsed.reason);
597
+ const value = parsed.value;
598
+ if (!hasOnlyKeys(value, ["confirmedFacts", "missingEvidence", "nextInspections"]) || ![value.confirmedFacts, value.missingEvidence, value.nextInspections].every(
599
+ (entry) => Array.isArray(entry) && entry.every((item) => string(item))
600
+ )) {
601
+ return failure(
602
+ contract,
603
+ "unmeasured",
604
+ "Provenance result must carry confirmedFacts, missingEvidence, and nextInspections"
605
+ );
606
+ }
607
+ return success(contract, "unmeasured", value);
608
+ }
609
+ function validateArchitect(contract, input) {
610
+ const artifactPath = path.resolve(input.cwd, contract.path);
611
+ const content = input.filesystem.readFile(artifactPath);
612
+ if (content === null || content.trim().length === 0) {
613
+ return failure(contract, "unmeasured", `required plan artifact is missing or empty: ${contract.path}`);
614
+ }
615
+ return success(contract, "unmeasured", {
616
+ path: contract.path,
617
+ artifactDigest: createHash("sha256").update(content, "utf8").digest("hex")
618
+ });
619
+ }
620
+ function parseScoutResult(output) {
621
+ const validation = validateScout({ kind: "scout-report" }, output);
622
+ if (validation.conformance !== "pass" || validation.scout === void 0) return null;
623
+ return validation.scout.degradedReason === void 0 ? validation.scout : null;
624
+ }
625
+ function validateResultContract(input) {
626
+ switch (input.contract.kind) {
627
+ case "architect-plan":
628
+ return validateArchitect(input.contract, input);
629
+ case "scout-report": {
630
+ const validation = validateScout(input.contract, input.output);
631
+ if (validation.scout === void 0) return validation;
632
+ const degradedReason = validation.scout.degradedReason;
633
+ if (degradedReason !== void 0) {
634
+ return groundDegradedScout(input.contract, input, validation.scout, degradedReason);
635
+ }
636
+ const citations = validateScoutCitations(input, validation.scout.citations);
637
+ return citations.ok ? success(
638
+ input.contract,
639
+ "pass",
640
+ { scout: validation.scout, evidence: citations.evidence },
641
+ { scout: validation.scout }
642
+ ) : failure(input.contract, "fail", citations.reason);
643
+ }
644
+ case "verifier-report":
645
+ return validateVerifier(input.contract, input.output);
646
+ case "council-report": {
647
+ const report = parseCouncilReport(input.output);
648
+ return report === null ? failure(input.contract, "fail", "council-report is malformed") : success(input.contract, "unmeasured", { council: report });
649
+ }
650
+ case "debugger-report":
651
+ return validateDebugger(input.contract, input.output);
652
+ case "research-report":
653
+ return validateResearch(input.contract, input.output, input.networkAllowed);
654
+ case "mutation-report":
655
+ return validateMutation(input.contract, input);
656
+ case "provenance-report":
657
+ return validateProvenance(input.contract, input.output);
658
+ case "delegation-plan": {
659
+ const plan = parseDelegationPlanResult(input.output);
660
+ return plan === null ? failure(
661
+ input.contract,
662
+ "fail",
663
+ "delegation-plan must carry tasks with id, agent, description, depends_on, writes, and optional mode"
664
+ ) : success(input.contract, "unmeasured", plan, { delegationPlan: plan });
665
+ }
666
+ case "oracle-report":
667
+ return validateOracle(input.contract, input.output);
668
+ case "external-delegation":
669
+ return success(input.contract, "unmeasured", { external: true });
670
+ case "artifact-report":
671
+ return success(input.contract, "unmeasured", { artifact: true });
672
+ case "context-handbook":
673
+ return validateContextHandbook(input.contract, input.output);
674
+ case "code-report":
675
+ return validateCodeReport(input.contract, input.output);
676
+ }
677
+ }
678
+ function validateRecipeResult(input) {
679
+ if (input.contract === null) return null;
680
+ if (!input.reachedTerminalResult) {
681
+ return {
682
+ applicable: false,
683
+ fact: {
684
+ sourceId: resultContractSourceId(input.contract),
685
+ validatorDigest: digest({ contract: input.contract, reached: false }),
686
+ conformance: "not-reached",
687
+ quality: "unmeasured"
688
+ }
689
+ };
690
+ }
691
+ const validation = validateResultContract({
692
+ contract: input.contract,
693
+ output: input.output,
694
+ cwd: input.cwd,
695
+ networkAllowed: input.networkAllowed,
696
+ filesystem: input.filesystem,
697
+ ...input.observedRunEffects !== void 0 ? { observedRunEffects: input.observedRunEffects } : {}
698
+ });
699
+ return {
700
+ applicable: true,
701
+ validation,
702
+ fact: {
703
+ sourceId: validation.sourceId,
704
+ validatorDigest: validation.validatorDigest,
705
+ conformance: validation.conformance,
706
+ quality: validation.quality
707
+ }
708
+ };
709
+ }
710
+ var RESULT_CONTRACT_REPAIR_LIMIT = 2;
711
+ var RESULT_CONTRACT_ANCHOR_LIMIT = 12;
712
+ function resultContractShape(contract) {
713
+ switch (contract.kind) {
714
+ case "architect-plan":
715
+ return `a plan artifact written to ${contract.path}, then optionally {"commitMessage":"...","summary":"..."} describing it`;
716
+ case "scout-report":
717
+ return '{"findings":[{"claim":"what you observed","path":"src/file.ts","line":1}],"needsSplit":false,"proposedSubtasks":[]} or {"findings":[],"needsSplit":true,"proposedSubtasks":[{"id":"inspect","task":"Inspect the boundary","dependencies":[],"expectedResultContract":"scout-report","requestedAuthority":"read-only"}]} or, if you cannot produce a citation you are sure of, at least {"findings":[{"claim":"what you observed"}]}, which is accepted as an ungrounded lead rather than losing the run';
718
+ case "verifier-report":
719
+ return '{"verdict":"pass","checks":[{"name":"npm run typecheck","passed":true,"evidence":"exit 0"}]}';
720
+ case "council-report":
721
+ return '{"members":[{"label":"alpha","runId":"run-1","round":1,"answer":"..."}],"synthesis":{"kind":"none"}}';
722
+ case "debugger-report":
723
+ return '{"diagnosis":"...","reproduction":"reproduced","evidence":["..."]}';
724
+ case "research-report":
725
+ return '{"source":"local","findings":[{"claim":"...","evidence":"..."}]}';
726
+ case "mutation-report":
727
+ return '{"mutatedPaths":["src/file.ts"],"validations":[{"name":"npm test","passed":true,"evidence":"exit 0"}],"commitMessage":"optional: the commit message for this change","summary":"optional: one line"}';
728
+ case "provenance-report":
729
+ return '{"confirmedFacts":["..."],"missingEvidence":["..."],"nextInspections":["..."]}';
730
+ case "delegation-plan":
731
+ return '{"tasks":[{"id":"build","agent":"coder","description":"Implement the change","depends_on":[],"writes":["src"],"mode":"parallel"}]}';
732
+ case "oracle-report":
733
+ return '{"verdict":"one line","challenge":"the strongest objection you can mount","changesMyMind":"the evidence that would reverse the verdict","citedDecisions":["decision key or task id you relied on"]}';
734
+ case "external-delegation":
735
+ return "any final text";
736
+ case "artifact-report":
737
+ return "any final text; the artifact you wrote at the location the task named is the result";
738
+ case "context-handbook":
739
+ return '{"projectName":"string","identity":"one sentence","conventions":[],"invariants":[],"sections":[{"title":"Architecture","body":"markdown that cites `real/path.ts` tokens"}]}';
740
+ case "code-report":
741
+ return '{"passed":false,"exitCode":1,"checks":[{"name":"test","passed":false,"evidence":"exit 1"}],"artifactPaths":["/path/command.log"],"outputExcerpt":"..."}';
742
+ }
743
+ }
744
+ function resultContractRepairMessage(input) {
745
+ const last = input.attempt >= RESULT_CONTRACT_REPAIR_LIMIT;
746
+ const lines = [
747
+ last ? "FINAL RESULT REQUIRED IN THIS RESPONSE. Your previous response still did not satisfy this run's result contract." : "Your previous response did not satisfy this run's result contract.",
748
+ `Validator reason: ${input.reason}`,
749
+ input.toolsAvailable === true ? "You may use the admitted tools to repair this validator failure, then emit the required terminal result." : "Tool use is over. Answer from the evidence you already gathered.",
750
+ `Emit exactly this shape and nothing else: ${resultContractShape(input.contract)}`,
751
+ "Do not add prose, code fences, or commentary around it. Do not describe work you intend to do next."
752
+ ];
753
+ if (input.anchors.length > 0) {
754
+ lines.push(
755
+ "",
756
+ "Locations you read successfully in this run (use these exact path:line values):",
757
+ ...input.anchors.slice(-RESULT_CONTRACT_ANCHOR_LIMIT).map((anchor) => `- ${anchor}`)
758
+ );
759
+ }
760
+ return lines.join("\n");
761
+ }
762
+ var RESULT_CONTRACT_REPAIR_TOOL = "result_contract";
763
+ function resultContractRepairMessages(input, origin) {
764
+ const id = `clio-result-contract-repair-${input.attempt}`;
765
+ const timestamp = Date.now();
766
+ return [
767
+ {
768
+ role: "assistant",
769
+ content: [{ type: "toolCall", id, name: RESULT_CONTRACT_REPAIR_TOOL, arguments: {} }],
770
+ stopReason: "toolUse",
771
+ usage: {
772
+ input: 0,
773
+ output: 0,
774
+ cacheRead: 0,
775
+ cacheWrite: 0,
776
+ totalTokens: 0,
777
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
778
+ },
779
+ ...origin,
780
+ timestamp
781
+ },
782
+ {
783
+ role: "toolResult",
784
+ toolCallId: id,
785
+ toolName: RESULT_CONTRACT_REPAIR_TOOL,
786
+ content: [{ type: "text", text: resultContractRepairMessage(input) }],
787
+ isError: true,
788
+ timestamp
789
+ }
790
+ ];
791
+ }
792
+ function parseResultContract(value, sourcePath) {
793
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
794
+ throw new Error(`agent recipe: ${sourcePath}: resultContract must be an object`);
795
+ }
796
+ const record = value;
797
+ if (typeof record.kind !== "string") throw new Error(`agent recipe: ${sourcePath}: resultContract.kind is required`);
798
+ const keys = Object.keys(record);
799
+ const only = (...allowed) => keys.every((key) => allowed.includes(key));
800
+ if (record.kind === "architect-plan") {
801
+ if (!only("kind", "path") || !string(record.path)) {
802
+ throw new Error(`agent recipe: ${sourcePath}: architect-plan requires only non-empty path`);
803
+ }
804
+ if (path.isAbsolute(record.path) || record.path.split(/[\\/]/u).includes("..")) {
805
+ throw new Error(`agent recipe: ${sourcePath}: architect-plan path must be workspace-relative`);
806
+ }
807
+ return { kind: "architect-plan", path: record.path };
808
+ }
809
+ const kinds = [
810
+ "scout-report",
811
+ "verifier-report",
812
+ "council-report",
813
+ "debugger-report",
814
+ "research-report",
815
+ "mutation-report",
816
+ "provenance-report",
817
+ "oracle-report",
818
+ "external-delegation",
819
+ "artifact-report",
820
+ "context-handbook",
821
+ "delegation-plan"
822
+ ];
823
+ if (!kinds.includes(record.kind) || !only("kind")) {
824
+ throw new Error(`agent recipe: ${sourcePath}: resultContract.kind is unsupported or has unknown keys`);
825
+ }
826
+ return { kind: record.kind };
827
+ }
828
+
829
+ export {
830
+ parseJsonObjectPayload,
831
+ parseCouncilReport,
832
+ resultContractSourceId,
833
+ parseVerifierResult,
834
+ parseOracleResult,
835
+ resultContractAuthorship,
836
+ parseScoutResult,
837
+ validateResultContract,
838
+ validateRecipeResult,
839
+ RESULT_CONTRACT_REPAIR_LIMIT,
840
+ resultContractRepairMessages,
841
+ parseResultContract
842
+ };
843
+ //# sourceMappingURL=chunk-DJNLUABN.js.map