@sanqianx/project-knowledge 5.0.16-rc.1 → 5.0.16-rc.2
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +5 -0
- package/_modules/knowledge-engine/README.md +2 -2
- package/_modules/knowledge-engine/package.json +1 -1
- package/_modules/knowledge-engine/src/retrieval.js +119 -24
- package/_modules/knowledge-engine/src/runtime/knowledge-promotion.js +80 -24
- package/_modules/knowledge-engine/src/runtime/knowledge-retrieval-service.js +8 -6
- package/_modules/knowledge-engine/src/runtime/markdown-knowledge-indexer.js +105 -64
- package/_site/_test/agent-capture-mcp-ui-test.js +67 -0
- package/_site/_test/agent-capture-ui-test.js +2 -1
- package/_site/_test/integration-adapters-test.js +7 -1
- package/_site/_test/integration-runtime-binding-a2-test.js +566 -0
- package/_site/_test/integration-runtime-binding-a3-test.js +227 -0
- package/_site/_test/integration-runtime-binding-test.js +473 -0
- package/_site/_test/native-context-integrations-test.js +1 -1
- package/_site/_test/release-version-sync-test.js +12 -1
- package/_site/lib/integration-installer.js +325 -8
- package/_site/lib/module-bridge.js +6 -2
- package/_site/scripts/sync-product-content.js +1 -1
- package/_site/scripts/sync-release-version.js +9 -5
- package/_site/scripts/verify-product-runtime.js +1 -1
- package/docs/leader-glm-workbench-playbook.md +87 -0
- package/docs/release-5.0.16-acceptance.md +53 -0
- package/module-runtime-manifest.json +29 -28
- package/package.json +5 -3
- package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.mcp.json +7 -6
- package/plugins/project-knowledge/scripts/mcp-launcher.cjs +78 -0
- package/ui/product.js +3 -1
- package/vendor-manifest.json +8 -8
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Run: node _site/_test/integration-runtime-binding-a3-test.js
|
|
2
|
+
//
|
|
3
|
+
// A3 acceptance hardening regressions (must fail before the fixes land):
|
|
4
|
+
// - a crashing mcpProbe reports the fixed PROBE_CRASH diagnostic and never
|
|
5
|
+
// echoes the exception text (SYNTHETIC_PRIVATE_MARKER counter-example);
|
|
6
|
+
// - a launcher stderr payload.code outside the allowlist never becomes a
|
|
7
|
+
// result code (fixed LAUNCHER_ERROR_UNKNOWN), while allowlisted codes pass;
|
|
8
|
+
// - an abnormal serverVersion is never echoed (VERSION_MISMATCH only);
|
|
9
|
+
// - install-time binding validation enforces bin realpath containment and a
|
|
10
|
+
// regular-file entry before any binding is written;
|
|
11
|
+
// - the launcher spawns with windowsHide and no "本产品签发" signing claim;
|
|
12
|
+
// - C2 minimal wiring: the supervised terminal spec carries
|
|
13
|
+
// KB_KNOWLEDGE_DATA_DIR (non-secret product root) in both command branches,
|
|
14
|
+
// while AGENT_TERMINAL_DATA_DIR stays the dedicated workbench subtree.
|
|
15
|
+
|
|
16
|
+
const fs = require('node:fs');
|
|
17
|
+
const os = require('node:os');
|
|
18
|
+
const path = require('node:path');
|
|
19
|
+
const { deepEqual } = require('node:assert/strict');
|
|
20
|
+
const { IntegrationManager } = require('../lib/integration-installer');
|
|
21
|
+
const { ModuleBridge } = require('../lib/module-bridge');
|
|
22
|
+
|
|
23
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
24
|
+
const LAUNCHER = path.join(ROOT, 'plugins', 'project-knowledge', 'scripts', 'mcp-launcher.cjs');
|
|
25
|
+
const INSTALLER = path.join(ROOT, '_site', 'lib', 'integration-installer.js');
|
|
26
|
+
const RUNTIME_SCHEMA = 'project-knowledge/integration-runtime/v1';
|
|
27
|
+
const ERROR_SCHEMA = 'project-knowledge/mcp-launcher-error/v1';
|
|
28
|
+
const PKG = '@sanqianx/project-knowledge';
|
|
29
|
+
const VERSION = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version;
|
|
30
|
+
const TEMP = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-a3-' + process.pid + '-'));
|
|
31
|
+
|
|
32
|
+
function assert(condition, message) { if (!condition) throw new Error(message); }
|
|
33
|
+
function dir(name) { const target = path.join(TEMP, name); fs.mkdirSync(target, { recursive: true }); return target; }
|
|
34
|
+
function bindingPathOf(dataDir) { return path.join(dataDir, 'integration-runtime.json'); }
|
|
35
|
+
function writeBinding(dataDir, overrides = {}) {
|
|
36
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
37
|
+
fs.writeFileSync(bindingPathOf(dataDir), JSON.stringify({
|
|
38
|
+
schema: RUNTIME_SCHEMA, packageName: PKG, packageRoot: ROOT, version: VERSION,
|
|
39
|
+
updatedAt: new Date().toISOString(), ...overrides,
|
|
40
|
+
}, null, 2));
|
|
41
|
+
}
|
|
42
|
+
function fakePackage(root, { name = PKG, version = VERSION, bin = 'bin/project-knowledge-mcp.js', withEntry = true } = {}) {
|
|
43
|
+
fs.mkdirSync(path.dirname(path.join(root, bin)), { recursive: true });
|
|
44
|
+
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ name, version, bin: { 'project-knowledge-mcp': bin } }));
|
|
45
|
+
if (withEntry) fs.writeFileSync(path.join(root, bin), 'process.exit(0);\n');
|
|
46
|
+
return path.join(root, bin);
|
|
47
|
+
}
|
|
48
|
+
function bridgeStub() {
|
|
49
|
+
return { createBridge: () => ({
|
|
50
|
+
registerConsumer: async () => ({}), getConsumer: async () => ({}), getHealth: async () => ({}), ensureRuntimeHome: async () => ({}),
|
|
51
|
+
installers: {
|
|
52
|
+
claudeCode: { installClaudeCodeHook: async () => ({ added: [] }), statusClaudeCodeHook: async () => ({ installed: false }), uninstallClaudeCodeHook: async () => ({}) },
|
|
53
|
+
codex: { statusCodexHook: async () => ({ installed: false }) },
|
|
54
|
+
},
|
|
55
|
+
}) };
|
|
56
|
+
}
|
|
57
|
+
function stubRunner(cmd, args) {
|
|
58
|
+
return { status: 0, stdout: cmd === 'codex' && args[1] === 'list' ? '{}' : '[]', stderr: '' };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function testProbeCrashNeverEchoes() {
|
|
62
|
+
const manager = new IntegrationManager({
|
|
63
|
+
rootDir: ROOT, homeDir: dir('crash-home'), env: {},
|
|
64
|
+
commandResolver: name => name, runner: stubRunner,
|
|
65
|
+
mcpProbe: async () => { throw Error('SYNTHETIC_PRIVATE_MARKER'); },
|
|
66
|
+
bridgeModule: bridgeStub(),
|
|
67
|
+
});
|
|
68
|
+
const summary = await manager.statusAll({ clients: ['claude'] });
|
|
69
|
+
const runtime = summary.mcpRuntime;
|
|
70
|
+
assert(runtime && runtime.state === 'failed' && runtime.code === 'PROBE_CRASH', 'a crashing probe reports PROBE_CRASH, got ' + JSON.stringify(runtime));
|
|
71
|
+
assert(runtime.detail === '启动探测自身异常终止;已使用固定诊断,未回显异常内容。', 'PROBE_CRASH must carry the fixed redacted diagnostic, got ' + JSON.stringify(runtime.detail));
|
|
72
|
+
assert(!JSON.stringify(summary).includes('SYNTHETIC_PRIVATE_MARKER'), 'probe crash text must never be reflected into status results');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function testLauncherCodeAllowlist() {
|
|
76
|
+
const base = {
|
|
77
|
+
rootDir: ROOT, homeDir: dir('code-home'), env: {},
|
|
78
|
+
commandResolver: name => name, runner: stubRunner,
|
|
79
|
+
};
|
|
80
|
+
const leaky = path.join(TEMP, 'code-leak-launcher.cjs');
|
|
81
|
+
fs.writeFileSync(leaky, 'process.stderr.write(JSON.stringify({ schema: ' + JSON.stringify(ERROR_SCHEMA) + ', code: \'SYNTHETIC_CODE_LEAK\', message: \'SYNTHETIC_STDERR_MARKER\' })); process.exit(1);\n');
|
|
82
|
+
const leaked = await new IntegrationManager(base).probeMcpStartup({ launcherPath: leaky, timeoutMs: 9000 });
|
|
83
|
+
assert(leaked.state === 'failed' && leaked.code === 'LAUNCHER_ERROR_UNKNOWN', 'unlisted launcher codes collapse to LAUNCHER_ERROR_UNKNOWN, got ' + JSON.stringify(leaked));
|
|
84
|
+
assert(!JSON.stringify(leaked).includes('SYNTHETIC_CODE_LEAK') && !JSON.stringify(leaked).includes('SYNTHETIC_STDERR_MARKER'), 'untrusted launcher stderr values must never be echoed');
|
|
85
|
+
|
|
86
|
+
const allowed = path.join(TEMP, 'allowed-code-launcher.cjs');
|
|
87
|
+
fs.writeFileSync(allowed, 'process.stderr.write(JSON.stringify({ schema: ' + JSON.stringify(ERROR_SCHEMA) + ', code: \'BINDING_ENTRY_INVALID\', message: \'SYNTHETIC_STDERR_MARKER\' })); process.exit(1);\n');
|
|
88
|
+
const passed = await new IntegrationManager({ ...base, homeDir: dir('code-home-allowed') }).probeMcpStartup({ launcherPath: allowed, timeoutMs: 9000 });
|
|
89
|
+
assert(passed.state === 'failed' && passed.code === 'BINDING_ENTRY_INVALID', 'allowlisted launcher codes keep passing through, got ' + JSON.stringify(passed));
|
|
90
|
+
assert(!JSON.stringify(passed).includes('SYNTHETIC_STDERR_MARKER'), 'launcher messages stay unechoed even for allowlisted codes');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const STUB_TOOLS = ['project_knowledge_resolve', 'project_knowledge_record_requirement', 'project_knowledge_search', 'project_knowledge_ask', 'project_knowledge_get', 'project_knowledge_history'];
|
|
94
|
+
const A3_STUB_SOURCE = [
|
|
95
|
+
'const marker = process.env.A3_VERSION_MARKER || \'0.0.1-SYNTHETIC_VERSION\';',
|
|
96
|
+
'let buffer = \'\';',
|
|
97
|
+
'const send = message => process.stdout.write(JSON.stringify(message) + String.fromCharCode(10));',
|
|
98
|
+
'process.stdin.setEncoding(\'utf8\');',
|
|
99
|
+
'process.stdin.on(\'data\', chunk => {',
|
|
100
|
+
' buffer += chunk; let index;',
|
|
101
|
+
' while ((index = buffer.indexOf(String.fromCharCode(10))) >= 0) {',
|
|
102
|
+
' const line = buffer.slice(0, index).trim(); buffer = buffer.slice(index + 1);',
|
|
103
|
+
' if (!line) continue; let message; try { message = JSON.parse(line); } catch { continue; }',
|
|
104
|
+
' if (message.method === \'initialize\') {',
|
|
105
|
+
' send({ jsonrpc: \'2.0\', id: message.id, result: { protocolVersion: \'2025-06-18\', capabilities: {}, serverInfo: { name: \'project-knowledge\', version: marker } } });',
|
|
106
|
+
' } else if (message.method === \'tools/list\') {',
|
|
107
|
+
' send({ jsonrpc: \'2.0\', id: message.id, result: { tools: ' + JSON.stringify(STUB_TOOLS.map(name => ({ name, inputSchema: { type: 'object' } }))) + ' } });',
|
|
108
|
+
' }',
|
|
109
|
+
' }',
|
|
110
|
+
'});',
|
|
111
|
+
].join('\n');
|
|
112
|
+
|
|
113
|
+
async function testVersionMismatchNeverEchoesServerVersion() {
|
|
114
|
+
const pkg = dir('version-marker-pkg');
|
|
115
|
+
const entry = path.join(pkg, 'bin', 'project-knowledge-mcp.js');
|
|
116
|
+
fs.mkdirSync(path.dirname(entry), { recursive: true });
|
|
117
|
+
fs.writeFileSync(entry, A3_STUB_SOURCE);
|
|
118
|
+
fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG, version: VERSION, bin: { 'project-knowledge-mcp': 'bin/project-knowledge-mcp.js' } }));
|
|
119
|
+
const dataDir = dir('version-marker-data');
|
|
120
|
+
writeBinding(dataDir, { packageRoot: pkg });
|
|
121
|
+
const manager = new IntegrationManager({
|
|
122
|
+
rootDir: ROOT, homeDir: dir('version-home'), env: { KB_DATA_DIR: dataDir, A3_VERSION_MARKER: '0.0.1-SYNTHETIC_VERSION' },
|
|
123
|
+
commandResolver: name => name, runner: stubRunner,
|
|
124
|
+
});
|
|
125
|
+
const result = await manager.probeMcpStartup({ timeoutMs: 12000 });
|
|
126
|
+
assert(result.state === 'failed' && result.code === 'VERSION_MISMATCH', 'a foreign server version fails VERSION_MISMATCH, got ' + JSON.stringify(result));
|
|
127
|
+
assert(result.actualVersion === undefined, 'the abnormal serverVersion must not be echoed as actualVersion');
|
|
128
|
+
assert(!JSON.stringify(result).includes('0.0.1-SYNTHETIC_VERSION'), 'the foreign version string must never appear in the probe result');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function testInstallTimeBinRealpathBoundary() {
|
|
132
|
+
// A junction inside the package resolving outside the real root must be
|
|
133
|
+
// rejected before any binding file is written.
|
|
134
|
+
const outside = dir('binding-outside-real');
|
|
135
|
+
fs.writeFileSync(path.join(outside, 'server.js'), 'process.exit(0);\n');
|
|
136
|
+
const junctionPkg = dir('binding-junction-pkg');
|
|
137
|
+
fakePackage(junctionPkg, { bin: 'datalink/server.js', withEntry: false });
|
|
138
|
+
fs.rmSync(path.join(junctionPkg, 'datalink'), { recursive: true, force: true });
|
|
139
|
+
fs.symlinkSync(outside, path.join(junctionPkg, 'datalink'), 'junction');
|
|
140
|
+
const junctionData = dir('binding-junction-data');
|
|
141
|
+
const junctionManager = new IntegrationManager({ rootDir: junctionPkg, homeDir: dir('binding-junction-home'), env: { KB_DATA_DIR: junctionData }, commandResolver: name => name, runner: stubRunner });
|
|
142
|
+
let junctionRejected = false;
|
|
143
|
+
try { junctionManager.ensureIntegrationRuntimeBinding(); } catch (error) { junctionRejected = true; }
|
|
144
|
+
assert(junctionRejected, 'an entry whose realpath escapes the package root must be rejected at install time');
|
|
145
|
+
assert(!fs.existsSync(bindingPathOf(junctionData)), 'a rejected entry must not produce a binding file');
|
|
146
|
+
|
|
147
|
+
// A bin entry that is a directory is not a regular file: rejected.
|
|
148
|
+
const dirPkg = dir('binding-dir-pkg');
|
|
149
|
+
fs.mkdirSync(fakePackage(dirPkg, { withEntry: false }), { recursive: true });
|
|
150
|
+
const dirData = dir('binding-dir-data');
|
|
151
|
+
const dirManager = new IntegrationManager({ rootDir: dirPkg, homeDir: dir('binding-dir-home'), env: { KB_DATA_DIR: dirData }, commandResolver: name => name, runner: stubRunner });
|
|
152
|
+
let dirRejected = false;
|
|
153
|
+
try { dirManager.ensureIntegrationRuntimeBinding(); } catch (error) { dirRejected = true; }
|
|
154
|
+
assert(dirRejected, 'a directory bin entry must be rejected at install time');
|
|
155
|
+
assert(!fs.existsSync(bindingPathOf(dirData)), 'no binding file may appear for a directory entry');
|
|
156
|
+
|
|
157
|
+
// A regular in-package file binds normally.
|
|
158
|
+
const okPkg = dir('binding-ok-pkg');
|
|
159
|
+
fakePackage(okPkg);
|
|
160
|
+
const okData = dir('binding-ok-data');
|
|
161
|
+
const okManager = new IntegrationManager({ rootDir: okPkg, homeDir: dir('binding-ok-home'), env: { KB_DATA_DIR: okData }, commandResolver: name => name, runner: stubRunner });
|
|
162
|
+
const bound = okManager.ensureIntegrationRuntimeBinding();
|
|
163
|
+
assert(bound.state === 'written' && fs.existsSync(bindingPathOf(okData)), 'a regular in-package bin entry still binds');
|
|
164
|
+
assert(readBindingPackageRoot(okData) === path.resolve(okPkg), 'the binding pins the validated package root');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function readBindingPackageRoot(dataDir) {
|
|
168
|
+
return JSON.parse(fs.readFileSync(bindingPathOf(dataDir), 'utf8')).packageRoot;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function testLauncherStaticHardening() {
|
|
172
|
+
const launcherSource = fs.readFileSync(LAUNCHER, 'utf8');
|
|
173
|
+
assert(launcherSource.includes('windowsHide: true'), 'the launcher must spawn the MCP entry with windowsHide: true');
|
|
174
|
+
assert(!launcherSource.includes('本产品签发'), 'the launcher must not claim a signing authority it does not have');
|
|
175
|
+
const installerSource = fs.readFileSync(INSTALLER, 'utf8');
|
|
176
|
+
assert(!installerSource.includes('本产品签发'), 'installer diagnostics must not claim a signing authority');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function testTerminalSpecCarriesKnowledgeDataDir() {
|
|
180
|
+
const dataDir = dir('terminal-knowledge-data');
|
|
181
|
+
const bridgeFor = () => new ModuleBridge({
|
|
182
|
+
terminalUrl: 'http://127.0.0.1:1',
|
|
183
|
+
vectorHubUrl: 'http://127.0.0.1:1',
|
|
184
|
+
eventBridgeUrl: 'http://127.0.0.1:1',
|
|
185
|
+
engineUrl: 'http://127.0.0.1:1',
|
|
186
|
+
dataDir,
|
|
187
|
+
});
|
|
188
|
+
const savedCommand = process.env.KB_TERMINAL_COMMAND;
|
|
189
|
+
try {
|
|
190
|
+
process.env.KB_TERMINAL_COMMAND = 'node C:/explicit/terminal-server.js';
|
|
191
|
+
const overrideSpec = bridgeFor()._supervisedSpecs().find(spec => spec.name === 'terminal');
|
|
192
|
+
assert(overrideSpec, 'the KB_TERMINAL_COMMAND branch must produce a terminal spec');
|
|
193
|
+
assert(overrideSpec.env.KB_KNOWLEDGE_DATA_DIR === dataDir, 'the override branch must pass the product knowledge root, got ' + JSON.stringify(overrideSpec.env.KB_KNOWLEDGE_DATA_DIR));
|
|
194
|
+
assert(!('AGENT_TERMINAL_DATA_DIR' in overrideSpec.env), 'the override branch must not widen the terminal-private data dir');
|
|
195
|
+
deepEqual(Object.keys(overrideSpec.env).sort(), ['KB_EVENT_BRIDGE_URL', 'KB_KNOWLEDGE_DATA_DIR', 'KB_KNOWLEDGE_ENGINE_URL', 'KB_WORKBENCH_RUNTIME_TOKEN'], 'the override branch env stays the minimal non-secret contract plus the product root');
|
|
196
|
+
|
|
197
|
+
delete process.env.KB_TERMINAL_COMMAND;
|
|
198
|
+
const defaultSpec = bridgeFor()._supervisedSpecs().find(spec => spec.name === 'terminal');
|
|
199
|
+
assert(defaultSpec, 'the vendored terminal entry must resolve in this checkout');
|
|
200
|
+
assert(defaultSpec.env.KB_KNOWLEDGE_DATA_DIR === dataDir, 'the vendored branch must pass the product knowledge root');
|
|
201
|
+
assert(defaultSpec.env.AGENT_TERMINAL_DATA_DIR === path.join(dataDir, 'workbench'), 'AGENT_TERMINAL_DATA_DIR stays the dedicated workbench subtree');
|
|
202
|
+
} finally {
|
|
203
|
+
if (savedCommand === undefined) delete process.env.KB_TERMINAL_COMMAND; else process.env.KB_TERMINAL_COMMAND = savedCommand;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function main() {
|
|
208
|
+
const tests = [
|
|
209
|
+
['probe-crash', testProbeCrashNeverEchoes],
|
|
210
|
+
['launcher-code-allowlist', testLauncherCodeAllowlist],
|
|
211
|
+
['version-echo', testVersionMismatchNeverEchoesServerVersion],
|
|
212
|
+
['binding-realpath', testInstallTimeBinRealpathBoundary],
|
|
213
|
+
['launcher-static', testLauncherStaticHardening],
|
|
214
|
+
['terminal-env', testTerminalSpecCarriesKnowledgeDataDir],
|
|
215
|
+
];
|
|
216
|
+
const only = process.env.A3_ONLY;
|
|
217
|
+
for (const [name, test] of tests) {
|
|
218
|
+
if (only && name !== only) continue;
|
|
219
|
+
await test();
|
|
220
|
+
}
|
|
221
|
+
console.log('INTEGRATION_RUNTIME_BINDING_A3_TEST_PASSED');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
main().catch(error => {
|
|
225
|
+
console.error('INTEGRATION_RUNTIME_BINDING_A3_TEST_FAILED', error.message);
|
|
226
|
+
process.exit(1);
|
|
227
|
+
});
|