@tea-agent/loop-agent 0.40.0 → 0.41.0-beta.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 (165) hide show
  1. package/CHANGELOG.md +140 -13
  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/build-stamp.json +3 -3
  5. package/dist/cli/command-definitions.js +12 -0
  6. package/dist/cli/program.js +23 -1
  7. package/dist/commands/dag-artifact.js +284 -0
  8. package/dist/commands/dag-context.js +184 -0
  9. package/dist/commands/dag-rerun.js +206 -1
  10. package/dist/executors/dag-pi-executor.js +39 -12
  11. package/dist/executors/pi-sdk-executor.js +3 -0
  12. package/dist/executors/shell-executor.js +3 -30
  13. package/dist/{worker → infrastructure}/console/app-data.js +4 -0
  14. package/dist/infrastructure/console/artifact-revision-store.js +430 -0
  15. package/dist/infrastructure/console/context-export-store.js +160 -0
  16. package/dist/infrastructure/console/dir-lock.js +132 -0
  17. package/dist/{worker → infrastructure}/console/operation-store.js +28 -0
  18. package/dist/infrastructure/harness/artifact-store.js +10 -1
  19. package/dist/infrastructure/harness/atomic-write.js +12 -2
  20. package/dist/shared/context-transfer/artifact-revision.js +172 -0
  21. package/dist/shared/context-transfer.js +418 -0
  22. package/dist/shared/operator/capabilities.js +14 -0
  23. package/dist/shared/operator/safe-run-summary.js +1 -0
  24. package/dist/shared/path-safety.js +93 -0
  25. package/dist/shared/preview.js +28 -4
  26. package/dist/task/config-types.js +2 -1
  27. package/dist/task/task-demand-routing.js +3 -0
  28. package/dist/worker/console/chat/chat-event-store.js +2 -2
  29. package/dist/worker/console/chat/resource-preferences-store.js +1 -1
  30. package/dist/worker/console/chat/routes.js +3 -11
  31. package/dist/worker/console/chat/session-store.js +1 -1
  32. package/dist/worker/console/chat/turn-process.js +2 -10
  33. package/dist/worker/console/chat/user-questions.js +1 -1
  34. package/dist/worker/console/console-update-runtime.js +1 -1
  35. package/dist/worker/console/context-transfer-diagnostics.js +198 -0
  36. package/dist/worker/console/dag-confirmation.js +1 -1
  37. package/dist/worker/console/dag-execution-receipt.js +1 -1
  38. package/dist/worker/console/doctor.js +1 -1
  39. package/dist/worker/console/draft-store.js +1 -1
  40. package/dist/worker/console/human-gate-token.js +1 -1
  41. package/dist/worker/console/index.js +3 -3
  42. package/dist/worker/console/interview/assessment.js +1 -1
  43. package/dist/worker/console/interview/session.js +1 -1
  44. package/dist/worker/console/operation-runner.js +45 -4
  45. package/dist/worker/console/operation-sse.js +1 -1
  46. package/dist/worker/console/operation-wait.js +1 -1
  47. package/dist/worker/console/operator-actions.js +104 -3
  48. package/dist/worker/console/operator-surface-health.js +1 -1
  49. package/dist/worker/console/operator-user-error.js +169 -0
  50. package/dist/worker/console/routes.js +618 -7
  51. package/dist/worker/console/security.js +35 -0
  52. package/dist/worker/console/server.js +4 -2
  53. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-Dy71QJp3.js → abnfDiagram-N423BO3Z-DSVcg1YO.js} +1 -1
  54. package/dist/worker/console/static/assets/{arc-M25fNMTE.js → arc-BtXhIqui.js} +1 -1
  55. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-CUWlVl1a.js → architectureDiagram-T3A2C74G-B-nh-ilJ.js} +1 -1
  56. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-Dd0Whpx2.js → blockDiagram-VBNYF7ZC-BIUSVdZI.js} +1 -1
  57. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-BdfeCkI5.js → c4Diagram-5PPSVZJV-Cmw3L4qM.js} +1 -1
  58. package/dist/worker/console/static/assets/channel-BhZFNefx.js +1 -0
  59. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-D_1sUkyD.js → chunk-2GRJ4B5K-CGpMMjGm.js} +1 -1
  60. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-Cxnxf36E.js → chunk-2Q5K7J3B-BNBkEpEJ.js} +1 -1
  61. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-D9RG3G_x.js → chunk-5RXB4S5H-ubln3eaU.js} +1 -1
  62. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-Zz9jgjLX.js → chunk-5VM5RSS4-_XcBTt1i.js} +1 -1
  63. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-BCggDRCH.js → chunk-6Q2QTUOP-Ln30Pgrh.js} +1 -1
  64. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-CFg-5iAS.js → chunk-GF5L2VYU-ESH3lhSx.js} +1 -1
  65. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-DRQTE8x_.js → chunk-JWPE2WC7-DAJt-qXB.js} +1 -1
  66. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-C_Dw7uZ8.js → chunk-KBJHAD2P-Cx10LIcH.js} +1 -1
  67. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-BjIiApsk.js → chunk-RYQCIY6F-CENeOxoJ.js} +1 -1
  68. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-B5XQD4KG.js → chunk-XXDRQBXY-DXqK-D38.js} +1 -1
  69. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-Sbv-NJni.js +1 -0
  70. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-Sbv-NJni.js +1 -0
  71. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-huHqH6WQ.js → cose-bilkent-JH36ORCC-CE4dmvGY.js} +1 -1
  72. package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-BSi6yZqP.js → cynefin-VYW2F7L2-CRacN1zK.js} +1 -1
  73. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-Bs_Jp31y.js → cynefinDiagram-MW4NZA55-Cneukjrt.js} +1 -1
  74. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-CYxavikT.js → dagre-VZM6K2ZE-DPFboRoL.js} +1 -1
  75. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-B6TErl71.js → diagram-7IWD3JNH-DIAQgcOP.js} +1 -1
  76. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-CvH4J2ii.js → diagram-B4RE2ZJO-VrYMKxuy.js} +1 -1
  77. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-v1NBAqXS.js → diagram-LBJQPF4R-CLHvBghn.js} +1 -1
  78. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-CUNHVAn2.js → diagram-Q27KOJAE-DVCWBif8.js} +1 -1
  79. package/dist/worker/console/static/assets/{diagram-UB23O5K3-Dzz1gUu-.js → diagram-UB23O5K3-BTMmbBzJ.js} +1 -1
  80. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-CCF8_LjK.js → ebnfDiagram-BXEA7PRR-BUZsKJ56.js} +1 -1
  81. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-DObdPVLa.js → erDiagram-JOGREHBK-BsBZ5NXC.js} +1 -1
  82. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-DlN8Pxrj.js → flowDiagram-UKHOOZJN-D7fH_kDa.js} +1 -1
  83. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-BJKIPTGX.js → ganttDiagram-PKOTCBZU-Bza5OohY.js} +1 -1
  84. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-XcSSnObi.js → gitGraphDiagram-DS77QQ5N-DpkoGR_Y.js} +1 -1
  85. package/dist/worker/console/static/assets/index-Ius3vxhf.css +1 -0
  86. package/dist/worker/console/static/assets/index-yASzcbBr.js +451 -0
  87. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-BKrRKMww.js → infoDiagram-6WML65LV-BYm3g6LT.js} +1 -1
  88. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-CN5dk-yb.js → ishikawaDiagram-WSZJBQD7-C2RS_H4v.js} +1 -1
  89. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-B4P4KZ-Y.js → journeyDiagram-NVQOT4AX-B4slKpCo.js} +1 -1
  90. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-BRlteP32.js → kanban-definition-27J2QSJJ-B7orRNpI.js} +1 -1
  91. package/dist/worker/console/static/assets/{linear-CG8D9fuL.js → linear-D1BeBxLQ.js} +1 -1
  92. package/dist/worker/console/static/assets/{mermaid.core-BuB6P2rX.js → mermaid.core-0TtMP8k4.js} +5 -5
  93. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-DYXGl_DR.js → mindmap-definition-FAOFIHXS-XL5EbCtT.js} +1 -1
  94. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-BM48yEVG.js → pegDiagram-VL7TDLO6-CwF7uas5.js} +1 -1
  95. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-mT8NL-Ow.js → pieDiagram-7S7Q4E2Y-A_Jo-72f.js} +1 -1
  96. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-C4pZ6DH_.js → quadrantDiagram-CIZ2JOQS-CxOa4gKL.js} +1 -1
  97. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-BKAcr70m.js → railroadDiagram-AXF67PYL-DoAoswIH.js} +1 -1
  98. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-CRxcKpoO.js → requirementDiagram-LRYGKXZP-C1Lc1MlD.js} +1 -1
  99. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-Ds4LxQDI.js → sankeyDiagram-W5VNT64P-DFXOkq0U.js} +1 -1
  100. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-CPLwPf_p.js → sequenceDiagram-SI44F4Z6-B0ufUCuW.js} +1 -1
  101. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-CL65uij0.js → sizeCapture-X5ZJPWSS-iPbW55g3.js} +1 -1
  102. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-CO0Mgd1W.js → stateDiagram-OKZ733FA-CHiXzEKP.js} +1 -1
  103. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BtMgzo_H.js +1 -0
  104. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-Cxv3TSNw.js → swimlanes-SLNWSIFB-LyFs7TpX.js} +2 -2
  105. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Cb-OVd9Y.js +8 -0
  106. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-Dw85f9L2.js → timeline-definition-Z64GVDOM-tNkJnb6z.js} +1 -1
  107. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-B4QLCqCy.js → vennDiagram-T6HMQDX7-DFm7Oo8o.js} +1 -1
  108. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-B_yKCWwn.js → wardleyDiagram-T6FBY63Y-tpblTp9i.js} +1 -1
  109. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-nniBEGv2.js → xychartDiagram-ELKLHX3M-BCDLWR_D.js} +1 -1
  110. package/dist/worker/console/static/index.html +7 -2
  111. package/dist/worker/console/static-src/app/useOperatorActions.js +3 -2
  112. package/dist/worker/console/static-src/shell/console-update-reload.js +25 -0
  113. package/dist/worker/console/workspace-context.js +28 -2
  114. package/dist/worker/console/workspace-registry.js +2 -2
  115. package/dist/worker/continuation/worker-continuation.js +278 -0
  116. package/dist/worker/observe/health.js +1 -1
  117. package/dist/worker/observe/node-transparency.js +572 -0
  118. package/dist/worker/observe/routes.js +51 -1
  119. package/dist/worker/observe/static/api.js +69 -5
  120. package/dist/worker/observe/static/dag-context-reason-labels.d.ts +9 -0
  121. package/dist/worker/observe/static/dag-context-reason-labels.js +120 -0
  122. package/dist/worker/observe/static/state.js +3 -1
  123. package/dist/worker/observe/static/styles.css +1037 -126
  124. package/dist/worker/observe/static/views/dag-inspector.js +1215 -58
  125. package/dist/worker/observe/static/views/session-timeline.js +75 -10
  126. package/dist/worker/outcomes/adapters.js +19 -0
  127. package/dist/worker/outcomes/types.js +1 -0
  128. package/dist/worker/pool/attempt-lease.js +97 -66
  129. package/dist/worker/pool/begin-attempt-with-lease.js +1 -0
  130. package/dist/worker/pool/reconcile.js +46 -1
  131. package/dist/worker/pool/run-store.js +2 -0
  132. package/dist/worker/pool/state-projection.js +2 -0
  133. package/dist/worker/task-spec/workflow-routing.js +8 -3
  134. package/dist/workflows/dag/artifact-bindings.js +149 -0
  135. package/dist/workflows/dag/artifact-revision-schema-registry.js +31 -0
  136. package/dist/workflows/dag/backend-test-result-contract.js +1 -1
  137. package/dist/workflows/dag/budget-enforcement.js +10 -0
  138. package/dist/workflows/dag/context-receipt.js +305 -0
  139. package/dist/workflows/dag/context-transfer/context-bundle.js +423 -0
  140. package/dist/workflows/dag/context-transfer/operator-actions.js +61 -0
  141. package/dist/workflows/dag/context-transfer/renderers.js +93 -0
  142. package/dist/workflows/dag/frontend-writer-rollback.js +32 -0
  143. package/dist/workflows/dag/init-hybrid.js +146 -0
  144. package/dist/workflows/dag/node-execution.js +112 -27
  145. package/dist/workflows/dag/path-safety.js +1 -0
  146. package/dist/workflows/dag/prompt.js +29 -4
  147. package/dist/workflows/dag/rerun-plan.js +555 -1
  148. package/dist/workflows/dag/rerun-run.js +601 -15
  149. package/dist/workflows/dag/runner.js +20 -1
  150. package/dist/workflows/dag/skill-snapshot.js +17 -0
  151. package/dist/workflows/dag/types.js +183 -7
  152. package/docs/architecture/runtime-boundaries.md +6 -6
  153. package/docs/architecture/worker-and-feature.md +1 -1
  154. package/docs/templates/agent-dag.schema.json +32 -0
  155. package/docs/templates/product-line/task.yaml +1 -1
  156. package/package.json +3 -1
  157. package/skills/loop-agent/references/command-reference.md +6 -0
  158. package/dist/worker/console/static/assets/channel-Ba0AKiEZ.js +0 -1
  159. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-BU3IjVEe.js +0 -1
  160. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-BU3IjVEe.js +0 -1
  161. package/dist/worker/console/static/assets/index-CIYzS16i.css +0 -1
  162. package/dist/worker/console/static/assets/index-CS3QOTfl.js +0 -451
  163. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BUewAVYS.js +0 -1
  164. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Bhe67Wjl.js +0 -8
  165. /package/dist/{worker → infrastructure}/console/repo-fingerprint.js +0 -0
