spec-layer 0.3.0 → 0.5.0

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.
Files changed (3) hide show
  1. package/README.md +116 -12
  2. package/dist/cli.js +2131 -69
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -51,21 +51,93 @@ npm install --save-dev spec-layer
51
51
 
52
52
  `npx spec-layer` then runs the pinned local copy, no `--yes` needed. Pinning
53
53
  also keeps `.speclayer/manifest.json` on one format: 0.1.0 wrote no
54
- `selection` field, and 0.2.0 does.
54
+ `selection` field, and 0.2.0 onward does. `setup` needs 0.3.0 or later; earlier
55
+ versions have no such command, so the setup command the plugin copies fails
56
+ against them. The Foundation landing under `tokens/` as Design Tokens Format
57
+ Module 2025.10 files, rather than `ai/foundation.yaml`, needs 0.4.0 or later.
58
+ `tools` and `skill` need 0.5.0 or later.
55
59
 
56
60
  ## Commands
57
61
 
58
62
  | Command | What it does |
59
63
  |---|---|
60
- | `init --id lib_... [--out DIR] [selection]` | Writes `speclayer.json` so later commands need no flags. |
64
+ | `setup --id lib_... --key sl_... [--out DIR] [selection]` | Writes `speclayer.json`, stores the key in `speclayer.local.json`, then pulls. The command the plugin copies. |
65
+ | `init --id lib_... [--out DIR] [selection]` | Writes `speclayer.json` so later commands need no flags. No key, no network. |
61
66
  | `pull [--id lib_...] [--key sl_...] [selection]` | Fetches the library and writes it into `DIR` (default `.speclayer`). |
62
67
  | `status [--id lib_...] [--key sl_...]` | Checks freshness without writing. Exits `2` when the local copy is behind. |
63
68
  | `list` | Lists every artifact in the last pull, with its file path or `not written`. |
64
- | `show foundation [--canonical]` | Prints the Foundation's AI YAML to stdout. |
69
+ | `show foundation [--canonical]` | Prints the Foundation's DTCG document to stdout. |
65
70
  | `show component NAME [--canonical]` | Prints one component's AI YAML to stdout. |
71
+ | `tools [--json]` | Lists every command with what it reaches, needs, and writes. |
72
+ | `skill [--install] [--agent HOST]... [--platform P] [--json]` | Prints a guide for a coding agent, adapted to this repository and the last pull; `--install` writes it where the agent reads instructions. |
66
73
 
67
74
  `--api URL` overrides the API origin (default `https://api.spec-layer.com`).
68
75
 
76
+ ## For a coding agent
77
+
78
+ The setup command is usually handed to a coding agent, and a bare command
79
+ tells the agent nothing about what it just wrote or how to read it. Two
80
+ local commands close that gap; neither needs a key or the network.
81
+
82
+ `spec-layer tools` lists every command with the facts an agent needs before
83
+ running one: whether it reaches the network, whether it needs the pull key,
84
+ what it writes, and what each exit code means. `--json` prints the same list
85
+ in a stable shape for machines.
86
+
87
+ `spec-layer skill` prints a guide to the pulled files, and `--install` writes
88
+ it where the agent reads project instructions:
89
+
90
+ ```bash
91
+ npx spec-layer skill --install
92
+ ```
93
+
94
+ `setup` names this command as the next step after a successful pull, and the
95
+ plugin's Publish screen has a **Copy for an AI agent** button that copies the
96
+ setup command already followed by it.
97
+
98
+ The guide is built from three things and nothing else:
99
+
100
+ - The tool list above.
101
+ - **What the last pull wrote.** Every component with its file path, every
102
+ token collection with its modes and default, the token files, the
103
+ `report.json` counts, and how many tokens landed as plain numbers because
104
+ their Figma scopes state no unit. Before a pull the guide says so and names
105
+ nothing.
106
+ - **What the repository root says about the codebase.** Detection reads only
107
+ the top level of the working directory (`package.json` dependency names,
108
+ build files, agent configuration directories) and names the file behind
109
+ every conclusion. A signal it cannot find is reported as absent, never
110
+ guessed. The platform decides which Figma `code_syntax` key the guide points
111
+ at (`WEB`, `iOS`, `ANDROID`; Flutter has none) and which token pipeline
112
+ advice it gives: Tailwind, Style Dictionary (with the `legacy` value form
113
+ suggested when package.json declares a major version below 5), Swift,
114
+ Kotlin or Compose, or Dart.
115
+
116
+ `--platform web|ios|android|flutter` overrides the detected target, which is
117
+ the way to get platform advice in a repository that carries no signal (a new
118
+ directory, a monorepo whose apps sit one level down). `--json` prints the
119
+ detection, the pull summary, and the install targets instead of the guide.
120
+
121
+ `--install` writes to every agent host detected at the root, or to the hosts
122
+ named with a repeatable `--agent`, or to `AGENTS.md` when nothing is detected
123
+ and nothing is named. Each run says which files it wrote, updated, or left
124
+ unchanged.
125
+
126
+ | Host | `--agent` | File |
127
+ |---|---|---|
128
+ | Claude Code | `claude` | `.claude/skills/spec-layer/SKILL.md` |
129
+ | Cursor | `cursor` | `.cursor/rules/spec-layer.mdc` |
130
+ | GitHub Copilot | `copilot` | `.github/instructions/spec-layer.instructions.md` |
131
+ | Windsurf | `windsurf` | `.windsurf/rules/spec-layer.md` |
132
+ | Gemini CLI | `gemini` | `GEMINI.md`, between `<!-- spec-layer:begin -->` and `<!-- spec-layer:end -->` |
133
+ | Anything that reads `AGENTS.md` | `agents-md` | `AGENTS.md`, between the same markers |
134
+
135
+ The dedicated files are replaced whole. The shared files (`AGENTS.md`,
136
+ `GEMINI.md`) are yours: only the marked block is replaced, and a file without
137
+ the markers gets the block appended. Re-run `skill --install` after a pull
138
+ that adds components or when the codebase changes stack. The written files
139
+ carry no key and are meant to be committed with the rest of the repository.
140
+
69
141
  ## Pulling part of a library
