@sanqianx/project-knowledge 5.0.31 → 5.0.33

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 (97) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +11 -0
  3. package/README.md +5 -2
  4. package/_site/_test/automatic-context-test.js +19 -0
  5. package/_site/_test/context-session-index-test.js +244 -0
  6. package/_site/_test/fixtures/retrieval-gold-queries.json +4 -0
  7. package/_site/_test/helpers/parallel-capture-safety-r5-cap-shell.js +1 -1
  8. package/_site/_test/helpers/parallel-capture-safety-r5-memory-shell.js +1 -1
  9. package/_site/_test/helpers/parallel-engine-advanced-engine-child.js +1 -1
  10. package/_site/_test/helpers/parallel-engine-advanced-fault-writer.js +3 -3
  11. package/_site/_test/helpers/parallel-engine-advanced-harness.js +1 -1
  12. package/_site/_test/helpers/parallel-engine-advanced-standin-analyzer.js +1 -1
  13. package/_site/_test/helpers/parallel-engine-final-harness.js +2 -2
  14. package/_site/_test/helpers/parallel-engine-final-standin-analyzer.js +1 -1
  15. package/_site/_test/helpers/parallel-engine-reconcile-r4-harness.js +1 -1
  16. package/_site/_test/helpers/parallel-engine-reconcile-r4-standin-analyzer.js +1 -1
  17. package/_site/_test/helpers/parallel-memory-analyzer.js +1 -1
  18. package/_site/_test/helpers/parallel-memory-capture-r4-cap-shell.js +1 -1
  19. package/_site/_test/helpers/parallel-memory-injection-shell.js +1 -1
  20. package/_site/_test/helpers/parallel-nav-shell.js +1 -1
  21. package/_site/_test/helpers/parallel-qa-engine-endpoint-guard.js +1 -1
  22. package/_site/_test/helpers/parallel-retrieval-followup-r2-shell.js +1 -1
  23. package/_site/_test/helpers/qa-r91-harness.cjs +4 -1
  24. package/_site/_test/package-boundary-test.js +5 -0
  25. package/_site/_test/parallel-capture-safety-r5-cap008e-probe.js +1 -1
  26. package/_site/_test/parallel-engine-advanced-eng011-ui-probe.js +1 -1
  27. package/_site/_test/parallel-knowledge-engine-test.js +3 -3
  28. package/_site/_test/parallel-knowledge-retrieval-test.js +2 -2
  29. package/_site/_test/parallel-memory-capture-r4-cap008e-probe.js +1 -1
  30. package/_site/_test/parallel-memory-injection-origin-probe.js +1 -1
  31. package/_site/_test/parallel-nav-isolation-test.js +1 -1
  32. package/_site/_test/parallel-qa-engine-endpoint-guard-test.js +1 -1
  33. package/_site/_test/parallel-retrieval-followup-citation-test.js +2 -2
  34. package/_site/_test/parallel-retrieval-followup-corpus-test.js +1 -1
  35. package/_site/_test/qa-r45-offline-backfill-test.js +2 -2
  36. package/_site/_test/t07d-git-rel-coverage-test.js +5 -3
  37. package/_site/_test/t07f-mem-008-coverage-test.js +1 -1
  38. package/_site/lib/module-bridge.js +2 -11
  39. package/_site/scripts/ab-rank-v2-v3.js +142 -0
  40. package/_site/scripts/install-module-candidates.js +1 -1
  41. package/_site/scripts/pack-module-candidates.js +2 -1
  42. package/_site/scripts/run-retrieval-gold-isolated.js +221 -0
  43. package/_site/scripts/verify-module-runtime.js +17 -32
  44. package/_site/scripts/verify-product-runtime.js +7 -3
  45. package/_site/scripts/verify-retrieval-gold.js +57 -10
  46. package/docs/README.zh-CN.md +3 -1
  47. package/module-runtime-manifest.json +54 -4
  48. package/package.json +2 -4
  49. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  50. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  51. package/plugins/project-knowledge/.mcp.json +1 -1
  52. package/plugins/project-knowledge/scripts/context-hook.cjs +9 -5
  53. package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +39 -28
  54. package/_modules/knowledge-engine/README.md +0 -133
  55. package/_modules/knowledge-engine/package.json +0 -38
  56. package/_modules/knowledge-engine/src/analysis-contract.js +0 -35
  57. package/_modules/knowledge-engine/src/analysis-failures.js +0 -39
  58. package/_modules/knowledge-engine/src/analysis-output.js +0 -52
  59. package/_modules/knowledge-engine/src/analysis-worker.js +0 -58
  60. package/_modules/knowledge-engine/src/bin.js +0 -52
  61. package/_modules/knowledge-engine/src/bridge-client.js +0 -24
  62. package/_modules/knowledge-engine/src/context.js +0 -140
  63. package/_modules/knowledge-engine/src/coordinator.js +0 -376
  64. package/_modules/knowledge-engine/src/diagnostics.js +0 -37
  65. package/_modules/knowledge-engine/src/headless-analyzer.js +0 -66
  66. package/_modules/knowledge-engine/src/index-request.js +0 -49
  67. package/_modules/knowledge-engine/src/knowledge-targets.js +0 -46
  68. package/_modules/knowledge-engine/src/memories.js +0 -281
  69. package/_modules/knowledge-engine/src/memory-eligibility.js +0 -74
  70. package/_modules/knowledge-engine/src/retrieval-policy.json +0 -14
  71. package/_modules/knowledge-engine/src/retrieval-ranking.js +0 -153
  72. package/_modules/knowledge-engine/src/retrieval.js +0 -367
  73. package/_modules/knowledge-engine/src/runtime/README.md +0 -7
  74. package/_modules/knowledge-engine/src/runtime/atomic-file.js +0 -204
  75. package/_modules/knowledge-engine/src/runtime/automation-config.js +0 -140
  76. package/_modules/knowledge-engine/src/runtime/commit-conversation-binder.js +0 -250
  77. package/_modules/knowledge-engine/src/runtime/commit-processing-ledger.js +0 -26
  78. package/_modules/knowledge-engine/src/runtime/commit-prompt.js +0 -205
  79. package/_modules/knowledge-engine/src/runtime/commit-reconciler.js +0 -432
  80. package/_modules/knowledge-engine/src/runtime/content-hash.js +0 -4
  81. package/_modules/knowledge-engine/src/runtime/contracts.js +0 -282
  82. package/_modules/knowledge-engine/src/runtime/conversation-exclusions.js +0 -204
  83. package/_modules/knowledge-engine/src/runtime/conversation-store.js +0 -389
  84. package/_modules/knowledge-engine/src/runtime/evidence-bundle.js +0 -228
  85. package/_modules/knowledge-engine/src/runtime/git-runner.js +0 -62
  86. package/_modules/knowledge-engine/src/runtime/knowledge-promotion.js +0 -559
  87. package/_modules/knowledge-engine/src/runtime/knowledge-retrieval-service.js +0 -408
  88. package/_modules/knowledge-engine/src/runtime/layout.js +0 -46
  89. package/_modules/knowledge-engine/src/runtime/markdown-knowledge-indexer.js +0 -276
  90. package/_modules/knowledge-engine/src/runtime/scanner.js +0 -298
  91. package/_modules/knowledge-engine/src/server.js +0 -166
  92. package/_modules/knowledge-engine/src/store.js +0 -267
  93. package/_modules/knowledge-engine/ui/app.css +0 -172
  94. package/_modules/knowledge-engine/ui/app.js +0 -318
  95. package/_modules/knowledge-engine/ui/index.html +0 -95
  96. package/_site/scripts/vendor-modules.js +0 -49
  97. package/vendor-manifest.json +0 -55
