@tea-agent/loop-agent 0.41.1-beta.0 → 0.42.0-next.1

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 (273) hide show
  1. package/CHANGELOG.md +61 -207
  2. package/dist/adapters/context-transfer/optional-pi-handoff.js +31 -0
  3. package/dist/adapters/context-transfer/pi-session.js +61 -0
  4. package/dist/application/dag/generate-task-dag.js +19 -75
  5. package/dist/application/task-lifecycle/advance.js +5 -24
  6. package/dist/application/task-lifecycle/observe.js +17 -171
  7. package/dist/application/task-lifecycle/plan-transitions.js +7 -42
  8. package/dist/application/task-lifecycle/recommendations.js +2 -13
  9. package/dist/build-stamp.json +3 -3
  10. package/dist/cli/command-definitions.js +12 -7
  11. package/dist/cli/program.js +23 -6
  12. package/dist/commands/client-recovery.js +0 -3
  13. package/dist/commands/dag-artifact.js +284 -0
  14. package/dist/commands/dag-context.js +184 -0
  15. package/dist/commands/dag-rerun.js +206 -1
  16. package/dist/commands/init.js +1 -27
  17. package/dist/commands/task-advance.js +0 -19
  18. package/dist/executors/dag-pi-executor.js +266 -3792
  19. package/dist/executors/pi-executor.js +4 -15
  20. package/dist/executors/pi-sdk-executor.js +3 -0
  21. package/dist/executors/shell-executor.js +217 -945
  22. package/dist/executors/shell-write-guard.js +0 -7
  23. package/dist/{worker → infrastructure}/console/app-data.js +4 -0
  24. package/dist/infrastructure/console/artifact-revision-store.js +430 -0
  25. package/dist/infrastructure/console/context-export-store.js +160 -0
  26. package/dist/infrastructure/console/dir-lock.js +132 -0
  27. package/dist/infrastructure/console/operation-store.js +197 -0
  28. package/dist/infrastructure/harness/artifact-store.js +10 -1
  29. package/dist/infrastructure/harness/atomic-write.js +12 -2
  30. package/dist/shared/context-transfer/artifact-revision.js +172 -0
  31. package/dist/shared/context-transfer.js +418 -0
  32. package/dist/shared/dag-failure-category.js +0 -12
  33. package/dist/shared/openspec-spec.js +4 -70
  34. package/dist/shared/operator/capabilities.js +14 -7
  35. package/dist/shared/operator/safe-run-summary.js +1 -0
  36. package/dist/shared/path-safety.js +93 -0
  37. package/dist/shared/preview.js +28 -4
  38. package/dist/task/config-types.js +9 -35
  39. package/dist/task/contract/adopt.js +0 -4
  40. package/dist/task/contract/import-revision.js +0 -4
  41. package/dist/task/contract/project.js +0 -3
  42. package/dist/task/contract/schema.js +1 -2
  43. package/dist/task/frontend-project-capability.js +20 -203
  44. package/dist/task/runtime.js +2 -5
  45. package/dist/task/source-prepare/build-draft.js +3 -3
  46. package/dist/task/source-prepare/fragment-inventory.js +9 -15
  47. package/dist/task/source-prepare/prepare.js +1 -89
  48. package/dist/task/source-prepare/semantic-intake.js +2 -6
  49. package/dist/task/source-references.js +1 -22
  50. package/dist/task/task-demand-routing.js +3 -0
  51. package/dist/worker/console/chat/chat-event-store.js +2 -2
  52. package/dist/worker/console/chat/pi-runtime.js +3 -2
  53. package/dist/worker/console/chat/resource-preferences-store.js +1 -1
  54. package/dist/worker/console/chat/routes.js +13 -4
  55. package/dist/worker/console/chat/semantic-activity.js +12 -11
  56. package/dist/worker/console/chat/session-stats.js +96 -0
  57. package/dist/worker/console/chat/session-store.js +1 -1
  58. package/dist/worker/console/chat/turn-process.js +28 -4
  59. package/dist/worker/console/chat/user-questions.js +1 -1
  60. package/dist/worker/console/console-update-runtime.js +1 -1
  61. package/dist/worker/console/context-transfer-diagnostics.js +198 -0
  62. package/dist/worker/console/dag-confirmation.js +1 -1
  63. package/dist/worker/console/dag-execution-receipt.js +1 -1
  64. package/dist/worker/console/doctor.js +1 -1
  65. package/dist/worker/console/draft-store.js +1 -1
  66. package/dist/worker/console/human-gate-token.js +1 -1
  67. package/dist/worker/console/index.js +3 -6
  68. package/dist/worker/console/interview/assessment.js +1 -1
  69. package/dist/worker/console/interview/session.js +1 -1
  70. package/dist/worker/console/operation-runner.js +45 -4
  71. package/dist/worker/console/operation-sse.js +1 -1
  72. package/dist/worker/console/operation-wait.js +1 -1
  73. package/dist/worker/console/operator-actions.js +107 -168
  74. package/dist/worker/console/operator-surface-health.js +1 -1
  75. package/dist/worker/console/operator-user-error.js +169 -0
  76. package/dist/worker/console/pi-plugins.js +60 -1
  77. package/dist/worker/console/routes.js +637 -8
  78. package/dist/worker/console/security.js +35 -0
  79. package/dist/worker/console/server.js +6 -6
  80. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-Bho4we4c.js → abnfDiagram-N423BO3Z-DZZ8m3PO.js} +1 -1
  81. package/dist/worker/console/static/assets/{arc-TBDkTeK0.js → arc-D6PvaVd-.js} +1 -1
  82. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-BF_fZrn2.js → architectureDiagram-T3A2C74G-B_OTOiI8.js} +1 -1
  83. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-CCnPgUe2.js → blockDiagram-VBNYF7ZC-Bv6rqHBg.js} +1 -1
  84. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-BCYZJLAT.js → c4Diagram-5PPSVZJV-B8eHr0oz.js} +1 -1
  85. package/dist/worker/console/static/assets/channel-BU5gOilw.js +1 -0
  86. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-D8K6adhU.js → chunk-2GRJ4B5K-DYwR0im2.js} +1 -1
  87. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-DkT1Q78b.js → chunk-2Q5K7J3B-D2WPGqXt.js} +1 -1
  88. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-DuhvpIr7.js → chunk-5RXB4S5H-CQISJ_I7.js} +1 -1
  89. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-BnK6dC49.js → chunk-5VM5RSS4-C0o2Du1e.js} +1 -1
  90. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-DPz__z7r.js → chunk-6Q2QTUOP-4f8kr-U7.js} +1 -1
  91. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-0kkppM2j.js → chunk-GF5L2VYU-D_OWvXzX.js} +1 -1
  92. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-BB41iK5t.js → chunk-JWPE2WC7-CasdPz5X.js} +1 -1
  93. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-CiVrxKHU.js → chunk-KBJHAD2P-Cj8lRrla.js} +1 -1
  94. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-C2h9Xje1.js → chunk-RYQCIY6F-CUvD1FSd.js} +1 -1
  95. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-3iOSHdbM.js → chunk-XXDRQBXY-CqLw_eqB.js} +1 -1
  96. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DIzKJGHr.js +1 -0
  97. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DIzKJGHr.js +1 -0
  98. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BN3A7tkk.js → cose-bilkent-JH36ORCC-ku-WqJPx.js} +1 -1
  99. package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-CTuBy0Or.js → cynefin-VYW2F7L2-Bq_PYDhl.js} +1 -1
  100. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-wb6tUlMN.js → cynefinDiagram-MW4NZA55-BiGZV641.js} +1 -1
  101. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-GP1Ivx8B.js → dagre-VZM6K2ZE-C4JRlglF.js} +1 -1
  102. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-ejrcK6L0.js → diagram-7IWD3JNH-B0dNeWYG.js} +1 -1
  103. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-YFkCCvUU.js → diagram-B4RE2ZJO-Cj35YvYM.js} +1 -1
  104. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-B4rrvIaL.js → diagram-LBJQPF4R-uzQoJ2-8.js} +1 -1
  105. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-C-YIZcUf.js → diagram-Q27KOJAE-D1a-Buoz.js} +1 -1
  106. package/dist/worker/console/static/assets/{diagram-UB23O5K3-BPF5wcL1.js → diagram-UB23O5K3-XjRrLRSs.js} +1 -1
  107. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-CU5SzXjO.js → ebnfDiagram-BXEA7PRR-Da_O24cW.js} +1 -1
  108. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-CpL414DE.js → erDiagram-JOGREHBK-BLJ8jrYU.js} +1 -1
  109. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-MrhLzNau.js → flowDiagram-UKHOOZJN-B9GrLjM0.js} +1 -1
  110. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-Bg4qFuUo.js → ganttDiagram-PKOTCBZU-CeJ0TqiK.js} +1 -1
  111. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-ColxSXLR.js → gitGraphDiagram-DS77QQ5N-Bm2eNNFX.js} +1 -1
  112. package/dist/worker/console/static/assets/index-H9rFJiGL.css +1 -0
  113. package/dist/worker/console/static/assets/index-xwu9GxEc.js +451 -0
  114. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-Czvtm6gc.js → infoDiagram-6WML65LV-DB26i3d8.js} +1 -1
  115. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-B7Xp8HyJ.js → ishikawaDiagram-WSZJBQD7-BOGRyeZT.js} +1 -1
  116. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-DWYZcvph.js → journeyDiagram-NVQOT4AX-CZRoBO_6.js} +1 -1
  117. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-KTLZRUjx.js → kanban-definition-27J2QSJJ-qlWhJyoB.js} +1 -1
  118. package/dist/worker/console/static/assets/{linear-_Exn7bfl.js → linear-CfUiDDB3.js} +1 -1
  119. package/dist/worker/console/static/assets/{mermaid.core-Cxg8kX8V.js → mermaid.core-BQe6fpqj.js} +5 -5
  120. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-oKrlo2Bt.js → mindmap-definition-FAOFIHXS-zFzWHw64.js} +1 -1
  121. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-XAeteiNd.js → pegDiagram-VL7TDLO6-DFGUqjZO.js} +1 -1
  122. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-BTf1K-lp.js → pieDiagram-7S7Q4E2Y-BB5i0l8Z.js} +1 -1
  123. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-C0IlY0Jf.js → quadrantDiagram-CIZ2JOQS-obbVZ_X5.js} +1 -1
  124. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-BVbKtZhW.js → railroadDiagram-AXF67PYL-BwdaNzc1.js} +1 -1
  125. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-C5e4JFcr.js → requirementDiagram-LRYGKXZP-CkTJaugh.js} +1 -1
  126. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-Cz30hc29.js → sankeyDiagram-W5VNT64P-BwJ-hIgq.js} +1 -1
  127. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-DS33n6d0.js → sequenceDiagram-SI44F4Z6-BzSgmm7w.js} +1 -1
  128. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-46w7v-9T.js → sizeCapture-X5ZJPWSS-Bn3oj5Q1.js} +1 -1
  129. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-pbcD5SsZ.js → stateDiagram-OKZ733FA-dxhGtL8K.js} +1 -1
  130. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Cld2qK9v.js +1 -0
  131. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-DuivYBSj.js → swimlanes-SLNWSIFB-BLpEInya.js} +2 -2
  132. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-TIHpiT7w.js +8 -0
  133. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-Cb9VZVIl.js → timeline-definition-Z64GVDOM-ChJGYcXy.js} +1 -1
  134. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-D2-mfOgR.js → vennDiagram-T6HMQDX7-DK-qjRer.js} +1 -1
  135. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-DeS2aC76.js → wardleyDiagram-T6FBY63Y-3qeaWAg-.js} +1 -1
  136. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-WGsrFjxH.js → xychartDiagram-ELKLHX3M-CootlyP9.js} +1 -1
  137. package/dist/worker/console/static/index.html +7 -2
  138. package/dist/worker/console/static-src/app/useOperatorActions.js +3 -2
  139. package/dist/worker/console/static-src/app/useRunProgress.js +9 -2
  140. package/dist/worker/console/static-src/operator-chat/dag-progress-link.js +22 -0
  141. package/dist/worker/console/static-src/operator-chat/useChatSessions.js +2 -0
  142. package/dist/worker/console/static-src/operator-chat/useChatThread.js +6 -0
  143. package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +28 -3
  144. package/dist/worker/console/static-src/pages/tasks/run-panel-progress.js +106 -0
  145. package/dist/worker/console/static-src/shell/console-update-reload.js +25 -0
  146. package/dist/worker/console/workspace-context.js +28 -112
  147. package/dist/worker/console/workspace-registry.js +2 -2
  148. package/dist/worker/continuation/worker-continuation.js +278 -0
  149. package/dist/worker/observability/read-model.js +4 -0
  150. package/dist/worker/observe/health.js +1 -1
  151. package/dist/worker/observe/node-transparency.js +572 -0
  152. package/dist/worker/observe/routes.js +51 -1
  153. package/dist/worker/observe/static/api.js +69 -5
  154. package/dist/worker/observe/static/dag-context-reason-labels.d.ts +9 -0
  155. package/dist/worker/observe/static/dag-context-reason-labels.js +120 -0
  156. package/dist/worker/observe/static/dag-node-purpose.js +0 -5
  157. package/dist/worker/observe/static/state.js +3 -1
  158. package/dist/worker/observe/static/styles.css +1037 -126
  159. package/dist/worker/observe/static/views/dag-inspector.js +1217 -65
  160. package/dist/worker/observe/static/views/session-timeline.js +121 -25
  161. package/dist/worker/outcomes/adapters.js +19 -0
  162. package/dist/worker/outcomes/types.js +1 -0
  163. package/dist/worker/pool/attempt-lease.js +97 -66
  164. package/dist/worker/pool/begin-attempt-with-lease.js +1 -0
  165. package/dist/worker/pool/reconcile.js +46 -1
  166. package/dist/worker/pool/run-store.js +2 -0
  167. package/dist/worker/pool/state-projection.js +2 -0
  168. package/dist/worker/task-spec/workflow-routing.js +8 -3
  169. package/dist/workflows/dag/artifact-bindings.js +149 -0
  170. package/dist/workflows/dag/artifact-revision-schema-registry.js +31 -0
  171. package/dist/workflows/dag/backend-test-result-contract.js +1 -1
  172. package/dist/workflows/dag/budget-enforcement.js +10 -0
  173. package/dist/workflows/dag/context-receipt.js +305 -0
  174. package/dist/workflows/dag/context-transfer/context-bundle.js +423 -0
  175. package/dist/workflows/dag/context-transfer/operator-actions.js +61 -0
  176. package/dist/workflows/dag/context-transfer/renderers.js +93 -0
  177. package/dist/workflows/dag/contract-validator-registrations.js +2 -1
  178. package/dist/workflows/dag/frontend-implementation-contract.js +162 -932
  179. package/dist/workflows/dag/frontend-plan-render.js +1 -2
  180. package/dist/workflows/dag/frontend-prewrite-gate.js +349 -255
  181. package/dist/workflows/dag/frontend-recovery-plan.js +10 -17
  182. package/dist/workflows/dag/frontend-recovery-run.js +20 -33
  183. package/dist/workflows/dag/frontend-repair.js +432 -1
  184. package/dist/workflows/dag/frontend-review-context.js +15 -261
  185. package/dist/workflows/dag/frontend-verification-trace.js +24 -249
  186. package/dist/workflows/dag/frontend-worktree-diff.js +17 -250
  187. package/dist/workflows/dag/frontend-writer-rollback.js +32 -0
  188. package/dist/workflows/dag/init-hybrid.js +640 -685
  189. package/dist/workflows/dag/interrupt-request.js +0 -7
  190. package/dist/workflows/dag/node-execution.js +116 -759
  191. package/dist/workflows/dag/path-safety.js +1 -0
  192. package/dist/workflows/dag/prompt.js +30 -38
  193. package/dist/workflows/dag/report.js +1 -37
  194. package/dist/workflows/dag/rerun-feedback.js +1 -256
  195. package/dist/workflows/dag/rerun-plan.js +557 -11
  196. package/dist/workflows/dag/rerun-run.js +601 -38
  197. package/dist/workflows/dag/rerun-task.js +0 -29
  198. package/dist/workflows/dag/retry-policy.js +104 -214
  199. package/dist/workflows/dag/runner.js +142 -430
  200. package/dist/workflows/dag/scheduler.js +16 -114
  201. package/dist/workflows/dag/skill-snapshot.js +17 -0
  202. package/dist/workflows/dag/types.js +195 -246
  203. package/dist/workflows/dag/validate.js +12 -28
  204. package/docs/architecture/runtime-boundaries.md +6 -6
  205. package/docs/architecture/worker-and-feature.md +1 -1
  206. package/docs/init-surface.manifest.json +12 -30
  207. package/docs/skills/vetted-skill-registry.md +2 -4
  208. package/docs/templates/README.md +0 -2
  209. package/docs/templates/agent-dag-report.schema.json +2 -8
  210. package/docs/templates/agent-dag.schema.json +33 -1
  211. package/docs/templates/frontend-implementation-contract.schema.json +1 -4
  212. package/docs/templates/product-line/task.yaml +1 -1
  213. package/harness.json +3 -3
  214. package/package.json +3 -1
  215. package/skills/frontend-bounded-implement/SKILL.md +14 -15
  216. package/skills/frontend-design-review/SKILL.md +41 -22
  217. package/skills/frontend-implementation/SKILL.md +52 -0
  218. package/skills/frontend-implementation/references/code-standards.md +33 -0
  219. package/skills/frontend-implementation/references/design-spec.md +56 -0
  220. package/skills/frontend-implementation/references/node-contracts.md +31 -0
  221. package/skills/frontend-review/SKILL.md +15 -20
  222. package/skills/frontend-review/references/review-findings.md +7 -6
  223. package/skills/frontend-verification/SKILL.md +1 -1
  224. package/skills/loop-agent/references/command-reference.md +6 -1
  225. package/skills/loop-agent/references/hybrid-dag.md +2 -2
  226. package/dist/commands/dag-follow-up.js +0 -138
  227. package/dist/executors/pi-read-budget-policy.js +0 -239
  228. package/dist/worker/console/frontend-human-decision-adapter.js +0 -19
  229. package/dist/worker/console/frontend-split-operation-adapter.js +0 -20
  230. package/dist/worker/console/operation-store.js +0 -389
  231. package/dist/worker/console/static/assets/channel-bnXW0U3C.js +0 -1
  232. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-rZpq_twR.js +0 -1
  233. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-rZpq_twR.js +0 -1
  234. package/dist/worker/console/static/assets/index-D3CC4eUz.css +0 -1
  235. package/dist/worker/console/static/assets/index-DLt4ZFvD.js +0 -437
  236. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-zBMYiUyi.js +0 -1
  237. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-d_rms-5i.js +0 -8
  238. package/dist/worker/console/static-src/active-run-badge.js +0 -17
  239. package/dist/worker/materialize/frontend-split-task-materializer.js +0 -72
  240. package/dist/workflows/dag/dag-retry-schema.js +0 -138
  241. package/dist/workflows/dag/frontend-closeout.js +0 -221
  242. package/dist/workflows/dag/frontend-design-policy.js +0 -400
  243. package/dist/workflows/dag/frontend-human-decision.js +0 -182
  244. package/dist/workflows/dag/frontend-provider-capability-matrix.js +0 -159
  245. package/dist/workflows/dag/frontend-read-budgets.js +0 -12
  246. package/dist/workflows/dag/frontend-recovery-capsule.js +0 -455
  247. package/dist/workflows/dag/frontend-recovery-controller.js +0 -202
  248. package/dist/workflows/dag/frontend-recovery-lineage.js +0 -178
  249. package/dist/workflows/dag/frontend-review-findings.js +0 -270
  250. package/dist/workflows/dag/frontend-shadow-dual-write.js +0 -914
  251. package/dist/workflows/dag/frontend-shape-capsule-store.js +0 -191
  252. package/dist/workflows/dag/frontend-shape-facts.js +0 -409
  253. package/dist/workflows/dag/frontend-shape.js +0 -427
  254. package/dist/workflows/dag/frontend-source-fidelity-ledger.js +0 -108
  255. package/dist/workflows/dag/frontend-split-application-service.js +0 -203
  256. package/dist/workflows/dag/frontend-split-orchestrator.js +0 -899
  257. package/dist/workflows/dag/frontend-typed-event-store.js +0 -452
  258. package/dist/workflows/dag/frontend-typed-event-transaction.js +0 -180
  259. package/dist/workflows/dag/frontend-writer-admission.js +0 -285
  260. package/dist/workflows/dag/frontend-writer-status.js +0 -256
  261. package/dist/workflows/dag/recovery-lease.js +0 -80
  262. package/docs/templates/frontend-implementation-dag.json +0 -89
  263. package/docs/templates/spec-registry.schema.json +0 -45
  264. package/skills/frontend-bounded-implement/references/code-standards.md +0 -19
  265. package/skills/frontend-contract/SKILL.md +0 -23
  266. package/skills/frontend-contract/references/contract-protocol.md +0 -34
  267. package/skills/frontend-plan/SKILL.md +0 -26
  268. package/skills/frontend-plan/references/decision-contract.md +0 -37
  269. package/skills/frontend-plan/references/design-decisions.md +0 -17
  270. package/skills/frontend-scout/SKILL.md +0 -25
  271. package/skills/frontend-scout/references/design-evidence.md +0 -16
  272. package/skills/frontend-scout/references/scout-evidence.md +0 -23
  273. /package/dist/{worker → infrastructure}/console/repo-fingerprint.js +0 -0
