@suifei/dsh-ai-team 0.4.128 → 0.4.129

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,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.129 - 2026-11-18
4
+
5
+ **人才市场(第 2 步 2c,第 2 步收尾):内置人才可改,技能可进化**
6
+
7
+ - 此前内置人才只读:想给内置人才加技能、改技能,只能先「存为人才」另起一个新 id,已招的成员仍用内置版;
8
+ SkillOpt(技能自我进化)也只有成员自己知道去调,界面上没有入口,且内置技能在插件目录里,就地改会在升级时被冲掉。
9
+ - **复制为可编辑**:人才市场里内置人才的卡片加「复制为可编辑」,把整个人才文件夹(talent.yml + skills/)拷进用户根、**同 id**,
10
+ 遮盖内置版;已招的成员下次激活就读副本里的技能。卡片标「已改」,可「恢复内置」(删副本,副本里的技能一并丢弃,需确认)。
11
+ `catalog.forkTalent` / `bundledHasTalent`;`POST /api/talents/:id/fork`(已是可编辑人才回 409,已有副本不覆盖);人才列表多一个 `forked`。
12
+ - **技能「进化」**:成员资料里每份技能旁加「进化」。服务端按成员实际读技能的路径找到那份文件(`skill-loader.findSkill`,与激活、存为人才同一查找),
13
+ 在内置人才里就先 fork 人才,让技能落到用户副本里;再私信这位成员按 SkillOpt 两步走:`skillopt_optimize` 拿诊断 → 只改最弱一维交 candidate →
14
+ 评审官盲评,好就保留、不好回退。插件目录里的内置文件永远不被改。岗位规程属于团队,不在这里进化(400)。
15
+ `POST /api/projects/:p/members/:m/skills/evolve`;诊断行 `talent.fork` / `talent.skill.evolve`。
16
+ - 测试:`test/catalog.test.js` 补 fork(同 id 遮盖、带技能、不覆盖已改副本)与 `findSkill`;`test/talent-routes.test.js` 补 fork / 恢复 / 进化(先 fork、第二次直接用副本、
17
+ 私信进账本、规程 400、未知成员 404)。实机 E2E r49(rc.1 / rc.3):fork、恢复、进化路径在用户根、内置文件未改、私信落账本。
18
+
3
19
  ## 0.4.128 - 2026-11-18
4
20
 
5
21
  **主理人只调度交付,不看产出**
package/README.md CHANGED
@@ -34,6 +34,7 @@
34
34
  - **新建自定义人才(界面)**:「添加成员 → 新建人才」填名号、岗位、职责、性格,再按需装技能——从现成人才 fork、自写一份、或导入 `.md`,存成可复用的人才(落用户根)。内置没有的角色能自己攒;技能装进人才自己的文件夹,自包含、可分享。走 `POST /api/talents` 与 `POST /api/talents/:id/skills`,内置只读、装删回 `409`。
35
35
  - **存为人才**:成员资料「存为人才」把项目里这位成员此刻的岗位、职责、性格、模型与技能存成可复用的人才(技能按成员实际读取的路径拷进人才文件夹,找不到正文的会提示),换个项目照样招。新建与存为都不会静默覆盖已有人才,撞名自动加序号。
36
36
  - **组队、建项目选团队**:「新建项目」里选团队(内置或自建),按它种成员、负责人当主理人;「组一个新团队」从人才里挑人(同一人才可招多位)、指定负责人即可保存。插件设置 `teamPreset` 只是不选时的默认值。
37
+ - **改内置人才、进化技能**:内置人才点「复制为可编辑」得到同 id 的副本(随时「恢复内置」);成员资料里技能旁的「进化」会让该成员用 SkillOpt 优化那份技能——内置的先自动复制,插件里的原文件不动。
37
38
  - 成员在账本里记下来源人才与版本、职责;人才文件之后再改,不会悄悄改动已招成员的性格与职责。已有项目不受新团队影响。文件写坏时跳过它并在诊断日志记 `catalog.load.fail` / `catalog.team.fail`。
38
39
 
39
40
  ---
