@suifei/dsh-ai-team 0.4.124 → 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 +35 -0
- package/README.md +2 -0
- package/client.js +155 -2
- package/index.js +104 -3
- package/lib/domain/catalog.js +111 -3
- package/lib/runtime/skill-loader.js +30 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
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
|
+
|
|
19
|
+
## 0.4.125 - 2026-11-18
|
|
20
|
+
|
|
21
|
+
**人才市场(第 2 步 2a):自定义智能体 + 安装 skill**
|
|
22
|
+
|
|
23
|
+
- 一个智能体 = 职责 + 性格 + 装上的若干技能。此前只能招内置人才;现在能从零造一个自己的人才,
|
|
24
|
+
按需装技能,存成可复用的人才,再招进项目——内置没有的角色也能自己攒出来;
|
|
25
|
+
- **catalog.js 增加「写」的唯一一份实现**(此前只读):`writeTalent` / `deleteTalent` / `installSkill` /
|
|
26
|
+
`readSkillText` / `listInstallableSkills` / `talentIdFrom` / `userCatalogDir`。校验复用 `parseTalent`
|
|
27
|
+
(先 `stringify` 再 `parse`,验不过就抛、绝不落盘),**只往用户根 `~/.dsh/ai-team/catalog/user/` 写,内置永不触碰**;
|
|
28
|
+
- **技能装进人才自己的文件夹** `talents/<id>/skills/<技能>/SKILL.md`——自包含、可打包、可分享(也是第 3 步在线库的最小单元)。
|
|
29
|
+
来源三选:从现成人才 fork、自写一份、导入 `.md` 文件;
|
|
30
|
+
- **新接口**:`POST /api/talents` 建/覆盖自定义人才(中文名自动生成兜底 id),`POST /api/talents/delete`,
|
|
31
|
+
`POST /api/talents/:id/skills` 装技能(`markdown` 自写 / `fromTalent`+`fromSkill` fork),
|
|
32
|
+
`GET /api/skills-install` 列可装技能,`GET /api/skills-install/content` 读技能正文;内置人才只读,装/删都回 `409 E_READONLY`;
|
|
33
|
+
- **界面**:「添加成员」弹窗加「新建人才」页——填名号/岗位/职责/分类/标签/性格,技能区三选装、可移除,「存为我的人才」后进市场;
|
|
34
|
+
- 诊断埋点 `talent.write` / `talent.delete` / `talent.skill.install`;
|
|
35
|
+
- 测试:`test/talent-routes.test.js`(进程内起 server 真打全部接口:建人才、自写装、从内置 fork、只读守卫、中文名兜底、删除);
|
|
36
|
+
`test/client-talent-market.test.js` 补 `talentFormToBody` / `blankTalentForm` 纯函数单测。
|
|
37
|
+
|
|
3
38
|
## 0.4.124 - 2026-11-18
|
|
4
39
|
|
|
5
40
|
**人才市场(第 1 步):人才 → 团队 → 项目成员**
|
package/README.md
CHANGED
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
- 团队 `teams/<团队>/team.yml`:只引用人才(可覆盖名字、岗位、性格,追加技能),`skills/` 放这个团队的三份岗位规程(`ai-team-core` / `ai-team-qa` / `ai-team-executor`),`procedures` 可换成自己的规程。内置默认团队见 [`teams/default/`](teams/default/)。还预置了**逆向工程队** [`teams/reverse/`](teams/reverse/):静态分析、动态调试、OLLVM 去混淆、移动端逆向、算法复刻与行为对账(`teamPreset: reverse` 启用)。此外预置了文档(`docs`)、视频(`video`)、游戏(`game`)、自媒体写作(`content`)、深度研究(`research`)、科学研究(`science`)、中小学教育软件(`education`)等团队,共 44 位人才可在人才市场挑选、组合或自建。
|
|
30
30
|
- 「人员 → 添加成员」先打开人才市场:按分类、关键词挑一位,点「招聘」预填表单,改名、换模型后创建;也可以切到「自定义」从零填写。
|
|
31
31
|
- 自建:人才放 `~/.dsh/ai-team/catalog/user/talents/<人才>/`,团队放 `~/.dsh/ai-team/catalog/user/teams/<团队>/`,同名覆盖内置;插件设置 `teamPreset` 选新项目用哪个团队。
|
|
32
|
+
- **新建自定义人才(界面)**:「添加成员 → 新建人才」填名号、岗位、职责、性格,再按需装技能——从现成人才 fork、自写一份、或导入 `.md`,存成可复用的人才(落用户根)。内置没有的角色能自己攒;技能装进人才自己的文件夹,自包含、可分享。走 `POST /api/talents` 与 `POST /api/talents/:id/skills`,内置只读、装删回 `409`。
|
|
33
|
+
- **存为人才**:成员资料「存为人才」把项目里这位成员此刻的岗位、职责、性格、模型与技能存成可复用的人才(技能按成员实际读取的路径拷进人才文件夹,找不到正文的会提示),换个项目照样招。新建与存为都不会静默覆盖已有人才,撞名自动加序号。
|
|
32
34
|
- 成员在账本里记下来源人才与版本、职责;人才文件之后再改,不会悄悄改动已招成员的性格与职责。已有项目不受新团队影响。文件写坏时跳过它并在诊断日志记 `catalog.load.fail` / `catalog.team.fail`。
|
|
33
35
|
|
|
34
36
|
---
|
package/client.js
CHANGED
|
@@ -296,6 +296,12 @@ window.__ModuleLoader__.load({
|
|
|
296
296
|
talentSearch: '搜索名字、岗位、技能…',
|
|
297
297
|
talentAll: '全部',
|
|
298
298
|
talentHire: '招聘',
|
|
299
|
+
talentCreate: '新建人才',
|
|
300
|
+
tcHint: '填好职责与性格,按需装几份技能,存成可复用的人才。',
|
|
301
|
+
tcName: '名号', tcRole: '岗位', tcDuty: '职责', tcCategory: '分类', tcTags: '标签', tcTagsHint: '逗号分隔', tcPersonality: '性格', tcPersonalityHint: '它怎么做事、什么风格',
|
|
302
|
+
tcSkills: '技能', tcEmpty: '还没装技能(可选)', tcAddExisting: '从已有装', tcWriteOwn: '自写一份', tcImport: '导入 .md', tcPick: '选一个已有技能…', tcAdd: '加入', tcRemove: '移除',
|
|
303
|
+
tcSkillName: '技能名(英文/数字/-)', tcSkillBody: '技能正文(SKILL.md)', tcSkillDup: '已经装了同名技能', tcSave: '存为我的人才', tcSaving: '保存中…',
|
|
304
|
+
memberSaveAsTalent: '存为人才', tcFromMember: '从成员「{name}」存出:沿用它此刻的岗位、职责、性格与技能,可先修改再保存。', tcModelKept: '沿用模型:{model}', tcMissing: '这些技能找不到正文,没有带上:{skills}', tcDraftFailed: '读取成员草稿失败:{error}',
|
|
299
305
|
talentEmpty: '没有符合条件的人才。',
|
|
300
306
|
talentLoading: '正在读取人才市场…',
|
|
301
307
|
talentLoadFailed: '人才市场读取失败:{error}',
|
|
@@ -739,6 +745,12 @@ window.__ModuleLoader__.load({
|
|
|
739
745
|
talentSearch: 'Search name, role, skill…',
|
|
740
746
|
talentAll: 'All',
|
|
741
747
|
talentHire: 'Hire',
|
|
748
|
+
talentCreate: 'New talent',
|
|
749
|
+
tcHint: 'Set the duty and personality, install a few skills, save a reusable talent.',
|
|
750
|
+
tcName: 'Name', tcRole: 'Role', tcDuty: 'Duty', tcCategory: 'Category', tcTags: 'Tags', tcTagsHint: 'comma-separated', tcPersonality: 'Personality', tcPersonalityHint: 'how it works, its style',
|
|
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',
|
|
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}',
|
|
742
754
|
talentEmpty: 'No talent matches.',
|
|
743
755
|
talentLoading: 'Loading the talent market…',
|
|
744
756
|
talentLoadFailed: 'Could not load the talent market: {error}',
|
|
@@ -1378,6 +1390,11 @@ window.__ModuleLoader__.load({
|
|
|
1378
1390
|
.at-modaltitle { margin: 0 0 2px; font-size: 15px; font-weight: 600; color: var(--dsw-alias-label-primary); }
|
|
1379
1391
|
.at-modal.at-modal-wide { width: min(640px, 100%); }
|
|
1380
1392
|
.at-addtabs { align-self: flex-start; }
|
|
1393
|
+
.at-tcskills { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
1394
|
+
.at-tcskill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: rgba(127,127,127,0.15); font-size: 12px; }
|
|
1395
|
+
.at-tcskill button { border: 0; background: transparent; cursor: pointer; font-size: 14px; line-height: 1; color: inherit; padding: 0; }
|
|
1396
|
+
.at-tcpick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
|
|
1397
|
+
.at-tcpanel { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
|
|
1381
1398
|
.at-market { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
|
|
1382
1399
|
.at-marketsearch { width: 100%; padding: 6px 8px; border: 1px solid var(--dsw-alias-border-l2); border-radius: var(--dsw-radius-sm); background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); font: inherit; font-size: 12px; }
|
|
1383
1400
|
.at-marketcats { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
@@ -2723,6 +2740,93 @@ window.__ModuleLoader__.load({
|
|
|
2723
2740
|
h('div', { className: 'at-modalactions' },
|
|
2724
2741
|
h('button', { className: 'at-btn', type: 'button', onClick: onCancel }, t('cancel'))));
|
|
2725
2742
|
}
|
|
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 : []));
|
|
2747
|
+
const [installable, setInstallable] = React.useState([]);
|
|
2748
|
+
const [pick, setPick] = React.useState('');
|
|
2749
|
+
const [pickFrom, setPickFrom] = React.useState('');
|
|
2750
|
+
const [skName, setSkName] = React.useState('');
|
|
2751
|
+
const [skBody, setSkBody] = React.useState('');
|
|
2752
|
+
const [busy, setBusy] = React.useState(false);
|
|
2753
|
+
const [error, setError] = React.useState('');
|
|
2754
|
+
const set = (key) => (event) => setForm((f) => ({ ...f, [key]: event.target.value }));
|
|
2755
|
+
React.useEffect(() => {
|
|
2756
|
+
let live = true;
|
|
2757
|
+
fetch('/ai-team/api/skills-install', { headers: { accept: 'application/json' } })
|
|
2758
|
+
.then((r) => r.json()).then((b) => { if (live) setInstallable(Array.isArray(b && b.skills) ? b.skills : []); })
|
|
2759
|
+
.catch(() => {});
|
|
2760
|
+
return () => { live = false; };
|
|
2761
|
+
}, []);
|
|
2762
|
+
function stage(skill) {
|
|
2763
|
+
if (pending.some((x) => x.name === skill.name)) { setError(t('tcSkillDup')); return false; }
|
|
2764
|
+
setPending((pp) => [...pp, skill]); setError(''); return true;
|
|
2765
|
+
}
|
|
2766
|
+
function addExisting() {
|
|
2767
|
+
const sep = String(pickFrom).indexOf('::'); if (sep < 0) return;
|
|
2768
|
+
const talent = pickFrom.slice(0, sep); const name = pickFrom.slice(sep + 2);
|
|
2769
|
+
if (stage({ name, kind: 'fork', fromTalent: talent, fromSkill: name })) { setPick(''); setPickFrom(''); }
|
|
2770
|
+
}
|
|
2771
|
+
function addWritten() {
|
|
2772
|
+
const name = skName.trim(); if (!name) return;
|
|
2773
|
+
if (stage({ name, kind: 'write', markdown: skBody })) { setPick(''); setSkName(''); setSkBody(''); }
|
|
2774
|
+
}
|
|
2775
|
+
function importFile(event) {
|
|
2776
|
+
const file = event.target.files && event.target.files[0]; if (!file) return;
|
|
2777
|
+
const reader = new FileReader();
|
|
2778
|
+
reader.onload = () => {
|
|
2779
|
+
const name = (file.name.replace(/\.md$/i, '').replace(/[^A-Za-z0-9._-]/g, '-').slice(0, 64)) || 'skill';
|
|
2780
|
+
stage({ name, kind: 'write', markdown: String(reader.result || '') });
|
|
2781
|
+
};
|
|
2782
|
+
reader.readAsText(file); event.target.value = '';
|
|
2783
|
+
}
|
|
2784
|
+
async function save() {
|
|
2785
|
+
if (!form.name.trim() || busy) return;
|
|
2786
|
+
setBusy(true); setError('');
|
|
2787
|
+
try {
|
|
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 } : {}) }) });
|
|
2789
|
+
const body = await res.json().catch(() => null);
|
|
2790
|
+
if (!res.ok) throw new Error((body && body.error && body.error.message) || ('HTTP ' + res.status));
|
|
2791
|
+
const id = body && body.talent && body.talent.id;
|
|
2792
|
+
for (const sk of pending) {
|
|
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 };
|
|
2794
|
+
const r2 = await fetch('/ai-team/api/talents/' + encodeURIComponent(id) + '/skills', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(payload) });
|
|
2795
|
+
const b2 = await r2.json().catch(() => null);
|
|
2796
|
+
if (!r2.ok) throw new Error(((b2 && b2.error && b2.error.message) || ('HTTP ' + r2.status)) + '(' + sk.name + ')');
|
|
2797
|
+
}
|
|
2798
|
+
onSaved();
|
|
2799
|
+
} catch (err) {
|
|
2800
|
+
setError((err && err.message) || String(err));
|
|
2801
|
+
} finally {
|
|
2802
|
+
setBusy(false);
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
return h('div', { className: 'at-market' },
|
|
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,
|
|
2811
|
+
h('label', { className: 'at-field' }, h('span', null, t('tcName')), h('input', { value: form.name, onChange: set('name'), autoFocus: true })),
|
|
2812
|
+
h('label', { className: 'at-field' }, h('span', null, t('tcRole')), h('input', { value: form.role, onChange: set('role') })),
|
|
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]))))),
|
|
2814
|
+
h('label', { className: 'at-field' }, h('span', null, t('tcCategory')), h('input', { value: form.category, onChange: set('category') })),
|
|
2815
|
+
h('label', { className: 'at-field' }, h('span', null, t('tcTags')), h('input', { value: form.tags, onChange: set('tags'), placeholder: t('tcTagsHint') })),
|
|
2816
|
+
h('label', { className: 'at-field' }, h('span', null, t('tcPersonality')), h('textarea', { value: form.personality, onChange: set('personality'), placeholder: t('tcPersonalityHint') })),
|
|
2817
|
+
h('div', { className: 'at-field' }, h('span', null, t('tcSkills')),
|
|
2818
|
+
pending.length === 0 ? h('div', { className: 'at-modalmeta' }, t('tcEmpty')) : h('div', { className: 'at-tcskills' }, pending.map((sk) => h('span', { key: sk.name, className: 'at-tcskill' }, sk.name, h('button', { type: 'button', 'aria-label': t('tcRemove'), onClick: () => setPending((pp) => pp.filter((x) => x.name !== sk.name)) }, '×')))),
|
|
2819
|
+
h('div', { className: 'at-tcpick' },
|
|
2820
|
+
h('button', { type: 'button', className: 'at-btn', onClick: () => setPick(pick === 'existing' ? '' : 'existing') }, t('tcAddExisting')),
|
|
2821
|
+
h('button', { type: 'button', className: 'at-btn', onClick: () => setPick(pick === 'write' ? '' : 'write') }, t('tcWriteOwn')),
|
|
2822
|
+
h('label', { className: 'at-btn' }, t('tcImport'), h('input', { type: 'file', accept: '.md,text/markdown,text/plain', style: { display: 'none' }, onChange: importFile }))),
|
|
2823
|
+
pick === 'existing' ? h('div', { className: 'at-tcpanel' }, h('select', { value: pickFrom, onChange: (e) => setPickFrom(e.target.value) }, h('option', { value: '' }, t('tcPick')), installable.map((sk) => h('option', { key: sk.talent + '::' + sk.name, value: sk.talent + '::' + sk.name }, sk.name + ' — ' + sk.talentName))), h('button', { type: 'button', className: 'at-btn at-btn-primary', onClick: addExisting }, t('tcAdd'))) : null,
|
|
2824
|
+
pick === 'write' ? h('div', { className: 'at-tcpanel' }, h('input', { value: skName, placeholder: t('tcSkillName'), onChange: (e) => setSkName(e.target.value) }), h('textarea', { value: skBody, placeholder: t('tcSkillBody'), onChange: (e) => setSkBody(e.target.value) }), h('button', { type: 'button', className: 'at-btn at-btn-primary', onClick: addWritten }, t('tcAdd'))) : null),
|
|
2825
|
+
error ? h('div', { className: 'at-modalerror', role: 'alert' }, error) : null,
|
|
2826
|
+
h('div', { className: 'at-modalactions' },
|
|
2827
|
+
h('button', { type: 'button', className: 'at-btn', onClick: onCancel }, t('cancel')),
|
|
2828
|
+
h('button', { type: 'button', className: 'at-btn at-btn-primary', disabled: !form.name.trim() || busy, onClick: save }, busy ? t('tcSaving') : t('tcSave'))));
|
|
2829
|
+
}
|
|
2726
2830
|
function ModelFields({ t, catalog, provider, model, effort, onEffort, onProvider, onModel, error }) {
|
|
2727
2831
|
const providers = Array.isArray(catalog?.providers) ? catalog.providers.slice() : [];
|
|
2728
2832
|
// 推理等级按「提供商 + 模型」按需解析:不同模型支持的档位不同,宿主也随时可能
|
|
@@ -2977,6 +3081,35 @@ window.__ModuleLoader__.load({
|
|
|
2977
3081
|
.some((field) => String(field ?? '').toLowerCase().includes(q));
|
|
2978
3082
|
});
|
|
2979
3083
|
}
|
|
3084
|
+
function blankTalentForm() {
|
|
3085
|
+
return { name: '', role: '', duty: 'executor', category: '', tags: '', personality: '' };
|
|
3086
|
+
}
|
|
3087
|
+
/** 新建人才表单 → POST /api/talents 的请求体:标签按逗号/顿号/空白拆开,职责只认三种。 */
|
|
3088
|
+
function talentFormToBody(form) {
|
|
3089
|
+
const tags = String((form && form.tags) || '').split(/[,,、\s]+/).map((x) => x.trim()).filter(Boolean);
|
|
3090
|
+
return {
|
|
3091
|
+
name: String((form && form.name) || '').trim(),
|
|
3092
|
+
role: String((form && form.role) || '').trim(),
|
|
3093
|
+
duty: ['lead', 'qa', 'executor'].includes(form && form.duty) ? form.duty : 'executor',
|
|
3094
|
+
category: String((form && form.category) || '').trim(),
|
|
3095
|
+
tags,
|
|
3096
|
+
personality: String((form && form.personality) || '').trim(),
|
|
3097
|
+
};
|
|
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
|
+
}
|
|
2980
3113
|
// </member-copy>
|
|
2981
3114
|
|
|
2982
3115
|
// <composer-rich>
|
|
@@ -3107,6 +3240,8 @@ window.__ModuleLoader__.load({
|
|
|
3107
3240
|
const [talentError, setTalentError] = React.useState('');
|
|
3108
3241
|
const [talentQuery, setTalentQuery] = React.useState('');
|
|
3109
3242
|
const [talentCategory, setTalentCategory] = React.useState('');
|
|
3243
|
+
// 「存为人才」:成员草稿(服务端生成),预填新建人才页。
|
|
3244
|
+
const [talentInit, setTalentInit] = React.useState(null);
|
|
3110
3245
|
const [mName, setMName] = React.useState('');
|
|
3111
3246
|
const [mRole, setMRole] = React.useState('');
|
|
3112
3247
|
const [mPrompt, setMPrompt] = React.useState('');
|
|
@@ -3943,6 +4078,7 @@ window.__ModuleLoader__.load({
|
|
|
3943
4078
|
setMCopy(null);
|
|
3944
4079
|
setMError('');
|
|
3945
4080
|
setMTab('market');
|
|
4081
|
+
setTalentInit(null);
|
|
3946
4082
|
setTalentQuery('');
|
|
3947
4083
|
setTalentCategory('');
|
|
3948
4084
|
setAddOpen(true);
|
|
@@ -3988,6 +4124,21 @@ window.__ModuleLoader__.load({
|
|
|
3988
4124
|
setMError('');
|
|
3989
4125
|
setAddOpen(true);
|
|
3990
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
|
+
}
|
|
3991
4142
|
async function createAgent() {
|
|
3992
4143
|
if (!mName.trim() || mBusy) return;
|
|
3993
4144
|
setMBusy(true);
|
|
@@ -4951,7 +5102,8 @@ window.__ModuleLoader__.load({
|
|
|
4951
5102
|
h('h2', { className: 'at-modaltitle' }, mCopy && !mCopy.talent ? t('memberCopy') : t('addAgentTitle')),
|
|
4952
5103
|
mCopy && !mCopy.talent ? null : h('div', { className: 'at-mode at-addtabs', role: 'group', 'aria-label': t('addAgentTitle') },
|
|
4953
5104
|
h('button', { type: 'button', 'aria-pressed': mTab === 'market' ? 'true' : 'false', onClick: () => setMTab('market') }, t('talentMarket')),
|
|
4954
|
-
h('button', { type: 'button', 'aria-pressed': mTab === 'custom' ? 'true' : 'false', onClick: () => setMTab('custom') }, t('talentCustom'))
|
|
5105
|
+
h('button', { type: 'button', 'aria-pressed': mTab === 'custom' ? 'true' : 'false', onClick: () => setMTab('custom') }, t('talentCustom')),
|
|
5106
|
+
h('button', { type: 'button', 'aria-pressed': mTab === 'create' ? 'true' : 'false', onClick: () => setMTab('create') }, t('talentCreate'))),
|
|
4955
5107
|
mTab === 'market' && !(mCopy && !mCopy.talent) ? h(TalentMarket, {
|
|
4956
5108
|
t,
|
|
4957
5109
|
talents,
|
|
@@ -4962,7 +5114,7 @@ window.__ModuleLoader__.load({
|
|
|
4962
5114
|
onCategory: setTalentCategory,
|
|
4963
5115
|
onHire: hireTalent,
|
|
4964
5116
|
onCancel: () => setAddOpen(false),
|
|
4965
|
-
}) : [
|
|
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); } }) : [
|
|
4966
5118
|
mCopy?.talent ? h('div', { key: 'from', className: 'at-modalmeta' }, tf(t, 'memberHireFrom', { name: mCopy.sourceName, version: mCopy.talent.version })) : null,
|
|
4967
5119
|
mCopy && !mCopy.talent ? h('div', { key: 'from', className: 'at-modalmeta' }, tf(t, 'memberCopyFrom', { name: mCopy.sourceName })) : null,
|
|
4968
5120
|
h('label', { key: 'name', className: 'at-field' }, h('span', null, t('memberName')),
|
|
@@ -5076,6 +5228,7 @@ window.__ModuleLoader__.load({
|
|
|
5076
5228
|
h('button', { className: 'at-btn', type: 'button', onClick: () => { const target = profileAgent; setProfileAgent(null); openMemberView(target); } }, t('memberTasks')),
|
|
5077
5229
|
h('button', { className: 'at-btn', type: 'button', onClick: () => { const target = profileAgent; setProfileAgent(null); void openAgentChat(target); } }, t('agentChat')),
|
|
5078
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')),
|
|
5079
5232
|
h('button', { className: 'at-btn', type: 'button', onClick: leaveProfile, disabled: pBusy }, t('leaveTeam')),
|
|
5080
5233
|
profileAgent.status === 'failed' ? h('button', { className: 'at-btn', type: 'button', onClick: retryProfile, disabled: pBusy }, t('retry')) : null,
|
|
5081
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, listTalents, loadCatalog, resolveTeam } 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,
|
|
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,96 @@ 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
|
+
}
|
|
2393
|
+
// 可安装的技能清单(每个人才自带的技能),给「从已有装」挑。
|
|
2394
|
+
if (req.method === 'GET' && url.pathname === '/ai-team/api/skills-install') {
|
|
2395
|
+
return send(res, { skills: listInstallableSkills(talentCatalog(diag)) });
|
|
2396
|
+
}
|
|
2397
|
+
// 某人才自带技能的正文(预览 / fork 前读)。
|
|
2398
|
+
if (req.method === 'GET' && url.pathname === '/ai-team/api/skills-install/content') {
|
|
2399
|
+
const cat = talentCatalog(diag);
|
|
2400
|
+
const t = cat.talents.get(url.searchParams.get('talent') ?? '');
|
|
2401
|
+
if (t === undefined) return send(res, { error: { code: 'NOT_FOUND', message: 'talent not found' } }, 404);
|
|
2402
|
+
try {
|
|
2403
|
+
return send(res, { markdown: readSkillText(t.dir, url.searchParams.get('name') ?? '') });
|
|
2404
|
+
} catch (error) {
|
|
2405
|
+
return send(res, { error: { code: 'NOT_FOUND', message: error.message } }, 404);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
// 新建 / 覆盖一个用户自定义人才(只写用户根;内置只读)。
|
|
2409
|
+
if (req.method === 'POST' && url.pathname === '/ai-team/api/talents') {
|
|
2410
|
+
const body = await readJson(req);
|
|
2411
|
+
// 显式 id 优先,其次按名字派生;中文名派生为空时生成兜底 id(纯中文名也能建)。
|
|
2412
|
+
let id = talentIdFrom(body?.id) || talentIdFrom(body?.name);
|
|
2413
|
+
if (id === '' && typeof body?.name === 'string' && body.name.trim() !== '') id = 'talent-' + Date.now().toString(36) + Math.random().toString(36).slice(2, 5);
|
|
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);
|
|
2418
|
+
try {
|
|
2419
|
+
const saved = writeTalent(userCatalogDir(dshHome()), id, body ?? {});
|
|
2420
|
+
diag?.append({ ev: 'talent.write', id, source: 'user' });
|
|
2421
|
+
return send(res, { ok: true, talent: { id: saved.id, source: saved.source, version: saved.version, name: saved.name, role: saved.role, duty: saved.duty, category: saved.category, tags: saved.tags, description: saved.description, personality: saved.personality, skills: saved.skills, model: saved.model } });
|
|
2422
|
+
} catch (error) {
|
|
2423
|
+
return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: error.message } }, 400);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
// 删一个用户自定义人才(只删用户根的)。
|
|
2427
|
+
if (req.method === 'POST' && url.pathname === '/ai-team/api/talents/delete') {
|
|
2428
|
+
const body = await readJson(req);
|
|
2429
|
+
const cat = talentCatalog(diag);
|
|
2430
|
+
const t = cat.talents.get(talentIdFrom(body?.id ?? ''));
|
|
2431
|
+
if (t === undefined) return send(res, { error: { code: 'NOT_FOUND', message: 'talent not found' } }, 404);
|
|
2432
|
+
if (t.source !== 'user') return send(res, { error: { code: 'E_READONLY', message: '内置人才只读,不能删除;它只会被同名的自定义人才遮盖' } }, 409);
|
|
2433
|
+
deleteTalent(userCatalogDir(dshHome()), t.id);
|
|
2434
|
+
diag?.append({ ev: 'talent.delete', id: t.id });
|
|
2435
|
+
return send(res, { ok: true });
|
|
2436
|
+
}
|
|
2437
|
+
// 往某用户人才装一份技能:自写(markdown)或从现成人才 fork(fromTalent + fromSkill)。
|
|
2438
|
+
const talentSkillRoute = url.pathname.match(/^\/ai-team\/api\/talents\/([^/]+)\/skills$/);
|
|
2439
|
+
if (req.method === 'POST' && talentSkillRoute !== null) {
|
|
2440
|
+
const body = await readJson(req);
|
|
2441
|
+
const cat = talentCatalog(diag);
|
|
2442
|
+
const t = cat.talents.get(decodeURIComponent(talentSkillRoute[1]));
|
|
2443
|
+
if (t === undefined) return send(res, { error: { code: 'NOT_FOUND', message: 'talent not found' } }, 404);
|
|
2444
|
+
if (t.source !== 'user') return send(res, { error: { code: 'E_READONLY', message: '内置人才只读;先把它存为自己的人才再装技能' } }, 409);
|
|
2445
|
+
let markdown = typeof body?.markdown === 'string' ? body.markdown : null;
|
|
2446
|
+
if (markdown === null && typeof body?.fromTalent === 'string' && typeof body?.fromSkill === 'string') {
|
|
2447
|
+
const src = cat.talents.get(body.fromTalent);
|
|
2448
|
+
if (src === undefined) return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: '来源人才不存在' } }, 400);
|
|
2449
|
+
try { markdown = readSkillText(src.dir, body.fromSkill); } catch (error) { return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: error.message } }, 400); }
|
|
2450
|
+
}
|
|
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);
|
|
2461
|
+
try {
|
|
2462
|
+
const name = installSkill(t.dir, body?.name, markdown);
|
|
2463
|
+
const saved = writeTalent(userCatalogDir(dshHome()), t.id, { ...t, skills: [...new Set([...t.skills, name])] });
|
|
2464
|
+
diag?.append({ ev: 'talent.skill.install', id: t.id, skill: name, from: body?.fromTalent ?? null });
|
|
2465
|
+
return send(res, { ok: true, skill: name, talent: { id: saved.id, source: saved.source, skills: saved.skills } });
|
|
2466
|
+
} catch (error) {
|
|
2467
|
+
return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: error.message } }, 400);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2369
2470
|
if (req.method === 'GET' && url.pathname === '/ai-team/api/models') {
|
|
2370
2471
|
const catalog = await buildModelCatalog(serviceOf(ctx, 'llm'), serviceOf(ctx, 'agentDefaultModel'));
|
|
2371
2472
|
return send(res, catalog);
|
package/lib/domain/catalog.js
CHANGED
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
* 文件写坏不阻断:记一行 `.fail` 诊断,跳过它(更低优先级的同名条目顶上)。
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
15
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
16
16
|
import { join } from 'node:path';
|
|
17
17
|
import { fileURLToPath } from 'node:url';
|
|
18
|
-
import { parse } from 'yaml';
|
|
18
|
+
import { parse, stringify } from 'yaml';
|
|
19
19
|
|
|
20
20
|
/** 插件内置目录(包根,下有 talents/ 与 teams/)。 */
|
|
21
21
|
export const BUNDLED_CATALOG_DIR = fileURLToPath(new URL('../../', import.meta.url));
|
|
@@ -137,10 +137,16 @@ export function parseTeam(source, label = 'team') {
|
|
|
137
137
|
return { name: text(doc.name, 60), description: text(doc.description, 400), lead, procedures, members };
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
/** 用户自建目录(可写),自定义人才与自建团队都落在这里。 */
|
|
141
|
+
export function userCatalogDir(dshHome) {
|
|
142
|
+
if (typeof dshHome !== 'string' || dshHome === '') throw new Error('userCatalogDir: 需要 dshHome');
|
|
143
|
+
return join(dshHome, 'ai-team', 'catalog', 'user');
|
|
144
|
+
}
|
|
145
|
+
|
|
140
146
|
/** 用户自建目录 + 插件内置目录(第 3 步在两者之间插入官方在线库)。 */
|
|
141
147
|
export function catalogRoots({ dshHome, bundledDir = BUNDLED_CATALOG_DIR } = {}) {
|
|
142
148
|
return [
|
|
143
|
-
...(typeof dshHome === 'string' && dshHome !== '' ? [{ source: 'user', dir:
|
|
149
|
+
...(typeof dshHome === 'string' && dshHome !== '' ? [{ source: 'user', dir: userCatalogDir(dshHome) }] : []),
|
|
144
150
|
{ source: 'bundled', dir: bundledDir },
|
|
145
151
|
];
|
|
146
152
|
}
|
|
@@ -227,3 +233,105 @@ export function procedureText(preset, kind, { bundledDir = BUNDLED_CATALOG_DIR }
|
|
|
227
233
|
for (const file of candidates) if (existsSync(file)) return readFileSync(file, 'utf8');
|
|
228
234
|
throw new Error(`bundled procedure missing: ${candidates.at(-1)}`);
|
|
229
235
|
}
|
|
236
|
+
|
|
237
|
+
// —— 写层(第 2 步 2a:安装 skill + 新建自定义人才)——
|
|
238
|
+
// 只往用户根写,内置永不触碰;同名用户条目遮盖内置即「覆盖」。校验复用 parseTalent:
|
|
239
|
+
// 先 stringify 再 parse,验不过就抛、绝不落盘,保证盘上的文件一定能被 loadCatalog 读回。
|
|
240
|
+
|
|
241
|
+
/** 规范人才 id:小写字母、数字、连字符,≤64 位(与扫描用的 SLUG 同一把尺)。 */
|
|
242
|
+
export function talentIdFrom(value) {
|
|
243
|
+
const id = text(value, 64).toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '').replace(/-{2,}/g, '-');
|
|
244
|
+
return SLUG.test(id) ? id : '';
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function talentDoc(input) {
|
|
248
|
+
const doc = { version: text(String(input?.version ?? '1.0.0'), 32) || '1.0.0', name: text(input?.name, 40), role: text(input?.role, 40) };
|
|
249
|
+
if (input?.duty) doc.duty = input.duty;
|
|
250
|
+
if (text(input?.category, 20)) doc.category = text(input.category, 20);
|
|
251
|
+
const tags = Array.isArray(input?.tags) ? input.tags.map((t) => text(String(t), 20)).filter(Boolean).slice(0, 12) : [];
|
|
252
|
+
if (tags.length) doc.tags = tags;
|
|
253
|
+
if (text(input?.description, 400)) doc.description = text(input.description, 400);
|
|
254
|
+
if (text(input?.personality, 2000)) doc.personality = text(input.personality, 2000);
|
|
255
|
+
const skills = skillList(input?.skills, 'skills');
|
|
256
|
+
if (skills.length) doc.skills = skills;
|
|
257
|
+
const m = input?.model;
|
|
258
|
+
if (m && (text(m.provider, 80) || text(m.model, 160))) doc.model = { provider: text(m.provider, 80), model: text(m.model, 160), reasoningEffort: text(m.reasoningEffort, 20) };
|
|
259
|
+
return doc;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* 写一个用户自定义人才:`<userRoot>/talents/<id>/talent.yml`。校验不过时抛错、不落盘。
|
|
264
|
+
* @returns {{ id: string, source: 'user', dir: string } & ReturnType<typeof parseTalent>}
|
|
265
|
+
*/
|
|
266
|
+
export function writeTalent(userRoot, id, input) {
|
|
267
|
+
if (typeof userRoot !== 'string' || userRoot === '') throw new Error('writeTalent: 需要 userRoot');
|
|
268
|
+
if (typeof id !== 'string' || !SLUG.test(id)) throw new Error('人才 id 必须是小写字母、数字、连字符,≤64 位');
|
|
269
|
+
const yaml = stringify(talentDoc(input), { lineWidth: 0 });
|
|
270
|
+
const talent = parseTalent(yaml, `talent ${id}`); // 先验后写
|
|
271
|
+
const dir = join(userRoot, 'talents', id);
|
|
272
|
+
mkdirSync(dir, { recursive: true });
|
|
273
|
+
writeFileSync(join(dir, 'talent.yml'), yaml, 'utf8');
|
|
274
|
+
return { id, source: 'user', dir, ...talent };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** 删一个用户自定义人才(连同自带技能)。只删用户根下的。 */
|
|
278
|
+
export function deleteTalent(userRoot, id) {
|
|
279
|
+
if (typeof id !== 'string' || !SLUG.test(id)) throw new Error('人才 id 不合法');
|
|
280
|
+
rmSync(join(userRoot, 'talents', id), { recursive: true, force: true });
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** 把一份技能装进某人才自己的文件夹:`<talentDir>/skills/<name>/SKILL.md`。返回规范后的技能名。 */
|
|
284
|
+
export function installSkill(talentDir, name, markdown) {
|
|
285
|
+
if (typeof talentDir !== 'string' || talentDir === '') throw new Error('installSkill: 需要 talentDir');
|
|
286
|
+
const safe = skillName(name, '技能名');
|
|
287
|
+
const dir = join(talentDir, 'skills', safe);
|
|
288
|
+
mkdirSync(dir, { recursive: true });
|
|
289
|
+
writeFileSync(join(dir, 'SKILL.md'), typeof markdown === 'string' ? markdown : '', 'utf8');
|
|
290
|
+
return safe;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** 读某人才自带技能的正文(给预览与 fork)。 */
|
|
294
|
+
export function readSkillText(talentDir, name) {
|
|
295
|
+
return readFileSync(join(talentDir, 'skills', skillName(name, '技能名'), 'SKILL.md'), 'utf8');
|
|
296
|
+
}
|
|
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
|
+
|
|
332
|
+
/** 列出可安装的技能:当前目录里每个人才自带的技能(名字 + 来源人才),给「从已有装」挑。 */
|
|
333
|
+
export function listInstallableSkills(catalog) {
|
|
334
|
+
const out = [];
|
|
335
|
+
for (const t of catalog.talents.values()) for (const name of t.skills) out.push({ name, talent: t.id, talentName: t.name, source: t.source });
|
|
336
|
+
return out.sort((a, b) => a.name.localeCompare(b.name) || a.talent.localeCompare(b.talent));
|
|
337
|
+
}
|
|
@@ -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 =
|
|
47
|
-
if (name === '' || name
|
|
48
|
-
|
|
49
|
-
|
|
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.
|
|
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",
|