@descent-vtt/spec-brief 0.4.0 → 0.5.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 (51) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +1 -0
  3. package/dist/archive.js +31 -18
  4. package/dist/archive.js.map +1 -1
  5. package/dist/brief.js +8 -5
  6. package/dist/brief.js.map +1 -1
  7. package/dist/cli.js +21 -13
  8. package/dist/cli.js.map +1 -1
  9. package/dist/collisions.d.ts +9 -0
  10. package/dist/collisions.js +50 -40
  11. package/dist/collisions.js.map +1 -1
  12. package/dist/config.d.ts +6 -0
  13. package/dist/config.js +17 -6
  14. package/dist/config.js.map +1 -1
  15. package/dist/corpus.js +21 -15
  16. package/dist/corpus.js.map +1 -1
  17. package/dist/engine.d.ts +2 -1
  18. package/dist/engine.js +24 -15
  19. package/dist/engine.js.map +1 -1
  20. package/dist/frontmatter.js +1 -1
  21. package/dist/frontmatter.js.map +1 -1
  22. package/dist/fs.js +9 -5
  23. package/dist/fs.js.map +1 -1
  24. package/dist/git.js +7 -4
  25. package/dist/git.js.map +1 -1
  26. package/dist/glob.d.ts +8 -0
  27. package/dist/glob.js +74 -0
  28. package/dist/glob.js.map +1 -1
  29. package/dist/links.js +2 -1
  30. package/dist/links.js.map +1 -1
  31. package/dist/lint.js +3 -4
  32. package/dist/lint.js.map +1 -1
  33. package/dist/plugins.js +10 -6
  34. package/dist/plugins.js.map +1 -1
  35. package/dist/report.d.ts +8 -1
  36. package/dist/report.js +22 -20
  37. package/dist/report.js.map +1 -1
  38. package/dist/rules.js +10 -6
  39. package/dist/rules.js.map +1 -1
  40. package/dist/scaffold.js +2 -2
  41. package/dist/scaffold.js.map +1 -1
  42. package/dist/schedule.js +10 -20
  43. package/dist/schedule.js.map +1 -1
  44. package/dist/schema.js +9 -13
  45. package/dist/schema.js.map +1 -1
  46. package/dist/scope.js +2 -2
  47. package/dist/scope.js.map +1 -1
  48. package/dist/text.d.ts +4 -1
  49. package/dist/text.js +10 -6
  50. package/dist/text.js.map +1 -1
  51. package/package.json +1 -1
package/dist/scaffold.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Comments are not content, so a freshly scaffolded brief reads as unwritten
5
5
  * until somebody writes it.
6
6
  */
7
- import { DEFAULT_CONFIG } from './config.js';
7
+ import { DEFAULT_CONFIG, typeSections } from './config.js';
8
8
  import { renderScalar } from './frontmatter.js';
9
9
  import { fillTemplate, slugify } from './text.js';
