@descent-vtt/spec-harness 0.5.0 → 0.7.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 (84) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +148 -0
  4. package/README.md +273 -24
  5. package/dist/audit.d.ts +71 -1
  6. package/dist/audit.js +140 -17
  7. package/dist/audit.js.map +1 -1
  8. package/dist/branch.d.ts +13 -0
  9. package/dist/branch.js +19 -0
  10. package/dist/branch.js.map +1 -1
  11. package/dist/cli.d.ts +1 -1
  12. package/dist/cli.js +51 -13
  13. package/dist/cli.js.map +1 -1
  14. package/dist/commands.js +13 -4
  15. package/dist/commands.js.map +1 -1
  16. package/dist/config.js +3 -1
  17. package/dist/config.js.map +1 -1
  18. package/dist/configure.d.ts +50 -3
  19. package/dist/configure.js +78 -5
  20. package/dist/configure.js.map +1 -1
  21. package/dist/context.d.ts +21 -7
  22. package/dist/context.js +104 -31
  23. package/dist/context.js.map +1 -1
  24. package/dist/document.d.ts +2 -1
  25. package/dist/document.js.map +1 -1
  26. package/dist/formats.d.ts +31 -0
  27. package/dist/formats.js +127 -0
  28. package/dist/formats.js.map +1 -0
  29. package/dist/git.d.ts +6 -0
  30. package/dist/git.js +8 -0
  31. package/dist/git.js.map +1 -1
  32. package/dist/guard.d.ts +8 -0
  33. package/dist/guard.js +19 -1
  34. package/dist/guard.js.map +1 -1
  35. package/dist/host.d.ts +14 -0
  36. package/dist/host.js +50 -0
  37. package/dist/host.js.map +1 -0
  38. package/dist/index.d.ts +5 -3
  39. package/dist/index.js +2 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/manifests.d.ts +8 -1
  42. package/dist/manifests.js +16 -6
  43. package/dist/manifests.js.map +1 -1
  44. package/dist/premises.d.ts +3 -0
  45. package/dist/premises.js +43 -13
  46. package/dist/premises.js.map +1 -1
  47. package/dist/reader.js +10 -2
  48. package/dist/reader.js.map +1 -1
  49. package/dist/round.d.ts +8 -0
  50. package/dist/round.js +73 -22
  51. package/dist/round.js.map +1 -1
  52. package/dist/server.js +11 -3
  53. package/dist/server.js.map +1 -1
  54. package/dist/setup.d.ts +10 -0
  55. package/dist/setup.js +68 -32
  56. package/dist/setup.js.map +1 -1
  57. package/dist/signers.d.ts +43 -0
  58. package/dist/signers.js +105 -0
  59. package/dist/signers.js.map +1 -0
  60. package/dist/types.d.ts +7 -0
  61. package/dist/types.js.map +1 -1
  62. package/dist/vendor/spec-core/markdown/frontmatter.d.ts +11 -1
  63. package/dist/vendor/spec-core/markdown/frontmatter.js +20 -3
  64. package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -1
  65. package/dist/vendor/spec-core/pattern/glob.d.ts +88 -2
  66. package/dist/vendor/spec-core/pattern/glob.js +234 -32
  67. package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
  68. package/dist/vendor/spec-core/pattern/index.d.ts +2 -2
  69. package/dist/vendor/spec-core/pattern/index.js +1 -1
  70. package/dist/vendor/spec-core/pattern/index.js.map +1 -1
  71. package/dist/vendor/spec-core/text/index.d.ts +1 -0
  72. package/dist/vendor/spec-core/text/index.js +1 -0
  73. package/dist/vendor/spec-core/text/index.js.map +1 -1
  74. package/dist/vendor/spec-core/text/width.d.ts +30 -0
  75. package/dist/vendor/spec-core/text/width.js +113 -0
  76. package/dist/vendor/spec-core/text/width.js.map +1 -0
  77. package/dist/versions.d.ts +27 -1
  78. package/dist/versions.js +23 -1
  79. package/dist/versions.js.map +1 -1
  80. package/dist/workspace.d.ts +6 -1
  81. package/dist/workspace.js +17 -6
  82. package/dist/workspace.js.map +1 -1
  83. package/package.json +1 -1
  84. package/skills/close-round/SKILL.md +4 -1
package/dist/context.js CHANGED
@@ -9,11 +9,13 @@
9
9
  * they fill what the budget leaves, in the order the brief cites them, and
10
10
  * the rest are named rather than dropped silently. So is a document whose
11
11
  * front matter is never closed, whose status cannot be read, rather than
12
- * shown as one without a status, and a pattern in the scope the guard cannot
13
- * read, with spec-core's reason, rather than listed as one it can.
12
+ * shown as one without a status, and a pattern in the scope, a protection or
13
+ * a ruling's path the guard cannot read, with spec-core's reason and what the
14
+ * guard does without it, rather than listed as one it can; and one a leading
15
+ * `/` roots, which names no path the guard decides.
14
16
  */
15
17
  import { sameId } from './branch.js';
