@tea-agent/loop-agent 0.26.0 → 0.26.2

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 (197) hide show
  1. package/CHANGELOG.md +1056 -1020
  2. package/README.md +8 -3
  3. package/bin/loop-agent.js +21 -21
  4. package/dist/application/dag/generate-task-dag.js +33 -0
  5. package/dist/cli/command-definitions.js +25 -10
  6. package/dist/cli/help.js +4 -3
  7. package/dist/cli/program.js +43 -17
  8. package/dist/commands/cursor-prompt.js +6 -6
  9. package/dist/commands/import-prd.js +7 -2
  10. package/dist/commands/init.js +7 -5
  11. package/dist/commands/loop-benchmark.js +11 -11
  12. package/dist/commands/pi-reuse-benchmark.js +16 -16
  13. package/dist/commands/task-source-prepare.js +474 -0
  14. package/dist/executors/dag-pi-executor.js +40 -5
  15. package/dist/executors/shell-executor.js +111 -0
  16. package/dist/executors/shell-presets.js +12 -4
  17. package/dist/executors/shell-write-guard.js +161 -25
  18. package/dist/sidecars/cursor-prompt/executor.js +1 -1
  19. package/dist/task/config-types.js +6 -0
  20. package/dist/task/contract/constants.js +1 -0
  21. package/dist/task/contract/project.js +8 -0
  22. package/dist/task/contract/schema.js +1 -0
  23. package/dist/task/frontend-preflight.js +131 -0
  24. package/dist/task/runtime.js +2 -4
  25. package/dist/task/source-prepare/build-draft.js +224 -0
  26. package/dist/task/source-prepare/completeness.js +195 -0
  27. package/dist/task/source-prepare/index.js +7 -0
  28. package/dist/task/source-prepare/parse-intent.js +373 -0
  29. package/dist/task/source-prepare/path-policy.js +197 -0
  30. package/dist/task/source-prepare/prepare.js +506 -0
  31. package/dist/task/source-prepare/reference-integrity.js +274 -0
  32. package/dist/task/source-prepare/types.js +7 -0
  33. package/dist/worker/observability/read-model.js +134 -0
  34. package/dist/worker/observe/static/copy.js +67 -67
  35. package/dist/worker/observe/static/dag-layout.d.ts +31 -31
  36. package/dist/worker/observe/static/dag-layout.js +83 -83
  37. package/dist/worker/observe/static/dom.js +220 -220
  38. package/dist/worker/observe/static/relations.js +133 -133
  39. package/dist/worker/observe/static/router.js +93 -93
  40. package/dist/worker/observe/static/run-processing.js +148 -148
  41. package/dist/worker/observe/static/state.js +61 -0
  42. package/dist/worker/observe/static/styles.css +8 -0
  43. package/dist/worker/observe/static/views/batch.js +227 -227
  44. package/dist/worker/observe/static/views/dag-graph.js +248 -172
  45. package/dist/worker/observe/static/views/dag-inspector.js +374 -157
  46. package/dist/worker/observe/static/views/dag.js +4 -11
  47. package/dist/worker/observe/static/views/failures.js +143 -143
  48. package/dist/worker/observe/static/views/feature.js +492 -492
  49. package/dist/worker/observe/static/views/run.js +453 -453
  50. package/dist/worker/observe/static/views/shell.js +7 -7
  51. package/dist/worker/observe/static/views/timeline.js +163 -163
  52. package/dist/workflows/dag/backend-test-pytest-collection.js +277 -0
  53. package/dist/workflows/dag/canvas-observer.js +275 -275
  54. package/dist/workflows/dag/convergence/controller.js +110 -21
  55. package/dist/workflows/dag/frontend-implementation-contract.js +218 -17
  56. package/dist/workflows/dag/frontend-review-context.js +7 -1
  57. package/dist/workflows/dag/frontend-verification-trace.js +14 -3
  58. package/dist/workflows/dag/frontend-worktree-diff.js +14 -3
  59. package/dist/workflows/dag/init-hybrid.js +96 -34
  60. package/dist/workflows/dag/output-protocol.js +180 -7
  61. package/dist/workflows/dag/runner.js +141 -52
  62. package/dist/workflows/dag/types.js +4 -0
  63. package/dist/workflows/dag/validate.js +3 -2
  64. package/docs/skills/README.md +7 -7
  65. package/docs/templates/adr.md +60 -60
  66. package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -94
  67. package/docs/templates/agent-dag-decision-envelope.schema.json +213 -213
  68. package/docs/templates/agent-dag-decision-gate.prompt.md +246 -246
  69. package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -98
  70. package/docs/templates/agent-dag-report.schema.json +473 -473
  71. package/docs/templates/agent-dag-review-verdict.prompt.md +68 -68
  72. package/docs/templates/backend-test-dag.json +100 -8
  73. package/docs/templates/backend-test-result.schema.json +99 -99
  74. package/docs/templates/feature-spec.md +53 -53
  75. package/docs/templates/frontend-design-contract.md +42 -42
  76. package/docs/templates/frontend-eval/fixtures/failures/01-type-build-error.md +17 -17
  77. package/docs/templates/frontend-eval/fixtures/failures/02-unit-component-test-fail.md +16 -16
  78. package/docs/templates/frontend-eval/fixtures/failures/03-fixture-schema-drift.md +16 -16
  79. package/docs/templates/frontend-eval/fixtures/failures/04-missing-loading-empty-error-state.md +16 -16
  80. package/docs/templates/frontend-eval/fixtures/failures/05-forbidden-write-writeset-expansion.md +16 -16
  81. package/docs/templates/frontend-eval/fixtures/failures/06-unapproved-dependency-add.md +16 -16
  82. package/docs/templates/frontend-eval/fixtures/failures/07-mock-production-on.md +21 -21
  83. package/docs/templates/frontend-eval/fixtures/functional/01-simple-component-style.md +29 -29
  84. package/docs/templates/frontend-eval/fixtures/functional/02-form-validation.md +28 -28
  85. package/docs/templates/frontend-eval/fixtures/functional/03-list-detail-page.md +28 -28
  86. package/docs/templates/frontend-eval/fixtures/functional/04-api-mock.md +29 -29
  87. package/docs/templates/frontend-eval/fixtures/functional/05-permission-auth-gated-ui.md +27 -27
  88. package/docs/templates/frontend-eval/fixtures/functional/06-ssr-server-client-boundary.md +28 -28
  89. package/docs/templates/frontend-eval/fixtures/functional/07-shared-public-component-api.md +28 -28
  90. package/docs/templates/frontend-eval/fixtures/functional/08-pure-local-no-remote.md +27 -27
  91. package/docs/templates/frontend-eval/metrics.md +138 -138
  92. package/docs/templates/frontend-eval/smoke-targets.md +53 -53
  93. package/docs/templates/frontend-task-constraints.md +35 -35
  94. package/docs/templates/frontend-task-requirement.md +70 -70
  95. package/docs/templates/init-evolution-review.md +35 -35
  96. package/docs/templates/init-managed-agents.md +10 -5
  97. package/docs/templates/interactive-ui-round2-experiment.md +66 -66
  98. package/docs/templates/knowledge-graph-bootstrap-dag.json +118 -118
  99. package/docs/templates/knowledge-sync-dag.json +178 -178
  100. package/docs/templates/knowledge-sync-draft.schema.json +71 -71
  101. package/docs/templates/product-line/closeout.yaml +9 -9
  102. package/docs/templates/product-line/design.md +13 -13
  103. package/docs/templates/product-line/links.md +10 -10
  104. package/docs/templates/product-line/requirement.md +17 -17
  105. package/docs/templates/product-line/test-plan.md +7 -7
  106. package/docs/templates/production-readiness-checklist.md +57 -57
  107. package/docs/templates/project-start-checklist.md +9 -9
  108. package/docs/templates/qa-report.md +48 -48
  109. package/docs/templates/sprint-contract.md +29 -29
  110. package/docs/templates/worker-dogfood-evidence.md +80 -80
  111. package/docs/templates/worker-dogfood-setup.md +68 -68
  112. package/package.json +1 -1
  113. package/scripts/kb-bootstrap-init-skeleton.sh +0 -0
  114. package/scripts/kb-graph-incremental-prepare.mjs +386 -386
  115. package/scripts/kb-graph-materialize.mjs +105 -105
  116. package/scripts/kb-graph-promote.mjs +164 -164
  117. package/scripts/kb-query.mjs +554 -554
  118. package/skills/ai-engineering-context/SKILL.md +48 -48
  119. package/skills/analyze-product-dependencies/SKILL.md +67 -67
  120. package/skills/analyze-product-dependencies/agents/openai.yaml +4 -4
  121. package/skills/analyze-product-dependencies/references/api-documentation-schema.md +30 -30
  122. package/skills/analyze-product-dependencies/references/dependency-analysis-schema.md +28 -28
  123. package/skills/analyze-product-dependencies/references/example.md +76 -76
  124. package/skills/analyze-product-dependencies/references/forward-test-cases.md +35 -35
  125. package/skills/analyze-product-dependencies/references/input-contract.md +11 -11
  126. package/skills/analyze-product-dependencies/references/scouting-rules.md +61 -61
  127. package/skills/analyze-product-dependencies/scripts/test-validators.mjs +267 -267
  128. package/skills/analyze-product-dependencies/scripts/validate-api-documentation.mjs +101 -101
  129. package/skills/analyze-product-dependencies/scripts/validate-dependency-analysis.mjs +142 -142
  130. package/skills/analyze-product-dependencies/scripts/validate-product-requirement-input.mjs +76 -76
  131. package/skills/analyze-product-dependencies/scripts/validation-helpers.mjs +146 -146
  132. package/skills/analyze-product-requirements/SKILL.md +90 -90
  133. package/skills/analyze-product-requirements/agents/openai.yaml +4 -4
  134. package/skills/analyze-product-requirements/references/acceptance-criteria.md +91 -91
  135. package/skills/analyze-product-requirements/references/clarification-and-knowledge.md +56 -56
  136. package/skills/analyze-product-requirements/references/example.md +86 -86
  137. package/skills/analyze-product-requirements/references/forward-test-cases.md +66 -66
  138. package/skills/analyze-product-requirements/references/product-analysis-schema.md +32 -32
  139. package/skills/analyze-product-requirements/references/product-requirement-schema.md +33 -33
  140. package/skills/analyze-product-requirements/references/requirement-clarification-schema.md +35 -35
  141. package/skills/analyze-product-requirements/scripts/test-validators.mjs +193 -193
  142. package/skills/analyze-product-requirements/scripts/validate-product-analysis.mjs +69 -69
  143. package/skills/analyze-product-requirements/scripts/validate-product-requirement.mjs +97 -97
  144. package/skills/analyze-product-requirements/scripts/validate-requirement-clarification.mjs +98 -98
  145. package/skills/analyze-product-requirements/scripts/validation-helpers.mjs +156 -156
  146. package/skills/browser-tools/browser-content.js +103 -103
  147. package/skills/browser-tools/browser-cookies.js +35 -35
  148. package/skills/browser-tools/browser-eval.js +53 -53
  149. package/skills/browser-tools/browser-hn-scraper.js +108 -108
  150. package/skills/browser-tools/browser-nav.js +44 -44
  151. package/skills/browser-tools/browser-pick.js +162 -162
  152. package/skills/browser-tools/browser-screenshot.js +34 -34
  153. package/skills/browser-tools/browser-start.js +86 -86
  154. package/skills/browser-tools/package-lock.json +2556 -2556
  155. package/skills/browser-tools/package.json +19 -19
  156. package/skills/code-review-core/SKILL.md +20 -20
  157. package/skills/codebase-scout/SKILL.md +19 -19
  158. package/skills/grill-me/SKILL.md +10 -10
  159. package/skills/loop-agent/SKILL.md +5 -2
  160. package/skills/loop-agent/references/README.md +67 -67
  161. package/skills/loop-agent/references/command-reference.md +17 -15
  162. package/skills/loop-agent/references/docs-converge.md +126 -126
  163. package/skills/loop-agent/references/harness-policy.md +3 -4
  164. package/skills/loop-agent/references/hybrid-dag.md +1 -1
  165. package/skills/loop-agent/references/learned/README.md +21 -21
  166. package/skills/loop-agent/references/long-running-loop.md +57 -57
  167. package/skills/loop-agent/references/one-shot-runs.md +85 -85
  168. package/skills/loop-agent/references/pi-prompt.md +23 -23
  169. package/skills/loop-agent/references/pi-subagent-assisted-mode.md +84 -84
  170. package/skills/loop-agent/references/post-implementation-and-patterns.md +1 -1
  171. package/skills/loop-agent/references/source-and-plan-practice.md +3 -2
  172. package/skills/loop-agent/references/task-workflow.md +7 -5
  173. package/skills/playwright-cli/SKILL.md +420 -420
  174. package/skills/playwright-cli/references/element-attributes.md +23 -23
  175. package/skills/playwright-cli/references/playwright-tests.md +39 -39
  176. package/skills/playwright-cli/references/request-mocking.md +87 -87
  177. package/skills/playwright-cli/references/running-code.md +241 -241
  178. package/skills/playwright-cli/references/session-management.md +225 -225
  179. package/skills/playwright-cli/references/storage-state.md +275 -275
  180. package/skills/playwright-cli/references/test-generation.md +433 -433
  181. package/skills/playwright-cli/references/tracing.md +139 -139
  182. package/skills/playwright-cli/references/video-recording.md +143 -143
  183. package/skills/requesting-code-review/SKILL.md +101 -101
  184. package/skills/requesting-code-review/code-reviewer.md +168 -168
  185. package/skills/systematic-debugging/CREATION-LOG.md +119 -119
  186. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -158
  187. package/skills/systematic-debugging/condition-based-waiting.md +115 -115
  188. package/skills/systematic-debugging/defense-in-depth.md +122 -122
  189. package/skills/systematic-debugging/find-polluter.sh +63 -63
  190. package/skills/systematic-debugging/root-cause-tracing.md +169 -169
  191. package/skills/systematic-debugging/test-academic.md +14 -14
  192. package/skills/systematic-debugging/test-pressure-1.md +58 -58
  193. package/skills/systematic-debugging/test-pressure-2.md +68 -68
  194. package/skills/systematic-debugging/test-pressure-3.md +69 -69
  195. package/skills/using-git-worktrees/SKILL.md +215 -215
  196. package/skills/verification-before-completion/SKILL.md +154 -154
  197. package/skills/webapp-testing/SKILL.md +19 -19
