@suifei/dsh-ai-team 0.4.159 → 0.4.161
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/CHANGELOG.md +9 -0
- package/README.md +9 -5
- package/index.js +25 -10
- package/lib/domain/catalog.js +89 -29
- package/lib/host/default-roster.js +7 -5
- package/lib/host/pmo.js +20 -5
- package/lib/host/project-runtime.js +2 -2
- package/lib/host/service.js +53 -1
- package/lib/host/session-roster.js +73 -35
- package/lib/host/session-team-command.js +16 -8
- package/lib/ledger/fold.js +32 -1
- package/lib/ledger/writer.js +14 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.161 - 2026-12-04
|
|
4
|
+
|
|
5
|
+
- DSH 会话内的增员、改岗位和离队交接可写进同一份编制草稿。确认时核对整组成员和任务,再写入一条账本记录。感谢 @buger-gif 提供会话调整编制与原任务交接的场景(#121)。
|
|
6
|
+
- 只读编制巡检同时记录项目级提交、通过、退回和人工自验次数,可与待验收积压和槽位余量对照。感谢 @buger-gif 提供验收队列巡检案例(#116)。
|
|
7
|
+
|
|
8
|
+
## 0.4.160 - 2026-12-04
|
|
9
|
+
|
|
10
|
+
- DSH 会话建队可按目标里明确出现的分工补齐预设,并把补位依据放入同一份建队草稿。确认时重新核对名单。初始化中断后可按确认时的名单补齐。感谢 @buger-gif 提供按目标增补岗位的场景(#121)。
|
|
11
|
+
|
|
3
12
|
## 0.4.159 - 2026-12-04
|
|
4
13
|
|
|
5
14
|
- 在 DSH 会话建队目标末尾可用「配 6 个人」指定人数。草稿显示目标人数、预设人数和岗位,人数不一致时先提示调整预设。感谢 @buger-gif 的会话组队与指定人数反馈(#121)。
|
package/README.md
CHANGED
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
|
|
38
38
|
## 最近更新
|
|
39
39
|
|
|
40
|
+
- **会话一次确认多项编制调整**(0.4.161)。增员、改岗位和原任务交接可进入同一份草稿,核对整组后一次写入。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)。
|
|
41
|
+
- **巡检验收流量**(0.4.161)。巡检在同一条记录里报告本窗口提交、通过与退回的次数,另列人工自验,方便和待验收积压、槽位余量对照。感谢 [@buger-gif](https://github.com/buger-gif),[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
|
|
42
|
+
- **会话建队按目标补位**(0.4.160)。当目标明确需要的岗位能补齐预设空缺时,同一草稿会列出新增岗位和匹配依据。确认时重新核对整份编制。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)。
|
|
40
43
|
- **会话建队人数核对**(0.4.159)。目标可用「配 6 个人」指定人数,草稿列出目标人数和预设编制,人数不一致时先提示调整预设。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)。
|
|
41
44
|
- **实时代理树槽位**(0.4.158)。支持 `capacityOf` 的宿主会在编制巡检中报告已占用和剩余槽位,建议新增成员时可看出同时启动是否需要排队。感谢 [@buger-gif](https://github.com/buger-gif),[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
|
|
42
45
|
- **DSH 0.2.3 Alpha 看板兼容**(0.4.158)。工作台沿用宿主 Web 路由的会话认证,修复已登录时看板仍加载失败的问题。感谢 [@Estelle00](https://github.com/Estelle00),[#122](https://github.com/suifei/dsh-ai-team/issues/122)。
|
|
@@ -144,7 +147,7 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
|
|
|
144
147
|
|
|
145
148
|
可用 `/ai-team 建队 --recommend 整理接口文档` 根据目标匹配文档、内容、教育、视频或游戏预设。唯一候选会随匹配依据进入草稿。有多个候选或线索不足时,用 `--team` 指定预设。省略这两个选项时使用设置中的团队。
|
|
146
149
|
|
|
147
|
-
若有明确人数,可用 `/ai-team 建队 --recommend 编写培训教材,配 6
|
|
150
|
+
若有明确人数,可用 `/ai-team 建队 --recommend 编写培训教材,配 6 个人`。也可以在目标中说明缺少的分工,例如 `/ai-team 建队 --recommend 整理接口文档,做交互体验评审,配六人`。这个例子在文档预设基础上补入 UX 设计,草稿会标出「体验、交互」作为依据。候选人数或分工有歧义时,先明确目标中的分工,或用 `--team` 指定人数匹配的预设。
|
|
148
151
|
|
|
149
152
|
会话会显示工作目录、目标、团队预设、人数与岗位。输入草稿末尾的 `/ai-team 确认 草稿ID` 创建项目,或用对应的取消命令丢弃草稿。草稿跟随当前会话,宿主重启后可以重新生成。
|
|
150
153
|
|
|
@@ -154,12 +157,13 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
|
|
|
154
157
|
|
|
155
158
|
`/ai-team 编制` 显示当前工作区的项目与成员编号。同一工作区有多个项目时,先选项目,使用 `/ai-team 编制 项目ID` 查看成员。用 `/ai-team 人才 [关键词]` 查看人才编号。
|
|
156
159
|
|
|
157
|
-
|
|
160
|
+
可以用 `/ai-team 调整` 在一句话里说明同一个项目的几项调整。同一工作区有多个项目时,在句子前加项目编号。同名成员或人才会列出编号供选择。
|
|
158
161
|
|
|
159
162
|
```text
|
|
160
163
|
/ai-team 调整 给团队加一位文案
|
|
161
164
|
/ai-team 调整 把校书的岗位改为文档协调
|
|
162
165
|
/ai-team 调整 让墨痕把任务交给校书后离队
|
|
166
|
+
/ai-team 调整 给团队加一位文案,并把校书的岗位改为文档协调,再让墨痕把任务交给校书后离队
|
|
163
167
|
```
|
|
164
168
|
|
|
165
169
|
```text
|
|
@@ -168,7 +172,7 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
|
|
|
168
172
|
/ai-team 离队 项目ID 成员ID [接手人ID]
|
|
169
173
|
```
|
|
170
174
|
|
|
171
|
-
|
|
175
|
+
变更命令先显示草稿,用同一会话里的确认命令写入。有未收口任务时须指定项目内会留队的接手人。多项调整共用一条账本记录,确认时重新核对成员、人才与原任务。有冲突或草稿过期时,先重新预览再确认。
|
|
172
176
|
|
|
173
177
|
### 按蓝图试跑
|
|
174
178
|
|
|
@@ -182,7 +186,7 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
|
|
|
182
186
|
|
|
183
187
|
### 只读编制巡检试跑
|
|
184
188
|
|
|
185
|
-
在当前 DSH profile 的 `ai-team` 配置中设 `staffingReviewMinutes: 180` 和 `diagLevel: full` 后,启用 PMO 自动的运行中普通项目会随现有巡检周期采样,每个时间窗口记录一次。`staffingReviewMinutes: 0`(默认)关闭采样。诊断日志中的 `pmo.staffing.review`
|
|
189
|
+
在当前 DSH profile 的 `ai-team` 配置中设 `staffingReviewMinutes: 180` 和 `diagLevel: full` 后,启用 PMO 自动的运行中普通项目会随现有巡检周期采样,每个时间窗口记录一次。`staffingReviewMinutes: 0`(默认)关闭采样。诊断日志中的 `pmo.staffing.review` 包含岗位已分配队列、可认领与待验收队列、最长及平均等待,以及采样窗口内每位成员的提交、验收和退回。返工率按退回的本窗口提交除以本窗口提交数计算,零样本为空。项目级 `acceptanceActivity` 按 `since`、`now` 内的账本记录计数,包含已离队成员和人工处理的结果。通过次数包含人工自验,日志另外列出自验次数。
|
|
186
190
|
|
|
187
191
|
巡检还会记录没有合格验收人的任务 ID 和在队成员运行回合数。宿主提供 `capacityOf` 时,`host-live` 表示当前代理树的实时槽位快照,`occupiedSlots` 和 `remainingSlots` 分别记录占用和余量。`host` 表示这棵树的容量回执,`default` 表示默认估计。这两种来源的占用和余量字段为空。宿主释放槽位后,插件优先补投本树排队最久的成员。加人建议会提示采样时的槽位不足,长期无人可验收的任务也会进入现有补位建议。
|
|
188
192
|
|
|
@@ -433,7 +437,7 @@ round-19 DeepSeek + Zhipu 双 provider
|
|
|
433
437
|
| 贡献者 | 贡献 | 带来的进展 |
|
|
434
438
|
|---|---|---|
|
|
435
439
|
| [@idontlikefruit](https://github.com/idontlikefruit) | 受阻状态的三组复现输入 [#115](https://github.com/suifei/dsh-ai-team/issues/115) | 统一看板徽标、读屏和分组统计的受阻判定,保留历史依赖 |
|
|
436
|
-
| [@buger-gif](https://github.com/buger-gif) | 编制巡检、离队交接案例 [#116](https://github.com/suifei/dsh-ai-team/issues/116)、[#117](https://github.com/suifei/dsh-ai-team/issues/117),派发空转记录 [#120](https://github.com/suifei/dsh-ai-team/issues/120)
|
|
440
|
+
| [@buger-gif](https://github.com/buger-gif) | 编制巡检、离队交接案例 [#116](https://github.com/suifei/dsh-ai-team/issues/116)、[#117](https://github.com/suifei/dsh-ai-team/issues/117),派发空转记录 [#120](https://github.com/suifei/dsh-ai-team/issues/120),会话建队、指定人数、按目标补位与调整编制场景 [#121](https://github.com/suifei/dsh-ai-team/issues/121) | 统一认领与离队顺序,减少派发空转,可按窗口对照验收流量和代理树槽位。在 DSH 会话按目标建议预设、核对人数和补位依据,一次确认多项编制调整及原任务交接 |
|
|
437
441
|
| [@Estelle00](https://github.com/Estelle00) | DSH 0.2.3 启动 503 的复现和桌面验证 [#122](https://github.com/suifei/dsh-ai-team/issues/122) | 接入新版会话鉴权接口,恢复工作台初始化,并在 Alpha 宿主验证看板登录 |
|
|
438
442
|
| [@phm101299-ui](https://github.com/phm101299-ui) | PMO 冷恢复的复现、根因和桌面验证 [#112](https://github.com/suifei/dsh-ai-team/issues/112) | 让原 PMO 在宿主重启后带着模型路由继续工作,保留成员关系和任务 |
|
|
439
443
|
| [@godfay-g](https://github.com/godfay-g) | 技能目录和 ZIP 的导入建议 [#109](https://github.com/suifei/dsh-ai-team/issues/109) | 成员与自定义人才可在文渊阁选择已安装的技能或导入完整技能包。0.4.151 统一新建人才的导入入口,并由文渊阁直接安装整包 |
|
package/index.js
CHANGED
|
@@ -82,7 +82,7 @@ import { readAttachment, uploadAttachment } from './lib/host/attachment-routes.j
|
|
|
82
82
|
import { createDiagLogger, defaultDiagDir, installDiagSink } from './lib/diaglog.js';
|
|
83
83
|
import { CATALOG_PACKAGE, clearOfficialCatalog, officialStatus, syncOfficialCatalog } from './lib/domain/catalog-sync.js';
|
|
84
84
|
import { AVATAR_PACKAGE, avatarFile, avatarOptions, renderAvatarSvg, startAvatarLib } from './lib/domain/avatar.js';
|
|
85
|
-
import { DEFAULT_TEAM, catalogRoots, deleteTalent, deleteTeam, forkTalent, installSkill, listInstallableSkills, listTalents, listTeams, loadCatalog, matchTeamPresets, readSkillText, resolveTeam, talentFromMember, talentIdFrom, uniqueTalentId, uniqueTeamId, userCatalogDir, writeTalent, writeTeam } from './lib/domain/catalog.js';
|
|
85
|
+
import { DEFAULT_TEAM, catalogRoots, deleteTalent, deleteTeam, forkTalent, installSkill, listInstallableSkills, listTalents, listTeams, loadCatalog, matchTeamPresets, readSkillText, resolveTeam, suggestTeamSupplements, talentFromMember, talentIdFrom, uniqueTalentId, uniqueTeamId, userCatalogDir, writeTalent, writeTeam } from './lib/domain/catalog.js';
|
|
86
86
|
|
|
87
87
|
export const name = 'ai-team';
|
|
88
88
|
|
|
@@ -2545,6 +2545,7 @@ export function apply(ctx, config = {}) {
|
|
|
2545
2545
|
if (disposed || booted === null) throw new Error('team ledger is unavailable');
|
|
2546
2546
|
let next = projectRuntime(nextProjectId);
|
|
2547
2547
|
if (next === null) {
|
|
2548
|
+
const resumeInitialRoster = !booted.registry.list().some(({ id }) => id === nextProjectId);
|
|
2548
2549
|
next = await ProjectRuntime.open({
|
|
2549
2550
|
rootDir: booted.dataDir,
|
|
2550
2551
|
projectId: nextProjectId,
|
|
@@ -2554,6 +2555,7 @@ export function apply(ctx, config = {}) {
|
|
|
2554
2555
|
diag,
|
|
2555
2556
|
pmoMaxRounds: config.pmoMaxRounds,
|
|
2556
2557
|
teamPreset: blueprint ? null : teamPreset ?? teamPresetFor(config, diag),
|
|
2558
|
+
resumeInitialRoster,
|
|
2557
2559
|
blueprint,
|
|
2558
2560
|
pmoAuto,
|
|
2559
2561
|
});
|
|
@@ -2591,17 +2593,30 @@ export function apply(ctx, config = {}) {
|
|
|
2591
2593
|
const nativeTeamCommand = sessionTeamCommand({
|
|
2592
2594
|
prepare(input) {
|
|
2593
2595
|
const project = projectInput(input);
|
|
2594
|
-
if (!input.recommend) return { ...project, teamPreset: teamPresetFor(config, diag, input.team) };
|
|
2595
2596
|
const catalog = talentCatalog(diag);
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
if (
|
|
2599
|
-
const
|
|
2600
|
-
|
|
2601
|
-
|
|
2597
|
+
let chosenTeam = input.team;
|
|
2598
|
+
let matchedTerms;
|
|
2599
|
+
if (input.recommend) {
|
|
2600
|
+
const candidates = matchTeamPresets(catalog, project.goal);
|
|
2601
|
+
diag.append({ ev: 'session.team.recommendation', candidates: candidates.map(({ id, terms }) => ({ id, terms })) });
|
|
2602
|
+
if (candidates.length !== 1) {
|
|
2603
|
+
const hint = '请用 /ai-team 建队 --team 预设ID 目标 指定团队。';
|
|
2604
|
+
const summary = candidates.map(({ name, id, terms }) => `- ${name}(${id}) · ${terms.join('、')}`).join('\n');
|
|
2605
|
+
fail(ERRORS.INVALID_ARGUMENT, summary ? `目标对应多个团队。${hint}\n${summary}` : `目标中缺少明确的团队线索。${hint}`);
|
|
2606
|
+
}
|
|
2607
|
+
chosenTeam = candidates[0].id;
|
|
2608
|
+
matchedTerms = candidates[0].terms;
|
|
2609
|
+
}
|
|
2610
|
+
const teamPreset = teamPresetFor(config, diag, chosenTeam, catalog);
|
|
2611
|
+
const { preset, suggestions, added } = suggestTeamSupplements(catalog, teamPreset, project.goal, input.requestedMembers);
|
|
2612
|
+
if (suggestions.length > 0) {
|
|
2613
|
+
diag.append({
|
|
2614
|
+
ev: 'session.team.supplements', preset: teamPreset.id, requestedMembers: input.requestedMembers,
|
|
2615
|
+
candidates: suggestions.map(({ id, terms }) => ({ id, terms })),
|
|
2616
|
+
added: added.map(({ member }) => member.talent.id),
|
|
2617
|
+
});
|
|
2602
2618
|
}
|
|
2603
|
-
|
|
2604
|
-
return { ...project, teamPreset: teamPresetFor(config, diag, match.id, catalog), matchedTerms: match.terms };
|
|
2619
|
+
return { ...project, teamPreset: preset, matchedTerms, suggestions, supplements: added };
|
|
2605
2620
|
},
|
|
2606
2621
|
create: async (id, input) => (await activateProject(id, { ...input, pmoAuto: false })).service.state.projects[id],
|
|
2607
2622
|
prepareRoster: createSessionRoster({
|
package/lib/domain/catalog.js
CHANGED
|
@@ -203,6 +203,20 @@ export function listTalents(catalog) {
|
|
|
203
203
|
.sort((a, b) => a.category.localeCompare(b.category, 'zh') || a.name.localeCompare(b.name, 'zh'));
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
function resolvedTeamMember(talent, member) {
|
|
207
|
+
return {
|
|
208
|
+
id: member.id,
|
|
209
|
+
name: member.name || talent.name,
|
|
210
|
+
role: member.role || talent.role,
|
|
211
|
+
duty: member.duty ?? talent.duty,
|
|
212
|
+
personality: member.personality || talent.personality,
|
|
213
|
+
skills: [...new Set([...talent.skills, ...(member.skills ?? [])])],
|
|
214
|
+
talent: { id: talent.id, version: talent.version, source: talent.source },
|
|
215
|
+
model: talent.model,
|
|
216
|
+
avatar: talent.avatar ?? null,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
206
220
|
/**
|
|
207
221
|
* 团队 → 可直接建成员的名单:每位成员按引用的人才补齐名字、岗位、职责、性格与技能
|
|
208
222
|
* (团队里写了的覆盖人才的)。团队缺失、写坏或引用了不存在的人才时退回默认团队并记 `.fail`。
|
|
@@ -217,17 +231,7 @@ export function resolveTeam(catalog, name = DEFAULT_TEAM, { diag } = {}) {
|
|
|
217
231
|
const members = entry.members.map((member) => {
|
|
218
232
|
const talent = catalog.talents.get(member.talent);
|
|
219
233
|
if (talent === undefined) throw new Error(`team ${wanted}: talent ${member.talent} not found`);
|
|
220
|
-
return
|
|
221
|
-
id: member.id,
|
|
222
|
-
name: member.name || talent.name,
|
|
223
|
-
role: member.role || talent.role,
|
|
224
|
-
duty: member.duty ?? talent.duty,
|
|
225
|
-
personality: member.personality || talent.personality,
|
|
226
|
-
skills: [...new Set([...talent.skills, ...member.skills])],
|
|
227
|
-
talent: { id: talent.id, version: talent.version, source: talent.source },
|
|
228
|
-
model: talent.model,
|
|
229
|
-
avatar: talent.avatar ?? null,
|
|
230
|
-
};
|
|
234
|
+
return resolvedTeamMember(talent, member);
|
|
231
235
|
});
|
|
232
236
|
return { id: wanted, source: entry.source, dir: entry.dir, team: { name: entry.name || wanted, description: entry.description, lead: entry.lead, procedures: entry.procedures, members } };
|
|
233
237
|
} catch (error) {
|
|
@@ -379,23 +383,82 @@ const PRESET_GOAL_TERMS = {
|
|
|
379
383
|
game: ['小游戏', '游戏开发', '游戏原型', '游戏玩法', 'game prototype'],
|
|
380
384
|
};
|
|
381
385
|
|
|
386
|
+
const goalTerm = (term) => term.normalize('NFKC').toLowerCase().trim();
|
|
387
|
+
|
|
388
|
+
function goalClauses(goal) {
|
|
389
|
+
return goalTerm(goal).split(/[,。;、!?,;!?\r\n]+/u)
|
|
390
|
+
.filter((clause) => !/(?:不要|不用|无需|不需要|不做|别|排除|\b(?:not|no|without|exclude)\b)/u.test(clause));
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function matchingGoalTerms(clauses, terms) {
|
|
394
|
+
return terms.filter((value) => {
|
|
395
|
+
const term = goalTerm(value);
|
|
396
|
+
if (term === '') return false;
|
|
397
|
+
if (/^[a-z\d][a-z\d -]*$/u.test(term)) {
|
|
398
|
+
const word = new RegExp(`\\b${term}\\b`, 'u');
|
|
399
|
+
return clauses.some((clause) => word.test(clause));
|
|
400
|
+
}
|
|
401
|
+
return clauses.some((clause) => clause.includes(term));
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const recommendableTeams = (catalog) => listTeams(catalog).filter((team) =>
|
|
406
|
+
Object.hasOwn(PRESET_GOAL_TERMS, team.id) && !team.broken && team.source !== 'user');
|
|
407
|
+
|
|
382
408
|
/** 只按现有预设的交付物找候选。命中多种方向时保留候选,交给用户选。 */
|
|
383
409
|
export function matchTeamPresets(catalog, goal) {
|
|
384
|
-
const clauses = goal
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
410
|
+
const clauses = goalClauses(goal);
|
|
411
|
+
return recommendableTeams(catalog).flatMap(({ id, name }) => {
|
|
412
|
+
const terms = matchingGoalTerms(clauses, PRESET_GOAL_TERMS[id]);
|
|
413
|
+
return terms.length > 0 ? [{ id, name, terms }] : [];
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function claimMemberId(talent, used) {
|
|
418
|
+
const base = `mem_${talent.replace(/-/g, '_')}`.slice(0, 60);
|
|
419
|
+
let id = base;
|
|
420
|
+
for (let n = 2; used.has(id); n += 1) id = `${base.slice(0, 56)}_${n}`;
|
|
421
|
+
used.add(id);
|
|
422
|
+
return id;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** 只用已支持推荐的预设和人才库中明确命中的岗位或标签,补齐目标需要的空缺。 */
|
|
426
|
+
export function suggestTeamSupplements(catalog, preset, goal, requestedMembers) {
|
|
427
|
+
const members = preset.team.members;
|
|
428
|
+
const empty = { preset, suggestions: [], added: [] };
|
|
429
|
+
if (!Number.isSafeInteger(requestedMembers) || requestedMembers <= members.length || preset.source === 'user') return empty;
|
|
430
|
+
const gap = requestedMembers - members.length;
|
|
431
|
+
const teams = recommendableTeams(catalog);
|
|
432
|
+
if (!teams.some(({ id }) => id === preset.id)) return empty;
|
|
433
|
+
|
|
434
|
+
const talentIds = new Set(members.map(({ talent }) => talent.id));
|
|
435
|
+
const coveredTerms = new Set(members.flatMap(({ role, talent }) =>
|
|
436
|
+
[role, ...(catalog.talents.get(talent.id)?.tags ?? [])]).map(goalTerm));
|
|
437
|
+
const pool = new Set(teams.flatMap(({ members: teamMembers }) => teamMembers.map(({ talent }) => talent)));
|
|
438
|
+
const clauses = goalClauses(goal);
|
|
439
|
+
const suggestions = [];
|
|
440
|
+
const termCounts = new Map();
|
|
441
|
+
for (const id of pool) {
|
|
442
|
+
const talent = catalog.talents.get(id);
|
|
443
|
+
if (talentIds.has(id) || talent.source === 'user' || talent.duty === 'lead') continue;
|
|
444
|
+
const terms = matchingGoalTerms(clauses, [talent.role, ...talent.tags]);
|
|
445
|
+
const uncovered = [...new Map(terms.map((term) => [goalTerm(term), term]))]
|
|
446
|
+
.filter(([term]) => !coveredTerms.has(term));
|
|
447
|
+
if (uncovered.length === 0) continue;
|
|
448
|
+
for (const [term] of uncovered) termCounts.set(term, (termCounts.get(term) ?? 0) + 1);
|
|
449
|
+
suggestions.push({ id, name: talent.name, role: talent.role, terms: uncovered.map(([, term]) => term) });
|
|
450
|
+
}
|
|
451
|
+
const hasSharedOnlyEvidence = suggestions.some(({ terms }) =>
|
|
452
|
+
terms.every((term) => termCounts.get(goalTerm(term)) !== 1));
|
|
453
|
+
if (suggestions.length !== gap || hasSharedOnlyEvidence) {
|
|
454
|
+
return { ...empty, suggestions };
|
|
397
455
|
}
|
|
398
|
-
|
|
456
|
+
const used = new Set(members.map(({ id }) => id));
|
|
457
|
+
const added = suggestions.map(({ id, terms }) => ({
|
|
458
|
+
member: resolvedTeamMember(catalog.talents.get(id), { id: claimMemberId(id, used) }),
|
|
459
|
+
terms,
|
|
460
|
+
}));
|
|
461
|
+
return { preset: { ...preset, team: { ...preset.team, members: [...members, ...added.map(({ member }) => member)] } }, suggestions, added };
|
|
399
462
|
}
|
|
400
463
|
|
|
401
464
|
/**
|
|
@@ -414,10 +477,7 @@ export function writeTeam(userRoot, id, input, catalog) {
|
|
|
414
477
|
const members = raw.map((m, i) => {
|
|
415
478
|
const talent = text(m?.talent, 64);
|
|
416
479
|
if (!SLUG.test(talent) || (catalog && !catalog.talents.has(talent))) throw new Error(`第 ${i + 1} 位成员引用的人才不存在:${String(m?.talent)}`);
|
|
417
|
-
const
|
|
418
|
-
let memberId = base;
|
|
419
|
-
for (let n = 2; used.has(memberId); n += 1) memberId = `${base.slice(0, 56)}_${n}`;
|
|
420
|
-
used.add(memberId);
|
|
480
|
+
const memberId = claimMemberId(talent, used);
|
|
421
481
|
const label = text(m?.name, 40);
|
|
422
482
|
return { talent, id: memberId, ...(label ? { name: label } : {}) };
|
|
423
483
|
});
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* UI placeholders: the Human can rename/re-role/re-model them, and the Lead is
|
|
4
4
|
* the default Project owner so a one-line Main-stream request can start work.
|
|
5
5
|
*
|
|
6
|
-
* Seeded
|
|
7
|
-
* user's roster is authoritative
|
|
6
|
+
* Seeded for a new Project before it is registered. On later boots the
|
|
7
|
+
* user's roster is authoritative.
|
|
8
8
|
*
|
|
9
9
|
* The roster itself is configuration: a team under `teams/` that picks talents from
|
|
10
10
|
* `talents/`, or a user team selected by the `teamPreset` setting (lib/domain/catalog.js).
|
|
@@ -61,7 +61,7 @@ async function upgradeLegacyDefaultNames(service, projectId, humanId, roster) {
|
|
|
61
61
|
* roles and the user's own roster are never touched or duplicated.
|
|
62
62
|
* @returns {Promise<{seeded: boolean, members: string[], renamed: string[]}>}
|
|
63
63
|
*/
|
|
64
|
-
export async function seedDefaultRoster(service, projectId, { humanId = 'mem_human', preset = resolveTeam(loadCatalog()) } = {}) {
|
|
64
|
+
export async function seedDefaultRoster(service, projectId, { humanId = 'mem_human', preset = resolveTeam(loadCatalog()), resumeInitialRoster = false } = {}) {
|
|
65
65
|
const blueprint = service.state.projects?.[projectId]?.blueprint;
|
|
66
66
|
if (blueprint) {
|
|
67
67
|
const actor = { kind: 'human', memberId: humanId };
|
|
@@ -81,7 +81,8 @@ export async function seedDefaultRoster(service, projectId, { humanId = 'mem_hum
|
|
|
81
81
|
}
|
|
82
82
|
const { team } = preset;
|
|
83
83
|
const roster = team.members;
|
|
84
|
-
|
|
84
|
+
// 未登记的新项目可能在播种中途失败,按同一份确认名单补齐。
|
|
85
|
+
if (!resumeInitialRoster && agentMembers(service).length > 0) {
|
|
85
86
|
const renamed = await upgradeLegacyDefaultNames(service, projectId, humanId, roster);
|
|
86
87
|
// 补缺岗只是老项目补齐 UX/业务 的迁移:只按**内置默认团队**做,且只对本来就由默认团队组成的项目
|
|
87
88
|
// (成员没记团队的老成员,或记的就是 default)。0.4.124 起内置团队不止一个(science、game…),
|
|
@@ -118,6 +119,7 @@ export async function seedDefaultRoster(service, projectId, { humanId = 'mem_hum
|
|
|
118
119
|
}
|
|
119
120
|
const added = [];
|
|
120
121
|
for (const member of roster) {
|
|
122
|
+
if (resumeInitialRoster && service.state.members?.[member.id]?.kind === 'agent') continue;
|
|
121
123
|
await service.dispatch({
|
|
122
124
|
type: 'member.add',
|
|
123
125
|
actor: { kind: 'human', memberId: humanId },
|
|
@@ -144,5 +146,5 @@ export async function seedDefaultRoster(service, projectId, { humanId = 'mem_hum
|
|
|
144
146
|
payload: { ownerMemberId: team.lead, reason: 'seed default roster' },
|
|
145
147
|
});
|
|
146
148
|
}
|
|
147
|
-
return { seeded:
|
|
149
|
+
return { seeded: added.length > 0, members: added, renamed: [] };
|
|
148
150
|
}
|
package/lib/host/pmo.js
CHANGED
|
@@ -259,6 +259,15 @@ function tasksWithoutReviewer(state, tasks) {
|
|
|
259
259
|
return tasks.filter((task) => !members.some((member) => isReviewCandidate(member, task, state)));
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
+
const ACCEPTANCE_ACTIVITY = new Map([
|
|
263
|
+
['task/submitted', 'submitted'],
|
|
264
|
+
['task/accepted', 'accepted'],
|
|
265
|
+
['review/accepted', 'accepted'],
|
|
266
|
+
['review/human_self_accept', 'accepted'],
|
|
267
|
+
['task/changes-requested', 'returned'],
|
|
268
|
+
['review/changes-requested', 'returned'],
|
|
269
|
+
]);
|
|
270
|
+
|
|
262
271
|
/** A read-only rollup of the existing queues and observed submissions in this window. */
|
|
263
272
|
export function staffingReview(state, events, { now, intervalMs, capacity, capacitySource = null, occupiedSlots = null, remainingSlots = null, inTurn, advice = [], suppressed = [] }) {
|
|
264
273
|
const since = now - intervalMs;
|
|
@@ -266,17 +275,22 @@ export function staffingReview(state, events, { now, intervalMs, capacity, capac
|
|
|
266
275
|
.filter((member) => member.kind === 'agent' && member.status !== 'retired')
|
|
267
276
|
.map(({ id, role, status }) => [id, { id, role: role || '未设置岗位', status, submitted: 0, accepted: 0, returned: 0 }]));
|
|
268
277
|
const submissions = new Map();
|
|
278
|
+
const acceptanceActivity = { submitted: 0, accepted: 0, returned: 0, humanSelfAccepted: 0 };
|
|
269
279
|
for (const event of events) {
|
|
270
280
|
if (!Number.isFinite(event.at) || event.at < since || event.at > now) continue;
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
if (
|
|
281
|
+
const activity = ACCEPTANCE_ACTIVITY.get(event.type);
|
|
282
|
+
const taskId = event.payload?.taskId ?? event.payload?.id;
|
|
283
|
+
if (activity === undefined || typeof taskId !== 'string' || taskId === '') continue;
|
|
284
|
+
acceptanceActivity[activity] += 1;
|
|
285
|
+
if (activity === 'submitted') {
|
|
274
286
|
const member = event.actor?.kind === 'agent' ? people.get(event.actor.memberId) : undefined;
|
|
275
287
|
submissions.set(taskId, member);
|
|
276
288
|
if (member) member.submitted += 1;
|
|
277
|
-
} else
|
|
289
|
+
} else {
|
|
290
|
+
const selfAccepted = activity === 'accepted' && (event.type === 'review/human_self_accept' || event.payload?.selfExecuted === true);
|
|
278
291
|
const member = submissions.get(taskId);
|
|
279
|
-
if (
|
|
292
|
+
if (selfAccepted) acceptanceActivity.humanSelfAccepted += 1;
|
|
293
|
+
else if (member) member[activity] += 1;
|
|
280
294
|
submissions.delete(taskId);
|
|
281
295
|
}
|
|
282
296
|
}
|
|
@@ -302,6 +316,7 @@ export function staffingReview(state, events, { now, intervalMs, capacity, capac
|
|
|
302
316
|
since, now, capacity, capacitySource, capacityScope: 'agent-tree', occupiedSlots, remainingSlots, activeMemberTurns,
|
|
303
317
|
claimable: waitingSummary(claimableTasks(state, open), now),
|
|
304
318
|
pendingAcceptance: waitingSummary(waitingReview, now),
|
|
319
|
+
acceptanceActivity,
|
|
305
320
|
pendingAcceptanceWithoutReviewer: { ...waitingSummary(missingReviewers, now), taskIds: missingReviewers.map(({ id }) => id) },
|
|
306
321
|
roles: [...groups.values()].map(({ assigned, ...group }) => ({ ...group, assignedQueue: waitingSummary(assigned, now) })),
|
|
307
322
|
advice,
|
|
@@ -26,7 +26,7 @@ export class ProjectRuntime {
|
|
|
26
26
|
this.service = service;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
static async open({ rootDir, projectId = DEFAULT_PROJECT_ID, now = undefined, seed = true, projectName = '我的项目', projectGoal = '把事交给团队', workspacePath = '', diag = null, pmoMaxRounds = undefined, teamPreset = null, blueprint = null, pmoAuto = true }) {
|
|
29
|
+
static async open({ rootDir, projectId = DEFAULT_PROJECT_ID, now = undefined, seed = true, projectName = '我的项目', projectGoal = '把事交给团队', workspacePath = '', diag = null, pmoMaxRounds = undefined, teamPreset = null, resumeInitialRoster = false, blueprint = null, pmoAuto = true }) {
|
|
30
30
|
const dir = join(rootDir, 'projects', projectId);
|
|
31
31
|
mkdirSync(dir, { recursive: true });
|
|
32
32
|
const ledger = openLedger({
|
|
@@ -91,7 +91,7 @@ export class ProjectRuntime {
|
|
|
91
91
|
payload: { id: projectId, name: projectName, goal: projectGoal, workspacePath, seed: true, blueprint, pmoAuto },
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
await seedDefaultRoster(service, projectId, { humanId: HUMAN_ID, ...(teamPreset ? { preset: teamPreset } : {}) });
|
|
94
|
+
await seedDefaultRoster(service, projectId, { humanId: HUMAN_ID, resumeInitialRoster, ...(teamPreset ? { preset: teamPreset } : {}) });
|
|
95
95
|
await service.backfillHumanMentions(state.projects?.[projectId]?.workspacePath ?? '');
|
|
96
96
|
} catch (error) {
|
|
97
97
|
runtime.close();
|
package/lib/host/service.js
CHANGED
|
@@ -23,7 +23,7 @@ import { appendReply, createThread } from '../domain/thread.js';
|
|
|
23
23
|
import { boardView, projectOverview, quadrantsView, taskCard } from './views.js';
|
|
24
24
|
import { applyMemberConfigPatch, normalizeMemberConfig } from '../domain/member-config.js';
|
|
25
25
|
import { parseAvatar } from '../domain/avatar.js';
|
|
26
|
-
import { MEMBER_STATUS, isBoardIdle } from '../ledger/fold.js';
|
|
26
|
+
import { MEMBER_STATUS, ROSTER_BATCH_EVENT, applyEvent, isBoardIdle, isRosterChange } from '../ledger/fold.js';
|
|
27
27
|
|
|
28
28
|
const MEMBER_STATUS_VALUES = new Set(Object.values(MEMBER_STATUS));
|
|
29
29
|
import { checkPersonality, isQaMember, unfinishedTasksFor } from '../domain/member-profile.js';
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
} from '../domain/team-blueprint.js';
|
|
36
36
|
|
|
37
37
|
const PMO_ACTOR = Object.freeze({ kind: 'system', memberId: 'mem_pmo' });
|
|
38
|
+
const ROSTER_COMMANDS = new Set(['member.add', 'member.profile.update', 'member.leave']);
|
|
38
39
|
const BLUEPRINT_START_STAGES = ['sample', 'improve', 'rerun'];
|
|
39
40
|
const BLUEPRINT_AGENT_COMMANDS = new Set([
|
|
40
41
|
'stream.post', 'thread.post', 'task.claim', 'task.submit', 'task.accept', 'task.request_changes', 'decision.request',
|
|
@@ -544,6 +545,57 @@ export class TeamService {
|
|
|
544
545
|
}
|
|
545
546
|
}
|
|
546
547
|
|
|
548
|
+
/** 会话确认的编制变更。多项变更共享一条持久事件,单项沿用原命令。 */
|
|
549
|
+
async dispatchRoster({ actor, projectId, correlationId, verifyDraft, commands }) {
|
|
550
|
+
if (actor?.kind !== 'human' || actor.memberId !== this.humanId() || typeof verifyDraft !== 'function') {
|
|
551
|
+
fail(ERRORS.UNAUTHORIZED, '编制草稿需要由本项目的用户确认');
|
|
552
|
+
}
|
|
553
|
+
if (projectId !== this.ledger.projectId) fail(ERRORS.NOT_FOUND, '编制草稿对应的项目已变化');
|
|
554
|
+
if (!Array.isArray(commands) || commands.length === 0 || commands.some((command) => !ROSTER_COMMANDS.has(command?.type))) {
|
|
555
|
+
fail(ERRORS.INVALID_ARGUMENT, '编制草稿只接受增员、改岗位和离队');
|
|
556
|
+
}
|
|
557
|
+
const scope = { actor, projectId, correlationId, verifyDraft };
|
|
558
|
+
if (commands.length === 1) return [await this.dispatch({ ...commands[0], ...scope })];
|
|
559
|
+
|
|
560
|
+
return this.runExclusive(async () => {
|
|
561
|
+
verifyDraft();
|
|
562
|
+
let stagedState = { ...this.state };
|
|
563
|
+
const expectedHeadSeq = stagedState.lastSeq;
|
|
564
|
+
const at = this.now();
|
|
565
|
+
const changes = [];
|
|
566
|
+
const staging = new TeamService({
|
|
567
|
+
now: () => at,
|
|
568
|
+
ledger: {
|
|
569
|
+
projectId,
|
|
570
|
+
get state() { return stagedState; },
|
|
571
|
+
async append(draft) {
|
|
572
|
+
const change = { type: draft.type, payload: draft.payload };
|
|
573
|
+
if (!isRosterChange(change)) fail(ERRORS.INVALID_STATE, '编制调整产生了不支持的账本变更');
|
|
574
|
+
const event = { ...draft, projectId, seq: stagedState.lastSeq + 1 };
|
|
575
|
+
stagedState = applyEvent(stagedState, event);
|
|
576
|
+
changes.push(change);
|
|
577
|
+
return event;
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
});
|
|
581
|
+
const results = [];
|
|
582
|
+
for (const { type, payload } of commands) {
|
|
583
|
+
// 整份草稿已复核。现有离队命令继续采用经复核的交接规则。
|
|
584
|
+
results.push(await staging.dispatch({ ...scope, type, payload, verifyDraft() {} }));
|
|
585
|
+
}
|
|
586
|
+
verifyDraft();
|
|
587
|
+
try {
|
|
588
|
+
await this.ledger.append({ type: ROSTER_BATCH_EVENT, projectId, actor, correlationId, at, payload: { changes } }, { expectedHeadSeq });
|
|
589
|
+
} catch (error) {
|
|
590
|
+
if (error?.code === 'E_LEDGER_HEAD_CHANGED') fail(ERRORS.REVISION, '项目在确认期间已有新变化,请重新生成草稿。');
|
|
591
|
+
if (error?.code === 'E_EVENT_TOO_LARGE') fail(ERRORS.INVALID_ARGUMENT, '这份编制草稿涉及的记录过多,请分成较小的草稿。');
|
|
592
|
+
throw error;
|
|
593
|
+
}
|
|
594
|
+
this.diag?.append({ ev: 'session.roster.batch.committed', projectId, draftId: correlationId, commands: commands.length, changes: changes.length });
|
|
595
|
+
return results;
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
|
|
547
599
|
checkBlueprintCommand(command, payload) {
|
|
548
600
|
const project = this.state.projects?.[command.projectId];
|
|
549
601
|
if (!project?.blueprint) return;
|
|
@@ -6,7 +6,7 @@ import { unfinishedTasksFor } from '../domain/member-profile.js';
|
|
|
6
6
|
|
|
7
7
|
const USAGE = {
|
|
8
8
|
编制: '/ai-team 编制 [项目ID]',
|
|
9
|
-
调整: '/ai-team 调整 [项目ID]
|
|
9
|
+
调整: '/ai-team 调整 [项目ID] 逐项说明编制调整',
|
|
10
10
|
人才: '/ai-team 人才 [关键词]',
|
|
11
11
|
增员: '/ai-team 增员 项目ID 人才ID',
|
|
12
12
|
改岗位: '/ai-team 改岗位 项目ID 成员ID 新岗位',
|
|
@@ -38,10 +38,10 @@ function resolveName(entries, value, label, aliases = (entry) => [entry.name]) {
|
|
|
38
38
|
fail(ERRORS.CONFLICT, `${label}「${name}」有多个候选,请使用编号。\n${matches.map(memberLabel).join('\n')}`);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (/[。;;\r\n]|(?:并|同时|然后)\s*(?:给|把|让|再|加|离队|改)/u.test(statement)) fail(ERRORS.INVALID_ARGUMENT,
|
|
41
|
+
const ROSTER_SENTENCE_HELP = '请明确每项调整。示例:给团队加一位文案,并把校书的岗位改为文档协调。';
|
|
42
|
+
|
|
43
|
+
function readRosterAction(statement, runtime, catalog) {
|
|
44
|
+
if (/[。;;\r\n]|(?:并|同时|然后)\s*(?:给|把|让|再|加|离队|改)/u.test(statement)) fail(ERRORS.INVALID_ARGUMENT, ROSTER_SENTENCE_HELP);
|
|
45
45
|
const hire = /^给团队加(?:一位|一名)\s*(.+)$/u.exec(statement);
|
|
46
46
|
if (hire) {
|
|
47
47
|
const target = resolveName(listTalents(catalog()), hire[1], '人才', ({ name, role }) => [name, role]);
|
|
@@ -55,7 +55,13 @@ function readRosterSentence(sentence, runtime, catalog) {
|
|
|
55
55
|
if (handoff) return { action: '离队', target: findMember(handoff[1]), value: findMember(handoff[2]) };
|
|
56
56
|
const leave = /^让(.+?)离队$/u.exec(statement);
|
|
57
57
|
if (leave) return { action: '离队', target: findMember(leave[1]), value: '' };
|
|
58
|
-
fail(ERRORS.INVALID_ARGUMENT,
|
|
58
|
+
fail(ERRORS.INVALID_ARGUMENT, ROSTER_SENTENCE_HELP);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function readRosterSentence(sentence, runtime, catalog) {
|
|
62
|
+
const statement = sentence.trim().replace(/[。!!.]$/u, '');
|
|
63
|
+
const separator = /(?:[,,;;。\r\n]+\s*|[,,;;。]?\s*(?:并且|同时|然后|另外|并|再|和)(?:\s*再)?\s*)(?=给团队加|把|让)/u;
|
|
64
|
+
return statement.split(separator).map((part) => readRosterAction(part.trim(), runtime, catalog));
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
function describeRoster(runtime, project) {
|
|
@@ -110,6 +116,29 @@ function planChange(runtime, action, target, value, catalog) {
|
|
|
110
116
|
};
|
|
111
117
|
}
|
|
112
118
|
|
|
119
|
+
function checkRosterActions(actions) {
|
|
120
|
+
const targets = new Set();
|
|
121
|
+
const leaving = new Set(actions.filter(({ action }) => action === '离队').map(({ target }) => target));
|
|
122
|
+
for (const { action, target, value } of actions) {
|
|
123
|
+
if (action === '增员') continue;
|
|
124
|
+
if (targets.has(target)) fail(ERRORS.CONFLICT, `同一草稿中有多项调整涉及成员 ${target},请明确保留哪一项。`);
|
|
125
|
+
targets.add(target);
|
|
126
|
+
if (action === '离队' && leaving.has(value)) fail(ERRORS.CONFLICT, '同一草稿中接手人也要离队,请指定会留队的成员。');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function planChanges(runtime, actions, catalog) {
|
|
131
|
+
const plans = actions.map(({ action, target, value }) => planChange(runtime, action, target, value, catalog));
|
|
132
|
+
const transferred = new Set();
|
|
133
|
+
for (const { taskRevisions = [] } of plans) {
|
|
134
|
+
for (const [id] of taskRevisions) {
|
|
135
|
+
if (transferred.has(id)) fail(ERRORS.CONFLICT, '同一张原任务涉及多个离队成员,请先明确交接顺序。');
|
|
136
|
+
transferred.add(id);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return plans;
|
|
140
|
+
}
|
|
141
|
+
|
|
113
142
|
export function createSessionRoster({ runtimes, isAvailable, catalog, actor, disposeMemberActivation }) {
|
|
114
143
|
return async function prepareRoster({ action: requested, argument, workspacePath }) {
|
|
115
144
|
if (requested === '人才') {
|
|
@@ -139,41 +168,50 @@ export function createSessionRoster({ runtimes, isAvailable, catalog, actor, dis
|
|
|
139
168
|
if (!selection) fail(ERRORS.NOT_FOUND, '当前会话的工作区找不到该项目。使用 /ai-team 编制 查看同一工作区的项目。');
|
|
140
169
|
const { runtime, project } = selection;
|
|
141
170
|
if (requested === '编制') return { text: describeRoster(runtime, project) };
|
|
142
|
-
const
|
|
171
|
+
const actions = requestedSentence
|
|
143
172
|
? readRosterSentence(requestedProject ? input.slice(first.length) : input, runtime, catalog)
|
|
144
|
-
: { action: requested, target: supplied, value: rest };
|
|
173
|
+
: [{ action: requested, target: supplied, value: rest }];
|
|
145
174
|
const projectId = project.id;
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
runtime.service.checkBlueprintCommand(
|
|
150
|
-
const approved = JSON.stringify(
|
|
175
|
+
checkRosterActions(actions);
|
|
176
|
+
const changes = planChanges(runtime, actions, catalog);
|
|
177
|
+
const commands = changes.map(({ type, payload }) => ({ type, payload }));
|
|
178
|
+
for (const { type, payload } of commands) runtime.service.checkBlueprintCommand({ type, actor, projectId }, payload);
|
|
179
|
+
const approved = JSON.stringify(changes);
|
|
180
|
+
const verifyDraft = () => {
|
|
181
|
+
const currentProject = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
|
|
182
|
+
if (!currentProject || currentProject.name !== project.name) {
|
|
183
|
+
fail(ERRORS.REVISION, '项目或工作目录已变化,请重新生成草稿。');
|
|
184
|
+
}
|
|
185
|
+
let current;
|
|
186
|
+
try {
|
|
187
|
+
current = planChanges(runtime, actions, catalog);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error instanceof DomainError) fail(ERRORS.REVISION, `${error.message} 请核对编制后重新生成草稿。`);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
if (JSON.stringify(current) !== approved) fail(ERRORS.REVISION, '成员、人才或任务已变化,请重新生成草稿。');
|
|
193
|
+
};
|
|
194
|
+
const grouped = changes.length > 1;
|
|
151
195
|
return {
|
|
152
|
-
projectId, action,
|
|
153
|
-
lines: [`编制草稿 ${project.name}(${projectId})`, ...
|
|
196
|
+
projectId, action: grouped ? '调整' : actions[0].action, details: { changes: changes.length },
|
|
197
|
+
lines: [`编制草稿 ${project.name}(${projectId})`, ...changes.flatMap(({ lines }) => lines)],
|
|
154
198
|
async apply(draftId) {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
verifyDraft() {
|
|
158
|
-
const currentProject = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
|
|
159
|
-
if (!currentProject || currentProject.name !== project.name) {
|
|
160
|
-
fail(ERRORS.REVISION, '项目或工作目录已变化,请重新生成草稿。');
|
|
161
|
-
}
|
|
162
|
-
let current;
|
|
163
|
-
try {
|
|
164
|
-
current = planChange(runtime, action, target, value, catalog);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
if (error instanceof DomainError) fail(ERRORS.REVISION, `${error.message} 请核对编制后重新生成草稿。`);
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
if (JSON.stringify(current) !== approved) fail(ERRORS.REVISION, '成员、人才或任务已变化,请重新生成草稿。');
|
|
170
|
-
},
|
|
199
|
+
const committed = await runtime.service.dispatchRoster({
|
|
200
|
+
commands, actor, projectId, correlationId: draftId, verifyDraft,
|
|
171
201
|
});
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
202
|
+
const lines = [];
|
|
203
|
+
for (const [index, result] of committed.entries()) {
|
|
204
|
+
const { action, target } = actions[index];
|
|
205
|
+
if (action === '离队') {
|
|
206
|
+
await disposeMemberActivation(runtime, target, commands[index].type);
|
|
207
|
+
lines.push(`已将${memberLabel(result.member)}移入人才池,交接了 ${result.transferredTasks?.length ?? 0} 张原任务。`);
|
|
208
|
+
} else if (action === '增员') {
|
|
209
|
+
lines.push(`已添加${memberLabel(result.member)}。`);
|
|
210
|
+
} else {
|
|
211
|
+
lines.push(`已将${memberLabel(result.member)}的岗位更新为「${result.member.role}」。`);
|
|
212
|
+
}
|
|
175
213
|
}
|
|
176
|
-
return
|
|
214
|
+
return grouped ? [`已确认 ${changes.length} 项编制调整。`, ...lines].join('\n') : lines[0];
|
|
177
215
|
},
|
|
178
216
|
};
|
|
179
217
|
};
|
|
@@ -15,7 +15,9 @@ function sessionWorkspace(session) {
|
|
|
15
15
|
return realpathSync(requireWorkspaceDirectory(path));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const draftSignature = ({ teamPreset, supplements }) => JSON.stringify([
|
|
19
|
+
teamPreset.id, teamPreset.source, teamPreset.dir, teamPreset.team, supplements,
|
|
20
|
+
]);
|
|
19
21
|
|
|
20
22
|
function requestedRosterSize(goal) {
|
|
21
23
|
const count = /(?:^|[,;。\r\n])\s*配\s*([+-]?\d+(?:\.\d+)?|[零〇一二两三四五六七八九十]+)\s*(?:[个名位]\s*)?(?:人|成员)\s*[。.!]?$/u.exec(goal.normalize('NFKC'))?.[1];
|
|
@@ -66,21 +68,24 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
|
|
|
66
68
|
const recommend = /^--recommend(?:\s|$)/.test(argument);
|
|
67
69
|
const goal = (recommend ? argument.slice('--recommend'.length) : selected?.[2] ?? argument).trim();
|
|
68
70
|
if (goal === '' || (!selected && argument.startsWith('--team'))) return { kind: 'error', text: HELP };
|
|
69
|
-
const input = { name: goal.split(/\r?\n/, 1)[0], goal, workspacePath, team: selected?.[1] ?? '', recommend };
|
|
70
71
|
const requestedMembers = requestedRosterSize(goal);
|
|
72
|
+
const input = { name: goal.split(/\r?\n/, 1)[0], goal, workspacePath, team: selected?.[1] ?? '', recommend, requestedMembers };
|
|
71
73
|
const prepareDraft = () => {
|
|
72
74
|
const project = prepare(input);
|
|
73
75
|
const count = project.teamPreset.team.members.length;
|
|
74
76
|
if (requestedMembers !== null && count !== requestedMembers) {
|
|
75
77
|
const { id, team } = project.teamPreset;
|
|
76
|
-
|
|
78
|
+
const suggestions = project.suggestions.map(({ role, name, terms }) => `- ${name} · ${role}(${terms.join('、')})`);
|
|
79
|
+
const hint = suggestions.length > 0 ? `\n匹配到这些补位候选,可在目标中明确所需分工。\n${suggestions.join('\n')}` : '';
|
|
80
|
+
fail(ERRORS.INVALID_ARGUMENT, `目标要求 ${requestedMembers} 人,${team.name}(${id})有 ${count} 人。请用 --team 选择匹配人数的预设,或在文渊阁调整预设后重新建队。${hint}`);
|
|
77
81
|
}
|
|
78
82
|
return project;
|
|
79
83
|
};
|
|
80
84
|
const proposed = prepareDraft();
|
|
81
85
|
const members = proposed.teamPreset.team.members;
|
|
82
86
|
const id = ids.project();
|
|
83
|
-
const signature =
|
|
87
|
+
const signature = draftSignature(proposed);
|
|
88
|
+
const supplementEvidence = new Map(proposed.supplements.map(({ member, terms }) => [member.id, terms]));
|
|
84
89
|
return preview(session, workspacePath, {
|
|
85
90
|
id, action,
|
|
86
91
|
details: { preset: proposed.teamPreset.id, members: members.length, requestedMembers },
|
|
@@ -91,7 +96,10 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
|
|
|
91
96
|
`预设 ${proposed.teamPreset.team.name}(${proposed.teamPreset.id})`,
|
|
92
97
|
...(proposed.matchedTerms ? [`匹配依据 ${proposed.matchedTerms.join('、')}`] : []),
|
|
93
98
|
`编制 ${members.length} 人${requestedMembers !== null ? `(目标 ${requestedMembers} 人)` : ''}`,
|
|
94
|
-
...members.map((member) =>
|
|
99
|
+
...members.map((member) => {
|
|
100
|
+
const terms = supplementEvidence.get(member.id);
|
|
101
|
+
return `- ${member.name} · ${member.role}${terms ? `(补位依据 ${terms.join('、')})` : ''}`;
|
|
102
|
+
}),
|
|
95
103
|
'确认后创建项目,PMO 自动为关闭状态。',
|
|
96
104
|
],
|
|
97
105
|
async apply() {
|
|
@@ -99,11 +107,11 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
|
|
|
99
107
|
try {
|
|
100
108
|
approved = prepareDraft();
|
|
101
109
|
} catch (error) {
|
|
102
|
-
if (error instanceof DomainError) fail(ERRORS.REVISION, '
|
|
110
|
+
if (error instanceof DomainError) fail(ERRORS.REVISION, '团队预设或匹配证据已更新,请重新生成草稿后再确认。');
|
|
103
111
|
throw error;
|
|
104
112
|
}
|
|
105
|
-
if (
|
|
106
|
-
fail(ERRORS.REVISION, '
|
|
113
|
+
if (draftSignature(approved) !== signature) {
|
|
114
|
+
fail(ERRORS.REVISION, '团队预设或匹配证据已更新,请重新生成草稿后再确认。');
|
|
107
115
|
}
|
|
108
116
|
const project = await create(id, approved);
|
|
109
117
|
return `已创建「${project.name}」(${project.id})。可在文渊阁查看团队,准备好后开启 PMO 自动。`;
|
package/lib/ledger/fold.js
CHANGED
|
@@ -54,8 +54,25 @@ import { normalizeAttachments } from '../domain/rich-message.js';
|
|
|
54
54
|
*
|
|
55
55
|
* v8:Human 改设置(成员资料 / 成员模型 / PMO 设置)不算 Human 意图(#18:il2c 实账本里
|
|
56
56
|
* 这类编辑占 Human 意图事件的 1/4,每次都把自主续开预算清零)。
|
|
57
|
+
*
|
|
58
|
+
* v9:同一份编制草稿里的多项调整从一条事件重放。旧 checkpoint 不认识该事件。
|
|
57
59
|
*/
|
|
58
|
-
export const FOLD_STATE_VERSION =
|
|
60
|
+
export const FOLD_STATE_VERSION = 9;
|
|
61
|
+
|
|
62
|
+
export const ROSTER_BATCH_EVENT = 'project/roster-adjusted';
|
|
63
|
+
const ROSTER_CHANGE_TYPES = new Set([
|
|
64
|
+
'project/member-added', 'member/profile-updated', 'task/taken-over', 'member/left-team',
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
export function isRosterChange(change) {
|
|
68
|
+
return isPlainObject(change) && ROSTER_CHANGE_TYPES.has(change.type) && isPlainObject(change.payload);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function rosterChanges(event) {
|
|
72
|
+
const changes = event.payload?.changes;
|
|
73
|
+
return event.actor?.kind === 'human' && Array.isArray(changes) && changes.length > 0 && changes.every(isRosterChange)
|
|
74
|
+
? changes : null;
|
|
75
|
+
}
|
|
59
76
|
|
|
60
77
|
/**
|
|
61
78
|
* 投影封顶:大规模/长迭代账本下,stream 与每个 Thread 的 entries 不随事件数
|
|
@@ -718,6 +735,9 @@ const HUMAN_BOOKKEEPING_EVENTS = new Set([
|
|
|
718
735
|
|
|
719
736
|
/** 事件是否代表 Human 的意图(而不是插件代 Human 记的簿记)。 */
|
|
720
737
|
export function isHumanIntent(event) {
|
|
738
|
+
if (event?.type === ROSTER_BATCH_EVENT) {
|
|
739
|
+
return rosterChanges(event)?.some(({ type }) => !HUMAN_BOOKKEEPING_EVENTS.has(type)) ?? false;
|
|
740
|
+
}
|
|
721
741
|
return event?.actor?.kind === 'human' && !HUMAN_BOOKKEEPING_EVENTS.has(event.type);
|
|
722
742
|
}
|
|
723
743
|
|
|
@@ -725,6 +745,17 @@ const PMO_NEWS_TASK_EVENTS = new Set(['task/accepted', 'task/cancelled', 'task/d
|
|
|
725
745
|
const PMO_SEEN_REASONS = new Set(['pmo_continue', 'wave_done', 'human_message']);
|
|
726
746
|
|
|
727
747
|
export function applyEvent(state, event) {
|
|
748
|
+
if (event?.type === ROSTER_BATCH_EVENT && isEventLike(event)) {
|
|
749
|
+
if (!isPlainObject(state)) throw new TypeError('applyEvent: state must be a plain object');
|
|
750
|
+
const lastSeq = Number.isSafeInteger(state.lastSeq) ? state.lastSeq : 0;
|
|
751
|
+
if (event.seq <= lastSeq) return state;
|
|
752
|
+
const changes = rosterChanges(event);
|
|
753
|
+
if (changes === null) return advance(state, event);
|
|
754
|
+
// 每项沿用原事件的折叠语义,账本位置都属于这条完整记录。
|
|
755
|
+
return changes.reduce((next, change) => applyEvent({ ...next, lastSeq }, {
|
|
756
|
+
...event, type: change.type, payload: change.payload,
|
|
757
|
+
}), state);
|
|
758
|
+
}
|
|
728
759
|
const next = applyBudget(state, event, applyEventCore(state, event));
|
|
729
760
|
if (next === state) return next;
|
|
730
761
|
if (isHumanIntent(event) || PMO_NEWS_TASK_EVENTS.has(event.type)) {
|
package/lib/ledger/writer.js
CHANGED
|
@@ -258,16 +258,17 @@ export class LedgerWriter {
|
|
|
258
258
|
* 追加单条事件。返回 sealed event(含 seq / hash / prevHash)。
|
|
259
259
|
* Promise 在写入(以及默认 fsync)完成后 resolve;失败则文件回滚、head 不变。
|
|
260
260
|
*/
|
|
261
|
-
append(draft) {
|
|
262
|
-
return this.appendMany([draft]).then((events) => events[0]);
|
|
261
|
+
append(draft, options) {
|
|
262
|
+
return this.appendMany([draft], options).then((events) => events[0]);
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
266
|
* 组提交:一批事件共享一次 fsync;任一失败整批回滚。
|
|
267
267
|
* @param {object[]} drafts
|
|
268
|
+
* @param {{expectedHeadSeq?: number}} [options]
|
|
268
269
|
* @returns {Promise<object[]>} sealed events
|
|
269
270
|
*/
|
|
270
|
-
appendMany(drafts) {
|
|
271
|
+
appendMany(drafts, { expectedHeadSeq } = {}) {
|
|
271
272
|
if (!Array.isArray(drafts)) {
|
|
272
273
|
return Promise.reject(new LedgerError('E_EVENT_INVALID', 'appendMany expects an array'));
|
|
273
274
|
}
|
|
@@ -280,7 +281,14 @@ export class LedgerWriter {
|
|
|
280
281
|
rollbackError: this._poisoned,
|
|
281
282
|
}));
|
|
282
283
|
}
|
|
283
|
-
return this._enqueue(() =>
|
|
284
|
+
return this._enqueue(() => {
|
|
285
|
+
if (expectedHeadSeq !== undefined && this._head.seq !== expectedHeadSeq) {
|
|
286
|
+
throw new LedgerError('E_LEDGER_HEAD_CHANGED', 'ledger advanced before append', {
|
|
287
|
+
expected: expectedHeadSeq, actual: this._head.seq,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
return this._appendBatch(drafts);
|
|
291
|
+
});
|
|
284
292
|
}
|
|
285
293
|
|
|
286
294
|
/**
|
|
@@ -1138,11 +1146,11 @@ export function openLedger(options = {}) {
|
|
|
1138
1146
|
get headSeq() {
|
|
1139
1147
|
return writer.head.seq;
|
|
1140
1148
|
},
|
|
1141
|
-
async append(draft) {
|
|
1149
|
+
async append(draft, options) {
|
|
1142
1150
|
// 先齐平 events:checkpoint 齐平启动时 events 还是 null,若等 append 之后再
|
|
1143
1151
|
// readAll,刚写入的事件会被读出来、再被 push 一次(重复)。
|
|
1144
1152
|
const list = ensureEvents();
|
|
1145
|
-
const event = await writer.append(draft);
|
|
1153
|
+
const event = await writer.append(draft, options);
|
|
1146
1154
|
// 只有 append 成功(含 fsync)后才推进内存状态。
|
|
1147
1155
|
Object.assign(state, applyEvent(state, event));
|
|
1148
1156
|
list.push(event);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.161",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
6
|
"license": "MIT",
|