@beehexa/hexasync-template-validate 2611.8.2 → 2611.8.3

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 (62) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +3 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/validate/agentTools.d.ts +2 -0
  6. package/dist/validate/agentTools.d.ts.map +1 -1
  7. package/dist/validate/agentTools.js +9 -1
  8. package/dist/validate/agentTools.js.map +1 -1
  9. package/dist/validate/answerAgentTool.d.ts.map +1 -1
  10. package/dist/validate/answerAgentTool.js +18 -1
  11. package/dist/validate/answerAgentTool.js.map +1 -1
  12. package/dist/validate/buildValidationModel.d.ts +2 -0
  13. package/dist/validate/buildValidationModel.d.ts.map +1 -1
  14. package/dist/validate/buildValidationModel.js +1 -0
  15. package/dist/validate/buildValidationModel.js.map +1 -1
  16. package/dist/validate/context.d.ts +4 -0
  17. package/dist/validate/context.d.ts.map +1 -1
  18. package/dist/validate/context.js +1 -0
  19. package/dist/validate/context.js.map +1 -1
  20. package/dist/validate/contextFromGraph.d.ts +1 -0
  21. package/dist/validate/contextFromGraph.d.ts.map +1 -1
  22. package/dist/validate/contextFromGraph.js +1 -0
  23. package/dist/validate/contextFromGraph.js.map +1 -1
  24. package/dist/validate/frontendFlags.d.ts +14 -0
  25. package/dist/validate/frontendFlags.d.ts.map +1 -0
  26. package/dist/validate/frontendFlags.js +31 -0
  27. package/dist/validate/frontendFlags.js.map +1 -0
  28. package/dist/validate/frontendReferences.d.ts +10 -0
  29. package/dist/validate/frontendReferences.d.ts.map +1 -0
  30. package/dist/validate/frontendReferences.js +924 -0
  31. package/dist/validate/frontendReferences.js.map +1 -0
  32. package/dist/validate/frontendTypeKnowledge.d.ts +5 -0
  33. package/dist/validate/frontendTypeKnowledge.d.ts.map +1 -0
  34. package/dist/validate/frontendTypeKnowledge.js +325 -0
  35. package/dist/validate/frontendTypeKnowledge.js.map +1 -0
  36. package/dist/validate/registry.d.ts +3 -3
  37. package/dist/validate/registry.d.ts.map +1 -1
  38. package/dist/validate/registry.js +19 -3
  39. package/dist/validate/registry.js.map +1 -1
  40. package/dist/validate/ruleCatalog.d.ts.map +1 -1
  41. package/dist/validate/ruleCatalog.js +66 -0
  42. package/dist/validate/ruleCatalog.js.map +1 -1
  43. package/dist/validate/rules/dependencyIntegrity.d.ts.map +1 -1
  44. package/dist/validate/rules/dependencyIntegrity.js +5 -41
  45. package/dist/validate/rules/dependencyIntegrity.js.map +1 -1
  46. package/dist/validate/rules/groupedFrontend.d.ts +3 -0
  47. package/dist/validate/rules/groupedFrontend.d.ts.map +1 -0
  48. package/dist/validate/rules/groupedFrontend.js +513 -0
  49. package/dist/validate/rules/groupedFrontend.js.map +1 -0
  50. package/dist/validate/rules/recordsForm.d.ts +3 -0
  51. package/dist/validate/rules/recordsForm.d.ts.map +1 -0
  52. package/dist/validate/rules/recordsForm.js +160 -0
  53. package/dist/validate/rules/recordsForm.js.map +1 -0
  54. package/dist/validate/rules/taskTable.d.ts +24 -0
  55. package/dist/validate/rules/taskTable.d.ts.map +1 -0
  56. package/dist/validate/rules/taskTable.js +57 -0
  57. package/dist/validate/rules/taskTable.js.map +1 -0
  58. package/dist/validate/sourceLocator.d.ts +4 -2
  59. package/dist/validate/sourceLocator.d.ts.map +1 -1
  60. package/dist/validate/sourceLocator.js +59 -0
  61. package/dist/validate/sourceLocator.js.map +1 -1
  62. package/package.json +8 -6
