@descent-vtt/spec-harness 0.6.0 → 0.8.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 (87) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +118 -0
  4. package/README.md +275 -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 +53 -13
  13. package/dist/cli.js.map +1 -1
  14. package/dist/commands.js +12 -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 +62 -3
  19. package/dist/configure.js +121 -5
  20. package/dist/configure.js.map +1 -1
  21. package/dist/context.d.ts +23 -7
  22. package/dist/context.js +69 -21
  23. package/dist/context.js.map +1 -1
  24. package/dist/document.d.ts +15 -2
  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 +15 -0
  36. package/dist/host.js +111 -0
  37. package/dist/host.js.map +1 -0
  38. package/dist/index.d.ts +4 -2
  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 +52 -14
  46. package/dist/premises.js.map +1 -1
  47. package/dist/reader.js +28 -3
  48. package/dist/reader.js.map +1 -1
  49. package/dist/round.d.ts +8 -0
  50. package/dist/round.js +70 -23
  51. package/dist/round.js.map +1 -1
  52. package/dist/server.js +10 -3
  53. package/dist/server.js.map +1 -1
  54. package/dist/setup.d.ts +10 -0
  55. package/dist/setup.js +73 -32
  56. package/dist/setup.js.map +1 -1
  57. package/dist/siblings.d.ts +2 -0
  58. package/dist/siblings.js +1 -1
  59. package/dist/siblings.js.map +1 -1
  60. package/dist/signers.d.ts +46 -0
  61. package/dist/signers.js +180 -0
  62. package/dist/signers.js.map +1 -0
  63. package/dist/types.d.ts +7 -0
  64. package/dist/types.js.map +1 -1
  65. package/dist/vendor/spec-core/markdown/frontmatter.d.ts +11 -1
  66. package/dist/vendor/spec-core/markdown/frontmatter.js +20 -3
  67. package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -1
  68. package/dist/vendor/spec-core/pattern/glob.d.ts +85 -0
  69. package/dist/vendor/spec-core/pattern/glob.js +207 -17
  70. package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
  71. package/dist/vendor/spec-core/pattern/index.d.ts +2 -2
  72. package/dist/vendor/spec-core/pattern/index.js +1 -1
  73. package/dist/vendor/spec-core/pattern/index.js.map +1 -1
  74. package/dist/vendor/spec-core/text/index.d.ts +1 -0
  75. package/dist/vendor/spec-core/text/index.js +1 -0
  76. package/dist/vendor/spec-core/text/index.js.map +1 -1
  77. package/dist/vendor/spec-core/text/width.d.ts +30 -0
  78. package/dist/vendor/spec-core/text/width.js +113 -0
  79. package/dist/vendor/spec-core/text/width.js.map +1 -0
  80. package/dist/versions.d.ts +40 -1
  81. package/dist/versions.js +33 -1
  82. package/dist/versions.js.map +1 -1
  83. package/dist/workspace.d.ts +6 -1
  84. package/dist/workspace.js +17 -6
  85. package/dist/workspace.js.map +1 -1
  86. package/package.json +1 -1
  87. package/skills/close-round/SKILL.md +4 -1
package/dist/context.js CHANGED
@@ -9,12 +9,15 @@
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, 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.
12
+ * shown as one without a status, and a line of front matter that is not
13
+ * `key: value`, passed over with any status written on it; and a pattern in
14
+ * the scope, a protection or a ruling's path the guard cannot read, with
15
+ * spec-core's reason and what the guard does without it, rather than listed
16
+ * as one it can; and one a leading `/` roots, which names no path the guard
17
+ * decides.
15
18
  */
16
19
  import { sameId } from './branch.js';