@@ -586,6 +586,35 @@ export function buildRichTimelineItems(events, options = {}) {
586
586
  return items;
587
587
  }
588
588
 
589
+ const EXECUTION_RECORD_FILTERS = Object.freeze([
590
+ ["all", "全部"],
591
+ ["model", "模型消息"],
592
+ ["tools", "工具与进程"],
593
+ ]);
594
+
595
+ function normalizeExecutionRecordFilter(value) {
596
+ return value === "model" || value === "tools" ? value : "all";
597
+ }
598
+
599
+ export function filterExecutionRecordItems(items, filter) {
600
+ const normalized = normalizeExecutionRecordFilter(filter);
601
+ if (normalized === "all") return items;
602
+ return items.filter((item) => {
603
+ const protocolEvents = Array.isArray(item.protocolEvents)
604
+ ? item.protocolEvents
605
+ : [item.event];
606
+ const toolProtocol =
607
+ item.kind === "protocol" &&
608
+ protocolEvents.some((event) => {
609
+ const role = event?.message?.role ?? event?.role;
610
+ return role === "tool" || role === "toolResult";
611
+ });
612
+ const modelFact =
613
+ item.kind === "turn" || (item.kind === "protocol" && !toolProtocol);
614
+ return normalized === "model" ? modelFact : !modelFact;
615
+ });
616
+ }
617
+
589
618
  function ensureOpenDetailsSet() {
590
619
  if (!(uiState.sessionTimelineOpenDetails instanceof Set)) {
591
620
  uiState.sessionTimelineOpenDetails = new Set();
@@ -829,7 +858,26 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
829
858
  }
830
859
 
831
860
  const showProtocol = Boolean(uiState.sessionTimelineShowProtocol);
861
+ const activeFilter = normalizeExecutionRecordFilter(
862
+ uiState.executionRecordFilter,
863
+ );
832
864
  const toolbar = el("div", "process-timeline-toolbar");
865
+ const filterGroup = el("div", "process-timeline-filter-group");
866
+ filterGroup.setAttribute("role", "group");
867
+ filterGroup.setAttribute("aria-label", "筛选执行记录");
868
+ for (const [filter, label] of EXECUTION_RECORD_FILTERS) {
869
+ const button = document.createElement("button");
870
+ button.type = "button";
871
+ button.className = "process-timeline-toggle process-timeline-filter";
872
+ button.setAttribute("aria-pressed", String(activeFilter === filter));
873
+ button.textContent = label;
874
+ button.addEventListener("click", () => {
875
+ uiState.executionRecordFilter = filter;
876
+ rerenderSessionTimeline(content, nodeId, options);
877
+ });
878
+ filterGroup.appendChild(button);
879
+ }
880
+ toolbar.appendChild(filterGroup);
833
881
  const protocolToggle = document.createElement("button");
834
882
  protocolToggle.type = "button";
835
883
  protocolToggle.className = "process-timeline-toggle";
@@ -839,13 +887,7 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
839
887
  : "展开原始协议事件";
840
888
  protocolToggle.addEventListener("click", () => {
841
889
  uiState.sessionTimelineShowProtocol = !showProtocol;
842
- const parent = content;
843
- const scrollTop = parent.scrollTop;
844
- const scrollLeft = parent.scrollLeft;
845
- while (parent.firstChild) parent.removeChild(parent.firstChild);
846
- renderSessionTimeline(parent, nodeId, options);
847
- parent.scrollTop = scrollTop;
848
- parent.scrollLeft = scrollLeft;
890
+ rerenderSessionTimeline(content, nodeId, options);
849
891
  });
850
892
  toolbar.appendChild(protocolToggle);
851
893
  const exportBtn = el("button", "btn btn-secondary", "导出 HTML");
@@ -879,9 +921,10 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
879
921
  toolbar.appendChild(exportBtn);
880
922
  content.appendChild(toolbar);
881
923
 
882
- const timelineItems = buildRichTimelineItems(visible.events, {
883
- showProtocol,
884
- });
924
+ const timelineItems = filterExecutionRecordItems(
925
+ buildRichTimelineItems(visible.events, { showProtocol }),
926
+ activeFilter,
927
+ );
885
928
  const hasEventTimes = visible.events.some((event) =>
886
929
  Boolean(sessionEventTimestamp(event)),
887
930
  );
@@ -895,6 +938,13 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
895
938
  );
