@descent-vtt/spec-brief 0.1.0 → 0.2.1

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 (128) hide show
  1. package/CHANGELOG.md +301 -0
  2. package/README.md +92 -22
  3. package/dist/archive.d.ts +52 -2
  4. package/dist/archive.js +205 -37
  5. package/dist/archive.js.map +1 -1
  6. package/dist/brief.d.ts +2 -0
  7. package/dist/brief.js +5 -1
  8. package/dist/brief.js.map +1 -1
  9. package/dist/cli.d.ts +1 -1
  10. package/dist/cli.js +48 -14
  11. package/dist/cli.js.map +1 -1
  12. package/dist/collisions.d.ts +43 -12
  13. package/dist/collisions.js +90 -58
  14. package/dist/collisions.js.map +1 -1
  15. package/dist/config.d.ts +18 -0
  16. package/dist/config.js +66 -11
  17. package/dist/config.js.map +1 -1
  18. package/dist/corpus.d.ts +21 -1
  19. package/dist/corpus.js +51 -2
  20. package/dist/corpus.js.map +1 -1
  21. package/dist/engine.d.ts +33 -3
  22. package/dist/engine.js +112 -9
  23. package/dist/engine.js.map +1 -1
  24. package/dist/frontmatter.d.ts +18 -61
  25. package/dist/frontmatter.js +31 -300
  26. package/dist/frontmatter.js.map +1 -1
  27. package/dist/glob.d.ts +77 -54
  28. package/dist/glob.js +104 -433
  29. package/dist/glob.js.map +1 -1
  30. package/dist/index.d.ts +10 -8
  31. package/dist/index.js +8 -6
  32. package/dist/index.js.map +1 -1
  33. package/dist/links.d.ts +1 -1
  34. package/dist/links.js +3 -4
  35. package/dist/links.js.map +1 -1
  36. package/dist/lint.d.ts +33 -2
  37. package/dist/lint.js +9 -2
  38. package/dist/lint.js.map +1 -1
  39. package/dist/markdown.d.ts +27 -23
  40. package/dist/markdown.js +66 -235
  41. package/dist/markdown.js.map +1 -1
  42. package/dist/plugins.d.ts +14 -0
  43. package/dist/plugins.js +142 -6
  44. package/dist/plugins.js.map +1 -1
  45. package/dist/report.d.ts +40 -3
  46. package/dist/report.js +227 -11
  47. package/dist/report.js.map +1 -1
  48. package/dist/rules.d.ts +22 -4
  49. package/dist/rules.js +175 -45
  50. package/dist/rules.js.map +1 -1
  51. package/dist/scaffold.d.ts +1 -1
  52. package/dist/scaffold.js +10 -9
  53. package/dist/scaffold.js.map +1 -1
  54. package/dist/schedule.d.ts +133 -0
  55. package/dist/schedule.js +265 -0
  56. package/dist/schedule.js.map +1 -0
  57. package/dist/scope.d.ts +52 -0
  58. package/dist/scope.js +56 -0
  59. package/dist/scope.js.map +1 -0
  60. package/dist/text.d.ts +13 -0
  61. package/dist/text.js +23 -0
  62. package/dist/text.js.map +1 -1
  63. package/dist/trigger.d.ts +17 -0
  64. package/dist/trigger.js +49 -0
  65. package/dist/trigger.js.map +1 -0
  66. package/dist/types.d.ts +14 -5
  67. package/dist/types.js.map +1 -1
  68. package/dist/vendor/spec-core/markdown/frontmatter.d.ts +103 -0
  69. package/dist/vendor/spec-core/markdown/frontmatter.js +459 -0
  70. package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -0
  71. package/dist/vendor/spec-core/markdown/headings.d.ts +45 -0
  72. package/dist/vendor/spec-core/markdown/headings.js +199 -0
  73. package/dist/vendor/spec-core/markdown/headings.js.map +1 -0
  74. package/dist/vendor/spec-core/markdown/index.d.ts +5 -0
  75. package/dist/vendor/spec-core/markdown/index.js +4 -0
  76. package/dist/vendor/spec-core/markdown/index.js.map +1 -0
  77. package/dist/vendor/spec-core/markdown/layout.d.ts +39 -0
  78. package/dist/vendor/spec-core/markdown/layout.js +28 -0
  79. package/dist/vendor/spec-core/markdown/layout.js.map +1 -0
  80. package/dist/vendor/spec-core/markdown/links.d.ts +25 -0
  81. package/dist/vendor/spec-core/markdown/links.js +394 -0
  82. package/dist/vendor/spec-core/markdown/links.js.map +1 -0
  83. package/dist/vendor/spec-core/markdown/lists.d.ts +22 -0
  84. package/dist/vendor/spec-core/markdown/lists.js +127 -0
  85. package/dist/vendor/spec-core/markdown/lists.js.map +1 -0
  86. package/dist/vendor/spec-core/markdown/scan.d.ts +36 -0
  87. package/dist/vendor/spec-core/markdown/scan.js +463 -0
  88. package/dist/vendor/spec-core/markdown/scan.js.map +1 -0
  89. package/dist/vendor/spec-core/markdown/syntax.d.ts +75 -0
  90. package/dist/vendor/spec-core/markdown/syntax.js +181 -0
  91. package/dist/vendor/spec-core/markdown/syntax.js.map +1 -0
  92. package/dist/vendor/spec-core/markdown/tables.d.ts +18 -0
  93. package/dist/vendor/spec-core/markdown/tables.js +86 -0
  94. package/dist/vendor/spec-core/markdown/tables.js.map +1 -0
  95. package/dist/vendor/spec-core/markdown/types.d.ts +290 -0
  96. package/dist/vendor/spec-core/markdown/types.js +9 -0
  97. package/dist/vendor/spec-core/markdown/types.js.map +1 -0
  98. package/dist/vendor/spec-core/path/index.d.ts +1 -0
  99. package/dist/vendor/spec-core/path/index.js +2 -0
  100. package/dist/vendor/spec-core/path/index.js.map +1 -0
  101. package/dist/vendor/spec-core/path/posix.d.ts +83 -0
  102. package/dist/vendor/spec-core/path/posix.js +150 -0
  103. package/dist/vendor/spec-core/path/posix.js.map +1 -0
  104. package/dist/vendor/spec-core/pattern/automaton.d.ts +129 -0
  105. package/dist/vendor/spec-core/pattern/automaton.js +340 -0
  106. package/dist/vendor/spec-core/pattern/automaton.js.map +1 -0
  107. package/dist/vendor/spec-core/pattern/charset.d.ts +58 -0
  108. package/dist/vendor/spec-core/pattern/charset.js +116 -0
  109. package/dist/vendor/spec-core/pattern/charset.js.map +1 -0
  110. package/dist/vendor/spec-core/pattern/glob.d.ts +121 -0
  111. package/dist/vendor/spec-core/pattern/glob.js +481 -0
  112. package/dist/vendor/spec-core/pattern/glob.js.map +1 -0
  113. package/dist/vendor/spec-core/pattern/index.d.ts +6 -0
  114. package/dist/vendor/spec-core/pattern/index.js +4 -0
  115. package/dist/vendor/spec-core/pattern/index.js.map +1 -0
  116. package/dist/vendor/spec-core/pattern/regex.d.ts +67 -0
  117. package/dist/vendor/spec-core/pattern/regex.js +813 -0
  118. package/dist/vendor/spec-core/pattern/regex.js.map +1 -0
  119. package/dist/vendor/spec-core/text/index.d.ts +2 -0
  120. package/dist/vendor/spec-core/text/index.js +2 -0
  121. package/dist/vendor/spec-core/text/index.js.map +1 -0
  122. package/dist/vendor/spec-core/text/lines.d.ts +72 -0
  123. package/dist/vendor/spec-core/text/lines.js +156 -0
  124. package/dist/vendor/spec-core/text/lines.js.map +1 -0
  125. package/package.json +4 -3
  126. package/schema.json +17 -0
  127. package/src/vendor/spec-core/LICENSE +21 -0
  128. package/src/vendor/spec-core/README.md +8 -0
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAa,aAAa,EAAoB,MAAM,cAAc,CAAC;AAEvF,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAA+C,MAAM,iBAAiB,CAAC;AAC7G,OAAO,EAAe,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,WAAW,EAAe,UAAU,EAAE,OAAO,EAAE,mBAAmB,EAAmB,MAAM,aAAa,CAAC;AAClH,OAAO,EAAE,aAAa,EAAmB,cAAc,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAA8C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAe,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,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AAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["/**\n * The engine: one repository's briefs, with the operations the CLI offers and\n * the same ones for a harness or an orchestrator that would rather call a\n * function than parse a terminal.\n *\n * This module and the CLI are where the pieces meet their implementations -\n * the real filesystem, the real git, the plugins a configuration names.\n * Everything they compose is a pure function that takes those as arguments,\n * so an engine can equally run over a `MemoryFileSystem` and no git at all.\n */\n\nimport { access } from 'node:fs/promises';\nimport { dirname, relative, resolve, sep } from 'node:path';\n\nimport { applyPlan } from './apply.js';\nimport { planArchive, type Plan, planUnarchive, type PullRequest } from './archive.js';\nimport type { Brief } from './brief.js';\nimport { collisionFindings, collisions, type CollisionOptions, type CollisionReport } from './collisions.js';\nimport { type Config, DEFAULT_CONFIG, locateConfig, parseConfig } from './config.js';\nimport { buildCorpus, type Corpus, findBriefs, isReady, pendingDependencies, type SourceFile } from './corpus.js';\nimport { canonicalPath, type FileSystem, NodeFileSystem } from './fs.js';\nimport { type CommitInfo, type FileChange, type Git, NodeGit, pullRequestUrl } from './git.js';\nimport { matchGlob, parseGlob } from './glob.js';\nimport { normalisePath } from './links.js';\nimport { lint, type Plugin } from './lint.js';\nimport { loadPlugins } from './plugins.js';\nimport { fileNameFor, nextId, renderNewBrief } from './scaffold.js';\nimport type { Finding, Phase } from './types.js';\n\nexport class EngineError extends Error {\n readonly code: 'not-found' | 'ambiguous' | 'invalid' | 'refused' | 'exists';\n\n constructor(code: EngineError['code'], message: string) {\n super(message);\n this.name = 'EngineError';\n this.code = code;\n }\n}\n\nexport interface EngineSetup {\n /** Absolute root: the directory holding the configuration. */\n readonly root: string;\n readonly config: Config;\n /** Repository-relative configuration path, or `null` when the defaults apply. */\n readonly configFile: string | null;\n readonly fs: FileSystem;\n readonly git: Git | null;\n readonly plugins?: readonly Plugin[];\n}\n\nexport interface OpenOptions {\n /** Where discovery starts. Defaults to the process's directory. */\n readonly cwd?: string;\n /** An explicit configuration file; discovery is skipped. */\n readonly config?: string;\n /** Use the defaults even where a configuration file exists. */\n readonly noConfig?: boolean;\n /** `null` runs without git. Defaults to git when the root is inside a working tree. */\n readonly git?: Git | null;\n readonly fs?: FileSystem;\n}\n\nexport interface ArchiveOptions {\n readonly pr?: number | undefined;\n /** The commit the round landed as. */\n readonly commit?: string | undefined;\n /** The branch the round started from; the diff runs from its merge base. */\n readonly base?: string | undefined;\n readonly summary?: string | undefined;\n readonly date?: string | undefined;\n readonly allowDirty?: boolean | undefined;\n readonly strict?: boolean | undefined;\n /** Leave git out, even where there is a repository. */\n readonly noGit?: boolean | undefined;\n}\n\nexport interface NewOptions {\n readonly title: string;\n readonly id?: string | undefined;\n readonly type?: string | undefined;\n readonly wave?: number | undefined;\n readonly dependsOn?: readonly string[] | undefined;\n readonly date?: string | undefined;\n}\n\nasync function exists(path: string): Promise<boolean> {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Today, in UTC. `SOURCE_DATE_EPOCH` wins where it is set, which is what makes\n * a banner written in a reproducible pipeline reproducible.\n */\nexport function today(env: Readonly<Record<string, string | undefined>> = process.env): string {\n const epoch = env['SOURCE_DATE_EPOCH'];\n const when = epoch !== undefined && /^\\d+$/.test(epoch) ? new Date(Number(epoch) * 1000) : new Date();\n return when.toISOString().slice(0, 10);\n}\n\nexport function isDate(text: string): boolean {\n if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(text)) return false;\n const parsed = new Date(`${text}T00:00:00Z`);\n return !Number.isNaN(parsed.getTime()) && parsed.toISOString().slice(0, 10) === text;\n}\n\nexport class BriefEngine {\n readonly root: string;\n readonly config: Config;\n readonly configFile: string | null;\n readonly fs: FileSystem;\n readonly git: Git | null;\n private plugins: readonly Plugin[] | undefined;\n private loaded: Corpus | undefined;\n private missingBriefs = false;\n\n constructor(setup: EngineSetup) {\n this.root = setup.root;\n this.config = setup.config;\n this.configFile = setup.configFile;\n this.fs = setup.fs;\n this.git = setup.git;\n this.plugins = setup.plugins;\n }\n\n /**\n * Finds the configuration, the root it defines and the repository around it,\n * and reads every brief. The root is the directory holding the\n * configuration; without one it is the working tree's top, or `cwd`.\n */\n static async open(options: OpenOptions = {}): Promise<BriefEngine> {\n // Named as git names them, so the root and the work tree compare.\n const cwd = await canonicalPath(resolve(options.cwd ?? process.cwd()));\n const explicit = options.config === undefined ? undefined : await canonicalPath(resolve(cwd, options.config));\n const configPath = options.noConfig === true ? undefined : (explicit ?? (await locateConfig(cwd, exists)));\n // Asking git costs a process; without git there is nothing to ask.\n const toplevel = options.git === null ? null : await NodeGit.toplevel(cwd);\n const root = configPath === undefined ? (toplevel ?? cwd) : dirname(configPath);\n let config = DEFAULT_CONFIG;\n if (configPath !== undefined) {\n const fs = new NodeFileSystem(dirname(configPath));\n const name = configPath.slice(dirname(configPath).length + 1);\n const text = await fs.read(name);\n if (text === null) throw new EngineError('not-found', `${configPath} does not exist`);\n config = parseConfig(text, relative(cwd, configPath));\n }\n const inTree = toplevel !== null && !relative(toplevel, root).startsWith('..');\n const engine = new BriefEngine({\n root,\n config,\n configFile: configPath === undefined ? null : relative(root, configPath).split(sep).join('/'),\n fs: options.fs ?? new NodeFileSystem(root),\n git: options.git === undefined ? (inTree ? new NodeGit(root) : null) : options.git,\n });\n await engine.load();\n return engine;\n }\n\n get corpus(): Corpus {\n if (this.loaded === undefined) throw new Error('the engine has not loaded its briefs; call load() first');\n return this.loaded;\n }\n\n /** Reads every brief again, as after an archival. */\n async load(): Promise<Corpus> {\n const files: SourceFile[] = [];\n const accept = parseGlob(this.config.files);\n const reject = this.config.exclude.map((pattern) => parseGlob(pattern));\n const isBrief = (name: string): boolean =>\n accept.ok && matchGlob(accept.glob, name) && !reject.some((r) => r.ok && matchGlob(r.glob, name));\n const read = async (directory: string, phase: Phase): Promise<boolean> => {\n const dir = normalisePath(directory);\n const names = await this.fs.list(dir);\n for (const name of names ?? []) {\n if (!isBrief(name)) continue;\n const path = dir === '' ? name : `${dir}/${name}`;\n const text = await this.fs.read(path);\n // A file listed a moment ago and gone now was removed under the run; there is nothing to read.\n /* v8 ignore next */\n if (text !== null) files.push({ path, text, phase });\n }\n return names !== null;\n };\n this.missingBriefs = !(await read(this.config.briefs, 'live'));\n await read(this.config.archive, 'archived');\n this.loaded = buildCorpus(files, this.config);\n return this.loaded;\n }\n\n /**\n * Refuses to report on a briefs directory that does not exist. A check over\n * nothing looks exactly like a clean one, and the likelier cause is a\n * configuration pointing at the wrong place.\n */\n requireBriefs(): void {\n if (this.missingBriefs) {\n throw new EngineError('not-found', `${normalisePath(this.config.briefs)}/ does not exist; run \"spec-brief init\", or set \"briefs\" in the configuration`);\n }\n }\n\n /** The plugins the configuration names, loaded once. */\n async loadedPlugins(): Promise<readonly Plugin[]> {\n this.plugins ??= await loadPlugins(this.config.plugins, this.root);\n return this.plugins;\n }\n\n /** The one brief a reference names: an id, a file name or a path. */\n find(reference: string): Brief {\n const found = findBriefs(this.corpus, reference);\n if (found.length === 0) throw new EngineError('not-found', `no brief is named \"${reference}\"`);\n if (found.length > 1) {\n throw new EngineError('ambiguous', `\"${reference}\" names ${found.length} briefs: ${found.map((b) => b.file).join(', ')}`);\n }\n return found[0] as Brief;\n }\n\n /** The files git sees, or every file when there is no git; `null` when neither can be read. */\n async repoFiles(): Promise<string[] | null> {\n try {\n return this.git === null ? await this.fs.walk() : await this.git.files();\n } catch {\n return null;\n }\n }\n\n async lint(references: readonly string[] = []): Promise<Finding[]> {\n const only = references.length === 0 ? undefined : references.map((r) => this.find(r));\n return lint(this.corpus, { plugins: await this.loadedPlugins(), repoFiles: await this.repoFiles(), ...(only ? { only } : {}) });\n }\n\n async collisions(options: CollisionOptions = {}): Promise<{ report: CollisionReport; findings: Finding[] }> {\n const report = collisions(this.corpus, { repoFiles: await this.repoFiles(), ...options });\n return { report, findings: collisionFindings(this.corpus, report) };\n }\n\n /** Live briefs that can run now: not drafts, every dependency archived. */\n ready(): Brief[] {\n return this.corpus.live.filter((b) => isReady(this.corpus, b));\n }\n\n /** The live dependencies holding a brief back. */\n waitingOn(brief: Brief): string[] {\n return pendingDependencies(this.corpus, brief);\n }\n\n async planArchive(reference: string, options: ArchiveOptions = {}): Promise<Plan> {\n const brief = this.find(reference);\n const date = options.date ?? today();\n if (!isDate(date)) throw new EngineError('invalid', `\"${date}\" is not a date written YYYY-MM-DD`);\n if (options.noGit === true && (options.commit !== undefined || options.base !== undefined)) {\n throw new EngineError('invalid', 'a commit or a base needs git; drop --no-git, or drop --commit and --base');\n }\n const git = options.noGit === true ? null : this.git;\n const base = options.base ?? this.config.archiving.base ?? undefined;\n const findings = await this.lint();\n\n let commit: CommitInfo | undefined;\n let changes: FileChange[] | undefined;\n let dirty: string[] | undefined;\n let pr: PullRequest | undefined;\n if (git !== null) {\n const revision = options.commit ?? (base === undefined ? undefined : 'HEAD');\n if (revision !== undefined) {\n commit = (await git.commit(revision)) ?? undefined;\n if (commit === undefined) throw new EngineError('not-found', `\"${revision}\" names no commit`);\n const from = base === undefined ? null : ((await git.mergeBase(base, commit.sha)) ?? base);\n changes = await git.changes(from, commit.sha);\n }\n dirty = await git.dirty();\n }\n if (options.pr !== undefined) {\n pr = { number: options.pr, url: git === null ? null : pullRequestUrl(await git.remoteUrl('origin'), options.pr) };\n }\n return planArchive(this.corpus, brief, {\n date,\n summary: options.summary,\n pr,\n commit,\n changes,\n dirty,\n allowDirty: options.allowDirty,\n strict: options.strict,\n findings,\n });\n }\n\n planUnarchive(reference: string): Plan {\n return planUnarchive(this.corpus, this.find(reference));\n }\n\n /** Executes a plan and reads the briefs again. A refused plan is never applied. */\n async apply(plan: Plan): Promise<void> {\n if (plan.blocking.length > 0) {\n throw new EngineError('refused', `${plan.action} of ${plan.brief.file} is refused: ${(plan.blocking[0] as Finding).message}`);\n }\n if (plan.done) return;\n await applyPlan(this.fs, plan.ops);\n await this.load();\n }\n\n /** Scaffolds a brief and writes it; the file is new, or nothing is written. */\n async create(options: NewOptions): Promise<{ file: string; content: string }> {\n const title = options.title.trim();\n if (title === '') throw new EngineError('invalid', 'a brief needs a title');\n const id = options.id ?? nextId(this.corpus);\n if (id === null) throw new EngineError('invalid', 'the ids here are not numbers, so there is no next one; pass --id');\n if (/[\\s/\\\\]/.test(id) || id.includes(this.config.id.separator)) {\n throw new EngineError('invalid', `\"${id}\" cannot be an id: no whitespace, slashes or \"${this.config.id.separator}\"`);\n }\n if (findBriefs(this.corpus, id).some((b) => b.id !== null)) throw new EngineError('exists', `the id \"${id}\" is taken`);\n if (options.type !== undefined && this.config.types[options.type] === undefined) {\n const names = Object.keys(this.config.types);\n throw new EngineError('invalid', `\"${options.type}\" is not a brief type here; use one of ${names.join(', ') || '(none)'}`);\n }\n const date = options.date ?? today();\n if (!isDate(date)) throw new EngineError('invalid', `\"${date}\" is not a date written YYYY-MM-DD`);\n const template = this.config.template === null ? null : await this.fs.read(this.config.template);\n if (this.config.template !== null && template === null) {\n throw new EngineError('not-found', `the template ${this.config.template} does not exist`);\n }\n const content = renderNewBrief(\n this.config,\n { id, title, date, type: options.type, wave: options.wave, dependsOn: options.dependsOn },\n template,\n );\n const dir = normalisePath(this.config.briefs);\n const file = `${dir}/${fileNameFor(this.config, id, title)}`;\n if (await this.fs.exists(file)) throw new EngineError('exists', `${file} already exists`);\n await this.fs.write(file, content);\n await this.load();\n return { file, content };\n }\n}\n"]}
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACL,YAAY,EACZ,WAAW,EAEX,aAAa,EAIb,QAAQ,GAET,M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AQ,iBAAiB,CAAC,CAAC;QAC5F,CAAC;QACD,MAAM,OAAO,GAAG,cAAc,CAC5B,IAAI,CAAC,MAAM,EACX,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,EACzF,QAAQ,CACT,CAAC;QACF,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,GAAG,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC;QAC7D,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,WAAW,CAAC,QAAQ,EAAE,GAAG,IAAI,iBAAiB,CAAC,CAAC;QAC1F,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["/**\n * The engine: one repository's briefs, with the operations the CLI offers and\n * the same ones for a harness or an orchestrator that would rather call a\n * function than parse a terminal.\n *\n * This module and the CLI are where the pieces meet their implementations -\n * the real filesystem, the real git, the plugins a configuration names.\n * Everything they compose is a pure function that takes those as arguments,\n * so an engine can equally run over a `MemoryFileSystem` and no git at all.\n */\n\nimport { access } from 'node:fs/promises';\nimport { dirname, relative, resolve, sep } from 'node:path';\n\nimport { applyPlan } from './apply.js';\nimport {\n applyWaivers,\n planArchive,\n type Plan,\n planUnarchive,\n type PullRequest,\n type UnarchiveRequest,\n type Unmeasured,\n WAIVABLE,\n type Waiver,\n} from './archive.js';\nimport type { Brief } from './brief.js';\nimport { collisionFindings, collisions, type CollisionOptions, type CollisionReport } from './collisions.js';\nimport { type Config, ConfigError, DEFAULT_CONFIG, locateConfig, parseConfig } from './config.js';\nimport { buildCorpus, type Corpus, findBriefs, isReady, pendingDependencies, type SourceFile } from './corpus.js';\nimport { canonicalPath, type FileSystem, NodeFileSystem } from './fs.js';\nimport { type CommitInfo, type FileChange, type Git, NodeGit, pullRequestUrl } from './git.js';\nimport { matchGlob, parseGlob } from './glob.js';\nimport { normalisePath } from './links.js';\nimport { lint, type Plugin } from './lint.js';\nimport { asWaivers, loadPlugins } from './plugins.js';\nimport { fileNameFor, nextId, renderNewBrief } from './scaffold.js';\nimport { planWaves, type Schedule, schedule, scheduleFindings, type ScheduleOptions } from './schedule.js';\nimport type { Finding, Phase } from './types.js';\n\nexport class EngineError extends Error {\n readonly code: 'not-found' | 'ambiguous' | 'invalid' | 'refused' | 'exists';\n\n constructor(code: EngineError['code'], message: string) {\n super(message);\n this.name = 'EngineError';\n this.code = code;\n }\n}\n\nexport interface EngineSetup {\n /** Absolute root: the directory holding the configuration. */\n readonly root: string;\n readonly config: Config;\n /** Repository-relative configuration path, or `null` when the defaults apply. */\n readonly configFile: string | null;\n readonly fs: FileSystem;\n readonly git: Git | null;\n readonly plugins?: readonly Plugin[];\n}\n\nexport interface OpenOptions {\n /** Where discovery starts. Defaults to the process's directory. */\n readonly cwd?: string;\n /** An explicit configuration file; discovery is skipped. */\n readonly config?: string;\n /** Use the defaults even where a configuration file exists. */\n readonly noConfig?: boolean;\n /** `null` runs without git. Defaults to git when the root is inside a working tree. */\n readonly git?: Git | null;\n readonly fs?: FileSystem;\n}\n\nexport interface ArchiveOptions {\n readonly pr?: number | undefined;\n /** The commit the round landed as. */\n readonly commit?: string | undefined;\n /** The branch the round started from; the diff runs from its merge base. */\n readonly base?: string | undefined;\n readonly summary?: string | undefined;\n readonly date?: string | undefined;\n readonly allowDirty?: boolean | undefined;\n readonly strict?: boolean | undefined;\n /** Leave git out, even where there is a repository. */\n readonly noGit?: boolean | undefined;\n}\n\nexport interface NewOptions {\n readonly title: string;\n readonly id?: string | undefined;\n readonly type?: string | undefined;\n readonly wave?: number | undefined;\n readonly dependsOn?: readonly string[] | undefined;\n readonly date?: string | undefined;\n}\n\nasync function exists(path: string): Promise<boolean> {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Today, in UTC. `SOURCE_DATE_EPOCH` wins where it is set, which is what makes\n * a banner written in a reproducible pipeline reproducible.\n */\nexport function today(env: Readonly<Record<string, string | undefined>> = process.env): string {\n const epoch = env['SOURCE_DATE_EPOCH'];\n const when = epoch !== undefined && /^\\d+$/.test(epoch) ? new Date(Number(epoch) * 1000) : new Date();\n return when.toISOString().slice(0, 10);\n}\n\n/**\n * A deep copy of a value in which every object and array is frozen. Plain\n * data only, as `structuredClone` takes it; the recursion ends at the data's\n * own depth.\n */\nfunction frozenCopy<T>(value: T): T {\n const freeze = (item: unknown): void => {\n if (typeof item !== 'object' || item === null) return;\n for (const child of Object.values(item)) freeze(child);\n Object.freeze(item);\n };\n const copy = structuredClone(value);\n freeze(copy);\n return copy;\n}\n\nexport function isDate(text: string): boolean {\n if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(text)) return false;\n const parsed = new Date(`${text}T00:00:00Z`);\n return !Number.isNaN(parsed.getTime()) && parsed.toISOString().slice(0, 10) === text;\n}\n\nexport class BriefEngine {\n readonly root: string;\n readonly config: Config;\n readonly configFile: string | null;\n readonly fs: FileSystem;\n readonly git: Git | null;\n private plugins: readonly Plugin[] | undefined;\n private loaded: Corpus | undefined;\n private missingBriefs = false;\n\n constructor(setup: EngineSetup) {\n this.root = setup.root;\n this.config = setup.config;\n this.configFile = setup.configFile;\n this.fs = setup.fs;\n this.git = setup.git;\n this.plugins = setup.plugins;\n }\n\n /**\n * Finds the configuration, the root it defines and the repository around it,\n * and reads every brief. The root is the directory holding the\n * configuration; without one it is the working tree's top, or `cwd`.\n */\n static async open(options: OpenOptions = {}): Promise<BriefEngine> {\n // Named as git names them, so the root and the work tree compare.\n const cwd = await canonicalPath(resolve(options.cwd ?? process.cwd()));\n const explicit = options.config === undefined ? undefined : await canonicalPath(resolve(cwd, options.config));\n const configPath = options.noConfig === true ? undefined : (explicit ?? (await locateConfig(cwd, exists)));\n // Asking git costs a process; without git there is nothing to ask.\n const toplevel = options.git === null ? null : await NodeGit.toplevel(cwd);\n const root = configPath === undefined ? (toplevel ?? cwd) : dirname(configPath);\n let config = DEFAULT_CONFIG;\n if (configPath !== undefined) {\n const fs = new NodeFileSystem(dirname(configPath));\n const name = configPath.slice(dirname(configPath).length + 1);\n const text = await fs.read(name);\n if (text === null) throw new EngineError('not-found', `${configPath} does not exist`);\n config = parseConfig(text, relative(cwd, configPath));\n }\n const inTree = toplevel !== null && !relative(toplevel, root).startsWith('..');\n const engine = new BriefEngine({\n root,\n config,\n configFile: configPath === undefined ? null : relative(root, configPath).split(sep).join('/'),\n fs: options.fs ?? new NodeFileSystem(root),\n git: options.git === undefined ? (inTree ? new NodeGit(root) : null) : options.git,\n });\n await engine.load();\n return engine;\n }\n\n get corpus(): Corpus {\n if (this.loaded === undefined) throw new Error('the engine has not loaded its briefs; call load() first');\n return this.loaded;\n }\n\n /** Reads every brief again, as after an archival. */\n async load(): Promise<Corpus> {\n const files: SourceFile[] = [];\n const accept = parseGlob(this.config.files);\n const reject = this.config.exclude.map((pattern) => parseGlob(pattern));\n const isBrief = (name: string): boolean =>\n accept.ok && matchGlob(accept.glob, name) && !reject.some((r) => r.ok && matchGlob(r.glob, name));\n const read = async (directory: string, phase: Phase): Promise<boolean> => {\n const dir = normalisePath(directory);\n const names = await this.fs.list(dir);\n for (const name of names ?? []) {\n if (!isBrief(name)) continue;\n const path = dir === '' ? name : `${dir}/${name}`;\n const text = await this.fs.read(path);\n // A file listed a moment ago and gone now was removed under the run; there is nothing to read.\n /* v8 ignore next */\n if (text !== null) files.push({ path, text, phase });\n }\n return names !== null;\n };\n this.missingBriefs = !(await read(this.config.briefs, 'live'));\n await read(this.config.archive, 'archived');\n this.loaded = buildCorpus(files, this.config);\n return this.loaded;\n }\n\n /**\n * Refuses to report on a briefs directory that does not exist. A check over\n * nothing looks exactly like a clean one, and the likelier cause is a\n * configuration pointing at the wrong place.\n */\n requireBriefs(): void {\n if (this.missingBriefs) {\n throw new EngineError('not-found', `${normalisePath(this.config.briefs)}/ does not exist; run \"spec-brief init\", or set \"briefs\" in the configuration`);\n }\n }\n\n /** The plugins the configuration names, loaded once. */\n async loadedPlugins(): Promise<readonly Plugin[]> {\n this.plugins ??= await loadPlugins(this.config.plugins, this.root);\n return this.plugins;\n }\n\n /** The one brief a reference names: an id, a file name or a path. */\n find(reference: string): Brief {\n const found = findBriefs(this.corpus, reference);\n if (found.length === 0) throw new EngineError('not-found', `no brief is named \"${reference}\"`);\n if (found.length > 1) {\n throw new EngineError('ambiguous', `\"${reference}\" names ${found.length} briefs: ${found.map((b) => b.file).join(', ')}`);\n }\n return found[0] as Brief;\n }\n\n /** The files git sees, or every file when there is no git; `null` when neither can be read. */\n async repoFiles(): Promise<string[] | null> {\n try {\n return this.git === null ? await this.fs.walk() : await this.git.files();\n } catch {\n return null;\n }\n }\n\n async lint(references: readonly string[] = []): Promise<Finding[]> {\n const only = references.length === 0 ? undefined : references.map((r) => this.find(r));\n return lint(this.corpus, { plugins: await this.loadedPlugins(), repoFiles: await this.repoFiles(), ...(only ? { only } : {}) });\n }\n\n async collisions(options: CollisionOptions = {}): Promise<{ report: CollisionReport; findings: Finding[] }> {\n const report = collisions(this.corpus, { repoFiles: await this.repoFiles(), ...options });\n return { report, findings: collisionFindings(this.corpus, report) };\n }\n\n async schedule(options: ScheduleOptions = {}): Promise<{ schedule: Schedule; findings: Finding[] }> {\n const computed = schedule(this.corpus, { repoFiles: await this.repoFiles(), ...options });\n return { schedule: computed, findings: scheduleFindings(this.corpus, computed) };\n }\n\n /**\n * Writes each brief's proposed wave into its front matter, every other line\n * as it was, as one transaction. Refused, with nothing written, when the\n * dependencies form a cycle or a front matter cannot be edited.\n */\n async writeWaves(computed: Schedule): Promise<{ written: string[]; refused: Finding[] }> {\n const plan = planWaves(computed);\n if (computed.cycles.length > 0 || plan.refused.length > 0) return { written: [], refused: [...plan.refused] };\n await applyPlan(this.fs, plan.ops);\n await this.load();\n return { written: plan.ops.map((op) => op.path), refused: [] };\n }\n\n /** Live briefs that can run now: every dependency archived, and neither a draft nor deferred. */\n ready(): Brief[] {\n return this.corpus.live.filter((b) => isReady(this.corpus, b));\n }\n\n /** The live dependencies holding a brief back. */\n waitingOn(brief: Brief): string[] {\n return pendingDependencies(this.corpus, brief);\n }\n\n async planArchive(reference: string, options: ArchiveOptions = {}): Promise<Plan> {\n const brief = this.find(reference);\n const date = options.date ?? today();\n if (!isDate(date)) throw new EngineError('invalid', `\"${date}\" is not a date written YYYY-MM-DD`);\n if (options.noGit === true && (options.commit !== undefined || options.base !== undefined)) {\n throw new EngineError('invalid', 'a commit or a base needs git; drop --no-git, or drop --commit and --base');\n }\n const git = options.noGit === true ? null : this.git;\n const base = options.base ?? this.config.archiving.base ?? undefined;\n const findings = await this.lint();\n\n let commit: CommitInfo | undefined;\n let changes: FileChange[] | undefined;\n let unmeasured: Unmeasured | undefined;\n let dirty: string[] | undefined;\n let pr: PullRequest | undefined;\n if (git !== null) {\n const revision = options.commit ?? (base === undefined ? undefined : 'HEAD');\n if (revision !== undefined) {\n commit = (await git.commit(revision)) ?? undefined;\n if (commit === undefined) throw new EngineError('not-found', `\"${revision}\" names no commit`);\n let from: string | null = null;\n if (base !== undefined) {\n from = await git.mergeBase(base, commit.sha);\n // No merge base: a base with a history of its own is diffed from\n // directly, and one that names nothing is a typo to report, not a\n // diff for git to fail.\n if (from === null) {\n if ((await git.commit(base)) === null) {\n throw new EngineError('not-found', `the base \"${base}\" names no commit; check --base and \"archiving.base\"`);\n }\n from = base;\n }\n }\n // A commit that is its own merge base with the base branch is already\n // in it: the diff is empty whatever the round changed, and an empty\n // diff would pass every scope check without measuring one.\n if (from === commit.sha) unmeasured = { reason: 'merged', base: base as string, commit: commit.sha };\n else changes = await git.changes(from, commit.sha);\n } else {\n unmeasured = { reason: 'revision' };\n }\n dirty = await git.dirty();\n } else {\n unmeasured = { reason: 'git' };\n }\n if (options.pr !== undefined) {\n pr = { number: options.pr, url: git === null ? null : pullRequestUrl(await git.remoteUrl('origin'), options.pr) };\n }\n const plan = planArchive(this.corpus, brief, {\n date,\n summary: options.summary,\n pr,\n commit,\n changes,\n unmeasured,\n dirty,\n allowDirty: options.allowDirty,\n strict: options.strict,\n findings,\n });\n return this.waive(plan, base ?? null, commit?.sha ?? null, options.strict === true);\n }\n\n /**\n * Asks each plugin with a `waive` hook which of a plan's refusals its own\n * check lifts, and turns those into notes. Asked only when the plan has a\n * refusal a plugin may lift: a hook may read git and verify signatures, and a\n * plan with nothing to waive has no question for it. A hook that throws, or\n * answers in the wrong shape, stops the run as a plugin that fails to load\n * does: an archival decided without the check it asked for is not one to\n * trust.\n *\n * A hook is handed a frozen copy of the refusals, and its waivers are\n * matched against the plan's own. Handed the plan's list, a hook could drop\n * a refusal from it, or relabel an open task as a protected file and waive\n * that, and so lift what only spec-brief may; writing to the copy throws,\n * which stops the run like any failing hook.\n */\n private async waive(plan: Plan, base: string | null, commit: string | null, strict: boolean): Promise<Plan> {\n if (!plan.blocking.some((f) => WAIVABLE.includes(f.rule))) return plan;\n const context = frozenCopy({\n root: this.root,\n brief: { id: plan.brief.id, file: plan.brief.file, text: plan.brief.text },\n findings: plan.blocking,\n base,\n commit,\n });\n const waivers: { plugin: string; waiver: Waiver }[] = [];\n for (const plugin of await this.loadedPlugins()) {\n if (plugin.waive === undefined) continue;\n let answer: unknown;\n try {\n answer = await plugin.waive(context);\n } catch (error) {\n throw new ConfigError(`plugin \"${plugin.name}\"`, [`\"waive\" failed: ${error instanceof Error ? error.message : String(error)}`]);\n }\n for (const waiver of asWaivers(answer, plugin.name)) waivers.push({ plugin: plugin.name, waiver });\n }\n return applyWaivers(plan, waivers, strict);\n }\n\n planUnarchive(reference: string, options: UnarchiveRequest = {}): Plan {\n return planUnarchive(this.corpus, this.find(reference), options);\n }\n\n /** Executes a plan and reads the briefs again. A refused plan is never applied. */\n async apply(plan: Plan): Promise<void> {\n if (plan.blocking.length > 0) {\n throw new EngineError('refused', `${plan.action} of ${plan.brief.file} is refused: ${(plan.blocking[0] as Finding).message}`);\n }\n if (plan.done) return;\n await applyPlan(this.fs, plan.ops);\n await this.load();\n }\n\n /** Scaffolds a brief and writes it; the file is new, or nothing is written. */\n async create(options: NewOptions): Promise<{ file: string; content: string }> {\n const title = options.title.trim();\n if (title === '') throw new EngineError('invalid', 'a brief needs a title');\n const id = options.id ?? nextId(this.corpus);\n if (id === null) throw new EngineError('invalid', 'the ids here are not numbers, so there is no next one; pass --id');\n if (/[\\s/\\\\]/.test(id) || id.includes(this.config.id.separator)) {\n throw new EngineError('invalid', `\"${id}\" cannot be an id: no whitespace, slashes or \"${this.config.id.separator}\"`);\n }\n if (findBriefs(this.corpus, id).some((b) => b.id !== null)) throw new EngineError('exists', `the id \"${id}\" is taken`);\n if (options.type !== undefined && this.config.types[options.type] === undefined) {\n const names = Object.keys(this.config.types);\n throw new EngineError('invalid', `\"${options.type}\" is not a brief type here; use one of ${names.join(', ') || '(none)'}`);\n }\n const date = options.date ?? today();\n if (!isDate(date)) throw new EngineError('invalid', `\"${date}\" is not a date written YYYY-MM-DD`);\n const template = this.config.template === null ? null : await this.fs.read(this.config.template);\n if (this.config.template !== null && template === null) {\n throw new EngineError('not-found', `the template ${this.config.template} does not exist`);\n }\n const content = renderNewBrief(\n this.config,\n { id, title, date, type: options.type, wave: options.wave, dependsOn: options.dependsOn },\n template,\n );\n const dir = normalisePath(this.config.briefs);\n const file = `${dir}/${fileNameFor(this.config, id, title)}`;\n if (await this.fs.exists(file)) throw new EngineError('exists', `${file} already exists`);\n await this.fs.write(file, content);\n await this.load();\n return { file, content };\n }\n}\n"]}
@@ -1,68 +1,25 @@
1
1
  /**
2
- * A front-matter reader and editor for the flat subset of YAML briefs use.
2
+ * A brief's front matter: spec-core's reader and editor, copied into
3
+ * `src/vendor/spec-core/`, over a brief's lines.
3
4
  *
4
- * Supported: `key: value` at the top level; plain, single-quoted and
5
- * double-quoted scalars; inline `[a, b]` sequences; block `- item` sequences;
6
- * `#` comments. Plain scalars follow the YAML 1.2 core schema, so `yes` is a
7
- * word and `035` keeps its leading zero for whoever reads it as text.
8
- *
9
- * Anything richer - nested mappings, block scalars, anchors, tags, a value
10
- * continued onto the next line - is recognised and reported as unsupported
11
- * rather than guessed at. A YAML library would parse more, and would be the
12
- * largest dependency of a package that has none; it would also not give back
13
- * the line of every value, and an edit that must leave every other line of a
14
- * file untouched needs exactly that.
5
+ * The flat subset of YAML briefs use: `key: value` lines, plain and quoted
6
+ * scalars, inline and block lists, comments. Anything richer is reported as
7
+ * unsupported rather than guessed at, TOML between `+++` lines included, and
8
+ * every value keeps its line, so an edit leaves every other line of the file
9
+ * as it was (ADR-0001). Offsets in what it reads count in the lines joined by
10
+ * `\n`, which for a brief are its `lines`, not its `text`.
15
11
  */
