aontu 0.53.0 → 0.55.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 (197) hide show
  1. package/dist/aontu.d.ts +3 -2
  2. package/dist/aontu.js +36 -7
  3. package/dist/aontu.js.map +1 -1
  4. package/dist/cli.d.ts +2 -1
  5. package/dist/cli.js +500 -8
  6. package/dist/cli.js.map +1 -1
  7. package/dist/ctx.d.ts +5 -0
  8. package/dist/ctx.js +1 -0
  9. package/dist/ctx.js.map +1 -1
  10. package/dist/diff.js.map +1 -1
  11. package/dist/err.js +7 -1
  12. package/dist/err.js.map +1 -1
  13. package/dist/graph.d.ts +2 -5
  14. package/dist/graph.js +83 -46
  15. package/dist/graph.js.map +1 -1
  16. package/dist/hcanon.js +9 -10
  17. package/dist/hcanon.js.map +1 -1
  18. package/dist/hints.js +94 -26
  19. package/dist/hints.js.map +1 -1
  20. package/dist/jsonschema.js +34 -0
  21. package/dist/jsonschema.js.map +1 -1
  22. package/dist/lang.js +593 -191
  23. package/dist/lang.js.map +1 -1
  24. package/dist/lsp.d.ts +1 -1
  25. package/dist/lsp.js +86 -6
  26. package/dist/lsp.js.map +1 -1
  27. package/dist/mcp.js +153 -6
  28. package/dist/mcp.js.map +1 -1
  29. package/dist/mod-tool.js +42 -8
  30. package/dist/mod-tool.js.map +1 -1
  31. package/dist/mod.d.ts +4 -0
  32. package/dist/mod.js +97 -2
  33. package/dist/mod.js.map +1 -1
  34. package/dist/patch.d.ts +5 -0
  35. package/dist/patch.js +25 -25
  36. package/dist/patch.js.map +1 -1
  37. package/dist/provenance.d.ts +1 -0
  38. package/dist/provenance.js +2 -1
  39. package/dist/provenance.js.map +1 -1
  40. package/dist/query.js.map +1 -1
  41. package/dist/reach.d.ts +1 -0
  42. package/dist/reach.js +49 -21
  43. package/dist/reach.js.map +1 -1
  44. package/dist/relation.d.ts +4 -0
  45. package/dist/relation.js +125 -200
  46. package/dist/relation.js.map +1 -1
  47. package/dist/sig.d.ts +25 -0
  48. package/dist/sig.js +277 -0
  49. package/dist/sig.js.map +1 -0
  50. package/dist/sigdecl.d.ts +2 -0
  51. package/dist/sigdecl.js +11 -0
  52. package/dist/sigdecl.js.map +1 -0
  53. package/dist/siggate.d.ts +4 -0
  54. package/dist/siggate.js +90 -0
  55. package/dist/siggate.js.map +1 -0
  56. package/dist/std.js +75 -16
  57. package/dist/std.js.map +1 -1
  58. package/dist/subsume.js +57 -10
  59. package/dist/subsume.js.map +1 -1
  60. package/dist/tsconfig.tsbuildinfo +1 -1
  61. package/dist/unify.d.ts +2 -2
  62. package/dist/unify.js +93 -114
  63. package/dist/unify.js.map +1 -1
  64. package/dist/utility.d.ts +1 -2
  65. package/dist/utility.js +7 -61
  66. package/dist/utility.js.map +1 -1
  67. package/dist/val/AggFuncVal.d.ts +12 -1
  68. package/dist/val/AggFuncVal.js +165 -3
  69. package/dist/val/AggFuncVal.js.map +1 -1
  70. package/dist/val/BagVal.d.ts +2 -0
  71. package/dist/val/BagVal.js +56 -8
  72. package/dist/val/BagVal.js.map +1 -1
  73. package/dist/val/ConstraintVal.js +33 -5
  74. package/dist/val/ConstraintVal.js.map +1 -1
  75. package/dist/val/ContainerKindVal.d.ts +35 -0
  76. package/dist/val/ContainerKindVal.js +99 -0
  77. package/dist/val/ContainerKindVal.js.map +1 -0
  78. package/dist/val/CopyFuncVal.js +0 -7
  79. package/dist/val/CopyFuncVal.js.map +1 -1
  80. package/dist/val/DisjunctVal.d.ts +1 -2
  81. package/dist/val/DisjunctVal.js +146 -39
  82. package/dist/val/DisjunctVal.js.map +1 -1
  83. package/dist/val/ExpectVal.js +37 -2
  84. package/dist/val/ExpectVal.js.map +1 -1
  85. package/dist/val/FuncBaseVal.d.ts +1 -0
  86. package/dist/val/FuncBaseVal.js +19 -8
  87. package/dist/val/FuncBaseVal.js.map +1 -1
  88. package/dist/val/GraphAtomVal.d.ts +39 -0
  89. package/dist/val/GraphAtomVal.js +184 -0
  90. package/dist/val/GraphAtomVal.js.map +1 -0
  91. package/dist/val/JunctionVal.js +22 -5
  92. package/dist/val/JunctionVal.js.map +1 -1
  93. package/dist/val/ListVal.js +27 -34
  94. package/dist/val/ListVal.js.map +1 -1
  95. package/dist/val/MapVal.d.ts +1 -0
  96. package/dist/val/MapVal.js +82 -35
  97. package/dist/val/MapVal.js.map +1 -1
  98. package/dist/val/PathFuncVal.d.ts +2 -2
  99. package/dist/val/PathFuncVal.js +75 -16
  100. package/dist/val/PathFuncVal.js.map +1 -1
  101. package/dist/val/PathVal.d.ts +25 -0
  102. package/dist/val/PathVal.js +150 -0
  103. package/dist/val/PathVal.js.map +1 -0
  104. package/dist/val/PlusOpVal.d.ts +2 -1
  105. package/dist/val/PlusOpVal.js +50 -35
  106. package/dist/val/PlusOpVal.js.map +1 -1
  107. package/dist/val/PrefVal.d.ts +2 -0
  108. package/dist/val/PrefVal.js +159 -32
  109. package/dist/val/PrefVal.js.map +1 -1
  110. package/dist/val/RecurseVal.d.ts +19 -0
  111. package/dist/val/RecurseVal.js +217 -0
  112. package/dist/val/RecurseVal.js.map +1 -0
  113. package/dist/val/RefVal.d.ts +2 -1
  114. package/dist/val/RefVal.js +105 -72
  115. package/dist/val/RefVal.js.map +1 -1
  116. package/dist/val/ReferFuncVal.d.ts +30 -7
  117. package/dist/val/ReferFuncVal.js +395 -94
  118. package/dist/val/ReferFuncVal.js.map +1 -1
  119. package/dist/val/ScalarKindVal.d.ts +4 -2
  120. package/dist/val/ScalarKindVal.js +12 -1
  121. package/dist/val/ScalarKindVal.js.map +1 -1
  122. package/dist/val/SuperFuncVal.d.ts +4 -2
  123. package/dist/val/SuperFuncVal.js +118 -14
  124. package/dist/val/SuperFuncVal.js.map +1 -1
  125. package/dist/val/TopVal.d.ts +1 -1
  126. package/dist/val/Val.d.ts +2 -3
  127. package/dist/val/Val.js +39 -20
  128. package/dist/val/Val.js.map +1 -1
  129. package/dist/val/arith.js +4 -1
  130. package/dist/val/arith.js.map +1 -1
  131. package/dist/vet.d.ts +1 -0
  132. package/dist/vet.js +32 -1
  133. package/dist/vet.js.map +1 -1
  134. package/dist/view.d.ts +90 -0
  135. package/dist/view.js +2168 -0
  136. package/dist/view.js.map +1 -0
  137. package/grammar/aontu.gbnf +18 -10
  138. package/grammar/aontu.lark +15 -10
  139. package/grammar/aontu.tmLanguage.json +184 -0
  140. package/package.json +10 -3
  141. package/skill/grammar-card.md +1 -2
  142. package/src/aontu.ts +37 -7
  143. package/src/cli.ts +553 -8
  144. package/src/ctx.ts +20 -0
  145. package/src/diff.ts +4 -2
  146. package/src/err.ts +8 -1
  147. package/src/graph.ts +125 -75
  148. package/src/hcanon.ts +9 -11
  149. package/src/hints.ts +112 -29
  150. package/src/jsonschema.ts +41 -0
  151. package/src/lang.ts +642 -203
  152. package/src/lsp.ts +75 -6
  153. package/src/mcp.ts +164 -6
  154. package/src/mod-tool.ts +48 -9
  155. package/src/mod.ts +110 -1
  156. package/src/patch.ts +31 -27
  157. package/src/provenance.ts +8 -1
  158. package/src/query.ts +4 -2
  159. package/src/reach.ts +52 -23
  160. package/src/relation.ts +139 -236
  161. package/src/sig.ts +345 -0
  162. package/src/sigdecl.ts +11 -0
  163. package/src/siggate.ts +144 -0
  164. package/src/std.ts +77 -16
  165. package/src/subsume.ts +59 -10
  166. package/src/unify.ts +102 -125
  167. package/src/utility.ts +7 -67
  168. package/src/val/AggFuncVal.ts +231 -4
  169. package/src/val/BagVal.ts +58 -9
  170. package/src/val/ConstraintVal.ts +34 -5
  171. package/src/val/ContainerKindVal.ts +158 -0
  172. package/src/val/CopyFuncVal.ts +0 -7
  173. package/src/val/DisjunctVal.ts +152 -40
  174. package/src/val/ExpectVal.ts +39 -4
  175. package/src/val/FuncBaseVal.ts +21 -8
  176. package/src/val/GraphAtomVal.ts +264 -0
  177. package/src/val/JunctionVal.ts +23 -6
  178. package/src/val/ListVal.ts +30 -37
  179. package/src/val/MapVal.ts +87 -39
  180. package/src/val/PathFuncVal.ts +107 -19
  181. package/src/val/PathVal.ts +221 -0
  182. package/src/val/PlusOpVal.ts +56 -37
  183. package/src/val/PrefVal.ts +186 -38
  184. package/src/val/RecurseVal.ts +285 -0
  185. package/src/val/RefVal.ts +105 -83
  186. package/src/val/ReferFuncVal.ts +445 -100
  187. package/src/val/ScalarKindVal.ts +12 -0
  188. package/src/val/SuperFuncVal.ts +137 -13
  189. package/src/val/TopVal.ts +1 -1
  190. package/src/val/Val.ts +44 -35
  191. package/src/val/arith.ts +4 -1
  192. package/src/vet.ts +41 -4
  193. package/src/view.ts +2882 -0
  194. package/dist/val/IdFuncVal.d.ts +0 -13
  195. package/dist/val/IdFuncVal.js +0 -54
  196. package/dist/val/IdFuncVal.js.map +0 -1
  197. package/src/val/IdFuncVal.ts +0 -91
