@sanqianx/project-knowledge 5.0.30 → 5.0.32

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 (135) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/README.md +5 -2
  4. package/_site/_test/appearance-settings-test.js +148 -0
  5. package/_site/_test/helpers/parallel-capture-safety-r5-cap-shell.js +606 -0
  6. package/_site/_test/helpers/parallel-capture-safety-r5-memory-shell.js +464 -0
  7. package/_site/_test/helpers/parallel-dock-acceptance-env.js +301 -0
  8. package/_site/_test/helpers/parallel-dock-acceptance-r2-env.js +378 -0
  9. package/_site/_test/helpers/parallel-dock-acceptance-r2-ui.js +314 -0
  10. package/_site/_test/helpers/parallel-dock-acceptance-ui.js +195 -0
  11. package/_site/_test/helpers/parallel-dock-isolation-r3-credential-preload.js +113 -0
  12. package/_site/_test/helpers/parallel-dock-isolation-r3-env.js +307 -0
  13. package/_site/_test/helpers/parallel-dock-isolation-r3-fixture.js +373 -0
  14. package/_site/_test/helpers/parallel-dock-isolation-r3-ui.js +314 -0
  15. package/_site/_test/helpers/parallel-engine-advanced-engine-child.js +1 -1
  16. package/_site/_test/helpers/parallel-engine-advanced-fault-writer.js +3 -3
  17. package/_site/_test/helpers/parallel-engine-advanced-harness.js +1 -1
  18. package/_site/_test/helpers/parallel-engine-advanced-standin-analyzer.js +1 -1
  19. package/_site/_test/helpers/parallel-engine-final-harness.js +2 -2
  20. package/_site/_test/helpers/parallel-engine-final-standin-analyzer.js +1 -1
  21. package/_site/_test/helpers/parallel-engine-reconcile-r4-harness.js +340 -0
  22. package/_site/_test/helpers/parallel-engine-reconcile-r4-standin-analyzer.js +82 -0
  23. package/_site/_test/helpers/parallel-memory-analyzer.js +1 -1
  24. package/_site/_test/helpers/parallel-memory-capture-r3-cap-shell.js +605 -0
  25. package/_site/_test/helpers/parallel-memory-capture-r3-shell.js +176 -0
  26. package/_site/_test/helpers/parallel-memory-capture-r4-cap-shell.js +577 -0
  27. package/_site/_test/helpers/parallel-memory-injection-shell.js +723 -0
  28. package/_site/_test/helpers/parallel-memory-injection-wb-host.js +81 -0
  29. package/_site/_test/helpers/parallel-nav-shell.js +1 -1
  30. package/_site/_test/helpers/parallel-qa-engine-endpoint-guard.js +1 -1
  31. package/_site/_test/helpers/parallel-retrieval-followup-r2-shell.js +1 -1
  32. package/_site/_test/helpers/parallel-workbench-drafts-r5-fixture.js +295 -0
  33. package/_site/_test/helpers/parallel-workbench-drafts-r5-harness.js +573 -0
  34. package/_site/_test/helpers/parallel-workbench-drafts-r5-host.js +69 -0
  35. package/_site/_test/helpers/parallel-workbench-runtime-harness.js +587 -0
  36. package/_site/_test/helpers/qa-r45-harness.js +94 -0
  37. package/_site/_test/helpers/qa-r48-env.js +64 -0
  38. package/_site/_test/helpers/qa-r51-env.cjs +77 -0
  39. package/_site/_test/helpers/qa-r91-harness.cjs +4 -1
  40. package/_site/_test/package-boundary-test.js +5 -0
  41. package/_site/_test/parallel-capture-safety-r5-cap006-probe.js +524 -0
  42. package/_site/_test/parallel-capture-safety-r5-cap008e-probe.js +577 -0
  43. package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +320 -0
  44. package/_site/_test/parallel-engine-advanced-eng011-ui-probe.js +1 -1
  45. package/_site/_test/parallel-engine-reconcile-r4-eng007-probe.js +304 -0
  46. package/_site/_test/parallel-knowledge-engine-test.js +3 -3
  47. package/_site/_test/parallel-knowledge-retrieval-test.js +2 -2
  48. package/_site/_test/parallel-logging-acceptance-log003-probe.js +78 -0
  49. package/_site/_test/parallel-logging-acceptance-log004-probe.js +85 -0
  50. package/_site/_test/parallel-memory-capture-r3-cap001-probe.js +238 -0
  51. package/_site/_test/parallel-memory-capture-r3-cap006-probe.js +371 -0
  52. package/_site/_test/parallel-memory-capture-r3-cap008-probe.js +439 -0
  53. package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +271 -0
  54. package/_site/_test/parallel-memory-capture-r4-cap006-probe.js +519 -0
  55. package/_site/_test/parallel-memory-capture-r4-cap008e-probe.js +569 -0
  56. package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +314 -0
  57. package/_site/_test/parallel-memory-injection-origin-probe.js +412 -0
  58. package/_site/_test/parallel-memory-injection-probe.js +411 -0
  59. package/_site/_test/parallel-nav-isolation-test.js +1 -1
  60. package/_site/_test/parallel-qa-engine-endpoint-guard-test.js +1 -1
  61. package/_site/_test/parallel-retrieval-followup-citation-test.js +2 -2
  62. package/_site/_test/parallel-retrieval-followup-corpus-test.js +1 -1
  63. package/_site/_test/parallel-workbench-drafts-r4-probe.js +477 -0
  64. package/_site/_test/parallel-workbench-drafts-r5-chrome-env-bisect.js +89 -0
  65. package/_site/_test/parallel-workbench-drafts-r5-probe.js +593 -0
  66. package/_site/_test/parallel-workbench-runtime-minimax-probe.js +321 -0
  67. package/_site/_test/parallel-workbench-runtime-wb004-ordering.js +307 -0
  68. package/_site/_test/parallel-workbench-runtime-wb005-drafts.js +313 -0
  69. package/_site/_test/parallel-workbench-runtime-wb008-abort.js +321 -0
  70. package/_site/_test/qa-r45-offline-backfill-test.js +279 -0
  71. package/_site/_test/qa-r48-sys003-blank-secret-test.js +258 -0
  72. package/_site/_test/t07c-cln-001-002-007-coverage-test.js +135 -0
  73. package/_site/_test/t07d-git-rel-coverage-test.js +226 -0
  74. package/_site/_test/t07e-qta-coverage-test.js +195 -0
  75. package/_site/_test/t07f-mem-008-coverage-test.js +101 -0
  76. package/_site/lib/module-bridge.js +2 -11
  77. package/_site/lib/server-app.js +11 -2
  78. package/_site/lib/settings-store.js +43 -1
  79. package/_site/scripts/install-module-candidates.js +1 -1
  80. package/_site/scripts/pack-module-candidates.js +2 -1
  81. package/_site/scripts/verify-module-runtime.js +17 -32
  82. package/_site/scripts/verify-product-runtime.js +7 -3
  83. package/docs/README.zh-CN.md +3 -1
  84. package/module-runtime-manifest.json +56 -6
  85. package/package.json +2 -4
  86. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  87. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  88. package/plugins/project-knowledge/.mcp.json +1 -1
  89. package/ui/index.html +18 -1
  90. package/ui/product.css +6 -2
  91. package/ui/product.js +86 -1
  92. package/_modules/knowledge-engine/README.md +0 -133
  93. package/_modules/knowledge-engine/package.json +0 -38
  94. package/_modules/knowledge-engine/src/analysis-contract.js +0 -35
  95. package/_modules/knowledge-engine/src/analysis-failures.js +0 -39
  96. package/_modules/knowledge-engine/src/analysis-output.js +0 -52
  97. package/_modules/knowledge-engine/src/analysis-worker.js +0 -58
  98. package/_modules/knowledge-engine/src/bin.js +0 -52
  99. package/_modules/knowledge-engine/src/bridge-client.js +0 -24
  100. package/_modules/knowledge-engine/src/context.js +0 -140
  101. package/_modules/knowledge-engine/src/coordinator.js +0 -376
  102. package/_modules/knowledge-engine/src/diagnostics.js +0 -37
  103. package/_modules/knowledge-engine/src/headless-analyzer.js +0 -66
  104. package/_modules/knowledge-engine/src/index-request.js +0 -49
  105. package/_modules/knowledge-engine/src/knowledge-targets.js +0 -46
  106. package/_modules/knowledge-engine/src/memories.js +0 -281
  107. package/_modules/knowledge-engine/src/memory-eligibility.js +0 -74
  108. package/_modules/knowledge-engine/src/retrieval-policy.json +0 -14
  109. package/_modules/knowledge-engine/src/retrieval-ranking.js +0 -153
  110. package/_modules/knowledge-engine/src/retrieval.js +0 -367
  111. package/_modules/knowledge-engine/src/runtime/README.md +0 -7
  112. package/_modules/knowledge-engine/src/runtime/atomic-file.js +0 -204
  113. package/_modules/knowledge-engine/src/runtime/automation-config.js +0 -140
  114. package/_modules/knowledge-engine/src/runtime/commit-conversation-binder.js +0 -250
  115. package/_modules/knowledge-engine/src/runtime/commit-processing-ledger.js +0 -26
  116. package/_modules/knowledge-engine/src/runtime/commit-prompt.js +0 -205
  117. package/_modules/knowledge-engine/src/runtime/commit-reconciler.js +0 -432
  118. package/_modules/knowledge-engine/src/runtime/content-hash.js +0 -4
  119. package/_modules/knowledge-engine/src/runtime/contracts.js +0 -282
  120. package/_modules/knowledge-engine/src/runtime/conversation-exclusions.js +0 -204
  121. package/_modules/knowledge-engine/src/runtime/conversation-store.js +0 -389
  122. package/_modules/knowledge-engine/src/runtime/evidence-bundle.js +0 -228
  123. package/_modules/knowledge-engine/src/runtime/git-runner.js +0 -62
  124. package/_modules/knowledge-engine/src/runtime/knowledge-promotion.js +0 -559
  125. package/_modules/knowledge-engine/src/runtime/knowledge-retrieval-service.js +0 -408
  126. package/_modules/knowledge-engine/src/runtime/layout.js +0 -46
  127. package/_modules/knowledge-engine/src/runtime/markdown-knowledge-indexer.js +0 -276
  128. package/_modules/knowledge-engine/src/runtime/scanner.js +0 -298
  129. package/_modules/knowledge-engine/src/server.js +0 -166
  130. package/_modules/knowledge-engine/src/store.js +0 -267
  131. package/_modules/knowledge-engine/ui/app.css +0 -172
  132. package/_modules/knowledge-engine/ui/app.js +0 -318
  133. package/_modules/knowledge-engine/ui/index.html +0 -95
  134. package/_site/scripts/vendor-modules.js +0 -49
  135. package/vendor-manifest.json +0 -55
