@firstpick/pi-package-webui 0.10.4 → 0.10.6

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.
Files changed (50) hide show
  1. package/DEVELOPMENT.md +11 -3
  2. package/README.md +2 -0
  3. package/TECHNICAL.md +3 -1
  4. package/bin/pi-webui.mjs +1 -1
  5. package/lib/thinking-stream-recovery.mjs +29 -142
  6. package/package.json +2 -2
  7. package/public/app.js +44 -79
  8. package/public/fast-output-live.mjs +8 -6
  9. package/public/index.html +2 -2
  10. package/public/service-worker.js +1 -1
  11. package/public/stream-output-controller.mjs +59 -12
  12. package/public/styles.css +2 -0
  13. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  14. package/tests/browser/footer-model-advanced-layout.spec.mjs +37 -0
  15. package/tests/codex-fast-mode-static.test.mjs +2 -2
  16. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  17. package/tests/control-visibility-static.test.mjs +3 -3
  18. package/tests/controls-layout-static.test.mjs +3 -3
  19. package/tests/events-tree-context-menu-static.test.mjs +3 -3
  20. package/tests/fast-mode-client-static.test.mjs +2 -2
  21. package/tests/fast-output-live.test.mjs +9 -0
  22. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  23. package/tests/file-viewer-image-static.test.mjs +3 -3
  24. package/tests/fixtures/fake-pi.mjs +2 -2
  25. package/tests/git-footer-context-menu-static.test.mjs +1 -1
  26. package/tests/guided-git-activation-static.test.mjs +3 -3
  27. package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
  28. package/tests/intercom-conversation-viewer-static.test.mjs +3 -3
  29. package/tests/intercom-main-transcript-suppression-static.test.mjs +5 -6
  30. package/tests/main-output-loading-static.test.mjs +3 -3
  31. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  32. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  33. package/tests/mobile-foundation-static.test.mjs +3 -3
  34. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  35. package/tests/mobile-static.test.mjs +3 -3
  36. package/tests/open-issue-wizard-static.test.mjs +1 -1
  37. package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
  38. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  39. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  40. package/tests/questionnaire-dialog.test.mjs +3 -3
  41. package/tests/session-sampling-ui-static.test.mjs +3 -3
  42. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  43. package/tests/stream-output-controller.test.mjs +4 -2
  44. package/tests/streaming-ui-coupling.test.mjs +2 -2
  45. package/tests/subagent-observability-static.test.mjs +2 -2
  46. package/tests/syntax-highlighting-static.test.mjs +3 -3
  47. package/tests/theme-customizer-static.test.mjs +1 -1
  48. package/tests/thinking-stream-recovery.test.mjs +58 -75
  49. package/tests/tool-call-stream.test.mjs +152 -0
  50. package/tests/windows-drive-cwd-picker-static.test.mjs +3 -3
