gsd-pi 2.70.1-dev.3591dcf → 2.70.1-dev.3e19108
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/dist/resources/extensions/claude-code-cli/stream-adapter.js +2 -0
- package/dist/resources/extensions/gsd/auto-start.js +3 -11
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +4 -0
- package/dist/resources/extensions/gsd/guided-flow.js +12 -10
- package/dist/resources/extensions/gsd/init-wizard.js +3 -11
- package/dist/resources/extensions/gsd/prompts/discuss.md +31 -13
- package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +34 -0
- package/dist/resources/extensions/gsd/workflow-mcp-auto-prep.js +56 -0
- package/dist/resources/extensions/gsd/workflow-mcp.js +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +17 -17
- package/dist/web/standalone/.next/build-manifest.json +3 -3
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/react-loadable-manifest.json +1 -1
- package/dist/web/standalone/.next/required-server-files.json +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +17 -17
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/dist/web/standalone/.next/static/chunks/2826.dd3dc8bbd3025fa5.js +9 -0
- package/dist/web/standalone/.next/static/chunks/{webpack-6e4d7e9a4f57bed4.js → webpack-b868033a5834586d.js} +1 -1
- package/dist/web/standalone/server.js +1 -1
- package/package.json +1 -1
- package/packages/mcp-server/dist/env-writer.d.ts +39 -0
- package/packages/mcp-server/dist/env-writer.d.ts.map +1 -0
- package/packages/mcp-server/dist/env-writer.js +158 -0
- package/packages/mcp-server/dist/env-writer.js.map +1 -0
- package/packages/mcp-server/dist/server.d.ts +11 -2
- package/packages/mcp-server/dist/server.d.ts.map +1 -1
- package/packages/mcp-server/dist/server.js +102 -2
- package/packages/mcp-server/dist/server.js.map +1 -1
- package/packages/mcp-server/src/env-writer.test.ts +280 -0
- package/packages/mcp-server/src/env-writer.ts +183 -0
- package/packages/mcp-server/src/secure-env-collect.test.ts +265 -0
- package/packages/mcp-server/src/server.ts +137 -3
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +133 -0
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +58 -21
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +152 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +83 -27
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +2 -0
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +33 -0
- package/src/resources/extensions/gsd/auto-start.ts +3 -13
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +4 -0
- package/src/resources/extensions/gsd/guided-flow.ts +12 -9
- package/src/resources/extensions/gsd/init-wizard.ts +3 -13
- package/src/resources/extensions/gsd/prompts/discuss.md +31 -13
- package/src/resources/extensions/gsd/tests/discuss-incremental-persistence.test.ts +9 -0
- package/src/resources/extensions/gsd/tests/workflow-mcp-auto-prep.test.ts +76 -0
- package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +155 -1
- package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +22 -0
- package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +60 -25
- package/src/resources/extensions/gsd/workflow-mcp-auto-prep.ts +76 -0
- package/src/resources/extensions/gsd/workflow-mcp.ts +1 -1
- package/dist/web/standalone/.next/static/chunks/2826.821e01b07d92e948.js +0 -9
- /package/dist/web/standalone/.next/static/{KdlODhIktLmeRKpLpHdKb → cHCEWiRJM5bXJa9HkP1QU}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{KdlODhIktLmeRKpLpHdKb → cHCEWiRJM5bXJa9HkP1QU}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { handleAgentEvent } from "../modes/interactive/controllers/chat-controller.js";
|
|
4
|
+
function makeUsage() {
|
|
5
|
+
return {
|
|
6
|
+
input: 0,
|
|
7
|
+
output: 0,
|
|
8
|
+
cacheRead: 0,
|
|
9
|
+
cacheWrite: 0,
|
|
10
|
+
totalTokens: 0,
|
|
11
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function makeAssistant(content) {
|
|
15
|
+
return {
|
|
16
|
+
role: "assistant",
|
|
17
|
+
content,
|
|
18
|
+
api: "anthropic-messages",
|
|
19
|
+
provider: "claude-code",
|
|
20
|
+
model: "claude-sonnet-4",
|
|
21
|
+
usage: makeUsage(),
|
|
22
|
+
stopReason: "stop",
|
|
23
|
+
timestamp: Date.now(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function createHost() {
|
|
27
|
+
const chatContainer = {
|
|
28
|
+
children: [],
|
|
29
|
+
addChild(component) {
|
|
30
|
+
this.children.push(component);
|
|
31
|
+
},
|
|
32
|
+
removeChild(component) {
|
|
33
|
+
const idx = this.children.indexOf(component);
|
|
34
|
+
if (idx !== -1)
|
|
35
|
+
this.children.splice(idx, 1);
|
|
36
|
+
},
|
|
37
|
+
clear() {
|
|
38
|
+
this.children = [];
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const host = {
|
|
42
|
+
isInitialized: true,
|
|
43
|
+
init: async () => { },
|
|
44
|
+
defaultEditor: { onEscape: undefined },
|
|
45
|
+
editor: {},
|
|
46
|
+
session: { retryAttempt: 0, abortCompaction: () => { }, abortRetry: () => { } },
|
|
47
|
+
ui: { requestRender: () => { } },
|
|
48
|
+
footer: { invalidate: () => { } },
|
|
49
|
+
keybindings: {},
|
|
50
|
+
statusContainer: { clear: () => { }, addChild: () => { } },
|
|
51
|
+
chatContainer,
|
|
52
|
+
settingsManager: { getTimestampFormat: () => "date-time-iso", getShowImages: () => false },
|
|
53
|
+
pendingTools: new Map(),
|
|
54
|
+
toolOutputExpanded: false,
|
|
55
|
+
hideThinkingBlock: false,
|
|
56
|
+
isBashMode: false,
|
|
57
|
+
defaultWorkingMessage: "Working...",
|
|
58
|
+
compactionQueuedMessages: [],
|
|
59
|
+
editorContainer: {},
|
|
60
|
+
pendingMessagesContainer: { clear: () => { } },
|
|
61
|
+
addMessageToChat: () => { },
|
|
62
|
+
getMarkdownThemeWithSettings: () => ({}),
|
|
63
|
+
formatWebSearchResult: () => "",
|
|
64
|
+
getRegisteredToolDefinition: () => undefined,
|
|
65
|
+
checkShutdownRequested: async () => { },
|
|
66
|
+
rebuildChatFromMessages: () => { },
|
|
67
|
+
flushCompactionQueue: async () => { },
|
|
68
|
+
showStatus: () => { },
|
|
69
|
+
showError: () => { },
|
|
70
|
+
updatePendingMessagesDisplay: () => { },
|
|
71
|
+
updateTerminalTitle: () => { },
|
|
72
|
+
updateEditorBorderColor: () => { },
|
|
73
|
+
};
|
|
74
|
+
return host;
|
|
75
|
+
}
|
|
76
|
+
test("chat-controller keeps tool output ahead of delayed assistant text for external tool streams", async () => {
|
|
77
|
+
// ToolExecutionComponent uses the global theme singleton.
|
|
78
|
+
// Install a minimal no-op theme implementation for this unit test.
|
|
79
|
+
globalThis[Symbol.for("@gsd/pi-coding-agent:theme")] = {
|
|
80
|
+
fg: (_key, text) => text,
|
|
81
|
+
bg: (_key, text) => text,
|
|
82
|
+
bold: (text) => text,
|
|
83
|
+
italic: (text) => text,
|
|
84
|
+
truncate: (text) => text,
|
|
85
|
+
};
|
|
86
|
+
const host = createHost();
|
|
87
|
+
const toolId = "mcp-tool-1";
|
|
88
|
+
const toolCall = {
|
|
89
|
+
type: "toolCall",
|
|
90
|
+
id: toolId,
|
|
91
|
+
name: "exec_command",
|
|
92
|
+
arguments: { cmd: "echo hi" },
|
|
93
|
+
};
|
|
94
|
+
await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) });
|
|
95
|
+
assert.equal(host.streamingComponent, undefined, "assistant component should be deferred at message_start");
|
|
96
|
+
assert.equal(host.chatContainer.children.length, 0, "nothing should render before content arrives");
|
|
97
|
+
await handleAgentEvent(host, {
|
|
98
|
+
type: "message_update",
|
|
99
|
+
message: makeAssistant([toolCall]),
|
|
100
|
+
assistantMessageEvent: {
|
|
101
|
+
type: "toolcall_end",
|
|
102
|
+
contentIndex: 0,
|
|
103
|
+
toolCall: {
|
|
104
|
+
...toolCall,
|
|
105
|
+
externalResult: {
|
|
106
|
+
content: [{ type: "text", text: "tool output" }],
|
|
107
|
+
details: {},
|
|
108
|
+
isError: false,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
partial: makeAssistant([toolCall]),
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
assert.equal(host.streamingComponent, undefined, "assistant text container should remain deferred for tool-only updates");
|
|
115
|
+
assert.equal(host.chatContainer.children.length, 1, "tool execution block should render immediately");
|
|
116
|
+
assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
|
|
117
|
+
// Re-assert required host method before the text-bearing update path.
|
|
118
|
+
host.getMarkdownThemeWithSettings = () => ({});
|
|
119
|
+
await handleAgentEvent(host, {
|
|
120
|
+
type: "message_update",
|
|
121
|
+
message: makeAssistant([toolCall, { type: "text", text: "done" }]),
|
|
122
|
+
assistantMessageEvent: {
|
|
123
|
+
type: "text_delta",
|
|
124
|
+
contentIndex: 1,
|
|
125
|
+
delta: "done",
|
|
126
|
+
partial: makeAssistant([toolCall, { type: "text", text: "done" }]),
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
assert.equal(host.chatContainer.children.length, 2, "assistant content should render after existing tool output");
|
|
130
|
+
assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
|
|
131
|
+
assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
|
|
132
|
+
});
|
|
133
|
+
//# sourceMappingURL=chat-controller-ordering.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-controller-ordering.test.js","sourceRoot":"","sources":["../../src/core/chat-controller-ordering.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAC;AAEvF,SAAS,SAAS;IACjB,OAAO;QACN,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,CAAC;QACd,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;KACpE,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,OAAc;IACpC,OAAO;QACN,IAAI,EAAE,WAAW;QACjB,OAAO;QACP,GAAG,EAAE,oBAAoB;QACzB,QAAQ,EAAE,aAAa;QACvB,KAAK,EAAE,iBAAiB;QACxB,KAAK,EAAE,SAAS,EAAE;QAClB,UAAU,EAAE,MAAM;QAClB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACrB,CAAC;AACH,CAAC;AAED,SAAS,UAAU;IAClB,MAAM,aAAa,GAAG;QACrB,QAAQ,EAAE,EAAW;QACrB,QAAQ,CAAC,SAAc;YACtB,IAAI,CAAC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E,WAAW,EAAE,IAAI,EAAE,wBAAwB,CAAC,CAAC;IAE1F,sEAAsE;IACtE,IAAI,CAAC,4BAA4B,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAE/C,MAAM,gBAAgB,CACrB,IAAI,EACJ;QACC,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,aAAa,CAAC,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAClE,qBAAqB,EAAE;YACtB,IAAI,EAAE,YAAY;YAClB,YAAY,EAAE,CAAC;YACf,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,aAAa,CAAC,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;SAClE;KACM,CACR,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,4DAA4D,CAAC,CAAC;IAClH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,wBAAwB,CAAC,CAAC;IAC1F,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,2BAA2B,CAAC,CAAC;AAC9F,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { test } from \"node:test\";\n\nimport { handleAgentEvent } from \"../modes/interactive/controllers/chat-controller.js\";\n\nfunction makeUsage() {\n\treturn {\n\t\tinput: 0,\n\t\toutput: 0,\n\t\tcacheRead: 0,\n\t\tcacheWrite: 0,\n\t\ttotalTokens: 0,\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t};\n}\n\nfunction makeAssistant(content: any[]) {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent,\n\t\tapi: \"anthropic-messages\",\n\t\tprovider: \"claude-code\",\n\t\tmodel: \"claude-sonnet-4\",\n\t\tusage: makeUsage(),\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction createHost() {\n\tconst chatContainer = {\n\t\tchildren: [] as any[],\n\t\taddChild(component: any) {\n\t\t\tthis.children.push(component);\n\t\t},\n\t\tremoveChild(component: any) {\n\t\t\tconst idx = this.children.indexOf(component);\n\t\t\tif (idx !== -1) this.children.splice(idx, 1);\n\t\t},\n\t\tclear() {\n\t\t\tthis.children = [];\n\t\t},\n\t};\n\n\tconst host: any = {\n\t\tisInitialized: true,\n\t\tinit: async () => {},\n\t\tdefaultEditor: { onEscape: undefined },\n\t\teditor: {},\n\t\tsession: { retryAttempt: 0, abortCompaction: () => {}, abortRetry: () => {} },\n\t\tui: { requestRender: () => {} },\n\t\tfooter: { invalidate: () => {} },\n\t\tkeybindings: {},\n\t\tstatusContainer: { clear: () => {}, addChild: () => {} },\n\t\tchatContainer,\n\t\tsettingsManager: { getTimestampFormat: () => \"date-time-iso\", getShowImages: () => false },\n\t\tpendingTools: new Map(),\n\t\ttoolOutputExpanded: false,\n\t\thideThinkingBlock: false,\n\t\tisBashMode: false,\n\t\tdefaultWorkingMessage: \"Working...\",\n\t\tcompactionQueuedMessages: [],\n\t\teditorContainer: {},\n\t\tpendingMessagesContainer: { clear: () => {} },\n\t\taddMessageToChat: () => {},\n\t\tgetMarkdownThemeWithSettings: () => ({}),\n\t\tformatWebSearchResult: () => \"\",\n\t\tgetRegisteredToolDefinition: () => undefined,\n\t\tcheckShutdownRequested: async () => {},\n\t\trebuildChatFromMessages: () => {},\n\t\tflushCompactionQueue: async () => {},\n\t\tshowStatus: () => {},\n\t\tshowError: () => {},\n\t\tupdatePendingMessagesDisplay: () => {},\n\t\tupdateTerminalTitle: () => {},\n\t\tupdateEditorBorderColor: () => {},\n\t};\n\n\treturn host;\n}\n\ntest(\"chat-controller keeps tool output ahead of delayed assistant text for external tool streams\", async () => {\n\t// ToolExecutionComponent uses the global theme singleton.\n\t// Install a minimal no-op theme implementation for this unit test.\n\t(globalThis as any)[Symbol.for(\"@gsd/pi-coding-agent:theme\")] = {\n\t\tfg: (_key: string, text: string) => text,\n\t\tbg: (_key: string, text: string) => text,\n\t\tbold: (text: string) => text,\n\t\titalic: (text: string) => text,\n\t\ttruncate: (text: string) => text,\n\t};\n\n\tconst host = createHost();\n\tconst toolId = \"mcp-tool-1\";\n\tconst toolCall = {\n\t\ttype: \"toolCall\",\n\t\tid: toolId,\n\t\tname: \"exec_command\",\n\t\targuments: { cmd: \"echo hi\" },\n\t};\n\n\tawait handleAgentEvent(host, { type: \"message_start\", message: makeAssistant([]) } as any);\n\n\tassert.equal(host.streamingComponent, undefined, \"assistant component should be deferred at message_start\");\n\tassert.equal(host.chatContainer.children.length, 0, \"nothing should render before content arrives\");\n\n\tawait handleAgentEvent(\n\t\thost,\n\t\t{\n\t\t\ttype: \"message_update\",\n\t\t\tmessage: makeAssistant([toolCall]),\n\t\t\tassistantMessageEvent: {\n\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\tcontentIndex: 0,\n\t\t\t\ttoolCall: {\n\t\t\t\t\t...toolCall,\n\t\t\t\t\texternalResult: {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"tool output\" }],\n\t\t\t\t\t\tdetails: {},\n\t\t\t\t\t\tisError: false,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tpartial: makeAssistant([toolCall]),\n\t\t\t},\n\t\t} as any,\n\t);\n\n\tassert.equal(host.streamingComponent, undefined, \"assistant text container should remain deferred for tool-only updates\");\n\tassert.equal(host.chatContainer.children.length, 1, \"tool execution block should render immediately\");\n\tassert.equal(host.chatContainer.children[0]?.constructor?.name, \"ToolExecutionComponent\");\n\n\t// Re-assert required host method before the text-bearing update path.\n\thost.getMarkdownThemeWithSettings = () => ({});\n\n\tawait handleAgentEvent(\n\t\thost,\n\t\t{\n\t\t\ttype: \"message_update\",\n\t\t\tmessage: makeAssistant([toolCall, { type: \"text\", text: \"done\" }]),\n\t\t\tassistantMessageEvent: {\n\t\t\t\ttype: \"text_delta\",\n\t\t\t\tcontentIndex: 1,\n\t\t\t\tdelta: \"done\",\n\t\t\t\tpartial: makeAssistant([toolCall, { type: \"text\", text: \"done\" }]),\n\t\t\t},\n\t\t} as any,\n\t);\n\n\tassert.equal(host.chatContainer.children.length, 2, \"assistant content should render after existing tool output\");\n\tassert.equal(host.chatContainer.children[0]?.constructor?.name, \"ToolExecutionComponent\");\n\tassert.equal(host.chatContainer.children[1]?.constructor?.name, \"AssistantMessageComponent\");\n});\n"]}
|
package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-controller.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-controller.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAqBnG,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,wBAAwB,GAAG;IACvE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,4BAA4B,EAAE,MAAM,GAAG,CAAC;IACxC,gBAAgB,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACxD,qBAAqB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IACpD,2BAA2B,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC;IACvD,sBAAsB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,uBAAuB,EAAE,MAAM,IAAI,CAAC;IACpC,oBAAoB,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,4BAA4B,EAAE,MAAM,IAAI,CAAC;IACzC,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,uBAAuB,EAAE,MAAM,IAAI,CAAC;IACpC,wBAAwB,EAAE;QAAE,KAAK,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CAChD,EAAE,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkZ7C"}
|
|
@@ -5,6 +5,13 @@ import { ToolExecutionComponent } from "../components/tool-execution.js";
|
|
|
5
5
|
import { appKey } from "../components/keybinding-hints.js";
|
|
6
6
|
// Tracks the last processed content index to avoid re-scanning all blocks on every message_update
|
|
7
7
|
let lastProcessedContentIndex = 0;
|
|
8
|
+
function hasVisibleAssistantContent(message) {
|
|
9
|
+
return message.content.some((c) => (c.type === "text" && typeof c.text === "string" && c.text.trim().length > 0)
|
|
10
|
+
|| (c.type === "thinking" && typeof c.thinking === "string" && c.thinking.trim().length > 0));
|
|
11
|
+
}
|
|
12
|
+
function hasAssistantToolBlocks(message) {
|
|
13
|
+
return message.content.some((c) => c.type === "toolCall" || c.type === "serverToolUse");
|
|
14
|
+
}
|
|
8
15
|
export async function handleAgentEvent(host, event) {
|
|
9
16
|
if (!host.isInitialized) {
|
|
10
17
|
await host.init();
|
|
@@ -78,37 +85,44 @@ export async function handleAgentEvent(host, event) {
|
|
|
78
85
|
host.ui.requestRender();
|
|
79
86
|
}
|
|
80
87
|
else if (event.message.role === "assistant") {
|
|
81
|
-
host.streamingComponent = new AssistantMessageComponent(undefined, host.hideThinkingBlock, host.getMarkdownThemeWithSettings(), host.settingsManager.getTimestampFormat());
|
|
82
88
|
host.streamingMessage = event.message;
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
// External-tool providers can stream multiple assistant turns through
|
|
90
|
+
// one response. Delay component creation until visible assistant text
|
|
91
|
+
// arrives so tool outputs keep chronological ordering.
|
|
85
92
|
host.ui.requestRender();
|
|
86
93
|
}
|
|
87
94
|
break;
|
|
88
95
|
case "message_update":
|
|
89
|
-
if (
|
|
96
|
+
if (event.message.role === "assistant") {
|
|
90
97
|
host.streamingMessage = event.message;
|
|
91
|
-
host.streamingComponent.updateContent(host.streamingMessage);
|
|
92
|
-
// When the stream adapter signals a completed tool call with an
|
|
93
|
-
// external result (from Claude Code SDK), update the pending
|
|
94
|
-
// ToolExecutionComponent immediately so output is visible in
|
|
95
|
-
// real-time instead of waiting for the session to end.
|
|
96
98
|
const innerEvent = event.assistantMessageEvent;
|
|
99
|
+
if (!host.streamingComponent && hasVisibleAssistantContent(host.streamingMessage)) {
|
|
100
|
+
host.streamingComponent = new AssistantMessageComponent(undefined, host.hideThinkingBlock, host.getMarkdownThemeWithSettings(), host.settingsManager.getTimestampFormat());
|
|
101
|
+
host.chatContainer.addChild(host.streamingComponent);
|
|
102
|
+
}
|
|
103
|
+
if (host.streamingComponent) {
|
|
104
|
+
host.streamingComponent.updateContent(host.streamingMessage);
|
|
105
|
+
}
|
|
106
|
+
let externalToolResult;
|
|
97
107
|
if (innerEvent.type === "toolcall_end" && innerEvent.toolCall) {
|
|
98
108
|
const tc = innerEvent.toolCall;
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
+
const ext = tc.externalResult;
|
|
110
|
+
if (ext) {
|
|
111
|
+
externalToolResult = {
|
|
112
|
+
toolCallId: tc.id,
|
|
113
|
+
content: ext.content ?? [{ type: "text", text: "" }],
|
|
114
|
+
details: ext.details ?? {},
|
|
115
|
+
isError: ext.isError ?? false,
|
|
116
|
+
};
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
119
|
const contentBlocks = host.streamingMessage.content;
|
|
120
|
+
// Some adapters reuse a single assistant lifecycle while internally
|
|
121
|
+
// spanning multiple provider turns. When a new turn starts, content
|
|
122
|
+
// length can shrink back to 0/1; reset scan index to avoid skipping.
|
|
123
|
+
if (lastProcessedContentIndex >= contentBlocks.length) {
|
|
124
|
+
lastProcessedContentIndex = 0;
|
|
125
|
+
}
|
|
112
126
|
for (let i = lastProcessedContentIndex; i < contentBlocks.length; i++) {
|
|
113
127
|
const content = contentBlocks[i];
|
|
114
128
|
if (content.type === "toolCall") {
|
|
@@ -150,6 +164,20 @@ export async function handleAgentEvent(host, event) {
|
|
|
150
164
|
}
|
|
151
165
|
}
|
|
152
166
|
}
|
|
167
|
+
// When the stream adapter signals a completed tool call with an
|
|
168
|
+
// external result (from Claude Code SDK), update the pending
|
|
169
|
+
// ToolExecutionComponent immediately so output is visible in
|
|
170
|
+
// real-time instead of waiting for the session to end.
|
|
171
|
+
if (externalToolResult) {
|
|
172
|
+
const component = host.pendingTools.get(externalToolResult.toolCallId);
|
|
173
|
+
if (component) {
|
|
174
|
+
component.updateResult({
|
|
175
|
+
content: externalToolResult.content,
|
|
176
|
+
details: externalToolResult.details,
|
|
177
|
+
isError: externalToolResult.isError,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
153
181
|
// Update index: fully processed blocks won't need re-scanning.
|
|
154
182
|
// Keep the last block's index (it may still be accumulating data),
|
|
155
183
|
// so we re-check it next time but skip all earlier ones.
|
|
@@ -162,7 +190,7 @@ export async function handleAgentEvent(host, event) {
|
|
|
162
190
|
case "message_end":
|
|
163
191
|
if (event.message.role === "user")
|
|
164
192
|
break;
|
|
165
|
-
if (
|
|
193
|
+
if (event.message.role === "assistant") {
|
|
166
194
|
host.streamingMessage = event.message;
|
|
167
195
|
let errorMessage;
|
|
168
196
|
if (host.streamingMessage.stopReason === "aborted") {
|
|
@@ -172,7 +200,16 @@ export async function handleAgentEvent(host, event) {
|
|
|
172
200
|
: "Operation aborted";
|
|
173
201
|
host.streamingMessage.errorMessage = errorMessage;
|
|
174
202
|
}
|
|
175
|
-
|
|
203
|
+
const shouldRenderAssistant = hasVisibleAssistantContent(host.streamingMessage)
|
|
204
|
+
|| ((host.streamingMessage.stopReason === "aborted" || host.streamingMessage.stopReason === "error")
|
|
205
|
+
&& !hasAssistantToolBlocks(host.streamingMessage));
|
|
206
|
+
if (!host.streamingComponent && shouldRenderAssistant) {
|
|
207
|
+
host.streamingComponent = new AssistantMessageComponent(undefined, host.hideThinkingBlock, host.getMarkdownThemeWithSettings(), host.settingsManager.getTimestampFormat());
|
|
208
|
+
host.chatContainer.addChild(host.streamingComponent);
|
|
209
|
+
}
|
|
210
|
+
if (host.streamingComponent) {
|
|
211
|
+
host.streamingComponent.updateContent(host.streamingMessage);
|
|
212
|
+
}
|
|
176
213
|
if (host.streamingMessage.stopReason === "aborted" || host.streamingMessage.stopReason === "error") {
|
|
177
214
|
if (!errorMessage) {
|
|
178
215
|
errorMessage = host.streamingMessage.errorMessage || "Error";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-controller.js","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,M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AM,GAAG,CAAC,CAAC;YAC/E,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;QAEP,KAAK,4BAA4B;YAChC,IAAI,CAAC,UAAU,CAAC,eAAe,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjD,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;QAEP,KAAK,0BAA0B;YAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;QAEP,KAAK,yBAAyB;YAC7B,IAAI,CAAC,UAAU,CACd,WAAW,KAAK,CAAC,aAAa,wDAAwD,CACtF,CAAC;YACF,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;IACR,CAAC;AACF,CAAC","sourcesContent":["import { Loader, Spacer, Text } from \"@gsd/pi-tui\";\n\nimport type { InteractiveModeEvent, InteractiveModeStateHost } from \"../interactive-mode-state.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { AssistantMessageComponent } from \"../components/assistant-message.js\";\nimport { ToolExecutionComponent } from \"../components/tool-execution.js\";\nimport { appKey } from \"../components/keybinding-hints.js\";\n\n// Tracks the last processed content index to avoid re-scanning all blocks on every message_update\nlet lastProcessedContentIndex = 0;\n\nexport async function handleAgentEvent(host: InteractiveModeStateHost & {\n\tinit: () => Promise<void>;\n\tgetMarkdownThemeWithSettings: () => any;\n\taddMessageToChat: (message: any, options?: any) => void;\n\tformatWebSearchResult: (content: unknown) => string;\n\tgetRegisteredToolDefinition: (toolName: string) => any;\n\tcheckShutdownRequested: () => Promise<void>;\n\trebuildChatFromMessages: () => void;\n\tflushCompactionQueue: (options?: { willRetry?: boolean }) => Promise<void>;\n\tshowStatus: (message: string) => void;\n\tshowError: (message: string) => void;\n\tupdatePendingMessagesDisplay: () => void;\n\tupdateTerminalTitle: () => void;\n\tupdateEditorBorderColor: () => void;\n\tpendingMessagesContainer: { clear: () => void };\n}, event: InteractiveModeEvent): Promise<void> {\n\tif (!host.isInitialized) {\n\t\tawait host.init();\n\t}\n\n\thost.footer.invalidate();\n\n\t// Reset content index tracker when a new assistant message starts\n\tif (event.type === \"message_start\" && event.message.role === \"assistant\") {\n\t\tlastProcessedContentIndex = 0;\n\t}\n\n\tswitch (event.type) {\n\t\tcase \"session_state_changed\":\n\t\t\tswitch (event.reason) {\n\t\t\t\tcase \"new_session\":\n\t\t\t\tcase \"switch_session\":\n\t\t\t\tcase \"fork\":\n\t\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\t\thost.streamingMessage = undefined;\n\t\t\t\t\thost.pendingTools.clear();\n\t\t\t\t\thost.pendingMessagesContainer.clear();\n\t\t\t\t\thost.compactionQueuedMessages = [];\n\t\t\t\t\thost.rebuildChatFromMessages();\n\t\t\t\t\thost.updatePendingMessagesDisplay();\n\t\t\t\t\thost.updateTerminalTitle();\n\t\t\t\t\thost.updateEditorBorderColor();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tcase \"set_session_name\":\n\t\t\t\t\thost.updateTerminalTitle();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tcase \"set_model\":\n\t\t\t\tcase \"set_thinking_level\":\n\t\t\t\t\thost.updateEditorBorderColor();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tdefault:\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t}\n\t\tcase \"agent_start\":\n\t\t\tif (host.retryEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.retryEscapeHandler;\n\t\t\t\thost.retryEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.retryLoader) {\n\t\t\t\thost.retryLoader.stop();\n\t\t\t\thost.retryLoader = undefined;\n\t\t\t}\n\t\t\tif (host.loadingAnimation) {\n\t\t\t\thost.loadingAnimation.stop();\n\t\t\t}\n\t\t\thost.statusContainer.clear();\n\t\t\thost.loadingAnimation = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"accent\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\thost.defaultWorkingMessage,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.loadingAnimation);\n\t\t\tif (host.pendingWorkingMessage !== undefined) {\n\t\t\t\tif (host.pendingWorkingMessage) {\n\t\t\t\t\thost.loadingAnimation.setMessage(host.pendingWorkingMessage);\n\t\t\t\t}\n\t\t\t\thost.pendingWorkingMessage = undefined;\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"message_start\":\n\t\t\tif (event.message.role === \"custom\") {\n\t\t\t\thost.addMessageToChat(event.message);\n\t\t\t\thost.ui.requestRender();\n\t\t\t} else if (event.message.role === \"user\") {\n\t\t\t\thost.addMessageToChat(event.message);\n\t\t\t\thost.updatePendingMessagesDisplay();\n\t\t\t\thost.ui.requestRender();\n\t\t\t} else if (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingComponent = new AssistantMessageComponent(\n\t\t\t\t\tundefined,\n\t\t\t\t\thost.hideThinkingBlock,\n\t\t\t\t\thost.getMarkdownThemeWithSettings(),\n\t\t\t\t\thost.settingsManager.getTimestampFormat(),\n\t\t\t\t);\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\thost.chatContainer.addChild(host.streamingComponent);\n\t\t\t\thost.streamingComponent.updateContent(host.streamingMessage);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"message_update\":\n\t\t\tif (host.streamingComponent && event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\thost.streamingComponent.updateContent(host.streamingMessage);\n\n\t\t\t\t// When the stream adapter signals a completed tool call with an\n\t\t\t\t// external result (from Claude Code SDK), update the pending\n\t\t\t\t// ToolExecutionComponent immediately so output is visible in\n\t\t\t\t// real-time instead of waiting for the session to end.\n\t\t\t\tconst innerEvent = event.assistantMessageEvent;\n\t\t\t\tif (innerEvent.type === \"toolcall_end\" && innerEvent.toolCall) {\n\t\t\t\t\tconst tc = innerEvent.toolCall as any;\n\t\t\t\t\tconst externalResult = tc.externalResult;\n\t\t\t\t\tif (externalResult) {\n\t\t\t\t\t\tconst component = host.pendingTools.get(tc.id);\n\t\t\t\t\t\tif (component) {\n\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\tcontent: externalResult.content ?? [{ type: \"text\", text: \"\" }],\n\t\t\t\t\t\t\t\tdetails: externalResult.details ?? {},\n\t\t\t\t\t\t\t\tisError: externalResult.isError ?? false,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst contentBlocks = host.streamingMessage.content;\n\t\t\t\tfor (let i = lastProcessedContentIndex; i < contentBlocks.length; i++) {\n\t\t\t\t\tconst content = contentBlocks[i];\n\t\t\t\t\tif (content.type === \"toolCall\") {\n\t\t\t\t\t\tif (!host.pendingTools.has(content.id)) {\n\t\t\t\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\t\t\t\tcontent.name,\n\t\t\t\t\t\t\t\tcontent.arguments,\n\t\t\t\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\t\t\t\thost.getRegisteredToolDefinition(content.name),\n\t\t\t\t\t\t\t\thost.ui,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\t\t\t\thost.pendingTools.set(content.id, component);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\thost.pendingTools.get(content.id)?.updateArgs(content.arguments);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (content.type === \"serverToolUse\") {\n\t\t\t\t\t\tif (!host.pendingTools.has(content.id)) {\n\t\t\t\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\t\t\t\tcontent.name,\n\t\t\t\t\t\t\t\tcontent.input ?? {},\n\t\t\t\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\thost.ui,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\t\t\t\thost.pendingTools.set(content.id, component);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (content.type === \"webSearchResult\") {\n\t\t\t\t\t\tconst component = host.pendingTools.get(content.toolUseId);\n\t\t\t\t\t\tif (component) {\n\t\t\t\t\t\t\tif (process.env.PI_OFFLINE === \"1\") {\n\t\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Web search disabled (offline mode)\" }],\n\t\t\t\t\t\t\t\t\tisError: false,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst searchContent = content.content;\n\t\t\t\t\t\t\t\tconst isError = searchContent && typeof searchContent === \"object\" && \"type\" in (searchContent as any) && (searchContent as any).type === \"web_search_tool_result_error\";\n\t\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: host.formatWebSearchResult(searchContent) }],\n\t\t\t\t\t\t\t\t\tisError: !!isError,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Update index: fully processed blocks won't need re-scanning.\n\t\t\t\t// Keep the last block's index (it may still be accumulating data),\n\t\t\t\t// so we re-check it next time but skip all earlier ones.\n\t\t\t\tif (contentBlocks.length > 0) {\n\t\t\t\t\tlastProcessedContentIndex = Math.max(0, contentBlocks.length - 1);\n\t\t\t\t}\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"message_end\":\n\t\t\tif (event.message.role === \"user\") break;\n\t\t\tif (host.streamingComponent && event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\tlet errorMessage: string | undefined;\n\t\t\t\tif (host.streamingMessage.stopReason === \"aborted\") {\n\t\t\t\t\tconst retryAttempt = host.session.retryAttempt;\n\t\t\t\t\terrorMessage = retryAttempt > 0\n\t\t\t\t\t\t? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? \"s\" : \"\"}`\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\t\thost.streamingMessage.errorMessage = errorMessage;\n\t\t\t\t}\n\t\t\t\thost.streamingComponent.updateContent(host.streamingMessage);\n\t\t\t\tif (host.streamingMessage.stopReason === \"aborted\" || host.streamingMessage.stopReason === \"error\") {\n\t\t\t\t\tif (!errorMessage) {\n\t\t\t\t\t\terrorMessage = host.streamingMessage.errorMessage || \"Error\";\n\t\t\t\t\t}\n\t\t\t\t\tfor (const [, component] of host.pendingTools.entries()) {\n\t\t\t\t\t\tcomponent.updateResult({ content: [{ type: \"text\", text: errorMessage }], isError: true });\n\t\t\t\t\t}\n\t\t\t\t\thost.pendingTools.clear();\n\t\t\t\t} else {\n\t\t\t\t\tfor (const [, component] of host.pendingTools.entries()) {\n\t\t\t\t\t\tcomponent.setArgsComplete();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\thost.streamingMessage = undefined;\n\t\t\t\thost.footer.invalidate();\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"tool_execution_start\":\n\t\t\tif (!host.pendingTools.has(event.toolCallId)) {\n\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\tevent.toolName,\n\t\t\t\t\tevent.args,\n\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\thost.getRegisteredToolDefinition(event.toolName),\n\t\t\t\t\thost.ui,\n\t\t\t\t);\n\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\thost.pendingTools.set(event.toolCallId, component);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"tool_execution_update\": {\n\t\t\tconst component = host.pendingTools.get(event.toolCallId);\n\t\t\tif (component) {\n\t\t\t\tcomponent.updateResult({ ...event.partialResult, isError: false }, true);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"tool_execution_end\": {\n\t\t\tconst component = host.pendingTools.get(event.toolCallId);\n\t\t\tif (component) {\n\t\t\t\tcomponent.updateResult({ ...event.result, isError: event.isError });\n\t\t\t\thost.pendingTools.delete(event.toolCallId);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"agent_end\":\n\t\t\tif (host.loadingAnimation) {\n\t\t\t\thost.loadingAnimation.stop();\n\t\t\t\thost.loadingAnimation = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (host.streamingComponent) {\n\t\t\t\thost.chatContainer.removeChild(host.streamingComponent);\n\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\thost.streamingMessage = undefined;\n\t\t\t}\n\t\t\thost.pendingTools.clear();\n\t\t\tawait host.checkShutdownRequested();\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_compaction_start\":\n\t\t\thost.autoCompactionEscapeHandler = host.defaultEditor.onEscape;\n\t\t\thost.defaultEditor.onEscape = () => host.session.abortCompaction();\n\t\t\thost.statusContainer.clear();\n\t\t\thost.autoCompactionLoader = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"accent\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\t`${event.reason === \"overflow\" ? \"Context overflow detected, \" : \"\"}Auto-compacting... (${appKey(host.keybindings, \"interrupt\")} to cancel)`,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.autoCompactionLoader);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_compaction_end\":\n\t\t\tif (host.autoCompactionEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.autoCompactionEscapeHandler;\n\t\t\t\thost.autoCompactionEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.autoCompactionLoader) {\n\t\t\t\thost.autoCompactionLoader.stop();\n\t\t\t\thost.autoCompactionLoader = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (event.aborted) {\n\t\t\t\thost.showStatus(\"Auto-compaction cancelled\");\n\t\t\t} else if (event.result) {\n\t\t\t\thost.chatContainer.clear();\n\t\t\t\thost.rebuildChatFromMessages();\n\t\t\t\thost.addMessageToChat({\n\t\t\t\t\trole: \"compactionSummary\",\n\t\t\t\t\ttokensBefore: event.result.tokensBefore,\n\t\t\t\t\tsummary: event.result.summary,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t});\n\t\t\t\thost.footer.invalidate();\n\t\t\t} else if (event.errorMessage) {\n\t\t\t\thost.chatContainer.addChild(new Spacer(1));\n\t\t\t\thost.chatContainer.addChild(new Text(theme.fg(\"error\", event.errorMessage), 1, 0));\n\t\t\t}\n\t\t\tvoid host.flushCompactionQueue({ willRetry: event.willRetry });\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_retry_start\":\n\t\t\thost.retryEscapeHandler = host.defaultEditor.onEscape;\n\t\t\thost.defaultEditor.onEscape = () => host.session.abortRetry();\n\t\t\thost.statusContainer.clear();\n\t\t\thost.retryLoader = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"warning\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\t`Retrying (${event.attempt}/${event.maxAttempts}) in ${Math.round(event.delayMs / 1000)}s... (${appKey(host.keybindings, \"interrupt\")} to cancel)`,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.retryLoader);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_retry_end\":\n\t\t\tif (host.retryEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.retryEscapeHandler;\n\t\t\t\thost.retryEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.retryLoader) {\n\t\t\t\thost.retryLoader.stop();\n\t\t\t\thost.retryLoader = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (!event.success) {\n\t\t\t\thost.showError(`Retry failed after ${event.attempt} attempts: ${event.finalError || \"Unknown error\"}`);\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_provider_switch\":\n\t\t\thost.showStatus(`Switched from ${event.from} → ${event.to} (${event.reason})`);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_provider_restored\":\n\t\t\thost.showStatus(`Restored to ${event.provider}`);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_chain_exhausted\":\n\t\t\thost.showError(event.reason);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"image_overflow_recovery\":\n\t\t\thost.showStatus(\n\t\t\t\t`Removed ${event.strippedCount} older image(s) to comply with API limits. Retrying...`,\n\t\t\t);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chat-controller.js","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGnD,OA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C,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;IACR,CAAC;AACF,CAAC","sourcesContent":["import { Loader, Spacer, Text } from \"@gsd/pi-tui\";\n\nimport type { InteractiveModeEvent, InteractiveModeStateHost } from \"../interactive-mode-state.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { AssistantMessageComponent } from \"../components/assistant-message.js\";\nimport { ToolExecutionComponent } from \"../components/tool-execution.js\";\nimport { appKey } from \"../components/keybinding-hints.js\";\n\n// Tracks the last processed content index to avoid re-scanning all blocks on every message_update\nlet lastProcessedContentIndex = 0;\n\nfunction hasVisibleAssistantContent(message: { content: Array<any> }): boolean {\n\treturn message.content.some(\n\t\t(c) =>\n\t\t\t(c.type === \"text\" && typeof c.text === \"string\" && c.text.trim().length > 0)\n\t\t\t|| (c.type === \"thinking\" && typeof c.thinking === \"string\" && c.thinking.trim().length > 0),\n\t);\n}\n\nfunction hasAssistantToolBlocks(message: { content: Array<any> }): boolean {\n\treturn message.content.some((c) => c.type === \"toolCall\" || c.type === \"serverToolUse\");\n}\n\nexport async function handleAgentEvent(host: InteractiveModeStateHost & {\n\tinit: () => Promise<void>;\n\tgetMarkdownThemeWithSettings: () => any;\n\taddMessageToChat: (message: any, options?: any) => void;\n\tformatWebSearchResult: (content: unknown) => string;\n\tgetRegisteredToolDefinition: (toolName: string) => any;\n\tcheckShutdownRequested: () => Promise<void>;\n\trebuildChatFromMessages: () => void;\n\tflushCompactionQueue: (options?: { willRetry?: boolean }) => Promise<void>;\n\tshowStatus: (message: string) => void;\n\tshowError: (message: string) => void;\n\tupdatePendingMessagesDisplay: () => void;\n\tupdateTerminalTitle: () => void;\n\tupdateEditorBorderColor: () => void;\n\tpendingMessagesContainer: { clear: () => void };\n}, event: InteractiveModeEvent): Promise<void> {\n\tif (!host.isInitialized) {\n\t\tawait host.init();\n\t}\n\n\thost.footer.invalidate();\n\n\t// Reset content index tracker when a new assistant message starts\n\tif (event.type === \"message_start\" && event.message.role === \"assistant\") {\n\t\tlastProcessedContentIndex = 0;\n\t}\n\n\tswitch (event.type) {\n\t\tcase \"session_state_changed\":\n\t\t\tswitch (event.reason) {\n\t\t\t\tcase \"new_session\":\n\t\t\t\tcase \"switch_session\":\n\t\t\t\tcase \"fork\":\n\t\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\t\thost.streamingMessage = undefined;\n\t\t\t\t\thost.pendingTools.clear();\n\t\t\t\t\thost.pendingMessagesContainer.clear();\n\t\t\t\t\thost.compactionQueuedMessages = [];\n\t\t\t\t\thost.rebuildChatFromMessages();\n\t\t\t\t\thost.updatePendingMessagesDisplay();\n\t\t\t\t\thost.updateTerminalTitle();\n\t\t\t\t\thost.updateEditorBorderColor();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tcase \"set_session_name\":\n\t\t\t\t\thost.updateTerminalTitle();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tcase \"set_model\":\n\t\t\t\tcase \"set_thinking_level\":\n\t\t\t\t\thost.updateEditorBorderColor();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tdefault:\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t}\n\t\tcase \"agent_start\":\n\t\t\tif (host.retryEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.retryEscapeHandler;\n\t\t\t\thost.retryEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.retryLoader) {\n\t\t\t\thost.retryLoader.stop();\n\t\t\t\thost.retryLoader = undefined;\n\t\t\t}\n\t\t\tif (host.loadingAnimation) {\n\t\t\t\thost.loadingAnimation.stop();\n\t\t\t}\n\t\t\thost.statusContainer.clear();\n\t\t\thost.loadingAnimation = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"accent\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\thost.defaultWorkingMessage,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.loadingAnimation);\n\t\t\tif (host.pendingWorkingMessage !== undefined) {\n\t\t\t\tif (host.pendingWorkingMessage) {\n\t\t\t\t\thost.loadingAnimation.setMessage(host.pendingWorkingMessage);\n\t\t\t\t}\n\t\t\t\thost.pendingWorkingMessage = undefined;\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"message_start\":\n\t\t\tif (event.message.role === \"custom\") {\n\t\t\t\thost.addMessageToChat(event.message);\n\t\t\t\thost.ui.requestRender();\n\t\t\t} else if (event.message.role === \"user\") {\n\t\t\t\thost.addMessageToChat(event.message);\n\t\t\t\thost.updatePendingMessagesDisplay();\n\t\t\t\thost.ui.requestRender();\n\t\t\t} else if (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\t// External-tool providers can stream multiple assistant turns through\n\t\t\t\t// one response. Delay component creation until visible assistant text\n\t\t\t\t// arrives so tool outputs keep chronological ordering.\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"message_update\":\n\t\t\tif (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\tconst innerEvent = event.assistantMessageEvent;\n\n\t\t\t\tif (!host.streamingComponent && hasVisibleAssistantContent(host.streamingMessage)) {\n\t\t\t\t\thost.streamingComponent = new AssistantMessageComponent(\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\thost.hideThinkingBlock,\n\t\t\t\t\t\thost.getMarkdownThemeWithSettings(),\n\t\t\t\t\t\thost.settingsManager.getTimestampFormat(),\n\t\t\t\t\t);\n\t\t\t\t\thost.chatContainer.addChild(host.streamingComponent);\n\t\t\t\t}\n\t\t\t\tif (host.streamingComponent) {\n\t\t\t\t\thost.streamingComponent.updateContent(host.streamingMessage);\n\t\t\t\t}\n\n\t\t\t\tlet externalToolResult:\n\t\t\t\t\t| { toolCallId: string; content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; details: Record<string, unknown>; isError: boolean }\n\t\t\t\t\t| undefined;\n\t\t\t\tif (innerEvent.type === \"toolcall_end\" && innerEvent.toolCall) {\n\t\t\t\t\tconst tc = innerEvent.toolCall as any;\n\t\t\t\t\tconst ext = tc.externalResult;\n\t\t\t\t\tif (ext) {\n\t\t\t\t\t\texternalToolResult = {\n\t\t\t\t\t\t\ttoolCallId: tc.id,\n\t\t\t\t\t\t\tcontent: ext.content ?? [{ type: \"text\", text: \"\" }],\n\t\t\t\t\t\t\tdetails: ext.details ?? {},\n\t\t\t\t\t\t\tisError: ext.isError ?? false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst contentBlocks = host.streamingMessage.content;\n\t\t\t\t// Some adapters reuse a single assistant lifecycle while internally\n\t\t\t\t// spanning multiple provider turns. When a new turn starts, content\n\t\t\t\t// length can shrink back to 0/1; reset scan index to avoid skipping.\n\t\t\t\tif (lastProcessedContentIndex >= contentBlocks.length) {\n\t\t\t\t\tlastProcessedContentIndex = 0;\n\t\t\t\t}\n\t\t\t\tfor (let i = lastProcessedContentIndex; i < contentBlocks.length; i++) {\n\t\t\t\t\tconst content = contentBlocks[i];\n\t\t\t\t\tif (content.type === \"toolCall\") {\n\t\t\t\t\t\tif (!host.pendingTools.has(content.id)) {\n\t\t\t\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\t\t\t\tcontent.name,\n\t\t\t\t\t\t\t\tcontent.arguments,\n\t\t\t\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\t\t\t\thost.getRegisteredToolDefinition(content.name),\n\t\t\t\t\t\t\t\thost.ui,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\t\t\t\thost.pendingTools.set(content.id, component);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\thost.pendingTools.get(content.id)?.updateArgs(content.arguments);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (content.type === \"serverToolUse\") {\n\t\t\t\t\t\tif (!host.pendingTools.has(content.id)) {\n\t\t\t\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\t\t\t\tcontent.name,\n\t\t\t\t\t\t\t\tcontent.input ?? {},\n\t\t\t\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\thost.ui,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\t\t\t\thost.pendingTools.set(content.id, component);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (content.type === \"webSearchResult\") {\n\t\t\t\t\t\tconst component = host.pendingTools.get(content.toolUseId);\n\t\t\t\t\t\tif (component) {\n\t\t\t\t\t\t\tif (process.env.PI_OFFLINE === \"1\") {\n\t\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Web search disabled (offline mode)\" }],\n\t\t\t\t\t\t\t\t\tisError: false,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst searchContent = content.content;\n\t\t\t\t\t\t\t\tconst isError = searchContent && typeof searchContent === \"object\" && \"type\" in (searchContent as any) && (searchContent as any).type === \"web_search_tool_result_error\";\n\t\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: host.formatWebSearchResult(searchContent) }],\n\t\t\t\t\t\t\t\t\tisError: !!isError,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// When the stream adapter signals a completed tool call with an\n\t\t\t\t// external result (from Claude Code SDK), update the pending\n\t\t\t\t// ToolExecutionComponent immediately so output is visible in\n\t\t\t\t// real-time instead of waiting for the session to end.\n\t\t\t\tif (externalToolResult) {\n\t\t\t\t\tconst component = host.pendingTools.get(externalToolResult.toolCallId);\n\t\t\t\t\tif (component) {\n\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\tcontent: externalToolResult.content,\n\t\t\t\t\t\t\tdetails: externalToolResult.details,\n\t\t\t\t\t\t\tisError: externalToolResult.isError,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Update index: fully processed blocks won't need re-scanning.\n\t\t\t\t// Keep the last block's index (it may still be accumulating data),\n\t\t\t\t// so we re-check it next time but skip all earlier ones.\n\t\t\t\tif (contentBlocks.length > 0) {\n\t\t\t\t\tlastProcessedContentIndex = Math.max(0, contentBlocks.length - 1);\n\t\t\t\t}\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"message_end\":\n\t\t\tif (event.message.role === \"user\") break;\n\t\t\tif (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\tlet errorMessage: string | undefined;\n\t\t\t\tif (host.streamingMessage.stopReason === \"aborted\") {\n\t\t\t\t\tconst retryAttempt = host.session.retryAttempt;\n\t\t\t\t\terrorMessage = retryAttempt > 0\n\t\t\t\t\t\t? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? \"s\" : \"\"}`\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\t\thost.streamingMessage.errorMessage = errorMessage;\n\t\t\t\t}\n\n\t\t\t\tconst shouldRenderAssistant = hasVisibleAssistantContent(host.streamingMessage)\n\t\t\t\t\t|| (\n\t\t\t\t\t\t(host.streamingMessage.stopReason === \"aborted\" || host.streamingMessage.stopReason === \"error\")\n\t\t\t\t\t\t&& !hasAssistantToolBlocks(host.streamingMessage)\n\t\t\t\t\t);\n\t\t\t\tif (!host.streamingComponent && shouldRenderAssistant) {\n\t\t\t\t\thost.streamingComponent = new AssistantMessageComponent(\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\thost.hideThinkingBlock,\n\t\t\t\t\t\thost.getMarkdownThemeWithSettings(),\n\t\t\t\t\t\thost.settingsManager.getTimestampFormat(),\n\t\t\t\t\t);\n\t\t\t\t\thost.chatContainer.addChild(host.streamingComponent);\n\t\t\t\t}\n\t\t\t\tif (host.streamingComponent) {\n\t\t\t\t\thost.streamingComponent.updateContent(host.streamingMessage);\n\t\t\t\t}\n\n\t\t\t\tif (host.streamingMessage.stopReason === \"aborted\" || host.streamingMessage.stopReason === \"error\") {\n\t\t\t\t\tif (!errorMessage) {\n\t\t\t\t\t\terrorMessage = host.streamingMessage.errorMessage || \"Error\";\n\t\t\t\t\t}\n\t\t\t\t\tfor (const [, component] of host.pendingTools.entries()) {\n\t\t\t\t\t\tcomponent.updateResult({ content: [{ type: \"text\", text: errorMessage }], isError: true });\n\t\t\t\t\t}\n\t\t\t\t\thost.pendingTools.clear();\n\t\t\t\t} else {\n\t\t\t\t\tfor (const [, component] of host.pendingTools.entries()) {\n\t\t\t\t\t\tcomponent.setArgsComplete();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\thost.streamingMessage = undefined;\n\t\t\t\thost.footer.invalidate();\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"tool_execution_start\":\n\t\t\tif (!host.pendingTools.has(event.toolCallId)) {\n\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\tevent.toolName,\n\t\t\t\t\tevent.args,\n\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\thost.getRegisteredToolDefinition(event.toolName),\n\t\t\t\t\thost.ui,\n\t\t\t\t);\n\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\thost.pendingTools.set(event.toolCallId, component);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"tool_execution_update\": {\n\t\t\tconst component = host.pendingTools.get(event.toolCallId);\n\t\t\tif (component) {\n\t\t\t\tcomponent.updateResult({ ...event.partialResult, isError: false }, true);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"tool_execution_end\": {\n\t\t\tconst component = host.pendingTools.get(event.toolCallId);\n\t\t\tif (component) {\n\t\t\t\tcomponent.updateResult({ ...event.result, isError: event.isError });\n\t\t\t\thost.pendingTools.delete(event.toolCallId);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"agent_end\":\n\t\t\tif (host.loadingAnimation) {\n\t\t\t\thost.loadingAnimation.stop();\n\t\t\t\thost.loadingAnimation = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (host.streamingComponent) {\n\t\t\t\thost.chatContainer.removeChild(host.streamingComponent);\n\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\thost.streamingMessage = undefined;\n\t\t\t}\n\t\t\thost.pendingTools.clear();\n\t\t\tawait host.checkShutdownRequested();\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_compaction_start\":\n\t\t\thost.autoCompactionEscapeHandler = host.defaultEditor.onEscape;\n\t\t\thost.defaultEditor.onEscape = () => host.session.abortCompaction();\n\t\t\thost.statusContainer.clear();\n\t\t\thost.autoCompactionLoader = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"accent\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\t`${event.reason === \"overflow\" ? \"Context overflow detected, \" : \"\"}Auto-compacting... (${appKey(host.keybindings, \"interrupt\")} to cancel)`,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.autoCompactionLoader);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_compaction_end\":\n\t\t\tif (host.autoCompactionEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.autoCompactionEscapeHandler;\n\t\t\t\thost.autoCompactionEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.autoCompactionLoader) {\n\t\t\t\thost.autoCompactionLoader.stop();\n\t\t\t\thost.autoCompactionLoader = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (event.aborted) {\n\t\t\t\thost.showStatus(\"Auto-compaction cancelled\");\n\t\t\t} else if (event.result) {\n\t\t\t\thost.chatContainer.clear();\n\t\t\t\thost.rebuildChatFromMessages();\n\t\t\t\thost.addMessageToChat({\n\t\t\t\t\trole: \"compactionSummary\",\n\t\t\t\t\ttokensBefore: event.result.tokensBefore,\n\t\t\t\t\tsummary: event.result.summary,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t});\n\t\t\t\thost.footer.invalidate();\n\t\t\t} else if (event.errorMessage) {\n\t\t\t\thost.chatContainer.addChild(new Spacer(1));\n\t\t\t\thost.chatContainer.addChild(new Text(theme.fg(\"error\", event.errorMessage), 1, 0));\n\t\t\t}\n\t\t\tvoid host.flushCompactionQueue({ willRetry: event.willRetry });\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_retry_start\":\n\t\t\thost.retryEscapeHandler = host.defaultEditor.onEscape;\n\t\t\thost.defaultEditor.onEscape = () => host.session.abortRetry();\n\t\t\thost.statusContainer.clear();\n\t\t\thost.retryLoader = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"warning\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\t`Retrying (${event.attempt}/${event.maxAttempts}) in ${Math.round(event.delayMs / 1000)}s... (${appKey(host.keybindings, \"interrupt\")} to cancel)`,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.retryLoader);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_retry_end\":\n\t\t\tif (host.retryEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.retryEscapeHandler;\n\t\t\t\thost.retryEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.retryLoader) {\n\t\t\t\thost.retryLoader.stop();\n\t\t\t\thost.retryLoader = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (!event.success) {\n\t\t\t\thost.showError(`Retry failed after ${event.attempt} attempts: ${event.finalError || \"Unknown error\"}`);\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_provider_switch\":\n\t\t\thost.showStatus(`Switched from ${event.from} → ${event.to} (${event.reason})`);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_provider_restored\":\n\t\t\thost.showStatus(`Restored to ${event.provider}`);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_chain_exhausted\":\n\t\t\thost.showError(event.reason);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"image_overflow_recovery\":\n\t\t\thost.showStatus(\n\t\t\t\t`Removed ${event.strippedCount} older image(s) to comply with API limits. Retrying...`,\n\t\t\t);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
|
|
4
|
+
import { handleAgentEvent } from "../modes/interactive/controllers/chat-controller.js";
|
|
5
|
+
|
|
6
|
+
function makeUsage() {
|
|
7
|
+
return {
|
|
8
|
+
input: 0,
|
|
9
|
+
output: 0,
|
|
10
|
+
cacheRead: 0,
|
|
11
|
+
cacheWrite: 0,
|
|
12
|
+
totalTokens: 0,
|
|
13
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function makeAssistant(content: any[]) {
|
|
18
|
+
return {
|
|
19
|
+
role: "assistant",
|
|
20
|
+
content,
|
|
21
|
+
api: "anthropic-messages",
|
|
22
|
+
provider: "claude-code",
|
|
23
|
+
model: "claude-sonnet-4",
|
|
24
|
+
usage: makeUsage(),
|
|
25
|
+
stopReason: "stop",
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createHost() {
|
|
31
|
+
const chatContainer = {
|
|
32
|
+
children: [] as any[],
|
|
33
|
+
addChild(component: any) {
|
|
34
|
+
this.children.push(component);
|
|
35
|
+
},
|
|
36
|
+
removeChild(component: any) {
|
|
37
|
+
const idx = this.children.indexOf(component);
|
|
38
|
+
if (idx !== -1) this.children.splice(idx, 1);
|
|
39
|
+
},
|
|
40
|
+
clear() {
|
|
41
|
+
this.children = [];
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const host: any = {
|
|
46
|
+
isInitialized: true,
|
|
47
|
+
init: async () => {},
|
|
48
|
+
defaultEditor: { onEscape: undefined },
|
|
49
|
+
editor: {},
|
|
50
|
+
session: { retryAttempt: 0, abortCompaction: () => {}, abortRetry: () => {} },
|
|
51
|
+
ui: { requestRender: () => {} },
|
|
52
|
+
footer: { invalidate: () => {} },
|
|
53
|
+
keybindings: {},
|
|
54
|
+
statusContainer: { clear: () => {}, addChild: () => {} },
|
|
55
|
+
chatContainer,
|
|
56
|
+
settingsManager: { getTimestampFormat: () => "date-time-iso", getShowImages: () => false },
|
|
57
|
+
pendingTools: new Map(),
|
|
58
|
+
toolOutputExpanded: false,
|
|
59
|
+
hideThinkingBlock: false,
|
|
60
|
+
isBashMode: false,
|
|
61
|
+
defaultWorkingMessage: "Working...",
|
|
62
|
+
compactionQueuedMessages: [],
|
|
63
|
+
editorContainer: {},
|
|
64
|
+
pendingMessagesContainer: { clear: () => {} },
|
|
65
|
+
addMessageToChat: () => {},
|
|
66
|
+
getMarkdownThemeWithSettings: () => ({}),
|
|
67
|
+
formatWebSearchResult: () => "",
|
|
68
|
+
getRegisteredToolDefinition: () => undefined,
|
|
69
|
+
checkShutdownRequested: async () => {},
|
|
70
|
+
rebuildChatFromMessages: () => {},
|
|
71
|
+
flushCompactionQueue: async () => {},
|
|
72
|
+
showStatus: () => {},
|
|
73
|
+
showError: () => {},
|
|
74
|
+
updatePendingMessagesDisplay: () => {},
|
|
75
|
+
updateTerminalTitle: () => {},
|
|
76
|
+
updateEditorBorderColor: () => {},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return host;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
test("chat-controller keeps tool output ahead of delayed assistant text for external tool streams", async () => {
|
|
83
|
+
// ToolExecutionComponent uses the global theme singleton.
|
|
84
|
+
// Install a minimal no-op theme implementation for this unit test.
|
|
85
|
+
(globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
|
|
86
|
+
fg: (_key: string, text: string) => text,
|
|
87
|
+
bg: (_key: string, text: string) => text,
|
|
88
|
+
bold: (text: string) => text,
|
|
89
|
+
italic: (text: string) => text,
|
|
90
|
+
truncate: (text: string) => text,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const host = createHost();
|
|
94
|
+
const toolId = "mcp-tool-1";
|
|
95
|
+
const toolCall = {
|
|
96
|
+
type: "toolCall",
|
|
97
|
+
id: toolId,
|
|
98
|
+
name: "exec_command",
|
|
99
|
+
arguments: { cmd: "echo hi" },
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
|
|
103
|
+
|
|
104
|
+
assert.equal(host.streamingComponent, undefined, "assistant component should be deferred at message_start");
|
|
105
|
+
assert.equal(host.chatContainer.children.length, 0, "nothing should render before content arrives");
|
|
106
|
+
|
|
107
|
+
await handleAgentEvent(
|
|
108
|
+
host,
|
|
109
|
+
{
|
|
110
|
+
type: "message_update",
|
|
111
|
+
message: makeAssistant([toolCall]),
|
|
112
|
+
assistantMessageEvent: {
|
|
113
|
+
type: "toolcall_end",
|
|
114
|
+
contentIndex: 0,
|
|
115
|
+
toolCall: {
|
|
116
|
+
...toolCall,
|
|
117
|
+
externalResult: {
|
|
118
|
+
content: [{ type: "text", text: "tool output" }],
|
|
119
|
+
details: {},
|
|
120
|
+
isError: false,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
partial: makeAssistant([toolCall]),
|
|
124
|
+
},
|
|
125
|
+
} as any,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
assert.equal(host.streamingComponent, undefined, "assistant text container should remain deferred for tool-only updates");
|
|
129
|
+
assert.equal(host.chatContainer.children.length, 1, "tool execution block should render immediately");
|
|
130
|
+
assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
|
|
131
|
+
|
|
132
|
+
// Re-assert required host method before the text-bearing update path.
|
|
133
|
+
host.getMarkdownThemeWithSettings = () => ({});
|
|
134
|
+
|
|
135
|
+
await handleAgentEvent(
|
|
136
|
+
host,
|
|
137
|
+
{
|
|
138
|
+
type: "message_update",
|
|
139
|
+
message: makeAssistant([toolCall, { type: "text", text: "done" }]),
|
|
140
|
+
assistantMessageEvent: {
|
|
141
|
+
type: "text_delta",
|
|
142
|
+
contentIndex: 1,
|
|
143
|
+
delta: "done",
|
|
144
|
+
partial: makeAssistant([toolCall, { type: "text", text: "done" }]),
|
|
145
|
+
},
|
|
146
|
+
} as any,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
assert.equal(host.chatContainer.children.length, 2, "assistant content should render after existing tool output");
|
|
150
|
+
assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
|
|
151
|
+
assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
|
|
152
|
+
});
|