@suifei/dsh-ai-team 0.4.125 → 0.4.126

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.126 - 2026-11-18
4
+
5
+ **人才市场(第 2 步 2b):把项目里的成员存为人才**
6
+
7
+ - 成员在项目里干久了,性格会被复盘与手工调整打磨,技能也会越挂越多;此前这些只属于那一个项目。
8
+ 现在成员资料多了「存为人才」:把它此刻的岗位、职责、性格、模型与技能存成可复用的人才,换个项目照样招;
9
+ - 草稿由服务端生成 `GET /api/projects/:p/members/:m/talent-draft`:职责与激活注入同一判定(`skillKindForMember`,主理人即 lead),
10
+ 逐份技能标出找不到正文的(如只是挂了名字);笔记、会话与任务不带——那是这位成员自己的经历;
11
+ - 技能按**成员实际读取的路径**拷进新人才的文件夹(团队目录 → 人才自带 → 工作区 `.dsh` → `~/.dsh` → 项目数据目录):
12
+ `POST /api/talents/:id/skills` 新增 `fromProject` + `fromMember`;查找抽成 `skill-loader.findSkillText` 一份实现,激活注入与存为人才共用;
13
+ - 存为人才复用「新建人才」页:草稿预填、可改,找不到正文的技能单列提示,沿用的模型一并存下;
14
+ - **新建不再静默覆盖**:`POST /api/talents` 撞了已有 id(含内置,如英文名 `editor`)自动加序号,要改写已有自定义人才须显式 `overwrite`(`uniqueTalentId`);
15
+ - 测试:`test/talent-routes.test.js` 补存为人才全流程与去重;`test/catalog.test.js` 补 `uniqueTalentId` / `talentFromMember`;
16
+ `test/client-talent-market.test.js` 补 `talentCreatorInit`。实机 E2E(rc.1 / rc.3):改过性格、挂了工作区独有技能的青岚存为人才,
17
+ 删掉工作区那份后招进新人才并激活——性格、模型与两份技能都随人才走。
18
+
3
19
  ## 0.4.125 - 2026-11-18
4
20
 
5
21
  **人才市场(第 2 步 2a):自定义智能体 + 安装 skill**
package/README.md CHANGED
@@ -30,6 +30,7 @@
30
30
  - 「人员 → 添加成员」先打开人才市场:按分类、关键词挑一位,点「招聘」预填表单,改名、换模型后创建;也可以切到「自定义」从零填写。
31
31
  - 自建:人才放 `~/.dsh/ai-team/catalog/user/talents/<人才>/`,团队放 `~/.dsh/ai-team/catalog/user/teams/<团队>/`,同名覆盖内置;插件设置 `teamPreset` 选新项目用哪个团队。
32
32
  - **新建自定义人才(界面)**:「添加成员 → 新建人才」填名号、岗位、职责、性格,再按需装技能——从现成人才 fork、自写一份、或导入 `.md`,存成可复用的人才(落用户根)。内置没有的角色能自己攒;技能装进人才自己的文件夹,自包含、可分享。走 `POST /api/talents` 与 `POST /api/talents/:id/skills`,内置只读、装删回 `409`。
33
+ - **存为人才**:成员资料「存为人才」把项目里这位成员此刻的岗位、职责、性格、模型与技能存成可复用的人才(技能按成员实际读取的路径拷进人才文件夹,找不到正文的会提示),换个项目照样招。新建与存为都不会静默覆盖已有人才,撞名自动加序号。
33
34
  - 成员在账本里记下来源人才与版本、职责;人才文件之后再改,不会悄悄改动已招成员的性格与职责。已有项目不受新团队影响。文件写坏时跳过它并在诊断日志记 `catalog.load.fail` / `catalog.team.fail`。
34
35
 
35
36
  ---
