@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/assembly.d.ts +20 -5
- package/dist/src/assembly.js +17 -7
- package/dist/src/builtins.d.ts +241 -52
- package/dist/src/builtins.js +248 -42
- package/dist/src/claude-code.d.ts +3 -2
- package/dist/src/claude-code.js +8 -1
- package/dist/src/contract.d.ts +20 -1
- package/dist/src/contract.js +20 -1
- package/dist/src/declarations.d.ts +26 -38
- package/dist/src/declarations.js +169 -92
- package/dist/src/emit.d.ts +9 -5
- package/dist/src/emit.js +265 -122
- package/dist/src/generated/AssemblyFactRow.d.ts +7 -5
- package/dist/src/generated/Declarations.d.ts +2 -2
- package/dist/src/generated/PayloadMember.d.ts +9 -3
- package/dist/src/generated/gate-commands.d.ts +2 -0
- package/dist/src/generated/gate-commands.js +3 -0
- package/dist/src/generated/index.d.ts +1 -0
- package/dist/src/generated/index.js +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/kind.d.ts +11 -4
- package/dist/src/kind.js +29 -0
- package/dist/src/member-address.d.ts +133 -25
- package/dist/src/member-address.js +144 -31
- package/dist/src/prose.d.ts +54 -13
- package/dist/src/prose.js +52 -11
- package/package.json +3 -3
|
@@ -23,14 +23,9 @@ export declare function compareStrings(a: string, b: string): number;
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function uniqueMap<K, V>(entries: Iterable<[K, V]>): Map<K, V>;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
* `
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
export declare function placementKey(host: string, kind: string, key: string): string;
|
|
31
|
-
/**
|
|
32
|
-
* Each composed embedded value's placed edge fields, by {@link placementKey} — `emit`'s
|
|
33
|
-
* record of which declared edges each value's format actually rendered (`emit.ts`'s
|
|
26
|
+
* Each composed embedded value's placed edge fields, by {@link nestedAddress} — the very
|
|
27
|
+
* address the `nested_member` row each entry feeds is identified by — `emit`'s record of
|
|
28
|
+
* which declared edges each value's format actually rendered (`emit.ts`'s
|
|
34
29
|
* `edgePlacements`). A value with no entry had no format observe it, which is distinct
|
|
35
30
|
* from a format that placed nothing: the row omits the column entirely and the
|
|
36
31
|
* `format-places-edges` clause stays undecided rather than indict a format that never ran.
|
|
@@ -44,26 +39,13 @@ export interface RenderedExtent {
|
|
|
44
39
|
readonly chars: number;
|
|
45
40
|
}
|
|
46
41
|
/**
|
|
47
|
-
* Each composed embedded value's rendered extent, by {@link
|
|
42
|
+
* Each composed embedded value's rendered extent, by {@link nestedAddress} — `emit`'s
|
|
48
43
|
* record of the span it projected for each value (`emit.ts`'s `renderedExtents`). A value
|
|
49
44
|
* with no entry had no format rendered it (a member read off a layout host's source),
|
|
50
45
|
* which the row spells by omitting both span columns rather than a captured zero: an
|
|
51
46
|
* unmeasured member's `extent` stays undecidable, never a zero read as a pass.
|
|
52
47
|
*/
|
|
53
48
|
export type RenderedExtents = ReadonlyMap<string, RenderedExtent>;
|
|
54
|
-
/**
|
|
55
|
-
* The `registration` rows — every fields-only registration member (a hook, an MCP server)
|
|
56
|
-
* erased for the manifest write face, kind-then-key sorted so double emit is byte-stable.
|
|
57
|
-
* Each carries its identity (`kind`/`key`), its collection address (`manifest`/`keyPath`,
|
|
58
|
-
* the wire's snake_case `key_path`), and its folded typed fields — the entry value the
|
|
59
|
-
* engine's write face places under `key`. The one source `emit.ts`'s public
|
|
60
|
-
* {@link RegistrationFact} view also maps from, so the seam and the `EmitResult` sibling
|
|
61
|
-
* cannot disagree on what a manifest carries.
|
|
62
|
-
*
|
|
63
|
-
* # Throws
|
|
64
|
-
* If a fields-only member declares no collection address — it surfaces in no host manifest.
|
|
65
|
-
*/
|
|
66
|
-
export declare function registrationRows(harness: Harness): RegistrationRow[];
|
|
67
49
|
/**
|
|
68
50
|
* Builds a collision-safe dedup key for a tap hook (event, matcher) pair.
|
|
69
51
|
* Two distinct pairs cannot produce the same key (e.g., ("Foo", "BarBaz") ≠ ("FooBar", "Baz")).
|
|
@@ -71,20 +53,25 @@ export declare function registrationRows(harness: Harness): RegistrationRow[];
|
|
|
71
53
|
*/
|
|
72
54
|
export declare function buildTapHookDedupeKey(event: string, matcher: string): string;
|
|
73
55
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
56
|
+
* Every `registration` row the program carries — the authored fields-only members
|
|
57
|
+
* ({@link registrationRows}) with the synthesized tap hooks ({@link tapHookRows}) **joined
|
|
58
|
+
* in**, and the one home both readers take: `compileDeclarations` writes it to
|
|
59
|
+
* `declarations.registrations` and `emit.ts`'s public {@link RegistrationFact} view maps
|
|
60
|
+
* from it, so the seam payload and the `EmitResult` sibling cannot disagree on whether a
|
|
61
|
+
* tap joined an authored group (`specs/process/engineering.md`, "One job, one home").
|
|
62
|
+
*
|
|
63
|
+
* A tap hook is an ordinary matcher group, so a tap whose (event, matcher) an authored
|
|
64
|
+
* group already claims **is** that group's further handler rather than a second group at
|
|
65
|
+
* the same key (0075): its handlers append to the claimant's `hooks` array in tap order,
|
|
66
|
+
* and only an unclaimed pair mints a row of its own. The claimant is the first authored
|
|
67
|
+
* row at the pair — a repeated pair joins one group rather than fanning the tap across
|
|
68
|
+
* every one of them. Authored rows keep their own order and position, so the merge moves
|
|
69
|
+
* no byte that did not need to move.
|
|
70
|
+
*
|
|
71
|
+
* # Throws
|
|
72
|
+
* If a fields-only member declares no collection address ({@link registrationRows}).
|
|
86
73
|
*/
|
|
87
|
-
export declare function
|
|
74
|
+
export declare function mergedRegistrationRows(harness: Harness): RegistrationRow[];
|
|
88
75
|
/**
|
|
89
76
|
* The `settings` rows — the assembly's harness-level residual settings keys, each folded
|
|
90
77
|
* into the settings.json manifest's opaque residue at emit. Key-sorted so double emit is
|
|
@@ -94,14 +81,15 @@ export declare function settingsRows(harness: Harness): SettingsRow[];
|
|
|
94
81
|
/** Every requirement name a `satisfies` claim may fill — assembly `require` ∪ member `requires`. */
|
|
95
82
|
export declare function declaredRequirements(harness: Harness): Set<string>;
|
|
96
83
|
/**
|
|
97
|
-
* Every address a mention may name — declared requirement names ∪ each member's
|
|
98
|
-
*
|
|
84
|
+
* Every address a mention may name — declared requirement names ∪ each member's own
|
|
85
|
+
* {@link memberAddress} ∪ each `blocks()`-declared embedded member's host-scoped
|
|
99
86
|
* `<host-kind>:<host-name>/<kind>/<key>` address. Shared by `emit.ts` (a
|
|
100
87
|
* member-level `Text` body's mentions) and this module (an embedded member's
|
|
101
88
|
* `Text` leaves) — the one resolution-check set, so a leaf mention and a member
|
|
102
89
|
* mention are held to the identical bar. The embedded address is host-scoped,
|
|
103
90
|
* never a flat `<kind>:<key>` — flat would force corpus-wide key uniqueness on
|
|
104
|
-
* embedded kinds
|
|
91
|
+
* embedded kinds, and a nested **file** child's own address carries its host for
|
|
92
|
+
* exactly that reason: two hosts may each carry a `home`, and a mention names one.
|
|
105
93
|
*/
|
|
106
94
|
export declare function declaredAddresses(harness: Harness): Set<string>;
|
|
107
95
|
/**
|
package/dist/src/declarations.js
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
12
|
import { isDeepStrictEqual } from "node:util";
|
|
13
|
-
import { isTextSpan,
|
|
14
|
-
import { SETTINGS_MANIFEST, TELEMETRY_EVENT_HOOKS, hook, tapHookRegistration } from "./builtins.js";
|
|
15
|
-
import {
|
|
13
|
+
import { isTextSpan, resolveEmbeddedLeaves } from "./prose.js";
|
|
14
|
+
import { HOOK_HANDLER_KEY, HOOK_MATCHER_KEY, SETTINGS_MANIFEST, TELEMETRY_EVENT_HOOKS, hook, hookCollectionKey, tapHookRegistration, } from "./builtins.js";
|
|
15
|
+
import { leafAddress, memberAddress, nestedAddress } from "./member-address.js";
|
|
16
16
|
/**
|
|
17
17
|
* Compile one `Clause` into its lock row: the shared `key`/`field`/`severity`/
|
|
18
18
|
* `guidance`/`cite` columns — the clause's four channels surviving erasure
|
|
@@ -28,34 +28,26 @@ import { hostAddress, leafAddress, nestedAddress } from "./member-address.js";
|
|
|
28
28
|
*/
|
|
29
29
|
function clauseRow(clause, kind) {
|
|
30
30
|
const { predicate } = clause;
|
|
31
|
-
// For a `when` clause, extract the guard predicate's key and arguments,
|
|
32
|
-
// then convert the body to nested rows.
|
|
33
31
|
if (predicate.key === "when") {
|
|
34
32
|
const guardPredicate = clause.when_guard;
|
|
35
33
|
if (!guardPredicate) {
|
|
36
|
-
throw new Error(
|
|
34
|
+
throw new Error(`a \`when\` clause carries no guard predicate — a guarded clause is one guard plus ` +
|
|
35
|
+
`the body it gates (specs/model/contract.md, "clause").`);
|
|
37
36
|
}
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
37
|
+
// The guard's argument columns ride through *whole*: a `when` row is the guard's own
|
|
38
|
+
// row with the clause's seven columns set over it, so a column a newly-guardable
|
|
39
|
+
// predicate adds reaches a guard's row by construction rather than by maintaining a
|
|
40
|
+
// list here. `src/contract.rs` `predicate_from_row` is the total counterpart on the
|
|
41
|
+
// read side, rebuilding the guard row by the same spread.
|
|
42
|
+
const { kind: _kind, predicate: guardKey, severity: _severity, guidance: _guidance, cite: _cite, guard_predicate: _guardPredicate, body: _body, ...guardColumns } = clauseRow({ predicate: guardPredicate, severity: clause.severity }, undefined);
|
|
41
43
|
return {
|
|
44
|
+
...guardColumns,
|
|
42
45
|
kind,
|
|
43
46
|
predicate: "when",
|
|
44
47
|
severity: clause.severity,
|
|
45
48
|
guidance: clause.guidance,
|
|
46
49
|
cite: clause.cite,
|
|
47
|
-
|
|
48
|
-
guard_predicate: guardRow.predicate,
|
|
49
|
-
value_type: guardRow.value_type,
|
|
50
|
-
shape: guardRow.shape,
|
|
51
|
-
bound: guardRow.bound,
|
|
52
|
-
unit: guardRow.unit,
|
|
53
|
-
charset: guardRow.charset,
|
|
54
|
-
keys: guardRow.keys,
|
|
55
|
-
values: guardRow.values,
|
|
56
|
-
range: guardRow.range,
|
|
57
|
-
section: guardRow.section,
|
|
58
|
-
sections: guardRow.sections,
|
|
50
|
+
guard_predicate: guardKey,
|
|
59
51
|
body: clause.when_body ? clause.when_body.map((c) => clauseRow(c, undefined)) : undefined,
|
|
60
52
|
};
|
|
61
53
|
}
|
|
@@ -538,7 +530,17 @@ function verifierRow(verifier) {
|
|
|
538
530
|
}
|
|
539
531
|
/**
|
|
540
532
|
* The assembly-scope facts, in a stable order: the root member's declared `mode`, then
|
|
541
|
-
* one
|
|
533
|
+
* one `contract` declaredness marker per `expect`-bound kind (kind-sorted, as `expect`'s
|
|
534
|
+
* own clause rows are) plus the root's where the author declared one, then one edge row
|
|
535
|
+
* per kind edge field.
|
|
536
|
+
*
|
|
537
|
+
* The `contract` marker is what makes an authored empty clause array a declared contract:
|
|
538
|
+
* a clause row count cannot tell `expect(kind, [])` from a kind the program never bound,
|
|
539
|
+
* nor a root `contract: []` from silence, so declaredness rides its own fact and
|
|
540
|
+
* `compose`'s two rows-or-default branches read it (decision 0072). It names its kind in
|
|
541
|
+
* the row's `from` column — the same column an `edge` fact names its source kind in — and
|
|
542
|
+
* omits `from` entirely for the root, the kind-absent-means-root discriminator a root
|
|
543
|
+
* clause row already uses.
|
|
542
544
|
*
|
|
543
545
|
* `kinds` is every kind in play at *any* locus, not just the unit-owning ones that take
|
|
544
546
|
* a kind-fact row: an edge is a declared relationship at any grain, so an embedded
|
|
@@ -547,6 +549,11 @@ function verifierRow(verifier) {
|
|
|
547
549
|
*/
|
|
548
550
|
function assemblyFactRows(harness, kinds) {
|
|
549
551
|
const facts = [{ fact: "mode", value: harness.mode }];
|
|
552
|
+
for (const binding of [...harness.expect].sort((a, b) => compareStrings(a.kind.key, b.kind.key))) {
|
|
553
|
+
facts.push({ fact: "contract", from: binding.kind.key });
|
|
554
|
+
}
|
|
555
|
+
if (harness.contractDeclared)
|
|
556
|
+
facts.push({ fact: "contract" });
|
|
550
557
|
for (const kind of kinds) {
|
|
551
558
|
for (const edge of kind.edgeFields ?? []) {
|
|
552
559
|
facts.push({ fact: "edge", from: kind.name, field: edge.field, to: [...edge.to] });
|
|
@@ -556,14 +563,15 @@ function assemblyFactRows(harness, kinds) {
|
|
|
556
563
|
}
|
|
557
564
|
/**
|
|
558
565
|
* The `satisfies` rows — every member's fill claims, member-then-requirement sorted.
|
|
559
|
-
* The `member` is the filler's own
|
|
566
|
+
* The `member` is the filler's own {@link memberAddress}, the same identity
|
|
560
567
|
* `mentionRows` writes, so the read side joins on a kind-qualified label a same-named
|
|
561
|
-
* member of another kind can never collide with
|
|
568
|
+
* member of another kind can never collide with — and a nested file child joins on the
|
|
569
|
+
* host-qualified one it resolves at, never a name its host's sibling also carries.
|
|
562
570
|
*/
|
|
563
571
|
function satisfiesRows(harness) {
|
|
564
572
|
const rows = [];
|
|
565
573
|
for (const member of harness.members) {
|
|
566
|
-
const address =
|
|
574
|
+
const address = memberAddress(member);
|
|
567
575
|
for (const requirement of member.satisfies) {
|
|
568
576
|
rows.push({ member: address, requirement });
|
|
569
577
|
}
|
|
@@ -573,18 +581,21 @@ function satisfiesRows(harness) {
|
|
|
573
581
|
/**
|
|
574
582
|
* The `mention` rows — every member's authored `n` targets, member-then-target
|
|
575
583
|
* sorted. `text`-kind prose contributes one row per mention, keyed to the
|
|
576
|
-
* member's own
|
|
584
|
+
* member's own {@link memberAddress}. A `blocks()` composed body keys each child
|
|
577
585
|
* to what it is: a prose span's mentions are host-level, keyed to the member's
|
|
578
|
-
* own
|
|
579
|
-
* mentions are keyed to that leaf's own
|
|
580
|
-
* address
|
|
581
|
-
*
|
|
582
|
-
*
|
|
586
|
+
* own address like a `text` body; an embedded value's `Text`-leaf
|
|
587
|
+
* mentions are keyed to that leaf's own
|
|
588
|
+
* `<host-address>/<kind>/<key>/<child-path>` address
|
|
589
|
+
* ([`embeddedLeafMentionRows`]), headed by the very `address` computed here —
|
|
590
|
+
* every row site in this function composes a host's address through
|
|
591
|
+
* {@link memberAddress}, the leaf branch included. A `file()` body names none.
|
|
592
|
+
* Recorded off the raw authored address, unconditionally — resolution is
|
|
593
|
+
* `emit`'s own refusal (`emit.ts`), not this row's concern.
|
|
583
594
|
*/
|
|
584
595
|
function mentionRows(harness) {
|
|
585
596
|
const rows = [];
|
|
586
597
|
for (const member of harness.members) {
|
|
587
|
-
const address =
|
|
598
|
+
const address = memberAddress(member);
|
|
588
599
|
if (member.prose?.kind === "text") {
|
|
589
600
|
for (const mention of member.prose.mentions) {
|
|
590
601
|
rows.push({ member: address, target: mention.target.address });
|
|
@@ -598,7 +609,7 @@ function mentionRows(harness) {
|
|
|
598
609
|
}
|
|
599
610
|
}
|
|
600
611
|
else {
|
|
601
|
-
rows.push(...embeddedLeafMentionRows(
|
|
612
|
+
rows.push(...embeddedLeafMentionRows(address, value));
|
|
602
613
|
}
|
|
603
614
|
}
|
|
604
615
|
}
|
|
@@ -611,10 +622,18 @@ function mentionRows(harness) {
|
|
|
611
622
|
* collection entry's leaves addressed `<collection>.<entry>.<field>` (one layer
|
|
612
623
|
* deep, matching the row's own shape) — each row keyed to the leaf's own
|
|
613
624
|
* structural address ({@link leafAddress}). A bare-string leaf names no mention.
|
|
625
|
+
*
|
|
626
|
+
* `host` is the hosting member's **own whole address** ({@link memberAddress}), at
|
|
627
|
+
* whatever grain the host sits: `kind:name` for a top-level host, the host's whole
|
|
628
|
+
* `<host-address>/<kind>/<key>` address under a nested one. A nested file child's
|
|
629
|
+
* identity *is* its host-qualified address (`compose.rs`'s `host_qualified`), so a
|
|
630
|
+
* head spelled off the bare name alone would name no member at `read.rs`'s
|
|
631
|
+
* `resolve_leaf` — and two sibling children each keyed `home` would head one string
|
|
632
|
+
* where the grammar scopes them to their hosts.
|
|
614
633
|
*/
|
|
615
|
-
function embeddedLeafMentionRows(
|
|
634
|
+
function embeddedLeafMentionRows(host, value) {
|
|
616
635
|
const rows = [];
|
|
617
|
-
const addressed = (childPath) => leafAddress(
|
|
636
|
+
const addressed = (childPath) => leafAddress(host, value.kind, value.key, childPath);
|
|
618
637
|
for (const [field, leaf] of Object.entries(value.leaves)) {
|
|
619
638
|
if (typeof leaf === "string")
|
|
620
639
|
continue;
|
|
@@ -637,13 +656,13 @@ function embeddedLeafMentionRows(hostName, value) {
|
|
|
637
656
|
}
|
|
638
657
|
/**
|
|
639
658
|
* The `include` rows — every member's `text`-body includes, in member-then-authored
|
|
640
|
-
* order. Each carries the host member's
|
|
659
|
+
* order. Each carries the host member's own {@link memberAddress} and the include target's
|
|
641
660
|
* path resolved against the stating module ({@link fileURLToPath} over the include's own
|
|
642
661
|
* `moduleUrl`), never the workspace — the engine reads, splices, and fingerprints it.
|
|
643
662
|
* Member order stays authored (never target-sorted): the body's include slots ride the
|
|
644
663
|
* same order, so the engine pairs the k-th slot with the k-th row. Includes ride a `text`
|
|
645
664
|
* body and a composed body's prose spans alike, in authored order across the interleave; an
|
|
646
|
-
* embedded leaf carries none (refused at
|
|
665
|
+
* embedded leaf carries none (refused at `prose.ts`'s `resolveLeaf`) and a `file()` body names none.
|
|
647
666
|
*/
|
|
648
667
|
function includeRows(harness) {
|
|
649
668
|
const rows = [];
|
|
@@ -651,7 +670,7 @@ function includeRows(harness) {
|
|
|
651
670
|
rows.push({ member: address, source_path: fileURLToPath(new URL(include.path, include.moduleUrl)) });
|
|
652
671
|
};
|
|
653
672
|
for (const member of harness.members) {
|
|
654
|
-
const address =
|
|
673
|
+
const address = memberAddress(member);
|
|
655
674
|
if (member.prose?.kind === "text") {
|
|
656
675
|
for (const include of member.prose.includes)
|
|
657
676
|
push(address, include);
|
|
@@ -669,7 +688,7 @@ function includeRows(harness) {
|
|
|
669
688
|
}
|
|
670
689
|
/**
|
|
671
690
|
* The `input` rows — every member's declared inputs, in member-then-authored order.
|
|
672
|
-
* Each carries the declaring member's
|
|
691
|
+
* Each carries the declaring member's own {@link memberAddress} and the input's path resolved
|
|
673
692
|
* against the stating module ({@link fileURLToPath} over the input's own `moduleUrl`),
|
|
674
693
|
* never the workspace — exactly as an include's is; the engine reads and fingerprints
|
|
675
694
|
* it, and splices nothing.
|
|
@@ -681,7 +700,7 @@ function includeRows(harness) {
|
|
|
681
700
|
function inputRows(harness) {
|
|
682
701
|
const rows = [];
|
|
683
702
|
for (const member of harness.members) {
|
|
684
|
-
const address =
|
|
703
|
+
const address = memberAddress(member);
|
|
685
704
|
for (const declared of member.inputs) {
|
|
686
705
|
rows.push({ member: address, source_path: fileURLToPath(new URL(declared.path, declared.moduleUrl)) });
|
|
687
706
|
}
|
|
@@ -689,38 +708,16 @@ function inputRows(harness) {
|
|
|
689
708
|
return rows;
|
|
690
709
|
}
|
|
691
710
|
/**
|
|
692
|
-
* One
|
|
693
|
-
* `
|
|
694
|
-
* `
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* One host member's declared embedded-member value as its declaration row —
|
|
701
|
-
* each `Text`-authored leaf resolved to its final stored string
|
|
702
|
-
* ([`NestedMemberRow`]), mention-resolution-checked against `scope` the identical
|
|
703
|
-
* way `emit.ts`'s `renderMemberToml` checks the same leaf on its way into the
|
|
704
|
-
* rendered fence — plus the `placed_edges` record `emit` observed while rendering the
|
|
705
|
-
* same value, which is the only way an edge's placement reaches the engine.
|
|
711
|
+
* One host member's declared embedded-member value as its declaration row
|
|
712
|
+
* ([`NestedMemberRow`]) — its leaves through the shared walk
|
|
713
|
+
* ({@link resolveEmbeddedLeaves}), the identical resolution `emit.ts` runs on the same
|
|
714
|
+
* leaf's way into the rendered fence — plus the `placed_edges` record `emit` observed
|
|
715
|
+
* while rendering the same value, which is the only way an edge's placement reaches
|
|
716
|
+
* the engine.
|
|
706
717
|
*/
|
|
707
718
|
function nestedMemberRow(host, value, scope, placements, extents) {
|
|
708
|
-
const
|
|
709
|
-
const
|
|
710
|
-
for (const [field, leaf] of Object.entries(value.leaves)) {
|
|
711
|
-
leaves[field] = resolveLeaf(leaf, scope, context(field));
|
|
712
|
-
}
|
|
713
|
-
const collections = {};
|
|
714
|
-
for (const [collection, entries] of Object.entries(value.collections)) {
|
|
715
|
-
collections[collection] = entries.map((entry) => {
|
|
716
|
-
const entryLeaves = {};
|
|
717
|
-
for (const [field, leaf] of Object.entries(entry.leaves)) {
|
|
718
|
-
entryLeaves[field] = resolveLeaf(leaf, scope, context(`${collection}.${entry.key}.${field}`));
|
|
719
|
-
}
|
|
720
|
-
return { key: entry.key, leaves: entryLeaves };
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
const key = placementKey(host, value.kind, value.key);
|
|
719
|
+
const { leaves, collections } = resolveEmbeddedLeaves(value, scope);
|
|
720
|
+
const key = nestedAddress(host, value.kind, value.key);
|
|
724
721
|
const placed = placements?.get(key);
|
|
725
722
|
const extent = extents?.get(key);
|
|
726
723
|
return {
|
|
@@ -767,8 +764,10 @@ function admissionsByHost(harness) {
|
|
|
767
764
|
}
|
|
768
765
|
/**
|
|
769
766
|
* The `nested_member` rows — every host member's `blocks()`-declared embedded-member
|
|
770
|
-
* values, host-then-kind-then-key sorted
|
|
771
|
-
*
|
|
767
|
+
* values, host-then-kind-then-key sorted, each keyed to its host's own
|
|
768
|
+
* {@link memberAddress} so a host that is itself a nested file child keys by the
|
|
769
|
+
* host-qualified address `check` resolves it at. Only a composed body's embedded values
|
|
770
|
+
* carry them (a `file()`/`text` body — and a composed body's prose spans — name none); the
|
|
772
771
|
* fence rendering itself is unchanged
|
|
773
772
|
* (`emit.ts`'s `resolveBody`) — this row is a second *read* of the same authored
|
|
774
773
|
* value, never a second copy the engine reads back (0018).
|
|
@@ -785,7 +784,7 @@ function nestedMemberRows(harness, admissions, scope, placements, extents) {
|
|
|
785
784
|
for (const member of harness.members) {
|
|
786
785
|
if (member.prose?.kind !== "blocks")
|
|
787
786
|
continue;
|
|
788
|
-
const host =
|
|
787
|
+
const host = memberAddress(member);
|
|
789
788
|
for (const value of member.prose.values) {
|
|
790
789
|
if (isTextSpan(value))
|
|
791
790
|
continue;
|
|
@@ -803,16 +802,22 @@ function nestedMemberRows(harness, admissions, scope, placements, extents) {
|
|
|
803
802
|
/**
|
|
804
803
|
* The `registration` rows — every fields-only registration member (a hook, an MCP server)
|
|
805
804
|
* erased for the manifest write face, kind-then-key sorted so double emit is byte-stable.
|
|
806
|
-
* Each carries its
|
|
807
|
-
* the wire's snake_case `key_path`), and its folded typed fields —
|
|
808
|
-
* engine's write face places under `key`. The
|
|
809
|
-
*
|
|
810
|
-
*
|
|
805
|
+
* Each carries its **collection key** (`kind`/`key`), its collection address
|
|
806
|
+
* (`manifest`/`keyPath`, the wire's snake_case `key_path`), and its folded typed fields —
|
|
807
|
+
* the entry value the engine's write face places under `key`. The authored half alone:
|
|
808
|
+
* the synthesized tap hooks join these rows in {@link mergedRegistrationRows}, which is
|
|
809
|
+
* what both readers of the family take.
|
|
810
|
+
*
|
|
811
|
+
* The row's `key` is where the entry **writes**, which for every kind but one is the
|
|
812
|
+
* member's own name. A hook's name joins its matcher onto the event because the group is
|
|
813
|
+
* the member, while the group still writes under `hooks.<Event>` — so the row keys the
|
|
814
|
+
* event back off the name ({@link hookCollectionKey}) and the member's address keeps the
|
|
815
|
+
* join.
|
|
811
816
|
*
|
|
812
817
|
* # Throws
|
|
813
818
|
* If a fields-only member declares no collection address — it surfaces in no host manifest.
|
|
814
819
|
*/
|
|
815
|
-
|
|
820
|
+
function registrationRows(harness) {
|
|
816
821
|
return harness.members
|
|
817
822
|
.filter((member) => member.facts.shape === "fields")
|
|
818
823
|
.map((member) => {
|
|
@@ -823,7 +828,7 @@ export function registrationRows(harness) {
|
|
|
823
828
|
}
|
|
824
829
|
return {
|
|
825
830
|
kind: member.kind,
|
|
826
|
-
key: member.name,
|
|
831
|
+
key: member.kind === hook.key ? hookCollectionKey(member.name) : member.name,
|
|
827
832
|
manifest: address.manifest,
|
|
828
833
|
key_path: address.keyPath,
|
|
829
834
|
// The generated row carries a mutable field list; the member's is read-only, so
|
|
@@ -853,13 +858,16 @@ export function buildTapHookDedupeKey(event, matcher) {
|
|
|
853
858
|
* unions the lifecycle events they name into one dumb registration apiece: the tap
|
|
854
859
|
* records every fire and read time joins raw events to members, so however many
|
|
855
860
|
* verifiers name an event it takes exactly one hook — the derived-aggregate precedent
|
|
856
|
-
* the permission union sets ({@link permissionUnion}). Each row
|
|
857
|
-
* under the event's documented matcher
|
|
858
|
-
*
|
|
859
|
-
* `builtins.ts`); an event-name outside that table is the
|
|
860
|
-
* finding, never a row.
|
|
861
|
+
* the permission union sets ({@link permissionUnion}). Each row is one matcher group
|
|
862
|
+
* running {@link TAP_COMMAND} under the event's documented matcher
|
|
863
|
+
* ({@link TELEMETRY_EVENT_HOOKS}), its key-path and fields sourced from the provider face
|
|
864
|
+
* ({@link tapHookRegistration}, `builtins.ts`); an event-name outside that table is the
|
|
865
|
+
* roster's inadmissibility finding, never a row. Synthesized in isolation here — whether a
|
|
866
|
+
* row stands alone or joins an authored group at the same pair is
|
|
867
|
+
* {@link mergedRegistrationRows}'s call, so this pass need not know what the program
|
|
868
|
+
* authored.
|
|
861
869
|
*/
|
|
862
|
-
|
|
870
|
+
function tapHookRows(harness) {
|
|
863
871
|
const deduped = new Map();
|
|
864
872
|
const collect = (requirement) => {
|
|
865
873
|
if (requirement.verifier?.species !== "telemetry")
|
|
@@ -889,6 +897,74 @@ export function tapHookRows(harness) {
|
|
|
889
897
|
};
|
|
890
898
|
});
|
|
891
899
|
}
|
|
900
|
+
/** A hook registration row's matcher — the group-level half of its identity, an omitted
|
|
901
|
+
* one read as the empty matcher it means (`"*"`/`""`/absent all name every tool). */
|
|
902
|
+
function groupMatcher(row) {
|
|
903
|
+
const found = row.fields.find(([name]) => name === HOOK_MATCHER_KEY)?.[1];
|
|
904
|
+
return typeof found === "string" ? found : "";
|
|
905
|
+
}
|
|
906
|
+
/** A hook registration row's handlers — the entries of its `hooks` array, or none where the
|
|
907
|
+
* row spells no array at all. */
|
|
908
|
+
function groupHandlers(row) {
|
|
909
|
+
const found = row.fields.find(([name]) => name === HOOK_HANDLER_KEY)?.[1];
|
|
910
|
+
return Array.isArray(found) ? found : [];
|
|
911
|
+
}
|
|
912
|
+
/** `row` with `extra` appended to its handler array — a fresh row over a fresh array, never
|
|
913
|
+
* a mutation: the authored array is the composing program's own value, and `emit` must be
|
|
914
|
+
* callable twice on one harness for the same bytes. */
|
|
915
|
+
function withHandlers(row, extra) {
|
|
916
|
+
const handlers = [...groupHandlers(row), ...extra];
|
|
917
|
+
const carried = row.fields.some(([name]) => name === HOOK_HANDLER_KEY);
|
|
918
|
+
const fields = row.fields.map(([name, value]) => name === HOOK_HANDLER_KEY ? [name, handlers] : [name, value]);
|
|
919
|
+
return { ...row, fields: carried ? fields : [...fields, [HOOK_HANDLER_KEY, handlers]] };
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Every `registration` row the program carries — the authored fields-only members
|
|
923
|
+
* ({@link registrationRows}) with the synthesized tap hooks ({@link tapHookRows}) **joined
|
|
924
|
+
* in**, and the one home both readers take: `compileDeclarations` writes it to
|
|
925
|
+
* `declarations.registrations` and `emit.ts`'s public {@link RegistrationFact} view maps
|
|
926
|
+
* from it, so the seam payload and the `EmitResult` sibling cannot disagree on whether a
|
|
927
|
+
* tap joined an authored group (`specs/process/engineering.md`, "One job, one home").
|
|
928
|
+
*
|
|
929
|
+
* A tap hook is an ordinary matcher group, so a tap whose (event, matcher) an authored
|
|
930
|
+
* group already claims **is** that group's further handler rather than a second group at
|
|
931
|
+
* the same key (0075): its handlers append to the claimant's `hooks` array in tap order,
|
|
932
|
+
* and only an unclaimed pair mints a row of its own. The claimant is the first authored
|
|
933
|
+
* row at the pair — a repeated pair joins one group rather than fanning the tap across
|
|
934
|
+
* every one of them. Authored rows keep their own order and position, so the merge moves
|
|
935
|
+
* no byte that did not need to move.
|
|
936
|
+
*
|
|
937
|
+
* # Throws
|
|
938
|
+
* If a fields-only member declares no collection address ({@link registrationRows}).
|
|
939
|
+
*/
|
|
940
|
+
export function mergedRegistrationRows(harness) {
|
|
941
|
+
const authored = registrationRows(harness);
|
|
942
|
+
const claimant = new Map();
|
|
943
|
+
authored.forEach((row, index) => {
|
|
944
|
+
if (row.kind !== hook.key)
|
|
945
|
+
return;
|
|
946
|
+
const key = buildTapHookDedupeKey(row.key, groupMatcher(row));
|
|
947
|
+
if (!claimant.has(key))
|
|
948
|
+
claimant.set(key, index);
|
|
949
|
+
});
|
|
950
|
+
const joined = new Map();
|
|
951
|
+
const unclaimed = [];
|
|
952
|
+
for (const tap of tapHookRows(harness)) {
|
|
953
|
+
const index = claimant.get(buildTapHookDedupeKey(tap.key, groupMatcher(tap)));
|
|
954
|
+
if (index === undefined) {
|
|
955
|
+
unclaimed.push(tap);
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
const handlers = joined.get(index) ?? [];
|
|
959
|
+
handlers.push(...groupHandlers(tap));
|
|
960
|
+
joined.set(index, handlers);
|
|
961
|
+
}
|
|
962
|
+
const rows = authored.map((row, index) => {
|
|
963
|
+
const extra = joined.get(index);
|
|
964
|
+
return extra === undefined ? row : withHandlers(row, extra);
|
|
965
|
+
});
|
|
966
|
+
return [...rows, ...unclaimed];
|
|
967
|
+
}
|
|
892
968
|
/**
|
|
893
969
|
* The `settings` rows — the assembly's harness-level residual settings keys, each folded
|
|
894
970
|
* into the settings.json manifest's opaque residue at emit. Key-sorted so double emit is
|
|
@@ -911,25 +987,26 @@ export function declaredRequirements(harness) {
|
|
|
911
987
|
return set;
|
|
912
988
|
}
|
|
913
989
|
/**
|
|
914
|
-
* Every address a mention may name — declared requirement names ∪ each member's
|
|
915
|
-
*
|
|
990
|
+
* Every address a mention may name — declared requirement names ∪ each member's own
|
|
991
|
+
* {@link memberAddress} ∪ each `blocks()`-declared embedded member's host-scoped
|
|
916
992
|
* `<host-kind>:<host-name>/<kind>/<key>` address. Shared by `emit.ts` (a
|
|
917
993
|
* member-level `Text` body's mentions) and this module (an embedded member's
|
|
918
994
|
* `Text` leaves) — the one resolution-check set, so a leaf mention and a member
|
|
919
995
|
* mention are held to the identical bar. The embedded address is host-scoped,
|
|
920
996
|
* never a flat `<kind>:<key>` — flat would force corpus-wide key uniqueness on
|
|
921
|
-
* embedded kinds
|
|
997
|
+
* embedded kinds, and a nested **file** child's own address carries its host for
|
|
998
|
+
* exactly that reason: two hosts may each carry a `home`, and a mention names one.
|
|
922
999
|
*/
|
|
923
1000
|
export function declaredAddresses(harness) {
|
|
924
1001
|
const set = declaredRequirements(harness);
|
|
925
1002
|
for (const member of harness.members) {
|
|
926
|
-
set.add(
|
|
1003
|
+
set.add(memberAddress(member));
|
|
927
1004
|
if (member.prose?.kind !== "blocks")
|
|
928
1005
|
continue;
|
|
929
1006
|
for (const value of member.prose.values) {
|
|
930
1007
|
if (isTextSpan(value))
|
|
931
1008
|
continue;
|
|
932
|
-
set.add(nestedAddress(
|
|
1009
|
+
set.add(nestedAddress(memberAddress(member), value.kind, value.key));
|
|
933
1010
|
}
|
|
934
1011
|
}
|
|
935
1012
|
return set;
|
|
@@ -987,7 +1064,7 @@ export function compileDeclarations(harness, placements, extents) {
|
|
|
987
1064
|
includes: includeRows(harness),
|
|
988
1065
|
inputs: inputRows(harness),
|
|
989
1066
|
nested_members: nestedMemberRows(harness, admissions, mentionScope(harness), placements, extents),
|
|
990
|
-
registrations:
|
|
1067
|
+
registrations: mergedRegistrationRows(harness),
|
|
991
1068
|
settings: settingsRows(harness),
|
|
992
1069
|
};
|
|
993
1070
|
}
|
package/dist/src/emit.d.ts
CHANGED
|
@@ -38,8 +38,9 @@ export interface ResolveOptions {
|
|
|
38
38
|
/** The addresses a mention may name — resolution-checked; a mention cannot dangle. */
|
|
39
39
|
readonly mentionable?: ReadonlySet<string>;
|
|
40
40
|
/**
|
|
41
|
-
* The discoverable (`at`-locus) kinds the program declares. A
|
|
42
|
-
* these whose member is not composed defers to `check` rather than refusing at emit
|
|
41
|
+
* The discoverable (`at`-locus) kinds the program declares. A reference naming one of
|
|
42
|
+
* these whose member is not composed defers to `check` rather than refusing at emit —
|
|
43
|
+
* a mention and an embedded value's edge target alike.
|
|
43
44
|
*/
|
|
44
45
|
readonly deferrableKinds?: ReadonlySet<string>;
|
|
45
46
|
/**
|
|
@@ -47,8 +48,10 @@ export interface ResolveOptions {
|
|
|
47
48
|
* resolves against to derive its target facts. Top-level members index at their
|
|
48
49
|
* `kind:name` address, and each composed embedded value at both of its own spellings:
|
|
49
50
|
* its full `<host-address>/<kind>/<key>` address and its bare `kind:key`.
|
|
50
|
-
*
|
|
51
|
-
*
|
|
51
|
+
* Refusal reaches exactly as far as the program's own universe, the one rule a mention
|
|
52
|
+
* and an edge target share: an address this table misses refuses, unless it names a kind
|
|
53
|
+
* {@link deferrableKinds} carries — then the member may be discovered on disk, and the
|
|
54
|
+
* field defers to `check` with no facts derived.
|
|
52
55
|
*/
|
|
53
56
|
readonly members?: ReadonlyMap<string, EdgeTarget>;
|
|
54
57
|
}
|
|
@@ -62,7 +65,8 @@ export interface ResolveOptions {
|
|
|
62
65
|
export interface RegistrationFact {
|
|
63
66
|
/** The erased registration kind — `hook`, `mcp-server` — joining `declarations.kinds`. */
|
|
64
67
|
readonly kind: string;
|
|
65
|
-
/** The
|
|
68
|
+
/** The collection key the entry writes under — a hook's event, a server's name. Not
|
|
69
|
+
* the member's own name where the two differ: a hook's name joins its matcher. */
|
|
66
70
|
readonly key: string;
|
|
67
71
|
/** The manifest collection address the registration surfaces at. */
|
|
68
72
|
readonly collectionAddress: {
|