@inventarch/runtime 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +17 -1
  2. package/SPEC.md +25 -5
  3. package/dist/context.d.ts +10 -1
  4. package/dist/context.d.ts.map +1 -1
  5. package/dist/context.js +14 -5
  6. package/dist/context.js.map +1 -1
  7. package/dist/coordinate.d.ts +9 -2
  8. package/dist/coordinate.d.ts.map +1 -1
  9. package/dist/coordinate.js +14 -0
  10. package/dist/coordinate.js.map +1 -1
  11. package/dist/door.d.ts +17 -0
  12. package/dist/door.d.ts.map +1 -1
  13. package/dist/door.js +101 -3
  14. package/dist/door.js.map +1 -1
  15. package/dist/errors.d.ts +4 -2
  16. package/dist/errors.d.ts.map +1 -1
  17. package/dist/errors.js +7 -1
  18. package/dist/errors.js.map +1 -1
  19. package/dist/index.d.ts +10 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +5 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/locator.d.ts +22 -2
  24. package/dist/locator.d.ts.map +1 -1
  25. package/dist/locator.js +290 -26
  26. package/dist/locator.js.map +1 -1
  27. package/dist/machine-protocol.d.ts +5 -0
  28. package/dist/machine-protocol.d.ts.map +1 -1
  29. package/dist/machine-protocol.js +141 -5
  30. package/dist/machine-protocol.js.map +1 -1
  31. package/dist/next.d.ts +151 -0
  32. package/dist/next.d.ts.map +1 -0
  33. package/dist/next.js +724 -0
  34. package/dist/next.js.map +1 -0
  35. package/dist/packet-host.d.ts +88 -0
  36. package/dist/packet-host.d.ts.map +1 -0
  37. package/dist/packet-host.js +239 -0
  38. package/dist/packet-host.js.map +1 -0
  39. package/dist/packet.d.ts +157 -0
  40. package/dist/packet.d.ts.map +1 -0
  41. package/dist/packet.js +207 -0
  42. package/dist/packet.js.map +1 -0
  43. package/dist/position.d.ts +275 -0
  44. package/dist/position.d.ts.map +1 -0
  45. package/dist/position.js +530 -0
  46. package/dist/position.js.map +1 -0
  47. package/dist/render.d.ts +6 -1
  48. package/dist/render.d.ts.map +1 -1
  49. package/dist/render.js +12 -0
  50. package/dist/render.js.map +1 -1
  51. package/dist/scope-key.d.ts +101 -0
  52. package/dist/scope-key.d.ts.map +1 -0
  53. package/dist/scope-key.js +175 -0
  54. package/dist/scope-key.js.map +1 -0
  55. package/package.json +24 -4
