craftar 0.9.0 → 0.11.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Craft, sync and convert AI-coding workspace harnesses — rules, agents, commands, skills, MCP servers — across every client workspace you maintain and every AI coder each team uses.
4
4
 
5
- > Status: **phase 0 prototype**. `import`, `sync`, `status`, `diff`, `explain`, `ls` work end-to-end for the `claude-code` and `kiro` targets and are validated byte-for-byte against a real workspace (see *Oracle*). The Forge commands `forge variants`, `forge diff` (with a suggested class per hunk) and `forge unify` (`--take base|variant`, `take: param` to turn a value into a `{{key}}` parameter, and `take: section` to turn a client block into a section) also work, covered by the unit and golden suites rather than the oracle, and `import` is render-aware: importing into an existing Forge reuses a base whose render equals the workspace file, and edits an existing profile and the recipes it owns in place. Ingredient bodies can hold client-specific **sections** (`<!-- craftar:section <name> -->` … `<!-- /craftar:section -->`), overridden by a profile's `sections` and a workspace's `overrides.sections`; import infers each client's content and `forge unify` can extract a section from a variant, and a Forge that uses them declares `schema: 2` (see *Forge layout*). The read-only catalogue — `recipes`, `ingredients` and `targets` with the capability matrix — works too. Everything else in the spec (profiles with IDP/PM-tool integrations, local services, `dotnet new` project templates, `craftar ui`, `craftar mcp`) is not built yet.
5
+ > Status: **phase 0 prototype**. `import`, `sync`, `status`, `diff`, `explain`, `ls` work end-to-end for the `claude-code` and `kiro` targets and are validated byte-for-byte against a real workspace (see *Oracle*). The Forge commands `forge variants`, `forge diff` (with a suggested class per hunk) and `forge unify` (`--take base|variant`, `take: param` to turn a value into a `{{key}}` parameter, and `take: section` to turn a client block into a section) also work, covered by the unit and golden suites rather than the oracle, and `import` is render-aware: importing into an existing Forge reuses a base whose render equals the workspace file, and edits an existing profile and the recipes it owns in place. Ingredient bodies can hold client-specific **sections** (`<!-- craftar:section <name> -->` … `<!-- /craftar:section -->`), overridden by a profile's `sections` and a workspace's `overrides.sections`; import infers each client's content and `forge unify` can extract a section from a variant, and a Forge that uses them declares `schema: 2` (see *Forge layout*). The read-only catalogue — `recipes`, `ingredients` and `targets` with the capability matrix — works too, and a workspace can name its Forge by git URL with an optional `ref`, read from a per-machine cache, with a lock that records the ref, commit, recipes and targets it was generated from (see *Remote Forge*). Everything else in the spec (profiles with IDP/PM-tool integrations, local services, `dotnet new` project templates, `craftar ui`, `craftar mcp`) is not built yet.
6
6
 
7
7
  ## The idea in one paragraph
8
8
 
