@tea-agent/loop-agent 0.51.0 → 0.52.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.
- package/CHANGELOG.md +123 -5
- package/dist/build-stamp.json +3 -3
- package/dist/cli/command-definitions.js +1 -75
- package/dist/cli/help.js +1 -1
- package/dist/cli/program.js +1 -28
- package/dist/commands/init-accepted-merge.js +46 -0
- package/dist/commands/init-upgrade.js +115 -2
- package/dist/commands/init.js +79 -12
- package/dist/executors/pi-sdk-executor.js +3 -3
- package/dist/governance/path-guard.js +2 -0
- package/dist/records/harvest.js +1 -1
- package/dist/shared/git-progress.js +3 -0
- package/dist/shared/operator/capabilities.js +0 -122
- package/dist/shared/pi-context-pressure/checkpoint.js +94 -24
- package/dist/shared/pi-context-pressure/compaction-policy.js +152 -66
- package/dist/shared/pi-context-pressure/extension.js +25 -8
- package/dist/shared/pi-context-pressure/index.js +1 -1
- package/dist/shared/pi-context-pressure/telemetry.js +10 -0
- package/dist/shared/update/npm-client.js +14 -3
- package/dist/task/config-types.js +5 -10
- package/dist/task/delegate.js +1 -1
- package/dist/task/read-model.js +0 -4
- package/dist/task/runtime.js +0 -1
- package/dist/task/worktree.js +1 -1
- package/dist/worker/console/chat/api-workbench-core.js +17 -6
- package/dist/worker/console/chat/api-workbench.js +2 -0
- package/dist/worker/console/chat/assistant-content.js +21 -3
- package/dist/worker/console/chat/chat-event-projection.js +6 -0
- package/dist/worker/console/chat/chat-event-store.js +32 -2
- package/dist/worker/console/chat/chat-references.js +4 -0
- package/dist/worker/console/chat/compaction-errors.js +14 -2
- package/dist/worker/console/chat/context-insights.js +41 -4
- package/dist/worker/console/chat/context-usage.js +4 -1
- package/dist/worker/console/chat/pi-runtime/custom-tools/apiworkbench-tools.js +65 -3
- package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +2 -2
- package/dist/worker/console/chat/pi-runtime/extension-bindings.js +39 -0
- package/dist/worker/console/chat/pi-runtime/sdk-bindings.js +4 -0
- package/dist/worker/console/chat/pi-runtime.js +389 -191
- package/dist/worker/console/chat/repo-browser.js +5 -2
- package/dist/worker/console/chat/repo-preview-kind.js +16 -6
- package/dist/worker/console/chat/routes.js +299 -25
- package/dist/worker/console/chat/scheduled-goal-request.js +1 -1
- package/dist/worker/console/chat/subagents/jobs.js +115 -4
- package/dist/worker/console/chat/terminal-sessions.js +52 -6
- package/dist/worker/console/chat/tool-exposure-catalog.js +1 -1
- package/dist/worker/console/chat/tool-presentation.js +17 -10
- package/dist/worker/console/chat/tool-preview.js +22 -0
- package/dist/worker/console/chat/turn-process.js +49 -0
- package/dist/worker/console/chat/vcp-prompt.js +14 -9
- package/dist/worker/console/chat/workspace-changes.js +17 -0
- package/dist/worker/console/console-update-runtime.js +5 -1
- package/dist/worker/console/operator-actions.js +7 -6
- package/dist/worker/console/operator-user-error.js +5 -1
- package/dist/worker/console/pi-compaction-settings.js +220 -0
- package/dist/worker/console/routes.js +1 -1
- package/dist/worker/console/server.js +148 -6
- package/dist/worker/console/static/assets/FilePreviewDocx-ybM3ZqSl.js +9 -0
- package/dist/worker/console/static/assets/abnfDiagram-N423BO3Z-CT26sIgH.js +1 -0
- package/dist/worker/console/static/assets/{arc-Bkf_oc0_.js → arc-CPwLqDB0.js} +1 -1
- package/dist/worker/console/static/assets/architectureDiagram-T3A2C74G-CzTSMPU_.js +36 -0
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-D62uVvbI.js → blockDiagram-VBNYF7ZC-BfgbtJLH.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-Iq0Y8Afx.js → c4Diagram-5PPSVZJV-B9pTjB8U.js} +1 -1
- package/dist/worker/console/static/assets/channel-DtYRMDck.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-D1TxRE3k.js → chunk-2GRJ4B5K-xORV8QsC.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-BE-DHkAO.js → chunk-2Q5K7J3B-BzpYWAHK.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-t0iYO8Cc.js → chunk-5RXB4S5H-D8zcRP6c.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-Clo2nExi.js → chunk-5VM5RSS4-DVEXxzQJ.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-C7bSpo-3.js → chunk-6Q2QTUOP-CKZOJU2z.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-DorZaymh.js → chunk-GF5L2VYU-Cgx34Dj8.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-Ch_4HvyJ.js → chunk-JWPE2WC7-ehcSKOcx.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-yaSoFe-3.js → chunk-KBJHAD2P-CiY9emCG.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-QpjaXecS.js → chunk-RYQCIY6F-Bk9X-ksQ.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-B3t6cycg.js → chunk-XXDRQBXY-DC0xXfHy.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DyesHbs5.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DyesHbs5.js +1 -0
- package/dist/worker/console/static/assets/cose-bilkent-JH36ORCC-C_EVg5l9.js +1 -0
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-CP8LtrOl.js → cynefin-VYW2F7L2-BIFL8KrA.js} +1 -1
- package/dist/worker/console/static/assets/cynefinDiagram-MW4NZA55-DjtUYOlE.js +62 -0
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BK0ua9V8.js → dagre-VZM6K2ZE-D2aN2V9t.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-t9-HP13j.js → diagram-7IWD3JNH-D_twhmFi.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-L5Sg9jMD.js → diagram-B4RE2ZJO-ChzncqLV.js} +1 -1
- package/dist/worker/console/static/assets/diagram-LBJQPF4R-B6LO-bF2.js +24 -0
- package/dist/worker/console/static/assets/diagram-Q27KOJAE-GrzM7AFc.js +24 -0
- package/dist/worker/console/static/assets/diagram-UB23O5K3-Bv-lntaq.js +41 -0
- package/dist/worker/console/static/assets/docx-preview-CAbT0VNs.js +23 -0
- package/dist/worker/console/static/assets/docxPreview-D_T4B7qe.js +1 -0
- package/dist/worker/console/static/assets/ebnfDiagram-BXEA7PRR-BvD2jkO_.js +1 -0
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-CNOuj3BO.js → erDiagram-JOGREHBK-BirPCcmA.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-h_Cyayai.js → flowDiagram-UKHOOZJN-Chu1YnGQ.js} +1 -1
- package/dist/worker/console/static/assets/ganttDiagram-PKOTCBZU-Djn17xhB.js +292 -0
- package/dist/worker/console/static/assets/gitGraphDiagram-DS77QQ5N-Bx1qbGHx.js +106 -0
- package/dist/worker/console/static/assets/infoDiagram-6WML65LV-D-TLMqmb.js +2 -0
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-DAdf5lHp.js → ishikawaDiagram-WSZJBQD7-DbJoh-6T.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-BQbGtg66.js → journeyDiagram-NVQOT4AX-DsyokZ6e.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-CetLubYc.js → kanban-definition-27J2QSJJ-DlzXTxic.js} +1 -1
- package/dist/worker/console/static/assets/{linear-DLZOjaVz.js → linear-ClnZn3vw.js} +1 -1
- package/dist/worker/console/static/assets/main-D-ZQ4gLb.css +1 -0
- package/dist/worker/console/static/assets/main-fc3P1HID.js +645 -0
- package/dist/worker/console/static/assets/{mermaid.core-B_xZl_gM.js → mermaid.core-DqSlcvbf.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-Dzo3dzp0.js → mindmap-definition-FAOFIHXS-CSFbzpiX.js} +1 -1
- package/dist/worker/console/static/assets/pegDiagram-VL7TDLO6-DK80yQqe.js +1 -0
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-Cp3YrVzQ.js → pieDiagram-7S7Q4E2Y-DWX7SFGb.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-4tI5mUgW.js → quadrantDiagram-CIZ2JOQS-BEPPhtXs.js} +1 -1
- package/dist/worker/console/static/assets/railroadDiagram-AXF67PYL-Ck_s6fQn.js +1 -0
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-DY-0JqdT.js → requirementDiagram-LRYGKXZP-CYig27Rj.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-DuJIzRKC.js → sankeyDiagram-W5VNT64P-u-0aSx5s.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-BTbVJ85l.js → sequenceDiagram-SI44F4Z6-NsEJI9sM.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-BPPh1uLw.js → sheet-workbook-kZ_HK4Sg.js} +2 -2
- package/dist/worker/console/static/assets/sizeCapture-X5ZJPWSS-8vneVM5U.js +1 -0
- package/dist/worker/console/static/assets/stateDiagram-OKZ733FA-CMIobUBh.js +1 -0
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Bd0pHHKP.js +1 -0
- package/dist/worker/console/static/assets/swimlanes-SLNWSIFB-D4Qzt6ug.js +2 -0
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BzmSZnl_.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-GR6lxokn.js → timeline-definition-Z64GVDOM-DMb1LpED.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-DEkwyzsF.js → vennDiagram-T6HMQDX7-C_9eFOs3.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-W5jnvEJ3.js → wardleyDiagram-T6FBY63Y-DJYMe3uT.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-cqsloioo.js → xychartDiagram-ELKLHX3M-Cv_1Mi3u.js} +1 -1
- package/dist/worker/console/static/docx-preview.html +25 -0
- package/dist/worker/console/static/index.html +3 -2
- package/dist/worker/console/static/vcp/fonts/README.md +28 -0
- package/dist/worker/console/static/vcp/vendor/vcp-engine-v1.js +4 -4
- package/dist/worker/console/static-src/operator-chat/StateDot.js +17 -0
- package/dist/worker/console/static-src/operator-chat/changed-file-diff.js +15 -0
- package/dist/worker/console/static-src/operator-chat/chat-font-size.js +90 -0
- package/dist/worker/console/static-src/operator-chat/chat-session-order.js +96 -0
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +8 -1
- package/dist/worker/console/static-src/operator-chat/compaction-message.js +4 -0
- package/dist/worker/console/static-src/operator-chat/details-rail-surfaces.js +2 -0
- package/dist/worker/console/static-src/operator-chat/file-touch.js +107 -0
- package/dist/worker/console/static-src/operator-chat/format-file-size.js +26 -0
- package/dist/worker/console/static-src/operator-chat/open-preview-in-browser.js +44 -0
- package/dist/worker/console/static-src/operator-chat/reference-display.js +7 -1
- package/dist/worker/console/static-src/operator-chat/tasks-auto-open.js +100 -0
- package/dist/worker/console/static-src/operator-chat/tasks-layout-tween.js +103 -0
- package/dist/worker/console/static-src/operator-chat/tasks-model.js +657 -0
- package/dist/worker/console/static-src/operator-chat/tasks-view-glide.js +96 -0
- package/dist/worker/console/static-src/operator-chat/turn-group-equality.js +1 -0
- package/dist/worker/console/static-src/operator-chat/use-auto-animate.js +61 -0
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +194 -47
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +4 -0
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +18 -0
- package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +111 -21
- package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +91 -47
- package/dist/worker/console/static-src/operator-chat/useVcpPreferences.js +1 -1
- package/dist/worker/console/static-src/operator-chat/user-turn-anchors-merge.js +50 -0
- package/dist/worker/console/static-src/operator-chat/vcp-fonts.js +180 -22
- package/dist/worker/console/static-src/operator-chat/vcp-frame.js +3 -3
- package/dist/worker/console/static-src/shell/console-update-progress.js +16 -0
- package/dist/worker/console/static-src/shell/console-update-reload.js +4 -1
- package/dist/worker/console/static-src/shell/workspace-route.js +0 -2
- package/dist/worker/console/vite.config.js +5 -1
- package/dist/worker/console/workspace-registry.js +62 -19
- package/dist/worker/observe/static/operator-chrome.js +0 -1
- package/dist/worker/scheduler/git-base.js +3 -0
- package/dist/worker/scheduler/night-git-finalizer.js +1 -1
- package/dist/worker/scheduler/night-harvest.js +1 -1
- package/dist/worker/scheduler/prepared-attempt-recovery.js +1 -1
- package/dist/worker/scheduler/scheduled-goal-evidence.js +1 -1
- package/dist/workflows/dag/backend-test-scenario-param.js +60 -4
- package/dist/workflows/dag/dynamic-runtime/reduction.js +7 -2
- package/dist/workflows/dag/frontend-test-framework-adapters.js +11 -2
- package/dist/workflows/script/windows/guest.js +13 -2
- package/dist/workflows/script/windows/native.js +21 -3
- package/docs/architecture/dag-execution.md +2 -13
- package/docs/architecture/facts-and-state.md +2 -3
- package/docs/architecture/runtime-boundaries.md +2 -2
- package/package.json +9 -7
- package/resource-catalog.v1.json +6 -6
- package/scripts/patch-pi-sdk-windows-hide.mjs +3 -3
- package/skills/loop-agent/references/command-reference.md +2 -41
- package/skills/loop-agent/references/harness-policy.md +3 -30
- package/skills/loop-agent/references/long-running-loop.md +6 -54
- package/dist/application/loop/run-action.js +0 -19
- package/dist/commands/dag-workflow-compile.js +0 -93
- package/dist/commands/dag-workflow-plan.js +0 -132
- package/dist/commands/dag-workflow-validate.js +0 -68
- package/dist/commands/loop-benchmark.js +0 -74
- package/dist/commands/loop.js +0 -251
- package/dist/commands/workflow.js +0 -259
- package/dist/infrastructure/harness/loop-store.js +0 -41
- package/dist/worker/console/static/assets/abnfDiagram-N423BO3Z-FQePHM07.js +0 -1
- package/dist/worker/console/static/assets/architectureDiagram-T3A2C74G-p_mwm8cd.js +0 -36
- package/dist/worker/console/static/assets/channel-CIBAg8WF.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-B4xQrSmv.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-B4xQrSmv.js +0 -1
- package/dist/worker/console/static/assets/cose-bilkent-JH36ORCC-BPXf8ZYr.js +0 -1
- package/dist/worker/console/static/assets/cynefinDiagram-MW4NZA55-CNsL9N2-.js +0 -62
- package/dist/worker/console/static/assets/diagram-LBJQPF4R-BipWFRgs.js +0 -24
- package/dist/worker/console/static/assets/diagram-Q27KOJAE-T2p4xa38.js +0 -24
- package/dist/worker/console/static/assets/diagram-UB23O5K3-CVwz6LVu.js +0 -41
- package/dist/worker/console/static/assets/ebnfDiagram-BXEA7PRR-CybQrGSA.js +0 -1
- package/dist/worker/console/static/assets/ganttDiagram-PKOTCBZU-D411_55h.js +0 -292
- package/dist/worker/console/static/assets/gitGraphDiagram-DS77QQ5N-DpVtzs9z.js +0 -106
- package/dist/worker/console/static/assets/index-B7cwOTL9.js +0 -649
- package/dist/worker/console/static/assets/index-CATbSkPc.css +0 -1
- package/dist/worker/console/static/assets/infoDiagram-6WML65LV-D74Uvx6K.js +0 -2
- package/dist/worker/console/static/assets/pegDiagram-VL7TDLO6-CSwoBOpM.js +0 -1
- package/dist/worker/console/static/assets/railroadDiagram-AXF67PYL-n0Mt3Yia.js +0 -1
- package/dist/worker/console/static/assets/sizeCapture-X5ZJPWSS-Dmf1pC7B.js +0 -1
- package/dist/worker/console/static/assets/stateDiagram-OKZ733FA-4-jdPUHD.js +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DojWfYnC.js +0 -1
- package/dist/worker/console/static/assets/swimlanes-SLNWSIFB-DNhjjaAU.js +0 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-CJo4AKWH.js +0 -8
- package/dist/worker/console/static/vcp/fonts/Lanxi-/345/217/257/345/256/213.woff2 +0 -0
- package/dist/worker/console/static/vcp/fonts/Lanxi-/346/234/227/345/256/213.woff2 +0 -0
- package/dist/worker/console/static/vcp/fonts/Lanxi-/350/266/205/347/262/227/351/273/221.woff2 +0 -0
- package/dist/workflows/dynamic/compile.js +0 -371
- package/dist/workflows/dynamic/compileTypes.js +0 -1
- package/dist/workflows/dynamic/errors.js +0 -5
- package/dist/workflows/dynamic/profiles.js +0 -156
- package/dist/workflows/dynamic/spec.js +0 -115
- package/dist/workflows/dynamic/validate.js +0 -275
- package/dist/workflows/loop/actions/dag-action.js +0 -129
- package/dist/workflows/loop/actions/pi-review.js +0 -267
- package/dist/workflows/loop/actions/shared.js +0 -157
- package/dist/workflows/loop/actions/shell-verify.js +0 -82
- package/dist/workflows/loop/actions/types.js +0 -1
- package/dist/workflows/loop/actions/workflow-action.js +0 -255
- package/dist/workflows/loop/actions.js +0 -160
- package/dist/workflows/loop/benchmark.js +0 -513
- package/dist/workflows/loop/closeout.js +0 -135
- package/dist/workflows/loop/context.js +0 -47
- package/dist/workflows/loop/events.js +0 -26
- package/dist/workflows/loop/hash.js +0 -32
- package/dist/workflows/loop/index.js +0 -8
- package/dist/workflows/loop/paths.js +0 -17
- package/dist/workflows/loop/policy/auto-policy.js +0 -112
- package/dist/workflows/loop/policy/path-patterns.js +0 -13
- package/dist/workflows/loop/rounds.js +0 -81
- package/dist/workflows/loop/signals.js +0 -52
- package/dist/workflows/loop/state.js +0 -116
- package/dist/workflows/loop/templates.js +0 -54
- package/dist/workflows/loop/types.js +0 -28
- /package/dist/workflows/{dynamic/artifacts.js → dag/dynamic-runtime/reduction-artifacts.js} +0 -0
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { AGENT_LIKE_WORKFLOW_NODE_TYPES, ITEM_SELECTOR_WORKFLOW_NODE_TYPES, workflowSpecSchema, workflowNodeSchema, } from "./spec.js";
|
|
2
|
-
import { formatWorkflowValidationIssues, } from "./errors.js";
|
|
3
|
-
export function parseWorkflowSpec(raw) {
|
|
4
|
-
return workflowSpecSchema.parse(raw);
|
|
5
|
-
}
|
|
6
|
-
function nodePath(node, suffix) {
|
|
7
|
-
return suffix ? `nodes.${node.id}.${suffix}` : `nodes.${node.id}`;
|
|
8
|
-
}
|
|
9
|
-
function pushIssue(issues, issue) {
|
|
10
|
-
issues.push(issue);
|
|
11
|
-
}
|
|
12
|
-
function collectSelectorNodeRefs(selector) {
|
|
13
|
-
const refs = new Set();
|
|
14
|
-
const pattern = /\.nodes\[['"]([^'"]+)['"]\]/g;
|
|
15
|
-
let match;
|
|
16
|
-
while ((match = pattern.exec(selector)) !== null) {
|
|
17
|
-
refs.add(match[1] ?? "");
|
|
18
|
-
}
|
|
19
|
-
return [...refs].filter(Boolean);
|
|
20
|
-
}
|
|
21
|
-
function collectAncestors(nodeId, dependenciesById, seen = new Set()) {
|
|
22
|
-
for (const dependency of dependenciesById.get(nodeId) ?? []) {
|
|
23
|
-
if (seen.has(dependency))
|
|
24
|
-
continue;
|
|
25
|
-
seen.add(dependency);
|
|
26
|
-
collectAncestors(dependency, dependenciesById, seen);
|
|
27
|
-
}
|
|
28
|
-
return seen;
|
|
29
|
-
}
|
|
30
|
-
function validateAcyclic(spec, issues) {
|
|
31
|
-
const dependenciesById = new Map(spec.nodes.map((node) => [node.id, node.dependsOn]));
|
|
32
|
-
const visiting = new Set();
|
|
33
|
-
const visited = new Set();
|
|
34
|
-
function visit(id, stack) {
|
|
35
|
-
if (visited.has(id))
|
|
36
|
-
return;
|
|
37
|
-
if (visiting.has(id)) {
|
|
38
|
-
pushIssue(issues, {
|
|
39
|
-
type: "cycle",
|
|
40
|
-
path: `nodes.${id}.dependsOn`,
|
|
41
|
-
message: `workflow dependency cycle detected: ${[...stack, id].join(" -> ")}`,
|
|
42
|
-
});
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
visiting.add(id);
|
|
46
|
-
for (const dependency of dependenciesById.get(id) ?? []) {
|
|
47
|
-
if (!dependenciesById.has(dependency))
|
|
48
|
-
continue;
|
|
49
|
-
visit(dependency, [...stack, id]);
|
|
50
|
-
}
|
|
51
|
-
visiting.delete(id);
|
|
52
|
-
visited.add(id);
|
|
53
|
-
}
|
|
54
|
-
for (const node of spec.nodes) {
|
|
55
|
-
visit(node.id, []);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
export function validateWorkflowSpec(spec) {
|
|
59
|
-
const issues = [];
|
|
60
|
-
const seen = new Set();
|
|
61
|
-
const nodeIds = new Set(spec.nodes.map((node) => node.id));
|
|
62
|
-
const dependenciesById = new Map(spec.nodes.map((node) => [node.id, node.dependsOn]));
|
|
63
|
-
for (const node of spec.nodes) {
|
|
64
|
-
if (seen.has(node.id)) {
|
|
65
|
-
pushIssue(issues, {
|
|
66
|
-
type: "duplicate-node-id",
|
|
67
|
-
path: nodePath(node),
|
|
68
|
-
message: `duplicate workflow node id "${node.id}"`,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
seen.add(node.id);
|
|
72
|
-
for (const dependency of node.dependsOn) {
|
|
73
|
-
if (dependency === node.id) {
|
|
74
|
-
pushIssue(issues, {
|
|
75
|
-
type: "self-dependency",
|
|
76
|
-
path: nodePath(node, "dependsOn"),
|
|
77
|
-
message: `node "${node.id}" cannot depend on itself`,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
if (!nodeIds.has(dependency)) {
|
|
81
|
-
pushIssue(issues, {
|
|
82
|
-
type: "missing-dependency",
|
|
83
|
-
path: nodePath(node, "dependsOn"),
|
|
84
|
-
message: `node "${node.id}" depends on missing node "${dependency}"`,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (AGENT_LIKE_WORKFLOW_NODE_TYPES.has(node.type) && !node.outputSchema) {
|
|
89
|
-
pushIssue(issues, {
|
|
90
|
-
type: "missing-output-schema",
|
|
91
|
-
path: nodePath(node, "outputSchema"),
|
|
92
|
-
message: `${node.type} node "${node.id}" requires outputSchema`,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
if (ITEM_SELECTOR_WORKFLOW_NODE_TYPES.has(node.type) && !node.itemsFrom) {
|
|
96
|
-
pushIssue(issues, {
|
|
97
|
-
type: "missing-items-from",
|
|
98
|
-
path: nodePath(node, "itemsFrom"),
|
|
99
|
-
message: `${node.type} node "${node.id}" requires itemsFrom`,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (node.itemsFrom) {
|
|
103
|
-
const refs = collectSelectorNodeRefs(node.itemsFrom);
|
|
104
|
-
const ancestors = collectAncestors(node.id, dependenciesById);
|
|
105
|
-
for (const ref of refs) {
|
|
106
|
-
if (!nodeIds.has(ref)) {
|
|
107
|
-
pushIssue(issues, {
|
|
108
|
-
type: "items-from-missing-node",
|
|
109
|
-
path: nodePath(node, "itemsFrom"),
|
|
110
|
-
message: `itemsFrom references missing node "${ref}"`,
|
|
111
|
-
});
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
if (!ancestors.has(ref)) {
|
|
115
|
-
pushIssue(issues, {
|
|
116
|
-
type: "items-from-not-upstream",
|
|
117
|
-
path: nodePath(node, "itemsFrom"),
|
|
118
|
-
message: `itemsFrom node "${ref}" must be an upstream dependency of "${node.id}"`,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (node.type === "command") {
|
|
124
|
-
if (!node.command) {
|
|
125
|
-
pushIssue(issues, {
|
|
126
|
-
type: "missing-command",
|
|
127
|
-
path: nodePath(node, "command"),
|
|
128
|
-
message: `command node "${node.id}" requires command`,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
else if (spec.permissions.shell.mode !== "allowlist") {
|
|
132
|
-
pushIssue(issues, {
|
|
133
|
-
type: "command-without-allowlist",
|
|
134
|
-
path: nodePath(node, "command"),
|
|
135
|
-
message: `command node "${node.id}" requires permissions.shell.mode=allowlist`,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
else if (!spec.permissions.shell.commands.includes(node.command)) {
|
|
139
|
-
pushIssue(issues, {
|
|
140
|
-
type: "command-not-allowlisted",
|
|
141
|
-
path: nodePath(node, "command"),
|
|
142
|
-
message: `command node "${node.id}" command is not listed in permissions.shell.commands`,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (node.type === "loop_until" && !node.maxIterations) {
|
|
147
|
-
pushIssue(issues, {
|
|
148
|
-
type: "missing-max-iterations",
|
|
149
|
-
path: nodePath(node, "maxIterations"),
|
|
150
|
-
message: `loop_until node "${node.id}" must declare maxIterations`,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
if (node.type === "loop_until") {
|
|
154
|
-
if (!node.body || node.body.length === 0) {
|
|
155
|
-
pushIssue(issues, {
|
|
156
|
-
type: "missing-loop-body",
|
|
157
|
-
path: nodePath(node, "body"),
|
|
158
|
-
message: `loop_until node "${node.id}" must declare a non-empty body`,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
for (const [index, bodyNode] of (node.body ?? []).entries()) {
|
|
162
|
-
const parsed = workflowNodeSchema.safeParse(bodyNode);
|
|
163
|
-
if (!parsed.success) {
|
|
164
|
-
pushIssue(issues, {
|
|
165
|
-
type: "invalid-loop-body",
|
|
166
|
-
path: nodePath(node, `body.${index}`),
|
|
167
|
-
message: `loop_until node "${node.id}" body node ${index} is invalid`,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (node.type === "condition") {
|
|
173
|
-
const ancestors = collectAncestors(node.id, dependenciesById);
|
|
174
|
-
for (const conditionCase of node.cases ?? []) {
|
|
175
|
-
if (!nodeIds.has(conditionCase.then)) {
|
|
176
|
-
pushIssue(issues, {
|
|
177
|
-
type: "missing-condition-target",
|
|
178
|
-
path: nodePath(node, "cases"),
|
|
179
|
-
message: `condition node "${node.id}" references missing then target "${conditionCase.then}"`,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
for (const ref of collectSelectorNodeRefs(conditionCase.when)) {
|
|
183
|
-
if (!nodeIds.has(ref) || !ancestors.has(ref)) {
|
|
184
|
-
pushIssue(issues, {
|
|
185
|
-
type: "condition-source-not-upstream",
|
|
186
|
-
path: nodePath(node, "cases"),
|
|
187
|
-
message: `condition node "${node.id}" reads non-upstream node "${ref}"`,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (node.default && !nodeIds.has(node.default)) {
|
|
193
|
-
pushIssue(issues, {
|
|
194
|
-
type: "missing-condition-target",
|
|
195
|
-
path: nodePath(node, "default"),
|
|
196
|
-
message: `condition node "${node.id}" references missing default target "${node.default}"`,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (node.type === "artifact_transform" && !node.transform) {
|
|
201
|
-
pushIssue(issues, {
|
|
202
|
-
type: "invalid-artifact-transform",
|
|
203
|
-
path: nodePath(node, "transform"),
|
|
204
|
-
message: `artifact_transform node "${node.id}" requires deterministic transform`,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
if (node.type === "verify_agent" && node.producerNodeId === node.id) {
|
|
208
|
-
pushIssue(issues, {
|
|
209
|
-
type: "producer-verifies-own-finding",
|
|
210
|
-
path: nodePath(node, "producerNodeId"),
|
|
211
|
-
message: `verify_agent node "${node.id}" cannot verify findings it produced`,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
if (node.type === "reduce_agent" && node.reducer) {
|
|
215
|
-
for (const [field, selector] of [
|
|
216
|
-
["findingsFrom", node.reducer.findingsFrom],
|
|
217
|
-
["verificationsFrom", node.reducer.verificationsFrom],
|
|
218
|
-
]) {
|
|
219
|
-
const refs = collectSelectorNodeRefs(selector);
|
|
220
|
-
if (refs.length === 0) {
|
|
221
|
-
pushIssue(issues, {
|
|
222
|
-
type: "missing-reducer-source",
|
|
223
|
-
path: nodePath(node, `reducer.${field}`),
|
|
224
|
-
message: `reduce_agent node "${node.id}" reducer.${field} must reference a workflow node output`,
|
|
225
|
-
});
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
const ancestors = collectAncestors(node.id, dependenciesById);
|
|
229
|
-
for (const ref of refs) {
|
|
230
|
-
if (!nodeIds.has(ref) || !ancestors.has(ref)) {
|
|
231
|
-
pushIssue(issues, {
|
|
232
|
-
type: "missing-reducer-source",
|
|
233
|
-
path: nodePath(node, `reducer.${field}`),
|
|
234
|
-
message: `reduce_agent node "${node.id}" reducer.${field} must reference an upstream node output`,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (!nodeIds.has(spec.final.from)) {
|
|
242
|
-
pushIssue(issues, {
|
|
243
|
-
type: "missing-final-node",
|
|
244
|
-
path: "final.from",
|
|
245
|
-
message: `final.from references missing node "${spec.final.from}"`,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
if (spec.permissions.edits !== "deny") {
|
|
249
|
-
const hasWriteScope = (spec.permissions.allowedPaths?.length ?? 0) > 0 &&
|
|
250
|
-
(spec.permissions.forbiddenPaths?.length ?? 0) > 0 &&
|
|
251
|
-
(spec.permissions.writeSet?.length ?? 0) > 0;
|
|
252
|
-
if (!hasWriteScope) {
|
|
253
|
-
pushIssue(issues, {
|
|
254
|
-
type: "write-scope-required",
|
|
255
|
-
path: "permissions",
|
|
256
|
-
message: "workflows with edits enabled require allowedPaths, forbiddenPaths, and writeSet",
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
if (!spec.nodes.some((node) => node.type === "human_gate")) {
|
|
260
|
-
pushIssue(issues, {
|
|
261
|
-
type: "write-human-gate-required",
|
|
262
|
-
path: "nodes",
|
|
263
|
-
message: "workflows with edits enabled require a human_gate node",
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
validateAcyclic(spec, issues);
|
|
268
|
-
return issues;
|
|
269
|
-
}
|
|
270
|
-
export function assertValidWorkflowSpec(spec) {
|
|
271
|
-
const issues = validateWorkflowSpec(spec);
|
|
272
|
-
if (issues.length > 0) {
|
|
273
|
-
throw new Error(`invalid WorkflowSpec: ${formatWorkflowValidationIssues(issues)}`);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { mkdir } from "node:fs/promises";
|
|
3
|
-
import { writeLoopDagRecord } from "../../../infrastructure/harness/loop-action-store.js";
|
|
4
|
-
import { getTaskPaths } from "../../../task/runtime.js";
|
|
5
|
-
import { getLoopPaths } from "../paths.js";
|
|
6
|
-
import { appendLoopRound } from "../rounds.js";
|
|
7
|
-
import { rewriteLoopContext } from "../context.js";
|
|
8
|
-
import { readLoopRounds } from "../rounds.js";
|
|
9
|
-
import { asRecord, dagFailureCategory, firstReportRun, loopDecisionForDagRun, loopResultForDagRun, relativeRef, stringField, } from "./shared.js";
|
|
10
|
-
let defaultDagCommandRunner;
|
|
11
|
-
export function configureLoopDagDefaultRunner(runner) {
|
|
12
|
-
defaultDagCommandRunner = runner;
|
|
13
|
-
}
|
|
14
|
-
function resolveDefaultRunner(repoRoot) {
|
|
15
|
-
if (!defaultDagCommandRunner) {
|
|
16
|
-
throw new Error("Loop DAG action default runner is not configured");
|
|
17
|
-
}
|
|
18
|
-
return (command, args) => defaultDagCommandRunner(repoRoot, command, args);
|
|
19
|
-
}
|
|
20
|
-
export async function runLoopDagAction(repoRoot, taskId, options = {}) {
|
|
21
|
-
const mode = options.mode ?? "review";
|
|
22
|
-
const cwd = options.cwd ? path.resolve(repoRoot, options.cwd) : repoRoot;
|
|
23
|
-
const rounds = await readLoopRounds(repoRoot, taskId);
|
|
24
|
-
const round = rounds.length + 1;
|
|
25
|
-
const paths = getLoopPaths(repoRoot, taskId);
|
|
26
|
-
const dagEvidenceDir = path.join(paths.loopDir, "dag");
|
|
27
|
-
await mkdir(dagEvidenceDir, { recursive: true });
|
|
28
|
-
const dagPath = options.dagPath
|
|
29
|
-
? path.resolve(repoRoot, options.dagPath)
|
|
30
|
-
: getTaskPaths(repoRoot, taskId).dagDraftPath;
|
|
31
|
-
const runner = options.runner ?? resolveDefaultRunner(repoRoot);
|
|
32
|
-
let generated = {};
|
|
33
|
-
if (!options.dagPath) {
|
|
34
|
-
generated = asRecord(await runner("dag-run-task", [
|
|
35
|
-
taskId,
|
|
36
|
-
"--profile",
|
|
37
|
-
"auto",
|
|
38
|
-
"--strict-models",
|
|
39
|
-
"--output",
|
|
40
|
-
dagPath,
|
|
41
|
-
"--cwd",
|
|
42
|
-
cwd,
|
|
43
|
-
]), "dag run-task");
|
|
44
|
-
}
|
|
45
|
-
await runner("dag-validate", [
|
|
46
|
-
"--dag",
|
|
47
|
-
dagPath,
|
|
48
|
-
"--strict-models",
|
|
49
|
-
"--strict-governance",
|
|
50
|
-
]);
|
|
51
|
-
let runId = "";
|
|
52
|
-
let runStatus = "not-run";
|
|
53
|
-
let runLifecycle = "not-run";
|
|
54
|
-
let runRef = "";
|
|
55
|
-
let reportRef = "";
|
|
56
|
-
let failureCategory = "";
|
|
57
|
-
let decision = "continue";
|
|
58
|
-
let result = "dag generated and strict-governance validated";
|
|
59
|
-
let lesson = "DAG review packet is ready; inspect writeSet, gates, and expected verification before execution.";
|
|
60
|
-
let completedCriteria = ["dag generated and strict-governance validated"];
|
|
61
|
-
if (mode === "execute") {
|
|
62
|
-
const runArgs = ["--dag", dagPath, "--cwd", cwd];
|
|
63
|
-
if (options.runId)
|
|
64
|
-
runArgs.push("--run-id", options.runId);
|
|
65
|
-
if (options.maxConcurrent !== undefined) {
|
|
66
|
-
runArgs.push("--max-concurrent", String(options.maxConcurrent));
|
|
67
|
-
}
|
|
68
|
-
const runSummary = asRecord(await runner("run-dag", runArgs), "run-dag");
|
|
69
|
-
runId = stringField(runSummary, "runId", "run-dag");
|
|
70
|
-
const report = await runner("dag-report", [
|
|
71
|
-
"--run-id",
|
|
72
|
-
runId,
|
|
73
|
-
"--json",
|
|
74
|
-
"--lifecycle",
|
|
75
|
-
"all",
|
|
76
|
-
]);
|
|
77
|
-
const run = firstReportRun(report);
|
|
78
|
-
runStatus = stringField(run, "status", "dag report run");
|
|
79
|
-
runLifecycle = stringField(run, "lifecycle", "dag report run");
|
|
80
|
-
runRef = relativeRef(repoRoot, stringField(run, "runDir", "dag report run"));
|
|
81
|
-
failureCategory = dagFailureCategory(run);
|
|
82
|
-
decision = loopDecisionForDagRun(run);
|
|
83
|
-
result = loopResultForDagRun(run);
|
|
84
|
-
lesson =
|
|
85
|
-
decision === "pause"
|
|
86
|
-
? "DAG run paused for human approval; use DAG decision commands before resuming."
|
|
87
|
-
: "DAG run facts recorded; inspect dag report and follow with shell verification or review.";
|
|
88
|
-
completedCriteria = ["dag round action executed"];
|
|
89
|
-
}
|
|
90
|
-
const recordPath = path.join(dagEvidenceDir, `round-${round}.json`);
|
|
91
|
-
reportRef = relativeRef(repoRoot, recordPath);
|
|
92
|
-
const record = {
|
|
93
|
-
schemaVersion: 1,
|
|
94
|
-
taskId,
|
|
95
|
-
round,
|
|
96
|
-
action: "dag",
|
|
97
|
-
mode,
|
|
98
|
-
ok: mode === "review" || runStatus === "finished",
|
|
99
|
-
dagPath: relativeRef(repoRoot, dagPath),
|
|
100
|
-
strictValidateOk: true,
|
|
101
|
-
runId,
|
|
102
|
-
runStatus,
|
|
103
|
-
runLifecycle,
|
|
104
|
-
runRef,
|
|
105
|
-
reportRef,
|
|
106
|
-
reviewPacket: generated.reviewPacket,
|
|
107
|
-
failureCategory,
|
|
108
|
-
expectedNextVerification: decision === "pause"
|
|
109
|
-
? "approve or reject paused DAG run, then resume or replan"
|
|
110
|
-
: "run shell verification or review DAG report before completion",
|
|
111
|
-
recordedAt: new Date().toISOString(),
|
|
112
|
-
};
|
|
113
|
-
await writeLoopDagRecord(repoRoot, taskId, round, record);
|
|
114
|
-
await appendLoopRound(repoRoot, taskId, {
|
|
115
|
-
action: "dag",
|
|
116
|
-
refs: [runRef, record.dagPath, reportRef].filter(Boolean),
|
|
117
|
-
result,
|
|
118
|
-
verification: mode === "review"
|
|
119
|
-
? "dag generated and validated with --strict-models --strict-governance"
|
|
120
|
-
: `dag report status=${runStatus}, lifecycle=${runLifecycle}`,
|
|
121
|
-
lesson,
|
|
122
|
-
next: record.expectedNextVerification,
|
|
123
|
-
decision,
|
|
124
|
-
failureCategory,
|
|
125
|
-
completedCriteria,
|
|
126
|
-
});
|
|
127
|
-
await rewriteLoopContext(repoRoot, taskId);
|
|
128
|
-
return record;
|
|
129
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { DEFAULT_PI_MODEL, DEFAULT_PI_PROVIDER, } from "../../../executors/pi-defaults.js";
|
|
4
|
-
import { executeSingleSdkAttempt } from "../../../executors/pi-sdk-executor.js";
|
|
5
|
-
import { writeLoopPiReviewPrompt, writeLoopPiReviewRecord, } from "../../../infrastructure/harness/loop-action-store.js";
|
|
6
|
-
import { createOneShotActiveRunDir, transferOneShotRunToCompleted, transferOneShotRunToFailed, writeOneShotRunMarkdown, writeOneShotRunMeta, } from "../../../infrastructure/harness/one-shot-run-store.js";
|
|
7
|
-
import { getLoopPaths } from "../paths.js";
|
|
8
|
-
import { appendLoopRound } from "../rounds.js";
|
|
9
|
-
import { rewriteLoopContext } from "../context.js";
|
|
10
|
-
import { readLoopRounds } from "../rounds.js";
|
|
11
|
-
import { latestVerificationSummary, relativeRef, truncateSummary } from "./shared.js";
|
|
12
|
-
const PI_REVIEW_TOOLS = ["read", "grep", "find", "ls"];
|
|
13
|
-
export async function buildLoopPiReviewPrompt(repoRoot, taskId) {
|
|
14
|
-
const paths = getLoopPaths(repoRoot, taskId);
|
|
15
|
-
const [objective, context, rounds] = await Promise.all([
|
|
16
|
-
readFile(paths.objectivePath, "utf-8"),
|
|
17
|
-
readFile(paths.contextPath, "utf-8"),
|
|
18
|
-
readLoopRounds(repoRoot, taskId),
|
|
19
|
-
]);
|
|
20
|
-
return [
|
|
21
|
-
"You are running as a read-only loop-agent loop Pi review action.",
|
|
22
|
-
"Do not edit files. Do not run shell commands. Use only read, grep, find, and ls tools if tools are needed.",
|
|
23
|
-
"Review the current loop state and return exactly one JSON object with these fields:",
|
|
24
|
-
'{"findingSummary":"","failureCategory":"","nextHypothesis":"","recommendedAction":"implement_fix|replan|pause|done","fixScope":["path/or/component"],"rootCause":"","invariant":""}',
|
|
25
|
-
"recommendedAction must be exactly one of: implement_fix, replan, pause, done.",
|
|
26
|
-
"",
|
|
27
|
-
"<objective>",
|
|
28
|
-
objective.trim(),
|
|
29
|
-
"</objective>",
|
|
30
|
-
"",
|
|
31
|
-
"<context>",
|
|
32
|
-
context.trim(),
|
|
33
|
-
"</context>",
|
|
34
|
-
"",
|
|
35
|
-
"<latest_verification>",
|
|
36
|
-
latestVerificationSummary(rounds),
|
|
37
|
-
"</latest_verification>",
|
|
38
|
-
].join("\n");
|
|
39
|
-
}
|
|
40
|
-
function parsePiReviewStructuredOutput(text) {
|
|
41
|
-
const trimmed = text.trim();
|
|
42
|
-
const jsonMatch = trimmed.match(/\{[\s\S]*\}/);
|
|
43
|
-
if (!jsonMatch) {
|
|
44
|
-
throw new Error("pi-review output did not contain a JSON object");
|
|
45
|
-
}
|
|
46
|
-
const parsed = JSON.parse(jsonMatch[0]);
|
|
47
|
-
for (const key of [
|
|
48
|
-
"findingSummary",
|
|
49
|
-
"failureCategory",
|
|
50
|
-
"nextHypothesis",
|
|
51
|
-
"recommendedAction",
|
|
52
|
-
"rootCause",
|
|
53
|
-
]) {
|
|
54
|
-
if (typeof parsed[key] !== "string" || parsed[key].trim().length === 0) {
|
|
55
|
-
throw new Error(`pi-review output missing structured field: ${key}`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (!Array.isArray(parsed.fixScope) || parsed.fixScope.length === 0) {
|
|
59
|
-
throw new Error("pi-review output missing structured field: fixScope");
|
|
60
|
-
}
|
|
61
|
-
const findingSummary = parsed.findingSummary;
|
|
62
|
-
const failureCategory = parsed.failureCategory;
|
|
63
|
-
const nextHypothesis = parsed.nextHypothesis;
|
|
64
|
-
const recommendedAction = parsed.recommendedAction;
|
|
65
|
-
const rootCause = parsed.rootCause;
|
|
66
|
-
if (typeof findingSummary !== "string" ||
|
|
67
|
-
typeof failureCategory !== "string" ||
|
|
68
|
-
typeof nextHypothesis !== "string" ||
|
|
69
|
-
typeof recommendedAction !== "string" ||
|
|
70
|
-
typeof rootCause !== "string") {
|
|
71
|
-
throw new Error("pi-review output failed structured field validation");
|
|
72
|
-
}
|
|
73
|
-
if (!isLoopPiReviewRecommendedAction(recommendedAction)) {
|
|
74
|
-
throw new Error(`pi-review output recommendedAction must be one of implement_fix|replan|pause|done, got: ${recommendedAction}`);
|
|
75
|
-
}
|
|
76
|
-
const fixScope = parsed.fixScope
|
|
77
|
-
.filter((value) => typeof value === "string")
|
|
78
|
-
.map((value) => value.trim())
|
|
79
|
-
.filter(Boolean);
|
|
80
|
-
if (fixScope.length === 0) {
|
|
81
|
-
throw new Error("pi-review output fixScope must contain at least one non-empty string");
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
findingSummary: findingSummary.trim(),
|
|
85
|
-
failureCategory: failureCategory.trim(),
|
|
86
|
-
nextHypothesis: nextHypothesis.trim(),
|
|
87
|
-
recommendedAction,
|
|
88
|
-
fixScope,
|
|
89
|
-
rootCause: rootCause.trim(),
|
|
90
|
-
invariant: typeof parsed.invariant === "string" ? parsed.invariant.trim() : undefined,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function isLoopPiReviewRecommendedAction(value) {
|
|
94
|
-
return (value === "implement_fix" ||
|
|
95
|
-
value === "replan" ||
|
|
96
|
-
value === "pause" ||
|
|
97
|
-
value === "done");
|
|
98
|
-
}
|
|
99
|
-
async function defaultPiReviewExecutor(input) {
|
|
100
|
-
const startedAt = Date.now();
|
|
101
|
-
const result = await executeSingleSdkAttempt({
|
|
102
|
-
repoRoot: input.cwd,
|
|
103
|
-
prompt: "You are a read-only reviewer for loop-agent loop. Return only structured JSON.",
|
|
104
|
-
userMessage: input.prompt,
|
|
105
|
-
attachedFiles: [],
|
|
106
|
-
toolNames: [...input.toolNames],
|
|
107
|
-
timeoutMs: input.timeoutMs,
|
|
108
|
-
step: "analyze",
|
|
109
|
-
modelConfig: {
|
|
110
|
-
provider: input.provider,
|
|
111
|
-
model: input.model,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
return {
|
|
115
|
-
ok: result.ok,
|
|
116
|
-
assistantText: result.assistantText,
|
|
117
|
-
durationMs: Date.now() - startedAt,
|
|
118
|
-
failureCategory: result.failureCategory,
|
|
119
|
-
stderr: result.stderr,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
export async function readLatestPiReviewRecord(repoRoot, taskId) {
|
|
123
|
-
const paths = getLoopPaths(repoRoot, taskId);
|
|
124
|
-
let entries;
|
|
125
|
-
try {
|
|
126
|
-
entries = await readdir(paths.reviewDir);
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
|
-
const roundFiles = entries
|
|
132
|
-
.map((entry) => {
|
|
133
|
-
const match = entry.match(/^round-(\d+)\.json$/);
|
|
134
|
-
return match ? { entry, round: Number.parseInt(match[1], 10) } : undefined;
|
|
135
|
-
})
|
|
136
|
-
.filter((entry) => Boolean(entry))
|
|
137
|
-
.sort((a, b) => b.round - a.round);
|
|
138
|
-
for (const { entry } of roundFiles) {
|
|
139
|
-
try {
|
|
140
|
-
const parsed = JSON.parse(await readFile(path.join(paths.reviewDir, entry), "utf-8"));
|
|
141
|
-
if (parsed.action === "pi-review" && parsed.structured) {
|
|
142
|
-
return parsed;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch {
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
151
|
-
export async function runLoopPiReview(repoRoot, taskId, options = {}) {
|
|
152
|
-
const provider = options.provider ?? DEFAULT_PI_PROVIDER;
|
|
153
|
-
const model = options.model ?? DEFAULT_PI_MODEL;
|
|
154
|
-
const timeoutMs = options.timeoutMs ?? 300_000;
|
|
155
|
-
const cwd = options.cwd ? path.resolve(repoRoot, options.cwd) : repoRoot;
|
|
156
|
-
const executor = options.executor ?? defaultPiReviewExecutor;
|
|
157
|
-
const rounds = await readLoopRounds(repoRoot, taskId);
|
|
158
|
-
const round = rounds.length + 1;
|
|
159
|
-
const paths = getLoopPaths(repoRoot, taskId);
|
|
160
|
-
const prompt = await buildLoopPiReviewPrompt(repoRoot, taskId);
|
|
161
|
-
const promptPath = path.join(paths.reviewDir, `round-${round}-prompt.md`);
|
|
162
|
-
await writeLoopPiReviewPrompt(repoRoot, taskId, round, prompt);
|
|
163
|
-
const result = await executor({
|
|
164
|
-
prompt,
|
|
165
|
-
cwd,
|
|
166
|
-
provider,
|
|
167
|
-
model,
|
|
168
|
-
timeoutMs,
|
|
169
|
-
toolNames: PI_REVIEW_TOOLS,
|
|
170
|
-
});
|
|
171
|
-
let structured;
|
|
172
|
-
let ok = result.ok;
|
|
173
|
-
let failureCategory = result.failureCategory ?? "";
|
|
174
|
-
try {
|
|
175
|
-
structured = parsePiReviewStructuredOutput(result.assistantText);
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
ok = false;
|
|
179
|
-
failureCategory = "invalid-structured-output";
|
|
180
|
-
structured = {
|
|
181
|
-
findingSummary: error instanceof Error ? error.message : "pi-review output parse failed",
|
|
182
|
-
failureCategory,
|
|
183
|
-
nextHypothesis: "rerun pi-review with a stricter structured-output prompt",
|
|
184
|
-
recommendedAction: "pause",
|
|
185
|
-
fixScope: ["unknown"],
|
|
186
|
-
rootCause: "invalid pi-review structured output",
|
|
187
|
-
invariant: "do not write until review output is valid",
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
const targetLifecycle = ok ? "completed" : "failed";
|
|
191
|
-
const runBaseName = `${new Date().toISOString().slice(0, 10)}-${taskId}-pi-review-r${round}`;
|
|
192
|
-
const activeRunDir = await createOneShotActiveRunDir(repoRoot, runBaseName);
|
|
193
|
-
const runId = path.basename(activeRunDir);
|
|
194
|
-
const runMarkdown = [
|
|
195
|
-
"# Pi Review Run",
|
|
196
|
-
"",
|
|
197
|
-
"| Field | Value |",
|
|
198
|
-
"|---|---|",
|
|
199
|
-
`| taskId | ${taskId} |`,
|
|
200
|
-
`| status | ${ok ? "completed" : "failed"} |`,
|
|
201
|
-
`| provider | ${provider} |`,
|
|
202
|
-
`| model | ${model} |`,
|
|
203
|
-
`| tools | ${PI_REVIEW_TOOLS.join(",")} |`,
|
|
204
|
-
`| prompt | ${relativeRef(repoRoot, promptPath)} |`,
|
|
205
|
-
"",
|
|
206
|
-
"## Structured Output",
|
|
207
|
-
"",
|
|
208
|
-
"```json",
|
|
209
|
-
JSON.stringify(structured, null, 2),
|
|
210
|
-
"```",
|
|
211
|
-
"",
|
|
212
|
-
"## Assistant Text Summary",
|
|
213
|
-
"",
|
|
214
|
-
truncateSummary(result.assistantText || result.stderr || ""),
|
|
215
|
-
"",
|
|
216
|
-
].join("\n");
|
|
217
|
-
await writeOneShotRunMarkdown(repoRoot, activeRunDir, runMarkdown);
|
|
218
|
-
await writeOneShotRunMeta(repoRoot, activeRunDir, {
|
|
219
|
-
runId,
|
|
220
|
-
taskId,
|
|
221
|
-
status: ok ? "completed" : "failed",
|
|
222
|
-
model,
|
|
223
|
-
provider,
|
|
224
|
-
channel: "pi-review",
|
|
225
|
-
cwd,
|
|
226
|
-
durationMs: result.durationMs,
|
|
227
|
-
failureCategory,
|
|
228
|
-
toolNames: PI_REVIEW_TOOLS,
|
|
229
|
-
logPath: "run.md",
|
|
230
|
-
});
|
|
231
|
-
const targetRunDir = targetLifecycle === "completed"
|
|
232
|
-
? await transferOneShotRunToCompleted(repoRoot, activeRunDir, runId)
|
|
233
|
-
: await transferOneShotRunToFailed(repoRoot, activeRunDir, runId);
|
|
234
|
-
const runRef = relativeRef(repoRoot, path.join(targetRunDir, "run.md"));
|
|
235
|
-
const record = {
|
|
236
|
-
schemaVersion: 1,
|
|
237
|
-
taskId,
|
|
238
|
-
round,
|
|
239
|
-
action: "pi-review",
|
|
240
|
-
ok,
|
|
241
|
-
provider,
|
|
242
|
-
model,
|
|
243
|
-
toolNames: PI_REVIEW_TOOLS,
|
|
244
|
-
promptPath: relativeRef(repoRoot, promptPath),
|
|
245
|
-
runRef,
|
|
246
|
-
structured,
|
|
247
|
-
assistantTextSummary: truncateSummary(result.assistantText || result.stderr || ""),
|
|
248
|
-
failureCategory,
|
|
249
|
-
recordedAt: new Date().toISOString(),
|
|
250
|
-
};
|
|
251
|
-
await writeLoopPiReviewRecord(repoRoot, taskId, round, record);
|
|
252
|
-
await appendLoopRound(repoRoot, taskId, {
|
|
253
|
-
action: "pi-review",
|
|
254
|
-
refs: [runRef, relativeRef(repoRoot, path.join(paths.reviewDir, `round-${round}.json`))],
|
|
255
|
-
result: ok ? "pi review completed" : "pi review failed",
|
|
256
|
-
verification: ok
|
|
257
|
-
? `pi-review structured output: ${structured.findingSummary}`
|
|
258
|
-
: `pi-review failed: ${structured.findingSummary}`,
|
|
259
|
-
lesson: structured.findingSummary,
|
|
260
|
-
next: structured.recommendedAction,
|
|
261
|
-
decision: "continue",
|
|
262
|
-
failureCategory: structured.failureCategory,
|
|
263
|
-
completedCriteria: ok ? ["pi read-only review action executed"] : [],
|
|
264
|
-
});
|
|
265
|
-
await rewriteLoopContext(repoRoot, taskId);
|
|
266
|
-
return record;
|
|
267
|
-
}
|