@sanqianx/project-knowledge 5.0.29 → 5.0.31

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 (65) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +21 -0
  3. package/_site/_test/appearance-settings-test.js +148 -0
  4. package/_site/_test/helpers/parallel-capture-safety-r5-cap-shell.js +606 -0
  5. package/_site/_test/helpers/parallel-capture-safety-r5-memory-shell.js +464 -0
  6. package/_site/_test/helpers/parallel-dock-acceptance-env.js +301 -0
  7. package/_site/_test/helpers/parallel-dock-acceptance-r2-env.js +378 -0
  8. package/_site/_test/helpers/parallel-dock-acceptance-r2-ui.js +314 -0
  9. package/_site/_test/helpers/parallel-dock-acceptance-ui.js +195 -0
  10. package/_site/_test/helpers/parallel-dock-isolation-r3-credential-preload.js +113 -0
  11. package/_site/_test/helpers/parallel-dock-isolation-r3-env.js +307 -0
  12. package/_site/_test/helpers/parallel-dock-isolation-r3-fixture.js +373 -0
  13. package/_site/_test/helpers/parallel-dock-isolation-r3-ui.js +314 -0
  14. package/_site/_test/helpers/parallel-engine-reconcile-r4-harness.js +340 -0
  15. package/_site/_test/helpers/parallel-engine-reconcile-r4-standin-analyzer.js +82 -0
  16. package/_site/_test/helpers/parallel-memory-capture-r3-cap-shell.js +605 -0
  17. package/_site/_test/helpers/parallel-memory-capture-r3-shell.js +176 -0
  18. package/_site/_test/helpers/parallel-memory-capture-r4-cap-shell.js +577 -0
  19. package/_site/_test/helpers/parallel-memory-injection-shell.js +723 -0
  20. package/_site/_test/helpers/parallel-memory-injection-wb-host.js +81 -0
  21. package/_site/_test/helpers/parallel-workbench-drafts-r5-fixture.js +295 -0
  22. package/_site/_test/helpers/parallel-workbench-drafts-r5-harness.js +573 -0
  23. package/_site/_test/helpers/parallel-workbench-drafts-r5-host.js +69 -0
  24. package/_site/_test/helpers/parallel-workbench-runtime-harness.js +587 -0
  25. package/_site/_test/helpers/qa-r45-harness.js +94 -0
  26. package/_site/_test/helpers/qa-r48-env.js +64 -0
  27. package/_site/_test/helpers/qa-r51-env.cjs +77 -0
  28. package/_site/_test/parallel-capture-safety-r5-cap006-probe.js +524 -0
  29. package/_site/_test/parallel-capture-safety-r5-cap008e-probe.js +577 -0
  30. package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +320 -0
  31. package/_site/_test/parallel-engine-reconcile-r4-eng007-probe.js +304 -0
  32. package/_site/_test/parallel-logging-acceptance-log003-probe.js +78 -0
  33. package/_site/_test/parallel-logging-acceptance-log004-probe.js +85 -0
  34. package/_site/_test/parallel-memory-capture-r3-cap001-probe.js +238 -0
  35. package/_site/_test/parallel-memory-capture-r3-cap006-probe.js +371 -0
  36. package/_site/_test/parallel-memory-capture-r3-cap008-probe.js +439 -0
  37. package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +271 -0
  38. package/_site/_test/parallel-memory-capture-r4-cap006-probe.js +519 -0
  39. package/_site/_test/parallel-memory-capture-r4-cap008e-probe.js +569 -0
  40. package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +314 -0
  41. package/_site/_test/parallel-memory-injection-origin-probe.js +412 -0
  42. package/_site/_test/parallel-memory-injection-probe.js +411 -0
  43. package/_site/_test/parallel-workbench-drafts-r4-probe.js +477 -0
  44. package/_site/_test/parallel-workbench-drafts-r5-chrome-env-bisect.js +89 -0
  45. package/_site/_test/parallel-workbench-drafts-r5-probe.js +593 -0
  46. package/_site/_test/parallel-workbench-runtime-minimax-probe.js +321 -0
  47. package/_site/_test/parallel-workbench-runtime-wb004-ordering.js +307 -0
  48. package/_site/_test/parallel-workbench-runtime-wb005-drafts.js +313 -0
  49. package/_site/_test/parallel-workbench-runtime-wb008-abort.js +321 -0
  50. package/_site/_test/qa-r45-offline-backfill-test.js +279 -0
  51. package/_site/_test/qa-r48-sys003-blank-secret-test.js +258 -0
  52. package/_site/_test/t07c-cln-001-002-007-coverage-test.js +135 -0
  53. package/_site/_test/t07d-git-rel-coverage-test.js +224 -0
  54. package/_site/_test/t07e-qta-coverage-test.js +195 -0
  55. package/_site/_test/t07f-mem-008-coverage-test.js +101 -0
  56. package/_site/lib/server-app.js +11 -2
  57. package/_site/lib/settings-store.js +43 -1
  58. package/module-runtime-manifest.json +16 -16
  59. package/package.json +2 -2
  60. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  61. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  62. package/plugins/project-knowledge/.mcp.json +1 -1
  63. package/ui/index.html +18 -1
  64. package/ui/product.css +6 -2
  65. package/ui/product.js +86 -1