@@ -52,10 +52,10 @@ From then on, change a rule in `forge/ingredients/rules/<name>/rule.md`, run `cr
52
52
 
53
53
  | Command | What it does |
54
54
  |---|---|
55
- | `craftar import --from claude-code --forge <dir> --profile <name> [--workspace .] [--write-config]` | Reads `.claude/{rules,agents,commands,skills,scripts,hooks}`, `.mcp.json` and, when present, `.kiro/steering` (for inclusion modes and hand-written steering). Creates ingredients, recipes (`base`, one `stack-*` per scoped rule, `<profile>-steering`) and a profile, or updates them. An ingredient already in the Forge is reused when the base, **rendered** for this profile (its declared defaults, the profile's `params`, the workspace's `overrides.params`), equals the workspace file; failing that, when a unique, proved assignment of the base's declared `{{keys}}` reproduces it, the values are **inferred** into the profile's `params` (one value per key per run; never a change another ingredient would feel). A base with section markers is rendered with the profile's `sections` and the workspace's `overrides.sections` first; when the workspace file differs from it only inside sections, the unique content that reproduces the file byte for byte is **inferred** into the profile's `sections` (tried after params, never combined with them; the report counts lines and never prints the content). An import that writes a section value, or compares a workspace file against a base holding markers, sets `schema: 2` in `craftar.forge.yaml`. A reused base takes the place its `<name>--<profile>` variant held: the profile moves to the shared recipe when that orders the base there, and an owned recipe gets the base in the variant's slot, so the rule order (and `AGENTS.md`) stays as it was. Anything else becomes a `<name>--<profile>` variant that emits under the original name, with the reason, so the workspace still round-trips while you decide what to unify. A shared recipe is never widened for one client: a profile whose ingredients differ from `base` or a `stack-*` gets its own `<recipe>--<profile>`. An existing profile is merged in place (`params`, `sections`, the recipes import owns, missing `targets`; every other field and comment kept, and an empty `{}` / `[]` it does not change stays on its line), as is a recipe the profile owns; `--write-config` merges an existing `craftar.yaml` (`forge`, `profile`, `targets`). The report adds `rendered` (with `sections <names>` when a section value filled the render), `inferred`, `sectioned`, `param <key>: <old> → <new>`, `section <key> <name>: <old> → <new>`, `forge craftar.forge.yaml edited (schema: 2)` and `profile … created|edited|unchanged` lines. It refuses, with the Forge untouched, a Forge that does not load, a profile or recipe or `craftar.yaml` that does not round-trip through the YAML writer, a misplaced profile, a recipe import writes whose file and `name` disagree, a workspace override that does not parse, a literal `{{key}}` the profile would render, changing a recipe or variant another profile uses, a workspace file holding a section marker at column 0 (sync would not reproduce it: indent it), a Forge base with malformed section markers, and a `craftar.forge.yaml` it needs to bump to `schema: 2` that does not round-trip (set it by hand). Ingredients holding a secret-like value (tokens, private keys, high-entropy MCP `env`/`args` values) are rejected and listed by location — the value is never printed. A UTF-16 file with a byte-order mark is decoded for the scan; UTF-16 without one is not detected. An ingredient that would not load back into the Forge (a name that is not slug-like, a non-string MCP `env` value) refuses the import, naming its source; so does an ingredient already in the Forge whose `ingredient.yaml` has an unknown key or a YAML syntax error, naming that file. Every read and check runs before the first write, so an import that fails leaves the Forge untouched and says so. |
56
- | `craftar status` | Classifies every file the Forge would produce: `new`, `update`, `unchanged`, `adopt`, `drift`, `collision`, `orphan`, `orphan-drift`. A `.json` file not yet in `craftar.lock` that parses to the planned value with its keys in the same order (it differs only in whitespace, escapes, number spelling or duplicate keys) is `adopt`, and the first `sync` rewrites it with the planned bytes — by design. For `claude-code`'s `.mcp.json` that is two-space JSON keeping the file's BOM and line endings; Kiro's JSON files become CRLF without a BOM, like every Kiro text file. A different key order is a `collision` — except for integer-like keys, which `JSON.parse` reorders. A locked JSON file reformatted by hand is `drift`, not `adopt`. `--json` for tooling. Exits 1 on malformed section markers and on a section marker in an ingredient the workspace resolves while `craftar.forge.yaml` declares `schema: 1` (or none), naming the Forge file and line, and when a rendered file would still hold a marker line, naming the ingredient, file and rendered line — as do `sync`, `diff`, `explain` and `ls`. Warns about a section value that names no ingredient, or no marker of an ingredient the workspace resolves, and about marker lines in an emitted file not every target renders as text (copied as they are). |
57
- | `craftar sync` | Renders sections (no rendered body holds a marker; an emitted file not every target renders as text keeps its markers, with a warning), then writes the plan and `craftar.lock`. `--dry-run` shows without writing. `--check` exits 1 when anything is out of sync (CI). `--overwrite-drift` regenerates hand-edited files (explicit, never default). |
58
- | `craftar diff [path]` | Line diff between disk and what the Forge would generate. |
55
+ | `craftar import --from claude-code --forge <dir> --profile <name> [--workspace .] [--write-config]` | Reads `.claude/{rules,agents,commands,skills,scripts,hooks}`, `.mcp.json` and, when present, `.kiro/steering` (for inclusion modes and hand-written steering). Creates ingredients, recipes (`base`, one `stack-*` per scoped rule, `<profile>-steering`) and a profile, or updates them. An ingredient already in the Forge is reused when the base, **rendered** for this profile (its declared defaults, the profile's `params`, the workspace's `overrides.params`), equals the workspace file; failing that, when a unique, proved assignment of the base's declared `{{keys}}` reproduces it, the values are **inferred** into the profile's `params` (one value per key per run; never a change another ingredient would feel). A base with section markers is rendered with the profile's `sections` and the workspace's `overrides.sections` first; when the workspace file differs from it only inside sections, the unique content that reproduces the file byte for byte is **inferred** into the profile's `sections` (tried after params, never combined with them; the report counts lines and never prints the content). An import that writes a section value, or compares a workspace file against a base holding markers, sets `schema: 2` in `craftar.forge.yaml`. A reused base takes the place its `<name>--<profile>` variant held: the profile moves to the shared recipe when that orders the base there, and an owned recipe gets the base in the variant's slot, so the rule order (and `AGENTS.md`) stays as it was. Anything else becomes a `<name>--<profile>` variant that emits under the original name, with the reason, so the workspace still round-trips while you decide what to unify. A shared recipe is never widened for one client: a profile whose ingredients differ from `base` or a `stack-*` gets its own `<recipe>--<profile>`. An existing profile is merged in place (`params`, `sections`, the recipes import owns, missing `targets`; every other field and comment kept, and an empty `{}` / `[]` it does not change stays on its line), as is a recipe the profile owns; `--write-config` merges an existing `craftar.yaml` (`forge`, `profile`, `targets`). The report adds `rendered` (with `sections <names>` when a section value filled the render), `inferred`, `sectioned`, `param <key>: <old> → <new>`, `section <key> <name>: <old> → <new>`, `forge craftar.forge.yaml edited (schema: 2)` and `profile … created\|edited\|unchanged` lines. It refuses, with the Forge untouched, a Forge that does not load, a profile or recipe or `craftar.yaml` that does not round-trip through the YAML writer, a misplaced profile, a recipe import writes whose file and `name` disagree, a workspace override that does not parse, a literal `{{key}}` the profile would render, changing a recipe or variant another profile uses, a workspace file holding a section marker at column 0 (sync would not reproduce it: indent it), a Forge base with malformed section markers, and a `craftar.forge.yaml` it needs to bump to `schema: 2` that does not round-trip (set it by hand). Ingredients holding a secret-like value (tokens, private keys, high-entropy MCP `env`/`args` values) are rejected and listed by location — the value is never printed. A UTF-16 file with a byte-order mark is decoded for the scan; UTF-16 without one is not detected. An ingredient that would not load back into the Forge (a name that is not slug-like, a non-string MCP `env` value) refuses the import, naming its source; so does an ingredient already in the Forge whose `ingredient.yaml` has an unknown key or a YAML syntax error, naming that file. Every read and check runs before the first write, so an import that fails leaves the Forge untouched and says so. |
56
+ | `craftar status` | With a remote Forge, the header's second line names it — `forge <url> @ <ref \| <branch> (default branch)> <commit>`, plus `· lock <commit>` when the Forge moved since the last sync — and `--json` carries `forge: {kind, source, ref, defaultBranch, commit, lockCommit, fetched}` for every Forge. Classifies every file the Forge would produce: `new`, `update`, `unchanged`, `adopt`, `drift`, `collision`, `orphan`, `orphan-drift`. A `.json` file not yet in `craftar.lock` that parses to the planned value with its keys in the same order (it differs only in whitespace, escapes, number spelling or duplicate keys) is `adopt`, and the first `sync` rewrites it with the planned bytes — by design. For `claude-code`'s `.mcp.json` that is two-space JSON keeping the file's BOM and line endings; Kiro's JSON files become CRLF without a BOM, like every Kiro text file. A different key order is a `collision` — except for integer-like keys, which `JSON.parse` reorders. A locked JSON file reformatted by hand is `drift`, not `adopt`. `--json` for tooling. Exits 1 on malformed section markers and on a section marker in an ingredient the workspace resolves while `craftar.forge.yaml` declares `schema: 1` (or none), naming the Forge file and line, and when a rendered file would still hold a marker line, naming the ingredient, file and rendered line — as do `sync`, `diff`, `explain` and `ls`. Warns about a section value that names no ingredient, or no marker of an ingredient the workspace resolves, and about marker lines in an emitted file not every target renders as text (copied as they are). |
57
+ | `craftar sync` | Renders sections (no rendered body holds a marker; an emitted file not every target renders as text keeps its markers, with a warning), then writes the plan and `craftar.lock` (schema 2: the Forge's source, requested `ref` and commit, the resolved recipes and targets — rewritten only when that content changes). With a remote Forge it fetches first and exits 1 when the fetch fails, `--dry-run` and `--check` included. `--dry-run` shows without writing. `--check` exits 1 when anything is out of sync (CI). `--overwrite-drift` regenerates hand-edited files (explicit, never default). |
58
+ | `craftar diff [path] [--exit-code]` | Line diff between disk and what the Forge would generate, for every file `sync --check` refuses: `update`, `drift`, `collision`, `new`, an `orphan` (shown as the removal of the whole file — the next `sync` deletes it) and an `orphan-drift` (a header and one line: `sync` keeps it). `[path]` limits it to the one file whose workspace-relative path, as `status` prints it, equals it. Exits 0 by default, differences or not. `--exit-code` exits 1 when there are differences — exactly when `sync --check` would — and makes a `[path]` that names no file craftar manages an error (exit 1, nothing on stdout); without the flag such a path prints `no differences`. With a remote Forge, `--exit-code` also exits 1 when the fetch fails, as `sync --check` does; plain `diff` reads the cached copy with a warning. |
59
59
  | `craftar explain <path>` | Which ingredient, recipe chain, target and origin produced a file and, for an ingredient with sections, which layer filled each one: `sections flavors (profile globex), extra (default)` (`default`, `profile <p>` or `workspace`). `AGENTS.md` gets no sections line: it is not one ingredient. |
60
60
  | `craftar ls` | Recipes and ingredients resolved for this workspace. |
61
61
  | `craftar recipes [--forge <dir> [--profile <name>] \| --workspace <dir>] [--json]` | Every recipe of the Forge, sorted by name: slot, the parents it extends, the ingredients it lists itself and the profiles that reach it. In a workspace (or with `--forge <dir> --profile <name>`) each recipe says whether it is in use and why — `profile`, `workspace` (`recipes.add`), `extends <child>` — and a recipe `recipes.remove` names reads `removed by this workspace`. A context that does not resolve (two recipes on one slot, an unknown recipe, a cycle) still lists everything, marks nothing and warns. Read-only: it resolves, never plans. `--json` is a contract: `{forge, context, recipes, warnings}`. |
@@ -65,7 +65,7 @@ From then on, change a rule in `forge/ingredients/rules/<name>/rule.md`, run `cr
65
65
  | `craftar forge diff <type/name> [--against <profile>] [--forge <dir> \| --workspace <dir>] [--json]` | Shows the differences between a base ingredient and each of its variants: a header carrying the same distance `forge variants` reports, then hunk by hunk, each with a suggested class and reason — `evolution` (one side is newer text), `value` (an identifier-like token swapped in shared prose, with a suggested `param.<slug>`) or `block` (lines only one side has) — then the files that exist on only one side. A suggestion never decides anything. It compares the raw Forge text, section marker lines included, so a base with markers shows them as hunks against a variant that has none. Read-only. `--json` prints an array of `{ref, profile, distance, diff}`; each hunk carries `suggestion: {class, reason, tokens?}` next to its `kind`. |
