@firstpick/pi-package-webui 0.9.1 → 0.9.3

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 (107) hide show
  1. package/README.md +31 -9
  2. package/bin/pi-webui-launcher.mjs +23 -12
  3. package/bin/pi-webui.mjs +729 -93
  4. package/index.ts +266 -1
  5. package/lib/agent-run-adapters.mjs +500 -0
  6. package/lib/agent-run-protocol.mjs +262 -0
  7. package/lib/agent-run-registry.mjs +339 -0
  8. package/lib/git-workflow-preferences.mjs +18 -28
  9. package/lib/intercom-conversations.mjs +491 -0
  10. package/lib/intercom-transcript-filter.mjs +99 -0
  11. package/lib/resource-selection.mjs +140 -0
  12. package/lib/trust-boundaries.mjs +2 -0
  13. package/lib/ui-layout-settings.mjs +172 -28
  14. package/lib/update/package-layout.mjs +50 -0
  15. package/lib/update/plan.mjs +11 -0
  16. package/package.json +2 -2
  17. package/public/app.js +2276 -419
  18. package/public/index.html +142 -72
  19. package/public/service-worker.js +2 -1
  20. package/public/stream-output-controller.mjs +15 -0
  21. package/public/styles.css +764 -92
  22. package/public/syntax-highlight.mjs +622 -0
  23. package/tests/agent-run-adapters.test.mjs +217 -0
  24. package/tests/agent-run-launcher.test.mjs +41 -0
  25. package/tests/agent-run-protocol.test.mjs +82 -0
  26. package/tests/agent-run-registry.test.mjs +102 -0
  27. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  28. package/tests/browser/control-deck-side-panels.spec.mjs +354 -0
  29. package/tests/browser/controls-layout.spec.mjs +122 -0
  30. package/tests/browser/file-tree-git-ignored.spec.mjs +113 -0
  31. package/tests/browser/interaction-continuity.spec.mjs +161 -0
  32. package/tests/browser/intercom-conversation-viewer.spec.mjs +355 -0
  33. package/tests/browser/mobile-foundation.spec.mjs +26 -0
  34. package/tests/browser/model-search-focus.spec.mjs +96 -0
  35. package/tests/browser/optimistic-prompt.spec.mjs +22 -0
  36. package/tests/browser/persistent-ui-layout.spec.mjs +285 -66
  37. package/tests/browser/resource-profiles.spec.mjs +200 -0
  38. package/tests/browser/subagent-observability.spec.mjs +116 -0
  39. package/tests/codex-fast-mode-static.test.mjs +7 -6
  40. package/tests/common-options-submenus-interaction-static.test.mjs +2 -0
  41. package/tests/common-options-submenus-markup-static.test.mjs +1 -0
  42. package/tests/component-update-api-static.test.mjs +2 -1
  43. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  44. package/tests/composer-skill-tag-layout.test.mjs +32 -2
  45. package/tests/control-deck-component-updates-static.test.mjs +6 -0
  46. package/tests/control-deck-side-panels-static.test.mjs +68 -0
  47. package/tests/controls-layout-static.test.mjs +22 -0
  48. package/tests/fast-mode-client-static.test.mjs +2 -2
  49. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  50. package/tests/feature-system-prompt-optional-feature-static.test.mjs +5 -5
  51. package/tests/file-tree-git-ignored-static.test.mjs +152 -0
  52. package/tests/file-tree-search-layout-static.test.mjs +2 -1
  53. package/tests/file-viewer-image-static.test.mjs +69 -0
  54. package/tests/fixtures/fake-pi.mjs +147 -12
  55. package/tests/foreground-transcript-catch-up-static.test.mjs +1 -1
  56. package/tests/git-panel-file-preview-static.test.mjs +5 -5
  57. package/tests/git-panel-live-updates-static.test.mjs +3 -3
  58. package/tests/git-workflow-preferences.test.mjs +55 -6
  59. package/tests/http-endpoints-harness.test.mjs +295 -14
  60. package/tests/intercom-conversation-viewer-static.test.mjs +105 -0
  61. package/tests/intercom-conversations-http.test.mjs +252 -0
  62. package/tests/intercom-conversations.test.mjs +374 -0
  63. package/tests/intercom-main-transcript-suppression-static.test.mjs +52 -0
  64. package/tests/intercom-tag-layout-static.test.mjs +46 -0
  65. package/tests/intercom-transcript-filter.test.mjs +98 -0
  66. package/tests/main-output-loading-static.test.mjs +59 -0
  67. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  68. package/tests/mobile-compact-layout.test.mjs +2 -3
  69. package/tests/mobile-continuity-tablet-static.test.mjs +6 -6
  70. package/tests/mobile-foundation-static.test.mjs +3 -3
  71. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  72. package/tests/mobile-static.test.mjs +76 -42
  73. package/tests/native-parity.test.mjs +8 -7
  74. package/tests/open-issue-wizard-static.test.mjs +2 -2
  75. package/tests/optional-feature-migration-frontend.test.mjs +5 -5
  76. package/tests/optional-feature-resource-setup-static.test.mjs +29 -0
  77. package/tests/persistent-ui-layout-static.test.mjs +13 -13
  78. package/tests/questionnaire-dialog.test.mjs +3 -3
  79. package/tests/remote-auth-settings-harness.test.mjs +1 -1
  80. package/tests/resource-defaults-helper.test.mjs +60 -6
  81. package/tests/resource-selection.test.mjs +114 -0
  82. package/tests/resource-tui-extension.test.mjs +23 -0
  83. package/tests/session-sampling-ui-static.test.mjs +3 -3
  84. package/tests/side-panel-context-menu-static.test.mjs +1 -1
  85. package/tests/side-panel-resize-static.test.mjs +26 -16
  86. package/tests/side-panel-section-height-removal-static.test.mjs +4 -4
  87. package/tests/side-panel-section-reorder-static.test.mjs +16 -70
  88. package/tests/stream-output-controller.test.mjs +8 -0
  89. package/tests/stream-output-isolation-static.test.mjs +2 -2
  90. package/tests/streaming-ui-coupling.test.mjs +5 -0
  91. package/tests/subagent-gate-visibility.test.mjs +2 -1
  92. package/tests/subagent-launch-slots.test.mjs +1 -1
  93. package/tests/subagent-observability-static.test.mjs +32 -0
  94. package/tests/subagent-reliability-integration.test.mjs +183 -0
  95. package/tests/subagent-workflow-section-static.test.mjs +67 -0
  96. package/tests/subagents-helper.test.mjs +548 -5
  97. package/tests/syntax-highlight.test.mjs +235 -0
  98. package/tests/syntax-highlighting-static.test.mjs +84 -0
  99. package/tests/terminal-tabs-resize-static.test.mjs +35 -0
  100. package/tests/theme-customizer-static.test.mjs +5 -5
  101. package/tests/thinking-format-parser.test.mjs +64 -0
  102. package/tests/ui-layout-settings.test.mjs +104 -32
  103. package/tests/update-api-harness.test.mjs +24 -10
  104. package/tests/update-package-layout.test.mjs +38 -0
  105. package/tests/update-plan.test.mjs +11 -1
  106. package/tests/webui-settings-locking.test.mjs +33 -3
  107. package/webui-rpc-helper.mjs +700 -89
