@sabaiway/agent-workflow-kit 14.40.0 → 14.41.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.
@@ -71,11 +71,11 @@ 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 } from './source-size-core.mjs';
74
+ import { CHECKER_CLAIM, INITIAL_ADOPTION_REASON, SOURCE_SIZE_GATE_ID, classifySourceSizeGate, loadSourceSizeConfig, readLayoutSetup } 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';
78
- import { readPreCommitState } from './git-hooks.mjs';
78
+ import { hookCheckAnswers, plannedRoles, readPreCommitState, unsafeToolsPath } from './git-hooks.mjs';
79
79
  export { resolveGitHooksPath, readPreCommitState, canonicalGuardLineRe, INSTALLER_MARKER_RE } from './git-hooks.mjs';
80
80
  import { loadConfig } from './orchestration-config.mjs';
81
81
  import { homeRelative } from './bridge-state-dirs.mjs';
@@ -130,6 +130,13 @@ const ENFORCEMENT_UNMANAGED_HOOK = 'an UNMANAGED pre-commit hook exists \u2014 t
130
130
  const COMMIT_GUARD_INSTALLER_VIA_ITEM = 'the hook installer (scripts/install-git-hooks.mjs) is not deployed \u2014 apply the enforcement item first, then re-run';
131
131
  const COMMIT_GUARD_INSTALLER_OWN_STEP = 'the hook installer (scripts/install-git-hooks.mjs) is not deployed here \u2014 deploying the enforcement scripts into this project is your own step, then re-run';
132
132
  const COMMIT_GUARD_UNMANAGED_HOOK = 'an UNMANAGED pre-commit hook exists \u2014 the installer never overwrites it; adding the guard line to it is your own step';
133
+ const HOOK_CHECKS_UNMANAGED_HOOK = 'an UNMANAGED pre-commit hook exists \u2014 the installer never overwrites it; adding the lines this item would arm to it is your own step';
134
+ const HOOK_CHECKS_WAIT = 'the layout line follows the source-size.layout record \u2014 apply that item first; this item\'s check line then arms the layout line too';
135
+ const LAYOUT_RECORD_RECIPE = 'the hook is per clone and the config per branch: a branch or linked worktree with no size config is judged under the kit\'s values and stops on its piles until it takes the record (a hidden deployment\'s linked worktree carries none); one with an older config without layout is not judged on layout; one whose config is schema 1 or unminted stops every commit on that config\'s own stop until it takes the current config';
136
+ const LAYOUT_HELD = {
137
+ stops: () => 'the source-size check stops on this tree, so a layout record or layout line not yet in place waits \u2014 record that growth first with the reasoned --write-baseline its stop names, then re-run',
138
+ 'store-root': ({ root }) => `the source-size config declares the root "${root}" at or inside the spec store docs/ai/specs \u2014 the layout record starts once that root is declared outside it`,
139
+ };
133
140
  // ── the section contract tokens (doc-parity-bound in upgrade.md + the mode doc) ────────────────
134
141
  export const RECOMMENDATIONS_SECTION_HEADER = '## Recommendations (agent-workflow)';
135
142
  export const RECOMMENDATIONS_EMPTY_LINE = 'no recommendations — flow optimal.';