package/dist/packet.js ADDED
@@ -0,0 +1,207 @@
1
+ import { FLOOR_REGISTRATIONS, PHASES, PRIMITIVE_ANCHORS, PRIMITIVES, SHAPES, SHAPE_ROWS, isKind, } from '@inventarch/language';
2
+ import { digest, laneOf } from '@inventarch/graph';
3
+ import { MOVES } from './mandate-modes.js';
4
+ import { position } from './position.js';
5
+ import { statedText, valueText } from './render.js';
6
+ import { freeze } from './types.js';
7
+ const NO_PARTICIPANT = 'none (no authored @mandate names an @agent)';
8
+ const UNRESOLVED = 'unresolved';
9
+ const INSTALLED = 'unknown (no join checked here)';
10
+ const PHASE_CHANGES = '--phase selects the playbook cell delivered and decides conditional relation rows (decision conditional-relations-in-delivery)';
11
+ /** Design §4's three SPEC-owned lines, `ia scope` read as `ia position` (decision scope-verb-dispatch). */
12
+ const LINES = [
13
+ 'run ia position; if it refuses, run the command it names',
14
+ 'state intent to the CLI as shape + optional phase + optional seat + optional word; the CLI never receives free text',
15
+ "when a word's owner is not this workspace, delegate by re-seating at the owning system; a steward pointer is readable, not an invocation",
16
+ ];
17
+ const LOWERS = /^lowers to ([a-z]+)$/;
18
+ const order = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
19
+ /** The fields `node` states unconditionally at `field`, a `section.key` path. */
20
+ function fieldsAt(node, field) {
21
+ const [section, key] = field.split('.');
22
+ return node.sections
23
+ .filter((s) => s.name === section)
24
+ .flatMap((s) => s.fields)
25
+ .filter((f) => 'key' in f && f.key === key && f.when === undefined);
26
+ }
27
+ /** The values `node` states unconditionally at `field`, a list's items one by one. */
28
+ const valuesAt = (node, field) => fieldsAt(node, field).flatMap((f) => (f.value.kind === 'list' ? f.value.items : [f.value]));
29
+ const textsAt = (node, field) => valuesAt(node, field).flatMap((value) => ('text' in value ? [value.text] : []));
30
+ /** Whether `node` states `field` at all: a declared empty list is stated, an absent key is not. */
31
+ const stated = (node, field) => fieldsAt(node, field).length > 0;
32
+ const isMove = (text) => MOVES.includes(text);
33
+ /** The `discriminators` rows a @system record states: each word, the kind it lowers to and its facets. */
34
+ function loweringsOf(node) {
35
+ return node.sections
36
+ .filter((s) => s.name === 'discriminators')
37
+ .flatMap((s) => s.fields)
38
+ .flatMap((f) => {
39
+ if (!('key' in f) || f.value.kind !== 'scalar')
40
+ return [];
41
+ const kind = LOWERS.exec(f.value.text)?.[1];
42
+ if (kind === undefined || !isKind(kind))
43
+ return [];
44
+ const facets = (f.fields ?? [])
45
+ .filter((child) => 'key' in child && child.key === 'facets')
46
+ .flatMap((child) => (child.value.kind === 'list' ? child.value.items : [child.value]))
47
+ .flatMap((value) => ('text' in value ? [value.text] : []));
48
+ return [{ word: f.key, kind, facets }];
49
+ });
50
+ }
51
+ /**
52
+ * R19: the position packet through the scope token `within`, with its digest and host note. It calls position once,
53
+ * at K0, and reads the rest through the same token. `catalog` is copied in its order, each row's five fields only. A
54
+ * workspace with no participant renders none (B3). The refusals are position's alone: the packet renders the records
55
+ * admission admitted and gates none of them (design §4, LS-30).
56
+ */
57
+ export function renderPacket(handle, within, catalog) {
58
+ const k0 = position(handle, within), body = k0.body, read = { within }, snapshot = handle.snapshot(read), records = snapshot.records.filter((node) => node.placement.kind !== 'runtime'), nodes = new Map(records.map((node) => [node.identity, node]));
59
+ const viewed = new Map();
60
+ const rowsOf = (identity) => {
61
+ let rows = viewed.get(identity);
62
+ if (rows === undefined)
63
+ viewed.set(identity, (rows = handle.directedView(identity, read).filter((row) => nodes.has(row.counterpart))));
64
+ return rows;
65
+ };
66
+ /** The admitted records `identity`'s typed field references at `field` resolve to. */
67
+ const targetsOf = (identity, field) => rowsOf(identity)
68
+ .filter((row) => row.kind === 'field-ref' && row.direction === 'out' && row.field === field)
69
+ .map((row) => row.counterpart);
70
+ /** Each reference `node` states at `field`, once: the admitted record it resolves to, or the reference as authored. */
71
+ const refsAt = (node, field) => {
72
+ const targets = targetsOf(node.identity, field);
73
+ return [
74
+ ...new Set(valuesAt(node, field).flatMap((value) => value.kind !== 'ref'
75
+ ? []
76
+ : [
77
+ targets.find((target) => {
78
+ const counterpart = nodes.get(target);
79
+ return (counterpart.discriminator === value.discriminator && counterpart.name === value.name.toLowerCase());
80
+ }) ?? valueText(value),
81
+ ])),
82
+ ];
83
+ };
84
+ const seatId = body.seat.identity, seat = seatId === undefined ? undefined : nodes.get(seatId);
85
+ // Participants and mandates (B3): the authored mandates body(K0) lists whose participant resolves to an authored
86
+ // @agent, each read through the same token; an @agent once however many mandates name it. Each authority field is
87
+ // rendered as admitted, never judged: a declared `moves []` is `moves: []`, an absent key no field, and a reference
88
+ // with a fragment the record it resolves to.
89
+ const mandates = [], agents = new Map();
90
+ for (const pointer of body.mandates) {
91
+ const node = nodes.get(pointer.identity), participant = targetsOf(node.identity, 'authority.participant')[0], agent = participant === undefined ? undefined : nodes.get(participant);
92
+ if (node.band !== 100 || agent?.discriminator !== 'agent' || agent.band !== 100)
93
+ continue;
94
+ const says = statedText(agent, 'meaning.says');
95
+ mandates.push({
96
+ identity: node.identity,
97
+ participant: agent.identity,
98
+ ...(stated(node, 'authority.moves') ? { moves: textsAt(node, 'authority.moves').filter(isMove) } : {}),
99
+ scope: refsAt(node, 'authority.scope'),
100
+ ...(stated(node, 'authority.excluded-words') ? { excludedWords: textsAt(node, 'authority.excluded-words') } : {}),
101
+ ...(stated(node, 'authority.covers') ? { covers: textsAt(node, 'authority.covers') } : {}),
102
+ });
103
+ agents.set(agent.identity, { identity: agent.identity, ...(says === undefined ? {} : { says }) });
104
+ }
105
+ mandates.sort((a, b) => order(a.identity, b.identity));
106
+ const participants = [...agents.values()].sort((a, b) => order(a.identity, b.identity));
107
+ // System pointer lines (B4): one per `composition.systems` reference of the seat, by identity.
108
+ const systems = (seat === undefined ? [] : refsAt(seat, 'composition.systems'))
109
+ .map((identity) => {
110
+ const node = nodes.get(identity);
111
+ if (node === undefined)
112
+ return { identity, words: UNRESOLVED, steward: UNRESOLVED };
113
+ const steward = targetsOf(identity, 'head.steward')[0];
114
+ return {
115
+ identity,
116
+ words: [...new Set(loweringsOf(node).map((row) => row.word))].sort(order),
117
+ band: node.band,
118
+ ...(steward === undefined ? {} : { steward }),
119
+ reach: `ia position --seat ${identity}`,
120
+ };
121
+ })
122
+ .sort((a, b) => order(a.identity, b.identity));
123
+ const steward = seat === undefined ? undefined : refsAt(seat, 'composition.steward')[0];
124
+ // Captured-record tallies, per word: the band-100 capture members (db D02a) under the seat's own declared roots, as
125
+ // position composes a workspace seat's (R15). A seat that declares no root has none, which body(K0)'s `sources`
126
+ // unknown says; its fallback closure is what position may enter, not what the workspace captures.
127
+ const roots = handle.roots(read), own = new Set(roots.filter((r) => r.workspace === seatId).map((r) => r.root));
128
+ const counts = new Map();
129
+ for (const row of snapshot.membership) {
130
+ const node = nodes.get(row.identity);
131
+ if (node?.band !== 100 || !own.has(row.root))
132
+ continue;
133
+ counts.set(node.discriminator, (counts.get(node.discriminator) ?? 0) + 1);
134
+ }
135
+ const tallies = [...counts].map(([word, count]) => ({ word, count })).sort((a, b) => order(a.word, b.word));
136
+ // The intent table: the five shapes, each with the registered words it seeds, read from the floor's two
137
+ // registrations and the admitted @system records' lowering rows (the first by identity, should two lower one word).
138
+ const registered = new Set(handle.words(read)), lowered = new Map(FLOOR_REGISTRATIONS.map((r) => [r.keyword, { word: r.keyword, kind: r.kind, facets: r.facets }]));
139
+ for (const node of [...records].sort((a, b) => order(a.identity, b.identity)))
140
+ if (node.discriminator === 'system')
141
+ for (const row of loweringsOf(node))
142
+ if (!lowered.has(row.word))
143
+ lowered.set(row.word, row);
144
+ const words = [...lowered.values()].filter((row) => registered.has(row.word)).sort((a, b) => order(a.word, b.word));
145
+ const intents = SHAPES.map((shape) => {
146
+ const row = SHAPE_ROWS[shape], kinds = row.kinds, lanes = row.lanes;
147
+ return {
148
+ shape,
149
+ category: row.category,
150
+ primitive: row.primitive,
151
+ phase: PRIMITIVE_ANCHORS[row.primitive],
152
+ // Copies: the packet is frozen whole, and the kernel's rows are not this packet's to freeze.
153
+ kinds: [...kinds],
154
+ lanes: [...lanes],
155
+ predicates: [...row.predicates],
156
+ priming: [...row.priming],
157
+ words: words
158
+ .filter(({ kind, facets }) => kinds.includes(kind) ||
159
+ (facets.length > 0 ? facets : ['']).some((facet) => lanes.includes(laneOf({ kind, facet }))))
160
+ .map(({ word }) => word),
161
+ };
162
+ });
163
+ const phases = PHASES.map((phase) => ({
164
+ phase,
165
+ primitives: PRIMITIVES.filter((primitive) => PRIMITIVE_ANCHORS[primitive] === phase),
166
+ changes: PHASE_CHANGES,
167
+ }));
168
+ const packet = {
169
+ format: 'ia.position-packet.v1',
170
+ revision: body.revision,
171
+ body: k0.digest,
172
+ seat: {
173
+ ...(seatId === undefined ? {} : { identity: seatId }),
174
+ sources: seat === undefined ? [] : textsAt(seat, 'composition.sources'),
175
+ systems: systems.length,
176
+ ...(steward === undefined ? {} : { steward }),
177
+ ...(participants.length === 0 ? { participants: NO_PARTICIPANT } : {}),
178
+ },
179
+ participants,
180
+ mandates,
181
+ systems,
182
+ tallies,
183
+ intents,
184
+ phases,
185
+ commands: catalog.map(({ command, mode, move, refuses, next }) => ({ command, mode, move, refuses, next })),
186
+ lines: [...LINES],
187
+ provenance: { revision: body.revision, ...(seat === undefined ? {} : { slug: seat.name }) },
188
+ };
189
+ return freeze({ packet, digest: digest(packet), hostNote: { ...k0.hostNote, installed: INSTALLED } });
190
+ }
191
+ /**
192
+ * B1: the packet's entries, design §4's formula. P participants + M mandates + 1 seat + N system lines + T tallies + 5
193
+ * intent rows + 4 phase rows + C catalog rows + 1 provenance + 3 SPEC lines; the host note is no entry.
194
+ */
195
+ export function entryCount(packet) {
196
+ return (packet.participants.length +
197
+ packet.mandates.length +
198
+ 1 +
199
+ packet.systems.length +
200
+ packet.tallies.length +
201
+ packet.intents.length +
202
+ packet.phases.length +
203
+ packet.commands.length +
204
+ 1 +
205
+ packet.lines.length);
206
+ }
207
+ //# sourceMappingURL=packet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packet.js","sourceRoot":"","sources":["../src/packet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,MAAM,EACN,iBAAiB,EACjB,UAAU,EACV,MAAM,EACN,UAAU,EACV,MAAM,GACP,MAAM,sBAAsB,CAAC;AAc9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA8IpC,MAAM,cAAc,GAAG,6CAAsD,CAAC;AAC9E,MAAM,UAAU,GAAG,YAAqB,CAAC;AACzC,MAAM,SAAS,GAAG,gCAAyC,CAAC;AAC5D,MAAM,aAAa,GACjB,gIAAgI,CAAC;AACnI,2GAA2G;AAC3G,MAAM,KAAK,GAAsB;IAC/B,0DAA0D;IAC1D,qHAAqH;IACrH,0IAA0I;CAC3I,CAAC;AACF,MAAM,MAAM,GAAG,sBAAsB,CAAC;AACtC,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAQ7E,iFAAiF;AACjF,SAAS,QAAQ,CAAC,IAAoB,EAAE,KAAa;IAC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AE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3G,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC;QACjB,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;KAC5F,CAAC;IACF,OAAO,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;AACxG,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAsB;IAC/C,OAAO,CACL,MAAM,CAAC,YAAY,CAAC,MAAM;QAC1B,MAAM,CAAC,QAAQ,CAAC,MAAM;QACtB,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,MAAM;QACrB,MAAM,CAAC,OAAO,CAAC,MAAM;QACrB,MAAM,CAAC,OAAO,CAAC,MAAM;QACrB,MAAM,CAAC,MAAM,CAAC,MAAM;QACpB,MAAM,CAAC,QAAQ,CAAC,MAAM;QACtB,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,MAAM,CACpB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,275 @@
1
+ import type { Band, Kind, Lane, Phase, Predicate } from '@inventarch/language';
2
+ import type { ClaimMatch } from '@inventarch/graph';
3
+ import type { ReadHandle } from '@inventarch/db';
4
+ import type { ResolvedScopeKey, ResolvedSeat, ScopeKey } from './scope-key.js';
5
+ /**
6
+ * The position body: body(K), position-and-projection §1, §6 (bound, order keys, quantification) and §7 (traversal),
7
+ * design item 10; decision scope-key-caps. `position` returns it with its digest and the host note (design §1 and item
8
+ * 11, R16).
9
+ *
10
+ * One scope key, resolved through one scope token, gives one body: the seat, the composition one level from it at cost
11
+ * 0, the seeds the shape's kind or lane focus picks from it, the records reached by hops along the shape's predicate
12
+ * focus, the blocking governance reserved outside the budget, the loaded set cut at the budget, the pointers and their
13
+ * tallies, the rules and playbooks that apply by word to the loaded and reserved records and their playbooks' cells
14
+ * (R17), the mandates that govern the seat, the frontier one hop past the loaded set, the unknowns, the counts and the
15
+ * two widening keys.
16
+ * It is a pure function of the key and the admitted records the token reads, and only a whole-workspace token (db PT5)
17
+ * also reads the admission findings it alone may disclose: no root path, token, time, request text or capture state
18
+ * enters it, and nothing is written. Record bodies are never in it, only the cells delivered; `ia read` fetches a body
19
+ * on demand. A record at runtime placement (band 0) is never entered, listed, tallied or reached through (design §4,
20
+ * excluded; decision evidence-placement: runtime-band evidence is admitted below authored and must not move what agents
21
+ * are given). The revision, the database's seat and root decisions and admission's findings still read every placement
22
+ * (R15, R16).
23
+ */
24
+ /** One way an entry was first reached: a row, a field reference, or one of the composition classes of design §7. */
25
+ export type PositionVia =
26
+ /** One directed-view edge row read from `from`'s side, as the record that states it spelled it (G06b). */
27
+ {
28
+ readonly by: 'row';
29
+ readonly from: string;
30
+ readonly predicate: Predicate;
31
+ readonly spelling: string;
32
+ readonly declaredBy: 'source' | 'target';
33
+ }
34
+ /** A typed field reference read from `from`'s side: `out` when `from` holds `field`, `in` when the entry does. */
35
+ | {
36
+ readonly by: 'field';
37
+ readonly from: string;
38
+ readonly field: string;
39
+ readonly direction: 'out' | 'in';
40
+ }
41
+ /** Capture membership at a workspace seat: the entry was captured under `root`, which the workspace declares. */
42
+ | {
43
+ readonly by: 'membership';
44
+ readonly root: string;
45
+ }
46
+ /** Word membership at a @system seat: `system` registers the entry's word. */
47
+ | {
48
+ readonly by: 'word';
49
+ readonly system: string;
50
+ }
51
+ /** A claimant of a location seat, with each of its selections that selects the path (graph G06c). */
52
+ | {
53
+ readonly by: 'claim';
54
+ readonly matches: readonly ClaimMatch[];
55
+ }
56
+ /** The record a location seat is declared at, and the rule that declares it (db D02b). */
57
+ | {
58
+ readonly by: 'declared-at';
59
+ readonly rule: 'system' | 'root' | 'repository';
60
+ }
61
+ /**
62
+ * A field match of design row 18, not a row: the entry's `subject.subject-word` names the word, or its
63
+ * `subject.subject-kind` the kind, of a record. It costs no hop and claims no relation or consent (R17).
64
+ */
65
+ | {
66
+ readonly by: 'subject';
67
+ readonly label: 'field match, not a row';
68
+ readonly matches: readonly SubjectMatch[];
69
+ };
70
+ /** One subject field a rule or playbook states that the word or kind of a record answers (design row 18, R17). */
71
+ export interface SubjectMatch {
72
+ readonly field: 'subject.subject-word' | 'subject.subject-kind';
73
+ /** The word or kind the field states. */
74
+ readonly value: string;
75
+ /**
76
+ * The first record of that word or kind: in `loaded` order, then `rules` order, for an applies-by-word entry, and
77
+ * among the candidates, the seat first and then by identity, for a rule reserved by word.
78
+ */
79
+ readonly record: string;
80
+ }
81
+ /** The pointer 9-tuple of design §7: (id, word, kind, lane, owner system, steward, band, hop, reaching row/field). */
82
+ export interface PositionRecord {
83
+ readonly identity: string;
84
+ readonly word: string;
85
+ readonly kind: Kind;
86
+ readonly lane: Lane;
87
+ /** The owner system, the system that registers the record's word. */
88
+ readonly system: string;
89
+ /** The `head.steward` of the owner system's @system record, when the scope admits that record and it names one. */
90
+ readonly steward?: string;
91
+ readonly band: Band;
92
+ /**
93
+ * 0 for the seat, the seeds, a composition record no hop reaches, a mandate and a field match; else the hop that
94
+ * first reached it (a composition record a hop reaches included), or for a pointer read from a loaded record, that
95
+ * record's hop.
96
+ */
97
+ readonly hop: number;
98
+ /** Absent for the seat; the first row that reached a hop-reached record, else its composition class. */
99
+ readonly via?: PositionVia;
100
+ }
101
+ /** A loaded or reserved record: the tuple and the per-record digest (graph G13) of the occurrence the scope admits. */
102
+ export interface LoadedRecord extends PositionRecord {
103
+ readonly digest: string;
104
+ }
105
+ /** The loaded entry of a seat that is no record: a location, or a workspace seat no record declares (`''`). */
106
+ export interface LoadedPlace {
107
+ readonly path: string;
108
+ }
109
+ export type LoadedEntry = LoadedRecord | LoadedPlace;
110
+ export interface PositionPointer extends PositionRecord {
111
+ readonly via: PositionVia;
112
+ /** For a record outside the seat's closure, never entered: the @workspace whose declared root holds it, if any. */
113
+ readonly workspace?: string;
114
+ }
115
+ /** The pointers past the listed ones, per (word, owner system). */
116
+ export interface PointerTally {
117
+ readonly system: string;
118
+ readonly word: string;
119
+ readonly steward?: string;
120
+ readonly count: number;
121
+ }
122
+ /**
123
+ * An applies-by-word entry (design row 18, plan amendment A4): a @law, @convention, @principle or @playbook whose
124
+ * subject names the word or kind of a loaded record or of a blocking candidate reserved in `rules`. It is a field
125
+ * match, listed whether or not the record is also loaded or a pointer, and carries the key that seats at it.
126
+ */
127
+ export interface AppliesByWord extends PositionRecord {
128
+ readonly via: Extract<PositionVia, {
129
+ readonly by: 'subject';
130
+ }>;
131
+ /** (x, H, P, 1, 16, no word): the re-seat key of design §7 at this entry. */
132
+ readonly reseat: ScopeKey;
133
+ }
134
+ /**
135
+ * A playbook's cell at (P, primitive(H)) (design row 19): the text of its cells at that address, as `ia read
136
+ * <address>` reads it, or, when it has none there, the nearest phase whose cells include that primitive's.
137
+ */
138
+ export type PositionCell = {
139
+ readonly playbook: string;
140
+ /** `<identity>#<phase>/<Primitive>`. */
141
+ readonly address: string;
142
+ readonly text: string;
143
+ } | {
144
+ readonly playbook: string;
145
+ /** The address that has no cell. */
146
+ readonly missing: string;
147
+ /**
148
+ * The nearest phase in the cycle orient, plan, act, learn with a cell of the primitive, a tie going to the phase
149
+ * that order lists first (from learn, orient before act).
150
+ */
151
+ readonly nearest?: Phase;
152
+ readonly message: string;
153
+ };
154
+ /** The frontier, per (owner system, kind): records one hop past the loaded set, never entered. */
155
+ export interface FrontierTally {
156
+ readonly system: string;
157
+ readonly kind: Kind;
158
+ readonly steward?: string;
159
+ readonly count: number;
160
+ }
161
+ export interface PositionUnknown {
162
+ /**
163
+ * `seat`: the seat's own unknown, or a location no record claims; `sources`: the seat's workspace declares no root,
164
+ * or no workspace holds the seat; `finding`: an admission finding on a loaded record; `unread`: a narrowed scope,
165
+ * which reads no admission finding.
166
+ */
167
+ readonly kind: 'seat' | 'sources' | 'finding' | 'unread';
168
+ /** The record, workspace or path it is about. */
169
+ readonly subject?: string;
170
+ readonly code?: string;
171
+ readonly path?: string;
172
+ readonly line?: number;
173
+ readonly message: string;
174
+ }
175
+ export interface PositionCounts {
176
+ /** |C0|: the composition inside the seat's closure, after the word filter. */
177
+ readonly composition: number;
178
+ /** |Σ|, the seat included. */
179
+ readonly seeds: number;
180
+ /** |L|, the seat included. */
181
+ readonly loaded: number;
182
+ readonly rules: number;
183
+ /** Every pointer, listed or tallied. */
184
+ readonly pointers: number;
185
+ /** |A|: every applies-by-word entry, listed or tallied. */
186
+ readonly appliesByWord: number;
187
+ readonly frontier: number;
188
+ /** Seeds and reached records the budget left out of `loaded`; each is a pointer. */
189
+ readonly truncatedLoaded: number;
190
+ /** Pointers past the first 48, counted in the tallies. */
191
+ readonly truncatedPointers: number;
192
+ /** Applies-by-word entries past the first 48, counted in their tallies. */
193
+ readonly truncatedAppliesByWord: number;
194
+ }
195
+ export interface PositionWidening {
196
+ /** (S, H, P, d + 1, n, w); absent at the depth cap. */
197
+ readonly deeper?: ScopeKey;
198
+ /** (x, H, P, 1, 16, no word): seat it at any pointer x; with no seat it is the repository's workspace. */
199
+ readonly reseat: Pick<ScopeKey, 'shape' | 'phase' | 'depth' | 'budget'>;
200
+ }
201
+ export interface PositionBody {
202
+ readonly format: 'ia.position-body.v1';
203
+ /** The revision of the view the scope reads. */
204
+ readonly revision: string;
205
+ readonly key: ScopeKey;
206
+ readonly seat: ResolvedSeat;
207
+ /** The seat first, then the first n of the other seeds and the reached records, in the shape's order, of w only. */
208
+ readonly loaded: readonly LoadedEntry[];
209
+ /**
210
+ * The blocking governance candidates, and the blocking rules that apply by word to a candidate (R17), reserved
211
+ * outside the budget, in the governance order: the candidates of the walk without the word, so w hides none.
212
+ */
213
+ readonly rules: readonly LoadedRecord[];
214
+ /** The first 48 pointers in the shape's order, of w only. */
215
+ readonly pointers: readonly PositionPointer[];
216
+ readonly pointerTallies: readonly PointerTally[];
217
+ /**
218
+ * The first 48 rules and playbooks outside `rules` that apply by word to a loaded record or a blocking candidate in
219
+ * `rules`, by band ↓, identity ↑, of any word whatever w is.
220
+ */
221
+ readonly appliesByWord: readonly AppliesByWord[];
222
+ /** The applies-by-word entries past the listed ones, per (word, owner system). */
223
+ readonly appliesByWordTallies: readonly PointerTally[];
224
+ /** The cells at (P, primitive(H)) of the first four playbooks that apply by word. */
225
+ readonly cells: readonly PositionCell[];
226
+ /**
227
+ * The @mandate records that claim a location seat or whose `authority.scope` names the seat's workspace, whatever w
228
+ * is.
229
+ */
230
+ readonly mandates: readonly PositionPointer[];
231
+ readonly frontier: readonly FrontierTally[];
232
+ readonly unknowns: readonly PositionUnknown[];
233
+ readonly counts: PositionCounts;
234
+ readonly widening: PositionWidening;
235
+ }
236
+ /** The host note's freshness: the capture `ia capture` last wrote against the revision the handle reads. */
237
+ export type Freshness = 'current' | 'stale' | 'no-capture';
238
+ /**
239
+ * The host note (design §1): host state printed beside the body, never digested and never claimed identical across
240
+ * hosts or working trees. Installed state is not reported before receipts exist (milestone position-packet).
241
+ */
242
+ export interface HostNote {
243
+ /** The revision of the handle's root view, which a capture is compared with. */
244
+ readonly revision: string;
245
+ /** The revision of the capture at `.ia/work/snapshot/current.json` (db D08a), when there is one. */
246
+ readonly capturedRevision?: string;
247
+ /** The revision of the previous root snapshot the handle retains (db D08), when it retains one. */
248
+ readonly previousRevision?: string;
249
+ /** `current` when the capture is at `revision`, `stale` when it is at another, `no-capture` when there is none. */
250
+ readonly freshness: Freshness;
251
+ /** The key used: the partial key completed by normalizeScopeKey, a location as the caller spelled it. */
252
+ readonly key: ScopeKey;
253
+ }
254
+ /** The two outputs of a position (design §1), always printed together and never merged. */
255
+ export interface PositionOutput {
256
+ readonly body: PositionBody;
257
+ /** Graph's codec digest of `body`, its canonical JSON text's SHA-256. */
258
+ readonly digest: string;
259
+ readonly hostNote: HostNote;
260
+ }
261
+ /**
262
+ * R16: the position of the partial key `partial` through the scope token `within`: body(K) for the key normalizeScopeKey
263
+ * completes and resolveScopeKey resolves, its digest, and the host note. The key's parts are closed, so request text or
264
+ * a token in it is refused as an unknown part, and nothing text-driven runs; the body reads no capture, and the note
265
+ * reads the handle's capture pair, so writing a capture moves only the note. Refusals are those of the three steps.
266
+ */
267
+ export declare function position(handle: ReadHandle, within: string, partial?: Partial<ScopeKey>): PositionOutput;
268
+ /**
269
+ * R15: body(K) for the key `resolved` that resolveScopeKey returned for the same scope token `within`. Every read goes
270
+ * through `within`, and admission findings are read only on a whole-workspace one (db PT5). A missing token, or a seat
271
+ * at runtime placement, is IA-RUNTIME-REQUEST-INVALID, and an unknown, stale or closed token keeps its database code.
272
+ * R17 adds the sections that apply by word, their cells and the mandates, and reserves blocking rules by word too.
273
+ */
274
+ export declare function positionBody(handle: ReadHandle, within: string, resolved: ResolvedScopeKey): PositionBody;
275
+ //# sourceMappingURL=position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../src/position.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAsC,MAAM,mBAAmB,CAAC;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/E;;;;;;;;;;;;;;;;;;GAkBG;AAEH,oHAAoH;AACpH,MAAM,MAAM,WAAW;AACrB,0GAA0G;AACxG;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC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