@tea-agent/loop-agent 0.51.0 → 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 +91 -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/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
|
@@ -89,6 +89,8 @@ async function handleSend(req, res, deps) {
|
|
|
89
89
|
queryParams: parseQueryParams(body.queryParams),
|
|
90
90
|
...(typeof body.environmentId === "string" ? { environmentId: body.environmentId } : {}),
|
|
91
91
|
...(Array.isArray(body.responseFields) && body.responseFields.every(field => typeof field === "string") ? { responseFields: body.responseFields } : {}),
|
|
92
|
+
// Human UI always wants the redacted full body so the response is readable without picking pointers.
|
|
93
|
+
bodyView: "full",
|
|
92
94
|
...(body.authRef && typeof body.authRef === "object" && "id" in body.authRef && "version" in body.authRef && typeof body.authRef.id === "string" && typeof body.authRef.version === "string" ? { authRef: { id: body.authRef.id, version: body.authRef.version } } : {}),
|
|
93
95
|
}, { signal: controller.signal });
|
|
94
96
|
sendJson(res, 200, outcome);
|
|
@@ -333,6 +333,8 @@ export function turnEventToStorePartial(event) {
|
|
|
333
333
|
case "todo_updated":
|
|
334
334
|
case "todo_cleared":
|
|
335
335
|
return { kind: event.type, data: { todos: Array.isArray(event.todos) ? event.todos : [], ...(event.toolCallId ? { toolCallId: String(event.toolCallId) } : {}) } };
|
|
336
|
+
case "workspace_changes":
|
|
337
|
+
return { kind: "workspace_changes", data: event.summary };
|
|
336
338
|
case "agent_end":
|
|
337
339
|
return {
|
|
338
340
|
kind: "agent_end",
|
|
@@ -856,6 +856,8 @@ export function createChatEventStore(options) {
|
|
|
856
856
|
/** B5-1: sessions whose latest `message_update` appends are still waiting
|
|
857
857
|
* for the next persist (debounced; structural events / turn changes flush). */
|
|
858
858
|
const pendingPersists = new Map();
|
|
859
|
+
/** P2-A: lightweight in-memory projection checkpoints. */
|
|
860
|
+
const checkpoints = new Map();
|
|
859
861
|
function persistedPath(sessionId) {
|
|
860
862
|
return persistenceDir
|
|
861
863
|
? path.join(persistenceDir, `${safeSessionId(sessionId)}.json`)
|
|
@@ -1390,14 +1392,41 @@ export function createChatEventStore(options) {
|
|
|
1390
1392
|
epoch(sessionId) {
|
|
1391
1393
|
return ringFor(sessionId).epoch;
|
|
1392
1394
|
},
|
|
1395
|
+
minSeq(sessionId) {
|
|
1396
|
+
return ringFor(sessionId).minSeq;
|
|
1397
|
+
},
|
|
1393
1398
|
latestSeq(sessionId) {
|
|
1394
1399
|
return ringFor(sessionId).nextSeq - 1;
|
|
1395
1400
|
},
|
|
1396
|
-
snapshot(sessionId) {
|
|
1401
|
+
snapshot(sessionId, options) {
|
|
1397
1402
|
const ring = rings.get(sessionId) ?? loadRing(sessionId);
|
|
1398
1403
|
if (ring)
|
|
1399
1404
|
rings.set(sessionId, ring);
|
|
1400
|
-
|
|
1405
|
+
if (!ring)
|
|
1406
|
+
return [];
|
|
1407
|
+
if (options?.afterSeq !== undefined) {
|
|
1408
|
+
return ring.events.filter((event) => event.seq > options.afterSeq);
|
|
1409
|
+
}
|
|
1410
|
+
return ring.events.slice();
|
|
1411
|
+
},
|
|
1412
|
+
getCheckpoint(sessionId) {
|
|
1413
|
+
const cp = checkpoints.get(sessionId);
|
|
1414
|
+
if (!cp)
|
|
1415
|
+
return undefined;
|
|
1416
|
+
const ring = rings.get(sessionId) ?? loadRing(sessionId);
|
|
1417
|
+
if (!ring)
|
|
1418
|
+
return undefined;
|
|
1419
|
+
if (cp.eventEpoch !== ring.epoch || (ring.events.length > 0 && cp.asOfSeq < ring.minSeq)) {
|
|
1420
|
+
checkpoints.delete(sessionId);
|
|
1421
|
+
return undefined;
|
|
1422
|
+
}
|
|
1423
|
+
return cp;
|
|
1424
|
+
},
|
|
1425
|
+
setCheckpoint(sessionId, checkpoint) {
|
|
1426
|
+
checkpoints.set(sessionId, checkpoint);
|
|
1427
|
+
},
|
|
1428
|
+
invalidateCheckpoint(sessionId) {
|
|
1429
|
+
checkpoints.delete(sessionId);
|
|
1401
1430
|
},
|
|
1402
1431
|
goalHistory(sessionId) {
|
|
1403
1432
|
const ring = ringFor(sessionId);
|
|
@@ -1436,6 +1465,7 @@ export function createChatEventStore(options) {
|
|
|
1436
1465
|
rings.delete(sessionId);
|
|
1437
1466
|
turnCounts.delete(sessionId);
|
|
1438
1467
|
subscribers.delete(sessionId);
|
|
1468
|
+
checkpoints.delete(sessionId);
|
|
1439
1469
|
// B5-1: drop any debounced (not yet written) updates with the ring itself —
|
|
1440
1470
|
// the file is being deleted, so flushing first would only resurrect it.
|
|
1441
1471
|
pendingPersists.delete(sessionId);
|
|
@@ -23,6 +23,7 @@ function validSource(value) {
|
|
|
23
23
|
file: ["kind", "workspaceId", "path", "version", "versionScope", "view", "anchor", "startLine", "endLine", "sheet", "cellRange"],
|
|
24
24
|
diff: ["kind", "workspaceId", "path", "side", "comparison", "version", "startLine", "endLine"],
|
|
25
25
|
terminal: ["kind", "workspaceId", "terminalSessionId", "ownerSessionId", "shell", "anchor"],
|
|
26
|
+
api: ["kind", "workspaceId", "method", "url", "status", "elapsedMs", "anchor"],
|
|
26
27
|
};
|
|
27
28
|
const allowed = typeof s.kind === "string" ? keys[s.kind] : undefined;
|
|
28
29
|
if (!allowed || Object.keys(s).some((key) => !allowed.includes(key)))
|
|
@@ -53,6 +54,9 @@ function validSource(value) {
|
|
|
53
54
|
&& validLine(s.startLine) && validLine(s.endLine) && s.endLine >= s.startLine;
|
|
54
55
|
case "terminal":
|
|
55
56
|
return boundedString(s.terminalSessionId) && boundedString(s.ownerSessionId) && boundedString(s.shell) && boundedString(s.anchor);
|
|
57
|
+
case "api":
|
|
58
|
+
return typeof s.method === "string" && /^[A-Za-z]{1,16}$/.test(s.method) && boundedString(s.url, 2_048) && typeof s.status === "number" && Number.isFinite(s.status)
|
|
59
|
+
&& typeof s.elapsedMs === "number" && Number.isFinite(s.elapsedMs) && s.elapsedMs >= 0 && boundedString(s.anchor);
|
|
56
60
|
default: return false;
|
|
57
61
|
}
|
|
58
62
|
}
|
|
@@ -7,6 +7,7 @@ import { parseAssertions } from "../../api-workbench-assertions.js";
|
|
|
7
7
|
* api_send send one sandboxed HTTP request (env {{key}} substitution)
|
|
8
8
|
* api_environments list environments; upsert baseUrl + key=value variables
|
|
9
9
|
* api_history list / clear recent send history
|
|
10
|
+
* api_debug one-shot debugging brief (endpoints + env + history)
|
|
10
11
|
*
|
|
11
12
|
* Envelope: success { ok: true, ... } / failure { ok: false, error: { code, message } }
|
|
12
13
|
* with stable APIWB_* error codes. Sends use the same validation,
|
|
@@ -15,8 +16,9 @@ import { parseAssertions } from "../../api-workbench-assertions.js";
|
|
|
15
16
|
import { scanSpecsSnapshot, parseQueryParams, ApiWorkbenchCoreError, } from "../../api-workbench-core.js";
|
|
16
17
|
const APIWB_TOOLS_DESCRIPTION = "API workbench: scan repo OpenAPI/Swagger specs and static code routes (api_scan), " +
|
|
17
18
|
"send one sandboxed HTTP request with environment {{key}} substitution (api_send), " +
|
|
18
|
-
"list/upsert environment prefixes + variables (api_environments),
|
|
19
|
-
"
|
|
19
|
+
"list/upsert environment prefixes + variables (api_environments), review send history (api_history), " +
|
|
20
|
+
"and pull a one-shot debugging brief (api_debug). " +
|
|
21
|
+
"Use api_scan or api_debug before guessing endpoints; environments carry non-secret key=value variables. Never submit credential values through tool arguments.";
|
|
20
22
|
export async function buildApiWorkbenchTools(options) {
|
|
21
23
|
const [{ Type }, { defineTool }] = await Promise.all([
|
|
22
24
|
import("typebox"),
|
|
@@ -130,6 +132,66 @@ export async function buildApiWorkbenchTools(options) {
|
|
|
130
132
|
}, { signal }));
|
|
131
133
|
},
|
|
132
134
|
}),
|
|
135
|
+
defineTool({
|
|
136
|
+
name: "api_debug",
|
|
137
|
+
label: "API debug brief",
|
|
138
|
+
description: "One-shot debugging brief: compact endpoint inventory, environments, credentials (metadata only), recent send history, and a debugging playbook. Read this BEFORE sending requests when unsure which endpoint/parameter to use; then use api_send to replay and iterate.",
|
|
139
|
+
parameters: Type.Object({
|
|
140
|
+
query: Type.Optional(Type.String({ maxLength: 120, description: "Case-insensitive substring filter for endpoint paths" })),
|
|
141
|
+
}, { additionalProperties: false }),
|
|
142
|
+
async execute(_id, params) {
|
|
143
|
+
return run("APIWB_DEBUG_FAILED", async () => {
|
|
144
|
+
const snapshot = await scanSpecsSnapshot(opts.repoRoot);
|
|
145
|
+
const needle = params.query?.trim().toLowerCase();
|
|
146
|
+
const endpoints = [];
|
|
147
|
+
for (const spec of snapshot.specs) {
|
|
148
|
+
for (const endpoint of spec.endpoints ?? []) {
|
|
149
|
+
const path = endpoint.path ?? "";
|
|
150
|
+
if (needle && !path.toLowerCase().includes(needle))
|
|
151
|
+
continue;
|
|
152
|
+
endpoints.push({
|
|
153
|
+
method: endpoint.method ?? "",
|
|
154
|
+
path,
|
|
155
|
+
...(endpoint.summary ? { summary: endpoint.summary } : {}),
|
|
156
|
+
required: (endpoint.parameters ?? [])
|
|
157
|
+
.filter((p) => p && typeof p === "object" && p.required === true && p.in !== "body")
|
|
158
|
+
.map((p) => String(p.name ?? ""))
|
|
159
|
+
.filter(Boolean),
|
|
160
|
+
});
|
|
161
|
+
if (endpoints.length >= 80)
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
if (endpoints.length >= 80)
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
const env = await opts.apiWorkbench.readEnvironmentState();
|
|
168
|
+
const credentials = (await opts.apiWorkbench.auth.list()).credentials.map((c) => ({
|
|
169
|
+
id: c.id,
|
|
170
|
+
name: c.name,
|
|
171
|
+
origin: c.origin,
|
|
172
|
+
configured: c.configured,
|
|
173
|
+
}));
|
|
174
|
+
const history = opts.apiWorkbench.listWorkbenchHistory().slice(0, 10).map((h) => ({
|
|
175
|
+
method: h.method,
|
|
176
|
+
url: h.url,
|
|
177
|
+
status: h.status,
|
|
178
|
+
elapsedMs: h.elapsedMs,
|
|
179
|
+
at: h.at,
|
|
180
|
+
}));
|
|
181
|
+
return {
|
|
182
|
+
ok: true,
|
|
183
|
+
stats: snapshot.stats,
|
|
184
|
+
endpoints,
|
|
185
|
+
environments: env,
|
|
186
|
+
credentials,
|
|
187
|
+
history,
|
|
188
|
+
playbook: "1) api_scan/api_debug to inventory endpoints; 2) pick endpoint + environment ({{key}} substitution); " +
|
|
189
|
+
"3) api_send with responseFields to extract only needed fields; 4) on failure read authDiagnosis/error code, " +
|
|
190
|
+
"fix one variable at a time and resend; 5) confirm with assertions; 6) save recurring flows with api_collections.",
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
133
195
|
defineTool({
|
|
134
196
|
name: "api_environments",
|
|
135
197
|
label: "API environments",
|
|
@@ -183,7 +245,7 @@ export async function buildApiWorkbenchTools(options) {
|
|
|
183
245
|
const capability = defineTool({
|
|
184
246
|
name: "apiCapabilities",
|
|
185
247
|
label: "API capabilities",
|
|
186
|
-
description: "Directory for the API workbench. Does not send a request, change an environment, or run a collection. Returns the family, a summary, how to discover tools, the
|
|
248
|
+
description: "Directory for the API workbench. Does not send a request, change an environment, or run a collection. Returns the family, a summary, how to discover tools, the six tool names, and whether they have side effects.",
|
|
187
249
|
parameters: Type.Object({ target: Type.Optional(Type.String({ maxLength: 80 })) }, { additionalProperties: false }),
|
|
188
250
|
async execute(_id, params) {
|
|
189
251
|
const result = discover(params.target);
|
|
@@ -127,6 +127,10 @@ function guardModelRuntimeCosts(value) {
|
|
|
127
127
|
* absent at module load (discovered lazily by pi-readiness instead).
|
|
128
128
|
*/
|
|
129
129
|
export function createDefaultPiSdkBindings() {
|
|
130
|
+
// Warm the ESM module graph while the user is still on the empty UI. The
|
|
131
|
+
// first create otherwise pays the cold SDK import before it can answer 201.
|
|
132
|
+
// A missing SDK still fails lazily on first use, not at bindings creation.
|
|
133
|
+
void loadSdk().catch(() => undefined);
|
|
130
134
|
const consoleServices = new WeakSet();
|
|
131
135
|
return {
|
|
132
136
|
getAgentDir: async () => {
|
|
@@ -325,6 +325,15 @@ export function createWizardLocalHeadersExtension(options) {
|
|
|
325
325
|
}
|
|
326
326
|
export { THINKING_LEVELS, RuntimeSnapshotUnavailableError, projectRuntimeSnapshot, };
|
|
327
327
|
export { createDefaultPiSdkBindings } from "./pi-runtime/sdk-bindings.js";
|
|
328
|
+
/**
|
|
329
|
+
* Give queued macrotasks (an in-flight HTTP 201, an SSE write, a pending
|
|
330
|
+
* `/sessions` read) a turn on the loop before the next synchronous stretch of
|
|
331
|
+
* session preparation starts. Microtasks alone are not enough: they drain
|
|
332
|
+
* inside the same tick that the materialization chain continues in.
|
|
333
|
+
*/
|
|
334
|
+
function yieldEventLoop() {
|
|
335
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
336
|
+
}
|
|
328
337
|
/** Catalog listing must not load skills/extensions/context — those belong to reopen. */
|
|
329
338
|
const CATALOG_RESOURCE_LOADER_OPTIONS = Object.freeze({
|
|
330
339
|
noContextFiles: true,
|
|
@@ -796,6 +805,7 @@ export class ConsolePiRuntime {
|
|
|
796
805
|
async refreshSkillPrefsCache() {
|
|
797
806
|
const prefs = await this.loadSkillAutoInvocationPreferences();
|
|
798
807
|
this.cachedSkillPrefs = prefs;
|
|
808
|
+
this.invalidateWorkspaceInspection();
|
|
799
809
|
return prefs;
|
|
800
810
|
}
|
|
801
811
|
getCompactionController(sessionId) {
|
|
@@ -1136,6 +1146,10 @@ export class ConsolePiRuntime {
|
|
|
1136
1146
|
if (existing?.status === "failed")
|
|
1137
1147
|
return Promise.reject(existing.error);
|
|
1138
1148
|
const promise = Promise.resolve(init.initializationBarrier)
|
|
1149
|
+
// The durable 201 response is still being written when this detached
|
|
1150
|
+
// chain starts. Yield one macrotask so it flushes before the first
|
|
1151
|
+
// synchronous preparation stretch takes the loop.
|
|
1152
|
+
.then(() => yieldEventLoop())
|
|
1139
1153
|
.then(() => this.materializeSession(sessionId, init))
|
|
1140
1154
|
.then(() => {
|
|
1141
1155
|
if (this.disposedSessions.has(sessionId)) {
|
|
@@ -1184,19 +1198,21 @@ export class ConsolePiRuntime {
|
|
|
1184
1198
|
abandon();
|
|
1185
1199
|
return undefined;
|
|
1186
1200
|
}
|
|
1187
|
-
// Capture before services parse models.json. A concurrent edit can therefore
|
|
1188
|
-
// cause at most one harmless extra refresh, never a missed next-turn refresh.
|
|
1189
|
-
const modelConfigFile = await captureModelConfigFile(agentDir);
|
|
1190
|
-
if (aborted()) {
|
|
1191
|
-
abandon();
|
|
1192
|
-
return undefined;
|
|
1193
|
-
}
|
|
1194
1201
|
const appendSystemPrompt = composeChatSystemPromptParts({
|
|
1195
1202
|
sessionMode: init.sessionMode,
|
|
1196
1203
|
workflowPrompt: OPERATOR_CHAT_SYSTEM_PROMPT_BASE,
|
|
1197
1204
|
systemPromptSuffix: init.systemPromptSuffix,
|
|
1198
1205
|
});
|
|
1199
|
-
|
|
1206
|
+
// One parallel pass: models.json change capture and the skill
|
|
1207
|
+
// auto-invocation preferences are independent, so a new session never
|
|
1208
|
+
// pays their disk reads one after another.
|
|
1209
|
+
const [modelConfigFile] = await Promise.all([
|
|
1210
|
+
// Capture before services parse models.json. A concurrent edit can
|
|
1211
|
+
// therefore cause at most one harmless extra refresh, never a missed
|
|
1212
|
+
// next-turn refresh.
|
|
1213
|
+
captureModelConfigFile(agentDir),
|
|
1214
|
+
this.refreshSkillPrefsCache().catch(() => undefined),
|
|
1215
|
+
]);
|
|
1200
1216
|
if (aborted()) {
|
|
1201
1217
|
abandon();
|
|
1202
1218
|
return undefined;
|
|
@@ -1212,6 +1228,10 @@ export class ConsolePiRuntime {
|
|
|
1212
1228
|
agentDir,
|
|
1213
1229
|
resourceLoaderOptions,
|
|
1214
1230
|
});
|
|
1231
|
+
// ResourceLoader construction is the heaviest synchronous stretch of
|
|
1232
|
+
// preparation (skills/AGENTS.md/packages scan). Let queued HTTP/SSE work
|
|
1233
|
+
// run before tool assembly starts.
|
|
1234
|
+
await yieldEventLoop();
|
|
1215
1235
|
if (init.sessionMode !== "pi") {
|
|
1216
1236
|
const expected = this.workflowIntakeCapabilities.get(init.sessionId);
|
|
1217
1237
|
const loader = services.resourceLoader;
|
|
@@ -1248,6 +1268,10 @@ export class ConsolePiRuntime {
|
|
|
1248
1268
|
}) ?? undefined)
|
|
1249
1269
|
: undefined;
|
|
1250
1270
|
assertNoWriteToolInList(OPERATOR_CHAT_ALLOWED_TOOLS);
|
|
1271
|
+
// Tool assembly builds every custom tool factory synchronously; yield
|
|
1272
|
+
// first so an already-queued create response or list read is not delayed
|
|
1273
|
+
// by the whole assembly.
|
|
1274
|
+
await yieldEventLoop();
|
|
1251
1275
|
const customTools = await this.loadCustomTools(init.sessionId);
|
|
1252
1276
|
if (aborted()) {
|
|
1253
1277
|
abandon();
|
|
@@ -1275,8 +1299,16 @@ export class ConsolePiRuntime {
|
|
|
1275
1299
|
await disposeSessionExtensions(session).catch(() => undefined);
|
|
1276
1300
|
return undefined;
|
|
1277
1301
|
}
|
|
1302
|
+
// Session creation registers the full tool catalog synchronously; the
|
|
1303
|
+
// extension handshake below is the next long await, so give the loop one
|
|
1304
|
+
// turn in between.
|
|
1305
|
+
await yieldEventLoop();
|
|
1278
1306
|
try {
|
|
1279
1307
|
await bindSessionExtensions(session);
|
|
1308
|
+
// Seven console extensions emit `session_start` here. Yield after the
|
|
1309
|
+
// handshake so their synchronous registrations do not stack onto the
|
|
1310
|
+
// readiness write that follows.
|
|
1311
|
+
await yieldEventLoop();
|
|
1280
1312
|
assertConsoleResourcePolicy(session, services.resourceLoader);
|
|
1281
1313
|
if (aborted()) {
|
|
1282
1314
|
abandon();
|
|
@@ -1893,7 +1925,28 @@ export class ConsolePiRuntime {
|
|
|
1893
1925
|
* conversation JSONL so the picker is not blocked on cold reopen.
|
|
1894
1926
|
*/
|
|
1895
1927
|
workspaceModelRuntime;
|
|
1896
|
-
|
|
1928
|
+
static WORKSPACE_INSPECTION_TTL_MS = 45_000;
|
|
1929
|
+
workspaceInspectionServices;
|
|
1930
|
+
workspaceInspectionCachedAt = 0;
|
|
1931
|
+
workspaceInspectionInFlight = null;
|
|
1932
|
+
workspaceInspectionGeneration = 0;
|
|
1933
|
+
workspaceInspectionModelsVersion;
|
|
1934
|
+
workspaceInspectionPrefsMtime;
|
|
1935
|
+
workspaceSnapshotTemplates = new Map();
|
|
1936
|
+
workspaceSnapshotInFlight = new Map();
|
|
1937
|
+
/**
|
|
1938
|
+
* Actively invalidate cached workspace inspection services and snapshot
|
|
1939
|
+
* templates (P1-A generation invalidation). Next inspection rebuilds cleanly.
|
|
1940
|
+
*/
|
|
1941
|
+
invalidateWorkspaceInspection() {
|
|
1942
|
+
this.workspaceInspectionServices = undefined;
|
|
1943
|
+
this.workspaceInspectionCachedAt = 0;
|
|
1944
|
+
this.workspaceInspectionInFlight = null;
|
|
1945
|
+
this.workspaceInspectionGeneration += 1;
|
|
1946
|
+
this.workspaceSnapshotTemplates.clear();
|
|
1947
|
+
this.workspaceSnapshotInFlight.clear();
|
|
1948
|
+
this.workspaceModelRuntime = undefined;
|
|
1949
|
+
}
|
|
1897
1950
|
async getWorkspaceModelRuntime() {
|
|
1898
1951
|
if (!this.workspaceModelRuntime) {
|
|
1899
1952
|
this.workspaceModelRuntime = (async () => {
|
|
@@ -1914,34 +1967,84 @@ export class ConsolePiRuntime {
|
|
|
1914
1967
|
/**
|
|
1915
1968
|
* Full OPEN-surface services for inspect UIs. No SessionManager / JSONL.
|
|
1916
1969
|
* Cached without sessionId so todo/goal extensions stay off the shared scope.
|
|
1970
|
+
* P1-A: short TTL + generation invalidation + single-flight concurrency.
|
|
1917
1971
|
*/
|
|
1918
1972
|
async getWorkspaceInspectionServices() {
|
|
1919
|
-
|
|
1920
|
-
|
|
1973
|
+
const now = Date.now();
|
|
1974
|
+
if (this.workspaceInspectionServices &&
|
|
1975
|
+
now - this.workspaceInspectionCachedAt < ConsolePiRuntime.WORKSPACE_INSPECTION_TTL_MS) {
|
|
1976
|
+
try {
|
|
1921
1977
|
const agentDir = await safeGetAgentDir(this.bindings);
|
|
1922
|
-
const
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1978
|
+
const modelsPath = path.join(agentDir, "models.json");
|
|
1979
|
+
const currentModelsVersion = await readModelConfigFileVersion(modelsPath);
|
|
1980
|
+
let prefsMtime;
|
|
1981
|
+
if (this.options.resourcePreferencesPath) {
|
|
1982
|
+
try {
|
|
1983
|
+
prefsMtime = (await stat(this.options.resourcePreferencesPath)).mtimeMs;
|
|
1984
|
+
}
|
|
1985
|
+
catch {
|
|
1986
|
+
prefsMtime = undefined;
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
if (this.workspaceInspectionModelsVersion &&
|
|
1990
|
+
sameModelConfigFileVersion(this.workspaceInspectionModelsVersion, currentModelsVersion) &&
|
|
1991
|
+
this.workspaceInspectionPrefsMtime === prefsMtime) {
|
|
1992
|
+
return this.workspaceInspectionServices;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
catch {
|
|
1996
|
+
// Failed probe: invalidate and recreate.
|
|
1997
|
+
}
|
|
1998
|
+
this.invalidateWorkspaceInspection();
|
|
1999
|
+
}
|
|
2000
|
+
if (this.workspaceInspectionInFlight) {
|
|
2001
|
+
return this.workspaceInspectionInFlight;
|
|
1943
2002
|
}
|
|
1944
|
-
|
|
2003
|
+
const promise = (async () => {
|
|
2004
|
+
const agentDir = await safeGetAgentDir(this.bindings);
|
|
2005
|
+
const modelsPath = path.join(agentDir, "models.json");
|
|
2006
|
+
const currentModelsVersion = await readModelConfigFileVersion(modelsPath);
|
|
2007
|
+
let prefsMtime;
|
|
2008
|
+
if (this.options.resourcePreferencesPath) {
|
|
2009
|
+
try {
|
|
2010
|
+
prefsMtime = (await stat(this.options.resourcePreferencesPath)).mtimeMs;
|
|
2011
|
+
}
|
|
2012
|
+
catch {
|
|
2013
|
+
prefsMtime = undefined;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
const appendSystemPrompt = composeChatSystemPromptParts({
|
|
2017
|
+
sessionMode: DEFAULT_CONSOLE_CHAT_SESSION_MODE,
|
|
2018
|
+
workflowPrompt: OPERATOR_CHAT_SYSTEM_PROMPT_BASE,
|
|
2019
|
+
});
|
|
2020
|
+
const { services } = await this.bindings.createServices({
|
|
2021
|
+
cwd: this.options.cwd,
|
|
2022
|
+
agentDir,
|
|
2023
|
+
resourceLoaderOptions: await this.buildResourceLoaderOptions({
|
|
2024
|
+
appendSystemPrompt,
|
|
2025
|
+
}),
|
|
2026
|
+
});
|
|
2027
|
+
const inspectionServices = {
|
|
2028
|
+
modelRuntime: services.modelRuntime,
|
|
2029
|
+
resourceLoader: services
|
|
2030
|
+
.resourceLoader,
|
|
2031
|
+
settingsManager: services.settingsManager,
|
|
2032
|
+
};
|
|
2033
|
+
this.workspaceInspectionServices = inspectionServices;
|
|
2034
|
+
this.workspaceInspectionCachedAt = Date.now();
|
|
2035
|
+
this.workspaceInspectionModelsVersion = currentModelsVersion;
|
|
2036
|
+
this.workspaceInspectionPrefsMtime = prefsMtime;
|
|
2037
|
+
return inspectionServices;
|
|
2038
|
+
})()
|
|
2039
|
+
.catch((error) => {
|
|
2040
|
+
this.invalidateWorkspaceInspection();
|
|
2041
|
+
throw error;
|
|
2042
|
+
})
|
|
2043
|
+
.finally(() => {
|
|
2044
|
+
this.workspaceInspectionInFlight = null;
|
|
2045
|
+
});
|
|
2046
|
+
this.workspaceInspectionInFlight = promise;
|
|
2047
|
+
return promise;
|
|
1945
2048
|
}
|
|
1946
2049
|
async listModels(sessionId) {
|
|
1947
2050
|
const live = this.modelRuntimes.get(sessionId);
|
|
@@ -2274,6 +2377,15 @@ export class ConsolePiRuntime {
|
|
|
2274
2377
|
}
|
|
2275
2378
|
async getRuntimeSnapshot(sessionId, options) {
|
|
2276
2379
|
const initializing = this.sessionInit.get(sessionId)?.status === "initializing";
|
|
2380
|
+
// Inspect GETs that supplied a durable `workspaceProjection` must not wait
|
|
2381
|
+
// for extension `session_start`: the model selector and context overview
|
|
2382
|
+
// render from the cached workspace ResourceLoader/ModelRuntime instead.
|
|
2383
|
+
// Direct `getRuntimeSnapshot(sessionId)` (no projection) keeps the
|
|
2384
|
+
// blocking `ensureSessionReady` contract, including
|
|
2385
|
+
// PiSessionInitFailedError, for callers that need the live Agent.
|
|
2386
|
+
if (initializing && options?.workspaceProjection) {
|
|
2387
|
+
return this.projectWorkspaceRuntimeSnapshot(sessionId, options);
|
|
2388
|
+
}
|
|
2277
2389
|
if (this.sessions.has(sessionId) || initializing) {
|
|
2278
2390
|
try {
|
|
2279
2391
|
await this.ensureSessionReady(sessionId);
|
|
@@ -2434,52 +2546,89 @@ export class ConsolePiRuntime {
|
|
|
2434
2546
|
const thinkingSelection = this.resolveWorkspaceThinkingSelection(sessionId, hint.thinkingLevel);
|
|
2435
2547
|
const effectiveThinkingLevel = settingsManager?.getDefaultThinkingLevel?.() ??
|
|
2436
2548
|
(thinkingSelection === "auto" ? undefined : thinkingSelection);
|
|
2437
|
-
const
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
let models = [];
|
|
2446
|
-
try {
|
|
2447
|
-
models = this.bindings
|
|
2448
|
-
.listAvailableModels({ modelRuntime: inspection.modelRuntime })
|
|
2449
|
-
.map((entry) => ({
|
|
2450
|
-
provider: entry.provider,
|
|
2451
|
-
id: entry.id,
|
|
2452
|
-
...(entry.name ? { name: entry.name } : {}),
|
|
2453
|
-
hasCredentials: entry.hasCredentials,
|
|
2454
|
-
}));
|
|
2455
|
-
}
|
|
2456
|
-
catch (error) {
|
|
2457
|
-
throw new RuntimeSnapshotUnavailableError(`model enumeration failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
2458
|
-
}
|
|
2459
|
-
const thinkingLevels = [
|
|
2460
|
-
{ value: "auto" },
|
|
2461
|
-
...THINKING_LEVELS.map((value) => ({ value })),
|
|
2462
|
-
];
|
|
2463
|
-
let skillPrefs = { schemaVersion: 1, skills: {} };
|
|
2464
|
-
let skillPrefsError;
|
|
2465
|
-
if (resourceLoader) {
|
|
2466
|
-
try {
|
|
2467
|
-
skillPrefs = await this.loadSkillAutoInvocationPreferences();
|
|
2549
|
+
const now = Date.now();
|
|
2550
|
+
let template = this.workspaceSnapshotTemplates.get(sessionMode);
|
|
2551
|
+
if (!template ||
|
|
2552
|
+
template.generation !== this.workspaceInspectionGeneration ||
|
|
2553
|
+
now - template.cachedAt >= ConsolePiRuntime.WORKSPACE_INSPECTION_TTL_MS) {
|
|
2554
|
+
const existingInFlight = this.workspaceSnapshotInFlight.get(sessionMode);
|
|
2555
|
+
if (existingInFlight) {
|
|
2556
|
+
template = await existingInFlight;
|
|
2468
2557
|
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2558
|
+
else {
|
|
2559
|
+
const promise = (async () => {
|
|
2560
|
+
const rawSystemPrompt = resourceLoader?.getSystemPrompt?.() ||
|
|
2561
|
+
composeChatSystemPrompt({
|
|
2562
|
+
sessionMode,
|
|
2563
|
+
workflowPrompt: OPERATOR_CHAT_SYSTEM_PROMPT_BASE,
|
|
2564
|
+
});
|
|
2565
|
+
if (!rawSystemPrompt) {
|
|
2566
|
+
throw new RuntimeSnapshotUnavailableError("system prompt projection failed: workspace prompt was empty");
|
|
2567
|
+
}
|
|
2568
|
+
let models = [];
|
|
2569
|
+
try {
|
|
2570
|
+
models = this.bindings
|
|
2571
|
+
.listAvailableModels({ modelRuntime: inspection.modelRuntime })
|
|
2572
|
+
.map((entry) => ({
|
|
2573
|
+
provider: entry.provider,
|
|
2574
|
+
id: entry.id,
|
|
2575
|
+
...(entry.name ? { name: entry.name } : {}),
|
|
2576
|
+
hasCredentials: entry.hasCredentials,
|
|
2577
|
+
}));
|
|
2578
|
+
}
|
|
2579
|
+
catch (error) {
|
|
2580
|
+
throw new RuntimeSnapshotUnavailableError(`model enumeration failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
2581
|
+
}
|
|
2582
|
+
const thinkingLevels = [
|
|
2583
|
+
{ value: "auto" },
|
|
2584
|
+
...THINKING_LEVELS.map((value) => ({ value })),
|
|
2585
|
+
];
|
|
2586
|
+
let skillPrefs = { schemaVersion: 1, skills: {} };
|
|
2587
|
+
let skillPrefsError;
|
|
2588
|
+
if (resourceLoader) {
|
|
2589
|
+
try {
|
|
2590
|
+
skillPrefs = await this.loadSkillAutoInvocationPreferences();
|
|
2591
|
+
}
|
|
2592
|
+
catch (error) {
|
|
2593
|
+
skillPrefsError = error;
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
const activeTools = chatActiveToolBaseline(sessionMode);
|
|
2597
|
+
const inventories = await collectRuntimeInventories({
|
|
2598
|
+
resourceLoader,
|
|
2599
|
+
skillPrefs,
|
|
2600
|
+
skillPrefsError,
|
|
2601
|
+
agentDir: await safeGetAgentDir(this.bindings),
|
|
2602
|
+
cwd: this.options.cwd,
|
|
2603
|
+
tools: [],
|
|
2604
|
+
activeToolNames: activeTools,
|
|
2605
|
+
});
|
|
2606
|
+
const createdTemplate = {
|
|
2607
|
+
models,
|
|
2608
|
+
thinkingLevels,
|
|
2609
|
+
rawSystemPrompt,
|
|
2610
|
+
activeTools,
|
|
2611
|
+
contextFiles: inventories.contextFiles,
|
|
2612
|
+
skills: inventories.skills,
|
|
2613
|
+
extensions: inventories.extensions,
|
|
2614
|
+
packages: inventories.packages,
|
|
2615
|
+
mcp: inventories.mcp,
|
|
2616
|
+
diagnostics: inventories.diagnostics,
|
|
2617
|
+
cachedAt: Date.now(),
|
|
2618
|
+
generation: this.workspaceInspectionGeneration,
|
|
2619
|
+
};
|
|
2620
|
+
this.workspaceSnapshotTemplates.set(sessionMode, createdTemplate);
|
|
2621
|
+
return createdTemplate;
|
|
2622
|
+
})().finally(() => {
|
|
2623
|
+
this.workspaceSnapshotInFlight.delete(sessionMode);
|
|
2624
|
+
});
|
|
2625
|
+
this.workspaceSnapshotInFlight.set(sessionMode, promise);
|
|
2626
|
+
template = await promise;
|
|
2471
2627
|
}
|
|
2472
2628
|
}
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
skillPrefs,
|
|
2477
|
-
skillPrefsError,
|
|
2478
|
-
agentDir: await safeGetAgentDir(this.bindings),
|
|
2479
|
-
cwd: this.options.cwd,
|
|
2480
|
-
tools: [],
|
|
2481
|
-
activeToolNames: activeTools,
|
|
2482
|
-
});
|
|
2629
|
+
if (!template) {
|
|
2630
|
+
throw new RuntimeSnapshotUnavailableError("workspace snapshot template missing");
|
|
2631
|
+
}
|
|
2483
2632
|
const storedModel = this.sessionModels.get(sessionId);
|
|
2484
2633
|
const provider = storedModel?.provider ?? hint.modelProvider;
|
|
2485
2634
|
const modelId = storedModel?.modelId ?? hint.modelId;
|
|
@@ -2496,21 +2645,21 @@ export class ConsolePiRuntime {
|
|
|
2496
2645
|
? { effectiveThinkingLevel: effectiveThinkingLevel }
|
|
2497
2646
|
: {}),
|
|
2498
2647
|
},
|
|
2499
|
-
models,
|
|
2500
|
-
thinkingLevels,
|
|
2648
|
+
models: template.models,
|
|
2649
|
+
thinkingLevels: template.thinkingLevels,
|
|
2501
2650
|
systemPrompt: {
|
|
2502
|
-
...(options.includeRaw ? { raw: rawSystemPrompt } : {}),
|
|
2503
|
-
text: rawSystemPrompt,
|
|
2504
|
-
sha256: createHash("sha256").update(rawSystemPrompt).digest("hex"),
|
|
2505
|
-
characters: rawSystemPrompt.length,
|
|
2651
|
+
...(options.includeRaw ? { raw: template.rawSystemPrompt } : {}),
|
|
2652
|
+
text: template.rawSystemPrompt,
|
|
2653
|
+
sha256: createHash("sha256").update(template.rawSystemPrompt).digest("hex"),
|
|
2654
|
+
characters: template.rawSystemPrompt.length,
|
|
2506
2655
|
},
|
|
2507
|
-
activeTools,
|
|
2508
|
-
contextFiles:
|
|
2509
|
-
skills:
|
|
2510
|
-
extensions:
|
|
2511
|
-
packages:
|
|
2512
|
-
mcp:
|
|
2513
|
-
diagnostics:
|
|
2656
|
+
activeTools: template.activeTools,
|
|
2657
|
+
contextFiles: template.contextFiles,
|
|
2658
|
+
skills: template.skills,
|
|
2659
|
+
extensions: template.extensions,
|
|
2660
|
+
packages: template.packages,
|
|
2661
|
+
mcp: template.mcp,
|
|
2662
|
+
diagnostics: template.diagnostics,
|
|
2514
2663
|
hasBash: true,
|
|
2515
2664
|
});
|
|
2516
2665
|
}
|
|
@@ -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,
|