@@ -9,7 +9,7 @@
9
9
  "plugins": [
10
10
  {
11
11
  "name": "project-knowledge",
12
- "version": "5.0.31",
12
+ "version": "5.0.33",
13
13
  "source": "./plugins/project-knowledge",
14
14
  "description": "Search durable project decisions and implementation history through MCP."
15
15
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.0.33] - 2026-11-11
4
+
5
+ - 知识注入改为会话一次索引(对齐 ZCode memory 的"索引+懒加载"模式):会话首条用户消息注入一次紧凑索引(适用已确认记忆全文 + 知识条目标题清单 + 仲裁声明),正文摘录不再进入注入层;后续消息默认静默,新增/变更的记忆全文重注入一次,删除的记忆发一行移除提示,相关问题对强命中条目(实词/身份/已校准向量命中,仅 bigram 撞词不触发)给一行面包屑并在 10 轮内冷却,超过 30 轮重发仅标题索引对冲上下文压缩。30 轮会话累计注入从旧设计的 ~90KB+ 降至 ≤10KB。
6
+ - 引擎升级至 `@sanqianx/ai-coding-knowledge-engine@0.2.8`(ranking-v3:词锚/字节对锚分离、listTitles、注入预算进 retrieval-policy);`context-hook` 空结果完全静默、降级提示只走 systemMessage,receipt 日志新增 `injectionKind`/`sessionIndexedCount`;响应契约向后兼容(status 枚举与必选字段不变)。
7
+ - 检索质量金标准新增 breadcrumb-gating 用例(正例强匹配出面包屑并冷却、负例零注入)与隔离运行器 `run-retrieval-gold-isolated.js`(自起真实 vector-hub 与引擎、语料只读副本、独立 VECTOR_HUB_CONFIG 防止继承用户全局 watcher);新增 `context-session-index-test.js` 端到端回归(跨项目诱饵零面包屑、30 轮累计注入量化断言)。
8
+
9
+ ## [5.0.32] - 2026-11-10
10
+
11
+ - 将 knowledge-engine 改为固定版本的公开 npm 依赖 `@sanqianx/ai-coding-knowledge-engine@0.2.7-rc.12`,从主仓库移除内置引擎源码和旧 vendoring 脚本;保留历史提交及现有 npm 版本。
12
+ - 四个模块统一进行安装版本与运行文件哈希验证,更新包边界、候选安装和回归工具;安装和运行无需访问模块的私有 GitHub 仓库。
13
+
3
14
  ## [5.0.31] - 2026-11-09
4
15
 
5
16
  - 新增外观与皮肤:预设主题与浅色/深色两套自定义颜色(`#RRGGBB` 白名单校验),改动即时预览、保存后对本机所有入口生效;支持 `kb-skin/v1` 皮肤文件的导出与导入,服务未就绪时保持默认皮肤不阻塞启动。
package/README.md CHANGED
@@ -20,7 +20,10 @@ project-knowledge
20
20
  ```
21
21
 
22
22
  1. `npm install -g @sanqianx/project-knowledge@latest` installs the shell,
23
- three pinned module dependencies and the bundled knowledge-engine.
23
+ four pinned npm module dependencies, including knowledge-engine.
24
+ Module source repositories may be private; installation uses public npm
25
+ packages and needs no GitHub credentials. Engine source is maintained in its
26
+ own repository rather than copied into this shell.
24
27
  2. `project-knowledge-integrations install` is the one-time Integration Setup.
25
28
  For every detected client (Claude Code / Codex / OpenCode) it installs two
26
29
  independent capabilities, reported separately:
@@ -316,7 +319,7 @@ _site/lib/knowledge-tool-runtime.js
316
319
  _site/scripts/hook-trigger.js
317
320
  ui/index.html # unified production web UI
318
321
  ui/product.js, ui/product.css # shell navigation and state projection
319
- _modules/knowledge-engine/ # verified dependency-free engine
322
+ node_modules/@sanqianx/ai-coding-knowledge-engine/ # pinned npm runtime (not tracked)
320
323
  bin/project-knowledge*.js # CLI and MCP entry points
321
324
  desktop/ # Windows Electron package
322
325
  ```
@@ -27,6 +27,25 @@ async function main() {
27
27
  await writeOutput(output, { write: (text, callback) => { assert.ok(!text.includes('receipt')); callback(); } });
28
28
  const logDir = path.join(root, 'logs/projects/project-a'); const logText = fs.readFileSync(path.join(logDir, fs.readdirSync(logDir)[0]), 'utf8');
29
29
  assert.ok(!logText.includes(payload.prompt)); assert.ok(!logText.includes('revision 37')); assert.ok(logText.includes('agent.context.output'));
30
+ // Session-index contract: empty turns are fully silent, degraded notices
31
+ // stay user-facing, injectionKind rides along to the receipt log.
32
+ const engineResponse = body => async (url, options) => {
33
+ if (String(url).endsWith('/identity')) return Response.json(identity);
34
+ const input = JSON.parse(options.body);
35
+ return Response.json({ ok: true, requestId: input.requestId, projectId: 'project-a', memoryStatus: 'ready', ...body });
36
+ };
37
+ const silent = await run(payload, { env, fetchImpl: engineResponse({ status: 'empty', prompt: '', facts: [], memories: [], references: [] }) });
38
+ assert.deepEqual(silent, {}, 'empty turns inject nothing at all');
39
+ const degraded = await run(payload, { env, fetchImpl: engineResponse({ status: 'file-fallback', prompt: '', facts: [], memories: [], references: [] }) });
40
+ assert.match(degraded.systemMessage, /向量检索暂不可用/);
41
+ assert.ok(!degraded.hookSpecificOutput, 'degraded notices never enter the model context');
42
+ const indexed = await run(payload, { env, fetchImpl: engineResponse({ status: 'ready', injectionKind: 'index', sessionIndexedCount: 7, prompt: '<knowledge_context>session index</knowledge_context>', facts: [{}, {}], memories: [], references: [{}, {}] }) });
43
+ assert.match(indexed.hookSpecificOutput.additionalContext, /session index/);
44
+ assert.equal(indexed.receipt.injectionKind, 'index'); assert.equal(indexed.receipt.sessionIndexedCount, 7);
45
+ await writeOutput(indexed, { write: (text, callback) => callback() });
46
+ assert.ok(fs.readFileSync(path.join(logDir, fs.readdirSync(logDir)[0]), 'utf8').includes('"injectionKind":"index"'), 'the receipt log carries the injection kind');
47
+ const oversized = await run(payload, { env, fetchImpl: engineResponse({ status: 'ready', prompt: 'x'.repeat(8001), facts: [], memories: [], references: [] }) });
48
+ assert.match(oversized.systemMessage, /CONTEXT_INVALID_RESPONSE/);
30
49
  calls.length = 0;
31
50
  assert.deepEqual(await run(payload, { env: { ...env, KB_KNOWLEDGE_CONTEXT: '0' }, fetchImpl }), {}); assert.equal(calls.length, 0);
32
51
  assert.deepEqual(await run({ ...payload, hook_event_name: 'Stop' }, { env, fetchImpl }), {});
@@ -0,0 +1,244 @@
1
+ 'use strict';
2
+ // CTX-SI: the knowledge context injection follows the ZCode-memory session
3
+ // model instead of re-sending a full pack on every user message.
4
+ //
5
+ // The case drives the real engine through the product shell route that the
6
+ // UserPromptSubmit hook itself uses (/api/engine/context), with the vector hub
7
+ // fixture answering 503 so the lexical channel is the one under test.
8
+ //
9
+ // Expectations:
10
+ // 1. the first turn of a session injects the statement block, applicable
11
+ // memories and a TITLE-ONLY index once - never body text;
12
+ // 2. later turns stay silent unless something changed;
13
+ // 3. boundary-bigram collisions from same-domain neighbour projects (the
14
+ // "外推算法/RpcTransportSDK inside a memory-system question" class of
15
+ // false positives) never produce a breadcrumb, while a real word match
16
+ // earns a one-line pointer that then cools down;
17
+ // 4. a memory added mid-session is re-sent in full exactly once, and a
18
+ // deletion is announced exactly once;
19
+ // 5. across a simulated 30-turn session the cumulative injection stays an
20
+ // order of magnitude below the previous per-turn 8000-char design.
21
+
22
+ const assert = require('node:assert/strict');
23
+ const crypto = require('node:crypto');
24
+ const fs = require('node:fs');
25
+ const path = require('node:path');
26
+ const { spawnSync } = require('node:child_process');
27
+ const { spawnServer } = require('./helpers/spawn-server');
28
+ const { createModuleFixture, createUpstreamProxy } = require('./helpers/module-fixture');
29
+ const freePort = require('./helpers/free-port');
30
+ const { applyDriverIsolation } = require('./helpers/parallel-qa-engine-endpoint-isolate');
31
+ const { guardedCreateEngineServer } = require('./helpers/parallel-qa-engine-endpoint-guard');
32
+
33
+ const ROOT = path.resolve(__dirname, '../..');
34
+
35
+ function git(cwd, args) {
36
+ const result = spawnSync('git', ['-C', cwd, ...args], { encoding: 'utf8', windowsHide: true, env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } });
37
+ assert.equal(result.status, 0, `git ${args.join(' ')} failed: ${result.stderr}`);
38
+ return String(result.stdout || '').trim();
39
+ }
40
+
41
+ function makeRepo(root, name) {
42
+ const repo = path.join(root, name);
43
+ fs.mkdirSync(repo, { recursive: true });
44
+ git(repo, ['init', '-q', '-b', 'main']);
45
+ git(repo, ['config', 'user.email', 'session-index@local.invalid']);
46
+ git(repo, ['config', 'user.name', 'Session Index Regression']);
47
+ fs.writeFileSync(path.join(repo, 'README.md'), `# ${name}\n`);
48
+ git(repo, ['add', '.']); git(repo, ['commit', '-qm', 'baseline']);
49
+ return repo;
50
+ }
51
+
52
+ async function waitForHealth(base, timeoutMs = 20000) {
53
+ const deadline = Date.now() + timeoutMs;
54
+ while (Date.now() < deadline) {
55
+ try {
56
+ const response = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(2000) });
57
+ if (response.ok) return;
58
+ } catch {}
59
+ await new Promise(resolve => setTimeout(resolve, 100));
60
+ }
61
+ throw new Error('Timed out waiting for the isolated server on ' + base);
62
+ }
63
+
64
+ async function main() {
65
+ // Driver isolation FIRST: the environment is rebuilt from a system whitelist
66
+ // with every product surface pointed at a per-run layout, before any product
67
+ // module is required.
68
+ const applied = applyDriverIsolation({ prefix: 'pk-qa-ctx-session' });
69
+ const fixture = fs.mkdtempSync(path.join(applied.layout.temp, 'pk-ctx-session-'));
70
+ const dataDir = path.join(fixture, 'data');
71
+ const knowledgeRoot = path.join(fixture, 'knowledge');
72
+ const repoA = makeRepo(fixture, 'repo-memory-system');
73
+ const repoC = makeRepo(fixture, 'repo-rpc-transport');
74
+ const knowledgeA = path.join(knowledgeRoot, '记忆系统项目');
75
+ const knowledgeC = path.join(knowledgeRoot, '轮转调度项目');
76
+ fs.mkdirSync(knowledgeA, { recursive: true }); fs.mkdirSync(knowledgeC, { recursive: true });
77
+
78
+ const engineToken = crypto.randomBytes(24).toString('hex');
79
+ const terminal = createModuleFixture({ kind: 'terminal' });
80
+ const vectorHub = createModuleFixture({ kind: 'vectorHub' });
81
+ const eventBridge = createModuleFixture({ kind: 'eventBridge' });
82
+ for (const fixtureService of [terminal, vectorHub, eventBridge]) {
83
+ await fixtureService.start();
84
+ fixtureService.setOnline(false);
85
+ }
86
+ const engine = guardedCreateEngineServer({ dataDir: path.join(fixture, 'engine'), runtimeToken: engineToken, debug: true, consume: false, vectorUrl: vectorHub.url, bridgeUrl: eventBridge.url });
87
+ await engine.ready;
88
+ await new Promise(resolve => engine.server.listen(0, '127.0.0.1', resolve));
89
+ const engineUrl = `http://127.0.0.1:${engine.server.address().port}`;
90
+ const engineProxy = createUpstreamProxy({ target: engineUrl, token: engineToken, tag: 'engine' });
91
+ await engineProxy.start();
92
+
93
+ const port = await freePort();
94
+ const base = `http://127.0.0.1:${port}`;
95
+ const server = spawnServer({
96
+ root: ROOT,
97
+ port,
98
+ dataDir,
99
+ tag: 'context-session-index',
100
+ analysisOwner: 'engine',
101
+ extraEnv: {
102
+ KB_MODULES_REGISTER: '1',
103
+ KB_MODULES_AUTOSTART: '0',
104
+ KB_KNOWLEDGE_ENGINE_URL: engineProxy.url,
105
+ KB_TERMINAL_URL: terminal.url,
106
+ KB_VECTORHUB_URL: vectorHub.url,
107
+ KB_EVENTBRIDGE_URL: eventBridge.url,
108
+ },
109
+ });
110
+ const api = async (method, route, body) => {
111
+ const response = await fetch(base + route, {
112
+ method,
113
+ headers: body === undefined ? undefined : { 'Content-Type': 'application/json' },
114
+ body: body === undefined ? undefined : JSON.stringify(body),
115
+ signal: AbortSignal.timeout(20000),
116
+ });
117
+ return { status: response.status, body: await response.json() };
118
+ };
119
+ const engineApi = async (method, route, body) => {
120
+ const response = await fetch(engineUrl + route, {
121
+ method,
122
+ headers: body === undefined ? undefined : { 'Content-Type': 'application/json' },
123
+ body: body === undefined ? undefined : JSON.stringify(body),
124
+ signal: AbortSignal.timeout(20000),
125
+ });
126
+ return { status: response.status, body: await response.json() };
127
+ };
128
+ let turnSeq = 0;
129
+ const context = async (query, sessionId, repoPath = repoA) => {
130
+ turnSeq += 1;
131
+ const result = await api('POST', '/api/engine/context', { repoPath, query, client: 'zcode', sessionId, requestId: `ctx-e2e-${turnSeq}` });
132
+ assert.equal(result.status, 200, JSON.stringify(result.body));
133
+ return result.body;
134
+ };
135
+
136
+ try {
137
+ await waitForHealth(base);
138
+ assert.equal((await api('PATCH', '/api/settings', { knowledge: { rootPath: knowledgeRoot } })).status, 200);
139
+ const domain = (await api('POST', '/api/domains', { name: '会话领域' })).body.domain;
140
+ assert.ok(domain && domain.id, 'the domain exists for both projects');
141
+
142
+ const importedA = await api('POST', '/api/projects/import', { localPath: repoA, knowledgePath: knowledgeA, displayName: '记忆系统项目', domainId: domain.id });
143
+ assert.equal(importedA.status, 201, JSON.stringify(importedA.body));
144
+ const projectA = importedA.body.projectId;
145
+ const importedC = await api('POST', '/api/projects/import', { localPath: repoC, knowledgePath: knowledgeC, displayName: '轮转调度项目', domainId: domain.id });
146
+ assert.equal(importedC.status, 201, JSON.stringify(importedC.body));
147
+ const projectC = importedC.body.projectId;
148
+ assert.notEqual(projectA, projectC, 'the decoy lives in a different project of the same domain');
149
+
150
+ // The current project owns memory-system knowledge; the neighbour owns the
151
+ // two decoys from the original complaint plus a boundary-bigram trap.
152
+ fs.mkdirSync(path.join(knowledgeA, 'modules'), { recursive: true });
153
+ fs.mkdirSync(path.join(knowledgeA, 'changes'), { recursive: true });
154
+ fs.writeFileSync(path.join(knowledgeA, 'README.md'), '# 记忆系统项目说明\n\n导出需要 schemaRevision 37。KB-INDEX-SECRET-A 导出契约正文。\n');
155
+ fs.writeFileSync(path.join(knowledgeA, 'modules', 'context.md'), '# 记忆注入机制\n\n会话首条消息注入一次索引,正文经 MCP 按需读取。KB-INDEX-SECRET-B 记忆注入机制正文。\n');
156
+ fs.writeFileSync(path.join(knowledgeA, 'changes', 'change.md'), '# 最近一次注入改造\n\n已完成会话索引改造。KB-INDEX-SECRET-C\n');
157
+ fs.mkdirSync(path.join(knowledgeC, 'modules'), { recursive: true });
158
+ fs.mkdirSync(path.join(knowledgeC, 'changes'), { recursive: true });
159
+ fs.writeFileSync(path.join(knowledgeC, 'modules', 'rpc.md'), '# RpcTransportSDK lane 轮转规则\n\n恢复导出配置的九步流程与并发调度。KB-INDEX-SECRET-D\n');
160
+ fs.writeFileSync(path.join(knowledgeC, 'changes', 'extrapolation.md'), '# 外推算法九步流程\n\n外推算法按九步执行并记录证据。KB-INDEX-SECRET-E\n');
161
+
162
+ // 1. The first turn injects the index once: statement block, no body text.
163
+ const first = await context('开始设计记忆系统的注入机制', 'sess-main');
164
+ assert.equal(first.status, 'ready'); assert.equal(first.injectionKind, 'index');
165
+ assert.equal(first.rankingVersion, 'project-knowledge/ranking-v3');
166
+ assert.ok(first.facts.some(item => item.entryId === 'modules/context.md' && item.role === '本项目事实'), 'the index lists the memory-system module');
167
+ assert.ok(first.facts.every(item => !('text' in item)), 'index facts never carry body text');
168
+ assert.ok(first.prompt.includes('modules/context.md'));
169
+ assert.equal((first.prompt.match(/当前生效的已确认记忆只来自 memories/g) || []).length, 1);
170
+ assert.ok(first.prompt.length <= 3000, `index stays compact, got ${first.prompt.length}`);
171
+ assert.ok(first.sessionIndexedCount >= 2, 'the session registry counts its titles');
172
+ for (const secret of ['KB-INDEX-SECRET-A', 'KB-INDEX-SECRET-B', 'KB-INDEX-SECRET-C', 'KB-INDEX-SECRET-D', 'KB-INDEX-SECRET-E']) {
173
+ assert.ok(!first.prompt.includes(secret), 'no knowledge body ever enters the injection layer');
174
+ }
175
+
176
+ // 2. A later turn without changes or strong matches is fully silent. With
177
+ // the vector fixture offline the turn reports file-fallback (a
178
+ // user-facing notice), which must still inject nothing.
179
+ const quiet = await context('顺便聊聊天气', 'sess-main');
180
+ assert.ok(quiet.status !== 'ready', 'nothing was injected');
181
+ assert.equal(quiet.prompt, '');
182
+ assert.equal(quiet.injectionKind, undefined); assert.equal(quiet.facts.length, 0);
183
+
184
+ // 3. Boundary-bigram decoys stay silent even though search admits them.
185
+ const decoyQuery = '修复导入功能的报错';
186
+ const admitted = await api('POST', '/api/knowledge/search', { projectId: projectA, query: decoyQuery, scope: 'domain' });
187
+ assert.equal(admitted.status, 200, JSON.stringify(admitted.body));
188
+ assert.ok((admitted.body.results || []).some(row => row.path === 'modules/rpc.md'), 'the lexical channel still admits the decoy entry');
189
+ const decoyTurn = await context(decoyQuery, 'sess-main');
190
+ assert.equal(decoyTurn.prompt, '', 'a boundary-bigram collision never becomes a breadcrumb');
191
+
192
+ // 4. A real word match earns a one-line breadcrumb, then cools down.
193
+ const strongQuery = '记忆注入机制是怎么设计的';
194
+ const crumb = await context(strongQuery, 'sess-main');
195
+ assert.equal(crumb.injectionKind, 'breadcrumb');
196
+ assert.ok(crumb.facts.some(item => item.entryId === 'modules/context.md'), 'the breadcrumb points at the matching entry');
197
+ assert.ok(!crumb.facts.some(item => String(item.entryId).includes('rpc') || String(item.entryId).includes('extrapolation')), 'the decoys never appear');
198
+ assert.ok(crumb.prompt.includes('modules/context.md')); assert.ok(!crumb.prompt.includes('KB-INDEX-SECRET-B'));
199
+ assert.ok(!crumb.prompt.includes('当前生效的已确认记忆只来自'), 'deltas never repeat the statement block');
200
+ assert.equal((await context(strongQuery, 'sess-main')).prompt, '', 'the same entry is on cooldown');
201
+
202
+ // 5. A memory added mid-session is re-sent in full exactly once.
203
+ const brainScope = (await engineApi('GET', '/api/snapshot?summary=1&limit=1')).body.sharedScopes.find(scope => scope.kind === 'brain');
204
+ assert.ok(brainScope, 'the brain scope exists');
205
+ const created = await engineApi('POST', '/api/memories', { text: '本仓库必须保持中文提交信息', scopeType: 'project', scopeId: projectA, brainId: brainScope.brainId });
206
+ assert.equal(created.status, 200, JSON.stringify(created.body));
207
+ const memoryId = created.body.memory.id;
208
+ const memoryTurn = await context('继续做别的', 'sess-main');
209
+ assert.equal(memoryTurn.injectionKind, 'memory-delta'); assert.equal(memoryTurn.memories.length, 1);
210
+ assert.equal(memoryTurn.memories[0].memoryId, memoryId);
211
+ assert.ok(memoryTurn.prompt.includes('本仓库必须保持中文提交信息'));
212
+ assert.equal((await context('继续做别的', 'sess-main')).prompt, '', 'an unchanged memory never repeats');
213
+ const deleted = await engineApi('DELETE', `/api/memories/${encodeURIComponent(memoryId)}`);
214
+ assert.equal(deleted.status, 200, JSON.stringify(deleted.body));
215
+ const removalTurn = await context('继续做别的', 'sess-main');
216
+ assert.ok(removalTurn.prompt.includes('记忆已移除'), 'a deletion is announced instead of silently vanishing');
217
+ assert.equal((await context('继续做别的', 'sess-main')).prompt, '', 'the removal notice fires once');
218
+
219
+ // 6. Thirty simulated turns stay an order of magnitude below the old
220
+ // per-turn 8000-char design (which accumulated ~90KB+ over 30 turns).
221
+ let cumulative = 0;
222
+ for (let turn = 1; turn <= 30; turn++) {
223
+ const query = turn === 1 ? '开始设计记忆系统的注入机制'
224
+ : turn % 5 === 0 ? '记忆注入机制还有哪些细节'
225
+ : turn % 7 === 0 ? '修复导入功能的报错'
226
+ : `随便记录一下第${turn}轮的进展`;
227
+ const result = await context(query, 'sess-30');
228
+ cumulative += (result.prompt || '').length;
229
+ assert.ok((result.prompt || '').length <= 8000, 'the hard contract never breaks');
230
+ assert.ok(!(result.prompt || '').includes('KB-INDEX-SECRET-'), 'no turn ever leaks a body');
231
+ }
232
+ assert.ok(cumulative <= 10240, `30 turns inject at most 10KB in total, got ${cumulative}`);
233
+
234
+ console.log('context-session-index-test PASS (one index per session, silent turns, gated breadcrumbs, once-only memory deltas, 30-turn cumulative injection bounded)');
235
+ } finally {
236
+ await server.cleanup();
237
+ await engine.close().catch(() => {});
238
+ await engineProxy.close();
239
+ for (const fixtureService of [terminal, vectorHub, eventBridge]) await fixtureService.close();
240
+ fs.rmSync(fixture, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
241
+ }
242
+ }
243
+
244
+ main().catch(error => { console.error(error.stack || error.message); process.exitCode = 1; });
@@ -1,5 +1,9 @@
1
1
  [
2
2
  {"id":"S01","kind":"semantic","project":"product","query":"默认监听地址被别的程序占用后,模块如何避让并确认服务身份?","entry":"changes/c4afa63fa1ca.md","fact":"dynamic"},
3
+ {"id":"B01","kind":"breadcrumb","project":"product","query":"默认监听地址被别的程序占用后,模块如何避让并确认服务身份?","expect":"changes/c4afa63fa1ca.md"},
4
+ {"id":"B02","kind":"breadcrumb","project":"workbench","query":"相同项目的嵌入消息反复到达,为何不应作废正在创建的会话?","expect":"changes/29e2cf932e08.md"},
5
+ {"id":"B03","kind":"breadcrumb","project":"product","query":"当前项目 PostgreSQL 主从故障切换与 WAL 归档策略是什么?"},
6
+ {"id":"B04","kind":"breadcrumb","project":"workbench","query":"当前项目 ElasticSearch 搜索集群如何备份?"},
3
7
  {"id":"S02","kind":"semantic","project":"product","query":"桌面窗口怎样复用网页后台并在退出时处理自己启动的进程?","entry":"changes/6ea83d5c4e59.md","fact":"后台"},
4
8
  {"id":"S03","kind":"semantic","project":"product","query":"客户端检测尚未结束时,为什么不能记录用户已移除接入?","entry":"changes/155e3bf3bb5f.md","fact":"扫描"},
5
9
  {"id":"S04","kind":"semantic","project":"product","query":"外部开发工具的接入开关怎样记住用户选择并在启动时修复?","entry":"changes/b2da6dd5d6fd.md","fact":"意图"},
@@ -64,7 +64,7 @@ const freePort = require('../helpers/free-port');
64
64
  const { createMemoryStandinAnalyzer } = require('./parallel-memory-analyzer');
65
65
 
66
66
  const ROOT = r3cap.ROOT;
67
- const ENGINE_ENTRY = path.join(ROOT, '_modules', 'knowledge-engine', 'src', 'server.js');
67
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(ROOT)] })), 'src', 'server.js');
68
68
  const CONSOLE_ENTRY = path.join(ROOT, 'node_modules', '@sanqianx', 'ai-coding-event-bridge-console', 'src', 'bin.js');