@@ -185,12 +192,14 @@ export const SEVERITIES = Object.freeze({
185
192
  'source-size.id-squatter': SEVERITY_ATTENTION,
186
193
  // A minted schema-1 config is a record the check stops on until the writer moves it.
187
194
  'source-size.schema-1': SEVERITY_ATTENTION,
195
+ 'source-size.layout': SEVERITY_OPTIONAL,
188
196
  'gate-hook': SEVERITY_OPTIONAL,
189
197
  // A placed hook that predates the marker key goes DARK on a marker-carrying declaration (unknown
190
198
  // key → auto-approval off), so a CONFIGURED capability silently stops working: attention, not an
191
199
  // offer to enable something.
192
200
  'gate-hook.marker-stale': SEVERITY_ATTENTION,
193
201
  'commit-guard': SEVERITY_OPTIONAL,
202
+ 'hook-checks': SEVERITY_OPTIONAL,
194
203
  enforcement: SEVERITY_OPTIONAL,
195
204
  'read-lane': SEVERITY_OPTIONAL,
196
205
  'read-lane.stale': SEVERITY_ATTENTION,
@@ -282,11 +291,13 @@ export const WHATS = Object.freeze({
282
291
  'source-size': 'no source-size gate — module size drifts unmeasured, and an over-cap file is invisible instead of recorded debt',
283
292
  '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
293
  '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',
294
+ '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',
285
295
  '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",
286
296
  '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',
287
297
  'gate-hook': '{n} declared gate(s) prompt per run — the gate-approval hook is not wired',
288
298
  'gate-hook.marker-stale': 'the declaration carries the lcovProducer key but the placed hook predates it — the hook goes dark and every gate prompts',
289
299
  'commit-guard': 'the gate matrix is final-run-capable but no commit-guard arms the pre-commit hook — a commit needs no green receipt yet',
300
+ 'hook-checks': 'the pre-commit hook lacks this kit\'s {checks} — the kit arms each line, refreshing a known-prior installer first',
290
301
  enforcement: ENFORCEMENT_WHAT,
291
302
  'read-lane': 'the gate hook is wired but the read-only compound lane is off — pipes/chains of seeded reads still prompt one by one',
292
303
  'read-lane.stale': 'the read-lane is ON but the placed gate hook is stale — an old hook never reads lanes.json, so the lane is silently dark; reseed it',
@@ -359,6 +370,7 @@ export const BENEFITS = Object.freeze({
359
370
  'source-size': 'maintainability — a module you can hold whole stays reviewable, and size drift becomes recorded, reasoned debt',
360
371
  'gate-hook': 'velocity — your own declared gate commands auto-approve byte-exactly (opt-in PreToolUse hook)',
361
372
  'commit-guard': 'integrity — commits require the ONE green --final receipt at the exact staged fingerprint (consented pre-commit arm)',
373
+ 'hook-checks': 'enforcement — every commit runs the checks armed here, so their findings stop the commit',
362
374
  enforcement: 'enforcement — bundled checks and the pre-commit hook keep caps, archives, and the generated index current',
363
375
  'read-lane': 'velocity — pipes/chains of your seeded read-only commands auto-approve instead of prompting (opt-in, conservatively classified)',
364
376
  'state-block': 'no silent stalls — a turn ending on «you are not needed», or on work it never started, warns at once instead of waiting to be spotted',
@@ -379,6 +391,7 @@ export const BENEFITS = Object.freeze({
379
391
  // The one arm whose gain differs from its base item's (BENEFITS stays keyed by item key).
380
392
  export const VARIANT_BENEFITS = Object.freeze({
381
393
  'executor-vehicle.differing': 'carrier fidelity — the placed executor runs the model and effort docs/ai/vehicles.json names, not a hand edit',
394
+ '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',
382
395
  });
383
396
 
384
397
  // ── the CLOSED opt-in capability registry (OPT-IN-SHIPS-INVISIBLE) ──────────────────────────────
@@ -416,6 +429,7 @@ export const OPT_IN_CAPABILITIES = Object.freeze([
416
429
  { id: 'read-lane', mode: 'hook', advisorKey: 'read-lane' },
417
430
  { id: 'commit-guard', mode: 'commit-guard', advisorKey: 'commit-guard' },
418
431
  { id: 'enforcement', mode: 'bootstrap', advisorKey: 'enforcement' },
432
+ { id: 'hook-checks', mode: 'bootstrap', advisorKey: 'hook-checks' },
419
433
  { id: 'attribution', mode: 'bootstrap', advisorKey: 'attribution' },
420
434
  { id: 'footprint-global', mode: 'bootstrap', advisorKey: 'footprint-global' },
421
435
  { id: 'state-block', mode: 'state-block-guard', advisorKey: 'state-block' },
@@ -855,13 +869,30 @@ const schema1Minted = (root, deps) => {
855
869
  try { const { state, config } = loadSourceSizeConfig(root, deps); return state === 'minted' && config.schema === 1; } catch { return false; }
856
870
  };
857
871
 
858
- const probeSourceSize = ({ root, deps, add, skip }) => {
872
+ // The layout setup's answer for the layout arm; its throw is a stated skip, and the other arms still speak.
873
+ const layoutSetupOrSkip = (root, deps, skip) => {
874
+ try {
875
+ return readLayoutSetup(root, deps);
876
+ } catch (err) {
877
+ skip('source-size.layout', err);
878
+ return null;
879
+ }
880
+ };
881
+
882
+ const probeSourceSize = ({ root, deps, add, skip, shared }) => {
859
883
  try {
860
884
  const tool = toolPath('source-size-check.mjs');
861
885
  if (schema1Minted(root, deps)) {
862
886
  add('source-size', fillTemplate(WHATS['source-size.schema-1'], {}), `node ${q(tool)} --write-baseline --cwd ${q(root)}`, 'source-size.schema-1');
863
887
  return;
864
888
  }
889
+ // The layout arm, additive: the record renders as its own item ahead of the other arms; a held answer
890
+ // no other arm speaks for is a stated skip, so the item's absence is explained in the run it goes.
891
+ const setup = layoutSetupOrSkip(root, deps, skip);
892
+ if (setup?.answer === 'record') {
893
+ shared.layoutRecord = add('source-size', fillTemplate(WHATS['source-size.layout'], {}),
894
+ `node ${q(tool)} ${setup.args.map(q).join(' ')} --cwd ${q(root)}`, 'source-size.layout', LAYOUT_RECORD_RECIPE);
895
+ } else if (setup?.answer === 'held' && Object.hasOwn(LAYOUT_HELD, setup.reason)) skip('source-size.layout', new Error(LAYOUT_HELD[setup.reason](setup)));
865
896
  const declaration = loadDeclaration(root, deps);
866
897
  const gates = declaration.outcome === 'loaded' ? declaration.gates : [];
867
898
  // The reason string is PINNED, not composed: it is copied unchanged into every entry the first
@@ -965,6 +996,30 @@ const probeCommitGuard = ({ root, deps, add, skip }) => {
965
996
  }
966
997
  };
967
998
 
999
+ // The hook-checks offer: the commit-guard probe's shape over the two answers the leaf asks, on disk.
1000
+ const HOOK_CHECK_NAMES = { rules: 'project-rules check', layout: 'layout check', both: 'project-rules and layout checks' };
1001
+ const probeHookChecks = ({ root, deps, add, skip, shared }) => {
1002
+ try {
1003
+ if (!(deps.exists ?? existsSync)(join(root, 'docs', 'ai'))) return;
1004
+ const unsafe = unsafeToolsPath(HERE);
1005
+ if (unsafe !== null) throw new Error(unsafe);
1006
+ const hook = readHookState(root, deps);
1007
+ if (hook.state === 'no-hooks-dir') return;
1008
+ const roles = plannedRoles(hookCheckAnswers(root, deps), hook).map(({ key }) => key);
1009
+ const waits = shared.layoutRecord === true && !hook.layoutArmed && !roles.includes('layout');
1010
+ if (roles.length === 0 && !waits) return;
1011
+ if (hook.state === 'unmanaged') throw new Error(HOOK_CHECKS_UNMANAGED_HOOK);
1012
+ if (!(deps.exists ?? existsSync)(join(root, 'scripts', 'install-git-hooks.mjs'))) {
1013
+ throw new Error(enforcementAdmits(root, deps) ? COMMIT_GUARD_INSTALLER_VIA_ITEM : COMMIT_GUARD_INSTALLER_OWN_STEP);
1014
+ }
1015
+ const keys = [...roles, ...(waits ? ['layout'] : [])];
1016
+ const checks = HOOK_CHECK_NAMES[keys.length === 2 ? 'both' : keys[0]];
1017
+ add('hook-checks', fillTemplate(WHATS['hook-checks'], { checks }), formsApply('hook-checks', root), 'hook-checks', waits ? HOOK_CHECKS_WAIT : null);
1018
+ } catch (err) {
1019
+ skip('hook-checks', err);
1020
+ }
1021
+ };
1022
+
968
1023
  const readEnforcementNode = (path, lstat) => {
969
1024
  try {
970
1025
  return lstat(path);
@@ -1357,7 +1412,7 @@ const readReadLaneToggle = (root, deps) => {
1357
1412
  // D3: the risk-marked keys — every key here has a per-item posture note in the mode doc, surfaced
1358
1413
  // at the consent moment; the static contract test asserts EXACT bidirectional coverage
1359
1414
  // (risk-marked keys == mode-doc note keys — a dropped note goes red, not silent).
1360
- export const RISK_NOTED_KEYS = Object.freeze(['bridge-tier', 'read-lane', 'worktrees-dir', 'adr-store-migration', 'gates-inert', 'source-size', 'gate-hook', 'mcp-channel', 'spec-adoption', 'enforcement', 'profile-gap', 'jev-connect', 'jev-skill', 'attribution', 'footprint-global']);
1415
+ export const RISK_NOTED_KEYS = Object.freeze(['bridge-tier', 'read-lane', 'worktrees-dir', 'adr-store-migration', 'gates-inert', 'source-size', 'gate-hook', 'mcp-channel', 'spec-adoption', 'enforcement', 'hook-checks', 'profile-gap', 'jev-connect', 'jev-skill', 'attribution', 'footprint-global']);
1361
1416
 
1362
1417
  // The feature-spec layer's adoption state (contract: kit/spec-adoption). The canon lets a plan cite
1363
1418
  // zero governing specs while a project adopts the layer, and nothing ever said whether adoption had
@@ -1657,6 +1712,7 @@ const PROBES = Object.freeze([
1657
1712
  probeGatesInert,
1658
1713
  probeSourceSize,
1659
1714
  probeCommitGuard,
1715
+ probeHookChecks,
1660
1716
  probeEnforcement,
1661
1717
  probeReadLane,
1662
1718
  probeStateBlockHook,
@@ -1,8 +1,9 @@
1
1
  // script-priors.mjs — the APPEND-ONLY catalog of every enforcement-script body this family has shipped
2
- // into a project's `scripts/`, as sha256 digests, and the ONE classifier the spec-layer ensure asks
3
- // before it refreshes a deployed script: `current` (byte-equal to the bundled copy) · `prior` (a body
4
- // a release shipped, never edited since) · `custom` (anything else — preserved verbatim, replaced only by
5
- // the replace run the user's yes starts). The lens-region idiom (AD-041) over whole script bodies.
2
+ // into a project's `scripts/`, as sha256 digests, and the ONE classifier a refresh asks before it
3
+ // replaces a deployed script — the spec-layer ensure for its pairs, the `hook-checks` writer for the
4
+ // hook installer: `current` (byte-equal to the bundled copy) · `prior` (a body a release shipped, never
5
+ // edited since) · `custom` (anything else — preserved verbatim, replaced only by the replace run the
6
+ // user's yes starts). The lens-region idiom (AD-041) over whole script bodies.
6
7
  //
7
8
  // Append discipline: when a release changes one of PRIOR_FILES, append the OUTGOING body's row here
8
9
  // in the same release and copy its bytes to test/fixtures/script-priors/<firstShipped>/<file>.txt —
@@ -13,11 +14,12 @@
13
14
 
14
15
  import { createHash } from 'node:crypto';
15
16
 
16
- // The deployed scripts the spec-layer ensure may REFRESH — the FULL refreshable catalog: the checker
17
- // pair that imports the reader, and (since 2a) the reader pair itself. Every other deployed script is
18
- // outside the refresh lane by design.
17
+ // The deployed scripts a refresh may REPLACE — the FULL refreshable catalog: the checker pair that
18
+ // imports the reader and (since 2a) the reader pair itself, which the spec-layer ensure refreshes, and
19
+ // the hook installer, which the `hook-checks` writer refreshes. Every other deployed script is outside
20
+ // the refresh lane by design.
19
21
  export const PRIOR_FILES = Object.freeze([
20
- 'check-docs-size.mjs', 'check-docs-size.test.mjs', 'spec-schema.mjs', 'spec-schema.test.mjs',
22
+ 'check-docs-size.mjs', 'check-docs-size.test.mjs', 'spec-schema.mjs', 'spec-schema.test.mjs', 'install-git-hooks.mjs',
21
23
  ]);
22
24
 
23
25
  const prior = (file, firstShipped, lastShipped, digest) => Object.freeze({ file, firstShipped, lastShipped, digest });
@@ -37,6 +39,7 @@ export const SCRIPT_PRIORS = Object.freeze([
37
39
  prior('spec-schema.mjs', '5.0.0', '7.2.1', '6a7d1e836c158baab5a412a1ad76d34891934dc28c88486c264a4b5d46f5892a'),
38
40
  prior('spec-schema.test.mjs', '5.0.0', '7.2.1', '698564d7283281be1826019d214df475bb876687915de086818d8f5ece0e0336'),
39
41
  prior('check-docs-size.mjs', '7.0.0', '8.1.5', '0cf90ae2cbfc809847574a8c71a6b1322c783359740b08e0ff179f0d9d04dffc'),
42
+ prior('install-git-hooks.mjs', '4.0.0', '8.2.1', '4c4010153cd3a9ca556f34d567d9985cff5c6e1b5ec3087ed7805e5c98f6f918'),
40
43
  ]);
41
44
 
42
45
  export const digestOf = (bytes) => createHash('sha256').update(bytes).digest('hex');
@@ -28,3 +28,9 @@ export {
28
28
  projectLayout,
29
29
  serialize,
30
30
  } from './record.mjs';
31
+
32
+ export {
33
+ SETUP_ANSWERS,
34
+ checkTargetOf,
35
+ layoutSetupOf,
36
+ } from './setup.mjs';
@@ -0,0 +1,40 @@
1
+ // setup.mjs — the layout setup: its closed answers, the one statement of what a --check run judges,
2
+ // and the setup's answer for a project. It writes no file, spawns no process of its own and imports no
3
+ // file of the practice: every read reaches it through the values its caller hands it, so the advisor,
4
+ // the git-hooks leaf and the check ask one rule.
5
+ //
6
+ // Dependency-free, Node >= 22. No side effects on import.
7
+
8
+ import { SPEC_STORE_ROOT } from './layout.mjs';
9
+
10
+ export const SETUP_ANSWERS = Object.freeze(['armable', 'record', 'held']);
11
+
12
+ // checkTargetOf({ loaded, absentConfig }) → exactly one of: the schema-1 stop, the unminted stop (a
13
+ // present config authored or incomplete), or the config to judge with the dimensions judged.
14
+ export const checkTargetOf = ({ loaded, absentConfig }) => {
15
+ const absent = loaded.state === 'absent';
16
+ const config = absent ? absentConfig : loaded.config;
17
+ if (config.schema === 1) return { stop: 'schema-1', config };
18
+ if (!absent && loaded.state !== 'minted') return { stop: 'unminted', config, state: loaded.state, missing: loaded.missingMachineKeys };
19
+ return { stop: null, config, judged: { absent, layout: absent || config.layout !== null } };
20
+ };
21
+
22
+ // The store-root rule of a config that starts layout: the store is a root of its own there.
23
+ const insideStore = (root) => root === SPEC_STORE_ROOT || root.startsWith(`${SPEC_STORE_ROOT}/`);
24
+
25
+ // layoutSetupOf(root, practice, deps) → { answer: 'armable' } | { answer: 'record', args } |
26
+ // { answer: 'held', reason } with reason schema-1, unminted, store-root (with the root) or stops.
27
+ // `practice` carries the loader, judgeTree, stopsOf, the absent config the check judges and the reason
28
+ // the record's first entries take.
29
+ export const layoutSetupOf = (root, practice, deps = {}) => {
30
+ const target = checkTargetOf({ loaded: practice.loadSourceSizeConfig(root, deps), absentConfig: practice.absentConfig });
31
+ if (target.stop !== null) return { answer: 'held', reason: target.stop };
32
+ const { config, judged } = target;
33
+ const starts = !judged.layout;
34
+ const storeRoot = starts ? config.roots.find(insideStore) : undefined;
35
+ if (storeRoot !== undefined) return { answer: 'held', reason: 'store-root', root: storeRoot };
36
+ const stops = practice.stopsOf(practice.judgeTree(root, config, deps, judged).findings).length > 0;
37
+ if (judged.absent) return stops ? { answer: 'record', args: ['--write-baseline', '--reason', practice.reason] } : { answer: 'armable' };
38
+ if (stops) return { answer: 'held', reason: 'stops' };
39
+ return starts ? { answer: 'record', args: ['--write-baseline', '--layout', '--reason', practice.reason] } : { answer: 'armable' };
40
+ };
@@ -42,6 +42,8 @@ import {
42
42
  SOURCE_SIZE_SCHEMA,
43
43
  applyOverride,
44
44
  assertNoStoreRoot,
45
+ checkTargetOf,
46
+ isRaise,
45
47
  loadSourceSizeConfig,
46
48
  matchesSourceSizeGate,
47
49
  materialize,
@@ -82,6 +84,7 @@ import {
82
84
 
83
85
  const usageFail = (message) => Object.assign(new Error(`[agent-workflow-kit] ${message}`), { exitCode: 2 });
84
86
  const RECORD_NOUN = 'the source-size record';
87
+ const LAYOUT_GROWTH_LEAD = 'source-size: --layout REFUSED — it starts the layout record and raises nothing else, but the record no longer holds for this tree, so that growth takes --write-baseline --reason first; nothing was written.';
85
88
 
86
89
  // What an absent config is judged as: schema 2 under the kit's values, layout over "." and the store.
87
90
  const ABSENT = Object.freeze({ _README: TEMPLATE_README, schema: SOURCE_SIZE_SCHEMA });
@@ -89,14 +92,12 @@ const ABSENT = Object.freeze({ _README: TEMPLATE_README, schema: SOURCE_SIZE_SCH
89
92
  // Every run returns the config it resolved, so the CLI states the limits that run judged, and the
90
93
  // scope it judged, so the CLI says once what it did not.
91
94
  export const runCheck = ({ cwd, deps = {} }) => {
92
- const { state, config: present, missingMachineKeys } = loadSourceSizeConfig(cwd, deps);
93
- const absent = state === 'absent';
94
- const config = absent ? validateSourceSizeConfig(ABSENT) : present;
95
- if (config.schema === 1) return { code: 1, lines: schema1StopLines(cwd), config };
96
- if (!absent && state !== 'minted') return { code: 1, lines: unmintedRefusalLines(cwd, { state, missing: missingMachineKeys }), config };
97
- const judged = { absent, layout: absent || config.layout !== null };
95
+ const target = checkTargetOf({ loaded: loadSourceSizeConfig(cwd, deps), absentConfig: validateSourceSizeConfig(ABSENT) });
96
+ const { config, judged } = target;
97
+ if (target.stop === 'schema-1') return { code: 1, lines: schema1StopLines(cwd), config };
98
+ if (target.stop === 'unminted') return { code: 1, lines: unmintedRefusalLines(cwd, { state: target.state, missing: target.missing }), config };
98
99
  const verdict = judgeTree(cwd, config, deps, judged);
99
- return { code: stopsOf(verdict.findings).length === 0 ? 0 : 1, lines: checkReportLines({ cwd, config, verdict, absent }), config, judged };
100
+ return { code: stopsOf(verdict.findings).length === 0 ? 0 : 1, lines: checkReportLines({ cwd, config, verdict, absent: judged.absent }), config, judged };
100
101
  };
101
102
 
102
103
  // ── the writer ────────────────────────────────────────────────────────────────────────────────────
@@ -133,6 +134,9 @@ export const runWriteBaseline = ({ cwd, reason, layout = false, deps = {} }) =>
133
134
  const judged = { absent, layout: absent || layout || config.layout !== null };
134
135
  const { plan, bandWarnings, warnings } = judgeForWrite(cwd, config, deps, judged);
135
136
  const starts = layout && !absent && config.layout === null;
137
+ // Starting layout on a minted record raises the layout record alone: growth takes the plain write first.
138
+ const plain = starts && loaded.state === 'minted' ? plan.deltas.filter((delta) => !plan.layout.deltas.includes(delta)) : [];
139
+ if (plain.some(isRaise)) return { code: 1, lines: [...bandWarnings, LAYOUT_GROWTH_LEAD, ...reasonRequiredLines(cwd, plain)], config, judged };
136
140
  if (plan.raises.length > 0 && reason === undefined) return { code: 1, lines: [...bandWarnings, ...reasonRequiredLines(cwd, plan.deltas, { layout: starts })], config, judged };
137
141
  const body = serialize(schema2Of(parsed), materialize(plan, reason));
138
142
  // Whether anything was written is decided by the BYTES, not by the delta count: completing a
@@ -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
- // for every surface that must ask about the practice without reaching a writer. It owns no logic and
3
- // no write API, and spawns only a read-only git query, so the read-graph purity suite
2
+ // for every surface that must ask about the practice without reaching a writer. It owns no logic but
3
+ // the layout setup's one bound form, 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:
@@ -10,10 +10,15 @@
10
10
  // • source-size-gate-cmd.mjs — whether a declared gate cmd IS this checker (the canonical matcher),
11
11
  // and which of the three tool claims it makes when it is not
12
12
  // • source-size/index.mjs — the door of the size check's module: the kit's limits and their
13
- // lines, the band and the layout count, and the recorded ratchet as data
13
+ // lines, the band and the layout count, the recorded ratchet as data
14
+ // and the layout setup
14
15
  //
15
- // Re-export only: a consumer imports the practice, never a particular half, so a later split moves
16
- // code without touching a single call site.
16
+ // Re-export only, but for readLayoutSetup: a consumer imports the practice, never a particular half, so
17
+ // a later split moves code without touching a single call site.
18
+
19
+ import { INITIAL_ADOPTION_REASON, SOURCE_SIZE_SCHEMA, loadSourceSizeConfig, validateSourceSizeConfig } from './source-size-config.mjs';
20
+ import { judgeTree, stopsOf } from './source-size-judge.mjs';
21
+ import { layoutSetupOf } from './source-size/index.mjs';
17
22
 
18
23
  export {
19
24
  SOURCE_SIZE_CONFIG_REL,
@@ -71,6 +76,9 @@ export {
71
76
  resolveLimits,
72
77
  serialize,
73
78
  walkSpecStore,
79
+ SETUP_ANSWERS,
80
+ checkTargetOf,
81
+ layoutSetupOf,
74
82
  } from './source-size/index.mjs';
75
83
 
76
84
  export {
@@ -84,3 +92,14 @@ export {
84
92
  // The claim vocabulary itself — a consumer naming an outcome imports the name, never a string
85
93
  // literal it could misspell into a silently-never-true comparison.
86
94
  export { CHECKER_CLAIM } from './checker-claim.mjs';
95
+
96
+ // readLayoutSetup(root, deps) → the layout setup's answer for a project, the one bound form the advisor
97
+ // and the git-hooks leaf ask: the loader, the tree judge and its stop filter, the absent config the
98
+ // check judges (schema 2 under the kit's values) and the reason the record's first entries take.
99
+ export const readLayoutSetup = (root, deps = {}) => layoutSetupOf(root, {
100
+ loadSourceSizeConfig,
101
+ judgeTree,
102
+ stopsOf,
103
+ absentConfig: validateSourceSizeConfig({ schema: SOURCE_SIZE_SCHEMA }),
104
+ reason: INITIAL_ADOPTION_REASON,
105
+ }, deps);
@@ -2,7 +2,7 @@ import { join, resolve } from 'node:path';
2
2
  import { dirCovers } from './declared-paths.mjs';
3
3
  import { claudeDirOf, quoteArg, skillTargets } from './jev-facts.mjs';
4
4
  import { targetsFor } from './jev-connect.mjs';
5
- import { BUNDLED_SCRIPT_NAMES, INSTALLER_REL, SCRIPTS_REL } from './git-hooks.mjs';
5
+ import { BUNDLED_SCRIPT_NAMES, INSTALLER_REL, SCRIPTS_DIR } from './node-evidence.mjs';
6
6
  import { dqUnsafePath } from './checker-claim.mjs';
7
7
  import { isLineUnsafe } from './source-size-refusal.mjs';
8
8
  import { SOURCE_SIZE_GATE_ID } from './source-size-gate-cmd.mjs';
@@ -32,9 +32,11 @@ export const VARIANT_LANES = Object.freeze({
32
32
  'source-size.adopted-elsewhere': LANE_CHAT,
33
33
  'source-size.id-squatter': LANE_USER,
34
34
  'source-size.schema-1': LANE_CHAT,
35
+ 'source-size.layout': LANE_CHAT,
35
36
  'gate-hook': LANE_HARNESS,
36
37
  'gate-hook.marker-stale': LANE_HARNESS,
37
38
  'commit-guard': LANE_HARNESS,
39
+ 'hook-checks': LANE_HARNESS,
38
40
  enforcement: LANE_HARNESS,
39
41
  'read-lane': LANE_CHAT,
40
42
  'read-lane.stale': LANE_HARNESS,
@@ -110,7 +112,7 @@ const getStartupPaths = ({ env, home, platform }) => targetsFor({
110
112
  }).filter(({ path }) => path !== null).map(({ path }) => path);
111
113
 
112
114
  const preCommitOf = (facts) => join(facts.hooksDir ?? join(facts.root, '.git', 'hooks'), 'pre-commit');
113
- const getEnforcementPaths = (facts) => [...BUNDLED_SCRIPT_NAMES.map((name) => join(facts.root, SCRIPTS_REL, name)), preCommitOf(facts)];
115
+ const getEnforcementPaths = (facts) => [...BUNDLED_SCRIPT_NAMES.map((name) => join(facts.root, SCRIPTS_DIR, name)), preCommitOf(facts)];
114
116
  const getGuardPaths = (facts) => [preCommitOf(facts), join(facts.root, INSTALLER_REL)];
115
117
 
116
118
  const formatCommand = (argv) => argv.map(quoteArg).join(' ');
@@ -183,6 +185,8 @@ const FORMS = Object.freeze({
183
185
  ['--enforcement', '--cwd', '<root>'], ['--apply', '--enforcement', '--cwd', '<root>'], getEnforcementPaths),
184
186
  'commit-guard': createForm('git-hooks.mjs',
185
187
  ['--commit-guard', '--cwd', '<root>'], ['--apply', '--commit-guard', '--cwd', '<root>'], getGuardPaths),
188
+ 'hook-checks': createForm('git-hooks.mjs',
189
+ ['--hook-checks', '--cwd', '<root>'], ['--apply', '--hook-checks', '--cwd', '<root>'], getGuardPaths),
186
190
  'worktrees-dir': createForm('velocity-profile.mjs',
187
191
  ['--worktrees', '--cwd', '<root>'], ['--apply', '--worktrees', '--cwd', '<root>'], LOCAL_SETTINGS_WRITES, false, null, true),
188
192
  'worktrees-dir.home': Object.freeze({