@suifei/dsh-ai-team 0.4.156 → 0.4.157

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.157 - 2026-12-03
4
+
5
+ - DSH 会话可根据目标建议团队,显示匹配的交付物。有多个候选时请用户选择。`/ai-team 调整` 可用一句话准备增员、改岗位或离队交接草稿,沿用会话确认和原卡交接。感谢 @buger-gif 的会话建队与编制反馈(#121)。
6
+
3
7
  ## 0.4.156 - 2026-12-03
4
8
 
5
9
  - 在 DSH 会话查看当前工作区的项目编制,从人才库增员、修改岗位或指定接手人后离队。确认时重新核对成员、人才和未收口任务,交接成功后原成员进入人才池。感谢 @buger-gif 的会话调整与任务交接场景(#121、#116)。
package/README.md CHANGED
@@ -37,6 +37,7 @@
37
37
 
38
38
  ## 最近更新
39
39
 
40
+ - **会话建队建议与一句话调整编制**(0.4.157)。根据目标匹配团队预设并显示依据。可用一句话准备增员、改岗位或离队交接的草稿。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)。
40
41
  - **从会话调整编制**(0.4.156)。可查看同一工作区的团队,从人才库增员、修改岗位或把原任务交给接手人后离队。变更经草稿确认。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)、[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
41
42
  - **从会话建队与分树容量**(0.4.155)。在 DSH 会话输入目标即可预览目录和岗位,确认后由现有流程创建项目。编制巡检和排队补投按项目代理树处理并发。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)、[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
42
43
  - **目录浏览和验收补位**(0.4.154)。新建或编辑项目时可使用宿主的原生对话框或浏览式选择器。桌面安装说明补齐首次初始化和退出步骤。编制巡检标明缺少合格验收人的任务、观察到的成员回合和容量来源。感谢 [@ljyzww](https://github.com/ljyzww),[#100](https://github.com/suifei/dsh-ai-team/issues/100)。感谢 [@Arnoldnuo](https://github.com/Arnoldnuo),[#102](https://github.com/suifei/dsh-ai-team/issues/102)。感谢 [@buger-gif](https://github.com/buger-gif),[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
@@ -138,7 +139,9 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
138
139
  /ai-team 建队 --team docs 整理接口文档
139
140
  ```
140
141
 
141
- 会话会显示工作目录、目标、团队预设与岗位。输入草稿末尾的 `/ai-team 确认 草稿ID` 创建项目,或用对应的取消命令丢弃草稿。省略 `--team` 时使用设置中的默认团队预设。草稿跟随当前会话,宿主重启后可以重新生成。
142
+ 可用 `/ai-team 建队 --recommend 整理接口文档` 根据目标匹配文档、内容、教育、视频或游戏预设。唯一候选会随匹配依据进入草稿。有多个候选或线索不足时,用 `--team` 指定预设。省略这两个选项时使用设置中的团队。
143
+
144
+ 会话会显示工作目录、目标、团队预设与岗位。输入草稿末尾的 `/ai-team 确认 草稿ID` 创建项目,或用对应的取消命令丢弃草稿。草稿跟随当前会话,宿主重启后可以重新生成。
142
145
 
143
146
  新项目会出现在文渊阁,PMO 自动初始关闭。团队准备好后,可以在项目页开启 PMO 自动。
144
147
 
@@ -146,6 +149,14 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
146
149
 
147
150
  `/ai-team 编制` 显示当前工作区的项目与成员编号。同一工作区有多个项目时,先选项目,使用 `/ai-team 编制 项目ID` 查看成员。用 `/ai-team 人才 [关键词]` 查看人才编号。
148
151
 
152
+ 也可以用 `/ai-team 调整` 说清一件事。同一工作区有多个项目时,在句子前加项目编号。同名成员或人才会列出编号供选择。
153
+
154
+ ```text
155
+ /ai-team 调整 给团队加一位文案
156
+ /ai-team 调整 把校书的岗位改为文档协调
157
+ /ai-team 调整 让墨痕把任务交给校书后离队
158
+ ```
159
+
149
160
  ```text
150
161
  /ai-team 增员 项目ID 人才ID
151
162
  /ai-team 改岗位 项目ID 成员ID 新岗位
@@ -417,7 +428,7 @@ round-19 DeepSeek + Zhipu 双 provider
417
428
  | 贡献者 | 贡献 | 带来的进展 |
418
429
  |---|---|---|
419
430
  | [@idontlikefruit](https://github.com/idontlikefruit) | 受阻状态的三组复现输入 [#115](https://github.com/suifei/dsh-ai-team/issues/115) | 统一看板徽标、读屏和分组统计的受阻判定,保留历史依赖 |
420
- | [@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 会话里确认建队、编制调整和原任务交接 |
431
+ | [@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 会话按目标建议预设,并确认一句话编制草稿及原任务交接 |
421
432
  | [@Estelle00](https://github.com/Estelle00) | DSH 0.2.3 启动 503 的复现和桌面验证 [#122](https://github.com/suifei/dsh-ai-team/issues/122) | 接入新版会话鉴权接口,恢复工作台初始化 |
422
433
  | [@phm101299-ui](https://github.com/phm101299-ui) | PMO 冷恢复的复现、根因和桌面验证 [#112](https://github.com/suifei/dsh-ai-team/issues/112) | 让原 PMO 在宿主重启后带着模型路由继续工作,保留成员关系和任务 |
423
434
  | [@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, 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, talentFromMember, talentIdFrom, uniqueTalentId, uniqueTeamId, userCatalogDir, writeTalent, writeTeam } from './lib/domain/catalog.js';
86
86
 
87
87
  export const name = 'ai-team';
88
88
 
@@ -182,8 +182,7 @@ async function memberHostSkillReferences(names, ownedRoots, summaries) {
182
182
  }
183
183
 
184
184
  /** 新项目用哪个团队:新建时选的优先,其次插件设置 `teamPreset`,最后内置默认团队。 */
185
- function teamPresetFor(config, diag, chosen = '') {
186
- const catalog = talentCatalog(diag);
185
+ function teamPresetFor(config, diag, chosen = '', catalog = talentCatalog(diag)) {
187
186
  if (chosen !== '') {
188
187
  const entry = listTeams(catalog).find((team) => team.id === chosen);
189
188
  if (entry === undefined) fail(ERRORS.INVALID_ARGUMENT, `团队不存在:${chosen}`, { status: 400 });
@@ -2590,7 +2589,20 @@ export function apply(ctx, config = {}) {
2590
2589
  }
2591
2590
 
2592
2591
  const nativeTeamCommand = sessionTeamCommand({
2593
- prepare: (input) => ({ ...projectInput(input), teamPreset: teamPresetFor(config, diag, input.team) }),
2592
+ prepare(input) {
2593
+ const project = projectInput(input);
2594
+ if (!input.recommend) return { ...project, teamPreset: teamPresetFor(config, diag, input.team) };
2595
+ const catalog = talentCatalog(diag);
2596
+ const candidates = matchTeamPresets(catalog, project.goal);
2597
+ diag.append({ ev: 'session.team.recommendation', candidates: candidates.map(({ id, terms }) => ({ id, terms })) });
2598
+ if (candidates.length !== 1) {
2599
+ const hint = '请用 /ai-team 建队 --team 预设ID 目标 指定团队。';
2600
+ const summary = candidates.map(({ name, id, terms }) => `- ${name}(${id}) · ${terms.join('、')}`).join('\n');
2601
+ fail(ERRORS.INVALID_ARGUMENT, summary ? `目标对应多个团队。${hint}\n${summary}` : `目标中缺少明确的团队线索。${hint}`);
2602
+ }
2603
+ const [match] = candidates;
2604
+ return { ...project, teamPreset: teamPresetFor(config, diag, match.id, catalog), matchedTerms: match.terms };
2605
+ },
2594
2606
  create: async (id, input) => (await activateProject(id, { ...input, pmoAuto: false })).service.state.projects[id],
2595
2607
  prepareRoster: createSessionRoster({
2596
2608
  async runtimes() {
@@ -371,6 +371,33 @@ export function listTeams(catalog) {
371
371
  .sort((a, b) => (a.id === DEFAULT_TEAM ? -1 : b.id === DEFAULT_TEAM ? 1 : 0) || a.source.localeCompare(b.source) || a.name.localeCompare(b.name, 'zh'));
372
372
  }
373
373
 
374
+ const PRESET_GOAL_TERMS = {
375
+ docs: ['文档', '手册', '知识库', 'readme', 'api documentation'],
376
+ content: ['公众号', '博客', '社媒', '文案', 'blog'],
377
+ education: ['课件', '教材', '题库', '教案', '复习', '课程', 'quiz'],
378
+ video: ['视频', '分镜', '剪辑', '字幕', 'video'],
379
+ game: ['小游戏', '游戏开发', '游戏原型', '游戏玩法', 'game prototype'],
380
+ };
381
+
382
+ /** 只按现有预设的交付物找候选。命中多种方向时保留候选,交给用户选。 */
383
+ export function matchTeamPresets(catalog, goal) {
384
+ const clauses = goal.normalize('NFKC').toLowerCase().split(/[,。;、!?,;!?\r\n]+/u)
385
+ .filter((clause) => !/(?:不要|不用|无需|不需要|不做|别|排除|\b(?:not|no|without|exclude)\b)/u.test(clause));
386
+ const candidates = [];
387
+ for (const team of listTeams(catalog)) {
388
+ if (!Object.hasOwn(PRESET_GOAL_TERMS, team.id) || team.broken || team.source === 'user') continue;
389
+ const terms = PRESET_GOAL_TERMS[team.id].filter((term) => {
390
+ if (/^[a-z ]+$/u.test(term)) {
391
+ const word = new RegExp(`\\b${term}\\b`, 'u');
392
+ return clauses.some((clause) => word.test(clause));
393
+ }
394
+ return clauses.some((clause) => clause.includes(term));
395
+ });
396
+ if (terms.length > 0) candidates.push({ id: team.id, name: team.name, terms });
397
+ }
398
+ return candidates;
399
+ }
400
+
374
401
  /**
375
402
  * 组队:写一个用户团队 `<userRoot>/teams/<id>/team.yml`。
376
403
  * `members` 是 [{ talent, name? }](同一人才可招多位,成员 id 自动生成且不重复),`lead` 是成员下标或成员 id(缺省第一位)。
@@ -1,141 +1,180 @@
1
- import { realpathSync } from 'node:fs';
2
- import { isAbsolute } from 'node:path';
3
- import { listTalents } from '../domain/catalog.js';
4
- import { DomainError, ERRORS, fail } from '../domain/errors.js';
5
- import { unfinishedTasksFor } from '../domain/member-profile.js';
6
-
7
- const USAGE = {
8
- 编制: '/ai-team 编制 [项目ID]',
9
- 人才: '/ai-team 人才 [关键词]',
10
- 增员: '/ai-team 增员 项目ID 人才ID',
11
- 改岗位: '/ai-team 改岗位 项目ID 成员ID 新岗位',
12
- 离队: '/ai-team 离队 项目ID 成员ID [接手人ID]',
13
- };
14
-
15
- export const rosterHelp = Object.values(USAGE).join('\n');
16
- export const isRosterAction = (action) => Object.hasOwn(USAGE, action);
17
-
18
- function workspaceProject(runtime, workspacePath) {
19
- const project = runtime.service.state.projects?.[runtime.id];
20
- if (!project || project.status === 'archived' || typeof project.workspacePath !== 'string' || !isAbsolute(project.workspacePath)) return null;
21
- try {
22
- return realpathSync(project.workspacePath) === workspacePath ? project : null;
23
- } catch {
24
- return null;
25
- }
26
- }
27
-
28
- const memberLabel = (member) => `${member.name}(${member.id})`;
29
-
30
- function describeRoster(runtime, project) {
31
- const state = runtime.service.state;
32
- const members = Object.values(state.members ?? {}).filter((member) => member.kind === 'agent');
33
- return [
34
- `「${project.name}」的编制(${project.id})`,
35
- ...members.map((member) => {
36
- const unfinished = unfinishedTasksFor(state, member.id).length;
37
- const role = member.role ? ` · ${member.role}` : '';
38
- const departed = member.status === 'retired' ? ' · 已离队' : '';
39
- return `- ${memberLabel(member)}${role}${departed} · ${unfinished} 张未收口任务`;
40
- }),
41
- '使用 /ai-team 人才查看可选人才。',
42
- ].join('\n');
43
- }
44
-
45
- function planChange(runtime, action, target, value, catalog) {
46
- const reason = '会话编制草稿确认';
47
- if (action === '增员') {
48
- const talent = catalog().talents.get(target);
49
- if (!talent) fail(ERRORS.NOT_FOUND, '人才库中找不到该人才。使用 /ai-team 人才 查看可选人才。');
50
- return {
51
- type: 'member.add',
52
- payload: {
53
- name: talent.name, role: talent.role, duty: talent.duty,
54
- personality: talent.personality, skills: talent.skills, avatar: talent.avatar,
55
- talent: talent.id, talentVersion: talent.version,
56
- },
57
- lines: [`增员 ${talent.name} · ${talent.role}(${talent.id})`],
58
- };
59
- }
60
- if (action === '改岗位') {
61
- const member = runtime.service.state.members?.[target];
62
- if (member?.kind !== 'agent' || member.status === 'retired') fail(ERRORS.NOT_FOUND, '同一项目中找不到这位在队成员。');
63
- if (member.role === value) fail(ERRORS.INVALID_ARGUMENT, '该成员已经是这个岗位。');
64
- return {
65
- type: 'member.profile.update', payload: { memberId: target, role: value, reason },
66
- lines: [`岗位 ${memberLabel(member)} 从「${member.role || '未设置'}」改为「${value}」`],
67
- };
68
- }
69
- const payload = { memberId: target, ...(value ? { successorId: value } : {}), reason };
70
- const { member, successor, unfinished } = runtime.service.describeMemberDeparture(runtime.id, payload, { reviewed: true });
71
- return {
72
- type: 'member.leave', payload,
73
- lines: [
74
- `离队 ${memberLabel(member)}进入人才池`,
75
- ...(successor === null ? [] : [`接手人 ${memberLabel(successor)}`]),
76
- ...(unfinished.length === 0 ? ['该成员没有未收口任务。'] : unfinished.map((task) => `- #${task.number} ${task.title}(${task.status})`)),
77
- ],
78
- taskRevisions: unfinished.map(({ id, revision }) => [id, revision]),
79
- };
80
- }
81
-
82
- export function createSessionRoster({ runtimes, isAvailable, catalog, actor, disposeMemberActivation }) {
83
- return async function prepareRoster({ action, argument, workspacePath }) {
84
- if (action === '人才') {
85
- const query = argument.trim().toLowerCase();
86
- const talents = listTalents(catalog()).filter((talent) => [talent.id, talent.name, talent.role].some((value) => value.toLowerCase().includes(query)));
87
- return { text: talents.length === 0 ? '没有匹配的人才。' : talents.map((talent) => `- ${talent.id} · ${talent.name} · ${talent.role}`).join('\n') };
88
- }
89
- const [, projectId, target, value = ''] = /^(\S+)(?:\s+(\S+))?(?:\s+([\s\S]+))?$/.exec(argument.trim()) ?? [];
90
- const wrongTarget = action === '编制' ? target !== undefined : target === undefined;
91
- if (wrongTarget || (action === '增员' && value !== '') || (action === '改岗位' && value === '')
92
- || (action === '离队' && /\s/.test(value))) {
93
- fail(ERRORS.INVALID_ARGUMENT, `用 ${USAGE[action]}。`);
94
- }
95
- const options = [];
96
- for (const runtime of await runtimes()) {
97
- const project = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
98
- if (project !== null) options.push({ runtime, project });
99
- }
100
- if (projectId === undefined && options.length > 1) {
101
- return { text: ['同一工作区有多个项目,请使用 /ai-team 编制 项目ID。', ...options.map(({ project }) => `- ${project.id} · ${project.name}`)].join('\n') };
102
- }
103
- const selection = projectId === undefined ? options[0] : options.find(({ project }) => project.id === projectId);
104
- if (!selection) fail(ERRORS.NOT_FOUND, '当前会话的工作区找不到该项目。使用 /ai-team 编制 查看同一工作区的项目。');
105
- const { runtime, project } = selection;
106
- if (action === '编制') return { text: describeRoster(runtime, project) };
107
-
108
- const change = planChange(runtime, action, target, value, catalog);
109
- const command = { type: change.type, payload: change.payload, actor, projectId };
110
- runtime.service.checkBlueprintCommand(command, change.payload);
111
- const approved = JSON.stringify(change);
112
- return {
113
- projectId, action,
114
- lines: [`编制草稿 ${project.name}(${projectId})`, ...change.lines],
115
- async apply(draftId) {
116
- const result = await runtime.service.dispatch({
117
- ...command, correlationId: draftId,
118
- verifyDraft() {
119
- const currentProject = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
120
- if (!currentProject || currentProject.name !== project.name) {
121
- fail(ERRORS.REVISION, '项目或工作目录已变化,请重新生成草稿。');
122
- }
123
- let current;
124
- try {
125
- current = planChange(runtime, action, target, value, catalog);
126
- } catch (error) {
127
- if (error instanceof DomainError) fail(ERRORS.REVISION, `${error.message} 请核对编制后重新生成草稿。`);
128
- throw error;
129
- }
130
- if (JSON.stringify(current) !== approved) fail(ERRORS.REVISION, '成员、人才或任务已变化,请重新生成草稿。');
131
- },
132
- });
133
- if (action === '离队') {
134
- await disposeMemberActivation(runtime, target, command.type);
135
- return `已将${memberLabel(result.member)}移入人才池,交接了 ${result.transferredTasks?.length ?? 0} 张原任务。`;
136
- }
137
- return action === '增员' ? `已添加${memberLabel(result.member)}。` : `已将${memberLabel(result.member)}的岗位更新为「${result.member.role}」。`;
138
- },
139
- };
140
- };
141
- }
1
+ import { realpathSync } from 'node:fs';
2
+ import { isAbsolute } from 'node:path';
3
+ import { listTalents } from '../domain/catalog.js';
4
+ import { DomainError, ERRORS, fail } from '../domain/errors.js';
5
+ import { unfinishedTasksFor } from '../domain/member-profile.js';
6
+
7
+ const USAGE = {
8
+ 编制: '/ai-team 编制 [项目ID]',
9
+ 调整: '/ai-team 调整 [项目ID] 一句话',
10
+ 人才: '/ai-team 人才 [关键词]',
11
+ 增员: '/ai-team 增员 项目ID 人才ID',
12
+ 改岗位: '/ai-team 改岗位 项目ID 成员ID 新岗位',
13
+ 离队: '/ai-team 离队 项目ID 成员ID [接手人ID]',
14
+ };
15
+
16
+ export const rosterHelp = Object.values(USAGE).join('\n');
17
+ export const isRosterAction = (action) => Object.hasOwn(USAGE, action);
18
+
19
+ function workspaceProject(runtime, workspacePath) {
20
+ const project = runtime.service.state.projects?.[runtime.id];
21
+ if (!project || project.status === 'archived' || typeof project.workspacePath !== 'string' || !isAbsolute(project.workspacePath)) return null;
22
+ try {
23
+ return realpathSync(project.workspacePath) === workspacePath ? project : null;
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+
29
+ const memberLabel = (member) => `${member.name}(${member.id})`;
30
+
31
+ function resolveName(entries, value, label, aliases = (entry) => [entry.name]) {
32
+ const name = value.trim();
33
+ const direct = entries.find(({ id }) => id === name);
34
+ if (direct) return direct.id;
35
+ const matches = entries.filter((entry) => aliases(entry).includes(name));
36
+ if (matches.length === 1) return matches[0].id;
37
+ if (matches.length === 0) fail(ERRORS.NOT_FOUND, `找不到${label}「${name}」,请核对名字或编号。`);
38
+ fail(ERRORS.CONFLICT, `${label}「${name}」有多个候选,请使用编号。\n${matches.map(memberLabel).join('\n')}`);
39
+ }
40
+
41
+ function readRosterSentence(sentence, runtime, catalog) {
42
+ const statement = sentence.trim().replace(/[。!!.]$/u, '');
43
+ const hint = '一句话只能准备一项调整。示例:给团队加一位文案;把校书的岗位改为文档协调;让墨痕把任务交给校书后离队。';
44
+ if (/[。;;\r\n]|(?:并|同时|然后)\s*(?:给|把|让|再|加|离队|改)/u.test(statement)) fail(ERRORS.INVALID_ARGUMENT, hint);
45
+ const hire = /^给团队加(?:一位|一名)\s*(.+)$/u.exec(statement);
46
+ if (hire) {
47
+ const target = resolveName(listTalents(catalog()), hire[1], '人才', ({ name, role }) => [name, role]);
48
+ return { action: '增员', target, value: '' };
49
+ }
50
+ const members = Object.values(runtime.service.state.members ?? {}).filter(({ kind, status }) => kind === 'agent' && status !== 'retired');
51
+ const findMember = (name) => resolveName(members, name, '成员');
52
+ const edit = /^把(.+?)的岗位改为\s*(.+)$/u.exec(statement);
53
+ if (edit) return { action: '改岗位', target: findMember(edit[1]), value: edit[2].trim() };
54
+ const handoff = /^让(.+?)把任务交给(.+?)后离队$/u.exec(statement);
55
+ if (handoff) return { action: '离队', target: findMember(handoff[1]), value: findMember(handoff[2]) };
56
+ const leave = /^让(.+?)离队$/u.exec(statement);
57
+ if (leave) return { action: '离队', target: findMember(leave[1]), value: '' };
58
+ fail(ERRORS.INVALID_ARGUMENT, hint);
59
+ }
60
+
61
+ function describeRoster(runtime, project) {
62
+ const state = runtime.service.state;
63
+ const members = Object.values(state.members ?? {}).filter((member) => member.kind === 'agent');
64
+ return [
65
+ `「${project.name}」的编制(${project.id})`,
66
+ ...members.map((member) => {
67
+ const unfinished = unfinishedTasksFor(state, member.id).length;
68
+ const role = member.role ? ` · ${member.role}` : '';
69
+ const departed = member.status === 'retired' ? ' · 已离队' : '';
70
+ return `- ${memberLabel(member)}${role}${departed} · ${unfinished} 张未收口任务`;
71
+ }),
72
+ '使用 /ai-team 人才查看可选人才。',
73
+ ].join('\n');
74
+ }
75
+
76
+ function planChange(runtime, action, target, value, catalog) {
77
+ const reason = '会话编制草稿确认';
78
+ if (action === '增员') {
79
+ const talent = catalog().talents.get(target);
80
+ if (!talent) fail(ERRORS.NOT_FOUND, '人才库中找不到该人才。使用 /ai-team 人才 查看可选人才。');
81
+ return {
82
+ type: 'member.add',
83
+ payload: {
84
+ name: talent.name, role: talent.role, duty: talent.duty,
85
+ personality: talent.personality, skills: talent.skills, avatar: talent.avatar,
86
+ talent: talent.id, talentVersion: talent.version,
87
+ },
88
+ lines: [`增员 ${talent.name} · ${talent.role}(${talent.id})`],
89
+ };
90
+ }
91
+ if (action === '改岗位') {
92
+ const member = runtime.service.state.members?.[target];
93
+ if (member?.kind !== 'agent' || member.status === 'retired') fail(ERRORS.NOT_FOUND, '同一项目中找不到这位在队成员。');
94
+ if (member.role === value) fail(ERRORS.INVALID_ARGUMENT, '该成员已经是这个岗位。');
95
+ return {
96
+ type: 'member.profile.update', payload: { memberId: target, role: value, reason },
97
+ lines: [`岗位 ${memberLabel(member)} 从「${member.role || '未设置'}」改为「${value}」`],
98
+ };
99
+ }
100
+ const payload = { memberId: target, ...(value ? { successorId: value } : {}), reason };
101
+ const { member, successor, unfinished } = runtime.service.describeMemberDeparture(runtime.id, payload, { reviewed: true });
102
+ return {
103
+ type: 'member.leave', payload,
104
+ lines: [
105
+ `离队 ${memberLabel(member)}进入人才池`,
106
+ ...(successor === null ? [] : [`接手人 ${memberLabel(successor)}`]),
107
+ ...(unfinished.length === 0 ? ['该成员没有未收口任务。'] : unfinished.map((task) => `- #${task.number} ${task.title}(${task.status})`)),
108
+ ],
109
+ taskRevisions: unfinished.map(({ id, revision }) => [id, revision]),
110
+ };
111
+ }
112
+
113
+ export function createSessionRoster({ runtimes, isAvailable, catalog, actor, disposeMemberActivation }) {
114
+ return async function prepareRoster({ action: requested, argument, workspacePath }) {
115
+ if (requested === '人才') {
116
+ const query = argument.trim().toLowerCase();
117
+ const talents = listTalents(catalog()).filter((talent) => [talent.id, talent.name, talent.role].some((value) => value.toLowerCase().includes(query)));
118
+ return { text: talents.length === 0 ? '没有匹配的人才。' : talents.map((talent) => `- ${talent.id} · ${talent.name} · ${talent.role}`).join('\n') };
119
+ }
120
+ const input = argument.trim();
121
+ const [, first, supplied, rest = ''] = /^(\S+)(?:\s+(\S+))?(?:\s+([\s\S]+))?$/.exec(input) ?? [];
122
+ const requestedSentence = requested === '调整';
123
+ const requestedProject = requestedSentence && !first?.startsWith('prj_') ? undefined : first;
124
+ if (!requestedSentence) {
125
+ const wrongTarget = requested === '编制' ? supplied !== undefined : supplied === undefined;
126
+ if (wrongTarget || (requested === '增员' && rest !== '') || (requested === '改岗位' && rest === '')
127
+ || (requested === '离队' && /\s/.test(rest))) fail(ERRORS.INVALID_ARGUMENT, `用 ${USAGE[requested]}。`);
128
+ }
129
+ const options = [];
130
+ for (const runtime of await runtimes()) {
131
+ const project = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
132
+ if (project !== null) options.push({ runtime, project });
133
+ }
134
+ if (requestedProject === undefined && options.length > 1) {
135
+ const usage = requestedSentence ? '/ai-team 调整 项目ID 一句话' : '/ai-team 编制 项目ID';
136
+ return { text: [`同一工作区有多个项目,请使用 ${usage}。`, ...options.map(({ project }) => `- ${project.id} · ${project.name}`)].join('\n') };
137
+ }
138
+ const selection = requestedProject === undefined ? options[0] : options.find(({ project }) => project.id === requestedProject);
139
+ if (!selection) fail(ERRORS.NOT_FOUND, '当前会话的工作区找不到该项目。使用 /ai-team 编制 查看同一工作区的项目。');
140
+ const { runtime, project } = selection;
141
+ if (requested === '编制') return { text: describeRoster(runtime, project) };
142
+ const { action, target, value } = requestedSentence
143
+ ? readRosterSentence(requestedProject ? input.slice(first.length) : input, runtime, catalog)
144
+ : { action: requested, target: supplied, value: rest };
145
+ const projectId = project.id;
146
+
147
+ const change = planChange(runtime, action, target, value, catalog);
148
+ const command = { type: change.type, payload: change.payload, actor, projectId };
149
+ runtime.service.checkBlueprintCommand(command, change.payload);
150
+ const approved = JSON.stringify(change);
151
+ return {
152
+ projectId, action,
153
+ lines: [`编制草稿 ${project.name}(${projectId})`, ...change.lines],
154
+ async apply(draftId) {
155
+ const result = await runtime.service.dispatch({
156
+ ...command, correlationId: draftId,
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
+ },
171
+ });
172
+ if (action === '离队') {
173
+ await disposeMemberActivation(runtime, target, command.type);
174
+ return `已将${memberLabel(result.member)}移入人才池,交接了 ${result.transferredTasks?.length ?? 0} 张原任务。`;
175
+ }
176
+ return action === '增员' ? `已添加${memberLabel(result.member)}。` : `已将${memberLabel(result.member)}的岗位更新为「${result.member.role}」。`;
177
+ },
178
+ };
179
+ };
180
+ }
@@ -5,7 +5,7 @@ import { ids, newId } from '../domain/ids.js';
5
5
  import { isRosterAction, rosterHelp } from './session-roster.js';
6
6
  import { requireWorkspaceDirectory } from './workspace-path.js';
7
7
 
8
- const HELP = `用 /ai-team 建队 目标 生成草稿。可在目标前加 --team 预设ID。按草稿中的命令确认或取消。\n${rosterHelp}`;
8
+ const HELP = `用 /ai-team 建队 目标 生成草稿。可在目标前加 --team 预设ID 或 --recommend。按草稿中的命令确认或取消。\n${rosterHelp}`;
9
9
 
10
10
  function sessionWorkspace(session) {
11
11
  const path = session?.header?.cwd;
@@ -31,7 +31,7 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
31
31
  return {
32
32
  name: 'ai-team',
33
33
  description: '在会话里建队和调整文渊阁编制',
34
- input: { hint: '建队 / 编制 / 人才 / 增员 / 改岗位 / 离队 / 确认 / 取消' },
34
+ input: { hint: '建队 / 编制 / 调整 / 人才 / 增员 / 改岗位 / 离队 / 确认 / 取消' },
35
35
  async handler({ agent, rawInput, signal }) {
36
36
  const session = agent?.session;
37
37
  const [, action, argument = ''] = /^(\S+)(?:\s+([\s\S]*))?$/.exec(rawInput.trim()) ?? [];
@@ -48,9 +48,10 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
48
48
  }
49
49
  if (action === '建队') {
50
50
  const selected = /^--team\s+(\S+)\s+([\s\S]+)$/.exec(argument);
51
- const goal = (selected?.[2] ?? argument).trim();
51
+ const recommend = /^--recommend(?:\s|$)/.test(argument);
52
+ const goal = (recommend ? argument.slice('--recommend'.length) : selected?.[2] ?? argument).trim();
52
53
  if (goal === '' || (!selected && argument.startsWith('--team'))) return { kind: 'error', text: HELP };
53
- const input = { name: goal.split(/\r?\n/, 1)[0], goal, workspacePath, team: selected?.[1] ?? '' };
54
+ const input = { name: goal.split(/\r?\n/, 1)[0], goal, workspacePath, team: selected?.[1] ?? '', recommend };
54
55
  const proposed = prepare(input);
55
56
  const id = ids.project();
56
57
  const signature = presetSignature(proposed.teamPreset);
@@ -62,11 +63,18 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
62
63
  `目标 ${goal}`,
63
64
  `工作目录 ${workspacePath}`,
64
65
  `预设 ${proposed.teamPreset.team.name}(${proposed.teamPreset.id})`,
66
+ ...(proposed.matchedTerms ? [`匹配依据 ${proposed.matchedTerms.join('、')}`] : []),
65
67
  ...proposed.teamPreset.team.members.map((member) => `- ${member.name} · ${member.role}`),
66
68
  '确认后创建项目,PMO 自动为关闭状态。',
67
69
  ],
68
70
  async apply() {
69
- const approved = prepare(input);
71
+ let approved;
72
+ try {
73
+ approved = prepare(input);
74
+ } catch (error) {
75
+ if (error instanceof DomainError) fail(ERRORS.REVISION, '团队预设已更新,请重新生成草稿后再确认。');
76
+ throw error;
77
+ }
70
78
  if (presetSignature(approved.teamPreset) !== signature) {
71
79
  fail(ERRORS.REVISION, '团队预设已更新,请重新生成草稿后再确认。');
72
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.156",
3
+ "version": "0.4.157",
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",