@suifei/dsh-ai-team 0.4.122 → 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.
- package/CHANGELOG.md +35 -0
- package/README.md +19 -6
- package/client.js +179 -12
- package/index.js +31 -2
- package/lib/domain/catalog.js +229 -0
- package/lib/domain/rich-message.js +14 -0
- package/lib/host/default-roster.js +124 -143
- package/lib/host/member-tools.js +5 -2
- package/lib/host/project-runtime.js +2 -2
- package/lib/host/service.js +17 -0
- package/lib/host/waker.js +1 -1
- package/lib/ledger/fold.js +6 -0
- package/lib/runtime/core-skill.js +16 -22
- package/lib/runtime/skill-loader.js +4 -2
- package/package.json +5 -2
- package/talents/algo-reimplementer/skills/reimplementation/SKILL.md +14 -0
- package/talents/algo-reimplementer/talent.yml +9 -0
- package/talents/analyst/skills/analysis-synthesis/SKILL.md +14 -0
- package/talents/analyst/talent.yml +9 -0
- package/talents/architect/skills/architecture-design/SKILL.md +14 -0
- package/talents/architect/talent.yml +9 -0
- package/talents/binary-analyst/skills/static-analysis/SKILL.md +14 -0
- package/talents/binary-analyst/talent.yml +9 -0
- package/talents/biz-analyst/skills/business-analysis/SKILL.md +14 -0
- package/talents/biz-analyst/talent.yml +9 -0
- package/talents/code-reviewer/skills/code-review/SKILL.md +14 -0
- package/talents/code-reviewer/talent.yml +9 -0
- package/talents/content-author/skills/question-authoring/SKILL.md +14 -0
- package/talents/content-author/talent.yml +9 -0
- package/talents/content-strategist/talent.yml +8 -0
- package/talents/copywriter/skills/copywriting/SKILL.md +14 -0
- package/talents/copywriter/talent.yml +9 -0
- package/talents/creative-director/talent.yml +8 -0
- package/talents/curriculum-designer/skills/curriculum-design/SKILL.md +14 -0
- package/talents/curriculum-designer/talent.yml +9 -0
- package/talents/data-analyst/skills/statistics/SKILL.md +14 -0
- package/talents/data-analyst/talent.yml +9 -0
- package/talents/deobfuscator/skills/deobfuscation/SKILL.md +14 -0
- package/talents/deobfuscator/talent.yml +9 -0
- package/talents/diagrammer/skills/diagramming/SKILL.md +14 -0
- package/talents/diagrammer/talent.yml +9 -0
- package/talents/dynamic-debugger/skills/dynamic-debugging/SKILL.md +14 -0
- package/talents/dynamic-debugger/talent.yml +9 -0
- package/talents/editor/skills/copyediting/SKILL.md +14 -0
- package/talents/editor/talent.yml +9 -0
- package/talents/editorial-lead/talent.yml +8 -0
- package/talents/education-lead/talent.yml +8 -0
- package/talents/engineer/skills/engineering/SKILL.md +15 -0
- package/talents/engineer/talent.yml +9 -0
- package/talents/executor/skills/delivery-checklist/SKILL.md +15 -0
- package/talents/executor/talent.yml +9 -0
- package/talents/experiment-designer/skills/experiment-design/SKILL.md +14 -0
- package/talents/experiment-designer/talent.yml +9 -0
- package/talents/fact-checker/skills/fact-check/SKILL.md +14 -0
- package/talents/fact-checker/talent.yml +9 -0
- package/talents/game-artist/skills/game-art/SKILL.md +14 -0
- package/talents/game-artist/talent.yml +9 -0
- package/talents/game-designer/skills/game-design/SKILL.md +14 -0
- package/talents/game-designer/talent.yml +9 -0
- package/talents/game-director/talent.yml +8 -0
- package/talents/game-tester/skills/playtesting/SKILL.md +14 -0
- package/talents/game-tester/talent.yml +9 -0
- package/talents/gameplay-programmer/skills/gameplay-programming/SKILL.md +14 -0
- package/talents/gameplay-programmer/talent.yml +9 -0
- package/talents/mobile-re/skills/mobile-re/SKILL.md +14 -0
- package/talents/mobile-re/talent.yml +9 -0
- package/talents/paper-writer/skills/paper-writing/SKILL.md +14 -0
- package/talents/paper-writer/talent.yml +9 -0
- package/talents/peer-reviewer/skills/peer-review/SKILL.md +14 -0
- package/talents/peer-reviewer/talent.yml +9 -0
- package/talents/pmo-lead/talent.yml +8 -0
- package/talents/principal-investigator/talent.yml +8 -0
- package/talents/qa-acceptor/skills/acceptance-testing/SKILL.md +14 -0
- package/talents/qa-acceptor/talent.yml +9 -0
- package/talents/re-lead/talent.yml +8 -0
- package/talents/re-verifier/skills/behavior-diff/SKILL.md +14 -0
- package/talents/re-verifier/talent.yml +9 -0
- package/talents/research-lead/talent.yml +8 -0
- package/talents/researcher/skills/source-research/SKILL.md +14 -0
- package/talents/researcher/talent.yml +9 -0
- package/talents/scriptwriter/skills/scriptwriting/SKILL.md +14 -0
- package/talents/scriptwriter/talent.yml +9 -0
- package/talents/security-auditor/skills/security-audit/SKILL.md +14 -0
- package/talents/security-auditor/talent.yml +9 -0
- package/talents/seo-specialist/skills/seo/SKILL.md +14 -0
- package/talents/seo-specialist/talent.yml +9 -0
- package/talents/storyboard-artist/skills/storyboarding/SKILL.md +14 -0
- package/talents/storyboard-artist/talent.yml +9 -0
- package/talents/tech-writer/skills/technical-writing/SKILL.md +14 -0
- package/talents/tech-writer/talent.yml +9 -0
- package/talents/ux-designer/skills/ux-research/SKILL.md +14 -0
- package/talents/ux-designer/talent.yml +9 -0
- package/talents/video-editor/skills/video-editing/SKILL.md +14 -0
- package/talents/video-editor/talent.yml +9 -0
- package/teams/content/team.yml +12 -0
- package/teams/default/team.yml +35 -0
- package/teams/docs/team.yml +12 -0
- package/teams/education/team.yml +13 -0
- package/teams/game/team.yml +12 -0
- package/teams/research/team.yml +11 -0
- package/teams/reverse/team.yml +17 -0
- package/teams/science/team.yml +12 -0
- package/teams/video/team.yml +12 -0
- /package/{skills → teams/default/skills}/ai-team-core/SKILL.md +0 -0
- /package/{skills → teams/default/skills}/ai-team-executor/SKILL.md +0 -0
- /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
|
+
}
|
|
@@ -120,3 +120,17 @@ export function messageContent(text, attachments) {
|
|
|
120
120
|
const list = normalizeAttachments(attachments);
|
|
121
121
|
return list.length === 0 ? text : [{ type: 'text', text }, ...list];
|
|
122
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Human 在主对话 @ 了这个成员、而成员还没在主对话回过话时,返回那条点名消息;否则 null。
|
|
125
|
+
* 主对话平时只有负责人发言;被点名的成员可以直接回这一次(il2c 11-17 21:44:tony 老师被 @ 后 say 被拒,只能请墨渊代发)。
|
|
126
|
+
* 每次点名只换一次发言:成员在点名之后发过一条,这次点名就算答过了。
|
|
127
|
+
*/
|
|
128
|
+
export function unansweredMention(stream, memberId, projectId) {
|
|
129
|
+
const entries = (Array.isArray(stream) ? stream : []).filter((entry) => projectId === undefined || projectId === null || entry.projectId === undefined || entry.projectId === projectId);
|
|
130
|
+
let mention = null;
|
|
131
|
+
for (const entry of entries) {
|
|
132
|
+
if (entry.kind === 'human_message' && Array.isArray(entry.mentions) && entry.mentions.includes(memberId)) mention = entry;
|
|
133
|
+
else if (mention !== null && entry.authorId === memberId && entry.seq > mention.seq) mention = null;
|
|
134
|
+
}
|
|
135
|
+
return mention;
|
|
136
|
+
}
|
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
id
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
}
|
package/lib/host/member-tools.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { taskCard } from './views.js';
|
|
11
11
|
import { isQaMember } from '../domain/member-profile.js';
|
|
12
|
+
import { unansweredMention } from '../domain/rich-message.js';
|
|
12
13
|
|
|
13
14
|
const ACTIONS = ['tasks', 'members', 'inbox', 'recall', 'create', 'askHuman', 'member', 'evolve', 'distill', 'note', 'skill', 'claim', 'submit', 'thread', 'reply', 'accept', 'requestChanges', 'say'];
|
|
14
15
|
|
|
@@ -56,7 +57,7 @@ function rosterText(state) {
|
|
|
56
57
|
export function createTeamTool(options) {
|
|
57
58
|
return {
|
|
58
59
|
name: 'team',
|
|
59
|
-
description: 'Read and act on the AI Team board. The Project owner (the PMO)
|
|
60
|
+
description: 'Read and act on the AI Team board. The Project owner (the PMO) speaks to Human in the Main stream with action=say (optionally listing taskIds); a member whom Human @-mentioned there may answer that mention once with action=say; everyone else talks in Task Threads. The Project owner can create tasks with action=create and must set resultDefinition and ownerId. Use members for the exact roster id/name/role; use tasks for ids/revisions. When Human must decide something, call askHuman with every question and options—do not bury questions in a report. Use recall to search your notes/skills and your past Tasks/Threads. Claim before working; read a Thread before replying; submit evidence before acceptance.',
|
|
60
61
|
parameters: {
|
|
61
62
|
type: 'object',
|
|
62
63
|
properties: {
|
|
@@ -314,7 +315,9 @@ export function createTeamTool(options) {
|
|
|
314
315
|
if (args.action === 'say') {
|
|
315
316
|
// 核心模型:只有项目 PMO 面向 Human 说话(主对话);成员在各自 Task Thread 里协作。
|
|
316
317
|
const ownerId = state.projects?.[pid]?.ownerMemberId ?? state.projects?.[pid]?.ownerId;
|
|
317
|
-
|
|
318
|
+
// #65:Human @ 了谁,谁就能在主对话直接回这一次点名(回完即收回);其余时候只有负责人说话。
|
|
319
|
+
const mentioned = ownerId === member.id ? null : unansweredMention(state.stream, member.id, pid);
|
|
320
|
+
if (ownerId !== member.id && mentioned === null) return failure({ code: 'E_UNAUTHORIZED', message: 'only the Project owner (PMO) speaks in the Main stream, or a member answering the Human message that @-mentioned it; use reply in the Task Thread instead' });
|
|
318
321
|
if (typeof args.body !== 'string' || args.body.trim() === '') return failure({ code: 'E_INVALID_ARGUMENT', message: 'body is required' });
|
|
319
322
|
const taskIds = Array.isArray(args.taskIds) ? args.taskIds.filter((id) => typeof id === 'string' && id !== '') : [];
|
|
320
323
|
const result = await command('stream.post', { body: args.body, taskIds });
|
|
@@ -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;
|
package/lib/host/service.js
CHANGED
|
@@ -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
|
}
|
package/lib/host/waker.js
CHANGED
|
@@ -269,7 +269,7 @@ export function planWakes(state, result, actor = {}, options = {}) {
|
|
|
269
269
|
null,
|
|
270
270
|
'human_mention',
|
|
271
271
|
`human_mention:${event.seq ?? event.payload?.seq}`,
|
|
272
|
-
`Human 在主对话点名你:“${body.slice(0, 2000)}”。${attachmentNote}项目负责人(${ownerName})也收到了这句话并统筹安排。先读 tasks
|
|
272
|
+
`Human 在主对话点名你:“${body.slice(0, 2000)}”。${attachmentNote}项目负责人(${ownerName})也收到了这句话并统筹安排。先读 tasks 与主对话,再从你的岗位回应:用 team action=say 在主对话直接回复 Human(这次点名你可以回一条,回完发言权收回,想清楚再写全);需要建卡、改派的交给负责人,不要自己另开一摊。`,
|
|
273
273
|
);
|
|
274
274
|
}
|
|
275
275
|
for (const plan of targets.values()) {
|
package/lib/ledger/fold.js
CHANGED
|
@@ -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),
|