@sanqianx/project-knowledge 5.1.4 → 5.1.5

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 (37) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +8 -0
  3. package/_site/_test/agent-capture-mcp-ui-test.js +21 -7
  4. package/_site/_test/agent-capture-ui-test.js +4 -3
  5. package/_site/_test/fixtures/integration-busy-worker.cjs +11 -3
  6. package/_site/_test/helpers/parallel-memory-shell.js +13 -2
  7. package/_site/_test/hook-relocation-rebind-test.js +120 -0
  8. package/_site/_test/integration-auto-repair-test.js +3 -1
  9. package/_site/_test/integration-intent-test.js +6 -2
  10. package/_site/_test/integration-runtime-binding-test.js +4 -4
  11. package/_site/_test/integration-status-scan-test.js +138 -7
  12. package/_site/_test/legacy-relocation-recovery-test.js +258 -0
  13. package/_site/_test/parallel-retrieval-followup-corpus-test.js +6 -4
  14. package/_site/_test/project-team-ui-test.js +124 -0
  15. package/_site/_test/recovery-label-contract-test.js +45 -0
  16. package/_site/lib/capture-hook-config.js +16 -7
  17. package/_site/lib/claude-plugin-status.js +60 -0
  18. package/_site/lib/commit-prompt.js +205 -202
  19. package/_site/lib/commit-reconciler.js +551 -444
  20. package/_site/lib/contracts.js +1 -0
  21. package/_site/lib/evidence-bundle.js +32 -5
  22. package/_site/lib/integration-auto-repair.js +3 -2
  23. package/_site/lib/integration-installer.js +153 -71
  24. package/_site/lib/integration-intent.js +12 -5
  25. package/_site/lib/integration-status-scan.js +101 -41
  26. package/_site/lib/integration-status-worker.js +4 -2
  27. package/_site/lib/knowledge-promotion.js +547 -435
  28. package/_site/lib/scanner.js +5 -3
  29. package/_site/lib/server-app.js +34 -7
  30. package/_site/scripts/refresh-runtime-manifest.js +1 -1
  31. package/module-runtime-manifest.json +84 -84
  32. package/package.json +6 -6
  33. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  34. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  35. package/plugins/project-knowledge/.mcp.json +1 -1
  36. package/ui/product.css +1 -0
  37. package/ui/product.js +125 -30
@@ -1,68 +1,114 @@
1
1
  'use strict';
2
2
  const path = require('node:path');
3
3
  const { fork, spawn } = require('node:child_process');
4
- const { IntegrationManager, SUPPORTED_CLIENTS, CLIENT_LABELS } = require('./integration-installer');
4
+ const { IntegrationManager, SUPPORTED_CLIENTS, CLIENT_LABELS, normalizeClient } = require('./integration-installer');
5
+
6
+ function clientSnapshot(entry, captureOnly) {
7
+ const { client, snapshot, promise, error, stale, checkedAt } = entry;
8
+ const state = error ? 'check-failed' : promise ? (snapshot ? 'refreshing' : 'checking') : 'ready';
9
+ const pending = { state: error ? 'check-failed' : 'checking', ok: !error };
10
+ return {
11
+ client,
12
+ label: CLIENT_LABELS[client],
13
+ developmentCapture: { ...pending, detail: error ? '采集状态尚未核实。' : '正在检查采集配置…' },
14
+ ...(!captureOnly ? {
15
+ knowledgeIntegration: { ...pending, detail: error ? '知识插件状态尚未核实。' : '正在检查知识插件…' },
16
+ automaticContext: { supported: client !== 'opencode', configured: false, state: pending.state, detail: error ? '开发前知识读取尚未核实。' : '正在检查开发前知识读取…' },
17
+ } : {}),
18
+ ...snapshot,
19
+ scan: { state, checkedAt, ...(stale ? { stale } : {}), ...(error ? { error } : {}) },
20
+ };
21
+ }
5
22
 