69
69
  const { resolveTempRoot, withSanitizedEnv } = r3cap;
70
70
 
@@ -48,7 +48,7 @@ const { createEventBridgeStandin } = require('./parallel-memory-event-bridge');
48
48
  const { startLaneVectorHub } = require('./parallel-capture-safety-r5-cap-shell');
49
49
 
50
50
  const ROOT = path.resolve(__dirname, '../../..');
51
- const ENGINE_ENTRY = path.join(ROOT, '_modules', 'knowledge-engine', 'src', 'server.js');
51
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(ROOT)] })), 'src', 'server.js');
52
52
  const LIVE_PORTS = new Set([5757, 5790, 8787, 8790]);
53
53
 
54
54
  function isInside(candidate, parent) {
@@ -7,7 +7,7 @@
7
7
  // The analyzer is the lane's declarative stand-in - real staged bytes, no real
8
8
  // model output. Vendored engine code is never modified.
9
9
 
10
- const { createEngineServer } = require('../../../_modules/knowledge-engine/src/server.js');
10
+ const { createEngineServer } = require('@sanqianx/ai-coding-knowledge-engine/src/server.js');
11
11
  const { createStandinAnalyzer } = require('./parallel-engine-advanced-standin-analyzer.js');
12
12
 
13
13
  async function main() {
@@ -22,9 +22,9 @@
22
22
  const fs = require('node:fs');
23
23
  const path = require('node:path');
24
24
  const crypto = require('node:crypto');
25
- const { RuntimeLayout } = require('../../../_modules/knowledge-engine/src/runtime/layout.js');
26
- const { KnowledgePromotionService } = require('../../../_modules/knowledge-engine/src/runtime/knowledge-promotion.js');
27
- const AtomicFile = require('../../../_modules/knowledge-engine/src/runtime/atomic-file.js');
25
+ const { RuntimeLayout } = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/layout.js');
26
+ const { KnowledgePromotionService } = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/knowledge-promotion.js');
27
+ const AtomicFile = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/atomic-file.js');
28
28
 
29
29
  const PROJECT_ID = 'project-eng009-fault';
30
30
  const COMMIT_SHA = 'a'.repeat(40); // fixture identity; not a real repo commit - promotion only needs claim identity + hashes
@@ -19,7 +19,7 @@ const os = require('node:os');
19
19
  const path = require('node:path');
20
20
 
21
21
  const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
22
- const VENDORED_ENGINE_SERVER = path.join(REPO_ROOT, '_modules', 'knowledge-engine', 'src', 'server.js');
22
+ const VENDORED_ENGINE_SERVER = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(REPO_ROOT)] })), 'src', 'server.js');
23
23
  const ENGINE_CHILD = path.join(__dirname, 'parallel-engine-advanced-engine-child.js');
