@suifei/dsh-ai-team 0.4.123 → 0.4.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +19 -6
  3. package/client.js +179 -12
  4. package/index.js +31 -2
  5. package/lib/domain/catalog.js +229 -0
  6. package/lib/host/default-roster.js +124 -143
  7. package/lib/host/project-runtime.js +2 -2
  8. package/lib/host/service.js +17 -0
  9. package/lib/ledger/fold.js +6 -0
  10. package/lib/runtime/core-skill.js +16 -22
  11. package/lib/runtime/skill-loader.js +4 -2
  12. package/package.json +5 -2
  13. package/talents/algo-reimplementer/skills/reimplementation/SKILL.md +14 -0
  14. package/talents/algo-reimplementer/talent.yml +9 -0
  15. package/talents/analyst/skills/analysis-synthesis/SKILL.md +14 -0
  16. package/talents/analyst/talent.yml +9 -0
  17. package/talents/architect/skills/architecture-design/SKILL.md +14 -0
  18. package/talents/architect/talent.yml +9 -0
  19. package/talents/binary-analyst/skills/static-analysis/SKILL.md +14 -0
  20. package/talents/binary-analyst/talent.yml +9 -0
  21. package/talents/biz-analyst/skills/business-analysis/SKILL.md +14 -0
  22. package/talents/biz-analyst/talent.yml +9 -0
  23. package/talents/code-reviewer/skills/code-review/SKILL.md +14 -0
  24. package/talents/code-reviewer/talent.yml +9 -0
  25. package/talents/content-author/skills/question-authoring/SKILL.md +14 -0
  26. package/talents/content-author/talent.yml +9 -0
  27. package/talents/content-strategist/talent.yml +8 -0
  28. package/talents/copywriter/skills/copywriting/SKILL.md +14 -0
  29. package/talents/copywriter/talent.yml +9 -0
  30. package/talents/creative-director/talent.yml +8 -0
  31. package/talents/curriculum-designer/skills/curriculum-design/SKILL.md +14 -0
  32. package/talents/curriculum-designer/talent.yml +9 -0
  33. package/talents/data-analyst/skills/statistics/SKILL.md +14 -0
  34. package/talents/data-analyst/talent.yml +9 -0
  35. package/talents/deobfuscator/skills/deobfuscation/SKILL.md +14 -0
  36. package/talents/deobfuscator/talent.yml +9 -0
  37. package/talents/diagrammer/skills/diagramming/SKILL.md +14 -0
  38. package/talents/diagrammer/talent.yml +9 -0
  39. package/talents/dynamic-debugger/skills/dynamic-debugging/SKILL.md +14 -0
  40. package/talents/dynamic-debugger/talent.yml +9 -0
  41. package/talents/editor/skills/copyediting/SKILL.md +14 -0
  42. package/talents/editor/talent.yml +9 -0
  43. package/talents/editorial-lead/talent.yml +8 -0
  44. package/talents/education-lead/talent.yml +8 -0
  45. package/talents/engineer/skills/engineering/SKILL.md +15 -0
  46. package/talents/engineer/talent.yml +9 -0
  47. package/talents/executor/skills/delivery-checklist/SKILL.md +15 -0
  48. package/talents/executor/talent.yml +9 -0
  49. package/talents/experiment-designer/skills/experiment-design/SKILL.md +14 -0
  50. package/talents/experiment-designer/talent.yml +9 -0
  51. package/talents/fact-checker/skills/fact-check/SKILL.md +14 -0
  52. package/talents/fact-checker/talent.yml +9 -0
  53. package/talents/game-artist/skills/game-art/SKILL.md +14 -0
  54. package/talents/game-artist/talent.yml +9 -0
  55. package/talents/game-designer/skills/game-design/SKILL.md +14 -0
  56. package/talents/game-designer/talent.yml +9 -0
  57. package/talents/game-director/talent.yml +8 -0
  58. package/talents/game-tester/skills/playtesting/SKILL.md +14 -0
  59. package/talents/game-tester/talent.yml +9 -0
  60. package/talents/gameplay-programmer/skills/gameplay-programming/SKILL.md +14 -0
  61. package/talents/gameplay-programmer/talent.yml +9 -0
  62. package/talents/mobile-re/skills/mobile-re/SKILL.md +14 -0
  63. package/talents/mobile-re/talent.yml +9 -0
  64. package/talents/paper-writer/skills/paper-writing/SKILL.md +14 -0
  65. package/talents/paper-writer/talent.yml +9 -0
  66. package/talents/peer-reviewer/skills/peer-review/SKILL.md +14 -0
  67. package/talents/peer-reviewer/talent.yml +9 -0
  68. package/talents/pmo-lead/talent.yml +8 -0
  69. package/talents/principal-investigator/talent.yml +8 -0
  70. package/talents/qa-acceptor/skills/acceptance-testing/SKILL.md +14 -0
  71. package/talents/qa-acceptor/talent.yml +9 -0
  72. package/talents/re-lead/talent.yml +8 -0
  73. package/talents/re-verifier/skills/behavior-diff/SKILL.md +14 -0
  74. package/talents/re-verifier/talent.yml +9 -0
  75. package/talents/research-lead/talent.yml +8 -0
  76. package/talents/researcher/skills/source-research/SKILL.md +14 -0
  77. package/talents/researcher/talent.yml +9 -0
  78. package/talents/scriptwriter/skills/scriptwriting/SKILL.md +14 -0
  79. package/talents/scriptwriter/talent.yml +9 -0
  80. package/talents/security-auditor/skills/security-audit/SKILL.md +14 -0
  81. package/talents/security-auditor/talent.yml +9 -0
  82. package/talents/seo-specialist/skills/seo/SKILL.md +14 -0
  83. package/talents/seo-specialist/talent.yml +9 -0
  84. package/talents/storyboard-artist/skills/storyboarding/SKILL.md +14 -0
  85. package/talents/storyboard-artist/talent.yml +9 -0
  86. package/talents/tech-writer/skills/technical-writing/SKILL.md +14 -0
  87. package/talents/tech-writer/talent.yml +9 -0
  88. package/talents/ux-designer/skills/ux-research/SKILL.md +14 -0
  89. package/talents/ux-designer/talent.yml +9 -0
  90. package/talents/video-editor/skills/video-editing/SKILL.md +14 -0
  91. package/talents/video-editor/talent.yml +9 -0
  92. package/teams/content/team.yml +12 -0
  93. package/teams/default/team.yml +35 -0
  94. package/teams/docs/team.yml +12 -0
  95. package/teams/education/team.yml +13 -0
  96. package/teams/game/team.yml +12 -0
  97. package/teams/research/team.yml +11 -0
  98. package/teams/reverse/team.yml +17 -0
  99. package/teams/science/team.yml +12 -0
  100. package/teams/video/team.yml +12 -0
  101. /package/{skills → teams/default/skills}/ai-team-core/SKILL.md +0 -0
  102. /package/{skills → teams/default/skills}/ai-team-executor/SKILL.md +0 -0
  103. /package/{skills → teams/default/skills}/ai-team-qa/SKILL.md +0 -0
