@sanqianx/project-knowledge 5.2.1 → 5.3.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +6 -0
- package/README.md +6 -0
- package/_site/_test/ai-team-ui-integration-test.js +219 -0
- package/_site/_test/automatic-context-test.js +6 -0
- package/_site/_test/context-session-index-test.js +19 -9
- package/_site/_test/helpers/ai-team-ui-fixture.js +235 -0
- package/_site/_test/helpers/parallel-memory-shell.js +15 -7
- package/_site/_test/helpers/parallel-qa-engine-endpoint-isolate.js +3 -1
- package/_site/_test/helpers/single-repo-maintenance-fixture.js +94 -0
- package/_site/_test/helpers/single-repo-maintenance-tool.js +56 -0
- package/_site/_test/memory-groups-ui-test.js +27 -3
- package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +2 -2
- package/_site/_test/parallel-engine-final-eng012-test.js +4 -4
- package/_site/_test/parallel-memory-candidate-test.js +7 -5
- package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +1 -1
- package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +2 -2
- package/_site/_test/parallel-memory-home-review-test.js +1 -1
- package/_site/_test/parallel-memory-manual-test.js +14 -25
- package/_site/_test/parallel-memory-scope-test.js +66 -264
- package/_site/_test/parallel-memory-source-test.js +5 -7
- package/_site/_test/parallel-memory-sync-test.js +18 -9
- package/_site/_test/parallel-qa-engine-endpoint-guard-test.js +4 -2
- package/_site/_test/project-team-ui-test.js +11 -15
- package/_site/_test/shared-scope-root-binding-test.js +7 -6
- package/_site/_test/single-repo-maintenance-e2e-test.js +200 -0
- package/_site/_test/t07f-mem-008-coverage-test.js +0 -1
- package/_site/_test/workbench-context-receipts-test.js +9 -4
- package/_site/lib/engine-connection.js +2 -2
- package/_site/lib/engine-knowledge-client.js +1 -1
- package/_site/scripts/verify-retrieval-gold.js +10 -13
- package/module-runtime-manifest.json +31 -26
- 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/scripts/context-hook.cjs +3 -3
- package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +5 -6
- package/ui/product.css +20 -0
- package/ui/product.js +161 -67
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [5.3.1] - 2026-11-25
|
|
4
|
+
|
|
5
|
+
- AI 团队新增单仓库维护页。成员可调用本机登记的工具,按目标分支提交、每日北京时间或手动触发检查、格式整理和文档更新。
|
|
6
|
+
- 同仓任务排队复用独立 Git worktree。开发占用、工作区有改动或运行中断时保留现场。页面记录检查、修复、复查和候选提交,支持经授权的普通快进推送。
|
|
7
|
+
- 固定 Workflow `0.2.3`,嵌入页面跟随知识库的主题和窄屏布局。
|
|
8
|
+
|
|
3
9
|
## [5.2.1] - 2026-11-22
|
|
4
10
|
|
|
5
11
|
- 工作流模块升级至 `0.2.1`。AI 团队页按新交互设计重构:任务工作台(列表搜索、团队计划的依赖工作项与真实成员、最新意见在前代码审查、验收依据含工具版本/命令摘要/退出码/快照与收据时效)、团队设置(真实配置编辑带版本冲突保护)与只读接入诊断;全部数据来自服务端,无示例内容。程序收据新增脱敏命令摘要;能力声明如实标记审查编排可用。
|
package/README.md
CHANGED
|
@@ -192,6 +192,12 @@ local legacy read contract. Use `--scope domain` or `--scope brain` to broaden
|
|
|
192
192
|
CLI searches; MCP accepts the equivalent `scope`. Shared-file reads accept
|
|
193
193
|
`--space <spaceId>` (MCP: `space` or `spaceId`).
|
|
194
194
|
|
|
195
|
+
## Long-term memory
|
|
196
|
+
|
|
197
|
+
A confirmed memory is stored once in the engine state and can belong to several combinations. A combination applies to the projects you bind to it. Unassigned memories stay in the library. Review candidates with their original evidence before assigning them to a combination.
|
|
198
|
+
|
|
199
|
+
Upgrading to 5.3 migrates old confirmed scopes into combinations for their existing projects. Existing combinations, memory IDs, bodies and candidate evidence are kept. The engine backs up its state before migration. Readable group Markdown is generated under the brain's shared knowledge directory at `memories/groups/<group-id>.md`. Export a project's effective memories as `MEMORY.md` from its detail page.
|
|
200
|
+
|
|
195
201
|
## Storage
|
|
196
202
|
|
|
197
203
|
Version 5 is a fresh start, not a data upgrade. Stop the previous process,
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { createAiTeamUiFixture, cliOptions } = require('./helpers/ai-team-ui-fixture');
|
|
6
|
+
const { launchCdpBrowser, waitFor } = require('./helpers/cdp-browser');
|
|
7
|
+
const { findChrome } = require('./helpers/find-chrome');
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
const options = cliOptions({ test: true, defaultMaintenance: true });
|
|
11
|
+
// Keep Windows known-folder discovery intact for Chrome. The browser's
|
|
12
|
+
// explicit user-data-dir still belongs to this fixture.
|
|
13
|
+
const browserEnv = { ...process.env };
|
|
14
|
+
const fixture = await createAiTeamUiFixture(options);
|
|
15
|
+
let browser;
|
|
16
|
+
try {
|
|
17
|
+
const disallowed = await fetch(fixture.address + '/api/integrations/status');
|
|
18
|
+
assert.equal(disallowed.status, 403, 'the preview never inspects daily client integrations');
|
|
19
|
+
browser = await launchCdpBrowser({
|
|
20
|
+
chrome: findChrome(), profileDir: fixture.browserProfile, url: fixture.address,
|
|
21
|
+
launchAttempts: 1, width: 1440, height: 940, env: browserEnv,
|
|
22
|
+
});
|
|
23
|
+
const page = expression => browser.evaluate(expression);
|
|
24
|
+
const workflow = expression => page(
|
|
25
|
+
'(() => { const doc = document.querySelector("#workflowFrame")?.contentDocument; if (!doc) return null; return (' + expression + '); })()'
|
|
26
|
+
);
|
|
27
|
+
const click = selector => workflow('doc.querySelector(' + JSON.stringify(selector) + ').click()');
|
|
28
|
+
const has = (selector, text) => workflow('doc.querySelector(' + JSON.stringify(selector) + ')?.textContent.includes(' + JSON.stringify(text) + ')');
|
|
29
|
+
const field = (form, name, value) => workflow(
|
|
30
|
+
'(() => { const field = doc.getElementById(' + JSON.stringify(form) + ').elements.namedItem(' + JSON.stringify(name) + '); field.value = ' + JSON.stringify(value) + '; return field.value; })()'
|
|
31
|
+
);
|
|
32
|
+
const shot = filename => browser.screenshot(path.join(options.dataDir, filename));
|
|
33
|
+
|
|
34
|
+
await browser.setViewport(1440, 940);
|
|
35
|
+
await page('document.querySelector(\'nav [data-view="team"]\').click()');
|
|
36
|
+
if (options.emptyTeam) {
|
|
37
|
+
assert.equal((await fixture.call('team')).status, 'empty');
|
|
38
|
+
await waitFor(() => has('#heading', '任务工作台'), 'AI team frame in a newly installed knowledge base');
|
|
39
|
+
await click('#navSettings');
|
|
40
|
+
await waitFor(() => has('#teamForm', '创建团队'), 'first-team creation form');
|
|
41
|
+
await shot('create-team.png');
|
|
42
|
+
await field('teamForm', 'name', '首次建队验收');
|
|
43
|
+
await click('#teamForm button[type="submit"]');
|
|
44
|
+
await waitFor(() => has('#teamName', '首次建队验收'), 'team saved through Workflow');
|
|
45
|
+
assert.equal((await fixture.call('team')).team.name, '首次建队验收');
|
|
46
|
+
assert.equal(await workflow('Boolean(doc.getElementById("teamForm"))'), false);
|
|
47
|
+
const duplicate = await fetch(fixture.address + '/api/workflow/team', {
|
|
48
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
49
|
+
body: JSON.stringify({ requestId: 'duplicate-team-check', name: '第二团队' }),
|
|
50
|
+
});
|
|
51
|
+
assert.equal(duplicate.status, 409, 'the current Workflow contract rejects a second default team');
|
|
52
|
+
assert.deepEqual(browser.exceptions, []);
|
|
53
|
+
console.log('ai-team-ui-integration-test PASS (empty team UI, real creation, existing team view, duplicate rejected)');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
await waitFor(() => has('#taskList', fixture.task.title), 'render a task through the real Workflow proxy');
|
|
57
|
+
assert.equal(await workflow('doc.body.dataset.embed'), '1');
|
|
58
|
+
assert.equal(await has('#teamName', '维护团队'), true);
|
|
59
|
+
await click('#taskList [data-task]');
|
|
60
|
+
await waitFor(() => workflow('doc.querySelectorAll("#detail .subnav [data-tab]").length === 3'), 'task detail and Review tabs');
|
|
61
|
+
await shot('tasks.png');
|
|
62
|
+
|
|
63
|
+
await click('#start');
|
|
64
|
+
assert.equal(await workflow('doc.getElementById("promptDialog").open'), true);
|
|
65
|
+
await click('#closeDialog');
|
|
66
|
+
await click('#navSettings');
|
|
67
|
+
await waitFor(() => workflow('Boolean(doc.getElementById("projectForm"))'), 'project editor over core project directory');
|
|
68
|
+
assert.equal(await workflow('doc.querySelector("#projectPicker option").textContent'), '示例代码仓库');
|
|
69
|
+
assert.equal(await workflow('doc.getElementById("projectForm").elements.autoDispatch.checked'), true);
|
|
70
|
+
await shot('settings.png');
|
|
71
|
+
|
|
72
|
+
await click('#addMember');
|
|
73
|
+
await waitFor(() => has('#memberForm', '代码规范'), 'memory directory in member editor');
|
|
74
|
+
await field('memberForm', 'name', '验证维护成员');
|
|
75
|
+
await field('memberForm', 'instructions', '先检查文档,再记录结果。');
|
|
76
|
+
await workflow('doc.querySelector(\'#memberForm input[value="group-docs"]\').checked = true');
|
|
77
|
+
await shot('member.png');
|
|
78
|
+
await click('#memberForm button[type="submit"]');
|
|
79
|
+
await waitFor(() => has('#memberList', '验证维护成员'), 'new member persisted');
|
|
80
|
+
const member = (await fixture.call('members')).members.find(item => item.name === '验证维护成员');
|
|
81
|
+
assert.deepEqual(member.memoryGroupIds, ['group-docs']);
|
|
82
|
+
assert.equal(member.instructions, '先检查文档,再记录结果。');
|
|
83
|
+
await click('[data-edit-member="' + member.memberId + '"]');
|
|
84
|
+
await field('memberForm', 'instructions', '按项目工具配置更新文档。');
|
|
85
|
+
await click('#memberForm button[type="submit"]');
|
|
86
|
+
await waitFor(() => has('#memberList', '按项目工具配置更新文档。'), 'edited member persisted');
|
|
87
|
+
assert.equal((await fixture.call('members/' + member.memberId)).member.instructions, '按项目工具配置更新文档。');
|
|
88
|
+
|
|
89
|
+
const project1 = fixture.projects[0].id;
|
|
90
|
+
const project2 = fixture.projects[1].id;
|
|
91
|
+
await workflow('(() => {const select = doc.getElementById("projectPicker");select.value = ' + JSON.stringify(project2) + ';select.dispatchEvent(new Event("change"));return select.value;})()');
|
|
92
|
+
await waitFor(() => has('#projectForm', '未启用'), 'newly picked project shows persisted settings');
|
|
93
|
+
await workflow('doc.getElementById("projectForm").elements.enabled.checked = true');
|
|
94
|
+
await field('projectForm', 'leaderMemberId', member.memberId);
|
|
95
|
+
await workflow('doc.querySelector(' + JSON.stringify('[name="developerMemberIds"][value="' + member.memberId + '"]') + ').checked = true');
|
|
96
|
+
await click('#projectForm button[type="submit"]');
|
|
97
|
+
await waitFor(() => has('#projectForm', '已启用'), 'project setting saved');
|
|
98
|
+
const settings = (await fixture.call('projects/' + project2 + '/settings')).settings;
|
|
99
|
+
assert.equal(settings.leaderMemberId, member.memberId);
|
|
100
|
+
assert.deepEqual(settings.developerMemberIds, [member.memberId]);
|
|
101
|
+
assert.equal((await fixture.call('projects/' + project1 + '/settings')).settings.substantiveCodeReview, false);
|
|
102
|
+
|
|
103
|
+
await fixture.call('projects/' + project2 + '/settings', {
|
|
104
|
+
method: 'PUT', body: { requestId: 'external-settings-edit', expectedRevision: settings.revision, reminders: false },
|
|
105
|
+
});
|
|
106
|
+
await click('#projectForm button[type="submit"]');
|
|
107
|
+
await waitFor(() => has('#projectError', '配置已更新'), 'stale editor does not overwrite newer version');
|
|
108
|
+
await click('#projectError button');
|
|
109
|
+
await waitFor(() => workflow('doc.querySelector("#projectForm button[type=submit]")?.disabled === false'), 'reload updated config');
|
|
110
|
+
assert.equal((await fixture.call('projects/' + project2 + '/settings')).settings.reminders, false);
|
|
111
|
+
|
|
112
|
+
await click('#navMaintenance');
|
|
113
|
+
if (fixture.maintenance) {
|
|
114
|
+
await waitFor(() => has('#maintenanceRepoTitle', '示例代码仓库'), 'actual registered repository in the knowledge-base frame');
|
|
115
|
+
await click('[data-maintenance-new]');
|
|
116
|
+
await waitFor(() => has('#maintenanceDialogTitle', '新建维护任务'), 'maintenance creation dialog');
|
|
117
|
+
await field('maintenanceForm', 'title', '每日格式整理');
|
|
118
|
+
await field('maintenanceForm', 'memberId', member.memberId);
|
|
119
|
+
await field('maintenanceForm', 'toolId', 'format');
|
|
120
|
+
await field('maintenanceForm', 'trigger', 'daily');
|
|
121
|
+
await workflow('doc.getElementById("maintenanceForm").elements.trigger.dispatchEvent(new Event("change"))');
|
|
122
|
+
assert.equal(await workflow('doc.getElementById("maintenanceTimeField").hidden'), false);
|
|
123
|
+
await field('maintenanceForm', 'at', '09:00');
|
|
124
|
+
await workflow('doc.getElementById("maintenanceForm").elements.enabled.checked = true');
|
|
125
|
+
await shot('maintenance-task-form.png');
|
|
126
|
+
await click('#maintenanceForm button[type="submit"]');
|
|
127
|
+
await waitFor(() => has('.maintenance-job', '验证维护成员'), 'saved member is visible on the scheduled task');
|
|
128
|
+
assert.equal(await has('.maintenance-job', '每天 09:00'), true);
|
|
129
|
+
const job = (await fixture.call('maintenance')).jobs[0];
|
|
130
|
+
assert.equal(job.memberId, member.memberId);
|
|
131
|
+
assert.deepEqual(job.trigger, { kind: 'daily', at: '09:00' });
|
|
132
|
+
assert.equal(job.delivery, 'candidate');
|
|
133
|
+
|
|
134
|
+
await click('[data-maintenance-busy]');
|
|
135
|
+
await waitFor(() => has('[data-maintenance-busy]', '释放开发占用'), 'developer occupancy is persisted');
|
|
136
|
+
await click('[data-maintenance-run]');
|
|
137
|
+
await waitFor(() => has('.maintenance-run', '已排队'), 'manual run is queued during development');
|
|
138
|
+
await shot('maintenance-queued.png');
|
|
139
|
+
await click('[data-maintenance-busy]');
|
|
140
|
+
await waitFor(() => has('.maintenance-run', '已保留候选提交'), 'registered tool really commits in the isolated worktree');
|
|
141
|
+
await shot('maintenance-light.png');
|
|
142
|
+
await click('[data-maintenance-detail]');
|
|
143
|
+
await waitFor(() => has('#maintenanceRunDetail', '候选提交'), 'record displays real candidate SHA');
|
|
144
|
+
await click('.maintenance-receipt summary');
|
|
145
|
+
assert.equal(await has('.maintenance-receipt pre', 'format completed'), true);
|
|
146
|
+
await shot('maintenance-run-detail.png');
|
|
147
|
+
await click('#maintenanceRunDetail [data-close]');
|
|
148
|
+
} else {
|
|
149
|
+
await waitFor(() => has('#maintenance', '登记维护仓库'), 'unconfigured maintenance shows actual registration state');
|
|
150
|
+
assert.equal(await workflow('doc.querySelector("[data-maintenance-new]") === null'), true);
|
|
151
|
+
}
|
|
152
|
+
await browser.setViewport(390, 840);
|
|
153
|
+
await waitFor(() => workflow('doc.documentElement.scrollWidth <= doc.defaultView.innerWidth'), 'narrow maintenance layout');
|
|
154
|
+
assert.equal(await workflow('doc.querySelector("#navMaintenance").getBoundingClientRect().width > 0'), true);
|
|
155
|
+
await browser.setViewport(1440, 940);
|
|
156
|
+
await click('#navSettings');
|
|
157
|
+
await waitFor(() => has('#memberList', '验证维护成员'), 'team settings return from maintenance');
|
|
158
|
+
|
|
159
|
+
await page(`(() => {
|
|
160
|
+
const input = document.querySelector('input[data-token="accent"]');
|
|
161
|
+
input.value = '#3a775a';
|
|
162
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
163
|
+
})()`);
|
|
164
|
+
await waitFor(() => workflow('doc.documentElement.style.getPropertyValue("--accent") === "#3a775a"'), 'parent live skin applies inside Workflow');
|
|
165
|
+
await page('document.getElementById("themeToggle").click()');
|
|
166
|
+
await waitFor(() => workflow('doc.documentElement.dataset.theme === "dark"'), 'parent dark mode applies inside Workflow');
|
|
167
|
+
await shot('settings-dark.png');
|
|
168
|
+
|
|
169
|
+
await browser.setViewport(390, 840);
|
|
170
|
+
assert.ok(await workflow('doc.defaultView.innerWidth >= 360'), 'the knowledge-base sidebar must leave a usable width for the embedded page');
|
|
171
|
+
assert.equal(await workflow('doc.documentElement.scrollWidth <= doc.defaultView.innerWidth'), true);
|
|
172
|
+
await shot('mobile.png');
|
|
173
|
+
if (fixture.maintenance) {
|
|
174
|
+
await click('#navMaintenance');
|
|
175
|
+
await waitFor(() => has('.maintenance-run', '已保留候选提交'), 'actual runs render in dark mobile mode');
|
|
176
|
+
assert.equal(await workflow('doc.documentElement.scrollWidth <= doc.defaultView.innerWidth'), true);
|
|
177
|
+
await shot('maintenance-dark-mobile.png');
|
|
178
|
+
}
|
|
179
|
+
await click('#navTasks');
|
|
180
|
+
assert.equal(await has('#taskList', fixture.task.title), true);
|
|
181
|
+
|
|
182
|
+
if (options.designFile) {
|
|
183
|
+
await browser.send('Page.navigate', { url: fixture.address + '/?maintenance-preview=1' });
|
|
184
|
+
await waitFor(() => page('document.readyState === "complete" && Boolean(document.querySelector(\'nav [data-view="team"]\'))'), 'open design fixture');
|
|
185
|
+
await page('document.querySelector(\'nav [data-view="team"]\').click()');
|
|
186
|
+
await waitFor(() => has('#tk-page', '任务调度'), 'maintenance design mounts through the team frame');
|
|
187
|
+
await browser.setViewport(1440, 940);
|
|
188
|
+
await click('[data-action="simulate"]');
|
|
189
|
+
await click('#tk-form button[type="submit"]');
|
|
190
|
+
await waitFor(() => has('.tk-metrics', '1 排队'), 'busy repo queued while other repositories finish', 15000);
|
|
191
|
+
await click('[data-nav="projects"]');
|
|
192
|
+
await click('[data-action="toggle-development"][data-id="project-1"]');
|
|
193
|
+
await waitFor(() => has('.tk-table tbody tr:first-child', '累计使用 6 次'), 'reuses the existing worktree');
|
|
194
|
+
await click('[data-nav="runs"]');
|
|
195
|
+
await waitFor(() => has('.tk-run-detail', '提交并推送完成'), 'resumed simulation finishes');
|
|
196
|
+
await shot('maintenance-design.png');
|
|
197
|
+
await click('[data-action="simulate"]');
|
|
198
|
+
await field('tk-form', 'task', 'review-task');
|
|
199
|
+
await workflow('doc.getElementById("tk-form").elements.task.dispatchEvent(new Event("change"))');
|
|
200
|
+
await click('#tk-form button[type="submit"]');
|
|
201
|
+
await waitFor(() => has('.tk-run-detail', '修复提交已生成'), 'commit Review and repair simulation');
|
|
202
|
+
assert.ok(await has('.tk-run-detail', '复查通过'));
|
|
203
|
+
await click('[data-action="simulate"]');
|
|
204
|
+
await field('tk-form', 'task', 'docs-task');
|
|
205
|
+
await workflow('doc.getElementById("tk-form").elements.task.dispatchEvent(new Event("change"))');
|
|
206
|
+
await click('#tk-form button[type="submit"]');
|
|
207
|
+
await waitFor(() => has('.tk-run-detail', '提交并推送完成'), 'documentation simulation');
|
|
208
|
+
assert.ok(await has('.tk-run-detail', 'update_documents'));
|
|
209
|
+
}
|
|
210
|
+
assert.deepEqual(browser.exceptions, []);
|
|
211
|
+
const maintenanceResult = fixture.maintenance ? 'real maintenance task, run and receipt' : 'unconfigured maintenance';
|
|
212
|
+
console.log('ai-team-ui-integration-test PASS (shell proxy, team, members, project CAS, theme, mobile, ' + maintenanceResult + ')');
|
|
213
|
+
} finally {
|
|
214
|
+
if (browser) await browser.close();
|
|
215
|
+
await fixture.close();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
main().catch(error => { console.error(error.stack); process.exitCode = 1; });
|
|
@@ -44,6 +44,12 @@ async function main() {
|
|
|
44
44
|
assert.equal(indexed.receipt.injectionKind, 'index'); assert.equal(indexed.receipt.sessionIndexedCount, 7);
|
|
45
45
|
await writeOutput(indexed, { write: (text, callback) => callback() });
|
|
46
46
|
assert.ok(fs.readFileSync(path.join(logDir, fs.readdirSync(logDir)[0]), 'utf8').includes('"injectionKind":"index"'), 'the receipt log carries the injection kind');
|
|
47
|
+
const evidence = await run(payload, { env, fetchImpl: engineResponse({ status: 'ready', injectionKind: 'evidence', prompt: '<knowledge_context>source excerpt 37</knowledge_context>', facts: [{ text: 'source excerpt 37' }], memories: [], references: [{}] }) });
|
|
48
|
+
assert.match(evidence.hookSpecificOutput.additionalContext, /source excerpt 37/);
|
|
49
|
+
assert.equal(evidence.receipt.injectionKind, 'evidence'); assert.equal(evidence.receipt.evidenceCount, 1);
|
|
50
|
+
await writeOutput(evidence, { write: (text, callback) => callback() });
|
|
51
|
+
const evidenceLog = fs.readFileSync(path.join(logDir, fs.readdirSync(logDir)[0]), 'utf8');
|
|
52
|
+
assert.match(evidenceLog, /"evidenceCount":1/); assert.doesNotMatch(evidenceLog, /source excerpt 37/);
|
|
47
53
|
const oversized = await run(payload, { env, fetchImpl: engineResponse({ status: 'ready', prompt: 'x'.repeat(8001), facts: [], memories: [], references: [] }) });
|
|
48
54
|
assert.match(oversized.systemMessage, /CONTEXT_INVALID_RESPONSE/);
|
|
49
55
|
calls.length = 0;
|
|
@@ -159,8 +159,8 @@ async function main() {
|
|
|
159
159
|
fs.writeFileSync(path.join(knowledgeC, 'modules', 'rpc.md'), '# RpcTransportSDK lane 轮转规则\n\n恢复导出配置的九步流程与并发调度。KB-INDEX-SECRET-D\n');
|
|
160
160
|
fs.writeFileSync(path.join(knowledgeC, 'changes', 'extrapolation.md'), '# 外推算法九步流程\n\n外推算法按九步执行并记录证据。KB-INDEX-SECRET-E\n');
|
|
161
161
|
|
|
162
|
-
//
|
|
163
|
-
const first = await context('
|
|
162
|
+
// 问候只需首轮索引。 / A greeting needs only the opening index.
|
|
163
|
+
const first = await context('你好', 'sess-main');
|
|
164
164
|
assert.equal(first.status, 'ready'); assert.equal(first.injectionKind, 'index');
|
|
165
165
|
assert.equal(first.rankingVersion, 'project-knowledge/ranking-v3');
|
|
166
166
|
assert.ok(first.facts.some(item => item.entryId === 'modules/context.md' && item.role === '本项目事实'), 'the index lists the memory-system module');
|
|
@@ -170,7 +170,7 @@ async function main() {
|
|
|
170
170
|
assert.ok(first.prompt.length <= 3000, `index stays compact, got ${first.prompt.length}`);
|
|
171
171
|
assert.ok(first.sessionIndexedCount >= 2, 'the session registry counts its titles');
|
|
172
172
|
for (const secret of ['KB-INDEX-SECRET-A', 'KB-INDEX-SECRET-B', 'KB-INDEX-SECRET-C', 'KB-INDEX-SECRET-D', 'KB-INDEX-SECRET-E']) {
|
|
173
|
-
assert.ok(!first.prompt.includes(secret), '
|
|
173
|
+
assert.ok(!first.prompt.includes(secret), 'a greeting does not recall excerpts');
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// 2. A later turn without changes or strong matches is fully silent. With
|
|
@@ -189,20 +189,30 @@ async function main() {
|
|
|
189
189
|
const decoyTurn = await context(decoyQuery, 'sess-main');
|
|
190
190
|
assert.equal(decoyTurn.prompt, '', 'a boundary-bigram collision never becomes a breadcrumb');
|
|
191
191
|
|
|
192
|
-
//
|
|
192
|
+
// 强命中只显示一次,兼容已发布的标题提示。 / A strong hit is sent once, including on released title-only engines.
|
|
193
193
|
const strongQuery = '记忆注入机制是怎么设计的';
|
|
194
194
|
const crumb = await context(strongQuery, 'sess-main');
|
|
195
|
-
assert.
|
|
196
|
-
assert.ok(crumb.facts.some(item => item.entryId === 'modules/context.md'), 'the
|
|
195
|
+
assert.ok(['evidence', 'breadcrumb'].includes(crumb.injectionKind));
|
|
196
|
+
assert.ok(crumb.facts.some(item => item.entryId === 'modules/context.md'), 'the response points at the matching entry');
|
|
197
197
|
assert.ok(!crumb.facts.some(item => String(item.entryId).includes('rpc') || String(item.entryId).includes('extrapolation')), 'the decoys never appear');
|
|
198
|
-
assert.ok(crumb.prompt.includes('modules/context.md'));
|
|
198
|
+
assert.ok(crumb.prompt.includes('modules/context.md'));
|
|
199
|
+
const hasEvidence = crumb.injectionKind === 'evidence';
|
|
200
|
+
assert.equal(crumb.prompt.includes('KB-INDEX-SECRET-B'), hasEvidence);
|
|
201
|
+
if (hasEvidence) {
|
|
202
|
+
const firstTask = await context(strongQuery, 'sess-first-task');
|
|
203
|
+
assert.equal(firstTask.injectionKind, 'index');
|
|
204
|
+
assert.ok(firstTask.facts.some(item => item.entryId === 'modules/context.md' && item.text?.includes('KB-INDEX-SECRET-B')));
|
|
205
|
+
}
|
|
199
206
|
assert.ok(!crumb.prompt.includes('当前生效的已确认记忆只来自'), 'deltas never repeat the statement block');
|
|
200
207
|
assert.equal((await context(strongQuery, 'sess-main')).prompt, '', 'the same entry is on cooldown');
|
|
201
208
|
|
|
202
209
|
// 5. A memory added mid-session is re-sent in full exactly once.
|
|
203
210
|
const brainScope = (await engineApi('GET', '/api/snapshot?summary=1&limit=1')).body.sharedScopes.find(scope => scope.kind === 'brain');
|
|
204
211
|
assert.ok(brainScope, 'the brain scope exists');
|
|
205
|
-
const
|
|
212
|
+
const group = (await engineApi('POST', '/api/memory-groups', { name: '提交约定' })).body.group;
|
|
213
|
+
assert.ok(group);
|
|
214
|
+
assert.equal((await engineApi('POST', `/api/memory-groups/${group.id}/project-bindings`, { addProjectIds: [projectA] })).status, 200);
|
|
215
|
+
const created = await engineApi('POST', '/api/memories', { text: '本仓库必须保持中文提交信息', groupId: group.id, brainId: brainScope.brainId });
|
|
206
216
|
assert.equal(created.status, 200, JSON.stringify(created.body));
|
|
207
217
|
const memoryId = created.body.memory.id;
|
|
208
218
|
const memoryTurn = await context('继续做别的', 'sess-main');
|
|
@@ -227,7 +237,7 @@ async function main() {
|
|
|
227
237
|
const result = await context(query, 'sess-30');
|
|
228
238
|
cumulative += (result.prompt || '').length;
|
|
229
239
|
assert.ok((result.prompt || '').length <= 8000, 'the hard contract never breaks');
|
|
230
|
-
assert.
|
|
240
|
+
assert.doesNotMatch(result.prompt || '', /KB-INDEX-SECRET-[DE]/, 'unrelated entries stay outside the prompt');
|
|
231
241
|
}
|
|
232
242
|
assert.ok(cumulative <= 10240, `30 turns inject at most 10KB in total, got ${cumulative}`);
|
|
233
243
|
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const http = require('node:http');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { Module } = require('node:module');
|
|
8
|
+
const { prepareMaintenanceFixture } = require('./single-repo-maintenance-fixture');
|
|
9
|
+
|
|
10
|
+
const root = path.resolve(__dirname, '..', '..', '..');
|
|
11
|
+
const host = '127.0.0.1';
|
|
12
|
+
const offline = 'http://127.0.0.1:0';
|
|
13
|
+
const projects = [
|
|
14
|
+
{ id: 'project-ai-team-ui-1', name: '示例代码仓库' },
|
|
15
|
+
{ id: 'project-ai-team-ui-2', name: '示例文档仓库' },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
function json(res, response, status = 200) {
|
|
19
|
+
res.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
20
|
+
res.end(JSON.stringify(response));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function listen(server) {
|
|
24
|
+
await new Promise((resolve, reject) => {
|
|
25
|
+
server.once('error', reject);
|
|
26
|
+
server.listen(0, host, resolve);
|
|
27
|
+
});
|
|
28
|
+
return 'http://' + host + ':' + server.address().port;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function stop(server) {
|
|
32
|
+
server.closeAllConnections?.();
|
|
33
|
+
return new Promise(resolve => server.close(resolve));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function copyInstall(from, to, files) {
|
|
37
|
+
fs.mkdirSync(to, { recursive: true });
|
|
38
|
+
for (const file of files) fs.cpSync(path.join(from, file), path.join(to, file), { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function prepareIsolatedEnvironment(sandbox, moduleUrls) {
|
|
42
|
+
const paths = {
|
|
43
|
+
KB_DATA_DIR: path.join(sandbox, 'kb-data'),
|
|
44
|
+
KB_KNOWLEDGE_DATA_DIR: path.join(sandbox, 'knowledge'),
|
|
45
|
+
KB_CLAUDE_RULES_DIR: path.join(sandbox, 'config'),
|
|
46
|
+
AI_CODING_EVENT_BRIDGE_HOME: path.join(sandbox, 'bridge-home'),
|
|
47
|
+
HOME: path.join(sandbox, 'git-home'),
|
|
48
|
+
};
|
|
49
|
+
if (process.platform === 'win32') paths.USERPROFILE = path.join(sandbox, 'home');
|
|
50
|
+
for (const directory of Object.values(paths)) fs.mkdirSync(directory);
|
|
51
|
+
Object.assign(process.env, paths, {
|
|
52
|
+
KB_TERMINAL_URL: offline,
|
|
53
|
+
KB_VECTORHUB_URL: offline,
|
|
54
|
+
KB_EVENTBRIDGE_URL: offline,
|
|
55
|
+
KB_EVENT_BRIDGE_URL: offline,
|
|
56
|
+
KB_KNOWLEDGE_ENGINE_URL: moduleUrls.engine,
|
|
57
|
+
KB_WORKFLOW_URL: moduleUrls.workflow,
|
|
58
|
+
KB_MODULES_AUTOSTART: '0',
|
|
59
|
+
KB_MODULES_REGISTER: '0',
|
|
60
|
+
NODE_PATH: path.join(root, 'node_modules'),
|
|
61
|
+
});
|
|
62
|
+
Module._initPaths();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function fetchJson(url, options = {}) {
|
|
66
|
+
const response = await fetch(url, {
|
|
67
|
+
...options, headers: { 'Content-Type': 'application/json' },
|
|
68
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
69
|
+
});
|
|
70
|
+
const payload = await response.json();
|
|
71
|
+
if (!response.ok) throw new Error(`${response.status} ${url} ${payload.message || ''}`);
|
|
72
|
+
return payload;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function seedSyntheticState(runtime, sandbox, call, emptyTeam) {
|
|
76
|
+
for (const project of projects) {
|
|
77
|
+
const repoPath = path.join(sandbox, 'repos', project.id);
|
|
78
|
+
const knowledgePath = path.join(sandbox, 'knowledge', project.id);
|
|
79
|
+
fs.mkdirSync(repoPath, { recursive: true });
|
|
80
|
+
fs.mkdirSync(knowledgePath, { recursive: true });
|
|
81
|
+
await runtime.projectStore.create(project.id, { displayName: project.name, repoPath, knowledgePath });
|
|
82
|
+
await runtime.registryStore.add(project.id, { displayName: project.name });
|
|
83
|
+
}
|
|
84
|
+
if (emptyTeam) return { members: [], task: null };
|
|
85
|
+
const { members } = await call('team', {
|
|
86
|
+
method: 'POST', body: {
|
|
87
|
+
requestId: 'seed-team', name: '维护团队',
|
|
88
|
+
members: [
|
|
89
|
+
{ name: '维护 Agent', role: 'developer', instructions: '检查和维护示例仓库。', memoryGroupIds: ['group-code'] },
|
|
90
|
+
{ name: '独立 Reviewer', role: 'reviewer', instructions: '审阅改动说明。' },
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
await call('projects/' + projects[0].id + '/settings', {
|
|
95
|
+
method: 'PUT', body: {
|
|
96
|
+
requestId: 'seed-settings', enabled: true, autoDispatch: true, substantiveCodeReview: false,
|
|
97
|
+
leaderMemberId: members[0].memberId, developerMemberIds: [members[0].memberId], reviewerMemberId: members[1].memberId,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
const { task } = await call('workflow-tasks', {
|
|
101
|
+
method: 'POST', body: {
|
|
102
|
+
requestId: 'seed-task', projectId: projects[0].id, title: '维护示例仓库的接口文档',
|
|
103
|
+
goal: '核对接口文档的用法与实现。',
|
|
104
|
+
ownerMemberId: members[0].memberId,
|
|
105
|
+
acceptance: [{ kind: 'manual', title: '示例文档与接口一致' }],
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
return { members, task };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function attachDesignPreview(install, designFile) {
|
|
112
|
+
const asset = path.join(install, 'core', 'ui', 'product.js');
|
|
113
|
+
const source = fs.readFileSync(asset, 'utf8');
|
|
114
|
+
const route = '/workflow-ui/?embed=1&apiBase=/api/workflow';
|
|
115
|
+
if (!source.includes(route)) throw new Error('Workflow iframe route has changed.');
|
|
116
|
+
fs.writeFileSync(asset, source.replace("'" + route + "'", `(new URLSearchParams(location.search).has('maintenance-preview') ? '/workflow-ui/maintenance-preview.html?embed=1' : '${route}')`));
|
|
117
|
+
return fs.readFileSync(designFile);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function fixtureRequestAllowed(method, pathname, maintenance) {
|
|
121
|
+
if (pathname.startsWith('/api/integrations')) return false;
|
|
122
|
+
if (method === 'GET' || method === 'HEAD') return true;
|
|
123
|
+
if (method === 'POST') {
|
|
124
|
+
if (maintenance && /^\/api\/workflow\/maintenance\/(jobs|runs|control)$/.test(pathname)) return true;
|
|
125
|
+
return ['/api/workflow/team', '/api/workflow/members', '/api/workflow/workflow-tasks'].includes(pathname);
|
|
126
|
+
}
|
|
127
|
+
if (method === 'PATCH') return /^\/api\/workflow\/members\/[^/]+$/.test(pathname);
|
|
128
|
+
if (method === 'PUT') return projects.some(project => pathname === `/api/workflow/projects/${project.id}/settings`);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function createAiTeamUiFixture({ dataDir, workflowRoot, designFile, emptyTeam = false, maintenance = false, maintenanceTiming }) {
|
|
133
|
+
// A fresh, explicitly named directory cannot alias an existing installation.
|
|
134
|
+
const sandbox = path.resolve(dataDir);
|
|
135
|
+
fs.mkdirSync(sandbox);
|
|
136
|
+
const install = path.join(sandbox, 'install');
|
|
137
|
+
const workflowInstall = path.join(install, 'workflow');
|
|
138
|
+
const coreInstall = path.join(install, 'core');
|
|
139
|
+
copyInstall(workflowRoot, workflowInstall, ['src', 'ui', 'package.json']);
|
|
140
|
+
copyInstall(root, coreInstall, ['_site', 'ui', 'package.json', 'module-runtime-manifest.json']);
|
|
141
|
+
const design = designFile ? attachDesignPreview(install, designFile) : null;
|
|
142
|
+
const workflowData = path.join(sandbox, 'workflow-data');
|
|
143
|
+
fs.mkdirSync(workflowData);
|
|
144
|
+
prepareIsolatedEnvironment(sandbox, { engine: offline, workflow: offline });
|
|
145
|
+
const maintenanceFixture = maintenance && prepareMaintenanceFixture({ sandbox, coreInstall, workflowData, projectId: projects[0].id });
|
|
146
|
+
if (maintenanceFixture) maintenanceFixture.journalId = await maintenanceFixture.registerProject();
|
|
147
|
+
const bridgeUrl = maintenanceFixture ? await listen(maintenanceFixture.server) : offline;
|
|
148
|
+
const { createWorkflowServer } = require(path.join(workflowInstall, 'src', 'server'));
|
|
149
|
+
const workflowOptions = {
|
|
150
|
+
dataDir: workflowData, bridgeUrl, maintenanceTiming,
|
|
151
|
+
projectRoots: maintenanceFixture ? { [projects[0].id]: maintenanceFixture.repo } : undefined,
|
|
152
|
+
};
|
|
153
|
+
let workflow = createWorkflowServer(workflowOptions);
|
|
154
|
+
const memoryDirectory = http.createServer((req, res) => {
|
|
155
|
+
if (req.method === 'GET' && req.url.startsWith('/api/memory-groups?')) {
|
|
156
|
+
json(res, { ok: true, groups: [{ id: 'group-code', name: '代码规范' }, { id: 'group-docs', name: '文档约定' }], total: 2 });
|
|
157
|
+
} else json(res, { ok: false, error: 'FIXTURE_ROUTE' }, 404);
|
|
158
|
+
});
|
|
159
|
+
const shell = http.createServer();
|
|
160
|
+
const close = () => Promise.allSettled([
|
|
161
|
+
stop(shell), stop(memoryDirectory), workflow.close(), ...(maintenanceFixture ? [stop(maintenanceFixture.server)] : []),
|
|
162
|
+
]);
|
|
163
|
+
try {
|
|
164
|
+
const [wf, engine] = await Promise.all([workflow.listen(0, host), listen(memoryDirectory)]);
|
|
165
|
+
const workflowUrl = 'http://' + host + ':' + wf.port;
|
|
166
|
+
Object.assign(process.env, {
|
|
167
|
+
KB_KNOWLEDGE_ENGINE_URL: engine, KB_WORKFLOW_URL: workflowUrl,
|
|
168
|
+
KB_EVENTBRIDGE_URL: bridgeUrl, KB_EVENT_BRIDGE_URL: bridgeUrl,
|
|
169
|
+
});
|
|
170
|
+
const { createRuntime, initializeRuntime, createRequestHandler } = require(path.join(coreInstall, '_site', 'lib', 'server-app'));
|
|
171
|
+
const runtime = createRuntime({ rootDir: coreInstall, dataDir: process.env.KB_DATA_DIR, analysisOwner: 'legacy' });
|
|
172
|
+
await initializeRuntime(runtime);
|
|
173
|
+
const address = await listen(shell);
|
|
174
|
+
const handler = createRequestHandler(runtime, { host, port: shell.address().port });
|
|
175
|
+
shell.on('request', (req, res) => {
|
|
176
|
+
const pathname = new URL(req.url, address).pathname;
|
|
177
|
+
if (!fixtureRequestAllowed(req.method, pathname, maintenance)) {
|
|
178
|
+
json(res, { ok: false, error: 'FIXTURE_READ_ONLY', message: '此操作超出隔离 AI 团队预览范围。' }, 403);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (design && req.method === 'GET' && req.url.startsWith('/workflow-ui/maintenance-preview.html?')) {
|
|
182
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
183
|
+
res.end(design);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
handler(req, res);
|
|
187
|
+
});
|
|
188
|
+
const call = (route, options) => fetchJson(address + '/api/workflow/' + route, options);
|
|
189
|
+
const seeded = await seedSyntheticState(runtime, sandbox, call, emptyTeam);
|
|
190
|
+
if (maintenanceFixture) {
|
|
191
|
+
maintenanceFixture.installHook(process.env.KB_DATA_DIR, shell.address().port);
|
|
192
|
+
await workflow.consumer.drain({ notifyUrl: workflowUrl + '/api/internal/bridge-notify' });
|
|
193
|
+
}
|
|
194
|
+
async function restartWorkflow() {
|
|
195
|
+
await workflow.close();
|
|
196
|
+
workflow = createWorkflowServer(workflowOptions);
|
|
197
|
+
await workflow.listen(wf.port, host);
|
|
198
|
+
if (maintenanceFixture) await workflow.consumer.drain({ notifyUrl: workflowUrl + '/api/internal/bridge-notify' });
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
address, call, projects, browserProfile: path.join(sandbox, 'browser-profile'), ...seeded,
|
|
202
|
+
maintenance: maintenanceFixture, workflowUrl, restartWorkflow, close,
|
|
203
|
+
};
|
|
204
|
+
} catch (error) {
|
|
205
|
+
await close();
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function argument(name) {
|
|
211
|
+
const index = process.argv.indexOf('--' + name);
|
|
212
|
+
return index < 0 ? '' : process.argv[index + 1] || '';
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function cliOptions({ test = false, defaultMaintenance = false } = {}) {
|
|
216
|
+
const dataDir = argument('data') || (test ? path.join(fs.mkdtempSync(path.join(process.env.PK_TEST_TEMP_ROOT || os.tmpdir(), 'pk-ai-team-')), 'data') : '');
|
|
217
|
+
const workflowRoot = argument('workflow-root') || (test ? path.dirname(require.resolve('@sanqianx/ai-coding-workflow/package.json')) : '');
|
|
218
|
+
if (!dataDir || !workflowRoot) throw new Error('Supply --data <new test directory> and --workflow-root <Workflow checkout>.');
|
|
219
|
+
return {
|
|
220
|
+
dataDir, workflowRoot, designFile: argument('design') || undefined,
|
|
221
|
+
emptyTeam: process.argv.includes('--empty-team'),
|
|
222
|
+
maintenance: process.argv.includes('--maintenance') || (defaultMaintenance && !process.argv.includes('--without-maintenance')),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (require.main === module) {
|
|
227
|
+
createAiTeamUiFixture(cliOptions()).then(fixture => {
|
|
228
|
+
const close = () => fixture.close().then(() => { process.exitCode = 0; });
|
|
229
|
+
process.once('SIGINT', close);
|
|
230
|
+
process.once('SIGTERM', close);
|
|
231
|
+
console.log(JSON.stringify({ address: fixture.address, pid: process.pid, data: path.resolve(argument('data')) }));
|
|
232
|
+
}).catch(error => { console.error(error.stack); process.exitCode = 1; });
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
module.exports = { createAiTeamUiFixture, cliOptions };
|