From 7bcbadef5dd22881ef2c6b70a76f03028cd7bbe1 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Sun, 6 Dec 2026 01:32:49 +0700 Subject: [PATCH 1/9] feat(config): unify project kit.toml, inherit door_paths, clean shim Use root kit.toml ([dev.*]) as canonical project config with .kit.toml fallback across all config readers, auto-inherit [repo].door_paths (or repokit.toml fallback) into the hard-path lane floor, migrate .kit.toml on adopt --refresh while preserving [repo], and remove pure 1-line @AGENTS.md CLAUDE.md shims under adopt.agents_only. --- commands/adopt.md | 37 +-- docs/guides/adopt.md | 14 +- .../unified-kit-toml-and-agents-only.md | 9 + docs/reference/FEATURES.md | 22 +- docs/reference/consumer-contract.md | 17 +- ...EC-434-unified-kit-toml-and-agents-only.md | 83 +++++ .../unified-kit-toml-and-agents-only.md | 71 +++++ lib/adopt.sh | 284 ++++++++++++++---- lib/adopt/README.md | 2 +- lib/bench/dashboard.py | 14 +- lib/classify/lane-classify.sh | 12 +- lib/config/README.md | 2 +- lib/config/config.sh | 31 +- lib/config/hook-module.sh | 9 +- lib/config/kit-config.sh | 242 +++++++++++++-- lib/config/merge-command.sh | 112 ++++--- lib/gate/gate-policy.sh | 19 +- lib/gate/lane-data.sh | 176 ++++++++--- lib/gate/ledger-key.sh | 23 +- lib/gate/proof-ledger.sh | 38 ++- lib/goal/mega-merge.sh | 7 +- lib/wrap/wrap-adopt.sh | 22 +- tests/test-adopt.sh | 200 ++++++++++-- tests/test-anchor-module-gate.sh | 10 +- tests/test-clean-room.sh | 2 +- tests/test-gate-opt-in.sh | 20 +- tests/test-gate-opt-out.sh | 2 +- tests/test-lanes-data.sh | 125 +++++++- tests/test-merge-command.sh | 32 +- tests/test-unified-kit-toml.sh | 106 +++++++ 30 files changed, 1406 insertions(+), 337 deletions(-) create mode 100644 docs/implementation-notes/unified-kit-toml-and-agents-only.md create mode 100644 docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md create mode 100644 docs/verification/unified-kit-toml-and-agents-only.md create mode 100755 tests/test-unified-kit-toml.sh diff --git a/commands/adopt.md b/commands/adopt.md index 835954a09..9f0bac115 100644 --- a/commands/adopt.md +++ b/commands/adopt.md @@ -9,7 +9,7 @@ coding, and the ship-gate engages on push. ## Run `$ARGUMENTS` may name a target dir (default: the repo root), `--check` (status only), -`--with ` (seed these modules `true` in a FRESH `.kit.toml`; ignored once one exists), +`--with ` (seed these modules `true` in a FRESH `kit.toml` `[dev.modules]`; ignored once devkit config exists), or `--single-source` (see below). 1. Resolve the target: default `.` (`git rev-parse --show-toplevel`). @@ -27,24 +27,10 @@ or `--single-source` (see below). - `AGENTS.md` -- a small pointer (about 1KB: four default rules that yield to the repo's own rules, plus where the full contract lives), not a copy of the 18KB contract. A repo's own `AGENTS.md` is never overwritten; an unmodified old kit copy is replaced only by `--refresh --swap-agents`, and an edited file gets a drift line. -- a `CLAUDE.md` loader pointer (Claude Code auto-loads CLAUDE.md, not AGENTS.md). Skipped when the repo sets `[adopt] agents_only = true` (see `## adopt.agents_only` below). +- a `CLAUDE.md` loader pointer (Claude Code auto-loads CLAUDE.md, not AGENTS.md). Skipped when the repo sets `[dev.adopt] agents_only = true` in `kit.toml` (or `[adopt] agents_only = true` in legacy `.kit.toml`; see `## adopt.agents_only` below). - `WORKFLOW.md` -- a pointer to the installed kit's lane x phase matrix (not a 49KB copy). - `docs/verification/README.md` -- the proof marker that makes the ship-gate engage. -- `.kit.toml` -- an OPT-IN starter override of the kit-root defaults. Created - only on a fresh adopt (never overwritten afterward); `--with` seeds the named modules - `true` instead of inheriting the kit-root default. `--with` names the exact set, so a core module - you leave out starts `false` (`install.sh --with` differs: it adds to the core set). Without `--with` - only `core` modules, today `board`, start `true`; every other module is opt-in. Edit `[modules]` any time and re-run - `/kit:adopt` (or `--refresh`) to re-wire. Its `[gate]` block is where the blocking quality - gates are set for this repo. A fresh seed turns `proof_of_done` and `lane_gates` ON (the kit - root keeps them off for a raw install, so a repo adopted before this change keeps whatever its - file says); an operator `kit.toml` that names either key still wins. `understanding_gate` and - `commit_format` are seeded with the values that resolved at adopt time (off by default), and - `board_row_gate`, `fixture_identities` and `review_verdict` default ON. Every key gets a comment, - and the block says how to turn each seeded gate off: set `proof_of_done = false` or - `lane_gates = false` and commit. Changes apply from the next hook fire (no re-adopt). Adopt only - seeds a fresh file: an existing `.kit.toml` is never touched, so a key the repo set or deleted - stays as it is. Safety gates have no key. Detail: `lib/gate/README.md` "Turning a gate on". +- `kit.toml` (`[dev.*]` sections) -- the unified root project config (devkit owns `[dev.*]`; repokit owns `[repo]` / `[repo.*]`). Created on a fresh adopt, or `[dev.modules]` and `[dev.gate]` are appended when `kit.toml` already exists with `[repo]` (preserving `[repo]` untouched). `--with` seeds the named modules `true` instead of inheriting the kit-root default. `--with` names the exact set, so a core module you leave out starts `false` (`install.sh --with` differs: it adds to the core set). Without `--with` only `core` modules, today `board`, start `true`; every other module is opt-in. Edit `[dev.modules]` any time and re-run `/kit:adopt` (or `--refresh`) to re-wire. Its `[dev.gate]` block is where the blocking quality gates are set for this repo. A fresh seed turns `proof_of_done` and `lane_gates` ON (the kit root keeps them off for a raw install, so a repo adopted before this change keeps whatever its file says); an operator `kit.toml` that names either key still wins. `understanding_gate` and `commit_format` are seeded with the values that resolved at adopt time (off by default), and `board_row_gate`, `fixture_identities` and `review_verdict` default ON. Every key gets a comment, and the block says how to turn each seeded gate off: set `proof_of_done = false` or `lane_gates = false` and commit. Changes apply from the next hook fire (no re-adopt). Legacy `.kit.toml` continues to work as a fallback, and `adopt.sh --refresh` migrates `.kit.toml` into `kit.toml` under `[dev.*]` (preserving `[repo]` and any existing `[dev.*]` sections) and removes `.kit.toml`. Safety gates have no key. Detail: `lib/gate/README.md` "Turning a gate on". - A one-time move of old kit logs into the durable ledger root (`lib/telemetry/kit-migrate.sh`), which `install.sh` also runs. It is the only place logs are copied; a hook or resolver never copies. `--check` and `--dry-run` skip it. @@ -76,14 +62,15 @@ overrides a `true` knob back off. ## `adopt.agents_only` -For a repo that wants `AGENTS.md` as its ONLY instruction file. Set `[adopt] agents_only = true` -in the repo's `.kit.toml` (or in the operator `kit.toml`). Then `adopt` and `adopt --refresh` never -create, restore or edit `CLAUDE.md`, and an existing `CLAUDE.md` is left exactly as found. The -operate-contract block lands in `AGENTS.md` (the block `--single-source` writes), `--check` no -longer needs `CLAUDE.md`, and the knob wins over `--single-source`. Default `false`: the -`CLAUDE.md` loader, as before. Needs Claude Code v2.1.277 or later, which reads `AGENTS.md` -directly when no `CLAUDE.md` exists in the working directory or above it; before v2.1.281 some -sessions (Bedrock, telemetry off) read only `CLAUDE.md`. +For a repo that wants `AGENTS.md` as its ONLY instruction file. Set `[dev.adopt] agents_only = true` +in the repo's `kit.toml` (or `[adopt] agents_only = true` in legacy `.kit.toml` or operator `kit.toml`). +Then `adopt` never creates a `CLAUDE.md` shim, and `adopt --refresh` removes an existing pure 1-line +`@AGENTS.md` `CLAUDE.md` shim (`git rm -f` if tracked, `rm -f` otherwise) while leaving any custom +`CLAUDE.md` untouched. The operate-contract block lands in `AGENTS.md` (the block `--single-source` +writes), `--check` no longer needs `CLAUDE.md`, and the knob wins over `--single-source`. Default +`false`: the `CLAUDE.md` loader, as before. Needs Claude Code v2.1.277 or later, which reads +`AGENTS.md` directly when no `CLAUDE.md` exists in the working directory or above it; before +v2.1.281 some sessions (Bedrock, telemetry off) read only `CLAUDE.md`. ## Overlays and seams diff --git a/docs/guides/adopt.md b/docs/guides/adopt.md index 9bf5994ed..559ddb189 100644 --- a/docs/guides/adopt.md +++ b/docs/guides/adopt.md @@ -12,7 +12,7 @@ _Figure: adoption writes a few small pointer files. The engine stays in the kit - `/kit:adopt` is the part that writes. It calls `lib/adopt.sh`, which only creates files and never overwrites one you wrote. - The files are small pointers. `AGENTS.md` carries four default rules, which apply only where the repo states no rule of its own, and a link to the full contract. `WORKFLOW.md` points at the installed lane matrix. - `CLAUDE.md` gets a loader block, because Claude Code reads `CLAUDE.md` and not `AGENTS.md`. -- The proof marker `docs/verification/README.md` is what makes the ship gate engage. A fresh `.kit.toml` turns `proof_of_done` and `lane_gates` on for the repo. +- The proof marker `docs/verification/README.md` is what makes the ship gate engage. A fresh `kit.toml` (`[dev.gate]`) turns `proof_of_done` and `lane_gates` on for the repo. If `kit.toml` already exists with `[repo]`, `[dev.modules]` and `[dev.gate]` are appended without touching `[repo]`. ## What you do @@ -33,20 +33,20 @@ _Figure: adoption writes a few small pointer files. The engine stays in the kit 5. Commit what adoption wrote. `lib/adopt.sh` does not commit. To adopt several repos and land one PR each, use `bin/wrap adopt ...`; it is a dry run until you add `--apply`. 6. Open a session in the adopted repo and say `/kit:start`. -**Refresh.** After you edit `[modules]` in `.kit.toml`, run `/kit:adopt --refresh`. It re-syncs the `WORKFLOW.md` pointer and the `CLAUDE.md` block and re-wires the project settings file to match. An existing `AGENTS.md`, `.kit.toml`, and proof marker are never touched. An old, unmodified kit `AGENTS.md` is replaced only with `--refresh --swap-agents`. +**Refresh.** After you edit `[dev.modules]` in `kit.toml`, run `/kit:adopt --refresh`. It re-syncs the `WORKFLOW.md` pointer and the `CLAUDE.md` block and re-wires the project settings file to match. If the repo still uses a legacy `.kit.toml`, `--refresh` migrates it into `kit.toml` under `[dev.*]` (preserving `[repo]` if present) and removes `.kit.toml`. An existing `AGENTS.md` and proof marker are never touched. An old, unmodified kit `AGENTS.md` is replaced only with `--refresh --swap-agents`. **Undo.** Nothing removes adoption for you. Delete the files it created, or revert the commit that added them. Removing `docs/verification/README.md` takes the repo out of the ship gate. Remove the `kit:adopt` block from `CLAUDE.md` by hand. **One guide file.** `--single-source` folds `CLAUDE.md` into `AGENTS.md` and leaves `CLAUDE.md` as a one-line import. If both files exist and differ, it refuses and writes nothing. -**No CLAUDE.md at all.** A repo that wants `AGENTS.md` as its only instruction file sets one key in its `.kit.toml`: +**No CLAUDE.md at all.** A repo that wants `AGENTS.md` as its only instruction file sets one key in its `kit.toml` (or `[adopt]` in legacy `.kit.toml`): ```toml -[adopt] +[dev.adopt] agents_only = true ``` -With the key set, `adopt` and `adopt --refresh` never create or restore `CLAUDE.md`, and an existing `CLAUDE.md` is left exactly as found. The operate-contract block lands in `AGENTS.md` (the same managed block `--single-source` writes), `adopt --check` stops asking for `CLAUDE.md`, and `bin/wrap adopt` stops counting a dirty `CLAUDE.md` as a collision. The key wins over `--single-source`. The default is `false`, so no other repo changes. +With the key set, `adopt` never creates a `CLAUDE.md` shim, and `adopt --refresh` removes an existing pure 1-line `@AGENTS.md` `CLAUDE.md` shim while leaving any custom `CLAUDE.md` untouched. The operate-contract block lands in `AGENTS.md` (the same managed block `--single-source` writes), `adopt --check` stops asking for `CLAUDE.md`, and `bin/wrap adopt` stops counting a dirty `CLAUDE.md` as a collision. The key wins over `--single-source`. The default is `false`, so no other repo changes. This needs Claude Code v2.1.277 or later. From that version Claude Code reads `AGENTS.md` directly when no `CLAUDE.md` exists in the working directory or above it ([docs](https://code.claude.com/docs/en/memory), section "AGENTS.md"). Before v2.1.281 some sessions, such as Bedrock or telemetry off, read only `CLAUDE.md`. If your team runs older builds, leave the key off. The session-start check in `hooks/context-readiness.sh` no longer warns about a missing `CLAUDE.md` when `AGENTS.md` exists. Detail: `kit.toml` `[adopt] agents_only`. @@ -80,10 +80,10 @@ adopt: AGENTS.md is not a kit file, 1 lines (left alone) | `/kit:onboard` says the kit is not installed | Install it first: `/plugin marketplace add consolelabs/devkit`, then `/plugin install kit@dwarves-marketplace`. Run `/kit:onboard` again. | | `onboard` warns that a plugin and a bash install are both present | The hooks fire twice. Keep one path; the warning names how to remove the other. | | `AGENTS.md is not a kit file ... (left alone)` | Expected. Your file stays. The operate-contract block lands in `CLAUDE.md`. | -| A module change had no effect | Edit `[modules]` in `.kit.toml`, then run `/kit:adopt --refresh`. On a plugin machine the plugin registers every hook, so the choice is recorded but adds no project hooks. | +| A module change had no effect | Edit `[dev.modules]` in `kit.toml` (or `[modules]` in `.kit.toml`), then run `/kit:adopt --refresh`. On a plugin machine the plugin registers every hook, so the choice is recorded but adds no project hooks. | | The ship gate never engages | Run `--check`. If it says not adopted, check that `docs/verification/README.md` exists. | | `--single-source` exits 1 | Both guide files exist and differ. Merge them by hand, then run it again. | -| `adopt` keeps writing `CLAUDE.md` and you want it gone | Set `[adopt] agents_only = true` in the repo's `.kit.toml`, delete the loader block from `CLAUDE.md` by hand, and re-run `/kit:adopt --refresh`. | +| `adopt` keeps writing `CLAUDE.md` and you want it gone | Set `[dev.adopt] agents_only = true` in the repo's `kit.toml` and run `/kit:adopt --refresh` (removes a pure 1-line `@AGENTS.md` shim automatically; remove custom blocks by hand). | ## Related diff --git a/docs/implementation-notes/unified-kit-toml-and-agents-only.md b/docs/implementation-notes/unified-kit-toml-and-agents-only.md new file mode 100644 index 000000000..149a18d03 --- /dev/null +++ b/docs/implementation-notes/unified-kit-toml-and-agents-only.md @@ -0,0 +1,9 @@ +# Implementation Notes: Unified project kit.toml ([dev.*]), [repo].door_paths inheritance, and agents_only shim cleanup + +Spec: `docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md` + +## Delta from spec + +- `lib/goal/mega-merge.sh` `_merge_config_guard`: emits the exact matched filename (`kit.toml` or `.kit.toml`) in its refusal message rather than a combined `kit.toml/.kit.toml` string so existing consumers and tests asserting `touches .kit.toml` stay backward-compatible while `kit.toml` PRs report `touches kit.toml`. +- `lib/adopt.sh` `_adopt_render_dev_sections`: retained the explicit `proof_of_done = false` / `lane_gates = false` turn-off comment inside the seeded `[dev.gate]` header to preserve the existing opt-out documentation contract tested by `tests/test-gate-opt-in.sh`. +- All other behavior matches `SPEC-434` verbatim. diff --git a/docs/reference/FEATURES.md b/docs/reference/FEATURES.md index b8da46ce1..9a4c9626f 100644 --- a/docs/reference/FEATURES.md +++ b/docs/reference/FEATURES.md @@ -13,14 +13,14 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | Command | Trigger | Description | Specs | Tests | |---|---|---|---|---| | `/kit:absorb` | `[H/I]` | Maintainer-only: audit the kit's upstream sources (Credits drift + seed-rescan) and draft a dated, proposal-only absorption report. Does no… | SPEC-004, SPEC-007, SPEC-009 +7 | test-command-emit-sweep.sh, test-hooks.sh, test-meta-spec-depth.sh +1 | -| `/kit:adopt` | `[H/I]` | Adopt the current (or a target) repo into the dwarves-kit operate-contract: write a small AGENTS.md pointer (never over a repo's own file) … | SPEC-004, SPEC-013, SPEC-014 +44 | test-adopt.sh, test-clean-room.sh, test-command-emit-sweep.sh +24 | +| `/kit:adopt` | `[H/I]` | Adopt the current (or a target) repo into the dwarves-kit operate-contract: write a small AGENTS.md pointer (never over a repo's own file) … | SPEC-004, SPEC-013, SPEC-014 +45 | test-adopt.sh, test-clean-room.sh, test-command-emit-sweep.sh +25 | | `/kit:assign` | `[H/I]` | Turn a backlog item (ID-NNN) into a scoped goal draft and route it into the right WORKFLOW lane. Writes .claude/goals/, never executes. | SPEC-006, SPEC-007, SPEC-024 +35 | test-context-note-shape.sh, test-hooks.sh, test-meta-contract.sh +5 | -| `/kit:battery` | `[H/I]` | The full independent-verification battery for a finished branch: a fresh-context acceptance verifier that RE-EXECUTES the verification comm… | SPEC-239, SPEC-244, SPEC-245 +11 | test-battery-gate.sh, test-board-work.sh, test-boundary-lint.sh +12 | +| `/kit:battery` | `[H/I]` | The full independent-verification battery for a finished branch: a fresh-context acceptance verifier that RE-EXECUTES the verification comm… | SPEC-239, SPEC-244, SPEC-245 +12 | test-battery-gate.sh, test-board-work.sh, test-boundary-lint.sh +12 | | `/kit:debug` | `[H/I]` | Systematic debug loop: root cause before any fix. Four phases, an evidence ledger, the 3-fix architecture wall. Use for any bug, defect, re… | SPEC-006, SPEC-013, SPEC-014 +19 | test-command-triggers.sh, test-config-registry.sh, test-doc-figures.sh +8 | | `/kit:design` | `[H/I]` | Opt-in interactive solution-design beat between /think and /spec. Use when the operator wants to shape HOW to build after the idea passed /… | SPEC-003, SPEC-004, SPEC-005 +162 | test-anomalies-advisor.sh, test-board-mirror-cleanup.sh, test-ceremony-fits-diff.sh +40 | | `/kit:devs-team` | `[H/I]` | Parallel multi-lens critique of a solution design (the active spec if present, else the decision brief). Dispatches 5 engineering lenses, m… | SPEC-016, SPEC-018, SPEC-019 +14 | test-gate-vocab-recording.sh, test-meta-review-verifiers.sh, test-meta-spec-depth.sh +1 | | `/kit:dispatch` | `[H/I]` | Fire several disjoint VALIDATED specs concurrently, each in its own worktree, then converge. Cross-goal fan-out behind a disjointness gate … | SPEC-002, SPEC-016, SPEC-017 +114 | test-advisor.sh, test-agent-effectiveness.sh, test-attempt-state-race.sh +52 | -| `/kit:docs` | `[H/I]` | Update all project documentation to match the current codebase. Cross-references the diff against every doc file and fixes drift. | SPEC-001, SPEC-002, SPEC-003 +293 | conform.sh, test-active-spec-pick.sh, test-adapters.sh +167 | +| `/kit:docs` | `[H/I]` | Update all project documentation to match the current codebase. Cross-references the diff against every doc file and fixes drift. | SPEC-001, SPEC-002, SPEC-003 +294 | conform.sh, test-active-spec-pick.sh, test-adapters.sh +167 | | `/kit:draft-agent` | `[H/I]` | Meta-agent agent-builder. From a one-line description, generates a new subagent definition OR a mega-goal sub-goal file and (by default) in… | SPEC-089, SPEC-108, SPEC-139 +1 | test-agent-effectiveness.sh, test-command-emit-sweep.sh, test-meta-agent.sh +1 | | `/kit:execute` | `[H/I]` | Whole-spec execution with verification. Dispatches one builder for the whole spec, verifies every task's criteria once at the end, retries … | SPEC-001, SPEC-003, SPEC-004 +82 | test-board-work.sh, test-break-it.sh, test-config-registry.sh +29 | | `/kit:explain` | `[H/I]` | Turn a merged change into a literate-diff explainer a human READS to understand: background -> goal + intuition -> a prose-ordered diff -> … | SPEC-050, SPEC-060, SPEC-094 +25 | test-boundary-lint.sh, test-clean-room.sh, test-command-emit-sweep.sh +13 | @@ -29,7 +29,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `/kit:greenlight` | `[H/I]` | Post-push CI-green lane: snapshots an open PR's checks via gh, classifies each failure real vs flaky, fixes real ones via the kit:fix-agent… | SPEC-019, SPEC-217, SPEC-369 | test-audit-verdict-grammar.sh, test-gate-ledger-actions.sh, test-ql-verdict.sh | | `/kit:grill` | `[H/I]` | Universal intake interview: one type-shaped question at a time, each with a recommended answer, until the task is actually understood. Answ… | SPEC-058, SPEC-059, SPEC-063 +27 | test-anomalies-advisor.sh, test-ceremony-lens.sh, test-config-stamp.sh +17 | | `/kit:kit-health` | `[H/I]` | Run a self-assessment of the kit against its own philosophy. Checks file count, hook performance, source citations, and structural health. | SPEC-001, SPEC-002, SPEC-004 +18 | test-command-emit-sweep.sh, test-meta-docs-registry.sh, test-meta-goal-ledger.sh +4 | -| `/kit:mega` | `[H/I]` | Turn a multi-objective destination into a sequenced roadmap of dependent sub-goals: decompose, front-load every clarification once, set the… | SPEC-034, SPEC-036, SPEC-088 +53 | test-adapters.sh, test-advisor.sh, test-bin-forwarders.sh +45 | +| `/kit:mega` | `[H/I]` | Turn a multi-objective destination into a sequenced roadmap of dependent sub-goals: decompose, front-load every clarification once, set the… | SPEC-034, SPEC-036, SPEC-088 +54 | test-adapters.sh, test-advisor.sh, test-bin-forwarders.sh +45 | | `/kit:next` | `[H/I]` | Pick up the next undone task from the spec. Loads context, shows acceptance criteria, lets you drive the implementation. | SPEC-001, SPEC-002, SPEC-003 +146 | smoke.sh, test-active-spec-pick.sh, test-adapters.sh +98 | | `/kit:onboard` | `[H/I]` | Guided first-run: detect the install mode, offer /kit:adopt for this repo, pick modules, capture the consumer knobs that make them work, di… | SPEC-199, SPEC-213, SPEC-232 +3 | test-clean-room.sh, test-command-emit-sweep.sh, test-onboard-detect.sh | | `/kit:pitch` | `[H/I]` | Assemble an outward buy-in doc from what a gated run already produced: the spec, the proof-of-done, the implementation-notes, and the gate … | SPEC-140, SPEC-141, SPEC-193 +7 | test-gate-validate-round.sh, test-outcome-emit-sweep.sh, test-pitch.sh +2 | @@ -40,7 +40,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `/kit:review` | `[H/I]` | Paranoid code review. Security, architecture, regressions, missing tests, edge cases. Produces actionable TODOS. | SPEC-001, SPEC-002, SPEC-003 +156 | smoke.sh, test-adopt.sh, test-advisor.sh +91 | | `/kit:ship` | `[H/I]` | Ship: review gate, tests, version bump, changelog, conventional commit, docs update, PR. Complete pipeline from done to merged. | SPEC-001, SPEC-002, SPEC-003 +111 | test-active-spec-pick.sh, test-adopt.sh, test-board-mirror.sh +65 | | `/kit:spec-validate` | `[H/I]` | Adversarial review of a spec before implementation. 7 specialist lenses attack the spec from different angles (6 advisory, 1 blocking on th… | SPEC-002, SPEC-003, SPEC-004 +70 | test-command-emit-sweep.sh, test-design-record.sh, test-every-step-review.sh +10 | -| `/kit:spec` | `[H/I]` | Generate a development spec from a feature idea or decision brief. Creates docs/specs/ with structured requirements. | SPEC-001, SPEC-002, SPEC-003 +241 | test-active-spec-pick.sh, test-audit-verdict-grammar.sh, test-bin-forwarders.sh +112 | +| `/kit:spec` | `[H/I]` | Generate a development spec from a feature idea or decision brief. Creates docs/specs/ with structured requirements. | SPEC-001, SPEC-002, SPEC-003 +241 | test-active-spec-pick.sh, test-adopt.sh, test-audit-verdict-grammar.sh +113 | | `/kit:start` | `[H/I]` | Detect project state and suggest the right next command. The entry point for any session. | SPEC-002, SPEC-003, SPEC-004 +94 | test-anomalies-advisor.sh, test-audit-cadence.sh, test-board-add.sh +98 | | `/kit:test-plan-review-team` | `[H/I]` | Parallel multi-lens adversarial critique of a spec's test plan (the ## Test plan section), with a bounded revise loop that tightens it. Dis… | SPEC-031, SPEC-052, SPEC-062 +14 | test-meta-docs-registry.sh, test-meta-review-verifiers.sh, test-meta-vmodel-dispatch.sh +3 | | `/kit:test-plan` | `[H/I]` | Derive a test-case coverage matrix from a spec's acceptance criteria before /kit:execute. Writes a `## Test plan` section into the active s… | SPEC-004, SPEC-016, SPEC-018 +38 | test-ceremony-lens.sh, test-e2e.sh, test-gate-ledger-inherit.sh +15 | @@ -50,7 +50,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `/kit:verify` | `[H/I]` | Re-run the test levels (kit:task-verifier + kit:integration-verifier + kit:acceptance-verifier, plus kit:system-verifier only with --full) … | SPEC-002, SPEC-003, SPEC-006 +57 | test-board-digest.sh, test-board-hermes.sh, test-board-lock-required.sh +35 | | `/kit:visual-team` | `[H/I]` | Parallel multi-lens critique of a visual/UI design. Dispatches 5 design lenses, merges findings, reports a verdict. Report-only, downstream… | SPEC-016, SPEC-018, SPEC-019 +12 | test-command-emit-sweep.sh, test-meta-review-verifiers.sh, test-meta-spec-depth.sh +1 | | `/kit:wayfind` | `[H]` | Plan a chunk of work too big for one agent session as a shared decision map: map.md + typed decision tickets in the mega-goal folder, resol… | SPEC-206, SPEC-207, SPEC-217 +2 | - | -| `/kit:wrap` | `[H/I]` | The session-scoped landing step after ship: flips board rows, merges green PRs, checks deploys, tidies worktrees, prints the skim-first rep… | SPEC-020, SPEC-060, SPEC-072 +76 | test-bash32-parse.sh, test-bin-forwarders.sh, test-board-lock-required.sh +62 | +| `/kit:wrap` | `[H/I]` | The session-scoped landing step after ship: flips board rows, merges green PRs, checks deploys, tidies worktrees, prints the skim-first rep… | SPEC-020, SPEC-060, SPEC-072 +77 | test-bash32-parse.sh, test-bin-forwarders.sh, test-board-lock-required.sh +62 | ## Agents @@ -100,7 +100,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `get-api-docs` | `[I]` | Fetch curated API documentation using Context Hub (chub) before coding against any external API. Use when the task involves calling a third… | SPEC-285, SPEC-372 | test-kit-foldin-hooks.sh | | `loop-engineering` | `[I]` | Use to design or add a new bounded loop to the kit's SDLC orchestration ("design a new loop", "is this worth a loop"), or mentions the Karp… | SPEC-209, SPEC-222, SPEC-225 +6 | test-loop-engineering-contract.sh, test-research-arch-contract.sh | | `memory-tidy` | `[I]` | Use when auditing, consolidating, or cleaning a repo's .claude/memory store, "dọn memory", "memory tidy", the biweekly memory audit, dupl… | SPEC-208, SPEC-225, SPEC-249 | test-audit-cadence.sh, test-audit-verdict-grammar.sh, test-memory-tidy-contract.sh +1 | -| `observe` | `[I]` | Query and render the kit's control plane (fleet runs, spend, debt; backed by lib/bench) from an agent session. NOT for your own Claude Code… | SPEC-033, SPEC-052, SPEC-128 +17 | smoke.sh, test-bin-forwarders.sh, test-kit-contract.sh +4 | +| `observe` | `[I]` | Query and render the kit's control plane (fleet runs, spend, debt; backed by lib/bench) from an agent session. NOT for your own Claude Code… | SPEC-033, SPEC-052, SPEC-128 +18 | smoke.sh, test-bin-forwarders.sh, test-kit-contract.sh +4 | | `repo-hygiene` | `[I]` | Use for the whole-repo decay audit, "run the repo-hygiene loop", "what has rotted in this repo", "is anything mis-shelved", "dọn repo", o… | SPEC-256 | test-audit-cadence.sh, test-audit-verdict-grammar.sh, test-repohygiene.sh | | `skill-review` | `[I]` | Review and promote skill drafts that skill-curator staged from past sessions. Use when the user runs /skill-review, says "review my skill d… | SPEC-218, SPEC-285 | test-async.sh, test-bin-forwarders.sh, test-egress-visible.sh +8 | | `stats` | `[I]` | Query or render ledger state and propose backlog rows off anomalies. Use when asked to SEE it -- "show me the ledger state", "my waived gat… | SPEC-001, SPEC-182, SPEC-192 +24 | test-anomalies-advisor.sh, test-bin-forwarders.sh, test-board-brief.sh +39 | @@ -146,14 +146,14 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | Verb | Trigger | Source | Description | Specs | Tests | |---|---|---|---|---|---| -| `adopt pointer` | `[V]` | `lib/adopt.sh` | inject the small AGENTS.md pointer, proof marker and CLAUDE.md loader into a target repo, hash-safe and idempotent | SPEC-047, SPEC-048, SPEC-049 +14 | test-adopt.sh, test-clean-room.sh, test-gate-opt-in.sh +12 | +| `adopt pointer` | `[V]` | `lib/adopt.sh` | inject the small AGENTS.md pointer, proof marker and CLAUDE.md loader into a target repo, hash-safe and idempotent | SPEC-047, SPEC-048, SPEC-049 +15 | test-adopt.sh, test-clean-room.sh, test-gate-opt-in.sh +13 | | `board state-check` | `[V]` | `lib/board/state_check.py` | validate the stored state values of a repo's own registry file; block new drift at commit, report existing drift | SPEC-428 | test-state-check.sh | | `board work` | `[V]` | `lib/board/work.sh` | one table of who is on what, how far along and who is stuck, joined at call time from board, git, Orca and the run ledger; read-only | SPEC-366, SPEC-370, SPEC-430 | test-board-work.sh, test-mega-box.sh, test-orchestrate-orca.sh | | `check-edit` | `[V]` | `lib/gate/check-edit.sh` | check-edit signal for execute: did the build weaken the checks the spec names, from a base ref diff | SPEC-369 | test-whole-spec-dispatch.sh | -| `classify floor` | `[V]` | `lib/classify/lane-classify.sh` | the diff floor: full when changed paths hit a hard path, else the size floor for the chosen lane | SPEC-036, SPEC-044, SPEC-045 +77 | test-active-spec-pick.sh, test-ceremony-fits-diff.sh, test-clean-room.sh +48 | -| `classify risk` | `[V]` | `lib/classify/lane-classify.sh` | risk verdict for a task and its files: full when the lane is full or a full-lane flag fires | SPEC-036, SPEC-044, SPEC-045 +77 | test-active-spec-pick.sh, test-ceremony-fits-diff.sh, test-clean-room.sh +48 | +| `classify floor` | `[V]` | `lib/classify/lane-classify.sh` | the diff floor: full when changed paths hit a hard path, else the size floor for the chosen lane | SPEC-036, SPEC-044, SPEC-045 +78 | test-active-spec-pick.sh, test-ceremony-fits-diff.sh, test-clean-room.sh +49 | +| `classify risk` | `[V]` | `lib/classify/lane-classify.sh` | risk verdict for a task and its files: full when the lane is full or a full-lane flag fires | SPEC-036, SPEC-044, SPEC-045 +78 | test-active-spec-pick.sh, test-ceremony-fits-diff.sh, test-clean-room.sh +49 | | `flick` | `[V]` | `lib/decide/flick.sh` | pick one of N through a decision API; shadow-only, fails open, always exit 0 | SPEC-381, SPEC-427 | test-bin-forwarders.sh, test-flick.sh, test-hooks.sh +2 | -| `lane data` | `[V]` | `lib/gate/lane-data.sh` | the one reader of lane data ([lane.] and [lanes] in kit.toml) for the gate ledger and the classifier | SPEC-044, SPEC-045, SPEC-048 +47 | test-active-spec-pick.sh, test-clean-room.sh, test-codex-hooks.sh +41 | +| `lane data` | `[V]` | `lib/gate/lane-data.sh` | the one reader of lane data ([lane.] and [lanes] in kit.toml) for the gate ledger and the classifier | SPEC-044, SPEC-045, SPEC-048 +48 | test-active-spec-pick.sh, test-clean-room.sh, test-codex-hooks.sh +41 | | `orchestrate --backend orca` | `[V]` | `lib/queue/orca-backend.sh` | opt-in Orca backend for the mega runner: sub-goals as Orca Tasks with supervised workers, state read live | SPEC-370 | test-orchestrate-orca.sh | | `push-refs` | `[V]` | `lib/gate/push-refs.sh` | fail-closed parser that names which refs a shell command pushes, used by the ship-gate | SPEC-044, SPEC-045, SPEC-048 +43 | test-active-spec-pick.sh, test-clean-room.sh, test-codex-hooks.sh +37 | | `recheck-sample decide` | `[V]` | `lib/gate/recheck-sample.sh` | decide and record whether an execute run rechecks its end-verifier PASSes, keyed on the rid | SPEC-369, SPEC-421 | test-whole-spec-dispatch.sh | diff --git a/docs/reference/consumer-contract.md b/docs/reference/consumer-contract.md index 0c607adf4..c6eedf499 100644 --- a/docs/reference/consumer-contract.md +++ b/docs/reference/consumer-contract.md @@ -15,8 +15,8 @@ idempotently. The step numbers match the `# N.` comments in `lib/adopt.sh`. | 2 | `WORKFLOW.md` | Pointer to the installed kit's lane x phase gate matrix | Yes, on `--refresh` (written atomically) | | 3 | `CLAUDE.md` (managed block) | `@AGENTS.md` import + the classify/gate one-liners, inside ` ... ` markers | Yes, on `--refresh` (block replaced; rest of the file untouched) | | 4 | `docs/verification/README.md` | The proof-of-done marker; its presence opts the repo into the ship-gate | Never | -| 5 | `.kit.toml` | Opt-in per-project starter, seeded once (see below) | Never; an existing file is not touched | -| 6 | `/.claude/settings.json` | Hook wiring for the enabled modules, a targeted `jq` merge | Every run, from the current `.kit.toml` | +| 5 | `kit.toml` (`[dev.*]`) | Unified project config starter (`[dev.modules]` + `[dev.gate]`), seeded once or appended alongside `[repo]` (see below) | Legacy `.kit.toml` migrated into `kit.toml` on `--refresh`; existing `[dev.*]` / `[repo]` preserved | +| 6 | `/.claude/settings.json` | Hook wiring for the enabled modules, a targeted `jq` merge | Every run, from the current `kit.toml` (or `.kit.toml`) | | 6b | `/.claude/settings.json`, `/.claude/output-styles/` | The `[output] style` pick, when set | Every run, when a style is set | Only `AGENTS.md` (bar the opt-in old-copy swap), the proof marker and an existing `.kit.toml` are never overwritten. The @@ -27,8 +27,7 @@ hook. `--single-source` folds the block into `AGENTS.md` and skips step 1. Claude Code auto-loads `CLAUDE.md`, not `AGENTS.md`, which is why the loader block exists: it `@AGENTS.md`-imports the real contract so an agent session actually reads it. -A repo may opt out of the loader with `[adopt] agents_only = true` in its `.kit.toml`. Then adopt never -writes or edits `CLAUDE.md`, the managed block lands in `AGENTS.md`, and row 3 above does not apply. +A repo may opt out of the loader with `[dev.adopt] agents_only = true` in its `kit.toml` (or `[adopt] agents_only = true` in legacy `.kit.toml`). Then adopt never creates `CLAUDE.md`, `--refresh` removes a pure 1-line `@AGENTS.md` shim while leaving custom `CLAUDE.md` files untouched, the managed block lands in `AGENTS.md`, and row 3 above does not apply. Claude Code v2.1.277 and later reads `AGENTS.md` directly when no `CLAUDE.md` exists in the working directory or above it; before v2.1.281 some sessions (Bedrock, telemetry off) read only `CLAUDE.md`. @@ -48,15 +47,9 @@ Pick **shared** (default) when several adopted projects should feed one run corp `/kit:retro` and the effectiveness eval. Pick **isolated** (or an explicit path) when a project's ledger must not mix with anything else on the machine. -## The optional `/.kit.toml` override +## The unified `/kit.toml` override (and legacy `.kit.toml`) -Seeded once by `/kit:adopt` (opt-in; never overwritten after creation; `--with a,b,c` seeds -those modules `true` instead of inheriting the kit-root default). A fresh seed also writes -`[gate] lane_gates = true` and `proof_of_done = true`, so an adopted repo enforces both gates; -a raw install keeps the `kit.toml` defaults, both off. Only the keys you set win; -everything you omit inherits the operator `kit.toml`, then the kit-root `kit.toml` default -(`lib/config/kit-config.sh` resolves project > operator > kit-root > default; a missing file -at any layer is skipped). +Seeded once by `/kit:adopt` under `[dev.*]` (never overwritten after creation; appends `[dev.modules]` and `[dev.gate]` if `kit.toml` already exists with `[repo]`; `--with a,b,c` seeds those modules `true` instead of inheriting the kit-root default). A fresh seed also writes `[dev.gate] lane_gates = true` and `proof_of_done = true`, so an adopted repo enforces both gates; a raw install keeps the `kit.toml` defaults, both off. Only the keys you set win; everything you omit inherits legacy `.kit.toml` (`[*]`), then the operator `kit.toml`, then the kit-root `kit.toml` default (`lib/config/kit-config.sh` resolves project `kit.toml [dev.*]` > project `.kit.toml [*]` > operator > kit-root > default; a missing file at any layer is skipped). `[repo].door_paths` in `kit.toml` (or `door_paths` in `repokit.toml`) is automatically inherited into devkit's hard-path lane floor alongside `[dev.lanes] extra_hard_paths`. The operator file lives at `${XDG_CONFIG_HOME:-$HOME/.config}/dwarves-kit/kit.toml` (`KIT_CONFIG_OPERATOR` overrides the directory). It holds the keys that name per-operator diff --git a/docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md b/docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md new file mode 100644 index 000000000..c962df886 --- /dev/null +++ b/docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md @@ -0,0 +1,83 @@ +# Spec: Unified project kit.toml ([dev.*]), [repo].door_paths inheritance, and agents_only shim cleanup + +Generated: 2026-12-06 +Status: VALIDATED +Lane: full (touches lib/config/kit-config.sh, lib/gate/, lib/classify/lane-classify.sh, and lib/adopt.sh) +Depth: standard (all config readers, gate surfaces, and adopt code paths read live in the repo) +Type: spec-feature +File: `docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md` +References: `lib/config/kit-config.sh`, `lib/config/config.sh`, `lib/config/hook-module.sh`, `lib/config/merge-command.sh`, `lib/gate/lane-data.sh`, `lib/gate/gate-policy.sh`, `lib/gate/proof-ledger.sh`, `lib/gate/ledger-key.sh`, `lib/classify/lane-classify.sh`, `lib/goal/mega-merge.sh`, `lib/adopt.sh`, `lib/wrap/wrap-adopt.sh`, `lib/bench/dashboard.py` + +## Problem + +1. Adopted repositories currently carry separate config files for `repokit` (`repokit.toml`) and `devkit` (`.kit.toml`). Consolidating into one root `kit.toml` with `[repo]` owned by `repokit` and `[dev.*]` owned by `devkit` removes config fragmentation without breaking existing `.kit.toml` repos. +2. `repokit` already declares one-way doors in `door_paths` (`[repo].door_paths` in `kit.toml`, or legacy `repokit.toml`), while `devkit` required duplicating them into `[lanes] extra_hard_paths` for the lane floor to engage. +3. Under `[dev.adopt] agents_only = true`, Claude Code v2.1.277+ reads `AGENTS.md` directly when no `CLAUDE.md` exists, leaving pre-existing 1-line `@AGENTS.md` `CLAUDE.md` shims redundant during `adopt.sh --refresh`. + +## Rules + +| # | Rule | +|---|---| +| R1 | Canonical project config is `/kit.toml`, where devkit sections live under `[dev.
]` (`[dev.modules]`, `[dev.gate]`, `[dev.adopt]`, `[dev.lanes]`, `[dev.lane.]`, `[dev.merge]`, `[dev.output]`, `[dev.proof]`, `[dev.ledger]`, `[dev.mega]`, `[dev.sync]`, `[dev.test]`, `[dev.battery]`, `[dev.wrap]`, `[dev.observe]`) and `[[dev.gate.hard_path_exempt]]`. `[repo]` and `[repo.*]` belong to `repokit` and are preserved untouched. | +| R2 | Precedence for project reads: `/kit.toml` `[dev.
]` wins over `/.kit.toml` `[
]`, which wins over operator `kit.toml` `[
]`, which wins over kit-root `kit.toml` `[
]`. Unprefixed `[
]` in `/kit.toml` is not read as a project override so devkit's own kit-root `kit.toml` never shadows the operator layer. | +| R3 | Every config reader (`kit-config.sh`, `config.sh`, `hook-module.sh`, `merge-command.sh`, `lane-data.sh`, `gate-policy.sh`, `proof-ledger.sh`, `ledger-key.sh`, `wrap-adopt.sh`, `mega-merge.sh`, `dashboard.py`) respects R1 and R2, including committed-at-rev reads (`--at`, `KIT_LANE_PROJECT_AT`, `KIT_FLOOR_CONFIG_AT`) and tracked-clean checks on the specific file that supplied the value. | +| R4 | `lane-classify.sh` treats both `.kit.toml` and `kit.toml` as `kit-config` hard paths; `mega-merge.sh` config guard blocks auto-merge on either; `proof-ledger.sh` treats project-config-only diffs to either as inert. | +| R5 | `lane_extra_hard_paths` automatically inherits `door_paths` from `[repo]` in `kit.toml`, falling back to `repokit.toml` (`door_paths` at top-level or `[repo]`) when `[repo].door_paths` is not declared in `kit.toml`. Supports single-line and multi-line TOML string arrays in pure POSIX awk. Escapes ERE metacharacters; trailing `/` matches directory prefix (`^`), non-trailing matches exact path or subdir (`^(/|$)`). Unions across working tree, HEAD, and `KIT_FLOOR_CONFIG_AT`, alongside `extra_hard_paths`. | +| R6 | `lib/adopt.sh` fresh adoption writes devkit sections under `[dev.*]` in `kit.toml` (appending `[dev.modules]` and `[dev.gate]` to an existing `kit.toml` that has `[repo]` without clobbering it). `adopt.sh --refresh` migrates an existing `.kit.toml` into `kit.toml` under `[dev.*]` (preserving all values and any existing `[repo]` or `[dev.*]` sections in `kit.toml`), removes `.kit.toml` (`git rm -f` if tracked, `rm -f` otherwise), and is idempotent on re-run. | +| R7 | Under `agents_only = true` (`[dev.adopt]` in `kit.toml` or `[adopt]` in `.kit.toml`), `lib/adopt.sh` never creates a `CLAUDE.md` shim. During `adopt.sh --refresh`, if `CLAUDE.md` is a regular non-symlink file whose trimmed content equals `@AGENTS.md`, remove it (`git rm -f` if tracked, `rm -f` otherwise); never remove any custom `CLAUDE.md`. `adopt.sh --check` exits 0 when `CLAUDE.md` is absent. | + +## Technical Design + +- `lib/config/kit-config.sh`: add `kit_config_project_dir`, `kit_config_project_kit`, `kit_config_project_legacy`, `_kit_project_get`, `_kit_project_get_with_file`, `kit_config_show_kit_at`, `kit_config_show_legacy_at`, `_kit_project_get_at`, and `_kit_toml_get_array` (pure POSIX awk parser for single-line and multi-line TOML string arrays). Update `kit_config_project`, `kit_config_get`, `kit_config_show_at`, and `kit_config_get_at`. +- `lib/gate/lane-data.sh`: read project `[dev.lane.]`, `[dev.lanes]`, `[[dev.gate.hard_path_exempt]]` / `[dev.gate] hard_path_canaries` from `kit.toml` with `.kit.toml` fallback; inherit `[repo].door_paths` (or `repokit.toml` fallback) into `lane_extra_hard_paths` with ERE escaping and anti-tamper git union. +- `lib/classify/lane-classify.sh`: widen `_HP_kitconfig` to `(^|/)\.?kit\.toml$`; exempt exact `.md` `door_paths` entries (like `SECURITY.md`) from doc-blanking in `_floor_scan`. +- `lib/gate/gate-policy.sh`, `lib/gate/proof-ledger.sh`, `lib/gate/ledger-key.sh`, `lib/config/config.sh`, `lib/config/hook-module.sh`, `lib/config/merge-command.sh`, `lib/goal/mega-merge.sh`, `lib/wrap/wrap-adopt.sh`, `lib/bench/dashboard.py`: support `kit.toml` `[dev.*]` with `.kit.toml` fallback. +- `lib/adopt.sh`: seed/append `[dev.modules]` + `[dev.gate]` into `kit.toml`; on `--refresh`, migrate `.kit.toml` -> `kit.toml` (`[dev.*]`) preserving `[repo]` and remove `.kit.toml`; under `agents_only = true` + `--refresh`, remove pure 1-line `@AGENTS.md` `CLAUDE.md` shim while preserving custom `CLAUDE.md`. + +## Test Plan + +- Unit tests in `lib/config/kit-config.sh selftest` (`tests/test-config.sh`): `kit.toml` `[dev.*]` precedence over `.kit.toml`, `.kit.toml` fallback, partial override across both files, `kit_config_get_at` precedence, single-line and multi-line `_kit_toml_get_array`, unprefixed kit-root isolation. +- Unit tests in `tests/test-lanes-data.sh`: `kit.toml` `[repo].door_paths` raises floor to `full` with zero `extra_hard_paths`, literal dot escaping (`deploy/macos/firewall.sh` vs `firewallXsh`), directory prefix (`internal/ghauth/`), multi-line array, `kit.toml` `[repo].door_paths` beats `repokit.toml`, legacy `repokit.toml` fallback, union with `[dev.lanes] extra_hard_paths`, negative control (unrelated path stays non-full, removing `door_paths` drops floor), `kit.toml` `[dev.gate]` / `[dev.lane.*]` / `[[dev.gate.hard_path_exempt]]`. +- Unit tests in `tests/test-adopt.sh`: fresh adopt seeds `kit.toml` (`[dev.modules]` + `[dev.gate]`), fresh adopt preserves existing `[repo]` in `kit.toml`, `--refresh` migrates `.kit.toml` into `kit.toml` under `[dev.*]` (with and without existing `[repo]`) and removes `.kit.toml` idempotently, `agents_only = true` shim-free adoption, `--refresh` removes pure 1-line `@AGENTS.md` `CLAUDE.md` shim (tracked and untracked, `--dry-run`), negative control preserving custom `CLAUDE.md`. +- Unit tests in `tests/test-anchor-module-gate.sh`, `tests/test-merge-command.sh`, `tests/test-config-registry.sh`, `tests/test-wrap-adopt.sh`, `tests/test-meta.sh`, `tests/test-hooks.sh`, and full `bash tests/run-all.sh`. + +## Task Breakdown + +- [x] Implement unified `kit.toml` (`[dev.*]`) resolver and update config readers across `lib/` and `bin/`. +- [x] Implement `[repo].door_paths` and `repokit.toml` auto-inheritance into `lane-data.sh` / `lane-classify.sh`. +- [x] Update `lib/adopt.sh` for `kit.toml` `[dev.*]` seeding, `--refresh` migration, and `agents_only = true` 1-line `@AGENTS.md` shim removal. +- [x] Update docs and unit tests; run full test suites and record proof with negative controls. + +## Review + +### Verdict: SHIP + +- Checked kit-root vs project `kit.toml` isolation: unprefixed `[
]` in project `kit.toml` is never read as a project override, preventing `consolelabs/devkit`'s own shipped-default `kit.toml` from shadowing the operator layer. +- Checked tracked-clean and committed-at-rev guards across `gate-policy.sh`, `lane-data.sh`, `proof-ledger.sh`, `merge-command.sh`, `wrap-adopt.sh`, and `ledger-key.sh`: every gate checks tracked-clean on the exact file (`kit.toml` or `.kit.toml`) that supplied the winning value. +- Checked anti-tamper union for `[repo].door_paths` / `repokit.toml` `door_paths` across working tree, `HEAD`, and `KIT_FLOOR_CONFIG_AT`, plus ERE metacharacter escaping and exact `.md` door preservation (`SECURITY.md`). +- Checked `adopt.sh --refresh` migration preserves `[repo]` and existing `[dev.*]` sections atomically, removes `.kit.toml` (`git rm` when tracked), and removes only pure 1-line `@AGENTS.md` `CLAUDE.md` shims under `agents_only = true` (never custom `CLAUDE.md` or symlinks). +- Verified with `bash tests/test-meta.sh`, `bash tests/run-all.sh`, targeted suites, and mechanized base-ref negative controls. + +## After state + +Projects adopt directly into `kit.toml` (`[dev.*]`), existing `.kit.toml` repos keep working and migrate cleanly on `adopt.sh --refresh` without touching `[repo]`, `door_paths` from `kit.toml [repo]` or `repokit.toml` automatically raise the lane floor to `full`, and `agents_only = true` stays free of redundant `@AGENTS.md` `CLAUDE.md` shims. + +## Acceptance Criteria + +| AC | Check | +|---|---| +| AC1 `kit.toml` `[dev.*]` wins over `.kit.toml`; `.kit.toml` fallback works; kit-root unprefixed `kit.toml` does not shadow operator | `bash tests/test-config.sh`, `bash tests/test-config-registry.sh`, `bash tests/test-anchor-module-gate.sh`, `bash tests/test-merge-command.sh` | +| AC2 `kit.toml` `[repo].door_paths` and `repokit.toml` `door_paths` (single-line and multi-line, ERE-escaped) raise lane floor to `full`, with precedence and negative controls | `bash tests/test-lanes-data.sh` | +| AC3 `adopt.sh` seeds/appends `kit.toml` `[dev.*]` preserving `[repo]`, `--refresh` migrates `.kit.toml` -> `kit.toml` idempotently, `agents_only = true` removes pure 1-line `@AGENTS.md` shim on `--refresh` without touching custom `CLAUDE.md` | `bash tests/test-adopt.sh`, `bash tests/test-wrap-adopt.sh` | +| AC4 Full test suites and structural meta checks pass | `bash tests/run-all.sh`, `bash tests/test-hooks.sh`, `bash tests/test-meta.sh` | + +## Verification + +```bash +bash tests/test-config.sh +bash tests/test-adopt.sh +bash tests/test-lanes-data.sh +bash tests/test-hooks.sh +bash tests/test-meta.sh +bash tests/run-all.sh +``` diff --git a/docs/verification/unified-kit-toml-and-agents-only.md b/docs/verification/unified-kit-toml-and-agents-only.md new file mode 100644 index 000000000..1a90027fe --- /dev/null +++ b/docs/verification/unified-kit-toml-and-agents-only.md @@ -0,0 +1,71 @@ +# Verification: Unified project kit.toml ([dev.*]), [repo].door_paths inheritance, and agents_only shim cleanup + +Spec: `docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md` +Date: 2026-12-06 +Class: behavioral + +## Green runs + +### 1. Targeted unified config, door_paths, adopt migration, and shim cleanup suite + +Command: `bash tests/test-unified-kit-toml.sh` +Exit: 0 +Output: +``` +ok - kit.toml [dev.*] wins over .kit.toml [*] +ok - gate-policy: kit.toml [dev.gate] lane_gates=true wins over .kit.toml false +ok - gate-policy: falls back to .kit.toml proof_of_done=false when absent in kit.toml +ok - kit.toml [repo].door_paths raises floor to full (zero extra_hard_paths) +ok - classify --files matches [repo].door_paths directory prefix +ok - ERE metacharacter escaping: literal dot does not match X +ok - negative control: unrelated path stays normal +ok - negative control: removing door_paths drops floor to normal +ok - fallback: legacy repokit.toml door_paths raises lane floor to full +ok - precedence: kit.toml [repo].door_paths wins over repokit.toml and unions with extra_hard_paths +ok - adopt --refresh migrates .kit.toml into kit.toml preserving [repo], removes 1-line @AGENTS.md shim, --check passes +--- +PASS=11 FAIL=0 +``` +Verdict: PASS + +### 2. Full affected suite, hooks suite, and structural meta suite + +Command: `bash tests/test-meta.sh && bash tests/run-all.sh --time` +Exit: 0 +Output: +``` +test-meta.sh: Passed: 945 / 945, Failed: 0 +test-adopt.sh: PASS=98 FAIL=0 +test-config.sh: PASS kit-config selftest (33/33) +test-anchor-module-gate.sh: Results: 41 passed, 0 failed +test-config-registry.sh: 60/60 passed +test-hooks: ok (137s) +test-lanes-data: ok (212s) +test-unified-kit-toml: ok (4s) +run-all: all 118 suites passed, 0 skipped for missing tooling +``` +Verdict: PASS + +## Negative controls + +### Negative control 1 (negctl, base-ref mode): unified kit.toml [dev.*] precedence + [repo].door_paths lane floor + +Base ref: master +Command: `bash -c 'd=$(mktemp -d); trap "rm -rf $d" EXIT; printf "[repo]\ndoor_paths = [\"deploy/macos/firewall.sh\"]\n[dev.ledger]\nlocation = \"unified\"\n" > "$d/kit.toml"; printf "[ledger]\nlocation = \"legacy\"\n" > "$d/.kit.toml"; v=$(KIT_PROJECT_ROOT="$d" bash -c "source lib/config/kit-config.sh; kit_config_get ledger.location"); l=$(KIT_PROJECT_ROOT="$d" bash lib/classify/lane-classify.sh classify --files deploy/macos/firewall.sh "tweak script" 2>/dev/null); echo "loc=$v lane=$l"; [ "$v" = unified ] && [ "$l" = full ]'` +Exit: 1 (base ref, RED expected) +Output: +``` + loc=legacy lane=normal +``` +Verdict: PASS + +### Negative control 2 (negctl, base-ref mode): adopt --refresh migration preserving [repo] + agents_only 1-line @AGENTS.md shim removal + +Base ref: master +Command: `bash -c 'd=$(mktemp -d); trap "rm -rf $d" EXIT; git -C "$d" init -q; printf "[repo]\nprofile = \"public-app\"\n" > "$d/kit.toml"; printf "[adopt]\nagents_only = true\n" > "$d/.kit.toml"; printf "@AGENTS.md\n" > "$d/CLAUDE.md"; CLAUDE_DIR="$d/.no-claude" KIT_CONFIG_OPERATOR="$d/.no-op" bash lib/adopt.sh --refresh "$d" >/dev/null 2>&1; echo "dotkit=$(test -e "$d/.kit.toml" && echo yes || echo no) claude=$(test -e "$d/CLAUDE.md" && echo yes || echo no)"; [ ! -e "$d/.kit.toml" ] && [ ! -e "$d/CLAUDE.md" ] && grep -q "^\[repo\]" "$d/kit.toml" && grep -q "^\[dev\.adopt\]" "$d/kit.toml"'` +Exit: 1 (base ref, RED expected) +Output: +``` + dotkit=yes claude=yes +``` +Verdict: PASS diff --git a/lib/adopt.sh b/lib/adopt.sh index c7a0dcb8c..90a291a3c 100755 --- a/lib/adopt.sh +++ b/lib/adopt.sh @@ -117,6 +117,7 @@ agents="$TARGET/AGENTS.md" workflow="$TARGET/WORKFLOW.md" claude="$TARGET/CLAUDE.md" marker="$TARGET/docs/verification/README.md" +kitfile="$TARGET/kit.toml" dotkit="$TARGET/.kit.toml" project_settings="$TARGET/.claude/settings.json" @@ -187,8 +188,8 @@ fi # them, would send the read or the write to a file outside the project, so refuse the target. # shellcheck source=lib/config/safe-path.sh source "$SELF_DIR/config/safe-path.sh" -claude_guard="$claude"; [ "$AGENTS_ONLY" -eq 1 ] && claude_guard="" # never touched in agents-only mode -kit_refuse_symlink_path "$TARGET" "$agents" ${claude_guard:+"$claude_guard"} "$workflow" "$marker" "$dotkit" \ +claude_guard="$claude"; [ "$AGENTS_ONLY" -eq 1 ] && claude_guard="" # never touched on fresh adopt; shim cleanup checks ! -L +kit_refuse_symlink_path "$TARGET" "$agents" ${claude_guard:+"$claude_guard"} "$workflow" "$marker" "$kitfile" "$dotkit" \ "$project_settings" "$TARGET/.claude/output-styles" \ || { echo "adopt: not adopting $TARGET" >&2; exit 1; } @@ -390,6 +391,30 @@ elif [ "$REFRESH" -eq 1 ]; then fi fi +# 3b. agents-only shim cleanup (--refresh only): Claude Code v2.1.277+ reads AGENTS.md natively +# when no CLAUDE.md exists. Remove a pure 1-line `@AGENTS.md` shim cleanly without ever touching +# a custom CLAUDE.md or a symlink. +_is_pure_agents_shim() { + [ -f "$1" ] && [ ! -L "$1" ] || return 1 + local trimmed + trimmed="$(tr -d '\r' < "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d')" + [ "$trimmed" = "@AGENTS.md" ] +} +if [ "$AGENTS_ONLY" -eq 1 ] && [ "$REFRESH" -eq 1 ] && _is_pure_agents_shim "$claude"; then + if [ "$DRY" -eq 1 ]; then + note "remove redundant 1-line @AGENTS.md shim CLAUDE.md (adopt.agents_only is on)" + else + if git -C "$TARGET" rev-parse --git-dir >/dev/null 2>&1 \ + && git -C "$TARGET" ls-files --error-unmatch CLAUDE.md >/dev/null 2>&1; then + git -C "$TARGET" rm -f -q CLAUDE.md >/dev/null 2>&1 || rm -f "$claude" + else + rm -f "$claude" + fi + echo "adopt: removed redundant 1-line @AGENTS.md shim CLAUDE.md (adopt.agents_only is on)" + fi + did=1 +fi + # 4. proof marker -- presence opts this repo into the ship-gate. NEVER overwritten. if [ ! -f "$marker" ]; then if [ "$DRY" -eq 1 ]; then note "create docs/verification/README.md (proof marker)"; else @@ -409,72 +434,209 @@ fi # kit_root_toml and the config resolver are already loaded up front (needed for the # single_source knob before this point too). -# 5. Per-project .kit.toml -- an OPT-IN starter. Created only if absent; a -# project's own config is NEVER overwritten by adopt, fresh or --refresh (same invariant as -# AGENTS.md / the proof marker). --with (first run only) seeds the named modules `true`; -# every other key seeds the kit-root default it would inherit anyway -- writing the line -# explicitly just makes the override point visible and editable. The one exception is -# [gate] proof_of_done and lane_gates: a fresh seed turns them ON (the kit root keeps them off -# for a raw install). An existing .kit.toml is never touched, so a repo that set or deleted -# either key keeps its choice. +# 5. Per-project unified kit.toml ([dev.*] sections; [repo] belongs to repokit and is preserved). +# - Fresh adopt (neither kit.toml nor .kit.toml): seeds kit.toml with [dev.modules] and [dev.gate]. +# - Fresh adopt with existing kit.toml that has no [dev.*] sections (e.g. repokit [repo]): appends +# [dev.modules] and [dev.gate] without clobbering existing sections. +# - --refresh when legacy .kit.toml exists: migrates .kit.toml into kit.toml under [dev.*] +# (preserving all values and any existing [repo] or [dev.*] sections in kit.toml), then removes +# .kit.toml (`git rm` if tracked, `rm` otherwise). Idempotent on re-run. +# - Existing devkit config is otherwise never overwritten. +_adopt_has_dev_sections() { + [ -f "$1" ] && grep -qE '^[[:space:]]*\[+[[:space:]]*dev(\.|])' "$1" 2>/dev/null +} + +_adopt_render_dev_sections() { + local with_norm="" m g v + [ -n "$WITH_ARG" ] && with_norm=" $(echo "$WITH_ARG" | tr ',' ' ' | xargs) " + echo "# [dev.*] sections -- this project's devkit overrides of $KIT_REF/kit.toml." + echo "# [repo] / [repo.*] sections belong to repokit and are preserved untouched." + echo "# Re-run \`bash $KIT_REF/lib/adopt.sh --refresh \` (or /kit:adopt) after" + echo "# editing [dev.modules] to re-wire this project's .claude/settings.json to match." + echo "# [dev.gate] is read when a hook fires: set a key to true/false and commit." + echo "" + echo "[dev.modules]" + for m in $KIT_KNOWN_MODULES; do + if [ -n "$with_norm" ]; then + case "$with_norm" in *" $m "*) v=true ;; *) v=false ;; esac + else + v="$(KIT_CONFIG_ROOT="$(dirname "$kit_root_toml")" KIT_PROJECT_ROOT="$TARGET" kit_config_get "modules.$m" "false")" + fi + echo "$m = $v" + done + echo "" + echo "[dev.gate] # quality gates. An adopted repo starts with proof_of_done and lane_gates ON (the kit root" + echo " # keeps them off for a raw install). The others are OPT-IN except board_row_gate," + echo " # fixture_identities and review_verdict (on by default). true turns a gate on for this repo," + echo " # false keeps it off (a false counts once this file is committed). To turn one of the two seeded" + echo " # gates off, set \`proof_of_done = false\` or \`lane_gates = false\` below and commit. Safety gates have no key." + echo " # proof_of_done ship-gate: a load-bearing diff needs a proof-of-done record (seeded true)" + echo " # lane_gates ship-gate: the lane x phase required gates + the no-Lane refusal (seeded true)" + echo " # understanding_gate Stop hook: blocks a stop that rationalizes unfinished work" + echo " # commit_format commit-subject lint (conventional type, <=72 chars)" + echo " # board_row_gate a commit adding a new board row needs a board-row-ok: line" + echo " # fixture_identities ship-gate: refuses fixture git identities on new commits" + echo " # review_verdict ship-gate: refuses push while spec last ## Review verdict is DO NOT SHIP" + for g in $(bash "$SELF_DIR/gate/gate-policy.sh" keys 2>/dev/null); do + case "$g" in + proof_of_done|lane_gates) + v="$(KIT_CONFIG_ROOT=/nonexistent KIT_PROJECT_ROOT=/nonexistent kit_config_get "gate.$g" "true")" ;; + *) + v="$(KIT_CONFIG_ROOT="$(dirname "$kit_root_toml")" KIT_PROJECT_ROOT="$TARGET" kit_config_get "gate.$g" "false")" ;; + esac + echo "$g = $v" + done +} + +# _adopt_migrate_dotkit -- transform sections to [dev.*] +# and merge cleanly with (preserving [repo] and any pre-existing [dev.*] sections). +_adopt_migrate_dotkit() { + local src="$1" existing="$2" dest="$3" mig + mig="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || return 1 + if [ -f "$existing" ]; then + awk ' + function norm_hdr(s, h) { + h = s; sub(/[[:space:]]*#.*$/, "", h); gsub(/[[:space:]\r]/, "", h); return h + } + function map_hdr(line, pre, br, name, tail, raw) { + sub(/\r$/, "", line) + raw = line + sub(/^[[:space:]]*/, "", raw) + pre = substr(line, 1, length(line) - length(raw)) + if (match(raw, /^\[\[[[:space:]]*[^]#]+[[:space:]]*\]\]/)) { + br = substr(raw, 1, RLENGTH) + tail = substr(raw, RLENGTH + 1) + name = br; sub(/^\[\[[[:space:]]*/, "", name); sub(/[[:space:]]*\]\]$/, "", name) + if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name + return pre "[[" name "]]" tail + } + if (match(raw, /^\[[[:space:]]*[^]#]+[[:space:]]*\]/)) { + br = substr(raw, 1, RLENGTH) + tail = substr(raw, RLENGTH + 1) + name = br; sub(/^\[[[:space:]]*/, "", name); sub(/[[:space:]]*\]$/, "", name) + if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name + return pre "[" name "]" tail + } + return line + } + NR == FNR { + if ($0 ~ /^[[:space:]]*\[/) { have[norm_hdr($0)] = 1 } + next + } + { + line = $0; sub(/\r$/, "", line) + if (line ~ /^[[:space:]]*\[/) { + seen_sec = 1 + mapped = map_hdr(line) + nh = norm_hdr(mapped) + if (nh in have) { skip = 1; next } + skip = 0 + print mapped + next + } + if (!seen_sec) { + # Drop auto-generated .kit.toml header boilerplate when appending to an existing kit.toml + if (line ~ /^# \.kit\.toml --/ || line ~ /^# Only the keys you set here/ \ + || line ~ /^# default at / || line ~ /^# Re-run `bash .*adopt\.sh/ \ + || line ~ /^# editing \[modules\]/ || line ~ /^# adopt reads \[modules\]/ \ + || line ~ /^# true, commit, and that quality gate/ || line ~ /^[[:space:]]*$/) next + } + if (!skip) print line + } + ' "$existing" "$src" > "$mig" || { rm -f "$mig"; return 1; } + cat "$existing" > "$dest" || { rm -f "$mig"; return 1; } + if [ -s "$mig" ]; then + # Ensure a blank line between existing kit.toml content and appended [dev.*] sections. + if [ -s "$dest" ]; then + [ -z "$(tail -c 1 "$dest")" ] || printf '\n' >> "$dest" + printf '\n' >> "$dest" + fi + cat "$mig" >> "$dest" || { rm -f "$mig"; return 1; } + fi + else + awk ' + function map_hdr(line, pre, br, name, tail, raw) { + sub(/\r$/, "", line) + raw = line + sub(/^[[:space:]]*/, "", raw) + pre = substr(line, 1, length(line) - length(raw)) + if (match(raw, /^\[\[[[:space:]]*[^]#]+[[:space:]]*\]\]/)) { + br = substr(raw, 1, RLENGTH) + tail = substr(raw, RLENGTH + 1) + name = br; sub(/^\[\[[[:space:]]*/, "", name); sub(/[[:space:]]*\]\]$/, "", name) + if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name + return pre "[[" name "]]" tail + } + if (match(raw, /^\[[[:space:]]*[^]#]+[[:space:]]*\]/)) { + br = substr(raw, 1, RLENGTH) + tail = substr(raw, RLENGTH + 1) + name = br; sub(/^\[[[:space:]]*/, "", name); sub(/[[:space:]]*\]$/, "", name) + if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name + return pre "[" name "]" tail + } + return line + } + { + line = $0; sub(/\r$/, "", line) + if (line ~ /^[[:space:]]*\[/) { print map_hdr(line); next } + print line + } + ' "$src" > "$dest" || { rm -f "$mig"; return 1; } + fi + rm -f "$mig" +} + if [ -n "$kit_root_toml" ] && [ "$RESOLVER_OK" -eq 1 ]; then - if [ ! -f "$dotkit" ]; then + if [ "$REFRESH" -eq 1 ] && [ -f "$dotkit" ]; then if [ "$DRY" -eq 1 ]; then - note "seed a starter .kit.toml (modules: ${WITH_ARG:-kit-root defaults})" + note "migrate .kit.toml into kit.toml under [dev.*] and remove .kit.toml" else - with_norm="" - [ -n "$WITH_ARG" ] && with_norm=" $(echo "$WITH_ARG" | tr ',' ' ' | xargs) " tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" - { - echo "# .kit.toml -- this PROJECT's override of the kit-root defaults." - echo "# Only the keys you set here matter; every key you omit inherits the kit-root" - echo "# default at $KIT_REF/kit.toml (lib/config/kit-config.sh: project keys WIN)." - echo "# Re-run \`bash $KIT_REF/lib/adopt.sh --refresh \` (or /kit:adopt) after" - echo "# editing [modules] to re-wire this project's .claude/settings.json to match --" - echo "# adopt reads [modules] at adopt time. [gate] is read when a hook fires: set a key to" - echo "# true, commit, and that quality gate is on for this project (false keeps it off)." - echo "" - echo "[modules]" - for m in $KIT_KNOWN_MODULES; do - if [ -n "$with_norm" ]; then - case "$with_norm" in *" $m "*) v=true ;; *) v=false ;; esac - else - v="$(KIT_CONFIG_ROOT="$(dirname "$kit_root_toml")" KIT_PROJECT_ROOT="$TARGET" kit_config_get "modules.$m" "false")" - fi - echo "$m = $v" - done - echo "" - echo "[gate] # quality gates. An adopted repo starts with proof_of_done and lane_gates ON (the kit root" - echo " # keeps them off for a raw install). The others are OPT-IN except board_row_gate and" - echo " # review_verdict (on by default). true turns a gate on for this repo, false keeps it off" - echo " # (a false counts once this file is committed). To turn one of the two seeded gates off," - echo " # set \`proof_of_done = false\` or \`lane_gates = false\` below and commit. The other values are" - echo " # what resolved at adopt time (operator ~/.config/dwarves-kit/kit.toml, else the kit default" - echo " # false); delete a line to follow the operator setting again. Detail: the installed kit's" - echo " # lib/gate/README.md, 'Turning a gate on'. Safety gates have no key." - echo " # proof_of_done ship-gate: a load-bearing diff needs a proof-of-done record (seeded true)" - echo " # lane_gates ship-gate: the lane x phase required gates + the no-Lane refusal (seeded true)" - echo " # understanding_gate Stop hook: blocks a stop that rationalizes unfinished work" - echo " # commit_format commit-subject lint (conventional type, <=72 chars)" - echo " # board_row_gate a commit adding a new board row needs a board-row-ok: line" - echo " # review_verdict ship-gate: a spec whose last ## Review verdict is DO NOT SHIP refuses the push (on by default)" - for g in $(bash "$SELF_DIR/gate/gate-policy.sh" keys 2>/dev/null); do - case "$g" in - # An adopted repo defaults these two ON. An operator overlay that names the key still - # wins; the kit root (which keeps them off for a raw install) is skipped. - proof_of_done|lane_gates) - v="$(KIT_CONFIG_ROOT=/nonexistent KIT_PROJECT_ROOT=/nonexistent kit_config_get "gate.$g" "true")" ;; - *) - v="$(KIT_CONFIG_ROOT="$(dirname "$kit_root_toml")" KIT_PROJECT_ROOT="$TARGET" kit_config_get "gate.$g" "false")" ;; - esac - echo "$g = $v" - done - } > "$tmp" - mv "$tmp" "$dotkit" + if _adopt_migrate_dotkit "$dotkit" "$kitfile" "$tmp"; then + if [ -f "$kitfile" ]; then keep_mode "$kitfile" "$tmp"; else chmod 0644 "$tmp"; fi + mv "$tmp" "$kitfile" + if git -C "$TARGET" rev-parse --git-dir >/dev/null 2>&1 \ + && git -C "$TARGET" ls-files --error-unmatch .kit.toml >/dev/null 2>&1; then + git -C "$TARGET" rm -f -q .kit.toml >/dev/null 2>&1 || rm -f "$dotkit" + else + rm -f "$dotkit" + fi + echo "adopt: migrated .kit.toml into kit.toml under [dev.*] and removed .kit.toml" + else + rm -f "$tmp" + echo "adopt: failed to migrate $dotkit into $kitfile" >&2 + exit 1 + fi + fi + did=1 + elif [ ! -f "$kitfile" ] && [ ! -f "$dotkit" ]; then + if [ "$DRY" -eq 1 ]; then + note "seed a starter kit.toml (modules: ${WITH_ARG:-kit-root defaults})" + else + tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" + _adopt_render_dev_sections > "$tmp" + chmod 0644 "$tmp" + mv "$tmp" "$kitfile" + fi + did=1 + elif [ -f "$kitfile" ] && [ ! -f "$dotkit" ] && ! _adopt_has_dev_sections "$kitfile"; then + if [ "$DRY" -eq 1 ]; then + note "append [dev.modules] and [dev.gate] to existing kit.toml (modules: ${WITH_ARG:-kit-root defaults})" + else + tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" + cat "$kitfile" > "$tmp" + if [ -s "$tmp" ]; then + [ -z "$(tail -c 1 "$tmp")" ] || printf '\n' >> "$tmp" + printf '\n' >> "$tmp" + fi + _adopt_render_dev_sections >> "$tmp" + keep_mode "$kitfile" "$tmp" + mv "$tmp" "$kitfile" fi did=1 elif [ -n "$WITH_ARG" ]; then - echo "adopt: note: $dotkit already exists; --with ignored (edit the file's [modules] section directly)" >&2 + existing_cfg="$kitfile"; _adopt_has_dev_sections "$kitfile" || existing_cfg="$dotkit" + echo "adopt: note: $existing_cfg already exists; --with ignored (edit the file's [dev.modules] section directly)" >&2 fi fi diff --git a/lib/adopt/README.md b/lib/adopt/README.md index f44277e4c..1152e2450 100644 --- a/lib/adopt/README.md +++ b/lib/adopt/README.md @@ -1,6 +1,6 @@ # adopt -Adopts a repo into the kit's operate-contract. It injects a small `AGENTS.md` pointer, a proof marker, and a `CLAUDE.md` loader (none when the repo sets `[adopt] agents_only = true`), so an agent classifies its work and the ship gate engages. It never copies the engine into the target and never overwrites a repo's own `AGENTS.md`. +Adopts a repo into the kit's operate-contract. It injects a small `AGENTS.md` pointer, a proof marker, a starter `kit.toml` (`[dev.*]`), and a `CLAUDE.md` loader (none when the repo sets `[dev.adopt] agents_only = true`), so an agent classifies its work and the ship gate engages. It never copies the engine into the target and never overwrites a repo's own `AGENTS.md` or `[repo]` section in `kit.toml`. **Entry points** - `lib/adopt.sh [--check | --dry-run | --refresh [--swap-agents]] [--single-source | --no-single-source] [--with ] `: the `/kit:adopt` driver. It sits at the lib root, outside this directory. `--check` reports status and writes nothing. `--refresh` re-syncs the kit-managed pieces. diff --git a/lib/bench/dashboard.py b/lib/bench/dashboard.py index c1a605acc..b550fe6c8 100644 --- a/lib/bench/dashboard.py +++ b/lib/bench/dashboard.py @@ -2049,13 +2049,19 @@ def observe_config(key, cli_value=None): if key == "push_url": xdg = os.environ.get("XDG_CONFIG_HOME") or str(Path.home() / ".config") op_dir = os.environ.get("KIT_CONFIG_OPERATOR") or os.path.join(xdg, "dwarves-kit") - sources = (Path(op_dir) / "kit.toml", kit_root) + sources = ((Path(op_dir) / "kit.toml", False), (kit_root, False)) else: - sources = (Path.cwd() / ".kit.toml", kit_root) - for p in sources: + sources = ((Path.cwd() / "kit.toml", True), (Path.cwd() / ".kit.toml", False), (kit_root, False)) + for p, dev_prefix in sources: if not os.path.lexists(p): continue try: - obs = tomllib.loads(p.read_text()).get("observe", {}) + data = tomllib.loads(p.read_text()) + if dev_prefix: + dev_tbl = data.get("dev", {}) + if not isinstance(dev_tbl, dict): raise ValueError("invalid [dev]") + obs = dev_tbl.get("observe", {}) + else: + obs = data.get("observe", {}) if not isinstance(obs, dict): raise ValueError("invalid [observe]") if key in obs and (key == "repos" or obs[key]): return None if (key == "repos" and p == kit_root and obs[key] == "") else obs[key] diff --git a/lib/classify/lane-classify.sh b/lib/classify/lane-classify.sh index 14468cf0a..8faaf8fb6 100755 --- a/lib/classify/lane-classify.sh +++ b/lib/classify/lane-classify.sh @@ -116,7 +116,7 @@ _HP_auth='(^|/)(auth(entication|orization|orisation|n|z|[_-][a-z_-]*)?|oauth|rba _HP_secret='(^|/)\.env(\.(local|dev|development|prod|production|staging|test))?$|(^|/)secrets?/|\.(pem|key|p12|pfx)$|(^|/)[^/]*credentials?[^/]*$' _HP_ci='(^|/)\.github/' _HP_infra='(^|/)Dockerfile[^/]*$|(^|/)[^/]*(iam|role|polic)[^/]*\.tf$|(^|/)(iam|policies)/[^/]*\.tf$' -_HP_kitconfig='(^|/)\.kit\.toml$' +_HP_kitconfig='(^|/)\.?kit\.toml$' # Test paths never count as kind `auth` (every other kind still matches them). Fixed, case-sensitive, # not configurable: a config hook here would be a second, unreviewed exemption path. # The data-loss sqli carve-out keeps its own _HL_sqli_testpath below; neither list feeds the other. @@ -165,7 +165,7 @@ _load_exempt() { [ "$_EXEMPT_LOADED" = 1 ] && return 0 _EXEMPT_LOADED=1 local top base recs - top="$(git -C "$(dirname "$(kit_config_project)")" rev-parse --show-toplevel 2>/dev/null)" || return 0 + top="$(git -C "$(kit_config_project_dir)" rev-parse --show-toplevel 2>/dev/null)" || return 0 base="$(git -C "$top" merge-base HEAD "$(_deesc_default_branch "$top")" 2>/dev/null)" || return 0 [ -n "$base" ] || return 0 recs="$(lane_hard_path_exempt "$top" "$base" 2>/dev/null)" @@ -1074,6 +1074,14 @@ _floor_scan() { lane_hard_path_exempt "$root" "${KIT_FLOOR_CONFIG_AT:-$base}" > "$tmp/recs" || true # KIT_FLOOR_CONFIG_AT: the mega gate reads config at the base-branch tip, not the PR-chosen base # A secret-shaped path is never a doc, whatever its extension or directory. grep -Ein -e "$(_hp_re secret)" "$tmp/paths" 2>/dev/null | cut -d: -f1 >> "$tmp/nosoft" || true + # Exact doc-named door_paths entries (e.g. SECURITY.md) stay floor-eligible (never blanked as generic docs). + local _dlist; _dlist="$(lane_door_hard_paths)" + if [ -n "$_dlist" ]; then + printf '%s\n' "$_dlist" | grep -E '\\\.(md|markdown)\(/\|\$\)$' > "$tmp/doormd" 2>/dev/null || true + if [ -s "$tmp/doormd" ]; then + grep -Ein -f "$tmp/doormd" "$tmp/paths" 2>/dev/null | cut -d: -f1 >> "$tmp/nosoft" || true + fi + fi # The unblanked list, for the added-workflow rule: a doc or a comment-only file beside the workflow still counts. cp "$tmp/paths" "$tmp/paths.all" # Docs never trip a hard path: blank them (line numbers stay valid) before any pattern runs. diff --git a/lib/config/README.md b/lib/config/README.md index ca98b1d69..10cb2ebfa 100644 --- a/lib/config/README.md +++ b/lib/config/README.md @@ -4,7 +4,7 @@ The kit's configuration layer. One resolver reads layered `kit.toml` values, one **Entry points** - `bin/config {list|get|explain|seams|data}` forwards to `lib/config/config.sh`. `list` shows every declared knob, `get ` prints the resolved value, `explain ` shows the env, project, kit-root and default chain, `seams [--check]` reports cross-kit seams. -- `lib/config/kit-config.sh`: source it for `kit_config_get [default]`, `kit_config_root`, `kit_config_operator` and `kit_config_project`. Project beats operator beats kit-root beats default. It is the only reader of TOML. +- `lib/config/kit-config.sh`: source it for `kit_config_get [default]`, `kit_config_root`, `kit_config_operator` and `kit_config_project`. Project (`kit.toml` `[dev.*]` > legacy `.kit.toml` `[*]`) beats operator beats kit-root beats default. It is the only reader of TOML. - `lib/config/merge-command.sh`: source it for `kit_merge_command []`, `kit_merge_command_slug`, `kit_merge_exec` and `kit_merge_verify`, the project's own PR merge command (`[merge] command`) that `wrap land`, `wrap merge`, `mega-merge` and `stack-merge` run in place of the plain squash. Tests: `tests/test-merge-command.sh`. - `lib/config/modules.sh`: source it for `kit_modules_known`, `kit_modules_core`, `kit_module_default`, `kit_module_hooks`, `kit_module_hook_events` and `kit_module_clis`. - `lib/config/hook-module.sh off `: exit 0 when the hook's module is switched off. `hooks/anchor-root.sh` calls it before every non-spine hook. diff --git a/lib/config/config.sh b/lib/config/config.sh index 4d70e8298..4411166e6 100755 --- a/lib/config/config.sh +++ b/lib/config/config.sh @@ -215,19 +215,30 @@ _resolve() { ENV_SET=1; ENV_VAL="$ev" fi - PROJ_VAL=""; PROJ_SET=0; OP_VAL=""; OP_SET=0; ROOT_VAL=""; ROOT_SET=0 + PROJ_VAL=""; PROJ_SET=0; PROJ_FILE=""; PROJ_LABEL="project kit.toml"; OP_VAL=""; OP_SET=0; ROOT_VAL=""; ROOT_SET=0 IS_ROOT_ONLY=0 if [ "$tomlkey" != "env-only" ] && [ "$tomlkey" != "-" ]; then - section="${tomlkey%%.*}"; key="${tomlkey#*.}" - # Root-only keys never consult the project layer: a project .kit.toml rides inside an + section="${tomlkey%.*}"; key="${tomlkey##*.}" + # Root-only keys never consult the project layer: a project config rides inside an # untrusted PR, and a row like understand.teach names code a command runs. Same fence # kit_config_get_root applies; kit_config_get_root's own layer order (operator, then # kit-root) is what this branch reproduces for a root-only row. if _is_root_only "$row"; then IS_ROOT_ONLY=1 else - PROJ_VAL="$(_kit_toml_get "$(kit_config_project)" "$section" "$key")" - [ -n "$PROJ_VAL" ] && PROJ_SET=1 + local pf_hit + pf_hit="$(_kit_project_get_with_file "$(kit_config_project_dir)" "$section" "$key")" + if [ -n "$pf_hit" ]; then + PROJ_FILE="${pf_hit%%$'\t'*}" + PROJ_VAL="${pf_hit#*$'\t'}" + PROJ_SET=1 + fi + fi + if [ -n "$PROJ_FILE" ]; then + PROJ_LABEL="project $(basename "$PROJ_FILE")" + else + PROJ_FILE="$(kit_config_project)" + PROJ_LABEL="project $(basename "$PROJ_FILE")" fi OP_VAL="$(_kit_toml_get "$(kit_config_operator)" "$section" "$key")" [ -n "$OP_VAL" ] && OP_SET=1 @@ -236,7 +247,7 @@ _resolve() { fi if [ "$ENV_SET" = 1 ]; then EFFECTIVE="$ENV_VAL"; PROVENANCE="env" - elif [ "$PROJ_SET" = 1 ]; then EFFECTIVE="$PROJ_VAL"; PROVENANCE="project .kit.toml" + elif [ "$PROJ_SET" = 1 ]; then EFFECTIVE="$PROJ_VAL"; PROVENANCE="$PROJ_LABEL" elif [ "$OP_SET" = 1 ]; then EFFECTIVE="$OP_VAL"; PROVENANCE="operator kit.toml" elif [ "$ROOT_SET" = 1 ]; then EFFECTIVE="$ROOT_VAL"; PROVENANCE="kit-root kit.toml" else EFFECTIVE="$defaultval"; PROVENANCE="default" @@ -452,15 +463,15 @@ cmd_explain() { if [ "$tomlkey" != "env-only" ] && [ "$tomlkey" != "-" ]; then if [ "$IS_ROOT_ONLY" = 1 ]; then - printf ' 2. project .kit.toml %-19s (not read: root-only key)\n' "[$tomlkey]" - elif [ "$PROJ_SET" = 1 ]; then printf ' 2. project .kit.toml %-19s = %s [%s]\n' "[$tomlkey]" "$PROJ_VAL" "$(kit_config_project)" - else printf ' 2. project .kit.toml %-19s = (unset) [%s]\n' "[$tomlkey]" "$(kit_config_project)"; fi + printf ' 2. %-17s %-19s (not read: root-only key)\n' "$PROJ_LABEL" "[$tomlkey]" + elif [ "$PROJ_SET" = 1 ]; then printf ' 2. %-17s %-19s = %s [%s]\n' "$PROJ_LABEL" "[$tomlkey]" "$PROJ_VAL" "$PROJ_FILE" + else printf ' 2. %-17s %-19s = (unset) [%s]\n' "$PROJ_LABEL" "[$tomlkey]" "$PROJ_FILE"; fi if [ "$OP_SET" = 1 ]; then printf ' 3. operator kit.toml %-19s = %s [%s]\n' "[$tomlkey]" "$OP_VAL" "$(kit_config_operator)" else printf ' 3. operator kit.toml %-19s = (unset) [%s]\n' "[$tomlkey]" "$(kit_config_operator)"; fi if [ "$ROOT_SET" = 1 ]; then printf ' 4. kit-root kit.toml %-19s = %s [%s]\n' "[$tomlkey]" "$ROOT_VAL" "$(kit_config_root)" else printf ' 4. kit-root kit.toml %-19s = (unset) [%s]\n' "[$tomlkey]" "$(kit_config_root)"; fi else - printf ' 2. project .kit.toml n/a (this key has no kit.toml backing: %s)\n' "$tomlkey" + printf ' 2. project kit.toml n/a (this key has no kit.toml backing: %s)\n' "$tomlkey" printf ' 3. operator kit.toml n/a (this key has no kit.toml backing: %s)\n' "$tomlkey" printf ' 4. kit-root kit.toml n/a (this key has no kit.toml backing: %s)\n' "$tomlkey" fi diff --git a/lib/config/hook-module.sh b/lib/config/hook-module.sh index 28dd0afdc..3fcf93bc7 100644 --- a/lib/config/hook-module.sh +++ b/lib/config/hook-module.sh @@ -27,14 +27,15 @@ _tsv="${KIT_MODULES_FILE:-${0%/*}/modules.tsv}" [ -f "$_tsv" ] || exit 1 _files=("$_tsv"); _layers="t" -for _l in "p:${KIT_PROJECT_ROOT:-$PWD}/.kit.toml" \ +for _l in "k:${KIT_PROJECT_ROOT:-$PWD}/kit.toml" \ + "p:${KIT_PROJECT_ROOT:-$PWD}/.kit.toml" \ "o:${KIT_CONFIG_OPERATOR:-${XDG_CONFIG_HOME:-$HOME/.config}/dwarves-kit}/kit.toml" \ "r:${KIT_CONFIG_ROOT:-${DWARVES_KIT:-$HOME/.claude/dwarves-kit}}/kit.toml"; do [ -s "${_l#*:}" ] && { _files+=("${_l#*:}"); _layers="$_layers ${_l%%:*}"; } done [ "$(awk -F'\t' -v hook="$2" -v layers="$_layers" ' BEGIN { split(layers, L, " ") } - FNR == 1 { n++ } + FNR == 1 { n++; insec = 0 } L[n] == "t" { if ($0 ~ /^#/ || NF < 4 || mod != "") next c = split($3, t, " ") @@ -43,13 +44,13 @@ done } mod == "" { next } { line = $0; sub(/#.*/, "", line); gsub(/[ \t\r]/, "", line) } - line ~ /^\[/ { insec = (line == "[modules]"); next } + line ~ /^\[/ { insec = (L[n] == "k" ? (line == "[dev.modules]") : (line == "[modules]")); next } insec && index(line, mod "=") == 1 && !(L[n] in val) { v = substr(line, length(mod) + 2); gsub(/"/, "", v) if (v == "true" || v == "false") val[L[n]] = v } END { if (mod == "" || mod == "spine") exit - r = ("p" in val) ? val["p"] : ("o" in val) ? val["o"] : ("r" in val) ? val["r"] : (def == "core" ? "true" : "false") + r = ("k" in val) ? val["k"] : ("p" in val) ? val["p"] : ("o" in val) ? val["o"] : ("r" in val) ? val["r"] : (def == "core" ? "true" : "false") if (r == "false") print "off" }' "${_files[@]}" 2>/dev/null)" = off ] diff --git a/lib/config/kit-config.sh b/lib/config/kit-config.sh index ffeeca1f6..c73bfdc2c 100755 --- a/lib/config/kit-config.sh +++ b/lib/config/kit-config.sh @@ -28,9 +28,21 @@ [ -n "${_KIT_CONFIG_SOURCED:-}" ] && return 0 2>/dev/null || true _KIT_CONFIG_SOURCED=1 -kit_config_root() { printf '%s' "${KIT_CONFIG_ROOT:-${DWARVES_KIT:-$HOME/.claude/dwarves-kit}}/kit.toml"; } -kit_config_operator() { printf '%s' "${KIT_CONFIG_OPERATOR:-${XDG_CONFIG_HOME:-$HOME/.config}/dwarves-kit}/kit.toml"; } -kit_config_project() { printf '%s' "${KIT_PROJECT_ROOT:-$PWD}/.kit.toml"; } +kit_config_root() { printf '%s' "${KIT_CONFIG_ROOT:-${DWARVES_KIT:-$HOME/.claude/dwarves-kit}}/kit.toml"; } +kit_config_operator() { printf '%s' "${KIT_CONFIG_OPERATOR:-${XDG_CONFIG_HOME:-$HOME/.config}/dwarves-kit}/kit.toml"; } +kit_config_project_dir() { printf '%s' "${KIT_PROJECT_ROOT:-$PWD}"; } +kit_config_project_kit() { printf '%s/kit.toml' "$(kit_config_project_dir)"; } +kit_config_project_legacy() { printf '%s/.kit.toml' "$(kit_config_project_dir)"; } +kit_config_project() { + local d; d="$(kit_config_project_dir)" + if [ -f "$d/kit.toml" ] && grep -qE '^[[:space:]]*\[+[[:space:]]*dev(\.|])' "$d/kit.toml" 2>/dev/null; then + printf '%s/kit.toml' "$d" + elif [ -f "$d/.kit.toml" ]; then + printf '%s/.kit.toml' "$d" + else + printf '%s/kit.toml' "$d" + fi +} # _kit_toml_get
-- print the raw value of [section].key, empty if absent. # Line-oriented, no TOML lib (matches install.sh's grep/sed style). Handles: [section] @@ -40,7 +52,7 @@ _kit_toml_get() { local file="$1" section="$2" key="$3" [ -f "$file" ] || return 0 awk -v sec="$section" -v k="$key" ' - { line = $0 } + { line = $0; sub(/\r$/, "", line) } line ~ /^[[:space:]]*#/ { next } # full-line comment line ~ /^[[:space:]]*\[/ { # section header h = line; sub(/#.*/, "", h); gsub(/[][[:space:]]/, "", h) @@ -58,13 +70,99 @@ _kit_toml_get() { ' "$file" } -# kit_config_get [default] -- project override, else operator, else kit-root, -# else default. The dotted key splits at the LAST dot: `lane.normal.phases` reads section -# `lane.normal`, key `phases`. A missing file at any layer is skipped silently. +# _kit_toml_get_array
-- print each string element of a single-line or +# multi-line TOML string array `key = ["a", "b"]` under [section], one element per line. +# Returns 0 when was declared in
(even if the array is empty `[]`), 1 when absent +# or file missing. When
is empty (""), matches top-level (before any header) or [repo]. +_kit_toml_get_array() { + local file="$1" section="$2" key="$3" + [ -f "$file" ] || return 1 + awk -v sec="$section" -v k="$key" ' + function sec_ok(c) { return (sec == "") ? (c == "" || c == "repo") : (c == sec) } + BEGIN { cur = ""; found = 0; collect = 0; in_arr = 0 } + { + line = $0; sub(/\r$/, "", line) + if (!collect) { + if (line ~ /^[[:space:]]*#/ || line ~ /^[[:space:]]*$/) next + if (line ~ /^[[:space:]]*\[/) { + h = line; sub(/#.*/, "", h); gsub(/[][[:space:]]/, "", h) + cur = h; next + } + if (sec_ok(cur) && line ~ ("^[[:space:]]*" k "[[:space:]]*=")) { + found = 1; collect = 1 + sub(/^[^=]*=/, "", line) + } else { + next + } + } + n = length(line); i = 1 + while (i <= n) { + c = substr(line, i, 1) + if (c == " " || c == "\t" || c == ",") { i++; continue } + if (c == "#") break + if (!in_arr) { + if (c == "[") { in_arr = 1; i++; continue } + # Not an array literal: stop without emitting elements. + collect = 0; exit 0 + } + if (c == "]") { collect = 0; exit 0 } + if (c == "\"") { + s = ""; i++ + while (i <= n) { + d = substr(line, i, 1) + if (d == "\\" && i < n) { + nx = substr(line, i + 1, 1) + s = s nx; i += 2; continue + } + if (d == "\"") { i++; break } + s = s d; i++ + } + print s; continue + } + if (c == "\047") { + s = ""; i++ + while (i <= n) { + d = substr(line, i, 1) + if (d == "\047") { i++; break } + s = s d; i++ + } + print s; continue + } + i++ + } + } + END { exit (found ? 0 : 1) } + ' "$file" +} + +# _kit_project_get_with_file
-- prints "" for the winning +# project config file: /kit.toml [dev.
] wins over /.kit.toml [
]. +# Unprefixed [
] in /kit.toml is deliberately NOT read as a project override, because +# devkit own kit-root kit.toml uses unprefixed sections (and [repo] belongs to repokit). +_kit_project_get_with_file() { + local dir="$1" section="$2" key="$3" v + v="$(_kit_toml_get "$dir/kit.toml" "dev.$section" "$key")" + if [ -n "$v" ]; then printf '%s\t%s' "$dir/kit.toml" "$v"; return 0; fi + v="$(_kit_toml_get "$dir/.kit.toml" "$section" "$key")" + if [ -n "$v" ]; then printf '%s\t%s' "$dir/.kit.toml" "$v"; return 0; fi +} + +# _kit_project_get
-- winning project-layer value only. +_kit_project_get() { + local dir="$1" section="$2" key="$3" v + v="$(_kit_toml_get "$dir/kit.toml" "dev.$section" "$key")" + [ -n "$v" ] && { printf '%s' "$v"; return 0; } + _kit_toml_get "$dir/.kit.toml" "$section" "$key" +} + +# kit_config_get [default] -- project override (kit.toml [dev.*] > .kit.toml [*]), +# else operator, else kit-root, else default. The dotted key splits at the LAST dot: +# `lane.normal.phases` reads section `lane.normal` (`dev.lane.normal` in project kit.toml), +# key `phases`. A missing file at any layer is skipped silently. kit_config_get() { local dotkey="$1" def="${2:-}" section key v section="${dotkey%.*}"; key="${dotkey##*.}" - v="$(_kit_toml_get "$(kit_config_project)" "$section" "$key")" + v="$(_kit_project_get "$(kit_config_project_dir)" "$section" "$key")" [ -n "$v" ] && { printf '%s' "$v"; return 0; } v="$(_kit_toml_get "$(kit_config_operator)" "$section" "$key")" [ -n "$v" ] && { printf '%s' "$v"; return 0; } @@ -74,7 +172,7 @@ kit_config_get() { } # kit_config_get_root [default] -- operator, else kit-root, else default. The -# project overlay is SKIPPED. For security-bearing keys a committed project .kit.toml must +# project overlay is SKIPPED. For security-bearing keys a committed project config must # NOT be able to set: a project toml rides inside an untrusted PR, so a key that selects a # runner host, a secret ref, or a dispatch target must resolve from an operator-owned file # alone. Same read-model the kit already applies to enabled_agent_clis. The operator file @@ -100,19 +198,47 @@ kit_config_tracked_clean() { && git -C "$d" diff --quiet HEAD -- "$b" 2>/dev/null } -# kit_config_show_at -- the committed .kit.toml at on stdout; empty when the -# file is absent there. A copy at a base is committed by definition. -kit_config_show_at() { git -C "$1" show "$2:.kit.toml" 2>/dev/null; } +# kit_config_show_kit_at -- committed kit.toml at , else empty. +# kit_config_show_legacy_at -- committed .kit.toml at , else empty. +# kit_config_show_at -- committed kit.toml if it holds any [dev*] section, +# else committed .kit.toml. +kit_config_show_kit_at() { git -C "$1" show "$2:kit.toml" 2>/dev/null; } +kit_config_show_legacy_at() { git -C "$1" show "$2:.kit.toml" 2>/dev/null; } +kit_config_show_at() { + local out + if out="$(git -C "$1" show "$2:kit.toml" 2>/dev/null)" \ + && printf '%s\n' "$out" | grep -qE '^[[:space:]]*\[+[[:space:]]*dev(\.|])'; then + printf '%s\n' "$out" + return 0 + fi + git -C "$1" show "$2:.kit.toml" 2>/dev/null +} -# kit_config_get_at [default] -- the value committed in .kit.toml at , -# else operator, else kit-root, else default. The working tree and the project overlay are never read, -# so a node branch cannot change what a gate reads from the base. -kit_config_get_at() { - local repo="$1" rev="$2" dotkey="$3" def="${4:-}" tmp v - tmp="$(mktemp "${TMPDIR:-/tmp}/kit-cfg-at.XXXXXX")" || { kit_config_get_root "$dotkey" "$def"; return 0; } - kit_config_show_at "$repo" "$rev" >| "$tmp" - v="$(_kit_toml_get "$tmp" "${dotkey%.*}" "${dotkey##*.}")" +# _kit_project_get_at
-- committed project lookup at : +# kit.toml [dev.
] wins over .kit.toml [
]. +_kit_project_get_at() { + local repo="$1" rev="$2" section="$3" key="$4" tmp v="" + tmp="$(mktemp "${TMPDIR:-/tmp}/kit-cfg-at.XXXXXX")" || return 0 + if kit_config_show_kit_at "$repo" "$rev" >| "$tmp" 2>/dev/null && [ -s "$tmp" ]; then + v="$(_kit_toml_get "$tmp" "dev.$section" "$key")" + fi + if [ -z "$v" ]; then + if kit_config_show_legacy_at "$repo" "$rev" >| "$tmp" 2>/dev/null && [ -s "$tmp" ]; then + v="$(_kit_toml_get "$tmp" "$section" "$key")" + fi + fi rm -f "$tmp" + [ -n "$v" ] && printf '%s' "$v" + return 0 +} + +# kit_config_get_at [default] -- the value committed in +# kit.toml [dev.*] or .kit.toml [*] at , else operator, else kit-root, else default. +# The working tree and the project overlay are never read, so a node branch cannot change +# what a gate reads from the base. +kit_config_get_at() { + local repo="$1" rev="$2" dotkey="$3" def="${4:-}" v + v="$(_kit_project_get_at "$repo" "$rev" "${dotkey%.*}" "${dotkey##*.}")" [ -n "$v" ] && { printf '%s' "$v"; return 0; } kit_config_get_root "$dotkey" "$def" } @@ -194,5 +320,81 @@ TOML "$(KIT_CONFIG_OPERATOR="$d/op" kit_config_get_root knowledge.root)" "/tmp/op" chk "root-only knowledge.root: empty with no operator/kit-root value, even though project sets it" \ "$(kit_config_get_root knowledge.root)" "" + + # Unified kit.toml ([dev.*]) precedence over legacy .kit.toml ([*]), plus [repo] isolation. + mkdir -p "$d/unified" "$d/both" "$d/unprefixed" + cat > "$d/unified/kit.toml" <<'TOML' +[repo] +profile = "public-app" +door_paths = [ + "deploy/macos/firewall.sh", # inline comment + "internal/ghauth/", + # full-line comment + 'SECURITY.md', +] + +[dev.ledger] +location = "from-kit-toml" + +[dev.lane.normal] +phases = ["spec", "build"] +TOML + cat > "$d/both/kit.toml" <<'TOML' +[repo] +door_paths = ["a/"] + +[dev.ledger] +location = "kit-toml-wins" +TOML + cat > "$d/both/.kit.toml" <<'TOML' +[ledger] +location = "legacy-loses" +[mega] +wave_cap = 7 +TOML + cat > "$d/unprefixed/kit.toml" <<'TOML' +[mega] +wave_cap = 99 +TOML + chk "unified kit.toml [dev.*] reads value" \ + "$(KIT_PROJECT_ROOT="$d/unified" kit_config_get ledger.location)" "from-kit-toml" + chk "unified kit.toml [dev.lane.normal] nested section" \ + "$(KIT_PROJECT_ROOT="$d/unified" kit_config_get lane.normal.phases)" '["spec", "build"]' + chk "kit.toml [dev.*] wins over .kit.toml [*]" \ + "$(KIT_PROJECT_ROOT="$d/both" kit_config_get ledger.location)" "kit-toml-wins" + chk ".kit.toml fallback when kit.toml omits that [dev.*] key" \ + "$(KIT_PROJECT_ROOT="$d/both" kit_config_get mega.wave_cap)" "7" + chk "unprefixed [mega] in project kit.toml does not shadow operator" \ + "$(KIT_PROJECT_ROOT="$d/unprefixed" KIT_CONFIG_OPERATOR="$d/op" kit_config_get mega.wave_cap)" "9" + chk "kit_config_project returns kit.toml when [dev.*] present" \ + "$(KIT_PROJECT_ROOT="$d/both" kit_config_project)" "$d/both/kit.toml" + chk "kit_config_project returns .kit.toml when only legacy present" \ + "$(KIT_PROJECT_ROOT="$d/proj" kit_config_project)" "$d/proj/.kit.toml" + + # _kit_toml_get_array: multi-line, single-line, empty, and missing. + arr_out="$(_kit_toml_get_array "$d/unified/kit.toml" repo door_paths | paste -sd',' -)" + chk "_kit_toml_get_array multi-line + comments + single quotes" \ + "$arr_out" "deploy/macos/firewall.sh,internal/ghauth/,SECURITY.md" + printf 'door_paths = ["hooks/", "install.sh"] # trailing\n' > "$d/repokit.toml" + chk "_kit_toml_get_array top-level single-line" \ + "$(_kit_toml_get_array "$d/repokit.toml" "" door_paths | paste -sd',' -)" "hooks/,install.sh" + printf '[repo]\ndoor_paths = []\n' > "$d/empty-arr.toml" + rc_empty=0; _kit_toml_get_array "$d/empty-arr.toml" repo door_paths >/dev/null || rc_empty=$? + rc_miss=0; _kit_toml_get_array "$d/both/kit.toml" dev.ledger nonexistent >/dev/null || rc_miss=$? + chk "_kit_toml_get_array empty array returns exit 0" "$rc_empty" "0" + chk "_kit_toml_get_array missing key returns exit 1" "$rc_miss" "1" + + # kit_config_get_at: committed kit.toml [dev.*] wins over committed .kit.toml. + mkdir -p "$d/gitrepo" + git -C "$d/gitrepo" init -q + printf '[ledger]\nlocation = "legacy-commit"\n[mega]\nwave_cap = 6\n' > "$d/gitrepo/.kit.toml" + printf '[dev.ledger]\nlocation = "unified-commit"\n' > "$d/gitrepo/kit.toml" + git -C "$d/gitrepo" add -A + git -C "$d/gitrepo" -c user.email=t@users.noreply.github.com -c user.name=t commit -qm init + chk "kit_config_get_at: kit.toml [dev.*] wins over .kit.toml" \ + "$(kit_config_get_at "$d/gitrepo" HEAD ledger.location)" "unified-commit" + chk "kit_config_get_at: falls back to .kit.toml when key absent in kit.toml" \ + "$(kit_config_get_at "$d/gitrepo" HEAD mega.wave_cap)" "6" + [ "$fail" = 0 ] && echo "PASS kit-config selftest" || { echo "SELFTEST FAILED"; exit 1; } fi diff --git a/lib/config/merge-command.sh b/lib/config/merge-command.sh index f54e04cbc..466365f0f 100644 --- a/lib/config/merge-command.sh +++ b/lib/config/merge-command.sh @@ -92,46 +92,59 @@ _kit_mc_base_ref() { printf '%s' "$ref" } -# _kit_mc_shape -- exit 0 when the file names `merge` only in the one shape the reader -# reads (or not at all), 1 otherwise. It looks at the raw lines, because the reader returns empty -# for the forms it cannot parse and empty would read as "unset". +# _kit_mc_shape [
] -- exit 0 when the file names
(default `merge`; +# `dev.merge` for unified project kit.toml) only in the one shape the reader reads (or not at all), +# 1 otherwise. It looks at the raw lines, because the reader returns empty for the forms it cannot +# parse and empty would read as "unset". _kit_mc_shape() { - [ -s "$1" ] || return 0 - awk -v q="'" ' + local f="$1" sec="${2:-merge}" + [ -s "$f" ] || return 0 + awk -v q="'" -v sec="$sec" ' function bad() { exit 1 } # key text with leading blanks and one layer of quotes around the first word removed function firstword(k, w) { w = k; sub(/[ \t]*[.=].*$/, "", w); gsub(/"/, "", w); gsub(q, "", w); return w } + function lhs_norm(k, w) { w = k; sub(/[ \t]*=.*$/, "", w); gsub(/[ \t]/, "", w); gsub(/"/, "", w); gsub(q, "", w); return w } /^[ \t]*#/ { next } { line = $0 h = line; sub(/[ \t]+#.*$/, "", h); gsub(/[ \t\r]/, "", h); gsub(/"/, "", h); gsub(q, "", h) } h ~ /^\[/ { - if (h ~ /^\[\[merge/) bad() - if (h == "[merge]") { if (seen++) bad(); insec = 1; ncmd = 0; next } - if (h ~ /^\[merge\./) bad() + if (h == "[[" sec "]]" || index(h, "[[" sec ".") == 1) bad() + if (h == "[" sec "]") { if (seen++) bad(); insec = 1; ncmd = 0; next } + if (index(h, "[" sec ".") == 1) bad() insec = 0; next } { k = line; sub(/^[ \t]+/, "", k) - if (!insec) { if (firstword(k) == "merge" && k ~ /[.=]/) bad(); next } + if (!insec) { + if (sec == "merge") { + if (firstword(k) == "merge" && k ~ /[.=]/) bad() + } else if (index(k, "=")) { + lh = lhs_norm(k) + if (lh == sec || index(lh, sec ".") == 1) bad() + } + next + } if (firstword(k) == "command" && k ~ /[.=]/) { if (++ncmd > 1) bad() sub(/\r$/, "", line) if (line !~ /^[ \t]*command[ \t]*=[ \t]*"[^"\\#]*"[ \t]*(#.*)?$/) bad() } } - ' "$1" + ' "$f" } -# _kit_mc_resolve -- project value, else operator, else kit-root. Exit 0 and -# the value, 1 nothing set, 2 a file names `merge` in a shape the reader cannot read. +# _kit_mc_resolve -- project kit.toml [dev.merge], +# else project .kit.toml [merge], else operator kit.toml [merge], else kit-root [merge]. +# Exit 0 and the value, 1 nothing set, 2 a file names the merge section in an unreadable shape. _kit_mc_resolve() { - local f v - for f in "$1" "$(kit_config_operator)" "$(kit_config_root)"; do + local pkit="$1" pleg="${2:-/nonexistent}" f sec v + for pair in "dev.merge:$pkit" "merge:$pleg" "merge:$(kit_config_operator)" "merge:$(kit_config_root)"; do + sec="${pair%%:*}"; f="${pair#*:}" [ -s "$f" ] || continue - _kit_mc_shape "$f" || { echo "merge command: $f names [merge] in a form the kit cannot read (use a plain [merge] table with command = \"...\", no # or backslash in the value); refusing to merge" >&2; return 2; } - v="$(_kit_toml_get "$f" merge command)" + _kit_mc_shape "$f" "$sec" || { echo "merge command: $f names [$sec] in a form the kit cannot read (use a plain [$sec] table with command = \"...\", no # or backslash in the value); refusing to merge" >&2; return 2; } + v="$(_kit_toml_get "$f" "$sec" command)" [ -z "$v" ] || { printf '%s' "$v"; return 0; } done return 1 @@ -159,54 +172,65 @@ _kit_mc_finish() { } kit_merge_command() { - local repo="${1:-}" def="${2:-}" ref tmp v r + local repo="${1:-}" def="${2:-}" ref tmpk tmpl v r [ -n "$repo" ] && [ -d "$repo" ] || { echo "merge command: no repo dir to read the project merge command from; refusing to merge" >&2; return 2; } - tmp="$(mktemp "${TMPDIR:-/tmp}/kit-merge-cmd.XXXXXX")" || return 2 + tmpk="$(mktemp "${TMPDIR:-/tmp}/kit-merge-cmd.XXXXXX")" || return 2 + tmpl="$(mktemp "${TMPDIR:-/tmp}/kit-merge-cmd.XXXXXX")" || { rm -f "$tmpk"; return 2; } if ref="$(_kit_mc_base_ref "$repo" "$def")"; then # ls-tree separates "the file is not there" (exit 0, no line) from a real read failure. - if ! v="$(_kit_mc_git -C "$repo" ls-tree --name-only "$ref" -- .kit.toml 2>/dev/null)"; then rm -f "$tmp"; return 2; fi + if ! v="$(_kit_mc_git -C "$repo" ls-tree --name-only "$ref" -- kit.toml 2>/dev/null)"; then rm -f "$tmpk" "$tmpl"; return 2; fi + if [ -n "$v" ]; then + _kit_mc_git -C "$repo" show "$ref:kit.toml" >| "$tmpk" 2>/dev/null || { rm -f "$tmpk" "$tmpl"; return 2; } + fi + if ! v="$(_kit_mc_git -C "$repo" ls-tree --name-only "$ref" -- .kit.toml 2>/dev/null)"; then rm -f "$tmpk" "$tmpl"; return 2; fi if [ -n "$v" ]; then - _kit_mc_git -C "$repo" show "$ref:.kit.toml" >| "$tmp" 2>/dev/null || { rm -f "$tmp"; return 2; } + _kit_mc_git -C "$repo" show "$ref:.kit.toml" >| "$tmpl" 2>/dev/null || { rm -f "$tmpk" "$tmpl"; return 2; } fi - v="$(_kit_mc_resolve "$tmp")"; r=$? - rm -f "$tmp" + v="$(_kit_mc_resolve "$tmpk" "$tmpl")"; r=$? + rm -f "$tmpk" "$tmpl" _kit_mc_finish "$r" "$v"; return $? fi # No default-branch commit to read: operator and kit-root are still read; a project key in the # working tree cannot be verified. - rm -f "$tmp" - v="$(_kit_mc_resolve /nonexistent)"; r=$? + rm -f "$tmpk" "$tmpl" + v="$(_kit_mc_resolve /nonexistent /nonexistent)"; r=$? if [ "$r" -ne 1 ]; then _kit_mc_finish "$r" "$v"; return $?; fi - if [ -n "$(_kit_toml_get "$repo/.kit.toml" merge command)" ] || ! _kit_mc_shape "$repo/.kit.toml"; then + if [ -n "$(_kit_toml_get "$repo/kit.toml" dev.merge command)" ] || ! _kit_mc_shape "$repo/kit.toml" dev.merge \ + || [ -n "$(_kit_toml_get "$repo/.kit.toml" merge command)" ] || ! _kit_mc_shape "$repo/.kit.toml" merge; then echo "merge command: $repo names [merge] but origin's default branch cannot be read to verify it (run git fetch); refusing to merge" >&2 return 2 fi return 1 } -kit_merge_command_slug() { - local slug="${1:-}" def="${2:-}" tmp out err names enc v r - [ -n "$slug" ] && [ -n "$def" ] || return 2 - tmp="$(mktemp "${TMPDIR:-/tmp}/kit-merge-cmd.XXXXXX")" || return 2 - err="$(mktemp "${TMPDIR:-/tmp}/kit-merge-err.XXXXXX")" || { rm -f "$tmp"; return 2; } - enc="$(jq -rn --arg d "$def" '$d|@uri')" - if out="$(gh api -H 'Accept: application/vnd.github.raw' "repos/${slug}/contents/.kit.toml?ref=${enc}" 2>"$err")"; then - printf '%s\n' "$out" >| "$tmp" +# _kit_mc_slug_fetch -- fetch from GitHub API. +# 404 is believed only when the root directory listing at is readable and omits . +_kit_mc_slug_fetch() { + local slug="$1" enc="$2" fname="$3" dest="$4" err out names + err="$(mktemp "${TMPDIR:-/tmp}/kit-merge-err.XXXXXX")" || return 2 + if out="$(gh api -H 'Accept: application/vnd.github.raw' "repos/${slug}/contents/${fname}?ref=${enc}" 2>"$err")"; then + printf '%s\n' "$out" >| "$dest" + rm -f "$err"; return 0 elif grep -q 'HTTP 404' "$err"; then - # A 404 is also what a token without contents access gets. Believe "no file" only when the - # directory listing of the same ref is readable and does not hold it. if names="$(gh api "repos/${slug}/contents/?ref=${enc}" --jq '.[].name' 2>/dev/null)" \ - && ! printf '%s\n' "$names" | grep -qxF .kit.toml; then - : >| "$tmp" - else - rm -f "$tmp" "$err"; return 2 + && ! printf '%s\n' "$names" | grep -qxF "$fname"; then + : >| "$dest" + rm -f "$err"; return 0 fi - else - rm -f "$tmp" "$err"; return 2 fi - rm -f "$err" - v="$(_kit_mc_resolve "$tmp")"; r=$? - rm -f "$tmp" + rm -f "$err"; return 2 +} + +kit_merge_command_slug() { + local slug="${1:-}" def="${2:-}" tmpk tmpl enc v r + [ -n "$slug" ] && [ -n "$def" ] || return 2 + tmpk="$(mktemp "${TMPDIR:-/tmp}/kit-merge-cmd.XXXXXX")" || return 2 + tmpl="$(mktemp "${TMPDIR:-/tmp}/kit-merge-cmd.XXXXXX")" || { rm -f "$tmpk"; return 2; } + enc="$(jq -rn --arg d "$def" '$d|@uri')" + _kit_mc_slug_fetch "$slug" "$enc" "kit.toml" "$tmpk" || { rm -f "$tmpk" "$tmpl"; return 2; } + _kit_mc_slug_fetch "$slug" "$enc" ".kit.toml" "$tmpl" || { rm -f "$tmpk" "$tmpl"; return 2; } + v="$(_kit_mc_resolve "$tmpk" "$tmpl")"; r=$? + rm -f "$tmpk" "$tmpl" _kit_mc_finish "$r" "$v" } diff --git a/lib/gate/gate-policy.sh b/lib/gate/gate-policy.sh index f45d46600..ebe5d821b 100755 --- a/lib/gate/gate-policy.sh +++ b/lib/gate/gate-policy.sh @@ -46,23 +46,26 @@ enabled() { # What the operator overlay and the kit root say, with the project file out of the picture. local def=false; case " $DEFAULT_ON " in *" $key "*) def=true ;; esac local rest; rest="$(KIT_PROJECT_ROOT=/nonexistent kit_config_get "gate.$key" "$def" 2>/dev/null)" || return 0 - local pfile="$root/.kit.toml" tmp="" + local pv="" pfile="" hit="" if [ -n "$at" ]; then - tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")"; pfile="$tmp" - kit_config_show_at "$root" "$at" > "$tmp" || : > "$tmp" + pv="$(_kit_project_get_at "$root" "$at" gate "$key")" + else + hit="$(_kit_project_get_with_file "$root" gate "$key")" + if [ -n "$hit" ]; then + pfile="${hit%%$'\t'*}" + pv="${hit#*$'\t'}" + fi fi - local pv; pv="$(_kit_toml_get "$pfile" gate "$key")" - [ -z "$tmp" ] || rm -f "$tmp" case "$pv" in true) return 0 ;; false) # At a base, the file is committed by definition: no clean check. [ -n "$at" ] && return 1 - # A project-level off over an operator on: only when the file is tracked and unmodified. - if kit_config_tracked_clean "$root/.kit.toml"; then + # A project-level off over an operator on: only when the winning file is tracked and unmodified. + if [ -n "$pfile" ] && kit_config_tracked_clean "$pfile"; then return 1 fi - [ "$rest" = "true" ] && echo "gate-policy: [gate] $key = false in $root/.kit.toml is not applied until the file is committed and clean" >&2 + [ "$rest" = "true" ] && echo "gate-policy: [gate] $key = false in ${pfile:-$root/kit.toml} is not applied until the file is committed and clean" >&2 ;; esac [ "$rest" = "true" ] diff --git a/lib/gate/lane-data.sh b/lib/gate/lane-data.sh index 504f6d9f6..390ee47cd 100644 --- a/lib/gate/lane-data.sh +++ b/lib/gate/lane-data.sh @@ -145,9 +145,9 @@ lane_effective() { printf '%s\t%s\t%s\t%s\n' "$lane" "$src" "${hdr:--}" "$chk" } -# lane_project_applies: 0 when the project .kit.toml is tracked and unmodified. +# lane_project_applies []: 0 when the project config file is tracked and unmodified. lane_project_applies() { - local pf; pf="$(kit_config_project)" + local pf="${1:-$(kit_config_project)}" [ -f "$pf" ] || return 1 kit_config_tracked_clean "$pf" } @@ -177,43 +177,61 @@ _ld_kit_has_required() { # Exit 1 when the lane is unknown or its data is malformed. Mode `kit` reads the kit root ONLY # (no operator overlay, no project); `nopro` skips just the project layer. lane_resolve() { - # KIT_LANE_PROJECT_AT=: read the project layer from the .kit.toml committed at (the merge - # base at ship time), never the working tree, so a change under review cannot rewrite its own lanes. - local _ld_at_file="" _ld_rc=0 + # KIT_LANE_PROJECT_AT=: read the project layer from the kit.toml / .kit.toml committed at + # (the merge base at ship time), never the working tree, so a change under review cannot rewrite its own lanes. + local _ld_at_kit="" _ld_at_leg="" _ld_rc=0 _pd if [ -n "${KIT_LANE_PROJECT_AT:-}" ]; then - _ld_at_file="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || return 1 - kit_config_show_at "$(dirname "$(kit_config_project)")" "$KIT_LANE_PROJECT_AT" > "$_ld_at_file" 2>/dev/null || : > "$_ld_at_file" + _pd="$(kit_config_project_dir)" + _ld_at_kit="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || return 1 + _ld_at_leg="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || { command rm -f "$_ld_at_kit"; return 1; } + kit_config_show_kit_at "$_pd" "$KIT_LANE_PROJECT_AT" > "$_ld_at_kit" 2>/dev/null || : > "$_ld_at_kit" + kit_config_show_legacy_at "$_pd" "$KIT_LANE_PROJECT_AT" > "$_ld_at_leg" 2>/dev/null || : > "$_ld_at_leg" fi - _ld_at_file="$_ld_at_file" _lane_resolve_layers "$@" || _ld_rc=$? - [ -z "$_ld_at_file" ] || command rm -f "$_ld_at_file" + _ld_at_kit="$_ld_at_kit" _ld_at_leg="$_ld_at_leg" _lane_resolve_layers "$@" || _ld_rc=$? + [ -z "$_ld_at_kit" ] || command rm -f "$_ld_at_kit" + [ -z "$_ld_at_leg" ] || command rm -f "$_ld_at_leg" return "$_ld_rc" } _lane_resolve_layers() { - local lane="$1" mode="${2:-}" layer f raw lraw ph known + local lane="$1" mode="${2:-}" layer f sec raw lraw ph known pd LANE_PHASES=""; LANE_LIGHT="" # Only the five kit lanes exist here. A committed `[lane.mega]` block must not make `mega` a # lane whose gate check passes; drop-in lanes answer `plan` only, through lanes.d. case " $LANE_NAMES " in *" $lane "*) ;; *) return 1 ;; esac - for layer in project operator kit; do + pd="$(kit_config_project_dir)" + for layer in project_kit project_legacy operator kit; do case "$layer" in - project) [ -n "$mode" ] && continue; f="$(kit_config_project)"; [ -z "${_ld_at_file:-}" ] || f="$_ld_at_file" ;; - operator) [ "$mode" = kit ] && continue; f="$(_ld_operator_file)" ;; - kit) f="$(_ld_kit_file)" ;; + project_kit) + [ -n "$mode" ] && continue + f="$pd/kit.toml"; [ -z "${_ld_at_kit:-}" ] || f="$_ld_at_kit" + sec="dev.lane.$lane" ;; + project_legacy) + [ -n "$mode" ] && continue + f="$pd/.kit.toml"; [ -z "${_ld_at_leg:-}" ] || f="$_ld_at_leg" + sec="lane.$lane" ;; + operator) + [ "$mode" = kit ] && continue + f="$(_ld_operator_file)"; sec="lane.$lane" ;; + kit) + f="$(_ld_kit_file)"; sec="lane.$lane" ;; esac - raw="$(_kit_toml_get "$f" "lane.$lane" phases)" + raw="$(_kit_toml_get "$f" "$sec" phases)" [ -n "$raw" ] || continue - if [ "$layer" = project ] && [ -z "${_ld_at_file:-}" ] && ! lane_project_applies; then - echo "lane-data: [lane.$lane] in $f is ignored: the file is not committed and clean" >&2 - continue + if { [ "$layer" = project_kit ] && [ -z "${_ld_at_kit:-}" ]; } \ + || { [ "$layer" = project_legacy ] && [ -z "${_ld_at_leg:-}" ]; }; then + if ! lane_project_applies "$f"; then + echo "lane-data: [$sec] in $f is ignored: the file is not committed and clean" >&2 + continue + fi fi LANE_PHASES="$(_ld_array "$raw")" || { LANE_PHASES=""; return 1; } - lraw="$(_kit_toml_get "$f" "lane.$lane" light)" + lraw="$(_kit_toml_get "$f" "$sec" light)" if [ -n "$lraw" ]; then LANE_LIGHT="$(_ld_array "$lraw")" || { LANE_PHASES=""; LANE_LIGHT=""; return 1; }; fi if [ "$layer" != kit ]; then # An override may not empty a lane that carries required gates: `phases = []` would waive # every one of them. if [ -z "$LANE_PHASES" ] && _ld_kit_has_required "$lane"; then - echo "lane-data: [lane.$lane] in $f sets no phases but the kit lane has required gates; override ignored, kit lane used" >&2 + echo "lane-data: [$sec] in $f sets no phases but the kit lane has required gates; override ignored, kit lane used" >&2 LANE_PHASES=""; LANE_LIGHT="" continue fi @@ -221,7 +239,7 @@ _lane_resolve_layers() { while IFS= read -r ph; do [ -n "$ph" ] || continue if ! printf '%s\n' "$known" | grep -qxF -- "$ph"; then - echo "lane-data: [lane.$lane] in $f names unknown phase '$ph'; override ignored, kit lane used" >&2 + echo "lane-data: [$sec] in $f names unknown phase '$ph'; override ignored, kit lane used" >&2 LANE_PHASES=""; LANE_LIGHT="" continue 2 fi @@ -258,10 +276,12 @@ lane_dropped() { # lane_default: the lane classify returns when no rule picks another. lane_default() { - local v pf; pf="$(kit_config_project)" - v="$(_kit_toml_get "$pf" lanes default)" - if [ -n "$v" ]; then - if lane_project_applies; then :; else + local v="" pf="" hit + hit="$(_kit_project_get_with_file "$(kit_config_project_dir)" lanes default)" + if [ -n "$hit" ]; then + pf="${hit%%$'\t'*}" + v="${hit#*$'\t'}" + if ! lane_project_applies "$pf"; then echo "lane-data: [lanes] default in $pf is ignored: the file is not committed and clean" >&2 v="" fi @@ -272,22 +292,87 @@ lane_default() { case " $LANE_NAMES " in *" $v "*) printf '%s' "$v" ;; *) printf 'normal' ;; esac } -# lane_extra_hard_paths: every ERE from [lanes] extra_hard_paths, one per line. The union of all -# layers, including both the working-tree and the HEAD copy of the project file, so a dirty edit -# that deletes an entry cannot drop it. KIT_FLOOR_CONFIG_AT= (the mega gate's PR-head mode) adds the -# copy committed at , so a stale checkout cannot drop an entry the base-branch tip carries. An -# invalid ERE is skipped with one stderr line. +# _ld_door_to_ere: convert newline-separated repo-relative door paths on stdin to anchored EREs. +# Escapes ERE metacharacters so literal dots (deploy/macos/firewall.sh) match only literal dots. +# A trailing `/` matches every file under that directory (`^`); any other path matches the +# exact path or files beneath it (`^(/|$)`). +_ld_door_to_ere() { + awk ' + { + p = $0 + sub(/^\.\//, "", p) + sub(/^\/+/, "", p) + if (p == "") next + out = "" + n = length(p) + for (i = 1; i <= n; i++) { + c = substr(p, i, 1) + if (index("\\.^$*+?()[]{}|", c) > 0) out = out "\\" c + else out = out c + } + if (substr(p, n, 1) == "/") print "^" out + else print "^" out "(/|$)" + } + ' +} + +# _ld_door_paths_pair : emit door_paths EREs from [repo], +# falling back to (top-level or [repo]) only when [repo].door_paths is not declared +# in . +_ld_door_paths_pair() { + local kf="$1" rf="$2" arr + if arr="$(_kit_toml_get_array "$kf" repo door_paths 2>/dev/null)"; then + [ -n "$arr" ] && printf '%s\n' "$arr" | _ld_door_to_ere + return 0 + fi + if arr="$(_kit_toml_get_array "$rf" "" door_paths 2>/dev/null)"; then + [ -n "$arr" ] && printf '%s\n' "$arr" | _ld_door_to_ere + return 0 + fi +} + +# lane_door_hard_paths: EREs auto-inherited from [repo].door_paths in kit.toml (or repokit.toml +# fallback). Unions working-tree, HEAD, and KIT_FLOOR_CONFIG_AT so an uncommitted edit cannot +# drop a door path. +lane_door_hard_paths() { + local d r tmpk tmpr + d="$(kit_config_project_dir)" + { + _ld_door_paths_pair "$d/kit.toml" "$d/repokit.toml" + if git -C "$d" rev-parse --is-inside-work-tree >/dev/null 2>&1; then + tmpk="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" + tmpr="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" + for r in HEAD ${KIT_FLOOR_CONFIG_AT:-}; do + git -C "$d" show "$r:kit.toml" > "$tmpk" 2>/dev/null || : > "$tmpk" + git -C "$d" show "$r:repokit.toml" > "$tmpr" 2>/dev/null || : > "$tmpr" + _ld_door_paths_pair "$tmpk" "$tmpr" + done + rm -f "$tmpk" "$tmpr" + fi + } | sed '/^$/d' | sort -u +} + +# lane_extra_hard_paths: every ERE from [dev.lanes]/[lanes] extra_hard_paths PLUS auto-inherited +# [repo].door_paths (kit.toml, or repokit.toml fallback), one per line. Unions all layers, +# including both the working-tree and the HEAD copy of the project files, so a dirty edit that +# deletes an entry cannot drop it. KIT_FLOOR_CONFIG_AT= (the mega gate's PR-head mode) adds +# the copy committed at , so a stale checkout cannot drop an entry the base-branch tip carries. +# An invalid ERE is skipped with one stderr line. lane_extra_hard_paths() { - local pf d v r; pf="$(kit_config_project)"; d="$(dirname "$pf")" + local d v r tmp + d="$(kit_config_project_dir)" { - _kit_toml_get "$pf" lanes extra_hard_paths + _kit_toml_get "$d/kit.toml" dev.lanes extra_hard_paths + _kit_toml_get "$d/.kit.toml" lanes extra_hard_paths if git -C "$d" rev-parse --is-inside-work-tree >/dev/null 2>&1; then - local tmp; tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" + tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" for r in HEAD ${KIT_FLOOR_CONFIG_AT:-}; do - kit_config_show_at "$d" "$r" > "$tmp" && _kit_toml_get "$tmp" lanes extra_hard_paths + kit_config_show_kit_at "$d" "$r" > "$tmp" 2>/dev/null && _kit_toml_get "$tmp" dev.lanes extra_hard_paths + kit_config_show_legacy_at "$d" "$r" > "$tmp" 2>/dev/null && _kit_toml_get "$tmp" lanes extra_hard_paths done rm -f "$tmp" fi + lane_door_hard_paths _kit_toml_get "$(_ld_operator_file)" lanes extra_hard_paths _kit_toml_get "$(_ld_kit_file)" lanes extra_hard_paths } | while IFS= read -r v; do @@ -318,15 +403,20 @@ db/migrations/0001_init.sql .github/workflows/ci.yml Dockerfile' lane_hard_path_exempt() { - local root="$1" rev="$2" tmp can sha + local root="$1" rev="$2" tmp can sha pfx="" [ -n "$root" ] && [ -n "$rev" ] || return 0 tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || return 0 - kit_config_show_at "$root" "$rev" > "$tmp" - if ! grep -q 'hard_path_exempt\|hard_path_canaries' "$tmp"; then command rm -f "$tmp"; return 0; fi + if kit_config_show_kit_at "$root" "$rev" > "$tmp" 2>/dev/null && grep -q 'hard_path_exempt\|hard_path_canaries' "$tmp"; then + pfx="dev." + elif kit_config_show_legacy_at "$root" "$rev" > "$tmp" 2>/dev/null && grep -q 'hard_path_exempt\|hard_path_canaries' "$tmp"; then + pfx="" + else + command rm -f "$tmp"; return 0 + fi can="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || { command rm -f "$tmp"; return 0; } printf '%s\n' "$_LD_EXEMPT_CANARIES" > "$can" sha="$(git -C "$root" rev-parse --short "$rev" 2>/dev/null || printf '%s' "$rev")" - awk -v sha="$sha" -v BOM="$(printf '\357\273\277')" ' + awk -v sha="$sha" -v pfx="$pfx" -v BOM="$(printf '\357\273\277')" ' function trim(s) { sub(/^[[:space:]]+/, "", s); sub(/[[:space:]]+$/, "", s); return s } function sw(v, i) { while (substr(v, i, 1) ~ /[ \t]/) i++; return i } function cfgerr(m) { cerr[++ncerr] = m } @@ -405,13 +495,13 @@ lane_hard_path_exempt() { t ~ /^\[/ { h = t; sub(/[[:space:]]*#.*$/, "", h); hn = h; gsub(/[[:space:]]/, "", hn) sec = "other" - if (hn == "[[gate.hard_path_exempt]]") { + if (hn == "[[" pfx "gate.hard_path_exempt]]") { hdr = 1 - if (h != "[[gate.hard_path_exempt]]") cfgerr("line " FNR ": the header must be exactly [[gate.hard_path_exempt]]") + if (h != "[[" pfx "gate.hard_path_exempt]]") cfgerr("line " FNR ": the header must be exactly [[" pfx "gate.hard_path_exempt]]") else { cur = ++ne; sec = "ent" } - } else if (hn == "[gate.hard_path_exempt]") { - hdr = 1; cfgerr("line " FNR ": use the array-of-tables header [[gate.hard_path_exempt]], not [gate.hard_path_exempt]") - } else if (hn == "[gate]") sec = "gate" + } else if (hn == "[" pfx "gate.hard_path_exempt]") { + hdr = 1; cfgerr("line " FNR ": use the array-of-tables header [[" pfx "gate.hard_path_exempt]], not [" pfx "gate.hard_path_exempt]") + } else if (hn == "[" pfx "gate]") sec = "gate" next } sec == "ent" { diff --git a/lib/gate/ledger-key.sh b/lib/gate/ledger-key.sh index ee9467721..21d8f2ddc 100644 --- a/lib/gate/ledger-key.sh +++ b/lib/gate/ledger-key.sh @@ -17,17 +17,20 @@ _LEDGER_KEY_SOURCED=1 source "${BASH_SOURCE[0]%/*}/../config/kit-config.sh" _lane_fp() { - local pf op clean=0 sums at - pf="$(kit_config_project)"; op="$(kit_config_operator)" - # lane-data.sh honours the project file only when it is tracked and clean against HEAD - if [ -f "$pf" ] && kit_config_tracked_clean "$pf"; then clean=1; fi + local pd pk pl op clean_k=0 clean_l=0 sums at="" + pd="$(kit_config_project_dir)" + pk="$pd/kit.toml"; pl="$pd/.kit.toml"; op="$(kit_config_operator)" + # lane-data.sh honours a project file only when it is tracked and clean against HEAD + if [ -f "$pk" ] && kit_config_tracked_clean "$pk"; then clean_k=1; fi + if [ -f "$pl" ] && kit_config_tracked_clean "$pl"; then clean_l=1; fi # one cksum process, one line per file (crc size path); a missing file has no line - sums="$(cksum "$LIB_ROOT/../kit.toml" "$op" "$pf" "$LIB_ROOT"/gate/*.sh "$LIB_ROOT/config/kit-config.sh" 2>/dev/null || true)" - sums="${sums//"$LIB_ROOT/"/}"; sums="${sums//"$op"/operator}"; sums="${sums//"$pf"/project}" - # A project layer read at a rev (KIT_LANE_PROJECT_AT) is keyed on the committed blob, not the working tree. - at="" - if [ -n "${KIT_LANE_PROJECT_AT:-}" ]; then at="$(kit_config_show_at "$(dirname "$pf")" "$KIT_LANE_PROJECT_AT" | cksum)"; fi - printf '%s\nclean=%s\nat=%s\n' "$sums" "$clean" "$at" | cksum | cut -d' ' -f1 + sums="$(cksum "$LIB_ROOT/../kit.toml" "$op" "$pk" "$pl" "$LIB_ROOT"/gate/*.sh "$LIB_ROOT/config/kit-config.sh" 2>/dev/null || true)" + sums="${sums//"$LIB_ROOT/"/}"; sums="${sums//"$op"/operator}"; sums="${sums//"$pk"/project-kit}"; sums="${sums//"$pl"/project-legacy}" + # A project layer read at a rev (KIT_LANE_PROJECT_AT) is keyed on both committed blobs, not the working tree. + if [ -n "${KIT_LANE_PROJECT_AT:-}" ]; then + at="$(kit_config_show_kit_at "$pd" "$KIT_LANE_PROJECT_AT" | cksum):$(kit_config_show_legacy_at "$pd" "$KIT_LANE_PROJECT_AT" | cksum)" + fi + printf '%s\nclean=%s:%s\nat=%s\n' "$sums" "$clean_k" "$clean_l" "$at" | cksum | cut -d' ' -f1 } # _file_id : ""; GNU stat first (BSD stat rejects -c, GNU diff --git a/lib/gate/proof-ledger.sh b/lib/gate/proof-ledger.sh index 71e92af5d..6744f96f5 100755 --- a/lib/gate/proof-ledger.sh +++ b/lib/gate/proof-ledger.sh @@ -102,7 +102,7 @@ _subjects() { git -C "$1" log "$2"..HEAD --format='%s' 2>/dev/null || true; } _nondoc_paths() { awk '{ lc = tolower($0) } lc ~ /(^|\/)[^\/]*credentials?[^\/]*$|(^|\/)secrets?\/|\.(pem|key|p12|pfx)$|(^|\/)\.env/ { print; next } - $0 ~ /\.(md|txt|markdown)$/ || $0 ~ /(^|\/)\.kit\.toml$/ { next } + $0 ~ /\.(md|txt|markdown)$/ || $0 ~ /(^|\/)\.?kit\.toml$/ { next } ($0 ~ /(^|\/)docs\// && $0 ~ /\.(rst|adoc|png|jpe?g|gif|webp|pdf|csv)$/) || ($0 ~ /^docs\// && $0 ~ /\.(html?|svg)$/) { next } { print }' } @@ -410,12 +410,18 @@ _green_marks() { # `full` weakens the gate, so like gate-policy.sh it counts only when .kit.toml is tracked and # clean; the operator and kit-root layers apply as-is. Anything unreadable or unknown means yes. _negctl_required() { - local root="$1" base="$2" slug="$3" mode pv spec lane changed + local root="$1" base="$2" slug="$3" mode pv pfile="" hit spec lane changed mode="$(KIT_PROJECT_ROOT=/nonexistent kit_config_get gate.negative_control always 2>/dev/null)" || mode=always - pv="$(_kit_toml_get "$root/.kit.toml" gate negative_control)" + hit="$(_kit_project_get_with_file "$root" gate negative_control)" + if [ -n "$hit" ]; then + pfile="${hit%%$'\t'*}" + pv="${hit#*$'\t'}" + else + pv="" + fi case "$pv" in always) mode=always ;; - full) kit_config_tracked_clean "$root/.kit.toml" && mode=full ;; + full) [ -n "$pfile" ] && kit_config_tracked_clean "$pfile" && mode=full ;; esac [ "$mode" = full ] || { echo yes; return 0; } [ -z "$slug" ] || spec="$(spec_for_slug "$root" "$slug")" # spec-active-ok: the enforcement name pick, the answer spec_active returns by default @@ -517,10 +523,14 @@ _visual_proof() { fi baseurl="${baseurl%/}" - local assets_local=no - if kit_config_tracked_clean "$root/.kit.toml" \ - && [ "$(_kit_toml_get "$root/.kit.toml" proof assets)" = "local" ]; then - assets_local=yes + local assets_local=no assets_hit assets_file assets_val + assets_hit="$(_kit_project_get_with_file "$root" proof assets)" + if [ -n "$assets_hit" ]; then + assets_file="${assets_hit%%$'\t'*}" + assets_val="${assets_hit#*$'\t'}" + if [ "$assets_val" = "local" ] && kit_config_tracked_clean "$assets_file"; then + assets_local=yes + fi fi local reasons="" pending=0 fetches=0 m mfile mslug st url sha f by got @@ -618,8 +628,16 @@ check() { local visual=no if [ "$class" = "behavioral" ] \ && [ -n "$(_changed "$root" "$base" | grep -E '\.(tsx|jsx|vue|svelte|css|scss|html)$')" ]; then - if kit_config_tracked_clean "$root/.kit.toml"; then - [ "$(KIT_PROJECT_ROOT="$root" kit_config_get proof.visual false 2>/dev/null)" = "true" ] && visual=yes + local vhit vfile vval + vhit="$(_kit_project_get_with_file "$root" proof visual)" + if [ -n "$vhit" ]; then + vfile="${vhit%%$'\t'*}" + vval="${vhit#*$'\t'}" + if kit_config_tracked_clean "$vfile"; then + [ "$vval" = "true" ] && visual=yes + else + [ "$(kit_config_get_root proof.visual false 2>/dev/null)" = "true" ] && visual=yes + fi else [ "$(kit_config_get_root proof.visual false 2>/dev/null)" = "true" ] && visual=yes fi diff --git a/lib/goal/mega-merge.sh b/lib/goal/mega-merge.sh index 9dedbdcca..71c4b1011 100755 --- a/lib/goal/mega-merge.sh +++ b/lib/goal/mega-merge.sh @@ -390,11 +390,12 @@ _pr_files() { # which `mark` re-runs to confirm a hold landed and so must stay state-only. # return 0 + a reason -> refuse; return 1 -> clear; return 2 -> the file list is unreadable or empty. _merge_config_guard() { - local files + local files hit files="$(_pr_files "$1")" || return 2 [ -n "$files" ] || return 2 - if printf '%s\n' "$files" | grep -qxF '.kit.toml'; then - echo "touches .kit.toml (hard-path and gate config); a human merges it"; return 0 + hit="$(printf '%s\n' "$files" | grep -xE '\.?kit\.toml' | head -1)" + if [ -n "$hit" ]; then + echo "touches $hit (hard-path and gate config); a human merges it"; return 0 fi return 1 } diff --git a/lib/wrap/wrap-adopt.sh b/lib/wrap/wrap-adopt.sh index 1a418f16a..462779554 100644 --- a/lib/wrap/wrap-adopt.sh +++ b/lib/wrap/wrap-adopt.sh @@ -15,9 +15,9 @@ # ADOPT_PATHS when it equals a listed file or sits under the listed directory; R3c # and R3k read it as a pathspec list and the apply-path guard matches the same list. ADOPT_BRANCH="chore/kit-adopt" -ADOPT_PATHS="AGENTS.md CLAUDE.md WORKFLOW.md .kit.toml docs/verification/README.md .claude/settings.json .claude/output-styles/" +ADOPT_PATHS="AGENTS.md CLAUDE.md WORKFLOW.md kit.toml .kit.toml docs/verification/README.md .claude/settings.json .claude/output-styles/" ADOPT_COMMIT_SUBJECT="chore: adopt the dwarves-kit operate-contract" -ADOPT_COMMIT_BODY="AGENTS.md pointer, CLAUDE.md loader (none under adopt.agents_only), WORKFLOW pointer, proof marker, starter .kit.toml, kit hook wiring." +ADOPT_COMMIT_BODY="AGENTS.md pointer, CLAUDE.md loader (none under adopt.agents_only), WORKFLOW pointer, proof marker, starter kit.toml, kit hook wiring." OVERRIDE_REASON="written by wrap adopt --apply: adoption scaffold only, every path in ADOPT_PATHS (R6); .claude/settings.json changes limited to kit hook commands and outputStyle (R6a); no other file changed" # Passed to jq as --arg re and applied with test(): \A and \z reject an embedded # newline, which ^ and $ would let past. Matches the two command shapes the kit's @@ -66,15 +66,13 @@ _adopt_style_of() { # file is read as COMMITTED at that ref, because the worktree adopt runs in is built from # origin/: a key that is only in the main checkout must not decide the preflight. _adopt_agents_only() { - local dir="$1" ref="${2:-}" proj="$1" tmp="" v kroot="${KIT_CONFIG_ROOT:-}" + local dir="$1" ref="${2:-}" v kroot="${KIT_CONFIG_ROOT:-}" [ -f "$LIB_ROOT/../kit.toml" ] && kroot="$(cd "$LIB_ROOT/.." && pwd)" if [ -n "$ref" ]; then - tmp="$(mktemp -d "${TMPDIR:-/tmp}/kit-adopt-ao.XXXXXX")" || return 1 - kit_config_show_at "$dir" "$ref" >| "$tmp/.kit.toml" 2>/dev/null || : >| "$tmp/.kit.toml" - proj="$tmp" + v="$(KIT_CONFIG_ROOT="$kroot" kit_config_get_at "$dir" "$ref" adopt.agents_only false)" + else + v="$(KIT_CONFIG_ROOT="$kroot" KIT_PROJECT_ROOT="$dir" kit_config_get adopt.agents_only false)" fi - v="$(KIT_CONFIG_ROOT="$kroot" KIT_PROJECT_ROOT="$proj" kit_config_get adopt.agents_only false)" - if [ -n "$tmp" ]; then rm -f "$tmp/.kit.toml"; rmdir "$tmp" 2>/dev/null || :; fi [ "$v" = "true" ] } @@ -90,7 +88,7 @@ _adopt_paths() { _adopt_path_ok() { [ "$1" = "CLAUDE.md" ] && [ "${ADOPT_AO:-0}" = 1 ] && return 1 case "$1" in - AGENTS.md|CLAUDE.md|WORKFLOW.md|.kit.toml|docs/verification/README.md|.claude/settings.json) return 0 ;; + AGENTS.md|CLAUDE.md|WORKFLOW.md|kit.toml|.kit.toml|docs/verification/README.md|.claude/settings.json) return 0 ;; .claude/output-styles/*) [ -n "$2" ] && [ "$1" = ".claude/output-styles/$2.md" ] ;; *) return 1 ;; @@ -364,7 +362,7 @@ _adopt_preflight() { # check-ignore: a tracked path answers 1 and still stages, so it passes; the # style file joins only when the dry run reports one (repos ignore .claude/* and # re-include .claude/settings.json). - for p in AGENTS.md CLAUDE.md WORKFLOW.md .kit.toml docs/verification/README.md .claude/settings.json; do + for p in AGENTS.md CLAUDE.md WORKFLOW.md kit.toml docs/verification/README.md .claude/settings.json; do [ "$p" = CLAUDE.md ] && [ "$ADOPT_AO" = 1 ] && continue git -C "$repo" check-ignore -q -- "$p" 2>/dev/null && _pf_add "$p is gitignored" done @@ -446,8 +444,8 @@ _adopt_one() { # built from fresh origin/, whose ignore rules R3k's main-checkout read # can miss. git prints a collapsed directory (`!! .claude/`) when one is # ignored whole. - ig="AGENTS.md CLAUDE.md WORKFLOW.md .kit.toml docs/verification/README.md .claude/settings.json" - [ "$ADOPT_AO" = 1 ] && ig="AGENTS.md WORKFLOW.md .kit.toml docs/verification/README.md .claude/settings.json" + ig="AGENTS.md CLAUDE.md WORKFLOW.md kit.toml docs/verification/README.md .claude/settings.json" + [ "$ADOPT_AO" = 1 ] && ig="AGENTS.md WORKFLOW.md kit.toml docs/verification/README.md .claude/settings.json" [ -n "$style" ] && ig="$ig .claude/output-styles/${style}.md" miss="$(git -C "$wt" status --porcelain --ignored -- $ig 2>/dev/null | sed -n 's/^!! //p' | sed -n 1p)" if [ -n "$miss" ]; then diff --git a/tests/test-adopt.sh b/tests/test-adopt.sh index 531789b73..9dd16e88d 100755 --- a/tests/test-adopt.sh +++ b/tests/test-adopt.sh @@ -118,24 +118,25 @@ if ! command -v jq >/dev/null 2>&1; then echo "skip - SPEC-192 module-wiring tests need jq; not found on PATH" else -# 12. Fresh adopt seeds a starter .kit.toml with a [modules] section naming every known module. +# 12. Fresh adopt seeds a starter kit.toml with [dev.modules] and [dev.gate]. T8="$(newrepo)" bash lib/adopt.sh "$T8" >/dev/null -if [ -f "$T8/.kit.toml" ] && grep -q '^\[modules\]' "$T8/.kit.toml" \ - && grep -qE '^board[[:space:]]*=' "$T8/.kit.toml" && grep -qE '^cosmetic[[:space:]]*=' "$T8/.kit.toml"; then - ok "fresh adopt seeds a starter .kit.toml with a [modules] section" +if [ -f "$T8/kit.toml" ] && [ ! -e "$T8/.kit.toml" ] && grep -q '^\[dev\.modules\]' "$T8/kit.toml" \ + && grep -q '^\[dev\.gate\]' "$T8/kit.toml" \ + && grep -qE '^board[[:space:]]*=' "$T8/kit.toml" && grep -qE '^cosmetic[[:space:]]*=' "$T8/kit.toml"; then + ok "fresh adopt seeds a starter kit.toml with [dev.modules] and [dev.gate]" else - no "fresh adopt did not seed .kit.toml with the expected [modules] section" + no "fresh adopt did not seed kit.toml with the expected [dev.modules] and [dev.gate] sections" fi # 12b. The seeded modules are exactly the module table's toggleable modules, in table order: the # ones the old private table lacked (worktree, money_gate, prose_rag, sync) are in, the folded # bridge is out. -SEEDED="$(awk '/^\[modules\]/ { s = 1; next } /^\[/ { s = 0 } s && /^[a-z_]+ = / { printf "%s ", $1 }' "$T8/.kit.toml" | sed 's/ $//')" +SEEDED="$(awk '/^\[dev\.modules\]/ { s = 1; next } /^\[/ { s = 0 } s && /^[a-z_]+ = / { printf "%s ", $1 }' "$T8/kit.toml" | sed 's/ $//')" TABLE_MODS="$(bash -c "source lib/config/modules.sh; kit_modules_known")" if [ "$SEEDED" = "$TABLE_MODS" ] && ! printf '%s' "$SEEDED" | grep -qw bridge && printf '%s' "$SEEDED" | grep -qw money_gate; then ok "fresh adopt seeds exactly the module table's modules (incl. money_gate, prose_rag, worktree, sync; no bridge)" else - no "seeded [modules] differ from the module table: [$SEEDED] vs [$TABLE_MODS]" + no "seeded [dev.modules] differ from the module table: [$SEEDED] vs [$TABLE_MODS]" fi # 13. That same fresh adopt wires the core modules' hooks into the project's settings.json @@ -154,14 +155,14 @@ fi # kit-root default is false (cosmetic defaults false; --with cosmetic turns it on for THIS repo). T9="$(newrepo)" bash lib/adopt.sh --with cosmetic "$T9" >/dev/null -if grep -qx 'cosmetic = true' "$T9/.kit.toml" \ +if grep -qx 'cosmetic = true' "$T9/kit.toml" \ && { trap '' PIPE; printf '%s\n' "$(wired_hooks "$T9/.claude/settings.json")" 2>/dev/null || :; } | grep -qx auto-format.sh; then ok "--with cosmetic on a fresh repo seeds cosmetic=true and wires its hook" else no "--with cosmetic did not seed/wire cosmetic for a fresh repo" fi -# 15. THE Done= proof: a project .kit.toml [modules] board=false results in that project NOT +# 15. THE Done= proof: a project kit.toml [dev.modules] board=false results in that project NOT # wiring the board hook (backlog-stage.sh), verified via its settings.json. T10="$(newrepo)" bash lib/adopt.sh --with board,session "$T10" >/dev/null @@ -169,14 +170,14 @@ W15_BEFORE="$(wired_hooks "$T10/.claude/settings.json")" { trap '' PIPE; printf '%s\n' "$W15_BEFORE" 2>/dev/null || :; } | grep -qx backlog-stage.sh \ && ok "precondition: board's hook is wired before the override (--with board,session)" \ || no "precondition failed: board's hook was never wired to begin with" -sed -i.bak 's/^board = true$/board = false/' "$T10/.kit.toml" && rm -f "$T10/.kit.toml.bak" -grep -qx 'board = false' "$T10/.kit.toml" || no "test setup: could not flip board=false in $T10/.kit.toml" +sed -i.bak 's/^board = true$/board = false/' "$T10/kit.toml" && rm -f "$T10/kit.toml.bak" +grep -qx 'board = false' "$T10/kit.toml" || no "test setup: could not flip board=false in $T10/kit.toml" bash lib/adopt.sh --refresh "$T10" >/dev/null W15_AFTER="$(wired_hooks "$T10/.claude/settings.json")" if ! { trap '' PIPE; printf '%s\n' "$W15_AFTER" 2>/dev/null || :; } | grep -qx backlog-stage.sh; then - ok "DONE=: project .kit.toml [modules] board=false -> board's hook is NOT wired (settings.json)" + ok "DONE=: project kit.toml [dev.modules] board=false -> board's hook is NOT wired (settings.json)" else - no "DONE=: board=false in .kit.toml did not stop board's hook from being wired" + no "DONE=: board=false in kit.toml did not stop board's hook from being wired" fi # session's hook must be untouched by the board-only edit (surgical re-wiring, not a full reset). if { trap '' PIPE; printf '%s\n' "$W15_AFTER" 2>/dev/null || :; } | grep -qx context-readiness.sh; then @@ -203,26 +204,26 @@ else no "a re-run after the anchor migration was not a no-op" fi -# 16. THE Done= proof, second clause: a [ledger] override in the project .kit.toml is honored +# 16. THE Done= proof, second clause: a [dev.ledger] override in the project kit.toml is honored # by a command reading it (the resolver from goal 01, exercised end-to-end through a real # adopted project directory rather than a synthetic fixture). T11="$(newrepo)" bash lib/adopt.sh "$T11" >/dev/null -printf '\n[ledger]\nlocation = "isolated"\n' >> "$T11/.kit.toml" +printf '\n[dev.ledger]\nlocation = "isolated"\n' >> "$T11/kit.toml" KIT_REPO_ROOT="$(pwd)" LEDGER_VAL="$(KIT_CONFIG_ROOT="$KIT_REPO_ROOT" KIT_PROJECT_ROOT="$T11" bash -c "source '$KIT_REPO_ROOT/lib/config/kit-config.sh'; kit_config_get ledger.location")" if [ "$LEDGER_VAL" = "isolated" ]; then - ok "DONE=: a [ledger] override in the project .kit.toml is honored by the resolver" + ok "DONE=: a [dev.ledger] override in the project kit.toml is honored by the resolver" else - no "DONE=: [ledger] override was not honored (got [$LEDGER_VAL], want isolated)" + no "DONE=: [dev.ledger] override was not honored (got [$LEDGER_VAL], want isolated)" fi -# 17. --with is ignored (never clobbers) once /.kit.toml already exists. +# 17. --with is ignored (never clobbers) once /kit.toml already has [dev.*]. bash lib/adopt.sh --with cosmetic "$T11" >/dev/null 2>&1 -if ! grep -qx 'cosmetic = true' "$T11/.kit.toml"; then - ok "--with is ignored once .kit.toml already exists (never overwritten)" +if ! grep -qx 'cosmetic = true' "$T11/kit.toml"; then + ok "--with is ignored once kit.toml already exists (never overwritten)" else - no "--with clobbered an existing .kit.toml" + no "--with clobbered an existing kit.toml" fi # 18. Idempotent re-run after a config edit: re-running adopt again with NO further edits is a @@ -274,9 +275,9 @@ T15="$(newrepo)" CD21="$(mktemp -d "${TMPDIR:-/tmp}/kit.XXXXXX")" || exit 1 mkdir -p "$CD21/plugins/cache/dwarves-marketplace/kit/1.0.0/lib" OUT21="$(CLAUDE_DIR="$CD21" bash lib/adopt.sh --with board,session "$T15" 2>&1)" -if [ ! -f "$T15/.claude/settings.json" ] && grep -qx 'board = true' "$T15/.kit.toml" && grep -qx 'session = true' "$T15/.kit.toml" \ +if [ ! -f "$T15/.claude/settings.json" ] && grep -qx 'board = true' "$T15/kit.toml" && grep -qx 'session = true' "$T15/kit.toml" \ && printf '%s' "$OUT21" | grep -q 'the kit plugin already registers'; then - ok "plugin machine: .kit.toml records the modules, no project settings.json is written, adopt names why" + ok "plugin machine: kit.toml records the modules, no project settings.json is written, adopt names why" else no "plugin machine wiring wrong: $OUT21" fi @@ -318,11 +319,11 @@ if [ ! -f "$T12/.claude/output-styles/adhd.md" ] \ else no "empty output.style still wrote a style into the project" fi -printf '\n[output]\nstyle = "adhd"\n' >> "$T12/.kit.toml" +printf '\n[dev.output]\nstyle = "adhd"\n' >> "$T12/kit.toml" bash lib/adopt.sh --refresh "$T12" >/dev/null if [ -f "$T12/.claude/output-styles/adhd.md" ] && cmp -s output-styles/adhd.md "$T12/.claude/output-styles/adhd.md" \ && [ "$(jq -r '.outputStyle' "$T12/.claude/settings.json")" = "adhd" ]; then - ok "project .kit.toml [output] style=adhd copies the kit style in and sets outputStyle" + ok "project kit.toml [dev.output] style=adhd copies the kit style in and sets outputStyle" else no "output.style=adhd did not wire the style file + settings key" fi @@ -335,7 +336,7 @@ else no "re-running adopt --refresh churned the style file or settings.json" fi # Negative control (name the kit does not ship): the key is set, nothing is copied. -sed -i.bak 's/^style = "adhd"/style = "Explanatory"/' "$T12/.kit.toml" && rm -f "$T12/.kit.toml.bak" +sed -i.bak 's/^style = "adhd"/style = "Explanatory"/' "$T12/kit.toml" && rm -f "$T12/kit.toml.bak" bash lib/adopt.sh --refresh "$T12" >/dev/null if [ "$(jq -r '.outputStyle' "$T12/.claude/settings.json")" = "Explanatory" ] \ && [ ! -f "$T12/.claude/output-styles/Explanatory.md" ]; then @@ -344,7 +345,7 @@ else no "non-kit style name mishandled" fi # A name with a path component is refused: nothing copied, the key left as it was. -sed -i.bak 's#^style = "Explanatory"#style = "../../etc/passwd"#' "$T12/.kit.toml" && rm -f "$T12/.kit.toml.bak" +sed -i.bak 's#^style = "Explanatory"#style = "../../etc/passwd"#' "$T12/kit.toml" && rm -f "$T12/kit.toml.bak" bash lib/adopt.sh --refresh "$T12" >/dev/null 2>&1 if [ "$(jq -r '.outputStyle' "$T12/.claude/settings.json")" = "Explanatory" ] \ && [ ! -e "$T12/.claude/output-styles/../../etc/passwd" ] && [ ! -e "$T12/etc/passwd" ]; then @@ -729,7 +730,7 @@ CLAUDE_PLUGIN_ROOT="$NSEMPTY" bash "$NS/lib/adopt.sh" "$NSTARGET" >/dev/null 2>& if [ "$r11" -eq 0 ] && cmp -s "$NSTARGET/AGENTS.md" "$POINTER"; then ok "no source contract"; else no "no source contract (rc=$r11)"; fi # --- adopt.agents_only: AGENTS.md is the repo's one instruction file; CLAUDE.md is never written --- -ao_repo() { local d; d="$(newrepo)"; printf '[adopt]\nagents_only = true\n' > "$d/.kit.toml"; echo "$d"; } +ao_repo() { local d; d="$(newrepo)"; printf '[dev.adopt]\nagents_only = true\n' > "$d/kit.toml"; echo "$d"; } # AO1: a fresh adopt writes the pointer, the marker and the hook wiring, but no CLAUDE.md; # --check passes; a second run is a clean no-op. @@ -828,7 +829,144 @@ printf '\nstale\n\n' >> "$AO10/AGENTS.md" bash lib/adopt.sh --refresh "$AO10" >/dev/null 2>&1; m2="$(stat -c %a "$AO10/AGENTS.md" 2>/dev/null || stat -f %Lp "$AO10/AGENTS.md")" if [ "$m1" = 640 ] && [ "$m2" = 640 ]; then ok "agents_only: the block append keeps the AGENTS.md mode (640)"; else no "agents_only mode after append/refresh ($m1/$m2)"; fi -rm -rf "$AO1" "$AO2" "$AO3" "$AO4" "$AO5" "$AO5N" "$AO6" "$AO7" "$AO8" "$AO9" "$AO9B" "$AO10" "$OPAO" +# AO11: --refresh with agents_only = true removes a tracked pure 1-line @AGENTS.md CLAUDE.md shim. +AO11="$(ao_repo)"; printf '@AGENTS.md\n' > "$AO11/CLAUDE.md" +bash lib/adopt.sh "$AO11" >/dev/null 2>&1 +git -C "$AO11" add -A; git -C "$AO11" -c user.email=t@t -c user.name=t commit -qm "chore: init with shim" +OUT_AO11="$(bash lib/adopt.sh --refresh "$AO11" 2>&1)" +if [ ! -e "$AO11/CLAUDE.md" ] && ! git -C "$AO11" ls-files --error-unmatch CLAUDE.md >/dev/null 2>&1 \ + && echo "$OUT_AO11" | grep -q 'removed redundant 1-line @AGENTS.md shim' \ + && bash lib/adopt.sh --check "$AO11" >/dev/null; then + ok "agents_only: --refresh git-rms a tracked 1-line @AGENTS.md CLAUDE.md shim and --check passes" +else + no "agents_only tracked shim removal ($OUT_AO11)" +fi +git -C "$AO11" commit -qm "chore: remove shim" +bash lib/adopt.sh --refresh "$AO11" >/dev/null 2>&1 +if git -C "$AO11" diff --quiet && [ -z "$(git -C "$AO11" status --porcelain)" ]; then + ok "agents_only: second --refresh after shim removal is a clean no-op" +else + no "agents_only second --refresh after shim removal was not a no-op" +fi + +# AO12: --refresh with agents_only = true removes an untracked whitespace/CRLF @AGENTS.md shim; +# --dry-run plans the removal without deleting the file. +AO12="$(ao_repo)"; printf ' @AGENTS.md \r\n\n' > "$AO12/CLAUDE.md" +OUT_AO12D="$(bash lib/adopt.sh --dry-run --refresh "$AO12" 2>&1)" +if [ -f "$AO12/CLAUDE.md" ] && echo "$OUT_AO12D" | grep -q 'would remove redundant 1-line @AGENTS.md shim'; then + ok "agents_only: --dry-run --refresh plans shim removal and leaves CLAUDE.md untouched" +else + no "agents_only dry-run shim removal ($OUT_AO12D)" +fi +bash lib/adopt.sh --refresh "$AO12" >/dev/null 2>&1 +if [ ! -e "$AO12/CLAUDE.md" ]; then + ok "agents_only: --refresh removes an untracked whitespace/CRLF @AGENTS.md shim" +else + no "agents_only untracked shim was not removed" +fi + +# AO13 (negative control): --refresh with agents_only = true NEVER removes a custom CLAUDE.md +# even when it contains @AGENTS.md plus other content. +AO13="$(ao_repo)"; printf '@AGENTS.md\n\nCustom repo instructions.\n' > "$AO13/CLAUDE.md" +cp "$AO13/CLAUDE.md" "$AO13/CLAUDE.before" +bash lib/adopt.sh --refresh "$AO13" >/dev/null 2>&1 +if [ -f "$AO13/CLAUDE.md" ] && cmp -s "$AO13/CLAUDE.md" "$AO13/CLAUDE.before"; then + ok "agents_only [NC]: --refresh never removes a custom CLAUDE.md with extra content" +else + no "agents_only [NC] unexpectedly touched custom CLAUDE.md" +fi + +# --- Unified kit.toml: append beside [repo] + --refresh migration from .kit.toml --- +# UK1: fresh adopt on a repo that already has kit.toml with [repo] appends [dev.modules] and +# [dev.gate] without clobbering [repo]. +UK1="$(newrepo)" +cat > "$UK1/kit.toml" <<'TOML' +[repo] +profile = "public-app" +door_paths = ["deploy/macos/firewall.sh", "internal/ghauth/"] +TOML +bash lib/adopt.sh "$UK1" >/dev/null 2>&1 +if grep -q '^\[repo\]' "$UK1/kit.toml" && grep -q 'profile = "public-app"' "$UK1/kit.toml" \ + && grep -q 'deploy/macos/firewall.sh' "$UK1/kit.toml" \ + && grep -q '^\[dev\.modules\]' "$UK1/kit.toml" && grep -q '^\[dev\.gate\]' "$UK1/kit.toml" \ + && [ ! -e "$UK1/.kit.toml" ]; then + ok "unified kit.toml: fresh adopt appends [dev.*] beside existing [repo] without clobbering it" +else + no "unified kit.toml append beside [repo]"; cat "$UK1/kit.toml" +fi + +# UK2: --refresh migrates a tracked .kit.toml into kit.toml under [dev.*], preserving existing +# [repo] in kit.toml and all user values (including nested sections and [[gate.hard_path_exempt]]), +# removes .kit.toml via git rm, and is idempotent on re-run. +UK2="$(newrepo)" +cat > "$UK2/kit.toml" <<'TOML' +[repo] +profile = "private-app" +door_paths = ["infra/"] +TOML +cat > "$UK2/.kit.toml" <<'TOML' +[modules] +board = true +cosmetic = true + +[gate] +proof_of_done = true +lane_gates = false + +[adopt] +agents_only = true + +[lane.normal] +phases = ["spec", "build", "ship"] + +[[gate.hard_path_exempt]] +paths = ["tools/demo/*"] +kinds = ["auth"] +reason = "demo only" +TOML +printf '@AGENTS.md\n' > "$UK2/CLAUDE.md" +git -C "$UK2" add -A; git -C "$UK2" -c user.email=t@t -c user.name=t commit -qm "chore: legacy config" +OUT_UK2D="$(bash lib/adopt.sh --dry-run --refresh "$UK2" 2>&1)" +if [ -f "$UK2/.kit.toml" ] && echo "$OUT_UK2D" | grep -q 'would migrate .kit.toml into kit.toml'; then + ok "unified kit.toml: --dry-run --refresh plans .kit.toml migration without modifying files" +else + no "unified kit.toml dry-run migration ($OUT_UK2D)" +fi +bash lib/adopt.sh --refresh "$UK2" >/dev/null 2>&1 +if [ ! -e "$UK2/.kit.toml" ] && ! git -C "$UK2" ls-files --error-unmatch .kit.toml >/dev/null 2>&1 \ + && [ ! -e "$UK2/CLAUDE.md" ] \ + && grep -q '^\[repo\]' "$UK2/kit.toml" && grep -q 'profile = "private-app"' "$UK2/kit.toml" \ + && grep -q '^\[dev\.modules\]' "$UK2/kit.toml" && grep -q '^cosmetic = true$' "$UK2/kit.toml" \ + && grep -q '^\[dev\.gate\]' "$UK2/kit.toml" && grep -q '^lane_gates = false$' "$UK2/kit.toml" \ + && grep -q '^\[dev\.adopt\]' "$UK2/kit.toml" && grep -q '^agents_only = true$' "$UK2/kit.toml" \ + && grep -q '^\[dev\.lane\.normal\]' "$UK2/kit.toml" \ + && grep -q '^\[\[dev\.gate\.hard_path_exempt\]\]' "$UK2/kit.toml" \ + && bash lib/adopt.sh --check "$UK2" >/dev/null; then + ok "unified kit.toml: --refresh migrates .kit.toml -> kit.toml [dev.*], preserves [repo], git-rms .kit.toml + shim" +else + no "unified kit.toml --refresh migration"; cat "$UK2/kit.toml" +fi +git -C "$UK2" add -A; git -C "$UK2" -c user.email=t@t -c user.name=t commit -qm "chore: migrated" +bash lib/adopt.sh --refresh "$UK2" >/dev/null 2>&1 +if git -C "$UK2" diff --quiet && [ -z "$(git -C "$UK2" status --porcelain)" ]; then + ok "unified kit.toml: second --refresh after migration is a clean idempotent no-op" +else + no "unified kit.toml second --refresh dirtied tree" +fi + +# UK3: --refresh migrates an untracked .kit.toml when no kit.toml exists yet. +UK3="$(newrepo)" +printf '[modules]\nboard = false\n[gate]\nproof_of_done = true\n' > "$UK3/.kit.toml" +bash lib/adopt.sh --refresh "$UK3" >/dev/null 2>&1 +if [ ! -e "$UK3/.kit.toml" ] && [ -f "$UK3/kit.toml" ] \ + && grep -q '^\[dev\.modules\]' "$UK3/kit.toml" && grep -q '^board = false$' "$UK3/kit.toml" \ + && grep -q '^\[dev\.gate\]' "$UK3/kit.toml"; then + ok "unified kit.toml: --refresh migrates untracked .kit.toml into fresh kit.toml" +else + no "unified kit.toml untracked migration" +fi + +rm -rf "$AO1" "$AO2" "$AO3" "$AO4" "$AO5" "$AO5N" "$AO6" "$AO7" "$AO8" "$AO9" "$AO9B" "$AO10" "$AO11" "$AO12" "$AO13" "$UK1" "$UK2" "$UK3" "$OPAO" rm -rf "$T1" "$T2" "$T3" "$T4" "$T5" "$T6" "$T7" "$T13" "$T14" "$T15" "$T16" "$T17" "$T18" "$T19" # ------------------------------------------------------------------------------------------ @@ -926,7 +1064,7 @@ if command -v jq >/dev/null 2>&1; then OUT_PLUG="$(HOME="$H_PLUG" CLAUDE_DIR="$H_PLUG/.claude" CLAUDE_PLUGIN_ROOT="" KIT_CONFIG_OPERATOR="$NO_OPERATOR" \ bash "$H_PLUG/.claude/dwarves-kit/lib/adopt.sh" "$R_PLUG" 2>&1)" if [ -L "$H_PLUG/.claude/dwarves-kit/settings.json" ] && [ -f "$H_PLUG/.claude/dwarves-kit/settings.json" ] \ - && [ ! -f "$R_PLUG/.claude/settings.json" ] && [ -f "$R_PLUG/.kit.toml" ] \ + && [ ! -f "$R_PLUG/.claude/settings.json" ] && [ -f "$R_PLUG/kit.toml" ] \ && printf '%s\n' "$OUT_PLUG" | grep -q 'the kit plugin already registers' \ && ! printf '%s\n' "$OUT_PLUG" | grep -qi 'settings\.json.*not found'; then ok "plugin compat install symlinks settings.json and leaves project settings.json alone without warning" @@ -941,7 +1079,7 @@ if command -v jq >/dev/null 2>&1; then R_PLUG2="$(newrepo)" OUT_PLUG2="$(HOME="$H_PLUG2" CLAUDE_DIR="$H_PLUG2/.claude" CLAUDE_PLUGIN_ROOT="$H_PLUG2/.claude/plugins/cache/dwarves-marketplace/kit/1.0.0" KIT_CONFIG_OPERATOR="$NO_OPERATOR" \ bash "$H_PLUG2/.claude/plugins/cache/dwarves-marketplace/kit/1.0.0/lib/adopt.sh" "$R_PLUG2" 2>&1)" - if [ ! -f "$R_PLUG2/.claude/settings.json" ] && [ -f "$R_PLUG2/.kit.toml" ] \ + if [ ! -f "$R_PLUG2/.claude/settings.json" ] && [ -f "$R_PLUG2/kit.toml" ] \ && printf '%s\n' "$OUT_PLUG2" | grep -q 'the kit plugin already registers' \ && ! printf '%s\n' "$OUT_PLUG2" | grep -qi 'settings\.json.*not found'; then ok "in-place plugin cache install leaves project settings.json alone without warning" diff --git a/tests/test-anchor-module-gate.sh b/tests/test-anchor-module-gate.sh index 70ae95b7a..09a8d9246 100644 --- a/tests/test-anchor-module-gate.sh +++ b/tests/test-anchor-module-gate.sh @@ -26,7 +26,7 @@ run() { # $1=hook -> ":"; layers come from the env the caller set bash "$T/kit/hooks/anchor-root.sh" "$T/kit/hooks/$1.sh" "$T/proj/.kit.toml" want "spine cannot be turned off" safety-gate ran +reset +printf '[dev.modules]\ncosmetic = true\n' > "$T/proj/kit.toml" +printf '[modules]\ncosmetic = false\n' > "$T/proj/.kit.toml" +want "unified kit.toml [dev.modules] beats .kit.toml [modules]" slop-cleaner ran +reset +printf '[modules]\ncosmetic = true\n' > "$T/proj/kit.toml" +want "unprefixed [modules] in project kit.toml is ignored (kit-root isolation)" slop-cleaner skipped + reset rm -f "$T/kit/lib/config/modules.tsv" want "missing table: the hook runs" slop-cleaner ran diff --git a/tests/test-clean-room.sh b/tests/test-clean-room.sh index e36d6bf15..2bb112d04 100644 --- a/tests/test-clean-room.sh +++ b/tests/test-clean-room.sh @@ -244,7 +244,7 @@ eq "adopt --dry-run exits 0" "$RC" "0" eq "adopt --dry-run writes nothing" "$(cr git -C "$REPO" status --porcelain | grep -vc '^?? .claude/$')" "0" run bash "$KIT/lib/adopt.sh" --with board "$REPO" eq "adopt exits 0" "$RC" "0" -for f in AGENTS.md CLAUDE.md WORKFLOW.md .kit.toml docs/verification/README.md; do +for f in AGENTS.md CLAUDE.md WORKFLOW.md kit.toml docs/verification/README.md; do chk "adopt wrote $f" "$([ -f "$REPO/$f" ]; echo $?)" done run bash "$KIT/lib/adopt.sh" --check "$REPO" diff --git a/tests/test-gate-opt-in.sh b/tests/test-gate-opt-in.sh index 5fb8bc39f..5ecb22635 100755 --- a/tests/test-gate-opt-in.sh +++ b/tests/test-gate-opt-in.sh @@ -55,24 +55,24 @@ printf '[gate]\ncommit_format = true\n' > "$C/.kit.toml"; hook commit-format.sh echo "== adopt seeds explicit values ==" A="$TMP/adopt-default"; bare "$A"; bash "$KIT_DIR/lib/adopt.sh" "$A" >/dev/null 2>&1 -{ grep -q '^\[gate\]' "$A/.kit.toml" && grep -q '^proof_of_done = true$' "$A/.kit.toml" && grep -q '^lane_gates = true$' "$A/.kit.toml" \ - && grep -q '^commit_format = false$' "$A/.kit.toml" && grep -q '^understanding_gate = false$' "$A/.kit.toml" && grep -q 'understanding_gate .*Stop hook' "$A/.kit.toml"; } \ - && pass "no overlay: adopt seeds proof_of_done and lane_gates true, the other opt-in keys false, each explained" || fail "default seed wrong: $(grep -n 'gate\|_gate\|proof' "$A/.kit.toml" | head -4)" -grep -q 'proof_of_done = false' "$A/.kit.toml" && grep -q 'lane_gates = false' "$A/.kit.toml" \ +{ grep -q '^\[dev\.gate\]' "$A/kit.toml" && grep -q '^proof_of_done = true$' "$A/kit.toml" && grep -q '^lane_gates = true$' "$A/kit.toml" \ + && grep -q '^commit_format = false$' "$A/kit.toml" && grep -q '^understanding_gate = false$' "$A/kit.toml" && grep -q 'understanding_gate .*Stop hook' "$A/kit.toml"; } \ + && pass "no overlay: adopt seeds proof_of_done and lane_gates true, the other opt-in keys false, each explained" || fail "default seed wrong: $(grep -n 'gate\|_gate\|proof' "$A/kit.toml" | head -4)" +grep -q 'proof_of_done = false' "$A/kit.toml" && grep -q 'lane_gates = false' "$A/kit.toml" \ && pass "the seed says how to turn each seeded gate off" || fail "no turn-off line in the seed" bash "$KIT_DIR/lib/gate/gate-policy.sh" enabled proof_of_done "$A" && bash "$KIT_DIR/lib/gate/gate-policy.sh" enabled lane_gates "$A" \ && pass "the seeded repo resolves both gates on" || fail "seeded repo did not resolve on" B="$TMP/adopt-on"; bare "$B"; KIT_CONFIG_OPERATOR="$KIT_DIR/tests/fixtures/gates-on" bash "$KIT_DIR/lib/adopt.sh" "$B" >/dev/null 2>&1 -grep -q '^proof_of_done = true$' "$B/.kit.toml" && grep -q '^commit_format = true$' "$B/.kit.toml" && pass "gates-on overlay: adopt seeds true (the preset follows the operator)" || fail "overlay not reflected in seed" +grep -q '^proof_of_done = true$' "$B/kit.toml" && grep -q '^commit_format = true$' "$B/kit.toml" && pass "gates-on overlay: adopt seeds true (the preset follows the operator)" || fail "overlay not reflected in seed" OFF="$TMP/operator-off"; mkdir -p "$OFF"; printf '[gate]\nproof_of_done = false\n' > "$OFF/kit.toml" D="$TMP/adopt-op-off"; bare "$D"; KIT_CONFIG_OPERATOR="$OFF" bash "$KIT_DIR/lib/adopt.sh" "$D" >/dev/null 2>&1 -{ grep -q '^proof_of_done = false$' "$D/.kit.toml" && grep -q '^lane_gates = true$' "$D/.kit.toml"; } \ +{ grep -q '^proof_of_done = false$' "$D/kit.toml" && grep -q '^lane_gates = true$' "$D/kit.toml"; } \ && pass "an operator overlay that names proof_of_done = false wins over the adopt default" || fail "operator false not honored in seed" -E="$TMP/adopt-existing"; bare "$E"; printf '[gate]\nlane_gates = false\n' > "$E/.kit.toml"; cp "$E/.kit.toml" "$TMP/existing.before" +E="$TMP/adopt-existing"; bare "$E"; printf '[dev.gate]\nlane_gates = false\n' > "$E/kit.toml"; cp "$E/kit.toml" "$TMP/existing.before" bash "$KIT_DIR/lib/adopt.sh" "$E" >/dev/null 2>&1; bash "$KIT_DIR/lib/adopt.sh" --refresh "$E" >/dev/null 2>&1 -cmp -s "$E/.kit.toml" "$TMP/existing.before" && pass "an existing .kit.toml is byte-identical after adopt and --refresh (no key added or flipped)" || fail "existing .kit.toml was changed" -F="$TMP/adopt-twice"; bare "$F"; bash "$KIT_DIR/lib/adopt.sh" "$F" >/dev/null 2>&1; cp "$F/.kit.toml" "$TMP/twice.before"; bash "$KIT_DIR/lib/adopt.sh" "$F" >/dev/null 2>&1 -cmp -s "$F/.kit.toml" "$TMP/twice.before" && pass "re-running adopt leaves the seeded .kit.toml unchanged (idempotent)" || fail "second adopt changed the seed" +cmp -s "$E/kit.toml" "$TMP/existing.before" && pass "an existing kit.toml is byte-identical after adopt and --refresh (no key added or flipped)" || fail "existing kit.toml was changed" +F="$TMP/adopt-twice"; bare "$F"; bash "$KIT_DIR/lib/adopt.sh" "$F" >/dev/null 2>&1; cp "$F/kit.toml" "$TMP/twice.before"; bash "$KIT_DIR/lib/adopt.sh" "$F" >/dev/null 2>&1 +cmp -s "$F/kit.toml" "$TMP/twice.before" && pass "re-running adopt leaves the seeded kit.toml unchanged (idempotent)" || fail "second adopt changed the seed" echo "== install prints the how-to ==" grep -q "OFF by default. Turn one on per repo" "$KIT_DIR/install.sh" && pass "install.sh ends with the gates how-to tip" || fail "install tip missing" diff --git a/tests/test-gate-opt-out.sh b/tests/test-gate-opt-out.sh index 87d88d2ab..a41bd319f 100755 --- a/tests/test-gate-opt-out.sh +++ b/tests/test-gate-opt-out.sh @@ -116,7 +116,7 @@ bash "$P" >/dev/null 2>&1; rc=$?; [ $rc -eq 64 ] && pass "no verb -> usage, exit echo "== adopt seeds the block with the resolved values ==" A="$TMP/adopt"; bare "$A" bash "$KIT_DIR/lib/adopt.sh" "$A" >/dev/null 2>&1 -{ grep -q '^\[gate\]' "$A/.kit.toml" && grep -q '^proof_of_done = true$' "$A/.kit.toml"; } && pass "fresh adopt under a gates-on overlay seeds [gate] proof_of_done = true (the preset follows the operator)" || fail "adopt seed shape wrong: $(grep -n 'gate\|proof_of_done' "$A/.kit.toml" 2>&1 | head -3)" +{ grep -q '^\[dev\.gate\]' "$A/kit.toml" && grep -q '^proof_of_done = true$' "$A/kit.toml"; } && pass "fresh adopt under a gates-on overlay seeds [dev.gate] proof_of_done = true (the preset follows the operator)" || fail "adopt seed shape wrong: $(grep -n 'gate\|proof_of_done' "$A/kit.toml" 2>&1 | head -3)" echo "== safety gate has no key ==" S="$TMP/safety"; bare "$S" diff --git a/tests/test-lanes-data.sh b/tests/test-lanes-data.sh index 497f4292c..86b97cb10 100644 --- a/tests/test-lanes-data.sh +++ b/tests/test-lanes-data.sh @@ -1713,6 +1713,129 @@ case_lane_rank_one_source() { fi } +# Unified kit.toml ([dev.*]) + [repo].door_paths and repokit.toml door_paths auto-inheritance. +case_door_paths_kit_toml() { + local out bad="" + mkrepo + _git checkout -q main >/dev/null 2>&1 + rm -f "$ROOT/.kit.toml" + cat > "$ROOT/kit.toml" <<'TOML' +[repo] +profile = "public-app" +door_paths = [ + "deploy/macos/firewall.sh", # inline comment + "internal/ghauth/", + "SECURITY.md", +] + +[dev.gate] +lane_gates = true +TOML + _commit "chore: unified kit.toml with door_paths" + _git checkout -q -B feat/x >/dev/null 2>&1 + # Exact file path in door_paths raises floor to full (zero extra_hard_paths) + addfile deploy/macos/firewall.sh "echo fw" + out="$(floor_out)" + case "$out" in "full extra: deploy/macos/firewall.sh") ;; *) bad="$bad [firewall.sh => '$out']" ;; esac + # Literal dot escaping: firewallXsh must NOT match deploy/macos/firewall.sh + mkrepo_keep_config; addfile deploy/macos/firewallXsh "echo not-dot" + out="$(floor_out)"; [ -z "$out" ] || bad="$bad [firewallXsh should not hit: '$out']" + # Directory prefix matches nested files + mkrepo_keep_config; addfile internal/ghauth/sub/token.go "package ghauth" + out="$(floor_out)" + case "$out" in "full extra: internal/ghauth/sub/token.go") ;; *) bad="$bad [ghauth => '$out']" ;; esac + # Directory prefix does NOT match sibling with shared prefix + mkrepo_keep_config; addfile internal/ghauth2/app.go "package ghauth2" + out="$(floor_out)"; [ -z "$out" ] || bad="$bad [ghauth2 should not hit: '$out']" + # Exact .md door path (SECURITY.md) raises floor to full + mkrepo_keep_config; addfile SECURITY.md "policy" + out="$(floor_out)" + case "$out" in "full extra: SECURITY.md") ;; *) bad="$bad [SECURITY.md => '$out']" ;; esac + # Negative control: unrelated path stays non-full + mkrepo_keep_config; addfile src/app.go "package app" + out="$(floor_out)"; [ -z "$out" ] || bad="$bad [src/app.go should not hit: '$out']" + # Negative control: removing the door_paths entry drops the floor + _git checkout -q main >/dev/null 2>&1 + cat > "$ROOT/kit.toml" <<'TOML' +[repo] +profile = "public-app" +door_paths = [] + +[dev.gate] +lane_gates = true +TOML + _commit "chore: clear door_paths" + _git checkout -q -B feat/x >/dev/null 2>&1 + addfile deploy/macos/firewall.sh "echo fw" + out="$(floor_out)"; [ -z "$out" ] || bad="$bad [cleared door_paths should drop floor: '$out']" + [ -z "$bad" ] && pass door-paths-kit-toml || fail door-paths-kit-toml "$bad" +} + +case_door_paths_repokit_fallback_and_precedence() { + local out bad="" + mkrepo + _git checkout -q main >/dev/null 2>&1 + printf 'door_paths = ["legacy/door.sh", "ops/firewall/"]\n' > "$ROOT/repokit.toml" + _commit "chore: add repokit.toml" + _git checkout -q -B feat/x >/dev/null 2>&1 + addfile legacy/door.sh "echo x" + out="$(floor_out)" + case "$out" in "full extra: legacy/door.sh") ;; *) bad="$bad [repokit fallback => '$out']" ;; esac + mkrepo_keep_config; addfile ops/firewall/rules.sh "echo r" + out="$(floor_out)" + case "$out" in "full extra: ops/firewall/rules.sh") ;; *) bad="$bad [repokit dir => '$out']" ;; esac + # Precedence: kit.toml [repo].door_paths wins over repokit.toml AND unions with [dev.lanes] extra_hard_paths + _git checkout -q main >/dev/null 2>&1 + cat > "$ROOT/kit.toml" <<'TOML' +[repo] +door_paths = ["new/door.sh"] + +[dev.lanes] +extra_hard_paths = "^billing/" +TOML + _commit "chore: add kit.toml door_paths + extra_hard_paths" + _git checkout -q -B feat/x >/dev/null 2>&1 + addfile new/door.sh "echo new" + out="$(floor_out)" + case "$out" in "full extra: new/door.sh") ;; *) bad="$bad [kit.toml door_paths => '$out']" ;; esac + mkrepo_keep_config; addfile billing/charge.py "x=1" + out="$(floor_out)" + case "$out" in "full extra: billing/charge.py") ;; *) bad="$bad [extra_hard_paths union => '$out']" ;; esac + mkrepo_keep_config; addfile legacy/door.sh "echo old" + out="$(floor_out)"; [ -z "$out" ] || bad="$bad [kit.toml should beat repokit.toml: '$out']" + [ -z "$bad" ] && pass door-paths-repokit-fallback-and-precedence || fail door-paths-repokit-fallback-and-precedence "$bad" +} + +case_unified_kit_toml_exempt_and_lane() { + local out bad="" + mkrepo; new_log + _git checkout -q main >/dev/null 2>&1 + rm -f "$ROOT/.kit.toml" + cat > "$ROOT/kit.toml" <<'TOML' +[dev.gate] +lane_gates = true + +[dev.lane.normal] +phases = ["spec", "build", "ship"] + +[[dev.gate.hard_path_exempt]] +paths = ["tools/demo/*"] +kinds = ["auth"] +reason = "public demo script" +TOML + _commit "chore: unified kit.toml lane + exempt" + _git checkout -q -B feat/x >/dev/null 2>&1 + addfile tools/demo/login.sh "echo hi" + out="$(floor_out)"; [ -z "$out" ] || bad="$bad [dev.gate.hard_path_exempt failed: '$out']" + local req; req="$(KIT_PROJECT_ROOT="$ROOT" gl required normal 2>/dev/null | tr '\n' ' ')" + [ "$req" = "spec build ship " ] || bad="$bad [dev.lane.normal required='$req']" + # Editing kit.toml itself hits kit-config hard path + mkrepo_keep_config; printf '\n# edit\n' >> "$ROOT/kit.toml"; _commit "chore: touch kit.toml" + out="$(floor_out)" + case "$out" in "full kit-config: kit.toml") ;; *) bad="$bad [kit.toml hard path => '$out']" ;; esac + [ -z "$bad" ] && pass unified-kit-toml-exempt-and-lane || fail unified-kit-toml-exempt-and-lane "$bad" +} + # --------------------------------------------------------------------------- run_case() { local fn="case_${1//-/_}" @@ -1720,7 +1843,7 @@ run_case() { } # `parity` (byte-identical against the baseline) holds only at the refactor commit; after the # flip the standing check is parity-after-flip. -ALL="lane-rank-one-source parity-after-flip plan-flip four-false-hits webhook-signature-suggests suggest-records explain-suggest-line classify-files-full escalate-suggest floor-paths floor-rename-counts-both-sides floor-data-loss floor-extra-paths-union floor-invalid-extra-ere override-drop-review override-uncommitted override-typo override-no-light pinned-root malformed-array-fails-closed policy-at-base ship-migration-blocks ship-migration-absent-quiet ship-switch-off-on-base ship-flip-gate-in-pr ship-hollow-full-override ship-data-loss ship-no-spec-blocks ship-suggest-advisory workflow-view floor-timing floor-non-ascii hook-timeout floor-submodule override-empty-phases ship-operator-hollow-full ship-push-forms ship-base-is-origin-head ship-checks-pushed-ref ship-slug-quoted risk-verb significance-uses-risk floor-no-leaks override-unknown-lane-name toml-valid ship-merge-base-once override-operator-precedence default-lane-layers start-no-duplicate-skips ship-fail-closed-refs floor-diff-hardening floor-plus-line floor-where-boundary floor-timing-30k default-rejects-tiny safety-push-forms ship-marker-collisions ship-continuation-and-heredoc ship-marker-at-base exempt-reader-rejects exempt-glob-semantics floor-test-paths-not-auth floor-test-paths-other-kinds floor-test-path-notice floor-exempt-fixture-quiet floor-exempt-glob-bounded floor-exempt-per-kind floor-exempt-migration-only floor-exempt-notice-rules floor-exempt-real-auth-still-hits floor-exempt-working-tree-ignored floor-exempt-forbidden-kinds-rejected floor-exempt-reason-required floor-exempt-canary-rejected floor-exempt-malformed-rejected floor-exempt-never-kit-config floor-exempt-old-shape-ignored floor-exempt-data-loss-still-hits classify-files-exempt ship-exempt-in-pr-blocks ship-exempt-logged ship-test-path-skip-visible ship-notices-env-ignored ship-rid-folded floor-data-loss-sqli-canonical floor-data-loss-sqli-guards floor-data-loss-sqli-paths floor-data-loss-sqli-crossline floor-data-loss-sqli-show-fails floor-data-loss-sqli-cap floor-data-loss-sqli-optin floor-data-loss-sqli-payload floor-data-loss-sqli-tab-path floor-data-loss-sqli-review-repros floor-data-loss-sqli-awk-fails ship-sqli-skip-visible floor-data-loss-sqli-long-line floor-data-loss-sqli-many-lines floor-data-loss-sqli-big-head kit-own-session-not-auth" +ALL="lane-rank-one-source parity-after-flip plan-flip four-false-hits webhook-signature-suggests suggest-records explain-suggest-line classify-files-full escalate-suggest floor-paths floor-rename-counts-both-sides floor-data-loss floor-extra-paths-union floor-invalid-extra-ere override-drop-review override-uncommitted override-typo override-no-light pinned-root malformed-array-fails-closed policy-at-base ship-migration-blocks ship-migration-absent-quiet ship-switch-off-on-base ship-flip-gate-in-pr ship-hollow-full-override ship-data-loss ship-no-spec-blocks ship-suggest-advisory workflow-view floor-timing floor-non-ascii hook-timeout floor-submodule override-empty-phases ship-operator-hollow-full ship-push-forms ship-base-is-origin-head ship-checks-pushed-ref ship-slug-quoted risk-verb significance-uses-risk floor-no-leaks override-unknown-lane-name toml-valid ship-merge-base-once override-operator-precedence default-lane-layers start-no-duplicate-skips ship-fail-closed-refs floor-diff-hardening floor-plus-line floor-where-boundary floor-timing-30k default-rejects-tiny safety-push-forms ship-marker-collisions ship-continuation-and-heredoc ship-marker-at-base exempt-reader-rejects exempt-glob-semantics floor-test-paths-not-auth floor-test-paths-other-kinds floor-test-path-notice floor-exempt-fixture-quiet floor-exempt-glob-bounded floor-exempt-per-kind floor-exempt-migration-only floor-exempt-notice-rules floor-exempt-real-auth-still-hits floor-exempt-working-tree-ignored floor-exempt-forbidden-kinds-rejected floor-exempt-reason-required floor-exempt-canary-rejected floor-exempt-malformed-rejected floor-exempt-never-kit-config floor-exempt-old-shape-ignored floor-exempt-data-loss-still-hits classify-files-exempt ship-exempt-in-pr-blocks ship-exempt-logged ship-test-path-skip-visible ship-notices-env-ignored ship-rid-folded floor-data-loss-sqli-canonical floor-data-loss-sqli-guards floor-data-loss-sqli-paths floor-data-loss-sqli-crossline floor-data-loss-sqli-show-fails floor-data-loss-sqli-cap floor-data-loss-sqli-optin floor-data-loss-sqli-payload floor-data-loss-sqli-tab-path floor-data-loss-sqli-review-repros floor-data-loss-sqli-awk-fails ship-sqli-skip-visible floor-data-loss-sqli-long-line floor-data-loss-sqli-many-lines floor-data-loss-sqli-big-head kit-own-session-not-auth door-paths-kit-toml door-paths-repokit-fallback-and-precedence unified-kit-toml-exempt-and-lane" if [ "$#" -eq 0 ]; then set -- $ALL; fi for c in "$@"; do run_case "$c"; done [ "$FAILS" -eq 0 ] diff --git a/tests/test-merge-command.sh b/tests/test-merge-command.sh index 21918f43b..5a39ed2b3 100644 --- a/tests/test-merge-command.sh +++ b/tests/test-merge-command.sh @@ -205,16 +205,26 @@ mkdir -p "$TMPD/shim" cat > "$TMPD/shim/gh" <&2; exit 1 ;; + *) echo "gh: Bad Gateway (HTTP 502)" >&2; exit 1 ;; + esac ;; *contents/.kit.toml*) case "\${MC_SLUG_MODE:-}" in - set) printf '[merge]\ncommand = "bash scripts/pr-merge.sh"\n'; exit 0 ;; + set|kit_set) printf '[merge]\ncommand = "bash scripts/pr-merge.sh"\n'; exit 0 ;; dotted) printf 'merge.command = "bash scripts/pr-merge.sh"\n'; exit 0 ;; - none|hidden) echo "gh: Not Found (HTTP 404)" >&2; exit 1 ;; + none|hidden|kit_dotted) echo "gh: Not Found (HTTP 404)" >&2; exit 1 ;; *) echo "gh: Bad Gateway (HTTP 502)" >&2; exit 1 ;; esac ;; *"contents/?ref="*) - # the directory listing of the same ref: readable for "none", also a 404 for "hidden" (no contents access) - if [ "\${MC_SLUG_MODE:-}" = none ]; then printf 'README.md\nsrc\n'; exit 0; fi + # the directory listing of the same ref: readable for "none"/"set"/"dotted", also a 404 for "hidden" (no contents access) + case "\${MC_SLUG_MODE:-}" in + none|set|dotted) printf 'README.md\nsrc\n'; exit 0 ;; + kit_dotted) printf 'README.md\nkit.toml\n'; exit 0 ;; + esac echo "gh: Not Found (HTTP 404)" >&2; exit 1 ;; esac exec "$TMPD/stub/gh" "\$@" @@ -231,6 +241,20 @@ PATH="$TMPD/shim:$PATH" MC_SLUG_MODE=hidden kit_merge_command_slug owner/name ma chk "slug: a 404 on the file AND on the listing (no contents access): exit 2, not unset" "$([ "$rc" -eq 2 ]; echo $?)" PATH="$TMPD/shim:$PATH" MC_SLUG_MODE=dotted kit_merge_command_slug owner/name main >/dev/null 2>&1; rc=$? chk "slug: the dotted form refuses (exit 2), not unset" "$([ "$rc" -eq 2 ]; echo $?)" +cmd="$(PATH="$TMPD/shim:$PATH" MC_SLUG_MODE=kit_set kit_merge_command_slug owner/name main)"; rc=$? +chk "slug: unified kit.toml [dev.merge] wins over .kit.toml [merge]" "$rc" +chk_has "slug: unified kit.toml [dev.merge] value" "$cmd" "bash scripts/kit-merge.sh" +PATH="$TMPD/shim:$PATH" MC_SLUG_MODE=kit_dotted kit_merge_command_slug owner/name main >/dev/null 2>&1; rc=$? +chk "slug: unified kit.toml dotted dev.merge.command refuses (exit 2)" "$([ "$rc" -eq 2 ]; echo $?)" + +# Unified kit.toml [dev.merge] in a git repo beats .kit.toml [merge] +R_UNI="$(mc_repo_toml uni '[merge] +command = "bash scripts/legacy-merge.sh"')" +printf '[repo]\nprofile = "public-app"\n\n[dev.merge]\ncommand = "bash scripts/unified-merge.sh"\n' > "$R_UNI/kit.toml" +git -C "$R_UNI" add kit.toml; git -C "$R_UNI" commit -qm "add unified kit.toml"; git -C "$R_UNI" push -q origin main +cmd="$(kit_merge_command "$R_UNI")"; rc=$? +chk "repo: unified kit.toml [dev.merge] wins over .kit.toml [merge]" "$rc" +chk_has "repo: unified kit.toml [dev.merge] value" "$cmd" "bash scripts/unified-merge.sh" # =========================================================================== echo "=== wrap merge --apply: the project command merges, the plain merge is never called ===" diff --git a/tests/test-unified-kit-toml.sh b/tests/test-unified-kit-toml.sh new file mode 100755 index 000000000..92b392bdc --- /dev/null +++ b/tests/test-unified-kit-toml.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +# test-unified-kit-toml.sh -- end-to-end verification of unified kit.toml ([dev.*]), +# [repo].door_paths / repokit.toml auto-inheritance, and adopt.sh --refresh migration + +# agents_only = true CLAUDE.md shim cleanup. +set -uo pipefail + +KIT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +export KIT_CONFIG_OPERATOR="${TMPDIR:-/tmp}/kit-no-operator.$$" +NO_CLAUDE="$(mktemp -d "${TMPDIR:-/tmp}/kit.XXXXXX")" || exit 1 +export CLAUDE_DIR="$NO_CLAUDE" +TMPD="$(mktemp -d "${TMPDIR:-/tmp}/kit.XXXXXX")" || exit 1 +trap 'rm -rf "$TMPD" "$NO_CLAUDE"' EXIT + +PASS=0; FAIL=0 +ok() { PASS=$((PASS + 1)); echo "ok - $1"; } +no() { FAIL=$((FAIL + 1)); echo "NOT ok - $1"; } + +newrepo() { + local d; d="$(mktemp -d "$TMPD/repo.XXXXXX")" || return 1 + git -C "$d" init -q -b main + git -C "$d" config user.email t@users.noreply.github.com + git -C "$d" config user.name t + echo hi > "$d/README.md" + git -C "$d" add README.md + git -C "$d" commit -qm "chore: init" + echo "$d" +} + +# 1. Precedence: kit.toml [dev.*] wins over .kit.toml [*]; .kit.toml fallback works. +R1="$(newrepo)" +printf '[gate]\nlane_gates = false\nproof_of_done = false\n[ledger]\nlocation = "legacy"\n' > "$R1/.kit.toml" +printf '[repo]\nprofile = "public-app"\n\n[dev.gate]\nlane_gates = true\n[dev.ledger]\nlocation = "unified"\n' > "$R1/kit.toml" +git -C "$R1" add -A && git -C "$R1" commit -qm "chore: both configs" +v_loc="$(KIT_CONFIG_ROOT="$KIT_DIR" KIT_PROJECT_ROOT="$R1" bash -c "source '$KIT_DIR/lib/config/kit-config.sh'; kit_config_get ledger.location")" +[ "$v_loc" = "unified" ] && ok "kit.toml [dev.*] wins over .kit.toml [*]" || no "precedence: got [$v_loc]" +bash "$KIT_DIR/lib/gate/gate-policy.sh" enabled lane_gates "$R1" && ok "gate-policy: kit.toml [dev.gate] lane_gates=true wins over .kit.toml false" || no "gate-policy lane_gates" +! bash "$KIT_DIR/lib/gate/gate-policy.sh" enabled proof_of_done "$R1" && ok "gate-policy: falls back to .kit.toml proof_of_done=false when absent in kit.toml" || no "gate-policy fallback" + +# 2. [repo].door_paths in kit.toml raises lane floor to full (single-line + multi-line + ERE escaping + negative control). +R2="$(newrepo)" +cat > "$R2/kit.toml" <<'TOML' +[repo] +door_paths = [ + "deploy/macos/firewall.sh", + "internal/ghauth/", +] + +[dev.gate] +lane_gates = true +TOML +git -C "$R2" add -A && git -C "$R2" commit -qm "chore: door_paths" +git -C "$R2" checkout -q -b feat/test +mkdir -p "$R2/deploy/macos" "$R2/internal/ghauth" "$R2/src" +echo "fw" > "$R2/deploy/macos/firewall.sh" +git -C "$R2" add -A && git -C "$R2" commit -qm "chore: touch firewall" +f2="$(bash "$KIT_DIR/lib/classify/lane-classify.sh" floor "$R2" main 2>/dev/null)" +[ "$f2" = "full extra: deploy/macos/firewall.sh" ] && ok "kit.toml [repo].door_paths raises floor to full (zero extra_hard_paths)" || no "door_paths floor: [$f2]" +c2="$(KIT_PROJECT_ROOT="$R2" bash "$KIT_DIR/lib/classify/lane-classify.sh" classify --files "internal/ghauth/token.go" "update helper" 2>/dev/null)" +[ "$c2" = "full" ] && ok "classify --files matches [repo].door_paths directory prefix" || no "classify dir prefix: [$c2]" +c2_dot="$(KIT_PROJECT_ROOT="$R2" bash "$KIT_DIR/lib/classify/lane-classify.sh" classify --files "deploy/macos/firewallXsh" "update helper" 2>/dev/null)" +[ "$c2_dot" = "normal" ] && ok "ERE metacharacter escaping: literal dot does not match X" || no "dot escape failed: [$c2_dot]" +c2_nc="$(KIT_PROJECT_ROOT="$R2" bash "$KIT_DIR/lib/classify/lane-classify.sh" classify --files "src/app.go" "update helper" 2>/dev/null)" +[ "$c2_nc" = "normal" ] && ok "negative control: unrelated path stays normal" || no "unrelated path: [$c2_nc]" + +# Removing door_paths drops the floor (negative control) +git -C "$R2" checkout -q main +printf '[repo]\ndoor_paths = []\n' > "$R2/kit.toml" +git -C "$R2" add kit.toml && git -C "$R2" commit -qm "chore: clear door_paths" +c2_drop="$(KIT_PROJECT_ROOT="$R2" bash "$KIT_DIR/lib/classify/lane-classify.sh" classify --files "deploy/macos/firewall.sh" "update helper" 2>/dev/null)" +[ "$c2_drop" = "normal" ] && ok "negative control: removing door_paths drops floor to normal" || no "removing door_paths: [$c2_drop]" + +# 3. Fallback: legacy repokit.toml door_paths raises lane floor to full; kit.toml [repo].door_paths wins when both exist. +R3="$(newrepo)" +printf 'door_paths = ["ops/net.sh"]\n' > "$R3/repokit.toml" +git -C "$R3" add -A && git -C "$R3" commit -qm "chore: repokit.toml" +c3="$(KIT_PROJECT_ROOT="$R3" bash "$KIT_DIR/lib/classify/lane-classify.sh" classify --files "ops/net.sh" "tweak script" 2>/dev/null)" +[ "$c3" = "full" ] && ok "fallback: legacy repokit.toml door_paths raises lane floor to full" || no "repokit fallback: [$c3]" +printf '[repo]\ndoor_paths = ["sec/key.sh"]\n[dev.lanes]\nextra_hard_paths = "^pay/"\n' > "$R3/kit.toml" +git -C "$R3" add -A && git -C "$R3" commit -qm "chore: kit.toml overrides repokit.toml" +c3_new="$(KIT_PROJECT_ROOT="$R3" bash "$KIT_DIR/lib/classify/lane-classify.sh" classify --files "sec/key.sh" "tweak script" 2>/dev/null)" +c3_ext="$(KIT_PROJECT_ROOT="$R3" bash "$KIT_DIR/lib/classify/lane-classify.sh" classify --files "pay/x.go" "tweak script" 2>/dev/null)" +c3_old="$(KIT_PROJECT_ROOT="$R3" bash "$KIT_DIR/lib/classify/lane-classify.sh" classify --files "ops/net.sh" "tweak script" 2>/dev/null)" +if [ "$c3_new" = "full" ] && [ "$c3_ext" = "full" ] && [ "$c3_old" = "normal" ]; then + ok "precedence: kit.toml [repo].door_paths wins over repokit.toml and unions with extra_hard_paths" +else + no "precedence mismatch (new=$c3_new ext=$c3_ext old=$c3_old)" +fi + +# 4. adopt.sh --refresh migrates .kit.toml -> kit.toml [dev.*] preserving [repo], and cleans 1-line @AGENTS.md shim under agents_only=true. +R4="$(newrepo)" +printf '[repo]\nprofile = "public-app"\ndoor_paths = ["infra/"]\n' > "$R4/kit.toml" +printf '[modules]\nboard = true\n[adopt]\nagents_only = true\n' > "$R4/.kit.toml" +printf '@AGENTS.md\n' > "$R4/CLAUDE.md" +git -C "$R4" add -A && git -C "$R4" commit -qm "chore: pre-migration" +bash "$KIT_DIR/lib/adopt.sh" --refresh "$R4" >/dev/null +if [ ! -e "$R4/.kit.toml" ] && [ ! -e "$R4/CLAUDE.md" ] \ + && grep -q '^\[repo\]' "$R4/kit.toml" && grep -q '^\[dev\.adopt\]' "$R4/kit.toml" \ + && bash "$KIT_DIR/lib/adopt.sh" --check "$R4" >/dev/null; then + ok "adopt --refresh migrates .kit.toml into kit.toml preserving [repo], removes 1-line @AGENTS.md shim, --check passes" +else + no "adopt --refresh end-to-end failed" +fi + +echo "---" +echo "PASS=$PASS FAIL=$FAIL" +[ "$FAIL" -eq 0 ] From 11af50bef265cd03d6bc9bf46d9ad5b80d44ac8f Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Sun, 6 Dec 2026 01:51:26 +0700 Subject: [PATCH 2/9] fix(config): merge migration per key, harden exemption and door floor --- docs/guides/adopt.md | 2 +- .../unified-kit-toml-and-agents-only.md | 4 +- docs/reference/consumer-contract.md | 2 +- ...EC-434-unified-kit-toml-and-agents-only.md | 4 +- lib/adopt.sh | 230 +++++++++++------- lib/classify/lane-classify.sh | 17 +- lib/gate/README.md | 4 +- lib/gate/lane-data.sh | 55 +++-- lib/gate/proof-ledger.sh | 12 +- lib/goal/mega-merge.sh | 1 + tests/test-clean-room.sh | 3 + tests/test-lanes-data.sh | 7 +- tests/test-merge-command.sh | 10 +- tests/test-unified-kit-toml.sh | 121 +++++++++ 14 files changed, 342 insertions(+), 130 deletions(-) diff --git a/docs/guides/adopt.md b/docs/guides/adopt.md index 559ddb189..64018120d 100644 --- a/docs/guides/adopt.md +++ b/docs/guides/adopt.md @@ -33,7 +33,7 @@ _Figure: adoption writes a few small pointer files. The engine stays in the kit 5. Commit what adoption wrote. `lib/adopt.sh` does not commit. To adopt several repos and land one PR each, use `bin/wrap adopt ...`; it is a dry run until you add `--apply`. 6. Open a session in the adopted repo and say `/kit:start`. -**Refresh.** After you edit `[dev.modules]` in `kit.toml`, run `/kit:adopt --refresh`. It re-syncs the `WORKFLOW.md` pointer and the `CLAUDE.md` block and re-wires the project settings file to match. If the repo still uses a legacy `.kit.toml`, `--refresh` migrates it into `kit.toml` under `[dev.*]` (preserving `[repo]` if present) and removes `.kit.toml`. An existing `AGENTS.md` and proof marker are never touched. An old, unmodified kit `AGENTS.md` is replaced only with `--refresh --swap-agents`. +**Refresh.** After you edit `[dev.modules]` in `kit.toml`, run `/kit:adopt --refresh`. It re-syncs the `WORKFLOW.md` pointer and the `CLAUDE.md` block and re-wires the project settings file to match. If the repo still uses a legacy `.kit.toml`, `--refresh` migrates it into `kit.toml` under `[dev.*]` (preserving `[repo]` if present) and removes `.kit.toml`. The merge is per key: a key `kit.toml` already sets wins and every other legacy key is added. `extra_hard_paths` and `hard_path_canaries` are unioned, since both files were read before. Legacy entries that were not in effect (a lane `light` beside `kit.toml` `phases`, exemption tables beside `kit.toml` ones) are kept as comments. An existing `AGENTS.md` and proof marker are never touched. An old, unmodified kit `AGENTS.md` is replaced only with `--refresh --swap-agents`. **Undo.** Nothing removes adoption for you. Delete the files it created, or revert the commit that added them. Removing `docs/verification/README.md` takes the repo out of the ship gate. Remove the `kit:adopt` block from `CLAUDE.md` by hand. diff --git a/docs/implementation-notes/unified-kit-toml-and-agents-only.md b/docs/implementation-notes/unified-kit-toml-and-agents-only.md index 149a18d03..beef014d8 100644 --- a/docs/implementation-notes/unified-kit-toml-and-agents-only.md +++ b/docs/implementation-notes/unified-kit-toml-and-agents-only.md @@ -6,4 +6,6 @@ Spec: `docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md` - `lib/goal/mega-merge.sh` `_merge_config_guard`: emits the exact matched filename (`kit.toml` or `.kit.toml`) in its refusal message rather than a combined `kit.toml/.kit.toml` string so existing consumers and tests asserting `touches .kit.toml` stay backward-compatible while `kit.toml` PRs report `touches kit.toml`. - `lib/adopt.sh` `_adopt_render_dev_sections`: retained the explicit `proof_of_done = false` / `lane_gates = false` turn-off comment inside the seeded `[dev.gate]` header to preserve the existing opt-out documentation contract tested by `tests/test-gate-opt-in.sh`. -- All other behavior matches `SPEC-434` verbatim. +- `lib/adopt.sh` migration: "insert every missing legacy key" has three exceptions, each so the migration cannot weaken a gate. `extra_hard_paths` and `hard_path_canaries` are unioned even when `kit.toml` sets them, because the readers read both files. A legacy lane `light` is left as a comment when `kit.toml` sets that lane's `phases`. Legacy `[[...]]` tables are left as comments when `kit.toml` declares its own. +- `lib/adopt.sh` migration refuses (keeps `.kit.toml`) when either `extra_hard_paths` is not a valid ERE, since joining it would disable the valid one. +- All other behavior matches `SPEC-434`. diff --git a/docs/reference/consumer-contract.md b/docs/reference/consumer-contract.md index c6eedf499..91640797d 100644 --- a/docs/reference/consumer-contract.md +++ b/docs/reference/consumer-contract.md @@ -15,7 +15,7 @@ idempotently. The step numbers match the `# N.` comments in `lib/adopt.sh`. | 2 | `WORKFLOW.md` | Pointer to the installed kit's lane x phase gate matrix | Yes, on `--refresh` (written atomically) | | 3 | `CLAUDE.md` (managed block) | `@AGENTS.md` import + the classify/gate one-liners, inside ` ... ` markers | Yes, on `--refresh` (block replaced; rest of the file untouched) | | 4 | `docs/verification/README.md` | The proof-of-done marker; its presence opts the repo into the ship-gate | Never | -| 5 | `kit.toml` (`[dev.*]`) | Unified project config starter (`[dev.modules]` + `[dev.gate]`), seeded once or appended alongside `[repo]` (see below) | Legacy `.kit.toml` migrated into `kit.toml` on `--refresh`; existing `[dev.*]` / `[repo]` preserved | +| 5 | `kit.toml` (`[dev.*]`) | Unified project config starter (`[dev.modules]` + `[dev.gate]`), seeded once or appended alongside `[repo]` (see below) | Legacy `.kit.toml` migrated into `kit.toml` on `--refresh`, key by key: a key `kit.toml` already sets wins, every other legacy key is added to its `[dev.*]` section, and `[repo]` is untouched | | 6 | `/.claude/settings.json` | Hook wiring for the enabled modules, a targeted `jq` merge | Every run, from the current `kit.toml` (or `.kit.toml`) | | 6b | `/.claude/settings.json`, `/.claude/output-styles/` | The `[output] style` pick, when set | Every run, when a style is set | diff --git a/docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md b/docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md index c962df886..8ec051b88 100644 --- a/docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md +++ b/docs/specs/SPEC-434-unified-kit-toml-and-agents-only.md @@ -21,9 +21,9 @@ References: `lib/config/kit-config.sh`, `lib/config/config.sh`, `lib/config/hook | R1 | Canonical project config is `/kit.toml`, where devkit sections live under `[dev.
]` (`[dev.modules]`, `[dev.gate]`, `[dev.adopt]`, `[dev.lanes]`, `[dev.lane.]`, `[dev.merge]`, `[dev.output]`, `[dev.proof]`, `[dev.ledger]`, `[dev.mega]`, `[dev.sync]`, `[dev.test]`, `[dev.battery]`, `[dev.wrap]`, `[dev.observe]`) and `[[dev.gate.hard_path_exempt]]`. `[repo]` and `[repo.*]` belong to `repokit` and are preserved untouched. | | R2 | Precedence for project reads: `/kit.toml` `[dev.
]` wins over `/.kit.toml` `[
]`, which wins over operator `kit.toml` `[
]`, which wins over kit-root `kit.toml` `[
]`. Unprefixed `[
]` in `/kit.toml` is not read as a project override so devkit's own kit-root `kit.toml` never shadows the operator layer. | | R3 | Every config reader (`kit-config.sh`, `config.sh`, `hook-module.sh`, `merge-command.sh`, `lane-data.sh`, `gate-policy.sh`, `proof-ledger.sh`, `ledger-key.sh`, `wrap-adopt.sh`, `mega-merge.sh`, `dashboard.py`) respects R1 and R2, including committed-at-rev reads (`--at`, `KIT_LANE_PROJECT_AT`, `KIT_FLOOR_CONFIG_AT`) and tracked-clean checks on the specific file that supplied the value. | -| R4 | `lane-classify.sh` treats both `.kit.toml` and `kit.toml` as `kit-config` hard paths; `mega-merge.sh` config guard blocks auto-merge on either; `proof-ledger.sh` treats project-config-only diffs to either as inert. | +| R4 | `lane-classify.sh` treats `.kit.toml`, `kit.toml` and a root `repokit.toml` as `kit-config` hard paths; `mega-merge.sh` config guard blocks auto-merge on either; `proof-ledger.sh` treats a `.kit.toml`-only diff as inert and a `kit.toml` diff as behavior that owes proof. Exemption tables come from `kit.toml` when it declares one under `[dev.gate]`, else `.kit.toml`; canaries come from both; comments declare nothing. | | R5 | `lane_extra_hard_paths` automatically inherits `door_paths` from `[repo]` in `kit.toml`, falling back to `repokit.toml` (`door_paths` at top-level or `[repo]`) when `[repo].door_paths` is not declared in `kit.toml`. Supports single-line and multi-line TOML string arrays in pure POSIX awk. Escapes ERE metacharacters; trailing `/` matches directory prefix (`^`), non-trailing matches exact path or subdir (`^(/|$)`). Unions across working tree, HEAD, and `KIT_FLOOR_CONFIG_AT`, alongside `extra_hard_paths`. | -| R6 | `lib/adopt.sh` fresh adoption writes devkit sections under `[dev.*]` in `kit.toml` (appending `[dev.modules]` and `[dev.gate]` to an existing `kit.toml` that has `[repo]` without clobbering it). `adopt.sh --refresh` migrates an existing `.kit.toml` into `kit.toml` under `[dev.*]` (preserving all values and any existing `[repo]` or `[dev.*]` sections in `kit.toml`), removes `.kit.toml` (`git rm -f` if tracked, `rm -f` otherwise), and is idempotent on re-run. | +| R6 | `lib/adopt.sh` fresh adoption writes devkit sections under `[dev.*]` in `kit.toml` (appending `[dev.modules]` and `[dev.gate]` to an existing `kit.toml` that has `[repo]` without clobbering it). `adopt.sh --refresh` migrates an existing `.kit.toml` into `kit.toml` under `[dev.*]` (merged per key: `kit.toml` wins on a key it sets, `extra_hard_paths` and `hard_path_canaries` are unioned, `[repo]` is untouched), removes `.kit.toml` (`git rm -f` if tracked, `rm -f` otherwise), and is idempotent on re-run. | | R7 | Under `agents_only = true` (`[dev.adopt]` in `kit.toml` or `[adopt]` in `.kit.toml`), `lib/adopt.sh` never creates a `CLAUDE.md` shim. During `adopt.sh --refresh`, if `CLAUDE.md` is a regular non-symlink file whose trimmed content equals `@AGENTS.md`, remove it (`git rm -f` if tracked, `rm -f` otherwise); never remove any custom `CLAUDE.md`. `adopt.sh --check` exits 0 when `CLAUDE.md` is absent. | ## Technical Design diff --git a/lib/adopt.sh b/lib/adopt.sh index 90a291a3c..4c2ae9a74 100755 --- a/lib/adopt.sh +++ b/lib/adopt.sh @@ -488,102 +488,168 @@ _adopt_render_dev_sections() { done } +# _ADOPT_AWK_MAP_HDR: awk map_hdr(line), a .kit.toml section header renamed under dev. +_ADOPT_AWK_MAP_HDR=' + function map_hdr(line, pre, br, name, tail, raw, arr) { + sub(/\r$/, "", line) + raw = line + sub(/^[[:space:]]*/, "", raw) + pre = substr(line, 1, length(line) - length(raw)) + arr = (substr(raw, 1, 2) == "[[") + if (!match(raw, arr ? "^\\[\\[[^]#]+\\]\\]" : "^\\[[^]#]+\\]")) return line + br = substr(raw, 1, RLENGTH) + tail = substr(raw, RLENGTH + 1) + name = br; gsub(/^\[+[[:space:]]*|[[:space:]]*\]+$/, "", name) + if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name + return pre (arr ? "[[" name "]]" : "[" name "]") tail + }' + +# _adopt_ere_ok : 0 when is empty or compiles as an ERE. +_adopt_ere_ok() { + local rc=0 + [ -n "$1" ] || return 0 + printf '' | grep -Eq -- "$1" 2>/dev/null || rc=$? + [ "$rc" -le 1 ] +} + # _adopt_migrate_dotkit -- transform sections to [dev.*] -# and merge cleanly with (preserving [repo] and any pre-existing [dev.*] sections). +# and merge with KEY BY KEY: a key already sets wins, every other legacy key is +# inserted into the matching [dev.*] section, and [repo] is left as it is. Three cases follow what +# the readers did before the migration, so it cannot weaken a gate: +# - extra_hard_paths and hard_path_canaries are read from both files, so they are unioned; +# - a lane's `light` is not inserted when already sets that lane's `phases`; +# - a [[...]] table already declares hid the legacy ones, which are kept as comments. _adopt_migrate_dotkit() { - local src="$1" existing="$2" dest="$3" mig - mig="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || return 1 - if [ -f "$existing" ]; then - awk ' - function norm_hdr(s, h) { - h = s; sub(/[[:space:]]*#.*$/, "", h); gsub(/[[:space:]\r]/, "", h); return h + local src="$1" existing="$2" dest="$3" + if [ ! -f "$existing" ]; then + awk "$_ADOPT_AWK_MAP_HDR"' + { + line = $0; sub(/\r$/, "", line) + if (line ~ /^[[:space:]]*\[/) { print map_hdr(line); next } + print line + } + ' "$src" > "$dest" + return + fi + if ! _adopt_ere_ok "$(_kit_toml_get "$existing" dev.lanes extra_hard_paths)" \ + || ! _adopt_ere_ok "$(_kit_toml_get "$src" lanes extra_hard_paths)"; then + echo "adopt: extra_hard_paths in $src or $existing is not a valid ERE; fix it, then re-run" >&2 + return 1 + fi + awk "$_ADOPT_AWK_MAP_HDR"' + function norm_hdr(s, h) { h = s; sub(/[[:space:]]*#.*$/, "", h); gsub(/[[:space:]\r]/, "", h); return h } + # scan : updates depth (open brackets of a value) and tq (inside a multi-line string). + function scan(s, i, c, q) { + q = "" + for (i = 1; i <= length(s); i++) { + c = substr(s, i, 1) + if (tq != "") { if (substr(s, i, 3) == tq) { tq = ""; i += 2 }; continue } + if (q != "") { if (c == "\\" && q == "\"") i++; else if (c == q) q = ""; continue } + if (substr(s, i, 3) == "\"\"\"" || substr(s, i, 3) == "\047\047\047") { tq = substr(s, i, 3); i += 2; continue } + if (c == "\"" || c == "\047") q = c + else if (c == "#") return + else if (c == "[" || c == "{") depth++ + else if (c == "]" || c == "}") depth-- } - function map_hdr(line, pre, br, name, tail, raw) { - sub(/\r$/, "", line) - raw = line - sub(/^[[:space:]]*/, "", raw) - pre = substr(line, 1, length(line) - length(raw)) - if (match(raw, /^\[\[[[:space:]]*[^]#]+[[:space:]]*\]\]/)) { - br = substr(raw, 1, RLENGTH) - tail = substr(raw, RLENGTH + 1) - name = br; sub(/^\[\[[[:space:]]*/, "", name); sub(/[[:space:]]*\]\]$/, "", name) - if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name - return pre "[[" name "]]" tail + } + function open_value() { return depth > 0 || tq != "" } + function key_of(s, k) { + if (s !~ /^[[:space:]]*[^#=[:space:]][^=]*=/) return "" + k = s; sub(/=.*$/, "", k); gsub(/[[:space:]]/, "", k); return k + } + # strings : adds each quoted element of an array value to U, once. + function strings(text, n, ln, i, s) { + n = split(text, ln, "\n") + for (i = 1; i <= n; i++) { + s = ln[i] + if (i == 1) sub(/^[^=]*=/, "", s) + while (match(s, /^[[:space:],\[\]]*("[^"]*"|\047[^\047]*\047)/)) { + el = substr(s, 1, RLENGTH); s = substr(s, RLENGTH + 1) + sub(/^[[:space:],\[\]]*/, "", el); el = substr(el, 2, length(el) - 2) + if (!(el in U)) { U[el] = 1; UL = UL (UL == "" ? "" : ", ") "\"" el "\"" } } - if (match(raw, /^\[[[:space:]]*[^]#]+[[:space:]]*\]/)) { - br = substr(raw, 1, RLENGTH) - tail = substr(raw, RLENGTH + 1) - name = br; sub(/^\[[[:space:]]*/, "", name); sub(/[[:space:]]*\]$/, "", name) - if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name - return pre "[" name "]" tail + } + } + function scalar(text, s) { + s = text; sub(/^[^=]*=[[:space:]]*/, "", s); sub(/[[:space:]]*#.*$/, "", s); gsub(/^["\047]|["\047]$/, "", s); return s + } + function commented(text, s) { s = text; gsub(/\n/, "\n# ", s); return "# " s } + # emit : one complete legacy `key = value` of section cur, holding every line of it. + function emit(entry, k, id, a, b, i, n, old) { + if (mode == "new") { app = app pend entry "\n"; pend = ""; return } + if (mode == "inert") { app = app commented(pend entry) "\n"; pend = ""; return } + k = key_of(entry); id = cur SUBSEP k + if (!(id in kstart)) { + if (cur ~ /^\[dev\.lane\./ && k == "light" && ((cur SUBSEP "phases") in kstart)) + ins[cur] = ins[cur] "# not in effect before the migration, so left off:\n" commented(entry) "\n" + else ins[cur] = ins[cur] pend entry "\n" + } else if ((cur == "[dev.lanes]" && k == "extra_hard_paths") || (cur == "[dev.gate]" && k == "hard_path_canaries")) { + old = "" + for (i = kstart[id]; i <= kend[id]; i++) old = old (old == "" ? "" : "\n") E[i] + if (k == "extra_hard_paths") { + a = scalar(old); b = scalar(entry) + if (b != "" && a != b) { repl[kstart[id]] = k " = \"" a (a == "" ? "" : "|") b "\""; for (i = kstart[id] + 1; i <= kend[id]; i++) gone[i] = 1 } + } else { + split("", U); UL = ""; strings(old); strings(entry) + repl[kstart[id]] = k " = [" UL "]"; for (i = kstart[id] + 1; i <= kend[id]; i++) gone[i] = 1 } - return line } - NR == FNR { - if ($0 ~ /^[[:space:]]*\[/) { have[norm_hdr($0)] = 1 } + pend = "" + } + fid == 1 { + E[++ne] = $0 + line = $0; sub(/\r$/, "", line) + if (!open_value() && line ~ /^[[:space:]]*\[/) { esec = norm_hdr(line); have[esec] = 1; last[esec] = ne; next } + if (!open_value()) { + if (line ~ /^[[:space:]]*(#|$)/) next + ekey = key_of(line); if (ekey != "") kstart[esec, ekey] = ne + } + scan(line) + if (ekey != "") kend[esec, ekey] = ne + if (esec != "") last[esec] = ne + next + } + FNR == 1 { depth = 0; tq = ""; mode = "preamble" } + { + line = $0; sub(/\r$/, "", line) + if (open_value()) { buf = buf "\n" line; scan(line); if (!open_value()) emit(buf); next } + if (line ~ /^[[:space:]]*\[/) { + mapped = map_hdr(line); cur = norm_hdr(mapped) + # pend holds the comments right above this header: they travel with it. + if (!(cur in have)) { mode = "new"; app = app (app == "" ? "" : "\n") pend mapped "\n" } + else if (substr(cur, 1, 2) == "[[") { + mode = "inert" + app = app (app == "" ? "" : "\n") pend "# Not migrated as live config: kit.toml already declares " cur ", which replaced these.\n# " mapped "\n" + print "adopt: note: " cur " entries from .kit.toml were not in effect (kit.toml declares its own); kept as comments" > "/dev/stderr" + } else mode = "merge" + pend = "" next } - { - line = $0; sub(/\r$/, "", line) - if (line ~ /^[[:space:]]*\[/) { - seen_sec = 1 - mapped = map_hdr(line) - nh = norm_hdr(mapped) - if (nh in have) { skip = 1; next } - skip = 0 - print mapped - next - } - if (!seen_sec) { - # Drop auto-generated .kit.toml header boilerplate when appending to an existing kit.toml + if (line ~ /^[[:space:]]*(#|$)/) { + # Drop the auto-generated .kit.toml header boilerplate. + if (mode == "preamble") { if (line ~ /^# \.kit\.toml --/ || line ~ /^# Only the keys you set here/ \ || line ~ /^# default at / || line ~ /^# Re-run `bash .*adopt\.sh/ \ || line ~ /^# editing \[modules\]/ || line ~ /^# adopt reads \[modules\]/ \ || line ~ /^# true, commit, and that quality gate/ || line ~ /^[[:space:]]*$/) next - } - if (!skip) print line - } - ' "$existing" "$src" > "$mig" || { rm -f "$mig"; return 1; } - cat "$existing" > "$dest" || { rm -f "$mig"; return 1; } - if [ -s "$mig" ]; then - # Ensure a blank line between existing kit.toml content and appended [dev.*] sections. - if [ -s "$dest" ]; then - [ -z "$(tail -c 1 "$dest")" ] || printf '\n' >> "$dest" - printf '\n' >> "$dest" - fi - cat "$mig" >> "$dest" || { rm -f "$mig"; return 1; } - fi - else - awk ' - function map_hdr(line, pre, br, name, tail, raw) { - sub(/\r$/, "", line) - raw = line - sub(/^[[:space:]]*/, "", raw) - pre = substr(line, 1, length(line) - length(raw)) - if (match(raw, /^\[\[[[:space:]]*[^]#]+[[:space:]]*\]\]/)) { - br = substr(raw, 1, RLENGTH) - tail = substr(raw, RLENGTH + 1) - name = br; sub(/^\[\[[[:space:]]*/, "", name); sub(/[[:space:]]*\]\]$/, "", name) - if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name - return pre "[[" name "]]" tail - } - if (match(raw, /^\[[[:space:]]*[^]#]+[[:space:]]*\]/)) { - br = substr(raw, 1, RLENGTH) - tail = substr(raw, RLENGTH + 1) - name = br; sub(/^\[[[:space:]]*/, "", name); sub(/[[:space:]]*\]$/, "", name) - if (name !~ /^(dev(\.|$)|repo(\.|$))/) name = "dev." name - return pre "[" name "]" tail - } - return line + app = app line "\n" + } else if (line ~ /^[[:space:]]*#/) pend = pend line "\n" + else if (mode == "merge") pend = "" + next } - { - line = $0; sub(/\r$/, "", line) - if (line ~ /^[[:space:]]*\[/) { print map_hdr(line); next } - print line + if (key_of(line) == "") next + buf = line; scan(line); if (!open_value()) emit(buf) + } + END { + for (s in ins) at[last[s]] = at[last[s]] ins[s] + for (i = 1; i <= ne; i++) { + if (i in repl) print repl[i]; else if (!(i in gone)) print E[i] + if (i in at) printf "%s", at[i] } - ' "$src" > "$dest" || { rm -f "$mig"; return 1; } - fi - rm -f "$mig" + if (mode != "merge") app = app pend + if (app != "") { if (ne) print ""; printf "%s", app } + } + ' fid=1 "$existing" fid=2 "$src" > "$dest" } if [ -n "$kit_root_toml" ] && [ "$RESOLVER_OK" -eq 1 ]; then diff --git a/lib/classify/lane-classify.sh b/lib/classify/lane-classify.sh index 8faaf8fb6..8245f16b5 100755 --- a/lib/classify/lane-classify.sh +++ b/lib/classify/lane-classify.sh @@ -116,7 +116,8 @@ _HP_auth='(^|/)(auth(entication|orization|orisation|n|z|[_-][a-z_-]*)?|oauth|rba _HP_secret='(^|/)\.env(\.(local|dev|development|prod|production|staging|test))?$|(^|/)secrets?/|\.(pem|key|p12|pfx)$|(^|/)[^/]*credentials?[^/]*$' _HP_ci='(^|/)\.github/' _HP_infra='(^|/)Dockerfile[^/]*$|(^|/)[^/]*(iam|role|polic)[^/]*\.tf$|(^|/)(iam|policies)/[^/]*\.tf$' -_HP_kitconfig='(^|/)\.?kit\.toml$' +# repokit.toml at the root feeds the door_paths floor, so one push cannot drop a door and edit behind it. +_HP_kitconfig='(^|/)\.?kit\.toml$|^repokit[.]toml$' # Test paths never count as kind `auth` (every other kind still matches them). Fixed, case-sensitive, # not configurable: a config hook here would be a second, unreviewed exemption path. # The data-loss sqli carve-out keeps its own _HL_sqli_testpath below; neither list feeds the other. @@ -565,7 +566,8 @@ _floor_git() { # floor-exempt auth test-path - built-in test-path default - # A kind with no records runs no entry grep, and no pattern is ever empty. _floor_blank() { - local tmp="$1" k="$2" short="$3" n ere re list="$tmp/paths" + local tmp="$1" k="$2" short="$3" n ere re + local list="$tmp/paths" re="$(_hp_re "$k")" : > "$tmp/m_$k" while IFS=$'\t' read -r n _ ere _; do @@ -905,7 +907,8 @@ AWK # Returns 1 on any read error, more than 50 files, a file over 200000 bytes, a byte count that is not all # digits, or a file the base program cannot classify; the caller then keeps the floor. _floor_wf_read() { - local root="$1" rev="$2" out="$3" tmp="$4" f n=0 img="$tmp/wf.rd" list="$tmp/wf.ls" bytes cr=$'\r' + local root="$1" rev="$2" out="$3" tmp="$4" f n=0 bytes cr=$'\r' + local img="$tmp/wf.rd" list="$tmp/wf.ls" _floor_git "$root" ls-tree -r -z --name-only "$rev" -- .github/workflows > "$list" 2>/dev/null || return 1 while IFS= read -r -d '' f; do n=$((n + 1)); [ "$n" -le 50 ] || return 1 @@ -928,7 +931,8 @@ _floor_wf_read() { # than the expected one returns 1 and the floor stands. No `git show` output is piped into a test here: each # image is read once into a file and its exit status is tested. _floor_workflow_additive() { - local root="$1" base="$2" head="$3" tmp="$4" n="$5" kind="$6" path st hm k extra rc rev def bytes img="$tmp/wf.img" + local root="$1" base="$2" head="$3" tmp="$4" n="$5" kind="$6" path st hm k extra rc rev def bytes + local img="$tmp/wf.img" [ "$kind" = ci ] || return 1 path="$(sed -n "${n}p" "$tmp/paths")"; st="$(sed -n "${n}p" "$tmp/status")"; hm="$(sed -n "${n}p" "$tmp/hmode")" [ -n "$path" ] || return 1 @@ -1008,7 +1012,8 @@ _floor_sqli_note() { printf 'floor-note\tdata-loss\tsqli-fallback\t%s\n' "$1" >& # the file's head image reads cleanly with no multi-line string opener, pass B exits 0 and the line # count holds. Any doubt keeps the raw lines and prints one floor-note. Bounded to 20 files and 5 s. _floor_sqli() { - local root="$1" head="$2" tmp="$3" p n=0 t0=$SECONDS img="$tmp/sqli-img" unread=0 d=dr lit + local root="$1" head="$2" tmp="$3" p n=0 t0=$SECONDS unread=0 d=dr lit + local img="$tmp/sqli-img" local env=(LC_ALL=C KIT_SQLI_PAY="$_HL_sqli_payload" KIT_SQLI_TP="$_HL_sqli_testpath" KIT_SQLI_EXT="$_HL_sqli_ext" KIT_SQLI_JOIN="$_HL_sqli_join") # Self-test: the literal after `in` must be rewritten, the same literal after `=` must stay. The @@ -1154,7 +1159,7 @@ main() { deescalate) deescalate "$@";; lanes) printf '%s\n' $LANE_NAMES;; flags) printf '%s\n' "${_hard_name[@]}" "${_soft_name[@]}";; - *) echo "usage: lane-classify.sh {classify [--files \"\"] \"\"|explain [--files ...] \"\"|check [--files ...] \"\"|risk [--files ""] [--rid ] ""|escalate |floor []|deescalate [--rid ] [--root ] [--base ] [--floor ]|lanes|flags}" >&2; return 64;; + *) echo "usage: lane-classify.sh {classify [--files \"\"] \"\"|explain [--files ...] \"\"|check [--files ...] \"\"|risk [--files \"\"] [--rid ] \"\"|escalate |floor []|deescalate [--rid ] [--root ] [--base ] [--floor ]|lanes|flags}" >&2; return 64;; esac } diff --git a/lib/gate/README.md b/lib/gate/README.md index 8ae6db31c..7eaf75ed1 100644 --- a/lib/gate/README.md +++ b/lib/gate/README.md @@ -179,7 +179,7 @@ silently. Proof: `tests/test-gate-ledger-amend.sh`. ### The hard-path floor and what it ignores -`ship_rule_floor` makes a diff that touches a hard path (migration, auth, secret, CI, infra or kit config) owe the full lane's gates, whatever lane the spec names. It does not count a diff +`ship_rule_floor` makes a diff that touches a hard path (migration, auth, secret, CI, infra or kit config: `kit.toml`, `.kit.toml`, or a root `repokit.toml`) owe the full lane's gates, whatever lane the spec names. It does not count a diff that only changes documentation, or one whose changed lines in a non-doc file are blank lines or `#` comments (`lane-classify.sh floor`). Anything it cannot decide keeps the floor: a secret-pattern path, a symlink, a gitlink, an unknown file type, a mode change, a NUL byte, a @@ -234,7 +234,7 @@ where a review sees it. Pulling a branch that flips a key flips it for your own branch too. `adopt` seeds the block with the values that resolved at adopt time (operator, else the kit default), each key explained in a comment; delete a line to follow the operator setting again. The proof classifier treats a `.kit.toml`-only diff as inert, whatever key it touches: -harness config owes no proof-of-done. Proof: `tests/test-gate-opt-out.sh`, `tests/test-gate-opt-in.sh`. +harness config owes no proof-of-done. A `kit.toml` diff is not inert and still owes proof. Proof: `tests/test-gate-opt-out.sh`, `tests/test-gate-opt-in.sh`. ## The merged check diff --git a/lib/gate/lane-data.sh b/lib/gate/lane-data.sh index 390ee47cd..f6d8ddd9f 100644 --- a/lib/gate/lane-data.sh +++ b/lib/gate/lane-data.sh @@ -383,17 +383,20 @@ lane_extra_hard_paths() { done | sort -u } -# lane_hard_path_exempt : the hard-path exemption records from the .kit.toml committed at -# , else nothing. Only that copy counts: no working tree, no operator overlay, no kit root. +# lane_hard_path_exempt : the hard-path exemption records from the project config committed +# at , else nothing. Only those copies count: no working tree, no operator overlay, no kit root. # Callers pass the merge base, so a PR cannot exempt its own push. The config is the array of -# tables [[gate.hard_path_exempt]] (keys paths, kinds, reason; kinds auth or migration only). +# tables [[dev.gate.hard_path_exempt]] in kit.toml, or [[gate.hard_path_exempt]] in .kit.toml (keys +# paths, kinds, reason; kinds auth or migration only). Entries come from ONE file: kit.toml when it +# declares such a table, else .kit.toml. Canaries come from BOTH. In kit.toml only [dev.*] sections +# are read, and a full-line comment never declares anything. # Everything is validated before anything prints: any invalid entry refuses the WHOLE config (stdout # empty, one stderr line per problem). Exit 0 always. Records, one per (entry, kind), TAB-separated: # # Not a TOML parser: it accepts exactly one-line arrays and double-quoted strings, and refuses the rest. # A glob uses A-Z a-z 0-9 . _ - / @ + ~ * ?; `*` and `?` stay in one segment, `**` is a whole segment # and crosses directories, and the match is anchored. An entry whose glob matches a canary is invalid: -# the built-in list below plus [gate] hard_path_canaries (literal paths) from the same . +# the built-in list below plus [dev.gate] / [gate] hard_path_canaries (literal paths) from the same . _LD_EXEMPT_CANARIES='src/auth/login.ts lib/session.ts app/auth.py @@ -402,21 +405,27 @@ config/secrets/prod.txt db/migrations/0001_init.sql .github/workflows/ci.yml Dockerfile' +# _ld_mentions_exempt : 0 when a non-comment line mentions an exemption or canary key. +_ld_mentions_exempt() { + [ -n "$(awk '!/^[[:space:]]*#/ && /hard_path_(exempt|canaries)/ { print; exit }' "$1" 2>/dev/null)" ] +} lane_hard_path_exempt() { - local root="$1" rev="$2" tmp can sha pfx="" + local root="$1" rev="$2" kit leg can sha kit_ent=0 leg_ent=1 [ -n "$root" ] && [ -n "$rev" ] || return 0 - tmp="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || return 0 - if kit_config_show_kit_at "$root" "$rev" > "$tmp" 2>/dev/null && grep -q 'hard_path_exempt\|hard_path_canaries' "$tmp"; then - pfx="dev." - elif kit_config_show_legacy_at "$root" "$rev" > "$tmp" 2>/dev/null && grep -q 'hard_path_exempt\|hard_path_canaries' "$tmp"; then - pfx="" - else - command rm -f "$tmp"; return 0 + kit="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || return 0 + leg="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || { command rm -f "$kit"; return 0; } + kit_config_show_kit_at "$root" "$rev" >| "$kit" 2>/dev/null || : >| "$kit" + kit_config_show_legacy_at "$root" "$rev" >| "$leg" 2>/dev/null || : >| "$leg" + if ! _ld_mentions_exempt "$kit" && ! _ld_mentions_exempt "$leg"; then + command rm -f "$kit" "$leg"; return 0 + fi + if grep -Eq '^[[:space:]]*\[+[[:space:]]*dev[[:space:]]*\.[[:space:]]*gate[[:space:]]*\.[[:space:]]*hard_path_exempt' "$kit"; then + kit_ent=1; leg_ent=0 fi - can="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || { command rm -f "$tmp"; return 0; } + can="$(mktemp "${TMPDIR:-/tmp}/kit.XXXXXX")" || { command rm -f "$kit" "$leg"; return 0; } printf '%s\n' "$_LD_EXEMPT_CANARIES" > "$can" sha="$(git -C "$root" rev-parse --short "$rev" 2>/dev/null || printf '%s' "$rev")" - awk -v sha="$sha" -v pfx="$pfx" -v BOM="$(printf '\357\273\277')" ' + awk -v sha="$sha" -v BOM="$(printf '\357\273\277')" ' function trim(s) { sub(/^[[:space:]]+/, "", s); sub(/[[:space:]]+$/, "", s); return s } function sw(v, i) { while (substr(v, i, 1) ~ /[ \t]/) i++; return i } function cfgerr(m) { cerr[++ncerr] = m } @@ -489,21 +498,25 @@ lane_hard_path_exempt() { return out } NR == FNR { can[++nc] = $0; next } + # pfx, ent and fid are set per file on the command line. Section state never crosses a file. + FNR == 1 { sec = (pfx == "") ? "other" : "outside" } { line = $0; sub(/\r$/, "", line); if (FNR == 1 && index(line, BOM) == 1) line = substr(line, 1 + length(BOM)); t = trim(line) } t == "" || t ~ /^#/ { next } - index(t, "\"\"\"") || index(t, "\047\047\047") { tq = 1 } + index(t, "\"\"\"") || index(t, "\047\047\047") { tq[fid] = 1 } t ~ /^\[/ { h = t; sub(/[[:space:]]*#.*$/, "", h); hn = h; gsub(/[[:space:]]/, "", hn) - sec = "other" + sec = (pfx != "" && hn !~ /^\[+dev[.\]]/) ? "outside" : "other" + if (!ent && index(hn, pfx "gate.hard_path_exempt]")) next if (hn == "[[" pfx "gate.hard_path_exempt]]") { - hdr = 1 + hdr[fid] = 1 if (h != "[[" pfx "gate.hard_path_exempt]]") cfgerr("line " FNR ": the header must be exactly [[" pfx "gate.hard_path_exempt]]") else { cur = ++ne; sec = "ent" } } else if (hn == "[" pfx "gate.hard_path_exempt]") { - hdr = 1; cfgerr("line " FNR ": use the array-of-tables header [[" pfx "gate.hard_path_exempt]], not [" pfx "gate.hard_path_exempt]") + hdr[fid] = 1; cfgerr("line " FNR ": use the array-of-tables header [[" pfx "gate.hard_path_exempt]], not [" pfx "gate.hard_path_exempt]") } else if (hn == "[" pfx "gate]") sec = "gate" next } + sec == "outside" { next } # kit.toml: only [dev.*] is project config sec == "ent" { if (t !~ /^[A-Za-z_][A-Za-z0-9_-]*[[:space:]]*=/) { eerr(cur, "line " FNR ": expected a key = value line"); next } key = t; sub(/[[:space:]]*=.*$/, "", key); val = t; sub(/^[^=]*=[[:space:]]*/, "", val) @@ -528,7 +541,7 @@ lane_hard_path_exempt() { } index(t, "hard_path_canaries") { cfgerr("line " FNR ": hard_path_canaries is read only as a key under [gate]") } END { - if (tq && hdr) cfgerr("the file holds a multi-line string; a table inside one cannot be told from an entry") + if ((tq[1] && hdr[1]) || (tq[2] && hdr[2])) cfgerr("the file holds a multi-line string; a table inside one cannot be told from an entry") if (ne > 32) cfgerr(ne " entries; the limit is 32") for (e = 1; e <= ne; e++) { m = err[e] @@ -558,7 +571,7 @@ lane_hard_path_exempt() { for (x = 1; x <= NK[e]; x++) { k = K[e, x]; if (done[k]++) continue; print e "\t" k "\t" ere "\t" globs "\t" R[e] } } } - ' "$can" "$tmp" - command rm -f "$tmp" "$can" + ' "$can" fid=1 pfx=dev. ent="$kit_ent" "$kit" fid=2 pfx= ent="$leg_ent" "$leg" + command rm -f "$kit" "$leg" "$can" return 0 } diff --git a/lib/gate/proof-ledger.sh b/lib/gate/proof-ledger.sh index 6744f96f5..4b831ee75 100755 --- a/lib/gate/proof-ledger.sh +++ b/lib/gate/proof-ledger.sh @@ -102,7 +102,7 @@ _subjects() { git -C "$1" log "$2"..HEAD --format='%s' 2>/dev/null || true; } _nondoc_paths() { awk '{ lc = tolower($0) } lc ~ /(^|\/)[^\/]*credentials?[^\/]*$|(^|\/)secrets?\/|\.(pem|key|p12|pfx)$|(^|\/)\.env/ { print; next } - $0 ~ /\.(md|txt|markdown)$/ || $0 ~ /(^|\/)\.?kit\.toml$/ { next } + $0 ~ /\.(md|txt|markdown)$/ || $0 ~ /(^|\/)\.kit\.toml$/ { next } ($0 ~ /(^|\/)docs\// && $0 ~ /\.(rst|adoc|png|jpe?g|gif|webp|pdf|csv)$/) || ($0 ~ /^docs\// && $0 ~ /\.(html?|svg)$/) { next } { print }' } @@ -195,14 +195,14 @@ delivery_ratio() { [ -n "$root" ] && [ -n "$base" ] || { echo "usage: delivery-ratio " >&2; return 64; } git -C "$root" rev-parse --verify -q "$base" >/dev/null 2>&1 \ || { echo "real=0 proof=0 | SKIP: base '$base' is not a commit"; return 0; } - local real=0 proof=0 add del path - while IFS=$'\t' read -r add del path; do + local real=0 proof=0 add path + while IFS=$'\t' read -r add _ path; do [ -n "$path" ] || continue [ "$add" = "-" ] && continue # binary file: no line count case "$path" in */proof-of-done.md|docs/proof/*|*/docs/proof/*|docs/verification/*|*/docs/verification/*|docs/specs/*|*/docs/specs/*|docs/implementation-notes/*|*/docs/implementation-notes/*|docs/runs/*|*/docs/runs/*|docs/decisions/*|*/docs/decisions/*|tests/*|*/tests/*) proof=$((proof+add)) ;; - *.lock|*/uv.lock|*/package-lock.json|*/pnpm-lock.yaml|*/Cargo.lock|*/go.sum) + *.lock|*/package-lock.json|*/pnpm-lock.yaml|*/go.sum) : ;; # generated lockfiles: ignore *) real=$((real+add)) ;; @@ -503,10 +503,10 @@ _visual_proof() { # existing path; git ls-files decides tracked (a gitignored or untracked file, the # .kit/proof-assets/ cache, never counts), and membership in the branch's changed # files stops an old tracked public/logo.png from excusing a new UI diff forever. - local pf ilink ipath + local pf ipath while IFS= read -r pf; do [ -n "$pf" ] || continue - while IFS=$'\t' read -r ilink ipath; do + while IFS=$'\t' read -r _ ipath; do [ -n "$ipath" ] || continue git -C "$root" ls-files --error-unmatch "$ipath" >/dev/null 2>&1 \ && grep -qxF "$ipath" < <(printf '%s\n' "$changed") && return 0 diff --git a/lib/goal/mega-merge.sh b/lib/goal/mega-merge.sh index 71c4b1011..c010d1853 100755 --- a/lib/goal/mega-merge.sh +++ b/lib/goal/mega-merge.sh @@ -211,6 +211,7 @@ _ship_rules_gate_head() { # order of spec_for_slug. Prints nothing when there is none. _spec_in_tree() { local root="$1" sha="$2" rid="$3" p rootpick="" colo="" n + # shellcheck source=lib/spec/spec-find.sh [ -r "$SPEC_FIND" ] && source "$SPEC_FIND" 2>/dev/null || return 0 while IFS= read -r -d '' p; do case "$p" in *$'\n'*) continue ;; esac diff --git a/tests/test-clean-room.sh b/tests/test-clean-room.sh index 2bb112d04..474d712b7 100644 --- a/tests/test-clean-room.sh +++ b/tests/test-clean-room.sh @@ -17,6 +17,8 @@ # scripts they call (lib/onboard-detect.sh, lib/adopt.sh). # # Run: bash tests/test-clean-room.sh +# SC2319 is off for this file: `chk "name" "$([ cond ]; echo $?)"` passes the status of the condition on purpose. +# shellcheck disable=SC2319 set -uo pipefail KIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" @@ -339,6 +341,7 @@ eq "no operator config appeared in the fake HOME" "$([ -e "$HOME_DIR/.config/dwa assert_no_host_leak "generated files" \ "$HOME_DIR/.claude/settings.json" "$KIT/kit.toml" "$KIT/INSTALL-STAMP" \ "$REPO/.kit.toml" "$REPO/AGENTS.md" "$REPO/CLAUDE.md" "$REPO/WORKFLOW.md" "$REPO/docs/verification/README.md" +# shellcheck disable=SC2046 # split on purpose: one argument per log file, no spaces in these paths assert_no_host_leak "ledger" $(find "$HOME_DIR/.local/state" -type f -name '*.log' 2>/dev/null | head -20) eq "no command output names the host" "$(host_leak_hits < "$OUT_LOG")" "" diff --git a/tests/test-lanes-data.sh b/tests/test-lanes-data.sh index 86b97cb10..ca344f663 100644 --- a/tests/test-lanes-data.sh +++ b/tests/test-lanes-data.sh @@ -125,7 +125,7 @@ case_suggest_records() { err="$(lcx classify --rid sr-1 "add a users table migration" 2>&1 >/dev/null)" led="$(cat "$LOGD/runs/sr-1.log" 2>/dev/null)" lcx classify "add a users table migration" >/dev/null 2>&1 - extra="$(ls "$LOGD/runs" 2>/dev/null | grep -vc '^sr-1\.log$' || true)" + extra="$(find "$LOGD/runs" -mindepth 1 -maxdepth 1 ! -name '.*' ! -name sr-1.log 2>/dev/null | wc -l | tr -d ' ')" if [ "$out" = normal ] && printf '%s' "$err" | grep -qF 'LANE-SUGGEST: full (data-model)' \ && printf '%s' "$led" | grep -qF '| ACTION | lane-suggest full flags=data-model' && [ "$extra" = 0 ]; then pass suggest-records else fail suggest-records "out=$out err=$err ledger=$led extra-ledgers=$extra"; fi @@ -233,7 +233,6 @@ case_floor_invalid_extra_ere() { # --------------------------------------------------------------------------- # Lane data overrides (project layer), the base-pinned gate switch, and the ship-gate wiring. # --------------------------------------------------------------------------- -NORMAL_PHASES='["think", "spec", "validate", "design-record", "test-plan", "build", "review", "docs", "ship"]' # commit_kit_toml : write .kit.toml (always keeps the lane_gates switch on) and commit it. commit_kit_toml() { printf '[gate]\nlane_gates = true\n%s\n' "$1" > "$ROOT/.kit.toml"; _commit "chore: kit config"; } plan_phases() { KIT_PROJECT_ROOT="$ROOT" gl plan "$1" 2>/dev/null | awk '{print $2}' | tr '\n' ' '; } @@ -1097,7 +1096,7 @@ exempt_repo() { printf '[gate]\nlane_gates = true\n%s\n' "$(ent "$1" "$2" "${3:-\"r\"}")" > "$ROOT/.kit.toml"; _commit "chore: exempt" _git checkout -q -B feat/x >/dev/null 2>&1 } -floor_err() { lcx floor "$ROOT" main 2>&1 >/dev/null; } +floor_err() { { lcx floor "$ROOT" main >/dev/null; } 2>&1; } # floor_both: one floor run; prints stdout, leaves stderr in $FLOOR_ERRF. FLOOR_ERRF="$(_mk)/floor-err" # made here, in the main shell: floor_both runs inside $(...) floor_both() { lcx floor "$ROOT" main 2>"$FLOOR_ERRF"; } @@ -1413,7 +1412,7 @@ SQ_SAMPLE='for bad in "x'"'"'; DROP TABLE alerts;--" "Kit_Regression" ""; do' SQ_LINE='for b in "x'"'"'; DROP TABLE t;--"; do' sqx() { env KIT_FLOOR_SQLI_CARVEOUT=1 KIT_CONFIG_OPERATOR=/nonexistent DWARVES_KIT_LOG_DIR="${LOGD:-/nonexistent}" bash "$LC" "$@"; } sq_out() { sqx floor "$ROOT" main 2>/dev/null; } -sq_err() { sqx floor "$ROOT" main 2>&1 >/dev/null; } +sq_err() { { sqx floor "$ROOT" main >/dev/null; } 2>&1; } # sq_rows : `path|content|want` rows on stdin, each in a fresh repo, floor run with the flag. sq_rows() { local name="$1" bad="" path content want out diff --git a/tests/test-merge-command.sh b/tests/test-merge-command.sh index 5a39ed2b3..2c47500f1 100644 --- a/tests/test-merge-command.sh +++ b/tests/test-merge-command.sh @@ -5,6 +5,8 @@ # plain squash. mega-merge's cases live in tests/test-mega-merge.sh. # Shares the harness in tests/lib/wrap-stub.sh (gh stub, fixtures, chk). # modules under test: lib/config/merge-command.sh lib/config/kit-config.sh lib/wrap/wrap.sh lib/wrap/wrap-common.sh lib/wrap/wrap-merge.sh lib/wrap/wrap-land.sh lib/goal/stack-merge.sh +# SC2319 is off for this file: `chk "name" "$([ cond ]; echo $?)"` passes the status of the condition on purpose. +# shellcheck disable=SC2319 KIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$KIT_DIR/tests/lib/wrap-stub.sh" @@ -60,7 +62,7 @@ mc_repo_toml() { # mc_repo