@descent-vtt/spec-harness 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +198 -0
  4. package/README.md +18 -3
  5. package/dist/branch.js +12 -0
  6. package/dist/branch.js.map +1 -1
  7. package/dist/cli.d.ts +1 -1
  8. package/dist/cli.js +76 -56
  9. package/dist/cli.js.map +1 -1
  10. package/dist/configure.d.ts +200 -20
  11. package/dist/configure.js +514 -69
  12. package/dist/configure.js.map +1 -1
  13. package/dist/hooks.d.ts +17 -1
  14. package/dist/hooks.js +17 -1
  15. package/dist/hooks.js.map +1 -1
  16. package/dist/reader.js +5 -1
  17. package/dist/reader.js.map +1 -1
  18. package/dist/round.d.ts +35 -6
  19. package/dist/round.js +137 -17
  20. package/dist/round.js.map +1 -1
  21. package/dist/rulings.js +6 -0
  22. package/dist/rulings.js.map +1 -1
  23. package/dist/setup.d.ts +1 -1
  24. package/dist/setup.js +72 -17
  25. package/dist/setup.js.map +1 -1
  26. package/dist/signers.js +5 -1
  27. package/dist/signers.js.map +1 -1
  28. package/dist/usage.d.ts +48 -8
  29. package/dist/usage.js +35 -1
  30. package/dist/usage.js.map +1 -1
  31. package/dist/vendor/spec-core/jsonrpc/mcp.js.map +1 -1
  32. package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -1
  33. package/dist/vendor/spec-core/markdown/headings.js.map +1 -1
  34. package/dist/vendor/spec-core/markdown/links.js.map +1 -1
  35. package/dist/vendor/spec-core/markdown/scan.js.map +1 -1
  36. package/dist/vendor/spec-core/pattern/automaton.js.map +1 -1
  37. package/dist/vendor/spec-core/pattern/charset.js.map +1 -1
  38. package/dist/vendor/spec-core/pattern/regex.js.map +1 -1
  39. package/dist/vendor/spec-core/text/lines.js.map +1 -1
  40. package/dist/vendor/spec-core/text/width.js.map +1 -1
  41. package/dist/workspace.d.ts +12 -3
  42. package/dist/workspace.js +20 -3
  43. package/dist/workspace.js.map +1 -1
  44. package/package.json +1 -1