@@ -0,0 +1,235 @@
1
+ import assert from "node:assert/strict";
2
+ import {
3
+ MAX_SYNTAX_HIGHLIGHT_CHARACTERS,
4
+ MAX_SYNTAX_HIGHLIGHT_LINES,
5
+ SUPPORTED_SYNTAX_LANGUAGES,
6
+ SYNTAX_LANGUAGE_ALIASES,
7
+ normalizeSyntaxLanguage,
8
+ tokenizeCode,
9
+ } from "../public/syntax-highlight.mjs";
10
+
11
+ const TOKEN_TYPES = new Set([
12
+ "plain",
13
+ "comment",
14
+ "keyword",
15
+ "function",
16
+ "variable",
17
+ "string",
18
+ "number",
19
+ "type",
20
+ "operator",
21
+ "punctuation",
22
+ ]);
23
+
24
+ function assertRoundTrip(language, source, message = language) {
25
+ const tokens = tokenizeCode(source, language);
26
+ assert.equal(tokens.map(({ text }) => text).join(""), source, `${message} should preserve source exactly`);
27
+ for (const token of tokens) {
28
+ assert.ok(TOKEN_TYPES.has(token.type), `${message} emitted unsupported token type ${token.type}`);
29
+ assert.equal(typeof token.text, "string", `${message} token text should be a string`);
30
+ assert.notEqual(token.text, "", `${message} should not emit empty tokens`);
31
+ assert.deepEqual(Object.keys(token).sort(), ["text", "type"], `${message} tokens should keep the small public shape`);
32
+ }
33
+ return tokens;
34
+ }
35
+
36
+ function tokenText(tokens, type) {
37
+ return tokens.filter((token) => token.type === type).map((token) => token.text).join("");
38
+ }
39
+
40
+ const expectedAliases = {
41
+ python: ["python", "py"],
42
+ javascript: ["javascript", "js", "jsx", "mjs", "cjs", "node"],
43
+ typescript: ["typescript", "ts", "tsx"],
44
+ bash: ["bash", "sh", "shell", "zsh"],
45
+ powershell: ["powershell", "pwsh", "ps1"],
46
+ cmd: ["cmd", "bat", "batch", "dos"],
47
+ json: ["json"],
48
+ jsonc: ["jsonc"],
49
+ ini: ["ini", "cfg", "conf", "properties"],
50
+ toml: ["toml"],
51
+ yaml: ["yaml", "yml"],
52
+ diff: ["diff", "patch"],
53
+ sql: ["sql"],
54
+ css: ["css"],
55
+ html: ["html", "htm"],
56
+ xml: ["xml", "svg"],
57
+ dockerfile: ["dockerfile", "docker"],
58
+ c: ["c", "h"],
59
+ cpp: ["cpp", "c++", "cc", "cxx", "hpp", "hxx"],
60
+ java: ["java"],
61
+ go: ["go", "golang"],
62
+ rust: ["rust", "rs"],
63
+ csharp: ["csharp", "cs", "c#", "dotnet"],
64
+ };
65
+
66
+ assert.deepEqual(new Set(SUPPORTED_SYNTAX_LANGUAGES), new Set(Object.keys(expectedAliases)), "supported languages should expose every canonical profile exactly once");
67
+ for (const [canonical, aliases] of Object.entries(expectedAliases)) {
68
+ for (const alias of aliases) {
69
+ assert.equal(normalizeSyntaxLanguage(alias), canonical, `${alias} should normalize to ${canonical}`);
70
+ assert.equal(SYNTAX_LANGUAGE_ALIASES[alias], canonical, `${alias} should be present in the exported alias catalog`);
71
+ }
72
+ }
73
+ assert.equal(normalizeSyntaxLanguage(" TSX "), "typescript", "language normalization should trim and ignore case");
74
+ assert.equal(normalizeSyntaxLanguage("unknown-language"), "", "unknown languages should not be guessed");
75
+ for (const inheritedName of ["constructor", "toString", "__proto__"]) {
76
+ assert.equal(normalizeSyntaxLanguage(inheritedName), "", `inherited object key ${inheritedName} must not resolve as a language alias`);
77
+ }
78
+
79
+ const fixtures = [
80
+ {
81
+ language: "python",
82
+ source: "def greet(name: str):\n # keep this\n return f\"Hello, {name}\" + str(42)",
83
+ types: ["keyword", "function", "type", "comment", "string", "number", "punctuation"],
84
+ },
85
+ {
86
+ language: "javascript",
87
+ source: "// browser code\nconst answer = format(`value ${42}`) + 42;",
88
+ types: ["comment", "keyword", "function", "string", "number", "operator", "punctuation"],
89
+ },
90
+ {
91
+ language: "typescript",
92
+ source: "interface User { name: string }\nconst load = async (id: number) => fetch(`/u/${id}`);",
93
+ types: ["keyword", "type", "function", "string", "operator", "punctuation"],
94
+ },
95
+ {
96
+ language: "bash",
97
+ source: "#!/usr/bin/env bash\nif [[ -n $HOME ]]; then echo \"ready\"; fi",
98
+ types: ["comment", "keyword", "variable", "string", "operator", "punctuation"],
99
+ },
100
+ {
101
+ language: "powershell",
102
+ source: "# profile\nparam([string]$Name)\nWrite-Output -InputObject \"Hi $Name\"",
103
+ types: ["comment", "keyword", "type", "variable", "string", "punctuation"],
104
+ },
105
+ {
106
+ language: "cmd",
107
+ source: "REM startup\r\nIF DEFINED USERPROFILE ECHO %USERPROFILE% & ECHO \"ready\"",
108
+ types: ["comment", "keyword", "variable", "string"],
109
+ },
110
+ {
111
+ language: "json",
112
+ source: "{\"enabled\": true, \"retries\": 3, \"value\": null}",
113
+ types: ["variable", "keyword", "number", "punctuation"],
114
+ },
115
+ {
116
+ language: "jsonc",
117
+ source: "{\n // safe comment\n \"path\": \"C:\\\\tmp\",\n \"ok\": false\n}",
118
+ types: ["comment", "variable", "string", "keyword", "punctuation"],
119
+ },
120
+ {
121
+ language: "ini",
122
+ source: "[server]\nhost-name = localhost\n; local only",
123
+ types: ["type", "variable", "operator", "comment", "punctuation"],
124
+ },
125
+ {
126
+ language: "toml",
127
+ source: "[[servers.alpha]]\nenabled = true\nport = 8080 # local",
128
+ types: ["type", "variable", "keyword", "number", "comment", "operator", "punctuation"],
129
+ },
130
+ {
131
+ language: "yaml",
132
+ source: "service-name: api\nenabled: true\nports:\n - 8080 # local",
133
+ types: ["variable", "keyword", "number", "comment", "operator", "punctuation"],
134
+ },
135
+ {
136
+ language: "diff",
137
+ source: "diff --git a/a.js b/a.js\n--- a/a.js\n+++ b/a.js\n@@ -1 +1 @@\n-old\n+new\n",
138
+ types: ["keyword", "type", "comment", "string"],
139
+ },
140
+ {
141
+ language: "sql",
142
+ source: "SELECT COUNT(id) FROM users WHERE created_at > DATE('2025-01-01'); -- bounded",
143
+ types: ["keyword", "function", "type", "string", "comment", "operator", "punctuation"],
144
+ },
145
+ {
146
+ language: "css",
147
+ source: ".card { color: #fff; margin-top: 12px; /* compact */ }",
148
+ types: ["variable", "number", "comment", "punctuation"],
149
+ },
150
+ {
151
+ language: "html",
152
+ source: "<!-- safe -->\n<section class=\"card\" data-id='7'><span>Text</span></section>",
153
+ types: ["comment", "type", "variable", "string", "operator", "punctuation"],
154
+ },
155
+ {
156
+ language: "xml",
157
+ source: "<?xml version=\"1.0\"?><root id=\"a\"><child /></root>",
158
+ types: ["type", "variable", "string", "operator", "punctuation"],
159
+ },
160
+ {
161
+ language: "dockerfile",
162
+ source: "FROM node:22\nARG APP_HOME=/app\nRUN echo $APP_HOME && echo \"ready\" # build path",
163
+ types: ["keyword", "variable", "string", "comment", "operator", "punctuation"],
164
+ },
165
+ {
166
+ language: "c",
167
+ source: "// C\nstatic int add(int a, int b) { return a + b; }",
168
+ types: ["comment", "keyword", "type", "function", "operator", "punctuation"],
169
+ },
170
+ {
171
+ language: "cpp",
172
+ source: "class Box { public: size_t size() const { return 1; } };",
173
+ types: ["keyword", "type", "function", "number", "punctuation"],
174
+ },
175
+ {
176
+ language: "java",
177
+ source: "public class Main { static String greet(String name) { return \"Hi \" + name; } }",
178
+ types: ["keyword", "type", "function", "string", "operator", "punctuation"],
179
+ },
180
+ {
181
+ language: "go",
182
+ source: "package main\nfunc add(a int, b int) int { return a + b }",
183
+ types: ["keyword", "type", "function", "operator", "punctuation"],
184
+ },
185
+ {
186
+ language: "rust",
187
+ source: "pub fn add(a: i32, b: i32) -> i32 { a + b }",
188
+ types: ["keyword", "type", "function", "operator", "punctuation"],
189
+ },
190
+ {
191
+ language: "csharp",
192
+ source: "public static string Greet(string name) => $\"Hi {name}\";",
193
+ types: ["keyword", "type", "string", "operator", "punctuation"],
194
+ },
195
+ ];
196
+
197
+ for (const fixture of fixtures) {
198
+ const tokens = assertRoundTrip(fixture.language, fixture.source);
199
+ for (const type of fixture.types) {
200
+ assert.notEqual(tokenText(tokens, type), "", `${fixture.language} should emit a representative ${type} token`);
201
+ }
202
+ }
203
+
204
+ const malicious = "const payload = \"</code><img src=x onerror=alert(1)>\"; // <script>alert(2)</script>";
205
+ const maliciousTokens = assertRoundTrip("js", malicious, "malicious-looking JavaScript");
206
+ assert.ok(tokenText(maliciousTokens, "string").includes("<img"), "HTML-looking source should remain inert token text for DOM-safe integration");
207
+ assert.ok(tokenText(maliciousTokens, "comment").includes("<script>"), "comment source should remain exact text rather than markup");
208
+
209
+ const unknown = "<b>plain & exact</b>\nconst x = 1;";
210
+ assert.deepEqual(tokenizeCode(unknown, "not-a-language"), [{ type: "plain", text: unknown }], "unknown languages should use one exact plain token");
211
+ assert.deepEqual(tokenizeCode(unknown, ""), [{ type: "plain", text: unknown }], "missing language metadata should use one exact plain token");
212
+ assert.deepEqual(tokenizeCode("", "python"), [], "empty source should not emit empty token objects");
213
+ assert.deepEqual(tokenizeCode(null, "python"), [], "null source should normalize to empty source");
214
+ assert.deepEqual(tokenizeCode(12345, "python"), [{ type: "number", text: "12345" }], "non-string source should normalize to its exact string form");
215
+
216
+ const characterLimit = "if ".repeat(Math.ceil(MAX_SYNTAX_HIGHLIGHT_CHARACTERS / 3)).slice(0, MAX_SYNTAX_HIGHLIGHT_CHARACTERS);
217
+ assert.notDeepEqual(tokenizeCode(characterLimit, "python"), [{ type: "plain", text: characterLimit }], "the exact character limit should remain eligible for highlighting");
218
+ const oversizedCharacters = `${characterLimit}x`;
219
+ assert.deepEqual(tokenizeCode(oversizedCharacters, "python"), [{ type: "plain", text: oversizedCharacters }], "source above the character cap should skip tokenization exactly");
220
+
221
+ const lineLimit = `${"if True:\n".repeat(MAX_SYNTAX_HIGHLIGHT_LINES - 1)}pass`;
222
+ assert.notDeepEqual(tokenizeCode(lineLimit, "python"), [{ type: "plain", text: lineLimit }], "the exact line limit should remain eligible for highlighting");
223
+ const oversizedLines = `${lineLimit}\npass`;
224
+ assert.deepEqual(tokenizeCode(oversizedLines, "python"), [{ type: "plain", text: oversizedLines }], "source above the line cap should skip tokenization exactly");
225
+
226
+ const cmdComment = "REM bounded";
227
+ const nearCapCmdLine = `${" ".repeat(MAX_SYNTAX_HIGHLIGHT_CHARACTERS - cmdComment.length)}${cmdComment}`;
228
+ const nearCapCmdTokens = assertRoundTrip("cmd", nearCapCmdLine, "near-cap indented cmd comment");
229
+ assert.equal(tokenText(nearCapCmdTokens, "comment"), cmdComment, "near-cap cmd input should scan indentation once and recognize the line-leading comment");
230
+
231
+ for (const alias of Object.keys(SYNTAX_LANGUAGE_ALIASES)) {
232
+ assertRoundTrip(alias, "keyword = \"value\" # exact\nnext(42)", `alias ${alias}`);
233
+ }
234
+
235
+ console.log(`syntax-highlight.test.mjs passed (${fixtures.length} language fixtures, ${Object.keys(SYNTAX_LANGUAGE_ALIASES).length} aliases)`);
@@ -0,0 +1,84 @@
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
+ import { SUPPORTED_SYNTAX_LANGUAGES, SYNTAX_LANGUAGE_ALIASES } from "../public/syntax-highlight.mjs";
6
+ import { THEME_TOKEN_GROUPS } from "../public/theme-contract.mjs";
7
+
8
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
9
+ const [app, css, html, serviceWorker, pkg, readme, technical, development] = await Promise.all([
10
+ readFile(join(root, "public", "app.js"), "utf8"),
11
+ readFile(join(root, "public", "styles.css"), "utf8"),
12
+ readFile(join(root, "public", "index.html"), "utf8"),
13
+ readFile(join(root, "public", "service-worker.js"), "utf8"),
14
+ readFile(join(root, "package.json"), "utf8"),
15
+ readFile(join(root, "README.md"), "utf8"),
16
+ readFile(join(root, "TECHNICAL.md"), "utf8"),
17
+ readFile(join(root, "DEVELOPMENT.md"), "utf8"),
18
+ ]);
19
+
20
+ function appFunctionSource(name) {
21
+ const start = app.indexOf(`function ${name}(`);
22
+ assert.notEqual(start, -1, `app.js should define ${name}`);
23
+ const end = app.indexOf("\n}\n", start);
24
+ assert.notEqual(end, -1, `${name} should be a complete declaration`);
25
+ return app.slice(start, end + 3);
26
+ }
27
+
28
+ const SYNTAX_TOKEN_NAMES = THEME_TOKEN_GROUPS.find((group) => group.id === "syntax")?.tokens.map(({ name }) => name) || [];
29
+ assert.equal(SYNTAX_TOKEN_NAMES.length, 9, "the shared theme contract should still expose exactly nine syntax tokens");
30
+
31
+ // --- Renderer wiring: the pure tokenizer owns fenced code text ---
32
+ assert.match(app, /import \{ tokenizeCode \} from "\.\/syntax-highlight\.mjs";/, "the app should import the shared pure tokenizer");
33
+
34
+ const renderTokens = appFunctionSource("appendMarkdownCodeTokens");
35
+ assert.match(renderTokens, /const tokens = tokenizeCode\(source, normalizedMarkdownLanguage\(language\)\)/, "fenced code should tokenize through the normalized Markdown language alias");
36
+ assert.match(renderTokens, /if \(!tokens\.length\) \{\s*codeNode\.textContent = source;\s*return;\s*\}/, "an empty token list should fall back to the exact source text");
37
+ assert.match(renderTokens, /if \(type === "plain"\) codeNode\.append\(document\.createTextNode\(text\)\)/, "plain tokens should render as bare text nodes");
38
+ assert.match(renderTokens, /else codeNode\.append\(make\("span", `syntax-token syntax-\$\{type\}`, text\)\)/, "styled tokens should render as spans whose text is assigned through make()/textContent");
39
+
40
+ const codeBlock = appFunctionSource("appendMarkdownCodeBlock");
41
+ assert.match(codeBlock, /if \(closed && isMermaidLanguage\(language\)\) \{\s*appendMarkdownMermaidBlock\(parent, code\)/, "Mermaid blocks must keep their existing dedicated rendering path");
42
+ assert.match(codeBlock, /appendMarkdownCodeTokens\(codeNode, String\(code \|\| ""\)\.replace\(\/\\n\+\$\/g, ""\), language\)/, "fenced code blocks should render through the tokenizing helper");
43
+ assert.doesNotMatch(codeBlock, /codeNode\.textContent = /, "the fenced-code path should no longer assign source text directly");
44
+ assert.match(codeBlock, /attachMarkdownCodeCopyButton\(wrapper\);/, "copy controls should remain attached to highlighted code blocks");
45
+
46
+ // --- DOM safety: source must never reach an HTML sink ---
47
+ for (const source of [renderTokens, codeBlock]) {
48
+ assert.doesNotMatch(source, /innerHTML|insertAdjacentHTML|outerHTML|document\.write/, "highlighted code must never be injected through an HTML parsing sink");
49
+ }
50
+ assert.doesNotMatch(app, /replaceHtml\([^)]*codeNode/, "code nodes must not be populated through the transcript HTML helper");
51
+
52
+ // --- Theme wiring: every contract syntax token drives one CSS variable ---
53
+ for (const token of SYNTAX_TOKEN_NAMES) {
54
+ const variable = `--syntax-${token.replace(/^syntax/, "").replace(/^[A-Z]/, (character) => character.toLowerCase())}`;
55
+ assert.match(app, new RegExp(`"${variable}": themeColor\\(theme, "${token}",`), `applyTheme should map the ${token} theme token to ${variable}`);
56
+ assert.match(css, new RegExp(`\\.markdown-code \\.${variable.slice(2)} \\{[^}]*var\\(${variable}, var\\(--ctp-[a-z]+\\)\\)`), `styles should color ${variable.slice(2)} from the theme variable with a Catppuccin fallback`);
57
+ }
58
+ assert.match(css, /\.markdown-code \.syntax-token \{\s*color: inherit;/, "the base token class should stay visually neutral");
59
+ assert.match(css, /\.markdown-code \.syntax-comment \{[^}]*font-style: italic;/, "comments should remain distinguishable without relying on color alone");
60
+
61
+ // --- Offline/PWA startup closure and coherent revisions ---
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-v108"/, "adding a startup module should advance the PWA cache identity");
64
+ assert.match(html, /styles\.css\?v=123/, "new token styles should advance the stylesheet revision");
65
+ assert.match(html, /data-app-src="\/app\.js\?v=146"/, "new renderer wiring should advance the app module revision");
66
+ assert.match(pkg, /node --check public\/syntax-highlight\.mjs/, "the package check should syntax-check the startup-critical tokenizer");
67
+
68
+ const appShell = serviceWorker.slice(serviceWorker.indexOf("const APP_SHELL"), serviceWorker.indexOf("];", serviceWorker.indexOf("const APP_SHELL")));
69
+ for (const [, specifier] of app.matchAll(/^import [^"]*"\.\/([a-z0-9-]+\.mjs)";$/gm)) {
70
+ assert.ok(appShell.includes(`"/${specifier}"`), `eagerly imported ${specifier} must stay inside the offline app shell`);
71
+ }
72
+
73
+ // --- Documented language coverage stays truthful ---
74
+ for (const alias of ["python", "js", "ts", "bash", "powershell", "cmd", "json", "ini", "toml", "yaml"]) {
75
+ assert.ok(Object.hasOwn(SYNTAX_LANGUAGE_ALIASES, alias), `the requested ${alias} alias should be supported by the tokenizer`);
76
+ }
77
+ assert.ok(SUPPORTED_SYNTAX_LANGUAGES.includes("diff"), "diff blocks should use the approved low-cost profile");
78
+
79
+ assert.match(readme, /[Ss]yntax highlighting/, "the README should make syntax highlighting visible as a user-facing feature");
80
+ assert.match(technical, /## Code block syntax highlighting[\s\S]*50,000[\s\S]*2,000/, "the technical reference should document the supported languages and the highlighting limits as a top-level feature");
81
+ assert.match(technical, /Syntax Highlighting/, "the technical reference should explain that theme syntax colors drive highlighting");
82
+ assert.match(development, /syntax-highlight\.mjs/, "the development guide should document the tokenizer module for contributors");
83
+
84
+ console.log("syntax-highlighting-static: all assertions passed");
@@ -0,0 +1,35 @@
1
+ import assert from "node:assert/strict";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import test from "node:test";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
8
+ const html = fs.readFileSync(path.join(root, "public/index.html"), "utf8");
9
+ const css = fs.readFileSync(path.join(root, "public/styles.css"), "utf8");
10
+ const app = fs.readFileSync(path.join(root, "public/app.js"), "utf8");
11
+
12
+ test("active desktop terminal rail exposes an accessible resize separator", () => {
13
+ assert.match(html, /id="terminalTabsResizeHandle"[^>]*role="separator"[^>]*aria-orientation="vertical"[^>]*aria-label="Resize terminal sidebar width"[^>]*tabindex="0"/);
14
+ assert.match(css, /--terminal-tabs-sidebar-width:\s*clamp\(13rem, 18vw, 19rem\)/);
15
+ assert.match(css, /body\.terminal-tabs-left \.chat-panel \{[\s\S]*grid-template-columns:\s*minmax\(0, 1fr\) minmax\(13rem, var\(--terminal-tabs-sidebar-width\)\)/);
16
+ assert.match(css, /\.terminal-tabs-resize-handle \{[\s\S]*left:\s*-0\.78rem/);
17
+ });
18
+
19
+ test("terminal rail supports bounded pointer and keyboard resizing", () => {
20
+ assert.match(app, /function terminalTabsSidebarResizeAvailable\(\)[\s\S]*terminalTabsLayout !== "left"[\s\S]*isSidePanelOverlayView\(\)/);
21
+ assert.match(app, /function terminalTabsSidebarMaxWidth\(\)[\s\S]*transcriptMinWidth = 320[\s\S]*panelWidth \* 0\.72/);
22
+ assert.match(app, /function beginTerminalTabsSidebarResize\(event\)[\s\S]*setPointerCapture[\s\S]*pointermove[\s\S]*pointercancel/);
23
+ assert.match(app, /function updateTerminalTabsSidebarResize\(event\)[\s\S]*terminal-tabs-sidebar-start[\s\S]*delta/);
24
+ assert.match(app, /function handleTerminalTabsSidebarResizeKeydown\(event\)[\s\S]*ArrowLeft[\s\S]*ArrowRight[\s\S]*Home[\s\S]*End/);
25
+ assert.match(app, /elements\.terminalTabsResizeHandle\?\.addEventListener\("pointerdown", beginTerminalTabsSidebarResize\);\nelements\.terminalTabsResizeHandle\?\.addEventListener\("keydown", handleTerminalTabsSidebarResizeKeydown\);/);
26
+ });
27
+
28
+ test("terminal rail width is locally cached and durably restored", () => {
29
+ assert.match(app, /const TERMINAL_TABS_SIDEBAR_WIDTH_STORAGE_KEY = "pi-webui-terminal-tabs-sidebar-width"/);
30
+ assert.match(app, /function persistTerminalTabsSidebarWidth\(width\)[\s\S]*localStorage\.setItem\(TERMINAL_TABS_SIDEBAR_WIDTH_STORAGE_KEY[\s\S]*markDurableUiLayoutDirty\("terminalTabs", "sidebarWidth"\)/);
31
+ assert.match(app, /function collectDurableTerminalTabsLayout\(\)[\s\S]*sidebarWidth: readStoredTerminalTabsSidebarWidth\(\)/);
32
+ assert.match(app, /function applyDurableTerminalTabsLayout\(value\)[\s\S]*value\.sidebarWidth[\s\S]*restoreTerminalTabsSidebarWidthPreference\(\)/);
33
+ assert.match(app, /window\.addEventListener\("storage"[\s\S]*TERMINAL_TABS_SIDEBAR_WIDTH_STORAGE_KEY\) restoreTerminalTabsSidebarWidthPreference\(\)/);
34
+ assert.match(app, /restoreFileViewerWidthPreference\(\);\nrestoreTerminalTabsSidebarWidthPreference\(\);/);
35
+ });
@@ -5,13 +5,13 @@ import { fileURLToPath } from "node:url";
5
5
  import { REQUIRED_THEME_TOKENS, THEME_TOKEN_GROUPS } from "../public/theme-contract.mjs";
6
6
 
7
7
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
- const [app, html, css, serviceWorker, pkg, readme] = await Promise.all([
8
+ const [app, html, css, serviceWorker, pkg, technical] = await Promise.all([
9
9
  readFile(join(root, "public", "app.js"), "utf8"),
10
10
  readFile(join(root, "public", "index.html"), "utf8"),
11
11
  readFile(join(root, "public", "styles.css"), "utf8"),
12
12
  readFile(join(root, "public", "service-worker.js"), "utf8"),
13
13
  readFile(join(root, "package.json"), "utf8"),
14
- readFile(join(root, "README.md"), "utf8"),
14
+ readFile(join(root, "TECHNICAL.md"), "utf8"),
15
15
  ]);
16
16
 
17
17
  assert.equal(THEME_TOKEN_GROUPS.length, 7, "customizer contract should expose seven labelled groups");
@@ -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-v84"/, "adding the theme contract to the startup graph should advance the PWA cache identity");
37
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v108"/, "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");
@@ -76,7 +76,7 @@ assert.match(css, /\.extension-dialog\.theme-customizer-dialog \{[\s\S]*inset: 0
76
76
  assert.match(css, /\.theme-token-swatch \{[^}]*width: 44px[^}]*height: 44px/, "visual color targets should remain at least 44px");
77
77
  assert.match(css, /env\(safe-area-inset-bottom\)/, "dialog actions should honor mobile safe-area insets");
78
78
 
79
- assert.match(readme, /### Custom themes[\s\S]*exact 51 required theme tokens[\s\S]*last valid preview[\s\S]*This project[\s\S]*Global themes/, "README should document controls, validation, and both scopes");
80
- assert.match(readme, /does not select the theme or mutate Pi\/browser settings[\s\S]*run `\/reload` or restart Pi/, "README should document non-persistence and truthful TUI activation");
79
+ assert.match(technical, /### Custom themes[\s\S]*exact 51 required theme tokens[\s\S]*last valid preview[\s\S]*This project[\s\S]*Global themes/, "technical reference should document controls, validation, and both scopes");
80
+ assert.match(technical, /does not select the theme or mutate Pi\/browser settings[\s\S]*run `\/reload` or restart Pi/, "technical reference should document non-persistence and truthful TUI activation");
81
81
 
82
82
  console.log("theme-customizer-static: all assertions passed");
@@ -0,0 +1,64 @@
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
+
7
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
+ const app = await readFile(join(root, "public", "app.js"), "utf8");
9
+ const helperStart = app.indexOf("function escapeRegExp(");
10
+ const helperEnd = app.indexOf("\nfunction appendThinkingFormatDisplayMessages(", helperStart);
11
+ assert.ok(helperStart >= 0 && helperEnd > helperStart, "thinking-format helpers should remain independently testable");
12
+
13
+ const context = {
14
+ THINKING_FORMAT_OPEN_TAG_REGEX: /^<think\b[^>]*>/i,
15
+ THINKING_FORMAT_CLOSE_TAG_REGEX: /<\/think\s*>/i,
16
+ CHANNEL_THINKING_FORMAT_OPEN_TAG_REGEX: /^<\|([a-z][\w-]*)>/i,
17
+ };
18
+ vm.runInNewContext(
19
+ `${app.slice(helperStart, helperEnd)}\nthis.splitThinkingFormatText = splitThinkingFormatText;`,
20
+ context,
21
+ { filename: "thinking-format-helpers.js" },
22
+ );
23
+
24
+ function parse(text, options) {
25
+ return JSON.parse(JSON.stringify(context.splitThinkingFormatText(text, options)));
26
+ }
27
+
28
+ assert.deepEqual(parse("<think>reasoning</think>\nfinal answer"), {
29
+ hasThinkingFormat: true,
30
+ thinkingText: "reasoning",
31
+ finalText: "final answer",
32
+ complete: true,
33
+ });
34
+
35
+ const nestedLiteral = "The user mentioned `<think>example</think>` inside the reasoning; keep the rest here.";
36
+ assert.deepEqual(parse(`<think>${nestedLiteral}</think>\nfinal answer`), {
37
+ hasThinkingFormat: true,
38
+ thinkingText: nestedLiteral,
39
+ finalText: "final answer",
40
+ complete: true,
41
+ }, "a balanced literal tag pair must not close the outer thinking block");
42
+
43
+ assert.deepEqual(parse(`<think>${nestedLiteral}`, { streaming: true }), {
44
+ hasThinkingFormat: true,
45
+ thinkingText: nestedLiteral,
46
+ finalText: "",
47
+ complete: false,
48
+ }, "streaming must not expose text after an inner literal close as final output");
49
+
50
+ assert.deepEqual(parse("<think>first</think><think>second</think>\nanswer"), {
51
+ hasThinkingFormat: true,
52
+ thinkingText: "first\n\nsecond",
53
+ finalText: "answer",
54
+ complete: true,
55
+ }, "consecutive outer thinking blocks should remain supported");
56
+
57
+ assert.deepEqual(parse("<|analysis>channel reasoning<analysis|>\nanswer"), {
58
+ hasThinkingFormat: true,
59
+ thinkingText: "channel reasoning",
60
+ finalText: "answer",
61
+ complete: true,
62
+ }, "channel-style thinking delimiters should remain unchanged");
63
+
64
+ console.log("thinking-format-parser.test.mjs passed");