@sanqianx/project-knowledge 5.0.9-rc.2 → 5.0.9-rc.4

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.
@@ -9,7 +9,7 @@
9
9
  "plugins": [
10
10
  {
11
11
  "name": "project-knowledge",
12
- "version": "5.0.9-rc.2",
12
+ "version": "5.0.9-rc.4",
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,26 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.0.9-rc.4] - 2026-10-11
4
+
5
+ - Pin Workbench 0.13.2-rc.2: resolve the installed ZCode provider resource
6
+ layout without rewriting desktop or personal configuration, and label
7
+ runtime failures with the correct agent.
8
+ - Disable the project selector until the first registry snapshot. This fixes
9
+ the startup interaction race exposed by the Node 22 packaged UI regression.
10
+ - Latest is unchanged; real installed acceptance and client authentication are
11
+ independent gates, not implied by a successful version probe.
12
+
13
+ ## [5.0.9-rc.3] - 2026-10-11
14
+
15
+ - Route engine-wired CLI and MCP reads through the same authoritative engine
16
+ as the web UI, preserving commit references and project/domain/brain scopes.
17
+ Verify the selected runtime identity and reject unavailable, mismatched or
18
+ malformed services instead of silently querying a different local index.
19
+ - Preserve the MCP `space` alias and expose explicit scope selection. Bound
20
+ responses and never forward profile or credential objects to read routes.
21
+ - Drain isolated regression servers before Windows fixture cleanup. Candidate
22
+ publication still does not promote latest or claim complete acceptance.
23
+
3
24
  ## [5.0.9-rc.2] - 2026-10-11
4
25
 
5
26
  - Pin the verified Workbench 0.13.2-rc.1 and vector-hub 1.0.8-rc.1 candidates.
package/README.md CHANGED
@@ -160,6 +160,15 @@ Queries never create or rewrite configuration. If the internal index is
160
160
  unavailable, search falls back to current Markdown. Project, domain and brain
161
161
  scopes are nested; unconfirmed memory candidates are not task preferences.
162
162
 
163
+ For engine-wired projects, the CLI and MCP delegate `search`, `ask`, `get` and
164
+ `history` to the same engine used by the web UI, including commit provenance.
165
+ They verify the running instance against the selected data directory; an
166
+ unavailable or mismatched instance is an explicit failure, not a second local
167
+ index with different facts. Only projects without engine wiring retain the
168
+ local legacy read contract. Use `--scope domain` or `--scope brain` to broaden
169
+ CLI searches; MCP accepts the equivalent `scope`. Shared-file reads accept
170
+ `--space <spaceId>` (MCP: `space` or `spaceId`).
171
+
163
172
  ## Storage
164
173
 
165
174
  Version 5 is a fresh start, not a data upgrade. Stop the previous process,
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('node:fs');
4
+ const os = require('node:os');
5
+ const path = require('node:path');
6
+ const http = require('node:http');
7
+ const { spawn } = require('node:child_process');
8
+ const { StorageLayout } = require('../lib/storage-layout');
9
+ const { SettingsStore } = require('../lib/settings-store');
10
+ const { ProjectRegistryStore } = require('../lib/project-registry-store');
11
+ const { ProjectStore } = require('../lib/project-store');
12
+ const { KnowledgeToolRuntime } = require('../lib/knowledge-tool-runtime');
13
+ const endpoint = require('../lib/runtime-endpoint');
14
+ const control = require('../lib/runtime-control');
15
+ const { EngineKnowledgeClient } = require('../lib/engine-knowledge-client');
16
+
17
+ (async () => {
18
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'knowledge-engine-client-'));
19
+ const layout = new StorageLayout({ dataDir: path.join(root, 'data') });
20
+ const settings = new SettingsStore({ layout }), registry = new ProjectRegistryStore({ layout }), projects = new ProjectStore({ layout });
21
+ const projectId = 'project-test', repoPath = path.join(root, 'repo'), knowledgePath = path.join(root, 'knowledge');
22
+ fs.mkdirSync(repoPath); fs.mkdirSync(knowledgePath);
23
+ fs.writeFileSync(path.join(knowledgePath, 'README.md'), '# Legacy\n\nlegacy-local-only\n');
24
+ await settings.initialize(); await registry.initialize();
25
+ await projects.create(projectId, { repoPath, knowledgePath }, { modules: { engine: { status: 'registered', projectId } } });
26
+ await projects.updateState(projectId, state => { state.modules = { engine: { status: 'registered', projectId } }; });
27
+ await registry.add(projectId, { displayNameSnapshot: 'Test' });
28
+ let invalidIdentity = false, malformed = false, businessError = false, oversized = false, wrongBinding = false;
29
+ const calls = [];
30
+ const reference = { scope_project_id: projectId, entry_id: 'changes/aaaaaaaaaaaa.md', commitSha: 'a'.repeat(40), chunk_text: 'Engine authoritative knowledge' };
31
+ const payload = { ok: true, projectId, backend: 'hybrid+markdown-truth', results: [reference], answer: reference.chunk_text, citations: [{ ...reference, entryId: reference.entry_id }], chunks: [{ chunk_text: reference.chunk_text }] };
32
+ const server = http.createServer(async (req, res) => {
33
+ res.setHeader('Content-Type', 'application/json');
34
+ if (req.url === '/api/runtime/identity') return res.end(JSON.stringify(control.identity(invalidIdentity ? root : layout.getDataDir(), { port: server.address().port, host: '127.0.0.1', startedAt: 'test-start' })));
35
+ if (req.url === '/api/health') return res.end(JSON.stringify({ name: 'knowledge-engine', dataSchemaVersion: 3 }));
36
+ if (req.url === '/api/projects') return res.end(JSON.stringify({ projects: [{ projectId, repoPath, knowledgePath: wrongBinding ? root : knowledgePath }] }));
37
+ let text = ''; for await (const bytes of req) text += bytes;
38
+ calls.push({ route: req.url, input: JSON.parse(text || '{}') });
39
+ if (oversized) return res.end(JSON.stringify({ ok: true, text: 'x'.repeat(2 * 1024 * 1024) }));
40
+ if (businessError) { res.statusCode = 403; return res.end(JSON.stringify({ ok: false, error: { code: 'PATH_OUTSIDE_ROOT', message: 'private-test-secret' } })); }
41
+ res.end(malformed ? '[]' : JSON.stringify(payload));
42
+ });
43
+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
44
+ endpoint.writeEndpoint(layout.getDataDir(), { pid: process.pid, port: server.address().port, host: '127.0.0.1', startedAt: 'test-start' });
45
+ const runtime = new KnowledgeToolRuntime({ layout, settingsStore: settings, registryStore: registry, projectStore: projects });
46
+ try {
47
+ for (const action of ['search', 'ask', 'get', 'history']) {
48
+ assert.deepEqual(await runtime[action]({ project: projectId, query: 'knowledge', entry: reference.entry_id, scope: 'brain', apiKey: 'must-not-forward', password: 'must-not-forward' }), payload);
49
+ const call = calls.at(-1);
50
+ assert.equal(call.route, `/api/engine/${action}`);
51
+ assert.equal(call.input.projectId, projectId); assert.equal(call.input.scope, 'brain');
52
+ assert.ok(!JSON.stringify(call.input).includes('must-not-forward'));
53
+ }
54
+ const subprocess = (file, args) => new Promise((resolve, reject) => {
55
+ const child = spawn(process.execPath, [file, ...args], { env: { ...process.env, KB_DATA_DIR: layout.getDataDir() }, windowsHide: true });
56
+ let out = '', err = ''; child.stdout.on('data', b => { out += b; }); child.stderr.on('data', b => { err += b; });
57
+ child.once('error', reject); child.once('close', code => resolve({ code, out, err }));
58
+ });
59
+ const cli = await subprocess(path.resolve(__dirname, '../../bin/project-knowledge-kb.js'), ['search', '--project', projectId, '--query', 'knowledge', '--scope', 'brain', '--json']);
60
+ assert.equal(cli.code, 0, cli.err); assert.deepEqual(JSON.parse(cli.out), payload);
61
+ assert.equal(calls.at(-1).input.scope, 'brain');
62
+ await runtime.get({ projectId, entry: reference.entry_id, space: 'brain:test' });
63
+ assert.equal(calls.at(-1).input.spaceId, 'brain:test', 'legacy space alias is forwarded');
64
+ const { createRequire } = require('node:module');
65
+ const sdk = createRequire(path.resolve(__dirname, '../../package.json'));
66
+ const { Client } = sdk('@modelcontextprotocol/sdk/client/index.js');
67
+ const { StdioClientTransport } = sdk('@modelcontextprotocol/sdk/client/stdio.js');
68
+ const transport = new StdioClientTransport({ command: process.execPath, args: [path.resolve(__dirname, '../../bin/project-knowledge-mcp.js')], env: { ...process.env, KB_DATA_DIR: layout.getDataDir() }, stderr: 'pipe' });
69
+ const client = new Client({ name: 'engine-regression', version: '1.0.0' });
70
+ try {
71
+ await client.connect(transport);
72
+ const tools = await client.listTools();
73
+ assert.deepEqual(tools.tools.find(t => t.name === 'project_knowledge_search').inputSchema.properties.scope.enum, ['project', 'domain', 'brain']);
74
+ for (const action of ['search', 'ask', 'get', 'history']) {
75
+ const result = await client.callTool({ name: `project_knowledge_${action}`, arguments: { projectId, scope: 'brain', ...(action === 'get' ? { entry: reference.entry_id, space: 'brain:test' } : action === 'history' ? {} : { query: 'knowledge' }) } });
76
+ assert.ok(!result.isError); assert.deepEqual(JSON.parse(result.content[0].text), payload);
77
+ assert.equal(calls.at(-1).input.scope, 'brain');
78
+ }
79
+ } finally { await client.close(); }
80
+ invalidIdentity = true;
81
+ await assert.rejects(runtime.search({ projectId, query: 'knowledge' }), e => e.code === 'ENGINE_IDENTITY_MISMATCH');
82
+ invalidIdentity = false; malformed = true;
83
+ await assert.rejects(runtime.search({ projectId, query: 'knowledge' }), e => e.code === 'ENGINE_INVALID_RESPONSE');
84
+ malformed = false; businessError = true;
85
+ await assert.rejects(runtime.get({ projectId, entry: '../outside.md' }), e => e.code === 'PATH_OUTSIDE_ROOT' && !e.message.includes('private-test-secret'));
86
+ businessError = false; oversized = true;
87
+ await assert.rejects(runtime.search({ projectId, query: 'knowledge' }), e => e.code === 'ENGINE_INVALID_RESPONSE');
88
+ oversized = false;
89
+ const direct = new EngineKnowledgeClient({ layout, engineUrl: `http://127.0.0.1:${server.address().port}` });
90
+ assert.deepEqual(await direct.request('search', {}, runtime.resolveProject({ projectId })), payload);
91
+ assert.equal(calls.at(-1).route, '/api/search');
92
+ wrongBinding = true;
93
+ await assert.rejects(direct.request('search', {}, runtime.resolveProject({ projectId })), e => e.code === 'ENGINE_IDENTITY_MISMATCH');
94
+ wrongBinding = false;
95
+ for (const engineUrl of ['http://example.com', 'http://secret@127.0.0.1', 'http://127.0.0.1/?apiKey=secret', 'file:///private']) {
96
+ const unsafe = new EngineKnowledgeClient({ layout, engineUrl });
97
+ await assert.rejects(unsafe.request('search', {}, runtime.resolveProject({ projectId })), e => e.code === 'ENGINE_URL_INVALID' && !e.message.includes('secret'));
98
+ }
99
+ await assert.rejects(direct.request('../runtime-config', {}, {}), e => e.code === 'INVALID_ARGUMENT');
100
+ await assert.rejects(runtime.search({ projectId, scope: 'another-brain' }), e => e.code === 'INVALID_ARGUMENT');
101
+ const unavailable = new EngineKnowledgeClient({ layout, fetchImpl: async () => { throw new Error('private-test-secret'); } });
102
+ await assert.rejects(unavailable.request('search', {}, runtime.resolveProject({ projectId })), e => e.code === 'ENGINE_UNAVAILABLE' && !e.message.includes('private-test-secret'));
103
+ console.log('knowledge-engine-client-test PASS (native runtime, CLI and MCP share engine facts)');
104
+ } finally { await runtime.close(); server.closeAllConnections(); await new Promise(resolve => server.close(resolve)); fs.rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); }
105
+ })().catch(error => { console.error(error); process.exitCode = 1; });
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const { spawnServer } = require('./helpers/spawn-server');
6
+ const freePort = require('./helpers/free-port');
7
+ const { readEndpoint } = require('../lib/runtime-endpoint');
8
+
9
+ (async () => {
10
+ const port = await freePort();
11
+ const spawned = spawnServer({ root: path.resolve(__dirname, '../..'), port, tag: 'graceful-cleanup' });
12
+ let stopped = false;
13
+ try {
14
+ for (let attempt = 0; attempt < 100; attempt++) {
15
+ const endpoint = readEndpoint(spawned.dataDir);
16
+ if (endpoint && (await fetch(`http://127.0.0.1:${port}/api/health`).catch(() => null))?.ok) break;
17
+ await new Promise(resolve => setTimeout(resolve, 100));
18
+ }
19
+ assert.equal(readEndpoint(spawned.dataDir)?.pid, spawned.child.pid);
20
+ let output = '';
21
+ spawned.child.stderr.on('data', bytes => { output += bytes; });
22
+ await spawned.cleanup(); stopped = true;
23
+ assert.notEqual(spawned.child.exitCode, null, output);
24
+ assert.equal(spawned.child.signalCode, null, 'normal cleanup must drain the server instead of force killing it');
25
+ assert.equal(spawned.child.exitCode, 0, output);
26
+ assert.ok(!fs.existsSync(spawned.dataDir));
27
+ assert.ok(!fs.existsSync(spawned.bridgeHome));
28
+ await assert.rejects(fetch(`http://127.0.0.1:${port}/api/health`));
29
+ console.log('test-server-cleanup-test PASS (verified graceful shutdown before fixture removal)');
30
+ } finally { if (!stopped) await spawned.cleanup(); }
31
+ })().catch(error => { console.error(error); process.exitCode = 1; });
@@ -11,6 +11,7 @@ for (const view of ['home', 'work', 'search', 'memory', 'projects', 'activity'])
11
11
  assert.ok(html.includes(`id="view-${view}"`));