package/client.js CHANGED
@@ -308,6 +308,7 @@ window.__ModuleLoader__.load({
308
308
  talentLoadFailed: '人才市场读取失败:{error}',
309
309
  talentSkills: '技能:{skills}',
310
310
  talentUser: '自建',
311
+ talentFork: '复制为可编辑', talentForkHint: '把这位内置人才复制成你自己的副本(同名遮盖内置),之后可装技能、进化技能;已招的成员下次激活就用副本。', talentForked: '已改', talentRestore: '恢复内置', talentRestoreConfirm: '删掉「{name}」的可编辑副本,恢复内置版?副本里装的、进化过的技能都会丢弃。', skillEvolve: '进化', skillEvolveHint: '让这位成员用 SkillOpt 优化这份技能:诊断最弱一维、改写、评审官盲评,好就保留,不好回退。', skillEvolveSent: '已私信 {name} 进化技能「{skill}」。', skillEvolveForked: '内置人才「{talent}」已复制为可编辑副本,并已私信 {name} 进化技能「{skill}」。', skillEvolveFailed: '技能进化没发出去:{error}',
311
312
  talentHint: '挑一位人才预填表单,改名、换模型后再招进项目;自建人才放在 ~/.dsh/ai-team/catalog/user/talents/。',
312
313
  memberHireFrom: '招自人才市场「{name}」v{version}:带入岗位、职责、人格与技能,可先修改再创建。',
313
314
  dutyLead: '主理人',
@@ -758,6 +759,7 @@ window.__ModuleLoader__.load({
758
759
  talentLoadFailed: 'Could not load the talent market: {error}',
759
760
  talentSkills: 'Skills: {skills}',
760
761
  talentUser: 'Custom',
762
+ talentFork: 'Make editable', talentForkHint: 'Copy this built-in talent into your own copy (same id, shadows the built-in) so you can install and evolve its skills; hired members use the copy on their next activation.', talentForked: 'Edited', talentRestore: 'Restore built-in', talentRestoreConfirm: 'Delete your editable copy of “{name}” and restore the built-in? Skills installed or evolved in the copy are discarded.', skillEvolve: 'Evolve', skillEvolveHint: 'Have this member optimize the skill with SkillOpt: diagnose the weakest dimension, rewrite, blind review by the reviewer; kept if better, reverted if not.', skillEvolveSent: 'Asked {name} to evolve the skill “{skill}”.', skillEvolveForked: 'Built-in talent “{talent}” was copied into an editable copy, and {name} was asked to evolve the skill “{skill}”.', skillEvolveFailed: 'Could not start skill evolution: {error}',
761
763
  talentHint: 'Pick a talent to prefill the form, rename it or change the model, then hire. Your own talents live in ~/.dsh/ai-team/catalog/user/talents/.',
762
764
  memberHireFrom: 'Hired from the talent market: “{name}” v{version}. Role, duty, personality and skills are filled in; edit before creating.',
763
765
  dutyLead: 'Lead',
@@ -2717,7 +2719,7 @@ window.__ModuleLoader__.load({
2717
2719
 
2718
2720
  const DUTY_LABEL = { lead: 'dutyLead', qa: 'dutyQa', executor: 'dutyExecutor' };
2719
2721
  /** 「添加成员」弹窗的人才市场页:分类、搜索、卡片;点「招聘」按人才预填表单。 */
2720
- function TalentMarket({ t, talents, error, query, onQuery, category, onCategory, onHire, onCancel }) {
2722
+ function TalentMarket({ t, talents, error, query, onQuery, category, onCategory, onHire, onFork, onRestore, onCancel }) {
2721
2723
  const categories = [...new Set((talents ?? []).map((talent) => talent.category).filter(Boolean))];
2722
2724
  const shown = filterTalents(talents, query, category);
2723
2725
  return h('div', { className: 'at-market' },
@@ -2739,12 +2741,15 @@ window.__ModuleLoader__.load({
2739
2741
  h('span', { className: 'at-talentname' }, talent.name),
2740
2742
  h('span', { className: 'at-talentrole' }, talent.role),
2741
2743
  talent.duty ? h('span', { className: 'at-talentduty' }, t(DUTY_LABEL[talent.duty])) : null,
2742
- talent.source === 'user' ? h('span', { className: 'at-talentduty' }, t('talentUser')) : null),
2744
+ talent.forked ? h('span', { className: 'at-talentduty' }, t('talentForked')) : talent.source === 'user' ? h('span', { className: 'at-talentduty' }, t('talentUser')) : null),
2743
2745
  talent.description ? h('div', { className: 'at-talentdesc' }, talent.description) : null,
2744
2746
  talent.skills?.length ? h('div', { className: 'at-modalmeta' }, tf(t, 'talentSkills', { skills: talent.skills.join('、') })) : null,
2745
2747
  h('div', { className: 'at-talentfoot' },
2746
2748
  h('span', { className: 'at-modalmeta' }, [talent.category, ...(talent.tags ?? [])].filter(Boolean).join(' · ')),
2747
- h('button', { type: 'button', className: 'at-btn at-btn-primary', onClick: () => onHire(talent) }, t('talentHire')))))),
2749
+ h('span', { className: 'at-tcpick' },
2750
+ talent.source !== 'user' && onFork ? h('button', { type: 'button', className: 'at-btn at-btn-small', title: t('talentForkHint'), onClick: () => onFork(talent) }, t('talentFork')) : null,
2751
+ talent.forked && onRestore ? h('button', { type: 'button', className: 'at-btn at-btn-small', onClick: () => onRestore(talent) }, t('talentRestore')) : null,
2752
+ h('button', { type: 'button', className: 'at-btn at-btn-primary', onClick: () => onHire(talent) }, t('talentHire'))))))),
2748
2753
  h('div', { className: 'at-modalactions' },
2749
2754
  h('button', { className: 'at-btn', type: 'button', onClick: onCancel }, t('cancel'))));
2750
2755
  }
