@f5-sales-demo/xcsh 21.15.0 → 21.16.0
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 +6 -0
- package/package.json +8 -8
- package/src/browser/capabilities.generated.ts +5 -3
- package/src/browser/capabilities.json +4 -2
- package/src/browser/chat-conformance.json +40 -1
- package/src/browser/chat-handler.ts +54 -5
- package/src/browser/chat-protocol.ts +19 -1
- package/src/browser/host-profiles.ts +18 -4
- package/src/edit/renderer.ts +24 -9
- package/src/internal-urls/build-info.generated.ts +8 -8
- package/src/internal-urls/docs-index.generated.ts +1 -1
- package/src/internal-urls/extension-tools.generated.ts +1 -1
- package/src/modes/controllers/btw-controller.ts +2 -7
- package/src/modes/controllers/event-controller.ts +12 -3
- package/src/modes/print-mode.ts +3 -5
- package/src/prompts/system/system-prompt.md +4 -0
- package/src/session/agent-session.ts +49 -31
- package/src/session/final-answer.ts +15 -0
- package/src/task/render.ts +19 -8
- package/src/tools/browser-renderer.ts +20 -18
- package/src/tools/inspect-image-renderer.ts +7 -6
- package/src/tools/read.ts +11 -8
- package/src/tools/render-utils.ts +2 -1
- package/src/tools/write.ts +16 -12
package/CHANGELOG.md
CHANGED
|
@@ -40,6 +40,12 @@
|
|
|
40
40
|
|
|
41
41
|
### Fixed
|
|
42
42
|
|
|
43
|
+
- Prevented malformed task `submit_result` data, non-string write content, and invalid renderer path
|
|
44
|
+
values from crashing task, read, write, edit, inspect-image, or browser output. Semantically
|
|
45
|
+
ported from [can1357/oh-my-pi#1989](https://github.com/can1357/oh-my-pi/pull/1989),
|
|
46
|
+
[#4497](https://github.com/can1357/oh-my-pi/pull/4497), and
|
|
47
|
+
[#4529](https://github.com/can1357/oh-my-pi/pull/4529)
|
|
48
|
+
([#3743](https://github.com/f5-sales-demo/xcsh/issues/3743)).
|
|
43
49
|
- Preserved MCP `structuredContent` through the shared tool bridge, avoided duplicate verbatim
|
|
44
50
|
payloads, and rendered every text block. Semantically ported from
|
|
45
51
|
[can1357/oh-my-pi#10523](https://github.com/can1357/oh-my-pi/pull/10523)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/xcsh",
|
|
4
|
-
"version": "21.
|
|
4
|
+
"version": "21.16.0",
|
|
5
5
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@agentclientprotocol/sdk": "1.3.0",
|
|
64
|
-
"@f5-sales-demo/pi-agent-core": "21.
|
|
65
|
-
"@f5-sales-demo/pi-ai": "21.
|
|
66
|
-
"@f5-sales-demo/pi-natives": "21.
|
|
67
|
-
"@f5-sales-demo/pi-resource-management": "21.
|
|
68
|
-
"@f5-sales-demo/pi-tui": "21.
|
|
69
|
-
"@f5-sales-demo/pi-utils": "21.
|
|
70
|
-
"@f5-sales-demo/xcsh-stats": "21.
|
|
64
|
+
"@f5-sales-demo/pi-agent-core": "21.16.0",
|
|
65
|
+
"@f5-sales-demo/pi-ai": "21.16.0",
|
|
66
|
+
"@f5-sales-demo/pi-natives": "21.16.0",
|
|
67
|
+
"@f5-sales-demo/pi-resource-management": "21.16.0",
|
|
68
|
+
"@f5-sales-demo/pi-tui": "21.16.0",
|
|
69
|
+
"@f5-sales-demo/pi-utils": "21.16.0",
|
|
70
|
+
"@f5-sales-demo/xcsh-stats": "21.16.0",
|
|
71
71
|
"@mozilla/readability": "^0.6",
|
|
72
72
|
"@sinclair/typebox": "^0.34",
|
|
73
73
|
"@xterm/headless": "^6.0",
|
|
@@ -46,7 +46,7 @@ export interface ExtensionCapabilities {
|
|
|
46
46
|
|
|
47
47
|
export const EXTENSION_CAPABILITIES: ExtensionCapabilities = {
|
|
48
48
|
"version": "0.1.0",
|
|
49
|
-
"contractVersion": "2.
|
|
49
|
+
"contractVersion": "2.2.0",
|
|
50
50
|
"multiPortDiscovery": true,
|
|
51
51
|
"protocol": "tool_request/result",
|
|
52
52
|
"tools": [
|
|
@@ -804,7 +804,9 @@ export const EXTENSION_CAPABILITIES: ExtensionCapabilities = {
|
|
|
804
804
|
],
|
|
805
805
|
"messages": [
|
|
806
806
|
"chat_request",
|
|
807
|
+
"chat_message_start",
|
|
807
808
|
"chat_delta",
|
|
809
|
+
"chat_message_end",
|
|
808
810
|
"chat_done",
|
|
809
811
|
"chat_error",
|
|
810
812
|
"chat_stop",
|
|
@@ -821,7 +823,7 @@ export const EXTENSION_CAPABILITIES: ExtensionCapabilities = {
|
|
|
821
823
|
"media_asset_chunk",
|
|
822
824
|
"media_asset_error"
|
|
823
825
|
],
|
|
824
|
-
"description": "User ↔ xcsh chat over the bridge. The extension side panel sends chat_request (with mode and page-context snapshot); xcsh streams chat_delta tokens
|
|
826
|
+
"description": "User ↔ xcsh chat over the bridge. The extension side panel sends chat_request (with mode and page-context snapshot); xcsh streams ordered assistant items using chat_message_start, correlated chat_delta tokens, and chat_message_end. Each item declares commentary or final_answer phase. Exactly one terminal chat_done (with reference links) or chat_error closes the whole turn. Chat ids are prefixed \"c-\". Tool calls during a turn use the normal tool_request flow. chat_stop halts a streaming response. chat_tool_notice is emitted by the EXTENSION (the service worker) to the panel as a best-effort UI signal when a tool runs during a turn — it is NOT sent by xcsh; xcsh must not produce it to avoid double-rendering in the panel. Rich media uses chat_media descriptors and bounded media_asset_read/media_asset_chunk exchanges; media_asset_error reports unavailable assets.",
|
|
825
827
|
"promptHints": {
|
|
826
828
|
"role": "You are xcsh, the AI assistant embedded in the F5 Distributed Cloud (XC) console side panel. The user is viewing a live console page; help them drive automation and understand settings and their purpose.",
|
|
827
829
|
"grounding": "Every user message carries a page-context snapshot: url/path, title, a trimmed accessibility tree, and — when available — the live XC API resource JSON the page loaded (context.api.body). Treat context.api.body as the authoritative current state of the resource and ground answers in it instead of guessing; respect the truncated flags.",
|
|
@@ -839,6 +841,6 @@ export const EXTENSION_CAPABILITIES: ExtensionCapabilities = {
|
|
|
839
841
|
}
|
|
840
842
|
};
|
|
841
843
|
|
|
842
|
-
export const EXTENSION_CONTRACT_VERSION = "2.
|
|
844
|
+
export const EXTENSION_CONTRACT_VERSION = "2.2.0";
|
|
843
845
|
|
|
844
846
|
export const EXTENSION_TOOL_NAMES: readonly string[] = ["ping","capabilities","reload","debug_exec","detach","set_bridge_port","navigate","scroll_to","resize_window","tabs_list","tabs_create","tabs_close","click","click_element","click_xy","type_text","form_input","key_press","select_option","label_select","file_upload","read_ax","get_page_text","query_dom","find","wait_for","assert_text","screenshot","read_console","read_network","diag_suspension","diag_bridges","diag_activation","diag_ttft","wait_for_api_response","get_page_context","javascript_tool","browser_batch","set_explain_mode","annotate"];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "0.1.0",
|
|
3
|
-
"contractVersion": "2.
|
|
3
|
+
"contractVersion": "2.2.0",
|
|
4
4
|
"multiPortDiscovery": true,
|
|
5
5
|
"protocol": "tool_request/result",
|
|
6
6
|
"tools": [
|
|
@@ -758,7 +758,9 @@
|
|
|
758
758
|
],
|
|
759
759
|
"messages": [
|
|
760
760
|
"chat_request",
|
|
761
|
+
"chat_message_start",
|
|
761
762
|
"chat_delta",
|
|
763
|
+
"chat_message_end",
|
|
762
764
|
"chat_done",
|
|
763
765
|
"chat_error",
|
|
764
766
|
"chat_stop",
|
|
@@ -775,7 +777,7 @@
|
|
|
775
777
|
"media_asset_chunk",
|
|
776
778
|
"media_asset_error"
|
|
777
779
|
],
|
|
778
|
-
"description": "User ↔ xcsh chat over the bridge. The extension side panel sends chat_request (with mode and page-context snapshot); xcsh streams chat_delta tokens
|
|
780
|
+
"description": "User ↔ xcsh chat over the bridge. The extension side panel sends chat_request (with mode and page-context snapshot); xcsh streams ordered assistant items using chat_message_start, correlated chat_delta tokens, and chat_message_end. Each item declares commentary or final_answer phase. Exactly one terminal chat_done (with reference links) or chat_error closes the whole turn. Chat ids are prefixed \"c-\". Tool calls during a turn use the normal tool_request flow. chat_stop halts a streaming response. chat_tool_notice is emitted by the EXTENSION (the service worker) to the panel as a best-effort UI signal when a tool runs during a turn — it is NOT sent by xcsh; xcsh must not produce it to avoid double-rendering in the panel. Rich media uses chat_media descriptors and bounded media_asset_read/media_asset_chunk exchanges; media_asset_error reports unavailable assets.",
|
|
779
781
|
"promptHints": {
|
|
780
782
|
"role": "You are xcsh, the AI assistant embedded in the F5 Distributed Cloud (XC) console side panel. The user is viewing a live console page; help them drive automation and understand settings and their purpose.",
|
|
781
783
|
"grounding": "Every user message carries a page-context snapshot: url/path, title, a trimmed accessibility tree, and — when available — the live XC API resource JSON the page loaded (context.api.body). Treat context.api.body as the authoritative current state of the resource and ground answers in it instead of guessing; respect the truncated flags.",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"contractVersion": "2.
|
|
2
|
+
"contractVersion": "2.2.0",
|
|
3
3
|
"schemas": {
|
|
4
4
|
"chat_request": {
|
|
5
5
|
"type": "object",
|
|
@@ -180,11 +180,22 @@
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
},
|
|
183
|
+
"chat_message_start": {
|
|
184
|
+
"type": "object",
|
|
185
|
+
"required": ["type", "id", "itemId", "phase"],
|
|
186
|
+
"properties": {
|
|
187
|
+
"type": { "const": "chat_message_start", "type": "string" },
|
|
188
|
+
"id": { "pattern": "^c-", "type": "string" },
|
|
189
|
+
"itemId": { "minLength": 1, "type": "string" },
|
|
190
|
+
"phase": { "enum": ["commentary", "final_answer"], "type": "string" }
|
|
191
|
+
}
|
|
192
|
+
},
|
|
183
193
|
"chat_delta": {
|
|
184
194
|
"type": "object",
|
|
185
195
|
"required": [
|
|
186
196
|
"type",
|
|
187
197
|
"id",
|
|
198
|
+
"itemId",
|
|
188
199
|
"seq",
|
|
189
200
|
"delta"
|
|
190
201
|
],
|
|
@@ -197,6 +208,10 @@
|
|
|
197
208
|
"pattern": "^c-",
|
|
198
209
|
"type": "string"
|
|
199
210
|
},
|
|
211
|
+
"itemId": {
|
|
212
|
+
"minLength": 1,
|
|
213
|
+
"type": "string"
|
|
214
|
+
},
|
|
200
215
|
"seq": {
|
|
201
216
|
"type": "number"
|
|
202
217
|
},
|
|
@@ -205,6 +220,16 @@
|
|
|
205
220
|
}
|
|
206
221
|
}
|
|
207
222
|
},
|
|
223
|
+
"chat_message_end": {
|
|
224
|
+
"type": "object",
|
|
225
|
+
"required": ["type", "id", "itemId", "phase"],
|
|
226
|
+
"properties": {
|
|
227
|
+
"type": { "const": "chat_message_end", "type": "string" },
|
|
228
|
+
"id": { "pattern": "^c-", "type": "string" },
|
|
229
|
+
"itemId": { "minLength": 1, "type": "string" },
|
|
230
|
+
"phase": { "enum": ["commentary", "final_answer"], "type": "string" }
|
|
231
|
+
}
|
|
232
|
+
},
|
|
208
233
|
"chat_done": {
|
|
209
234
|
"type": "object",
|
|
210
235
|
"required": [
|
|
@@ -1179,18 +1204,32 @@
|
|
|
1179
1204
|
"type": "chat_stop",
|
|
1180
1205
|
"id": "c-1111"
|
|
1181
1206
|
},
|
|
1207
|
+
"chat_message_start": {
|
|
1208
|
+
"type": "chat_message_start",
|
|
1209
|
+
"id": "c-1111",
|
|
1210
|
+
"itemId": "c-1111:assistant:0",
|
|
1211
|
+
"phase": "commentary"
|
|
1212
|
+
},
|
|
1182
1213
|
"chat_delta": {
|
|
1183
1214
|
"type": "chat_delta",
|
|
1184
1215
|
"id": "c-1111",
|
|
1216
|
+
"itemId": "c-1111:assistant:0",
|
|
1185
1217
|
"seq": 0,
|
|
1186
1218
|
"delta": "This LB "
|
|
1187
1219
|
},
|
|
1188
1220
|
"chat_delta_1": {
|
|
1189
1221
|
"type": "chat_delta",
|
|
1190
1222
|
"id": "c-1111",
|
|
1223
|
+
"itemId": "c-1111:assistant:0",
|
|
1191
1224
|
"seq": 1,
|
|
1192
1225
|
"delta": "routes traffic."
|
|
1193
1226
|
},
|
|
1227
|
+
"chat_message_end": {
|
|
1228
|
+
"type": "chat_message_end",
|
|
1229
|
+
"id": "c-1111",
|
|
1230
|
+
"itemId": "c-1111:assistant:0",
|
|
1231
|
+
"phase": "commentary"
|
|
1232
|
+
},
|
|
1194
1233
|
"chat_done": {
|
|
1195
1234
|
"type": "chat_done",
|
|
1196
1235
|
"id": "c-1111",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import type { AssistantMessage, ImageContent } from "@f5-sales-demo/pi-ai";
|
|
3
|
+
import type { AssistantMessage, AssistantMessagePhase, ImageContent } from "@f5-sales-demo/pi-ai";
|
|
4
4
|
import { parseModelString } from "../config/model-resolver";
|
|
5
5
|
import { settings } from "../config/settings";
|
|
6
6
|
import { DEFAULT_MODEL_ROLE } from "../config/settings-schema";
|
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
type ChatErrorReason,
|
|
30
30
|
type ChatKeepalive,
|
|
31
31
|
type ChatMedia,
|
|
32
|
+
type ChatMessageEnd,
|
|
33
|
+
type ChatMessageStart,
|
|
32
34
|
type ChatRequest,
|
|
33
35
|
type Configure,
|
|
34
36
|
type ConfigureAck,
|
|
@@ -77,7 +79,8 @@ export function shouldSendKeepalive(nowMs: number, lastKeepaliveAt: number): boo
|
|
|
77
79
|
|
|
78
80
|
interface ActiveChat {
|
|
79
81
|
id: string;
|
|
80
|
-
seq: number
|
|
82
|
+
items: Map<number, { itemId: string; phase: AssistantMessagePhase; seq: number }>;
|
|
83
|
+
nextItem: number;
|
|
81
84
|
terminalSent: boolean;
|
|
82
85
|
unsubscribe: () => void;
|
|
83
86
|
entryAt: number;
|
|
@@ -215,7 +218,8 @@ export class ChatHandler {
|
|
|
215
218
|
|
|
216
219
|
const chat: ActiveChat = {
|
|
217
220
|
id,
|
|
218
|
-
|
|
221
|
+
items: new Map(),
|
|
222
|
+
nextItem: 0,
|
|
219
223
|
terminalSent: false,
|
|
220
224
|
unsubscribe: () => {},
|
|
221
225
|
entryAt: Date.now(),
|
|
@@ -359,11 +363,44 @@ export class ChatHandler {
|
|
|
359
363
|
|
|
360
364
|
if (event.type === "message_update" && "assistantMessageEvent" in event) {
|
|
361
365
|
const ame = event.assistantMessageEvent;
|
|
362
|
-
if (ame.type === "
|
|
366
|
+
if (ame.type === "text_start") {
|
|
367
|
+
const item = {
|
|
368
|
+
itemId: `${chat.id}:assistant:${chat.nextItem++}`,
|
|
369
|
+
phase: ame.phase ?? "final_answer",
|
|
370
|
+
seq: 0,
|
|
371
|
+
};
|
|
372
|
+
chat.items.set(ame.contentIndex, item);
|
|
373
|
+
this.#server.send({
|
|
374
|
+
type: "chat_message_start",
|
|
375
|
+
id: chat.id,
|
|
376
|
+
itemId: item.itemId,
|
|
377
|
+
phase: item.phase,
|
|
378
|
+
} satisfies ChatMessageStart);
|
|
379
|
+
} else if (ame.type === "text_delta") {
|
|
380
|
+
let item = chat.items.get(ame.contentIndex);
|
|
381
|
+
if (!item) {
|
|
382
|
+
// Legacy/synthetic streams can omit text_start (and older test or proxy
|
|
383
|
+
// emitters can omit partial entirely). Keep that compatibility path
|
|
384
|
+
// deterministic: missing metadata has final-answer semantics.
|
|
385
|
+
const content = ame.partial?.content?.[ame.contentIndex];
|
|
386
|
+
item = {
|
|
387
|
+
itemId: `${chat.id}:assistant:${chat.nextItem++}`,
|
|
388
|
+
phase: content?.type === "text" && content.phase === "commentary" ? "commentary" : "final_answer",
|
|
389
|
+
seq: 0,
|
|
390
|
+
};
|
|
391
|
+
chat.items.set(ame.contentIndex, item);
|
|
392
|
+
this.#server.send({
|
|
393
|
+
type: "chat_message_start",
|
|
394
|
+
id: chat.id,
|
|
395
|
+
itemId: item.itemId,
|
|
396
|
+
phase: item.phase,
|
|
397
|
+
} satisfies ChatMessageStart);
|
|
398
|
+
}
|
|
363
399
|
this.#server.send({
|
|
364
400
|
type: "chat_delta",
|
|
365
401
|
id: chat.id,
|
|
366
|
-
|
|
402
|
+
itemId: item.itemId,
|
|
403
|
+
seq: item.seq++,
|
|
367
404
|
delta: ame.delta,
|
|
368
405
|
} satisfies ChatDelta);
|
|
369
406
|
// TTFT Phase 2: first token out — emit the chat-segment spans once, keyed by
|
|
@@ -375,6 +412,18 @@ export class ChatHandler {
|
|
|
375
412
|
this.#server.send(s);
|
|
376
413
|
}
|
|
377
414
|
}
|
|
415
|
+
} else if (ame.type === "text_end") {
|
|
416
|
+
const item = chat.items.get(ame.contentIndex);
|
|
417
|
+
if (item) {
|
|
418
|
+
item.phase = ame.phase ?? item.phase;
|
|
419
|
+
this.#server.send({
|
|
420
|
+
type: "chat_message_end",
|
|
421
|
+
id: chat.id,
|
|
422
|
+
itemId: item.itemId,
|
|
423
|
+
phase: item.phase,
|
|
424
|
+
} satisfies ChatMessageEnd);
|
|
425
|
+
chat.items.delete(ame.contentIndex);
|
|
426
|
+
}
|
|
378
427
|
} else if (ame.type === "thinking_delta") {
|
|
379
428
|
// LIVENESS: the model is streaming extended thinking before any visible
|
|
380
429
|
// token. Emit a throttled chat_keepalive so the panel re-arms its
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wire protocol types for the Chrome extension chat side window.
|
|
3
|
-
* Contract source of truth: capabilities.json v2.
|
|
3
|
+
* Contract source of truth: capabilities.json v2.2.0.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import type { AssistantMessagePhase } from "@f5-sales-demo/pi-ai";
|
|
6
7
|
// Import the guards + wire types from the PURE leaf modules (not the `../host-tools`
|
|
7
8
|
// barrel), so this browser-safe contract can be consumed by a lib.dom (React)
|
|
8
9
|
// TypeScript program without pulling the RpcHostToolBridge's theme/tool-proxy graph.
|
|
@@ -198,13 +199,30 @@ export interface MediaAssetRead extends MediaAssetReadRequest {
|
|
|
198
199
|
// Outbound messages (xcsh → extension)
|
|
199
200
|
// ---------------------------------------------------------------------------
|
|
200
201
|
|
|
202
|
+
export type { AssistantMessagePhase };
|
|
203
|
+
|
|
204
|
+
export interface ChatMessageStart {
|
|
205
|
+
type: "chat_message_start";
|
|
206
|
+
id: string;
|
|
207
|
+
itemId: string;
|
|
208
|
+
phase: AssistantMessagePhase;
|
|
209
|
+
}
|
|
210
|
+
|
|
201
211
|
export interface ChatDelta {
|
|
202
212
|
type: "chat_delta";
|
|
203
213
|
id: string;
|
|
214
|
+
itemId: string;
|
|
204
215
|
seq: number;
|
|
205
216
|
delta: string;
|
|
206
217
|
}
|
|
207
218
|
|
|
219
|
+
export interface ChatMessageEnd {
|
|
220
|
+
type: "chat_message_end";
|
|
221
|
+
id: string;
|
|
222
|
+
itemId: string;
|
|
223
|
+
phase: AssistantMessagePhase;
|
|
224
|
+
}
|
|
225
|
+
|
|
208
226
|
export interface ChatDone {
|
|
209
227
|
type: "chat_done";
|
|
210
228
|
id: string;
|
|
@@ -40,6 +40,12 @@ export interface HostProfile {
|
|
|
40
40
|
systemPrompt: string;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
const COMMENTARY_POLICY = `COMMENTARY POLICY:
|
|
44
|
+
- No commentary for trivial no-tool work; answer directly.
|
|
45
|
+
- Before non-trivial tool work, emit one concise commentary sentence describing the immediate action.
|
|
46
|
+
- During long work, report meaningful progress at natural intervals and avoid roughly 60 seconds of unexplained silence.
|
|
47
|
+
- Do not narrate every routine read or command. Keep the final answer self-contained.`;
|
|
48
|
+
|
|
43
49
|
/**
|
|
44
50
|
* Chrome-extension self-awareness prompt. Injected when xcsh is serving a browser
|
|
45
51
|
* chat (not the CLI TUI). Tells the LLM it's in a Chrome side panel alongside the
|
|
@@ -48,7 +54,9 @@ export interface HostProfile {
|
|
|
48
54
|
export const CHROME_CHAT_SYSTEM_PROMPT = `<system-directive>
|
|
49
55
|
You are still xcsh, the F5 Distributed Cloud technical coworker defined in your role above; this session is a Chrome side panel alongside the F5 XC console — an additional surface, not a new identity. Keep your xcsh/F5 purpose and adopt this browser context on top of it.
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
${COMMENTARY_POLICY}
|
|
58
|
+
|
|
59
|
+
For questions ("what page am I on?", "what is this?"), answer with text using the page context below — no tools needed. Only use tools when the user explicitly asks you to DO something (create, navigate, click, modify).
|
|
52
60
|
|
|
53
61
|
CONTEXT: The user sees a small chat window alongside the F5 XC admin console. You receive page-aware context each turn: the current URL (interpreted as workspace/resource/CRUD operation/namespace), the API resource JSON, and the accessibility tree. USE THIS CONTEXT to answer questions — don't call tools to find information you already have.
|
|
54
62
|
|
|
@@ -112,7 +120,9 @@ SAFETY:
|
|
|
112
120
|
const EXCEL_CHAT_SYSTEM_PROMPT = `<system-directive>
|
|
113
121
|
You are still xcsh, the F5 Distributed Cloud technical coworker defined in your role above. This session reaches you through a Microsoft Excel task pane instead of the terminal — an additional surface, not a new identity. Help the F5 SE with the OPEN workbook (often demo data, MEDDPICC sheets, account plans, pricing models) using the Excel host tools available to you. Keep your xcsh/F5 purpose AND adopt the Excel context on top of it.
|
|
114
122
|
|
|
115
|
-
|
|
123
|
+
${COMMENTARY_POLICY}
|
|
124
|
+
|
|
125
|
+
Answer questions from the data you read; only WRITE to the workbook when the user asks you to.
|
|
116
126
|
|
|
117
127
|
CONTEXT: Your workspace centers on the open workbook. Think in cells, ranges, and — above all — FORMULAS and their dependencies:
|
|
118
128
|
- Preserve formula relationships. When you change a cell, let dependent cells recompute; do not overwrite a formula with its current value unless asked.
|
|
@@ -143,7 +153,9 @@ BEHAVIOR:
|
|
|
143
153
|
const POWERPOINT_CHAT_SYSTEM_PROMPT = `<system-directive>
|
|
144
154
|
You are still xcsh, the F5 Distributed Cloud technical coworker defined in your role above. This session reaches you through a Microsoft PowerPoint task pane instead of the terminal — an additional surface, not a new identity. Help the F5 SE with the OPEN presentation (often a customer deck, demo walkthrough, or QBR) using the PowerPoint host tools available to you. Keep your xcsh/F5 purpose AND adopt the PowerPoint context on top of it.
|
|
145
155
|
|
|
146
|
-
|
|
156
|
+
${COMMENTARY_POLICY}
|
|
157
|
+
|
|
158
|
+
Answer questions from what you read; only edit the deck when the user asks you to.
|
|
147
159
|
|
|
148
160
|
CONTEXT: Your workspace centers on the open presentation. Think in slides, shapes, and the slide master:
|
|
149
161
|
- Conform any new content to the deck's existing template, fonts, and colors — do not introduce a different look.
|
|
@@ -172,7 +184,9 @@ BEHAVIOR:
|
|
|
172
184
|
const WORD_CHAT_SYSTEM_PROMPT = `<system-directive>
|
|
173
185
|
You are still xcsh, the F5 Distributed Cloud technical coworker defined in your role above. This session reaches you through a Microsoft Word task pane instead of the terminal — an additional surface, not a new identity. Help the F5 SE with the OPEN document (often a proposal, SOW, discovery write-up, or technical brief) using the Word host tools available to you. Keep your xcsh/F5 purpose AND adopt the Word context on top of it.
|
|
174
186
|
|
|
175
|
-
|
|
187
|
+
${COMMENTARY_POLICY}
|
|
188
|
+
|
|
189
|
+
Answer questions from what you read; only edit the document when the user asks you to.
|
|
176
190
|
|
|
177
191
|
CONTEXT: Your workspace centers on the open document. Think in paragraphs, the current selection, comments, and tracked changes:
|
|
178
192
|
- Preserve the document's styles and numbering — do not flatten formatting.
|
package/src/edit/renderer.ts
CHANGED
|
@@ -92,15 +92,15 @@ export interface EditToolDetails {
|
|
|
92
92
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
93
93
|
|
|
94
94
|
interface EditRenderArgs {
|
|
95
|
-
path?:
|
|
96
|
-
file_path?:
|
|
95
|
+
path?: unknown;
|
|
96
|
+
file_path?: unknown;
|
|
97
97
|
oldText?: string;
|
|
98
98
|
newText?: string;
|
|
99
99
|
patch?: string;
|
|
100
100
|
all?: boolean;
|
|
101
101
|
// Patch mode fields
|
|
102
102
|
op?: Operation;
|
|
103
|
-
rename?:
|
|
103
|
+
rename?: unknown;
|
|
104
104
|
diff?: string;
|
|
105
105
|
/**
|
|
106
106
|
* Computed preview diff (used when tool args don't include a diff, e.g. hashline mode).
|
|
@@ -154,8 +154,8 @@ interface FormattedStreamingEdit {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
/** Extract file path from an edit entry's path (handles chunk's file:selector format). */
|
|
157
|
-
function filePathFromEditEntry(p:
|
|
158
|
-
if (!p) return undefined;
|
|
157
|
+
function filePathFromEditEntry(p: unknown): string | undefined {
|
|
158
|
+
if (typeof p !== "string" || !p) return undefined;
|
|
159
159
|
const ci = /^[a-zA-Z]:[/\\]/.test(p) ? p.indexOf(":", 2) : p.indexOf(":");
|
|
160
160
|
return ci === -1 ? p : p.slice(0, ci);
|
|
161
161
|
}
|
|
@@ -441,8 +441,15 @@ export const editToolRenderer = {
|
|
|
441
441
|
|
|
442
442
|
// Extract path from first edit entry when top-level path is absent (new schema)
|
|
443
443
|
const firstEdit = Array.isArray(args.edits) && args.edits.length > 0 ? args.edits[0] : undefined;
|
|
444
|
-
const rawPath =
|
|
445
|
-
|
|
444
|
+
const rawPath =
|
|
445
|
+
typeof args.file_path === "string"
|
|
446
|
+
? args.file_path
|
|
447
|
+
: typeof args.path === "string"
|
|
448
|
+
? args.path
|
|
449
|
+
: (filePathFromEditEntry((firstEdit as { path?: unknown } | undefined)?.path) ?? "");
|
|
450
|
+
const rename =
|
|
451
|
+
(typeof args.rename === "string" ? args.rename : undefined) ??
|
|
452
|
+
filePathFromEditEntry((firstEdit as { rename?: unknown } | undefined)?.rename);
|
|
446
453
|
const op = args.op || (firstEdit as any)?.op;
|
|
447
454
|
const { description } = formatEditDescription(rawPath, uiTheme, { rename });
|
|
448
455
|
const spinner =
|
|
@@ -498,9 +505,17 @@ function renderSingleFileResult(
|
|
|
498
505
|
): Component {
|
|
499
506
|
const details = result.details;
|
|
500
507
|
const isError = result.isError ?? (details && "isError" in details ? details.isError : false);
|
|
501
|
-
const
|
|
508
|
+
const detailPath = details && "path" in details && typeof details.path === "string" ? details.path : undefined;
|
|
509
|
+
const rawPath =
|
|
510
|
+
typeof args?.file_path === "string"
|
|
511
|
+
? args.file_path
|
|
512
|
+
: typeof args?.path === "string"
|
|
513
|
+
? args.path
|
|
514
|
+
: (detailPath ?? "");
|
|
502
515
|
const op = args?.op || details?.op;
|
|
503
|
-
const rename =
|
|
516
|
+
const rename =
|
|
517
|
+
(typeof args?.rename === "string" ? args.rename : undefined) ??
|
|
518
|
+
(details && "move" in details && typeof details.move === "string" ? details.move : undefined);
|
|
504
519
|
const { language } = formatEditDescription(rawPath, uiTheme, { rename });
|
|
505
520
|
|
|
506
521
|
const metadataLine =
|
|
@@ -17,17 +17,17 @@ export interface BuildInfo {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const BUILD_INFO: BuildInfo = {
|
|
20
|
-
"version": "21.
|
|
21
|
-
"commit": "
|
|
22
|
-
"shortCommit": "
|
|
20
|
+
"version": "21.16.0",
|
|
21
|
+
"commit": "2ee9c73e64d26cdd744468c74b92968709a8be86",
|
|
22
|
+
"shortCommit": "2ee9c73",
|
|
23
23
|
"branch": "main",
|
|
24
|
-
"tag": "v21.
|
|
25
|
-
"commitDate": "2026-09-
|
|
26
|
-
"buildDate": "2026-09-
|
|
24
|
+
"tag": "v21.16.0",
|
|
25
|
+
"commitDate": "2026-09-07T04:11:15+00:00",
|
|
26
|
+
"buildDate": "2026-09-07T05:10:58.140Z",
|
|
27
27
|
"dirty": true,
|
|
28
28
|
"prNumber": "",
|
|
29
29
|
"repoUrl": "https://github.com/f5-sales-demo/xcsh",
|
|
30
30
|
"repoSlug": "f5-sales-demo/xcsh",
|
|
31
|
-
"commitUrl": "https://github.com/f5-sales-demo/xcsh/commit/
|
|
32
|
-
"releaseUrl": "https://github.com/f5-sales-demo/xcsh/releases/tag/v21.
|
|
31
|
+
"commitUrl": "https://github.com/f5-sales-demo/xcsh/commit/2ee9c73e64d26cdd744468c74b92968709a8be86",
|
|
32
|
+
"releaseUrl": "https://github.com/f5-sales-demo/xcsh/releases/tag/v21.16.0"
|
|
33
33
|
};
|
|
@@ -14,7 +14,7 @@ export const EMBEDDED_DOCS: Readonly<Record<string, string>> = {
|
|
|
14
14
|
"en/architecture-contribution/storage-artifacts.mdx": "---\ntitle: \"Storage, blobs, and artifacts\"\ndescription: \"Trace configuration roots, session JSONL, binary blobs, text artifacts, scan caches, and move semantics.\"\nsidebar:\n order: 2\n label: \"Storage and artifacts\"\n---\n\nxcsh separates append-only conversation state from large or generated payloads. Session JSON Lines (JSONL) preserves the event graph; blob and artifact stores keep bulky data addressable without inflating every session entry.\n\n## How are stored values allocated and resolved?\n\nStorage helpers choose user or project roots, allocate collision-resistant identifiers, and record names separately from content addresses. Text artifacts remain inspectable; binary blobs are externalized and referenced by uniform resource locator (URL)-like identifiers. URL handlers validate the scheme and authority before opening the backing object.\n\n## How do resume, fork, and move treat state?\n\nResume rebuilds context from the selected session leaf. Forking creates a new branch without rewriting the source branch. Moves must update the session reference and its dependent stored values as one operation or leave the original valid; partial copies are not a successful move.\n\n## How is filesystem discovery cached?\n\nThe scan cache partitions keys by root and discovery options, evicts by freshness policy, and uses a short empty-result recheck so a newly created configuration file is noticed. Mutating code owns invalidation. A new consumer must define its cache key, freshness need, and invalidation points explicitly.\n\nRead `packages/coding-agent/src/session` for the append-only event graph and `packages/coding-agent/src/discovery` for the scan cache.\n",
|
|
15
15
|
"en/architecture-contribution/tool-runtime.mdx": "---\ntitle: \"Tool runtime\"\ndescription: \"Trace Bash, notebook, deferred-action, custom-tool, context, and task-agent execution boundaries.\"\nsidebar:\n order: 3\n label: \"Tool runtime\"\n---\n\nThe agent loop sees a common tool contract, but each runtime owns its validation, cancellation, output, and side effects.\n\n## How do shell and notebook work execute?\n\nThe Bash tool validates the request, launches through the configured shell boundary, streams bounded output, and spills oversized results to an artifact. Notebook editing changes cell structure; kernel execution is a separate Python gateway operation with its own environment and Multipurpose Internet Mail Extensions (MIME) rendering.\n\n## How are deferred actions resolved?\n\nDeferred actions are pushed onto a last-in, first-out stack and resolved only at the runtime checkpoint that owns them. Custom tools use the host application programming interface (API) to register actions; they must pair cancellation and cleanup with any external resource they create.\n\n## How are commands and task agents discovered?\n\nSlash-command templates and agent definitions are discovered from normalized user, project, plugin, and bundled providers. Precedence resolves duplicate identifiers before execution. Argument expansion produces prompt input; it must not bypass tool policy or agent execution guardrails.\n\nRead `packages/coding-agent/src/tools/bash.ts` for the shell boundary, `packages/coding-agent/src/tools/notebook.ts` for cell editing, and `packages/coding-agent/src/slash-commands/builtin-registry.ts` for command discovery.\n",
|
|
16
16
|
"en/architecture-contribution/tui-runtime.mdx": "---\ntitle: \"TUI runtime\"\ndescription: \"Trace component contracts, differential rendering, terminal input, modal UI, and custom tool renderers.\"\nsidebar:\n order: 8\n label: \"TUI runtime\"\n---\n\nThe terminal user interface (TUI) renders session and runtime state through components. Components return terminal cells and semantic styles; the renderer computes a differential update instead of repainting unrelated rows.\n\n## How are input and rendering routed?\n\nTerminal decoding turns bytes and escape sequences into key events. Focused overlays receive input before the prompt editor and global actions. State changes schedule a render, layout produces the next frame, and the diff layer emits only changed terminal regions.\n\n## How do I extend interactive surfaces?\n\nExtensions can open a modal through `ctx.ui.custom` only when an interactive UI host exists. Custom tools may provide renderers for calls and results while preserving a plain-text representation for headless clients. A renderer must not become the only copy of durable tool output.\n\nRead `packages/tui/src` for the component and rendering contracts, and `packages/coding-agent/src/tui` for the session-aware components built on them.\n",
|
|
17
|
-
"en/architecture-contribution/upstream-pi.mdx": "---\ntitle: \"Relationship to pi\"\ndescription: \"Understand what xcsh inherits from pi and where the project deliberately specializes.\"\nsidebar:\n order: 9\n label: \"Relationship to pi\"\n---\n\nxcsh is derived from the open-source pi coding agent and adds F5 Distributed Cloud resource workflows, integrations, packaging, and project-specific governance.\n\n## Which upstream range was reviewed?\n\nThe last proven sync with `can1357/oh-my-pi` was `d350ea60e` on April 9, 2026. The
|
|
17
|
+
"en/architecture-contribution/upstream-pi.mdx": "---\ntitle: \"Relationship to pi\"\ndescription: \"Understand what xcsh inherits from pi and where the project deliberately specializes.\"\nsidebar:\n order: 9\n label: \"Relationship to pi\"\n---\n\nxcsh is derived from the open-source pi coding agent and adds F5 Distributed Cloud resource workflows, integrations, packaging, and project-specific governance.\n\n## Which upstream range was reviewed?\n\nThe last proven sync with `can1357/oh-my-pi` was `d350ea60e` on April 9, 2026. The first-pass\nsecurity and shared-runtime audit reviewed the divergent line through `b2f25dbfe1` on September 5,\n2026. The second-pass TUI and renderer audit extends that lineage through the frozen tip\n`6d3bc569d16cd7351073eaa767caed51021befbb` on September 6, 2026.\nBecause the repositories no longer share a usable linear history, accepted changes are semantic\nports with adapted regressions rather than merges or ancestry-based cherry-picks.\n\n## Which changes were accepted?\n\nThe four implementation waves accepted these upstream pull requests:\n\n| Wave | Upstream pull requests | xcsh delivery |\n| --- | --- | --- |\n| Provider and prompt security | #2147, the opaque-thinking portion of #3239, #7067, and #8727 | #3710 |\n| Configuration and execution security | #7362 and #5636 | #3720 |\n| Core runtime | #7743, #10415, #10523, #10325, and #10550 | #3723 |\n| Terminal and platform | #10613, #10997, #10492, #9233, and #7634 | #3724 |\n| TUI and renderer crash containment | #1989, #4497, #4529, #2047, #5837, and #6788 | #3743 |\n\nThese ports protect provider-bound secrets and compaction boundaries, enforce exact-case\nenvironment references and complete protocol tails, repair Responses replay and shared MCP\nresults, improve rate-limit and retained-string behavior, chain directory completion, extend\npower assertions across supported platforms, and harden stats persistence and network exposure.\nThe source pull requests remain attributable to `can1357/oh-my-pi`; the xcsh deliveries link the\nexact commits and regression evidence.\n\nThe second-pass renderer work normalizes malformed task result data, accepts only strings at path\nboundaries, bounds ANSI-heavy rows before width measurement, and treats terminal disconnect\ncleanup as best effort before SIGHUP. Upstream #5438 is equivalent because `Container.render()`\nalready isolates child-render exceptions; its richer fallback display remains deferred.\n\n## Where does xcsh deliberately diverge?\n\nxcsh retains its own:\n\n- F5-scoped packages, prompts-as-files, tool factories, and capability discovery;\n- SQLite multi-credential storage, multi-account authentication, and provider routing;\n- MCP, SSH, F5 Distributed Cloud, Office, and browser integrations;\n- Bun-first runtime, session semantics, release pipeline, branding, and governance.\n\nPublic interfaces use prerelease clean breaks. In this wave,\n`MacOSPowerAssertion`/`MacOSPowerAssertionOptions` became\n`PowerAssertion`/`PowerAssertionOptions` without aliases, and `power.sleepPrevention` was added with\nan `idle` default.\n\n## What remains excluded or deferred?\n\nUpstream workflows, branding, release machinery, generated model catalogs, compatibility shims,\nnew packages, and large unrelated subsystems are excluded. The security-scan subsystem in #7048\nand the native minimizer in #2176 remain deferred. The range-dashboard optimization in #9327 and\nearendil-works/pi-only fullscreen transcript, mouse, clipboard, and renderer subsystems also remain\noutside this campaign. MCP, OpenCode, Herdr, #10625, and #10491 are explicitly excluded from the\nsecond-pass batch. Commits after the frozen source tip require a later audit.\n\n## How do I decide where a fix belongs?\n\nTrace the affected module and compare it with the pinned upstream lineage. A generic agent-loop\ndefect may belong upstream; an xcsh resource command, integration, or packaging change belongs\nhere.\n\n## How do I preserve attribution?\n\nKeep upstream license notices and document imported changes. Avoid copying a patch blindly across\ndiverged modules; port the behavior with tests against the current xcsh architecture.\n",
|
|
18
18
|
"en/automate-extend/extensions-custom-tools.mdx": "---\ntitle: \"Build extensions and custom tools\"\ndescription: \"Add TypeScript behavior, slash commands, providers, or schema-validated tools.\"\nsidebar:\n order: 3\n label: \"Build extensions and custom tools\"\n---\n\nExtensions load TypeScript behavior with `--extension` or `--hook`; project discovery can also load extensions, tools, hooks, commands, and rules under `.xcsh/`.\n\n## How do I test an extension boundary?\n\nLoad one explicit file with `-e <PATH>` and disable discovery with `--no-extensions`. Confirm its registered command or tool, then test shutdown and error handling.\n\n## Where do hooks and rules belong?\n\nHooks observe or alter lifecycle events; rules add durable instructions. Keep each rule narrow and each hook deterministic. Use `--no-rules` to prove whether a rule changes the result.\n",
|
|
19
19
|
"en/automate-extend/headless-protocols.mdx": "---\ntitle: \"Headless modes\"\ndescription: \"Integrate xcsh with scripts through print, JSON, JSON-RPC, agent client protocol, manager, and worker modes.\"\nsidebar:\n order: 1\n label: \"Headless modes\"\n---\n\nHeadless integrations select `json`, `rpc`, or `acp` with `--mode`: a JavaScript Object Notation (JSON) event stream, JSON remote procedure call (RPC), or the agent client protocol (ACP). Each mode has a different framing contract; consumers must parse that protocol rather than decorated terminal text.\n\n## How do I start with the smallest surface?\n\n```bash\nxcsh --mode json --no-session --no-tools -p \"Return one sentence\"\n```\n\nCapture stdout as protocol data and stderr as diagnostics. Pin the xcsh version in automation and test framing against the exact release.\n\n## When do I use the software development kit (SDK) instead?\n\nUse the SDK when the host process needs in-memory session control, tool registration, or provider events. See [SDK automation](./sdk/).\n",
|
|
20
20
|
"en/automate-extend/hooks-rules.mdx": "---\ntitle: \"Apply hooks and rules\"\ndescription: \"Choose event-driven mutation or declarative prompt guidance and understand discovery precedence.\"\nsidebar:\n order: 4\n label: \"Hooks and rules\"\n---\n\nRules contribute normalized instructions to the prompt. Hooks execute code at named lifecycle events. Use rules for guidance that does not need side effects; use a hook only when an event must inspect, transform, or reject runtime data.\n\n## How are rules discovered and classified?\n\nRule providers scan project and user roots, parse frontmatter, normalize identifiers, then deduplicate by precedence. Classification separates ordinary rulebook entries, always-apply guidance, and time-to-self-reflect material. The `rule://` handler resolves the final normalized item rather than reading an arbitrary path.\n\n## What determines hook execution order?\n\nA hook module exports handlers for supported events. Discovery determines the module set, and registration order determines sequential mutation when more than one handler sees the same payload. A thrown error follows the event's propagation contract; it is not converted into a successful empty result.\n\n## How do I test the hook boundary?\n\nExercise each of these separately:\n\n1. Discovery, so the module set is the one you expect.\n2. The exact event, with a representative payload.\n3. Mutation ordering, with more than one handler registered.\n4. Cancellation.\n5. A handler that throws.\n\nInterface calls made by hooks require an interactive host, so a headless integration must not assume a modal interface exists.\n",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Auto-generated by scripts/generate-extension-capabilities.ts - DO NOT EDIT
|
|
2
2
|
// Source: src/browser/capabilities.json (the Chrome extension's published contract).
|
|
3
3
|
|
|
4
|
-
export const EXTENSION_TOOL_REFERENCE = "# Chrome Extension Tool Signatures\n\nGenerated from extension capability contract `2.
|
|
4
|
+
export const EXTENSION_TOOL_REFERENCE = "# Chrome Extension Tool Signatures\n\nGenerated from extension capability contract `2.2.0`.\n\n## annotation\n\n### `annotate`\n\nDraw an overlay annotation (fingerprint/highlight). No-op unless explain mode is on.\n\n- Parameters: `{\"properties\":{\"h\":{\"type\":\"number\"},\"kind\":{\"type\":\"string\"},\"ref\":{\"type\":\"string\"},\"w\":{\"type\":\"number\"},\"x\":{\"type\":\"number\"},\"y\":{\"type\":\"number\"}},\"required\":[\"kind\"],\"type\":\"object\"}`\n- Semantic flags: `{\"requiresExplainMode\":true}`\n\n### `set_explain_mode`\n\nEnter/leave explain mode — the gate for all on-page annotation overlays.\n\n- Parameters: `{\"properties\":{\"enabled\":{\"type\":\"boolean\"}},\"type\":\"object\"}`\n- Semantic flags: `{}`\n\n## interaction\n\n### `click`\n\nDeterministic click of an AX-ref element (layout-engine coords + hit-test).\n\n- Parameters: `{\"properties\":{\"ref\":{\"type\":\"string\"}},\"required\":[\"ref\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `click_element`\n\nClick the element returned by a JS expression (polls; occlusion-safe).\n\n- Parameters: `{\"properties\":{\"js\":{\"type\":\"string\"},\"wait_ms\":{\"type\":\"number\"}},\"required\":[\"js\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `click_xy`\n\nTrusted click at explicit viewport coordinates.\n\n- Parameters: `{\"properties\":{\"x\":{\"type\":\"number\"},\"y\":{\"type\":\"number\"}},\"required\":[\"x\",\"y\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `file_upload`\n\nUpload files (base64 data URIs) to a file input by AX ref.\n\n- Parameters: `{\"properties\":{\"files\":{\"items\":{\"type\":\"string\"},\"type\":\"array\"},\"ref\":{\"type\":\"string\"}},\"required\":[\"ref\",\"files\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `form_input`\n\nSet a form field value by AX ref.\n\n- Parameters: `{\"properties\":{\"ref\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"ref\",\"value\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `key_press`\n\nDispatch a key press.\n\n- Parameters: `{\"properties\":{\"key\":{\"type\":\"string\"}},\"required\":[\"key\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `label_select`\n\nType into a CDK-portal typeahead and click the matching option.\n\n- Parameters: `{\"properties\":{\"label_value\":{\"type\":\"string\"},\"selector\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"},\"wait_ms\":{\"type\":\"number\"}},\"required\":[\"selector\",\"value\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `select_option`\n\nSelect an option in a native <select> by AX ref.\n\n- Parameters: `{\"properties\":{\"ref\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"ref\",\"value\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `type_text`\n\nType text into the focused element (trusted input).\n\n- Parameters: `{\"properties\":{\"text\":{\"type\":\"string\"}},\"required\":[\"text\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n## meta\n\n### `capabilities`\n\nReturn this self-describing capability manifest (tools + features + versions).\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `debug_exec`\n\nDiagnostic: probe in-page bridge availability.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `detach`\n\nDetach the debugger from the target tab.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `ping`\n\nLiveness check; returns { ok, version }.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `reload`\n\nReload the extension (re-reads dist/ from disk).\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `set_bridge_port`\n\nSet the WebSocket bridge port (persists across reload; enables multi-session on different ports).\n\n- Parameters: `{\"properties\":{\"port\":{\"type\":\"number\"}},\"required\":[\"port\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n## navigation\n\n### `navigate`\n\nNavigate the console tab to a scoped https URL.\n\n- Parameters: `{\"properties\":{\"url\":{\"type\":\"string\"}},\"required\":[\"url\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `resize_window`\n\nResize the browser window.\n\n- Parameters: `{\"properties\":{\"height\":{\"type\":\"number\"},\"width\":{\"type\":\"number\"}},\"required\":[\"width\",\"height\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `scroll_to`\n\nScroll an AX-ref element into view.\n\n- Parameters: `{\"properties\":{\"ref\":{\"type\":\"string\"}},\"required\":[\"ref\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `tabs_close`\n\nClose a tab by id.\n\n- Parameters: `{\"properties\":{\"tabId\":{\"type\":\"number\"}},\"required\":[\"tabId\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `tabs_create`\n\nOpen a new tab at a scoped URL.\n\n- Parameters: `{\"properties\":{\"url\":{\"type\":\"string\"}},\"required\":[\"url\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `tabs_list`\n\nList scoped console tabs.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{}`\n\n## read\n\n### `assert_text`\n\nAssert an element contains expected text.\n\n- Parameters: `{\"properties\":{\"context\":{\"type\":\"string\"},\"expected\":{\"type\":\"string\"},\"selector\":{\"type\":\"string\"}},\"required\":[\"selector\",\"expected\"],\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `diag_activation`\n\nDiagnostic: per-gate tab-activation readiness timings (bridge/worker/page), cold/warm.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{}`\n\n### `diag_bridges`\n\nList discovered xcsh bridge health without tenant, environment, or session identifiers.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{}`\n\n### `diag_suspension`\n\nDiagnostic: SW-lifecycle event buffer + suspension summary (Phase 0a).\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{}`\n\n### `diag_ttft`\n\nDiagnostic: init→first-token timeline (per-stage ms, total, dominant, cold/warm).\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{}`\n\n### `find`\n\nFind AX nodes matching a locator.\n\n- Parameters: `{\"properties\":{\"selector\":{\"type\":\"string\"}},\"required\":[\"selector\"],\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `get_page_context`\n\nReturn a snapshot of the active console page (url, AX tree, captured XC API body) for chat grounding.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `get_page_text`\n\nReturn the page text.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `query_dom`\n\nDirect DOM.querySelector at wire speed — bypasses Runtime.evaluate for simple CSS selectors.\n\n- Parameters: `{\"properties\":{\"selector\":{\"type\":\"string\"}},\"required\":[\"selector\"],\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `read_ax`\n\nRead the accessibility tree of the page.\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `read_console`\n\nRead buffered console messages, optionally filtered by pattern.\n\n- Parameters: `{\"properties\":{\"pattern\":{\"type\":\"string\"}},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `read_network`\n\nRead buffered network events, optionally filtered by pattern.\n\n- Parameters: `{\"properties\":{\"pattern\":{\"type\":\"string\"}},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `screenshot`\n\nCapture a screenshot (base64 PNG).\n\n- Parameters: `{\"properties\":{},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `wait_for`\n\nWait for an AX node matching a locator to appear.\n\n- Parameters: `{\"properties\":{\"context\":{\"type\":\"string\"},\"selector\":{\"type\":\"string\"},\"timeoutMs\":{\"type\":\"number\"}},\"required\":[\"selector\"],\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n### `wait_for_api_response`\n\nWait for a network response whose URL matches a pattern.\n\n- Parameters: `{\"properties\":{\"pattern\":{\"type\":\"string\"},\"timeout_ms\":{\"type\":\"number\"}},\"type\":\"object\"}`\n- Semantic flags: `{\"readOnly\":true}`\n\n## script\n\n### `browser_batch`\n\nRun a batch of { tool, params } actions in sequence.\n\n- Parameters: `{\"properties\":{\"actions\":{\"items\":{\"properties\":{\"params\":{},\"tool\":{\"type\":\"string\"}},\"required\":[\"tool\"],\"type\":\"object\"},\"type\":\"array\"}},\"required\":[\"actions\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n\n### `javascript_tool`\n\nEvaluate arbitrary JS in the page (length-capped).\n\n- Parameters: `{\"properties\":{\"code\":{\"type\":\"string\"}},\"required\":[\"code\"],\"type\":\"object\"}`\n- Semantic flags: `{\"mutates\":true}`\n";
|
|
@@ -2,6 +2,7 @@ import type { AgentMessage } from "@f5-sales-demo/pi-agent-core";
|
|
|
2
2
|
import { type AssistantMessage, type Context, streamSimple } from "@f5-sales-demo/pi-ai";
|
|
3
3
|
import { prompt } from "@f5-sales-demo/pi-utils";
|
|
4
4
|
import btwUserPrompt from "../../prompts/system/btw-user.md" with { type: "text" };
|
|
5
|
+
import { finalAnswerText } from "../../session/final-answer";
|
|
5
6
|
import { toReasoningEffort } from "../../thinking";
|
|
6
7
|
import { BtwPanelComponent } from "../components/btw-panel";
|
|
7
8
|
import type { InteractiveModeContext } from "../types";
|
|
@@ -166,13 +167,7 @@ export class BtwController {
|
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
#assistantText(message: AssistantMessage): string {
|
|
169
|
-
|
|
170
|
-
for (const content of message.content) {
|
|
171
|
-
if (content.type === "text") {
|
|
172
|
-
text += content.text;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return text.trim();
|
|
170
|
+
return finalAnswerText(message).trim();
|
|
176
171
|
}
|
|
177
172
|
|
|
178
173
|
#closeActiveRequest(options: { abort: boolean }): void {
|
|
@@ -124,9 +124,12 @@ export class EventController {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
subscribeToAgent(): void {
|
|
127
|
-
this.ctx.unsubscribe = this.ctx.session.subscribe(
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
this.ctx.unsubscribe = this.ctx.session.subscribe(
|
|
128
|
+
async (event: AgentSessionEvent) => {
|
|
129
|
+
await this.handleEvent(event);
|
|
130
|
+
},
|
|
131
|
+
{ waitForTurnSettlement: true },
|
|
132
|
+
);
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
async handleEvent(event: AgentSessionEvent): Promise<void> {
|
|
@@ -218,6 +221,12 @@ export class EventController {
|
|
|
218
221
|
if (this.ctx.streamingComponent && event.message.role === "assistant") {
|
|
219
222
|
this.ctx.streamingMessage = event.message;
|
|
220
223
|
this.ctx.streamingComponent.updateContent(this.ctx.streamingMessage);
|
|
224
|
+
if (
|
|
225
|
+
event.assistantMessageEvent.type === "text_end" &&
|
|
226
|
+
event.assistantMessageEvent.phase === "commentary"
|
|
227
|
+
) {
|
|
228
|
+
this.ctx.streamingAssistantGutter?.setThinkingMode();
|
|
229
|
+
}
|
|
221
230
|
|
|
222
231
|
const thinkingCount = this.ctx.streamingMessage.content.filter(
|
|
223
232
|
content => content.type === "thinking" && content.thinking.trim(),
|
package/src/modes/print-mode.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { AgentMessage, ThinkingLevel } from "@f5-sales-demo/pi-agent-core";
|
|
9
9
|
import type { AssistantMessage, ImageContent, Model } from "@f5-sales-demo/pi-ai";
|
|
10
10
|
import type { AgentSession, AgentSessionEvent } from "../session/agent-session";
|
|
11
|
+
import { finalAnswerText } from "../session/final-answer";
|
|
11
12
|
import type { SessionHeader } from "../session/session-manager";
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -210,11 +211,8 @@ export async function runPrintMode(session: AgentSession, options: PrintModeOpti
|
|
|
210
211
|
if (failed) {
|
|
211
212
|
process.stderr.write(`${assistantMsg.errorMessage || `Request ${assistantMsg.stopReason}`}\n`);
|
|
212
213
|
} else {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
process.stdout.write(`${content.text}\n`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
214
|
+
const text = finalAnswerText(assistantMsg);
|
|
215
|
+
if (text) process.stdout.write(`${text}\n`);
|
|
218
216
|
}
|
|
219
217
|
}
|
|
220
218
|
|
|
@@ -77,6 +77,10 @@ The SE decides what to do; evidence decides what is true. See `<epistemic-integr
|
|
|
77
77
|
- (1) Correctness first, (2) Brevity second, (3) Politeness third.
|
|
78
78
|
- Prefer concise, information-dense writing.
|
|
79
79
|
- Avoid repeating the user's request or narrating routine tool calls.
|
|
80
|
+
- No commentary for trivial no-tool work: answer directly.
|
|
81
|
+
- Before non-trivial tool work, emit one concise commentary sentence describing the immediate action.
|
|
82
|
+
- During long work, report meaningful progress at natural intervals; avoid roughly 60 seconds of unexplained silence without narrating every routine read or command.
|
|
83
|
+
- Keep the final answer self-contained. Commentary is progress, never the terminal answer.
|
|
80
84
|
- When producing customer-facing content, maintain a professional tone appropriate to the audience.
|
|
81
85
|
</communication>
|
|
82
86
|
|
|
@@ -167,6 +167,7 @@ import {
|
|
|
167
167
|
shouldCompact,
|
|
168
168
|
} from "./compaction";
|
|
169
169
|
import { DEFAULT_PRUNE_CONFIG, pruneToolOutputs } from "./compaction/pruning";
|
|
170
|
+
import { finalAnswerText } from "./final-answer";
|
|
170
171
|
import {
|
|
171
172
|
type BashExecutionMessage,
|
|
172
173
|
type CompactionSummaryMessage,
|
|
@@ -212,7 +213,15 @@ export type AgentSessionEvent =
|
|
|
212
213
|
| { type: "todo_auto_clear" };
|
|
213
214
|
|
|
214
215
|
/** Listener function for agent session events */
|
|
215
|
-
export type AgentSessionEventListener = (event: AgentSessionEvent) =>
|
|
216
|
+
export type AgentSessionEventListener = (event: AgentSessionEvent) => unknown;
|
|
217
|
+
export interface AgentSessionEventSubscriptionOptions {
|
|
218
|
+
/** Delay normalized turn settlement until this listener finishes handling agent_end. */
|
|
219
|
+
waitForTurnSettlement?: boolean;
|
|
220
|
+
}
|
|
221
|
+
interface AgentSessionEventSubscription {
|
|
222
|
+
listener: AgentSessionEventListener;
|
|
223
|
+
waitForTurnSettlement: boolean;
|
|
224
|
+
}
|
|
216
225
|
export type AsyncJobSnapshotItem = Pick<AsyncJob, "id" | "type" | "status" | "label" | "startTime">;
|
|
217
226
|
|
|
218
227
|
export interface AsyncJobSnapshot {
|
|
@@ -475,7 +484,7 @@ export class AgentSession {
|
|
|
475
484
|
|
|
476
485
|
// Event subscription state
|
|
477
486
|
#unsubscribeAgent?: () => void;
|
|
478
|
-
#eventListeners:
|
|
487
|
+
#eventListeners: AgentSessionEventSubscription[] = [];
|
|
479
488
|
#turnPhase = new TurnPhaseController(event => this.#publishTurnPhase(event));
|
|
480
489
|
|
|
481
490
|
// Callers (e.g., SDK-level code that registers external listeners) register cleanups here so
|
|
@@ -767,12 +776,17 @@ export class AgentSession {
|
|
|
767
776
|
// =========================================================================
|
|
768
777
|
|
|
769
778
|
/** Emit an event to all listeners */
|
|
770
|
-
#emit(event: AgentSessionEvent):
|
|
779
|
+
#emit(event: AgentSessionEvent): Promise<unknown>[] {
|
|
771
780
|
// Copy array before iteration to avoid mutation during iteration
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
|
|
781
|
+
const subscriptions = [...this.#eventListeners];
|
|
782
|
+
const turnSettlementListeners: Promise<unknown>[] = [];
|
|
783
|
+
for (const subscription of subscriptions) {
|
|
784
|
+
const result = subscription.listener(event);
|
|
785
|
+
if (event.type === "agent_end" && subscription.waitForTurnSettlement) {
|
|
786
|
+
turnSettlementListeners.push(Promise.resolve(result));
|
|
787
|
+
}
|
|
775
788
|
}
|
|
789
|
+
return turnSettlementListeners;
|
|
776
790
|
}
|
|
777
791
|
|
|
778
792
|
#queuedExtensionEvents: Promise<void> = Promise.resolve();
|
|
@@ -786,11 +800,11 @@ export class AgentSession {
|
|
|
786
800
|
return queued;
|
|
787
801
|
}
|
|
788
802
|
|
|
789
|
-
async #emitSessionEvent(event: AgentSessionEvent): Promise<
|
|
803
|
+
async #emitSessionEvent(event: AgentSessionEvent): Promise<Promise<unknown>[]> {
|
|
790
804
|
if (event.type === "message_update" || event.type === "turn_phase") {
|
|
791
805
|
this.#emit(event);
|
|
792
806
|
void this.#queueExtensionEvent(event);
|
|
793
|
-
return;
|
|
807
|
+
return [];
|
|
794
808
|
}
|
|
795
809
|
|
|
796
810
|
if (
|
|
@@ -804,7 +818,7 @@ export class AgentSession {
|
|
|
804
818
|
}
|
|
805
819
|
|
|
806
820
|
await this.#emitExtensionEvent(event);
|
|
807
|
-
this.#emit(event);
|
|
821
|
+
return this.#emit(event);
|
|
808
822
|
}
|
|
809
823
|
|
|
810
824
|
// Track last assistant message for auto-compaction check
|
|
@@ -885,23 +899,33 @@ export class AgentSession {
|
|
|
885
899
|
}
|
|
886
900
|
}
|
|
887
901
|
|
|
888
|
-
await this.#emitSessionEvent(displayEvent);
|
|
902
|
+
const turnSettlementListeners = await this.#emitSessionEvent(displayEvent);
|
|
889
903
|
|
|
890
904
|
// `agent_end` is the provider-neutral completion boundary. Settle only
|
|
891
|
-
// after
|
|
892
|
-
//
|
|
893
|
-
//
|
|
905
|
+
// after the designated lifecycle consumer has finished clearing provider/tool
|
|
906
|
+
// status before Herdr observes idle. Other subscribers and post-turn maintenance
|
|
907
|
+
// continue concurrently. This also covers Agent.continue() continuations.
|
|
894
908
|
if (event.type === "agent_end") {
|
|
895
909
|
const lastAssistant = [...event.messages]
|
|
896
910
|
.reverse()
|
|
897
911
|
.find((message): message is AssistantMessage => message.role === "assistant");
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
912
|
+
const settle = () => {
|
|
913
|
+
this.#turnPhase.settle(
|
|
914
|
+
lastAssistant?.stopReason === "aborted"
|
|
915
|
+
? "aborted"
|
|
916
|
+
: lastAssistant?.stopReason === "error"
|
|
917
|
+
? "error"
|
|
918
|
+
: "stop",
|
|
919
|
+
);
|
|
920
|
+
};
|
|
921
|
+
if (turnSettlementListeners.length === 0) {
|
|
922
|
+
settle();
|
|
923
|
+
} else {
|
|
924
|
+
void Promise.all(turnSettlementListeners).then(settle, error => {
|
|
925
|
+
logger.warn("Turn settlement listener failed", { error: String(error) });
|
|
926
|
+
settle();
|
|
927
|
+
});
|
|
928
|
+
}
|
|
905
929
|
}
|
|
906
930
|
|
|
907
931
|
if (event.type === "turn_start") {
|
|
@@ -2168,12 +2192,13 @@ export class AgentSession {
|
|
|
2168
2192
|
* Session persistence is handled internally (saves messages on message_end).
|
|
2169
2193
|
* Multiple listeners can be added. Returns unsubscribe function for this listener.
|
|
2170
2194
|
*/
|
|
2171
|
-
subscribe(listener: AgentSessionEventListener): () => void {
|
|
2172
|
-
|
|
2195
|
+
subscribe(listener: AgentSessionEventListener, options: AgentSessionEventSubscriptionOptions = {}): () => void {
|
|
2196
|
+
const subscription = { listener, waitForTurnSettlement: options.waitForTurnSettlement ?? false };
|
|
2197
|
+
this.#eventListeners.push(subscription);
|
|
2173
2198
|
|
|
2174
2199
|
// Return unsubscribe function for this specific listener
|
|
2175
2200
|
return () => {
|
|
2176
|
-
const index = this.#eventListeners.indexOf(
|
|
2201
|
+
const index = this.#eventListeners.indexOf(subscription);
|
|
2177
2202
|
if (index !== -1) {
|
|
2178
2203
|
this.#eventListeners.splice(index, 1);
|
|
2179
2204
|
}
|
|
@@ -7548,14 +7573,7 @@ export class AgentSession {
|
|
|
7548
7573
|
|
|
7549
7574
|
if (!lastAssistant) return undefined;
|
|
7550
7575
|
|
|
7551
|
-
|
|
7552
|
-
for (const content of (lastAssistant as AssistantMessage).content) {
|
|
7553
|
-
if (content.type === "text") {
|
|
7554
|
-
text += content.text;
|
|
7555
|
-
}
|
|
7556
|
-
}
|
|
7557
|
-
|
|
7558
|
-
return text.trim() || undefined;
|
|
7576
|
+
return finalAnswerText(lastAssistant as AssistantMessage).trim() || undefined;
|
|
7559
7577
|
}
|
|
7560
7578
|
|
|
7561
7579
|
/**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AssistantMessage, TextContent } from "@f5-sales-demo/pi-ai";
|
|
2
|
+
|
|
3
|
+
/** Missing phase intentionally follows Codex's final-answer fallback. */
|
|
4
|
+
export function isFinalAnswerContent(content: TextContent): boolean {
|
|
5
|
+
return content.phase !== "commentary";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Select only terminal answer text; commentary remains available on the message transcript. */
|
|
9
|
+
export function finalAnswerText(message: AssistantMessage): string {
|
|
10
|
+
return message.content
|
|
11
|
+
.filter((content): content is TextContent => content.type === "text" && isFinalAnswerContent(content))
|
|
12
|
+
.map(content => content.text)
|
|
13
|
+
.filter(Boolean)
|
|
14
|
+
.join("\n");
|
|
15
|
+
}
|
package/src/task/render.ts
CHANGED
|
@@ -79,6 +79,17 @@ function normalizeReportFindings(value: unknown): ReportFindingDetails[] {
|
|
|
79
79
|
return findings;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** Normalize renderer-facing submit_result data without weakening tool schemas. */
|
|
83
|
+
function normalizeSubmitResultData(value: unknown): Array<{ data: unknown }> {
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
return value.filter((item): item is { data: unknown } => item !== null && typeof item === "object");
|
|
86
|
+
}
|
|
87
|
+
if (value !== null && typeof value === "object") {
|
|
88
|
+
return [value as { data: unknown }];
|
|
89
|
+
}
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
function formatJsonScalar(value: unknown, _theme: Theme): string {
|
|
83
94
|
if (value === null) return "null";
|
|
84
95
|
if (typeof value === "string") {
|
|
@@ -588,12 +599,12 @@ function renderAgentProgress(
|
|
|
588
599
|
if (progress.extractedToolData) {
|
|
589
600
|
// For completed tasks, check for review verdict from submit_result tool
|
|
590
601
|
if (progress.status === "completed") {
|
|
591
|
-
const completeData = progress.extractedToolData.submit_result
|
|
602
|
+
const completeData = normalizeSubmitResultData(progress.extractedToolData.submit_result);
|
|
592
603
|
const reportFindingData = normalizeReportFindings(progress.extractedToolData.report_finding);
|
|
593
604
|
const reviewData = completeData
|
|
594
|
-
|
|
605
|
+
.map(c => c.data as SubmitReviewDetails)
|
|
595
606
|
.filter(d => d && typeof d === "object" && "overall_correctness" in d);
|
|
596
|
-
if (reviewData
|
|
607
|
+
if (reviewData.length > 0) {
|
|
597
608
|
const summary = reviewData[reviewData.length - 1];
|
|
598
609
|
const findings = reportFindingData;
|
|
599
610
|
lines.push(...renderReviewResult(summary, findings, continuePrefix, expanded, theme));
|
|
@@ -798,16 +809,16 @@ function renderAgentResult(result: SingleResult, isLast: boolean, expanded: bool
|
|
|
798
809
|
);
|
|
799
810
|
}
|
|
800
811
|
// Check for review result (submit_result with review schema + report_finding)
|
|
801
|
-
const completeData = result.extractedToolData?.submit_result
|
|
812
|
+
const completeData = normalizeSubmitResultData(result.extractedToolData?.submit_result);
|
|
802
813
|
const reportFindingData = normalizeReportFindings(result.extractedToolData?.report_finding);
|
|
803
814
|
|
|
804
815
|
// Extract review verdict from submit_result tool's data field if it matches SubmitReviewDetails
|
|
805
816
|
const reviewData = completeData
|
|
806
|
-
|
|
817
|
+
.map(c => c.data as SubmitReviewDetails)
|
|
807
818
|
.filter(d => d && typeof d === "object" && "overall_correctness" in d);
|
|
808
|
-
const submitReviewData = reviewData
|
|
819
|
+
const submitReviewData = reviewData.length > 0 ? reviewData : undefined;
|
|
809
820
|
|
|
810
|
-
if (submitReviewData
|
|
821
|
+
if (submitReviewData) {
|
|
811
822
|
// Use combined review renderer
|
|
812
823
|
const summary = submitReviewData[submitReviewData.length - 1];
|
|
813
824
|
const findings = reportFindingData;
|
|
@@ -815,7 +826,7 @@ function renderAgentResult(result: SingleResult, isLast: boolean, expanded: bool
|
|
|
815
826
|
return lines;
|
|
816
827
|
}
|
|
817
828
|
if (reportFindingData.length > 0) {
|
|
818
|
-
const hasCompleteData = completeData
|
|
829
|
+
const hasCompleteData = completeData.length > 0;
|
|
819
830
|
const message = hasCompleteData
|
|
820
831
|
? "Review verdict missing expected fields"
|
|
821
832
|
: "Review incomplete (submit_result not called)";
|
|
@@ -11,9 +11,9 @@ const TOOL_TITLE = "Browser";
|
|
|
11
11
|
const MAX_CONTENT_LINES = 30;
|
|
12
12
|
|
|
13
13
|
type BrowserRenderArgs = {
|
|
14
|
-
action?:
|
|
15
|
-
url?:
|
|
16
|
-
selector?:
|
|
14
|
+
action?: unknown;
|
|
15
|
+
url?: unknown;
|
|
16
|
+
selector?: unknown;
|
|
17
17
|
text?: string;
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -42,12 +42,13 @@ const ACTION_COLORS: Partial<Record<string, ThemeColor>> = {
|
|
|
42
42
|
|
|
43
43
|
export const browserRenderer = {
|
|
44
44
|
renderCall(args: BrowserRenderArgs, _options: RenderResultOptions, uiTheme: Theme): Component {
|
|
45
|
-
const action = args.action
|
|
46
|
-
const description =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
const action = typeof args.action === "string" ? args.action : "browse";
|
|
46
|
+
const description =
|
|
47
|
+
typeof args.url === "string" && args.url
|
|
48
|
+
? uiTheme.fg("muted", args.url)
|
|
49
|
+
: typeof args.selector === "string" && args.selector
|
|
50
|
+
? uiTheme.fg("dim", args.selector)
|
|
51
|
+
: undefined;
|
|
51
52
|
const badgeColor = ACTION_COLORS[action] ?? "muted";
|
|
52
53
|
const text = renderStatusLine(
|
|
53
54
|
{ icon: "pending", title: TOOL_TITLE, badge: { label: action, color: badgeColor }, description },
|
|
@@ -70,7 +71,12 @@ export const browserRenderer = {
|
|
|
70
71
|
return new Text(formatErrorMessage(errorText, uiTheme), 0, 0);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
const action =
|
|
74
|
+
const action =
|
|
75
|
+
typeof details?.action === "string"
|
|
76
|
+
? details.action
|
|
77
|
+
: typeof args?.action === "string"
|
|
78
|
+
? args.action
|
|
79
|
+
: "browse";
|
|
74
80
|
const badgeColor = ACTION_COLORS[action] ?? "muted";
|
|
75
81
|
const sections: Array<{ label?: string; lines: string[] }> = [];
|
|
76
82
|
const meta: string[] = [];
|
|
@@ -79,16 +85,12 @@ export const browserRenderer = {
|
|
|
79
85
|
const errorText = result.content?.find(c => c.type === "text")?.text ?? "Unknown error";
|
|
80
86
|
addSection(sections, "Error", [uiTheme.fg("error", errorText)], uiTheme);
|
|
81
87
|
} else {
|
|
82
|
-
if (details?.url)
|
|
88
|
+
if (typeof details?.url === "string" && details.url)
|
|
83
89
|
meta.push(uiTheme.fg("dim", details.url.length > 50 ? `${details.url.slice(0, 47)}…` : details.url));
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"Screenshot",
|
|
89
|
-
[uiTheme.fg("toolOutput", ` ${shortenPath(details.screenshotPath)}`)],
|
|
90
|
-
uiTheme,
|
|
91
|
-
);
|
|
91
|
+
const screenshotPath = typeof details?.screenshotPath === "string" ? details.screenshotPath : "";
|
|
92
|
+
if (screenshotPath) {
|
|
93
|
+
addSection(sections, "Screenshot", [uiTheme.fg("toolOutput", ` ${shortenPath(screenshotPath)}`)], uiTheme);
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
if (details?.viewport) {
|
|
@@ -10,13 +10,13 @@ const TOOL_TITLE = "Inspect Image";
|
|
|
10
10
|
const MAX_OUTPUT_LINES = 30;
|
|
11
11
|
|
|
12
12
|
interface InspectImageRenderArgs {
|
|
13
|
-
path?:
|
|
14
|
-
question?:
|
|
13
|
+
path?: unknown;
|
|
14
|
+
question?: unknown;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
interface InspectImageRendererDetails {
|
|
18
18
|
model: string;
|
|
19
|
-
imagePath:
|
|
19
|
+
imagePath: unknown;
|
|
20
20
|
mimeType: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -28,7 +28,7 @@ interface InspectImageRendererResult {
|
|
|
28
28
|
|
|
29
29
|
export const inspectImageToolRenderer = {
|
|
30
30
|
renderCall(args: InspectImageRenderArgs, _options: RenderResultOptions, uiTheme: Theme): Component {
|
|
31
|
-
const rawPath = args.path
|
|
31
|
+
const rawPath = typeof args.path === "string" ? args.path : "";
|
|
32
32
|
const pathDisplay = rawPath ? shortenPath(rawPath) : "…";
|
|
33
33
|
const description = uiTheme.fg("muted", pathDisplay);
|
|
34
34
|
const text = renderStatusLine({ icon: "pending", title: TOOL_TITLE, description }, uiTheme);
|
|
@@ -49,7 +49,8 @@ export const inspectImageToolRenderer = {
|
|
|
49
49
|
return new Text(formatErrorMessage(errorText, uiTheme), 0, 0);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const rawPath =
|
|
52
|
+
const rawPath =
|
|
53
|
+
typeof details?.imagePath === "string" ? details.imagePath : typeof args?.path === "string" ? args.path : "";
|
|
53
54
|
const pathDisplay = rawPath ? shortenPath(rawPath) : "image";
|
|
54
55
|
const sections: Array<{ label?: string; lines: string[] }> = [];
|
|
55
56
|
const meta: string[] = [];
|
|
@@ -61,7 +62,7 @@ export const inspectImageToolRenderer = {
|
|
|
61
62
|
const errorText = result.content?.find(c => c.type === "text")?.text ?? "Unknown error";
|
|
62
63
|
addSection(sections, "Error", [uiTheme.fg("error", errorText)], uiTheme);
|
|
63
64
|
} else {
|
|
64
|
-
if (args?.question) {
|
|
65
|
+
if (typeof args?.question === "string" && args.question) {
|
|
65
66
|
addSection(sections, "Question", [uiTheme.fg("chromeAccent", ` ${args.question}`)], uiTheme);
|
|
66
67
|
}
|
|
67
68
|
|
package/src/tools/read.ts
CHANGED
|
@@ -1451,8 +1451,8 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
|
|
|
1451
1451
|
// =============================================================================
|
|
1452
1452
|
|
|
1453
1453
|
interface ReadRenderArgs {
|
|
1454
|
-
path?:
|
|
1455
|
-
file_path?:
|
|
1454
|
+
path?: unknown;
|
|
1455
|
+
file_path?: unknown;
|
|
1456
1456
|
sel?: string;
|
|
1457
1457
|
timeout?: number;
|
|
1458
1458
|
// Legacy fields from old schema — tolerated for in-flight tool calls during transition
|
|
@@ -1463,11 +1463,12 @@ interface ReadRenderArgs {
|
|
|
1463
1463
|
|
|
1464
1464
|
export const readToolRenderer = {
|
|
1465
1465
|
renderCall(args: ReadRenderArgs, _options: RenderResultOptions, uiTheme: Theme): Component {
|
|
1466
|
-
|
|
1467
|
-
|
|
1466
|
+
const rawPath =
|
|
1467
|
+
typeof args.file_path === "string" ? args.file_path : typeof args.path === "string" ? args.path : "";
|
|
1468
|
+
if (isReadableUrlPath(rawPath)) {
|
|
1469
|
+
return renderReadUrlCall({ path: rawPath, raw: args.raw }, _options, uiTheme);
|
|
1468
1470
|
}
|
|
1469
1471
|
|
|
1470
|
-
const rawPath = args.file_path || args.path || "";
|
|
1471
1472
|
const filePath = shortenPath(rawPath);
|
|
1472
1473
|
const offset = args.offset;
|
|
1473
1474
|
const limit = args.limit;
|
|
@@ -1490,7 +1491,9 @@ export const readToolRenderer = {
|
|
|
1490
1491
|
args?: ReadRenderArgs,
|
|
1491
1492
|
): Component {
|
|
1492
1493
|
const urlDetails = result.details as ReadUrlToolDetails | undefined;
|
|
1493
|
-
|
|
1494
|
+
const rawPathForKind =
|
|
1495
|
+
typeof args?.file_path === "string" ? args.file_path : typeof args?.path === "string" ? args.path : "";
|
|
1496
|
+
if (urlDetails?.kind === "url" || isReadableUrlPath(rawPathForKind)) {
|
|
1494
1497
|
return renderReadUrlResult(
|
|
1495
1498
|
result as { content: Array<{ type: string; text?: string }>; details?: ReadUrlToolDetails },
|
|
1496
1499
|
_options,
|
|
@@ -1501,9 +1504,9 @@ export const readToolRenderer = {
|
|
|
1501
1504
|
const details = result.details;
|
|
1502
1505
|
const contentText = result.content?.find(c => c.type === "text")?.text ?? "";
|
|
1503
1506
|
const imageContent = result.content?.find(c => c.type === "image");
|
|
1504
|
-
const rawPath =
|
|
1507
|
+
const rawPath = rawPathForKind;
|
|
1505
1508
|
const filePath = shortenPath(rawPath);
|
|
1506
|
-
const lang = getLanguageFromPath(rawPath);
|
|
1509
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
1507
1510
|
|
|
1508
1511
|
const warningLines: string[] = [];
|
|
1509
1512
|
const truncation = details?.meta?.truncation;
|
|
@@ -549,7 +549,8 @@ export function truncateDiffByHunk(
|
|
|
549
549
|
// Path Utilities
|
|
550
550
|
// =============================================================================
|
|
551
551
|
|
|
552
|
-
export function shortenPath(filePath:
|
|
552
|
+
export function shortenPath(filePath: unknown, homeDir?: string): string {
|
|
553
|
+
if (typeof filePath !== "string") return "";
|
|
553
554
|
const home = homeDir ?? os.homedir();
|
|
554
555
|
if (home && filePath.startsWith(home)) {
|
|
555
556
|
return `~${filePath.slice(home.length)}`;
|
package/src/tools/write.ts
CHANGED
|
@@ -517,9 +517,9 @@ export class WriteTool implements AgentTool<typeof writeSchema, WriteToolDetails
|
|
|
517
517
|
// =============================================================================
|
|
518
518
|
|
|
519
519
|
interface WriteRenderArgs {
|
|
520
|
-
path?:
|
|
521
|
-
file_path?:
|
|
522
|
-
content?:
|
|
520
|
+
path?: unknown;
|
|
521
|
+
file_path?: unknown;
|
|
522
|
+
content?: unknown;
|
|
523
523
|
}
|
|
524
524
|
|
|
525
525
|
const WRITE_PREVIEW_LINES = 6;
|
|
@@ -538,8 +538,9 @@ function formatMetadataLine(lineCount: number | null, language: string | undefin
|
|
|
538
538
|
return uiTheme.fg("dim", `${icon}`);
|
|
539
539
|
}
|
|
540
540
|
|
|
541
|
-
function normalizeDisplayText(text:
|
|
542
|
-
|
|
541
|
+
function normalizeDisplayText(text: unknown): string {
|
|
542
|
+
if (text === undefined || text === null) return "";
|
|
543
|
+
return String(text).replace(/\r/g, "");
|
|
543
544
|
}
|
|
544
545
|
|
|
545
546
|
function formatStreamingContent(content: string, uiTheme: Theme, maxWidth: number): string {
|
|
@@ -580,9 +581,10 @@ function renderContentPreview(content: string, expanded: boolean, uiTheme: Theme
|
|
|
580
581
|
|
|
581
582
|
export const writeToolRenderer = {
|
|
582
583
|
renderCall(args: WriteRenderArgs, options: RenderResultOptions, uiTheme: Theme): Component {
|
|
583
|
-
const rawPath =
|
|
584
|
+
const rawPath =
|
|
585
|
+
typeof args.file_path === "string" ? args.file_path : typeof args.path === "string" ? args.path : "";
|
|
584
586
|
const filePath = shortenPath(rawPath);
|
|
585
|
-
const lang = getLanguageFromPath(rawPath) ?? "text";
|
|
587
|
+
const lang = rawPath ? (getLanguageFromPath(rawPath) ?? "text") : "text";
|
|
586
588
|
const langIcon = uiTheme.fg("muted", uiTheme.getLangIcon(lang));
|
|
587
589
|
const pathDisplay = filePath ? uiTheme.fg("accent", filePath) : uiTheme.fg("toolOutput", "…");
|
|
588
590
|
const spinner =
|
|
@@ -590,7 +592,8 @@ export const writeToolRenderer = {
|
|
|
590
592
|
|
|
591
593
|
const header = `${formatTitle("Write", uiTheme)} ${spinner ? `${spinner} ` : ""}${langIcon} ${pathDisplay}`;
|
|
592
594
|
|
|
593
|
-
|
|
595
|
+
const content = normalizeDisplayText(args.content);
|
|
596
|
+
if (!content) {
|
|
594
597
|
return {
|
|
595
598
|
render(width: number) {
|
|
596
599
|
return [truncateToWidth(header, width, Ellipsis.Omit)];
|
|
@@ -601,7 +604,7 @@ export const writeToolRenderer = {
|
|
|
601
604
|
|
|
602
605
|
return {
|
|
603
606
|
render(width: number) {
|
|
604
|
-
const text = header + formatStreamingContent(
|
|
607
|
+
const text = header + formatStreamingContent(content, uiTheme, width);
|
|
605
608
|
return text.split("\n").map(l => truncateToWidth(l, width, Ellipsis.Omit));
|
|
606
609
|
},
|
|
607
610
|
invalidate() {},
|
|
@@ -614,10 +617,11 @@ export const writeToolRenderer = {
|
|
|
614
617
|
uiTheme: Theme,
|
|
615
618
|
args?: WriteRenderArgs,
|
|
616
619
|
): Component {
|
|
617
|
-
const rawPath =
|
|
620
|
+
const rawPath =
|
|
621
|
+
typeof args?.file_path === "string" ? args.file_path : typeof args?.path === "string" ? args.path : "";
|
|
618
622
|
const filePath = shortenPath(rawPath);
|
|
619
|
-
const fileContent = args?.content
|
|
620
|
-
const lang = getLanguageFromPath(rawPath);
|
|
623
|
+
const fileContent = normalizeDisplayText(args?.content);
|
|
624
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
621
625
|
const langIcon = uiTheme.fg("muted", uiTheme.getLangIcon(lang));
|
|
622
626
|
const pathDisplay = filePath ? uiTheme.fg("accent", filePath) : uiTheme.fg("toolOutput", "…");
|
|
623
627
|
const lineCount = countLines(fileContent);
|