16
- export interface YamlScalar {
17
- readonly text: string;
18
- readonly quoted: boolean;
19
- }
20
- export type YamlValue = {
21
- readonly kind: 'scalar';
22
- readonly scalar: YamlScalar;
23
- } | {
24
- readonly kind: 'list';
25
- readonly items: readonly YamlScalar[];
26
- } | {
27
- readonly kind: 'unsupported';
28
- readonly reason: string;
29
- };
30
- export interface FrontMatterEntry {
31
- /** The key as written. */
32
- readonly key: string;
33
- /** The key compared: lower case, without `-` or `_`, so `depends-on` is `dependsOn`. */
34
- readonly name: string;
35
- /** 0-based line of the key. */
36
- readonly line: number;
37
- /** 0-based line after the entry's last line. */
38
- readonly end: number;
39
- readonly value: YamlValue;
40
- }
41
- export interface FrontMatterProblem {
42
- readonly line: number;
43
- readonly message: string;
44
- }
45
- export interface FrontMatter {
46
- /** 0-based line of the closing delimiter, or -1 when the block is never closed. */
47
- readonly close: number;
48
- readonly entries: readonly FrontMatterEntry[];
49
- readonly problems: readonly FrontMatterProblem[];
50
- }
51
- export declare function keyName(key: string): string;
12
+ import { type FrontMatter } from './vendor/spec-core/markdown/index.js';
13
+ export { findEntry, isNull, keyName, parseInline, removeEntry, renderScalar, setEntry, type FrontMatter, type FrontMatterEntry, type FrontMatterProblem, type YamlScalar, type YamlValue, } from './vendor/spec-core/markdown/index.js';
52
14
  /** Reads the front matter at the top of `lines`, or `null` when there is none. */
