@tea-agent/loop-agent 0.52.0-next.1 → 0.52.0-next.2
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 +67 -21
- 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/shared/operator/capabilities.js +0 -122
- package/dist/shared/update/npm-client.js +14 -3
- package/dist/task/config-types.js +5 -10
- package/dist/task/read-model.js +0 -4
- package/dist/task/runtime.js +0 -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/chat-event-projection.js +2 -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/pi-runtime/custom-tools/apiworkbench-tools.js +65 -3
- package/dist/worker/console/chat/pi-runtime/sdk-bindings.js +4 -0
- package/dist/worker/console/chat/pi-runtime.js +238 -89
- 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 +295 -25
- package/dist/worker/console/chat/subagents/jobs.js +115 -4
- package/dist/worker/console/chat/terminal-sessions.js +27 -2
- package/dist/worker/console/chat/tool-exposure-catalog.js +1 -1
- package/dist/worker/console/chat/tool-preview.js +22 -0
- package/dist/worker/console/chat/turn-process.js +52 -0
- package/dist/worker/console/chat/vcp-prompt.js +14 -9
- package/dist/worker/console/chat/workspace-changes.js +137 -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/routes.js +1 -1
- package/dist/worker/console/server.js +89 -5
- package/dist/worker/console/static/assets/FilePreviewDocx-ybM3ZqSl.js +9 -0
- package/dist/worker/console/static/assets/abnfDiagram-N423BO3Z-BJkTFDSU.js +1 -0
- package/dist/worker/console/static/assets/{arc-Bkf_oc0_.js → arc-BJoqB-FK.js} +1 -1
- package/dist/worker/console/static/assets/architectureDiagram-T3A2C74G-Dnks_tKL.js +36 -0
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-D62uVvbI.js → blockDiagram-VBNYF7ZC-CYfXZ-MS.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-Iq0Y8Afx.js → c4Diagram-5PPSVZJV-C8QUVTzH.js} +1 -1
- package/dist/worker/console/static/assets/channel-gvXtLBqv.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-D1TxRE3k.js → chunk-2GRJ4B5K-BeQTq_mP.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-BE-DHkAO.js → chunk-2Q5K7J3B-Cz8TULTz.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-t0iYO8Cc.js → chunk-5RXB4S5H-DTGsDFfs.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-Clo2nExi.js → chunk-5VM5RSS4-D3xtdDtx.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-C7bSpo-3.js → chunk-6Q2QTUOP-CFcH1dmG.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-DorZaymh.js → chunk-GF5L2VYU-D1oWTPzh.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-Ch_4HvyJ.js → chunk-JWPE2WC7-DQ1784gP.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-yaSoFe-3.js → chunk-KBJHAD2P-BUa9gwx1.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-QpjaXecS.js → chunk-RYQCIY6F-u-ANrNSL.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-B3t6cycg.js → chunk-XXDRQBXY-Daj0bhib.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DQ5hdEfB.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DQ5hdEfB.js +1 -0
- package/dist/worker/console/static/assets/cose-bilkent-JH36ORCC-Bk1oZEJ1.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-C4Ev_fka.js +62 -0
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BK0ua9V8.js → dagre-VZM6K2ZE-D0n24UDZ.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-t9-HP13j.js → diagram-7IWD3JNH-C1FlRrys.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-L5Sg9jMD.js → diagram-B4RE2ZJO-CWpeId5Y.js} +1 -1
- package/dist/worker/console/static/assets/diagram-LBJQPF4R-CeEU1CTn.js +24 -0
- package/dist/worker/console/static/assets/diagram-Q27KOJAE-DgpFxfNH.js +24 -0
- package/dist/worker/console/static/assets/diagram-UB23O5K3--9JrEf2p.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-D7E9C_OC.js +1 -0
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-CNOuj3BO.js → erDiagram-JOGREHBK-OYp4ZJQC.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-h_Cyayai.js → flowDiagram-UKHOOZJN-Cyf8gGYJ.js} +1 -1
- package/dist/worker/console/static/assets/ganttDiagram-PKOTCBZU-B7gUfjoR.js +292 -0
- package/dist/worker/console/static/assets/gitGraphDiagram-DS77QQ5N-mirrpSLp.js +106 -0
- package/dist/worker/console/static/assets/infoDiagram-6WML65LV-gRb5KI0B.js +2 -0
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-DAdf5lHp.js → ishikawaDiagram-WSZJBQD7-v3JGPZ1t.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-BQbGtg66.js → journeyDiagram-NVQOT4AX-jJLc06Q0.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-CetLubYc.js → kanban-definition-27J2QSJJ-BJ7qkdrx.js} +1 -1
- package/dist/worker/console/static/assets/{linear-DLZOjaVz.js → linear-B8iMATOq.js} +1 -1
- package/dist/worker/console/static/assets/main-BA6TGEgV.js +644 -0
- package/dist/worker/console/static/assets/main-BWBC5cML.css +1 -0
- package/dist/worker/console/static/assets/{mermaid.core-B_xZl_gM.js → mermaid.core-C-6iih3_.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-Dzo3dzp0.js → mindmap-definition-FAOFIHXS-kUxtuaLJ.js} +1 -1
- package/dist/worker/console/static/assets/pegDiagram-VL7TDLO6-CWscAnG2.js +1 -0
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-Cp3YrVzQ.js → pieDiagram-7S7Q4E2Y-B4P97R-G.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-4tI5mUgW.js → quadrantDiagram-CIZ2JOQS-TK_kx3AZ.js} +1 -1
- package/dist/worker/console/static/assets/railroadDiagram-AXF67PYL-BvoUgYhv.js +1 -0
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-DY-0JqdT.js → requirementDiagram-LRYGKXZP-DD-OVcGf.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-DuJIzRKC.js → sankeyDiagram-W5VNT64P-C_d-co8f.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-BTbVJ85l.js → sequenceDiagram-SI44F4Z6-DEDF0c92.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-BPPh1uLw.js → sheet-workbook-BI2AD1uG.js} +2 -2
- package/dist/worker/console/static/assets/sizeCapture-X5ZJPWSS-C9N-yQxX.js +1 -0
- package/dist/worker/console/static/assets/stateDiagram-OKZ733FA-BXgVo9RE.js +1 -0
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-CPyYpg4o.js +1 -0
- package/dist/worker/console/static/assets/swimlanes-SLNWSIFB-DsJnGMMG.js +2 -0
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BECT1jaq.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-GR6lxokn.js → timeline-definition-Z64GVDOM-BHQjX5sj.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-DEkwyzsF.js → vennDiagram-T6HMQDX7-Cq_lSjge.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-W5jnvEJ3.js → wardleyDiagram-T6FBY63Y-BEX8BDY-.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-cqsloioo.js → xychartDiagram-ELKLHX3M-BTyfZdAf.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/chat-sse-events.js +8 -1
- 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/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/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/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 +5 -3
- package/resource-catalog.v1.json +6 -6
- 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
|
@@ -71,9 +71,9 @@ export const UNVIEWABLE_BINARY_EXTENSIONS = [
|
|
|
71
71
|
"tar",
|
|
72
72
|
"jar",
|
|
73
73
|
// office documents without a renderer — `key` stays out: it collides with
|
|
74
|
-
// readable key/credential text files. xls/xlsx are spreadsheets
|
|
74
|
+
// readable key/credential text files. xls/xlsx are spreadsheets and docx is
|
|
75
|
+
// the Word renderer, so neither belongs here.
|
|
75
76
|
"doc",
|
|
76
|
-
"docx",
|
|
77
77
|
"ppt",
|
|
78
78
|
"pptx",
|
|
79
79
|
"odt",
|
|
@@ -115,6 +115,9 @@ export const UNVIEWABLE_BINARY_EXTENSIONS = [
|
|
|
115
115
|
];
|
|
116
116
|
/** Spreadsheet suffixes rendered as a table (DSH excel renderer). */
|
|
117
117
|
export const SHEET_EXTENSIONS = ["xlsx", "xls", "csv", "tsv"];
|
|
118
|
+
/** Word suffixes rendered by the in-browser docx renderer. `.doc` stays out:
|
|
119
|
+
* the legacy binary format has no renderer and remains unsupported. */
|
|
120
|
+
export const DOCX_EXTENSIONS = ["docx"];
|
|
118
121
|
/** Workbook suffixes whose bytes are not readable text. CSV and TSV stay text. */
|
|
119
122
|
export const BINARY_SHEET_EXTENSIONS = ["xlsx", "xls"];
|
|
120
123
|
const SHEET_MEDIA_TYPES = {
|
|
@@ -135,6 +138,7 @@ const IMAGE_MEDIA_TYPES = {
|
|
|
135
138
|
};
|
|
136
139
|
const IMAGE_SUFFIX_SET = new Set(IMAGE_EXTENSIONS);
|
|
137
140
|
const SHEET_SUFFIX_SET = new Set(SHEET_EXTENSIONS);
|
|
141
|
+
const DOCX_SUFFIX_SET = new Set(DOCX_EXTENSIONS);
|
|
138
142
|
const UNVIEWABLE_SUFFIX_SET = new Set(UNVIEWABLE_BINARY_EXTENSIONS);
|
|
139
143
|
const UNVIEWABLE_FILENAME_SET = new Set(UNVIEWABLE_BINARY_FILENAMES);
|
|
140
144
|
/** The lowercased final path segment (DSH documentFileName). */
|
|
@@ -152,10 +156,10 @@ export function fileSuffixOf(path) {
|
|
|
152
156
|
return "";
|
|
153
157
|
return name.slice(dot + 1);
|
|
154
158
|
}
|
|
155
|
-
/** Classify a repo-relative path by its final extension: image, PDF,
|
|
156
|
-
* spreadsheet renderers first, then unviewable binary containers
|
|
157
|
-
* or, for extensionless dotfiles like `.DS_Store`, by full name),
|
|
158
|
-
* else text. */
|
|
159
|
+
/** Classify a repo-relative path by its final extension: image, PDF,
|
|
160
|
+
* spreadsheet, and Word renderers first, then unviewable binary containers
|
|
161
|
+
* (by suffix or, for extensionless dotfiles like `.DS_Store`, by full name),
|
|
162
|
+
* everything else text. */
|
|
159
163
|
export function classifyRepoPreview(path) {
|
|
160
164
|
const name = documentFileName(path);
|
|
161
165
|
if (UNVIEWABLE_FILENAME_SET.has(name))
|
|
@@ -166,6 +170,12 @@ export function classifyRepoPreview(path) {
|
|
|
166
170
|
}
|
|
167
171
|
if (suffix === "pdf")
|
|
168
172
|
return { kind: "pdf", mediaType: "application/pdf" };
|
|
173
|
+
if (DOCX_SUFFIX_SET.has(suffix)) {
|
|
174
|
+
return {
|
|
175
|
+
kind: "docx",
|
|
176
|
+
mediaType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
177
|
+
};
|
|
178
|
+
}
|
|
169
179
|
if (SHEET_SUFFIX_SET.has(suffix)) {
|
|
170
180
|
return {
|
|
171
181
|
kind: "sheet",
|
|
@@ -10,6 +10,8 @@ import { listBuiltinSubagentMetadata } from "./subagents/registry.js";
|
|
|
10
10
|
import { cleanChatTitle, isBlankChatSession } from "./session-store.js";
|
|
11
11
|
import { projectUserTurnOutline } from "./user-turn-outline.js";
|
|
12
12
|
import { hashChatTurnPayload, projectCompactSnapshot, } from "./chat-event-store.js";
|
|
13
|
+
import { fileToolPreview, toolRecord } from "./tool-presentation.js";
|
|
14
|
+
import { captureWorkspaceBaseline, captureWorkspaceChanges, fallbackWorkspaceChanges } from "./workspace-changes.js";
|
|
13
15
|
import { projectDeferredTurnSummary, projectDeferredTurnSummaries, } from "./deferred-turn.js";
|
|
14
16
|
import { THINKING_LEVELS, RuntimeSnapshotUnavailableError, } from "./pi-runtime.js";
|
|
15
17
|
import { ResourcePreferencesError, setSkillAutoInvocationPreference, } from "./resource-preferences-store.js";
|
|
@@ -47,7 +49,7 @@ import { handleBrowserRequest } from "./browser-routes.js";
|
|
|
47
49
|
import { handleApiWorkbenchRequest } from "./api-workbench.js";
|
|
48
50
|
import { DbConnectionError } from "./db-connections.js";
|
|
49
51
|
import { projectSubagentCatalog } from "./subagents/catalog.js";
|
|
50
|
-
import { listWorkspaceJobs, scopeWorkspaceJobs } from "./subagents/jobs.js";
|
|
52
|
+
import { listWorkspaceJobs, projectShellToolJobs, scopeWorkspaceJobs } from "./subagents/jobs.js";
|
|
51
53
|
function projectBrowserChatSession(record) {
|
|
52
54
|
const { telemetrySessionId, systemPromptSuffix, ...projected } = record;
|
|
53
55
|
void telemetrySessionId;
|
|
@@ -353,6 +355,65 @@ function ensureAgentEndEvent(deps, sessionId, turnId) {
|
|
|
353
355
|
});
|
|
354
356
|
}
|
|
355
357
|
}
|
|
358
|
+
function recordTurnFileMutation(event, fallbackToolPaths, fallbackFiles) {
|
|
359
|
+
if (event.type === "tool_call" && (event.toolName === "edit" || event.toolName === "write")) {
|
|
360
|
+
const args = toolRecord(event.args);
|
|
361
|
+
const path = typeof args?.path === "string" ? args.path : typeof args?.file_path === "string" ? args.file_path : "";
|
|
362
|
+
if (path && typeof event.toolCallId === "string") {
|
|
363
|
+
fallbackToolPaths.set(event.toolCallId, path);
|
|
364
|
+
}
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (event.type === "tool_result" && !event.isError && (event.toolName === "edit" || event.toolName === "write")) {
|
|
368
|
+
const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : "";
|
|
369
|
+
const rawPath = fallbackToolPaths.get(toolCallId) ?? "";
|
|
370
|
+
if (!rawPath)
|
|
371
|
+
return;
|
|
372
|
+
const display = rawPath.replace(/\\/g, "/");
|
|
373
|
+
const preview = fileToolPreview(event.result);
|
|
374
|
+
const added = preview?.added ?? 0;
|
|
375
|
+
const deleted = preview?.removed ?? 0;
|
|
376
|
+
const existing = fallbackFiles.get(display);
|
|
377
|
+
if (existing) {
|
|
378
|
+
existing.added += added;
|
|
379
|
+
existing.deleted += deleted;
|
|
380
|
+
if (existing.firstChangedLine === undefined && preview?.firstChangedLine !== undefined) {
|
|
381
|
+
existing.firstChangedLine = preview.firstChangedLine;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
fallbackFiles.set(display, {
|
|
386
|
+
path: rawPath,
|
|
387
|
+
display,
|
|
388
|
+
added,
|
|
389
|
+
deleted,
|
|
390
|
+
...(preview?.firstChangedLine !== undefined ? { firstChangedLine: preview.firstChangedLine } : {}),
|
|
391
|
+
status: event.toolName === "write" ? "added" : "modified",
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async function resolveTurnWorkspaceChanges(input) {
|
|
397
|
+
const toolFiles = [...input.fallbackFiles.values()];
|
|
398
|
+
if (input.workspaceBaseline) {
|
|
399
|
+
const snapshot = await captureWorkspaceChanges({
|
|
400
|
+
baseline: input.workspaceBaseline,
|
|
401
|
+
sessionId: input.sessionId,
|
|
402
|
+
turnId: input.turnId,
|
|
403
|
+
turnNumber: input.turnNumber,
|
|
404
|
+
failedTurn: input.failedTurn,
|
|
405
|
+
toolFiles,
|
|
406
|
+
}).catch(() => undefined);
|
|
407
|
+
if (snapshot)
|
|
408
|
+
return snapshot;
|
|
409
|
+
}
|
|
410
|
+
return fallbackWorkspaceChanges({
|
|
411
|
+
sessionId: input.sessionId,
|
|
412
|
+
turnId: input.turnId,
|
|
413
|
+
files: toolFiles,
|
|
414
|
+
failedTurn: input.failedTurn,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
356
417
|
async function readJsonBody(req, maxBytes = 2 * 1024 * 1024) {
|
|
357
418
|
// AC-R5-003: the multi-workspace dispatcher (server.ts readBodyOnce)
|
|
358
419
|
// pre-reads and JSON-parses the body for workspaceId resolution, stashing
|
|
@@ -1011,8 +1072,100 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1011
1072
|
const messagePage = await deps.store.listMessages(sessionId, { limit: 50 });
|
|
1012
1073
|
const composerDraftSnapshot = await new ComposerDraftStore(deps.appData).getDraft(sessionId);
|
|
1013
1074
|
const composerDraft = composerDraftSnapshot.text;
|
|
1014
|
-
|
|
1015
|
-
const
|
|
1075
|
+
// P2-A: projection checkpoint / baseline optimization
|
|
1076
|
+
const currentEpoch = deps.events.epoch(sessionId);
|
|
1077
|
+
const existingCheckpoint = deps.events.getCheckpoint?.(sessionId);
|
|
1078
|
+
const minSeq = deps.events.minSeq?.(sessionId) ?? 1;
|
|
1079
|
+
const isCheckpointValid = existingCheckpoint &&
|
|
1080
|
+
existingCheckpoint.schemaVersion === 1 &&
|
|
1081
|
+
existingCheckpoint.sessionId === sessionId &&
|
|
1082
|
+
existingCheckpoint.eventEpoch === currentEpoch &&
|
|
1083
|
+
existingCheckpoint.asOfSeq >= minSeq;
|
|
1084
|
+
let snapshot;
|
|
1085
|
+
let telemetry;
|
|
1086
|
+
let turnTelemetry;
|
|
1087
|
+
let workspaceChanges;
|
|
1088
|
+
let todos;
|
|
1089
|
+
let compactions;
|
|
1090
|
+
let asOfSeq;
|
|
1091
|
+
if (isCheckpointValid) {
|
|
1092
|
+
const incremental = deps.events.snapshot(sessionId, { afterSeq: existingCheckpoint.asOfSeq });
|
|
1093
|
+
if (incremental.length === 0) {
|
|
1094
|
+
snapshot = deps.events.snapshot(sessionId);
|
|
1095
|
+
telemetry = existingCheckpoint.telemetry;
|
|
1096
|
+
turnTelemetry = existingCheckpoint.turnTelemetry;
|
|
1097
|
+
workspaceChanges = existingCheckpoint.workspaceChanges;
|
|
1098
|
+
todos = existingCheckpoint.todos;
|
|
1099
|
+
compactions = existingCheckpoint.compactions;
|
|
1100
|
+
asOfSeq = existingCheckpoint.asOfSeq;
|
|
1101
|
+
}
|
|
1102
|
+
else {
|
|
1103
|
+
snapshot = deps.events.snapshot(sessionId);
|
|
1104
|
+
telemetry = deriveChatSessionTelemetry(snapshot);
|
|
1105
|
+
turnTelemetry = deriveChatTurnTelemetry(snapshot);
|
|
1106
|
+
workspaceChanges = snapshot.filter((event) => event.kind === "workspace_changes").map((event) => event.data);
|
|
1107
|
+
todos = projectCurrentTodos(snapshot) ?? [];
|
|
1108
|
+
compactions = snapshot
|
|
1109
|
+
.filter((event) => event.kind === "compact" ||
|
|
1110
|
+
event.kind === "compaction_start" ||
|
|
1111
|
+
event.kind === "compaction_end")
|
|
1112
|
+
.map((event) => ({
|
|
1113
|
+
eventId: event.eventId,
|
|
1114
|
+
kind: event.kind,
|
|
1115
|
+
at: event.at,
|
|
1116
|
+
seq: event.seq,
|
|
1117
|
+
turnId: event.turnId,
|
|
1118
|
+
data: event.data,
|
|
1119
|
+
}));
|
|
1120
|
+
asOfSeq = snapshot.at(-1)?.seq ?? existingCheckpoint.asOfSeq;
|
|
1121
|
+
deps.events.setCheckpoint?.(sessionId, {
|
|
1122
|
+
schemaVersion: 1,
|
|
1123
|
+
sessionId,
|
|
1124
|
+
eventEpoch: currentEpoch,
|
|
1125
|
+
asOfSeq,
|
|
1126
|
+
createdAt: new Date().toISOString(),
|
|
1127
|
+
telemetry,
|
|
1128
|
+
turnTelemetry,
|
|
1129
|
+
turnStates: [],
|
|
1130
|
+
workspaceChanges,
|
|
1131
|
+
todos: todos ?? [],
|
|
1132
|
+
compactions,
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
else {
|
|
1137
|
+
snapshot = deps.events.snapshot(sessionId);
|
|
1138
|
+
telemetry = deriveChatSessionTelemetry(snapshot);
|
|
1139
|
+
turnTelemetry = deriveChatTurnTelemetry(snapshot);
|
|
1140
|
+
workspaceChanges = snapshot.filter((event) => event.kind === "workspace_changes").map((event) => event.data);
|
|
1141
|
+
todos = projectCurrentTodos(snapshot) ?? [];
|
|
1142
|
+
compactions = snapshot
|
|
1143
|
+
.filter((event) => event.kind === "compact" ||
|
|
1144
|
+
event.kind === "compaction_start" ||
|
|
1145
|
+
event.kind === "compaction_end")
|
|
1146
|
+
.map((event) => ({
|
|
1147
|
+
eventId: event.eventId,
|
|
1148
|
+
kind: event.kind,
|
|
1149
|
+
at: event.at,
|
|
1150
|
+
seq: event.seq,
|
|
1151
|
+
turnId: event.turnId,
|
|
1152
|
+
data: event.data,
|
|
1153
|
+
}));
|
|
1154
|
+
asOfSeq = snapshot.at(-1)?.seq ?? 0;
|
|
1155
|
+
deps.events.setCheckpoint?.(sessionId, {
|
|
1156
|
+
schemaVersion: 1,
|
|
1157
|
+
sessionId,
|
|
1158
|
+
eventEpoch: currentEpoch,
|
|
1159
|
+
asOfSeq,
|
|
1160
|
+
createdAt: new Date().toISOString(),
|
|
1161
|
+
telemetry,
|
|
1162
|
+
turnTelemetry,
|
|
1163
|
+
turnStates: [],
|
|
1164
|
+
workspaceChanges,
|
|
1165
|
+
todos: todos ?? [],
|
|
1166
|
+
compactions,
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1016
1169
|
const lastEvent = snapshot.at(-1);
|
|
1017
1170
|
const activeTurn = deps.events.getActiveTurn(sessionId);
|
|
1018
1171
|
const pendingQuestion = await deps.questionRegistry?.get(sessionId);
|
|
@@ -1026,7 +1179,12 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1026
1179
|
]);
|
|
1027
1180
|
sendJson(res, 200, {
|
|
1028
1181
|
ok: true,
|
|
1029
|
-
eventEpoch:
|
|
1182
|
+
eventEpoch: currentEpoch,
|
|
1183
|
+
checkpoint: {
|
|
1184
|
+
schemaVersion: 1,
|
|
1185
|
+
eventEpoch: currentEpoch,
|
|
1186
|
+
asOfSeq,
|
|
1187
|
+
},
|
|
1030
1188
|
subagents: await subagentCatalogFor(deps, sessionId, record.messages),
|
|
1031
1189
|
session: {
|
|
1032
1190
|
...projectBrowserChatSession(record),
|
|
@@ -1043,7 +1201,8 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1043
1201
|
: "running"
|
|
1044
1202
|
: "idle",
|
|
1045
1203
|
pendingQuestion: pendingQuestion ?? null,
|
|
1046
|
-
todos:
|
|
1204
|
+
todos: todos ?? [],
|
|
1205
|
+
workspaceChanges,
|
|
1047
1206
|
...(deps.goalRegistry?.read(sessionId) ?? { goalStatus: "absent", goal: null }),
|
|
1048
1207
|
},
|
|
1049
1208
|
history: {
|
|
@@ -1053,7 +1212,7 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1053
1212
|
hasBash: true,
|
|
1054
1213
|
sessionStats: telemetry.stats,
|
|
1055
1214
|
usage: telemetry.usage,
|
|
1056
|
-
turnTelemetry
|
|
1215
|
+
turnTelemetry,
|
|
1057
1216
|
requestDetails: (deps.events.listRequestDetails?.(sessionId) ?? []).map(projectRequestSummary),
|
|
1058
1217
|
userTurnOutline: projectUserTurnOutline(record.messages ?? []),
|
|
1059
1218
|
...(sddSessionIdentity
|
|
@@ -1062,18 +1221,7 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1062
1221
|
contextPressure: typeof deps.runtime.getContextPressureTelemetry === "function"
|
|
1063
1222
|
? deps.runtime.getContextPressureTelemetry(sessionId)
|
|
1064
1223
|
: undefined,
|
|
1065
|
-
compactions
|
|
1066
|
-
.filter((event) => event.kind === "compact" ||
|
|
1067
|
-
event.kind === "compaction_start" ||
|
|
1068
|
-
event.kind === "compaction_end")
|
|
1069
|
-
.map((event) => ({
|
|
1070
|
-
eventId: event.eventId,
|
|
1071
|
-
kind: event.kind,
|
|
1072
|
-
at: event.at,
|
|
1073
|
-
seq: event.seq,
|
|
1074
|
-
turnId: event.turnId,
|
|
1075
|
-
data: event.data,
|
|
1076
|
-
})),
|
|
1224
|
+
compactions,
|
|
1077
1225
|
conversationEvents: snapshot.filter((event) => [
|
|
1078
1226
|
"step_start",
|
|
1079
1227
|
"step_end",
|
|
@@ -1684,13 +1832,20 @@ function flattenSubagentCatalogItems(items) {
|
|
|
1684
1832
|
export async function listWorkspaceSubagentTasks(deps, workspaceScope) {
|
|
1685
1833
|
const sessions = await deps.store.list({ includeArchived: true });
|
|
1686
1834
|
const diagnostics = [];
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
:
|
|
1693
|
-
|
|
1835
|
+
// Terminal sessions are a first-class job source: they are the live
|
|
1836
|
+
// long-running commands the reader watches, and the terminal registry is
|
|
1837
|
+
// process-scoped (not repo-scoped), so it answers even with no appData.
|
|
1838
|
+
const terminalSessions = deps.terminals?.list() ?? [];
|
|
1839
|
+
const availableJobs = await listWorkspaceJobs(deps.appData?.repoRoot ?? "", terminalSessions, workspaceScope).catch((error) => {
|
|
1840
|
+
diagnostics.push(`jobs: ${error instanceof Error ? error.message : String(error)}`);
|
|
1841
|
+
return [];
|
|
1842
|
+
});
|
|
1843
|
+
// Shell tool calls from THIS workspace's sessions are the rows DSH shows
|
|
1844
|
+
// (`pshw npm run …`). They are projected from each ring's retained tail.
|
|
1845
|
+
const shellJobs = sessions
|
|
1846
|
+
.filter((session) => session.workspaceId === workspaceScope)
|
|
1847
|
+
.flatMap((session) => projectShellToolJobs(deps.events?.snapshot(session.sessionId) ?? [], session.sessionId, workspaceScope));
|
|
1848
|
+
const scopedJobs = scopeWorkspaceJobs([...shellJobs, ...availableJobs], workspaceScope);
|
|
1694
1849
|
if (scopedJobs.omitted > 0)
|
|
1695
1850
|
diagnostics.push(`${scopedJobs.omitted} scheduler jobs omitted: workspace ownership unavailable or mismatched`);
|
|
1696
1851
|
const taskGroups = await Promise.all(sessions
|
|
@@ -1962,6 +2117,67 @@ export async function handleStopChatSubagent(req, res, deps, parentSessionId, ch
|
|
|
1962
2117
|
const responseChild = latest ?? child;
|
|
1963
2118
|
sendJson(res, 202, { ok: true, accepted: true, cleanupPending: responseChild.finishedAt === undefined, child: responseChild, continuation: subagentContinuation(deps, parentSessionId, responseChild) });
|
|
1964
2119
|
}
|
|
2120
|
+
export async function handleStopWorkspaceSubagent(req, res, deps, childSessionId) {
|
|
2121
|
+
const gate = gateMutation(req, deps);
|
|
2122
|
+
if (!gate.ok) {
|
|
2123
|
+
sendJson(res, gate.status, { ok: false, accepted: false, error: { code: gate.code, message: gate.message } });
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
const child = await deps.subagents?.get(childSessionId).catch(() => undefined);
|
|
2127
|
+
if (!child) {
|
|
2128
|
+
sendJson(res, 404, { ok: false, accepted: false, error: { code: "SUBAGENT_NOT_FOUND", message: "subagent not found" } });
|
|
2129
|
+
return;
|
|
2130
|
+
}
|
|
2131
|
+
await handleStopChatSubagent(req, res, deps, child.parentSessionId, childSessionId);
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Terminate one background job.
|
|
2135
|
+
*
|
|
2136
|
+
* DSH's drawer terminates a row with `jobs.kill(ownerSessionId, jobId)` behind a
|
|
2137
|
+
* two-click confirm. Loop's jobs come from two surfaces, and only one of them
|
|
2138
|
+
* has a process to kill:
|
|
2139
|
+
*
|
|
2140
|
+
* - a TERMINAL session (the registry's own `kill()`), and
|
|
2141
|
+
* - a shell tool call that is still running.
|
|
2142
|
+
*
|
|
2143
|
+
* A settled shell call is a historical fact — there is nothing to terminate, so
|
|
2144
|
+
* it is refused explicitly rather than pretending to succeed. The client never
|
|
2145
|
+
* offers the control for those rows (it is `status === "running"` only, exactly
|
|
2146
|
+
* as DSH gates it).
|
|
2147
|
+
*/
|
|
2148
|
+
export async function handleStopWorkspaceJob(req, res, deps, jobId) {
|
|
2149
|
+
const gate = gateMutation(req, deps);
|
|
2150
|
+
if (!gate.ok) {
|
|
2151
|
+
sendJson(res, gate.status, { ok: false, accepted: false, error: { code: gate.code, message: gate.message } });
|
|
2152
|
+
return;
|
|
2153
|
+
}
|
|
2154
|
+
// A terminal session id IS the job id for terminal-backed rows.
|
|
2155
|
+
const terminals = deps.terminals;
|
|
2156
|
+
if (terminals) {
|
|
2157
|
+
const session = terminals.list().find((candidate) => candidate.sessionId === jobId);
|
|
2158
|
+
if (session) {
|
|
2159
|
+
if (session.exited) {
|
|
2160
|
+
sendJson(res, 409, {
|
|
2161
|
+
ok: false,
|
|
2162
|
+
accepted: false,
|
|
2163
|
+
error: { code: "JOB_ALREADY_SETTLED", message: "任务已结束,无需终止" },
|
|
2164
|
+
});
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
await terminals.kill(session.sessionId);
|
|
2168
|
+
sendJson(res, 200, { ok: true, accepted: true, jobId: session.sessionId, status: "killed" });
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
sendJson(res, 404, {
|
|
2173
|
+
ok: false,
|
|
2174
|
+
accepted: false,
|
|
2175
|
+
error: {
|
|
2176
|
+
code: "JOB_NOT_TERMINABLE",
|
|
2177
|
+
message: "该任务不是运行中的终端会话,无法终止",
|
|
2178
|
+
},
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
1965
2181
|
export async function handlePromptChatSubagent(req, res, deps, parentSessionId, childSessionId) {
|
|
1966
2182
|
const gate = gateMutation(req, deps);
|
|
1967
2183
|
if (!gate.ok) {
|
|
@@ -2326,6 +2542,7 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2326
2542
|
return;
|
|
2327
2543
|
}
|
|
2328
2544
|
const turnId = createdTurn.turn.turnId;
|
|
2545
|
+
const workspaceBaseline = await captureWorkspaceBaseline(deps.appData.repoRoot).catch(() => undefined);
|
|
2329
2546
|
deps.events.setTurnState(sessionId, turnId, "running");
|
|
2330
2547
|
// Stream events via SSE. Each event is FIRST persisted to the chat event
|
|
2331
2548
|
// ring (so a reconnect via GET /events can resume by Last-Event-ID), THEN
|
|
@@ -2346,6 +2563,8 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2346
2563
|
// Lazily import to avoid circular module load.
|
|
2347
2564
|
const { runChatTurn } = await import("./session-store.js");
|
|
2348
2565
|
let firstUserText;
|
|
2566
|
+
const fallbackFiles = new Map();
|
|
2567
|
+
const fallbackToolPaths = new Map();
|
|
2349
2568
|
try {
|
|
2350
2569
|
const outcome = await runChatTurn({
|
|
2351
2570
|
runtime: deps.runtime,
|
|
@@ -2405,6 +2624,7 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2405
2624
|
return;
|
|
2406
2625
|
}
|
|
2407
2626
|
recordRequestEventFact(deps, sessionId, turnId, event);
|
|
2627
|
+
recordTurnFileMutation(event, fallbackToolPaths, fallbackFiles);
|
|
2408
2628
|
const partial = turnEventToStorePartial(event);
|
|
2409
2629
|
if (!partial)
|
|
2410
2630
|
return;
|
|
@@ -2413,7 +2633,23 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2413
2633
|
writeChatSse(res, persisted);
|
|
2414
2634
|
},
|
|
2415
2635
|
});
|
|
2636
|
+
const appendWorkspaceChanges = async (failedTurn) => {
|
|
2637
|
+
const summary = await resolveTurnWorkspaceChanges({
|
|
2638
|
+
workspaceBaseline,
|
|
2639
|
+
sessionId,
|
|
2640
|
+
turnId,
|
|
2641
|
+
turnNumber: createdTurn.turn.ordinal,
|
|
2642
|
+
fallbackFiles,
|
|
2643
|
+
failedTurn,
|
|
2644
|
+
});
|
|
2645
|
+
if (!summary)
|
|
2646
|
+
return;
|
|
2647
|
+
const persisted = deps.events.append(sessionId, turnId, { kind: "workspace_changes", data: summary });
|
|
2648
|
+
if (!res.writableEnded)
|
|
2649
|
+
writeChatSse(res, persisted);
|
|
2650
|
+
};
|
|
2416
2651
|
if (abortedByClient || ac.signal.aborted) {
|
|
2652
|
+
await appendWorkspaceChanges(true);
|
|
2417
2653
|
ensureAgentEndEvent(deps, sessionId, turnId);
|
|
2418
2654
|
deps.events.setTurnState(sessionId, turnId, "aborted", {
|
|
2419
2655
|
code: "CLIENT_ABORTED",
|
|
@@ -2421,6 +2657,7 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2421
2657
|
});
|
|
2422
2658
|
}
|
|
2423
2659
|
else {
|
|
2660
|
+
await appendWorkspaceChanges(!outcome.ok);
|
|
2424
2661
|
ensureAgentEndEvent(deps, sessionId, turnId);
|
|
2425
2662
|
deps.events.setTurnState(sessionId, turnId, outcome.ok ? "settled" : "failed", outcome.error);
|
|
2426
2663
|
if (outcome.ok && firstUserText)
|
|
@@ -2434,6 +2671,21 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2434
2671
|
// stream is already open. Persist + emit an error event so a reconnecting
|
|
2435
2672
|
// client also sees the failure (not just the original requester).
|
|
2436
2673
|
const message = error instanceof Error ? error.message : String(error);
|
|
2674
|
+
{
|
|
2675
|
+
const summary = await resolveTurnWorkspaceChanges({
|
|
2676
|
+
workspaceBaseline,
|
|
2677
|
+
sessionId,
|
|
2678
|
+
turnId,
|
|
2679
|
+
turnNumber: createdTurn.turn.ordinal,
|
|
2680
|
+
fallbackFiles,
|
|
2681
|
+
failedTurn: true,
|
|
2682
|
+
});
|
|
2683
|
+
if (summary) {
|
|
2684
|
+
const persisted = deps.events.append(sessionId, turnId, { kind: "workspace_changes", data: summary });
|
|
2685
|
+
if (!res.writableEnded)
|
|
2686
|
+
writeChatSse(res, persisted);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2437
2689
|
ensureAgentEndEvent(deps, sessionId, turnId);
|
|
2438
2690
|
deps.events.setTurnState(sessionId, turnId, abortedByClient || ac.signal.aborted ? "aborted" : "failed", {
|
|
2439
2691
|
code: abortedByClient || ac.signal.aborted
|
|
@@ -2682,6 +2934,21 @@ export async function handleCreateChatTurn(req, res, deps, sessionId, trustedPay
|
|
|
2682
2934
|
// Abort ownership lives in the execution registry (real Stop path).
|
|
2683
2935
|
void (async () => {
|
|
2684
2936
|
const { runChatTurn } = await import("./session-store.js");
|
|
2937
|
+
const workspaceBaseline = await captureWorkspaceBaseline(deps.appData.repoRoot).catch(() => undefined);
|
|
2938
|
+
const fallbackFiles = new Map();
|
|
2939
|
+
const fallbackToolPaths = new Map();
|
|
2940
|
+
const appendWorkspaceChanges = async (failedTurn) => {
|
|
2941
|
+
const summary = await resolveTurnWorkspaceChanges({
|
|
2942
|
+
workspaceBaseline,
|
|
2943
|
+
sessionId,
|
|
2944
|
+
turnId: turn.turnId,
|
|
2945
|
+
turnNumber: turn.ordinal,
|
|
2946
|
+
fallbackFiles,
|
|
2947
|
+
failedTurn,
|
|
2948
|
+
});
|
|
2949
|
+
if (summary)
|
|
2950
|
+
deps.events.append(sessionId, turn.turnId, { kind: "workspace_changes", data: summary });
|
|
2951
|
+
};
|
|
2685
2952
|
let firstUserText;
|
|
2686
2953
|
let terminalState = "failed";
|
|
2687
2954
|
let terminalError;
|
|
@@ -2725,11 +2992,13 @@ export async function handleCreateChatTurn(req, res, deps, sessionId, trustedPay
|
|
|
2725
2992
|
if (event.type === "heartbeat")
|
|
2726
2993
|
return;
|
|
2727
2994
|
recordRequestEventFact(deps, sessionId, turn.turnId, event);
|
|
2995
|
+
recordTurnFileMutation(event, fallbackToolPaths, fallbackFiles);
|
|
2728
2996
|
const partial = turnEventToStorePartial(event);
|
|
2729
2997
|
if (partial)
|
|
2730
2998
|
deps.events.append(sessionId, turn.turnId, partial);
|
|
2731
2999
|
},
|
|
2732
3000
|
});
|
|
3001
|
+
await appendWorkspaceChanges(controller.signal.aborted || !outcome.ok);
|
|
2733
3002
|
ensureAgentEndEvent(deps, sessionId, turn.turnId);
|
|
2734
3003
|
if (controller.signal.aborted) {
|
|
2735
3004
|
terminalState = "aborted";
|
|
@@ -2757,6 +3026,7 @@ export async function handleCreateChatTurn(req, res, deps, sessionId, trustedPay
|
|
|
2757
3026
|
}
|
|
2758
3027
|
catch (error) {
|
|
2759
3028
|
const message = error instanceof Error ? error.message : String(error);
|
|
3029
|
+
await appendWorkspaceChanges(true);
|
|
2760
3030
|
if (controller.signal.aborted) {
|
|
2761
3031
|
terminalState = "aborted";
|
|
2762
3032
|
terminalError = {
|
|
@@ -1,11 +1,116 @@
|
|
|
1
1
|
import { buildNightJobDetail, buildNightJobsList } from "../../../observe/night-jobs.js";
|
|
2
|
+
import { getCommandToolArgs, getCommandToolResult, isShellTool } from "../tool-preview.js";
|
|
2
3
|
export function scopeWorkspaceJobs(jobs, workspaceId) {
|
|
3
4
|
const items = jobs.filter((job) => job.workspaceId === workspaceId);
|
|
4
5
|
return { items, omitted: jobs.length - items.length };
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Project Console terminal sessions into the background-jobs shape.
|
|
9
|
+
*
|
|
10
|
+
* DSH's drawer lists the HOST's client jobs — the long-running commands a
|
|
11
|
+
* reader started and wants to watch. Loop's equivalent live surface is the
|
|
12
|
+
* terminal registry: a PTY session carries a name, a start time, an exit code
|
|
13
|
+
* and a readable output buffer, which is exactly a job row. Scheduler night
|
|
14
|
+
* jobs are merged in separately because they carry different facts (feature /
|
|
15
|
+
* task / worker run) and are often empty on a working machine.
|
|
16
|
+
*/
|
|
17
|
+
export function projectTerminalJobs(terminals, workspaceId) {
|
|
18
|
+
return terminals.map((session) => ({
|
|
19
|
+
jobId: session.sessionId,
|
|
20
|
+
...(workspaceId ? { workspaceId } : {}),
|
|
21
|
+
featureId: "",
|
|
22
|
+
taskId: session.name || session.sessionId,
|
|
23
|
+
status: session.exited ? (session.exitCode === 0 ? "completed" : "failed") : "running",
|
|
24
|
+
startedAt: session.createdAt,
|
|
25
|
+
nextAction: session.exited ? "已结束" : "运行中",
|
|
26
|
+
source: "terminal",
|
|
27
|
+
shell: session.shell,
|
|
28
|
+
terminalSessionId: session.sessionId,
|
|
29
|
+
ownerSessionId: session.ownerSessionId,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Project a session's event ring into background-job rows.
|
|
34
|
+
*
|
|
35
|
+
* DSH's drawer lists the long-running commands of the session — the rows read
|
|
36
|
+
* `pshw npm run test:fast` with a state dot and an elapsed time. In Loop those
|
|
37
|
+
* commands are SHELL TOOL CALLS (`bash` / `powershell` / `pwsh`), which the
|
|
38
|
+
* event ring already records as `tool_call` → `tool_result` pairs. Projecting
|
|
39
|
+
* them here means the drawer shows real work with no new backend surface.
|
|
40
|
+
*
|
|
41
|
+
* Only shell tools are projected: a read/grep call is not something a reader
|
|
42
|
+
* watches, and the ring deliberately caps its retained tail, so this is a
|
|
43
|
+
* bounded projection of recent activity rather than a durable job registry.
|
|
44
|
+
*/
|
|
45
|
+
export function projectShellToolJobs(events, ownerSessionId, workspaceId) {
|
|
46
|
+
const byCallId = new Map();
|
|
47
|
+
const order = [];
|
|
48
|
+
for (const event of events) {
|
|
49
|
+
const payload = event.data;
|
|
50
|
+
const toolCallId = typeof payload.toolCallId === "string" ? payload.toolCallId : undefined;
|
|
51
|
+
const toolName = typeof payload.toolName === "string" ? payload.toolName : undefined;
|
|
52
|
+
if (!toolCallId || !isShellTool(toolName))
|
|
53
|
+
continue;
|
|
54
|
+
if (event.kind === "tool_call") {
|
|
55
|
+
if (byCallId.has(toolCallId))
|
|
56
|
+
continue;
|
|
57
|
+
// The preview is the bounded one-line command the UI already prints,
|
|
58
|
+
// so the job row shows exactly what the timeline shows.
|
|
59
|
+
const args = getCommandToolArgs(toolName, payload.argsPreview);
|
|
60
|
+
const name = args?.description?.trim() || args?.command?.trim() || toolName;
|
|
61
|
+
byCallId.set(toolCallId, {
|
|
62
|
+
toolCallId,
|
|
63
|
+
name: name.split(/\r?\n/)[0].slice(0, 160),
|
|
64
|
+
startedAt: event.at,
|
|
65
|
+
failed: false,
|
|
66
|
+
});
|
|
67
|
+
order.push(toolCallId);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (event.kind === "tool_result" || event.kind === "tool_update") {
|
|
71
|
+
const current = byCallId.get(toolCallId);
|
|
72
|
+
if (!current)
|
|
73
|
+
continue;
|
|
74
|
+
const result = getCommandToolResult(payload.resultPreview);
|
|
75
|
+
if (result.exitCode !== undefined)
|
|
76
|
+
current.exitCode = result.exitCode;
|
|
77
|
+
if (event.kind === "tool_result") {
|
|
78
|
+
current.finishedAt = event.at;
|
|
79
|
+
if (result.exitCode !== undefined && result.exitCode !== 0)
|
|
80
|
+
current.failed = true;
|
|
81
|
+
}
|
|
82
|
+
if (result.output)
|
|
83
|
+
current.output = result.output.slice(0, 2000);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return order
|
|
87
|
+
.map((toolCallId) => byCallId.get(toolCallId))
|
|
88
|
+
// Newest first: the drawer is a recency list, not a full audit trail
|
|
89
|
+
// (the event ring only retains a bounded tail anyway).
|
|
90
|
+
.sort((a, b) => (b.finishedAt ?? b.startedAt).localeCompare(a.finishedAt ?? a.startedAt))
|
|
91
|
+
.slice(0, 20)
|
|
92
|
+
.map((job) => ({
|
|
93
|
+
jobId: job.toolCallId,
|
|
94
|
+
...(workspaceId ? { workspaceId } : {}),
|
|
95
|
+
featureId: "",
|
|
96
|
+
taskId: job.name,
|
|
97
|
+
status: job.finishedAt ? (job.failed ? "failed" : "completed") : "running",
|
|
98
|
+
startedAt: job.startedAt,
|
|
99
|
+
...(job.finishedAt ? { finishedAt: job.finishedAt } : {}),
|
|
100
|
+
nextAction: job.finishedAt ? "已结束" : "运行中",
|
|
101
|
+
source: "terminal",
|
|
102
|
+
shell: "pwsh",
|
|
103
|
+
terminalSessionId: job.toolCallId,
|
|
104
|
+
ownerSessionId,
|
|
105
|
+
...(job.output ? { outputRef: job.output } : {}),
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
export async function listWorkspaceJobs(repoRoot, terminals = [], workspaceId) {
|
|
109
|
+
const terminal = projectTerminalJobs(terminals, workspaceId);
|
|
110
|
+
if (!repoRoot)
|
|
111
|
+
return terminal;
|
|
112
|
+
const scheduler = await buildNightJobsList(repoRoot)
|
|
113
|
+
.then((list) => Promise.all(list.schedules.map(async (schedule) => {
|
|
9
114
|
const detail = schedule.currentExecutionId
|
|
10
115
|
? await buildNightJobDetail(repoRoot, schedule.scheduleId).catch(() => null)
|
|
11
116
|
: null;
|
|
@@ -23,6 +128,12 @@ export async function listWorkspaceJobs(repoRoot) {
|
|
|
23
128
|
...(execution?.dagRunId ? { dagRunId: execution.dagRunId } : {}),
|
|
24
129
|
...(execution?.evidenceArchivePath ? { outputRef: execution.evidenceArchivePath } : {}),
|
|
25
130
|
nextAction: schedule.nextAction,
|
|
131
|
+
source: "scheduler",
|
|
26
132
|
};
|
|
27
|
-
}))
|
|
133
|
+
})))
|
|
134
|
+
.catch(() => []);
|
|
135
|
+
// Live rows first (a running command is what the reader is watching), then
|
|
136
|
+
// running scheduler jobs, then everything settled.
|
|
137
|
+
const rank = (job) => job.status === "running" || job.status === "working" ? (job.source === "terminal" ? 0 : 1) : 2;
|
|
138
|
+
return [...terminal, ...scheduler].sort((a, b) => rank(a) - rank(b));
|
|
28
139
|
}
|