aontu 0.57.0 → 0.59.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 (132) hide show
  1. package/README.md +2 -2
  2. package/dist/agentsmd.js +1 -1
  3. package/dist/alias.d.ts +3 -0
  4. package/dist/alias.js +59 -0
  5. package/dist/alias.js.map +1 -0
  6. package/dist/aontu.d.ts +4 -2
  7. package/dist/aontu.js +12 -3
  8. package/dist/aontu.js.map +1 -1
  9. package/dist/cli.d.ts +3 -1
  10. package/dist/cli.js +486 -4
  11. package/dist/cli.js.map +1 -1
  12. package/dist/ctx.d.ts +4 -0
  13. package/dist/ctx.js +3 -0
  14. package/dist/ctx.js.map +1 -1
  15. package/dist/err.js +6 -3
  16. package/dist/err.js.map +1 -1
  17. package/dist/format.js +8 -2
  18. package/dist/format.js.map +1 -1
  19. package/dist/hints.js +40 -9
  20. package/dist/hints.js.map +1 -1
  21. package/dist/lang.js +409 -58
  22. package/dist/lang.js.map +1 -1
  23. package/dist/lower.d.ts +20 -0
  24. package/dist/lower.js +575 -0
  25. package/dist/lower.js.map +1 -0
  26. package/dist/lsp.d.ts +1 -1
  27. package/dist/lsp.js +1 -1
  28. package/dist/lsp.js.map +1 -1
  29. package/dist/mcp-server.js +1 -1
  30. package/dist/mcp.d.ts +1 -0
  31. package/dist/mcp.js +40 -3
  32. package/dist/mcp.js.map +1 -1
  33. package/dist/render.d.ts +53 -0
  34. package/dist/render.js +542 -0
  35. package/dist/render.js.map +1 -0
  36. package/dist/sigdecl.js +1 -1
  37. package/dist/sigdecl.js.map +1 -1
  38. package/dist/std.d.ts +2 -0
  39. package/dist/std.js +498 -2
  40. package/dist/std.js.map +1 -1
  41. package/dist/template.d.ts +5 -0
  42. package/dist/template.js +257 -0
  43. package/dist/template.js.map +1 -0
  44. package/dist/tsconfig.tsbuildinfo +1 -1
  45. package/dist/type.d.ts +2 -0
  46. package/dist/type.js.map +1 -1
  47. package/dist/unify.js +43 -0
  48. package/dist/unify.js.map +1 -1
  49. package/dist/val/AggFuncVal.d.ts +1 -1
  50. package/dist/val/AggFuncVal.js +10 -21
  51. package/dist/val/AggFuncVal.js.map +1 -1
  52. package/dist/val/BagVal.js +1 -1
  53. package/dist/val/BagVal.js.map +1 -1
  54. package/dist/val/ConstraintVal.js +1 -1
  55. package/dist/val/DisjunctVal.js +33 -2
  56. package/dist/val/DisjunctVal.js.map +1 -1
  57. package/dist/val/EachFuncVal.d.ts +1 -1
  58. package/dist/val/EachFuncVal.js +8 -13
  59. package/dist/val/EachFuncVal.js.map +1 -1
  60. package/dist/val/EmitFuncVal.d.ts +23 -4
  61. package/dist/val/EmitFuncVal.js +298 -28
  62. package/dist/val/EmitFuncVal.js.map +1 -1
  63. package/dist/val/FilterFuncVal.js +8 -4
  64. package/dist/val/FilterFuncVal.js.map +1 -1
  65. package/dist/val/FormFuncVal.d.ts +14 -0
  66. package/dist/val/FormFuncVal.js +55 -0
  67. package/dist/val/FormFuncVal.js.map +1 -0
  68. package/dist/val/FuncBaseVal.js +36 -13
  69. package/dist/val/FuncBaseVal.js.map +1 -1
  70. package/dist/val/ListVal.js +9 -1
  71. package/dist/val/ListVal.js.map +1 -1
  72. package/dist/val/MapVal.d.ts +2 -1
  73. package/dist/val/MapVal.js +2 -1
  74. package/dist/val/MapVal.js.map +1 -1
  75. package/dist/val/PackFuncVal.d.ts +1 -1
  76. package/dist/val/PackFuncVal.js +22 -18
  77. package/dist/val/PackFuncVal.js.map +1 -1
  78. package/dist/val/PlaceVal.js +7 -2
  79. package/dist/val/PlaceVal.js.map +1 -1
  80. package/dist/val/RefVal.d.ts +3 -0
  81. package/dist/val/RefVal.js +181 -18
  82. package/dist/val/RefVal.js.map +1 -1
  83. package/dist/val/Val.d.ts +8 -1
  84. package/dist/val/Val.js +39 -1
  85. package/dist/val/Val.js.map +1 -1
  86. package/dist/val/members.d.ts +9 -0
  87. package/dist/val/members.js +52 -0
  88. package/dist/val/members.js.map +1 -0
  89. package/grammar/aontu.abnf +1 -1
  90. package/grammar/aontu.gbnf +1 -1
  91. package/grammar/aontu.lark +1 -1
  92. package/grammar/aontu.tmLanguage.json +1 -1
  93. package/package.json +1 -1
  94. package/skill/SKILL.md +4 -4
  95. package/skill/error-codes.md +1 -1
  96. package/skill/examples.md +1 -1
  97. package/skill/grammar-card.md +1 -1
  98. package/src/agentsmd.ts +1 -1
  99. package/src/alias.ts +112 -0
  100. package/src/aontu.ts +20 -2
  101. package/src/cli.ts +528 -4
  102. package/src/ctx.ts +18 -0
  103. package/src/err.ts +6 -3
  104. package/src/format.ts +12 -2
  105. package/src/hints.ts +47 -9
  106. package/src/lang.ts +453 -63
  107. package/src/lower.ts +636 -0
  108. package/src/lsp.ts +1 -1
  109. package/src/mcp-server.ts +1 -1
  110. package/src/mcp.ts +43 -4
  111. package/src/render.ts +727 -0
  112. package/src/sigdecl.ts +1 -1
  113. package/src/std.ts +506 -1
  114. package/src/template.ts +291 -0
  115. package/src/type.ts +10 -1
  116. package/src/unify.ts +47 -0
  117. package/src/val/AggFuncVal.ts +10 -21
  118. package/src/val/BagVal.ts +1 -1
  119. package/src/val/ConstraintVal.ts +1 -1
  120. package/src/val/DisjunctVal.ts +33 -2
  121. package/src/val/EachFuncVal.ts +8 -16
  122. package/src/val/EmitFuncVal.ts +376 -39
  123. package/src/val/FilterFuncVal.ts +11 -4
  124. package/src/val/FormFuncVal.ts +119 -0
  125. package/src/val/FuncBaseVal.ts +36 -13
  126. package/src/val/ListVal.ts +9 -1
  127. package/src/val/MapVal.ts +3 -2
  128. package/src/val/PackFuncVal.ts +23 -19
  129. package/src/val/PlaceVal.ts +7 -2
  130. package/src/val/RefVal.ts +193 -20
  131. package/src/val/Val.ts +75 -4
  132. package/src/val/members.ts +86 -0