@@ -0,0 +1,31 @@
1
+ # Frontend Node Contracts
2
+
3
+ Pre-write nodes are read-only. Preserve IDs, labels, commands, language, required headings.
4
+
5
+ ## Core nodes
6
+
7
+ - **`frontend-contract-pi`**: `Scope`, `Non-goals`, `Acceptance Criteria`, `UI States`, `Target Runtime Environment`, `Risks`, `Verification Expectations`; no guessed requirements.
8
+ - **`frontend-scout-pi`**: routes, components, tokens, data/API/Mock, scripts, tests, assets; fact vs inference vs gap. Search+read `openspec/schemas/`, `openspec/project-specs/`, `ai_workspace/` first. Output stack, styling, conventions, state/data, test entry points, reuse, risks.
9
+ - **`frontend-plan-pi` + conditional design loop**: AC → observable `expectedOutcome`; interactions → `trigger`+`expectedBehavior`; include steps, in-bound files, UI states, reuse, deps, Mock/API, frozen verify entrypoints and integration gaps. DAG freezes a protected skeleton (`schemaVersion`, `sourceBinding`, `riskLevel`, `targets.files`, `mockApi.productionDefaultOff`). Model returns a **JSON-only** editable RFC 7386 patch (`frontend-implementation-contract-plan-patch-v1`) plus one `openspec-citations` block. Runtime compiles canonical `frontend-implementation-contract-v1` and archives raw/extracted/normalized/validation candidates; unresolved optional symbols are dropped and audited. No plan prose; gate renders plan.md. IDs+paths ≠ behavior semantics. Applicable UI states need behavior/implementation/verification; non-applicable states need reasons. Active Mock needs frozen commands; `auto` without confirmed capability/command → `not-needed`; `required` without command → generation-time blocked. Only `request-revision` runs revision+final review; small-risk gets one review.
10
+ - `uiComponentChoices[]` (optional): `{purpose, component, decision, specReference, rationale}`; `specified` needs `specReference{path,section,line}`; `new` needs null ref+rationale.
11
+ - **`frontend-prewrite-gate-shell`**: sole write authorization. Resolve effective plan (revised if revision ran, else original) + review; require exact pass; retain every REQ/BR/AC id; enforce Mock policy; validate schema/source binding+writeSet containment; materialize `contracts/frontend-implementation-contract.json` from the **single** fenced contract block (multiple candidates fail closed `invalid-output`). Fallback only when conditional primary absent; malformed primary fails closed. Generation-time blocked Mock yields one blocking shell node, no writer.
12
+ - `verificationTarget.commandLabel` must be a **frozen command label** from `verifyEvidence.commandLabels`; others fail closed (`invalid-output`). Empty frozen set (no `run.json`) skips check.
13
+ - `mockApi.strategy !== "not-needed"` fails closed when `mockCommandLabels` empty (`no authorized Mock verification commands`).
14
+ - OpenSpec policy: `task.json.frontendOpenspec.policy` (default `cited`); candidates = `requiredReadPaths` ∪ task-source citations; effective plan must append one fenced `openspec-citations` block (one JSON `{"path","section","line"}` per line). Candidates non-empty but block missing/unparseable → `openspec-citation-block-unparseable`; candidate not cited → `openspec-not-cited`; cited path without read event → `openspec-citation-not-read` (anti-fabrication). Empty candidates skip enforcement. `scan-strict` keeps full-read semantics (`openspec-not-read`); both modes keep `candidate-missing-drift`.
15
+ - Component conformance: missing `uiComponentChoices` (frozen bucket non-empty + UI-visible work) → `component-choices-missing`; bad/uncited `specReference.path` → `component-spec-reference-invalid` / `component-spec-not-cited`.
16
+ - revisionPatch mode: revision output is an RFC 7386 merge-patch delta applied on the original canonical contract node (`planFallbackFromNodeIds[0]`); protected skeleton paths remain immutable. Legacy DAGs keep full-contract semantics. Size guard: canonical serialization >64KB → `retryable-invalid` + `contract-too-large`.
17
+ - **`frontend-implement-pi`**: sole regular exclusive writer; uses `frontend-bounded-implement` (not this skill). Stay in `writeSet`; real requests default-on. Atomic handler/intercept/adapter with tests. Stop on forbidden paths/guesses. First line `IMPLEMENTATION_OUTCOME: changed|already-satisfied|blocked`; runtime checks against attributed diff. Optional mock-verify when frozen; static+behavior always; behavior must prove page consumption. `not-needed` keeps real integration pending unless real backend has fresh evidence.
18
+
19
+ ## Contract / trace / stages (M1–M2)
20
+
21
+ - `frontend-verify-assess-shell` runs Mock/static/behavior groups, binds `verificationTargets` to command labels+evidence, writes `frontend-verification-trace.json`+`frontend-repair-assessment.json`; browser/visual stay `not-run`.
22
+ - `frontend-review-context-shell` captures real diff; combines contract, effective trace, repair assessment, diff into `contracts/frontend-review-context.json`.
23
+ - Implement stages: (1) contract confirm (2) tests sync (3) component/UI (4) API/Mock (5) frozen checks (6) diff cleanup. Summary: Contract Ref, Changed Files, Requirements, UI States, Tests, Verification Attempts, Deviations, Residual Risks.
24
+
25
+ ## Repair (M3)
26
+
27
+ Only `eligible=true` runs `frontend-repair-pi` (same writeSet; no re-spec; max 1 attempt) + `frontend-reverify-shell`. No-failure skips both. Non-repairable contract/path/dependency/credential/deploy/spec-unclear failures fail closed.
28
+
29
+ ## Risk & capability (M4–M6)
30
+
31
+ Deterministic risk, no model; high-risk beats small; supervised never small. Standard/high-risk: 15 top-level nodes; small: 13 (omits revision + final review). Capability seed injects adapters; openspec specs and task sources outrank adapter guidance. A11y: static/component tools only when present; Browser a11y always not-run.
@@ -9,25 +9,17 @@ references:
9
9
 
