@dtmd/temper 0.0.24 → 0.0.26

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.
Files changed (70) hide show
  1. package/README.md +14 -12
  2. package/dist/src/assembly.d.ts +45 -11
  3. package/dist/src/assembly.js +116 -8
  4. package/dist/src/builtins.d.ts +436 -103
  5. package/dist/src/builtins.js +772 -167
  6. package/dist/src/claude-code.d.ts +6 -3
  7. package/dist/src/claude-code.js +2 -2
  8. package/dist/src/contract.d.ts +153 -44
  9. package/dist/src/contract.js +123 -34
  10. package/dist/src/counsel.d.ts +11 -0
  11. package/dist/src/counsel.js +68 -0
  12. package/dist/src/declarations.d.ts +108 -2
  13. package/dist/src/declarations.js +606 -100
  14. package/dist/src/dial.d.ts +3 -3
  15. package/dist/src/dial.js +21 -5
  16. package/dist/src/emit.d.ts +12 -14
  17. package/dist/src/emit.js +123 -47
  18. package/dist/src/generated/AbsenceGateRow.d.ts +16 -0
  19. package/dist/src/generated/AbsenceGateRow.js +2 -0
  20. package/dist/src/generated/AreaMode.d.ts +5 -0
  21. package/dist/src/generated/AreaMode.js +2 -0
  22. package/dist/src/generated/AreaRow.d.ts +20 -0
  23. package/dist/src/generated/AreaRow.js +1 -0
  24. package/dist/src/generated/AssemblyFactRow.d.ts +17 -4
  25. package/dist/src/generated/BoundRow.d.ts +9 -4
  26. package/dist/src/generated/CedeRow.d.ts +14 -0
  27. package/dist/src/generated/CedeRow.js +2 -0
  28. package/dist/src/generated/CharsetRow.d.ts +14 -3
  29. package/dist/src/generated/ClauseRow.d.ts +23 -21
  30. package/dist/src/generated/CollectionAddressRow.d.ts +1 -1
  31. package/dist/src/generated/Declarations.d.ts +24 -9
  32. package/dist/src/generated/FeatureValue.d.ts +3 -3
  33. package/dist/src/generated/Features.d.ts +3 -3
  34. package/dist/src/generated/KindFactRow.d.ts +41 -8
  35. package/dist/src/generated/Payload.d.ts +3 -5
  36. package/dist/src/generated/PayloadMember.d.ts +7 -0
  37. package/dist/src/generated/RunsRow.d.ts +17 -0
  38. package/dist/src/generated/RunsRow.js +2 -0
  39. package/dist/src/generated/Section.d.ts +2 -2
  40. package/dist/src/generated/SectionContainsRow.d.ts +1 -1
  41. package/dist/src/generated/TypecheckRow.d.ts +20 -0
  42. package/dist/src/generated/TypecheckRow.js +2 -0
  43. package/dist/src/generated/Verifier.d.ts +8 -2
  44. package/dist/src/generated/index.d.ts +6 -0
  45. package/dist/src/index.d.ts +20 -15
  46. package/dist/src/index.js +10 -9
  47. package/dist/src/kind.d.ts +382 -52
  48. package/dist/src/kind.js +461 -49
  49. package/dist/src/lockfile.d.ts +39 -0
  50. package/dist/src/lockfile.js +265 -0
  51. package/dist/src/member-address.d.ts +15 -3
  52. package/dist/src/member-address.js +23 -6
  53. package/dist/src/needs.d.ts +25 -15
  54. package/dist/src/needs.js +10 -11
  55. package/dist/src/patterns.d.ts +112 -0
  56. package/dist/src/patterns.js +90 -0
  57. package/dist/src/pipe.d.ts +16 -0
  58. package/dist/src/pipe.js +39 -0
  59. package/dist/src/playbook.d.ts +203 -0
  60. package/dist/src/playbook.js +239 -0
  61. package/dist/src/prose.d.ts +69 -12
  62. package/dist/src/prose.js +125 -13
  63. package/dist/src/reference.d.ts +70 -0
  64. package/dist/src/reference.js +368 -0
  65. package/package.json +13 -4
  66. package/schemas/agent.json +23 -0
  67. package/schemas/command.json +5 -0
  68. package/schemas/output-style.json +4 -0
  69. package/schemas/rule.json +33 -0
  70. package/schemas/skill.json +63 -0
@@ -10,10 +10,14 @@
10
10
  */
11
11
  import { fileURLToPath } from "node:url";
12
12
  import { isDeepStrictEqual } from "node:util";
13
- import { manifestOf } from "./kind.js";
14
- import { isTextSpan, resolveEmbeddedLeaves } from "./prose.js";
15
- import { GATE_BINARY_KEY, HOOK_HANDLER_KEY, HOOK_MATCHER_KEY, SETTINGS_MANIFEST, TELEMETRY_EVENT_HOOKS, gateHookBinary, hook, hookCollectionKey, tapHookRegistration, } from "./builtins.js";
16
- import { leafAddress, memberAddress, nestedAddress } from "./member-address.js";
13
+ import { absenceGatesOf, baseOf, collectionAddressOf, edgeTargetNames, manifestOf, registrationOf, templatesOf } from "./kind.js";
14
+ import { isTextSpan, resolveEmbeddedLeaves, span } from "./prose.js";
15
+ import * as shippedBuiltins from "./builtins.js";
16
+ import { dial } from "./dial.js";
17
+ import { COUNSEL_RULE_NAME, GUIDANCE_RULE_PREFIX, SDK_COUNSEL } from "./counsel.js";
18
+ import { GATE_TOOL_KEY, HOOK_HANDLER_KEY, HOOK_MATCHER_KEY, ROOT_HOSTED_KINDS, RUNS_FIELD, SETTINGS_MANIFEST, TELEMETRY_EVENT_HOOKS, gateHookTool, hook, hookCollectionKey, requirement, requirementOf, requirementSource, rule, settings, tapHookRegistration, tool, } from "./builtins.js";
19
+ import { ROOT_ADDRESS, leafAddress, memberAddress, nestedAddress } from "./member-address.js";
20
+ import { playbookArea } from "./playbook.js";
17
21
  /**
18
22
  * Compile one `Clause` into its lock row: the shared `key`/`field`/`severity`/
19
23
  * `guidance`/`cite` columns — the clause's four channels surviving erasure
@@ -21,8 +25,8 @@ import { leafAddress, memberAddress, nestedAddress } from "./member-address.js";
21
25
  * predicate carries them, the `count`/`target`/`degree` argument columns a
22
26
  * requirement's own set-/edge-scope demand needs, and the
23
27
  * `bound`/`charset`/`keys`/`values` argument columns a kind's own node-scope
24
- * floor clause needs (`min_len`/`max_len`/`extent`'s bound, `extent`'s unit,
25
- * `allowed_chars`'s charset, `forbidden_keys`'s keys, `deny`'s values) — so
28
+ * floor clause needs (`min-len`/`max-len`/`extent`'s bound, `extent`'s unit,
29
+ * `allowed-chars`'s charset, `forbidden-keys`'s keys, `deny`'s values) — so
26
30
  * the lock encodes the floor losslessly, not identity+severity alone. `kind`
27
31
  * is supplied only for a kind's own `expect` clause; a requirement's nested
28
32
  * clause carries none.
@@ -77,10 +81,17 @@ function clauseRow(clause, kind) {
77
81
  // The by-incidence field set rides its own shared column, not the direction-only
78
82
  // `degree` bound — the slot `reached-from`'s via set joins it. Copied into a
79
83
  // fresh array: the predicate's set is read-only, the row's column is not.
80
- fields: (predicate.key === "degree" || predicate.key === "reached-from") && predicate.fields
84
+ fields: (predicate.key === "degree" ||
85
+ predicate.key === "reached-from" ||
86
+ predicate.key === "listing") &&
87
+ predicate.fields
81
88
  ? [...predicate.fields]
82
89
  : undefined,
83
- gate: predicate.key === "mention-reachable" ? predicate.gate : undefined,
90
+ gate: predicate.key === "mention-reachable" ||
91
+ predicate.key === "trigger-agrees" ||
92
+ predicate.key === "listing"
93
+ ? predicate.gate
94
+ : undefined,
84
95
  value_type: predicate.key === "type" && predicate.value_type ? [...predicate.value_type] : undefined,
85
96
  shape: predicate.key === "shape" ? predicate.shape : undefined,
86
97
  bound: nodeScopeBoundArgs(predicate),
@@ -88,23 +99,27 @@ function clauseRow(clause, kind) {
88
99
  // The generated rows carry mutable columns; the predicate's `value_type`/
89
100
  // `charset`/`keys`/`values` are read-only, so copy each into a fresh
90
101
  // array/object — the same bytes, a shape the row will accept.
91
- charset: predicate.key === "allowed_chars" && predicate.charset !== undefined
102
+ charset: predicate.key === "allowed-chars" && predicate.charset !== undefined
92
103
  ? {
104
+ ...predicate.charset,
93
105
  ranges: predicate.charset.ranges ? [...predicate.charset.ranges] : undefined,
94
- chars: predicate.charset.chars,
95
106
  }
96
107
  : undefined,
97
- keys: predicate.key === "forbidden_keys" && predicate.keys ? [...predicate.keys] : undefined,
98
- values: (predicate.key === "deny" || predicate.key === "enum") && predicate.values
108
+ keys: predicate.key === "forbidden-keys" && predicate.keys ? [...predicate.keys] : undefined,
109
+ values: (predicate.key === "deny" ||
110
+ predicate.key === "enum" ||
111
+ predicate.key === "listing" ||
112
+ predicate.key === "loads") &&
113
+ predicate.values
99
114
  ? [...predicate.values]
100
115
  : undefined,
101
116
  range: predicate.key === "range" && predicate.range !== undefined
102
117
  ? { min: predicate.range.min, max: predicate.range.max }
103
118
  : undefined,
104
- section: predicate.key === "section_contains" && predicate.section !== undefined
119
+ section: predicate.key === "section-contains" && predicate.section !== undefined
105
120
  ? { heading: predicate.section.heading, marker: predicate.section.marker }
106
121
  : undefined,
107
- sections: predicate.key === "require_sections" && predicate.sections
122
+ sections: predicate.key === "require-sections" && predicate.sections
108
123
  ? [...predicate.sections]
109
124
  : undefined,
110
125
  };
@@ -114,7 +129,7 @@ function clauseRow(clause, kind) {
114
129
  * predicates that name a *section*, a field *set*, or a *requirement* rather than a
115
130
  * field — an identity synthesized from the arguments the row already carries.
116
131
  *
117
- * `section_contains`, `require_sections`, `degree` and `reached-from` set no `field`,
132
+ * `section-contains`, `require-sections`, `degree` and `reached-from` set no `field`,
118
133
  * and the column is what emit stamps a clause's label from (`stamp_clause_label`,
119
134
  * `src/drift.rs`), so reading `Predicate.field` folds every clause of one of those
120
135
  * predicates on one kind into one label — two rows wearing one label, which
@@ -123,12 +138,12 @@ function clauseRow(clause, kind) {
123
138
  * `section`/`sections`/`fields`/`target` columns and never from this one, so nothing
124
139
  * round-trips through the synthesized text.
125
140
  */
