@gameslate/sdk 0.3.11 → 0.3.13

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 CHANGED
@@ -61,6 +61,9 @@ validates it and writes every file.
61
61
 
62
62
  `0.3.x` speaks plugin contract (`sdkApi`) 3: new 0.3 versions add tools, never change the contract. The core refuses a plugin built for another contract.
63
63
 
64
+ - **Next** (not yet published): `gameslate-plugin addresses` takes `statics`, file-static
65
+ variables placed at their object's section base in the ld map plus the offset their accessor
66
+ shows (IDO keeps statics out of the map), each with its `evidence`.
64
67
  - **0.3.9** (not yet published): `gameslate-plugin addresses` takes `expectSizes` and fails
65
68
  when the probe disagrees with a size the decomp states. `verify.json`'s `expect` also checks the inventory (`has`,
66
69
  `lacks`, `exactly`), the equipped item (`null` for nothing) and flags; a flag the state doesn't
@@ -29,6 +29,9 @@ const { values, positionals } = parseArgs({
29
29
  'core-version': { type: 'string' },
30
30
  id: { type: 'string' },
31
31
  name: { type: 'string' },
32
+ readme: { type: 'string' },
33
+ built: { type: 'string' },
34
+ write: { type: 'boolean' },
32
35
  },
33
36
  allowPositionals: true,
34
37
  });
@@ -39,6 +42,7 @@ const USAGE = [
39
42
  ' gameslate-plugin validate <builtDir> [--core-version <version>]',
40
43
  ' gameslate-plugin verify <verify.json>',
41
44
  ' gameslate-plugin addresses <spec.json> [--out <file.ts>]',
45
+ ' gameslate-plugin support <gamesDir> [--readme README.md] [--built <builtDir>] [--write]',
42
46
  ' gameslate-plugin names <map or symbol file> … does the decomp name the game? (triage)',
43
47
  ].join('\n');
44
48
 
