@kontourai/flow-agents 3.2.0 → 3.4.0

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 (281) hide show
  1. package/.github/workflows/add-to-project.yml +15 -0
  2. package/.github/workflows/ci.yml +173 -0
  3. package/CHANGELOG.md +54 -0
  4. package/CONTEXT.md +5 -1
  5. package/README.md +19 -8
  6. package/build/src/builder-flow-run-adapter.d.ts +80 -0
  7. package/build/src/builder-flow-run-adapter.js +241 -0
  8. package/build/src/builder-flow-runtime.d.ts +16 -0
  9. package/build/src/builder-flow-runtime.js +290 -0
  10. package/build/src/cli/assignment-provider.js +10 -1
  11. package/build/src/cli/builder-run.d.ts +1 -0
  12. package/build/src/cli/builder-run.js +27 -0
  13. package/build/src/cli/effective-backlog-settings.js +70 -2
  14. package/build/src/cli/init.d.ts +34 -0
  15. package/build/src/cli/init.js +341 -61
  16. package/build/src/cli/kit.js +55 -12
  17. package/build/src/cli/pull-work-provider.js +346 -5
  18. package/build/src/cli/skill-drift-check.d.ts +1 -0
  19. package/build/src/cli/skill-drift-check.js +165 -0
  20. package/build/src/cli/telemetry-doctor.d.ts +37 -0
  21. package/build/src/cli/telemetry-doctor.js +53 -6
  22. package/build/src/cli/validate-hook-influence.js +37 -7
  23. package/build/src/cli/workflow-artifact-cleanup-audit.js +418 -11
  24. package/build/src/cli/workflow-sidecar.d.ts +310 -1
  25. package/build/src/cli/workflow-sidecar.js +1914 -126
  26. package/build/src/cli.js +5 -0
  27. package/build/src/flow-kit/validate.d.ts +54 -34
  28. package/build/src/flow-kit/validate.js +237 -26
  29. package/build/src/index.d.ts +2 -0
  30. package/build/src/index.js +1 -0
  31. package/build/src/lib/console-connect-options.d.ts +97 -0
  32. package/build/src/lib/console-connect-options.js +199 -0
  33. package/build/src/lib/console-telemetry-validate.d.ts +49 -0
  34. package/build/src/lib/console-telemetry-validate.js +91 -0
  35. package/build/src/lib/flow-resolver.d.ts +54 -1
  36. package/build/src/lib/flow-resolver.js +112 -5
  37. package/build/src/lib/fs.d.ts +17 -0
  38. package/build/src/lib/fs.js +172 -0
  39. package/build/src/lib/local-artifact-root.d.ts +44 -1
  40. package/build/src/lib/local-artifact-root.js +131 -3
  41. package/build/src/runtime-adapters.d.ts +39 -3
  42. package/build/src/runtime-adapters.js +77 -31
  43. package/build/src/tools/build-universal-bundles.js +40 -2
  44. package/build/src/tools/codex-agent-routing.d.ts +2 -0
  45. package/build/src/tools/codex-agent-routing.js +49 -0
  46. package/build/src/tools/generate-context-map.js +1 -0
  47. package/build/src/tools/validate-source-tree.js +30 -3
  48. package/context/contracts/artifact-contract.md +16 -2
  49. package/context/scripts/hooks/lib/kit-catalog.js +235 -0
  50. package/context/scripts/hooks/lib/runnable-command.js +177 -0
  51. package/context/scripts/hooks/stop-goal-fit.js +278 -48
  52. package/context/scripts/hooks/workflow-steering.js +194 -22
  53. package/context/scripts/package.json +3 -0
  54. package/context/scripts/telemetry/install-console-config.sh +25 -4
  55. package/context/scripts/telemetry/lib/config.sh +102 -12
  56. package/context/scripts/telemetry/lib/pricing.sh +50 -0
  57. package/context/scripts/telemetry/lib/session.sh +3 -0
  58. package/context/scripts/telemetry/lib/transport.sh +87 -0
  59. package/context/scripts/telemetry/lib/usage.sh +205 -4
  60. package/context/scripts/telemetry/telemetry.conf +6 -0
  61. package/context/scripts/telemetry/telemetry.sh +48 -0
  62. package/context/settings/workspace-backlog-provider-settings.example.json +48 -0
  63. package/docs/agent-usage-feedback-loop.md +35 -0
  64. package/docs/architecture-engine-and-kits.md +110 -0
  65. package/docs/context-map.md +2 -0
  66. package/docs/coordination-guide.md +370 -0
  67. package/docs/decisions/agent-coordination.md +26 -9
  68. package/docs/decisions/embeddable-engine.md +152 -0
  69. package/docs/decisions/index.md +5 -3
  70. package/docs/decisions/trust-ledger-retention.md +88 -0
  71. package/docs/decisions/trust-reconcile.md +42 -9
  72. package/docs/decisions/workflow-enforcement.md +31 -9
  73. package/docs/fixture-ownership.md +6 -2
  74. package/docs/implementing-trust-reconciliation.md +129 -0
  75. package/docs/index.md +23 -9
  76. package/docs/integrations/flow-agents-console.md +275 -0
  77. package/docs/integrations/index.md +4 -0
  78. package/docs/kit-authoring-guide.md +52 -21
  79. package/docs/spec/builder-flow-runtime.md +80 -0
  80. package/docs/spec/runtime-hook-surface.md +45 -1
  81. package/docs/specs/economics-record-contract.md +270 -0
  82. package/docs/specs/harness-capability-matrix.md +74 -0
  83. package/docs/specs/learning-review-proposals-contract.md +340 -0
  84. package/docs/specs/routing-efficiency-review.md +59 -0
  85. package/docs/verifiable-trust.md +74 -25
  86. package/docs/workflow-artifact-lifecycle.md +38 -1
  87. package/docs/workflow-usage-guide.md +10 -0
  88. package/evals/acceptance/prove-capture-teeth.sh +132 -0
  89. package/evals/ci/antigaming-suite.sh +2 -0
  90. package/evals/ci/run-baseline.sh +78 -4
  91. package/evals/fixtures/economics/acceptance.json +12 -0
  92. package/evals/fixtures/economics/agents/tool-worker-1/events.jsonl +2 -0
  93. package/evals/fixtures/economics/agents/tool-worker-2/events.jsonl +2 -0
  94. package/evals/fixtures/economics/agents/tool-worker-3/events.jsonl +2 -0
  95. package/evals/fixtures/economics/agents/tool-worker-4/events.jsonl +1 -0
  96. package/evals/fixtures/economics/agents/tool-worker-5/events.jsonl +2 -0
  97. package/evals/fixtures/economics/critique.json +22 -0
  98. package/evals/fixtures/economics/expected-record.json +71 -0
  99. package/evals/fixtures/economics/session-usage-event.json +1 -0
  100. package/evals/fixtures/economics/state.json +11 -0
  101. package/evals/fixtures/economics/transcript.jsonl +3 -0
  102. package/evals/fixtures/hook-influence/cases.json +7 -7
  103. package/evals/fixtures/learning-review-proposals/balanced/economics.jsonl +6 -0
  104. package/evals/fixtures/learning-review-proposals/effect-follow-up/economics.jsonl +5 -0
  105. package/evals/fixtures/learning-review-proposals/effect-follow-up/sessions/task-lr-ef-1/trust.bundle +21 -0
  106. package/evals/fixtures/learning-review-proposals/effect-follow-up/sessions/task-lr-ef-2/trust.bundle +21 -0
  107. package/evals/fixtures/learning-review-proposals/effect-follow-up/sessions/task-lr-ef-3/trust.bundle +21 -0
  108. package/evals/fixtures/learning-review-proposals/effect-follow-up/sessions/task-lr-ef-4/trust.bundle +21 -0
  109. package/evals/fixtures/learning-review-proposals/effect-follow-up/sessions/task-lr-ef-5/trust.bundle +21 -0
  110. package/evals/fixtures/learning-review-proposals/pattern-present/economics.jsonl +6 -0
  111. package/evals/fixtures/learning-review-proposals/pattern-present/expected-aggregates.json +30 -0
  112. package/evals/fixtures/learning-review-proposals/pattern-present/expected-aggregates.md +66 -0
  113. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-1/gate-review.inquiries.json +26 -0
  114. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-1/trust.bundle +21 -0
  115. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-2/gate-review.inquiries.json +26 -0
  116. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-2/trust.bundle +21 -0
  117. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-3/gate-review.inquiries.json +26 -0
  118. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-3/trust.bundle +21 -0
  119. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-4/gate-review.inquiries.json +26 -0
  120. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-4/trust.bundle +21 -0
  121. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-5/trust.bundle +21 -0
  122. package/evals/fixtures/learning-review-proposals/pattern-present/sessions/task-lr-pp-6/trust.bundle +21 -0
  123. package/evals/fixtures/learning-review-proposals/repeat-window/economics.jsonl +6 -0
  124. package/evals/fixtures/learning-review-proposals/under-threshold/economics.jsonl +3 -0
  125. package/evals/fixtures/reconcile-preflight/disputed-critique-unsuperseded.json +48 -0
  126. package/evals/fixtures/reconcile-preflight/standalone-disputed-session-local.json +59 -0
  127. package/evals/fixtures/telemetry/usage-transcript-sample.jsonl +4 -0
  128. package/evals/fixtures/trust-reconcile-exploits/mcp-degrade.json +42 -0
  129. package/evals/integration/test_builder_entry_enforcement.sh +241 -0
  130. package/evals/integration/test_builder_step_producers.sh +18 -10
  131. package/evals/integration/test_bundle_install.sh +172 -0
  132. package/evals/integration/test_checkpoint_signing.sh +10 -2
  133. package/evals/integration/test_ci_actor_identity.sh +221 -0
  134. package/evals/integration/test_console_tenant_isolation.sh +167 -0
  135. package/evals/integration/test_critique_supersession_roundtrip.sh +4 -1
  136. package/evals/integration/test_dual_emit_flow_step.sh +10 -4
  137. package/evals/integration/test_economics_record.sh +674 -0
  138. package/evals/integration/test_effective_backlog_settings.sh +1 -1
  139. package/evals/integration/test_evidence_capture_hook.sh +17 -2
  140. package/evals/integration/test_exemption_usage_review.sh +198 -0
  141. package/evals/integration/test_fixture_retirement_audit.sh +2 -2
  142. package/evals/integration/test_flow_kit_install_git.sh +83 -0
  143. package/evals/integration/test_flowdef_session_activation.sh +0 -1
  144. package/evals/integration/test_flowdef_session_history_preservation.sh +13 -3
  145. package/evals/integration/test_gate_lockdown.sh +7 -0
  146. package/evals/integration/test_gate_review_inquiry_records.sh +9 -1
  147. package/evals/integration/test_goal_fit_hook.sh +2031 -0
  148. package/evals/integration/test_hook_category_behaviors.sh +8 -1
  149. package/evals/integration/test_hook_influence_cases.sh +25 -1
  150. package/evals/integration/test_install_merge.sh +227 -2
  151. package/evals/integration/test_kit_conformance_levels.sh +6 -6
  152. package/evals/integration/test_learning_review_proposals.sh +329 -0
  153. package/evals/integration/test_liveness_conflict_injection.sh +26 -22
  154. package/evals/integration/test_liveness_console_relay.sh +166 -0
  155. package/evals/integration/test_liveness_heartbeat.sh +17 -17
  156. package/evals/integration/test_liveness_worktree_root.sh +575 -0
  157. package/evals/integration/test_phase_map_and_gate_claim.sh +6 -1
  158. package/evals/integration/test_publish_delivery.sh +389 -2
  159. package/evals/integration/test_pull_work_board.sh +200 -0
  160. package/evals/integration/test_pull_work_provider.sh +1 -1
  161. package/evals/integration/test_reconcile_preflight.sh +304 -0
  162. package/evals/integration/test_record_check.sh +378 -0
  163. package/evals/integration/test_routing_efficiency.sh +71 -0
  164. package/evals/integration/test_runtime_adapter_activation.sh +28 -0
  165. package/evals/integration/test_session_resume_roundtrip.sh +16 -19
  166. package/evals/integration/test_skill_drift_check.sh +870 -0
  167. package/evals/integration/test_takeover_protocol.sh +340 -0
  168. package/evals/integration/test_telemetry.sh +445 -0
  169. package/evals/integration/test_telemetry_doctor.sh +66 -0
  170. package/evals/integration/test_telemetry_usage_pipeline.sh +228 -0
  171. package/evals/integration/test_trust_reconcile_negatives.sh +121 -13
  172. package/evals/integration/test_trust_reconcile_trailer_diagnostic.sh +247 -0
  173. package/evals/integration/test_usage_cost.sh +61 -0
  174. package/evals/integration/test_verify_hold.sh +910 -0
  175. package/evals/integration/test_veritas_governance_kit.sh +257 -0
  176. package/evals/integration/test_workflow_artifact_cleanup_audit.sh +575 -3
  177. package/evals/integration/test_workflow_sidecar_writer.sh +1395 -0
  178. package/evals/integration/test_workflow_steering_hook.sh +157 -16
  179. package/evals/integration/test_workspace_settings.sh +176 -0
  180. package/evals/lib/env.sh +26 -0
  181. package/evals/lib/node.sh +8 -0
  182. package/evals/run.sh +37 -0
  183. package/evals/static/test_ci_integration_coverage.sh +115 -0
  184. package/evals/static/test_declared_scope_forms_documented.sh +114 -0
  185. package/evals/static/test_universal_bundles.sh +34 -0
  186. package/evals/static/test_validate_source_kit_asset_scope.sh +259 -0
  187. package/evals/static/test_workflow_skills.sh +1 -1
  188. package/kits/builder/flows/build.flow.json +9 -18
  189. package/kits/builder/flows/publish-learn.flow.json +5 -1
  190. package/kits/builder/kit.json +120 -0
  191. package/kits/builder/skills/continue-work/SKILL.md +2 -0
  192. package/kits/builder/skills/deliver/SKILL.md +115 -0
  193. package/kits/builder/skills/evidence-gate/SKILL.md +12 -0
  194. package/kits/builder/skills/execute-plan/SKILL.md +9 -0
  195. package/kits/builder/skills/learning-review/SKILL.md +51 -0
  196. package/kits/builder/skills/plan-work/SKILL.md +17 -20
  197. package/kits/builder/skills/pull-work/SKILL.md +33 -2
  198. package/kits/builder/skills/release-readiness/SKILL.md +12 -0
  199. package/kits/knowledge/kit.json +9 -0
  200. package/kits/veritas-governance/docs/README.md +113 -7
  201. package/kits/veritas-governance/fixtures/exemption/approved.trust-bundle.json +74 -0
  202. package/kits/veritas-governance/fixtures/exemption/not-approved.trust-bundle.json +74 -0
  203. package/kits/veritas-governance/fixtures/exemption-review/mixed-fresh-stale.DECLARED.json +14 -0
  204. package/kits/veritas-governance/flows/exemption-issuance.flow.json +35 -0
  205. package/kits/veritas-governance/kit.json +19 -0
  206. package/kits/veritas-governance/skills/exemption-usage-review/SKILL.md +128 -0
  207. package/kits/veritas-governance/skills/exemption-usage-review/review-exemptions.mjs +231 -0
  208. package/package.json +2 -2
  209. package/packaging/manifest.json +29 -0
  210. package/schemas/backlog-provider-settings.schema.json +13 -0
  211. package/schemas/workflow-state.schema.json +44 -0
  212. package/scripts/README.md +4 -0
  213. package/scripts/check-content-boundary.cjs +8 -1
  214. package/scripts/ci/trust-reconcile.js +214 -253
  215. package/scripts/hooks/codex-hook-adapter.js +77 -2
  216. package/scripts/hooks/evidence-capture.js +38 -5
  217. package/scripts/hooks/lib/actor-identity.js +82 -0
  218. package/scripts/hooks/lib/codex-exit-code.js +316 -0
  219. package/scripts/hooks/lib/kit-catalog.js +235 -0
  220. package/scripts/hooks/lib/liveness-write.js +28 -1
  221. package/scripts/hooks/lib/local-artifact-paths.js +97 -1
  222. package/scripts/hooks/lib/runnable-command.js +177 -0
  223. package/scripts/hooks/lib/skill-drift.js +350 -0
  224. package/scripts/hooks/stop-goal-fit.js +278 -48
  225. package/scripts/hooks/workflow-steering.js +194 -22
  226. package/scripts/install-codex-home.sh +97 -47
  227. package/scripts/install-merge.js +72 -14
  228. package/scripts/install-owned-files.js +178 -0
  229. package/scripts/lib/reconcile-shape.js +381 -0
  230. package/scripts/liveness/relay.sh +84 -0
  231. package/scripts/telemetry/economics-record.schema.json +145 -0
  232. package/scripts/telemetry/economics-record.sh +331 -0
  233. package/scripts/telemetry/install-console-config.sh +25 -4
  234. package/scripts/telemetry/learning-review-decide.sh +124 -0
  235. package/scripts/telemetry/learning-review-proposals.schema.json +161 -0
  236. package/scripts/telemetry/learning-review-proposals.sh +484 -0
  237. package/scripts/telemetry/lib/config.sh +102 -12
  238. package/scripts/telemetry/lib/pricing.sh +14 -6
  239. package/scripts/telemetry/lib/session.sh +3 -0
  240. package/scripts/telemetry/lib/transport.sh +133 -15
  241. package/scripts/telemetry/lib/usage.sh +121 -28
  242. package/scripts/telemetry/routing-efficiency.sh +0 -0
  243. package/scripts/telemetry/telemetry.conf +6 -0
  244. package/scripts/telemetry/telemetry.sh +48 -0
  245. package/src/builder-flow-run-adapter.ts +357 -0
  246. package/src/builder-flow-runtime.ts +348 -0
  247. package/src/cli/assignment-provider.ts +12 -1
  248. package/src/cli/builder-flow-run-adapter.test.mjs +495 -0
  249. package/src/cli/builder-flow-runtime.test.mjs +213 -0
  250. package/src/cli/builder-run.ts +28 -0
  251. package/src/cli/codex-agent-routing.test.mjs +44 -0
  252. package/src/cli/codex-exit-code.test.mjs +207 -0
  253. package/src/cli/console-connect-options.test.mjs +329 -0
  254. package/src/cli/console-telemetry-validate.test.mjs +157 -0
  255. package/src/cli/effective-backlog-settings.ts +68 -2
  256. package/src/cli/flow-resolver-composition.test.mjs +72 -0
  257. package/src/cli/init.test.mjs +161 -0
  258. package/src/cli/init.ts +407 -62
  259. package/src/cli/kit-metadata-security.test.mjs +443 -0
  260. package/src/cli/kit.ts +50 -12
  261. package/src/cli/pull-work-provider.ts +377 -3
  262. package/src/cli/sidecar-pure-helpers.test.mjs +64 -0
  263. package/src/cli/skill-drift-check.ts +196 -0
  264. package/src/cli/telemetry-doctor.test.mjs +53 -0
  265. package/src/cli/telemetry-doctor.ts +50 -7
  266. package/src/cli/validate-hook-influence.ts +37 -6
  267. package/src/cli/workflow-artifact-cleanup-audit.ts +483 -10
  268. package/src/cli/workflow-sidecar.ts +1980 -119
  269. package/src/cli.ts +5 -0
  270. package/src/flow-kit/validate.ts +277 -38
  271. package/src/index.ts +19 -0
  272. package/src/lib/console-connect-options.ts +261 -0
  273. package/src/lib/console-telemetry-validate.ts +88 -0
  274. package/src/lib/flow-resolver.ts +117 -4
  275. package/src/lib/fs.ts +160 -0
  276. package/src/lib/local-artifact-root.ts +129 -3
  277. package/src/runtime-adapters.ts +113 -33
  278. package/src/tools/build-universal-bundles.ts +36 -2
  279. package/src/tools/codex-agent-routing.ts +48 -0
  280. package/src/tools/generate-context-map.ts +1 -0
  281. package/src/tools/validate-source-tree.ts +29 -3