66
66
  | `craftar forge unify <type/name> --profile <p> (--take base\|variant \| --plan <file> \| --save-plan <file>) [--forge <dir> \| --workspace <dir>] [--json]` | Resolves one variant back into its base, hunk by hunk. `--save-plan` writes a reviewable plan with every decision set to `keep`, each hunk annotated with its suggested class (which `--plan` ignores) and, for a `value` hunk, a pre-filled `params` list (`token` → suggested `key`); on a `block` hunk, a pre-filled `section: { name }` from the Markdown heading above (or `section-<n>`); and on a hunk touching a section the base already has, that section's name. It refuses a path that resolves inside the Forge (after `..` segments and symlinks) and a path that already exists, so it never overwrites a Forge file or a plan you already edited; it writes nothing else. A hunk set to `take: param` turns each listed token into `{{key}}` in the base, declares the base's text as the key's default in the base's `ingredient.yaml` and writes the variant's text into the variant profile's `profile.yaml` `params` — only after proving that both the base's and the variant's text render back exactly, and only when the same plan resolves the variant; it refuses (with the Forge untouched) a key another layer, profile or ingredient already uses, a variant another profile also uses, a whitespace-only difference, and a YAML file that would not round-trip unchanged. A hunk set to `take: section` (with `section: { name, lines? }`) wraps the base's lines in section markers as the default and writes the variant's lines into the variant profile's `sections` — consecutive hunks with one name form one section, `lines: "<from>-<to>"` widens it over equal base lines, and hunks inside a section the base already has only write the profile value; it is proved (both sides render back exactly) and needs the same plan to resolve the variant; `take: param` and `take: section` may share a plan, never a hunk. It refuses (Forge untouched) a `take: param` or `take: section` on a file no target emits, a variant that holds markers, a profile that already sets that section (another profile for a new section, or the variant's profile with other content), a span that cuts a hunk or crosses another section, a span that covers a hunk outside the run (including `take: base` on a hunk inside a section the plan fills), a hunk mixing lines inside and outside an existing section, and a span reaching a missing final newline; when it adds a section to a Forge still at `schema: 1` it sets `schema: 2` in `craftar.forge.yaml` in place (refused if the file does not round-trip). `--plan` applies an edited plan, refusing when it is not for this exact ingredient/profile or either side's fingerprint moved since it was saved. `--take base\|variant` resolves every decision to that side. Writes the merged base and, once every difference is resolved, removes the variant and rewrites every recipe reference to it (`ingredients`) to name the base. It never deletes a recipe and never edits an `extends`; it edits a profile only to write the values of a `take: param` or `take: section` extraction into the variant's own profile, and otherwise never: a `<recipe>--<profile>` left identical to `<recipe>` is reported as a warning, to be removed by hand after repointing the lists that name it — unify does not, because a workspace or an `extends` chain may also name `<recipe>` and the recipe order or param precedence would change. Unify cannot reach workspaces, so a removed variant is reported as a warning for any `craftar.yaml` that disables it in `overrides.ingredients.disable`. Every recipe rewrite is checked before the first write, so one that cannot land (a reference behind a YAML alias) is refused with the Forge untouched; a failure after writing began (an I/O error, a locked file) names the paths already touched and the `git checkout` / `git clean` commands that undo them. A merge never adds, removes or changes a section marker other than the sections the plan declares; a plan or `--take variant` that would is refused before the first write — take `base` for the marker lines, or `take: section` to fill the section; the citation checks of `take: param` also read the profiles' section values, which can cite `{{key}}`. `ingredient.yaml` is never merged: when the two sides' metadata differs (beyond `name`, `as` and `origin`), the variant stays unresolved and the differing fields are named — edit it by hand, or `--take base` to discard the variant, metadata included. Requires a clean git checkout in the Forge with at least one commit (`--save-plan` excepted) — the Forge has no lock, so git is the undo. It also refuses when any path it would overwrite or delete (the base, the variant, the recipe files it rewrites, the profile a parameter or section extraction edits, `craftar.forge.yaml` when it is bumped) is ignored, untracked, modified, or flagged skip-worktree or assume-unchanged in the index, since git could not restore it. `--json` prints `{base, profile, resolved, written, removed, unresolved, variantRemoved, recipes: {rewritten, identicalToSibling}, metaDiffers, params, profileEdited, sections, manifestEdited, warnings}` for `--take`/`--plan` (every key always present, `[]` when empty), or `{base, profile, plan, unresolved}` for `--save-plan`. |