896
939
  }
897
940
 
941
+ if (timelineItems.length === 0) {
942
+ content.appendChild(
943
+ el("p", "empty", "当前筛选下没有可显示的执行记录。"),
944
+ );
945
+ return;
946
+ }
947
+
898
948
  const ul = el("ul", "process-timeline process-timeline-rich");
899
949
  for (let index = 0; index < timelineItems.length; index += 1) {
900
950
  const item = timelineItems[index];
@@ -973,3 +1023,18 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
973
1023
  content.scrollTop = timelineState.scrollTop;
974
1024
  }
975
1025
  }
1026
+
1027
+ function rerenderSessionTimeline(content, nodeId, options) {
1028
+ const scrollTop = content.scrollTop;
1029
+ const scrollLeft = content.scrollLeft;
1030
+ const preserved = [...content.children].filter((child) =>
1031
+ String(child.className ?? "")
1032
+ .split(/\s+/)
1033
+ .includes("dag-inspector-attempt-bar"),
1034
+ );
1035
+ while (content.firstChild) content.removeChild(content.firstChild);
1036
+ for (const child of preserved) content.appendChild(child);
1037
+ renderSessionTimeline(content, nodeId, options);
1038
+ content.scrollTop = scrollTop;
1039
+ content.scrollLeft = scrollLeft;
1040
+ }
@@ -98,6 +98,24 @@ class FrontendImplementationAdapter {
98
98
  };