10
10
  /**
@@ -67,7 +67,7 @@ export function renderNewBrief(config, brief, template) {
67
67
  status: config.status.draft ?? config.status.active,
68
68
  });
69
69
  }
70
- const typed = brief.type === undefined ? [] : (config.types[brief.type] ?? []);
70
+ const typed = brief.type === undefined ? [] : (typeSections(config, brief.type) ?? []);
71
71
  const lines = [...frontMatter(config, brief), '', `# ${brief.id} \u2014 ${brief.title}`];
72
72
  for (const rule of [...config.sections, ...typed]) {
73
73
  lines.push('', `## ${rule.name}`, '', `<!-- ${hint(rule)} -->`);
@@ -1 +1 @@
1
- {"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAe,cAAc,EAAoB,MAAM,aAAa,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWlD;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,MAAc;IACnC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;IACrF,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,I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EAAE,QAAQ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChE,qEAAqE;QACrE,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;QAChG,IAAI,IAAI,CAAC,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,0BAA0B,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC","sourcesContent":["/**\n * Writing a new brief: the next free id, a file name, and a body with every\n * section the configuration requires, each holding a hint in a comment.\n * Comments are not content, so a freshly scaffolded brief reads as unwritten\n * until somebody writes it.\n */\n\nimport { type Config, DEFAULT_CONFIG, type SectionRule } from './config.js';\nimport type { Corpus } from './corpus.js';\nimport { renderScalar } from './frontmatter.js';\nimport { fillTemplate, slugify } from './text.js';\n\nexport interface NewBrief {\n readonly id: string;\n readonly title: string;\n readonly date: string;\n readonly type?: string | undefined;\n readonly wave?: number | undefined;\n readonly dependsOn?: readonly string[] | undefined;\n}\n\n/**\n * The next id: one more than the highest numeric id, live or archived, at the\n * configured width. Ids are never reused, so an archived brief still holds\n * its number. `null` when the corpus has ids but none of them are numbers.\n */\nexport function nextId(corpus: Corpus): string | null {\n const ids = corpus.briefs.map((b) => b.id).filter((id): id is string => id !== null);\n const numeric = ids.filter((id) => /^\\d+$/.test(id)).map(Number);\n if (numeric.length === 0 && ids.length > 0) return null;\n const next = numeric.length === 0 ? 1 : Math.max(...numeric) + 1;\n return String(next).padStart(corpus.config.id.digits, '0');\n}\n\nexport function fileNameFor(config: Config, id: string, title: string): string {\n const slug = slugify(title);\n if (config.id.source === 'frontmatter') return `${slug === '' ? id : slug}.md`;\n return slug === '' ? `${id}.md` : `${id}${config.id.separator}${slug}.md`;\n}\n\nconst DEFAULT_RULES: readonly SectionRule[] = [...DEFAULT_CONFIG.sections, ...Object.values(DEFAULT_CONFIG.types).flat()];\n\n/**\n * What a new brief says under a heading: the section's configured hint, or the\n * default section's of the same name - a configuration written before hints\n * existed names its sections without one - or a plain instruction. A \"-->\"\n * would end the comment early and leave the rest as content, so it is broken.\n */\nfunction hint(rule: SectionRule): string {\n const text = rule.hint ?? DEFAULT_RULES.find((d) => d.name.toLowerCase() === rule.name.toLowerCase())?.hint ?? `Write the ${rule.name}.`;\n return text.replaceAll('-->', '-- >');\n}\n\nfunction frontMatter(config: Config, brief: NewBrief): string[] {\n const lines = ['---'];\n if (config.id.source === 'frontmatter') lines.push(`id: ${renderScalar(brief.id)}`);\n if (config.status.field !== null) {\n lines.push(`${config.status.field}: ${renderScalar(config.status.draft ?? config.status.active)}`);\n }\n lines.push(`date: ${brief.date}`);\n if (brief.type !== undefined) lines.push(`type: ${renderScalar(brief.type)}`);\n if (brief.wave !== undefined) lines.push(`wave: ${brief.wave}`);\n if (brief.dependsOn !== undefined && brief.dependsOn.length > 0) {\n lines.push(`dependsOn: [${brief.dependsOn.map((d) => JSON.stringify(d)).join(', ')}]`);\n }\n lines.push('affectedFiles: []', 'protectedFiles: []', '---');\n return lines;\n}\n\n/** The text of a new brief, from the configured template or from the section list. */\nexport function renderNewBrief(config: Config, brief: NewBrief, template: string | null): string {\n if (template !== null) {\n return fillTemplate(template, {\n id: brief.id,\n title: brief.title,\n date: brief.date,\n type: brief.type ?? '',\n wave: brief.wave === undefined ? '' : String(brief.wave),\n status: config.status.draft ?? config.status.active,\n });\n }\n const typed = brief.type === undefined ? [] : (config.types[brief.type] ?? []);\n const lines = [...frontMatter(config, brief), '', `# ${brief.id} \\u2014 ${brief.title}`];\n for (const rule of [...config.sections, ...typed]) {\n lines.push('', `## ${rule.name}`, '', `<!-- ${hint(rule)} -->`);\n // Text a section must contain is written in, so it is not forgotten.\n if (rule.mustContain.length > 0) lines.push('', ...rule.mustContain.map((text) => `- ${text}`));\n if (rule.checklist) lines.push('', '- [ ] <!-- one check -->');\n }\n return `${lines.join('\\n')}\\n`;\n}\n"]}
1
+ {"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAe,cAAc,EAAoB,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1F,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWlD;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,MAAc;IACnC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;IACrF,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,EAAU,E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requires, each holding a hint in a comment.\n * Comments are not content, so a freshly scaffolded brief reads as unwritten\n * until somebody writes it.\n */\n\nimport { type Config, DEFAULT_CONFIG, type SectionRule, typeSections } from './config.js';\nimport type { Corpus } from './corpus.js';\nimport { renderScalar } from './frontmatter.js';\nimport { fillTemplate, slugify } from './text.js';\n\nexport interface NewBrief {\n readonly id: string;\n readonly title: string;\n readonly date: string;\n readonly type?: string | undefined;\n readonly wave?: number | undefined;\n readonly dependsOn?: readonly string[] | undefined;\n}\n\n/**\n * The next id: one more than the highest numeric id, live or archived, at the\n * configured width. Ids are never reused, so an archived brief still holds\n * its number. `null` when the corpus has ids but none of them are numbers.\n */\nexport function nextId(corpus: Corpus): string | null {\n const ids = corpus.briefs.map((b) => b.id).filter((id): id is string => id !== null);\n const numeric = ids.filter((id) => /^\\d+$/.test(id)).map(Number);\n if (numeric.length === 0 && ids.length > 0) return null;\n const next = numeric.length === 0 ? 1 : Math.max(...numeric) + 1;\n return String(next).padStart(corpus.config.id.digits, '0');\n}\n\nexport function fileNameFor(config: Config, id: string, title: string): string {\n const slug = slugify(title);\n if (config.id.source === 'frontmatter') return `${slug === '' ? id : slug}.md`;\n return slug === '' ? `${id}.md` : `${id}${config.id.separator}${slug}.md`;\n}\n\nconst DEFAULT_RULES: readonly SectionRule[] = [...DEFAULT_CONFIG.sections, ...Object.values(DEFAULT_CONFIG.types).flat()];\n\n/**\n * What a new brief says under a heading: the section's configured hint, or the\n * default section's of the same name - a configuration written before hints\n * existed names its sections without one - or a plain instruction. A \"-->\"\n * would end the comment early and leave the rest as content, so it is broken.\n */\nfunction hint(rule: SectionRule): string {\n const text = rule.hint ?? DEFAULT_RULES.find((d) => d.name.toLowerCase() === rule.name.toLowerCase())?.hint ?? `Write the ${rule.name}.`;\n return text.replaceAll('-->', '-- >');\n}\n\nfunction frontMatter(config: Config, brief: NewBrief): string[] {\n const lines = ['---'];\n if (config.id.source === 'frontmatter') lines.push(`id: ${renderScalar(brief.id)}`);\n if (config.status.field !== null) {\n lines.push(`${config.status.field}: ${renderScalar(config.status.draft ?? config.status.active)}`);\n }\n lines.push(`date: ${brief.date}`);\n if (brief.type !== undefined) lines.push(`type: ${renderScalar(brief.type)}`);\n if (brief.wave !== undefined) lines.push(`wave: ${brief.wave}`);\n if (brief.dependsOn !== undefined && brief.dependsOn.length > 0) {\n lines.push(`dependsOn: [${brief.dependsOn.map((d) => JSON.stringify(d)).join(', ')}]`);\n }\n lines.push('affectedFiles: []', 'protectedFiles: []', '---');\n return lines;\n}\n\n/** The text of a new brief, from the configured template or from the section list. */\nexport function renderNewBrief(config: Config, brief: NewBrief, template: string | null): string {\n if (template !== null) {\n return fillTemplate(template, {\n id: brief.id,\n title: brief.title,\n date: brief.date,\n type: brief.type ?? '',\n wave: brief.wave === undefined ? '' : String(brief.wave),\n status: config.status.draft ?? config.status.active,\n });\n }\n const typed = brief.type === undefined ? [] : (typeSections(config, brief.type) ?? []);\n const lines = [...frontMatter(config, brief), '', `# ${brief.id} \\u2014 ${brief.title}`];\n for (const rule of [...config.sections, ...typed]) {\n lines.push('', `## ${rule.name}`, '', `<!-- ${hint(rule)} -->`);\n // Text a section must contain is written in, so it is not forgotten.\n if (rule.mustContain.length > 0) lines.push('', ...rule.mustContain.map((text) => `- ${text}`));\n if (rule.checklist) lines.push('', '- [ ] <!-- one check -->');\n }\n return `${lines.join('\\n')}\\n`;\n}\n"]}
package/dist/schedule.js CHANGED
@@ -52,14 +52,14 @@ function breachesOf(brief, wave, judge) {
52
52
  if (dependency.wave !== null && dependency.wave >= wave)
53
53
  out.push({ reason: 'dependency', brief: dependency, wave: dependency.wave });
54
54
  }
55
- for (const other of judge.dependents.get(brief) ?? []) {
56
- if (other.wave !== null && other.wave <= wave)
55
+ for (const [other, needs] of judge.dependencies) {
56
+ if (other.wave !== null && other.wave <= wave && needs.includes(brief))
57
57
  out.push({ reason: 'dependent', brief: other, wave: other.wave });
58
58
  }
59
59
  for (const other of judge.compared) {
60
60
  if (other === brief || other.wave !== wave)
61
61
  continue;
62
- const overlaps = meet(judge.scope(brief), judge.scope(other), judge.budget, judge.files).overlaps;
62
+ const overlaps = meet(judge.scopes.get(brief), judge.scopes.get(other), judge.budget, judge.files).overlaps;
63
63
  if (overlaps.length > 0)
64
64
  out.push({ reason: 'collision', brief: other, overlaps });
65
65
  }
@@ -71,24 +71,14 @@ export function schedule(corpus, options = {}) {
71
71
  const budget = options.budget ?? WITNESS_BUDGET;
72
72
  const deferred = corpus.live.filter((b) => b.status === 'deferred').sort(byId);
73
73
  const briefs = corpus.live.filter((b) => b.status !== 'deferred').sort(byId);
74
- const dependencies = new Map(briefs.map((b) => [b, liveDependencies(corpus, b)]));
74
+ // Of deferred briefs too: lint's wave-order reads every live brief's wave.
75
+ // In the order of the ids, which is the order a brief's dependents are named in.
76
+ const dependencies = new Map([...corpus.live].sort(byId).map((b) => [b, liveDependencies(corpus, b)]));
75
77
  const declared = briefs.flatMap((b) => (b.wave === null ? [] : [b.wave]));
76
78
  const first = declared.length === 0 ? 1 : Math.min(...declared);
77
- const scopes = new Map();
78
- const scope = (b) => {
79
- const known = scopes.get(b) ?? scopeOf(b, reading);
80
- scopes.set(b, known);
81
- return known;
82
- };
79
+ const scopes = new Map(briefs.map((b) => [b, scopeOf(b, reading)]));
83
80
  const waiting = new Set(waitingOnDeferred(corpus).map((w) => w.brief));
84
- // Deferred briefs too: lint's wave-order reads every live brief's wave.
85
- const everyDependency = new Map(corpus.live.map((b) => [b, liveDependencies(corpus, b)]));
86
- const dependents = new Map();
87
- for (const b of [...corpus.live].sort(byId)) {
88
- for (const d of everyDependency.get(b))
89
- dependents.set(d, [...(dependents.get(d) ?? []), b]);
90
- }
91
- const judge = { compared: briefs.filter((b) => !waiting.has(b)), dependencies: everyDependency, dependents, scope, budget, files };
81
+ const judge = { compared: briefs.filter((b) => !waiting.has(b)), dependencies, scopes, budget, files };
92
82
  const waveOf = new Map();
93
83
  const occupants = new Map();
94
84
  const placements = [];
@@ -106,7 +96,7 @@ export function schedule(corpus, options = {}) {
106
96
  if (after === null || wave > after.wave)
107
97
  after = { brief: dependency, wave };
108
98
  }
109
- const own = scope(next);
99
+ const own = scopes.get(next);
110
100
  const passed = [];
111
101
  let wave = after === null ? first : after.wave + 1;
112
102
  // Ends by construction: a wave past every occupied one is empty, and an empty wave takes anyone.
@@ -247,7 +237,7 @@ export function planWaves(s) {
247
237
  for (const p of moves(s)) {
248
238
  const { brief } = p;
249
239
  if (brief.frontMatter !== null && !editable(brief.frontMatter)) {
250
- const open = brief.frontMatter.close < 0;
240
+ const open = brief.frontMatter.close === -1;
251
241
  refused.push({
252
242
  rule: 'front-matter',
253
243
  severity: 'error',
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.js","sourceRoot":"","sources":["../src/schedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAc,WAAW,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAe,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrH,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAA4B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAqEvC,SAAS,KAAK,CAAC,KAAY;IACzB,OAAO,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC;AAChC,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,2FAA2F;AAC3F,SAAS,KAAK,CAAC,G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D,CAAC,CAAC,CAAC,wEAAwE;aACvJ,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QACD,MAAM,KAAK,GAAG,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACjG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAChH,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Waves, computed: which live briefs can run side by side, so that no two in\n * one wave can write the same file and every brief runs after the briefs it\n * depends on.\n *\n * Deciding what the rounds of a goal are is prose, and an agent's work. Given\n * the rounds, placing them is not: it is precedence-constrained colouring, and\n * a tool answers it the same way every time (ADR-0011). Briefs are taken in\n * dependency order, ties broken by id, and each goes into the lowest wave that\n * is after every live dependency's and holds nothing it collides with. A brief\n * with no scope cannot be proved apart from anything, so it shares its wave\n * with nobody. The greedy answer is not always the fewest waves - no fast\n * method promises that - but it is always a valid one, and the same one.\n *\n * Nothing is written here. `planWaves` says what `--write` would write, and\n * the engine writes it as the archive writes, as one transaction.\n */\n\nimport type { FileOp } from './archive.js';\nimport { type Brief, lineOfField } from './brief.js';\nimport { undecidedFinding, unscopedFinding } from './collisions.js';\nimport { byId, type Corpus, cycleSubject, dependencyCycles, liveDependencies, waitingOnDeferred } from './corpus.js';\nimport { editable, setEntryKeepingComment } from './frontmatter.js';\nimport { readingIn, WITNESS_BUDGET } from './glob.js';\nimport { configuredSeverity } from './lint.js';\nimport { meet, type Overlap, type Scope, scopeOf, witnessText } from './scope.js';\nimport { encodeLike } from './text.js';\nimport type { Finding } from './types.js';\n\nexport interface ScheduleOptions {\n /** The files the tree holds, which say whether a literal path is a file or a directory. */\n readonly repoFiles?: readonly string[] | null;\n /** How many states one witness search may visit before it answers `undecided`. */\n readonly budget?: number;\n}\n\n/** A wave a brief could not join, and the brief already there that kept it out. */\nexport type Passed =\n | { readonly wave: number; readonly reason: 'collision'; readonly brief: Brief; readonly overlaps: readonly Overlap[] }\n | { readonly wave: number; readonly reason: 'undecided'; readonly brief: Brief; readonly patterns: readonly (readonly [string, string])[] }\n /** One of the two declares no affectedFiles, and an unscoped brief runs alone. */\n | { readonly wave: number; readonly reason: 'unscoped'; readonly brief: Brief };\n\n/**\n * Why a declared wave does not hold: what `matrix` or `lint` would report as\n * an error if the brief ran there.\n */\nexport type Breach =\n /** A brief the matrix compares, declaring the same wave, whose scope meets this one's. Overlaps name this brief's pattern first. */\n | { readonly reason: 'collision'; readonly brief: Brief; readonly overlaps: readonly Overlap[] }\n /** A live dependency declaring the same wave or a later one. */\n | { readonly reason: 'dependency'; readonly brief: Brief; readonly wave: number }\n /** A live brief depending on this one, declaring the same wave or an earlier one. */\n | { readonly reason: 'dependent'; readonly brief: Brief; readonly wave: number };\n\nexport interface Placement {\n readonly brief: Brief;\n /** The wave its front matter declares; `null` when it declares none it can read. */\n readonly declared: number | null;\n readonly proposed: number;\n /** The live dependency in the latest wave, which sets the earliest wave this one may run in. */\n readonly after: { readonly brief: Brief; readonly wave: number } | null;\n /** Every wave from that earliest one that it could not join, in order. Overlaps and patterns name its own pattern first. */\n readonly passed: readonly Passed[];\n /** Declares no affectedFiles, so it shares its wave with nobody. */\n readonly unscoped: boolean;\n /**\n * Why the declared wave does not hold, when it is not the proposed one. Empty\n * when it holds - a person moved the brief, and `lint` and `matrix` accept\n * the wave - and when there is no declared wave to judge.\n */\n readonly breaches: readonly Breach[];\n}\n\n/** A live brief that can be placed in no wave, and the dependency that holds it. */\nexport interface Unplaced {\n readonly brief: Brief;\n readonly waitsOn: Brief;\n /** The dependency is deferred, is in a dependency cycle, or is itself unplaced. */\n readonly because: 'deferred' | 'cycle' | 'unplaced';\n}\n\nexport interface Schedule {\n /** The first wave: the lowest any scheduled brief declares, or 1 when none declares one. */\n readonly first: number;\n /** In the order they were placed: dependency order, ties by id. */\n readonly placements: readonly Placement[];\n /** By id. */\n readonly unplaced: readonly Unplaced[];\n /** Dependency cycles among the scheduled briefs, each as a path back to its start. */\n readonly cycles: readonly (readonly Brief[])[];\n /** Deferred briefs, which wait for their trigger and run in no wave. By id. */\n readonly deferred: readonly Brief[];\n}\n\nfunction label(brief: Brief): string {\n return brief.id ?? brief.name;\n}\n\nexport { byId } from './corpus.js';\n\n/** The first brief in a wave this one cannot share it with, or `null` when it can join. */\nfunction clash(own: Scope, wave: number, here: readonly Scope[], budget: number, files: readonly string[] | null): Passed | null {\n for (const other of here) {\n if (own.affected.length === 0 || other.affected.length === 0) return { wave, reason: 'unscoped', brief: other.brief };\n const meeting = meet(own, other, budget, files);\n if (meeting.overlaps.length > 0) return { wave, reason: 'collision', brief: other.brief, overlaps: meeting.overlaps };\n if (meeting.undecided.length > 0) return { wave, reason: 'undecided', brief: other.brief, patterns: meeting.undecided };\n }\n return null;\n}\n\n/** What a declared wave is judged against. */\ninterface Judge {\n /** The briefs the matrix compares: none deferred, none waiting on deferred work. */\n readonly compared: readonly Brief[];\n /** Every live brief's live dependencies, and the live briefs that depend on each, by id. */\n readonly dependencies: ReadonlyMap<Brief, readonly Brief[]>;\n readonly dependents: ReadonlyMap<Brief, readonly Brief[]>;\n readonly scope: (b: Brief) => Scope;\n readonly budget: number;\n readonly files: readonly string[] | null;\n}\n\n/**\n * Why a brief's declared wave does not hold, judged as `lint` and `matrix`\n * judge it: against the waves the other briefs declare, not the ones proposed.\n * Collisions are with the briefs the matrix compares; the dependency order is\n * wave-order's, both ways, over every live brief.\n */\nfunction breachesOf(brief: Brief, wave: number, judge: Judge): Breach[] {\n const out: Breach[] = [];\n for (const dependency of judge.dependencies.get(brief) as Brief[]) {\n if (dependency.wave !== null && dependency.wave >= wave) out.push({ reason: 'dependency', brief: dependency, wave: dependency.wave });\n }\n for (const other of judge.dependents.get(brief) ?? []) {\n if (other.wave !== null && other.wave <= wave) out.push({ reason: 'dependent', brief: other, wave: other.wave });\n }\n for (const other of judge.compared) {\n if (other === brief || other.wave !== wave) continue;\n const overlaps = meet(judge.scope(brief), judge.scope(other), judge.budget, judge.files).overlaps;\n if (overlaps.length > 0) out.push({ reason: 'collision', brief: other, overlaps });\n }\n return out;\n}\n\nexport function schedule(corpus: Corpus, options: ScheduleOptions = {}): Schedule {\n const files = options.repoFiles ?? null;\n const reading = readingIn(files);\n const budget = options.budget ?? WITNESS_BUDGET;\n const deferred = corpus.live.filter((b) => b.status === 'deferred').sort(byId);\n const briefs = corpus.live.filter((b) => b.status !== 'deferred').sort(byId);\n const dependencies = new Map(briefs.map((b) => [b, liveDependencies(corpus, b)]));\n const declared = briefs.flatMap((b) => (b.wave === null ? [] : [b.wave]));\n const first = declared.length === 0 ? 1 : Math.min(...declared);\n const scopes = new Map<Brief, Scope>();\n const scope = (b: Brief): Scope => {\n const known = scopes.get(b) ?? scopeOf(b, reading);\n scopes.set(b, known);\n return known;\n };\n const waiting = new Set(waitingOnDeferred(corpus).map((w) => w.brief));\n // Deferred briefs too: lint's wave-order reads every live brief's wave.\n const everyDependency = new Map(corpus.live.map((b) => [b, liveDependencies(corpus, b)]));\n const dependents = new Map<Brief, Brief[]>();\n for (const b of [...corpus.live].sort(byId)) {\n for (const d of everyDependency.get(b) as Brief[]) dependents.set(d, [...(dependents.get(d) ?? []), b]);\n }\n const judge: Judge = { compared: briefs.filter((b) => !waiting.has(b)), dependencies: everyDependency, dependents, scope, budget, files };\n\n const waveOf = new Map<Brief, number>();\n const occupants = new Map<number, Scope[]>();\n const placements: Placement[] = [];\n const pending = [...briefs];\n // Kahn's order, taking the least id whose dependencies are all placed. A\n // brief waiting on a deferred one, or on a cycle, is never taken.\n for (;;) {\n const next = pending.find((b) => (dependencies.get(b) as Brief[]).every((d) => waveOf.has(d)));\n if (next === undefined) break;\n pending.splice(pending.indexOf(next), 1);\n let after: Placement['after'] = null;\n for (const dependency of dependencies.get(next) as Brief[]) {\n const wave = waveOf.get(dependency) as number;\n if (after === null || wave > after.wave) after = { brief: dependency, wave };\n }\n const own = scope(next);\n const passed: Passed[] = [];\n let wave = after === null ? first : after.wave + 1;\n // Ends by construction: a wave past every occupied one is empty, and an empty wave takes anyone.\n for (;;) {\n const found = clash(own, wave, occupants.get(wave) ?? [], budget, files);\n if (found === null) break;\n passed.push(found);\n wave += 1;\n }\n waveOf.set(next, wave);\n occupants.set(wave, [...(occupants.get(wave) ?? []), own]);\n const breaches = next.wave === null || next.wave === wave ? [] : breachesOf(next, next.wave, judge);\n placements.push({ brief: next, declared: next.wave, proposed: wave, after, passed, unscoped: own.affected.length === 0, breaches });\n }\n\n const cycles = dependencyCycles(corpus).filter((cycle) => cycle.every((b) => b.status !== 'deferred'));\n const inCycle = new Set(cycles.flat());\n const unplaced = pending.map((brief): Unplaced => {\n const waitsOn = (dependencies.get(brief) as Brief[]).find((d) => !waveOf.has(d)) as Brief;\n const because = waitsOn.status === 'deferred' ? 'deferred' : inCycle.has(waitsOn) ? 'cycle' : 'unplaced';\n return { brief, waitsOn, because };\n });\n return { first, placements, unplaced, cycles, deferred };\n}\n\n/** The briefs whose declared wave the schedule would change. */\nexport function moves(s: Schedule): Placement[] {\n return s.placements.filter((p) => p.proposed !== p.declared);\n}\n\n/**\n * Whether a brief's declared wave holds: it is the proposed one, or one a\n * person chose that `lint` and `matrix` accept. The schedule is one valid\n * answer, not the only one (ADR-0011, amended).\n */\nexport function holds(p: Placement): boolean {\n return p.declared !== null && p.breaches.length === 0;\n}\n\n/** Why a declared wave does not hold, a clause each. */\nexport function breachReasons(p: Placement): string[] {\n return p.breaches.map((b) => {\n if (b.reason === 'collision') return `${label(b.brief)} there also writes ${witnessText(b.overlaps[0] as Overlap)}`;\n if (b.reason === 'dependency') return `it depends on ${label(b.brief)}, in wave ${b.wave}`;\n return `${label(b.brief)} depends on it, in wave ${b.wave}`;\n });\n}\n\n/** Why a brief is in its wave and not an earlier one, a clause each. */\nexport function reasons(p: Placement): string[] {\n const out: string[] = [];\n if (p.after !== null) out.push(`after ${label(p.after.brief)}, in wave ${p.after.wave}`);\n if (p.unscoped && p.passed.length > 0) out.push('it declares no affectedFiles, so it runs in a wave of its own');\n for (const passed of p.passed) {\n const there = `not wave ${passed.wave}, where ${label(passed.brief)}`;\n if (passed.reason === 'collision') {\n const [overlap] = passed.overlaps as [Overlap];\n out.push(`${there} also writes ${witnessText(overlap)} (\"${overlap.patterns[0]}\" and \"${overlap.patterns[1]}\")`);\n } else if (passed.reason === 'undecided') {\n out.push(`${there} may write the same files: the search could not decide within its budget`);\n } else if (!p.unscoped) {\n out.push(`${there} declares no affectedFiles and runs alone`);\n }\n }\n if (out.length === 0) out.push('nothing holds it later');\n return out;\n}\n\n/** The schedule as findings: cycles, briefs whose waves would move, briefs that run alone, and pairs it could not decide. */\nexport function scheduleFindings(corpus: Corpus, s: Schedule): Finding[] {\n const findings: Finding[] = [];\n const cycle = configuredSeverity(corpus, 'dependency-cycle');\n if (cycle !== null) {\n for (const members of s.cycles) {\n const start = members[0] as Brief;\n findings.push({\n rule: 'dependency-cycle',\n severity: cycle,\n message: `dependencies form a cycle, so no wave can hold them: ${members.map(label).join(' -> ')}`,\n file: start.file,\n line: lineOfField(start, 'dependsOn') + 1,\n brief: start.id ?? undefined,\n hint: 'a cycle can never become ready; remove the dependency that is not real',\n subject: cycleSubject(members),\n });\n }\n }\n const change = configuredSeverity(corpus, 'wave-schedule');\n if (change !== null) {\n // A wave a person chose that lint and matrix accept is theirs to keep: a\n // note, so that CI passes it. One missing, or one that does not hold, is\n // the rule's finding at its configured severity.\n for (const p of moves(s)) {\n const valid = holds(p);\n const was =\n p.declared === null\n ? 'declares no wave'\n : valid\n ? `declares wave ${p.declared}, which holds`\n : `declares wave ${p.declared}, which does not hold (${breachReasons(p).join('; ')})`;\n findings.push({\n rule: 'wave-schedule',\n severity: valid ? 'note' : change,\n message: `${was}; the schedule puts it in wave ${p.proposed}: ${reasons(p).join('; ')}`,\n file: p.brief.file,\n line: lineOfField(p.brief, 'wave') + 1,\n brief: p.brief.id ?? undefined,\n hint: valid\n ? `keep wave ${p.declared as number}, or run \"spec-brief schedule --write\" for wave ${p.proposed}`\n : `run \"spec-brief schedule --write\", or set \"wave: ${p.proposed}\"`,\n });\n }\n }\n const unscoped = configuredSeverity(corpus, 'unscoped');\n if (unscoped !== null && s.placements.length > 1) {\n for (const p of s.placements.filter((x) => x.unscoped)) {\n findings.push(unscopedFinding(unscoped, p.brief, `the ${s.placements.length - 1} other brief(s) the schedule places; it runs alone in wave ${p.proposed}`));\n }\n }\n const undecided = configuredSeverity(corpus, 'collision-undecided');\n if (undecided !== null) {\n for (const p of s.placements) {\n for (const passed of p.passed) {\n if (passed.reason !== 'undecided') continue;\n const theirsFirst = passed.patterns.map(([own, theirs]) => [theirs, own] as const);\n findings.push(undecidedFinding(undecided, passed.brief, p.brief, theirsFirst, passed.wave));\n }\n }\n }\n return findings;\n}\n\nexport interface WavePlan {\n /** A write of each brief whose wave changes: its front matter's `wave`, and every other line as it was. */\n readonly ops: readonly FileOp[];\n /** Briefs whose wave cannot be written, which refuse the whole write. */\n readonly refused: readonly Finding[];\n}\n\n/** What `--write` writes. */\nexport function planWaves(s: Schedule): WavePlan {\n const ops: FileOp[] = [];\n const refused: Finding[] = [];\n for (const p of moves(s)) {\n const { brief } = p;\n if (brief.frontMatter !== null && !editable(brief.frontMatter)) {\n const open = brief.frontMatter.close < 0;\n refused.push({\n rule: 'front-matter',\n severity: 'error',\n message: `the front matter is ${open ? 'never closed' : 'TOML'}, so wave ${p.proposed} cannot be written into it`,\n file: brief.file,\n line: 1,\n brief: brief.id ?? undefined,\n hint: open ? 'close the front matter with a \"---\" line, and schedule again' : 'write the front matter as YAML between \"---\" lines, and schedule again',\n });\n continue;\n }\n const lines = setEntryKeepingComment(brief.lines, brief.frontMatter, 'wave', String(p.proposed));\n ops.push({ kind: 'write', path: brief.file, content: encodeLike(brief.source, lines), before: brief.source });\n }\n return { ops, refused };\n}\n"]}
1
+ {"version":3,"file":"schedule.js","sourceRoot":"","sources":["../src/schedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAc,WAAW,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAe,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrH,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAA4B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAqEvC,SAAS,KAAK,CAAC,KAAY;IACzB,OAAO,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC;AAChC,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,2FAA2F;AAC3F,SAAS,KAAK,CAAC,GAAU,EAAE,IAAY,EAAE,IAAsB,EAAE,MAAc,EAAE,KAA+B;IAC9G,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC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CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,uBAAuB,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,aAAa,CAAC,CAAC,QAAQ,4BAA4B;gBACjH,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,IAAI,EAAE,CAAC;gBACP,KAAK,EAAE,KAAK,CAAC,EAAE,IAAI,SAAS;gBAC5B,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,8DAA8D,CAAC,CAAC,CAAC,wEAAwE;aACvJ,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QACD,MAAM,KAAK,GAAG,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACjG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAChH,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Waves, computed: which live briefs can run side by side, so that no two in\n * one wave can write the same file and every brief runs after the briefs it\n * depends on.\n *\n * Deciding what the rounds of a goal are is prose, and an agent's work. Given\n * the rounds, placing them is not: it is precedence-constrained colouring, and\n * a tool answers it the same way every time (ADR-0011). Briefs are taken in\n * dependency order, ties broken by id, and each goes into the lowest wave that\n * is after every live dependency's and holds nothing it collides with. A brief\n * with no scope cannot be proved apart from anything, so it shares its wave\n * with nobody. The greedy answer is not always the fewest waves - no fast\n * method promises that - but it is always a valid one, and the same one.\n *\n * Nothing is written here. `planWaves` says what `--write` would write, and\n * the engine writes it as the archive writes, as one transaction.\n */\n\nimport type { FileOp } from './archive.js';\nimport { type Brief, lineOfField } from './brief.js';\nimport { undecidedFinding, unscopedFinding } from './collisions.js';\nimport { byId, type Corpus, cycleSubject, dependencyCycles, liveDependencies, waitingOnDeferred } from './corpus.js';\nimport { editable, setEntryKeepingComment } from './frontmatter.js';\nimport { readingIn, WITNESS_BUDGET } from './glob.js';\nimport { configuredSeverity } from './lint.js';\nimport { meet, type Overlap, type Scope, scopeOf, witnessText } from './scope.js';\nimport { encodeLike } from './text.js';\nimport type { Finding } from './types.js';\n\nexport interface ScheduleOptions {\n /** The files the tree holds, which say whether a literal path is a file or a directory. */\n readonly repoFiles?: readonly string[] | null;\n /** How many states one witness search may visit before it answers `undecided`. */\n readonly budget?: number;\n}\n\n/** A wave a brief could not join, and the brief already there that kept it out. */\nexport type Passed =\n | { readonly wave: number; readonly reason: 'collision'; readonly brief: Brief; readonly overlaps: readonly Overlap[] }\n | { readonly wave: number; readonly reason: 'undecided'; readonly brief: Brief; readonly patterns: readonly (readonly [string, string])[] }\n /** One of the two declares no affectedFiles, and an unscoped brief runs alone. */\n | { readonly wave: number; readonly reason: 'unscoped'; readonly brief: Brief };\n\n/**\n * Why a declared wave does not hold: what `matrix` or `lint` would report as\n * an error if the brief ran there.\n */\nexport type Breach =\n /** A brief the matrix compares, declaring the same wave, whose scope meets this one's. Overlaps name this brief's pattern first. */\n | { readonly reason: 'collision'; readonly brief: Brief; readonly overlaps: readonly Overlap[] }\n /** A live dependency declaring the same wave or a later one. */\n | { readonly reason: 'dependency'; readonly brief: Brief; readonly wave: number }\n /** A live brief depending on this one, declaring the same wave or an earlier one. */\n | { readonly reason: 'dependent'; readonly brief: Brief; readonly wave: number };\n\nexport interface Placement {\n readonly brief: Brief;\n /** The wave its front matter declares; `null` when it declares none it can read. */\n readonly declared: number | null;\n readonly proposed: number;\n /** The live dependency in the latest wave, which sets the earliest wave this one may run in. */\n readonly after: { readonly brief: Brief; readonly wave: number } | null;\n /** Every wave from that earliest one that it could not join, in order. Overlaps and patterns name its own pattern first. */\n readonly passed: readonly Passed[];\n /** Declares no affectedFiles, so it shares its wave with nobody. */\n readonly unscoped: boolean;\n /**\n * Why the declared wave does not hold, when it is not the proposed one. Empty\n * when it holds - a person moved the brief, and `lint` and `matrix` accept\n * the wave - and when there is no declared wave to judge.\n */\n readonly breaches: readonly Breach[];\n}\n\n/** A live brief that can be placed in no wave, and the dependency that holds it. */\nexport interface Unplaced {\n readonly brief: Brief;\n readonly waitsOn: Brief;\n /** The dependency is deferred, is in a dependency cycle, or is itself unplaced. */\n readonly because: 'deferred' | 'cycle' | 'unplaced';\n}\n\nexport interface Schedule {\n /** The first wave: the lowest any scheduled brief declares, or 1 when none declares one. */\n readonly first: number;\n /** In the order they were placed: dependency order, ties by id. */\n readonly placements: readonly Placement[];\n /** By id. */\n readonly unplaced: readonly Unplaced[];\n /** Dependency cycles among the scheduled briefs, each as a path back to its start. */\n readonly cycles: readonly (readonly Brief[])[];\n /** Deferred briefs, which wait for their trigger and run in no wave. By id. */\n readonly deferred: readonly Brief[];\n}\n\nfunction label(brief: Brief): string {\n return brief.id ?? brief.name;\n}\n\nexport { byId } from './corpus.js';\n\n/** The first brief in a wave this one cannot share it with, or `null` when it can join. */\nfunction clash(own: Scope, wave: number, here: readonly Scope[], budget: number, files: readonly string[] | null): Passed | null {\n for (const other of here) {\n if (own.affected.length === 0 || other.affected.length === 0) return { wave, reason: 'unscoped', brief: other.brief };\n const meeting = meet(own, other, budget, files);\n if (meeting.overlaps.length > 0) return { wave, reason: 'collision', brief: other.brief, overlaps: meeting.overlaps };\n if (meeting.undecided.length > 0) return { wave, reason: 'undecided', brief: other.brief, patterns: meeting.undecided };\n }\n return null;\n}\n\n/** What a declared wave is judged against. */\ninterface Judge {\n /** The briefs the matrix compares: none deferred, none waiting on deferred work. */\n readonly compared: readonly Brief[];\n /** Every live brief's live dependencies, the briefs in the order of their ids. */\n readonly dependencies: ReadonlyMap<Brief, readonly Brief[]>;\n /** The scope of every brief the schedule places or compares. */\n readonly scopes: ReadonlyMap<Brief, Scope>;\n readonly budget: number;\n readonly files: readonly string[] | null;\n}\n\n/**\n * Why a brief's declared wave does not hold, judged as `lint` and `matrix`\n * judge it: against the waves the other briefs declare, not the ones proposed.\n * Collisions are with the briefs the matrix compares; the dependency order is\n * wave-order's, both ways, over every live brief.\n */\nfunction breachesOf(brief: Brief, wave: number, judge: Judge): Breach[] {\n const out: Breach[] = [];\n for (const dependency of judge.dependencies.get(brief) as Brief[]) {\n if (dependency.wave !== null && dependency.wave >= wave) out.push({ reason: 'dependency', brief: dependency, wave: dependency.wave });\n }\n for (const [other, needs] of judge.dependencies) {\n if (other.wave !== null && other.wave <= wave && needs.includes(brief)) out.push({ reason: 'dependent', brief: other, wave: other.wave });\n }\n for (const other of judge.compared) {\n if (other === brief || other.wave !== wave) continue;\n const overlaps = meet(judge.scopes.get(brief) as Scope, judge.scopes.get(other) as Scope, judge.budget, judge.files).overlaps;\n if (overlaps.length > 0) out.push({ reason: 'collision', brief: other, overlaps });\n }\n return out;\n}\n\nexport function schedule(corpus: Corpus, options: ScheduleOptions = {}): Schedule {\n const files = options.repoFiles ?? null;\n const reading = readingIn(files);\n const budget = options.budget ?? WITNESS_BUDGET;\n const deferred = corpus.live.filter((b) => b.status === 'deferred').sort(byId);\n const briefs = corpus.live.filter((b) => b.status !== 'deferred').sort(byId);\n // Of deferred briefs too: lint's wave-order reads every live brief's wave.\n // In the order of the ids, which is the order a brief's dependents are named in.\n const dependencies = new Map([...corpus.live].sort(byId).map((b) => [b, liveDependencies(corpus, b)]));\n const declared = briefs.flatMap((b) => (b.wave === null ? [] : [b.wave]));\n const first = declared.length === 0 ? 1 : Math.min(...declared);\n const scopes = new Map(briefs.map((b) => [b, scopeOf(b, reading)]));\n const waiting = new Set(waitingOnDeferred(corpus).map((w) => w.brief));\n const judge: Judge = { compared: briefs.filter((b) => !waiting.has(b)), dependencies, scopes, budget, files };\n\n const waveOf = new Map<Brief, number>();\n const occupants = new Map<number, Scope[]>();\n const placements: Placement[] = [];\n const pending = [...briefs];\n // Kahn's order, taking the least id whose dependencies are all placed. A\n // brief waiting on a deferred one, or on a cycle, is never taken.\n for (;;) {\n const next = pending.find((b) => (dependencies.get(b) as Brief[]).every((d) => waveOf.has(d)));\n if (next === undefined) break;\n pending.splice(pending.indexOf(next), 1);\n let after: Placement['after'] = null;\n for (const dependency of dependencies.get(next) as Brief[]) {\n const wave = waveOf.get(dependency) as number;\n if (after === null || wave > after.wave) after = { brief: dependency, wave };\n }\n const own = scopes.get(next) as Scope;\n const passed: Passed[] = [];\n let wave = after === null ? first : after.wave + 1;\n // Ends by construction: a wave past every occupied one is empty, and an empty wave takes anyone.\n for (;;) {\n const found = clash(own, wave, occupants.get(wave) ?? [], budget, files);\n if (found === null) break;\n passed.push(found);\n wave += 1;\n }\n waveOf.set(next, wave);\n occupants.set(wave, [...(occupants.get(wave) ?? []), own]);\n const breaches = next.wave === null || next.wave === wave ? [] : breachesOf(next, next.wave, judge);\n placements.push({ brief: next, declared: next.wave, proposed: wave, after, passed, unscoped: own.affected.length === 0, breaches });\n }\n\n const cycles = dependencyCycles(corpus).filter((cycle) => cycle.every((b) => b.status !== 'deferred'));\n const inCycle = new Set(cycles.flat());\n const unplaced = pending.map((brief): Unplaced => {\n const waitsOn = (dependencies.get(brief) as Brief[]).find((d) => !waveOf.has(d)) as Brief;\n const because = waitsOn.status === 'deferred' ? 'deferred' : inCycle.has(waitsOn) ? 'cycle' : 'unplaced';\n return { brief, waitsOn, because };\n });\n return { first, placements, unplaced, cycles, deferred };\n}\n\n/** The briefs whose declared wave the schedule would change. */\nexport function moves(s: Schedule): Placement[] {\n return s.placements.filter((p) => p.proposed !== p.declared);\n}\n\n/**\n * Whether a brief's declared wave holds: it is the proposed one, or one a\n * person chose that `lint` and `matrix` accept. The schedule is one valid\n * answer, not the only one (ADR-0011, amended).\n */\nexport function holds(p: Placement): boolean {\n return p.declared !== null && p.breaches.length === 0;\n}\n\n/** Why a declared wave does not hold, a clause each. */\nexport function breachReasons(p: Placement): string[] {\n return p.breaches.map((b) => {\n if (b.reason === 'collision') return `${label(b.brief)} there also writes ${witnessText(b.overlaps[0] as Overlap)}`;\n if (b.reason === 'dependency') return `it depends on ${label(b.brief)}, in wave ${b.wave}`;\n return `${label(b.brief)} depends on it, in wave ${b.wave}`;\n });\n}\n\n/** Why a brief is in its wave and not an earlier one, a clause each. */\nexport function reasons(p: Placement): string[] {\n const out: string[] = [];\n if (p.after !== null) out.push(`after ${label(p.after.brief)}, in wave ${p.after.wave}`);\n if (p.unscoped && p.passed.length > 0) out.push('it declares no affectedFiles, so it runs in a wave of its own');\n for (const passed of p.passed) {\n const there = `not wave ${passed.wave}, where ${label(passed.brief)}`;\n if (passed.reason === 'collision') {\n const [overlap] = passed.overlaps as [Overlap];\n out.push(`${there} also writes ${witnessText(overlap)} (\"${overlap.patterns[0]}\" and \"${overlap.patterns[1]}\")`);\n } else if (passed.reason === 'undecided') {\n out.push(`${there} may write the same files: the search could not decide within its budget`);\n } else if (!p.unscoped) {\n out.push(`${there} declares no affectedFiles and runs alone`);\n }\n }\n if (out.length === 0) out.push('nothing holds it later');\n return out;\n}\n\n/** The schedule as findings: cycles, briefs whose waves would move, briefs that run alone, and pairs it could not decide. */\nexport function scheduleFindings(corpus: Corpus, s: Schedule): Finding[] {\n const findings: Finding[] = [];\n const cycle = configuredSeverity(corpus, 'dependency-cycle');\n if (cycle !== null) {\n for (const members of s.cycles) {\n const start = members[0] as Brief;\n findings.push({\n rule: 'dependency-cycle',\n severity: cycle,\n message: `dependencies form a cycle, so no wave can hold them: ${members.map(label).join(' -> ')}`,\n file: start.file,\n line: lineOfField(start, 'dependsOn') + 1,\n brief: start.id ?? undefined,\n hint: 'a cycle can never become ready; remove the dependency that is not real',\n subject: cycleSubject(members),\n });\n }\n }\n const change = configuredSeverity(corpus, 'wave-schedule');\n if (change !== null) {\n // A wave a person chose that lint and matrix accept is theirs to keep: a\n // note, so that CI passes it. One missing, or one that does not hold, is\n // the rule's finding at its configured severity.\n for (const p of moves(s)) {\n const valid = holds(p);\n const was =\n p.declared === null\n ? 'declares no wave'\n : valid\n ? `declares wave ${p.declared}, which holds`\n : `declares wave ${p.declared}, which does not hold (${breachReasons(p).join('; ')})`;\n findings.push({\n rule: 'wave-schedule',\n severity: valid ? 'note' : change,\n message: `${was}; the schedule puts it in wave ${p.proposed}: ${reasons(p).join('; ')}`,\n file: p.brief.file,\n line: lineOfField(p.brief, 'wave') + 1,\n brief: p.brief.id ?? undefined,\n hint: valid\n ? `keep wave ${p.declared as number}, or run \"spec-brief schedule --write\" for wave ${p.proposed}`\n : `run \"spec-brief schedule --write\", or set \"wave: ${p.proposed}\"`,\n });\n }\n }\n const unscoped = configuredSeverity(corpus, 'unscoped');\n if (unscoped !== null && s.placements.length > 1) {\n for (const p of s.placements.filter((x) => x.unscoped)) {\n findings.push(unscopedFinding(unscoped, p.brief, `the ${s.placements.length - 1} other brief(s) the schedule places; it runs alone in wave ${p.proposed}`));\n }\n }\n const undecided = configuredSeverity(corpus, 'collision-undecided');\n if (undecided !== null) {\n for (const p of s.placements) {\n for (const passed of p.passed) {\n if (passed.reason !== 'undecided') continue;\n const theirsFirst = passed.patterns.map(([own, theirs]) => [theirs, own] as const);\n findings.push(undecidedFinding(undecided, passed.brief, p.brief, theirsFirst, passed.wave));\n }\n }\n }\n return findings;\n}\n\nexport interface WavePlan {\n /** A write of each brief whose wave changes: its front matter's `wave`, and every other line as it was. */\n readonly ops: readonly FileOp[];\n /** Briefs whose wave cannot be written, which refuse the whole write. */\n readonly refused: readonly Finding[];\n}\n\n/** What `--write` writes. */\nexport function planWaves(s: Schedule): WavePlan {\n const ops: FileOp[] = [];\n const refused: Finding[] = [];\n for (const p of moves(s)) {\n const { brief } = p;\n if (brief.frontMatter !== null && !editable(brief.frontMatter)) {\n const open = brief.frontMatter.close === -1;\n refused.push({\n rule: 'front-matter',\n severity: 'error',\n message: `the front matter is ${open ? 'never closed' : 'TOML'}, so wave ${p.proposed} cannot be written into it`,\n file: brief.file,\n line: 1,\n brief: brief.id ?? undefined,\n hint: open ? 'close the front matter with a \"---\" line, and schedule again' : 'write the front matter as YAML between \"---\" lines, and schedule again',\n });\n continue;\n }\n const lines = setEntryKeepingComment(brief.lines, brief.frontMatter, 'wave', String(p.proposed));\n ops.push({ kind: 'write', path: brief.file, content: encodeLike(brief.source, lines), before: brief.source });\n }\n return { ops, refused };\n}\n"]}
package/dist/schema.js CHANGED
@@ -73,7 +73,7 @@ export function validate(schema, value, path = '') {
73
73
  if (schema.enum !== undefined && !schema.enum.includes(value)) {
74
74
  return [`${where} must be one of ${schema.enum.map((e) => `"${e}"`).join(', ')}, not "${value}"`];
75
75
  }
76
- if (schema.minLength !== undefined && value.length < schema.minLength)
76
+ if (value.length < (schema.minLength ?? 0))
77
77
  return [`${where} must not be empty`];
78
78
  return [];
79
79
  }
@@ -81,9 +81,9 @@ export function validate(schema, value, path = '') {
81
81
  const number = value;
82
82
  if (!Number.isInteger(number))
83
83
  return [`${where} must be an integer`];
84
- if (schema.minimum !== undefined && number < schema.minimum)
84
+ if (number < (schema.minimum ?? -Infinity))
85
85
  return [`${where} must be at least ${schema.minimum}`];
86
- if (schema.maximum !== undefined && number > schema.maximum)
86
+ if (number > (schema.maximum ?? Infinity))
87
87
  return [`${where} must be at most ${schema.maximum}`];
88
88
  return [];
89
89
  }
@@ -94,7 +94,8 @@ export function validate(schema, value, path = '') {
94
94
  const known = Object.keys(schema.properties);
95
95
  const problems = [];
96
96
  for (const key of Object.keys(record)) {
97
- const property = schema.properties[key];
97
+ // Its own keys only: `constructor` is on every object, and is no key of a configuration.
98
+ const property = Object.hasOwn(schema.properties, key) ? schema.properties[key] : undefined;
98
99
  if (property === undefined) {
99
100
  const guess = closest(key, known);
100
101
  problems.push(`"${at(path, key)}" is not a known key${guess === undefined ? '' : `; did you mean "${guess}"?`}`);
@@ -111,15 +112,10 @@ export function validate(schema, value, path = '') {
111
112
  case 'map':
112
113
  return Object.entries(value).flatMap(([key, item]) => validate(schema.values, item, at(path, key)));
113
114
  case 'anyOf': {
114
- const candidates = schema.options.filter((option) => accepts(option, kindOf(value)));
115
- let first;
116
- for (const option of candidates) {
117
- const problems = validate(option, value, path);
118
- if (problems.length === 0)
119
- return [];
120
- first ??= problems;
121
- }
122
- return first ?? [];
115
+ // Some option accepts the value's kind, or the check above would have answered: there is a first.
116
+ const kind = kindOf(value);
117
+ const problems = schema.options.filter((option) => accepts(option, kind)).map((option) => validate(option, value, path));
118
+ return problems.some((found) => found.length === 0) ? [] : problems[0];
123
119
  }
124
120
  case 'boolean':
125
121
  case 'any':
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2BH,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACzC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,MAAc,EAAE,IAAU;IACzC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,QAAQ;YACX,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;QAC5E,KAAK,SAAS;YACZ,OAAO,IAAI,KAAK,SAAS,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,IAAI,KAAK,QAAQ,CAAC;QAC3B,KAAK,OAAO;YACV,O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B,CAAC;AACH,CAAC","sourcesContent":["/**\n * A small schema language: one description that both validates a value and\n * renders as JSON Schema, so the published `schema.json` and the checks the\n * loader runs cannot disagree about what a configuration may say.\n */\n\ninterface Described {\n readonly description?: string;\n}\n\nexport type Schema =\n | (Described & {\n readonly type: 'string';\n readonly enum?: readonly string[];\n readonly nullable?: boolean;\n readonly minLength?: number;\n })\n | (Described & { readonly type: 'boolean' })\n | (Described & { readonly type: 'integer'; readonly minimum?: number; readonly maximum?: number })\n | (Described & { readonly type: 'array'; readonly items: Schema })\n | (Described & {\n readonly type: 'object';\n readonly properties: Readonly<Record<string, Schema>>;\n readonly required?: readonly string[];\n })\n | (Described & { readonly type: 'map'; readonly values: Schema })\n | (Described & { readonly type: 'anyOf'; readonly options: readonly Schema[] })\n | (Described & { readonly type: 'any' });\n\ntype Kind = 'null' | 'string' | 'boolean' | 'number' | 'array' | 'object';\n\nfunction kindOf(value: unknown): Kind {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n switch (typeof value) {\n case 'string':\n return 'string';\n case 'boolean':\n return 'boolean';\n case 'number':\n return 'number';\n default:\n return 'object';\n }\n}\n\nfunction accepts(schema: Schema, kind: Kind): boolean {\n switch (schema.type) {\n case 'string':\n return kind === 'string' || (kind === 'null' && schema.nullable === true);\n case 'boolean':\n return kind === 'boolean';\n case 'integer':\n return kind === 'number';\n case 'array':\n return kind === 'array';\n case 'object':\n case 'map':\n return kind === 'object';\n case 'anyOf':\n return schema.options.some((option) => accepts(option, kind));\n case 'any':\n return true;\n }\n}\n\nfunction noun(schema: Schema): string {\n switch (schema.type) {\n case 'string':\n return schema.nullable === true ? 'a string or null' : 'a string';\n case 'boolean':\n return 'true or false';\n case 'integer':\n return 'an integer';\n case 'array':\n return 'a list';\n case 'object':\n case 'map':\n return 'an object';\n case 'anyOf':\n return schema.options.map(noun).join(' or ');\n /* v8 ignore next 2 -- \"any\" accepts every value, so no message ever names it. */\n case 'any':\n return 'anything';\n }\n}\n\nfunction at(path: string, key: string): string {\n return path === '' ? key : `${path}.${key}`;\n}\n\n/** The problems with `value`, each naming the path to it. Empty when it conforms. */\nexport function validate(schema: Schema, value: unknown, path = ''): string[] {\n const where = path === '' ? 'the configuration' : `\"${path}\"`;\n if (!accepts(schema, kindOf(value))) return [`${where} must be ${noun(schema)}`];\n switch (schema.type) {\n case 'string': {\n if (typeof value !== 'string') return [];\n if (schema.enum !== undefined && !schema.enum.includes(value)) {\n return [`${where} must be one of ${schema.enum.map((e) => `\"${e}\"`).join(', ')}, not \"${value}\"`];\n }\n if (schema.minLength !== undefined && value.length < schema.minLength) return [`${where} must not be empty`];\n return [];\n }\n case 'integer': {\n const number = value as number;\n if (!Number.isInteger(number)) return [`${where} must be an integer`];\n if (schema.minimum !== undefined && number < schema.minimum) return [`${where} must be at least ${schema.minimum}`];\n if (schema.maximum !== undefined && number > schema.maximum) return [`${where} must be at most ${schema.maximum}`];\n return [];\n }\n case 'array':\n return (value as unknown[]).flatMap((item, i) => validate(schema.items, item, `${path}[${i}]`));\n case 'object': {\n const record = value as Record<string, unknown>;\n const known = Object.keys(schema.properties);\n const problems: string[] = [];\n for (const key of Object.keys(record)) {\n const property = schema.properties[key];\n if (property === undefined) {\n const guess = closest(key, known);\n problems.push(`\"${at(path, key)}\" is not a known key${guess === undefined ? '' : `; did you mean \"${guess}\"?`}`);\n continue;\n }\n problems.push(...validate(property, record[key], at(path, key)));\n }\n for (const key of schema.required ?? []) {\n if (!(key in record)) problems.push(`\"${at(path, key)}\" is required`);\n }\n return problems;\n }\n case 'map':\n return Object.entries(value as Record<string, unknown>).flatMap(([key, item]) =>\n validate(schema.values, item, at(path, key)),\n );\n case 'anyOf': {\n const candidates = schema.options.filter((option) => accepts(option, kindOf(value)));\n let first: string[] | undefined;\n for (const option of candidates) {\n const problems = validate(option, value, path);\n if (problems.length === 0) return [];\n first ??= problems;\n }\n return first ?? [];\n }\n case 'boolean':\n case 'any':\n return [];\n }\n}\n\n/**\n * The known key nearest to a misspelling, when one is near enough to be what\n * was meant. One that keeps no character of the word is no misspelling of it,\n * however short both are: `狀態` is two edits from `id`.\n */\nexport function closest(word: string, options: readonly string[]): string | undefined {\n let best: string | undefined;\n let bestDistance = Math.max(2, Math.floor(word.length / 3)) + 1;\n for (const option of options) {\n const d = distance(word.toLowerCase(), option.toLowerCase());\n if (d < bestDistance && d < Math.max(word.length, option.length)) {\n best = option;\n bestDistance = d;\n }\n }\n return best;\n}\n\nfunction distance(a: string, b: string): number {\n let previous = Array.from({ length: b.length + 1 }, (_, j) => j);\n for (let i = 1; i <= a.length; i += 1) {\n const row = [i];\n for (let j = 1; j <= b.length; j += 1) {\n const cost = a.charAt(i - 1) === b.charAt(j - 1) ? 0 : 1;\n row.push(Math.min((previous[j] as number) + 1, (row[j - 1] as number) + 1, (previous[j - 1] as number) + cost));\n }\n previous = row;\n }\n return previous[b.length] as number;\n}\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json };\n\n/** Renders a schema as JSON Schema (draft 2020-12). */\nexport function toJsonSchema(schema: Schema): { [key: string]: Json } {\n const described = (body: { [key: string]: Json }): { [key: string]: Json } =>\n schema.description === undefined ? body : { description: schema.description, ...body };\n switch (schema.type) {\n case 'string': {\n const body: { [key: string]: Json } = { type: schema.nullable === true ? ['string', 'null'] : 'string' };\n if (schema.enum !== undefined) body['enum'] = [...schema.enum, ...(schema.nullable === true ? [null] : [])];\n if (schema.minLength !== undefined) body['minLength'] = schema.minLength;\n return described(body);\n }\n case 'boolean':\n return described({ type: 'boolean' });\n case 'integer': {\n const body: { [key: string]: Json } = { type: 'integer' };\n if (schema.minimum !== undefined) body['minimum'] = schema.minimum;\n if (schema.maximum !== undefined) body['maximum'] = schema.maximum;\n return described(body);\n }\n case 'array':\n return described({ type: 'array', items: toJsonSchema(schema.items) });\n case 'object': {\n const properties: { [key: string]: Json } = {};\n for (const [key, value] of Object.entries(schema.properties)) properties[key] = toJsonSchema(value);\n const body: { [key: string]: Json } = { type: 'object', properties, additionalProperties: false };\n if (schema.required !== undefined && schema.required.length > 0) body['required'] = [...schema.required];\n return described(body);\n }\n case 'map':\n return described({ type: 'object', additionalProperties: toJsonSchema(schema.values) });\n case 'anyOf':\n return described({ anyOf: schema.options.map(toJsonSchema) });\n case 'any':\n return described({});\n }\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2BH,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACzC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,MAAc,EAAE,IAAU;IACzC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,QAAQ;YACX,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;QAC5E,KAAK,SAAS;YACZ,OAAO,IAAI,KAAK,SAAS,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,IAAI,KAAK,QAAQ,CAAC;QAC3B,KAAK,OAAO;YACV,OAAO,IAAI,KAAK,OAAO,CAAC;QAC1B,KAAK,QAAQ,CAAC;QACd,KAAK,KAAK;YACR,OAAO,IAAI,KAAK,QAAQ,CAAC;QAC3B,KAAK,OAAO;YACV,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CA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AM,CAAC,OAAO,CAAC;YACnE,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,KAAK,OAAO;YACV,OAAO,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzE,KAAK,QAAQ,EAAE,CAAC;YACd,MAAM,UAAU,GAA4B,EAAE,CAAC;YAC/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;gBAAE,UAAU,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YACpG,MAAM,IAAI,GAA4B,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;YAClG,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YACzG,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1F,KAAK,OAAO;YACV,OAAO,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QAChE,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;AACH,CAAC","sourcesContent":["/**\n * A small schema language: one description that both validates a value and\n * renders as JSON Schema, so the published `schema.json` and the checks the\n * loader runs cannot disagree about what a configuration may say.\n */\n\ninterface Described {\n readonly description?: string;\n}\n\nexport type Schema =\n | (Described & {\n readonly type: 'string';\n readonly enum?: readonly string[];\n readonly nullable?: boolean;\n readonly minLength?: number;\n })\n | (Described & { readonly type: 'boolean' })\n | (Described & { readonly type: 'integer'; readonly minimum?: number; readonly maximum?: number })\n | (Described & { readonly type: 'array'; readonly items: Schema })\n | (Described & {\n readonly type: 'object';\n readonly properties: Readonly<Record<string, Schema>>;\n readonly required?: readonly string[];\n })\n | (Described & { readonly type: 'map'; readonly values: Schema })\n | (Described & { readonly type: 'anyOf'; readonly options: readonly Schema[] })\n | (Described & { readonly type: 'any' });\n\ntype Kind = 'null' | 'string' | 'boolean' | 'number' | 'array' | 'object';\n\nfunction kindOf(value: unknown): Kind {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n switch (typeof value) {\n case 'string':\n return 'string';\n case 'boolean':\n return 'boolean';\n case 'number':\n return 'number';\n default:\n return 'object';\n }\n}\n\nfunction accepts(schema: Schema, kind: Kind): boolean {\n switch (schema.type) {\n case 'string':\n return kind === 'string' || (kind === 'null' && schema.nullable === true);\n case 'boolean':\n return kind === 'boolean';\n case 'integer':\n return kind === 'number';\n case 'array':\n return kind === 'array';\n case 'object':\n case 'map':\n return kind === 'object';\n case 'anyOf':\n return schema.options.some((option) => accepts(option, kind));\n case 'any':\n return true;\n }\n}\n\nfunction noun(schema: Schema): string {\n switch (schema.type) {\n case 'string':\n return schema.nullable === true ? 'a string or null' : 'a string';\n case 'boolean':\n return 'true or false';\n case 'integer':\n return 'an integer';\n case 'array':\n return 'a list';\n case 'object':\n case 'map':\n return 'an object';\n case 'anyOf':\n return schema.options.map(noun).join(' or ');\n /* v8 ignore next 2 -- \"any\" accepts every value, so no message ever names it. */\n case 'any':\n return 'anything';\n }\n}\n\nfunction at(path: string, key: string): string {\n return path === '' ? key : `${path}.${key}`;\n}\n\n/** The problems with `value`, each naming the path to it. Empty when it conforms. */\nexport function validate(schema: Schema, value: unknown, path = ''): string[] {\n const where = path === '' ? 'the configuration' : `\"${path}\"`;\n if (!accepts(schema, kindOf(value))) return [`${where} must be ${noun(schema)}`];\n switch (schema.type) {\n case 'string': {\n if (typeof value !== 'string') return [];\n if (schema.enum !== undefined && !schema.enum.includes(value)) {\n return [`${where} must be one of ${schema.enum.map((e) => `\"${e}\"`).join(', ')}, not \"${value}\"`];\n }\n if (value.length < (schema.minLength ?? 0)) return [`${where} must not be empty`];\n return [];\n }\n case 'integer': {\n const number = value as number;\n if (!Number.isInteger(number)) return [`${where} must be an integer`];\n if (number < (schema.minimum ?? -Infinity)) return [`${where} must be at least ${schema.minimum}`];\n if (number > (schema.maximum ?? Infinity)) return [`${where} must be at most ${schema.maximum}`];\n return [];\n }\n case 'array':\n return (value as unknown[]).flatMap((item, i) => validate(schema.items, item, `${path}[${i}]`));\n case 'object': {\n const record = value as Record<string, unknown>;\n const known = Object.keys(schema.properties);\n const problems: string[] = [];\n for (const key of Object.keys(record)) {\n // Its own keys only: `constructor` is on every object, and is no key of a configuration.\n const property = Object.hasOwn(schema.properties, key) ? schema.properties[key] : undefined;\n if (property === undefined) {\n const guess = closest(key, known);\n problems.push(`\"${at(path, key)}\" is not a known key${guess === undefined ? '' : `; did you mean \"${guess}\"?`}`);\n continue;\n }\n problems.push(...validate(property, record[key], at(path, key)));\n }\n for (const key of schema.required ?? []) {\n if (!(key in record)) problems.push(`\"${at(path, key)}\" is required`);\n }\n return problems;\n }\n case 'map':\n return Object.entries(value as Record<string, unknown>).flatMap(([key, item]) =>\n validate(schema.values, item, at(path, key)),\n );\n case 'anyOf': {\n // Some option accepts the value's kind, or the check above would have answered: there is a first.\n const kind = kindOf(value);\n const problems = schema.options.filter((option) => accepts(option, kind)).map((option) => validate(option, value, path));\n return problems.some((found) => found.length === 0) ? [] : (problems[0] as string[]);\n }\n case 'boolean':\n case 'any':\n return [];\n }\n}\n\n/**\n * The known key nearest to a misspelling, when one is near enough to be what\n * was meant. One that keeps no character of the word is no misspelling of it,\n * however short both are: `狀態` is two edits from `id`.\n */\nexport function closest(word: string, options: readonly string[]): string | undefined {\n let best: string | undefined;\n let bestDistance = Math.max(2, Math.floor(word.length / 3)) + 1;\n for (const option of options) {\n const d = distance(word.toLowerCase(), option.toLowerCase());\n if (d < bestDistance && d < Math.max(word.length, option.length)) {\n best = option;\n bestDistance = d;\n }\n }\n return best;\n}\n\nfunction distance(a: string, b: string): number {\n let previous = Array.from({ length: b.length + 1 }, (_, j) => j);\n for (let i = 1; i <= a.length; i += 1) {\n const row = [i];\n for (let j = 1; j <= b.length; j += 1) {\n const cost = a.charAt(i - 1) === b.charAt(j - 1) ? 0 : 1;\n row.push(Math.min((previous[j] as number) + 1, (row[j - 1] as number) + 1, (previous[j - 1] as number) + cost));\n }\n previous = row;\n }\n return previous[b.length] as number;\n}\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json };\n\n/** Renders a schema as JSON Schema (draft 2020-12). */\nexport function toJsonSchema(schema: Schema): { [key: string]: Json } {\n const described = (body: { [key: string]: Json }): { [key: string]: Json } =>\n schema.description === undefined ? body : { description: schema.description, ...body };\n switch (schema.type) {\n case 'string': {\n const body: { [key: string]: Json } = { type: schema.nullable === true ? ['string', 'null'] : 'string' };\n if (schema.enum !== undefined) body['enum'] = [...schema.enum, ...(schema.nullable === true ? [null] : [])];\n if (schema.minLength !== undefined) body['minLength'] = schema.minLength;\n return described(body);\n }\n case 'boolean':\n return described({ type: 'boolean' });\n case 'integer': {\n const body: { [key: string]: Json } = { type: 'integer' };\n if (schema.minimum !== undefined) body['minimum'] = schema.minimum;\n if (schema.maximum !== undefined) body['maximum'] = schema.maximum;\n return described(body);\n }\n case 'array':\n return described({ type: 'array', items: toJsonSchema(schema.items) });\n case 'object': {\n const properties: { [key: string]: Json } = {};\n for (const [key, value] of Object.entries(schema.properties)) properties[key] = toJsonSchema(value);\n const body: { [key: string]: Json } = { type: 'object', properties, additionalProperties: false };\n if (schema.required !== undefined && schema.required.length > 0) body['required'] = [...schema.required];\n return described(body);\n }\n case 'map':\n return described({ type: 'object', additionalProperties: toJsonSchema(schema.values) });\n case 'anyOf':\n return described({ anyOf: schema.options.map(toJsonSchema) });\n case 'any':\n return described({});\n }\n}\n"]}
package/dist/scope.js CHANGED
@@ -9,7 +9,7 @@
9
9
  * the tree holds, or else the shortest such path the search builds, as an
10
10
  * example (ADR-0005).
11
11
  */
12
- import { globCovers, globWitness, matchGlob, parseGlob, WITNESS_BUDGET } from './glob.js';
12
+ import { filesMatching, globCovers, globWitness, matchGlob, parseGlob, WITNESS_BUDGET } from './glob.js';
13
13
  /** Patterns that parse, read with one reading. */
14
14
  export function patternsOf(patterns, reading) {
15
15
  return patterns.flatMap((pattern) => {
@@ -34,7 +34,7 @@ function matching(files, glob) {
34
34
  }
35
35
  let found = byGlob.get(glob);
36
36
  if (found === undefined) {
37
- found = new Set(files.filter((file) => matchGlob(glob, file)));
37
+ found = new Set(filesMatching(glob, files));
38
38
  byGlob.set(glob, found);
39
39
  }
40
40
  return found;
package/dist/scope.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAa,UAAU,EAAE,WAAW,EAAuB,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAiB1H,kDAAkD;AAClD,MAAM,UAAU,UAAU,CAAC,QAA2B,EAAE,OAAgB;IACtE,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAA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ief's scope, and whether two briefs can write the same file.\n *\n * What a brief may write is its `affectedFiles` less its `protectedFiles`:\n * protection wins, so \"all of `src/` but the schema\" is written\n * `affectedFiles: [src/**]` with `protectedFiles: [src/db/schema.ts]`. Two\n * briefs meet when some file lies in both writable scopes - in a pattern of\n * each, and in neither brief's protections - and the witness is such a file\n * the tree holds, or else the shortest such path the search builds, as an\n * example (ADR-0005).\n */\n\nimport type { Brief } from './brief.js';\nimport { type Glob, globCovers, globWitness, type LiteralReading, matchGlob, parseGlob, WITNESS_BUDGET } from './glob.js';\n\n/** How a literal path is read, as {@link readingIn} answers for a tree. */\nexport type Reading = (path: string) => LiteralReading;\n\nexport interface ScopePattern {\n readonly pattern: string;\n readonly glob: Glob;\n}\n\nexport interface Scope {\n readonly brief: Brief;\n /** The `affectedFiles` that parse. One that does not is the `glob` rule's finding, and scopes nothing. */\n readonly affected: readonly ScopePattern[];\n readonly protected: readonly ScopePattern[];\n}\n\n/** Patterns that parse, read with one reading. */\nexport function patternsOf(patterns: readonly string[], reading: Reading): ScopePattern[] {\n return patterns.flatMap((pattern) => {\n const parsed = parseGlob(pattern, { literal: reading });\n return parsed.ok ? [{ pattern, glob: parsed.glob }] : [];\n });\n}\n\nexport function scopeOf(brief: Brief, reading: Reading): Scope {\n return { brief, affected: patternsOf(brief.affectedFiles, reading), protected: patternsOf(brief.protectedFiles, reading) };\n}\n\n/** A pattern from each scope, and a file both may write. */\nexport interface Overlap {\n readonly patterns: readonly [string, string];\n readonly witness: string;\n /**\n * `true` when the witness is a file the tree holds; `false` when the tree\n * holds none both patterns match outside the protections, and the witness\n * is an example the search built; `null` when no tree was given.\n */\n readonly inTree: boolean | null;\n}\n\nexport interface Meeting {\n /** Every pair of patterns that meets outside both protections, the first scope's pattern first. */\n readonly overlaps: readonly Overlap[];\n /** Pairs of patterns the search could not decide within its budget, and no file of the tree decides. */\n readonly undecided: readonly (readonly [string, string])[];\n}\n\nconst matched = new WeakMap<readonly string[], WeakMap<Glob, ReadonlySet<string>>>();\n\n/**\n * The files of a tree a pattern matches, in the tree's order. Found once per\n * pattern and tree, which every pair a brief is in shares; kept or not, the\n * answer is the same, and only the time differs.\n */\nfunction matching(files: readonly string[], glob: Glob): ReadonlySet<string> {\n let byGlob = matched.get(files);\n if (byGlob === undefined) {\n byGlob = new WeakMap();\n matched.set(files, byGlob);\n }\n let found = byGlob.get(glob);\n if (found === undefined) {\n found = new Set(files.filter((file) => matchGlob(glob, file)));\n byGlob.set(glob, found);\n }\n return found;\n}\n\n/**\n * The first file of the tree, in its order, that both patterns match and no\n * protection does. The engine's list is sorted, so the file named is the same\n * on every run.\n */\nfunction heldInBoth(files: readonly string[], x: Glob, y: Glob, avoid: readonly Glob[]): string | undefined {\n const other = matching(files, y);\n for (const file of matching(files, x)) {\n if (other.has(file) && !avoid.some((glob) => matchGlob(glob, file))) return file;\n }\n return undefined;\n}\n\n/**\n * Where two writable scopes meet. Each pair of affected patterns is searched\n * for a file both cover that neither brief protects: a file one brief protects\n * is one that brief will not write, so it is no collision.\n *\n * The search names the shortest such path, which the tree need not hold:\n * `src/Shop/OrderService.cs` where the tree has `src/Shop/Orders/OrderService.cs`.\n * So where the search finds a meeting, or cannot decide one, the tree's files\n * are read, and the first both patterns match outside the protections is the\n * witness (ADR-0005, amended 2026-09-30). A file that exists and both briefs\n * may write settles a pair the search could not: it is a collision, proved by\n * the file, not a guess. Where the tree holds none, the search's path stands,\n * as an example. A pair the search proves apart has no such file, and the tree\n * is not read for it.\n */\nexport function meet(a: Scope, b: Scope, budget: number = WITNESS_BUDGET, files: readonly string[] | null = null): Meeting {\n const avoid = [...a.protected, ...b.protected].map((p) => p.glob);\n const overlaps: Overlap[] = [];\n const undecided: (readonly [string, string])[] = [];\n for (const x of a.affected) {\n for (const y of b.affected) {\n const witness = globWitness([x.glob, y.glob], avoid, budget);\n if (witness.kind === 'none') continue;\n const patterns = [x.pattern, y.pattern] as const;\n const held = files === null ? undefined : heldInBoth(files, x.glob, y.glob, avoid);\n if (held !== undefined) overlaps.push({ patterns, witness: held, inTree: true });\n else if (witness.kind === 'found') overlaps.push({ patterns, witness: witness.path, inTree: files === null ? null : false });\n else undecided.push(patterns);\n }\n }\n return { overlaps, undecided };\n}\n\n/**\n * A witness as a reader is told it: a file of the tree by its path, and a path\n * the search built with a word that it is an example.\n */\nexport function witnessText(overlap: Overlap): string {\n return overlap.inTree === false ? `${overlap.witness}, an example not in the tree` : overlap.witness;\n}\n\nexport interface Contradiction {\n /** Affected patterns every file of which is protected: nothing of them is writable. */\n readonly covered: readonly string[];\n /** Affected patterns for which the search could not decide within its budget. */\n readonly undecided: readonly string[];\n}\n\n/** The affected patterns a brief's own protections cover entirely. */\nexport function contradictions(scope: Scope, budget: number = WITNESS_BUDGET): Contradiction {\n const covered: string[] = [];\n const undecided: string[] = [];\n const outer = scope.protected.map((p) => p.glob);\n for (const { pattern, glob } of scope.affected) {\n const answer = globCovers(outer, glob, budget);\n if (answer === true) covered.push(pattern);\n else if (answer === 'undecided') undecided.push(pattern);\n }\n return { covered, undecided };\n}\n"]}
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,aAAa,EAAa,UAAU,EAAE,WAAW,EAAuB,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAiBzI,kDAAkD;AAClD,MAAM,UAAU,UAAU,CAAC,QAA2B,EAAE,OAAgB;IACtE,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3D,CAAC,CAA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ief may write is its `affectedFiles` less its `protectedFiles`:\n * protection wins, so \"all of `src/` but the schema\" is written\n * `affectedFiles: [src/**]` with `protectedFiles: [src/db/schema.ts]`. Two\n * briefs meet when some file lies in both writable scopes - in a pattern of\n * each, and in neither brief's protections - and the witness is such a file\n * the tree holds, or else the shortest such path the search builds, as an\n * example (ADR-0005).\n */\n\nimport type { Brief } from './brief.js';\nimport { filesMatching, type Glob, globCovers, globWitness, type LiteralReading, matchGlob, parseGlob, WITNESS_BUDGET } from './glob.js';\n\n/** How a literal path is read, as {@link readingIn} answers for a tree. */\nexport type Reading = (path: string) => LiteralReading;\n\nexport interface ScopePattern {\n readonly pattern: string;\n readonly glob: Glob;\n}\n\nexport interface Scope {\n readonly brief: Brief;\n /** The `affectedFiles` that parse. One that does not is the `glob` rule's finding, and scopes nothing. */\n readonly affected: readonly ScopePattern[];\n readonly protected: readonly ScopePattern[];\n}\n\n/** Patterns that parse, read with one reading. */\nexport function patternsOf(patterns: readonly string[], reading: Reading): ScopePattern[] {\n return patterns.flatMap((pattern) => {\n const parsed = parseGlob(pattern, { literal: reading });\n return parsed.ok ? [{ pattern, glob: parsed.glob }] : [];\n });\n}\n\nexport function scopeOf(brief: Brief, reading: Reading): Scope {\n return { brief, affected: patternsOf(brief.affectedFiles, reading), protected: patternsOf(brief.protectedFiles, reading) };\n}\n\n/** A pattern from each scope, and a file both may write. */\nexport interface Overlap {\n readonly patterns: readonly [string, string];\n readonly witness: string;\n /**\n * `true` when the witness is a file the tree holds; `false` when the tree\n * holds none both patterns match outside the protections, and the witness\n * is an example the search built; `null` when no tree was given.\n */\n readonly inTree: boolean | null;\n}\n\nexport interface Meeting {\n /** Every pair of patterns that meets outside both protections, the first scope's pattern first. */\n readonly overlaps: readonly Overlap[];\n /** Pairs of patterns the search could not decide within its budget, and no file of the tree decides. */\n readonly undecided: readonly (readonly [string, string])[];\n}\n\nconst matched = new WeakMap<readonly string[], WeakMap<Glob, ReadonlySet<string>>>();\n\n/**\n * The files of a tree a pattern matches, in the tree's order. Found once per\n * pattern and tree, which every pair a brief is in shares; kept or not, the\n * answer is the same, and only the time differs.\n */\nfunction matching(files: readonly string[], glob: Glob): ReadonlySet<string> {\n let byGlob = matched.get(files);\n if (byGlob === undefined) {\n byGlob = new WeakMap();\n matched.set(files, byGlob);\n }\n let found = byGlob.get(glob);\n if (found === undefined) {\n found = new Set(filesMatching(glob, files));\n byGlob.set(glob, found);\n }\n return found;\n}\n\n/**\n * The first file of the tree, in its order, that both patterns match and no\n * protection does. The engine's list is sorted, so the file named is the same\n * on every run.\n */\nfunction heldInBoth(files: readonly string[], x: Glob, y: Glob, avoid: readonly Glob[]): string | undefined {\n const other = matching(files, y);\n for (const file of matching(files, x)) {\n if (other.has(file) && !avoid.some((glob) => matchGlob(glob, file))) return file;\n }\n return undefined;\n}\n\n/**\n * Where two writable scopes meet. Each pair of affected patterns is searched\n * for a file both cover that neither brief protects: a file one brief protects\n * is one that brief will not write, so it is no collision.\n *\n * The search names the shortest such path, which the tree need not hold:\n * `src/Shop/OrderService.cs` where the tree has `src/Shop/Orders/OrderService.cs`.\n * So where the search finds a meeting, or cannot decide one, the tree's files\n * are read, and the first both patterns match outside the protections is the\n * witness (ADR-0005, amended 2026-09-30). A file that exists and both briefs\n * may write settles a pair the search could not: it is a collision, proved by\n * the file, not a guess. Where the tree holds none, the search's path stands,\n * as an example. A pair the search proves apart has no such file, and the tree\n * is not read for it.\n */\nexport function meet(a: Scope, b: Scope, budget: number = WITNESS_BUDGET, files: readonly string[] | null = null): Meeting {\n const avoid = [...a.protected, ...b.protected].map((p) => p.glob);\n const overlaps: Overlap[] = [];\n const undecided: (readonly [string, string])[] = [];\n for (const x of a.affected) {\n for (const y of b.affected) {\n const witness = globWitness([x.glob, y.glob], avoid, budget);\n if (witness.kind === 'none') continue;\n const patterns = [x.pattern, y.pattern] as const;\n const held = files === null ? undefined : heldInBoth(files, x.glob, y.glob, avoid);\n if (held !== undefined) overlaps.push({ patterns, witness: held, inTree: true });\n else if (witness.kind === 'found') overlaps.push({ patterns, witness: witness.path, inTree: files === null ? null : false });\n else undecided.push(patterns);\n }\n }\n return { overlaps, undecided };\n}\n\n/**\n * A witness as a reader is told it: a file of the tree by its path, and a path\n * the search built with a word that it is an example.\n */\nexport function witnessText(overlap: Overlap): string {\n return overlap.inTree === false ? `${overlap.witness}, an example not in the tree` : overlap.witness;\n}\n\nexport interface Contradiction {\n /** Affected patterns every file of which is protected: nothing of them is writable. */\n readonly covered: readonly string[];\n /** Affected patterns for which the search could not decide within its budget. */\n readonly undecided: readonly string[];\n}\n\n/** The affected patterns a brief's own protections cover entirely. */\nexport function contradictions(scope: Scope, budget: number = WITNESS_BUDGET): Contradiction {\n const covered: string[] = [];\n const undecided: string[] = [];\n const outer = scope.protected.map((p) => p.glob);\n for (const { pattern, glob } of scope.affected) {\n const answer = globCovers(outer, glob, budget);\n if (answer === true) covered.push(pattern);\n else if (answer === 'undecided') undecided.push(pattern);\n }\n return { covered, undecided };\n}\n"]}
package/dist/text.d.ts CHANGED
@@ -47,7 +47,10 @@ export declare function labelMatches(heading: string, name: string): boolean;
47
47
  export declare function slugify(title: string, maxLength?: number): string;
48
48
  /** `a`, `a and b`, `a, b and c`. */
49
49
  export declare function inWords(items: readonly string[]): string;
50
- /** Fills `{name}` holes. An unknown name is left as written. */
50
+ /**
51
+ * Fills `{name}` holes. An unknown name is left as written, and a name every
52
+ * object answers to, `{constructor}`, is unknown unless it was given.
53
+ */
51
54
  export declare function fillTemplate(template: string, values: Readonly<Record<string, string>>): string;
52
55
  /** The `{name}` holes a template line refers to. */
53
56
  export declare function templateHoles(template: string): string[];
package/dist/text.js CHANGED
@@ -60,7 +60,7 @@ export function normaliseLabel(label) {
60
60
  .replace(/[\u2018\u2019\u201b\u2032\u00b4]/g, "'")
61
61
  .replace(/[\u201c\u201d\u201f\u2033]/g, '"')
62
62
  .replace(/[*_`]/g, '')
63
- .replace(/^\s*\d+(?:\.\d+)*[.)]?\s+/, '')
63
+ .replace(/^\s*\d+(?:\.\d+)*[.)]?\s/, '')
64
64
  .replace(/\s*:\s*$/, '')
65
65
  .replace(/\s+/g, ' ')
66
66
  .trim()
@@ -80,8 +80,9 @@ export function labelMatches(heading, name) {
80
80
  return true;
81
81
  if (!h.startsWith(n))
82
82
  return false;
83
+ // Normalised, so whitespace is single spaces.
83
84
  const rest = h.slice(n.length);
84
- return /^(?:\s*[:(\u2014\u2013]|\s+-\s)/.test(rest);
85
+ return /^(?:\s*[:(\u2014\u2013]|\s-\s)/.test(rest);
85
86
  }
86
87
  /**
87
88
  * A file-name slug: lower case, ASCII letters and digits, single hyphens.
@@ -93,7 +94,7 @@ export function slugify(title, maxLength = 80) {
93
94
  .replace(/[\u0300-\u036f]/g, '')
94
95
  .toLowerCase()
95
96
  .replace(/[^a-z0-9]+/g, '-')
96
- .replace(/^-+|-+$/g, '');
97
+ .replace(/^-|-$/g, '');
97
98
  if (slug.length <= maxLength)
98
99
  return slug;
99
100
  const cut = slug.slice(0, maxLength);
@@ -101,15 +102,18 @@ export function slugify(title, maxLength = 80) {
101
102
  if (slug.charAt(maxLength) === '-')
102
103
  return cut;
103
104
  const lastBreak = cut.lastIndexOf('-');
104
- return lastBreak > 0 ? cut.slice(0, lastBreak) : cut;
105
+ return lastBreak === -1 ? cut : cut.slice(0, lastBreak);
105
106
  }
106
107
  /** `a`, `a and b`, `a, b and c`. */
107
108
  export function inWords(items) {
108
109
  return items.length < 2 ? (items[0] ?? '') : `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}`;
109
110
  }
110
- /** Fills `{name}` holes. An unknown name is left as written. */
111
+ /**
112
+ * Fills `{name}` holes. An unknown name is left as written, and a name every
113
+ * object answers to, `{constructor}`, is unknown unless it was given.
114
+ */
111
115
  export function fillTemplate(template, values) {
112
- return template.replace(/\{([A-Za-z]+)\}/g, (hole, name) => values[name] ?? hole);
116
+ return template.replace(/\{([A-Za-z]+)\}/g, (hole, name) => (Object.hasOwn(values, name) ? values[name] : hole));
113
117
  }
114
118
  /** The `{name}` holes a template line refers to. */
115
119
  export function templateHoles(template) {
package/dist/text.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,sFAAsF;AACtF,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,CAAC;IACpE,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,KAAwB;IAClD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,SAAS,CAAC,KAAwB,EAAE,GAAkB;IACpE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC;AAC9D,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,KAAwB;IACjE,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC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,UAAU,OAAO,CAAC,KAAwB;IAC9C,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAW,EAAE,CAAC;AAC3H,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,MAAwC;IACrF,OAAO,QAAQ,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,IAAI,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;AAC5F,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,OAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAW,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/**\n * Line handling and the normalisations every other module agrees on.\n */\n\n/** Splits text into lines without their terminators. A final newline adds no line. */\nexport function splitLines(text: string): string[] {\n const lines = text.split(/\\r?\\n/);\n if (lines.length > 1 && lines[lines.length - 1] === '') lines.pop();\n return lines;\n}\n\n/**\n * A brief's lines as one text, for spec-core's readers.\n *\n * A brief's lines end at LF or CRLF, and a sealed brief's hash is taken over\n * them. spec-core ends a line at a lone CR as well, as CommonMark does, so a\n * lone CR is handed to it as a space: every line and column it reports is\n * then one of the brief's own.\n */\nexport function textOfLines(lines: readonly string[]): string {\n return lines.join('\\n').replace(/\\r/g, ' ');\n}\n\n/**\n * The line ending a file already uses, so a rewrite does not flip it. Decided by\n * the first terminator; a file with none is written with LF.\n */\nexport function lineEnding(text: string): '\\n' | '\\r\\n' {\n return text.charAt(text.indexOf('\\n') - 1) === '\\r' ? '\\r\\n' : '\\n';\n}\n\n/** Joins lines with the given ending and a final newline. */\nexport function joinLines(lines: readonly string[], eol: '\\n' | '\\r\\n'): string {\n return lines.length === 0 ? '' : `${lines.join(eol)}${eol}`;\n}\n\n/** Lines written back with the source's byte-order mark, line ending and final newline, or lack of one. */\nexport function encodeLike(source: string, lines: readonly string[]): string {\n const bom = source.charCodeAt(0) === 0xfeff ? '\\uFEFF' : '';\n const eol = lineEnding(source);\n const text = joinLines(lines, eol);\n const finalNewline = source === '' || source.endsWith('\\n');\n return `${bom}${finalNewline ? text : text.slice(0, text.length - eol.length)}`;\n}\n\nexport function stripBom(text: string): string {\n return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;\n}\n\n/** CRLF and a byte-order mark are storage details, not content. */\nexport function canonicalText(text: string): string {\n return stripBom(text).replace(/\\r\\n/g, '\\n');\n}\n\n/**\n * The form in which two section names are compared.\n *\n * Headings are typed by people and pasted from documents, so the comparison\n * forgives what does not change meaning: typographic apostrophes and quotes,\n * emphasis and code markers, a leading number, a trailing colon, case and runs\n * of whitespace. `## 2. Commander’s Intent:` and `Commander's Intent` compare\n * equal. Nothing else is folded: a different word is a different section.\n */\nexport function normaliseLabel(label: string): string {\n return label\n .normalize('NFKC')\n .replace(/[\\u2018\\u2019\\u201b\\u2032\\u00b4]/g, \"'\")\n .replace(/[\\u201c\\u201d\\u201f\\u2033]/g, '\"')\n .replace(/[*_`]/g, '')\n .replace(/^\\s*\\d+(?:\\.\\d+)*[.)]?\\s+/, '')\n .replace(/\\s*:\\s*$/, '')\n .replace(/\\s+/g, ' ')\n .trim()\n .toLowerCase();\n}\n\n/**\n * Whether a heading names a section: equal after normalisation, or the section\n * name followed by a separator and a qualifier, as in `Invariants (must hold)`\n * or `Deliverables — round two`.\n */\nexport function labelMatches(heading: string, name: string): boolean {\n const h = normaliseLabel(heading);\n const n = normaliseLabel(name);\n if (n.length === 0) return false;\n if (h === n) return true;\n if (!h.startsWith(n)) return false;\n const rest = h.slice(n.length);\n return /^(?:\\s*[:(\\u2014\\u2013]|\\s+-\\s)/.test(rest);\n}\n\n/**\n * A file-name slug: lower case, ASCII letters and digits, single hyphens.\n * Letters with diacritics lose them; anything else becomes a separator.\n */\nexport function slugify(title: string, maxLength = 80): string {\n const slug = title\n .normalize('NFKD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '');\n if (slug.length <= maxLength) return slug;\n const cut = slug.slice(0, maxLength);\n // A cut that lands on a break keeps its last word whole.\n if (slug.charAt(maxLength) === '-') return cut;\n const lastBreak = cut.lastIndexOf('-');\n return lastBreak > 0 ? cut.slice(0, lastBreak) : cut;\n}\n\n/** `a`, `a and b`, `a, b and c`. */\nexport function inWords(items: readonly string[]): string {\n return items.length < 2 ? (items[0] ?? '') : `${items.slice(0, -1).join(', ')} and ${items[items.length - 1] as string}`;\n}\n\n/** Fills `{name}` holes. An unknown name is left as written. */\nexport function fillTemplate(template: string, values: Readonly<Record<string, string>>): string {\n return template.replace(/\\{([A-Za-z]+)\\}/g, (hole, name: string) => values[name] ?? hole);\n}\n\n/** The `{name}` holes a template line refers to. */\nexport function templateHoles(template: string): string[] {\n return [...template.matchAll(/\\{([A-Za-z]+)\\}/g)].map((match) => match[1] as string);\n}\n"]}
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,sFAAsF;AACtF,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,CAAC;IAC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AQ,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,IAAI,EAAE,IAAY,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,IAAI,CAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACvI,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,OAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAW,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/**\n * Line handling and the normalisations every other module agrees on.\n */\n\n/** Splits text into lines without their terminators. A final newline adds no line. */\nexport function splitLines(text: string): string[] {\n const lines = text.split(/\\r?\\n/);\n if (lines.length > 1 && lines[lines.length - 1] === '') lines.pop();\n return lines;\n}\n\n/**\n * A brief's lines as one text, for spec-core's readers.\n *\n * A brief's lines end at LF or CRLF, and a sealed brief's hash is taken over\n * them. spec-core ends a line at a lone CR as well, as CommonMark does, so a\n * lone CR is handed to it as a space: every line and column it reports is\n * then one of the brief's own.\n */\nexport function textOfLines(lines: readonly string[]): string {\n return lines.join('\\n').replace(/\\r/g, ' ');\n}\n\n/**\n * The line ending a file already uses, so a rewrite does not flip it. Decided by\n * the first terminator; a file with none is written with LF.\n */\nexport function lineEnding(text: string): '\\n' | '\\r\\n' {\n return text.charAt(text.indexOf('\\n') - 1) === '\\r' ? '\\r\\n' : '\\n';\n}\n\n/** Joins lines with the given ending and a final newline. */\nexport function joinLines(lines: readonly string[], eol: '\\n' | '\\r\\n'): string {\n return lines.length === 0 ? '' : `${lines.join(eol)}${eol}`;\n}\n\n/** Lines written back with the source's byte-order mark, line ending and final newline, or lack of one. */\nexport function encodeLike(source: string, lines: readonly string[]): string {\n const bom = source.charCodeAt(0) === 0xfeff ? '\\uFEFF' : '';\n const eol = lineEnding(source);\n const text = joinLines(lines, eol);\n const finalNewline = source === '' || source.endsWith('\\n');\n return `${bom}${finalNewline ? text : text.slice(0, text.length - eol.length)}`;\n}\n\nexport function stripBom(text: string): string {\n return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;\n}\n\n/** CRLF and a byte-order mark are storage details, not content. */\nexport function canonicalText(text: string): string {\n return stripBom(text).replace(/\\r\\n/g, '\\n');\n}\n\n/**\n * The form in which two section names are compared.\n *\n * Headings are typed by people and pasted from documents, so the comparison\n * forgives what does not change meaning: typographic apostrophes and quotes,\n * emphasis and code markers, a leading number, a trailing colon, case and runs\n * of whitespace. `## 2. Commander’s Intent:` and `Commander's Intent` compare\n * equal. Nothing else is folded: a different word is a different section.\n */\nexport function normaliseLabel(label: string): string {\n return label\n .normalize('NFKC')\n .replace(/[\\u2018\\u2019\\u201b\\u2032\\u00b4]/g, \"'\")\n .replace(/[\\u201c\\u201d\\u201f\\u2033]/g, '\"')\n .replace(/[*_`]/g, '')\n .replace(/^\\s*\\d+(?:\\.\\d+)*[.)]?\\s/, '')\n .replace(/\\s*:\\s*$/, '')\n .replace(/\\s+/g, ' ')\n .trim()\n .toLowerCase();\n}\n\n/**\n * Whether a heading names a section: equal after normalisation, or the section\n * name followed by a separator and a qualifier, as in `Invariants (must hold)`\n * or `Deliverables — round two`.\n */\nexport function labelMatches(heading: string, name: string): boolean {\n const h = normaliseLabel(heading);\n const n = normaliseLabel(name);\n if (n.length === 0) return false;\n if (h === n) return true;\n if (!h.startsWith(n)) return false;\n // Normalised, so whitespace is single spaces.\n const rest = h.slice(n.length);\n return /^(?:\\s*[:(\\u2014\\u2013]|\\s-\\s)/.test(rest);\n}\n\n/**\n * A file-name slug: lower case, ASCII letters and digits, single hyphens.\n * Letters with diacritics lose them; anything else becomes a separator.\n */\nexport function slugify(title: string, maxLength = 80): string {\n const slug = title\n .normalize('NFKD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '');\n if (slug.length <= maxLength) return slug;\n const cut = slug.slice(0, maxLength);\n // A cut that lands on a break keeps its last word whole.\n if (slug.charAt(maxLength) === '-') return cut;\n const lastBreak = cut.lastIndexOf('-');\n return lastBreak === -1 ? cut : cut.slice(0, lastBreak);\n}\n\n/** `a`, `a and b`, `a, b and c`. */\nexport function inWords(items: readonly string[]): string {\n return items.length < 2 ? (items[0] ?? '') : `${items.slice(0, -1).join(', ')} and ${items[items.length - 1] as string}`;\n}\n\n/**\n * Fills `{name}` holes. An unknown name is left as written, and a name every\n * object answers to, `{constructor}`, is unknown unless it was given.\n */\nexport function fillTemplate(template: string, values: Readonly<Record<string, string>>): string {\n return template.replace(/\\{([A-Za-z]+)\\}/g, (hole, name: string) => (Object.hasOwn(values, name) ? (values[name] as string) : hole));\n}\n\n/** The `{name}` holes a template line refers to. */\nexport function templateHoles(template: string): string[] {\n return [...template.matchAll(/\\{([A-Za-z]+)\\}/g)].map((match) => match[1] as string);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descent-vtt/spec-brief",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Lifecycle management for task briefs: lint the contract, map parallel collisions, and archive a round in one atomic command.",
5
5
  "keywords": [
6
6
  "agents",