67
67
 
68
- All commands take `--workspace <dir>` (default: current directory); the `forge` commands, `recipes` and `ingredients` also take `--forge <dir>` as an alternative to it, and `targets` needs no Forge.
68
+ All commands take `--workspace <dir>` (default: current directory); the `forge` commands, `recipes` and `ingredients` also take `--forge <dir>` as an alternative to it — a directory: a URL there is refused — and `targets` needs no Forge. With a remote Forge (see *Remote Forge*), `status`, `sync`, `diff`, `explain`, `ls`, `recipes`, `ingredients`, `forge variants` and `forge diff` fetch first and take `--offline` to use the cached copy; `targets` never fetches; `forge unify` refuses a workspace whose Forge is remote — clone it and pass `--forge <dir>`; `import --write-config` keeps a remote `forge:` and sets only `profile` and `targets`.
69
69
 
70
70
  ## Forge layout
71
71
 
@@ -171,7 +171,8 @@ params: { angularVersion: { default: "20" } }
171
171
  Workspace `craftar.yaml`:
172
172
 
173
173
  ```yaml
174
- forge: ../forge # path today; git URL later
174
+ forge: ../forge # a path, or a git URL (see Remote Forge)
175
+ ref: v1.4.0 # optional, with a git URL: a branch, a tag or a full SHA
175
176
  profile: acme-portal
176
177
  targets: [claude-code, kiro] # optional, overrides the profile
177
178
  recipes: { add: [], remove: [] }
@@ -250,13 +251,37 @@ npm test
250
251
 
251
252
  Copy a workspace with `.claude/` and `.kiro/` into `fixtures/` (keep `local-stack/` and `projects/` out).
252
253
 
254
+ ## Remote Forge
255
+
256
+ `forge:` may be a git URL — `https://…`, `ssh://…`, `file://…`, or the SCP-like `git@host:org/forge.git` (any SSH user) — with an optional `ref`: a branch (followed: its tip at each fetch), a tag or a full 40-hex SHA (fixed); `refs/heads/<x>` / `refs/tags/<x>` when a name is both; no `ref` follows the remote's default branch. Abbreviated SHAs are refused. A `ref` next to a path `forge:` is ignored, with a warning.
257
+
258
+ - **The cache.** Each machine keeps one copy per URL in `$CRAFTAR_HOME/forges/` (`~/.craftar` by default): a bare repository and one tree per resolved commit, never written by Craftar, shared by every workspace on the machine. Each tree holds the commit's bytes on every platform: the host's `core.autocrlf`, `core.eol` and global attributes file do not apply to it; the Forge's own `.gitattributes` does. Trees unused for 14 days are removed after a fetch. It is the one place Craftar writes outside a workspace and a Forge on its own.
259
+ - **The network.** `sync` (with `--check` and `--dry-run`) and `diff --exit-code` fetch first and exit 1 when they cannot; `status`, `diff`, `explain`, `ls`, `recipes`, `ingredients`, `forge variants` and `forge diff` fall back to the cached copy with a warning; `--offline` uses the cached copy on purpose; with no cached copy every one of them exits 1. `targets` never fetches: it reads the cached copy, and without one prints the matrix unmarked, with a warning. A full SHA already cached is not fetched again.
260
+ - **Authentication belongs to git** (credential helper, SSH agent). A URL holding credentials (`https://user:token@…`, a password in any scheme) is refused in `craftar.yaml` and `craftar.local.yaml`, naming the file and never the value. In CI, configure git (e.g. a credential helper or an SSH deploy key), never a token in `forge:`; without a terminal, git does not prompt.
261
+ - **Writing into the Forge** stays local: `import` and `forge unify` need a clone passed as `--forge <dir>`; Craftar never pushes. After importing into the clone, push it for `sync` to see the import.
262
+ - **`craftar.local.yaml`** may override `forge:` (a local clone while you work on the Forge); every planning command then warns not to commit `craftar.lock` or the generated files.
263
+
253
264
  ## Roadmap (from the functional spec)
254
265
 
