@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.
Files changed (70) hide show
  1. package/README.md +7 -2
  2. package/bin/pi-webui.mjs +90 -5
  3. package/lib/optional-feature-catalog.mjs +1 -1
  4. package/lib/session-actions.mjs +20 -2
  5. package/lib/ui-layout-settings.mjs +37 -6
  6. package/package.json +1 -1
  7. package/public/app.js +2311 -257
  8. package/public/index.html +82 -55
  9. package/public/service-worker.js +4 -1
  10. package/public/stream-derived-output.mjs +799 -0
  11. package/public/stream-markdown-tail.mjs +204 -0
  12. package/public/stream-output-controller.mjs +222 -51
  13. package/public/stream-render-scheduler.mjs +85 -0
  14. package/public/styles.css +276 -20
  15. package/public/transcript-renderer.mjs +73 -24
  16. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  17. package/tests/browser/composer-action-grid-reorder.spec.mjs +114 -31
  18. package/tests/browser/control-deck-side-panels.spec.mjs +42 -0
  19. package/tests/browser/control-visibility.spec.mjs +396 -0
  20. package/tests/browser/mobile-foundation.spec.mjs +28 -0
  21. package/tests/browser/persistent-ui-layout.spec.mjs +9 -9
  22. package/tests/browser/stream-output-isolation.spec.mjs +308 -3
  23. package/tests/browser/user-noticeable-fixes.spec.mjs +204 -0
  24. package/tests/codex-fast-mode-static.test.mjs +2 -2
  25. package/tests/composer-action-grid-reorder-static.test.mjs +8 -7
  26. package/tests/control-deck-side-panels-static.test.mjs +3 -1
  27. package/tests/control-visibility-static.test.mjs +294 -0
  28. package/tests/controls-layout-static.test.mjs +3 -3
  29. package/tests/cwd-footer-reliability-static.test.mjs +1 -1
  30. package/tests/fast-mode-client-static.test.mjs +1 -1
  31. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  32. package/tests/file-viewer-image-static.test.mjs +3 -3
  33. package/tests/fixtures/fake-pi.mjs +57 -10
  34. package/tests/fixtures/streaming-workloads.mjs +167 -0
  35. package/tests/footer-provider-usage-visual-static.test.mjs +15 -0
  36. package/tests/foreground-transcript-catch-up-static.test.mjs +7 -1
  37. package/tests/git-workflow-preferences.test.mjs +2 -2
  38. package/tests/http-endpoints-harness.test.mjs +4 -4
  39. package/tests/interaction-state-stability-static.test.mjs +3 -1
  40. package/tests/intercom-conversation-viewer-static.test.mjs +4 -4
  41. package/tests/intercom-conversations-http.test.mjs +16 -0
  42. package/tests/main-output-loading-static.test.mjs +3 -3
  43. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  44. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  45. package/tests/mobile-foundation-static.test.mjs +3 -3
  46. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  47. package/tests/mobile-static.test.mjs +77 -66
  48. package/tests/open-issue-wizard-static.test.mjs +2 -2
  49. package/tests/persistent-ui-layout-static.test.mjs +7 -7
  50. package/tests/prompt-input-vertical-scroll-static.test.mjs +26 -0
  51. package/tests/questionnaire-dialog.test.mjs +3 -3
  52. package/tests/runtime-error-visibility.test.mjs +3 -3
  53. package/tests/session-auth-harness.test.mjs +26 -1
  54. package/tests/session-sampling-ui-static.test.mjs +3 -3
  55. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  56. package/tests/stream-derived-output.test.mjs +121 -0
  57. package/tests/stream-markdown-tail.test.mjs +218 -0
  58. package/tests/stream-output-controller.test.mjs +119 -4
  59. package/tests/stream-output-isolation-static.test.mjs +34 -6
  60. package/tests/stream-output-workloads.test.mjs +276 -0
  61. package/tests/stream-render-scheduler.test.mjs +115 -0
  62. package/tests/streaming-ui-coupling.test.mjs +1 -1
  63. package/tests/subagent-observability-static.test.mjs +2 -2
  64. package/tests/syntax-highlighting-static.test.mjs +3 -3
  65. package/tests/theme-customizer-static.test.mjs +1 -1
  66. package/tests/thinking-format-parser.test.mjs +15 -0
  67. package/tests/todo-filter-static.test.mjs +148 -0
  68. package/tests/transcript-markdown-tail.test.mjs +137 -0
  69. package/tests/ui-layout-settings.test.mjs +54 -7
  70. package/tests/webui-settings-locking.test.mjs +3 -3
