@serene-pub/sdk 0.6.0-pr-7 → 0.6.0-pr-8

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 (79) hide show
  1. package/dist/annexFields.d.ts +14 -0
  2. package/dist/annexFields.js +7 -0
  3. package/dist/announce.d.ts +26 -13
  4. package/dist/announce.js +31 -0
  5. package/dist/appletCard.d.ts +17 -0
  6. package/dist/appletCard.js +60 -0
  7. package/dist/attributes.d.ts +3 -3
  8. package/dist/attributes.js +1 -1
  9. package/dist/builder.d.ts +23 -6
  10. package/dist/builder.js +57 -5
  11. package/dist/cadences.d.ts +11 -2
  12. package/dist/cadences.js +27 -2
  13. package/dist/characterProfile.d.ts +137 -0
  14. package/dist/characterProfile.js +24 -0
  15. package/dist/component.d.ts +1 -1
  16. package/dist/componentImports.d.ts +1 -1
  17. package/dist/componentImports.js +2 -0
  18. package/dist/declarations.js +4 -0
  19. package/dist/descriptors.d.ts +68 -3
  20. package/dist/descriptors.js +23 -0
  21. package/dist/document.d.ts +8 -0
  22. package/dist/document.js +44 -1
  23. package/dist/events.d.ts +35 -4
  24. package/dist/events.js +7 -3
  25. package/dist/executor.js +26 -5
  26. package/dist/extension.d.ts +17 -0
  27. package/dist/fit.d.ts +4 -1
  28. package/dist/fit.js +43 -1
  29. package/dist/functions.d.ts +7 -1
  30. package/dist/functions.js +3 -1
  31. package/dist/genres.d.ts +7 -0
  32. package/dist/genres.js +32 -1
  33. package/dist/hookGrants.js +10 -0
  34. package/dist/index.d.ts +4 -0
  35. package/dist/index.js +9 -0
  36. package/dist/layout.d.ts +18 -0
  37. package/dist/libraryDraft.d.ts +2 -0
  38. package/dist/libraryDraft.js +5 -1
  39. package/dist/lorebookFile.d.ts +8 -0
  40. package/dist/lorebookFile.js +21 -0
  41. package/dist/participants.d.ts +53 -8
  42. package/dist/participants.js +9 -5
  43. package/dist/pluginPermissions.js +1 -1
  44. package/dist/promptBlocks.d.ts +5 -1
  45. package/dist/promptBlocks.js +23 -8
  46. package/dist/registry.js +6 -3
  47. package/dist/sceneSettings.d.ts +4 -0
  48. package/dist/sceneSettings.js +7 -4
  49. package/dist/sessionDossier.d.ts +57 -0
  50. package/dist/sessionLayout.d.ts +296 -85
  51. package/dist/sessionLayout.js +397 -133
  52. package/dist/settings.d.ts +28 -1
  53. package/dist/settings.js +50 -2
  54. package/dist/shapes.d.ts +6 -1
  55. package/dist/shapes.js +6 -1
  56. package/dist/sheetLatitude.d.ts +148 -0
  57. package/dist/sheetLatitude.js +161 -0
  58. package/dist/storyTime.js +6 -4
  59. package/dist/surfaces.d.ts +11 -1
  60. package/dist/template.d.ts +26 -1
  61. package/dist/templateCheck.d.ts +24 -0
  62. package/dist/templateCheck.js +299 -7
  63. package/dist/templateFit.js +4 -0
  64. package/dist/templateIds.d.ts +6 -0
  65. package/dist/templateIds.js +9 -0
  66. package/dist/turnLock.d.ts +10 -1
  67. package/dist/turnLock.js +6 -1
  68. package/dist/turnOrder.d.ts +37 -4
  69. package/dist/turnOrder.js +49 -11
  70. package/dist/validate.d.ts +4 -2
  71. package/dist/validate.js +15 -11
  72. package/dist/variableLayouts.d.ts +141 -0
  73. package/dist/variableLayouts.js +183 -0
  74. package/dist/variables.d.ts +35 -7
  75. package/dist/variables.js +34 -1
  76. package/dist/widgetDecls.js +12 -0
  77. package/dist/widgets.d.ts +384 -41
  78. package/dist/widgets.js +23 -0
  79. package/package.json +1 -1
@@ -20,6 +20,10 @@
20
20
  * - **unknown-path** — a field the declared type positively contradicts
21
21
  * (`characters.nmae`, a field read straight off a list).
22
22
  * - **unknown-helper** — a Handlebars helper nobody registered.