package/dist/usage.js CHANGED
@@ -118,6 +118,15 @@ export function isClaudeHook(command, argument) {
118
118
  export function noDirectory(root) {
119
119
  return `--root is "${root}", which is not a directory`;
120
120
  }
121
+ /**
122
+ * A line under which the round has no brief to be checked against, since
123
+ * what names one names a brief spec-brief does not know, or one it has
124
+ * archived: the hook holds the write, exit 2, and every write after it until
125
+ * the name is mended (ADR-0004). `wrong` is what is said of the name.
126
+ */
127
+ export function heldHookLine(wrong) {
128
+ return { state: 'held', wrong };
129
+ }
121
130
  /**
122
131
  * A line the parser refused: an option no command has, an option left
123
132
  * without its value, a `--format` or an `--at` that is none. The parser's
@@ -142,6 +151,24 @@ export function readHookLine(root, cwd, isDirectory) {
142
151
  }
143
152
  return { state: 'guards', root: given };
144
153
  }
154
+ /**
155
+ * A line whose root is a directory outside any git work tree. The hook
156
+ * reads that as a session outside one, where it has nothing to guard: it
157
+ * checks no write and says nothing, exit 0 (ADR-0005), and that stays. Only
158
+ * git can tell such a root, so the caller asks it. A line that carries one
159
+ * is a guard someone set up that checks nothing, and `doctor` says it as
160
+ * off.
161
+ */
162
+ export function outsideHookLine(root) {
163
+ return {
164
+ state: 'off',
165
+ silent: true,
166
+ fault: {
167
+ wrong: `--root is "${root}", a directory outside any git work tree, which the hook reads as a session outside one, exit 0 and no word`,
168
+ mend: "give the hook's line a directory in the work tree, or leave --root out for the project Claude Code names",
169
+ },
170
+ };
171
+ }
145
172
  /**
146
173
  * What Claude Code's hook does with the words it is handed, or `null` for
147
174
  * words that are not its line: read by the parser the command line reads
@@ -149,6 +176,10 @@ export function readHookLine(root, cwd, isDirectory) {
149
176
  * line that parsed and on one that did not, as the command line knows it
150
177
  * (cli.ts). `parse` is that parser, which throws its refusal with the words
151
178
  * it could still read.
179
+ *
180
+ * A line that guards says which brief it names, where it names one: the hook
181
+ * passes over a `--brief` that is empty, as every release has, and holds
182
+ * every write under one that names no brief, which only spec-brief can tell.
152
183
  */
153
184
  export function claudeHookLine(words, parse, cwd, isDirectory) {
154
185
  let line;
@@ -159,7 +190,10 @@ export function claudeHookLine(words, parse, cwd, isDirectory) {
159
190
  const refused = error;
160
191
  return isClaudeHook(refused.words[0], refused.words[1]) ? unreadHookLine(refused.message) : null;
161
192
  }
162
- return isClaudeHook(line.command, line.positionals[0]) ? readHookLine(line.root, cwd, isDirectory) : null;
193
+ if (!isClaudeHook(line.command, line.positionals[0]))
194
+ return null;
195
+ const read = readHookLine(line.root, cwd, isDirectory);
196
+ return read.state === 'guards' && line.brief !== undefined && !isBlank(line.brief) ? { ...read, brief: line.brief } : read;
163
197
  }
164
198
  /**
165
199
  * Why the command line is refused, or `null` when the command can run:
package/dist/usage.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAmBvC,2DAA2D;AAC3D,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAQD,8EAA8E;AAC9E,yEAAyE;AACzE,MAAM,GAAG,GAAG,CAAC,KAAyB,EAAqB,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAEnG;;;;;GAKG;AACH,MAAM,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,kGAAkG,EAAE;IAClJ,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GA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GAAG,OAAO,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,uBAAuB,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChI,CAAC;IACD,4EAA4E;IAC5E,uEAAuE;IACvE,yEAAyE;IACzE,oDAAoD;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,4EAA4E,CAAC;IAC/G,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * What a command line that parsed has still to be before it runs.\n *\n * The parser says what was typed. Whether it names anything was left to each\n * command, and most never asked: an option another command reads was taken\n * and did nothing, an argument no command asked for was dropped, and an\n * option given an empty value, as `--root \"$DIR\"` is where the variable is\n * not set, was read as the option left out. Each run then answered a\n * question nobody had put, exit 0, where a tool never falls back to its\n * defaults and reports clean (spec-core ADR-0005).\n *\n * Pure: the command line as it was read, and the line that refuses it, or\n * `null`. The one thing only the disk knows, whether `--root` is a\n * directory, is asked of the caller.\n */\n\nimport { literal } from './literal.js';\n\n/** A command line as the parser read it; what `parseOptions` returns is one. */\nexport interface CommandLine {\n readonly command: string | undefined;\n readonly positionals: readonly string[];\n /** The long name of every option on it, in the order given. */\n readonly given: readonly string[];\n readonly brief: string | undefined;\n readonly base: string | undefined;\n readonly root: string | undefined;\n readonly paths: readonly string[];\n readonly reason: string | undefined;\n readonly options: readonly string[];\n readonly recommend: string | undefined;\n readonly show: string | undefined;\n readonly id: string | undefined;\n}\n\n/** Whether a value names nothing: empty, or only space. */\nexport function isBlank(value: string): boolean {\n return value.trim() === '';\n}\n\ninterface Valued {\n readonly of: (line: CommandLine) => readonly string[];\n /** What is said of a value that names nothing, and what to do instead. */\n readonly says: string;\n}\n\n// An option left out has no value to refuse, and a value that names something\n// is passed over as none is: the empty list is equivalent to its mutant.\nconst one = (value: string | undefined): readonly string[] => (value === undefined ? [] : [value]);\n\n/**\n * The options that take a value, and what an empty one fails to name.\n * `--format` and `--at` are not here: each takes one of a few words, and the\n * parser refuses any other, the empty one with them. Nor is `--note`, which\n * `rule` refuses by name itself.\n */\nconst VALUED = literal({\n brief: { of: (line) => one(line.brief), says: \"names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names\" },\n base: { of: (line) => one(line.base), says: 'names no commit; give it a branch or a commit, or leave it out for the configured base' },\n root: { of: (line) => one(line.root), says: 'names no directory; give it one, or leave it out to run in the current directory' },\n path: { of: (line) => line.paths, says: 'names no file; give it the path of a file' },\n reason: { of: (line) => one(line.reason), says: 'gives no reason; say why the round cannot be done without the file' },\n option: { of: (line) => line.options, says: 'names no choice; give it \"<label>: <cost>\", or leave it out' },\n recommend: { of: (line) => one(line.recommend), says: 'recommends nothing; say which option and why, or leave it out' },\n show: { of: (line) => one(line.show), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },\n id: { of: (line) => one(line.id), says: \"names no probe; give it a probe's id, or leave it out to run every probe\" },\n}) satisfies Record<string, Valued>;\n\nexport type ValuedOption = keyof typeof VALUED;\n\n/**\n * The line for a value that names nothing. `subject` is the input as its\n * caller knows it: `--brief` on a command line, `\"brief\"` in a tool call. The\n * value is shown as JSON, where a tab or a line break in it can be seen.\n */\nexport function emptyValue(subject: string, option: ValuedOption, value: string): string {\n return `${subject} is ${JSON.stringify(value)}, which ${VALUED[option].says}`;\n}\n\ninterface Shape {\n /** The options the command reads, by their long names. */\n readonly options: readonly string[];\n /** The most arguments it takes, with that said for the refusal of one more; `null` where it takes any number. */\n readonly limit: { readonly most: number; readonly takes: string } | null;\n /**\n * What an argument of it is, and what to do about an empty one; absent\n * where it takes none, or says so itself. `option` is the option that\n * names the same thing, where there is one: the two together are refused.\n * Only a brief is named both ways.\n */\n readonly argument?: { readonly role: string; readonly instead: string; readonly option?: 'brief' };\n /** The options whose empty value the command says in its own report. */\n readonly reports?: readonly string[];\n /**\n * The options that make the command another one, each with the only\n * options it reads beside it. The first on the list that is given decides,\n * as the command itself decides.\n */\n readonly modes?: readonly { readonly option: string; readonly beside: readonly string[] }[];\n}\n\nconst NO_ARGUMENT = literal({ limit: { most: 0, takes: 'no argument' } });\nconst ONE_BRIEF = literal({\n limit: { most: 1, takes: \"one argument at most, a brief's id\" },\n argument: { role: 'the brief', instead: \"give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names\", option: 'brief' },\n});\n\n/**\n * Every command, with what it reads of a command line. An option is listed\n * for a command only where the command's answer depends on it: `init`\n * chooses the base itself and the server is told the brief by each call, so\n * neither takes `--base` or `--brief`, and taking them would tell someone\n * the base or the brief had been set.\n */\nconst SHAPE = literal({\n context: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n guard: {\n options: ['brief', 'base', 'root', 'format', 'strict'],\n limit: null,\n argument: { role: 'a path', instead: 'give it the paths the round would write' },\n },\n hook: { options: ['brief', 'base', 'root'], limit: { most: 1, takes: 'one argument, \"claude\" or \"git\"' } },\n // `--list` and `--show` print what waits and raise nothing: neither reads\n // the parts of a request, nor a brief, since what waits is every round's.\n escalate: {\n options: ['brief', 'root', 'format', 'path', 'reason', 'option', 'recommend', 'list', 'show'],\n ...NO_ARGUMENT,\n modes: [\n { option: 'list', beside: ['root', 'format'] },\n { option: 'show', beside: ['root', 'format'] },\n ],\n },\n rule: {\n options: ['root', 'format', 'allow', 'deny', 'note'],\n limit: { most: 1, takes: \"one argument, the escalation's id\" },\n argument: { role: 'the escalation', instead: 'give it an id, as spec-harness escalate --list prints them' },\n },\n rulings: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n audit: { options: ['brief', 'base', 'root', 'format', 'strict'], ...ONE_BRIEF },\n probe: { options: ['brief', 'base', 'root', 'format', 'id', 'at'], ...ONE_BRIEF },\n premises: { options: ['brief', 'root', 'format', 'strict'], ...NO_ARGUMENT },\n init: { options: ['root', 'format', 'write', 'git-hook'], ...NO_ARGUMENT },\n mcp: { options: ['root'], ...NO_ARGUMENT },\n // A diagnosis says what is wrong with what it was given, where a command\n // that acts on it stops: a brief or a base that names nothing is a line of\n // doctor's report.\n doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },\n}) satisfies Record<string, Shape>;\n\n/** Every command there is: the command line dispatches on these names and no other. */\nexport type Command = keyof typeof SHAPE;\n\n// A map, since a command is a word a person types and an object answers to\n// more names than it was given: `constructor` has no shape.\nconst SHAPES: ReadonlyMap<string, Shape> = new Map(Object.entries(SHAPE));\n\nfunction listed(options: readonly string[]): string {\n const names = options.map((option) => `--${option}`);\n // Every command reads at least `--root`, so a list is never empty.\n if (names.length === 1) return `its only option is ${names[0] as string}`;\n return `its options are ${names.slice(0, -1).join(', ')} and ${names.at(-1)!}`;\n}\n\n/**\n * Whether a line is Claude Code's hook, by its command and the argument\n * after it. It is exempt from every refusal here, and read as each release\n * since 0.1.0 read it: the line lives in settings files and in the plugin of\n * every release, which this one cannot rewrite, and exit 2 from it holds\n * every write of a session, the write that would fix the line among them.\n * A line the parser cannot read is asked the same, and the hook says it\n * with exit 1 (cli.ts).\n */\nexport function isClaudeHook(command: string | undefined, argument: string | undefined): boolean {\n return command === 'hook' && argument === 'claude';\n}\n\n/** The words for a `--root` that is a file, or is not there, wherever it is said. */\nexport function noDirectory(root: string): string {\n return `--root is \"${root}\", which is not a directory`;\n}\n\n/** What is wrong with the line of Claude Code's hook, and what mends it. */\nexport interface LineFault {\n readonly wrong: string;\n readonly mend: string;\n}\n\n/**\n * What Claude Code's hook does with its own line, as far as the line decides\n * it: it guards, in the root the line gives it where it gives one, or the\n * guard is off, for a fault the hook says with exit 1 and holds no write for\n * (ADR-0005). The hook reads its line through the three functions below, and\n * `doctor` reads a line it finds in Claude Code's settings through the same\n * three, so what it says of a line is what the hook does with it.\n */\nexport type HookLine = { readonly state: 'guards'; readonly root: string | undefined } | GuardOff;\n\nexport interface GuardOff {\n readonly state: 'off';\n readonly fault: LineFault;\n}\n\n/**\n * A line the parser refused: an option no command has, an option left\n * without its value, a `--format` or an `--at` that is none. The parser's\n * words are kept, on one line: what node says of an option that may have\n * lost its value is three.\n */\nexport function unreadHookLine(said: string): GuardOff {\n return { state: 'off', fault: { wrong: `the hook's line cannot be read (${said.split('\\n').join(' ')})`, mend: 'mend it in Claude Code\\'s settings, where init writes \"hook claude\" and nothing after it' } };\n}\n\n/**\n * A line that parsed, by the root it gives. An empty root is the directory\n * the hook was started in: git starts there when it is handed no directory,\n * so the hook has guarded there for an empty root in every release. A root\n * that is a file, or is not there, is one git starts in neither of, which\n * read as a session outside a work tree, exit 0 and no word, and the guard\n * someone had configured was off.\n */\nexport function readHookLine(root: string | undefined, cwd: string, isDirectory: (path: string) => boolean): HookLine {\n const given = root === '' ? cwd : root;\n if (given !== undefined && !isDirectory(given)) {\n return { state: 'off', fault: { wrong: noDirectory(given), mend: \"give the hook's line a directory that exists, or leave --root out for the project Claude Code names\" } };\n }\n return { state: 'guards', root: given };\n}\n\n/**\n * What Claude Code's hook does with the words it is handed, or `null` for\n * words that are not its line: read by the parser the command line reads\n * every line with, and known by its command and the argument after it on a\n * line that parsed and on one that did not, as the command line knows it\n * (cli.ts). `parse` is that parser, which throws its refusal with the words\n * it could still read.\n */\nexport function claudeHookLine(\n words: readonly string[],\n parse: (argv: readonly string[]) => CommandLine,\n cwd: string,\n isDirectory: (path: string) => boolean,\n): HookLine | null {\n let line: CommandLine;\n try {\n line = parse(words);\n } catch (error) {\n const refused = error as { readonly message: string; readonly words: readonly string[] };\n return isClaudeHook(refused.words[0], refused.words[1]) ? unreadHookLine(refused.message) : null;\n }\n return isClaudeHook(line.command, line.positionals[0]) ? readHookLine(line.root, cwd, isDirectory) : null;\n}\n\n/**\n * Why the command line is refused, or `null` when the command can run:\n * an option it does not read, alone or beside another, an argument it does\n * not take, a brief named twice, a value or an argument that names nothing,\n * a `--root` that is no directory. Asked once a command is known and neither\n * `--help` nor `--version` answers instead; a command with no shape is none,\n * which its caller says.\n */\nexport function refusal(line: CommandLine, isDirectory: (path: string) => boolean): string | null {\n const { command, positionals } = line;\n // No shape is kept under `undefined`, so the first check is the compiler's,\n // and its mutant is equivalent.\n if (command === undefined) return null;\n const shape = SHAPES.get(command);\n if (shape === undefined || isClaudeHook(command, positionals[0])) return null;\n const stray = line.given.find((option) => !shape.options.includes(option));\n if (stray !== undefined) return `${command} does not take --${stray}; ${listed(shape.options)}`;\n // An option the command reads, beside one that leaves it unread:\n // `escalate --list --path src/a.ts` printed the list, exit 0, and the\n // request it also spelled out was never raised.\n const mode = shape.modes?.find((candidate) => line.given.includes(candidate.option));\n if (mode !== undefined) {\n const unread = line.given.find((option) => option !== mode.option && !mode.beside.includes(option));\n if (unread !== undefined) return `${command} --${mode.option} does not take --${unread}; beside --${mode.option} ${listed(mode.beside)}`;\n }\n if (shape.limit !== null && positionals.length > shape.limit.most) {\n return `${command} takes ${shape.limit.takes}, not ${positionals.map((argument) => JSON.stringify(argument)).join(', ')}`;\n }\n // One thing named two ways, whatever the two hold: the argument won with\n // no word, so `audit 012 --brief 013` audited 012 for someone who had\n // also typed 013.\n const { argument } = shape;\n if (argument?.option !== undefined && positionals.length > 0 && line.given.includes(argument.option)) {\n return `${command} was given ${argument.role} twice, as its argument ${JSON.stringify(positionals[0])} and as --${argument.option} ${JSON.stringify(line[argument.option])}; give one of them`;\n }\n for (const [option, valued] of Object.entries(VALUED) as [ValuedOption, Valued][]) {\n if (shape.reports?.includes(option)) continue;\n const empty = valued.of(line).find(isBlank);\n if (empty !== undefined) return emptyValue(`--${option}`, option, empty);\n }\n const empty = positionals.find(isBlank);\n if (shape.argument !== undefined && empty !== undefined) {\n return `${command} was given ${JSON.stringify(empty)} as ${shape.argument.role}, which names none; ${shape.argument.instead}`;\n }\n // An empty one was refused above, so this is a path that was meant: a file,\n // or a directory that is not there. git starts in neither, and the run\n // ended saying the path was outside a work tree, which named neither the\n // option nor what was wrong with what it was given.\n if (line.root !== undefined && !isDirectory(line.root)) {\n return `${noDirectory(line.root)}; give it one that exists, or leave it out to run in the current directory`;\n }\n return null;\n}\n"]}
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAmBvC,2DAA2D;AAC3D,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAQD,8EAA8E;AAC9E,yEAAyE;AACzE,MAAM,GAAG,GAAG,CAAC,KAAyB,EAAqB,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAEnG;;;;;GAKG;AACH,MAAM,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,kGAAkG,EAAE;IAClJ,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,wFAAwF,EAAE;IACtI,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,kFAAkF,EAAE;IAChI,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,2CAA2C,EAAE;IACrF,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CA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,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxD,OAAO,GAAG,OAAO,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,uBAAuB,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChI,CAAC;IACD,4EAA4E;IAC5E,uEAAuE;IACvE,yEAAyE;IACzE,oDAAoD;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,4EAA4E,CAAC;IAC/G,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * What a command line that parsed has still to be before it runs.\n *\n * The parser says what was typed. Whether it names anything was left to each\n * command, and most never asked: an option another command reads was taken\n * and did nothing, an argument no command asked for was dropped, and an\n * option given an empty value, as `--root \"$DIR\"` is where the variable is\n * not set, was read as the option left out. Each run then answered a\n * question nobody had put, exit 0, where a tool never falls back to its\n * defaults and reports clean (spec-core ADR-0005).\n *\n * Pure: the command line as it was read, and the line that refuses it, or\n * `null`. The one thing only the disk knows, whether `--root` is a\n * directory, is asked of the caller.\n */\n\nimport { literal } from './literal.js';\n\n/** A command line as the parser read it; what `parseOptions` returns is one. */\nexport interface CommandLine {\n readonly command: string | undefined;\n readonly positionals: readonly string[];\n /** The long name of every option on it, in the order given. */\n readonly given: readonly string[];\n readonly brief: string | undefined;\n readonly base: string | undefined;\n readonly root: string | undefined;\n readonly paths: readonly string[];\n readonly reason: string | undefined;\n readonly options: readonly string[];\n readonly recommend: string | undefined;\n readonly show: string | undefined;\n readonly id: string | undefined;\n}\n\n/** Whether a value names nothing: empty, or only space. */\nexport function isBlank(value: string): boolean {\n return value.trim() === '';\n}\n\ninterface Valued {\n readonly of: (line: CommandLine) => readonly string[];\n /** What is said of a value that names nothing, and what to do instead. */\n readonly says: string;\n}\n\n// An option left out has no value to refuse, and a value that names something\n// is passed over as none is: the empty list is equivalent to its mutant.\nconst one = (value: string | undefined): readonly string[] => (value === undefined ? [] : [value]);\n\n/**\n * The options that take a value, and what an empty one fails to name.\n * `--format` and `--at` are not here: each takes one of a few words, and the\n * parser refuses any other, the empty one with them. Nor is `--note`, which\n * `rule` refuses by name itself.\n */\nconst VALUED = literal({\n brief: { of: (line) => one(line.brief), says: \"names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names\" },\n base: { of: (line) => one(line.base), says: 'names no commit; give it a branch or a commit, or leave it out for the configured base' },\n root: { of: (line) => one(line.root), says: 'names no directory; give it one, or leave it out to run in the current directory' },\n path: { of: (line) => line.paths, says: 'names no file; give it the path of a file' },\n reason: { of: (line) => one(line.reason), says: 'gives no reason; say why the round cannot be done without the file' },\n option: { of: (line) => line.options, says: 'names no choice; give it \"<label>: <cost>\", or leave it out' },\n recommend: { of: (line) => one(line.recommend), says: 'recommends nothing; say which option and why, or leave it out' },\n show: { of: (line) => one(line.show), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },\n id: { of: (line) => one(line.id), says: \"names no probe; give it a probe's id, or leave it out to run every probe\" },\n}) satisfies Record<string, Valued>;\n\nexport type ValuedOption = keyof typeof VALUED;\n\n/**\n * The line for a value that names nothing. `subject` is the input as its\n * caller knows it: `--brief` on a command line, `\"brief\"` in a tool call. The\n * value is shown as JSON, where a tab or a line break in it can be seen.\n */\nexport function emptyValue(subject: string, option: ValuedOption, value: string): string {\n return `${subject} is ${JSON.stringify(value)}, which ${VALUED[option].says}`;\n}\n\ninterface Shape {\n /** The options the command reads, by their long names. */\n readonly options: readonly string[];\n /** The most arguments it takes, with that said for the refusal of one more; `null` where it takes any number. */\n readonly limit: { readonly most: number; readonly takes: string } | null;\n /**\n * What an argument of it is, and what to do about an empty one; absent\n * where it takes none, or says so itself. `option` is the option that\n * names the same thing, where there is one: the two together are refused.\n * Only a brief is named both ways.\n */\n readonly argument?: { readonly role: string; readonly instead: string; readonly option?: 'brief' };\n /** The options whose empty value the command says in its own report. */\n readonly reports?: readonly string[];\n /**\n * The options that make the command another one, each with the only\n * options it reads beside it. The first on the list that is given decides,\n * as the command itself decides.\n */\n readonly modes?: readonly { readonly option: string; readonly beside: readonly string[] }[];\n}\n\nconst NO_ARGUMENT = literal({ limit: { most: 0, takes: 'no argument' } });\nconst ONE_BRIEF = literal({\n limit: { most: 1, takes: \"one argument at most, a brief's id\" },\n argument: { role: 'the brief', instead: \"give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names\", option: 'brief' },\n});\n\n/**\n * Every command, with what it reads of a command line. An option is listed\n * for a command only where the command's answer depends on it: `init`\n * chooses the base itself and the server is told the brief by each call, so\n * neither takes `--base` or `--brief`, and taking them would tell someone\n * the base or the brief had been set.\n */\nconst SHAPE = literal({\n context: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n guard: {\n options: ['brief', 'base', 'root', 'format', 'strict'],\n limit: null,\n argument: { role: 'a path', instead: 'give it the paths the round would write' },\n },\n hook: { options: ['brief', 'base', 'root'], limit: { most: 1, takes: 'one argument, \"claude\" or \"git\"' } },\n // `--list` and `--show` print what waits and raise nothing: neither reads\n // the parts of a request, nor a brief, since what waits is every round's.\n escalate: {\n options: ['brief', 'root', 'format', 'path', 'reason', 'option', 'recommend', 'list', 'show'],\n ...NO_ARGUMENT,\n modes: [\n { option: 'list', beside: ['root', 'format'] },\n { option: 'show', beside: ['root', 'format'] },\n ],\n },\n rule: {\n options: ['root', 'format', 'allow', 'deny', 'note'],\n limit: { most: 1, takes: \"one argument, the escalation's id\" },\n argument: { role: 'the escalation', instead: 'give it an id, as spec-harness escalate --list prints them' },\n },\n rulings: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n audit: { options: ['brief', 'base', 'root', 'format', 'strict'], ...ONE_BRIEF },\n probe: { options: ['brief', 'base', 'root', 'format', 'id', 'at'], ...ONE_BRIEF },\n premises: { options: ['brief', 'root', 'format', 'strict'], ...NO_ARGUMENT },\n init: { options: ['root', 'format', 'write', 'git-hook'], ...NO_ARGUMENT },\n mcp: { options: ['root'], ...NO_ARGUMENT },\n // A diagnosis says what is wrong with what it was given, where a command\n // that acts on it stops: a brief or a base that names nothing is a line of\n // doctor's report.\n doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },\n}) satisfies Record<string, Shape>;\n\n/** Every command there is: the command line dispatches on these names and no other. */\nexport type Command = keyof typeof SHAPE;\n\n// A map, since a command is a word a person types and an object answers to\n// more names than it was given: `constructor` has no shape.\nconst SHAPES: ReadonlyMap<string, Shape> = new Map(Object.entries(SHAPE));\n\nfunction listed(options: readonly string[]): string {\n const names = options.map((option) => `--${option}`);\n // Every command reads at least `--root`, so a list is never empty.\n if (names.length === 1) return `its only option is ${names[0] as string}`;\n return `its options are ${names.slice(0, -1).join(', ')} and ${names.at(-1)!}`;\n}\n\n/**\n * Whether a line is Claude Code's hook, by its command and the argument\n * after it. It is exempt from every refusal here, and read as each release\n * since 0.1.0 read it: the line lives in settings files and in the plugin of\n * every release, which this one cannot rewrite, and exit 2 from it holds\n * every write of a session, the write that would fix the line among them.\n * A line the parser cannot read is asked the same, and the hook says it\n * with exit 1 (cli.ts).\n */\nexport function isClaudeHook(command: string | undefined, argument: string | undefined): boolean {\n return command === 'hook' && argument === 'claude';\n}\n\n/** The words for a `--root` that is a file, or is not there, wherever it is said. */\nexport function noDirectory(root: string): string {\n return `--root is \"${root}\", which is not a directory`;\n}\n\n/** What is wrong with the line of Claude Code's hook, and what mends it. */\nexport interface LineFault {\n readonly wrong: string;\n readonly mend: string;\n}\n\n/**\n * What Claude Code's hook does with its own line, as far as the line decides\n * it: it guards, in the root the line gives it where it gives one and under\n * the brief it names where it names one; or the guard is off, for a fault\n * the hook says with exit 1 and holds no write for; or every write is held,\n * exit 2, for a brief the line names that is not one (ADR-0005). The hook\n * reads its line through the functions below, and `doctor` reads a line it\n * finds in Claude Code's settings through the same ones, so what it says of\n * a line is what the hook does with it.\n */\nexport type HookLine = Guards | GuardOff | WritesHeld;\n\nexport interface Guards {\n readonly state: 'guards';\n readonly root: string | undefined;\n /**\n * The brief the line names with `--brief`, as written. Whether it is a\n * brief is spec-brief's to say, which the caller asks. Absent where the\n * line names none.\n */\n readonly brief?: string;\n}\n\nexport interface GuardOff {\n readonly state: 'off';\n readonly fault: LineFault;\n /**\n * Set where the hook says nothing of the fault and exits 0, so that no\n * run of it fails: a root outside any work tree. Every other fault it\n * says, with exit 1.\n */\n readonly silent?: true;\n}\n\nexport interface WritesHeld {\n readonly state: 'held';\n /** What is said of the name, by what named the brief (workspace.ts). */\n readonly wrong: string;\n}\n\n/**\n * A line under which the round has no brief to be checked against, since\n * what names one names a brief spec-brief does not know, or one it has\n * archived: the hook holds the write, exit 2, and every write after it until\n * the name is mended (ADR-0004). `wrong` is what is said of the name.\n */\nexport function heldHookLine(wrong: string): WritesHeld {\n return { state: 'held', wrong };\n}\n\n/**\n * A line the parser refused: an option no command has, an option left\n * without its value, a `--format` or an `--at` that is none. The parser's\n * words are kept, on one line: what node says of an option that may have\n * lost its value is three.\n */\nexport function unreadHookLine(said: string): GuardOff {\n return { state: 'off', fault: { wrong: `the hook's line cannot be read (${said.split('\\n').join(' ')})`, mend: 'mend it in Claude Code\\'s settings, where init writes \"hook claude\" and nothing after it' } };\n}\n\n/**\n * A line that parsed, by the root it gives. An empty root is the directory\n * the hook was started in: git starts there when it is handed no directory,\n * so the hook has guarded there for an empty root in every release. A root\n * that is a file, or is not there, is one git starts in neither of, which\n * read as a session outside a work tree, exit 0 and no word, and the guard\n * someone had configured was off.\n */\nexport function readHookLine(root: string | undefined, cwd: string, isDirectory: (path: string) => boolean): Guards | GuardOff {\n const given = root === '' ? cwd : root;\n if (given !== undefined && !isDirectory(given)) {\n return { state: 'off', fault: { wrong: noDirectory(given), mend: \"give the hook's line a directory that exists, or leave --root out for the project Claude Code names\" } };\n }\n return { state: 'guards', root: given };\n}\n\n/**\n * A line whose root is a directory outside any git work tree. The hook\n * reads that as a session outside one, where it has nothing to guard: it\n * checks no write and says nothing, exit 0 (ADR-0005), and that stays. Only\n * git can tell such a root, so the caller asks it. A line that carries one\n * is a guard someone set up that checks nothing, and `doctor` says it as\n * off.\n */\nexport function outsideHookLine(root: string): GuardOff {\n return {\n state: 'off',\n silent: true,\n fault: {\n wrong: `--root is \"${root}\", a directory outside any git work tree, which the hook reads as a session outside one, exit 0 and no word`,\n mend: \"give the hook's line a directory in the work tree, or leave --root out for the project Claude Code names\",\n },\n };\n}\n\n/**\n * What Claude Code's hook does with the words it is handed, or `null` for\n * words that are not its line: read by the parser the command line reads\n * every line with, and known by its command and the argument after it on a\n * line that parsed and on one that did not, as the command line knows it\n * (cli.ts). `parse` is that parser, which throws its refusal with the words\n * it could still read.\n *\n * A line that guards says which brief it names, where it names one: the hook\n * passes over a `--brief` that is empty, as every release has, and holds\n * every write under one that names no brief, which only spec-brief can tell.\n */\nexport function claudeHookLine(\n words: readonly string[],\n parse: (argv: readonly string[]) => CommandLine,\n cwd: string,\n isDirectory: (path: string) => boolean,\n): HookLine | null {\n let line: CommandLine;\n try {\n line = parse(words);\n } catch (error) {\n const refused = error as { readonly message: string; readonly words: readonly string[] };\n return isClaudeHook(refused.words[0], refused.words[1]) ? unreadHookLine(refused.message) : null;\n }\n if (!isClaudeHook(line.command, line.positionals[0])) return null;\n const read = readHookLine(line.root, cwd, isDirectory);\n return read.state === 'guards' && line.brief !== undefined && !isBlank(line.brief) ? { ...read, brief: line.brief } : read;\n}\n\n/**\n * Why the command line is refused, or `null` when the command can run:\n * an option it does not read, alone or beside another, an argument it does\n * not take, a brief named twice, a value or an argument that names nothing,\n * a `--root` that is no directory. Asked once a command is known and neither\n * `--help` nor `--version` answers instead; a command with no shape is none,\n * which its caller says.\n */\nexport function refusal(line: CommandLine, isDirectory: (path: string) => boolean): string | null {\n const { command, positionals } = line;\n // No shape is kept under `undefined`, so the first check is the compiler's,\n // and its mutant is equivalent.\n if (command === undefined) return null;\n const shape = SHAPES.get(command);\n if (shape === undefined || isClaudeHook(command, positionals[0])) return null;\n const stray = line.given.find((option) => !shape.options.includes(option));\n if (stray !== undefined) return `${command} does not take --${stray}; ${listed(shape.options)}`;\n // An option the command reads, beside one that leaves it unread:\n // `escalate --list --path src/a.ts` printed the list, exit 0, and the\n // request it also spelled out was never raised.\n const mode = shape.modes?.find((candidate) => line.given.includes(candidate.option));\n if (mode !== undefined) {\n const unread = line.given.find((option) => option !== mode.option && !mode.beside.includes(option));\n if (unread !== undefined) return `${command} --${mode.option} does not take --${unread}; beside --${mode.option} ${listed(mode.beside)}`;\n }\n if (shape.limit !== null && positionals.length > shape.limit.most) {\n return `${command} takes ${shape.limit.takes}, not ${positionals.map((argument) => JSON.stringify(argument)).join(', ')}`;\n }\n // One thing named two ways, whatever the two hold: the argument won with\n // no word, so `audit 012 --brief 013` audited 012 for someone who had\n // also typed 013.\n const { argument } = shape;\n if (argument?.option !== undefined && positionals.length > 0 && line.given.includes(argument.option)) {\n return `${command} was given ${argument.role} twice, as its argument ${JSON.stringify(positionals[0])} and as --${argument.option} ${JSON.stringify(line[argument.option])}; give one of them`;\n }\n for (const [option, valued] of Object.entries(VALUED) as [ValuedOption, Valued][]) {\n if (shape.reports?.includes(option)) continue;\n const empty = valued.of(line).find(isBlank);\n if (empty !== undefined) return emptyValue(`--${option}`, option, empty);\n }\n const empty = positionals.find(isBlank);\n if (shape.argument !== undefined && empty !== undefined) {\n return `${command} was given ${JSON.stringify(empty)} as ${shape.argument.role}, which names none; ${shape.argument.instead}`;\n }\n // An empty one was refused above, so this is a path that was meant: a file,\n // or a directory that is not there. git starts in neither, and the run\n // ended saying the path was outside a work tree, which named neither the\n // option nor what was wrong with what it was given.\n if (line.root !== undefined && !isDirectory(line.root)) {\n return `${noDirectory(line.root)}; give it one that exists, or leave it out to run in the current directory`;\n }\n return null;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/jsonrpc/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,wBAAwB,GAAsB,CAAC,YAAY,CAAC,CAAC;AAE1E,+EAA+E;AAC/E,MAAM,CAAC,MAAM,wBAAwB,GAAsB,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;AAElI,MAAM,CAAC,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,4CAA4C,CAAC;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,oCAAoC,CAAC;AACpE,MAAM,CAAC,MAAM,eAAe,GAAG,oCAAoC,CAAC;AAEpE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAK,CAAC;AACvC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AACrC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AACrC,kFAAkF;AAClF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,KAAK,CAAC;AAChD,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,KAAK,CAAC;AAiBnD,qEAAqE;AACrE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAS;IACb,IAAI,CAAU;IACvB,YAAY,IAAY,EAAE,OAAe,EAAE,IAAc;QACvD,KAAK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,GAAG,CAAC,CAAC;gBACrB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,QAAQ,KAAK,IAAI;oBAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACjF,MAAM,EAAE,CAAC;YACX,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAiB,EAAE,EAAE;YACrC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,KAAK,IAAI,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxF,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBACtC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;gBACnC,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;YACrB,KAAK,GAAG,IAAI,CAAC;YACb,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACnC,MAAM,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * The Model Context Protocol over JSON-RPC 2.0, without an SDK.\n *\n * MCP over stdio is JSON-RPC 2.0, one message per line, and what a server must\n * get right fits here: framing, the two eras of the protocol, and the methods\n * that serve tools, resources and prompts. The official SDK brings a schema\n * library and a dependency tree to do the same; every spec-* tool promises no\n * runtime dependencies. Moved here from spec-guard (its ADR-0012), where it\n * was first written and measured, so that a second server does not relearn it.\n *\n * Two eras, served side by side. Revisions up to 2025-11-25 open with an\n * `initialize` handshake; 2026-07-28 has none, and every request carries its\n * protocol version in `_meta`. Clients of both are in use - the newest\n * revision is not yet the one most clients speak - so each request is\n * classified on its own, by the rule the TypeScript SDK's server applies: a\n * request that claims a version in `_meta` is modern and its claim is\n * validated; anything else, `initialize` included, is legacy.\n *\n * Nothing here touches a stream or a file. A server is a function from one\n * parsed message to the message owed back; `serveLines` binds one to any\n * source of bytes with `on('data')`, which on Node is `process.stdin`.\n */\n\n/** Revisions that carry their version on every request. Newest first. */\nexport const MODERN_PROTOCOL_VERSIONS: readonly string[] = ['2026-07-28'];\n\n/** Revisions negotiated by `initialize`, newest first - the SDK's own list. */\nexport const LEGACY_PROTOCOL_VERSIONS: readonly string[] = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05', '2024-10-07'];\n\nexport const PROTOCOL_VERSION_KEY = 'io.modelcontextprotocol/protocolVersion';\nexport const CLIENT_CAPABILITIES_KEY = 'io.modelcontextprotocol/clientCapabilities';\nexport const CLIENT_INFO_KEY = 'io.modelcontextprotocol/clientInfo';\nexport const SERVER_INFO_KEY = 'io.modelcontextprotocol/serverInfo';\n\nexport const PARSE_ERROR = -32700;\nexport const INVALID_REQUEST = -32600;\nexport const METHOD_NOT_FOUND = -32601;\nexport const INVALID_PARAMS = -32602;\nexport const INTERNAL_ERROR = -32603;\n/** Resource not found before 2026-07-28, which forbids it in favour of -32602. */\nexport const LEGACY_RESOURCE_NOT_FOUND = -32002;\nexport const UNSUPPORTED_PROTOCOL_VERSION = -32022;\n\nexport type RequestId = string | number;\nexport type Era = 'legacy' | 'modern';\nexport type JsonObject = Record<string, unknown>;\n\nexport interface ErrorObject {\n readonly code: number;\n readonly message: string;\n readonly data?: unknown;\n}\n\n/** Everything a server here writes. It never sends a request. */\nexport type OutgoingMessage =\n | { readonly jsonrpc: '2.0'; readonly id: RequestId; readonly result: JsonObject }\n | { readonly jsonrpc: '2.0'; readonly id?: RequestId; readonly error: ErrorObject };\n\n/** An error that becomes a JSON-RPC error response with its code. */\nexport class ProtocolError extends Error {\n readonly code: number;\n readonly data: unknown;\n constructor(code: number, message: string, data?: unknown) {\n super(message);\n this.name = 'ProtocolError';\n this.code = code;\n this.data = data;\n }\n}\n\nexport function isObject(value: unknown): value is JsonObject {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** JSON-RPC allows a null id; MCP does not, and wants an integer if a number. */\nexport function isRequestId(value: unknown): value is RequestId {\n return typeof value === 'string' || Number.isInteger(value);\n}\n\n/**\n * What is wrong with a request's `_meta` once it claims a protocol version,\n * or `undefined`. A claim is never ignored: a malformed one is an error, not\n * a reason to fall back to the legacy handling.\n */\nexport function envelopeIssue(meta: JsonObject): string | undefined {\n if (!(CLIENT_CAPABILITIES_KEY in meta)) return `${CLIENT_CAPABILITIES_KEY}: missing`;\n if (typeof meta[PROTOCOL_VERSION_KEY] !== 'string') return `${PROTOCOL_VERSION_KEY}: expected a string`;\n if (!isObject(meta[CLIENT_CAPABILITIES_KEY])) return `${CLIENT_CAPABILITIES_KEY}: expected an object`;\n const info = meta[CLIENT_INFO_KEY];\n if (info !== undefined && !(isObject(info) && typeof info['name'] === 'string' && typeof info['version'] === 'string')) {\n return `${CLIENT_INFO_KEY}: expected an object with a string name and version`;\n }\n return undefined;\n}\n\n/**\n * The era a request belongs to, or the error that answers it instead.\n *\n * `initialize` is the legacy handshake unless it carries a valid modern claim.\n * Any other request is modern exactly when `_meta` holds the version key - its\n * presence is the claim, whatever its value - and legacy otherwise.\n */\nexport function classifyRequest(method: string, params: JsonObject | undefined): Era {\n const meta = params?.['_meta'];\n const claimed = isObject(meta) && PROTOCOL_VERSION_KEY in meta;\n if (!claimed) return 'legacy';\n const issue = envelopeIssue(meta);\n const version = meta[PROTOCOL_VERSION_KEY] as string;\n const supported = issue === undefined && MODERN_PROTOCOL_VERSIONS.includes(version);\n if (method === 'initialize' && !supported) return 'legacy';\n if (issue !== undefined) throw new ProtocolError(INVALID_PARAMS, `Invalid _meta envelope: ${issue}`);\n if (!supported) {\n throw new ProtocolError(UNSUPPORTED_PROTOCOL_VERSION, 'Unsupported protocol version', {\n supported: [...MODERN_PROTOCOL_VERSIONS],\n requested: version,\n });\n }\n return 'modern';\n}\n\n/** The version `initialize` settles on: the one asked for, or the newest legacy one. */\nexport function negotiateLegacyVersion(requested: unknown): string {\n return LEGACY_PROTOCOL_VERSIONS.includes(requested as string) ? (requested as string) : (LEGACY_PROTOCOL_VERSIONS[0] as string);\n}\n\n/* ------------------------------------------------------------------ servers */\n\n/** What a tool call produced: text for the model, and the same as data. */\nexport interface ToolOutcome {\n readonly text: string;\n readonly structured?: JsonObject | undefined;\n readonly isError?: boolean | undefined;\n}\n\nexport interface ToolDefinition {\n /** The descriptor `tools/list` returns: name, title, description, inputSchema, annotations. */\n readonly descriptor: JsonObject & { readonly name: string };\n /** Runs the tool. Arguments arrive as an object, unvalidated beyond that. */\n call(args: JsonObject): Promise<ToolOutcome>;\n}\n\nexport interface ResourceProvider {\n /** Concrete resources, as `resources/list` returns them. */\n list(): Promise<readonly JsonObject[]>;\n /** URI templates, as `resources/templates/list` returns them. */\n readonly templates?: readonly JsonObject[] | undefined;\n /** The contents of one resource, or `null` when there is no such resource. */\n read(uri: string): Promise<readonly JsonObject[] | null>;\n}\n\nexport interface PromptDefinition {\n /** The descriptor `prompts/list` returns: name, title, description, arguments. */\n readonly descriptor: JsonObject & { readonly name: string };\n /** The messages the prompt expands to, given its arguments as strings. */\n get(args: Readonly<Record<string, string>>): Promise<JsonObject>;\n}\n\nexport interface McpServerDefinition {\n readonly name: string;\n readonly version: string;\n /** Sent in the handshake: what the server is for, and when to call what. */\n readonly instructions: string;\n readonly tools?: readonly ToolDefinition[] | undefined;\n readonly resources?: ResourceProvider | undefined;\n readonly prompts?: readonly PromptDefinition[] | undefined;\n /**\n * Whether results other than a tool call's may be cached by a modern\n * client, and for how long. Absent: every result is stale at once and\n * private, which is right for a server that reads the repository afresh\n * on each request.\n */\n readonly cacheTtlMs?: number | undefined;\n}\n\n/** A tool's failure, reported to the model rather than as a protocol error it cannot read. */\nexport function toolError(text: string): ToolOutcome {\n return { text, isError: true };\n}\n\n/**\n * Arguments a tool does not declare, which the model should hear about rather\n * than have silently dropped. `undefined` when there are none.\n */\nexport function unknownArguments(args: JsonObject, allowed: readonly string[]): ToolOutcome | undefined {\n const unknown = Object.keys(args).filter((name) => !allowed.includes(name));\n if (unknown.length === 0) return undefined;\n const list = unknown.map((name) => `\"${name}\"`).join(', ');\n const takes =\n allowed.length === 0\n ? 'no arguments'\n : allowed.length === 1\n ? (allowed[0] as string)\n : `${allowed.slice(0, -1).join(', ')} and ${allowed[allowed.length - 1] as string}`;\n return toolError(`Unknown argument${unknown.length === 1 ? '' : 's'} ${list}; this tool takes ${takes}.`);\n}\n\n/**\n * Builds the function that answers one parsed JSON-RPC message: the message\n * to send back, or `null` when nothing is owed - a notification, or a\n * response the client should not have sent.\n */\nexport function createMcpServer(definition: McpServerDefinition): (message: unknown) => Promise<OutgoingMessage | null> {\n const serverInfo = { name: definition.name, version: definition.version };\n const tools = definition.tools ?? [];\n const prompts = definition.prompts ?? [];\n const capabilities: JsonObject = {\n ...(tools.length > 0 ? { tools: {} } : {}),\n ...(definition.resources !== undefined ? { resources: {} } : {}),\n ...(prompts.length > 0 ? { prompts: {} } : {}),\n };\n\n const refuseCursor = (params: JsonObject | undefined): void => {\n if (params?.['cursor'] !== undefined) throw new ProtocolError(INVALID_PARAMS, 'Invalid cursor: this server does not paginate.');\n };\n\n const callTool = async (params: JsonObject): Promise<JsonObject> => {\n const name = params['name'];\n if (typeof name !== 'string') throw new ProtocolError(INVALID_PARAMS, 'tools/call needs the name of a tool.');\n const tool = tools.find((candidate) => candidate.descriptor.name === name);\n if (tool === undefined) throw new ProtocolError(INVALID_PARAMS, `Unknown tool: ${name}`);\n const args = params['arguments'] ?? {};\n if (!isObject(args)) throw new ProtocolError(INVALID_PARAMS, 'Tool arguments must be an object.');\n let outcome: ToolOutcome;\n try {\n outcome = await tool.call(args);\n } catch (error) {\n outcome = toolError(`${definition.name} failed: ${error instanceof Error ? error.message : String(error)}`);\n }\n return {\n content: [{ type: 'text', text: outcome.text }],\n ...(outcome.structured === undefined ? {} : { structuredContent: outcome.structured }),\n ...(outcome.isError === true ? { isError: true } : {}),\n };\n };\n\n const readResource = async (params: JsonObject, era: Era): Promise<JsonObject> => {\n const uri = params['uri'];\n if (typeof uri !== 'string') throw new ProtocolError(INVALID_PARAMS, 'resources/read needs a uri.');\n const contents = await (definition.resources as ResourceProvider).read(uri);\n if (contents === null) {\n throw new ProtocolError(era === 'modern' ? INVALID_PARAMS : LEGACY_RESOURCE_NOT_FOUND, 'Resource not found', { uri });\n }\n return { contents: [...contents] };\n };\n\n const getPrompt = async (params: JsonObject): Promise<JsonObject> => {\n const name = params['name'];\n if (typeof name !== 'string') throw new ProtocolError(INVALID_PARAMS, 'prompts/get needs the name of a prompt.');\n const prompt = prompts.find((candidate) => candidate.descriptor.name === name);\n if (prompt === undefined) throw new ProtocolError(INVALID_PARAMS, `Unknown prompt: ${name}`);\n const args = params['arguments'] ?? {};\n if (!isObject(args) || !Object.values(args).every((value) => typeof value === 'string')) {\n throw new ProtocolError(INVALID_PARAMS, 'Prompt arguments must be an object of strings.');\n }\n return prompt.get(args as Record<string, string>);\n };\n\n const dispatch = async (method: string, params: JsonObject | undefined, era: Era): Promise<JsonObject> => {\n const given = params ?? {};\n if (era === 'legacy') {\n if (method === 'initialize') {\n return {\n protocolVersion: negotiateLegacyVersion(given['protocolVersion']),\n capabilities,\n serverInfo,\n instructions: definition.instructions,\n };\n }\n if (method === 'ping') return {};\n } else if (method === 'server/discover') {\n return { supportedVersions: [...MODERN_PROTOCOL_VERSIONS], capabilities, instructions: definition.instructions };\n }\n // A method for a capability the server did not declare does not exist on\n // it: the answer is the one for any unknown method, not an empty list that\n // reads as \"declared, and empty\".\n const family = method.slice(0, method.indexOf('/') + 1);\n if (\n (family === 'tools/' && tools.length === 0) ||\n (family === 'resources/' && definition.resources === undefined) ||\n (family === 'prompts/' && prompts.length === 0)\n ) {\n throw new ProtocolError(METHOD_NOT_FOUND, 'Method not found');\n }\n switch (method) {\n case 'tools/list':\n refuseCursor(params);\n return { tools: tools.map((tool) => tool.descriptor) };\n case 'tools/call':\n return callTool(given);\n case 'resources/list':\n refuseCursor(params);\n return { resources: [...(await (definition.resources as ResourceProvider).list())] };\n case 'resources/templates/list':\n refuseCursor(params);\n return { resourceTemplates: [...((definition.resources as ResourceProvider).templates ?? [])] };\n case 'resources/read':\n return readResource(given, era);\n case 'prompts/list':\n refuseCursor(params);\n return { prompts: prompts.map((prompt) => prompt.descriptor) };\n case 'prompts/get':\n return getPrompt(given);\n default:\n throw new ProtocolError(METHOD_NOT_FOUND, 'Method not found');\n }\n };\n\n /** The 2026-07-28 shape: a result type, caching hints where required, and identity. */\n const modernResult = (method: string, result: JsonObject): JsonObject => {\n const cacheable = method !== 'tools/call';\n return {\n resultType: 'complete',\n ...result,\n ...(cacheable ? { ttlMs: definition.cacheTtlMs ?? 0, cacheScope: 'private' } : {}),\n _meta: { [SERVER_INFO_KEY]: serverInfo },\n };\n };\n\n return async (message: unknown): Promise<OutgoingMessage | null> => {\n if (!isObject(message)) {\n return {\n jsonrpc: '2.0',\n error: {\n code: INVALID_REQUEST,\n message: Array.isArray(message) ? 'Invalid Request: batches are not supported' : 'Invalid Request',\n },\n };\n }\n const { id, method, params } = message;\n if (message['jsonrpc'] === '2.0' && method === undefined && isRequestId(id) && ('result' in message || 'error' in message)) {\n return null;\n }\n if (message['jsonrpc'] !== '2.0' || typeof method !== 'string' || (id !== undefined && !isRequestId(id))) {\n return { jsonrpc: '2.0', ...(isRequestId(id) ? { id } : {}), error: { code: INVALID_REQUEST, message: 'Invalid Request' } };\n }\n if (id === undefined) return null;\n try {\n if (params !== undefined && !isObject(params)) throw new ProtocolError(INVALID_PARAMS, 'params must be an object.');\n const era = classifyRequest(method, params);\n const result = await dispatch(method, params, era);\n return { jsonrpc: '2.0', id, result: era === 'modern' ? modernResult(method, result) : result };\n } catch (error) {\n const failure: ErrorObject =\n error instanceof ProtocolError\n ? { code: error.code, message: error.message, data: error.data }\n : { code: INTERNAL_ERROR, message: `Internal error: ${error instanceof Error ? error.message : String(error)}` };\n return { jsonrpc: '2.0', id, error: failure };\n }\n };\n}\n\n/* -------------------------------------------------------------------- lines */\n\n/** Anything that delivers bytes and says when it has finished: `process.stdin`, or a test's stand-in. */\nexport interface ByteSource {\n on(event: 'data', listener: (chunk: Uint8Array) => void): unknown;\n once(event: 'end', listener: () => void): unknown;\n once(event: 'error', listener: (error: Error) => void): unknown;\n}\n\n/** The key a request is tracked under: `1` and `\"1\"` are different ids. */\nfunction trackingKey(id: RequestId): string {\n return `${typeof id}:${id}`;\n}\n\n/**\n * Serves a handler over newline-delimited JSON-RPC until the input ends.\n *\n * Messages are split on `\\n`; a CRLF line keeps its `\\r`, which JSON reads\n * as whitespace. Blank lines are skipped, and every response is written as a\n * single line - `JSON.stringify` never emits a raw newline, which is what the\n * binding requires. Requests are answered concurrently, in whatever order\n * they finish. A request the client cancels gets no response. When the input\n * closes, requests still running finish and then this resolves.\n */\nexport function serveLines(\n input: ByteSource,\n write: (line: string) => void,\n handle: (message: unknown) => Promise<OutgoingMessage | null>,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const decoder = new TextDecoder();\n let buffer = '';\n let running = 0;\n let ended = false;\n const inFlight = new Set<string | undefined>();\n const cancelled = new Set<string | undefined>();\n const settle = (): void => {\n if (ended && running === 0) resolve();\n };\n\n const receive = (line: string): void => {\n if (line.trim() === '') return;\n let message: unknown;\n try {\n message = JSON.parse(line);\n } catch {\n write(JSON.stringify({ jsonrpc: '2.0', error: { code: PARSE_ERROR, message: 'Parse error' } }));\n return;\n }\n if (isObject(message) && message['method'] === 'notifications/cancelled') {\n const requestId = isObject(message['params']) ? message['params']['requestId'] : undefined;\n if (isRequestId(requestId) && inFlight.has(trackingKey(requestId))) cancelled.add(trackingKey(requestId));\n return;\n }\n const key = isObject(message) && typeof message['method'] === 'string' ? trackingKey(message['id'] as RequestId) : undefined;\n inFlight.add(key);\n running += 1;\n void handle(message).then((response) => {\n running -= 1;\n inFlight.delete(key);\n if (!cancelled.delete(key) && response !== null) write(JSON.stringify(response));\n settle();\n });\n };\n\n input.on('data', (chunk: Uint8Array) => {\n buffer += decoder.decode(chunk, { stream: true });\n for (let newline = buffer.indexOf('\\n'); newline !== -1; newline = buffer.indexOf('\\n')) {\n const line = buffer.slice(0, newline);\n buffer = buffer.slice(newline + 1);\n receive(line);\n }\n });\n input.once('end', () => {\n ended = true;\n receive(buffer + decoder.decode());\n settle();\n });\n input.once('error', reject);\n });\n}\n"]}
1
+ {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/jsonrpc/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,wBAAwB,GAAsB,CAAC,YAAY,CAAC,CAAC;AAE1E,+EAA+E;AAC/E,MAAM,CAAC,MAAM,wBAAwB,GAAsB,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;AAElI,MAAM,CAAC,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,4CAA4C,CAAC;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,oCAAoC,CAAC;AACpE,MAAM,CAAC,MAAM,eAAe,GAAG,oCAAoC,CAAC;AAEpE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,gBAAgB,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,EAAE;YACrB,KAAK,GAAG,IAAI,CAAC;YACb,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACnC,MAAM,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * The Model Context Protocol over JSON-RPC 2.0, without an SDK.\n *\n * MCP over stdio is JSON-RPC 2.0, one message per line, and what a server must\n * get right fits here: framing, the two eras of the protocol, and the methods\n * that serve tools, resources and prompts. The official SDK brings a schema\n * library and a dependency tree to do the same; every spec-* tool promises no\n * runtime dependencies. Moved here from spec-guard (its ADR-0012), where it\n * was first written and measured, so that a second server does not relearn it.\n *\n * Two eras, served side by side. Revisions up to 2025-11-25 open with an\n * `initialize` handshake; 2026-07-28 has none, and every request carries its\n * protocol version in `_meta`. Clients of both are in use - the newest\n * revision is not yet the one most clients speak - so each request is\n * classified on its own, by the rule the TypeScript SDK's server applies: a\n * request that claims a version in `_meta` is modern and its claim is\n * validated; anything else, `initialize` included, is legacy.\n *\n * Nothing here touches a stream or a file. A server is a function from one\n * parsed message to the message owed back; `serveLines` binds one to any\n * source of bytes with `on('data')`, which on Node is `process.stdin`.\n */\n\n/** Revisions that carry their version on every request. Newest first. */\nexport const MODERN_PROTOCOL_VERSIONS: readonly string[] = ['2026-07-28'];\n\n/** Revisions negotiated by `initialize`, newest first - the SDK's own list. */\nexport const LEGACY_PROTOCOL_VERSIONS: readonly string[] = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05', '2024-10-07'];\n\nexport const PROTOCOL_VERSION_KEY = 'io.modelcontextprotocol/protocolVersion';\nexport const CLIENT_CAPABILITIES_KEY = 'io.modelcontextprotocol/clientCapabilities';\nexport const CLIENT_INFO_KEY = 'io.modelcontextprotocol/clientInfo';\nexport const SERVER_INFO_KEY = 'io.modelcontextprotocol/serverInfo';\n\nexport const PARSE_ERROR = -32700;\nexport const INVALID_REQUEST = -32600;\nexport const METHOD_NOT_FOUND = -32601;\nexport const INVALID_PARAMS = -32602;\nexport const INTERNAL_ERROR = -32603;\n/** Resource not found before 2026-07-28, which forbids it in favour of -32602. */\nexport const LEGACY_RESOURCE_NOT_FOUND = -32002;\nexport const UNSUPPORTED_PROTOCOL_VERSION = -32022;\n\nexport type RequestId = string | number;\nexport type Era = 'legacy' | 'modern';\nexport type JsonObject = Record<string, unknown>;\n\nexport interface ErrorObject {\n readonly code: number;\n readonly message: string;\n readonly data?: unknown;\n}\n\n/** Everything a server here writes. It never sends a request. */\nexport type OutgoingMessage =\n | { readonly jsonrpc: '2.0'; readonly id: RequestId; readonly result: JsonObject }\n | { readonly jsonrpc: '2.0'; readonly id?: RequestId; readonly error: ErrorObject };\n\n/** An error that becomes a JSON-RPC error response with its code. */\nexport class ProtocolError extends Error {\n readonly code: number;\n readonly data: unknown;\n constructor(code: number, message: string, data?: unknown) {\n super(message);\n this.name = 'ProtocolError';\n this.code = code;\n this.data = data;\n }\n}\n\nexport function isObject(value: unknown): value is JsonObject {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** JSON-RPC allows a null id; MCP does not, and wants an integer if a number. */\nexport function isRequestId(value: unknown): value is RequestId {\n return typeof value === 'string' || Number.isInteger(value);\n}\n\n/**\n * What is wrong with a request's `_meta` once it claims a protocol version,\n * or `undefined`. A claim is never ignored: a malformed one is an error, not\n * a reason to fall back to the legacy handling.\n */\nexport function envelopeIssue(meta: JsonObject): string | undefined {\n if (!(CLIENT_CAPABILITIES_KEY in meta)) return `${CLIENT_CAPABILITIES_KEY}: missing`;\n if (typeof meta[PROTOCOL_VERSION_KEY] !== 'string') return `${PROTOCOL_VERSION_KEY}: expected a string`;\n if (!isObject(meta[CLIENT_CAPABILITIES_KEY])) return `${CLIENT_CAPABILITIES_KEY}: expected an object`;\n const info = meta[CLIENT_INFO_KEY];\n if (info !== undefined && !(isObject(info) && typeof info['name'] === 'string' && typeof info['version'] === 'string')) {\n return `${CLIENT_INFO_KEY}: expected an object with a string name and version`;\n }\n return undefined;\n}\n\n/**\n * The era a request belongs to, or the error that answers it instead.\n *\n * `initialize` is the legacy handshake unless it carries a valid modern claim.\n * Any other request is modern exactly when `_meta` holds the version key - its\n * presence is the claim, whatever its value - and legacy otherwise.\n */\nexport function classifyRequest(method: string, params: JsonObject | undefined): Era {\n const meta = params?.['_meta'];\n const claimed = isObject(meta) && PROTOCOL_VERSION_KEY in meta;\n if (!claimed) return 'legacy';\n const issue = envelopeIssue(meta);\n const version = meta[PROTOCOL_VERSION_KEY] as string;\n const supported = issue === undefined && MODERN_PROTOCOL_VERSIONS.includes(version);\n if (method === 'initialize' && !supported) return 'legacy';\n if (issue !== undefined) throw new ProtocolError(INVALID_PARAMS, `Invalid _meta envelope: ${issue}`);\n if (!supported) {\n throw new ProtocolError(UNSUPPORTED_PROTOCOL_VERSION, 'Unsupported protocol version', {\n supported: [...MODERN_PROTOCOL_VERSIONS],\n requested: version,\n });\n }\n return 'modern';\n}\n\n/** The version `initialize` settles on: the one asked for, or the newest legacy one. */\nexport function negotiateLegacyVersion(requested: unknown): string {\n return LEGACY_PROTOCOL_VERSIONS.includes(requested as string) ? (requested as string) : (LEGACY_PROTOCOL_VERSIONS[0] as string);\n}\n\n/* ------------------------------------------------------------------ servers */\n\n/** What a tool call produced: text for the model, and the same as data. */\nexport interface ToolOutcome {\n readonly text: string;\n readonly structured?: JsonObject | undefined;\n readonly isError?: boolean | undefined;\n}\n\nexport interface ToolDefinition {\n /** The descriptor `tools/list` returns: name, title, description, inputSchema, annotations. */\n readonly descriptor: JsonObject & { readonly name: string };\n /** Runs the tool. Arguments arrive as an object, unvalidated beyond that. */\n call(args: JsonObject): Promise<ToolOutcome>;\n}\n\nexport interface ResourceProvider {\n /** Concrete resources, as `resources/list` returns them. */\n list(): Promise<readonly JsonObject[]>;\n /** URI templates, as `resources/templates/list` returns them. */\n readonly templates?: readonly JsonObject[] | undefined;\n /** The contents of one resource, or `null` when there is no such resource. */\n read(uri: string): Promise<readonly JsonObject[] | null>;\n}\n\nexport interface PromptDefinition {\n /** The descriptor `prompts/list` returns: name, title, description, arguments. */\n readonly descriptor: JsonObject & { readonly name: string };\n /** The messages the prompt expands to, given its arguments as strings. */\n get(args: Readonly<Record<string, string>>): Promise<JsonObject>;\n}\n\nexport interface McpServerDefinition {\n readonly name: string;\n readonly version: string;\n /** Sent in the handshake: what the server is for, and when to call what. */\n readonly instructions: string;\n readonly tools?: readonly ToolDefinition[] | undefined;\n readonly resources?: ResourceProvider | undefined;\n readonly prompts?: readonly PromptDefinition[] | undefined;\n /**\n * Whether results other than a tool call's may be cached by a modern\n * client, and for how long. Absent: every result is stale at once and\n * private, which is right for a server that reads the repository afresh\n * on each request.\n */\n readonly cacheTtlMs?: number | undefined;\n}\n\n/** A tool's failure, reported to the model rather than as a protocol error it cannot read. */\nexport function toolError(text: string): ToolOutcome {\n return { text, isError: true };\n}\n\n/**\n * Arguments a tool does not declare, which the model should hear about rather\n * than have silently dropped. `undefined` when there are none.\n */\nexport function unknownArguments(args: JsonObject, allowed: readonly string[]): ToolOutcome | undefined {\n const unknown = Object.keys(args).filter((name) => !allowed.includes(name));\n if (unknown.length === 0) return undefined;\n const list = unknown.map((name) => `\"${name}\"`).join(', ');\n const takes =\n allowed.length === 0\n ? 'no arguments'\n : allowed.length === 1\n ? (allowed[0] as string)\n : `${allowed.slice(0, -1).join(', ')} and ${allowed[allowed.length - 1]!}`;\n return toolError(`Unknown argument${unknown.length === 1 ? '' : 's'} ${list}; this tool takes ${takes}.`);\n}\n\n/**\n * Builds the function that answers one parsed JSON-RPC message: the message\n * to send back, or `null` when nothing is owed - a notification, or a\n * response the client should not have sent.\n */\nexport function createMcpServer(definition: McpServerDefinition): (message: unknown) => Promise<OutgoingMessage | null> {\n const serverInfo = { name: definition.name, version: definition.version };\n const tools = definition.tools ?? [];\n const prompts = definition.prompts ?? [];\n const capabilities: JsonObject = {\n ...(tools.length > 0 ? { tools: {} } : {}),\n ...(definition.resources !== undefined ? { resources: {} } : {}),\n ...(prompts.length > 0 ? { prompts: {} } : {}),\n };\n\n const refuseCursor = (params: JsonObject | undefined): void => {\n if (params?.['cursor'] !== undefined) throw new ProtocolError(INVALID_PARAMS, 'Invalid cursor: this server does not paginate.');\n };\n\n const callTool = async (params: JsonObject): Promise<JsonObject> => {\n const name = params['name'];\n if (typeof name !== 'string') throw new ProtocolError(INVALID_PARAMS, 'tools/call needs the name of a tool.');\n const tool = tools.find((candidate) => candidate.descriptor.name === name);\n if (tool === undefined) throw new ProtocolError(INVALID_PARAMS, `Unknown tool: ${name}`);\n const args = params['arguments'] ?? {};\n if (!isObject(args)) throw new ProtocolError(INVALID_PARAMS, 'Tool arguments must be an object.');\n let outcome: ToolOutcome;\n try {\n outcome = await tool.call(args);\n } catch (error) {\n outcome = toolError(`${definition.name} failed: ${error instanceof Error ? error.message : String(error)}`);\n }\n return {\n content: [{ type: 'text', text: outcome.text }],\n ...(outcome.structured === undefined ? {} : { structuredContent: outcome.structured }),\n ...(outcome.isError === true ? { isError: true } : {}),\n };\n };\n\n const readResource = async (params: JsonObject, era: Era): Promise<JsonObject> => {\n const uri = params['uri'];\n if (typeof uri !== 'string') throw new ProtocolError(INVALID_PARAMS, 'resources/read needs a uri.');\n const contents = await (definition.resources as ResourceProvider).read(uri);\n if (contents === null) {\n throw new ProtocolError(era === 'modern' ? INVALID_PARAMS : LEGACY_RESOURCE_NOT_FOUND, 'Resource not found', { uri });\n }\n return { contents: [...contents] };\n };\n\n const getPrompt = async (params: JsonObject): Promise<JsonObject> => {\n const name = params['name'];\n if (typeof name !== 'string') throw new ProtocolError(INVALID_PARAMS, 'prompts/get needs the name of a prompt.');\n const prompt = prompts.find((candidate) => candidate.descriptor.name === name);\n if (prompt === undefined) throw new ProtocolError(INVALID_PARAMS, `Unknown prompt: ${name}`);\n const args = params['arguments'] ?? {};\n if (!isObject(args) || !Object.values(args).every((value) => typeof value === 'string')) {\n throw new ProtocolError(INVALID_PARAMS, 'Prompt arguments must be an object of strings.');\n }\n return prompt.get(args as Record<string, string>);\n };\n\n const dispatch = async (method: string, params: JsonObject | undefined, era: Era): Promise<JsonObject> => {\n const given = params ?? {};\n if (era === 'legacy') {\n if (method === 'initialize') {\n return {\n protocolVersion: negotiateLegacyVersion(given['protocolVersion']),\n capabilities,\n serverInfo,\n instructions: definition.instructions,\n };\n }\n if (method === 'ping') return {};\n } else if (method === 'server/discover') {\n return { supportedVersions: [...MODERN_PROTOCOL_VERSIONS], capabilities, instructions: definition.instructions };\n }\n // A method for a capability the server did not declare does not exist on\n // it: the answer is the one for any unknown method, not an empty list that\n // reads as \"declared, and empty\".\n const family = method.slice(0, method.indexOf('/') + 1);\n if (\n (family === 'tools/' && tools.length === 0) ||\n (family === 'resources/' && definition.resources === undefined) ||\n (family === 'prompts/' && prompts.length === 0)\n ) {\n throw new ProtocolError(METHOD_NOT_FOUND, 'Method not found');\n }\n switch (method) {\n case 'tools/list':\n refuseCursor(params);\n return { tools: tools.map((tool) => tool.descriptor) };\n case 'tools/call':\n return callTool(given);\n case 'resources/list':\n refuseCursor(params);\n return { resources: [...(await (definition.resources as ResourceProvider).list())] };\n case 'resources/templates/list':\n refuseCursor(params);\n return { resourceTemplates: [...((definition.resources as ResourceProvider).templates ?? [])] };\n case 'resources/read':\n return readResource(given, era);\n case 'prompts/list':\n refuseCursor(params);\n return { prompts: prompts.map((prompt) => prompt.descriptor) };\n case 'prompts/get':\n return getPrompt(given);\n default:\n throw new ProtocolError(METHOD_NOT_FOUND, 'Method not found');\n }\n };\n\n /** The 2026-07-28 shape: a result type, caching hints where required, and identity. */\n const modernResult = (method: string, result: JsonObject): JsonObject => {\n const cacheable = method !== 'tools/call';\n return {\n resultType: 'complete',\n ...result,\n ...(cacheable ? { ttlMs: definition.cacheTtlMs ?? 0, cacheScope: 'private' } : {}),\n _meta: { [SERVER_INFO_KEY]: serverInfo },\n };\n };\n\n return async (message: unknown): Promise<OutgoingMessage | null> => {\n if (!isObject(message)) {\n return {\n jsonrpc: '2.0',\n error: {\n code: INVALID_REQUEST,\n message: Array.isArray(message) ? 'Invalid Request: batches are not supported' : 'Invalid Request',\n },\n };\n }\n const { id, method, params } = message;\n if (message['jsonrpc'] === '2.0' && method === undefined && isRequestId(id) && ('result' in message || 'error' in message)) {\n return null;\n }\n if (message['jsonrpc'] !== '2.0' || typeof method !== 'string' || (id !== undefined && !isRequestId(id))) {\n return { jsonrpc: '2.0', ...(isRequestId(id) ? { id } : {}), error: { code: INVALID_REQUEST, message: 'Invalid Request' } };\n }\n if (id === undefined) return null;\n try {\n if (params !== undefined && !isObject(params)) throw new ProtocolError(INVALID_PARAMS, 'params must be an object.');\n const era = classifyRequest(method, params);\n const result = await dispatch(method, params, era);\n return { jsonrpc: '2.0', id, result: era === 'modern' ? modernResult(method, result) : result };\n } catch (error) {\n const failure: ErrorObject =\n error instanceof ProtocolError\n ? { code: error.code, message: error.message, data: error.data }\n : { code: INTERNAL_ERROR, message: `Internal error: ${error instanceof Error ? error.message : String(error)}` };\n return { jsonrpc: '2.0', id, error: failure };\n }\n };\n}\n\n/* -------------------------------------------------------------------- lines */\n\n/** Anything that delivers bytes and says when it has finished: `process.stdin`, or a test's stand-in. */\nexport interface ByteSource {\n on(event: 'data', listener: (chunk: Uint8Array) => void): unknown;\n once(event: 'end', listener: () => void): unknown;\n once(event: 'error', listener: (error: Error) => void): unknown;\n}\n\n/** The key a request is tracked under: `1` and `\"1\"` are different ids. */\nfunction trackingKey(id: RequestId): string {\n return `${typeof id}:${id}`;\n}\n\n/**\n * Serves a handler over newline-delimited JSON-RPC until the input ends.\n *\n * Messages are split on `\\n`; a CRLF line keeps its `\\r`, which JSON reads\n * as whitespace. Blank lines are skipped, and every response is written as a\n * single line - `JSON.stringify` never emits a raw newline, which is what the\n * binding requires. Requests are answered concurrently, in whatever order\n * they finish. A request the client cancels gets no response. When the input\n * closes, requests still running finish and then this resolves.\n */\nexport function serveLines(\n input: ByteSource,\n write: (line: string) => void,\n handle: (message: unknown) => Promise<OutgoingMessage | null>,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const decoder = new TextDecoder();\n let buffer = '';\n let running = 0;\n let ended = false;\n const inFlight = new Set<string | undefined>();\n const cancelled = new Set<string | undefined>();\n const settle = (): void => {\n if (ended && running === 0) resolve();\n };\n\n const receive = (line: string): void => {\n if (line.trim() === '') return;\n let message: unknown;\n try {\n message = JSON.parse(line);\n } catch {\n write(JSON.stringify({ jsonrpc: '2.0', error: { code: PARSE_ERROR, message: 'Parse error' } }));\n return;\n }\n if (isObject(message) && message['method'] === 'notifications/cancelled') {\n const requestId = isObject(message['params']) ? message['params']['requestId'] : undefined;\n if (isRequestId(requestId) && inFlight.has(trackingKey(requestId))) cancelled.add(trackingKey(requestId));\n return;\n }\n const key = isObject(message) && typeof message['method'] === 'string' ? trackingKey((message as { id: RequestId })['id']) : undefined;\n inFlight.add(key);\n running += 1;\n void handle(message).then((response) => {\n running -= 1;\n inFlight.delete(key);\n if (!cancelled.delete(key) && response !== null) write(JSON.stringify(response));\n settle();\n });\n };\n\n input.on('data', (chunk: Uint8Array) => {\n buffer += decoder.decode(chunk, { stream: true });\n for (let newline = buffer.indexOf('\\n'); newline !== -1; newline = buffer.indexOf('\\n')) {\n const line = buffer.slice(0, newline);\n buffer = buffer.slice(newline + 1);\n receive(line);\n }\n });\n input.once('end', () => {\n ended = true;\n receive(buffer + decoder.decode());\n settle();\n });\n input.once('error', reject);\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/markdown/frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA0DxC,MAAM,SAAS,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S,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAW,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;IAClJ,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,WAAW,CAAC,KAAwB,EAAE,WAA+B,EAAE,GAAW;IAChG,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["/**\n * A reader and editor for the front matter the spec-* tools use: a flat bag\n * of YAML scalars and lists, and optionally one level of nested mapping.\n *\n * Supported: `key: value` lines; plain, single-quoted and double-quoted\n * scalars; inline `[a, b]` sequences; block `- item` sequences; `#` comments.\n * Plain scalars follow the YAML 1.2 core schema, so `yes` is a word and `035`\n * keeps its leading zero for whoever reads it as text. With `nested`, a key\n * whose value is an indented block of keys is read as `parent.child` entries.\n *\n * Anything richer - deeper nesting, block scalars, anchors, tags, a value\n * continued onto the next line - is recognised and reported as unsupported\n * rather than guessed at. A YAML library would parse more, but it would not\n * give back the line and the offset of every value, and a report has to point\n * at the value it is about, and an edit has to leave every other line of the\n * file as it was.\n */\n\nimport { lineStarts, splitLines, stripBom } from '../text/index.js';\nimport { leadIndex } from './syntax.js';\nimport type { FrontMatterKind } from './types.js';\n\nexport interface YamlScalar {\n readonly text: string;\n readonly quoted: boolean;\n}\n\nexport type YamlValue =\n | { readonly kind: 'scalar'; readonly scalar: YamlScalar }\n | { readonly kind: 'list'; readonly items: readonly YamlScalar[] }\n | { readonly kind: 'unsupported'; readonly reason: string };\n\nexport interface FrontMatterEntry {\n /** The key as written; a nested key is its parent's and its own, joined by a dot. */\n readonly key: string;\n /** The key compared: {@link keyName} of `key`, so `depends-on` is `dependsOn`. */\n readonly name: string;\n /** The parent key as written, for a nested key; `null` at the top level. */\n readonly parent: string | null;\n /** 0-based line of the key. */\n readonly line: number;\n /** 0-based line after the entry's last line. */\n readonly end: number;\n /** Offset of the key in the text read. */\n readonly keyStart: number;\n /**\n * Offsets of the value as written: a quoted scalar with its quotes, an\n * inline list with its brackets, a block list from its first item's text to\n * its last item's. An empty value is the empty range just past the colon.\n */\n readonly valueStart: number;\n readonly valueEnd: number;\n readonly value: YamlValue;\n}\n\nexport interface FrontMatterProblem {\n /** 0-based line. */\n readonly line: number;\n readonly message: string;\n}\n\nexport interface FrontMatter {\n readonly kind: FrontMatterKind;\n /** 0-based line of the closing delimiter, or -1 when the block is never closed. */\n readonly close: number;\n readonly entries: readonly FrontMatterEntry[];\n readonly problems: readonly FrontMatterProblem[];\n}\n\nexport interface ReadOptions {\n /**\n * Read one level of nested mapping as `parent.child` entries, instead of\n * reporting the parent's value as unsupported.\n */\n readonly nested?: boolean;\n}\n\nconst YAML_OPEN = /^---[ \\t]*$/;\nconst YAML_CLOSE = /^(?:---|\\.\\.\\.)[ \\t]*$/;\nconst TOML_FENCE = /^\\+\\+\\+[ \\t]*$/;\n\n/** The kind of front matter a document's first line opens, or `null` when it opens none. */\nexport function frontMatterKind(firstLine: string): FrontMatterKind | null {\n if (YAML_OPEN.test(firstLine)) return 'yaml';\n return TOML_FENCE.test(firstLine) ? 'toml' : null;\n}\n\n/** Whether a line closes front matter of a kind: `---` or `...` for YAML, `+++` for TOML. */\nexport function frontMatterCloses(line: string, kind: FrontMatterKind): boolean {\n return (kind === 'yaml' ? YAML_CLOSE : TOML_FENCE).test(line);\n}\n\n/**\n * A key and what follows its colon. A key is a word of any script, as a YAML\n * plain key may be: a letter or `_` first, then letters, marks, digits and\n * `_.-`, so `狀態` and `状态` are keys as `status` is. Nothing else is one: a\n * digit or a mark first, a space, punctuation, and a full-width colon, which\n * YAML does not read as one.\n */\nconst KEY = /^([\\p{L}_][\\p{L}\\p{M}\\p{N}_.-]*)[ \\t]*:(?:[ \\t]+(.*))?$/u;\nconst SEQUENCE_ITEM = /^([ \\t]*)-(?:[ \\t]+(.*))?$/;\nconst BLANK_OR_COMMENT = /^[ \\t]*(?:#.*)?$/;\n\nexport function keyName(key: string): string {\n return key.toLowerCase().replace(/[-_]/g, '');\n}\n\n/**\n * Reads the front matter at the top of a text, or `null` when there is none.\n *\n * A leading byte-order mark is not part of the text read: offsets count from\n * the character after it, as a scan's do.\n */\nexport function readFrontMatter(source: string, options: ReadOptions = {}): FrontMatter | null {\n const text = stripBom(source);\n const lines = splitLines(text);\n const kind = frontMatterKind(lines[0] as string);\n if (kind === null) return null;\n const close = lines.findIndex((line, i) => i > 0 && frontMatterCloses(line, kind));\n if (close === -1) {\n return { kind, close, entries: [], problems: [{ line: 0, message: 'the front matter opened on line 1 is never closed' }] };\n }\n if (kind === 'toml') {\n return { kind, close, entries: [], problems: [{ line: 0, message: 'TOML front matter is not read; write YAML between \"---\" lines' }] };\n }\n\n const reader: Reader = {\n lines,\n starts: lineStarts(text),\n nested: options.nested === true,\n entries: [],\n problems: [],\n seen: new Map(),\n };\n let i = 1;\n while (i < close) {\n const line = lines[i] as string;\n if (BLANK_OR_COMMENT.test(line)) {\n i += 1;\n continue;\n }\n const match = KEY.exec(line);\n if (match === null) {\n reader.problems.push({\n line: i,\n message: /^\\s/.test(line) ? 'an indented line belongs to no key' : 'not a \"key: value\" line',\n });\n i += 1;\n continue;\n }\n // The closing delimiter belongs to no value, so the block stops there.\n let end = i + 1;\n while (belongsToBlock(lines[end] as string)) end += 1;\n end = trimBlock(lines, end);\n readEntry(reader, { key: match[1] as string, parent: null, line: i, column: 0, inline: match[2] ?? '', end });\n i = end;\n }\n return { kind, close, entries: reader.entries, problems: reader.problems };\n}\n\ninterface Reader {\n readonly lines: readonly string[];\n readonly starts: readonly number[];\n readonly nested: boolean;\n readonly entries: FrontMatterEntry[];\n readonly problems: FrontMatterProblem[];\n readonly seen: Map<string, number>;\n}\n\ninterface KeyLine {\n /** The key as written on its line, without a parent. */\n readonly key: string;\n readonly parent: string | null;\n readonly line: number;\n /** Column of the key. */\n readonly column: number;\n /** What follows the colon and its whitespace, as written. */\n readonly inline: string;\n /** 0-based line after the key's value. */\n readonly end: number;\n}\n\n/** A line under a top-level key is part of its value when it is indented or starts a sequence item. */\nfunction belongsToBlock(line: string): boolean {\n return /^[ \\t]/.test(line) || /^-(?:[ \\t]|$)/.test(line) || line.trim() === '';\n}\n\n/**\n * Takes trailing blank and comment lines off a value's block: they belong to\n * no key. The key's own line is neither, so the walk stops there at the latest.\n */\nfunction trimBlock(lines: readonly string[], end: number): number {\n let at = end;\n while (BLANK_OR_COMMENT.test(lines[at - 1] as string)) at -= 1;\n return at;\n}\n\nfunction note(reader: Reader, key: string, line: number): string {\n const name = keyName(key);\n const previous = reader.seen.get(name);\n if (previous === undefined) reader.seen.set(name, line);\n else reader.problems.push({ line, message: `\"${key}\" is declared twice (first on line ${previous + 1})` });\n return name;\n}\n\nfunction readEntry(reader: Reader, at: KeyLine): void {\n const { lines, starts } = reader;\n const text = lines[at.line] as string;\n const lineStart = starts[at.line] as number;\n const key = at.parent === null ? at.key : `${at.parent}.${at.key}`;\n // A key holds no colon and nothing before it does, so the first is its own.\n const colon = lineStart + text.indexOf(':') + 1;\n // What follows the colon starts after its whitespace; what ends it is\n // trimmed by whichever reader takes it.\n const inline = stripLeadingComment(at.inline);\n\n let read: Read;\n if (inline.length > 0) {\n const valueStart = lineStart + text.length - at.inline.length;\n const continued = contentLines(lines, at.line + 1, at.end).length > 0;\n const parsed = continued\n ? rough(unsupported('the value continues on the next line; keep it on one line, or quote it'), inline)\n : readInline(inline);\n read = { value: parsed.value, valueStart, valueEnd: valueStart + parsed.length };\n } else {\n const content = contentLines(lines, at.line + 1, at.end);\n const first = content[0];\n if (first !== undefined && at.parent === null && reader.nested && KEY.test((lines[first] as string).trim())) {\n note(reader, at.key, at.line);\n readChildren(reader, at.key, at.line + 1, at.end);\n return;\n }\n read = readBlock(reader, content, colon, at.parent === null);\n }\n\n reader.entries.push({\n key,\n name: note(reader, key, at.line),\n parent: at.parent,\n line: at.line,\n end: at.end,\n keyStart: lineStart + at.column,\n ...read,\n });\n}\n\n/** One level of keys under a parent, all at the indentation of the first. */\nfunction readChildren(reader: Reader, parent: string, from: number, end: number): void {\n const { lines } = reader;\n const first = lines[contentLines(lines, from, end)[0] as number] as string;\n const lead = first.slice(0, leadIndex(first));\n let i = from;\n while (i < end) {\n const line = lines[i] as string;\n if (BLANK_OR_COMMENT.test(line)) {\n i += 1;\n continue;\n }\n // A line deeper than the keys is always taken by the key above it, so only\n // one at their indentation or shallower reaches here.\n const match = line.startsWith(lead) ? KEY.exec(line.slice(lead.length)) : null;\n if (match === null) {\n reader.problems.push({ line: i, message: 'not a \"key: value\" line at the indentation of the keys before it' });\n i += 1;\n continue;\n }\n // Past the parent's value, a line belongs to a child only when it is blank\n // or a comment, and those are trimmed off again.\n let childEnd = i + 1;\n while (belongsToChild(lines[childEnd] as string, lead)) childEnd += 1;\n childEnd = trimBlock(lines, childEnd);\n readEntry(reader, { key: match[1] as string, parent, line: i, column: lead.length, inline: match[2] ?? '', end: childEnd });\n i = childEnd;\n }\n}\n\n/** A line under a nested key is part of its value when it is deeper, or a sequence item at the key's indentation. */\nfunction belongsToChild(line: string, lead: string): boolean {\n if (line.trim() === '') return true;\n if (!line.startsWith(lead)) return false;\n return /^(?:[ \\t]|-(?:[ \\t]|$))/.test(line.slice(lead.length));\n}\n\ninterface Read {\n readonly value: YamlValue;\n readonly valueStart: number;\n readonly valueEnd: number;\n}\n\n/** Indices of the lines in a range that are neither blank nor a comment. */\nfunction contentLines(lines: readonly string[], from: number, end: number): number[] {\n const out: number[] = [];\n for (let i = from; i < end; i += 1) if (!BLANK_OR_COMMENT.test(lines[i] as string)) out.push(i);\n return out;\n}\n\n/** A value written on the lines under its key. */\nfunction readBlock(reader: Reader, content: readonly number[], colon: number, topLevel: boolean): Read {\n const { lines, starts } = reader;\n const first = content[0];\n if (first === undefined) return { value: { kind: 'scalar', scalar: { text: '', quoted: false } }, valueStart: colon, valueEnd: colon };\n\n // An unsupported block is reported over all of its content lines.\n const firstText = lines[first] as string;\n const last = content[content.length - 1] as number;\n const whole = (value: YamlValue): Read => ({\n value,\n valueStart: (starts[first] as number) + leadIndex(firstText),\n valueEnd: (starts[last] as number) + (lines[last] as string).trimEnd().length,\n });\n\n const head = SEQUENCE_ITEM.exec(firstText);\n if (head === null) {\n // Quoting a list would make it a string, so a list gets its own advice.\n if (firstText.trim().startsWith('[')) return whole(unsupported('an inline list starts on the line after its key; write it after the colon'));\n if (!KEY.test(firstText.trim())) return whole(unsupported('the value continues on the next line; keep it on one line, or quote it'));\n return whole(\n unsupported(topLevel ? 'nested mappings are not supported; flatten the key' : 'only one level of nesting is read; flatten the key'),\n );\n }\n const indent = (head[1] as string).length;\n const items: YamlScalar[] = [];\n const spans: [number, number][] = [];\n for (const index of content) {\n const line = lines[index] as string;\n const item = SEQUENCE_ITEM.exec(line);\n if (item === null || (item[1] as string).length !== indent) {\n return whole(unsupported('a list item is continued or nested; keep each item on one line'));\n }\n // The item's text starts after its whitespace, as a key's value does.\n const written = item[2] ?? '';\n const text = stripLeadingComment(written);\n if (text.length === 0) return whole(unsupported('a list item is empty'));\n const parsed = readInline(text);\n if (parsed.value.kind !== 'scalar') {\n return whole(parsed.value.kind === 'list' ? unsupported('nested lists are not supported') : parsed.value);\n }\n const start = (starts[index] as number) + line.length - written.length;\n spans.push([start, start + parsed.length]);\n items.push(parsed.value.scalar);\n }\n return { value: { kind: 'list', items }, valueStart: (spans[0] as [number, number])[0], valueEnd: (spans[spans.length - 1] as [number, number])[1] };\n}\n\nfunction stripLeadingComment(text: string): string {\n return text.startsWith('#') ? '' : text;\n}\n\nfunction unsupported(reason: string): YamlValue {\n return { kind: 'unsupported', reason };\n}\n\ninterface Parsed {\n readonly value: YamlValue;\n /** Characters of the text the value spans. */\n readonly length: number;\n}\n\n/** An unsupported value spans its text up to any comment. */\nfunction rough(value: YamlValue, text: string): Parsed {\n return { value, length: stripTrailingComment(text).length };\n}\n\n/** Parses a value written on the key's own line. `text` is trimmed and non-empty. */\nexport function parseInline(text: string): YamlValue {\n return readInline(text).value;\n}\n\n/** `text` starts with the value; whitespace after it is allowed. */\nfunction readInline(text: string): Parsed {\n const head = text.charAt(0);\n if (head === '\"' || head === \"'\") {\n const quoted = head === '\"' ? readDoubleQuoted(text) : readSingleQuoted(text);\n if (typeof quoted === 'string') return rough(unsupported(quoted), text);\n return trailingIsComment(text.slice(quoted.next))\n ? { value: { kind: 'scalar', scalar: { text: quoted.text, quoted: true } }, length: quoted.next }\n : rough(unsupported('text follows a closing quote'), text);\n }\n if (head === '[') return parseFlowSequence(text);\n if (head === '{') return rough(unsupported('inline mappings are not supported'), text);\n if (head === '|' || head === '>') return rough(unsupported('block scalars are not supported; keep the value on one line'), text);\n if (head === '&' || head === '*' || head === '!') return rough(unsupported('anchors, aliases and tags are not supported'), text);\n if (head === '@' || head === '`') return rough(unsupported(`a plain value cannot start with \"${head}\"; quote it`), text);\n const plain = stripTrailingComment(text);\n if (/:(?:\\s|$)/.test(plain)) return rough(unsupported('a plain value cannot contain \": \"; quote it'), text);\n if (/^-(?:\\s|$)/.test(plain)) return rough(unsupported('a list must start on the line after its key'), text);\n return { value: { kind: 'scalar', scalar: { text: plain, quoted: false } }, length: plain.length };\n}\n\n/** A comment starts at a `#` after whitespace; a `#` inside a word is text. */\nfunction stripTrailingComment(text: string): string {\n return (text.split(/\\s#/, 1)[0] as string).trim();\n}\n\n/** Nothing after a closing quote or bracket, or whitespace and then a comment. */\nfunction trailingIsComment(rest: string): boolean {\n return /^(?:\\s+(?:#.*)?)?$/.test(rest);\n}\n\ninterface Quoted {\n readonly text: string;\n /** Index just past the closing quote. */\n readonly next: number;\n}\n\nconst ESCAPES: Readonly<Record<string, string>> = {\n '\"': '\"',\n '\\\\': '\\\\',\n '/': '/',\n '0': '\\u0000',\n b: '\\b',\n f: '\\f',\n n: '\\n',\n r: '\\r',\n t: '\\t',\n};\n\nconst HEX_ESCAPE_LENGTH: Readonly<Record<string, number>> = { x: 2, u: 4, U: 8 };\n\n/** Reads a double-quoted scalar starting at index 0, or returns why it cannot. */\nfunction readDoubleQuoted(text: string): Quoted | string {\n let out = '';\n for (let i = 1; ; i += 1) {\n const ch = text.charAt(i);\n if (ch === '') return 'a double-quoted value is never closed';\n if (ch === '\"') return { text: out, next: i + 1 };\n if (ch !== '\\\\') {\n out += ch;\n continue;\n }\n const code = text.charAt(i + 1);\n const simple = ESCAPES[code];\n if (simple !== undefined) {\n out += simple;\n i += 1;\n continue;\n }\n // An escape this reader does not know has no digits to read, and no\n // digits are not a number.\n const width = HEX_ESCAPE_LENGTH[code] ?? 0;\n const hex = text.slice(i + 2, i + 2 + width);\n if (hex.length !== width || !/^[0-9A-Fa-f]+$/.test(hex)) return `\"\\\\${code}\" is not an escape this reader knows`;\n const point = Number.parseInt(hex, 16);\n if (point > 0x10ffff) return `\"\\\\${code}${hex}\" is not a character`;\n out += String.fromCodePoint(point);\n i += 1 + width;\n }\n}\n\nfunction readSingleQuoted(text: string): Quoted | string {\n let out = '';\n for (let i = 1; ; i += 1) {\n const ch = text.charAt(i);\n if (ch === '') return 'a single-quoted value is never closed';\n if (ch !== \"'\") {\n out += ch;\n continue;\n }\n if (text.charAt(i + 1) !== \"'\") return { text: out, next: i + 1 };\n out += \"'\";\n i += 1;\n }\n}\n\n/** The first index at or after `from` that is not whitespace. */\nfunction skipSpace(text: string, from: number): number {\n let i = from;\n while (/\\s/.test(text.charAt(i))) i += 1;\n return i;\n}\n\nfunction parseFlowSequence(text: string): Parsed {\n const items: YamlScalar[] = [];\n const fail = (reason: string): Parsed => rough(unsupported(reason), text);\n let i = 1;\n for (;;) {\n i = skipSpace(text, i);\n const ch = text.charAt(i);\n if (ch === '') return fail('an inline list is never closed; keep it on one line');\n if (ch === ']') {\n return trailingIsComment(text.slice(i + 1))\n ? { value: { kind: 'list', items }, length: i + 1 }\n : fail('text follows the end of an inline list');\n }\n if (ch === '[' || ch === '{') return fail('nested lists and mappings are not supported');\n if (ch === ',') return fail('an inline list has an empty item');\n if (ch === '\"' || ch === \"'\") {\n const rest = text.slice(i);\n const quoted = ch === '\"' ? readDoubleQuoted(rest) : readSingleQuoted(rest);\n if (typeof quoted === 'string') return fail(quoted);\n items.push({ text: quoted.text, quoted: true });\n i += quoted.next;\n } else {\n let j = i;\n // One step past the end reads nothing and slices nothing more, so the\n // bound could be one further and still stop the walk.\n while (j < text.length && text.charAt(j) !== ',' && text.charAt(j) !== ']') j += 1;\n const plain = text.slice(i, j).trim();\n if (/[[{]/.test(plain) || /:(?:\\s|$)/.test(plain) || plain.includes(' #')) {\n return fail(`\"${plain}\" needs quoting inside an inline list`);\n }\n items.push({ text: plain, quoted: false });\n i = j;\n }\n i = skipSpace(text, i);\n // After a comma the next pass reads an item or, legally in YAML, the\n // bracket; at the end of the text it says the list is never closed.\n const next = text.charAt(i);\n if (next === ',') i += 1;\n else if (next !== ']' && next !== '') return fail('inline list items must be separated by commas');\n }\n}\n\n/** Null in the YAML 1.2 core schema: empty, `~` or `null` in any of its three spellings. */\nexport function isNull(scalar: YamlScalar): boolean {\n return !scalar.quoted && ['', '~', 'null', 'Null', 'NULL'].includes(scalar.text);\n}\n\n/**\n * Renders a string as a scalar that reads back as the same string.\n *\n * Plain only as a YAML plain scalar that reads back as itself: a letter\n * first, of any script, then letters, marks, digits, spaces and `._/+-` - so\n * a status of `封存` or `已接受` is written as it is typed - with no space at\n * the end, and none of `true`, `false`, `null`, `yes`, `no`, `on`, `off` or\n * `~` in any case, which YAML 1.2 or 1.1 reads as a boolean or a null.\n * Anything else is quoted: an indicator, `: ` or ` #`, a number, a space at\n * either end, a full-width space or punctuation.\n */\nexport function renderScalar(value: string): string {\n const reserved = /^(?:true|false|null|yes|no|on|off|~)$/i.test(value);\n const plain = /^\\p{L}[\\p{L}\\p{M}\\p{N} ._/+-]*$/u.test(value) && !value.endsWith(' ');\n return plain && !reserved ? value : JSON.stringify(value);\n}\n\nexport function findEntry(frontMatter: FrontMatter | null, key: string): FrontMatterEntry | undefined {\n const name = keyName(key);\n return frontMatter?.entries.find((entry) => entry.name === name);\n}\n\n/**\n * Sets one key, leaving every other line as it was.\n *\n * `lines` are the lines of the text the front matter was read from, as\n * `splitLines` gives them. An existing entry keeps the spelling and the\n * indentation of its key; a new one goes last, at the top level. A text with\n * no front matter gains a block.\n */\nexport function setEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string, rendered: string): string[] {\n if (frontMatter === null) return ['---', `${key}: ${rendered}`, '---', ...lines];\n if (frontMatter.close === -1) throw new Error('cannot edit front matter that is never closed');\n if (frontMatter.kind === 'toml') throw new Error('cannot edit TOML front matter');\n const entry = findEntry(frontMatter, key);\n if (entry === undefined) {\n return [...lines.slice(0, frontMatter.close), `${key}: ${rendered}`, ...lines.slice(frontMatter.close)];\n }\n const written =\n entry.parent === null\n ? `${entry.key}: ${rendered}`\n : `${(lines[entry.line] as string).slice(0, leadIndex(lines[entry.line] as string))}${entry.key.slice(entry.parent.length + 1)}: ${rendered}`;\n return [...lines.slice(0, entry.line), written, ...lines.slice(entry.end)];\n}\n\n/** Removes one key and its value lines; a key that is absent changes nothing. */\nexport function removeEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string): string[] {\n const entry = findEntry(frontMatter, key);\n if (entry === undefined) return [...lines];\n return [...lines.slice(0, entry.line), ...lines.slice(entry.end)];\n}\n"]}
1
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C,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1G,CAAC;IACD,MAAM,OAAO,GACX,KAAK,CAAC,MAAM,KAAK,IAAI;QACnB,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE;QAC7B,CAAC,CAAC,GAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAW,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;IAClJ,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,WAAW,CAAC,KAAwB,EAAE,WAA+B,EAAE,GAAW;IAChG,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["/**\n * A reader and editor for the front matter the spec-* tools use: a flat bag\n * of YAML scalars and lists, and optionally one level of nested mapping.\n *\n * Supported: `key: value` lines; plain, single-quoted and double-quoted\n * scalars; inline `[a, b]` sequences; block `- item` sequences; `#` comments.\n * Plain scalars follow the YAML 1.2 core schema, so `yes` is a word and `035`\n * keeps its leading zero for whoever reads it as text. With `nested`, a key\n * whose value is an indented block of keys is read as `parent.child` entries.\n *\n * Anything richer - deeper nesting, block scalars, anchors, tags, a value\n * continued onto the next line - is recognised and reported as unsupported\n * rather than guessed at. A YAML library would parse more, but it would not\n * give back the line and the offset of every value, and a report has to point\n * at the value it is about, and an edit has to leave every other line of the\n * file as it was.\n */\n\nimport { lineStarts, splitLines, stripBom } from '../text/index.js';\nimport { leadIndex } from './syntax.js';\nimport type { FrontMatterKind } from './types.js';\n\nexport interface YamlScalar {\n readonly text: string;\n readonly quoted: boolean;\n}\n\nexport type YamlValue =\n | { readonly kind: 'scalar'; readonly scalar: YamlScalar }\n | { readonly kind: 'list'; readonly items: readonly YamlScalar[] }\n | { readonly kind: 'unsupported'; readonly reason: string };\n\nexport interface FrontMatterEntry {\n /** The key as written; a nested key is its parent's and its own, joined by a dot. */\n readonly key: string;\n /** The key compared: {@link keyName} of `key`, so `depends-on` is `dependsOn`. */\n readonly name: string;\n /** The parent key as written, for a nested key; `null` at the top level. */\n readonly parent: string | null;\n /** 0-based line of the key. */\n readonly line: number;\n /** 0-based line after the entry's last line. */\n readonly end: number;\n /** Offset of the key in the text read. */\n readonly keyStart: number;\n /**\n * Offsets of the value as written: a quoted scalar with its quotes, an\n * inline list with its brackets, a block list from its first item's text to\n * its last item's. An empty value is the empty range just past the colon.\n */\n readonly valueStart: number;\n readonly valueEnd: number;\n readonly value: YamlValue;\n}\n\nexport interface FrontMatterProblem {\n /** 0-based line. */\n readonly line: number;\n readonly message: string;\n}\n\nexport interface FrontMatter {\n readonly kind: FrontMatterKind;\n /** 0-based line of the closing delimiter, or -1 when the block is never closed. */\n readonly close: number;\n readonly entries: readonly FrontMatterEntry[];\n readonly problems: readonly FrontMatterProblem[];\n}\n\nexport interface ReadOptions {\n /**\n * Read one level of nested mapping as `parent.child` entries, instead of\n * reporting the parent's value as unsupported.\n */\n readonly nested?: boolean;\n}\n\nconst YAML_OPEN = /^---[ \\t]*$/;\nconst YAML_CLOSE = /^(?:---|\\.\\.\\.)[ \\t]*$/;\nconst TOML_FENCE = /^\\+\\+\\+[ \\t]*$/;\n\n/** The kind of front matter a document's first line opens, or `null` when it opens none. */\nexport function frontMatterKind(firstLine: string): FrontMatterKind | null {\n if (YAML_OPEN.test(firstLine)) return 'yaml';\n return TOML_FENCE.test(firstLine) ? 'toml' : null;\n}\n\n/** Whether a line closes front matter of a kind: `---` or `...` for YAML, `+++` for TOML. */\nexport function frontMatterCloses(line: string, kind: FrontMatterKind): boolean {\n return (kind === 'yaml' ? YAML_CLOSE : TOML_FENCE).test(line);\n}\n\n/**\n * A key and what follows its colon. A key is a word of any script, as a YAML\n * plain key may be: a letter or `_` first, then letters, marks, digits and\n * `_.-`, so `狀態` and `状态` are keys as `status` is. Nothing else is one: a\n * digit or a mark first, a space, punctuation, and a full-width colon, which\n * YAML does not read as one.\n */\nconst KEY = /^([\\p{L}_][\\p{L}\\p{M}\\p{N}_.-]*)[ \\t]*:(?:[ \\t]+(.*))?$/u;\nconst SEQUENCE_ITEM = /^([ \\t]*)-(?:[ \\t]+(.*))?$/;\nconst BLANK_OR_COMMENT = /^[ \\t]*(?:#.*)?$/;\n\nexport function keyName(key: string): string {\n return key.toLowerCase().replace(/[-_]/g, '');\n}\n\n/**\n * Reads the front matter at the top of a text, or `null` when there is none.\n *\n * A leading byte-order mark is not part of the text read: offsets count from\n * the character after it, as a scan's do.\n */\nexport function readFrontMatter(source: string, options: ReadOptions = {}): FrontMatter | null {\n const text = stripBom(source);\n const lines = splitLines(text);\n const kind = frontMatterKind(lines[0] as string);\n if (kind === null) return null;\n const close = lines.findIndex((line, i) => i > 0 && frontMatterCloses(line, kind));\n if (close === -1) {\n return { kind, close, entries: [], problems: [{ line: 0, message: 'the front matter opened on line 1 is never closed' }] };\n }\n if (kind === 'toml') {\n return { kind, close, entries: [], problems: [{ line: 0, message: 'TOML front matter is not read; write YAML between \"---\" lines' }] };\n }\n\n const reader: Reader = {\n lines,\n starts: lineStarts(text),\n nested: options.nested === true,\n entries: [],\n problems: [],\n seen: new Map(),\n };\n let i = 1;\n while (i < close) {\n const line = lines[i] as string;\n if (BLANK_OR_COMMENT.test(line)) {\n i += 1;\n continue;\n }\n const match = KEY.exec(line);\n if (match === null) {\n reader.problems.push({\n line: i,\n message: /^\\s/.test(line) ? 'an indented line belongs to no key' : 'not a \"key: value\" line',\n });\n i += 1;\n continue;\n }\n // The closing delimiter belongs to no value, so the block stops there.\n let end = i + 1;\n while (belongsToBlock(lines[end] as string)) end += 1;\n end = trimBlock(lines, end);\n readEntry(reader, { key: match[1] as string, parent: null, line: i, column: 0, inline: match[2] ?? '', end });\n i = end;\n }\n return { kind, close, entries: reader.entries, problems: reader.problems };\n}\n\ninterface Reader {\n readonly lines: readonly string[];\n readonly starts: readonly number[];\n readonly nested: boolean;\n readonly entries: FrontMatterEntry[];\n readonly problems: FrontMatterProblem[];\n readonly seen: Map<string, number>;\n}\n\ninterface KeyLine {\n /** The key as written on its line, without a parent. */\n readonly key: string;\n readonly parent: string | null;\n readonly line: number;\n /** Column of the key. */\n readonly column: number;\n /** What follows the colon and its whitespace, as written. */\n readonly inline: string;\n /** 0-based line after the key's value. */\n readonly end: number;\n}\n\n/** A line under a top-level key is part of its value when it is indented or starts a sequence item. */\nfunction belongsToBlock(line: string): boolean {\n return /^[ \\t]/.test(line) || /^-(?:[ \\t]|$)/.test(line) || line.trim() === '';\n}\n\n/**\n * Takes trailing blank and comment lines off a value's block: they belong to\n * no key. The key's own line is neither, so the walk stops there at the latest.\n */\nfunction trimBlock(lines: readonly string[], end: number): number {\n let at = end;\n while (BLANK_OR_COMMENT.test(lines[at - 1]!)) at -= 1;\n return at;\n}\n\nfunction note(reader: Reader, key: string, line: number): string {\n const name = keyName(key);\n const previous = reader.seen.get(name);\n if (previous === undefined) reader.seen.set(name, line);\n else reader.problems.push({ line, message: `\"${key}\" is declared twice (first on line ${previous + 1})` });\n return name;\n}\n\nfunction readEntry(reader: Reader, at: KeyLine): void {\n const { lines, starts } = reader;\n const text = lines[at.line] as string;\n const lineStart = starts[at.line] as number;\n const key = at.parent === null ? at.key : `${at.parent}.${at.key}`;\n // A key holds no colon and nothing before it does, so the first is its own.\n const colon = lineStart + text.indexOf(':') + 1;\n // What follows the colon starts after its whitespace; what ends it is\n // trimmed by whichever reader takes it.\n const inline = stripLeadingComment(at.inline);\n\n let read: Read;\n if (inline.length > 0) {\n const valueStart = lineStart + text.length - at.inline.length;\n const continued = contentLines(lines, at.line + 1, at.end).length > 0;\n const parsed = continued\n ? rough(unsupported('the value continues on the next line; keep it on one line, or quote it'), inline)\n : readInline(inline);\n read = { value: parsed.value, valueStart, valueEnd: valueStart + parsed.length };\n } else {\n const content = contentLines(lines, at.line + 1, at.end);\n const first = content[0];\n if (first !== undefined && at.parent === null && reader.nested && KEY.test((lines[first] as string).trim())) {\n note(reader, at.key, at.line);\n readChildren(reader, at.key, at.line + 1, at.end);\n return;\n }\n read = readBlock(reader, content, colon, at.parent === null);\n }\n\n reader.entries.push({\n key,\n name: note(reader, key, at.line),\n parent: at.parent,\n line: at.line,\n end: at.end,\n keyStart: lineStart + at.column,\n ...read,\n });\n}\n\n/** One level of keys under a parent, all at the indentation of the first. */\nfunction readChildren(reader: Reader, parent: string, from: number, end: number): void {\n const { lines } = reader;\n const first = lines[contentLines(lines, from, end)[0] as number] as string;\n const lead = first.slice(0, leadIndex(first));\n let i = from;\n while (i < end) {\n const line = lines[i] as string;\n if (BLANK_OR_COMMENT.test(line)) {\n i += 1;\n continue;\n }\n // A line deeper than the keys is always taken by the key above it, so only\n // one at their indentation or shallower reaches here.\n const match = line.startsWith(lead) ? KEY.exec(line.slice(lead.length)) : null;\n if (match === null) {\n reader.problems.push({ line: i, message: 'not a \"key: value\" line at the indentation of the keys before it' });\n i += 1;\n continue;\n }\n // Past the parent's value, a line belongs to a child only when it is blank\n // or a comment, and those are trimmed off again.\n let childEnd = i + 1;\n while (belongsToChild(lines[childEnd] as string, lead)) childEnd += 1;\n childEnd = trimBlock(lines, childEnd);\n readEntry(reader, { key: match[1] as string, parent, line: i, column: lead.length, inline: match[2] ?? '', end: childEnd });\n i = childEnd;\n }\n}\n\n/** A line under a nested key is part of its value when it is deeper, or a sequence item at the key's indentation. */\nfunction belongsToChild(line: string, lead: string): boolean {\n if (line.trim() === '') return true;\n if (!line.startsWith(lead)) return false;\n return /^(?:[ \\t]|-(?:[ \\t]|$))/.test(line.slice(lead.length));\n}\n\ninterface Read {\n readonly value: YamlValue;\n readonly valueStart: number;\n readonly valueEnd: number;\n}\n\n/** Indices of the lines in a range that are neither blank nor a comment. */\nfunction contentLines(lines: readonly string[], from: number, end: number): number[] {\n const out: number[] = [];\n for (let i = from; i < end; i += 1) if (!BLANK_OR_COMMENT.test(lines[i] as string)) out.push(i);\n return out;\n}\n\n/** A value written on the lines under its key. */\nfunction readBlock(reader: Reader, content: readonly number[], colon: number, topLevel: boolean): Read {\n const { lines, starts } = reader;\n const first = content[0];\n if (first === undefined) return { value: { kind: 'scalar', scalar: { text: '', quoted: false } }, valueStart: colon, valueEnd: colon };\n\n // An unsupported block is reported over all of its content lines.\n const firstText = lines[first] as string;\n const last = content[content.length - 1]!;\n const whole = (value: YamlValue): Read => ({\n value,\n valueStart: (starts[first] as number) + leadIndex(firstText),\n valueEnd: (starts[last] as number) + (lines[last] as string).trimEnd().length,\n });\n\n const head = SEQUENCE_ITEM.exec(firstText);\n if (head === null) {\n // Quoting a list would make it a string, so a list gets its own advice.\n if (firstText.trim().startsWith('[')) return whole(unsupported('an inline list starts on the line after its key; write it after the colon'));\n if (!KEY.test(firstText.trim())) return whole(unsupported('the value continues on the next line; keep it on one line, or quote it'));\n return whole(\n unsupported(topLevel ? 'nested mappings are not supported; flatten the key' : 'only one level of nesting is read; flatten the key'),\n );\n }\n const indent = (head[1] as string).length;\n const items: YamlScalar[] = [];\n const spans: [number, number][] = [];\n for (const index of content) {\n const line = lines[index] as string;\n const item = SEQUENCE_ITEM.exec(line);\n if (item === null || (item[1] as string).length !== indent) {\n return whole(unsupported('a list item is continued or nested; keep each item on one line'));\n }\n // The item's text starts after its whitespace, as a key's value does.\n const written = item[2] ?? '';\n const text = stripLeadingComment(written);\n if (text.length === 0) return whole(unsupported('a list item is empty'));\n const parsed = readInline(text);\n if (parsed.value.kind !== 'scalar') {\n return whole(parsed.value.kind === 'list' ? unsupported('nested lists are not supported') : parsed.value);\n }\n const start = (starts[index] as number) + line.length - written.length;\n spans.push([start, start + parsed.length]);\n items.push(parsed.value.scalar);\n }\n return { value: { kind: 'list', items }, valueStart: (spans[0] as [number, number])[0], valueEnd: spans[spans.length - 1]![1] };\n}\n\nfunction stripLeadingComment(text: string): string {\n return text.startsWith('#') ? '' : text;\n}\n\nfunction unsupported(reason: string): YamlValue {\n return { kind: 'unsupported', reason };\n}\n\ninterface Parsed {\n readonly value: YamlValue;\n /** Characters of the text the value spans. */\n readonly length: number;\n}\n\n/** An unsupported value spans its text up to any comment. */\nfunction rough(value: YamlValue, text: string): Parsed {\n return { value, length: stripTrailingComment(text).length };\n}\n\n/** Parses a value written on the key's own line. `text` is trimmed and non-empty. */\nexport function parseInline(text: string): YamlValue {\n return readInline(text).value;\n}\n\n/** `text` starts with the value; whitespace after it is allowed. */\nfunction readInline(text: string): Parsed {\n const head = text.charAt(0);\n if (head === '\"' || head === \"'\") {\n const quoted = head === '\"' ? readDoubleQuoted(text) : readSingleQuoted(text);\n if (typeof quoted === 'string') return rough(unsupported(quoted), text);\n return trailingIsComment(text.slice(quoted.next))\n ? { value: { kind: 'scalar', scalar: { text: quoted.text, quoted: true } }, length: quoted.next }\n : rough(unsupported('text follows a closing quote'), text);\n }\n if (head === '[') return parseFlowSequence(text);\n if (head === '{') return rough(unsupported('inline mappings are not supported'), text);\n if (head === '|' || head === '>') return rough(unsupported('block scalars are not supported; keep the value on one line'), text);\n if (head === '&' || head === '*' || head === '!') return rough(unsupported('anchors, aliases and tags are not supported'), text);\n if (head === '@' || head === '`') return rough(unsupported(`a plain value cannot start with \"${head}\"; quote it`), text);\n const plain = stripTrailingComment(text);\n if (/:(?:\\s|$)/.test(plain)) return rough(unsupported('a plain value cannot contain \": \"; quote it'), text);\n if (/^-(?:\\s|$)/.test(plain)) return rough(unsupported('a list must start on the line after its key'), text);\n return { value: { kind: 'scalar', scalar: { text: plain, quoted: false } }, length: plain.length };\n}\n\n/** A comment starts at a `#` after whitespace; a `#` inside a word is text. */\nfunction stripTrailingComment(text: string): string {\n return text.split(/\\s#/, 1)[0]!.trim();\n}\n\n/** Nothing after a closing quote or bracket, or whitespace and then a comment. */\nfunction trailingIsComment(rest: string): boolean {\n return /^(?:\\s+(?:#.*)?)?$/.test(rest);\n}\n\ninterface Quoted {\n readonly text: string;\n /** Index just past the closing quote. */\n readonly next: number;\n}\n\nconst ESCAPES: Readonly<Record<string, string>> = {\n '\"': '\"',\n '\\\\': '\\\\',\n '/': '/',\n '0': '\\u0000',\n b: '\\b',\n f: '\\f',\n n: '\\n',\n r: '\\r',\n t: '\\t',\n};\n\nconst HEX_ESCAPE_LENGTH: Readonly<Record<string, number>> = { x: 2, u: 4, U: 8 };\n\n/** Reads a double-quoted scalar starting at index 0, or returns why it cannot. */\nfunction readDoubleQuoted(text: string): Quoted | string {\n let out = '';\n for (let i = 1; ; i += 1) {\n const ch = text.charAt(i);\n if (ch === '') return 'a double-quoted value is never closed';\n if (ch === '\"') return { text: out, next: i + 1 };\n if (ch !== '\\\\') {\n out += ch;\n continue;\n }\n const code = text.charAt(i + 1);\n const simple = ESCAPES[code];\n if (simple !== undefined) {\n out += simple;\n i += 1;\n continue;\n }\n // An escape this reader does not know has no digits to read, and no\n // digits are not a number.\n const width = HEX_ESCAPE_LENGTH[code] ?? 0;\n const hex = text.slice(i + 2, i + 2 + width);\n if (hex.length !== width || !/^[0-9A-Fa-f]+$/.test(hex)) return `\"\\\\${code}\" is not an escape this reader knows`;\n const point = Number.parseInt(hex, 16);\n if (point > 0x10ffff) return `\"\\\\${code}${hex}\" is not a character`;\n out += String.fromCodePoint(point);\n i += 1 + width;\n }\n}\n\nfunction readSingleQuoted(text: string): Quoted | string {\n let out = '';\n for (let i = 1; ; i += 1) {\n const ch = text.charAt(i);\n if (ch === '') return 'a single-quoted value is never closed';\n if (ch !== \"'\") {\n out += ch;\n continue;\n }\n if (text.charAt(i + 1) !== \"'\") return { text: out, next: i + 1 };\n out += \"'\";\n i += 1;\n }\n}\n\n/** The first index at or after `from` that is not whitespace. */\nfunction skipSpace(text: string, from: number): number {\n let i = from;\n while (/\\s/.test(text.charAt(i))) i += 1;\n return i;\n}\n\nfunction parseFlowSequence(text: string): Parsed {\n const items: YamlScalar[] = [];\n const fail = (reason: string): Parsed => rough(unsupported(reason), text);\n let i = 1;\n for (;;) {\n i = skipSpace(text, i);\n const ch = text.charAt(i);\n if (ch === '') return fail('an inline list is never closed; keep it on one line');\n if (ch === ']') {\n return trailingIsComment(text.slice(i + 1))\n ? { value: { kind: 'list', items }, length: i + 1 }\n : fail('text follows the end of an inline list');\n }\n if (ch === '[' || ch === '{') return fail('nested lists and mappings are not supported');\n if (ch === ',') return fail('an inline list has an empty item');\n if (ch === '\"' || ch === \"'\") {\n const rest = text.slice(i);\n const quoted = ch === '\"' ? readDoubleQuoted(rest) : readSingleQuoted(rest);\n if (typeof quoted === 'string') return fail(quoted);\n items.push({ text: quoted.text, quoted: true });\n i += quoted.next;\n } else {\n let j = i;\n // One step past the end reads nothing and slices nothing more, so the\n // bound could be one further and still stop the walk.\n while (j < text.length && text.charAt(j) !== ',' && text.charAt(j) !== ']') j += 1;\n const plain = text.slice(i, j).trim();\n if (/[[{]/.test(plain) || /:(?:\\s|$)/.test(plain) || plain.includes(' #')) {\n return fail(`\"${plain}\" needs quoting inside an inline list`);\n }\n items.push({ text: plain, quoted: false });\n i = j;\n }\n i = skipSpace(text, i);\n // After a comma the next pass reads an item or, legally in YAML, the\n // bracket; at the end of the text it says the list is never closed.\n const next = text.charAt(i);\n if (next === ',') i += 1;\n else if (next !== ']' && next !== '') return fail('inline list items must be separated by commas');\n }\n}\n\n/** Null in the YAML 1.2 core schema: empty, `~` or `null` in any of its three spellings. */\nexport function isNull(scalar: YamlScalar): boolean {\n return !scalar.quoted && ['', '~', 'null', 'Null', 'NULL'].includes(scalar.text);\n}\n\n/**\n * Renders a string as a scalar that reads back as the same string.\n *\n * Plain only as a YAML plain scalar that reads back as itself: a letter\n * first, of any script, then letters, marks, digits, spaces and `._/+-` - so\n * a status of `封存` or `已接受` is written as it is typed - with no space at\n * the end, and none of `true`, `false`, `null`, `yes`, `no`, `on`, `off` or\n * `~` in any case, which YAML 1.2 or 1.1 reads as a boolean or a null.\n * Anything else is quoted: an indicator, `: ` or ` #`, a number, a space at\n * either end, a full-width space or punctuation.\n */\nexport function renderScalar(value: string): string {\n const reserved = /^(?:true|false|null|yes|no|on|off|~)$/i.test(value);\n const plain = /^\\p{L}[\\p{L}\\p{M}\\p{N} ._/+-]*$/u.test(value) && !value.endsWith(' ');\n return plain && !reserved ? value : JSON.stringify(value);\n}\n\nexport function findEntry(frontMatter: FrontMatter | null, key: string): FrontMatterEntry | undefined {\n const name = keyName(key);\n return frontMatter?.entries.find((entry) => entry.name === name);\n}\n\n/**\n * Sets one key, leaving every other line as it was.\n *\n * `lines` are the lines of the text the front matter was read from, as\n * `splitLines` gives them. An existing entry keeps the spelling and the\n * indentation of its key; a new one goes last, at the top level. A text with\n * no front matter gains a block.\n */\nexport function setEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string, rendered: string): string[] {\n if (frontMatter === null) return ['---', `${key}: ${rendered}`, '---', ...lines];\n if (frontMatter.close === -1) throw new Error('cannot edit front matter that is never closed');\n if (frontMatter.kind === 'toml') throw new Error('cannot edit TOML front matter');\n const entry = findEntry(frontMatter, key);\n if (entry === undefined) {\n return [...lines.slice(0, frontMatter.close), `${key}: ${rendered}`, ...lines.slice(frontMatter.close)];\n }\n const written =\n entry.parent === null\n ? `${entry.key}: ${rendered}`\n : `${(lines[entry.line] as string).slice(0, leadIndex(lines[entry.line] as string))}${entry.key.slice(entry.parent.length + 1)}: ${rendered}`;\n return [...lines.slice(0, entry.line), written, ...lines.slice(entry.end)];\n}\n\n/** Removes one key and its value lines; a key that is absent changes nothing. */\nexport function removeEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string): string[] {\n const entry = findEntry(frontMatter, key);\n if (entry === undefined) return [...lines];\n return [...lines.slice(0, entry.line), ...lines.slice(entry.end)];\n}\n"]}