@crustjs/skills 0.1.2 → 0.2.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
@@ -1,8 +1,6 @@
1
1
  # @crustjs/skills
2
2
 
3
- Generate distributable AI agent skills from [Crust](https://crustjs.com) command definitions.
4
-
5
- Instead of hand-maintaining skill files for AI coding agents, generate them from your Crust command metadata. The output is a portable skill bundle that developers can download and install into their own agent environments (OpenCode, Claude Code, etc.).
3
+ Package and install agent skills for AI coding assistants.
6
4
 
7
5
  ## Install
8
6
 
@@ -10,678 +8,6 @@ Instead of hand-maintaining skill files for AI coding agents, generate them from
10
8
  bun add @crustjs/skills
11
9
  ```
12
10
 
13
- ## Quick Start
14
-
15
- ### CLI (via `@crustjs/crust`)
16
-
17
- ```sh
18
- crust skills generate ./src/cli.ts --name my-cli --description "My CLI tool"
19
- ```
20
-
21
- ### Programmatic API
22
-
23
- ```ts
24
- import { generateSkill } from "@crustjs/skills";
25
- import { rootCommand } from "./commands.ts";
26
-
27
- const result = await generateSkill({
28
- command: rootCommand,
29
- meta: {
30
- name: "my-cli",
31
- description: "CLI tool for managing widgets",
32
- version: "1.0.0",
33
- },
34
- agents: ["opencode", "claude-code"],
35
- });
36
-
37
- for (const agent of result.agents) {
38
- console.log(`${agent.agent}: ${agent.status} -> ${agent.outputDir}`);
39
- }
40
- ```
41
-
42
- ### Runtime Plugin (`autoUpdate`)
43
-
44
- Register `skillPlugin()` on your `Crust` builder with `.use()`:
45
-
46
- ```ts
47
- import { Crust } from "@crustjs/core";
48
- import { skillPlugin } from "@crustjs/skills";
49
-
50
- const app = new Crust("my-cli")
51
- .meta({ description: "My CLI" })
52
- .use(
53
- skillPlugin({
54
- version: "1.0.0",
55
- instructions: `
56
- Prefer readonly commands before mutating project state.
57
-
58
- ## Response Policy
59
-
60
- - Read the relevant command doc before suggesting flags.
61
- `,
62
- // autoUpdate: true (default) — silently updates installed skills
63
- // command: "skill" (default) — registers "my-cli skill" subcommand
64
- // defaultScope: "global" | "project" — skip scope prompt when set
65
- // installMode: "auto" | "symlink" | "copy" (default: "auto")
66
- }),
67
- )
68
- .run(() => {
69
- console.log("hello");
70
- });
71
-
72
- await app.execute();
73
- ```
74
-
75
- The plugin automatically updates already-installed skills when the version changes, checking both project and global paths for the current working directory. If the current working directory is the home directory, `project` scope is normalized to `global` so installs, updates, and status checks use the global skill locations. First-time installation is done via the interactive `skill` subcommand (or `skill update` for update-only flows), or programmatically using the exported primitives.
76
-
77
- Generated bundles are written once to a canonical store (`.crust/skills` for project scope, `~/.crust/skills` for global scope) and then installed into agent paths via symlink or copy depending on `installMode`.
78
-
79
- #### Hand-authored bundles via `customSkills`
80
-
81
- The plugin can also manage **hand-authored** skill bundles alongside the
82
- auto-generated command-reference skill. Pass an array of
83
- `CustomSkillConfig` entries via `customSkills`; each entry is reconciled
84
- through the same lifecycle as the main skill.
85
-
86
- ```ts
87
- import { Crust } from "@crustjs/core";
88
- import { skillPlugin } from "@crustjs/skills";
89
- import pkg from "./package.json" with { type: "json" };
90
-
91
- const app = new Crust("my-cli")
92
- .meta({ description: "My CLI" })
93
- .use(
94
- skillPlugin({
95
- version: pkg.version,
96
- customSkills: [
97
- // Inherits `version: pkg.version` from the plugin — the typical
98
- // case when the bundle ships in the same package as the CLI.
99
- {
100
- name: "funnel-builder",
101
- // Resolved against the nearest package.json walking up from
102
- // process.argv[1] — same rules as installSkillBundle().
103
- sourceDir: "skills/funnel-builder",
104
- },
105
- // Explicit override for an independently-versioned bundle.
106
- {
107
- name: "vendored-toolkit",
108
- sourceDir: "skills/vendored-toolkit",
109
- version: "0.3.0",
110
- },
111
- ],
112
- }),
113
- )
114
- .run(() => {});
115
-
116
- await app.execute();
117
- ```
118
-
119
- - **`name`** must satisfy `isValidSkillName` (1–64 lowercase alphanumeric
120
- characters and hyphens, no leading/trailing/consecutive hyphens), must
121
- be unique within the array, and must not collide with the main skill's
122
- name. The bundle's `SKILL.md` frontmatter must declare a matching
123
- `name:` field — mismatches are rejected at install time.
124
- - **`sourceDir`** accepts a `URL` (`file:` protocol), an absolute path, or
125
- a relative string resolved from the nearest `package.json`. Resolution
126
- errors surface at install time, not at plugin setup.
127
- - **`version`** is optional. When omitted, the bundle inherits the
128
- plugin's top-level `version` — the typical case when the bundle ships
129
- alongside the CLI. Pass an explicit value when the bundle's release
130
- cadence is independent of the consuming CLI (for example, vendored
131
- from another package). Identical-version reinstalls are skipped, so
132
- bump the effective version whenever bundle contents change. The
133
- bundle's `SKILL.md` frontmatter `version:` / `metadata.version`, if
134
- any, is intentionally ignored — see the [`installSkillBundle()` note](#installing-hand-authored-bundles).
135
- - **`scope`** and **`installMode`** are optional per-entry overrides;
136
- unset values inherit from the plugin's `defaultScope` / `installMode`.
137
-
138
- The interactive `skill` command shows one multiselect prompt per skill in
139
- order: the main auto-generated skill first, then each `customSkills`
140
- entry with its name in the prompt header (e.g. `"Select agents to install
141
- skills for [funnel-builder]"`). Each prompt is independent — selecting
142
- or deselecting agents reconciles only that skill's installs. `skill
143
- --all` skips every prompt and installs every skill for the full agent
144
- set; `skill update` updates outdated installs across main + every bundle.
145
-
146
- Auto-update on plugin startup is per-skill: only outdated installs are
147
- rewritten, and a single bundle's failure (e.g. missing `sourceDir`) does
148
- not abort the others. Pass `autoUpdate: false` to disable startup auto-
149
- update for both the main skill and all bundles.
150
-
151
- ### Programmatic Auto-Install
152
-
153
- For full control over first-time installation, call `generateSkill()`
154
- directly from your handler. With `agents` omitted, it installs into every
155
- universal agent plus every additional agent whose CLI is on `PATH`, and
156
- returns `up-to-date` for targets that already match the current version —
157
- so the same call is safe to run on every invocation. Pass `agents: []` to
158
- opt out, or an explicit array to scope the install.
159
-
160
- ```ts
161
- import { Crust } from "@crustjs/core";
162
- import { generateSkill } from "@crustjs/skills";
163
-
164
- export const app = new Crust("my-cli").meta({ description: "My CLI" }).run(async (ctx) => {
165
- // Defaults to universal + agents detected on PATH. Idempotent: targets
166
- // that already match the current version are returned as `up-to-date`.
167
- const result = await generateSkill({
168
- command: ctx.command,
169
- meta: {
170
- name: ctx.command.meta.name,
171
- description: ctx.command.meta.description ?? "",
172
- version: "1.0.0",
173
- },
174
- scope: "global",
175
- });
176
-
177
- const changed = result.agents.filter((a) => a.status !== "up-to-date");
178
- if (changed.length > 0) {
179
- console.log(`Installed or updated skills for ${changed.length} target(s).`);
180
- }
181
- });
182
-
183
- if (import.meta.main) {
184
- await app.execute();
185
- }
186
- ```
187
-
188
- `getUniversalAgents()`, `getAdditionalAgents()`, and
189
- `detectInstalledAgents()` remain exported for callers that want to compose
190
- their own agent list.
191
-
192
- #### Troubleshooting
193
-
194
- If auto-update does not appear to work:
195
-
196
- - Ensure `skillPlugin(...)` is registered on the `Crust` builder via `.use()`.
197
- - Ensure at least one supported agent is detected. Auto-update checks both project and global install paths, with home-directory `project` scope treated as `global`.
198
- - Check for existing conflicting skill directories without `crust.json`.
199
-
200
- ## Recommended Export Pattern
201
-
202
- To avoid side effects when your command module is imported for generation, guard runtime code with `import.meta.main`:
203
-
204
- ```ts
205
- import { Crust } from "@crustjs/core";
206
-
207
- // Export the command — used by skill generation.
208
- export const rootCommand = new Crust("my-cli")
209
- .meta({ description: "My CLI tool" })
210
- .run(({ args }) => {
211
- console.log("Hello from my-cli!");
212
- });
213
-
214
- // Only execute when run directly — not when imported for generation.
215
- if (import.meta.main) {
216
- await rootCommand.execute();
217
- }
218
- ```
219
-
220
- ### Custom Instructions
221
-
222
- Use plugin-level `instructions` to add top-level guidance to the generated
223
- `SKILL.md`, and `annotate()` to add prompt guidance to specific
224
- command docs under `commands/`.
225
-
226
- - `instructions: string` renders as a raw markdown block.
227
- - `instructions: string[]` renders as bullet list items.
228
- - Empty or whitespace-only instruction input is ignored.
229
- - `annotate()` always renders command guidance as bullets.
230
-
231
- ```ts
232
- import { Crust } from "@crustjs/core";
233
- import { annotate, skillPlugin } from "@crustjs/skills";
234
-
235
- const deploy = annotate(
236
- new Crust("deploy")
237
- .meta({ description: "Deploy the application" })
238
- .flags({
239
- "dry-run": { type: "boolean", description: "Preview changes only" },
240
- })
241
- .run(() => {
242
- // ...
243
- }),
244
- [
245
- "Prefer `--dry-run` before executing deployment changes.",
246
- "Ask for confirmation before production deployments.",
247
- ],
248
- );
249
-
250
- const app = new Crust("my-cli")
251
- .meta({ description: "My CLI" })
252
- .use(
253
- skillPlugin({
254
- version: "1.0.0",
255
- instructions: `
256
- Read command docs before suggesting exact flags.
257
-
258
- ## Answer Style
259
-
260
- - Prefer exact syntax copied from the relevant command file.
261
- `,
262
- }),
263
- )
264
- .command(deploy);
265
- ```
266
-
267
- This pattern lets `crust skills generate` import the command definition without triggering `app.execute()`.
268
-
269
- ## CLI Usage
270
-
271
- The `crust skills generate` command is provided by `@crustjs/crust`:
272
-
273
- ```sh
274
- crust skills generate <module> [options]
275
- ```
276
-
277
- ### Arguments
278
-
279
- | Argument | Description |
280
- | -------- | ------------------------------------------------ |
281
- | `module` | Path to the command module (e.g. `./src/cli.ts`) |
282
-
283
- ### Flags
284
-
285
- | Flag | Alias | Required | Default | Description |
286
- | --------------- | ----- | -------- | --------- | ---------------------------------------------- |
287
- | `--name` | `-n` | Yes | - | Skill name (used as directory name) |
288
- | `--description` | `-d` | Yes | - | Human-readable description |
289
- | `--version` | `-V` | No | - | Version string |
290
- | `--out-dir` | `-o` | No | `.` | Output directory |
291
- | `--clean` | - | No | `true` | Remove existing skill directory before writing |
292
- | `--export` | `-e` | No | `default` | Named export to use from the module |
293
-
294
- ### Examples
295
-
296
- ```sh
297
- # Basic generation
298
- crust skills generate ./src/cli.ts --name my-cli --description "My CLI"
299
-
300
- # With version and custom output directory
301
- crust skills generate ./src/cli.ts -n my-cli -d "My CLI" --version 1.0.0 -o ./dist
302
-
303
- # Using a named export instead of the default export
304
- crust skills generate ./src/cli.ts -n my-cli -d "My CLI" --export rootCommand
305
-
306
- # Keep existing files (no clean)
307
- crust skills generate ./src/cli.ts -n my-cli -d "My CLI" --no-clean
308
- ```
309
-
310
- ## Programmatic API
311
-
312
- ### `generateSkill(options)`
313
-
314
- High-level API that runs the full pipeline: introspection, rendering, and writing to disk.
315
-
316
- The `meta.name` must be a valid skill name — lowercase alphanumeric with hyphens, 1–64 characters (validated against the [Agent Skills spec](https://agentskills.io/specification) pattern). Use `isValidSkillName()` to check before calling.
317
-
318
- ```ts
319
- import { generateSkill } from "@crustjs/skills";
320
-
321
- const result = await generateSkill({
322
- command: rootCommand,
323
- meta: {
324
- name: "my-cli",
325
- description: "My CLI tool",
326
- version: "1.0.0",
327
- instructions: ["Prefer readonly commands before making changes."],
328
- },
329
- agents: ["opencode"],
330
- scope: "project", // default: "global"
331
- installMode: "auto", // default: "auto" — symlink first, fallback to copy
332
- clean: true, // default: true — removes existing skill dir first
333
- force: false, // default: false — set true to rewrite same-version output or overwrite conflicts
334
- });
335
-
336
- // result.agents — per-agent install results
337
- ```
338
-
339
- ### `buildManifest(command)`
340
-
341
- Introspects a command tree and produces a canonical, serializable manifest.
342
-
343
- ```ts
344
- import { buildManifest } from "@crustjs/skills";
345
-
346
- const manifest = buildManifest(rootCommand);
347
- // manifest.name, manifest.path, manifest.args, manifest.flags, manifest.children
348
- ```
349
-
350
- ### `renderSkill(manifest, meta)`
351
-
352
- Renders markdown files from a manifest tree without writing to disk.
353
-
354
- ```ts
355
- import { buildManifest, renderSkill } from "@crustjs/skills";
356
-
357
- const manifest = buildManifest(rootCommand);
358
- const files = renderSkill(manifest, { name: "my-cli", description: "My CLI" });
359
-
360
- for (const file of files) {
361
- console.log(file.path); // e.g. "SKILL.md", "commands/serve.md"
362
- console.log(file.content); // markdown content
363
- }
364
- ```
365
-
366
- ### `resolveCanonicalSkillPath(scope, name)`
367
-
368
- Resolves the canonical store path where Crust writes the single source-of-truth skill bundle. Agent install paths are symlinked (or copied) from this location.
369
-
370
- ```ts
371
- import { resolveCanonicalSkillPath } from "@crustjs/skills";
372
-
373
- resolveCanonicalSkillPath("project", "my-cli");
374
- // → "<cwd>/.crust/skills/my-cli"
375
-
376
- resolveCanonicalSkillPath("global", "my-cli");
377
- // → "~/.crust/skills/my-cli"
378
- ```
379
-
380
- When `process.cwd()` is the home directory, `resolveCanonicalSkillPath("project", ...)` returns the same global path as `resolveCanonicalSkillPath("global", ...)`.
381
-
382
- ### `isValidSkillName(name)`
383
-
384
- Validates a skill name against the [Agent Skills spec](https://agentskills.io/specification) pattern: 1–64 lowercase alphanumeric characters and hyphens, no leading/trailing/consecutive hyphens.
385
-
386
- ```ts
387
- import { isValidSkillName } from "@crustjs/skills";
388
-
389
- isValidSkillName("my-cli"); // true
390
- isValidSkillName("My_CLI"); // false — uppercase and underscores not allowed
391
- isValidSkillName("-leading"); // false — leading hyphen
392
- isValidSkillName("a".repeat(65)); // false — exceeds 64 characters
393
- ```
394
-
395
- > **Note:** `generateSkill()` automatically validates `meta.name` and throws a descriptive error if the name is invalid.
396
-
397
- ## Skill Metadata
398
-
399
- The `SkillMeta` object controls the generated `SKILL.md` frontmatter. Beyond the required `name`, `description`, and `version` fields, several optional fields are supported:
400
-
401
- ```ts
402
- const meta: SkillMeta = {
403
- name: "my-cli",
404
- description: "CLI tool for managing widgets",
405
- version: "1.0.0",
406
-
407
- // Optional fields — emitted in SKILL.md YAML frontmatter when set
408
- allowedTools: "Bash(my-cli *) Read Grep", // Pre-approved tools (avoids per-use prompts)
409
- license: "MIT", // License name or reference
410
- compatibility: "Requires my-cli on PATH", // Environment requirements (max 500 chars)
411
- disableModelInvocation: false, // true = agent won't auto-load; user must invoke manually
412
- };
413
- ```
414
-
415
- | Field | Frontmatter Key | Description |
416
- | ------------------------ | -------------------------- | ---------------------------------------------------------------------------- |
417
- | `allowedTools` | `allowed-tools` | Space-delimited list of pre-approved tools (e.g. `Bash(my-cli *) Read Grep`) |
418
- | `license` | `license` | License name or file reference |
419
- | `compatibility` | `compatibility` | Environment requirements or compatibility notes |
420
- | `disableModelInvocation` | `disable-model-invocation` | When `true`, prevents agents from auto-loading the skill |
421
-
422
- ## Escaping
423
-
424
- The renderer automatically handles special characters in generated output:
425
-
426
- - **YAML frontmatter**: Values containing YAML-special characters (`:`, `#`, `*`, `!`, `[`, `{`, `'`, `"`, etc.) are wrapped in double quotes with internal quotes escaped.
427
- - **Markdown tables**: Literal `|` characters in argument/flag descriptions are escaped as `\|` to prevent broken table rendering.
428
-
429
- No manual escaping is needed — pass raw values and the renderer handles the rest.
430
-
431
- ## Output Structure
432
-
433
- Generated output goes to `<outDir>/skills/<name>/`:
434
-
435
- ```
436
- skills/my-cli/
437
- SKILL.md # Entrypoint — loaded by the agent
438
- commands/ # Per-command documentation mirroring the CLI hierarchy
439
- my-cli.md # Root command
440
- serve.md # Subcommand
441
- db/
442
- migrate.md # Nested subcommand
443
- seed.md
444
- crust.json # Machine-readable bundle metadata (Crust ownership marker)
445
- ```
446
-
447
- ### File Details
448
-
449
- | File | Purpose |
450
- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
451
- | `SKILL.md` | Agent entrypoint with YAML frontmatter and an embedded command reference table listing every command path, type (runnable/group), and documentation link. |
452
- | `commands/*.md` | Per-command reference files. Leaf commands include usage, arguments, flags, defaults, and aliases. Group commands list subcommands with links. |
453
- | `crust.json` | Crust-specific JSON metadata: name, description, and version. Also serves as an ownership marker — its presence indicates the skill was generated by Crust. |
454
-
455
- ## Conflict Detection
456
-
457
- Each Crust-managed skill directory contains a `crust.json` file that acts
458
- as an ownership marker. Both `generateSkill()` and `installSkillBundle()`
459
- refuse to overwrite a target directory in three cases:
460
-
461
- 1. **No `crust.json`** — the directory exists but was not created by Crust
462
- (e.g. manually authored or installed by another tool).
463
- 2. **Kind mismatch** — `crust.json` records a different
464
- [`kind`](#kind-field-on-crustjson) than the install attempt (e.g. an
465
- existing `generated` skill collides with an incoming `bundle`).
466
- 3. **Malformed manifest** — `crust.json` is present but cannot be
467
- interpreted (invalid JSON, top-level non-object, missing `version`, or
468
- an unrecognized `kind` value such as a hand-edit typo).
469
-
470
- All three throw `SkillConflictError`. Pass `force: true` to overwrite, or
471
- uninstall the existing skill first.
472
-
473
- `SkillConflictError.details` carries optional discriminators:
474
-
475
- - `details.kindMismatch?: { existing, attempted }` — set on kind mismatch.
476
- - `details.manifestMalformed?: { reason, rawKind? }` — set on malformed
477
- `crust.json`. `reason` is one of `"parse-error"`, `"not-an-object"`,
478
- `"missing-version"`, or `"unknown-kind"`. `rawKind` is populated only
479
- when `reason === "unknown-kind"`.
480
- - Neither field set — the original "directory exists with no `crust.json`" case.
481
-
482
- ```ts
483
- import { generateSkill, SkillConflictError } from "@crustjs/skills";
484
-
485
- try {
486
- await generateSkill({ command, meta, agents });
487
- } catch (err) {
488
- if (!(err instanceof SkillConflictError)) throw err;
489
-
490
- if (err.details.kindMismatch) {
491
- const { existing, attempted } = err.details.kindMismatch;
492
- console.error(
493
- `Cannot install ${attempted} skill at ${err.details.outputDir} — ` +
494
- `existing skill was installed as ${existing}.`,
495
- );
496
- } else if (err.details.manifestMalformed) {
497
- console.error(
498
- `crust.json at ${err.details.outputDir} is malformed: ` +
499
- `${err.details.manifestMalformed.reason}.`,
500
- );
501
- } else {
502
- console.error(`${err.details.outputDir} exists but was not created by Crust.`);
503
- }
504
- }
505
- ```
506
-
507
- ### Uninstall Cleanup
508
-
509
- When `uninstallSkill()` removes agent install paths, it also checks whether any other agent paths still reference the skill. If no agent installs remain, the canonical store entry (`.crust/skills/<skill>` or `~/.crust/skills/<skill>`) is automatically removed.
510
-
511
- ## Installing Generated Skills
512
-
513
- After generating a skill bundle, consumers can install it by copying the skill directory.
514
-
515
- ### Universal agents (OpenCode, Codex, Cursor, and others)
516
-
517
- ```sh
518
- cp -r skills/my-cli/ .agents/skills/my-cli/
519
- ```
520
-
521
- Global install for universal agents:
522
-
523
- ```sh
524
- cp -r skills/my-cli/ ~/.agents/skills/my-cli/
525
- ```
526
-
527
- ### Claude Code
528
-
529
- ```sh
530
- cp -r skills/my-cli/ .claude/skills/my-cli/
531
- ```
532
-
533
- The agent will discover the skill from `SKILL.md` and load command documentation on demand from the `commands/` directory.
534
-
535
- ## Installing Hand-Authored Bundles
536
-
537
- `generateSkill()` produces a skill bundle from a Crust command tree.
538
- `installSkillBundle()` is the dual entrypoint for **hand-authored** bundles —
539
- use it when you have a directory containing `SKILL.md` and any supporting
540
- files that you want to install through the same canonical-store + agent
541
- fan-out pipeline.
542
-
543
- Use `installSkillBundle()` when:
544
-
545
- - You ship a published CLI package that bundles authored skill directories
546
- alongside generated ones.
547
- - The skill's `SKILL.md` is hand-curated (or produced by your own renderer)
548
- and Crust just needs to handle install plumbing — canonical storage,
549
- symlink/copy fan-out, version tracking, and conflict detection.
550
-
551
- ```ts
552
- import { installSkillBundle } from "@crustjs/skills";
553
- import pkg from "./package.json" with { type: "json" };
554
-
555
- await installSkillBundle({
556
- // Resolved relative to the nearest package.json walking up from
557
- // process.argv[1]. You can also pass an absolute string or a file: URL.
558
- sourceDir: "skills/funnel-builder",
559
- agents: ["claude-code", "opencode"],
560
- version: pkg.version,
561
- });
562
- ```
563
-
564
- ### Where `name`, `description`, and `version` come from
565
-
566
- The bundle's `SKILL.md` frontmatter is the source of truth for `name` and
567
- `description` — Crust reads them but never rewrites the file. Both fields
568
- are required:
569
-
570
- ```yaml
571
- ---
572
- name: funnel-builder
573
- description: Build a sales funnel
574
- ---
575
- ```
576
-
577
- `version` is supplied by the caller and recorded in `crust.json`. Wiring
578
- it to the consuming package's `package.json` `version` (as in the example
579
- above) is the typical pattern; pass any string explicitly when one package
580
- publishes multiple bundles with independent versions:
581
-
582
- ```ts
583
- await installSkillBundle({
584
- sourceDir: "skills/funnel-builder",
585
- agents: ["claude-code"],
586
- version: "2.0.0",
587
- });
588
- ```
589
-
590
- > **Note:** `metadata.version` declared inside the bundle's SKILL.md
591
- > frontmatter is **not** read — the `version` option is the sole source of
592
- > truth for `crust.json` and update detection. If you keep a
593
- > `metadata.version` in your SKILL.md for Agent Skills spec compliance,
594
- > keep it in sync with the value you pass here.
595
-
596
- ### Options
597
-
598
- | Option | Type | Default | Description |
599
- | ------------- | ------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------- |
600
- | `sourceDir` | `string \| URL` | — required | Bundle directory. Absolute path, `file:` URL, or relative path resolved from the nearest `package.json`. |
601
- | `agents` | `AgentTarget[]` | — required | Agents to install for. `[]` validates the bundle without installing (no auto-detection — unlike `generateSkill()`). |
602
- | `version` | `string` | — required | Recorded in `crust.json` and compared on subsequent installs. |
603
- | `scope` | `"global" \| "project"` | `"global"` | Install scope. When `process.cwd()` is the home directory, `"project"` normalizes to `"global"`. |
604
- | `installMode` | `"auto" \| "symlink" \| "copy"` | `"auto"` | Same semantics as `generateSkill()`. `"auto"` symlinks from the canonical store, falling back to copy. |
605
- | `clean` | `boolean` | `true` | Remove the existing skill directory before writing. |
606
- | `force` | `boolean` | `false` | Rewrite even when the recorded version is unchanged, and overwrite a conflicting directory instead of throwing. |
607
-
608
- ### What gets copied
609
-
610
- The bundle's `SKILL.md` plus every supporting file is copied into the
611
- canonical Crust store — markdown, configs, scripts, images, fonts, and other
612
- assets. Bundle files are copied as raw bytes; `SKILL.md` is also parsed as
613
- UTF-8 to read its required frontmatter.
614
-
615
- Bundle content changes do not propagate without a `version` bump:
616
- identical-version reinstalls report `up-to-date` and leave the canonical
617
- store untouched, unless `force: true` is passed. Pass a fresh `version`
618
- (typically wired to the consuming package's `package.json` `version`)
619
- whenever the bundle contents change.
620
-
621
- Bundle contents are copied as authored — no implicit name-based filtering.
622
- Dotfiles, `node_modules/`, `.DS_Store`, and editor cruft are all copied if
623
- present. Keep `sourceDir` clean. The only reserved filename is
624
- `crust.json` at the bundle root (Crust generates this and rejects bundles
625
- that ship one).
626
-
627
- ### Publishing a bundle to npm
628
-
629
- Two gotchas trip up bundle authors who publish to npm:
630
-
631
- 1. **Include the bundle directory in the published tarball.** Add the path
632
- to your `package.json` `files` array and verify with `npm pack --dry-run`
633
- before publishing. Local installs work even when the directory would be
634
- excluded from the tarball, but consumers will hit a missing-`SKILL.md`
635
- error.
636
-
637
- ```json
638
- {
639
- "name": "acme-skills",
640
- "version": "1.0.0",
641
- "files": ["dist", "skills"]
642
- }
643
- ```
644
-
645
- 2. **Consumers point at the published path with `import.meta.resolve`.**
646
- Relative `sourceDir` resolution walks up from the consumer's
647
- `process.argv[1]`, so it lands in the consumer's package — not yours.
648
- Consumers should use a `file:` URL via `import.meta.resolve`:
649
-
650
- ```ts
651
- import skillsPkg from "acme-skills/package.json" with { type: "json" };
652
-
653
- await installSkillBundle({
654
- sourceDir: new URL(import.meta.resolve("acme-skills/skills/funnel-builder")),
655
- agents: ["claude-code"],
656
- version: skillsPkg.version,
657
- });
658
- ```
659
-
660
- For this to work, the bundle directory must be reachable from your
661
- package's `exports` (or accessible as a subpath of the package root).
662
- Bundle authors who want explicit subpath access can declare it in
663
- `package.json` `exports`.
664
-
665
- ### `kind` field on `crust.json`
666
-
667
- Every installed bundle records its origin in `crust.json` as a `kind`
668
- field: `"generated"` for `generateSkill()` output, `"bundle"` for
669
- `installSkillBundle()`. This prevents accidental cross-overwrites:
670
-
671
- - Trying to install a bundle on top of a generated skill (or vice versa) at
672
- the same name throws a `SkillConflictError` whose `details.kindMismatch`
673
- carries `{ existing, attempted }`.
674
- - To proceed anyway, uninstall the existing skill first or pass
675
- `force: true`.
676
-
677
- Legacy `crust.json` files written before this field existed are read as
678
- `kind: "generated"` for backward compatibility — generated installs continue
679
- to update cleanly with no migration step.
680
-
681
11
  ## Documentation
682
12
 
683
- See the full docs at [crustjs.com](https://crustjs.com).
684
-
685
- ## License
686
-
687
- MIT
13
+ Full docs: [crustjs.com/docs/modules/skills](https://crustjs.com/docs/modules/skills)