24
24
 
25
25
  // Temp root: PK_TEST_TEMP_ROOT or the OS temp dir; never inside the repository.
@@ -23,7 +23,7 @@
23
23
  const fs = require('node:fs');
24
24
  const path = require('node:path');
25
25
  const crypto = require('node:crypto');
26
- const AtomicFile = require('../../../_modules/knowledge-engine/src/runtime/atomic-file.js');
26
+ const AtomicFile = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/atomic-file.js');
27
27
 
28
28
  function hashBuffer(value) {
29
29
  return `sha256:${crypto.createHash('sha256').update(value).digest('hex')}`;
@@ -31,8 +31,8 @@ const os = require('node:os');
31
31
  const path = require('node:path');
32
32
 
33
33
  const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
34
- const VENDORED_ENGINE_SERVER = path.join(REPO_ROOT, '_modules', 'knowledge-engine', 'src', 'server.js');
35
- const VENDORED_ATOMIC_FILE = path.join(REPO_ROOT, '_modules', 'knowledge-engine', 'src', 'runtime', 'atomic-file.js');
34
+ const VENDORED_ENGINE_SERVER = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(REPO_ROOT)] })), 'src', 'server.js');
35
+ const VENDORED_ATOMIC_FILE = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(REPO_ROOT)] })), 'src', 'runtime', 'atomic-file.js');
36
36
 