@@ -0,0 +1,924 @@
1
+ const frontendBlankCharacter = /\s/u;
2
+ // Liquid excludes FEFF from blanks and includes U180E; these are word boundaries too.
3
+ const liquidBlankCharacters = '\\t\\n\\v\\f\\r \\u00A0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000';
4
+ const liquidBlank = `[${liquidBlankCharacters}]`;
5
+ const liquidTagStart = `^-?${liquidBlank}*`;
6
+ const liquidBlankCharacter = new RegExp(liquidBlank, 'u');
7
+ // Keep $ opaque as before; complete Liquid words also include -/? and non-ASCII.
8
+ const liquidWordCharacter = new RegExp(`[A-Za-z0-9_$?-]|[^\\x00-\\x7F${liquidBlankCharacters}\\u201C\\u201D]`, 'u');
9
+ const liquidNonReadTag = new RegExp(`${liquidTagStart}(?:capture|endcapture|increment|decrement|break|continue|else|endif|endfor|endtablerow)\\b`, 'u');
10
+ const liquidAssignment = new RegExp(`${liquidTagStart}assign${liquidBlank}+[^${liquidBlankCharacters}=]+${liquidBlank}*=`, 'u');
11
+ const liquidIteration = new RegExp(`${liquidTagStart}(?:for|tablerow)${liquidBlank}+[^${liquidBlankCharacters}]+${liquidBlank}+in${liquidBlank}+`, 'u');
12
+ const liquidDeclaration = new RegExp(`${liquidTagStart}(assign|capture|for|tablerow)${liquidBlank}+([^${liquidBlankCharacters}=]+)`, 'u');
13
+ const liquidCaptureEnd = new RegExp(`${liquidTagStart}endcapture\\b`, 'u');
14
+ const liquidTag = new RegExp(`${liquidTagStart}(\\w+)`, 'u');
15
+ const liquidLiteralBlock = new RegExp(`${liquidTagStart}(raw|comment)${liquidBlank}*-?$`, 'u');
16
+ const liquidMultilineTag = new RegExp(`${liquidTagStart}liquid\\b`, 'u');
17
+ const liquidTrimStart = new RegExp(`^${liquidBlank}+`, 'u');
18
+ /** Known binding targets are syntax, while their RHS/iterables are evaluated. */
19
+ function liquidTagRead(body) {
20
+ if (liquidNonReadTag.test(body))
21
+ return '';
22
+ const binding = liquidAssignment.exec(body) ?? liquidIteration.exec(body);
23
+ return binding ? body.slice(binding[0].length) : body;
24
+ }
25
+ function frontendExpressionsIn(value, rawJsonata) {
26
+ const result = [];
27
+ const source = [];
28
+ let copied = 0;
29
+ let trimFloor = 0;
30
+ let captureDepth = 0;
31
+ let trimNext = false;
32
+ let liquidShadows = 0;
33
+ const captures = [];
34
+ const appendTag = (body) => {
35
+ result.push({ text: liquidTagRead(body), liquidShadows });
36
+ const declaration = liquidDeclaration.exec(body);
37
+ const name = declaration?.[2];
38
+ const shadow = name === 'outputs' ? 1 : name === '_outputs' ? 2 : 0;
39
+ if (declaration?.[1] === 'capture')
40
+ captures.push(shadow);
41
+ else if (liquidCaptureEnd.test(body))
42
+ liquidShadows |= captures.pop() ?? 0;
43
+ else
44
+ liquidShadows |= shadow;
45
+ };
46
+ const append = (text) => {
47
+ if (trimNext)
48
+ text = text.replace(liquidTrimStart, '');
49
+ trimNext = false;
50
+ if (rawJsonata && captureDepth === 0 && text.length > 0)
51
+ source.push(text);
52
+ };
53
+ const trimOutput = () => {
54
+ if (!rawJsonata || captureDepth > 0)
55
+ return;
56
+ while (source.length > trimFloor) {
57
+ const last = source[source.length - 1];
58
+ let end = last.length;
59
+ while (end > 0 && liquidBlankCharacter.test(last[end - 1]))
60
+ end -= 1;
61
+ if (end > 0) {
62
+ if (end !== last.length)
63
+ source[source.length - 1] = last.slice(0, end);
64
+ break;
65
+ }
66
+ source.pop();
67
+ }
68
+ };
69
+ let interpolation = value.indexOf('{{');
70
+ let control = value.indexOf('{%');
71
+ while (interpolation !== -1 || control !== -1) {
72
+ const isControl = control !== -1 && (interpolation === -1 || control < interpolation);
73
+ const open = isControl ? control : interpolation;
74
+ const close = value.indexOf(isControl ? '%}' : '}}', open + 2);
75
+ if (rawJsonata)
76
+ append(value.slice(copied, open));
77
+ if (value[open + 2] === '-')
78
+ trimOutput();
79
+ if (close === -1) {
80
+ copied = value.length;
81
+ break;
82
+ }
83
+ const trimRight = value[close - 1] === '-';
84
+ const expression = value.slice(open + 2 + (value[open + 2] === '-' ? 1 : 0), close - (trimRight ? 1 : 0));
85
+ let next = close + 2;
86
+ const tag = isControl ? liquidTag.exec(expression)?.[1] : undefined;
87
+ const literalBlock = isControl && liquidLiteralBlock.exec(expression);
88
+ if (literalBlock) {
89
+ // Raw bodies remain literal; whitespace control applies only outside them.
90
+ const end = new RegExp(`\\{%-?${liquidBlank}*end${literalBlock[1]}${liquidBlank}*-?%\\}`, 'gu');
91
+ end.lastIndex = next;
92
+ const closing = end.exec(value);
93
+ if (rawJsonata && literalBlock[1] === 'raw') {
94
+ const body = value.slice(next, closing?.index ?? value.length);
95
+ trimNext = false;
96
+ append(body);
97
+ }
98
+ trimNext = closing?.[0].endsWith('-%}') ?? false;
99
+ next = closing === null ? value.length : closing.index + closing[0].length;
100
+ }
101
+ else {
102
+ // Captures still evaluate their active Liquid reads, but their literal body
103
+ // is stored, not emitted into the downstream JSONata program.
104
+ if (!isControl)
105
+ result.push({ text: expression, liquidShadows });
106
+ else if (tag === 'liquid') {
107
+ for (const line of expression.replace(liquidMultilineTag, '').split(/\r?\n/u))
108
+ appendTag(line);
109
+ }
110
+ else
111
+ appendTag(expression);
112
+ if (tag === 'capture')
113
+ captureDepth += 1;
114
+ else if (tag === 'endcapture')
115
+ captureDepth = Math.max(0, captureDepth - 1);
116
+ else if (rawJsonata && captureDepth === 0 && tag !== 'assign') {
117
+ // Unknown emitters and control-flow boundaries are opaque, not empty.
118
+ // Do not join tokens across dynamic output or mutually exclusive arms.
119
+ source.push('\0');
120
+ }
121
+ trimNext = trimRight;
122
+ }
123
+ copied = next;
124
+ // Left trim applies only to literal text after the previous Liquid token.
125
+ trimFloor = source.length;
126
+ // Cache misses as well as openings: repeated tags must not rescan an absent delimiter.
127
+ if (interpolation !== -1 && interpolation < next)
128
+ interpolation = value.indexOf('{{', next);
129
+ if (control !== -1 && control < next)
130
+ control = value.indexOf('{%', next);
131
+ }
132
+ // JSONata handlers first render Liquid, including tags inside JSONata strings.
133
+ // Keep emitted quotes intact; raw bodies are JSONata, comments/captures are
134
+ // absent, and only known non-emitting tags permit adjacent token joining.
135
+ if (rawJsonata) {
136
+ append(value.slice(copied));
137
+ result.push({ text: source.join(''), liquidShadows: 0 });
138
+ }
139
+ return result;
140
+ }
141
+ /** Whitespace and comments are trivia even between path tokens. */
142
+ function skipFrontendTrivia(expression, start, blank = frontendBlankCharacter) {
143
+ let at = start;
144
+ while (at < expression.length) {
145
+ if (blank.test(expression[at])) {
146
+ at += 1;
147
+ continue;
148
+ }
149
+ if (expression.startsWith('/*', at)) {
150
+ const end = expression.indexOf('*/', at + 2);
151
+ at = end === -1 ? expression.length : end + 2;
152
+ }
153
+ else if (expression.startsWith('//', at)) {
154
+ const end = expression.indexOf('\n', at + 2);
155
+ at = end === -1 ? expression.length : end + 1;
156
+ }
157
+ else
158
+ break;
159
+ }
160
+ return at;
161
+ }
162
+ const punctuation = new Set('[]{}().,:;+-*/%|=<>^!?&~@#`');
163
+ const doubleOperators = new Set(['..', ':=', '!=', '>=', '<=', '**', '~>', '?:', '??']);
164
+ /** Tokens preserve field identity and opacity; comments alone are trivia. */
165
+ function jsonataTokens(source) {
166
+ const tokens = [];
167
+ let at = 0;
168
+ let operand = true;
169
+ while (at < source.length) {
170
+ const start = at;
171
+ const char = source[at];
172
+ if (/\s/u.test(char)) {
173
+ at += 1;
174
+ continue;
175
+ }
176
+ if (source.startsWith('/*', at) || source.startsWith('//', at)) {
177
+ const block = source[at + 1] === '*';
178
+ const close = source.indexOf(block ? '*/' : '\n', at + 2);
179
+ const end = close < 0 ? source.length : close + (block ? 2 : 1);
180
+ while (at < end) {
181
+ if (source[at] === '\0')
182
+ tokens.push({ kind: 'hole', value: '', start: at, end: at + 1, complete: false });
183
+ at += 1;
184
+ }
185
+ continue;
186
+ }
187
+ if (char === '\0') {
188
+ tokens.push({ kind: 'hole', value: '', start, end: ++at, complete: false });
189
+ // Unknown source cannot establish a new operand/operator context.
190
+ continue;
191
+ }
192
+ if (char === '"' || char === "'" || char === '`' || (char === '/' && operand)) {
193
+ const kind = char === '`' ? 'backtick' : char === '/' ? 'regex' : 'string';
194
+ const holes = [];
195
+ at += 1;
196
+ const content = at;
197
+ let characterClass = false;
198
+ let closed = false;
199
+ while (at < source.length) {
200
+ const current = source[at];
201
+ if (current === '\0')
202
+ holes.push({ kind: 'hole', value: '', start: at, end: at + 1, complete: false, contained: true });
203
+ if (current === '\\' && kind !== 'backtick' && source[at + 1] !== '\0') {
204
+ at += 2;
205
+ continue;
206
+ }
207
+ if (kind === 'regex') {
208
+ if (current === '[')
209
+ characterClass = true;
210
+ else if (current === ']')
211
+ characterClass = false;
212
+ }
213
+ if (current === char && !characterClass) {
214
+ closed = true;
215
+ break;
216
+ }
217
+ at += 1;
218
+ }
219
+ let value = source.slice(content, at);
220
+ if (kind === 'string' && value.includes('\\')) {
221
+ const escapes = { b: '\b', f: '\f', n: '\n', r: '\r', t: '\t' };
222
+ value = value.replace(/\\(u[0-9a-fA-F]{4}|["'\\/bfnrt])/gu, (_match, escape) => escape.startsWith('u') ? String.fromCharCode(Number.parseInt(escape.slice(1), 16)) : escapes[escape] ?? escape);
223
+ }
224
+ if (closed)
225
+ at += 1;
226
+ if (kind === 'regex')
227
+ while (at < source.length && /[A-Za-z]/u.test(source[at]))
228
+ at += 1;
229
+ tokens.push({ kind, value, start, end: at, complete: closed && holes.length === 0 }, ...holes);
230
+ operand = false;
231
+ continue;
232
+ }
233
+ if (/[0-9]/u.test(char)) {
234
+ const number = /^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[Ee][+-]?[0-9]+)?/u.exec(source.slice(at));
235
+ at += number[0].length;
236
+ tokens.push({ kind: 'number', value: number[0], start, end: at, complete: true });
237
+ operand = false;
238
+ continue;
239
+ }
240
+ const double = source.slice(at, at + 2);
241
+ if (punctuation.has(char)) {
242
+ const value = doubleOperators.has(double) ? double : char;
243
+ at += value.length;
244
+ tokens.push({ kind: 'operator', value, start, end: at, complete: true });
245
+ operand = value === '*' || value === '**' ? !operand : ![')', ']', '}'].includes(value);
246
+ continue;
247
+ }
248
+ // JSONata names end at whitespace/operators, not at ASCII-only word bounds.
249
+ while (at < source.length && source[at] !== '\0' && !/\s/u.test(source[at]) && !punctuation.has(source[at]))
250
+ at += 1;
251
+ const value = source.slice(start, at);
252
+ const previous = tokens[tokens.length - 1];
253
+ const wordOperator = /^(and|or|in)$/u.test(value) && !(previous?.kind === 'operator' && previous.value === '.');
254
+ tokens.push({ kind: value.startsWith('$') ? 'variable' : wordOperator ? 'operator' : /^(true|false|null)$/u.test(value) ? 'number' : 'name', value, start, end: at, complete: true });
255
+ operand = wordOperator;
256
+ }
257
+ for (let index = 0; index < tokens.length; index += 1) {
258
+ const token = tokens[index];
259
+ if (!['name', 'variable', 'number'].includes(token.kind))
260
+ continue;
261
+ const before = tokens[index - 1];
262
+ const after = tokens[index + 1];
263
+ if ((before?.kind === 'hole' && !before.contained && before.end === token.start) ||
264
+ (after?.kind === 'hole' && !after.contained && token.end === after.start))
265
+ token.complete = false;
266
+ }
267
+ tokens.push({ kind: 'end', value: '', start: at, end: at, complete: true });
268
+ return tokens;
269
+ }
270
+ const precedence = {
271
+ ':=': 10, '?': 20, '?:': 20, '??': 20, or: 25, and: 30,
272
+ '=': 40, '!=': 40, '<': 40, '>': 40, '<=': 40, '>=': 40, in: 40,
273
+ '&': 45, '..': 50, '+': 55, '-': 55, '*': 60, '/': 60, '%': 60, '~>': 65,
274
+ '.': 80, '@': 85, '#': 85, '[': 90, '{': 90, '^': 90, '(': 95,
275
+ };
276
+ // Authored expressions must not exhaust the editor/Node host stack. A bounded
277
+ // analysis reports uncertainty; it never certifies an unvisited namespace read.
278
+ const MAX_REFERENCE_DEPTH = 128;
279
+ /**
280
+ * Structural grammar only: no executable AST, evaluation, function lookup, or
281
+ * result-member inference. Recovery retains opacity instead of restarting roots.
282
+ */
283
+ class JsonataStructure {
284
+ tokens;
285
+ at = 0;
286
+ depth = 0;
287
+ limited = false;
288
+ constructor(tokens) {
289
+ this.tokens = tokens;
290
+ }
291
+ current() { return this.tokens[this.at]; }
292
+ operator(value) {
293
+ const token = this.current();
294
+ return token.kind === 'operator' && token.value === value;
295
+ }
296
+ list(close, separator) {
297
+ const children = [];
298
+ while (this.current().kind !== 'end' && !this.operator(close)) {
299
+ children.push(this.read());
300
+ if (this.operator(separator))
301
+ this.at += 1;
302
+ }
303
+ if (this.operator(close))
304
+ this.at += 1;
305
+ return children;
306
+ }
307
+ object() {
308
+ const children = [];
309
+ while (this.current().kind !== 'end' && !this.operator('}')) {
310
+ children.push(this.read());
311
+ if (this.operator(':')) {
312
+ this.at += 1;
313
+ children.push(this.read());
314
+ }
315
+ if (this.operator(','))
316
+ this.at += 1;
317
+ }
318
+ if (this.operator('}'))
319
+ this.at += 1;
320
+ return { kind: 'object', children, end: this.tokens[this.at - 1].end };
321
+ }
322
+ prefix() {
323
+ if (this.current().kind === 'end')
324
+ return { kind: 'atom', token: this.current(), complete: false, end: this.current().end };
325
+ const token = this.current();
326
+ this.at += 1;
327
+ if (token.value === '(' && token.kind === 'operator') {
328
+ const children = this.list(')', ';');
329
+ return { kind: 'block', children, end: this.tokens[this.at - 1].end };
330
+ }
331
+ if (token.value === '[' && token.kind === 'operator') {
332
+ const children = this.list(']', ',');
333
+ return { kind: 'array', children, end: this.tokens[this.at - 1].end };
334
+ }
335
+ if (token.value === '{' && token.kind === 'operator')
336
+ return this.object();
337
+ if (token.value === '-' && token.kind === 'operator') {
338
+ const operand = this.read(70);
339
+ return { kind: 'unary', operand, end: operand.end };
340
+ }
341
+ const next = this.current();
342
+ if (token.kind === 'name' && (token.value === 'function' || token.value === 'λ') && next.kind === 'operator' && next.value === '(') {
343
+ this.at += 1;
344
+ const parameters = [];
345
+ while (this.current().kind !== 'end' && !this.operator(')')) {
346
+ if (this.current().kind === 'variable' || this.current().kind === 'hole')
347
+ parameters.push(this.current());
348
+ this.at += 1;
349
+ }
350
+ if (this.operator(')'))
351
+ this.at += 1;
352
+ // Optional function signatures contain types, not executable references.
353
+ if (this.operator('<')) {
354
+ while (this.current().kind !== 'end' && !this.operator('{')) {
355
+ if (this.current().kind === 'hole')
356
+ parameters.push(this.current());
357
+ this.at += 1;
358
+ }
359
+ }
360
+ let children = [];
361
+ if (this.operator('{')) {
362
+ this.at += 1;
363
+ children = this.list('}', ';');
364
+ }
365
+ const body = { kind: 'sequence', children, end: this.tokens[this.at - 1].end };
366
+ return { kind: 'lambda', parameters, body, end: body.end };
367
+ }
368
+ // Unrecognized operand syntax (including transform boundaries) cannot
369
+ // preserve definite focus through recovery as an ordinary literal.
370
+ let complete = token.complete && (token.kind !== 'operator' || token.value === '*' || token.value === '**');
371
+ let end = token.end;
372
+ while (this.current().kind === 'hole' && this.current().contained) {
373
+ complete = false;
374
+ this.at += 1;
375
+ }
376
+ // An opaque insertion adjoining a word is part of one incomplete token,
377
+ // never a terminator proving its prefix is a producer key.
378
+ while (['name', 'variable', 'number', 'hole'].includes(token.kind) &&
379
+ this.current().kind === 'hole' && !this.current().contained && this.current().start === end) {
380
+ complete = false;
381
+ end = this.current().end;
382
+ this.at += 1;
383
+ if (['name', 'variable', 'number'].includes(this.current().kind) && this.current().start === end) {
384
+ end = this.current().end;
385
+ this.at += 1;
386
+ }
387
+ }
388
+ return { kind: 'atom', token, complete, end };
389
+ }
390
+ read(minimum = 0, field = false) {
391
+ if (this.depth >= MAX_REFERENCE_DEPTH) {
392
+ this.limited = true;
393
+ const token = { ...this.current(), kind: 'hole', complete: false };
394
+ this.at = this.tokens.length - 1;
395
+ return { kind: 'atom', token, complete: false, end: token.end };
396
+ }
397
+ this.depth += 1;
398
+ try {
399
+ return this.readExpression(minimum, field);
400
+ }
401
+ finally {
402
+ this.depth -= 1;
403
+ }
404
+ }
405
+ readExpression(minimum, field) {
406
+ let left = this.prefix();
407
+ if (field && left.kind === 'atom')
408
+ left.field = true;
409
+ while (this.current().kind !== 'end') {
410
+ const operator = this.current().value;
411
+ const power = this.current().kind === 'operator' ? precedence[operator] : undefined;
412
+ if (power === undefined || power < minimum)
413
+ break;
414
+ this.at += 1;
415
+ if (operator === '(') {
416
+ const args = this.list(')', ',');
417
+ left = { kind: 'call', callee: left, args, end: this.tokens[this.at - 1].end };
418
+ }
419
+ else if (operator === '[') {
420
+ const children = this.list(']', ';');
421
+ const right = { kind: 'sequence', children, end: this.tokens[this.at - 1].end };
422
+ left = { kind: 'predicate', operator, left, right, end: right.end };
423
+ }
424
+ else if (operator === '{') {
425
+ const right = this.object();
426
+ left = { kind: 'group', operator, left, right, end: right.end };
427
+ }
428
+ else if (operator === '^' && this.operator('(')) {
429
+ this.at += 1;
430
+ const children = this.list(')', ',');
431
+ const right = { kind: 'sequence', children, end: this.tokens[this.at - 1].end };
432
+ left = { kind: 'predicate', operator, left, right, end: right.end };
433
+ }
434
+ else if (operator === '?') {
435
+ const yes = this.read();
436
+ let no;
437
+ if (this.operator(':')) {
438
+ this.at += 1;
439
+ no = this.read();
440
+ }
441
+ left = { kind: 'conditional', condition: left, yes, no, end: no?.end ?? yes.end };
442
+ }
443
+ else {
444
+ if (operator === '.') {
445
+ let head = left;
446
+ while (head.kind === 'predicate' || head.kind === 'group' || head.kind === 'bind')
447
+ head = head.left;
448
+ if (head.kind === 'atom' && head.token.kind === 'string')
449
+ head.field = true;
450
+ }
451
+ // Tuple declarations consume one target; following predicates/calls are
452
+ // evaluated stages, not part of the declaration and never discarded.
453
+ const right = operator === '@' || operator === '#'
454
+ ? this.prefix() : this.read(operator === ':=' ? power : power + 1, operator === '.');
455
+ left = { kind: operator === '.' ? 'path' : operator === '@' || operator === '#' ? 'bind' : 'binary', operator, left, right, end: right.end };
456
+ }
457
+ }
458
+ return left;
459
+ }
460
+ parse() {
461
+ const children = [];
462
+ while (this.current().kind !== 'end')
463
+ children.push(this.read());
464
+ return { kind: 'sequence', children, end: this.current().end };
465
+ }
466
+ }
467
+ const otherFocus = { origin: 'other' };
468
+ const opaqueFocus = { origin: 'unknown', opaque: true };
469
+ function joinOrigin(left, right) { return left === right ? left : 'unknown'; }
470
+ function rootAssignment(node) {
471
+ return node.kind === 'binary' && node.operator === ':=' && node.left.kind === 'atom' &&
472
+ node.left.complete && node.left.token.kind === 'variable' && node.left.token.value === '$$';
473
+ }
474
+ /** Local writes stop at frames; syntax holes cannot prove those boundaries intact. */
475
+ function frameWrites(nodes) {
476
+ const writes = [];
477
+ const visit = (node, bindings, depth = 0) => {
478
+ if (depth >= MAX_REFERENCE_DEPTH) {
479
+ writes.push(node);
480
+ return;
481
+ }
482
+ if (node.kind === 'lambda') {
483
+ if (node.parameters.some((parameter) => !parameter.complete))
484
+ writes.push(node);
485
+ visit(node.body, false, depth + 1);
486
+ return;
487
+ }
488
+ if ((bindings && rootAssignment(node)) || (node.kind === 'atom' && !node.complete))
489
+ writes.push(node);
490
+ switch (node.kind) {
491
+ case 'atom': return;
492
+ case 'block':
493
+ case 'sequence':
494
+ case 'array':
495
+ case 'object':
496
+ for (const child of node.children)
497
+ visit(child, bindings && node.kind !== 'block', depth + 1);
498
+ return;
499
+ case 'call':
500
+ visit(node.callee, bindings, depth + 1);
501
+ for (const argument of node.args)
502
+ visit(argument, bindings, depth + 1);
503
+ return;
504
+ case 'conditional':
505
+ visit(node.condition, bindings, depth + 1);
506
+ visit(node.yes, bindings, depth + 1);
507
+ if (node.no)
508
+ visit(node.no, bindings, depth + 1);
509
+ return;
510
+ case 'unary':
511
+ visit(node.operand, bindings, depth + 1);
512
+ return;
513
+ default:
514
+ visit(node.left, bindings, depth + 1);
515
+ visit(node.right, bindings, depth + 1);
516
+ }
517
+ };
518
+ for (const node of nodes)
519
+ visit(node, true);
520
+ return writes;
521
+ }
522
+ /** Abstract provenance only. No values, invocation simulation, or alias inference. */
523
+ class JsonataReferences {
524
+ references = [];
525
+ depth = 0;
526
+ limited = false;
527
+ emit(value, key) {
528
+ const namespace = value.namespace;
529
+ if (!namespace || namespace.emitted)
530
+ return;
531
+ namespace.emitted = true;
532
+ this.references.push({ namespace: namespace.namespace, rootCertainty: namespace.rootCertainty, ...(key === undefined ? {} : { key }) });
533
+ }
534
+ root(state) { return state.tupleRoot ?? state.frame.root; }
535
+ fork(state) { return { ...state, frame: { ...state.frame } }; }
536
+ merge(state, alternatives) {
537
+ state.frame.root = alternatives.map((branch) => branch.frame.root).reduce(joinOrigin);
538
+ if (state.tupleRoot !== undefined)
539
+ state.tupleRoot = alternatives.map((branch) => this.root(branch)).reduce(joinOrigin);
540
+ state.frame.shadowed = alternatives.every((branch) => branch.frame.shadowed);
541
+ state.tainted = alternatives.some((branch) => branch.tainted);
542
+ }
543
+ taint(state) {
544
+ state.tainted = true;
545
+ state.frame.root = 'unknown';
546
+ if (state.tupleRoot !== undefined)
547
+ state.tupleRoot = 'unknown';
548
+ }
549
+ atom(node, state) {
550
+ const token = node.token;
551
+ const focus = state.focus;
552
+ if (!node.complete || token.kind === 'hole') {
553
+ this.emit(focus);
554
+ this.taint(state);
555
+ return opaqueFocus;
556
+ }
557
+ if (token.kind === 'variable') {
558
+ return { origin: token.value === '$$' ? this.root(state) : token.value === '$' ? focus.origin : 'other', incoming: focus, tupleRoot: state.tupleRoot };
559
+ }
560
+ const field = token.kind === 'name' || token.kind === 'backtick' || (node.field && token.kind === 'string');
561
+ if (field && focus.namespace) {
562
+ this.emit(focus, token.value);
563
+ return { origin: 'other', incoming: focus, tupleRoot: state.tupleRoot };
564
+ }
565
+ if (field && !focus.opaque && (token.value === 'outputs' || token.value === '_outputs')) {
566
+ const origin = state.tainted && focus.origin !== 'other' ? 'unknown' : focus.origin;
567
+ if (origin !== 'other')
568
+ return {
569
+ origin: 'other', incoming: focus, tupleRoot: state.tupleRoot,
570
+ namespace: { namespace: token.value, rootCertainty: origin === 'workflow' ? 'definite' : 'uncertain', emitted: false },
571
+ };
572
+ }
573
+ if (focus.namespace)
574
+ this.emit(focus);
575
+ return { origin: 'other', incoming: focus, tupleRoot: state.tupleRoot };
576
+ }
577
+ sequence(nodes, state) {
578
+ let value = otherFocus;
579
+ for (const node of nodes) {
580
+ this.emit(value);
581
+ value = this.walk(node, state);
582
+ }
583
+ return value;
584
+ }
585
+ writeOrigin(node, state) {
586
+ if (node.kind === 'binary' && rootAssignment(node))
587
+ return this.staticOrigin(node.right, state);
588
+ return 'unknown';
589
+ }
590
+ staticOrigin(node, state) {
591
+ if (node.kind === 'atom') {
592
+ if (!node.complete)
593
+ return 'unknown';
594
+ return node.token.kind === 'variable' && node.token.value === '$$' ? this.root(state) :
595
+ node.token.kind === 'variable' && node.token.value === '$' ? state.focus.origin : 'other';
596
+ }
597
+ if (node.kind === 'conditional')
598
+ return joinOrigin(this.staticOrigin(node.yes, state), node.no ? this.staticOrigin(node.no, state) : 'other');
599
+ if (node.kind === 'block' || node.kind === 'sequence') {
600
+ // A block-local write changes the meaning of its tail variable. Without
601
+ // evaluating that frame, the caller's binding is not a valid summary.
602
+ if (frameWrites(node.children).length > 0)
603
+ return 'unknown';
604
+ const last = node.children[node.children.length - 1];
605
+ return last ? this.staticOrigin(last, state) : 'other';
606
+ }
607
+ return node.kind === 'path' || node.kind === 'predicate' ? 'unknown' : 'other';
608
+ }
609
+ /** Constructor siblings may run concurrently; source order proves no binding. */
610
+ parallel(nodes, state) {
611
+ const writes = new Map();
612
+ const totals = { workflow: 0, other: 0, unknown: 0 };
613
+ for (let index = 0; index < nodes.length; index += 1) {
614
+ const effects = frameWrites([nodes[index]]);
615
+ if (effects.length === 0)
616
+ continue;
617
+ const counts = { workflow: 0, other: 0, unknown: 0 };
618
+ for (const write of effects) {
619
+ const origin = this.writeOrigin(write, state);
620
+ counts[origin] += 1;
621
+ totals[origin] += 1;
622
+ }
623
+ writes.set(index, counts);
624
+ }
625
+ if (writes.size === 0) {
626
+ for (const node of nodes)
627
+ this.emit(this.walk(node, state));
628
+ return;
629
+ }
630
+ const branches = [];
631
+ for (let index = 0; index < nodes.length; index += 1) {
632
+ const branch = this.fork(state);
633
+ // Origin summaries depend only on incoming state. Aggregate them once,
634
+ // excluding this child with three counts instead of re-reading all peers.
635
+ const own = writes.get(index);
636
+ for (const origin of ['workflow', 'other', 'unknown']) {
637
+ if (totals[origin] <= (own?.[origin] ?? 0))
638
+ continue;
639
+ const joined = joinOrigin(this.root(branch), origin);
640
+ if (branch.tupleRoot !== undefined)
641
+ branch.tupleRoot = joined;
642
+ else
643
+ branch.frame.root = joined;
644
+ }
645
+ this.emit(this.walk(nodes[index], branch));
646
+ branches.push(branch);
647
+ }
648
+ const changed = branches.filter((_branch, index) => writes.has(index));
649
+ if (changed.length > 0)
650
+ this.merge(state, changed);
651
+ state.tainted ||= branches.some((branch) => branch.tainted);
652
+ }
653
+ mutableCapture(node, frame) {
654
+ if (frame.lastWriteEnd >= node.end)
655
+ return true;
656
+ return !frame.shadowed && frame.parent !== undefined && this.mutableCapture(node, frame.parent);
657
+ }
658
+ /** Only a syntactically named first step establishes a producer. */
659
+ producerStep(node) {
660
+ for (;;) {
661
+ switch (node.kind) {
662
+ case 'atom': return true;
663
+ case 'predicate':
664
+ case 'group':
665
+ case 'bind':
666
+ node = node.left;
667
+ break;
668
+ case 'call':
669
+ node = node.callee;
670
+ break;
671
+ case 'block':
672
+ if (node.children.length !== 1)
673
+ return false;
674
+ node = node.children[0];
675
+ break;
676
+ default: return false;
677
+ }
678
+ }
679
+ }
680
+ walk(node, state) {
681
+ if (this.depth >= MAX_REFERENCE_DEPTH) {
682
+ this.limited = true;
683
+ return opaqueFocus;
684
+ }
685
+ this.depth += 1;
686
+ try {
687
+ return this.walkExpression(node, state);
688
+ }
689
+ finally {
690
+ this.depth -= 1;
691
+ }
692
+ }
693
+ walkExpression(node, state) {
694
+ switch (node.kind) {
695
+ case 'atom': return this.atom(node, state);
696
+ case 'sequence': return this.sequence(node.children, state);
697
+ case 'block': {
698
+ const lastWriteEnd = frameWrites(node.children).reduce((end, write) => Math.max(end, write.end), -1);
699
+ const frame = { root: this.root(state), shadowed: state.tupleRoot !== undefined, parent: state.frame, lastWriteEnd };
700
+ const nested = { ...state, frame, tupleRoot: undefined };
701
+ const value = this.sequence(node.children, nested);
702
+ state.tainted ||= nested.tainted;
703
+ return value;
704
+ }
705
+ case 'array':
706
+ case 'object':
707
+ this.parallel(node.children, state);
708
+ return otherFocus;
709
+ case 'unary':
710
+ this.emit(this.walk(node.operand, state));
711
+ return otherFocus;
712
+ case 'lambda': {
713
+ const parameterRoot = node.parameters.some((parameter) => parameter.complete && parameter.kind === 'variable' && parameter.value === '$$');
714
+ const uncertainParameters = node.parameters.some((parameter) => !parameter.complete);
715
+ const capturedRoot = this.root(state);
716
+ const root = uncertainParameters ? 'unknown' : parameterRoot ? 'other' :
717
+ this.mutableCapture(node, state.frame) ? 'unknown' : capturedRoot;
718
+ const frame = {
719
+ root, shadowed: parameterRoot || state.tupleRoot !== undefined, parent: state.frame,
720
+ lastWriteEnd: frameWrites([node.body]).reduce((end, write) => Math.max(end, write.end), -1),
721
+ };
722
+ const nested = { focus: state.focus, frame, tainted: state.tainted || uncertainParameters };
723
+ this.emit(this.walk(node.body, nested));
724
+ if (nested.tainted)
725
+ this.taint(state);
726
+ return otherFocus;
727
+ }
728
+ case 'call':
729
+ this.emit(this.walk(node.callee, state));
730
+ // Calls do not pipe their first argument into subsequent arguments.
731
+ for (const argument of node.args)
732
+ this.emit(this.walk(argument, state));
733
+ return otherFocus;
734
+ case 'conditional': {
735
+ this.emit(this.walk(node.condition, state));
736
+ const yes = this.fork(state);
737
+ const no = this.fork(state);
738
+ const yesValue = this.walk(node.yes, yes);
739
+ const noValue = node.no ? this.walk(node.no, no) : otherFocus;
740
+ this.emit(yesValue);
741
+ this.emit(noValue);
742
+ this.merge(state, [yes, no]);
743
+ return { origin: joinOrigin(yesValue.origin, noValue.origin) };
744
+ }
745
+ case 'path': {
746
+ const left = this.walk(node.left, state);
747
+ if (left.namespace && !this.producerStep(node.right))
748
+ this.emit(left);
749
+ const before = this.fork(state);
750
+ const tupleRoot = left.tupleRoot ?? state.tupleRoot;
751
+ const rightState = { ...state, focus: left, tupleRoot };
752
+ const right = this.walk(node.right, rightState);
753
+ this.emit(left);
754
+ // Mapping a possibly empty path need not execute its RHS.
755
+ this.merge(state, [before, rightState]);
756
+ // Result identity does not erase bindings; stage-local writes cannot
757
+ // establish a different outgoing named tuple binding with certainty.
758
+ return right.tupleRoot !== undefined || tupleRoot === undefined
759
+ ? right : { ...right, tupleRoot: joinOrigin(tupleRoot, this.root(rightState)) };
760
+ }
761
+ case 'predicate':
762
+ case 'group': {
763
+ const left = this.walk(node.left, state);
764
+ this.emit(left);
765
+ const before = this.fork(state);
766
+ const contextual = { ...state, focus: { origin: left.origin }, tupleRoot: left.tupleRoot ?? state.tupleRoot };
767
+ this.emit(this.walk(node.right, contextual));
768
+ this.merge(state, [before, contextual]);
769
+ // A JSONata bracket is a predicate, never a literal producer lookup.
770
+ return node.kind === 'predicate' ? { origin: left.origin, tupleRoot: left.tupleRoot } : otherFocus;
771
+ }
772
+ case 'bind': {
773
+ const left = this.walk(node.left, state);
774
+ this.emit(left);
775
+ const target = node.right;
776
+ const uncertain = target.kind !== 'atom' || !target.complete || target.token.kind !== 'variable';
777
+ if (uncertain) {
778
+ this.taint(state);
779
+ this.emit(this.walk(target, { ...state, focus: { origin: 'unknown' } }));
780
+ }
781
+ const binding = !uncertain && target.token.value === '$$';
782
+ const tupleRoot = uncertain ? 'unknown' : binding ? node.operator === '@' ? left.origin : 'other' : left.tupleRoot;
783
+ return { ...(node.operator === '@' ? left.incoming ?? state.focus : left), tupleRoot };
784
+ }
785
+ case 'binary': {
786
+ if (node.operator === ':=') {
787
+ const right = this.walk(node.right, state);
788
+ this.emit(right);
789
+ if (rootAssignment(node)) {
790
+ if (state.tupleRoot !== undefined)
791
+ state.tupleRoot = right.origin;
792
+ else {
793
+ state.frame.root = right.origin;
794
+ state.frame.shadowed = true;
795
+ }
796
+ }
797
+ return right;
798
+ }
799
+ const left = this.walk(node.left, state);
800
+ this.emit(left);
801
+ const before = this.fork(state);
802
+ const rightState = this.fork(state);
803
+ const right = this.walk(node.right, rightState);
804
+ this.emit(right);
805
+ if (['and', 'or', '?:', '??'].includes(node.operator))
806
+ this.merge(state, [before, rightState]);
807
+ else
808
+ this.merge(state, [rightState]);
809
+ return node.operator === '?:' || node.operator === '??' ? { origin: joinOrigin(left.origin, right.origin) } : otherFocus;
810
+ }
811
+ }
812
+ }
813
+ inspect(expression) {
814
+ const lastWriteEnd = frameWrites([expression]).reduce((end, write) => Math.max(end, write.end), -1);
815
+ const frame = { root: 'workflow', shadowed: true, lastWriteEnd };
816
+ this.emit(this.walk(expression, { focus: { origin: 'workflow' }, frame, tainted: false }));
817
+ return this.references;
818
+ }
819
+ }
820
+ /** Liquid fragments have lookup brackets, but no JSONata focus/binding grammar. */
821
+ function liquidReferences(expression, result, liquidShadows) {
822
+ let at = 0;
823
+ let previous = '';
824
+ while (at < expression.length) {
825
+ const char = expression[at];
826
+ if (char === '"' || char === "'") {
827
+ const quote = char;
828
+ at += 1;
829
+ while (at < expression.length) {
830
+ if (expression[at] === '\\') {
831
+ at += 2;
832
+ continue;
833
+ }
834
+ if (expression[at++] === quote)
835
+ break;
836
+ }
837
+ previous = quote;
838
+ continue;
839
+ }
840
+ if (char === '#') {
841
+ const end = expression.indexOf('\n', at);
842
+ at = end < 0 ? expression.length : end + 1;
843
+ continue;
844
+ }
845
+ if (!liquidWordCharacter.test(char)) {
846
+ if (liquidBlankCharacter.test(char)) {
847
+ at += 1;
848
+ continue;
849
+ }
850
+ const next = skipFrontendTrivia(expression, at);
851
+ if (next !== at) {
852
+ at = next;
853
+ continue;
854
+ }
855
+ previous = char;
856
+ at += 1;
857
+ continue;
858
+ }
859
+ const start = at++;
860
+ while (at < expression.length && liquidWordCharacter.test(expression[at]))
861
+ at += 1;
862
+ const name = expression.slice(start, at);
863
+ const property = previous === '.';
864
+ previous = name;
865
+ if (property || (name !== 'outputs' && name !== '_outputs'))
866
+ continue;
867
+ let selector = skipFrontendTrivia(expression, at);
868
+ let key;
869
+ if (expression[selector] === '.') {
870
+ selector = skipFrontendTrivia(expression, selector + 1, liquidBlankCharacter);
871
+ const keyStart = selector;
872
+ while (selector < expression.length && liquidWordCharacter.test(expression[selector]))
873
+ selector += 1;
874
+ if (selector > keyStart)
875
+ key = expression.slice(keyStart, selector);
876
+ }
877
+ else if (expression[selector] === '[') {
878
+ selector = skipFrontendTrivia(expression, selector + 1, liquidBlankCharacter);
879
+ const quote = expression[selector];
880
+ if (quote === '"' || quote === "'") {
881
+ const keyStart = ++selector;
882
+ while (selector < expression.length && expression[selector] !== quote && expression[selector] !== '\\')
883
+ selector += 1;
884
+ if (expression[selector] === quote && expression[skipFrontendTrivia(expression, selector + 1, liquidBlankCharacter)] === ']')
885
+ key = expression.slice(keyStart, selector);
886
+ }
887
+ }
888
+ else if (name !== '_outputs')
889
+ continue;
890
+ const shadowed = (liquidShadows & (name === 'outputs' ? 1 : 2)) !== 0;
891
+ result.push({ namespace: name, rootCertainty: shadowed ? 'uncertain' : 'definite', ...(key === undefined ? {} : { key }) });
892
+ }
893
+ }
894
+ /** Inspect the owning field's grammar, never treating literal Liquid text as a root read. */
895
+ export function frontendOutputReferences(value, rawJsonata = false) {
896
+ const prefixed = value.startsWith('jsonata::');
897
+ const jsonata = prefixed || rawJsonata;
898
+ const expressions = frontendExpressionsIn(prefixed ? value.slice(9) : value, jsonata);
899
+ const result = [];
900
+ for (let index = 0; index < expressions.length; index += 1) {
901
+ const { text: expression, liquidShadows } = expressions[index];
902
+ if (jsonata && index === expressions.length - 1) {
903
+ const tokens = jsonataTokens(expression);
904
+ const parser = new JsonataStructure(tokens);
905
+ const structure = parser.parse();
906
+ const analyzer = new JsonataReferences();
907
+ const references = parser.limited ? [] : analyzer.inspect(structure);
908
+ if (parser.limited || analyzer.limited) {
909
+ // Only recognizable namespace names are reported. Partial structural
910
+ // results cannot establish definite ownership after a depth refusal.
911
+ for (const namespace of ['outputs', '_outputs']) {
912
+ if (tokens.some((token) => ['name', 'backtick', 'string'].includes(token.kind) && token.value === namespace))
913
+ result.push({ namespace, rootCertainty: 'uncertain' });
914
+ }
915
+ }
916
+ else
917
+ result.push(...references);
918
+ }
919
+ else
920
+ liquidReferences(expression, result, liquidShadows);
921
+ }
922
+ return result;
923
+ }
924
+ //# sourceMappingURL=frontendReferences.js.map