53
15
  export declare function readFrontMatter(lines: readonly string[]): FrontMatter | null;
54
- /** Parses a value written on the key's own line. `text` is trimmed and non-empty. */
55
- export declare function parseInline(text: string): YamlValue;
56
- /** Null in the YAML 1.2 core schema: empty, `~` or `null` in any of its three spellings. */
57
- export declare function isNull(scalar: YamlScalar): boolean;
58
- /** Renders a string as a scalar that reads back as the same string. */
59
- export declare function renderScalar(value: string): string;
60
- export declare function findEntry(frontMatter: FrontMatter | null, key: string): FrontMatterEntry | undefined;
61
16
  /**
62
- * Sets one key, leaving every other line as it was. An existing entry keeps the
63
- * spelling of its key; a new one goes last. A file with no front matter gains
64
- * a block.
17
+ * Sets one key as `setEntry` does, and keeps a comment that followed the old
18
+ * value on its line: `wave: 2 # after the review` becomes `wave: 3 # after
19
+ * the review`. spec-core's editor writes the key and the value alone, and a
20
+ * comment beside a value is often the only record of why it was chosen. A
21
+ * value over several lines is rewritten as `setEntry` rewrites it.
65
22
  */
66
- export declare function setEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string, rendered: string): string[];
67
- /** Removes one key and its value lines; a key that is absent changes nothing. */
68
- export declare function removeEntry(lines: readonly string[], frontMatter: FrontMatter | null, key: string): string[];
23
+ export declare function setEntryKeepingComment(lines: readonly string[], frontMatter: FrontMatter | null, key: string, rendered: string): string[];
24
+ /** Front matter an edit can be written into: YAML, and closed. */
25
+ export declare function editable(frontMatter: FrontMatter): boolean;
@@ -1,311 +1,42 @@
1
1
  /**
2
- * A front-matter reader and editor for the flat subset of YAML briefs use.
2
+ * A brief's front matter: spec-core's reader and editor, copied into
3
+ * `src/vendor/spec-core/`, over a brief's lines.
3
4
  *
4
- * Supported: `key: value` at the top level; plain, single-quoted and
5
- * double-quoted scalars; inline `[a, b]` sequences; block `- item` sequences;
6
- * `#` comments. Plain scalars follow the YAML 1.2 core schema, so `yes` is a
7
- * word and `035` keeps its leading zero for whoever reads it as text.
8
- *
9
- * Anything richer - nested mappings, block scalars, anchors, tags, a value
10
- * continued onto the next line - is recognised and reported as unsupported
11
- * rather than guessed at. A YAML library would parse more, and would be the
12
- * largest dependency of a package that has none; it would also not give back
13
- * the line of every value, and an edit that must leave every other line of a
14
- * file untouched needs exactly that.
5
+ * The flat subset of YAML briefs use: `key: value` lines, plain and quoted
6
+ * scalars, inline and block lists, comments. Anything richer is reported as
7
+ * unsupported rather than guessed at, TOML between `+++` lines included, and
8
+ * every value keeps its line, so an edit leaves every other line of the file
9
+ * as it was (ADR-0001). Offsets in what it reads count in the lines joined by
10
+ * `\n`, which for a brief are its `lines`, not its `text`.
15
11
  */
