@sanqianx/project-knowledge 5.1.6 → 5.2.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 +11 -0
- package/_site/_test/recovery-label-contract-test.js +10 -0
- package/_site/_test/workflow-module-wiring-test.js +150 -0
- package/_site/_test/workflow-tools-test.js +218 -72
- package/_site/lib/contracts.js +3 -0
- package/_site/lib/module-bridge.js +86 -5
- package/_site/lib/server-app.js +6 -1
- package/_site/lib/workflow-tool-runtime.js +233 -43
- package/bin/project-knowledge-mcp.js +312 -282
- package/module-runtime-manifest.json +36 -36
- package/package.json +3 -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 +1 -1
- package/plugins/project-knowledge/skills/pk-team/SKILL.md +37 -4
- package/ui/product.js +13 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [5.2.0] - 2026-11-21
|
|
4
|
+
|
|
5
|
+
- 工作流模块升级至 `0.2.0`。任务创建在事务内绑定受信 Git 根(同名仓与目录不符直接拒绝,未绑定任务在检查启动前失败);CLI 修复二次监听崩溃。
|
|
6
|
+
- 审查作业化:提交审查立即返回 reviewJobId,程序检查在事务外执行,作业完成前复核占有权、验收版本与快照;模型审查阶段如实投影(等待/缺配置/身份已核实/阻塞),晚到的历史结果只留档不覆盖新一轮整改;独立 Codex 审查者拿到有界 diff 与交付树内容,只有运行身份通过受信模型校验才可能形成通过收据。
|
|
7
|
+
- 团队执行(最小自治):项目配置 Leader、预算、可派发成员与审查成员并显式开启 autoDispatch 后,一句话即可激活团队任务——真实 GLM Leader 产出至多 3 项依赖有序的工作项计划(原子预算预留),工作项由发起会话认领、实现、报告交付,整任务经独立审查裁决;普通任务零 Leader 调用。浏览器伪造 executionMode 一律降级为普通任务。
|
|
8
|
+
|
|
9
|
+
## [5.1.7] - 2026-11-20
|
|
10
|
+
|
|
11
|
+
- 知识引擎升级至 `0.3.4`。维护任务先读 Git 提交树与对象元数据,再对筛选后的路径生成补丁。数据集和超大对象按路径、大小和新旧对象 ID 归档。只有数据变更的提交也能生成可索引的记录。
|
|
12
|
+
- 活动详情显示实际采集到的补丁范围和提前归档的对象数量。文本补丁超限时保留有界的文件补丁,旧失败任务可在原记录上重试。
|
|
13
|
+
|
|
3
14
|
## [5.1.6] - 2026-11-20
|
|
4
15
|
|
|
5
16
|
- 知识引擎升级至 `0.3.3`。提交取证合并文件变更统计、限制重命名搜索,并流式生成可校验的补丁证据。60 秒内未生成补丁时,用 180 秒再尝试一次。活动详情显示 Git 失败原因、限时和已读取的字节数。
|
|
@@ -42,4 +42,14 @@ assert(app.includes('已提交重试'), 'retry button toast must acknowledge sub
|
|
|
42
42
|
// Evidence failures render their concrete resource.
|
|
43
43
|
assert(app.includes('失败资源:'), 'evidence failures must show the concrete resource');
|
|
44
44
|
|
|
45
|
+
const coverageRenderer = app.match(/function gitEvidenceCoverage\(coverage\) \{[\s\S]*?\n \}/);
|
|
46
|
+
assert(coverageRenderer, 'activity must explain the evidence coverage for oversized commits');
|
|
47
|
+
const renderCoverage = new Function('esc', 'return (' + coverageRenderer[0] + ')')(String);
|
|
48
|
+
assert.strictEqual(renderCoverage(null), '');
|
|
49
|
+
assert.match(renderCoverage({ kind: 'text-patch' }), /完整文本差异.*二进制 Git 对象标识/);
|
|
50
|
+
assert.match(renderCoverage({ kind: 'selected-file-patches', textPathCount: 3 }), /3 项文本补丁/);
|
|
51
|
+
assert.match(renderCoverage({ kind: 'selected-file-patches', textPathCount: 1, preflightSkippedPaths: 2 }), /2 项在生成补丁前已仅归档对象标识/);
|
|
52
|
+
assert.match(renderCoverage({ kind: 'file-object-list' }), /补丁未收录/);
|
|
53
|
+
assert(app.includes('${gitEvidenceCoverage(r.patchCoverage)}'), 'activity cards must use the reported evidence coverage');
|
|
54
|
+
|
|
45
55
|
console.log('recovery-label-contract-test PASS');
|
|
@@ -53,6 +53,12 @@ function workflowInstalled() {
|
|
|
53
53
|
} else {
|
|
54
54
|
assert.ok(specs.some(spec => spec.name === 'workflow'), 'an installed workflow runtime gets a supervised spec');
|
|
55
55
|
assert.match(specs.find(spec => spec.name === 'workflow').command, /ai-coding-workflow.*serve/, 'the spec launches the workflow CLI');
|
|
56
|
+
// M0-C: the managed workflow module receives the Bridge URL so its
|
|
57
|
+
// independent consumer registers with a wake-up callback — exactly like
|
|
58
|
+
// the terminal/workbench/engine specs already do.
|
|
59
|
+
const workflowSpec = specs.find(spec => spec.name === 'workflow');
|
|
60
|
+
assert.equal(workflowSpec.env.KB_EVENT_BRIDGE_URL, bridge.eventBridgeUrl, 'the workflow spec carries KB_EVENT_BRIDGE_URL');
|
|
61
|
+
assert.equal(workflowSpec.env.KB_WORKFLOW_RUNTIME_TOKEN, bridge.runtimeToken, 'the workflow spec carries the runtime token');
|
|
56
62
|
}
|
|
57
63
|
for (const pinned of ['terminal', 'vector-hub', 'event-bridge', 'knowledge-engine']) {
|
|
58
64
|
assert.ok(specs.some(spec => spec.name === pinned), `pinned module ${pinned} keeps its spec`);
|
|
@@ -98,5 +104,149 @@ function workflowInstalled() {
|
|
|
98
104
|
assert.equal(res.body.error, 'MODULE_UNREACHABLE');
|
|
99
105
|
assert.equal(res.body.details.failureKind, 'NETWORK_ERROR');
|
|
100
106
|
|
|
107
|
+
// 6) M0-C trusted review forward: the shell resolves the registered project
|
|
108
|
+
// through its own read-only resolver and attaches ITS runtime token plus
|
|
109
|
+
// the canonical Git root; the caller's own token header is never
|
|
110
|
+
// forwarded as module trust. Verified against a REAL workflow module
|
|
111
|
+
// (installed pinned package, or KB_WORKFLOW_TEST_SOURCE candidate).
|
|
112
|
+
let upstreamWorkflow = null;
|
|
113
|
+
const path = require('node:path');
|
|
114
|
+
try {
|
|
115
|
+
const source = process.env.KB_WORKFLOW_TEST_SOURCE
|
|
116
|
+
? path.resolve(process.env.KB_WORKFLOW_TEST_SOURCE)
|
|
117
|
+
: require.resolve('@sanqianx/ai-coding-workflow/src/server', { paths: [path.resolve(__dirname, '..', '..')] });
|
|
118
|
+
upstreamWorkflow = require(source).createWorkflowServer;
|
|
119
|
+
} catch {
|
|
120
|
+
upstreamWorkflow = null;
|
|
121
|
+
}
|
|
122
|
+
if (!upstreamWorkflow) {
|
|
123
|
+
console.log('workflow-module-wiring-test: trusted-forward section skipped (no workflow module available)');
|
|
124
|
+
} else {
|
|
125
|
+
const fs = require('node:fs');
|
|
126
|
+
const os = require('node:os');
|
|
127
|
+
const childPath = require('node:path');
|
|
128
|
+
const { spawnSync } = require('node:child_process');
|
|
129
|
+
const moduleToken = 'module-runtime-token';
|
|
130
|
+
const upstream = upstreamWorkflow({ dataDir: fs.mkdtempSync(childPath.join(os.tmpdir(), 'wf-wiring-')), runtimeToken: moduleToken });
|
|
131
|
+
const bound = await upstream.listen(0);
|
|
132
|
+
await fetch(`${bound.host === '127.0.0.1' ? 'http://127.0.0.1' : `http://${bound.host}`}:${bound.port}/api/workflow/v1/team`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ requestId: 'wiring-seed' }) });
|
|
133
|
+
const repo = fs.mkdtempSync(childPath.join(os.tmpdir(), 'wf-wiring-repo-'));
|
|
134
|
+
const git = args => { const r = spawnSync('git', ['-C', repo, ...args], { encoding: 'utf8' }); if (r.status !== 0) throw new Error(r.stderr); };
|
|
135
|
+
git(['init', '-q', '-b', 'main']); git(['config', 'user.email', 't@t']); git(['config', 'user.name', 't']);
|
|
136
|
+
fs.writeFileSync(childPath.join(repo, 'a.js'), 'export const a = 1;\n');
|
|
137
|
+
git(['add', '.']); git(['commit', '-qm', 'init']);
|
|
138
|
+
const seen = { authorization: null, runtimeToken: null, body: null };
|
|
139
|
+
const forwardingBridge = new ModuleBridge({
|
|
140
|
+
workflowUrl: `http://127.0.0.1:${bound.port}`,
|
|
141
|
+
runtimeToken: moduleToken,
|
|
142
|
+
workflowProjectResolver: input => ({ projectId: input.projectId || 'proj-wired', repoPath: repo }),
|
|
143
|
+
});
|
|
144
|
+
const shellProxy = http.createServer((req2, res2) => forwardingBridge.proxyWorkflow(req2, res2, req2.url.replace(/\?.*$/, ''), (req2.url.match(/\?.*$/) || [''])[0]));
|
|
145
|
+
await new Promise(resolve => shellProxy.listen(0, '127.0.0.1', resolve));
|
|
146
|
+
try {
|
|
147
|
+
// Create a task through the same proxy, then request its review.
|
|
148
|
+
const createdResponse = await fetch(`http://127.0.0.1:${shellProxy.address().port}/api/workflow/workflow-tasks`, {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
headers: { 'Content-Type': 'application/json', 'X-KB-Runtime-Token': 'client-token-must-not-forward' },
|
|
151
|
+
body: JSON.stringify({ requestId: 'wiring-task', projectId: 'proj-wired', title: '受信转发' }),
|
|
152
|
+
});
|
|
153
|
+
const created = await createdResponse.json().catch(() => ({}));
|
|
154
|
+
assert.equal(createdResponse.status, 201, JSON.stringify(created));
|
|
155
|
+
// The creation itself carries no canonicalGitRoot (only reviews do), so
|
|
156
|
+
// the task stays unbound unless the review forwards the trusted root.
|
|
157
|
+
const reviewResponse = await fetch(`http://127.0.0.1:${shellProxy.address().port}/api/workflow/workflow-tasks/${created.task.taskId}/reviews`, {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
headers: { 'Content-Type': 'application/json', 'X-KB-Runtime-Token': 'client-token-must-not-forward' },
|
|
160
|
+
body: JSON.stringify({ requestId: 'wiring-review', projectId: 'proj-wired', repoPath: repo, tools: ['eslint'] }),
|
|
161
|
+
});
|
|
162
|
+
const reviewBody = await reviewResponse.json().catch(() => ({}));
|
|
163
|
+
assert.ok(reviewResponse.status === 202 || reviewResponse.status === 201, `review via the shell proxy answers ${reviewResponse.status}: ${JSON.stringify(reviewBody).slice(0, 200)}`);
|
|
164
|
+
if (reviewBody.reviewJobId) {
|
|
165
|
+
const job = await (await fetch(`http://127.0.0.1:${bound.port}/api/workflow/v1/review-jobs/${reviewBody.reviewJobId}`, { headers: { 'X-KB-Runtime-Token': moduleToken } })).json();
|
|
166
|
+
assert.equal(job.job.repoPath, fs.realpathSync(repo), 'the trusted forward bound the canonical root');
|
|
167
|
+
assert.equal(job.job.tools[0], 'eslint');
|
|
168
|
+
assert.equal(job.job.executionToken, undefined, 'the execution token never leaves the module');
|
|
169
|
+
} else {
|
|
170
|
+
// Old installed module: the POST answered with legacy receipts — the
|
|
171
|
+
// forward still resolved the project through the shell.
|
|
172
|
+
assert.ok(Array.isArray(reviewBody.receipts), 'the old module answers with receipts');
|
|
173
|
+
}
|
|
174
|
+
} finally {
|
|
175
|
+
shellProxy.closeAllConnections(); await new Promise(resolve => shellProxy.close(resolve));
|
|
176
|
+
await upstream.close();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 7) P2b: team-mode creation is trusted-forwarded ONLY for registered projects.
|
|
181
|
+
{
|
|
182
|
+
const path = require('node:path');
|
|
183
|
+
const source = process.env.KB_WORKFLOW_TEST_SOURCE
|
|
184
|
+
? path.resolve(process.env.KB_WORKFLOW_TEST_SOURCE)
|
|
185
|
+
: require.resolve('@sanqianx/ai-coding-workflow/src/server', { paths: [path.resolve(__dirname, '..', '..')] });
|
|
186
|
+
let createServer = null;
|
|
187
|
+
try { createServer = require(source).createWorkflowServer; } catch { createServer = null; }
|
|
188
|
+
if (!createServer) {
|
|
189
|
+
console.log('workflow-module-wiring-test: P2b team-forward section skipped (no module)');
|
|
190
|
+
} else {
|
|
191
|
+
const fsx = require('node:fs');
|
|
192
|
+
const osx = require('node:os');
|
|
193
|
+
const { spawnSync } = require('node:child_process');
|
|
194
|
+
const moduleToken = 'p2b-module-token';
|
|
195
|
+
const upstream = createServer({ dataDir: fsx.mkdtempSync(path.join(osx.tmpdir(), 'p2b-wire-')), runtimeToken: moduleToken });
|
|
196
|
+
const bound = await upstream.listen(0);
|
|
197
|
+
const base = 'http://127.0.0.1:' + bound.port;
|
|
198
|
+
await fetch(base + '/api/workflow/v1/team', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ requestId: 'seed' }) });
|
|
199
|
+
const repo = fsx.mkdtempSync(path.join(osx.tmpdir(), 'p2b-wire-repo-'));
|
|
200
|
+
const git = a => { const r = spawnSync('git', ['-C', repo, ...a], { encoding: 'utf8' }); if (r.status !== 0) throw new Error(r.stderr); };
|
|
201
|
+
git(['init', '-q', '-b', 'main']); git(['config', 'user.email', 't@t']); git(['config', 'user.name', 't']);
|
|
202
|
+
fsx.writeFileSync(path.join(repo, 'a.js'), 'export const a = 1;' + String.fromCharCode(10));
|
|
203
|
+
git(['add', '.']); git(['commit', '-qm', 'i']);
|
|
204
|
+
// 注册受信根 + 开启 autoDispatch 的项目(受信 settings 写入)
|
|
205
|
+
const authHeaders = { 'Content-Type': 'application/json', 'X-KB-Runtime-Token': moduleToken };
|
|
206
|
+
await fetch(base + '/api/internal/project-roots', { method: 'POST', headers: authHeaders, body: JSON.stringify({ requestId: 'reg', projectId: 'proj-p2b', canonicalGitRoot: repo }) });
|
|
207
|
+
const members = (await (await fetch(base + '/api/workflow/v1/members')).json()).members;
|
|
208
|
+
await fetch(base + '/api/workflow/v1/projects/proj-p2b/settings', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ requestId: 'cfg', enabled: true, autoDispatch: true, leaderMemberId: members[0].memberId, developerMemberIds: [members[0].memberId] }) });
|
|
209
|
+
const seenToken = { value: null };
|
|
210
|
+
const bridge = new ModuleBridge({
|
|
211
|
+
workflowUrl: base, runtimeToken: moduleToken,
|
|
212
|
+
workflowProjectResolver: input => ({ projectId: input.projectId === 'proj-p2b' ? 'proj-p2b' : null, repoPath: input.projectId === 'proj-p2b' ? repo : null }),
|
|
213
|
+
});
|
|
214
|
+
// 用最小 http 服务驱动 proxyWorkflow
|
|
215
|
+
const http = require('node:http');
|
|
216
|
+
const shell = http.createServer((rq, rs) => bridge.proxyWorkflow(rq, rs, rq.url.split('?')[0], ''));
|
|
217
|
+
await new Promise(r => shell.listen(0, '127.0.0.1', r));
|
|
218
|
+
try {
|
|
219
|
+
// 注册项目 + team → 受信(壳解析成功才带 token)→ 模块生效
|
|
220
|
+
const okRes = await fetch('http://127.0.0.1:' + shell.address().port + '/api/workflow/workflow-tasks', {
|
|
221
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
222
|
+
body: JSON.stringify({ requestId: 'team-ok', projectId: 'proj-p2b', title: '团队任务', executionMode: 'team' }),
|
|
223
|
+
});
|
|
224
|
+
const okJson = await okRes.json();
|
|
225
|
+
// Capability-branched: the installed pinned module predates team
|
|
226
|
+
// execution (its tasks have no executionMode) — only a module that
|
|
227
|
+
// UNDERSTANDS team mode may be asserted to arm it.
|
|
228
|
+
if (okJson.task && okJson.task.executionMode === 'team') {
|
|
229
|
+
assert.equal(okJson.task.planStatus, 'pending-plan', 'team armed with a pending plan');
|
|
230
|
+
} else {
|
|
231
|
+
const health = await (await fetch(base + '/api/health')).json();
|
|
232
|
+
assert.notEqual(health.capabilities && health.capabilities.teamExecution, true, 'a team-capable module must arm team mode through the trusted forward');
|
|
233
|
+
console.log('workflow-module-wiring-test: P2b team-arm skipped (legacy module without team execution)');
|
|
234
|
+
}
|
|
235
|
+
// 未注册项目 + team → 壳不带 token → 模块静默降级
|
|
236
|
+
const degradeRes = await fetch('http://127.0.0.1:' + shell.address().port + '/api/workflow/workflow-tasks', {
|
|
237
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
238
|
+
body: JSON.stringify({ requestId: 'team-no', projectId: 'unregistered', title: '伪造团队', executionMode: 'team' }),
|
|
239
|
+
});
|
|
240
|
+
const degradeJson = await degradeRes.json();
|
|
241
|
+
assert.notEqual(degradeJson.task && degradeJson.task.executionMode, 'team', 'unregistered project degrades to a plain task');
|
|
242
|
+
assert.notEqual(degradeJson.task && degradeJson.task.planStatus, 'pending-plan');
|
|
243
|
+
} finally {
|
|
244
|
+
shell.closeAllConnections(); await new Promise(r => shell.close(r));
|
|
245
|
+
await upstream.close();
|
|
246
|
+
}
|
|
247
|
+
console.log('workflow-module-wiring-test PASS (P2b: trusted team forward / unregistered degrade)');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
101
251
|
console.log('workflow-module-wiring-test PASS');
|
|
102
252
|
})().catch(error => { console.error(error); process.exitCode = 1; });
|
|
@@ -1,97 +1,243 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
// project_workflow_* MCP tool contract: the tools are a thin adapter over the
|
|
3
|
-
// shell proxy into the workflow module. This suite runs a REAL workflow
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// shell proxy into the workflow module. This suite runs a REAL workflow module
|
|
4
|
+
// instance (installed pinned package by default, an explicit local candidate
|
|
5
|
+
// via KB_WORKFLOW_TEST_SOURCE) and drives a REAL stdio MCP child through
|
|
6
|
+
// initialize → tools/list → tools/call for all six tools, plus the review-job
|
|
7
|
+
// flow and the structured degradation when no service is reachable. Missing
|
|
8
|
+
// module sources FAIL the suite — they are never a silent pass.
|
|
7
9
|
const assert = require('node:assert/strict');
|
|
8
10
|
const fs = require('node:fs');
|
|
9
11
|
const os = require('node:os');
|
|
10
12
|
const path = require('node:path');
|
|
13
|
+
const { spawn, spawnSync } = require('node:child_process');
|
|
11
14
|
const { WorkflowToolRuntime } = require('../lib/workflow-tool-runtime');
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
const REPO_ROOT = path.resolve(__dirname, '..', '..');
|
|
17
|
+
const CANDIDATE_SOURCE = process.env.KB_WORKFLOW_TEST_SOURCE || '';
|
|
18
|
+
|
|
19
|
+
function resolveWorkflowModule() {
|
|
20
|
+
if (CANDIDATE_SOURCE) {
|
|
21
|
+
const entry = path.resolve(CANDIDATE_SOURCE);
|
|
22
|
+
if (!fs.existsSync(entry)) throw new Error(`workflow-tools-test FAIL: KB_WORKFLOW_TEST_SOURCE points at a missing file: ${entry}`);
|
|
23
|
+
return { createWorkflowServer: require(entry).createWorkflowServer, source: entry };
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const entry = require.resolve('@sanqianx/ai-coding-workflow/src/server', { paths: [REPO_ROOT] });
|
|
27
|
+
return { createWorkflowServer: require(entry).createWorkflowServer, source: entry };
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw new Error(`workflow-tools-test FAIL: the pinned @sanqianx/ai-coding-workflow package is not installed and KB_WORKFLOW_TEST_SOURCE is not set (${error.message}).`);
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
function tempDataDir() { return fs.mkdtempSync(path.join(os.tmpdir(), 'ai-workflow-mcp-')); }
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Real workflow module upstream: the resolved module's createWorkflowServer
|
|
37
|
+
* binds an ephemeral loopback port in THIS process (the real-CLI lifecycle
|
|
38
|
+
* gate lives in the workflow repo's own integration suite — that keeps this
|
|
39
|
+
* suite working against the currently pinned installed package too).
|
|
40
|
+
*/
|
|
41
|
+
async function startWorkflowModule({ createWorkflowServer, runtimeToken }) {
|
|
42
|
+
const runtime = createWorkflowServer({ dataDir: tempDataDir(), runtimeToken });
|
|
30
43
|
const bound = await runtime.listen(0);
|
|
31
44
|
const base = `http://127.0.0.1:${bound.port}`;
|
|
32
|
-
// Seed the default team so task creation is allowed.
|
|
33
45
|
await fetch(`${base}/api/workflow/v1/team`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ requestId: 'mcp-seed' }) });
|
|
34
|
-
|
|
46
|
+
let hasProjectRoots = false;
|
|
47
|
+
try {
|
|
48
|
+
const probe = await fetch(`${base}/api/health`);
|
|
49
|
+
const health = await probe.json();
|
|
50
|
+
hasProjectRoots = Boolean(health.capabilities && health.capabilities.projectRepoBinding);
|
|
51
|
+
} catch { hasProjectRoots = false; }
|
|
52
|
+
return { runtime, base, hasProjectRoots, close: () => runtime.close() };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function makeGitRepo(files) {
|
|
56
|
+
const repo = fs.mkdtempSync(path.join(os.tmpdir(), 'wf-mcp-review-'));
|
|
57
|
+
const git = args => { const r = spawnSync('git', ['-C', repo, ...args], { encoding: 'utf8' }); if (r.status !== 0) throw new Error(r.stderr); };
|
|
58
|
+
git(['init', '-b', 'main']); git(['config', 'user.email', 't@t']); git(['config', 'user.name', 't']);
|
|
59
|
+
for (const [name, content] of Object.entries(files)) fs.writeFileSync(path.join(repo, name), content);
|
|
60
|
+
git(['add', '.']); git(['commit', '-m', 'init']);
|
|
61
|
+
return repo;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Minimal MCP stdio client: newline-delimited JSON-RPC over the child. */
|
|
65
|
+
class McpClient {
|
|
66
|
+
constructor(env) {
|
|
67
|
+
this.child = spawn(process.execPath, [path.join(REPO_ROOT, 'bin', 'project-knowledge-mcp.js')], {
|
|
68
|
+
cwd: REPO_ROOT,
|
|
69
|
+
env: { ...process.env, ...env },
|
|
70
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
71
|
+
windowsHide: true,
|
|
72
|
+
});
|
|
73
|
+
this.nextId = 1;
|
|
74
|
+
this.pending = new Map();
|
|
75
|
+
this.buffer = '';
|
|
76
|
+
this.child.stdout.on('data', data => {
|
|
77
|
+
this.buffer += data.toString('utf8');
|
|
78
|
+
for (;;) {
|
|
79
|
+
const newline = this.buffer.indexOf('\n');
|
|
80
|
+
if (newline < 0) break;
|
|
81
|
+
const line = this.buffer.slice(0, newline).trim();
|
|
82
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
83
|
+
if (!line) continue;
|
|
84
|
+
let message; try { message = JSON.parse(line); } catch { continue; }
|
|
85
|
+
const pending = this.pending.get(message.id);
|
|
86
|
+
if (pending) { this.pending.delete(message.id); pending(message); }
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.child.stderr.on('data', () => { /* diagnostics only */ });
|
|
90
|
+
}
|
|
91
|
+
request(method, params) {
|
|
92
|
+
const id = this.nextId++;
|
|
93
|
+
const payload = JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n';
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const timer = setTimeout(() => { this.pending.delete(id); reject(new Error(`MCP ${method} timed out`)); }, 60_000);
|
|
96
|
+
this.pending.set(id, message => { clearTimeout(timer); resolve(message); });
|
|
97
|
+
this.child.stdin.write(payload);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async initialize() {
|
|
101
|
+
const reply = await this.request('initialize', { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'workflow-tools-test', version: '0.0.1' } });
|
|
102
|
+
assert.equal(reply.result.serverInfo.name, 'project-knowledge');
|
|
103
|
+
await this.request('notifications/initialized', {});
|
|
104
|
+
return reply.result;
|
|
105
|
+
}
|
|
106
|
+
async listTools() { return (await this.request('tools/list', {})).result.tools; }
|
|
107
|
+
async callTool(name, args) { return (await this.request('tools/call', { name, arguments: args })).result; }
|
|
108
|
+
close() { try { this.child.kill(); } catch { /* already gone */ } }
|
|
35
109
|
}
|
|
36
110
|
|
|
37
111
|
(async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
112
|
+
const { createWorkflowServer, source } = resolveWorkflowModule();
|
|
113
|
+
const runtimeToken = 'test-runtime-token';
|
|
114
|
+
const upstream = await startWorkflowModule({ createWorkflowServer, runtimeToken });
|
|
115
|
+
let repo = null;
|
|
116
|
+
try {
|
|
117
|
+
repo = makeGitRepo({
|
|
118
|
+
'package.json': '{"name":"x","private":true}',
|
|
119
|
+
'eslint.config.mjs': 'export default [{ rules: { complexity: ["error", { max: 1 }] } }];\n',
|
|
120
|
+
'violation.js': 'export function b(x){if(x===1){return 1;}if(x===2){return 2;}if(x===3){return 3;}return 0;}\n',
|
|
121
|
+
});
|
|
122
|
+
// Capability branch: a NEW module exposes the trusted project-roots
|
|
123
|
+
// registry; the pinned installed package may predate it and keeps its
|
|
124
|
+
// own (unbound) behavior — both are real, honestly asserted.
|
|
125
|
+
let boundMode = false;
|
|
126
|
+
if (upstream.hasProjectRoots) {
|
|
127
|
+
const reg = await fetch(`${upstream.base}/api/internal/project-roots`, {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
headers: { 'Content-Type': 'application/json', 'X-KB-Runtime-Token': runtimeToken },
|
|
130
|
+
body: JSON.stringify({ requestId: 'reg-p1', projectId: 'p1', canonicalGitRoot: repo }),
|
|
131
|
+
});
|
|
132
|
+
assert.equal(reg.status, 201, `trusted project-roots registration must succeed: ${JSON.stringify(await reg.json().catch(() => ({})))}`);
|
|
133
|
+
boundMode = true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ---- Real stdio MCP: initialize → tools/list → tools/call × 6 ----
|
|
137
|
+
const mcp = new McpClient({ KB_WORKFLOW_URL: upstream.base, KB_DATA_DIR: tempDataDir() });
|
|
138
|
+
try {
|
|
139
|
+
await mcp.initialize();
|
|
140
|
+
const tools = await mcp.listTools();
|
|
141
|
+
const workflowTools = tools.filter(t => t.name.startsWith('project_workflow_'));
|
|
142
|
+
assert.equal(workflowTools.length, 6, 'the six workflow tools are exposed');
|
|
143
|
+
const byName = Object.fromEntries(workflowTools.map(t => [t.name, t]));
|
|
144
|
+
assert.ok(byName.project_workflow_request_review.inputSchema.properties.tools, 'request_review declares the tools parameter');
|
|
145
|
+
assert.ok(byName.project_workflow_review_result.inputSchema.properties.reviewJobId, 'review_result declares the optional reviewJobId');
|
|
146
|
+
assert.ok(byName.project_workflow_review_result.inputSchema.properties.waitMs.maximum <= 8000, 'the wait ceiling stays inside the runtime timeout');
|
|
147
|
+
|
|
148
|
+
const started = JSON.parse((await mcp.callTool('project_workflow_start', { title: '修复重复重试', goal: '超时后不得重复提交', acceptance: [{ title: '无违规', kind: 'automated', requiredEvidence: [{ toolId: 'eslint' }] }], client: 'claude', sessionId: 'sess-mcp-1', projectId: 'p1' })).content[0].text);
|
|
149
|
+
assert.ok(started.taskId.startsWith('task_'));
|
|
150
|
+
if (boundMode) assert.equal(started.repoBinding.status, 'bound', 'the task binds the trusted root at creation');
|
|
151
|
+
assert.equal(started.sessionBinding.basis, 'declared');
|
|
152
|
+
|
|
153
|
+
const resumed = JSON.parse((await mcp.callTool('project_workflow_resume', { taskId: started.taskId })).content[0].text);
|
|
154
|
+
assert.equal(resumed.title, '修复重复重试');
|
|
155
|
+
assert.equal(resumed.acceptance.length, 1);
|
|
156
|
+
|
|
157
|
+
const listed = JSON.parse((await mcp.callTool('project_workflow_status', { projectId: 'p1' })).content[0].text);
|
|
158
|
+
assert.equal(listed.total, 1);
|
|
159
|
+
|
|
160
|
+
const checkpointed = JSON.parse((await mcp.callTool('project_workflow_checkpoint', { taskId: started.taskId, kind: 'fact', summary: '修复完成', verifiedResults: ['单测通过'], nextAction: '提交审查' })).content[0].text);
|
|
161
|
+
assert.ok(checkpointed.checkpoint.checkpointId);
|
|
162
|
+
|
|
163
|
+
// request_review: a NEW module reserves a job and answers with the
|
|
164
|
+
// reviewJobId; the pinned old module answers with legacy receipts.
|
|
165
|
+
// Over the installed package eslint is absent — 'missing' never passes.
|
|
166
|
+
const review = JSON.parse((await mcp.callTool('project_workflow_request_review', { taskId: started.taskId, repoPath: repo, tools: ['eslint'], note: '第一轮检查' })).content[0].text);
|
|
167
|
+
assert.ok(['completed', 'running', 'legacy-sync'].includes(review.reviewStatus), `honest review status: ${JSON.stringify(review).slice(0, 300)}`);
|
|
168
|
+
if (review.reviewStatus === 'legacy-sync') {
|
|
169
|
+
assert.ok(Array.isArray(review.receipts) && review.receipts.length >= 1, 'the old module still answers with receipts');
|
|
170
|
+
assert.notEqual(review.receipts[0].verdict, 'pass');
|
|
171
|
+
} else {
|
|
172
|
+
assert.ok(review.reviewJobId, 'the review answer carries the job id');
|
|
173
|
+
if (review.reviewStatus === 'completed') {
|
|
174
|
+
assert.equal(review.receipts[0].toolId, 'eslint');
|
|
175
|
+
assert.notEqual(review.receipts[0].verdict, 'pass', 'missing tool never passes');
|
|
176
|
+
} else {
|
|
177
|
+
assert.equal(review.pending, true);
|
|
178
|
+
}
|
|
179
|
+
const resultRead = JSON.parse((await mcp.callTool('project_workflow_review_result', { taskId: started.taskId, reviewJobId: review.reviewJobId, waitMs: 8000 })).content[0].text);
|
|
180
|
+
assert.equal(resultRead.reviewJobId, review.reviewJobId);
|
|
181
|
+
assert.ok(['completed', 'running', 'failed', 'stale'].includes(resultRead.reviewStatus));
|
|
182
|
+
assert.ok(Array.isArray(resultRead.acceptance));
|
|
183
|
+
}
|
|
184
|
+
} finally { mcp.close(); }
|
|
185
|
+
|
|
186
|
+
// ---------- P1b: real model-phase projection + job/task attribution ----------
|
|
187
|
+
if (upstream.hasProjectRoots) {
|
|
188
|
+
const runtime = new (require('../lib/workflow-tool-runtime').WorkflowToolRuntime)({ workflowUrl: upstream.base });
|
|
189
|
+
// A model-required task with no reviewer config must answer the honest
|
|
190
|
+
// blocked projection, never 'pending-model-review'.
|
|
191
|
+
const modelTask = (await runtime.request('workflow-tasks', { method: 'POST', body: {
|
|
192
|
+
requestId: 'p1b-t1', projectId: 'p1', title: 'P1b 模型审查任务',
|
|
193
|
+
acceptance: [{ title: '独立 Review', kind: 'model_review' }],
|
|
194
|
+
} })).task;
|
|
195
|
+
const otherTask = (await runtime.request('workflow-tasks', { method: 'POST', body: {
|
|
196
|
+
requestId: 'p1b-t2', projectId: 'p1', title: 'P1b 另一任务',
|
|
197
|
+
acceptance: [{ title: '独立 Review', kind: 'model_review' }],
|
|
198
|
+
} })).task;
|
|
199
|
+
const reviewA = await runtime.requestReview({ taskId: modelTask.taskId, repoPath: repo, tools: ['eslint'], requestId: 'p1b-rv1' });
|
|
200
|
+
if (reviewA.reviewJobId) {
|
|
201
|
+
const deadline = Date.now() + 60_000;
|
|
202
|
+
let answer = reviewA;
|
|
203
|
+
while (Date.now() < deadline && answer.pending) {
|
|
204
|
+
await new Promise(r => setTimeout(r, 500));
|
|
205
|
+
answer = await runtime.reviewResult({ taskId: modelTask.taskId, reviewJobId: reviewA.reviewJobId, waitMs: 0 });
|
|
206
|
+
}
|
|
207
|
+
assert.equal(answer.overallStatus, 'blocked-missing-config', `P1b: honest projection, got ${answer.overallStatus}`);
|
|
208
|
+
assert.equal(answer.modelReview.status, 'blocked-missing-config');
|
|
209
|
+
assert.equal(answer.pending, false);
|
|
210
|
+
// An explicit job of ANOTHER task must be rejected, never served.
|
|
211
|
+
let mismatch = null;
|
|
212
|
+
try { await runtime.reviewResult({ taskId: otherTask.taskId, reviewJobId: reviewA.reviewJobId, waitMs: 0 }); }
|
|
213
|
+
catch (error) { mismatch = error; }
|
|
214
|
+
assert.ok(mismatch && /属于任务/.test(mismatch.message), 'P1b: cross-task job rejected');
|
|
215
|
+
// A second round makes the first job historical; review_result marks it.
|
|
216
|
+
const reviewB = await runtime.requestReview({ taskId: modelTask.taskId, repoPath: repo, tools: ['eslint'], requestId: 'p1b-rv2' });
|
|
217
|
+
if (reviewB.reviewJobId) {
|
|
218
|
+
const hist = await runtime.reviewResult({ taskId: modelTask.taskId, reviewJobId: reviewA.reviewJobId, waitMs: 0 });
|
|
219
|
+
assert.equal(hist.historical, true, 'P1b: superseded job reads as history');
|
|
220
|
+
assert.match(hist.note || '', /历史/);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
console.log('workflow-tools-test PASS (P1b: model-phase projection, cross-task job rejection, historical marking)');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
console.log(`workflow-tools-test PASS (real stdio MCP over a real workflow module [${boundMode ? 'job+binding' : 'legacy'} mode]: 6 tools, review flow)`);
|
|
227
|
+
} finally {
|
|
228
|
+
await upstream.close();
|
|
229
|
+
}
|
|
91
230
|
|
|
92
231
|
// Degradation: no live shell, no explicit URL -> structured WORKFLOW_UNAVAILABLE.
|
|
93
232
|
const offline = new WorkflowToolRuntime({ workflowUrl: 'http://127.0.0.1:9' });
|
|
94
233
|
try { await offline.status({}); throw new Error('offline status should fail'); }
|
|
95
234
|
catch (error) { assert.equal(error.code, 'WORKFLOW_UNAVAILABLE'); }
|
|
235
|
+
const offlineMcp = new McpClient({ KB_DATA_DIR: tempDataDir() });
|
|
236
|
+
try {
|
|
237
|
+
await offlineMcp.initialize();
|
|
238
|
+
const offlineCall = await offlineMcp.callTool('project_workflow_status', {});
|
|
239
|
+
assert.equal(offlineCall.isError, true, 'an unreachable module is a structured tool error');
|
|
240
|
+
assert.match(offlineCall.content[0].text, /WORKFLOW_UNAVAILABLE/);
|
|
241
|
+
} finally { offlineMcp.close(); }
|
|
96
242
|
console.log('workflow-tools-test PASS (structured degradation when unreachable)');
|
|
97
243
|
})().catch(error => { console.error(error); process.exitCode = 1; });
|
package/_site/lib/contracts.js
CHANGED
|
@@ -79,6 +79,9 @@ const ERROR_CODES = Object.freeze([
|
|
|
79
79
|
'ENGINE_INVALID_RESPONSE',
|
|
80
80
|
'ENGINE_REQUEST_FAILED',
|
|
81
81
|
'ENGINE_URL_INVALID',
|
|
82
|
+
// Workflow module (fifth module) tool surface — additive M0-C.
|
|
83
|
+
'WORKFLOW_UNAVAILABLE',
|
|
84
|
+
'WORKFLOW_HTTP_ERROR',
|
|
82
85
|
]);
|
|
83
86
|
|
|
84
87
|
const IMMUTABLE_PROJECT_FIELDS = Object.freeze([
|