@tea-agent/loop-agent 0.41.1 → 0.42.0-next.10

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 (302) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +397 -5
  3. package/dist/adapters/context-transfer/optional-pi-handoff.js +31 -0
  4. package/dist/adapters/context-transfer/pi-session.js +61 -0
  5. package/dist/application/dag/generate-task-dag.js +75 -19
  6. package/dist/application/dag/run-dag.js +41 -0
  7. package/dist/application/task-lifecycle/advance.js +24 -5
  8. package/dist/application/task-lifecycle/observe.js +171 -17
  9. package/dist/application/task-lifecycle/plan-transitions.js +42 -7
  10. package/dist/application/task-lifecycle/recommendations.js +13 -2
  11. package/dist/build-stamp.json +3 -3
  12. package/dist/cli/command-definitions.js +19 -0
  13. package/dist/cli/program.js +29 -2
  14. package/dist/commands/client-recovery.js +3 -0
  15. package/dist/commands/dag-artifact.js +284 -0
  16. package/dist/commands/dag-context.js +184 -0
  17. package/dist/commands/dag-follow-up.js +138 -0
  18. package/dist/commands/dag-rerun-task.js +2 -0
  19. package/dist/commands/dag-rerun.js +206 -1
  20. package/dist/commands/init.js +27 -1
  21. package/dist/commands/task-advance.js +19 -0
  22. package/dist/executors/dag-pi-executor.js +4013 -86
  23. package/dist/executors/pi-executor.js +15 -4
  24. package/dist/executors/pi-read-budget-policy.js +239 -0
  25. package/dist/executors/pi-sdk-executor.js +3 -0
  26. package/dist/executors/shell-executor.js +978 -188
  27. package/dist/executors/shell-write-guard.js +7 -0
  28. package/dist/{worker → infrastructure}/console/app-data.js +4 -0
  29. package/dist/infrastructure/console/artifact-revision-store.js +430 -0
  30. package/dist/infrastructure/console/context-export-store.js +160 -0
  31. package/dist/infrastructure/console/dir-lock.js +132 -0
  32. package/dist/infrastructure/console/operation-store.js +417 -0
  33. package/dist/infrastructure/harness/artifact-store.js +10 -1
  34. package/dist/infrastructure/harness/atomic-write.js +12 -2
  35. package/dist/shared/context-transfer/artifact-revision.js +172 -0
  36. package/dist/shared/context-transfer.js +418 -0
  37. package/dist/shared/dag-failure-category.js +12 -0
  38. package/dist/shared/openspec-spec.js +70 -4
  39. package/dist/shared/operator/capabilities.js +21 -0
  40. package/dist/shared/operator/safe-run-summary.js +1 -0
  41. package/dist/shared/path-safety.js +93 -0
  42. package/dist/shared/preview.js +28 -4
  43. package/dist/task/config-types.js +107 -6
  44. package/dist/task/contract/adopt.js +4 -0
  45. package/dist/task/contract/import-revision.js +4 -0
  46. package/dist/task/contract/project.js +3 -0
  47. package/dist/task/contract/schema.js +2 -1
  48. package/dist/task/frontend-project-capability.js +203 -20
  49. package/dist/task/runtime.js +5 -2
  50. package/dist/task/source-prepare/build-draft.js +3 -3
  51. package/dist/task/source-prepare/fragment-inventory.js +64 -25
  52. package/dist/task/source-prepare/prepare.js +126 -21
  53. package/dist/task/source-prepare/semantic-intake.js +6 -2
  54. package/dist/task/source-references.js +22 -1
  55. package/dist/task/task-demand-routing.js +3 -0
  56. package/dist/worker/console/chat/chat-event-store.js +2 -2
  57. package/dist/worker/console/chat/model-resolver.js +7 -4
  58. package/dist/worker/console/chat/pi-runtime.js +86 -5
  59. package/dist/worker/console/chat/resource-preferences-store.js +1 -1
  60. package/dist/worker/console/chat/routes.js +136 -53
  61. package/dist/worker/console/chat/sdd-data-alignment.js +222 -0
  62. package/dist/worker/console/chat/session-catalog.js +2 -0
  63. package/dist/worker/console/chat/session-store.js +43 -1
  64. package/dist/worker/console/chat/shortcuts.js +18 -2
  65. package/dist/worker/console/chat/user-questions.js +1 -1
  66. package/dist/worker/console/console-update-runtime.js +1 -1
  67. package/dist/worker/console/context-transfer-diagnostics.js +198 -0
  68. package/dist/worker/console/dag-confirmation.js +1 -1
  69. package/dist/worker/console/dag-execution-receipt.js +1 -1
  70. package/dist/worker/console/doctor.js +1 -1
  71. package/dist/worker/console/draft-store.js +1 -1
  72. package/dist/worker/console/frontend-human-decision-adapter.js +19 -0
  73. package/dist/worker/console/frontend-split-operation-adapter.js +20 -0
  74. package/dist/worker/console/human-gate-token.js +1 -1
  75. package/dist/worker/console/index.js +6 -3
  76. package/dist/worker/console/interview/assessment.js +1 -1
  77. package/dist/worker/console/interview/session.js +1 -1
  78. package/dist/worker/console/operation-runner.js +45 -4
  79. package/dist/worker/console/operation-sse.js +1 -1
  80. package/dist/worker/console/operation-wait.js +1 -1
  81. package/dist/worker/console/operator-actions.js +273 -10
  82. package/dist/worker/console/operator-surface-health.js +1 -1
  83. package/dist/worker/console/operator-user-error.js +169 -0
  84. package/dist/worker/console/pi-plugins.js +57 -0
  85. package/dist/worker/console/pi-readiness.js +3 -2
  86. package/dist/worker/console/routes.js +637 -8
  87. package/dist/worker/console/security.js +35 -0
  88. package/dist/worker/console/server.js +29 -4
  89. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-D7oU983t.js → abnfDiagram-N423BO3Z-CcS17TBr.js} +1 -1
  90. package/dist/worker/console/static/assets/{arc-BrKSRdFS.js → arc-COptKq2S.js} +1 -1
  91. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-CiXV7L56.js → architectureDiagram-T3A2C74G-h4LKMHjP.js} +1 -1
  92. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-D_Hs_gIG.js → blockDiagram-VBNYF7ZC-COA1MOH0.js} +1 -1
  93. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-DbM-Lqqh.js → c4Diagram-5PPSVZJV-DJUf0QPm.js} +1 -1
  94. package/dist/worker/console/static/assets/channel-DdBCaOJ6.js +1 -0
  95. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-D1M8uqJw.js → chunk-2GRJ4B5K-mtWfKrUX.js} +1 -1
  96. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-4D3RFHT6.js → chunk-2Q5K7J3B-B8pXsxDQ.js} +1 -1
  97. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-CdwpY_n9.js → chunk-5RXB4S5H-ipKzByl1.js} +1 -1
  98. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-BLeLZ9PG.js → chunk-5VM5RSS4-DYi3Ald_.js} +1 -1
  99. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-CeRNEMvc.js → chunk-6Q2QTUOP-DQtGYoty.js} +1 -1
  100. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-CjkHP8Vy.js → chunk-GF5L2VYU-BU0qS2YV.js} +1 -1
  101. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-B54ZUQY-.js → chunk-JWPE2WC7-DVH9dIGE.js} +1 -1
  102. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-4bKaMVmx.js → chunk-KBJHAD2P-Dt60SmgM.js} +1 -1
  103. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-Cyjfznu_.js → chunk-RYQCIY6F-BoaUGuEY.js} +1 -1
  104. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-CDN-zGFV.js → chunk-XXDRQBXY-_WHFDTp2.js} +1 -1
  105. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DZFra1GO.js +1 -0
  106. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DZFra1GO.js +1 -0
  107. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-HxJmz411.js → cose-bilkent-JH36ORCC-BxkbTIRd.js} +1 -1
  108. package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-DtSt5K2w.js → cynefin-VYW2F7L2-Bf2UVnoG.js} +1 -1
  109. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-VtkSpRmG.js → cynefinDiagram-MW4NZA55-Bo23q1J_.js} +1 -1
  110. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-Bj4DT4du.js → dagre-VZM6K2ZE-Dd_UU49i.js} +1 -1
  111. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-Bpuk6BmP.js → diagram-7IWD3JNH-ebUa1a9y.js} +1 -1
  112. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BHYGv_yO.js → diagram-B4RE2ZJO-BucthU8r.js} +1 -1
  113. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-DEx3WwnT.js → diagram-LBJQPF4R-BgqNpAkm.js} +1 -1
  114. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-Cj0dS5e8.js → diagram-Q27KOJAE-DC4q5NGa.js} +1 -1
  115. package/dist/worker/console/static/assets/{diagram-UB23O5K3-B97h8l21.js → diagram-UB23O5K3-CBqCaMeb.js} +1 -1
  116. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-DMSFAhBd.js → ebnfDiagram-BXEA7PRR-CGtnbQ3-.js} +1 -1
  117. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-DhVOCbt6.js → erDiagram-JOGREHBK-CG3LUao5.js} +1 -1
  118. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-GlakITWL.js → flowDiagram-UKHOOZJN-D2ZVgoFS.js} +1 -1
  119. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-VxPpu9eQ.js → ganttDiagram-PKOTCBZU-DoYFZiKt.js} +1 -1
  120. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-Bs_e5DRT.js → gitGraphDiagram-DS77QQ5N-CKoP1s6j.js} +1 -1
  121. package/dist/worker/console/static/assets/index-CAZ2fC_X.css +1 -0
  122. package/dist/worker/console/static/assets/index-vbTcFnFs.js +449 -0
  123. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-BXYuU4Uw.js → infoDiagram-6WML65LV-Duofv8p2.js} +1 -1
  124. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-C34erCbU.js → ishikawaDiagram-WSZJBQD7-D2nlCkA1.js} +1 -1
  125. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-DZCAiOU3.js → journeyDiagram-NVQOT4AX-Dd4IHdus.js} +1 -1
  126. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-C9gaTdUm.js → kanban-definition-27J2QSJJ-Bi20AOdt.js} +1 -1
  127. package/dist/worker/console/static/assets/{linear-CvI0Z17U.js → linear-D59YJ9kB.js} +1 -1
  128. package/dist/worker/console/static/assets/{mermaid.core-DMMSIx7j.js → mermaid.core-Bl13LpNa.js} +5 -5
  129. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-BKKP0EO6.js → mindmap-definition-FAOFIHXS-C6DLP5eY.js} +1 -1
  130. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-C3LiFbl5.js → pegDiagram-VL7TDLO6-BjO4cy64.js} +1 -1
  131. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-Bb3Om2Dz.js → pieDiagram-7S7Q4E2Y-D7i2qZTG.js} +1 -1
  132. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-DNthMjzc.js → quadrantDiagram-CIZ2JOQS-Dx8o_h0y.js} +1 -1
  133. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-miFsr4Tv.js → railroadDiagram-AXF67PYL-B55orI_t.js} +1 -1
  134. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-yXUncmn6.js → requirementDiagram-LRYGKXZP-zWaehp6f.js} +1 -1
  135. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-DLeWKLak.js → sankeyDiagram-W5VNT64P-CcA-pjvD.js} +1 -1
  136. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-CI3he1R3.js → sequenceDiagram-SI44F4Z6-BOFbzNHI.js} +1 -1
  137. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-B7jfDkS5.js → sizeCapture-X5ZJPWSS-BjAejah1.js} +1 -1
  138. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-BmrZod7J.js → stateDiagram-OKZ733FA-DXYwxJwZ.js} +1 -1
  139. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Clg3V9t1.js +1 -0
  140. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-CDOlHVSY.js → swimlanes-SLNWSIFB-OYiOch8n.js} +2 -2
  141. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-DX1dxAAW.js +8 -0
  142. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-Cz-XX1gy.js → timeline-definition-Z64GVDOM-cZfH3nmU.js} +1 -1
  143. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-caV4cI8C.js → vennDiagram-T6HMQDX7-BDE7b3E1.js} +1 -1
  144. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-dImPlnIO.js → wardleyDiagram-T6FBY63Y-kyyGy9WJ.js} +1 -1
  145. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-CtRYVJcn.js → xychartDiagram-ELKLHX3M-CJj6VTog.js} +1 -1
  146. package/dist/worker/console/static/index.html +7 -2
  147. package/dist/worker/console/static-src/active-run-badge.js +17 -0
  148. package/dist/worker/console/static-src/app/useOperatorActions.js +3 -2
  149. package/dist/worker/console/static-src/app/useRecoveryConsole.js +5 -5
  150. package/dist/worker/console/static-src/operator-chat/input-history.js +8 -6
  151. package/dist/worker/console/static-src/operator-chat/runtime-snapshot-store.js +10 -0
  152. package/dist/worker/console/static-src/operator-chat/useChatSessions.js +258 -23
  153. package/dist/worker/console/static-src/operator-chat/useChatThread.js +112 -4
  154. package/dist/worker/console/static-src/operator-chat/useComposer.js +13 -4
  155. package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +29 -6
  156. package/dist/worker/console/static-src/operator-chat/useRuntimeSnapshot.js +8 -2
  157. package/dist/worker/console/static-src/shell/console-update-reload.js +52 -0
  158. package/dist/worker/console/static-src/shell/workspace-route.js +11 -0
  159. package/dist/worker/console/workspace-context.js +142 -2
  160. package/dist/worker/console/workspace-registry.js +2 -2
  161. package/dist/worker/continuation/worker-continuation.js +278 -0
  162. package/dist/worker/materialize/frontend-split-task-materializer.js +72 -0
  163. package/dist/worker/observe/health.js +1 -1
  164. package/dist/worker/observe/node-transparency.js +572 -0
  165. package/dist/worker/observe/routes.js +55 -1
  166. package/dist/worker/observe/static/api.js +69 -5
  167. package/dist/worker/observe/static/dag-context-reason-labels.d.ts +9 -0
  168. package/dist/worker/observe/static/dag-context-reason-labels.js +120 -0
  169. package/dist/worker/observe/static/dag-helpers.js +4 -2
  170. package/dist/worker/observe/static/dag-node-purpose.js +5 -0
  171. package/dist/worker/observe/static/inspect-workspace.js +23 -0
  172. package/dist/worker/observe/static/kpi.js +2 -2
  173. package/dist/worker/observe/static/operator-chrome.d.ts +10 -2
  174. package/dist/worker/observe/static/operator-chrome.js +37 -23
  175. package/dist/worker/observe/static/relations.js +2 -2
  176. package/dist/worker/observe/static/router.d.ts +12 -1
  177. package/dist/worker/observe/static/router.js +48 -6
  178. package/dist/worker/observe/static/run-processing.js +4 -2
  179. package/dist/worker/observe/static/shell-chrome.js +2 -2
  180. package/dist/worker/observe/static/state.js +8 -1
  181. package/dist/worker/observe/static/styles.css +1092 -86
  182. package/dist/worker/observe/static/views/dag-inspector.js +1228 -64
  183. package/dist/worker/observe/static/views/dag.js +10 -2
  184. package/dist/worker/observe/static/views/dags.js +3 -1
  185. package/dist/worker/observe/static/views/dashboard.js +14 -6
  186. package/dist/worker/observe/static/views/pool.js +7 -2
  187. package/dist/worker/observe/static/views/run.js +12 -3
  188. package/dist/worker/observe/static/views/session-timeline.js +142 -18
  189. package/dist/worker/observe/static/views/task.js +7 -2
  190. package/dist/worker/outcomes/adapters.js +19 -0
  191. package/dist/worker/outcomes/types.js +1 -0
  192. package/dist/worker/pool/attempt-lease.js +97 -66
  193. package/dist/worker/pool/begin-attempt-with-lease.js +1 -0
  194. package/dist/worker/pool/reconcile.js +46 -1
  195. package/dist/worker/pool/run-store.js +2 -0
  196. package/dist/worker/pool/state-projection.js +2 -0
  197. package/dist/worker/task-spec/workflow-routing.js +8 -3
  198. package/dist/workflows/dag/artifact-bindings.js +149 -0
  199. package/dist/workflows/dag/artifact-revision-schema-registry.js +31 -0
  200. package/dist/workflows/dag/backend-test-case-coverage-analysis.js +215 -28
  201. package/dist/workflows/dag/backend-test-markdown-workflow.js +13 -1
  202. package/dist/workflows/dag/backend-test-plan-protocol.js +106 -0
  203. package/dist/workflows/dag/backend-test-scenario-param.js +172 -25
  204. package/dist/workflows/dag/backend-test-scenario-partitions.js +62 -1
  205. package/dist/workflows/dag/backend-test-writer-completeness.js +104 -12
  206. package/dist/workflows/dag/budget-enforcement.js +10 -0
  207. package/dist/workflows/dag/context-receipt.js +305 -0
  208. package/dist/workflows/dag/context-transfer/context-bundle.js +423 -0
  209. package/dist/workflows/dag/context-transfer/operator-actions.js +61 -0
  210. package/dist/workflows/dag/context-transfer/renderers.js +93 -0
  211. package/dist/workflows/dag/contract-validator-registrations.js +1 -2
  212. package/dist/workflows/dag/dag-retry-schema.js +138 -0
  213. package/dist/workflows/dag/frontend-closeout.js +221 -0
  214. package/dist/workflows/dag/frontend-design-policy.js +400 -0
  215. package/dist/workflows/dag/frontend-human-decision.js +182 -0
  216. package/dist/workflows/dag/frontend-implementation-contract.js +1237 -192
  217. package/dist/workflows/dag/frontend-plan-render.js +2 -1
  218. package/dist/workflows/dag/frontend-prewrite-gate.js +256 -350
  219. package/dist/workflows/dag/frontend-provider-capability-matrix.js +159 -0
  220. package/dist/workflows/dag/frontend-recovery-capsule.js +455 -0
  221. package/dist/workflows/dag/frontend-recovery-controller.js +226 -0
  222. package/dist/workflows/dag/frontend-recovery-lineage.js +178 -0
  223. package/dist/workflows/dag/frontend-recovery-plan.js +21 -10
  224. package/dist/workflows/dag/frontend-recovery-run.js +166 -34
  225. package/dist/workflows/dag/frontend-repair.js +1 -432
  226. package/dist/workflows/dag/frontend-review-context.js +261 -15
  227. package/dist/workflows/dag/frontend-review-findings.js +270 -0
  228. package/dist/workflows/dag/frontend-shadow-dual-write.js +941 -0
  229. package/dist/workflows/dag/frontend-shape-capsule-store.js +191 -0
  230. package/dist/workflows/dag/frontend-shape-facts.js +419 -0
  231. package/dist/workflows/dag/frontend-shape.js +435 -0
  232. package/dist/workflows/dag/frontend-source-fidelity-ledger.js +108 -0
  233. package/dist/workflows/dag/frontend-split-application-service.js +203 -0
  234. package/dist/workflows/dag/frontend-split-orchestrator.js +899 -0
  235. package/dist/workflows/dag/frontend-typed-event-store.js +452 -0
  236. package/dist/workflows/dag/frontend-typed-event-transaction.js +180 -0
  237. package/dist/workflows/dag/frontend-verification-trace.js +252 -25
  238. package/dist/workflows/dag/frontend-worktree-diff.js +250 -17
  239. package/dist/workflows/dag/frontend-writer-admission.js +319 -0
  240. package/dist/workflows/dag/frontend-writer-rollback.js +32 -0
  241. package/dist/workflows/dag/frontend-writer-status.js +256 -0
  242. package/dist/workflows/dag/init-hybrid.js +1174 -562
  243. package/dist/workflows/dag/interrupt-request.js +7 -0
  244. package/dist/workflows/dag/node-execution.js +940 -31
  245. package/dist/workflows/dag/path-safety.js +1 -0
  246. package/dist/workflows/dag/prompt.js +99 -7
  247. package/dist/workflows/dag/recovery-lease.js +170 -0
  248. package/dist/workflows/dag/report.js +37 -1
  249. package/dist/workflows/dag/rerun-feedback.js +315 -1
  250. package/dist/workflows/dag/rerun-plan.js +568 -3
  251. package/dist/workflows/dag/rerun-run.js +642 -18
  252. package/dist/workflows/dag/rerun-task.js +251 -13
  253. package/dist/workflows/dag/retry-policy.js +219 -104
  254. package/dist/workflows/dag/runner.js +596 -121
  255. package/dist/workflows/dag/scheduler.js +133 -20
  256. package/dist/workflows/dag/skill-snapshot.js +17 -0
  257. package/dist/workflows/dag/types.js +426 -22
  258. package/dist/workflows/dag/validate.js +28 -12
  259. package/docs/architecture/runtime-boundaries.md +6 -6
  260. package/docs/architecture/worker-and-feature.md +1 -1
  261. package/docs/examples/README.md +5 -0
  262. package/docs/init-surface.manifest.json +30 -12
  263. package/docs/skills/vetted-skill-registry.md +4 -2
  264. package/docs/templates/README.md +2 -0
  265. package/docs/templates/agent-dag-report.schema.json +8 -2
  266. package/docs/templates/agent-dag.schema.json +33 -1
  267. package/docs/templates/backend-test-dag.json +23 -20
  268. package/docs/templates/frontend-implementation-contract.schema.json +4 -1
  269. package/docs/templates/frontend-implementation-dag.json +89 -0
  270. package/docs/templates/product-line/task.yaml +1 -1
  271. package/docs/templates/spec-registry.schema.json +45 -0
  272. package/harness.json +1 -1
  273. package/package.json +6 -3
  274. package/skills/frontend-bounded-implement/SKILL.md +15 -14
  275. package/skills/frontend-bounded-implement/references/code-standards.md +19 -0
  276. package/skills/frontend-contract/SKILL.md +23 -0
  277. package/skills/frontend-contract/references/contract-protocol.md +34 -0
  278. package/skills/frontend-design-review/SKILL.md +22 -41
  279. package/skills/frontend-plan/SKILL.md +26 -0
  280. package/skills/frontend-plan/references/decision-contract.md +37 -0
  281. package/skills/frontend-plan/references/design-decisions.md +17 -0
  282. package/skills/frontend-review/SKILL.md +20 -15
  283. package/skills/frontend-review/references/review-findings.md +6 -7
  284. package/skills/frontend-scout/SKILL.md +25 -0
  285. package/skills/frontend-scout/references/design-evidence.md +16 -0
  286. package/skills/frontend-scout/references/scout-evidence.md +23 -0
  287. package/skills/frontend-verification/SKILL.md +1 -1
  288. package/skills/loop-agent/references/command-reference.md +7 -0
  289. package/skills/loop-agent/references/hybrid-dag.md +2 -2
  290. package/dist/worker/console/operation-store.js +0 -169
  291. package/dist/worker/console/static/assets/channel-D1xajGpe.js +0 -1
  292. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-BmuGTfRr.js +0 -1
  293. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-BmuGTfRr.js +0 -1
  294. package/dist/worker/console/static/assets/index-BLzcAykx.js +0 -451
  295. package/dist/worker/console/static/assets/index-Cs9JUSPs.css +0 -1
  296. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-D9ykKEWP.js +0 -1
  297. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BvPOXALT.js +0 -8
  298. package/skills/frontend-implementation/SKILL.md +0 -52
  299. package/skills/frontend-implementation/references/code-standards.md +0 -33
  300. package/skills/frontend-implementation/references/design-spec.md +0 -56
  301. package/skills/frontend-implementation/references/node-contracts.md +0 -31
  302. /package/dist/{worker → infrastructure}/console/repo-fingerprint.js +0 -0
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Probe only. pi-handoff is an interactive Pi extension, not a renderer API,
3
+ * so Context Bundle generation never imports or executes it. This isolation
4
+ * keeps the authoritative export path deterministic when the optional package
5
+ * is absent, broken, or changes its private Pi dependencies.
6
+ */
7
+ export async function probeOptionalPiHandoff(input = {}) {
8
+ const resolve = input.resolve ?? (async (specifier) => import.meta.resolve(specifier));
9
+ try {
10
+ await resolve("@nicknisi/pi-handoff");
11
+ return {
12
+ schemaVersion: 1,
13
+ packageName: "@nicknisi/pi-handoff",
14
+ status: "available-interactive-only",
15
+ coreBundleUnaffected: true,
16
+ detail: "extension can be used after Pi import, but does not expose a Context Bundle renderer API",
17
+ };
18
+ }
19
+ catch (error) {
20
+ const message = error instanceof Error ? error.message : String(error);
21
+ return {
22
+ schemaVersion: 1,
23
+ packageName: "@nicknisi/pi-handoff",
24
+ status: /cannot find|not found|resolve/i.test(message)
25
+ ? "not-installed"
26
+ : "incompatible",
27
+ coreBundleUnaffected: true,
28
+ detail: "optional extension unavailable; use generic or Pi session adapter",
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,61 @@
1
+ import { createHash } from "node:crypto";
2
+ function sha256(value) {
3
+ return createHash("sha256").update(value, "utf8").digest("hex");
4
+ }
5
+ export function evaluatePiSessionCapability(receipt) {
6
+ const limitations = [
7
+ "Pi JSONL import does not restore the captured system prompt as a system message",
8
+ "provider authentication and external tool state are intentionally not exported",
9
+ ];
10
+ if (receipt.runtime.executor !== "pi") {
11
+ return {
12
+ schemaVersion: 1,
13
+ compatible: false,
14
+ reproducibility: "semantic-handoff",
15
+ reasonCodes: ["PI_EXECUTOR_NOT_CAPTURED"],
16
+ limitations,
17
+ };
18
+ }
19
+ return {
20
+ schemaVersion: 1,
21
+ compatible: true,
22
+ reproducibility: "semantic-handoff",
23
+ reasonCodes: ["PI_IMPORT_SEMANTIC_ONLY"],
24
+ limitations,
25
+ };
26
+ }
27
+ /**
28
+ * Build a minimal Pi v3 JSONL session that can be opened with `/import`.
29
+ * It deliberately references the sibling bundle materials instead of
30
+ * duplicating a potentially large prompt inside the session file.
31
+ */
32
+ export function renderPiSessionJsonl(input) {
33
+ const capability = evaluatePiSessionCapability(input.receipt);
34
+ const seed = `${input.runId}:${input.nodeId}:${input.attempt}:${input.receipt.contextDigest}`;
35
+ const sessionId = sha256(`session:${seed}`).slice(0, 32);
36
+ const messageId = sha256(`message:${seed}`).slice(0, 16);
37
+ const timestamp = input.receipt.identity.capturedAt;
38
+ const header = {
39
+ type: "session",
40
+ version: 3,
41
+ id: sessionId,
42
+ timestamp,
43
+ cwd: ".",
44
+ };
45
+ const message = {
46
+ type: "message",
47
+ id: messageId,
48
+ parentId: null,
49
+ timestamp,
50
+ message: {
51
+ role: "user",
52
+ content: [
53
+ "This session was imported from a loop-agent Context Bundle.",
54
+ "Read and follow context/system-prompt.md, then continue the request in context/user-message.md.",
55
+ `Context digest: ${input.receipt.contextDigest}`,
56
+ `Reproducibility: ${capability.reproducibility}. ${capability.limitations.join("; ")}.`,
57
+ ].join("\n\n"),
58
+ },
59
+ };
60
+ return `${JSON.stringify(header)}\n${JSON.stringify(message)}\n`;
61
+ }
@@ -13,6 +13,8 @@ import { runDagUseCase } from "./run-dag.js";
13
13
  import { getTaskPaths, loadTaskConfig } from "../../task/runtime.js";
14
14
  import { writeTaskConfig } from "../../infrastructure/harness/task-store.js";
15
15
  import { runFrontendPreflight } from "../../task/frontend-preflight.js";
16
+ import { discoverFrontendProjectCapability } from "../../task/frontend-project-capability.js";
17
+ import { classifyTaskDemand } from "../../task/task-demand-routing.js";
16
18
  import { observeTaskContract } from "../../task/contract/observe.js";
17
19
  import { adoptTaskContract } from "../../task/contract/adopt.js";
18
20
  const PLACEHOLDER_WRITESET_MARKER = "REPLACE/WITH";
@@ -88,6 +90,63 @@ function buildBasicValidationLevel(outputPath) {
88
90
  note: "Internal generation validation is basic only; standalone strict governance validation must be confirmed separately.",
89
91
  };
90
92
  }
93
+ async function promoteAutomaticFrontendTaskKind(input) {
94
+ if (input.taskConfig.taskKind !== "standard" ||
95
+ input.taskConfig.taskKindExplicit) {
96
+ return false;
97
+ }
98
+ let requirementMarkdown = "";
99
+ try {
100
+ requirementMarkdown = await readFile(path.join(getTaskPaths(input.repoRoot, input.taskId).sourceDir, "需求.md"), "utf8");
101
+ }
102
+ catch {
103
+ return false;
104
+ }
105
+ if (!requirementMarkdown.trim())
106
+ return false;
107
+ let frontendProject;
108
+ try {
109
+ frontendProject = await discoverFrontendProjectCapability(input.repoRoot);
110
+ }
111
+ catch {
112
+ // The existing standard route remains the safe fallback when capability
113
+ // discovery is unavailable.
114
+ }
115
+ const classification = classifyTaskDemand({
116
+ title: input.taskConfig.title,
117
+ requirementMarkdown,
118
+ allowedPaths: input.taskConfig.allowedPaths,
119
+ frontendProject: frontendProject
120
+ ? {
121
+ framework: frontendProject.framework,
122
+ evidencePaths: frontendProject.evidencePaths,
123
+ }
124
+ : undefined,
125
+ });
126
+ if (classification.kind !== "frontend")
127
+ return false;
128
+ await writeTaskConfig(input.repoRoot, input.taskId, {
129
+ ...input.taskConfig,
130
+ taskKind: "frontend-implementation",
131
+ dagFallbackReason: "Automatically classified as a high-confidence frontend implementation task.",
132
+ });
133
+ const state = await observeTaskContract({
134
+ repoRoot: input.repoRoot,
135
+ taskId: input.taskId,
136
+ });
137
+ if (!state.ref || !state.observedCanonicalHash) {
138
+ throw new Error("automatic frontend routing could not reconcile the managed Task Contract");
139
+ }
140
+ await adoptTaskContract({
141
+ repoRoot: input.repoRoot,
142
+ taskId: input.taskId,
143
+ expectedRevision: state.ref.revision,
144
+ expectedObservedHash: state.observedCanonicalHash,
145
+ requestId: `automatic-frontend-route-${input.taskId}-${randomUUID()}`,
146
+ requestPayloadSha256: randomUUID().replaceAll("-", "").padEnd(64, "0"),
147
+ });
148
+ return true;
149
+ }
91
150
  function isBroadWriteSetEntryForPacket(entry) {
92
151
  const normalized = entry.trim().replace(/\\/g, "/").replace(/^\.\//, "");
93
152
  if (!normalized || normalized === "." || normalized === "./")
@@ -280,12 +339,25 @@ export async function generateTaskDagUseCase(input) {
280
339
  requestPayloadSha256: randomUUID().replaceAll("-", "").padEnd(64, "0"),
281
340
  });
282
341
  }
283
- const candidateResult = await initHybridDagFromTask(repoRoot, parsed.taskId, {
342
+ const routingTaskConfig = await loadTaskConfig(repoRoot, parsed.taskId);
343
+ let initialTemplate = routingTaskConfig.taskKind === "frontend-implementation"
344
+ ? "frontend-implementation"
345
+ : "standard-dag";
346
+ if (initialTemplate === "standard-dag") {
347
+ const promoted = await promoteAutomaticFrontendTaskKind({
348
+ repoRoot,
349
+ taskId: parsed.taskId,
350
+ taskConfig: routingTaskConfig,
351
+ });
352
+ if (promoted)
353
+ initialTemplate = "frontend-implementation";
354
+ }
355
+ let candidateResult = await initHybridDagFromTask(repoRoot, parsed.taskId, {
284
356
  outputPath: parsed.outputPath,
285
- template: "standard-dag",
357
+ template: initialTemplate,
286
358
  rerunFeedback: parsed.rerunFeedback,
287
359
  });
288
- const candidateValidateSummary = await validateDagUseCase(buildValidateInput(repoRoot, candidateResult.outputPath, parsed));
360
+ let candidateValidateSummary = await validateDagUseCase(buildValidateInput(repoRoot, candidateResult.outputPath, parsed));
289
361
  const profileRouting = await resolveProfileRouting(repoRoot, parsed, candidateValidateSummary.governanceProfile ?? {
290
362
  profile: "standard",
291
363
  process: [],
@@ -308,22 +380,6 @@ export async function generateTaskDagUseCase(input) {
308
380
  profileRouting.selectedByProfile = parsed.profile;
309
381
  }
310
382
  }
311
- // Persist the automatic business workflow route while preserving the
312
- // governance profile as a separate routing dimension.
313
- if (hasAutomaticTaskSourceRoute &&
314
- candidateResult.template === "frontend-implementation") {
315
- const taskConfig = await loadTaskConfig(repoRoot, parsed.taskId);
316
- // Human-explicit taskKind (incl. explicit standard) is a hard contract:
317
- // never rewrite task.json taskKind via semantic classification.
318
- if (!taskConfig.taskKindExplicit &&
319
- (!taskConfig.taskKind || taskConfig.taskKind === "standard")) {
320
- await writeTaskConfig(repoRoot, parsed.taskId, {
321
- ...taskConfig,
322
- taskKind: "frontend-implementation",
323
- dagFallbackReason: "Automatically classified as a high-confidence frontend implementation task.",
324
- });
325
- }
326
- }
327
383
  const initResult = profileRouting.selectedTemplate === candidateResult.template
328
384
  ? candidateResult
329
385
  : await initHybridDagFromTask(repoRoot, parsed.taskId, {
@@ -1,3 +1,4 @@
1
+ import path from "node:path";
1
2
  import { createDagEventObserver } from "../../workflows/dag/event-observer.js";
2
3
  import { composeDagRunObservers } from "../../workflows/dag/observer-compose.js";
3
4
  import { createDagCanvasObserver, resolveCanvasPath, } from "../../workflows/dag/canvas-observer.js";
@@ -28,6 +29,41 @@ function buildRunDagNextSteps(runId) {
28
29
  `loop-agent dag report --run-id ${runId} --markdown # advanced forensic`,
29
30
  ];
30
31
  }
32
+ /** Shared production recovery seam for fresh runs and recovery continuations. */
33
+ export async function buildDefaultFrontendRecoveryDeps(repoRoot) {
34
+ // Keep the application layer free of a static worker→application cycle. The
35
+ // recovery controller is only needed after a frontend terminal failure.
36
+ const [{ openConsoleAppData }, { OperationStore }, { createOperationEventStore }, { LoopAgentClient }, { resolveSiblingLoopAgentBin },] = await Promise.all([
37
+ import("../../infrastructure/console/app-data.js"),
38
+ import("../../infrastructure/console/operation-store.js"),
39
+ import("../../worker/console/operation-sse.js"),
40
+ import("../../worker/loop-agent/loop-agent-client.js"),
41
+ import("../../worker/console/sibling-controller.js"),
42
+ ]);
43
+ const appData = openConsoleAppData({ repoRoot });
44
+ const store = new OperationStore(appData);
45
+ const events = createOperationEventStore({
46
+ persistenceDir: path.join(appData.operations, "events"),
47
+ });
48
+ const client = new LoopAgentClient({
49
+ loopAgentBin: resolveSiblingLoopAgentBin(),
50
+ artifactRoot: path.join(appData.root, "client-artifacts", appData.fingerprint),
51
+ resolveIdentity: true,
52
+ });
53
+ return {
54
+ store,
55
+ operationRunnerDeps: {
56
+ store,
57
+ events,
58
+ client,
59
+ repoRoot,
60
+ env: {
61
+ ...process.env,
62
+ LOOP_CONSOLE_APP_DATA: appData.root,
63
+ },
64
+ },
65
+ };
66
+ }
31
67
  export async function runDagUseCase(input) {
32
68
  const spec = await loadDagSpecFromFile(input.dagPath);
33
69
  assertValidDagSpec(spec);
@@ -80,6 +116,10 @@ export async function runDagUseCase(input) {
80
116
  ...(canvasError ? { canvasError } : {}),
81
117
  };
82
118
  }
119
+ const recovery = input.recovery ??
120
+ (!input.initOnly && spec.tasks.some((task) => task.id === "frontend-implement-pi")
121
+ ? await buildDefaultFrontendRecoveryDeps(input.cwd)
122
+ : undefined);
83
123
  const summary = await runDag(spec, {
84
124
  cwd: input.cwd,
85
125
  initOnly: input.initOnly,
@@ -90,6 +130,7 @@ export async function runDagUseCase(input) {
90
130
  ...(input.workerAssociation
91
131
  ? { workerAssociation: input.workerAssociation }
92
132
  : {}),
133
+ ...(recovery ? { recovery } : {}),
93
134
  });
94
135
  const canvasError = await flushCanvasSafely(canvas);
95
136
  if (resolvedCanvasPath) {
@@ -260,6 +260,10 @@ async function monitorRun(input) {
260
260
  failureCategory: "monitor-timeout",
261
261
  });
262
262
  }
263
+ function isStartupGateEligible(snapshot) {
264
+ const status = snapshot.source?.sourceFidelityStartup?.status;
265
+ return status === undefined || status === "complete" || status === "not-applicable";
266
+ }
263
267
  function nextMutationAction(actions) {
264
268
  for (const action of actions) {
265
269
  if (action.type !== "stop")
@@ -379,7 +383,10 @@ export async function advanceTaskLifecycle(input) {
379
383
  };
380
384
  }
381
385
  const token = parseGateToken(input.rejectGateToken);
382
- const currentGate = snapshot.gate ?? (await buildCurrentGate(input.repoRoot, input.taskId));
386
+ const currentGate = snapshot.gate ??
387
+ (isStartupGateEligible(snapshot)
388
+ ? await buildCurrentGate(input.repoRoot, input.taskId)
389
+ : null);
383
390
  if (!currentGate || !gateMatches(currentGate, token)) {
384
391
  return {
385
392
  taskId: input.taskId,
@@ -443,11 +450,12 @@ export async function advanceTaskLifecycle(input) {
443
450
  dryRun,
444
451
  skipFinalize: Boolean(input.skipFinalize),
445
452
  forcePrepareContract: Boolean(input.fromDraftPath) && !preparedContractThisCall,
453
+ startupRepairAttempted: preparedContractThisCall,
446
454
  });
447
455
  if (dryRun) {
448
456
  const plan = planOnce(snapshot);
449
457
  const plannedGate = snapshot.gate ??
450
- (snapshot.dagDraft?.exists
458
+ (isStartupGateEligible(snapshot) && snapshot.dagDraft?.exists
451
459
  ? await buildCurrentGate(input.repoRoot, input.taskId)
452
460
  : null);
453
461
  return {
@@ -499,7 +507,10 @@ export async function advanceTaskLifecycle(input) {
499
507
  }
500
508
  if (action.type === "create-task") {
501
509
  if (!snapshot.exists) {
502
- await createTask(input.repoRoot, input.taskId, input.title);
510
+ await createTask(input.repoRoot, input.taskId, input.title, {
511
+ taskKind: input.taskKind,
512
+ taskKindExplicit: input.taskKindExplicit,
513
+ });
503
514
  record = appendTransition(record, "task-created");
504
515
  completed.push("task-created");
505
516
  await saveLifecycleRecord(input.repoRoot, record);
@@ -586,6 +597,10 @@ export async function advanceTaskLifecycle(input) {
586
597
  continue;
587
598
  }
588
599
  if (action.type === "prepare-contract") {
600
+ const startupStatus = snapshot.source?.sourceFidelityStartup?.status;
601
+ const startupRepairAction = startupStatus === "missing" ||
602
+ startupStatus === "invalid" ||
603
+ startupStatus === "coverage-incomplete";
589
604
  // 生产 source fidelity Pi 接线(AC-PROD-001/005):仅 frontend-implementation
590
605
  // 任务注入 reconcile executor + 独立 reviewer;ineligible 返回 undefined 不接线。
591
606
  // 主路径与 semantic-intake retry 路径共用同一接线,保证任意一条生产路径都实际
@@ -731,7 +746,9 @@ export async function advanceTaskLifecycle(input) {
731
746
  message: "structured requirement draft via semantic intake; projected managed source",
732
747
  });
733
748
  preparedContractThisCall = true;
734
- if (refreshManagedContractThisCall || input.fromDraftPath) {
749
+ if (startupRepairAction ||
750
+ refreshManagedContractThisCall ||
751
+ input.fromDraftPath) {
735
752
  refreshManagedContractThisCall = false;
736
753
  regenerateDagThisCall = true;
737
754
  }
@@ -825,7 +842,9 @@ export async function advanceTaskLifecycle(input) {
825
842
  break;
826
843
  }
827
844
  preparedContractThisCall = true;
828
- if (refreshManagedContractThisCall || input.fromDraftPath) {
845
+ if (startupRepairAction ||
846
+ refreshManagedContractThisCall ||
847
+ input.fromDraftPath) {
829
848
  // The old DAG and gate were bound to the pre-mutation contract.
830
849
  refreshManagedContractThisCall = false;
831
850
  regenerateDagThisCall = true;
@@ -1,9 +1,11 @@
1
- import { access, readFile } from "node:fs/promises";
1
+ import { access, readFile, readdir } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { getTaskDir, getTaskPaths, getTaskStatus, loadTaskConfig, } from "../../task/runtime.js";
4
4
  import { logicalRevisionForState, observeTaskContractState, } from "../../task/contract/index.js";
5
5
  import { assessDagRunLiveness, listAllDagRunEntries, readDagRunSpec, readDagRunState, } from "../../workflows/dag/lifecycle.js";
6
6
  import { resolveRunningControllerIdentity } from "../../shared/package-metadata.js";
7
+ import { parseLedgerJson, validateRequirementLedger, } from "../../task/source-prepare/ledger.js";
8
+ import { REQUIREMENT_LEDGER_FILE_NAME } from "../../task/source-prepare/types.js";
7
9
  import { loadLifecycleRecord } from "./record.js";
8
10
  import { buildGateBinding, buildWriteSetGate, buildWriteSetGateDelta, controllerIdentityAnchor, hashCanonicalPayload, normalizeWriteSet, sha256Hex, } from "./gates.js";
9
11
  async function exists(filePath) {
@@ -47,6 +49,140 @@ async function taskExists(repoRoot, taskId) {
47
49
  const paths = getTaskPaths(repoRoot, taskId);
48
50
  return exists(paths.taskConfigPath);
49
51
  }
52
+ async function assessReferenceEvidence(referencesDir) {
53
+ try {
54
+ const entries = await readdir(referencesDir);
55
+ const importedPrdCount = entries.filter((name) => name.endsWith(".md")).length;
56
+ return importedPrdCount > 0
57
+ ? { status: "present", importedPrdCount }
58
+ : { status: "absent-or-empty", importedPrdCount: 0 };
59
+ }
60
+ catch (error) {
61
+ if (error &&
62
+ typeof error === "object" &&
63
+ "code" in error &&
64
+ error.code === "ENOENT") {
65
+ return { status: "absent-or-empty", importedPrdCount: 0 };
66
+ }
67
+ return {
68
+ status: "unknown",
69
+ importedPrdCount: 0,
70
+ error: error instanceof Error ? error.message : String(error),
71
+ };
72
+ }
73
+ }
74
+ function hasLedgerStructure(value) {
75
+ if (!value || typeof value !== "object")
76
+ return false;
77
+ const ledger = value;
78
+ return (typeof ledger.taskId === "string" &&
79
+ typeof ledger.inputDigest === "string" &&
80
+ typeof ledger.requirementSha256 === "string" &&
81
+ Array.isArray(ledger.sourcePaths) &&
82
+ Array.isArray(ledger.fragments) &&
83
+ Array.isArray(ledger.canonicalRequirements) &&
84
+ Boolean(ledger.stats && typeof ledger.stats === "object") &&
85
+ Array.isArray(ledger.unresolved) &&
86
+ Array.isArray(ledger.conflicts) &&
87
+ Array.isArray(ledger.sourceResolutions) &&
88
+ typeof ledger.schemaReconcilerVersion === "string" &&
89
+ typeof ledger.builtAt === "string");
90
+ }
91
+ async function assessSourceFidelityStartup(input) {
92
+ if (!input.applicable) {
93
+ return {
94
+ status: "not-applicable",
95
+ ledgerPath: input.ledgerPath,
96
+ diagnostics: [],
97
+ };
98
+ }
99
+ if (input.referenceEvidenceError) {
100
+ return {
101
+ status: "invalid",
102
+ ledgerPath: input.ledgerPath,
103
+ diagnostics: [
104
+ {
105
+ code: "SOURCE_FIDELITY_LEDGER_STALE",
106
+ message: `imported PRD reference evidence is unreadable: ${input.referenceEvidenceError}`,
107
+ },
108
+ ],
109
+ };
110
+ }
111
+ let raw;
112
+ try {
113
+ raw = await readFile(input.ledgerPath, "utf-8");
114
+ }
115
+ catch (error) {
116
+ const missing = !(await exists(input.ledgerPath));
117
+ return {
118
+ status: missing ? "missing" : "invalid",
119
+ ledgerPath: input.ledgerPath,
120
+ diagnostics: [
121
+ {
122
+ code: missing
123
+ ? "SOURCE_FIDELITY_LEDGER_MISSING"
124
+ : "SOURCE_FIDELITY_LEDGER_STALE",
125
+ message: missing
126
+ ? "managed frontend task has no requirement-ledger.json"
127
+ : `requirement ledger is unreadable: ${error instanceof Error ? error.message : String(error)}`,
128
+ },
129
+ ],
130
+ };
131
+ }
132
+ try {
133
+ const ledger = parseLedgerJson(raw);
134
+ if (!hasLedgerStructure(ledger)) {
135
+ return {
136
+ status: "invalid",
137
+ ledgerPath: input.ledgerPath,
138
+ diagnostics: [
139
+ {
140
+ code: "SOURCE_FIDELITY_LEDGER_STALE",
141
+ message: "requirement ledger is missing required structural fields",
142
+ },
143
+ ],
144
+ };
145
+ }
146
+ const nonDecisionErrors = validateRequirementLedger(ledger, {
147
+ allowedUnresolved: true,
148
+ allowedConflicts: true,
149
+ });
150
+ if (nonDecisionErrors.length > 0) {
151
+ const coverageCodes = new Set([
152
+ "SOURCE_FIDELITY_HIGH_RISK_UNCOVERED",
153
+ "SOURCE_FIDELITY_REQUIREMENT_NOT_COVERED",
154
+ ]);
155
+ return {
156
+ status: nonDecisionErrors.every((error) => coverageCodes.has(error.code))
157
+ ? "coverage-incomplete"
158
+ : "invalid",
159
+ ledgerPath: input.ledgerPath,
160
+ diagnostics: nonDecisionErrors,
161
+ };
162
+ }
163
+ const decisionErrors = validateRequirementLedger(ledger);
164
+ if (decisionErrors.length > 0) {
165
+ return {
166
+ status: "human-decision-blocked",
167
+ ledgerPath: input.ledgerPath,
168
+ diagnostics: decisionErrors,
169
+ };
170
+ }
171
+ return { status: "complete", ledgerPath: input.ledgerPath, diagnostics: [] };
172
+ }
173
+ catch (error) {
174
+ return {
175
+ status: "invalid",
176
+ ledgerPath: input.ledgerPath,
177
+ diagnostics: [
178
+ {
179
+ code: "SOURCE_FIDELITY_LEDGER_STALE",
180
+ message: error instanceof Error ? error.message : String(error),
181
+ },
182
+ ],
183
+ };
184
+ }
185
+ }
50
186
  /**
51
187
  * Explicit Task↔DAG association only:
52
188
  * - lifecycle.json recorded runAssociations
@@ -182,10 +318,12 @@ export async function observeTaskLifecycle(repoRoot, taskId) {
182
318
  const record = await loadLifecycleRecord(repoRoot, taskId);
183
319
  const contractState = await observeTaskContractState(repoRoot, taskId);
184
320
  let title;
321
+ let taskKind;
185
322
  let taskConfigAllowed = [];
186
323
  try {
187
324
  const config = await loadTaskConfig(repoRoot, taskId);
188
325
  title = config.title;
326
+ taskKind = config.taskKind;
189
327
  taskConfigAllowed = config.allowedPaths ?? [];
190
328
  }
191
329
  catch {
@@ -199,19 +337,22 @@ export async function observeTaskLifecycle(repoRoot, taskId) {
199
337
  ...(requirementReady ? [] : [requirementPath]),
200
338
  ...(constraintsReady ? [] : [constraintsPath]),
201
339
  ];
202
- let importedPrdCount = 0;
340
+ const contractManaged = contractState.effectiveStatus === "managed" || Boolean(contractState.ref);
203
341
  const referencesDir = path.join(paths.sourceDir, "references");
204
- if (await exists(referencesDir)) {
205
- // Count is best-effort; absence is fine.
206
- try {
207
- const { readdir } = await import("node:fs/promises");
208
- const entries = await readdir(referencesDir);
209
- importedPrdCount = entries.filter((name) => name.endsWith(".md")).length;
210
- }
211
- catch {
212
- importedPrdCount = 0;
213
- }
214
- }
342
+ const referenceEvidence = await assessReferenceEvidence(referencesDir);
343
+ const importedPrdCount = referenceEvidence.importedPrdCount;
344
+ const ledgerPath = path.join(paths.sourceDir, REQUIREMENT_LEDGER_FILE_NAME);
345
+ const sourceFidelityStartup = await assessSourceFidelityStartup({
346
+ ledgerPath,
347
+ applicable: contractManaged &&
348
+ taskKind === "frontend-implementation" &&
349
+ referenceEvidence.status !== "absent-or-empty",
350
+ referenceEvidenceError: referenceEvidence.status === "unknown"
351
+ ? referenceEvidence.error
352
+ : undefined,
353
+ });
354
+ const sourceFidelityReady = sourceFidelityStartup.status === "complete" ||
355
+ sourceFidelityStartup.status === "not-applicable";
215
356
  const dagDraftPath = paths.dagDraftPath;
216
357
  const dagDraftExists = await exists(dagDraftPath);
217
358
  let specHash = null;
@@ -285,7 +426,11 @@ export async function observeTaskLifecycle(repoRoot, taskId) {
285
426
  // Open gate only when draft is strict-validated and the current binding is
286
427
  // not already approved/rejected. Rejected same-digest gates stay closed
287
428
  // until contract/source/DAG/writeSet/controller binding changes.
288
- const gate = gateBound && strictValidated && !approvedCurrent && !rejectedCurrent
429
+ const gate = gateBound &&
430
+ strictValidated &&
431
+ sourceFidelityReady &&
432
+ !approvedCurrent &&
433
+ !rejectedCurrent
289
434
  ? buildWriteSetGate({ taskId, bound: gateBound, delta: gateDelta })
290
435
  : null;
291
436
  const gateOpen = Boolean(gate);
@@ -310,11 +455,10 @@ export async function observeTaskLifecycle(repoRoot, taskId) {
310
455
  activeRun.failureCategory === "needs-attention" ||
311
456
  activeRun.failureCategory === "suspected-stall" ||
312
457
  activeRun.failureCategory === "monitor-timeout"));
313
- const contractManaged = contractState.effectiveStatus === "managed" || Boolean(contractState.ref);
314
458
  const lifecycleState = deriveLifecycleState({
315
459
  exists: true,
316
460
  contractManaged,
317
- sourceReady: requirementReady,
461
+ sourceReady: requirementReady && sourceFidelityReady,
318
462
  dagValidated: strictValidated,
319
463
  gateOpen: Boolean(gate),
320
464
  activeRun,
@@ -352,6 +496,7 @@ export async function observeTaskLifecycle(repoRoot, taskId) {
352
496
  constraintsReady,
353
497
  importedPrdCount,
354
498
  missing,
499
+ sourceFidelityStartup,
355
500
  },
356
501
  dagDraft: {
357
502
  path: dagDraftPath,
@@ -375,7 +520,16 @@ export async function observeTaskLifecycle(repoRoot, taskId) {
375
520
  exists: closeoutExists || Boolean(record?.closeout),
376
521
  },
377
522
  completedTransitions: record?.completedTransitions ?? [],
378
- blockers: [],
523
+ blockers: sourceFidelityReady
524
+ ? []
525
+ : sourceFidelityStartup.diagnostics.map((diagnostic) => ({
526
+ code: diagnostic.code,
527
+ message: diagnostic.message,
528
+ details: {
529
+ startupStatus: sourceFidelityStartup.status,
530
+ ledgerPath: sourceFidelityStartup.ledgerPath,
531
+ },
532
+ })),
379
533
  warnings: [],
380
534
  next,
381
535
  };