@@ -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=126[\s\S]*app\.js\?v=148/, "browser assets should use the current subagent-observability revisions");
32
- assert.match(worker, /pi-webui-pwa-v112/, "PWA cache identity should advance with subagent widget suppression");
31
+ assert.match(html, /styles\.css\?v=132[\s\S]*app\.js\?v=157/, "browser assets should use the current subagent-observability revisions");
32
+ assert.match(worker, /pi-webui-pwa-v123/, "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-v112"/, "adding a startup module should advance the PWA cache identity");
64
- assert.match(html, /styles\.css\?v=126/, "new token styles should advance the stylesheet revision");
65
- assert.match(html, /data-app-src="\/app\.js\?v=148"/, "new renderer wiring should advance the app module revision");
63
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "adding a startup module should advance the PWA cache identity");
64
+ assert.match(html, /styles\.css\?v=132/, "new token styles should advance the stylesheet revision");
65
+ assert.match(html, /data-app-src="\/app\.js\?v=157"/, "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-v112"/, "adding the theme contract to the startup graph should advance the PWA cache identity");
37
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "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");
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
3
3
  import vm from "node:vm";
4
4
  import { dirname, join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
+ import { splitThinkingFormatTextAuthoritative } from "../public/stream-derived-output.mjs";
6
7
 
7
8
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
9
  const app = await readFile(join(root, "public", "app.js"), "utf8");
@@ -61,4 +62,18 @@ assert.deepEqual(parse("<|analysis>channel reasoning<analysis|>\nanswer"), {
61
62
  complete: true,
62
63
  }, "channel-style thinking delimiters should remain unchanged");
63
64
 
65
+ for (const [text, options] of [
66
+ ["<th", { streaming: true }],
67
+ ["<think>reasoning</thi", { streaming: true }],
68
+ ["<think>first</think><th", { streaming: true }],
69
+ ["<think>first</think><think>second</think>\r\nanswer", { streaming: true }],
70
+ ["<|Analysis>Unicode 😀<ANALYSIS|>\nanswer", { streaming: true }],
71
+ ]) {
72
+ assert.deepEqual(
73
+ parse(text, options),
74
+ JSON.parse(JSON.stringify(splitThinkingFormatTextAuthoritative(text, options))),
75
+ `stream-derived authoritative parsing should stay aligned for ${JSON.stringify(text)}`,
76
+ );
77
+ }
78
+
64
79
  console.log("thinking-format-parser.test.mjs passed");
@@ -0,0 +1,148 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import vm from "node:vm";
4
+ import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { stripTodoProgressLinesAuthoritative } from "../public/stream-derived-output.mjs";
7
+
8
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
9
+ const app = await readFile(join(root, "public", "app.js"), "utf8");
10
+
11
+ // Extract the contiguous region containing textLines and stripTodoProgressLines.
12
+ // textLines is a shared helper; stripTodoProgressLines references it and the
13
+ // todo-progress regex constants. The region ends at the next function boundary.
14
+ const textLinesStart = app.indexOf("\nfunction textLines(");
15
+ assert.ok(textLinesStart >= 0, "textLines helper should exist in app.js");
16
+ const nextFnAfterStrip = app.indexOf("\nfunction parseTodoProgressItemLine(", textLinesStart);
17
+ assert.ok(nextFnAfterStrip > textLinesStart, "parseTodoProgressItemLine should follow stripTodoProgressLines");
18
+ const todoFilterRegion = app.slice(textLinesStart, nextFnAfterStrip);
19
+
20
+ // Also need the regex constants from the module-level scope.
21
+ assert.ok(app.includes("const TODO_PROGRESS_LINE_REGEX = "), "TODO_PROGRESS_LINE_REGEX should be defined");
22
+ assert.ok(app.includes("const TODO_PROGRESS_PARTIAL_LINE_REGEX = "), "TODO_PROGRESS_PARTIAL_LINE_REGEX should be defined");
23
+
24
+ // VM context: provide the regex constants and stub isOptionalFeatureDetected.
25
+ const context = {
26
+ TODO_PROGRESS_LINE_REGEX: /^\s*(?:(?:[-*]|\d+[.)])\s*)?\[(?: |x|X|-)\]\s+.+$/,
27
+ TODO_PROGRESS_PARTIAL_LINE_REGEX: /^\s*(?:(?:[-*]|\d+[.)])\s*)?\[(?: |x|X|-)?\]?\s*.*$/,
28
+ isOptionalFeatureDetected: () => true,
29
+ };
30
+ vm.runInNewContext(
31
+ `${todoFilterRegion}\nthis.stripTodoProgressLines = stripTodoProgressLines;`,
32
+ context,
33
+ { filename: "todo-filter-helpers.js" },
34
+ );
35
+
36
+ function appStrip(text, options) {
37
+ return context.stripTodoProgressLines(text, options);
38
+ }
39
+
40
+ /**
41
+ * Representative cases for todo-progress line filtering equivalence:
42
+ * - todo lines with all markers: [ ], [x], [X], [-]
43
+ * - ordered/unordered/numeric prefixes: * [ ], - [ ], 1. [ ]
44
+ * - partial todo tails with and without trailing newline
45
+ * - fenced code containing todo-like lines
46
+ * - CRLF normalization
47
+ * - blank-line collapsing
48
+ * - Unicode
49
+ * - feature-disabled passthrough
50
+ */
51
+ const representativeCases = [
52
+ // Simple todo lines with all markers
53
+ { text: "- [ ] pending\n- [x] done\n- [-] partial\n- [X] done caps\nfinal", opts: { streaming: true } },
54
+ // Ordered/numeric prefixes
55
+ { text: "Goal: steps\n* [ ] task one\n- [x] task two\n1. [ ] task three\n4) [ ] task four\nfinal", opts: { streaming: true } },
56
+ // Partial todo tails without trailing newline (streaming)
57
+ { text: "Goal: ship\n- [", opts: { streaming: true } },
58
+ // Partial todo tails with trailing newline
59
+ { text: "Goal: ship\n- [\nvisible", opts: { streaming: true } },
60
+ // Partial todo tails with incomplete markers
61
+ { text: "Goal: ship\n- [x", opts: { streaming: true } },
62
+ { text: "Some text\n- [ ] partial item", opts: { streaming: true } },
63
+ { text: "Some text\n- [ ] partial item\n", opts: { streaming: true } },
64
+ // Fenced code containing todo-like lines
65
+ { text: "```md\n- [ ] literal checklist\n```\n- [ ] transport\nAnswer", opts: { streaming: true } },
66
+ // Nested fences and edge cases
67
+ { text: "```\n- [ ] inside\n```` still code\n```\nafter\n- [ ] filtered", opts: { streaming: true } },
68
+ // CRLF
69
+ { text: "Goal: ship\r\n- [ ] first\r\n- [x] second\r\n- [-] third\r\nAnswer", opts: { streaming: true } },
70
+ { text: "Goal: ship\r\n- [ ] first\r\nAnswer\r\n- [x] leftover", opts: { streaming: true } },
71
+ // Blank-line collapsing
72
+ { text: "- [ ] filtered\n\n\n\nvisible\n\n\n- [x] filtered\n\nkeep", opts: { streaming: true } },
73
+ // Unicode
74
+ { text: "😀 live\n- [ ] 隐藏\n- [x] 完成\n🚀 final", opts: { streaming: true } },
75
+ // Unicode with code fence
76
+ { text: "```émoji\n- [ ] literal\n```\n- [ ] transport\nfinal 🌟", opts: { streaming: true } },
77
+ // No todo lines at all (passthrough)
78
+ { text: "Plain assistant output with no derived markers.", opts: { streaming: true } },
79
+ // Empty string
80
+ { text: "", opts: { streaming: true } },
81
+ // Only todo lines
82
+ { text: "- [ ] only todos\n- [x] all filtered", opts: { streaming: true } },
83
+ // Streaming=false (complete output)
84
+ { text: "- [ ] line\nvisible", opts: { streaming: false } },
85
+ // Feature-disabled passthrough (isOptionalFeatureDetected returns false)
86
+ { text: "- [ ] visible when todo feature is absent\n- [x] also visible", opts: { streaming: true, _featureDisabled: true } },
87
+ // Partial incomplete fence
88
+ { text: "```\n- [ ] hidden inside incomplete fence\n", opts: { streaming: true } },
89
+ // Whitespace-prefixed todo lines
90
+ { text: "spaced:\n - [ ] indented\n\t- [x] tabbed\nvisible", opts: { streaming: true } },
91
+ // Consecutive blank-line handling
92
+ { text: "- [ ] filtered\n\nkeep\n\n\n- [x] filtered\nend", opts: { streaming: true } },
93
+ // Single line partial
94
+ { text: "- [ ]", opts: { streaming: true } },
95
+ { text: "- [ ]\n", opts: { streaming: true } },
96
+ ];
97
+
98
+ for (const { text, opts } of representativeCases) {
99
+ const { streaming = false, _featureDisabled = false } = opts || {};
100
+ const appResult = _featureDisabled
101
+ ? (() => {
102
+ // Simulate feature-disabled passthrough without modifying the vm context
103
+ const raw = String(text || "");
104
+ // When isOptionalFeatureDetected returns false, stripTodoProgressLines returns text as-is.
105
+ // Re-create that logic manually since we can't re-run the vm context with a different stub.
106
+ return raw;
107
+ })()
108
+ : appStrip(text, { streaming });
109
+ const authResult = stripTodoProgressLinesAuthoritative(text, { streaming, todoProgressDetected: !_featureDisabled });
110
+
111
+ const label = _featureDisabled
112
+ ? `feature-disabled ${JSON.stringify(text)}`
113
+ : `${JSON.stringify(text)} streaming=${streaming}`;
114
+ assert.deepEqual(appResult, authResult, `app stripTodoProgressLines must match authoritative at ${label}`);
115
+ }
116
+
117
+ // Additional deep-equal checks via vm extraction of a known instance
118
+ // to ensure function bodies produce the exact same string output line by line.
119
+ const targetedCases = [
120
+ ["Goal: ship\r\n- [ ] first\r\n- [x] second\r\nAnswer", { streaming: true }],
121
+ ["Goal: ship\r\n- [ ] first\r\n- [x] second\r\nAnswer", { streaming: false }],
122
+ ["```md\n- [ ] literal\n```\n- [ ] transport\nAnswer", { streaming: true }],
123
+ ["```\n- [ ] one\n```\n- [x] two\nfinal", { streaming: true }],
124
+ ["Alpha\n\n\n- [ ] filtered\n\n\nBeta", { streaming: true }],
125
+ ["😀unicode🌍\n- [ ] hidden\nkeep", { streaming: true }],
126
+ ["", { streaming: true }],
127
+ ["", { streaming: false }],
128
+ ["- [ ]", { streaming: true }],
129
+ ["- [ ] done", { streaming: false }],
130
+ ["- [ ] done\n- [x] all\n- [-] three\nvisible", { streaming: true }],
131
+ // Partial tails without newline
132
+ ["text\n- [", { streaming: true }],
133
+ ["text\n- [x", { streaming: true }],
134
+ ["text\n1. [", { streaming: true }],
135
+ ];
136
+
137
+ for (const [text, opts] of targetedCases) {
138
+ const { streaming = false } = opts || {};
139
+ const appResult = appStrip(text, { streaming });
140
+ const authResult = stripTodoProgressLinesAuthoritative(text, { streaming });
141
+ assert.deepEqual(
142
+ appResult,
143
+ authResult,
144
+ `targeted case should match: ${JSON.stringify(text)} streaming=${streaming}`,
145
+ );
146
+ }
147
+
148
+ console.log("todo-filter-static.test.mjs passed");
@@ -0,0 +1,137 @@
1
+ import assert from "node:assert/strict";
2
+ import { advanceStreamingMarkdownTail } from "../public/stream-markdown-tail.mjs";
3
+ import { createTranscriptRenderer } from "../public/transcript-renderer.mjs";
4
+
5
+ class FakeNode {
6
+ static ELEMENT_NODE = 1;
7
+ static TEXT_NODE = 3;
8
+ constructor(nodeType) {
9
+ this.nodeType = nodeType;
10
+ this.childNodes = [];
11
+ this.parentNode = null;
12
+ this.isConnected = false;
13
+ }
14
+ get firstChild() { return this.childNodes[0] || null; }
15
+ append(...nodes) {
16
+ for (const node of nodes) {
17
+ if (node.nodeType === 11) {
18
+ this.append(...[...node.childNodes]);
19
+ node.childNodes = [];
20
+ continue;
21
+ }
22
+ node.parentNode = this;
23
+ node.isConnected = this.isConnected;
24
+ this.childNodes.push(node);
25
+ }
26
+ }
27
+ remove() {
28
+ if (this.parentNode) this.parentNode.childNodes = this.parentNode.childNodes.filter((node) => node !== this);
29
+ this.parentNode = null;
30
+ this.setConnected(false);
31
+ }
32
+ setConnected(value) {
33
+ this.isConnected = value;
34
+ for (const child of this.childNodes) child.setConnected(value);
35
+ }
36
+ }
37
+
38
+ class FakeText extends FakeNode {
39
+ constructor(data = "") { super(FakeNode.TEXT_NODE); this.data = data; }
40
+ appendData(value) { this.data += value; }
41
+ }
42
+
43
+ class FakeElement extends FakeNode {
44
+ constructor() { super(FakeNode.ELEMENT_NODE); this.dataset = {}; }
45
+ addEventListener() {}
46
+ closest() { return null; }
47
+ matches() { return false; }
48
+ querySelectorAll() { return []; }
49
+ contains(candidate) {
50
+ if (candidate === this) return true;
51
+ return this.childNodes.some((child) => child === candidate || (child.contains?.(candidate) ?? false));
52
+ }
53
+ }
54
+
55
+ class FakeFragment extends FakeNode {
56
+ constructor() { super(11); }
57
+ }
58
+
59
+ globalThis.Node = FakeNode;
60
+ globalThis.document = {
61
+ addEventListener() {},
62
+ createDocumentFragment: () => new FakeFragment(),
63
+ createTextNode: (value) => new FakeText(value),
64
+ createElement: () => new FakeElement(),
65
+ };
66
+ globalThis.window = {
67
+ addEventListener() {},
68
+ getSelection: () => ({ rangeCount: 0, isCollapsed: true }),
69
+ };
70
+
71
+ const chat = new FakeElement();
72
+ chat.setConnected(true);
73
+ const surface = new FakeElement();
74
+ chat.append(surface);
75
+ const renderer = createTranscriptRenderer({ chat });
76
+ let liveCreates = 0;
77
+ let liveAppends = 0;
78
+ let authoritativeRenders = 0;
79
+
80
+ const options = {
81
+ surface,
82
+ messageKey: "live:test",
83
+ kind: "assistant-final",
84
+ stableBoundary: (text, state, advanceOptions) => advanceStreamingMarkdownTail(state, text, advanceOptions),
85
+ renderInto(parent, text) {
86
+ authoritativeRenders += 1;
87
+ const block = new FakeElement();
88
+ block.append(new FakeText(text));
89
+ parent.append(block);
90
+ },
91
+ renderLiveTail(parent, tail) {
92
+ liveCreates += 1;
93
+ const block = new FakeElement();
94
+ block.append(new FakeText(tail));
95
+ parent.append(block);
96
+ },
97
+ appendLiveTail(nodes, previousTail, tail) {
98
+ liveAppends += 1;
99
+ nodes[0].firstChild.appendData(tail.slice(previousTail.length));
100
+ },
101
+ };
102
+
103
+ const first = renderer.reconcileMarkdownSurface({ ...options, text: "```js\none" });
104
+ const mountedTail = surface.firstChild;
105
+ assert.equal(first.liveMode, "open-fence");
106
+ assert.equal(liveCreates, 1);
107
+ assert.equal(authoritativeRenders, 0, "an incomplete fence must not run authoritative Markdown/tokenization");
108
+
109
+ const second = renderer.reconcileMarkdownSurface({ ...options, text: "```js\nonetwo" });
110
+ assert.equal(second.reusedTail, true);
111
+ assert.equal(surface.firstChild, mountedTail, "live open-fence appends must retain the mounted tail node identity");
112
+ assert.equal(liveCreates, 1);
113
+ assert.equal(liveAppends, 1);
114
+ assert.equal(authoritativeRenders, 0);
115
+
116
+ const closedText = "```js\nonetwo\n```";
117
+ renderer.reconcileMarkdownSurface({ ...options, text: closedText });
118
+ assert.equal(authoritativeRenders, 1, "closing the fence must perform one authoritative highlighted render");
119
+ assert.notEqual(surface.firstChild, mountedTail);
120
+ const highlightedTail = surface.firstChild;
121
+
122
+ renderer.reconcileMarkdownSurface({ ...options, text: closedText, complete: true });
123
+ assert.equal(authoritativeRenders, 1, "explicit completion must promote an already authoritative close without highlighting twice");
124
+ assert.equal(surface.firstChild, highlightedTail, "authoritative completion must preserve the completed block identity");
125
+
126
+ const longPlain = "x".repeat(16 * 1024 + 1);
127
+ renderer.reconcileMarkdownSurface({ ...options, text: longPlain });
128
+ assert.equal(surface.firstChild.firstChild.data, longPlain);
129
+ renderer.reconcileMarkdownSurface({ ...options, text: longPlain, complete: true });
130
+ assert.equal(authoritativeRenders, 2, "completion must replace the cheap long-tail representation with authoritative Markdown");
131
+
132
+ const incompleteFence = "```js\nunfinished";
133
+ renderer.reconcileMarkdownSurface({ ...options, text: incompleteFence });
134
+ renderer.reconcileMarkdownSurface({ ...options, text: incompleteFence, complete: true });
135
+ assert.equal(authoritativeRenders, 3, "completion must authoritatively tokenize even an unclosed fence exactly once");
136
+
137
+ console.log("transcript-markdown-tail.test.mjs passed");
@@ -1,6 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import {
3
3
  UI_LAYOUT_LIMITS,
4
+ UI_LAYOUT_VERSION,
4
5
  defaultUiLayout,
5
6
  mergeUiLayout,
6
7
  normalizeUiLayout,
@@ -10,6 +11,8 @@ import {
10
11
 
11
12
  const defaults = defaultUiLayout();
12
13
  assert.deepEqual(normalizeUiLayout(undefined), defaults);
14
+ assert.equal(UI_LAYOUT_VERSION, 3);
15
+ assert.deepEqual(defaults.controlVisibility, { hiddenIds: null });
13
16
  assert.deepEqual(normalizeUiLayout({ version: 99, sidePanel: { placement: "both" } }), defaults, "unknown layout versions must fail soft to nullable defaults");
14
17
 
15
18
  const completeV1 = {
@@ -33,7 +36,7 @@ const completeV1 = {
33
36
  fileViewerWidth: 560.4,
34
37
  };
35
38
  const migrated = normalizeUiLayout(completeV1, { legacySidePanelWidth: 612.4 });
36
- assert.equal(migrated.version, 2);
39
+ assert.equal(migrated.version, 3);
37
40
  assert.equal(migrated.sidePanel.placement, "right", "v1 layouts must migrate to the existing right-side presentation");
38
41
  assert.deepEqual(migrated.sidePanel.sectionLayout, { order: ["files", "controls", "git"], leftSectionIds: [] });
39
42
  assert.deepEqual(migrated.sidePanel.collapsedSectionIds, ["git"]);
@@ -44,6 +47,7 @@ assert.deepEqual(migrated.composerActions, completeV1.composerActions, "composer
44
47
  assert.deepEqual(migrated.footerScopedModelOrder, completeV1.footerScopedModelOrder);
45
48
  assert.deepEqual(migrated.terminalTabs, { ...completeV1.terminalTabs, sidebarWidth: 285 }, "terminal placement, custom groups, and normalized sidebar width must survive migration");
46
49
  assert.equal(migrated.fileViewerWidth, 560);
50
+ assert.deepEqual(migrated.controlVisibility, { hiddenIds: null }, "v1 layouts must migrate to default control visibility");
47
51
 
48
52
  const malformedV1 = normalizeUiLayout({
49
53
  ...completeV1,
@@ -68,7 +72,7 @@ assert.equal(malformedV1.terminalTabs.layout, null);
68
72
  assert.deepEqual(malformedV1.terminalTabs.customGroups, completeV1.terminalTabs.customGroups);
69
73
  assert.equal(malformedV1.fileViewerWidth, null);
70
74
 
71
- const valid = normalizeUiLayout({
75
+ const completeV2 = {
72
76
  version: 2,
73
77
  sidePanel: {
74
78
  placement: "both",
@@ -82,6 +86,20 @@ const valid = normalizeUiLayout({
82
86
  footerScopedModelOrder: completeV1.footerScopedModelOrder,
83
87
  terminalTabs: completeV1.terminalTabs,
84
88
  fileViewerWidth: 560,
89
+ };
90
+ const migratedV2 = normalizeUiLayout(completeV2);
91
+ assert.equal(migratedV2.version, 3);
92
+ assert.deepEqual(migratedV2.controlVisibility, { hiddenIds: null }, "v2 layouts must gain default control visibility");
93
+ assert.deepEqual(migratedV2.sidePanel.sectionLayout, completeV2.sidePanel.sectionLayout, "v2 side-panel state must survive migration");
94
+ assert.deepEqual(migratedV2.composerActions, completeV2.composerActions, "v2 composer state must survive migration");
95
+ assert.deepEqual(migratedV2.footerScopedModelOrder, completeV2.footerScopedModelOrder);
96
+ assert.deepEqual(migratedV2.terminalTabs, { ...completeV2.terminalTabs, sidebarWidth: 285 });
97
+ assert.equal(migratedV2.fileViewerWidth, completeV2.fileViewerWidth);
98
+
99
+ const valid = normalizeUiLayout({
100
+ ...completeV2,
101
+ version: 3,
102
+ controlVisibility: { hiddenIds: ["tag.future-kind", "composer.new", "control-deck.sponsor"] },
85
103
  });
86
104
  assert.equal(valid.sidePanel.placement, "both");
87
105
  assert.deepEqual(valid.sidePanel.sectionLayout.leftSectionIds, ["files", "future-section"], "unknown historical section ids may be retained");
@@ -89,6 +107,11 @@ assert.deepEqual(valid.sidePanel.panelWidths, { left: 420, right: 641 });
89
107
  assert.equal(valid.fileViewerWidth, 560);
90
108
  assert.equal(valid.terminalTabs.layout, "left");
91
109
  assert.equal(valid.terminalTabs.sidebarWidth, 285);
110
+ assert.deepEqual(
111
+ valid.controlVisibility.hiddenIds,
112
+ ["composer.new", "control-deck.sponsor", "tag.future-kind"],
113
+ "visibility ids must normalize deterministically while retaining unknown well-formed future ids",
114
+ );
92
115
 
93
116
  const partiallyMalformed = normalizeUiLayout({
94
117
  ...valid,
@@ -105,15 +128,24 @@ assert.deepEqual(partiallyMalformed.sidePanel.sectionLayout, defaults.sidePanel.
105
128
  assert.deepEqual(partiallyMalformed.sidePanel.collapsedPanels, { left: null, right: true }, "malformed side values must not erase valid siblings on disk");
106
129
  assert.deepEqual(partiallyMalformed.sidePanel.panelWidths, { left: null, right: 700 });
107
130
  assert.deepEqual(partiallyMalformed.composerActions, valid.composerActions, "unrelated valid envelope fields must survive malformed side-panel fields");
131
+ assert.deepEqual(partiallyMalformed.controlVisibility, valid.controlVisibility, "unrelated visibility state must survive malformed side-panel fields");
132
+
133
+ const malformedVisibility = normalizeUiLayout({
134
+ ...valid,
135
+ controlVisibility: { hiddenIds: ["composer.new", "composer.new"] },
136
+ });
137
+ assert.deepEqual(malformedVisibility.controlVisibility, defaults.controlVisibility, "malformed persisted visibility must fail soft without affecting sibling fields");
138
+ assert.deepEqual(malformedVisibility.sidePanel, valid.sidePanel);
108
139
 
109
140
  const merged = mergeUiLayout(valid, {
110
- version: 2,
141
+ version: 3,
111
142
  sidePanel: {
112
143
  placement: "left",
113
144
  collapsedPanels: { right: true },
114
145
  panelWidths: { left: 500.2 },
115
146
  hiddenSectionIds: null,
116
147
  },
148
+ controlVisibility: { hiddenIds: [] },
117
149
  footerScopedModelOrder: [],
118
150
  fileViewerWidth: null,
119
151
  });
@@ -122,6 +154,7 @@ assert.deepEqual(merged.sidePanel.sectionLayout, valid.sidePanel.sectionLayout,
122
154
  assert.deepEqual(merged.sidePanel.collapsedPanels, { left: true, right: true }, "side-specific partial state must preserve its sibling");
123
155
  assert.deepEqual(merged.sidePanel.panelWidths, { left: 500, right: 641 });
124
156
  assert.equal(merged.sidePanel.hiddenSectionIds, null, "explicit null must clear only the named field");
157
+ assert.deepEqual(merged.controlVisibility, { hiddenIds: [] }, "an explicit empty visibility list must preserve show-all state");
125
158
  assert.deepEqual(merged.footerScopedModelOrder, [], "explicit empty arrays are valid resets");
126
159
  assert.equal(merged.fileViewerWidth, null);
127
160
 
@@ -131,10 +164,14 @@ const composerReset = mergeUiLayout(valid, { composerActions: { order: [], grid:
131
164
  assert.deepEqual(composerReset.composerActions, { order: [], grid: null });
132
165
  const terminalReset = mergeUiLayout(valid, { terminalTabs: null });
133
166
  assert.deepEqual(terminalReset.terminalTabs, defaults.terminalTabs);
167
+ const visibilityReset = mergeUiLayout(valid, { controlVisibility: { hiddenIds: null } });
168
+ assert.deepEqual(visibilityReset.controlVisibility, { hiddenIds: null }, "null hiddenIds must restore defaults/no explicit preference");
169
+ const visibilityObjectReset = mergeUiLayout(valid, { controlVisibility: null });
170
+ assert.deepEqual(visibilityObjectReset.controlVisibility, defaults.controlVisibility);
134
171
 
135
172
  assert.throws(() => validateUiLayoutPatch({}), /at least one mutable field/);
136
173
  assert.throws(() => validateUiLayoutPatch({ unknown: true }), /unsupported field/);
137
- assert.throws(() => validateUiLayoutPatch({ version: 1, fileViewerWidth: 500 }), /version must be 2/, "stale v1 writes must be rejected");
174
+ assert.throws(() => validateUiLayoutPatch({ version: 2, fileViewerWidth: 500 }), /version must be 3/, "stale v2 writes must be rejected");
138
175
  assert.throws(() => validateUiLayoutPatch({ composerActions: { order: ["send"] } }), /order and grid together/);
139
176
  assert.throws(() => validateUiLayoutPatch({ sidePanel: { sectionOrder: ["files"] } }), /unsupported field: sectionOrder/);
140
177
  assert.throws(() => validateUiLayoutPatch({ sidePanel: { collapsed: true } }), /unsupported field: collapsed/);
@@ -148,6 +185,11 @@ assert.throws(() => validateUiLayoutPatch({ sidePanel: { panelWidths: { left: UI
148
185
  assert.throws(() => validateUiLayoutPatch({ sidePanel: { panelWidths: { right: UI_LAYOUT_LIMITS.panelWidthMax + 1 } } }), /must be between/);
149
186
  assert.throws(() => validateUiLayoutPatch({ fileViewerWidth: UI_LAYOUT_LIMITS.fileViewerWidthMin - 1 }), /must be between/);
150
187
  assert.throws(() => validateUiLayoutPatch({ terminalTabs: { sidebarWidth: UI_LAYOUT_LIMITS.terminalTabsSidebarWidthMin - 1 } }), /must be between/);
188
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: {} }), /must include hiddenIds/);
189
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: { hiddenIds: "composer.new" } }), /must be an array/);
190
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: { hiddenIds: ["composer.new", "composer.new"] } }), /duplicate/);
191
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: { hiddenIds: [" composer.new"] } }), /trimmed string/);
192
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: { hiddenIds: Array.from({ length: UI_LAYOUT_LIMITS.listItems + 1 }, (_, index) => `future.item-${index}`) } }), /at most/);
151
193
  assert.throws(() => validateUiLayoutPatch({ footerScopedModelOrder: Array(UI_LAYOUT_LIMITS.listItems + 1).fill("model") }), /at most/);
152
194
  assert.throws(() => validateUiLayoutPatch({
153
195
  composerActions: { order: ["a", "b"], grid: { version: 2, columns: 2, positions: { a: 0, b: 0 } } },
@@ -165,13 +207,18 @@ assert.throws(() => validateUiLayoutPatch({
165
207
  }), /only one group/);
166
208
 
167
209
  assert.match(uiLayoutRevision(defaults), /^[a-f0-9]{64}$/);
168
- assert.equal(uiLayoutRevision(defaults), uiLayoutRevision(normalizeUiLayout({ version: 2 })), "equivalent normalized layouts need stable revisions");
210
+ assert.equal(uiLayoutRevision(defaults), uiLayoutRevision(normalizeUiLayout({ version: 3 })), "equivalent normalized layouts need stable revisions");
169
211
  assert.equal(
170
212
  uiLayoutRevision(completeV1),
171
213
  uiLayoutRevision(normalizeUiLayout(completeV1)),
172
- "a migrated v1 envelope and its canonical v2 representation need the same revision",
214
+ "a migrated v1 envelope and its canonical v3 representation need the same revision",
215
+ );
216
+ assert.equal(
217
+ uiLayoutRevision({ ...valid, controlVisibility: { hiddenIds: ["tag.future-kind", "control-deck.sponsor", "composer.new"] } }),
218
+ uiLayoutRevision(valid),
219
+ "equivalent hidden sets must have a stable revision independent of input order",
173
220
  );
174
- assert.notEqual(uiLayoutRevision(valid), uiLayoutRevision(merged), "placement, collapse, and width changes must change the revision");
221
+ assert.notEqual(uiLayoutRevision(valid), uiLayoutRevision(merged), "layout and visibility changes must change the revision");
175
222
  assert.notEqual(
176
223
  uiLayoutRevision(valid),
177
224
  uiLayoutRevision(mergeUiLayout(valid, { sidePanel: { sectionLayout: { order: ["controls", "files", "git", "future-section"], leftSectionIds: ["files"] } } })),
@@ -119,7 +119,7 @@ try {
119
119
  assert.equal(queued.interfacePreferences.sidePanelWidth, 611);
120
120
  assert.equal(queued.gitWorkflow.deliveryMode, "current");
121
121
 
122
- const futureLayout = { version: 3, futureSurface: { order: ["keep-this"] } };
122
+ const futureLayout = { version: 4, futureSurface: { order: ["keep-this"] } };
123
123
  const futureSettings = JSON.parse(await readFile(settingsFile, "utf8"));
124
124
  futureSettings.uiLayout = futureLayout;
125
125
  await writeFile(settingsFile, `${JSON.stringify(futureSettings, null, 2)}\n`, "utf8");
@@ -131,7 +131,7 @@ try {
131
131
  await writeWebuiSettings({
132
132
  interfacePreferences: { sidePanelWidth: 612 },
133
133
  uiLayout: {
134
- version: 2,
134
+ version: 3,
135
135
  sidePanel: {
136
136
  placement: "right",
137
137
  sectionLayout: { order: ["files", "controls", "git"], leftSectionIds: [] },
@@ -154,7 +154,7 @@ try {
154
154
  }), atomicWidthFile);
155
155
  const atomicWidth = JSON.parse(await readFile(atomicWidthFile, "utf8"));
156
156
  assert.equal(atomicWidth.interfacePreferences.sidePanelWidth, 700);
157
- assert.equal(atomicWidth.uiLayout.sidePanel.panelWidths.right, 700, "one locked settings update must atomically persist the v2 right width and legacy mirror");
157
+ assert.equal(atomicWidth.uiLayout.sidePanel.panelWidths.right, 700, "one locked settings update must atomically persist the v3 right width and legacy mirror");
158
158
  assert.equal(atomicWidth.uiLayout.sidePanel.panelWidths.left, 384);
159
159
 
160
160
  const liveLockTarget = path.join(root, "live-lock", "settings.json");