@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
|
@@ -125,6 +125,7 @@ export function repoHtmlAssetContentType(rawPath) {
|
|
|
125
125
|
".mp4": "video/mp4",
|
|
126
126
|
".webm": "video/webm",
|
|
127
127
|
".pdf": "application/pdf",
|
|
128
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
128
129
|
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
129
130
|
".xls": "application/vnd.ms-excel",
|
|
130
131
|
".csv": "text/csv; charset=utf-8",
|
|
@@ -263,10 +264,12 @@ async function readRepoNonTextPreview(repoRoot, rawPath, classified) {
|
|
|
263
264
|
// Same ceiling as the byte route that serves the preview bytes.
|
|
264
265
|
if (size > HTML_PREVIEW_ASSET_LIMIT)
|
|
265
266
|
throw new RepoBrowserError(413, "TOO_LARGE", `file exceeds ${HTML_PREVIEW_ASSET_LIMIT} byte preview limit`);
|
|
266
|
-
if (classified.kind === "sheet") {
|
|
267
|
+
if (classified.kind === "sheet" || classified.kind === "docx") {
|
|
268
|
+
// Sheets and Word documents are cited by visible region, so the snapshot
|
|
269
|
+
// carries a content hash as the reference version.
|
|
267
270
|
return {
|
|
268
271
|
path: repoRelative,
|
|
269
|
-
kind:
|
|
272
|
+
kind: classified.kind,
|
|
270
273
|
content: "",
|
|
271
274
|
language,
|
|
272
275
|
mediaType: classified.mediaType,
|
|
@@ -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,9 @@ 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 { projectFileResult } from "./tool-presentation-projection.js";
|
|
15
|
+
import { summarizeTurnFileEdits } from "./workspace-changes.js";
|
|
13
16
|
import { projectDeferredTurnSummary, projectDeferredTurnSummaries, } from "./deferred-turn.js";
|
|
14
17
|
import { THINKING_LEVELS, RuntimeSnapshotUnavailableError, } from "./pi-runtime.js";
|
|
15
18
|
import { ResourcePreferencesError, setSkillAutoInvocationPreference, } from "./resource-preferences-store.js";
|
|
@@ -47,7 +50,7 @@ import { handleBrowserRequest } from "./browser-routes.js";
|
|
|
47
50
|
import { handleApiWorkbenchRequest } from "./api-workbench.js";
|
|
48
51
|
import { DbConnectionError } from "./db-connections.js";
|
|
49
52
|
import { projectSubagentCatalog } from "./subagents/catalog.js";
|
|
50
|
-
import { listWorkspaceJobs, scopeWorkspaceJobs } from "./subagents/jobs.js";
|
|
53
|
+
import { listWorkspaceJobs, projectShellToolJobs, scopeWorkspaceJobs } from "./subagents/jobs.js";
|
|
51
54
|
function projectBrowserChatSession(record) {
|
|
52
55
|
const { telemetrySessionId, systemPromptSuffix, ...projected } = record;
|
|
53
56
|
void telemetrySessionId;
|
|
@@ -353,6 +356,53 @@ function ensureAgentEndEvent(deps, sessionId, turnId) {
|
|
|
353
356
|
});
|
|
354
357
|
}
|
|
355
358
|
}
|
|
359
|
+
function recordTurnFileMutation(event, editToolPaths, editedFiles) {
|
|
360
|
+
if (event.type === "tool_call" && (event.toolName === "edit" || event.toolName === "write")) {
|
|
361
|
+
const args = toolRecord(event.args);
|
|
362
|
+
const path = typeof args?.path === "string" ? args.path : typeof args?.file_path === "string" ? args.file_path : "";
|
|
363
|
+
if (path && typeof event.toolCallId === "string") {
|
|
364
|
+
editToolPaths.set(event.toolCallId, path);
|
|
365
|
+
}
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (event.type === "tool_result" && !event.isError && !event.interrupted && (event.toolName === "edit" || event.toolName === "write")) {
|
|
369
|
+
const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : "";
|
|
370
|
+
const rawPath = editToolPaths.get(toolCallId) ?? "";
|
|
371
|
+
if (!rawPath)
|
|
372
|
+
return;
|
|
373
|
+
const display = rawPath.replace(/\\/g, "/");
|
|
374
|
+
const preview = fileToolPreview(event.result) ?? fileToolPreview(projectFileResult(event.toolName, event.result));
|
|
375
|
+
const added = preview?.added ?? 0;
|
|
376
|
+
const deleted = preview?.removed ?? 0;
|
|
377
|
+
const existing = editedFiles.get(display);
|
|
378
|
+
if (existing) {
|
|
379
|
+
existing.added += added;
|
|
380
|
+
existing.deleted += deleted;
|
|
381
|
+
if (existing.firstChangedLine === undefined && preview?.firstChangedLine !== undefined) {
|
|
382
|
+
existing.firstChangedLine = preview.firstChangedLine;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
editedFiles.set(display, {
|
|
387
|
+
path: rawPath,
|
|
388
|
+
display,
|
|
389
|
+
added,
|
|
390
|
+
deleted,
|
|
391
|
+
...(preview?.firstChangedLine !== undefined ? { firstChangedLine: preview.firstChangedLine } : {}),
|
|
392
|
+
status: event.toolName === "write" ? "added" : "modified",
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function resolveTurnWorkspaceChanges(input) {
|
|
398
|
+
return summarizeTurnFileEdits({
|
|
399
|
+
sessionId: input.sessionId,
|
|
400
|
+
turnId: input.turnId,
|
|
401
|
+
turnNumber: input.turnNumber,
|
|
402
|
+
files: [...input.editedFiles.values()],
|
|
403
|
+
failedTurn: input.failedTurn,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
356
406
|
async function readJsonBody(req, maxBytes = 2 * 1024 * 1024) {
|
|
357
407
|
// AC-R5-003: the multi-workspace dispatcher (server.ts readBodyOnce)
|
|
358
408
|
// pre-reads and JSON-parses the body for workspaceId resolution, stashing
|
|
@@ -1011,8 +1061,100 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1011
1061
|
const messagePage = await deps.store.listMessages(sessionId, { limit: 50 });
|
|
1012
1062
|
const composerDraftSnapshot = await new ComposerDraftStore(deps.appData).getDraft(sessionId);
|
|
1013
1063
|
const composerDraft = composerDraftSnapshot.text;
|
|
1014
|
-
|
|
1015
|
-
const
|
|
1064
|
+
// P2-A: projection checkpoint / baseline optimization
|
|
1065
|
+
const currentEpoch = deps.events.epoch(sessionId);
|
|
1066
|
+
const existingCheckpoint = deps.events.getCheckpoint?.(sessionId);
|
|
1067
|
+
const minSeq = deps.events.minSeq?.(sessionId) ?? 1;
|
|
1068
|
+
const isCheckpointValid = existingCheckpoint &&
|
|
1069
|
+
existingCheckpoint.schemaVersion === 1 &&
|
|
1070
|
+
existingCheckpoint.sessionId === sessionId &&
|
|
1071
|
+
existingCheckpoint.eventEpoch === currentEpoch &&
|
|
1072
|
+
existingCheckpoint.asOfSeq >= minSeq;
|
|
1073
|
+
let snapshot;
|
|
1074
|
+
let telemetry;
|
|
1075
|
+
let turnTelemetry;
|
|
1076
|
+
let workspaceChanges;
|
|
1077
|
+
let todos;
|
|
1078
|
+
let compactions;
|
|
1079
|
+
let asOfSeq;
|
|
1080
|
+
if (isCheckpointValid) {
|
|
1081
|
+
const incremental = deps.events.snapshot(sessionId, { afterSeq: existingCheckpoint.asOfSeq });
|
|
1082
|
+
if (incremental.length === 0) {
|
|
1083
|
+
snapshot = deps.events.snapshot(sessionId);
|
|
1084
|
+
telemetry = existingCheckpoint.telemetry;
|
|
1085
|
+
turnTelemetry = existingCheckpoint.turnTelemetry;
|
|
1086
|
+
workspaceChanges = existingCheckpoint.workspaceChanges;
|
|
1087
|
+
todos = existingCheckpoint.todos;
|
|
1088
|
+
compactions = existingCheckpoint.compactions;
|
|
1089
|
+
asOfSeq = existingCheckpoint.asOfSeq;
|
|
1090
|
+
}
|
|
1091
|
+
else {
|
|
1092
|
+
snapshot = deps.events.snapshot(sessionId);
|
|
1093
|
+
telemetry = deriveChatSessionTelemetry(snapshot);
|
|
1094
|
+
turnTelemetry = deriveChatTurnTelemetry(snapshot);
|
|
1095
|
+
workspaceChanges = snapshot.filter((event) => event.kind === "workspace_changes").map((event) => event.data);
|
|
1096
|
+
todos = projectCurrentTodos(snapshot) ?? [];
|
|
1097
|
+
compactions = snapshot
|
|
1098
|
+
.filter((event) => event.kind === "compact" ||
|
|
1099
|
+
event.kind === "compaction_start" ||
|
|
1100
|
+
event.kind === "compaction_end")
|
|
1101
|
+
.map((event) => ({
|
|
1102
|
+
eventId: event.eventId,
|
|
1103
|
+
kind: event.kind,
|
|
1104
|
+
at: event.at,
|
|
1105
|
+
seq: event.seq,
|
|
1106
|
+
turnId: event.turnId,
|
|
1107
|
+
data: event.data,
|
|
1108
|
+
}));
|
|
1109
|
+
asOfSeq = snapshot.at(-1)?.seq ?? existingCheckpoint.asOfSeq;
|
|
1110
|
+
deps.events.setCheckpoint?.(sessionId, {
|
|
1111
|
+
schemaVersion: 1,
|
|
1112
|
+
sessionId,
|
|
1113
|
+
eventEpoch: currentEpoch,
|
|
1114
|
+
asOfSeq,
|
|
1115
|
+
createdAt: new Date().toISOString(),
|
|
1116
|
+
telemetry,
|
|
1117
|
+
turnTelemetry,
|
|
1118
|
+
turnStates: [],
|
|
1119
|
+
workspaceChanges,
|
|
1120
|
+
todos: todos ?? [],
|
|
1121
|
+
compactions,
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
else {
|
|
1126
|
+
snapshot = deps.events.snapshot(sessionId);
|
|
1127
|
+
telemetry = deriveChatSessionTelemetry(snapshot);
|
|
1128
|
+
turnTelemetry = deriveChatTurnTelemetry(snapshot);
|
|
1129
|
+
workspaceChanges = snapshot.filter((event) => event.kind === "workspace_changes").map((event) => event.data);
|
|
1130
|
+
todos = projectCurrentTodos(snapshot) ?? [];
|
|
1131
|
+
compactions = snapshot
|
|
1132
|
+
.filter((event) => event.kind === "compact" ||
|
|
1133
|
+
event.kind === "compaction_start" ||
|
|
1134
|
+
event.kind === "compaction_end")
|
|
1135
|
+
.map((event) => ({
|
|
1136
|
+
eventId: event.eventId,
|
|
1137
|
+
kind: event.kind,
|
|
1138
|
+
at: event.at,
|
|
1139
|
+
seq: event.seq,
|
|
1140
|
+
turnId: event.turnId,
|
|
1141
|
+
data: event.data,
|
|
1142
|
+
}));
|
|
1143
|
+
asOfSeq = snapshot.at(-1)?.seq ?? 0;
|
|
1144
|
+
deps.events.setCheckpoint?.(sessionId, {
|
|
1145
|
+
schemaVersion: 1,
|
|
1146
|
+
sessionId,
|
|
1147
|
+
eventEpoch: currentEpoch,
|
|
1148
|
+
asOfSeq,
|
|
1149
|
+
createdAt: new Date().toISOString(),
|
|
1150
|
+
telemetry,
|
|
1151
|
+
turnTelemetry,
|
|
1152
|
+
turnStates: [],
|
|
1153
|
+
workspaceChanges,
|
|
1154
|
+
todos: todos ?? [],
|
|
1155
|
+
compactions,
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1016
1158
|
const lastEvent = snapshot.at(-1);
|
|
1017
1159
|
const activeTurn = deps.events.getActiveTurn(sessionId);
|
|
1018
1160
|
const pendingQuestion = await deps.questionRegistry?.get(sessionId);
|
|
@@ -1026,7 +1168,12 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1026
1168
|
]);
|
|
1027
1169
|
sendJson(res, 200, {
|
|
1028
1170
|
ok: true,
|
|
1029
|
-
eventEpoch:
|
|
1171
|
+
eventEpoch: currentEpoch,
|
|
1172
|
+
checkpoint: {
|
|
1173
|
+
schemaVersion: 1,
|
|
1174
|
+
eventEpoch: currentEpoch,
|
|
1175
|
+
asOfSeq,
|
|
1176
|
+
},
|
|
1030
1177
|
subagents: await subagentCatalogFor(deps, sessionId, record.messages),
|
|
1031
1178
|
session: {
|
|
1032
1179
|
...projectBrowserChatSession(record),
|
|
@@ -1043,7 +1190,8 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1043
1190
|
: "running"
|
|
1044
1191
|
: "idle",
|
|
1045
1192
|
pendingQuestion: pendingQuestion ?? null,
|
|
1046
|
-
todos:
|
|
1193
|
+
todos: todos ?? [],
|
|
1194
|
+
workspaceChanges,
|
|
1047
1195
|
...(deps.goalRegistry?.read(sessionId) ?? { goalStatus: "absent", goal: null }),
|
|
1048
1196
|
},
|
|
1049
1197
|
history: {
|
|
@@ -1053,7 +1201,7 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1053
1201
|
hasBash: true,
|
|
1054
1202
|
sessionStats: telemetry.stats,
|
|
1055
1203
|
usage: telemetry.usage,
|
|
1056
|
-
turnTelemetry
|
|
1204
|
+
turnTelemetry,
|
|
1057
1205
|
requestDetails: (deps.events.listRequestDetails?.(sessionId) ?? []).map(projectRequestSummary),
|
|
1058
1206
|
userTurnOutline: projectUserTurnOutline(record.messages ?? []),
|
|
1059
1207
|
...(sddSessionIdentity
|
|
@@ -1062,18 +1210,7 @@ export async function handleGetChatSession(_req, res, deps, sessionId) {
|
|
|
1062
1210
|
contextPressure: typeof deps.runtime.getContextPressureTelemetry === "function"
|
|
1063
1211
|
? deps.runtime.getContextPressureTelemetry(sessionId)
|
|
1064
1212
|
: 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
|
-
})),
|
|
1213
|
+
compactions,
|
|
1077
1214
|
conversationEvents: snapshot.filter((event) => [
|
|
1078
1215
|
"step_start",
|
|
1079
1216
|
"step_end",
|
|
@@ -1684,13 +1821,20 @@ function flattenSubagentCatalogItems(items) {
|
|
|
1684
1821
|
export async function listWorkspaceSubagentTasks(deps, workspaceScope) {
|
|
1685
1822
|
const sessions = await deps.store.list({ includeArchived: true });
|
|
1686
1823
|
const diagnostics = [];
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
:
|
|
1693
|
-
|
|
1824
|
+
// Terminal sessions are a first-class job source: they are the live
|
|
1825
|
+
// long-running commands the reader watches, and the terminal registry is
|
|
1826
|
+
// process-scoped (not repo-scoped), so it answers even with no appData.
|
|
1827
|
+
const terminalSessions = deps.terminals?.list() ?? [];
|
|
1828
|
+
const availableJobs = await listWorkspaceJobs(deps.appData?.repoRoot ?? "", terminalSessions, workspaceScope).catch((error) => {
|
|
1829
|
+
diagnostics.push(`jobs: ${error instanceof Error ? error.message : String(error)}`);
|
|
1830
|
+
return [];
|
|
1831
|
+
});
|
|
1832
|
+
// Shell tool calls from THIS workspace's sessions are the rows DSH shows
|
|
1833
|
+
// (`pshw npm run …`). They are projected from each ring's retained tail.
|
|
1834
|
+
const shellJobs = sessions
|
|
1835
|
+
.filter((session) => session.workspaceId === workspaceScope)
|
|
1836
|
+
.flatMap((session) => projectShellToolJobs(deps.events?.snapshot(session.sessionId) ?? [], session.sessionId, workspaceScope));
|
|
1837
|
+
const scopedJobs = scopeWorkspaceJobs([...shellJobs, ...availableJobs], workspaceScope);
|
|
1694
1838
|
if (scopedJobs.omitted > 0)
|
|
1695
1839
|
diagnostics.push(`${scopedJobs.omitted} scheduler jobs omitted: workspace ownership unavailable or mismatched`);
|
|
1696
1840
|
const taskGroups = await Promise.all(sessions
|
|
@@ -1962,6 +2106,67 @@ export async function handleStopChatSubagent(req, res, deps, parentSessionId, ch
|
|
|
1962
2106
|
const responseChild = latest ?? child;
|
|
1963
2107
|
sendJson(res, 202, { ok: true, accepted: true, cleanupPending: responseChild.finishedAt === undefined, child: responseChild, continuation: subagentContinuation(deps, parentSessionId, responseChild) });
|
|
1964
2108
|
}
|
|
2109
|
+
export async function handleStopWorkspaceSubagent(req, res, deps, childSessionId) {
|
|
2110
|
+
const gate = gateMutation(req, deps);
|
|
2111
|
+
if (!gate.ok) {
|
|
2112
|
+
sendJson(res, gate.status, { ok: false, accepted: false, error: { code: gate.code, message: gate.message } });
|
|
2113
|
+
return;
|
|
2114
|
+
}
|
|
2115
|
+
const child = await deps.subagents?.get(childSessionId).catch(() => undefined);
|
|
2116
|
+
if (!child) {
|
|
2117
|
+
sendJson(res, 404, { ok: false, accepted: false, error: { code: "SUBAGENT_NOT_FOUND", message: "subagent not found" } });
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
await handleStopChatSubagent(req, res, deps, child.parentSessionId, childSessionId);
|
|
2121
|
+
}
|
|
2122
|
+
/**
|
|
2123
|
+
* Terminate one background job.
|
|
2124
|
+
*
|
|
2125
|
+
* DSH's drawer terminates a row with `jobs.kill(ownerSessionId, jobId)` behind a
|
|
2126
|
+
* two-click confirm. Loop's jobs come from two surfaces, and only one of them
|
|
2127
|
+
* has a process to kill:
|
|
2128
|
+
*
|
|
2129
|
+
* - a TERMINAL session (the registry's own `kill()`), and
|
|
2130
|
+
* - a shell tool call that is still running.
|
|
2131
|
+
*
|
|
2132
|
+
* A settled shell call is a historical fact — there is nothing to terminate, so
|
|
2133
|
+
* it is refused explicitly rather than pretending to succeed. The client never
|
|
2134
|
+
* offers the control for those rows (it is `status === "running"` only, exactly
|
|
2135
|
+
* as DSH gates it).
|
|
2136
|
+
*/
|
|
2137
|
+
export async function handleStopWorkspaceJob(req, res, deps, jobId) {
|
|
2138
|
+
const gate = gateMutation(req, deps);
|
|
2139
|
+
if (!gate.ok) {
|
|
2140
|
+
sendJson(res, gate.status, { ok: false, accepted: false, error: { code: gate.code, message: gate.message } });
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
// A terminal session id IS the job id for terminal-backed rows.
|
|
2144
|
+
const terminals = deps.terminals;
|
|
2145
|
+
if (terminals) {
|
|
2146
|
+
const session = terminals.list().find((candidate) => candidate.sessionId === jobId);
|
|
2147
|
+
if (session) {
|
|
2148
|
+
if (session.exited) {
|
|
2149
|
+
sendJson(res, 409, {
|
|
2150
|
+
ok: false,
|
|
2151
|
+
accepted: false,
|
|
2152
|
+
error: { code: "JOB_ALREADY_SETTLED", message: "任务已结束,无需终止" },
|
|
2153
|
+
});
|
|
2154
|
+
return;
|
|
2155
|
+
}
|
|
2156
|
+
await terminals.kill(session.sessionId);
|
|
2157
|
+
sendJson(res, 200, { ok: true, accepted: true, jobId: session.sessionId, status: "killed" });
|
|
2158
|
+
return;
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
sendJson(res, 404, {
|
|
2162
|
+
ok: false,
|
|
2163
|
+
accepted: false,
|
|
2164
|
+
error: {
|
|
2165
|
+
code: "JOB_NOT_TERMINABLE",
|
|
2166
|
+
message: "该任务不是运行中的终端会话,无法终止",
|
|
2167
|
+
},
|
|
2168
|
+
});
|
|
2169
|
+
}
|
|
1965
2170
|
export async function handlePromptChatSubagent(req, res, deps, parentSessionId, childSessionId) {
|
|
1966
2171
|
const gate = gateMutation(req, deps);
|
|
1967
2172
|
if (!gate.ok) {
|
|
@@ -2346,6 +2551,8 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2346
2551
|
// Lazily import to avoid circular module load.
|
|
2347
2552
|
const { runChatTurn } = await import("./session-store.js");
|
|
2348
2553
|
let firstUserText;
|
|
2554
|
+
const editedFiles = new Map();
|
|
2555
|
+
const editToolPaths = new Map();
|
|
2349
2556
|
try {
|
|
2350
2557
|
const outcome = await runChatTurn({
|
|
2351
2558
|
runtime: deps.runtime,
|
|
@@ -2405,6 +2612,7 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2405
2612
|
return;
|
|
2406
2613
|
}
|
|
2407
2614
|
recordRequestEventFact(deps, sessionId, turnId, event);
|
|
2615
|
+
recordTurnFileMutation(event, editToolPaths, editedFiles);
|
|
2408
2616
|
const partial = turnEventToStorePartial(event);
|
|
2409
2617
|
if (!partial)
|
|
2410
2618
|
return;
|
|
@@ -2413,7 +2621,22 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2413
2621
|
writeChatSse(res, persisted);
|
|
2414
2622
|
},
|
|
2415
2623
|
});
|
|
2624
|
+
const appendWorkspaceChanges = async (failedTurn) => {
|
|
2625
|
+
const summary = await resolveTurnWorkspaceChanges({
|
|
2626
|
+
sessionId,
|
|
2627
|
+
turnId,
|
|
2628
|
+
turnNumber: createdTurn.turn.ordinal,
|
|
2629
|
+
editedFiles,
|
|
2630
|
+
failedTurn,
|
|
2631
|
+
});
|
|
2632
|
+
if (!summary)
|
|
2633
|
+
return;
|
|
2634
|
+
const persisted = deps.events.append(sessionId, turnId, { kind: "workspace_changes", data: summary });
|
|
2635
|
+
if (!res.writableEnded)
|
|
2636
|
+
writeChatSse(res, persisted);
|
|
2637
|
+
};
|
|
2416
2638
|
if (abortedByClient || ac.signal.aborted) {
|
|
2639
|
+
await appendWorkspaceChanges(true);
|
|
2417
2640
|
ensureAgentEndEvent(deps, sessionId, turnId);
|
|
2418
2641
|
deps.events.setTurnState(sessionId, turnId, "aborted", {
|
|
2419
2642
|
code: "CLIENT_ABORTED",
|
|
@@ -2421,6 +2644,7 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2421
2644
|
});
|
|
2422
2645
|
}
|
|
2423
2646
|
else {
|
|
2647
|
+
await appendWorkspaceChanges(!outcome.ok);
|
|
2424
2648
|
ensureAgentEndEvent(deps, sessionId, turnId);
|
|
2425
2649
|
deps.events.setTurnState(sessionId, turnId, outcome.ok ? "settled" : "failed", outcome.error);
|
|
2426
2650
|
if (outcome.ok && firstUserText)
|
|
@@ -2434,6 +2658,20 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
|
|
|
2434
2658
|
// stream is already open. Persist + emit an error event so a reconnecting
|
|
2435
2659
|
// client also sees the failure (not just the original requester).
|
|
2436
2660
|
const message = error instanceof Error ? error.message : String(error);
|
|
2661
|
+
{
|
|
2662
|
+
const summary = await resolveTurnWorkspaceChanges({
|
|
2663
|
+
sessionId,
|
|
2664
|
+
turnId,
|
|
2665
|
+
turnNumber: createdTurn.turn.ordinal,
|
|
2666
|
+
editedFiles,
|
|
2667
|
+
failedTurn: true,
|
|
2668
|
+
});
|
|
2669
|
+
if (summary) {
|
|
2670
|
+
const persisted = deps.events.append(sessionId, turnId, { kind: "workspace_changes", data: summary });
|
|
2671
|
+
if (!res.writableEnded)
|
|
2672
|
+
writeChatSse(res, persisted);
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2437
2675
|
ensureAgentEndEvent(deps, sessionId, turnId);
|
|
2438
2676
|
deps.events.setTurnState(sessionId, turnId, abortedByClient || ac.signal.aborted ? "aborted" : "failed", {
|
|
2439
2677
|
code: abortedByClient || ac.signal.aborted
|
|
@@ -2682,6 +2920,19 @@ export async function handleCreateChatTurn(req, res, deps, sessionId, trustedPay
|
|
|
2682
2920
|
// Abort ownership lives in the execution registry (real Stop path).
|
|
2683
2921
|
void (async () => {
|
|
2684
2922
|
const { runChatTurn } = await import("./session-store.js");
|
|
2923
|
+
const editedFiles = new Map();
|
|
2924
|
+
const editToolPaths = new Map();
|
|
2925
|
+
const appendWorkspaceChanges = async (failedTurn) => {
|
|
2926
|
+
const summary = await resolveTurnWorkspaceChanges({
|
|
2927
|
+
sessionId,
|
|
2928
|
+
turnId: turn.turnId,
|
|
2929
|
+
turnNumber: turn.ordinal,
|
|
2930
|
+
editedFiles,
|
|
2931
|
+
failedTurn,
|
|
2932
|
+
});
|
|
2933
|
+
if (summary)
|
|
2934
|
+
deps.events.append(sessionId, turn.turnId, { kind: "workspace_changes", data: summary });
|
|
2935
|
+
};
|
|
2685
2936
|
let firstUserText;
|
|
2686
2937
|
let terminalState = "failed";
|
|
2687
2938
|
let terminalError;
|
|
@@ -2725,11 +2976,13 @@ export async function handleCreateChatTurn(req, res, deps, sessionId, trustedPay
|
|
|
2725
2976
|
if (event.type === "heartbeat")
|
|
2726
2977
|
return;
|
|
2727
2978
|
recordRequestEventFact(deps, sessionId, turn.turnId, event);
|
|
2979
|
+
recordTurnFileMutation(event, editToolPaths, editedFiles);
|
|
2728
2980
|
const partial = turnEventToStorePartial(event);
|
|
2729
2981
|
if (partial)
|
|
2730
2982
|
deps.events.append(sessionId, turn.turnId, partial);
|
|
2731
2983
|
},
|
|
2732
2984
|
});
|
|
2985
|
+
await appendWorkspaceChanges(controller.signal.aborted || !outcome.ok);
|
|
2733
2986
|
ensureAgentEndEvent(deps, sessionId, turn.turnId);
|
|
2734
2987
|
if (controller.signal.aborted) {
|
|
2735
2988
|
terminalState = "aborted";
|
|
@@ -2757,6 +3010,7 @@ export async function handleCreateChatTurn(req, res, deps, sessionId, trustedPay
|
|
|
2757
3010
|
}
|
|
2758
3011
|
catch (error) {
|
|
2759
3012
|
const message = error instanceof Error ? error.message : String(error);
|
|
3013
|
+
await appendWorkspaceChanges(true);
|
|
2760
3014
|
if (controller.signal.aborted) {
|
|
2761
3015
|
terminalState = "aborted";
|
|
2762
3016
|
terminalError = {
|
|
@@ -3628,6 +3882,26 @@ async function handleChatFiles(res, deps, sessionId, query) {
|
|
|
3628
3882
|
sendJson(res, 200, { ok: true, files });
|
|
3629
3883
|
}
|
|
3630
3884
|
export async function handleChatCommands(res, deps, sessionId) {
|
|
3885
|
+
/*
|
|
3886
|
+
* A durable session is not necessarily resident: after a Console restart,
|
|
3887
|
+
* or for a conversation reopened from history, the Pi runtime holds no live
|
|
3888
|
+
* session for it until something reopens it. `listSlashCommands` needs the
|
|
3889
|
+
* live session, so it used to fail with "chat session not found" while the
|
|
3890
|
+
* transcript and the session list looked perfectly healthy — the reader had
|
|
3891
|
+
* to run /reload to see their commands again.
|
|
3892
|
+
*
|
|
3893
|
+
* Reopen silently here, before listing: the durable record is the source of
|
|
3894
|
+
* truth for how to reopen, and the caller only asked for the command list.
|
|
3895
|
+
*/
|
|
3896
|
+
if (typeof deps.runtime.hasSession === "function" &&
|
|
3897
|
+
!deps.runtime.hasSession(sessionId)) {
|
|
3898
|
+
const record = await deps.store.get(sessionId).catch(() => undefined);
|
|
3899
|
+
if (record) {
|
|
3900
|
+
await deps.runtime
|
|
3901
|
+
.reopenSession(reopenInitFromRecord(record))
|
|
3902
|
+
.catch(() => ({ ok: false }));
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3631
3905
|
try {
|
|
3632
3906
|
const listed = typeof deps.runtime.listSlashCommands === "function"
|
|
3633
3907
|
? await deps.runtime.listSlashCommands(sessionId)
|
|
@@ -55,7 +55,7 @@ export function resolveScheduledTaskTime(input, now) {
|
|
|
55
55
|
stopAtUtc: new Date(stop).toISOString(), expiresAt: new Date(stop).toISOString(), timezone,
|
|
56
56
|
allowedHours: schedule.allowedHours ?? [], misfirePolicy: "run-immediately" });
|
|
57
57
|
}
|
|
58
|
-
const git = async (cwd, ...args) => (await execFileAsync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 30000, maxBuffer: 4 * 1024 * 1024 })).stdout.trim();
|
|
58
|
+
const git = async (cwd, ...args) => (await execFileAsync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 30000, maxBuffer: 4 * 1024 * 1024, windowsHide: true })).stdout.trim();
|
|
59
59
|
const sameSet = (a, b) => JSON.stringify([...new Set(a)].sort()) === JSON.stringify([...new Set(b)].sort());
|
|
60
60
|
function assertScheduledAcceptanceDoesNotRepeatBackendTests(request) {
|
|
61
61
|
if (request.workflow !== "backend-test")
|