70
142
 
71
143
  By default `pull` writes the Foundation and every documented component. When
@@ -166,15 +238,22 @@ matter what the ignore rules say.
166
238
 
167
239
  ```text
168
240
  .speclayer/
169
- bundle.json the published bundle, verbatim
170
- manifest.json every artifact indexed by content hash and ai path, plus the selection
171
- ai/foundation.yaml tokens, styles, and modes (when selected and the library has a Foundation)
172
- ai/components/<name>.yaml one file per selected component
241
+ bundle.json the published bundle, verbatim
242
+ manifest.json every artifact indexed by content hash and path, plus the selection
243
+ tokens/ the Foundation as Design Tokens Format Module 2025.10 files
244
+ <collection>.<mode>.json one file per collection and mode, rooted at the collection name
245
+ styles.typography.json text styles as typography composites (when present)
246
+ styles.effects.json effect styles as shadow composites (when present)
247
+ resolver.json Design Tokens Resolver Module 2025.10: sets, modifiers, order
248
+ spec-layer.meta.json Figma ids, scopes, code syntax, publication, keyed by DTCG path
249
+ report.json what DTCG could not express, with reasons and stable ids
250
+ ai/components/<name>.yaml one file per selected component
173
251
  ```
174
252
 
175
- Point your agent at `.speclayer/ai/`. The YAML there is the same compact form
176
- the plugin's **Copy for AI** puts on your clipboard; `bundle.json` additionally
177
- holds the full canonical artifacts if you need them.
253
+ Point your agent at `.speclayer/ai/` and `.speclayer/tokens/`. The component
254
+ YAML is the same compact form the plugin's **Copy for AI** puts on your
255
+ clipboard; `bundle.json` additionally holds the full canonical artifacts if
256
+ you need them.
178
257
 
179
258
  In `manifest.json`, an artifact the selection left unwritten has `"aiPath":
180
259
  null`. A manifest from CLI 0.1.0 has no `selection` field and means
@@ -189,14 +268,39 @@ When nothing changed since the last pull with the same selection, `pull`
189
268
  prints `Already up to date` and writes nothing. Every republish stamps a new
190
269
  export id and time into the canonical artifacts, so `bundle.json` and
191
270
  `manifest.json` change on each republish even when the content did not. The
192
- `ai/` YAML files and the content hashes stay stable.
271
+ `ai/` YAML files, the `tokens/` files, and the content hashes stay stable.
272
+
273
+ ## Configuring the token output
274
+
275
+ `speclayer.json` may carry a `dtcg` block:
276
+
277
+ {
278
+ "libraryId": "lib_...",
279
+ "outDir": ".speclayer",
280
+ "dtcg": {
281
+ "values": "standard",
282
+ "units": { "Foundation/spacing/*": "px", "Foundation/radius/*": "px" }
283
+ }
284
+ }
285
+
286
+ `values` is `standard` (the 2025.10 object forms, the default) or `legacy`
287
+ (the string forms Style Dictionary 4 and Tokens Studio read today). `units`
288
+ promotes a number whose Figma scopes state no unit to a dimension. Keys are a
289
+ collection name, a slash, and a glob over the variable name. An override that
290
+ contradicts a stated scope is ignored and listed in `report.json`. Nothing is
291
+ inferred from a name. Changing the `dtcg` block re-projects `tokens/` on the
292
+ next `pull` even when the library has not been republished.
293
+
294
+ Point Style Dictionary at `.speclayer/tokens/` and load the files
295
+ `resolver.json` names for the mode you are building. The metadata sidecar and
296
+ the report are not token files; exclude them from token globs.
193
297
 
194
298
  ## Exit codes
195
299
 
196
300
  | Code | Meaning |
197
301
  |---|---|
198
302
  | `0` | Success, or `status` found the local copy up to date. |
199
- | `1` | Usage error, bad key or id, unknown component name, or a network or server failure. |
303
+ | `1` | Usage error, bad key or id, unknown component name, a network or server failure, or a file `skill --install` could not write. |
200
304
  | `2` | `status` only: the local copy is behind, or no local pull exists yet. |
201
305
 
202
306
  `status` is safe in CI: it writes nothing, and exit `2` is the signal to run