255
- Phase 0 (this): schema, import, sync/status/diff/explain, claude-code + kiro + agents-md targets, lock, drift, orphans; the read-only catalogue (`recipes`, `ingredients`, `targets` with the capability matrix).
256
- Next: `craftar init` from a profile; profile-driven integrations (PM tool → MCP, IDP → MCP); `service` ingredients with compose fragments (`craftar services up`); `dotnet new` template registration; rulesync bridge for Codex/Kimi/Cursor specifics; remote Forge (git URL + ref); `craftar docs validate`; GitHub Action and Azure Pipelines task around `sync --check`; `craftar ui`; `craftar mcp` + Claude Code / Agent Plugin packaging.
266
+ Phase 0 (this): schema, import, sync/status/diff/explain, claude-code + kiro + agents-md targets, lock, drift, orphans; the read-only catalogue (`recipes`, `ingredients`, `targets` with the capability matrix); remote Forge (git URL + `ref`, a per-machine cache, the schema 2 lock).
267
+ Next: `craftar init` from a profile; profile-driven integrations (PM tool → MCP, IDP → MCP); `service` ingredients with compose fragments (`craftar services up`); `dotnet new` template registration; rulesync bridge for Codex/Kimi/Cursor specifics; `craftar docs validate`; GitHub Action and Azure Pipelines task around `sync --check`; `craftar ui`; `craftar mcp` + Claude Code / Agent Plugin packaging.
257
268
 
258
269
  ## Upgrading
259
270
 
271
+ ### to 0.11.0
272
+
273
+ - **`craftar.lock` is schema 2**, written by the next `sync` of every workspace, path Forge or remote: it adds `forge.ref`, `recipes` and `targets`. **Once a schema 2 lock is committed, every craftar up to 0.10.1 stops on it** (a zod error on `schema`) until upgraded — upgrade the whole team, and CI, before committing it. This craftar reads schema 1 and 2, and refuses a later one by name.
274
+ - **The lock is rewritten only when its content changes** (`generatedAt` is when it last did): a `sync` that changes nothing no longer touches it. The first `sync` after upgrading rewrites it once.
275
+ - **A `user@host:path` value of `forge:` is a URL** now (any SSH user, not only `git@`); before, it was read as a relative path.
276
+ - A `forge:` value holding credentials is refused; a `ref` next to a path `forge:` is ignored with a warning; `forge:` from `craftar.local.yaml` adds a do-not-commit warning.
277
+ - `status --json` gains a `forge` key (additive). `diff`, `explain`, `ls`, `forge variants` and `forge diff` print warnings about loading the workspace on stderr. A missing path Forge reads `Forge not found at <path>`.
278
+
279
+ ### to 0.10.0
280
+
281
+ - **`craftar diff` shows orphans.** A file the Forge no longer produces is printed as the removal of the whole file (`+++ <path> (forge: no longer produced — sync removes it)`), and a hand-edited one as a header and one line, since `sync` keeps it. Output changes only in a workspace that has an `orphan` or an `orphan-drift` — one whose only pending change was an orphan used to print `no differences`; elsewhere it is byte for byte 0.9.0's.
282
+ - **`craftar diff --exit-code`** exits 1 when there are differences — exactly when `sync --check` would — and refuses a `[path]` that names no file craftar manages. Without the flag `diff` still exits 0.
283
+ - **No byte change**: no emitter, `plan`, `status` or `sync` changed. No workspace sees `update`.
284
+
260
285
  ### to 0.9.0
261
286
 
262
287
  - **Three new read-only commands**: `craftar recipes`, `craftar ingredients` and `craftar targets`. They write nothing — no generated file, no lock, no Forge file.
package/dist/cli.js CHANGED
@@ -4,6 +4,7 @@ import path from "node:path";
4
4
  import { promises as fs } from "node:fs";
5
5
  import YAML from "yaml";
6
6
  import { importClaudeCode } from "./importers/claude-code.js";
7
+ import { classifyForge } from "./core/remote.js";
7
8
  import { loadWorkspace, plan, readLock, status, apply, resolveForge, resolveForgeSource, WORKSPACE_FILE } from "./core/sync.js";
8
9
  import { resolve, sectionKey } from "./core/resolve.js";
9
10
  import { catalogueContext, listRecipes, listIngredients, checkType } from "./core/catalogue.js";
@@ -19,8 +20,14 @@ import { checkParamWrites, writeParamFile } from "./core/param-writes.js";
19
20
  import { HUNK_CLASSES, INGREDIENT_TYPES, UnifyPlanSchema } from "./schema/index.js";
20
21
  process.stdout.on("error", (e) => { if (e.code === "EPIPE")
21
22
  process.exit(0); });
23
+ /**
24
+ * Q13-1, answered by the user (2026-10-07): with a remote Forge whose fetch fails, `diff --exit-code`
25
+ * fails like `sync --check` — a CI gate does not pass against a stale cached copy. Plain `diff` still
26
+ * reads the cached copy with a warning (spec 13 §4.1).
27
+ */
28
+ const DIFF_EXIT_CODE_FETCH_MODE = "sync";
22
29
  const program = new Command();
23
- program.name("craftar").description("Craft, sync and convert AI-coding workspace harnesses.").version("0.9.0");
30
+ program.name("craftar").description("Craft, sync and convert AI-coding workspace harnesses.").version("0.11.0");
24
31
  /* ---------------------------------------------------------------- import */
25
32
  program
26
33
  .command("import")
@@ -33,6 +40,9 @@ program
33
40
  .action(async (o) => {
34
41
  if (o.from !== "claude-code")
35
42
  fail(`unsupported source "${o.from}" (only claude-code for now)`);
43
+ // import writes a local Forge; a URL would become a directory named after it (spec 13 §4.4).
44
+ if (classifyForge(o.forge) === "url")
45
+ fail("--forge takes a directory; to read a remote Forge, run inside a workspace that names it");
36
46
  const r = await importClaudeCode({ workspaceRoot: o.workspace, forgeRoot: o.forge, profileName: o.profile, writeWorkspaceConfig: o.writeConfig });
37
47
  console.log(pc.bold(`Imported ${path.resolve(o.workspace)} → ${path.resolve(o.forge)} as profile "${r.profile}"`));
38
48
  console.log(` ${pc.green(String(r.created.length))} created, ${pc.cyan(String(r.reused.length))} reused, ${pc.yellow(String(r.variants.length))} variants, ${pc.red(String(r.rejected.length))} rejected`);
@@ -64,7 +74,9 @@ program
64
74
  const split = new Map(r.recipeSplits.map((x) => [x.owned, x.reason]));
65
75
  console.log(` recipes: ${r.recipes.map((n) => (split.has(n) ? `${n} (${split.get(n)})` : n)).join(", ")}`);
66
76
  if (r.configWrite === "edited")
67
- console.log(` workspace craftar.yaml edited (forge, profile, targets)`);
77
+ console.log(r.configForgeKept
78
+ ? ` workspace craftar.yaml edited (profile, targets) — forge kept (remote ${r.configForgeKept}); push the Forge for sync to see this import`
79
+ : ` workspace craftar.yaml edited (forge, profile, targets)`);
68
80
  for (const w of r.warnings)
69
81
  console.log(` ${pc.yellow("warn")} ${w}`);
70
82
  });