@@ -1,53 +1,50 @@
1
1
  "use strict";
2
2
  /* Copyright (c) 2025 Richard Rodger, MIT License */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ReferVal = exports.ReferFuncVal = void 0;
5
- exports.parseAddress = parseAddress;
6
- exports.findEntity = findEntity;
4
+ exports.RelVal = exports.RelFuncVal = exports.ReferVal = exports.ReferFuncVal = void 0;
5
+ exports.addressPath = addressPath;
6
+ exports.findAt = findAt;
7
7
  const type_1 = require("../type");
8
8
  const err_1 = require("../err");
9
9
  const FuncBaseVal_1 = require("./FuncBaseVal");
10
+ const PathVal_1 = require("./PathVal");
10
11
  const FeatureVal_1 = require("./FeatureVal");
11
- const StringVal_1 = require("./StringVal");
12
+ const ConjunctVal_1 = require("./ConjunctVal");
12
13
  const unify_1 = require("../unify");
13
14
  const top_1 = require("./top");
14
15
  const utility_1 = require("../utility");
15
- // A segment of the path INSIDE an entity. The entity name's own
16
- // grammar (no dots) is what makes the split unambiguous: everything
17
- // before the first dot names the entity, everything after walks its
18
- // value.
19
- const ADDR_SEGMENT = /^[A-Za-z0-9_-]+$/;
20
- const ADDR_NAME = /^[A-Za-z0-9_/-]+$/;
21
- // The address a string spells, or undefined when it does not spell
22
- // one. `svc/auth` is the entity; `svc/auth.ports.http` is a node
23
- // inside it — the two addressing schemes reconciled: `$.a.b` answers
24
- // WHERE, an address answers WHAT, and beneath entity granularity the
25
- // tree is authoritative again.
26
- function parseAddress(s) {
27
- const parts = s.split('.');
28
- if (!ADDR_NAME.test(parts[0])) {
29
- return undefined;
16
+ // A RELATION PREDICATE is still a declared D-1 name
17
+ // (docs/design/RELATIONS.0.md §3.2). Entity names are gone with
18
+ // ADR-014; predicate names are not -- a relation is a vocabulary term,
19
+ // not an address.
20
+ const PREDICATE_NAME = /^[_a-zA-Z][-_a-zA-Z0-9]*$/;
21
+ // The tree path an address resolves to from `at` -- the position of
22
+ // the link itself -- or undefined when a relative address climbs off
23
+ // the top of the tree.
24
+ function addressPath(addr, at) {
25
+ if (addr.absolute) {
26
+ return addr.parts;
30
27
  }
31
- for (const seg of parts.slice(1)) {
32
- if (!ADDR_SEGMENT.test(seg)) {
33
- return undefined;
34
- }
28
+ // The SIBLING scope: drop the link's own key, then take the parent
29
+ // steps. A link at `$.a.b.dep` spelling `.other` means `$.a.b.other`.
30
+ const cut = at.length - 1 - addr.up;
31
+ if (cut < 0) {
32
+ return undefined;
35
33
  }
36
- return { name: parts[0], path: parts.slice(1) };
34
+ return at.slice(0, cut).map(String).concat(addr.parts);
37
35
  }
38
- // The value an address names, or undefined when the evaluation does
39
- // not (yet) have one. Pending is not failure: an entity may be
40
- // declared by a later conjunct, include or spread, so `refer`
36
+ // The node a tree path names, with the parent and key that hold it so
37
+ // a type flow can be written back. Pending is not failure: the target
38
+ // may be introduced by a later conjunct, include or spread, so `refer`
41
39
  // residuates exactly as a forward reference does.
42
- function findEntity(reg, addr) {
43
- const rep = reg?.get(addr.name);
44
- if (null == rep) {
40
+ function findAt(root, path) {
41
+ if (null == root || 0 === path.length) {
45
42
  return undefined;
46
43
  }
47
44
  let parent = undefined;
48
45
  let key = undefined;
49
- let val = rep;
50
- for (const seg of addr.path) {
46
+ let val = root;
47
+ for (const seg of path) {
51
48
  if (true !== val?.isMap && true !== val?.isList) {
52
49
  return undefined;
53
50
  }
@@ -96,6 +93,16 @@ class ReferVal extends FeatureVal_1.FeatureVal {
96
93
  super(spec, ctx);
97
94
  this.isRefer = true;
98
95
  this.isGenable = true;
96
+ // AFTER the plain values (base 99999), BEFORE the sizing atoms
97
+ // (LATE_CJO): sibling path values fold together first under the
98
+ // prefix rule, and the residual then meets ONE merged address --
99
+ // without this, `refer() & path($.a) & path($.a.b)` settled on the
100
+ // first path and the second met the finished link too late.
101
+ this.cjo = 120000;
102
+ // The codes this residual refuses with: refer() keeps its own,
103
+ // rel()-minted residuals carry rel_address/rel_unresolved.
104
+ this.addrcode = 'refer_address';
105
+ this.unresolvedcode = 'refer_unresolved';
99
106
  this.tval = spec.tval ?? (0, top_1.top)();
100
107
  this.addr = spec.addr;
101
108
  this.addrsrc = spec.addrsrc;
@@ -106,7 +113,7 @@ class ReferVal extends FeatureVal_1.FeatureVal {
106
113
  // met, the constraints it holds — TRAVELS with the clone. A spread
107
114
  // template holds the FUNCTION, so a template never needs this; a
108
115
  // REFERENCE to a value that already contains a resolved link does
109
- // (`z: id(a) & {u: refer() & "a"}` then `s: $.z`). Without it the
116
+ // (`z: {u: refer() & "$.a"}` then `s: $.z`). Without it the
110
117
  // clone came back as a bare `refer()` — the address silently
111
118
  // dropped, and the copied link resolving to nothing.
112
119
  //
@@ -118,6 +125,9 @@ class ReferVal extends FeatureVal_1.FeatureVal {
118
125
  out.addr = this.addr;
119
126
  out.addrsrc = this.addrsrc;
120
127
  out.held = this.held;
128
+ out.relkey = this.relkey;
129
+ out.addrcode = this.addrcode;
130
+ out.unresolvedcode = this.unresolvedcode;
121
131
  return out;
122
132
  }
123
133
  unify(peer, ctx) {
@@ -140,31 +150,43 @@ class ReferVal extends FeatureVal_1.FeatureVal {
140
150
  if (true === p.isNil) {
141
151
  return peer;
142
152
  }
143
- // A STRING is the ADDRESS, when there is not one yet. It is the
144
- // only thing that can be: a link's value is its address.
145
- if (undefined === this.addr
146
- && true === p.isScalar && 'string' === typeof p.peg) {
147
- const addr = parseAddress(p.peg);
148
- if (undefined === addr) {
149
- return (0, err_1.makeNilErr)(ctx, 'refer_address', this, peer, 'refer', { addr: p.peg });
150
- }
153
+ // A PATH VALUE is the ADDRESS, when there is not one yet. Only a
154
+ // path value can be one (PATHS.0.md, amended): a bare string is
155
+ // never a path -- `path("...")` is the one string conversion, and
156
+ // it happens at the call, not here. The peg is pre-validated by
157
+ // the capture, so no parse can fail.
158
+ if (undefined === this.addr && true === p.isPath) {
159
+ const addr = (0, PathVal_1.parseAddress)(p.peg);
151
160
  return this.with(ctx, { addr, addrsrc: p.peg }, peer);
152
161
  }
153
- // A value that can never BE a string cannot constrain one either,
154
- // and no later pass can repair it — so this arm refuses rather
155
- // than defers. A KIND or a constraint is not in it: `string`,
156
- // `re("^svc/")` and the like are perfectly good constraints on an
157
- // address, and are held below until there is one to apply them to.
158
- if ((true === p.isScalar && 'string' !== typeof p.peg)
162
+ // A SECOND path peer refines the address by the prefix rule: the
163
+ // longer of the two when one opens the other, exactly as two path
164
+ // values meet on their own. Two incomparable addresses are the
165
+ // same conflict two unequal scalars are.
166
+ if (undefined !== this.addr && true === p.isPath) {
167
+ const merged = (0, PathVal_1.prefixMeet)(this.addrsrc, p.peg);
168
+ if (undefined === merged) {
169
+ return (0, err_1.makeNilErr)(ctx, 'scalar_value', this, peer);
170
+ }
171
+ return this.with(ctx, { addr: (0, PathVal_1.parseAddress)(merged), addrsrc: merged }, peer);
172
+ }
173
+ // A value that can never BE a path cannot be the address, and no
174
+ // later pass can repair it — so this arm refuses rather than
175
+ // defers. A bare STRING is in it now (PATHS.0.md, amended):
176
+ // `path("...")` is the one conversion, at the call. A KIND or a
177
+ // constraint is not in it: `string`, `re("^svc_")` and the like
178
+ // are perfectly good constraints on an address, and are held
179
+ // below until there is one to apply them to.
180
+ if ((true === p.isScalar && true !== p.isPath)
159
181
  || true === p.isMap || true === p.isList) {
160
- return (0, err_1.makeNilErr)(ctx, 'refer_address', this, peer, 'refer');
182
+ return (0, err_1.makeNilErr)(ctx, this.addrcode, this, peer, 'refer');
161
183
  }
162
184
  // HELD: everything else waits for the address. Carried on the
163
185
  // residual rather than parked in a conjunct, because a conjunct
164
186
  // rebuilt every pass grows a level every pass; the held constraint
165
187
  // meets the link the moment the address resolves, so
166
- // `refer() & "x" & "y"` still conflicts and `refer() & string & "x"`
167
- // still passes.
188
+ // `refer() & re("a") & re("b") & path($.z)` still applies both and
189
+ // `refer() & string & path($.z)` still passes.
168
190
  return this.with(ctx, {
169
191
  held: null == this.held ? peer : (0, unify_1.unite)(ctx, this.held, peer, 'refer-held'),
170
192
  }, this);
@@ -178,6 +200,9 @@ class ReferVal extends FeatureVal_1.FeatureVal {
178
200
  out.addr = spec.addr ?? this.addr;
179
201
  out.addrsrc = spec.addrsrc ?? this.addrsrc;
180
202
  out.held = spec.held ?? this.held;
203
+ out.relkey = this.relkey;
204
+ out.addrcode = this.addrcode;
205
+ out.unresolvedcode = this.unresolvedcode;
181
206
  (0, utility_1.propagateMarks)(this, out);
182
207
  out.site = site.site;
183
208
  out.path = this.path;
@@ -197,75 +222,134 @@ class ReferVal extends FeatureVal_1.FeatureVal {
197
222
  this.dc = 0;
198
223
  return this;
199
224
  }
200
- const reg = ctx?.entities;
201
- const found = findEntity(reg, this.addr);
225
+ // The address is a TREE PATH, resolved from the link's own
226
+ // position for a relative one. A climb off the top of the tree can
227
+ // never be repaired by a later pass, so it refuses at once.
228
+ const target = addressPath(this.addr, this.path);
229
+ if (undefined === target) {
230
+ return (0, err_1.makeNilErr)(ctx, this.unresolvedcode, this, undefined, 'refer', { addr: this.addrsrc });
231
+ }
232
+ const found = findAt(ctx?.root, target);
202
233
  if (undefined === found) {
203
- // PENDING, not failed — until the last pass. An entity may be
204
- // declared by a later conjunct, include or spread, so `refer`
234
+ // PENDING, not failed — until the last pass. The target may be
235
+ // introduced by a later conjunct, include or spread, so `refer`
205
236
  // residuates as a forward reference does; but within ONE
206
237
  // evaluation the document-set is fixed, so existence IS
207
238
  // decidable, and the final pass is where it is decided. A
208
239
  // pending refer keeps the tree not-done, so the pass loop always
209
240
  // reaches that pass when there is one to decide.
210
241
  if (ctx.cc + 1 >= ctx.budget.passes) {
211
- return (0, err_1.makeNilErr)(ctx, 'refer_unresolved', this, undefined, 'refer', { addr: this.addrsrc });
242
+ return (0, err_1.makeNilErr)(ctx, this.unresolvedcode, this, undefined, 'refer', { addr: this.addrsrc });
212
243
  }
213
244
  this.dc = 0;
214
245
  return this;
215
246
  }
216
- // THE FLOW. `t` is unified into the target and written back, so
217
- // every position of the entity carries it after the pass's
218
- // identity merge — the same channel the merge itself uses.
247
+ // THE FLOW. `t` is unified into the target and written back at the
248
+ // target's own position — one position, because the tree is the
249
+ // namespace and a path names exactly one node.
219
250
  //
220
- // RE-ENTRANT ONLY ONCE PER ENTITY (use-cases/BUGS.md §19). Uniting
251
+ // RE-ENTRANT ONLY ONCE PER TARGET (use-cases/BUGS.md §19). Uniting
221
252
  // the target drives the target's OWN subtree, and if the target
222
253
  // links back — `a` typed-refers `b`, `b` typed-refers `a`, the
223
- // shape every inverse pair has — that drives this entity again,
254
+ // shape every inverse pair has — that drives this target again,
224
255
  // and the two flow into each other until the depth budget or the
225
256
  // host stack ends it. `unify_cycle` on a model whose meet plainly
226
257
  // converges: `{k:1}` meeting `{k:1}` is a fixpoint, and the
227
258
  // evaluator never got far enough to notice.
228
259
  //
229
- // The guard is the set of entities a flow is currently inside, on
230
- // the context. A flow that would re-enter one is SKIPPED, not
231
- // failed: the outer flow it is nested in is already uniting that
232
- // entity, so the same information arrives by the same channel one
233
- // frame up. What each flow contributes is unchanged; only the
234
- // order it arrives in is, and unification does not care.
235
- const flowing = (ctx._referflow ??=
236
- new Set());
237
- if (!this.tval.isTop && !flowing.has(this.addr.name)) {
238
- flowing.add(this.addr.name);
239
- try {
240
- // The flowed type is CONCRETE at the target: a schema flowing
241
- // into a value must not make the value a schema. Same reasoning
242
- // as a reference's clone clearing marks — `refer($.std.Service)`
243
- // says the target IS a Service, not that it is the definition
244
- // of one — and without it the target silently stopped
245
- // generating.
246
- const merged = (0, unify_1.unite)(ctx, found.val, concreteFlow(ctx, this.tval), 'refer-flow');
247
- if (true === merged.isNil) {
248
- return merged;
249
- }
250
- if (undefined === found.parent) {
251
- reg.set(this.addr.name, merged);
260
+ // The guard is the set of paths a flow is currently inside, on the
261
+ // context. A flow that would re-enter one has its MEET skipped:
262
+ // the outer flow it is nested in is already uniting that node, and
263
+ // re-entering is what runs the host stack out.
264
+ //
265
+ // ITS RECORD IS STILL WRITTEN. The skip used to take the record
266
+ // with it, on the reasoning that "the same information arrives by
267
+ // the same channel one frame up" -- true of the outer flow's TYPE,
268
+ // and false of a nested flow carrying a DIFFERENT one. The outer
269
+ // flow delivers only its own type, the residual is consumed into a
270
+ // settled link in the same breath, and nothing re-offers it: the
271
+ // nested type was lost for good, and which of two flows was the
272
+ // nested one depended on which link the evaluator happened to
273
+ // reach first. A layering rule declared on one field and reached
274
+ // through another module's mirror therefore held in one
275
+ // declaration order and not in the other (BUGS.md 69).
276
+ //
277
+ // Recording it DEFERS the meet to `applyFlows`, which runs at the
278
+ // top of the tree with no flow in flight and so cannot re-enter
279
+ // anything -- the channel this record already exists to be.
280
+ const guard = target.join('.');
281
+ // Seeded on the unify root (ts/src/unify.ts): a `??=` here would
282
+ // make a fresh set on whichever descended context asked first.
283
+ const flowing = ctx._referflow ?? new Set();
284
+ if (!this.tval.isTop) {
285
+ // The flowed type is CONCRETE at the target: a schema flowing
286
+ // into a value must not make the value a schema. Same reasoning
287
+ // as a reference's clone clearing marks — `refer($.std.Service)`
288
+ // says the target IS a Service, not that it is the definition
289
+ // of one — and without it the target silently stopped
290
+ // generating.
291
+ const flow = concreteFlow(ctx, this.tval);
292
+ // THE RECORD, keyed by the target's path, replayed onto every
293
+ // later pass by applyFlows in ts/src/unify.ts. A pass rebuilds
294
+ // subtrees, so the write below does not survive one when the
295
+ // link sits inside its own target or two nodes link at each
296
+ // other; the record is what makes the flow reach the result
297
+ // rather than the tree it was computed from.
298
+ const flows = ctx.referflows ??
299
+ new Map();
300
+ const key = target.join('\x00');
301
+ const prev = flows.get(key);
302
+ flows.set(key, null == prev ? flow : (0, unify_1.unite)(ctx, prev, flow, 'refer-flow-record'));
303
+ if (!flowing.has(guard)) {
304
+ flowing.add(guard);
305
+ try {
306
+ const merged = (0, unify_1.unite)(ctx, found.val, flow, 'refer-flow');
307
+ if (true === merged.isNil) {
308
+ return merged;
309
+ }
310
+ // The write into THIS pass's view, so the rest of the pass
311
+ // sees it. findAt refuses the empty path, so a resolved
312
+ // target always has a parent holding it.
313
+ //
314
+ // NOT FROM INSIDE A TRIAL. A disjunction member is a
315
+ // HYPOTHESIS, and writing its flow into the live tree
316
+ // asserts the member's type on another node before the
317
+ // member is known to survive. The `unite` above still runs:
318
+ // its nil is how a member legitimately fails. Only the
319
+ // COMMIT waits, and the surviving member's flow reaches the
320
+ // tree on the next pass, from the record DisjunctVal stages
321
+ // and merges for survivors alone.
322
+ if (true !== ctx._trialMode) {
323
+ found.parent.peg[found.key] = merged;
324
+ }
252
325
  }
253
- else {
254
- found.parent.peg[found.key] = merged;
326
+ finally {
327
+ flowing.delete(guard);
255
328
  }
256
329
  }
257
- finally {
258
- flowing.delete(this.addr.name);
259
- }
260
330
  }
261
- // The value IS the address string: a link, not an embedding.
262
- const out = new StringVal_1.StringVal({ peg: this.addrsrc }, ctx);
331
+ // The value IS the address, as a PATH VALUE (ADR-016): a link,
332
+ // not an embedding -- and re-stating or refining the address
333
+ // still meets it, which a string link could not do under the
334
+ // strict rules.
335
+ const out = new PathVal_1.PathVal({ peg: this.addrsrc }, ctx);
263
336
  out.dc = type_1.DONE;
264
337
  // STAMPED as a link (G4 phase 3): the value is the address string,
265
338
  // so without this nothing downstream could tell a checked link from
266
339
  // a literal that happens to look like one. The edge set is exactly
267
- // the set of these stamps.
268
- out.link = this.addrsrc;
340
+ // the set of these stamps. A rel()-minted link also carries its
341
+ // PREDICATE (the rel field's key), so the graph reports a declared
342
+ // relation rather than inferring one from the path.
343
+ //
344
+ // The stamp is the RESOLVED path, not the written one: a relative
345
+ // address means a different node from each position it is written
346
+ // at, and an edge set whose far ends were spellings rather than
347
+ // nodes could not be traversed. The VALUE stays what the author
348
+ // wrote --- the link is what it says, the edge is where it goes.
349
+ out.link = '$.' + target.join('.');
350
+ if (undefined !== this.relkey) {
351
+ out.relkey = this.relkey;
352
+ }
269
353
  (0, utility_1.propagateMarks)(this, out);
270
354
  out.site = site.site;
271
355
  out.path = this.path;
@@ -275,11 +359,228 @@ class ReferVal extends FeatureVal_1.FeatureVal {
275
359
  const t = this.tval.isTop ? '' : this.tval.canon;
276
360
  const call = 'refer(' + t + ')' +
277
361
  (null == this.held ? '' : '&' + this.held.canon);
362
+ // The address renders as the path call: a bare string address no
363
+ // longer reparses (PATHS.0.md, amended), and canon must.
278
364
  return undefined === this.addrsrc
279
- ? call : call + '&' + JSON.stringify(this.addrsrc);
365
+ ? call : call + '&path(' + this.addrsrc + ')';
280
366
  }
281
367
  }
282
368
  exports.ReferVal = ReferVal;
369
+ // RelVal is what `rel(t?)` RESOLVES to (RELATIONS.0.md §3.2): the
370
+ // relation constraint, sited on the FIELD the way the sizing atoms sit
371
+ // on containers. Its value may be one address, a LIST of addresses, or
372
+ // a MAP whose string leaves are addresses -- the container shapes are
373
+ // rewritten leaf by leaf through the refer machinery, so pending
374
+ // resolution, type flow and link stamping are the one battle-tested
375
+ // path, and the data side stays plain strings. The PREDICATE of every
376
+ // edge produced is the key the rel() sits on -- declared once, in the
377
+ // schema, never inferred from the path.
378
+ class RelVal extends FeatureVal_1.FeatureVal {
379
+ constructor(spec, ctx) {
380
+ super(spec, ctx);
381
+ this.isRel = true;
382
+ this.isGenable = true;
383
+ this.cjo = 45000;
384
+ this.tval = spec.tval ?? (0, top_1.top)();
385
+ this.held = spec.held;
386
+ // DONE while unmet, deliberately -- the property refer() lacks and
387
+ // G4 phase 4 records the cost of: a type() body holding a rel()
388
+ // must SETTLE, or the schema idiom (`dependsOn?: rel($.T)` inside
389
+ // a vocabulary) leaves the type unresolved and every reference to
390
+ // it deferring forever. An unmet rel is its own settled residual,
391
+ // like `min(1)`; the meet re-activates it whenever a value
392
+ // arrives, because map merges build the conjunct regardless.
393
+ this.dc = type_1.DONE;
394
+ }
395
+ clone(ctx, spec) {
396
+ const out = super.clone(ctx, spec);
397
+ out.tval = this.tval;
398
+ out.held = this.held;
399
+ return out;
400
+ }
401
+ // The predicate: the last segment of the field path the constraint
402
+ // is being APPLIED at -- when that segment is a D-1 NAME. A relation
403
+ // predicate is a declared name (RELATIONS.0.md §3.2), so a list
404
+ // index or a key outside the name grammar produces unlabelled
405
+ // links, and the graph falls back to its old inference. The D-1
406
+ // test is also what keeps the two ports' edges identical: a list
407
+ // index is a number here and a string in Go.
408
+ //
409
+ // THE PATH COMES FROM THE CONTEXT, not from `this.path`. The val's
410
+ // own path records where this constraint was CLONED FROM, and the
411
+ // two part company the moment a second document merges into an
412
+ // entity: the field's constraint is then driven at the ENTITY, and
413
+ // `this.path` names the entity while the context names the field.
414
+ // The predicate became the entity's own key, every link under it
415
+ // minted an edge starting one level too high, and `inverse(n)`
416
+ // reported a mirror that was written as missing.
417
+ fieldkey(ctx) {
418
+ const path = ctx.path;
419
+ const seg = path[path.length - 1];
420
+ return 'string' === typeof seg && PREDICATE_NAME.test(seg) ? seg : undefined;
421
+ }
422
+ // One leaf's residual: the refer machinery carrying rel's codes,
423
+ // predicate and type. The predicate is passed IN, because the field
424
+ // it names is decided where the rewrite starts and must not be
425
+ // re-read on the way down (see `rewriteUnder`).
426
+ leafRefer(ctx, relkey) {
427
+ const rv = new ReferVal({ tval: this.tval }, ctx);
428
+ rv.addrcode = 'rel_address';
429
+ rv.unresolvedcode = 'rel_unresolved';
430
+ rv.relkey = relkey;
431
+ rv.site = this.site;
432
+ rv.path = this.path;
433
+ return rv;
434
+ }
435
+ // The container, every string leaf wrapped as a link. Nested
436
+ // containers descend; a leaf already STAMPED as a link is left
437
+ // alone, which is what makes a second application (a template
438
+ // re-applied, a later pass) a no-op.
439
+ rewrite(ctx, container) {
440
+ return this.rewriteUnder(ctx, container, this.fieldkey(ctx));
441
+ }
442
+ // The rewrite proper, carrying the predicate decided at the field.
443
+ // It is decided ONCE, at the top: a map-valued relation
444
+ // (`dependsOn: {primary: [...]}`) descends through the inner label
445
+ // and must still report `dependsOn`, which is the whole reason a
446
+ // link carries a declared predicate rather than letting the graph
447
+ // infer one from its position.
448
+ rewriteUnder(ctx, container, relkey) {
449
+ const out = container.clone(ctx);
450
+ const peg = out.peg;
451
+ const keys = Array.isArray(peg)
452
+ ? peg.map((_v, i) => i) : Object.keys(peg);
453
+ let pending = false;
454
+ let nested = false;
455
+ for (const k of keys) {
456
+ // Children here are always Vals: the parse builds Vals, elision
457
+ // builds a NilVal, and clone preserved whatever the container
458
+ // held.
459
+ const child = peg[k];
460
+ if (true === child.isMap || true === child.isList) {
461
+ nested = true;
462
+ const sub = this.rewriteUnder(ctx.descend('' + k), child, relkey);
463
+ peg[k] = sub;
464
+ pending = pending || true !== sub.done;
465
+ }
466
+ else if (undefined === child.link) {
467
+ let leaf = (0, unify_1.unite)(ctx.descend('' + k), this.leafRefer(ctx, relkey), child, 'rel-leaf');
468
+ // The held constraints apply PER LEAF: a re() on the relation
469
+ // constrains every address, never the container that holds
470
+ // them (found by the service catalog, whose re("^svc_") met
471
+ // the whole list and refused it).
472
+ if (null != this.held) {
473
+ leaf = (0, unify_1.unite)(ctx.descend('' + k), leaf, this.held, 'rel-held');
474
+ }
475
+ peg[k] = leaf;
476
+ pending = pending || true !== leaf.done;
477
+ }
478
+ }
479
+ // The rewrite holds its PENDING leaves open (an address whose
480
+ // entity a later statement declares), so the pass loop keeps
481
+ // driving the container until every link settles. A rewrite that
482
+ // minted NOTHING pending -- every leaf already linked or settled
483
+ // in place -- keeps the clone's doneness: re-applying a template
484
+ // over a settled value must converge in the same pass, or the
485
+ // enclosing bags reopen forever (the service catalog, where the
486
+ // entity merge drops the spread stamp each pass).
487
+ if (pending) {
488
+ out.dc = 0;
489
+ }
490
+ // Elements that arrive AFTER this rewrite -- another statement of
491
+ // the list, a patch position of the entity -- must convert too, so
492
+ // the rewrite installs its own leaf constraint as the container's
493
+ // ELEMENT SPREAD, exactly the machinery the old per-element
494
+ // `[&: refer()]` idiom used. Only on a FLAT address container (a
495
+ // labelled map's sub-containers get their own spread from the
496
+ // recursion above; a leaf template meeting a map child would
497
+ // refuse it), and only where no spread already stands: a schema's
498
+ // own template is not this rewrite's to clobber.
499
+ if (!nested && null == out.spread.cj) {
500
+ let tmpl = this.leafRefer(ctx, relkey);
501
+ if (null != this.held) {
502
+ tmpl = new ConjunctVal_1.ConjunctVal({ peg: [tmpl, this.held] }, ctx);
503
+ }
504
+ ;
505
+ out.spread.cj = tmpl;
506
+ }
507
+ return out;
508
+ }
509
+ unify(peer, ctx) {
510
+ const p = peer;
511
+ // Two rel() at one field: one relation, both types.
512
+ if (true === p?.isRel) {
513
+ const out = new RelVal({}, ctx);
514
+ out.tval = (0, unify_1.unite)(ctx, this.tval, p.tval, 'rel-t');
515
+ out.held = null == this.held ? p.held
516
+ : null == p.held ? this.held
517
+ : (0, unify_1.unite)(ctx, this.held, p.held, 'rel-held');
518
+ (0, utility_1.propagateMarks)(this, out);
519
+ out.site = this.site;
520
+ out.path = this.path;
521
+ return out;
522
+ }
523
+ // No null/top/nil arms: unite's dispatch ladder absorbs those
524
+ // peers before any Val's own unify is consulted (a null or top
525
+ // peer returns this side; a nil peer returns the nil), and unite
526
+ // is the only entrance -- the container hand-offs pass the
527
+ // container itself.
528
+ // ONE ADDRESS: the scalar-valued field, refer's own shape. A path
529
+ // value only -- a bare string is never an address (PATHS.0.md,
530
+ // amended); the scalar arm below refuses it.
531
+ if (true === p.isPath) {
532
+ const out = (0, unify_1.unite)(ctx, this.leafRefer(ctx, this.fieldkey(ctx)), peer, 'rel-scalar');
533
+ return null == this.held ? out
534
+ : (0, unify_1.unite)(ctx, out, this.held, 'rel-held');
535
+ }
536
+ // A SET OF LINKS: list or map, rewritten leaf by leaf; the held
537
+ // constraints ride into each leaf inside the rewrite.
538
+ if (true === p.isMap || true === p.isList) {
539
+ return this.rewrite(ctx, peer);
540
+ }
541
+ // A scalar that can never be an address.
542
+ if (true === p.isScalar) {
543
+ return (0, err_1.makeNilErr)(ctx, 'rel_address', this, peer, 'refer');
544
+ }
545
+ // Everything else -- a reference still resolving, a kind, a
546
+ // container constraint -- waits for the value, as refer's held
547
+ // does.
548
+ const out = new RelVal({}, ctx);
549
+ out.tval = this.tval;
550
+ out.held = null == this.held ? peer
551
+ : (0, unify_1.unite)(ctx, this.held, peer, 'rel-held');
552
+ (0, utility_1.propagateMarks)(this, out);
553
+ out.site = this.site;
554
+ out.path = this.path;
555
+ return out;
556
+ }
557
+ get canon() {
558
+ const t = this.tval.isTop ? '' : this.tval.canon;
559
+ return 'rel(' + t + ')' +
560
+ (null == this.held ? '' : '&' + this.held.canon);
561
+ }
562
+ }
563
+ exports.RelVal = RelVal;
564
+ class RelFuncVal extends FuncBaseVal_1.FuncBaseVal {
565
+ constructor(spec, ctx) {
566
+ super(spec, ctx);
567
+ this.isRelFunc = true;
568
+ }
569
+ make(_ctx, spec) {
570
+ return new RelFuncVal(spec);
571
+ }
572
+ funcname() {
573
+ return 'rel';
574
+ }
575
+ resolve(ctx, args) {
576
+ const out = new RelVal({}, ctx);
577
+ out.tval = 0 < args.length ? args[0] : (0, top_1.top)();
578
+ out.site = this.site;
579
+ out.path = this.path;
580
+ return out;
581
+ }
582
+ }
583
+ exports.RelFuncVal = RelFuncVal;
283
584
  class ReferFuncVal extends FuncBaseVal_1.FuncBaseVal {
284
585
  constructor(spec, ctx) {
285
586
  super(spec, ctx);
@@ -298,6 +599,6 @@ class ReferFuncVal extends FuncBaseVal_1.FuncBaseVal {
298
599
  out.path = this.path;
299
600
  return out;
300
601
  }
301
- } /* node:coverage ignore next 6 */
602
+ } /* node:coverage ignore next 10 */
302
603
  exports.ReferFuncVal = ReferFuncVal;
303
604
  //# sourceMappingURL=ReferFuncVal.js.map