@@ -3331,6 +3336,7 @@ window.__ModuleLoader__.load({
3331
3336
  const [pNote, setPNote] = React.useState('');
3332
3337
  const [pSkill, setPSkill] = React.useState('');
3333
3338
  const [pMessage, setPMessage] = React.useState('');
3339
+ const [pEvolve, setPEvolve] = React.useState('');
3334
3340
  const [newOpen, setNewOpen] = React.useState(false);
3335
3341
  const [nName, setNName] = React.useState('');
3336
3342
  const [nGoal, setNGoal] = React.useState('');
@@ -4197,6 +4203,41 @@ window.__ModuleLoader__.load({
4197
4203
  setTalentError(error?.message ?? String(error));
4198
4204
  }
4199
4205
  }
4206
+ /** 2c:内置人才 fork 成可编辑副本(同 id 遮盖内置,已招成员下次激活读副本)。 */
4207
+ async function forkTalent(talent) {
4208
+ try {
4209
+ const response = await fetch('/ai-team/api/talents/' + encodeURIComponent(talent.id) + '/fork', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' });
4210
+ const body = await response.json().catch(() => null);
4211
+ if (!response.ok) throw new Error(body?.error?.message ?? ('HTTP ' + response.status));
4212
+ await loadTalents();
4213
+ } catch (error) {
4214
+ setTalentError(error?.message ?? String(error));
4215
+ }
4216
+ }
4217
+ /** 删掉可编辑副本,恢复内置版(副本里改过的技能一并丢弃)。 */
4218
+ async function restoreTalent(talent) {
4219
+ if (!(await askConfirm(t('talentRestore'), tf(t, 'talentRestoreConfirm', { name: talent.name })))) return;
4220
+ try {
4221
+ const response = await fetch('/ai-team/api/talents/delete', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: talent.id }) });
4222
+ const body = await response.json().catch(() => null);
4223
+ if (!response.ok) throw new Error(body?.error?.message ?? ('HTTP ' + response.status));
4224
+ await loadTalents();
4225
+ } catch (error) {
4226
+ setTalentError(error?.message ?? String(error));
4227
+ }
4228
+ }
4229
+ /** 2c:技能「进化」——服务端必要时先 fork 人才,再私信成员按 SkillOpt 两步优化这份技能。 */
4230
+ async function evolveSkill(agent, name) {
4231
+ setPEvolve('');
4232
+ try {
4233
+ const response = await fetch('/ai-team/api/projects/' + encodeURIComponent(projectId) + '/members/' + encodeURIComponent(agent.id) + '/skills/evolve', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ name }) });
4234
+ const body = await response.json().catch(() => null);
4235
+ if (!response.ok) throw new Error(body?.error?.message ?? ('HTTP ' + response.status));
4236
+ setPEvolve(tf(t, body.forked ? 'skillEvolveForked' : 'skillEvolveSent', { name: agent.name, skill: body.skill, talent: body.talent || '' }));
4237
+ } catch (error) {
4238
+ setPEvolve(tf(t, 'skillEvolveFailed', { error: error?.message ?? String(error) }));
4239
+ }
4240
+ }
4200
4241
  /** 招聘:按人才预填表单,切到自定义页让 Human 改名、换模型后再确认。 */