package/skill/SKILL.md CHANGED
@@ -1,23 +1,23 @@
1
1
  ---
2
2
  name: aontu
3
3
  description: >-
4
- Write, check and query Aontu definitions — a JSON superset where
4
+ Write, check and query aontu definitions — a JSON superset where
5
5
  documents UNIFY instead of overwriting. Use when a repository holds
6
6
  `.aon` files, when configuration must satisfy a schema rather than
7
7
  merely parse, or when you need to ask what a configuration says at a
8
8
  path and why it says it.
9
9
  ---
10
10
 
11
- # Aontu
11
+ # aontu
12
12
 
13
- Aontu is JSON plus a lattice. Two documents do not override each
13
+ aontu is JSON plus a lattice. Two documents do not override each
14
14
  other, they **unify**: the result is the most specific value that
15
15
  satisfies both, or an error naming the contradiction. That makes a
16
16
  definition checkable, queryable and safe to change.
17
17
 
18
18
  Start here:
19
19
 
20
- - Every JSON document is an Aontu document. Write JSON, then add
20
+ - Every JSON document is an aontu document. Write JSON, then add
21
21
  what JSON cannot say.
22
22
  - [`grammar-card.md`](grammar-card.md) — the whole surface on one
23
23
  page.
@@ -1,6 +1,6 @@
1
1
  # What a refusal means
2
2
 
3
- Every Aontu error carries a **code**, and every code has a **class**.
3
+ Every aontu error carries a **code**, and every code has a **class**.
4
4
  The class says what kind of thing went wrong, which is what decides
5
5
  your next move. The full registry — every code, its class, and the
6
6
  version it appeared in — is
