@suifei/dsh-ai-team 0.3.54 → 0.3.60

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.
@@ -3,6 +3,12 @@
3
3
  * marketplace's user-skill scanner. It exposes `<dshHome>/skills` and project
4
4
  * `.dsh/skills` / `.agents/skills` to the normal `skills` service, so members can
5
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).
6
12
  */
7
13
 
8
14
  import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
@@ -11,6 +17,14 @@ import { isSkillExcluded } from './skill-policy.js';
11
17
 
12
18
  const MAX_BODY_BYTES = 512 * 1024;
13
19
 
20
+ /** Official per-source ranks; a lower rank beats a higher one on name clash. */
21
+ const SOURCE_RANK = Object.freeze({
22
+ 'project-dsh': 100,
23
+ 'project-agents': 200,
24
+ 'user-dsh': 400,
25
+ bundled: 600,
26
+ });
27
+
14
28
  function parseFrontmatter(text) {
15
29
  if (!text.startsWith('---')) return {};
16
30
  const end = text.indexOf('\n---', 3);
@@ -39,6 +53,68 @@ function unquote(value) {
39
53
  : text;
40
54
  }
41
55
 
56
+ /**
57
+ * Official loose boolean syntax (skill-filesystem README L38): YAML booleans
58
+ * plus case-insensitive true/false, yes/no, on/off, 1/0. `null` marks a
59
+ * rejected spelling, which drops the whole skill instead of silently allowing
60
+ * an interface.
61
+ */
62
+ function parseLooseBoolean(value) {
63
+ if (typeof value === 'boolean') return value;
64
+ const text = String(value ?? '').trim().toLowerCase();
65
+ if (['true', 'yes', 'on', '1'].includes(text)) return true;
66
+ if (['false', 'no', 'off', '0'].includes(text)) return false;
67
+ return null;
68
+ }
69
+
70
+ /** Resolve one invocation flag; returns null when the skill must be dropped. */
71
+ function invocationFlag(fields, key, inverted) {
72
+ const raw = fields[key];
73
+ if (raw === undefined) return true;
74
+ const parsed = parseLooseBoolean(raw);
75
+ if (parsed === null) return null;
76
+ return inverted ? !parsed : parsed;
77
+ }
78
+
79
+ function scanCandidate(file, fallbackName, source) {
80
+ if (!existsSync(file)) return null;
81
+ let text;
82
+ try {
83
+ if (statSync(file).size > MAX_BODY_BYTES) return null;
84
+ text = readFileSync(file, 'utf8');
85
+ } catch {
86
+ return null;
87
+ }
88
+ const fields = parseFrontmatter(text);
89
+ const name = unquote(fields.name) || fallbackName;
90
+ if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) return null;
91
+ if (isSkillExcluded(name)) return null;
92
+ const description = unquote(fields.description);
93
+ // Official semantics: `description` is required; a skill without one is
94
+ // dropped with a warning rather than synthesized into the catalog.
95
+ if (description === '') {
96
+ console.warn(`[ai-team] skill "${name}" dropped: frontmatter description is required`);
97
+ return null;
98
+ }
99
+ const modelInvocable = invocationFlag(fields, 'disable-model-invocation', true);
100
+ const userInvocable = invocationFlag(fields, 'user-invocable', false);
101
+ if (modelInvocable === null || userInvocable === null) {
102
+ console.warn(`[ai-team] skill "${name}" dropped: "${modelInvocable === null ? 'disable-model-invocation' : 'user-invocable'}" is not a recognized boolean`);
103
+ return null;
104
+ }
105
+ return {
106
+ name,
107
+ description,
108
+ whenToUse: unquote(fields.whenToUse) || unquote(fields['when-to-use']) || undefined,
109
+ invocation: { modelInvocable, userInvocable },
110
+ source,
111
+ provider: 'ai-team-files',
112
+ path: file,
113
+ locator: file,
114
+ rank: SOURCE_RANK[source] ?? 500,
115
+ };
116
+ }
117
+
42
118
  function scanRoot(root, source) {
43
119
  const candidates = [];
44
120
  if (!existsSync(root)) return candidates;
@@ -49,43 +125,30 @@ function scanRoot(root, source) {
49
125
  return candidates;
50
126
  }
51
127
  for (const entry of entries) {
52
- if (!entry.isDirectory() || entry.name.startsWith('.')) continue;
53
- const file = join(root, entry.name, 'SKILL.md');
54
- if (!existsSync(file)) continue;
55
- let text;
56
- try {
57
- if (statSync(file).size > MAX_BODY_BYTES) continue;
58
- text = readFileSync(file, 'utf8');
59
- } catch {
128
+ if (entry.name.startsWith('.')) continue;
129
+ if (entry.isDirectory()) {
130
+ const found = scanCandidate(join(root, entry.name, 'SKILL.md'), entry.name, source);
131
+ if (found !== null) candidates.push(found);
60
132
  continue;
61
133
  }
62
- const fields = parseFrontmatter(text);
63
- const name = unquote(fields.name) || entry.name;
64
- if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) continue;
65
- if (isSkillExcluded(name)) continue;
66
- candidates.push({
67
- name,
68
- description: unquote(fields.description) || `Skill ${name}`,
69
- whenToUse: unquote(fields.whenToUse) || unquote(fields['when-to-use']) || undefined,
70
- invocation: { modelInvocable: true, userInvocable: true },
71
- source,
72
- provider: 'ai-team-files',
73
- path: file,
74
- locator: file,
75
- rank: 0,
76
- });
134
+ if (entry.isFile() && entry.name.endsWith('.md')) {
135
+ const found = scanCandidate(join(root, entry.name), entry.name.replace(/\.md$/, ''), source);
136
+ if (found !== null) candidates.push(found);
137
+ }
77
138
  }
78
139
  return candidates;
79
140
  }