@@ -0,0 +1,577 @@
1
+ 'use strict';
2
+ // _site/_test/parallel-capture-safety-r5-cap008e-probe.js
3
+ //
4
+ // R5 copy of _site/_test/parallel-memory-capture-r4-cap008e-probe.js
5
+ // (logic identical; two mechanical changes only — the shell require points at
6
+ // the R5 cap shell, and every real-home read now resolves the real home
7
+ // explicitly via realHomeDir() [PK_CAPTURE_SAFETY_R5_REAL_HOME, set by the
8
+ // wrapper before the env switch] instead of os.homedir(), which under the
9
+ // wrapper's isolated USERPROFILE would have compared the fixture home against
10
+ // itself).
11
+ //
12
+ // CAP-008 (engine mode) 同basename不同真实路径A/B并行 — the default-owner
13
+ // half that the R3 legacy run never proved.
14
+ //
15
+ // steps: 相同basename不同真实路径A/B开发会话并行。
16
+ // expected: 以canonical身份隔离,不串对话/Commit。
17
+ //
18
+ // WHAT IS DIFFERENT FROM THE ACCEPTED R3 LEGACY RUN
19
+ //
20
+ // The R3 probe ran the product with analysisOwner 'legacy': the shell's own
21
+ // BridgeConsumerService drained the journal into the SHELL's per-project
22
+ // stores. The production default is analysisOwner 'engine' — the ENGINE
23
+ // consumes. This probe runs the DEFAULT topology end to end:
24
+ //
25
+ // * the REAL event-bridge console (the pinned installed package) as its own
26
+ // child process, serving the journal home the installed shim writes to;
27
+ // * the REAL vendored engine in-process with its BridgeClient pointed at
28
+ // that console. Consumption starts DISABLED and is switched on by the
29
+ // SHELL's own connectEngine -> /api/control activation — the driver never
30
+ // calls control, never routes a projectId and never sets a health flag;
31
+ // * the real product server in its DEFAULT mode (analysisOwner 'engine');
32
+ // * the real 接入 click installs the Bridge shim; the sessions are fired
33
+ // through that real installed shim; the commits run the real managed
34
+ // post-commit hooks; the shell forwards the boundary to the Bridge and
35
+ // the engine consumes it.
36
+ //
37
+ // Isolation is asserted at every layer with falsifiable cross-checks:
38
+ // distinct canonical workspaceIds (the product's own resolver), distinct
39
+ // console journals (the real console's own API), per-project conversation
40
+ // stores inside the ENGINE (its own validated read-back, whose
41
+ // appendBridgeEvent gate rejects a mismatched workspaceId), engine-side
42
+ // commit boundary files under the owning project only, git-hook-triggered
43
+ // engine runs, and a whole-engine-datadir grep. The SHELL's legacy stores
44
+ // must stay marker-free — the default consumer is the engine, and a legacy
45
+ // write would mean the wrong path ran.
46
+ //
47
+ // HONEST SCOPE: the shim payloads (UserPromptSubmit / Stop) are artificial
48
+ // protocol fixtures fired by the driver through the real installed shim —
49
+ // they are NOT real model chat. The engine's analysis step is the frozen
50
+ // P-MEMORY-01 stand-in analyzer with an empty plan; the terminal side uses
51
+ // the shared module fixture and the vector side a lane-local endpoint
52
+ // implementing the real hub's /api/sync contract (the engine is created with
53
+ // an explicit vectorUrl — its built-in default 127.0.0.1:8787 is a LIVE
54
+ // module on this machine and must never be reached). Everything on the
55
+ // capture/consumption identity chain (console, journal, shim, hooks, shell,
56
+ // engine) is real.
57
+
58
+ const fs = require('node:fs');
59
+ const path = require('node:path');
60
+ const os = require('node:os');
61
+ const crypto = require('node:crypto');
62
+ const assert = require('node:assert/strict');
63
+ const { execFileSync, spawnSync } = require('node:child_process');
64
+
65
+ const { startCapHarness, consoleIdentity, sha256File, realHomeDir } = require('./helpers/parallel-capture-safety-r5-cap-shell');
66
+ const r3cap = require('./helpers/parallel-memory-capture-r3-cap-shell');
67
+ const { BridgeAdapter } = require(path.join(r3cap.ROOT, '_site', 'lib', 'bridge-adapter'));
68
+ const { parseManagedMarker } = require(path.join(r3cap.ROOT, '_site', 'lib', 'hook-manager'));
69
+
70
+ const EVIDENCE = process.env.PK_TEST_EVIDENCE_DIR ? path.resolve(process.env.PK_TEST_EVIDENCE_DIR) : null;
71
+ const CLIENT = 'claude';
72
+
73
+ function gitHead() {
74
+ try {
75
+ return execFileSync('git', ['-C', r3cap.ROOT, 'rev-parse', 'HEAD'], { encoding: 'utf8', windowsHide: true }).trim();
76
+ } catch { return null; }
77
+ }
78
+
79
+ function walkFiles(dir) {
80
+ const out = [];
81
+ const walk = current => {
82
+ let entries = [];
83
+ try { entries = fs.readdirSync(current, { withFileTypes: true }); } catch { return; }
84
+ for (const entry of entries) {
85
+ const full = path.join(current, entry.name);
86
+ if (entry.isDirectory()) walk(full);
87
+ else if (entry.isFile()) out.push(full);
88
+ }
89
+ };
90
+ walk(dir);
91
+ return out;
92
+ }
93
+
94
+ function grepTree(dir, needles) {
95
+ const hits = [];
96
+ for (const file of walkFiles(dir)) {
97
+ let text;
98
+ try { text = fs.readFileSync(file, 'utf8'); } catch { continue; }
99
+ for (const needle of needles) if (text.includes(needle)) hits.push({ file: path.relative(dir, file).split(path.sep).join('/'), needle });
100
+ }
101
+ return hits;
102
+ }
103
+
104
+ function runGitRaw(repo, args) {
105
+ const result = spawnSync('git', ['-C', repo, ...args], { encoding: 'utf8', windowsHide: true });
106
+ if (result.status !== 0) throw new Error(`git ${args.join(' ')} in ${repo} failed (${result.status}): ${String(result.stderr || result.stdout || '').slice(0, 500)}`);
107
+ return { exitCode: result.status };
108
+ }
109
+
110
+ /** The identity chain of the default path: core, engine, console, shim. */
111
+ function identityChain(shimPath) {
112
+ const coreFiles = ['_site/lib/server-app.js', '_site/lib/engine-connection.js', '_site/lib/module-bridge.js', '_site/lib/bridge-adapter.js', '_site/lib/hook-manager.js'];
113
+ const engineFiles = ['src/server.js', 'src/coordinator.js', 'src/bridge-client.js', 'src/store.js', 'src/runtime/conversation-store.js', 'src/runtime/layout.js'];
114
+ const consoleHookSource = path.join(r3cap.ROOT, 'node_modules', '@sanqianx', 'ai-coding-event-bridge-console', 'src', 'bridge', 'connectors', 'claude-code', 'hook-entry.js');
115
+ return {
116
+ gitHead: gitHead(),
117
+ core: coreFiles.map(file => ({ file, sha256: sha256File(path.join(r3cap.ROOT, file)) })),
118
+ engine: engineFiles.map(file => ({ file, sha256: sha256File(path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(r3cap.ROOT)] })), file)) })),
119
+ console: consoleIdentity(),
120
+ shim: {
121
+ installedPath: shimPath,
122
+ installedSha256: sha256File(shimPath),
123
+ consoleHookSource: 'src/bridge/connectors/claude-code/hook-entry.js',
124
+ consoleHookSourceSha256: sha256File(consoleHookSource),
125
+ },
126
+ };
127
+ }
128
+
129
+ async function main() {
130
+ const step = label => console.error(`[cap008e] ${label} @ ${new Date().toISOString()}`);
131
+ step('harness starting');
132
+ const harness = await startCapHarness({ tag: 'cap008e', evidenceDir: EVIDENCE || undefined });
133
+ step('harness ready');
134
+ const evidence = [];
135
+ const reposRoot = fs.mkdtempSync(path.join(harness.tempRoot, 'pk-cap008e-repos-'));
136
+ const engineDataDir = path.join(harness.fixture, 'engine');
137
+ const shellDataDir = harness.server.dataDir;
138
+ try {
139
+ const hex = () => crypto.randomBytes(6).toString('hex');
140
+ const markerA = { prompt: `CAP008E-A-PROMPT-${hex()}`, answer: `CAP008E-A-ANSWER-${hex()}`, commit: `CAP008E-A-COMMIT-${hex()}`, session: `cap008e-alpha-${hex()}` };
141
+ const markerB = { prompt: `CAP008E-B-PROMPT-${hex()}`, answer: `CAP008E-B-ANSWER-${hex()}`, commit: `CAP008E-B-COMMIT-${hex()}`, session: `cap008e-beta-${hex()}` };
142
+ const commands = [];
143
+
144
+ // ------------------------------------------------------------------
145
+ // 1. The real 接入 click: the Bridge shim that will receive both
146
+ // sessions is the one the product itself installed.
147
+ // ------------------------------------------------------------------
148
+ await harness.openSystemDrawer();
149
+ await harness.nativeClick(`[data-agent-switch="install"][data-agent-client="${CLIENT}"]`);
150
+ await harness.waitFor(
151
+ () => harness.run("document.getElementById('agentCaptureFeedback').textContent.trim().length > 0 && !document.getElementById('agentCaptureFeedback').textContent.includes('正在接入')"),
152
+ 'the 接入 action answers in the UI',
153
+ 180000,
154
+ );
155
+ const installCall = await harness.lastInstallCall();
156
+ assert.ok(installCall, 'the UI really sent an install request');
157
+ assert.equal(installCall.status, 200, `the install request answers 200: ${JSON.stringify(installCall)}`);
158
+ assert.equal(installCall.response.complete, true, `the install must complete: ${JSON.stringify(installCall.response)}`);
159
+ await harness.waitFor(
160
+ () => harness.run(`(() => { const row = [...document.querySelectorAll('#agentCaptureList .agent-capture-row')].find(item => item.querySelector('[data-agent-switch]') && item.querySelector('[data-agent-switch]').dataset.agentClient === ${JSON.stringify(CLIENT)}); return Boolean(row) && row.querySelector('.status').textContent === '已接入'; })()`),
161
+ 'the row shows the client as connected',
162
+ 90000,
163
+ );
164
+ const hooks = harness.ownedHookEntries();
165
+ const shimPaths = [...new Set(hooks.map(entry => entry.shimPath))];
166
+ assert.equal(shimPaths.length, 1, `both capture events must point at one shim: ${JSON.stringify(hooks)}`);
167
+ assert.equal(fs.existsSync(shimPaths[0]), true, 'the shim must exist on disk');
168
+ const shimPath = shimPaths[0];
169
+ step('access installed');
170
+
171
+ // ------------------------------------------------------------------
172
+ // 2. Two real repositories with the SAME basename at different paths.
173
+ // ------------------------------------------------------------------
174
+ const repoA = path.join(reposRoot, 'alpha', 'service');
175
+ const repoB = path.join(reposRoot, 'beta', 'service');
176
+ for (const [repo, seed] of [[repoA, 'a'], [repoB, 'b']]) {
177
+ fs.mkdirSync(repo, { recursive: true });
178
+ commands.push({ cwd: repo, args: ['init', '-b', 'main'], ...runGitRaw(repo, ['init', '-b', 'main']) });
179
+ commands.push({ cwd: repo, args: ['config', 'user.name', 'CAP008E Probe'], ...runGitRaw(repo, ['config', 'user.name', 'CAP008E Probe']) });
180
+ commands.push({ cwd: repo, args: ['config', 'user.email', 'cap008e@probe.invalid'], ...runGitRaw(repo, ['config', 'user.email', 'cap008e@probe.invalid']) });
181
+ fs.writeFileSync(path.join(repo, 'README.md'), `CAP008E same-basename fixture ${seed}\n`, 'utf8');
182
+ commands.push({ cwd: repo, args: ['add', 'README.md'], ...runGitRaw(repo, ['add', 'README.md']) });
183
+ commands.push({ cwd: repo, args: ['commit', '-m', `seed ${seed}`], ...runGitRaw(repo, ['commit', '-m', `seed ${seed}`]) });
184
+ }
185
+ assert.equal(path.basename(repoA), path.basename(repoB), 'the two repos must share one basename');
186
+ assert.notEqual(path.resolve(repoA).toLowerCase(), path.resolve(repoB).toLowerCase(), 'the two repos must live at different canonical paths');
187
+
188
+ // ------------------------------------------------------------------
189
+ // 3. Import both through the real API in the DEFAULT mode. The import
190
+ // itself wires each project into the REAL console and the REAL
191
+ // engine (registerProjectLinks) and installs the managed hook bound
192
+ // to its own projectId.
193
+ // ------------------------------------------------------------------
194
+ const knowledgeRoot = path.join(harness.fixture, 'knowledge');
195
+ fs.mkdirSync(knowledgeRoot, { recursive: true });
196
+ const settingsResult = await harness.productApi('PATCH', '/api/settings', { knowledge: { rootPath: knowledgeRoot } });
197
+ assert.equal(settingsResult.status, 200, `the isolated instance must accept its knowledge root: ${JSON.stringify(settingsResult.body)}`);
198
+ const imported = [];
199
+ for (const [repo, side] of [[repoA, 'a'], [repoB, 'b']]) {
200
+ const knowledgePath = path.join(knowledgeRoot, `service-${side}`);
201
+ fs.mkdirSync(knowledgePath, { recursive: true });
202
+ const result = await harness.productApi('POST', '/api/projects/import', { localPath: repo, knowledgePath });
203
+ assert.equal(result.status, 201, `importing ${repo} must answer 201: ${JSON.stringify(result.body)}`);
204
+ const project = result.body && result.body.project;
205
+ assert.ok(project && project.projectId, `the import must return the project: ${JSON.stringify(result.body)}`);
206
+ const modules = result.body.modules || {};
207
+ assert.equal(modules.eventBridge && modules.eventBridge.ok, true, `the real console must register the project (${side}): ${JSON.stringify(modules)}`);
208
+ assert.equal(modules.engine && modules.engine.ok, true, `the real engine must register the project (${side}): ${JSON.stringify(modules)}`);
209
+ imported.push({ repo, projectId: project.projectId, workspaceId: project.config && project.config.repoIdentity ? project.config.repoIdentity.workspaceId : null });
210
+ }
211
+ const [projectA, projectB] = imported;
212
+ assert.notEqual(projectA.projectId, projectB.projectId, 'the two repos must be two projects');
213
+ assert.ok(projectA.workspaceId && projectB.workspaceId, `both projects must carry a canonical workspace identity: ${JSON.stringify(imported)}`);
214
+ assert.notEqual(projectA.workspaceId, projectB.workspaceId, 'same basename at different paths must yield different canonical identities');
215
+
216
+ // The product's own identity resolver is the oracle for the same claim.
217
+ const adapter = new BridgeAdapter({});
218
+ const oracleA = await adapter.resolveRepoIdentity(repoA);
219
+ const oracleB = await adapter.resolveRepoIdentity(repoB);
220
+ assert.equal(oracleA.status, 'ok', `the product's own resolver must answer for A: ${JSON.stringify(oracleA)}`);
221
+ assert.equal(oracleB.status, 'ok', `the product's own resolver must answer for B: ${JSON.stringify(oracleB)}`);
222
+ assert.equal(oracleA.repoIdentity.workspaceId, projectA.workspaceId, 'project A identity must equal the canonical one');
223
+ assert.equal(oracleB.repoIdentity.workspaceId, projectB.workspaceId, 'project B identity must equal the canonical one');
224
+ assert.notEqual(oracleA.repoIdentity.workspaceId, oracleB.repoIdentity.workspaceId, 'the canonical identities of A and B must differ');
225
+
226
+ // The managed hook of each repo is bound to its own project only.
227
+ const hookMarkers = {};
228
+ for (const project of imported) {
229
+ const hookFile = path.join(project.repo, '.git', 'hooks', 'post-commit');
230
+ assert.equal(fs.existsSync(hookFile), true, `the managed post-commit hook must exist in ${project.repo}`);
231
+ const marker = parseManagedMarker(fs.readFileSync(hookFile, 'utf8'));
232
+ assert.ok(marker, `the hook must be managed: ${hookFile}`);
233
+ assert.equal(marker.projectId, project.projectId, `the hook of ${project.repo} must be bound to its own project: ${JSON.stringify(marker)}`);
234
+ hookMarkers[project.projectId] = marker;
235
+ }
236
+ assert.notEqual(hookMarkers[projectA.projectId].projectId, hookMarkers[projectB.projectId].projectId, 'the two hooks must carry different projectIds');
237
+ step('both projects imported and wired');
238
+
239
+ // ------------------------------------------------------------------
240
+ // 4. The DEFAULT owner is really connected and really consuming: the
241
+ // product reports engine ownership ready, and the engine's own
242
+ // health reports its journal consumer enabled — switched on by the
243
+ // shell's activation, never by this driver.
244
+ // ------------------------------------------------------------------
245
+ let ownership = null;
246
+ await harness.waitFor(async () => {
247
+ const result = await harness.productApi('GET', '/api/modules/health');
248
+ if (result.status !== 200) return false;
249
+ ownership = result.body && result.body.ownership;
250
+ return Boolean(ownership && ownership.owner === 'engine' && ownership.ready === true);
251
+ }, 'the product reports the engine owner ready (the shell really activated the engine)', 60000);
252
+ let engineHealth = null;
253
+ await harness.waitFor(async () => {
254
+ const result = await harness.engineApi('GET', '/api/health');
255
+ engineHealth = result.body;
256
+ return Boolean(engineHealth && engineHealth.journal && engineHealth.journal.enabled === true);
257
+ }, 'the engine own health reports journal consumption enabled', 60000);
258
+ assert.equal(engineHealth.journal.consumer, 'knowledge-engine', `the engine consuming is the knowledge-engine itself: ${JSON.stringify(engineHealth.journal)}`);
259
+ assert.deepEqual(engineHealth.journal.failures, [], `no journal consumption failures: ${JSON.stringify(engineHealth.journal.failures)}`);
260
+
261
+ // The engine's project records carry the console-derived journal
262
+ // identity — the canonical chain the consumer matches on.
263
+ const engineProject = id => harness.engine.coordinator.store.getProject(id);
264
+ const engineA0 = engineProject(projectA.projectId);
265
+ const engineB0 = engineProject(projectB.projectId);
266
+ assert.ok(engineA0 && engineB0, 'the engine really registered both projects');
267
+ assert.ok(/^sha256:[a-f0-9]{64}$/.test(engineA0.journalId || ''), `A's engine journalId must be the canonical sha256 form: ${JSON.stringify(engineA0.journalId)}`);
268
+ assert.ok(/^sha256:[a-f0-9]{64}$/.test(engineB0.journalId || ''), `B's engine journalId must be the canonical sha256 form: ${JSON.stringify(engineB0.journalId)}`);
269
+ assert.equal(engineA0.journalId, projectA.workspaceId, "A's engine journalId is A's canonical workspace identity");
270
+ assert.equal(engineB0.journalId, projectB.workspaceId, "B's engine journalId is B's canonical workspace identity");
271
+ assert.notEqual(engineA0.journalId, engineB0.journalId, 'the two engine journal identities must differ');
272
+ const consoleProjects = await harness.consoleApi('GET', '/api/projects');
273
+ assert.equal(consoleProjects.status, 200, `the real console must list its projects: ${JSON.stringify(consoleProjects.body)}`);
274
+ const consoleIds = (consoleProjects.body.projects || []).map(project => project.id);
275
+ assert.equal(consoleIds.includes(projectA.workspaceId), true, 'the real console holds a project keyed by A canonical identity');
276
+ assert.equal(consoleIds.includes(projectB.workspaceId), true, 'the real console holds a project keyed by B canonical identity');
277
+ step('default owner connected and consuming');
278
+
279
+ // ------------------------------------------------------------------
280
+ // 5. Two interleaved development sessions through the REAL installed
281
+ // shim (artificial protocol fixtures — see the honest scope above).
282
+ // ------------------------------------------------------------------
283
+ const fire = (payload) => {
284
+ const env = { ...process.env, AI_CODING_EVENT_BRIDGE_HOME: harness.bridgeHome };
285
+ delete env.AI_CODING_EVENT_BRIDGE_CAPTURE; // an ambient kill-switch must not silence the real capture
286
+ const result = spawnSync(process.execPath, [shimPath], {
287
+ input: JSON.stringify(payload), env, encoding: 'utf8', timeout: 90000, windowsHide: true,
288
+ });
289
+ return { payload: payload.hook_event_name, cwd: payload.cwd, exitCode: result.status, error: result.error ? result.error.message : null };
290
+ };
291
+ const sessionCommands = [
292
+ fire({ hook_event_name: 'UserPromptSubmit', session_id: markerA.session, prompt: markerA.prompt, cwd: repoA }),
293
+ fire({ hook_event_name: 'UserPromptSubmit', session_id: markerB.session, prompt: markerB.prompt, cwd: repoB }),
294
+ fire({ hook_event_name: 'Stop', session_id: markerA.session, last_assistant_message: markerA.answer, cwd: repoA }),
295
+ fire({ hook_event_name: 'Stop', session_id: markerB.session, last_assistant_message: markerB.answer, cwd: repoB }),
296
+ ];
297
+ for (const call of sessionCommands) {
298
+ assert.equal(call.exitCode, 0, `the shim must exit 0 (fail-open contract): ${JSON.stringify(call)}`);
299
+ commands.push({ cwd: call.cwd, args: ['shim', call.payload], exitCode: call.exitCode });
300
+ }
301
+ step('sessions fired through the installed shim');
302
+
303
+ // ------------------------------------------------------------------
304
+ // 6. The ENGINE's own conversation stores: each project carries only
305
+ // its own session. appendBridgeEvent rejects a mismatched
306
+ // workspaceId, so a crossed event would surface as a journal
307
+ // failure, not as silent contamination.
308
+ // ------------------------------------------------------------------
309
+ const readEngineEvents = projectId => {
310
+ try { return harness.engine.coordinator.conversations.readEvents(projectId); } catch { return []; }
311
+ };
312
+ await harness.waitFor(() => {
313
+ const text = JSON.stringify(readEngineEvents(projectA.projectId));
314
+ return text.includes(markerA.prompt) && text.includes(markerA.answer);
315
+ }, 'the engine consumed A session into A conversation store', 90000);
316
+ await harness.waitFor(() => {
317
+ const text = JSON.stringify(readEngineEvents(projectB.projectId));
318
+ return text.includes(markerB.prompt) && text.includes(markerB.answer);
319
+ }, 'the engine consumed B session into B conversation store', 90000);
320
+
321
+ const eventsA = readEngineEvents(projectA.projectId);
322
+ const eventsB = readEngineEvents(projectB.projectId);
323
+ const recordCheck = (events, marker, workspaceId, projectId, journalId, side) => {
324
+ const own = events.filter(event => String(event.content || '').includes(marker.prompt) || String(event.content || '').includes(marker.answer));
325
+ assert.ok(own.length >= 2, `${side} must persist its own prompt and answer events: ${JSON.stringify(own.map(event => ({ eventType: event.eventType, content: String(event.content || '').slice(0, 60) })))}`);
326
+ assert.equal(own.every(event => event.projectId === projectId), true, `every ${side} record must be named after its project: ${JSON.stringify(own.map(event => event.projectId))}`);
327
+ assert.equal(own.every(event => event.repoIdentity && event.repoIdentity.workspaceId === workspaceId), true, `every ${side} record must carry ${side}'s canonical identity: ${JSON.stringify(own.map(event => event.repoIdentity))}`);
328
+ assert.equal(own.every(event => event.journalId === journalId), true, `every ${side} record must come from ${side}'s journal: ${JSON.stringify(own.map(event => event.journalId))}`);
329
+ assert.equal(own.every(event => event.sessionId === marker.session), true, `every ${side} record must belong to ${side}'s session: ${JSON.stringify(own.map(event => event.sessionId))}`);
330
+ };
331
+ recordCheck(eventsA, markerA, projectA.workspaceId, projectA.projectId, engineA0.journalId, 'A');
332
+ recordCheck(eventsB, markerB, projectB.workspaceId, projectB.projectId, engineB0.journalId, 'B');
333
+ const textA = JSON.stringify(eventsA);
334
+ const textB = JSON.stringify(eventsB);
335
+ assert.equal(textA.includes(markerB.prompt) || textA.includes(markerB.answer) || textA.includes(markerB.session), false, "A's engine store must not carry B's session");
336
+ assert.equal(textB.includes(markerA.prompt) || textB.includes(markerA.answer) || textB.includes(markerA.session), false, "B's engine store must not carry A's session");
337
+ const consumptionHealth = await harness.engineApi('GET', '/api/health');
338
+ assert.deepEqual(consumptionHealth.body.journal.failures, [], `no journal consumption failures after both sessions: ${JSON.stringify(consumptionHealth.body.journal.failures)}`);
339
+
340
+ // ------------------------------------------------------------------
341
+ // 7. The real console's own journals: the traffic really passed through
342
+ // the Bridge, and the two sides live in two distinct journals.
343
+ // ------------------------------------------------------------------
344
+ const journalsAnswer = await harness.consoleApi('GET', '/api/journals');
345
+ assert.equal(journalsAnswer.status, 200, `the real console must list its journals: ${JSON.stringify(journalsAnswer.body)}`);
346
+ const journalEvidence = [];
347
+ for (const journal of journalsAnswer.body.journals || []) {
348
+ const eventsAnswer = await harness.consoleApi('GET', `/api/journal/events?journalId=${encodeURIComponent(journal.journalId)}&fromSequence=1&limit=200`);
349
+ assert.equal(eventsAnswer.status, 200, `the real console must serve journal events: ${JSON.stringify(eventsAnswer.body)}`);
350
+ const text = JSON.stringify(eventsAnswer.body.events || []);
351
+ journalEvidence.push({
352
+ journalId: journal.journalId,
353
+ eventCount: (eventsAnswer.body.events || []).length,
354
+ carriesA: text.includes(markerA.prompt) || text.includes(markerA.answer),
355
+ carriesB: text.includes(markerB.prompt) || text.includes(markerB.answer),
356
+ });
357
+ }
358
+ const journalA = journalEvidence.find(entry => entry.carriesA);
359
+ const journalB = journalEvidence.find(entry => entry.carriesB);
360
+ assert.ok(journalA, `A's session must really live in a real console journal: ${JSON.stringify(journalEvidence)}`);
361
+ assert.ok(journalB, `B's session must really live in a real console journal: ${JSON.stringify(journalEvidence)}`);
362
+ assert.notEqual(journalA.journalId, journalB.journalId, 'the two sessions must live in two distinct console journals');
363
+ assert.equal(journalA.carriesB || journalB.carriesA, false, `no console journal may carry both sides' sessions: ${JSON.stringify(journalEvidence)}`);
364
+ assert.equal(journalA.journalId, engineA0.journalId, "A's console journal is A's engine journal identity");
365
+ assert.equal(journalB.journalId, engineB0.journalId, "B's console journal is B's engine journal identity");
366
+ step('engine stores and console journals isolated');
367
+
368
+ // ------------------------------------------------------------------
369
+ // 8. Real commits in both repos. The managed hooks notify the shell,
370
+ // the shell forwards the boundary to the Bridge, and the ENGINE
371
+ // consumes it: the boundary file lands under the owning project's
372
+ // runtime directory in the ENGINE data dir, and a git-hook run is
373
+ // enqueued.
374
+ // ------------------------------------------------------------------
375
+ const commits = [];
376
+ for (const [project, marker, seed] of [[projectA, markerA, 'a'], [projectB, markerB, 'b']]) {
377
+ const file = path.join(project.repo, `work-${seed}.md`);
378
+ fs.writeFileSync(file, `${marker.commit}\n`, 'utf8');
379
+ commands.push({ cwd: project.repo, args: ['add', `work-${seed}.md`], ...runGitRaw(project.repo, ['add', `work-${seed}.md`]) });
380
+ commands.push({ cwd: project.repo, args: ['commit', '-m', marker.commit], ...runGitRaw(project.repo, ['commit', '-m', marker.commit]) });
381
+ const sha = execFileSync('git', ['-C', project.repo, 'rev-parse', 'HEAD'], { encoding: 'utf8', windowsHide: true }).trim();
382
+ assert.match(sha, /^[0-9a-f]{40}$/, 'the commit must produce a real sha');
383
+ commits.push({ projectId: project.projectId, repo: project.repo, marker: marker.commit, sha });
384
+ }
385
+ const [commitA, commitB] = commits;
386
+ const layout = harness.engine.coordinator.layout;
387
+ const boundaryPath = (projectId, sha) => layout.getProjectCommitBoundaryPath(projectId, sha);
388
+ await harness.waitFor(() => fs.existsSync(boundaryPath(commitA.projectId, commitA.sha)), 'the engine persists A commit boundary under A project runtime', 90000);
389
+ await harness.waitFor(() => fs.existsSync(boundaryPath(commitB.projectId, commitB.sha)), 'the engine persists B commit boundary under B project runtime', 90000);
390
+ assert.equal(fs.existsSync(boundaryPath(commitB.projectId, commitA.sha)), false, "the engine must not write A's boundary under B");
391
+ assert.equal(fs.existsSync(boundaryPath(commitA.projectId, commitB.sha)), false, "the engine must not write B's boundary under A");
392
+ const boundaryA = JSON.parse(fs.readFileSync(boundaryPath(commitA.projectId, commitA.sha), 'utf8'));
393
+ const boundaryB = JSON.parse(fs.readFileSync(boundaryPath(commitB.projectId, commitB.sha), 'utf8'));
394
+ assert.equal(boundaryA.projectId, commitA.projectId, `A's boundary must name A: ${JSON.stringify(boundaryA)}`);
395
+ assert.equal(boundaryA.repoIdentity.workspaceId, projectA.workspaceId, `A's boundary must carry A's canonical identity: ${JSON.stringify(boundaryA)}`);
396
+ assert.equal(boundaryA.journalId, engineA0.journalId, `A's boundary must come from A's journal: ${JSON.stringify(boundaryA)}`);
397
+ assert.equal(boundaryB.projectId, commitB.projectId, `B's boundary must name B: ${JSON.stringify(boundaryB)}`);
398
+ assert.equal(boundaryB.repoIdentity.workspaceId, projectB.workspaceId, `B's boundary must carry B's canonical identity: ${JSON.stringify(boundaryB)}`);
399
+ assert.equal(boundaryB.journalId, engineB0.journalId, `B's boundary must come from B's journal: ${JSON.stringify(boundaryB)}`);
400
+
401
+ // The git-hook runs settled for both projects. The lane-local vector
402
+ // endpoint answers the engine's index step, so the only honest settled
403
+ // state is 'succeeded' — a run parked in 'index-pending' or 'failed'
404
+ // would mean the index plane was not the lane's (that is exactly how
405
+ // attempt 4 exposed the default-vectorUrl leak).
406
+ const runsOf = projectId => harness.engine.coordinator.store.listRuns(projectId)
407
+ .filter(run => run.trigger === 'git-hook');
408
+ await harness.waitFor(() => runsOf(commitA.projectId).some(run => run.state === 'succeeded'), "A git-hook run reaches 'succeeded' (knowledge promoted AND indexed)", 90000);
409
+ await harness.waitFor(() => runsOf(commitB.projectId).some(run => run.state === 'succeeded'), "B git-hook run reaches 'succeeded' (knowledge promoted AND indexed)", 90000);
410
+ const runsA = runsOf(commitA.projectId).map(run => ({ runId: run.runId, state: run.state, commitSha: run.commitSha }));
411
+ const runsB = runsOf(commitB.projectId).map(run => ({ runId: run.runId, state: run.state, commitSha: run.commitSha }));
412
+ assert.equal(runsA.length > 0 && runsA.every(run => run.state === 'succeeded'), true, `every A git-hook run must be 'succeeded': ${JSON.stringify(runsA)}`);
413
+ assert.equal(runsB.length > 0 && runsB.every(run => run.state === 'succeeded'), true, `every B git-hook run must be 'succeeded': ${JSON.stringify(runsB)}`);
414
+ assert.equal(runsA.every(run => run.commitSha === commitA.sha), true, `every A git-hook run targets A's commit: ${JSON.stringify(runsA)}`);
415
+ assert.equal(runsB.every(run => run.commitSha === commitB.sha), true, `every B git-hook run targets B's commit: ${JSON.stringify(runsB)}`);
416
+
417
+ // The engine's index plane stayed inside the lane AND inside each
418
+ // project's own identity: /api/sync arrived at the lane-local endpoint
419
+ // under the OWNING project id and knowledge path only.
420
+ const vectorSyncs = harness.laneVector.requests
421
+ .filter(entry => entry.method === 'POST' && entry.path === '/api/sync')
422
+ .map(entry => entry.body);
423
+ const syncsA = vectorSyncs.filter(body => body && body.project === commitA.projectId);
424
+ const syncsB = vectorSyncs.filter(body => body && body.project === commitB.projectId);
425
+ assert.ok(syncsA.length > 0, "the engine really indexed A's knowledge through the lane vector plane");
426
+ assert.ok(syncsB.length > 0, "the engine really indexed B's knowledge through the lane vector plane");
427
+ assert.equal(syncsA.every(body => body.sourceDir === engineA0.knowledgePath), true, `every A index sync must point at A's knowledge path: ${JSON.stringify(syncsA)}`);
428
+ assert.equal(syncsB.every(body => body.sourceDir === engineB0.knowledgePath), true, `every B index sync must point at B's knowledge path: ${JSON.stringify(syncsB)}`);
429
+ assert.equal(vectorSyncs.length, syncsA.length + syncsB.length, `no vector sync may target any identity besides A and B: ${JSON.stringify(vectorSyncs)}`);
430
+ const finalHealth = await harness.engineApi('GET', '/api/health');
431
+ assert.deepEqual(finalHealth.body.journal.failures, [], `no journal consumption failures after the commits: ${JSON.stringify(finalHealth.body.journal.failures)}`);
432
+ step('commits consumed, boundaries and runs settled');
433
+
434
+ // ------------------------------------------------------------------
435
+ // 9. The SHELL's legacy stores stay marker-free: the default consumer
436
+ // is the engine, and a legacy-side write would be the wrong path.
437
+ // ------------------------------------------------------------------
438
+ const shellProjectDir = projectId => path.join(shellDataDir, 'projects', projectId);
439
+ for (const project of imported) {
440
+ assert.equal(fs.existsSync(path.join(shellProjectDir(project.projectId), 'conversation-events.jsonl')), false, `the shell legacy conversation store must not exist for ${project.projectId} in engine mode`);
441
+ }
442
+ const shellGrep = grepTree(shellDataDir, [markerA.prompt, markerA.answer, markerA.commit, markerB.prompt, markerB.answer, markerB.commit]);
443
+ assert.deepEqual(shellGrep, [], `no session or commit marker may be written into the shell legacy stores: ${JSON.stringify(shellGrep)}`);
444
+
445
+ // ------------------------------------------------------------------
446
+ // 10. Whole-engine-datadir grep: each side's evidence exists under its
447
+ // own project directory and nowhere under the other's.
448
+ // ------------------------------------------------------------------
449
+ const hitsA = grepTree(engineDataDir, [markerA.prompt, markerA.answer, markerA.session, commitA.sha]);
450
+ const hitsB = grepTree(engineDataDir, [markerB.prompt, markerB.answer, markerB.session, commitB.sha]);
451
+ assert.ok(hitsA.length > 0, "A's evidence must exist in the engine data dir");
452
+ assert.ok(hitsB.length > 0, "B's evidence must exist in the engine data dir");
453
+ assert.equal(hitsA.some(hit => hit.file.split('/').includes(projectA.projectId)), true, `A's evidence must be under A's engine project directory: ${JSON.stringify(hitsA)}`);
454
+ assert.equal(hitsB.some(hit => hit.file.split('/').includes(projectB.projectId)), true, `B's evidence must be under B's engine project directory: ${JSON.stringify(hitsB)}`);
455
+ assert.equal(hitsA.some(hit => hit.file.split('/').includes(projectB.projectId)), false, `no A evidence may live under B's engine project directory: ${JSON.stringify(hitsA)}`);
456
+ assert.equal(hitsB.some(hit => hit.file.split('/').includes(projectA.projectId)), false, `no B evidence may live under A's engine project directory: ${JSON.stringify(hitsB)}`);
457
+
458
+ // ------------------------------------------------------------------
459
+ // 11. The real UI on its default projection: reload, home view lists
460
+ // both same-basename projects from the real registry.
461
+ // ------------------------------------------------------------------
462
+ await harness.browser.send('Page.reload', {});
463
+ await harness.waitFor(() => harness.run("document.readyState === 'complete'"), 'the reloaded page is complete', 20000);
464
+ await harness.waitFor(
465
+ () => harness.run(`document.getElementById('homeContent').textContent.split('service').length - 1 >= 2`),
466
+ 'the home view lists both same-basename projects after the reload',
467
+ 20000,
468
+ );
469
+ if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'cap008e-after.png'));
470
+
471
+ // ------------------------------------------------------------------
472
+ // 12. Nothing leaked into the developer's real home.
473
+ // ------------------------------------------------------------------
474
+ const configComparison = r3cap.compareConfigSurface(harness.realHomeBefore, r3cap.digestRealClientConfigs(realHomeDir()));
475
+ assert.equal(configComparison.byteIdentical, true, `the real client configuration must be untouched: ${JSON.stringify({ changedFiles: configComparison.changedFiles, changedDirs: configComparison.changedDirs })}`);
476
+ const treeComparison = r3cap.compareRealTrees(harness.realTreesBefore, r3cap.digestRealClientTrees(realHomeDir()));
477
+ // The developer's LIVE Codex rewrites its own global session state
478
+ // (.codex-global-state.json + .bak, an atomic replace) at any moment —
479
+ // other fleet agents work in this repo while the case executes. Such a
480
+ // rewrite is a concurrent live write, never this lane's doing, and the
481
+ // falsifiable proof is that the rewritten bytes carry NONE of this
482
+ // case's markers. Everything else outside the known runtime set must
483
+ // still be untouched.
484
+ const LIVE_CODEX_STATE = /^\.codex\/\.codex-global-state\.json(\.bak)?$/;
485
+ const codexTreeAfter = r3cap.digestRealClientTrees(realHomeDir()).find(entry => entry.dir === '.codex');
486
+ const codexTreeBefore = harness.realTreesBefore.find(entry => entry.dir === '.codex');
487
+ const concurrentLiveWrites = treeComparison.leaks
488
+ .filter(item => LIVE_CODEX_STATE.test(`${item.dir}/${item.file}`))
489
+ .map(item => ({
490
+ dir: item.dir, file: item.file, state: item.state,
491
+ beforeSha256: (codexTreeBefore && codexTreeBefore.files.get(item.file)) || null,
492
+ afterSha256: (codexTreeAfter && codexTreeAfter.files.get(item.file)) || null,
493
+ }));
494
+ for (const write of concurrentLiveWrites) {
495
+ assert.equal(write.state, 'modified', `a live codex state file may only be rewritten, never created or deleted, by the outside world: ${JSON.stringify(write)}`);
496
+ assert.ok(write.beforeSha256, `the codex state file must already exist in the before-digest: ${JSON.stringify(write)}`);
497
+ }
498
+ const realCodexDir = path.join(realHomeDir(), '.codex');
499
+ for (const name of ['.codex-global-state.json', '.codex-global-state.json.bak']) {
500
+ let text = '';
501
+ try { text = fs.readFileSync(path.join(realCodexDir, name), 'utf8'); } catch { continue; }
502
+ const markersAll = [markerA.prompt, markerA.answer, markerA.commit, markerB.prompt, markerB.answer, markerB.commit];
503
+ assert.equal(markersAll.some(marker => text.includes(marker)), false, `the concurrent live codex state ${name} must not carry this case's markers`);
504
+ }
505
+ const realLeaks = treeComparison.leaks.filter(item => !LIVE_CODEX_STATE.test(`${item.dir}/${item.file}`));
506
+ assert.deepEqual(realLeaks, [], `nothing outside the runtime set and the live codex state may change in the real home: ${JSON.stringify(realLeaks)}`);
507
+ assert.deepEqual(treeComparison.configChanges, [], `no configuration file may change in the real home: ${JSON.stringify(treeComparison.configChanges)}`);
508
+ step('all assertions passed, writing evidence');
509
+
510
+ evidence.push({
511
+ case: 'CAP-008-engine-mode',
512
+ fixture: {
513
+ tag: 'cap008e', fixtureDir: harness.fixture, reposRoot, isolatedHome: harness.homeDir,
514
+ bridgeHome: harness.bridgeHome, consoleUrl: harness.consoleChild.url, engineDataDir, shellDataDir,
515
+ port: Number(harness.base.split(':').pop()), analysisOwner: 'engine',
516
+ },
517
+ identityChain: identityChain(shimPath),
518
+ repos: [
519
+ { side: 'A', path: repoA, basename: path.basename(repoA), projectId: projectA.projectId, workspaceId: projectA.workspaceId, journalId: engineA0.journalId, hookMarker: hookMarkers[projectA.projectId] },
520
+ { side: 'B', path: repoB, basename: path.basename(repoB), projectId: projectB.projectId, workspaceId: projectB.workspaceId, journalId: engineB0.journalId, hookMarker: hookMarkers[projectB.projectId] },
521
+ ],
522
+ markers: { A: markerA, B: markerB },
523
+ wiring: { installRequest: installCall.request, httpStatus: installCall.status, operationId: installCall.response.operationId, shimPath, ownedHookEntries: hooks },
524
+ identityOracle: { A: oracleA.repoIdentity, B: oracleB.repoIdentity },
525
+ defaultOwnerActivation: {
526
+ productOwnership: ownership,
527
+ engineHealthBeforeSessions: { journal: engineHealth.journal, counts: engineHealth.counts },
528
+ engineHealthAfterCommits: { journal: finalHealth.body.journal, counts: finalHealth.body.counts },
529
+ note: 'consumption was switched on by the shell connectEngine -> /api/control activation; the driver never called control and never routed a projectId',
530
+ },
531
+ consoleJournals: journalEvidence,
532
+ sessionCommands,
533
+ commands: commands.map(entry => ({ cwd: entry.cwd, args: entry.args, exitCode: entry.exitCode })),
534
+ engineStoreRecords: {
535
+ A: eventsA.map(event => ({ eventType: event.eventType, role: event.role, sessionId: event.sessionId, journalId: event.journalId, workspaceId: event.repoIdentity && event.repoIdentity.workspaceId, contentHead: String(event.content || '').slice(0, 40) })),
536
+ B: eventsB.map(event => ({ eventType: event.eventType, role: event.role, sessionId: event.sessionId, journalId: event.journalId, workspaceId: event.repoIdentity && event.repoIdentity.workspaceId, contentHead: String(event.content || '').slice(0, 40) })),
537
+ },
538
+ commits: {
539
+ A: { sha: commitA.sha, message: markerA.commit, boundaryFile: path.relative(engineDataDir, boundaryPath(commitA.projectId, commitA.sha)), boundary: boundaryA, runs: runsA },
540
+ B: { sha: commitB.sha, message: markerB.commit, boundaryFile: path.relative(engineDataDir, boundaryPath(commitB.projectId, commitB.sha)), boundary: boundaryB, runs: runsB },
541
+ crossBoundaryAUnderB: fs.existsSync(boundaryPath(commitB.projectId, commitA.sha)),
542
+ crossBoundaryBUnderA: fs.existsSync(boundaryPath(commitA.projectId, commitB.sha)),
543
+ },
544
+ shellLegacyStores: { markerFree: shellGrep.length === 0, hits: shellGrep, note: 'the default consumer is the engine; the shell legacy conversation stores must stay unwritten' },
545
+ engineStoreGrep: { A: hitsA, B: hitsB },
546
+ engineVectorPlane: {
547
+ laneVectorUrl: harness.laneVector.url,
548
+ engineVectorUrl: harness.laneVector.url,
549
+ syncCalls: vectorSyncs,
550
+ indexedProjects: harness.laneVector.state.projects.map(project => project.name),
551
+ note: 'the engine was created with an explicit vectorUrl (the lane-local endpoint implementing the real hub /api/sync contract); its built-in default 127.0.0.1:8787 is a LIVE module on this machine and must never be reached',
552
+ },
553
+ realHomeIsolation: {
554
+ configuration: { byteIdentical: configComparison.byteIdentical, changedFiles: configComparison.changedFiles, changedDirs: configComparison.changedDirs },
555
+ tree: { leaks: treeComparison.leaks, realLeaksBeyondLiveCodexState: realLeaks, configChanges: treeComparison.configChanges, runtimeChangeCount: treeComparison.runtimeChanges },
556
+ concurrentLiveWrites: {
557
+ writes: concurrentLiveWrites,
558
+ proof: 'the live Codex own global-state files were byte-rewritten by an outside process during the window; the new bytes carry none of this case markers, and no command of this lane ever targeted ~/.codex',
559
+ },
560
+ scopeLabel: "honest: the developer's own live client sessions keep writing runtime files while the case runs; the isolation claim is about the client configuration surface and every changed file outside the known runtime set — except the live Codex global-state pair, which is a concurrent outside write proven marker-free",
561
+ },
562
+ scopeLabel: 'honest: the sessions are artificial protocol fixtures fired through the real installed shim (not real model chat); the analysis step is the frozen P-MEMORY-01 stand-in analyzer with an empty plan; the terminal fixture is shared and the vector endpoint is lane-local (a fixture implementing the real hub /api/sync contract — not the vector-hub module); the console, its journals, the shell, the managed hooks and the engine consumption chain are real, and the product ran in its DEFAULT engine-owner mode (never switched to legacy)',
563
+ });
564
+
565
+ if (harness.evidence) {
566
+ fs.mkdirSync(harness.evidence, { recursive: true });
567
+ fs.writeFileSync(path.join(harness.evidence, 'cap008e-engine-mode-cross-workspace-isolation.json'), `${JSON.stringify(evidence, null, 2)}\n`, 'utf8');
568
+ }
569
+
570
+ console.log('parallel-memory-capture-r4-cap008e-probe PASS (same-basename repos at different canonical paths stayed isolated through the DEFAULT engine/Bridge consumption: distinct canonical identities and console journals, engine conversation stores and commit boundaries never crossed sides, and the shell legacy stores stayed unwritten)');
571
+ } finally {
572
+ await harness.cleanup();
573
+ fs.rmSync(reposRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
574
+ }
575
+ }
576
+
577
+ main().catch(error => { console.error(error.stack || error.message); process.exitCode = 1; });