@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.
package/dist/src/emit.js CHANGED
@@ -10,10 +10,10 @@
10
10
  */
11
11
  import { fileURLToPath } from "node:url";
12
12
  import { readFileSync } from "node:fs";
13
- import { checkMentions, isTextSpan, renderText, resolveLeaf } from "./prose.js";
13
+ import { checkMentions, defersToGate, isTextSpan, renderText, resolveEmbeddedLeaves } from "./prose.js";
14
14
  import { permissionUnion } from "./needs.js";
15
- import { compareStrings, compileDeclarations, declaredAddresses, declaredAtLocusKinds, declaredRequirements, encodeSeam, placementKey, registrationRows, settingsRows, tapHookRows, uniqueMap, } from "./declarations.js";
16
- import { bareLookupKey, edgeLookupKey, hostAddress, nestedAddress } from "./member-address.js";
15
+ import { compareStrings, compileDeclarations, declaredAddresses, declaredAtLocusKinds, declaredRequirements, encodeSeam, mergedRegistrationRows, settingsRows, uniqueMap, } from "./declarations.js";
16
+ import { bareLookupKey, edgeLookupKey, hostAddress, isOneSegment, memberAddress, nestedAddress, } from "./member-address.js";
17
17
  /** The {@link MentionScope} a set of {@link ResolveOptions} names — its two sets, each defaulting to empty. */