16
- import { whyUnreadable } from './guard.js';
18
+ import { rooted, whyUnreadable } from './guard.js';
17
19
  /**
18
20
  * spec-guard's answer to `query --json`, read. It exits 2 both when no spec
19
21
  * file matched its patterns - a repository that keeps none, or keeps them
@@ -43,10 +45,36 @@ export function readRules(answer) {
43
45
  }
44
46
  return out;
45
47
  }
46
- function list(items, empty) {
47
- return items.length === 0 ? `- ${empty}` : items.map((item) => `- \`${item}\``).join('\n');
48
+ function list(items) {
49
+ return items.map((item) => `- \`${item}\``).join('\n');
48
50
  }
49
- function rulesSection(rules, scopeUnread) {
51
+ /**
52
+ * Each pattern a line, as the guard reads it: as written, or with spec-core's
53
+ * reason the guard cannot read it and what the guard does without it. The
54
+ * guard's own compile decides, so the packet and the guard cannot disagree.
55
+ * With `rootedNote`, a pattern a leading `/` roots, or one of whose
56
+ * alternatives it roots, is marked too, and counted when every alternative
57
+ * is rooted.
58
+ */
59
+ function patternLines(patterns, consequence, rootedNote) {
60
+ const unreadable = [];
61
+ let rootedWhole = 0;
62
+ const lines = patterns.map((pattern) => {
63
+ const reason = whyUnreadable(pattern);
64
+ if (reason === null) {
65
+ const root = rootedNote === undefined ? null : rooted(pattern);
66
+ if (root === null)
67
+ return `- \`${pattern}\``;
68
+ if (root === 'whole')
69
+ rootedWhole += 1;
70
+ return `- \`${pattern}\`, ${rootedNote[root]}`;
71
+ }
72
+ unreadable.push({ pattern, reason });
73
+ return `- \`${pattern}\`, which the guard cannot read: ${reason}; ${consequence}`;
74
+ });
75
+ return { lines, unreadable, rootedWhole };
76
+ }
77
+ function rulesSection(rules, scopeUnread, scopeRooted) {
50
78
  if ('none' in rules)
51
79
  return `spec-guard holds no rule over this scope: ${rules.none}.`;
52
80
  if ('unavailable' in rules) {
@@ -56,8 +84,11 @@ function rulesSection(rules, scopeUnread) {
56
84
  // With no pattern of the scope readable, spec-guard was asked about no
57
85
  // path, so an empty answer is no answer: "no rule" would tell the agent
58
86
  // the code it writes is unconstrained.
59
- return scopeUnread
60
- ? 'The scope could not be read: no pattern in `affectedFiles` can be read, so spec-guard was not asked for the rules over it. Treat every ADR as binding until the scope is fixed.'
87
+ if (scopeUnread) {
88
+ return 'The scope could not be read: no pattern in `affectedFiles` can be read, so spec-guard was not asked for the rules over it. Treat every ADR as binding until the scope is fixed.';
89
+ }
90
+ return scopeRooted
91
+ ? "No pattern in `affectedFiles` puts a path in the scope: each is rooted at the filesystem's root or cannot be read, so spec-guard was not asked for the rules over it. Treat every ADR as binding until the scope is fixed."
61
92
  : 'spec-guard holds no rule over this scope.';
62
93
  }
63
94
  const byDocument = new Map();
@@ -73,15 +104,19 @@ function rulesSection(rules, scopeUnread) {
73
104
  return parts.join('\n').trimEnd();
74
105
  }
75
106
  /**
76
- * A brief's title without the id it repeats: `012 - Rotate tokens` read as
77
- * `Rotate tokens`, and the same with an en or an em dash, which `spec-brief
78
- * new` writes, or with a colon after the id. Only the brief's own id is taken
79
- * off: `Fix - the login bug` is a title, not an id and a title.
107
+ * A brief's title without the id it repeats, by the rules spec-brief reads
108
+ * it with: the brief's own id, then an em dash, which `spec-brief new`
109
+ * writes, an en dash, a full-width colon or a colon, spaced or not, or a
110
+ * hyphen with a space on each side; `012 - Rotate tokens`, `012\u2014Rotate
111
+ * tokens` and `012\uFF1ARotate tokens` read as `Rotate tokens`. A bare hyphen
112
+ * is part of a word or a number, as in `001-2 migration`, and only the
113
+ * brief's own id is taken off: `Fix - the login bug` is a title, and so is
114
+ * `0010 \u2014 x` on brief 001.
80
115
  */
81
116
  export function titleOf(brief) {
82
117
  if (brief.title === null)
83
118
  return null;
84
- return brief.title.replace(/^\s*([^\s:]+)(?:\s+[-\u2013\u2014]|:)\s+/, (whole, first) => (sameId(first, brief.id) ? '' : whole));
119
+ return brief.title.replace(/^\s*([^\s:\uFF1A\u2013\u2014]+)(?:\s*[:\uFF1A\u2013\u2014]\s*|\s+-\s+)(?=\S)/, (whole, first) => sameId(first, brief.id) ? '' : whole);
85
120
  }
86
121
  /** Renders the packet, filling the budget with cited documents in the order the brief cites them. */
87
122
  export function renderContext(input) {
@@ -101,25 +136,55 @@ export function renderContext(input) {
101
136
  '',
102
137
  ].join('\n');
103
138
  const contract = ['## The contract', '', `\`${brief.file}\`, in full:`, '', '````markdown', input.briefText.trimEnd(), '````', ''].join('\n');
139
+ // The guard passes over a ruling's path it cannot read, so the path allows
140
+ // nothing. The paths share a line, so the note is in parentheses, closed
141
+ // before the next path.
142
+ const unreadableRulingPaths = [];
104
143
  const rulings = input.rulings.length === 0
105
144
  ? '- none'
106
- : input.rulings.map((ruling) => `- ${ruling.id}, signed by ${ruling.signer}: ${ruling.paths.map((p) => `\`${p}\``).join(', ')}`).join('\n');
107
- const unreadableScope = [];
108
- const mayWrite = brief.affectedFiles.map((pattern) => {
109
- const reason = whyUnreadable(pattern);
110
- if (reason === null)
111
- return `- \`${pattern}\``;
112
- unreadableScope.push({ pattern, reason });
113
- return `- \`${pattern}\`, which the guard cannot read: ${reason}; it puts no path in the scope`;
145
+ : input.rulings
146
+ .map((ruling) => {
147
+ const paths = ruling.paths.map((pattern) => {
148
+ const reason = whyUnreadable(pattern);
149
+ if (reason === null) {
150
+ // A rooted path can be read, and names no path the guard decides.
151
+ const root = rooted(pattern);
152
+ if (root === 'whole')
153
+ return `\`${pattern}\` (which a leading \`/\` roots at the filesystem's root; it allows nothing)`;
154
+ if (root === 'part')
155
+ return `\`${pattern}\` (an alternative of which a leading \`/\` roots at the filesystem's root; that alternative allows nothing)`;
156
+ return `\`${pattern}\``;
157
+ }
158
+ unreadableRulingPaths.push({ ruling: ruling.id, pattern, reason });
159
+ return `\`${pattern}\` (which the guard cannot read: ${reason}; it allows nothing)`;
160
+ });
161
+ return `- ${ruling.id}, signed by ${ruling.signer}: ${paths.join(', ')}`;
162
+ })
163
+ .join('\n');
164
+ // A rooted pattern can be read and puts no path in the scope: every path
165
+ // the guard decides is repository-relative. spec-guard is not asked about it.
166
+ const mayWrite = patternLines(brief.affectedFiles, 'it puts no path in the scope', {
167
+ whole: "which a leading `/` roots at the filesystem's root: it puts no path in the scope, and spec-guard is not asked about it",
168
+ part: "an alternative of which a leading `/` roots at the filesystem's root: that alternative puts no path in the scope, and spec-guard is not asked about it",
169
+ });
170
+ const unreadableScope = mayWrite.unreadable;
171
+ // While a protection the guard cannot read stands, the guard refuses every
172
+ // write, and no ruling waives it; a write to the brief is let through,
173
+ // since that is where it is fixed. A rooted protection can be read, and
174
+ // protects nothing: the file it was meant to protect is the round's to write.
175
+ const mustNot = patternLines(brief.protectedFiles, 'until it is fixed, the guard refuses every write but to the brief', {
176
+ whole: "which a leading `/` roots at the filesystem's root: it protects no path",
177
+ part: "an alternative of which a leading `/` roots at the filesystem's root: that alternative protects no path",
114
178
  });
179
+ const unreadableProtections = mustNot.unreadable;
115
180
  const scope = [
116
181
  '## Scope, as the guard reads it',
117
182
  '',
118
183
  'May write:',
119
- mayWrite.length === 0 ? '- nothing declared: every write is outside the scope' : mayWrite.join('\n'),
184
+ mayWrite.lines.length === 0 ? '- nothing declared: every write is outside the scope' : mayWrite.lines.join('\n'),
120
185
  '',
121
186
  'Must not change without a ruling:',
122
- list(brief.protectedFiles, 'nothing declared'),
187
+ mustNot.lines.length === 0 ? '- nothing declared' : mustNot.lines.join('\n'),
123
188
  '',
124
189
  'Rulings in force:',
125
190
  rulings,
@@ -131,8 +196,9 @@ export function renderContext(input) {
131
196
  return `- ${dependency.id}${named === null ? '' : ` ${named}`}: ${state}`;
132
197
  });
133
198
  const dependencies = ['## Depends on', '', waiting.length === 0 ? '- nothing' : waiting.join('\n'), ''].join('\n');
134
- const scopeUnread = mayWrite.length > 0 && unreadableScope.length === mayWrite.length;
135
- const rules = ['## Rules in force for this scope', '', rulesSection(input.rules, scopeUnread), ''].join('\n');
199
+ const scopeUnread = mayWrite.lines.length > 0 && unreadableScope.length === mayWrite.lines.length;
200
+ const scopeRooted = mayWrite.rootedWhole > 0 && unreadableScope.length + mayWrite.rootedWhole === mayWrite.lines.length;
201
+ const rules = ['## Rules in force for this scope', '', rulesSection(input.rules, scopeUnread, scopeRooted), ''].join('\n');
136
202
  const howTo = [
137
203
  '## How this round works',
138
204
  '',
@@ -172,16 +238,23 @@ export function renderContext(input) {
172
238
  if (documents.length === 0 && omitted.length === 0 && unresolved.length === 0)
173
239
  citedSection.push('None.', '');
174
240
  citedSection.push(...documents);
175
- // Each list below is shown only with an entry in it, so the text `list`
176
- // gives an empty one is never read, and its mutants are equivalent.
177
241
  if (omitted.length > 0) {
178
- citedSection.push(`Left out to stay within ${input.budget} characters; read them when the work reaches them:`, list(omitted, ''), '');
242
+ citedSection.push(`Left out to stay within ${input.budget} characters; read them when the work reaches them:`, list(omitted), '');
179
243
  }
180
244
  if (unresolved.length > 0)
181
- citedSection.push('Cited but not found in the repository:', list(unresolved, ''), '');
245
+ citedSection.push('Cited but not found in the repository:', list(unresolved), '');
182
246
  if (unclosed.length > 0) {
183
- citedSection.push('Front matter opened on line 1 and never closed, so the status was not read; close the block with `---` on a line of its own:', list(unclosed, ''), '');
247
+ citedSection.push('Front matter opened on line 1 and never closed, so the status was not read; close the block with `---` on a line of its own:', list(unclosed), '');
184
248
  }
185
- return { markdown: `${fixed}\n${citedSection.join('\n').trimEnd()}\n`, included, omitted, unresolved, unclosedFrontMatter: unclosed, unreadableScope };
249
+ return {
250
+ markdown: `${fixed}\n${citedSection.join('\n').trimEnd()}\n`,
251
+ included,
252
+ omitted,
253
+ unresolved,
254
+ unclosedFrontMatter: unclosed,
255
+ unreadableScope,
256
+ unreadableProtections,
257
+ unreadableRulingPaths,
258
+ };
186
259
  }
187
260
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,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SAAS,CAAC,CAAC;IAChC,wEAAwE;IACxE,oEAAoE;IACpE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,YAAY,CAAC,IAAI,CAAC,2BAA2B,KAAK,CAAC,MAAM,oDAAoD,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACxI,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,YAAY,CAAC,IAAI,CAAC,wCAAwC,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACjH,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,YAAY,CAAC,IAAI,CAAC,8HAA8H,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5K,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,KAAK,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AACzJ,CAAC","sourcesContent":["/**\n * What an agent needs to start a round, and nothing it does not.\n *\n * The brief in full - it is the contract, and a summary of a contract is a\n * different contract. Then what the brief implies but does not say: the scope\n * as the guard will read it, the rulings already signed, the briefs it waits\n * on, the rules spec-guard holds the scope's code to, and the documents the\n * brief cites. The cited documents are the one part that can be large, so\n * they fill what the budget leaves, in the order the brief cites them, and\n * the rest are named rather than dropped silently. So is a document whose\n * front matter is never closed, whose status cannot be read, rather than\n * shown as one without a status, and a pattern in the scope the guard cannot\n * read, with spec-core's reason, rather than listed as one it can.\n */\n\nimport { sameId } from './branch.js';\nimport { whyUnreadable } from './guard.js';\nimport type { BriefRow } from './types.js';\n\nexport interface CitedDocument {\n readonly path: string;\n readonly title: string | null;\n readonly status: string | null;\n /** `null` when the link does not resolve to a readable file. */\n readonly text: string | null;\n /** YAML front matter opened on line 1 and never closed, so no status was read from it. */\n readonly unclosedFrontMatter?: boolean | undefined;\n}\n\nexport interface RuleInForce {\n readonly document: string;\n readonly line: number;\n readonly kind: string;\n readonly description: string;\n readonly reason: string | null;\n}\n\n/**\n * The rules in force for the scope; `none` when spec-guard reads no\n * specification here, so none can be in force; `unavailable` when the rules\n * could not be read.\n */\nexport type Rules = readonly RuleInForce[] | { readonly none: string } | { readonly unavailable: string };\n\ninterface QueryDocument {\n readonly specFiles?: unknown;\n readonly results?: readonly { readonly rules?: readonly (RuleInForce & { readonly reason?: string | null; readonly inForce?: boolean })[] }[];\n}\n\n/**\n * spec-guard's answer to `query --json`, read. It exits 2 both when no spec\n * file matched its patterns - a repository that keeps none, or keeps them\n * where it does not look - and when it could not read the specs it has; only\n * the first prints a document, one with no spec file in it, so that is how\n * the two are told apart. What it said on stderr is the reason for the second.\n */\nexport function readRules(answer: { readonly code: number; readonly document: unknown; readonly stderr: string }): Rules {\n const document = (answer.document ?? {}) as QueryDocument;\n if (answer.code !== 0) {\n if (Array.isArray(document.specFiles) && document.specFiles.length === 0) {\n return { none: 'no spec file matched its patterns (\"specs\" in its configuration, docs/**/*.md by default)' };\n }\n const said = (answer.stderr.trim().split('\\n')[0] ?? '').replace(/^spec-guard:\\s*/, '');\n return { unavailable: said === '' ? `spec-guard exited ${answer.code}` : `spec-guard exited ${answer.code}: ${said}` };\n }\n const seen = new Set<string>();\n const out: RuleInForce[] = [];\n for (const result of document.results ?? []) {\n for (const rule of result.rules ?? []) {\n const key = `${rule.document}:${rule.line}`;\n if (rule.inForce === false || seen.has(key)) continue;\n seen.add(key);\n out.push({ document: rule.document, line: rule.line, kind: rule.kind, description: rule.description, reason: rule.reason ?? null });\n }\n }\n return out;\n}\n\nexport interface RulingInForce {\n readonly id: string;\n readonly paths: readonly string[];\n readonly signer: string;\n}\n\nexport interface ContextInput {\n readonly brief: BriefRow;\n readonly briefText: string;\n readonly dependencies: readonly BriefRow[];\n readonly cited: readonly CitedDocument[];\n /** The rules in force for the scope, none because spec-guard reads no specification, or why they could not be read. */\n readonly rules: Rules;\n readonly rulings: readonly RulingInForce[];\n readonly branch: string | null;\n readonly base: string | null;\n readonly budget: number;\n}\n\n/** A pattern in the brief's scope that the guard cannot read, with spec-core's reason. */\nexport interface UnreadablePattern {\n readonly pattern: string;\n readonly reason: string;\n}\n\nexport interface ContextPacket {\n readonly markdown: string;\n /** Cited documents included whole. */\n readonly included: readonly string[];\n /** Cited documents named but left out for the budget. */\n readonly omitted: readonly string[];\n /** Links in the brief that resolve to nothing. */\n readonly unresolved: readonly string[];\n /** Cited documents whose front matter opens on line 1 and is never closed, so no status was read from them. */\n readonly unclosedFrontMatter: readonly string[];\n /** Patterns in `affectedFiles` the guard cannot read, in the brief's order: each puts no path in the scope. */\n readonly unreadableScope: readonly UnreadablePattern[];\n}\n\nfunction list(items: readonly string[], empty: string): string {\n return items.length === 0 ? `- ${empty}` : items.map((item) => `- \\`${item}\\``).join('\\n');\n}\n\nfunction rulesSection(rules: Rules, scopeUnread: boolean): string {\n if ('none' in rules) return `spec-guard holds no rule over this scope: ${rules.none}.`;\n if ('unavailable' in rules) {\n return `The rules spec-guard holds this code to could not be read: ${rules.unavailable}. Treat every ADR as binding until they can.`;\n }\n if (rules.length === 0) {\n // With no pattern of the scope readable, spec-guard was asked about no\n // path, so an empty answer is no answer: \"no rule\" would tell the agent\n // the code it writes is unconstrained.\n return scopeUnread\n ? 'The scope could not be read: no pattern in `affectedFiles` can be read, so spec-guard was not asked for the rules over it. Treat every ADR as binding until the scope is fixed.'\n : 'spec-guard holds no rule over this scope.';\n }\n const byDocument = new Map<string, RuleInForce[]>();\n for (const rule of rules) byDocument.set(rule.document, [...(byDocument.get(rule.document) ?? []), rule]);\n const parts: string[] = [];\n for (const [document, found] of byDocument) {\n parts.push(`### ${document}`, '');\n for (const rule of found) parts.push(`- line ${rule.line}: ${rule.description}${rule.reason === null ? '' : ` - ${rule.reason}`}`);\n parts.push('');\n }\n return parts.join('\\n').trimEnd();\n}\n\n/**\n * A brief's title without the id it repeats: `012 - Rotate tokens` read as\n * `Rotate tokens`, and the same with an en or an em dash, which `spec-brief\n * new` writes, or with a colon after the id. Only the brief's own id is taken\n * off: `Fix - the login bug` is a title, not an id and a title.\n */\nexport function titleOf(brief: Pick<BriefRow, 'id' | 'title'>): string | null {\n if (brief.title === null) return null;\n return brief.title.replace(/^\\s*([^\\s:]+)(?:\\s+[-\\u2013\\u2014]|:)\\s+/, (whole, first: string) => (sameId(first, brief.id) ? '' : whole));\n}\n\n/** Renders the packet, filling the budget with cited documents in the order the brief cites them. */\nexport function renderContext(input: ContextInput): ContextPacket {\n const { brief } = input;\n const title = titleOf(brief);\n const header = [\n `# Round ${brief.id}${title === null ? '' : `: ${title}`}`,\n '',\n [\n `Status ${brief.status ?? 'unknown'}`,\n brief.wave === null ? null : `wave ${brief.wave}`,\n input.branch === null ? null : `branch \\`${input.branch}\\``,\n input.base === null ? null : `measured from \\`${input.base}\\``,\n ]\n .filter((part) => part !== null)\n .join(' · '),\n '',\n ].join('\\n');\n\n const contract = ['## The contract', '', `\\`${brief.file}\\`, in full:`, '', '````markdown', input.briefText.trimEnd(), '````', ''].join('\\n');\n\n const rulings =\n input.rulings.length === 0\n ? '- none'\n : input.rulings.map((ruling) => `- ${ruling.id}, signed by ${ruling.signer}: ${ruling.paths.map((p) => `\\`${p}\\``).join(', ')}`).join('\\n');\n const unreadableScope: UnreadablePattern[] = [];\n const mayWrite = brief.affectedFiles.map((pattern) => {\n const reason = whyUnreadable(pattern);\n if (reason === null) return `- \\`${pattern}\\``;\n unreadableScope.push({ pattern, reason });\n return `- \\`${pattern}\\`, which the guard cannot read: ${reason}; it puts no path in the scope`;\n });\n const scope = [\n '## Scope, as the guard reads it',\n '',\n 'May write:',\n mayWrite.length === 0 ? '- nothing declared: every write is outside the scope' : mayWrite.join('\\n'),\n '',\n 'Must not change without a ruling:',\n list(brief.protectedFiles, 'nothing declared'),\n '',\n 'Rulings in force:',\n rulings,\n '',\n ].join('\\n');\n\n const waiting = input.dependencies.map((dependency) => {\n const state = dependency.phase === 'archived' ? 'archived, done' : `still ${dependency.status ?? 'live'}`;\n const named = titleOf(dependency);\n return `- ${dependency.id}${named === null ? '' : ` ${named}`}: ${state}`;\n });\n const dependencies = ['## Depends on', '', waiting.length === 0 ? '- nothing' : waiting.join('\\n'), ''].join('\\n');\n\n const scopeUnread = mayWrite.length > 0 && unreadableScope.length === mayWrite.length;\n const rules = ['## Rules in force for this scope', '', rulesSection(input.rules, scopeUnread), ''].join('\\n');\n\n const howTo = [\n '## How this round works',\n '',\n '- Before writing a file, ask whether the round may: `spec-harness guard <path>`, or the `check_path` tool.',\n '- A protected file is changed only under a ruling a person signs. If the round cannot be done without one, stop and ask: `spec-harness escalate --path <file> --reason <why>`, or the `request_escalation` tool. Do not work around it.',\n '- Every box in the brief ends ticked, or with a note under it that starts with a disposition (`**Delegated`, `**Accepted debt`, `**Rejected`, or what the repository configures).',\n '- When the work is done, run `spec-harness audit` and fix what it reports. The archive is a person\\'s decision, not the round\\'s.',\n '',\n ].join('\\n');\n\n const fixed = [header, contract, scope, dependencies, rules, howTo].join('\\n');\n const included: string[] = [];\n const omitted: string[] = [];\n const unresolved: string[] = [];\n const unclosed: string[] = [];\n const documents: string[] = [];\n let used = fixed.length;\n for (const cited of input.cited) {\n if (cited.text === null) {\n unresolved.push(cited.path);\n continue;\n }\n // Named whether or not the budget leaves room for it: the status is\n // unread either way, and the fix is the same.\n if (cited.unclosedFrontMatter === true) unclosed.push(cited.path);\n const heading = `### \\`${cited.path}\\`${cited.title === null ? '' : ` - ${cited.title}`}${cited.status === null ? '' : ` (${cited.status})`}`;\n const block = [heading, '', '````markdown', cited.text.trimEnd(), '````', ''].join('\\n');\n if (used + block.length > input.budget) {\n omitted.push(cited.path);\n continue;\n }\n used += block.length;\n included.push(cited.path);\n documents.push(block);\n }\n const citedSection = ['## Documents the brief cites', ''];\n if (documents.length === 0 && omitted.length === 0 && unresolved.length === 0) citedSection.push('None.', '');\n citedSection.push(...documents);\n // Each list below is shown only with an entry in it, so the text `list`\n // gives an empty one is never read, and its mutants are equivalent.\n if (omitted.length > 0) {\n citedSection.push(`Left out to stay within ${input.budget} characters; read them when the work reaches them:`, list(omitted, ''), '');\n }\n if (unresolved.length > 0) citedSection.push('Cited but not found in the repository:', list(unresolved, ''), '');\n if (unclosed.length > 0) {\n citedSection.push('Front matter opened on line 1 and never closed, so the status was not read; close the block with `---` on a line of its own:', list(unclosed, ''), '');\n }\n\n return { markdown: `${fixed}\\n${citedSection.join('\\n').trimEnd()}\\n`, included, omitted, unresolved, unclosedFrontMatter: unclosed, unreadableScope };\n}\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiCnD;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,MAAsF;IAC9G,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAkB,CAAC;IAC1D,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACtB,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzE,OAAO,EAAE,IAAI,EAAE,2FAA2F,EAAE,CAAC;QAC/G,CAAC;QACD,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CA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AAE,CAAC;QACvB,YAAY,CAAC,IAAI,CAAC,2BAA2B,KAAK,CAAC,MAAM,oDAAoD,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IACpI,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,YAAY,CAAC,IAAI,CAAC,wCAAwC,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7G,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,YAAY,CAAC,IAAI,CAAC,8HAA8H,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;IACxK,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,GAAG,KAAK,KAAK,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI;QAC5D,QAAQ;QACR,OAAO;QACP,UAAU;QACV,mBAAmB,EAAE,QAAQ;QAC7B,eAAe;QACf,qBAAqB;QACrB,qBAAqB;KACtB,CAAC;AACJ,CAAC","sourcesContent":["/**\n * What an agent needs to start a round, and nothing it does not.\n *\n * The brief in full - it is the contract, and a summary of a contract is a\n * different contract. Then what the brief implies but does not say: the scope\n * as the guard will read it, the rulings already signed, the briefs it waits\n * on, the rules spec-guard holds the scope's code to, and the documents the\n * brief cites. The cited documents are the one part that can be large, so\n * they fill what the budget leaves, in the order the brief cites them, and\n * the rest are named rather than dropped silently. So is a document whose\n * front matter is never closed, whose status cannot be read, rather than\n * shown as one without a status, and a pattern in the scope, a protection or\n * a ruling's path the guard cannot read, with spec-core's reason and what the\n * guard does without it, rather than listed as one it can; and one a leading\n * `/` roots, which names no path the guard decides.\n */\n\nimport { sameId } from './branch.js';\nimport { rooted, whyUnreadable } from './guard.js';\nimport type { BriefRow } from './types.js';\n\nexport interface CitedDocument {\n readonly path: string;\n readonly title: string | null;\n readonly status: string | null;\n /** `null` when the link does not resolve to a readable file. */\n readonly text: string | null;\n /** YAML front matter opened on line 1 and never closed, so no status was read from it. */\n readonly unclosedFrontMatter?: boolean | undefined;\n}\n\nexport interface RuleInForce {\n readonly document: string;\n readonly line: number;\n readonly kind: string;\n readonly description: string;\n readonly reason: string | null;\n}\n\n/**\n * The rules in force for the scope; `none` when spec-guard reads no\n * specification here, so none can be in force; `unavailable` when the rules\n * could not be read.\n */\nexport type Rules = readonly RuleInForce[] | { readonly none: string } | { readonly unavailable: string };\n\ninterface QueryDocument {\n readonly specFiles?: unknown;\n readonly results?: readonly { readonly rules?: readonly (RuleInForce & { readonly reason?: string | null; readonly inForce?: boolean })[] }[];\n}\n\n/**\n * spec-guard's answer to `query --json`, read. It exits 2 both when no spec\n * file matched its patterns - a repository that keeps none, or keeps them\n * where it does not look - and when it could not read the specs it has; only\n * the first prints a document, one with no spec file in it, so that is how\n * the two are told apart. What it said on stderr is the reason for the second.\n */\nexport function readRules(answer: { readonly code: number; readonly document: unknown; readonly stderr: string }): Rules {\n const document = (answer.document ?? {}) as QueryDocument;\n if (answer.code !== 0) {\n if (Array.isArray(document.specFiles) && document.specFiles.length === 0) {\n return { none: 'no spec file matched its patterns (\"specs\" in its configuration, docs/**/*.md by default)' };\n }\n const said = (answer.stderr.trim().split('\\n')[0] ?? '').replace(/^spec-guard:\\s*/, '');\n return { unavailable: said === '' ? `spec-guard exited ${answer.code}` : `spec-guard exited ${answer.code}: ${said}` };\n }\n const seen = new Set<string>();\n const out: RuleInForce[] = [];\n for (const result of document.results ?? []) {\n for (const rule of result.rules ?? []) {\n const key = `${rule.document}:${rule.line}`;\n if (rule.inForce === false || seen.has(key)) continue;\n seen.add(key);\n out.push({ document: rule.document, line: rule.line, kind: rule.kind, description: rule.description, reason: rule.reason ?? null });\n }\n }\n return out;\n}\n\nexport interface RulingInForce {\n readonly id: string;\n readonly paths: readonly string[];\n readonly signer: string;\n}\n\nexport interface ContextInput {\n readonly brief: BriefRow;\n readonly briefText: string;\n readonly dependencies: readonly BriefRow[];\n readonly cited: readonly CitedDocument[];\n /** The rules in force for the scope, none because spec-guard reads no specification, or why they could not be read. */\n readonly rules: Rules;\n readonly rulings: readonly RulingInForce[];\n readonly branch: string | null;\n readonly base: string | null;\n readonly budget: number;\n}\n\n/** A pattern in the brief's scope or protections that the guard cannot read, with spec-core's reason. */\nexport interface UnreadablePattern {\n readonly pattern: string;\n readonly reason: string;\n}\n\n/** A path of a ruling in force that the guard cannot read, with the ruling's id and spec-core's reason. */\nexport interface UnreadableRulingPath extends UnreadablePattern {\n readonly ruling: string;\n}\n\nexport interface ContextPacket {\n readonly markdown: string;\n /** Cited documents included whole. */\n readonly included: readonly string[];\n /** Cited documents named but left out for the budget. */\n readonly omitted: readonly string[];\n /** Links in the brief that resolve to nothing. */\n readonly unresolved: readonly string[];\n /** Cited documents whose front matter opens on line 1 and is never closed, so no status was read from them. */\n readonly unclosedFrontMatter: readonly string[];\n /** Patterns in `affectedFiles` the guard cannot read, in the brief's order: each puts no path in the scope. */\n readonly unreadableScope: readonly UnreadablePattern[];\n /** Patterns in `protectedFiles` the guard cannot read, in the brief's order: while one stands, the guard refuses every write but to the brief. */\n readonly unreadableProtections: readonly UnreadablePattern[];\n /** Paths of the rulings in force the guard cannot read, in the order the rulings are listed: each allows nothing. */\n readonly unreadableRulingPaths: readonly UnreadableRulingPath[];\n}\n\nfunction list(items: readonly string[]): string {\n return items.map((item) => `- \\`${item}\\``).join('\\n');\n}\n\n/**\n * Each pattern a line, as the guard reads it: as written, or with spec-core's\n * reason the guard cannot read it and what the guard does without it. The\n * guard's own compile decides, so the packet and the guard cannot disagree.\n * With `rootedNote`, a pattern a leading `/` roots, or one of whose\n * alternatives it roots, is marked too, and counted when every alternative\n * is rooted.\n */\nfunction patternLines(\n patterns: readonly string[],\n consequence: string,\n rootedNote?: { readonly whole: string; readonly part: string },\n): { lines: string[]; unreadable: UnreadablePattern[]; rootedWhole: number } {\n const unreadable: UnreadablePattern[] = [];\n let rootedWhole = 0;\n const lines = patterns.map((pattern) => {\n const reason = whyUnreadable(pattern);\n if (reason === null) {\n const root = rootedNote === undefined ? null : rooted(pattern);\n if (root === null) return `- \\`${pattern}\\``;\n if (root === 'whole') rootedWhole += 1;\n return `- \\`${pattern}\\`, ${(rootedNote as { whole: string; part: string })[root]}`;\n }\n unreadable.push({ pattern, reason });\n return `- \\`${pattern}\\`, which the guard cannot read: ${reason}; ${consequence}`;\n });\n return { lines, unreadable, rootedWhole };\n}\n\nfunction rulesSection(rules: Rules, scopeUnread: boolean, scopeRooted: boolean): string {\n if ('none' in rules) return `spec-guard holds no rule over this scope: ${rules.none}.`;\n if ('unavailable' in rules) {\n return `The rules spec-guard holds this code to could not be read: ${rules.unavailable}. Treat every ADR as binding until they can.`;\n }\n if (rules.length === 0) {\n // With no pattern of the scope readable, spec-guard was asked about no\n // path, so an empty answer is no answer: \"no rule\" would tell the agent\n // the code it writes is unconstrained.\n if (scopeUnread) {\n return 'The scope could not be read: no pattern in `affectedFiles` can be read, so spec-guard was not asked for the rules over it. Treat every ADR as binding until the scope is fixed.';\n }\n return scopeRooted\n ? \"No pattern in `affectedFiles` puts a path in the scope: each is rooted at the filesystem's root or cannot be read, so spec-guard was not asked for the rules over it. Treat every ADR as binding until the scope is fixed.\"\n : 'spec-guard holds no rule over this scope.';\n }\n const byDocument = new Map<string, RuleInForce[]>();\n for (const rule of rules) byDocument.set(rule.document, [...(byDocument.get(rule.document) ?? []), rule]);\n const parts: string[] = [];\n for (const [document, found] of byDocument) {\n parts.push(`### ${document}`, '');\n for (const rule of found) parts.push(`- line ${rule.line}: ${rule.description}${rule.reason === null ? '' : ` - ${rule.reason}`}`);\n parts.push('');\n }\n return parts.join('\\n').trimEnd();\n}\n\n/**\n * A brief's title without the id it repeats, by the rules spec-brief reads\n * it with: the brief's own id, then an em dash, which `spec-brief new`\n * writes, an en dash, a full-width colon or a colon, spaced or not, or a\n * hyphen with a space on each side; `012 - Rotate tokens`, `012\\u2014Rotate\n * tokens` and `012\\uFF1ARotate tokens` read as `Rotate tokens`. A bare hyphen\n * is part of a word or a number, as in `001-2 migration`, and only the\n * brief's own id is taken off: `Fix - the login bug` is a title, and so is\n * `0010 \\u2014 x` on brief 001.\n */\nexport function titleOf(brief: Pick<BriefRow, 'id' | 'title'>): string | null {\n if (brief.title === null) return null;\n return brief.title.replace(/^\\s*([^\\s:\\uFF1A\\u2013\\u2014]+)(?:\\s*[:\\uFF1A\\u2013\\u2014]\\s*|\\s+-\\s+)(?=\\S)/, (whole, first: string) =>\n sameId(first, brief.id) ? '' : whole,\n );\n}\n\n/** Renders the packet, filling the budget with cited documents in the order the brief cites them. */\nexport function renderContext(input: ContextInput): ContextPacket {\n const { brief } = input;\n const title = titleOf(brief);\n const header = [\n `# Round ${brief.id}${title === null ? '' : `: ${title}`}`,\n '',\n [\n `Status ${brief.status ?? 'unknown'}`,\n brief.wave === null ? null : `wave ${brief.wave}`,\n input.branch === null ? null : `branch \\`${input.branch}\\``,\n input.base === null ? null : `measured from \\`${input.base}\\``,\n ]\n .filter((part) => part !== null)\n .join(' · '),\n '',\n ].join('\\n');\n\n const contract = ['## The contract', '', `\\`${brief.file}\\`, in full:`, '', '````markdown', input.briefText.trimEnd(), '````', ''].join('\\n');\n\n // The guard passes over a ruling's path it cannot read, so the path allows\n // nothing. The paths share a line, so the note is in parentheses, closed\n // before the next path.\n const unreadableRulingPaths: UnreadableRulingPath[] = [];\n const rulings =\n input.rulings.length === 0\n ? '- none'\n : input.rulings\n .map((ruling) => {\n const paths = ruling.paths.map((pattern) => {\n const reason = whyUnreadable(pattern);\n if (reason === null) {\n // A rooted path can be read, and names no path the guard decides.\n const root = rooted(pattern);\n if (root === 'whole') return `\\`${pattern}\\` (which a leading \\`/\\` roots at the filesystem's root; it allows nothing)`;\n if (root === 'part') return `\\`${pattern}\\` (an alternative of which a leading \\`/\\` roots at the filesystem's root; that alternative allows nothing)`;\n return `\\`${pattern}\\``;\n }\n unreadableRulingPaths.push({ ruling: ruling.id, pattern, reason });\n return `\\`${pattern}\\` (which the guard cannot read: ${reason}; it allows nothing)`;\n });\n return `- ${ruling.id}, signed by ${ruling.signer}: ${paths.join(', ')}`;\n })\n .join('\\n');\n // A rooted pattern can be read and puts no path in the scope: every path\n // the guard decides is repository-relative. spec-guard is not asked about it.\n const mayWrite = patternLines(brief.affectedFiles, 'it puts no path in the scope', {\n whole: \"which a leading `/` roots at the filesystem's root: it puts no path in the scope, and spec-guard is not asked about it\",\n part: \"an alternative of which a leading `/` roots at the filesystem's root: that alternative puts no path in the scope, and spec-guard is not asked about it\",\n });\n const unreadableScope = mayWrite.unreadable;\n // While a protection the guard cannot read stands, the guard refuses every\n // write, and no ruling waives it; a write to the brief is let through,\n // since that is where it is fixed. A rooted protection can be read, and\n // protects nothing: the file it was meant to protect is the round's to write.\n const mustNot = patternLines(brief.protectedFiles, 'until it is fixed, the guard refuses every write but to the brief', {\n whole: \"which a leading `/` roots at the filesystem's root: it protects no path\",\n part: \"an alternative of which a leading `/` roots at the filesystem's root: that alternative protects no path\",\n });\n const unreadableProtections = mustNot.unreadable;\n const scope = [\n '## Scope, as the guard reads it',\n '',\n 'May write:',\n mayWrite.lines.length === 0 ? '- nothing declared: every write is outside the scope' : mayWrite.lines.join('\\n'),\n '',\n 'Must not change without a ruling:',\n mustNot.lines.length === 0 ? '- nothing declared' : mustNot.lines.join('\\n'),\n '',\n 'Rulings in force:',\n rulings,\n '',\n ].join('\\n');\n\n const waiting = input.dependencies.map((dependency) => {\n const state = dependency.phase === 'archived' ? 'archived, done' : `still ${dependency.status ?? 'live'}`;\n const named = titleOf(dependency);\n return `- ${dependency.id}${named === null ? '' : ` ${named}`}: ${state}`;\n });\n const dependencies = ['## Depends on', '', waiting.length === 0 ? '- nothing' : waiting.join('\\n'), ''].join('\\n');\n\n const scopeUnread = mayWrite.lines.length > 0 && unreadableScope.length === mayWrite.lines.length;\n const scopeRooted = mayWrite.rootedWhole > 0 && unreadableScope.length + mayWrite.rootedWhole === mayWrite.lines.length;\n const rules = ['## Rules in force for this scope', '', rulesSection(input.rules, scopeUnread, scopeRooted), ''].join('\\n');\n\n const howTo = [\n '## How this round works',\n '',\n '- Before writing a file, ask whether the round may: `spec-harness guard <path>`, or the `check_path` tool.',\n '- A protected file is changed only under a ruling a person signs. If the round cannot be done without one, stop and ask: `spec-harness escalate --path <file> --reason <why>`, or the `request_escalation` tool. Do not work around it.',\n '- Every box in the brief ends ticked, or with a note under it that starts with a disposition (`**Delegated`, `**Accepted debt`, `**Rejected`, or what the repository configures).',\n '- When the work is done, run `spec-harness audit` and fix what it reports. The archive is a person\\'s decision, not the round\\'s.',\n '',\n ].join('\\n');\n\n const fixed = [header, contract, scope, dependencies, rules, howTo].join('\\n');\n const included: string[] = [];\n const omitted: string[] = [];\n const unresolved: string[] = [];\n const unclosed: string[] = [];\n const documents: string[] = [];\n let used = fixed.length;\n for (const cited of input.cited) {\n if (cited.text === null) {\n unresolved.push(cited.path);\n continue;\n }\n // Named whether or not the budget leaves room for it: the status is\n // unread either way, and the fix is the same.\n if (cited.unclosedFrontMatter === true) unclosed.push(cited.path);\n const heading = `### \\`${cited.path}\\`${cited.title === null ? '' : ` - ${cited.title}`}${cited.status === null ? '' : ` (${cited.status})`}`;\n const block = [heading, '', '````markdown', cited.text.trimEnd(), '````', ''].join('\\n');\n if (used + block.length > input.budget) {\n omitted.push(cited.path);\n continue;\n }\n used += block.length;\n included.push(cited.path);\n documents.push(block);\n }\n const citedSection = ['## Documents the brief cites', ''];\n if (documents.length === 0 && omitted.length === 0 && unresolved.length === 0) citedSection.push('None.', '');\n citedSection.push(...documents);\n if (omitted.length > 0) {\n citedSection.push(`Left out to stay within ${input.budget} characters; read them when the work reaches them:`, list(omitted), '');\n }\n if (unresolved.length > 0) citedSection.push('Cited but not found in the repository:', list(unresolved), '');\n if (unclosed.length > 0) {\n citedSection.push('Front matter opened on line 1 and never closed, so the status was not read; close the block with `---` on a line of its own:', list(unclosed), '');\n }\n\n return {\n markdown: `${fixed}\\n${citedSection.join('\\n').trimEnd()}\\n`,\n included,\n omitted,\n unresolved,\n unclosedFrontMatter: unclosed,\n unreadableScope,\n unreadableProtections,\n unreadableRulingPaths,\n };\n}\n"]}
@@ -27,7 +27,8 @@ export interface DocumentReader {
27
27
  sectionTables(text: string, section: string): SectionTables;
28
28
  citations(text: string): Citation[];
29
29
  /**
30
- * The first level-one heading, and the front matter's status. YAML front
30
+ * The first level-one heading, and the front matter's status, under
31
+ * `status`, `狀態` or `状态`, the first the document holds. YAML front
31
32
  * matter opened on line 1 and never closed is `unclosedFrontMatter`: none
32
33
  * of it is read, so a status its author wrote there reads as none.
33
34
  */
@@ -1 +1 @@
1
- {"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG","sourcesContent":["/**\n * What the harness reads out of a brief or a cited document, through\n * spec-core's Markdown scanner so that code and comments are never mistaken\n * for structure: fenced blocks with their info strings, the section a line\n * sits in, a section's tables, the relative links a document cites, and a\n * document's title and status.\n */\n\nimport type { CodeBlock } from './probe.js';\nimport type { TableView } from './rulings.js';\n\nexport interface Citation {\n readonly target: string;\n /** 1-based. */\n readonly line: number;\n}\n\nexport interface SectionTables {\n readonly tables: readonly TableView[];\n /** 1-based line of the section's heading, or `null` when there is no such section. */\n readonly headingLine: number | null;\n /** 0-based index of the line after the section's last table row, or `null` when it has no table. */\n readonly tableEndLine: number | null;\n}\n\nexport interface DocumentReader {\n codeBlocks(text: string): CodeBlock[];\n sectionAt(text: string, line: number): string | null;\n /** Every section a line sits in, outermost first: a `###` under a `##` is in both. */\n sectionsAt(text: string, line: number): string[];\n sectionTables(text: string, section: string): SectionTables;\n citations(text: string): Citation[];\n /**\n * The first level-one heading, and the front matter's status. YAML front\n * matter opened on line 1 and never closed is `unclosedFrontMatter`: none\n * of it is read, so a status its author wrote there reads as none.\n */\n titleAndStatus(text: string): { readonly title: string | null; readonly status: string | null; readonly unclosedFrontMatter: boolean };\n}\n"]}
1
+ {"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG","sourcesContent":["/**\n * What the harness reads out of a brief or a cited document, through\n * spec-core's Markdown scanner so that code and comments are never mistaken\n * for structure: fenced blocks with their info strings, the section a line\n * sits in, a section's tables, the relative links a document cites, and a\n * document's title and status.\n */\n\nimport type { CodeBlock } from './probe.js';\nimport type { TableView } from './rulings.js';\n\nexport interface Citation {\n readonly target: string;\n /** 1-based. */\n readonly line: number;\n}\n\nexport interface SectionTables {\n readonly tables: readonly TableView[];\n /** 1-based line of the section's heading, or `null` when there is no such section. */\n readonly headingLine: number | null;\n /** 0-based index of the line after the section's last table row, or `null` when it has no table. */\n readonly tableEndLine: number | null;\n}\n\nexport interface DocumentReader {\n codeBlocks(text: string): CodeBlock[];\n sectionAt(text: string, line: number): string | null;\n /** Every section a line sits in, outermost first: a `###` under a `##` is in both. */\n sectionsAt(text: string, line: number): string[];\n sectionTables(text: string, section: string): SectionTables;\n citations(text: string): Citation[];\n /**\n * The first level-one heading, and the front matter's status, under\n * `status`, `狀態` or `状态`, the first the document holds. YAML front\n * matter opened on line 1 and never closed is `unclosedFrontMatter`: none\n * of it is read, so a status its author wrote there reads as none.\n */\n titleAndStatus(text: string): { readonly title: string | null; readonly status: string | null; readonly unclosedFrontMatter: boolean };\n}\n"]}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Findings in the formats a forge reads beside a change: GitLab Code Quality,
3
+ * SARIF 2.1.0 and GitHub workflow commands (spec-core ADR-0005).
4
+ *
5
+ * The shapes are the siblings': spec-brief's severities and its hint in the
6
+ * text, spec-guard's fingerprint of a finding's identity. Pure: the command
7
+ * prints what these return.
8
+ */
9
+ import type { Finding } from './types.js';
10
+ /** The formats that place findings, which `audit` and `premises` print. */
11
+ export type FindingFormat = 'gitlab' | 'sarif' | 'github';
12
+ export declare const FINDING_FORMATS: readonly FindingFormat[];
13
+ export interface FormatOptions {
14
+ /** Where a finding with no file of its own is placed: the brief the command is about. */
15
+ readonly file: string;
16
+ /** This tool's version, which SARIF names. */
17
+ readonly version: string;
18
+ /** What the run measured, which SARIF carries as a note beside its results. */
19
+ readonly summary?: string | undefined;
20
+ }
21
+ /** GitLab Code Quality: a JSON array of issues, which a merge request shows beside the lines they are on. */
22
+ export declare function formatGitlab(findings: readonly Finding[], options: FormatOptions): string;
23
+ /**
24
+ * SARIF 2.1.0, for code scanning. What the run measured is a note in the
25
+ * invocation, SARIF's place for what happened in a run that is not a finding,
26
+ * so a page with no result still says what was checked.
27
+ */
28
+ export declare function formatSarif(findings: readonly Finding[], options: FormatOptions): string;
29
+ /** GitHub Actions workflow commands, one line each, which a job's log turns into annotations on the diff. */
30
+ export declare function formatGithub(findings: readonly Finding[], options: FormatOptions): string;
31
+ export declare function formatFindings(format: FindingFormat, findings: readonly Finding[], options: FormatOptions): string;
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Findings in the formats a forge reads beside a change: GitLab Code Quality,
3
+ * SARIF 2.1.0 and GitHub workflow commands (spec-core ADR-0005).
4
+ *
5
+ * The shapes are the siblings': spec-brief's severities and its hint in the
6
+ * text, spec-guard's fingerprint of a finding's identity. Pure: the command
7
+ * prints what these return.
8
+ */
9
+ import { createHash } from 'node:crypto';
10
+ import { RULES } from './audit.js';
11
+ export const FINDING_FORMATS = ['gitlab', 'sarif', 'github'];
12
+ /**
13
+ * GitLab's severities. An error fails the run, but it is not the crash or the
14
+ * security hole `critical` and `blocker` say in GitLab's own reports, so the
15
+ * scale tops out at `major`, as spec-brief's does.
16
+ */
17
+ const GITLAB_SEVERITY = { error: 'major', warning: 'minor', note: 'info' };
18
+ const SARIF_LEVEL = { error: 'error', warning: 'warning', note: 'note' };
19
+ const GITHUB_COMMAND = { error: 'error', warning: 'warning', note: 'notice' };
20
+ /**
21
+ * Each finding with its place and its fingerprint. A finding about a whole
22
+ * brief is placed on the brief's first line. The fingerprint is the SHA-256
23
+ * of the finding's identity - its rule, its file and its subject - and never
24
+ * of its message, hint or line: GitLab tells a new finding from one it has
25
+ * seen by it, so a reworded message or a line added above must not read as
26
+ * one problem fixed and another found. Two findings with one identity are
27
+ * told apart by the order they come in.
28
+ */
29
+ function place(findings, fallback) {
30
+ const seen = new Map();
31
+ return findings.map((finding) => {
32
+ const file = finding.file ?? fallback;
33
+ const identity = [finding.rule, file, finding.subject ?? ''].join('\u0000');
34
+ const repeat = seen.get(identity) ?? 0;
35
+ seen.set(identity, repeat + 1);
36
+ const fingerprint = createHash('sha256').update(repeat === 0 ? identity : `${identity}\u0000${repeat}`).digest('hex');
37
+ return { finding, file, line: Math.max(finding.line ?? 1, 1), fingerprint };
38
+ });
39
+ }
40
+ /**
41
+ * The message and the next action, which every format carries (spec-core
42
+ * ADR-0005). A message a sibling ended with a full stop keeps one.
43
+ */
44
+ function text(finding) {
45
+ return `${finding.message.replace(/\.$/, '')}. ${finding.hint}`;
46
+ }
47
+ /** GitLab Code Quality: a JSON array of issues, which a merge request shows beside the lines they are on. */
48
+ export function formatGitlab(findings, options) {
49
+ const issues = place(findings, options.file).map(({ finding, file, line, fingerprint }) => ({
50
+ description: text(finding),
51
+ check_name: finding.rule,
52
+ fingerprint,
53
+ severity: GITLAB_SEVERITY[finding.severity],
54
+ location: { path: file, lines: { begin: line } },
55
+ }));
56
+ return `${JSON.stringify(issues, null, 2)}\n`;
57
+ }
58
+ /** How SARIF describes a rule: the audit's own words, or the archive rule spec-brief gave. */
59
+ function describeRule(id) {
60
+ if (id.startsWith('archive/'))
61
+ return `A reason spec-brief's archive gives: ${id.slice('archive/'.length)}.`;
62
+ return RULES[id] ?? id;
63
+ }
64
+ /**
65
+ * SARIF 2.1.0, for code scanning. What the run measured is a note in the
66
+ * invocation, SARIF's place for what happened in a run that is not a finding,
67
+ * so a page with no result still says what was checked.
68
+ */
69
+ export function formatSarif(findings, options) {
70
+ const placed = place(findings, options.file);
71
+ const ids = [...new Set(findings.map((finding) => finding.rule))].sort();
72
+ const document = {
73
+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
74
+ version: '2.1.0',
75
+ runs: [
76
+ {
77
+ ...(options.summary === undefined
78
+ ? {}
79
+ : { invocations: [{ executionSuccessful: true, toolExecutionNotifications: [{ level: 'note', message: { text: options.summary } }] }] }),
80
+ tool: {
81
+ driver: {
82
+ name: 'spec-harness',
83
+ version: options.version,
84
+ informationUri: 'https://github.com/DescentVTT/spec-harness',
85
+ rules: ids.map((id) => ({ id, shortDescription: { text: describeRule(id) } })),
86
+ },
87
+ },
88
+ results: placed.map(({ finding, file, line, fingerprint }) => ({
89
+ ruleId: finding.rule,
90
+ level: SARIF_LEVEL[finding.severity],
91
+ message: { text: text(finding) },
92
+ locations: [{ physicalLocation: { artifactLocation: { uri: file, uriBaseId: '%SRCROOT%' }, region: { startLine: line } } }],
93
+ partialFingerprints: { specHarnessFinding: fingerprint },
94
+ })),
95
+ },
96
+ ],
97
+ };
98
+ return `${JSON.stringify(document, null, 2)}\n`;
99
+ }
100
+ /** A workflow command's message: `%`, and the line breaks that would end the command. */
101
+ function escapeData(value) {
102
+ return value.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
103
+ }
104
+ /** A workflow command's property: as a message, and the `:` and `,` that would end the property. */
105
+ function escapeProperty(value) {
106
+ return escapeData(value).replace(/:/g, '%3A').replace(/,/g, '%2C');
107
+ }
108
+ /** GitHub Actions workflow commands, one line each, which a job's log turns into annotations on the diff. */
109
+ export function formatGithub(findings, options) {
110
+ return place(findings, options.file)
111
+ .map(({ finding, file, line }) => {
112
+ const properties = `file=${escapeProperty(file)},line=${line},title=${escapeProperty(`spec-harness ${finding.rule}`)}`;
113
+ return `::${GITHUB_COMMAND[finding.severity]} ${properties}::${escapeData(text(finding))}\n`;
114
+ })
115
+ .join('');
116
+ }
117
+ export function formatFindings(format, findings, options) {
118
+ switch (format) {
119
+ case 'gitlab':
120
+ return formatGitlab(findings, options);
121
+ case 'sarif':
122
+ return formatSarif(findings, options);
123
+ case 'github':
124
+ return formatGithub(findings, options);
125
+ }
126
+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,GAAG,QAAQ,cAAc,CAAC,IAAI,CAAC,SAAS,IAAI,UAAU,cAAc,CAAC,gBAAgB,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QACvH,OAAO,KAAK,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,UAAU,KAAK,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;IAC/F,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAqB,EAAE,QAA4B,EAAE,OAAsB;IACxG,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACzC,KAAK,OAAO;YACV,OAAO,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACxC,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC","sourcesContent":["/**\n * Findings in the formats a forge reads beside a change: GitLab Code Quality,\n * SARIF 2.1.0 and GitHub workflow commands (spec-core ADR-0005).\n *\n * The shapes are the siblings': spec-brief's severities and its hint in the\n * text, spec-guard's fingerprint of a finding's identity. Pure: the command\n * prints what these return.\n */\n\nimport { createHash } from 'node:crypto';\n\nimport { RULES } from './audit.js';\nimport type { Finding, Severity } from './types.js';\n\n/** The formats that place findings, which `audit` and `premises` print. */\nexport type FindingFormat = 'gitlab' | 'sarif' | 'github';\n\nexport const FINDING_FORMATS: readonly FindingFormat[] = ['gitlab', 'sarif', 'github'];\n\nexport interface FormatOptions {\n /** Where a finding with no file of its own is placed: the brief the command is about. */\n readonly file: string;\n /** This tool's version, which SARIF names. */\n readonly version: string;\n /** What the run measured, which SARIF carries as a note beside its results. */\n readonly summary?: string | undefined;\n}\n\n/**\n * GitLab's severities. An error fails the run, but it is not the crash or the\n * security hole `critical` and `blocker` say in GitLab's own reports, so the\n * scale tops out at `major`, as spec-brief's does.\n */\nconst GITLAB_SEVERITY: Readonly<Record<Severity, string>> = { error: 'major', warning: 'minor', note: 'info' };\nconst SARIF_LEVEL: Readonly<Record<Severity, string>> = { error: 'error', warning: 'warning', note: 'note' };\nconst GITHUB_COMMAND: Readonly<Record<Severity, string>> = { error: 'error', warning: 'warning', note: 'notice' };\n\ninterface Placed {\n readonly finding: Finding;\n readonly file: string;\n readonly line: number;\n readonly fingerprint: string;\n}\n\n/**\n * Each finding with its place and its fingerprint. A finding about a whole\n * brief is placed on the brief's first line. The fingerprint is the SHA-256\n * of the finding's identity - its rule, its file and its subject - and never\n * of its message, hint or line: GitLab tells a new finding from one it has\n * seen by it, so a reworded message or a line added above must not read as\n * one problem fixed and another found. Two findings with one identity are\n * told apart by the order they come in.\n */\nfunction place(findings: readonly Finding[], fallback: string): Placed[] {\n const seen = new Map<string, number>();\n return findings.map((finding) => {\n const file = finding.file ?? fallback;\n const identity = [finding.rule, file, finding.subject ?? ''].join('\\u0000');\n const repeat = seen.get(identity) ?? 0;\n seen.set(identity, repeat + 1);\n const fingerprint = createHash('sha256').update(repeat === 0 ? identity : `${identity}\\u0000${repeat}`).digest('hex');\n return { finding, file, line: Math.max(finding.line ?? 1, 1), fingerprint };\n });\n}\n\n/**\n * The message and the next action, which every format carries (spec-core\n * ADR-0005). A message a sibling ended with a full stop keeps one.\n */\nfunction text(finding: Finding): string {\n return `${finding.message.replace(/\\.$/, '')}. ${finding.hint}`;\n}\n\n/** GitLab Code Quality: a JSON array of issues, which a merge request shows beside the lines they are on. */\nexport function formatGitlab(findings: readonly Finding[], options: FormatOptions): string {\n const issues = place(findings, options.file).map(({ finding, file, line, fingerprint }) => ({\n description: text(finding),\n check_name: finding.rule,\n fingerprint,\n severity: GITLAB_SEVERITY[finding.severity],\n location: { path: file, lines: { begin: line } },\n }));\n return `${JSON.stringify(issues, null, 2)}\\n`;\n}\n\n/** How SARIF describes a rule: the audit's own words, or the archive rule spec-brief gave. */\nfunction describeRule(id: string): string {\n if (id.startsWith('archive/')) return `A reason spec-brief's archive gives: ${id.slice('archive/'.length)}.`;\n return RULES[id] ?? id;\n}\n\n/**\n * SARIF 2.1.0, for code scanning. What the run measured is a note in the\n * invocation, SARIF's place for what happened in a run that is not a finding,\n * so a page with no result still says what was checked.\n */\nexport function formatSarif(findings: readonly Finding[], options: FormatOptions): string {\n const placed = place(findings, options.file);\n const ids = [...new Set(findings.map((finding) => finding.rule))].sort();\n const document = {\n $schema: 'https://json.schemastore.org/sarif-2.1.0.json',\n version: '2.1.0',\n runs: [\n {\n ...(options.summary === undefined\n ? {}\n : { invocations: [{ executionSuccessful: true, toolExecutionNotifications: [{ level: 'note', message: { text: options.summary } }] }] }),\n tool: {\n driver: {\n name: 'spec-harness',\n version: options.version,\n informationUri: 'https://github.com/DescentVTT/spec-harness',\n rules: ids.map((id) => ({ id, shortDescription: { text: describeRule(id) } })),\n },\n },\n results: placed.map(({ finding, file, line, fingerprint }) => ({\n ruleId: finding.rule,\n level: SARIF_LEVEL[finding.severity],\n message: { text: text(finding) },\n locations: [{ physicalLocation: { artifactLocation: { uri: file, uriBaseId: '%SRCROOT%' }, region: { startLine: line } } }],\n partialFingerprints: { specHarnessFinding: fingerprint },\n })),\n },\n ],\n };\n return `${JSON.stringify(document, null, 2)}\\n`;\n}\n\n/** A workflow command's message: `%`, and the line breaks that would end the command. */\nfunction escapeData(value: string): string {\n return value.replace(/%/g, '%25').replace(/\\r/g, '%0D').replace(/\\n/g, '%0A');\n}\n\n/** A workflow command's property: as a message, and the `:` and `,` that would end the property. */\nfunction escapeProperty(value: string): string {\n return escapeData(value).replace(/:/g, '%3A').replace(/,/g, '%2C');\n}\n\n/** GitHub Actions workflow commands, one line each, which a job's log turns into annotations on the diff. */\nexport function formatGithub(findings: readonly Finding[], options: FormatOptions): string {\n return place(findings, options.file)\n .map(({ finding, file, line }) => {\n const properties = `file=${escapeProperty(file)},line=${line},title=${escapeProperty(`spec-harness ${finding.rule}`)}`;\n return `::${GITHUB_COMMAND[finding.severity]} ${properties}::${escapeData(text(finding))}\\n`;\n })\n .join('');\n}\n\nexport function formatFindings(format: FindingFormat, findings: readonly Finding[], options: FormatOptions): string {\n switch (format) {\n case 'gitlab':\n return formatGitlab(findings, options);\n case 'sarif':\n return formatSarif(findings, options);\n case 'github':\n return formatGithub(findings, options);\n }\n}\n"]}
package/dist/git.d.ts CHANGED
@@ -21,6 +21,12 @@ export declare class GitError extends Error {
21
21
  export declare function workTreeRoot(cwd: string): Promise<string | null>;
22
22
  /** The git directory every worktree of this repository shares. */
23
23
  export declare function commonDirectory(cwd: string): Promise<string | null>;
24
+ /**
25
+ * Where git runs the hook `name` from, absolute: `core.hooksPath` read as git
26
+ * reads it - relative to the work tree, absolute, or under `~` - and a linked
27
+ * worktree's shared hooks. `null` when git cannot say, before 2.31.
28
+ */
29
+ export declare function hookPath(name: string, cwd: string): Promise<string | null>;
24
30
  /** The checked-out branch's short name, or `null` on a detached head. */
25
31
  export declare function currentBranch(cwd: string): Promise<string | null>;
26
32
  /** The remote's default branch as a local ref, such as `origin/main`, or `null`. */
package/dist/git.js CHANGED
@@ -36,6 +36,14 @@ export async function workTreeRoot(cwd) {
36
36
  export async function commonDirectory(cwd) {
37
37
  return value(['rev-parse', '--path-format=absolute', '--git-common-dir'], cwd);
38
38
  }
39
+ /**
40
+ * Where git runs the hook `name` from, absolute: `core.hooksPath` read as git
41
+ * reads it - relative to the work tree, absolute, or under `~` - and a linked
42
+ * worktree's shared hooks. `null` when git cannot say, before 2.31.
43
+ */
44
+ export async function hookPath(name, cwd) {
45
+ return value(['rev-parse', '--path-format=absolute', '--git-path', `hooks/${name}`], cwd);
46
+ }
39
47
  /** The checked-out branch's short name, or `null` on a detached head. */
40
48
  export async function currentBranch(cwd) {
41
49
  return value(['symbolic-ref', '--quiet', '--short', 'HEAD'], cwd);