@@ -74,13 +86,15 @@ program
74
86
  .description("Show what sync would do: new, update, drift, orphan, collision")
75
87
  .option("--workspace <dir>", "workspace root", ".")
76
88
  .option("--json", "machine-readable output", false)
89
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
77
90
  .action(async (o) => {
78
- const ws = await loadWorkspace(o.workspace);
91
+ const ws = await loadWorkspace(o.workspace, load(o, "read"));
79
92
  const p = await plan(ws);
80
- const st = await status(ws, p, await readLock(ws.root));
93
+ const lock = await readLock(ws.root);
94
+ const st = await status(ws, p, lock);
81
95
  if (o.json)
82
- return console.log(JSON.stringify({ statuses: st.map(({ planned, ...s }) => s), warnings: p.warnings }, null, 2));
83
- printStatus(st, p.warnings, ws.config.profile, p.resolution.recipes);
96
+ return console.log(JSON.stringify({ forge: forgeJson(ws, lock), statuses: st.map(({ planned, ...s }) => s), warnings: p.warnings }, null, 2));
97
+ printStatus(st, p.warnings, ws.config.profile, p.resolution.recipes, false, forgeLine(ws, lock));
84
98
  });
85
99
  /* ---------------------------------------------------------------- sync */
86
100
  program
@@ -90,13 +104,15 @@ program
90
104
  .option("--check", "exit 1 when the workspace is out of date or has drift (CI mode)", false)
91
105
  .option("--dry-run", "show the plan, write nothing", false)
92
106
  .option("--overwrite-drift", "regenerate files that were hand-edited (their edits are lost)", false)
