@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.
Files changed (29) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +5 -0
  3. package/_site/_test/chat-claudecodeui-match-test.js +1 -1
  4. package/_site/_test/integration-runtime-binding-test.js +1 -1
  5. package/_site/_test/mcp-server-test.js +149 -149
  6. package/_site/_test/module-supervisor-backoff-reset-test.js +64 -0
  7. package/_site/_test/packaged-ui-smoke-test.js +1 -1
  8. package/_site/_test/parallel-memory-home-review-test.js +148 -0
  9. package/_site/_test/parallel-nav-home-issues-test.js +159 -0
  10. package/_site/_test/parallel-nav-theme-test.js +5 -4
  11. package/_site/_test/parallel-nav-viewport-test.js +4 -2
  12. package/_site/_test/product-empty-state-test.js +2 -2
  13. package/_site/_test/product-navigation-test.js +2 -2
  14. package/_site/_test/workflow-module-wiring-test.js +102 -0
  15. package/_site/_test/workflow-tools-test.js +97 -0
  16. package/_site/_test/workspace-ui-contract-test.js +16 -3
  17. package/_site/lib/integration-installer.js +3 -1
  18. package/_site/lib/module-bridge.js +59 -11
  19. package/_site/lib/server-app.js +12 -0
  20. package/_site/lib/workflow-tool-runtime.js +209 -0
  21. package/bin/project-knowledge-mcp.js +282 -201
  22. package/module-runtime-manifest.json +5 -5
  23. package/package.json +1 -1
  24. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  25. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  26. package/plugins/project-knowledge/.mcp.json +1 -1
  27. package/plugins/project-knowledge/skills/pk-team/SKILL.md +35 -0
  28. package/ui/index.html +6 -0
  29. package/ui/product.js +113 -12
