@sanqianx/project-knowledge 5.0.35 → 5.1.1

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.
@@ -1,4 +1,8 @@
1
1
  'use strict';
2
+ // 迁移说明(2026-11-15 六页主导航:新增 AI 团队):
3
+ // - 导航契约:五页 home/memory/projects/search/activity → 六页,在 home 后
4
+ // 插入 team(AI 团队)。team 页是独立工作流模块的同源 iframe 挂载
5
+ // (/workflow-ui/ 页面代理),不是 shell 业务代码;诊断仍不得成为主导航。
2
6
  // 迁移说明(2026-11 五页简化 UI):
3
7
  // - 导航契约:旧六页(含 work 导航按钮)→ 新五页 nav [data-view] =
4
8
  // home/memory/projects/search/activity,各出现一次;data-view 总数 6 → 5。
@@ -26,12 +30,21 @@ const root = path.resolve(__dirname, '../..');
26
30
  const html = fs.readFileSync(path.join(root, 'ui/index.html'), 'utf8');
27
31
  const script = fs.readFileSync(path.join(root, 'ui/product.js'), 'utf8');
28
32
  const css = fs.readFileSync(path.join(root, 'ui/product.css'), 'utf8');
29
- // Five-page navigation contract: exactly one nav button per primary view.
30
- for (const view of ['home', 'memory', 'projects', 'search', 'activity']) {
33
+ // Six-page navigation contract (2026-11 adds AI 团队): exactly one nav button
34
+ // per primary view, in the fixed order home/team/memory/projects/search/
35
+ // activity. The original purpose survives: diagnostics and module consoles
36
+ // still must not become another primary product.
37
+ for (const view of ['home', 'team', 'memory', 'projects', 'search', 'activity']) {
31
38
  assert.equal((html.match(new RegExp(`data-view="${view}"`, 'g')) || []).length, 1);
32
39
  assert.ok(html.includes(`id="view-${view}"`));
33
40
  }
34
- assert.equal((html.match(/data-view=/g) || []).length, 5, 'exactly five primary views; diagnostics must not become another primary product');
41
+ assert.equal((html.match(/data-view=/g) || []).length, 6, 'exactly six primary views; diagnostics must not become another primary product');
42
+ const navOrder = [...html.matchAll(/data-view="([^"]+)"/g)].map(m => m[1]);
43
+ assert.deepEqual(navOrder, ['home', 'team', 'memory', 'projects', 'search', 'activity'], 'six-page navigation order is fixed');
44
+ // The AI team page is an embedded module surface, not shell business code:
45
+ // an iframe mount plus the /workflow-ui/ proxy, and nothing else in shell UI.
46
+ assert.match(html, /<section[^>]*id="view-team"[^>]*>\s*<div class="frame-container"><iframe id="workflowFrame"/, 'team view is a module iframe mount');
47
+ assert.match(script, /workflow: \{ id: 'workflowFrame', url: '\/workflow-ui\/\?embed=1&apiBase=\/api\/workflow'/, 'the team frame targets the workflow-ui proxy');
35
48
  assert.ok(!html.includes('data-view="work"'), 'work is no longer a navigation target');
36
49
  // The workbench frame survives as a hidden service mount: #view-work stays in
37
50
  // the DOM (forever hidden) and keeps #workFrame for the Workbench service.
@@ -591,7 +591,9 @@ class IntegrationManager {
591
591
  try { listed = await client.listTools(); } catch (error) { return failed('TOOLS_CONTRACT', { toolCount: 0 }); }
592
592
  if (settled) return;
593
593
  const names = (listed && Array.isArray(listed.tools) ? listed.tools : []).map(tool => String((tool && tool.name) || '')).filter(Boolean);
594
- if (names.length !== MCP_TOOL_NAMES.length || !MCP_TOOL_NAMES.every(name => names.includes(name))) return failed('TOOLS_CONTRACT', { toolCount: names.length });
594
+ // The contract requires every knowledge tool to be present; additional tool
595
+ // families (project_workflow_*) are expected, not a violation.
596
+ if (!MCP_TOOL_NAMES.every(name => names.includes(name))) return failed('TOOLS_CONTRACT', { toolCount: names.length });
595
597
  settled = true;
596
598
  clearTimeout(timer);
597
599
  resolve({ state: 'ready', checkedAt, scope, expectedVersion, actualVersion: String(serverVersion.version || ''), serverName: serverVersion.name, tools: names, detail: '本地 MCP 服务已完成 initialize,并通过身份、版本与六工具契约校验。' });
@@ -54,12 +54,16 @@ const PICKER_TIMEOUT_MS = 10 * 60 * 1000;
54
54
  // while the shell kept proxying to its dead port (endless MODULE_UNREACHABLE).
55
55
  const SUPERVISOR_STABLE_MS = 60_000;
56
56
 
57
- // All four services resolve through the host's pinned npm dependencies.
57
+ // All four pinned services resolve through the host's npm dependencies. The
58
+ // workflow module is fifth and OPTIONAL until its public release is pinned
59
+ // (W8): resolveModuleEntry returning null means "not installed", which
60
+ // degrades to an external-service warning — never a startup failure.
58
61
  const MODULE_ENTRIES = {
59
62
  terminal: 'claude-ai-workbench/packages/server/bin/agent-terminal-server.js',
60
63
  'vector-hub': '@sanqianx/vector-hub/bin.js',
61
64
  'event-bridge': '@sanqianx/ai-coding-event-bridge-console/src/bin.js',
62
65
  'knowledge-engine': '@sanqianx/ai-coding-knowledge-engine/src/bin.js',
66
+ workflow: '@sanqianx/ai-coding-workflow/src/bin.js',
63
67
  };
64
68
 
65
69
  function resolveModuleEntry(name) {
@@ -87,6 +91,7 @@ function defaultEventBridgeUrl() {
87
91
  }
88
92
 
89
93
  function defaultEngineUrl() { return String(process.env.KB_KNOWLEDGE_ENGINE_URL || 'http://127.0.0.1:5790').replace(/\/+$/, ''); }
94
+ function defaultWorkflowUrl() { return String(process.env.KB_WORKFLOW_URL || 'http://127.0.0.1:5810').replace(/\/+$/, ''); }
90
95
 
91
96
  // Health identity markers: an HTTP 200 alone can come from any foreign
92
97
  // service that grabbed the port. Only a body that matches the product
@@ -97,6 +102,7 @@ const MODULE_IDENTITY = {
97
102
  vectorHub: body => body && typeof body === 'object' && Array.isArray(body.projects),
98
103
  eventBridge: body => body && typeof body === 'object' && typeof body.registeredProjects === 'number',
99
104
  engine: body => body && typeof body === 'object' && body.name === 'knowledge-engine',
105
+ workflow: body => body && typeof body === 'object' && body.name === 'ai-coding-workflow' && typeof body.apiVersion === 'string',
100
106
  };
101
107
 
102
108
  // kind -> bridge URL property, explicit env override, spawn spec name
@@ -105,6 +111,7 @@ const MODULE_URL_TARGETS = [
105
111
  { kind: 'vectorHub', prop: 'vectorHubUrl', env: 'KB_VECTORHUB_URL', specName: 'vector-hub' },
106
112
  { kind: 'eventBridge', prop: 'eventBridgeUrl', env: 'KB_EVENTBRIDGE_URL', specName: 'event-bridge' },
107
113
  { kind: 'engine', prop: 'engineUrl', env: 'KB_KNOWLEDGE_ENGINE_URL', specName: 'knowledge-engine' },
114
+ { kind: 'workflow', prop: 'workflowUrl', env: 'KB_WORKFLOW_URL', specName: 'workflow' },
108
115
  ];
109
116
 
110
117
  function specNameToKind(specName) {
@@ -129,6 +136,7 @@ class ModuleBridge {
129
136
  this.vectorHubUrl = options.vectorHubUrl || defaultVectorHubUrl();
130
137
  this.eventBridgeUrl = options.eventBridgeUrl || defaultEventBridgeUrl();
131
138
  this.engineUrl = options.engineUrl || defaultEngineUrl();
139
+ this.workflowUrl = options.workflowUrl || defaultWorkflowUrl();
132
140
  // Explicitly injected URLs (option or env) mean an external service;
133
141
  // only managed defaults participate in dynamic port resolution.
134
142
  this.explicitModuleUrls = {
@@ -136,8 +144,9 @@ class ModuleBridge {
136
144
  vectorHub: Boolean(options.vectorHubUrl || process.env.KB_VECTORHUB_URL),
137
145
  eventBridge: Boolean(options.eventBridgeUrl || process.env.KB_EVENTBRIDGE_URL),
138
146
  engine: Boolean(options.engineUrl || process.env.KB_KNOWLEDGE_ENGINE_URL),
147
+ workflow: Boolean(options.workflowUrl || process.env.KB_WORKFLOW_URL),
139
148
  };
140
- this.moduleUrlSources = { terminal: 'pending', vectorHub: 'pending', eventBridge: 'pending', engine: 'pending' };
149
+ this.moduleUrlSources = { terminal: 'pending', vectorHub: 'pending', eventBridge: 'pending', engine: 'pending', workflow: 'pending' };
141
150
  this.runtimeToken = options.runtimeToken || crypto.randomBytes(32).toString('hex');
142
151
  this.registryStore = options.registryStore || null;
143
152
  this.projectStore = options.projectStore || null;
@@ -165,6 +174,12 @@ class ModuleBridge {
165
174
  return `${this.eventBridgeUrl}/api/${rest}`;
166
175
  }
167
176
 
177
+ _workflowApi(pathname) {
178
+ // /api/workflow/<rest> -> <workflow module>/api/workflow/v1/<rest>
179
+ const rest = pathname.replace(/^\/api\/workflow\/?/, '');
180
+ return `${this.workflowUrl}/api/workflow/v1/${rest}`;
181
+ }
182
+
168
183
  async _fetch(url, init = {}) {
169
184
  const controller = new AbortController();
170
185
  const timer = setTimeout(() => controller.abort(), init.timeoutMs || PROXY_TIMEOUT_MS);
@@ -248,13 +263,17 @@ class ModuleBridge {
248
263
  return this.proxy(req, res, this._eventBridgeApi(pathname) + (search || ''));
249
264
  }
250
265
 
266
+ proxyWorkflow(req, res, pathname, search) {
267
+ return this.proxy(req, res, this._workflowApi(pathname) + (search || ''));
268
+ }
269
+
251
270
  proxyEngine(req, res, pathname, search) {
252
271
  if (this.engineCompatible === false) throw new DomainError('ENGINE_CONNECTION_PENDING', '知识引擎连接尚未确认,请查看系统状态;不会读取旧服务中的知识。', { status: 503 });
253
272
  return this.proxy(req, res, `${this.engineUrl}/api/${pathname.replace(/^\/api\/engine\/?/, '')}${search || ''}`);
254
273
  }
255
274
 
256
275
  proxyModuleUi(req, res, module, rest, search) {
257
- const base = { terminal: this.terminalUrl, vectorhub: this.vectorHubUrl, eventbridge: this.eventBridgeUrl, engine: this.engineUrl }[module];
276
+ const base = { terminal: this.terminalUrl, vectorhub: this.vectorHubUrl, eventbridge: this.eventBridgeUrl, engine: this.engineUrl, workflow: this.workflowUrl }[module];
258
277
  let decoded;
259
278
  try { decoded = decodeURIComponent(rest); } catch { decoded = null; }
260
279
  // Reject encoded separators/dot segments before URL normalization. Static
@@ -379,17 +398,22 @@ class ModuleBridge {
379
398
  }
380
399
 
381
400
  async modulesHealth() {
382
- const [terminal, vectorHub, eventBridge, engine] = await Promise.all([
401
+ const [terminal, vectorHub, eventBridge, engine, workflow] = await Promise.all([
383
402
  this._probe(this.terminalUrl, 'terminal'),
384
403
  this._probe(this.vectorHubUrl, 'vectorHub'),
385
404
  this._probe(this.eventBridgeUrl, 'eventBridge'),
386
405
  this._probe(this.engineUrl, 'engine'),
406
+ this._probe(this.workflowUrl, 'workflow'),
387
407
  ]);
388
408
  return { ok: true, modules: {
389
409
  terminal: { url: this.terminalUrl, up: terminal, source: this.moduleUrlSources.terminal },
390
410
  vectorHub: { url: this.vectorHubUrl, up: vectorHub, source: this.moduleUrlSources.vectorHub },
391
411
  eventBridge: { url: this.eventBridgeUrl, up: eventBridge, source: this.moduleUrlSources.eventBridge },
392
412
  engine: { url: this.engineUrl, up: engine, source: this.moduleUrlSources.engine },
413
+ // Optional fifth module: `installed` tells the UI "not installed" apart
414
+ // from "installed but down" so a missing package is never mistaken for
415
+ // a service failure of the four pinned runtimes.
416
+ workflow: { url: this.workflowUrl, up: workflow, source: this.moduleUrlSources.workflow, installed: Boolean(resolveModuleEntry('workflow')) },
393
417
  } };
394
418
  }
395
419
 
@@ -794,6 +818,20 @@ class ModuleBridge {
794
818
  }
795
819
  const engineEntry = resolveModuleEntry('knowledge-engine');
796
820
  if (process.env.KB_KNOWLEDGE_ENGINE_COMMAND || engineEntry) specs.push({ name: 'knowledge-engine', command: process.env.KB_KNOWLEDGE_ENGINE_COMMAND || `node ${JSON.stringify(engineEntry)} serve --port ${urlPort(this.engineUrl, 5790)} --host ${urlHost(this.engineUrl)}`, url: this.engineUrl, env: { KNOWLEDGE_ENGINE_DATA: path.join(this.dataDir || require('./data-dir').getDataDir(), 'knowledge-engine'), KB_ENGINE_MANAGED: '1', KNOWLEDGE_ENGINE_CONSUME: '0', KB_ENGINE_RUNTIME_TOKEN: this.runtimeToken, KB_EVENT_BRIDGE_URL: this.eventBridgeUrl, KB_VECTOR_HUB_URL: this.vectorHubUrl, NODE_PATH: path.resolve(__dirname, '..', '..', 'node_modules') } });
821
+ // Optional fifth module (workflow). Absent entry => warn and expect an
822
+ // external service, exactly like an unpinned optional runtime: the four
823
+ // pinned modules and the shell keep working.
824
+ const workflowEntry = resolveModuleEntry('workflow');
825
+ if (process.env.KB_WORKFLOW_COMMAND || workflowEntry) {
826
+ specs.push({
827
+ name: 'workflow',
828
+ command: process.env.KB_WORKFLOW_COMMAND || `node ${JSON.stringify(workflowEntry)} serve --port ${urlPort(this.workflowUrl, 5810)} --host ${urlHost(this.workflowUrl)} --data ${JSON.stringify(this.dataDir || require('./data-dir').getDataDir())}`,
829
+ url: this.workflowUrl,
830
+ env: { KB_WORKFLOW_MANAGED: '1', KB_WORKFLOW_RUNTIME_TOKEN: this.runtimeToken },
831
+ });
832
+ } else {
833
+ this.logger.warn('modules.supervisor', '@sanqianx/ai-coding-workflow runtime not installed; team features report "not installed".', {});
834
+ }
797
835
  return specs;
798
836
  }
799
837
 
@@ -919,6 +919,18 @@ function createRequestHandler(runtime, options = {}) {
919
919
  if (pathname.startsWith('/api/eventbridge/internal/')) throw new DomainError('FORBIDDEN', 'Internal module endpoints are not exposed to browsers.', { status: 403 });
920
920
  return runtime.moduleBridge.proxyEventBridge(req, res, pathname, url.search);
921
921
  }
922
+ // Fifth module (optional): team/workflow business API. The module's
923
+ // own base is /api/workflow/v1; the shell rewrites /api/workflow/<rest>
924
+ // to it. Internal (trusted-service) subroutes stay server-side only.
925
+ if (pathname.startsWith('/api/workflow/') || pathname === '/api/workflow') {
926
+ if (pathname.startsWith('/api/workflow/internal/')) throw new DomainError('FORBIDDEN', 'Internal module endpoints are not exposed to browsers.', { status: 403 });
927
+ return runtime.moduleBridge.proxyWorkflow(req, res, pathname, url.search);
928
+ }
929
+ // AI team page proxy: /workflow-ui/<asset> -> workflow module /<asset>.
930
+ // GET-only, encoded-segment and api/internal segments rejected inside
931
+ // proxyModuleUi; the module serves its own index.html at the root.
932
+ const workflowUi = pathname.match(/^\/workflow-ui\/?(.*)$/);
933
+ if (workflowUi && method === 'GET') return runtime.moduleBridge.proxyModuleUi(req, res, 'workflow', workflowUi[1], url.search);
922
934
  if (method === 'GET' && pathname === '/api/modules/health') {
923
935
  return send(res, 200, { ...await runtime.moduleBridge.modulesHealth(), ownership: runtime.ownership });
924
936
  }
@@ -0,0 +1,209 @@
1
+ 'use strict';
2
+
3
+ // MCP tool runtime for the six project_workflow_* tools. These tools are a
4
+ // thin adapter over the shell's /api/workflow/* proxy into the independent
5
+ // workflow module — no task state is stored here (runbook §2.3: the tools
6
+ // call the workflow master store, never a second copy).
7
+
8
+ const path = require('path');
9
+ const endpoint = require('./runtime-endpoint');
10
+ const { getDataDir } = require('./data-dir');
11
+
12
+ const DEFAULT_TIMEOUT_MS = 15000;
13
+
14
+ class WorkflowToolRuntime {
15
+ constructor(options = {}) {
16
+ this.layout = options.layout || null;
17
+ this.workflowUrl = options.workflowUrl || process.env.KB_WORKFLOW_URL || null;
18
+ this.fetchImpl = options.fetchImpl || fetch;
19
+ this.timeoutMs = options.timeoutMs || DEFAULT_TIMEOUT_MS;
20
+ }
21
+
22
+ /** Prefer an explicit module URL; else the live shell's proxy base. */
23
+ resolveBase() {
24
+ if (this.workflowUrl) return { base: this.workflowUrl.replace(/\/+$/, ''), prefix: '/api/workflow/v1' };
25
+ try {
26
+ const dataDir = this.layout ? this.layout.getDataDir() : getDataDir();
27
+ const live = endpoint.readLiveEndpoint(dataDir, { removeStale: false });
28
+ if (live && live.host && live.port) return { base: `http://${live.host}:${live.port}`, prefix: '/api/workflow' };
29
+ } catch { /* no live shell — surfaced as a structured error below */ }
30
+ return null;
31
+ }
32
+
33
+ async request(apiPath, { method = 'GET', body } = {}) {
34
+ const resolved = this.resolveBase();
35
+ if (!resolved) {
36
+ const error = new Error('WORKFLOW_UNAVAILABLE');
37
+ error.code = 'WORKFLOW_UNAVAILABLE';
38
+ error.message = '工作流服务不可达:未设置 KB_WORKFLOW_URL,且没有运行中的知识库实例。任务与知识检索不受影响。';
39
+ throw error;
40
+ }
41
+ const url = `${resolved.base}${resolved.prefix}/${apiPath.replace(/^\/+/, '')}`;
42
+ const controller = new AbortController();
43
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
44
+ try {
45
+ const response = await this.fetchImpl(url, {
46
+ method,
47
+ headers: body ? { 'Content-Type': 'application/json' } : {},
48
+ body: body ? JSON.stringify(body) : undefined,
49
+ signal: controller.signal,
50
+ });
51
+ const json = await response.json().catch(() => ({}));
52
+ if (!response.ok) {
53
+ const error = new Error(json.message || `HTTP ${response.status}`);
54
+ error.code = json.error || 'WORKFLOW_HTTP_ERROR';
55
+ error.status = response.status;
56
+ error.details = json.details || {};
57
+ throw error;
58
+ }
59
+ return json;
60
+ } catch (inner) {
61
+ if (inner.code) throw inner;
62
+ const error = new Error('工作流服务不可达;原生开发可以继续,页面会显示降级状态。');
63
+ error.code = 'WORKFLOW_UNAVAILABLE';
64
+ throw error;
65
+ } finally { clearTimeout(timer); }
66
+ }
67
+
68
+ /**
69
+ * start: create the business task, bind the calling session (declared
70
+ * basis — the Bridge consumer's captured sessionId drives observation, not
71
+ * acceptance), and return the short task contract.
72
+ */
73
+ async start(args) {
74
+ const title = String(args.title || '').trim();
75
+ if (!title) { const e = new Error('title is required'); e.code = 'VALIDATION'; throw e; }
76
+ const payload = {
77
+ requestId: `mcp-start-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
78
+ projectId: args.projectId || 'unknown-project',
79
+ title,
80
+ goal: args.goal || null,
81
+ acceptance: Array.isArray(args.acceptance) ? args.acceptance : undefined,
82
+ ownerMemberId: args.memberId || null,
83
+ };
84
+ const created = await this.request('workflow-tasks', { method: 'POST', body: payload });
85
+ const taskId = created.task.taskId;
86
+ let binding = null;
87
+ if (args.client && args.sessionId) {
88
+ const bindBody = {
89
+ requestId: `mcp-bind-${payload.requestId}`,
90
+ client: String(args.client),
91
+ nativeSessionId: String(args.sessionId),
92
+ workspaceIdentity: args.workspaceIdentity || args.repoPath || process.cwd(),
93
+ memberId: args.memberId || null,
94
+ verificationBasis: 'declared',
95
+ };
96
+ try { binding = await this.request(`workflow-tasks/${encodeURIComponent(taskId)}/session-bindings`, { method: 'POST', body: bindBody }); }
97
+ catch { binding = null; /* observation still works once the hook-captured session id matches */ }
98
+ }
99
+ return {
100
+ ok: true,
101
+ taskId,
102
+ task: created.task,
103
+ sessionBinding: binding ? { bindingId: binding.binding.bindingId, basis: 'declared' } : null,
104
+ nextStep: '实现需求;完成后用 project_workflow_checkpoint 记录事实,再 request_review(交付检查在后续版本接入)。',
105
+ note: '会话绑定当前为声明级:事件观察按采集会话归因,验收始终由服务端裁决。',
106
+ };
107
+ }
108
+
109
+ async resume(args) {
110
+ if (!args.taskId) { const e = new Error('taskId is required'); e.code = 'VALIDATION'; throw e; }
111
+ const result = await this.request(`workflow-tasks/${encodeURIComponent(args.taskId)}`);
112
+ const task = result.task;
113
+ const checkpoints = task.checkpoints || [];
114
+ const latest = checkpoints[checkpoints.length - 1] || null;
115
+ return {
116
+ ok: true,
117
+ taskId: task.taskId,
118
+ title: task.title,
119
+ goal: task.goal,
120
+ status: task.status,
121
+ phase: task.phase,
122
+ acceptance: task.acceptance,
123
+ acceptanceRevision: task.acceptanceRevision,
124
+ confirmedDecisions: latest ? latest.decided : [],
125
+ verifiedResults: latest ? latest.verifiedResults : [],
126
+ remaining: latest ? latest.remaining : task.acceptance.filter(a => a.status === 'pending').map(a => a.title),
127
+ nextAction: task.nextAction,
128
+ revision: task.revision,
129
+ };
130
+ }
131
+
132
+ async status(args) {
133
+ if (args.taskId) return { ok: true, task: (await this.request(`workflow-tasks/${encodeURIComponent(args.taskId)}`)).task };
134
+ const query = new URLSearchParams();
135
+ if (args.projectId) query.set('projectId', args.projectId);
136
+ if (args.status) query.set('status', args.status);
137
+ const list = await this.request(`workflow-tasks?${query.toString()}`);
138
+ return { ok: true, total: list.total, tasks: list.tasks.map(t => ({ taskId: t.taskId, title: t.title, projectId: t.projectId, status: t.status, phase: t.phase, nextAction: t.nextAction, updatedAt: t.updatedAt })) };
139
+ }
140
+
141
+ async checkpoint(args) {
142
+ if (!args.taskId) { const e = new Error('taskId is required'); e.code = 'VALIDATION'; throw e; }
143
+ const payload = {
144
+ requestId: `mcp-ckpt-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
145
+ kind: args.kind === 'fact' ? 'fact' : 'candidate',
146
+ summary: args.summary || null,
147
+ decided: args.decided,
148
+ verifiedResults: args.verifiedResults,
149
+ remaining: args.remaining,
150
+ nextAction: args.nextAction || null,
151
+ eventRefs: args.eventRefs,
152
+ };
153
+ const result = await this.request(`workflow-tasks/${encodeURIComponent(args.taskId)}/checkpoints`, { method: 'POST', body: payload });
154
+ return { ok: true, checkpoint: result.checkpoint };
155
+ }
156
+
157
+ async requestReview(args) {
158
+ if (!args.taskId) { const e = new Error('taskId is required'); e.code = 'VALIDATION'; throw e; }
159
+ // W5: submit the current snapshot to the deterministic check pipeline.
160
+ // Receipt verdicts drive automated acceptance server-side; the model
161
+ // review stage is reported honestly as pending.
162
+ const result = await this.request(`workflow-tasks/${encodeURIComponent(args.taskId)}/reviews`, { method: 'POST', body: {
163
+ requestId: `mcp-review-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
164
+ repoPath: args.repoPath || undefined,
165
+ tools: Array.isArray(args.tools) ? args.tools : undefined,
166
+ } });
167
+ return {
168
+ ok: true,
169
+ snapshot: result.snapshot,
170
+ receipts: result.receipts,
171
+ decision: result.decision,
172
+ modelReview: result.modelReview,
173
+ note: '程序检查收据已记录;自动验收由服务端依据收据裁决。模型审查阶段当前为 pending(编排交付前不虚构意见)。',
174
+ };
175
+ }
176
+
177
+ async reviewResult(args) {
178
+ if (!args.taskId) { const e = new Error('taskId is required'); e.code = 'VALIDATION'; throw e; }
179
+ const task = (await this.request(`workflow-tasks/${encodeURIComponent(args.taskId)}`)).task;
180
+ const checks = (task.runs || []).filter(r => r.kind === 'check');
181
+ // Full findings of the LATEST check run: the rework member works from
182
+ // concrete file:line[rule] items, not from summaries.
183
+ let latestFindings = null;
184
+ const latest = checks[checks.length - 1];
185
+ if (latest && latest.executionRef) {
186
+ try {
187
+ const receipt = await this.request(`check-receipts/${encodeURIComponent(latest.executionRef)}`);
188
+ latestFindings = (receipt.receipt.findings || []).slice(0, 100).map(f => ({ ruleId: f.ruleId, file: f.file, line: f.line, severity: f.severity, message: f.message }));
189
+ } catch { latestFindings = null; /* receipt purged or unavailable — reworkItems on the task still carry the queue */ }
190
+ }
191
+ return {
192
+ ok: true,
193
+ taskId: args.taskId,
194
+ status: task.status,
195
+ phase: task.phase,
196
+ nextAction: task.nextAction,
197
+ reworkItems: task.reworkItems || [],
198
+ latestCheckFindings: latestFindings,
199
+ checks: checks.map(r => ({ runId: r.runId, summary: r.summary, status: r.status, finishedAt: r.finishedAt })),
200
+ acceptance: task.acceptance,
201
+ modelReview: 'pending-model-review',
202
+ note: task.reworkItems && task.reworkItems.length
203
+ ? `整改 ${task.reworkItems.length} 项:按 file:line[rule] 修复后重新 project_workflow_request_review。`
204
+ : '当前快照没有待整改项。',
205
+ };
206
+ }
207
+ }
208
+
209
+ module.exports = { WorkflowToolRuntime };
@@ -13,6 +13,7 @@ const definitions = {
13
13
  vectorHub: { option: '--vector-source', name: '@sanqianx/vector-hub', installName: '@sanqianx/vector-hub', required: ['dist/cjs/bin.js', 'dist/cjs/server/manager.js', 'ui/index.html'] },
14
14
  eventBridge: { option: '--bridge-source', name: '@sanqianx/ai-coding-event-bridge-console', installName: '@sanqianx/ai-coding-event-bridge-console', required: ['src/server.js', 'src/bridge/core/consumer-registry.js', 'console/index.html'] },
15
15
  engine: { option: '--engine-source', name: '@sanqianx/ai-coding-knowledge-engine', installName: '@sanqianx/ai-coding-knowledge-engine', required: ['src/bin.js', 'src/server.js', 'src/coordinator.js', 'src/analysis-worker.js', 'ui/index.html', 'ui/app.js', 'ui/app.css'] },
16
+ workflow: { option: '--workflow-source', name: '@sanqianx/ai-coding-workflow', installName: '@sanqianx/ai-coding-workflow', required: ['src/bin.js', 'src/server.js', 'src/store.js', 'src/tasks.js', 'ui/index.html', 'ui/app.js'] },
16
17
  };
17
18
  function run(command, args, cwd) {
18
19
  const result = spawnSync(command, args, { cwd, windowsHide: true, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
@@ -29,7 +29,8 @@ function verify() {
29
29
  if (indexed.status !== 0 || indexed.stdout.toString().replace(/\r\n/g, '\n') !== fs.readFileSync(path.join(root, file), 'utf8').replace(/\r\n/g, '\n')) throw new Error(`Release blocked: Git bytes differ from runtime contract: ${file}`);
30
30
  }
31
31
  }
32
- process.stdout.write(workingTree ? 'Four npm module runtimes verified; working tree is not release approval.\n' : 'Pinned npm runtime release gate passed.\n');
32
+ const count = Object.keys(require('./pack-module-candidates').definitions).length;
33
+ process.stdout.write(workingTree ? `${count} npm module runtimes verified; working tree is not release approval.\n` : 'Pinned npm runtime release gate passed.\n');
33
34
  }
34
35
  if (require.main === module) { try { verify(); } catch (error) { process.stderr.write(`${error.message}\n`); process.exitCode = 1; } }
35
36
  module.exports = { isPinnedModuleVersion };