4201
4242
  function hireTalent(talent) {
4202
4243
  const draft = hireTalentDraft(talent, (data?.agents ?? []).map((agent) => agent.name));
@@ -4341,6 +4382,7 @@ window.__ModuleLoader__.load({
4341
4382
  }
4342
4383
  function openProfile(agent) {
4343
4384
  setProfileAgent(agent);
4385
+ setPEvolve('');
4344
4386
  setPName(agent.name ?? '');
4345
4387
  setPRole(agent.role ?? '');
4346
4388
  setPPersonality(agent.personality ?? '');
@@ -5213,6 +5255,8 @@ window.__ModuleLoader__.load({
5213
5255
  category: talentCategory,
5214
5256
  onCategory: setTalentCategory,
5215
5257
  onHire: hireTalent,
5258
+ onFork: (talent) => void forkTalent(talent),
5259
+ onRestore: (talent) => void restoreTalent(talent),
5216
5260
  onCancel: () => setAddOpen(false),
5217
5261
  }) : mTab === 'create' && !(mCopy && !mCopy.talent) ? h(TalentCreator, { key: talentInit && talentInit.memberId ? 'm:' + talentInit.memberId : 'blank', t, initial: talentInit, onSaved: () => { loadTalents(); setTalentInit(null); setMTab('market'); }, onCancel: () => { setAddOpen(false); setTalentInit(null); } }) : [
5218
5262
  mCopy?.talent ? h('div', { key: 'from', className: 'at-modalmeta' }, tf(t, 'memberHireFrom', { name: mCopy.sourceName, version: mCopy.talent.version })) : null,
@@ -5266,12 +5310,14 @@ window.__ModuleLoader__.load({
5266
5310
  h('div', { className: 'at-permbadge', title: t('permissionNote') },
5267
5311
  t('permissionBadge') + ' @ ' + (project?.workspacePath || '—')),
5268
5312
  h('div', { className: 'at-modalmeta' }, t('permissionNote')),
5269
- (profileAgent.skills?.length || profileAgent.notes?.length)
5270
- ? h('div', { className: 'at-modalmeta' },
5271
- (profileAgent.skills?.length ? t('memberSkills') + ':' + profileAgent.skills.join('、') : ''),
5272
- (profileAgent.skills?.length && profileAgent.notes?.length ? ' · ' : ''),
5273
- (profileAgent.notes?.length ? t('memberNotes') + ':' + profileAgent.notes.slice(-3).join(';') : ''))
5313
+ profileAgent.skills?.length
5314
+ ? h('div', { className: 'at-tcskills', 'aria-label': t('memberSkills') },
5315
+ h('span', { className: 'at-modalmeta' }, t('memberSkills') + ':'),
5316
+ profileAgent.skills.map((name) => h('span', { key: name, className: 'at-tcskill' }, name,
5317
+ h('button', { type: 'button', className: 'at-btn at-btn-small', title: t('skillEvolveHint'), onClick: () => void evolveSkill(profileAgent, name) }, t('skillEvolve')))))
5274
5318
  : null,
5319
+ pEvolve ? h('div', { className: 'at-modalmeta', role: 'status' }, pEvolve) : null,
5320
+ profileAgent.notes?.length ? h('div', { className: 'at-modalmeta' }, t('memberNotes') + ':' + profileAgent.notes.slice(-3).join(';')) : null,
5275
5321
  h('label', { className: 'at-field' }, h('span', null, t('memberName')),
5276
5322
  h('input', { value: pName, onChange: (event) => setPName(event.target.value), autoFocus: true })),
5277
5323
  h('label', { className: 'at-field' }, h('span', null, t('memberRole')),
package/index.js CHANGED
@@ -28,7 +28,7 @@ import { activationSpec } from './lib/runtime/activation-spec.js';
28
28
  import { repairArchivedHosts as repairHostSessions } from './lib/runtime/host-repair.js';
29
29
  import { classifyLlmFailure, nextRequestAttempt, retryDecision } from './lib/runtime/failure-policy.js';
30
30
  import { memberIdentity } from './lib/domain/member-profile.js';
31
- import { findSkillText, loadSkillContext } from './lib/runtime/skill-loader.js';
31
+ import { findSkill, findSkillText, loadSkillContext } from './lib/runtime/skill-loader.js';
32
32
  import { skillKindForMember } from './lib/runtime/core-skill.js';
33
33
  import { formatSkillCatalog } from './lib/runtime/skill-catalog.js';
34
34
  import { isSkillExcluded } from './lib/runtime/skill-policy.js';
@@ -72,7 +72,7 @@ import { isInformationalThreadMention } from './lib/domain/inbox.js';
72
72
  import { messageContent, normalizeAttachments } from './lib/domain/rich-message.js';
73
73
  import { readAttachment, uploadAttachment } from './lib/host/attachment-routes.js';
74
74
  import { createDiagLogger, defaultDiagDir, installDiagSink } from './lib/diaglog.js';
75
- import { DEFAULT_TEAM, catalogRoots, deleteTalent, deleteTeam, installSkill, listInstallableSkills, listTalents, listTeams, loadCatalog, readSkillText, resolveTeam, talentFromMember, talentIdFrom, uniqueTalentId, uniqueTeamId, userCatalogDir, writeTalent, writeTeam } from './lib/domain/catalog.js';
75
+ 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';
76
76
 
77
77
  export const name = 'ai-team';
78
78
 
@@ -2463,6 +2463,43 @@ export function apply(ctx, config = {}) {
2463
2463
  diag?.append({ ev: 'talent.delete', id: t.id });
2464
2464
  return send(res, { ok: true });
2465
2465
  }
2466
+ // 2c:把内置人才 fork 成可编辑副本(同 id,整个文件夹拷进用户根)。已招成员下次激活即读副本;删副本恢复内置。
2467
+ const talentForkRoute = url.pathname.match(/^\/ai-team\/api\/talents\/([^/]+)\/fork$/);
2468
+ if (req.method === 'POST' && talentForkRoute !== null) {
2469
+ const t = talentCatalog(diag).talents.get(decodeURIComponent(talentForkRoute[1]));
2470
+ if (t === undefined) return send(res, { error: { code: 'NOT_FOUND', message: 'talent not found' } }, 404);
2471
+ if (t.source === 'user') return send(res, { error: { code: 'E_CONFLICT', message: '已经是可编辑的人才了' } }, 409);
2472
+ const { forked } = forkTalent(userCatalogDir(dshHome()), t);
2473
+ diag?.append({ ev: 'talent.fork', id: t.id, forked });
2474
+ return send(res, { ok: true, forked, talent: listTalents(talentCatalog(diag)).find((x) => x.id === t.id) });
2475
+ }
2476
+ // 2c:技能「进化」入口。找到成员实际读的那份技能;在内置人才里就先 fork 人才,让技能落到可写的副本里;
2477
+ // 再私信该成员按 SkillOpt 两步走(诊断 → 只改最弱一维交 candidate → 评审官盲评 keep/revert)。
2478
+ const evolveRoute = url.pathname.match(/^\/ai-team\/api\/projects\/([^/]+)\/members\/([^/]+)\/skills\/evolve$/);
2479
+ if (req.method === 'POST' && evolveRoute !== null) {
2480
+ const body = await readJson(req);
2481
+ const runtime = projectRuntime(decodeURIComponent(evolveRoute[1]));
2482
+ const member = runtime?.service?.state?.members?.[decodeURIComponent(evolveRoute[2])];
2483
+ if (member === undefined || member.kind !== 'agent') return send(res, { error: { code: 'NOT_FOUND', message: 'member not found' } }, 404);
2484
+ let found = await findSkill(memberSkillRoots(member, runtime, diag), body?.name);
2485
+ if (found === null) return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: `成员「${member.name}」没有可进化的技能 ${String(body?.name ?? '')}(岗位规程属于团队,不在这里进化)` } }, 400);
2486
+ let forked = false;
2487
+ const talent = typeof member.talent === 'string' ? talentCatalog(diag).talents.get(member.talent) : undefined;
2488
+ if (talent !== undefined && talent.source !== 'user' && found.root === talent.dir) {
2489
+ forked = forkTalent(userCatalogDir(dshHome()), talent).forked;
2490
+ found = await findSkill(memberSkillRoots(member, runtime, diag), found.name);
2491
+ if (found === null || found.root === talent.dir) return send(res, { error: { code: 'E_INTERNAL', message: 'fork 后仍找不到可写的技能副本' } }, 500);
2492
+ }
2493
+ const message = [
2494
+ `技能进化:请优化你的技能「${found.name}」,文件 ${found.path}。`,
2495
+ `1. 调用 skillopt_optimize(skillPath=${found.path},不带 candidate)拿诊断;`,
2496
+ '2. 只针对诊断出的最弱维度改写整份 SKILL.md(保留失败分支与检查点,不超过原文 150%),再带 candidate 调一次;',
2497
+ '3. 评审官盲评后用 skillopt_jobs 查结果,好就保留、不好自动回退。只改这一个文件,不开新卡。',
2498
+ ].join('\n');
2499
+ await runtime.service.dispatch({ type: 'member.message', actor: { kind: 'human', memberId: HUMAN_ID }, projectId: runtime.id, payload: { memberId: member.id, body: message } });
2500
+ diag?.append({ ev: 'talent.skill.evolve', memberId: member.id, skill: found.name, path: found.path, forked });
2501
+ return send(res, { ok: true, skill: found.name, skillPath: found.path, forked, talent: talent?.id ?? null });
2502
+ }
2466
2503
  // 往某用户人才装一份技能:自写(markdown)或从现成人才 fork(fromTalent + fromSkill)。
2467
2504
  const talentSkillRoute = url.pathname.match(/^\/ai-team\/api\/talents\/([^/]+)\/skills$/);
2468
2505
  if (req.method === 'POST' && talentSkillRoute !== null) {
@@ -2470,7 +2507,7 @@ export function apply(ctx, config = {}) {
2470
2507
  const cat = talentCatalog(diag);
2471
2508
  const t = cat.talents.get(decodeURIComponent(talentSkillRoute[1]));
2472
2509
  if (t === undefined) return send(res, { error: { code: 'NOT_FOUND', message: 'talent not found' } }, 404);
2473
- if (t.source !== 'user') return send(res, { error: { code: 'E_READONLY', message: '内置人才只读;先把它存为自己的人才再装技能' } }, 409);
2510
+ if (t.source !== 'user') return send(res, { error: { code: 'E_READONLY', message: '内置人才只读;先 fork 成可编辑副本再装技能' } }, 409);
2474
2511
  let markdown = typeof body?.markdown === 'string' ? body.markdown : null;
2475
2512
  if (markdown === null && typeof body?.fromTalent === 'string' && typeof body?.fromSkill === 'string') {
2476
2513
  const src = cat.talents.get(body.fromTalent);
@@ -12,7 +12,7 @@
12
12
  * 文件写坏不阻断:记一行 `.fail` 诊断,跳过它(更低优先级的同名条目顶上)。
13
13
  */
14
14
 
15
- import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
15
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
16
16
  import { join } from 'node:path';
17
17
  import { fileURLToPath } from 'node:url';
18
18
  import { parse, stringify } from 'yaml';
@@ -184,7 +184,7 @@ export function loadCatalog({ roots = catalogRoots(), diag } = {}) {
184
184
  /** 人才市场列表(给「添加成员」弹窗):按分类、名字排序。 */
185
185
  export function listTalents(catalog) {
186
186
  return [...catalog.talents.values()]
187
- .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 }))
187
+ .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, forked: source === 'user' && bundledHasTalent(id) }))
188
188
  .sort((a, b) => a.category.localeCompare(b.category, 'zh') || a.name.localeCompare(b.name, 'zh'));
189
189
  }
190
190
 
@@ -280,6 +280,26 @@ export function deleteTalent(userRoot, id) {
280
280
  rmSync(join(userRoot, 'talents', id), { recursive: true, force: true });
281
281
  }
282
282
 
283
+ /** 内置目录里有没有这个人才(用户根里的同 id 人才就是它的可编辑副本)。 */
284
+ export function bundledHasTalent(id, { bundledDir = BUNDLED_CATALOG_DIR } = {}) {
285
+ return typeof id === 'string' && SLUG.test(id) && existsSync(join(bundledDir, 'talents', id, 'talent.yml'));
286
+ }
287
+
288
+ /**
289
+ * 把内置人才 fork 成用户根里的可编辑副本:同 id 整个文件夹(talent.yml + skills/)拷过去。
290
+ * 同 id 遮盖内置版,已招的成员下次激活就读副本里的技能;删掉副本即恢复内置版。
291
+ * 已有用户副本时不覆盖(返回 forked: false),免得把改过的副本冲掉。
292
+ */
293
+ export function forkTalent(userRoot, talent) {
294
+ if (typeof userRoot !== 'string' || userRoot === '') throw new Error('forkTalent: 需要 userRoot');
295
+ if (!talent || !SLUG.test(talent.id ?? '')) throw new Error('人才 id 不合法');
296
+ const dir = join(userRoot, 'talents', talent.id);
297
+ if (existsSync(join(dir, 'talent.yml'))) return { forked: false, dir };
298
+ if (talent.source === 'user') return { forked: false, dir: talent.dir };
299
+ cpSync(talent.dir, dir, { recursive: true });
300
+ return { forked: true, dir };
301
+ }
302
+
283
303
  /** 把一份技能装进某人才自己的文件夹:`<talentDir>/skills/<name>/SKILL.md`。返回规范后的技能名。 */
284
304
  export function installSkill(talentDir, name, markdown) {
285
305
  if (typeof talentDir !== 'string' || talentDir === '') throw new Error('installSkill: 需要 talentDir');
@@ -31,13 +31,18 @@ export function skillFileName(raw) {
31
31
  * 找不到返回 null。成员激活注入与「存为人才」拷技能共用这一份查找,保证拷出来的就是成员实际读到的。
32
32
  */
33
33
  export async function findSkillText(roots, raw) {
34
+ return (await findSkill(roots, raw))?.text ?? null;
35
+ }
36
+
37
+ /** 同 findSkillText,另带命中的文件路径(技能进化要知道改哪个文件)。按根的顺序,先命中者胜。 */
38
+ export async function findSkill(roots, raw) {
34
39
  const name = skillFileName(raw);
35
40
  if (name === '') return null;
36
41
  for (const root of Array.isArray(roots) ? roots : [roots]) {
37
42
  if (typeof root !== 'string' || root === '') continue;
38
43
  for (const candidate of [join(root, 'skills', name, 'SKILL.md'), join(root, 'skills', `${name}.md`)]) {
39
44
  try {
40
- return await readFile(candidate, 'utf8');
45
+ return { name, path: candidate, root, text: await readFile(candidate, 'utf8') };
41
46
  } catch (error) {
42
47
  if (error?.code !== 'ENOENT') break;
43
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.128",
3
+ "version": "0.4.129",
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",