37
37
  // Pinned runtime by default: the root repo's installed
38
38
  // versions declared by the root package (identity-checked below), so the drivers are portable to any checkout of this
@@ -82,7 +82,7 @@ function createStandinAnalyzer(options = {}) {
82
82
  if (delegatedQuote) lines.push(`维护指令:${delegatedQuote}`, '');
83
83
  const markdown = lines.join('\n');
84
84
 
85
- const AtomicFile = require('../../../_modules/knowledge-engine/src/runtime/atomic-file.js');
85
+ const AtomicFile = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/atomic-file.js');
86
86
  AtomicFile.writeFileAtomic(path.join(input.stagingPath, 'files', ...filename.split('/')), markdown);
87
87
 
88
88
  const references = [
@@ -36,7 +36,7 @@ const path = require('node:path');
36
36
  const crypto = require('node:crypto');
37
37
 
38
38
  const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
39
- const VENDORED_ENGINE_ROOT = path.join(REPO_ROOT, '_modules', 'knowledge-engine');
39
+ const VENDORED_ENGINE_ROOT = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(REPO_ROOT)] })));
40
40
  const VENDORED_ENGINE_VERSION = '0.2.7-rc.10';
41
41
 
42
42
  function resolveRuntimeRoot(envVar, pinnedDir, pinnedVersion) {
@@ -47,7 +47,7 @@ function createStandinAnalyzer(options = {}) {
47
47
 
48
48
  const atomicFilePath = engineRoot
49
49
  ? path.join(engineRoot, 'src', 'runtime', 'atomic-file.js')
50
- : path.join(__dirname, '..', '..', '..', '_modules', 'knowledge-engine', 'src', 'runtime', 'atomic-file.js');
50
+ : path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(__dirname, '..', '..', '..')] })), 'src', 'runtime', 'atomic-file.js');
51
51
  const AtomicFile = require(atomicFilePath);