@@ -0,0 +1,314 @@
1
+ // _site/_test/helpers/parallel-dock-acceptance-r2-ui.js
2
+ //
3
+ // Lane-exclusive real-UI driver for P-DOCK-ACCEPTANCE-02. Derived from the
4
+ // R1 helper (parallel-dock-acceptance-ui.js, read-only reference).
5
+ //
6
+ // All interactions happen in a REAL browser against REAL pages:
7
+ // - the product page (pkb) with the real workbench iframe inside it,
8
+ // - the workbench module's own shipped panel host proof page, loaded from
9
+ // the same isolated module, used as a real host for the
10
+ // two-simultaneous-panel case.
11
+ // Observation is additive only: extra window message listeners that record
12
+ // kb:* traffic, plus real DOM reads. Nothing in the product or the module is
13
+ // wrapped, replaced or removed.
14
+
15
+ 'use strict';
16
+
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+
20
+ const { launchCdpBrowser, waitFor } = require('./cdp-browser');
21
+ const { findChrome } = require('./find-chrome');
22
+
23
+ // Records every kb:* message that crosses a window boundary, including the
24
+ // requestId, so a host-issued protocol request can be matched with its
25
+ // reply. Additive: it never intercepts or rewrites a message.
26
+ const LISTENER = (slot) => `(() => {
27
+ if (window.${slot}) return true;
28
+ window.${slot} = [];
29
+ window.addEventListener('message', ev => {
30
+ const data = ev.data;
31
+ if (!data || typeof data.type !== 'string' || !data.type.startsWith('kb:')) return;
32
+ window.${slot}.push({
33
+ t: Date.now(), type: data.type,
34
+ requestId: data.requestId || null,
35
+ panelId: data.panelId || null, providerId: data.providerId || null,
36
+ version: data.version === undefined ? null : data.version,
37
+ ok: data.ok === undefined ? null : data.ok,
38
+ code: data.code || null, error: data.error || null,
39
+ sessionId: data.sessionId || null, projectId: data.projectId || null,
40
+ activeProjectId: data.activeProjectId || null,
41
+ reason: data.reason || null,
42
+ panels: Array.isArray(data.panels) ? data.panels.map(p => ({
43
+ panelId: p.panelId, providerId: p.providerId, panelType: p.panelType || null,
44
+ open: p.open, active: p.active, ready: p.ready, error: p.error || null,
45
+ contentVersion: p.content && p.content.version !== undefined ? p.content.version : null,
46
+ contentAck: p.content && p.content.ack ? { version: p.content.ack.version, ok: p.content.ack.ok, error: p.content.ack.error || null } : null,
47
+ scope: p.scope || null,
48
+ })) : null,
49
+ providers: Array.isArray(data.providers) ? data.providers.map(p => ({ providerId: p.providerId, panelType: p.panelType || null, title: p.title || null })) : null,
50
+ });
51
+ });
52
+ return true;
53
+ })()`;
54
+
55
+ function termExpr(body) {
56
+ return `(() => {
57
+ const frame = document.getElementById('workFrame');
58
+ const doc = frame && frame.contentDocument;
59
+ if (!doc) return null;
60
+ ${body}
61
+ })()`;
62
+ }
63
+
64
+ async function frameEval(browser, body) {
65
+ return browser.evaluate(termExpr(body));
66
+ }
67
+
68
+ async function openWorkView(browser, productUrl, { timeoutMs = 90000 } = {}) {
69
+ await waitFor(() => browser.evaluate(`!!document.querySelector('[data-select-project]')`), 'product project list on home', timeoutMs);
70
+ await browser.evaluate(`document.querySelector('[data-select-project]').click(); true`);
71
+ await waitFor(() => browser.evaluate(`document.getElementById('workEmpty') && document.getElementById('workEmpty').hidden === true`), 'active project', 20000);
72
+ await browser.evaluate(`document.querySelector('[data-view="work"]').click(); true`);
73
+ await waitFor(() => browser.evaluate(`(() => { const f = document.getElementById('workFrame'); return !!(f && f.src); })()`), 'work frame src', 20000);
74
+ await waitFor(() => frameEval(browser, `return !!doc.getElementById('btn-new-session');`), 'terminal iframe loaded', timeoutMs);
75
+ }
76
+
77
+ async function installProductLog(browser) {
78
+ await browser.evaluate(LISTENER('__r2ProductLog'));
79
+ }
80
+
81
+ async function installTerminalLog(browser) {
82
+ await waitFor(() => browser.evaluate(`(() => {
83
+ const frame = document.getElementById('workFrame');
84
+ const win = frame && frame.contentWindow;
85
+ if (!win) return false;
86
+ if (win.__r2TermLog) return true;
87
+ win.__r2TermLog = [];
88
+ win.addEventListener('message', ev => {
89
+ const data = ev.data;
90
+ if (!data || typeof data.type !== 'string' || !data.type.startsWith('kb:')) return;
91
+ win.__r2TermLog.push({
92
+ t: Date.now(), type: data.type,
93
+ requestId: data.requestId || null,
94
+ panelId: data.panelId || null, providerId: data.providerId || null,
95
+ version: data.version === undefined ? null : data.version,
96
+ ok: data.ok === undefined ? null : data.ok,
97
+ code: data.code || null, error: data.error || null,
98
+ });
99
+ });
100
+ return true;
101
+ })()`), 'terminal message listener', 15000);
102
+ }
103
+
104
+ async function getLogs(browser) {
105
+ const productLog = await browser.evaluate(`window.__r2ProductLog ? window.__r2ProductLog.slice() : []`);
106
+ const termLog = await frameEval(browser, `return (frame.contentWindow.__r2TermLog || []).slice();`);
107
+ return { productLog, termLog };
108
+ }
109
+
110
+ async function dockSnapshot(browser) {
111
+ return frameEval(browser, `return (() => {
112
+ const toggle = doc.getElementById('btn-dock-toggle');
113
+ const dock = doc.getElementById('right-dock');
114
+ const tabs = Array.from(doc.querySelectorAll('.rd-tabs .rd-tab')).map((item, index) => ({
115
+ index,
116
+ label: (item.querySelector('.rd-tab-label') || { textContent: '' }).textContent || '',
117
+ title: item.title || '',
118
+ active: item.classList.contains('active'),
119
+ selected: item.querySelector('.rd-tab-open') ? item.querySelector('.rd-tab-open').getAttribute('aria-selected') === 'true' : false,
120
+ dot: (item.querySelector('.rd-dot') || { className: '' }).className || '',
121
+ hasClose: !!item.querySelector('.rd-tab-close'),
122
+ }));
123
+ return {
124
+ toggleHidden: !toggle || toggle.hidden,
125
+ expanded: toggle ? toggle.getAttribute('aria-expanded') : null,
126
+ toggleTitle: toggle ? toggle.title : null,
127
+ dockHidden: !dock || dock.hidden,
128
+ dockOpenClass: !!doc.querySelector('.dock-open'),
129
+ tabCount: tabs.length,
130
+ tabs,
131
+ hostFrames: doc.querySelectorAll('.rd-host-frame').length,
132
+ hostFrameTitles: Array.from(doc.querySelectorAll('.rd-host-frame')).map(frame => frame.getAttribute('title') || ''),
133
+ launcherPanes: doc.querySelectorAll('.rd-launcher').length,
134
+ };
135
+ })();`);
136
+ }
137
+
138
+ async function termClick(browser, body, label, timeoutMs = 15000) {
139
+ await waitFor(() => frameEval(browser, body), label, timeoutMs);
140
+ }
141
+
142
+ async function newSessionViaUi(browser) {
143
+ await termClick(browser, `const n = doc.getElementById('btn-new-session'); if (!n) return false; n.click(); return true;`, 'new-session button');
144
+ }
145
+
146
+ async function clickSessionRow(browser, sessionId) {
147
+ await termClick(browser, `const n = doc.querySelector('[data-session="${sessionId}"]'); if (!n) return false; n.scrollIntoView({block:'center'}); n.click(); return true;`, `session row ${sessionId}`);
148
+ }
149
+
150
+ async function clickDockToggle(browser) {
151
+ await termClick(browser, `const n = doc.getElementById('btn-dock-toggle'); if (!n || n.hidden) return false; n.click(); return true;`, 'dock toggle button');
152
+ }
153
+
154
+ async function clickPlus(browser) {
155
+ await termClick(browser, `const n = doc.querySelector('.rd-plus'); if (!n) return false; n.click(); return true;`, 'dock + button');
156
+ }
157
+
158
+ async function clickLauncherKnowledgeRow(browser) {
159
+ await termClick(browser, `const n = doc.querySelector('.rd-launcher .rd-picker-host-row'); if (!n) return false; n.click(); return true;`, 'launcher knowledge row');
160
+ }
161
+
162
+ async function clickTabByLabel(browser, label) {
163
+ await termClick(browser, `const row = Array.from(doc.querySelectorAll('.rd-tabs .rd-tab')).find(item => ((item.querySelector('.rd-tab-label') || { textContent: '' }).textContent || '') === '${label}'); if (!row) return false; row.click(); return true;`, `tab ${label}`);
164
+ }
165
+
166
+ async function closeTabByLabel(browser, label) {
167
+ await termClick(browser, `const row = Array.from(doc.querySelectorAll('.rd-tabs .rd-tab')).find(item => ((item.querySelector('.rd-tab-label') || { textContent: '' }).textContent || '') === '${label}'); if (!row) return false; row.querySelector('.rd-tab-close').click(); return true;`, `close tab ${label}`);
168
+ }
169
+
170
+ async function sessionRowExists(browser, sessionId) {
171
+ return frameEval(browser, `return !!doc.querySelector('[data-session="${sessionId}"]');`);
172
+ }
173
+
174
+ // The newest kb:panel/state is authoritative: after a close the workbench
175
+ // posts panels: [] and the provider must be absent from it.
176
+ function latestPanelState(productLog) {
177
+ for (let i = productLog.length - 1; i >= 0; i -= 1) {
178
+ const entry = productLog[i];
179
+ if (entry.type === 'kb:panel/state') return entry;
180
+ }
181
+ return null;
182
+ }
183
+
184
+ function knowledgePanelOf(productLog, providerId) {
185
+ const state = latestPanelState(productLog);
186
+ if (!state || !Array.isArray(state.panels)) return null;
187
+ return state.panels.find(panel => panel.providerId === providerId) || null;
188
+ }
189
+
190
+ // Real host-side protocol request: the host window posts the message to the
191
+ // workbench frame and waits for the workbench's own reply. The request is a
192
+ // legitimate protocol input (the same channel the product uses for its
193
+ // knowledge panel), never a DOM/listener manipulation.
194
+ let hostRequestSeq = 0;
195
+ async function hostPanelRequest(browser, type, payload = {}, { timeoutMs = 15000 } = {}) {
196
+ const requestId = `r2-${++hostRequestSeq}-${Date.now()}`;
197
+ const message = { type, requestId, ...payload };
198
+ const sent = await browser.evaluate(`(() => {
199
+ const frame = document.getElementById('workFrame');
200
+ if (!frame || !frame.contentWindow) return false;
201
+ frame.contentWindow.postMessage(${JSON.stringify(message)}, location.origin);
202
+ return true;
203
+ })()`);
204
+ if (!sent) throw new Error(`host protocol request ${type} could not be posted (no workFrame)`);
205
+ return waitFor(() => getLogs(browser).then(logs => {
206
+ const reply = logs.productLog.find(entry => entry.requestId === requestId && entry.type !== type);
207
+ return reply || null;
208
+ }), `host protocol reply for ${type}`, timeoutMs);
209
+ }
210
+
211
+ // Real reload of the embedded workbench iframe (the browser re-runs the
212
+ // whole app boot, exactly like a user refreshing the frame).
213
+ async function reloadWorkFrame(browser) {
214
+ const before = await browser.evaluate(`(() => { const f = document.getElementById('workFrame'); return f ? f.src : null; })()`);
215
+ await browser.evaluate(`(() => { const f = document.getElementById('workFrame'); if (!f) return false; f.src = f.src; return true; })()`);
216
+ await waitFor(() => browser.evaluate(`(() => { const f = document.getElementById('workFrame'); return !!(f && f.src); })()`), 'work frame src after reload', 20000);
217
+ return before;
218
+ }
219
+
220
+ // ---- the module's own shipped panel host proof page ----------------------
221
+
222
+ async function openPanelProofHost(browser, url, { timeoutMs = 60000 } = {}) {
223
+ // The embedded terminal posts kb:ready as soon as it boots, which can be
224
+ // before a post-navigation listener is installed. Install the recorder for
225
+ // every new document first so no early protocol message is missed.
226
+ await browser.send('Page.addScriptToEvaluateOnNewDocument', { source: LISTENER('__r2ProofLog') });
227
+ await browser.send('Page.navigate', { url });
228
+ await waitFor(() => browser.evaluate(`document.readyState === 'complete'`), 'proof host page load', timeoutMs);
229
+ await browser.evaluate(LISTENER('__r2ProofLog'));
230
+ await waitFor(() => browser.evaluate(`!!document.getElementById('terminal-frame')`), 'proof host terminal frame', timeoutMs);
231
+ await waitFor(() => browser.evaluate(`(() => {
232
+ const log = window.__r2ProofLog || [];
233
+ return log.some(entry => entry.type === 'kb:ready');
234
+ })()`), 'proof host kb:ready', timeoutMs);
235
+ return true;
236
+ }
237
+
238
+ async function proofLogs(browser) {
239
+ return browser.evaluate(`window.__r2ProofLog ? window.__r2ProofLog.slice() : []`);
240
+ }
241
+
242
+ async function clickProofButton(browser, id) {
243
+ return browser.evaluate(`(() => { const n = document.getElementById(${JSON.stringify(id)}); if (!n || n.disabled) return false; n.click(); return true; })()`);
244
+ }
245
+
246
+ async function proofStatus(browser) {
247
+ return browser.evaluate(`(() => {
248
+ const status = document.getElementById('panel-status');
249
+ const lines = Array.from(document.querySelectorAll('#state-log .line')).map(n => (n.textContent || '').trim());
250
+ return { status: status ? status.textContent : null, lines };
251
+ })()`);
252
+ }
253
+
254
+ // Host-role protocol request issued from the proof host page itself.
255
+ async function proofHostRequest(browser, type, payload = {}, { timeoutMs = 15000 } = {}) {
256
+ const requestId = `r2-proof-${++hostRequestSeq}-${Date.now()}`;
257
+ const message = { type, requestId, ...payload };
258
+ const sent = await browser.evaluate(`(() => {
259
+ const frame = document.getElementById('terminal-frame');
260
+ if (!frame || !frame.contentWindow) return false;
261
+ frame.contentWindow.postMessage(${JSON.stringify(message)}, location.origin);
262
+ return true;
263
+ })()`);
264
+ if (!sent) throw new Error(`proof host protocol request ${type} could not be posted`);
265
+ return waitFor(() => proofLogs(browser).then(logs => {
266
+ const reply = logs.find(entry => entry.requestId === requestId && entry.type !== type);
267
+ return reply || null;
268
+ }), `proof host protocol reply for ${type}`, timeoutMs);
269
+ }
270
+
271
+ async function failureContext(browser) {
272
+ const out = {};
273
+ const grab = async (key, expr) => {
274
+ try { out[key] = await browser.evaluate(expr); } catch (error) { out[key] = `unavailable: ${error.message}`; }
275
+ };
276
+ await grab('url', 'location.href');
277
+ await grab('frameSrc', `(() => { const f = document.getElementById('workFrame'); return f ? f.src : null; })()`);
278
+ try { out.logs = await getLogs(browser); } catch (error) { out.logs = `unavailable: ${error.message}`; }
279
+ try {
280
+ out.terminalDom = await frameEval(browser, `return (() => {
281
+ const btn = doc.getElementById('btn-new-session');
282
+ const sessions = Array.from(doc.querySelectorAll('[data-session]')).map(n => ({ id: n.getAttribute('data-session'), text: (n.textContent || '').replace(/\\s+/g, ' ').slice(0, 60) }));
283
+ return {
284
+ newSessionButton: btn ? { hidden: btn.hidden, disabled: btn.disabled, text: (btn.textContent || '').slice(0, 40) } : null,
285
+ sessionRows: sessions,
286
+ bodySnippet: (doc.body.textContent || '').replace(/\\s+/g, ' ').slice(0, 600),
287
+ };
288
+ })();`);
289
+ } catch (error) { out.terminalDom = `unavailable: ${error.message}`; }
290
+ return out;
291
+ }
292
+
293
+ function evidenceWriter(artifactsDir, baseName) {
294
+ fs.mkdirSync(artifactsDir, { recursive: true });
295
+ return {
296
+ write(value) {
297
+ const file = path.join(artifactsDir, baseName);
298
+ fs.writeFileSync(file, JSON.stringify(value, null, 2), 'utf8');
299
+ return file;
300
+ },
301
+ };
302
+ }
303
+
304
+ module.exports = {
305
+ launchCdpBrowser, waitFor, findChrome,
306
+ openWorkView, installProductLog, installTerminalLog, dockSnapshot,
307
+ newSessionViaUi, clickSessionRow, sessionRowExists,
308
+ clickDockToggle, clickPlus, clickLauncherKnowledgeRow,
309
+ clickTabByLabel, closeTabByLabel,
310
+ getLogs, frameEval, evidenceWriter, failureContext,
311
+ hostPanelRequest, reloadWorkFrame,
312
+ latestPanelState, knowledgePanelOf,
313
+ openPanelProofHost, proofLogs, clickProofButton, proofStatus, proofHostRequest,
314
+ };
@@ -0,0 +1,195 @@
1
+ // _site/_test/helpers/parallel-dock-acceptance-ui.js
2
+ //
3
+ // Lane-exclusive real-UI driver for P-DOCK-ACCEPTANCE-01. All interactions
4
+ // happen through the REAL product page in a real CDP browser: the terminal
5
+ // iframe is reached same-origin (the product proxies the module UI), and
6
+ // clicks are dispatched on the real DOM nodes the product itself renders.
7
+ // Observation is additive only: extra window message listeners that record
8
+ // kb:* traffic. Nothing in the product is wrapped or replaced.
9
+
10
+ 'use strict';
11
+
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+
15
+ const { launchCdpBrowser, waitFor } = require('./cdp-browser');
16
+ const { findChrome } = require('./find-chrome');
17
+
18
+ const PRODUCT_LISTENER = `(() => {
19
+ if (window.__dkProductLog) return true;
20
+ window.__dkProductLog = [];
21
+ window.addEventListener('message', ev => {
22
+ const data = ev.data;
23
+ if (!data || typeof data.type !== 'string' || !data.type.startsWith('kb:')) return;
24
+ window.__dkProductLog.push({
25
+ t: Date.now(), type: data.type,
26
+ panelId: data.panelId || null, providerId: data.providerId || null,
27
+ version: data.version === undefined ? null : data.version, ok: data.ok === undefined ? null : data.ok,
28
+ sessionId: data.sessionId || null, projectId: data.projectId || null,
29
+ knowledgeStatus: data.knowledge && data.knowledge.status || null,
30
+ knowledgeRefs: data.knowledge && Array.isArray(data.knowledge.references) ? data.knowledge.references.map(r => r.entryId || r.title || '') : null,
31
+ contentRefs: data.content && Array.isArray(data.content.references) ? data.content.references.map(r => r.entryId || r.title || '') : null,
32
+ panels: Array.isArray(data.panels) ? data.panels.map(p => ({ panelId: p.panelId, providerId: p.providerId, open: p.open, active: p.active, ready: p.ready, error: p.error || null })) : null,
33
+ });
34
+ });
35
+ return true;
36
+ })()`;
37
+
38
+ const TERMINAL_LISTENER = `(() => {
39
+ const frame = document.getElementById('workFrame');
40
+ const win = frame && frame.contentWindow;
41
+ if (!win) return false;
42
+ if (win.__dkTermLog) return true;
43
+ win.__dkTermLog = [];
44
+ win.addEventListener('message', ev => {
45
+ const data = ev.data;
46
+ if (!data || typeof data.type !== 'string' || !data.type.startsWith('kb:')) return;
47
+ win.__dkTermLog.push({
48
+ t: Date.now(), type: data.type,
49
+ panelId: data.panelId || null, providerId: data.providerId || null,
50
+ version: data.version === undefined ? null : data.version, ok: data.ok === undefined ? null : data.ok,
51
+ sessionId: data.sessionId || null,
52
+ contentRefs: data.content && Array.isArray(data.content.references) ? data.content.references.map(r => r.entryId || r.title || '') : null,
53
+ ackVersion: data.version === undefined ? null : data.version,
54
+ });
55
+ });
56
+ return true;
57
+ })()`;
58
+
59
+ function termExpr(body) {
60
+ return `(() => {
61
+ const frame = document.getElementById('workFrame');
62
+ const doc = frame && frame.contentDocument;
63
+ if (!doc) return null;
64
+ ${body}
65
+ })()`;
66
+ }
67
+
68
+ async function frameEval(browser, body) {
69
+ return browser.evaluate(termExpr(body));
70
+ }
71
+
72
+ async function openWorkView(browser, productUrl, { timeoutMs = 90000 } = {}) {
73
+ await waitFor(() => browser.evaluate(`!!document.querySelector('[data-select-project]')`), 'product project list on home', timeoutMs);
74
+ await browser.evaluate(`document.querySelector('[data-select-project]').click(); true`);
75
+ await waitFor(() => browser.evaluate(`document.getElementById('workEmpty') && document.getElementById('workEmpty').hidden === true`), 'active project', 20000);
76
+ await browser.evaluate(`document.querySelector('[data-view="work"]').click(); true`);
77
+ await waitFor(() => browser.evaluate(`(() => { const f = document.getElementById('workFrame'); return !!(f && f.src); })()`), 'work frame src', 20000);
78
+ await waitFor(() => frameEval(browser, `return !!doc.getElementById('btn-new-session');`), 'terminal iframe loaded', timeoutMs);
79
+ }
80
+
81
+ async function installProductLog(browser) {
82
+ await browser.evaluate(PRODUCT_LISTENER);
83
+ }
84
+
85
+ async function installTerminalLog(browser) {
86
+ await waitFor(() => browser.evaluate(TERMINAL_LISTENER), 'terminal message listener', 15000);
87
+ }
88
+
89
+ async function dockSnapshot(browser) {
90
+ return frameEval(browser, `return (() => {
91
+ const toggle = doc.getElementById('btn-dock-toggle');
92
+ const dock = doc.getElementById('right-dock');
93
+ const tabs = Array.from(doc.querySelectorAll('.rd-tabs .rd-tab')).map(item => ({
94
+ label: (item.querySelector('.rd-tab-label') || { textContent: '' }).textContent || '',
95
+ selected: item.querySelector('.rd-tab-open') ? item.querySelector('.rd-tab-open').getAttribute('aria-selected') === 'true' : false,
96
+ hasClose: !!item.querySelector('.rd-tab-close'),
97
+ }));
98
+ return {
99
+ toggleHidden: !toggle || toggle.hidden,
100
+ expanded: toggle ? toggle.getAttribute('aria-expanded') : null,
101
+ toggleTitle: toggle ? toggle.title : null,
102
+ dockHidden: !dock || dock.hidden,
103
+ dockOpenClass: !!doc.querySelector('.dock-open'),
104
+ tabCount: tabs.length,
105
+ tabs,
106
+ hostFrames: doc.querySelectorAll('.rd-host-frame').length,
107
+ launcherPanes: doc.querySelectorAll('.rd-launcher').length,
108
+ emptyPane: (doc.querySelector('.rd-empty') || { textContent: '' }).textContent || null,
109
+ };
110
+ })();`);
111
+ }
112
+
113
+ async function termClick(browser, body, label, timeoutMs = 15000) {
114
+ await waitFor(() => frameEval(browser, body), label, timeoutMs);
115
+ }
116
+
117
+ async function newSessionViaUi(browser) {
118
+ await termClick(browser, `const n = doc.getElementById('btn-new-session'); if (!n) return false; n.click(); return true;`, 'new-session button');
119
+ }
120
+
121
+ async function clickSessionRow(browser, sessionId) {
122
+ await termClick(browser, `const n = doc.querySelector('[data-session="${sessionId}"]'); if (!n) return false; n.scrollIntoView({block:'center'}); n.click(); return true;`, `session row ${sessionId}`);
123
+ }
124
+
125
+ async function clickDockToggle(browser) {
126
+ await termClick(browser, `const n = doc.getElementById('btn-dock-toggle'); if (!n || n.hidden) return false; n.click(); return true;`, 'dock toggle button');
127
+ }
128
+
129
+ async function clickPlus(browser) {
130
+ await termClick(browser, `const n = doc.querySelector('.rd-plus'); if (!n) return false; n.click(); return true;`, 'dock + button');
131
+ }
132
+
133
+ async function clickLauncherKnowledgeRow(browser) {
134
+ await termClick(browser, `const n = doc.querySelector('.rd-launcher .rd-picker-host-row'); if (!n) return false; n.click(); return true;`, 'launcher knowledge row');
135
+ }
136
+
137
+ async function clickTabByLabel(browser, label) {
138
+ await termClick(browser, `const row = Array.from(doc.querySelectorAll('.rd-tabs .rd-tab')).find(item => ((item.querySelector('.rd-tab-label') || { textContent: '' }).textContent || '') === '${label}'); if (!row) return false; row.querySelector('.rd-tab-open').click(); return true;`, `tab ${label}`);
139
+ }
140
+
141
+ async function closeTabByLabel(browser, label) {
142
+ await termClick(browser, `const row = Array.from(doc.querySelectorAll('.rd-tabs .rd-tab')).find(item => ((item.querySelector('.rd-tab-label') || { textContent: '' }).textContent || '') === '${label}'); if (!row) return false; row.querySelector('.rd-tab-close').click(); return true;`, `close tab ${label}`);
143
+ }
144
+
145
+ async function getLogs(browser) {
146
+ const productLog = await browser.evaluate(`window.__dkProductLog ? window.__dkProductLog.slice() : []`);
147
+ const termLog = await frameEval(browser, `return (frame.contentWindow.__dkTermLog || []).slice();`);
148
+ return { productLog, termLog };
149
+ }
150
+
151
+ async function sessionRowExists(browser, sessionId) {
152
+ return frameEval(browser, `return !!doc.querySelector('[data-session="${sessionId}"]');`);
153
+ }
154
+
155
+ async function failureContext(browser) {
156
+ const out = {};
157
+ const grab = async (key, expr) => {
158
+ try { out[key] = await browser.evaluate(expr); } catch (error) { out[key] = `unavailable: ${error.message}`; }
159
+ };
160
+ await grab('url', 'location.href');
161
+ await grab('frameSrc', `(() => { const f = document.getElementById('workFrame'); return f ? f.src : null; })()`);
162
+ try { out.logs = await getLogs(browser); } catch (error) { out.logs = `unavailable: ${error.message}`; }
163
+ try {
164
+ out.terminalDom = await frameEval(browser, `return (() => {
165
+ const btn = doc.getElementById('btn-new-session');
166
+ const sessions = Array.from(doc.querySelectorAll('[data-session]')).map(n => ({ id: n.getAttribute('data-session'), text: (n.textContent || '').replace(/\\s+/g, ' ').slice(0, 60) }));
167
+ return {
168
+ newSessionButton: btn ? { hidden: btn.hidden, disabled: btn.disabled, text: (btn.textContent || '').slice(0, 40) } : null,
169
+ sessionRows: sessions,
170
+ bodySnippet: (doc.body.textContent || '').replace(/\\s+/g, ' ').slice(0, 600),
171
+ };
172
+ })();`);
173
+ } catch (error) { out.terminalDom = `unavailable: ${error.message}`; }
174
+ return out;
175
+ }
176
+
177
+ function evidenceWriter(artifactsDir, baseName) {
178
+ fs.mkdirSync(artifactsDir, { recursive: true });
179
+ return {
180
+ write(value) {
181
+ const file = path.join(artifactsDir, baseName);
182
+ fs.writeFileSync(file, JSON.stringify(value, null, 2), 'utf8');
183
+ return file;
184
+ },
185
+ };
186
+ }
187
+
188
+ module.exports = {
189
+ launchCdpBrowser, waitFor, findChrome,
190
+ openWorkView, installProductLog, installTerminalLog, dockSnapshot,
191
+ newSessionViaUi, clickSessionRow, sessionRowExists,
192
+ clickDockToggle, clickPlus, clickLauncherKnowledgeRow,
193
+ clickTabByLabel, closeTabByLabel,
194
+ getLogs, frameEval, evidenceWriter, failureContext,
195
+ };
@@ -0,0 +1,113 @@
1
+ // _site/_test/helpers/parallel-dock-isolation-r3-credential-preload.js
2
+ //
3
+ // Loaded INSIDE the isolated terminal-module process through
4
+ // `node --require <this file> <module entry>`.
5
+ //
6
+ // The real subscription credential is handed over through an extra pipe
7
+ // (file descriptor 3) that the launcher writes once and closes. The secret
8
+ // therefore never appears in argv, in the environment, in a file, in a URL or
9
+ // in the browser - it exists in the server process memory only.
10
+ //
11
+ // The overlay serves the READ paths of the module's own ProfileStore
12
+ // (runtimeProfile / publicProfile / _configured). Every write-capable method
13
+ // runs with the overlay switched off, so the secret can never be persisted
14
+ // into the isolated credentials.v1.json.
15
+
16
+ 'use strict';
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+
21
+ const HANDOFF_FD = 3;
22
+
23
+ function sleep(ms) {
24
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
25
+ }
26
+
27
+ // Reads the whole payload of the handoff pipe. The pipe is non-blocking on
28
+ // some platforms, so EAGAIN is retried until the writer closes it.
29
+ function readHandoff(fd) {
30
+ const buffer = Buffer.alloc(8192);
31
+ let text = '';
32
+ for (;;) {
33
+ let read = 0;
34
+ try {
35
+ read = fs.readSync(fd, buffer, 0, buffer.length, null);
36
+ } catch (error) {
37
+ if (error && (error.code === 'EAGAIN' || error.code === 'EWOULDBLOCK')) { sleep(5); continue; }
38
+ if (error && error.code === 'EOF') break;
39
+ return null;
40
+ }
41
+ if (!read) break;
42
+ text += buffer.slice(0, read).toString('utf8');
43
+ }
44
+ const trimmed = text.trim();
45
+ if (!trimmed) return null;
46
+ try { return JSON.parse(trimmed); } catch { return null; }
47
+ }
48
+
49
+ function resolveProfileStore() {
50
+ const root = String(process.env.PK_R3_MODULE_ROOT || '').trim();
51
+ const candidates = root
52
+ ? [path.join(root, 'packages', 'server', 'lib', 'profile-store.js')]
53
+ : [];
54
+ candidates.push(path.resolve(__dirname, '..', '..', '..', 'node_modules', 'claude-ai-workbench', 'packages', 'server', 'lib', 'profile-store.js'));
55
+ for (const candidate of candidates) {
56
+ try { if (fs.existsSync(candidate)) return candidate; } catch {}
57
+ }
58
+ throw new Error(`profile-store.js not found (candidates: ${candidates.join(', ')})`);
59
+ }
60
+
61
+ function installOverlay(payload) {
62
+ if (!payload || !payload.secret || !payload.credentialRef) return false;
63
+ const profileStorePath = resolveProfileStore();
64
+ const { ProfileStore } = require(profileStorePath);
65
+
66
+ let overlayEnabled = true;
67
+ const originalCredentials = ProfileStore.prototype._credentials;
68
+ ProfileStore.prototype._credentials = function patchedCredentials() {
69
+ const file = originalCredentials.call(this);
70
+ if (!overlayEnabled) return file;
71
+ const credentials = Object.assign({}, file.credentials || {});
72
+ if (!credentials[payload.credentialRef]) credentials[payload.credentialRef] = payload.secret;
73
+ return Object.assign({}, file, { credentials });
74
+ };
75
+
76
+ // Methods that persist the credential file must never see the overlay,
77
+ // otherwise the in-memory secret would be written to disk.
78
+ for (const name of ['setCredential', 'delete', 'setEmbeddingConfig', 'importLegacy', 'importEmbedding']) {
79
+ const original = ProfileStore.prototype[name];
80
+ if (typeof original !== 'function') continue;
81
+ ProfileStore.prototype[name] = function patchedWriter(...args) {
82
+ const previous = overlayEnabled;
83
+ overlayEnabled = false;
84
+ try { return original.apply(this, args); } finally { overlayEnabled = previous; }
85
+ };
86
+ }
87
+
88
+ // The masked credential would otherwise leak six leading and six trailing
89
+ // characters of the secret into the UI and the public API.
90
+ const originalPublicProfile = ProfileStore.prototype.publicProfile;
91
+ ProfileStore.prototype.publicProfile = function patchedPublicProfile(profile) {
92
+ const result = originalPublicProfile.call(this, profile);
93
+ if (profile && profile.credentialRef === payload.credentialRef) result.credentialMasked = '********';
94
+ return result;
95
+ };
96
+
97
+ process.env.PK_R3_CREDENTIAL_IN_MEMORY = '1';
98
+ return true;
99
+ }
100
+
101
+ let installed = false;
102
+ try {
103
+ const payload = readHandoff(HANDOFF_FD);
104
+ installed = installOverlay(payload);
105
+ } catch (error) {
106
+ // A preload failure must never abort the server silently: the server is
107
+ // started without the overlay and the profile then simply has no
108
+ // credential, which the probe reports as a hard failure.
109
+ process.stderr.write(`[r3-preload] credential overlay not installed: ${error && error.message}\n`);
110
+ installed = false;
111
+ }
112
+
113
+ module.exports = { installed };