10
10
  # Frontend Review
11
11
 
12
- Use for `frontend-review-pi`; read the findings guide and capacity diagnostic first.
13
- Inputs are `contracts/frontend-review-context.json`, its hash-bound contract
14
- reference/index and diff fragments, and only source files named by that diff. Use
15
- indexed contract sections when recommended. Do not reopen task sources, plans,
16
- design-review prose, OpenSpec, or `ai_workspace/`; the bound context is authoritative.
12
+ Use for `frontend-review-pi`; read the findings guide first. Required inputs are
13
+ original task/reference material, effective plan/design branch, implementation summary,
14
+ and `contracts/frontend-review-context.json`. That canonical context binds the validated
15
+ implementation contract, effective verification trace, repair assessment, optional
16
+ `frontend-lint-assessment-v1`, and run-owned diff. The diff is authoritative.
17
17
 
18
- ## Authoritative Terminal
18
+ ## Verdict Contract
19
19
 
20
- Complete the review with exactly one committed typed tool call:
21
-
22
- - `approve_review` when no Critical/Important finding remains;
23
- - `request_review_changes` for a defect, missing required evidence, forbidden
24
- write, or unmet acceptance criterion. It must include a typed `issueCategory`,
25
- at least one `evidenceRef`, and non-empty findings.
26
-
27
- The typed terminal is the only authoritative outcome. Do not require or emit a
28
- `VERDICT:` line or response-text JSON verdict. A request for review changes ends
29
- this run and is handled by the recovery controller rather than a same-run repair
30
- branch.
20
+ The first non-empty line must be exactly `VERDICT: pass` or
21
+ `VERDICT: request-revision`. Any Critical/Important finding, failed or missing
22
+ required check, forbidden write, or unmet acceptance criterion forces revision.
31
23
 
