@sabaiway/agent-workflow-kit 19.3.0 → 19.4.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 +39 -0
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +3 -2
- package/references/advisor-writers.md +1 -0
- package/references/modes/recommendations.md +1 -1
- package/references/rules/project-layout.md +1 -1
- package/tools/project-rules/memory-map-row.mjs +3 -1
- package/tools/project-rules/rules-priors.mjs +3 -1
- package/tools/project-rules/themes.mjs +1 -1
- package/tools/queue-audit-cli.mjs +1 -1
- package/tools/recommendations.mjs +23 -2
- package/tools/source-size/index.mjs +13 -0
- package/tools/source-size/limits.mjs +1 -1
- package/tools/source-size/piles-cli.mjs +88 -0
- package/tools/source-size/piles.mjs +233 -0
- package/tools/source-size-core.mjs +28 -3
- package/tools/source-size-judge.mjs +4 -2
- package/tools/source-size-report.mjs +8 -6
- package/tools/write-lanes.mjs +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,45 @@ 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
|
+
## 19.4.0 — each recorded pile is offered a queue row; the layout rules are read at every session start; the spec store drops files per root (AD-214)
|
|
8
|
+
|
|
9
|
+
**Recommendations now offers a queue row that plans the cleanup of each pile the size check records.** A pile is a
|
|
10
|
+
directory the layout record of `docs/ai/source-size.json` holds beyond its entries band: with the kit's limit of 20 at
|
|
11
|
+
10%, a record of 23 entries or more. For each pile no queue row names, the new chat item `source-size.piles` offers one
|
|
12
|
+
row at the end of the Later bucket of `docs/plans/queue.md`. On your yes the agent runs
|
|
13
|
+
`node <kit>/tools/source-size/piles-cli.mjs --write --cwd <project>`, which prints one `queued: <id> — <key>` line per
|
|
14
|
+
row, and the next run shows nothing. A no writes nothing, and the item comes back. Each row reads:
|
|
15
|
+
|
|
16
|
+
- Plan the cleanup of the directory `<key>`, whose <n> entries the size check records over the limit of <v>, so its files are laid out by meaning — id PILE-<the key upper-cased, each run of other characters one dash>-<8 hex digits>
|
|
17
|
+
- recorded in docs/ai/source-size.json under "layout"."directories"; a regeneration lowers the record as the directory shrinks
|
|
18
|
+
|
|
19
|
+
- **Your queue's own check decides.** The rows are judged by each `queue-audit-cli.mjs` gate of `docs/ai/gates.json`
|
|
20
|
+
that checks this queue (with no such gate, by the readback alone), then read back, before anything is written.
|
|
21
|
+
Where a write would not pass, nothing is written and the item is a stated skip naming why: a pile key a row cannot
|
|
22
|
+
carry; a queue that cannot take the rows (absent, a link, unreadable, not a regular UTF-8 file within 8 MiB, CR line
|
|
23
|
+
endings, a text the queue audit refuses, already failing its own check, or rows that would not read back in its
|
|
24
|
+
Later bucket); not exactly one heading reading `Later` or opening with `Later `; a `docs/ai/gates.json` or a gate
|
|
25
|
+
the advisor cannot read, or whose check cannot judge the queue; or the check refusing the queue with the rows added (a row cap, for one).
|
|
26
|
+
- **A pile a row already names is offered no more**, whatever the row's bucket or state.
|
|
27
|
+
- **No tree is walked**: the piles come from the record alone, so the offer follows the record, not the tree.
|
|
28
|
+
|
|
29
|
+
**The project-layout rules are read at the start of every session.** The theme's Memory Map row in `AGENTS.md` now
|
|
30
|
+
reads `**Start of every session**` where it read `Creating, moving or naming a file, a module or a spec`, and *The
|
|
31
|
+
spec mirrors the module* opens with `Specs live in docs/ai/specs.` Your upgrade writes both current: the earlier row
|
|
32
|
+
answers `refreshed`, and with no local rules file the earlier rules text answers `refreshed` and the effective file is
|
|
33
|
+
rebuilt from the new text; with one, the kit file is still refreshed, the op answers `pending` and names the merge for
|
|
34
|
+
the agent to make, as for any change of the kit's rules.
|
|
35
|
+
|
|
36
|
+
**Files per root no longer judges the spec store.** `docs/ai/specs` keeps its limits on entries per directory and depth,
|
|
37
|
+
but its file count is no longer recorded or judged, so a store recorded at one spec takes its third with no stop, while
|
|
38
|
+
a declared code root beyond its band still stops. A config that still records `docs/ai/specs` in `"layout"."roots"` is
|
|
39
|
+
read with no stop and warns on every check until the next record write drops it:
|
|
40
|
+
|
|
41
|
+
`source-size: WARNING — docs/ai/specs: recorded in "layout"."roots", but files per root no longer judges the spec store — the regeneration removes it`
|
|
42
|
+
|
|
43
|
+
A check with no stop prints the paste-ready regeneration line beside that warning. The limit line and the root lines
|
|
44
|
+
now say *declared root* where they said *judged root*.
|
|
45
|
+
|
|
7
46
|
## 19.3.0 — the orchestration note is written current with no question; a differing one is named with its route (AD-213)
|
|
8
47
|
|
|
9
48
|
**Your upgrade now writes the onboarding note of `docs/ai/orchestration.json` current, with no question and no copy
|
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: '19.
|
|
6
|
+
version: '19.4.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": "19.
|
|
3
|
+
"version": "19.4.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",
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"bridges/",
|
|
54
54
|
"!bin/*.test.mjs",
|
|
55
55
|
"!tools/**/*.test.mjs",
|
|
56
|
-
"!tools/manifest/fixtures/**"
|
|
56
|
+
"!tools/manifest/fixtures/**",
|
|
57
|
+
"!tools/project-rules/fixtures/**"
|
|
57
58
|
],
|
|
58
59
|
"engines": {
|
|
59
60
|
"node": ">=22"
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
| source-size.id-squatter | user | user step |
|
|
25
25
|
| source-size.schema-1 | chat | source-size-check.mjs |
|
|
26
26
|
| source-size.layout | chat | source-size-check.mjs |
|
|
27
|
+
| source-size.piles | chat | source-size/piles-cli.mjs |
|
|
27
28
|
| gate-hook | harness | gate-hook.mjs |
|
|
28
29
|
| gate-hook.not-current | kit | gate-hook.mjs |
|
|
29
30
|
| commit-guard | harness | git-hooks.mjs |
|
|
@@ -37,7 +37,7 @@ A variant's posture note, where its key has one, is printed by `init` from this
|
|
|
37
37
|
|
|
38
38
|
- `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`. The remedy needs the producer to run BEFORE the checker — declared or MOVED there. 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.
|
|
39
39
|
|
|
40
|
-
- `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. **`layout`** — on a config with no layout record, the record of the piles already there comes first, as its own item: a no writes nothing and the item returns every run; its `recipe:` line names the branch states, and `source-size.layout` is applied before the `hook-checks` check line runs, whose layout line follows that record. 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.
|
|
40
|
+
- `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. **`layout`** — on a config with no layout record, the record of the piles already there comes first, as its own item: a no writes nothing and the item returns every run; its `recipe:` line names the branch states, and `source-size.layout` is applied before the `hook-checks` check line runs, whose layout line follows that record. **`piles`** — each recorded pile with no queue row gets one, at the end of the queue's Later bucket; a write the queue's own declared check would refuse is not made and the stated skip says why. 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.
|
|
41
41
|
- `gate-hook` — the offer wires the hook 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. Over a wired hook the key renders the kit item `gate-hook.not-current` instead: the placed hook file is absent or differs from the body the kit writes for it. An older body validates your declaration through its OWN baked copy and goes dark on a key it does not know, such as `lcovProducer` (present, whatever its value), so every gate prompts again with no error anywhere. The agent applies the kit item with no question after the check, whose result names the file with its new digest, and the old one too over a differing file; it writes only the hook file. Risk profile: the offer places a hook file and wires one settings entry; the kit item writes one hook file with the kit's body; the declaration is never touched.
|
|
42
42
|
- `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.
|
|
43
43
|
- `hook-checks` — the agent applies the item on the chat yes after the check; `init` applies it on the terminal y as the route the user may take instead. Risk profile: future commits stop on the rules check and, where judged, on the size check's findings — lines, aggregate and layout; over a clone with no pre-commit hook the installer writes its whole hook, so commits also stop on its docs, archive and `scripts/` test lines.
|
|
@@ -34,7 +34,7 @@ Modules never nest by technical layer, so there is no directory of all controlle
|
|
|
34
34
|
|
|
35
35
|
## The spec mirrors the module
|
|
36
36
|
|
|
37
|
-
A spec's path mirrors its module's path, so the name of one gives the place of the other.
|
|
37
|
+
Specs live in docs/ai/specs. A spec's path mirrors its module's path, so the name of one gives the place of the other.
|
|
38
38
|
|
|
39
39
|
## Old code
|
|
40
40
|
|
|
@@ -6,7 +6,9 @@ import { THEMES, themePaths } from './themes.mjs';
|
|
|
6
6
|
|
|
7
7
|
// The row texts a release shipped, append-only: a release that changes a row's text first appends
|
|
8
8
|
// the outgoing one here.
|
|
9
|
-
export const MEMORY_MAP_PRIOR_ROWS = Object.freeze([
|
|
9
|
+
export const MEMORY_MAP_PRIOR_ROWS = Object.freeze([
|
|
10
|
+
'| [`docs/ai/rules/effective/project-layout.md`](./docs/ai/rules/effective/project-layout.md) | Creating, moving or naming a file, a module or a spec | Only through `/agent-workflow-kit rules` |',
|
|
11
|
+
]);
|
|
10
12
|
|
|
11
13
|
// The route the reconcile's row note names when it wrote a row with other text.
|
|
12
14
|
export const ROW_ROUTE = 'a row of your own goes on a line of its own, its first cell a path of your own';
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
import { digestOf } from './rules-check.mjs';
|
|
5
5
|
|
|
6
|
-
export const RULES_PRIORS = Object.freeze([
|
|
6
|
+
export const RULES_PRIORS = Object.freeze([
|
|
7
|
+
Object.freeze({ theme: 'project-layout', release: '14.37.0', sha256: 'b79f19a9e0583f1e0619ee6aca06feb2c359b9655f1d260e87d8d5647bd1de19' }),
|
|
8
|
+
]);
|
|
7
9
|
|
|
8
10
|
// isKnownPrior(theme, bytes, catalog?) → true exactly when the bytes hash to an entry of that theme.
|
|
9
11
|
export const isKnownPrior = (theme, bytes, catalog = RULES_PRIORS) => {
|
|
@@ -44,7 +44,7 @@ const valueOf = (argv, index, flag) => {
|
|
|
44
44
|
return value;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
const parseArgv = (argv) => {
|
|
47
|
+
export const parseArgv = (argv) => {
|
|
48
48
|
// `--help` is answered ONLY when it is the whole invocation. A help flag that wins from anywhere
|
|
49
49
|
// makes `--check <dirty-file> --help` exit 0 — the gate's refusal replaced by a help page, which
|
|
50
50
|
// is the same bypass a second mode flag would be, reached by a flag nobody reads as dangerous.
|
|
@@ -71,7 +71,7 @@ import { takeCensus, censusFact, CENSUS_VERDICT } from './tracked-tree-census.mj
|
|
|
71
71
|
// fill's own WRITER is never called from here — the advisor renders its consent-gated command, it
|
|
72
72
|
// does not run it.
|
|
73
73
|
import { buildOffer } from './gates-init.mjs';
|
|
74
|
-
import { CHECKER_CLAIM, INITIAL_ADOPTION_REASON, SOURCE_SIZE_GATE_ID, classifySourceSizeGate, loadSourceSizeConfig, readLayoutSetup } from './source-size-core.mjs';
|
|
74
|
+
import { CHECKER_CLAIM, INITIAL_ADOPTION_REASON, SOURCE_SIZE_GATE_ID, classifySourceSizeGate, loadSourceSizeConfig, readLayoutSetup, readPileOffer } from './source-size-core.mjs';
|
|
75
75
|
// The declared-path resolution + segment containment this item's convergence lane shares with the
|
|
76
76
|
// autonomy render's allowWrite degrade — ONE leaf, so the two answers cannot drift.
|
|
77
77
|
import { resolveDeclaredDir, dirCovers, isResolvableDeclaredEntry } from './declared-paths.mjs';
|
|
@@ -192,6 +192,7 @@ export const SEVERITIES = Object.freeze({
|
|
|
192
192
|
// A minted schema-1 config is a record the check stops on until the writer moves it.
|
|
193
193
|
'source-size.schema-1': SEVERITY_ATTENTION,
|
|
194
194
|
'source-size.layout': SEVERITY_OPTIONAL,
|
|
195
|
+
'source-size.piles': SEVERITY_OPTIONAL,
|
|
195
196
|
'gate-hook': SEVERITY_OPTIONAL,
|
|
196
197
|
// A wired hook's kit file absent or differing: its lane is kit, as `agents.not-current`'s.
|
|
197
198
|
'gate-hook.not-current': SEVERITY_OPTIONAL,
|
|
@@ -286,6 +287,7 @@ export const WHATS = Object.freeze({
|
|
|
286
287
|
'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',
|
|
287
288
|
'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',
|
|
288
289
|
'source-size.layout': 'the layout record is not started — starting it records any directory already beyond the layout limits, so the commit hook can judge layout',
|
|
290
|
+
'source-size.piles': '{n} recorded pile(s) have no queue row planning their cleanup — one row each goes to the end of the queue\'s Later bucket',
|
|
289
291
|
'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",
|
|
290
292
|
'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',
|
|
291
293
|
'gate-hook': '{n} declared gate(s) prompt per run — the gate-approval hook is not wired',
|
|
@@ -386,6 +388,7 @@ export const VARIANT_BENEFITS = Object.freeze({
|
|
|
386
388
|
'state-block.not-current': HOOK_CURRENCY_BENEFIT,
|
|
387
389
|
'jev-skill.not-current': "currency — every agent skill root the kit fills holds the vendor skill at the kit's pin once a copy is placed",
|
|
388
390
|
'source-size.layout': 'layout — piles past the layout limits become recorded, reasoned debt, so the commit hook can judge new ones once its layout line is armed',
|
|
391
|
+
'source-size.piles': 'layout — each recorded pile gets a queue row that plans its cleanup, so the debt is ordered work in the queue, not only a record',
|
|
389
392
|
});
|
|
390
393
|
|
|
391
394
|
// ── the CLOSED opt-in capability registry (OPT-IN-SHIPS-INVISIBLE) ──────────────────────────────
|
|
@@ -859,6 +862,20 @@ const layoutSetupOrSkip = (root, deps, skip) => {
|
|
|
859
862
|
}
|
|
860
863
|
};
|
|
861
864
|
|
|
865
|
+
// The piles arm: write renders the item, held its stated skip, none nothing; its own throw is a stated skip.
|
|
866
|
+
const pilesArm = (root, declaration, deps, add, skip) => {
|
|
867
|
+
try {
|
|
868
|
+
const offer = readPileOffer(root, declaration, deps);
|
|
869
|
+
if (offer.answer === 'write') {
|
|
870
|
+
add('source-size', fillTemplate(WHATS['source-size.piles'], { n: offer.piles.length }),
|
|
871
|
+
`node ${q(toolPath('source-size/piles-cli.mjs'))} --write --cwd ${q(root)}`, 'source-size.piles',
|
|
872
|
+
`piles without a row: ${offer.piles.map(({ key }) => key).join(', ')}`);
|
|
873
|
+
} else if (offer.answer === 'held') skip('source-size.piles', new Error(offer.text));
|
|
874
|
+
} catch (err) {
|
|
875
|
+
skip('source-size.piles', err);
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
|
|
862
879
|
const probeSourceSize = ({ root, deps, add, skip, shared }) => {
|
|
863
880
|
try {
|
|
864
881
|
const tool = toolPath('source-size-check.mjs');
|
|
@@ -873,7 +890,11 @@ const probeSourceSize = ({ root, deps, add, skip, shared }) => {
|
|
|
873
890
|
shared.layoutRecord = add('source-size', fillTemplate(WHATS['source-size.layout'], {}),
|
|
874
891
|
`node ${q(tool)} ${setup.args.map(q).join(' ')} --cwd ${q(root)}`, 'source-size.layout', LAYOUT_RECORD_RECIPE);
|
|
875
892
|
} else if (setup?.answer === 'held' && Object.hasOwn(LAYOUT_HELD, setup.reason)) skip('source-size.layout', new Error(LAYOUT_HELD[setup.reason](setup)));
|
|
876
|
-
|
|
893
|
+
// One declaration read for the piles arm and the gate arms; where it throws, the gate arms rethrow it.
|
|
894
|
+
let loadError = null;
|
|
895
|
+
const declaration = (() => { try { return loadDeclaration(root, deps); } catch (err) { loadError = err; return { outcome: 'error', message: err.message }; } })();
|
|
896
|
+
pilesArm(root, declaration, deps, add, skip);
|
|
897
|
+
if (loadError !== null) throw loadError;
|
|
877
898
|
const gates = declaration.outcome === 'loaded' ? declaration.gates : [];
|
|
878
899
|
// The reason string is PINNED, not composed: it is copied unchanged into every entry the first
|
|
879
900
|
// mint records, and a first mint records the whole tree — so "this is what the tree already
|
|
@@ -34,3 +34,16 @@ export {
|
|
|
34
34
|
checkTargetOf,
|
|
35
35
|
layoutSetupOf,
|
|
36
36
|
} from './setup.mjs';
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
PILE_ANSWERS,
|
|
40
|
+
PILE_HELD,
|
|
41
|
+
PILE_QUEUE_MAX_BYTES,
|
|
42
|
+
PILE_QUEUE_REL,
|
|
43
|
+
pileIdOf,
|
|
44
|
+
pileOfferOf,
|
|
45
|
+
pileRowOf,
|
|
46
|
+
pilesOf,
|
|
47
|
+
queueChecksOf,
|
|
48
|
+
spliceLater,
|
|
49
|
+
} from './piles.mjs';
|
|
@@ -76,7 +76,7 @@ export const resolveLimits = (limits = {}) => {
|
|
|
76
76
|
// the check and the plan-time render state the same five lines from this one function.
|
|
77
77
|
export const limitLines = (limits, { escape = String, recorded = false } = {}) => Object.keys(KIT_LIMITS).map((id) => {
|
|
78
78
|
const { value, tolerance, source, reason } = limits[id];
|
|
79
|
-
const amount = value !== null ? `${value}` : recorded ? "each
|
|
79
|
+
const amount = value !== null ? `${value}` : recorded ? "each declared root's recorded count" : 'none recorded';
|
|
80
80
|
return `limit ${id} ${amount}, tolerance ${tolerance}% — ${source === 'kit' ? 'from kit' : `from override: ${escape(reason)}`}`;
|
|
81
81
|
});
|
|
82
82
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// piles-cli.mjs — the writer of the pile rows: one queue row per recorded pile that has none, at the end
|
|
3
|
+
// of the queue's Later bucket, written only when the queue's own declared check and the readback accept
|
|
4
|
+
// it. The answer is the read core's readPileOffer, asked once; this file owns argv, the one atomic write
|
|
5
|
+
// and the lines. Nothing in the read graph imports it.
|
|
6
|
+
//
|
|
7
|
+
// Exit codes: 0 rows written, or every pile already has its row; 1 the offer is held, or the atomic
|
|
8
|
+
// write is refused, the queue byte-unchanged; 2 usage or config error, writing nothing.
|
|
9
|
+
//
|
|
10
|
+
// Dependency-free, Node >= 22.
|
|
11
|
+
|
|
12
|
+
import { join, resolve } from 'node:path';
|
|
13
|
+
import { writeContainedFileAtomic } from '../atomic-write.mjs';
|
|
14
|
+
import { isDirectRun } from '../direct-run.mjs';
|
|
15
|
+
import { loadDeclaration } from '../gates-declaration.mjs';
|
|
16
|
+
import { PILE_QUEUE_REL, readPileOffer } from '../source-size-core.mjs';
|
|
17
|
+
|
|
18
|
+
const HELP = `piles-cli — one queue row per recorded pile (agent-workflow-kit).
|
|
19
|
+
|
|
20
|
+
Usage:
|
|
21
|
+
node piles-cli.mjs --write [--cwd <dir>]
|
|
22
|
+
node piles-cli.mjs --help
|
|
23
|
+
|
|
24
|
+
--write adds one two-line row per directory the layout record of docs/ai/source-size.json holds
|
|
25
|
+
beyond its entries band and no queue row names by its id, at the end of the one heading of
|
|
26
|
+
${PILE_QUEUE_REL} reading Later or opening with Later and a space; nothing is written
|
|
27
|
+
when the queue's own check in docs/ai/gates.json would refuse the result or the rows would
|
|
28
|
+
not read back.
|
|
29
|
+
--cwd the project root (default: the current directory).
|
|
30
|
+
|
|
31
|
+
Exit codes: 0 written, or nothing to write; 1 held or refused, nothing written; 2 usage or config error.`;
|
|
32
|
+
|
|
33
|
+
const usage = (message) => ({ code: 2, stdout: '', stderr: `piles-cli: ${message} (see --help)` });
|
|
34
|
+
|
|
35
|
+
// The argv: --write once, --cwd <dir> at most once, nothing else; --help only as the whole argv.
|
|
36
|
+
const parse = (argv) => {
|
|
37
|
+
if (argv.length === 1 && argv[0] === '--help') return { help: true };
|
|
38
|
+
let write = false;
|
|
39
|
+
let cwd;
|
|
40
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
41
|
+
const arg = argv[index];
|
|
42
|
+
if (arg === '--write' && !write) write = true;
|
|
43
|
+
else if (arg === '--cwd' && cwd === undefined && argv[index + 1] !== undefined && !argv[index + 1].startsWith('--')) {
|
|
44
|
+
cwd = argv[index + 1];
|
|
45
|
+
index += 1;
|
|
46
|
+
} else return { error: `unexpected argument ${JSON.stringify(arg)}` };
|
|
47
|
+
}
|
|
48
|
+
return write ? { cwd } : { error: '--write is the one mode' };
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// The declaration as the offer takes it: the loader's answer, or its error.
|
|
52
|
+
const declarationOf = (root, deps) => {
|
|
53
|
+
try {
|
|
54
|
+
return loadDeclaration(root, deps);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
return { outcome: 'error', message: err.message };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const main = (argv, ctx = {}) => {
|
|
61
|
+
const options = parse(argv);
|
|
62
|
+
if (options.help) return { code: 0, stdout: HELP, stderr: '' };
|
|
63
|
+
if (options.error !== undefined) return usage(options.error);
|
|
64
|
+
const deps = ctx.deps ?? {};
|
|
65
|
+
const root = resolve(ctx.cwd ?? process.cwd(), options.cwd ?? '.');
|
|
66
|
+
let offer;
|
|
67
|
+
try {
|
|
68
|
+
offer = readPileOffer(root, declarationOf(root, deps), deps);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
return { code: 2, stdout: '', stderr: `piles-cli: ${err.message}` };
|
|
71
|
+
}
|
|
72
|
+
if (offer.answer === 'none') return { code: 0, stdout: 'every recorded pile has its queue row — nothing to write', stderr: '' };
|
|
73
|
+
if (offer.answer === 'held') return { code: 1, stdout: '', stderr: offer.text };
|
|
74
|
+
try {
|
|
75
|
+
writeContainedFileAtomic(root, join(root, PILE_QUEUE_REL), offer.text, deps, { label: PILE_QUEUE_REL });
|
|
76
|
+
} catch (err) {
|
|
77
|
+
return { code: 1, stdout: '', stderr: `piles-cli: the write of ${PILE_QUEUE_REL} was refused — ${err.message}` };
|
|
78
|
+
}
|
|
79
|
+
const queued = offer.piles.map(({ id, key }) => `queued: ${id} — ${key}`);
|
|
80
|
+
return { code: 0, stdout: [...queued, `wrote ${offer.rows.length} row(s) to ${PILE_QUEUE_REL}`].join('\n'), stderr: '' };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (isDirectRun(import.meta.url)) {
|
|
84
|
+
const result = main(process.argv.slice(2));
|
|
85
|
+
if (result.stdout) process.stdout.write(`${result.stdout}\n`);
|
|
86
|
+
if (result.stderr) process.stderr.write(`${result.stderr}\n`);
|
|
87
|
+
process.exitCode = result.code;
|
|
88
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// piles.mjs — a queue row per recorded pile: the piles the layout record holds beyond the entries band,
|
|
2
|
+
// each pile's id and two-line row, the queue's own declared checks, the splice into the Later bucket and
|
|
3
|
+
// the closed answer the advisor's item and the writer both ask. It writes no file, spawns nothing and
|
|
4
|
+
// makes no fs call of its own: every read reaches it through the values its caller hands it.
|
|
5
|
+
//
|
|
6
|
+
// Dependency-free, Node >= 22. No side effects on import.
|
|
7
|
+
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { join, resolve } from 'node:path';
|
|
10
|
+
import { tokenizeMarkdown } from '../../references/scripts/markdown-blocks.mjs';
|
|
11
|
+
import { auditQueue, canonicalHeading, checkQueue } from '../queue-audit.mjs';
|
|
12
|
+
import { parseArgv } from '../queue-audit-cli.mjs';
|
|
13
|
+
import { bandOf } from './layout.mjs';
|
|
14
|
+
|
|
15
|
+
export const PILE_ANSWERS = Object.freeze(['none', 'held', 'write']);
|
|
16
|
+
export const PILE_HELD = Object.freeze(['key', 'queue', 'bucket', 'check', 'refused']);
|
|
17
|
+
export const PILE_QUEUE_REL = 'docs/plans/queue.md';
|
|
18
|
+
export const PILE_QUEUE_MAX_BYTES = 8388608;
|
|
19
|
+
|
|
20
|
+
const QUEUE_CLI = 'queue-audit-cli.mjs';
|
|
21
|
+
const ABSENT_CAUSE = 'it is absent';
|
|
22
|
+
const FATAL_UTF8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
23
|
+
const HELD_TEXT = {
|
|
24
|
+
key: (key) => `a recorded pile's directory key holds a backtick or a byte a queue row cannot carry, so no pile row is offered: ${key}`,
|
|
25
|
+
queue: (cause) => `${PILE_QUEUE_REL} cannot take the pile rows, so none is written: ${cause}`,
|
|
26
|
+
bucket: (k) => `the pile rows go to the end of the one heading reading Later or opening with Later after its # run, and ${PILE_QUEUE_REL} holds ${k}`,
|
|
27
|
+
check: (cause) => `the queue's own check in docs/ai/gates.json cannot judge the pile rows, so none is written: ${cause}`,
|
|
28
|
+
refused: (problem, k) => `the queue's own check would refuse the queue with the ${k} pile row(s) added, so none is written: ${problem}`,
|
|
29
|
+
};
|
|
30
|
+
const held = (reason, ...args) => ({ answer: 'held', reason, text: HELD_TEXT[reason](...args) });
|
|
31
|
+
|
|
32
|
+
// pilesOf(loaded) → [{ key, entries, value }]: each directory of a minted schema-2 layout record whose
|
|
33
|
+
// recorded entries exceed the resolved entries-per-directory value plus its band, in the record's order.
|
|
34
|
+
export const pilesOf = (loaded) => {
|
|
35
|
+
const config = loaded?.state === 'minted' ? loaded.config : null;
|
|
36
|
+
if (config === null || config.schema !== 2 || config.layout === null) return [];
|
|
37
|
+
const { value, tolerance } = config.limits['entries-per-directory'];
|
|
38
|
+
return Object.entries(config.layout.directories)
|
|
39
|
+
.filter(([, record]) => Object.hasOwn(record, 'entries') && record.entries > value + bandOf(value, tolerance))
|
|
40
|
+
.map(([key, record]) => ({ key, entries: record.entries, value }));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// pileIdOf(key) → PILE-, the key's slug upper-cased, then the first 8 hex digits of its sha256.
|
|
44
|
+
export const pileIdOf = (key) => {
|
|
45
|
+
const slug = key.toUpperCase().replace(/[^A-Z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
46
|
+
const hex = createHash('sha256').update(key, 'utf8').digest('hex').slice(0, 8).toUpperCase();
|
|
47
|
+
return `PILE-${slug === '' ? '' : `${slug}-`}${hex}`;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// pileRowOf(pile) → the row's two lines, joined by one newline.
|
|
51
|
+
export const pileRowOf = ({ key, entries, value }) => [
|
|
52
|
+
`- Plan the cleanup of the directory \`${key}\`, whose ${entries} entries the size check records over the limit of ${value}, so its files are laid out by meaning — id ${pileIdOf(key)}`,
|
|
53
|
+
' - recorded in docs/ai/source-size.json under "layout"."directories"; a regeneration lowers the record as the directory shrinks',
|
|
54
|
+
].join('\n');
|
|
55
|
+
|
|
56
|
+
// The narrow sh subset a gate cmd is read by: bare tokens, or one quoted run each, separated by spaces.
|
|
57
|
+
const TOKEN = `[^"\\\\$\`;&|<>()*?\\[\\]{}~#' \\t\\n]+|'[^']*'|"[^"\\\\$\`]*"`;
|
|
58
|
+
const CMD_FORM = new RegExp(`^ *(?:(?:${TOKEN})(?: +(?:${TOKEN}))*)? *$`);
|
|
59
|
+
const shTokens = (cmd) => {
|
|
60
|
+
if (!CMD_FORM.test(cmd)) return null;
|
|
61
|
+
return [...cmd.matchAll(new RegExp(TOKEN, 'g'))].map(([token]) => (/^['"]/.test(token) ? token.slice(1, -1) : token));
|
|
62
|
+
};
|
|
63
|
+
const basenameOf = (path) => path.split('/').at(-1);
|
|
64
|
+
|
|
65
|
+
// queueChecksOf(declaration, root) → { checks: [{ id, path, options }] } | { cause }: the --check gates
|
|
66
|
+
// of a loaded declaration whose cmd carries queue-audit-cli.mjs, each read by the sh subset and the
|
|
67
|
+
// audit's own parseArgv, its path resolved from the root.
|
|
68
|
+
export const queueChecksOf = (declaration, root) => {
|
|
69
|
+
if (declaration.outcome === 'error') return { cause: declaration.message };
|
|
70
|
+
if (declaration.outcome !== 'loaded') return { checks: [] };
|
|
71
|
+
const checks = [];
|
|
72
|
+
for (const { id, cmd } of declaration.gates.filter((gate) => gate.cmd.includes(QUEUE_CLI))) {
|
|
73
|
+
const tokens = shTokens(cmd);
|
|
74
|
+
if (tokens === null || tokens[0] !== 'node' || tokens.length < 2 || basenameOf(tokens[1]) !== QUEUE_CLI) {
|
|
75
|
+
return { cause: `gate ${id} is outside the sh form the advisor reads` };
|
|
76
|
+
}
|
|
77
|
+
let options;
|
|
78
|
+
try {
|
|
79
|
+
options = parseArgv(tokens.slice(2));
|
|
80
|
+
} catch (err) {
|
|
81
|
+
return { cause: `gate ${id}: ${err.message}` };
|
|
82
|
+
}
|
|
83
|
+
if (options.mode === 'check') checks.push({ id, path: resolve(root, options.path), options });
|
|
84
|
+
}
|
|
85
|
+
return { checks };
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// The headings of a text with their 1-based file lines, frontmatter included.
|
|
89
|
+
const headingsOf = (text) => {
|
|
90
|
+
const { headings, frontLines } = tokenizeMarkdown(text, PILE_QUEUE_REL);
|
|
91
|
+
return headings.map((heading) => ({ ...heading, line: frontLines + heading.index + 1 }));
|
|
92
|
+
};
|
|
93
|
+
const isLater = ({ text }) => {
|
|
94
|
+
const bare = canonicalHeading(text.replace(/^ {0,3}#{1,6}[ \t]+/, ''));
|
|
95
|
+
return bare === 'Later' || bare.startsWith('Later ');
|
|
96
|
+
};
|
|
97
|
+
const isBlank = (line) => line.trim() === '';
|
|
98
|
+
|
|
99
|
+
// The bucket's span in file lines: its heading's index and the index of the next heading, or the end.
|
|
100
|
+
const bucketSpan = (text, line) => {
|
|
101
|
+
const next = headingsOf(text).find((heading) => heading.line > line);
|
|
102
|
+
return { at: line - 1, end: next === undefined ? text.split('\n').length : next.line - 1, closes: next === undefined };
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// spliceLater(text, line, rows) → the text with each row at the end of the bucket whose heading is the
|
|
106
|
+
// 1-based file line `line`: its trailing blank lines dropped, one blank line before each row and one
|
|
107
|
+
// before the next heading; a bucket that closes the file ends it with one newline.
|
|
108
|
+
export const spliceLater = (text, line, rows) => {
|
|
109
|
+
const lines = text.split('\n');
|
|
110
|
+
const { at, end, closes } = bucketSpan(text, line);
|
|
111
|
+
const body = lines.slice(at + 1, end);
|
|
112
|
+
while (body.length > 0 && isBlank(body.at(-1))) body.pop();
|
|
113
|
+
const added = rows.flatMap((row) => ['', ...row.split('\n')]);
|
|
114
|
+
const head = [...lines.slice(0, at + 1), ...body, ...added];
|
|
115
|
+
return closes ? `${head.join('\n')}\n` : [...head, '', ...lines.slice(end)].join('\n');
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// The queue as read, or the cause it cannot take the rows: the lstat walk the writer's containment check
|
|
119
|
+
// makes, then the capped no-follow read, the fatal decode, the CR rule and the audit.
|
|
120
|
+
const readQueueText = (root, reads) => {
|
|
121
|
+
const parts = PILE_QUEUE_REL.split('/');
|
|
122
|
+
for (let depth = 0; depth <= parts.length; depth += 1) {
|
|
123
|
+
const rel = depth === 0 ? '.' : parts.slice(0, depth).join('/');
|
|
124
|
+
let stat;
|
|
125
|
+
try {
|
|
126
|
+
stat = reads.lstat(depth === 0 ? root : join(root, rel));
|
|
127
|
+
} catch (err) {
|
|
128
|
+
return { cause: err?.code === 'ENOENT' ? ABSENT_CAUSE : String(err?.code ?? err?.message ?? err) };
|
|
129
|
+
}
|
|
130
|
+
if (stat.isSymbolicLink()) return { cause: `${rel} is a symlink` };
|
|
131
|
+
}
|
|
132
|
+
const read = reads.readQueue(join(root, PILE_QUEUE_REL));
|
|
133
|
+
if (read.outcome === 'absent') return { cause: ABSENT_CAUSE };
|
|
134
|
+
if (read.outcome === 'foreign') return { cause: read.className === 'symlink' ? `${PILE_QUEUE_REL} is a symlink` : 'not a regular file' };
|
|
135
|
+
if (read.outcome === 'over-cap') return { cause: `over ${PILE_QUEUE_MAX_BYTES} bytes` };
|
|
136
|
+
if (read.outcome !== 'ok') return { cause: String(read.code) };
|
|
137
|
+
let text;
|
|
138
|
+
try {
|
|
139
|
+
text = FATAL_UTF8.decode(read.bytes);
|
|
140
|
+
} catch {
|
|
141
|
+
return { cause: 'invalid UTF-8' };
|
|
142
|
+
}
|
|
143
|
+
if (text.includes('\r')) return { cause: 'carries CR line endings' };
|
|
144
|
+
try {
|
|
145
|
+
return { text, audit: auditQueue(text, { label: PILE_QUEUE_REL }) };
|
|
146
|
+
} catch (err) {
|
|
147
|
+
return { cause: err.message };
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// What the composed text fails to carry back, or null: each new id on exactly one live row with no name
|
|
152
|
+
// finding whose last bucket is the Later heading, and no byte moved outside the bucket's tail.
|
|
153
|
+
const readbackDefect = (text, composed, line, piles, rows) => {
|
|
154
|
+
const before = text.split('\n');
|
|
155
|
+
const after = composed.split('\n');
|
|
156
|
+
const { at, end, closes } = bucketSpan(text, line);
|
|
157
|
+
let keep = end;
|
|
158
|
+
while (keep > at + 1 && isBlank(before[keep - 1])) keep -= 1;
|
|
159
|
+
const tail = closes ? [] : before.slice(end);
|
|
160
|
+
const middle = after.slice(keep, after.length - tail.length);
|
|
161
|
+
const rowLines = new Set(rows.flatMap((row) => row.split('\n')));
|
|
162
|
+
if (after.slice(0, keep).join('\n') !== before.slice(0, keep).join('\n') || after.slice(after.length - tail.length).join('\n') !== tail.join('\n')
|
|
163
|
+
|| after.length - tail.length < keep || !middle.every((entry) => isBlank(entry) || rowLines.has(entry))) {
|
|
164
|
+
return 'a byte outside the bucket\'s end would move';
|
|
165
|
+
}
|
|
166
|
+
let audit;
|
|
167
|
+
try {
|
|
168
|
+
audit = auditQueue(composed, { label: PILE_QUEUE_REL });
|
|
169
|
+
} catch (err) {
|
|
170
|
+
return err.message;
|
|
171
|
+
}
|
|
172
|
+
for (const { id } of piles) {
|
|
173
|
+
const carried = audit.rows.filter((row) => row.id === id);
|
|
174
|
+
if (carried.length !== 1) return `${id} is carried by ${carried.length} rows`;
|
|
175
|
+
const [row] = carried;
|
|
176
|
+
if (row.klass !== 'live') return `${id} reads as ${row.klass}`;
|
|
177
|
+
if (row.nameFindings.length > 0) return `${id} has a name finding (${row.nameFindings[0].cause})`;
|
|
178
|
+
if (row.buckets.at(-1)?.line !== line) return `${id} does not sit in the Later bucket`;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// The first problem a check finds over a text, as { thrown } or { problem }, or null when it accepts.
|
|
184
|
+
const judge = (check, text) => {
|
|
185
|
+
try {
|
|
186
|
+
const result = checkQueue(text, { ...check.options, label: PILE_QUEUE_REL });
|
|
187
|
+
return result.ok ? null : { problem: result.problems[0] };
|
|
188
|
+
} catch (err) {
|
|
189
|
+
return { thrown: `gate ${check.id}: ${err.message}` };
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// pileOfferOf(root, reads, declaration, deps) → { answer: 'none' } | { answer: 'held', reason, text } |
|
|
194
|
+
// { answer: 'write', piles, rows, text }. `reads` carries loadSourceSizeConfig, readQueue, realpath,
|
|
195
|
+
// lstat, isLineUnsafe and jsonForLine; `declaration` is the gates declaration's answer, or its error.
|
|
196
|
+
export const pileOfferOf = (root, reads, declaration, deps = {}) => {
|
|
197
|
+
const piles = pilesOf(reads.loadSourceSizeConfig(root, deps));
|
|
198
|
+
if (piles.length === 0) return { answer: 'none' };
|
|
199
|
+
const unsafe = piles.find(({ key }) => key.includes('`') || reads.isLineUnsafe(key));
|
|
200
|
+
if (unsafe !== undefined) return held('key', reads.jsonForLine(unsafe.key));
|
|
201
|
+
const queue = readQueueText(root, reads);
|
|
202
|
+
if (queue.cause !== undefined) return held('queue', queue.cause);
|
|
203
|
+
const { text, audit } = queue;
|
|
204
|
+
const named = new Set(audit.rows.map((row) => row.id));
|
|
205
|
+
const left = piles.map((pile) => ({ ...pile, id: pileIdOf(pile.key) })).filter(({ id }) => !named.has(id));
|
|
206
|
+
if (left.length === 0) return { answer: 'none' };
|
|
207
|
+
const later = headingsOf(text).filter(isLater);
|
|
208
|
+
if (later.length !== 1) return held('bucket', later.length);
|
|
209
|
+
const found = queueChecksOf(declaration, root);
|
|
210
|
+
if (found.cause !== undefined) return held('check', found.cause);
|
|
211
|
+
const queuePath = join(root, PILE_QUEUE_REL);
|
|
212
|
+
const realOf = (path) => {
|
|
213
|
+
try { return reads.realpath(path); } catch { return null; }
|
|
214
|
+
};
|
|
215
|
+
const queueReal = realOf(queuePath);
|
|
216
|
+
const checks = found.checks.filter((check) => queueReal !== null && realOf(check.path) === queueReal);
|
|
217
|
+
for (const check of checks) {
|
|
218
|
+
const verdict = judge(check, text);
|
|
219
|
+
if (verdict?.thrown !== undefined) return held('check', verdict.thrown);
|
|
220
|
+
if (verdict !== null) return held('queue', `it already fails its own check: ${verdict.problem}`);
|
|
221
|
+
}
|
|
222
|
+
const rows = left.map(pileRowOf);
|
|
223
|
+
const composed = (deps.spliceLater ?? spliceLater)(text, later[0].line, rows);
|
|
224
|
+
if (Buffer.byteLength(composed, 'utf8') > PILE_QUEUE_MAX_BYTES) return held('queue', `over ${PILE_QUEUE_MAX_BYTES} bytes once the rows are added`);
|
|
225
|
+
for (const check of checks) {
|
|
226
|
+
const verdict = judge(check, composed);
|
|
227
|
+
if (verdict?.thrown !== undefined) return held('check', verdict.thrown);
|
|
228
|
+
if (verdict !== null) return held('refused', verdict.problem, rows.length);
|
|
229
|
+
}
|
|
230
|
+
const defect = readbackDefect(text, composed, later[0].line, left, rows);
|
|
231
|
+
if (defect !== null) return held('queue', `the rows would not read back in the Later bucket: ${defect}`);
|
|
232
|
+
return { answer: 'write', piles: left, rows, text: composed };
|
|
233
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// source-size-core.mjs — the PURE READ core of the source-size practice (D-18): the ONE import point
|
|
2
2
|
// for every surface that must ask about the practice without reaching a writer. It owns no logic but
|
|
3
|
-
// the layout setup's
|
|
3
|
+
// the layout setup's and the pile offer's bound forms, no write API, and spawns only a read-only git query, so the read-graph purity suite
|
|
4
4
|
// (test/read-graph-purity.test.mjs) stays true however the halves behind it move.
|
|
5
5
|
//
|
|
6
6
|
// The halves, each holding ONE rule set and each within the cap this practice declares:
|
|
@@ -13,12 +13,15 @@
|
|
|
13
13
|
// lines, the band and the layout count, the recorded ratchet as data
|
|
14
14
|
// and the layout setup
|
|
15
15
|
//
|
|
16
|
-
// Re-export only, but for readLayoutSetup: a consumer imports the practice, never a particular half, so
|
|
16
|
+
// Re-export only, but for readLayoutSetup and readPileOffer: a consumer imports the practice, never a particular half, so
|
|
17
17
|
// a later split moves code without touching a single call site.
|
|
18
18
|
|
|
19
|
+
import { lstatSync, realpathSync } from 'node:fs';
|
|
20
|
+
import { readFileBytesNoFollowCapped } from './fs-read-nofollow.mjs';
|
|
19
21
|
import { INITIAL_ADOPTION_REASON, SOURCE_SIZE_SCHEMA, loadSourceSizeConfig, validateSourceSizeConfig } from './source-size-config.mjs';
|
|
20
22
|
import { judgeTree, stopsOf } from './source-size-judge.mjs';
|
|
21
|
-
import {
|
|
23
|
+
import { isLineUnsafe, jsonForLine } from './source-size-refusal.mjs';
|
|
24
|
+
import { PILE_QUEUE_MAX_BYTES, layoutSetupOf, pileOfferOf } from './source-size/index.mjs';
|
|
22
25
|
|
|
23
26
|
export {
|
|
24
27
|
SOURCE_SIZE_CONFIG_REL,
|
|
@@ -79,6 +82,16 @@ export {
|
|
|
79
82
|
SETUP_ANSWERS,
|
|
80
83
|
checkTargetOf,
|
|
81
84
|
layoutSetupOf,
|
|
85
|
+
PILE_ANSWERS,
|
|
86
|
+
PILE_HELD,
|
|
87
|
+
PILE_QUEUE_MAX_BYTES,
|
|
88
|
+
PILE_QUEUE_REL,
|
|
89
|
+
pileIdOf,
|
|
90
|
+
pileOfferOf,
|
|
91
|
+
pileRowOf,
|
|
92
|
+
pilesOf,
|
|
93
|
+
queueChecksOf,
|
|
94
|
+
spliceLater,
|
|
82
95
|
} from './source-size/index.mjs';
|
|
83
96
|
|
|
84
97
|
export {
|
|
@@ -103,3 +116,15 @@ export const readLayoutSetup = (root, deps = {}) => layoutSetupOf(root, {
|
|
|
103
116
|
absentConfig: validateSourceSizeConfig({ schema: SOURCE_SIZE_SCHEMA }),
|
|
104
117
|
reason: INITIAL_ADOPTION_REASON,
|
|
105
118
|
}, deps);
|
|
119
|
+
|
|
120
|
+
// readPileOffer(root, declaration, deps) → the pile offer for a project, the one bound form the advisor
|
|
121
|
+
// and the writer ask: the loader, the capped no-follow queue read, realpath, lstat and the line rule.
|
|
122
|
+
// `declaration` is the caller's loadDeclaration answer, or { outcome: 'error', message } where it threw.
|
|
123
|
+
export const readPileOffer = (root, declaration, deps = {}) => pileOfferOf(root, {
|
|
124
|
+
loadSourceSizeConfig,
|
|
125
|
+
readQueue: (path) => readFileBytesNoFollowCapped(path, PILE_QUEUE_MAX_BYTES),
|
|
126
|
+
realpath: realpathSync,
|
|
127
|
+
lstat: lstatSync,
|
|
128
|
+
isLineUnsafe,
|
|
129
|
+
jsonForLine,
|
|
130
|
+
}, declaration, deps);
|
|
@@ -47,6 +47,8 @@ export const standingWarningsOf = (findings) => findings.flatMap((f) => {
|
|
|
47
47
|
return kind && f.dimension !== 'depth' && f.actual > f.allowed && f.actual <= f.ceiling ? [{ ...f, kind }] : [];
|
|
48
48
|
});
|
|
49
49
|
export const hasLoweredRecord = (findings) => findings.some((f) => LOWERED_KINDS.has(f.kind));
|
|
50
|
+
// The spec store's files count, recorded before files per root left the store: no decomposition, so no focus line.
|
|
51
|
+
export const hasStoreRecord = (findings) => findings.some((f) => f.kind === 'store-record');
|
|
50
52
|
|
|
51
53
|
// One rule for every recorded number: a raise stops, any other change warns. `kinds` names no record
|
|
52
54
|
// yet, grew, lowered and no longer needed in the target's own vocabulary.
|
|
@@ -95,7 +97,7 @@ const measureLayout = (cwd, config, scope, deps) => {
|
|
|
95
97
|
const undecodable = [];
|
|
96
98
|
for (const [root, entries] of counted) {
|
|
97
99
|
const counts = layoutCounts(entries);
|
|
98
|
-
roots.set(root, counts.files);
|
|
100
|
+
if (root !== SPEC_STORE_ROOT) roots.set(root, counts.files);
|
|
99
101
|
const base = Buffer.from(root, 'utf8').toString('latin1');
|
|
100
102
|
for (const [below, facts] of counts.directories) {
|
|
101
103
|
const bytes = Buffer.from(below === '' ? base : root === '.' ? below : `${base}/${below}`, 'latin1');
|
|
@@ -119,7 +121,7 @@ const rootFindings = (measured, projected, recorded, tolerance) => {
|
|
|
119
121
|
else if (actual > was) findings.push({ kind: 'root-band', severity: WARNING, root, actual, recorded: was, ceiling });
|
|
120
122
|
}
|
|
121
123
|
for (const [root, was] of Object.entries(recorded.roots)) {
|
|
122
|
-
if (!measured.roots.has(root)) findings.push({ kind: 'root-gone', severity: WARNING, root, recorded: was.files });
|
|
124
|
+
if (!measured.roots.has(root)) findings.push({ kind: root === SPEC_STORE_ROOT ? 'store-record' : 'root-gone', severity: WARNING, root, recorded: was.files });
|
|
123
125
|
}
|
|
124
126
|
return findings;
|
|
125
127
|
};
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { SOURCE_SIZE_CONFIG_REL, SOURCE_SIZE_WARNING_PREFIX, SOURCE_SIZE_WHY, configPathFor, escapeForLine, isLineUnsafe, jsonForLine } from './source-size-refusal.mjs';
|
|
19
19
|
import { INITIAL_ADOPTION_REASON, SOURCE_SIZE_SCHEMA, practiceFacts } from './source-size-config.mjs';
|
|
20
20
|
import { SOURCE_SIZE_TOOL_PATH, dqUnsafePath } from './source-size-gate-cmd.mjs';
|
|
21
|
-
import { hasLoweredRecord, stopsOf, warningsOf } from './source-size-judge.mjs';
|
|
21
|
+
import { hasLoweredRecord, hasStoreRecord, stopsOf, warningsOf } from './source-size-judge.mjs';
|
|
22
22
|
import { isRaise, limitLines } from './source-size/index.mjs';
|
|
23
23
|
|
|
24
24
|
// The project directory is project-controlled too, so the path every refusal names enters its line
|
|
@@ -140,7 +140,7 @@ const FINDING_LINE = Object.freeze({
|
|
|
140
140
|
grew: (f) => `${f.rel}: ${f.dimension} ${f.actual} exceeds its recorded baseline ${f.recorded} — recorded debt is not permission to grow`,
|
|
141
141
|
'aggregate-grew': (f) => `${f.root}: aggregate lines ${f.actual} exceeds the recorded budget ${f.recorded} — splitting a file buys no aggregate headroom`,
|
|
142
142
|
'aggregate-unrecorded': (f) => `${f.root}: declared root carries NO recorded aggregate budget (${f.actual} lines measured) — the record must mirror the declared roots exactly`,
|
|
143
|
-
'root-unrecorded': (f) => `${f.root}:
|
|
143
|
+
'root-unrecorded': (f) => `${f.root}: declared root carries NO recorded files count (${f.actual} files measured) — the layout record must mirror the declared roots exactly`,
|
|
144
144
|
'root-grew': (f) => `${f.root}: files ${f.actual} exceeds its recorded ${f.recorded} beyond its band (up to ${f.ceiling})`,
|
|
145
145
|
'dir-over': (f) => `${f.dir}: ${f.dimension} ${f.actual} exceeds the limit ${f.allowed} beyond its band (up to ${f.ceiling})`,
|
|
146
146
|
'dir-grew': (f) => `${f.dir}: ${f.dimension} ${f.actual} exceeds its recorded ${f.recorded} — recorded debt is not permission to grow`,
|
|
@@ -156,7 +156,8 @@ const WARNING_LINE = Object.freeze({
|
|
|
156
156
|
'aggregate-root-gone': (f) => `${f.root}: recorded in "aggregate" but no longer a declared root — the regeneration removes it`,
|
|
157
157
|
'root-band': (f) => `${f.root}: files ${f.actual} is over its recorded ${f.recorded} but within its band (up to ${f.ceiling}) — past ${f.ceiling} it stops`,
|
|
158
158
|
'root-stale': (f) => `${f.root}: files ${f.actual} is under the recorded ${f.recorded} — the regeneration lowers it`,
|
|
159
|
-
'root-gone': (f) => `${f.root}: recorded in "layout"."roots" but no longer a
|
|
159
|
+
'root-gone': (f) => `${f.root}: recorded in "layout"."roots" but no longer a declared root — the regeneration removes it`,
|
|
160
|
+
'store-record': (f) => `${f.root}: recorded in "layout"."roots", but files per root no longer judges the spec store — the regeneration removes it`,
|
|
160
161
|
'dir-band': (f) => `${f.dir}: ${f.dimension} ${f.actual} is ${BAND(f)} — past ${f.ceiling} it stops`,
|
|
161
162
|
'dir-stale': (f) => `${f.dir}: ${f.dimension} ${f.actual} is under the recorded ${f.recorded} — the regeneration lowers it`,
|
|
162
163
|
'dir-obsolete': (f) => (f.actual > f.ceiling ? `${f.dir}: its depth record ${f.recorded} no longer sits on the shallowest directory beyond the depth band — the regeneration removes it` : `${f.dir}: ${f.dimension} ${f.actual} is within its band (up to ${f.ceiling}), so its record is obsolete — the regeneration removes it`),
|
|
@@ -206,7 +207,8 @@ export const checkReportLines = ({ cwd, config, verdict, absent = false }) => {
|
|
|
206
207
|
lines.push(...warningLines(warnings));
|
|
207
208
|
const lowered = hasLoweredRecord(warnings);
|
|
208
209
|
if (stops.length === 0) {
|
|
209
|
-
if (lowered) lines.push(tightenLine(cwd)
|
|
210
|
+
if (lowered || hasStoreRecord(warnings)) lines.push(tightenLine(cwd));
|
|
211
|
+
if (lowered) lines.push(SPLIT_QUALITY_FOCUS);
|
|
210
212
|
lines.push(warnings.length === 0
|
|
211
213
|
? `source-size: PASS — ${verdict.scope.files.length} in-scope file(s) within the declared caps`
|
|
212
214
|
: `source-size: PASS with ${warnings.length} warning(s) — ${verdict.scope.files.length} in-scope file(s) judged and nothing beyond a band or a record; each warning above repeats on every run until it is settled`);
|
|
@@ -362,8 +364,8 @@ tolerance and source, then what it does not judge, then its warnings, then its s
|
|
|
362
364
|
|
|
363
365
|
Counting: lines, and the longest line in BYTES. A terminator never counts (the CR of a CRLF
|
|
364
366
|
included); a last line with no final newline still counts; an empty file is 0 lines. Layout: the
|
|
365
|
-
entries of each directory
|
|
366
|
-
|
|
367
|
+
entries of each directory and its depth below its root, over every tracked entry under a declared
|
|
368
|
+
root plus the spec store docs/ai/specs walked from disk, and the files of each declared root.
|
|
367
369
|
|
|
368
370
|
A recorded entry is DEBT: a finding stops exactly when the regeneration would raise it, and a record
|
|
369
371
|
above the tree or gone warns until the regeneration lowers or removes it. Each declared root carries
|
package/tools/write-lanes.mjs
CHANGED
|
@@ -34,6 +34,7 @@ export const VARIANT_LANES = Object.freeze({
|
|
|
34
34
|
'source-size.id-squatter': LANE_USER,
|
|
35
35
|
'source-size.schema-1': LANE_CHAT,
|
|
36
36
|
'source-size.layout': LANE_CHAT,
|
|
37
|
+
'source-size.piles': LANE_CHAT,
|
|
37
38
|
'gate-hook': LANE_HARNESS,
|
|
38
39
|
'gate-hook.not-current': LANE_KIT,
|
|
39
40
|
'commit-guard': LANE_HARNESS,
|