craftar 0.10.1 → 0.12.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 +44 -9
- package/dist/cli.js +199 -22
- package/dist/cli.js.map +1 -1
- package/dist/core/home-lock.js +46 -0
- package/dist/core/home-lock.js.map +1 -0
- package/dist/core/registry.js +274 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/remote.js +373 -0
- package/dist/core/remote.js.map +1 -0
- package/dist/core/sync.js +102 -16
- package/dist/core/sync.js.map +1 -1
- package/dist/core/workspace-yaml.js +18 -0
- package/dist/core/workspace-yaml.js.map +1 -0
- package/dist/importers/claude-code.js +19 -6
- package/dist/importers/claude-code.js.map +1 -1
- package/dist/importers/decide.js +3 -3
- package/dist/importers/decide.js.map +1 -1
- package/dist/schema/index.js +69 -2
- package/dist/schema/index.js.map +1 -1
- package/package.json +1 -1
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*). A writing `sync` records each workspace in a per-machine registry, and `craftar workspaces` lists them all with their status (see *Workspace registry*). 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,12 +52,14 @@ 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
|
|
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
|
|
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`. |
|
|
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). A writing `sync` (not `--dry-run`, not `--check`) also records the workspace in `$CRAFTAR_HOME/registry.json` (see *Workspace registry*); a registry it cannot write is a warning, never a failed `sync`. |
|
|
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
|
+
| `craftar workspaces [--fetch] [--json]` | Every workspace a writing `sync` registered on this machine, sorted by path: name, path, profile, stack (`slot=recipe`), targets, the Forge, the last sync, and a status computed now — `up to date`, `outdated` (`new`, `update` or `orphan` pending), `drift` (a `drift`, `orphan-drift` or `collision`), `no lock`, `missing` (directory or `craftar.yaml` gone) or `error` (it no longer loads, plans or reads its lock), plus `forge moved` when the Forge's commit differs from the lock's. Read without the network: a remote Forge comes from the cache; `--fetch` fetches first. Each row's warnings print after the table, prefixed with its path. Times are UTC. Writes nothing. Exits 0 whenever the table prints. Takes no `--workspace`. `--json` is a contract: `{registry, fetch, workspaces, warnings}`. |
|
|
62
|
+
| `craftar workspaces forget <dir>` / `craftar workspaces prune` | `forget` removes one entry (the directory is not touched; an unregistered path exits 1); `prune` removes every `missing` entry and never an `error` one. Nothing else removes an entry. |
|
|
61
63
|
| `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}`. |
|
|
62
64
|
| `craftar ingredients [--recipe <name>] [--type <type>] [--forge <dir> [--profile <name>] \| --workspace <dir>] [--json]` | Every ingredient of the Forge, grouped by type: output name, targets, the recipes that list it, and whether the context uses it or the workspace disables it; a reference a recipe makes to an ingredient the Forge does not hold is listed under `missing`, never dropped. `--recipe <name>` lists what choosing that recipe brings, with the parents it extends, parents first; two of them on one slot is a warning. `--type` keeps one type. Read-only. `--json` is a contract: `{forge, context, recipe, ingredients, missing, warnings}`. |
|
|
63
65
|
| `craftar targets [--workspace <dir>] [--json]` | The capability matrix (see *Targets*): what each target does with each ingredient type, the paths it writes and what changes. Needs no Forge; inside a workspace it marks the targets in use, and when that workspace does not load or resolve it prints the matrix unmarked with a warning. An explicit `--workspace <dir>` without a `craftar.yaml` exits 1; the current directory without one just prints the matrix unmarked. `--json` is a contract: `{ingredientTypes, targets, warnings}`. |
|
|
@@ -65,7 +67,7 @@ From then on, change a rule in `forge/ingredients/rules/<name>/rule.md`, run `cr
|
|
|
65
67
|
| `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
68
|
| `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
69
|
|
|
68
|
-
All commands take `--workspace <dir>` (default: current directory); the `forge` commands, `recipes` and `ingredients` also take `--forge <dir>` as an alternative to it
|
|
70
|
+
All commands but `workspaces` 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
71
|
|
|
70
72
|
## Forge layout
|
|
71
73
|
|
|
@@ -171,7 +173,8 @@ params: { angularVersion: { default: "20" } }
|
|
|
171
173
|
Workspace `craftar.yaml`:
|
|
172
174
|
|
|
173
175
|
```yaml
|
|
174
|
-
forge: ../forge # path
|
|
176
|
+
forge: ../forge # a path, or a git URL (see Remote Forge)
|
|
177
|
+
ref: v1.4.0 # optional, with a git URL: a branch, a tag or a full SHA
|
|
175
178
|
profile: acme-portal
|
|
176
179
|
targets: [claude-code, kiro] # optional, overrides the profile
|
|
177
180
|
recipes: { add: [], remove: [] }
|
|
@@ -250,13 +253,45 @@ npm test
|
|
|
250
253
|
|
|
251
254
|
Copy a workspace with `.claude/` and `.kiro/` into `fixtures/` (keep `local-stack/` and `projects/` out).
|
|
252
255
|
|
|
256
|
+
## Remote Forge
|
|
257
|
+
|
|
258
|
+
`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.
|
|
259
|
+
|
|
260
|
+
- **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. The cache and the workspace registry (below) are the two places, both under `$CRAFTAR_HOME`, where Craftar writes outside a workspace and a Forge on its own.
|
|
261
|
+
- **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.
|
|
262
|
+
- **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.
|
|
263
|
+
- **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.
|
|
264
|
+
- **`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.
|
|
265
|
+
|
|
266
|
+
## Workspace registry
|
|
267
|
+
|
|
268
|
+
A writing `sync` records the workspace in `$CRAFTAR_HOME/registry.json` (`~/.craftar` by default): its real path, profile, the Forge it used and where that Forge lives, the resolved recipes and targets, and when `sync` last ran there. It is an index, not the memory — `craftar.lock` stays that, and nothing in a workspace changes because of it. `craftar workspaces` prints it as a table with every status computed on the spot — `up to date`, `outdated`, `drift`, `no lock`, `missing` or `error` — read without the network (a remote Forge from the cache; `--fetch` fetches first); `forget` and `prune` remove entries, and a workspace that is gone stays listed as `missing` until you prune it.
|
|
269
|
+
|
|
270
|
+
- **`CRAFTAR_NO_REGISTRY`** — read the name as "no registry", the way `NO_COLOR` means "no colour". Set to any non-empty value, it turns the registry off: `sync` neither reads nor writes it, and `craftar workspaces` exits 1. An empty value counts as unset. Set it on CI runners and throwaway checkouts, whose directories would only pile up as `missing`.
|
|
271
|
+
- **A registry that cannot be written** (an unwritable `$CRAFTAR_HOME`, a busy lock after 60 s, a file this craftar cannot read) leaves `sync`'s files, lock and exit code as they would be, and adds one warning. Craftar never overwrites a registry it cannot read: repair or remove it yourself.
|
|
272
|
+
- The registry is per machine: paths are native and absolute, and SSH and HTTPS spellings of one remote are two Forges in it, as they are two cache entries.
|
|
273
|
+
|
|
253
274
|
## Roadmap (from the functional spec)
|
|
254
275
|
|
|
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;
|
|
276
|
+
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); the workspace registry and `craftar workspaces`.
|
|
277
|
+
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
278
|
|
|
258
279
|
## Upgrading
|
|
259
280
|
|
|
281
|
+
### to 0.12.0
|
|
282
|
+
|
|
283
|
+
- **A writing `sync` now writes outside the workspace**: `$CRAFTAR_HOME/registry.json` (`~/.craftar` by default) gains or updates the workspace's entry. On CI runners and throwaway checkouts set `CRAFTAR_NO_REGISTRY=1`. A registry that cannot be written is a warning; the exit code of `sync` does not change.
|
|
284
|
+
- **New command `craftar workspaces`** (with `forget` and `prune`). Its `--json` output is a tooling contract, like `status --json`.
|
|
285
|
+
- **No byte change**: no emitter, `plan`, `status` or lock changed. No workspace sees `update`.
|
|
286
|
+
|
|
287
|
+
### to 0.11.0
|
|
288
|
+
|
|
289
|
+
- **`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.
|
|
290
|
+
- **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.
|
|
291
|
+
- **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.
|
|
292
|
+
- 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.
|
|
293
|
+
- `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>`.
|
|
294
|
+
|
|
260
295
|
### to 0.10.0
|
|
261
296
|
|
|
262
297
|
- **`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.
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,9 @@ 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";
|
|
8
|
+
import { forget, listWorkspaces, prune, register, registryFile } from "./core/registry.js";
|
|
9
|
+
import { resolveHome } from "./core/home-lock.js";
|
|
7
10
|
import { loadWorkspace, plan, readLock, status, apply, resolveForge, resolveForgeSource, WORKSPACE_FILE } from "./core/sync.js";
|
|
8
11
|
import { resolve, sectionKey } from "./core/resolve.js";
|
|
9
12
|
import { catalogueContext, listRecipes, listIngredients, checkType } from "./core/catalogue.js";
|
|
@@ -19,8 +22,14 @@ import { checkParamWrites, writeParamFile } from "./core/param-writes.js";
|
|
|
19
22
|
import { HUNK_CLASSES, INGREDIENT_TYPES, UnifyPlanSchema } from "./schema/index.js";
|
|
20
23
|
process.stdout.on("error", (e) => { if (e.code === "EPIPE")
|
|
21
24
|
process.exit(0); });
|
|
25
|
+
/**
|
|
26
|
+
* Q13-1, answered by the user (2026-10-07): with a remote Forge whose fetch fails, `diff --exit-code`
|
|
27
|
+
* fails like `sync --check` — a CI gate does not pass against a stale cached copy. Plain `diff` still
|
|
28
|
+
* reads the cached copy with a warning (spec 13 §4.1).
|
|
29
|
+
*/
|
|
30
|
+
const DIFF_EXIT_CODE_FETCH_MODE = "sync";
|
|
22
31
|
const program = new Command();
|
|
23
|
-
program.name("craftar").description("Craft, sync and convert AI-coding workspace harnesses.").version("0.
|
|
32
|
+
program.name("craftar").description("Craft, sync and convert AI-coding workspace harnesses.").version("0.12.0");
|
|
24
33
|
/* ---------------------------------------------------------------- import */
|
|
25
34
|
program
|
|
26
35
|
.command("import")
|
|
@@ -33,6 +42,9 @@ program
|
|
|
33
42
|
.action(async (o) => {
|
|
34
43
|
if (o.from !== "claude-code")
|
|
35
44
|
fail(`unsupported source "${o.from}" (only claude-code for now)`);
|
|
45
|
+
// import writes a local Forge; a URL would become a directory named after it (spec 13 §4.4).
|
|
46
|
+
if (classifyForge(o.forge) === "url")
|
|
47
|
+
fail("--forge takes a directory; to read a remote Forge, run inside a workspace that names it");
|
|
36
48
|
const r = await importClaudeCode({ workspaceRoot: o.workspace, forgeRoot: o.forge, profileName: o.profile, writeWorkspaceConfig: o.writeConfig });
|
|
37
49
|
console.log(pc.bold(`Imported ${path.resolve(o.workspace)} → ${path.resolve(o.forge)} as profile "${r.profile}"`));
|
|
38
50
|
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 +76,9 @@ program
|
|
|
64
76
|
const split = new Map(r.recipeSplits.map((x) => [x.owned, x.reason]));
|
|
65
77
|
console.log(` recipes: ${r.recipes.map((n) => (split.has(n) ? `${n} (${split.get(n)})` : n)).join(", ")}`);
|
|
66
78
|
if (r.configWrite === "edited")
|
|
67
|
-
console.log(
|
|
79
|
+
console.log(r.configForgeKept
|
|
80
|
+
? ` workspace craftar.yaml edited (profile, targets) — forge kept (remote ${r.configForgeKept}); push the Forge for sync to see this import`
|
|
81
|
+
: ` workspace craftar.yaml edited (forge, profile, targets)`);
|
|
68
82
|
for (const w of r.warnings)
|
|
69
83
|
console.log(` ${pc.yellow("warn")} ${w}`);
|
|
70
84
|
});
|
|
@@ -74,29 +88,33 @@ program
|
|
|
74
88
|
.description("Show what sync would do: new, update, drift, orphan, collision")
|
|
75
89
|
.option("--workspace <dir>", "workspace root", ".")
|
|
76
90
|
.option("--json", "machine-readable output", false)
|
|
91
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
77
92
|
.action(async (o) => {
|
|
78
|
-
const ws = await loadWorkspace(o.workspace);
|
|
93
|
+
const ws = await loadWorkspace(o.workspace, load(o, "read"));
|
|
79
94
|
const p = await plan(ws);
|
|
80
|
-
const
|
|
95
|
+
const lock = await readLock(ws.root);
|
|
96
|
+
const st = await status(ws, p, lock);
|
|
81
97
|
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);
|
|
98
|
+
return console.log(JSON.stringify({ forge: forgeJson(ws, lock), statuses: st.map(({ planned, ...s }) => s), warnings: p.warnings }, null, 2));
|
|
99
|
+
printStatus(st, p.warnings, ws.config.profile, p.resolution.recipes, false, forgeLine(ws, lock));
|
|
84
100
|
});
|
|
85
101
|
/* ---------------------------------------------------------------- sync */
|
|
86
102
|
program
|
|
87
103
|
.command("sync")
|
|
88
|
-
.description("Generate the harness for every target from the Forge and update craftar.lock")
|
|
104
|
+
.description("Generate the harness for every target from the Forge and update craftar.lock; a writing sync also records the workspace in $CRAFTAR_HOME/registry.json (see craftar workspaces)")
|
|
89
105
|
.option("--workspace <dir>", "workspace root", ".")
|
|
90
106
|
.option("--check", "exit 1 when the workspace is out of date or has drift (CI mode)", false)
|
|
91
107
|
.option("--dry-run", "show the plan, write nothing", false)
|
|
92
108
|
.option("--overwrite-drift", "regenerate files that were hand-edited (their edits are lost)", false)
|
|
109
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
93
110
|
.action(async (o) => {
|
|
94
|
-
const ws = await loadWorkspace(o.workspace);
|
|
111
|
+
const ws = await loadWorkspace(o.workspace, load(o, "sync"));
|
|
95
112
|
const p = await plan(ws);
|
|
96
|
-
const
|
|
113
|
+
const lock = await readLock(ws.root);
|
|
114
|
+
const st = await status(ws, p, lock);
|
|
97
115
|
if (o.check) {
|
|
98
116
|
const bad = st.filter((s) => !["unchanged", "adopt"].includes(s.state));
|
|
99
|
-
printStatus(st, p.warnings, ws.config.profile, p.resolution.recipes, true);
|
|
117
|
+
printStatus(st, p.warnings, ws.config.profile, p.resolution.recipes, true, forgeLine(ws, lock));
|
|
100
118
|
if (bad.length) {
|
|
101
119
|
console.log(pc.red(`\n${bad.length} file(s) out of sync`));
|
|
102
120
|
process.exit(1);
|
|
@@ -105,8 +123,22 @@ program
|
|
|
105
123
|
return;
|
|
106
124
|
}
|
|
107
125
|
const r = await apply(ws, p, st, { dryRun: o.dryRun, overwriteDrift: o.overwriteDrift });
|
|
126
|
+
// A writing sync records the workspace (spec 21 §4.1); the registry is an index, so a failure is a warning.
|
|
127
|
+
let registryWarning = null;
|
|
128
|
+
if (!o.dryRun && !registryOff()) {
|
|
129
|
+
const home = craftarHome();
|
|
130
|
+
try {
|
|
131
|
+
await register(home, ws, p);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
registryWarning = `registry not updated (${registryFile(home)}): ${e instanceof Error ? e.message : String(e)}`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
108
137
|
const verb = o.dryRun ? "would write" : "wrote";
|
|
109
138
|
console.log(pc.bold(`craftar sync — profile ${ws.config.profile} · recipes ${p.resolution.recipes.join(" → ")} · targets ${p.resolution.targets.join(", ")}`));
|
|
139
|
+
const fl = forgeLine(ws, lock);
|
|
140
|
+
if (fl)
|
|
141
|
+
console.log(fl);
|
|
110
142
|
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
143
|
for (const f of r.written)
|
|
112
144
|
console.log(` ${pc.green("+")} ${f}`);
|
|
@@ -116,16 +148,20 @@ program
|
|
|
116
148
|
console.log(` ${pc.yellow("!")} ${s.path} ${explainSkip(s)}`);
|
|
117
149
|
for (const w of p.warnings)
|
|
118
150
|
console.log(` ${pc.yellow("warn")} ${w}`);
|
|
151
|
+
if (registryWarning)
|
|
152
|
+
console.log(` ${pc.yellow("warn")} ${registryWarning}`);
|
|
119
153
|
});
|
|
120
154
|
/* ---------------------------------------------------------------- diff */
|
|
121
155
|
program
|
|
122
156
|
.command("diff")
|
|
123
157
|
.description("Unified diff between the files on disk and what the Forge would generate, orphans included (files the Forge no longer produces)")
|
|
124
158
|
.option("--workspace <dir>", "workspace root", ".")
|
|
125
|
-
.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", false)
|
|
159
|
+
.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)
|
|
126
160
|
.argument("[path]", "limit to one file")
|
|
161
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
127
162
|
.action(async (only, o) => {
|
|
128
|
-
const ws = await loadWorkspace(o.workspace);
|
|
163
|
+
const ws = await loadWorkspace(o.workspace, load(o, o.exitCode ? DIFF_EXIT_CODE_FETCH_MODE : "read"));
|
|
164
|
+
warnStderr(ws.warnings);
|
|
129
165
|
const p = await plan(ws);
|
|
130
166
|
const st = await status(ws, p, await readLock(ws.root));
|
|
131
167
|
// Spec 19 §3.3: under --exit-code a path nothing matches must not read as "clean" to a script
|
|
@@ -172,8 +208,10 @@ program
|
|
|
172
208
|
.description("Why does this file exist? Which ingredient, recipe chain and target produced it, and which layer filled each section")
|
|
173
209
|
.argument("<path>", "workspace-relative path of a generated file")
|
|
174
210
|
.option("--workspace <dir>", "workspace root", ".")
|
|
211
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
175
212
|
.action(async (file, o) => {
|
|
176
|
-
const ws = await loadWorkspace(o.workspace);
|
|
213
|
+
const ws = await loadWorkspace(o.workspace, load(o, "read"));
|
|
214
|
+
warnStderr(ws.warnings);
|
|
177
215
|
const p = await plan(ws);
|
|
178
216
|
const f = p.files.find((x) => x.path === file.replace(/\\/g, "/"));
|
|
179
217
|
if (!f)
|
|
@@ -198,10 +236,15 @@ program
|
|
|
198
236
|
.command("ls")
|
|
199
237
|
.description("List recipes and ingredients resolved for this workspace")
|
|
200
238
|
.option("--workspace <dir>", "workspace root", ".")
|
|
239
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
201
240
|
.action(async (o) => {
|
|
202
|
-
const ws = await loadWorkspace(o.workspace);
|
|
241
|
+
const ws = await loadWorkspace(o.workspace, load(o, "read"));
|
|
242
|
+
warnStderr(ws.warnings);
|
|
203
243
|
const p = await plan(ws);
|
|
204
244
|
console.log(pc.bold(`Forge ${ws.forge.manifest.name} @ ${ws.forge.commit?.slice(0, 8) ?? "no git"} · profile ${ws.config.profile}`));
|
|
245
|
+
const fl = forgeLine(ws, await readLock(ws.root));
|
|
246
|
+
if (fl)
|
|
247
|
+
console.log(fl);
|
|
205
248
|
for (const r of p.resolution.recipes) {
|
|
206
249
|
const rec = ws.forge.recipes.get(r);
|
|
207
250
|
console.log(`\n${pc.cyan(r)}${rec.slot ? pc.dim(` [slot ${rec.slot}]`) : ""}${rec.description ? pc.dim(" — " + rec.description) : ""}`);
|
|
@@ -212,6 +255,38 @@ program
|
|
|
212
255
|
}
|
|
213
256
|
console.log(`\n${p.files.length} files across targets ${p.resolution.targets.join(", ")}`);
|
|
214
257
|
});
|
|
258
|
+
/* ---------------------------------------------------------------- workspaces */
|
|
259
|
+
const workspaces = program
|
|
260
|
+
.command("workspaces")
|
|
261
|
+
.description("List every workspace a writing sync registered on this machine ($CRAFTAR_HOME/registry.json), with its status computed now: up to date, outdated, drift, no lock, missing or error — read without the network")
|
|
262
|
+
.option("--fetch", "fetch each remote Forge first instead of reading the cached copy", false)
|
|
263
|
+
.option("--json", "machine-readable output", false)
|
|
264
|
+
.action(async (o) => {
|
|
265
|
+
registryGate();
|
|
266
|
+
const t = await listWorkspaces(craftarHome(), { fetch: o.fetch });
|
|
267
|
+
if (o.json)
|
|
268
|
+
return console.log(JSON.stringify({ registry: t.registry, fetch: o.fetch, workspaces: t.rows, warnings: t.warnings }, null, 2));
|
|
269
|
+
printWorkspaces(t.rows, t.warnings, o.fetch);
|
|
270
|
+
});
|
|
271
|
+
workspaces
|
|
272
|
+
.command("forget")
|
|
273
|
+
.description("Remove a workspace from the registry; the directory itself is not touched")
|
|
274
|
+
.argument("<dir>", "the workspace's directory, as registered")
|
|
275
|
+
.action(async (dir) => {
|
|
276
|
+
registryGate();
|
|
277
|
+
console.log(`forgot ${await forget(craftarHome(), dir)}`);
|
|
278
|
+
});
|
|
279
|
+
workspaces
|
|
280
|
+
.command("prune")
|
|
281
|
+
.description("Remove every registered workspace whose directory or craftar.yaml is gone")
|
|
282
|
+
.action(async () => {
|
|
283
|
+
registryGate();
|
|
284
|
+
const gone = await prune(craftarHome());
|
|
285
|
+
if (gone.length === 0)
|
|
286
|
+
console.log("nothing to prune");
|
|
287
|
+
for (const p of gone)
|
|
288
|
+
console.log(`pruned ${p}`);
|
|
289
|
+
});
|
|
215
290
|
/* ---------------------------------------------------------------- recipes */
|
|
216
291
|
program
|
|
217
292
|
.command("recipes")
|
|
@@ -220,10 +295,11 @@ program
|
|
|
220
295
|
.option("--profile <name>", "with --forge: mark what this profile resolves")
|
|
221
296
|
.option("--workspace <dir>", "workspace whose craftar.yaml names the Forge (default: .)")
|
|
222
297
|
.option("--json", "machine-readable output", false)
|
|
298
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
223
299
|
.action(async (o) => {
|
|
224
300
|
if (o.profile && !o.forge)
|
|
225
301
|
fail("--profile goes with --forge — inside a workspace the profile comes from craftar.yaml");
|
|
226
|
-
const { forge: forg, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace });
|
|
302
|
+
const { forge: forg, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace, ...load(o, "read") });
|
|
227
303
|
const source = workspace
|
|
228
304
|
? { kind: "workspace", config: workspace.config }
|
|
229
305
|
: o.profile
|
|
@@ -239,6 +315,9 @@ program
|
|
|
239
315
|
}
|
|
240
316
|
}
|
|
241
317
|
const r = listRecipes(forg, context);
|
|
318
|
+
// Loading the workspace may warn (spec 13 §4.2); those come first, as in `plan()`.
|
|
319
|
+
if (workspace)
|
|
320
|
+
r.warnings.unshift(...workspace.warnings);
|
|
242
321
|
if (o.json) {
|
|
243
322
|
return console.log(JSON.stringify(r, null, 2));
|
|
244
323
|
}
|
|
@@ -328,6 +407,7 @@ program
|
|
|
328
407
|
.option("--profile <name>", "with --forge: mark what this profile resolves")
|
|
329
408
|
.option("--workspace <dir>", "workspace whose craftar.yaml names the Forge (default: .)")
|
|
330
409
|
.option("--json", "machine-readable output", false)
|
|
410
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
331
411
|
.action(async (o) => {
|
|
332
412
|
if (o.profile && !o.forge)
|
|
333
413
|
fail("--profile goes with --forge — inside a workspace the profile comes from craftar.yaml");
|
|
@@ -339,7 +419,7 @@ program
|
|
|
339
419
|
fail(e instanceof Error ? e.message : String(e));
|
|
340
420
|
}
|
|
341
421
|
}
|
|
342
|
-
const { forge: forg, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace });
|
|
422
|
+
const { forge: forg, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace, ...load(o, "read") });
|
|
343
423
|
const source = workspace
|
|
344
424
|
? { kind: "workspace", config: workspace.config }
|
|
345
425
|
: o.profile
|
|
@@ -361,6 +441,8 @@ program
|
|
|
361
441
|
catch (e) {
|
|
362
442
|
fail(e instanceof Error ? e.message : String(e));
|
|
363
443
|
}
|
|
444
|
+
if (workspace)
|
|
445
|
+
result.warnings.unshift(...workspace.warnings);
|
|
364
446
|
if (o.json) {
|
|
365
447
|
return console.log(JSON.stringify(result, null, 2));
|
|
366
448
|
}
|
|
@@ -528,7 +610,7 @@ program
|
|
|
528
610
|
if (o.workspace !== undefined) {
|
|
529
611
|
// Explicit --workspace: exit 1 with loadWorkspace's message
|
|
530
612
|
try {
|
|
531
|
-
await loadWorkspace(root);
|
|
613
|
+
await loadWorkspace(root, load({}, "no-fetch"));
|
|
532
614
|
}
|
|
533
615
|
catch (e) {
|
|
534
616
|
fail(e instanceof Error ? e.message : String(e));
|
|
@@ -539,7 +621,7 @@ program
|
|
|
539
621
|
else {
|
|
540
622
|
// craftar.yaml exists, try to load
|
|
541
623
|
try {
|
|
542
|
-
const ws = await loadWorkspace(root);
|
|
624
|
+
const ws = await loadWorkspace(root, load({}, "no-fetch"));
|
|
543
625
|
inUse = resolve(ws.forge, ws.config).targets;
|
|
544
626
|
}
|
|
545
627
|
catch (e) {
|
|
@@ -603,8 +685,9 @@ forge
|
|
|
603
685
|
.option("--forge <dir>", "Forge directory (instead of --workspace)")
|
|
604
686
|
.option("--workspace <dir>", "workspace whose craftar.yaml names the Forge (default: .)")
|
|
605
687
|
.option("--json", "machine-readable output", false)
|
|
688
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
606
689
|
.action(async (o) => {
|
|
607
|
-
const f = await
|
|
690
|
+
const f = await forgeFor(o);
|
|
608
691
|
const report = await listVariants(f);
|
|
609
692
|
if (o.json)
|
|
610
693
|
return console.log(JSON.stringify(report, null, 2));
|
|
@@ -632,8 +715,9 @@ forge
|
|
|
632
715
|
.option("--forge <dir>", "Forge directory (instead of --workspace)")
|
|
633
716
|
.option("--workspace <dir>", "workspace whose craftar.yaml names the Forge (default: .)")
|
|
634
717
|
.option("--json", "machine-readable output", false)
|
|
718
|
+
.option("--offline", "use the cached copy of a remote Forge, without fetching", false)
|
|
635
719
|
.action(async (ref, o) => {
|
|
636
|
-
const f = await
|
|
720
|
+
const f = await forgeFor(o);
|
|
637
721
|
const base = f.ingredients.get(ref);
|
|
638
722
|
if (!base)
|
|
639
723
|
fail(`${ref} is not an ingredient of this Forge`);
|
|
@@ -693,7 +777,13 @@ forge
|
|
|
693
777
|
fail("pass exactly one of --take, --plan or --save-plan");
|
|
694
778
|
if (o.take !== undefined && o.take !== "base" && o.take !== "variant")
|
|
695
779
|
fail(`--take must be "base" or "variant"`);
|
|
696
|
-
|
|
780
|
+
// Never through the cache: a tree there is clean and tracked, so gitUnheld would pass and the edit
|
|
781
|
+
// would be lost at the next cleanup without reaching the remote (spec 13 §4.4).
|
|
782
|
+
const f = await resolveForge({
|
|
783
|
+
forge: o.forge,
|
|
784
|
+
workspace: o.workspace,
|
|
785
|
+
refuseRemote: (url) => `the Forge of this workspace is remote (${url}) — clone it and pass --forge <dir>`,
|
|
786
|
+
});
|
|
697
787
|
const base = f.ingredients.get(ref);
|
|
698
788
|
if (!base)
|
|
699
789
|
fail(`${ref} is not an ingredient of this Forge`);
|
|
@@ -944,15 +1034,102 @@ forge
|
|
|
944
1034
|
});
|
|
945
1035
|
program.parseAsync().catch((e) => fail(e instanceof Error ? e.message : String(e)));
|
|
946
1036
|
/* ---------------------------------------------------------------- helpers */
|
|
1037
|
+
/** The network rule of a command, `--offline`, and `$CRAFTAR_HOME` (spec 13 §4.1, §6.3). */
|
|
1038
|
+
function load(o, mode) {
|
|
1039
|
+
return { mode, offline: o.offline === true, home: process.env.CRAFTAR_HOME || undefined };
|
|
1040
|
+
}
|
|
1041
|
+
/** A `forge` command's Forge; the warnings of reading a remote one go to stderr, so `--json` stays its shape. */
|
|
1042
|
+
async function forgeFor(o) {
|
|
1043
|
+
const { forge, workspace } = await resolveForgeSource({ forge: o.forge, workspace: o.workspace, ...load(o, "read") });
|
|
1044
|
+
warnStderr(workspace?.warnings ?? []);
|
|
1045
|
+
return forge;
|
|
1046
|
+
}
|
|
1047
|
+
/** `$CRAFTAR_HOME`, as the cache reads it (spec 13 §6.3). */
|
|
1048
|
+
function craftarHome() {
|
|
1049
|
+
return resolveHome(process.env.CRAFTAR_HOME || undefined);
|
|
1050
|
+
}
|
|
1051
|
+
/** `CRAFTAR_NO_REGISTRY` — "no registry", read like NO_COLOR: any non-empty value turns it off (spec 21 §4.1). */
|
|
1052
|
+
function registryOff() {
|
|
1053
|
+
return Boolean(process.env.CRAFTAR_NO_REGISTRY);
|
|
1054
|
+
}
|
|
1055
|
+
function registryGate() {
|
|
1056
|
+
if (registryOff())
|
|
1057
|
+
fail("the workspace registry is off (CRAFTAR_NO_REGISTRY is set)");
|
|
1058
|
+
}
|
|
1059
|
+
const ROW_WORDS = {
|
|
1060
|
+
"up-to-date": "up to date",
|
|
1061
|
+
outdated: "outdated",
|
|
1062
|
+
drift: "drift",
|
|
1063
|
+
"no-lock": "no lock",
|
|
1064
|
+
missing: "missing",
|
|
1065
|
+
error: "error",
|
|
1066
|
+
};
|
|
1067
|
+
/** The text table of `craftar workspaces` (spec 21 §4.2) — presentation, not contract. */
|
|
1068
|
+
function printWorkspaces(rows, warnings, fetched) {
|
|
1069
|
+
if (rows.length === 0) {
|
|
1070
|
+
console.log(pc.bold("craftar workspaces — no workspace registered (craftar sync registers one)"));
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
const offline = !fetched && rows.some((r) => r.forge.kind === "remote") ? " (status read offline from the Forge cache)" : "";
|
|
1074
|
+
console.log(pc.bold(`craftar workspaces — ${rows.length} registered${offline}`));
|
|
1075
|
+
const width = Math.max(...rows.map((r) => r.name.length));
|
|
1076
|
+
for (const r of rows) {
|
|
1077
|
+
console.log(` ${pc.cyan(r.name.padEnd(width))} ${r.path}`);
|
|
1078
|
+
const stack = Object.entries(r.stack).map(([slot, recipe]) => `${slot}=${recipe}`);
|
|
1079
|
+
console.log(` ${[`profile ${r.profile}`, ...(stack.length ? [stack.join(", ")] : []), ...(r.targets.length ? [r.targets.join(", ")] : [])].join(" · ")}`);
|
|
1080
|
+
const synced = `synced ${r.lastSync.slice(0, 16).replace("T", " ")} UTC`;
|
|
1081
|
+
const word = ROW_WORDS[r.status] + (r.forgeMoved ? ", forge moved" : "");
|
|
1082
|
+
const painted = r.status === "drift" || r.status === "error" || r.status === "missing" ? pc.red(word) : r.status === "up-to-date" ? pc.dim(word) : pc.yellow(word);
|
|
1083
|
+
if (r.status === "missing" || r.status === "error") {
|
|
1084
|
+
console.log(` ${synced} · ${painted}`);
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
const f = r.forge;
|
|
1088
|
+
const at = f.kind === "remote" ? `${f.ref ?? `${f.defaultBranch} (default branch)`} ${f.commit?.slice(0, 8) ?? "no git"}` : (f.commit?.slice(0, 8) ?? "no git");
|
|
1089
|
+
console.log(` forge ${f.source}${f.fromLocalFile ? " (local override)" : ""} @ ${at} · ${synced} · ${painted}`);
|
|
1090
|
+
}
|
|
1091
|
+
for (const w of warnings)
|
|
1092
|
+
console.log(` ${pc.yellow("warn")} ${w}`);
|
|
1093
|
+
}
|
|
1094
|
+
/** Warnings of loading the workspace, for commands whose stdout is not a report (a diff, `explain`, `ls`, `--json`). */
|
|
1095
|
+
function warnStderr(warnings) {
|
|
1096
|
+
for (const w of warnings)
|
|
1097
|
+
console.error(`${pc.yellow("warn")} ${w}`);
|
|
1098
|
+
}
|
|
1099
|
+
/** The header line naming a remote Forge (spec 13 §4.1); null for a path Forge, whose headers keep their shape. */
|
|
1100
|
+
function forgeLine(ws, lock) {
|
|
1101
|
+
const o = ws.origin;
|
|
1102
|
+
if (o.kind !== "remote")
|
|
1103
|
+
return null;
|
|
1104
|
+
const commit = ws.forge.commit;
|
|
1105
|
+
const at = o.ref ?? `${o.defaultBranch} (default branch)`;
|
|
1106
|
+
const moved = lock?.forge.commit && commit && lock.forge.commit !== commit ? ` · lock ${lock.forge.commit.slice(0, 8)}` : "";
|
|
1107
|
+
return ` forge ${o.source} @ ${at} ${commit?.slice(0, 8) ?? "no git"}${moved}`;
|
|
1108
|
+
}
|
|
1109
|
+
/** `status --json`'s `forge` key, for every Forge (spec 13 §4.1). */
|
|
1110
|
+
function forgeJson(ws, lock) {
|
|
1111
|
+
const o = ws.origin;
|
|
1112
|
+
return {
|
|
1113
|
+
kind: o.kind,
|
|
1114
|
+
source: o.source,
|
|
1115
|
+
ref: o.ref,
|
|
1116
|
+
defaultBranch: o.defaultBranch,
|
|
1117
|
+
commit: ws.forge.commit,
|
|
1118
|
+
lockCommit: lock?.forge.commit ?? null,
|
|
1119
|
+
fetched: o.fetched,
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
947
1122
|
function fail(msg) {
|
|
948
1123
|
console.error(pc.red("error: ") + msg);
|
|
949
1124
|
process.exit(1);
|
|
950
1125
|
}
|
|
951
|
-
function printStatus(st, warnings, profile, recipes, compact = false) {
|
|
1126
|
+
function printStatus(st, warnings, profile, recipes, compact = false, forge = null) {
|
|
952
1127
|
const counts = {};
|
|
953
1128
|
for (const s of st)
|
|
954
1129
|
counts[s.state] = (counts[s.state] ?? 0) + 1;
|
|
955
1130
|
console.log(pc.bold(`craftar status — profile ${profile} · recipes ${recipes.join(" → ")}`));
|
|
1131
|
+
if (forge)
|
|
1132
|
+
console.log(forge);
|
|
956
1133
|
console.log(" " +
|
|
957
1134
|
Object.entries(counts)
|
|
958
1135
|
.map(([k, v]) => `${color(k)(k)} ${v}`)
|