aontu 0.52.1 → 0.54.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 (310) hide show
  1. package/README.md +88 -0
  2. package/bin/aontu-mcp.js +4 -0
  3. package/dist/agentsmd.d.ts +16 -0
  4. package/dist/agentsmd.js +107 -0
  5. package/dist/agentsmd.js.map +1 -0
  6. package/dist/aontu.d.ts +15 -3
  7. package/dist/aontu.js +126 -5
  8. package/dist/aontu.js.map +1 -1
  9. package/dist/cli.d.ts +45 -1
  10. package/dist/cli.js +2845 -69
  11. package/dist/cli.js.map +1 -1
  12. package/dist/ctx.d.ts +18 -0
  13. package/dist/ctx.js +44 -0
  14. package/dist/ctx.js.map +1 -1
  15. package/dist/diff.d.ts +22 -0
  16. package/dist/diff.js +141 -0
  17. package/dist/diff.js.map +1 -0
  18. package/dist/err.d.ts +3 -1
  19. package/dist/err.js +45 -8
  20. package/dist/err.js.map +1 -1
  21. package/dist/graph.d.ts +13 -0
  22. package/dist/graph.js +110 -0
  23. package/dist/graph.js.map +1 -0
  24. package/dist/hcanon.d.ts +3 -0
  25. package/dist/hcanon.js +145 -0
  26. package/dist/hcanon.js.map +1 -0
  27. package/dist/hints.js +235 -8
  28. package/dist/hints.js.map +1 -1
  29. package/dist/jsonschema.d.ts +20 -0
  30. package/dist/jsonschema.js +425 -0
  31. package/dist/jsonschema.js.map +1 -0
  32. package/dist/lang.js +955 -110
  33. package/dist/lang.js.map +1 -1
  34. package/dist/lsp.d.ts +9 -2
  35. package/dist/lsp.js +343 -48
  36. package/dist/lsp.js.map +1 -1
  37. package/dist/mcp-server.d.ts +20 -0
  38. package/dist/mcp-server.js +147 -0
  39. package/dist/mcp-server.js.map +1 -0
  40. package/dist/mcp.d.ts +42 -0
  41. package/dist/mcp.js +941 -0
  42. package/dist/mcp.js.map +1 -0
  43. package/dist/mod-tool.d.ts +58 -0
  44. package/dist/mod-tool.js +532 -0
  45. package/dist/mod-tool.js.map +1 -0
  46. package/dist/mod.d.ts +35 -0
  47. package/dist/mod.js +345 -0
  48. package/dist/mod.js.map +1 -0
  49. package/dist/patch.d.ts +49 -0
  50. package/dist/patch.js +506 -0
  51. package/dist/patch.js.map +1 -0
  52. package/dist/provenance.d.ts +41 -0
  53. package/dist/provenance.js +336 -0
  54. package/dist/provenance.js.map +1 -0
  55. package/dist/query.d.ts +27 -0
  56. package/dist/query.js +294 -0
  57. package/dist/query.js.map +1 -0
  58. package/dist/reach.d.ts +15 -0
  59. package/dist/reach.js +168 -0
  60. package/dist/reach.js.map +1 -0
  61. package/dist/relation.d.ts +23 -0
  62. package/dist/relation.js +230 -0
  63. package/dist/relation.js.map +1 -0
  64. package/dist/report-sarif.d.ts +14 -0
  65. package/dist/report-sarif.js +102 -0
  66. package/dist/report-sarif.js.map +1 -0
  67. package/dist/sig.d.ts +25 -0
  68. package/dist/sig.js +277 -0
  69. package/dist/sig.js.map +1 -0
  70. package/dist/sigdecl.d.ts +2 -0
  71. package/dist/sigdecl.js +11 -0
  72. package/dist/sigdecl.js.map +1 -0
  73. package/dist/siggate.d.ts +4 -0
  74. package/dist/siggate.js +90 -0
  75. package/dist/siggate.js.map +1 -0
  76. package/dist/site.d.ts +4 -0
  77. package/dist/site.js +31 -0
  78. package/dist/site.js.map +1 -1
  79. package/dist/std.d.ts +1 -0
  80. package/dist/std.js +129 -0
  81. package/dist/std.js.map +1 -0
  82. package/dist/subsume.d.ts +39 -0
  83. package/dist/subsume.js +573 -0
  84. package/dist/subsume.js.map +1 -0
  85. package/dist/trim.d.ts +19 -0
  86. package/dist/trim.js +155 -0
  87. package/dist/trim.js.map +1 -0
  88. package/dist/tsconfig.tsbuildinfo +1 -1
  89. package/dist/type.d.ts +17 -1
  90. package/dist/type.js.map +1 -1
  91. package/dist/unify.d.ts +2 -1
  92. package/dist/unify.js +234 -38
  93. package/dist/unify.js.map +1 -1
  94. package/dist/utility.d.ts +8 -1
  95. package/dist/utility.js +68 -1
  96. package/dist/utility.js.map +1 -1
  97. package/dist/val/AggFuncVal.d.ts +44 -0
  98. package/dist/val/AggFuncVal.js +364 -0
  99. package/dist/val/AggFuncVal.js.map +1 -0
  100. package/dist/val/ArithFuncVal.d.ts +31 -0
  101. package/dist/val/ArithFuncVal.js +62 -0
  102. package/dist/val/ArithFuncVal.js.map +1 -0
  103. package/dist/val/BagVal.d.ts +7 -0
  104. package/dist/val/BagVal.js +150 -11
  105. package/dist/val/BagVal.js.map +1 -1
  106. package/dist/val/CloseFuncVal.js +9 -1
  107. package/dist/val/CloseFuncVal.js.map +1 -1
  108. package/dist/val/ConjunctVal.d.ts +1 -1
  109. package/dist/val/ConjunctVal.js +19 -0
  110. package/dist/val/ConjunctVal.js.map +1 -1
  111. package/dist/val/ConstraintVal.d.ts +7 -1
  112. package/dist/val/ConstraintVal.js +523 -45
  113. package/dist/val/ConstraintVal.js.map +1 -1
  114. package/dist/val/ContainerKindVal.d.ts +35 -0
  115. package/dist/val/ContainerKindVal.js +99 -0
  116. package/dist/val/ContainerKindVal.js.map +1 -0
  117. package/dist/val/CopyFuncVal.d.ts +1 -2
  118. package/dist/val/CopyFuncVal.js.map +1 -1
  119. package/dist/val/Decimal.d.ts +1 -0
  120. package/dist/val/Decimal.js +13 -0
  121. package/dist/val/Decimal.js.map +1 -1
  122. package/dist/val/DeprecateFuncVal.d.ts +11 -0
  123. package/dist/val/DeprecateFuncVal.js +47 -0
  124. package/dist/val/DeprecateFuncVal.js.map +1 -0
  125. package/dist/val/DisjunctVal.d.ts +1 -2
  126. package/dist/val/DisjunctVal.js +269 -53
  127. package/dist/val/DisjunctVal.js.map +1 -1
  128. package/dist/val/EachFuncVal.d.ts +15 -0
  129. package/dist/val/EachFuncVal.js +75 -0
  130. package/dist/val/EachFuncVal.js.map +1 -0
  131. package/dist/val/ExpectVal.js +62 -4
  132. package/dist/val/ExpectVal.js.map +1 -1
  133. package/dist/val/FeatureVal.js +1 -1
  134. package/dist/val/FeatureVal.js.map +1 -1
  135. package/dist/val/FilterFuncVal.d.ts +15 -0
  136. package/dist/val/FilterFuncVal.js +91 -0
  137. package/dist/val/FilterFuncVal.js.map +1 -0
  138. package/dist/val/FuncBaseVal.d.ts +7 -1
  139. package/dist/val/FuncBaseVal.js +183 -2
  140. package/dist/val/FuncBaseVal.js.map +1 -1
  141. package/dist/val/GraphAtomVal.d.ts +39 -0
  142. package/dist/val/GraphAtomVal.js +184 -0
  143. package/dist/val/GraphAtomVal.js.map +1 -0
  144. package/dist/val/HideFuncVal.js.map +1 -1
  145. package/dist/val/JunctionVal.js +24 -1
  146. package/dist/val/JunctionVal.js.map +1 -1
  147. package/dist/val/KeyFuncVal.d.ts +1 -1
  148. package/dist/val/KeyFuncVal.js +38 -30
  149. package/dist/val/KeyFuncVal.js.map +1 -1
  150. package/dist/val/ListVal.js +94 -14
  151. package/dist/val/ListVal.js.map +1 -1
  152. package/dist/val/LowerFuncVal.js.map +1 -1
  153. package/dist/val/MapVal.d.ts +1 -0
  154. package/dist/val/MapVal.js +146 -14
  155. package/dist/val/MapVal.js.map +1 -1
  156. package/dist/val/MatchFuncVal.d.ts +15 -0
  157. package/dist/val/MatchFuncVal.js +107 -0
  158. package/dist/val/MatchFuncVal.js.map +1 -0
  159. package/dist/val/MoveFuncVal.js.map +1 -1
  160. package/dist/val/NilVal.js +24 -0
  161. package/dist/val/NilVal.js.map +1 -1
  162. package/dist/val/OpBaseVal.d.ts +1 -1
  163. package/dist/val/OpBaseVal.js +19 -1
  164. package/dist/val/OpBaseVal.js.map +1 -1
  165. package/dist/val/OpenFuncVal.js +4 -1
  166. package/dist/val/OpenFuncVal.js.map +1 -1
  167. package/dist/val/PackFuncVal.d.ts +15 -0
  168. package/dist/val/PackFuncVal.js +108 -0
  169. package/dist/val/PackFuncVal.js.map +1 -0
  170. package/dist/val/PathFuncVal.d.ts +2 -2
  171. package/dist/val/PathFuncVal.js +75 -16
  172. package/dist/val/PathFuncVal.js.map +1 -1
  173. package/dist/val/PathVal.d.ts +25 -0
  174. package/dist/val/PathVal.js +150 -0
  175. package/dist/val/PathVal.js.map +1 -0
  176. package/dist/val/PlaceVal.d.ts +13 -0
  177. package/dist/val/PlaceVal.js +131 -0
  178. package/dist/val/PlaceVal.js.map +1 -0
  179. package/dist/val/PlusOpVal.d.ts +2 -1
  180. package/dist/val/PlusOpVal.js +61 -37
  181. package/dist/val/PlusOpVal.js.map +1 -1
  182. package/dist/val/PrefFuncVal.js.map +1 -1
  183. package/dist/val/PrefVal.d.ts +4 -2
  184. package/dist/val/PrefVal.js +223 -41
  185. package/dist/val/PrefVal.js.map +1 -1
  186. package/dist/val/RecurseVal.d.ts +19 -0
  187. package/dist/val/RecurseVal.js +217 -0
  188. package/dist/val/RecurseVal.js.map +1 -0
  189. package/dist/val/RefVal.d.ts +3 -2
  190. package/dist/val/RefVal.js +181 -66
  191. package/dist/val/RefVal.js.map +1 -1
  192. package/dist/val/ReferFuncVal.d.ts +59 -0
  193. package/dist/val/ReferFuncVal.js +604 -0
  194. package/dist/val/ReferFuncVal.js.map +1 -0
  195. package/dist/val/ScalarKindVal.d.ts +4 -3
  196. package/dist/val/ScalarKindVal.js +12 -12
  197. package/dist/val/ScalarKindVal.js.map +1 -1
  198. package/dist/val/SuperFuncVal.d.ts +4 -2
  199. package/dist/val/SuperFuncVal.js +118 -14
  200. package/dist/val/SuperFuncVal.js.map +1 -1
  201. package/dist/val/TopVal.d.ts +1 -1
  202. package/dist/val/TopVal.js.map +1 -1
  203. package/dist/val/TypeFuncVal.js.map +1 -1
  204. package/dist/val/UpperFuncVal.js.map +1 -1
  205. package/dist/val/Val.d.ts +7 -1
  206. package/dist/val/Val.js +170 -2
  207. package/dist/val/Val.js.map +1 -1
  208. package/dist/val/VarVal.js.map +1 -1
  209. package/dist/val/arith.d.ts +6 -0
  210. package/dist/val/arith.js +173 -0
  211. package/dist/val/arith.js.map +1 -0
  212. package/dist/vet.d.ts +45 -0
  213. package/dist/vet.js +802 -0
  214. package/dist/vet.js.map +1 -0
  215. package/dist/view.d.ts +85 -0
  216. package/dist/view.js +1948 -0
  217. package/dist/view.js.map +1 -0
  218. package/dist/walk.d.ts +2 -0
  219. package/dist/walk.js +91 -0
  220. package/dist/walk.js.map +1 -0
  221. package/grammar/aontu.gbnf +138 -0
  222. package/grammar/aontu.lark +118 -0
  223. package/grammar/aontu.tmLanguage.json +184 -0
  224. package/package.json +30 -8
  225. package/skill/SKILL.md +37 -0
  226. package/skill/error-codes.md +62 -0
  227. package/skill/examples.md +99 -0
  228. package/skill/grammar-card.md +56 -0
  229. package/src/agentsmd.ts +135 -0
  230. package/src/aontu.ts +166 -5
  231. package/src/cli.ts +3324 -72
  232. package/src/ctx.ts +93 -1
  233. package/src/diff.ts +198 -0
  234. package/src/err.ts +50 -8
  235. package/src/graph.ts +185 -0
  236. package/src/hcanon.ts +167 -0
  237. package/src/hints.ts +291 -8
  238. package/src/jsonschema.ts +552 -0
  239. package/src/lang.ts +1049 -110
  240. package/src/lsp.ts +351 -49
  241. package/src/mcp-server.ts +187 -0
  242. package/src/mcp.ts +1130 -0
  243. package/src/mod-tool.ts +718 -0
  244. package/src/mod.ts +453 -0
  245. package/src/patch.ts +628 -0
  246. package/src/provenance.ts +437 -0
  247. package/src/query.ts +381 -0
  248. package/src/reach.ts +213 -0
  249. package/src/relation.ts +298 -0
  250. package/src/report-sarif.ts +137 -0
  251. package/src/sig.ts +345 -0
  252. package/src/sigdecl.ts +11 -0
  253. package/src/siggate.ts +144 -0
  254. package/src/site.ts +36 -1
  255. package/src/std.ts +131 -0
  256. package/src/subsume.ts +739 -0
  257. package/src/trim.ts +195 -0
  258. package/src/tsconfig.json +10 -4
  259. package/src/type.ts +51 -2
  260. package/src/unify.ts +253 -38
  261. package/src/utility.ts +79 -1
  262. package/src/val/AggFuncVal.ts +546 -0
  263. package/src/val/ArithFuncVal.ts +108 -0
  264. package/src/val/BagVal.ts +158 -12
  265. package/src/val/CloseFuncVal.ts +9 -1
  266. package/src/val/ConjunctVal.ts +20 -0
  267. package/src/val/ConstraintVal.ts +576 -48
  268. package/src/val/ContainerKindVal.ts +158 -0
  269. package/src/val/CopyFuncVal.ts +0 -1
  270. package/src/val/Decimal.ts +15 -0
  271. package/src/val/DeprecateFuncVal.ts +84 -0
  272. package/src/val/DisjunctVal.ts +282 -59
  273. package/src/val/EachFuncVal.ts +133 -0
  274. package/src/val/ExpectVal.ts +65 -8
  275. package/src/val/FeatureVal.ts +1 -1
  276. package/src/val/FilterFuncVal.ts +154 -0
  277. package/src/val/FuncBaseVal.ts +206 -2
  278. package/src/val/GraphAtomVal.ts +264 -0
  279. package/src/val/HideFuncVal.ts +0 -2
  280. package/src/val/JunctionVal.ts +24 -1
  281. package/src/val/KeyFuncVal.ts +39 -35
  282. package/src/val/ListVal.ts +101 -15
  283. package/src/val/LowerFuncVal.ts +0 -1
  284. package/src/val/MapVal.ts +153 -14
  285. package/src/val/MatchFuncVal.ts +176 -0
  286. package/src/val/MoveFuncVal.ts +0 -2
  287. package/src/val/NilVal.ts +25 -0
  288. package/src/val/OpBaseVal.ts +20 -1
  289. package/src/val/OpenFuncVal.ts +4 -2
  290. package/src/val/PackFuncVal.ts +175 -0
  291. package/src/val/PathFuncVal.ts +107 -20
  292. package/src/val/PathVal.ts +221 -0
  293. package/src/val/PlaceVal.ts +193 -0
  294. package/src/val/PlusOpVal.ts +67 -39
  295. package/src/val/PrefFuncVal.ts +0 -1
  296. package/src/val/PrefVal.ts +251 -60
  297. package/src/val/RecurseVal.ts +285 -0
  298. package/src/val/RefVal.ts +183 -78
  299. package/src/val/ReferFuncVal.ts +732 -0
  300. package/src/val/ScalarKindVal.ts +12 -13
  301. package/src/val/SuperFuncVal.ts +137 -13
  302. package/src/val/TopVal.ts +1 -2
  303. package/src/val/TypeFuncVal.ts +0 -2
  304. package/src/val/UpperFuncVal.ts +0 -1
  305. package/src/val/Val.ts +216 -4
  306. package/src/val/VarVal.ts +0 -1
  307. package/src/val/arith.ts +319 -0
  308. package/src/vet.ts +1025 -0
  309. package/src/view.ts +2563 -0
  310. package/src/walk.ts +99 -0
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /* Copyright (c) 2025 Richard Rodger, MIT License */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.relationFindings = relationFindings;
5
+ exports.relationErrors = relationErrors;
6
+ exports.relationCheck = relationCheck;
7
+ // RELATION GRAPH VERDICTS (RELATIONS.0.md §3.3, replacing the G4
8
+ // phase 5 magic-key pass): acyclicity and inverse consistency over
9
+ // the edge set, DECLARED by the graph atoms -- `acyclic()` and
10
+ // `inverse(name)` conjoined at the field whose key is the predicate
11
+ // -- and decided AFTER unification, never by it.
12
+ //
13
+ // Why not in the lattice. Both properties are GLOBAL and NON-MONOTONE:
14
+ // an acyclic graph becomes cyclic when one more edge unifies in, and an
15
+ // inverse that is present becomes absent when the far side is narrowed.
16
+ // The lattice guarantee is that more information never falsifies what
17
+ // has been observed, so a constraint that could be true and then false
18
+ // is not a constraint the lattice may hold. These are facts about the
19
+ // finished model, so the atoms only REGISTER during unification
20
+ // (GraphAtomVal.register, onto ctx._reldecls), and the verdict lands
21
+ // at GENERATION -- the sizing atoms' model -- where no more
22
+ // information can arrive. The `relations` verb reports the same
23
+ // verdict from the same declarations: one decision, two surfaces.
24
+ //
25
+ // The old declaration channel -- a `relations:` key at the document
26
+ // root, read by name -- is GONE, discharging ADR-010's grandfather
27
+ // clause: the engine no longer knows any spellable key. The target
28
+ // half of the old declaration is `rel(t)`'s flow at the site, which
29
+ // checks by unifying rather than by a report-layer probe.
30
+ const aontu_1 = require("./aontu");
31
+ const vet_1 = require("./vet");
32
+ const graph_1 = require("./graph");
33
+ const keyorder_1 = require("./keyorder");
34
+ const err_1 = require("./err");
35
+ // The first cycle reachable from `start`, as the node paths it runs
36
+ // through, or undefined. Depth-first with the path as the stack, and
37
+ // the successors visited in sorted order, so the cycle a report names
38
+ // is the same one in both ports.
39
+ function findCycle(start, succ, done) {
40
+ const stack = [];
41
+ const onStack = new Set();
42
+ const walk = (node) => {
43
+ if (onStack.has(node)) {
44
+ return [...stack.slice(stack.indexOf(node)), node];
45
+ }
46
+ if (done.has(node)) {
47
+ return undefined;
48
+ }
49
+ done.add(node);
50
+ stack.push(node);
51
+ onStack.add(node);
52
+ for (const next of succ.get(node) ?? []) {
53
+ const found = walk(next);
54
+ if (undefined !== found) {
55
+ return found;
56
+ }
57
+ }
58
+ stack.pop();
59
+ onStack.delete(node);
60
+ return undefined;
61
+ };
62
+ return walk(start);
63
+ }
64
+ // The verdict itself, pure over what the evaluation produced: the
65
+ // registered declarations and the edge set. Shared by the generation
66
+ // hook (relationErrors) and the `relations` verb, so the two surfaces
67
+ // cannot disagree.
68
+ function relationFindings(decls, graph) {
69
+ const findings = [];
70
+ // The edge set, indexed the two ways the checks read it.
71
+ const byRelation = new Map();
72
+ const pairs = new Set();
73
+ for (const e of graph.edges) {
74
+ const list = byRelation.get(e.key);
75
+ if (undefined === list) {
76
+ byRelation.set(e.key, [e]);
77
+ }
78
+ else {
79
+ list.push(e);
80
+ }
81
+ pairs.add(e.key + ' ' + e.from + ' ' + e.to);
82
+ }
83
+ // Predicates in sorted order, so the findings arrive the same way
84
+ // in both ports (the registry is insertion-ordered here, random in
85
+ // Go).
86
+ const names = [...decls.keys()].sort(keyorder_1.cmpCodePoint);
87
+ for (const name of names) {
88
+ const decl = decls.get(name);
89
+ const mine = byRelation.get(name) ?? [];
90
+ if (true === decl.acyclic) {
91
+ const succ = new Map();
92
+ for (const e of mine) {
93
+ const list = succ.get(e.from);
94
+ const to = e.to;
95
+ if (undefined === list) {
96
+ succ.set(e.from, [to]);
97
+ }
98
+ else {
99
+ list.push(to);
100
+ }
101
+ }
102
+ for (const list of succ.values()) {
103
+ list.sort(keyorder_1.cmpCodePoint);
104
+ }
105
+ // The roots are visited in sorted order, and a node already
106
+ // settled is not revisited, so one cycle is reported once and the
107
+ // SAME one in both ports.
108
+ const done = new Set();
109
+ const roots = [...succ.keys()].sort(keyorder_1.cmpCodePoint);
110
+ for (const from of roots) {
111
+ const cycle = findCycle(from, succ, done);
112
+ if (undefined !== cycle) {
113
+ // The cycle's first node is a key of `succ`, and every key of
114
+ // `succ` came from an edge's `from`, so the edge is there.
115
+ const at = mine.find((e) => e.from === cycle[0]);
116
+ findings.push({
117
+ code: 'relation_cycle',
118
+ relation: name,
119
+ at: at.at,
120
+ detail: cycle,
121
+ });
122
+ break;
123
+ }
124
+ }
125
+ }
126
+ const inverses = [...decl.inverses].sort(keyorder_1.cmpCodePoint);
127
+ for (const inv of inverses) {
128
+ for (const e of mine) {
129
+ const to = e.to;
130
+ if (!pairs.has(inv + ' ' + to + ' ' + e.from)) {
131
+ findings.push({
132
+ code: 'relation_inverse_missing',
133
+ relation: name,
134
+ at: e.at,
135
+ detail: [e.from, to, inv],
136
+ });
137
+ }
138
+ }
139
+ }
140
+ }
141
+ // SORTED, because a report is read by a machine that diffs it: by the
142
+ // position the offending edge is written at, then by code, then by
143
+ // the detail (two inverse declarations on one predicate can flag one
144
+ // edge twice). The sort is STABLE and the predicates were iterated
145
+ // in sorted order, so what order remains is fixed anyway.
146
+ findings.sort((a, b) => (0, keyorder_1.cmpCodePoint)(a.at, b.at) || (0, keyorder_1.cmpCodePoint)(a.code, b.code)
147
+ || (0, keyorder_1.cmpCodePoint)(a.detail.join(' '), b.detail.join(' ')));
148
+ return findings;
149
+ }
150
+ // The generation hook (Aontu.generate, between unification success
151
+ // and value generation): each finding becomes a LOCATED evaluation
152
+ // error at the offending edge, exactly as an unmet sizing atom
153
+ // refuses at generation. Findings name node paths and positions the
154
+ // document spelled, so the walk to the site cannot miss.
155
+ function relationErrors(ctx, root) {
156
+ const decls = ctx._reldecls;
157
+ if (0 === decls.size) {
158
+ return;
159
+ }
160
+ const findings = relationFindings(decls, (0, graph_1.graphOf)(root));
161
+ for (const f of findings) {
162
+ let node = root;
163
+ for (const seg of f.at.slice(2).split('.')) {
164
+ // Graph atoms hold the field's value -- possibly nested, one
165
+ // atom carrying another -- and the path steps through them
166
+ // exactly as the graph walk does.
167
+ while (true === node?.isGraphAtom) {
168
+ node = node.held;
169
+ }
170
+ node = node?.peg?.[seg];
171
+ }
172
+ // No unwrap AFTER the walk: a finding's `at` names an edge
173
+ // element, and an edge's element is a string -- an atom-wrapped
174
+ // element mints no edge in the first place (the graph visit
175
+ // descends atoms only at field values), so the walk cannot end on
176
+ // an atom.
177
+ ctx.adderr((0, err_1.makeNilErr)(ctx, f.code, node, undefined, 'relate', {
178
+ relation: f.relation,
179
+ detail: f.detail.join(' -> '),
180
+ }));
181
+ }
182
+ }
183
+ // The relation checks for one document: evaluate, then report the
184
+ // same verdict generation enforces.
185
+ function relationCheck(src, opts) {
186
+ const options = opts ?? {};
187
+ const aontu = new aontu_1.Aontu(null == options.trust ? undefined : { trust: options.trust });
188
+ const ctx = aontu.ctx({ collect: true });
189
+ const parseOpts = null == options.path ? undefined : { path: options.path };
190
+ const root = aontu.unify(src, parseOpts, ctx);
191
+ // A document that does not stand up is not a document with a bad
192
+ // graph: the errors it already has are the answer, and blaming its
193
+ // relations on top would be noise.
194
+ if (0 < ctx.err.length || true === root?.isNil) {
195
+ return {
196
+ verdict: 'error',
197
+ findings: [],
198
+ errors: [(0, vet_1.failureFinding)(ctx, options.path, root)],
199
+ };
200
+ }
201
+ const decls = ctx._reldecls;
202
+ if (0 === decls.size) {
203
+ return { verdict: 'pass', findings: [] };
204
+ }
205
+ // NOR IS A DOCUMENT THAT CANNOT BE GENERATED. Unification can
206
+ // succeed over a tree that still holds an unsettled disjunction --
207
+ // more than one alternative admitted, which `disjunct_no_gen`
208
+ // refuses at generation -- and the graph walk cannot read inside
209
+ // one: the links in every alternative are invisible, so a mirror
210
+ // the document plainly writes is missing from the edge set and
211
+ // `inverse(n)` calls it missing. Generation is therefore asked
212
+ // FIRST, on a collecting context of its own, and what it says is
213
+ // the answer. Generation is what the atoms' verdict lands at, so
214
+ // this is the same order the engine itself now runs in.
215
+ const gctx = ctx.clone({ err: [], collect: true });
216
+ root.gen(gctx);
217
+ if (0 < gctx.err.length) {
218
+ return {
219
+ verdict: 'error',
220
+ findings: [],
221
+ errors: [(0, vet_1.failureFinding)(gctx, options.path, root)],
222
+ };
223
+ }
224
+ const findings = relationFindings(decls, (0, graph_1.graphOf)(root));
225
+ return {
226
+ verdict: 0 === findings.length ? 'pass' : 'fail',
227
+ findings,
228
+ };
229
+ }
230
+ //# sourceMappingURL=relation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relation.js","sourceRoot":"","sources":["../src/relation.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;AAEpD,iEAAiE;AACjE,mEAAmE;AACnE,+DAA+D;AAC/D,oEAAoE;AACpE,iDAAiD;AACjD,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,wEAAwE;AACxE,sEAAsE;AACtE,uEAAuE;AACvE,sEAAsE;AACtE,gEAAgE;AAChE,qEAAqE;AACrE,4DAA4D;AAC5D,gEAAgE;AAChE,kEAAkE;AAClE,EAAE;AACF,oEAAoE;AACpE,mEAAmE;AACnE,mEAAmE;AACnE,oEAAoE;AACpE,0DAA0D;AAE1D,mCAA+B;AAC/B,+BAAsC;AAGtC,mCAAiC;AAEjC,yCAAyC;AACzC,+BAAkC;AA0ClC,oEAAoE;AACpE,qEAAqE;AACrE,sEAAsE;AACtE,iCAAiC;AACjC,SAAS,SAAS,CAChB,KAAa,EACb,IAA2B,EAC3B,IAAiB;IAEjB,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IAEjC,MAAM,IAAI,GAAG,CAAC,IAAY,EAAwB,EAAE;QAClD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;QACpD,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,C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AE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SAClD,CAAA;IACH,CAAC;IAED,MAAM,KAAK,GAA0B,GAAW,CAAC,SAAS,CAAA;IAC1D,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAA;IAC1C,CAAC;IAED,8DAA8D;IAC9D,mEAAmE;IACnE,8DAA8D;IAC9D,iEAAiE;IACjE,iEAAiE;IACjE,+DAA+D;IAC/D,+DAA+D;IAC/D,iEAAiE;IACjE,iEAAiE;IACjE,wDAAwD;IACxD,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IAClD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACd,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO;YACL,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,EAAE;YACZ,MAAM,EAAE,CAAC,IAAA,oBAAc,EAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACnD,CAAA;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,gBAAgB,CAAC,KAAK,EAAE,IAAA,eAAO,EAAC,IAAI,CAAC,CAAC,CAAA;IACvD,OAAO;QACL,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;QAChD,QAAQ;KACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { VetReport } from './vet';
2
+ /**
3
+ * Render a vet report as SARIF 2.1.0 text (a minimal profile: one run,
4
+ * one result per finding, the finding embedded in `properties`).
5
+ *
6
+ * @param report A report from `vet()`.
7
+ * @param version The producer version for `tool.driver.version` —
8
+ * the CLI passes its package version; the two ports'
9
+ * version series are independent by design.
10
+ * @returns The SARIF JSON text, indented two spaces, keys in
11
+ * the canonical emitter's sorted order.
12
+ */
13
+ declare function sarifReport(report: VetReport, version: string): string;
14
+ export { sarifReport, };
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /* Copyright (c) 2025 Richard Rodger, MIT License */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.sarifReport = sarifReport;
5
+ const exactjson_1 = require("./exactjson");
6
+ // SARIF levels are error/warning/note; the report's severities are
7
+ // error/warning/info. Only `info` needs translating, but the map spells
8
+ // out all three so a new severity fails loudly here rather than
9
+ // silently emitting itself.
10
+ const SARIF_LEVEL = {
11
+ error: 'error',
12
+ warning: 'warning',
13
+ info: 'note',
14
+ };
15
+ // A site's file is a filesystem path, and a SARIF artifactLocation.uri
16
+ // is a URI reference: `#`, `%`, spaces and every other URI-significant
17
+ // character must be percent-encoded or a consumer parses the path as
18
+ // something else (text after `#` becomes a fragment). Encoded BY BYTE
19
+ // over UTF-8, with RFC 3986's unreserved and path characters kept
20
+ // literal, so the Go twin produces identical bytes from an identical
21
+ // loop (go/report_sarif.go sarifURI).
22
+ function sarifUri(path) {
23
+ const bytes = Buffer.from(path, 'utf8');
24
+ let out = '';
25
+ for (const b of bytes) {
26
+ const c = String.fromCharCode(b);
27
+ if (b < 128 && /[A-Za-z0-9\-._~/!$&'()*+,;=:@]/.test(c)) {
28
+ out += c;
29
+ }
30
+ else {
31
+ out += '%' + b.toString(16).toUpperCase().padStart(2, '0');
32
+ }
33
+ }
34
+ return out;
35
+ }
36
+ function sarifLocation(site) {
37
+ const physical = {
38
+ artifactLocation: { uri: sarifUri(site.file) },
39
+ };
40
+ // SARIF regions are 1-based. A finding with no position — a parse
41
+ // failure reports at -1:-1 — gets a location with no region rather
42
+ // than an invented one.
43
+ if (1 <= site.row) {
44
+ physical.region = { startColumn: site.col, startLine: site.row };
45
+ }
46
+ return { physicalLocation: physical };
47
+ }
48
+ function sarifResult(finding) {
49
+ // The engine orders sites data-first (the thing to fix), so the first
50
+ // site is the primary location and the rest are related — which for a
51
+ // two-site conflict puts the schema's declaration under
52
+ // `relatedLocations`, exactly where a code-scanning UI shows "the
53
+ // other side".
54
+ const result = {
55
+ level: SARIF_LEVEL[finding.severity],
56
+ locations: [sarifLocation(finding.sites[0])],
57
+ message: { text: finding.message },
58
+ properties: finding,
59
+ ruleId: 'aontu/' + finding.code,
60
+ };
61
+ const related = finding.sites.slice(1);
62
+ if (0 < related.length) {
63
+ result.relatedLocations = related.map(sarifLocation);
64
+ }
65
+ return result;
66
+ }
67
+ /**
68
+ * Render a vet report as SARIF 2.1.0 text (a minimal profile: one run,
69
+ * one result per finding, the finding embedded in `properties`).
70
+ *
71
+ * @param report A report from `vet()`.
72
+ * @param version The producer version for `tool.driver.version` —
73
+ * the CLI passes its package version; the two ports'
74
+ * version series are independent by design.
75
+ * @returns The SARIF JSON text, indented two spaces, keys in
76
+ * the canonical emitter's sorted order.
77
+ */
78
+ function sarifReport(report, version) {
79
+ return (0, exactjson_1.exactJSON)({
80
+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
81
+ runs: [{
82
+ // An `error` verdict means the run could not be set up (an
83
+ // unusable schema): zero findings from a FAILED run must not
84
+ // read like zero findings from a clean one, so the failure is
85
+ // carried in SARIF's own invocation metadata rather than by an
86
+ // indistinguishable empty result list.
87
+ invocations: [{
88
+ executionSuccessful: 'error' !== report.verdict,
89
+ }],
90
+ results: report.findings.map(sarifResult),
91
+ tool: {
92
+ driver: {
93
+ informationUri: 'https://github.com/rjrodger/aontu',
94
+ name: 'aontu',
95
+ version,
96
+ },
97
+ },
98
+ }],
99
+ version: '2.1.0',
100
+ }, 2);
101
+ } /* node:coverage ignore next 6 */
102
+ //# sourceMappingURL=report-sarif.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report-sarif.js","sourceRoot":"","sources":["../src/report-sarif.ts"],"names":[],"mappings":";AAAA,oDAAoD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E,OAAO;wBACb,OAAO;qBACR;iBACF;aACF,CAAC;QACF,OAAO,EAAE,OAAO;KACjB,EAAE,CAAC,CAAC,CAAA;AACP,CAAC,CAAC,iCAAiC"}
package/dist/sig.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ type ArgMode = 'value' | 'capture' | 'template' | 'trial' | 'projector' | 'text';
2
+ type GroupSig = {
3
+ mode: ArgMode;
4
+ type: string;
5
+ };
6
+ type ArgSig = {
7
+ name: string;
8
+ mode: ArgMode;
9
+ type: string;
10
+ opt?: boolean;
11
+ rest?: boolean;
12
+ group?: GroupSig[];
13
+ };
14
+ type FuncSig = {
15
+ name: string;
16
+ args: ArgSig[];
17
+ out: string;
18
+ };
19
+ declare function parseSigLine(line: string): FuncSig;
20
+ declare function renderSigArg(a: ArgSig): string;
21
+ declare function renderSig(sig: FuncSig): string;
22
+ declare function parseSigText(text: string): Record<string, FuncSig>;
23
+ export type { ArgMode, ArgSig, GroupSig, FuncSig, };
24
+ declare const funcSig: Record<string, FuncSig>;
25
+ export { funcSig, parseSigLine, parseSigText, renderSig, renderSigArg, };
package/dist/sig.js ADDED
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ /* Copyright (c) 2021-2026 Richard Rodger, MIT License */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.funcSig = void 0;
5
+ exports.parseSigLine = parseSigLine;
6
+ exports.parseSigText = parseSigText;
7
+ exports.renderSig = renderSig;
8
+ exports.renderSigArg = renderSigArg;
9
+ // THE SIGNATURE REGISTRY (docs/design/SIGNATURES.0.md). The call
10
+ // surface of the built-in functions is DECLARED, in the signature
11
+ // syntax itself, in test/spec/signature.tsv; this module is the
12
+ // TypeScript half of the pair that reads it. The declaration text is
13
+ // inlined at build time (ts/src/sigdecl.ts, `make sig`) and parsed at
14
+ // initialisation by the signature grammar -- a custom tabnas grammar,
15
+ // the same engine the aontu grammar itself is built on -- into the
16
+ // registry the runtime signature checker, the error-message builder,
17
+ // the docs table and the LSP all consume. Neither port authors a
18
+ // table: go/sig.go parses the same text with the same grammar, and
19
+ // the shared suite round-trips every line (render(parse(line)) is the
20
+ // line) so the two parsers cannot drift.
21
+ //
22
+ // line = name '(' [ arg {',' arg} ] ')' ':' type
23
+ // arg = [mode] name ['?'] ':' type
24
+ // | '...' name ':' ( type | '(' [mode] type {',' [mode] type} ')' )
25
+ // type = word {'|' word}
26
+ // mode = 'capture' | 'template' | 'trial' | 'projector' | 'text'
27
+ //
28
+ // `value` mode is unmarked; the five marked modes are the vocabulary
29
+ // plain pseudo-TypeScript cannot say (a captured spelling is not a
30
+ // string value). The grammar is line-oriented: the loader strips
31
+ // comment and blank lines and parses each declaration line alone, so
32
+ // the grammar never sees line structure.
33
+ const parser_1 = require("@tabnas/parser");
34
+ const sigdecl_1 = require("./sigdecl");
35
+ const ARG_MODES = {
36
+ capture: true, template: true, trial: true, projector: true, text: true,
37
+ };
38
+ // The signature grammar, as a tabnas grammar plugin. Rules: sig (the
39
+ // line) -> args -> arg -> argtype -> type | group -> gmember. Alts
40
+ // match at most two tokens, the engine's shape; lists loop the
41
+ // json-grammar way (the element rule replaces itself on ',' and
42
+ // backtracks the closer for its parent to consume).
43
+ function sigGrammar(tn) {
44
+ tn.options({
45
+ fixed: {
46
+ token: {
47
+ '#OP': '(',
48
+ '#CP': ')',
49
+ '#QM': '?',
50
+ '#PI': '|',
51
+ '#DD': '...',
52
+ },
53
+ },
54
+ rule: { start: 'sig' },
55
+ });
56
+ // Parse-level validation errors, collected by the actions: the
57
+ // engine's own errors cover token shape, these cover word choice (a
58
+ // mode that is not a mode). Read after parse by parseSigLine.
59
+ const errs = [];
60
+ tn.sigErrs = errs;
61
+ const mode = (word) => {
62
+ if (true !== ARG_MODES[word]) {
63
+ errs.push('mode:' + word);
64
+ return 'value';
65
+ }
66
+ return word;
67
+ };
68
+ tn.grammar({
69
+ ref: {
70
+ '@sig-bo': (r) => {
71
+ r.node = { name: '', args: [], out: '' };
72
+ r.u.words = [];
73
+ },
74
+ '@signame': (r) => {
75
+ r.node.name = String(r.o0.val);
76
+ },
77
+ '@sigargs': (r) => {
78
+ r.node.args = r.child.node;
79
+ },
80
+ '@sigout': (r) => {
81
+ r.node.out = r.u.words.join('|');
82
+ },
83
+ '@args-bo': (r) => {
84
+ r.node = [];
85
+ },
86
+ '@arg-bo': (r) => {
87
+ r.u.sig = { name: '', mode: 'value', type: '' };
88
+ },
89
+ '@arg-rest': (r) => {
90
+ r.u.sig.rest = true;
91
+ r.u.sig.name = String(r.o1.val);
92
+ },
93
+ '@arg-modename': (r) => {
94
+ r.u.sig.mode = mode(String(r.o0.val));
95
+ r.u.sig.name = String(r.o1.val);
96
+ },
97
+ '@arg-name': (r) => {
98
+ r.u.sig.name = String(r.o0.val);
99
+ },
100
+ '@arg-opt': (r) => {
101
+ r.u.sig.opt = true;
102
+ },
103
+ '@arg-done': (r) => {
104
+ const sig = r.u.sig;
105
+ const at = r.child.node;
106
+ if (Array.isArray(at)) {
107
+ sig.group = at;
108
+ sig.type = '';
109
+ }
110
+ else {
111
+ sig.type = String(at);
112
+ }
113
+ r.node.push(sig);
114
+ },
115
+ '@argtype-bo': (r) => {
116
+ r.u.words = [];
117
+ },
118
+ '@argtype-bc': (r) => {
119
+ r.node = 0 < r.u.words.length ?
120
+ r.u.words.join('|') : r.child.node;
121
+ },
122
+ '@type-word': (r) => {
123
+ r.parent.u.words.push(String(r.o0.val));
124
+ },
125
+ '@group-bo': (r) => {
126
+ r.node = [];
127
+ },
128
+ '@gm-two': (r) => {
129
+ r.u.gm = { mode: mode(String(r.o0.val)), type: String(r.o1.val) };
130
+ },
131
+ '@gm-one': (r) => {
132
+ r.u.gm = { mode: 'value', type: String(r.o0.val) };
133
+ },
134
+ '@gm-done': (r) => {
135
+ r.node.push(r.u.gm);
136
+ },
137
+ },
138
+ rule: {
139
+ sig: {
140
+ open: [
141
+ { s: '#TX #OP', a: '@signame', p: 'args' },
142
+ ],
143
+ close: [
144
+ { s: '#CL', p: 'type', a: '@sigargs' },
145
+ { s: '#ZZ', a: '@sigout' },
146
+ ],
147
+ },
148
+ args: {
149
+ open: [
150
+ { s: '#CP', b: 1 },
151
+ { p: 'arg' },
152
+ ],
153
+ close: [
154
+ { s: '#CP' },
155
+ ],
156
+ },
157
+ arg: {
158
+ open: [
159
+ { s: '#DD #TX', a: '@arg-rest' },
160
+ { s: '#TX #TX', a: '@arg-modename' },
161
+ { s: '#TX', a: '@arg-name' },
162
+ ],
163
+ close: [
164
+ { s: '#QM #CL', a: '@arg-opt', p: 'argtype' },
165
+ { s: '#CL', p: 'argtype' },
166
+ { s: '#CA', a: '@arg-done', r: 'arg' },
167
+ { s: '#CP', a: '@arg-done', b: 1 },
168
+ ],
169
+ },
170
+ argtype: {
171
+ open: [
172
+ { s: '#OP', p: 'group' },
173
+ { p: 'type' },
174
+ ],
175
+ close: [
176
+ {},
177
+ ],
178
+ },
179
+ type: {
180
+ open: [
181
+ { s: '#TX', a: '@type-word' },
182
+ ],
183
+ close: [
184
+ { s: '#PI', r: 'type' },
185
+ {},
186
+ ],
187
+ },
188
+ group: {
189
+ open: [
190
+ { p: 'gmember' },
191
+ ],
192
+ close: [
193
+ { s: '#CP' },
194
+ ],
195
+ },
196
+ gmember: {
197
+ open: [
198
+ { s: '#TX #TX', a: '@gm-two' },
199
+ { s: '#TX', a: '@gm-one' },
200
+ ],
201
+ close: [
202
+ { s: '#CA', a: '@gm-done', r: 'gmember' },
203
+ { s: '#CP', a: '@gm-done', b: 1 },
204
+ ],
205
+ },
206
+ },
207
+ });
208
+ }
209
+ let sigParser = undefined;
210
+ function makeSigParser() {
211
+ if (undefined === sigParser) {
212
+ sigParser = new parser_1.Tabnas({ plugins: [sigGrammar] });
213
+ }
214
+ return sigParser;
215
+ }
216
+ // Parse ONE declaration line. A malformed line is an Error: the
217
+ // declaration is repository content, read at build and test time, so
218
+ // failing loudly is the right shape (the round-trip suite holds the
219
+ // gate).
220
+ function parseSigLine(line) {
221
+ const tn = makeSigParser();
222
+ tn.sigErrs.length = 0;
223
+ const out = tn.parse(line);
224
+ if (0 < tn.sigErrs.length) {
225
+ throw new Error('signature: bad declaration ' +
226
+ tn.sigErrs.join(',') + ': ' + line);
227
+ }
228
+ if (null == out || '' === out.name || '' === out.out) {
229
+ throw new Error('signature: incomplete declaration: ' + line);
230
+ }
231
+ return out;
232
+ }
233
+ // Render one argument of a signature -- the piece the LSP's
234
+ // signatureHelp parameters share with the whole-line renderer.
235
+ function renderSigArg(a) {
236
+ const type = undefined === a.group ? a.type :
237
+ '(' + a.group.map((g) => ('value' === g.mode ? '' : g.mode + ' ') + g.type).join(', ') + ')';
238
+ return (true === a.rest ? '...' : '') +
239
+ ('value' === a.mode || true === a.rest ? '' : a.mode + ' ') +
240
+ a.name +
241
+ (true === a.opt ? '?' : '') +
242
+ ': ' + type;
243
+ }
244
+ // Render the canonical line for a parsed signature -- the round-trip
245
+ // twin of parseSigLine, and the one renderer every consumer (hints,
246
+ // docs, LSP) uses.
247
+ function renderSig(sig) {
248
+ return sig.name + '(' +
249
+ sig.args.map(renderSigArg).join(', ') + ') : ' + sig.out;
250
+ }
251
+ // Parse the whole declaration text: comment (#) and blank lines are
252
+ // the loader's to skip, one FuncSig per remaining line, name-keyed.
253
+ // A duplicate name is an error for the same reason a bad line is.
254
+ function parseSigText(text) {
255
+ const reg = {};
256
+ for (const rawline of text.split('\n')) {
257
+ const line = rawline.trim();
258
+ if ('' === line || line.startsWith('#')) {
259
+ continue;
260
+ }
261
+ const sig = parseSigLine(line);
262
+ if (undefined !== reg[sig.name]) {
263
+ throw new Error('signature: duplicate declaration: ' + sig.name);
264
+ }
265
+ reg[sig.name] = sig;
266
+ }
267
+ return reg;
268
+ }
269
+ // The parsed registry, built once from the inlined declaration -- the
270
+ // one source every consumer (the arity tables, the runtime gate, the
271
+ // hints, the docs table, the LSP) reads. A parse failure here throws
272
+ // at module load: the inlined text is repository content whose parse
273
+ // the round-trip suite gates, so a failure is a build defect, not a
274
+ // runtime condition. Twin: funcSig in go/sig.go.
275
+ const funcSig = parseSigText(sigdecl_1.SIGDECL); /* node:coverage ignore next 9 */
276
+ exports.funcSig = funcSig;
277
+ //# sourceMappingURL=sig.js.map