32
24
  ## Review Scope
33
25
 
@@ -35,7 +27,7 @@ branch.
35
27
  - Inspect every changed file against allowed, forbidden, and approved write scope.
36
28
  - Map criteria to behavior, applicable UI states, tests, and shell evidence.
37
29
  - Review state/data flow, validation, async/error behavior, design, responsive/a11y,
38
- dependencies, and regression risk when applicable.
30
+ dependencies, maintenance, and regression risk when applicable.
39
31
  - Inspect static, behavior, and available Mock-specific artifacts directly. For Mock
40
32
  strategies, compare the endpoint matrix, handler/fixture/adapter and consumer diff;
41
33
  require the real request as default, contract-aligned fixtures, production isolation,
@@ -46,8 +38,11 @@ branch.
46
38
  baseline-matched diagnostics on unchanged files, and none on writer-changed files.
47
39
  Report debt, never `lint passed`; `failed`/`unavailable` blocks. Typecheck, build,
48
40
  and test still require successful final exits.
49
- - Evaluate component/design claims against bound evidence; do not replace it with a
50
- repository-wide search or connector query.
41
+ - Component/design claims need both knowledge-base and local openspec evidence. Query
42
+ the connector when available and always read task-relevant files under
43
+ `<repoRoot>/openspec/schemas/`, `<repoRoot>/openspec/project-specs/`, and `<repoRoot>/ai_workspace/`.
44
+ Connector format is TODO; never invent evidence. Only successful `read` calls are
45
+ observable as "已读取规范文件".
51
46
  - Treat shell exit status as authoritative. Do not edit files.
52
47
 
53
48
  ## Evidence And Output