12
12
  }
13
13
  assert.equal((html.match(/data-view=/g) || []).length, 6, 'diagnostics must not become another primary product');
14
+ assert.match(html, /<select\b[^>]*id="projectSelect"[^>]*\bdisabled\b/, 'project selection is disabled until the initial registry snapshot has loaded');
14
15
  for (const id of ['workFrame', 'vectorFrame', 'bridgeFrame', 'engineFrame', 'importDialog', 'importCode', 'importKnowledge', 'importDomain', 'setupImportRoot', 'createDomain', 'logsDialog', 'systemDrawer', 'copyReference']) assert.equal((html.match(new RegExp(`id="${id}"`, 'g')) || []).length, 1);
15
16
  assert.ok(html.includes('data-action="import"') && html.includes('不分析全部历史'));
16
17
  assert.ok(!html.includes('srcdoc') && !/data-simulate|data-analyze|data-install-hook/.test(html));
@@ -71,6 +71,11 @@ const ERROR_CODES = Object.freeze([
71
71
  'KNOWLEDGE_WRITE_MOVED',
72
72
  'MODEL_CONFIG_MOVED',
73
73
  'MODULE_UNREACHABLE',
74
+ 'ENGINE_UNAVAILABLE',
75
+ 'ENGINE_IDENTITY_MISMATCH',
76
+ 'ENGINE_INVALID_RESPONSE',
77
+ 'ENGINE_REQUEST_FAILED',
78
+ 'ENGINE_URL_INVALID',
74
79
  ]);
