@lythos/skill-deck 0.5.0 → 0.5.1

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/README.md CHANGED
@@ -49,8 +49,9 @@ skills = ["report-generation-combo"]
49
49
 
50
50
  | Situation | Command |
51
51
  |-----------|---------|
52
- | Sync `.claude/skills/` with `skill-deck.toml` | `bunx @lythos/skill-deck link` |
52
+ | Sync working set with `skill-deck.toml` | `bunx @lythos/skill-deck link` |
53
53
  | Validate `skill-deck.toml` before committing | `bunx @lythos/skill-deck validate` |
54
+ | Download a skill to cold pool and add to deck | `bunx @lythos/skill-deck add owner/repo` |
54
55
  | Use a custom deck file or working dir | `bunx @lythos/skill-deck link --deck ./my-deck.toml --workdir /path/to/project` |
55
56
 
56
57
  ### Commands
@@ -59,6 +60,7 @@ skills = ["report-generation-combo"]
59
60
  |---------|------|-------------|
60
61
  | `link` | `[--deck <path>] [--workdir <dir>]` | Sync working set. Removes undeclared skills (deny-by-default). |
61
62
  | `validate` | `[deck.toml] [--workdir <dir>]` | Validate deck config without modifying files. |
63
+ | `add` | `<locator> [--via <backend>] [--deck <path>]` | Download skill to cold pool and append to skill-deck.toml. |
62
64
 
63
65
  ### Options
64
66
 
@@ -66,6 +68,11 @@ skills = ["report-generation-combo"]
66
68
  |------|-------------|---------|
67
69
  | `--deck <path>` | Path to skill-deck.toml | Find upward from cwd |
68
70
  | `--workdir <dir>` | Working directory | cwd |
71
+ | `--via <backend>` | Download backend for `add`: `git` or `skills.sh` | `git` |
72
+
73
+ ### Safety guards
74
+
75
+ `link` refuses to operate if `working_set` resolves to your home directory or root (`/`). It also only removes **symlinks** from the working set — real files or directories are skipped with a warning.
69
76
 
70
77
  ### Exit codes
71
78
 
@@ -106,10 +113,22 @@ bunx @lythos/skill-deck link
106
113
  |---------|-----------|
107
114
  | **Cold Pool** | All downloaded skills (`~/.agents/skill-repos/`). Agent cannot see here. |
108
115
  | **skill-deck.toml** | Declares desired state: "this project uses these skills." |
109
- | **`deck link`** | Reconciler. Makes `.claude/skills/` match the declaration. |
110
- | **Working Set** | `.claude/skills/` — symlinks only. What the agent actually scans. |
116
+ | **`deck link`** | Reconciler. Makes the working set match the declaration. |
117
+ | **Working Set** | Symlinks only. Default: `.claude/skills/` — where agents scan for skills. |
111
118
  | **deny-by-default** | Undeclared skills are physically absent from the working set. |
112
119
 
120
+ ### Agent skill scan locations
121
+
122
+ Different agents look for skills in different directories. `skill-deck.toml` configures the working set to match your agent:
123
+
124
+ | Agent | Default skills directory |
125
+ |-------|--------------------------|
126
+ | Claude Code | `.claude/skills/` |
127
+ | Cursor | `.cursor/skills/` |
128
+ | Generic / custom | Configure `working_set` in `skill-deck.toml` |
129
+
130
+ > **If you are an agent**: verify where your platform scans for skills, then set `working_set` to that path before running `deck link`.
131
+
113
132
  ## Skill Documentation
114
133
 
115
134
  This package is the **Starter** layer (CLI implementation).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lythos/skill-deck",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Declarative skill deck governance — cold pool, working set, deny-by-default",
