@sjawhar/claude-envoy 5.10.1 → 5.10.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 (33) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.omp-plugin/plugin.json +1 -1
  3. package/dist/codex-hook.js +1242 -3
  4. package/dist/dispatch.js +1240 -1
  5. package/dist/envoy-channel.js +1389 -5
  6. package/dist/session-hook.js +1242 -3
  7. package/legion/agents/thermonuclear-code-quality.md +1 -0
  8. package/legion/agents/thermonuclear-deep-review.md +1 -0
  9. package/legion/skills/legion-architect/SKILL.md +1 -1
  10. package/legion/skills/legion-architect/references/acceptance.md +1 -2
  11. package/legion/skills/legion-architect/references/decomposition.md +4 -4
  12. package/legion/skills/legion-architect/references/design-gate.md +5 -3
  13. package/legion/skills/legion-architect/references/wake-routing.md +4 -4
  14. package/legion/skills/legion-controller/references/admission.md +3 -3
  15. package/legion/skills/legion-controller/references/consolidation.md +1 -1
  16. package/legion/skills/legion-controller/references/daily-report.md +1 -1
  17. package/legion/skills/legion-controller/references/finding-asks.md +2 -2
  18. package/legion/skills/legion-controller/references/parked-decisions.md +2 -2
  19. package/legion/skills/legion-controller/references/wakes.md +3 -3
  20. package/legion/skills/legion-oracle/SKILL.md +1 -3
  21. package/legion/skills/legion-retro/SKILL.md +3 -3
  22. package/legion/skills/legion-worker/SKILL.md +6 -8
  23. package/legion/skills/legion-worker/references/conflicts-and-rewrites.md +2 -2
  24. package/legion/skills/legion-worker/references/pr-body.md +1 -1
  25. package/package.json +1 -1
  26. package/skills/agent-secrets/SKILL.md +4 -4
  27. package/skills/envoy/references/check-settlement.md +2 -1
  28. package/skills/envoy/references/legion.md +1 -1
  29. package/skills/envoy/references/roles.md +1 -1
  30. package/skills/thermonuclear-code-quality/SKILL.md +0 -2
  31. package/skills/thermonuclear-deep-review/SKILL.md +0 -2
  32. package/legion/skills/legion-worker/references/default-branch-check.md +0 -31
  33. package/legion/skills/legion-worker/references/foreign-path.md +0 -19
@@ -14699,7 +14699,7 @@ var dispatchToolSpecs = [
14699
14699
  verdict: "pass",
14700
14700
  commit: "1111111111111111111111111111111111111111"
14701
14701
  },
