@sanqianx/project-knowledge 5.0.34 → 5.1.0
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/CHANGELOG.md +5 -0
- package/_site/_test/chat-claudecodeui-match-test.js +1 -1
- package/_site/_test/integration-runtime-binding-test.js +1 -1
- package/_site/_test/mcp-server-test.js +149 -149
- package/_site/_test/module-supervisor-backoff-reset-test.js +64 -0
- package/_site/_test/packaged-ui-smoke-test.js +1 -1
- package/_site/_test/parallel-memory-home-review-test.js +148 -0
- package/_site/_test/parallel-nav-home-issues-test.js +159 -0
- package/_site/_test/parallel-nav-theme-test.js +5 -4
- package/_site/_test/parallel-nav-viewport-test.js +4 -2
- package/_site/_test/product-empty-state-test.js +2 -2
- package/_site/_test/product-navigation-test.js +2 -2
- package/_site/_test/workflow-module-wiring-test.js +102 -0
- package/_site/_test/workflow-tools-test.js +97 -0
- package/_site/_test/workspace-ui-contract-test.js +16 -3
- package/_site/lib/integration-installer.js +3 -1
- package/_site/lib/module-bridge.js +59 -11
- package/_site/lib/server-app.js +12 -0
- package/_site/lib/workflow-tool-runtime.js +209 -0
- package/bin/project-knowledge-mcp.js +282 -201
- package/module-runtime-manifest.json +5 -5
- package/package.json +1 -1
- 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 +1 -1
- package/plugins/project-knowledge/skills/pk-team/SKILL.md +35 -0
- package/ui/index.html +6 -0
- package/ui/product.js +113 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [5.0.35] - 2026-11-13
|
|
4
|
+
|
|
5
|
+
- 模块监督器退避计数在稳定运行后重置:连续健康运行 ≥60 秒的模块服务,其下一次退出按新事故计(计数归 1),只有持续快速崩溃才累计到放弃上限,快速崩溃循环的原有保护与退避节奏不变。消除「偶发退出的模块被监督器永久放弃、外壳持续向死端口反代、界面长时间 MODULE_UNREACHABLE 直到重启外壳」的故障模式(系统日志中 10-22→23、10-26→27 两波 24/20 小时级故障即此成因)。新增 `module-supervisor-backoff-reset-test.js` 回归(崩溃循环仍放弃 + 稳定退出必拉起且计数归 1)。
|
|
6
|
+
- 首页直达处理移植到五页外壳:「需要处理」的 overview 运行行提供「去处理」入口(绑定具体 runId),openRunDetail 落到活动记录中该次运行的展开行,pendingOpenRun 在快照/SSE/分页并发重渲染下保持展开不被吞掉;「待确认记忆」沿用五页共享的候选审核对话框,确认在原位完成。浏览器回归 `parallel-nav-home-issues-test.js` 与 `parallel-memory-home-review-test.js` 迁移到五页选择器(#projectSelect 登记面、review-candidate 入口、appDialog 审核流)。
|
|
7
|
+
|
|
3
8
|
## [5.0.34] - 2026-11-12
|
|
4
9
|
|
|
5
10
|
- 界面简化为五页(首页、长期记忆、项目、知识检索、活动记录),移除「开始工作」导航;Workbench 服务保留为隐藏挂载,模型供应商管理与默认维护模型仍从系统状态打开。首页集中展示全局人工待办(上限预览 + 总数)、自动恢复横幅、待确认记忆预览与最多 4 个记忆组合入口。
|
|
@@ -91,7 +91,7 @@ const runner = require('../lib/claude-cli-runner');
|
|
|
91
91
|
const nav = /<nav aria-label="主要导航">([\s\S]*?)<\/nav>/.exec(html);
|
|
92
92
|
assert(nav, 'the navigation block exists');
|
|
93
93
|
const navViews = [...nav[1].matchAll(/data-view="([a-z]+)"/g)].map(match => match[1]);
|
|
94
|
-
assert.deepStrictEqual(navViews, ['home', 'memory', 'projects', 'search', 'activity'], 'the navigation offers exactly the
|
|
94
|
+
assert.deepStrictEqual(navViews, ['home', 'team', 'memory', 'projects', 'search', 'activity'], 'the navigation offers exactly the six fixed pages (AI 团队 added 2026-11)');
|
|
95
95
|
// 检索页不再内嵌 vectorHub:服务端检索取代 vectorFrame。
|
|
96
96
|
assert(html.includes('id="view-search"') && !html.includes('id="vectorFrame"'));
|
|
97
97
|
assert(app.includes("'/api/engine/search'"), 'the search page drives the server-side engine search');
|
|
@@ -328,7 +328,7 @@ async function testMcpStartupProbe() {
|
|
|
328
328
|
assert(ready.state === 'ready', `a healthy binding must probe ready, got ${JSON.stringify(ready)}`);
|
|
329
329
|
assert(ready.actualVersion === packageInfo.version && ready.expectedVersion === packageInfo.version, 'the probe must report both versions');
|
|
330
330
|
assert(ready.scope === 'product-runtime' && ready.serverName === 'project-knowledge', 'A2: the probe reports its scope and the verified server identity');
|
|
331
|
-
assert(Array.isArray(ready.tools) && ready.tools.length
|
|
331
|
+
assert(Array.isArray(ready.tools) && ready.tools.length >= 6 && ['project_knowledge_resolve','project_knowledge_search','project_knowledge_ask','project_knowledge_get','project_knowledge_history','project_knowledge_record_requirement'].every(n => ready.tools.includes(n)), 'A2: the probe verifies the six knowledge tools are present (workflow tools are additive)');
|
|
332
332
|
assert(typeof ready.checkedAt === 'string', 'the probe must record checkedAt');
|
|
333
333
|
|
|
334
334
|
// A broken binding must surface a failed probe with a machine code.
|
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { spawn, spawnSync } = require('child_process');
|
|
6
|
-
const { StorageLayout } = require('../lib/storage-layout');
|
|
7
|
-
const { SettingsStore } = require('../lib/settings-store');
|
|
8
|
-
const { ProjectRegistryStore } = require('../lib/project-registry-store');
|
|
9
|
-
const { ProjectStore } = require('../lib/project-store');
|
|
10
|
-
const { ConversationStore } = require('../lib/conversation-store');
|
|
11
|
-
const { KnowledgeDatabase } = require('../lib/knowledge-db');
|
|
12
|
-
const { EMBEDDING_DIMENSIONS } = require('../lib/knowledge-schema');
|
|
13
|
-
|
|
14
|
-
const ROOT = path.resolve(__dirname, '..', '..');
|
|
15
|
-
const MCP_BIN = path.join(ROOT, 'bin', 'project-knowledge-mcp.js');
|
|
16
|
-
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-mcp-v2-'));
|
|
17
|
-
const dataDir = path.join(temp, 'data');
|
|
18
|
-
const repo = path.join(temp, 'repo');
|
|
19
|
-
const vectorRepo = path.join(temp, 'vector-repo');
|
|
20
|
-
const markdownKb = path.join(temp, 'knowledge-markdown');
|
|
21
|
-
const vectorKb = path.join(temp, 'knowledge-vector');
|
|
22
|
-
|
|
23
|
-
function write(filePath, content) {
|
|
24
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
25
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function git(cwd, args) {
|
|
29
|
-
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
30
|
-
assert.strictEqual(result.status, 0, result.stderr);
|
|
31
|
-
return String(result.stdout || '').trim();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function fakeVector(text) {
|
|
35
|
-
const vector = new Array(EMBEDDING_DIMENSIONS).fill(0);
|
|
36
|
-
for (let index = 0; index < String(text).length; index += 1) vector[String(text).charCodeAt(index) % vector.length] += 1;
|
|
37
|
-
const norm = Math.sqrt(vector.reduce((sum, item) => sum + item * item, 0)) || 1;
|
|
38
|
-
return vector.map(item => item / norm);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function createMcpClient() {
|
|
42
|
-
const child = spawn(process.execPath, [MCP_BIN], {
|
|
43
|
-
cwd: repo,
|
|
44
|
-
env: { ...process.env, KB_DATA_DIR: dataDir, KB_SKIP_MIGRATION: '1', KB_EMBEDDING_FAKE: '1' },
|
|
45
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
46
|
-
windowsHide: true,
|
|
47
|
-
});
|
|
48
|
-
let stderr = '';
|
|
49
|
-
let buffer = '';
|
|
50
|
-
let nextId = 1;
|
|
51
|
-
const pending = new Map();
|
|
52
|
-
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
53
|
-
child.stdout.on('data', chunk => {
|
|
54
|
-
buffer += chunk;
|
|
55
|
-
let newline;
|
|
56
|
-
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
57
|
-
const line = buffer.slice(0, newline).trim();
|
|
58
|
-
buffer = buffer.slice(newline + 1);
|
|
59
|
-
if (!line) continue;
|
|
60
|
-
const message = JSON.parse(line);
|
|
61
|
-
const entry = pending.get(message.id);
|
|
62
|
-
if (entry) { entry(message); pending.delete(message.id); }
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
const request = (method, params = {}) => new Promise((resolve, reject) => {
|
|
66
|
-
const id = nextId++;
|
|
67
|
-
const timer = setTimeout(() => { pending.delete(id); reject(new Error(`MCP timeout: ${method}\n${stderr}`)); }, 15_000);
|
|
68
|
-
pending.set(id, message => { clearTimeout(timer); resolve(message); });
|
|
69
|
-
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
70
|
-
});
|
|
71
|
-
await request('initialize', { protocolVersion: '2025-03-26', capabilities: {}, clientInfo: { name: 'test', version: '1' } });
|
|
72
|
-
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized', params: {} })}\n`);
|
|
73
|
-
return { child, request, stderr: () => stderr };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
(async () => {
|
|
77
|
-
for (const cwd of [repo, vectorRepo]) {
|
|
78
|
-
fs.mkdirSync(cwd, { recursive: true });
|
|
79
|
-
git(cwd, ['init', '--initial-branch=main']);
|
|
80
|
-
git(cwd, ['config', 'user.email', 'mcp@example.test']);
|
|
81
|
-
git(cwd, ['config', 'user.name', 'MCP Test']);
|
|
82
|
-
write(path.join(cwd, 'README.md'), '# source\n');
|
|
83
|
-
git(cwd, ['add', 'README.md']);
|
|
84
|
-
git(cwd, ['commit', '-m', 'baseline']);
|
|
85
|
-
}
|
|
86
|
-
write(path.join(markdownKb, 'README.md'), '# Demo knowledge\n\nThis project uses rotating refresh tokens.\n');
|
|
87
|
-
write(path.join(markdownKb, 'modules', 'auth.md'), '# Authentication\n\nRefresh tokens rotate after every successful renewal.\n');
|
|
88
|
-
write(path.join(markdownKb, 'changes', 'auth.md'), '# Authentication update\n\nIntroduced rotating refresh tokens.\n');
|
|
89
|
-
write(path.join(vectorKb, 'modules', 'payments.md'), '# Payment tokens\n\nPayment tokens expire after fifteen minutes.\n');
|
|
90
|
-
|
|
91
|
-
const layout = new StorageLayout({ dataDir });
|
|
92
|
-
const settingsStore = new SettingsStore({ layout });
|
|
93
|
-
const registryStore = new ProjectRegistryStore({ layout });
|
|
94
|
-
const projectStore = new ProjectStore({ layout });
|
|
95
|
-
await settingsStore.initialize({ knowledge: { rootPath: path.join(temp, 'future-root') } });
|
|
96
|
-
await registryStore.initialize();
|
|
97
|
-
await projectStore.create('project-demo', { displayName: 'Demo', storageName: 'demo', repoPath: repo, knowledgePath: markdownKb, legacyExtensions: { slug: 'demo' } }, { trackingStartCommit: git(repo, ['rev-parse', 'HEAD']), index: { dirty: true, generation: 1 } });
|
|
98
|
-
await registryStore.add('project-demo', { displayNameSnapshot: 'Demo' });
|
|
99
|
-
await projectStore.create('project-vector', { displayName: 'Vector', storageName: 'vector', repoPath: vectorRepo, knowledgePath: vectorKb, legacyExtensions: { slug: 'vector' } }, { trackingStartCommit: git(vectorRepo, ['rev-parse', 'HEAD']) });
|
|
100
|
-
await registryStore.add('project-vector', { displayNameSnapshot: 'Vector' });
|
|
101
|
-
|
|
102
|
-
const database = new KnowledgeDatabase({ dbPath: layout.getIndexPath(), maintenancePath: layout.getRuntimePath('index-maintenance.json') });
|
|
103
|
-
await database.replaceEntry('project:project-vector', 'modules/payments.md', [{ chunkOrder: 0, title: 'Payment tokens', chunkText: 'Payment tokens expire after fifteen minutes.', vector: fakeVector('payment tokens'), sourceCommit: 'abc123' }]);
|
|
104
|
-
await database.ensureSearchIndexes();
|
|
105
|
-
await database.close();
|
|
106
|
-
|
|
107
|
-
const client = await createMcpClient();
|
|
108
|
-
try {
|
|
109
|
-
const listed = await client.request('tools/list');
|
|
110
|
-
assert.strictEqual(listed.result.tools.length,
|
|
111
|
-
assert(listed.result.tools.some(tool => tool.name === 'project_knowledge_record_requirement'));
|
|
112
|
-
|
|
113
|
-
let response = await client.request('tools/call', { name: 'project_knowledge_resolve', arguments: { repoPath: repo } });
|
|
114
|
-
assert.strictEqual(response.result.structuredContent.projectId, 'project-demo');
|
|
115
|
-
assert.strictEqual(response.result.structuredContent.knowledgePath, markdownKb);
|
|
116
|
-
assert.strictEqual(response.result.structuredContent.indexPath, layout.getVectorRootPath(settingsStore.read()));
|
|
117
|
-
|
|
118
|
-
response = await client.request('tools/call', { name: 'project_knowledge_search', arguments: { projectId: 'project-demo', query: 'refresh tokens' } });
|
|
119
|
-
assert.strictEqual(response.result.structuredContent.source, 'knowledge-retrieval-service');
|
|
120
|
-
assert.strictEqual(response.result.structuredContent.backend, 'hybrid+markdown-truth');
|
|
121
|
-
assert.strictEqual(response.result.structuredContent.health.scopes[0].dirty, true);
|
|
122
|
-
assert(response.result.structuredContent.results.some(result => result.entry_id === 'modules/auth.md'));
|
|
123
|
-
|
|
124
|
-
response = await client.request('tools/call', { name: 'project_knowledge_search', arguments: { project: 'vector', query: 'payment tokens' } });
|
|
125
|
-
assert.strictEqual(response.result.structuredContent.source, 'knowledge-retrieval-service');
|
|
126
|
-
assert.strictEqual(response.result.structuredContent.backend, 'hybrid+markdown-truth');
|
|
127
|
-
assert(response.result.structuredContent.results.some(result => result.entry_id === 'modules/payments.md'));
|
|
128
|
-
|
|
129
|
-
response = await client.request('tools/call', { name: 'project_knowledge_get', arguments: { projectId: 'project-demo', entry: 'modules/auth.md' } });
|
|
130
|
-
assert.match(response.result.structuredContent.chunks[0].chunk_text, /rotate/i);
|
|
131
|
-
response = await client.request('tools/call', { name: 'project_knowledge_history', arguments: { projectId: 'project-demo' } });
|
|
132
|
-
assert.strictEqual(response.result.structuredContent.results[0].entry_id, 'changes/auth.md');
|
|
133
|
-
|
|
134
|
-
const stateBefore = fs.readFileSync(layout.getProjectStatePath('project-demo'), 'utf8');
|
|
135
|
-
response = await client.request('tools/call', { name: 'project_knowledge_record_requirement', arguments: { projectId: 'project-demo', repoPath: repo, client: 'codex', sessionId: 'session-mcp', text: 'Keep refresh token rotation documented.' } });
|
|
136
|
-
assert.strictEqual(response.result.structuredContent.projectId, 'project-demo');
|
|
137
|
-
assert.strictEqual(new ConversationStore({ layout, projectStore }).readEvents('project-demo').length, 1);
|
|
138
|
-
assert.strictEqual(fs.existsSync(layout.getProjectRequirementsPath('project-demo')), false, 'explicit MCP adapter must not create legacy requirements.jsonl');
|
|
139
|
-
assert.strictEqual(fs.readFileSync(layout.getProjectStatePath('project-demo'), 'utf8'), stateBefore, 'requirement tool must not trigger analysis or mutate state');
|
|
140
|
-
assert(!fs.existsSync(layout.getRuntimePath('staging')));
|
|
141
|
-
|
|
142
|
-
response = await client.request('tools/call', { name: 'project_knowledge_get', arguments: { projectId: 'project-demo', entry: '../settings.json' } });
|
|
143
|
-
assert.strictEqual(response.result.isError, true);
|
|
144
|
-
console.log('mcp-server-test PASS');
|
|
145
|
-
} finally {
|
|
146
|
-
client.child.stdin.end();
|
|
147
|
-
await new Promise(resolve => client.child.once('exit', resolve));
|
|
148
|
-
}
|
|
149
|
-
})().catch(error => { console.error(error); process.exitCode = 1; }).finally(() => fs.rmSync(temp, { recursive: true, force: true }));
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawn, spawnSync } = require('child_process');
|
|
6
|
+
const { StorageLayout } = require('../lib/storage-layout');
|
|
7
|
+
const { SettingsStore } = require('../lib/settings-store');
|
|
8
|
+
const { ProjectRegistryStore } = require('../lib/project-registry-store');
|
|
9
|
+
const { ProjectStore } = require('../lib/project-store');
|
|
10
|
+
const { ConversationStore } = require('../lib/conversation-store');
|
|
11
|
+
const { KnowledgeDatabase } = require('../lib/knowledge-db');
|
|
12
|
+
const { EMBEDDING_DIMENSIONS } = require('../lib/knowledge-schema');
|
|
13
|
+
|
|
14
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
15
|
+
const MCP_BIN = path.join(ROOT, 'bin', 'project-knowledge-mcp.js');
|
|
16
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-mcp-v2-'));
|
|
17
|
+
const dataDir = path.join(temp, 'data');
|
|
18
|
+
const repo = path.join(temp, 'repo');
|
|
19
|
+
const vectorRepo = path.join(temp, 'vector-repo');
|
|
20
|
+
const markdownKb = path.join(temp, 'knowledge-markdown');
|
|
21
|
+
const vectorKb = path.join(temp, 'knowledge-vector');
|
|
22
|
+
|
|
23
|
+
function write(filePath, content) {
|
|
24
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
25
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function git(cwd, args) {
|
|
29
|
+
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
30
|
+
assert.strictEqual(result.status, 0, result.stderr);
|
|
31
|
+
return String(result.stdout || '').trim();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function fakeVector(text) {
|
|
35
|
+
const vector = new Array(EMBEDDING_DIMENSIONS).fill(0);
|
|
36
|
+
for (let index = 0; index < String(text).length; index += 1) vector[String(text).charCodeAt(index) % vector.length] += 1;
|
|
37
|
+
const norm = Math.sqrt(vector.reduce((sum, item) => sum + item * item, 0)) || 1;
|
|
38
|
+
return vector.map(item => item / norm);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function createMcpClient() {
|
|
42
|
+
const child = spawn(process.execPath, [MCP_BIN], {
|
|
43
|
+
cwd: repo,
|
|
44
|
+
env: { ...process.env, KB_DATA_DIR: dataDir, KB_SKIP_MIGRATION: '1', KB_EMBEDDING_FAKE: '1' },
|
|
45
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
46
|
+
windowsHide: true,
|
|
47
|
+
});
|
|
48
|
+
let stderr = '';
|
|
49
|
+
let buffer = '';
|
|
50
|
+
let nextId = 1;
|
|
51
|
+
const pending = new Map();
|
|
52
|
+
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
53
|
+
child.stdout.on('data', chunk => {
|
|
54
|
+
buffer += chunk;
|
|
55
|
+
let newline;
|
|
56
|
+
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
57
|
+
const line = buffer.slice(0, newline).trim();
|
|
58
|
+
buffer = buffer.slice(newline + 1);
|
|
59
|
+
if (!line) continue;
|
|
60
|
+
const message = JSON.parse(line);
|
|
61
|
+
const entry = pending.get(message.id);
|
|
62
|
+
if (entry) { entry(message); pending.delete(message.id); }
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const request = (method, params = {}) => new Promise((resolve, reject) => {
|
|
66
|
+
const id = nextId++;
|
|
67
|
+
const timer = setTimeout(() => { pending.delete(id); reject(new Error(`MCP timeout: ${method}\n${stderr}`)); }, 15_000);
|
|
68
|
+
pending.set(id, message => { clearTimeout(timer); resolve(message); });
|
|
69
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
70
|
+
});
|
|
71
|
+
await request('initialize', { protocolVersion: '2025-03-26', capabilities: {}, clientInfo: { name: 'test', version: '1' } });
|
|
72
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized', params: {} })}\n`);
|
|
73
|
+
return { child, request, stderr: () => stderr };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
(async () => {
|
|
77
|
+
for (const cwd of [repo, vectorRepo]) {
|
|
78
|
+
fs.mkdirSync(cwd, { recursive: true });
|
|
79
|
+
git(cwd, ['init', '--initial-branch=main']);
|
|
80
|
+
git(cwd, ['config', 'user.email', 'mcp@example.test']);
|
|
81
|
+
git(cwd, ['config', 'user.name', 'MCP Test']);
|
|
82
|
+
write(path.join(cwd, 'README.md'), '# source\n');
|
|
83
|
+
git(cwd, ['add', 'README.md']);
|
|
84
|
+
git(cwd, ['commit', '-m', 'baseline']);
|
|
85
|
+
}
|
|
86
|
+
write(path.join(markdownKb, 'README.md'), '# Demo knowledge\n\nThis project uses rotating refresh tokens.\n');
|
|
87
|
+
write(path.join(markdownKb, 'modules', 'auth.md'), '# Authentication\n\nRefresh tokens rotate after every successful renewal.\n');
|
|
88
|
+
write(path.join(markdownKb, 'changes', 'auth.md'), '# Authentication update\n\nIntroduced rotating refresh tokens.\n');
|
|
89
|
+
write(path.join(vectorKb, 'modules', 'payments.md'), '# Payment tokens\n\nPayment tokens expire after fifteen minutes.\n');
|
|
90
|
+
|
|
91
|
+
const layout = new StorageLayout({ dataDir });
|
|
92
|
+
const settingsStore = new SettingsStore({ layout });
|
|
93
|
+
const registryStore = new ProjectRegistryStore({ layout });
|
|
94
|
+
const projectStore = new ProjectStore({ layout });
|
|
95
|
+
await settingsStore.initialize({ knowledge: { rootPath: path.join(temp, 'future-root') } });
|
|
96
|
+
await registryStore.initialize();
|
|
97
|
+
await projectStore.create('project-demo', { displayName: 'Demo', storageName: 'demo', repoPath: repo, knowledgePath: markdownKb, legacyExtensions: { slug: 'demo' } }, { trackingStartCommit: git(repo, ['rev-parse', 'HEAD']), index: { dirty: true, generation: 1 } });
|
|
98
|
+
await registryStore.add('project-demo', { displayNameSnapshot: 'Demo' });
|
|
99
|
+
await projectStore.create('project-vector', { displayName: 'Vector', storageName: 'vector', repoPath: vectorRepo, knowledgePath: vectorKb, legacyExtensions: { slug: 'vector' } }, { trackingStartCommit: git(vectorRepo, ['rev-parse', 'HEAD']) });
|
|
100
|
+
await registryStore.add('project-vector', { displayNameSnapshot: 'Vector' });
|
|
101
|
+
|
|
102
|
+
const database = new KnowledgeDatabase({ dbPath: layout.getIndexPath(), maintenancePath: layout.getRuntimePath('index-maintenance.json') });
|
|
103
|
+
await database.replaceEntry('project:project-vector', 'modules/payments.md', [{ chunkOrder: 0, title: 'Payment tokens', chunkText: 'Payment tokens expire after fifteen minutes.', vector: fakeVector('payment tokens'), sourceCommit: 'abc123' }]);
|
|
104
|
+
await database.ensureSearchIndexes();
|
|
105
|
+
await database.close();
|
|
106
|
+
|
|
107
|
+
const client = await createMcpClient();
|
|
108
|
+
try {
|
|
109
|
+
const listed = await client.request('tools/list');
|
|
110
|
+
assert.strictEqual(listed.result.tools.length, 12, 'six knowledge tools + six workflow tools');
|
|
111
|
+
assert(listed.result.tools.some(tool => tool.name === 'project_knowledge_record_requirement'));
|
|
112
|
+
|
|
113
|
+
let response = await client.request('tools/call', { name: 'project_knowledge_resolve', arguments: { repoPath: repo } });
|
|
114
|
+
assert.strictEqual(response.result.structuredContent.projectId, 'project-demo');
|
|
115
|
+
assert.strictEqual(response.result.structuredContent.knowledgePath, markdownKb);
|
|
116
|
+
assert.strictEqual(response.result.structuredContent.indexPath, layout.getVectorRootPath(settingsStore.read()));
|
|
117
|
+
|
|
118
|
+
response = await client.request('tools/call', { name: 'project_knowledge_search', arguments: { projectId: 'project-demo', query: 'refresh tokens' } });
|
|
119
|
+
assert.strictEqual(response.result.structuredContent.source, 'knowledge-retrieval-service');
|
|
120
|
+
assert.strictEqual(response.result.structuredContent.backend, 'hybrid+markdown-truth');
|
|
121
|
+
assert.strictEqual(response.result.structuredContent.health.scopes[0].dirty, true);
|
|
122
|
+
assert(response.result.structuredContent.results.some(result => result.entry_id === 'modules/auth.md'));
|
|
123
|
+
|
|
124
|
+
response = await client.request('tools/call', { name: 'project_knowledge_search', arguments: { project: 'vector', query: 'payment tokens' } });
|
|
125
|
+
assert.strictEqual(response.result.structuredContent.source, 'knowledge-retrieval-service');
|
|
126
|
+
assert.strictEqual(response.result.structuredContent.backend, 'hybrid+markdown-truth');
|
|
127
|
+
assert(response.result.structuredContent.results.some(result => result.entry_id === 'modules/payments.md'));
|
|
128
|
+
|
|
129
|
+
response = await client.request('tools/call', { name: 'project_knowledge_get', arguments: { projectId: 'project-demo', entry: 'modules/auth.md' } });
|
|
130
|
+
assert.match(response.result.structuredContent.chunks[0].chunk_text, /rotate/i);
|
|
131
|
+
response = await client.request('tools/call', { name: 'project_knowledge_history', arguments: { projectId: 'project-demo' } });
|
|
132
|
+
assert.strictEqual(response.result.structuredContent.results[0].entry_id, 'changes/auth.md');
|
|
133
|
+
|
|
134
|
+
const stateBefore = fs.readFileSync(layout.getProjectStatePath('project-demo'), 'utf8');
|
|
135
|
+
response = await client.request('tools/call', { name: 'project_knowledge_record_requirement', arguments: { projectId: 'project-demo', repoPath: repo, client: 'codex', sessionId: 'session-mcp', text: 'Keep refresh token rotation documented.' } });
|
|
136
|
+
assert.strictEqual(response.result.structuredContent.projectId, 'project-demo');
|
|
137
|
+
assert.strictEqual(new ConversationStore({ layout, projectStore }).readEvents('project-demo').length, 1);
|
|
138
|
+
assert.strictEqual(fs.existsSync(layout.getProjectRequirementsPath('project-demo')), false, 'explicit MCP adapter must not create legacy requirements.jsonl');
|
|
139
|
+
assert.strictEqual(fs.readFileSync(layout.getProjectStatePath('project-demo'), 'utf8'), stateBefore, 'requirement tool must not trigger analysis or mutate state');
|
|
140
|
+
assert(!fs.existsSync(layout.getRuntimePath('staging')));
|
|
141
|
+
|
|
142
|
+
response = await client.request('tools/call', { name: 'project_knowledge_get', arguments: { projectId: 'project-demo', entry: '../settings.json' } });
|
|
143
|
+
assert.strictEqual(response.result.isError, true);
|
|
144
|
+
console.log('mcp-server-test PASS');
|
|
145
|
+
} finally {
|
|
146
|
+
client.child.stdin.end();
|
|
147
|
+
await new Promise(resolve => client.child.once('exit', resolve));
|
|
148
|
+
}
|
|
149
|
+
})().catch(error => { console.error(error); process.exitCode = 1; }).finally(() => fs.rmSync(temp, { recursive: true, force: true }));
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Regression: the module supervisor's backoff counter must reset after a
|
|
3
|
+
// stable run. Before the fix, attempts accumulated for the whole shell
|
|
4
|
+
// lifetime, so one-off exits spread over weeks eventually hit the give-up
|
|
5
|
+
// cap and left the module dead while the shell kept proxying to its port —
|
|
6
|
+
// the endless MODULE_UNREACHABLE episodes in the shell UI.
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const os = require('node:os');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const assert = require('node:assert/strict');
|
|
11
|
+
const { ModuleBridge } = require('../lib/module-bridge');
|
|
12
|
+
|
|
13
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
14
|
+
|
|
15
|
+
function supervisedBridge() {
|
|
16
|
+
const bridge = new ModuleBridge();
|
|
17
|
+
const events = [];
|
|
18
|
+
bridge.logger = {
|
|
19
|
+
info: () => {},
|
|
20
|
+
warn: (event, message) => events.push({ event, message }),
|
|
21
|
+
error: () => {},
|
|
22
|
+
};
|
|
23
|
+
return { bridge, events };
|
|
24
|
+
}
|
|
25
|
+
const restarted = events => events.filter(entry => entry.event === 'modules.supervisor' && /restarting/.test(entry.message)).length;
|
|
26
|
+
const gaveUp = events => events.filter(entry => entry.event === 'modules.supervisor' && /stopped/.test(entry.message)).length;
|
|
27
|
+
|
|
28
|
+
async function main() {
|
|
29
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'kb-supervisor-backoff-'));
|
|
30
|
+
|
|
31
|
+
// A quick crash loop must still be abandoned (the cap keeps its purpose).
|
|
32
|
+
// No _stableAfterMs override here: quick exits face the production default.
|
|
33
|
+
const crashLoop = supervisedBridge();
|
|
34
|
+
const quickExit = path.join(root, 'quick-exit.js');
|
|
35
|
+
fs.writeFileSync(quickExit, 'process.exit(0);');
|
|
36
|
+
crashLoop.bridge._spawnSupervised({ name: 'fixture', command: `node ${JSON.stringify(quickExit)}`, _attempts: 5 });
|
|
37
|
+
await sleep(300);
|
|
38
|
+
assert.equal(crashLoop.bridge.supervised.length, 0, 'the exited child must not linger as supervised');
|
|
39
|
+
assert.equal(restarted(crashLoop.events), 0, 'a sixth quick exit must not schedule a restart');
|
|
40
|
+
assert.equal(gaveUp(crashLoop.events), 1, 'a sixth quick exit must give up');
|
|
41
|
+
await crashLoop.bridge.stopSupervised();
|
|
42
|
+
|
|
43
|
+
// A service that ran stably before exiting must respawn with a fresh counter.
|
|
44
|
+
const stable = supervisedBridge();
|
|
45
|
+
const linger = path.join(root, 'linger.js');
|
|
46
|
+
fs.writeFileSync(linger, 'setTimeout(() => process.exit(0), 50);');
|
|
47
|
+
const spawnedSpecs = [];
|
|
48
|
+
const spawnOriginal = stable.bridge._spawnSupervised.bind(stable.bridge);
|
|
49
|
+
stable.bridge._spawnSupervised = spec => { spawnedSpecs.push(spec); return spawnOriginal(spec); };
|
|
50
|
+
stable.bridge._spawnSupervised({ name: 'fixture', command: `node ${JSON.stringify(linger)}`, _attempts: 5, _stableAfterMs: 0 });
|
|
51
|
+
await sleep(300);
|
|
52
|
+
assert.equal(spawnedSpecs.length, 1, 'the first child is the only spawn so far');
|
|
53
|
+
assert.equal(restarted(stable.events), 1, 'a stable exit at the attempt cap must schedule a restart, not give up');
|
|
54
|
+
assert.equal(gaveUp(stable.events), 0, 'a stable exit must never abandon the service');
|
|
55
|
+
await sleep(2000 + 400); // first backoff of a fresh incident: 1000 * 2^1 = 2s
|
|
56
|
+
assert.equal(spawnedSpecs.length, 2, 'the service must have been respawned');
|
|
57
|
+
assert.equal(spawnedSpecs[1]._attempts, 1, 'the respawn opens a fresh incident instead of inheriting the old count');
|
|
58
|
+
assert.equal(gaveUp(stable.events), 0, 'the respawned service must not be abandoned');
|
|
59
|
+
await stable.bridge.stopSupervised();
|
|
60
|
+
|
|
61
|
+
console.log('module supervisor backoff reset test PASS');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
main().catch(error => { console.error(error); process.exitCode = 1; });
|
|
@@ -109,7 +109,7 @@ function buildAndInstallPackage() {
|
|
|
109
109
|
}, 'packaged UI bootstrap', 20000);
|
|
110
110
|
|
|
111
111
|
assert.strictEqual(await browser.evaluate("document.getElementById('projectSelect').disabled"), true);
|
|
112
|
-
assert.strictEqual(await browser.evaluate("document.querySelectorAll('nav [data-view]').length"),
|
|
112
|
+
assert.strictEqual(await browser.evaluate("document.querySelectorAll('nav [data-view]').length"), 6, 'six fixed pages (AI 团队 added 2026-11)');
|
|
113
113
|
assert.strictEqual(await browser.evaluate("document.querySelector('[data-view=\"work\"]')"), null, 'the packed UI ships no work navigation entry');
|
|
114
114
|
assert.strictEqual(browser.exceptions.length, 0, `packaged UI runtime exceptions: ${JSON.stringify(browser.exceptions)}`);
|
|
115
115
|
console.log('packaged-ui-smoke-test PASS');
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// MEM-HOME — 首页待确认记忆直达审核。
|
|
3
|
+
//
|
|
4
|
+
// 迁移说明(五页简化 UI):
|
|
5
|
+
// - 首页不再罗列项目:导入成功的可见面改为顶栏 #projectSelect 的选项。
|
|
6
|
+
// - 首页候选行的审核入口改为 data-action="review-candidate"(data-id 绑定
|
|
7
|
+
// 具体候选),与「长期记忆」页候选箱共用 reviewCandidate() 的
|
|
8
|
+
// #appDialog 审核对话框;确认动作为表单提交(reviewForm 的提交按钮)。
|
|
9
|
+
// - 冻结依据的展示从「原始总结」字段改为「查看原始依据(冻结原文)」
|
|
10
|
+
// 折叠块;确认后面板空态文案为「没有待确认的记忆」。
|
|
11
|
+
//
|
|
12
|
+
// The home「待确认记忆」panel names a candidate memory, so it must be an
|
|
13
|
+
// entry into review, not a read-only preview: one real pointer click on the
|
|
14
|
+
// candidate row must open the review dialog for THAT exact candidate — text,
|
|
15
|
+
// scope and frozen evidence included — and the confirm action in the dialog
|
|
16
|
+
// must complete the handling without ever visiting the memory view. The old
|
|
17
|
+
// shell offered only a generic「查看候选箱」jump, leaving the user to find
|
|
18
|
+
// the candidate again in the full list.
|
|
19
|
+
//
|
|
20
|
+
// The regression drives the real product UI in a real browser against an
|
|
21
|
+
// isolated instance (own port, own data dir, own knowledge dir, own Bridge
|
|
22
|
+
// journal, own browser profile). The candidate is produced by the REAL
|
|
23
|
+
// pipeline — a real follow-up commit, a real conversation event, a real
|
|
24
|
+
// maintenance run, the real eligibility gate — so the home panel lists what
|
|
25
|
+
// the engine really stored. Every pointer action is a CDP
|
|
26
|
+
// Input.dispatchMouseEvent on the real coordinates of the real control, and
|
|
27
|
+
// the page itself records that the click it received carried
|
|
28
|
+
// isTrusted === true.
|
|
29
|
+
//
|
|
30
|
+
// Screenshots are written to PK_TEST_EVIDENCE_DIR when the batch sets it, so
|
|
31
|
+
// this tracked file stays free of machine-specific paths.
|
|
32
|
+
|
|
33
|
+
const path = require('node:path');
|
|
34
|
+
const assert = require('node:assert/strict');
|
|
35
|
+
|
|
36
|
+
const { startHarness, makeRepo } = require('./helpers/parallel-memory-shell');
|
|
37
|
+
|
|
38
|
+
const EVIDENCE = process.env.PK_TEST_EVIDENCE_DIR ? path.resolve(process.env.PK_TEST_EVIDENCE_DIR) : null;
|
|
39
|
+
|
|
40
|
+
const CANDIDATE_TEXT = '对外错误信息使用中文表述,并优先复用已有模块。';
|
|
41
|
+
|
|
42
|
+
/** Record every click the page really receives on the home review entry. */
|
|
43
|
+
async function installHomeReviewClickRecorder(harness) {
|
|
44
|
+
await harness.run(`(() => {
|
|
45
|
+
window.__homeReviewClicks = [];
|
|
46
|
+
if (!window.__homeReviewHooked) {
|
|
47
|
+
window.__homeReviewHooked = true;
|
|
48
|
+
document.addEventListener('click', event => {
|
|
49
|
+
const button = event.target.closest ? event.target.closest('#homeContent [data-action="review-candidate"]') : null;
|
|
50
|
+
if (button) window.__homeReviewClicks.push({
|
|
51
|
+
trusted: event.isTrusted === true,
|
|
52
|
+
memoryId: button.getAttribute('data-id'),
|
|
53
|
+
label: (button.textContent || '').trim(),
|
|
54
|
+
});
|
|
55
|
+
}, true);
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
})()`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function main() {
|
|
62
|
+
const harness = await startHarness({ tag: 'memhome', evidenceDir: EVIDENCE || undefined });
|
|
63
|
+
try {
|
|
64
|
+
// A real project, imported through the real product API. The five-page
|
|
65
|
+
// shell surfaces the registry in the top-bar project selector.
|
|
66
|
+
const repo = makeRepo(harness.fixture, 'memhome-repo', { 'README.md': '# 首页候选\n' });
|
|
67
|
+
const { projectId } = await harness.importProject(repo, '首页候选甲');
|
|
68
|
+
await harness.requestRegistryRefresh();
|
|
69
|
+
await harness.waitFor(
|
|
70
|
+
() => harness.run("document.getElementById('projectSelect').textContent.includes('首页候选甲')"),
|
|
71
|
+
'the imported project is listed',
|
|
72
|
+
20000,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// A real candidate through the real pipeline (commit + event + run + gate).
|
|
76
|
+
const produced = await harness.produceCandidate({ repo, projectId, text: CANDIDATE_TEXT, scopeType: 'global' });
|
|
77
|
+
assert.equal(produced.capture.accepted, 1, `the real run admitted one candidate: ${JSON.stringify(produced.capture)}`);
|
|
78
|
+
const stored = (await harness.productMemories()).find(m => m.text === CANDIDATE_TEXT);
|
|
79
|
+
assert.ok(stored, 'the candidate really exists in the engine');
|
|
80
|
+
assert.equal(stored.status, 'candidate', 'the stored candidate is still pending review');
|
|
81
|
+
|
|
82
|
+
await installHomeReviewClickRecorder(harness);
|
|
83
|
+
|
|
84
|
+
// MEM-HOME expected 1: the home panel not only names the candidate, it
|
|
85
|
+
// exposes a per-item review entry bound to that exact memory.
|
|
86
|
+
await harness.requestRegistryRefresh();
|
|
87
|
+
await harness.waitFor(
|
|
88
|
+
() => harness.run(`(() => {
|
|
89
|
+
const button = document.querySelector('#homeContent [data-action="review-candidate"]');
|
|
90
|
+
if (!button) return false;
|
|
91
|
+
const panel = button.closest('section.panel');
|
|
92
|
+
const row = button.closest('.row');
|
|
93
|
+
return panel && panel.querySelector('h2').textContent.includes('待确认记忆')
|
|
94
|
+
&& row && row.textContent.includes(${JSON.stringify(CANDIDATE_TEXT)})
|
|
95
|
+
&& button.getAttribute('data-id') === ${JSON.stringify(stored.id)};
|
|
96
|
+
})()`),
|
|
97
|
+
'the home 待确认记忆 panel offers a review entry for the exact candidate',
|
|
98
|
+
20000,
|
|
99
|
+
);
|
|
100
|
+
await harness.browser.screenshot(path.join(harness.evidence, 'memhome-home-review-entry.png'));
|
|
101
|
+
|
|
102
|
+
// MEM-HOME expected 2: one trusted pointer click opens the review dialog
|
|
103
|
+
// for that exact candidate, straight from the home view.
|
|
104
|
+
await harness.nativeClick('#homeContent [data-action="review-candidate"]');
|
|
105
|
+
const clicks = await harness.run('window.__homeReviewClicks || []');
|
|
106
|
+
assert.ok(clicks.length >= 1, 'the page really received the home review click');
|
|
107
|
+
const click = clicks[clicks.length - 1];
|
|
108
|
+
assert.equal(click.trusted, true, `the click the page received is a trusted browser event: ${JSON.stringify(click)}`);
|
|
109
|
+
assert.equal(click.memoryId, stored.id, `the click is bound to the exact candidate: ${JSON.stringify(click)}`);
|
|
110
|
+
|
|
111
|
+
await harness.waitFor(
|
|
112
|
+
() => harness.run(`(() => document.getElementById('appDialog').open === true
|
|
113
|
+
&& document.getElementById('appDialogTitle').textContent.includes('审核候选记忆')
|
|
114
|
+
&& document.getElementById('appDialogBody').textContent.includes(${JSON.stringify(CANDIDATE_TEXT)}))()`),
|
|
115
|
+
'the review dialog opens with the exact candidate',
|
|
116
|
+
10000,
|
|
117
|
+
);
|
|
118
|
+
const dialogText = await harness.run("document.getElementById('appDialog').textContent");
|
|
119
|
+
assert.ok(dialogText.includes('原始依据'), `the dialog carries the frozen source evidence: ${dialogText.slice(0, 120)}`);
|
|
120
|
+
await harness.browser.screenshot(path.join(harness.evidence, 'memhome-review-dialog.png'));
|
|
121
|
+
|
|
122
|
+
// MEM-HOME expected 3: the handling completes in place — confirm inside
|
|
123
|
+
// the dialog, and the home panel itself reflects the resolved candidate.
|
|
124
|
+
await harness.nativeClick('#appDialogActions button[type="submit"]');
|
|
125
|
+
await harness.waitFor(
|
|
126
|
+
() => harness.run("document.getElementById('appDialog').open === false"),
|
|
127
|
+
'the review dialog closes after confirming',
|
|
128
|
+
10000,
|
|
129
|
+
);
|
|
130
|
+
await harness.waitFor(
|
|
131
|
+
() => harness.run(`(() => document.getElementById('homeContent').textContent.includes('没有待确认的记忆')
|
|
132
|
+
&& !document.querySelectorAll('#homeContent [data-action="review-candidate"]').length)()`),
|
|
133
|
+
'the home panel no longer offers the confirmed candidate for review',
|
|
134
|
+
20000,
|
|
135
|
+
);
|
|
136
|
+
const confirmed = (await harness.productMemories()).find(m => m.id === stored.id);
|
|
137
|
+
assert.equal(confirmed.status, 'confirmed', `the engine really holds the confirmed memory: ${JSON.stringify(confirmed.status)}`);
|
|
138
|
+
await harness.browser.screenshot(path.join(harness.evidence, 'memhome-confirmed-home.png'));
|
|
139
|
+
|
|
140
|
+
assert.equal(harness.browser.exceptions.length, 0, `no uncaught product JavaScript exceptions: ${JSON.stringify(harness.browser.exceptions)}`);
|
|
141
|
+
|
|
142
|
+
console.log('parallel-memory-home-review-test PASS (the home 待确认记忆 entry opens the exact candidate for review and confirm completes in place)');
|
|
143
|
+
} finally {
|
|
144
|
+
await harness.cleanup();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
main().catch(error => { console.error(error.stack || error.message); process.exitCode = 1; });
|