5
5
  "keywords": [
6
6
  "ai-agent",
package/src/add.ts CHANGED
@@ -105,6 +105,11 @@ export async function addSkill(locator: string, options: { via?: string; deck?:
105
105
  process.exit(1)
106
106
  }
107
107
 
108
+ if (!existsSync(coldPool)) {
109
+ console.log(`📁 Creating cold pool: ${coldPool}`)
110
+ mkdirSync(coldPool, { recursive: true })
111
+ }
112
+
108
113
  const tmpDir = mkdtempSync(join(tmpdir(), 'lythoskill-deck-add-'))
109
114
  const tmpRepo = join(tmpDir, 'repo')
110
115
 
@@ -113,13 +118,23 @@ export async function addSkill(locator: string, options: { via?: string; deck?:
113
118
  const skillsShLocator = `${parsed.owner}/${parsed.repo}`
114
119
  console.log(`📦 Downloading via skills.sh: ${skillsShLocator}`)
115
120
  execSync(`npx skills add ${skillsShLocator} -g`, { cwd: tmpDir, stdio: 'inherit' })
116
- console.error(`⚠️ skills.sh backend: manual cold-pool placement may be needed`)
117
121
  } else {
118
122
  const gitUrl = `https://${parsed.host}/${parsed.owner}/${parsed.repo}.git`
119
123
  console.log(`📦 Cloning: ${gitUrl}`)
120
124
  execSync(`git clone --depth 1 ${gitUrl} ${tmpRepo}`, { stdio: 'inherit' })
121
125
  }
122
126
 
127
+ if (!existsSync(tmpRepo)) {
128
+ if (backend === 'skills.sh' || backend === 'vercel') {
129
+ console.error(`❌ skills.sh backend installs globally, not to cold pool.`)
130
+ console.error(` Please manually place the skill at: ${targetDir}`)
131
+ console.error(` Or use: deck add ${locator} --via git`)
132
+ process.exit(1)
133
+ }
134
+ console.error(`❌ Download failed: expected output not found at ${tmpRepo}`)
135
+ process.exit(1)
136
+ }
137
+
123
138
  mkdirSync(dirname(targetDir), { recursive: true })
124
139
  renameSync(tmpRepo, targetDir)
125
140
 
package/src/link.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  existsSync, mkdirSync, readFileSync, readdirSync,
15
15
  symlinkSync, lstatSync, rmSync, writeFileSync,
16
16
  } from "fs";
17
- import { resolve, dirname, join } from "path";
17
+ import { resolve, dirname, join, basename, relative } from "path";
18
18
  import { homedir } from "os";
19
19
  import {
20
20
  SkillDeckLockSchema,
@@ -152,7 +152,7 @@ for (const section of ["innate", "tool", "combo"] as const) {
152
152
  if (!name || typeof name !== "string") continue;
153
153
  const src = findSource(name, COLD_POOL, PROJECT_DIR);
154
154
  if (!src) {
155
- errors.push(`skill 未找到: ${name}`);
155
+ errors.push(`Skill not found: ${name}`);
156
156
  continue;
157
157
  }
158
158
  declared.push({ name, type: section, sourcePath: src });
@@ -165,7 +165,7 @@ for (const [key, value] of Object.entries(deck.transient || {})) {
165
165
  if (!t?.path) continue;
166
166
  const src = resolve(PROJECT_DIR, t.path);
167
167
  if (!existsSync(src)) {
168
- errors.push(`transient 路径不存在: ${key} → ${src}`);
168
+ errors.push(`Transient path does not exist: ${key} → ${src}`);
169
169
  continue;
170
170
  }
171
171
  declared.push({ name: key, type: "transient", sourcePath: src, expires: t.expires });
@@ -179,23 +179,54 @@ if (errors.length > 0) {
179
179
  // ── 预算检查(硬约束,链接前检查)──────────────────────────
180
180
 
181
181
  if (declared.length > MAX_CARDS) {
182
- console.error(`❌ 超出预算: 声明 ${declared.length} 个,上限 ${MAX_CARDS}`);
183
- console.error(` 减少 skill-deck.toml 中的声明,或调整 max_cards`);
182
+ console.error(`❌ Budget exceeded: declared ${declared.length}, max ${MAX_CARDS}`);
183
+ console.error(` Reduce declarations in skill-deck.toml or increase max_cards`);
184
184
  process.exit(1);
185
185
  }
186
186
 
187
+ // ── 工作目录安全 guard ──────────────────────────────────────
188
+
189
+ const resolvedWorkingSet = resolve(WORKING_SET);
190
+ const resolvedHome = resolve(homedir());
191
+ const resolvedCwd = resolve(process.cwd());
192
+ const resolvedColdPool = resolve(COLD_POOL);
193
+
194
+ if (resolvedWorkingSet === resolvedHome || resolvedWorkingSet === "/") {
195
+ console.error(`❌ Refusing operation: working_set resolves to home or root directory (${resolvedWorkingSet})`);
196
+ console.error(` Check working_set in skill-deck.toml`);
197
+ process.exit(1);
198
+ }
199
+
200
+ const relWs = relative(resolvedColdPool, resolvedWorkingSet);
201
+ if (
202
+ resolvedWorkingSet.startsWith(resolvedColdPool + "/") &&
203
+ !relWs.split("/").some(p => p.startsWith("."))
204
+ ) {
205
+ console.warn(`⚠️ working_set is inside cold_pool and not hidden — may be picked up by cold-pool scans`);
206
+ console.warn(` working_set: ${resolvedWorkingSet}`);
207
+ console.warn(` cold_pool: ${resolvedColdPool}`);
208
+ }
209
+
187
210
  // ── 收束 working set ────────────────────────────────────────
188
211
 
189
212
  mkdirSync(WORKING_SET, { recursive: true });
190
213
 
191
- // 清理未声明的条目
214
+ // 清理未声明的条目(只删 symlink,防呆)
192
215
  const declaredNames = new Set(declared.map(d => d.name.split("/")[0]));
193
216
  try {
194
217
  for (const entry of readdirSync(WORKING_SET)) {
195
218
  if (entry.startsWith("_")) continue;
196
219
  if (!declaredNames.has(entry)) {
197
- rmSync(join(WORKING_SET, entry), { recursive: true, force: true });
198
- console.log(` 🗑️ 移除: ${entry}`);
220
+ const entryPath = join(WORKING_SET, entry);
221
+ try {
222
+ const st = lstatSync(entryPath);
223
+ if (!st.isSymbolicLink()) {
224
+ console.warn(`⚠️ Skipping non-symlink entry: ${entry}`);
225
+ continue;
226
+ }
227
+ } catch { continue; }
228
+ rmSync(entryPath, { recursive: true, force: true });
229
+ console.log(` 🗑️ Removed: ${entry}`);
199
230
  }
200
231
  }
201
232
  } catch {}
@@ -216,7 +247,7 @@ for (const item of declared) {
216
247
  mkdirSync(dirname(dest), { recursive: true });
217
248
  symlinkSync(item.sourcePath, dest);
218
249
  } catch (err: any) {
219
- console.error(`❌ 链接失败: ${item.name}: ${err.message}`);
250
+ console.error(`❌ Link failed: ${item.name}: ${err.message}`);
220
251
  continue;
221
252
  }
222
253
 
@@ -260,9 +291,9 @@ for (const s of linkedSkills) {
260
291
  const days = Math.ceil((exp - now) / 86400000);
261
292
  transientWarnings.push({ name: s.name, expires: s.expires, days_remaining: days });
262
293
  if (days <= 0) {
263
- console.warn(`⚠️ 过期: ${s.name}(到期 ${s.expires})— 评估是否仍需要`);
294
+ console.warn(`⚠️ Expired: ${s.name} (expires ${s.expires}) — evaluate if still needed`);
264
295
  } else if (days <= 14) {
265
- console.warn(`⏰ 即将过期: ${s.name}(剩余 ${days} 天)`);
296
+ console.warn(`⏰ Expiring soon: ${s.name} (${days} days remaining)`);
266
297
  }
267
298
  }
268
299
 
@@ -282,7 +313,7 @@ const dirOverlaps: { dir: string; skills: string[] }[] = [];
282
313
  for (const [dir, owners] of dirOwners) {
283
314
  if (owners.length > 1) {
284
315
  dirOverlaps.push({ dir, skills: owners });
285
- console.warn(`⚠️ 目录重叠: ${dir} ← ${owners.join(", ")}`);
316
+ console.warn(`⚠️ Directory overlap: ${dir} ← ${owners.join(", ")}`);
286
317
  }
287
318
  }
288
319
 
@@ -297,7 +328,7 @@ for (let i = 0; i < allDirs.length; i++) {
297
328
  const cross = parentOwners.filter(o => !childOwners.includes(o));
298
329
  if (cross.length > 0) {
299
330
  const msg = `${allDirs[i]} (${parentOwners.join(",")}) 包含 ${allDirs[j]} (${childOwners.join(",")})`;
300
- console.warn(`⚠️ 目录包含关系: ${msg}`);
331
+ console.warn(`⚠️ Directory containment: ${msg}`);
301
332
  dirOverlaps.push({ dir: `${allDirs[i]} ⊃ ${allDirs[j]}`, skills: [...new Set([...parentOwners, ...childOwners])] });
302
333
  }
303
334
  }
@@ -326,7 +357,7 @@ const lock: SkillDeckLock = {
326
357
 
327
358
  const parsed = SkillDeckLockSchema.safeParse(lock);
328
359
  if (!parsed.success) {
329
- console.error("❌ Lock schema 校验失败:", JSON.stringify(parsed.error.format(), null, 2));
360
+ console.error("❌ Lock schema validation failed:", JSON.stringify(parsed.error.format(), null, 2));
330
361
  process.exit(1);
331
362
  }
332
363
 
@@ -336,10 +367,10 @@ writeFileSync(LOCK_PATH, JSON.stringify(parsed.data, null, 2) + "\n");
336
367
  // ── 报告 ────────────────────────────────────────────────────
337
368
 
338
369
  console.log("");
339
- console.log(`✅ 同步完成: ${linkedSkills.length}/${MAX_CARDS} skill`);
370
+ console.log(`✅ Sync complete: ${linkedSkills.length}/${MAX_CARDS} skills`);
340
371
  console.log(` lock: ${LOCK_PATH}`);
341
372
  if (dirOverlaps.length > 0) {
342
- console.log(` ⚠️ ${dirOverlaps.length} 个目录重叠(详见上方警告)`);
373
+ console.log(` ⚠️ ${dirOverlaps.length} directory overlap(s) (see warnings above)`);
343
374
  }
344
375
  }
345
376