75
80
 
76
81
  const IMMUTABLE_PROJECT_FIELDS = Object.freeze([
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+ const { DomainError } = require('./contracts');
3
+ const endpoint = require('./runtime-endpoint');
4
+ const control = require('./runtime-control');
5
+
6
+ class EngineKnowledgeClient {
7
+ constructor({ layout, engineUrl, fetchImpl = fetch, timeoutMs = 20000 }) {
8
+ this.layout = layout;
9
+ this.engineUrl = engineUrl || process.env.KB_KNOWLEDGE_ENGINE_URL;
10
+ this.fetch = fetchImpl;
11
+ this.timeoutMs = timeoutMs;
12
+ }
13
+
14
+ async json(url, options = {}) {
15
+ let response;
16
+ try { response = await this.fetch(url, { ...options, redirect: 'error', signal: AbortSignal.timeout(this.timeoutMs) }); }
17
+ catch { throw new DomainError('ENGINE_UNAVAILABLE', '知识引擎连接失败或超时,请在系统状态中检查服务。', { status: 503 }); }
18
+ let payload;
19
+ try {
20
+ const reader = response.body.getReader();
21
+ const chunks = []; let size = 0;
22
+ try {
23
+ while (true) {
24
+ const part = await reader.read(); if (part.done) break;
25
+ size += part.value.byteLength;
26
+ if (size > 2 * 1024 * 1024) { await reader.cancel(); throw new Error('response limit'); }
27
+ chunks.push(Buffer.from(part.value));
28
+ }
29
+ } finally { reader.releaseLock(); }
30
+ payload = JSON.parse(Buffer.concat(chunks).toString('utf8'));
31
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload)) throw new Error('invalid envelope');
32
+ } catch { throw new DomainError('ENGINE_INVALID_RESPONSE', '知识引擎返回了无效响应。', { status: 502 }); }
33
+ if (!response.ok || payload.ok === false) {
34
+ const code = /^[A-Z][A-Z0-9_]{0,79}$/.test(payload.error?.code || '') ? payload.error.code : 'ENGINE_REQUEST_FAILED';
35
+ throw new DomainError(code, '知识引擎未完成读取,请检查项目接线或请求参数。', { status: response.ok ? 502 : response.status });
36
+ }
37
+ return payload;
38
+ }
39
+
40
+ async target(project) {
41
+ if (this.engineUrl) {
42
+ let url; try { url = new URL(this.engineUrl); } catch {}
43
+ if (!url || !['http:', 'https:'].includes(url.protocol) || !endpoint.isLoopbackHost(url.hostname.replace(/^\[|\]$/g, '')) || url.username || url.password || url.search || url.hash || !['', '/'].includes(url.pathname)) throw new DomainError('ENGINE_URL_INVALID', '知识引擎地址必须是无凭据的本机服务地址。');
44
+ const health = await this.json(new URL('/api/health', url));
45
+ const registered = await this.json(new URL('/api/projects', url));
46
+ const match = registered.projects?.find(item => item.projectId === project.projectId && item.enabled !== false);
47
+ if (health.name !== 'knowledge-engine' || health.dataSchemaVersion !== 3 || !match || !this.layout.pathsEqual(match.repoPath, project.repoPath) || !this.layout.pathsEqual(match.knowledgePath, project.knowledgePath)) throw new DomainError('ENGINE_IDENTITY_MISMATCH', '知识引擎与当前项目目录绑定不匹配。', { status: 409 });
48
+ return { url, prefix: '/api' };
49
+ }
50
+ const live = endpoint.readLiveEndpoint(this.layout.getDataDir(), { removeStale: false });
51
+ if (!live) throw new DomainError('ENGINE_UNAVAILABLE', '知识库服务尚未运行,请先启动 project-knowledge。', { status: 503 });
52
+ const url = new URL(`http://${live.host.includes(':') ? `[${live.host}]` : live.host}:${live.port}`);
53
+ const identity = await this.json(new URL('/api/runtime/identity', url));
54
+ if (identity.schema !== control.SCHEMA || identity.name !== 'project-knowledge' || identity.pid !== live.pid || identity.port !== live.port || identity.startedAt !== live.startedAt || !identity.dataDir || !this.layout.pathsEqual(identity.dataDir, this.layout.getDataDir())) throw new DomainError('ENGINE_IDENTITY_MISMATCH', '知识库实例与当前数据目录不匹配,已拒绝读取。', { status: 409 });
55
+ return { url, prefix: '/api/engine' };
56
+ }
57
+
58
+ async request(action, input, project) {
59
+ if (!['search', 'ask', 'get', 'history'].includes(action)) throw new DomainError('INVALID_ARGUMENT', '仅支持知识读取操作。');
60
+ if (input.scope !== undefined && !['project', 'domain', 'brain'].includes(input.scope)) throw new DomainError('INVALID_ARGUMENT', '知识范围必须是项目、领域或智脑。');
61
+ const target = await this.target(project);
62
+ // Forward only the read contract, never profiles, credentials or context objects.
63
+ const body = { projectId: project.projectId };
64
+ for (const key of ['query', 'limit', 'entryId', 'entry', 'scope', 'spaceId']) if (input[key] !== undefined) body[key] = input[key];
65
+ if (body.spaceId === undefined && input.space !== undefined) body.spaceId = input.space;
66
+ const result = await this.json(new URL(`${target.prefix}/${action}`, target.url), { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
67
+ const valid = action === 'get' ? Array.isArray(result.chunks) : Array.isArray(result.results);
68
+ if (result.ok !== true || !valid || (action === 'ask' && (typeof result.answer !== 'string' || !Array.isArray(result.citations)))) throw new DomainError('ENGINE_INVALID_RESPONSE', '知识引擎返回了无效读取结果。', { status: 502 });
69
+ return result;
70
+ }
71
+ }
72
+ module.exports = { EngineKnowledgeClient };
@@ -12,6 +12,7 @@ const { EMBEDDING_DIMENSIONS } = require('./knowledge-schema');
12
12
  const { DomainError } = require('./contracts');
13
13
  const { KnowledgeRetrievalService } = require('./knowledge-retrieval-service');
14
14
  const { ConversationStore } = require('./conversation-store');
15
+ const { EngineKnowledgeClient } = require('./engine-knowledge-client');
15
16
 
16
17
  function gitRoot(candidate) {
17
18
  const resolved = path.resolve(candidate || process.cwd());
@@ -97,6 +98,7 @@ class KnowledgeToolRuntime {
97
98
  this.settingsStore = options.settingsStore || new SettingsStore({ layout: this.layout });
98
99
  this.registryStore = options.registryStore || new ProjectRegistryStore({ layout: this.layout });
99
100
  this.projectStore = options.projectStore || new ProjectStore({ layout: this.layout });
101
+ this.engineClient = options.engineClient || new EngineKnowledgeClient({ layout: this.layout, engineUrl: options.engineUrl, fetchImpl: options.fetchImpl });
100
102
  this.database = null;
101
103
  this.embedder = null;
102
104
  this.conversationStore = options.conversationStore || new ConversationStore({
@@ -279,10 +281,13 @@ class KnowledgeToolRuntime {
279
281
 
280
282
  async search(input = {}) {
281
283
  const project = this.resolveProject(input);
284
+ if (this.projectStore.readState(project.projectId).modules?.engine) return this.engineClient.request('search', input, project);
282
285
  return this.retrievalService.search({ ...input, project });
283
286
  }
284
287
 
285
288
  async ask(input = {}) {
289
+ const project = this.resolveProject(input);
290
+ if (this.projectStore.readState(project.projectId).modules?.engine) return this.engineClient.request('ask', input, project);
286
291
  const searched = await this.search(input);
287
292
  const citations = searched.results.slice(0, 5).map((result, index) => ({
288
293
  index: index + 1,
@@ -300,6 +305,7 @@ class KnowledgeToolRuntime {
300
305
 
301
306
  async get(input = {}) {
302
307
  const project = this.resolveProject(input);
308
+ if (this.projectStore.readState(project.projectId).modules?.engine) return this.engineClient.request('get', input, project);
303
309
  const entryId = String(input.entryId || input.entry || '').trim().replace(/\\/g, '/');
304
310
  if (!entryId) throw new DomainError('INVALID_ARGUMENT', 'entry is required.');
305
311
  const target = path.resolve(project.knowledgePath, ...entryId.split('/'));
@@ -321,6 +327,7 @@ class KnowledgeToolRuntime {
321
327
 
322
328
  async history(input = {}) {
323
329
  const project = this.resolveProject(input);
330
+ if (this.projectStore.readState(project.projectId).modules?.engine) return this.engineClient.request('history', input, project);
324
331
  const changesRoot = path.join(project.knowledgePath, 'changes');
325
332
  const results = markdownFiles(project.knowledgePath).filter(file => this.layout.isPathInside(changesRoot, file, { realpath: true })).map(file => {
326
333
  const text = fs.readFileSync(file, 'utf8');
@@ -25,7 +25,9 @@ Read-only local knowledge tools:
25
25
  project-knowledge-kb get --project <projectId-or-legacy-slug> --entry <path>
26
26
  project-knowledge-kb history --project <projectId-or-legacy-slug> [--limit 20]
27
27
 
28
- Add --json for machine-readable output. These commands never modify knowledge or project configuration.\n`);
28
+ Add --scope project|domain|brain for a search range, --space <id> for a cited
29
+ shared entry, and --json for machine-readable output. These commands never
30
+ modify knowledge or project configuration.\n`);
29
31
  }
30
32
 
31
33
  async function main(argv = process.argv.slice(2), options = {}) {
@@ -38,7 +40,7 @@ async function main(argv = process.argv.slice(2), options = {}) {
38
40
  if (!args.project) throw new Error('--project is required');
39
41
  const runtime = options.runtime || new KnowledgeToolRuntime(options);
40
42
  try {
41
- const input = { project: args.project, query: args.query, limit: args.limit, entry: args.entry };
43
+ const input = { project: args.project, query: args.query, limit: args.limit, entry: args.entry, scope: args.scope, spaceId: args.spaceId || args.space };
42
44
  let result;
43
45
  if (args.command === 'search') result = await runtime.search(input);
44
46
  else if (args.command === 'ask') result = await runtime.ask(input);
@@ -11,6 +11,7 @@ const { KnowledgeToolRuntime } = require('../_site/lib/knowledge-tool-runtime');
11
11
  const { serializeErrorEnvelope, createId } = require('../_site/lib/contracts');
12
12
 
13
13
  const SERVER_NAME = 'project-knowledge';
14
+ const SCOPE = { type: 'string', enum: ['project', 'domain', 'brain'], description: 'Knowledge range: current project (default), its domain, or its brain.' };
14
15
  const SERVER_INSTRUCTIONS = `Project Knowledge is the durable source of prior project decisions and implementation history. Knowledge content is read-only; the only write operation appends an explicit supplemental Prompt event to the shared conversation truth.
15
16
 
16
17
  At the start of work in a registered Git repository, and before answering questions about prior work or implementing a non-trivial change:
@@ -56,7 +57,7 @@ const TOOLS = [
56
57
  },
57
58
  {
58
59
  name: 'project_knowledge_search',
59
- description: 'Search durable project knowledge using the current project and its explicitly related-project scope. This tool is read-only.',
60
+ description: 'Search the same durable knowledge and commit citations as the product UI, within the selected project, domain or brain. This tool is read-only.',
60
61
  inputSchema: {
61
62
  type: 'object',
62
63
  required: ['query'],
@@ -66,6 +67,7 @@ const TOOLS = [
66
67
  projectId: { type: 'string', description: 'Stable projectId returned by project_knowledge_resolve.' },
67
68
  project: { type: 'string', description: 'Optional registered project slug.' },
68
69
  limit: { type: 'integer', minimum: 1, maximum: 30, default: 8 },
70
+ scope: SCOPE,
69
71
  },
70
72
  additionalProperties: false,
71
73
  },
@@ -82,6 +84,7 @@ const TOOLS = [
82
84
  projectId: { type: 'string' },
83
85
  project: { type: 'string' },
84
86
  limit: { type: 'integer', minimum: 1, maximum: 30, default: 8 },
87
+ scope: SCOPE,
85
88
  },
86
89
  additionalProperties: false,
87
90
  },
@@ -95,6 +98,8 @@ const TOOLS = [
95
98
  properties: {
96
99
  entry: { type: 'string', minLength: 1, description: 'Entry identifier returned by search.' },
97
100
  space: { type: 'string', description: 'Optional scoped knowledge space identifier.' },
101
+ spaceId: { type: 'string', description: 'Knowledge space identifier returned by a citation; alias of space.' },
102
+ scope: SCOPE,
98
103
  repoPath: { type: 'string' },
99
104
  projectId: { type: 'string' },
100
105
  project: { type: 'string' },
@@ -112,6 +117,7 @@ const TOOLS = [
112
117
  projectId: { type: 'string' },
113
118
  project: { type: 'string' },
114
119
  limit: { type: 'integer', minimum: 1, maximum: 100, default: 20 },
120
+ scope: SCOPE,
115
121
  },
116
122
  additionalProperties: false,
117
123
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": "project-knowledge/module-content/v1",
3
3
  "productFiles": {
4
- "ui/index.html": "db9cc5624132d336ee6b31ba37c93572b89e382f68e4b6331b4b886be8253bb5",
4
+ "ui/index.html": "0cb319212230af66f3530bb1b57915894f41789f1ea1c57bb8ae54b0f01164a8",
5
5
  "ui/product.js": "50d26a9aa3a95889804f8ca771dada9e1ea89d6956851e58dadf119a75842b9c",
6
6
  "ui/product.css": "3f89daeb52c5f1ed8a79150c9a84200187474a013fd97c6d7c8799d850e5b0b7",
7
7
  "ui/favicon.svg": "c48be946b224112ebb0238b44263f7a61bda31e531afa895c2e9801c0ff24f32"
@@ -10,10 +10,10 @@
10
10
  "terminal": {
11
11
  "name": "@sanqianx/claude-ai-workbench",
12
12
  "installName": "claude-ai-workbench",
13
- "version": "0.13.2-rc.1",
13
+ "version": "0.13.2-rc.2",
14
14
  "files": {
15
15
  "LICENSE": "c1b9df1275e769f3dbab000d1e457a2d4b0f28eb5da6c77e48dc37eeba202ed7",
16
- "README.md": "7efdf88b6eabdd3280fe69b6b78fce4ad9c1b5373ed5fc59e2a3db39d3f774d0",
16
+ "README.md": "f2e3bf656a5fc82588881691fc570fceb1e0ab6b47c6124ed26a538915887543",
17
17
  "apps/agent-terminal/app.css": "39cc65ac65bcb390f4aa21d9b783182ca229557f6bec15090f69598120161917",
18
18
  "apps/agent-terminal/app.js": "2fedcc79f9515ebae89d1c7dc996d732aa1d0946038eaaa045438121bf27f551",
19
19
  "apps/agent-terminal/index.html": "6a52ba210696c8aed99e2786e21d2771340070d51583199dd74c8da41edf0257",
@@ -27,20 +27,20 @@
27
27
  "apps/minimal-test-host/README.md": "fa73136f4ee3865c2d91eb97b2e8c03679aa4688e44c1e1c8ec6e27d604b0de5",
28
28
  "docs/sdk/FILE_LAYOUT.md": "17882f96505c8161bfb66876684b9d2d3f50021a111b8b844502d3cb4e97870a",
29
29
  "docs/sdk/INTEGRATION.md": "d4c0c80d2d2fc610205102d703a429bfaa20f9f3a48f1718f5bab02ee90138df",
30
- "docs/sdk/openapi.yaml": "c14dd8a1989a6fbb748285d8b488f553e5673d52ff2439c124c435f65a57b570",
30
+ "docs/sdk/openapi.yaml": "1961c83c7992a02ecf942d9eb9dd3632af34daac2fefc059943acc130b7ca45a",
31
31
  "docs/sdk/README.md": "7ab591d39c36a3b84cfdf487ff567040ec453975f3ef0fba86dc822094667b61",
32
- "package.json": "21b1d94149a71e9678e4a50c3146d292c2672f206ef621ae919850b67660804b",
32
+ "package.json": "c1109d568b15616b7e38014463265459beddab822a5f3bfa2ff9edb25c5a1b53",
33
33
  "packages/client/index.d.ts": "fb66b7b21ac936cddcb7f74543cf4f3bb7e80c169534ec249ab8ef2356224162",
34
34
  "packages/client/index.js": "92fe5ddd32289d729f336f669e47bd9601e562f5a4309ee4fa7f7f15b567edc2",
35
- "packages/client/package.json": "5b5ea236e6a0769fd71b32759e0d87a33b84f4211ad298fe60452e5e8cb8bc3d",
35
+ "packages/client/package.json": "02af5ac530c8d5974d3425961acb98312c005f6e9729603392ea53109b3a57cc",
36
36
  "packages/client/README.md": "342dff9b1dcbc85fccc9b980ed3e4e455aa71133af1d0805b8431ea2ac564ef8",
37
37
  "packages/contracts/index.d.ts": "edc717067bfb864c6c95df0c408a799fbf90b7552519131e6dc35af3f9eb9006",
38
38
  "packages/contracts/index.js": "565b4a88190dbb8994cd0a9309b30b00f64305d65505fff9fa360d7ce69dfb58",
39
- "packages/contracts/package.json": "95887ef01fa0e1ccc4f8e22089bfabe8252566e38cbfb8aef0882cfe8fe22e61",
39
+ "packages/contracts/package.json": "7a84f54780c27c9c862b4c0f1071be7d9b8af86cbbcb0fa6358dcb8e4c504b88",
40
40
  "packages/contracts/README.md": "44d83a3cc508cec6c5c20dfa1f2c08d5ea03e3afb2853639fdc0a9cc8eb5b9c8",
41
41
  "packages/core/index.d.ts": "c95b24a13f8aeeb128497833cf298790563baca6036ea5d29a9d8daff53199d7",
42
42
  "packages/core/index.js": "5579ceb1a63d3f962f5656c75f82cf60cd834fd270b4aa95e581bf38e4432448",
43
- "packages/core/package.json": "d21084880b3d52e371d208c071ec94a3df456ea483055acc4a65b1aa7ec2fb9a",
43
+ "packages/core/package.json": "c699e3ab0453dd528d6a1a85a95b15c61957da4674bd8eb79ec6c4c3babf99de",
44
44
  "packages/core/README.md": "e222c546104a168f1038d95c6c4efb8e5603edd6145ab2cab79cab977fb710e5",
45
45
  "packages/server/bin/agent-terminal-server.js": "b01297ab245a2b994bf42043b7469bd6e71d8f76a4bb99d4ed651e71844c152f",
46
46
  "packages/server/bin/claude-workbench-server.js": "a8c46ed7e71afcc10e00a104ed6f2d0ac05346a743b33c3a5bd11b1314d80f40",
@@ -59,7 +59,7 @@
59
59
  "packages/server/lib/drivers/cli-json-runner.js": "c3febcea2df92b72125d053a4ffe6349e61caa98491acb6123ae964b6b90de8a",
60
60
  "packages/server/lib/drivers/codex-driver.js": "cb6f60048af534d836c7e95c494fbd16aa28ba24c5e94d76edb2eb9720f4cb54",
61
61
  "packages/server/lib/drivers/opencode-driver.js": "119b11663d926a3f5f7c63c960264784879459b3f84e6fdf482b4346697a6376",
62
- "packages/server/lib/drivers/zcode-driver.js": "507dcd56e17066703f2467a96bb3c9efca6b7b1810a78d607ac576508e8d4615",
62
+ "packages/server/lib/drivers/zcode-driver.js": "6204a174de7a3735c86a902350c17edbd596bd22eb15c69f4de44fe2b77b51a9",
63
63
  "packages/server/lib/event-stream.js": "b0f20bac19933a1a428c22938ae2666a1231b74a4330619b885171662133f48b",
64
64
  "packages/server/lib/folder-picker.js": "70f55df999262b90433f2b4251aa69dd70a23b55a84756b5f1d24dbeacfbda31",
65
65
  "packages/server/lib/http-handler.js": "c0b1cc19c66beef0f0d9b8db48ede6b110bff59d410b81673bab2e81c05b01d7",
@@ -71,8 +71,8 @@
71
71
  "packages/server/lib/session-archive-store.js": "d3335b832a6e9fb9792991056f6596a997a4959efa6e62b60fb60133fb724196",
72
72
  "packages/server/lib/system-doctor.js": "2b0e858d69d8fb268eaed950c9883473ee9850684b532bc2db8e14674a974919",
73
73
  "packages/server/lib/ui-preferences-store.js": "e108cb22e7cc1f3438704913d5401e01de2c0e717eb2abd3bdc4727209393819",
74
- "packages/server/lib/workbench-service.js": "b5caac09665b21a118a0cd826adfa3f3006e68989182e4d80bf3a4554b951250",
75
- "packages/server/package.json": "77ded7b6683df90e731a0f0204ea56698a19f2a138959bee18355ba987eb04c2",
74
+ "packages/server/lib/workbench-service.js": "c1d1148b9b55b2701b6513f7cf1e2724569a8055e1431a05642ed620d8de7cfd",
75
+ "packages/server/package.json": "9e07de268280ea80f7490bec6b6afd1756a570b0f35a4edf8930b8742e9a36cc",
76
76
  "packages/server/README.md": "a34cfaa4f4e859008b44e2be8e1aafb56e97fe83e6129c968a8562945fa843f3",
77
77
  "packages/ui/ai-profile-settings.d.ts": "0551b6c6eda6d18ea89a976daddf01b2161195f4874fe2d67a57cd9ecc6ce643",
78
78
  "packages/ui/ai-profile-settings.js": "e92bbac67a1199d473e4e44b32d1cc76c5b6c79306d4fef9d9067a1bb6ec42ca",
@@ -80,7 +80,7 @@
80
80
  "packages/ui/claude-terminal.js": "96bd217a4a7e4792ae3fbaaf46249ecee13b0f4e01fc6d25a1b8b22d8f8fe00c",
81
81
  "packages/ui/index.d.ts": "e547ab39640fe7519fb367b78442dc8a2c51b2efd17b66f8b0a003b154b36ead",
82
82
  "packages/ui/index.js": "f4394aabd395938f5c3fe587e430471d4033e83945a9b9c7e0149ad4040982c9",
83
- "packages/ui/package.json": "47418b48345efd2099b5b0861eed4a04db8cfe613efc95cec4aa181c373af72c",
83
+ "packages/ui/package.json": "f8840a1425921e6c2698a5480467e4e484bc5ba1fdfed5c32d5e75c40796b973",
84
84
  "packages/ui/README.md": "793c4a9c286fee23f39062a1976ca3afe9d2816dcdb55e156ba940e1ef514f89",
85
85
  "packages/ui/theme.css": "8f03a081272a7db11b196f7a70d0fafb1f8d954778f329f1ba53d110d9d5fd98",
86
86
  "src/assets/claude-prompts.json": "cb111f2e0a45afe8a31c251a504d1ab5375966ed61291660e61fd2efd77f6d9f",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanqianx/project-knowledge",
3
- "version": "5.0.9-rc.2",
3
+ "version": "5.0.9-rc.4",
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": {
@@ -84,7 +84,7 @@
84
84
  "@sanqianx/vector-hub": "1.0.8-rc.1",
85
85
  "buffer": "^6.0.3",
86
86
  "cheerio": "^1.2.0",
87
- "claude-ai-workbench": "npm:@sanqianx/claude-ai-workbench@0.13.2-rc.1",
87
+ "claude-ai-workbench": "npm:@sanqianx/claude-ai-workbench@0.13.2-rc.2",
88
88
  "cross-spawn": "7.0.6",
89
89
  "dotenv": "^17.4.2",
90
90
  "gpt-tokenizer": "^3.4.0",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
3
3
  "name": "project-knowledge",
4
- "version": "5.0.9-rc.2",
4
+ "version": "5.0.9-rc.4",
5
5
  "description": "Read durable project decisions and implementation history from Project Knowledge.",
6
6
  "author": {
7
7
  "name": "SanQianX",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-knowledge",
3
- "version": "5.0.9-rc.2",
3
+ "version": "5.0.9-rc.4",
4
4
  "description": "Read durable project decisions and implementation history from Project Knowledge.",
5
5
  "author": {
6
6
  "name": "SanQianX",
@@ -6,7 +6,7 @@
6
6
  "args": [
7
7
  "-y",
8
8
  "--package",
9
- "@sanqianx/project-knowledge@5.0.9-rc.2",
9
+ "@sanqianx/project-knowledge@5.0.9-rc.4",
10
10
  "project-knowledge-mcp"
11
11
  ]
12
12
  }
package/ui/index.html CHANGED
@@ -20,7 +20,7 @@
20
20
  <button id="openSystem" class="system-button"><span class="dot" id="systemDot"></span><span><b id="systemTitle">正在检查系统</b><small id="systemDetail">本机知识服务</small></span><svg viewBox="0 0 24 24"><path d="m9 6 6 6-6 6"/></svg></button>
21
21
  </aside>
22
22
  <main>
23
- <header class="topbar"><div><small id="breadcrumb">我的智脑</small><h1 id="pageTitle">智脑首页</h1></div><div class="spacer"></div><select id="projectSelect" aria-label="当前项目"><option value="">尚未导入项目</option></select><button id="themeToggle" class="icon-button" title="切换浅色或深色主题" aria-label="切换主题"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3"/></svg></button></header>
23
+ <header class="topbar"><div><small id="breadcrumb">我的智脑</small><h1 id="pageTitle">智脑首页</h1></div><div class="spacer"></div><select id="projectSelect" aria-label="当前项目" disabled><option value="">尚未导入项目</option></select><button id="themeToggle" class="icon-button" title="切换浅色或深色主题" aria-label="切换主题"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3"/></svg></button></header>
24
24
  <div class="content">
25
25
  <section class="view" id="view-home"><div class="welcome"><div><small>工作概览</small><h2 id="homeTitle">我的智脑</h2><p>保存项目事实,连接相关经验。你的长期偏好,只在确认后使用。</p></div><div class="actions"><button class="primary" data-go="work">开始工作</button><button data-action="import">导入项目</button></div></div><div id="homeContent"></div></section>
26
26
  <section class="view module-view" id="view-work"><div id="workEmpty" class="empty" hidden>导入项目后,就可以在这里开始工作。<button data-action="import">导入项目</button></div><div class="work-layout" id="workLayout"><div class="frame-container"><iframe id="workFrame" title="Agent 工作台" referrerpolicy="same-origin"></iframe></div><aside class="knowledge-context"><header><h2>本次知识引用</h2><small id="contextScope">任务发送前自动检索</small></header><div id="contextContent" class="empty small-empty">发送任务后显示实际检索到的项目事实、领域经验和已确认记忆。</div></aside></div></section>