@@ -0,0 +1,229 @@
1
+ /**
2
+ * 人才市场目录:人才 → 团队 → 项目成员。
3
+ *
4
+ * talents/<人才>/talent.yml 一个能干特定事的智能体:职责、性格、技能、推荐模型
5
+ * talents/<人才>/skills/<技能>/SKILL.md 人才自带的技能
6
+ * teams/<团队>/team.yml 从人才里挑人组队(只引用人才),选团队的岗位规程
7
+ * teams/<团队>/skills/<规程>/SKILL.md 团队的工作方式(主理人 / 验收 / 执行三份岗位规程)
8
+ *
9
+ * 同一格式有多处来源,按顺序覆盖(同名先到先得):用户自建 `~/.dsh/ai-team/catalog/user/`
10
+ * → (第 3 步)官方在线库 → 插件内置。招进项目的成员是账本里的实例,记下来源人才与版本;
11
+ * 人才文件之后再变,不会悄悄改动已招成员的性格与职责。
12
+ * 文件写坏不阻断:记一行 `.fail` 诊断,跳过它(更低优先级的同名条目顶上)。
13
+ */
14
+
15
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
16
+ import { join } from 'node:path';
17
+ import { fileURLToPath } from 'node:url';
18
+ import { parse } from 'yaml';
19
+
20
+ /** 插件内置目录(包根,下有 talents/ 与 teams/)。 */
21
+ export const BUNDLED_CATALOG_DIR = fileURLToPath(new URL('../../', import.meta.url));
22
+ export const DEFAULT_TEAM = 'default';
23
+ /** 三种职责,各对应一份岗位规程。 */
24
+ export const DUTIES = Object.freeze(['lead', 'qa', 'executor']);
25
+ export const DEFAULT_PROCEDURES = Object.freeze({ lead: 'ai-team-core', qa: 'ai-team-qa', executor: 'ai-team-executor' });
26
+
27
+ const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
28
+ const MEMBER_ID = /^mem_[a-z0-9_]{1,60}$/;
29
+ const SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
30
+ const VERSION = /^\d+\.\d+\.\d+$/;
31
+ const text = (value, max) => (typeof value === 'string' ? value.trim().slice(0, max) : '');
32
+
33
+ function readYaml(source, label) {
34
+ let doc;
35
+ try {
36
+ doc = parse(source);
37
+ } catch (error) {
38
+ throw new Error(`${label}: YAML 解析失败:${error.message}`);
39
+ }
40
+ if (doc === null || typeof doc !== 'object' || Array.isArray(doc)) throw new Error(`${label}: 顶层必须是对象`);
41
+ return doc;
42
+ }
43
+
44
+ function skillName(value, at) {
45
+ const name = text(value, 64);
46
+ if (!SKILL_NAME.test(name) || name.includes('..')) throw new Error(`${at} 不是合法的技能名:${String(value)}`);
47
+ return name;
48
+ }
49
+
50
+ function skillList(value, at) {
51
+ if (value === undefined || value === null) return [];
52
+ if (!Array.isArray(value)) throw new Error(`${at} 必须是列表`);
53
+ return [...new Set(value.map((skill, i) => skillName(skill, `${at}[${i}]`)))];
54
+ }
55
+
56
+ function duty(value, at) {
57
+ if (value === undefined || value === null) return null;
58
+ if (!DUTIES.includes(value)) throw new Error(`${at} 只认 ${DUTIES.join(' / ')}`);
59
+ return value;
60
+ }
61
+
62
+ /**
63
+ * talent.yml → 规范化人才;不合法抛错(说明哪一处)。
64
+ * @param {string} source
65
+ * @param {string} [label]
66
+ */
67
+ export function parseTalent(source, label = 'talent') {
68
+ const doc = readYaml(source, label);
69
+ const name = text(doc.name, 40);
70
+ const role = text(doc.role, 40);
71
+ if (name === '') throw new Error(`${label}: name 不能为空`);
72
+ if (role === '') throw new Error(`${label}: role 不能为空`);
73
+ const version = doc.version === undefined ? '1.0.0' : text(String(doc.version), 32);
74
+ if (!VERSION.test(version)) throw new Error(`${label}: version 必须形如 1.2.3`);
75
+ if (doc.tags !== undefined && !Array.isArray(doc.tags)) throw new Error(`${label}: tags 必须是列表`);
76
+ let model = null;
77
+ if (doc.model !== undefined && doc.model !== null) {
78
+ if (typeof doc.model !== 'object' || Array.isArray(doc.model)) throw new Error(`${label}: model 必须是对象(provider / model / reasoningEffort)`);
79
+ model = {
80
+ provider: text(doc.model.provider, 80),
81
+ model: text(doc.model.model, 160),
82
+ reasoningEffort: text(doc.model.reasoningEffort, 20),
83
+ };
84
+ }
85
+ return {
86
+ version,
87
+ name,
88
+ role,
89
+ duty: duty(doc.duty, `${label}: duty`),
90
+ category: text(doc.category, 20),
91
+ tags: (doc.tags ?? []).map((tag) => text(String(tag), 20)).filter(Boolean).slice(0, 12),
92
+ description: text(doc.description, 400),
93
+ personality: text(doc.personality, 2000),
94
+ skills: skillList(doc.skills, `${label}: skills`),
95
+ model,
96
+ };
97
+ }
98
+
99
+ /**
100
+ * team.yml → 规范化团队(成员仍是对人才的引用,见 resolveTeam);不合法抛错。
101
+ * @param {string} source
102
+ * @param {string} [label]
103
+ */
104
+ export function parseTeam(source, label = 'team') {
105
+ const doc = readYaml(source, label);
106
+ if (!Array.isArray(doc.members) || doc.members.length === 0) throw new Error(`${label}: members 至少要有一位成员`);
107
+ const procedures = { ...DEFAULT_PROCEDURES };
108
+ if (doc.procedures !== undefined && doc.procedures !== null) {
109
+ if (typeof doc.procedures !== 'object' || Array.isArray(doc.procedures)) throw new Error(`${label}: procedures 必须是对象`);
110
+ for (const [kind, name] of Object.entries(doc.procedures)) {
111
+ if (!DUTIES.includes(kind)) throw new Error(`${label}: procedures.${kind} 不是职责(只认 ${DUTIES.join(' / ')})`);
112
+ procedures[kind] = skillName(name, `${label}: procedures.${kind}`);
113
+ }
114
+ }
115
+ const ids = new Set();
116
+ const members = doc.members.map((raw, index) => {
117
+ const at = `${label}: members[${index}]`;
118
+ if (raw === null || typeof raw !== 'object') throw new Error(`${at} 必须是对象`);
119
+ const talent = text(raw.talent, 64);
120
+ if (!SLUG.test(talent)) throw new Error(`${at}.talent 必须是人才 id(小写字母、数字、连字符)`);
121
+ const id = raw.id === undefined ? `mem_${talent.replace(/-/g, '_')}` : text(raw.id, 64);
122
+ if (!MEMBER_ID.test(id)) throw new Error(`${at}.id 必须形如 mem_xxx(小写字母、数字、下划线)`);
123
+ if (ids.has(id)) throw new Error(`${at}.id 重复:${id}(同一人才招两位时给每位写 id)`);
124
+ ids.add(id);
125
+ return {
126
+ id,
127
+ talent,
128
+ name: text(raw.name, 40),
129
+ role: text(raw.role, 40),
130
+ duty: duty(raw.duty, `${at}.duty`),
131
+ personality: text(raw.personality, 2000),
132
+ skills: skillList(raw.skills, `${at}.skills`),
133
+ };
134
+ });
135
+ const lead = doc.lead === undefined || doc.lead === null ? members[0].id : text(doc.lead, 64);
136
+ if (!ids.has(lead)) throw new Error(`${label}: lead「${lead}」不在 members 的 id 里`);
137
+ return { name: text(doc.name, 60), description: text(doc.description, 400), lead, procedures, members };
138
+ }
139
+
140
+ /** 用户自建目录 + 插件内置目录(第 3 步在两者之间插入官方在线库)。 */
141
+ export function catalogRoots({ dshHome, bundledDir = BUNDLED_CATALOG_DIR } = {}) {
142
+ return [
143
+ ...(typeof dshHome === 'string' && dshHome !== '' ? [{ source: 'user', dir: join(dshHome, 'ai-team', 'catalog', 'user') }] : []),
144
+ { source: 'bundled', dir: bundledDir },
145
+ ];
146
+ }
147
+
148
+ function scan(roots, kind, file, parser, diag) {
149
+ const found = new Map();
150
+ for (const { source, dir } of roots) {
151
+ const base = join(dir, kind);
152
+ if (!existsSync(base)) continue;
153
+ for (const id of readdirSync(base)) {
154
+ if (!SLUG.test(id) || found.has(id)) continue;
155
+ const path = join(base, id, file);
156
+ if (!existsSync(path)) continue;
157
+ try {
158
+ found.set(id, { id, source, dir: join(base, id), ...parser(readFileSync(path, 'utf8'), path) });
159
+ } catch (error) {
160
+ diag?.append?.({ ev: 'catalog.load.fail', kind, id, source, message: error.message });
161
+ }
162
+ }
163
+ }
164
+ return found;
165
+ }
166
+
167
+ /**
168
+ * 读出全部人才与团队(每次现读:改了文件不用重启)。
169
+ * @param {{ roots?: Array<{source: string, dir: string}>, diag?: { append?: (row: object) => void } }} [options]
170
+ */
171
+ export function loadCatalog({ roots = catalogRoots(), diag } = {}) {
172
+ return {
173
+ talents: scan(roots, 'talents', 'talent.yml', parseTalent, diag),
174
+ teams: scan(roots, 'teams', 'team.yml', parseTeam, diag),
175
+ };
176
+ }
177
+
178
+ /** 人才市场列表(给「添加成员」弹窗):按分类、名字排序。 */
179
+ export function listTalents(catalog) {
180
+ return [...catalog.talents.values()]
181
+ .map(({ id, source, version, name, role, duty: d, category, tags, description, personality, skills, model }) => ({ id, source, version, name, role, duty: d, category, tags, description, personality, skills, model }))
182
+ .sort((a, b) => a.category.localeCompare(b.category, 'zh') || a.name.localeCompare(b.name, 'zh'));
183
+ }
184
+
185
+ /**
186
+ * 团队 → 可直接建成员的名单:每位成员按引用的人才补齐名字、岗位、职责、性格与技能
187
+ * (团队里写了的覆盖人才的)。团队缺失、写坏或引用了不存在的人才时退回默认团队并记 `.fail`。
188
+ * @returns {{ id: string, source: string, dir: string, team: { name: string, description: string, lead: string, procedures: Record<string, string>, members: object[] } }}
189
+ */
190
+ export function resolveTeam(catalog, name = DEFAULT_TEAM, { diag } = {}) {
191
+ const wanted = typeof name === 'string' && SLUG.test(name) ? name : DEFAULT_TEAM;
192
+ if (wanted !== name) diag?.append?.({ ev: 'catalog.team.fail', name, reason: 'invalid team name' });
193
+ const entry = catalog.teams.get(wanted);
194
+ try {
195
+ if (entry === undefined) throw new Error(`team ${wanted} not found`);
196
+ const members = entry.members.map((member) => {
197
+ const talent = catalog.talents.get(member.talent);
198
+ if (talent === undefined) throw new Error(`team ${wanted}: talent ${member.talent} not found`);
199
+ return {
200
+ id: member.id,
201
+ name: member.name || talent.name,
202
+ role: member.role || talent.role,
203
+ duty: member.duty ?? talent.duty,
204
+ personality: member.personality || talent.personality,
205
+ skills: [...new Set([...talent.skills, ...member.skills])],
206
+ talent: { id: talent.id, version: talent.version, source: talent.source },
207
+ model: talent.model,
208
+ };
209
+ });
210
+ return { id: wanted, source: entry.source, dir: entry.dir, team: { name: entry.name || wanted, description: entry.description, lead: entry.lead, procedures: entry.procedures, members } };
211
+ } catch (error) {
212
+ if (wanted === DEFAULT_TEAM) throw error; // 内置默认团队有测试守着;坏了说明安装包坏了。
213
+ diag?.append?.({ ev: 'catalog.team.fail', name: wanted, message: error.message });
214
+ return resolveTeam(catalog, DEFAULT_TEAM, { diag });
215
+ }
216
+ }
217
+
218
+ /**
219
+ * 某职责的岗位规程正文(含 front-matter,调用方负责剥掉):先找团队自己的 skills/,
220
+ * 团队没带就退回内置默认团队的同职责规程。
221
+ */
222
+ export function procedureText(preset, kind, { bundledDir = BUNDLED_CATALOG_DIR } = {}) {
223
+ const d = DUTIES.includes(kind) ? kind : 'executor';
224
+ const candidates = [];
225
+ if (preset?.dir) candidates.push(join(preset.dir, 'skills', preset.team?.procedures?.[d] ?? DEFAULT_PROCEDURES[d], 'SKILL.md'));
226
+ candidates.push(join(bundledDir, 'teams', DEFAULT_TEAM, 'skills', DEFAULT_PROCEDURES[d], 'SKILL.md'));
227
+ for (const file of candidates) if (existsSync(file)) return readFileSync(file, 'utf8');
228
+ throw new Error(`bundled procedure missing: ${candidates.at(-1)}`);
229
+ }
@@ -1,143 +1,124 @@
1
- /**
2
- * The initial 文渊阁 roster. These are real Members in the Project ledger, not
3
- * UI placeholders: the Human can rename/re-role/re-model them, and the Lead is
4
- * the default Project owner so a one-line Main-stream request can start work.
5
- *
6
- * Seeded only when a Project has no Agent member yet. Once a member exists the
7
- * user's roster is authoritative and boot never adds these people back.
8
- */
9
-
10
- export const DEFAULT_MEMBER_ROSTER = Object.freeze([
11
- {
12
- id: 'mem_lead',
13
- name: '墨渊',
14
- role: '主理人',
15
- personality: '先定义可验收的结果,再把方向拆成 Task;不替执行者写实现,只在关键时刻做决定。',
16
- },
17
- {
18
- id: 'mem_maker',
19
- name: '青岚',
20
- role: '执行',
21
- personality: '认领 Task 后直接推进,先交付可运行结果和证据再汇报;遇到阻塞先找 owner。',
22
- },
23
- {
24
- id: 'mem_check',
25
- name: '白砚',
26
- role: '验收',
27
- personality: '独立验收,只按结果定义和证据判断;不确定就退回,不与执行者共用 claim。',
28
- },
29
- {
30
- id: 'mem_coder',
31
- name: '玄策',
32
- role: '编程',
33
- personality: '负责实现与工程化落地;先读核心纪律,拆分可验证小步,实测证据优先;与 PMO、QA 协同,不抢执行者的 claim。',
34
- },
35
- {
36
- id: 'mem_ux',
37
- name: '知微',
38
- role: 'UX 设计',
39
- personality: '以用户体验为第一核心:研究目标产品的 UI/UE,从真实使用路径找摩擦点;每个改进意见都要落到可验证的交互设计与证据,不凭感觉改版。',
40
- },
41
- {
42
- id: 'mem_biz',
43
- name: '观澜',
44
- role: '业务',
45
- personality: '从运营/用户视角研究目标系统如何使用,洞察真实需求与使用场景;把需求转成可执行的 UX 改进意见,交 PMO 会议评审立项。',
46
- },
47
- ]);
48
-
49
- /** Names shipped by 0.3.9 and earlier; only these exact pins are migrated. */
50
- const LEGACY_DEFAULT_NAMES = Object.freeze({
51
- mem_lead: '沈舟',
52
- mem_maker: '林岚',
53
- mem_check: '顾清',
54
- });
55
-
56
- export const DEFAULT_LEAD_ID = 'mem_lead';
57
-
58
- function agentMembers(service) {
59
- return Object.values(service.state.members ?? {}).filter((member) => member.kind === 'agent');
60
- }
61
-
62
- async function upgradeLegacyDefaultNames(service, projectId, humanId) {
63
- const renamed = [];
64
- for (const [memberId, legacyName] of Object.entries(LEGACY_DEFAULT_NAMES)) {
65
- const member = service.state.members?.[memberId];
66
- if (member === undefined || member.kind !== 'agent' || member.name !== legacyName) continue;
67
- const next = DEFAULT_MEMBER_ROSTER.find((entry) => entry.id === memberId);
68
- if (next === undefined) continue;
69
- await service.dispatch({
70
- type: 'member.profile.update',
71
- actor: { kind: 'human', memberId: humanId },
72
- projectId,
73
- payload: { memberId, name: next.name, reason: 'rename legacy default roster' },
74
- });
75
- renamed.push(memberId);
76
- }
77
- return renamed;
78
- }
79
-
80
- /**
81
- * Add the default roster to an empty Project and make the Lead its owner.
82
- * On an existing roster, exact legacy default names are upgraded and any
83
- * still-missing core-role member (UX/业务) is appended; custom names, custom
84
- * roles and the user's own roster are never touched or duplicated.
85
- * @returns {Promise<{seeded: boolean, members: string[], renamed: string[]}>}
86
- */
87
- export async function seedDefaultRoster(service, projectId, { humanId = 'mem_human' } = {}) {
88
- if (agentMembers(service).length > 0) {
89
- const renamed = await upgradeLegacyDefaultNames(service, projectId, humanId);
90
- const added = [];
91
- const existingRoles = new Set(agentMembers(service).map((member) => member.role));
92
- const existingIds = new Set(Object.keys(service.state.members ?? {}));
93
- for (const member of DEFAULT_MEMBER_ROSTER) {
94
- if (existingIds.has(member.id)) continue;
95
- if (existingRoles.has(member.role)) continue;
96
- await service.dispatch({
97
- type: 'member.add',
98
- actor: { kind: 'human', memberId: humanId },
99
- projectId,
100
- payload: {
101
- id: member.id,
102
- name: member.name,
103
- role: member.role,
104
- personality: member.personality,
105
- kind: 'agent',
106
- status: 'idle',
107
- },
108
- });
109
- existingIds.add(member.id);
110
- existingRoles.add(member.role);
111
- added.push(member.id);
112
- }
113
- return { seeded: false, members: added, renamed };
114
- }
115
- const added = [];
116
- for (const member of DEFAULT_MEMBER_ROSTER) {
117
- await service.dispatch({
118
- type: 'member.add',
119
- actor: { kind: 'human', memberId: humanId },
120
- projectId,
121
- payload: {
122
- id: member.id,
123
- name: member.name,
124
- role: member.role,
125
- personality: member.personality,
126
- kind: 'agent',
127
- status: 'idle',
128
- },
129
- });
130
- added.push(member.id);
131
- }
132
- const project = service.state.projects?.[projectId];
133
- const owner = project?.ownerMemberId ?? project?.ownerId;
134
- if (owner === humanId || owner === undefined || owner === null) {
135
- await service.dispatch({
136
- type: 'project.owner.update',
137
- actor: { kind: 'human', memberId: humanId },
138
- projectId,
139
- payload: { ownerMemberId: DEFAULT_LEAD_ID, reason: 'seed default roster' },
140
- });
141
- }
142
- return { seeded: true, members: added, renamed: [] };
143
- }
1
+ /**
2
+ * The initial 文渊阁 roster. These are real Members in the Project ledger, not
3
+ * UI placeholders: the Human can rename/re-role/re-model them, and the Lead is
4
+ * the default Project owner so a one-line Main-stream request can start work.
5
+ *
6
+ * Seeded only when a Project has no Agent member yet. Once a member exists the
7
+ * user's roster is authoritative and boot never adds these people back.
8
+ *
9
+ * The roster itself is configuration: a team under `teams/` that picks talents from
10
+ * `talents/`, or a user team selected by the `teamPreset` setting (lib/domain/catalog.js).
11
+ */
12
+
13
+ import { loadCatalog, resolveTeam } from '../domain/catalog.js';
14
+
15
+ /** Names shipped by 0.3.9 and earlier; only these exact pins are migrated. */
16
+ const LEGACY_DEFAULT_NAMES = Object.freeze({
17
+ mem_lead: '沈舟',
18
+ mem_maker: '林岚',
19
+ mem_check: '顾清',
20
+ });
21
+
22
+ /** 成员记住来源团队、人才(含版本)、职责与技能:激活时按它们取岗位规程与技能(lib/runtime/skill-loader.js)。 */
23
+ function teamFields(preset, member) {
24
+ return {
25
+ team: preset.id,
26
+ talent: member.talent.id,
27
+ talentVersion: member.talent.version,
28
+ ...(member.duty ? { duty: member.duty } : {}),
29
+ ...(member.skills?.length > 0 ? { skills: member.skills } : {}),
30
+ };
31
+ }
32
+
33
+ function agentMembers(service) {
34
+ return Object.values(service.state.members ?? {}).filter((member) => member.kind === 'agent');
35
+ }
36
+
37
+ async function upgradeLegacyDefaultNames(service, projectId, humanId, roster) {
38
+ const renamed = [];
39
+ for (const [memberId, legacyName] of Object.entries(LEGACY_DEFAULT_NAMES)) {
40
+ const member = service.state.members?.[memberId];
41
+ if (member === undefined || member.kind !== 'agent' || member.name !== legacyName) continue;
42
+ const next = roster.find((entry) => entry.id === memberId);
43
+ if (next === undefined) continue;
44
+ await service.dispatch({
45
+ type: 'member.profile.update',
46
+ actor: { kind: 'human', memberId: humanId },
47
+ projectId,
48
+ payload: { memberId, name: next.name, reason: 'rename legacy default roster' },
49
+ });
50
+ renamed.push(memberId);
51
+ }
52
+ return renamed;
53
+ }
54
+
55
+ /**
56
+ * Add the team's roster to an empty Project and make its lead the owner.
57
+ * On an existing roster, exact legacy default names are upgraded and, for the bundled team, any
58
+ * still-missing core-role member (UX/业务) is appended; custom names, custom
59
+ * roles and the user's own roster are never touched or duplicated.
60
+ * @returns {Promise<{seeded: boolean, members: string[], renamed: string[]}>}
61
+ */
62
+ export async function seedDefaultRoster(service, projectId, { humanId = 'mem_human', preset = resolveTeam(loadCatalog()) } = {}) {
63
+ const { team } = preset;
64
+ const roster = team.members;
65
+ if (agentMembers(service).length > 0) {
66
+ const renamed = await upgradeLegacyDefaultNames(service, projectId, humanId, roster);
67
+ // 补缺岗只是老项目补齐 UX/业务 的迁移,只按内置团队做;用户团队只用于新项目,不改已有项目。
68
+ if (preset.source !== 'bundled') return { seeded: false, members: [], renamed };
69
+ const added = [];
70
+ const existingRoles = new Set(agentMembers(service).map((member) => member.role));
71
+ const existingIds = new Set(Object.keys(service.state.members ?? {}));
72
+ for (const member of roster) {
73
+ if (existingIds.has(member.id)) continue;
74
+ if (existingRoles.has(member.role)) continue;
75
+ await service.dispatch({
76
+ type: 'member.add',
77
+ actor: { kind: 'human', memberId: humanId },
78
+ projectId,
79
+ payload: {
80
+ id: member.id,
81
+ name: member.name,
82
+ role: member.role,
83
+ personality: member.personality,
84
+ ...teamFields(preset, member),
85
+ kind: 'agent',
86
+ status: 'idle',
87
+ },
88
+ });
89
+ existingIds.add(member.id);
90
+ existingRoles.add(member.role);
91
+ added.push(member.id);
92
+ }
93
+ return { seeded: false, members: added, renamed };
94
+ }
95
+ const added = [];
96
+ for (const member of roster) {
97
+ await service.dispatch({
98
+ type: 'member.add',
99
+ actor: { kind: 'human', memberId: humanId },
100
+ projectId,
101
+ payload: {
102
+ id: member.id,
103
+ name: member.name,
104
+ role: member.role,
105
+ personality: member.personality,
106
+ ...teamFields(preset, member),
107
+ kind: 'agent',
108
+ status: 'idle',
109
+ },
110
+ });
111
+ added.push(member.id);
112
+ }
113
+ const project = service.state.projects?.[projectId];
114
+ const owner = project?.ownerMemberId ?? project?.ownerId;
115
+ if (owner === humanId || owner === undefined || owner === null) {
116
+ await service.dispatch({
117
+ type: 'project.owner.update',
118
+ actor: { kind: 'human', memberId: humanId },
119
+ projectId,
120
+ payload: { ownerMemberId: team.lead, reason: 'seed default roster' },
121
+ });
122
+ }
123
+ return { seeded: true, members: added, renamed: [] };
124
+ }
@@ -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 }) {
29
+ static async open({ rootDir, projectId = DEFAULT_PROJECT_ID, now = undefined, seed = true, projectName = '我的项目', projectGoal = '把事交给团队', workspacePath = '', diag = null, pmoMaxRounds = undefined, teamPreset = null }) {
30
30
  const dir = join(rootDir, 'projects', projectId);
31
31
  mkdirSync(dir, { recursive: true });
32
32
  const ledger = openLedger({
@@ -90,7 +90,7 @@ export class ProjectRuntime {
90
90
  payload: { id: projectId, name: projectName, goal: projectGoal, workspacePath, seed: true },
91
91
  });
92
92
  }
93
- await seedDefaultRoster(service, projectId, { humanId: HUMAN_ID });
93
+ await seedDefaultRoster(service, projectId, { humanId: HUMAN_ID, ...(teamPreset ? { preset: teamPreset } : {}) });
94
94
  await service.backfillHumanMentions(state.projects?.[projectId]?.workspacePath ?? '');
95
95
  }
96
96
  return runtime;
@@ -191,6 +191,10 @@ export class TeamService {
191
191
  personality: m.personality ?? '',
192
192
  notes: m.notes ?? [],
193
193
  skills: m.skills ?? [],
194
+ team: m.team ?? null,
195
+ talent: m.talent ?? null,
196
+ talentVersion: m.talentVersion ?? null,
197
+ duty: m.duty ?? null,
194
198
  profileVersion: m.profileVersion ?? 1,
195
199
  distillVersion: m.distillVersion ?? 0,
196
200
  distilledAt: m.distilledAt ?? null,
@@ -738,6 +742,15 @@ export class TeamService {
738
742
  status,
739
743
  createdAt: this.now(),
740
744
  };
745
+ if (payload.duty !== undefined && payload.duty !== null && !['lead', 'qa', 'executor'].includes(payload.duty)) {
746
+ fail(ERRORS.INVALID_ARGUMENT, 'member duty must be one of lead, qa, executor');
747
+ }
748
+ // 从团队或人才市场建的成员带上来源团队、人才(含版本)、职责和技能(lib/domain/catalog.js)。
749
+ const ref = (value) => (typeof value === 'string' && value.trim() !== '' ? value.trim().slice(0, 64) : null);
750
+ const team = ref(payload.team);
751
+ const talent = ref(payload.talent);
752
+ const talentVersion = talent === null ? null : ref(payload.talentVersion);
753
+ const skills = Array.isArray(payload.skills) ? payload.skills.filter((name) => typeof name === 'string' && name.trim() !== '').map((name) => name.trim()) : [];
741
754
  await this.append(command, 'project/member-added', {
742
755
  memberId: member.id,
743
756
  name: member.name,
@@ -746,6 +759,10 @@ export class TeamService {
746
759
  personality: member.personality,
747
760
  status: member.status,
748
761
  projectId: payload.projectId,
762
+ ...(team !== null ? { team } : {}),
763
+ ...(talent !== null ? { talent, ...(talentVersion !== null ? { talentVersion } : {}) } : {}),
764
+ ...(payload.duty ? { duty: payload.duty } : {}),
765
+ ...(skills.length > 0 ? { skills } : {}),
749
766
  });
750
767
  return { member };
751
768
  }
@@ -206,6 +206,12 @@ function makeMember(payload, event, existing) {
206
206
  name: textOr(source.name, existing?.name ?? textOr(source.memberId, '')),
207
207
  kind,
208
208
  role: textOr(source.role, existing?.role ?? ''),
209
+ // 来自哪个团队、担什么职责(teams/<团队>/team.yml);老成员为 null,按岗位文字推断职责。
210
+ team: stringOrNull(source.team) ?? existing?.team ?? null,
211
+ // 招自人才市场的哪位人才、哪个版本(talents/<人才>/talent.yml)。
212
+ talent: stringOrNull(source.talent) ?? existing?.talent ?? null,
213
+ talentVersion: stringOrNull(source.talentVersion) ?? existing?.talentVersion ?? null,
214
+ duty: ['lead', 'qa', 'executor'].includes(source.duty) ? source.duty : existing?.duty ?? null,
209
215
  status,
210
216
  preset: stringOrNull(source.preset),
211
217
  model: stringOrNull(source.model),
@@ -1,8 +1,9 @@
1
- import { readFileSync } from 'node:fs';
2
1
  import { isQaMember, isReviewerMember } from '../domain/member-profile.js';
2
+ import { DUTIES, procedureText } from '../domain/catalog.js';
3
3
 
4
4
  /**
5
- * 内置技能按**身份**装配:主理人/PMO 拿审查与导航规程,验收拿复跑规程,其余拿执行规程。
5
+ * 岗位规程按**职责**装配:主理人/PMO 拿审查与导航规程,验收拿复跑规程,其余拿执行规程。
6
+ * 规程正文属于团队(`teams/<团队>/skills/`,见 lib/domain/catalog.js),这里只决定职责。
6
7
  *
7
8
  * 实机(2026-11-13):`ai-team-core` 被改写成第二人称的「你是本会话的审查与导航 PMO,
8
9
  * 只读,不写代码」,但它对**所有成员**注入——执行成员会收到「你不写代码」的指令。
@@ -11,41 +12,34 @@ import { isQaMember, isReviewerMember } from '../domain/member-profile.js';
11
12
 
12
13
  const LEAD_PATTERN = /主理人|项目负责人|PMO|lead|owner/i;
13
14
 
14
- function load(file) {
15
- return readFileSync(new URL(`../../skills/${file}/SKILL.md`, import.meta.url), 'utf8');
16
- }
17
-
18
- /** 主理人/PMO:只读审查与导航。 */
19
- export const CORE_SKILL_TEXT = load('ai-team-core');
20
- /** 执行成员:按 resultDefinition 交付。 */
21
- export const EXECUTOR_SKILL_TEXT = load('ai-team-executor');
22
- /** 验收成员:独立复跑判定。 */
23
- export const QA_SKILL_TEXT = load('ai-team-qa');
15
+ /** 内置默认团队的三份规程(含 front-matter)。 */
16
+ export const CORE_SKILL_TEXT = procedureText(null, 'lead');
17
+ export const EXECUTOR_SKILL_TEXT = procedureText(null, 'executor');
18
+ export const QA_SKILL_TEXT = procedureText(null, 'qa');
24
19
 
25
- export const SKILL_KINDS = Object.freeze(['lead', 'qa', 'executor']);
20
+ export const SKILL_KINDS = DUTIES;
26
21
 
27
22
  /**
28
- * 判定一个成员该装配哪份内置技能。
23
+ * 判定一个成员该装配哪份岗位规程。
29
24
  *
30
- * 优先级:项目主理人(账本 ownerMemberId)→ 角色名里的主理人/PMO → 验收角色 → 执行。
31
- * 只认身份,不看任务:同一个人换角色要立刻换规程。
25
+ * 优先级:项目主理人(账本 ownerMemberId)→ 团队配置里写明的 duty → 角色名里的主理人/PMO
26
+ * → 验收角色 → 执行。只认身份,不看任务。
32
27
  *
33
- * @param {{id?: string, role?: string}|null|undefined} member
28
+ * @param {{id?: string, role?: string, duty?: string|null}|null|undefined} member
34
29
  * @param {{ownerId?: string}|null|undefined} context 项目主理人 id
35
30
  * @returns {'lead'|'qa'|'executor'}
36
31
  */
37
32
  export function skillKindForMember(member, context = {}) {
38
33
  const ownerId = typeof context?.ownerId === 'string' ? context.ownerId : '';
39
34
  if (ownerId !== '' && member?.id === ownerId) return 'lead';
35
+ if (DUTIES.includes(member?.duty)) return member.duty;
40
36
  const role = typeof member?.role === 'string' ? member.role : '';
41
37
  if (LEAD_PATTERN.test(role)) return 'lead';
42
38
  if (isQaMember(member) || isReviewerMember(member)) return 'qa';
43
39
  return 'executor';
44
40
  }
45
41
 
46
- /** 按种类取技能正文(含 front-matter,调用方负责剥掉)。 */
47
- export function coreSkillTextFor(kind) {
48
- if (kind === 'lead') return CORE_SKILL_TEXT;
49
- if (kind === 'qa') return QA_SKILL_TEXT;
50
- return EXECUTOR_SKILL_TEXT;
42
+ /** 按职责取规程正文(含 front-matter,调用方负责剥掉);给了团队就用团队的规程。 */
43
+ export function coreSkillTextFor(kind, preset = null) {
44
+ return procedureText(preset, kind);
51
45
  }