14702
- description: "Record one result of one check of an issue's Verification document, or retract a result " + "recorded before. A record prints the pull-request body line it implies. Write that line " + "into the pull-request body unchanged: it is the one grammar every writer uses, and it " + "carries no link to Dispatch, no private host and no issue key: Dispatch keeps only words " + "of letters, digits and plain punctuation, and of those leaves out every word that holds " + "`://`, a private or Dispatch host, or an issue key of one of its projects; the record keeps " + "the whole reading. --dry-run prints the line the record would print, and records nothing. " + "Name the check by its block id. Where two Verification documents in reach hold that id, " + "name it by its canonical reference (dispatch://KEY/artifact/verification-md#b-<id>). " + "409 CHECK_AMBIGUOUS names both documents. An id no Verification document of the issue " + "or of an issue above it holds is 400 UNKNOWN_CHECK. " + `${CHECK_PROVED_BY_CI}. ` + "Dispatch reads its result from that run, so a record for it is 409 " + "CHECK_PROVED_BY_CI from every role, which names the check and the run. " + "A pass that counts a failed, a skipped or an excluded case contradicts itself, and is " + "400 RESULT_CONTRADICTS. " + "Dispatch asks GitHub whether the repository of the check's issue holds the commit. If " + "GitHub does not say that it does, Dispatch reads the external links of the check's issue: " + "a link to a GitHub pull request (https://github.com/<owner>/<repo>/pull/<n>) that is open " + "or merged, in a repository that Dispatch's GitHub App is installed on and can read, adds " + "the repository of that pull request. One record reads at most 10 linked pull requests. A " + "commit that none of these repositories holds is 400 RESULT_COMMIT_UNKNOWN, which names the " + "commit and each owner/repo that Dispatch asked. It also names, with its reason " + "(owner/repo#n (repository_unreadable)), each linked pull request that Dispatch could not " + "read, at most 10 and a count of the rest, and every linked pull request in whose " + "repository it could not read the commit, since each of those spent one of the record's 10 " + "reads, and says to grant Dispatch's GitHub App that repository or to link a readable pull " + "request. It says how many linked pull requests it left unread past that bound. Record the " + "result after the commit is pushed. A linked repository that the App is not installed on " + "or cannot read does " + "not count. Where a read of " + "a linked pull request or of a linked repository does not answer, and no repository is shown " + "to hold the commit, the record is 502 GITHUB_UNREADABLE and nothing is recorded: record the " + "result again, after the wait the refusal names for a rate limit. Where the issue has no " + "repository, the result is recorded as before. Where Dispatch cannot read the repository " + "of the check's issue, the result is recorded as before only when every linked read " + "answers and no linked repository holds the commit: a linked read that does not answer " + "is 502 GITHUB_UNREADABLE and nothing is recorded. " + "The result is recorded against the check's own issue, so a child's run of a parent's " + "check appears under that check. A closed issue takes a result only for a check whose " + "when is after_merge or default_branch, the production check after the merge. It refuses " + "every other record with 409 ISSUE_CLOSED, as it refuses every other write. " + "A check a document version rewords while the result is being written is 409 " + "CHECK_CONTENDED, with nothing recorded: run the same command again. " + RESULT_RETRACT_RULE + " The retraction keeps both records: the result stays readable, and it proves nothing " + "from then on. Record a new result where the check still needs one. A retraction is " + "taken on a closed issue and for a check of any when. Three callers may retract: the " + "session that recorded the result, a session that holds the Dispatch claim of the issue " + "the result was recorded on, and a caller whose credential carries a person. Every other " + "caller is 403 RETRACTION_FORBIDDEN. A result retracted already is 409 RESULT_RETRACTED. " + ISSUE_REFERENCE,
14702
+ description: "Record one result of one check of an issue's Verification document, or retract a result " + "recorded before. A record prints the pull-request body line it implies. Write that line " + "into the pull-request body unchanged: it is the one grammar every writer uses, and it " + "carries no link to Dispatch, no private host and no issue key: Dispatch keeps only words " + "of letters, digits and plain punctuation, and of those leaves out every word that holds " + "`://`, a private or Dispatch host, or an issue key of one of its projects; the record keeps " + "the whole reading. --dry-run prints the line the record would print, and records nothing. " + "Name the check by its block id. Where two Verification documents in reach hold that id, " + "name it by its canonical reference (dispatch://KEY/artifact/verification-md#b-<id>). " + "409 CHECK_AMBIGUOUS names both documents. An id no Verification document of the issue " + "or of an issue above it holds is 400 UNKNOWN_CHECK. " + `${CHECK_PROVED_BY_CI}. ` + "Dispatch reads its result from that run, so a record for it is 409 " + "CHECK_PROVED_BY_CI from every role, which names the check and the run. " + "A pass that counts a failed, a skipped or an excluded case contradicts itself, and is " + "400 RESULT_CONTRADICTS. " + "Dispatch asks GitHub whether the repository of the check's issue holds the commit. If " + "GitHub does not say that it does, Dispatch reads the external links of the check's issue: " + "a link to a GitHub pull request (https://github.com/<owner>/<repo>/pull/<n>) that is open " + "or merged, in a repository that Dispatch's GitHub App is installed on and can read, adds " + "the repository of that pull request. One record reads at most 10 linked pull requests. A " + "commit that none of these repositories holds is 400 RESULT_COMMIT_UNKNOWN, which names the " + "commit and each owner/repo that Dispatch asked. It also names, with its reason " + "(owner/repo#n (repository_unreadable)), each linked pull request that Dispatch could not " + "read, at most 10 and a count of the rest, and every linked pull request in whose " + "repository it could not read the commit, since each of those spent one of the record's 10 " + "reads, and says to grant Dispatch's GitHub App that repository or to link a readable pull " + "request. It says how many linked pull requests it left unread past that bound. Record the " + "result after the commit is pushed. A linked repository that the App is not installed on " + "or cannot read does " + "not count. Where a read of " + "a linked pull request or of a linked repository does not answer, and no repository is shown " + "to hold the commit, the record is 502 GITHUB_UNREADABLE and nothing is recorded: record the " + "result again, after the wait the refusal names for a rate limit. Where the issue has no " + "repository, the result is recorded as before. Where Dispatch cannot read the repository " + "of the check's issue, the result is recorded as before only when every linked read " + "answers and no linked repository holds the commit: a linked read that does not answer " + "is 502 GITHUB_UNREADABLE and nothing is recorded. " + "The result is recorded against the check's own issue, so a child's run of a parent's " + "check appears under that check. A closed issue takes a result only for a check whose " + "when is after_merge or default_branch, the production check after the merge. It refuses " + "every other record with 409 ISSUE_CLOSED. " + "A check a document version rewords while the result is being written is 409 " + "CHECK_CONTENDED, with nothing recorded: run the same command again. " + RESULT_RETRACT_RULE + " The retraction keeps both records: the result stays readable, and it proves nothing " + "from then on. Record a new result where the check still needs one. A retraction is " + "taken on a closed issue and for a check of any when. Three callers may retract: the " + "session that recorded the result, a session that holds the Dispatch claim of the issue " + "the result was recorded on, and a caller whose credential carries a person. Every other " + "caller is 403 RETRACTION_FORBIDDEN. A result retracted already is 409 RESULT_RETRACTED. " + ISSUE_REFERENCE,
14703
14703
  arguments: (z) => ({
14704
14704
  issue: z.string().describe(ISSUE_REFERENCE).optional(),
14705
14705
  check: z.string().describe("The check block's id, or its canonical reference dispatch://KEY/artifact/verification-md#b-<id> when the id is not unique among the issue's Verification document and those of the issues above it.").optional(),
@@ -18142,13 +18142,1129 @@ var DELIMITERS = {
18142
18142
  pipe: "|"
18143
18143
  };
18144
18144
  var DEFAULT_DELIMITER = DELIMITERS.comma;
18145
+ function trimSpaces(value) {
18146
+ let start = 0;
18147
+ let end = value.length;
18148
+ while (start < end && value[start] === " ")
18149
+ start++;
18150
+ while (end > start && value[end - 1] === " ")
18151
+ end--;
18152
+ return start === 0 && end === value.length ? value : value.slice(start, end);
18153
+ }
18145
18154
  function escapeString(value) {
18146
18155
  return value.replace(/\\/g, `\\\\`).replace(/"/g, `\\"`).replace(/\n/g, `\\n`).replace(/\r/g, `\\r`).replace(/\t/g, `\\t`).replace(/[\u0000-\u001F]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
18147
18156
  }
18157
+ function unescapeString(value) {
18158
+ let unescaped = "";
18159
+ let i = 0;
18160
+ while (i < value.length) {
18161
+ if (value[i] === "\\") {
18162
+ if (i + 1 >= value.length)
18163
+ throw new SyntaxError("Invalid escape sequence: backslash at end of string");
18164
+ const next = value[i + 1];
18165
+ if (next === "n") {
18166
+ unescaped += `
18167
+ `;
18168
+ i += 2;
18169
+ continue;
18170
+ }
18171
+ if (next === "t") {
18172
+ unescaped += "\t";
18173
+ i += 2;
18174
+ continue;
18175
+ }
18176
+ if (next === "r") {
18177
+ unescaped += "\r";
18178
+ i += 2;
18179
+ continue;
18180
+ }
18181
+ if (next === "\\") {
18182
+ unescaped += "\\";
18183
+ i += 2;
18184
+ continue;
18185
+ }
18186
+ if (next === '"') {
18187
+ unescaped += '"';
18188
+ i += 2;
18189
+ continue;
18190
+ }
18191
+ if (next === "u") {
18192
+ if (i + 6 > value.length)
18193
+ throw new SyntaxError(`Invalid escape sequence: truncated \\u escape at "${value.slice(i, i + 6)}"`);
18194
+ const hex = value.slice(i + 2, i + 6);
18195
+ if (!/^[0-9a-f]{4}$/i.test(hex))
18196
+ throw new SyntaxError(`Invalid escape sequence: \\u must be followed by 4 hex digits, got "${hex}"`);
18197
+ const codeUnit = Number.parseInt(hex, 16);
18198
+ if (codeUnit >= 55296 && codeUnit <= 57343)
18199
+ throw new SyntaxError(`Invalid escape sequence: \\u${hex} is a lone surrogate. Supplementary code points MUST appear as literal UTF-8`);
18200
+ unescaped += String.fromCodePoint(codeUnit);
18201
+ i += 6;
18202
+ continue;
18203
+ }
18204
+ throw new SyntaxError(`Invalid escape sequence: \\${next}`);
18205
+ }
18206
+ unescaped += value[i];
18207
+ i++;
18208
+ }
18209
+ return unescaped;
18210
+ }
18211
+ function findClosingQuote(content, start) {
18212
+ let i = start + 1;
18213
+ while (i < content.length) {
18214
+ if (content[i] === "\\" && i + 1 < content.length) {
18215
+ i += 2;
18216
+ continue;
18217
+ }
18218
+ if (content[i] === '"')
18219
+ return i;
18220
+ i++;
18221
+ }
18222
+ return -1;
18223
+ }
18224
+ function findUnquotedChar(content, char, start = 0) {
18225
+ let inQuotes = false;
18226
+ let i = start;
18227
+ while (i < content.length) {
18228
+ if (content[i] === "\\" && i + 1 < content.length && inQuotes) {
18229
+ i += 2;
18230
+ continue;
18231
+ }
18232
+ if (content[i] === '"') {
18233
+ inQuotes = !inQuotes;
18234
+ i++;
18235
+ continue;
18236
+ }
18237
+ if (content[i] === char && !inQuotes)
18238
+ return i;
18239
+ i++;
18240
+ }
18241
+ return -1;
18242
+ }
18243
+ var ToonDecodeError = class extends SyntaxError {
18244
+ constructor(message, context) {
18245
+ const prefix = context?.line !== undefined ? `Line ${context.line}: ` : "";
18246
+ super(prefix + message, context?.cause !== undefined ? { cause: context.cause } : undefined);
18247
+ this.name = "ToonDecodeError";
18248
+ this.line = context?.line;
18249
+ this.source = context?.source;
18250
+ }
18251
+ };
18252
+ function withLine(line, fn) {
18253
+ try {
18254
+ return fn();
18255
+ } catch (error) {
18256
+ if (error instanceof ToonDecodeError)
18257
+ throw error;
18258
+ if (error instanceof Error)
18259
+ throw new ToonDecodeError(error.message, {
18260
+ line: line.lineNumber,
18261
+ source: line.raw,
18262
+ cause: error
18263
+ });
18264
+ throw error;
18265
+ }
18266
+ }
18267
+ var LEADING_WHITESPACE_PATTERN = /^[ \t]*/;
18268
+ function createScanState() {
18269
+ return {
18270
+ lineNumber: 0,
18271
+ blankLines: []
18272
+ };
18273
+ }
18274
+ function parseLineIncremental(raw, state, indentSize, strict) {
18275
+ state.lineNumber++;
18276
+ const lineNumber = state.lineNumber;
18277
+ if (lineNumber === 1 && raw[0] === "\uFEFF")
18278
+ raw = raw.slice(1);
18279
+ if (raw[raw.length - 1] === "\r")
18280
+ raw = raw.slice(0, -1);
18281
+ const leadingWhitespace = LEADING_WHITESPACE_PATTERN.exec(raw)[0];
18282
+ const firstTabIndex = leadingWhitespace.indexOf("\t");
18283
+ const indent = strict && firstTabIndex !== -1 ? firstTabIndex : leadingWhitespace.length;
18284
+ const tabIndent = strict || firstTabIndex === -1 ? 0 : leadingWhitespace.split("\t").length - 1;
18285
+ const content = trimTrailingSpaces(raw.slice(indent));
18286
+ if (firstTabIndex === -1 && content[0] === "#")
18287
+ return;
18288
+ const depth = computeDepthFromIndent(indent - tabIndent, indentSize) + tabIndent;
18289
+ if (!content) {
18290
+ state.blankLines.push({
18291
+ lineNumber,
18292
+ indent,
18293
+ depth
18294
+ });
18295
+ return;
18296
+ }
18297
+ if (strict) {
18298
+ if (firstTabIndex !== -1)
18299
+ throw new ToonDecodeError("Tabs are not allowed in indentation in strict mode", {
18300
+ line: lineNumber,
18301
+ source: raw
18302
+ });
18303
+ if (indent > 0 && indent % indentSize !== 0)
18304
+ throw new ToonDecodeError(`Indentation must be exact multiple of ${indentSize}, but found ${indent} spaces`, {
18305
+ line: lineNumber,
18306
+ source: raw
18307
+ });
18308
+ }
18309
+ return {
18310
+ raw,
18311
+ indent,
18312
+ content,
18313
+ depth,
18314
+ lineNumber
18315
+ };
18316
+ }
18317
+ function computeDepthFromIndent(indentSpaces, indentSize) {
18318
+ return Math.floor(indentSpaces / indentSize);
18319
+ }
18320
+ function trimTrailingSpaces(value) {
18321
+ let end = value.length;
18322
+ while (end > 0 && value[end - 1] === " ")
18323
+ end--;
18324
+ return end === value.length ? value : value.slice(0, end);
18325
+ }
18148
18326
  var FETCH_LINE = Symbol("fetch-line");
18327
+ function createLineReader(context) {
18328
+ return {
18329
+ buffer: [],
18330
+ done: false,
18331
+ lastLine: undefined,
18332
+ scanState: createScanState(),
18333
+ indentSize: context.indentSize,
18334
+ strict: context.strict
18335
+ };
18336
+ }
18337
+ function* fillBuffer(reader) {
18338
+ while (reader.buffer.length === 0 && !reader.done) {
18339
+ const raw = yield FETCH_LINE;
18340
+ if (raw === undefined) {
18341
+ reader.done = true;
18342
+ return;
18343
+ }
18344
+ const parsedLine = parseLineIncremental(raw, reader.scanState, reader.indentSize, reader.strict);
18345
+ if (parsedLine !== undefined)
18346
+ reader.buffer.push(parsedLine);
18347
+ }
18348
+ }
18349
+ function* peekLine(reader) {
18350
+ yield* fillBuffer(reader);
18351
+ return reader.buffer[0];
18352
+ }
18353
+ function* readLine(reader) {
18354
+ yield* fillBuffer(reader);
18355
+ const line = reader.buffer[0];
18356
+ if (line !== undefined) {
18357
+ reader.buffer.shift();
18358
+ reader.lastLine = line;
18359
+ }
18360
+ return line;
18361
+ }
18362
+ function* driveSync(rawSource, rule) {
18363
+ const iterator = rawSource[Symbol.iterator]();
18364
+ let step = rule.next();
18365
+ while (!step.done)
18366
+ if (step.value === FETCH_LINE) {
18367
+ const result = iterator.next();
18368
+ step = rule.next(result.done ? undefined : result.value);
18369
+ } else {
18370
+ yield step.value;
18371
+ step = rule.next();
18372
+ }
18373
+ }
18374
+ var NUMERIC_LITERAL_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/i;
18149
18375
  function isBooleanOrNullLiteral(token) {
18150
18376
  return token === "true" || token === "false" || token === "null";
18151
18377
  }
18378
+ function isNumericLiteral(token) {
18379
+ if (!token)
18380
+ return false;
18381
+ if (!NUMERIC_LITERAL_PATTERN.test(token))
18382
+ return false;
18383
+ const numericValue = Number(token);
18384
+ return !Number.isNaN(numericValue) && Number.isFinite(numericValue);
18385
+ }
18386
+ function parseArrayHeaderLine(content, defaultDelimiter) {
18387
+ const trimmedToken = content.trimStart();
18388
+ let bracketStart = -1;
18389
+ if (trimmedToken.startsWith('"')) {
18390
+ const closingQuoteIndex = findClosingQuote(trimmedToken, 0);
18391
+ if (closingQuoteIndex === -1)
18392
+ return { kind: "notHeader" };
18393
+ if (!trimmedToken.slice(closingQuoteIndex + 1).startsWith("["))
18394
+ return { kind: "notHeader" };
18395
+ const keyEndIndex = content.length - trimmedToken.length + closingQuoteIndex + 1;
18396
+ bracketStart = content.indexOf("[", keyEndIndex);
18397
+ } else
18398
+ bracketStart = findUnquotedChar(content, "[");
18399
+ if (bracketStart === -1)
18400
+ return { kind: "notHeader" };
18401
+ const firstColonIndex = findUnquotedChar(content, ":");
18402
+ if (firstColonIndex !== -1 && firstColonIndex < bracketStart)
18403
+ return { kind: "notHeader" };
18404
+ const bracketEnd = findUnquotedChar(content, "]", bracketStart);
18405
+ if (bracketEnd === -1)
18406
+ return { kind: "notHeader" };
18407
+ let colonIndex = bracketEnd + 1;
18408
+ let braceEnd = colonIndex;
18409
+ const braceStart = findUnquotedChar(content, "{", bracketEnd);
18410
+ if (braceStart !== -1 && braceStart < findUnquotedChar(content, ":", bracketEnd)) {
18411
+ const gapBeforeBrace = content.slice(bracketEnd + 1, braceStart);
18412
+ if (gapBeforeBrace !== "") {
18413
+ const trimmedGap = gapBeforeBrace.trim();
18414
+ return {
18415
+ kind: "invalid",
18416
+ reason: trimmedGap === "" ? `Unexpected whitespace between bracket segment and field list` : `Unexpected content "${trimmedGap}" between bracket segment and field list`
18417
+ };
18418
+ }
18419
+ const foundBraceEnd = findMatchingBrace(content, braceStart);
18420
+ if (foundBraceEnd !== -1)
18421
+ braceEnd = foundBraceEnd + 1;
18422
+ }
18423
+ colonIndex = findUnquotedChar(content, ":", Math.max(bracketEnd, braceEnd));
18424
+ if (colonIndex === -1)
18425
+ return { kind: "notHeader" };
18426
+ const gapStart = Math.max(bracketEnd + 1, braceEnd);
18427
+ const gapBeforeColon = content.slice(gapStart, colonIndex);
18428
+ if (gapBeforeColon !== "") {
18429
+ const trimmedGap = gapBeforeColon.trim();
18430
+ return {
18431
+ kind: "invalid",
18432
+ reason: trimmedGap === "" ? `Unexpected whitespace between bracket segment and colon` : `Unexpected content "${trimmedGap}" between bracket segment and colon`
18433
+ };
18434
+ }
18435
+ let key;
18436
+ if (bracketStart > 0) {
18437
+ const rawKey = content.slice(0, bracketStart);
18438
+ if (rawKey !== rawKey.trimEnd())
18439
+ return {
18440
+ kind: "invalid",
18441
+ reason: "Unexpected whitespace between key and bracket segment"
18442
+ };
18443
+ key = rawKey.startsWith('"') ? parseStringLiteral(rawKey) : rawKey;
18444
+ }
18445
+ const afterColon = trimSpaces(content.slice(colonIndex + 1));
18446
+ const bracketContent = content.slice(bracketStart + 1, bracketEnd);
18447
+ let parsedBracket;
18448
+ try {
18449
+ parsedBracket = parseBracketSegment(bracketContent, defaultDelimiter);
18450
+ } catch (error) {
18451
+ return {
18452
+ kind: "invalid",
18453
+ reason: error.message
18454
+ };
18455
+ }
18456
+ const { length, delimiter, keyed } = parsedBracket;
18457
+ let fields;
18458
+ if (braceStart !== -1 && braceStart < colonIndex) {
18459
+ const foundBraceEnd = findMatchingBrace(content, braceStart);
18460
+ if (foundBraceEnd !== -1 && foundBraceEnd < colonIndex) {
18461
+ const fieldsContent = content.slice(braceStart + 1, foundBraceEnd);
18462
+ const mismatchedDelimiter = findUnquotedMismatchedDelimiter(fieldsContent, delimiter);
18463
+ if (mismatchedDelimiter !== undefined)
18464
+ return {
18465
+ kind: "invalid",
18466
+ reason: `Header delimiter mismatch: bracket declares "${formatDelimiter(delimiter)}" but field list contains unquoted "${formatDelimiter(mismatchedDelimiter)}"`
18467
+ };
18468
+ try {
18469
+ fields = parseFieldEntries(fieldsContent, delimiter);
18470
+ } catch (error) {
18471
+ return {
18472
+ kind: "invalid",
18473
+ reason: error.message
18474
+ };
18475
+ }
18476
+ }
18477
+ }
18478
+ const duplicateFieldName = fields ? findDuplicateFieldName(fields) : undefined;
18479
+ const duplicateReason = duplicateFieldName ? `Duplicate field name "${duplicateFieldName}" in field list` : undefined;
18480
+ if (keyed && !fields)
18481
+ return {
18482
+ kind: "invalid",
18483
+ reason: "Keyed header requires a field list"
18484
+ };
18485
+ if (fields && afterColon)
18486
+ return {
18487
+ kind: "invalid",
18488
+ reason: duplicateReason ?? "Unexpected content after fields-bearing header colon"
18489
+ };
18490
+ return {
18491
+ kind: "header",
18492
+ header: {
18493
+ key,
18494
+ length,
18495
+ delimiter,
18496
+ fields,
18497
+ keyed
18498
+ },
18499
+ inlineValues: afterColon || undefined,
18500
+ strictError: duplicateReason
18501
+ };
18502
+ }
18503
+ var BRACKET_LENGTH_PATTERN = /^(?:0|[1-9]\d*)$/;
18504
+ function parseBracketSegment(seg, defaultDelimiter) {
18505
+ let content = seg;
18506
+ let delimiter = defaultDelimiter;
18507
+ if (content.endsWith("\t")) {
18508
+ delimiter = DELIMITERS.tab;
18509
+ content = content.slice(0, -1);
18510
+ } else if (content.endsWith("|")) {
18511
+ delimiter = DELIMITERS.pipe;
18512
+ content = content.slice(0, -1);
18513
+ }
18514
+ let keyed = false;
18515
+ if (content.endsWith(":")) {
18516
+ keyed = true;
18517
+ content = content.slice(0, -1);
18518
+ }
18519
+ if (!BRACKET_LENGTH_PATTERN.test(content))
18520
+ throw new SyntaxError(`Invalid array length: "${seg}" (expected non-negative integer with no leading zeros)`);
18521
+ return {
18522
+ length: Number.parseInt(content, 10),
18523
+ delimiter,
18524
+ keyed
18525
+ };
18526
+ }
18527
+ function parseFieldEntries(fieldsContent, delimiter) {
18528
+ return splitFieldEntries(fieldsContent, delimiter).map((entry) => {
18529
+ const trimmedEntry = trimSpaces(entry);
18530
+ if (!trimmedEntry)
18531
+ throw new SyntaxError("Empty field name in field list");
18532
+ const groupStart = findUnquotedChar(trimmedEntry, "{");
18533
+ if (groupStart === -1)
18534
+ return { name: parseStringLiteral(trimmedEntry) };
18535
+ const namePart = trimSpaces(trimmedEntry.slice(0, groupStart));
18536
+ if (!namePart)
18537
+ throw new SyntaxError("Missing field name before nested field group");
18538
+ const groupEnd = findMatchingBrace(trimmedEntry, groupStart);
18539
+ if (groupEnd === -1)
18540
+ throw new SyntaxError("Unmatched brace in field list");
18541
+ if (groupEnd !== trimmedEntry.length - 1)
18542
+ throw new SyntaxError("Unexpected content after nested field group");
18543
+ const children = parseFieldEntries(trimmedEntry.slice(groupStart + 1, groupEnd), delimiter);
18544
+ return {
18545
+ name: parseStringLiteral(namePart),
18546
+ children
18547
+ };
18548
+ });
18549
+ }
18550
+ function splitFieldEntries(content, delimiter) {
18551
+ const entries = [];
18552
+ let entryBuffer = "";
18553
+ let inQuotes = false;
18554
+ let braceDepth = 0;
18555
+ let i = 0;
18556
+ while (i < content.length) {
18557
+ const char = content[i];
18558
+ if (char === "\\" && i + 1 < content.length && inQuotes) {
18559
+ entryBuffer += char + content[i + 1];
18560
+ i += 2;
18561
+ continue;
18562
+ }
18563
+ if (char === '"') {
18564
+ inQuotes = !inQuotes;
18565
+ entryBuffer += char;
18566
+ i++;
18567
+ continue;
18568
+ }
18569
+ if (!inQuotes) {
18570
+ if (char === "{")
18571
+ braceDepth++;
18572
+ else if (char === "}")
18573
+ braceDepth--;
18574
+ else if (char === delimiter && braceDepth === 0) {
18575
+ entries.push(entryBuffer);
18576
+ entryBuffer = "";
18577
+ i++;
18578
+ continue;
18579
+ }
18580
+ }
18581
+ entryBuffer += char;
18582
+ i++;
18583
+ }
18584
+ entries.push(entryBuffer);
18585
+ return entries;
18586
+ }
18587
+ function findMatchingBrace(content, braceStart) {
18588
+ let inQuotes = false;
18589
+ let braceDepth = 0;
18590
+ let i = braceStart;
18591
+ while (i < content.length) {
18592
+ const char = content[i];
18593
+ if (char === "\\" && i + 1 < content.length && inQuotes) {
18594
+ i += 2;
18595
+ continue;
18596
+ }
18597
+ if (char === '"') {
18598
+ inQuotes = !inQuotes;
18599
+ i++;
18600
+ continue;
18601
+ }
18602
+ if (!inQuotes) {
18603
+ if (char === "{")
18604
+ braceDepth++;
18605
+ else if (char === "}") {
18606
+ braceDepth--;
18607
+ if (braceDepth === 0)
18608
+ return i;
18609
+ }
18610
+ }
18611
+ i++;
18612
+ }
18613
+ return -1;
18614
+ }
18615
+ function findDuplicateFieldName(fields) {
18616
+ const seenNames = /* @__PURE__ */ new Set;
18617
+ for (const field of fields) {
18618
+ if (seenNames.has(field.name))
18619
+ return field.name;
18620
+ seenNames.add(field.name);
18621
+ if (field.children) {
18622
+ const nestedDuplicate = findDuplicateFieldName(field.children);
18623
+ if (nestedDuplicate !== undefined)
18624
+ return nestedDuplicate;
18625
+ }
18626
+ }
18627
+ }
18628
+ function countLeafFields(fields) {
18629
+ let leafCount = 0;
18630
+ for (const field of fields)
18631
+ leafCount += field.children ? countLeafFields(field.children) : 1;
18632
+ return leafCount;
18633
+ }
18634
+ var DELIMITER_CANDIDATES = [
18635
+ ",",
18636
+ "\t",
18637
+ "|"
18638
+ ];
18639
+ function findUnquotedMismatchedDelimiter(content, activeDelimiter) {
18640
+ for (const candidate of DELIMITER_CANDIDATES) {
18641
+ if (candidate === activeDelimiter)
18642
+ continue;
18643
+ if (findUnquotedChar(content, candidate) !== -1)
18644
+ return candidate;
18645
+ }
18646
+ }
18647
+ function formatDelimiter(delimiter) {
18648
+ if (delimiter === "\t")
18649
+ return "\\t";
18650
+ return delimiter;
18651
+ }
18652
+ function parseDelimitedValues(input, delimiter) {
18653
+ const values = [];
18654
+ let valueBuffer = "";
18655
+ let inQuotes = false;
18656
+ let i = 0;
18657
+ while (i < input.length) {
18658
+ const char = input[i];
18659
+ if (char === "\\" && i + 1 < input.length && inQuotes) {
18660
+ valueBuffer += char + input[i + 1];
18661
+ i += 2;
18662
+ continue;
18663
+ }
18664
+ if (char === '"') {
18665
+ inQuotes = !inQuotes;
18666
+ valueBuffer += char;
18667
+ i++;
18668
+ continue;
18669
+ }
18670
+ if (char === delimiter && !inQuotes) {
18671
+ values.push(trimSpaces(valueBuffer));
18672
+ valueBuffer = "";
18673
+ i++;
18674
+ continue;
18675
+ }
18676
+ valueBuffer += char;
18677
+ i++;
18678
+ }
18679
+ if (valueBuffer || values.length > 0)
18680
+ values.push(trimSpaces(valueBuffer));
18681
+ return values;
18682
+ }
18683
+ function mapRowValuesToPrimitives(values) {
18684
+ return values.map((v) => parsePrimitiveToken(v));
18685
+ }
18686
+ function parsePrimitiveToken(token) {
18687
+ const trimmedToken = trimSpaces(token);
18688
+ if (!trimmedToken)
18689
+ return "";
18690
+ if (trimmedToken.startsWith('"'))
18691
+ return parseStringLiteral(trimmedToken);
18692
+ if (isBooleanOrNullLiteral(trimmedToken)) {
18693
+ if (trimmedToken === "true")
18694
+ return true;
18695
+ if (trimmedToken === "false")
18696
+ return false;
18697
+ if (trimmedToken === "null")
18698
+ return null;
18699
+ }
18700
+ if (isNumericLiteral(trimmedToken)) {
18701
+ const parsedNumber = Number.parseFloat(trimmedToken);
18702
+ return Object.is(parsedNumber, -0) ? 0 : parsedNumber;
18703
+ }
18704
+ return trimmedToken;
18705
+ }
18706
+ function parseStringLiteral(token) {
18707
+ const trimmedToken = trimSpaces(token);
18708
+ if (trimmedToken.startsWith('"')) {
18709
+ const closingQuoteIndex = findClosingQuote(trimmedToken, 0);
18710
+ if (closingQuoteIndex === -1)
18711
+ throw new SyntaxError("Unterminated string: missing closing quote");
18712
+ if (closingQuoteIndex !== trimmedToken.length - 1)
18713
+ throw new SyntaxError("Unexpected characters after closing quote");
18714
+ return unescapeString(trimmedToken.slice(1, closingQuoteIndex));
18715
+ }
18716
+ return trimmedToken;
18717
+ }
18718
+ function parseUnquotedKey(content, start) {
18719
+ const colonIndex = findUnquotedChar(content, ":", start);
18720
+ if (colonIndex === -1)
18721
+ throw new SyntaxError("Missing colon after key");
18722
+ return {
18723
+ key: trimSpaces(content.slice(start, colonIndex)),
18724
+ end: colonIndex + 1
18725
+ };
18726
+ }
18727
+ function parseQuotedKey(content, start) {
18728
+ const closingQuoteIndex = findClosingQuote(content, start);
18729
+ if (closingQuoteIndex === -1)
18730
+ throw new SyntaxError("Unterminated quoted key");
18731
+ const key = unescapeString(content.slice(start + 1, closingQuoteIndex));
18732
+ let parsePosition = closingQuoteIndex + 1;
18733
+ if (parsePosition >= content.length || content[parsePosition] !== ":")
18734
+ throw new SyntaxError("Missing colon after key");
18735
+ parsePosition++;
18736
+ return {
18737
+ key,
18738
+ end: parsePosition
18739
+ };
18740
+ }
18741
+ function parseKeyToken(content, start) {
18742
+ return content[start] === '"' ? parseQuotedKey(content, start) : parseUnquotedKey(content, start);
18743
+ }
18744
+ function isArrayHeaderContent(content) {
18745
+ return content.trim().startsWith("[") && findUnquotedChar(content, ":") !== -1;
18746
+ }
18747
+ function isKeyValueContent(content) {
18748
+ return findUnquotedChar(content, ":") !== -1;
18749
+ }
18750
+ function assertExpectedCount(actual, expected, itemType, options, line) {
18751
+ if (options.strict && actual !== expected)
18752
+ throw new ToonDecodeError(`Expected ${expected} ${itemType}, but got ${actual}`, {
18753
+ line: line.lineNumber,
18754
+ source: line.raw
18755
+ });
18756
+ }
18757
+ function validateNoExtraListItems(nextLine, itemDepth, expectedCount) {
18758
+ if (nextLine?.depth === itemDepth && nextLine.content.startsWith("- "))
18759
+ throw new ToonDecodeError(`Expected ${expectedCount} list-form items, but found more`, {
18760
+ line: nextLine.lineNumber,
18761
+ source: nextLine.raw
18762
+ });
18763
+ }
18764
+ function validateNoExtraTabularRows(nextLine, rowDepth, header) {
18765
+ if (nextLine?.depth === rowDepth && !nextLine.content.startsWith("- ") && isDataRow(nextLine.content, header.delimiter))
18766
+ throw new ToonDecodeError(`Expected ${header.length} tabular rows, but found more`, {
18767
+ line: nextLine.lineNumber,
18768
+ source: nextLine.raw
18769
+ });
18770
+ }
18771
+ function validateNoBlankLinesInRange(startLine, endLine, blankLines, strict, context) {
18772
+ if (!strict)
18773
+ return;
18774
+ const firstBlank = blankLines.find((blank) => blank.lineNumber > startLine && blank.lineNumber < endLine);
18775
+ if (firstBlank)
18776
+ throw new ToonDecodeError(`Blank lines inside ${context} are not allowed in strict mode`, { line: firstBlank.lineNumber });
18777
+ }
18778
+ function isDataRow(content, delimiter) {
18779
+ const colonPos = findUnquotedChar(content, ":");
18780
+ const delimiterPos = findUnquotedChar(content, delimiter);
18781
+ if (colonPos === -1)
18782
+ return true;
18783
+ if (delimiterPos !== -1 && delimiterPos < colonPos)
18784
+ return true;
18785
+ return false;
18786
+ }
18787
+ function resolveContext(options) {
18788
+ return {
18789
+ indentSize: options?.indentSize ?? options?.indent ?? 2,
18790
+ strict: options?.strict ?? true
18791
+ };
18792
+ }
18793
+ function decodeStreamSync$1(source, options) {
18794
+ const resolvedOptions = resolveContext(options);
18795
+ return driveSync(source, decodeDocument(createLineReader(resolvedOptions), resolvedOptions));
18796
+ }
18797
+ function* decodeDocument(reader, options) {
18798
+ const first = yield* peekLine(reader);
18799
+ if (!first) {
18800
+ yield { type: "startObject" };
18801
+ yield { type: "endObject" };
18802
+ return;
18803
+ }
18804
+ if (trimSpaces(first.content) === "[]") {
18805
+ yield* readLine(reader);
18806
+ yield {
18807
+ type: "startArray",
18808
+ length: 0
18809
+ };
18810
+ yield { type: "endArray" };
18811
+ yield* assertFullyConsumed(reader, options.strict);
18812
+ return;
18813
+ }
18814
+ if (isArrayHeaderContent(first.content)) {
18815
+ const headerInfo = withLine(first, () => resolveArrayHeader(parseArrayHeaderLine(first.content, DEFAULT_DELIMITER), options.strict));
18816
+ if (headerInfo) {
18817
+ yield* readLine(reader);
18818
+ yield* decodeArrayFromHeader(headerInfo.header, headerInfo.inlineValues, reader, 0, options, first);
18819
+ yield* assertFullyConsumed(reader, options.strict);
18820
+ return;
18821
+ }
18822
+ }
18823
+ yield* readLine(reader);
18824
+ const following = yield* peekLine(reader);
18825
+ if (!(following !== undefined) && !isKeyValueLine(first)) {
18826
+ yield {
18827
+ type: "primitive",
18828
+ value: withLine(first, () => parsePrimitiveToken(first.content))
18829
+ };
18830
+ return;
18831
+ }
18832
+ if (!isKeyValueLine(first) && following?.depth === 0)
18833
+ throw new ToonDecodeError("Top-level document must start with a key-value or array-header line", {
18834
+ line: first.lineNumber,
18835
+ source: first.raw
18836
+ });
18837
+ const rootSeenKeys = options.strict ? /* @__PURE__ */ new Set : undefined;
18838
+ yield { type: "startObject" };
18839
+ yield* decodeKeyValue(first, reader, 0, options, rootSeenKeys);
18840
+ while (true) {
18841
+ const line = yield* peekLine(reader);
18842
+ if (!line)
18843
+ break;
18844
+ if (line.depth !== 0) {
18845
+ if (options.strict)
18846
+ throw overIndentedLineError(line, 0);
18847
+ assertNotScalarLine(line);
18848
+ yield* readLine(reader);
18849
+ continue;
18850
+ }
18851
+ yield* readLine(reader);
18852
+ yield* decodeKeyValue(line, reader, 0, options, rootSeenKeys);
18853
+ }
18854
+ yield { type: "endObject" };
18855
+ }
18856
+ function assertNoDepthJump(firstNestedLine, parentDepth, strict) {
18857
+ if (strict && firstNestedLine.depth > parentDepth + 1)
18858
+ throw new ToonDecodeError(`Indentation depth jump: expected depth ${parentDepth + 1}, but found ${firstNestedLine.depth}`, {
18859
+ line: firstNestedLine.lineNumber,
18860
+ source: firstNestedLine.raw
18861
+ });
18862
+ }
18863
+ function overIndentedLineError(line, expectedDepth) {
18864
+ return new ToonDecodeError(`Over-indented line: expected depth ${expectedDepth}, but found ${line.depth}`, {
18865
+ line: line.lineNumber,
18866
+ source: line.raw
18867
+ });
18868
+ }
18869
+ function assertNotScalarLine(line) {
18870
+ if (line.content.startsWith("- ") || line.content === "-" || findUnquotedChar(line.content, ":") !== -1)
18871
+ return;
18872
+ throw new ToonDecodeError("Unexpected bare token line outside root primitive position", {
18873
+ line: line.lineNumber,
18874
+ source: line.raw
18875
+ });
18876
+ }
18877
+ function keylessKeyedError(line) {
18878
+ return new ToonDecodeError("Keyless keyed header is only valid at the document root", {
18879
+ line: line.lineNumber,
18880
+ source: line.raw
18881
+ });
18882
+ }
18883
+ function keylessHeaderError(line) {
18884
+ return new ToonDecodeError("Keyless array header is only valid at the document root or as a list item", {
18885
+ line: line.lineNumber,
18886
+ source: line.raw
18887
+ });
18888
+ }
18889
+ function keylessFieldsHeaderError(line) {
18890
+ return new ToonDecodeError("Keyless header with a field list is only valid at the document root", {
18891
+ line: line.lineNumber,
18892
+ source: line.raw
18893
+ });
18894
+ }
18895
+ function* assertFullyConsumed(reader, strict) {
18896
+ if (!strict)
18897
+ return;
18898
+ const line = yield* peekLine(reader);
18899
+ if (line)
18900
+ throw new ToonDecodeError("Unexpected content after the document root", {
18901
+ line: line.lineNumber,
18902
+ source: line.raw
18903
+ });
18904
+ }
18905
+ function assertNoDuplicateKey(key, line, seenKeys) {
18906
+ if (!seenKeys)
18907
+ return;
18908
+ if (seenKeys.has(key))
18909
+ throw new ToonDecodeError(`Duplicate sibling key "${key}"`, {
18910
+ line: line.lineNumber,
18911
+ source: line.raw
18912
+ });
18913
+ seenKeys.add(key);
18914
+ }
18915
+ function* decodeKeyValue(line, reader, baseDepth, options, seenKeys) {
18916
+ const content = line.content;
18917
+ const arrayHeader = withLine(line, () => resolveArrayHeader(parseArrayHeaderLine(content, DEFAULT_DELIMITER), options.strict));
18918
+ if (arrayHeader && arrayHeader.header.key !== undefined) {
18919
+ assertNoDuplicateKey(arrayHeader.header.key, line, seenKeys);
18920
+ yield {
18921
+ type: "key",
18922
+ key: arrayHeader.header.key
18923
+ };
18924
+ yield* decodeArrayFromHeader(arrayHeader.header, arrayHeader.inlineValues, reader, baseDepth, options, line);
18925
+ return;
18926
+ }
18927
+ if (arrayHeader && arrayHeader.header.key === undefined && options.strict)
18928
+ throw arrayHeader.header.keyed ? keylessKeyedError(line) : keylessHeaderError(line);
18929
+ const { key, end } = withLine(line, () => parseKeyToken(content, 0));
18930
+ const rest = trimSpaces(content.slice(end));
18931
+ assertNoDuplicateKey(key, line, seenKeys);
18932
+ yield {
18933
+ type: "key",
18934
+ key
18935
+ };
18936
+ if (!rest) {
18937
+ const nextLine = yield* peekLine(reader);
18938
+ if (nextLine && nextLine.depth > baseDepth) {
18939
+ assertNoDepthJump(nextLine, baseDepth, options.strict);
18940
+ yield { type: "startObject" };
18941
+ yield* decodeObjectFields(reader, baseDepth + 1, options);
18942
+ yield { type: "endObject" };
18943
+ return;
18944
+ }
18945
+ yield { type: "startObject" };
18946
+ yield { type: "endObject" };
18947
+ return;
18948
+ }
18949
+ if (rest === "[]") {
18950
+ yield {
18951
+ type: "startArray",
18952
+ length: 0
18953
+ };
18954
+ yield { type: "endArray" };
18955
+ return;
18956
+ }
18957
+ yield {
18958
+ type: "primitive",
18959
+ value: withLine(line, () => parsePrimitiveToken(rest))
18960
+ };
18961
+ }
18962
+ function* decodeObjectFields(reader, baseDepth, options) {
18963
+ let computedDepth;
18964
+ const seenKeys = options.strict ? /* @__PURE__ */ new Set : undefined;
18965
+ while (true) {
18966
+ const line = yield* peekLine(reader);
18967
+ if (!line || line.depth < baseDepth)
18968
+ break;
18969
+ if (computedDepth === undefined && line.depth >= baseDepth)
18970
+ computedDepth = line.depth;
18971
+ if (line.depth === computedDepth) {
18972
+ yield* readLine(reader);
18973
+ yield* decodeKeyValue(line, reader, computedDepth, options, seenKeys);
18974
+ } else if (computedDepth !== undefined && line.depth > computedDepth) {
18975
+ if (options.strict)
18976
+ throw overIndentedLineError(line, computedDepth);
18977
+ assertNotScalarLine(line);
18978
+ yield* readLine(reader);
18979
+ } else
18980
+ break;
18981
+ }
18982
+ }
18983
+ function* decodeArrayFromHeader(header, inlineValues, reader, baseDepth, options, headerLine) {
18984
+ if (header.keyed) {
18985
+ yield* decodeKeyedObject(header, reader, baseDepth, options, headerLine);
18986
+ return;
18987
+ }
18988
+ yield {
18989
+ type: "startArray",
18990
+ length: header.length
18991
+ };
18992
+ if (inlineValues) {
18993
+ yield* decodeInlinePrimitiveArray(header, inlineValues, options, headerLine);
18994
+ yield { type: "endArray" };
18995
+ return;
18996
+ }
18997
+ if (header.fields && header.fields.length > 0) {
18998
+ yield* decodeTabularArray(header, reader, baseDepth, options, headerLine);
18999
+ yield { type: "endArray" };
19000
+ return;
19001
+ }
19002
+ yield* decodeListArray(header, reader, baseDepth, options, headerLine);
19003
+ yield { type: "endArray" };
19004
+ }
19005
+ function* decodeInlinePrimitiveArray(header, inlineValues, options, headerLine) {
19006
+ if (!trimSpaces(inlineValues)) {
19007
+ assertExpectedCount(0, header.length, "inline-form values", options, headerLine);
19008
+ return;
19009
+ }
19010
+ const values = withLine(headerLine, () => parseDelimitedValues(inlineValues, header.delimiter));
19011
+ const primitives = withLine(headerLine, () => mapRowValuesToPrimitives(values));
19012
+ assertExpectedCount(primitives.length, header.length, "inline-form values", options, headerLine);
19013
+ for (const primitive of primitives)
19014
+ yield {
19015
+ type: "primitive",
19016
+ value: primitive
19017
+ };
19018
+ }
19019
+ function* decodeKeyedObject(header, reader, baseDepth, options, headerLine) {
19020
+ const entryDepth = baseDepth + 1;
19021
+ const leafFieldCount = countLeafFields(header.fields);
19022
+ const seenEntryKeys = options.strict ? /* @__PURE__ */ new Set : undefined;
19023
+ let entryCount = 0;
19024
+ let startLine;
19025
+ let endLine;
19026
+ let lastEntryLine = headerLine;
19027
+ yield { type: "startObject" };
19028
+ while (true) {
19029
+ const line = yield* peekLine(reader);
19030
+ if (!line || line.depth <= baseDepth)
19031
+ break;
19032
+ if (line.depth > entryDepth) {
19033
+ if (options.strict)
19034
+ throw new ToonDecodeError("Unexpected indentation inside keyed tabular object", {
19035
+ line: line.lineNumber,
19036
+ source: line.raw
19037
+ });
19038
+ yield* readLine(reader);
19039
+ continue;
19040
+ }
19041
+ if (findUnquotedChar(line.content, ":") === -1) {
19042
+ if (options.strict)
19043
+ throw new ToonDecodeError("Expected entry row inside keyed tabular object", {
19044
+ line: line.lineNumber,
19045
+ source: line.raw
19046
+ });
19047
+ yield* readLine(reader);
19048
+ continue;
19049
+ }
19050
+ yield* readLine(reader);
19051
+ if (startLine === undefined)
19052
+ startLine = line.lineNumber;
19053
+ endLine = line.lineNumber;
19054
+ lastEntryLine = line;
19055
+ const { key, end } = withLine(line, () => parseKeyToken(line.content, 0));
19056
+ assertNoDuplicateKey(key, line, seenEntryKeys);
19057
+ yield {
19058
+ type: "key",
19059
+ key
19060
+ };
19061
+ const cellsContent = trimSpaces(line.content.slice(end));
19062
+ const values = cellsContent === "" ? [] : withLine(line, () => parseDelimitedValues(cellsContent, header.delimiter));
19063
+ assertExpectedCount(values.length, leafFieldCount, "keyed entry cells", options, line);
19064
+ const primitives = withLine(line, () => mapRowValuesToPrimitives(values));
19065
+ yield* yieldObjectFromFields(header.fields, primitives);
19066
+ entryCount++;
19067
+ }
19068
+ assertExpectedCount(entryCount, header.length, "keyed entries", options, lastEntryLine);
19069
+ if (options.strict && startLine !== undefined && endLine !== undefined)
19070
+ validateNoBlankLinesInRange(startLine, endLine, reader.scanState.blankLines, options.strict, "keyed tabular object");
19071
+ yield { type: "endObject" };
19072
+ }
19073
+ function* decodeTabularArray(header, reader, baseDepth, options, headerLine) {
19074
+ const rowDepth = baseDepth + 1;
19075
+ let rowCount = 0;
19076
+ let startLine;
19077
+ let endLine;
19078
+ let lastRowLine = headerLine;
19079
+ while (!options.strict || rowCount < header.length) {
19080
+ const line = yield* peekLine(reader);
19081
+ if (!line || line.depth < rowDepth)
19082
+ break;
19083
+ if (line.depth === rowDepth) {
19084
+ if (!isDataRow(line.content, header.delimiter))
19085
+ break;
19086
+ if (startLine === undefined)
19087
+ startLine = line.lineNumber;
19088
+ endLine = line.lineNumber;
19089
+ lastRowLine = line;
19090
+ yield* readLine(reader);
19091
+ const values = withLine(line, () => parseDelimitedValues(line.content, header.delimiter));
19092
+ assertExpectedCount(values.length, countLeafFields(header.fields), "tabular row values", options, line);
19093
+ const primitives = withLine(line, () => mapRowValuesToPrimitives(values));
19094
+ yield* yieldObjectFromFields(header.fields, primitives);
19095
+ rowCount++;
19096
+ } else
19097
+ break;
19098
+ }
19099
+ assertExpectedCount(rowCount, header.length, "tabular rows", options, lastRowLine);
19100
+ if (options.strict && startLine !== undefined && endLine !== undefined)
19101
+ validateNoBlankLinesInRange(startLine, endLine, reader.scanState.blankLines, options.strict, "tabular array");
19102
+ if (options.strict)
19103
+ validateNoExtraTabularRows(yield* peekLine(reader), rowDepth, header);
19104
+ }
19105
+ function* decodeListArray(header, reader, baseDepth, options, headerLine) {
19106
+ const itemDepth = baseDepth + 1;
19107
+ let itemCount = 0;
19108
+ let startLine;
19109
+ let endLine;
19110
+ let lastItemLine = headerLine;
19111
+ while (!options.strict || itemCount < header.length) {
19112
+ const line = yield* peekLine(reader);
19113
+ if (!line || line.depth < itemDepth)
19114
+ break;
19115
+ const isListItem = line.content.startsWith("- ") || line.content === "-";
19116
+ if (line.depth === itemDepth && isListItem) {
19117
+ if (startLine === undefined)
19118
+ startLine = line.lineNumber;
19119
+ endLine = line.lineNumber;
19120
+ lastItemLine = line;
19121
+ yield* decodeListItem(reader, itemDepth, options);
19122
+ const lastConsumedLine = reader.lastLine;
19123
+ if (lastConsumedLine) {
19124
+ endLine = lastConsumedLine.lineNumber;
19125
+ lastItemLine = lastConsumedLine;
19126
+ }
19127
+ itemCount++;
19128
+ } else
19129
+ break;
19130
+ }
19131
+ assertExpectedCount(itemCount, header.length, "list-form items", options, lastItemLine);
19132
+ if (options.strict && startLine !== undefined && endLine !== undefined)
19133
+ validateNoBlankLinesInRange(startLine, endLine, reader.scanState.blankLines, options.strict, "list-form array");
19134
+ if (options.strict)
19135
+ validateNoExtraListItems(yield* peekLine(reader), itemDepth, header.length);
19136
+ }
19137
+ function* decodeListItem(reader, baseDepth, options) {
19138
+ const line = yield* readLine(reader);
19139
+ if (!line)
19140
+ throw new ReferenceError("Expected list item");
19141
+ let afterHyphen;
19142
+ if (line.content === "-") {
19143
+ yield { type: "startObject" };
19144
+ yield { type: "endObject" };
19145
+ return;
19146
+ } else if (line.content.startsWith("- "))
19147
+ afterHyphen = line.content.slice(2);
19148
+ else
19149
+ throw new ToonDecodeError(`Expected list item to start with "- "`, {
19150
+ line: line.lineNumber,
19151
+ source: line.raw
19152
+ });
19153
+ if (!trimSpaces(afterHyphen)) {
19154
+ yield { type: "startObject" };
19155
+ yield { type: "endObject" };
19156
+ return;
19157
+ }
19158
+ if (trimSpaces(afterHyphen) === "[]") {
19159
+ yield {
19160
+ type: "startArray",
19161
+ length: 0
19162
+ };
19163
+ yield { type: "endArray" };
19164
+ return;
19165
+ }
19166
+ const itemLine = {
19167
+ ...line,
19168
+ content: afterHyphen
19169
+ };
19170
+ if (isArrayHeaderContent(afterHyphen)) {
19171
+ const arrayHeader = withLine(itemLine, () => resolveArrayHeader(parseArrayHeaderLine(afterHyphen, DEFAULT_DELIMITER), options.strict));
19172
+ if (arrayHeader)
19173
+ if (arrayHeader.header.keyed || arrayHeader.header.fields !== undefined) {
19174
+ if (options.strict)
19175
+ throw arrayHeader.header.keyed ? keylessKeyedError(itemLine) : keylessFieldsHeaderError(itemLine);
19176
+ } else {
19177
+ yield* decodeArrayFromHeader(arrayHeader.header, arrayHeader.inlineValues, reader, baseDepth, options, itemLine);
19178
+ return;
19179
+ }
19180
+ }
19181
+ const headerInfo = withLine(itemLine, () => resolveArrayHeader(parseArrayHeaderLine(afterHyphen, DEFAULT_DELIMITER), options.strict));
19182
+ if (headerInfo && headerInfo.header.key !== undefined && headerInfo.header.fields !== undefined) {
19183
+ const header = headerInfo.header;
19184
+ const seenKeys = options.strict ? /* @__PURE__ */ new Set([header.key]) : undefined;
19185
+ yield { type: "startObject" };
19186
+ yield {
19187
+ type: "key",
19188
+ key: header.key
19189
+ };
19190
+ yield* decodeArrayFromHeader(header, headerInfo.inlineValues, reader, baseDepth + 1, options, itemLine);
19191
+ yield* followSiblingFields(reader, baseDepth + 1, options, seenKeys);
19192
+ yield { type: "endObject" };
19193
+ return;
19194
+ }
19195
+ if (isKeyValueContent(afterHyphen)) {
19196
+ const seenKeys = options.strict ? /* @__PURE__ */ new Set : undefined;
19197
+ yield { type: "startObject" };
19198
+ yield* decodeKeyValue(itemLine, reader, baseDepth + 1, options, seenKeys);
19199
+ yield* followSiblingFields(reader, baseDepth + 1, options, seenKeys);
19200
+ yield { type: "endObject" };
19201
+ return;
19202
+ }
19203
+ yield {
19204
+ type: "primitive",
19205
+ value: withLine(itemLine, () => parsePrimitiveToken(afterHyphen))
19206
+ };
19207
+ }
19208
+ function* followSiblingFields(reader, followDepth, options, seenKeys) {
19209
+ while (true) {
19210
+ const nextLine = yield* peekLine(reader);
19211
+ if (!nextLine || nextLine.depth < followDepth)
19212
+ break;
19213
+ if (nextLine.depth === followDepth && !nextLine.content.startsWith("- ")) {
19214
+ yield* readLine(reader);
19215
+ yield* decodeKeyValue(nextLine, reader, followDepth, options, seenKeys);
19216
+ } else
19217
+ break;
19218
+ }
19219
+ }
19220
+ function isKeyValueLine(line) {
19221
+ const content = line.content;
19222
+ if (content.startsWith('"')) {
19223
+ const closingQuoteIndex = findClosingQuote(content, 0);
19224
+ if (closingQuoteIndex === -1)
19225
+ return false;
19226
+ return content.slice(closingQuoteIndex + 1).includes(":");
19227
+ } else
19228
+ return content.includes(":");
19229
+ }
19230
+ function resolveArrayHeader(result, strict) {
19231
+ if (result.kind === "notHeader")
19232
+ return;
19233
+ if (result.kind === "invalid") {
19234
+ if (strict)
19235
+ throw new SyntaxError(result.reason);
19236
+ return;
19237
+ }
19238
+ if (strict && result.strictError !== undefined)
19239
+ throw new SyntaxError(result.strictError);
19240
+ return {
19241
+ header: result.header,
19242
+ inlineValues: result.inlineValues
19243
+ };
19244
+ }
19245
+ function* yieldObjectFromFields(fields, primitives) {
19246
+ let cellIndex = 0;
19247
+ function* walkFieldGroup(nodes) {
19248
+ yield { type: "startObject" };
19249
+ for (const node of nodes) {
19250
+ if (!node.children && cellIndex >= primitives.length)
19251
+ continue;
19252
+ yield {
19253
+ type: "key",
19254
+ key: node.name
19255
+ };
19256
+ if (node.children)
19257
+ yield* walkFieldGroup(node.children);
19258
+ else
19259
+ yield {
19260
+ type: "primitive",
19261
+ value: primitives[cellIndex++]
19262
+ };
19263
+ }
19264
+ yield { type: "endObject" };
19265
+ }
19266
+ yield* walkFieldGroup(fields);
19267
+ }
18152
19268
  function setOwnProperty(target, key, value) {
18153
19269
  if (key === "__proto__") {
18154
19270
  Object.defineProperty(target, key, {
@@ -18161,6 +19277,116 @@ function setOwnProperty(target, key, value) {
18161
19277
  }
18162
19278
  target[key] = value;
18163
19279
  }
19280
+ function buildValueFromEvents(events) {
19281
+ const state = {
19282
+ stack: [],
19283
+ root: undefined
19284
+ };
19285
+ for (const event of events)
19286
+ applyEvent(state, event);
19287
+ return finalizeState(state);
19288
+ }
19289
+ function applyEvent(state, event) {
19290
+ const { stack } = state;
19291
+ switch (event.type) {
19292
+ case "startObject": {
19293
+ const obj = {};
19294
+ if (stack.length === 0)
19295
+ stack.push({
19296
+ type: "object",
19297
+ obj
19298
+ });
19299
+ else {
19300
+ const parent = stack[stack.length - 1];
19301
+ if (parent.type === "object") {
19302
+ if (parent.currentKey === undefined)
19303
+ throw new Error("Object startObject event without preceding key");
19304
+ setOwnProperty(parent.obj, parent.currentKey, obj);
19305
+ parent.currentKey = undefined;
19306
+ } else if (parent.type === "array")
19307
+ parent.arr.push(obj);
19308
+ stack.push({
19309
+ type: "object",
19310
+ obj
19311
+ });
19312
+ }
19313
+ break;
19314
+ }
19315
+ case "endObject": {
19316
+ if (stack.length === 0)
19317
+ throw new Error("Unexpected endObject event");
19318
+ const context = stack.pop();
19319
+ if (context.type !== "object")
19320
+ throw new Error("Mismatched endObject event");
19321
+ if (stack.length === 0)
19322
+ state.root = context.obj;
19323
+ break;
19324
+ }
19325
+ case "startArray": {
19326
+ const arr = [];
19327
+ if (stack.length === 0)
19328
+ stack.push({
19329
+ type: "array",
19330
+ arr
19331
+ });
19332
+ else {
19333
+ const parent = stack[stack.length - 1];
19334
+ if (parent.type === "object") {
19335
+ if (parent.currentKey === undefined)
19336
+ throw new Error("Array startArray event without preceding key");
19337
+ setOwnProperty(parent.obj, parent.currentKey, arr);
19338
+ parent.currentKey = undefined;
19339
+ } else if (parent.type === "array")
19340
+ parent.arr.push(arr);
19341
+ stack.push({
19342
+ type: "array",
19343
+ arr
19344
+ });
19345
+ }
19346
+ break;
19347
+ }
19348
+ case "endArray": {
19349
+ if (stack.length === 0)
19350
+ throw new Error("Unexpected endArray event");
19351
+ const context = stack.pop();
19352
+ if (context.type !== "array")
19353
+ throw new Error("Mismatched endArray event");
19354
+ if (stack.length === 0)
19355
+ state.root = context.arr;
19356
+ break;
19357
+ }
19358
+ case "key": {
19359
+ if (stack.length === 0)
19360
+ throw new Error("Key event outside of object context");
19361
+ const parent = stack[stack.length - 1];
19362
+ if (parent.type !== "object")
19363
+ throw new Error("Key event outside of object context");
19364
+ parent.currentKey = event.key;
19365
+ break;
19366
+ }
19367
+ case "primitive":
19368
+ if (stack.length === 0)
19369
+ state.root = event.value;
19370
+ else {
19371
+ const parent = stack[stack.length - 1];
19372
+ if (parent.type === "object") {
19373
+ if (parent.currentKey === undefined)
19374
+ throw new Error("Primitive event without preceding key in object");
19375
+ setOwnProperty(parent.obj, parent.currentKey, event.value);
19376
+ parent.currentKey = undefined;
19377
+ } else if (parent.type === "array")
19378
+ parent.arr.push(event.value);
19379
+ }
19380
+ break;
19381
+ }
19382
+ }
19383
+ function finalizeState(state) {
19384
+ if (state.stack.length !== 0)
19385
+ throw new Error("Incomplete event stream: unclosed objects or arrays");
19386
+ if (state.root === undefined)
19387
+ throw new Error("No root value built from events");
19388
+ return state.root;
19389
+ }
18164
19390
  var COMMENT_LINE_PATTERN = new RegExp(`(?:^\uFEFF?|\\n) *#`);
18165
19391
  var RawString = class {
18166
19392
  constructor(value) {
@@ -18642,11 +19868,18 @@ function encode3(input, options) {
18642
19868
  return Array.from(encodeLines(input, options)).join(`
18643
19869
  `);
18644
19870
  }
19871
+ function decode3(input, options) {
19872
+ return decodeFromLines(input.split(`
19873
+ `), options);
19874
+ }
18645
19875
  function encodeLines(input, options) {
18646
19876
  const normalizedValue = normalizeValue(input);
18647
19877
  const resolvedOptions = resolveOptions(options);
18648
19878
  return encodeJsonValue(resolvedOptions.replacer ? applyReplacer(normalizedValue, resolvedOptions.replacer) : normalizedValue, resolvedOptions, 0);
18649
19879
  }
19880
+ function decodeFromLines(lines, options) {
19881
+ return buildValueFromEvents(decodeStreamSync$1(lines, resolveDecodeOptions(options)));
19882
+ }
18650
19883
  function resolveOptions(options) {
18651
19884
  const delimiter = options?.delimiter ?? DEFAULT_DELIMITER;
18652
19885
  assertValidDelimiter(delimiter);
@@ -18656,6 +19889,12 @@ function resolveOptions(options) {
18656
19889
  replacer: options?.replacer
18657
19890
  };
18658
19891
  }
19892
+ function resolveDecodeOptions(options) {
19893
+ return {
19894
+ indentSize: options?.indentSize ?? options?.indent ?? 2,
19895
+ strict: options?.strict ?? true
19896
+ };
19897
+ }
18659
19898
 
18660
19899
  // ../envoy-client/src/ask-answer.ts
18661
19900
  var HEAD_LENGTH = 120;
@@ -27560,7 +28799,7 @@ function decodeBase64(encoded) {
27560
28799
 
27561
28800
  // ../../node_modules/.bun/jose@6.2.9/node_modules/jose/dist/webapi/util/base64url.js
27562
28801
  var invalid = "The input to be decoded is not correctly encoded.";
27563
- function decode3(input) {
28802
+ function decode4(input) {
27564
28803
  if (Uint8Array.fromBase64) {
27565
28804
  try {
27566
28805
  return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
@@ -27754,7 +28993,7 @@ async function prepareKey(entry, key, usage) {
27754
28993
  case JWK: {
27755
28994
  const key = tagged[1];
27756
28995
  if (key.k) {
27757
- return decode3(key.k);
28996
+ return decode4(key.k);
27758
28997
  }
27759
28998
  if (!Object.isFrozen(key)) {
27760
28999
  const { key_ops } = key;