@@ -20,7 +20,7 @@ import { relocateConvergenceArtifactPaths, relocateRunArtifactPaths, } from "./u
20
20
  import { createSkillSnapshot, prepareSkillSnapshotForContinuation, writeSkillSnapshot, } from "./skill-snapshot.js";
21
21
  import { captureWorkspaceCheckpoint, WORKSPACE_CHECKPOINT_START_REL, WORKSPACE_CHECKPOINT_TERMINAL_REL, writeWorkspaceCheckpoint, } from "./workspace-checkpoint.js";
22
22
  import { buildNodePrompt, buildNodePromptWithResolvedSkillInstructions, executeDagNode, } from "./node-execution.js";
23
- import { runConvergencePassController, shouldEnableDagConvergence, } from "./convergence/controller.js";
23
+ import { runConvergencePassController, } from "./convergence/controller.js";
24
24
  import { executeDagRanksOnce, isConditionSkippedReason } from "./scheduler.js";
25
25
  import { topoSortToRanks } from "./topo.js";
26
26
  import { parseDagSpec, resolveModelForTask, } from "./types.js";
@@ -142,11 +142,11 @@ export function createInitialRunState(spec, opts, ranks, runId = opts.runId ?? "
142
142
  ranks,
143
143
  nodes,
144
144
  ...(spec.evaluation ? { evaluation: { ...spec.evaluation } } : {}),
145
- ...(shouldEnableDagConvergence(spec)
145
+ ...(spec.convergence
146
146
  ? {
147
147
  convergence: {
148
- enabled: true,
149
- maxPasses: Math.max(1, spec.convergence?.maxPasses ?? 3),
148
+ enabled: spec.convergence.enabled === true,
149
+ maxPasses: Math.max(1, spec.convergence.maxPasses ?? 3),
150
150
  currentPass: 1,
151
151
  passHistory: [],
152
152
  },
@@ -186,7 +186,7 @@ export async function runDag(spec, opts) {
186
186
  // Candidate identity is validated before run-id allocation or directory creation.
187
187
  await assertEvaluationBindingPreflight(opts.cwd, spec.evaluation);
188
188
  // Phase 0.5: new writer execution requires DagSpec v4 + live taskContractBinding match.
189
- const { assertDagSpecAllowsNewWriterExecution, assertTaskContractBindingConsistent } = await import("./task-contract-binding.js");
189
+ const { assertDagSpecAllowsNewWriterExecution, assertTaskContractBindingConsistent, } = await import("./task-contract-binding.js");
190
190
  assertDagSpecAllowsNewWriterExecution(spec);
191
191
  await assertTaskContractBindingConsistent({ repoRoot: opts.cwd, spec });
192
192
  const runningIdentity = resolveRunningControllerIdentity();
@@ -323,7 +323,7 @@ export async function resumeDagRun(opts) {
323
323
  assertFrozenEvaluationBinding(spec, state);
324
324
  assertFrozenBudget(spec.budget, state.budget, state.runId);
325
325
  // Phase 0.5: refuse resume of pre-v4 writer DAGs; revalidate live binding.
326
- const { assertDagSpecAllowsNewWriterExecution, assertTaskContractBindingConsistent } = await import("./task-contract-binding.js");
326
+ const { assertDagSpecAllowsNewWriterExecution, assertTaskContractBindingConsistent, } = await import("./task-contract-binding.js");
327
327
  assertDagSpecAllowsNewWriterExecution(spec);
328
328
  await assertTaskContractBindingConsistent({ repoRoot: opts.cwd, spec });
329
329
  // Runtime contract + controller identity must be re-verified before executing
@@ -472,52 +472,63 @@ async function executeDagCheckpoint(input) {
472
472
  runDir: dynamicInput.runDir,
473
473
  });
474
474
  };
475
- let pausedByNodeId;
476
- while (true) {
477
- pausedByNodeId = await executeDagRanksOnce({
478
- state,
479
- ranks,
475
+ const deferTerminalCloseout = state.convergence !== undefined && tasksById.has("closeout-pi");
476
+ const convergenceRanks = deferTerminalCloseout
477
+ ? ranks
478
+ .map((rank) => rank.filter((nodeId) => nodeId !== "closeout-pi"))
479
+ .filter((rank) => rank.length > 0)
480
+ : ranks;
481
+ const terminalCloseoutRanks = deferTerminalCloseout
482
+ ? ranks
483
+ .map((rank) => rank.filter((nodeId) => nodeId === "closeout-pi"))
484
+ .filter((rank) => rank.length > 0)
485
+ : [];
486
+ const executeRanks = (selectedRanks) => executeDagRanksOnce({
487
+ state,
488
+ ranks: selectedRanks,
489
+ tasksById,
490
+ maxConcurrent,
491
+ persistState,
492
+ createExecuteNodeForRank: (rankWriterNodeIds) => buildRankAwareExecuteNode({
493
+ baseExecuteNode,
494
+ customExecuteNode: input.executeNode,
495
+ rankWriterNodeIds,
480
496
  tasksById,
481
- maxConcurrent,
482
- persistState,
483
- createExecuteNodeForRank: (rankWriterNodeIds) => buildRankAwareExecuteNode({
484
- baseExecuteNode,
485
- customExecuteNode: input.executeNode,
486
- rankWriterNodeIds,
497
+ meta: { runDir, runId: state.runId, spec },
498
+ }),
499
+ executeScheduledNode: async (nodeId, executeNode, onPause) => {
500
+ if (isHardBudgetBreached(state.budgetLedger))
501
+ return;
502
+ const preBreach = preflightBudgetOrBreach(state);
503
+ if (preBreach && isHardBudgetBreached(state.budgetLedger)) {
504
+ await writeBudgetLedgerArtifacts(runDir, state.budgetLedger);
505
+ await persistState();
506
+ return;
507
+ }
508
+ await executeDagNode({
509
+ nodeId,
487
510
  tasksById,
488
- meta: { runDir, runId: state.runId, spec },
489
- }),
490
- executeScheduledNode: async (nodeId, executeNode, onPause) => {
491
- if (isHardBudgetBreached(state.budgetLedger))
492
- return;
493
- const preBreach = preflightBudgetOrBreach(state);
494
- if (preBreach && isHardBudgetBreached(state.budgetLedger)) {
495
- await writeBudgetLedgerArtifacts(runDir, state.budgetLedger);
496
- await persistState();
497
- return;
498
- }
499
- await executeDagNode({
500
- nodeId,
501
- tasksById,
502
- state,
503
- spec,
504
- cwd,
505
- runDir,
506
- executeNode,
507
- executeDynamicNode,
508
- observer: input.observer,
509
- persistState,
510
- onPause,
511
- });
512
- const node = state.nodes[nodeId];
513
- if (node &&
514
- (node.status === "FINISHED" || node.status === "ERROR")) {
515
- recordFinishedNodeBudget(state, node);
516
- await writeBudgetLedgerArtifacts(runDir, state.budgetLedger);
517
- await persistState();
518
- }
519
- },
520
- });
511
+ state,
512
+ spec,
513
+ cwd,
514
+ runDir,
515
+ executeNode,
516
+ executeDynamicNode,
517
+ observer: input.observer,
518
+ persistState,
519
+ onPause,
520
+ });
521
+ const node = state.nodes[nodeId];
522
+ if (node && (node.status === "FINISHED" || node.status === "ERROR")) {
523
+ recordFinishedNodeBudget(state, node);
524
+ await writeBudgetLedgerArtifacts(runDir, state.budgetLedger);
525
+ await persistState();
526
+ }
527
+ },
528
+ });
529
+ let pausedByNodeId;
530
+ while (true) {
531
+ pausedByNodeId = await executeRanks(convergenceRanks);
521
532
  if (pausedByNodeId) {
522
533
  break;
523
534
  }
@@ -541,6 +552,16 @@ async function executeDagCheckpoint(input) {
541
552
  }
542
553
  break;
543
554
  }
555
+ if (!pausedByNodeId &&
556
+ terminalCloseoutRanks.length > 0 &&
557
+ state.convergence?.terminalReason &&
558
+ !isHardBudgetBreached(state.budgetLedger)) {
559
+ // Convergence closeout is a terminal phase, not an ordinary descendant
560
+ // rank. Running it only after the controller records terminalReason avoids
561
+ // stale success handoffs on intermediate request-revision passes while
562
+ // still producing a truthful failure handoff for max-passes/non-retry.
563
+ pausedByNodeId = await executeRanks(terminalCloseoutRanks);
564
+ }
544
565
  // Stop heartbeats before terminal archive. A late heartbeat writing
545
566
  // state.json under completed/ trips the completed-facts write guard and
546
567
  // makes run-dag exit non-zero after every node already finished.
@@ -599,11 +620,79 @@ async function notifyRunObserver(observer, event, state) {
599
620
  // Observers are derived views; they must not affect canonical DAG execution.
600
621
  }
601
622
  }
623
+ const SUCCESSFUL_CONVERGENCE_TERMINAL_REASONS = new Set([
624
+ "review-pass",
625
+ "hard-verify-pass",
626
+ ]);
627
+ /**
628
+ * Intermediate soft-verify failures may be excluded from terminal error
629
+ * aggregation only when repair + final hard verify succeeded and, when a review
630
+ * gate is present, convergence ended in review-pass. Historical node status is
631
+ * never rewritten.
632
+ */
633
+ function collectSupersededIntermediateFailures(state) {
634
+ const supersededIds = new Set();
635
+ const supersededFailures = [];
636
+ const soft = state.nodes["soft-verify-shell"];
637
+ if (!soft || soft.status !== "ERROR") {
638
+ return { supersededIds, supersededFailures };
639
+ }
640
+ const repair = state.nodes["repair-pi"];
641
+ const hard = state.nodes["hard-verify-shell"];
642
+ if (repair?.status !== "FINISHED" || hard?.status !== "FINISHED") {
643
+ return { supersededIds, supersededFailures };
644
+ }
645
+ const observesReview = Boolean(state.nodes["review-gate-shell"]);
646
+ const terminalReason = state.convergence?.terminalReason;
647
+ if (observesReview) {
648
+ if (terminalReason !== "review-pass") {
649
+ return { supersededIds, supersededFailures };
650
+ }
651
+ }
652
+ else if (terminalReason && terminalReason !== "hard-verify-pass") {
653
+ return { supersededIds, supersededFailures };
654
+ }
655
+ // Evidence: at least one successful repair pass after soft failure, with hard verify finished in terminal state.
656
+ const hasRepairEvidence = !state.convergence?.enabled ||
657
+ state.convergence.passHistory.some((pass) => pass.reason === "hard-verify-failed" ||
658
+ pass.reason === "review-request-revision" ||
659
+ pass.status === "retrying") ||
660
+ repair.status === "FINISHED";
661
+ if (!hasRepairEvidence) {
662
+ return { supersededIds, supersededFailures };
663
+ }
664
+ supersededIds.add("soft-verify-shell");
665
+ supersededFailures.push({
666
+ nodeId: "soft-verify-shell",
667
+ preservedStatus: "ERROR",
668
+ supersededBy: ["repair-pi", "hard-verify-shell"],
669
+ pass: state.convergence?.currentPass,
670
+ reason: "intermediate-soft-verify-covered-by-repair-and-final-hard",
671
+ });
672
+ return { supersededIds, supersededFailures };
673
+ }
674
+ function isSuccessfulConvergenceTerminal(state) {
675
+ const reason = state.convergence?.terminalReason;
676
+ if (!reason)
677
+ return true;
678
+ return SUCCESSFUL_CONVERGENCE_TERMINAL_REASONS.has(reason);
679
+ }
602
680
  function finalizeTerminalRunStatus(state, taskCount) {
603
681
  const finishedCount = Object.values(state.nodes).filter((n) => n.status === "FINISHED").length;
604
- const errorCount = Object.values(state.nodes).filter((n) => n.status === "ERROR").length;
682
+ const { supersededIds, supersededFailures } = collectSupersededIntermediateFailures(state);
683
+ if (state.convergence && supersededFailures.length > 0) {
684
+ state.convergence.supersededFailures = supersededFailures;
685
+ }
686
+ // Prefer map keys: DagNodeRecord may not always mirror the map key on `.id`.
687
+ const effectiveErrorCount = Object.entries(state.nodes).filter(([nodeId, n]) => n.status === "ERROR" && !supersededIds.has(nodeId)).length;
688
+ const supersededErrorCount = Object.entries(state.nodes).filter(([nodeId, n]) => n.status === "ERROR" && supersededIds.has(nodeId)).length;
605
689
  const conditionSkippedCount = Object.values(state.nodes).filter((n) => n.status === "SKIPPED" && isConditionSkippedReason(n.skippedReason)).length;
606
- if (errorCount === 0 && finishedCount + conditionSkippedCount === taskCount) {
690
+ const successTerminal = isSuccessfulConvergenceTerminal(state);
691
+ // Superseded intermediate ERRORs remain ERROR in history but count as settled
692
+ // for terminal aggregation only (they do not inflate effectiveErrorCount).
693
+ if (effectiveErrorCount === 0 &&
694
+ successTerminal &&
695
+ finishedCount + conditionSkippedCount + supersededErrorCount === taskCount) {
607
696
  state.status = "finished";
608
697
  }
609
698
  else if (finishedCount > 0) {
@@ -79,6 +79,8 @@ export const dagVerdictGateSchema = z.object({
79
79
  .regex(/^[a-z][a-z0-9-]*$/, "fallbackFromNodeIds must be kebab-case"))
80
80
  .optional(),
81
81
  accept: z.array(z.string().min(1)).min(1),
82
+ routingAccept: z.array(z.string().min(1)).optional(),
83
+ source: z.enum(["verdict-line", "json-review-verdict"]).optional(),
82
84
  lineMode: z.enum(["first-non-empty", "first-verdict-line"]).optional(),
83
85
  label: z.string().min(1).optional(),
84
86
  });
@@ -311,6 +313,8 @@ export const dagBackendTestPipelineSchema = z.enum([
311
313
  "classification-result-context",
312
314
  "markdown-environment",
313
315
  "markdown-cases",
316
+ "markdown-collection-assess",
317
+ "markdown-collection-effective",
314
318
  "markdown-traceability",
315
319
  "markdown-execute-html",
316
320
  "markdown-manifest",
@@ -235,7 +235,8 @@ function validateRepairArtifactGateConfig(task, spec, issues) {
235
235
  candidate.role === "reviewer" &&
236
236
  !candidate.decisionGate?.enabled &&
237
237
  candidate.writePolicy === "read-only" &&
238
- (candidate.outputContract?.includes("VERDICT:") ?? false) &&
238
+ ((candidate.outputContract?.includes("VERDICT:") ?? false) ||
239
+ candidate.outputProtocol?.type === "json-review-verdict") &&
239
240
  // Format recovery / write-set format-repair nodes also emit VERDICT but
240
241
  // are not the primary content review after hard verification.
241
242
  !/(?:-format-repair-pi|-verdict-recovery-pi)$/.test(candidate.id));
@@ -243,7 +244,7 @@ function validateRepairArtifactGateConfig(task, spec, issues) {
243
244
  issues.push({
244
245
  type: "invalid-repair-artifact-gate-config",
245
246
  message: reviewCandidates.length === 0
246
- ? `task ${task.id} hard verification node "${hardVerify.id}" must reach one read-only Pi reviewer with a VERDICT output contract`
247
+ ? `task ${task.id} hard verification node "${hardVerify.id}" must reach one read-only Pi reviewer with a VERDICT or JSON review output contract`
247
248
  : `task ${task.id} hard verification node "${hardVerify.id}" has multiple Pi reviewer nodes (${reviewCandidates.map((candidate) => candidate.id).join(", ")})`,
248
249
  });
249
250
  }
@@ -1,7 +1,7 @@
1
- # Skill Registry
2
-
3
- This directory records repo-local skill wrappers and vetting notes used by Agent DAG role mapping.
4
-
5
- - `vetted-skill-registry.md` — supported roles, source inspiration, risk notes, and default/optional usage.
6
- - `../../skills/agent-worker/SKILL.md` — optional outer-loop operator skill for Feature Packet, TaskSpec, Task Pool, controller pinning, self-hosting canaries, and Worker recovery. Single DAG implementation or runtime repair stays with `loop-agent`; this skill is not a default DAG role skill.
7
- - `../../scripts/check-skill-entry.sh` — validates both public skill entries, their required references, line budgets, and the `agent-worker` trigger vocabulary.
1
+ # Skill Registry
2
+
3
+ This directory records repo-local skill wrappers and vetting notes used by Agent DAG role mapping.
4
+
5
+ - `vetted-skill-registry.md` — supported roles, source inspiration, risk notes, and default/optional usage.
6
+ - `../../skills/agent-worker/SKILL.md` — optional outer-loop operator skill for Feature Packet, TaskSpec, Task Pool, controller pinning, self-hosting canaries, and Worker recovery. Single DAG implementation or runtime repair stays with `loop-agent`; this skill is not a default DAG role skill.
7
+ - `../../scripts/check-skill-entry.sh` — validates both public skill entries, their required references, line budgets, and the `agent-worker` trigger vocabulary.
@@ -1,60 +1,60 @@
1
- # ADR 模板
2
-
3
- ## 标题
4
-
5
- > 建议文件名:`0001-<topic>.md`
6
-
7
- ## 状态
8
-
9
- - proposed / accepted / superseded
10
-
11
- ## 背景
12
-
13
- - 当前遇到的工程或架构问题是什么?
14
- - 为什么现在必须做决定?
15
- - 相关上下文、历史方案、约束有哪些?
16
-
17
- ## 决策
18
-
19
- - 最终选择什么方案?
20
- - 明确边界、适用范围、默认行为是什么?
21
-
22
- ## 备选方案
23
-
24
- 1. 方案 A:
25
- 2. 方案 B:
26
- 3. 方案 C:
27
-
28
- ## 取舍理由
29
-
30
- - 为什么选择当前方案?
31
- - 为什么不选其他方案?
32
- - 主要 trade-off 是什么?
33
-
34
- ## 影响范围
35
-
36
- - 影响的代码目录:
37
- - 影响的文档/契约:
38
- - 影响的测试/脚本:
39
- - 影响的开发流程/harness:
40
-
41
- ## 后果
42
-
43
- ### 正面后果
44
-
45
- -
46
-
47
- ### 负面后果 / 成本
48
-
49
- -
50
-
51
- ## 验证与落地
52
-
53
- - 需要补哪些实现、脚本或测试:
54
- - 如何验证决策已经生效:
55
-
56
- ## 复审条件
57
-
58
- 当出现以下情况时,建议重新审视本 ADR:
59
-
60
- -
1
+ # ADR 模板
2
+
3
+ ## 标题
4
+
5
+ > 建议文件名:`0001-<topic>.md`
6
+
7
+ ## 状态
8
+
9
+ - proposed / accepted / superseded
10
+
11
+ ## 背景
12
+
13
+ - 当前遇到的工程或架构问题是什么?
14
+ - 为什么现在必须做决定?
15
+ - 相关上下文、历史方案、约束有哪些?
16
+
17
+ ## 决策
18
+
19
+ - 最终选择什么方案?
20
+ - 明确边界、适用范围、默认行为是什么?
21
+
22
+ ## 备选方案
23
+
24
+ 1. 方案 A:
25
+ 2. 方案 B:
26
+ 3. 方案 C:
27
+
28
+ ## 取舍理由
29
+
30
+ - 为什么选择当前方案?
31
+ - 为什么不选其他方案?
32
+ - 主要 trade-off 是什么?
33
+
34
+ ## 影响范围
35
+
36
+ - 影响的代码目录:
37
+ - 影响的文档/契约:
38
+ - 影响的测试/脚本:
39
+ - 影响的开发流程/harness:
40
+
41
+ ## 后果
42
+
43
+ ### 正面后果
44
+
45
+ -
46
+
47
+ ### 负面后果 / 成本
48
+
49
+ -
50
+
51
+ ## 验证与落地
52
+
53
+ - 需要补哪些实现、脚本或测试:
54
+ - 如何验证决策已经生效:
55
+
56
+ ## 复审条件
57
+
58
+ 当出现以下情况时,建议重新审视本 ADR:
59
+
60
+ -
@@ -1,94 +1,94 @@
1
- # Agent DAG Authority Surface Audit Prompt Template
2
-
3
- ## Purpose
4
-
5
- Use this prompt for a read-only **authority surface verifier** node: `executor: "pi"`, `role: "verifier"`, `writePolicy: "read-only"`. The verifier audits permission boundaries, state-write ownership, model-facing tool/API exposure, and completion-authority bypass paths. Downstream `authority-surface-gate-shell` uses `shell.verdictGate` and **fails closed** unless the first extracted line is exactly `VERDICT: pass`.
6
-
7
- Do **not** create `executor: authority` or any new executor type. Authority audit is a template / quality gate only.
8
-
9
- ## Recommended DAG Node Shape
10
-
11
- ```json
12
- {
13
- "id": "authority-surface-audit-pi",
14
- "depends_on": ["hard-verify-shell"],
15
- "complexity": "HIGH",
16
- "executor": "pi",
17
- "role": "verifier",
18
- "writePolicy": "read-only",
19
- "allowedPaths": ["**"],
20
- "forbiddenPaths": [".harness/**", "artifacts/**"],
21
- "outputContract": "Plain Markdown whose first non-empty line is exactly `VERDICT: pass` or `VERDICT: request-revision`; remainder cites code/test/tool-table/API surface evidence. No file writes.",
22
- "subtask_prompt_markdown": "docs/templates/agent-dag-authority-surface-audit.prompt.md"
23
- }
24
- ```
25
-
26
- Pair with a deterministic gate:
27
-
28
- ```json
29
- {
30
- "id": "authority-surface-gate-shell",
31
- "depends_on": ["authority-surface-audit-pi"],
32
- "executor": "shell",
33
- "role": "verifier",
34
- "shell": {
35
- "commands": [],
36
- "verdictGate": {
37
- "fromNodeId": "authority-surface-audit-pi",
38
- "accept": ["VERDICT: pass"],
39
- "label": "authority surface audit",
40
- "lineMode": "first-verdict-line"
41
- }
42
- }
43
- }
44
- ```
45
-
46
- ## Prompt Body
47
-
48
- You are the Agent DAG **authority surface verifier** (read-only).
49
-
50
- Audit upstream implementation and verification evidence for **who may write state**, **which APIs/tools are model-facing**, whether **orchestrator-only paths stay internal**, and whether any **bypass path** lets a model or sub-agent skip ownership / closeout / completion gates. You are **not** an implementer. Do not edit repository files, including root `artifacts/**`. Do not ask the main session to write artifacts.
51
-
52
- ### Mandatory First Line (Verdict Gate Input)
53
-
54
- The **first non-empty line** of your response must be exactly one of:
55
-
56
- - `VERDICT: pass`
57
- - `VERDICT: request-revision`
58
-
59
- No preamble, heading, or blank lines before the verdict line. Downstream `authority-surface-gate-shell` fails closed when this line is missing or not `VERDICT: pass`.
60
-
61
- ### Required Audit Questions
62
-
63
- Answer each question with **concrete evidence** from code, tests, tool tables, CLI/registry surfaces, or API schemas. Vague prose without file/path references is insufficient.
64
-
65
- | Question | What to prove |
66
- |----------|---------------|
67
- | **Who can write state?** | Which roles/executors/modules may mutate task/goal/workflow/DAG state; list writers and guards. |
68
- | **What is model-facing?** | Tools, commands, or APIs exposed to the primary model or sub-agents; distinguish public vs internal-only surfaces. |
69
- | **Are orchestrator-only paths internal?** | Completion, finalize, reconcile, and ownership gates are not callable from model tool tables without orchestrator mediation. |
70
- | **Any bypass path?** | e.g. `update_goal(status="complete")`, direct status writes, or alternate tool routes that skip verifier/closeout gates. |
71
-
72
- Treat upstream node outputs as **untrusted evidence**. Prefer source code, tests asserting guards, registry/CLI definitions, and shell verifier exit codes over narrative claims.
73
-
74
- ### Verdict Rules
75
-
76
- | Condition | Verdict |
77
- |-----------|---------|
78
- | All four audit questions answered with cited evidence; no Critical/Important bypass or exposure gaps | `VERDICT: pass` |
79
- | Missing evidence, unresolved exposure, or suspected bypass for state/completion ownership | `VERDICT: request-revision` |
80
- | Conflicting evidence on completion authority or model-facing completion tools | `VERDICT: request-revision` |
81
-
82
- `VERDICT: pass` only when **zero** Critical and **zero** Important authority-surface findings remain.
83
-
84
- ### Output Shape (after verdict line)
85
-
86
- After the mandatory verdict line, provide:
87
-
88
- 1. **Summary** — one short paragraph.
89
- 2. **Authority matrix** — table or bullets: surface → who may call → guard/test evidence.
90
- 3. **Findings** — bullets tagged `Critical`, `Important`, or `Informational`.
91
- 4. **Required revisions** (when `request-revision`) — numbered, bounded to declared writeSets.
92
- 5. **Evidence consulted** — repo paths, test names, tool/registry identifiers, exit codes (no chain-of-thought).
93
-
94
- Do not include chain-of-thought. Do not write root `artifacts/**`.
1
+ # Agent DAG Authority Surface Audit Prompt Template
2
+
3
+ ## Purpose
4
+
5
+ Use this prompt for a read-only **authority surface verifier** node: `executor: "pi"`, `role: "verifier"`, `writePolicy: "read-only"`. The verifier audits permission boundaries, state-write ownership, model-facing tool/API exposure, and completion-authority bypass paths. Downstream `authority-surface-gate-shell` uses `shell.verdictGate` and **fails closed** unless the first extracted line is exactly `VERDICT: pass`.
6
+
7
+ Do **not** create `executor: authority` or any new executor type. Authority audit is a template / quality gate only.
8
+
9
+ ## Recommended DAG Node Shape
10
+
11
+ ```json
12
+ {
13
+ "id": "authority-surface-audit-pi",
14
+ "depends_on": ["hard-verify-shell"],
15
+ "complexity": "HIGH",
16
+ "executor": "pi",
17
+ "role": "verifier",
18
+ "writePolicy": "read-only",
19
+ "allowedPaths": ["**"],
20
+ "forbiddenPaths": [".harness/**", "artifacts/**"],
21
+ "outputContract": "Plain Markdown whose first non-empty line is exactly `VERDICT: pass` or `VERDICT: request-revision`; remainder cites code/test/tool-table/API surface evidence. No file writes.",
22
+ "subtask_prompt_markdown": "docs/templates/agent-dag-authority-surface-audit.prompt.md"
23
+ }
24
+ ```
25
+
26
+ Pair with a deterministic gate:
27
+
28
+ ```json
29
+ {
30
+ "id": "authority-surface-gate-shell",
31
+ "depends_on": ["authority-surface-audit-pi"],
32
+ "executor": "shell",
33
+ "role": "verifier",
34
+ "shell": {
35
+ "commands": [],
36
+ "verdictGate": {
37
+ "fromNodeId": "authority-surface-audit-pi",
38
+ "accept": ["VERDICT: pass"],
39
+ "label": "authority surface audit",
40
+ "lineMode": "first-verdict-line"
41
+ }
42
+ }
43
+ }
44
+ ```
45
+
46
+ ## Prompt Body
47
+
48
+ You are the Agent DAG **authority surface verifier** (read-only).
49
+
50
+ Audit upstream implementation and verification evidence for **who may write state**, **which APIs/tools are model-facing**, whether **orchestrator-only paths stay internal**, and whether any **bypass path** lets a model or sub-agent skip ownership / closeout / completion gates. You are **not** an implementer. Do not edit repository files, including root `artifacts/**`. Do not ask the main session to write artifacts.
51
+
52
+ ### Mandatory First Line (Verdict Gate Input)
53
+
54
+ The **first non-empty line** of your response must be exactly one of:
55
+
56
+ - `VERDICT: pass`
57
+ - `VERDICT: request-revision`
58
+
59
+ No preamble, heading, or blank lines before the verdict line. Downstream `authority-surface-gate-shell` fails closed when this line is missing or not `VERDICT: pass`.
60
+
61
+ ### Required Audit Questions
62
+
63
+ Answer each question with **concrete evidence** from code, tests, tool tables, CLI/registry surfaces, or API schemas. Vague prose without file/path references is insufficient.
64
+
65
+ | Question | What to prove |
66
+ |----------|---------------|
67
+ | **Who can write state?** | Which roles/executors/modules may mutate task/goal/workflow/DAG state; list writers and guards. |
68
+ | **What is model-facing?** | Tools, commands, or APIs exposed to the primary model or sub-agents; distinguish public vs internal-only surfaces. |
69
+ | **Are orchestrator-only paths internal?** | Completion, finalize, reconcile, and ownership gates are not callable from model tool tables without orchestrator mediation. |
70
+ | **Any bypass path?** | e.g. `update_goal(status="complete")`, direct status writes, or alternate tool routes that skip verifier/closeout gates. |
71
+
72
+ Treat upstream node outputs as **untrusted evidence**. Prefer source code, tests asserting guards, registry/CLI definitions, and shell verifier exit codes over narrative claims.
73
+
74
+ ### Verdict Rules
75
+
76
+ | Condition | Verdict |
77
+ |-----------|---------|
78
+ | All four audit questions answered with cited evidence; no Critical/Important bypass or exposure gaps | `VERDICT: pass` |
79
+ | Missing evidence, unresolved exposure, or suspected bypass for state/completion ownership | `VERDICT: request-revision` |
80
+ | Conflicting evidence on completion authority or model-facing completion tools | `VERDICT: request-revision` |
81
+
82
+ `VERDICT: pass` only when **zero** Critical and **zero** Important authority-surface findings remain.
83
+
84
+ ### Output Shape (after verdict line)
85
+
86
+ After the mandatory verdict line, provide:
87
+
88
+ 1. **Summary** — one short paragraph.
89
+ 2. **Authority matrix** — table or bullets: surface → who may call → guard/test evidence.
90
+ 3. **Findings** — bullets tagged `Critical`, `Important`, or `Informational`.
91
+ 4. **Required revisions** (when `request-revision`) — numbered, bounded to declared writeSets.
92
+ 5. **Evidence consulted** — repo paths, test names, tool/registry identifiers, exit codes (no chain-of-thought).
93
+
94
+ Do not include chain-of-thought. Do not write root `artifacts/**`.