@suifei/dsh-ai-team 0.4.84 → 0.4.86

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';
@@ -745,6 +745,23 @@ export function apply(ctx, config = {}) {
745
745
  let pmoTimer = null;
746
746
  // 项目工作目录(显式,无兜底):null 表示尚未设置。历史版本在此处用
747
747
  // runtime.dir(账本目录)兜底,曾把成员会话 cwd 钉进插件数据目录。
748
+ // 技能里的 {{GOAL}}:项目目标来自账本 projects[id].goal;没填就明说,不要让成员
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
+ };
760
+ const goalForProject = (projectRuntime) => {
761
+ const goal = projectRuntime?.service?.state?.projects?.[projectRuntime?.id]?.goal;
762
+ const text = typeof goal === 'string' ? goal.trim() : '';
763
+ return text === '' ? '(本项目尚未填写目标:请先在项目简报里补充)' : text;
764
+ };
748
765
  const projectWorkspace = (projectRuntime, member) => member?.workspace
749
766
  || projectRuntime?.service?.state?.projects?.[projectRuntime.id]?.workspacePath
750
767
  || null;
@@ -1295,6 +1312,17 @@ export function apply(ctx, config = {}) {
1295
1312
  dshHome: dshHome(),
1296
1313
  projectCwd: process.cwd(),
1297
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
+ },
1298
1326
  }) ?? (() => {});