23
+ * - **layout-argument** — a `layout` call that does not name a variable in
24
+ * scope that a variable layout writes out, and a layout reference in quotes.
25
+ * - **unknown-layout** — a layout reference that is malformed, or that the
26
+ * variable does not offer (checked only when the host supplies offers).
23
27
  *
24
28
  * Conservative by construction: an `'any'` root, a record's author-chosen
25
29
  * key, a dynamic lookup (`lookup`, `a[k]`) and a subexpression's result are
@@ -33,10 +37,11 @@
33
37
  * @experimental
34
38
  */
35
39
  import Handlebars from 'handlebars';
36
- import { Liquid, Tag, Hash, analyzeSync } from 'liquidjs';
40
+ import { Liquid, Tag, Hash, Value, TokenKind, analyzeSync, toValueSync } from 'liquidjs';
37
41
  import { handlebars as handlebarsEngine, liquid as liquidEngine } from './engines.js';
38
42
  import { enterHandlebarsBlock, nearestName, resolveHandlebarsPath, rootHandlebarsReach, typeOfHandlebarsPath, } from './handlebarsReach.js';
39
43
  import { resolvePath } from './template.js';
44
+ import { VARIABLE_LAYOUT_HELPER, parseVariableLayoutReference } from './variableLayouts.js';
40
45
  /**
41
46
  * Helpers Handlebars itself registers. A host's own (`json`, `isSet`, …) are
42
47
  * an input — {@link TemplateCheckOptions.helpers} — never hard-coded here.
@@ -82,7 +87,7 @@ export function checkTemplateSourceReport(engine, src, scope, options = {}) {
82
87
  catch (err) {
83
88
  return { checked: true, findings: [syntaxFinding(err, lines)] };
84
89
  }
85
- const sink = new FindingSink(scope, options.untyped ?? [], lines);
90
+ const sink = new FindingSink(scope, options.untyped ?? [], lines, isHandlebars ? 'handlebars' : 'liquid', options.variableLayoutOffers);
86
91
  try {
87
92
  if (isHandlebars)
88
93
  walkHandlebars(parsed, scope, helperSet(options), sink);
@@ -107,6 +112,17 @@ function lineStarts(src) {
107
112
  }
108
113
  /** 1-based line, 1-based column → 0-based offset. */
109
114
  const offsetOf = (lines, line, column) => (lines[line - 1] ?? 0) + column - 1;