126
- function clauseField(predicate) {
127
- if (predicate.key === "section_contains") {
141
+ export function clauseField(predicate) {
142
+ if (predicate.key === "section-contains") {
128
143
  const { section } = predicate;
129
144
  return section === undefined ? undefined : `${section.heading}.${section.marker}`;
130
145
  }
131
- if (predicate.key === "require_sections") {
146
+ if (predicate.key === "require-sections") {
132
147
  // Joined with `+` rather than the label's own `.`, so the segment reads as the
133
148
  // set it is and two different heading lists cannot fold to one label.
134
149
  return predicate.sections?.join("+");
@@ -142,10 +157,15 @@ function clauseField(predicate) {
142
157
  // are a redundancy the author collapses, never a distinction an address must hold.
143
158
  return predicate.fields === undefined ? undefined : [...predicate.fields].sort().join("+");
144
159
  }
160
+ if (predicate.key === "listing") {
161
+ // A `listing` names no field of its own: the fields it lists are its identity, kept
162
+ // in listed order since the entry joins them in that order.
163
+ return predicate.fields?.join("+");
164
+ }
145
165
  if (predicate.key === "reached-from") {
146
166
  // A `reached-from` clause names no field either: its identity is the pair it walks.
147
167
  // The roots requirement leads, and a declared via set follows after a `.` — the
148
- // two-argument `section_contains` precedent — sorted and `+`-joined by `degree`'s
168
+ // two-argument `section-contains` precedent — sorted and `+`-joined by `degree`'s
149
169
  // rule directly above. So two closures rooted at one requirement over different
150
170
  // arcs land two addresses instead of folding into one, and two spellings of one via
151
171
  // set land one. An unfiltered closure adds no second segment: the roots are its
@@ -160,16 +180,23 @@ function clauseField(predicate) {
160
180
  }
161
181
  return predicate.field;
162
182
  }
163
- /** `min_len`/`max_len`/`extent`'s scalar bound off their shared `min`/`max`
164
- * args keys — `undefined` for every other predicate, and for these three when
165
- * neither endpoint is present. */
183
+ /** `min-len`/`max-len`/`extent`/`listing`'s scalar bound off their shared `min`/`max`
184
+ * args keys, plus `listing`'s per-entry `entry` cap — `undefined` for every other
185
+ * predicate, and for these four when no endpoint is present. */
166
186
  function nodeScopeBoundArgs(predicate) {
167
- if (predicate.key !== "min_len" && predicate.key !== "max_len" && predicate.key !== "extent") {
187
+ if (predicate.key !== "min-len" &&
188
+ predicate.key !== "max-len" &&
189
+ predicate.key !== "extent" &&
190
+ predicate.key !== "listing") {
168
191
  return undefined;
169
192
  }
170
193
  const min = predicate.args?.min;
171
194
  const max = predicate.args?.max;
172
- return min === undefined && max === undefined ? undefined : { min, max };
195
+ const entry = predicate.args?.entry;
196
+ if (min === undefined && max === undefined && entry === undefined)
197
+ return undefined;
198
+ // `entry` is `listing`'s alone, so the other three rows keep their two-key bound.
199
+ return entry === undefined ? { min, max } : { min, max, entry };
173
200
  }
174
201
  /** One `degree` direction's `{min, max}` off its flat `<dir>_min`/`<dir>_max` args
175
202
  * keys — `undefined` when neither is present (that direction is unconstrained). */
@@ -179,15 +206,17 @@ function edgeBoundArgs(args, direction) {
179
206
  return min === undefined && max === undefined ? undefined : { min, max };
180
207
  }
181
208
  /**
182
- * The lock label for a kind's declared unit shape: `file`/`directory`/`starred-segment`
183
- * verbatim, or `named-field(<identityField>)` for the field-sourced mode — the same
209
+ * The lock label for a kind's declared unit shape: `file`/`directory`/`starred-segment`/`path`
210
+ * verbatim, or `named-field(<identityField>)` / `named-field-or-file(<identityField>)` for
211
+ * the field-sourced modes — the same
184
212
  * `<name>(<field>)` call syntax [`registrationLabel`] uses, so the id source round-trips
185
213
  * through the row rather than degrading to a bare, unreconstructable `"named-field"`.
186
214
  */
187
215
  function unitShapeLabel(facts) {
188
- if (facts.unitShape !== "named-field")
216
+ if (facts.unitShape !== "named-field" && facts.unitShape !== "named-field-or-file") {
189
217
  return facts.unitShape;
190
- return `named-field(${facts.identityField})`;
218
+ }
219
+ return `${facts.unitShape}(${facts.identityField})`;
191
220
  }
192
221
  /** The lock label for one declared registration channel. */
193
222
  function registrationLabel(registration) {
@@ -200,6 +229,10 @@ function registrationLabel(registration) {
200
229
  return `description-trigger(${registration.field})`;
201
230
  case "paths-match":
202
231
  return `paths-match(${registration.field})`;
232
+ case "on-read-beneath":
233
+ return "on-read-beneath";
234
+ case "paths-listing":
235
+ return `paths-listing(${registration.field})`;
203
236
  case "event":
204
237
  return `event(${registration.field})`;
205
238
  case "connection":
@@ -208,6 +241,8 @@ function registrationLabel(registration) {
208
241
  return `enablement(${registration.field})`;
209
242
  case "registry":
210
243
  return "registry";
244
+ case "selected":
245
+ return `selected(${registration.field})`;
211
246
  }
212
247
  }
213
248
  /** The lock labels for a kind's declared registration **set**, in declaration order —
@@ -289,12 +324,10 @@ function contentRow(content) {
289
324
  * `undefined` for a file-locus kind, so its row omits the column and stays byte-identical.
290
325
  */
291
326
  function collectionAddressRow(facts) {
292
- if (facts.collectionAddress === undefined)
327
+ const address = collectionAddressOf(facts);
328
+ if (address === undefined)
293
329
  return undefined;
294
- return {
295
- key_path: facts.collectionAddress.keyPath,
296
- entry_shape: facts.collectionAddress.entryShape,
297
- };
330
+ return { key_path: address.keyPath, entry_shape: address.entryShape };
298
331
  }
299
332
  /**
300
333
  * Lower a kind's exhaustive leaf-set witness into the row's `leaves` column: the
@@ -307,7 +340,7 @@ function leafSetRow(leaves) {
307
340
  return leaves === undefined ? undefined : Object.keys(leaves);
308
341
  }
309
342
  /**
310
- * One kind's fact row — an `at` locus supplies `governs_root`/`governs_glob` and any
343
+ * One kind's fact row — an `at` locus supplies `locus_root`/`locus_glob` and any
311
344
  * other locus neither (a nested-file kind's path composes from its host's unit and the
312
345
  * host template's pattern; an embedded kind owns no unit at all — both govern no glob).
313
346
  * A file locus's `commitment` class and `exclude` paths ride the same spelling, absent for
@@ -321,19 +354,25 @@ function leafSetRow(leaves) {
321
354
  * actually take a row.
322
355
  */
323
356
  function kindFactRow(facts, admissions) {
324
- const governs = facts.locus.kind === "at" ? facts.locus : undefined;
357
+ const at = facts.locus.kind === "at" ? facts.locus : undefined;
325
358
  return {
326
359
  name: facts.name,
327
360
  provider: facts.provider,
328
- governs_root: governs?.root,
329
- governs_glob: governs?.glob,
330
- commitment: governs?.commitment,
361
+ base: facts.base,
362
+ locus_root: at?.root,
363
+ // Always the list: the lock column is one or more templates.
364
+ locus_glob: at === undefined ? undefined : [...templatesOf(at)],
365
+ commitment: at?.commitment,
331
366
  // Spread rather than an `undefined` column: a row excluding nothing carries no key.
332
- ...(governs?.exclude?.length ? { exclude: [...governs.exclude] } : {}),
367
+ ...(at?.exclude?.length ? { exclude: [...at.exclude] } : {}),
368
+ ...(at !== undefined && absenceGatesOf(at).length
369
+ ? { absence_gate: absenceGatesOf(at).map((gate) => ({ template: gate.glob, absent: [...gate.absent] })) }
370
+ : {}),
371
+ ...("leniency" in facts && facts.leniency?.length ? { leniency: [...facts.leniency] } : {}),
333
372
  format: facts.format,
334
373
  unit_shape: unitShapeLabel(facts),
335
374
  // An embedded or nested-file kind declares no set — its locus already states it empty.
336
- registration: registrationLabels(facts.registration ?? []),
375
+ registration: registrationLabels(registrationOf(facts)),
337
376
  templates: templatesFor(facts, admissions),
338
377
  content: contentRow(facts.content),
339
378
  shape: facts.shape,
@@ -352,18 +391,24 @@ function locusLabel(facts) {
352
391
  const { locus } = facts;
353
392
  if (locus.kind !== "at")
354
393
  return `the \`${locus.kind}\` locus`;
355
- return `\`${locus.root === "." ? locus.glob : `${locus.root}/${locus.glob}`}\``;
394
+ return templatesOf(locus)
395
+ .map((glob) => `\`${locus.root === "." ? glob : `${locus.root}/${glob}`}\``)
396
+ .join(" and ");
356
397
  }
357
398
  /**
358
- * A kind's facts with the three faces a relocation may diverge from its base on erased:
359
- * the `relocates` marker, the appended `edgeFields`, and an `at` locus's moved root and
360
- * glob (`kind.ts`'s `KindRelocation`). Two values agreeing here are one kind up to a
399
+ * A kind's facts with the faces a relocation may diverge from its base on erased: the
400
+ * `relocates` marker, the appended `edgeFields`, an `at` locus's moved root and glob, and
401
+ * the replaced counsel (`kind.ts`'s `KindRelocation`). Two values agreeing here are one kind up to a
361
402
  * relocation delta; the delta's own faces are checked on their own terms.
362
403
  */
363
404
  function relocationInvariants(facts) {
364
405
  const bare = { ...facts };
365
406
  delete bare.relocates;
366
407
  delete bare.edgeFields;
408
+ delete bare.guidance;
409
+ delete bare.fieldGuidance;
410
+ delete bare.cite;
411
+ delete bare.mode;
367
412
  if (facts.locus.kind === "at")
368
413
  bare.locus = { ...facts.locus, root: "", glob: "" };
369
414
  return bare;
@@ -371,7 +416,8 @@ function relocationInvariants(facts) {
371
416
  /**
372
417
  * Whether `relocation` was derived from `base` — the provenance the relocation-wins rule
373
418
  * rests on. The marker names the base, `relocate` only ever *appends* edge fields (so the
374
- * base's are a prefix of the relocation's), and every other fact rides through unchanged:
419
+ * base's are a prefix of the relocation's), and every other fact but the counsel a
420
+ * relocation replaces by design rides through unchanged:
375
421
  * the base's facts are a subset by construction, which is exactly what makes keeping the
376
422
  * relocation lossless. Checked rather than assumed, because the marker carries a name and
377
423
  * a name is what is in dispute — a value bearing it whose facts are not the other's
@@ -436,16 +482,22 @@ function resolveNameCollision(held, arriving) {
436
482
  * column rather than a row of its own, so those channels are the only way one is in play
437
483
  * at all — and its declared edge fields are still owed their assembly facts.
438
484
  *
439
- * Only *embedded* children are drawn in. A path-carrying template is the nested-file
440
- * layer, whose child owns a unit and reaches the lock through `expect` like any other
441
- * unit kind; pulling one in here would forge it a kind-fact row it never declared.
485
+ * Beside them, a template's **subkind** child is drawn in: an extended host names it in its
486
+ * base's place, so the host's own row is what puts it in play. Any other path-carrying
487
+ * template is the nested-file layer, whose child owns a unit and reaches the lock through
488
+ * `expect` like any other unit kind; pulling one in here would forge it a kind-fact row
489
+ * it never declared.
490
+ *
491
+ * A synthesized tap hook ({@link tapHookRows}) puts the `hook` kind in play as an authored
492
+ * hook member would: its row lands in `registrations` under `hook`, so the kind is owed
493
+ * the fact row the engine resolves that row's kind against.
442
494
  *
443
495
  * Two facts values arriving under one name are decided by {@link resolveNameCollision},
444
496
  * never by arrival order: the deduped facts are what `assemblyFactRows` derives every
445
497
  * `edge` row from, so first-wins would drop a relocation's added edge on the floor
446
498
  * whenever the base happened to be named first.
447
499
  */
448
- function kindsInPlay(harness) {
500
+ export function kindsInPlay(harness) {
449
501
  const byName = new Map();
450
502
  const pending = [];
451
503
  const admit = (facts) => {
@@ -465,10 +517,24 @@ function kindsInPlay(harness) {
465
517
  for (const { admits } of harness.admit)
466
518
  for (const child of admits)
467
519
  admit(child.facts);
520
+ // A synthesized tap is a hook registration row, so it brings the hook kind with it:
521
+ // a program whose only hook content is a tap still owes `hook` its kind-fact row.
522
+ if (tapHookRows(harness).length > 0)
523
+ admit(hook.facts);
524
+ // A requirement subkind's members are the root's nested members, never roster members,
525
+ // so the requirement map is what puts the subkind — and each subkind up its chain to the
526
+ // shipped `requirement` — in play: its row's `base` is how the engine binds its members
527
+ // where a selection of `requirement` reaches.
528
+ for (const [, declared] of requirementEntries(harness)) {
529
+ const source = requirementSource(declared)?.facts;
530
+ for (let facts = source; facts !== undefined && facts.base !== undefined; facts = baseOf(facts))
531
+ admit(facts);
532
+ }
468
533
  for (let facts = pending.pop(); facts !== undefined; facts = pending.pop()) {
469
534
  for (const template of facts.templates ?? []) {
470
- if (template.kind.facts.locus.kind === "embedded")
471
- admit(template.kind.facts);
535
+ const child = template.kind.facts;
536
+ if (child.locus.kind === "embedded" || child.base !== undefined)
537
+ admit(child);
472
538
  }
473
539
  }
474
540
  return [...byName.values()].sort((a, b) => compareStrings(a.name, b.name));
@@ -482,7 +548,7 @@ function atLocusKindsInPlay(allKinds) {
482
548
  * unconditionally (a nested-file kind owns a file the engine must place, and places it
483
549
  * off its row, though it governs no glob to be discovered at), plus an embedded kind that
484
550
  * has something of its own for a row to carry: `guidance` or `cite` (decision 0045), or a
485
- * declared leaf set (decision 0053). The leaf set is on this list for the reason the
551
+ * declared leaf set (decision 0053), or a `base` — a subkind the engine binds off its row. The leaf set is on this list for the reason the
486
552
  * column exists — it teaches what a child carries *before* the surface holds a member of
487
553
  * it, and an embedded kind taking no row never reaches the lock to teach it. An embedded
488
554
  * kind declaring none of the three has nothing for the row to carry, and its members
@@ -491,31 +557,272 @@ function atLocusKindsInPlay(allKinds) {
491
557
  */
492
558
  function kindFactKindsInPlay(allKinds) {
493
559
  return allKinds.filter((facts) => facts.locus.kind !== "embedded" ||
560
+ facts.base !== undefined ||
494
561
  facts.guidance !== undefined ||
495
562
  facts.cite !== undefined ||
496
563
  facts.leaves !== undefined);
497
564
  }
498
565
  /**
499
- * The requirement rows — assembly `require` and every member's `requires`, one namespace.
500
- * An unset `required` lowers the corpus's shipped default — "this must be filled": at
501
- * least one satisfier, at error — so only an explicit `required: false` is advisory.
566
+ * Every kind temper ships, by facts identity — what a program reaches by import alone.
567
+ * Read off the provider module's exports rather than listed, so a built-in added there
568
+ * can never project its shipped counsel by being forgotten here.
502
569
  */
503
- function requirementRows(harness) {
504
- const entries = [];
505
- for (const [name, requirement] of Object.entries(harness.require)) {
506
- entries.push([name, requirement]);
570
+ const SHIPPED_KINDS = new Set([...Object.values(shippedBuiltins), dial].flatMap((value) => typeof value === "function" && "facts" in value ? [value.facts] : []));
571
+ const COUNSEL_RULE_PATHS = ".temper/**";
572
+ /** The synthesized guidance rules, so a harness already carrying them is not re-synthesized. */
573
+ const SYNTHESIZED_RULES = new WeakSet();
574
+ /**
575
+ * The repository-relative file globs a kind's members occupy — the `paths` a rule scoped
576
+ * to them lists. An `at` kind is its own root and glob (an `exclude` is not expressible
577
+ * in `paths`, so the scope over-reaches it, which advisory counsel tolerates); a nested
578
+ * file kind sits at each templating host's unit joined with the template's pattern; an
579
+ * embedded kind owns no file and takes the loci of every host that templates or admits
580
+ * it, so its counsel is stated once over all of them rather than per host.
581
+ */
582
+ function locusGlobs(facts, kinds, admissions, seen = new Set()) {
583
+ const locus = facts.locus;
584
+ if (locus.kind === "at") {
585
+ const root = locus.root;
586
+ return templatesOf(locus).map((glob) => [root, glob].filter((part) => part !== "" && part !== ".").join("/"));
587
+ }
588
+ if (seen.has(facts.name))
589
+ return [];
590
+ const visiting = new Set([...seen, facts.name]);
591
+ const globs = new Set();
592
+ for (const host of kinds) {
593
+ const layers = (host.templates ?? []).filter((template) => template.kind.key === facts.name);
594
+ if (locus.kind === "nested-file") {
595
+ for (const layer of layers) {
596
+ if (layer.path === undefined || host.unitShape !== "directory")
597
+ continue;
598
+ for (const hostGlob of locusGlobs(host, kinds, admissions, visiting)) {
599
+ const slash = hostGlob.lastIndexOf("/");
600
+ if (slash >= 0)
601
+ globs.add(`${hostGlob.slice(0, slash)}/${layer.path}`);
602
+ }
603
+ }
604
+ }
605
+ else if (layers.some((layer) => layer.path === undefined) ||
606
+ admissions.get(host.name)?.has(facts.name) === true) {
607
+ for (const hostGlob of locusGlobs(host, kinds, admissions, visiting))
608
+ globs.add(hostGlob);
609
+ }
507
610
  }
611
+ return [...globs].sort(compareStrings);
612
+ }
613
+ /** A list item whose text may span lines — continuation lines indent under the bullet. */
614
+ function bullet(head, text) {
615
+ return `- ${head}: ${text.trim().split("\n").join("\n ")}`;
616
+ }
617
+ /** The kind names an edge field's `to` set lists, for a line that states where it points. */
618
+ export function targetList(to) {
619
+ return to.map((target) => `\`${target}\``).join(", ");
620
+ }
621
+ /** A kind's counsel for one field, when it declares any that is not blank. */
622
+ function fieldCounsel(owner, field) {
623
+ const counsel = owner.fieldGuidance?.[field];
624
+ return counsel === undefined || counsel.trim() === "" ? undefined : counsel;
625
+ }
626
+ /**
627
+ * The edges at a kind's two ends, with their intent: `outbound` its own edge fields in
628
+ * declared order, `inbound` every kind-in-play's edge field whose `to` set names it, in
629
+ * `kinds` order. The one assembly of edge intent the guidance rules and the reference's
630
+ * kind topics both state, so a relationship's intent reads the same at every surface.
631
+ */
632
+ export function kindEdges(facts, kinds) {
633
+ const of = (source, edge) => ({
634
+ from: source.name,
635
+ field: edge.field,
636
+ to: edgeTargetNames(edge),
637
+ intent: fieldCounsel(source, edge.field),
638
+ shipped: SHIPPED_KINDS.has(source),
639
+ });
640
+ return {
641
+ outbound: (facts.edgeFields ?? []).map((edge) => of(facts, edge)),
642
+ inbound: kinds.flatMap((source) => (source.edgeFields ?? []).filter((edge) => edgeTargetNames(edge).includes(facts.name)).map((edge) => of(source, edge))),
643
+ };
644
+ }
645
+ /**
646
+ * The repository-relative file globs a kind's members occupy over `harness` — what a
647
+ * guidance rule's `paths` lists and a kind topic names as its locus.
648
+ */
649
+ export function kindLocusGlobs(facts, harness) {
650
+ return locusGlobs(facts, kindsInPlay(harness), admissionsByHost(harness));
651
+ }
652
+ /**
653
+ * Every declared requirement — assembly `require` ∪ each member's `requires`, the
654
+ * namespace {@link requirementRows} lowers — with the members claiming to fill it, name
655
+ * sorted, satisfiers in address order.
656
+ */
657
+ export function contractedRequirements(harness) {
658
+ const entries = requirementEntries(harness);
659
+ const satisfiers = new Map();
508
660
  for (const member of harness.members) {
509
- for (const [name, requirement] of Object.entries(member.requires)) {
510
- entries.push([name, requirement]);
661
+ for (const name of member.satisfies) {
662
+ const list = satisfiers.get(name) ?? [];
663
+ list.push({ kind: member.kind, address: memberAddress(member) });
664
+ satisfiers.set(name, list);
665
+ }
666
+ }
667
+ return [...uniqueMap(entries).entries()]
668
+ .sort(([a], [b]) => compareStrings(a, b))
669
+ .map(([name, requirement]) => ({
670
+ name,
671
+ kind: requirement.kind?.key,
672
+ prose: requirement.prose,
673
+ verifier: requirement.verifier,
674
+ satisfiers: (satisfiers.get(name) ?? []).sort((a, b) => compareStrings(a.address, b.address)),
675
+ }));
676
+ }
677
+ /**
678
+ * The body a kind's guidance rule carries — the kind's own counsel; its counselled
679
+ * non-edge fields under `Fields`, in authored order; each counselled edge's intent
680
+ * ({@link kindEdges}) under `Edges`, outbound ones (the kind's own, in declared order)
681
+ * before inbound ones (another kind's field targeting this one), so an edge's intent
682
+ * reads at both its ends; and under
683
+ * `Requirements` every requirement this kind's members satisfy or that declares this
684
+ * kind, with its prose and satisfiers — what is already contracted, before an agent adds
685
+ * to the set. A shipped kind contributes none of its shipped counsel (`shipped`): its
686
+ * rule carries only the program's contracts. A body with nothing in it is none, and
687
+ * projects no rule.
688
+ */
689
+ function guidanceBody(facts, kinds, requirements) {
690
+ const shipped = SHIPPED_KINDS.has(facts);
691
+ const edges = kindEdges(facts, kinds);
692
+ const ownEdges = new Set(edges.outbound.map((edge) => edge.field));
693
+ const own = shipped ? "" : (facts.guidance?.trim() ?? "");
694
+ const fields = [];
695
+ for (const field of shipped ? [] : Object.keys(facts.fieldGuidance ?? {})) {
696
+ const counsel = fieldCounsel(facts, field);
697
+ if (counsel !== undefined && !ownEdges.has(field))
698
+ fields.push(bullet(`\`${field}\``, counsel));
699
+ }
700
+ const projected = (edge) => !edge.shipped && edge.intent !== undefined;
701
+ const outbound = edges.outbound
702
+ .filter(projected)
703
+ .map((edge) => bullet(`\`${edge.field}\` → ${targetList(edge.to)}`, edge.intent));
704
+ const inbound = edges.inbound
705
+ .filter(projected)
706
+ .map((edge) => bullet(`\`${edge.from}\`.\`${edge.field}\` → here`, edge.intent));
707
+ const contracted = requirements.flatMap((requirement) => {
708
+ const mine = requirement.kind === facts.name || requirement.satisfiers.some((s) => s.kind === facts.name);
709
+ if (!mine)
710
+ return [];
711
+ const declared = requirement.kind === undefined ? "" : ` (kind \`${requirement.kind}\`)`;
712
+ const filled = requirement.satisfiers.length === 0
713
+ ? "No member satisfies it yet."
714
+ : `Satisfied by ${requirement.satisfiers.map((s) => `\`${s.address}\``).join(", ")}.`;
715
+ return [bullet(`\`${requirement.name}\`${declared}`, `${requirement.prose.trim()}\n${filled}`)];
716
+ });
717
+ const sections = [
718
+ own,
719
+ fields.length === 0 ? "" : `## Fields\n\n${fields.join("\n")}`,
720
+ outbound.length + inbound.length === 0 ? "" : `## Edges\n\n${[...outbound, ...inbound].join("\n")}`,
721
+ contracted.length === 0 ? "" : `## Requirements\n\n${contracted.join("\n")}`,
722
+ ].filter((section) => section !== "");
723
+ if (sections.length === 0)
724
+ return undefined;
725
+ // A body of the kind's own counsel alone keeps it exactly as authored.
726
+ if (sections.length === 1 && own !== "")
727
+ return facts.guidance;
728
+ return sections.join("\n\n");
729
+ }
730
+ /**
731
+ * The {@link SDK_COUNSEL} rule over the program directory, always, then one `rule`
732
+ * member per **guided corpus kind**: a kind in play whose {@link guidanceBody} is
733
+ * non-empty — the program's own counsel, edge intent and contracts over it. A built-in
734
+ * the program only imports projects none of its shipped counsel (every harness would
735
+ * otherwise get rules it never asked for), so it takes a rule only when the program
736
+ * contracts over it. A relocated built-in is the program's own:
737
+ * `relocate` replaces the base's counsel with the relocation's, so it projects exactly what
738
+ * its relocation declares, and nothing when it declares none. Its `paths` are the kind's
739
+ * {@link locusGlobs}, its body the counsel, so the runtime hands the counsel to an agent
740
+ * the first time a session touches a member's document. A kind whose locus resolves to no
741
+ * file (an embedded kind nothing hosts) has nowhere to scope a rule and projects none.
742
+ *
743
+ * Synthesized the way telemetry synthesizes tap hooks: memberless in the program, an
744
+ * ordinary member at the seam. It takes the program's own `rule` kind when one is in play
745
+ * (a relocated `rule` places it at the relocated root), else the built-in.
746
+ *
747
+ * # Throws
748
+ * If an authored `rule` member already holds a synthesized rule's name — those names
749
+ * are temper's, so two writers at one file is a collision.
750
+ */
751
+ function guidanceRules(harness) {
752
+ const kinds = kindsInPlay(harness);
753
+ const admissions = admissionsByHost(harness);
754
+ const ruleFacts = kinds.find((facts) => facts.name === rule.key) ?? rule.facts;
755
+ const authored = new Set(harness.members.filter((member) => member.kind === rule.key).map((member) => member.name));
756
+ const synthesize = (name, prose, paths, owner) => {
757
+ if (authored.has(name)) {
758
+ throw new Error(`rule \`${name}\`: the name is the ${owner} — the \`${GUIDANCE_RULE_PREFIX}\` names and ` +
759
+ `\`${COUNSEL_RULE_NAME}\` are temper's own, so rename the authored rule.`);
511
760
  }
761
+ const member = {
762
+ kind: rule.key,
763
+ facts: ruleFacts,
764
+ name,
765
+ prose: span(prose),
766
+ fields: [["paths", paths]],
767
+ satisfies: [],
768
+ requires: {},
769
+ needs: [],
770
+ inputs: [],
771
+ };
772
+ SYNTHESIZED_RULES.add(member);
773
+ return member;
774
+ };
775
+ const rules = [
776
+ synthesize(COUNSEL_RULE_NAME, SDK_COUNSEL, [COUNSEL_RULE_PATHS], "SDK counsel rule temper synthesizes over the program"),
777
+ ];
778
+ const requirements = contractedRequirements(harness);
779
+ for (const facts of kinds) {
780
+ const guidance = guidanceBody(facts, kinds, requirements);
781
+ if (guidance === undefined)
782
+ continue;
783
+ const paths = locusGlobs(facts, kinds, admissions);
784
+ if (paths.length === 0)
785
+ continue;
786
+ rules.push(synthesize(`${GUIDANCE_RULE_PREFIX}${facts.name}`, guidance, paths, `guidance rule temper synthesizes for kind \`${facts.name}\``));
787
+ }
788
+ return rules;
789
+ }
790
+ /**
791
+ * `harness` with its {@link guidanceRules} joined into the member roster — the one view
792
+ * every compiled face reads, so the declaration rows and the projected members agree on
793
+ * what was synthesized. Idempotent: a harness already carrying them comes back as is.
794
+ */
795
+ export function withGuidanceRules(harness) {
796
+ if (harness.members.some((member) => SYNTHESIZED_RULES.has(member)))
797
+ return harness;
798
+ return { ...harness, members: [...harness.members, ...guidanceRules(harness)] };
799
+ }
800
+ /**
801
+ * Every declared requirement as a `[name, requirement]` entry — the assembly's (its
802
+ * `require` map and the requirement members its roster composed, which `harness()` already
803
+ * resolved), then each member's published `requires`, a requirement member among them read
804
+ * through {@link requirementOf}. The one source every requirement reader walks.
805
+ */
806
+ function requirementEntries(harness) {
807
+ const entries = Object.entries(harness.require);
808
+ for (const member of harness.members) {
809
+ for (const [name, value] of Object.entries(member.requires))
810
+ entries.push([name, requirementOf(name, value)]);
512
811
  }
513
- const merged = uniqueMap(entries);
812
+ return entries;
813
+ }
814
+ /**
815
+ * The requirement rows — assembly `require` and every member's `requires`, one namespace.
816
+ * An unset `required` lowers the corpus's shipped default — "this must be filled": at
817
+ * least one satisfier, at error — so only an explicit `required: false` is advisory.
818
+ */
819
+ function requirementRows(harness) {
820
+ const merged = uniqueMap(requirementEntries(harness));
514
821
  return [...merged.entries()]
515
822
  .sort(([a], [b]) => compareStrings(a, b))
516
823
  .map(([name, requirement]) => ({
517
824
  name,
518
- kind: typeof requirement.kind === "string" ? requirement.kind : requirement.kind?.key,
825
+ kind: requirement.kind?.key,
519
826
  required: requirement.required ?? true,
520
827
  clauses: (requirement.clauses ?? []).map((clause) => clauseRow(clause)),
521
828
  verifier: verifierRow(requirement.verifier),
@@ -531,13 +838,18 @@ function requirementRows(harness) {
531
838
  function verifierRow(verifier) {
532
839
  if (verifier === undefined)
533
840
  return undefined;
534
- return verifier.species === "script"
535
- ? { species: "script", path: verifier.path }
536
- : { species: "telemetry", events: [...verifier.events] };
841
+ switch (verifier.species) {
842
+ case "script":
843
+ return { species: "script", path: verifier.path };
844
+ case "telemetry":
845
+ return { species: "telemetry", events: [...verifier.events] };
846
+ case "review":
847
+ return { species: "review", prose: verifier.prose };
848
+ }
537
849
  }
538
850
  /**
539
- * The assembly-scope facts, in a stable order: the root member's declared `mode`, then
540
- * one `contract` declaredness marker per `expect`-bound kind (kind-sorted, as `expect`'s
851
+ * The assembly-scope facts, in a stable order: the root member's declared `mode` and the
852
+ * kind and member overrides beneath it, then one `contract` declaredness marker per `expect`-bound kind (kind-sorted, as `expect`'s
541
853
  * own clause rows are) plus the root's where the author declared one, then one edge row
542
854
  * per kind edge field.
543
855
  *
@@ -555,7 +867,7 @@ function verifierRow(verifier) {
555
867
  * through its host's `templates` column alone.
556
868
  */
557
869
  function assemblyFactRows(harness, kinds) {
558
- const facts = [{ fact: "mode", value: harness.mode }];
870
+ const facts = [{ fact: "mode", value: harness.mode }, ...modeOverrideRows(harness, kinds)];
559
871
  for (const binding of [...harness.expect].sort((a, b) => compareStrings(a.kind.key, b.kind.key))) {
560
872
  facts.push({ fact: "contract", from: binding.kind.key });
561
873
  }
@@ -563,11 +875,31 @@ function assemblyFactRows(harness, kinds) {
563
875
  facts.push({ fact: "contract" });
564
876
  for (const kind of kinds) {
565
877
  for (const edge of kind.edgeFields ?? []) {
566
- facts.push({ fact: "edge", from: kind.name, field: edge.field, to: [...edge.to] });
878
+ facts.push({
879
+ fact: "edge",
880
+ from: kind.name,
881
+ field: edge.field,
882
+ to: edgeTargetNames(edge),
883
+ ...(edge.provided !== undefined ? { provided: [...edge.provided] } : {}),
884
+ });
567
885
  }
568
886
  }
569
887
  return facts;
570
888
  }
889
+ /**
890
+ * The `mode` overrides beneath the root's: one per kind declaring its own (kind-sorted,
891
+ * named in `from` as a `contract` marker names its kind), then one per member declaring
892
+ * its own (address-sorted, named in `member`).
893
+ */
894
+ function modeOverrideRows(harness, kinds) {
895
+ const byKind = kinds
896
+ .flatMap((kind) => (kind.mode === undefined ? [] : [{ fact: "mode", value: kind.mode, from: kind.name }]))
897
+ .sort((a, b) => compareStrings(a.from ?? "", b.from ?? ""));
898
+ const byMember = harness.members
899
+ .flatMap((member) => member.mode === undefined ? [] : [{ fact: "mode", value: member.mode, member: memberAddress(member) }])
900
+ .sort((a, b) => compareStrings(a.member ?? "", b.member ?? ""));
901
+ return [...byKind, ...byMember];
902
+ }
571
903
  /**
572
904
  * The `satisfies` rows — every member's fill claims, member-then-requirement sorted.
573
905
  * The `member` is the filler's own {@link memberAddress}, the same identity
@@ -751,6 +1083,33 @@ function nestedMemberRow(host, value, scope, placements, extents) {
751
1083
  ...(extent === undefined ? {} : { rendered_lines: extent.lines, rendered_chars: extent.chars }),
752
1084
  };
753
1085
  }
1086
+ /** The `nested_member` row of a root-hosted roster member, its string fields its leaves. */
1087
+ function rootHostedRow(member) {
1088
+ const leaves = {};
1089
+ for (const [field, value] of member.fields) {
1090
+ if (typeof value === "string")
1091
+ leaves[field] = value;
1092
+ }
1093
+ return { host: ROOT_ADDRESS, kind: member.kind, key: member.name, leaves, collections: {} };
1094
+ }
1095
+ /**
1096
+ * The `nested_member` rows of the declared requirements — each the root's nested member
1097
+ * `root/<kind>/<name>`, its kind the member's own (a subkind's name, `requirement` for a
1098
+ * literal) and its string fields its leaves, so a subkind's own fields reach `check` and
1099
+ * the read verbs at leaf grain. The requirement row still carries the contract-facing
1100
+ * template (fill posture, clauses, verifier, prose); this row is the member's identity.
1101
+ */
1102
+ function requirementHostedRows(harness) {
1103
+ return [...uniqueMap(requirementEntries(harness)).entries()].map(([name, declared]) => {
1104
+ const source = requirementSource(declared);
1105
+ const leaves = {};
1106
+ for (const [field, value] of source?.fields ?? []) {
1107
+ if (typeof value === "string")
1108
+ leaves[field] = value;
1109
+ }
1110
+ return { host: ROOT_ADDRESS, kind: source?.kind ?? requirement.key, key: name, leaves, collections: {} };
1111
+ });
1112
+ }
754
1113
  /**
755
1114
  * The corpus's `admit` declarations, indexed by host kind name — the one source both
756
1115
  * {@link templatesFor} and {@link nestedMemberRows} read. Admission carries kind values,
@@ -781,7 +1140,8 @@ function admissionsByHost(harness) {
781
1140
  * values, host-then-kind-then-key sorted, each keyed to its host's own
782
1141
  * {@link memberAddress} so a host that is itself a nested file child keys by the
783
1142
  * host-qualified address `check` resolves it at. Only a composed body's embedded values
784
- * carry them (a `file()`/`text` body — and a composed body's prose spans — name none); the
1143
+ * carry them (a `file()`/`text` body — and a composed body's prose spans — name none),
1144
+ * beside each root-hosted roster member ({@link rootHostedRow}); the
785
1145
  * fence rendering itself is unchanged
786
1146
  * (`emit.ts`'s `resolveBody`) — this row is a second *read* of the same authored
787
1147
  * value, never a second copy the engine reads back (0018).
@@ -796,6 +1156,10 @@ function admissionsByHost(harness) {
796
1156
  function nestedMemberRows(harness, admissions, scope, placements, extents) {
797
1157
  const rows = [];
798
1158
  for (const member of harness.members) {
1159
+ if (ROOT_HOSTED_KINDS.has(member.kind)) {
1160
+ rows.push(rootHostedRow(member));
1161
+ continue;
1162
+ }
799
1163
  if (member.prose?.kind !== "blocks")
800
1164
  continue;
801
1165
  const host = memberAddress(member);
@@ -811,6 +1175,7 @@ function nestedMemberRows(harness, admissions, scope, placements, extents) {
811
1175
  rows.push(nestedMemberRow(host, value, scope, placements, extents));
812
1176
  }
813
1177
  }
1178
+ rows.push(...requirementHostedRows(harness));
814
1179
  return rows.sort((a, b) => compareStrings(a.host, b.host) || compareStrings(a.kind, b.kind) || compareStrings(a.key, b.key));
815
1180
  }
816
1181
  /**
@@ -833,9 +1198,9 @@ function nestedMemberRows(harness, admissions, scope, placements, extents) {
833
1198
  */
834
1199
  function registrationRows(harness) {
835
1200
  return harness.members
836
- .filter((member) => member.facts.shape === "fields")
1201
+ .filter((member) => member.facts.shape === "fields" && member.facts.locus.kind !== "embedded")
837
1202
  .map((member) => {
838
- const address = member.facts.collectionAddress;
1203
+ const address = collectionAddressOf(member.facts);
839
1204
  if (address === undefined) {
840
1205
  throw new Error(`member \`${member.name}\`: a fields-only registration kind declares no ` +
841
1206
  `collection address — it surfaces in no host manifest (specs/model/authoring.md, "The SDK").`);
@@ -848,25 +1213,141 @@ function registrationRows(harness) {
848
1213
  // The generated row carries a mutable field list; the member's is read-only, so
849
1214
  // copy each pair into a fresh tuple — the same values, a shape the row accepts.
850
1215
  fields: [
851
- ...member.fields.map(([name, value]) => [name, value]),
852
- // A gate hook carries its declared binary across the seam beside its fields; the
1216
+ ...member.fields.map(([name, value]) => [name, projectedField(member, name, value)]),
1217
+ // A gate hook carries its tool's address across the seam beside its fields; the
853
1218
  // engine renders the handler's command from it and drops the key ({@link gateHook}).
854
- ...gateBinaryField(member),
1219
+ ...gateToolField(harness, member),
855
1220
  ],
856
1221
  };
857
1222
  })
858
1223
  .sort((a, b) => compareStrings(a.kind, b.kind) || compareStrings(a.key, b.key));
859
1224
  }
860
- /** The gate hook row's binary field — `[GATE_BINARY_KEY, binary]` for a {@link gateHook}
861
- * member, `null` declaring none, and nothing for every other member. */
862
- function gateBinaryField(member) {
863
- const binary = gateHookBinary(member);
864
- return binary === undefined ? [] : [[GATE_BINARY_KEY, binary]];
1225
+ /** The settings key a status line rides under — {@link Settings}' `statusLine`. */
1226
+ const STATUS_LINE_KEY = "statusLine";
1227
+ /** `value` without its {@link RUNS_FIELD} edge, where it is an object carrying one. */
1228
+ function withoutRuns(value) {
1229
+ if (typeof value !== "object" || value === null || Array.isArray(value) || !(RUNS_FIELD in value))
1230
+ return value;
1231
+ const { [RUNS_FIELD]: _runs, ...projected } = value;
1232
+ return projected;
1233
+ }
1234
+ /**
1235
+ * A member's field as its artifact carries it: a hook's handlers and a settings member's
1236
+ * `statusLine` each lose the {@link RUNS_FIELD} edge, which is temper's and rides the lock
1237
+ * as a `runs` row ({@link runsRows}), never a key in `settings.json`. Every other field is
1238
+ * as authored. The one projection of a runner's fields, read by the registration rows here
1239
+ * and by the payload members `emit.ts` hands the engine.
1240
+ */
1241
+ export function projectedField(member, name, value) {
1242
+ if (member.kind === hook.key && name === HOOK_HANDLER_KEY && Array.isArray(value))
1243
+ return value.map(withoutRuns);
1244
+ if (member.kind === settings.key && name === STATUS_LINE_KEY)
1245
+ return withoutRuns(value);
1246
+ return value;
1247
+ }
1248
+ /**
1249
+ * Each runner a member carries, paired with the `runs` value it names: a hook's handlers,
1250
+ * each at its own address (`<hook-address>/handler/<position>`, where the engine reads the
1251
+ * handler back), and a settings member's `statusLine`, at the member's own address.
1252
+ */
1253
+ function runners(member) {
1254
+ const field = (name) => member.fields.find(([key]) => key === name)?.[1];
1255
+ const runsOf = (value) => typeof value === "object" && value !== null ? value[RUNS_FIELD] : undefined;
1256
+ if (member.kind === hook.key) {
1257
+ const handlers = field(HOOK_HANDLER_KEY);
1258
+ if (!Array.isArray(handlers))
1259
+ return [];
1260
+ return handlers.map((handler, position) => [nestedAddress(memberAddress(member), "handler", String(position)), runsOf(handler)]);
1261
+ }
1262
+ if (member.kind === settings.key)
1263
+ return [[memberAddress(member), runsOf(field(STATUS_LINE_KEY))]];
1264
+ return [];
1265
+ }
1266
+ /**
1267
+ * The `runs` rows — each runner naming the {@link tool} it runs (a hook handler, a
1268
+ * settings status line, the root for its typecheck, a requirement for its telemetry tap or script verifier), keyed to the runner's own address and the tool's
1269
+ * (`root/tool/<name>`), in member-then-position order. The edge is declared, never read
1270
+ * off the runner's `command`: the program states which tool a command runs.
1271
+ *
1272
+ * # Throws
1273
+ * If a `runs` is not a `tool(...)` member, or names a tool the harness does not compose —
1274
+ * the edge would point at nothing the lock carries.
1275
+ */
1276
+ function runsRows(harness) {
1277
+ const rows = [];
1278
+ for (const member of harness.members) {
1279
+ for (const [runner, runs] of runners(member)) {
1280
+ if (runs === undefined)
1281
+ continue;
1282
+ rows.push({ member: runner, tool: composedToolAddress(harness, runner, "runs", runs) });
1283
+ }
1284
+ }
1285
+ // The harness root declares the typecheck, so the root is the compiler tool's runner.
1286
+ if (harness.typecheck !== undefined) {
1287
+ rows.push({ member: ROOT_ADDRESS, tool: composedToolAddress(harness, "typecheck", "tool", harness.typecheck.tool) });
1288
+ }
1289
+ // A telemetry requirement declares the tool its tap hooks run, and a script requirement the
1290
+ // tool that runs its script, so the requirement is the runner.
1291
+ const verified = requirementEntries(harness).sort(([a], [b]) => compareStrings(a, b));
1292
+ for (const [named, declared] of verified) {
1293
+ const verifier = declared.verifier;
1294
+ if (verifier === undefined || verifier.species === "review" || verifier.tool === undefined)
1295
+ continue;
1296
+ rows.push({
1297
+ member: nestedAddress(ROOT_ADDRESS, requirement.key, named),
1298
+ tool: composedToolAddress(harness, named, "tool", verifier.tool),
1299
+ });
1300
+ }
1301
+ return rows;
1302
+ }
1303
+ /**
1304
+ * The address (`root/tool/<name>`) of the composed {@link tool} a runner names under
1305
+ * `field` — the one check every runner→tool reference passes, a `runs` edge and the
1306
+ * typecheck alike.
1307
+ *
1308
+ * # Throws
1309
+ * If the value is not a `tool(...)` member, or names a tool the harness does not compose —
1310
+ * the reference would point at nothing the lock carries.
1311
+ */
1312
+ function composedToolAddress(harness, runner, field, value) {
1313
+ if (typeof value !== "object" || value === null || value.kind !== tool.key) {
1314
+ throw new Error(`\`${runner}\`: \`${field}\` names the tool the command runs — pass a \`tool(...)\` member.`);
1315
+ }
1316
+ if (!harness.members.includes(value)) {
1317
+ throw new Error(`\`${runner}\`: \`${field}\` names tool \`${value.name}\`, which the harness ` +
1318
+ `does not compose — add it to \`members\`.`);
1319
+ }
1320
+ return memberAddress(value);
1321
+ }
1322
+ /**
1323
+ * The typecheck row — the declared compiler's tool address and the project file, resolved
1324
+ * against the stating module like any {@link input} — or `null` where the program declares
1325
+ * none. Seam-inbound only: the engine runs it before compiling and lowers the project to a
1326
+ * root-owned input.
1327
+ *
1328
+ * # Throws
1329
+ * If the typecheck's `tool` is not a composed `tool(...)` member ({@link composedToolAddress}).
1330
+ */
1331
+ function typecheckRow(harness) {
1332
+ const declared = harness.typecheck;
1333
+ if (declared === undefined)
1334
+ return null;
1335
+ return {
1336
+ tool: composedToolAddress(harness, "typecheck", "tool", declared.tool),
1337
+ project: fileURLToPath(new URL(declared.project.path, declared.project.moduleUrl)),
1338
+ };
1339
+ }
1340
+ /** The gate hook row's tool field — `[GATE_TOOL_KEY, address]` for a {@link gateHook}
1341
+ * member, `null` declaring none, and nothing for every other member.
1342
+ *
1343
+ * # Throws
1344
+ * If the gate hook names a tool the harness does not compose ({@link composedToolAddress}). */
1345
+ function gateToolField(harness, member) {
1346
+ const reached = gateHookTool(member);
1347
+ if (reached === undefined)
1348
+ return [];
1349
+ return [[GATE_TOOL_KEY, reached === null ? null : composedToolAddress(harness, memberAddress(member), "tool", reached)]];
865
1350
  }
866
- /** The tap invocation the synthesized telemetry hooks run — the sibling verb of the
867
- * session-start reporter, appending one event record to the per-machine log
868
- * (`src/tap.rs`). Every synthesized hook's `command` field carries it verbatim. */
869
- const TAP_COMMAND = "temper tap \"$CLAUDE_PROJECT_DIR\"";
870
1351
  /**
871
1352
  * Builds a collision-safe dedup key for a tap hook (event, matcher) pair.
872
1353
  * Two distinct pairs cannot produce the same key (e.g., ("Foo", "BarBaz") ≠ ("FooBar", "Baz")).
@@ -884,35 +1365,48 @@ export function buildTapHookDedupeKey(event, matcher) {
884
1365
  * records every fire and read time joins raw events to members, so however many
885
1366
  * verifiers name an event it takes exactly one hook — the derived-aggregate precedent
886
1367
  * the permission union sets ({@link permissionUnion}). Each row is one matcher group
887
- * running {@link TAP_COMMAND} under the event's documented matcher
888
- * ({@link TELEMETRY_EVENT_HOOKS}), its key-path and fields sourced from the provider face
1368
+ * under the event's documented matcher ({@link TELEMETRY_EVENT_HOOKS}) whose one handler
1369
+ * carries the address of the tool the naming declarations reach — the engine renders the
1370
+ * tap command from it, anchored at the project (`src/drift.rs`) — its key-path and fields sourced from the provider face
889
1371
  * ({@link tapHookRegistration}, `builtins.ts`); an event-name outside that table is the
890
1372
  * roster's inadmissibility finding, never a row. Synthesized in isolation here — whether a
891
1373
  * row stands alone or joins an authored group at the same pair is
892
1374
  * {@link mergedRegistrationRows}'s call, so this pass need not know what the program
893
1375
  * authored.
1376
+ *
1377
+ * Declarations sharing a tap but naming different tools each keep a handler, named for
1378
+ * the first declaration naming it: whether two tools agree is the command the engine
1379
+ * renders (an undeclared one is the engine's default), so the engine merges or refuses
1380
+ * them — this pass never resolves the default.
1381
+ *
1382
+ * # Throws
1383
+ * If a declaration names a tool the harness does not compose ({@link composedToolAddress}).
894
1384
  */
895
1385
  function tapHookRows(harness) {
896
1386
  const deduped = new Map();
897
- const collect = (requirement) => {
1387
+ const collect = (named, requirement) => {
898
1388
  if (requirement.verifier?.species !== "telemetry")
899
1389
  return;
1390
+ const reached = requirement.verifier.tool;
1391
+ const tool = reached === undefined ? null : composedToolAddress(harness, named, "tool", reached);
900
1392
  for (const name of requirement.verifier.events) {
901
1393
  const mapping = TELEMETRY_EVENT_HOOKS[name];
902
- if (mapping !== undefined)
903
- deduped.set(buildTapHookDedupeKey(mapping.event, mapping.matcher), mapping);
1394
+ if (mapping === undefined)
1395
+ continue;
1396
+ const key = buildTapHookDedupeKey(mapping.event, mapping.matcher);
1397
+ const tap = deduped.get(key) ?? { ...mapping, declarations: [] };
1398
+ deduped.set(key, tap);
1399
+ if (!tap.declarations.some((declared) => declared.tool === tool)) {
1400
+ tap.declarations.push({ tool, named });
1401
+ }
904
1402
  }
905
1403
  };
906
- for (const requirement of Object.values(harness.require))
907
- collect(requirement);
908
- for (const member of harness.members) {
909
- for (const requirement of Object.values(member.requires))
910
- collect(requirement);
911
- }
1404
+ for (const [named, requirement] of requirementEntries(harness))
1405
+ collect(named, requirement);
912
1406
  return [...deduped.values()]
913
1407
  .sort((a, b) => compareStrings(a.event, b.event) || compareStrings(a.matcher, b.matcher))
914
- .map(({ event, matcher }) => {
915
- const { keyPath, fields } = tapHookRegistration(TAP_COMMAND, matcher);
1408
+ .map(({ event, matcher, declarations }) => {
1409
+ const { keyPath, fields } = tapHookRegistration(declarations, matcher);
916
1410
  return {
917
1411
  kind: hook.key,
918
1412
  key: event,
@@ -1000,6 +1494,14 @@ export function settingsRows(harness) {
1000
1494
  .map(([key, value]) => ({ manifest: SETTINGS_MANIFEST, key, value }))
1001
1495
  .sort((a, b) => compareStrings(a.key, b.key));
1002
1496
  }
1497
+ /** The playbook areas a guard attachment binds, one row per guarded playbook, in member
1498
+ * order — what `temper guard` reads an edit's path against. */
1499
+ function areaRows(harness) {
1500
+ return harness.members.flatMap((member) => {
1501
+ const area = playbookArea(member);
1502
+ return area === undefined ? [] : [{ rule: area.rule, paths: [...area.paths], mode: area.mode }];
1503
+ });
1504
+ }
1003
1505
  /** Every requirement name a `satisfies` claim may fill — assembly `require` ∪ member `requires`. */
1004
1506
  export function declaredRequirements(harness) {
1005
1507
  const set = new Set();
@@ -1052,7 +1554,7 @@ function mentionScope(harness) {
1052
1554
  return { mentionable: declaredAddresses(harness), deferrableKinds: declaredAtLocusKinds(harness) };
1053
1555
  }
1054
1556
  /**
1055
- * Compile a harness into its seven declaration families — the erased program.
1557
+ * Compile a harness into its declaration families — the erased program.
1056
1558
  *
1057
1559
  * `placements` and `extents` are `emit`'s record of what each embedded value's format
1058
1560
  * rendered (`emit.ts`'s `edgePlacements`) and the span it spanned (`renderedExtents`); this
@@ -1061,7 +1563,8 @@ function mentionScope(harness) {
1061
1563
  * columns — honest (nothing observed a render) but undecidable for a `format-places-edges`
1062
1564
  * or `extent` clause, so a whole compile goes through `emit`, never this alone.
1063
1565
  */
1064
- export function compileDeclarations(harness, placements, extents, modules = []) {
1566
+ export function compileDeclarations(program, placements, extents, modules = []) {
1567
+ const harness = withGuidanceRules(program);
1065
1568
  const allKinds = kindsInPlay(harness);
1066
1569
  const admissions = admissionsByHost(harness);
1067
1570
  const clauses = [];
@@ -1086,12 +1589,15 @@ export function compileDeclarations(harness, placements, extents, modules = [])
1086
1589
  assembly: assemblyFactRows(harness, allKinds),
1087
1590
  satisfies: satisfiesRows(harness),
1088
1591
  mentions: mentionRows(harness),
1592
+ runs: runsRows(harness),
1089
1593
  includes: includeRows(harness),
1090
1594
  inputs: inputRows(harness),
1091
1595
  modules: moduleRows(modules),
1596
+ typecheck: typecheckRow(harness),
1092
1597
  nested_members: nestedMemberRows(harness, admissions, mentionScope(harness), placements, extents),
1093
1598
  registrations: mergedRegistrationRows(harness),
1094
1599
  settings: settingsRows(harness),
1600
+ areas: areaRows(harness),
1095
1601
  };
1096
1602
  }
1097
1603
  /** The SDK's pinned engine/interchange version — the JSON pipe rides it in lockstep. */