package/skill/examples.md CHANGED
@@ -1,4 +1,4 @@
1
- # Aontu by example
1
+ # aontu by example
2
2
 
3
3
  The ladder: start with the JSON you already know, add one thing at a
4
4
  time. Every rung is a valid document.
@@ -1,4 +1,4 @@
1
- # Aontu grammar card
1
+ # aontu grammar card
2
2
 
3
3
  Everything the language spells, on one page. The published machine
4
4
  grammars are [`grammar/aontu.abnf`](../grammar/aontu.abnf) — the
package/src/agentsmd.ts CHANGED
@@ -81,7 +81,7 @@ export function agentsMd(
81
81
  AGENTSMD_BEGIN,
82
82
  '## Ground truth: `' + name + '`',
83
83
  '',
84
- 'The values below are DERIVED from `' + name + '`, an Aontu',
84
+ 'The values below are DERIVED from `' + name + '`, an aontu',
85
85
  'definition. Do not restate them here — read them from the source,',
86
86
  'which is the only copy that cannot go stale.',
87
87
  '',
package/src/alias.ts ADDED
@@ -0,0 +1,112 @@
1
+ /* Copyright (c) 2021-2026 Richard Rodger, MIT License */
2
+
3
+ // ALIAS EXPANSION FOR CANON. An alias is a name for a value, and
4
+ // nothing more (docs/design/ALIASES.0.md §4): the declaration is
5
+ // erased from generation, canon and the hash, and a reference resolves
6
+ // to the value in place. One place a reference is NOT resolved in
7
+ // place is a spread template -- `[&: %unit]`, `{&: {a: %u}}` -- because
8
+ // a template applies to children that have not arrived, so it stands
9
+ // in the settled tree as the reference it was written as. Canon has
10
+ // erased the declaration, so the name alone would not reparse, and the
11
+ // hash of `t: {&: %u}` would differ from the hash of `t: {&: integer}`,
12
+ // which is the same document.
13
+ //
14
+ // This walk runs ONCE, after the last unification pass, and attaches
15
+ // to every standing alias reference the value it names, which its
16
+ // canon then renders instead of the name. The tree is not changed:
17
+ // the reference still stands, still resolves at each destination, and
18
+ // unification never reads the expansion.
19
+ //
20
+ // What a reference expands to. The ref-spread SNAPSHOT where one was
21
+ // taken (MapVal.snapshotRefSpread: a path-dependent template captured
22
+ // before its key()/path() resolved at the declaration), else the
23
+ // declaration's settled value at the root. The snapshot is the
24
+ // template the destinations actually saw; the settled value of
25
+ // `%row = {name: key()}` is `{name: "%row"}`, the leak the snapshot
26
+ // exists to prevent, and canon must not print it either.
27
+ //
28
+ // The knot. A recursive alias names itself inside its own template
29
+ // (`%json = null | ... | [&: %json] | {&: %json}`). Its expansion
30
+ // contains a reference to the name being expanded, and that reference
31
+ // keeps its name: canon cannot spell the declaration it erased, and
32
+ // an infinite unrolling is not a canon. Such a canon does not reparse
33
+ // on its own -- the one place alias erasure and canon convergence
34
+ // pull apart (use-cases/BUGS.md §82). Only the reference that closes
35
+ // the cycle is left as a name; everything up to it expands.
36
+ //
37
+ // Every value is visited once (templates are shared across
38
+ // destinations, and one declaration is reached through many
39
+ // references), children in code-point key order, so the two ports
40
+ // attach the same expansions in the same order and print one canon.
41
+ // Twin of expandAliases in go/alias.go.
42
+
43
+ import type { Val } from './type'
44
+
45
+ import { cmpCodePoint } from './keyorder'
46
+ import { spreadSnapKey } from './val/MapVal'
47
+
48
+
49
+ function expandAliases(root: Val, snapmap: Map<string, Val>): void {
50
+ if (true !== (root as any).isMap) {
51
+ return
52
+ }
53
+
54
+ const seen = new Set<Val>()
55
+
56
+ const visit = (v: any, stack: string[]): void => {
57
+ if (null == v || true !== v.isVal || seen.has(v)) {
58
+ return
59
+ }
60
+ seen.add(v)
61
+
62
+ if (true === v.isRef) {
63
+ const name: string | undefined = v.aliasName
64
+ if (undefined === name) {
65
+ return
66
+ }
67
+ v.expansion = undefined
68
+ if (stack.includes(name)) {
69
+ return
70
+ }
71
+ const target: Val | undefined =
72
+ snapmap.get(spreadSnapKey(v)) ?? (root as any).peg[name]
73
+ if (null == target) {
74
+ return
75
+ }
76
+ v.expansion = target
77
+ visit(target, [...stack, name])
78
+ return
79
+ }
80
+
81
+ if (true === v.isMap) {
82
+ // A declaration is reached through its references, each under
83
+ // its own name, never as a child: a self-reference inside it
84
+ // is a knot only from inside.
85
+ const keys = Object.keys(v.peg)
86
+ .filter((k: string) => !v.aliasKeys.includes(k))
87
+ .sort(cmpCodePoint)
88
+ for (const k of keys) {
89
+ visit(v.peg[k], stack)
90
+ }
91
+ }
92
+ else if (Array.isArray(v.peg)) {
93
+ for (const e of v.peg) {
94
+ visit(e, stack)
95
+ }
96
+ }
97
+ else if (null != v.peg && true === v.peg.isVal) {
98
+ visit(v.peg, stack)
99
+ }
100
+
101
+ if ((true === v.isMap || true === v.isList) && null != v.spread.cj) {
102
+ visit(v.spread.cj, stack)
103
+ }
104
+ }
105
+
106
+ visit(root, [])
107
+ } /* node:coverage ignore next 5 */
108
+
109
+
110
+ export {
111
+ expandAliases,
112
+ }
package/src/aontu.ts CHANGED
@@ -25,6 +25,8 @@ import { agentsMd } from './agentsmd'
25
25
  import { graphOf } from './graph'
26
26
  import { relationCheck, relationErrors } from './relation'
27
27
  import { view, viewSet, viewTree } from './view'
28
+ import { render, renderValue, renderProfile } from './render'
29
+ import { desugarTemplate, resugarTemplate, markerFor } from './template'
28
30
  import { format, unifiedDiff } from './format'
29
31
  export type { LintFinding, FormatReport, FormatOptions } from './format'
30
32
 
@@ -36,7 +38,7 @@ export type { LintFinding, FormatReport, FormatOptions } from './format'
36
38
  // Kept in step with package.json by the `version` npm lifecycle script,
37
39
  // which runs on `npm version` / `npm run repo-bump`. version.test.ts
38
40
  // fails if the two ever drift.
39
- const VERSION = '0.57.0'
41
+ const VERSION = '0.59.0'
40
42
 
41
43
 
42
44
  // A module file's VALUE, as far as it goes. COLLECTED, not raised: a
@@ -101,6 +103,7 @@ class Aontu {
101
103
  ctx(cfg?: AontuContextConfig): AontuContext {
102
104
  cfg = cfg ?? {}
103
105
  cfg.fs = cfg.fs ?? this.opts.fs
106
+ ;(cfg as any).errfs = (cfg as any).errfs ?? (this.opts as any).errfs
104
107
  // The trust profile rides the instance (its resolver is built once,
105
108
  // in the Lang constructor); the context needs it too, for the
106
109
  // budgets (G5, docs/trust.md).
@@ -287,7 +290,7 @@ class Aontu {
287
290
  if (err instanceof AontuError || true === err.aontu) {
288
291
  throw err
289
292
  }
290
- const unex = new AontuError('Aontu: unexpected error: ' + err.message)
293
+ const unex = new AontuError('aontu: unexpected error: ' + err.message)
291
294
  Object.assign(unex, err)
292
295
  unex.stack = err.stack
293
296
  throw unex
@@ -478,6 +481,21 @@ export {
478
481
  viewSet,
479
482
  viewTree,
480
483
 
484
+ // G9 -- the renderer (docs/design/RENDER.0.md): evaluate, vet and
485
+ // fold an aontu:code instance into bytes, or the fold alone over
486
+ // generate() output.
487
+ render,
488
+ renderValue,
489
+ renderProfile,
490
+
491
+ // The template surface (docs/design/TEMPLATE.0.md): the two text
492
+ // transforms behind `aontu template`, and the marker an extension
493
+ // names. Neither evaluates anything -- a template is a spelling of
494
+ // a generator, so the transforms are text in and text out.
495
+ desugarTemplate,
496
+ resugarTemplate,
497
+ markerFor,
498
+
481
499
  // The source formatter (docs/design/FMT.0.md): the agreed form of a
482
500
  // document, and the unified diff `aontu fmt --diff` prints.
483
501
  format,