@tea-agent/loop-agent 0.41.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 (162) hide show
  1. package/CHANGELOG.md +102 -14
  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/{worker → infrastructure}/console/app-data.js +4 -0
  13. package/dist/infrastructure/console/artifact-revision-store.js +430 -0
  14. package/dist/infrastructure/console/context-export-store.js +160 -0
  15. package/dist/infrastructure/console/dir-lock.js +132 -0
  16. package/dist/{worker → infrastructure}/console/operation-store.js +28 -0
  17. package/dist/infrastructure/harness/artifact-store.js +10 -1
  18. package/dist/infrastructure/harness/atomic-write.js +12 -2
  19. package/dist/shared/context-transfer/artifact-revision.js +172 -0
  20. package/dist/shared/context-transfer.js +418 -0
  21. package/dist/shared/operator/capabilities.js +14 -0
  22. package/dist/shared/operator/safe-run-summary.js +1 -0
  23. package/dist/shared/path-safety.js +93 -0
  24. package/dist/shared/preview.js +28 -4
  25. package/dist/task/config-types.js +2 -1
  26. package/dist/task/task-demand-routing.js +3 -0
  27. package/dist/worker/console/chat/chat-event-store.js +2 -2
  28. package/dist/worker/console/chat/resource-preferences-store.js +1 -1
  29. package/dist/worker/console/chat/routes.js +1 -1
  30. package/dist/worker/console/chat/session-store.js +1 -1
  31. package/dist/worker/console/chat/user-questions.js +1 -1
  32. package/dist/worker/console/console-update-runtime.js +1 -1
  33. package/dist/worker/console/context-transfer-diagnostics.js +198 -0
  34. package/dist/worker/console/dag-confirmation.js +1 -1
  35. package/dist/worker/console/dag-execution-receipt.js +1 -1
  36. package/dist/worker/console/doctor.js +1 -1
  37. package/dist/worker/console/draft-store.js +1 -1
  38. package/dist/worker/console/human-gate-token.js +1 -1
  39. package/dist/worker/console/index.js +3 -3
  40. package/dist/worker/console/interview/assessment.js +1 -1
  41. package/dist/worker/console/interview/session.js +1 -1
  42. package/dist/worker/console/operation-runner.js +45 -4
  43. package/dist/worker/console/operation-sse.js +1 -1
  44. package/dist/worker/console/operation-wait.js +1 -1
  45. package/dist/worker/console/operator-actions.js +104 -3
  46. package/dist/worker/console/operator-surface-health.js +1 -1
  47. package/dist/worker/console/operator-user-error.js +169 -0
  48. package/dist/worker/console/pi-plugins.js +57 -0
  49. package/dist/worker/console/routes.js +637 -8
  50. package/dist/worker/console/security.js +35 -0
  51. package/dist/worker/console/server.js +6 -3
  52. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-DwVJxUxz.js → abnfDiagram-N423BO3Z-DZZ8m3PO.js} +1 -1
  53. package/dist/worker/console/static/assets/{arc-DqfCcXdu.js → arc-D6PvaVd-.js} +1 -1
  54. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-qMVtggRv.js → architectureDiagram-T3A2C74G-B_OTOiI8.js} +1 -1
  55. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-ECrV38dh.js → blockDiagram-VBNYF7ZC-Bv6rqHBg.js} +1 -1
  56. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-DBaaLqQv.js → c4Diagram-5PPSVZJV-B8eHr0oz.js} +1 -1
  57. package/dist/worker/console/static/assets/channel-BU5gOilw.js +1 -0
  58. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-BvfNHkAz.js → chunk-2GRJ4B5K-DYwR0im2.js} +1 -1
  59. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-C5StiIbc.js → chunk-2Q5K7J3B-D2WPGqXt.js} +1 -1
  60. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-HabGiJkS.js → chunk-5RXB4S5H-CQISJ_I7.js} +1 -1
  61. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-BiTg127i.js → chunk-5VM5RSS4-C0o2Du1e.js} +1 -1
  62. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-CZsXBPuR.js → chunk-6Q2QTUOP-4f8kr-U7.js} +1 -1
  63. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-D-r1MxLK.js → chunk-GF5L2VYU-D_OWvXzX.js} +1 -1
  64. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-DQxb9plr.js → chunk-JWPE2WC7-CasdPz5X.js} +1 -1
  65. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-DMndGvCT.js → chunk-KBJHAD2P-Cj8lRrla.js} +1 -1
  66. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-ByL4BgOJ.js → chunk-RYQCIY6F-CUvD1FSd.js} +1 -1
  67. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-BVe1b1gL.js → chunk-XXDRQBXY-CqLw_eqB.js} +1 -1
  68. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DIzKJGHr.js +1 -0
  69. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DIzKJGHr.js +1 -0
  70. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BAyGzN8j.js → cose-bilkent-JH36ORCC-ku-WqJPx.js} +1 -1
  71. package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-C5yVYU7E.js → cynefin-VYW2F7L2-Bq_PYDhl.js} +1 -1
  72. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-x-MwsEm9.js → cynefinDiagram-MW4NZA55-BiGZV641.js} +1 -1
  73. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-CT5Tle5F.js → dagre-VZM6K2ZE-C4JRlglF.js} +1 -1
  74. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-BARERhlS.js → diagram-7IWD3JNH-B0dNeWYG.js} +1 -1
  75. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BwfUz0VM.js → diagram-B4RE2ZJO-Cj35YvYM.js} +1 -1
  76. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-Mk4r2WvJ.js → diagram-LBJQPF4R-uzQoJ2-8.js} +1 -1
  77. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-KUrxuBs0.js → diagram-Q27KOJAE-D1a-Buoz.js} +1 -1
  78. package/dist/worker/console/static/assets/{diagram-UB23O5K3-CjZOceZn.js → diagram-UB23O5K3-XjRrLRSs.js} +1 -1
  79. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-rnwUCiEI.js → ebnfDiagram-BXEA7PRR-Da_O24cW.js} +1 -1
  80. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-DM4j23FM.js → erDiagram-JOGREHBK-BLJ8jrYU.js} +1 -1
  81. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-DD5HdDEs.js → flowDiagram-UKHOOZJN-B9GrLjM0.js} +1 -1
  82. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-CIAGSF47.js → ganttDiagram-PKOTCBZU-CeJ0TqiK.js} +1 -1
  83. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-DbwFbVEL.js → gitGraphDiagram-DS77QQ5N-Bm2eNNFX.js} +1 -1
  84. package/dist/worker/console/static/assets/index-H9rFJiGL.css +1 -0
  85. package/dist/worker/console/static/assets/{index-Bih9w9h9.js → index-xwu9GxEc.js} +80 -80
  86. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-B-Pb0T66.js → infoDiagram-6WML65LV-DB26i3d8.js} +1 -1
  87. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-B9Unk-YX.js → ishikawaDiagram-WSZJBQD7-BOGRyeZT.js} +1 -1
  88. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-C2F3JkPt.js → journeyDiagram-NVQOT4AX-CZRoBO_6.js} +1 -1
  89. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-Bl8-Xcoz.js → kanban-definition-27J2QSJJ-qlWhJyoB.js} +1 -1
  90. package/dist/worker/console/static/assets/{linear-yK4uZmC5.js → linear-CfUiDDB3.js} +1 -1
  91. package/dist/worker/console/static/assets/{mermaid.core-Bpa6PmuE.js → mermaid.core-BQe6fpqj.js} +5 -5
  92. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-BfGRoCSe.js → mindmap-definition-FAOFIHXS-zFzWHw64.js} +1 -1
  93. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-Bz6_HtST.js → pegDiagram-VL7TDLO6-DFGUqjZO.js} +1 -1
  94. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-i0Umbsby.js → pieDiagram-7S7Q4E2Y-BB5i0l8Z.js} +1 -1
  95. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-DaVQBobe.js → quadrantDiagram-CIZ2JOQS-obbVZ_X5.js} +1 -1
  96. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-DMTGnSq7.js → railroadDiagram-AXF67PYL-BwdaNzc1.js} +1 -1
  97. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-2ao_DaSq.js → requirementDiagram-LRYGKXZP-CkTJaugh.js} +1 -1
  98. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-2SG1lTB9.js → sankeyDiagram-W5VNT64P-BwJ-hIgq.js} +1 -1
  99. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-BQYOLybR.js → sequenceDiagram-SI44F4Z6-BzSgmm7w.js} +1 -1
  100. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-C8g3yjuI.js → sizeCapture-X5ZJPWSS-Bn3oj5Q1.js} +1 -1
  101. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-q_F8nAQG.js → stateDiagram-OKZ733FA-dxhGtL8K.js} +1 -1
  102. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Cld2qK9v.js +1 -0
  103. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-8LrWpH2s.js → swimlanes-SLNWSIFB-BLpEInya.js} +2 -2
  104. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-TIHpiT7w.js +8 -0
  105. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-BQoY3qzl.js → timeline-definition-Z64GVDOM-ChJGYcXy.js} +1 -1
  106. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-BDu1UjSp.js → vennDiagram-T6HMQDX7-DK-qjRer.js} +1 -1
  107. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-C48M7Y0a.js → wardleyDiagram-T6FBY63Y-3qeaWAg-.js} +1 -1
  108. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-YU6FTl_F.js → xychartDiagram-ELKLHX3M-CootlyP9.js} +1 -1
  109. package/dist/worker/console/static/index.html +7 -2
  110. package/dist/worker/console/static-src/app/useOperatorActions.js +3 -2
  111. package/dist/worker/console/static-src/shell/console-update-reload.js +25 -0
  112. package/dist/worker/console/workspace-context.js +28 -2
  113. package/dist/worker/console/workspace-registry.js +2 -2
  114. package/dist/worker/continuation/worker-continuation.js +278 -0
  115. package/dist/worker/observe/health.js +1 -1
  116. package/dist/worker/observe/node-transparency.js +572 -0
  117. package/dist/worker/observe/routes.js +51 -1
  118. package/dist/worker/observe/static/api.js +69 -5
  119. package/dist/worker/observe/static/dag-context-reason-labels.d.ts +9 -0
  120. package/dist/worker/observe/static/dag-context-reason-labels.js +120 -0
  121. package/dist/worker/observe/static/state.js +3 -1
  122. package/dist/worker/observe/static/styles.css +1037 -126
  123. package/dist/worker/observe/static/views/dag-inspector.js +1215 -58
  124. package/dist/worker/observe/static/views/session-timeline.js +75 -10
  125. package/dist/worker/outcomes/adapters.js +19 -0
  126. package/dist/worker/outcomes/types.js +1 -0
  127. package/dist/worker/pool/attempt-lease.js +97 -66
  128. package/dist/worker/pool/begin-attempt-with-lease.js +1 -0
  129. package/dist/worker/pool/reconcile.js +46 -1
  130. package/dist/worker/pool/run-store.js +2 -0
  131. package/dist/worker/pool/state-projection.js +2 -0
  132. package/dist/worker/task-spec/workflow-routing.js +8 -3
  133. package/dist/workflows/dag/artifact-bindings.js +149 -0
  134. package/dist/workflows/dag/artifact-revision-schema-registry.js +31 -0
  135. package/dist/workflows/dag/budget-enforcement.js +10 -0
  136. package/dist/workflows/dag/context-receipt.js +305 -0
  137. package/dist/workflows/dag/context-transfer/context-bundle.js +423 -0
  138. package/dist/workflows/dag/context-transfer/operator-actions.js +61 -0
  139. package/dist/workflows/dag/context-transfer/renderers.js +93 -0
  140. package/dist/workflows/dag/frontend-writer-rollback.js +32 -0
  141. package/dist/workflows/dag/init-hybrid.js +146 -0
  142. package/dist/workflows/dag/node-execution.js +112 -27
  143. package/dist/workflows/dag/path-safety.js +1 -0
  144. package/dist/workflows/dag/prompt.js +29 -4
  145. package/dist/workflows/dag/rerun-plan.js +555 -1
  146. package/dist/workflows/dag/rerun-run.js +601 -15
  147. package/dist/workflows/dag/runner.js +20 -1
  148. package/dist/workflows/dag/skill-snapshot.js +17 -0
  149. package/dist/workflows/dag/types.js +183 -7
  150. package/docs/architecture/runtime-boundaries.md +6 -6
  151. package/docs/architecture/worker-and-feature.md +1 -1
  152. package/docs/templates/agent-dag.schema.json +32 -0
  153. package/docs/templates/product-line/task.yaml +1 -1
  154. package/package.json +3 -1
  155. package/skills/loop-agent/references/command-reference.md +6 -0
  156. package/dist/worker/console/static/assets/channel-CL1NRAmS.js +0 -1
  157. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-PBGzzjZA.js +0 -1
  158. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-PBGzzjZA.js +0 -1
  159. package/dist/worker/console/static/assets/index-BfleX-qj.css +0 -1
  160. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DrxGBDJu.js +0 -1
  161. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BhpDxzAf.js +0 -8
  162. /package/dist/{worker → infrastructure}/console/repo-fingerprint.js +0 -0
