@firstpick/pi-package-webui 0.9.4 → 0.9.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.
- package/README.md +7 -2
- package/bin/pi-webui.mjs +90 -5
- package/lib/optional-feature-catalog.mjs +1 -1
- package/lib/session-actions.mjs +20 -2
- package/lib/ui-layout-settings.mjs +37 -6
- package/package.json +1 -1
- package/public/app.js +2311 -257
- package/public/index.html +82 -55
- 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 +222 -51
- package/public/stream-render-scheduler.mjs +85 -0
- package/public/styles.css +276 -20
- 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-deck-side-panels.spec.mjs +42 -0
- package/tests/browser/control-visibility.spec.mjs +396 -0
- package/tests/browser/mobile-foundation.spec.mjs +28 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +9 -9
- 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/composer-action-grid-reorder-static.test.mjs +8 -7
- package/tests/control-deck-side-panels-static.test.mjs +3 -1
- package/tests/control-visibility-static.test.mjs +294 -0
- package/tests/controls-layout-static.test.mjs +3 -3
- package/tests/cwd-footer-reliability-static.test.mjs +1 -1
- package/tests/fast-mode-client-static.test.mjs +1 -1
- 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 +167 -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 +2 -2
- package/tests/http-endpoints-harness.test.mjs +4 -4
- package/tests/interaction-state-stability-static.test.mjs +3 -1
- package/tests/intercom-conversation-viewer-static.test.mjs +4 -4
- 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 +77 -66
- package/tests/open-issue-wizard-static.test.mjs +2 -2
- package/tests/persistent-ui-layout-static.test.mjs +7 -7
- package/tests/prompt-input-vertical-scroll-static.test.mjs +26 -0
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/runtime-error-visibility.test.mjs +3 -3
- package/tests/session-auth-harness.test.mjs +26 -1
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- 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 +34 -6
- package/tests/stream-output-workloads.test.mjs +276 -0
- package/tests/stream-render-scheduler.test.mjs +115 -0
- package/tests/streaming-ui-coupling.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- 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/tests/ui-layout-settings.test.mjs +54 -7
- package/tests/webui-settings-locking.test.mjs +3 -3
|
@@ -46,7 +46,7 @@ assert.doesNotMatch(botClient, /OPENAI_API_KEY|GITHUB_APP_|PRIVATE_KEY/, "the br
|
|
|
46
46
|
|
|
47
47
|
assert.match(html, /__PI_WEBUI_ISSUE_BOT_CONFIG__[\s\S]*?enabled: false/, "the page must expose only disabled-by-default public runtime configuration");
|
|
48
48
|
assert.match(html, /id="openIssueButton"[\s\S]*?aria-controls="issueWizardDialog"/, "the persistent Control Deck action must target the dialog");
|
|
49
|
-
assert.match(html, /<footer class="side-panel-footer" data-control-deck-shared-footer>[\s\S]*?id="openIssueButton"/, "the singleton action must stay outside scrolling Control Deck content while rehosting with the active shell");
|
|
49
|
+
assert.match(html, /<footer class="side-panel-footer" data-control-deck-shared-footer data-visibility-region="control-deck">[\s\S]*?id="openIssueButton"/, "the singleton action must stay outside scrolling Control Deck content while rehosting with the active shell");
|
|
50
50
|
assert.match(html, /<dialog id="issueWizardDialog"[\s\S]*?aria-labelledby="issueWizardTitle"[\s\S]*?aria-describedby="issueWizardDescription"/, "the dialog must have an accessible name and description");
|
|
51
51
|
for (const step of [1, 2, 3, 4, 5]) assert.match(html, new RegExp(`data-issue-wizard-page="${step}"`), `step ${step} markup must exist`);
|
|
52
52
|
assert.match(html, /id="issueWizardStatus"[^>]*role="status"[^>]*aria-live="polite"/, "wizard progress must retain its accessible live region");
|
|
@@ -68,7 +68,7 @@ assert.match(server, /STATIC_PUBLIC_FILE_EXTENSIONS[\s\S]*"\.mjs"/, "the server
|
|
|
68
68
|
assert.match(serviceWorker, /"\/issue-wizard-state\.mjs"/, "the PWA shell must keep caching the pure wizard module");
|
|
69
69
|
assert.match(serviceWorker, /"\/issue-bot-client\.mjs"/, "the PWA shell must cache the browser client module");
|
|
70
70
|
// Intent preserved: changing the public startup graph advances the PWA cache identity.
|
|
71
|
-
assert.match(serviceWorker, /pi-webui-pwa-
|
|
71
|
+
assert.match(serviceWorker, /pi-webui-pwa-v123/, "the PWA cache name must change with browser wiring updates");
|
|
72
72
|
assert.match(packageJson, /node --check public\/issue-wizard-state\.mjs/, "the package check must keep syntax-checking the pure wizard module");
|
|
73
73
|
assert.match(packageJson, /node --check public\/issue-bot-client\.mjs/, "the package check must syntax-check the browser client module");
|
|
74
74
|
|
|
@@ -14,12 +14,12 @@ const [html, app, serviceWorker] = await Promise.all([
|
|
|
14
14
|
|
|
15
15
|
assert.match(
|
|
16
16
|
app,
|
|
17
|
-
/const UI_LAYOUT_SCHEMA_VERSION =
|
|
18
|
-
"the browser controller should target the accepted version-
|
|
17
|
+
/const UI_LAYOUT_SCHEMA_VERSION = 3;[\s\S]*const UI_LAYOUT_ENDPOINT = "\/api\/interface-preferences";/,
|
|
18
|
+
"the browser controller should target the accepted version-3 layout schema on the existing interface-preferences endpoint",
|
|
19
19
|
);
|
|
20
20
|
assert.match(
|
|
21
21
|
app,
|
|
22
|
-
/const UI_LAYOUT_FIELDS = \["sidePanel", "composerActions", "footerScopedModelOrder", "terminalTabs", "fileViewerWidth"\];/,
|
|
22
|
+
/const UI_LAYOUT_FIELDS = \["sidePanel", "composerActions", "controlVisibility", "footerScopedModelOrder", "terminalTabs", "fileViewerWidth"\];/,
|
|
23
23
|
"every approved arrangement surface should be a durable layout field",
|
|
24
24
|
);
|
|
25
25
|
assert.match(
|
|
@@ -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-v123"/, "changed browser assets should advance the PWA cache identity");
|
|
275
|
+
assert.match(html, /styles\.css\?v=132/, "the page should request the updated layout stylesheet revision");
|
|
276
|
+
assert.match(html, /data-app-src="\/app\.js\?v=157"/, "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=132/, "the page should request the scroll-enabled stylesheet revision");
|
|
23
|
+
assert.match(html, /app\.js\?v=157/, "the page should request the scroll-enabled app revision");
|
|
24
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "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=132/, "questionnaire CSS needs the current stylesheet revision");
|
|
508
|
+
assert.match(html, /app\.js\?v=157/, "questionnaire behavior needs the current app revision");
|
|
509
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "questionnaire public assets need a coherent PWA cache revision");
|
|
510
510
|
|
|
511
511
|
console.log("questionnaire-dialog.test.mjs passed");
|
|
@@ -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-v123"/, "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=132/, "the changed stylesheet should have a new revision");
|
|
63
|
+
assert.match(html, /app\.js\?v=157/, "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=
|
|
31
|
-
assert.match(html, /app\.js\?v=
|
|
32
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
30
|
+
assert.match(html, /styles\.css\?v=132/, "removing section resize styles should advance the stylesheet revision");
|
|
31
|
+
assert.match(html, /app\.js\?v=157/, "removing section resize behavior should advance the app revision");
|
|
32
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "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");
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import {
|
|
3
|
+
STREAMING_MARKDOWN_PLAIN_TAIL_LIMIT,
|
|
4
|
+
advanceStreamingMarkdownTail,
|
|
5
|
+
} from "../public/stream-markdown-tail.mjs";
|
|
6
|
+
|
|
7
|
+
function append(state, text, options = {}) {
|
|
8
|
+
return advanceStreamingMarkdownTail(state, text, { appendOnly: !!state, ...options });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function referenceTail(text, plainTailLimit = STREAMING_MARKDOWN_PLAIN_TAIL_LIMIT) {
|
|
12
|
+
const value = String(text || "");
|
|
13
|
+
const lines = value.split("\n");
|
|
14
|
+
// CommonMark: an opening fence is 3+ backticks (optionally followed by an info string); the
|
|
15
|
+
// closing fence must have at least as many backticks and nothing but whitespace after them.
|
|
16
|
+
let inFence = false;
|
|
17
|
+
let fenceTicks = 0;
|
|
18
|
+
let boundary = 0;
|
|
19
|
+
let offset = 0;
|
|
20
|
+
let fenceContentOffset = -1;
|
|
21
|
+
let fenceLanguage = "";
|
|
22
|
+
const closingFence = (line) => {
|
|
23
|
+
const match = line.match(/^\s*(`{3,})\s*$/);
|
|
24
|
+
return Boolean(match && match[1].length >= fenceTicks);
|
|
25
|
+
};
|
|
26
|
+
const openingFence = (line) => {
|
|
27
|
+
const match = line.match(/^\s*(`{3,})\s*([\w.+-]*)\s*$/);
|
|
28
|
+
return match ? { ticks: match[1].length, language: match[2] || "" } : null;
|
|
29
|
+
};
|
|
30
|
+
for (let index = 0; index < lines.length - 1; index += 1) {
|
|
31
|
+
const line = lines[index];
|
|
32
|
+
if (inFence) {
|
|
33
|
+
if (closingFence(line)) {
|
|
34
|
+
inFence = false;
|
|
35
|
+
fenceTicks = 0;
|
|
36
|
+
fenceContentOffset = -1;
|
|
37
|
+
fenceLanguage = "";
|
|
38
|
+
boundary = offset + line.length + 1;
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
const opening = openingFence(line);
|
|
42
|
+
if (opening) {
|
|
43
|
+
inFence = true;
|
|
44
|
+
fenceTicks = opening.ticks;
|
|
45
|
+
fenceContentOffset = offset + line.length + 1;
|
|
46
|
+
fenceLanguage = opening.language;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
offset += line.length + 1;
|
|
50
|
+
if (!inFence && !line.trim()) boundary = offset;
|
|
51
|
+
}
|
|
52
|
+
const pendingRaw = lines.at(-1) || "";
|
|
53
|
+
const pending = pendingRaw.endsWith("\r") ? pendingRaw.slice(0, -1) : pendingRaw;
|
|
54
|
+
const pendingOpening = !inFence ? openingFence(pending) : null;
|
|
55
|
+
const pendingClose = inFence && closingFence(pending);
|
|
56
|
+
if (pendingClose) return { boundary, liveMode: "authoritative", tailKind: "closed-fence", fenceContentOffset, fenceLanguage };
|
|
57
|
+
if (inFence) return { boundary, liveMode: "open-fence", tailKind: "open-fence", fenceContentOffset, fenceLanguage };
|
|
58
|
+
if (pendingOpening) return { boundary, liveMode: "open-fence", tailKind: "open-fence", fenceContentOffset: value.length, fenceLanguage: pendingOpening.language };
|
|
59
|
+
if (value.length - boundary > plainTailLimit) return { boundary, liveMode: "plain", tailKind: "long-text", fenceContentOffset, fenceLanguage };
|
|
60
|
+
return { boundary, liveMode: "markdown", tailKind: "text", fenceContentOffset, fenceLanguage };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for (const sample of [
|
|
64
|
+
"paragraph without a newline",
|
|
65
|
+
"alpha\r\n\r\n ``` ts \r\nconst value = `x`;\r\n```\r\nafter",
|
|
66
|
+
"```mermaid\nflowchart LR\n```\n",
|
|
67
|
+
"```js\ncode\n```` still code\n```",
|
|
68
|
+
" ``` c++\nline one\nline two\n ``` \r\n",
|
|
69
|
+
]) {
|
|
70
|
+
let state = null;
|
|
71
|
+
for (let end = 1; end <= sample.length; end += 1) {
|
|
72
|
+
const text = sample.slice(0, end);
|
|
73
|
+
const result = append(state, text);
|
|
74
|
+
state = result.state;
|
|
75
|
+
const expected = referenceTail(text);
|
|
76
|
+
assert.deepEqual(
|
|
77
|
+
{
|
|
78
|
+
boundary: result.boundary,
|
|
79
|
+
liveMode: result.liveMode,
|
|
80
|
+
tailKind: result.tailKind,
|
|
81
|
+
fenceContentOffset: result.fenceContentOffset,
|
|
82
|
+
fenceLanguage: result.fenceLanguage,
|
|
83
|
+
},
|
|
84
|
+
expected,
|
|
85
|
+
`incremental line state must match authoritative boundary semantics at split ${end} of ${JSON.stringify(sample)}`,
|
|
86
|
+
);
|
|
87
|
+
assert.equal(result.scannedChars, 1);
|
|
88
|
+
assert.equal(state.scanOffset, text.length);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
{
|
|
93
|
+
let state = null;
|
|
94
|
+
let text = "stable paragraph\n\n";
|
|
95
|
+
let result = append(state, text);
|
|
96
|
+
state = result.state;
|
|
97
|
+
assert.equal(result.boundary, text.length);
|
|
98
|
+
assert.equal(result.scannedChars, text.length);
|
|
99
|
+
|
|
100
|
+
for (const suffix of ["```js", "\n", "const smile = '😀';", "\nconsole.log(smile);"]) {
|
|
101
|
+
text += suffix;
|
|
102
|
+
result = append(state, text);
|
|
103
|
+
state = result.state;
|
|
104
|
+
assert.equal(result.scannedChars, suffix.length, "only the newly appended UTF-16 suffix may be boundary-scanned");
|
|
105
|
+
assert.equal(result.boundary, "stable paragraph\n\n".length, "the committed prefix must not be rescanned or moved inside an open fence");
|
|
106
|
+
assert.equal(result.liveMode, "open-fence");
|
|
107
|
+
assert.equal(result.tailKind, "open-fence");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
text += "\n```";
|
|
111
|
+
result = append(state, text);
|
|
112
|
+
state = result.state;
|
|
113
|
+
assert.equal(result.scannedChars, 4);
|
|
114
|
+
assert.equal(result.liveMode, "authoritative", "a recognized closing delimiter must request one authoritative tail render");
|
|
115
|
+
assert.equal(result.tailKind, "closed-fence");
|
|
116
|
+
|
|
117
|
+
text += "\n";
|
|
118
|
+
result = append(state, text);
|
|
119
|
+
assert.equal(result.scannedChars, 1);
|
|
120
|
+
assert.equal(result.boundary, text.length, "a newline-terminated closed fence becomes a safe committed block checkpoint");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
{
|
|
124
|
+
const prefix = "alpha\n\n";
|
|
125
|
+
let result = append(null, prefix);
|
|
126
|
+
const previous = result.state;
|
|
127
|
+
result = append(previous, `${prefix}beta`);
|
|
128
|
+
assert.equal(result.scannedChars, 4);
|
|
129
|
+
assert.equal(result.fallback, false);
|
|
130
|
+
result = append(result.state, `${prefix}replacement`, { appendOnly: false });
|
|
131
|
+
assert.equal(result.fallback, true, "a divergent snapshot must use the authoritative scanner fallback");
|
|
132
|
+
assert.equal(result.scannedChars, `${prefix}replacement`.length);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
{
|
|
136
|
+
const longTail = "x".repeat(STREAMING_MARKDOWN_PLAIN_TAIL_LIMIT + 1);
|
|
137
|
+
const result = append(null, longTail);
|
|
138
|
+
assert.equal(result.liveMode, "plain", "ambiguous tails above the bound must use the cheap live representation");
|
|
139
|
+
assert.equal(result.tailKind, "long-text");
|
|
140
|
+
const completed = append(result.state, longTail, { complete: true });
|
|
141
|
+
assert.equal(completed.boundary, longTail.length);
|
|
142
|
+
assert.equal(completed.liveMode, "authoritative", "completion must restore authoritative Markdown semantics");
|
|
143
|
+
assert.equal(completed.scannedChars, 0, "completion of an unchanged value does not rescan the committed prefix");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
{
|
|
147
|
+
let state = null;
|
|
148
|
+
let text = "```mermaid\nflowchart LR";
|
|
149
|
+
let result = append(state, text);
|
|
150
|
+
state = result.state;
|
|
151
|
+
assert.equal(result.liveMode, "open-fence", "incomplete Mermaid remains plain live code");
|
|
152
|
+
assert.equal(result.fenceLanguage, "mermaid");
|
|
153
|
+
text += "\n```";
|
|
154
|
+
result = append(state, text);
|
|
155
|
+
assert.equal(result.liveMode, "authoritative", "Mermaid becomes authoritative only after its close delimiter");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
{
|
|
159
|
+
let state = null;
|
|
160
|
+
let text = "";
|
|
161
|
+
let result;
|
|
162
|
+
const length = STREAMING_MARKDOWN_PLAIN_TAIL_LIMIT + 4096;
|
|
163
|
+
for (let index = 0; index < length; index += 1) {
|
|
164
|
+
text += index === length - 1 ? "😀" : "x";
|
|
165
|
+
const suffixLength = index === length - 1 ? 2 : 1;
|
|
166
|
+
result = append(state, text);
|
|
167
|
+
state = result.state;
|
|
168
|
+
assert.equal(result.scannedChars, suffixLength, "a growing no-newline paragraph must examine exactly its new suffix");
|
|
169
|
+
}
|
|
170
|
+
assert.equal(result.liveMode, "plain");
|
|
171
|
+
assert.equal(result.tailKind, "long-text");
|
|
172
|
+
assert.equal(result.boundary, 0);
|
|
173
|
+
assert.equal(state.scanOffset, text.length, "the scan cursor must advance past a known non-fence partial line");
|
|
174
|
+
assert.equal(state.lineStage, "invalid", "a known non-fence line must retain only bounded classification state");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
{
|
|
178
|
+
let state = null;
|
|
179
|
+
let text = "";
|
|
180
|
+
let result;
|
|
181
|
+
for (const suffix of [" ", "`", "`", "`", " ", "j", "s", "\r", "\n"]) {
|
|
182
|
+
text += suffix;
|
|
183
|
+
result = append(state, text);
|
|
184
|
+
state = result.state;
|
|
185
|
+
assert.equal(result.scannedChars, suffix.length, "split opening-fence and CRLF input must scan only each suffix");
|
|
186
|
+
}
|
|
187
|
+
assert.equal(result.liveMode, "open-fence");
|
|
188
|
+
assert.equal(result.fenceLanguage, "js");
|
|
189
|
+
assert.equal(result.fenceContentOffset, text.length);
|
|
190
|
+
|
|
191
|
+
const codeLength = STREAMING_MARKDOWN_PLAIN_TAIL_LIMIT + 2048;
|
|
192
|
+
for (let index = 0; index < codeLength; index += 3) {
|
|
193
|
+
const suffix = "abc".slice(0, Math.min(3, codeLength - index));
|
|
194
|
+
text += suffix;
|
|
195
|
+
result = append(state, text);
|
|
196
|
+
state = result.state;
|
|
197
|
+
assert.equal(result.scannedChars, suffix.length, "a long open-fence code line must scan only its appended chunk");
|
|
198
|
+
assert.equal(result.liveMode, "open-fence");
|
|
199
|
+
assert.equal(result.fenceLanguage, "js");
|
|
200
|
+
assert.equal(state.scanOffset, text.length, "open-fence code scanning must advance past the accumulated partial line");
|
|
201
|
+
}
|
|
202
|
+
assert.equal(state.lineStage, "invalid", "ordinary code content must stop fence-candidate work after its first decisive character");
|
|
203
|
+
|
|
204
|
+
for (const suffix of ["\r", "\n", "`", "`", "`", " ", " ", "\r"]) {
|
|
205
|
+
text += suffix;
|
|
206
|
+
result = append(state, text);
|
|
207
|
+
state = result.state;
|
|
208
|
+
assert.equal(result.scannedChars, suffix.length, "split closing-fence input must scan only each suffix");
|
|
209
|
+
}
|
|
210
|
+
assert.equal(result.liveMode, "authoritative");
|
|
211
|
+
assert.equal(result.tailKind, "closed-fence");
|
|
212
|
+
text += "\n";
|
|
213
|
+
result = append(state, text);
|
|
214
|
+
assert.equal(result.scannedChars, 1);
|
|
215
|
+
assert.equal(result.boundary, text.length);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
console.log("stream-markdown-tail.test.mjs passed");
|