1299
1327
  } catch (error) {
1300
1328
  diag.append({ ev: 'skill.provider.fail', message: error?.message ?? String(error) });
@@ -1945,7 +1973,12 @@ export function apply(ctx, config = {}) {
1945
1973
  const result = await runtime.activate(activationMember, {
1946
1974
  prompt: `${memberIdentity(activationMember)}\n\n${typeof body.payload?.prompt === 'string'
1947
1975
  ? body.payload.prompt
1948
- : '你被加入 AI Team。先读取项目简报与收件箱,再处理分配给你的任务。'}${await formatSkillCatalog(skillsService, { cwd: effectiveDir })}${await loadSkillContext(activationMember, [join(effectiveDir, '.dsh'), dshHome(), projectRuntime.dir])}`,
1976
+ : '你被加入 AI Team。先读取项目简报与收件箱,再处理分配给你的任务。'}${await formatSkillCatalog(skillsService, { cwd: effectiveDir })}${await loadSkillContext(activationMember, [join(effectiveDir, '.dsh'), dshHome(), projectRuntime.dir], {
1977
+ GOAL: goalForProject(projectRuntime),
1978
+ PROJECT: projectRuntime.service.state.projects?.[projectRuntime.id]?.name ?? '',
1979
+ MEMBER: activationMember.name ?? '',
1980
+ WORKSPACE: effectiveDir,
1981
+ })}`,
1949
1982
  });
1950
1983
  let bound;
1951
1984
  try {
@@ -1,37 +1,53 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { basename, join } from 'node:path';
3
- import { isSkillExcluded } from './skill-policy.js';
4
- import { CORE_SKILL_TEXT } from './core-skill.js';
5
-
6
- const MAX_SKILL_CHARS = 1800;
7
-
8
- /** Read bounded SKILL.md files for member-declared skills from the profile skill library. */
9
- export async function loadSkillContext(member, dataDir) {
10
- const skills = Array.isArray(member?.skills) ? member.skills : [];
11
- const chunks = [CORE_SKILL_TEXT.replace(/^---[\s\S]*?\n---\s*/, '').trim()];
12
- // 可以传一个根,也可以传多个根(工作区 `.dsh/skills`、用户 `~/.dsh/skills`、插件数据目录)。
13
- // 只认一个根时,成员声明的技能会静默缺席——调用方传的是项目账本目录,它下面
14
- // 永远没有 `skills/`。
15
- const roots = (Array.isArray(dataDir) ? dataDir : [dataDir])
16
- .filter((root) => typeof root === 'string' && root !== '');
17
- for (const raw of skills.slice(0, 4)) {
18
- const name = basename(String(raw)).replace(/[^a-zA-Z0-9._-]/g, '');
19
- if (name === '' || name === '.' || name === '..' || name.startsWith('.')) continue;
20
- if (isSkillExcluded(name)) continue;
21
- for (const root of roots) {
22
- let loaded = false;
23
- for (const candidate of [join(root, 'skills', name, 'SKILL.md'), join(root, 'skills', `${name}.md`)]) {
24
- try {
25
- const text = await readFile(candidate, 'utf8');
26
- chunks.push(`### ${name}\n${text.slice(0, MAX_SKILL_CHARS)}`);
27
- loaded = true;
28
- break;
29
- } catch (error) {
30
- if (error?.code !== 'ENOENT') break;
31
- }
32
- }
33
- if (loaded) break;
34
- }
35
- }
36
- return chunks.length === 0 ? '' : `\n\n[技能资料]\n${chunks.join('\n\n')}`;
37
- }
1
+ import { readFile } from 'node:fs/promises';
2
+ import { basename, join } from 'node:path';
3
+ import { isSkillExcluded } from './skill-policy.js';
4
+ import { CORE_SKILL_TEXT } from './core-skill.js';
5
+
6
+ const MAX_SKILL_CHARS = 1800;
7
+
8
+ /**
9
+ * 把 `{{KEY}}` 渲染成调用方给的变量。
10
+ *
11
+ * 实机(2026-11-13):用户把 `ai-team-core` 改写成「审查与导航 PMO」提示词,正文里带
12
+ * 【目标锚点】`{{GOAL}}`——插件此前没有任何插值,成员看到的是字面量 `{{GOAL}}`,
13
+ * 等于目标那一行全是噪音。未知键保持原样(宁可露出占位符,也不要静默变成空行)。
14
+ */
15
+ export function renderSkillVars(text, vars = {}) {
16
+ if (typeof text !== 'string' || text === '') return '';
17
+ return text.replace(/\{\{\s*([A-Za-z_][\w]*)\s*\}\}/g, (match, key) => {
18
+ const value = vars?.[key] ?? vars?.[key.toUpperCase()] ?? vars?.[key.toLowerCase()];
19
+ return typeof value === 'string' && value.trim() !== '' ? value.trim() : match;
20
+ });
21
+ }
22
+
23
+ /** Read bounded SKILL.md files for member-declared skills from the profile skill library. */
24
+ export async function loadSkillContext(member, dataDir, vars = {}) {
25
+ const skills = Array.isArray(member?.skills) ? member.skills : [];
26
+ const core = renderSkillVars(CORE_SKILL_TEXT.replace(/^---[\s\S]*?\n---\s*/, '').trim(), vars);
27
+ const chunks = [core];
28
+ // 可以传一个根,也可以传多个根(工作区 `.dsh/skills`、用户 `~/.dsh/skills`、插件数据目录)。
29
+ // 只认一个根时,成员声明的技能会静默缺席——调用方传的是项目账本目录,它下面
30
+ // 永远没有 `skills/`。
31
+ const roots = (Array.isArray(dataDir) ? dataDir : [dataDir])
32
+ .filter((root) => typeof root === 'string' && root !== '');
33
+ for (const raw of skills.slice(0, 4)) {
34
+ const name = basename(String(raw)).replace(/[^a-zA-Z0-9._-]/g, '');
35
+ if (name === '' || name === '.' || name === '..' || name.startsWith('.')) continue;
36
+ if (isSkillExcluded(name)) continue;
37
+ for (const root of roots) {
38
+ let loaded = false;
39
+ for (const candidate of [join(root, 'skills', name, 'SKILL.md'), join(root, 'skills', `${name}.md`)]) {
40
+ try {
41
+ const text = await readFile(candidate, 'utf8');
42
+ chunks.push(`### ${name}\n${text.slice(0, MAX_SKILL_CHARS)}`);
43
+ loaded = true;
44
+ break;
45
+ } catch (error) {
46
+ if (error?.code !== 'ENOENT') break;
47
+ }
48
+ }
49
+ if (loaded) break;
50
+ }
51
+ }
52
+ return chunks.length === 0 ? '' : `\n\n[技能资料]\n${chunks.join('\n\n')}`;
53
+ }
@@ -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.84",
3
+ "version": "0.4.86",
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,48 +1,31 @@
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 核心工程纪律
8
-
9
- **同一能力在仓库内只允许一份实现,禁止另立简化版并存。**
10
-
11
- **抓取网页可以模拟请求带 useragent,海外如果联不通,则探查本地是否有存在 http 代理再试。**
12
-
13
- ## 开发规程(长期生效)
14
-
15
- **核心理念:懒惰的高级程序员思维**,这里的“懒惰”不是敷衍,而是对成本、风险与维护负担的敏感。
16
-
17
- - **能不写就不写。** 每一行新代码都是维护负债;写代码是最后手段,不是第一反应。
18
- - **能复用就不重造。** 已有且经过验证的实现优先;能扩展现有实现,就不另起一套。
19
- - **系统原生能解决就不引入新依赖。** 在目标平台与架构允许的边界内,优先使用标准库、运行时与操作系统已有能力。
20
- - **必须实现日志埋点**,记录关键操作和流程,用于 debug 分析插件工作状态。
21
-
22
- ## PMO 自主性(硬规则)
23
-
24
- - PMO、任务续派、停滞检测、决策处理必须由插件算法自己执行;禁止 Human 或外部 Agent 通过手动消息、临时脚本、外部 bridge 代为指挥。
25
- - 不得靠人工催办或人工改标题来掩盖。
26
- - 需要 Human 的决策交给 PMO 自动决策;Human 只观测和补充目标。
27
- **任何任务立即开工(永久性作业原则)**
28
-
29
- ## 角色要求
30
-
31
- - PMO/主理人:用复盘、头脑风暴、深度研究形成验收标准与 Task 草案,不把决策推给 Human;需要 Human 时交给 PMO 自动决策。
32
- - 执行:先读核心纪律与结果定义;交付证据必须实测,不手填数字。
33
- - 验收:独立复跑;只按 resultDefinition / QA checklist 判定;不共享执行者的 claim。
34
-
35
- ## 会议要求
36
-
37
- 请启动“正反极限论证器”。不要急着回答,也不要默认 Human 或 PMO 的问题已经定义正确。
38
- 第一步,用最完整、最准确的方式重新表述我真正想解决的问题,并指出其中可能存在的隐含假设。
39
- 第二步,分别建立两个最强版本的论证:【最强支持方】尽可能使用事实、逻辑、案例和因果关系证明我的当前想法成立;【最强反对方】同样以最有力的方式证明我的想法可能错误。禁止故意给任何一边安排弱论据。
40
- 第三步,比较双方真正的分歧点,找出最可能改变最终结论的3个关键变量。
41
- 第四步,只向我提出一个最值得回答的问题。等我回答后,再综合双方证据,明确给出当前判断、理由、最大风险、结论置信度以及下一步最值得采取的行动。
42
- 我的问题是:[用户填写,或者由 PMO 代填]。
43
-
44
- ## 结果定义
45
-
46
- - **明确可量化**:结果必须能够被客观测量和验证。
47
- - **与业务目标对齐**:结果应直接反映业务价值和用户满意度。
48
- - **可追溯性**:所有结果都应有清晰的来源和记录,便于后续分析和优化。
8
+ 你是本会话的「审查与导航」PMO。只读,不写代码、不改文件。
9
+
10
+ 【目标锚点】
11
+ {{GOAL}}
12
+
13
+ 【每轮输入】
14
+ 子代理刚完成的一轮输出。必要时自行查看 diff、文件、测试结果。
15
+
16
+ 【你的工作】
17
+ 1. 核实:子代理声称完成的事是否真的完成。以代码和运行结果为准,不以它的自述为准。
18
+ 2. 对照锚点:是否偏离目标、越界加功能、漏项。
19
+ 3. 决定下一步:只给当前最重要的一步。
20
+
21
+ 【输出格式】(会原样发给子代理)
22
+ STATUS: CONTINUE | DONE | NEED_HUMAN
23
+ 结论:一句话
24
+ 问题:最多 3 条,每条附证据(文件/行号/输出)
25
+ 下一步指令:给子代理的具体可执行指令
26
+
27
+ 【规则】
28
+ - 没有实质问题就输出 DONE,不为挑刺而挑刺。
29
+ - 同一问题连续两轮未解决、需求有歧义、或涉及不可逆操作 → NEED_HUMAN。
30
+ - 锚点之外的改进建议一律不提。
31
+ - 用户中途插入的意见优先于锚点,并视为锚点更新。