@@ -623,6 +623,35 @@ export function buildRichTimelineItems(events, options = {}) {
623
623
  return items;
624
624
  }
625
625
 
626
+ const EXECUTION_RECORD_FILTERS = Object.freeze([
627
+ ["all", "全部"],
628
+ ["model", "模型消息"],
629
+ ["tools", "工具与进程"],
630
+ ]);
631
+
632
+ function normalizeExecutionRecordFilter(value) {
633
+ return value === "model" || value === "tools" ? value : "all";
634
+ }
635
+
636
+ export function filterExecutionRecordItems(items, filter) {
637
+ const normalized = normalizeExecutionRecordFilter(filter);
638
+ if (normalized === "all") return items;
639
+ return items.filter((item) => {
640
+ const protocolEvents = Array.isArray(item.protocolEvents)
641
+ ? item.protocolEvents
642
+ : [item.event];
643
+ const toolProtocol =
644
+ item.kind === "protocol" &&
645
+ protocolEvents.some((event) => {
646
+ const role = event?.message?.role ?? event?.role;
647
+ return role === "tool" || role === "toolResult";
648
+ });
649
+ const modelFact =
650
+ item.kind === "turn" || (item.kind === "protocol" && !toolProtocol);
651
+ return normalized === "model" ? modelFact : !modelFact;
652
+ });
653
+ }
654
+
626
655
  function ensureOpenDetailsSet() {
627
656
  if (!(uiState.sessionTimelineOpenDetails instanceof Set)) {
628
657
  uiState.sessionTimelineOpenDetails = new Set();
@@ -866,7 +895,26 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
866
895
  }
867
896
 
868
897
  const showProtocol = Boolean(uiState.sessionTimelineShowProtocol);
898
+ const activeFilter = normalizeExecutionRecordFilter(
899
+ uiState.executionRecordFilter,
900
+ );
869
901
  const toolbar = el("div", "process-timeline-toolbar");
902
+ const filterGroup = el("div", "process-timeline-filter-group");
903
+ filterGroup.setAttribute("role", "group");
904
+ filterGroup.setAttribute("aria-label", "筛选执行记录");
905
+ for (const [filter, label] of EXECUTION_RECORD_FILTERS) {
906
+ const button = document.createElement("button");
907
+ button.type = "button";
908
+ button.className = "process-timeline-toggle process-timeline-filter";
909
+ button.setAttribute("aria-pressed", String(activeFilter === filter));
910
+ button.textContent = label;
911
+ button.addEventListener("click", () => {
912
+ uiState.executionRecordFilter = filter;
913
+ rerenderSessionTimeline(content, nodeId, options);
914
+ });
915
+ filterGroup.appendChild(button);
916
+ }
917
+ toolbar.appendChild(filterGroup);
870
918
  const protocolToggle = document.createElement("button");
871
919
  protocolToggle.type = "button";
872
920
  protocolToggle.className = "process-timeline-toggle";
@@ -876,13 +924,7 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
876
924
  : "展开原始协议事件";
877
925
  protocolToggle.addEventListener("click", () => {
878
926
  uiState.sessionTimelineShowProtocol = !showProtocol;
879
- const parent = content;
880
- const scrollTop = parent.scrollTop;
881
- const scrollLeft = parent.scrollLeft;
882
- while (parent.firstChild) parent.removeChild(parent.firstChild);
883
- renderSessionTimeline(parent, nodeId, options);
884
- parent.scrollTop = scrollTop;
885
- parent.scrollLeft = scrollLeft;
927
+ rerenderSessionTimeline(content, nodeId, options);
886
928
  });
887
929
  toolbar.appendChild(protocolToggle);
888
930
  const exportBtn = el("button", "btn btn-secondary", "导出 HTML");
@@ -910,9 +952,10 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
910
952
  toolbar.appendChild(exportBtn);
911
953
  content.appendChild(toolbar);
912
954
 
913
- const timelineItems = buildRichTimelineItems(visible.events, {
914
- showProtocol,
915
- });
955
+ const timelineItems = filterExecutionRecordItems(
956
+ buildRichTimelineItems(visible.events, { showProtocol }),
957
+ activeFilter,
958
+ );
916
959
  const hasEventTimes = visible.events.some((event) =>
917
960
  Boolean(sessionEventTimestamp(event)),
918
961
  );
@@ -926,6 +969,13 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
926
969
  );