@@ -0,0 +1,304 @@
1
+ #!/usr/bin/env bash
2
+ # test_reconcile_preflight.sh — #356 (Local Reconcile-Shape Preflight) proof.
3
+ #
4
+ # Proves `workflow-sidecar reconcile-preflight <artifact-dir>` catches every documented
5
+ # ADR-0020-invalid trust.bundle shape LOCALLY, before git push — reusing (never forking)
6
+ # scripts/lib/reconcile-shape.js's own classification (the same module
7
+ # scripts/ci/trust-reconcile.js requires), so the local check can never silently drift from
8
+ # what CI enforces. Mirrors evals/integration/test_trust_reconcile_negatives.sh's
9
+ # fixture-per-case + run_case() helper shape.
10
+ #
11
+ # 1. non-manifest command-backed claim (reuses trust-reconcile-exploits/no-label-bypass.json)
12
+ # → not-run divergence + fix hint to name the exact manifest command.
13
+ # 2. unwaived assumed claim (reuses trust-reconcile-exploits/skip-assumed-bypass.json)
14
+ # → unwaived-assumed divergence + fix hint (also carries Q2's root-cause hint for shape 5).
15
+ # 3. un-superseded disputed critique (new fixture: disputed-critique-unsuperseded.json)
16
+ # → session-local-failed divergence (a workflow.critique.review claim, no superseded_by).
17
+ # 4. standalone fail/disputed session-local claim, non-critique (#292/#384 variant; new
18
+ # fixture: standalone-disputed-session-local.json) → the SAME session-local-failed
19
+ # divergence type as case 3, proving a disjoint pre-existing failure can never be
20
+ # smuggled in as a standalone claim either way.
21
+ # 5. waiver-voided-by-mixed-call — reproduced via the REAL producer CLI (record-evidence),
22
+ # not a hand-built fixture. Confirms the actual current behavior: the command-backed-
23
+ # waiver guard at src/cli/workflow-sidecar.ts's recordEvidence() dies at RECORD time
24
+ # when --accepted-gap-reason/--waived-by is combined with ANY command-backed check in
25
+ # the same call (even alongside other, session-local checks in the same --check-json
26
+ # set) — so there is no "silently voided" bundle to reconcile in this repo's current
27
+ # producer; this is documented, correct, prevention-at-the-source, not a preflight gap.
28
+ # 6. dropped waiver metadata round-trip (AC2) — a regression PROOF, not a preflight
29
+ # detection: record-evidence (waiver on a session-local check) → record-critique
30
+ # (rebuilds via checksFromBundle) → the bundle's claim STILL has metadata.waiver.
31
+ #
32
+ # Plus: CLEAN-BUNDLE (AC4, reuses trust-reconcile-mixed-bundle/mixed-bundle.json) → exit 0,
33
+ # no issues. AC5 (local/fast, no CI spawn): a --manifest override naming a sentinel-writing
34
+ # command is never invoked by the preflight on the clean bundle.
35
+ #
36
+ # Deterministic, no model spend, self-cleaning.
37
+ # Usage: bash evals/integration/test_reconcile_preflight.sh
38
+
39
+ set -uo pipefail
40
+
41
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
42
+ source "$ROOT/evals/lib/node.sh"
43
+
44
+ WRITER="workflow-sidecar"
45
+ FX_EXPLOITS="$ROOT/evals/fixtures/trust-reconcile-exploits"
46
+ FX_PREFLIGHT="$ROOT/evals/fixtures/reconcile-preflight"
47
+ MIXED_BUNDLE="$ROOT/evals/fixtures/trust-reconcile-mixed-bundle/mixed-bundle.json"
48
+
49
+ TMP="$(mktemp -d)"
50
+ errors=0
51
+
52
+ _pass() { echo " PASS: $1"; }
53
+ _fail() { echo " FAIL: $1"; errors=$((errors + 1)); }
54
+
55
+ cleanup() { rm -rf "$TMP"; }
56
+ trap cleanup EXIT
57
+
58
+ # run_case <label> <bundle> <needle...>
59
+ # Copies <bundle> into a fresh session dir as trust.bundle, runs reconcile-preflight, and
60
+ # asserts: exit non-zero AND stdout/stderr contains EVERY needle passed after <bundle>.
61
+ run_case() {
62
+ local label="$1" bundle="$2"
63
+ shift 2
64
+ echo "=== $label ==="
65
+ if [[ ! -f "$bundle" ]]; then _fail "$label: fixture not found at $bundle"; return; fi
66
+ local session="$TMP/case-$RANDOM$RANDOM"
67
+ mkdir -p "$session"
68
+ cp "$bundle" "$session/trust.bundle"
69
+ local out code
70
+ out="$(flow_agents_node "$WRITER" reconcile-preflight "$session" --repo-root "$ROOT" 2>&1)"
71
+ code=$?
72
+ if [[ $code -ne 0 ]]; then
73
+ _pass "$label: reconcile-preflight exits non-zero ($code)"
74
+ else
75
+ _fail "$label: expected non-zero exit, got 0 — output: $out"
76
+ fi
77
+ local needle
78
+ for needle in "$@"; do
79
+ if echo "$out" | grep -qF "$needle"; then
80
+ _pass "$label: output contains \"$needle\""
81
+ else
82
+ _fail "$label: expected \"$needle\" in output — output: $out"
83
+ fi
84
+ done
85
+ }
86
+
87
+ # ==== Case 1: non-manifest command-backed claim (reused fixture) ====================
88
+ run_case "case 1: non-manifest command-backed claim" "$FX_EXPLOITS/no-label-bypass.json" \
89
+ "c-fabricated-test" \
90
+ "no manifest-matched execution.label" \
91
+ "FIX: fold this into a non-command summary"
92
+
93
+ # ==== Case 2: unwaived assumed claim (reused fixture) ================================
94
+ run_case "case 2: unwaived assumed claim" "$FX_EXPLOITS/skip-assumed-bypass.json" \
95
+ "c-skipped" \
96
+ "re-derived status 'assumed' but carries no waiver" \
97
+ "requires a documented waiver (--accepted-gap-reason/--waived-by)"
98
+
99
+ # ==== Case 3: un-superseded disputed critique (new fixture) ==========================
100
+ run_case "case 3: un-superseded disputed critique" "$FX_PREFLIGHT/disputed-critique-unsuperseded.json" \
101
+ "c-disputed-critique" \
102
+ "workflow.critique.review" \
103
+ "has re-derived status 'disputed'" \
104
+ "FIX: a disputed/failing claim always blocks reconcile. Document a disjoint pre-existing failure as prose in a WAIVED non-command summary, not as a standalone claim."
105
+
106
+ # ==== Case 4: standalone fail/disputed session-local claim, non-critique (#292/#384) =
107
+ run_case "case 4: standalone disputed session-local claim (non-critique)" "$FX_PREFLIGHT/standalone-disputed-session-local.json" \
108
+ "c-standalone-disputed" \
109
+ "has re-derived status 'disputed'" \
110
+ "FIX: a disputed/failing claim always blocks reconcile. Document a disjoint pre-existing failure as prose in a WAIVED non-command summary, not as a standalone claim."
111
+
112
+ # ==== Case 5: waiver-voided-by-mixed-call — REAL PRODUCER CLI reproduction ===========
113
+ # Q2 resolution: shape #5 is NOT a distinct predicate — per the plan, confirm the ACTUAL
114
+ # current behavior first. This repo's guard at record-evidence time (the command-backed-
115
+ # waiver check ahead of any bundle write) dies loudly BEFORE a bundle is ever written when
116
+ # --accepted-gap-reason/--waived-by is combined with a command-backed check in the same
117
+ # call — including when a session-local check is ALSO present in the same call. That is the
118
+ # correct prevention (fail at the source, not a silently-voided bundle downstream) — assert
119
+ # the die message is clear and that no trust.bundle is produced.
120
+ echo "=== case 5: waiver-voided-by-mixed-call (real producer CLI reproduction) ==="
121
+
122
+ AROOT5="$TMP/repo5/.flow-agents"
123
+ SLUG5="case5-mixed-call"
124
+ SESSION_DIR5="$AROOT5/$SLUG5"
125
+ mkdir -p "$TMP/repo5/kits" "$AROOT5"
126
+
127
+ flow_agents_node "$WRITER" ensure-session --artifact-root "$AROOT5" --task-slug "$SLUG5" \
128
+ --title "Case 5" --summary "waiver-voided-by-mixed-call repro" --criterion "x" \
129
+ --timestamp "2026-07-04T10:00:00Z" >/dev/null 2>&1
130
+ flow_agents_node "$WRITER" init-plan "$SESSION_DIR5/${SLUG5}--deliver.md" \
131
+ --source-request "t" --summary "t" --timestamp "2026-07-04T10:01:00Z" >/dev/null 2>&1
132
+
133
+ # 5a. Single command-backed check + waiver flags in the SAME call → dies at record time.
134
+ case5a_out="$(flow_agents_node "$WRITER" record-evidence "$SESSION_DIR5" --verdict pass \
135
+ --check-json '{"id":"cmdcheck","kind":"test","status":"pass","summary":"cmd ran","command":"npm run validate:source --"}' \
136
+ --accepted-gap-reason "load test env unavailable" --waived-by "brian" \
137
+ --timestamp "2026-07-04T10:02:00Z" 2>&1)"
138
+ case5a_code=$?
139
+ if [[ $case5a_code -ne 0 ]]; then
140
+ _pass "case 5a: record-evidence dies at RECORD time for a mixed waiver+command-backed call ($case5a_code)"
141
+ else
142
+ _fail "case 5a: expected record-evidence to die (non-zero exit), got 0 — output: $case5a_out"
143
+ fi
144
+ if echo "$case5a_out" | grep -qF "cannot be applied to a command-backed check"; then
145
+ _pass "case 5a: die message clearly names the command-backed-waiver rejection"
146
+ else
147
+ _fail "case 5a: expected the command-backed-waiver die message — output: $case5a_out"
148
+ fi
149
+ if [[ ! -f "$SESSION_DIR5/trust.bundle" ]]; then
150
+ _pass "case 5a: no trust.bundle written (dies BEFORE any bundle write — no silently-voided waiver bundle downstream)"
151
+ else
152
+ _fail "case 5a: a trust.bundle was written despite the mixed-call guard firing"
153
+ fi
154
+
155
+ # 5b. TWO checks in the SAME call (one command-backed, one session-local) + waiver flags →
156
+ # the guard scans ALL checks in the call, so this ALSO dies at record time (proves the
157
+ # guard is not scoped only to a single-check call — the exact "mixed call" shape).
158
+ case5b_out="$(flow_agents_node "$WRITER" record-evidence "$SESSION_DIR5" --verdict pass \
159
+ --check-json '{"id":"cmdcheck2","kind":"test","status":"pass","summary":"cmd ran","command":"npm run validate:source --"}' \
160
+ --check-json '{"id":"sessioncheck2","kind":"external","status":"skip","summary":"manual load test skip"}' \
161
+ --accepted-gap-reason "load test env unavailable" --waived-by "brian" \
162
+ --timestamp "2026-07-04T10:03:00Z" 2>&1)"
163
+ case5b_code=$?
164
+ if [[ $case5b_code -ne 0 ]]; then
165
+ _pass "case 5b: record-evidence ALSO dies for a two-check mixed call (command-backed + session-local, one waiver) ($case5b_code)"
166
+ else
167
+ _fail "case 5b: expected record-evidence to die (non-zero exit), got 0 — output: $case5b_out"
168
+ fi
169
+ if echo "$case5b_out" | grep -qF "cannot be applied to a command-backed check"; then
170
+ _pass "case 5b: die message clearly names the command-backed-waiver rejection"
171
+ else
172
+ _fail "case 5b: expected the command-backed-waiver die message — output: $case5b_out"
173
+ fi
174
+ if [[ ! -f "$SESSION_DIR5/trust.bundle" ]]; then
175
+ _pass "case 5b: no trust.bundle written"
176
+ else
177
+ _fail "case 5b: a trust.bundle was written despite the mixed-call guard firing"
178
+ fi
179
+
180
+ # 5c. Sanity: the Q2 root-cause hint IS reachable via reconcile-preflight's message for an
181
+ # honest (non-mixed-call) unwaived-assumed divergence — i.e. an agent who DOES end up
182
+ # with an unwaived-assumed claim (by whatever path) gets pointed at the mixed-call guard
183
+ # as a likely root cause. Reuses case 2's fixture; restated here for traceability to
184
+ # shape #5 per Q2's resolution (shape #5 is #2 enriched with a root-cause hint, not a
185
+ # distinct predicate).
186
+ Q2_SESSION="$TMP/q2-check"
187
+ mkdir -p "$Q2_SESSION"
188
+ cp "$FX_EXPLOITS/skip-assumed-bypass.json" "$Q2_SESSION/trust.bundle"
189
+ q2_out="$(flow_agents_node "$WRITER" reconcile-preflight "$Q2_SESSION" --repo-root "$ROOT" 2>&1)"
190
+ if echo "$q2_out" | grep -qF "voids/rejects the waiver"; then
191
+ _pass "case 5c (Q2 traceability): unwaived-assumed's preflight message carries the mixed-call root-cause hint"
192
+ else
193
+ _fail "case 5c (Q2 traceability): expected the mixed-call root-cause hint on an unwaived-assumed divergence — output: $q2_out"
194
+ fi
195
+
196
+ # ==== Case 6 (AC2): dropped waiver metadata round-trip — regression PROOF, not detection ==
197
+ echo "=== case 6 (AC2): waiver metadata round-trip survives record-critique rebuild ==="
198
+
199
+ AROOT6="$TMP/repo6/.flow-agents"
200
+ SLUG6="case6-waiver-roundtrip"
201
+ SESSION_DIR6="$AROOT6/$SLUG6"
202
+ mkdir -p "$TMP/repo6/kits" "$AROOT6"
203
+
204
+ flow_agents_node "$WRITER" ensure-session --artifact-root "$AROOT6" --task-slug "$SLUG6" \
205
+ --title "Case 6" --summary "waiver round-trip repro" --criterion "x" \
206
+ --timestamp "2026-07-04T10:00:00Z" >/dev/null 2>&1
207
+ flow_agents_node "$WRITER" init-plan "$SESSION_DIR6/${SLUG6}--deliver.md" \
208
+ --source-request "t" --summary "t" --timestamp "2026-07-04T10:01:00Z" >/dev/null 2>&1
209
+
210
+ flow_agents_node "$WRITER" record-evidence "$SESSION_DIR6" --verdict pass \
211
+ --check-json '{"id":"loadtest","kind":"external","status":"skip","summary":"load test skip"}' \
212
+ --accepted-gap-reason "load test env unavailable" --waived-by "brian" \
213
+ --timestamp "2026-07-04T10:02:00Z" >/dev/null 2>&1
214
+
215
+ flow_agents_node "$WRITER" record-critique "$SESSION_DIR6" --verdict pass --summary "ok." \
216
+ --timestamp "2026-07-04T10:03:00Z" >/dev/null 2>&1
217
+
218
+ if [[ -f "$SESSION_DIR6/trust.bundle" ]]; then
219
+ _pass "case 6: trust.bundle exists after record-evidence -> record-critique rebuild"
220
+ bundle_json="$(cat "$SESSION_DIR6/trust.bundle")"
221
+ if echo "$bundle_json" | grep -qF '"waiver"'; then
222
+ _pass "case 6: rebuilt trust.bundle's claim STILL carries metadata.waiver (AC2 fix holds — pre-fix this silently dropped)"
223
+ else
224
+ _fail "case 6: rebuilt trust.bundle's claim LOST metadata.waiver — AC2 round-trip regressed. bundle: $bundle_json"
225
+ fi
226
+ if echo "$bundle_json" | grep -qF '"approved_by": "brian"'; then
227
+ _pass "case 6: waiver's approved_by ('brian') survives the rebuild"
228
+ else
229
+ _fail "case 6: expected waiver.approved_by 'brian' to survive the rebuild — bundle: $bundle_json"
230
+ fi
231
+ else
232
+ _fail "case 6: trust.bundle was not found at $SESSION_DIR6/trust.bundle after the round-trip sequence"
233
+ fi
234
+
235
+ # Reconcile-preflight must ALSO pass cleanly on the rebuilt (waiver-intact) bundle —
236
+ # an accepted-gap waiver on a session-local check is a shape-clean, WAIVED divergence-free
237
+ # bundle by ADR 0020's own rules.
238
+ preflight6_out="$(flow_agents_node "$WRITER" reconcile-preflight "$SESSION_DIR6" --repo-root "$ROOT" 2>&1)"
239
+ preflight6_code=$?
240
+ if [[ $preflight6_code -eq 0 ]]; then
241
+ _pass "case 6: reconcile-preflight exits 0 on the round-tripped, waiver-intact bundle"
242
+ else
243
+ _fail "case 6: expected reconcile-preflight exit 0 on the round-tripped bundle, got $preflight6_code — output: $preflight6_out"
244
+ fi
245
+
246
+ # ==== CLEAN-BUNDLE (AC4) ==============================================================
247
+ echo "=== CLEAN-BUNDLE (AC4): a valid ADR-0020-conformant bundle passes ==="
248
+
249
+ CLEAN_SESSION="$TMP/clean-bundle"
250
+ mkdir -p "$CLEAN_SESSION"
251
+ cp "$MIXED_BUNDLE" "$CLEAN_SESSION/trust.bundle"
252
+
253
+ clean_out="$(flow_agents_node "$WRITER" reconcile-preflight "$CLEAN_SESSION" --repo-root "$ROOT" 2>&1)"
254
+ clean_code=$?
255
+ if [[ $clean_code -eq 0 ]]; then
256
+ _pass "CLEAN-BUNDLE: reconcile-preflight exits 0 for a valid bundle"
257
+ else
258
+ _fail "CLEAN-BUNDLE: expected exit 0, got $clean_code — output: $clean_out"
259
+ fi
260
+ if echo "$clean_out" | grep -qF "OK — no shape issues found"; then
261
+ _pass "CLEAN-BUNDLE: output reports no issues"
262
+ else
263
+ _fail "CLEAN-BUNDLE: expected the no-issues OK line — output: $clean_out"
264
+ fi
265
+
266
+ # ==== AC5: preflight never spawns a manifest command =================================
267
+ echo "=== AC5: reconcile-preflight never spawns a fresh manifest command ==="
268
+
269
+ AC5_SESSION="$TMP/ac5-bundle"
270
+ mkdir -p "$AC5_SESSION"
271
+ cp "$MIXED_BUNDLE" "$AC5_SESSION/trust.bundle"
272
+ SENTINEL="$TMP/ac5-sentinel-should-not-exist"
273
+ rm -f "$SENTINEL"
274
+
275
+ # --manifest override: the mixed bundle's real command ("npm run check:content-boundary --")
276
+ # PLUS a second entry whose command WRITES a sentinel file if actually executed. Since
277
+ # reconcile-preflight resolves the manifest (a pure, local, no-command-execution lookup) but
278
+ # never calls runCommand/spawns a manifest entry's command to prove reconciliation, the
279
+ # sentinel must never appear.
280
+ AC5_MANIFEST='[{"id":"content-boundary","command":"npm run check:content-boundary --"},{"id":"sentinel","command":"touch '"$SENTINEL"'"}]'
281
+
282
+ ac5_out="$(flow_agents_node "$WRITER" reconcile-preflight "$AC5_SESSION" --repo-root "$ROOT" --manifest "$AC5_MANIFEST" 2>&1)"
283
+ ac5_code=$?
284
+ if [[ $ac5_code -eq 0 ]]; then
285
+ _pass "AC5: reconcile-preflight exits 0 on the clean bundle with the sentinel manifest override"
286
+ else
287
+ _fail "AC5: expected exit 0, got $ac5_code — output: $ac5_out"
288
+ fi
289
+ if [[ ! -f "$SENTINEL" ]]; then
290
+ _pass "AC5: sentinel file absent after the preflight run — no manifest command was spawned"
291
+ else
292
+ _fail "AC5: sentinel file EXISTS — reconcile-preflight spawned a manifest command (AC5 violated)"
293
+ fi
294
+
295
+ # ---- Summary ----
296
+ echo ""
297
+ echo "----------------------------------------------"
298
+ if [[ $errors -eq 0 ]]; then
299
+ echo "test_reconcile_preflight: all checks passed."
300
+ exit 0
301
+ else
302
+ echo "test_reconcile_preflight: $errors check(s) failed."
303
+ exit 1
304
+ fi