80
141
 
81
142
  export function createFileSkillProvider({ dshHome, projectCwd, bundledDir } = {}) {
143
+ // Bundled last: the official rank order puts disk roots above the packaged
144
+ // copy, so a user's own edit of a same-named skill wins (README L48-56).
82
145
  const roots = [];
83
- if (bundledDir) roots.push([join(bundledDir, 'skills'), 'bundled']);
84
- if (dshHome) roots.push([join(dshHome, 'skills'), 'user-dsh']);
85
146
  if (projectCwd) {
86
147
  roots.push([join(projectCwd, '.dsh', 'skills'), 'project-dsh']);
87
148
  roots.push([join(projectCwd, '.agents', 'skills'), 'project-agents']);
88
149
  }
150
+ if (dshHome) roots.push([join(dshHome, 'skills'), 'user-dsh']);
151
+ if (bundledDir) roots.push([join(bundledDir, 'skills'), 'bundled']);
89
152
  return {
90
153
  name: 'ai-team-files',
91
154
  async list(options = {}) {
@@ -95,16 +158,17 @@ export function createFileSkillProvider({ dshHome, projectCwd, bundledDir } = {}
95
158
  [join(options.cwd, '.agents', 'skills'), 'project-agents'],
96
159
  ]
97
160
  : [];
98
- const seen = new Set();
99
161
  const all = [];
100
162
  for (const [root, source] of [...roots, ...extra]) {
101
- for (const candidate of scanRoot(root, source)) {
102
- if (seen.has(candidate.name)) continue;
103
- seen.add(candidate.name);
104
- all.push(candidate);
105
- }
163
+ all.push(...scanRoot(root, source));
106
164
  }
107
- return all.sort((left, right) => left.name.localeCompare(right.name));
165
+ // Same-name clash: the lowest rank wins, mirroring the registry's
166
+ // rank → provider-order → local-order adjudication.
167
+ const byName = new Map();
168
+ for (const candidate of all.sort((left, right) => left.rank - right.rank)) {
169
+ if (!byName.has(candidate.name)) byName.set(candidate.name, candidate);
170
+ }
171
+ return [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));
108
172
  },
109
173
  async get(candidate) {
110
174
  const file = candidate?.locator;
@@ -120,4 +184,3 @@ export function installFileSkillProvider(skills, options) {
120
184
  const provider = createFileSkillProvider(options);
121
185
  return skills.registerProvider(() => provider);
122
186
  }
123
-
@@ -9,6 +9,7 @@
9
9
  const defineTool = (definition) => definition
10
10
  import { dirname, join } from 'node:path'
11
11
  import { fileURLToPath } from 'node:url'
12
+ import { existsSync, readFileSync, readdirSync } from 'node:fs'
12
13
 
13
14
  export const name = 'skillopt'
14
15
 
@@ -17,7 +18,7 @@ export const name = 'skillopt'
17
18
  const PLUGIN_DIR = dirname(fileURLToPath(import.meta.url)) + '/..'
18
19
 
19
20
  // Exported for the canary test (scripts/canary.mjs).
20
- export { buildArgv, quoteArgv, q, IS_WINDOWS }
21
+ export { buildArgv, quoteArgv, q, IS_WINDOWS, adoptGuardVerdict }
21
22
 
22
23
  // Wait for the tool registry and the shell executor before applying.
23
24
  export const inject = ['tools', 'shell']
@@ -147,8 +148,59 @@ function pick(obj, keys) {
147
148
  return out
148
149
  }
149
150
 
151
+ /**
152
+ * adopt 的 live-change 归因门(一手证据来自引擎 staging 布局:
153
+ * <project>/.skillopt-sleep/staging/<ts>/,.latest 指针 + manifest.json +
154
+ * diagnostics.json(cycle.py 每轮写入 `"backend": cfg.get("backend")`)。
155
+ * 返回 null 表示放行;返回字符串表示拒绝原因(fail-closed)。
156
+ */
157
+ function adoptGuardVerdict(project) {
158
+ const root = join(project, '.skillopt-sleep', 'staging')
159
+ let latest = null
160
+ try {
161
+ latest = readFileSync(join(root, '.latest'), 'utf8').trim() || null
162
+ } catch { /* 无指针:退化为扫描 ts 目录 */ }
163
+ if (!latest) {
164
+ try {
165
+ latest = readdirSync(root)
166
+ .filter((n) => /^\d{8}-\d{6}(-\d+)?$/.test(n) && existsSync(join(root, n, 'manifest.json')))
167
+ .sort()
168
+ .at(-1) ?? null
169
+ } catch {
170
+ return 'refusing to adopt: no staged proposal found (run skillopt_run first)'
171
+ }
172
+ }
173
+ // 指针目录必须含 manifest.json(与引擎 latest_staging 一致),否则按扫描
174
+ // 回退——残指针不应产生误导性报因。
175
+ if (!latest || !existsSync(join(root, latest, 'manifest.json'))) {
176
+ try {
177
+ latest = readdirSync(root)
178
+ .filter((n) => /^\d{8}-\d{6}(-\d+)?$/.test(n) && existsSync(join(root, n, 'manifest.json')))
179
+ .sort()
180
+ .at(-1) ?? null
181
+ } catch {
182
+ return 'refusing to adopt: no staged proposal found (run skillopt_run first)'
183
+ }
184
+ }
185
+ if (!latest) return 'refusing to adopt: no staged proposal found (run skillopt_run first)'
186
+ const stagedDir = join(root, latest)
187
+ let backend = null
188
+ try {
189
+ const diag = JSON.parse(readFileSync(join(stagedDir, 'diagnostics.json'), 'utf8'))
190
+ backend = typeof diag.backend === 'string' ? diag.backend : null
191
+ } catch {
192
+ return `refusing to adopt: cannot attribute this proposal to a validating backend (no readable diagnostics.json in ${stagedDir}). Re-run skillopt_run to stage a fresh, attributable proposal.`
193
+ }
194
+ if (backend === 'mock') {
195
+ return `refusing to adopt: this staged proposal was validated by the MOCK backend — no real model ran and its scores are synthetic. Run skillopt_run with a real backend (config skilloptBackend, or per-call backend) to produce a genuine gate result. Staged dir: ${stagedDir}`
196
+ }
197
+ if (!backend) {
198
+ return `refusing to adopt: diagnostics.json in ${stagedDir} does not name the validating backend. Re-run skillopt_run to stage a fresh, attributable proposal.`
199
+ }
200
+ return null
201
+ }
202
+
150
203
  // Value-domain guard for model-supplied path-like strings.
151
- //
152
204
  // argv-level quoting (quoteArgv) protects the dsh `bash -c` boundary, but the
153
205
  // engine re-interpolates these values into its OWN shell/command strings:
154
206
  // scheduler.py builds `--project "{project}"` inside a crontab line and a
@@ -264,10 +316,12 @@ export function apply(ctx, config = {}) {
264
316
  {
265
317
  name: 'skillopt_adopt',
266
318
  description:
267
- 'Apply the latest staged proposal, backing up existing target files first. This is the live-change boundary.',
319
+ 'Apply the latest staged proposal, backing up existing target files first. This is the live-change boundary. Refuses proposals validated by the mock backend (scores are synthetic, no real model ran).',
268
320
  parameters: {
269
321
  project: { type: 'string', description: 'Project directory' },
270
322
  },
323
+ // live-change boundary 前的一手证据门:拒绝时不发起引擎调用。
324
+ guard: (project) => adoptGuardVerdict(project),
271
325
  build: (a) => buildArgv(config, 'adopt', pick(a, ['project']), [], ['project']),
272
326
  },
273
327
  {
@@ -339,6 +393,12 @@ export function apply(ctx, config = {}) {
339
393
  } catch (err) {
340
394
  return `[skillopt ${t.name}] ${err.message}`
341
395
  }
396
+ // 工具自带的前置门(如 adopt 的 mock 验证归因检查):拒绝时不发起
397
+ // 引擎调用,直接返回拒绝原因。
398
+ if (typeof t.guard === 'function') {
399
+ const verdict = t.guard(a.project ?? config.project ?? process.cwd())
400
+ if (verdict) return `[skillopt ${t.name}] ${verdict}`
401
+ }
342
402
  const argv = t.build(a)
343
403
  // `command` must be the shell-quoted form for the platform executor;
344
404
  // resolve() applies the executor's workdir/output-cap/sandbox defaults.
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "AI Team workbench",
4
+ "description": "Concurrent Projects with owned Tasks, Threads, an inbox and an append-only team ledger."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "文渊阁 AI Team 工作台",
4
+ "description": "并发项目、责任到人的任务、讨论串、收件箱与 append-only 团队账本。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.3.54",
3
+ "version": "0.3.60",
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",
@@ -31,13 +31,18 @@
31
31
  ".": "./index.js",
32
32
  "./client": "./client.js",
33
33
  "./lib/*": "./lib/*",
34
+ "./locale/*.json": "./locale/*.json",
34
35
  "./icon": "./icon.svg"
35
36
  },
37
+ "dependencies": {
38
+ "@deepseek-ai/schemastery": "~3.19.0"
39
+ },
36
40
  "files": [
37
41
  "index.js",
38
42
  "client.js",
39
43
  "cordis.patch.yml",
40
44
  "icon.svg",
45
+ "locale/*.json",
41
46
  "lib/**/*.js",
42
47
  "lib/vendor/skillopt/scripts/**/*",
43
48
  "lib/vendor/skillopt/skillopt_sleep/**/*",