927
970
  }
928
971
 
972
+ if (timelineItems.length === 0) {
973
+ content.appendChild(
974
+ el("p", "empty", "当前筛选下没有可显示的执行记录。"),
975
+ );
976
+ return;
977
+ }
978
+
929
979
  const ul = el("ul", "process-timeline process-timeline-rich");
930
980
  for (let index = 0; index < timelineItems.length; index += 1) {
931
981
  const item = timelineItems[index];
@@ -1004,3 +1054,18 @@ export function renderSessionTimeline(content, nodeId, options = {}) {
1004
1054
  content.scrollTop = timelineState.scrollTop;
1005
1055
  }
1006
1056
  }
1057
+
1058
+ function rerenderSessionTimeline(content, nodeId, options) {
1059
+ const scrollTop = content.scrollTop;
1060
+ const scrollLeft = content.scrollLeft;
1061
+ const preserved = [...content.children].filter((child) =>
1062
+ String(child.className ?? "")
1063
+ .split(/\s+/)
1064
+ .includes("dag-inspector-attempt-bar"),
1065
+ );
1066
+ while (content.firstChild) content.removeChild(content.firstChild);
1067
+ for (const child of preserved) content.appendChild(child);
1068
+ renderSessionTimeline(content, nodeId, options);
1069
+ content.scrollTop = scrollTop;
1070
+ content.scrollLeft = scrollLeft;
1071
+ }
@@ -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
+ }