@suifei/dsh-ai-team 0.4.85 → 0.4.87

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/index.js CHANGED
@@ -27,7 +27,7 @@ import { memberIdentity } from './lib/domain/member-profile.js';
27
27
  import { loadSkillContext } from './lib/runtime/skill-loader.js';
28
28
  import { formatSkillCatalog } from './lib/runtime/skill-catalog.js';
29
29
  import { isSkillExcluded } from './lib/runtime/skill-policy.js';
30
- import { installFileSkillProvider } from './lib/runtime/skill-provider.js';
30
+ import { installFileSkillProvider, pickProjectForCwd } from './lib/runtime/skill-provider.js';
31
31
  import { apply as applySkillOpt } from './lib/vendor/skillopt/src/index.js';
32
32
  import { createAdoptGate, wrapToolsWithAdoptGate } from './lib/skillopt/adopt-gate.js';
33
33
  import { wrapToolsWithSkilloptAccess } from './lib/skillopt/tool-access.js';
@@ -747,6 +747,16 @@ export function apply(ctx, config = {}) {
747
747
  // runtime.dir(账本目录)兜底,曾把成员会话 cwd 钉进插件数据目录。
748
748
  // 技能里的 {{GOAL}}:项目目标来自账本 projects[id].goal;没填就明说,不要让成员
749
749
  // 对着一行空白猜(这也是 {{GOAL}} 之前"原样出现"的替代品)。
750
+ // cwd → 项目:技能 provider 的 get() 只拿得到 cwd,用它反查所属项目,
751
+ // 才能把 `{{GOAL}}` 渲染成那个项目的目标。
752
+ const projectForCwd = (cwd) => {
753
+ const projects = [];
754
+ for (const runtime of booted?.runtimes?.values() ?? []) {
755
+ const project = runtime?.service?.state?.projects?.[runtime.id];
756
+ if (project !== undefined) projects.push(project);
757
+ }
758
+ return pickProjectForCwd(projects, cwd);
759
+ };
750
760
  const goalForProject = (projectRuntime) => {
751
761
  const goal = projectRuntime?.service?.state?.projects?.[projectRuntime?.id]?.goal;
752
762
  const text = typeof goal === 'string' ? goal.trim() : '';
@@ -1302,6 +1312,17 @@ export function apply(ctx, config = {}) {
1302
1312
  dshHome: dshHome(),
1303
1313
  projectCwd: process.cwd(),
1304
1314
  bundledDir: fileURLToPath(new URL('./', import.meta.url)),
1315
+ // 成员用 `skill` 工具主动加载技能时,内容按文件原样返回——`{{GOAL}}`
1316
+ // 若不在这里渲染,成员看到的就是字面量。cwd 由 list() 随候选带下来,
1317
+ // 这里反查它属于哪个项目,再取该项目账本里的目标。
1318
+ resolveVars: ({ cwd }) => {
1319
+ const project = projectForCwd(cwd);
1320
+ return {
1321
+ GOAL: project?.goal || '(本项目尚未填写目标:请先在项目简报里补充)',
1322
+ PROJECT: project?.name ?? '',
1323
+ WORKSPACE: typeof cwd === 'string' ? cwd : '',
1324
+ };
1325
+ },
1305
1326
  }) ?? (() => {});
1306
1327
  } catch (error) {
1307
1328
  diag.append({ ev: 'skill.provider.fail', message: error?.message ?? String(error) });
@@ -1953,11 +1974,16 @@ export function apply(ctx, config = {}) {
1953
1974
  prompt: `${memberIdentity(activationMember)}\n\n${typeof body.payload?.prompt === 'string'
1954
1975
  ? body.payload.prompt
1955
1976
  : '你被加入 AI Team。先读取项目简报与收件箱,再处理分配给你的任务。'}${await formatSkillCatalog(skillsService, { cwd: effectiveDir })}${await loadSkillContext(activationMember, [join(effectiveDir, '.dsh'), dshHome(), projectRuntime.dir], {
1956
- GOAL: goalForProject(projectRuntime),
1957
- PROJECT: projectRuntime.service.state.projects?.[projectRuntime.id]?.name ?? '',
1958
- MEMBER: activationMember.name ?? '',
1959
- WORKSPACE: effectiveDir,
1960
- })}`,
1977
+ vars: {
1978
+ GOAL: goalForProject(projectRuntime),
1979
+ PROJECT: projectRuntime.service.state.projects?.[projectRuntime.id]?.name ?? '',
1980
+ MEMBER: activationMember.name ?? '',
1981
+ WORKSPACE: effectiveDir,
1982
+ },
1983
+ // 按身份装配内置技能:项目主理人拿审查规程,验收拿复跑规程,其余拿执行规程。
1984
+ ownerId: projectRuntime.service.state.projects?.[projectRuntime.id]?.ownerMemberId
1985
+ ?? projectRuntime.service.state.projects?.[projectRuntime.id]?.ownerId,
1986
+ })}`,
1961
1987
  });
1962
1988
  let bound;
1963
1989
  try {
@@ -1,4 +1,51 @@
1
- import { readFileSync } from 'node:fs';
2
-
3
- /** Single source of the built-in engineering discipline; packaged as skills/ai-team-core/SKILL.md. */
4
- export const CORE_SKILL_TEXT = readFileSync(new URL('../../skills/ai-team-core/SKILL.md', import.meta.url), 'utf8');
1
+ import { readFileSync } from 'node:fs';
2
+ import { isQaMember, isReviewerMember } from '../domain/member-profile.js';
3
+
4
+ /**
5
+ * 内置技能按**身份**装配:主理人/PMO 拿审查与导航规程,验收拿复跑规程,其余拿执行规程。
6
+ *
7
+ * 实机(2026-11-13):`ai-team-core` 被改写成第二人称的「你是本会话的审查与导航 PMO,
8
+ * 只读,不写代码」,但它对**所有成员**注入——执行成员会收到「你不写代码」的指令。
9
+ * 因此这里按成员身份分派,没有身份的(普通执行)拿执行规程。
10
+ */
11
+
12
+ const LEAD_PATTERN = /主理人|项目负责人|PMO|lead|owner/i;
13
+
14
+ function load(file) {
15
+ return readFileSync(new URL(`../../skills/${file}/SKILL.md`, import.meta.url), 'utf8');
16
+ }
17
+
18
+ /** 主理人/PMO:只读审查与导航。 */
19
+ export const CORE_SKILL_TEXT = load('ai-team-core');
20
+ /** 执行成员:按 resultDefinition 交付。 */
21
+ export const EXECUTOR_SKILL_TEXT = load('ai-team-executor');
22
+ /** 验收成员:独立复跑判定。 */
23
+ export const QA_SKILL_TEXT = load('ai-team-qa');
24
+
25
+ export const SKILL_KINDS = Object.freeze(['lead', 'qa', 'executor']);
26
+
27
+ /**
28
+ * 判定一个成员该装配哪份内置技能。
29
+ *
30
+ * 优先级:项目主理人(账本 ownerMemberId)→ 角色名里的主理人/PMO → 验收角色 → 执行。
31
+ * 只认身份,不看任务:同一个人换角色要立刻换规程。
32
+ *
33
+ * @param {{id?: string, role?: string}|null|undefined} member
34
+ * @param {{ownerId?: string}|null|undefined} context 项目主理人 id
35
+ * @returns {'lead'|'qa'|'executor'}
36
+ */
37
+ export function skillKindForMember(member, context = {}) {
38
+ const ownerId = typeof context?.ownerId === 'string' ? context.ownerId : '';
39
+ if (ownerId !== '' && member?.id === ownerId) return 'lead';
40
+ const role = typeof member?.role === 'string' ? member.role : '';
41
+ if (LEAD_PATTERN.test(role)) return 'lead';
42
+ if (isQaMember(member) || isReviewerMember(member)) return 'qa';
43
+ return 'executor';
44
+ }
45
+
46
+ /** 按种类取技能正文(含 front-matter,调用方负责剥掉)。 */
47
+ export function coreSkillTextFor(kind) {
48
+ if (kind === 'lead') return CORE_SKILL_TEXT;
49
+ if (kind === 'qa') return QA_SKILL_TEXT;
50
+ return EXECUTOR_SKILL_TEXT;
51
+ }
@@ -1,7 +1,7 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { basename, join } from 'node:path';
3
3
  import { isSkillExcluded } from './skill-policy.js';
4
- import { CORE_SKILL_TEXT } from './core-skill.js';
4
+ import { coreSkillTextFor, skillKindForMember } from './core-skill.js';
5
5
 
6
6
  const MAX_SKILL_CHARS = 1800;
7
7
 
@@ -20,10 +20,20 @@ export function renderSkillVars(text, vars = {}) {
20
20
  });
21
21
  }
22
22
 
23
- /** Read bounded SKILL.md files for member-declared skills from the profile skill library. */
24
- export async function loadSkillContext(member, dataDir, vars = {}) {
23
+ /**
24
+ * Read bounded SKILL.md files for member-declared skills from the profile skill library.
25
+ *
26
+ * 第三参数兼容两种写法:直接给变量表(`{ GOAL }`),或给 `{ vars, ownerId }`——
27
+ * 后者用于按身份挑内置技能(主理人=审查规程 / 验收=复跑规程 / 其余=执行规程)。
28
+ */
29
+ export async function loadSkillContext(member, dataDir, options = {}) {
30
+ const hasParts = options !== null && typeof options === 'object'
31
+ && Object.prototype.hasOwnProperty.call(options, 'vars');
32
+ const vars = hasParts ? (options.vars ?? {}) : (options ?? {});
33
+ const ownerId = hasParts && typeof options.ownerId === 'string' ? options.ownerId : undefined;
25
34
  const skills = Array.isArray(member?.skills) ? member.skills : [];
26
- const core = renderSkillVars(CORE_SKILL_TEXT.replace(/^---[\s\S]*?\n---\s*/, '').trim(), vars);
35
+ const kind = skillKindForMember(member, { ownerId });
36
+ const core = renderSkillVars(coreSkillTextFor(kind).replace(/^---[\s\S]*?\n---\s*/, '').trim(), vars);
27
37
  const chunks = [core];
28
38
  // 可以传一个根,也可以传多个根(工作区 `.dsh/skills`、用户 `~/.dsh/skills`、插件数据目录)。
29
39
  // 只认一个根时,成员声明的技能会静默缺席——调用方传的是项目账本目录,它下面
@@ -1,206 +1,248 @@
1
- /**
2
- * Filesystem skill provider for DSH profiles that do not mount the desktop
3
- * marketplace's user-skill scanner. It exposes `<dshHome>/skills` and project
4
- * `.dsh/skills` / `.agents/skills` to the normal `skills` service, so members can
5
- * load installed skills through their own `skill` tool.
6
- *
7
- * Discovery parity with @deepseek-ai/dsh-skill-filesystem (README L36-56):
8
- * directory bundles `<name>/SKILL.md` and flat `<name>.md` files, required
9
- * kebab-case `name` + `description`, loose-boolean `disable-model-invocation`
10
- * / `user-invocable` keys, and the official rank order (project-dsh 100,
11
- * project-agents 200, user-dsh 400, bundled 600; lower rank wins a name).
12
- */
13
-
14
- import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
15
- import { join } from 'node:path';
16
- import { isSkillExcluded } from './skill-policy.js';
17
- import { reportFail } from '../diaglog.js';
18
-
19
- const MAX_BODY_BYTES = 512 * 1024;
20
-
21
- /** Official per-source ranks; a lower rank beats a higher one on name clash. */
22
- const SOURCE_RANK = Object.freeze({
23
- 'project-dsh': 100,
24
- 'project-agents': 200,
25
- 'user-dsh': 400,
26
- bundled: 600,
27
- });
28
-
29
- function parseFrontmatter(text) {
30
- if (!text.startsWith('---')) return {};
31
- const end = text.indexOf('\n---', 3);
32
- if (end < 0) return {};
33
- // CRLF 必须在这里断干净:`\r` 在 JS 里是行终止符,`.$` 无法越过它,
34
- // 带尾 `\r` 的最后一行(常见于 Windows 编辑器)会整行失配——
35
- // description 恰好位于末尾时,整个技能被当成「缺少 description」丢弃。
36
- const lines = text.slice(3, end).split(/\r\n|\r|\n/);
37
- const fields = {};
38
- let key = null;
39
- for (const line of lines) {
40
- const match = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line);
41
- if (match) {
42
- key = match[1];
43
- fields[key] = match[2].trim();
44
- continue;
45
- }
46
- if (key !== null && /^\s+/.test(line)) {
47
- fields[key] = `${fields[key] ? fields[key] + ' ' : ''}${line.trim()}`;
48
- }
49
- }
50
- return fields;
51
- }
52
-
53
- function unquote(value) {
54
- const text = String(value ?? '').trim();
55
- return text.length >= 2 && ((text.startsWith('"') && text.endsWith('"')) || (text.startsWith("'") && text.endsWith("'")))
56
- ? text.slice(1, -1)
57
- : text;
58
- }
59
-
60
- /**
61
- * Official loose boolean syntax (skill-filesystem README L38): YAML booleans
62
- * plus case-insensitive true/false, yes/no, on/off, 1/0. `null` marks a
63
- * rejected spelling, which drops the whole skill instead of silently allowing
64
- * an interface.
65
- */
66
- function parseLooseBoolean(value) {
67
- if (typeof value === 'boolean') return value;
68
- const text = String(value ?? '').trim().toLowerCase();
69
- if (['true', 'yes', 'on', '1'].includes(text)) return true;
70
- if (['false', 'no', 'off', '0'].includes(text)) return false;
71
- return null;
72
- }
73
-
74
- /** Resolve one invocation flag; returns null when the skill must be dropped. */
75
- function invocationFlag(fields, key, inverted) {
76
- const raw = fields[key];
77
- if (raw === undefined) return true;
78
- const parsed = parseLooseBoolean(raw);
79
- if (parsed === null) return null;
80
- return inverted ? !parsed : parsed;
81
- }
82
-
83
- function scanCandidate(file, fallbackName, source) {
84
- if (!existsSync(file)) return null;
85
- let text;
86
- try {
87
- if (statSync(file).size > MAX_BODY_BYTES) return null;
88
- text = readFileSync(file, 'utf8');
89
- } catch {
90
- return null;
91
- }
92
- const fields = parseFrontmatter(text);
93
- const name = unquote(fields.name) || fallbackName;
94
- // Must match the host registry's SKILL_NAME exactly (`^[a-z0-9]+(?:-[a-z0-9]+)*$`):
95
- // a name we accept but the registry rejects makes `skills.snapshot` throw
96
- // "skill provider returned invalid skill name", which aborts every agent step.
97
- if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name)) return null;
98
- if (isSkillExcluded(name)) return null;
99
- const description = unquote(fields.description);
100
- // Official semantics: `description` is required; a skill without one is
101
- // dropped with a warning rather than synthesized into the catalog.
102
- if (description === '') {
103
- reportFail('skill.dropped.fail', { skill: name, file, reason: 'description-required' }, `[ai-team] skill "${name}" dropped: frontmatter description is required`);
104
- return null;
105
- }
106
- const modelInvocable = invocationFlag(fields, 'disable-model-invocation', true);
107
- const userInvocable = invocationFlag(fields, 'user-invocable', false);
108
- if (modelInvocable === null || userInvocable === null) {
109
- reportFail('skill.dropped.fail', { skill: name, file, reason: 'invocation-not-boolean' }, `[ai-team] skill "${name}" dropped: invocation flag is not a boolean`);
110
- return null;
111
- }
112
- return {
113
- name,
114
- description,
115
- whenToUse: unquote(fields.whenToUse) || unquote(fields['when-to-use']) || undefined,
116
- invocation: { modelInvocable, userInvocable },
117
- source,
118
- provider: 'ai-team-files',
119
- path: file,
120
- locator: file,
121
- rank: SOURCE_RANK[source] ?? 500,
122
- };
123
- }
124
-
125
- function scanRoot(root, source) {
126
- const candidates = [];
127
- if (!existsSync(root)) return candidates;
128
- let entries;
129
- try {
130
- entries = readdirSync(root, { withFileTypes: true });
131
- } catch {
132
- return candidates;
133
- }
134
- for (const entry of entries) {
135
- if (entry.name.startsWith('.')) continue;
136
- if (entry.isDirectory()) {
137
- const found = scanCandidate(join(root, entry.name, 'SKILL.md'), entry.name, source);
138
- if (found !== null) candidates.push(found);
139
- continue;
140
- }
141
- if (entry.isFile() && entry.name.endsWith('.md')) {
142
- const found = scanCandidate(join(root, entry.name), entry.name.replace(/\.md$/, ''), source);
143
- if (found !== null) candidates.push(found);
144
- }
145
- }
146
- return candidates;
147
- }
148
-
149
- export function createFileSkillProvider({ dshHome, projectCwd, bundledDir } = {}) {
150
- // Bundled last: the official rank order puts disk roots above the packaged
151
- // copy, so a user's own edit of a same-named skill wins (README L48-56).
152
- const roots = [];
153
- if (projectCwd) {
154
- roots.push([join(projectCwd, '.dsh', 'skills'), 'project-dsh']);
155
- roots.push([join(projectCwd, '.agents', 'skills'), 'project-agents']);
156
- }
157
- if (dshHome) roots.push([join(dshHome, 'skills'), 'user-dsh']);
158
- if (bundledDir) roots.push([join(bundledDir, 'skills'), 'bundled']);
159
- return {
160
- name: 'ai-team-files',
161
- async list(options = {}) {
162
- const extra = options.cwd && options.cwd !== projectCwd
163
- ? [
164
- [join(options.cwd, '.dsh', 'skills'), 'project-dsh'],
165
- [join(options.cwd, '.agents', 'skills'), 'project-agents'],
166
- ]
167
- : [];
168
- const all = [];
169
- for (const [root, source] of [...roots, ...extra]) {
170
- all.push(...scanRoot(root, source));
171
- }
172
- // Same-name clash: the lowest rank wins, mirroring the registry's
173
- // rank → provider-order → local-order adjudication.
174
- const byName = new Map();
175
- for (const candidate of all.sort((left, right) => left.rank - right.rank)) {
176
- if (!byName.has(candidate.name)) byName.set(candidate.name, candidate);
177
- }
178
- return [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));
179
- },
180
- async get(candidate) {
181
- const file = candidate?.locator;
182
- if (typeof file !== 'string' || !existsSync(file)) return undefined;
183
- // 读取失败不能把 rejection 冒到 skill 工具:宿主在 agent/pre-step 里
184
- // await skills.snapshot,一次 EACCES/EBUSY 会打断该 agent 的整个回合。
185
- try {
186
- if (statSync(file).size > MAX_BODY_BYTES) return undefined;
187
- return { ...candidate, content: readFileSync(file, 'utf8') };
188
- } catch {
189
- return undefined;
190
- }
191
- },
192
- };
193
- }
194
-
195
- export function installFileSkillProvider(skills, options) {
196
- if (!skills || typeof skills.registerProvider !== 'function') return () => {};
197
- const provider = createFileSkillProvider(options);
198
- // SDK 契约(dsh-skill.md):`registerProvider` 同步注册、**返回 disposer**,
199
- // 没有 invalidate 这一档。旧实现按「可能返回 { dispose, invalidate }」处理,
200
- // invalidate 分支永远不可达,属于死代码——这里只保留真实的两种返回形态。
201
- const control = skills.registerProvider(() => provider);
202
- const dispose = typeof control === 'function' ? control : control?.dispose;
203
- return () => {
204
- try { dispose?.(); } catch { /* already disposed */ }
205
- };
206
- }
1
+ /**
2
+ * Filesystem skill provider for DSH profiles that do not mount the desktop
3
+ * marketplace's user-skill scanner. It exposes `<dshHome>/skills` and project
4
+ * `.dsh/skills` / `.agents/skills` to the normal `skills` service, so members can
5
+ * load installed skills through their own `skill` tool.
6
+ *
7
+ * Discovery parity with @deepseek-ai/dsh-skill-filesystem (README L36-56):
8
+ * directory bundles `<name>/SKILL.md` and flat `<name>.md` files, required
9
+ * kebab-case `name` + `description`, loose-boolean `disable-model-invocation`
10
+ * / `user-invocable` keys, and the official rank order (project-dsh 100,
11
+ * project-agents 200, user-dsh 400, bundled 600; lower rank wins a name).
12
+ */
13
+
14
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
15
+ import { join } from 'node:path';
16
+ import { isSkillExcluded } from './skill-policy.js';
17
+ import { renderSkillVars } from './skill-loader.js';
18
+ import { reportFail } from '../diaglog.js';
19
+
20
+ /**
21
+ * 从项目列表里挑出 cwd 所属的那个项目(用于把 `{{GOAL}}` 等变量渲染成真实值)。
22
+ *
23
+ * 技能加载器按文件原样返回内容,`get()` 不知道自己属于哪个项目;`list()` 知道 cwd,
24
+ * 于是把它随候选一起带下去。这里只做「cwd → 项目」的匹配:先精确(忽略大小写与
25
+ * 分隔符差异),再按前缀(成员在项目子目录里工作时也要命中),最后当只有一个项目时
26
+ * 直接用它。
27
+ *
28
+ * @param {Array<{id?: string, name?: string, goal?: string, workspacePath?: string}>} projects
29
+ * @param {string} cwd
30
+ * @returns {{id: string, name: string, goal: string}|undefined}
31
+ */
32
+ export function pickProjectForCwd(projects, cwd) {
33
+ const list = (Array.isArray(projects) ? projects : []).filter((project) => project !== null && typeof project === 'object');
34
+ if (list.length === 0) return undefined;
35
+ const normalize = (value) => String(value ?? '').trim().replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase();
36
+ const target = normalize(cwd);
37
+ const shape = (project) => ({
38
+ id: typeof project.id === 'string' ? project.id : '',
39
+ name: typeof project.name === 'string' ? project.name : '',
40
+ goal: typeof project.goal === 'string' ? project.goal.trim() : '',
41
+ });
42
+ if (target === '') return list.length === 1 ? shape(list[0]) : undefined;
43
+ const withWorkspace = list.filter((project) => normalize(project.workspacePath) !== '');
44
+ const exact = withWorkspace.find((project) => normalize(project.workspacePath) === target);
45
+ if (exact !== undefined) return shape(exact);
46
+ const prefix = withWorkspace
47
+ .filter((project) => target.startsWith(normalize(project.workspacePath) + '/'))
48
+ .sort((left, right) => normalize(right.workspacePath).length - normalize(left.workspacePath).length);
49
+ if (prefix.length > 0) return shape(prefix[0]);
50
+ return list.length === 1 ? shape(list[0]) : undefined;
51
+ }
52
+
53
+ const MAX_BODY_BYTES = 512 * 1024;
54
+
55
+ /** Official per-source ranks; a lower rank beats a higher one on name clash. */
56
+ const SOURCE_RANK = Object.freeze({
57
+ 'project-dsh': 100,
58
+ 'project-agents': 200,
59
+ 'user-dsh': 400,
60
+ bundled: 600,
61
+ });
62
+
63
+ function parseFrontmatter(text) {
64
+ if (!text.startsWith('---')) return {};
65
+ const end = text.indexOf('\n---', 3);
66
+ if (end < 0) return {};
67
+ // CRLF 必须在这里断干净:`\r` 在 JS 里是行终止符,`.$` 无法越过它,
68
+ // 带尾 `\r` 的最后一行(常见于 Windows 编辑器)会整行失配——
69
+ // description 恰好位于末尾时,整个技能被当成「缺少 description」丢弃。
70
+ const lines = text.slice(3, end).split(/\r\n|\r|\n/);
71
+ const fields = {};
72
+ let key = null;
73
+ for (const line of lines) {
74
+ const match = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line);
75
+ if (match) {
76
+ key = match[1];
77
+ fields[key] = match[2].trim();
78
+ continue;
79
+ }
80
+ if (key !== null && /^\s+/.test(line)) {
81
+ fields[key] = `${fields[key] ? fields[key] + ' ' : ''}${line.trim()}`;
82
+ }
83
+ }
84
+ return fields;
85
+ }
86
+
87
+ function unquote(value) {
88
+ const text = String(value ?? '').trim();
89
+ return text.length >= 2 && ((text.startsWith('"') && text.endsWith('"')) || (text.startsWith("'") && text.endsWith("'")))
90
+ ? text.slice(1, -1)
91
+ : text;
92
+ }
93
+
94
+ /**
95
+ * Official loose boolean syntax (skill-filesystem README L38): YAML booleans
96
+ * plus case-insensitive true/false, yes/no, on/off, 1/0. `null` marks a
97
+ * rejected spelling, which drops the whole skill instead of silently allowing
98
+ * an interface.
99
+ */
100
+ function parseLooseBoolean(value) {
101
+ if (typeof value === 'boolean') return value;
102
+ const text = String(value ?? '').trim().toLowerCase();
103
+ if (['true', 'yes', 'on', '1'].includes(text)) return true;
104
+ if (['false', 'no', 'off', '0'].includes(text)) return false;
105
+ return null;
106
+ }
107
+
108
+ /** Resolve one invocation flag; returns null when the skill must be dropped. */
109
+ function invocationFlag(fields, key, inverted) {
110
+ const raw = fields[key];
111
+ if (raw === undefined) return true;
112
+ const parsed = parseLooseBoolean(raw);
113
+ if (parsed === null) return null;
114
+ return inverted ? !parsed : parsed;
115
+ }
116
+
117
+ function scanCandidate(file, fallbackName, source) {
118
+ if (!existsSync(file)) return null;
119
+ let text;
120
+ try {
121
+ if (statSync(file).size > MAX_BODY_BYTES) return null;
122
+ text = readFileSync(file, 'utf8');
123
+ } catch {
124
+ return null;
125
+ }
126
+ const fields = parseFrontmatter(text);
127
+ const name = unquote(fields.name) || fallbackName;
128
+ // Must match the host registry's SKILL_NAME exactly (`^[a-z0-9]+(?:-[a-z0-9]+)*$`):
129
+ // a name we accept but the registry rejects makes `skills.snapshot` throw
130
+ // "skill provider returned invalid skill name", which aborts every agent step.
131
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name)) return null;
132
+ if (isSkillExcluded(name)) return null;
133
+ const description = unquote(fields.description);
134
+ // Official semantics: `description` is required; a skill without one is
135
+ // dropped with a warning rather than synthesized into the catalog.
136
+ if (description === '') {
137
+ reportFail('skill.dropped.fail', { skill: name, file, reason: 'description-required' }, `[ai-team] skill "${name}" dropped: frontmatter description is required`);
138
+ return null;
139
+ }
140
+ const modelInvocable = invocationFlag(fields, 'disable-model-invocation', true);
141
+ const userInvocable = invocationFlag(fields, 'user-invocable', false);
142
+ if (modelInvocable === null || userInvocable === null) {
143
+ reportFail('skill.dropped.fail', { skill: name, file, reason: 'invocation-not-boolean' }, `[ai-team] skill "${name}" dropped: invocation flag is not a boolean`);
144
+ return null;
145
+ }
146
+ return {
147
+ name,
148
+ description,
149
+ whenToUse: unquote(fields.whenToUse) || unquote(fields['when-to-use']) || undefined,
150
+ invocation: { modelInvocable, userInvocable },
151
+ source,
152
+ provider: 'ai-team-files',
153
+ path: file,
154
+ locator: file,
155
+ rank: SOURCE_RANK[source] ?? 500,
156
+ };
157
+ }
158
+
159
+ function scanRoot(root, source) {
160
+ const candidates = [];
161
+ if (!existsSync(root)) return candidates;
162
+ let entries;
163
+ try {
164
+ entries = readdirSync(root, { withFileTypes: true });
165
+ } catch {
166
+ return candidates;
167
+ }
168
+ for (const entry of entries) {
169
+ if (entry.name.startsWith('.')) continue;
170
+ if (entry.isDirectory()) {
171
+ const found = scanCandidate(join(root, entry.name, 'SKILL.md'), entry.name, source);
172
+ if (found !== null) candidates.push(found);
173
+ continue;
174
+ }
175
+ if (entry.isFile() && entry.name.endsWith('.md')) {
176
+ const found = scanCandidate(join(root, entry.name), entry.name.replace(/\.md$/, ''), source);
177
+ if (found !== null) candidates.push(found);
178
+ }
179
+ }
180
+ return candidates;
181
+ }
182
+
183
+ export function createFileSkillProvider({ dshHome, projectCwd, bundledDir, resolveVars } = {}) {
184
+ // Bundled last: the official rank order puts disk roots above the packaged
185
+ // copy, so a user's own edit of a same-named skill wins (README L48-56).
186
+ const roots = [];
187
+ if (projectCwd) {
188
+ roots.push([join(projectCwd, '.dsh', 'skills'), 'project-dsh']);
189
+ roots.push([join(projectCwd, '.agents', 'skills'), 'project-agents']);
190
+ }
191
+ if (dshHome) roots.push([join(dshHome, 'skills'), 'user-dsh']);
192
+ if (bundledDir) roots.push([join(bundledDir, 'skills'), 'bundled']);
193
+ return {
194
+ name: 'ai-team-files',
195
+ async list(options = {}) {
196
+ const extra = options.cwd && options.cwd !== projectCwd
197
+ ? [
198
+ [join(options.cwd, '.dsh', 'skills'), 'project-dsh'],
199
+ [join(options.cwd, '.agents', 'skills'), 'project-agents'],
200
+ ]
201
+ : [];
202
+ const all = [];
203
+ const resolveCwd = typeof options.cwd === 'string' && options.cwd !== '' ? options.cwd : projectCwd;
204
+ for (const [root, source] of [...roots, ...extra]) {
205
+ for (const candidate of scanRoot(root, source)) all.push({ ...candidate, resolveCwd });
206
+ }
207
+ // Same-name clash: the lowest rank wins, mirroring the registry's
208
+ // rank → provider-order → local-order adjudication.
209
+ const byName = new Map();
210
+ for (const candidate of all.sort((left, right) => left.rank - right.rank)) {
211
+ if (!byName.has(candidate.name)) byName.set(candidate.name, candidate);
212
+ }
213
+ return [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));
214
+ },
215
+ async get(candidate) {
216
+ const file = candidate?.locator;
217
+ if (typeof file !== 'string' || !existsSync(file)) return undefined;
218
+ // 读取失败不能把 rejection 冒到 skill 工具:宿主在 agent/pre-step 里
219
+ // await skills.snapshot,一次 EACCES/EBUSY 会打断该 agent 的整个回合。
220
+ try {
221
+ if (statSync(file).size > MAX_BODY_BYTES) return undefined;
222
+ const raw = readFileSync(file, 'utf8');
223
+ // 技能按文件原样提供,但 `{{GOAL}}` 这类占位符必须在返回前渲染:成员主动
224
+ // 加载技能时不该看到字面量(与激活注入走同一套变量)。
225
+ const vars = typeof resolveVars === 'function'
226
+ ? resolveVars({ cwd: candidate?.resolveCwd ?? projectCwd, candidate }) ?? {}
227
+ : {};
228
+ const content = renderSkillVars(raw, vars);
229
+ return { ...candidate, content };
230
+ } catch {
231
+ return undefined;
232
+ }
233
+ },
234
+ };
235
+ }
236
+
237
+ export function installFileSkillProvider(skills, options) {
238
+ if (!skills || typeof skills.registerProvider !== 'function') return () => {};
239
+ const provider = createFileSkillProvider(options);
240
+ // SDK 契约(dsh-skill.md):`registerProvider` 同步注册、**返回 disposer**,
241
+ // 没有 invalidate 这一档。旧实现按「可能返回 { dispose, invalidate }」处理,
242
+ // invalidate 分支永远不可达,属于死代码——这里只保留真实的两种返回形态。
243
+ const control = skills.registerProvider(() => provider);
244
+ const dispose = typeof control === 'function' ? control : control?.dispose;
245
+ return () => {
246
+ try { dispose?.(); } catch { /* already disposed */ }
247
+ };
248
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.85",
3
+ "version": "0.4.87",
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",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ai-team-core
3
- description: 文渊阁 AI Team 核心工程纪律:单一实现、网页取证与代理、懒惰的高级程序员、最小依赖、日志埋点。
4
- whenToUse: 所有 Agent(PMO/主理人/执行/验收)在规划、实现、验收、排查和汇报前都应加载并遵守。
3
+ description: 只读「审查与导航」PMO 作业规程:核实子代理是否真的做到、对照目标锚点找偏离与漏项、只给下一步,输出 STATUS: CONTINUE | DONE | NEED_HUMAN。
4
+ whenToUse: 每一轮子代理输出之后做核实与导航时加载;需要确认交付是否达标、是否越界加功能、该不该转交 Human 决策时使用。
5
5
  ---
6
6
 
7
7
  # AI Team 核心工程纪律
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: ai-team-executor
3
+ description: 执行成员的作业规程:按 resultDefinition 交付、只做被要求的事、交付必须带实测证据、阻塞立刻上报。
4
+ whenToUse: 领取任务并动手实现、修改文件、跑命令、提交验收之前加载。
5
+ ---
6
+
7
+ 你是 AI Team 的执行成员。目标是把分到的 Task 按 `resultDefinition` 交付,不改变目标本身。
8
+
9
+ 【动手前】
10
+ - 读 Task 描述、`resultDefinition`、QA checklist 与 thread 里已有的结论,别重复别人做过的事。
11
+ - 需求有歧义、缺依赖、缺权限、与现有实现冲突 → 在 thread 里说明并交回主理人,不要自己补设定。
12
+
13
+ 【交付标准】
14
+ - 每条结论都要有实测证据:命令输出、文件路径与行号、计数。不手填数字、不凭印象汇报。
15
+ - 只做被要求的事:不顺手重构、不越界加功能、不改无关文件。
16
+ - 改完自测:能跑测试就跑测试,能复现就复现,把「怎么验的」写进交付说明。
17
+
18
+ 【收尾】
19
+ - 说明改了什么、为什么这么改、怎么验证的、还有什么没覆盖。
20
+ - 按 tasks 的状态流转提交验收,交给验收成员独立复跑。
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: ai-team-qa
3
+ description: 验收成员的作业规程:独立复跑、只按 resultDefinition 与 QA checklist 判定、不采信执行者自述、证据不足即退回。
4
+ whenToUse: 拿到待验收的任务、需要判定是否通过、或要退回并写最小修复建议时加载。
5
+ ---
6
+
7
+ 你是 AI Team 的验收成员。判定只依据 `resultDefinition` 与 QA checklist,不依据执行者的自述。
8
+
9
+ 【复跑】
10
+ - 自己执行验证:跑测试、跑命令、打开产物、核对数据。执行者说「已通过」不算证据。
11
+ - 不与执行者共用同一次运行结果;能从干净状态复跑就从干净状态复跑。
12
+ - 拿不准时换数据、换环境再跑一遍,而不是放宽标准。
13
+
14
+ 【判定】
15
+ - 逐条对 checklist 打勾,每条附证据(输出片段、路径、行号、计数)。
16
+ - 证据缺失、只能部分满足、或与要求口径不一致 → 判为未通过。
17
+ - 结论只有两种:**通过**(列证据)或 **退回**(列复跑结果 + 最小修复建议)。
18
+ - 不替执行者改代码,也不因为赶时间而降低验收线。
19
+
20
+ 【收尾】
21
+ - 把判定与证据写进 thread,让主理人据此决定续派还是收口。