99
99
  }
100
100
  }
101
+ /**
102
+ * `backend-test-analysis` — read-only requirements/API analysis. It produces
103
+ * the strict Backend Test Analysis v2 contract without claiming that tests or
104
+ * a real integration ran.
105
+ */
106
+ class BackendTestAnalysisAdapter {
107
+ workflow = "backend-test-analysis";
108
+ project(input) {
109
+ return {
110
+ artifacts: [
111
+ ...canonicalArtifacts(input),
112
+ ...structuredArtifactsFromReport(input.dagReportRun),
113
+ ],
114
+ acceptanceCoverage: [...input.acceptanceRefs],
115
+ integrationStatus: { mock: false, real: false },
116
+ };
117
+ }
118
+ }
101
119
  /**
102
120
  * `backend-test` — generates + executes backend tests. Integration status is
103
121
  * `real: true` only when the report completed (a real test execution); mock is
@@ -139,6 +157,7 @@ class FrontendTestAdapter {
139
157
  const ADAPTERS = new Map([
140
158
  ["agent-dag", new AgentDagAdapter()],
141
159
  ["frontend-implementation", new FrontendImplementationAdapter()],
160
+ ["backend-test-analysis", new BackendTestAnalysisAdapter()],
142
161
  ["backend-test", new BackendTestAdapter()],
143
162
  ["frontend-test", new FrontendTestAdapter()],
144
163
  ]);
@@ -24,6 +24,7 @@ export const outcomeFailureCategorySchema = z.enum([
24
24
  export const OUTCOME_WORKFLOWS = [
25
25
  "agent-dag",
26
26
  "frontend-implementation",
27
+ "backend-test-analysis",
27
28
  "backend-test",
28
29
  "frontend-test",
29
30
  ];
@@ -1,6 +1,7 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
  import { mkdir, readFile, readdir, unlink } from "node:fs/promises";
3
3
  import path from "node:path";
4
+ import { acquireDirLock } from "../../infrastructure/console/dir-lock.js";
4
5
  import { writeJsonAtomic } from "../../infrastructure/harness/atomic-write.js";
5
6
  import { assertSafeTaskPoolId, getTaskPoolRoot, } from "./run-store.js";
6
7
  import { TASK_POOL_STATE_ERROR_CODES, TaskPoolStateError } from "./types.js";
@@ -19,6 +20,20 @@ export function getAttemptLeasePath(repoRoot, featureId, taskId) {
19
20
  }
20
21
  return leasePath;
21
22
  }
23
+ function getAttemptLeaseMutationLockPath(repoRoot, featureId, taskId) {
24
+ assertSafeTaskPoolId(featureId, "featureId");
25
+ assertSafeTaskPoolId(taskId, "taskId");
26
+ return path.join(getAttemptLeasesRoot(repoRoot), "_locks", `${featureId}__${taskId}.lock`);
27
+ }
28
+ async function withAttemptLeaseMutationLock(repoRoot, featureId, taskId, operation) {
29
+ const lock = await acquireDirLock(getAttemptLeaseMutationLockPath(repoRoot, featureId, taskId));
30
+ try {
31
+ return await operation();
32
+ }
33
+ finally {
34
+ await lock.release();
35
+ }
36
+ }
22
37
  function isLeaseRecord(value) {
23
38
  if (!value || typeof value !== "object" || Array.isArray(value))
24
39
  return false;
@@ -30,7 +45,11 @@ function isLeaseRecord(value) {
30
45
  typeof record.batchRunId === "string" &&
31
46
  typeof record.token === "string" &&
32
47
  typeof record.acquiredAt === "string" &&
33
- typeof record.renewedAt === "string");
48
+ typeof record.renewedAt === "string" &&
49
+ (record.revisionId === undefined || typeof record.revisionId === "string") &&
50
+ (record.controllerAnchor === undefined ||
51
+ typeof record.controllerAnchor === "string") &&
52
+ (record.claimId === undefined || typeof record.claimId === "string"));
34
53
  }
35
54
  export async function readAttemptLease(repoRoot, featureId, taskId) {
36
55
  const leasePath = getAttemptLeasePath(repoRoot, featureId, taskId);
@@ -47,82 +66,94 @@ export async function readAttemptLease(repoRoot, featureId, taskId) {
47
66
  }
48
67
  /**
49
68
  * Acquire Task-scoped attempt lease before beginWorkerAttempt.
50
- * Same identity+token reuse is idempotent; different active identity → conflict.
69
+ * Same identity+claim reuse is idempotent; a competing admission or active
70
+ * identity conflicts. The Task-scoped mutation lock closes cross-process
71
+ * read-before-rename and release-vs-successor races.
51
72
  */