115
+ /** 0-based offset → 1-based line and column. */
116
+ function positionAtOffset(lines, offset) {
117
+ let line = 1;
118
+ for (let i = 0; i < lines.length; i++) {
119
+ if (lines[i] <= offset)
120
+ line = i + 1;
121
+ else
122
+ break;
123
+ }
124
+ return { line, column: offset - lines[line - 1] + 1 };
125
+ }
110
126
  /**
111
127
  * Read a line and column off whatever the engine threw — the engine's own
112
128
  * report, never a guess. Handlebars sets `lineNumber` when a block does not
@@ -141,16 +157,42 @@ function syntaxFinding(err, lines) {
141
157
  ...(at.line ? { start: offsetOf(lines, at.line, at.column ?? 1) } : {}),
142
158
  };
143
159
  }
160
+ const LAYOUT_EXAMPLE = 'core/json@1';
161
+ /** The sentences a `layout` call is refused with, by engine. */
162
+ const LAYOUT_WORDS = {
163
+ handlebars: {
164
+ shape: 'layout takes a variable in scope and a quoted layout reference: {{{layout characters "core/json@1"}}}.',
165
+ shapeFix: 'write {{{layout characters "core/json@1"}}}',
166
+ reference: 'layout\'s second argument is a layout reference in quotes, such as "core/json@1" — a path or a subexpression can\'t be checked, or laid out before the template runs.',
167
+ referenceFix: 'write the layout reference in quotes: "core/json@1"',
168
+ plain: (key) => `{{{${key}}}}`,
169
+ },
170
+ liquid: {
171
+ shape: 'layout comes straight after the variable\'s name: {{ characters | layout: "core/json@1" }}.',
172
+ shapeFix: 'write {{ characters | layout: "core/json@1" }}',
173
+ reference: 'layout takes exactly one argument, a layout reference in quotes, such as "core/json@1" — a path or a keyword argument can\'t be checked, or laid out before the template runs.',
174
+ referenceFix: 'write the layout reference in quotes: layout: "core/json@1"',
175
+ plain: (key) => `{{ ${key} }}`,
176
+ },
177
+ };
178
+ /** The variable whose layout writes this declaration out, when one does. */
179
+ const laidOutByOf = (decl) => decl && decl !== 'any' && !Array.isArray(decl) && typeof decl.laidOutBy === 'string'
180
+ ? decl.laidOutBy
181
+ : undefined;
144
182
  class FindingSink {
145
183
  scope;
146
184
  untyped;
147
185
  lines;
186
+ engine;
187
+ offers;
148
188
  findings = [];
149
189
  seen = new Set();
150
- constructor(scope, untyped, lines) {
190
+ constructor(scope, untyped, lines, engine = 'handlebars', offers) {
151
191
  this.scope = scope;
152
192
  this.untyped = untyped;
153
193
  this.lines = lines;
194
+ this.engine = engine;
195
+ this.offers = offers;
154
196
  }
155
197
  get nameSeverity() {
156
198
  return this.untyped.length ? 'warning' : 'error';
@@ -239,6 +281,92 @@ class FindingSink {
239
281
  get scopeNames() {
240
282
  return Object.keys(this.scope);
241
283
  }
284
+ /** A `layout` call written wrongly: which argument, and the sentence that says how. */
285
+ layoutArgument(kind, at, tag) {
286
+ const words = LAYOUT_WORDS[this.engine];
287
+ this.push({
288
+ kind: 'layout-argument',
289
+ severity: 'error',
290
+ name: VARIABLE_LAYOUT_HELPER,
291
+ message: kind === 'shape' ? words.shape : words.reference,
292
+ fix: kind === 'shape' ? words.shapeFix : words.referenceFix,
293
+ ...at,
294
+ ...(tag ? { tag } : {}),
295
+ });
296
+ }
297
+ /**
298
+ * Judge a well-formed `layout` call: the key, then the reference. One
299
+ * judgement for both engines. `keyReported` is true when the ordinary walk
300
+ * already says the key is missing (an unknown name), so it is not said twice.
301
+ */
302
+ layoutCall(key, keyAt, reference, referenceAt, keyReported, tag) {
303
+ const laidBy = laidOutByOf(this.scope[key]);
304
+ if (laidBy === undefined) {
305
+ if (keyReported)
306
+ return;
307
+ const laidKeys = Object.keys(this.scope).filter((k) => laidOutByOf(this.scope[k]));
308
+ const suggestion = nearestName(key, laidKeys);
309
+ this.push({
310
+ kind: 'layout-argument',
311
+ severity: 'error',
312
+ name: key,
313
+ path: key,
314
+ message: `"${key}" is not written out by a variable layout, so it has no layout to name. ` +
315
+ `Write ${LAYOUT_WORDS[this.engine].plain(key)}.` +
316
+ (suggestion ? ` Did you mean "${suggestion}"?` : ''),
317
+ fix: suggestion
318
+ ? `use "${suggestion}"`
319
+ : laidKeys.length
320
+ ? `variables with layouts here: ${laidKeys.join(', ')}`
321
+ : 'no variable here has layouts — drop the layout call',
322
+ available: laidKeys,
323
+ ...(suggestion ? { suggestion } : {}),
324
+ ...keyAt,
325
+ ...(tag ? { tag } : {}),
326
+ });
327
+ return;
328
+ }
329
+ const refs = (this.offers?.[laidBy] ?? []).map((o) => o.reference);
330
+ const base = { name: reference, path: reference, ...referenceAt, ...(tag ? { tag } : {}) };
331
+ if (!parseVariableLayoutReference(reference)) {
332
+ const suggestion = this.offers ? nearestName(reference, refs) : undefined;
333
+ this.push({
334
+ kind: 'unknown-layout',
335
+ severity: 'error',
336
+ message: `"${reference}" isn't a layout reference — write <owner>/<slug>@<major>, such as "${LAYOUT_EXAMPLE}".` +
337
+ (suggestion ? ` Did you mean "${suggestion}"?` : ''),
338
+ fix: suggestion
339
+ ? `use "${suggestion}"`
340
+ : `write <owner>/<slug>@<major>, such as "${refs[0] ?? LAYOUT_EXAMPLE}"`,
341
+ ...(this.offers ? { available: refs } : {}),
342
+ ...(suggestion ? { suggestion } : {}),
343
+ ...base,
344
+ });
345
+ }
346
+ else if (this.offers) {
347
+ if (refs.includes(reference))
348
+ return;
349
+ const suggestion = nearestName(reference, refs);
350
+ this.push({
351
+ kind: 'unknown-layout',
352
+ severity: 'error',
353
+ message: `"${reference}" isn't a layout of ${key}.` +
354
+ (suggestion ? ` Did you mean "${suggestion}"?` : ''),
355
+ fix: suggestion
356
+ ? `use "${suggestion}"`
357
+ : refs.length
358
+ ? `layouts here: ${refs.join(', ')}`
359
+ : `${key} offers no layouts here`,
360
+ available: refs,
361
+ ...(suggestion ? { suggestion } : {}),
362
+ ...base,
363
+ });
364
+ }
365
+ // No offers (the packager, or any check with no host in view): a
366
+ // well-formed reference passes silently. The host always supplies
367
+ // offers at save, select and in the editor, so a warning here would
368
+ // fire on every reference a plugin writes and say nothing new.
369
+ }
242
370
  }
243
371
  function helperSet(options) {
244
372
  return new Set([...HANDLEBARS_BUILTIN_HELPERS, ...(options.helpers ?? [])]);
@@ -256,7 +384,7 @@ const readPath = (p) => ({
256
384
  const simpleName = (p) => isPath(p) && !p.data && !p.depth && p.parts?.length === 1 && !scopedOf(p)
257
385
  ? p.parts[0]
258
386
  : undefined;
259
- function walkHandlebars(ast, scope, helpers, sink) {
387
+ function walkHandlebars(ast, scope, helpers, sink, layoutCalls) {
260
388
  const knownHelpers = [...helpers].sort();
261
389
  const lines = sink.lines;
262
390
  const spanOf = (loc) => loc
@@ -265,6 +393,15 @@ function walkHandlebars(ast, scope, helpers, sink) {
265
393
  end: offsetOf(lines, loc.end.line, loc.end.column + 1),
266
394
  }
267
395
  : undefined;
396
+ const atOf = (loc) => {
397
+ const s = spanOf(loc);
398
+ return {
399
+ line: loc?.start.line ?? 1,
400
+ column: (loc?.start.column ?? 0) + 1,
401
+ start: s?.start ?? 0,
402
+ end: s?.end ?? 0,
403
+ };
404
+ };
268
405
  const ref = (node, reach, tag) => {
269
406
  if (!node)
270
407
  return;
@@ -285,9 +422,43 @@ function walkHandlebars(ast, scope, helpers, sink) {
285
422
  for (const pair of node.hash?.pairs ?? [])
286
423
  ref(pair.value, reach, tag);
287
424
  };
425
+ /** `{{{layout characters "core/json@1"}}}` — in a mustache, a subexpression or (wrongly) a block. */
426
+ const layoutCall = (node, reach, tag, block) => {
427
+ const params = node.params ?? [];
428
+ const pairs = node.hash?.pairs ?? [];
429
+ const [first, second] = params;
430
+ const key = simpleName(first);
431
+ let bad;
432
+ let which = 'shape';
433
+ if (block || params.length !== 2 || pairs.length)
434
+ bad = atOf(pairs.length && params.length === 2 ? pairs[0].loc : node.path.loc);
435
+ else if (key === undefined)
436
+ bad = atOf(first.loc);
437
+ else if (second.type !== 'StringLiteral') {
438
+ bad = atOf(second.loc);
439
+ which = 'reference';
440
+ }
441
+ if (bad) {
442
+ sink.layoutArgument(which, bad, tag);
443
+ args(node, reach, tag);
444
+ return;
445
+ }
446
+ const reference = second.value;
447
+ ref(first, reach, tag);
448
+ layoutCalls?.push({ key: key, reference });
449
+ const r = resolveHandlebarsPath(readPath(first), reach, scope);
450
+ const quote = atOf(second.loc);
451
+ sink.layoutCall(key, atOf(first.loc), reference, {
452
+ ...positionAtOffset(lines, quote.start + 1),
453
+ start: quote.start + 1,
454
+ end: quote.start + 1 + reference.length,
455
+ }, r.kind === 'unknown-root', tag);
456
+ };
288
457
  /** A helper invocation — `(eq a b)`, `{{pad x 2}}`: the name is a helper, the rest are values. */
289
458
  const call = (node, reach, tag) => {
290
459
  const name = simpleName(node.path);
460
+ if (name === VARIABLE_LAYOUT_HELPER)
461
+ return layoutCall(node, reach, tag, false);
291
462
  if (name !== undefined && !helpers.has(name))
292
463
  sink.unknownHelper(name, knownHelpers, node.path.loc?.start.line ?? 1, (node.path.loc?.start.column ?? 0) + 1, tag);
293
464
  else if (name === undefined)
@@ -303,6 +474,8 @@ function walkHandlebars(ast, scope, helpers, sink) {
303
474
  switch (node.type) {
304
475
  case 'MustacheStatement': {
305
476
  const m = node;
477
+ if (simpleName(m.path) === VARIABLE_LAYOUT_HELPER)
478
+ return layoutCall(m, reach, tag, false);
306
479
  if (m.params?.length || m.hash?.pairs?.length)
307
480
  return call(m, reach, tag);
308
481
  // `{{log}}`-style: a bare name that IS a helper is a call, not a read.
@@ -315,9 +488,13 @@ function walkHandlebars(ast, scope, helpers, sink) {
315
488
  const b = node;
316
489
  // `{{#foo}}` is always an invocation, never a variable.
317
490
  const name = simpleName(b.path);
318
- if (name !== undefined && !helpers.has(name))
319
- sink.unknownHelper(name, knownHelpers, b.path.loc?.start.line ?? 1, (b.path.loc?.start.column ?? 0) + 1, tag);
320
- args(b, reach, tag);
491
+ if (name === VARIABLE_LAYOUT_HELPER)
492
+ layoutCall(b, reach, tag, true);
493
+ else {
494
+ if (name !== undefined && !helpers.has(name))
495
+ sink.unknownHelper(name, knownHelpers, b.path.loc?.start.line ?? 1, (b.path.loc?.start.column ?? 0) + 1, tag);
496
+ args(b, reach, tag);
497
+ }
321
498
  const helper = name ?? '';
322
499
  const first = b.params?.[0];
323
500
  const target = (helper === 'each' || helper === 'with') && isPath(first)
@@ -442,6 +619,8 @@ function makeLiquid(o) {
442
619
  // Parse only: a filter need exist, not work.
443
620
  for (const name of o.filters ?? [])
444
621
  liquid.registerFilter(name, (v) => v);
622
+ // `layout` is always known: the checker judges the call itself.
623
+ liquid.registerFilter(VARIABLE_LAYOUT_HELPER, (v) => v);
445
624
  return liquid;
446
625
  }
447
626
  /** Liquid answers these on a list (and `size` on a string) without a declaration. */
@@ -489,6 +668,16 @@ function walkLiquid(templates, src, scope, sink) {
489
668
  // the conservative line. Loop items are therefore unchecked.
490
669
  const analysis = analyzeSync(templates, { partials: false });
491
670
  const lines = sink.lines;
671
+ for (const { value, tag } of liquidValues(templates))
672
+ value.filters.forEach((filter, index) => {
673
+ if (filter.name !== VARIABLE_LAYOUT_HELPER)
674
+ return;
675
+ const call = liquidLayoutCall(value, index, lines);
676
+ if ('bad' in call)
677
+ return sink.layoutArgument(call.bad, call.at, tag);
678
+ const key = call.key;
679
+ sink.layoutCall(key, call.keyAt, call.reference, call.referenceAt, scope[key] === undefined && key in analysis.globals, tag);
680
+ });
492
681
  for (const [root, uses] of Object.entries(analysis.globals))
493
682
  for (const use of uses) {
494
683
  const { row, col } = use.location;
@@ -513,4 +702,107 @@ function walkLiquid(templates, src, scope, sink) {
513
702
  sink.badPath(r, root, written, row, col);
514
703
  }
515
704
  }
705
+ /** A tag or output's `{{ … }}`/`{% … %}` span. */
706
+ const tokenSpan = (t) => {
707
+ const token = t.token;
708
+ return token ? { start: token.begin, end: token.end } : undefined;
709
+ };
710
+ /**
711
+ * Every filtered value a template writes — `{{ … }}` output and tag arguments
712
+ * such as `{% assign x = … %}` — in source order, nested blocks included. The
713
+ * walk liquidjs's own `analyzeSync` makes: `arguments()`, then `children()`.
714
+ */
715
+ function liquidValues(templates) {
716
+ const out = [];
717
+ const visit = (t) => {
718
+ const tag = tokenSpan(t);
719
+ const impl = t;
720
+ if (impl.arguments)
721
+ for (const arg of impl.arguments())
722
+ if (arg instanceof Value)
723
+ out.push({ value: arg, tag });
724
+ if (impl.children)
725
+ for (const child of toValueSync(impl.children(false, true)) ?? [])
726
+ visit(child);
727
+ };
728
+ for (const t of templates)
729
+ visit(t);
730
+ return out;
731
+ }
732
+ /** Judge the shape of the `layout` filter at `index` in `value`. One judgement for the check and the listing. */
733
+ function liquidLayoutCall(value, index, lines) {
734
+ const filter = value.filters[index];
735
+ const token = filter.token;
736
+ const atOffsets = (start, end) => ({
737
+ ...positionAtOffset(lines, start),
738
+ start,
739
+ end,
740
+ });
741
+ const filterAt = atOffsets(token.begin, token.end);
742
+ const postfix = value.initial.postfix;
743
+ const initial = postfix.length === 1 ? postfix[0] : undefined;
744
+ const key = initial?.getText();
745
+ if (index !== 0 ||
746
+ initial?.kind !== TokenKind.PropertyAccess ||
747
+ !key ||
748
+ !/^[A-Za-z_][\w-]*$/.test(key))
749
+ return { bad: 'shape', at: filterAt };
750
+ const args = filter.args;
751
+ if (args.length !== 1)
752
+ return { bad: 'shape', at: filterAt };
753
+ const arg = args[0];
754
+ if (Array.isArray(arg) || arg.kind !== TokenKind.Quoted || typeof arg.content !== 'string') {
755
+ const t = (Array.isArray(arg) ? arg[1] : arg);
756
+ return {
757
+ bad: 'reference',
758
+ at: t ? atOffsets(t.begin, t.end) : filterAt,
759
+ };
760
+ }
761
+ return {
762
+ key,
763
+ keyAt: atOffsets(initial.begin, initial.end),
764
+ reference: arg.content,
765
+ referenceAt: atOffsets(arg.begin + 1, arg.begin + 1 + arg.content.length),
766
+ };
767
+ }
768
+ /**
769
+ * Every `layout` call in `src`, in source order, duplicates kept, calls inside
770
+ * blocks included. A call is listed when its key is a simple root name and its
771
+ * reference a string literal — whether or not the reference is well-formed or
772
+ * offered, because the render pre-pass must see every call it will meet and
773
+ * the check is what refuses. A call written wrongly (a path for a key, a
774
+ * reference that is not a literal, the wrong number of arguments, a Liquid
775
+ * `layout` that is not the first filter) is not listed. Same parser and walk
776
+ * as {@link checkTemplateSource}. A source that does not parse, or an engine
777
+ * this checker does not read, lists nothing.
778
+ * @experimental
779
+ */
780
+ export function variableLayoutCalls(engine, src, options = {}) {
781
+ if (!canCheckTemplateEngine(engine))
782
+ return [];
783
+ const calls = [];
784
+ const lines = lineStarts(src);
785
+ try {
786
+ if (engine === handlebarsEngine.id) {
787
+ const ast = Handlebars.parse(src);
788
+ const sink = new FindingSink({}, [], lines);
789
+ walkHandlebars(ast, {}, helperSet(options), sink, calls);
790
+ }
791
+ else {
792
+ const templates = liquidFor(options).parse(src);
793
+ for (const { value } of liquidValues(templates))
794
+ value.filters.forEach((filter, index) => {
795
+ if (filter.name !== VARIABLE_LAYOUT_HELPER)
796
+ return;
797
+ const call = liquidLayoutCall(value, index, lines);
798
+ if (!('bad' in call))
799
+ calls.push({ key: call.key, reference: call.reference });
800
+ });
801
+ }
802
+ }
803
+ catch {
804
+ return [];
805
+ }
806
+ return calls;
807
+ }
516
808
  //# sourceMappingURL=templateCheck.js.map
@@ -68,6 +68,10 @@ function clause(f) {
68
68
  return `it does not parse (${f.message})`;
69
69
  case 'unknown-helper':
70
70
  return `it calls \`${f.name}\`, which is not a helper here`;
71
+ case 'layout-argument':
72
+ return `a \`layout\` call there doesn't name a variable with layouts and a quoted layout reference`;
73
+ case 'unknown-layout':
74
+ return `it names the layout "${written}", which isn't a layout of that variable here`;
71
75
  default:
72
76
  return `it uses \`${written}\`, which nothing supplies here`;
73
77
  }
@@ -125,6 +125,12 @@ export interface TemplateSeed {
125
125
  body: string | Record<string, string>;
126
126
  /** The human title. Defaults to the id's name segment where absent. */
127
127
  label?: string;
128
+ /**
129
+ * 🚧 `variables` only: the slug of this layout's reference
130
+ * `<owner>/<slug>@<major>`, whose owner and major are the id's. Kebab-case.
131
+ * Absent, the reference's slug is the id's name segment.
132
+ */
133
+ slug?: string;
128
134
  }
129
135
  /**
130
136
  * Everything wrong with one declared template, in the author's words.
@@ -48,6 +48,7 @@
48
48
  * overlap is recorded here rather than left to be discovered.
49
49
  * @ruling R19, R19
50
50
  */
51
+ import { VARIABLE_LAYOUT_SLUG } from './variableLayouts.js';
51
52
  /**
52
53
  * The grammar, mirroring the attribute slot id's exactly one kind segment over.
53
54
  * Owner is a plugin slug (`vendor.plugin`) or `core`; name is kebab-case;
@@ -139,6 +140,14 @@ export function templateSeedProblems(t, owner) {
139
140
  problems.push(`template '${t.id}' has kind '${t.kind}'. ` +
140
141
  `A shipped template fills a 'prompts', 'template' or 'variables' slot.`);
141
142
  }
143
+ if (t.slug !== undefined) {
144
+ if (t.kind === 'prompts' || t.kind === 'template')
145
+ problems.push(`template '${t.id}' is ${t.kind === 'prompts' ? 'a prompts row' : 'a context template'} and declares a slug — ` +
146
+ `only a variable layout has a layout reference; drop 'slug'.`);
147
+ else if (typeof t.slug !== 'string' || !VARIABLE_LAYOUT_SLUG.test(t.slug))
148
+ problems.push(`template '${t.id}' has slug '${String(t.slug)}', which is not kebab-case — lowercase ` +
149
+ `letters and digits joined by '-' (titled-json).`);
150
+ }
142
151
  return problems;
143
152
  }
144
153
  //# sourceMappingURL=templateIds.js.map
@@ -42,6 +42,11 @@
42
42
  export interface TurnMessage {
43
43
  id: number;
44
44
  speakerId: number | null;
45
+ /**
46
+ * 🚧 The speaker's cast member (the member behind `speakerId`), when the
47
+ * asker knows. What a `seated_member` owner matches on — never `speakerId`.
48
+ */
49
+ castMemberId?: number | null;
45
50
  /**
46
51
  * The **turn** the message belongs to — the run that created it — when
47
52
  * the asker knows. Optional: absent, the
@@ -63,7 +68,11 @@ export interface TurnMessage {
63
68
  * @experimental
64
69
  */
65
70
  export interface TurnOwner {
66
- kind: 'session' | 'session_cast';
71
+ /**
72
+ * `session_cast`'s `id` is the card — ⏳ removed in S5 of the seat-cast
73
+ * programme. 🚧 `seated_member`'s `id` is the cast member id.
74
+ */
75
+ kind: 'session' | 'session_cast' | 'seated_member';
67
76
  id: number;
68
77
  }
69
78
  /**
package/dist/turnLock.js CHANGED
@@ -44,8 +44,13 @@
44
44
  export function openAnchorFor(messages, owner) {
45
45
  if (owner.kind === 'session')
46
46
  return messages.length ? messages[messages.length - 1].id : null;
47
+ // A card id and a cast member id share one number range: a `seated_member`
48
+ // owner is matched on `castMemberId` alone, never on `speakerId`.
49
+ const matches = owner.kind === 'seated_member'
50
+ ? (m) => m.castMemberId === owner.id
51
+ : (m) => m.speakerId === owner.id;
47
52
  for (let i = messages.length - 1; i >= 0; i--)
48
- if (messages[i].speakerId === owner.id)
53
+ if (matches(messages[i]))
49
54
  return messages[i].id;
50
55
  return null;
51
56
  }
@@ -97,6 +97,12 @@ export interface TurnHistoryMessage {
97
97
  role: string;
98
98
  characterId?: number | null;
99
99
  personaId?: number | null;
100
+ /**
101
+ * 🚧 The speaker's cast member (the host's `cast_member_id` on the row).
102
+ * Read through the cast lookup (`refOfMember`) when one is given; absent,
103
+ * the card form is read (⏳ until S5 of the seat-cast programme).
104
+ */
105
+ castMemberId?: number | null;
100
106
  isHidden?: boolean | null;
101
107
  isNarratorResponse?: boolean | null;
102
108
  /**
@@ -114,9 +120,19 @@ export interface TurnHistoryMessage {
114
120
  * carries; null for a row from neither. The one reading of a sender —
115
121
  * the row that opens a round (`spokenRefsSince`) is read by it.
116
122
  *
123
+ * 🚧 `refOfMember` is the cast lookup: a cast member id → the seat's `ref`, as
124
+ * the cast entry whose `castMemberId` matches carries it. When the row has a
125
+ * `castMemberId` and the lookup returns a ref, that ref is the sender; it
126
+ * changes **identity only**, never whether a row is a sender (an assistant row
127
+ * never becomes one). Without the lookup the card form is read (⏳ until S5 of
128
+ * the seat-cast programme). A sender is always a player seat's line, so the
129
+ * lookup is asked for a `'player-seat'`.
130
+ *
117
131
  * @experimental 🚧 provisional with the turn-order vocabulary.
118
132
  */
119
- export declare function senderRefOf(m: Pick<TurnHistoryMessage, 'personaId' | 'speaker' | 'metadata'>): `character:${number}` | `player-seat:${number}` | null;
133
+ export declare function senderRefOf(m: Pick<TurnHistoryMessage, 'personaId' | 'castMemberId' | 'speaker' | 'metadata'>, refOfMember?: (castMemberId: number,
134
+ /** Which kind of seat the caller means; the lookup prefers a seat of that kind and falls back to any seat of the member. */
135
+ seatKind?: 'character-seat' | 'player-seat') => ParticipantRef | null | undefined): ParticipantRef | null;
120
136
  /**
121
137
  * The rows that count as turns: not hidden, not narration. Hidden rows and
122
138
  * narrator responses are outside the rotation entirely. A missing row (`null`
@@ -129,7 +145,8 @@ export declare function senderRefOf(m: Pick<TurnHistoryMessage, 'personaId' | 's
129
145
  export declare function countedTurns<M extends TurnHistoryMessage>(messages: readonly (M | null | undefined)[]): M[];
130
146
  /**
131
147
  * Which participants have already spoken since the person last did, as
132
- * references (`character:<id>`, `player-seat:<id>`, `envoy:<slug>`).
148
+ * references (`character:<id>`, 🚧 `seated-member:<id>`, `player-seat:<id>`,
149
+ * `envoy:<slug>`).
133
150
  *
134
151
  * Three readings, one per kind, each the fact that kind leaves in the
135
152
  * history: a character's id on a reply row, an envoy's reference on a reply
@@ -139,10 +156,20 @@ export declare function countedTurns<M extends TurnHistoryMessage>(messages: rea
139
156
  * envoy's reply marks no character. Before any user row the whole history is
140
157
  * one round, so a greeting counts as its character's turn.
141
158
  *
159
+ * 🚧 `refOfMember` is the cast lookup: a cast member id → the seat's `ref`, as
160
+ * the cast entry whose `castMemberId` matches carries it. A row with a
161
+ * `castMemberId` the lookup answers is read as that ref (a card-less member's
162
+ * reply too); otherwise the card form is read (⏳ until S5 of the seat-cast
163
+ * programme). It changes identity only, never whether a row counts. Without
164
+ * it the answer is as it was. A reply row asks the lookup for a `'character-seat'`,
165
+ * the opening person's row for a `'player-seat'`.
166
+ *
142
167
  * @experimental 🚧 provisional with the turn-order vocabulary.
143
168
  * @ruling PLAN-turn-order §4.4
144
169
  */
145
- export declare function spokenRefsSince(messages: readonly (TurnHistoryMessage | null | undefined)[]): Set<string>;
170
+ export declare function spokenRefsSince(messages: readonly (TurnHistoryMessage | null | undefined)[], refOfMember?: (castMemberId: number,
171
+ /** Which kind of seat the caller means; the lookup prefers a seat of that kind and falls back to any seat of the member. */
172
+ seatKind?: 'character-seat' | 'player-seat') => ParticipantRef | null | undefined): Set<string>;
146
173
  /**
147
174
  * Round robin — once per turn of the person's: every candidate that has not
148
175
  * spoken since the person last did, in candidate order, each entry
@@ -153,8 +180,14 @@ export declare function spokenRefsSince(messages: readonly (TurnHistoryMessage |
153
180
  * This is the rule `core:task/turn-round-robin@1` runs, and the fallback a
154
181
  * plugin's own strategy should use rather than carry a copy of it.
155
182
  *
183
+ * 🚧 `refOfMember` is the cast lookup, passed through to `spokenRefsSince`
184
+ * (see there, with its seat-kind hint); without it the card form is read (⏳ until
185
+ * S5 of the seat-cast programme).
186
+ *
156
187
  * @experimental 🚧 provisional with the turn-order vocabulary.
157
188
  * @ruling PLAN-turn-order §4.4
158
189
  */
159
- export declare function roundRobinOrder(candidates: readonly TurnCandidateV1[], messages: readonly (TurnHistoryMessage | null | undefined)[]): TurnEntryV1[];
190
+ export declare function roundRobinOrder(candidates: readonly TurnCandidateV1[], messages: readonly (TurnHistoryMessage | null | undefined)[], refOfMember?: (castMemberId: number,
191
+ /** Which kind of seat the caller means; the lookup prefers a seat of that kind and falls back to any seat of the member. */
192
+ seatKind?: 'character-seat' | 'player-seat') => ParticipantRef | null | undefined): TurnEntryV1[];
160
193
  //# sourceMappingURL=turnOrder.d.ts.map