@sabaiway/agent-workflow-kit 14.39.0 → 14.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/advisor-writers.md +1 -0
- package/references/modes/gates.md +1 -1
- package/references/modes/procedures.md +1 -1
- package/references/modes/recommendations.md +1 -1
- package/references/modes/rules.md +4 -3
- package/tools/gates-init.mjs +17 -8
- package/tools/procedures.mjs +9 -2
- package/tools/recommendations.mjs +25 -11
- package/tools/run-gates.mjs +13 -3
- package/tools/source-size/index.mjs +30 -0
- package/tools/source-size/layout.mjs +136 -0
- package/tools/source-size/limits.mjs +110 -0
- package/tools/source-size/record.mjs +143 -0
- package/tools/source-size-check.mjs +192 -127
- package/tools/source-size-config.mjs +92 -27
- package/tools/source-size-core.mjs +27 -0
- package/tools/source-size-judge.mjs +143 -77
- package/tools/source-size-refusal.mjs +8 -3
- package/tools/source-size-report.mjs +182 -46
- package/tools/source-size-scope.mjs +31 -6
- package/tools/write-lanes.mjs +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,39 @@ Semantically versioned ([semver](https://semver.org)), newest first. The `versio
|
|
|
4
4
|
is the current release. `upgrade` mode reads a project's `docs/ai/.workflow-version` and applies
|
|
5
5
|
every `migrations/<version>-<slug>.md` newer than it, in semver order.
|
|
6
6
|
|
|
7
|
+
## 14.40.0 — the size check judges every limit with a tolerance, counts entries per directory, depth and files per root, and changes a kit number only through `--override` (AD-192)
|
|
8
|
+
|
|
9
|
+
**`source-size-check.mjs` now judges five limits from one frozen kit table, each with a tolerance: a value over its
|
|
10
|
+
limit but within its band, ceil(value × tolerance / 100), warns on every run and still exits 0, and only a value
|
|
11
|
+
beyond the band stops, unless a record holds it.** The table: lines per file 400 (10%), bytes per line 1000 (0%), entries per directory 20 (10%), depth 5 (0%),
|
|
12
|
+
files per root the recorded count (10%). On a present config, a finding stops exactly when `--write-baseline` would raise a record; a record
|
|
13
|
+
above the tree, or one whose file is gone, now warns until the regeneration lowers or removes it.
|
|
14
|
+
|
|
15
|
+
- **Layout.** Entries per directory, depth and files per root are counted over every tracked entry under each declared
|
|
16
|
+
root, and over `docs/ai/specs` walked from disk as one more root. Start it with
|
|
17
|
+
`source-size-check.mjs --write-baseline --layout --reason "<text>"`: the record goes under the new machine key
|
|
18
|
+
`layout`. Until then every run prints one line saying layout is not judged.
|
|
19
|
+
- **No config.** `--check` on a project with no `docs/ai/source-size.json` judges layout alone under the kit's values,
|
|
20
|
+
says so, and writes nothing; `--write-baseline --reason "<text>"` writes the whole config in one write.
|
|
21
|
+
- **Config schema 2.** `docs/ai/source-size.json` holds the scope, the record and reasoned overrides; the numbers live
|
|
22
|
+
in the kit. `--override <id> [--value <n>] [--tolerance <p>] --reason "<text>"` changes one limit and regenerates
|
|
23
|
+
the record in the same write; `--override <id> --kit-default --reason "<text>"` returns it to the kit's (files per
|
|
24
|
+
root takes a tolerance only). `/agent-workflow-kit rules` routes "change
|
|
25
|
+
a number" to that command and runs it on your yes. The root `.` covers the whole tree; a config declaring no
|
|
26
|
+
extension judges no file's lines and says so.
|
|
27
|
+
- **Schema 1.** An old config is still read. `--check` stops on it and names the move; `--write-baseline` and
|
|
28
|
+
`--adopt` move it to schema 2 in their one write, keeping your scope and records. The advisor offers the move as
|
|
29
|
+
`source-size.schema-1`, and the gate fill does not offer the source-size gate over it.
|
|
30
|
+
- **Everywhere it is read.** The gate matrix prints a green source-size check's warning lines under its row; the
|
|
31
|
+
practice block of every `procedures` render names the five limits with their tolerances, whether layout is
|
|
32
|
+
recorded and, on a schema-1 config, the move.
|
|
33
|
+
|
|
34
|
+
**Upgrade note.** A deployment whose `docs/ai/source-size.json` is schema 1 has one step: the check stops on it, so
|
|
35
|
+
say yes when the advisor shows `source-size.schema-1`, and it runs `--write-baseline` once to move the config (a raise
|
|
36
|
+
riding the move asks for `--reason`). Every other deployment needs no step. A file of 401 to 440 lines now warns instead of stopping, and its record
|
|
37
|
+
warns as obsolete until the next `--write-baseline` removes it. To judge layout, run
|
|
38
|
+
`source-size-check.mjs --write-baseline --layout --reason "<text>"` once.
|
|
39
|
+
|
|
7
40
|
## 14.39.0 — agents find the project rules from a row in the entry file's Memory Map, and you change them through one command, `/agent-workflow-kit rules` (AD-191)
|
|
8
41
|
|
|
9
42
|
**Every upgrade now keeps a Memory Map row in `AGENTS.md` that links `docs/ai/rules/effective/project-layout.md`, so an
|
package/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: agent-workflow-kit
|
|
|
3
3
|
description: Deploy or upgrade a portable AI-agent memory-and-workflow system in any project. Use when the user wants to bootstrap `docs/ai/` + an entry-point `AGENTS.md` (+ `CLAUDE.md` alias) + cap/archive/index enforcement in a new or existing repo, set up the Memory Map and session protocols, install the docs-rotation pre-commit hook, or run `/agent-workflow-kit` / `/agent-workflow-kit upgrade`. Triggers on phrases like "set up the memory system", "deploy the AI workflow here", "bootstrap docs/ai", "upgrade the workflow". New to the epic, story and task tier? Run `/agent-workflow-kit tier`. A typed decision with a confidence from Jev? Run `/agent-workflow-kit jev`.
|
|
4
4
|
disable-model-invocation: true
|
|
5
5
|
metadata:
|
|
6
|
-
version: '14.
|
|
6
|
+
version: '14.40.0'
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# agent-workflow-kit
|
package/capability.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sabaiway/agent-workflow-kit",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.40.0",
|
|
4
4
|
"description": "Portable, cross-agent memory & workflow for AI coding agents — Claude Code, Codex, Cursor, Devin Desktop. One command deploys an AGENTS.md entry point + docs/ai context with cap/archive/index enforcement into any repo.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
| source-size.unminted | chat | source-size-check.mjs |
|
|
23
23
|
| source-size.adopted-elsewhere | chat | ack-write.mjs |
|
|
24
24
|
| source-size.id-squatter | user | user step |
|
|
25
|
+
| source-size.schema-1 | chat | source-size-check.mjs |
|
|
25
26
|
| gate-hook | harness | gate-hook.mjs |
|
|
26
27
|
| gate-hook.marker-stale | harness | gate-hook.mjs |
|
|
27
28
|
| commit-guard | harness | git-hooks.mjs |
|
|
@@ -21,7 +21,7 @@ Declared gates can also be **auto-approved** (no permission prompt on a byte-exa
|
|
|
21
21
|
|
|
22
22
|
**Candidate line — the review-receipt gate (opt-in, never auto-seeded; AD-021).** Projects that configure a reviewed/council `plan-execution.review` recipe can declare the review-state check as one more gate — the exact candidate `{ id, title, cmd }` line and its contract live under `${CLAUDE_SKILL_DIR}/references/modes/review-state.md` (step 3).
|
|
23
23
|
|
|
24
|
-
**Candidate line — the source-size gate (opt-in, never auto-seeded).** A project declaring the source-size practice (`docs/ai/source-size.json`) can declare its checker as one more gate, offered **only over a MINTED practice** — an absent config has nothing to offer, an authored-but-unminted one is withheld by name rather than declaring a gate that would refuse. Adoption is ONE consented verb, `node ${CLAUDE_SKILL_DIR}/tools/source-size-check.mjs --adopt --reason "<text>" [--cwd <project>]`: it mints the record and declares this gate and NOTHING else, is idempotent once adopted, and with no config refuses with the exact file to author
|
|
24
|
+
**Candidate line — the source-size gate (opt-in, never auto-seeded).** A project declaring the source-size practice (`docs/ai/source-size.json`) can declare its checker as one more gate, offered **only over a MINTED schema-2 practice** — an absent config has nothing to offer, an authored-but-unminted one is withheld by name rather than declaring a gate that would refuse, and a minted schema-1 one is withheld naming its `--write-baseline` move. Adoption is ONE consented verb, `node ${CLAUDE_SKILL_DIR}/tools/source-size-check.mjs --adopt --reason "<text>" [--cwd <project>]`: it mints the record and declares this gate and NOTHING else, is idempotent once adopted, and with no config refuses with the exact file to author. The advisor surfaces it as the `source-size` item, reading a declared cmd as one of THREE claims rather than a yes/no — **canonical** (this copy — answered), **tool-elsewhere** (the same shape resolving to a DIFFERENT real copy — a vendored deployment, converging on a `source-size-copy` acknowledgement, never on `--adopt`, which would collide on the declared id), **not-the-tool** (a gate merely CARRYING the id is a squatter: rename it, or repoint its cmd at this `--check` form) — in that precedence. An unminted record stays the same attention outcome for either copy, and no acknowledgement silences it.
|
|
25
25
|
|
|
26
26
|
**Candidate lines — the kit's own checkers (opt-in, one consented verb).** `control-bytes`, `plan-shape`, `spec-check` and `spec-coverage` can each be declared as a gate of your project: `node ${CLAUDE_SKILL_DIR}/tools/checker-gates.mjs --cwd <project>` previews them and writes nothing. Each is offered only over a state where its checker runs by design: `control-bytes` over a `.git` directory or gitfile at the project root, `plan-shape` on any deployment, `spec-check` over a regular `docs/ai/specs/index.md`, `spec-coverage` over a regular `docs/ai/spec-coverage.json` beside that store root. An offered checker prints its paste-ready entry line; the upgrade's `tier` ask writes the offered entries on your explicit yes — add-only, placed by the rule below, not stamp-gated, after the preview printed the disclosure below. An entry it wrote is removed by hand from `docs/ai/gates.json`: the verb never un-declares. `epic-shape` and `queue-audit` take a project operand and `doc-parity` checks only the kit's own package, so none of them is offered.
|
|
27
27
|
|
|
@@ -31,7 +31,7 @@ Run **`node ${CLAUDE_SKILL_DIR}/tools/procedures.mjs <activity> [--override <slo
|
|
|
31
31
|
|
|
32
32
|
**Flow armed-halves block (session-start read side).** When the config carries a `flow` block, the advisor also renders `Flow (schema 1) — armed halves (config · chain · bookkeeping):` — the **config half** (preset · councilRounds · kitMinVersion), the **chain half** (a light read-only probe of the flow store on the checker's fixed path: ARMED at an adoption record, UNARMED for an absent or unadopted store, fail-closed BROKEN wording for a malformed one), and the **bookkeeping half** (each declared path: declared non-excluded — the tracked-file floor verifies on the `set-flow` arming path — vs loudly DECLARED-EXCLUDED). A config with no `flow` block renders byte-identically to before and pays no store probe.
|
|
33
33
|
|
|
34
|
-
**Declared source-size practice block (upfront knowledge, D-17 U1).** When the project declares a source-size practice in `docs/ai/source-size.json`, the advisor also renders `Declared source-size practice (docs/ai/source-size.json) — known BEFORE the code is written:` — the caps, what is recorded and the canonical WHY sentence (the plan-time layout itself is the planning canon's Module ledger). `--json` carries the SAME lines under **`declaredPractice`** (an empty array when nothing is declared), so the human and structured renders never diverge. The four config states each read as themselves: **ABSENT** renders nothing at all (a project declaring no practice is handed no invented limits), **AUTHORED** and **INCOMPLETE** are pre-mint (the second names the half-written machine key), **MINTED** carries the recorded counts. A declaration that cannot be read (malformed, unknown-keyed, a dangling symlink) renders ONE loud `UNREADABLE` line and the advisor **still exits 0** — the practice's own checker owns the exit code for its config (exit 2 there) and its declared gate reds the gate matrix. Read through the practice's pure read core, so this advisor never reaches its writer half.
|
|
34
|
+
**Declared source-size practice block (upfront knowledge, D-17 U1).** When the project declares a source-size practice in `docs/ai/source-size.json`, the advisor also renders `Declared source-size practice (docs/ai/source-size.json) — known BEFORE the code is written:` — the caps, the five limits with their tolerances, whether layout is recorded, on schema 1 the `--write-baseline` move, what is recorded and the canonical WHY sentence (the plan-time layout itself is the planning canon's Module ledger). `--json` carries the SAME lines under **`declaredPractice`** (an empty array when nothing is declared), so the human and structured renders never diverge. The four config states each read as themselves: **ABSENT** renders nothing at all (a project declaring no practice is handed no invented limits), **AUTHORED** and **INCOMPLETE** are pre-mint (the second names the half-written machine key), **MINTED** carries the recorded counts. A declaration that cannot be read (malformed, unknown-keyed, a dangling symlink) renders ONE loud `UNREADABLE` line and the advisor **still exits 0** — the practice's own checker owns the exit code for its config (exit 2 there) and its declared gate reds the gate matrix. Read through the practice's pure read core, so this advisor never reaches its writer half.
|
|
35
35
|
|
|
36
36
|
**Readers-sweep block (`plan-authoring` only, unconditional).** Before the review-loop block the advisor renders `Readers sweep (before the first review) — …`: the search form for every config key, registry entry, exported constant, receipt field or canon sentence the plan changes, and the classification rule (a ledger row, a stated non-goal, or unchanged with its proof). The command line `run: node <kit>/tools/repo-search.mjs --pattern <the literal>` ALWAYS renders — bare wherever the `--kit-tools` tier could seed that path (the tier's own byte-form, the same predicate), and single-quoted otherwise (an unseedable path has no rule to match); `--pattern-file <f>` only for a pattern carrying a shell-significant byte; when the project's MCP registration is complete (`/agent-workflow-kit mcp`) a `use: repo_search {"pattern": "<the literal>"}` line renders ABOVE it — registration on disk, never a claim the tool is loaded in this session. `--json` carries the SAME lines under **`readersSweep`** (an empty array for the other activities).
|
|
37
37
|
|
|
@@ -35,7 +35,7 @@ A variant's posture note, where its key has one, is printed by `init` from this
|
|
|
35
35
|
|
|
36
36
|
- `gates-inert` — the gate matrix is DECLARED but verifies nothing, and the two causes have different remedies, so the item renders a different apply for each. **Cause A** — a canonical `coverage-check` gate with no producer gate declared BEFORE it (none at all, or one declared after it, which writes the lcov too late): the run certifies no coverage of its own — `coverage=not-run` when nothing wrote an lcov, or a verdict over STALE bytes an earlier run left in the git dir, which is worse because it reads as `coverage=certified`. This item is what surfaces that state at upgrade instead of leaving it to be noticed. The remedy needs the producer to run BEFORE the checker — declared or MOVED there — and what the fill can do about that is exactly what the apply says. When the checker is the LAST declared gate and the project's own scripts yield an offerable producer, the fill PLACES that producer before it, so the apply is the ordinary `gates-init` dry-run preview. Otherwise — no offerable producer, or a checker that is not last — it is the user item `gates-inert.unfillable`: the user's own step is to edit `docs/ai/gates.json` (the exact producer form lives in `${CLAUDE_SKILL_DIR}/references/modes/gates.md`), because the fill never reorders entries it did not write. **Cause B** — every declared gate is one of the kit's own canonical checkers, so the matrix runs no project-verification command at all: the apply is the `gates-init` dry-run preview, the same consent-gated seeder the `gates-declaration` item renders, and after the SAME confirmation you run the `--apply` line it prints. Neither cause changes any gate result, exit code or receipt — the item adds no enforcement, only the offer. Risk profile: `docs/ai/gates.json` is a PRIVILEGED file (a declared gate is auto-approvable by the wired hook), so both causes land in the same place — where the fill can help, it declares a project-controlled command on your explicit yes; where it cannot, the edit is the user's own step.
|
|
37
37
|
|
|
38
|
-
- `source-size` — the
|
|
38
|
+
- `source-size` — the arms differ by what the declared gate IS. **`adopted-elsewhere`** — the gate runs a DIFFERENT real copy of this checker (a vendored deployment): the practice runs, the advisor cannot resolve it as its own sibling, and the realpath anchor does not widen (that stops a lookalike). So the convergence is the ack writer's preview (`--lane source-size-copy` → `sourceSizeCopyAck`), never `--adopt`, which would mint and then be refused by the fill on the declared id. The fingerprint binds the declared claims AS AUTHORED, sorted, not resolved paths, so a second external copy re-fires it. **`id-squatter`** — a gate carries the `source-size` id and is not this checker under any reading: it claims the practice while nothing measures module size, so it is the user's own step (rename the id, or repoint the cmd at this `--check`). **`unminted`**, for both copies: a gate refusing every run over an authored or incomplete record (over an absent one the check judges layout alone), attention, and NO acknowledgement silences it; only the verb differs (with the gate declared elsewhere, `--write-baseline`). **`schema-1`** — the check stops on a minted schema-1 config, so this arm comes first: its `--write-baseline` line carries NO reason (a pinned one would launder a raise; a raise riding the move refuses and you relay it), every run until the move. Risk profile: `docs/ai/gates.json` is a PRIVILEGED file, so every arm here either records an acknowledgement or hands you an edit — the kit declares nothing on its own.
|
|
39
39
|
- `gate-hook` — the base arm is the ordinary opt-in wiring offer on the harness lane: the agent applies it on the chat yes after the check; `init` previews and applies it on the terminal yes as the route the user may take instead. The **`marker-stale`** arm is not: the placed hook validates your declaration through its OWN baked copy and goes dark on any key it does not know, so a declaration carrying the `lcovProducer` key under a hook that predates it silently turns auto-approval OFF, and every gate prompts again with no error anywhere. The condition is the key's PRESENCE, not its value — an older hook rejects a key it does not know whatever that key says, so `"lcovProducer": false` darkens it exactly as `true` does. The arm is deliberately marker-scoped — a stale hook is otherwise harmless — and it is a harness item: its writer is `gate-hook --apply --reseed`, which replaces the placed hook with the bundled bytes in place (and wires the entry only while it is unwired), so the agent applies it on the chat yes after the check, whose result names the replaced file with the old and the new digest; `init` applies it on the terminal y as the route the user may take instead. When the read-lane is also enabled, this arm and `read-lane.stale` would report the same file with the same recovery, so exactly one renders — **this one**, because its cause is the true one: a hook that postdates the read-lane and merely predates the marker key reads `lanes.json` perfectly well, and the read-lane arm's wording would be false over it. Risk profile: one placed hook file replaced by the bundled runtime; the declaration is never touched.
|
|
40
40
|
- `enforcement` — copies the bundled `references/scripts/*.mjs` runnable scripts and their tests, then runs the project's own hook installer, which installs the pre-commit hook. The lane is harness: the agent applies the item on the chat yes after the check, whose result shows each script the kit places with its bytes and the installer it runs with its bytes; `init` applies it on the batch terminal yes as the route the user may take instead. The copy is create-only: an existing file stands and nothing is written through a link, and the offer renders only when `scripts/` is absent or a plain directory contains no bundled basename. The hook invokes `node` directly, so a committer without it on PATH gets a loud failure. The installer refuses to overwrite a pre-commit hook it did not write: an install it refuses removes the scripts this apply copied, and the item is offered again with the installer's output shown; over a pre-commit hook the installer did not write the item is not offered — its skip names the user's own step. Risk profile: local tooling and a Git hook are added on the chat yes after the check, or on init's y.
|
|
41
41
|
- `attribution` — the agent applies the item on the chat yes after the check, setting one key in the project `.claude/settings.json`; `init` applies it on the terminal y as the route the user may take instead. An existing "includeCoAuthoredBy": false already converges the item unless an "attribution" key sets a commit or PR text; a local-scope override is the user's own edit. Risk profile: one settings key, nothing widened.
|
|
@@ -8,15 +8,16 @@ Requires: ${CLAUDE_SKILL_DIR}/references/shared/command-shapes.md
|
|
|
8
8
|
|
|
9
9
|
**1. Start with the ensure.** Run `node ${CLAUDE_SKILL_DIR}/tools/ensure-configs.mjs --reconcile --only rules --cwd <project>` and relay its line in plain words. The effective file is built, never written by hand: this mode moves no edit out of it, and the ensure's rebuild or the next merge replaces one.
|
|
10
10
|
|
|
11
|
-
**2. Do what the user asks — one of
|
|
11
|
+
**2. Do what the user asks — one of four.**
|
|
12
12
|
|
|
13
13
|
- **Change a rule.** The user says in plain words what to change. Show the exact text you will write to `docs/ai/rules/local/<theme>.md`, its frontmatter included, holding only the user's own rules and never a copy of the kit's, and write it on the user's yes. That request and that yes are the consent for the write of the local file.
|
|
14
14
|
- **Move an edit of the kit file.** When an ensure line for the kit file says it `carries your edit`, whatever token the run printed (`pending` and `regenerated` included), offer the move: compare `docs/ai/rules/<theme>.md` with the bundled `${CLAUDE_SKILL_DIR}/references/rules/<theme>.md`, write the user's changes, by meaning, into the local file (shown first, written on the yes), then delete the kit file. The next ensure seeds it again from the template, so the kit file keeps its one writer.
|
|
15
15
|
- **Drop the local rules.** On the user's request, delete the local file; the next ensure rebuilds the effective file from the kit file and records it.
|
|
16
|
+
- **Change a number.** A request to change a number, a limit's value or its tolerance, is never written into a rules file: the rules are prose and carry no numbers; the kit keeps its numbers in its code, and a project's own number is a reasoned override in the size check's config. Show the exact `node ${CLAUDE_SKILL_DIR}/tools/source-size-check.mjs --override <id> [--value <n>] [--tolerance <p>] --reason "<text>" --cwd <project>` command, passing only the numbers the user named (an option left out keeps the limit's current value or tolerance; `files-per-root` takes `--tolerance` only), with `--kit-default` in their place to return to the kit's numbers; run it on the user's yes and relay its lines. This route ends there: it runs no ensure, merge, record or closing check.
|
|
16
17
|
|
|
17
|
-
**3. After each of
|
|
18
|
+
**3. After each of the three rules routes, run the ensure again.** On `pending`, do the merge its line states, show the user what changed in the final rules, then run the record command the line prints with the sha256 of the merged file (one plain command for the digest, per the shared command-shapes contract).
|
|
18
19
|
|
|
19
|
-
**It stops on a refusal.** When an ensure run answers `failed`, or the
|
|
20
|
+
**It stops on a refusal.** When an ensure run answers `failed`, the record command exits non-zero, or the `--override` command exits non-zero, relay the line and stop: write, delete and record nothing further, and run no closing check as if the change held.
|
|
20
21
|
|
|
21
22
|
**4. End with the checks.** Run `node ${CLAUDE_SKILL_DIR}/tools/ensure-configs.mjs --reconcile --only index --cwd <project>`, then `node ${CLAUDE_SKILL_DIR}/tools/project-rules/rules-cli.mjs --check --cwd <project>`, which answers `current` for every theme; relay both in plain words.
|
|
22
23
|
|
package/tools/gates-init.mjs
CHANGED
|
@@ -425,12 +425,12 @@ export const flowCheckCandidate = (cwd, deps = {}) => {
|
|
|
425
425
|
};
|
|
426
426
|
|
|
427
427
|
// The conditional SOURCE-SIZE candidate — keyed on the practice's own declaration rather than on a
|
|
428
|
-
// recipe: the gate is offered ONLY over a MINTED docs/ai/source-size.json
|
|
429
|
-
//
|
|
430
|
-
//
|
|
431
|
-
//
|
|
432
|
-
//
|
|
433
|
-
//
|
|
428
|
+
// recipe: the gate is offered ONLY over a MINTED schema-2 docs/ai/source-size.json. Over an authored
|
|
429
|
+
// or half-written one the checker REFUSES by design, and a declared gate that refuses is a matrix
|
|
430
|
+
// this preview would have reddened on the user's behalf; a minted schema-1 one is withheld naming its
|
|
431
|
+
// --write-baseline move. A project that never declared the practice hears nothing here, while one
|
|
432
|
+
// that authored it and stopped short hears WHY the gate is not offered yet — the mint is the step it
|
|
433
|
+
// is missing.
|
|
434
434
|
// A path is unrenderable when EITHER guard fires, and both are asked ONCE, before anything about
|
|
435
435
|
// this candidate is printed. They are the same question wearing two coats: double-quoting cannot
|
|
436
436
|
// survive a shell-active byte, and a line-unsafe byte cannot be printed at all — U+2028 quotes
|
|
@@ -441,8 +441,9 @@ const unrenderableToolPath = (text) => isLineUnsafe(text) || DQ_UNSAFE_PATH_PATT
|
|
|
441
441
|
export const sourceSizeCandidate = (cwd, deps = {}) => {
|
|
442
442
|
const toolPath = deps.sourceSizeTool ?? SOURCE_SIZE_TOOL_PATH;
|
|
443
443
|
try {
|
|
444
|
-
const { state } = loadSourceSizeConfig(resolve(cwd), deps);
|
|
444
|
+
const { state, config } = loadSourceSizeConfig(resolve(cwd), deps);
|
|
445
445
|
if (state === 'absent') return { candidate: null, note: null };
|
|
446
|
+
const schema1 = state === 'minted' && config.schema === 1;
|
|
446
447
|
// Asked BEFORE the state branches: every branch below prints this path, so a check that only one
|
|
447
448
|
// of them performs is a guard the other silently lacks.
|
|
448
449
|
if (unrenderableToolPath(toolPath)) {
|
|
@@ -451,7 +452,7 @@ export const sourceSizeCandidate = (cwd, deps = {}) => {
|
|
|
451
452
|
// The advice still follows the STATE: over an unminted record a hand-declared gate is red on
|
|
452
453
|
// every run, so pointing there would hand the reader their next failure as the way out.
|
|
453
454
|
const lane = state === 'minted'
|
|
454
|
-
? 'declare the gate by hand
|
|
455
|
+
? `${schema1 ? 'move the record to schema 2 first — run source-size-check.mjs --write-baseline with the working directory set to this project, then ' : ''}declare the gate by hand`
|
|
455
456
|
: `mint the record first — run source-size-check.mjs --adopt --reason "${INITIAL_ADOPTION_REASON}" with the working directory set to this project, then declare the gate by hand`;
|
|
456
457
|
return {
|
|
457
458
|
candidate: null,
|
|
@@ -479,6 +480,14 @@ export const sourceSizeCandidate = (cwd, deps = {}) => {
|
|
|
479
480
|
`${recovery}, then re-run this preview`,
|
|
480
481
|
};
|
|
481
482
|
}
|
|
483
|
+
// A minted schema-1 record stops the check until the writer moves it; the move takes no reason.
|
|
484
|
+
if (schema1) {
|
|
485
|
+
const project = resolve(cwd);
|
|
486
|
+
return {
|
|
487
|
+
candidate: null,
|
|
488
|
+
note: `the source-size candidate was withheld: the declared practice is schema 1, which the check stops on until it is moved — ${unrenderableToolPath(project) ? 'run source-size-check.mjs --write-baseline yourself, with the working directory set to this project (no command is printed: this project\'s path cannot be rendered into one)' : `run node "${toolPath}" --write-baseline --cwd "${project}"`}, then re-run this preview`,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
482
491
|
return {
|
|
483
492
|
candidate: {
|
|
484
493
|
id: SOURCE_SIZE_GATE_ID,
|
package/tools/procedures.mjs
CHANGED
|
@@ -53,7 +53,7 @@ import { readRegistration } from './mcp-registration.mjs';
|
|
|
53
53
|
// The declared source-size practice (D-17 U1), read through the practice's PURE READ core — never
|
|
54
54
|
// source-size-check.mjs, which owns the writer half: this advisor is a read root of
|
|
55
55
|
// test/read-graph-purity.test.mjs, and the core exists so a surface can ask without reaching a writer.
|
|
56
|
-
import { SOURCE_SIZE_CONFIG_REL, SOURCE_SIZE_WHY, loadSourceSizeConfig, practiceFacts } from './source-size-core.mjs';
|
|
56
|
+
import { SOURCE_SIZE_CONFIG_REL, SOURCE_SIZE_WHY, escapeForLine, limitLines, loadSourceSizeConfig, practiceFacts } from './source-size-core.mjs';
|
|
57
57
|
export { CONFIG_REL };
|
|
58
58
|
|
|
59
59
|
// ── argument + override parsing (usage errors → exit 2) ─────────────────────────────
|
|
@@ -562,11 +562,18 @@ const declaredPracticeAdvice = (cwd, readFile, lstat) => {
|
|
|
562
562
|
const unmintedRecord = declaration.state === 'incomplete'
|
|
563
563
|
? ` recorded: PARTIAL — the machine record is half-written (missing ${declaration.missingMachineKeys.map((key) => `"${key}"`).join(', ')}), so the ratchet holds nothing yet; run \`source-size-check.mjs --check\` for the mint step.`
|
|
564
564
|
: ' recorded: NOTHING YET — the caps are declared but no size is recorded, so the ratchet holds nothing; run `source-size-check.mjs --check` for the mint step.';
|
|
565
|
+
// The five limits are the check's own lines, from the one function both renders read.
|
|
566
|
+
const { config } = declaration;
|
|
565
567
|
return [
|
|
566
568
|
DECLARED_PRACTICE_HEADER,
|
|
567
569
|
` caps: ${facts.maxLines} lines · ${facts.maxLineBytes} bytes per line, over ${facts.roots} declared root(s).`,
|
|
570
|
+
...limitLines(config.limits, { escape: escapeForLine, recorded: config.layout !== null }).map((line) => ` ${line}`),
|
|
571
|
+
config.layout !== null
|
|
572
|
+
? ' layout: recorded — entries per directory, depth and files per root are judged by the size check.'
|
|
573
|
+
: ' layout: not recorded — `source-size-check.mjs --write-baseline --layout --reason "<text>"` starts it.',
|
|
574
|
+
...(config.schema === 1 ? [' schema 1: the check stops on it — `source-size-check.mjs --write-baseline` moves it to schema 2.'] : []),
|
|
568
575
|
declaration.state === 'minted'
|
|
569
|
-
? ` recorded: ${facts.recordedFiles} file(s) carry a recorded size (debt, not permission) · aggregate ${facts.aggregateLines} line(s)
|
|
576
|
+
? ` recorded: ${facts.recordedFiles} file(s) carry a recorded size (debt, not permission) · aggregate ${facts.aggregateLines} line(s) — growth past a record takes a reasoned bump, and a record above the tree warns until the regeneration lowers it.`
|
|
570
577
|
: unmintedRecord,
|
|
571
578
|
` why: ${SOURCE_SIZE_WHY}`,
|
|
572
579
|
];
|
|
@@ -183,6 +183,8 @@ export const SEVERITIES = Object.freeze({
|
|
|
183
183
|
// acknowledgment. An id SQUATTER is the opposite: the id says adopted while nothing measures size.
|
|
184
184
|
'source-size.adopted-elsewhere': SEVERITY_OPTIONAL,
|
|
185
185
|
'source-size.id-squatter': SEVERITY_ATTENTION,
|
|
186
|
+
// A minted schema-1 config is a record the check stops on until the writer moves it.
|
|
187
|
+
'source-size.schema-1': SEVERITY_ATTENTION,
|
|
186
188
|
'gate-hook': SEVERITY_OPTIONAL,
|
|
187
189
|
// A placed hook that predates the marker key goes DARK on a marker-carrying declaration (unknown
|
|
188
190
|
// key → auto-approval off), so a CONFIGURED capability silently stops working: attention, not an
|
|
@@ -278,7 +280,8 @@ export const WHATS = Object.freeze({
|
|
|
278
280
|
'gates-inert.producer-unrecognized': 'the coverage checker ({id}) has NO producer declared and none offerable, on a tree the changed-line domain barely reaches',
|
|
279
281
|
'gates-inert.coverage-domain-narrow': 'certification covers the assessable minority only — {ext} dominate(s) the tracked tree, and the changed-line domain excludes them',
|
|
280
282
|
'source-size': 'no source-size gate — module size drifts unmeasured, and an over-cap file is invisible instead of recorded debt',
|
|
281
|
-
'source-size.unminted': 'the source-size gate is declared
|
|
283
|
+
'source-size.unminted': 'the source-size gate is declared over an unminted record ({state}) — the check refuses it, or if absent judges layout alone, no line',
|
|
284
|
+
'source-size.schema-1': 'the source-size config is schema 1, which the check stops on — the writer moves it to schema 2 in one write',
|
|
282
285
|
'source-size.adopted-elsewhere': "the source-size gate runs a DIFFERENT copy of this checker ({n} declared) — adopted here, just not through this kit's own tool",
|
|
283
286
|
'source-size.id-squatter': 'a gate carries the source-size id but is not this checker — the practice reads as declared while nothing measures module size',
|
|
284
287
|
'gate-hook': '{n} declared gate(s) prompt per run — the gate-approval hook is not wired',
|
|
@@ -830,10 +833,10 @@ export const probeGatesInert = ({ root, deps, add, skip }) => {
|
|
|
830
833
|
};
|
|
831
834
|
|
|
832
835
|
// The SOURCE-SIZE offer (baseline-practices Plan 1). This is the practice's ONE discovery lane: the
|
|
833
|
-
// checker ships with the kit and
|
|
834
|
-
// item a deployment would never learn the practice exists — the same
|
|
835
|
-
// the capability registry was built for. New and existing deployments
|
|
836
|
-
// the advisor section is mandatory at every upgrade.
|
|
836
|
+
// checker ships with the kit and, until a project declares its own scope, judges no file's lines, so
|
|
837
|
+
// without this item a deployment would never learn the practice exists — the same
|
|
838
|
+
// OPT-IN-SHIPS-INVISIBLE failure the capability registry was built for. New and existing deployments
|
|
839
|
+
// meet it identically, because the advisor section is mandatory at every upgrade.
|
|
837
840
|
//
|
|
838
841
|
// The probe asks what each declared cmd CLAIMS about this checker, in the three named outcomes —
|
|
839
842
|
// because the boolean it used to ask made a DELIBERATELY VENDORED copy read as "no source-size gate
|
|
@@ -845,11 +848,22 @@ export const probeGatesInert = ({ root, deps, add, skip }) => {
|
|
|
845
848
|
//
|
|
846
849
|
// Precedence over a MIXED declaration is pinned and deterministic: any canonical match answers the
|
|
847
850
|
// practice question outright; else any tool-elsewhere claim; else the id collision; else the offer.
|
|
851
|
+
// A MINTED schema-1 config is asked first, ahead of the gate arms: the check stops on it whatever is
|
|
852
|
+
// declared. Its line carries no reason, since a pinned one would launder a raise; an unreadable
|
|
853
|
+
// config keeps today's arms, which report it.
|
|
854
|
+
const schema1Minted = (root, deps) => {
|
|
855
|
+
try { const { state, config } = loadSourceSizeConfig(root, deps); return state === 'minted' && config.schema === 1; } catch { return false; }
|
|
856
|
+
};
|
|
857
|
+
|
|
848
858
|
const probeSourceSize = ({ root, deps, add, skip }) => {
|
|
849
859
|
try {
|
|
860
|
+
const tool = toolPath('source-size-check.mjs');
|
|
861
|
+
if (schema1Minted(root, deps)) {
|
|
862
|
+
add('source-size', fillTemplate(WHATS['source-size.schema-1'], {}), `node ${q(tool)} --write-baseline --cwd ${q(root)}`, 'source-size.schema-1');
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
850
865
|
const declaration = loadDeclaration(root, deps);
|
|
851
866
|
const gates = declaration.outcome === 'loaded' ? declaration.gates : [];
|
|
852
|
-
const tool = toolPath('source-size-check.mjs');
|
|
853
867
|
// The reason string is PINNED, not composed: it is copied unchanged into every entry the first
|
|
854
868
|
// mint records, and a first mint records the whole tree — so "this is what the tree already
|
|
855
869
|
// carried when the practice arrived" is the one sentence that is true of all of them.
|
|
@@ -858,11 +872,11 @@ const probeSourceSize = ({ root, deps, add, skip }) => {
|
|
|
858
872
|
const canonical = claims.filter((c) => c.claim === CHECKER_CLAIM.CANONICAL);
|
|
859
873
|
const elsewhere = claims.filter((c) => c.claim === CHECKER_CLAIM.ELSEWHERE);
|
|
860
874
|
if (canonical.length > 0 || elsewhere.length > 0) {
|
|
861
|
-
// A DECLARED gate is not the same fact as a working one: the checker refuses
|
|
862
|
-
//
|
|
863
|
-
//
|
|
864
|
-
// nothing about the one thing
|
|
865
|
-
// outcome, its attention class and its immunity to every ack are the same whichever copy runs.
|
|
875
|
+
// A DECLARED gate is not the same fact as a working one: the checker refuses an authored or
|
|
876
|
+
// half-written record, so a gate declared over one reds the matrix on every run, and over an
|
|
877
|
+
// absent one it judges layout alone and no line. The declaration alone would report that deployment
|
|
878
|
+
// as adopted and say nothing about the one thing wrong with it. The split changes NOTHING here —
|
|
879
|
+
// the outcome, its attention class and its immunity to every ack are the same whichever copy runs.
|
|
866
880
|
const { state } = loadSourceSizeConfig(root, deps);
|
|
867
881
|
if (state !== 'minted') {
|
|
868
882
|
// Only the way OUT differs. With the gate declared through another copy, `--adopt` would
|
package/tools/run-gates.mjs
CHANGED
|
@@ -72,6 +72,7 @@ import {
|
|
|
72
72
|
// token this runner records) — run-gates already imports core-evidence, so a shared home is the
|
|
73
73
|
// only direction that has no cycle. Re-exported here: this module is the vocabulary's public face.
|
|
74
74
|
import { COVERAGE } from './coverage-state.mjs';
|
|
75
|
+
import { CHECKER_CLAIM, SOURCE_SIZE_WARNING_PREFIX, classifySourceSizeGate } from './source-size-core.mjs';
|
|
75
76
|
|
|
76
77
|
export { GATES_REL, loadDeclaration, validateDeclaration, canonicalCheckerGates, isFinalCapableDeclaration, isReviewDependentGate };
|
|
77
78
|
export { COVERAGE };
|
|
@@ -227,8 +228,16 @@ export const BASH_PROBE_CMD = 'true';
|
|
|
227
228
|
const formatSeconds = (ms) => `${(ms / 1000).toFixed(1)}s`;
|
|
228
229
|
const trimTrailingNewline = (text) => text.replace(/\n$/, '');
|
|
229
230
|
|
|
230
|
-
//
|
|
231
|
-
//
|
|
231
|
+
// A green source-size check's warnings print on every run, so the matrix echoes them — and nothing
|
|
232
|
+
// else of its output — under a gate running this checker or a regular-file copy of it elsewhere.
|
|
233
|
+
const SOURCE_SIZE_CLAIMS = new Set([CHECKER_CLAIM.CANONICAL, CHECKER_CLAIM.ELSEWHERE]);
|
|
234
|
+
const sourceSizeWarnings = (gate, cwd, stdout) => (SOURCE_SIZE_CLAIMS.has(classifySourceSizeGate(gate.cmd, cwd))
|
|
235
|
+
? String(stdout).split(/\r?\n/).filter((line) => line.startsWith(SOURCE_SIZE_WARNING_PREFIX))
|
|
236
|
+
: []);
|
|
237
|
+
|
|
238
|
+
// Run the selected gates sequentially (declaration order). A green gate logs one PASS line (and a
|
|
239
|
+
// source-size check its warnings); a failing gate logs FAIL + its captured stdout/stderr VERBATIM
|
|
240
|
+
// (triage without re-running).
|
|
232
241
|
export const runGates = (gates, { cwd, spawn = spawnGateViaBash, now = Date.now, log = console.log }) => {
|
|
233
242
|
const results = [];
|
|
234
243
|
for (const gate of gates) {
|
|
@@ -242,6 +251,7 @@ export const runGates = (gates, { cwd, spawn = spawnGateViaBash, now = Date.now,
|
|
|
242
251
|
results.push({ id: gate.id, title: gate.title, ok, code, elapsedMs, stdout: res.stdout ? String(res.stdout) : '' });
|
|
243
252
|
if (ok) {
|
|
244
253
|
log(` PASS (${formatSeconds(elapsedMs)})`);
|
|
254
|
+
for (const line of sourceSizeWarnings(gate, cwd, res.stdout ?? '')) log(line);
|
|
245
255
|
} else {
|
|
246
256
|
log(` FAIL exit=${code} (${formatSeconds(elapsedMs)})`);
|
|
247
257
|
if (res.stdout) log(trimTrailingNewline(res.stdout));
|
|
@@ -797,7 +807,7 @@ export const runCli = (argv, deps = {}) => {
|
|
|
797
807
|
}
|
|
798
808
|
}
|
|
799
809
|
}
|
|
800
|
-
// A green gate's stdout is
|
|
810
|
+
// A green gate's stdout is not echoed but for a source-size check's warnings — the table IS the report. The row above
|
|
801
811
|
// now names the withheld verdict; this block adds the checker's OWN words and the remedy, so a
|
|
802
812
|
// plain run never leaves a PASS standing for a coverage claim that was never made. Only that.
|
|
803
813
|
if (!opts.final && coverage.state === COVERAGE.notRun && coverage.checkerRow?.ok) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// index.mjs — the door of the size check's module: every kit module outside tools/source-size/
|
|
2
|
+
// reaches it through this file alone.
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
KIT_LIMITS,
|
|
6
|
+
SCHEMA1_REASON,
|
|
7
|
+
applyOverride,
|
|
8
|
+
limitLines,
|
|
9
|
+
limitsDefect,
|
|
10
|
+
migrateSchema1,
|
|
11
|
+
resolveLimits,
|
|
12
|
+
} from './limits.mjs';
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
SPEC_STORE_ROOT,
|
|
16
|
+
bandOf,
|
|
17
|
+
layoutCounts,
|
|
18
|
+
layoutDefect,
|
|
19
|
+
walkSpecStore,
|
|
20
|
+
} from './layout.mjs';
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
changesFor,
|
|
24
|
+
isRaise,
|
|
25
|
+
materialize,
|
|
26
|
+
ownEntry,
|
|
27
|
+
planRecord,
|
|
28
|
+
projectLayout,
|
|
29
|
+
serialize,
|
|
30
|
+
} from './record.mjs';
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// layout.mjs — the layout limits: the band every limit is judged with, the layout count over a list
|
|
2
|
+
// of entries, the layout record's grammar and the spec store's walk. It writes no file, spawns no
|
|
3
|
+
// process and imports no file of the practice, so the record's reason rule is handed in by its
|
|
4
|
+
// caller; the walk alone reads the disk, through the readdir and lstat it is handed.
|
|
5
|
+
//
|
|
6
|
+
// A name is carried as a binary string — one code point per byte — so names are compared as bytes
|
|
7
|
+
// and a name that is not valid UTF-8 is still counted; the caller decodes a key only where a record
|
|
8
|
+
// needs one.
|
|
9
|
+
//
|
|
10
|
+
// Dependency-free, Node >= 22. No side effects on import.
|
|
11
|
+
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
|
|
14
|
+
// The spec store: one more judged root, at a fixed path, walked from disk because a deployment may
|
|
15
|
+
// hide it from git.
|
|
16
|
+
export const SPEC_STORE_ROOT = 'docs/ai/specs';
|
|
17
|
+
|
|
18
|
+
// bandOf(value, tolerance) → ceil(value × tolerance / 100), in integers so no float rounds it.
|
|
19
|
+
export const bandOf = (value, tolerance) => Math.floor((value * tolerance + 99) / 100);
|
|
20
|
+
|
|
21
|
+
// layoutCounts(entries) → { files, directories }: `entries` are { path, dir } relative to one root,
|
|
22
|
+
// '/'-separated; `directories` maps each directory ('' for the root's own) to its entries (the
|
|
23
|
+
// distinct names directly under it), its depth (its segments below the root) and its reach (the
|
|
24
|
+
// deepest level its subtree holds). A file's own name is no level; a non-directory entry is a file.
|
|
25
|
+
export const layoutCounts = (entries) => {
|
|
26
|
+
const children = new Map([['', new Set()]]);
|
|
27
|
+
const namesOf = (dir) => {
|
|
28
|
+
if (!children.has(dir)) children.set(dir, new Set());
|
|
29
|
+
return children.get(dir);
|
|
30
|
+
};
|
|
31
|
+
let files = 0;
|
|
32
|
+
for (const { path, dir } of entries) {
|
|
33
|
+
const segments = path.split('/');
|
|
34
|
+
segments.forEach((name, at) => namesOf(segments.slice(0, at).join('/')).add(name));
|
|
35
|
+
if (dir) namesOf(path);
|
|
36
|
+
else files += 1;
|
|
37
|
+
}
|
|
38
|
+
const directories = new Map([...children].map(([key, names]) => {
|
|
39
|
+
const depth = key === '' ? 0 : key.split('/').length;
|
|
40
|
+
return [key, { entries: names.size, depth, reach: depth }];
|
|
41
|
+
}));
|
|
42
|
+
for (const [key, { depth }] of directories) {
|
|
43
|
+
const segments = key === '' ? [] : key.split('/');
|
|
44
|
+
for (let at = 0; at < segments.length; at += 1) {
|
|
45
|
+
const ancestor = directories.get(segments.slice(0, at).join('/'));
|
|
46
|
+
if (ancestor.reach < depth) ancestor.reach = depth;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { files, directories };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const isPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
53
|
+
const BAD_SEGMENTS = new Set(['', '.', '..']);
|
|
54
|
+
|
|
55
|
+
const keysDefect = (value, what, allowed, required) => {
|
|
56
|
+
if (!isPlainObject(value)) return `${what} must be an object holding ${allowed.join(', ')}`;
|
|
57
|
+
const unknown = Object.keys(value).filter((key) => !allowed.includes(key));
|
|
58
|
+
if (unknown.length > 0) return `${what} carries unknown key(s): ${unknown.join(', ')}`;
|
|
59
|
+
const missing = required.filter((key) => !Object.hasOwn(value, key));
|
|
60
|
+
return missing.length > 0 ? `${what} is missing ${missing.join(', ')}` : null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const entryDefect = (key, entry, what, counts, reasonDefect) => {
|
|
64
|
+
if (key !== '.' && key.split('/').some((segment) => BAD_SEGMENTS.has(segment))) {
|
|
65
|
+
return `${what} key "${key}" must be ".", or a path with no empty, "." or ".." segment`;
|
|
66
|
+
}
|
|
67
|
+
const at = `${what}."${key}"`;
|
|
68
|
+
const shape = keysDefect(entry, at, [...counts, 'reason'], counts.length === 1 ? [...counts, 'reason'] : ['reason']);
|
|
69
|
+
if (shape) return shape;
|
|
70
|
+
if (!counts.some((count) => Object.hasOwn(entry, count))) return `${at} must record ${counts.join(' or ')}`;
|
|
71
|
+
for (const count of counts.filter((name) => Object.hasOwn(entry, name))) {
|
|
72
|
+
if (!(Number.isSafeInteger(entry[count]) && entry[count] >= 0)) {
|
|
73
|
+
return `${at}.${count} must be a non-negative integer, got ${JSON.stringify(entry[count])}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const reason = reasonDefect(entry.reason);
|
|
77
|
+
return reason ? `${at}.reason: ${reason}` : null;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// layoutDefect(layout, reasonDefect) → the first defect naming its key, or null. The record holds
|
|
81
|
+
// exactly roots (each exactly files and reason) and directories (entries, depth or both, and reason).
|
|
82
|
+
export const layoutDefect = (layout, reasonDefect) => {
|
|
83
|
+
const shape = keysDefect(layout, '"layout"', ['roots', 'directories'], ['roots', 'directories']);
|
|
84
|
+
if (shape) return shape;
|
|
85
|
+
for (const [map, counts] of [['roots', ['files']], ['directories', ['entries', 'depth']]]) {
|
|
86
|
+
const what = `"layout"."${map}"`;
|
|
87
|
+
if (!isPlainObject(layout[map])) return `${what} must be an object`;
|
|
88
|
+
for (const [key, entry] of Object.entries(layout[map])) {
|
|
89
|
+
const defect = entryDefect(key, entry, what, counts, reasonDefect);
|
|
90
|
+
if (defect) return defect;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const SLASH = Buffer.from('/');
|
|
97
|
+
|
|
98
|
+
// walkSpecStore(cwd, { readdir, lstat }) → { state: 'absent' } | { state: 'present', entries } |
|
|
99
|
+
// { state: 'refused', path, cause }. Every entry is read by lstat and no symlink is followed, so a
|
|
100
|
+
// link — one pointing at its own parent included — is counted once as an entry and never entered.
|
|
101
|
+
export const walkSpecStore = (cwd, { readdir, lstat }) => {
|
|
102
|
+
const root = Buffer.from(join(cwd, SPEC_STORE_ROOT));
|
|
103
|
+
const refused = (path, err) => ({ state: 'refused', path: path.toString(), cause: err?.message ?? String(err) });
|
|
104
|
+
let stat;
|
|
105
|
+
try {
|
|
106
|
+
stat = lstat(root);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
return err?.code === 'ENOENT' || err?.code === 'ENOTDIR' ? { state: 'absent' } : refused(root, err);
|
|
109
|
+
}
|
|
110
|
+
if (!stat.isDirectory()) return refused(root, new Error('present but not a directory'));
|
|
111
|
+
const entries = [];
|
|
112
|
+
const pending = [{ abs: root, rel: '' }];
|
|
113
|
+
while (pending.length > 0) {
|
|
114
|
+
const { abs, rel } = pending.pop();
|
|
115
|
+
let names;
|
|
116
|
+
try {
|
|
117
|
+
names = readdir(abs, { encoding: 'buffer' });
|
|
118
|
+
} catch (err) {
|
|
119
|
+
return refused(abs, err);
|
|
120
|
+
}
|
|
121
|
+
for (const raw of names) {
|
|
122
|
+
const name = typeof raw === 'string' ? Buffer.from(raw) : raw;
|
|
123
|
+
const path = Buffer.concat([abs, SLASH, name]);
|
|
124
|
+
let entry;
|
|
125
|
+
try {
|
|
126
|
+
entry = lstat(path);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
return refused(path, err);
|
|
129
|
+
}
|
|
130
|
+
const child = rel === '' ? name.toString('latin1') : `${rel}/${name.toString('latin1')}`;
|
|
131
|
+
entries.push({ path: child, dir: entry.isDirectory() });
|
|
132
|
+
if (entry.isDirectory()) pending.push({ abs: path, rel: child });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { state: 'present', entries };
|
|
136
|
+
};
|