52
73
  export async function acquireAttemptLease(input) {
53
- const now = input.now ?? new Date();
54
- const existing = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
55
- if (existing) {
56
- if (existing.workerRunId === input.workerRunId &&
57
- existing.batchRunId === input.batchRunId &&
58
- existing.featureId === input.featureId &&
59
- existing.taskId === input.taskId) {
60
- return { status: "idempotent-reuse", lease: existing };
74
+ return withAttemptLeaseMutationLock(input.repoRoot, input.featureId, input.taskId, async () => {
75
+ const now = input.now ?? new Date();
76
+ const existing = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
77
+ if (existing) {
78
+ if (existing.workerRunId === input.workerRunId &&
79
+ existing.batchRunId === input.batchRunId &&
80
+ existing.featureId === input.featureId &&
81
+ existing.taskId === input.taskId &&
82
+ existing.revisionId === input.revisionId &&
83
+ existing.controllerAnchor === input.controllerAnchor &&
84
+ existing.claimId === input.claimId) {
85
+ return { status: "idempotent-reuse", lease: existing };
86
+ }
87
+ throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `attempt-lease-conflict for ${input.featureId}/${input.taskId}: held by ${existing.workerRunId}`);
61
88
  }
62
- throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `attempt-lease-conflict for ${input.featureId}/${input.taskId}: held by ${existing.workerRunId}`);
63
- }
64
- const lease = {
65
- schemaVersion: 1,
66
- featureId: input.featureId,
67
- taskId: input.taskId,
68
- workerRunId: input.workerRunId,
69
- batchRunId: input.batchRunId,
70
- acquiredAt: now.toISOString(),
71
- renewedAt: now.toISOString(),
72
- token: `atk-${randomBytes(8).toString("hex")}`,
73
- ownerProcess: { pid: process.pid },
74
- ...(input.revisionId ? { revisionId: input.revisionId } : {}),
75
- ...(input.controllerAnchor
76
- ? { controllerAnchor: input.controllerAnchor }
77
- : {}),
78
- };
79
- await mkdir(path.dirname(getAttemptLeasePath(input.repoRoot, input.featureId, input.taskId)), {
80
- recursive: true,
89
+ const lease = {
90
+ schemaVersion: 1,
91
+ featureId: input.featureId,
92
+ taskId: input.taskId,
93
+ workerRunId: input.workerRunId,
94
+ batchRunId: input.batchRunId,
95
+ acquiredAt: now.toISOString(),
96
+ renewedAt: now.toISOString(),
97
+ token: `atk-${randomBytes(8).toString("hex")}`,
98
+ ownerProcess: { pid: process.pid },
99
+ ...(input.revisionId ? { revisionId: input.revisionId } : {}),
100
+ ...(input.controllerAnchor
101
+ ? { controllerAnchor: input.controllerAnchor }
102
+ : {}),
103
+ ...(input.claimId ? { claimId: input.claimId } : {}),
104
+ };
105
+ await mkdir(path.dirname(getAttemptLeasePath(input.repoRoot, input.featureId, input.taskId)), {
106
+ recursive: true,
107
+ });
108
+ await writeJsonAtomic(getAttemptLeasePath(input.repoRoot, input.featureId, input.taskId), lease, { repoRoot: input.repoRoot });
109
+ const confirmed = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
110
+ if (!confirmed) {
111
+ throw new Error(`failed to persist attempt lease for ${input.featureId}/${input.taskId}`);
112
+ }
113
+ if (confirmed.token !== lease.token) {
114
+ throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `attempt-lease-conflict race for ${input.featureId}/${input.taskId}`);
115
+ }
116
+ return { status: "acquired", lease: confirmed };
81
117
  });
82
- await writeJsonAtomic(getAttemptLeasePath(input.repoRoot, input.featureId, input.taskId), lease, { repoRoot: input.repoRoot });
83
- const confirmed = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
84
- if (!confirmed) {
85
- throw new Error(`failed to persist attempt lease for ${input.featureId}/${input.taskId}`);
86
- }
87
- if (confirmed.workerRunId !== input.workerRunId) {
88
- throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `attempt-lease-conflict race for ${input.featureId}/${input.taskId}`);
89
- }
90
- return { status: "acquired", lease: confirmed };
91
118
  }