@@ -154,6 +158,51 @@ if (command === 'build' && dir && values.out) {
154
158
  const text = addressModule(table, provenance);
155
159
  if (values.out) fs.writeFileSync(path.resolve(values.out), text);
156
160
  else process.stdout.write(text);
161
+ } else if (command === 'support' && dir) {
162
+ const {
163
+ inspectPlugin,
164
+ loadQuickJs,
165
+ readPluginManifest,
166
+ supportContextsFromPlugin,
167
+ verifyOrWriteSupportDocs,
168
+ } = await import('../lib/host/index.js');
169
+ const gamesDir = path.resolve(dir);
170
+ const topReadmePath = path.resolve(values.readme ?? 'README.md');
171
+ let expectedGameIds;
172
+ let codeByGame;
173
+ if (values.built) {
174
+ const builtDir = path.resolve(values.built);
175
+ const read = readPluginManifest(builtDir);
176
+ if ('problem' in read) {
177
+ console.error(`refused: ${read.problem}`);
178
+ process.exit(1);
179
+ }
180
+ expectedGameIds = read.manifest.games.map(g => g.id);
181
+ const coreVersion = values['core-version'] ?? read.manifest.testedWith[0] ?? '0.0.0';
182
+ const inspected = inspectPlugin(await loadQuickJs(), builtDir, read.manifest, {
183
+ coreVersion,
184
+ log: line => console.error(line),
185
+ });
186
+ if (typeof inspected === 'string') {
187
+ console.error(`refused: ${inspected}`);
188
+ process.exit(1);
189
+ }
190
+ codeByGame = supportContextsFromPlugin(inspected);
191
+ }
192
+ const { entries, problems } = verifyOrWriteSupportDocs({
193
+ gamesDir,
194
+ topReadmePath,
195
+ expectedGameIds,
196
+ codeByGame,
197
+ write: Boolean(values.write),
198
+ });
199
+ for (const p of problems) console.error(`refused: ${p}`);
200
+ if (problems.length === 0) {
201
+ console.log(
202
+ `support docs OK (${entries.length} games -> ${path.relative(process.cwd(), topReadmePath) || path.basename(topReadmePath)})`,
203
+ );
204
+ }
205
+ process.exit(problems.length ? 1 : 0);
157
206
  } else if (command === 'names' && dir) {
158
207
  const { parseSymbolFile, triageNames } = await import('../lib/host/index.js');
159
208
  const symbols = new Map(
@@ -10,6 +10,8 @@ export declare const ItemSchema: z.ZodObject<{
10
10
  short: z.ZodOptional<z.ZodString>;
11
11
  /** where/how it's obtained, spoiler-light */
12
12
  source: z.ZodOptional<z.ZodString>;
13
+ /** a counter holding how many the player holds (potions in a pouch): its slot shows ×N */
14
+ count: z.ZodOptional<z.ZodString>;
13
15
  }, "strict", z.ZodTypeAny, {
14
16
  label: string;
15
17
  id: string;
@@ -17,6 +19,7 @@ export declare const ItemSchema: z.ZodObject<{
17
19
  source?: string | undefined;
18
20
  category?: string | undefined;
19
21
  short?: string | undefined;
22
+ count?: string | undefined;
20
23
  }, {
21
24
  label: string;
22
25
  id: string;
@@ -24,6 +27,7 @@ export declare const ItemSchema: z.ZodObject<{
24
27
  source?: string | undefined;
25
28
  category?: string | undefined;
26
29
  short?: string | undefined;
30
+ count?: string | undefined;
27
31
  }>;
28
32
  export type CatalogueItem = z.infer<typeof ItemSchema>;
29
33
  export declare const CounterSchema: z.ZodObject<{
@@ -36,14 +40,16 @@ export declare const CounterSchema: z.ZodObject<{
36
40
  display: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
37
41
  /** what core features know it as: the AI's health and magic, the "no small key" chip */
38
42
  role: z.ZodOptional<z.ZodEnum<["health", "magic", "armor", "keys"]>>;
39
- /** `percent`: a 0..max bar (max defaults to 1), shown as a percentage */
40
- format: z.ZodOptional<z.ZodEnum<["number", "percent"]>>;
43
+ /** `percent`: a 0..max bar (max defaults to 1), shown as a percentage. `duration`: whole
44
+ * milliseconds, shown as 1'23"456 (also in chips); any other value reads as unknown, and
45
+ * `display` doesn't apply */
46
+ format: z.ZodOptional<z.ZodEnum<["number", "percent", "duration"]>>;
41
47
  }, "strict", z.ZodTypeAny, {
42
48
  label: string;
43
49
  id: string;
44
50
  icon?: string | undefined;
45
51
  max?: string | number | undefined;
46
- format?: "number" | "percent" | undefined;
52
+ format?: "number" | "duration" | "percent" | undefined;
47
53
  display?: Record<string, string> | undefined;
48
54
  role?: "keys" | "health" | "magic" | "armor" | undefined;
49
55
  }, {
@@ -51,7 +57,7 @@ export declare const CounterSchema: z.ZodObject<{
51
57
  id: string;
52
58
  icon?: string | undefined;
53
59
  max?: string | number | undefined;
54
- format?: "number" | "percent" | undefined;
60
+ format?: "number" | "duration" | "percent" | undefined;
55
61
  display?: Record<string, string> | undefined;
56
62
  role?: "keys" | "health" | "magic" | "armor" | undefined;
57
63
  }>;
@@ -96,16 +102,23 @@ export declare const LayoutSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<
96
102
  id: z.ZodString;
97
103
  title: z.ZodString;
98
104
  counters: z.ZodArray<z.ZodString, "many">;
105
+ /** leave out a counter the state doesn't have rather than show it as unknown (per-player
106
+ * counters a one-player game has no value for); a layout left empty is left out. A
107
+ * counter the decoder failed to read is hidden too, so use it only where absence means
108
+ * "doesn't apply" */
109
+ hideMissing: z.ZodOptional<z.ZodBoolean>;
99
110
  }, "strict", z.ZodTypeAny, {
100
111
  id: string;
101
112
  title: string;
102
113
  counters: string[];
103
114
  kind: "counters";
115
+ hideMissing?: boolean | undefined;
104
116
  }, {
105
117
  id: string;
106
118
  title: string;
107
119
  counters: string[];
108
120
  kind: "counters";
121
+ hideMissing?: boolean | undefined;
109
122
  }>]>;
110
123
  export type CatalogueLayout = z.infer<typeof LayoutSchema>;
111
124
  export declare const MissionStepSchema: z.ZodObject<{
@@ -581,6 +594,8 @@ export declare const CatalogueSchema: z.ZodObject<{
581
594
  short: z.ZodOptional<z.ZodString>;
582
595
  /** where/how it's obtained, spoiler-light */
583
596
  source: z.ZodOptional<z.ZodString>;
597
+ /** a counter holding how many the player holds (potions in a pouch): its slot shows ×N */
598
+ count: z.ZodOptional<z.ZodString>;
584
599
  }, "strict", z.ZodTypeAny, {
585
600
  label: string;
586
601
  id: string;
@@ -588,6 +603,7 @@ export declare const CatalogueSchema: z.ZodObject<{
588
603
  source?: string | undefined;
589
604
  category?: string | undefined;
590
605
  short?: string | undefined;
606
+ count?: string | undefined;
591
607
  }, {
592
608
  label: string;
593
609
  id: string;
@@ -595,6 +611,7 @@ export declare const CatalogueSchema: z.ZodObject<{
595
611
  source?: string | undefined;
596
612
  category?: string | undefined;
597
613
  short?: string | undefined;
614
+ count?: string | undefined;
598
615
  }>, "many">;
599
616
  counters: z.ZodArray<z.ZodObject<{
600
617
  id: z.ZodString;
@@ -606,14 +623,16 @@ export declare const CatalogueSchema: z.ZodObject<{
606
623
  display: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
607
624
  /** what core features know it as: the AI's health and magic, the "no small key" chip */
608
625
  role: z.ZodOptional<z.ZodEnum<["health", "magic", "armor", "keys"]>>;
609
- /** `percent`: a 0..max bar (max defaults to 1), shown as a percentage */
610
- format: z.ZodOptional<z.ZodEnum<["number", "percent"]>>;
626
+ /** `percent`: a 0..max bar (max defaults to 1), shown as a percentage. `duration`: whole
627
+ * milliseconds, shown as 1'23"456 (also in chips); any other value reads as unknown, and
628
+ * `display` doesn't apply */
629
+ format: z.ZodOptional<z.ZodEnum<["number", "percent", "duration"]>>;
611
630
  }, "strict", z.ZodTypeAny, {
612
631
  label: string;
613
632
  id: string;
614
633
  icon?: string | undefined;
615
634
  max?: string | number | undefined;
616
- format?: "number" | "percent" | undefined;
635
+ format?: "number" | "duration" | "percent" | undefined;
617
636
  display?: Record<string, string> | undefined;
618
637
  role?: "keys" | "health" | "magic" | "armor" | undefined;
619
638
  }, {
@@ -621,7 +640,7 @@ export declare const CatalogueSchema: z.ZodObject<{
621
640
  id: string;
622
641
  icon?: string | undefined;
623
642
  max?: string | number | undefined;
624
- format?: "number" | "percent" | undefined;
643
+ format?: "number" | "duration" | "percent" | undefined;
625
644
  display?: Record<string, string> | undefined;
626
645
  role?: "keys" | "health" | "magic" | "armor" | undefined;
627
646
  }>, "many">;
@@ -651,16 +670,23 @@ export declare const CatalogueSchema: z.ZodObject<{
651
670
  id: z.ZodString;
652
671
  title: z.ZodString;
653
672
  counters: z.ZodArray<z.ZodString, "many">;
673
+ /** leave out a counter the state doesn't have rather than show it as unknown (per-player
674
+ * counters a one-player game has no value for); a layout left empty is left out. A
675
+ * counter the decoder failed to read is hidden too, so use it only where absence means
676
+ * "doesn't apply" */
677
+ hideMissing: z.ZodOptional<z.ZodBoolean>;
654
678
  }, "strict", z.ZodTypeAny, {
655
679
  id: string;
656
680
  title: string;
657
681
  counters: string[];
658
682
  kind: "counters";
683
+ hideMissing?: boolean | undefined;
659
684
  }, {
660
685
  id: string;
661
686
  title: string;
662
687
  counters: string[];
663
688
  kind: "counters";
689
+ hideMissing?: boolean | undefined;
664
690
  }>]>, "many">;
665
691
  missions: z.ZodArray<z.ZodObject<{
666
692
  id: z.ZodString;
@@ -1048,7 +1074,7 @@ export declare const CatalogueSchema: z.ZodObject<{
1048
1074
  id: string;
1049
1075
  icon?: string | undefined;
1050
1076
  max?: string | number | undefined;
1051
- format?: "number" | "percent" | undefined;
1077
+ format?: "number" | "duration" | "percent" | undefined;
1052
1078
  display?: Record<string, string> | undefined;
1053
1079
  role?: "keys" | "health" | "magic" | "armor" | undefined;
1054
1080
  }[];
@@ -1060,6 +1086,7 @@ export declare const CatalogueSchema: z.ZodObject<{
1060
1086
  source?: string | undefined;
1061
1087
  category?: string | undefined;
1062
1088
  short?: string | undefined;
1089
+ count?: string | undefined;
1063
1090
  }[];
1064
1091
  chips: {
1065
1092
  label: string;
@@ -1078,6 +1105,7 @@ export declare const CatalogueSchema: z.ZodObject<{
1078
1105
  title: string;
1079
1106
  counters: string[];
1080
1107
  kind: "counters";
1108
+ hideMissing?: boolean | undefined;
1081
1109
  })[];
1082
1110
  missions: {
1083
1111
  id: string;
@@ -1167,7 +1195,7 @@ export declare const CatalogueSchema: z.ZodObject<{
1167
1195
  id: string;
1168
1196
  icon?: string | undefined;
1169
1197
  max?: string | number | undefined;
1170
- format?: "number" | "percent" | undefined;
1198
+ format?: "number" | "duration" | "percent" | undefined;
1171
1199
  display?: Record<string, string> | undefined;
1172
1200
  role?: "keys" | "health" | "magic" | "armor" | undefined;
1173
1201
  }[];
@@ -1179,6 +1207,7 @@ export declare const CatalogueSchema: z.ZodObject<{
1179
1207
  source?: string | undefined;
1180
1208
  category?: string | undefined;
1181
1209
  short?: string | undefined;
1210
+ count?: string | undefined;
1182
1211
  }[];
1183
1212
  chips: {
1184
1213
  label: string;
@@ -1197,6 +1226,7 @@ export declare const CatalogueSchema: z.ZodObject<{
1197
1226
  title: string;
1198
1227
  counters: string[];
1199
1228
  kind: "counters";
1229
+ hideMissing?: boolean | undefined;
1200
1230
  })[];
1201
1231
  missions: {
1202
1232
  id: string;
package/lib/catalogue.js CHANGED
@@ -17,6 +17,8 @@ export const ItemSchema = z
17
17
  short: z.string().optional(),
18
18
  /** where/how it's obtained, spoiler-light */
19
19
  source: z.string().optional(),
20
+ /** a counter holding how many the player holds (potions in a pouch): its slot shows ×N */
21
+ count: Id.optional(),
20
22
  })
21
23
  .strict();
22
24
  export const CounterSchema = z
@@ -30,8 +32,10 @@ export const CounterSchema = z
30
32
  display: z.record(z.string(), z.string()).optional(),
31
33
  /** what core features know it as: the AI's health and magic, the "no small key" chip */
32
34
  role: z.enum(['health', 'magic', 'armor', 'keys']).optional(),
33
- /** `percent`: a 0..max bar (max defaults to 1), shown as a percentage */
34
- format: z.enum(['number', 'percent']).optional(),
35
+ /** `percent`: a 0..max bar (max defaults to 1), shown as a percentage. `duration`: whole
36
+ * milliseconds, shown as 1'23"456 (also in chips); any other value reads as unknown, and
37
+ * `display` doesn't apply */
38
+ format: z.enum(['number', 'percent', 'duration']).optional(),
35
39
  })
36
40
  .strict();
37
41
  /** A variant of the game the decoder can report (`state.variant`). */
@@ -60,6 +64,11 @@ export const LayoutSchema = z.discriminatedUnion('kind', [
60
64
  id: Id,
61
65
  title: z.string(),
62
66
  counters: z.array(Id).min(1),
67
+ /** leave out a counter the state doesn't have rather than show it as unknown (per-player
68
+ * counters a one-player game has no value for); a layout left empty is left out. A
69
+ * counter the decoder failed to read is hidden too, so use it only where absence means
70
+ * "doesn't apply" */
71
+ hideMissing: z.boolean().optional(),
63
72
  })
64
73
  .strict(),
65
74
  ]);
@@ -272,19 +281,32 @@ function checkDuplicateIds(cat) {
272
281
  ];
273
282
  return groups.flatMap(([what, ids]) => duplicates(ids).map(d => `duplicate ${what} id "${d}"`));
274
283
  }
284
+ /* every place a catalogue names a counter by id, with where it says so */
285
+ function counterReferences(cat) {
286
+ const refs = [
287
+ ...cat.missions.map((m) => [
288
+ `mission ${m.id}.progress`,
289
+ m.progress?.counter,
290
+ ]),
291
+ ...cat.collectibles.map((c) => [
292
+ `collectibles ${c.id}.counter`,
293
+ c.counter,
294
+ ]),
295
+ ...cat.items.map((i) => [`item ${i.id}.count`, i.count]),
296
+ ...cat.counters.map((c) => [
297
+ `counter ${c.id}.max`,
298
+ typeof c.max === 'string' ? c.max : undefined,
299
+ ]),
300
+ ];
301
+ return refs.flatMap(([where, id]) => (id === undefined ? [] : [[where, id]]));
302
+ }
275
303
  function checkStructure(cat, known) {
276
- const problems = [];
277
- for (const m of cat.missions) {
278
- if (m.progress && !known.counters.has(m.progress.counter)) {
279
- problems.push(`mission ${m.id}.progress: unknown counter "${m.progress.counter}"`);
280
- }
281
- }
304
+ const problems = counterReferences(cat)
305
+ .filter(([, id]) => !known.counters.has(id))
306
+ .map(([where, id]) => `${where}: unknown counter "${id}"`);
282
307
  for (const set of cat.collectibles) {
283
308
  if (!set.entries && !set.localSource)
284
309
  problems.push(`collectibles ${set.id}: needs entries or a localSource`);
285
- if (set.counter && !known.counters.has(set.counter)) {
286
- problems.push(`collectibles ${set.id}.counter: unknown counter "${set.counter}"`);
287
- }
288
310
  }
289
311
  for (const layout of cat.inventoryLayouts) {
290
312
  const [ids, pool, noun] = layout.kind === 'slotGrid'
@@ -293,11 +315,6 @@ function checkStructure(cat, known) {
293
315
  for (const id of ids.filter(x => !pool.has(x)))
294
316
  problems.push(`layout ${layout.id}: unknown ${noun} "${id}"`);
295
317
  }
296
- for (const c of cat.counters) {
297
- if (typeof c.max === 'string' && !known.counters.has(c.max)) {
298
- problems.push(`counter ${c.id}.max: unknown counter "${c.max}"`);
299
- }
300
- }
301
318
  return problems;
302
319
  }
303
320
  /**
package/lib/chips.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Catalogue } from './catalogue.js';
1
+ import type { Catalogue, CatalogueCounter } from './catalogue.js';
2
2
  import type { EvaluationContext } from './condition.js';
3
3
  import type { GameState } from './types.js';
4
4
  /** Values a chip's label and prompt may reference: `{location}`, `{difficulty}`, `{counter:id}`. */
@@ -8,7 +8,7 @@ export interface ChipVars {
8
8
  }
9
9
  /** null when a referenced value isn't available, so the caller drops the chip instead of
10
10
  * showing "{difficulty}" or "undefined" to the player. */
11
- export declare function fillChipText(text: string, vars: ChipVars, state: GameState): string | null;
11
+ export declare function fillChipText(text: string, vars: ChipVars, state: GameState, counters?: readonly CatalogueCounter[]): string | null;
12
12
  export interface FilledChip {
13
13
  id: string;
14
14
  label: string;
package/lib/chips.js CHANGED
@@ -1,12 +1,20 @@
1
1
  import { evaluate, readCounter } from './condition.js';
2
+ import { getCounterView } from './status.js';
2
3
  const PLACEHOLDER_RE = /\{(location|difficulty|counter:[A-Za-z0-9_:.-]+)\}/g;
4
+ /* a duration reads as a time (1'23"456), as its card shows it; other counters as their number */
5
+ function counterText(id, state, counters) {
6
+ const counter = counters.find(c => c.id === id);
7
+ if (counter?.format === 'duration')
8
+ return getCounterView(counter, state)?.text;
9
+ return readCounter(state, id)?.toString();
10
+ }
3
11
  /** null when a referenced value isn't available, so the caller drops the chip instead of
4
12
  * showing "{difficulty}" or "undefined" to the player. */
5
- export function fillChipText(text, vars, state) {
13
+ export function fillChipText(text, vars, state, counters = []) {
6
14
  let missing = false;
7
15
  const out = text.replace(PLACEHOLDER_RE, (_m, key) => {
8
16
  const value = key.startsWith('counter:')
9
- ? readCounter(state, key.slice('counter:'.length))?.toString()
17
+ ? counterText(key.slice('counter:'.length), state, counters)
10
18
  : key === 'location'
11
19
  ? vars.location
12
20
  : vars.difficulty;
@@ -21,8 +29,8 @@ export function getActiveChips(catalogue, state, vars, ctx = {}) {
21
29
  return catalogue.chips.flatMap((chip) => {
22
30
  if (chip.when && evaluate(chip.when, state, ctx) !== 'met')
23
31
  return [];
24
- const label = fillChipText(chip.label, vars, state);
25
- const prompt = fillChipText(chip.prompt, vars, state);
32
+ const label = fillChipText(chip.label, vars, state, catalogue.counters);
33
+ const prompt = fillChipText(chip.prompt, vars, state, catalogue.counters);
26
34
  return label && prompt ? [{ id: chip.id, label, prompt }] : [];
27
35
  });
28
36
  }
@@ -0,0 +1,5 @@
1
+ export type YamlScalar = string | boolean;
2
+ export type YamlNode = YamlScalar | YamlScalar[] | Array<Record<string, YamlScalar>> | {
3
+ [k: string]: YamlNode;
4
+ };
5
+ export declare function parseSupportYaml(yamlBlock: string): Record<string, YamlNode>;
@@ -0,0 +1,124 @@
1
+ /*
2
+ * Minimal strict YAML parser for `<game>/README.md` support frontmatter: nested mappings,
3
+ * scalars (`true`/`false`/strings), inline `[a, b]` arrays, and `- key: val` object lists.
4
+ */
5
+ function stripComment(raw) {
6
+ let inSingle = false;
7
+ let inDouble = false;
8
+ for (let i = 0; i < raw.length; i++) {
9
+ const ch = raw[i];
10
+ if (ch === "'" && !inDouble)
11
+ inSingle = !inSingle;
12
+ else if (ch === '"' && !inSingle)
13
+ inDouble = !inDouble;
14
+ else if (ch === '#' && !inSingle && !inDouble && (i === 0 || raw[i - 1] === ' ')) {
15
+ return raw.slice(0, i).trimEnd();
16
+ }
17
+ }
18
+ return raw.trimEnd();
19
+ }
20
+ function parseScalar(raw) {
21
+ const s = raw.trim();
22
+ if (s === 'true')
23
+ return true;
24
+ if (s === 'false')
25
+ return false;
26
+ if ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'"))) {
27
+ return s.slice(1, -1);
28
+ }
29
+ return s;
30
+ }
31
+ function parseInlineArray(raw) {
32
+ const inner = raw.slice(1, -1).trim();
33
+ if (!inner)
34
+ return [];
35
+ return inner.split(',').map(part => parseScalar(part));
36
+ }
37
+ function tokenizeYaml(yamlText) {
38
+ const out = [];
39
+ const rawLines = yamlText.split(/\r?\n/);
40
+ rawLines.forEach((raw, idx) => {
41
+ if (raw.includes('\t'))
42
+ throw new Error(`YAML line ${idx + 1}: tabs are not allowed`);
43
+ const cleaned = stripComment(raw);
44
+ if (!cleaned.trim())
45
+ return;
46
+ const indent = cleaned.length - cleaned.trimStart().length;
47
+ out.push({ num: idx + 1, indent, text: cleaned.trim() });
48
+ });
49
+ return out;
50
+ }
51
+ function parseSequenceOfObjects(lines, start, baseIndent) {
52
+ const items = [];
53
+ let i = start;
54
+ while (i < lines.length) {
55
+ const line = lines[i];
56
+ if (!line || line.indent < baseIndent || !line.text.startsWith('- '))
57
+ break;
58
+ if (line.indent !== baseIndent)
59
+ throw new Error(`YAML line ${line.num}: unexpected list indentation`);
60
+ const obj = {};
61
+ const firstRest = line.text.slice(2).trim();
62
+ const colon = firstRest.indexOf(':');
63
+ if (colon <= 0)
64
+ throw new Error(`YAML line ${line.num}: expected "- key: value"`);
65
+ obj[firstRest.slice(0, colon).trim()] = parseScalar(firstRest.slice(colon + 1));
66
+ i++;
67
+ while (i < lines.length) {
68
+ const sub = lines[i];
69
+ if (!sub || sub.indent <= baseIndent)
70
+ break;
71
+ const sc = sub.text.indexOf(':');
72
+ if (sc <= 0)
73
+ throw new Error(`YAML line ${sub.num}: expected "key: value"`);
74
+ obj[sub.text.slice(0, sc).trim()] = parseScalar(sub.text.slice(sc + 1));
75
+ i++;
76
+ }
77
+ items.push(obj);
78
+ }
79
+ return { value: items, next: i };
80
+ }
81
+ function parseMapping(lines, start, baseIndent) {
82
+ const map = {};
83
+ let i = start;
84
+ while (i < lines.length) {
85
+ const line = lines[i];
86
+ if (!line || line.indent < baseIndent)
87
+ break;
88
+ if (line.indent !== baseIndent)
89
+ throw new Error(`YAML line ${line.num}: unexpected indentation`);
90
+ const colon = line.text.indexOf(':');
91
+ if (colon <= 0)
92
+ throw new Error(`YAML line ${line.num}: expected "key: value"`);
93
+ const key = line.text.slice(0, colon).trim();
94
+ const rest = line.text.slice(colon + 1).trim();
95
+ if (rest.startsWith('[') && rest.endsWith(']')) {
96
+ map[key] = parseInlineArray(rest);
97
+ i++;
98
+ }
99
+ else if (rest.length > 0) {
100
+ map[key] = parseScalar(rest);
101
+ i++;
102
+ }
103
+ else {
104
+ const child = lines[i + 1];
105
+ if (!child || child.indent <= baseIndent) {
106
+ throw new Error(`YAML line ${line.num}: "${key}:" has no nested block`);
107
+ }
108
+ const parsed = child.text.startsWith('- ')
109
+ ? parseSequenceOfObjects(lines, i + 1, child.indent)
110
+ : parseMapping(lines, i + 1, child.indent);
111
+ map[key] = parsed.value;
112
+ i = parsed.next;
113
+ }
114
+ }
115
+ return { value: map, next: i };
116
+ }
117
+ export function parseSupportYaml(yamlBlock) {
118
+ const tokens = tokenizeYaml(yamlBlock);
119
+ const { value, next } = parseMapping(tokens, 0, 0);
120
+ if (next < tokens.length) {
121
+ throw new Error(`YAML line ${tokens[next]?.num ?? 0}: trailing content`);
122
+ }
123
+ return value;
124
+ }