107
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
93
108
  .action(async (o) => {
94
- const ws = await loadWorkspace(o.workspace);
109
+ const ws = await loadWorkspace(o.workspace, load(o, "sync"));
95
110
  const p = await plan(ws);
96
- const st = await status(ws, p, await readLock(ws.root));
111
+ const lock = await readLock(ws.root);
112
+ const st = await status(ws, p, lock);
97
113
  if (o.check) {
98
114
  const bad = st.filter((s) => !["unchanged", "adopt"].includes(s.state));
99
- printStatus(st, p.warnings, ws.config.profile, p.resolution.recipes, true);
115
+ printStatus(st, p.warnings, ws.config.profile, p.resolution.recipes, true, forgeLine(ws, lock));
100
116
  if (bad.length) {
101
117
  console.log(pc.red(`\n${bad.length} file(s) out of sync`));
102
118
  process.exit(1);
@@ -107,6 +123,9 @@ program
107
123
  const r = await apply(ws, p, st, { dryRun: o.dryRun, overwriteDrift: o.overwriteDrift });
108
124
  const verb = o.dryRun ? "would write" : "wrote";
109
125
  console.log(pc.bold(`craftar sync — profile ${ws.config.profile} · recipes ${p.resolution.recipes.join(" → ")} · targets ${p.resolution.targets.join(", ")}`));
126
+ const fl = forgeLine(ws, lock);
127
+ if (fl)
128
+ console.log(fl);
110
129
  console.log(` ${verb} ${pc.green(String(r.written.length))}, removed ${pc.magenta(String(r.removed.length))} orphan(s), skipped ${pc.yellow(String(r.skipped.length))}`);
111
130
  for (const f of r.written)
112
131
  console.log(` ${pc.green("+")} ${f}`);
@@ -120,28 +139,53 @@ program
120
139
  /* ---------------------------------------------------------------- diff */
121
140
  program
122
141
  .command("diff")
123
- .description("Unified diff between the files on disk and what the Forge would generate")
142
+ .description("Unified diff between the files on disk and what the Forge would generate, orphans included (files the Forge no longer produces)")
124
143
  .option("--workspace <dir>", "workspace root", ".")
144
+ .option("--exit-code", "exit 1 when there are differences (exactly when `sync --check` would fail); a [path] that names no file craftar manages becomes an error; with a remote Forge, a failed fetch exits 1 as `sync --check` does (--offline to use the cached copy)", false)
125
145
  .argument("[path]", "limit to one file")
146
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
126
147
  .action(async (only, o) => {
127
- const ws = await loadWorkspace(o.workspace);
148
+ const ws = await loadWorkspace(o.workspace, load(o, o.exitCode ? DIFF_EXIT_CODE_FETCH_MODE : "read"));
149
+ warnStderr(ws.warnings);
128
150
  const p = await plan(ws);
129
151
  const st = await status(ws, p, await readLock(ws.root));
152
+ // Spec 19 §3.3: under --exit-code a path nothing matches must not read as "clean" to a script
153
+ if (o.exitCode && only && !st.some((s) => s.path === only))
154
+ fail(`${only} is not a file craftar manages in this workspace — pass the workspace-relative path as \`craftar status\` prints it (forward slashes)`);
130
155
  let shown = 0;
156
+ const render = { paint: { same: pc.dim, del: pc.red, add: pc.green } };
131
157
  for (const s of st) {
132
158
  if (only && s.path !== only)
133
159
  continue;
134
- if (!["update", "drift", "collision", "new"].includes(s.state))
160
+ // Spec 19 §3.2: show the six states sync --check refuses (skip unchanged and adopt)
161
+ if (["unchanged", "adopt"].includes(s.state))
135
162
  continue;
136
163
  shown++;
164
+ if (s.state === "orphan-drift") {
165
+ // Header and one line, no body: sync keeps this file
166
+ console.log(pc.bold(`--- ${s.path} (disk, orphan-drift)`));
167
+ console.log(` ${explainSkip(s)}`);
168
+ continue;
169
+ }
137
170
  const disk = await readText(path.join(ws.root, s.path));
138
- const next = s.planned ? toLf(stripBom(s.planned.content.toString("utf8"))) : "";
139
- console.log(pc.bold(`--- ${s.path} (disk, ${s.state})`));
140
- console.log(pc.bold(`+++ ${s.path} (forge)`));
141
- console.log(renderDiff(disk ?? "", next, { paint: { same: pc.dim, del: pc.red, add: pc.green } }));
171
+ if (s.state === "orphan") {
172
+ // A removal: the file exists on disk but the Forge no longer produces it
173
+ console.log(pc.bold(`--- ${s.path} (disk, orphan)`));
174
+ console.log(pc.bold(`+++ ${s.path} (forge: no longer produced — sync removes it)`));
175
+ console.log(renderDiff(disk ?? "", "", render));
176
+ }
177
+ else {
178
+ const next = s.planned ? toLf(stripBom(s.planned.content.toString("utf8"))) : "";
179
+ console.log(pc.bold(`--- ${s.path} (disk, ${s.state})`));
180
+ console.log(pc.bold(`+++ ${s.path} (forge)`));
181
+ console.log(renderDiff(disk ?? "", next, render));
182
+ }
142
183
  }
143
184
  if (!shown)
144
185
  console.log(pc.green("no differences"));
186
+ // exitCode, not process.exit: exit drops a piped diff still queued for a slow reader (spec 19 §3.1)
187
+ else if (o.exitCode)
188
+ process.exitCode = 1;
145
189
  });
146
190
  /* ---------------------------------------------------------------- explain */
147
191
  program
@@ -149,8 +193,10 @@ program
149
193
  .description("Why does this file exist? Which ingredient, recipe chain and target produced it, and which layer filled each section")
150
194
  .argument("<path>", "workspace-relative path of a generated file")
151
195
  .option("--workspace <dir>", "workspace root", ".")
196
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
152
197
  .action(async (file, o) => {
153
- const ws = await loadWorkspace(o.workspace);
198
+ const ws = await loadWorkspace(o.workspace, load(o, "read"));
199
+ warnStderr(ws.warnings);
154
200
  const p = await plan(ws);
155
201
  const f = p.files.find((x) => x.path === file.replace(/\\/g, "/"));
156
202
  if (!f)
@@ -175,10 +221,15 @@ program
175
221
  .command("ls")
176
222
  .description("List recipes and ingredients resolved for this workspace")
177
223
  .option("--workspace <dir>", "workspace root", ".")
224
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
178
225
  .action(async (o) => {
179
- const ws = await loadWorkspace(o.workspace);
226
+ const ws = await loadWorkspace(o.workspace, load(o, "read"));
227
+ warnStderr(ws.warnings);
180
228
  const p = await plan(ws);
181
229
  console.log(pc.bold(`Forge ${ws.forge.manifest.name} @ ${ws.forge.commit?.slice(0, 8) ?? "no git"} · profile ${ws.config.profile}`));
230
+ const fl = forgeLine(ws, await readLock(ws.root));
231
+ if (fl)
232
+ console.log(fl);
182
233
  for (const r of p.resolution.recipes) {
183
234
  const rec = ws.forge.recipes.get(r);
184
235
  console.log(`\n${pc.cyan(r)}${rec.slot ? pc.dim(` [slot ${rec.slot}]`) : ""}${rec.description ? pc.dim(" — " + rec.description) : ""}`);
@@ -197,10 +248,11 @@ program
197
248
  .option("--profile <name>", "with --forge: mark what this profile resolves")
198
249
  .option("--workspace <dir>", "workspace whose craftar.yaml names the Forge (default: .)")
199
250
  .option("--json", "machine-readable output", false)
251
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
200
252
  .action(async (o) => {
201
253
  if (o.profile && !o.forge)
202
254
  fail("--profile goes with --forge — inside a workspace the profile comes from craftar.yaml");
203
- const { forge: forg, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace });
255
+ const { forge: forg, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace, ...load(o, "read") });
204
256
  const source = workspace
205
257
  ? { kind: "workspace", config: workspace.config }
206
258
  : o.profile
@@ -216,6 +268,9 @@ program
216
268
  }
217
269
  }
218
270
  const r = listRecipes(forg, context);
271
+ // Loading the workspace may warn (spec 13 §4.2); those come first, as in `plan()`.
272
+ if (workspace)
273
+ r.warnings.unshift(...workspace.warnings);
219
274
  if (o.json) {
220
275
  return console.log(JSON.stringify(r, null, 2));
221
276
  }
@@ -305,6 +360,7 @@ program
305
360
  .option("--profile <name>", "with --forge: mark what this profile resolves")
306
361
  .option("--workspace <dir>", "workspace whose craftar.yaml names the Forge (default: .)")
307
362
  .option("--json", "machine-readable output", false)
363
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
308
364
  .action(async (o) => {
309
365
  if (o.profile && !o.forge)
310
366
  fail("--profile goes with --forge — inside a workspace the profile comes from craftar.yaml");
@@ -316,7 +372,7 @@ program
316
372
  fail(e instanceof Error ? e.message : String(e));
317
373
  }
318
374
  }
319
- const { forge: forg, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace });
375
+ const { forge: forg, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace, ...load(o, "read") });
320
376
  const source = workspace
321
377
  ? { kind: "workspace", config: workspace.config }
322
378
  : o.profile
@@ -338,6 +394,8 @@ program
338
394
  catch (e) {
339
395
  fail(e instanceof Error ? e.message : String(e));
340
396
  }
397
+ if (workspace)
398
+ result.warnings.unshift(...workspace.warnings);
341
399
  if (o.json) {
342
400
  return console.log(JSON.stringify(result, null, 2));
343
401
  }
@@ -505,7 +563,7 @@ program
505
563
  if (o.workspace !== undefined) {
506
564
  // Explicit --workspace: exit 1 with loadWorkspace's message
507
565
  try {
508
- await loadWorkspace(root);
566
+ await loadWorkspace(root, load({}, "no-fetch"));
509
567
  }
510
568
  catch (e) {
511
569
  fail(e instanceof Error ? e.message : String(e));
@@ -516,7 +574,7 @@ program
516
574
  else {
517
575
  // craftar.yaml exists, try to load
518
576
  try {
519
- const ws = await loadWorkspace(root);
577
+ const ws = await loadWorkspace(root, load({}, "no-fetch"));
520
578
  inUse = resolve(ws.forge, ws.config).targets;
521
579
  }
522
580
  catch (e) {
@@ -580,8 +638,9 @@ forge
580
638
  .option("--forge <dir>", "Forge directory (instead of --workspace)")
581
639
  .option("--workspace <dir>", "workspace whose craftar.yaml names the Forge (default: .)")
582
640
  .option("--json", "machine-readable output", false)
641
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
583
642
  .action(async (o) => {
584
- const f = await resolveForge({ forge: o.forge, workspace: o.workspace });
643
+ const f = await forgeFor(o);
585
644
  const report = await listVariants(f);
586
645
  if (o.json)
587
646
  return console.log(JSON.stringify(report, null, 2));
@@ -609,8 +668,9 @@ forge
609
668
  .option("--forge <dir>", "Forge directory (instead of --workspace)")
610
669
  .option("--workspace <dir>", "workspace whose craftar.yaml names the Forge (default: .)")
611
670
  .option("--json", "machine-readable output", false)
671
+ .option("--offline", "use the cached copy of a remote Forge, without fetching", false)
612
672
  .action(async (ref, o) => {
613
- const f = await resolveForge({ forge: o.forge, workspace: o.workspace });
673
+ const f = await forgeFor(o);
614
674
  const base = f.ingredients.get(ref);
615
675
  if (!base)
616
676
  fail(`${ref} is not an ingredient of this Forge`);
@@ -670,7 +730,13 @@ forge
670
730
  fail("pass exactly one of --take, --plan or --save-plan");
671
731
  if (o.take !== undefined && o.take !== "base" && o.take !== "variant")
672
732
  fail(`--take must be "base" or "variant"`);
673
- const f = await resolveForge({ forge: o.forge, workspace: o.workspace });
733
+ // Never through the cache: a tree there is clean and tracked, so gitUnheld would pass and the edit
734
+ // would be lost at the next cleanup without reaching the remote (spec 13 §4.4).
735
+ const f = await resolveForge({
736
+ forge: o.forge,
737
+ workspace: o.workspace,
738
+ refuseRemote: (url) => `the Forge of this workspace is remote (${url}) — clone it and pass --forge <dir>`,
739
+ });
674
740
  const base = f.ingredients.get(ref);
675
741
  if (!base)
676
742
  fail(`${ref} is not an ingredient of this Forge`);
@@ -921,15 +987,55 @@ forge
921
987
  });
922
988
  program.parseAsync().catch((e) => fail(e instanceof Error ? e.message : String(e)));
923
989
  /* ---------------------------------------------------------------- helpers */
990
+ /** The network rule of a command, `--offline`, and `$CRAFTAR_HOME` (spec 13 §4.1, §6.3). */
991
+ function load(o, mode) {
992
+ return { mode, offline: o.offline === true, home: process.env.CRAFTAR_HOME || undefined };
993
+ }
994
+ /** A `forge` command's Forge; the warnings of reading a remote one go to stderr, so `--json` stays its shape. */
995
+ async function forgeFor(o) {
996
+ const { forge, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace, ...load(o, "read") });
997
+ warnStderr(workspace?.warnings ?? []);
998
+ return forge;
999
+ }
1000
+ /** Warnings of loading the workspace, for commands whose stdout is not a report (a diff, `explain`, `ls`, `--json`). */
1001
+ function warnStderr(warnings) {
1002
+ for (const w of warnings)
1003
+ console.error(`${pc.yellow("warn")} ${w}`);
1004
+ }
1005
+ /** The header line naming a remote Forge (spec 13 §4.1); null for a path Forge, whose headers keep their shape. */
1006
+ function forgeLine(ws, lock) {
1007
+ const o = ws.origin;
1008
+ if (o.kind !== "remote")
1009
+ return null;
1010
+ const commit = ws.forge.commit;
1011
+ const at = o.ref ?? `${o.defaultBranch} (default branch)`;
1012
+ const moved = lock?.forge.commit && commit && lock.forge.commit !== commit ? ` · lock ${lock.forge.commit.slice(0, 8)}` : "";
1013
+ return ` forge ${o.source} @ ${at} ${commit?.slice(0, 8) ?? "no git"}${moved}`;
1014
+ }
1015
+ /** `status --json`'s `forge` key, for every Forge (spec 13 §4.1). */
1016
+ function forgeJson(ws, lock) {
1017
+ const o = ws.origin;
1018
+ return {
1019
+ kind: o.kind,
1020
+ source: o.source,
1021
+ ref: o.ref,
1022
+ defaultBranch: o.defaultBranch,
1023
+ commit: ws.forge.commit,
1024
+ lockCommit: lock?.forge.commit ?? null,
1025
+ fetched: o.fetched,
1026
+ };
1027
+ }
924
1028
  function fail(msg) {
925
1029
  console.error(pc.red("error: ") + msg);
926
1030
  process.exit(1);
927
1031
  }
928
- function printStatus(st, warnings, profile, recipes, compact = false) {
1032
+ function printStatus(st, warnings, profile, recipes, compact = false, forge = null) {
929
1033
  const counts = {};
930
1034
  for (const s of st)
931
1035
  counts[s.state] = (counts[s.state] ?? 0) + 1;
932
1036
  console.log(pc.bold(`craftar status — profile ${profile} · recipes ${recipes.join(" → ")}`));
1037
+ if (forge)
1038
+ console.log(forge);
933
1039
  console.log(" " +
934
1040
  Object.entries(counts)
935
1041
  .map(([k, v]) => `${color(k)(k)} ${v}`)