92
119
  export async function renewAttemptLease(input) {
93
- const existing = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
94
- if (!existing) {
95
- throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `cannot renew missing lease for ${input.featureId}/${input.taskId}`);
96
- }
97
- if (existing.token !== input.token || existing.workerRunId !== input.workerRunId) {
98
- throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `cannot renew lease: CAS token/identity mismatch for ${input.featureId}/${input.taskId}`);
99
- }
100
- const renewed = {
101
- ...existing,
102
- renewedAt: (input.now ?? new Date()).toISOString(),
103
- };
104
- await writeJsonAtomic(getAttemptLeasePath(input.repoRoot, input.featureId, input.taskId), renewed, { repoRoot: input.repoRoot });
105
- return renewed;
120
+ return withAttemptLeaseMutationLock(input.repoRoot, input.featureId, input.taskId, async () => {
121
+ const existing = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
122
+ if (!existing) {
123
+ throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `cannot renew missing lease for ${input.featureId}/${input.taskId}`);
124
+ }
125
+ if (existing.token !== input.token || existing.workerRunId !== input.workerRunId) {
126
+ throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `cannot renew lease: CAS token/identity mismatch for ${input.featureId}/${input.taskId}`);
127
+ }
128
+ const renewed = {
129
+ ...existing,
130
+ renewedAt: (input.now ?? new Date()).toISOString(),
131
+ };
132
+ await writeJsonAtomic(getAttemptLeasePath(input.repoRoot, input.featureId, input.taskId), renewed, { repoRoot: input.repoRoot });
133
+ return renewed;
134
+ });
106
135
  }
107
136
  /**
108
137
  * Release active lease after terminal/recovery evidence. Moves to lease-history then deletes active locator.
109
138
  */
110
139
  export async function releaseAttemptLease(input) {
111
- const existing = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
112
- if (!existing)
113
- return;
114
- if (existing.token !== input.token || existing.workerRunId !== input.workerRunId) {
115
- throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `cannot release lease: CAS token/identity mismatch for ${input.featureId}/${input.taskId}`);
116
- }
117
- const historyRoot = path.join(getAttemptLeasesRoot(input.repoRoot), "_history");
118
- await mkdir(historyRoot, { recursive: true });
119
- const historyPath = path.join(historyRoot, `${input.featureId}__${input.taskId}__${existing.workerRunId}.json`);
120
- const activePath = getAttemptLeasePath(input.repoRoot, input.featureId, input.taskId);
121
- await writeJsonAtomic(historyPath, {
122
- ...existing,
123
- releasedAt: (input.now ?? new Date()).toISOString(),
124
- }, { repoRoot: input.repoRoot });
125
- await unlink(activePath).catch(() => { });
140
+ await withAttemptLeaseMutationLock(input.repoRoot, input.featureId, input.taskId, async () => {
141
+ const existing = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
142
+ if (!existing)
143
+ return;
144
+ if (existing.token !== input.token || existing.workerRunId !== input.workerRunId) {
145
+ throw new TaskPoolStateError(TASK_POOL_STATE_ERROR_CODES.CONFLICT, `cannot release lease: CAS token/identity mismatch for ${input.featureId}/${input.taskId}`);
146
+ }
147
+ const historyRoot = path.join(getAttemptLeasesRoot(input.repoRoot), "_history");
148
+ await mkdir(historyRoot, { recursive: true });
149
+ const historyPath = path.join(historyRoot, `${input.featureId}__${input.taskId}__${existing.workerRunId}.json`);
150
+ const activePath = getAttemptLeasePath(input.repoRoot, input.featureId, input.taskId);
151
+ await writeJsonAtomic(historyPath, {
152
+ ...existing,
153
+ releasedAt: (input.now ?? new Date()).toISOString(),
154
+ }, { repoRoot: input.repoRoot });
155
+ await unlink(activePath).catch(() => { });
156
+ });
126
157
  }