@@ -14,23 +14,24 @@
14
14
  `baseline-debt` only with a valid `frontend-lint-assessment-v1`; this is not a
15
15
  passed lint result. A changed-file lint diagnostic, new unmatched diagnostic,
16
16
  command drift, missing baseline, timeout, or unparseable output is Important.
17
- - Treat the design evidence already bound in the canonical review context as the
18
- source of truth. Do not launch a connector query or repository-wide OpenSpec/
19
- `ai_workspace` search to replace frozen evidence; label a missing bound evidence
20
- reference accurately instead.
17
+ - Treat knowledge base, `openspec/schemas/`, `openspec/project-specs/`, and `ai_workspace/` as
18
+ parallel sources. Record connector/query/source/time plus openspec search terms and
19
+ matched paths/headings; label fallback or unavailable accurately.
21
20
 
22
21
  ## Review Sequence
23
22
 
24
23
  1. Establish changed-file inventory and write boundaries.
25
- 2. Compare the bound contract with the approved constraints and cumulative diff.
24
+ 2. Compare original requirement with derived contract/constraints.
26
25
  3. Map each criterion to code, states, tests, and evidence.
27
26
  4. Inspect interactions, state/data/API behavior, failure paths, and regressions.
28
27
  5. Check mock selection, contract-to-fixture mapping, activation/default path,
29
28
  handler/fixture/adapter and consumer diff, verification, production imports, and
30
29
  the real-integration gap.
31
- 6. Check bound design evidence, responsive/a11y behavior, dependencies, and maintenance.
30
+ 6. Check design evidence, responsive/a11y behavior, dependencies, and maintenance.
32
31
  7. Classify findings and derive the verdict mechanically.
33
32
 
33
+ Skipping either directory is Important when design compliance affects acceptance.
34
+
34
35
  ```text
35
36
  - [Critical|Important|Minor] path:line — Problem; impact; required correction; evidence.
36
37
  ```
@@ -30,7 +30,7 @@ verdict/findings, and required browser, visual, manual, or knowledge evidence.
30
30
  `frontend-lint-assessment-v1` proving only pre-writer diagnostics on unchanged
31
31
  files. Report debt count, changed files, and raw evidence. Typecheck/build/test do
32
32
  not support debt.
33
- - Use design and requirement evidence referenced and hash-bound by
33
+ - Use design and requirement evidence already bound inside
34
34
  `contracts/frontend-review-context.json`. Closeout must not query connectors,
35
35
  re-open task sources, OpenSpec, AI workspace, upstream model prose, or start new
36
36
  repository research.
@@ -347,8 +347,13 @@ loop-agent dag reconcile-run --run-id <run-id> --action abandon --reason "..."
347
347
  loop-agent dag request-interrupt --run-id <run-id> --request-id <id> --target-operation-id <id> --reason-code <code> --reason <detail> [--json] # 协作中止:写入 interrupt.json(identity CAS);需配 --expected-runner-pid/--expected-runner-hostname 校验 runner 身份
348
348
  loop-agent dag rerun --run-id <run-id> --from-node <node-id> --plan [--json] # 从节点重跑资格预检(不执行)
349
349
  loop-agent dag rerun --run-id <run-id> --from-node <node-id> --plan-hash <sha256> --request-id <key> --reason "..." [--json] # 安全子图 continuation
350
+ loop-agent dag context show --run-id <run-id> --node-id <node-id> --attempt <n> --json # 有界 effective-context 摘要
351
+ loop-agent dag context export --run-id <run-id> --node-id <node-id> --attempt <n> --target <generic|pi-session|pi-handoff|readable> --output <bundle.zip> # 默认 redacted;raw 另需显式确认
352
+ loop-agent dag artifact consumers --run-id <run-id> --node-id <producer> --artifact <relative-path> --json # 只读 frozen binding consumer
353
+ loop-agent dag artifact revision stage --run-id <run-id> --node-id <producer> --artifact <relative-path> --file <replacement> --request-id <key> --json # 暂存 revision,不修改 parent
354
+ loop-agent dag artifact revision discard --revision-id <revision-id> --request-id <key> --json
355
+ loop-agent dag rerun --run-id <run-id> --artifact-revision <revision-id> --plan [--json] # 单产物影响闭包预检
350
356
  loop-agent dag rerun-task --run-id <run-id> --reason "..." --request-id <key> [--profile auto] [--task-id <id>] [--json] # standalone 完整任务重跑
351
- loop-agent dag follow-up <parent-run-id> [--task-id <id>] [--execute] [--profile auto|minimal|standard|reviewed|supervised] # 将 frontend review 的 request_review_changes findings 物化为下游 frontend task;默认只创建并返回 task advance 命令
352
357
  loop-agent dag request-interrupt --run-id <run-id> --request-id <key> --target-operation-id <op-id> --reason-code <code> --reason "..." --expected-runner-pid <pid> --expected-runner-hostname <host> --expected-runner-started-at <ts> --expected-controller-fingerprint <fingerprint> # 协作式中止:经 Human Gate 登记 interrupt.json,runner 等当前节点安全收敛后再停调度,不直接 SIGKILL
353
358
  loop-agent dag reconcile-tasks --glob '<pattern>' # 仅报告的 task/run/artifact/verify drift audit
354
359
  loop-agent dag final-verification <task-id> # 生成 closeout DAG,closeout artifact 后再 final verify
@@ -16,7 +16,7 @@
16
16
 
17
17
  对于默认 `standard` 任务,生成器先读取 `source/需求.md` 中的结构化任务类型,再结合 `allowedPaths` 与 React/Next/Vue 强工程证据做确定性分类。确认是前端项目且任务不是明确后端、前后端混合、排除前端或仅文档/测试范围时,默认选择 `frontend-implementation` DAG,不依赖需求关键词。分类不会把普通后端实现路由到 `backend-test`;显式 profile、`workflowPolicy` 或 supervised quality gate 只记录治理强度,不把已识别的前端业务 workflow 换回通用模板。
18
18
 
19
- 前端专用链保留独立 contract/scout;plan 通过增量 typed `record_*` 工具提交决策账本并以唯一 `finalize_plan` 收口(无 fenced JSON 文本协议)。写授权由 `frontend-design-policy-shell`(确定性设计检查 + 物化唯一 authoritative `frontend-implementation-contract-v1`)与 `frontend-writer-admission-shell`(唯一写入授权:派生并冻结 writeSet、pre-writer baseline、admission digest,`admitted` 才放行 writer)承接;design review 与 final review 的权威终态是 committed typed tool(`approve_design|request_design_changes`、`approve_review|request_review_changes`)。实现后 `frontend-verify-shell` 合并 lint/Mock/static/behavior/trace;任何验证失败都是 terminal,物化 `frontend-verify-failure-v1` 供 recovery 路由,无同 run repair。`frontend-review-context-shell` 绑定真实 diff 与有效验证证据后再 review/closeout。拓扑按 shape 路由:Micro 7 / Small 10 / Standard-High 11 个顶层节点;Standard/High 完整主链为 `frontend-contract-pi` → `frontend-scout-pi` → `frontend-plan-pi` → `frontend-design-policy-shell` → `frontend-design-review-pi` → `frontend-writer-admission-shell` → `frontend-implement-pi` → `frontend-verify-shell` → `frontend-review-context-shell` → `frontend-review-pi` → `frontend-closeout-shell`,Small 去掉独立 `frontend-design-review-pi`,Micro 为 `frontend-contract-import-shell` → `frontend-writer-admission-shell` → `frontend-implement-pi` → `frontend-verify-shell` → `frontend-review-context-shell` → `frontend-review-pi` → `frontend-closeout-shell`。生成期 blocked Mock 只生成一个确定性阻塞节点且没有 writer。
19
+ 前端专用链保留独立 contract/scout;plan 同时选择 Mock/API 策略并输出结构化 implementation contract。design initial pass 直接使用原计划,只有 request-revision 才运行 revision/final review;small-risk 只执行一次 design review。`frontend-prewrite-gate-shell` 合并生效 verdict、REQ/BR/AC 覆盖、Mock policy 和 contract 物化,是唯一写入授权。实现后 `frontend-verify-assess-shell` 合并 Mock/static/behavior/trace/assessment;只有 `eligible=true` 才运行同 writeSet 的 repair 和 `frontend-reverify-shell`。`frontend-review-context-shell` 绑定真实 diff 与有效验证证据后再 review/closeout。standard/high-risk 为 15 个顶层节点,small-risk 为 13;绿色路径执行 11 个节点、7 次 Pi。生成期 blocked Mock 只生成一个确定性阻塞节点且没有 writer。
20
20
 