package/client.js CHANGED
@@ -301,6 +301,7 @@ window.__ModuleLoader__.load({
301
301
  tcName: '名号', tcRole: '岗位', tcDuty: '职责', tcCategory: '分类', tcTags: '标签', tcTagsHint: '逗号分隔', tcPersonality: '性格', tcPersonalityHint: '它怎么做事、什么风格',
302
302
  tcSkills: '技能', tcEmpty: '还没装技能(可选)', tcAddExisting: '从已有装', tcWriteOwn: '自写一份', tcImport: '导入 .md', tcPick: '选一个已有技能…', tcAdd: '加入', tcRemove: '移除',
303
303
  tcSkillName: '技能名(英文/数字/-)', tcSkillBody: '技能正文(SKILL.md)', tcSkillDup: '已经装了同名技能', tcSave: '存为我的人才', tcSaving: '保存中…',
304
+ memberSaveAsTalent: '存为人才', tcFromMember: '从成员「{name}」存出:沿用它此刻的岗位、职责、性格与技能,可先修改再保存。', tcModelKept: '沿用模型:{model}', tcMissing: '这些技能找不到正文,没有带上:{skills}', tcDraftFailed: '读取成员草稿失败:{error}',
304
305
  talentEmpty: '没有符合条件的人才。',
305
306
  talentLoading: '正在读取人才市场…',
306
307
  talentLoadFailed: '人才市场读取失败:{error}',
@@ -749,6 +750,7 @@ window.__ModuleLoader__.load({
749
750
  tcName: 'Name', tcRole: 'Role', tcDuty: 'Duty', tcCategory: 'Category', tcTags: 'Tags', tcTagsHint: 'comma-separated', tcPersonality: 'Personality', tcPersonalityHint: 'how it works, its style',
750
751
  tcSkills: 'Skills', tcEmpty: 'No skills yet (optional)', tcAddExisting: 'From existing', tcWriteOwn: 'Write one', tcImport: 'Import .md', tcPick: 'Pick an existing skill…', tcAdd: 'Add', tcRemove: 'Remove',
751
752
  tcSkillName: 'Skill name (a-z, 0-9, -)', tcSkillBody: 'Skill body (SKILL.md)', tcSkillDup: 'That skill name is already staged', tcSave: 'Save as my talent', tcSaving: 'Saving…',
753
+ memberSaveAsTalent: 'Save as talent', tcFromMember: 'Saved from member “{name}”: its current role, duty, personality and skills are filled in; edit before saving.', tcModelKept: 'Keeps the model: {model}', tcMissing: 'These skills have no readable body and were left out: {skills}', tcDraftFailed: 'Could not read the member draft: {error}',
752
754
  talentEmpty: 'No talent matches.',
753
755
  talentLoading: 'Loading the talent market…',
754
756
  talentLoadFailed: 'Could not load the talent market: {error}',
@@ -2738,9 +2740,10 @@ window.__ModuleLoader__.load({
2738
2740
  h('div', { className: 'at-modalactions' },
2739
2741
  h('button', { className: 'at-btn', type: 'button', onClick: onCancel }, t('cancel'))));
2740
2742
  }
2741
- function TalentCreator({ t, onSaved, onCancel }) {
2742
- const [form, setForm] = React.useState(blankTalentForm);
2743
- const [pending, setPending] = React.useState([]);
2743
+ function TalentCreator({ t, initial, onSaved, onCancel }) {
2744
+ const seed = initial && initial.draft ? talentCreatorInit(initial) : null;
2745
+ const [form, setForm] = React.useState(() => (seed ? seed.form : blankTalentForm()));
2746
+ const [pending, setPending] = React.useState(() => (seed ? seed.pending : []));
2744
2747
  const [installable, setInstallable] = React.useState([]);
2745
2748
  const [pick, setPick] = React.useState('');
2746
2749
  const [pickFrom, setPickFrom] = React.useState('');
@@ -2782,12 +2785,12 @@ window.__ModuleLoader__.load({
2782
2785
  if (!form.name.trim() || busy) return;
2783
2786
  setBusy(true); setError('');
2784
2787
  try {
2785
- const res = await fetch('/ai-team/api/talents', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(talentFormToBody(form)) });
2788
+ const res = await fetch('/ai-team/api/talents', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ ...talentFormToBody(form), ...(seed && seed.model ? { model: seed.model } : {}) }) });
2786
2789
  const body = await res.json().catch(() => null);
2787
2790
  if (!res.ok) throw new Error((body && body.error && body.error.message) || ('HTTP ' + res.status));
2788
2791
  const id = body && body.talent && body.talent.id;
2789
2792
  for (const sk of pending) {
2790
- const payload = sk.kind === 'fork' ? { name: sk.name, fromTalent: sk.fromTalent, fromSkill: sk.fromSkill } : { name: sk.name, markdown: sk.markdown };
2793
+ const payload = sk.kind === 'fork' ? { name: sk.name, fromTalent: sk.fromTalent, fromSkill: sk.fromSkill } : sk.kind === 'member' ? { name: sk.name, fromProject: sk.fromProject, fromMember: sk.fromMember } : { name: sk.name, markdown: sk.markdown };
2791
2794
  const r2 = await fetch('/ai-team/api/talents/' + encodeURIComponent(id) + '/skills', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(payload) });
2792
2795
  const b2 = await r2.json().catch(() => null);
2793
2796
  if (!r2.ok) throw new Error(((b2 && b2.error && b2.error.message) || ('HTTP ' + r2.status)) + '(' + sk.name + ')');
@@ -2801,6 +2804,10 @@ window.__ModuleLoader__.load({
2801
2804
  }
2802
2805
  return h('div', { className: 'at-market' },
2803
2806
  h('div', { className: 'at-modalmeta' }, t('tcHint')),
2807
+ initial && initial.error ? h('div', { className: 'at-modalerror', role: 'alert' }, initial.error) : null,
2808
+ seed ? h('div', { className: 'at-modalmeta' }, tf(t, 'tcFromMember', { name: seed.sourceName })) : null,
2809
+ seed && seed.model ? h('div', { className: 'at-modalmeta' }, tf(t, 'tcModelKept', { model: [seed.model.provider, seed.model.model].filter(Boolean).join(' / ') })) : null,
2810
+ seed && seed.missing.length ? h('div', { className: 'at-modalmeta' }, tf(t, 'tcMissing', { skills: seed.missing.join('、') })) : null,
2804
2811
  h('label', { className: 'at-field' }, h('span', null, t('tcName')), h('input', { value: form.name, onChange: set('name'), autoFocus: true })),
2805
2812
  h('label', { className: 'at-field' }, h('span', null, t('tcRole')), h('input', { value: form.role, onChange: set('role') })),
2806
2813
  h('label', { className: 'at-field' }, h('span', null, t('tcDuty')), h('select', { value: form.duty, onChange: set('duty') }, ['executor', 'qa', 'lead'].map((d) => h('option', { key: d, value: d }, t(DUTY_LABEL[d]))))),
@@ -3089,6 +3096,20 @@ window.__ModuleLoader__.load({
3089
3096
  personality: String((form && form.personality) || '').trim(),
3090
3097
  };
3091
3098
  }
3099
+ /**
3100
+ * 「存为人才」:服务端草稿 → 新建人才页的初值。找得到正文的技能按「从成员拷」暂存,找不到的单列出来。
3101
+ */
3102
+ function talentCreatorInit(initial) {
3103
+ const draft = (initial && initial.draft) || {};
3104
+ const skills = Array.isArray(draft.skills) ? draft.skills : [];
3105
+ return {
3106
+ form: { name: String(draft.name || ''), role: String(draft.role || ''), duty: ['lead', 'qa', 'executor'].includes(draft.duty) ? draft.duty : 'executor', category: String(draft.category || ''), tags: (Array.isArray(draft.tags) ? draft.tags : []).join(', '), personality: String(draft.personality || '') },
3107
+ pending: skills.filter((x) => x && x.found).map((x) => ({ name: x.name, kind: 'member', fromProject: initial.projectId, fromMember: initial.memberId })),
3108
+ missing: skills.filter((x) => x && !x.found).map((x) => x.name),
3109
+ model: draft.model && (draft.model.provider || draft.model.model) ? draft.model : null,
3110
+ sourceName: String(draft.name || ''),
3111
+ };
3112
+ }
3092
3113
  // </member-copy>
3093
3114
 
3094
3115
  // <composer-rich>
@@ -3219,6 +3240,8 @@ window.__ModuleLoader__.load({
3219
3240
  const [talentError, setTalentError] = React.useState('');
3220
3241
  const [talentQuery, setTalentQuery] = React.useState('');
3221
3242
  const [talentCategory, setTalentCategory] = React.useState('');
3243
+ // 「存为人才」:成员草稿(服务端生成),预填新建人才页。
3244
+ const [talentInit, setTalentInit] = React.useState(null);
3222
3245
  const [mName, setMName] = React.useState('');
3223
3246
  const [mRole, setMRole] = React.useState('');
3224
3247
  const [mPrompt, setMPrompt] = React.useState('');
@@ -4055,6 +4078,7 @@ window.__ModuleLoader__.load({
4055
4078
  setMCopy(null);
4056
4079
  setMError('');
4057
4080
  setMTab('market');
4081
+ setTalentInit(null);
4058
4082
  setTalentQuery('');
4059
4083
  setTalentCategory('');
4060
4084
  setAddOpen(true);
@@ -4100,6 +4124,21 @@ window.__ModuleLoader__.load({
4100
4124
  setMError('');
4101
4125
  setAddOpen(true);
4102
4126
  }
4127
+ /** 存为人才:取服务端草稿(职责按身份判定、标出找不到正文的技能),在「新建人才」页预填。 */
4128
+ async function openSaveAsTalent(source) {
4129
+ try {
4130
+ const response = await fetch('/ai-team/api/projects/' + encodeURIComponent(projectId) + '/members/' + encodeURIComponent(source.id) + '/talent-draft', { headers: { accept: 'application/json' } });
4131
+ const body = await response.json().catch(() => null);
4132
+ if (!response.ok) throw new Error((body && body.error && body.error.message) || ('HTTP ' + response.status));
4133
+ setTalentInit(body);
4134
+ } catch (error) {
4135
+ setTalentInit({ error: tf(t, 'tcDraftFailed', { error: (error && error.message) || String(error) }) });
4136
+ }
4137
+ setMCopy(null);
4138
+ setMTab('create');
4139
+ setAddOpen(true);
4140
+ loadTalents();
4141
+ }
4103
4142
  async function createAgent() {
4104
4143
  if (!mName.trim() || mBusy) return;
4105
4144
  setMBusy(true);
@@ -5075,7 +5114,7 @@ window.__ModuleLoader__.load({
5075
5114
  onCategory: setTalentCategory,
5076
5115
  onHire: hireTalent,
5077
5116
  onCancel: () => setAddOpen(false),
5078
- }) : mTab === 'create' && !(mCopy && !mCopy.talent) ? h(TalentCreator, { t, onSaved: () => { loadTalents(); setMTab('market'); }, onCancel: () => setAddOpen(false) }) : [
5117
+ }) : 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); } }) : [
5079
5118
  mCopy?.talent ? h('div', { key: 'from', className: 'at-modalmeta' }, tf(t, 'memberHireFrom', { name: mCopy.sourceName, version: mCopy.talent.version })) : null,
5080
5119
  mCopy && !mCopy.talent ? h('div', { key: 'from', className: 'at-modalmeta' }, tf(t, 'memberCopyFrom', { name: mCopy.sourceName })) : null,
5081
5120
  h('label', { key: 'name', className: 'at-field' }, h('span', null, t('memberName')),
@@ -5189,6 +5228,7 @@ window.__ModuleLoader__.load({
5189
5228
  h('button', { className: 'at-btn', type: 'button', onClick: () => { const target = profileAgent; setProfileAgent(null); openMemberView(target); } }, t('memberTasks')),
5190
5229
  h('button', { className: 'at-btn', type: 'button', onClick: () => { const target = profileAgent; setProfileAgent(null); void openAgentChat(target); } }, t('agentChat')),
5191
5230
  h('button', { className: 'at-btn', type: 'button', onClick: () => { const source = profileAgent; setProfileAgent(null); openCopyAgent(source); }, disabled: pBusy }, t('memberCopy')),
5231
+ h('button', { className: 'at-btn', type: 'button', onClick: () => { const source = profileAgent; setProfileAgent(null); void openSaveAsTalent(source); }, disabled: pBusy }, t('memberSaveAsTalent')),
5192
5232
  h('button', { className: 'at-btn', type: 'button', onClick: leaveProfile, disabled: pBusy }, t('leaveTeam')),
5193
5233
  profileAgent.status === 'failed' ? h('button', { className: 'at-btn', type: 'button', onClick: retryProfile, disabled: pBusy }, t('retry')) : null,
5194
5234
  profileAgent.sessionId ? h('button', { className: 'at-btn', type: 'button', title: t('reseatConfirm'), onClick: reseatProfile, disabled: pBusy }, t('reseatSession')) : null,
package/index.js CHANGED
@@ -28,7 +28,8 @@ 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 { loadSkillContext } from './lib/runtime/skill-loader.js';
31
+ import { findSkillText, loadSkillContext } from './lib/runtime/skill-loader.js';
32
+ import { skillKindForMember } from './lib/runtime/core-skill.js';
32
33
  import { formatSkillCatalog } from './lib/runtime/skill-catalog.js';
33
34
  import { isSkillExcluded } from './lib/runtime/skill-policy.js';
34
35
  import { installFileSkillProvider, pickProjectForCwd } from './lib/runtime/skill-provider.js';
@@ -71,7 +72,7 @@ import { isInformationalThreadMention } from './lib/domain/inbox.js';
71
72
  import { messageContent, normalizeAttachments } from './lib/domain/rich-message.js';
72
73
  import { readAttachment, uploadAttachment } from './lib/host/attachment-routes.js';
73
74
  import { createDiagLogger, defaultDiagDir, installDiagSink } from './lib/diaglog.js';
74
- import { DEFAULT_TEAM, catalogRoots, deleteTalent, installSkill, listInstallableSkills, listTalents, loadCatalog, readSkillText, resolveTeam, talentIdFrom, userCatalogDir, writeTalent } from './lib/domain/catalog.js';
75
+ import { DEFAULT_TEAM, catalogRoots, deleteTalent, installSkill, listInstallableSkills, listTalents, loadCatalog, readSkillText, resolveTeam, talentFromMember, talentIdFrom, uniqueTalentId, userCatalogDir, writeTalent } from './lib/domain/catalog.js';
75
76
 
76
77
  export const name = 'ai-team';
77
78
 
@@ -138,6 +139,16 @@ function memberCatalogDirs(member, diag) {
138
139
  return talent === undefined ? [] : [talent.dir];
139
140
  }
140
141
 
142
+ /**
143
+ * 成员技能的查找根(团队规程目录另由 preset 前置):人才自带 → 工作区 `.dsh` → 用户 `~/.dsh` → 项目数据目录。
144
+ * 激活注入与「存为人才」共用,拷出来的技能就是成员实际读到的那份。
145
+ */
146
+ function memberSkillRoots(member, runtime, diag) {
147
+ const workspacePath = runtime?.service?.state?.projects?.[runtime.id]?.workspacePath;
148
+ const dir = member?.workspace || (typeof workspacePath === 'string' ? workspacePath.trim() : '');
149
+ return [...memberCatalogDirs(member, diag), ...(dir ? [join(dir, '.dsh')] : []), dshHome(), runtime?.dir].filter((root) => typeof root === 'string' && root !== '');
150
+ }
151
+
141
152
  /** 新项目用哪个团队。 */
142
153
  function teamPresetFor(config, diag) {
143
154
  const preset = resolveTeam(talentCatalog(diag), config?.teamPreset || DEFAULT_TEAM, { diag });
@@ -2134,7 +2145,7 @@ export function apply(ctx, config = {}) {
2134
2145
  // #65:激活时若带着 Human 消息的图片/文件,一并放进首条消息。
2135
2146
  prompt: messageContent(`${memberIdentity(activationMember)}\n\n${typeof body.payload?.prompt === 'string'
2136
2147
  ? body.payload.prompt
2137
- : '你被加入 AI Team。先读取项目简报与收件箱,再处理分配给你的任务。'}${await formatSkillCatalog(skillsService, { cwd: effectiveDir })}${await loadSkillContext(activationMember, [...memberCatalogDirs(activationMember, diag), join(effectiveDir, '.dsh'), dshHome(), projectRuntime.dir], {
2148
+ : '你被加入 AI Team。先读取项目简报与收件箱,再处理分配给你的任务。'}${await formatSkillCatalog(skillsService, { cwd: effectiveDir })}${await loadSkillContext(activationMember, memberSkillRoots(activationMember, projectRuntime, diag), {
2138
2149
  vars: {
2139
2150
  GOAL: goalForProject(projectRuntime),
2140
2151
  PROJECT: projectRuntime.service.state.projects?.[projectRuntime.id]?.name ?? '',
@@ -2366,6 +2377,19 @@ export function apply(ctx, config = {}) {
2366
2377
  if (req.method === 'GET' && url.pathname === '/ai-team/api/talents') {
2367
2378
  return send(res, { talents: listTalents(talentCatalog(diag)) });
2368
2379
  }
2380
+ // 「存为人才」草稿:按成员此刻的岗位、职责(与激活同一判定)、性格、模型与技能生成;标出每份技能找不找得到。
2381
+ const talentDraftRoute = url.pathname.match(/^\/ai-team\/api\/projects\/([^/]+)\/members\/([^/]+)\/talent-draft$/);
2382
+ if (req.method === 'GET' && talentDraftRoute !== null) {
2383
+ const runtime = projectRuntime(decodeURIComponent(talentDraftRoute[1]));
2384
+ const member = runtime?.service?.state?.members?.[decodeURIComponent(talentDraftRoute[2])];
2385
+ if (member === undefined || member.kind !== 'agent') return send(res, { error: { code: 'NOT_FOUND', message: 'member not found' } }, 404);
2386
+ const project = runtime.service.state.projects?.[runtime.id];
2387
+ const draft = talentFromMember(member, skillKindForMember(member, { ownerId: project?.ownerMemberId ?? project?.ownerId }));
2388
+ const roots = [resolveTeam(talentCatalog(diag), member.team ?? DEFAULT_TEAM, { diag }).dir, ...memberSkillRoots(member, runtime, diag)];
2389
+ const skills = [];
2390
+ for (const name of draft.skills) skills.push({ name, found: (await findSkillText(roots, name)) !== null });
2391
+ return send(res, { draft: { ...draft, skills }, projectId: runtime.id, memberId: member.id });
2392
+ }
2369
2393
  // 可安装的技能清单(每个人才自带的技能),给「从已有装」挑。
2370
2394
  if (req.method === 'GET' && url.pathname === '/ai-team/api/skills-install') {
2371
2395
  return send(res, { skills: listInstallableSkills(talentCatalog(diag)) });
@@ -2388,6 +2412,9 @@ export function apply(ctx, config = {}) {
2388
2412
  let id = talentIdFrom(body?.id) || talentIdFrom(body?.name);
2389
2413
  if (id === '' && typeof body?.name === 'string' && body.name.trim() !== '') id = 'talent-' + Date.now().toString(36) + Math.random().toString(36).slice(2, 5);
2390
2414
  if (id === '') return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: '人才需要一个名字(用于生成 id)' } }, 400);
2415
+ // 新建不静默覆盖:撞了已有人才(含内置)就加序号;要改写已有的自定义人才须显式 overwrite。
2416
+ if (body?.overwrite !== true) id = uniqueTalentId(talentCatalog(diag), id);
2417
+ if (id === '') return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: '找不到可用的人才 id' } }, 400);
2391
2418
  try {
2392
2419
  const saved = writeTalent(userCatalogDir(dshHome()), id, body ?? {});
2393
2420
  diag?.append({ ev: 'talent.write', id, source: 'user' });
@@ -2421,7 +2448,16 @@ export function apply(ctx, config = {}) {
2421
2448
  if (src === undefined) return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: '来源人才不存在' } }, 400);
2422
2449
  try { markdown = readSkillText(src.dir, body.fromSkill); } catch (error) { return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: error.message } }, 400); }
2423
2450
  }
2424
- if (markdown === null) return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: '需要 markdown 正文,或 fromTalent + fromSkill' } }, 400);
2451
+ // 「存为人才」:按来源成员实际读技能的路径找正文(团队规程目录 + 成员技能根),拷进新人才。
2452
+ if (markdown === null && typeof body?.fromProject === 'string' && typeof body?.fromMember === 'string') {
2453
+ const runtime = projectRuntime(body.fromProject);
2454
+ const member = runtime?.service?.state?.members?.[body.fromMember];
2455
+ if (member === undefined) return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: '来源成员不存在' } }, 400);
2456
+ const roots = [resolveTeam(cat, member.team ?? DEFAULT_TEAM, { diag }).dir, ...memberSkillRoots(member, runtime, diag)];
2457
+ markdown = await findSkillText(roots, body?.name);
2458
+ if (markdown === null) return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: `成员「${member.name}」能读到的位置里找不到技能 ${String(body?.name)}` } }, 400);
2459
+ }
2460
+ if (markdown === null) return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: '需要 markdown 正文,或 fromTalent + fromSkill,或 fromProject + fromMember' } }, 400);
2425
2461
  try {
2426
2462
  const name = installSkill(t.dir, body?.name, markdown);
2427
2463
  const saved = writeTalent(userCatalogDir(dshHome()), t.id, { ...t, skills: [...new Set([...t.skills, name])] });
@@ -295,6 +295,40 @@ export function readSkillText(talentDir, name) {
295
295
  return readFileSync(join(talentDir, 'skills', skillName(name, '技能名'), 'SKILL.md'), 'utf8');
296
296
  }
297
297
 
298
+ /**
299
+ * 新建时取一个不撞车的 id:已被任何来源(用户或内置)占用就加序号 -2、-3…。
300
+ * 新建绝不静默覆盖别人的人才,也不意外遮盖同名内置人才(要覆盖得显式 overwrite)。
301
+ */
302
+ export function uniqueTalentId(catalog, base) {
303
+ if (!SLUG.test(base)) return '';
304
+ if (!catalog.talents.has(base)) return base;
305
+ for (let n = 2; n < 1000; n += 1) {
306
+ const id = `${base.slice(0, 60)}-${n}`;
307
+ if (!catalog.talents.has(id)) return id;
308
+ }
309
+ return '';
310
+ }
311
+
312
+ /**
313
+ * 项目成员 → 人才草稿(「存为人才」):带上它此刻的岗位、职责、性格(含复盘长出来的)、模型与技能名;
314
+ * 不带笔记、会话与任务——那是这位成员自己的经历。duty 由调用方按身份判定后传入。
315
+ */
316
+ export function talentFromMember(member, duty) {
317
+ const config = member?.config ?? {};
318
+ const provider = text(config.provider, 80);
319
+ const model = text(config.model, 160);
320
+ return {
321
+ name: text(member?.name, 40),
322
+ role: text(member?.role, 40),
323
+ duty: DUTIES.includes(duty) ? duty : 'executor',
324
+ category: '',
325
+ tags: [],
326
+ personality: text(member?.personality, 2000),
327
+ model: provider || model ? { provider, model, reasoningEffort: text(config.reasoningEffort, 20) } : null,
328
+ skills: (Array.isArray(member?.skills) ? member.skills : []).map((s) => text(String(s), 64)).filter((s) => SKILL_NAME.test(s)),
329
+ };
330
+ }
331
+
298
332
  /** 列出可安装的技能:当前目录里每个人才自带的技能(名字 + 来源人才),给「从已有装」挑。 */
299
333
  export function listInstallableSkills(catalog) {
300
334
  const out = [];
@@ -20,6 +20,32 @@ export function renderSkillVars(text, vars = {}) {
20
20
  });
21
21
  }
22
22
 
23
+ /** 技能名规范化(防路径穿越):只留文件名里的字母数字与 ._-,不合法返回空串。 */
24
+ export function skillFileName(raw) {
25
+ const name = basename(String(raw ?? '')).replace(/[^a-zA-Z0-9._-]/g, '');
26
+ return name === '' || name === '.' || name === '..' || name.startsWith('.') ? '' : name;
27
+ }
28
+
29
+ /**
30
+ * 按根的顺序找一份技能正文:`<root>/skills/<name>/SKILL.md` 或 `<root>/skills/<name>.md`,先到先得;
31
+ * 找不到返回 null。成员激活注入与「存为人才」拷技能共用这一份查找,保证拷出来的就是成员实际读到的。
32
+ */
33
+ export async function findSkillText(roots, raw) {
34
+ const name = skillFileName(raw);
35
+ if (name === '') return null;
36
+ for (const root of Array.isArray(roots) ? roots : [roots]) {
37
+ if (typeof root !== 'string' || root === '') continue;
38
+ for (const candidate of [join(root, 'skills', name, 'SKILL.md'), join(root, 'skills', `${name}.md`)]) {
39
+ try {
40
+ return await readFile(candidate, 'utf8');
41
+ } catch (error) {
42
+ if (error?.code !== 'ENOENT') break;
43
+ }
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+
23
49
  /**
24
50
  * Read bounded SKILL.md files for member-declared skills from the profile skill library.
25
51
  *
@@ -43,23 +69,10 @@ export async function loadSkillContext(member, dataDir, options = {}) {
43
69
  const roots = [preset?.dir, ...(Array.isArray(dataDir) ? dataDir : [dataDir])]
44
70
  .filter((root) => typeof root === 'string' && root !== '');
45
71
  for (const raw of skills.slice(0, 4)) {
46
- const name = basename(String(raw)).replace(/[^a-zA-Z0-9._-]/g, '');
47
- if (name === '' || name === '.' || name === '..' || name.startsWith('.')) continue;
48
- if (isSkillExcluded(name)) continue;
49
- for (const root of roots) {
50
- let loaded = false;
51
- for (const candidate of [join(root, 'skills', name, 'SKILL.md'), join(root, 'skills', `${name}.md`)]) {
52
- try {
53
- const text = await readFile(candidate, 'utf8');
54
- chunks.push(`### ${name}\n${text.slice(0, MAX_SKILL_CHARS)}`);
55
- loaded = true;
56
- break;
57
- } catch (error) {
58
- if (error?.code !== 'ENOENT') break;
59
- }
60
- }
61
- if (loaded) break;
62
- }
72
+ const name = skillFileName(raw);
73
+ if (name === '' || isSkillExcluded(name)) continue;
74
+ const text = await findSkillText(roots, name);
75
+ if (text !== null) chunks.push(`### ${name}\n${text.slice(0, MAX_SKILL_CHARS)}`);
63
76
  }
64
77
  return chunks.length === 0 ? '' : `\n\n[技能资料]\n${chunks.join('\n\n')}`;
65
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.125",
3
+ "version": "0.4.126",
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",