@@ -0,0 +1,159 @@
1
+ 'use strict';
2
+ // NAV-007 — 首页待处理直达处理。
3
+ //
4
+ // 迁移说明(五页简化 UI):
5
+ // - 首页不再罗列项目:导入成功的可见面改为顶栏 #projectSelect 的选项
6
+ // (与旧首页列表读同一份 state.projects)。
7
+ // - 需要处理面板改为服务端 /api/engine/overview 的 needsPreview 投影;
8
+ // 行级「去处理」入口(data-open-run)移植到 needRow() 的 run 行上,
9
+ // 断言选择器不变。
10
+ // - 活动记录视图新增过滤栏;默认「全部」即包含失败运行,展开行的
11
+ // .error 与 [data-retry-run] 结构不变。
12
+ //
13
+ // The home「需要处理」panel names a failed maintenance run, so it must be an
14
+ // entry into handling, not a read-only preview: one real pointer click on the
15
+ // issue row must land on THAT exact run in the activity view, already
16
+ // expanded, with its failure details loaded and the retry control within
17
+ // reach. The old shell showed the failure on the home page and offered only a
18
+ // generic "查看运行详情" jump, leaving the user to find the record again in
19
+ // the activity list — view-only where handling was expected.
20
+ //
21
+ // The regression drives the real product UI in a real browser against an
22
+ // isolated instance (own port, own data dir, own knowledge dir, own Bridge
23
+ // journal, own browser profile). The failed run is real engine state, written
24
+ // into the real vendored engine's store through its own API; the shell reads
25
+ // it through the same snapshot the user's browser would. Every pointer action
26
+ // is a CDP Input.dispatchMouseEvent on the real coordinates of the real
27
+ // control, and 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-nav-shell');
37
+
38
+ const EVIDENCE = process.env.PK_TEST_EVIDENCE_DIR ? path.resolve(process.env.PK_TEST_EVIDENCE_DIR) : null;
39
+
40
+ const FAILURE_MESSAGE = '注入的额度故障:后台维护模型额度不足';
41
+
42
+ /** Record every click the page really receives on the home issue entry. */
43
+ async function installHomeClickRecorder(harness) {
44
+ await harness.run(`(() => {
45
+ window.__homeIssueClicks = [];
46
+ if (!window.__homeIssueHooked) {
47
+ window.__homeIssueHooked = true;
48
+ document.addEventListener('click', event => {
49
+ const button = event.target.closest ? event.target.closest('[data-open-run]') : null;
50
+ if (button) window.__homeIssueClicks.push({
51
+ trusted: event.isTrusted === true,
52
+ runId: button.getAttribute('data-open-run'),
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: 'nav007', 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, 'nav007-a');
67
+ const project = await harness.importProject(repo, 'NAV007 甲');
68
+ await harness.requestRegistryRefresh();
69
+ await harness.waitFor(
70
+ () => harness.run("document.getElementById('projectSelect').textContent.includes('NAV007 甲')"),
71
+ 'the imported project is listed',
72
+ 20000,
73
+ );
74
+
75
+ // Real engine state: one failed maintenance run for that project, with a
76
+ // quota-style error the way a real failed phase leaves it.
77
+ const created = harness.engine.store.addRun({ projectId: project.projectId, commitSha: repo.headCommit, trigger: 'manual' });
78
+ harness.engine.store.updateRun(created.runId, {
79
+ state: 'failed',
80
+ phase: 'analyze',
81
+ error: { code: 'MODEL_QUOTA_EXHAUSTED', message: FAILURE_MESSAGE },
82
+ finishedAt: new Date().toISOString(),
83
+ });
84
+
85
+ await installHomeClickRecorder(harness);
86
+
87
+ // NAV-007 expected 1: the home panel not only names the failure, it
88
+ // exposes a per-item handling entry bound to that exact run.
89
+ await harness.requestRegistryRefresh();
90
+ await harness.waitFor(
91
+ () => harness.run(`(() => {
92
+ const button = document.querySelector('#homeContent [data-open-run]');
93
+ if (!button) return false;
94
+ const panel = button.closest('section.panel');
95
+ const row = button.closest('.row');
96
+ return panel && panel.querySelector('h2').textContent.includes('需要处理')
97
+ && row && row.textContent.includes(${JSON.stringify(FAILURE_MESSAGE)})
98
+ && button.getAttribute('data-run-project') === ${JSON.stringify(project.projectId)};
99
+ })()`),
100
+ 'the home 需要处理 panel offers a handling entry for the exact failed run',
101
+ 20000,
102
+ );
103
+ await harness.browser.screenshot(path.join(harness.evidence, 'nav007-home-issue-entry.png'));
104
+
105
+ // NAV-007 expected 2: one trusted pointer click lands on THAT run in the
106
+ // activity view — expanded, details loaded, retry reachable.
107
+ await harness.nativeClick('#homeContent [data-open-run]');
108
+ const clicks = await harness.run('window.__homeIssueClicks || []');
109
+ assert.ok(clicks.length >= 1, 'the page really received the home issue click');
110
+ const click = clicks[clicks.length - 1];
111
+ assert.equal(click.trusted, true, `the click the page received is a trusted browser event: ${JSON.stringify(click)}`);
112
+ assert.equal(click.runId, created.runId, `the click is bound to the failed run: ${JSON.stringify(click)}`);
113
+
114
+ await harness.waitFor(
115
+ () => harness.run(`document.getElementById('view-activity').classList.contains('active')`),
116
+ 'the activity view is open',
117
+ );
118
+ const openRun = `(() => {
119
+ const row = document.querySelector(${JSON.stringify(`details.run[data-run-id="${created.runId}"][open]`)});
120
+ if (!row) return null;
121
+ return {
122
+ open: true,
123
+ error: (row.querySelector('.error') || {}).textContent || '',
124
+ retryRunId: row.querySelector('[data-retry-run]') ? row.querySelector('[data-retry-run]').getAttribute('data-retry-run') : '',
125
+ };
126
+ })()`;
127
+ const landed = await harness.waitFor(
128
+ () => harness.run(openRun),
129
+ 'the exact failed run is expanded with its retry control',
130
+ 20000,
131
+ );
132
+ assert.ok(landed.error.includes(FAILURE_MESSAGE), `the expanded run shows the real failure detail: ${JSON.stringify(landed)}`);
133
+ assert.equal(landed.retryRunId, created.runId, `the retry control belongs to the exact failed run: ${JSON.stringify(landed)}`);
134
+ await harness.browser.screenshot(path.join(harness.evidence, 'nav007-activity-run-opened.png'));
135
+
136
+ // NAV-007 expected 2 (continued): the flow repeats from a warmed shell —
137
+ // the already-loaded list must not swallow the second expansion.
138
+ await harness.nativeClick('nav [data-view="home"]');
139
+ await harness.waitFor(
140
+ () => harness.run("document.getElementById('view-home').classList.contains('active') && !!document.querySelector('#homeContent [data-open-run]')"),
141
+ 'the home view is back with the handling entry',
142
+ 20000,
143
+ );
144
+ await harness.nativeClick('#homeContent [data-open-run]');
145
+ await harness.waitFor(
146
+ () => harness.run(`!!document.querySelector(${JSON.stringify(`details.run[data-run-id="${created.runId}"][open]`)})`),
147
+ 'the second click opens the same run again',
148
+ 20000,
149
+ );
150
+
151
+ assert.equal(harness.browser.exceptions.length, 0, `no uncaught product JavaScript exceptions: ${JSON.stringify(harness.browser.exceptions)}`);
152
+
153
+ console.log('parallel-nav-home-issues-test PASS (the home 需要处理 entry opens the exact failed run, expanded, with retry reachable)');
154
+ } finally {
155
+ await harness.cleanup();
156
+ }
157
+ }
158
+
159
+ main().catch(error => { console.error(error.stack || error.message); process.exitCode = 1; });
@@ -62,12 +62,13 @@ async function main() {
62
62
  20000,
63
63
  );
64
64
 
65
- // NAV-002 navigation contract (five-page UI): exactly the five pages, no
66
- // work button, and the workbench survives as a hidden service mount.
65
+ // NAV-002 navigation contract (six-page UI, AI 团队 added 2026-11):
66
+ // exactly the six fixed pages, no work button, and the workbench survives
67
+ // as a hidden service mount.
67
68
  assert.deepEqual(
68
69
  await harness.run("[...document.querySelectorAll('nav [data-view]')].map(button => button.dataset.view)"),
69
- ['home', 'memory', 'projects', 'search', 'activity'],
70
- 'the navigation offers exactly the five pages',
70
+ ['home', 'team', 'memory', 'projects', 'search', 'activity'],
71
+ 'the navigation offers exactly the six fixed pages',
71
72
  );
72
73
  assert.equal(await harness.run("document.querySelector('[data-view=\"work\"]') === null"), true, 'the work navigation button is removed');
73
74
  assert.equal(await harness.run("document.getElementById('view-work') !== null"), true, 'the work section survives in the DOM');
@@ -51,10 +51,12 @@ const VIEWPORTS = [
51
51
 
52
52
  const THEMES = ['light', 'dark'];
53
53
 
54
- // The five-page navigation contract: home, memory, projects, search,
55
- // activity. The workbench section stays hidden and is not a page.
54
+ // The six-page navigation contract (2026-11 adds AI 团队): home, team,
55
+ // memory, projects, search, activity. The workbench section stays hidden and
56
+ // is not a page; the team page is the workflow module's embedded surface.
56
57
  const PAGES = [
57
58
  { key: 'home', view: 'home' },
59
+ { key: 'team', view: 'team' },
58
60
  { key: 'memory', view: 'memory' },
59
61
  { key: 'projects', view: 'projects' },
60
62
  { key: 'search', view: 'search' },
@@ -137,8 +137,8 @@ async function main() {
137
137
  // hidden service mount.
138
138
  assert.deepEqual(
139
139
  await run("[...document.querySelectorAll('nav [data-view]')].map(button => button.dataset.view)"),
140
- ['home', 'memory', 'projects', 'search', 'activity'],
141
- 'the navigation offers exactly the five pages',
140
+ ['home', 'team', 'memory', 'projects', 'search', 'activity'],
141
+ 'the navigation offers exactly the six fixed pages (AI 团队 added 2026-11)',
142
142
  );
143
143
  assert.equal(await run("document.querySelector('[data-view=\"work\"]') === null"), true, 'the work navigation button is removed');
144
144
  assert.equal(await run("document.getElementById('view-work') !== null"), true, 'the work section survives in the DOM');
@@ -114,9 +114,9 @@ async function main() {
114
114
  const run = expression => browser.evaluate(expression);
115
115
 
116
116
  await waitFor(() => run("document.getElementById('homeContent').textContent.includes('第一个项目')"), 'the real empty home', 20000);
117
- assert.equal(await run("document.querySelectorAll('nav [data-view]').length"), 5, 'the shell exposes five navigation entries');
117
+ assert.equal(await run("document.querySelectorAll('nav [data-view]').length"), 6, 'the shell exposes six navigation entries (AI 团队 added 2026-11)');
118
118
  assert.equal(await run("document.querySelector('[data-view=\"work\"]')"), null, 'the retired work page no longer has a navigation entry');
119
- assert.equal(await run("document.querySelectorAll('.view').length"), 6, 'five pages plus the hidden work service mount');
119
+ assert.equal(await run("document.querySelectorAll('.view').length"), 7, 'six pages plus the hidden work service mount');
120
120
 
121
121
  const readShell = () => run(`(() => ({
122
122
  marker: window.__navMarker === undefined ? null : String(window.__navMarker),
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+ // 第五模块(独立工作流)接线合同(W1):
3
+ // - /api/workflow/<rest> 改写到模块 /api/workflow/v1/<rest>;
4
+ // - 模块身份探测(MODULE_IDENTITY.workflow)按 name+apiVersion 判定,
5
+ // 外来服务占用端口时判 foreign,不误认、不抢端口;
6
+ // - 模块未安装(resolveModuleEntry null)时:不产生受管 spec、四模块
7
+ // spec 不受影响,modulesHealth 如实报 installed:false;
8
+ // - /workflow-ui/ 页面代理仅 GET、拒绝编码分隔符与 api/internal 段;
9
+ // - 模块不可达时代理返回结构化 502,不影响其他模块路由。
10
+ // 真实 tarball 安装级验证(五模块同装)在 W8 前以隔离 prefix 单独执行,
11
+ // 不在本文件伪造。
12
+ const assert = require('node:assert/strict');
13
+ const http = require('node:http');
14
+ const { Readable } = require('node:stream');
15
+ const { EventEmitter } = require('node:events');
16
+ const { ModuleBridge } = require('../lib/module-bridge');
17
+
18
+ function workflowInstalled() {
19
+ try { require.resolve('@sanqianx/ai-coding-workflow/src/bin.js'); return true; } catch { return false; }
20
+ }
21
+
22
+ (async () => {
23
+ // 1) URL rewrite contract.
24
+ const bridge = new ModuleBridge({ workflowUrl: 'http://127.0.0.1:5810' });
25
+ assert.equal(bridge._workflowApi('/api/workflow/team'), 'http://127.0.0.1:5810/api/workflow/v1/team');
26
+ assert.equal(bridge._workflowApi('/api/workflow'), 'http://127.0.0.1:5810/api/workflow/v1/');
27
+
28
+ // 2) Identity classification against a REAL workflow-shaped health body and
29
+ // a foreign listener.
30
+ const workflowBody = JSON.stringify({ ok: true, name: 'ai-coding-workflow', version: '0.1.0', apiVersion: 'v1', capabilities: {} });
31
+ const foreignBody = JSON.stringify({ ok: true, name: 'something-else', apiVersion: 'v1' });
32
+ const upstream = http.createServer((req, res) => {
33
+ res.writeHead(200, { 'Content-Type': 'application/json' });
34
+ res.end(req.url === '/api/health?foreign=1' ? foreignBody : workflowBody);
35
+ });
36
+ await new Promise(resolve => upstream.listen(0, '127.0.0.1', resolve));
37
+ const port = upstream.address().port;
38
+ try {
39
+ assert.equal(await bridge._probeClass(`http://127.0.0.1:${port}`, 'workflow'), 'module', 'a real workflow health body classifies as our module');
40
+ // A dedicated foreign listener: same shape, wrong identity.
41
+ const foreignServer = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(foreignBody); });
42
+ await new Promise(resolve => foreignServer.listen(0, '127.0.0.1', resolve));
43
+ try {
44
+ assert.equal(await bridge._probeClass(`http://127.0.0.1:${foreignServer.address().port}`, 'workflow'), 'foreign', 'an identity mismatch is foreign, never reused');
45
+ } finally { foreignServer.closeAllConnections(); await new Promise(resolve => foreignServer.close(resolve)); }
46
+ } finally { upstream.closeAllConnections(); await new Promise(resolve => upstream.close(resolve)); }
47
+
48
+ // 3) Optional-module degradation: without the package installed the
49
+ // supervisor builds no workflow spec and health reports not installed.
50
+ const specs = bridge._supervisedSpecs();
51
+ if (!workflowInstalled()) {
52
+ assert.ok(!specs.some(spec => spec.name === 'workflow'), 'no workflow spec when the runtime is not installed');
53
+ } else {
54
+ assert.ok(specs.some(spec => spec.name === 'workflow'), 'an installed workflow runtime gets a supervised spec');
55
+ assert.match(specs.find(spec => spec.name === 'workflow').command, /ai-coding-workflow.*serve/, 'the spec launches the workflow CLI');
56
+ }
57
+ for (const pinned of ['terminal', 'vector-hub', 'event-bridge', 'knowledge-engine']) {
58
+ assert.ok(specs.some(spec => spec.name === pinned), `pinned module ${pinned} keeps its spec`);
59
+ }
60
+ const health = await bridge.modulesHealth();
61
+ assert.ok(health.modules.workflow, 'health lists the workflow module');
62
+ assert.equal(health.modules.workflow.installed, workflowInstalled(), 'installed reflects package presence');
63
+
64
+ // 4) Workflow UI proxy: GET-only, rejects encoded separators and api/internal
65
+ // segments, accepts the bare entry.
66
+ const uiUpstream = http.createServer((req, res) => {
67
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
68
+ res.end('<html>AI 团队</html>');
69
+ });
70
+ await new Promise(resolve => uiUpstream.listen(0, '127.0.0.1', resolve));
71
+ const uiBridge = new ModuleBridge({ workflowUrl: `http://127.0.0.1:${uiUpstream.address().port}` });
72
+ const shellUi = http.createServer((req, res) => {
73
+ const match = req.url.match(/^\/workflow-ui\/?(.*)$/);
74
+ if (!match || req.method !== 'GET') { res.statusCode = 404; res.end('Not found'); return; }
75
+ return uiBridge.proxyModuleUi(req, res, 'workflow', match[1], '');
76
+ });
77
+ await new Promise(resolve => shellUi.listen(0, '127.0.0.1', resolve));
78
+ try {
79
+ const page = await fetch(`http://127.0.0.1:${shellUi.address().port}/workflow-ui/`);
80
+ assert.equal(page.status, 200);
81
+ assert.match(await page.text(), /AI 团队/);
82
+ for (const bad of ['/workflow-ui/app.js/../../package.json', '/workflow-ui/%2e%2e/secret', '/workflow-ui/api/health', '/workflow-ui/internal/x']) {
83
+ const response = await fetch(`http://127.0.0.1:${shellUi.address().port}${bad}`);
84
+ assert.notEqual(response.status, 200, `${bad} must not proxy`);
85
+ }
86
+ const post = await fetch(`http://127.0.0.1:${shellUi.address().port}/workflow-ui/`, { method: 'POST' });
87
+ assert.equal(post.status, 404, 'the UI proxy is GET-only');
88
+ } finally {
89
+ shellUi.closeAllConnections(); await new Promise(resolve => shellUi.close(resolve));
90
+ uiUpstream.closeAllConnections(); await new Promise(resolve => uiUpstream.close(resolve));
91
+ }
92
+
93
+ // 5) Unreachable module yields a structured 502 without breaking the bridge.
94
+ const deadBridge = new ModuleBridge({ workflowUrl: 'http://127.0.0.1:1' });
95
+ const req = Readable.from([]); req.method = 'GET'; req.headers = {};
96
+ const res = new EventEmitter(); res.writeHead = () => {}; res.end = bytes => { res.writableEnded = true; res.body = JSON.parse(bytes); };
97
+ await deadBridge.proxy(req, res, deadBridge._workflowApi('/api/workflow/team'));
98
+ assert.equal(res.body.error, 'MODULE_UNREACHABLE');
99
+ assert.equal(res.body.details.failureKind, 'NETWORK_ERROR');
100
+
101
+ console.log('workflow-module-wiring-test PASS');
102
+ })().catch(error => { console.error(error); process.exitCode = 1; });
@@ -0,0 +1,97 @@
1
+ 'use strict';
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
+ // module instance as upstream and verifies start/resume/status/checkpoint and
5
+ // the truthful UNSUPPORTED answers for the review pipeline, plus the
6
+ // structured degradation when no service is reachable.
7
+ const assert = require('node:assert/strict');
8
+ const fs = require('node:fs');
9
+ const os = require('node:os');
10
+ const path = require('node:path');
11
+ const { WorkflowToolRuntime } = require('../lib/workflow-tool-runtime');
12
+
13
+ // Development-machine suite: the upstream is the real workflow module from
14
+ // its private source checkout. CI without that checkout gets an explicit,
15
+ // logged skip (never a silent pass); once the package publishes (W8) this
16
+ // switches to installing the tarball and the suite becomes mandatory.
17
+ let createWorkflowServer = null;
18
+ try {
19
+ createWorkflowServer = require('D:/SanQian.Xu/ai-coding-workflow/src/server').createWorkflowServer;
20
+ } catch { /* not present on this machine */ }
21
+ if (!createWorkflowServer) {
22
+ console.log('workflow-tools-test SKIP: workflow module source not present (dev-machine suite; becomes mandatory after the package publishes in W8)');
23
+ process.exit(0);
24
+ }
25
+
26
+ function tempDataDir() { return fs.mkdtempSync(path.join(os.tmpdir(), 'ai-workflow-mcp-')); }
27
+
28
+ async function withUpstream(fn) {
29
+ const runtime = createWorkflowServer({ dataDir: tempDataDir() });
30
+ const bound = await runtime.listen(0);
31
+ const base = `http://127.0.0.1:${bound.port}`;
32
+ // Seed the default team so task creation is allowed.
33
+ await fetch(`${base}/api/workflow/v1/team`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ requestId: 'mcp-seed' }) });
34
+ try { await fn(base); } finally { await runtime.close(); }
35
+ }
36
+
37
+ (async () => {
38
+ await withUpstream(async base => {
39
+ const tools = new WorkflowToolRuntime({ workflowUrl: base });
40
+
41
+ // start creates a task, binds the declared session, returns the contract.
42
+ const started = await tools.start({ title: '修复重复重试', goal: '超时后不得重复提交', acceptance: [{ title: '重试幂等', kind: 'automated' }], client: 'claude', sessionId: 'sess-mcp-1', projectId: 'p1' });
43
+ assert.ok(started.taskId.startsWith('task_'));
44
+ assert.equal(started.sessionBinding.basis, 'declared');
45
+ assert.ok(started.nextStep.includes('checkpoint'));
46
+
47
+ // resume answers the short contract with acceptance and remaining.
48
+ const resumed = await tools.resume({ taskId: started.taskId });
49
+ assert.equal(resumed.title, '修复重复重试');
50
+ assert.equal(resumed.acceptance.length, 1);
51
+ assert.equal(resumed.remaining[0], '重试幂等');
52
+ assert.ok(resumed.acceptanceRevision >= 1);
53
+
54
+ // status lists and reads.
55
+ const list = await tools.status({ projectId: 'p1' });
56
+ assert.equal(list.total, 1);
57
+ const one = await tools.status({ taskId: started.taskId });
58
+ assert.equal(one.task.taskId, started.taskId);
59
+
60
+ // checkpoint candidate does not move nextAction; fact does.
61
+ await tools.checkpoint({ taskId: started.taskId, kind: 'candidate', summary: '可能完成', nextAction: '不该出现' });
62
+ let task = await tools.status({ taskId: started.taskId });
63
+ assert.notEqual(task.task.nextAction, '不该出现');
64
+ await tools.checkpoint({ taskId: started.taskId, kind: 'fact', summary: '修复完成', verifiedResults: ['单测通过'], nextAction: '提交审查' });
65
+ task = await tools.status({ taskId: started.taskId });
66
+ assert.equal(task.task.nextAction, '提交审查');
67
+ const resumed2 = await tools.resume({ taskId: started.taskId });
68
+ assert.deepEqual(resumed2.verifiedResults, ['单测通过']);
69
+
70
+ // request_review now runs the real check pipeline: use a synthetic repo
71
+ // with a real eslint violation so the receipt path is exercised (the
72
+ // verdict depends only on the synthetic files, never on this machine's
73
+ // other state).
74
+ const { spawnSync } = require('node:child_process');
75
+ const repo = fs.mkdtempSync(path.join(os.tmpdir(), 'wf-mcp-review-'));
76
+ const git = args => { const r = spawnSync('git', ['-C', repo, ...args], { encoding: 'utf8' }); if (r.status !== 0) throw new Error(r.stderr); };
77
+ git(['init', '-b', 'main']); git(['config', 'user.email', 't@t']); git(['config', 'user.name', 't']);
78
+ fs.writeFileSync(path.join(repo, 'package.json'), '{"name":"x","private":true}');
79
+ fs.writeFileSync(path.join(repo, 'eslint.config.mjs'), 'export default [{ rules: { complexity: ["error", { max: 1 }] } }];\n');
80
+ fs.writeFileSync(path.join(repo, 'violation.js'), 'export function b(x){if(x===1){return 1;}if(x===2){return 2;}if(x===3){return 3;}return 0;}\n');
81
+ git(['add', '.']); git(['commit', '-m', 'init']);
82
+ const review = await tools.requestReview({ taskId: started.taskId, repoPath: repo, tools: ['eslint'] });
83
+ assert.ok(review.receipts.some(r => r.toolId === 'eslint'));
84
+ assert.ok(['fail', 'warn', 'error'].includes(review.receipts[0].verdict), `real violation must not pass: ${JSON.stringify(review.receipts[0])}`);
85
+ assert.equal(review.decision.delivered, false);
86
+ assert.equal(review.modelReview, 'pending-model-review');
87
+ const resultRead = await tools.reviewResult({ taskId: started.taskId });
88
+ assert.ok(Array.isArray(resultRead.checks) && resultRead.checks.length >= 1, 'review_result reads the recorded checks');
89
+ console.log('workflow-tools-test PASS (start/resume/status/checkpoint + real check receipts over a real module instance)');
90
+ });
91
+
92
+ // Degradation: no live shell, no explicit URL -> structured WORKFLOW_UNAVAILABLE.
93
+ const offline = new WorkflowToolRuntime({ workflowUrl: 'http://127.0.0.1:9' });
94
+ try { await offline.status({}); throw new Error('offline status should fail'); }
95
+ catch (error) { assert.equal(error.code, 'WORKFLOW_UNAVAILABLE'); }
96
+ console.log('workflow-tools-test PASS (structured degradation when unreachable)');
97
+ })().catch(error => { console.error(error); process.exitCode = 1; });
@@ -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,并通过身份、版本与六工具契约校验。' });