@@ -57,10 +57,10 @@ assert.match(css, /\.sampling-parameter-control\.unsupported:hover:not\(\.sampli
57
57
  assert.match(css, /\.sampling-parameter-control\.unsupported:focus-visible:not\(\.sampling-tooltip-dismissed\) > \.sampling-parameter-unsupported-tooltip/, "keyboard focus should reveal dismissible unsupported reasons");
58
58
  assert.match(css, /\.sampling-parameter-unsupported-tooltip\.sampling-tooltip-below/, "bounded placement should support flipping below top-edge rows");
59
59
  assert.match(css, /pointer-events: auto;/, "a visible unsupported tooltip should remain pointer-hoverable");
60
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v154"/, "native-control assets should advance the cache identity");
60
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v155"/, "native-control assets should advance the cache identity");
61
61
  assert.match(serviceWorker, /"\/sampling-parameter-controls\.mjs"/, "the pure sampling module should be part of the offline app shell");
62
- assert.match(html, /styles\.css\?v=152/, "the changed stylesheet should have a new revision");
63
- assert.match(html, /app\.js\?v=183/, "the changed app module should have a new revision");
62
+ assert.match(html, /styles\.css\?v=154/, "the changed stylesheet should have a new revision");
63
+ assert.match(html, /app\.js\?v=184/, "the changed app module should have a new revision");
64
64
 
65
65
  // --- Browser state behavior -------------------------------------------------
66
66
 
@@ -27,8 +27,8 @@ assert.doesNotMatch(layout, /sectionHeightMin|sectionHeightMax|validateSectionHe
27
27
  assert.match(app, /const UI_LAYOUT_SIDE_PANEL_FIELDS = \["placement", "sectionLayout", "collapsedSectionIds", "hiddenSectionIds", "collapsedPanels", "panelWidths"\];/, "the browser durable layout field list should omit section heights");
28
28
  assert.match(app, /function clearRemovedSidePanelSectionHeightState\(\)[\s\S]*localStorage\.removeItem\(REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY\)[\s\S]*record\.field === "sidePanel" && record\.subfield === "sectionHeights"/, "startup should remove the retired cache and pending mutations");
29
29
  assert.match(app, /clearRemovedSidePanelSectionHeightState\(\);\s*restoreDurableUiLayoutPendingJournal\(\);/, "retired height state should be cleared before pending layout restoration");
30
- assert.match(html, /styles\.css\?v=152/, "removing section resize styles should advance the stylesheet revision");
31
- assert.match(html, /app\.js\?v=183/, "removing section resize behavior should advance the app revision");
32
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v154"/, "removing browser assets should advance the PWA cache identity");
30
+ assert.match(html, /styles\.css\?v=154/, "removing section resize styles should advance the stylesheet revision");
31
+ assert.match(html, /app\.js\?v=184/, "removing section resize behavior should advance the app revision");
32
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v155"/, "removing browser assets should advance the PWA cache identity");
33
33
 
34
34
  console.log("side-panel-section-height-removal-static.test.mjs passed");
@@ -56,9 +56,11 @@ assert.equal(DEFAULT_STREAM_PENDING_ENTRY_LIMIT, 128);
56
56
  assert.equal(DEFAULT_STREAM_PENDING_BYTE_LIMIT, 256 * 1024);
57
57
  assert.equal(
58
58
  reconcileTranscriptThinkingSnapshot("first\n\nsecond\n\nthird\n\nfourth", "first\n\nsecond\n\nthird"),
59
- "first\n\nsecond\n\nthird\n\nfourth",
60
- "a regressive final thinking snapshot must not remove an already-rendered tail",
59
+ "first\n\nsecond\n\nthird",
60
+ "a final thinking snapshot must remove a discarded streamed tail",
61
61
  );
62
+ assert.equal(reconcileTranscriptThinkingSnapshot("draft", ""), "", "explicit empty thinking clears the draft");
63
+ assert.equal(reconcileTranscriptThinkingSnapshot("draft", undefined), "draft", "missing snapshots retain the draft");
62
64
  assert.equal(reconcileTranscriptThinkingSnapshot("short", "shorter complete"), "shorter complete", "a longer compatible final snapshot should win");
63
65
  assert.equal(reconcileTranscriptThinkingSnapshot("draft reasoning", "provider correction"), "provider correction", "divergent provider corrections must remain authoritative");
64
66
 
@@ -136,8 +136,8 @@ assert.doesNotMatch(styles, /\.chat > \.message:first-of-type \{ margin-top:\s*a
136
136
  assert.match(appendOptimisticUserPrompt, /renderAllMessages\(\);[\s\S]*?scrollChatToBottom\(\{ force:\s*true \}\);/, "submitting a prompt should explicitly resume bottom-follow for the new turn");
137
137
  assert.doesNotMatch(appendOptimisticUserPrompt, /if \(autoFollowChat \|\| isChatNearBottom\(\)\)/, "a paused reader position should not leave a newly submitted turn off-screen");
138
138
  assert.match(app, /import \{[^}]*reconcileTranscriptThinkingSnapshot[^}]*\} from "\.\/stream-output-controller\.mjs";/, "the browser should import the tested thinking-snapshot reconciler");
139
- assert.match(setStreamThinkingRawText, /reconcile\s*\?\s*reconcileTranscriptThinkingSnapshot\(streamThinkingRawText, snapshot\)/, "thinking state should support prefix-safe snapshot reconciliation");
140
- assert.match(syncStreamingThinkingFromUpdate, /update\.type === "thinking_end"[\s\S]*?setStreamThinkingRawText\(delta, \{ reconcile: true \}\)[\s\S]*?setStreamThinkingRawText\(fallback, \{ reconcile: true \}\)/, "thinking_end snapshots and fallbacks must not cut off an already-rendered compatible tail");
139
+ assert.match(setStreamThinkingRawText, /reconcile\s*\?\s*reconcileTranscriptThinkingSnapshot\(streamThinkingRawText, snapshot\)/, "thinking state should use authoritative snapshot reconciliation");
140
+ assert.match(syncStreamingThinkingFromUpdate, /update\.type === "thinking_end"[\s\S]*?typeof update\.content === "string"[\s\S]*?setStreamThinkingRawText\(snapshot, \{ reconcile: true \}\)/, "thinking_end must apply explicit shortened or empty content rather than preserving discarded tails");
141
141
 
142
142
  futureInvariant("theory #1: message_update streaming hot path must not call immediate scroll/layout work", () => {
143
143
  assert.doesNotMatch(handleMessageUpdate, /scrollChatToBottom\s*\(/, "handleMessageUpdate should schedule/coalesce follow-scroll instead of calling scrollChatToBottom() directly");
@@ -28,7 +28,7 @@ assert.match(app, /const SUBAGENT_ASYNC_WIDGET_KEY = "subagent-async"[\s\S]*case
28
28
  assert.match(app, /for \(const \[key, value\] of widgets\)[\s\S]*if \(key === SUBAGENT_ASYNC_WIDGET_KEY\) continue;/, "stale cached async-status widgets should remain hidden defensively");
29
29
  assert.match(css, /\.subagent-source-badge[\s\S]*text-overflow: ellipsis[\s\S]*@media \(max-width: 720px\)/, "source badges should remain compact and responsive");
30
30
  assert.match(html, /Managed and registered Pi agent runs[\s\S]*External agents/, "help should explain managed, registered, and external groups");
31
- assert.match(html, /styles\.css\?v=152[\s\S]*app\.js\?v=183/, "browser assets should use the current subagent-observability revisions");
32
- assert.match(worker, /pi-webui-pwa-v154/, "PWA cache identity should advance with subagent widget suppression");
31
+ assert.match(html, /styles\.css\?v=154[\s\S]*app\.js\?v=184/, "browser assets should use the current subagent-observability revisions");
32
+ assert.match(worker, /pi-webui-pwa-v155/, "PWA cache identity should advance with subagent widget suppression");
33
33
 
34
34
  console.log("subagent-observability-static.test.mjs passed");
@@ -60,9 +60,9 @@ assert.match(css, /\.markdown-code \.syntax-comment \{[^}]*font-style: italic;/,
60
60
 
61
61
  // --- Offline/PWA startup closure and coherent revisions ---
62
62
  assert.match(serviceWorker, /"\/syntax-highlight\.mjs",/, "the eagerly imported tokenizer must be part of the offline app shell");
63
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v154"/, "adding a startup module should advance the PWA cache identity");
64
- assert.match(html, /styles\.css\?v=152/, "new token styles should advance the stylesheet revision");
65
- assert.match(html, /data-app-src="\/app\.js\?v=183"/, "new renderer wiring should advance the app module revision");
63
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v155"/, "adding a startup module should advance the PWA cache identity");
64
+ assert.match(html, /styles\.css\?v=154/, "new token styles should advance the stylesheet revision");
65
+ assert.match(html, /data-app-src="\/app\.js\?v=184"/, "new renderer wiring should advance the app module revision");
66
66
  assert.match(pkg, /node --check public\/syntax-highlight\.mjs/, "the package check should syntax-check the startup-critical tokenizer");
67
67
 
68
68
  const appShell = serviceWorker.slice(serviceWorker.indexOf("const APP_SHELL"), serviceWorker.indexOf("];", serviceWorker.indexOf("const APP_SHELL")));
@@ -34,7 +34,7 @@ assert.match(html, /role="alert" hidden>[\s\S]*Replace this exact target\?/, "ov
34
34
 
35
35
  assert.match(app, /from "\.\/theme-contract\.mjs"/, "frontend should consume the shared browser-safe theme contract");
36
36
  assert.match(serviceWorker, /"\/theme-contract\.mjs"/, "the PWA app shell should cache the startup-critical theme contract");
37
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v154"/, "adding the theme contract to the startup graph should advance the PWA cache identity");
37
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v155"/, "adding the theme contract to the startup graph should advance the PWA cache identity");
38
38
  assert.match(pkg, /node --check public\/theme-contract\.mjs/, "the package check should syntax-check the startup-critical theme contract");
39
39
  assert.match(app, /function themeDraftFromCatalog\(theme, name = theme\?\.name\)[\s\S]*colors: cloneThemeDraft\(theme\?\.colors \|\| \{\}\)/, "catalog metadata should be projected into a schema-only editable draft");
40
40
  assert.match(app, /for \(const \{ name, label \} of group\.tokens\)/, "visual controls should render from the exact shared token inventory");
@@ -1,88 +1,71 @@
1
1
  import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { readFile } from "node:fs/promises";
2
4
  import { ThinkingStreamRecovery, reconcileThinkingSnapshot } from "../lib/thinking-stream-recovery.mjs";
3
5
 
4
- assert.equal(reconcileThinkingSnapshot("complete streamed thinking", "complete streamed"), "complete streamed thinking", "a regressive prefix snapshot must not cut off streamed thinking");
5
- assert.equal(reconcileThinkingSnapshot("complete streamed", "complete streamed thinking"), "complete streamed thinking", "a longer cumulative snapshot should win");
6
- assert.equal(reconcileThinkingSnapshot("draft reasoning", "provider correction"), "provider correction", "divergent authoritative content should still win");
6
+ function update(type, fields = {}) {
7
+ return { type: "message_update", assistantMessageEvent: { type, contentIndex: 0, ...fields } };
8
+ }
7
9
 
8
- const recovery = new ThinkingStreamRecovery();
9
- recovery.ingest({ type: "message_start", message: { role: "assistant", content: [] } });
10
- recovery.ingest({
11
- type: "message_update",
12
- assistantMessageEvent: {
13
- type: "thinking_delta",
14
- contentIndex: 0,
15
- delta: "complete streamed ",
16
- partial: { role: "assistant", content: [{ type: "thinking", thinking: "complete streamed " }] },
17
- },
18
- });
19
- recovery.ingest({
20
- type: "message_update",
21
- assistantMessageEvent: {
22
- type: "thinking_delta",
23
- contentIndex: 0,
24
- delta: "thinking",
25
- partial: { role: "assistant", content: [{ type: "thinking", thinking: "complete streamed thinking" }] },
26
- },
10
+ test("explicit snapshots replace streamed thinking, including empty and shortened text", () => {
11
+ for (const snapshot of ["draft", "", "replacement", "draft with a longer tail"]) {
12
+ assert.equal(reconcileThinkingSnapshot("draft with a tail", snapshot), snapshot);
13
+ }
14
+ assert.equal(reconcileThinkingSnapshot("draft", undefined), "draft");
27
15
  });
28
16
 
29
- const recoveredThinkingEnd = recovery.ingest({
30
- type: "message_update",
31
- assistantMessageEvent: {
32
- type: "thinking_end",
33
- contentIndex: 0,
34
- content: "complete streamed",
35
- partial: { role: "assistant", content: [{ type: "thinking", thinking: "complete streamed" }] },
36
- },
17
+ test("missing thinking-end content is reconstructed without adding cumulative partial snapshots", () => {
18
+ const recovery = new ThinkingStreamRecovery();
19
+ recovery.ingest({ type: "message_start", message: { role: "assistant", content: [] } });
20
+ recovery.ingest(update("thinking_delta", { delta: "first " }));
21
+ recovery.ingest(update("thinking_delta", { delta: "second" }));
22
+ recovery.ingest(update("thinking_delta", { contentIndex: 1, delta: "separate" }));
23
+ const end = recovery.ingest(update("thinking_end"));
24
+ assert.equal(end.assistantMessageEvent.content, "first second");
25
+ assert.equal(end.assistantMessageEvent.partial, undefined);
26
+ assert.equal(recovery.ingest(update("thinking_end", { contentIndex: 1 })).assistantMessageEvent.content, "separate");
37
27
  });
38
- assert.equal(recoveredThinkingEnd.assistantMessageEvent.content, "complete streamed thinking", "thinking_end should expose the complete compatible stream to normal and compact clients");
39
- assert.equal(recoveredThinkingEnd.assistantMessageEvent.partial.content[0].thinking, "complete streamed thinking");
40
28
 
41
- const recoveredMessageEnd = recovery.ingest({
42
- type: "message_end",
43
- message: {
44
- role: "assistant",
45
- timestamp: 1700000000000,
46
- content: [
47
- { type: "thinking", thinking: "complete streamed" },
48
- { type: "text", text: "final answer" },
49
- ],
50
- },
29
+ test("thinking_end corrections are unchanged with both old and snapshot-free RPC events", () => {
30
+ for (const legacy of [false, true]) {
31
+ for (const content of ["draft", "", "provider correction"]) {
32
+ const recovery = new ThinkingStreamRecovery();
33
+ const partial = legacy ? { partial: { role: "assistant", content: [{ type: "thinking", thinking: "draft removed tail" }] } } : {};
34
+ recovery.ingest(update("thinking_delta", { delta: "draft removed tail", ...partial }));
35
+ const end = update("thinking_end", { content, ...partial });
36
+ assert.equal(recovery.ingest(end), end, "explicit end content must not be patched from the stream or stale partial");
37
+ }
38
+ }
51
39
  });
52
- assert.equal(recoveredMessageEnd.message.content[0].thinking, "complete streamed thinking", "message settlement should retain the complete streamed thinking block");
53
-
54
- const fetched = recovery.applyToMessages([
55
- { role: "user", timestamp: 1699999999999, content: "prompt" },
56
- {
57
- role: "assistant",
58
- timestamp: 1700000000000,
59
- content: [
60
- { type: "thinking", thinking: "complete streamed" },
61
- { type: "text", text: "final answer" },
62
- ],
63
- },
64
- ]);
65
- assert.equal(fetched[1].content[0].thinking, "complete streamed thinking", "later get_messages responses should not erase recovered thinking in the main transcript");
66
40
 
67
- const correction = new ThinkingStreamRecovery();
68
- correction.ingest({ type: "message_start", message: { role: "assistant" } });
69
- correction.ingest({
70
- type: "message_update",
71
- assistantMessageEvent: {
72
- type: "thinking_delta",
73
- contentIndex: 0,
74
- delta: "draft reasoning",
75
- partial: { role: "assistant", content: [{ type: "thinking", thinking: "draft reasoning" }] },
76
- },
41
+ test("message_end is authoritative for prefixes, clearing, redaction, removal, and reordered blocks", () => {
42
+ for (const content of [
43
+ [{ type: "thinking", thinking: "draft" }],
44
+ [{ type: "thinking", thinking: "" }],
45
+ [{ type: "thinking", thinking: "", redacted: true, thinkingSignature: "opaque" }],
46
+ [{ type: "text", text: "final answer" }],
47
+ [{ type: "text", text: "answer" }, { type: "thinking", thinking: "replacement" }],
48
+ [],
49
+ ]) {
50
+ const recovery = new ThinkingStreamRecovery();
51
+ recovery.ingest(update("thinking_delta", { delta: "draft removed tail", partial: { role: "assistant", content: [{ type: "thinking", thinking: "draft removed tail" }] } }));
52
+ const end = { type: "message_end", message: { role: "assistant", timestamp: 1, content } };
53
+ const before = structuredClone(end);
54
+ assert.equal(recovery.ingest(end), end);
55
+ assert.deepEqual(end, before);
56
+ assert.equal(recovery.ingest(update("thinking_end")).assistantMessageEvent.content, "", "settlement clears all draft state");
57
+ }
77
58
  });
78
- const correctedEnd = correction.ingest({
79
- type: "message_end",
80
- message: {
81
- role: "assistant",
82
- timestamp: 1700000000001,
83
- content: [{ type: "thinking", thinking: "provider correction" }],
84
- },
59
+
60
+ test("a new assistant message cannot inherit another message's thinking", () => {
61
+ const recovery = new ThinkingStreamRecovery();
62
+ recovery.ingest(update("thinking_delta", { delta: "old message" }));
63
+ recovery.ingest({ type: "message_start", message: { role: "assistant", content: [] } });
64
+ assert.equal(recovery.ingest(update("thinking_end")).assistantMessageEvent.content, "");
85
65
  });
86
- assert.equal(correctedEnd.message.content[0].thinking, "provider correction", "recovery must not overwrite a divergent provider correction");
87
66
 
88
- console.log("thinking-stream-recovery.test.mjs passed");
67
+ test("fetched history bypasses streaming recovery entirely", async () => {
68
+ const server = await readFile(new URL("../bin/pi-webui.mjs", import.meta.url), "utf8");
69
+ assert.match(server, /filterSessionSummaryTranscriptMessages\(filterIntercomTranscriptMessages\(response\.data\.messages\)\)/);
70
+ assert.doesNotMatch(server, /thinkingStreamRecovery\.applyToMessages/);
71
+ });
@@ -0,0 +1,152 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import vm from "node:vm";
4
+ import { readFile } from "node:fs/promises";
5
+ import { createToolCallStreamTracker } from "../public/stream-output-controller.mjs";
6
+
7
+ const isHiddenTool = (name) => name.trim().toLowerCase() === "intercom";
8
+ const tracker = (options = {}) => createToolCallStreamTracker({ isHiddenTool, ...options });
9
+ const event = (type, contentIndex, fields = {}) => ({ type: "message_update", assistantMessageEvent: { type, contentIndex, ...fields } });
10
+ const end = (contentIndex, id, name, args) => event("toolcall_end", contentIndex, { toolCall: { type: "toolCall", id, name, arguments: args } });
11
+
12
+ test("snapshot-free starts retain identity across bare deltas and completed arguments", () => {
13
+ const state = tracker();
14
+ const start = event("toolcall_start", 2, { id: "read-1", toolName: "read" });
15
+ const before = structuredClone(start);
16
+ assert.equal(state.ingest(start).id, "read-1");
17
+ state.ingest(event("toolcall_delta", 2, { delta: '{"path":' }));
18
+ const delta = state.ingest(event("toolcall_delta", 2, { delta: '"雪.txt"}' }));
19
+ assert.equal(delta.name, "read");
20
+ assert.equal(delta.id, "read-1");
21
+ assert.equal(delta.rawArguments, '{"path":"雪.txt"}');
22
+ const result = state.ingest(end(2, "read-1", "read", {}));
23
+ assert.equal(result.rawArguments, "{}", "completed arguments replace even a longer streamed draft");
24
+ assert.equal(result.complete, true);
25
+ assert.deepEqual(start, before);
26
+ });
27
+
28
+ test("interleaved content indexes do not exchange names, IDs, or arguments", () => {
29
+ const state = tracker();
30
+ state.ingest(event("toolcall_start", 0, { id: "a", toolName: "read" }));
31
+ state.ingest(event("toolcall_start", 1, { id: "b", toolName: "write" }));
32
+ state.ingest(event("toolcall_delta", 0, { delta: "first" }));
33
+ state.ingest(event("toolcall_delta", 1, { delta: "second" }));
34
+ assert.equal(state.ingest(event("toolcall_delta", 0, { delta: " tail" })).rawArguments, "first tail");
35
+ const second = state.ingest(event("toolcall_delta", 1, { delta: " end" }));
36
+ assert.equal(second.rawArguments, "second end");
37
+ assert.equal(second.name, "write");
38
+ assert.equal(second.id, "b");
39
+ });
40
+
41
+ test("Intercom stays hidden for every bare argument delta without retaining its arguments", () => {
42
+ const state = tracker();
43
+ for (const input of [
44
+ event("toolcall_start", 1, { id: "hidden", toolName: " Intercom " }),
45
+ event("toolcall_delta", 1, { delta: '{"message":"PRIVATE"}' }),
46
+ end(1, "hidden", "intercom", { message: "PRIVATE" }),
47
+ ]) {
48
+ const call = state.ingest(input);
49
+ assert.equal(call.visible, false);
50
+ assert.equal(call.rawArguments, "");
51
+ assert.equal(call.id, "hidden");
52
+ }
53
+ assert.equal(state.ingest(event("toolcall_start", 2, { id: "visible", toolName: "read" })).visible, true);
54
+ });
55
+
56
+ test("v0.84 starts with no metadata defer display until toolcall_end identifies the call", () => {
57
+ for (const name of ["intercom", "read"]) {
58
+ const state = tracker();
59
+ assert.equal(state.ingest(event("toolcall_start", 0)).visible, false);
60
+ const unknown = state.ingest(event("toolcall_delta", 0, { delta: '{"message":"PRIVATE"}' }));
61
+ assert.equal(unknown.visible, false);
62
+ assert.equal(unknown.rawArguments, "", "unidentified arguments must not be retained for display");
63
+ const result = state.ingest(end(0, "identified", name, { path: "file.txt" }));
64
+ assert.equal(result.visible, name === "read");
65
+ assert.equal(result.rawArguments, name === "read" ? JSON.stringify({ path: "file.txt" }, null, 2) : "");
66
+ }
67
+ });
68
+
69
+ test("legacy cumulative snapshots use only the indexed tool block", () => {
70
+ const state = tracker();
71
+ const message = { role: "assistant", content: [
72
+ { type: "toolCall", id: "a", name: "read", arguments: { path: "a.txt" } },
73
+ { type: "toolCall", id: "b", name: "intercom", arguments: { message: "PRIVATE" } },
74
+ ] };
75
+ const call = state.ingest(event("toolcall_start", 0, { partial: message }));
76
+ assert.equal(call.name, "read");
77
+ assert.equal(call.rawArguments, JSON.stringify({ path: "a.txt" }, null, 2));
78
+ assert.equal(state.ingest(event("toolcall_start", 2, { partial: message })).visible, false, "never borrow the last block's identity");
79
+ });
80
+
81
+ test("message resets and replacement calls clear stale identities", () => {
82
+ const state = tracker();
83
+ state.ingest(event("toolcall_start", 0, { id: "a", toolName: "read" }));
84
+ state.ingest(event("toolcall_delta", 0, { delta: "old" }));
85
+ const replaced = state.ingest(event("toolcall_start", 0, { id: "b", toolName: "write" }));
86
+ assert.equal(replaced.rawArguments, "");
87
+ assert.equal(replaced.id, "b");
88
+ state.reset();
89
+ assert.equal(state.ingest(event("toolcall_delta", 0, { delta: "new" })).visible, false);
90
+ });
91
+
92
+ test("retained calls and argument previews are bounded and resettable", () => {
93
+ const state = tracker({ maxCalls: 1, maxArgumentChars: 4 });
94
+ state.ingest(event("toolcall_start", 0, { id: "a", toolName: "read" }));
95
+ const preview = state.ingest(event("toolcall_delta", 0, { delta: "123456" }));
96
+ assert.equal(preview.rawArguments, "1234");
97
+ assert.equal(preview.truncated, true);
98
+ assert.equal(state.ingest(event("toolcall_start", 1, { id: "b", toolName: "write" })), null);
99
+ assert.equal(state.ingest(end(0, "a", "read", {})).truncated, false);
100
+ state.reset();
101
+ assert.equal(state.ingest(event("toolcall_start", 1, { id: "b", toolName: "write" })).visible, true);
102
+ assert.equal(state.ingest(event("toolcall_delta", -1, { delta: "invalid" })), null);
103
+ assert.throws(() => tracker({ maxCalls: 0 }));
104
+ });
105
+
106
+ const app = await readFile(new URL("../public/app.js", import.meta.url), "utf8");
107
+ function functionSource(name) {
108
+ const start = app.indexOf(`function ${name}(`);
109
+ assert.ok(start >= 0);
110
+ const rest = app.slice(start + 1);
111
+ const next = rest.search(/\n(?:async )?function \w+\(/);
112
+ return app.slice(start, next < 0 ? app.length : start + 1 + next);
113
+ }
114
+
115
+ test("browser tool sink withholds unknown and Intercom calls in normal and compact modes", () => {
116
+ const start = app.indexOf(" applyToolCallUpdate: (event) => {");
117
+ const finish = app.indexOf(" applyToolExecutionUpdate:", start);
118
+ assert.ok(start >= 0 && finish > start);
119
+ for (const compact of [false, true]) {
120
+ const rendered = [];
121
+ const compactEvents = [];
122
+ const context = vm.createContext({
123
+ streamToolCalls: tracker(),
124
+ suppressStreamingAssistantTextBeforeToolCall() {},
125
+ compactOutputActive: () => compact,
126
+ handleCompactMessageUpdate: (input) => compactEvents.push(input),
127
+ rendered,
128
+ });
129
+ vm.runInContext(`
130
+ let streamToolCallSeen = false, streamToolCallBubble = null, streamToolCallText = null;
131
+ let streamToolCallRawArguments = "", streamToolCallName = "", streamToolCallId = "", streamToolCallContentIndex = null, streamToolCallComplete = false;
132
+ function renderStreamingToolCallCard() { rendered.push({ name: streamToolCallName, id: streamToolCallId, args: streamToolCallRawArguments }); }
133
+ ${functionSource("resetStreamingToolCallState")}
134
+ ${functionSource("updateStreamingToolCallFromState")}
135
+ const sink = { ${app.slice(start, finish)} };
136
+ globalThis.apply = sink.applyToolCallUpdate;
137
+ `, context);
138
+ for (const name of [undefined, "intercom"]) {
139
+ context.apply(event("toolcall_start", 0, name ? { id: "hidden", toolName: name } : {}));
140
+ context.apply(event("toolcall_delta", 0, { delta: "PRIVATE" }));
141
+ context.apply(end(0, "hidden", "intercom", { message: "PRIVATE" }));
142
+ }
143
+ assert.equal(rendered.length, 0);
144
+ assert.equal(compactEvents.length, 0);
145
+ context.apply(event("toolcall_start", 1, { id: "visible", toolName: "read" }));
146
+ context.apply(event("toolcall_delta", 1, { delta: "visible args" }));
147
+ if (compact) assert.equal(compactEvents.length, 2);
148
+ else assert.equal(JSON.stringify(rendered.at(-1)), JSON.stringify({ name: "read", id: "visible", args: "visible args" }));
149
+ }
150
+ assert.match(functionSource("resetStreamBubble"), /streamToolCalls\.reset\(\)/);
151
+ assert.match(app, /case "message_end": \{\s+if \(event\.message\?\.role === "assistant"\) streamToolCalls\.reset\(\)/);
152
+ });
@@ -74,8 +74,8 @@ assert.match(technical, /working-directory picker accepts a direct path[\s\S]*\*
74
74
  assert.match(development, /virtual \*\*This PC\*\* response with an empty cwd and `selectable: false`/i, "the contributor guide should record the server/browser virtual-view contract");
75
75
  assert.ok(packageJson.files.includes("TECHNICAL.md"), "the published package should include its advanced user reference");
76
76
  assert.ok(packageJson.files.includes("DEVELOPMENT.md"), "the published package should include its contributor guide");
77
- assert.match(html, /styles\.css\?v=152/, "the existing picker layout should retain its stylesheet revision");
78
- assert.match(html, /app\.js\?v=183/, "the changed picker behavior should advance the app revision");
79
- assert.match(serviceWorker, /pi-webui-pwa-v154/, "the changed browser assets should advance the PWA cache identity");
77
+ assert.match(html, /styles\.css\?v=154/, "the existing picker layout should retain its stylesheet revision");
78
+ assert.match(html, /app\.js\?v=184/, "the changed picker behavior should advance the app revision");
79
+ assert.match(serviceWorker, /pi-webui-pwa-v155/, "the changed browser assets should advance the PWA cache identity");
80
80
 
81
81
  console.log("windows-drive-cwd-picker-static.test.mjs passed");