@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
@@ -3,10 +3,10 @@ const fs = require('node:fs');
3
3
  const path = require('node:path');
4
4
  const crypto = require('node:crypto');
5
5
 
6
- async function verify({ url, projects, fixtureRoot, queries, reportPath }) {
6
+ async function verify({ url, projects, fixtureRoot, queries, reportPath, basePath = '/api/engine', recallAt = 15 }) {
7
7
  const root = path.resolve(fixtureRoot);
8
8
  const inside = file => { const relative = path.relative(root, path.resolve(file)); return relative && !relative.startsWith('..') && !path.isAbsolute(relative); };
9
- const report = { passed: false, source: 'real engine and configured remote embeddings', startedAt: new Date().toISOString(), cases: [], metrics: {} };
9
+ const report = { passed: false, source: 'real engine and configured remote embeddings', startedAt: new Date().toISOString(), recallAt, cases: [], metrics: {} };
10
10
  const save = () => fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
11
11
  let semanticHits = 0, vectorCases = 0, checkedCitations = 0, badCitations = 0, scopeLeaks = 0, deepReads = 0, snippetFactHits = 0;
12
12
  for (const q of queries) {
@@ -22,8 +22,8 @@ async function verify({ url, projects, fixtureRoot, queries, reportPath }) {
22
22
  if (fs.existsSync(hidden)) throw new Error('prior interrupted stale test needs recovery');
23
23
  fs.renameSync(target, hidden);
24
24
  }
25
- const response = await fetch(new URL('/api/engine/search', url), { method: 'POST', headers: { 'Content-Type': 'application/json' },
26
- body: JSON.stringify({ projectId: project.projectId, scope: 'project', query: q.query, limit: 5 }), signal: AbortSignal.timeout(20000) });
25
+ const response = await fetch(new URL(basePath + '/search', url), { method: 'POST', headers: { 'Content-Type': 'application/json' },
26
+ body: JSON.stringify({ projectId: project.projectId, scope: 'project', query: q.query, limit: Math.max(5, recallAt) }), signal: AbortSignal.timeout(20000) });
27
27
  const result = await response.json();
28
28
  if (!response.ok) throw new Error(`search failed with HTTP ${response.status}`);
29
29
  const rows = result.results || [];
@@ -42,13 +42,54 @@ async function verify({ url, projects, fixtureRoot, queries, reportPath }) {
42
42
  if (!snippet.trim() || !body.includes(snippet) || hash !== row.content_hash) citationErrors++;
43
43
  }
44
44
  badCitations += citationErrors; scopeLeaks += leaks;
45
- const documentHit = rows.some(row => row.entry_id === q.entry);
45
+ const documentHit = rows.slice(0, recallAt).some(row => row.entry_id === q.entry);
46
+ const documentRank = q.entry ? rows.findIndex(row => row.entry_id === q.entry) + 1 : null;
47
+ if (q.kind === 'breadcrumb') {
48
+ // The session-injection gate: same engine, same corpus, real channels.
49
+ // Positive cases assert BEHAVIOUR (a strong query earns one-line
50
+ // pointers with no body text, and an immediate repeat cools down);
51
+ // which specific entry tops the ranking is the search gate's job, not
52
+ // this one. Negative cases must stay completely silent.
53
+ const sessionId = `gold-${q.id}`;
54
+ const contextCall = async query => {
55
+ // scope: 'project' keeps the injection gate on the same corpus the
56
+ // search gate uses; the domain default would let a sibling project's
57
+ // entry about the very technology being asked about answer an
58
+ // "unsupported topic" question.
59
+ const response = await fetch(new URL(basePath + '/context', url), { method: 'POST', headers: { 'Content-Type': 'application/json' },
60
+ body: JSON.stringify({ projectId: project.projectId, query, client: 'gold', sessionId, scope: 'project' }), signal: AbortSignal.timeout(20000) });
61
+ const result = await response.json();
62
+ if (!response.ok || result.ok !== true) throw new Error(`context failed with HTTP ${response.status}`);
63
+ return result;
64
+ };
65
+ await contextCall(q.query);
66
+ const turn = await contextCall(q.query);
67
+ const entries = (turn.facts || []).map(item => item.entryId);
68
+ item.injectionKind = turn.injectionKind || null; item.injectedEntries = entries;
69
+ const bodyLeak = (turn.facts || []).some(item => typeof item.text === 'string' && item.text.length > 0);
70
+ if (q.expect) {
71
+ item.passed = turn.injectionKind === 'breadcrumb' && entries.length > 0 && entries.length <= 3 && !bodyLeak;
72
+ // Cooldown is per ENTRY (10 turns): an immediate repeat may surface
73
+ // the next strong entries, but the ones just sent must not repeat.
74
+ const repeat = await contextCall(q.query);
75
+ const repeatEntries = (repeat.facts || []).map(entry => entry.entryId);
76
+ item.cooldownRespected = entries.every(entry => !repeatEntries.includes(entry));
77
+ item.passed = item.passed && item.cooldownRespected;
78
+ item.expectedEntryWithinInjected = entries.includes(q.expect);
79
+ } else {
80
+ item.passed = !turn.prompt && entries.length === 0 && !turn.injectionKind;
81
+ }
82
+ item.bodyLeak = bodyLeak;
83
+ report.cases.push(item); save();
84
+ console.log(`${item.passed ? 'PASS' : 'FAIL'} ${q.id} ${q.kind}`);
85
+ continue;
86
+ }
46
87
  const snippetFactHit = rows.some(row => row.entry_id === q.entry && (!q.fact || String(row.chunk_text).toLowerCase().includes(q.fact.toLowerCase())));
47
88
  let factRetrieved = snippetFactHit;
48
89
  if (q.fact && documentHit && !snippetFactHit) {
49
90
  // Search locates documents; an agent may then get the selected entry.
50
91
  // Record this separately rather than claiming a snippet contained it.
51
- const detail = await fetch(new URL('/api/engine/get', url), { method: 'POST', headers: { 'Content-Type': 'application/json' },
92
+ const detail = await fetch(new URL(basePath + '/get', url), { method: 'POST', headers: { 'Content-Type': 'application/json' },
52
93
  body: JSON.stringify({ projectId: project.projectId, entryId: q.entry, scope: 'project' }), signal: AbortSignal.timeout(10000) });
53
94
  const full = await detail.json();
54
95
  const text = full.chunks?.map(chunk => chunk.chunk_text).join('\n') || '';
@@ -57,10 +98,15 @@ async function verify({ url, projects, fixtureRoot, queries, reportPath }) {
57
98
  item.followupRead = { entry: q.entry, passed: factRetrieved, sha256: crypto.createHash('sha256').update(text).digest('hex') };
58
99
  deepReads++;
59
100
  }
60
- item.documentHit = documentHit; item.snippetFactHit = snippetFactHit;
101
+ item.documentHit = documentHit; item.documentRank = documentRank; item.snippetFactHit = snippetFactHit;
61
102
  const vector = rows.some(row => row.match_channels?.includes('index:vector-hub')) && result.health?.vectorMode === 'verified-chunks';
62
103
  if (q.kind === 'semantic') { if (documentHit) semanticHits++; if (vector) vectorCases++; if (snippetFactHit) snippetFactHits++; }
63
- item.passed = !citationErrors && !leaks && (q.empty ? rows.length === 0
104
+ // Empty-result expectations are enforced for "unsupported topic" cases
105
+ // (named technologies absent from the corpus). For isolation cases the
106
+ // guarantee under test is scope integrity - zero leaks and zero citation
107
+ // errors - not row counts, because unrelated same-scope entries may
108
+ // legitimately match a cross-project question lexically.
109
+ item.passed = !citationErrors && !leaks && (q.empty && q.kind === 'unsupported' ? rows.length === 0
64
110
  : q.kind === 'stale' ? rows.every(row => row.entry_id !== q.entry)
65
111
  : q.kind === 'isolation' ? true : documentHit && factRetrieved && (q.kind !== 'semantic' || vector));
66
112
  item.citationErrors = citationErrors; item.scopeLeaks = leaks;
@@ -69,8 +115,9 @@ async function verify({ url, projects, fixtureRoot, queries, reportPath }) {
69
115
  report.cases.push(item); save();
70
116
  console.log(`${item.passed ? 'PASS' : 'FAIL'} ${q.id} ${q.kind}`);
71
117
  }
72
- report.metrics = { semanticRecallAt5: semanticHits / queries.filter(q => q.kind === 'semantic').length, semanticSnippetFactCoverage: snippetFactHits / 10, followupEntryReads: deepReads, semanticVectorCases: vectorCases, checkedCitations, badCitations, scopeLeaks };
73
- report.passed = report.cases.every(c => c.passed) && report.metrics.semanticRecallAt5 >= 0.9 && vectorCases === 10 && !badCitations && !scopeLeaks;
118
+ const semanticCount = queries.filter(q => q.kind === 'semantic').length;
119
+ report.metrics = { [`semanticRecallAt${recallAt}`]: semanticHits / semanticCount, semanticSnippetFactCoverage: snippetFactHits / 10, followupEntryReads: deepReads, semanticVectorCases: vectorCases, checkedCitations, badCitations, scopeLeaks };
120
+ report.passed = report.cases.every(c => c.passed) && report.metrics[`semanticRecallAt${recallAt}`] >= 0.9 && vectorCases === 10 && !badCitations && !scopeLeaks;
74
121
  report.finishedAt = new Date().toISOString(); save();
75
122
  return report;
76
123
  }
@@ -18,7 +18,9 @@ project-knowledge
18
18
  ```
19
19
 
20
20
  1. `npm install -g @sanqianx/project-knowledge@latest` 安装外壳、固定版本的
21
- 工作台、vector-hub、event-bridge,以及包内 knowledge-engine。
21
+ 工作台、vector-hub、event-bridge,以及固定版本的 knowledge-engine npm 包。
22
+ 模块源码仓库可保持私有;安装使用公开 npm 包,不需要 GitHub 凭据。
23
+ 主仓库不再保存 knowledge-engine 的源码副本。
22
24
  2. `project-knowledge-integrations install` 是一次性的 Integration Setup,
23
25
  对检测到的每个客户端(Claude Code / Codex / OpenCode)同时安装两类
24
26
  相互独立、分别上报状态的能力:
@@ -9,11 +9,11 @@
9
9
  "ui/favicon.svg": "c48be946b224112ebb0238b44263f7a61bda31e531afa895c2e9801c0ff24f32",
10
10
  "plugins/project-knowledge/hooks/claude.json": "d61510327e3e1facbb4c645228e9f50cad05a88b33d80c4c22e5ba9f8b9f5359",
11
11
  "plugins/project-knowledge/hooks/codex.json": "216e03c07295606ef6ebb2c4f669ad0d790b5e7c4f3f34600488033db75e4239",
12
- "plugins/project-knowledge/scripts/context-hook.cjs": "da666153ad5723592cce42d25337ae649f7d93e43fab76b3c6d1263933de063f",
12
+ "plugins/project-knowledge/scripts/context-hook.cjs": "ddc1f6f5638c662adbbf4391557bbeb7196af2fb869e7ecfeefba76b9bab5760",
13
13
  "plugins/project-knowledge/scripts/mcp-launcher.cjs": "7c68830b5c73eb53ef030756a4de33987f7eab6b1a6cc15602835aac3f954893",
14
- "plugins/project-knowledge/.claude-plugin/plugin.json": "59ad3f272ded6a27ef41cf1d708627d65a7051f484569bc0e1f39534223aed8b",
15
- "plugins/project-knowledge/.codex-plugin/plugin.json": "64535429df3c28f911d0eb612cadf4aac7b3976d81bd92d6d18d3d5612e5915a",
16
- "plugins/project-knowledge/.mcp.json": "cff99a572f83892725f27b7389ed03af2971546121a26a823cfa367a60b2e5c4",
14
+ "plugins/project-knowledge/.claude-plugin/plugin.json": "d0f026321ed7abf03d88e2780d61d95defa912a6ed64b55c2408de37e9ad356e",
15
+ "plugins/project-knowledge/.codex-plugin/plugin.json": "0bb11b88f2f39d5aef49e8586e13457a175bf5690713a3427a7665eafa765a0d",
16
+ "plugins/project-knowledge/.mcp.json": "06311aedc5fce8cc6d03a68c1d0a123feb31e02d2a1882a750d7e21caccbccb2",
17
17
  "ui/version-info.js": "01a82217b031de54b80d6c7974da9c70888c4c90a046bd4248a808f7989ddce7",
18
18
  "ui/version-info.css": "209fad8e42b661f72d2aba3280e1ca47768b5cefb776fe5459538d34fbad120f"
19
19
  },
@@ -263,6 +263,56 @@
263
263
  "src/pick-folder.js": "70f55df999262b90433f2b4251aa69dd70a23b55a84756b5f1d24dbeacfbda31",
264
264
  "src/server.js": "de78bae8873eea4bcd5f85d176450e1ff1fca7b8041e7c3893fd7a231d5e6320"
265
265
  }
266
+ },
267
+ "engine": {
268
+ "name": "@sanqianx/ai-coding-knowledge-engine",
269
+ "installName": "@sanqianx/ai-coding-knowledge-engine",
270
+ "version": "0.2.8",
271
+ "files": {
272
+ "LICENSE": "c1b9df1275e769f3dbab000d1e457a2d4b0f28eb5da6c77e48dc37eeba202ed7",
273
+ "README.md": "4d99cf4b19a4b07533dc86bb63015255364016fad76c1306bea69db0a9ff8743",
274
+ "package.json": "ae0178fbf2a7b5da8d4181380e36f98b56b32337f4f9106d1ea2b2f7006705c8",
275
+ "src/analysis-contract.js": "6d4b9fde0e05d9a80d43e96d0c27febf082ecdb19312faf0280d6c9b16ac71b1",
276
+ "src/analysis-failures.js": "eb1e5a476b1e3e3c87dfd9955707c85151707799883595bcb5e9cc3e26a991c4",
277
+ "src/analysis-output.js": "95a3c19dcc9ab85d1dba7fee5b9aec80f9c000dfba89da3fd0be25a81e2fb680",
278
+ "src/analysis-worker.js": "a0bae40784c690ac68a174cb6d98fbb21dbdb69becfd27eee316ba17de544de9",
279
+ "src/bin.js": "22208907431d0f3a971a669c7e5eb44b3b7af9bbb36fd7ba17c3b90c4288bd70",
280
+ "src/bridge-client.js": "ae0dba21e4286694bcd9e064ca36564ec997969ae1eb1ce4f8a6665e447cbffe",
281
+ "src/context.js": "0f5b685210807bef36628bf6522c3a4a22ac5b8136aa7608cb61fc33fa1b646d",
282
+ "src/coordinator.js": "dc6fb98ba3a593007fa873797844b39888861258dc58afe93f14f0db6f79da55",
283
+ "src/diagnostics.js": "f7b516ace61a1e9faaa6876930b9e2e258499a25857d1203f4e53d28bfd0fa1a",
284
+ "src/headless-analyzer.js": "df570864136981cf98f3f69d047fa5729fbbfdeeaee0c6bfad26dab941dbbdae",
285
+ "src/index-request.js": "78f26b872299005499fff4f2d1f9e8f986784f2ff36a5cf2be2b1e7b7c7d9378",
286
+ "src/knowledge-targets.js": "aa44ec285d16d7b1c0b63bf084058a1d6f867fa9929c753b6b0cbb24f7b20ee2",
287
+ "src/memories.js": "b661474b51688a7ec9bc9d79bdc628070f7e128effbf7b86be9520398ead00a5",
288
+ "src/memory-eligibility.js": "48af31f23f81140dbc706ff83a39ba9f411314d87d01e5accfaf419c7a74e0ea",
289
+ "src/retrieval-policy.json": "8c8f997ddde851a17a307d36b9aa7b01aac37861efe9196eadb4778218d4530b",
290
+ "src/retrieval-ranking.js": "43f61504bca5e5fd9fdaf7234e775b25dd97d2777ef4615394e8069c7371e75e",
291
+ "src/retrieval.js": "1486efcbb8d050eeca38d39720df451e6d559584ea9602d7aa6b16df7ebe5c07",
292
+ "src/runtime/atomic-file.js": "9846b4b69db5ded811acf19a1181ef93615d93efaa542b858e552a7f3124ad23",
293
+ "src/runtime/automation-config.js": "2794aea67e3604db9b69dcaef6d303d0b5163b7e998a9730b93797f306c679cc",
294
+ "src/runtime/commit-conversation-binder.js": "5dd4b65d153918ecf491acf68db81dfbdd78156fc5a2a4f9b962b4dcfdd50135",
295
+ "src/runtime/commit-processing-ledger.js": "82cf7e15df123e2e9ea28129d9ab91d075c119923ad78f828f211f4cffbced5a",
296
+ "src/runtime/commit-prompt.js": "3382cfa8f3476dfb5255ffae2189f91b03e8c795103f1ae7af04d92deaa90f8d",
297
+ "src/runtime/commit-reconciler.js": "64ede337ce3734560df0425c539f084fe58a6ec073c227c34f83c69c414c191e",
298
+ "src/runtime/content-hash.js": "201ee7dcc054310f14097a00058cf9b28fa913367eef616e0fdd8facbf3c6c41",
299
+ "src/runtime/contracts.js": "68cff2d6007330ad11637f717c368ed67cefd5ee9532e5ea8f27ded3b93e0301",
300
+ "src/runtime/conversation-exclusions.js": "ef8545034b862d384fb460140490bb531b58d94992f5e2222ebaaa079b44fa63",
301
+ "src/runtime/conversation-store.js": "4c91f16cef516556e381ee4369d67165b00833214b7675012340cbc1637ec8d7",
302
+ "src/runtime/evidence-bundle.js": "d8e74774c2860a869f62e8adbe54d1c80818ea3da09436eff94037536ba559bf",
303
+ "src/runtime/git-runner.js": "8d4b784e33f05733e0236d0c39f573d07ec7b44e093d022e0fbc05305cdaab7b",
304
+ "src/runtime/knowledge-promotion.js": "c1d29e8eca3708f8841f1a697e8bb51ed7a977f4fea649b8ae98be2d7195c06e",
305
+ "src/runtime/knowledge-retrieval-service.js": "a4dcd09d34185f196814ff37821666e43ed0839126eab63b234bd53c4513ef1a",
306
+ "src/runtime/layout.js": "e47fe54c605218493ce46f6289798d9db2a3ecec95089d288ed03d3b75cf871a",
307
+ "src/runtime/markdown-knowledge-indexer.js": "adbb6057f1acce1041c72803b97511f01deb0c108d9350afe567dec364ac717f",
308
+ "src/runtime/README.md": "9be676eca76a7857b34d7357194e6f0ee733c22e61d962d53984715dbec7f673",
309
+ "src/runtime/scanner.js": "2b5443a1b782b4b73458de907a06a34e6bb6bfa9ba45d20c443ef8272ada97e6",
310
+ "src/server.js": "1d89378d889d563082e7ca0ade198ba312332288d5d253a9379c24b542f39b75",
311
+ "src/store.js": "66f573a58662f0a726c2ef62ccc1697616e9d93066af9f65a87c2c1f6b16829d",
312
+ "ui/app.css": "7ad370c269e60a7b5ec907d81a607b2d16bd07b2d7c22a81f102dab51eeb2889",
313
+ "ui/app.js": "e9ecb0125d5f2a8bb30a58c4d278fe0737ee2540ecfb065f97f453495cfc792d",
314
+ "ui/index.html": "ce3565cfefd4838b11d37a91a906ef26ca5a1834844fe3f7c897b56851a3c418"
315
+ }
266
316
  }
267
317
  }
268
318
  }
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@sanqianx/project-knowledge",
3
- "version": "5.0.31",
3
+ "version": "5.0.33",
4
4
  "description": "Knowledge base manager with Git integration, AI-driven analysis, and bilingual (zh-CN/en-US) knowledge output",
5
5
  "main": "_site/server.js",
6
6
  "scripts": {
7
7
  "start": "node _site/server.js",
8
8
  "test": "node _site/_test/run-all-tests.js",
9
9
  "release:sync": "node _site/scripts/sync-release-version.js --web-only",
10
- "vendor:modules": "node _site/scripts/vendor-modules.js",
11
10
  "runtime:verify": "node _site/scripts/verify-module-runtime.js --working-tree",
12
11
  "release:verify": "node _site/scripts/sync-release-version.js --check --web-only && node _site/scripts/verify-module-runtime.js && node _site/scripts/verify-product-runtime.js && node _site/_test/integration-adapters-test.js",
13
12
  "preversion": "npm run release:verify",
@@ -34,8 +33,6 @@
34
33
  "ui/version-info.css",
35
34
  "ui/favicon.svg",
36
35
  "_site/lib/",
37
- "_modules/knowledge-engine/",
38
- "vendor-manifest.json",
39
36
  "module-runtime-manifest.json",
40
37
  "_site/scripts/",
41
38
  "_site/_test/*.js",
@@ -90,6 +87,7 @@
90
87
  "@lancedb/lancedb": "0.31.0",
91
88
  "@modelcontextprotocol/sdk": "1.29.0",
92
89
  "@sanqianx/ai-coding-event-bridge-console": "0.7.4",
90
+ "@sanqianx/ai-coding-knowledge-engine": "0.2.8",
93
91
  "@sanqianx/vector-hub": "1.0.8-rc.8",
94
92
  "buffer": "^6.0.3",
95
93
  "cheerio": "^1.2.0",
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
3
3
  "name": "project-knowledge",
4
4
  "hooks": "./hooks/claude.json",
5
- "version": "5.0.31",
5
+ "version": "5.0.33",
6
6
  "description": "Read durable project decisions and implementation history from Project Knowledge.",
7
7
  "author": {
8
8
  "name": "SanQianX",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-knowledge",
3
- "version": "5.0.31",
3
+ "version": "5.0.33",
4
4
  "description": "Read durable project decisions and implementation history from Project Knowledge.",
5
5
  "author": {
6
6
  "name": "SanQianX",
@@ -8,7 +8,7 @@
8
8
  "const fs=require('fs'),path=require('path'),os=require('os');const PKG='@sanqianx/project-knowledge',SC='project-knowledge/integration-runtime/v1';let f='';const root=process.env.CLAUDE_PLUGIN_ROOT||process.env.PLUGIN_ROOT;if(root){f=path.join(root,'scripts','mcp-launcher.cjs');if(!fs.existsSync(f))f=''}if(!f){const dd=process.env.KB_DATA_DIR||path.join(os.homedir(),'.project-knowledge-v5');try{const bp=path.join(dd,'integration-runtime.json');const st=fs.statSync(bp);if(st.isFile()&&st.size<=32768){const b=JSON.parse(fs.readFileSync(bp,'utf8'));if(b&&b.schema===SC&&b.packageName===PKG&&typeof b.packageRoot==='string'&&path.isAbsolute(b.packageRoot)){const c=path.join(b.packageRoot,'plugins','project-knowledge','scripts','mcp-launcher.cjs');const rr=fs.realpathSync(b.packageRoot),cr=fs.realpathSync(c);const rel=path.relative(rr,cr);if(rel&&rel!=='..'&&!rel.startsWith('..'+path.sep)&&!path.isAbsolute(rel)&&fs.statSync(cr).isFile())f=cr}}}catch(e){}}if(!f){console.error('[project-knowledge-mcp] 未能通过受信任插件根或已验证的安装绑定定位启动器,已停止;不访问网络,也不加载工作目录源码。');process.exit(127)}require(f);"
9
9
  ],
10
10
  "env": {
11
- "KB_PLUGIN_VERSION": "5.0.31"
11
+ "KB_PLUGIN_VERSION": "5.0.33"
12
12
  }
13
13
  }
14
14
  }
@@ -22,7 +22,7 @@ async function boundedJson(response) {
22
22
  function log(dataDir, event, input) {
23
23
  // Only metadata: never log the prompt, context body, headers or CLI environment.
24
24
  const projectId = /^project-[A-Za-z0-9._-]+$/.test(input.projectId || '') ? input.projectId : '';
25
- const record = { schema: 'log/v2', id: `log-${crypto.randomUUID()}`, ts: new Date().toISOString(), level: input.code ? 'warn' : 'info', component: 'agent-context', event, message: input.code ? '开发前知识读取未完成,已提示后继续。' : '知识上下文已输出给客户端;模型实际送达需原生运行证据。', projectId, operationId: input.requestId, phase: 'context', context: { client: input.client, code: input.code || null, status: input.status, factCount: input.factCount, memoryCount: input.memoryCount, durationMs: input.durationMs } };
25
+ const record = { schema: 'log/v2', id: `log-${crypto.randomUUID()}`, ts: new Date().toISOString(), level: input.code ? 'warn' : 'info', component: 'agent-context', event, message: input.code ? '开发前知识读取未完成,已提示后继续。' : '知识上下文已输出给客户端;模型实际送达需原生运行证据。', projectId, operationId: input.requestId, phase: 'context', context: { client: input.client, code: input.code || null, status: input.status, injectionKind: input.injectionKind || null, sessionIndexedCount: input.sessionIndexedCount ?? null, factCount: input.factCount, memoryCount: input.memoryCount, durationMs: input.durationMs } };
26
26
  try { const directory = path.join(dataDir, 'logs', projectId ? 'projects' : 'system', ...(projectId ? [projectId] : [])); fs.mkdirSync(directory, { recursive: true }); const now = new Date(), date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`; fs.appendFileSync(path.join(directory, `${date}.jsonl`), JSON.stringify(record) + '\n', { encoding: 'utf8', mode: 0o600 }); } catch { /* Diagnostic disk failures must not block the IDE. */ }
27
27
  }
28
28
 
@@ -51,10 +51,14 @@ async function run(payload, { env = process.env, argv = process.argv.slice(2), f
51
51
  }
52
52
  if (!response.ok || result.ok !== true) throw new Error(/^[A-Z][A-Z0-9_]{0,79}$/.test(code || '') ? code : 'CONTEXT_UNAVAILABLE');
53
53
  if (result.requestId !== requestId || !Array.isArray(result.references) || !Array.isArray(result.memories) || !Array.isArray(result.facts) || typeof result.prompt !== 'string' || result.prompt.length > 8000 || !['ready', 'empty', 'file-fallback'].includes(result.status)) throw new Error('CONTEXT_INVALID_RESPONSE');
54
- const note = result.status === 'file-fallback' ? '知识向量检索暂不可用,本次使用当前文件事实。' : result.status === 'empty' ? '已查询当前知识范围,没有匹配知识或适用的已确认记忆。' : '';
55
- const warning = result.memoryStatus === 'pending' ? '部分已确认记忆文件待同步,本次未注入失效内容。' : '';
56
- const output = { ...(note || warning ? { systemMessage: [note, warning].filter(Boolean).join(' ') } : {}), hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext: result.prompt || note } };
57
- Object.defineProperty(output, 'receipt', { value: { dataDir, requestId, client, projectId: result.projectId, status: result.status, factCount: result.facts.length, memoryCount: result.memories.length, durationMs: Date.now() - started } });
54
+ // Empty and silent turns inject nothing at all: a per-turn "no match" note
55
+ // is fixed overhead that repeats in the conversation history forever.
56
+ // Degraded-index and pending-memory notices stay user-facing system
57
+ // messages and never enter the model context.
58
+ const notice = [result.status === 'file-fallback' ? '知识向量检索暂不可用,本次使用当前文件事实。' : '', result.memoryStatus === 'pending' ? '部分已确认记忆文件待同步,本次未注入失效内容。' : ''].filter(Boolean).join(' ');
59
+ const output = { ...(notice ? { systemMessage: notice } : {}), ...(result.prompt ? { hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext: result.prompt } } : {}) };
60
+ const injectionKind = /^(index|memory-delta|breadcrumb|refresh)$/.test(result.injectionKind || '') ? result.injectionKind : null;
61
+ Object.defineProperty(output, 'receipt', { value: { dataDir, requestId, client, projectId: result.projectId, status: result.status, injectionKind, sessionIndexedCount: Number.isInteger(result.sessionIndexedCount) ? result.sessionIndexedCount : null, factCount: result.facts.length, memoryCount: result.memories.length, durationMs: Date.now() - started } });
58
62
  return output;
59
63
  } catch (error) {
60
64
  const code = controller.signal.aborted ? 'CONTEXT_TIMEOUT' : /^[A-Z][A-Z0-9_]{0,79}$/.test(error.message || '') ? error.message : 'CONTEXT_UNAVAILABLE';
@@ -1,28 +1,39 @@
1
- ---
2
- name: project-knowledge
3
- description: Query durable Project Knowledge records for prior decisions, implementation history, known constraints, and related-project context. Use when starting non-trivial work in a registered repository, investigating why code was designed a certain way, checking whether a problem was solved before, or answering questions about earlier commits and project history.
4
- ---
5
-
6
- # Project Knowledge
7
-
8
- Use Project Knowledge as a read-only source of durable project context. Automatic client capture is the primary conversation truth. Its one write-capable tool only supplements that truth with an explicit user Prompt event and never starts knowledge analysis. Verify returned knowledge against the current source whenever the repository may have changed since the knowledge entry was produced.
9
-
10
- ## Workflow
11
-
12
- 1. Call `project_knowledge_resolve` with the current Git root before substantial implementation, diagnosis, or design work. Do not guess the project slug.
13
- 2. Call `project_knowledge_search` for focused matching records, or `project_knowledge_ask` when a compact cited synthesis is more useful.
14
- 3. Review titles and summaries before loading complete entries.
15
- 4. Call `project_knowledge_get` only for the most relevant entries. Call `project_knowledge_history` when sequence or recent change history matters.
16
- 5. Cite the returned project, entry, and commit information when it materially supports an answer or decision.
17
- 6. Call `project_knowledge_record_requirement` only when the user explicitly requests supplemental capture or automatic client capture is known to be unavailable. Supply the exact user request, resolved project, client, and stable session identifier; never record assistant output, system prompts, credentials, or tool transcripts.
18
-
19
- Client integrations may prefix MCP tool names with the server name. Match the tools by their final names: `project_knowledge_resolve`, `project_knowledge_record_requirement`, `project_knowledge_search`, `project_knowledge_ask`, `project_knowledge_get`, and `project_knowledge_history`.
20
-
21
- ## Boundaries
22
-
23
- - Treat knowledge search/get/history results as read-only. The explicit adapter may only append a user Prompt event to ConversationStore.
24
- - Do not write directly to the knowledge database or knowledge files.
25
- - Recording a requirement must not be used as a signal that analysis already ran or succeeded.
26
- - Do not substitute remembered conversation context for a knowledge lookup when prior project work is relevant.
27
- - Do not treat old knowledge as stronger evidence than current code, tests, or explicit user direction.
28
- - If the repository is not registered, continue using the source tree and tell the user that no matching Project Knowledge project was found.
1
+ ---
2
+ name: project-knowledge
3
+ description: Query durable Project Knowledge records for prior decisions, implementation history, known constraints, and related-project context. Use when starting non-trivial work in a registered repository, investigating why code was designed a certain way, checking whether a problem was solved before, or answering questions about earlier commits and project history.
4
+ ---
5
+
6
+ # Project Knowledge
7
+
8
+ Use Project Knowledge as a read-only source of durable project context. Automatic client capture is the primary conversation truth. Its one write-capable tool only supplements that truth with an explicit user Prompt event and never starts knowledge analysis. Verify returned knowledge against the current source whenever the repository may have changed since the knowledge entry was produced.
9
+
10
+ ## Automatic session injection (read this first)
11
+
12
+ Clients with the UserPromptSubmit hook receive knowledge automatically, once per session:
13
+
14
+ - The first message of a session injects one compact block: applicable confirmed memories in full, plus a **title-only index** of knowledge entries (with their entry ids). Body text is never auto-injected.
15
+ - When a later message strongly matches an indexed entry, a one-line breadcrumb `- 相关知识:title (entryId)` points back at it; the same entry cools down for several turns.
16
+ - Edited or newly confirmed memories are re-sent in full exactly once; removed memories get a one-line notice.
17
+ - Everything else is silent by design - silence means "nothing new", not "no knowledge".
18
+
19
+ Therefore: when a task touches an indexed entry, read its body with `project_knowledge_get` instead of assuming the index line is the whole story, and do not re-ask for knowledge that is already in the session index above.
20
+
21
+ ## Workflow
22
+
23
+ 1. Call `project_knowledge_resolve` with the current Git root before substantial implementation, diagnosis, or design work. Do not guess the project slug.
24
+ 2. Call `project_knowledge_search` for focused matching records, or `project_knowledge_ask` when a compact cited synthesis is more useful.
25
+ 3. Review titles and summaries before loading complete entries.
26
+ 4. Call `project_knowledge_get` only for the most relevant entries. Call `project_knowledge_history` when sequence or recent change history matters.
27
+ 5. Cite the returned project, entry, and commit information when it materially supports an answer or decision.
28
+ 6. Call `project_knowledge_record_requirement` only when the user explicitly requests supplemental capture or automatic client capture is known to be unavailable. Supply the exact user request, resolved project, client, and stable session identifier; never record assistant output, system prompts, credentials, or tool transcripts.
29
+
30
+ Client integrations may prefix MCP tool names with the server name. Match the tools by their final names: `project_knowledge_resolve`, `project_knowledge_record_requirement`, `project_knowledge_search`, `project_knowledge_ask`, `project_knowledge_get`, and `project_knowledge_history`.
31
+
32
+ ## Boundaries
33
+
34
+ - Treat knowledge search/get/history results as read-only. The explicit adapter may only append a user Prompt event to ConversationStore.
35
+ - Do not write directly to the knowledge database or knowledge files.
36
+ - Recording a requirement must not be used as a signal that analysis already ran or succeeded.
37
+ - Do not substitute remembered conversation context for a knowledge lookup when prior project work is relevant.
38
+ - Do not treat old knowledge as stronger evidence than current code, tests, or explicit user direction.
39
+ - If the repository is not registered, continue using the source tree and tell the user that no matching Project Knowledge project was found.
@@ -1,133 +0,0 @@
1
- # knowledge-engine
2
-
3
- 正式知识检索(包括 `get`)排除 `dev-conversations`、内部会话、备份与隐藏目录。提交会话只作为分析证据,不直接充当已晋升知识;原始证据仍由事件模块保留。
4
-
5
- > 开发前读 [AGENTS.md](AGENTS.md)。该指南中的脚手架状态是历史背景;当前运行契约及实现状态以本 README 为准。
6
-
7
- `project-knowledge` 模块家族的第四块:**知识引擎**。owns 两个职责面,shell 只负责连接与投影("The shell owns no features"):
8
-
9
- - **触发面**:消费 event-bridge journal 的 commit boundary 与关联会话事件 → CommitReconciler 对账/认领 → 无头 Claude Agent SDK 会话分析 → staging 校验 → 晋升知识树(README / GOAL / ARCHITECTURE / modules / changes)。
10
- - **检索面**:search / ask / get / history,供开发期辅助检索。对外入口:MCP server 与 `project-knowledge-kb` CLI 直接指向本服务。
11
-
12
- ## 家族关系
13
-
14
- | 模块 | 端口 | 职责 |
15
- |---|---|---|
16
- | claude-ai-workbench | 5760 | Agent Terminal |
17
- | vector-hub | 8787 | 知识树向量索引 |
18
- | ai-coding-event-bridge | 8790 | 会话/commit 事件总线 |
19
- | **knowledge-engine** | **5790** | **知识生成(触发面)+ 知识检索(检索面)** |
20
-
21
- 数据流:任意 IDE(claude / codex / opencode / zcode)→ bridge hooks → journal → **knowledge-engine(注册消费者)** → 分析运行 → 知识树 → vector-hub 派生向量索引 → 检索面/MCP 供开发 agent 查询。
22
-
23
- ## 与 shell 的接线契约(模块契约)
24
-
25
- 运行投影支持 `GET /api/snapshot?summary=1&limit=50` 和 `GET /api/runs?summary=1&projectId=...&before=<cursor>`,每页最多 100 条;概要不携带 staging 和冻结证据,完整详情仍由 `GET /api/runs/:id` 读取。未指定概要参数时保留旧接口。进度订阅 `summary=1` 的初始快照只含游标,消费者先读取有界快照。
26
-
27
- 受管激活 `POST /api/control` 可传入已安全接线的 `projectIds` 白名单;未接线项目的任务保留排队,不能执行或恢复晋升。新增可用项目只恢复其自身的晋升与索引,重复激活不重复恢复;服务就绪与单项目接线失败分别投影。
28
-
29
- - **env**:`KB_KNOWLEDGE_ENGINE_URL`(默认 `http://127.0.0.1:5790`)、`KB_KNOWLEDGE_ENGINE_COMMAND`(显式命令行覆盖)、随家族一起受 `KB_MODULES_AUTOSTART=0` 约束。
30
- - **supervisor**:shell `_supervisedSpecs()` 增加本模块条目(vendored runtime 位于 `project-knowledge-base/_modules/knowledge-engine/`),探测已监听则不重复拉起,退出指数退避重启。
31
- - **反代**:`/api/engine/<rest>` → 本服务 `/api/<rest>`,浏览器同源,无 CORS。
32
- - **注册扇出**:项目导入时随 terminal/vector-hub/event-bridge 一并登记(`repoPath` + `knowledgePath`),wiring 写入 `state.modules.engine`,摘除走 keep-data 语义(知识树与运行历史不删)。
33
-
34
- ## 运行
35
-
36
- ```bash
37
- node src/bin.js serve [--port 5790] [--host 127.0.0.1] [--data DIR]
38
- ```
39
-
40
- 打开 `http://127.0.0.1:5790` 即调试台。默认绑定 loopback:运行历史包含 commit 证据与知识内容,不出本机。
41
-
42
- 首次启动为空,不创建演示项目。`--debug` 才开放手工运行、事件注入和模拟失败。独立运行默认只提供读取与诊断;设置 `KNOWLEDGE_ENGINE_CONSUME=1` 开始消费。外壳守护使用 `KB_ENGINE_MANAGED=1`,确认服务身份、运行期鉴权、项目接线及配置后启用消费与执行;不再导入旧外壳任务。
43
-
44
- 0.2.0 使用全新 schemaVersion 3,独立运行默认目录为 `./data-v3`。旧版状态目录明确拒绝读取,原文件保持不变;不备份后重置、不迁移、不创建 `upgrade-recovery`。同一新版数据目录内的崩溃恢复仍保留。
45
-
46
- 本模块零新增 npm 依赖、CommonJS、Node ≥18;无头 Agent SDK 由宿主已安装的 Workbench/SDK 提供,缺失时明确失败,不退回假分析。完整产品的 Node 门槛为 ≥22。
47
-
48
- 隔离无头分析只读冻结证据、只写 staging,不以开发工作树的前后变化判定失败。用户可以在分析中继续编辑或提交;当前任务仍归属冻结提交,后续提交按项目 FIFO 执行。未声明隔离冻结证据能力的自定义分析器仍保留源码变更检查;目录越界、工具权限和晋升校验不变。
49
-
50
- 每次真实分析在只读证据区冻结已有知识的目标路径与哈希清单,覆盖未被检索选中的文件;重试复用该清单。Agent 不得把“未检索到”当作“文件不存在”,也不得用部分片段覆盖完整旧文档;无法保留原文时只追加当前提交的变更记录。已有目标仍由晋升校验拒绝非法 create,不自动改为覆盖。清单仅保存元数据,不把整个知识树复制到每次运行中。
51
-
52
- ## API
53
-
54
- | 方法 | 路径 | 说明 |
55
- |---|---|---|
56
- | GET | `/api/health` | 版本 / dataSchemaVersion / uptime / 计数 / journal 游标 |
57
- | GET / POST | `/api/projects` | 项目列表 / 注册(按 projectId 幂等) |
58
- | DELETE | `/api/projects/:id` | 摘除登记,取消未开始任务;实际运行或写入租约未释放时返回 409;保留代码、知识和证据 |
59
- | GET | `/api/runs?projectId=` | 分析运行列表(新→旧) |
60
- | POST | `/api/runs` | 仅调试模式手工运行;必填完整 `commitSha` |
61
- | GET | `/api/runs/:id` | 运行详情(含 staging manifest) |
62
- | POST | `/api/runs/:id/retry` | 只恢复失败阶段;索引失败不重新分析 |
63
- | POST | `/api/search` | `{ projectId 或 repoPath, query, limit, scope }` → 带项目、文件、commit 的结果 |
64
- | POST | `/api/context` | `{ repoPath 或 projectId, query, client, sessionId, turnId, requestId, scope? }` → 开发前知识事实、适用的已确认记忆、引用与有界 prompt;只读 |
65
- | POST | `/api/ask` | `{ projectId, query }` → 确定性答案 + 引用(非 LLM 生成) |
66
- | GET / POST | `/api/get`、`/api/history` | 当前知识文件 / 变更历史,保留 CLI/MCP 输出字段 |
67
- | GET | `/api/snapshot`、`/api/progress` | 持久化快照 / 快照先行的 SSE 更新 |
68
- | GET / POST | `/api/events` | 真实事件查询 / 仅调试模式注入事件 |
69
- | POST | `/api/bridge/notify` | 唤醒 journal 消费;通知丢失仍由轮询恢复 |
70
- | GET / PATCH | `/api/memories`、`/api/memories/:id` | 按 status/scopeType/scopeId 筛选;一次编辑内容、适用范围和确认状态;来源证据只读 |
71
- | POST | `/api/memories` | `{ text, brainId?, scopeType?, scopeId? }` → 手动添加已确认记忆;默认全局,领域/项目必须指定已登记目标,不接受伪造来源 |
72
- | DELETE | `/api/memories/:id` | 软删除为无正文墓碑:默认列表与新任务不再使用,原始对话与知识来源保留;重复删除返回 404;完整契约见下方记忆删除边界 |
73
- | POST | `/api/scopes` | 外壳投影智脑、领域共享目录;受运行期鉴权保护 |
74
- | POST | `/api/runtime-config` | 运行期模型配置,仅保留在内存;受鉴权保护 |
75
- | GET | `/api/runtime-auth` | 本机服务确认运行期鉴权;受鉴权保护,不对浏览器反代 |
76
- | POST | `/api/control` | 外壳完成接线后启用;受鉴权保护。旧 `/api/migrate` 已删除 |
77
-
78
- 鉴权接口只接受无浏览器 Origin 的本机服务调用,使用 `KB_ENGINE_RUNTIME_TOKEN` 的 Bearer token。外壳不能把这些接口或解析后的凭据转发到浏览器。登记投影只接受白名单元数据,API key 不写入 EngineStore、任务记录或日志。
79
-
80
- ## 真实运行与恢复边界
81
-
82
- 开发前 `/api/context` 复用正式检索与记忆适用范围校验,不运行分析模型、不写知识树。默认本项目优先、相关时补充所属领域;适用记忆独立准备,即使需求没有偏好关键词也保留。完整注入最多 8,000 字符,记忆最多 3,000 字符;剩余事实预算本项目保留 70%,领域参考最多 30%,不凑满低质量结果。候选、忽略、失效及未同步投影不进入上下文,向量故障明确标为 `file-fallback`。输入的凭据样式在向量查询前脱敏,不记录原需求或知识正文。读取日志的 `knowledge.context.prepared` 只证明准备完成,不能冒充模型送达证据。
83
-
84
- 检索排序 `project-knowledge/ranking-v2` 在当前文件片段上使用中文分词 BM25 与向量片段 RRF 融合,不直接叠加原始分数。vector-hub 的可选 `resultLevel=chunk` 返回 LF 规范化正文哈希及半开字符范围;匹配只影响相应片段,不扩散至整篇。已校验范围不足半个词法分块时,引擎从当前规范正文按同一半开坐标系截取独立片段候选,进入同一 RRF 融合,纯语义命中不因分块尺寸不一致而丢失;重复段落按文档顺序定位,周期性重复文本不得把后续分块拉回更早的重复位置伪造向量证据。词法分块器为版本 2:标题边界围栏感知,代码围栏内的 `#` 注释不再切成伪小节,分块几何随版本号封入 documentHash。既有 v5 数据的 version-1 词法缓存因此哈希失配,经当前文件、版本与哈希校验走安全 delta overlay 按需重建派生索引;知识正文与来源不改写,不做全量分析,也不强制全量 embedding 索引重建,向量行按正文哈希独立校验不受影响。健康信息只记录召回、合并、截取与各类拒绝计数,不回显知识正文。原文变化、删除、项目归属变化及记忆失效都会重新验证;未知或未标定模型不能只凭高向量分返回知识。`retrieval-policy.json` 的 embo-01 / 1536 维门槛来自固定语料的训练问题族,测试问题族不参与选择;不是对任意语料准确率的保证。单次检索内,正文阶段复用扫描阶段刚读取的同一篇文件内容(请求内私有复用,不跨请求缓存正文);异步等待后的有界最终校验仍重读真实文件核对文档哈希。
85
-
86
- 普通搜索每篇最多两个互补片段,精确提交与源文件仍优先。`search` 增加 `intent`、`rankingVersion`、`matchStatus`、`currentProjectStatus` 和 `matchReason` 等兼容字段;最近进度优先当前项目维护历史,时间来源区分提交依据、晋升和 mtime 回退。问候不进行主题召回,短追问仅复用同项目同会话五分钟内仍有效的引用,引用缓存只在内存中且有界,不保存原对话。索引故障与“本次无可靠匹配”不等于知识为空。
87
-
88
- 上下文明确区分当前已确认记忆与历史事实:项目约定优先于领域,领域优先于全局;同范围冲突参考记忆的更新时间。历史提交中的旧实现、偏好描述不能覆盖本次下发的现行记忆;记忆也不扩大当前用户授权或替代安全限制。保留旧事实及其提交依据,不删除历史来制造新记忆生效的结果。
89
-
90
- 同一正文哈希下,经校验的短向量范围(不足父分块一半)完全包含于 Markdown 分块时只占一个片段名额,避免父段落和其首句挤掉互补证据;不同哈希、未知坐标、较大范围与互不相交范围不据此合并,不扩大向量得分的作用范围。任务明确引用已识别提交时,当前项目的小型知识条目(最多 2500 字符)可在原有 8000 字符总预算及项目预算内完整送达;重新读取并匹配分块版本与文档哈希后才展开,同文件不重复注入。大文件、变化文档、普通语义查询或跨项目参考仍使用原有片段,不新增模型调用或知识写入。
91
-
92
- 检索中明确命名且当前知识已有依据的源文件与 commit 标识优先做身份匹配,避免重复历史范例挤出指定文件。已识别 commit 的 SHA 只限定提交依据,不再重复计入主题词分;该提交内按其余主题的 BM25 选择片段,分数为 `1 + BM25 / (1 + BM25)`(排序分,不是置信概率)。普通语义查询继续使用原 RRF。中英引擎、晋升、单写者词汇使用双向别名,保持每文档最多两个互补片段。尚无知识依据的新文件名仍允许检索相似背景;不把没有范围授权的项目或原始会话当作匹配来源。
93
-
94
- - journal 游标按来源隔离;证据投影及可恢复任务先落盘,再 ACK。不等待模型才能消费下一条事件。
95
- - 会话来源接受 bridge 的四客户端契约(Claude Code、Codex、OpenCode、ZCode)。单个 journal 的非法证据不被跳过或 ACK,但不阻塞其他项目;失败位置和错误码写入日志,健康接口提供 `journal.failures`,重复轮询不刷屏,恢复后续接原游标。
96
- - 不同项目最多并发 2 个分析,同项目按提交顺序执行。未晋升的失败提交会阻挡本项目后续提交,不阻挡其他项目。
97
- - 无头分析在隔离进程中运行,只读冻结证据,只写本次 staging。产物必须通过路径、内容 hash 和依据校验,只有晋升路径写最终项目知识。
98
- - 归档对话和检索内容只作证据,不能覆盖后台维护指令。SDK 返回成功文字但未生成 manifest 时,记录 `ANALYSIS_OUTPUT_MISSING` 并保留证据供重试,不误报晋升完成。
99
- - 空知识库是正常首用状态。输出合同明确 UTF-8、一级标题和非空正文;仅缺标题的非空文档在 staging 中确定性补齐并重新封印哈希,空正文、非法路径、占位内容或不匹配哈希仍拒绝晋升。
100
- - 占位检测区分未完成正文与源码示例:HTML 的 `placeholder=` 属性、行内代码和有正文解释的围栏代码不被误判为未完成知识;只有标题或仅用代码包裹未完成标记的文档仍拒绝。裸 `placeholder` 术语只在 UI 语境加完整事实谓语时放行——中文事实动词(属性、校验、描述等)或英文完整说明谓语(describes、specifies 等),且句内不得出现待补、后续补齐等待填措辞;空引号或仅省略号的样例只在紧邻该术语或其限定词(属性说明、值为、value is 等)之后才拒绝,同句其它字段的空值不计入。`TBD` 仅在讨论标记机制本身的完整规则清单事实中放行(如"均未改动""之外不再有其它"且其后有实际文本),正则、围栏等技术名词本身不构成豁免,计划谓语(实现 TBD、方案待定)仍拒绝。校验不改写有效原文。
101
- - 具体失败原因、失败步骤和提交依据进入运行详情及 `log/v2` 诊断。受外壳守护时通过 IPC 交给外壳现有日志系统;独立运行保存在 `<data>/logs/`,不写模型凭据和原始证据。升级不会重新运行已失败提交,用户可显式重试失败阶段。
102
- - 数据目录有单实例租约,目标知识目录有写入锁。关闭或超时等待子进程实际退出,再释放写入锁。
103
- - 晋升与索引分别记录。索引失败保留已晋升知识并显示待修复,不重新调用模型。
104
- - 索引错误保留兼容的 `INDEX_FAILED` 及可选 `error.details`(类别、HTTP 状态、上游代码/脱敏原因、请求标识、耗时和尝试次数);项目和共享索引均写入 `log/v2`。响应仅解析有界 JSON,不记录原始 body 或认证头。只重试索引保留原分析运行、晋升时间和知识字节。
105
- - 项目、领域、智脑检索使用包含范围。未分配领域不是共享领域:领域范围只包含当前项目与智脑共享知识;显式加入同一领域后才包含其他项目。整个智脑范围仍包含全部同智脑项目。向量只提供排序,显示内容必须来自当前真实文件;索引不可用时降级为文件检索。
106
- - 已晋升提交的 SHA 或短 SHA 在自然语言查询中仍作为标识符匹配,只返回当前文件的晋升依据;仅在原始会话中提到相同 SHA 不构成知识晋升引用。多个提交标识符可以一起查询。
107
- - 候选必须有已晋升文件中的引用依据,未确认候选不能进入任务。确认记录原子持久化后写共享记忆文件,派生索引异步更新,索引失败不会撤销有效记忆。
108
- - 候选的 `entryId` 必须等于本次晋升清单中实际文档的 `operations[].path`,不是候选编号;引用必须与该文档原文匹配。无效候选不会伪造来源或阻塞有效知识更新,运行的 `memoryCapture` 与 `knowledge.memory.candidate_rejected` 日志记录安全的计数、序号和原因代码。
109
- - 记忆的适用范围为 `global/domain/project`,目标用 `scopeId` 指定;来源项目/领域不等于适用范围。新候选默认来源项目,分析器只有明确证据时才建议领域/全局;用户审核时可以编辑内容并选择当前智脑中的其他已有目标。原始总结与证据保持不变,同一范围内容去重,忽略和编辑后的原候选不会重复生成。
110
- - 长期记忆统一保存在已绑定的智脑共享目录:`memories/confirmed.md`(全局)、`memories/domains/<id>.md`、`memories/projects/<id>.md`。不创建第二份项目知识目录。现有 v5 缺少范围字段的记忆仍按全局解释;不读取 pre-v5 状态、不重扫历史。
111
- - 手动记忆以用户确认作为来源,记录 `sourceType: manual`、`evidence: null`,不伪造提交或分析运行。内容限制为 1–2000 字符,同范围内容去重;创建、编辑、投影与恢复复用引擎受控写入。空项目列表也可添加全局记忆,但必须已绑定共享目录;无需模型分析或 Git 提交,索引状态独立报告。
112
- - 任务检索只允许当前项目、当前所属领域与全局的已确认记忆,即使检索整个智脑也不放宽专属记忆范围。过滤在排名之前完成,`get` 同样校验;向量旧内容不能绕过当前状态和文件一致性校验。已确认记录修改范围会同步清理旧投影;写入失败显示待同步并自动重试,未同步文件不能进入上下文。
113
- - 删除记忆写入无正文墓碑记录:删除后默认列表与新任务上下文不再使用该记忆,原始对话与知识来源保持保留;同文本的自动候选按墓碑去重不会复活,同一适用范围仍可手动重加;重复删除返回 404;派生记忆文件写入失败时如实记录待同步并自动重试,不伪造一致状态。
114
- - 旧格式不读取、不自动迁移。损坏的正式状态不覆盖、不清空。
115
- - 引擎状态复用受控原子写入:独占随机临时文件、文件同步、Windows 短暂共享冲突有界重试;永久失败保留原状态并清理本次临时文件,绝不先删正式状态。
116
-
117
- ## 验证与尚未验收项
118
-
119
- 默认维护模型额度或余额不足时,不会成功生成知识;提交任务仍先持久化。SDK 明确报告 billing 错误时记录 `MODEL_QUOTA_EXHAUSTED`,请求限流单独记录 `MODEL_RATE_LIMITED`,不把任意 HTTP 429 当作余额耗尽。同项目后续提交保持排队,失败与排队记录跨重启保留;恢复额度或更换默认维护模型后需显式重试前一条失败提交,不会自动消耗额度反复重试。
120
-
121
- `/api/snapshot` 的兼容扩展字段 `maintenance` 包含执行启用状态、事件消费启用状态及按当前项目过滤的 journal 故障。建单前的消费故障不会伪造提交运行;外壳展示“提交事件消费受阻”,不能将零条运行当作没有提交。故障变化和恢复通过现有 progress 流通知,稳定故障不产生重复刷新事件。未启动服务时,Hook 已捕获的事件保留于 journal,服务消费后才生成分析任务。
122
-
123
- `npm test` 覆盖真实 Git/Hook、真实分项目 journal、真实 vector-hub 文件索引、晋升、重复抑制、FIFO/并发、记忆、旧格式拒绝、新版恢复及进程隔离。自动测试中的模型和 embedding 是可控替身。
124
-
125
- `npm run test:web` 使用兄弟源码仓库启动隔离的五服务网页环境,只有模型与 embedding 是替身。单一 1920×1080 视口验证双目录 UI 导入、真实 Hook 到自动刷新、原生消息流与中止、快速项目切换/草稿/历史、迟到检索及文件响应、领域检索、记忆落盘、四 iframe 身份与主题、唯一进度连接、诊断关闭和保留数据解绑;不会在用户代码仓库提交。该脚本是开发验收工具,不属于引擎生产运行依赖。
126
-
127
- `npm run test:web:faults` 从真实网页重试模型超时和索引失败,验证同项目 FIFO 恢复、不同项目继续运行、非法产物不写最终知识、浏览器离线时后台仍完成维护、恢复连接后自动恢复快照及唯一订阅,并检查私有接口鉴权及公开状态不含测试凭据。故障注入只存在于明确启用的验收替身,不进入生产管道。
128
-
129
- `test/support/product-preview.js` 提供隔离的四模块加外壳验收环境,绝不使用用户代码仓库进行测试提交。显式设置 `KB_ACCEPTANCE_REAL_PROFILE_ID` 才会从本机 Workbench 只读复制所选模型配置;`real-agent-acceptance.js` 验证真实模型提交和并发,并保留失败记录。默认 embedding 是替身;`KB_ACCEPTANCE_REAL_EMBEDDING=1` 才会只读复制实际向量供应商配置,`verify-real-embedding.js` 检查实际向量维度、语义查询及来源。
130
-
131
- 已完成真实 MiniMax-M3 分析、单项目提交、双项目并发、知识晋升、真实 embo-01 索引/检索,以及原生工作台流式回答和引用抽测。`verify-real-capture.js` 另检查实际工作台输入/最终回答经过鉴权 bridge 进入提交归档和引擎冻结证据,不把注入的上下文伪装成用户输入。
132
-
133
- 本地 npm 候选包已在隔离安装目录启动四模块,校验包内 UI 与运行文件,不依赖兄弟源码仓库。本轮按用户确认仅交付网页版本,Windows 安装包、安装器和桌面自动更新不在实施或验收范围内。新版外壳完整回归与五服务网页核心验收已通过;剩余故障组合及最终切换验收单独记录。远程发布及 Git 跟踪门禁也单独记录,不以工作树校验代替发布通过。此前使用替身 embedding 的真实模型记录,与本轮真实模型加真实 embedding 记录分别保存。详见 [实施与验收记录](docs/unified-product-implementation.md),不得据此宣称五仓库改造已全部交付。
@@ -1,38 +0,0 @@
1
- {
2
- "name": "@sanqianx/ai-coding-knowledge-engine",
3
- "version": "0.2.7-rc.12",
4
- "description": "Knowledge engine module for project-knowledge: commit-boundary triggered knowledge analysis/generation (trigger plane) and retrieval for development assistants (retrieval plane).",
5
- "license": "Apache-2.0",
6
- "main": "src/server.js",
7
- "bin": {
8
- "knowledge-engine": "src/bin.js"
9
- },
10
- "engines": {
11
- "node": ">=18"
12
- },
13
- "files": [
14
- "src",
15
- "ui/index.html",
16
- "ui/app.js",
17
- "ui/app.css",
18
- "README.md"
19
- ],
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/SanQianX/knowledge-engine.git"
23
- },
24
- "scripts": {
25
- "start": "node src/bin.js serve",
26
- "test": "node --test test/*.test.js",
27
- "test:web": "node test/support/product-web-ui-test.js",
28
- "test:web:faults": "node test/support/product-web-fault-test.js"
29
- },
30
- "keywords": [
31
- "knowledge-base",
32
- "knowledge-engine",
33
- "commit-boundary",
34
- "retrieval",
35
- "project-knowledge",
36
- "mcp"
37
- ]
38
- }