@firstpick/pi-package-webui 0.9.5 → 0.9.7
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/README.md +11 -5
- package/bin/pi-webui.mjs +457 -77
- package/lib/git-workflow-preferences.mjs +21 -1
- package/lib/optional-feature-catalog.mjs +1 -1
- package/lib/session-actions.mjs +20 -2
- package/lib/session-tree-event-targets.mjs +70 -0
- package/lib/subagent-launch-policy.mjs +375 -0
- package/lib/subagent-launch-slots.mjs +2 -1
- package/package.json +1 -1
- package/public/app.js +2539 -292
- package/public/index.html +87 -31
- package/public/service-worker.js +4 -1
- package/public/stream-derived-output.mjs +799 -0
- package/public/stream-markdown-tail.mjs +204 -0
- package/public/stream-output-controller.mjs +193 -51
- package/public/stream-render-scheduler.mjs +85 -0
- package/public/styles.css +501 -19
- package/public/transcript-renderer.mjs +73 -24
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/composer-action-grid-reorder.spec.mjs +114 -31
- package/tests/browser/control-visibility.spec.mjs +141 -2
- package/tests/browser/events-tree-context-menu.spec.mjs +240 -0
- package/tests/browser/guided-git-fallback.spec.mjs +153 -0
- package/tests/browser/mobile-foundation.spec.mjs +28 -0
- package/tests/browser/stream-output-isolation.spec.mjs +308 -3
- package/tests/browser/user-noticeable-fixes.spec.mjs +204 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/compact-sections-static.test.mjs +4 -0
- package/tests/composer-action-grid-reorder-static.test.mjs +8 -7
- package/tests/control-visibility-static.test.mjs +66 -3
- package/tests/controls-layout-static.test.mjs +3 -3
- package/tests/cwd-footer-reliability-static.test.mjs +1 -1
- package/tests/events-tree-context-menu-static.test.mjs +131 -0
- package/tests/fast-mode-client-static.test.mjs +5 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/file-viewer-image-static.test.mjs +3 -3
- package/tests/fixtures/fake-pi.mjs +57 -10
- package/tests/fixtures/streaming-workloads.mjs +36 -0
- package/tests/footer-provider-usage-visual-static.test.mjs +15 -0
- package/tests/foreground-transcript-catch-up-static.test.mjs +7 -1
- package/tests/git-workflow-preferences.test.mjs +30 -1
- package/tests/guided-git-fallback-runtime.test.mjs +418 -0
- package/tests/guided-git-fallback-ui-static.test.mjs +60 -0
- package/tests/guided-git-message-reliability-static.test.mjs +8 -7
- package/tests/interaction-state-stability-static.test.mjs +3 -1
- package/tests/intercom-conversation-viewer-static.test.mjs +3 -3
- package/tests/intercom-conversations-http.test.mjs +16 -0
- package/tests/main-output-loading-static.test.mjs +3 -3
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +80 -67
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +4 -4
- package/tests/prompt-input-vertical-scroll-static.test.mjs +26 -0
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +23 -0
- package/tests/resource-defaults-helper.test.mjs +12 -0
- package/tests/runtime-error-visibility.test.mjs +3 -3
- package/tests/session-auth-harness.test.mjs +26 -1
- package/tests/session-sampling-helper.test.mjs +1 -0
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/session-tree-event-targets.test.mjs +106 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-derived-output.test.mjs +121 -0
- package/tests/stream-markdown-tail.test.mjs +218 -0
- package/tests/stream-output-controller.test.mjs +119 -4
- package/tests/stream-output-isolation-static.test.mjs +27 -6
- package/tests/stream-output-workloads.test.mjs +40 -3
- package/tests/stream-render-scheduler.test.mjs +115 -0
- package/tests/streaming-ui-coupling.test.mjs +1 -1
- package/tests/subagent-launch-policy.test.mjs +532 -0
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagents-helper.test.mjs +211 -1
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +23 -0
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thinking-format-parser.test.mjs +15 -0
- package/tests/todo-filter-static.test.mjs +148 -0
- package/tests/transcript-markdown-tail.test.mjs +137 -0
- package/webui-rpc-helper.mjs +220 -3
|
@@ -223,7 +223,7 @@ assert.match(
|
|
|
223
223
|
);
|
|
224
224
|
assert.match(
|
|
225
225
|
app,
|
|
226
|
-
/function restoreComposerActionSlotLayout\(\)[\s\S]*stored\.columns === columns[\s\S]*
|
|
226
|
+
/function restoreComposerActionSlotLayout\(\)[\s\S]*stored\.columns === columns[\s\S]*projectComposerActionSlots[\s\S]*nearestAvailableComposerActionSlot/,
|
|
227
227
|
"stored slots should project into mismatched column counts without rewriting the saved source geometry",
|
|
228
228
|
);
|
|
229
229
|
|
|
@@ -271,8 +271,8 @@ assert.match(
|
|
|
271
271
|
|
|
272
272
|
// --- Coherent browser asset revisions --------------------------------------
|
|
273
273
|
|
|
274
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
275
|
-
assert.match(html, /styles\.css\?v=
|
|
276
|
-
assert.match(html, /data-app-src="\/app\.js\?v=
|
|
274
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v132"/, "changed browser assets should advance the PWA cache identity");
|
|
275
|
+
assert.match(html, /styles\.css\?v=137/, "the page should request the updated layout stylesheet revision");
|
|
276
|
+
assert.match(html, /data-app-src="\/app\.js\?v=166"/, "the boot loader should request the updated app module revision");
|
|
277
277
|
|
|
278
278
|
console.log("persistent-ui-layout-static.test.mjs passed");
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const [app, css, html, serviceWorker] = await Promise.all([
|
|
8
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
9
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
10
|
+
readFile(join(root, "public", "index.html"), "utf8"),
|
|
11
|
+
readFile(join(root, "public", "service-worker.js"), "utf8"),
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const resizeStart = app.indexOf("function resizePromptInput()");
|
|
15
|
+
const resizeEnd = app.indexOf("\nfunction updateComposerModeButtons", resizeStart);
|
|
16
|
+
assert.ok(resizeStart >= 0 && resizeEnd > resizeStart, "resizePromptInput should remain inspectable");
|
|
17
|
+
const resizePromptInput = app.slice(resizeStart, resizeEnd);
|
|
18
|
+
|
|
19
|
+
assert.match(css, /#promptInput \{[\s\S]*max-height: min\(25vh, 10rem\);[\s\S]*overflow-y: auto;[\s\S]*overscroll-behavior-y: contain;/, "the prompt should retain bounded growth with native vertical scrolling as its CSS fallback");
|
|
20
|
+
assert.match(resizePromptInput, /input\.style\.height = "auto";[\s\S]*Math\.min\(input\.scrollHeight, maxHeight\)[\s\S]*input\.style\.overflowY = "auto";/, "every auto-resize pass should preserve vertical scrolling after the height cap is reached or growth stalls");
|
|
21
|
+
assert.doesNotMatch(resizePromptInput, /overflowY[^\n]+"hidden"/, "auto-resizing must not disable the prompt's vertical overflow fallback");
|
|
22
|
+
assert.match(html, /styles\.css\?v=137/, "the page should request the scroll-enabled stylesheet revision");
|
|
23
|
+
assert.match(html, /app\.js\?v=166/, "the page should request the scroll-enabled app revision");
|
|
24
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v132"/, "the PWA cache identity should advance with the prompt scroll assets");
|
|
25
|
+
|
|
26
|
+
console.log("prompt-input-vertical-scroll-static.test.mjs passed");
|
|
@@ -504,8 +504,8 @@ assert.match(css, /@media \(max-width: 720px\), \(max-device-width: 720px\), \(p
|
|
|
504
504
|
assert.match(css, /\.questionnaire-options button\s*\{\s*min-height:\s*3\.35rem/, "mobile questionnaire targets must exceed the 44px floor");
|
|
505
505
|
assert.match(css, /@media \(prefers-reduced-motion: reduce\)\s*\{[\s\S]*?\*, \*::before, \*::after[\s\S]*?transition-duration:\s*1ms !important/, "global reduced-motion rules must cover questionnaire transitions");
|
|
506
506
|
|
|
507
|
-
assert.match(html, /styles\.css\?v=
|
|
508
|
-
assert.match(html, /app\.js\?v=
|
|
509
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
507
|
+
assert.match(html, /styles\.css\?v=137/, "questionnaire CSS needs the current stylesheet revision");
|
|
508
|
+
assert.match(html, /app\.js\?v=166/, "questionnaire behavior needs the current app revision");
|
|
509
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v132"/, "questionnaire public assets need a coherent PWA cache revision");
|
|
510
510
|
|
|
511
511
|
console.log("questionnaire-dialog.test.mjs passed");
|
|
@@ -133,6 +133,11 @@ try {
|
|
|
133
133
|
assert.equal(initialGitSetup.body?.data?.configured, false, "guided Git should require first-time model setup");
|
|
134
134
|
assert.equal(initialGitSetup.body?.data?.preferences?.stagingPolicy, "review", "review/select should be the safe staging default");
|
|
135
135
|
assert.equal(initialGitSetup.body?.data?.preferences?.reviewProcessEnabled, true, "manual review should remain enabled by default for compatibility");
|
|
136
|
+
assert.deepEqual(initialGitSetup.body?.data?.preferences?.generation?.fallback, {
|
|
137
|
+
provider: "",
|
|
138
|
+
modelId: "",
|
|
139
|
+
thinkingLevel: "low",
|
|
140
|
+
}, "existing settings should expose fallback as disabled until explicitly selected");
|
|
136
141
|
assert.equal(initialGitSetup.body?.data?.models?.[0]?.id, "fake-model");
|
|
137
142
|
|
|
138
143
|
const unsupportedEffort = await request("/api/git-workflow/preferences", {
|
|
@@ -141,6 +146,24 @@ try {
|
|
|
141
146
|
});
|
|
142
147
|
assert.equal(unsupportedEffort.status, 400, "setup should reject effort levels unsupported by the selected model");
|
|
143
148
|
|
|
149
|
+
const sameAsPrimaryFallback = await request("/api/git-workflow/preferences", {
|
|
150
|
+
method: "POST",
|
|
151
|
+
body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", fallback: { provider: "fake", modelId: "fake-model", thinkingLevel: "off" } } } },
|
|
152
|
+
});
|
|
153
|
+
assert.equal(sameAsPrimaryFallback.status, 400, "setup should reject a fallback equal to the primary model");
|
|
154
|
+
|
|
155
|
+
const unavailableFallback = await request("/api/git-workflow/preferences", {
|
|
156
|
+
method: "POST",
|
|
157
|
+
body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", fallback: { provider: "fake", modelId: "missing-model", thinkingLevel: "off" } } } },
|
|
158
|
+
});
|
|
159
|
+
assert.equal(unavailableFallback.status, 400, "setup should reject unavailable fallback models");
|
|
160
|
+
|
|
161
|
+
const invalidFallbackEffort = await request("/api/git-workflow/preferences", {
|
|
162
|
+
method: "POST",
|
|
163
|
+
body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", fallback: { provider: "", modelId: "", thinkingLevel: "extreme" } } } },
|
|
164
|
+
});
|
|
165
|
+
assert.equal(invalidFallbackEffort.status, 400, "setup should reject unsupported fallback effort values even while fallback is disabled");
|
|
166
|
+
|
|
144
167
|
const invalidStagingPolicy = await request("/api/git-workflow/preferences", {
|
|
145
168
|
method: "POST",
|
|
146
169
|
body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off" }, stagingPolicy: "everything" } },
|
|
@@ -58,6 +58,7 @@ try {
|
|
|
58
58
|
extensionHandlers.set(name, handlers);
|
|
59
59
|
},
|
|
60
60
|
registerCommand(name, command) { registeredCommands.set(name, command); },
|
|
61
|
+
registerTool() {},
|
|
61
62
|
getAllTools() {
|
|
62
63
|
return ["read", "bash", "write"].map((name) => ({ name, description: `${name} tool`, sourceInfo: { source: "builtin" } }));
|
|
63
64
|
},
|
|
@@ -109,9 +110,20 @@ try {
|
|
|
109
110
|
for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "startup" }, ctx);
|
|
110
111
|
assert.deepEqual(activeTools, ["read", "bash", "write"], "an initial settings-read failure must leave Pi's runtime tools unchanged");
|
|
111
112
|
assert.ok(notifications.some((entry) => /tools and skills remain unchanged/i.test(entry.message)), "initial settings failure should emit a bounded warning");
|
|
113
|
+
const applyLaunchSlotDefaults = (extensionHandlers.get("tool_call") || [])[0];
|
|
114
|
+
assert.ok(applyLaunchSlotDefaults, "resource defaults helper should register launch-slot admission");
|
|
115
|
+
const unavailableReviewer = await applyLaunchSlotDefaults({ toolName: "subagent", input: { agent: "reviewer", task: "Review while settings are unavailable" } }, ctx);
|
|
116
|
+
assert.equal(unavailableReviewer?.block, true, "a reviewer-bearing direct launch must fail closed after snapshot load failure");
|
|
117
|
+
assert.match(unavailableReviewer?.reason || "", /snapshot could not be loaded.*Reload the active tab/i);
|
|
118
|
+
const unavailableWorkflow = await applyLaunchSlotDefaults({ toolName: "subagent", input: { workflowScript: "return runs.run('review', {agent:'reviewer', task:'Review'})" } }, ctx);
|
|
119
|
+
assert.equal(unavailableWorkflow?.block, true, "an opaque workflow launch must fail closed after snapshot load failure");
|
|
120
|
+
const unaffectedDelegate = { agent: "delegate", task: "Continue non-reviewer work", model: "provider/delegate" };
|
|
121
|
+
assert.equal(await applyLaunchSlotDefaults({ toolName: "subagent", input: unaffectedDelegate }, ctx), undefined, "a non-reviewer direct launch should remain available after snapshot load failure");
|
|
122
|
+
assert.equal(unaffectedDelegate.model, "provider/delegate");
|
|
112
123
|
|
|
113
124
|
await writeFile(settingsFile, `${JSON.stringify(settingsPayload, null, 2)}\n`, "utf8");
|
|
114
125
|
for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "settings-restored" }, ctx);
|
|
126
|
+
assert.equal(await applyLaunchSlotDefaults({ toolName: "subagent", input: { agent: "reviewer", task: "Review after reload" } }, ctx), undefined, "a successful reload should clear snapshot-failure admission blocking");
|
|
115
127
|
availableSkills = ["skill-a", "skill-b", "skill-c"];
|
|
116
128
|
assert.deepEqual(activeTools, ["read", "write"], "a new session should inherit the global tool allowlist");
|
|
117
129
|
assert.deepEqual(
|
|
@@ -8,7 +8,7 @@ const app = await readFile(join(root, "public", "app.js"), "utf8");
|
|
|
8
8
|
|
|
9
9
|
assert.match(
|
|
10
10
|
app,
|
|
11
|
-
/function surfaceRuntimeDiagnostic\(title, content, level = "error"\)[\s\S]*?addEvent\(message, level\);[\s\S]*?addTransientMessage\(\{ role: level === "error" \? "error" : "warn", title, content: message, level \}\);/,
|
|
11
|
+
/function surfaceRuntimeDiagnostic\(title, content, level = "error", \{ actions = null \} = \{\}\)[\s\S]*?addEvent\(message, level, \{ notify: false \}\);[\s\S]*?addTransientMessage\(\{ role: level === "error" \? "error" : "warn", title, content: message, level, \.\.\.\(actions \? \{ actions \} : \{\}\) \}\);/,
|
|
12
12
|
"runtime diagnostics should be written to both the event log and the visible transcript",
|
|
13
13
|
);
|
|
14
14
|
assert.match(
|
|
@@ -23,7 +23,7 @@ assert.match(
|
|
|
23
23
|
);
|
|
24
24
|
assert.match(
|
|
25
25
|
app,
|
|
26
|
-
/case "message_end":[\s\S]*?event\.message\.stopReason === "error"[\s\S]*?surfaceRuntimeDiagnostic\("Assistant error", message\)[\s\S]*?assistantErrorSurfacedThisRun = true/,
|
|
26
|
+
/case "message_end":[\s\S]*?event\.message\.stopReason === "error"[\s\S]*?surfaceRuntimeDiagnostic\("Assistant error", describeAssistantFailure\(message\), "error", \{ actions: assistantFailureActions\([\s\S]*?assistantErrorSurfacedThisRun = true/,
|
|
27
27
|
"final assistant errors should remain visible after transcript reconciliation",
|
|
28
28
|
);
|
|
29
29
|
assert.match(
|
|
@@ -33,7 +33,7 @@ assert.match(
|
|
|
33
33
|
);
|
|
34
34
|
assert.match(
|
|
35
35
|
app,
|
|
36
|
-
/case "agent_end":[\s\S]*?!assistantErrorSurfacedThisRun && event\.willRetry !== true[\s\S]*?assistantErrorFromAgentEnd\(event\)[\s\S]*?surfaceRuntimeDiagnostic\("Assistant error", message\)/,
|
|
36
|
+
/case "agent_end":[\s\S]*?!assistantErrorSurfacedThisRun && event\.willRetry !== true[\s\S]*?assistantErrorFromAgentEnd\(event\)[\s\S]*?surfaceRuntimeDiagnostic\("Assistant error", describeAssistantFailure\(message\)/,
|
|
37
37
|
"agent_end should visibly surface a non-retrying provider error when message_end was absent",
|
|
38
38
|
);
|
|
39
39
|
assert.match(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
@@ -75,6 +75,31 @@ try {
|
|
|
75
75
|
assert.equal(isSessionPathAllowed(path.join(tempDir, "..", "escape.jsonl"), [tempDir]), false);
|
|
76
76
|
assert.equal(isSessionPathAllowed(outsidePath, []), true, "empty allowedDirs must mean no confinement");
|
|
77
77
|
|
|
78
|
+
// Symlinked session dir (e.g. ~/.pi -> dotfiles): a not-yet-created session
|
|
79
|
+
// file must still canonicalize through the symlink, otherwise every fresh
|
|
80
|
+
// session is rejected with "sessionPath must stay inside the Pi session
|
|
81
|
+
// directory" until its file first exists on disk.
|
|
82
|
+
const realSessionDir = await mkdtemp(path.join(tmpdir(), "pi-webui-real-sessions-"));
|
|
83
|
+
const symlinkParent = await mkdtemp(path.join(tmpdir(), "pi-webui-link-parent-"));
|
|
84
|
+
const symlinkedSessionDir = path.join(symlinkParent, "sessions-link");
|
|
85
|
+
await symlink(realSessionDir, symlinkedSessionDir, "dir");
|
|
86
|
+
const pendingSessionFile = path.join(symlinkedSessionDir, "not-created-yet.jsonl");
|
|
87
|
+
assert.equal(
|
|
88
|
+
isSessionPathAllowed(pendingSessionFile, [realSessionDir]),
|
|
89
|
+
true,
|
|
90
|
+
"non-existent session file under a symlinked session dir must be allowed",
|
|
91
|
+
);
|
|
92
|
+
assert.equal(
|
|
93
|
+
isSessionPathAllowed(path.join(realSessionDir, "not-created-yet.jsonl"), [symlinkedSessionDir]),
|
|
94
|
+
true,
|
|
95
|
+
"real path target must be allowed when the configured dir is the symlink",
|
|
96
|
+
);
|
|
97
|
+
assert.equal(
|
|
98
|
+
isSessionPathAllowed(path.join(symlinkedSessionDir, "..", "escape.jsonl"), [realSessionDir]),
|
|
99
|
+
false,
|
|
100
|
+
"traversal through a symlinked session dir must stay blocked",
|
|
101
|
+
);
|
|
102
|
+
|
|
78
103
|
const blockedOutside = validateSessionDelete(outsidePath, {
|
|
79
104
|
openSessionFiles: new Set(),
|
|
80
105
|
currentSessionFile: undefined,
|
|
@@ -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-
|
|
60
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v132"/, "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=
|
|
63
|
-
assert.match(html, /app\.js\?v=
|
|
62
|
+
assert.match(html, /styles\.css\?v=137/, "the changed stylesheet should have a new revision");
|
|
63
|
+
assert.match(html, /app\.js\?v=166/, "the changed app module should have a new revision");
|
|
64
64
|
|
|
65
65
|
// --- Browser state behavior -------------------------------------------------
|
|
66
66
|
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { sessionTreeEventTargets } from "../lib/session-tree-event-targets.mjs";
|
|
3
|
+
|
|
4
|
+
function messageEntry(id, message) {
|
|
5
|
+
return { type: "message", id, parentId: null, timestamp: "2026-08-20T12:00:00.000Z", message };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
const entries = [
|
|
10
|
+
messageEntry("assistant-1", {
|
|
11
|
+
role: "assistant",
|
|
12
|
+
content: [
|
|
13
|
+
{ type: "text", text: "PRIVATE_ASSISTANT_TEXT" },
|
|
14
|
+
{ type: "toolCall", id: "call-read", name: "read", arguments: { path: "/private/secret.txt" } },
|
|
15
|
+
{ type: "toolCall", toolCallId: "call-bash", toolName: "bash", arguments: { command: "printenv TOKEN" } },
|
|
16
|
+
],
|
|
17
|
+
}),
|
|
18
|
+
messageEntry("result-read", {
|
|
19
|
+
role: "toolResult",
|
|
20
|
+
toolCallId: "call-read",
|
|
21
|
+
toolName: "read",
|
|
22
|
+
content: [{ type: "text", text: "PRIVATE_READ_RESULT" }],
|
|
23
|
+
}),
|
|
24
|
+
messageEntry("result-bash", {
|
|
25
|
+
role: "toolResult",
|
|
26
|
+
toolCallId: "call-bash",
|
|
27
|
+
toolName: "bash",
|
|
28
|
+
content: [{ type: "text", text: "PRIVATE_BASH_RESULT" }],
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const targets = sessionTreeEventTargets(entries);
|
|
33
|
+
assert.deepEqual(targets, [
|
|
34
|
+
{ toolCallId: "call-read", toolName: "read", startEntryId: "assistant-1", finishEntryId: "result-read" },
|
|
35
|
+
{ toolCallId: "call-bash", toolName: "bash", startEntryId: "assistant-1", finishEntryId: "result-bash" },
|
|
36
|
+
], "multiple calls should map their shared assistant start and distinct result finishes in call order");
|
|
37
|
+
assert.equal(JSON.stringify(targets).includes("PRIVATE_"), false, "message and result content must not enter event targets");
|
|
38
|
+
assert.equal(JSON.stringify(targets).includes("/private/secret.txt"), false, "tool arguments must not enter event targets");
|
|
39
|
+
assert.deepEqual(Object.keys(targets[0]), ["toolCallId", "toolName", "startEntryId", "finishEntryId"], "the contract should expose only the four approved fields");
|
|
40
|
+
assert.doesNotThrow(() => JSON.stringify(targets), "event targets should be JSON-safe");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
{
|
|
44
|
+
const entries = [
|
|
45
|
+
messageEntry("assistant-first", {
|
|
46
|
+
role: "assistant",
|
|
47
|
+
content: [
|
|
48
|
+
{ type: "toolCall", id: "duplicate", name: "first-name", arguments: { secret: "FIRST_ARGUMENT_SECRET" } },
|
|
49
|
+
{ type: "toolCall", id: "", name: "missing-id" },
|
|
50
|
+
{ type: "toolCall", name: "also-missing-id" },
|
|
51
|
+
],
|
|
52
|
+
}),
|
|
53
|
+
messageEntry("assistant-later", {
|
|
54
|
+
role: "assistant",
|
|
55
|
+
content: [{ type: "toolCall", id: "duplicate", name: "later-name", arguments: { secret: "LATER_ARGUMENT_SECRET" } }],
|
|
56
|
+
}),
|
|
57
|
+
messageEntry("result-first", {
|
|
58
|
+
role: "toolResult",
|
|
59
|
+
toolCallId: "duplicate",
|
|
60
|
+
toolName: "result-name",
|
|
61
|
+
content: "FIRST_RESULT_SECRET",
|
|
62
|
+
}),
|
|
63
|
+
messageEntry("result-later", {
|
|
64
|
+
role: "toolResult",
|
|
65
|
+
toolCallId: "duplicate",
|
|
66
|
+
toolName: "later-result-name",
|
|
67
|
+
content: "LATER_RESULT_SECRET",
|
|
68
|
+
}),
|
|
69
|
+
messageEntry("result-missing-id", { role: "toolResult", toolName: "read", content: "MISSING_ID_RESULT_SECRET" }),
|
|
70
|
+
messageEntry("not-a-tool-call", { role: "assistant", content: [{ type: "text", text: "ignore" }] }),
|
|
71
|
+
{ type: "message", message: { role: "toolResult", toolCallId: "missing-entry-id", toolName: "read" } },
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
assert.deepEqual(sessionTreeEventTargets(entries), [
|
|
75
|
+
{ toolCallId: "duplicate", toolName: "first-name", startEntryId: "assistant-first", finishEntryId: "result-first" },
|
|
76
|
+
], "missing IDs should be ignored and duplicate boundaries should keep their first stable entry IDs and tool name");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
{
|
|
80
|
+
const finishOnly = sessionTreeEventTargets([
|
|
81
|
+
messageEntry("finish-only-entry", {
|
|
82
|
+
role: "toolResult",
|
|
83
|
+
toolCallId: "finish-only",
|
|
84
|
+
toolName: "write",
|
|
85
|
+
content: [{ type: "text", text: "FINISH_ONLY_RESULT_SECRET" }],
|
|
86
|
+
}),
|
|
87
|
+
]);
|
|
88
|
+
assert.deepEqual(finishOnly, [
|
|
89
|
+
{ toolCallId: "finish-only", toolName: "write", startEntryId: null, finishEntryId: "finish-only-entry" },
|
|
90
|
+
], "persisted finish-only records should remain navigable without inventing a start boundary");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
{
|
|
94
|
+
const resultBeforeCall = sessionTreeEventTargets([
|
|
95
|
+
messageEntry("finish-before-start", { role: "toolResult", toolCallId: "out-of-order", toolName: "bash", content: "secret" }),
|
|
96
|
+
messageEntry("start-after-finish", { role: "assistant", content: [{ type: "toolCall", id: "out-of-order", name: "bash", arguments: {} }] }),
|
|
97
|
+
]);
|
|
98
|
+
assert.deepEqual(resultBeforeCall, [
|
|
99
|
+
{ toolCallId: "out-of-order", toolName: "bash", startEntryId: "start-after-finish", finishEntryId: "finish-before-start" },
|
|
100
|
+
], "merge logic should fill either boundary without depending on entry ordering");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
assert.deepEqual(sessionTreeEventTargets(undefined), [], "non-array input should return an empty JSON-safe list");
|
|
104
|
+
assert.deepEqual(sessionTreeEventTargets([null, {}, { type: "message", id: "empty-message" }]), [], "malformed entries should be ignored");
|
|
105
|
+
|
|
106
|
+
console.log("session-tree-event-targets.test.mjs passed");
|
|
@@ -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=
|
|
31
|
-
assert.match(html, /app\.js\?v=
|
|
32
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
30
|
+
assert.match(html, /styles\.css\?v=137/, "removing section resize styles should advance the stylesheet revision");
|
|
31
|
+
assert.match(html, /app\.js\?v=166/, "removing section resize behavior should advance the app revision");
|
|
32
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v132"/, "removing browser assets should advance the PWA cache identity");
|
|
33
33
|
|
|
34
34
|
console.log("side-panel-section-height-removal-static.test.mjs passed");
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import {
|
|
3
|
+
createStreamDerivedOutputState,
|
|
4
|
+
deriveStreamOutputAuthoritative,
|
|
5
|
+
splitThinkingFormatTextAuthoritative,
|
|
6
|
+
stripTodoProgressLinesAuthoritative,
|
|
7
|
+
} from "../public/stream-derived-output.mjs";
|
|
8
|
+
|
|
9
|
+
function plain(value) {
|
|
10
|
+
return JSON.parse(JSON.stringify(value));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function assertCurrent(state, rawText, options, label) {
|
|
14
|
+
assert.deepEqual(
|
|
15
|
+
plain(state.value()),
|
|
16
|
+
plain(deriveStreamOutputAuthoritative(rawText, options)),
|
|
17
|
+
label,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function verifyEverySplit(rawText, options = {}) {
|
|
22
|
+
for (let split = 0; split <= rawText.length; split += 1) {
|
|
23
|
+
const state = createStreamDerivedOutputState({ ...options, shadow: true });
|
|
24
|
+
const first = rawText.slice(0, split);
|
|
25
|
+
const second = rawText.slice(split);
|
|
26
|
+
state.append(first);
|
|
27
|
+
assertCurrent(state, first, options, `prefix at code-unit split ${split}: ${JSON.stringify(rawText)}`);
|
|
28
|
+
state.append(second);
|
|
29
|
+
assertCurrent(state, rawText, options, `complete at code-unit split ${split}: ${JSON.stringify(rawText)}`);
|
|
30
|
+
assert.equal(state.takeDiagnostics().shadowMismatch, false, `shadow parse should agree at split ${split}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const state = createStreamDerivedOutputState({ ...options, shadow: true });
|
|
34
|
+
for (let index = 0; index < rawText.length; index += 1) {
|
|
35
|
+
state.append(rawText.slice(index, index + 1));
|
|
36
|
+
assertCurrent(state, rawText.slice(0, index + 1), options, `single-code-unit chunk ${index}: ${JSON.stringify(rawText)}`);
|
|
37
|
+
assert.equal(state.takeDiagnostics().shadowMismatch, false, `shadow parse should agree after code unit ${index}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
assert.equal(
|
|
42
|
+
stripTodoProgressLinesAuthoritative("Goal: ship\r\n- [ ] first\r\n- [x] second\r\nAnswer", { streaming: true }),
|
|
43
|
+
"Goal: ship\nAnswer",
|
|
44
|
+
"authoritative todo filtering should retain current CRLF normalization",
|
|
45
|
+
);
|
|
46
|
+
assert.equal(
|
|
47
|
+
stripTodoProgressLinesAuthoritative("```md\n- [ ] literal\n```\n- [ ] transport\nAnswer", { streaming: true }),
|
|
48
|
+
"```md\n- [ ] literal\n```\nAnswer",
|
|
49
|
+
"todo-looking lines inside fences must stay visible",
|
|
50
|
+
);
|
|
51
|
+
assert.deepEqual(plain(splitThinkingFormatTextAuthoritative("<think>first</think><think>second</think>\nanswer", { streaming: true })), {
|
|
52
|
+
hasThinkingFormat: true,
|
|
53
|
+
thinkingText: "first\n\nsecond",
|
|
54
|
+
finalText: "answer",
|
|
55
|
+
complete: true,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const representativeCases = [
|
|
59
|
+
"Plain assistant output with no derived markers.",
|
|
60
|
+
"Goal: preserve semantics\r\n- [ ] pending\r\n1. [x] complete\r\nFinal answer 😀",
|
|
61
|
+
"Before\n\n\n```md\r\n- [ ] literal checklist\r\n```\n\n\nAfter",
|
|
62
|
+
"- [",
|
|
63
|
+
"- [not a todo after all",
|
|
64
|
+
"<th",
|
|
65
|
+
"<think>reasoning</thi",
|
|
66
|
+
"<think>reasoning</think>\r\nfinal answer",
|
|
67
|
+
"<think data-kind=\"analysis\">reasoning</think >\nfinal",
|
|
68
|
+
"<think>The user mentioned `<think>example</think>` inside the reasoning.</think>\nfinal answer",
|
|
69
|
+
"<think>first</think><think>second</think>\nanswer",
|
|
70
|
+
"<think>first</think> \r\n<think>second</think>\r\nanswer",
|
|
71
|
+
"<think>first</think><th",
|
|
72
|
+
"<|analysis>channel reasoning<analysis|>\nanswer",
|
|
73
|
+
"<|analysis>one<analysis|><|reflection>two<reflection|>answer",
|
|
74
|
+
"<|Analysis>Unicode 😀 e\u0301 漢字<ANALYSIS|>\r\nfinal 🚀",
|
|
75
|
+
"<think>nested <think>inner</think> tail</think>\nanswer",
|
|
76
|
+
"<think>partial close with spaces</thi ",
|
|
77
|
+
"<think>todo in thought\n- [ ] hidden</think>\n- [x] transport\nvisible",
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
for (const rawText of representativeCases) verifyEverySplit(rawText, { todoProgressDetected: true });
|
|
81
|
+
for (const rawText of representativeCases.slice(0, 6)) verifyEverySplit(rawText, { todoProgressDetected: false });
|
|
82
|
+
|
|
83
|
+
const suffixState = createStreamDerivedOutputState({ todoProgressDetected: true, shadow: false });
|
|
84
|
+
const longPrefix = "x".repeat(100_000);
|
|
85
|
+
suffixState.append(longPrefix);
|
|
86
|
+
assert.deepEqual(suffixState.takeDiagnostics(), {
|
|
87
|
+
scannedCodeUnits: longPrefix.length,
|
|
88
|
+
fallbackReason: "",
|
|
89
|
+
shadowMismatch: false,
|
|
90
|
+
});
|
|
91
|
+
suffixState.append("y");
|
|
92
|
+
assert.deepEqual(suffixState.takeDiagnostics(), {
|
|
93
|
+
scannedCodeUnits: 1,
|
|
94
|
+
fallbackReason: "",
|
|
95
|
+
shadowMismatch: false,
|
|
96
|
+
}, "a normal append should report only the newly scanned suffix");
|
|
97
|
+
|
|
98
|
+
suffixState.replace(`${longPrefix}snapshot`, { reason: "authoritative-snapshot" });
|
|
99
|
+
assert.deepEqual(suffixState.takeDiagnostics(), {
|
|
100
|
+
scannedCodeUnits: longPrefix.length + "snapshot".length,
|
|
101
|
+
fallbackReason: "authoritative-snapshot",
|
|
102
|
+
shadowMismatch: false,
|
|
103
|
+
}, "snapshot replacement should expose its full authoritative fallback scan");
|
|
104
|
+
|
|
105
|
+
const divergenceState = createStreamDerivedOutputState({ shadow: true });
|
|
106
|
+
divergenceState.append("- ");
|
|
107
|
+
divergenceState.takeDiagnostics();
|
|
108
|
+
divergenceState.append("[");
|
|
109
|
+
const divergenceDiagnostic = divergenceState.takeDiagnostics();
|
|
110
|
+
assert.equal(divergenceDiagnostic.fallbackReason, "assistant-divergence", "retroactive partial-todo hiding should use an observable conservative fallback");
|
|
111
|
+
assert.equal(divergenceDiagnostic.shadowMismatch, false);
|
|
112
|
+
assertCurrent(divergenceState, "- [", {}, "fallback output should remain authoritative");
|
|
113
|
+
|
|
114
|
+
const modeState = createStreamDerivedOutputState({ todoProgressDetected: false });
|
|
115
|
+
modeState.append("- [ ] visible while todo transport is absent");
|
|
116
|
+
modeState.takeDiagnostics();
|
|
117
|
+
modeState.setTodoProgressDetected(true);
|
|
118
|
+
assert.equal(modeState.value().finalText, "");
|
|
119
|
+
assert.equal(modeState.takeDiagnostics().fallbackReason, "todo-mode-change", "todo capability changes should force an observable rebuild");
|
|
120
|
+
|
|
121
|
+
console.log("stream-derived-output.test.mjs passed");
|