@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
@@ -1,15 +1,15 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { readFile } from "node:fs/promises";
3
3
 
4
- const [catalog, app, readme, manifest] = await Promise.all([
4
+ const [catalog, app, development, manifest] = await Promise.all([
5
5
  readFile(new URL("../lib/optional-feature-catalog.mjs", import.meta.url), "utf8"),
6
6
  readFile(new URL("../public/app.js", import.meta.url), "utf8"),
7
- readFile(new URL("../README.md", import.meta.url), "utf8"),
7
+ readFile(new URL("../DEVELOPMENT.md", import.meta.url), "utf8"),
8
8
  readFile(new URL("../../pi-extension-feature-system-prompt/package.json", import.meta.url), "utf8").then(JSON.parse),
9
9
  ]);
10
10
 
11
11
  assert.equal(manifest.name, "@firstpick/pi-extension-feature-system-prompt");
12
- assert.equal(manifest.version, "0.1.3");
12
+ assert.equal(manifest.version, "0.1.5");
13
13
  assert.match(
14
14
  catalog,
15
15
  /\["featureSystemPrompt", "@firstpick\/pi-extension-feature-system-prompt", "\^0\.1\.3"\]/,
@@ -41,9 +41,9 @@ assert.match(
41
41
  "disabling the optional integration should clear replayed classifier state",
42
42
  );
43
43
  assert.match(
44
- readme,
44
+ development,
45
45
  /`@firstpick\/pi-extension-feature-system-prompt` — feature-request classification and routing/,
46
- "the optional companion list should document the new package",
46
+ "the contributor companion list should document the new package",
47
47
  );
48
48
 
49
49
  console.log("feature-system-prompt optional-feature static tests passed");
@@ -0,0 +1,152 @@
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, css] = await Promise.all([
9
+ readFile(join(root, "public", "app.js"), "utf8"),
10
+ readFile(join(root, "public", "styles.css"), "utf8"),
11
+ ]);
12
+
13
+ function sourceBetween(source, startMarker, endMarker, label) {
14
+ const start = source.indexOf(startMarker);
15
+ const end = source.indexOf(endMarker, start + startMarker.length);
16
+ assert.ok(start >= 0 && end > start, `${label} source should be present`);
17
+ return source.slice(start, end);
18
+ }
19
+
20
+ const ignoreHelpers = sourceBetween(app, "function fileTreeEntryGitIgnored(", "\nfunction fileTreeGitStatusClasses(", "Git-ignore helpers");
21
+ const renderSignature = sourceBetween(app, "function fileTreeEntryRenderSignature(", "\nfunction fileTreeRenderSignature(", "file tree entry render signature");
22
+ const searchEntry = sourceBetween(app, "function appendFileSearchEntry(", "\nasync function revealFileTreeEntry(", "file search entry renderer");
23
+ const treeEntry = sourceBetween(app, "function appendFileTreeEntry(", "\nasync function loadFileTreeDirectory(", "file tree entry renderer");
24
+ const ignoredCss = sourceBetween(css, ".file-tree-node.git-ignored > .file-tree-item {", "\n.file-tree-git-badge {", "Git-ignored row styles");
25
+
26
+ // Renderer source contract: additive payload consumption without disabling or hiding anything.
27
+ for (const [label, source] of [["browse", treeEntry], ["search", searchEntry]]) {
28
+ assert.match(source, /const gitIgnored = fileTreeEntryGitIgnored\(entry\);/, `the ${label} renderer should read the additive Git-ignore decoration from the entry payload`);
29
+ assert.match(source, /\$\{gitIgnored \? " git-ignored" : ""\}/, `the ${label} renderer should add a stable git-ignored node class`);
30
+ assert.match(source, /button\.title = \[path \|\| "\.", fileTreeGitIgnoredTitle\(gitIgnored\), fileTreeGitStatusTitle\(gitStatus\)/, `the ${label} renderer should place ignore context in the row title without replacing Git status context`);
31
+ assert.doesNotMatch(source, /disabled|aria-disabled|hidden|pointer-events/, `the ${label} renderer should never disable or hide ignored rows`);
32
+ }
33
+ assert.match(ignoreHelpers, /function fileTreeGitIgnoredTitle\(gitIgnored = false\) \{\s*return gitIgnored \? "Ignored by Git" : "";/, "ignored rows should carry the plain-language “Ignored by Git” explanation");
34
+ assert.match(renderSignature, /fileTreeEntryGitIgnored\(entry\),/, "entry render identity should include ignored state so live refreshes repaint changed rows");
35
+
36
+ // Render identity: an ignore-only transition must produce a different signature.
37
+ const signatureRuntime = { normalizeFileTreePath: (value) => String(value || "").replace(/^\/+|\/+$/g, "") };
38
+ vm.runInNewContext(`${ignoreHelpers}\n${renderSignature}\nthis.signature = fileTreeEntryRenderSignature;`, signatureRuntime);
39
+ const normalEntry = { name: "build.log", path: "build.log", type: "file", extension: ".log" };
40
+ const ignoredEntry = { ...normalEntry, gitIgnored: true };
41
+ assert.notDeepEqual(signatureRuntime.signature(ignoredEntry), signatureRuntime.signature(normalEntry), "an ignore-only change should invalidate the cached render signature");
42
+ assert.equal(signatureRuntime.signature(ignoredEntry).includes(true), true, "the signature should carry the ignored boolean");
43
+ assert.equal(signatureRuntime.signature(normalEntry).includes(true), false, "ordinary entries should keep a false ignored signature component");
44
+
45
+ function fakeNode(tag, className = "", text = "") {
46
+ return {
47
+ tag,
48
+ className,
49
+ textContent: text,
50
+ title: "",
51
+ children: [],
52
+ attributes: new Map(),
53
+ listeners: {},
54
+ dataset: {},
55
+ style: { setProperty() {} },
56
+ append(...children) { this.children.push(...children); },
57
+ setAttribute(name, value) { this.attributes.set(name, String(value)); },
58
+ addEventListener(name, listener) { this.listeners[name] = listener; },
59
+ };
60
+ }
61
+
62
+ const dragBindings = [];
63
+ const openedFiles = [];
64
+ const contextMenuEntries = [];
65
+ const fileTreeState = {
66
+ expanded: new Set(["ignored-dir"]),
67
+ loading: new Set(),
68
+ selectedPath: "",
69
+ searchQuery: "log",
70
+ entriesByPath: new Map([["ignored-dir", [{ name: "nested.log", path: "ignored-dir/nested.log", type: "file", extension: ".log", gitIgnored: true }]]]),
71
+ gitStatusByPath: new Map(),
72
+ };
73
+ const runtime = {
74
+ fileTreeState,
75
+ normalizeFileTreePath: signatureRuntime.normalizeFileTreePath,
76
+ fileTreeGitStatusForEntry: () => null,
77
+ fileTreeGitStatusClasses: () => "",
78
+ fileTreeGitStatusTitle: () => "",
79
+ fileTreeGitStatusBadge: () => null,
80
+ fileParentPath: (value) => String(value || "").split("/").slice(0, -1).join("/"),
81
+ fileDisplayName: (value) => String(value || "").split("/").pop() || ".",
82
+ make: fakeNode,
83
+ fileTreeExpander: (expanded) => fakeNode("span", "file-tree-expander", expanded ? "▾" : "▸"),
84
+ fileEntryIcon: () => "TXT",
85
+ openFileInViewer: (path) => { openedFiles.push(path); },
86
+ toggleFileTreeDirectory: async () => {},
87
+ addEvent: () => {},
88
+ showFileContextMenu: (event, entry) => { contextMenuEntries.push(entry); },
89
+ bindFileTreeDragAndDrop: (button, item, entry) => { dragBindings.push(entry.path); },
90
+ fileTreeOverflowButton: () => fakeNode("button", "file-tree-overflow-button", "⋯"),
91
+ };
92
+ vm.runInNewContext(`${ignoreHelpers}\n${searchEntry}\n${treeEntry}\nthis.renderSearchEntry = appendFileSearchEntry;\nthis.renderTreeEntry = appendFileTreeEntry;`, runtime);
93
+
94
+ const ignoredFile = { name: "build.log", path: "build.log", type: "file", extension: ".log", gitIgnored: true };
95
+ const ordinaryFile = { name: "index.js", path: "index.js", type: "file", extension: ".js" };
96
+ const ignoredDirectory = { name: "ignored-dir", path: "ignored-dir", type: "directory", directory: true, gitIgnored: true };
97
+
98
+ function renderRow(render, entry, ...rest) {
99
+ const parent = fakeNode("ul");
100
+ render(parent, entry, ...rest);
101
+ const item = parent.children[0];
102
+ return { item, button: item.children[0] };
103
+ }
104
+
105
+ for (const [label, render, extra] of [["browse", runtime.renderTreeEntry, [0]], ["search", runtime.renderSearchEntry, []]]) {
106
+ fileTreeState.selectedPath = "";
107
+ const ignoredRow = renderRow(render, ignoredFile, ...extra);
108
+ const ordinaryRow = renderRow(render, ordinaryFile, ...extra);
109
+ assert.match(ignoredRow.item.className, /(^| )git-ignored( |$)/, `${label} rows should expose a stable ignored class`);
110
+ assert.doesNotMatch(ordinaryRow.item.className, /git-ignored/, `${label} rows without the decoration should stay unmarked`);
111
+ assert.equal(ignoredRow.button.title, "build.log\nIgnored by Git", `${label} rows should explain the ignored state in the row title`);
112
+ assert.equal(ordinaryRow.button.title, "index.js", `${label} rows should keep the plain path title when not ignored`);
113
+ assert.match(ignoredRow.button.className, /file-tree-item/, `${label} ignored rows should keep the normal row button class`);
114
+ assert.equal(ignoredRow.button.attributes.get("role"), "treeitem", `${label} ignored rows should stay tree items`);
115
+ assert.equal(ignoredRow.button.attributes.get("aria-selected"), "false", `${label} ignored rows should keep selection semantics`);
116
+ assert.equal(ignoredRow.button.attributes.has("aria-disabled"), false, `${label} ignored rows should never be marked disabled`);
117
+ assert.equal(ignoredRow.button.attributes.has("hidden"), false, `${label} ignored rows should never be hidden`);
118
+ assert.equal(typeof ignoredRow.button.listeners.click, "function", `${label} ignored rows should keep their activation handler`);
119
+ assert.equal(typeof ignoredRow.button.listeners.contextmenu, "function", `${label} ignored rows should keep their context menu`);
120
+ assert.equal(ignoredRow.item.children.at(-1).className, "file-tree-overflow-button", `${label} ignored rows should keep the overflow action`);
121
+ ignoredRow.button.listeners.click();
122
+ ignoredRow.button.listeners.contextmenu({});
123
+ assert.equal(fileTreeState.selectedPath, "build.log", `${label} ignored rows should still become the selected entry`);
124
+ }
125
+ fileTreeState.selectedPath = "";
126
+ assert.deepEqual(openedFiles, ["build.log", "build.log"], "ignored files should still open in the viewer from both renderers");
127
+ assert.deepEqual(contextMenuEntries, [ignoredFile, ignoredFile], "ignored rows should still reach the file context menu from both renderers");
128
+ assert.deepEqual(dragBindings.filter((path) => path === "build.log").length, 2, "ignored rows should keep drag-and-drop wiring in both renderers");
129
+
130
+ const nestedSearchRow = renderRow(runtime.renderSearchEntry, ignoredDirectory);
131
+ assert.match(nestedSearchRow.item.className, /git-ignored/, "ignored directories should be marked in search results");
132
+ const nestedList = nestedSearchRow.item.children.find((child) => child.className === "file-tree-list");
133
+ assert.ok(nestedList, "expanded ignored directories should still render their children");
134
+ assert.match(nestedList.children[0].className, /git-ignored/, "nested rows inside an ignored directory should be marked from their own payload");
135
+ assert.equal(nestedList.children[0].children[0].title, "ignored-dir/nested.log\nIgnored by Git", "nested ignored rows should carry the same explanation");
136
+
137
+ // Styling contract: explicit muted colors, no resting whole-row opacity, stronger state feedback retained.
138
+ assert.match(ignoredCss, /\.file-tree-node\.git-ignored > \.file-tree-item \{[^}]*color: rgba\(var\(--ctp-overlay-rgb\)[^}]*border-color: rgba\([^}]*background: rgba\(var\(--ctp-crust-rgb\)/, "the resting ignored row should use explicit muted color, border, and background values");
139
+ assert.doesNotMatch(ignoredCss, /opacity:/, "the muted treatment should not rely on whole-row opacity that would hurt readability");
140
+ for (const [label, selector] of [
141
+ ["hover and focus", /\.file-tree-node\.git-ignored > \.file-tree-item:hover,\s*\.file-tree-node\.git-ignored > \.file-tree-item:focus-visible \{[^}]*box-shadow: inset 2px 0 0 var\(--ctp-blue\)/],
142
+ ["selection", /\.file-tree-node\.git-ignored\.selected > \.file-tree-item,\s*\.file-tree-node\.git-ignored > \.file-tree-item\[aria-selected="true"\] \{[^}]*box-shadow: inset 3px 0 0 var\(--ctp-teal\)/],
143
+ ["Git status", /\.file-tree-node\.git-ignored\.git-changed > \.file-tree-item \{[^}]*box-shadow: inset 2px 0 0 var\(--file-tree-git-color\)/],
144
+ ["drag", /\.file-tree-node\.git-ignored\.dragging > \.file-tree-item \{[^}]*cursor: grabbing/],
145
+ ["drop target", /\.file-tree-node\.git-ignored\.drop-target > \.file-tree-item \{[^}]*box-shadow: inset 2px 0 0 var\(--ctp-green\)/],
146
+ ["blocked drop", /\.file-tree-node\.git-ignored\.drop-blocked > \.file-tree-item \{[^}]*box-shadow: inset 2px 0 0 var\(--ctp-red\)/],
147
+ ]) {
148
+ assert.match(ignoredCss, selector, `${label} feedback should still win over the resting muted treatment`);
149
+ }
150
+ assert.match(ignoredCss, /\.file-tree-node\.git-ignored > \.file-tree-item \.file-tree-kind,\s*\.file-tree-node\.git-ignored > \.file-tree-item \.file-tree-search-path \{/, "browse and search metadata should be muted together");
151
+
152
+ console.log("file-tree-git-ignored-static.test.mjs passed");
@@ -18,6 +18,7 @@ function sourceBetween(source, startMarker, endMarker, label) {
18
18
  }
19
19
 
20
20
  const searchEntry = sourceBetween(app, "function appendFileSearchEntry(", "\nasync function revealFileTreeEntry(", "file search entry renderer");
21
+ const ignoreHelpers = sourceBetween(app, "function fileTreeEntryGitIgnored(", "\nfunction fileTreeGitStatusClasses(", "Git-ignore helpers");
21
22
  const revealSearchEntry = sourceBetween(app, "async function revealFileTreeEntry(", "\nfunction appendFileTreeEntry(", "file search reveal behavior");
22
23
  const clearSearch = sourceBetween(app, "function focusVisibleFileTreeSelection(", "\nasync function runFileTreeSearch(", "file search clear behavior");
23
24
  const searchLabelCss = sourceBetween(css, ".file-tree-search-label {", "\n.file-tree-kind {", "file search row styles");
@@ -106,7 +107,7 @@ const runtime = {
106
107
  fileTreeOverflowButton: () => fakeNode("button", "file-tree-overflow-button", "⋯"),
107
108
  appendFileTreeEntry: (parent, child, depth) => { renderedChildren.push({ child, depth }); parent.append(fakeNode("li", "file-tree-node", child.name)); },
108
109
  };
109
- vm.runInNewContext(`${searchEntry}\nthis.renderSearchEntry = appendFileSearchEntry;`, runtime);
110
+ vm.runInNewContext(`${ignoreHelpers}\n${searchEntry}\nthis.renderSearchEntry = appendFileSearchEntry;`, runtime);
110
111
 
111
112
  const directory = { name: "packages", path: "packages", type: "directory", directory: true };
112
113
  const collapsedParent = fakeNode("ul");
@@ -0,0 +1,69 @@
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 vm from "node:vm";
6
+
7
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
+ const [app, css, html, server, readme, technical, development, serviceWorker] = await Promise.all([
9
+ readFile(join(root, "public", "app.js"), "utf8"),
10
+ readFile(join(root, "public", "styles.css"), "utf8"),
11
+ readFile(join(root, "public", "index.html"), "utf8"),
12
+ readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
13
+ readFile(join(root, "README.md"), "utf8"),
14
+ readFile(join(root, "TECHNICAL.md"), "utf8"),
15
+ readFile(join(root, "DEVELOPMENT.md"), "utf8"),
16
+ readFile(join(root, "public", "service-worker.js"), "utf8"),
17
+ ]);
18
+
19
+ function sourceBetween(source, startMarker, endMarker, label) {
20
+ const start = source.indexOf(startMarker);
21
+ const end = source.indexOf(endMarker, start);
22
+ assert.ok(start >= 0 && end > start, `${label} should remain independently inspectable`);
23
+ return source.slice(start, end);
24
+ }
25
+
26
+ const imageHelpers = sourceBetween(app, "const FILE_VIEWER_IMAGE_MIME_TYPES", "\n// Changes mode only exists", "image data helper");
27
+ const modeSource = sourceBetween(app, "function resolveFileViewerMode(", "\nfunction setFileViewerMode(", "image-aware mode resolver");
28
+ const openSource = sourceBetween(app, "async function openFileInViewer(", "\nasync function openAurReviewReportInViewer(", "file open flow");
29
+ const uiSource = sourceBetween(app, "function updateFileViewerUi(", "\nconst FILE_VIEWER_SEARCH_MATCH_LIMIT", "file viewer UI renderer");
30
+
31
+ const helperResults = JSON.parse(vm.runInNewContext(`${imageHelpers}\nJSON.stringify([
32
+ fileViewerImageDataUrl({ mimeType: "image/png", data: "AQ==" }),
33
+ fileViewerImageDataUrl({ mimeType: "image/svg+xml", data: "AQ==" }),
34
+ fileViewerImageDataUrl({ mimeType: "image/png", data: "" }),
35
+ ])`));
36
+ assert.deepEqual(helperResults, ["data:image/png;base64,AQ==", "", ""], "the browser should create data URLs only for supported non-empty raster payloads");
37
+
38
+ const modes = JSON.parse(vm.runInNewContext(`${modeSource}\nJSON.stringify([
39
+ resolveFileViewerMode({ kind: "image", mode: "image" }),
40
+ resolveFileViewerMode({ kind: "image", mode: "preview" }),
41
+ resolveFileViewerMode({ kind: "image", mode: "changes", gitChanges: { category: "unstaged" } }),
42
+ resolveFileViewerMode({ kind: "text", mode: "preview", language: "markdown" }),
43
+ ])`));
44
+ assert.deepEqual(modes, ["image", "image", "changes", "preview"], "supported images should default back to Image mode while preserving Git Changes mode");
45
+
46
+ assert.match(server, /const FILE_VIEWER_IMAGE_MIME_TYPES_BY_EXTENSION = Object\.freeze\(\{[\s\S]*"\.png": "image\/png"[\s\S]*"\.jpe?g": "image\/jpeg"[\s\S]*"\.gif": "image\/gif"[\s\S]*"\.webp": "image\/webp"[\s\S]*"\.avif": "image\/avif"/, "the server should use an explicit raster extension allowlist");
47
+ assert.doesNotMatch(server, /"\.svg": "image\/svg\+xml"/, "active SVG documents should remain outside image-viewer scope");
48
+ assert.match(server, /if \(imageMimeType\) \{\s*return \{ \.\.\.shared, kind: "image", mimeType: imageMimeType, data: buffer\.toString\("base64"\) \};\s*\}/, "the bounded content endpoint should return image bytes without UTF-8 reinterpretation");
49
+ assert.match(server, /resolved\.info\.size > FILE_VIEWER_MAX_BYTES[\s\S]*const buffer = await readFile\(resolved\.targetPath\);[\s\S]*const imageMimeType = fileViewerImageMimeType/, "image reads should stay behind the existing workspace file size limit");
50
+
51
+ assert.match(html, /id="fileViewerImage"[^>]*role="group"[^>]*aria-label="Image preview"[^>]*hidden>[\s\S]*<img id="fileViewerImageElement" alt="" \/>/, "the viewer should expose a labelled, initially hidden image surface");
52
+ assert.match(app, /fileViewerImage: \$\("#fileViewerImage"\)[\s\S]*fileViewerImageElement: \$\("#fileViewerImageElement"\)/, "the image surface should be registered in the frontend element map");
53
+ assert.match(openSource, /const kind = data\.kind === "image" \? "image" : "text";[\s\S]*const imageUrl = kind === "image" \? fileViewerImageDataUrl\(data\) : "";/, "the standard file-open flow should validate image payloads through the allowlisted data URL helper");
54
+ assert.match(openSource, /readOnly: kind === "image",\s*sourceAvailable: kind === "text"/, "images should be read-only and unavailable to the source editor");
55
+ assert.match(uiSource, /elements\.fileViewerImage\.hidden = mode !== "image"/, "the image surface should render only in image mode");
56
+ assert.match(uiSource, /elements\.fileViewerImageElement\.alt = `Preview of \$\{viewer\.name \|\| fileDisplayName\(viewer\.path\)\}`/, "rendered images should receive a useful filename-based alternative label");
57
+ assert.match(app, /if \(!activeFileViewer \|\| activeFileViewer\.kind === "image" \|\| !elements\.fileViewerSearchBar\) return;/, "text search should not open for image previews");
58
+ assert.match(app, /elements\.fileViewerImageElement\.removeAttribute\("src"\);\s*elements\.fileViewerImageElement\.alt = "";/, "closing or replacing a viewer should release stale image source state");
59
+
60
+ assert.match(css, /\.file-viewer-image \{[\s\S]*display: grid;[\s\S]*place-items: center;/, "the image surface should center its preview");
61
+ assert.match(css, /\.file-viewer-image img \{[\s\S]*max-width: 100%;[\s\S]*max-height: 100%;[\s\S]*object-fit: contain;/, "images should fit within the viewer without distortion");
62
+ assert.match(readme, /PNG, JPEG, GIF, WebP, and AVIF/i, "the Files panel guide should list supported image formats");
63
+ assert.match(technical, /supported raster images[\s\S]*2 MiB/i, "the advanced reference should document image support and its size limit");
64
+ assert.match(development, /kind: "image"[\s\S]*base64/i, "the contributor guide should document the image response contract");
65
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v108"/, "changed viewer assets should advance the PWA cache identity");
66
+ assert.match(html, /styles\.css\?v=123/, "changed image styles should advance the stylesheet revision");
67
+ assert.match(html, /app\.js\?v=146/, "changed image rendering should advance the app revision");
68
+
69
+ console.log("file viewer image static tests passed");
@@ -17,6 +17,10 @@
17
17
  // isStreaming=true while a scripted flow runs.
18
18
  // - FAKE_PI_STATS_PROMPT_CONTEXT=1: advertise /stats-webui and publish deterministic
19
19
  // structured or malformed-subsection Prompt/context dashboard payloads.
20
+ // - FAKE_PI_TRANSCRIPT_JSON=<JSON array>: replace only the three baseline get_messages
21
+ // records with an isolated transcript fixture; dynamic/scripted messages still append.
22
+ // - FAKE_PI_INTERCOM_LIVE=1: accept the isolated "fixture modal transport live"
23
+ // prompt and emit a generic Intercom tool stream with visible unrelated output.
20
24
  import { createHash, randomUUID } from "node:crypto";
21
25
  import { createInterface } from "node:readline";
22
26
  import { appendFileSync } from "node:fs";
@@ -88,6 +92,17 @@ const continuityModeEnabled = process.env.FAKE_PI_CONTINUITY_MODE === "1";
88
92
  const largePayloadsEnabled = process.env.FAKE_PI_LARGE_PAYLOADS === "1";
89
93
  const sseFloodEnabled = process.env.FAKE_PI_SSE_FLOOD === "1";
90
94
  const statsPromptContextEnabled = process.env.FAKE_PI_STATS_PROMPT_CONTEXT === "1";
95
+ const intercomLiveEnabled = process.env.FAKE_PI_INTERCOM_LIVE === "1";
96
+ const fakeTranscriptMessages = (() => {
97
+ const source = process.env.FAKE_PI_TRANSCRIPT_JSON;
98
+ if (!source) return null;
99
+ try {
100
+ const parsed = JSON.parse(source);
101
+ return Array.isArray(parsed) && parsed.every((message) => message && typeof message === "object" && !Array.isArray(message)) ? parsed : null;
102
+ } catch {
103
+ return null;
104
+ }
105
+ })();
91
106
  const streamIsolationEnabled = process.env.FAKE_PI_STREAM_ISOLATION === "1";
92
107
  const commandLogFile = process.env.FAKE_PI_LOG_FILE || "";
93
108
  const largeRpcText = "large-rpc-payload:" + "λ".repeat(70_000);
@@ -313,6 +328,56 @@ function runVoiceScriptFlow({ text, chunks, chunkSpacingMs = 60, toolPhase = fal
313
328
  runScriptedSteps(steps);
314
329
  }
315
330
 
331
+ function runIntercomLiveScript() {
332
+ scriptedStreaming = true;
333
+ const toolCallId = "live-intercom-call";
334
+ const normalText = "LIVE NORMAL OUTPUT VISIBLE";
335
+ const toolCall = {
336
+ type: "toolCall",
337
+ id: toolCallId,
338
+ name: "intercom",
339
+ arguments: { action: "send", to: "peer-live", message: "LIVEINTERCOMARGUMENTSECRET" },
340
+ };
341
+ const assistantMessage = { role: "assistant", content: [{ type: "text", text: normalText }, toolCall], timestamp: Date.now() };
342
+ const toolResult = {
343
+ role: "toolResult",
344
+ toolCallId,
345
+ toolName: "intercom",
346
+ content: [{ type: "text", text: "LIVEINTERCOMRESULTSECRET" }],
347
+ isError: false,
348
+ timestamp: Date.now() + 1,
349
+ };
350
+ runScriptedSteps([
351
+ { afterMs: 30, run: () => emitScriptedEvent({ type: "agent_start" }) },
352
+ { afterMs: 30, run: () => emitScriptedEvent({ type: "message_start", message: { role: "assistant" } }) },
353
+ { afterMs: 40, run: () => emitScriptedEvent({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: normalText } }) },
354
+ { afterMs: 40, run: () => emitScriptedEvent({ type: "message_update", assistantMessageEvent: { type: "toolcall_start", contentIndex: 1, name: "intercom", toolCall } }) },
355
+ { afterMs: 30, run: () => emitScriptedEvent({ type: "message_update", assistantMessageEvent: { type: "toolcall_delta", contentIndex: 1, name: "intercom", toolCall, delta: "" } }) },
356
+ { afterMs: 30, run: () => emitScriptedEvent({ type: "message_update", assistantMessageEvent: { type: "toolcall_end", contentIndex: 1, name: "intercom", toolCall } }) },
357
+ { afterMs: 30, run: () => emitScriptedEvent({ type: "tool_execution_start", toolCallId, toolName: "intercom", args: toolCall.arguments }) },
358
+ { afterMs: 40, run: () => emitScriptedEvent({ type: "tool_execution_update", toolCallId, toolName: "intercom", partialResult: { content: toolResult.content } }) },
359
+ { afterMs: 40, run: () => emitScriptedEvent({ type: "tool_execution_end", toolCallId, toolName: "intercom", isError: false, result: { content: toolResult.content } }) },
360
+ { afterMs: 40, run: () => {
361
+ appendDynamicMessage(assistantMessage);
362
+ appendDynamicMessage(toolResult);
363
+ emitScriptedEvent({ type: "message_end", message: assistantMessage });
364
+ } },
365
+ { afterMs: 40, run: () => emitScriptedEvent({ type: "agent_end" }) },
366
+ { afterMs: 10, run: () => {
367
+ scriptedStreaming = false;
368
+ emitScriptedEvent({ type: "agent_settled" });
369
+ } },
370
+ ]);
371
+ }
372
+
373
+ function handleIntercomLivePrompt(command, base) {
374
+ if (!intercomLiveEnabled || String(command.message || "").trim() !== "fixture modal transport live") return false;
375
+ appendDynamicMessage({ role: "user", content: String(command.message), timestamp: Date.now() });
376
+ respond({ ...base, data: { output: "fake live transport accepted", pid: process.pid } });
377
+ runIntercomLiveScript();
378
+ return true;
379
+ }
380
+
316
381
  function runContinuityDelayedStream() {
317
382
  scriptedStreaming = true;
318
383
  const text = "continuity stream complete";
@@ -631,7 +696,8 @@ function handleWebuiHelperPrompt(command, base) {
631
696
  respondHelper({ requestId, ok: true, data: { tools: fakeTools.map((tool) => ({ ...tool, enabled: enabledToolNames.has(tool.name) })) } });
632
697
  return true;
633
698
  case "tools-set": {
634
- if (Array.isArray(request.payload?.enabledTools)) enabledToolNames = new Set(request.payload.enabledTools.map(String));
699
+ if (request.payload?.mode === "inherit") enabledToolNames = new Set(fakeTools.map((tool) => tool.name));
700
+ else if (Array.isArray(request.payload?.enabledTools)) enabledToolNames = new Set(request.payload.enabledTools.map(String));
635
701
  else if (Array.isArray(request.payload?.disabledTools)) {
636
702
  const disabled = new Set(request.payload.disabledTools.map(String));
637
703
  enabledToolNames = new Set(fakeTools.map((tool) => tool.name).filter((name) => !disabled.has(name)));
@@ -642,8 +708,15 @@ function handleWebuiHelperPrompt(command, base) {
642
708
  case "skills-state":
643
709
  respondHelper({ requestId, ok: true, data: { skills: fakeSkills.map((skill) => ({ ...skill, enabled: enabledSkillNames.has(skill.name) })) } });
644
710
  return true;
711
+ case "resources-recompute":
712
+ respondHelper({ requestId, ok: true, data: {
713
+ tools: { tools: fakeTools.map((tool) => ({ ...tool, enabled: enabledToolNames.has(tool.name) })) },
714
+ skills: { skills: fakeSkills.map((skill) => ({ ...skill, enabled: enabledSkillNames.has(skill.name) })) },
715
+ } });
716
+ return true;
645
717
  case "skills-set": {
646
- if (Array.isArray(request.payload?.enabledSkills)) enabledSkillNames = new Set(request.payload.enabledSkills.map(String));
718
+ if (request.payload?.mode === "inherit") enabledSkillNames = new Set(fakeSkills.map((skill) => skill.name));
719
+ else if (Array.isArray(request.payload?.enabledSkills)) enabledSkillNames = new Set(request.payload.enabledSkills.map(String));
647
720
  else if (Array.isArray(request.payload?.disabledSkills)) {
648
721
  const disabled = new Set(request.payload.disabledSkills.map(String));
649
722
  enabledSkillNames = new Set(fakeSkills.map((skill) => skill.name).filter((name) => !disabled.has(name)));
@@ -683,8 +756,11 @@ function handleWebuiHelperPrompt(command, base) {
683
756
  respondHelper({ requestId, ok: true, data: mutateRuntimeQueue(request.payload) });
684
757
  return true;
685
758
  case "subagent-output": {
686
- const run = fixtureSubagentRuns.find((candidate) => candidate.id === request.payload?.runId);
687
- const agent = run?.agents?.find((candidate) => candidate.id === request.payload?.agentId);
759
+ const opaqueSelection = request.payload?.outputId
760
+ ? fixtureSubagentRuns.flatMap((run) => run.agents.map((agent) => ({ run, agent }))).find(({ run, agent }) => `h-${createHash("sha256").update(`${run.id}\0${agent.id}`).digest("hex").slice(0, 32)}` === request.payload.outputId)
761
+ : null;
762
+ const run = opaqueSelection?.run || fixtureSubagentRuns.find((candidate) => candidate.id === request.payload?.runId);
763
+ const agent = opaqueSelection?.agent || run?.agents?.find((candidate) => candidate.id === request.payload?.agentId);
688
764
  if (!run || !agent) {
689
765
  respondHelper({ requestId, ok: false, error: "Subagent output is no longer tracked" });
690
766
  return true;
@@ -1055,23 +1131,56 @@ function handleTransportFixturePrompt(command, base) {
1055
1131
  return false;
1056
1132
  }
1057
1133
 
1058
- function emitSubagentFixtureStatus() {
1134
+ function emitSubagentFixtureStatus({ legacyOnly = false } = {}) {
1135
+ const now = Date.now();
1059
1136
  emitEvent({
1060
1137
  type: "extension_ui_request",
1061
1138
  id: randomUUID(),
1062
1139
  method: "setStatus",
1063
1140
  statusKey: "webui-subagents",
1064
- statusText: `PI_WEBUI_SUBAGENTS_V1 ${JSON.stringify({ version: 1, available: true, updatedAt: Date.now(), runs: fixtureSubagentRuns, gates: fixtureSubagentGates })}`,
1141
+ statusText: `PI_WEBUI_SUBAGENTS_V1 ${JSON.stringify({ version: 1, available: true, updatedAt: now, runs: fixtureSubagentRuns, gates: fixtureSubagentGates })}`,
1142
+ });
1143
+ if (legacyOnly) return;
1144
+ const instances = fixtureSubagentRuns.flatMap((run) => run.agents.map((agent) => {
1145
+ const terminal = agent.status !== "running";
1146
+ const startedAt = run.startedAt;
1147
+ const endedAt = terminal ? run.endedAt || now : null;
1148
+ return {
1149
+ version: 1,
1150
+ instanceId: agent.id,
1151
+ runId: run.id,
1152
+ parentSessionId: "fake-session",
1153
+ launcher: run.source === "workflow" ? "workflow" : "pi-subagents",
1154
+ provider: run.source === "workflow" ? "workflow-run" : "pi-subagents",
1155
+ origin: run.source,
1156
+ name: agent.name,
1157
+ status: agent.status,
1158
+ startedAt,
1159
+ updatedAt: endedAt || now,
1160
+ endedAt,
1161
+ model: agent.model,
1162
+ thinking: agent.thinking,
1163
+ ...(agent.currentTool ? { currentTool: agent.currentTool } : {}),
1164
+ capabilities: { open: true, refresh: true, cancel: !terminal && run.source !== "workflow", steer: false },
1165
+ outputRef: { kind: "helper", id: `h-${createHash("sha256").update(`${run.id}\0${agent.id}`).digest("hex").slice(0, 32)}` },
1166
+ };
1167
+ }));
1168
+ emitEvent({
1169
+ type: "extension_ui_request",
1170
+ id: randomUUID(),
1171
+ method: "setStatus",
1172
+ statusKey: "webui-subagents-v2",
1173
+ statusText: `PI_WEBUI_SUBAGENTS_V2 ${JSON.stringify({ version: 2, available: true, updatedAt: now, instances, gateReferences: [], diagnostics: [] })}`,
1065
1174
  });
1066
1175
  }
1067
1176
 
1068
1177
  function handleSubagentFixturePrompt(command, base) {
1069
1178
  const message = String(command.message || "").trim();
1070
- if (!["fixture subagents running", "fixture subagents clear", "fixture subagents retained"].includes(message)) return false;
1179
+ if (!["fixture subagents running", "fixture subagents old-helper", "fixture subagents workflow", "fixture subagents clear", "fixture subagents retained"].includes(message)) return false;
1071
1180
  const now = Date.now();
1072
1181
  fixtureSubagentRuns.splice(0, fixtureSubagentRuns.length);
1073
1182
  fixtureSubagentGates.splice(0, fixtureSubagentGates.length);
1074
- if (message === "fixture subagents running") {
1183
+ if (message === "fixture subagents running" || message === "fixture subagents old-helper") {
1075
1184
  fixtureSubagentRuns.push({
1076
1185
  id: "fixture-run",
1077
1186
  source: "async",
@@ -1097,6 +1206,29 @@ function handleSubagentFixturePrompt(command, base) {
1097
1206
  { id: "fixture-gate:1:1", taskIndex: 1, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "fixture-review-2", model: "openrouter/moonshotai/kimi-k3", provider: "openrouter", status: "failed", failureKind: "transient-provider", error: "provider overloaded" },
1098
1207
  ],
1099
1208
  });
1209
+ } else if (message === "fixture subagents workflow") {
1210
+ fixtureSubagentRuns.push(
1211
+ {
1212
+ id: "fixture-workflow-controller",
1213
+ source: "recovered",
1214
+ mode: "single",
1215
+ status: "done",
1216
+ startedAt: now - 2500,
1217
+ agents: [
1218
+ { id: "fixture-workflow-controller:workflow", name: "workflow", status: "done", index: 0, nested: false },
1219
+ ],
1220
+ },
1221
+ {
1222
+ id: "fixture-workflow-worker",
1223
+ source: "recovered",
1224
+ mode: "single",
1225
+ status: "running",
1226
+ startedAt: now - 2450,
1227
+ agents: [
1228
+ { id: "fixture-workflow-worker:worker", name: "worker", status: "running", index: 0, model: "openai-codex/gpt-5.6-sol", thinking: "high", nested: false },
1229
+ ],
1230
+ },
1231
+ );
1100
1232
  } else if (message === "fixture subagents retained") {
1101
1233
  fixtureSubagentRuns.push(
1102
1234
  {
@@ -1123,7 +1255,7 @@ function handleSubagentFixturePrompt(command, base) {
1123
1255
  );
1124
1256
  }
1125
1257
  respond({ ...base, data: { output: "fake subagent status emitted" } });
1126
- emitSubagentFixtureStatus();
1258
+ emitSubagentFixtureStatus({ legacyOnly: message === "fixture subagents old-helper" });
1127
1259
  return true;
1128
1260
  }
1129
1261
 
@@ -1374,9 +1506,11 @@ rl.on("line", (line) => {
1374
1506
  ...base,
1375
1507
  data: {
1376
1508
  messages: [
1377
- { role: "user", content: "fake prompt", timestamp: 1000 },
1378
- { role: "assistant", content: [{ type: "text", text: "fake answer" }], timestamp: 2000 },
1379
- { role: "user", content: "fake follow-up", timestamp: 3000 },
1509
+ ...(fakeTranscriptMessages || [
1510
+ { role: "user", content: "fake prompt", timestamp: 1000 },
1511
+ { role: "assistant", content: [{ type: "text", text: "fake answer" }], timestamp: 2000 },
1512
+ { role: "user", content: "fake follow-up", timestamp: 3000 },
1513
+ ]),
1380
1514
  ...dynamicMessages,
1381
1515
  ...(largeTranscriptEnabled ? [{ role: "assistant", content: [{ type: "text", text: largeRpcText }], timestamp: 4000 }] : []),
1382
1516
  ],
@@ -1416,6 +1550,7 @@ rl.on("line", (line) => {
1416
1550
  return;
1417
1551
  }
1418
1552
  case "prompt":
1553
+ if (handleIntercomLivePrompt(command, base)) return;
1419
1554
  if (handleFeatureDecisionFixturePrompt(command, base)) return;
1420
1555
  if (handleStatsPromptContextFixturePrompt(command, base)) return;
1421
1556
  if (handleWebuiHelperPrompt(command, base)) return;
@@ -28,7 +28,7 @@ function functionBody(source, name) {
28
28
  assert.fail(`${name} should close`);
29
29
  }
30
30
 
31
- assert.match(app, /import \{ classifyTranscriptStreamEvent, createStreamOutputController \} from "\.\/stream-output-controller\.mjs";/);
31
+ assert.match(app, /import \{[^}]*classifyTranscriptStreamEvent[^}]*createStreamOutputController[^}]*\} from "\.\/stream-output-controller\.mjs";/);
32
32
  assert.match(app, /let foregroundTranscriptCatchUpRequired = document\.visibilityState === "hidden";/);
33
33
 
34
34
  const beginCatchUp = functionBody(app, "beginForegroundTranscriptCatchUp");
@@ -115,7 +115,7 @@ assert.match(setModeSource, /if \(activeFileViewer\.mode === "changes" && previo
115
115
  assert.match(viewerUiSource, /const hasChanges = !!viewer\.gitChanges;/, "the viewer UI should derive Changes availability from the open-time snapshot");
116
116
  assert.match(viewerUiSource, /elements\.fileViewerChangesModeButton\.hidden = !hasChanges;\s*elements\.fileViewerChangesModeButton\.disabled = !hasChanges;/, "the Changes control should stay hidden and disabled for non-Git opens");
117
117
  assert.match(viewerUiSource, /elements\.fileViewerSourceModeButton\.disabled = !sourceAvailable;/, "Source should be disabled when the live file content is unavailable");
118
- assert.match(viewerUiSource, /elements\.fileViewerPreviewModeButton\.hidden = !isMarkdown;\s*elements\.fileViewerPreviewModeButton\.disabled = !isMarkdown \|\| !sourceAvailable;/, "Markdown Preview should stay hidden for non-Markdown and disabled when live source is unavailable");
118
+ assert.match(viewerUiSource, /elements\.fileViewerPreviewModeButton\.hidden = !isMarkdown && !isImage;\s*elements\.fileViewerPreviewModeButton\.disabled = \(!isMarkdown \|\| !sourceAvailable\) && !isImage;/, "Preview should be available for Markdown and supported images while remaining unavailable for other files");
119
119
  assert.match(viewerUiSource, /elements\.fileViewerEditor\.hidden = mode !== "source";/, "Source editing should remain bound to Source mode");
120
120
  assert.match(
121
121
  viewerUiSource,
@@ -171,10 +171,10 @@ assert.match(openFileSource, /const changesRequestSerial = category \? \+\+fileV
171
171
  assert.match(openFileSource, /const changesRequest = category \? loadGitFileChangesSnapshot\(changesPath, category, tabContext\.tabId\) : null;/, "only category-carrying opens should request a diff");
172
172
  assert.match(openFileSource, /const gitChanges = changesRequest \? gitFileChangesPlaceholder\(category, changesPath, changesRequestSerial\) : null;/, "normal File-section opens should carry no Git snapshot at all");
173
173
  assert.match(openFileSource, /applyGitFileChangesSnapshot\(changesRequest, tabContext, activeFileViewer\.path, changesRequestSerial\)/, "same-path Git requests should apply only through their captured request identity");
174
- assert.match(openFileSource, /mode: gitChanges \? "changes" : data\.language === "markdown" \? "preview" : "source",/, "Git opens should default to Changes while normal opens keep the Markdown/Source default");
174
+ assert.match(openFileSource, /mode: gitChanges \? "changes" : kind === "image" \? "image" : data\.language === "markdown" \? "preview" : "source",/, "Git opens should default to Changes while normal opens keep the Image/Markdown/Source default");
175
175
  assert.match(openFileSource, /if \(!isCurrentTabContext\(tabContext\) \|\| openRequestSerial !== fileViewerOpenRequestSerial\) return;/, "the source-success path should reject stale same-tab viewer opens");
176
176
  assert.match(openFileSource, /const gitChanges = changesRequest \? await changesRequest : null;\s*if \(!isCurrentTabContext\(tabContext\) \|\| openRequestSerial !== fileViewerOpenRequestSerial\) return;/, "the deleted-file fallback should reject stale same-tab viewer opens after awaiting the diff");
177
- assert.match(openFileSource, /readOnly: false,\s*sourceAvailable: true,/, "a live Git-originated file should stay editable");
177
+ assert.match(openFileSource, /readOnly: kind === "image",\s*sourceAvailable: kind === "text",/, "a live Git-originated text file should stay editable while image previews remain read-only");
178
178
  assert.match(
179
179
  openFileSource,
180
180
  /const gitChanges = changesRequest \? await changesRequest : null;\s*if \(!isCurrentTabContext\(tabContext\) \|\| openRequestSerial !== fileViewerOpenRequestSerial\) return;\s*if \(gitChanges && !gitChanges\.error\) \{/,
@@ -195,7 +195,7 @@ assert.match(viewerPersistenceSource, /fileViewersByTab\.set\(tabId, activeFileV
195
195
  assert.match(viewerPersistenceSource, /fileViewerSelectionsByTab\.set\(tabId, fileViewerSelection\)/, "caching a terminal should retain its active file selection");
196
196
  assert.match(viewerPersistenceSource, /activeFileViewer = activeTabId \? fileViewersByTab\.get\(activeTabId\) \|\| null : null;\s*fileViewerSelection = activeTabId \? fileViewerSelectionsByTab\.get\(activeTabId\) \|\| null : null;\s*updateFileViewerUi\(\);/, "activating a terminal should restore its own viewer and selection");
197
197
  assert.match(viewerPersistenceSource, /function closeFileViewer\(\) \{\s*if \(activeTabId\) \{\s*fileViewersByTab\.delete\(activeTabId\);\s*fileViewerSelectionsByTab\.delete\(activeTabId\);/, "explicitly closing a viewer should remove only the active terminal's cached state");
198
- assert.match(switchTabSource, /cacheActiveFileViewerForTab\(activeTabId\);\s*const tabContext = setActiveTabId\(tabId, \{ remember: true \}\);/, "switching terminals should cache the outgoing viewer before changing the active tab identity");
198
+ assert.match(switchTabSource, /cacheActiveFileViewerForTab\(activeTabId\);[\s\S]*?const tabContext = setActiveTabId\(tabId, \{ remember: true \}\);/, "switching terminals should cache the outgoing viewer before changing the active tab identity");
199
199
  assert.match(resetActiveTabUiSource, /resetFileViewerUi\(\);\s*resetFileTreeState\(\);\s*restoreFileViewerForActiveTab\(\);/, "resetting tab UI should restore the incoming terminal's viewer instead of closing it");
200
200
  assert.match(closeTabsSource, /fileViewersByTab\.delete\(id\);\s*fileViewerSelectionsByTab\.delete\(id\);/, "closing terminal tabs should discard their cached viewers and selections");
201
201
 
@@ -228,7 +228,7 @@ assert.match(changesRenderSource, /return renderGitDiffFile\(gitUntrackedEntryTo
228
228
  assert.match(changesRenderSource, /if \(entry\.contentMissing\) return fileViewerChangesNotice\("Untracked file content is unavailable\.", "error"\);/, "an untracked response without content should not pretend the file is empty");
229
229
  assert.doesNotMatch(changesRenderSource, /runGitFileAction|gitChangesFileActionsFor|gitFileActionButtons/, "the read-only changes surface must not expose staging or discard actions");
230
230
 
231
- assert.match(css, /\.file-viewer-editor,\n\.file-viewer-preview,\n\.file-viewer-changes \{/, "the changes surface should share the file viewer content frame");
231
+ assert.match(css, /\.file-viewer-editor,\n\.file-viewer-preview,\n\.file-viewer-image,\n\.file-viewer-changes \{/, "the text, image, and changes surfaces should share the file viewer content frame");
232
232
  assert.match(css, /\.file-viewer-changes \{\n\s*padding: 0\.72rem;\n\}/, "the changes surface should have its own padding inside the shared frame");
233
233
  assert.match(css, /\.file-viewer-changes \.git-diff-grid \{[\s\S]*grid-template-columns:[\s\S]*min-width: 30rem;[\s\S]*\}/, "the split diff grid should be narrowed for the file viewer pane");
234
234
  assert.match(css, /\.file-viewer-changes-notice \{[\s\S]*font-size: var\(--text-xs\);[\s\S]*\}\n\.file-viewer-changes-notice\.error \{ color: var\(--ctp-red\); \}/, "changes notices should be readable and mark errors distinctly");
@@ -4,11 +4,11 @@ import { dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
6
6
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
7
- const [app, server, watcher, readme] = await Promise.all([
7
+ const [app, server, watcher, development] = await Promise.all([
8
8
  readFile(join(root, "public", "app.js"), "utf8"),
9
9
  readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
10
10
  readFile(join(root, "lib", "git-live-watcher.mjs"), "utf8"),
11
- readFile(join(root, "README.md"), "utf8"),
11
+ readFile(join(root, "DEVELOPMENT.md"), "utf8"),
12
12
  ]);
13
13
 
14
14
  function functionBody(source, name) {
@@ -49,6 +49,6 @@ assert.match(invalidateRepository, /if \(!gitPanelSectionExpanded\(\)\) return;/
49
49
  assert.match(ensureVisibleFresh, /snapshot\?\.error/, "persistent Git read errors should not cause an unbounded render/reload loop");
50
50
  assert.match(ensureVisibleFresh, /gitPanelSnapshotFresh\(snapshot\)[\s\S]*loadGitPanelRepository\(card\)/, "visible stale repositories should refresh on render");
51
51
  assert.match(handleEvent, /case "webui_git_changed":[\s\S]*invalidateGitPanelRepository\(event\.root\)/, "the browser event stream should route Git invalidations to the cache");
52
- assert.match(readme, /live filesystem updates[\s\S]*SSE/, "README should document live watcher-driven Git refresh behavior");
52
+ assert.match(development, /live filesystem updates[\s\S]*SSE/, "development guide should document live watcher-driven Git refresh behavior");
53
53
 
54
54
  console.log("git-panel-live-updates-static.test.mjs passed");