21
21
  > Backend-test Markdown-first:先由确定性环境 Shell 检查 clean env 中 Python/pytest、常见配置、conftest/fixture、test root、server entry 和 HTML renderer,失败时不消耗模型调用。随后 Pi 生成中文 README 索引与模块用例卡片并独立 Review `testcase/md/**`。第 4 节点只把前置条件、操作步骤、预期结果作为必选章节,并检查 Case ID、业务 AC、步骤/预期和占位措辞;不校验需求来源引用有效性或 Markdown sensitive-shaped 内容。pytest writer 为每次真实接口调用记录脱敏、有界的请求 method/URL/参数摘要和响应 status/body 摘要。第 6 节点只扫描每条 Case 明确映射的 pytest 脚本,同时支持模块级函数和 pytest class 方法,并把缺少请求/响应日志、递归脱敏或有界截断证据记录为 advisory。第 4/6 节点均写 PASS/FAIL findings 而不阻断后续;pytest 仍只运行一次,生成 JUnit,并把 Markdown 名称/场景/脚本映射与同一 JUnit 合成为按测试概览、质量校验、失败概览、用例执行明细和技术证据组织的中文 self-contained HTML 与 Markdown facts。最终 Pi 按固定简洁结构汇总 advisory 状态、执行事实和 L-5 结论。active 流程不要求模型生成 backend-test 业务 JSON。
22
22
 
@@ -91,7 +91,7 @@ loop-agent dag execute --dag <temp-dir>/hybrid-dag.json --init-only --canvas-pat
91
91
  - **Source binding / recovery**:新生成 DAG 在顶层冻结 `sourceBinding`(任务源相对路径、SHA-256、显式 `REQ/BR/AC`)。前端计划在存在显式编号时经过 `frontend-requirement-coverage-shell`;修订计划为 primary,只在条件分支未产生输出时 fallback 到原计划。主来源存在但缺号时仍在 writer 前 fail closed。中断后重新生成完整 DAG,不要从二手摘要拼接 impl-only DAG;v3 孤立 exclusive writer 若无 `sourceBinding` 且没有只读 planner 上游,会被 strict governance 拒绝。
92
92
  - **勿宣称 live smoke 已通过**,除非真实 `dag execute` execution 中 Pi read-only、Pi writer、显式 Cursor 或 shell node 均按 DAG 完成。
93
93
 
94
- 可复用 template:`docs/templates/agent-dag.base.json`(model 生成 DAG 的首选 base template)、`docs/templates/agent-dag.schema.json`(JSON Schema)、`docs/templates/agent-dag.supervised-implementation.json`(supervised implementation:writeSet audit、soft/hard verify、process supervisor、repair、review verdict gate)、`docs/templates/frontend-implementation-dag.json`(自包含的前端实现完整默认链:contract、scout、plan、design policy/review、writer admission、implement、verify、review context/review、closeout;不依赖 runtime builder 或其他模板,执行前替换全部 `REPLACE/WITH/...` 值)、`docs/templates/backend-test-dag.json`(后端测试专用模板)、`docs/templates/frontend-test-dag.json`(FE-test RAG:Markdown case manifest、串行 Playwright CLI case 子节点与逐 case 证据)、`docs/templates/agent-dag-process-supervisor.prompt.md`、`docs/templates/agent-dag-review-verdict.prompt.md`、`docs/templates/agent-dag-authority-surface-audit.prompt.md`(可选 authority surface verifier;authority signal 或显式 enablement 匹配时由 `dag init-hybrid` 插入)、`examples/hybrid-loop-agent-dag.json`、`docs/templates/hybrid-dag.json`。
94
+ 可复用 template:`docs/templates/agent-dag.base.json`(model 生成 DAG 的首选 base template)、`docs/templates/agent-dag.schema.json`(JSON Schema)、`docs/templates/agent-dag.supervised-implementation.json`(supervised implementation:writeSet audit、soft/hard verify、process supervisor、repair、review verdict gate)、`docs/templates/backend-test-dag.json`(后端测试专用模板)、`docs/templates/frontend-test-dag.json`(FE-test RAG:Markdown case manifest、串行 Playwright CLI case 子节点与逐 case 证据)、`docs/templates/agent-dag-process-supervisor.prompt.md`、`docs/templates/agent-dag-review-verdict.prompt.md`、`docs/templates/agent-dag-authority-surface-audit.prompt.md`(可选 authority surface verifier;authority signal 或显式 enablement 匹配时由 `dag init-hybrid` 插入)、`examples/hybrid-loop-agent-dag.json`、`docs/templates/hybrid-dag.json`。
95
95
 
96
96
  ### Supervised implementation flow(减少 operator 中途介入)
97
97
 
