@tea-agent/loop-agent 0.42.0-next.1 → 0.42.0-next.11

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 (247) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +321 -1
  3. package/dist/application/dag/generate-task-dag.js +75 -19
  4. package/dist/application/dag/run-dag.js +41 -0
  5. package/dist/application/task-lifecycle/advance.js +24 -5
  6. package/dist/application/task-lifecycle/observe.js +171 -17
  7. package/dist/application/task-lifecycle/plan-transitions.js +42 -7
  8. package/dist/application/task-lifecycle/recommendations.js +13 -2
  9. package/dist/build-stamp.json +3 -3
  10. package/dist/cli/command-definitions.js +7 -0
  11. package/dist/cli/program.js +6 -1
  12. package/dist/commands/client-recovery.js +3 -0
  13. package/dist/commands/dag-follow-up.js +138 -0
  14. package/dist/commands/dag-rerun-task.js +2 -0
  15. package/dist/commands/init.js +27 -1
  16. package/dist/commands/task-advance.js +19 -0
  17. package/dist/executors/dag-pi-executor.js +4010 -78
  18. package/dist/executors/pi-executor.js +15 -4
  19. package/dist/executors/pi-extension-resolver.js +14 -2
  20. package/dist/executors/pi-read-budget-policy.js +239 -0
  21. package/dist/executors/shell-executor.js +978 -188
  22. package/dist/executors/shell-write-guard.js +7 -0
  23. package/dist/infrastructure/console/operation-store.js +226 -6
  24. package/dist/shared/dag-failure-category.js +12 -0
  25. package/dist/shared/openspec-spec.js +70 -4
  26. package/dist/shared/operator/capabilities.js +7 -0
  27. package/dist/task/config-types.js +105 -5
  28. package/dist/task/contract/adopt.js +4 -0
  29. package/dist/task/contract/import-revision.js +4 -0
  30. package/dist/task/contract/project.js +3 -0
  31. package/dist/task/contract/schema.js +2 -1
  32. package/dist/task/frontend-project-capability.js +203 -20
  33. package/dist/task/runtime.js +5 -2
  34. package/dist/task/source-prepare/build-draft.js +3 -3
  35. package/dist/task/source-prepare/fragment-inventory.js +64 -25
  36. package/dist/task/source-prepare/prepare.js +126 -21
  37. package/dist/task/source-prepare/semantic-intake.js +6 -2
  38. package/dist/task/source-references.js +22 -1
  39. package/dist/worker/console/chat/chat-ui-policy.js +4 -2
  40. package/dist/worker/console/chat/model-resolver.js +7 -4
  41. package/dist/worker/console/chat/pi-runtime.js +258 -11
  42. package/dist/worker/console/chat/repo-browser.js +10 -3
  43. package/dist/worker/console/chat/routes.js +165 -71
  44. package/dist/worker/console/chat/sdd-data-alignment.js +222 -0
  45. package/dist/worker/console/chat/session-catalog.js +2 -0
  46. package/dist/worker/console/chat/session-store.js +159 -70
  47. package/dist/worker/console/chat/shortcuts.js +19 -3
  48. package/dist/worker/console/chat/turn-process.js +111 -56
  49. package/dist/worker/console/frontend-human-decision-adapter.js +19 -0
  50. package/dist/worker/console/frontend-split-operation-adapter.js +20 -0
  51. package/dist/worker/console/index.js +3 -0
  52. package/dist/worker/console/operator-actions.js +169 -7
  53. package/dist/worker/console/pi-readiness.js +3 -2
  54. package/dist/worker/console/server.js +23 -1
  55. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-DZZ8m3PO.js → abnfDiagram-N423BO3Z-CcS17TBr.js} +1 -1
  56. package/dist/worker/console/static/assets/{arc-D6PvaVd-.js → arc-COptKq2S.js} +1 -1
  57. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-B_OTOiI8.js → architectureDiagram-T3A2C74G-h4LKMHjP.js} +1 -1
  58. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-Bv6rqHBg.js → blockDiagram-VBNYF7ZC-COA1MOH0.js} +1 -1
  59. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-B8eHr0oz.js → c4Diagram-5PPSVZJV-DJUf0QPm.js} +1 -1
  60. package/dist/worker/console/static/assets/channel-DdBCaOJ6.js +1 -0
  61. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-DYwR0im2.js → chunk-2GRJ4B5K-mtWfKrUX.js} +1 -1
  62. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-D2WPGqXt.js → chunk-2Q5K7J3B-B8pXsxDQ.js} +1 -1
  63. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-CQISJ_I7.js → chunk-5RXB4S5H-ipKzByl1.js} +1 -1
  64. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-C0o2Du1e.js → chunk-5VM5RSS4-DYi3Ald_.js} +1 -1
  65. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-4f8kr-U7.js → chunk-6Q2QTUOP-DQtGYoty.js} +1 -1
  66. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-D_OWvXzX.js → chunk-GF5L2VYU-BU0qS2YV.js} +1 -1
  67. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-CasdPz5X.js → chunk-JWPE2WC7-DVH9dIGE.js} +1 -1
  68. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-Cj8lRrla.js → chunk-KBJHAD2P-Dt60SmgM.js} +1 -1
  69. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-CUvD1FSd.js → chunk-RYQCIY6F-BoaUGuEY.js} +1 -1
  70. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-CqLw_eqB.js → chunk-XXDRQBXY-_WHFDTp2.js} +1 -1
  71. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DZFra1GO.js +1 -0
  72. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DZFra1GO.js +1 -0
  73. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-ku-WqJPx.js → cose-bilkent-JH36ORCC-BxkbTIRd.js} +1 -1
  74. package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-Bq_PYDhl.js → cynefin-VYW2F7L2-Bf2UVnoG.js} +1 -1
  75. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-BiGZV641.js → cynefinDiagram-MW4NZA55-Bo23q1J_.js} +1 -1
  76. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-C4JRlglF.js → dagre-VZM6K2ZE-Dd_UU49i.js} +1 -1
  77. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-B0dNeWYG.js → diagram-7IWD3JNH-ebUa1a9y.js} +1 -1
  78. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-Cj35YvYM.js → diagram-B4RE2ZJO-BucthU8r.js} +1 -1
  79. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-uzQoJ2-8.js → diagram-LBJQPF4R-BgqNpAkm.js} +1 -1
  80. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-D1a-Buoz.js → diagram-Q27KOJAE-DC4q5NGa.js} +1 -1
  81. package/dist/worker/console/static/assets/{diagram-UB23O5K3-XjRrLRSs.js → diagram-UB23O5K3-CBqCaMeb.js} +1 -1
  82. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-Da_O24cW.js → ebnfDiagram-BXEA7PRR-CGtnbQ3-.js} +1 -1
  83. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-BLJ8jrYU.js → erDiagram-JOGREHBK-CG3LUao5.js} +1 -1
  84. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-B9GrLjM0.js → flowDiagram-UKHOOZJN-D2ZVgoFS.js} +1 -1
  85. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-CeJ0TqiK.js → ganttDiagram-PKOTCBZU-DoYFZiKt.js} +1 -1
  86. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-Bm2eNNFX.js → gitGraphDiagram-DS77QQ5N-CKoP1s6j.js} +1 -1
  87. package/dist/worker/console/static/assets/index-CAZ2fC_X.css +1 -0
  88. package/dist/worker/console/static/assets/index-vbTcFnFs.js +449 -0
  89. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-DB26i3d8.js → infoDiagram-6WML65LV-Duofv8p2.js} +1 -1
  90. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-BOGRyeZT.js → ishikawaDiagram-WSZJBQD7-D2nlCkA1.js} +1 -1
  91. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-CZRoBO_6.js → journeyDiagram-NVQOT4AX-Dd4IHdus.js} +1 -1
  92. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-qlWhJyoB.js → kanban-definition-27J2QSJJ-Bi20AOdt.js} +1 -1
  93. package/dist/worker/console/static/assets/{linear-CfUiDDB3.js → linear-D59YJ9kB.js} +1 -1
  94. package/dist/worker/console/static/assets/{mermaid.core-BQe6fpqj.js → mermaid.core-Bl13LpNa.js} +5 -5
  95. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-zFzWHw64.js → mindmap-definition-FAOFIHXS-C6DLP5eY.js} +1 -1
  96. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-DFGUqjZO.js → pegDiagram-VL7TDLO6-BjO4cy64.js} +1 -1
  97. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-BB5i0l8Z.js → pieDiagram-7S7Q4E2Y-D7i2qZTG.js} +1 -1
  98. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-obbVZ_X5.js → quadrantDiagram-CIZ2JOQS-Dx8o_h0y.js} +1 -1
  99. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-BwdaNzc1.js → railroadDiagram-AXF67PYL-B55orI_t.js} +1 -1
  100. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-CkTJaugh.js → requirementDiagram-LRYGKXZP-zWaehp6f.js} +1 -1
  101. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-BwJ-hIgq.js → sankeyDiagram-W5VNT64P-CcA-pjvD.js} +1 -1
  102. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-BzSgmm7w.js → sequenceDiagram-SI44F4Z6-BOFbzNHI.js} +1 -1
  103. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-Bn3oj5Q1.js → sizeCapture-X5ZJPWSS-BjAejah1.js} +1 -1
  104. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-dxhGtL8K.js → stateDiagram-OKZ733FA-DXYwxJwZ.js} +1 -1
  105. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Clg3V9t1.js +1 -0
  106. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-BLpEInya.js → swimlanes-SLNWSIFB-OYiOch8n.js} +2 -2
  107. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-DX1dxAAW.js +8 -0
  108. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-ChJGYcXy.js → timeline-definition-Z64GVDOM-cZfH3nmU.js} +1 -1
  109. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-DK-qjRer.js → vennDiagram-T6HMQDX7-BDE7b3E1.js} +1 -1
  110. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-3qeaWAg-.js → wardleyDiagram-T6FBY63Y-kyyGy9WJ.js} +1 -1
  111. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-CootlyP9.js → xychartDiagram-ELKLHX3M-CJj6VTog.js} +1 -1
  112. package/dist/worker/console/static/index.html +2 -2
  113. package/dist/worker/console/static-src/active-run-badge.js +17 -0
  114. package/dist/worker/console/static-src/app/useRecoveryConsole.js +5 -5
  115. package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +19 -8
  116. package/dist/worker/console/static-src/operator-chat/input-history.js +8 -6
  117. package/dist/worker/console/static-src/operator-chat/open-preview-in-browser.js +15 -7
  118. package/dist/worker/console/static-src/operator-chat/runtime-snapshot-store.js +10 -0
  119. package/dist/worker/console/static-src/operator-chat/useChatSessions.js +258 -23
  120. package/dist/worker/console/static-src/operator-chat/useChatThread.js +112 -4
  121. package/dist/worker/console/static-src/operator-chat/useComposer.js +13 -4
  122. package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +29 -6
  123. package/dist/worker/console/static-src/operator-chat/useRuntimeSnapshot.js +8 -2
  124. package/dist/worker/console/static-src/shell/console-update-reload.js +36 -9
  125. package/dist/worker/console/static-src/shell/workspace-route.js +11 -0
  126. package/dist/worker/console/workspace-context.js +115 -1
  127. package/dist/worker/materialize/frontend-split-task-materializer.js +72 -0
  128. package/dist/worker/observe/routes.js +4 -0
  129. package/dist/worker/observe/static/constants.js +22 -22
  130. package/dist/worker/observe/static/dag-context-reason-labels.js +19 -0
  131. package/dist/worker/observe/static/dag-helpers.js +4 -2
  132. package/dist/worker/observe/static/dag-history-labels.js +1 -0
  133. package/dist/worker/observe/static/dag-inspector-humanize.d.ts +16 -0
  134. package/dist/worker/observe/static/dag-inspector-humanize.js +339 -0
  135. package/dist/worker/observe/static/dag-node-purpose.js +13 -8
  136. package/dist/worker/observe/static/index.html +4 -4
  137. package/dist/worker/observe/static/inspect-workspace.js +23 -0
  138. package/dist/worker/observe/static/kpi.js +2 -2
  139. package/dist/worker/observe/static/operator-chrome.d.ts +10 -2
  140. package/dist/worker/observe/static/operator-chrome.js +37 -23
  141. package/dist/worker/observe/static/prompt-restart-candidates.js +4 -2
  142. package/dist/worker/observe/static/relations.js +7 -7
  143. package/dist/worker/observe/static/router.d.ts +12 -1
  144. package/dist/worker/observe/static/router.js +48 -6
  145. package/dist/worker/observe/static/run-processing.js +4 -2
  146. package/dist/worker/observe/static/shell-chrome.js +2 -2
  147. package/dist/worker/observe/static/state.js +5 -0
  148. package/dist/worker/observe/static/styles.css +231 -0
  149. package/dist/worker/observe/static/views/dag-graph.js +1 -1
  150. package/dist/worker/observe/static/views/dag-inspector.js +336 -181
  151. package/dist/worker/observe/static/views/dag.js +26 -14
  152. package/dist/worker/observe/static/views/dags.js +3 -1
  153. package/dist/worker/observe/static/views/dashboard.js +14 -6
  154. package/dist/worker/observe/static/views/pool.js +7 -2
  155. package/dist/worker/observe/static/views/run.js +12 -3
  156. package/dist/worker/observe/static/views/session-timeline.js +74 -13
  157. package/dist/worker/observe/static/views/task.js +7 -2
  158. package/dist/workflows/dag/backend-test-case-coverage-analysis.js +215 -28
  159. package/dist/workflows/dag/backend-test-markdown-workflow.js +13 -1
  160. package/dist/workflows/dag/backend-test-plan-protocol.js +210 -0
  161. package/dist/workflows/dag/backend-test-scenario-param.js +172 -25
  162. package/dist/workflows/dag/backend-test-scenario-partitions.js +62 -1
  163. package/dist/workflows/dag/backend-test-writer-completeness.js +104 -12
  164. package/dist/workflows/dag/contract-validator-registrations.js +1 -2
  165. package/dist/workflows/dag/dag-retry-schema.js +138 -0
  166. package/dist/workflows/dag/frontend-closeout.js +221 -0
  167. package/dist/workflows/dag/frontend-design-policy.js +400 -0
  168. package/dist/workflows/dag/frontend-human-decision.js +182 -0
  169. package/dist/workflows/dag/frontend-implementation-contract.js +1237 -192
  170. package/dist/workflows/dag/frontend-plan-render.js +2 -1
  171. package/dist/workflows/dag/frontend-prewrite-gate.js +256 -350
  172. package/dist/workflows/dag/frontend-provider-capability-matrix.js +159 -0
  173. package/dist/workflows/dag/frontend-recovery-capsule.js +455 -0
  174. package/dist/workflows/dag/frontend-recovery-controller.js +226 -0
  175. package/dist/workflows/dag/frontend-recovery-lineage.js +178 -0
  176. package/dist/workflows/dag/frontend-recovery-plan.js +21 -10
  177. package/dist/workflows/dag/frontend-recovery-run.js +166 -34
  178. package/dist/workflows/dag/frontend-repair.js +1 -432
  179. package/dist/workflows/dag/frontend-review-context.js +261 -15
  180. package/dist/workflows/dag/frontend-review-findings.js +270 -0
  181. package/dist/workflows/dag/frontend-shadow-dual-write.js +941 -0
  182. package/dist/workflows/dag/frontend-shape-capsule-store.js +191 -0
  183. package/dist/workflows/dag/frontend-shape-facts.js +419 -0
  184. package/dist/workflows/dag/frontend-shape.js +435 -0
  185. package/dist/workflows/dag/frontend-source-fidelity-ledger.js +108 -0
  186. package/dist/workflows/dag/frontend-split-application-service.js +203 -0
  187. package/dist/workflows/dag/frontend-split-orchestrator.js +899 -0
  188. package/dist/workflows/dag/frontend-typed-event-store.js +452 -0
  189. package/dist/workflows/dag/frontend-typed-event-transaction.js +180 -0
  190. package/dist/workflows/dag/frontend-verification-trace.js +252 -25
  191. package/dist/workflows/dag/frontend-worktree-diff.js +250 -17
  192. package/dist/workflows/dag/frontend-writer-admission.js +319 -0
  193. package/dist/workflows/dag/frontend-writer-status.js +256 -0
  194. package/dist/workflows/dag/init-hybrid.js +1031 -564
  195. package/dist/workflows/dag/interrupt-request.js +7 -0
  196. package/dist/workflows/dag/node-execution.js +854 -4
  197. package/dist/workflows/dag/prompt.js +70 -3
  198. package/dist/workflows/dag/recovery-lease.js +170 -0
  199. package/dist/workflows/dag/report.js +37 -1
  200. package/dist/workflows/dag/rerun-feedback.js +315 -1
  201. package/dist/workflows/dag/rerun-plan.js +17 -6
  202. package/dist/workflows/dag/rerun-run.js +44 -6
  203. package/dist/workflows/dag/rerun-task.js +251 -13
  204. package/dist/workflows/dag/retry-policy.js +230 -104
  205. package/dist/workflows/dag/runner.js +580 -124
  206. package/dist/workflows/dag/scheduler.js +133 -20
  207. package/dist/workflows/dag/types.js +244 -16
  208. package/dist/workflows/dag/validate.js +28 -12
  209. package/docs/examples/README.md +5 -0
  210. package/docs/init-surface.manifest.json +30 -12
  211. package/docs/skills/vetted-skill-registry.md +4 -2
  212. package/docs/templates/README.md +2 -0
  213. package/docs/templates/agent-dag-report.schema.json +8 -2
  214. package/docs/templates/agent-dag.schema.json +1 -1
  215. package/docs/templates/backend-test-dag.json +25 -20
  216. package/docs/templates/frontend-implementation-contract.schema.json +4 -1
  217. package/docs/templates/frontend-implementation-dag.json +89 -0
  218. package/docs/templates/spec-registry.schema.json +45 -0
  219. package/harness.json +1 -1
  220. package/package.json +4 -3
  221. package/skills/frontend-bounded-implement/SKILL.md +15 -14
  222. package/skills/frontend-bounded-implement/references/code-standards.md +19 -0
  223. package/skills/frontend-contract/SKILL.md +23 -0
  224. package/skills/frontend-contract/references/contract-protocol.md +34 -0
  225. package/skills/frontend-design-review/SKILL.md +22 -41
  226. package/skills/frontend-plan/SKILL.md +26 -0
  227. package/skills/frontend-plan/references/decision-contract.md +37 -0
  228. package/skills/frontend-plan/references/design-decisions.md +17 -0
  229. package/skills/frontend-review/SKILL.md +20 -15
  230. package/skills/frontend-review/references/review-findings.md +6 -7
  231. package/skills/frontend-scout/SKILL.md +25 -0
  232. package/skills/frontend-scout/references/design-evidence.md +16 -0
  233. package/skills/frontend-scout/references/scout-evidence.md +23 -0
  234. package/skills/frontend-verification/SKILL.md +1 -1
  235. package/skills/loop-agent/references/command-reference.md +1 -0
  236. package/skills/loop-agent/references/hybrid-dag.md +2 -2
  237. package/dist/worker/console/static/assets/channel-BU5gOilw.js +0 -1
  238. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DIzKJGHr.js +0 -1
  239. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DIzKJGHr.js +0 -1
  240. package/dist/worker/console/static/assets/index-H9rFJiGL.css +0 -1
  241. package/dist/worker/console/static/assets/index-xwu9GxEc.js +0 -451
  242. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Cld2qK9v.js +0 -1
  243. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-TIHpiT7w.js +0 -8
  244. package/skills/frontend-implementation/SKILL.md +0 -52
  245. package/skills/frontend-implementation/references/code-standards.md +0 -33
  246. package/skills/frontend-implementation/references/design-spec.md +0 -56
  247. package/skills/frontend-implementation/references/node-contracts.md +0 -31
