@cavelang/canonical 0.35.0 → 0.36.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.
- package/README.md +234 -3
- package/dist/src/canonicalize.d.ts.map +1 -1
- package/dist/src/canonicalize.js +31 -2
- package/dist/src/canonicalize.js.map +1 -1
- package/dist/src/emit.d.ts +5 -0
- package/dist/src/emit.d.ts.map +1 -1
- package/dist/src/emit.js +239 -52
- package/dist/src/emit.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/package.json +4 -4
- package/src/canonicalize.ts +27 -3
- package/src/emit.ts +238 -62
- package/src/index.ts +1 -1
package/README.md
CHANGED
|
@@ -51,9 +51,11 @@ preserves direction and makes reverse reads return the preferred opposite name.
|
|
|
51
51
|
nodes joined to the parent by role edges. `UNLESS x` normalizes to
|
|
52
52
|
role `WHEN` + negated condition. Condition shapes:
|
|
53
53
|
- bare entity → `x EXISTS` claim (negated for `NOT x`);
|
|
54
|
-
- comparison → a
|
|
54
|
+
- comparison → a claim with a canonical verb: `>` → `EXCEEDS`,
|
|
55
55
|
`<` → `IS-BELOW`, `>=` → `IS-AT-LEAST`, `<=` → `IS-AT-MOST`,
|
|
56
|
-
`=` → `EQUALS`, and `!=` → `DIFFERS-FROM
|
|
56
|
+
`=` → `EQUALS`, and `!=` → `DIFFERS-FROM`. Numbers, dates and trajectories
|
|
57
|
+
become metrics; text/code literals and ordinary words become relations,
|
|
58
|
+
matching ordinary claim parsing so payload identity survives emission;
|
|
57
59
|
- full claim → canonicalized as usual (inverse resolution applies).
|
|
58
60
|
- **Grouped claims** (§8.4): indented full triples stay independent and
|
|
59
61
|
link to their parent with the `QUALIFIES` edge role (§13.2's role list).
|
|
@@ -80,6 +82,14 @@ preserves direction and makes reverse reads return the preferred opposite name.
|
|
|
80
82
|
- recursive factoring of adjacent sibling claims through shared incomplete
|
|
81
83
|
prefixes, stopping before a header would itself parse as a complete claim.
|
|
82
84
|
|
|
85
|
+
Text round trips apply the parser's comment normalization: CRLF physical line
|
|
86
|
+
endings become LF, trailing whitespace on comment lines is removed, and empty
|
|
87
|
+
lines at the combined comment's edges are dropped. Interior blank paragraphs
|
|
88
|
+
and leading indentation within nonempty comment lines survive. Consequently,
|
|
89
|
+
programmatically supplied comments can reparse with different whitespace even
|
|
90
|
+
though their claim keys remain the same. Emission does not mutate the supplied
|
|
91
|
+
claim. Use exact SQLite snapshots when preserving stored comment bytes matters.
|
|
92
|
+
|
|
83
93
|
For example, two canonical rows emit tersely without changing their keys:
|
|
84
94
|
|
|
85
95
|
```cave
|
|
@@ -92,12 +102,231 @@ The same factoring applies inside qualifier/grouping trees. Transaction
|
|
|
92
102
|
annotations remain directly above each materialized leaf, so annotated export
|
|
93
103
|
and sync preserve row identity.
|
|
94
104
|
|
|
105
|
+
Transaction annotations may carry an optional JSON provenance payload on the
|
|
106
|
+
same line. `txOfLine` reads the ID and `txDataOfLine` exposes the payload for
|
|
107
|
+
sync validation. `EmitOptions.annotate` preserves it through factoring and
|
|
108
|
+
repeated lineage references; ordinary claim parsing ignores the metadata.
|
|
109
|
+
|
|
110
|
+
Canonical confidence emission preserves the full stored number, including computed
|
|
111
|
+
and subnormal values. Percentages use decimal notation without rounding or
|
|
112
|
+
exponents; parsing shifts the decimal point before converting to a number.
|
|
113
|
+
|
|
95
114
|
Emission of a complete canonicalization result is stable:
|
|
96
115
|
`emit ∘ canonicalize ∘ emit ≡ emit`, and claim keys survive the round trip
|
|
97
116
|
(tested). Comparison rows are valid CAVE both under their qualifier edge and
|
|
98
117
|
when emitted in isolation, which keeps storage fallbacks and citations
|
|
99
118
|
parseable.
|
|
100
119
|
|
|
120
|
+
The emitter uses `@claim` when an unmarked full claim would be read as a
|
|
121
|
+
qualifier or continuation. `@claim WHEN IS ready` keeps `WHEN` as an entity;
|
|
122
|
+
`@claim IS EXISTS` keeps `IS` as an affirmative bare-existence subject. An
|
|
123
|
+
explicit qualifier payload such as `WHEN @claim NOT EXISTS` preserves the
|
|
124
|
+
entity `NOT` without consuming it as negation. Conditions whose verb is `NOT`
|
|
125
|
+
also need the marker: `WHEN @claim item NOT ready`; a negated condition emits
|
|
126
|
+
as `WHEN NOT @claim item NOT ready`. A trailing `@claim` remains an
|
|
127
|
+
ordinary context, independent of the leading marker. Existing unmarked
|
|
128
|
+
continuation and qualifier rules are unchanged.
|
|
129
|
+
|
|
130
|
+
Sigma overrides emit positive finite plain decimals, including magnitudes for
|
|
131
|
+
which JavaScript uses scientific notation. For example, sigma level `1e-7`
|
|
132
|
+
emits as `(0.0000001σ)`. Invalid structured sigma levels fail emission.
|
|
133
|
+
Uncertainty deltas likewise require a positive finite scalar, including when
|
|
134
|
+
emitted directly from structured claims; zero, negative and nonnumeric values
|
|
135
|
+
fail before producing CAVE text.
|
|
136
|
+
|
|
137
|
+
The marker changes no claim fields, keys, edges or metadata. Readers of exports
|
|
138
|
+
using it must support explicit claims. `node scripts/reserved-subject-audit.mjs`
|
|
139
|
+
checks 510 reserved-name/verb/placement/polarity cases and exits nonzero on any
|
|
140
|
+
mismatch in diagnostics, keys or edges. Literal quoting is not used to change
|
|
141
|
+
entity kinds as a workaround.
|
|
142
|
+
|
|
143
|
+
The emission composition regression exercises 4,928 parser-accepted combinations
|
|
144
|
+
of subjects, verbs, payload forms and metadata. It compares every semantic claim
|
|
145
|
+
field (including confidence, uncertainty and comments), graph edges and second-
|
|
146
|
+
emission text stability. Raw source spelling and line locations intentionally
|
|
147
|
+
change during canonicalization. This finite corpus complements the reserved-name
|
|
148
|
+
and malformed structured-input checks; it is not an exhaustive grammar proof.
|
|
149
|
+
|
|
150
|
+
### Structured claim validation
|
|
151
|
+
|
|
152
|
+
`emitClaim` and `emit` reject these programmatically constructed fields with a
|
|
153
|
+
`TypeError` before returning canonical text:
|
|
154
|
+
|
|
155
|
+
| Field | Rejected input | Supported representation |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| Context and tag collections | Non-arrays, including strings, sets and array-like objects | Supply arrays; `Claim.of` defaults omitted collections to empty arrays. |
|
|
158
|
+
| Term text and value raw text | Non-strings, including arrays and boxed strings | Supply primitive strings; emission does not coerce data into literal text. |
|
|
159
|
+
| Term and payload kinds | Missing or unsupported kind names | Terms use `entity`, `text` or `code`; payloads use `relation`, `attribute`, `metric` or `none`. Unknown kinds are rejected rather than emitted as an entity or dropped. |
|
|
160
|
+
| Negation and importance | Any non-boolean, including missing fields, `null`, numbers and strings | Supply `true` or `false`; `Claim.of` provides defaults. This also applies to qualifier claims. |
|
|
161
|
+
| Subject, verb, payload or metadata | Embedded LF newline | Put multiline commentary in the claim's comment. |
|
|
162
|
+
| Text or code literal | Its own closing delimiter: a double quote in text, or a backtick in code | The other delimiter remains ordinary content. |
|
|
163
|
+
| Rendered claim body | An unquoted comment start or unmatched literal delimiter | Keep comment text in the comment field and delimit literal content completely. |
|
|
164
|
+
| Entity relation object | Text that reparses as a metric, attribute, literal, negation or metadata, or has no object | Use the appropriate payload kind or an explicit text/code literal. Ordinary object phrases retain whitespace normalization. |
|
|
165
|
+
| Value fields, including uncertainty deltas | Kind, numeric fields, units or approximation flags that disagree with raw text | Construct values with `Value.parse`, `Value.ofText` or `Value.ofCode`. |
|
|
166
|
+
| Unquoted value text | Empty text, metadata tokens, literal syntax mislabeled as unquoted, or whitespace that tokenization changes | Use canonical single spaces between words; use text/code literals for exact whitespace or metadata-looking content. |
|
|
167
|
+
| Metric payload | An atom, text or code value | Metrics use numbers, dates or trajectories; use relations or attributes for other values. |
|
|
168
|
+
| Empty payload | A verb other than `EXISTS` | Supply an object/value, or use `EXISTS` for bare existence. |
|
|
169
|
+
| Attribute name | Empty text, token splits, literal syntax or a metadata prefix | One non-metadata word followed by the emitted colon; embedded colons and Unicode remain supported. |
|
|
170
|
+
| Context or tag | Empty metadata tokens, whitespace/comment splits, or a tag key that reparses as a key/value pair | Contexts retain their complete token; colons in scoped tag values remain supported. |
|
|
171
|
+
| Verb | Anything other than an uppercase atom | Uppercase letters and hyphens, starting with a letter; extension verbs and trailing hyphens are accepted. |
|
|
172
|
+
| Entity subject | Empty text, multiple tokens, a comment start, metadata, or literal syntax mislabeled as an entity | Use a text or code term when the subject needs literal syntax. |
|
|
173
|
+
|
|
174
|
+
These checks also apply to abbreviated existence qualifiers such as `WHEN
|
|
175
|
+
subject`, their metadata, and their negated forms. Multiline comments retain
|
|
176
|
+
their separate comment lines. Object phrases retain the existing parsing and
|
|
177
|
+
canonical normalization rules.
|
|
178
|
+
Bare carriage returns inside text and code literal values remain literal content:
|
|
179
|
+
emission and parsing preserve their exact value and claim key. Embedded LF,
|
|
180
|
+
including the LF in CRLF, remains rejected in structured claim fields.
|
|
181
|
+
|
|
182
|
+
For graph input, `emit` requires every edge's `parent` and `child` to be
|
|
183
|
+
non-negative safe integer indices within the claims array, and its `role` to be
|
|
184
|
+
`WHEN`, `VIA`, `BECAUSE` or `QUALIFIES`. It captures those fields once and validates
|
|
185
|
+
all edges before rendering or invoking annotation callbacks. Invalid edges throw
|
|
186
|
+
`TypeError` instead of silently disappearing or becoming ordinary claim text.
|
|
187
|
+
Shared premises and cycles retain their existing re-statement behavior.
|
|
188
|
+
The claims collection must be a dense array with an own entry at every index.
|
|
189
|
+
Sparse arrays throw `TypeError` before annotation callbacks run instead of
|
|
190
|
+
silently omitting their holes. Rejection leaves the supplied array unchanged;
|
|
191
|
+
passing a corrected dense collection permits a fresh emission.
|
|
192
|
+
|
|
193
|
+
`EmitOptions.annotate` runs in depth-first appearance order, including each
|
|
194
|
+
re-statement of a shared or cyclic claim. The same claim index can therefore
|
|
195
|
+
reach the callback more than once. For replayable text, derive the annotation
|
|
196
|
+
from a stable transaction ID associated with that index; generating a new ID on
|
|
197
|
+
every callback invocation would give one graph claim several identities.
|
|
198
|
+
The returned string is emitted verbatim. Return `undefined` for appearances
|
|
199
|
+
that need no annotation; the emitter does not validate transaction IDs or
|
|
200
|
+
annotation payloads on the callback's behalf.
|
|
201
|
+
If an annotation callback throws, emission propagates that error and stops
|
|
202
|
+
invoking callbacks. A fresh call starts traversal again; the emitter does not
|
|
203
|
+
retain partial graph state or undo side effects performed by the callback.
|
|
204
|
+
|
|
205
|
+
Graph expansion and text rendering use explicit traversal stacks, so deep
|
|
206
|
+
qualifier chains do not consume one JavaScript call frame per level. A
|
|
207
|
+
3,000-claim support chain closing into a cycle is covered by a regression that
|
|
208
|
+
checks every emitted line and annotation visit in order. This removes the
|
|
209
|
+
recursive call-stack limit; it does not cap graph size or output memory.
|
|
210
|
+
Indentation still grows with depth, so a long single chain produces text whose
|
|
211
|
+
size grows quadratically with the number of claims.
|
|
212
|
+
Sibling-prefix checks, metadata appends and multiline-comment rendering also
|
|
213
|
+
avoid spreading unbounded arrays into function arguments. Regressions cover
|
|
214
|
+
130,000 sibling claims and a 130,000-line comment. The renderer retains each
|
|
215
|
+
sibling group's end and skips prefix factoring for one-token leaves, avoiding
|
|
216
|
+
repeated scans and copies of those remaining siblings. These checks establish
|
|
217
|
+
specific workloads, not a general output-size or processing-time limit.
|
|
218
|
+
The deep-cycle and broad-sibling regressions also canonicalize the emitted text
|
|
219
|
+
without diagnostics, check the resulting claim and edge counts, and verify that
|
|
220
|
+
re-emission is byte-for-byte stable. Plain text represents a cycle's closing
|
|
221
|
+
reference as a repeated claim; transaction annotations supply identity when
|
|
222
|
+
replay must reconstruct shared graph rows.
|
|
223
|
+
The 130,000-line comment fixture also parses back into one claim with its entire
|
|
224
|
+
comment unchanged and re-emits identically, including the final inline comment
|
|
225
|
+
line. This checks both comment rendering and reconstruction at that size.
|
|
226
|
+
The renderer also checks once per sibling group whether its shared first token
|
|
227
|
+
already completes a claim. If so, no suffix can use it as a factored header;
|
|
228
|
+
the remaining siblings render directly. This avoids repeated suffix scans for
|
|
229
|
+
groups such as `EXISTS @ 70%` beneath an inherited subject prefix, while retaining
|
|
230
|
+
confidence metadata and allowing later groups to factor normally.
|
|
231
|
+
|
|
232
|
+
CAVE has no literal escape syntax. Emission does not rewrite the supplied claim
|
|
233
|
+
or change its literal kind to make invalid content fit. These checks cover the
|
|
234
|
+
listed boundaries; they do not establish that every malformed programmatic
|
|
235
|
+
claim is validated. The store applies them during
|
|
236
|
+
[structured appends](../store/README.md#structured-appends), including when raw
|
|
237
|
+
text is supplied. Historical rows remain unchanged. In particular, previously
|
|
238
|
+
stored metrics containing atom/text/code values now fail emission instead of
|
|
239
|
+
silently changing payload identity; this validation does not migrate them.
|
|
240
|
+
|
|
241
|
+
`canonicalize` and `canonicalizeText` run the same validation before accepting
|
|
242
|
+
claims. Rejected lines produce diagnostics and do not add claims, edges or
|
|
243
|
+
registry declarations. This includes unterminated delimiters that the tolerant
|
|
244
|
+
tokenizer represents as words. Descendant continuations and qualifiers report
|
|
245
|
+
a missing canonicalized parent when their parent was rejected. Grouped full
|
|
246
|
+
claims remain independent (§8.4): they survive a rejected parent, with a
|
|
247
|
+
diagnostic for the missing grouping edge, and retain their own descendants and
|
|
248
|
+
declarations. Store ingestion
|
|
249
|
+
keeps valid lines in lenient mode; strict mode rejects the whole input.
|
|
250
|
+
|
|
251
|
+
Unquoted relation objects are checked against the parser's payload classification
|
|
252
|
+
before emission. ASCII names starting with a letter or underscore, followed by letters, digits,
|
|
253
|
+
underscores, dots, slashes or hyphens, use a lexical fast path except for `NOT`; other objects use the parser and retain the existing entity
|
|
254
|
+
whitespace normalization. This check does not convert a relation into a metric,
|
|
255
|
+
attribute or literal on the caller's behalf.
|
|
256
|
+
|
|
257
|
+
### Emission cost
|
|
258
|
+
|
|
259
|
+
Fully uppercase entity subjects also run document classification to determine
|
|
260
|
+
whether `@claim` is needed. The subject/object benchmarks below do not measure
|
|
261
|
+
that path.
|
|
262
|
+
|
|
263
|
+
Common ASCII entity subjects use a fast lexical check; other subjects retain
|
|
264
|
+
the parser-based validation. Both paths reject the same malformed boundaries.
|
|
265
|
+
The ASCII check requires the actual end of input, so a terminal line break
|
|
266
|
+
cannot pass as an ordinary name. Character-boundary tests compare emission
|
|
267
|
+
with the parser's decisions across ASCII controls, punctuation and Unicode.
|
|
268
|
+
|
|
269
|
+
Run `node scripts/subject-emission-bench.mjs` from the repository root to measure
|
|
270
|
+
20,000 independent claim emissions per family. Fixture creation and output
|
|
271
|
+
checks are untimed; two warmup passes precede seven measured passes. On the
|
|
272
|
+
review machine, medians before and after the ASCII fast path were:
|
|
273
|
+
|
|
274
|
+
| Node | ASCII subjects | Unicode subjects | Literal subjects |
|
|
275
|
+
|---|---:|---:|---:|
|
|
276
|
+
| 24.16.0 | 33.046 → 3.410 ms | 32.760 → 33.310 ms | 2.747 → 2.852 ms |
|
|
277
|
+
| 26.5.0 | 30.807 → 3.341 ms | 34.530 → 33.801 ms | 2.442 → 2.490 ms |
|
|
278
|
+
|
|
279
|
+
These are local emitter measurements, not end-to-end store or export timings.
|
|
280
|
+
Unicode subjects retain the full parser path; no general speedup is claimed.
|
|
281
|
+
|
|
282
|
+
After adding comment-boundary validation, the same benchmark measured:
|
|
283
|
+
|
|
284
|
+
| Node | ASCII subjects | Unicode subjects | Literal subjects |
|
|
285
|
+
|---|---:|---:|---:|
|
|
286
|
+
| 24.16.0 | 4.565 ms | 36.289 ms | 6.771 ms |
|
|
287
|
+
| 26.5.0 | 4.350 ms | 35.791 ms | 6.188 ms |
|
|
288
|
+
|
|
289
|
+
Bodies containing quotes, backticks or semicolons now also run the comment
|
|
290
|
+
splitter to verify that a following comment remains outside the claim body.
|
|
291
|
+
The simple ASCII case avoids that scan. These measurements include the added
|
|
292
|
+
validation and retain the same benchmark limits above.
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
With relation identity validation, the same benchmark measured:
|
|
296
|
+
|
|
297
|
+
| Runtime | ASCII subjects | Unicode subjects | Literal subjects |
|
|
298
|
+
|---|---:|---:|---:|
|
|
299
|
+
| Node 24.16.0 | 4.792 ms | 34.414 ms | 6.979 ms |
|
|
300
|
+
| Node 26.5.0 | 4.772 ms | 37.184 ms | 6.767 ms |
|
|
301
|
+
|
|
302
|
+
All three families use the alphabetic object `retained`, exercising the object
|
|
303
|
+
fast path. These numbers do not measure the parser fallback for other objects.
|
|
304
|
+
The initial version parsed every entity relation and measured 51.512/46.762 ms
|
|
305
|
+
for the ASCII family on Node 24/26, motivating the narrow lexical fast path.
|
|
306
|
+
|
|
307
|
+
Object-shape costs can be reproduced with `node scripts/object-emission-bench.mjs`.
|
|
308
|
+
This uses 20,000 claims per shape, two warmups and seven measured passes; fixture
|
|
309
|
+
creation, full output checks and representative semantic round trips are untimed.
|
|
310
|
+
Expanding the object fast path to letter/underscore-led names with digits, dots,
|
|
311
|
+
slashes and hyphens measured the following local medians:
|
|
312
|
+
|
|
313
|
+
| Object shape | Node 24 before | Node 24 after | Node 26 before | Node 26 after |
|
|
314
|
+
|---|---:|---:|---:|---:|
|
|
315
|
+
| Alphabetic | 4.489 ms | 4.485 ms | 4.597 ms | 4.249 ms |
|
|
316
|
+
| Hyphenated with digits | 60.024 ms | 4.714 ms | 52.084 ms | 4.507 ms |
|
|
317
|
+
| Scoped path | 58.492 ms | 4.065 ms | 56.606 ms | 3.710 ms |
|
|
318
|
+
| Object phrase | 90.963 ms | 88.563 ms | 81.158 ms | 79.319 ms |
|
|
319
|
+
| Unicode name | 57.232 ms | 56.716 ms | 55.710 ms | 56.462 ms |
|
|
320
|
+
| Text literal | 7.214 ms | 7.360 ms | 8.213 ms | 6.586 ms |
|
|
321
|
+
| Code literal | 6.569 ms | 6.886 ms | 6.079 ms | 6.204 ms |
|
|
322
|
+
|
|
323
|
+
These Node 24.16.0/26.5.0 measurements isolate emission on this machine, not
|
|
324
|
+
end-to-end ingestion. Phrases and Unicode names still use the parser fallback;
|
|
325
|
+
small differences in unchanged paths are measurement variation. The parser
|
|
326
|
+
comparison test covers accepted names and adjacent reserved syntax across three
|
|
327
|
+
verbs. `NOT`, numeric/date prefixes, colons, whitespace and metadata remain
|
|
328
|
+
outside the fast path.
|
|
329
|
+
|
|
101
330
|
## Design decisions
|
|
102
331
|
|
|
103
332
|
- **"As written" inheritance**: a continuation under an inverse-form parent
|
|
@@ -109,7 +338,9 @@ parseable.
|
|
|
109
338
|
endpoint is a metric payload in one direction and a subject term in the
|
|
110
339
|
other, so `deploy PRECEDES 2026-01-01` and `2026-01-01 FOLLOWS deploy`
|
|
111
340
|
land on one claim key. Qualifier negation always emits as the `WHEN NOT …`
|
|
112
|
-
prefix
|
|
341
|
+
prefix; an affirmative entity named `NOT` or a condition with verb `NOT` uses
|
|
342
|
+
an explicit claim marker.
|
|
343
|
+
A claim-internal `VERB NOT` after a symbolic comparison operator
|
|
113
344
|
would invert the condition on reparse.
|
|
114
345
|
- **Undeclared inverse continuations** (§8.3 calls them ill-formed) cannot
|
|
115
346
|
be *detected* — `PART-OF` without a declaration is just an unknown verb,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalize.d.ts","sourceRoot":"","sources":["../../src/canonicalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,EAAuB,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAiB,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"canonicalize.d.ts","sourceRoot":"","sources":["../../src/canonicalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,EAAuB,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAiB,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAGzC,wDAAwD;AACxD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,WAAW,CAAA;AAE/D,sDAAsD;AACtD,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,yDAAyD;AACzD,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAA;IACjC,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAA;IAC/B,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAA;CACtC,CAAA;AA0ED,uCAAuC;AACvC,eAAO,MAAM,YAAY,GAAI,UAAU,GAAG,CAAC,QAAQ,EAAE,WAAU,QAAQ,CAAC,CAAkB,KAAG,MAiK5F,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,EAAE,WAAU,QAAQ,CAAC,CAAkB,KAAG,MAavF,CAAA"}
|
package/dist/src/canonicalize.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import { Claim, Entity, Value, Verb } from '@cavelang/core';
|
|
23
23
|
import { parseDocument } from '@cavelang/parser';
|
|
24
24
|
import * as Registry from "./registry.js";
|
|
25
|
+
import { emitClaim } from "./emit.js";
|
|
25
26
|
const roleOf = {
|
|
26
27
|
WHEN: 'WHEN',
|
|
27
28
|
UNLESS: 'WHEN',
|
|
@@ -66,6 +67,17 @@ const payloadOfTerm = (term) => {
|
|
|
66
67
|
}
|
|
67
68
|
return Claim.relation(term);
|
|
68
69
|
};
|
|
70
|
+
/** Match ordinary claim parsing so comparison emission keeps its payload identity. */
|
|
71
|
+
const comparisonPayload = (value) => {
|
|
72
|
+
switch (value.kind) {
|
|
73
|
+
case 'number':
|
|
74
|
+
case 'date':
|
|
75
|
+
case 'trajectory': return Claim.metric(value);
|
|
76
|
+
case 'text': return Claim.relation(Claim.text(value.raw));
|
|
77
|
+
case 'code': return Claim.relation(Claim.code(value.raw));
|
|
78
|
+
default: return Claim.relation(Claim.entity(Entity.normalize(value.raw)));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
69
81
|
const initOf = (meta) => ({
|
|
70
82
|
contexts: meta.contexts,
|
|
71
83
|
tags: meta.tags,
|
|
@@ -117,6 +129,15 @@ export const canonicalize = (document, registry = Registry.empty) => {
|
|
|
117
129
|
return { claim, writtenSubject };
|
|
118
130
|
};
|
|
119
131
|
const append = (claim, line, writtenSubject, lineIndex) => {
|
|
132
|
+
try {
|
|
133
|
+
emitClaim(claim);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (!(error instanceof TypeError))
|
|
137
|
+
throw error;
|
|
138
|
+
problem(line, error.message);
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
120
141
|
const index = claims.length;
|
|
121
142
|
claims.push({ claim, line });
|
|
122
143
|
byLine.set(lineIndex, { index, writtenSubject });
|
|
@@ -170,7 +191,7 @@ export const canonicalize = (document, registry = Registry.empty) => {
|
|
|
170
191
|
subject: payload.left,
|
|
171
192
|
verb: comparisonVerbs[payload.op],
|
|
172
193
|
negated: payload.negated !== unless,
|
|
173
|
-
payload:
|
|
194
|
+
payload: comparisonPayload(payload.value),
|
|
174
195
|
meta: payload.meta
|
|
175
196
|
};
|
|
176
197
|
}
|
|
@@ -180,11 +201,16 @@ export const canonicalize = (document, registry = Registry.empty) => {
|
|
|
180
201
|
case 'claim': {
|
|
181
202
|
const { claim, writtenSubject } = buildClaim(line.claim, line.expanded ?? line.raw, line.line);
|
|
182
203
|
const index = append(claim, line.line, writtenSubject, lineIndex);
|
|
204
|
+
if (index === undefined)
|
|
205
|
+
return;
|
|
183
206
|
if (line.parent !== undefined) {
|
|
184
207
|
const parent = byLine.get(line.parent);
|
|
185
208
|
if (parent !== undefined) {
|
|
186
209
|
edges.push({ parent: parent.index, role: 'QUALIFIES', child: index });
|
|
187
210
|
}
|
|
211
|
+
else {
|
|
212
|
+
problem(line.line, 'grouped claim has no canonicalized parent — keeping the independent claim (spec §8.4)');
|
|
213
|
+
}
|
|
188
214
|
}
|
|
189
215
|
applyDeclarations(claim, line.line);
|
|
190
216
|
return;
|
|
@@ -197,7 +223,8 @@ export const canonicalize = (document, registry = Registry.empty) => {
|
|
|
197
223
|
}
|
|
198
224
|
const full = { subject: parent.writtenSubject, ...line.body };
|
|
199
225
|
const { claim, writtenSubject } = buildClaim(full, line.expanded ?? line.raw, line.line);
|
|
200
|
-
append(claim, line.line, writtenSubject, lineIndex)
|
|
226
|
+
if (append(claim, line.line, writtenSubject, lineIndex) === undefined)
|
|
227
|
+
return;
|
|
201
228
|
// §8.3: each continuation is an ordinary independent claim, so an
|
|
202
229
|
// in-band declaration works here exactly as on a full line (§5.4).
|
|
203
230
|
applyDeclarations(claim, line.line);
|
|
@@ -212,6 +239,8 @@ export const canonicalize = (document, registry = Registry.empty) => {
|
|
|
212
239
|
const full = conditionOf(line.payload, line.qualifier === 'UNLESS');
|
|
213
240
|
const { claim, writtenSubject } = buildClaim(full, line.expanded ?? line.raw, line.line);
|
|
214
241
|
const index = append(claim, line.line, writtenSubject, lineIndex);
|
|
242
|
+
if (index === undefined)
|
|
243
|
+
return;
|
|
215
244
|
edges.push({ parent: parent.index, role: roleOf[line.qualifier], child: index });
|
|
216
245
|
return;
|
|
217
246
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalize.js","sourceRoot":"","sources":["../../src/canonicalize.ts"],"names":[],"mappings":"AAAA;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AAA;IAC/C,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO;QACL,GAAG,MAAM;QACT,QAAQ,EAAE;YACR,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;YACnG,GAAG,MAAM,CAAC,QAAQ;SACnB;KACF,CAAA;AACH,CAAC,CAAA"}
|
package/dist/src/emit.d.ts
CHANGED
|
@@ -30,12 +30,17 @@ export declare const txComment: (tx: string) => string;
|
|
|
30
30
|
* caller validates the id shape.
|
|
31
31
|
*/
|
|
32
32
|
export declare const txOfLine: (raw: string) => undefined | string;
|
|
33
|
+
/** Optional annotation payload, interpreted by the interchange reader. */
|
|
34
|
+
export declare const txDataOfLine: (raw: string) => undefined | string;
|
|
33
35
|
export type EmitOptions = {
|
|
34
36
|
/**
|
|
35
37
|
* Per-claim annotation lines (spec §28.4): when defined for a claim
|
|
36
38
|
* index, the returned text is emitted verbatim as its own line directly
|
|
37
39
|
* above that claim, at the claim's indentation. Used by tx-carrying
|
|
38
40
|
* export ({@link txComment}); return `undefined` to annotate nothing.
|
|
41
|
+
* Called in depth-first appearance order, including every re-statement
|
|
42
|
+
* of a shared or cyclic claim. Repeated appearances use the same index;
|
|
43
|
+
* return a stable transaction identity for that index when enabling replay.
|
|
39
44
|
*/
|
|
40
45
|
readonly annotate?: (index: number) => undefined | string;
|
|
41
46
|
};
|
package/dist/src/emit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAqD,MAAM,gBAAgB,CAAA;AAEzF,OAAO,KAAK,KAAK,YAAY,MAAM,mBAAmB,CAAA;AA+KtD;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,KAAK,CAAC,CAAC,KAAG,MACa,CAAA;AA0BxD;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GAAI,IAAI,MAAM,KAAG,MAC3B,CAAA;AAEZ;;;;GAIG;AACH,eAAO,MAAM,QAAQ,qCAAiB,CAAA;AAEtC,0EAA0E;AAC1E,eAAO,MAAM,YAAY,qCAAqB,CAAA;AAE9C,MAAM,MAAM,WAAW,GAAG;IACxB;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,GAAG,MAAM,CAAA;CAC1D,CAAA;AAsID;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,IAAI,GAAI,QAAQ,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,EAAE,UAAS,WAAgB,KAAG,MAqEvG,CAAA"}
|