6
23
  class IntegrationStatusScan {
7
- constructor({ workerFile, timeoutMs = 20000 } = {}) {
24
+ constructor({ workerFile, timeoutMs = 30_000 } = {}) {
8
25
  this.workerFile = workerFile || path.join(__dirname, 'integration-status-worker.js');
9
26
  this.timeoutMs = timeoutMs; this.entries = new Map(); this.children = new Set(); this.generation = 0;
10
27
  this.queue = []; this.running = 0; this.closed = false;
11
28
  }
12
29
  async read(managerOptions, statusOptions = {}, { force = false, waitMs = 500 } = {}) {
13
30
  if (managerOptions.runner || managerOptions.commandResolver || managerOptions.bridgeModule || managerOptions.codexHookProbe) return new IntegrationManager(managerOptions).statusAll(statusOptions);
14
- const key = JSON.stringify([managerOptions.rootDir, managerOptions.homeDir, managerOptions.bridgeHomeDir, statusOptions.cwd, statusOptions.captureOnly, statusOptions.clients]);
15
- let entry = this.entries.get(key);
16
- if (!entry || !entry.promise && (force || Date.now() - entry.at > 30000)) {
17
- entry = { at: Date.now(), generation: ++this.generation, summary: entry?.summary || null, promise: null };
18
- entry.promise = this.run(managerOptions, statusOptions).then(summary => { entry.summary = summary; entry.at = Date.now(); return summary; }, error => {
19
- if (entry.summary) {
20
- entry.summary = { ...entry.summary, stale: true, error: { code: error.code || 'INTEGRATION_STATUS_FAILED' } };
21
- return entry.summary;
22
- }
23
- entry.summary = { bridge: { ok: false, state: 'check-failed', detail: '接入状态检查失败或超时,未将其判为未安装。' },
24
- clients: (statusOptions.clients || SUPPORTED_CLIENTS).map(client => ({ client, label: CLIENT_LABELS[client],
25
- knowledgeIntegration: { ok: false, state: 'check-failed', detail: '检查未完成,请重试。' }, automaticContext: { supported: client !== 'opencode', configured: false, state: 'check-failed', detail: '检查未完成,不代表客户端未接入。' },
26
- developmentCapture: { ok: false, state: 'check-failed', detail: '采集状态尚未核实。' } })), error: { code: error.code || 'INTEGRATION_STATUS_FAILED' } };
27
- return entry.summary;
28
- }).finally(() => { entry.promise = null; });
29
- this.entries.set(key, entry);
30
- if (this.entries.size > 100) for (const [oldKey, old] of this.entries) { if (!old.promise && oldKey !== key) { this.entries.delete(oldKey); break; } }
31
- }
32
- if (entry.promise && waitMs > 0) {
31
+ const captureOnly = statusOptions.captureOnly === true;
32
+ const clients = statusOptions.clients?.length ? [...new Set(statusOptions.clients.map(normalizeClient))] : SUPPORTED_CLIENTS;
33
+ const owner = [managerOptions.rootDir, managerOptions.homeDir, managerOptions.bridgeHomeDir, captureOnly];
34
+ const entries = clients.map(client => this.schedule(
35
+ [...owner, client, ['claude', 'codex'].includes(client) ? statusOptions.cwd : null],
36
+ managerOptions, { ...statusOptions, clients: [client], includeShared: false }, client, force,
37
+ ));
38
+ const shared = this.schedule([...owner, 'shared'], managerOptions, { captureOnly, sharedOnly: true }, null, force && !statusOptions.clients?.length);
39
+ const jobs = [...entries, shared];
40
+ const pending = jobs.map(entry => entry.promise).filter(Boolean);
41
+ if (pending.length && waitMs > 0) {
33
42
  let timer;
34
- await Promise.race([entry.promise, new Promise(resolve => { timer = setTimeout(resolve, waitMs); })]); clearTimeout(timer);
43
+ await Promise.race([Promise.all(pending), new Promise(resolve => { timer = setTimeout(resolve, waitMs); })]);
44
+ clearTimeout(timer);
45
+ }
46
+ const error = jobs.find(entry => entry.error)?.error;
47
+ const active = jobs.some(entry => entry.promise);
48
+ const hasResults = entries.some(entry => entry.snapshot);
49
+ return {
50
+ ...shared.snapshot,
51
+ bridge: shared.snapshot?.bridge || { ok: !shared.error, state: shared.error ? 'check-failed' : 'checking' },
52
+ clients: entries.map(entry => clientSnapshot(entry, captureOnly)),
53
+ ...(error ? { error } : {}),
54
+ scan: {
55
+ state: active ? (hasResults ? 'refreshing' : 'checking') : 'ready',
56
+ generation: Math.max(...jobs.map(entry => entry.generation)),
57
+ updatedAt: Math.max(...jobs.map(entry => entry.at)),
58
+ },
59
+ };
60
+ }
61
+
62
+ schedule(parts, managerOptions, statusOptions, client, force) {
63
+ const key = JSON.stringify(parts);
64
+ const previous = this.entries.get(key);
65
+ if (previous && (previous.promise || !force && Date.now() - previous.at <= 30_000)) return previous;
66
+ const entry = { client, generation: ++this.generation, at: Date.now(),
67
+ snapshot: previous?.snapshot, checkedAt: previous?.checkedAt, stale: Boolean(previous?.snapshot) };
68
+ const publish = snapshot => {
69
+ entry.snapshot = snapshot;
70
+ entry.checkedAt = new Date().toISOString();
71
+ entry.stale = false;
72
+ };
73
+ entry.promise = this.run(managerOptions, statusOptions, partial => {
74
+ if (client === partial?.client) publish(partial);
75
+ }).then(summary => {
76
+ const snapshot = client ? summary?.clients?.find(row => row.client === client) : summary;
77
+ if (snapshot) publish(snapshot);
78
+ else entry.error = { code: 'INTEGRATION_STATUS_INCOMPLETE' };
79
+ }, error => {
80
+ entry.error = { code: error.code || 'INTEGRATION_STATUS_FAILED' };
81
+ }).finally(() => { entry.promise = null; entry.at = Date.now(); });
82
+ this.entries.set(key, entry);
83
+ if (this.entries.size > 100) for (const [oldKey, old] of this.entries) {
84
+ if (!old.promise && oldKey !== key) { this.entries.delete(oldKey); break; }
35
85
  }
36
- const pending = entry.promise !== null;
37
- if (entry.summary) return { ...entry.summary, scan: { state: pending ? 'refreshing' : 'ready', generation: entry.generation, updatedAt: entry.at } };
38
- return { bridge: { ok: true, state: 'checking' }, clients: (statusOptions.clients || SUPPORTED_CLIENTS).map(client => ({ client, label: CLIENT_LABELS[client],
39
- configFound: new IntegrationManager(managerOptions).captureConfigFound(client),
40
- knowledgeIntegration: { ok: true, state: 'checking', detail: '正在检查接入状态…' },
41
- automaticContext: { supported: client !== 'opencode', configured: false, state: 'checking', detail: '正在检查开发前知识读取…' },
42
- developmentCapture: { ok: true, state: 'checking', detail: '正在检查采集…' } })), scan: { state: 'checking', generation: entry.generation } };
86
+ return entry;
43
87
  }
44
- run(managerOptions, statusOptions) {
88
+
89
+ run(managerOptions, statusOptions, onPartial) {
45
90
  return new Promise((resolve, reject) => {
46
91
  if (this.closed || this.queue.length >= 64) { reject(Object.assign(new Error('状态检查暂不可用。'), { code: this.closed ? 'INTEGRATION_STATUS_CLOSED' : 'INTEGRATION_STATUS_BUSY' })); return; }
47
- this.queue.push({ managerOptions, statusOptions, resolve, reject }); this.drain();
92
+ this.queue.push({ managerOptions, statusOptions, onPartial, resolve, reject }); this.drain();
48
93
  });
49
94
  }
50
95
  drain() {
51
- while (!this.closed && this.running < 2 && this.queue.length) {
96
+ while (!this.closed && this.running < SUPPORTED_CLIENTS.length && this.queue.length) {
52
97
  const next = this.queue.shift(); this.running++;
53
- this.probe(next.managerOptions, next.statusOptions).then(next.resolve, next.reject).finally(() => { this.running--; this.drain(); });
98
+ this.probe(next.managerOptions, next.statusOptions, next.onPartial).then(next.resolve, next.reject).finally(() => { this.running--; this.drain(); });
54
99
  }
55
100
  }
56
- probe(managerOptions, statusOptions) {
101
+ probe(managerOptions, statusOptions, onPartial) {
57
102
  return new Promise((resolve, reject) => {
58
- const child = fork(this.workerFile, [], { stdio: ['ignore', 'ignore', 'ignore', 'ipc'], windowsHide: true, env: { ...process.env, KB_INTEGRATION_STATUS_WORKER: '1' } });
103
+ const child = fork(this.workerFile, [], { stdio: ['ignore', 'ignore', 'ignore', 'ipc'], windowsHide: true, detached: process.platform !== 'win32', env: { ...process.env, KB_INTEGRATION_STATUS_WORKER: '1' } });
59
104
  this.children.add(child);
60
105
  let settled = false;
61
106
  const finish = (error, summary) => { if (settled) return; settled = true; clearTimeout(timer); error ? reject(error) : resolve(summary); };
107
+ let phase = statusOptions.sharedOnly ? 'shared' : 'capture';
62
108
  const timer = setTimeout(() => {
63
109
  Promise.resolve(managerOptions.logger?.warn?.('integration.status.timeout', '客户端接入状态检查超时;未将其判为未安装。', {
64
110
  operationId: managerOptions.operationId, component: 'integration', phase: 'status',
65
- context: { clients: statusOptions.clients || SUPPORTED_CLIENTS, timeoutMs: this.timeoutMs },
111
+ context: { clients: statusOptions.clients || [], step: phase, timeoutMs: this.timeoutMs },
66
112
  })).catch(() => {});
67
113
  this.terminate(child); finish(Object.assign(new Error('状态检查超时。'), { code: 'INTEGRATION_STATUS_TIMEOUT' }));
68
114
  }, this.timeoutMs);
@@ -71,24 +117,38 @@ class IntegrationStatusScan {
71
117
  if (['info', 'warn', 'error'].includes(message.level) && Array.isArray(message.args) && /^integration\./.test(message.args[0] || '')) Promise.resolve(managerOptions.logger?.[message.level]?.(...message.args)).catch(() => {});
72
118
  return;
73
119
  }
120
+ if (message?.kind === 'client-status') {
121
+ if (!settled) {
122
+ phase = message.entry?.knowledgeIntegration ? 'context-and-mcp' : 'knowledge-plugin';
123
+ onPartial(message.entry);
124
+ }
125
+ return;
126
+ }
74
127
  finish(message?.ok ? null : Object.assign(new Error('状态检查失败。'), { code: message?.code }), message?.summary);
75
128
  });
76
129
  child.once('error', error => finish(error));
77
130
  child.once('exit', () => { this.children.delete(child); if (!settled) finish(Object.assign(new Error('状态检查进程提前退出。'), { code: 'INTEGRATION_STATUS_EXITED' })); });
78
- const allowed = ['rootDir', 'homeDir', 'version', 'packageSpec', 'operationId', 'bridgeHomeDir', 'bridgeConsumerName', 'claudeSettingsFile', 'codexConfigFile', 'zcodeConfigFile', 'openCodePluginsDir'];
79
- child.send({ managerOptions: Object.fromEntries(allowed.filter(k => managerOptions[k] !== undefined).map(k => [k, managerOptions[k]])), statusOptions });
131
+ const allowed = ['rootDir', 'homeDir', 'env', 'version', 'packageSpec', 'operationId', 'bridgeHomeDir', 'bridgeConsumerName', 'claudeSettingsFile', 'codexConfigFile', 'zcodeConfigFile', 'openCodePluginsDir'];
132
+ child.send({ managerOptions: Object.fromEntries(allowed.filter(k => managerOptions[k] !== undefined).map(k => [k, managerOptions[k]])), statusOptions }, error => { if (error) finish(error); });
80
133
  });
81
134
  }
82
135
  terminate(child) {
83
- if (child.exitCode !== null || child.signalCode !== null) return;
136
+ if (!child.pid || child.exitCode !== null || child.signalCode !== null) return;
84
137
  if (process.platform === 'win32') {
85
138
  // Only the live worker we created, including its probe children. Never
86
139
  // terminate by executable name or scan unrelated Node processes.
87
140
  const killer = spawn('taskkill.exe', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
88
141
  killer.on('error', () => child.kill());
89
- } else child.kill('SIGTERM');
142
+ } else {
143
+ try { process.kill(-child.pid, 'SIGTERM'); } catch { child.kill('SIGTERM'); }
144
+ }
145
+ }
146
+ invalidate(clients) {
147
+ const selected = clients?.length ? new Set(clients.map(normalizeClient)) : null;
148
+ for (const [key, entry] of this.entries) {
149
+ if (!selected || !entry.client || selected.has(entry.client)) this.entries.delete(key);
150
+ }
90
151
  }
91
- invalidate() { for (const entry of this.entries.values()) entry.at = 0; }
92
152
  close() {
93
153
  this.closed = true;
94
154
  for (const child of this.children) this.terminate(child);
@@ -5,8 +5,10 @@ process.once('message', async input => {
5
5
  const logger = Object.fromEntries(['info', 'warn', 'error'].map(level => [level, (...args) => {
6
6
  if (process.connected) process.send({ kind: 'log', level, args: args.map(value => value instanceof Error ? { name: value.name, code: value.code, message: 'Integration command failed.' } : value) });
7
7
  }]));
8
- const manager = new IntegrationManager({ ...input.managerOptions, logger });
9
- const summary = await manager.statusAll(input.statusOptions);
8
+ const manager = new IntegrationManager({ ...input.managerOptions, localStatus: true, logger });
9
+ const summary = await manager.statusAll({ ...input.statusOptions, onClientStatus: entry => {
10
+ if (process.connected) process.send({ kind: 'client-status', entry });
11
+ } });
10
12
  process.send({ ok: true, summary }, () => process.disconnect());
11
13
  } catch (error) {
12
14
  process.send({ ok: false, code: error.code || 'INTEGRATION_STATUS_FAILED' }, () => process.disconnect());