127
158
  export function decideAttemptLeaseReclaim(input) {
128
159
  if (input.hasTerminalEvidence) {
@@ -19,6 +19,7 @@ export async function beginWorkerAttemptWithLease(input) {
19
19
  ...(input.controllerAnchor
20
20
  ? { controllerAnchor: input.controllerAnchor }
21
21
  : {}),
22
+ ...(input.leaseClaimId ? { claimId: input.leaseClaimId } : {}),
22
23
  ...(input.now ? { now: input.now } : {}),
23
24
  });
24
25
  const begun = await beginWorkerAttempt(input);
@@ -3,6 +3,8 @@ import path from "node:path";
3
3
  import { executeDagReconcileRun } from "../../workflows/dag/reconcile-run.js";
4
4
  import { assessDagRunLiveness, assessDagRunRecoveryEligibility, locateDagRun, readDagRunState, } from "../../workflows/dag/lifecycle.js";
5
5
  import { appendTaskPoolEvent, findRunByWorkerRunId, getTaskPoolRoot, readTaskPoolState, writeTaskPoolState, } from "./run-store.js";
6
+ import { readRunOwner } from "./run-owner-store.js";
7
+ import { readAttemptLease, releaseAttemptLease } from "./attempt-lease.js";
6
8
  const RECOVERABLE_LIVENESS = new Set([
7
9
  "active",
8
10
  "node-quiet",
@@ -110,6 +112,17 @@ export async function reconcileTaskPoolAbandon(input) {
110
112
  idempotent: false,
111
113
  evidencePath: operatorRecovery.evidencePath,
112
114
  });
115
+ const lease = await readAttemptLease(input.repoRoot, input.featureId, input.taskId);
116
+ if (lease?.workerRunId === input.workerRunId) {
117
+ await releaseAttemptLease({
118
+ repoRoot: input.repoRoot,
119
+ featureId: input.featureId,
120
+ taskId: input.taskId,
121
+ token: lease.token,
122
+ workerRunId: input.workerRunId,
123
+ now: input.now,
124
+ });
125
+ }
113
126
  return {
114
127
  schemaVersion: 1,
115
128
  status: "Failed",
@@ -201,7 +214,6 @@ export async function markTaskPoolFailed(input) {
201
214
  };
202
215
  }
203
216
  async function validateWorkerDagAssociation(input) {
204
- const run = await validateWorkerRunOwnership(input);
205
217
  const dagLocated = await locateDagRun(input.repoRoot, input.dagRunId);
206
218
  if (!dagLocated) {
207
219
  throw new Error(`dag run not found: ${input.dagRunId}`);
@@ -210,6 +222,39 @@ async function validateWorkerDagAssociation(input) {
210
222
  if (dagState.runId !== input.dagRunId) {
211
223
  throw new Error(`dag run identity mismatch: expected ${input.dagRunId}, found ${dagState.runId}`);
212
224
  }
225
+ let run = await findRunByWorkerRunId(input.repoRoot, input.workerRunId);
226
+ if (!run) {
227
+ const owner = await readRunOwner(input.repoRoot, input.workerRunId);
228
+ const association = dagState.workerAssociation;
229
+ const authority = dagState.continuation?.workerContinuationAuthority;
230
+ if (!owner ||
231
+ owner.featureId !== input.featureId ||
232
+ owner.taskId !== input.taskId ||
233
+ owner.workerRunId !== input.workerRunId ||
234
+ owner.revisionId === undefined ||
235
+ input.dagRunId !== input.workerRunId ||
236
+ association?.workerRunId !== input.workerRunId ||
237
+ association.featureId !== input.featureId ||
238
+ association.taskId !== input.taskId ||
239
+ authority?.childWorkerRunId !== input.workerRunId ||
240
+ authority.parentWorkerRunId === input.workerRunId ||
241
+ authority.revisionId !== owner.revisionId) {
242
+ throw new Error(`worker run not found: ${input.workerRunId}`);
243
+ }
244
+ run = {
245
+ schemaVersion: 1,
246
+ batchRunId: owner.batchRunId,
247
+ workerRunId: owner.workerRunId,
248
+ featureId: owner.featureId,
249
+ taskId: owner.taskId,
250
+ status: "run-error",
251
+ attemptKind: "artifact-continuation",
252
+ recordedAt: owner.registeredAt,
253
+ };
254
+ }
255
+ else if (run.featureId !== input.featureId || run.taskId !== input.taskId) {
256
+ throw new Error(`worker run ownership mismatch: expected ${input.featureId}/${input.taskId}, found ${run.featureId}/${run.taskId}`);
257
+ }
213
258
  const linked = await proveWorkerDagLink(input.repoRoot, run, input.workerRunId, input.dagRunId);
214
259
  if (!linked) {
215
260
  throw new Error(`worker run ${input.workerRunId} is not associated with dag run ${input.dagRunId}`);
@@ -350,6 +350,8 @@ function eventFromRun(run) {
350
350
  taskId: run.taskId,
351
351
  featureId: run.featureId,
352
352
  status: run.status,
353
+ ...(run.attemptKind ? { attemptKind: run.attemptKind } : {}),
354
+ ...(run.continuation ? { continuation: run.continuation } : {}),
353
355
  };
354
356
  }
355
357
  function isNotFound(error) {
@@ -47,6 +47,8 @@ export function stateFromRun(run) {
47
47
  status: projectTaskPoolStatusFromRun(run),
48
48
  updatedAt: run.recordedAt,
49
49
  workerRunId: run.workerRunId,
50
+ ...(run.attemptKind ? { attemptKind: run.attemptKind } : {}),
51
+ ...(run.continuation ? { continuation: run.continuation } : {}),
50
52
  ...(run.runRecordPath ? { lastRunRecordPath: run.runRecordPath } : {}),
51
53
  ...(run.failure ? { failure: run.failure } : {}),
52
54
  ...(run.failureV2 ? { failureV2: run.failureV2 } : {}),
@@ -11,6 +11,7 @@ export const workflowSchema = z.enum([
11
11
  "agent-dag",
12
12
  "frontend-implementation",
13
13
  "backend-test",
14
+ "backend-test-analysis",
14
15
  "frontend-test",
15
16
  ]);
16
17
  /**
@@ -23,6 +24,7 @@ export const WORKFLOW_TASK_KIND = {
23
24
  "agent-dag": "standard",
24
25
  "frontend-implementation": "frontend-implementation",
25
26
  "backend-test": "backend-test",
27
+ "backend-test-analysis": "backend-test-analysis",
26
28
  "frontend-test": "frontend-test",
27
29
  };
28
30
  /**
@@ -48,7 +50,7 @@ export function legacyDefaultWorkflow(type) {
48
50
  }
49
51
  /** Migration guidance surfaced whenever a legacy QA type lacks an explicit workflow. */
50
52
  export const LEGACY_QA_MIGRATION_GUIDANCE = "Legacy qa-casegen/qa-testcode/qa-execute tasks no longer auto-select a backend or frontend workflow. " +
51
- "Add `execution.workflow` with one of: agent-dag, frontend-implementation, backend-test, frontend-test. " +
53
+ "Add `execution.workflow` with one of: agent-dag, frontend-implementation, backend-test-analysis, backend-test, frontend-test. " +
52
54
  "Use backend-test for backend-only test generation/execution, frontend-test for browser/UI tests, " +
53
55
  "or agent-dag when the QA task is a generic agent study.";
54
56
  export class WorkflowRoutingError extends Error {
@@ -120,10 +122,13 @@ export function validateWorkflowCompatibility(taskSpec) {
120
122
  }
121
123
  const issues = [];
122
124
  const type = taskSpec.type;
123
- if (type === "backend-feature" && explicit !== "agent-dag" && explicit !== "backend-test") {
125
+ if (type === "backend-feature" &&
126
+ explicit !== "agent-dag" &&
127
+ explicit !== "backend-test-analysis" &&
128
+ explicit !== "backend-test") {
124
129
  issues.push({
125
130
  code: "workflow-type-incompatible",
126
- message: `backend-feature is incompatible with workflow "${explicit}" (expected agent-dag or backend-test)`,
131
+ message: `backend-feature is incompatible with workflow "${explicit}" (expected agent-dag, backend-test-analysis, or backend-test)`,
127
132
  path: "execution.workflow",
128
133
  });
129
134
  }
@@ -0,0 +1,149 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { canonicalSha256 } from "../../shared/context-transfer.js";
5
+ export function buildArtifactBindingGraph(spec) {
6
+ const consumers = new Map();
7
+ for (const task of spec.tasks) {
8
+ for (const binding of task.consumesArtifacts ?? []) {
9
+ const nodeIds = consumers.get(binding.artifactId) ?? [];
10
+ nodeIds.push(task.id);
11
+ consumers.set(binding.artifactId, nodeIds);
12
+ }
13
+ }
14
+ const artifacts = spec.tasks
15
+ .flatMap((task) => (task.producesArtifacts ?? []).map((artifact) => ({
16
+ ...artifact,
17
+ producerNodeId: task.id,
18
+ directConsumerNodeIds: [...(consumers.get(artifact.artifactId) ?? [])].sort(),
19
+ })))
20
+ .sort((a, b) => a.artifactId.localeCompare(b.artifactId));
21
+ const available = artifacts.length > 0;
22
+ const payload = { schemaVersion: 1, artifacts };
23
+ return {
24
+ ...payload,
25
+ available,
26
+ ...(available ? {} : { reasonCode: "ARTIFACT_BINDING_UNAVAILABLE" }),
27
+ artifactGraphSha256: canonicalSha256(payload),
28
+ };
29
+ }
30
+ function collectDescendants(spec, roots) {
31
+ const children = new Map();
32
+ for (const task of spec.tasks) {
33
+ for (const parent of task.depends_on) {
34
+ const values = children.get(parent) ?? [];
35
+ values.push(task.id);
36
+ children.set(parent, values);
37
+ }
38
+ }
39
+ const queue = [...roots];
40
+ const seen = new Set();
41
+ while (queue.length > 0) {
42
+ const nodeId = queue.shift();
43
+ if (seen.has(nodeId))
44
+ continue;
45
+ seen.add(nodeId);
46
+ queue.push(...(children.get(nodeId) ?? []));
47
+ }
48
+ return spec.tasks.map((task) => task.id).filter((nodeId) => seen.has(nodeId));
49
+ }
50
+ export function computeArtifactImpact(spec, artifactId) {
51
+ const graph = buildArtifactBindingGraph(spec);
52
+ const artifact = graph.artifacts.find((entry) => entry.artifactId === artifactId);
53
+ if (!artifact || artifact.directConsumerNodeIds.length === 0)
54
+ return undefined;
55
+ const affectedNodeIds = collectDescendants(spec, artifact.directConsumerNodeIds);
56
+ const affectedSet = new Set(affectedNodeIds);
57
+ const importedNodeIds = spec.tasks
58
+ .map((task) => task.id)
59
+ .filter((nodeId) => !affectedSet.has(nodeId));
60
+ return {
61
+ artifactId,
62
+ producerNodeId: artifact.producerNodeId,
63
+ directConsumerNodeIds: artifact.directConsumerNodeIds,
64
+ effectiveFromNodeId: affectedNodeIds[0],
65
+ affectedNodeIds,
66
+ importedNodeIds,
67
+ };
68
+ }
69
+ function runtimeArtifactFields(node, kind) {
70
+ if (kind === "structured") {
71
+ return {
72
+ path: node.structuredArtifactPath,
73
+ sha256: node.structuredArtifactSha256,
74
+ schemaId: node.structuredArtifactSchemaId,
75
+ };
76
+ }
77
+ if (kind === "assistant") {
78
+ return { path: node.assistantArtifactPath, sha256: node.assistantSha256 };
79
+ }
80
+ return { path: node.stdoutArtifactPath, sha256: node.stdoutSha256 };
81
+ }
82
+ export async function materializeDeclaredArtifactFacts(input) {
83
+ const facts = [];
84
+ for (const declaration of input.task.producesArtifacts ?? []) {
85
+ const runtime = runtimeArtifactFields(input.node, declaration.kind);
86
+ const base = { ...declaration, revisionEligible: false };
87
+ if (!runtime.path || !runtime.sha256) {
88
+ facts.push({
89
+ ...base,
90
+ status: "missing",
91
+ reasonCode: "ARTIFACT_NOT_MATERIALIZED",
92
+ });
93
+ continue;
94
+ }
95
+ const relativePath = path
96
+ .relative(input.runDir, runtime.path)
97
+ .split(path.sep)
98
+ .join("/");
99
+ if (relativePath !== declaration.path) {
100
+ facts.push({
101
+ ...base,
102
+ status: "mismatch",
103
+ sha256: runtime.sha256,
104
+ reasonCode: "ARTIFACT_PATH_MISMATCH",
105
+ });
106
+ continue;
107
+ }
108
+ if (declaration.schemaId !== runtime.schemaId) {
109
+ facts.push({
110
+ ...base,
111
+ status: "mismatch",
112
+ sha256: runtime.sha256,
113
+ reasonCode: "ARTIFACT_SCHEMA_MISMATCH",
114
+ });
115
+ continue;
116
+ }
117
+ let bytes;
118
+ try {
119
+ bytes = await readFile(runtime.path);
120
+ }
121
+ catch {
122
+ facts.push({
123
+ ...base,
124
+ status: "missing",
125
+ reasonCode: "ARTIFACT_NOT_MATERIALIZED",
126
+ });
127
+ continue;
128
+ }
129
+ const actualSha256 = createHash("sha256").update(bytes).digest("hex");
130
+ if (actualSha256 !== runtime.sha256) {
131
+ facts.push({
132
+ ...base,
133
+ status: "mismatch",
134
+ sha256: actualSha256,
135
+ bytes: bytes.byteLength,
136
+ reasonCode: "ARTIFACT_HASH_MISMATCH",
137
+ });
138
+ continue;
139
+ }
140
+ facts.push({
141
+ ...base,
142
+ status: "materialized",
143
+ sha256: actualSha256,
144
+ bytes: bytes.byteLength,
145
+ revisionEligible: declaration.revisionPolicy === "replace-file",
146
+ });
147
+ }
148
+ return facts;
149
+ }