@@ -19,6 +19,40 @@ const RERUN_FEEDBACK_ROLES = new Set([
19
19
  "verifier",
20
20
  "reviewer",
21
21
  ]);
22
+ function globPatternToRegExp(pattern) {
23
+ const normalized = pattern.replace(/\\/g, "/");
24
+ let source = "";
25
+ for (let index = 0; index < normalized.length; index += 1) {
26
+ const char = normalized[index];
27
+ if (char === "*" && normalized[index + 1] === "*") {
28
+ source += ".*";
29
+ index += 1;
30
+ }
31
+ else if (char === "*") {
32
+ source += "[^/]*";
33
+ }
34
+ else {
35
+ source += char.replace(/[.*+?^${}()|[\\]\\]/g, "\\$&");
36
+ }
37
+ }
38
+ return new RegExp(`^${source}$`);
39
+ }
40
+ function readSetAllowsArtifactPath(task, artifactPath) {
41
+ const readSet = task.readSet ?? [];
42
+ if (readSet.length === 0)
43
+ return true;
44
+ const candidate = artifactPath.replace(/\\/g, "/");
45
+ const candidates = [candidate];
46
+ for (const marker of ["/.harness/", "/source/", "/testcase/"]) {
47
+ const index = candidate.indexOf(marker);
48
+ if (index >= 0)
49
+ candidates.push(candidate.slice(index + 1));
50
+ }
51
+ return readSet.some((pattern) => {
52
+ const regex = globPatternToRegExp(pattern);
53
+ return candidates.some((value) => regex.test(value));
54
+ });
55
+ }
22
56
  function formatBulletList(items, emptyLabel) {
23
57
  if (!items || items.length === 0)
24
58
  return emptyLabel;
@@ -46,9 +80,42 @@ function formatResolvedSkillInstructions(instructions) {
46
80
  if (!instructions || instructions.length === 0)
47
81
  return "(none)";
48
82
  return instructions
49
- .map((instruction) => instruction.promptText)
83
+ .map((instruction) => formatSkillChecklist(instruction))
50
84
  .join("\n\n---\n\n");
51
85
  }
86
+ /** Keep skill provenance, but turn bounded inline manuals into a small action list. */
87
+ function formatSkillChecklist(instruction) {
88
+ const metadata = [
89
+ `Skill: ${instruction.name}`,
90
+ `Resolution: ${instruction.resolution}`,
91
+ ...(instruction.path ? [`Path: ${instruction.path}`] : []),
92
+ ...(instruction.sha256 ? [`Sha256: ${instruction.sha256}`] : []),
93
+ "Injection mode: checklist",
94
+ ];
95
+ if (instruction.resolution !== "resolved")
96
+ return [...metadata, instruction.promptText].join("\n");
97
+ const source = instruction.promptText.split("Instructions:\n")[1] ?? "";
98
+ const candidates = source
99
+ .split(/\r?\n/)
100
+ .map((line) => line.trim())
101
+ .filter((line) => /^(?:#{1,3}\s+|[-*]\s+|\d+[.)]\s+)/.test(line) || line.length > 0)
102
+ .map((line) => line.replace(/^#{1,3}\s+/, "").replace(/^[-*]\s+/, "").replace(/^\d+[.)]\s+/, ""))
103
+ .filter((line) => line.length > 0);
104
+ const checklist = [];
105
+ let chars = 0;
106
+ for (const item of candidates) {
107
+ const bounded = item.slice(0, 240);
108
+ if (checklist.length >= 10 || chars + bounded.length > 1_600)
109
+ break;
110
+ checklist.push(`- ${bounded}`);
111
+ chars += bounded.length;
112
+ }
113
+ return [
114
+ ...metadata,
115
+ "Checklist (apply these actions; consult the immutable resolved file only when a listed action requires detail):",
116
+ ...(checklist.length > 0 ? checklist : ["- Follow the resolved skill's declared workflow."]),
117
+ ].join("\n");
118
+ }
52
119
  export function formatOutputLanguageBlock(language = DEFAULT_DAG_OUTPUT_LANGUAGE) {
53
120
  if (language === "en") {
54
121
  return [
@@ -96,7 +163,7 @@ export function buildUpstreamContext(task, upstream, maxChars = MAX_UPSTREAM_CHA
96
163
  : artifactKind === "assistant"
97
164
  ? record.assistantArtifactPath
98
165
  : undefined;
99
- if (truncated && artifactPath) {
166
+ if (truncated && artifactPath && readSetAllowsArtifactPath(task, artifactPath)) {
100
167
  section += formatUpstreamArtifactPointerMap(record, artifactKind === "stdout" ? "stdout" : "assistant");
101
168
  }
102
169
  else if (truncated && record.nodeRecordPath) {
@@ -172,7 +239,7 @@ export function buildUpstreamContext(task, upstream, maxChars = MAX_UPSTREAM_CHA
172
239
  if (consumedArtifactSection) {
173
240
  section += `\n\n${consumedArtifactSection}`;
174
241
  }
175
- if (truncated && artifactPath) {
242
+ if (truncated && artifactPath && readSetAllowsArtifactPath(task, artifactPath)) {
176
243
  section += formatUpstreamArtifactPointerMap(record, artifactKind);
177
244
  }
178
245
  sections.push(section);
@@ -0,0 +1,170 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
3
+ import { hostname as localHostname } from "node:os";
4
+ import path from "node:path";
5
+ import { setTimeout as delay } from "node:timers/promises";
6
+ import { writeJsonAtomic } from "../../infrastructure/harness/atomic-write.js";
7
+ import { DAG_RUNS_DIR } from "./lifecycle.js";
8
+ function recoveryLeasePath(cwd, parentRunId) {
9
+ // Never derive a filesystem name directly from an externally supplied legacy
10
+ // run id. The content remains auditable while the filename is traversal-safe.
11
+ const key = createHash("sha256").update(parentRunId).digest("hex");
12
+ return path.join(cwd, DAG_RUNS_DIR, ".recovery-leases", `${key}.json`);
13
+ }
14
+ function parseLease(raw, parentRunId) {
15
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
16
+ throw new Error("invalid dag recovery lease: expected object");
17
+ }
18
+ const record = raw;
19
+ if (record.schemaVersion !== 1 ||
20
+ record.parentRunId !== parentRunId ||
21
+ typeof record.requestId !== "string" ||
22
+ record.requestId.length === 0 ||
23
+ (record.kind !== "auto-frontend-recovery" &&
24
+ record.kind !== "rerun-from-node" &&
25
+ record.kind !== "standalone-task-rerun") ||
26
+ typeof record.leaseToken !== "string" ||
27
+ record.leaseToken.length === 0 ||
28
+ typeof record.ownerPid !== "number" ||
29
+ !Number.isInteger(record.ownerPid) ||
30
+ record.ownerPid <= 0 ||
31
+ typeof record.ownerHostname !== "string" ||
32
+ record.ownerHostname.length === 0 ||
33
+ typeof record.acquiredAt !== "string" ||
34
+ typeof record.executionRef !== "undefined" &&
35
+ typeof record.executionRef !== "string") {
36
+ throw new Error("invalid dag recovery lease: schema mismatch");
37
+ }
38
+ return record;
39
+ }
40
+ const LEASE_MUTATION_LOCK_STALE_MS = 60_000;
41
+ const LEASE_MUTATION_LOCK_RETRIES = 200;
42
+ async function withLeaseMutationLock(leasePath, operation) {
43
+ const lockPath = `${leasePath}.mutation-lock`;
44
+ for (let attempt = 0; attempt < LEASE_MUTATION_LOCK_RETRIES; attempt += 1) {
45
+ try {
46
+ await mkdir(lockPath);
47
+ }
48
+ catch (error) {
49
+ if (!(error && typeof error === "object" && "code" in error && error.code === "EEXIST")) {
50
+ throw error;
51
+ }
52
+ try {
53
+ const lockStat = await stat(lockPath);
54
+ if (Date.now() - lockStat.mtimeMs >= LEASE_MUTATION_LOCK_STALE_MS) {
55
+ await rm(lockPath, { recursive: true, force: true });
56
+ continue;
57
+ }
58
+ }
59
+ catch (statError) {
60
+ if (statError &&
61
+ typeof statError === "object" &&
62
+ "code" in statError &&
63
+ statError.code === "ENOENT") {
64
+ continue;
65
+ }
66
+ throw statError;
67
+ }
68
+ await delay(10);
69
+ continue;
70
+ }
71
+ try {
72
+ return await operation();
73
+ }
74
+ finally {
75
+ await rm(lockPath, { recursive: true, force: true });
76
+ }
77
+ }
78
+ throw new Error("dag recovery lease mutation lock is busy");
79
+ }
80
+ function defaultIsProcessAlive(pid) {
81
+ try {
82
+ process.kill(pid, 0);
83
+ return true;
84
+ }
85
+ catch {
86
+ return false;
87
+ }
88
+ }
89
+ function leaseOwnerIsAlive(input) {
90
+ if (input.lease.ownerHostname !== input.hostname)
91
+ return true;
92
+ return input.isProcessAlive(input.lease.ownerPid);
93
+ }
94
+ export async function acquireDagRecoveryLease(input) {
95
+ const leasePath = recoveryLeasePath(input.cwd, input.parentRunId);
96
+ const lease = {
97
+ schemaVersion: 1,
98
+ parentRunId: input.parentRunId,
99
+ requestId: input.requestId,
100
+ kind: input.kind,
101
+ leaseToken: randomBytes(16).toString("hex"),
102
+ ownerPid: process.pid,
103
+ ownerHostname: localHostname(),
104
+ acquiredAt: (input.now ?? (() => new Date()))().toISOString(),
105
+ };
106
+ await mkdir(path.dirname(leasePath), { recursive: true });
107
+ try {
108
+ // `wx` is the cross-process compare-and-create primitive. The lease is
109
+ // parent-scoped for the full recovery lineage. Ownership may only be
110
+ // replaced by claimDagRecoveryLease after the recorded owner is proven dead.
111
+ await writeFile(leasePath, `${JSON.stringify(lease, null, 2)}\n`, {
112
+ encoding: "utf8",
113
+ flag: "wx",
114
+ });
115
+ return { kind: "acquired", leasePath, lease };
116
+ }
117
+ catch (error) {
118
+ if (!(error && typeof error === "object" && "code" in error && error.code === "EEXIST")) {
119
+ throw error;
120
+ }
121
+ const existing = parseLease(JSON.parse(await readFile(leasePath, "utf8")), input.parentRunId);
122
+ return { kind: "held", leasePath, lease: existing };
123
+ }
124
+ }
125
+ /**
126
+ * Reclaim a lease only after its recorded same-host owner is proven dead.
127
+ * The mutation lock serializes reclaim with execution binding, so a live owner
128
+ * can never race a stale-owner takeover and launch a second recovery.
129
+ */
130
+ export async function claimDagRecoveryLease(input) {
131
+ const hostname = input.hostname ?? localHostname();
132
+ const isProcessAlive = input.isProcessAlive ?? defaultIsProcessAlive;
133
+ return withLeaseMutationLock(input.leasePath, async () => {
134
+ const existing = parseLease(JSON.parse(await readFile(input.leasePath, "utf8")), input.lease.parentRunId);
135
+ if (existing.leaseToken !== input.lease.leaseToken ||
136
+ leaseOwnerIsAlive({ lease: existing, hostname, isProcessAlive })) {
137
+ return { kind: "held", leasePath: input.leasePath, lease: existing };
138
+ }
139
+ const claimed = {
140
+ ...existing,
141
+ leaseToken: randomBytes(16).toString("hex"),
142
+ ownerPid: process.pid,
143
+ ownerHostname: hostname,
144
+ acquiredAt: (input.now ?? (() => new Date()))().toISOString(),
145
+ };
146
+ await writeJsonAtomic(input.leasePath, claimed);
147
+ return { kind: "acquired", leasePath: input.leasePath, lease: claimed };
148
+ });
149
+ }
150
+ /** Persist the operation/run identity before the caller is allowed to execute it. */
151
+ export async function bindDagRecoveryLeaseExecution(input) {
152
+ if (!input.executionRef.trim()) {
153
+ throw new Error("dag recovery lease executionRef is required");
154
+ }
155
+ return withLeaseMutationLock(input.leasePath, async () => {
156
+ const existing = parseLease(JSON.parse(await readFile(input.leasePath, "utf8")), input.lease.parentRunId);
157
+ if (existing.leaseToken !== input.lease.leaseToken) {
158
+ throw new Error("dag recovery lease ownership drift");
159
+ }
160
+ if (existing.executionRef && existing.executionRef !== input.executionRef) {
161
+ throw new Error("dag recovery lease execution identity drift");
162
+ }
163
+ const bound = {
164
+ ...existing,
165
+ executionRef: input.executionRef,
166
+ };
167
+ await writeJsonAtomic(input.leasePath, bound);
168
+ return bound;
169
+ });
170
+ }
@@ -125,6 +125,8 @@ const dagNodeArtifactsReportSchema = z
125
125
  humanEscalationMd: dagArtifactRefSchema,
126
126
  humanApproval: dagArtifactRefSchema,
127
127
  humanRejection: dagArtifactRefSchema,
128
+ changeManifest: dagArtifactRefSchema,
129
+ changeManifestChangedFiles: z.array(z.string()).optional(),
128
130
  })
129
131
  .strict();
130
132
  const dagNodeReportRowSchema = z
@@ -259,6 +261,20 @@ export async function probeArtifact(filePath) {
259
261
  export async function buildNodeArtifactsReport(runDir, nodeId) {
260
262
  const nodeDir = path.join(runDir, nodeId);
261
263
  const artifact = (name) => probeArtifact(path.join(nodeDir, name));
264
+ const changeManifestRef = await artifact("change-manifest.json");
265
+ let changeManifestChangedFiles;
266
+ if (changeManifestRef.exists) {
267
+ try {
268
+ const manifest = JSON.parse(await readFile(path.join(nodeDir, "change-manifest.json"), "utf-8"));
269
+ changeManifestChangedFiles = Array.isArray(manifest.changedFiles)
270
+ ? manifest.changedFiles
271
+ .filter((item) => typeof item === "string")
272
+ : undefined;
273
+ }
274
+ catch {
275
+ // unreadable manifest → leave undefined
276
+ }
277
+ }
262
278
  return {
263
279
  resultSummary: await artifact("result.summary.md"),
264
280
  promptRedacted: await artifact("prompt.redacted.md"),
@@ -270,6 +286,8 @@ export async function buildNodeArtifactsReport(runDir, nodeId) {
270
286
  humanEscalationMd: await artifact("human-escalation.md"),
271
287
  humanApproval: await artifact("human-approval.json"),
272
288
  humanRejection: await artifact("human-rejection.json"),
289
+ changeManifest: changeManifestRef,
290
+ changeManifestChangedFiles,
273
291
  };
274
292
  }
275
293
  function taskById(spec) {
@@ -726,6 +744,12 @@ function formatArtifactFlags(artifacts) {
726
744
  flags.push("approval");
727
745
  if (artifacts.humanRejection.exists)
728
746
  flags.push("rejection");
747
+ if (artifacts.changeManifest.exists) {
748
+ const count = artifacts.changeManifestChangedFiles?.length;
749
+ flags.push(count !== undefined
750
+ ? `changed:${count}`
751
+ : "change-manifest");
752
+ }
729
753
  return flags.length > 0 ? flags.join(",") : "-";
730
754
  }
731
755
  function formatTimestamp(value) {
@@ -749,7 +773,19 @@ function summarizeNodeStatuses(nodes) {
749
773
  return `${total} total / ${finished} finished / ${failed} failed / ${skipped} skipped / ${pending} pending`;
750
774
  }
751
775
  function hasArtifact(artifacts) {
752
- return Object.values(artifacts).some((artifact) => artifact.exists);
776
+ return [
777
+ artifacts.resultSummary,
778
+ artifacts.promptRedacted,
779
+ artifacts.skills,
780
+ artifacts.nodeRecord,
781
+ artifacts.decisionEnvelope,
782
+ artifacts.decisionEnvelopeValidation,
783
+ artifacts.humanEscalationJson,
784
+ artifacts.humanEscalationMd,
785
+ artifacts.humanApproval,
786
+ artifacts.humanRejection,
787
+ artifacts.changeManifest,
788
+ ].some((artifact) => artifact.exists);
753
789
  }
754
790
  function failureRows(run) {
755
791
  return run.nodes.filter((node) => node.status === "ERROR" ||
@@ -2,6 +2,8 @@ import { createHash } from "node:crypto";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { parseJsonReviewVerdict } from "./output-protocol.js";
5
+ import { FRONTEND_DESIGN_REVIEW_NODE_ID, FRONTEND_REVIEW_NODE_ID, readCommittedDesignRequestFact, readCommittedReviewRequestFact, } from "./frontend-review-findings.js";
6
+ import { readTypedEventStoreFromJsonl } from "./frontend-typed-event-store.js";
5
7
  export const MAX_RERUN_FEEDBACK_CHARS = 12_000;
6
8
  const RERUN_FEEDBACK_TRUNCATION_MARKER = "\n\n...[上一轮反馈已按长度上限截断]...\n\n";
7
9
  const MAX_EVIDENCE_REFS = 8;
@@ -35,6 +37,44 @@ function requestRevision(text) {
35
37
  return (emphasized?.[1] ?? trimmed).trim() === "VERDICT: request-revision";
36
38
  });
37
39
  }
40
+ /**
41
+ * Deterministically render a typed `request_review_changes` fact into feedback
42
+ * text. Unlike the legacy text channel (VERDICT: request-revision), the
43
+ * frontend review terminal is a committed typed fact; the findings are the
44
+ * actionable body the next round must consume.
45
+ */
46
+ export function formatTypedReviewRequestFeedback(fact) {
47
+ const lines = [];
48
+ lines.push(`frontend review committed request_review_changes (issueCategory=${typeof fact.issueCategory === "string" ? fact.issueCategory : "unknown"})`);
49
+ if (Array.isArray(fact.findings) && fact.findings.length > 0) {
50
+ lines.push("review findings:");
51
+ for (const finding of fact.findings) {
52
+ if (!finding || typeof finding !== "object")
53
+ continue;
54
+ const record = finding;
55
+ const severity = typeof record.severity === "string" ? record.severity : "";
56
+ const issue = typeof record.issue === "string" ? record.issue : "";
57
+ const location = [
58
+ typeof record.file === "string" ? record.file : "",
59
+ typeof record.line === "number" ? String(record.line) : "",
60
+ ]
61
+ .filter(Boolean)
62
+ .join(":");
63
+ const prefix = location ? `[${location}] ` : "";
64
+ const requiredChange = typeof record.requiredChange === "string" &&
65
+ record.requiredChange.length > 0
66
+ ? ` (requiredChange: ${record.requiredChange})`
67
+ : "";
68
+ lines.push(`- ${prefix}${severity}: ${issue}${requiredChange}`);
69
+ }
70
+ }
71
+ if (Array.isArray(fact.evidenceRefs) && fact.evidenceRefs.length > 0) {
72
+ lines.push(`evidenceRefs: ${fact.evidenceRefs
73
+ .filter((ref) => typeof ref === "string")
74
+ .join(", ")}`);
75
+ }
76
+ return lines.join("\n");
77
+ }
38
78
  function pathInside(root, candidate) {
39
79
  const relative = path.relative(root, candidate);
40
80
  return (relative === "" ||
@@ -127,6 +167,162 @@ function evidenceRefs(repoRoot, runDir, pass, sourceNodeId) {
127
167
  }
128
168
  return result;
129
169
  }
170
+ /**
171
+ * Read the committed frontend review request fact (typed terminal channel).
172
+ * Returns { nodeId, fact } when the review node committed `request_review_changes`.
173
+ */
174
+ async function readTypedReviewRequestFact(runDir) {
175
+ const fact = await readCommittedReviewRequestFact({ runDir });
176
+ if (!fact)
177
+ return undefined;
178
+ return {
179
+ nodeId: FRONTEND_REVIEW_NODE_ID,
180
+ fact: {
181
+ issueCategory: fact.issueCategory,
182
+ evidenceRefs: fact.evidenceRefs,
183
+ findings: fact.findings,
184
+ },
185
+ };
186
+ }
187
+ /**
188
+ * Read the committed frontend design request fact (typed terminal channel).
189
+ * Returns { nodeId, fact } when the design review node committed
190
+ * `request_design_changes` — the design analog of request_review_changes.
191
+ */
192
+ async function readTypedDesignRequestFact(runDir) {
193
+ const fact = await readCommittedDesignRequestFact({ runDir });
194
+ if (!fact)
195
+ return undefined;
196
+ return {
197
+ nodeId: FRONTEND_DESIGN_REVIEW_NODE_ID,
198
+ fact: {
199
+ issueCategory: fact.issueCategory,
200
+ evidenceRefs: fact.evidenceRefs,
201
+ findings: fact.findings,
202
+ },
203
+ };
204
+ }
205
+ const RERUN_FEEDBACK_LINEAGE_MAX_DEPTH = 5;
206
+ const RERUN_FEEDBACK_LINEAGE_LIFECYCLES = [
207
+ "active",
208
+ "paused",
209
+ "completed",
210
+ ];
211
+ function safeLineageRunId(value) {
212
+ if (typeof value !== "string" || !value || value !== value.trim())
213
+ return undefined;
214
+ if (value === "." ||
215
+ value === ".." ||
216
+ value.includes("/") ||
217
+ value.includes("\\") ||
218
+ value.includes("\0"))
219
+ return undefined;
220
+ return value;
221
+ }
222
+ async function readCommittedTerminalKind(input) {
223
+ try {
224
+ const records = await readTypedEventStoreFromJsonl(path.join(input.runDir, input.nodeId, input.factsFile));
225
+ for (const record of records) {
226
+ if (record.phase !== "committed")
227
+ continue;
228
+ const kind = record.fact.kind;
229
+ if (typeof kind === "string" && input.kinds.includes(kind))
230
+ return kind;
231
+ }
232
+ }
233
+ catch {
234
+ // A missing/unreadable terminal store means this run did not establish a
235
+ // usable resolution barrier; lineage lookup may continue.
236
+ }
237
+ return undefined;
238
+ }
239
+ async function readReviewTerminalKind(runDir) {
240
+ return readCommittedTerminalKind({
241
+ runDir,
242
+ nodeId: FRONTEND_REVIEW_NODE_ID,
243
+ factsFile: "review-typed-facts.jsonl",
244
+ kinds: ["request_review_changes", "approve_review"],
245
+ });
246
+ }
247
+ async function readDesignTerminalKind(runDir) {
248
+ return readCommittedTerminalKind({
249
+ runDir,
250
+ nodeId: FRONTEND_DESIGN_REVIEW_NODE_ID,
251
+ factsFile: "design-typed-facts.jsonl",
252
+ kinds: ["request_design_changes", "approve_design"],
253
+ });
254
+ }
255
+ /**
256
+ * Walk the rerun-task lineage chain (`<runDir>/.runtime/rerun-task-lineage.json`
257
+ * → parentRunId) looking for the nearest ancestor run with a committed review
258
+ * or design request fact. A nearer final-review approval resolves all older
259
+ * findings; a nearer design approval resolves older design findings while
260
+ * still allowing an older final-review request to survive. Bounded depth;
261
+ * unsafe ids, mismatched state identities, cycles, and unreadable lineage
262
+ * files terminate the walk with undefined.
263
+ */
264
+ async function readAncestorTypedRequestFact(runDir) {
265
+ let currentRunDir = runDir;
266
+ let currentRunId;
267
+ let designResolved = false;
268
+ const dagRunsRoot = path.resolve(runDir, "..", "..");
269
+ const visitedRunDirs = new Set([path.resolve(runDir)]);
270
+ for (let depth = 0; depth <= RERUN_FEEDBACK_LINEAGE_MAX_DEPTH; depth += 1) {
271
+ const reviewTerminalKind = await readReviewTerminalKind(currentRunDir);
272
+ if (currentRunId && reviewTerminalKind === "request_review_changes") {
273
+ const fact = await readTypedReviewRequestFact(currentRunDir);
274
+ if (fact)
275
+ return { ...fact, parentRunId: currentRunId };
276
+ }
277
+ if (reviewTerminalKind === "approve_review")
278
+ return undefined;
279
+ const designTerminalKind = await readDesignTerminalKind(currentRunDir);
280
+ if (currentRunId &&
281
+ !designResolved &&
282
+ designTerminalKind === "request_design_changes") {
283
+ const fact = await readTypedDesignRequestFact(currentRunDir);
284
+ if (fact)
285
+ return { ...fact, parentRunId: currentRunId };
286
+ }
287
+ if (designTerminalKind === "approve_design")
288
+ designResolved = true;
289
+ if (depth === RERUN_FEEDBACK_LINEAGE_MAX_DEPTH)
290
+ return undefined;
291
+ let parentRunId;
292
+ try {
293
+ const lineage = JSON.parse(await readFile(path.join(currentRunDir, ".runtime", "rerun-task-lineage.json"), "utf8"));
294
+ parentRunId = safeLineageRunId(lineage.parentRunId);
295
+ }
296
+ catch {
297
+ return undefined;
298
+ }
299
+ if (!parentRunId)
300
+ return undefined;
301
+ let ancestorRunDir;
302
+ for (const lifecycle of RERUN_FEEDBACK_LINEAGE_LIFECYCLES) {
303
+ const candidate = path.join(dagRunsRoot, lifecycle, parentRunId);
304
+ try {
305
+ const ancestorState = JSON.parse(await readFile(path.join(candidate, "state.json"), "utf8"));
306
+ if (ancestorState.runId === parentRunId) {
307
+ ancestorRunDir = candidate;
308
+ break;
309
+ }
310
+ }
311
+ catch {
312
+ // try next lifecycle
313
+ }
314
+ }
315
+ if (!ancestorRunDir)
316
+ return undefined;
317
+ const resolvedAncestorRunDir = path.resolve(ancestorRunDir);
318
+ if (visitedRunDirs.has(resolvedAncestorRunDir))
319
+ return undefined;
320
+ visitedRunDirs.add(resolvedAncestorRunDir);
321
+ currentRunDir = ancestorRunDir;
322
+ currentRunId = parentRunId;
323
+ }
324
+ return undefined;
325
+ }
130
326
  /**
131
327
  * Derive only the latest unresolved verify/review feedback from canonical
132
328
  * parent-run facts. Provider-only failures intentionally return undefined.
@@ -144,8 +340,126 @@ export async function deriveDagRerunFeedback(input) {
144
340
  break;
145
341
  }
146
342
  }
147
- if (!sourceNodeId || !sourceNode)
343
+ if (!sourceNodeId || !sourceNode) {
344
+ // Typed terminal channel: the frontend review/design review commit their
345
+ // verdicts as typed facts (request_review_changes / request_design_changes)
346
+ // instead of VERDICT text, and the frontend DAG has no convergence
347
+ // passHistory. Fall back to reading the typed event stores so findings
348
+ // still flow into the next round as unresolved feedback. Prefer review;
349
+ // if absent, fall through to the design review (a design rejection also
350
+ // carries actionable findings the next plan round must consume). When
351
+ // the direct parent has neither because it failed before review, walk the
352
+ // rerun-task lineage chain — chained
353
+ // reruns otherwise lose the grandparent's code-review findings and the
354
+ // reviewer re-flags them as "unresolved previous-round feedback" (r18).
355
+ // A committed approval is a resolution barrier and prevents older
356
+ // findings from being resurrected.
357
+ const typedFact = (await readTypedReviewRequestFact(input.runDir)) ??
358
+ (await readTypedDesignRequestFact(input.runDir)) ??
359
+ (await readAncestorTypedRequestFact(input.runDir));
360
+ if (typedFact) {
361
+ const parentSourceBindingHash = sourceBindingHash(input.spec);
362
+ return withDigest({
363
+ schemaVersion: 1,
364
+ kind: "unresolved-terminal-feedback",
365
+ parentRunId: "parentRunId" in typedFact &&
366
+ typeof typedFact.parentRunId === "string"
367
+ ? typedFact.parentRunId
368
+ : input.parentRunId,
369
+ taskId: input.taskId,
370
+ sourceNodeId: typedFact.nodeId,
371
+ verdict: "request-revision",
372
+ failureCategory: typedFact.nodeId === FRONTEND_REVIEW_NODE_ID
373
+ ? "review-request-changes"
374
+ : "design-request-changes",
375
+ feedbackText: scrubAndBoundFeedbackText(formatTypedReviewRequestFeedback(typedFact.fact), input.runDir, input.state.cwd),
376
+ evidenceRefs: [
377
+ {
378
+ nodeId: typedFact.nodeId,
379
+ preservedNodeRecordPath: `${typedFact.nodeId}.json`,
380
+ },
381
+ ],
382
+ attemptSummary: {
383
+ completedPasses: 1,
384
+ maxPasses: 1,
385
+ ...(input.state.terminalReason
386
+ ? { terminalReason: input.state.terminalReason }
387
+ : {}),
388
+ },
389
+ binding: {
390
+ ...(parentSourceBindingHash
391
+ ? { sourceCanonicalHash: parentSourceBindingHash }
392
+ : {}),
393
+ ...(input.spec.taskContractBinding?.canonicalHash
394
+ ? {
395
+ taskContractCanonicalHash: input.spec.taskContractBinding.canonicalHash,
396
+ }
397
+ : {}),
398
+ status: "unknown",
399
+ },
400
+ });
401
+ }
402
+ // Preserve actionable writer failures even when the run stopped before a
403
+ // final review node could commit typed findings. This is especially
404
+ // important for provider length exhaustion: the next run must see the
405
+ // stop reason/tool statistics instead of repeating the same prompt.
406
+ const writerNodeId = ["frontend-implement-pi", "implement-pi"].find((nodeId) => {
407
+ const node = input.state.nodes[nodeId];
408
+ return (node?.status === "ERROR" &&
409
+ [
410
+ "empty-output",
411
+ "invalid-output",
412
+ "writer-thinking-exhausted",
413
+ "writer-budget-exhausted",
414
+ "incomplete-write-set",
415
+ "partial-success-with-context-overflow",
416
+ ].includes(node.failureCategory ?? ""));
417
+ });
418
+ if (writerNodeId) {
419
+ const writerNode = await readNodeRecord(input.runDir, pass, undefined, writerNodeId, input.state.nodes[writerNodeId]);
420
+ if (writerNode) {
421
+ const writerFeedback = [
422
+ `writer failure category: ${writerNode.failureCategory ?? "unknown"}`,
423
+ writerNode.stopReason ? `provider stopReason: ${writerNode.stopReason}` : "",
424
+ typeof writerNode.writeToolCallCount === "number"
425
+ ? `write tool calls: ${writerNode.writeToolCallCount}`
426
+ : "",
427
+ writerNode.stderr?.trim() ?? "",
428
+ canonicalNodeOutput(writerNode),
429
+ ]
430
+ .filter(Boolean)
431
+ .join("\n\n");
432
+ const parentSourceBindingHash = sourceBindingHash(input.spec);
433
+ return withDigest({
434
+ schemaVersion: 1,
435
+ kind: "unresolved-terminal-feedback",
436
+ parentRunId: input.parentRunId,
437
+ taskId: input.taskId,
438
+ sourceNodeId: writerNodeId,
439
+ verdict: "request-revision",
440
+ failureCategory: writerNode.failureCategory,
441
+ feedbackText: scrubAndBoundFeedbackText(writerFeedback, input.runDir, input.state.cwd),
442
+ evidenceRefs: [
443
+ {
444
+ nodeId: writerNodeId,
445
+ preservedNodeRecordPath: `${writerNodeId}.json`,
446
+ },
447
+ ],
448
+ attemptSummary: { completedPasses: 1, maxPasses: 1 },
449
+ binding: {
450
+ ...(parentSourceBindingHash
451
+ ? { sourceCanonicalHash: parentSourceBindingHash }
452
+ : {}),
453
+ ...(input.spec.taskContractBinding?.canonicalHash
454
+ ? { taskContractCanonicalHash: input.spec.taskContractBinding.canonicalHash }
455
+ : {}),
456
+ status: "unknown",
457
+ },
458
+ });
459
+ }
460
+ }
148
461
  return undefined;
462
+ }
149
463
  const completedPasses = pass?.pass ?? Math.max(1, input.state.convergence?.currentPass ?? 1);
150
464
  const maxPasses = Math.max(completedPasses, input.state.convergence?.maxPasses ?? 1);
151
465
  const parentSourceBindingHash = sourceBindingHash(input.spec);