16
- const OPEN = /^---[ \t]*$/;
17
- const CLOSE = /^(?:---|\.\.\.)[ \t]*$/;
18
- const KEY = /^([A-Za-z_][\w.-]*)[ \t]*:(?:[ \t]+(.*))?$/;
19
- const SEQUENCE_ITEM = /^([ \t]*)-(?:[ \t]+(.*))?$/;
20
- const BLANK_OR_COMMENT = /^[ \t]*(?:#.*)?$/;
21
- export function keyName(key) {
22
- return key.toLowerCase().replace(/[-_]/g, '');
23
- }
12
+ import { findEntry, readFrontMatter as readText, setEntry } from './vendor/spec-core/markdown/index.js';
13
+ import { textOfLines } from './text.js';
14
+ export { findEntry, isNull, keyName, parseInline, removeEntry, renderScalar, setEntry, } from './vendor/spec-core/markdown/index.js';
24
15
  /** Reads the front matter at the top of `lines`, or `null` when there is none. */
25
16
  export function readFrontMatter(lines) {
26
- if (lines.length === 0 || !OPEN.test(lines[0]))
27
- return null;
28
- let close = -1;
29
- for (let i = 1; i < lines.length; i += 1) {
30
- if (CLOSE.test(lines[i])) {
31
- close = i;
32
- break;
33
- }
34
- }
35
- if (close < 0) {
36
- return {
37
- close: -1,
38
- entries: [],
39
- problems: [{ line: 0, message: 'the front matter opened on line 1 is never closed' }],
40
- };
41
- }
42
- const entries = [];
43
- const problems = [];
44
- const seen = new Map();
45
- let i = 1;
46
- while (i < close) {
47
- const line = lines[i];
48
- if (BLANK_OR_COMMENT.test(line)) {
49
- i += 1;
50
- continue;
51
- }
52
- const match = KEY.exec(line);
53
- if (!match) {
54
- problems.push({
55
- line: i,
56
- message: /^\s/.test(line) ? 'an indented line belongs to no key' : 'not a "key: value" line',
57
- });
58
- i += 1;
59
- continue;
60
- }
61
- const key = match[1];
62
- const inline = stripLeadingComment((match[2] ?? '').trim());
63
- let end = i + 1;
64
- while (end < close && belongsToBlock(lines[end]))
65
- end += 1;
66
- while (end > i + 1 && BLANK_OR_COMMENT.test(lines[end - 1]))
67
- end -= 1;
68
- const block = lines.slice(i + 1, end);
69
- let value;
70
- if (inline.length > 0) {
71
- value = block.some((l) => !BLANK_OR_COMMENT.test(l))
72
- ? unsupported('the value continues on the next line; keep it on one line, or quote it')
73
- : parseInline(inline);
74
- }
75
- else {
76
- value = parseBlock(block);
77
- }
78
- const name = keyName(key);
79
- const previous = seen.get(name);
80
- if (previous !== undefined) {
81
- problems.push({ line: i, message: `"${key}" is declared twice (first on line ${previous + 1})` });
82
- }
83
- else {
84
- seen.set(name, i);
85
- }
86
- entries.push({ key, name, line: i, end, value });
87
- i = end;
88
- }
89
- return { close, entries, problems };
90
- }
91
- /** A line under a key is part of its value when it is indented or starts a sequence item. */
92
- function belongsToBlock(line) {
93
- return /^[ \t]/.test(line) || /^-(?:[ \t]|$)/.test(line) || line.trim() === '';
94
- }
95
- function stripLeadingComment(text) {
96
- return text.startsWith('#') ? '' : text;
97
- }
98
- function unsupported(reason) {
99
- return { kind: 'unsupported', reason };
100
- }
101
- function parseBlock(block) {
102
- const content = block.filter((l) => !BLANK_OR_COMMENT.test(l));
103
- if (content.length === 0)
104
- return { kind: 'scalar', scalar: { text: '', quoted: false } };
105
- const first = SEQUENCE_ITEM.exec(content[0]);
106
- if (!first) {
107
- return KEY.test(content[0].trim())
108
- ? unsupported('nested mappings are not supported; flatten the key')
109
- : unsupported('the value continues on the next line; keep it on one line, or quote it');
110
- }
111
- const indent = first[1].length;
112
- const items = [];
113
- for (const line of content) {
114
- const item = SEQUENCE_ITEM.exec(line);
115
- if (!item || item[1].length !== indent) {
116
- return unsupported('a list item is continued or nested; keep each item on one line');
117
- }
118
- const text = stripLeadingComment((item[2] ?? '').trim());
119
- if (text.length === 0)
120
- return unsupported('a list item is empty');
121
- const parsed = parseInline(text);
122
- if (parsed.kind !== 'scalar') {
123
- return parsed.kind === 'list' ? unsupported('nested lists are not supported') : parsed;
124
- }
125
- items.push(parsed.scalar);
126
- }
127
- return { kind: 'list', items };
128
- }
129
- /** Parses a value written on the key's own line. `text` is trimmed and non-empty. */
130
- export function parseInline(text) {
131
- const head = text.charAt(0);
132
- if (head === '"' || head === "'") {
133
- const quoted = head === '"' ? readDoubleQuoted(text) : readSingleQuoted(text);
134
- if (typeof quoted === 'string')
135
- return unsupported(quoted);
136
- return trailingIsComment(text.slice(quoted.next))
137
- ? { kind: 'scalar', scalar: { text: quoted.text, quoted: true } }
138
- : unsupported('text follows a closing quote');
139
- }
140
- if (head === '[')
141
- return parseFlowSequence(text);
142
- if (head === '{')
143
- return unsupported('inline mappings are not supported');
144
- if (head === '|' || head === '>')
145
- return unsupported('block scalars are not supported; keep the value on one line');
146
- if (head === '&' || head === '*' || head === '!')
147
- return unsupported('anchors, aliases and tags are not supported');
148
- if (head === '@' || head === '`')
149
- return unsupported(`a plain value cannot start with "${head}"; quote it`);
150
- const plain = stripTrailingComment(text);
151
- if (/:(?:\s|$)/.test(plain))
152
- return unsupported('a plain value cannot contain ": "; quote it');
153
- if (/^-(?:\s|$)/.test(plain))
154
- return unsupported('a list must start on the line after its key');
155
- return { kind: 'scalar', scalar: { text: plain, quoted: false } };
156
- }
157
- function stripTrailingComment(text) {
158
- const hash = text.search(/\s#/);
159
- return (hash < 0 ? text : text.slice(0, hash)).trim();
160
- }
161
- function trailingIsComment(rest) {
162
- return /^\s*(?:#.*)?$/.test(rest) && (rest.trim() === '' || /^\s/.test(rest));
163
- }
164
- const ESCAPES = {
165
- '"': '"',
166
- '\\': '\\',
167
- '/': '/',
168
- '0': '\0',
169
- b: '\b',
170
- f: '\f',
171
- n: '\n',
172
- r: '\r',
173
- t: '\t',
174
- };
175
- const HEX_ESCAPE_LENGTH = { x: 2, u: 4, U: 8 };
176
- /** Reads a double-quoted scalar starting at index 0, or returns why it cannot. */
177
- function readDoubleQuoted(text) {
178
- let out = '';
179
- for (let i = 1; i < text.length; i += 1) {
180
- const ch = text.charAt(i);
181
- if (ch === '"')
182
- return { text: out, next: i + 1 };
183
- if (ch !== '\\') {
184
- out += ch;
185
- continue;
186
- }
187
- const code = text.charAt(i + 1);
188
- const simple = ESCAPES[code];
189
- if (simple !== undefined) {
190
- out += simple;
191
- i += 1;
192
- continue;
193
- }
194
- const width = HEX_ESCAPE_LENGTH[code];
195
- const hex = width === undefined ? '' : text.slice(i + 2, i + 2 + width);
196
- if (width === undefined || hex.length !== width || !/^[0-9A-Fa-f]+$/.test(hex)) {
197
- return `"\\${code}" is not an escape this reader knows`;
198
- }
199
- const point = Number.parseInt(hex, 16);
200
- if (point > 0x10ffff)
201
- return `"\\${code}${hex}" is not a character`;
202
- out += String.fromCodePoint(point);
203
- i += 1 + width;
204
- }
205
- return 'a double-quoted value is never closed';
206
- }
207
- function readSingleQuoted(text) {
208
- let out = '';
209
- for (let i = 1; i < text.length; i += 1) {
210
- const ch = text.charAt(i);
211
- if (ch !== "'") {
212
- out += ch;
213
- continue;
214
- }
215
- if (text.charAt(i + 1) === "'") {
216
- out += "'";
217
- i += 1;
218
- continue;
219
- }
220
- return { text: out, next: i + 1 };
221
- }
222
- return 'a single-quoted value is never closed';
223
- }
224
- function parseFlowSequence(text) {
225
- const items = [];
226
- let i = 1;
227
- for (;;) {
228
- while (i < text.length && /\s/.test(text.charAt(i)))
229
- i += 1;
230
- if (i >= text.length)
231
- return unsupported('an inline list is never closed; keep it on one line');
232
- const ch = text.charAt(i);
233
- if (ch === ']') {
234
- return trailingIsComment(text.slice(i + 1))
235
- ? { kind: 'list', items }
236
- : unsupported('text follows the end of an inline list');
237
- }
238
- if (ch === '[' || ch === '{')
239
- return unsupported('nested lists and mappings are not supported');
240
- if (ch === ',')
241
- return unsupported('an inline list has an empty item');
242
- let item;
243
- if (ch === '"' || ch === "'") {
244
- const rest = text.slice(i);
245
- const quoted = ch === '"' ? readDoubleQuoted(rest) : readSingleQuoted(rest);
246
- if (typeof quoted === 'string')
247
- return unsupported(quoted);
248
- item = { text: quoted.text, quoted: true };
249
- i += quoted.next;
250
- }
251
- else {
252
- let j = i;
253
- while (j < text.length && !',]'.includes(text.charAt(j)))
254
- j += 1;
255
- const plain = text.slice(i, j).trim();
256
- if (/[[{]/.test(plain) || /:(?:\s|$)/.test(plain) || plain.includes(' #')) {
257
- return unsupported(`"${plain}" needs quoting inside an inline list`);
258
- }
259
- item = { text: plain, quoted: false };
260
- i = j;
261
- }
262
- items.push(item);
263
- while (i < text.length && /\s/.test(text.charAt(i)))
264
- i += 1;
265
- if (i >= text.length)
266
- return unsupported('an inline list is never closed; keep it on one line');
267
- // After a comma the next pass reads an item or, legally in YAML, the bracket.
268
- if (text.charAt(i) === ',')
269
- i += 1;
270
- else if (text.charAt(i) !== ']')
271
- return unsupported('inline list items must be separated by commas');
272
- }
273
- }
274
- /** Null in the YAML 1.2 core schema: empty, `~` or `null` in any of its three spellings. */
275
- export function isNull(scalar) {
276
- return !scalar.quoted && ['', '~', 'null', 'Null', 'NULL'].includes(scalar.text);
277
- }
278
- /** Renders a string as a scalar that reads back as the same string. */
279
- export function renderScalar(value) {
280
- const reserved = /^(?:true|false|null|yes|no|on|off|~)$/i.test(value);
281
- const plain = /^[A-Za-z][A-Za-z0-9 ._/+-]*$/.test(value) && !value.endsWith(' ');
282
- return plain && !reserved ? value : JSON.stringify(value);
283
- }
284
- export function findEntry(frontMatter, key) {
285
- const name = keyName(key);
286
- return frontMatter?.entries.find((entry) => entry.name === name);
17
+ return readText(textOfLines(lines));
287
18
  }
288
19
  /**
289
- * Sets one key, leaving every other line as it was. An existing entry keeps the
290
- * spelling of its key; a new one goes last. A file with no front matter gains
291
- * a block.
20
+ * Sets one key as `setEntry` does, and keeps a comment that followed the old
21
+ * value on its line: `wave: 2 # after the review` becomes `wave: 3 # after
22
+ * the review`. spec-core's editor writes the key and the value alone, and a
23
+ * comment beside a value is often the only record of why it was chosen. A
24
+ * value over several lines is rewritten as `setEntry` rewrites it.
292
25
  */
293
- export function setEntry(lines, frontMatter, key, rendered) {
294
- if (frontMatter === null)
295
- return ['---', `${key}: ${rendered}`, '---', ...lines];
296
- if (frontMatter.close < 0)
297
- throw new Error('cannot edit front matter that is never closed');
298
- const entry = findEntry(frontMatter, key);
299
- if (entry === undefined) {
300
- return [...lines.slice(0, frontMatter.close), `${key}: ${rendered}`, ...lines.slice(frontMatter.close)];
301
- }
302
- return [...lines.slice(0, entry.line), `${entry.key}: ${rendered}`, ...lines.slice(entry.end)];
303
- }
304
- /** Removes one key and its value lines; a key that is absent changes nothing. */
305
- export function removeEntry(lines, frontMatter, key) {
26
+ export function setEntryKeepingComment(lines, frontMatter, key, rendered) {
27
+ const edited = setEntry(lines, frontMatter, key, rendered);
306
28
  const entry = findEntry(frontMatter, key);
307
- if (entry === undefined)
308
- return [...lines];
309
- return [...lines.slice(0, entry.line), ...lines.slice(entry.end)];
29
+ if (entry === undefined || entry.end !== entry.line + 1)
30
+ return edited;
31
+ // Offsets count in the lines joined by one character each.
32
+ const lineStart = lines.slice(0, entry.line).reduce((sum, line) => sum + line.length + 1, 0);
33
+ const rest = lines[entry.line].slice(entry.valueEnd - lineStart);
34
+ if (!/^[ \t]+#/.test(rest))
35
+ return edited;
36
+ return edited.map((line, i) => (i === entry.line ? `${line}${rest}` : line));
37
+ }
38
+ /** Front matter an edit can be written into: YAML, and closed. */
39
+ export function editable(frontMatter) {
40
+ return frontMatter.kind === 'yaml' && frontMatter.close >= 0;
310
41
  }
311
42
  //# sourceMappingURL=frontmatter.js.map