@dtmd/temper 0.0.20 → 0.0.22

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.
@@ -14,9 +14,15 @@ export type PayloadMember = {
14
14
  */
15
15
  name: string;
16
16
  /**
17
- * The `kind:name` address of the host member this member's unit composes under —
18
- * carried by a **nested file** child, whose path is its host's unit joined with the
19
- * host template's pattern; absent at every other locus.
17
+ * The host member's **own whole address** — the member this one's unit composes
18
+ * under. Carried by a **nested file** child, whose path is its host's unit joined
19
+ * with the host template's pattern; absent at every other locus.
20
+ *
21
+ * `<kind>:<name>` for a top-level host, and the host's own
22
+ * `<host-address>/<kind>/<key>` when the host is itself nested: deriving this
23
+ * member's path means deriving its host's unit, which means knowing the host's own
24
+ * host, so the column carries the whole chain rather than the nearest link
25
+ * (`specs/model/representation.md`, "nesting").
20
26
  */
21
27
  host?: string;
22
28
  /**
@@ -0,0 +1,2 @@
1
+ export declare const GUARD_COMMAND = "command -v temper >/dev/null 2>&1 || { echo \"temper: command not found\" >&2; exit 127; } && temper guard .";
2
+ export declare const SESSION_START_COMMAND = "command -v temper >/dev/null 2>&1 || { echo \"temper: command not found\" >&2; exit 127; } && temper check . --reporter session-start";
@@ -0,0 +1,3 @@
1
+ // This file carries temper's gate commands, generated from the engine's own constants. Do not edit this file manually.
2
+ export const GUARD_COMMAND = "command -v temper >/dev/null 2>&1 || { echo \"temper: command not found\" >&2; exit 127; } && temper guard .";
3
+ export const SESSION_START_COMMAND = "command -v temper >/dev/null 2>&1 || { echo \"temper: command not found\" >&2; exit 127; } && temper check . --reporter session-start";
@@ -34,3 +34,4 @@ export type { Shape } from "./Shape.js";
34
34
  export type { TemplateRow } from "./TemplateRow.js";
35
35
  export type { ValueType } from "./ValueType.js";
36
36
  export type { Verifier } from "./Verifier.js";
37
+ export { GUARD_COMMAND, SESSION_START_COMMAND } from "./gate-commands.js";
@@ -1 +1 @@
1
- export {};
1
+ export { GUARD_COMMAND, SESSION_START_COMMAND } from "./gate-commands.js";
@@ -17,7 +17,7 @@ export { blocks, file, include, mentionOf, renderText, span, text } from "./pros
17
17
  export type { Capability } from "./needs.js";
18
18
  export { bash, capability, permissionUnion } from "./needs.js";
19
19
  export type { Charset, Clause, ExtentUnit, Predicate, Requirement, Severity, Verifier } from "./contract.js";
20
- export { allowedChars, clause, closedKeys, count, degree, deny, enumOf, extent, forbiddenKeys, formatPlacesEdges, fresh, globValid, locusDeclared, maxLen, membership, mentionReachable, minLen, mustDefine, nameMatchesDir, optional, range, reachable, reachedFrom, required, requireSections, requirement, script, sectionContains, shape, telemetry, type, unique, uniqueName, when, } from "./contract.js";
20
+ export { allowedChars, clause, closedKeys, count, degree, deny, engineMatches, enumOf, extent, forbiddenKeys, formatPlacesEdges, fresh, globValid, locusDeclared, maxLen, membership, mentionReachable, minLen, mustDefine, nameMatchesDir, optional, range, reachable, reachedFrom, required, requireSections, requirement, script, sectionContains, shape, telemetry, type, unique, uniqueName, when, } from "./contract.js";
21
21
  export type { CollectionAddress, EdgeField, EdgeTargetFacts, EmbeddedMemberCollectionEntry, EmbeddedMemberValue, Format, Input, KindDefinition, KindFacts, KindOptions, KindRelocation, Layout, LayoutRegion, LeafSet, Locus, Member, MemberInit, Registration, Residue, ResolvedEmbeddedMemberCollectionEntry, ResolvedEmbeddedMemberValue, Shape, Template, UnitShape, } from "./kind.js";
22
22
  export { embeddedMemberValue, kind, relocate } from "./kind.js";
23
23
  export { input } from "./kind.js";
package/dist/src/index.js CHANGED
@@ -14,7 +14,7 @@
14
14
  */
15
15
  export { blocks, file, include, mentionOf, renderText, span, text } from "./prose.js";
16
16
  export { bash, capability, permissionUnion } from "./needs.js";
17
- export { allowedChars, clause, closedKeys, count, degree, deny, enumOf, extent, forbiddenKeys, formatPlacesEdges, fresh, globValid, locusDeclared, maxLen, membership, mentionReachable, minLen, mustDefine, nameMatchesDir, optional, range, reachable, reachedFrom, required, requireSections, requirement, script, sectionContains, shape, telemetry, type, unique, uniqueName, when, } from "./contract.js";
17
+ export { allowedChars, clause, closedKeys, count, degree, deny, engineMatches, enumOf, extent, forbiddenKeys, formatPlacesEdges, fresh, globValid, locusDeclared, maxLen, membership, mentionReachable, minLen, mustDefine, nameMatchesDir, optional, range, reachable, reachedFrom, required, requireSections, requirement, script, sectionContains, shape, telemetry, type, unique, uniqueName, when, } from "./contract.js";
18
18
  export { embeddedMemberValue, kind, relocate } from "./kind.js";
19
19
  // Inputs — the files a member's claims rest on, fingerprinted by the lock and moved
20
20
  // nowhere. A member-grain declaration, not a word in a body, so it rides here rather
@@ -668,10 +668,17 @@ export interface ResolvedEmbeddedMemberValue {
668
668
  /** Sibling collections, each entry's leaves already resolved. */
669
669
  readonly collections: Readonly<Record<string, readonly ResolvedEmbeddedMemberCollectionEntry[]>>;
670
670
  /**
671
- * The target facts of each edge field this value *fills*, keyed by the edge field's
672
- * own name — the data a `render` hook selects to spell a reference. An unfilled
673
- * field is no edge and carries no entry; a kind declaring no edge fields (or a value
674
- * composed off a bare kind name, which carries none) has an empty map.
671
+ * The target facts of each edge field this value *fills and resolves*, keyed by the edge
672
+ * field's own name — the data a `render` hook selects to spell a reference. Two cases
673
+ * read absent: an unfilled field (no edge at all), and a kind declaring no edge fields —
674
+ * or a value composed off a bare kind name, which carries none. A hook spelling a
675
+ * reference off such a key must therefore handle its absence. A third derives no facts
676
+ * but does not read absent: a filled field whose target defers to `check`, naming a
677
+ * declared `at`-locus kind's uncomposed member (`pipeline.md`, "Emit", the "Refusing"
678
+ * bullet) — reading it refuses by name at emit, naming the member, the value, the field
679
+ * and the authored address, rather than handing a hook an absent key to trip over. The
680
+ * default TOML view is unaffected either way, writing the authored address leaf whether
681
+ * the program resolves it or the gate does.
675
682
  */
676
683
  readonly targets: Readonly<Record<string, EdgeTargetFacts>>;
677
684
  }
package/dist/src/kind.js CHANGED
@@ -8,6 +8,7 @@
8
8
  * rows. Identity travels by import, never by string — a `kind` reference is the imported
9
9
  * value.
10
10
  */
11
+ import { isOneSegment } from "./member-address.js";
11
12
  /**
12
13
  * Declare a file a member's claims rest on — the lock fingerprints it and no byte
13
14
  * reaches the projection. The path resolves against the stating module, so the call is
@@ -235,6 +236,7 @@ export function relocate(base, delta) {
235
236
  export function embeddedMemberValue(init) {
236
237
  const definition = typeof init.kind === "string" ? undefined : init.kind;
237
238
  const kindKey = definition?.key ?? init.kind;
239
+ refuseSegmentedKey(kindKey, init.key);
238
240
  refuseReservedLeaf(kindKey, init.key, init.leaves);
239
241
  for (const [collection, entries] of Object.entries(init.collections ?? {})) {
240
242
  for (const entry of entries) {
@@ -252,6 +254,33 @@ export function embeddedMemberValue(init) {
252
254
  ...(edgeFields !== undefined ? { edgeFields } : {}),
253
255
  };
254
256
  }
257
+ /**
258
+ * Refuse an embedded member's key that is not **one address segment** — empty, or carrying
259
+ * the `/` the member-address grammar cuts an address at ({@link isOneSegment}). A member's
260
+ * identity *is* its `<host-address>/<kind>/<key>` address, so a key carrying the separator
261
+ * spells an address one segment too long: `authority/rejected` spells what the sibling
262
+ * keyed `authority` spells for its `rejected` leaf, and every reader answers that address
263
+ * at leaf grain.
264
+ *
265
+ * Refused at compose for the posture {@link refuseReservedLeaf} states for the sibling
266
+ * case: a coincident address is loud at the authoring seam, where the author can still
267
+ * rename, never at emit over bytes already written (0051). The engine's own judge is not
268
+ * this one twice — it judges a committed lock (hand-edited, or written by an older SDK),
269
+ * this one judges the composing program.
270
+ *
271
+ * Scoped to the member's own key: a `collections` entry key lands inside the **leaf tail**,
272
+ * which the grammar defines as the whole remainder after the third slash, so it aliases
273
+ * nothing and is deliberately left legal.
274
+ *
275
+ * # Throws
276
+ * If `key` is empty or carries `/`.
277
+ */
278
+ function refuseSegmentedKey(kind, key) {
279
+ if (isOneSegment(key))
280
+ return;
281
+ throw new Error(`embedded member \`${kind}\` \`${key}\`: a member's key is one address segment — ` +
282
+ `non-empty and carrying no \`/\`, the separator its address is cut at`);
283
+ }
255
284
  /**
256
285
  * Refuse a composed leaf named {@link RESERVED_LEAF} — the key a read member's own span
257
286
  * owns, so a second meaning under it is a coincident leaf address, refused at compose
@@ -1,18 +1,22 @@
1
1
  /**
2
2
  * The member-address grammar — one home for every spelling a member's identity takes and
3
- * for the reader those writers round-trip against. Three spellings, each the one before
4
- * it plus a segment:
3
+ * for the reader those writers round-trip against. Three spellings, each built on the one
4
+ * before it:
5
5
  *
6
6
  * - `<kind>:<name>` — a **host address**, a top-level member's own identity.
7
7
  * - `<host-address>/<kind>/<key>` — a **nested-member address**, the identity a member
8
- * embedded in a host carries.
9
- * - `<member>/<kind>/<key>/<leaf>` — a **leaf address**, one authored string beneath a
10
- * nested member. A grain of its own, and no member address at all.
8
+ * beneath a host carries. Any member's address may host, so the host segment is itself
9
+ * a member address and the spelling nests as deep as the model does.
10
+ * - `<member-address>/<leaf>` — a **leaf address**, one authored string beneath a nested
11
+ * member. A grain of its own, and no member address at all.
11
12
  *
12
- * Because the third is the second plus a `/<leaf>` tail, both are read off one
13
- * segmentation ({@link segment}) rather than two independently-shaped parses that could
14
- * come to disagree about where the member ends. The engine's `src/member_address.rs` is
15
- * the other end of the same grammar: a spelling moves on both sides at once or the seam
13
+ * Every name, key and leaf is **one segment** — a leaf's child path joins its own layers
14
+ * with `.`, never `/` (`declarations.ts`'s `embeddedLeafMentionRows`) — so the segment
15
+ * **count** decides the grain: a member address has an odd count, a leaf address an even
16
+ * one. That parity is the whole discrimination, which is why both grains are read off
17
+ * **one** segmentation ({@link segment}) rather than two independently-shaped parses that
18
+ * could come to disagree about where the member ends. The engine's `src/member_address.rs`
19
+ * is the other end of the same grammar: a spelling moves on both sides at once or the seam
16
20
  * breaks.
17
21
  */
18
22
  /** The two halves a host address names — the reader's answer, and never re-split by hand. */
@@ -24,7 +28,10 @@ export interface HostAddress {
24
28
  }
25
29
  /** One parsed nested-member address. */
26
30
  export interface NestedAddress {
27
- /** The host member's own `<kind>:<name>` address — the segment before the first `/`. */
31
+ /**
32
+ * The host member's own address — every segment but the final two, verbatim, and itself
33
+ * a member address (`area:a`, or `area:a/page/b` one layer down).
34
+ */
28
35
  readonly host: string;
29
36
  /** The nested member's kind. */
30
37
  readonly kind: string;
@@ -35,16 +42,21 @@ export interface NestedAddress {
35
42
  export interface LeafAddress {
36
43
  /**
37
44
  * The member the leaf lives under, verbatim as its author spelled it: the canonical
38
- * `<kind>:<name>` host address, or the bare member id this SDK's own leaf writer and
39
- * the committed lock mention targets spell. Which of the two a head is, is resolution's
40
- * question, not the grammar's.
45
+ * `<kind>:<name>` host address, that host's own whole address one layer down, or the
46
+ * bare member id a lock committed before the writers spelled the canonical head.
47
+ * Which spelling a head is, is resolution's question, not the grammar's.
41
48
  */
42
49
  readonly member: string;
43
50
  /** The nested member's kind. */
44
51
  readonly kind: string;
45
52
  /** The nested member's key among its host's members of that kind. */
46
53
  readonly key: string;
47
- /** The leaf's path within the nested member — the whole remainder after the third slash. */
54
+ /**
55
+ * The leaf's path within the nested member — the address's **final segment**, dots
56
+ * intact and carrying no `/`: a child path joins its own layers with `.`
57
+ * (`declarations.ts`'s `embeddedLeafMentionRows`), so a further `/` is a further segment
58
+ * and the count reads the whole as a member address instead.
59
+ */
48
60
  readonly childPath: string;
49
61
  }
50
62
  /** Spell a top-level member's own `<kind>:<name>` address. */
@@ -52,9 +64,91 @@ export declare function hostAddress(kind: string, name: string): string;
52
64
  /** Spell a nested member's address from its host's address, its own kind and its key. */
53
65
  export declare function nestedAddress(host: string, kind: string, key: string): string;
54
66
  /**
55
- * Spell one leaf's address beneath a nested member. `member` is carried verbatim, so a
56
- * writer holding the bare member id spells the short form the lock already commits
57
- * ({@link LeafAddress.member}).
67
+ * The three facts a member's own address composes from — its kind, its name, and the host
68
+ * member a nested-file child sits under. Structurally what a composed `Member` carries, so
69
+ * {@link memberAddress} takes one without this module depending on `kind.ts`: the grammar
70
+ * is the bottom of the tree and owes the member model nothing.
71
+ */
72
+ export interface AddressedMember {
73
+ /** The member's kind. */
74
+ readonly kind: string;
75
+ /** The member's name among its kind — its key where it sits beneath a host. */
76
+ readonly name: string;
77
+ /**
78
+ * The host a nested-file child composes under; absent at every other locus. Itself an
79
+ * addressed member, because a host may be nested too and contributes its **own whole
80
+ * address** — the shape recurses exactly as far as the model nests, which is what a
81
+ * composed `Member` already carries (`kind.ts`'s `Member.host`).
82
+ */
83
+ readonly host?: AddressedMember | undefined;
84
+ }
85
+ /**
86
+ * A member's **own address** — the one home for the discrimination between the two forms a
87
+ * composed member's identity takes, and the twin of the engine's `payload_member_address`
88
+ * over the same member arriving on the seam ({@link AddressedMember.host} is the payload's
89
+ * own `host` column).
90
+ *
91
+ * A top-level member's address is its kind joined onto its name ({@link hostAddress}). A
92
+ * nested **file** child's identity *is* its whole `<host-address>/<kind>/<key>` address,
93
+ * exactly as an embedded member's is: the host segment is the whole of what tells two
94
+ * same-named children under different hosts apart, so two hosts may each carry a `home`
95
+ * and neither claims the other's. Keying one by `<kind>:<name>` alone made a child's name
96
+ * corpus-wide at a grain the grammar scopes to a host.
97
+ *
98
+ * The host contributes its **own whole address**, composed through this very function, so
99
+ * depth is the model's to choose rather than the grammar's: any member's address may host,
100
+ * and a host that is itself nested is spelled `area:a/page/b`, so the grandparent survives
101
+ * into every row its child is declared under. Flattening the host to `<kind>:<name>` lost
102
+ * that grandparent the moment a second layer emitted, and keyed two cousins — one name
103
+ * under each of two hosts — under one address.
104
+ *
105
+ * Every site naming "the address of this member" reads the rule here rather than deciding
106
+ * the join again, so the rows a member is declared, cited and mentioned under cannot come
107
+ * to disagree with the address it resolves at.
108
+ */
109
+ export declare function memberAddress(member: AddressedMember): string;
110
+ /**
111
+ * Whether `spelling` is exactly **one segment** of this grammar — non-empty, and carrying
112
+ * none of the `/` {@link segment} cuts an address at.
113
+ *
114
+ * The predicate every writer's caller judges a key by, because {@link nestedAddress} is
115
+ * infallible and the reader beneath it is not. A key carrying a `/` shifts every segment
116
+ * below it by one: `nestedAddress("spec:alpha", "decision", "authority/rejected")` spells
117
+ * the very address the member keyed `authority` spells for its `rejected` leaf — and since
118
+ * the count decides the grain, that address is **even** and so a leaf's by construction,
119
+ * no member address at all. The member's own identity answers its sibling's leaf and
120
+ * nothing answers the member. An empty key spells an address {@link segment} admits at no
121
+ * grain at all.
122
+ * `specs/model/representation.md` ("member") makes both a malformed lock rather than a
123
+ * precedence rule: resolution is total, and coincident addresses are refused.
124
+ *
125
+ * The engine's `is_one_segment` is the same predicate at the seam's other end.
126
+ */
127
+ export declare function isOneSegment(spelling: string): boolean;
128
+ /**
129
+ * Whether `spelling` may be joined onto a member's name as a **qualifier** — the text a
130
+ * name carries after its own `:` to tell two members apart that share a collection key (a
131
+ * hook's matcher: `PostToolUse:Edit|Write`).
132
+ *
133
+ * The bar is {@link isOneSegment}'s, less its non-emptiness: a qualifier joins a non-empty
134
+ * key, so the joined name is non-empty whatever the qualifier is, and an **empty**
135
+ * qualifier is a real authored spelling — a group whose `matcher` is `""` is its own group
136
+ * on the wire, and a matcher is carried verbatim, never normalized. What it may not carry
137
+ * is the `/` {@link segment} cuts an address at: the joined name is the first segment of
138
+ * every address beneath the member, so a `/` in it shifts every segment below by one and
139
+ * the member's own handler answers to an address naming no member at all.
140
+ *
141
+ * The engine's `is_name_qualifier` is the same predicate at the seam's other end.
142
+ */
143
+ export declare function isNameQualifier(spelling: string): boolean;
144
+ /**
145
+ * Spell one leaf's address beneath a nested member. `member` is carried verbatim, and
146
+ * every writer hands it the hosting member's **own whole address** at whatever grain the
147
+ * host sits — `<kind>:<name>` top-level, the host's whole address under a nested one
148
+ * ({@link memberAddress}). A bare member id spells a head the reader still accepts for
149
+ * the locks that commit it ({@link LeafAddress.member}), never one to write: a nested
150
+ * file child's identity *is* its host-qualified address, so a bare head names no member
151
+ * at resolution and two sibling children of one name head one string.
58
152
  */
59
153
  export declare function leafAddress(member: string, kind: string, key: string, childPath: string): string;
60
154
  /**
@@ -83,20 +177,34 @@ export declare function edgeLookupKey(address: string, to: readonly string[]): s
83
177
  * ({@link parseNestedAddress}, {@link parseLeafAddress}) and no host address at all. The
84
178
  * refusal lives here rather than at each caller, so a reader that asks "is this a host
85
179
  * address?" never has to re-spell the separator to get the answer right.
180
+ *
181
+ * A name carrying a colon is not hypothetical: a hook's name is its lifecycle event, then
182
+ * `:` and its matcher's authored bytes (`hook:PostToolUse:Edit|Write`), because the
183
+ * matcher group — not the event — is the member. The grammar is unchanged by it: the
184
+ * split is at the first colon, so the kind comes off and the rest stays one name, and the
185
+ * qualifier joined onto it is judged by {@link isNameQualifier} rather than given a third
186
+ * segment.
86
187
  */
87
188
  export declare function parseHostAddress(address: string): HostAddress | undefined;
88
189
  /**
89
- * Parse a nested-member address, or `undefined` when `address` is not one: exactly three
90
- * non-empty segments, the first of them a host address.
190
+ * Parse a nested-member address, or `undefined` when `address` is not one.
191
+ *
192
+ * The grammar is an **odd** count of non-empty segments, three or more: a host address —
193
+ * every segment but the final two, itself a member address at any depth — then the nested
194
+ * kind and the key. Depth is the model's to choose, not the grammar's: any member's address
195
+ * may host, so the reader reads what the model nests rather than capping at one layer.
91
196
  *
92
- * A `/<leaf>` tail is ruled out here explicitly — a leaf is its own grain, and truncating
93
- * one to the member that happens to contain it would answer a leaf reference with a member
94
- * the author never named.
197
+ * The **leaf tail is ruled out by the count**: a leaf is its own grain, parsed by
198
+ * {@link parseLeafAddress} off this very segmentation, so an even count is no member
199
+ * address at all. Truncating one to the member that happens to contain the leaf would
200
+ * answer a leaf reference with a member the author never named.
95
201
  */
96
202
  export declare function parseNestedAddress(address: string): NestedAddress | undefined;
97
203
  /**
98
- * Parse a leaf address, or `undefined` when `target` carries no tail or a segment-shaped
99
- * hole. The head is carried on verbatim rather than split, because the bare member id is
100
- * a live short form ({@link LeafAddress.member}).
204
+ * Parse a leaf address — a member address plus its `/<leaf>` tail, so an **even** count of
205
+ * segments — or `undefined` when `target` carries an odd count or a segment-shaped hole.
206
+ *
207
+ * The head is carried on verbatim rather than split, because the bare member id is a live
208
+ * short form ({@link LeafAddress.member}).
101
209
  */
102
210
  export declare function parseLeafAddress(target: string): LeafAddress | undefined;
@@ -1,18 +1,22 @@
1
1
  /**
2
2
  * The member-address grammar — one home for every spelling a member's identity takes and
3
- * for the reader those writers round-trip against. Three spellings, each the one before
4
- * it plus a segment:
3
+ * for the reader those writers round-trip against. Three spellings, each built on the one
4
+ * before it:
5
5
  *
6
6
  * - `<kind>:<name>` — a **host address**, a top-level member's own identity.
7
7
  * - `<host-address>/<kind>/<key>` — a **nested-member address**, the identity a member
8
- * embedded in a host carries.
9
- * - `<member>/<kind>/<key>/<leaf>` — a **leaf address**, one authored string beneath a
10
- * nested member. A grain of its own, and no member address at all.
11
- *
12
- * Because the third is the second plus a `/<leaf>` tail, both are read off one
13
- * segmentation ({@link segment}) rather than two independently-shaped parses that could
14
- * come to disagree about where the member ends. The engine's `src/member_address.rs` is
15
- * the other end of the same grammar: a spelling moves on both sides at once or the seam
8
+ * beneath a host carries. Any member's address may host, so the host segment is itself
9
+ * a member address and the spelling nests as deep as the model does.
10
+ * - `<member-address>/<leaf>` — a **leaf address**, one authored string beneath a nested
11
+ * member. A grain of its own, and no member address at all.
12
+ *
13
+ * Every name, key and leaf is **one segment** — a leaf's child path joins its own layers
14
+ * with `.`, never `/` (`declarations.ts`'s `embeddedLeafMentionRows`) — so the segment
15
+ * **count** decides the grain: a member address has an odd count, a leaf address an even
16
+ * one. That parity is the whole discrimination, which is why both grains are read off
17
+ * **one** segmentation ({@link segment}) rather than two independently-shaped parses that
18
+ * could come to disagree about where the member ends. The engine's `src/member_address.rs`
19
+ * is the other end of the same grammar: a spelling moves on both sides at once or the seam
16
20
  * breaks.
17
21
  */
18
22
  /** Spell a top-level member's own `<kind>:<name>` address. */
@@ -24,9 +28,81 @@ export function nestedAddress(host, kind, key) {
24
28
  return `${host}/${kind}/${key}`;
25
29
  }
26
30
  /**
27
- * Spell one leaf's address beneath a nested member. `member` is carried verbatim, so a
28
- * writer holding the bare member id spells the short form the lock already commits
29
- * ({@link LeafAddress.member}).
31
+ * A member's **own address** — the one home for the discrimination between the two forms a
32
+ * composed member's identity takes, and the twin of the engine's `payload_member_address`
33
+ * over the same member arriving on the seam ({@link AddressedMember.host} is the payload's
34
+ * own `host` column).
35
+ *
36
+ * A top-level member's address is its kind joined onto its name ({@link hostAddress}). A
37
+ * nested **file** child's identity *is* its whole `<host-address>/<kind>/<key>` address,
38
+ * exactly as an embedded member's is: the host segment is the whole of what tells two
39
+ * same-named children under different hosts apart, so two hosts may each carry a `home`
40
+ * and neither claims the other's. Keying one by `<kind>:<name>` alone made a child's name
41
+ * corpus-wide at a grain the grammar scopes to a host.
42
+ *
43
+ * The host contributes its **own whole address**, composed through this very function, so
44
+ * depth is the model's to choose rather than the grammar's: any member's address may host,
45
+ * and a host that is itself nested is spelled `area:a/page/b`, so the grandparent survives
46
+ * into every row its child is declared under. Flattening the host to `<kind>:<name>` lost
47
+ * that grandparent the moment a second layer emitted, and keyed two cousins — one name
48
+ * under each of two hosts — under one address.
49
+ *
50
+ * Every site naming "the address of this member" reads the rule here rather than deciding
51
+ * the join again, so the rows a member is declared, cited and mentioned under cannot come
52
+ * to disagree with the address it resolves at.
53
+ */
54
+ export function memberAddress(member) {
55
+ const { host } = member;
56
+ if (host === undefined)
57
+ return hostAddress(member.kind, member.name);
58
+ return nestedAddress(memberAddress(host), member.kind, member.name);
59
+ }
60
+ /**
61
+ * Whether `spelling` is exactly **one segment** of this grammar — non-empty, and carrying
62
+ * none of the `/` {@link segment} cuts an address at.
63
+ *
64
+ * The predicate every writer's caller judges a key by, because {@link nestedAddress} is
65
+ * infallible and the reader beneath it is not. A key carrying a `/` shifts every segment
66
+ * below it by one: `nestedAddress("spec:alpha", "decision", "authority/rejected")` spells
67
+ * the very address the member keyed `authority` spells for its `rejected` leaf — and since
68
+ * the count decides the grain, that address is **even** and so a leaf's by construction,
69
+ * no member address at all. The member's own identity answers its sibling's leaf and
70
+ * nothing answers the member. An empty key spells an address {@link segment} admits at no
71
+ * grain at all.
72
+ * `specs/model/representation.md` ("member") makes both a malformed lock rather than a
73
+ * precedence rule: resolution is total, and coincident addresses are refused.
74
+ *
75
+ * The engine's `is_one_segment` is the same predicate at the seam's other end.
76
+ */
77
+ export function isOneSegment(spelling) {
78
+ return spelling !== "" && !spelling.includes("/");
79
+ }
80
+ /**
81
+ * Whether `spelling` may be joined onto a member's name as a **qualifier** — the text a
82
+ * name carries after its own `:` to tell two members apart that share a collection key (a
83
+ * hook's matcher: `PostToolUse:Edit|Write`).
84
+ *
85
+ * The bar is {@link isOneSegment}'s, less its non-emptiness: a qualifier joins a non-empty
86
+ * key, so the joined name is non-empty whatever the qualifier is, and an **empty**
87
+ * qualifier is a real authored spelling — a group whose `matcher` is `""` is its own group
88
+ * on the wire, and a matcher is carried verbatim, never normalized. What it may not carry
89
+ * is the `/` {@link segment} cuts an address at: the joined name is the first segment of
90
+ * every address beneath the member, so a `/` in it shifts every segment below by one and
91
+ * the member's own handler answers to an address naming no member at all.
92
+ *
93
+ * The engine's `is_name_qualifier` is the same predicate at the seam's other end.
94
+ */
95
+ export function isNameQualifier(spelling) {
96
+ return !spelling.includes("/");
97
+ }
98
+ /**
99
+ * Spell one leaf's address beneath a nested member. `member` is carried verbatim, and
100
+ * every writer hands it the hosting member's **own whole address** at whatever grain the
101
+ * host sits — `<kind>:<name>` top-level, the host's whole address under a nested one
102
+ * ({@link memberAddress}). A bare member id spells a head the reader still accepts for
103
+ * the locks that commit it ({@link LeafAddress.member}), never one to write: a nested
104
+ * file child's identity *is* its host-qualified address, so a bare head names no member
105
+ * at resolution and two sibling children of one name head one string.
30
106
  */
31
107
  export function leafAddress(member, kind, key, childPath) {
32
108
  return `${nestedAddress(member, kind, key)}/${childPath}`;
@@ -61,6 +137,13 @@ export function edgeLookupKey(address, to) {
61
137
  * ({@link parseNestedAddress}, {@link parseLeafAddress}) and no host address at all. The
62
138
  * refusal lives here rather than at each caller, so a reader that asks "is this a host
63
139
  * address?" never has to re-spell the separator to get the answer right.
140
+ *
141
+ * A name carrying a colon is not hypothetical: a hook's name is its lifecycle event, then
142
+ * `:` and its matcher's authored bytes (`hook:PostToolUse:Edit|Write`), because the
143
+ * matcher group — not the event — is the member. The grammar is unchanged by it: the
144
+ * split is at the first colon, so the kind comes off and the rest stays one name, and the
145
+ * qualifier joined onto it is judged by {@link isNameQualifier} rather than given a third
146
+ * segment.
64
147
  */
65
148
  export function parseHostAddress(address) {
66
149
  if (address.includes("/"))
@@ -72,39 +155,69 @@ export function parseHostAddress(address) {
72
155
  }
73
156
  /**
74
157
  * Cut an address into its segments, or `undefined` when it carries fewer than three or a
75
- * segment-shaped hole. The tail keeps its own dots and slashes, so it is the whole
76
- * remainder after the third slash rather than a fourth segment among more.
158
+ * segment-shaped hole — an address names exactly one thing or the reader refuses, so an
159
+ * empty segment names nothing.
160
+ *
161
+ * The cut is at **every** `/`, and the count decides the grain: every name, key and leaf
162
+ * is one segment, so an even count ends in a `/<leaf>` tail and an odd one stops at member
163
+ * grain. The tail is therefore the final segment alone, not the remainder past a fixed
164
+ * count.
165
+ *
166
+ * Three is the cut's floor: the shallowest member address beneath a host is
167
+ * `<kind>:<name>/<kind>/<key>`, and the shallowest leaf address names a nested member's
168
+ * kind and key ahead of its leaf ({@link LeafAddress}), so it is four.
77
169
  */
78
170
  function segment(address) {
79
171
  const parts = address.split("/");
80
- if (parts.length < 3)
81
- return undefined;
82
- const [host, kind, key] = parts;
83
- const tail = parts.length > 3 ? parts.slice(3).join("/") : undefined;
84
- if (host === "" || kind === "" || key === "" || tail === "")
172
+ if (parts.length < 3 || parts.includes(""))
85
173
  return undefined;
86
- return { host, kind, key, tail };
174
+ // Even is leaf grain: the final segment is the whole leaf, and everything ahead of it is
175
+ // a member address of odd count — three segments at least, which the cut below takes
176
+ // apart.
177
+ const leaf = parts.length % 2 === 0;
178
+ const member = leaf ? parts.slice(0, -1) : parts;
179
+ // A member address ends in its own kind and key; everything ahead of those two is the
180
+ // host address, carried whole however deep it runs.
181
+ return {
182
+ host: member.slice(0, -2).join("/"),
183
+ kind: member[member.length - 2],
184
+ key: member[member.length - 1],
185
+ tail: leaf ? parts[parts.length - 1] : undefined,
186
+ };
87
187
  }
88
188
  /**
89
- * Parse a nested-member address, or `undefined` when `address` is not one: exactly three
90
- * non-empty segments, the first of them a host address.
189
+ * Parse a nested-member address, or `undefined` when `address` is not one.
91
190
  *
92
- * A `/<leaf>` tail is ruled out here explicitly — a leaf is its own grain, and truncating
93
- * one to the member that happens to contain it would answer a leaf reference with a member
94
- * the author never named.
191
+ * The grammar is an **odd** count of non-empty segments, three or more: a host address —
192
+ * every segment but the final two, itself a member address at any depth — then the nested
193
+ * kind and the key. Depth is the model's to choose, not the grammar's: any member's address
194
+ * may host, so the reader reads what the model nests rather than capping at one layer.
195
+ *
196
+ * The **leaf tail is ruled out by the count**: a leaf is its own grain, parsed by
197
+ * {@link parseLeafAddress} off this very segmentation, so an even count is no member
198
+ * address at all. Truncating one to the member that happens to contain the leaf would
199
+ * answer a leaf reference with a member the author never named.
95
200
  */
96
201
  export function parseNestedAddress(address) {
97
202
  const segments = segment(address);
203
+ // An odd count and no tail: an even count ends in a `/<leaf>`, a different grain.
98
204
  if (segments === undefined || segments.tail !== undefined)
99
205
  return undefined;
100
- if (parseHostAddress(segments.host) === undefined)
206
+ // The host is itself a member address, read at its own grain: a top-level host address,
207
+ // or a nested one read back through this very parser however deep it runs. Never off a
208
+ // first-colon split, which would take `area` / `a/page/b` out of `area:a/page/b`.
209
+ const { host } = segments;
210
+ if (parseHostAddress(host) === undefined && parseNestedAddress(host) === undefined) {
101
211
  return undefined;
102
- return { host: segments.host, kind: segments.kind, key: segments.key };
212
+ }
213
+ return { host, kind: segments.kind, key: segments.key };
103
214
  }
104
215
  /**
105
- * Parse a leaf address, or `undefined` when `target` carries no tail or a segment-shaped
106
- * hole. The head is carried on verbatim rather than split, because the bare member id is
107
- * a live short form ({@link LeafAddress.member}).
216
+ * Parse a leaf address — a member address plus its `/<leaf>` tail, so an **even** count of
217
+ * segments — or `undefined` when `target` carries an odd count or a segment-shaped hole.
218
+ *
219
+ * The head is carried on verbatim rather than split, because the bare member id is a live
220
+ * short form ({@link LeafAddress.member}).
108
221
  */
109
222
  export function parseLeafAddress(target) {
110
223
  const segments = segment(target);