52
52
  AtomicFile.writeFileAtomic(path.join(input.stagingPath, 'files', ...filename.split('/')), markdown);
53
53
 
@@ -20,7 +20,7 @@
20
20
 
21
21
  const path = require('node:path');
22
22
  const crypto = require('node:crypto');
23
- const AtomicFile = require('../../../_modules/knowledge-engine/src/runtime/atomic-file.js');
23
+ const AtomicFile = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/atomic-file.js');
24
24
 
25
25
  /**
26
26
  * A long enough sentence that the engine's own capture gate accepts it as a
@@ -49,7 +49,7 @@ const freePort = require('../helpers/free-port');
49
49
  const { createMemoryStandinAnalyzer } = require('./parallel-memory-analyzer');
50
50
 
51
51
  const ROOT = r3cap.ROOT;
52
- const ENGINE_ENTRY = path.join(ROOT, '_modules', 'knowledge-engine', 'src', 'server.js');
52
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(ROOT)] })), 'src', 'server.js');
53
53
  const CONSOLE_ENTRY = path.join(ROOT, 'node_modules', '@sanqianx', 'ai-coding-event-bridge-console', 'src', 'bin.js');
54
54
  const { resolveTempRoot, withSanitizedEnv } = r3cap;
55
55
 
@@ -37,7 +37,7 @@ const crypto = require('node:crypto');
37
37
  const { spawn, execFileSync } = require('node:child_process');
38
38
 
39
39
  const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
40
- const ENGINE_ENTRY = path.join(REPO_ROOT, '_modules', 'knowledge-engine', 'src', 'server.js');
40
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(REPO_ROOT)] })), 'src', 'server.js');
41
41
  const BRIDGE_CONSOLE_ENTRY = path.join(REPO_ROOT, 'node_modules', '@sanqianx', 'ai-coding-event-bridge-console', 'src', 'server.js');
42
42
  const BRIDGE_REPO_CONTEXT = path.join(REPO_ROOT, 'node_modules', '@sanqianx', 'ai-coding-event-bridge-console', 'src', 'bridge', 'core', 'repo-context.js');
43
43
 
@@ -36,7 +36,7 @@ const { enterNavIsolation } = require('./parallel-nav-isolation-env');
36
36
  const freePort = require('../helpers/free-port');
37
37
 
38
38
  const ROOT = path.resolve(__dirname, '../../..');
39
- const ENGINE_ENTRY = path.join(ROOT, '_modules', 'knowledge-engine', 'src', 'server.js');
39
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(ROOT)] })), 'src', 'server.js');
40
40
 
41
41
  const THEMES = ['light', 'dark'];
42
42
 
@@ -43,7 +43,7 @@ const { PROTECTED_PORTS } = require('./parallel-qa-engine-endpoint-isolate');
43
43
 
44
44
  const REFUSAL_CODE = 'PK_ENGINE_ENDPOINT_REFUSED';
45
45
  const EGRESS_BLOCK_CODE = 'PK_PROTECTED_EGRESS_BLOCKED';
46
- const ENGINE_SERVER_MODULE = path.resolve(__dirname, '..', '..', '..', '_modules', 'knowledge-engine', 'src', 'server.js');
46
+ const ENGINE_SERVER_MODULE = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.resolve(__dirname, '..', '..', '..')] })), 'src', 'server.js');
47
47
 
48
48
  function refusal(message, extra = {}) {
49
49
  return Object.assign(new Error(message), { code: REFUSAL_CODE, ...extra });
@@ -44,7 +44,7 @@ const { spawn, execFileSync } = require('node:child_process');
44
44
  const chain = require('./parallel-retrieval-followup-shell');
45
45
 
46
46
  const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
47
- const ENGINE_ENTRY = path.join(REPO_ROOT, '_modules', 'knowledge-engine', 'src', 'server.js');
47
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(REPO_ROOT)] })), 'src', 'server.js');
48
48
  const BRIDGE_CONSOLE_ENTRY = path.join(REPO_ROOT, 'node_modules', '@sanqianx', 'ai-coding-event-bridge-console', 'src', 'server.js');
49
49
  const BRIDGE_REPO_CONTEXT = path.join(REPO_ROOT, 'node_modules', '@sanqianx', 'ai-coding-event-bridge-console', 'src', 'bridge', 'core', 'repo-context.js');
50
50
 
@@ -120,7 +120,10 @@ function resolveProductRoot(candidate) {
120
120
  if (!packageJson || typeof packageJson.name !== 'string' || !packageJson.name || typeof packageJson.version !== 'string' || !packageJson.version) {
121
121
  throw invalidProductRoot('INVALID_PACKAGE', `package.json must carry name and version, got ${JSON.stringify({ name: packageJson && packageJson.name, version: packageJson && packageJson.version })}`);
122
122
  }
123
- return { root, packageJson, siteEntry, engineRoot: path.join(root, '_modules', 'knowledge-engine') };
123
+ let engineRoot;
124
+ try { engineRoot = path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [root] })); }
125
+ catch { throw invalidProductRoot('MISSING_ENGINE', 'the installed npm engine dependency is missing'); }
126
+ return { root, packageJson, siteEntry, engineRoot };
124
127
  }
125
128
 
126
129
  function r91CreateEngineServer(options = {}, engineSourceRoot = ENGINE_SOURCE_ROOT) {
@@ -4,6 +4,9 @@ const path = require('path');
4
4
  const { spawnSync } = require('child_process');
5
5
 
6
6
  const root = path.resolve(__dirname, '..', '..');
7
+ for (const retired of ['_modules/knowledge-engine', 'vendor-manifest.json', '_site/scripts/vendor-modules.js']) {
8
+ assert(!fs.existsSync(path.join(root, retired)), `engine must remain an npm dependency; remove the retired source copy: ${retired}`);
9
+ }
7
10
  const npmCli = process.env.npm_execpath
8
11
  || path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js');
9
12
  const result = spawnSync(process.execPath, [npmCli, 'pack', '--dry-run', '--json'], {
@@ -16,6 +19,8 @@ assert.strictEqual(result.status, 0, result.stderr || result.stdout);
16
19
  const report = JSON.parse(result.stdout);
17
20
  const files = report[0].files.map(entry => entry.path.replace(/\\/g, '/'));
18
21
  const forbidden = [
22
+ '_modules/knowledge-engine/',
23
+ 'vendor-manifest.json',
19
24
  'docs/project-knowledge-base-review-deliverables.zip',
20
25
  'docs/project-knowledge-base-review-deliverables/',
21
26
  'docs/project-knowledge-base-pro-review-prompt.md',
@@ -115,7 +115,7 @@ function identityChain(shimPath) {
115
115
  return {
116
116
  gitHead: gitHead(),
117
117
  core: coreFiles.map(file => ({ file, sha256: sha256File(path.join(r3cap.ROOT, file)) })),
118
- engine: engineFiles.map(file => ({ file, sha256: sha256File(path.join(r3cap.ROOT, '_modules', 'knowledge-engine', 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
119
  console: consoleIdentity(),
120
120
  shim: {
121
121
  installedPath: shimPath,
@@ -80,7 +80,7 @@ const { attachNetworkCapture } = require('./helpers/cdp-network-capture.js');
80
80
  const ARTIFACTS = process.env.KB_ENG011_EVIDENCE_DIR
81
81
  || path.resolve(__dirname, '../../qa-autopilot/artifacts/parallel-20261023/engine-review-r3/evidence/eng011ui');
82
82
  const UI_DIR = process.env.KB_ENG011_UI_DIR
83
- || path.join(REPO_ROOT, '_modules', 'knowledge-engine', 'ui');
83
+ || path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(REPO_ROOT)] })), 'ui');
84
84
 
85
85
  function isRetryPost(entry) {
86
86
  return entry.method === 'POST' && /\/api\/runs\/[^/]+\/retry$/.test(new URL(entry.url).pathname);
@@ -19,9 +19,9 @@ const { StorageLayout } = require('../lib/storage-layout');
19
19
  const { ProjectStore } = require('../lib/project-store');
20
20
  const { ProjectRegistryStore } = require('../lib/project-registry-store');
21
21
  const { ProjectLifecycleService } = require('../lib/project-lifecycle-service');
22
- const { createEngineServer } = require('../../_modules/knowledge-engine/src/server');
23
- const { CommitScanner } = require('../../_modules/knowledge-engine/src/runtime/scanner');
24
- const AtomicFile = require('../../_modules/knowledge-engine/src/runtime/atomic-file');
22
+ const { createEngineServer } = require('@sanqianx/ai-coding-knowledge-engine/src/server');
23
+ const { CommitScanner } = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/scanner');
24
+ const AtomicFile = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/atomic-file');
25
25
 
26
26
  const results = [];
27
27
  function record(caseId, status, detail) {
@@ -21,8 +21,8 @@ const { KnowledgeRetrievalService } = require('../lib/knowledge-retrieval-servic
21
21
  const { EngineKnowledgeClient } = require('../lib/engine-knowledge-client');
22
22
  const { CHUNKER_VERSION } = require('../lib/markdown-knowledge-indexer');
23
23
  const { sha256 } = require('../lib/knowledge-schema');
24
- const { createEngineServer } = require('../../_modules/knowledge-engine/src/server');
25
- const AtomicFile = require('../../_modules/knowledge-engine/src/runtime/atomic-file');
24
+ const { createEngineServer } = require('@sanqianx/ai-coding-knowledge-engine/src/server');
25
+ const AtomicFile = require('@sanqianx/ai-coding-knowledge-engine/src/runtime/atomic-file');
26
26
 
27
27
  const results = [];
28
28
  function record(caseId, status, detail) {
@@ -107,7 +107,7 @@ function identityChain(shimPath) {
107
107
  return {
108
108
  gitHead: gitHead(),
109
109
  core: coreFiles.map(file => ({ file, sha256: sha256File(path.join(r3cap.ROOT, file)) })),
110
- engine: engineFiles.map(file => ({ file, sha256: sha256File(path.join(r3cap.ROOT, '_modules', 'knowledge-engine', file)) })),
110
+ 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)) })),
111
111
  console: consoleIdentity(),
112
112
  shim: {
113
113
  installedPath: shimPath,
@@ -41,7 +41,7 @@ const REQUESTED_MODEL = String(process.env.PK_WB_MODEL_ID || 'MiniMax-M3.1-Flash
41
41
  const EFFORT = String(process.env.PK_WB_MODEL_EFFORT || 'max');
42
42
  const TURN_TIMEOUT_MS = Number(process.env.PK_WB_TURN_TIMEOUT_MS || 420000);
43
43
 
44
- const BINDER_ENTRY = path.join(shell.REPO_ROOT, '_modules', 'knowledge-engine', 'src', 'runtime', 'commit-conversation-binder.js');
44
+ const BINDER_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [path.join(shell.REPO_ROOT)] })), 'src', 'runtime', 'commit-conversation-binder.js');
45
45
 
46
46
  const results = [];
47
47
  function record(caseId, status, detail) {