18
18
  function scopeOf(options) {
19
19
  return {
@@ -62,47 +62,92 @@ function joinSlash(...parts) {
62
62
  return parts.filter((part) => part !== "" && part !== ".").join("/");
63
63
  }
64
64
  /**
65
- * `name` spliced through `pattern`'s single `*` — the one name-through-a-glob map, shared
66
- * by a flat `at` glob and a host template's path pattern. A `*`-free pattern is a fixed
67
- * path, left verbatim. `starredSegment` admits a single-`*` segment glob whose one `*` stars
68
- * a whole leading directory segment (a starred-segment kind's locus), landing `<name>/<file>`;
69
- * every other caller passes `false`, where a `/` beside the `*` is a stray directory the
70
- * splice cannot place.
65
+ * `name` spliced through `pattern`'s lone `*` — the one name-through-a-glob rule, and the
66
+ * only one: every flat `at` glob and every host template's path pattern places through it.
67
+ *
68
+ * A leading `**\/` collapses to zero segments, because an any-depth prefix names where the
69
+ * glob *matches*, never where a projection *lands*. What remains is placement: literal
70
+ * segments verbatim, the name into the final segment's lone `*` (`**\/CLAUDE.md` → the
71
+ * fixed `CLAUDE.md`, `**\/sub/*.json` → `sub/<name>.json`), and a `*`-free pattern wholly
72
+ * fixed. `starredSegment` is the one admission on top: a `*\/<file>` glob whose `*` stars a
73
+ * whole leading directory segment, landing `<name>/<file>` — there the name identifies the
74
+ * directory, not the leaf. Every other caller passes `false`.
71
75
  *
72
76
  * # Throws
73
- * If `pattern` carries a `*` yet is neither single-star nor single-segment (and not the
74
- * admitted leading-segment case): the splice would leave a stray literal `*` or directory
75
- * segment behind.
77
+ * If what remains after the collapse carries more than one `*`, or its one `*` sits above
78
+ * the final segment and is not the admitted starred-segment case: the splice would leave a
79
+ * stray literal `*` behind, or star a directory the member name does not identify.
76
80
  */
77
81
  function spliceName(kindName, pattern, name, starredSegment) {
78
- const stars = pattern.split("*").length - 1;
79
- const leadingSegment = starredSegment && stars === 1 && pattern.startsWith("*/");
80
- if (stars > 0 && !leadingSegment && (stars > 1 || pattern.includes("/"))) {
81
- throw new Error(`kind \`${kindName}\`: glob \`${pattern}\` is neither a single-segment single-\`*\` ` +
82
- `pattern nor an any-depth \`**\` glob — a member name splices through neither.`);
82
+ const placed = pattern.startsWith("**/") ? pattern.slice(3) : pattern;
83
+ const stars = placed.split("*").length - 1;
84
+ const starInLeaf = placed.lastIndexOf("*") > placed.lastIndexOf("/");
85
+ const leadingSegment = starredSegment && stars === 1 && placed.startsWith("*/");
86
+ if (stars > 0 && !leadingSegment && (stars > 1 || !starInLeaf)) {
87
+ throw new Error(`kind \`${kindName}\`: glob \`${pattern}\` maps its member name onto no one path — a ` +
88
+ `name splices through exactly one \`*\`, confined to the glob's final segment (a ` +
89
+ `leading \`**/\` collapses to nothing, and literal leading segments are fixed ` +
90
+ `placement); this glob carries more than one \`*\`, or a \`*\` above the leaf.`);
91
+ }
92
+ return placed.replace("*", name);
93
+ }
94
+ /**
95
+ * The placement a member of `facts` named `name` takes **inside the locus its pattern is
96
+ * rooted at** — the half an `at` kind and a nested file child derive identically, since a
97
+ * host template's path pattern stands to its host's unit exactly as an `at` kind's glob
98
+ * stands to its `governs` root (`specs/model/representation.md`, "locus").
99
+ *
100
+ * A **directory** unit owns a directory and seats its entry file inside it, so the pattern
101
+ * names that entry file and the member's own name is the directory: the leading segment
102
+ * drops and `<name>/` takes its place, which is what makes `*\/SKILL.md` and a template's
103
+ * `*\/PAGE.md` land the same shape. Every other shape places its name through the one
104
+ * splice rule ({@link spliceName}), a starred-segment kind's `*\/<file>` included.
105
+ *
106
+ * # Throws
107
+ * Whatever {@link spliceName} throws when the pattern maps the name onto no one path.
108
+ */
109
+ function placementInUnit(facts, pattern, name) {
110
+ if (facts.unitShape === "directory") {
111
+ const slash = pattern.indexOf("/");
112
+ return joinSlash(name, slash < 0 ? pattern : pattern.slice(slash + 1));
83
113
  }
84
- return pattern.replace("*", name);
114
+ return spliceName(facts.name, pattern, name, facts.unitShape === "starred-segment");
85
115
  }
86
116
  /**
87
117
  * The unit `host`'s file children compose their paths under — a directory unit's own
88
118
  * directory, since a template's path pattern is relative to the parent's unit.
89
119
  *
120
+ * Composed from the host's **own projection**, never read off its locus columns: a
121
+ * directory unit seats its entry file inside the directory it owns, so the directory is
122
+ * that projection less its final segment. A host at an `at` locus supplies
123
+ * `<root>/<name>`; a host that is itself a nested file child supplies an interior under
124
+ * *its* own host's unit, so depth is unbounded and one rule composes every layer —
125
+ * exactly as the engine's `nested_file_path` (`src/drift.rs`) composes it.
126
+ *
90
127
  * # Throws
91
128
  * If the host owns no directory unit: a lone file has no interior for a child to sit in.
129
+ * Propagates every refusal the host's own path derivation raises.
92
130
  */
93
131
  function hostUnit(host, context) {
94
- if (host.facts.locus.kind === "at" && host.facts.unitShape === "directory") {
95
- return joinSlash(host.facts.locus.root, host.name);
132
+ if (host.facts.unitShape !== "directory") {
133
+ throw new Error(`${context}: its host \`${memberAddress(host)}\` owns no directory unit — a template's ` +
134
+ `path pattern is relative to the host's unit, and a lone file has no interior for a ` +
135
+ `child to sit in (specs/model/representation.md, "locus").`);
136
+ }
137
+ const projection = projectionPath(host);
138
+ const slash = projection.lastIndexOf("/");
139
+ if (slash < 0) {
140
+ throw new Error(`${context}: its host \`${memberAddress(host)}\` projects to \`${projection}\`, which names ` +
141
+ `no directory for a child to sit in (specs/model/representation.md, "locus").`);
96
142
  }
97
- throw new Error(`${context}: its host \`${hostAddress(host.kind, host.name)}\` owns no directory unit — a template's ` +
98
- `path pattern is relative to the host's unit, and a lone file has no interior for a ` +
99
- `child to sit in (specs/model/representation.md, "locus").`);
143
+ return projection.slice(0, slash);
100
144
  }
101
145
  /**
102
146
  * A nested file child's harness-relative locus: its host member's unit joined with the
103
- * host template's path pattern, its own name spliced through the pattern. The pattern is
104
- * the host kind's declared fact and the child kind governs no glob, so one home owns the
105
- * path and no child contends with its host's own locus.
147
+ * host template's path pattern, its own name placed through the pattern
148
+ * ({@link placementInUnit}). The pattern is the host kind's declared fact and the child
149
+ * kind governs no glob, so one home owns the path and no child contends with its host's
150
+ * own locus.
106
151
  *
107
152
  * # Throws
108
153
  * If the child names no host, or its host's kind templates no file layer for the child's
@@ -116,20 +161,30 @@ function nestedFilePath(member) {
116
161
  }
117
162
  const template = (host.facts.templates ?? []).find((layer) => layer.kind.key === member.kind && layer.path !== undefined);
118
163
  if (template?.path === undefined) {
119
- throw new Error(`${context}: its host \`${hostAddress(host.kind, host.name)}\` templates no file layer for kind ` +
164
+ throw new Error(`${context}: its host \`${memberAddress(host)}\` templates no file layer for kind ` +
120
165
  `\`${member.kind}\` — the path pattern is the host kind's declared fact, and there is ` +
121
166
  `none to compose against (specs/model/representation.md, "locus").`);
122
167
  }
123
- return joinSlash(hostUnit(host, context), spliceName(member.kind, template.path, member.name, false));
168
+ return joinSlash(hostUnit(host, context), placementInUnit(member.facts, template.path, member.name));
124
169
  }
125
170
  /**
126
- * The harness-relative locus `member` projects onto: a directory unit lands its entry
127
- * file under `<root>/<name>/`; a lone file splices the name through the glob's single
128
- * `*` (an any-depth glob — a memory kind's `**\/CLAUDE.md` — lands the root `<name>.md`,
129
- * and a `*`-free glob is a fixed path left verbatim); a nested file child composes its
130
- * path under its host's unit ({@link nestedFilePath}). The engine derives the same locus
131
- * from the same facts (`src/drift.rs`'s `member_projection_path`); the two must agree,
132
- * since a hook's rendered link is written from this side and reaped from that one.
171
+ * The harness-relative locus `member` projects onto: a file member places its name inside
172
+ * the locus its own `governs` glob is rooted at ({@link placementInUnit}); a nested file
173
+ * child places it inside its host's unit instead, through that same rule and its host
174
+ * kind's declared template pattern ({@link nestedFilePath}). The engine
175
+ * derives the same locus from the same facts (`src/drift.rs`'s `member_projection_path`);
176
+ * the two must agree, since a hook's rendered link is written from this side and reaped
177
+ * from that one.
178
+ *
179
+ * The property both derivations owe is a **round trip**: the path a member is placed at is
180
+ * one the kind's own glob finds again when `check` walks the locus, so placement and
181
+ * discovery are one agreement rather than two spellings that happen to coincide. A path
182
+ * outside its glob is written and locked yet ungoverned — the kind counted `(0)` with no
183
+ * finding to name it. The engine holds the round trip with the glob engine it already has
184
+ * (`UngovernedProjection`); this side has no matcher, so what it holds is the half a
185
+ * matcher is not needed for — a member name carrying the `/` a path is placed with
186
+ * ({@link refuseSegmentedName}) — and `tests/projection_path_seam.rs` gates the property
187
+ * itself, per unit shape, over what emit actually wrote.
133
188
  *
134
189
  * # Throws
135
190
  * If the kind is embedded (no standalone projection), or the member's glob or host
@@ -145,14 +200,7 @@ function projectionPath(member) {
145
200
  if (facts.locus.kind === "nested-file")
146
201
  return nestedFilePath(member);
147
202
  const { root, glob } = facts.locus;
148
- if (facts.unitShape === "directory") {
149
- const slash = glob.indexOf("/");
150
- return joinSlash(root, member.name, slash < 0 ? glob : glob.slice(slash + 1));
151
- }
152
- if (glob.includes("**"))
153
- return joinSlash(root, `${member.name}.md`);
154
- const starredSegment = facts.unitShape === "starred-segment";
155
- return joinSlash(root, spliceName(facts.name, glob, member.name, starredSegment));
203
+ return joinSlash(root, placementInUnit(facts, glob, member.name));
156
204
  }
157
205
  /**
158
206
  * `to`'s path as read from the document at `from` — the shared leading segments drop
@@ -176,16 +224,23 @@ function relativeProjection(from, to) {
176
224
  * selects them renders a reference true by construction; the four are the whole set.
177
225
  *
178
226
  * An unfilled leaf is no edge, so it contributes no entry: requiredness is the kind's
179
- * own field schema, which fails in the author's program at compose time.
227
+ * own field schema, which fails in the author's program at compose time. A filled leaf
228
+ * whose address {@link defersToGate} admits derives none either — the program's own
229
+ * universe does not reach it, so the address rides the lock as authored and `check` owns
230
+ * its route verdict, exactly as a dangling mention defers (`pipeline.md`, "Emit", the
231
+ * "Refusing" bullet). Such a field is reported by name in {@link EdgeTargets.deferred}
232
+ * rather than dropped, so reading it refuses by name ({@link deferringTargets}) instead
233
+ * of surfacing as an absent key.
180
234
  *
181
235
  * # Throws
182
- * If a filled leaf names no composed member, names one that owns no projection to
183
- * point at, or names a bare nested key several hosts carry
184
- * ({@link resolvedTargetFacts}). An edge target cannot defer to the gate the way a bare
185
- * mention may: the reference is written now, and there is nothing true to write.
236
+ * If a filled leaf names no composed member and no declared `at`-locus kind either, names
237
+ * one that owns no projection to point at, or names a bare nested key several hosts carry
238
+ * ({@link resolvedTargetFacts}).
186
239
  */
187
240
  function edgeTargetFacts(host, value, leaves, options) {
188
- const targets = {};
241
+ const facts = {};
242
+ const deferred = new Map();
243
+ const { deferrableKinds } = scopeOf(options);
189
244
  const context = `member \`${host.name}\`: embedded value \`${value.key}\` of kind \`${value.kind}\``;
190
245
  for (const edge of value.edgeFields ?? []) {
191
246
  const address = leaves[edge.field];
@@ -195,12 +250,47 @@ function edgeTargetFacts(host, value, leaves, options) {
195
250
  const target = options.members?.get(lookup);
196
251
  const reference = `${context}: edge field \`${edge.field}\` names \`${address}\``;
197
252
  if (target === undefined) {
253
+ // Judged on the address the author wrote, never `lookup`: the one-element-`to` lift
254
+ // spells a bare name as a host address for the member table alone, and a bare name
255
+ // names no discoverable member.
256
+ if (defersToGate(address, deferrableKinds)) {
257
+ deferred.set(edge.field, reference);
258
+ continue;
259
+ }
198
260
  throw new Error(`${reference}, which resolves to no composed member — an edge target's facts are ` +
199
261
  `derived, never fabricated (specs/model/pipeline.md, "Emit", the "Refusing" bullet).`);
200
262
  }
201
- targets[edge.field] = resolvedTargetFacts(host, target, lookup, reference);
263
+ facts[edge.field] = resolvedTargetFacts(host, target, reference);
202
264
  }
203
- return targets;
265
+ return { facts, deferred };
266
+ }
267
+ /**
268
+ * The `targets` view a `render` hook receives: the resolved facts, plus a trap that
269
+ * refuses by name on a deferred edge field. Emit derives no facts for a target `check`
270
+ * owns, and a format cannot spell a reference off facts that do not exist — so the read
271
+ * is the failure, and it names the member, the value, the field and the address rather
272
+ * than surfacing as a `TypeError` off an absent key in the author's own template
273
+ * (invariant 6, "Loud or nothing").
274
+ *
275
+ * Only a string key in the deferred set is trapped: a symbol get — inspection, a `then`
276
+ * probe — reads through untouched. `ownKeys` is deliberately untrapped, so the deferred
277
+ * field stays invisible to {@link placedEdges}'s `Object.keys` and earns no
278
+ * `format-places-edges` obligation.
279
+ */
280
+ function deferringTargets(targets) {
281
+ if (targets.deferred.size === 0)
282
+ return targets.facts;
283
+ return new Proxy(targets.facts, {
284
+ get(record, property, receiver) {
285
+ const reference = typeof property === "string" ? targets.deferred.get(property) : undefined;
286
+ if (reference !== undefined) {
287
+ throw new Error(`${reference}, whose target defers to \`check\` — emit derives no facts for it, so a ` +
288
+ `format cannot spell a reference off it (specs/model/pipeline.md, "Emit", the ` +
289
+ `"Refusing" bullet).`);
290
+ }
291
+ return Reflect.get(record, property, receiver);
292
+ },
293
+ });
204
294
  }
205
295
  /** Whether an address named the nested index — the embedded values one spelling reaches. */
206
296
  function isNested(target) {
@@ -208,25 +298,26 @@ function isNested(target) {
208
298
  }
209
299
  /**
210
300
  * The four derived facts one resolved edge target contributes, read off the target
211
- * itself and never off the citing instance. A top-level member answers with its own
212
- * identity and its own projection; an embedded value answers with its own kind and key,
213
- * its canonical `<host-address>/<kind>/<key>` address (whichever spelling the leaf
214
- * authored), and its *host's* projection — an embedded member owns no file, so the file
215
- * its rendering lands in is the host's.
301
+ * itself and never off the citing instance. A member answers with its own identity, its own
302
+ * {@link memberAddress} — the canonical one, whichever of its spellings the leaf authored,
303
+ * so a file child cited by its bare key still renders the host-qualified address it
304
+ * resolves at — and its own projection; an embedded value answers with its own kind and
305
+ * key, its canonical `<host-address>/<kind>/<key>` address, and its *host's* projection —
306
+ * an embedded member owns no file, so the file its rendering lands in is the host's.
216
307
  *
217
308
  * # Throws
218
309
  * If a bare `kind:key` is carried by more than one host — an ambiguous address names
219
310
  * nothing, and the full spelling is what tells the carriers apart — or if the target,
220
311
  * or the host carrying it, owns no projection to point at.
221
312
  */
222
- function resolvedTargetFacts(host, target, lookup, reference) {
313
+ function resolvedTargetFacts(host, target, reference) {
223
314
  const noProjection = () => new Error(`${reference}, which owns no projection to reference (specs/model/representation.md, "locus").`);
224
315
  if (!isNested(target)) {
225
316
  if (!isProjected(target))
226
317
  throw noProjection();
227
318
  return {
228
319
  name: target.name,
229
- address: lookup,
320
+ address: memberAddress(target),
230
321
  kind: target.kind,
231
322
  path: relativeProjection(projectionPath(host), projectionPath(target)),
232
323
  repoRootedPath: projectionPath(target),
@@ -244,46 +335,28 @@ function resolvedTargetFacts(host, target, lookup, reference) {
244
335
  const carrierPath = projectionPath(carrier);
245
336
  return {
246
337
  name: value.key,
247
- address: nestedAddress(hostAddress(carrier.kind, carrier.name), value.kind, value.key),
338
+ address: nestedAddress(memberAddress(carrier), value.kind, value.key),
248
339
  kind: value.kind,
249
340
  path: relativeProjection(projectionPath(host), carrierPath),
250
341
  repoRootedPath: carrierPath,
251
342
  };
252
343
  }
253
344
  /**
254
- * Resolve one embedded member's value's leaves — top-level and each
255
- * collection entry's — to their final stored strings, and derive its edge fields'
256
- * target facts off the resolved leaves: a `Text`-authored leaf
257
- * resolves the way `resolveBody` resolves a member-level `Text` body (mention
258
- * resolution-checked against `mentionable`, loud on a dangling address); a
259
- * bare-string leaf is unchanged. The one resolution point shared by the
260
- * default TOML view and a kind's own `render` hook, so refusing on a dangling
261
- * embedded-kind leaf mention never depends on whether the kind declares
262
- * `render` (`pipeline.md`, "Emit", the "Refusing" bullet).
345
+ * One embedded member value as a kind's `render` hook receives it: the shared leaf
346
+ * walk ({@link resolveEmbeddedLeaves}, scoped by {@link scopeOf}) plus this module's
347
+ * own job — the edge fields' target facts derived off the resolved top-level leaves.
348
+ * Called on both the default-TOML and the `render`-hook path before either reads a
349
+ * leaf, so refusing on a dangling embedded-kind leaf mention never depends on whether
350
+ * the kind declares `render` (`pipeline.md`, "Emit", the "Refusing" bullet).
263
351
  */
264
352
  function resolveMemberLeaves(host, value, options) {
265
- const scope = scopeOf(options);
266
- const context = (childPath) => `member.${value.kind} ${value.key}: leaf \`${childPath}\``;
267
- const leaves = {};
268
- for (const [key, leaf] of Object.entries(value.leaves)) {
269
- leaves[key] = resolveLeaf(leaf, scope, context(key));
270
- }
271
- const collections = {};
272
- for (const [collection, entries] of Object.entries(value.collections)) {
273
- collections[collection] = entries.map((entry) => {
274
- const entryLeaves = {};
275
- for (const [leaf, text] of Object.entries(entry.leaves)) {
276
- entryLeaves[leaf] = resolveLeaf(text, scope, context(`${collection}.${entry.key}.${leaf}`));
277
- }
278
- return { key: entry.key, leaves: entryLeaves };
279
- });
280
- }
353
+ const { leaves, collections } = resolveEmbeddedLeaves(value, scopeOf(options));
281
354
  return {
282
355
  kind: value.kind,
283
356
  key: value.key,
284
357
  leaves,
285
358
  collections,
286
- targets: edgeTargetFacts(host, value, leaves, options),
359
+ targets: deferringTargets(edgeTargetFacts(host, value, leaves, options)),
287
360
  };
288
361
  }
289
362
  /**
@@ -356,10 +429,12 @@ function recordingView(resolved, edgeFields, placed) {
356
429
  * declares one runs the hook against a {@link recordingView} and reports what it
357
430
  * selected.
358
431
  *
359
- * The obligation ranges over the edges this value *fills*, never its kind's whole
360
- * declared set: an unfilled field is no edge, so a format cannot omit it. `undefined`
361
- * when the value fills none — there is nothing to place, so the row records nothing
362
- * rather than an empty column on every ordinary value.
432
+ * The obligation ranges over the edges this value *fills and resolves*, never its kind's
433
+ * whole declared set: an unfilled field is no edge, so a format cannot omit it, and a
434
+ * field whose target defers to `check` carries no facts to place — the route verdict is
435
+ * the gate's, not this clause's. `undefined` when the value leaves the set empty — there
436
+ * is nothing to place, so the row records nothing rather than an empty column on every
437
+ * ordinary value.
363
438
  *
364
439
  * This renders the value a second time, the way `nestedMemberRow` reads its leaves a
365
440
  * second time: a hook is pure (emit double-verifies its own bytes), so the observing
@@ -369,7 +444,8 @@ function placedEdges(host, value, options) {
369
444
  if ((value.edgeFields ?? []).length === 0)
370
445
  return undefined;
371
446
  const resolved = resolveMemberLeaves(host, value, options);
372
- // `targets` carries exactly the filled edge fields — an unfilled one derives no facts.
447
+ // `targets` carries exactly the filled, resolved edge fields — an unfilled one and a
448
+ // deferred one each derive no facts.
373
449
  const edgeFields = new Set(Object.keys(resolved.targets));
374
450
  if (edgeFields.size === 0)
375
451
  return undefined;
@@ -381,7 +457,7 @@ function placedEdges(host, value, options) {
381
457
  }
382
458
  /**
383
459
  * Every composed embedded value's placed edge fields, keyed by the value's
384
- * {@link placementKey} — what `emit` hands {@link compileDeclarations} so each
460
+ * {@link nestedAddress} — what `emit` hands {@link compileDeclarations} so each
385
461
  * `nested_member` row carries its own format's placement record. Iterates exactly the
386
462
  * values `nestedMemberRows` does, so every edge-bearing row it builds has an observation.
387
463
  */
@@ -395,7 +471,7 @@ function edgePlacements(harness, options) {
395
471
  continue;
396
472
  const placed = placedEdges(member, value, options);
397
473
  if (placed !== undefined) {
398
- entries.push([placementKey(hostAddress(member.kind, member.name), value.kind, value.key), placed]);
474
+ entries.push([nestedAddress(memberAddress(member), value.kind, value.key), placed]);
399
475
  }
400
476
  }
401
477
  }
@@ -415,7 +491,7 @@ function renderedLineCount(block) {
415
491
  }
416
492
  /**
417
493
  * Every composed embedded value's rendered extent — the line and character count of the
418
- * block `emit` projected for it — keyed by its {@link placementKey}, what `emit` hands
494
+ * block `emit` projected for it — keyed by its {@link nestedAddress}, what `emit` hands
419
495
  * {@link compileDeclarations} so each `nested_member` row carries the span an `extent`
420
496
  * clause budgets. Iterates exactly the values {@link edgePlacements} does, rendering each
421
497
  * through the same {@link renderMemberBlock} the body projection uses (a hook is pure, so
@@ -436,7 +512,7 @@ function renderedExtents(harness, options) {
436
512
  continue;
437
513
  const block = renderMemberBlock(member, value, options);
438
514
  entries.push([
439
- placementKey(hostAddress(member.kind, member.name), value.kind, value.key),
515
+ nestedAddress(memberAddress(member), value.kind, value.key),
440
516
  {
441
517
  lines: renderedLineCount(block),
442
518
  // Unicode scalar values, matching Rust's `chars().count()` — iterating a string
@@ -560,15 +636,16 @@ function fileSourcePath(member) {
560
636
  * The harness's registration write facts as the public {@link RegistrationFact} view —
561
637
  * the seam's own `registration` rows mapped to the nested `collectionAddress` shape the
562
638
  * `EmitResult` sibling exposes, so the two cannot disagree on what a manifest carries.
563
- * The fields-only registration members ({@link registrationRows}) and the memberless tap
564
- * hooks a telemetry verifier synthesizes ({@link tapHookRows}) fold in together, the same
565
- * union `compileDeclarations` writes into `declarations.registrations`.
639
+ * The rows are {@link mergedRegistrationRows}' — the fields-only registration members
640
+ * with the memberless tap hooks a telemetry verifier synthesizes joined into them — the
641
+ * one home `compileDeclarations` also reads for `declarations.registrations`, so a tap
642
+ * that joined an authored group did so for both faces or for neither.
566
643
  *
567
644
  * # Throws
568
645
  * If a fields-only member declares no collection address — it surfaces in no manifest.
569
646
  */
570
647
  function registrationFacts(harness) {
571
- return [...registrationRows(harness), ...tapHookRows(harness)].map((row) => ({
648
+ return mergedRegistrationRows(harness).map((row) => ({
572
649
  kind: row.kind,
573
650
  key: row.key,
574
651
  collectionAddress: { manifest: row.manifest, keyPath: row.key_path },
@@ -586,32 +663,65 @@ function settingsResidue(harness) {
586
663
  }
587
664
  /**
588
665
  * The harness's composed members by address — the table an embedded value's edge field
589
- * resolves its target against. A top-level member keys the identical way
590
- * {@link declaredAddresses} spells a member address, so an edge field and a mention name
591
- * a member the same way; a nested member keys under both of its own spellings
592
- * ({@link nestedTargets}), so an embedded edge target resolves at emit as a top-level one
593
- * does.
666
+ * resolves its target against. Every member keys by its own address ({@link memberAddress}),
667
+ * the identical way {@link declaredAddresses} spells one, so an edge field and a mention
668
+ * name a member the same way; a nested member keys under both of its own spellings — an
669
+ * embedded value through {@link nestedTargets}, a file child through its own address here
670
+ * and {@link bareFileChildTargets} — so a nested edge target resolves at emit as a
671
+ * top-level one does.
594
672
  *
595
673
  * A projected member's address is its file, so two at one address are a collision and
596
- * refuse loud. A registration member's address is its *group key* — a `hook` registers on
597
- * its event, and Claude Code admits any number of matcher groups per event — so several
598
- * legitimately share one address and the table keeps the last composed (the pre-0.0.16
599
- * reading; an edge targeting that shared address resolves ambiguously, the open fork
600
- * `(hook-member-identity)` in `.flume/plan/open-questions.md`). Refusing them broke
601
- * `emit` on every harness with two hooks on one event (0.0.16).
674
+ * refuse loud. A nested file child's address carries its host, so two hosts each carrying a
675
+ * `home` are two addresses rather than one name twice — the collision a corpus-wide
676
+ * `<kind>:<name>` keying raised for a corpus that is perfectly well-formed. A registration
677
+ * member's address is its *group key* — a `hook` registers on its event, and Claude Code
678
+ * admits any number of matcher groups per event — so several legitimately share one address
679
+ * and the table keeps the last composed (the pre-0.0.16 reading; an edge targeting that
680
+ * shared address resolves ambiguously, the open fork `(hook-member-identity)` in
681
+ * `.flume/plan/open-questions.md`). Refusing them broke `emit` on every harness with two
682
+ * hooks on one event (0.0.16).
602
683
  */
603
684
  function memberTable(harness) {
604
685
  const table = uniqueMap([
605
686
  ...harness.members
606
687
  .filter((member) => !isRegistration(member))
607
- .map((member) => [hostAddress(member.kind, member.name), member]),
688
+ .map((member) => [memberAddress(member), member]),
689
+ ...bareFileChildTargets(harness),
608
690
  ...nestedTargets(harness),
609
691
  ]);
610
692
  for (const member of harness.members.filter(isRegistration)) {
611
- table.set(hostAddress(member.kind, member.name), member);
693
+ table.set(memberAddress(member), member);
612
694
  }
613
695
  return table;
614
696
  }
697
+ /**
698
+ * Every nested **file** child under the bare `<kind>:<name>` short form as well as its own
699
+ * host-qualified address — the same second spelling {@link nestedTargets} gives an embedded
700
+ * member, so the two nested grains resolve alike.
701
+ *
702
+ * A bare key names a nested member only while a single host carries it, so a name several
703
+ * hosts spell enters under no bare key at all and an edge citing it refuses as an address
704
+ * resolving to no composed member ({@link edgeTargetFacts}) — loud, with the whole
705
+ * `<host-address>/<kind>/<key>` spelling always available to tell the carriers apart. The
706
+ * ambiguity is not refused *here*, because uniqueness is the resolver's bar and not the
707
+ * corpus's: one name two hosts carry and nothing cites still composes.
708
+ */
709
+ function bareFileChildTargets(harness) {
710
+ const carriers = new Map();
711
+ for (const member of harness.members) {
712
+ if (member.host === undefined || isRegistration(member))
713
+ continue;
714
+ const key = bareLookupKey(member.kind, member.name);
715
+ const carried = carriers.get(key);
716
+ if (carried === undefined)
717
+ carriers.set(key, [member]);
718
+ else
719
+ carried.push(member);
720
+ }
721
+ return [...carriers]
722
+ .filter(([, carried]) => carried.length === 1)
723
+ .map(([key, carried]) => [key, carried[0]]);
724
+ }
615
725
  /**
616
726
  * Every composed embedded value as member-table entries, under both of its spellings: the
617
727
  * full `<host-address>/<kind>/<key>` address, whose one carrier is the host whose body
@@ -632,7 +742,7 @@ function nestedTargets(harness) {
632
742
  if (isTextSpan(value))
633
743
  continue;
634
744
  const target = { host: member, value };
635
- qualified.push([nestedAddress(hostAddress(member.kind, member.name), value.kind, value.key), [target]]);
745
+ qualified.push([nestedAddress(memberAddress(member), value.kind, value.key), [target]]);
636
746
  const key = bareLookupKey(value.kind, value.key);
637
747
  const carriers = bare.get(key);
638
748
  if (carriers === undefined)
@@ -643,21 +753,54 @@ function nestedTargets(harness) {
643
753
  }
644
754
  return [...qualified, ...bare];
645
755
  }
756
+ /**
757
+ * Refuse a projected member whose **name** carries the `/` an address is cut at
758
+ * ({@link isOneSegment}) — the bar `kind.ts`'s `refuseSegmentedKey` already holds one grain
759
+ * down, for an embedded member's key.
760
+ *
761
+ * A member's name is its own first address segment and, at every `at` locus, the identity a
762
+ * projection path is spliced from: a file stem, or the one directory segment the kind's glob
763
+ * stars. A `/` in it therefore does two things at once — it shifts every address beneath the
764
+ * member by a segment, and it places the projection outside the glob the kind declares, so
765
+ * the file is written where no discovery walk looks. The engine refuses the same name
766
+ * (`src/drift.rs`'s `MemberNameSeparator`), and this half is the loud one: at compose time
767
+ * the author can still rename.
768
+ *
769
+ * Total over the projected set rather than inside {@link spliceName}, which a directory-unit
770
+ * member's path never reaches.
771
+ *
772
+ * # Throws
773
+ * If `name` is empty or carries `/`.
774
+ */
775
+ function refuseSegmentedName(kind, name) {
776
+ if (isOneSegment(name))
777
+ return;
778
+ throw new Error(`member \`${name}\` of kind \`${kind}\`: a member's name is one address segment — ` +
779
+ `non-empty and carrying no \`/\`, the separator its address is cut at and the one a ` +
780
+ `projection path is placed with; a name carrying it addresses another member's leaf ` +
781
+ `and places outside the kind's own glob`);
782
+ }
646
783
  /** The harness's projected members as payload members, deterministically kind-then-name ordered. */
647
784
  function orderedMembers(harness, options) {
648
785
  return [...harness.members]
649
786
  .filter(isProjected)
650
787
  .sort((a, b) => compareStrings(a.kind, b.kind) || compareStrings(a.name, b.name))
651
- .map((member) => ({
652
- kind: member.kind,
653
- name: member.name,
654
- host: member.host && hostAddress(member.host.kind, member.host.name),
655
- // The generated row carries a mutable field list; the member's is read-only,
656
- // so copy each pair into a fresh tuple — the same values, a shape the row accepts.
657
- fields: member.fields.map(([name, value]) => [name, value]),
658
- body: resolveBody(member, options),
659
- source_path: fileSourcePath(member),
660
- }));
788
+ .map((member) => {
789
+ refuseSegmentedName(member.kind, member.name);
790
+ return {
791
+ kind: member.kind,
792
+ name: member.name,
793
+ // The host's **own whole address**, never its `kind:name` alone: the engine reads
794
+ // this column to find the host's host when it composes a child's path, so a
795
+ // flattened spelling would strand every layer above the nearest one.
796
+ host: member.host && memberAddress(member.host),
797
+ // The generated row carries a mutable field list; the member's is read-only,
798
+ // so copy each pair into a fresh tuple — the same values, a shape the row accepts.
799
+ fields: member.fields.map(([name, value]) => [name, value]),
800
+ body: resolveBody(member, options),
801
+ source_path: fileSourcePath(member),
802
+ };
803
+ });
661
804
  }
662
805
  /**
663
806
  * Compile the whole face in one deterministic pass: the declaration rows (its
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * One assembly-scope fact — the root member's own declarations plus the
3
- * graph edges the harness binds: a `fact` discriminator (`mode`, `edge`)
4
- * plus the columns that fact carries. Absent columns are omitted from the
5
- * lock, so each row round-trips to exactly what its producer wrote.
3
+ * graph edges the harness binds: a `fact` discriminator (`mode`, `contract`,
4
+ * `edge`) plus the columns that fact carries. Absent columns are omitted from
5
+ * the lock, so each row round-trips to exactly what its producer wrote.
6
6
  */
7
7
  export type AssemblyFactRow = {
8
8
  /**
9
- * The fact discriminator: `mode` or `edge`.
9
+ * The fact discriminator: `mode`, `contract` or `edge`.
10
10
  */
11
11
  fact: string;
12
12
  /**
@@ -15,7 +15,9 @@ export type AssemblyFactRow = {
15
15
  */
16
16
  value?: string;
17
17
  /**
18
- * An `edge` fact's source kind.
18
+ * An `edge` fact's source kind, or the kind a `contract` fact marks a declared
19
+ * contract for — absent on a `contract` fact, which makes it the root's, the same
20
+ * kind-absent-means-root discriminator a top-level clause row uses.
19
21
  */
20
22
  from?: string;
21
23
  /**
@@ -43,8 +43,8 @@ export type Declarations = {
43
43
  */
44
44
  requirements: Array<RequirementRow>;
45
45
  /**
46
- * The assembly-scope facts — the root member's declared enforcement `mode`,
47
- * edges.
46
+ * The assembly-scope facts — the root member's declared enforcement `mode`, the
47
+ * declared-contract markers, edges.
48
48
  */
49
49
  assembly: Array<AssemblyFactRow>;
50
50
  /**