17
- import { whyUnreadable } from './guard.js';
20
+ import { rooted, whyUnreadable } from './guard.js';
18
21
  /**
19
22
  * spec-guard's answer to `query --json`, read. It exits 2 both when no spec
20
23
  * file matched its patterns - a repository that keeps none, or keeps them
@@ -47,23 +50,36 @@ export function readRules(answer) {
47
50
  function list(items) {
48
51
  return items.map((item) => `- \`${item}\``).join('\n');
49
52
  }
53
+ /** An unread line of front matter: where it is, as written, and spec-core's reason. */
54
+ function unreadLine(found) {
55
+ return `- \`${found.path}\`, line ${found.line}, \`${found.text}\`: ${found.reason}`;
56
+ }
50
57
  /**
51
58
  * Each pattern a line, as the guard reads it: as written, or with spec-core's
52
59
  * reason the guard cannot read it and what the guard does without it. The
53
60
  * guard's own compile decides, so the packet and the guard cannot disagree.
61
+ * A pattern a leading `/` roots, or one of whose alternatives it roots, is
62
+ * marked with `rootedNote`, and counted when every alternative is rooted.
54
63
  */
55
- function patternLines(patterns, consequence) {
64
+ function patternLines(patterns, consequence, rootedNote) {
56
65
  const unreadable = [];
66
+ let rootedWhole = 0;
57
67
  const lines = patterns.map((pattern) => {
58
68
  const reason = whyUnreadable(pattern);
59
- if (reason === null)
60
- return `- \`${pattern}\``;
69
+ if (reason === null) {
70
+ const root = rooted(pattern);
71
+ if (root === null)
72
+ return `- \`${pattern}\``;
73
+ if (root === 'whole')
74
+ rootedWhole += 1;
75
+ return `- \`${pattern}\`, ${rootedNote[root]}`;
76
+ }
61
77
  unreadable.push({ pattern, reason });
62
78
  return `- \`${pattern}\`, which the guard cannot read: ${reason}; ${consequence}`;
63
79
  });
64
- return { lines, unreadable };
80
+ return { lines, unreadable, rootedWhole };
65
81
  }
66
- function rulesSection(rules, scopeUnread) {
82
+ function rulesSection(rules, scopeUnread, scopeRooted) {
67
83
  if ('none' in rules)
68
84
  return `spec-guard holds no rule over this scope: ${rules.none}.`;
69
85
  if ('unavailable' in rules) {
@@ -73,8 +89,11 @@ function rulesSection(rules, scopeUnread) {
73
89
  // With no pattern of the scope readable, spec-guard was asked about no
74
90
  // path, so an empty answer is no answer: "no rule" would tell the agent
75
91
  // the code it writes is unconstrained.
76
- return scopeUnread
77
- ? '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.'
92
+ if (scopeUnread) {
93
+ 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.';
94
+ }
95
+ return scopeRooted
96
+ ? "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."
78
97
  : 'spec-guard holds no rule over this scope.';
79
98
  }
80
99
  const byDocument = new Map();
@@ -90,15 +109,19 @@ function rulesSection(rules, scopeUnread) {
90
109
  return parts.join('\n').trimEnd();
91
110
  }
92
111
  /**
93
- * A brief's title without the id it repeats: `012 - Rotate tokens` read as
94
- * `Rotate tokens`, and the same with an en or an em dash, which `spec-brief
95
- * new` writes, or with a colon after the id. Only the brief's own id is taken
96
- * off: `Fix - the login bug` is a title, not an id and a title.
112
+ * A brief's title without the id it repeats, by the rules spec-brief reads
113
+ * it with: the brief's own id, then an em dash, which `spec-brief new`
114
+ * writes, an en dash, a full-width colon or a colon, spaced or not, or a
115
+ * hyphen with a space on each side; `012 - Rotate tokens`, `012\u2014Rotate
116
+ * tokens` and `012\uFF1ARotate tokens` read as `Rotate tokens`. A bare hyphen
117
+ * is part of a word or a number, as in `001-2 migration`, and only the
118
+ * brief's own id is taken off: `Fix - the login bug` is a title, and so is
119
+ * `0010 \u2014 x` on brief 001.
97
120
  */
98
121
  export function titleOf(brief) {
99
122
  if (brief.title === null)
100
123
  return null;
101
- return brief.title.replace(/^\s*([^\s:]+)(?:\s+[-\u2013\u2014]|:)\s+/, (whole, first) => (sameId(first, brief.id) ? '' : whole));
124
+ return brief.title.replace(/^\s*([^\s:\uFF1A\u2013\u2014]+)(?:\s*[:\uFF1A\u2013\u2014]\s*|\s+-\s+)(?=\S)/, (whole, first) => sameId(first, brief.id) ? '' : whole);
102
125
  }
103
126
  /** Renders the packet, filling the budget with cited documents in the order the brief cites them. */
104
127
  export function renderContext(input) {
@@ -128,20 +151,36 @@ export function renderContext(input) {
128
151
  .map((ruling) => {
129
152
  const paths = ruling.paths.map((pattern) => {
130
153
  const reason = whyUnreadable(pattern);
131
- if (reason === null)
154
+ if (reason === null) {
155
+ // A rooted path can be read, and names no path the guard decides.
156
+ const root = rooted(pattern);
157
+ if (root === 'whole')
158
+ return `\`${pattern}\` (which a leading \`/\` roots at the filesystem's root; it allows nothing)`;
159
+ if (root === 'part')
160
+ return `\`${pattern}\` (an alternative of which a leading \`/\` roots at the filesystem's root; that alternative allows nothing)`;
132
161
  return `\`${pattern}\``;
162
+ }
133
163
  unreadableRulingPaths.push({ ruling: ruling.id, pattern, reason });
134
164
  return `\`${pattern}\` (which the guard cannot read: ${reason}; it allows nothing)`;
135
165
  });
136
166
  return `- ${ruling.id}, signed by ${ruling.signer}: ${paths.join(', ')}`;
137
167
  })
138
168
  .join('\n');
139
- const mayWrite = patternLines(brief.affectedFiles, 'it puts no path in the scope');
169
+ // A rooted pattern can be read and puts no path in the scope: every path
170
+ // the guard decides is repository-relative. spec-guard is not asked about it.
171
+ const mayWrite = patternLines(brief.affectedFiles, 'it puts no path in the scope', {
172
+ 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",
173
+ 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",
174
+ });
140
175
  const unreadableScope = mayWrite.unreadable;
141
176
  // While a protection the guard cannot read stands, the guard refuses every
142
177
  // write, and no ruling waives it; a write to the brief is let through,
143
- // since that is where it is fixed.
144
- const mustNot = patternLines(brief.protectedFiles, 'until it is fixed, the guard refuses every write but to the brief');
178
+ // since that is where it is fixed. A rooted protection can be read, and
179
+ // protects nothing: the file it was meant to protect is the round's to write.
180
+ const mustNot = patternLines(brief.protectedFiles, 'until it is fixed, the guard refuses every write but to the brief', {
181
+ whole: "which a leading `/` roots at the filesystem's root: it protects no path",
182
+ part: "an alternative of which a leading `/` roots at the filesystem's root: that alternative protects no path",
183
+ });
145
184
  const unreadableProtections = mustNot.unreadable;
146
185
  const scope = [
147
186
  '## Scope, as the guard reads it',
@@ -163,7 +202,8 @@ export function renderContext(input) {
163
202
  });
164
203
  const dependencies = ['## Depends on', '', waiting.length === 0 ? '- nothing' : waiting.join('\n'), ''].join('\n');
165
204
  const scopeUnread = mayWrite.lines.length > 0 && unreadableScope.length === mayWrite.lines.length;
166
- const rules = ['## Rules in force for this scope', '', rulesSection(input.rules, scopeUnread), ''].join('\n');
205
+ const scopeRooted = mayWrite.rootedWhole > 0 && unreadableScope.length + mayWrite.rootedWhole === mayWrite.lines.length;
206
+ const rules = ['## Rules in force for this scope', '', rulesSection(input.rules, scopeUnread, scopeRooted), ''].join('\n');
167
207
  const howTo = [
168
208
  '## How this round works',
169
209
  '',
@@ -178,6 +218,7 @@ export function renderContext(input) {
178
218
  const omitted = [];
179
219
  const unresolved = [];
180
220
  const unclosed = [];
221
+ const unreadableFrontMatter = [];
181
222
  const documents = [];
182
223
  let used = fixed.length;
183
224
  for (const cited of input.cited) {
@@ -189,6 +230,8 @@ export function renderContext(input) {
189
230
  // unread either way, and the fix is the same.
190
231
  if (cited.unclosedFrontMatter === true)
191
232
  unclosed.push(cited.path);
233
+ for (const line of cited.unreadableFrontMatter ?? [])
234
+ unreadableFrontMatter.push({ path: cited.path, ...line });
192
235
  const heading = `### \`${cited.path}\`${cited.title === null ? '' : ` - ${cited.title}`}${cited.status === null ? '' : ` (${cited.status})`}`;
193
236
  const block = [heading, '', '````markdown', cited.text.trimEnd(), '````', ''].join('\n');
194
237
  if (used + block.length > input.budget) {
@@ -211,12 +254,17 @@ export function renderContext(input) {
211
254
  if (unclosed.length > 0) {
212
255
  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), '');
213
256
  }
257
+ // The last note: the section is trimmed at its end, so no blank line follows it.
258
+ if (unreadableFrontMatter.length > 0) {
259
+ citedSection.push('Front matter lines that are not `key: value` were not read, so a status written on one, if any, was not read either:', unreadableFrontMatter.map(unreadLine).join('\n'));
260
+ }
214
261
  return {
215
262
  markdown: `${fixed}\n${citedSection.join('\n').trimEnd()}\n`,
216
263
  included,
217
264
  omitted,
218
265
  unresolved,
219
266
  unclosedFrontMatter: unclosed,
267
+ unreadableFrontMatter,
220
268
  unreadableScope,
221
269
  unreadableProtections,
222
270
  unreadableRulingPaths,
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiC3C;;;;;;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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AAC;QACrB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IACD,MAAM,YAAY,GAAG,CAAC,8BAA8B,EAAE,EAAE,CAAC,CAAC;IAC1D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC9G,YAAY,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IAChC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,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.\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 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 */\nfunction patternLines(patterns: readonly string[], consequence: string): { lines: string[]; unreadable: UnreadablePattern[] } {\n const unreadable: UnreadablePattern[] = [];\n const lines = patterns.map((pattern) => {\n const reason = whyUnreadable(pattern);\n if (reason === null) return `- \\`${pattern}\\``;\n unreadable.push({ pattern, reason });\n return `- \\`${pattern}\\`, which the guard cannot read: ${reason}; ${consequence}`;\n });\n return { lines, unreadable };\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 // 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) return `\\`${pattern}\\``;\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 const mayWrite = patternLines(brief.affectedFiles, 'it puts no path in the scope');\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.\n const mustNot = patternLines(brief.protectedFiles, 'until it is fixed, the guard refuses every write but to the brief');\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 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 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"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAmCnD;;;;;;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,CA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QACrB,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 line of front matter that is not\n * `key: value`, passed over with any status written on it; and a pattern in\n * the scope, a protection or a ruling's path the guard cannot read, with\n * spec-core's reason and what the guard does without it, rather than listed\n * as one it can; and one a leading `/` roots, which names no path the guard\n * decides.\n */\n\nimport { sameId } from './branch.js';\nimport type { UnreadableFrontMatterLine } from './document.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 /** Lines of its front matter that are not `key: value`, passed over with any status written on them. */\n readonly unreadableFrontMatter?: readonly UnreadableFrontMatterLine[] | 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 line of a cited document's front matter that is not `key: value`, with spec-core's reason. */\nexport interface UnreadableFrontMatter extends UnreadableFrontMatterLine {\n readonly path: 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 /** Lines of cited documents' front matter that are not `key: value`, in the order the brief cites them: a status written on one was not read. */\n readonly unreadableFrontMatter: readonly UnreadableFrontMatter[];\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/** An unread line of front matter: where it is, as written, and spec-core's reason. */\nfunction unreadLine(found: UnreadableFrontMatter): string {\n return `- \\`${found.path}\\`, line ${found.line}, \\`${found.text}\\`: ${found.reason}`;\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 * A pattern a leading `/` roots, or one of whose alternatives it roots, is\n * marked with `rootedNote`, and counted when every alternative 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 = rooted(pattern);\n if (root === null) return `- \\`${pattern}\\``;\n if (root === 'whole') rootedWhole += 1;\n return `- \\`${pattern}\\`, ${rootedNote[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 unreadableFrontMatter: UnreadableFrontMatter[] = [];\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 for (const line of cited.unreadableFrontMatter ?? []) unreadableFrontMatter.push({ path: cited.path, ...line });\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 // The last note: the section is trimmed at its end, so no blank line follows it.\n if (unreadableFrontMatter.length > 0) {\n citedSection.push(\n 'Front matter lines that are not `key: value` were not read, so a status written on one, if any, was not read either:',\n unreadableFrontMatter.map(unreadLine).join('\\n'),\n );\n }\n\n return {\n markdown: `${fixed}\\n${citedSection.join('\\n').trimEnd()}\\n`,\n included,\n omitted,\n unresolved,\n unclosedFrontMatter: unclosed,\n unreadableFrontMatter,\n unreadableScope,\n unreadableProtections,\n unreadableRulingPaths,\n };\n}\n"]}
@@ -19,6 +19,15 @@ export interface SectionTables {
19
19
  /** 0-based index of the line after the section's last table row, or `null` when it has no table. */
20
20
  readonly tableEndLine: number | null;
21
21
  }
22
+ /** A line of front matter spec-core's reader passes over, since it is not `key: value`. */
23
+ export interface UnreadableFrontMatterLine {
24
+ /** 1-based. */
25
+ readonly line: number;
26
+ /** The line as written. */
27
+ readonly text: string;
28
+ /** spec-core's reason it was not read. */
29
+ readonly reason: string;
30
+ }
22
31
  export interface DocumentReader {
23
32
  codeBlocks(text: string): CodeBlock[];
24
33
  sectionAt(text: string, line: number): string | null;
@@ -27,13 +36,17 @@ export interface DocumentReader {
27
36
  sectionTables(text: string, section: string): SectionTables;
28
37
  citations(text: string): Citation[];
29
38
  /**
30
- * The first level-one heading, and the front matter's status. YAML front
39
+ * The first level-one heading, and the front matter's `status`. YAML front
31
40
  * matter opened on line 1 and never closed is `unclosedFrontMatter`: none
32
- * of it is read, so a status its author wrote there reads as none.
41
+ * of it is read, so a status its author wrote there reads as none. A line
42
+ * of closed YAML front matter that is not `key: value` is in
43
+ * `unreadableFrontMatter`: it is passed over, and a status written on it
44
+ * with it, as `status accepted` without its colon writes one.
33
45
  */
34
46
  titleAndStatus(text: string): {
35
47
  readonly title: string | null;
36
48
  readonly status: string | null;
37
49
  readonly unclosedFrontMatter: boolean;
50
+ readonly unreadableFrontMatter: readonly UnreadableFrontMatterLine[];
38
51
  };
39
52
  }
@@ -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\n/** A line of front matter spec-core's reader passes over, since it is not `key: value`. */\nexport interface UnreadableFrontMatterLine {\n /** 1-based. */\n readonly line: number;\n /** The line as written. */\n readonly text: string;\n /** spec-core's reason it was not read. */\n readonly reason: string;\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. A line\n * of closed YAML front matter that is not `key: value` is in\n * `unreadableFrontMatter`: it is passed over, and a status written on it\n * with it, as `status accepted` without its colon writes one.\n */\n titleAndStatus(text: string): {\n readonly title: string | null;\n readonly status: string | null;\n readonly unclosedFrontMatter: boolean;\n readonly unreadableFrontMatter: readonly UnreadableFrontMatterLine[];\n };\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
+ }
127
+ //# sourceMappingURL=formats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.js","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAMnC,MAAM,CAAC,MAAM,eAAe,GAA6B,CAAC,QA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I,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);