@@ -1,138 +0,0 @@
1
- import { mkdir } from "node:fs/promises";
2
- import path from "node:path";
3
- import { FRONTEND_REVIEW_FINDINGS_PRD_REL, readFrontendReviewFindingsPrd, } from "../workflows/dag/frontend-review-findings.js";
4
- import { locateDagRun } from "../workflows/dag/lifecycle.js";
5
- import { createTask, getTaskPaths } from "../task/runtime.js";
6
- import { importPrdDocument } from "../task/source-references.js";
7
- function parseFlagValue(rawArgs, flag) {
8
- const index = rawArgs.indexOf(flag);
9
- if (index < 0 || index + 1 >= rawArgs.length)
10
- return undefined;
11
- return rawArgs[index + 1];
12
- }
13
- export function parseDagFollowUpArgs(rawArgs) {
14
- const positional = rawArgs.filter((arg) => !arg.startsWith("-"));
15
- const parentRunId = positional[0];
16
- if (!parentRunId) {
17
- throw new Error("usage: dag follow-up <parent-run-id> [--task-id <id>] [--execute] [--profile <profile>]");
18
- }
19
- return {
20
- parentRunId,
21
- taskId: parseFlagValue(rawArgs, "--task-id"),
22
- execute: rawArgs.includes("--execute"),
23
- profile: parseFlagValue(rawArgs, "--profile"),
24
- };
25
- }
26
- export function deriveFollowUpTaskId(parentRunId) {
27
- // Deterministic, valid task id derived from the parent run id.
28
- return `${parentRunId}-followup`;
29
- }
30
- /** CLI entry: parse raw args and run the follow-up flow. */
31
- export async function runDagFollowUp(repoRoot, rawArgs) {
32
- const parsed = parseDagFollowUpArgs(rawArgs);
33
- const result = await runDagFollowUpInternal(repoRoot, parsed.parentRunId, {
34
- taskId: parsed.taskId,
35
- execute: parsed.execute,
36
- profile: parsed.profile,
37
- });
38
- console.log(JSON.stringify(result, null, 2));
39
- if (!result.ok) {
40
- process.exitCode = result.mode === "blocked" ? 2 : 1;
41
- }
42
- }
43
- export async function runDagFollowUpInternal(repoRoot, parentRunId, options = {}) {
44
- const located = await locateDagRun(repoRoot, parentRunId);
45
- if (!located) {
46
- return {
47
- ok: false,
48
- mode: "invalid",
49
- reason: `dag run not found: ${parentRunId}`,
50
- };
51
- }
52
- const prd = await readFrontendReviewFindingsPrd(located.runDir);
53
- if (!prd) {
54
- return {
55
- ok: false,
56
- mode: "invalid",
57
- reason: `no frontend review findings PRD found in run ${parentRunId} (${FRONTEND_REVIEW_FINDINGS_PRD_REL}); the review must have committed request_review_changes`,
58
- };
59
- }
60
- const taskId = options.taskId ?? deriveFollowUpTaskId(parentRunId);
61
- try {
62
- await createTask(repoRoot, taskId, `修复 review 发现(parent ${parentRunId})`);
63
- }
64
- catch (error) {
65
- return {
66
- ok: false,
67
- mode: "blocked",
68
- reason: `failed to create task ${taskId}: ${error instanceof Error ? error.message : String(error)}`,
69
- };
70
- }
71
- // Materialize the PRD draft into the task's source directory so the task
72
- // lifecycle can import it as its requirement.
73
- const prdMaterialized = path.join(getTaskPaths(repoRoot, taskId).sourceDir, "review-findings-prd.md");
74
- try {
75
- await mkdir(path.dirname(prdMaterialized), { recursive: true });
76
- await importPrdDocument({
77
- repoRoot,
78
- taskId,
79
- filePath: path.join(located.runDir, FRONTEND_REVIEW_FINDINGS_PRD_REL),
80
- name: "review-findings-prd",
81
- });
82
- }
83
- catch (error) {
84
- return {
85
- ok: false,
86
- mode: "blocked",
87
- reason: `failed to import PRD into task ${taskId}: ${error instanceof Error ? error.message : String(error)}`,
88
- };
89
- }
90
- if (!options.execute) {
91
- return {
92
- ok: true,
93
- mode: "created",
94
- taskId,
95
- prdPath: prdMaterialized,
96
- next: {
97
- kind: "advance",
98
- command: `loop-agent task advance ${taskId} --task-kind frontend-implementation --json`,
99
- },
100
- };
101
- }
102
- // Execute: advance through the frontend DAG.
103
- const { advanceTaskLifecycle } = await import("../application/task-lifecycle/advance.js");
104
- const profile = options.profile === "auto" ||
105
- options.profile === "minimal" ||
106
- options.profile === "standard" ||
107
- options.profile === "reviewed" ||
108
- options.profile === "supervised"
109
- ? options.profile
110
- : undefined;
111
- const result = await advanceTaskLifecycle({
112
- repoRoot,
113
- taskId,
114
- taskKind: "frontend-implementation",
115
- taskKindExplicit: true,
116
- ...(profile ? { profile, profileExplicit: true } : {}),
117
- observer: undefined,
118
- });
119
- const ok = result.lifecycleState === "run-succeeded" ||
120
- result.lifecycleState === "awaiting-write-set-approval";
121
- return {
122
- ok,
123
- mode: ok ? "created" : "blocked",
124
- taskId,
125
- prdPath: prdMaterialized,
126
- reason: ok
127
- ? undefined
128
- : `advance lifecycleState: ${result.lifecycleState}${result.blockers.length > 0
129
- ? `; blockers: ${result.blockers.map((b) => b.code).join(", ")}`
130
- : ""}`,
131
- next: ok
132
- ? undefined
133
- : {
134
- kind: "advance",
135
- command: `loop-agent task advance ${taskId} --task-kind frontend-implementation --json`,
136
- },
137
- };
138
- }
@@ -1,239 +0,0 @@
1
- import { access, open, readFile, stat, } from "node:fs/promises";
2
- import path from "node:path";
3
- class PiReadBudgetSoftLimitError extends Error {
4
- }
5
- class PiReadAccessDeniedError extends Error {
6
- }
7
- class PiReadBudgetGuard {
8
- budget;
9
- files = new Set();
10
- violations = [];
11
- bytes = 0;
12
- operations = 0;
13
- startedAt = Date.now();
14
- allowedReadPaths;
15
- allowedReadRoots;
16
- constructor(budget, readAccess) {
17
- this.budget = budget;
18
- this.allowedReadPaths = readAccess?.allowedReadPaths
19
- ? new Set(readAccess.allowedReadPaths.map((candidate) => path.resolve(candidate)))
20
- : undefined;
21
- this.allowedReadRoots = (readAccess?.allowedReadRoots ?? []).map((candidate) => path.resolve(candidate));
22
- }
23
- issues() {
24
- return [...this.violations];
25
- }
26
- report(message) {
27
- if (!this.violations.includes(message))
28
- this.violations.push(message);
29
- }
30
- exhaust(message) {
31
- if (this.budget.onExhaustion === "return-guidance") {
32
- throw new PiReadBudgetSoftLimitError(message);
33
- }
34
- this.report(message);
35
- throw new Error(message);
36
- }
37
- assertElapsed() {
38
- if (this.budget.maxMs === undefined)
39
- return;
40
- const elapsedMs = Date.now() - this.startedAt;
41
- if (elapsedMs > this.budget.maxMs) {
42
- const message = `read budget exhausted: ${elapsedMs}ms (budget ${this.budget.maxMs}ms)`;
43
- this.exhaust(message);
44
- }
45
- }
46
- beforeToolOperation() {
47
- this.assertElapsed();
48
- if (this.budget.maxOperations === undefined)
49
- return true;
50
- if (this.operations >= this.budget.maxOperations) {
51
- const message = `read budget exhausted: operation ${this.operations + 1} would exceed ${this.budget.maxOperations} read-only tool calls`;
52
- if (this.budget.onExhaustion === "return-guidance")
53
- return false;
54
- this.exhaust(message);
55
- }
56
- this.operations += 1;
57
- return true;
58
- }
59
- operationLimitGuidance() {
60
- return {
61
- content: [
62
- {
63
- type: "text",
64
- text: "[read limit reached: no repository data was read. Do not call discovery tools again; use injected facts, commit remaining record_* facts, then call finalize_plan exactly once.]",
65
- },
66
- ],
67
- };
68
- }
69
- readAccessGuidance() {
70
- return {
71
- content: [
72
- {
73
- type: "text",
74
- text: "[read denied: this node may read only named upstream artifacts or Scout-confirmed paths. Do not explore a new repository path; use committed facts or record an evidence gap, then finish the required terminal protocol.]",
75
- },
76
- ],
77
- };
78
- }
79
- assertReadablePath(absolutePath) {
80
- if (!this.allowedReadPaths)
81
- return;
82
- const resolved = path.resolve(absolutePath);
83
- if (this.allowedReadPaths.has(resolved))
84
- return;
85
- if (this.allowedReadRoots.some((root) => resolved === root || resolved.startsWith(`${root}${path.sep}`)))
86
- return;
87
- throw new PiReadAccessDeniedError(`read access denied: ${resolved}`);
88
- }
89
- reserveFile(absolutePath) {
90
- this.assertElapsed();
91
- if (this.files.has(absolutePath))
92
- return;
93
- if (this.files.size >= this.budget.maxFiles) {
94
- const message = `read budget exhausted: file ${absolutePath} would exceed ${this.budget.maxFiles} files`;
95
- this.exhaust(message);
96
- }
97
- this.files.add(absolutePath);
98
- }
99
- reserveBytes(bytes) {
100
- this.assertElapsed();
101
- const remaining = Math.max(0, this.budget.maxBytes - this.bytes);
102
- if (remaining === 0) {
103
- const message = `read budget exhausted: ${this.bytes} bytes (budget ${this.budget.maxBytes})`;
104
- this.exhaust(message);
105
- }
106
- const granted = Math.min(bytes, remaining);
107
- if (granted < bytes && this.budget.onExhaustion === "return-guidance") {
108
- this.exhaust(`read budget exhausted: ${bytes} requested bytes would exceed ${this.budget.maxBytes} bytes`);
109
- }
110
- this.bytes += granted;
111
- if (granted < bytes) {
112
- this.report(`read budget truncated: ${bytes} requested bytes at ${this.bytes}/${this.budget.maxBytes} bytes`);
113
- }
114
- return granted;
115
- }
116
- async readFile(absolutePath) {
117
- this.assertReadablePath(absolutePath);
118
- this.reserveFile(absolutePath);
119
- const metadata = await stat(absolutePath);
120
- const granted = this.reserveBytes(metadata.size);
121
- if (granted === metadata.size)
122
- return await readFile(absolutePath);
123
- const handle = await open(absolutePath, "r");
124
- try {
125
- const buffer = Buffer.allocUnsafe(granted);
126
- const { bytesRead } = await handle.read(buffer, 0, granted, 0);
127
- return buffer.subarray(0, bytesRead);
128
- }
129
- finally {
130
- await handle.close();
131
- }
132
- }
133
- async access(absolutePath) {
134
- this.assertReadablePath(absolutePath);
135
- this.reserveFile(absolutePath);
136
- await access(absolutePath);
137
- }
138
- limitToolResult(result) {
139
- if (!result || typeof result !== "object" || !Array.isArray(result.content)) {
140
- return result;
141
- }
142
- const content = result.content.map((item) => {
143
- if (!item || item.type !== "text" || typeof item.text !== "string") {
144
- this.report("read budget truncated: non-text tool result omitted");
145
- return {
146
- type: "text",
147
- text: "[read budget reached: non-text result omitted]",
148
- };
149
- }
150
- const granted = this.reserveBytes(Buffer.byteLength(item.text));
151
- return {
152
- ...item,
153
- text: truncateUtf8(item.text, granted),
154
- };
155
- });
156
- return { ...result, content };
157
- }
158
- }
159
- function truncateUtf8(text, maxBytes) {
160
- if (Buffer.byteLength(text) <= maxBytes)
161
- return text;
162
- const marker = "\n[read result truncated by node budget]";
163
- const markerBytes = Buffer.byteLength(marker);
164
- if (maxBytes <= markerBytes)
165
- return truncateUtf8Prefix(marker, maxBytes);
166
- const contentBudget = maxBytes - markerBytes;
167
- return `${truncateUtf8Prefix(text, contentBudget)}${marker}`;
168
- }
169
- function truncateUtf8Prefix(text, maxBytes) {
170
- let result = "";
171
- let bytes = 0;
172
- for (const codePoint of text) {
173
- const size = Buffer.byteLength(codePoint);
174
- if (bytes + size > maxBytes)
175
- break;
176
- result += codePoint;
177
- bytes += size;
178
- }
179
- return result;
180
- }
181
- function wrapTool(definition, guard, consumeResult) {
182
- return {
183
- ...definition,
184
- async execute(...args) {
185
- try {
186
- if (!guard.beforeToolOperation())
187
- return guard.operationLimitGuidance();
188
- const result = await definition.execute(...args);
189
- return consumeResult ? guard.limitToolResult(result) : result;
190
- }
191
- catch (error) {
192
- if (error instanceof PiReadBudgetSoftLimitError) {
193
- return guard.operationLimitGuidance();
194
- }
195
- if (error instanceof PiReadAccessDeniedError) {
196
- return guard.readAccessGuidance();
197
- }
198
- throw error;
199
- }
200
- },
201
- };
202
- }
203
- /**
204
- * Override Pi's built-in read-only tools with SDK definitions that meter the
205
- * content before it reaches the model. The read tool caps filesystem bytes at
206
- * the operation boundary; grep/find/ls have their returned payload clipped
207
- * before the agent receives it. This is SDK-only by design: the CLI backend
208
- * cannot inject same-name built-in overrides safely.
209
- */
210
- export async function createPiReadBudgetCustomTools(input) {
211
- const sdk = (await import("@earendil-works/pi-coding-agent"));
212
- const createReadToolDefinition = sdk.createReadToolDefinition;
213
- const createGrepToolDefinition = sdk.createGrepToolDefinition;
214
- const createFindToolDefinition = sdk.createFindToolDefinition;
215
- const createLsToolDefinition = sdk.createLsToolDefinition;
216
- if (typeof createReadToolDefinition !== "function" ||
217
- typeof createGrepToolDefinition !== "function" ||
218
- typeof createFindToolDefinition !== "function" ||
219
- typeof createLsToolDefinition !== "function") {
220
- throw new Error("pi read budget policy unavailable: SDK read/grep/find/ls tool factories missing");
221
- }
222
- const guard = new PiReadBudgetGuard(input.budget, input.readAccess);
223
- const read = wrapTool(createReadToolDefinition(input.repoRoot, {
224
- operations: {
225
- readFile: (absolutePath) => guard.readFile(absolutePath),
226
- access: (absolutePath) => guard.access(absolutePath),
227
- },
228
- }), guard, false);
229
- const grep = wrapTool(createGrepToolDefinition(input.repoRoot), guard, true);
230
- const find = wrapTool(createFindToolDefinition(input.repoRoot), guard, true);
231
- const ls = wrapTool(createLsToolDefinition(input.repoRoot), guard, true);
232
- if (read.name !== "read" ||
233
- grep.name !== "grep" ||
234
- find.name !== "find" ||
235
- ls.name !== "ls") {
236
- throw new Error("pi read budget policy unavailable: SDK tool name mismatch");
237
- }
238
- return { customTools: [read, grep, find, ls], issues: () => guard.issues() };
239
- }
@@ -1,19 +0,0 @@
1
- import { parseFrontendHumanDecisionProjection } from "../../workflows/dag/frontend-human-decision.js";
2
- /** Worker/Console persistence seam. Canonical validation and freshness remain in the workflow service. */
3
- export function createFrontendHumanDecisionAdapter(store) {
4
- return {
5
- async load(operationId) {
6
- const record = await store.get(operationId);
7
- if (!record || record.revision === undefined || !record.frontendHumanDecision)
8
- return undefined;
9
- return { revision: record.revision, projection: parseFrontendHumanDecisionProjection(record.frontendHumanDecision) };
10
- },
11
- materialize(input) {
12
- return store.materializeFrontendHumanDecision(input);
13
- },
14
- consume(input) {
15
- return store.consumeFrontendHumanDecision(input);
16
- },
17
- initializeSplit: store.initializeFrontendHumanApprovedSplit.bind(store),
18
- };
19
- }
@@ -1,20 +0,0 @@
1
- import { FrontendSplitOrchestrator, frontendSplitProjectionSchema, } from "../../workflows/dag/frontend-split-application-service.js";
2
- /** Worker/Console boundary adapter. All orchestration policy remains canonical. */
3
- export function createFrontendSplitOperationAdapter(dependencies) {
4
- const ports = {
5
- load: async (operationId) => {
6
- const record = await dependencies.store.get(operationId);
7
- return record?.frontendSplit === undefined ? undefined : frontendSplitProjectionSchema.parse(record.frontendSplit);
8
- },
9
- compareAndSwap: (input) => dependencies.store.compareAndSwapFrontendSplit(input),
10
- materialize: async (request) => {
11
- const result = await dependencies.materializer.materialize(request);
12
- return { taskId: result.taskId, operationId: result.operationId };
13
- },
14
- schedule: dependencies.schedule,
15
- auditStale: dependencies.auditStale,
16
- loadChildCloseoutFacts: (input) => dependencies.store.loadChildCloseoutFacts(input),
17
- settleAggregate: (input) => dependencies.store.settleFrontendSplitAggregate({ ...input, prepareAggregate: dependencies.prepareAggregate }),
18
- };
19
- return new FrontendSplitOrchestrator(ports);
20
- }