@outerlayer/cli 0.12.0 → 0.13.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 (83) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +9 -4
  3. package/dist/{agent-setup-52LRZ6AY.js → agent-setup-QE6PSCEZ.js} +8 -8
  4. package/dist/build-info.json +1 -1
  5. package/dist/{builder-OF67QKDS.js → builder-UUS4ORDH.js} +3 -3
  6. package/dist/{check-RJOJU2WA.js → check-63IDCEEV.js} +27 -27
  7. package/dist/{chunk-XR3BJN33.js → chunk-22RMZBGW.js} +20 -1
  8. package/dist/{chunk-AHZQBGD2.js → chunk-2M63GG56.js} +1 -1
  9. package/dist/{chunk-27Y7AX2O.js → chunk-3D4OYFCD.js} +4 -4
  10. package/dist/{chunk-GGMRZPEA.js → chunk-3KTA5UU2.js} +1 -1
  11. package/dist/{chunk-USO2DKBD.js → chunk-4KSQKQXE.js} +8 -2
  12. package/dist/{chunk-C7N4TDHW.js → chunk-4QVZCVWT.js} +5 -5
  13. package/dist/{chunk-NPXQXYVA.js → chunk-6S3H3J6H.js} +2 -2
  14. package/dist/{chunk-DVT73QJO.js → chunk-C6IV5BV7.js} +10 -10
  15. package/dist/{chunk-JOXYKGUV.js → chunk-CNFVHDHG.js} +1 -1
  16. package/dist/{chunk-ANW7VHMH.js → chunk-DPKX26LT.js} +92 -16
  17. package/dist/{chunk-ZQUCTFXC.js → chunk-DXQ5MHCO.js} +1 -1
  18. package/dist/{chunk-GATMPAMK.js → chunk-EFZLAYPE.js} +2 -2
  19. package/dist/{chunk-SZOVKFWB.js → chunk-GI4XXD4I.js} +3 -3
  20. package/dist/{chunk-G5XY6CVG.js → chunk-HDTVTA6I.js} +2 -2
  21. package/dist/{chunk-325272HM.js → chunk-J5M7BSJQ.js} +11 -4
  22. package/dist/{chunk-3ZPYPFNM.js → chunk-JXYVA45C.js} +1 -1
  23. package/dist/{chunk-G5IEVZGI.js → chunk-LCEXHCHD.js} +1 -1
  24. package/dist/{chunk-GEBQXUFY.js → chunk-MJXXRX4M.js} +24 -10
  25. package/dist/{chunk-SKHN72JO.js → chunk-MZN7AQOB.js} +8 -8
  26. package/dist/{chunk-QEESCZ26.js → chunk-NX57IBNK.js} +1 -1
  27. package/dist/{chunk-6FH2AHJY.js → chunk-P4MM66C6.js} +30 -17
  28. package/dist/{chunk-IBB4D4KE.js → chunk-P6FX4D43.js} +1 -1
  29. package/dist/{chunk-A56PYPDF.js → chunk-R7OQTKWT.js} +2 -1
  30. package/dist/{chunk-2KLBKHT4.js → chunk-RLYZLUQ7.js} +1 -1
  31. package/dist/chunk-RMWLBUCJ.js +50 -0
  32. package/dist/{chunk-YEQL54G5.js → chunk-SFFHGX3G.js} +1 -1
  33. package/dist/{chunk-G4RXNF2L.js → chunk-SVEP7PVH.js} +12 -12
  34. package/dist/{chunk-VK25O2ZM.js → chunk-T5VPP6H7.js} +1 -1
  35. package/dist/{chunk-FO7KKPYG.js → chunk-TCIW27FM.js} +1 -1
  36. package/dist/{chunk-PDRYXERC.js → chunk-TOPDNXHZ.js} +5 -5
  37. package/dist/{chunk-5TGQHOUX.js → chunk-XJKL4BNU.js} +3 -3
  38. package/dist/{cli-JSSRGA6V.js → cli-WSBIAVZU.js} +116 -80
  39. package/dist/{command-3WYZ2ML5.js → command-N7BAB4XJ.js} +18 -18
  40. package/dist/{config-MKBX2ZQD.js → config-N3C6DFQA.js} +1 -1
  41. package/dist/{connect-cmd-A5NGODCJ.js → connect-cmd-FGYRLLXL.js} +5 -5
  42. package/dist/{context-adopt-BAHGXJZV.js → context-adopt-B3PWGFHL.js} +5 -5
  43. package/dist/{context-materialize-45OVRRK2.js → context-materialize-7S6NLLRO.js} +5 -5
  44. package/dist/{dist-EQDW7MZW.js → dist-LKDWQWZ7.js} +2 -2
  45. package/dist/{docker-VGWEJWI7.js → docker-BZ55BMBJ.js} +4 -4
  46. package/dist/{doctor-4FFXTQJ2.js → doctor-3H25Q7WT.js} +20 -20
  47. package/dist/{emit-artifact-cmd-QS7XNKBT.js → emit-artifact-cmd-IQCRXOH7.js} +8 -8
  48. package/dist/{emit-cmd-LXEIDKLT.js → emit-cmd-KDSM5VAO.js} +4 -4
  49. package/dist/{emit-criteria-cmd-XN6AKA53.js → emit-criteria-cmd-EYUXME26.js} +6 -6
  50. package/dist/{emit-finding-cmd-SQJSEHYS.js → emit-finding-cmd-P4RKBPBB.js} +6 -6
  51. package/dist/{emit-result-cmd-56RHPHOA.js → emit-result-cmd-6XYENU6H.js} +8 -8
  52. package/dist/{hook-fast-HLESEJAL.js → hook-fast-PXWKQPN6.js} +1 -1
  53. package/dist/{import-capture-cmd-NHMAFDM6.js → import-capture-cmd-2BKM5I2N.js} +3 -3
  54. package/dist/{import-ruler-cmd-UYB32YUT.js → import-ruler-cmd-IXR7YK47.js} +2 -2
  55. package/dist/index.js +3 -3
  56. package/dist/{init-UZKD4RY7.js → init-2LWVS4AH.js} +19 -19
  57. package/dist/{init-6AY5T3P6.js → init-ZL7ORPTF.js} +38 -28
  58. package/dist/{init-cmd-XGSX2BCC.js → init-cmd-JXOBCOIB.js} +14 -12
  59. package/dist/{install-VXXI7UR6.js → install-HDBIPHTX.js} +2 -2
  60. package/dist/{login-browser-7XGSV7MA.js → login-browser-QZCS3WW6.js} +2 -1
  61. package/dist/{loop-4NMI2USY.js → loop-XOAE6ZIY.js} +27 -27
  62. package/dist/{machine-4JX2D4TS.js → machine-G6PY2J2J.js} +15 -15
  63. package/dist/{mcp-install-cmd-XZARXNYT.js → mcp-install-cmd-VXVIH7PH.js} +1 -1
  64. package/dist/{runner-env-WAXTJXZK.js → runner-env-XTC53CHN.js} +3 -3
  65. package/dist/runner-key-TDTLNAKJ.js +154 -0
  66. package/dist/{session-sender-T7PN4YRC.js → session-sender-XVGZFWRK.js} +6 -6
  67. package/dist/{starter-pack-Z22VRFPF.js → starter-pack-B7JPGEDO.js} +4 -4
  68. package/dist/{status-OXBIRWJ7.js → status-MRTPG34B.js} +20 -20
  69. package/dist/{sync-cmd-EVXNR47N.js → sync-cmd-UBUZMMDN.js} +5 -5
  70. package/dist/{watch-7NSFOAL5.js → watch-STNPEWD6.js} +5 -5
  71. package/dist/{work-claim-cmd-KR7UR2AB.js → work-claim-cmd-CWGYEIJE.js} +10 -10
  72. package/dist/{work-cmd-JPM37MLF.js → work-cmd-X7NMJDFL.js} +7 -7
  73. package/dist/{work-comment-cmd-3DC6BC34.js → work-comment-cmd-FI2TMAYQ.js} +7 -7
  74. package/dist/{work-open-pr-cmd-XZQRJBNZ.js → work-open-pr-cmd-OVHJ5I5H.js} +8 -8
  75. package/dist/{work-pr-cmd-WHGZOP22.js → work-pr-cmd-Y5TDMQ4O.js} +7 -7
  76. package/package.json +1 -1
  77. package/skill-pack/template/build/SKILL.md +60 -33
  78. package/skill-pack/template/build/references/agent-briefs.md +4 -2
  79. package/skill-pack/template/build/references/release.md +1 -1
  80. package/skill-pack/template/build/references/review-loop.md +6 -2
  81. package/skill-pack/template/build/scripts/record-criteria.mjs +109 -143
  82. package/skill-pack/validators/code-review.yaml +4 -2
  83. package/dist/chunk-T6OIJQRT.js +0 -31
@@ -1,13 +1,19 @@
1
1
  #!/usr/bin/env node
2
- // Reads an issue body, finds the acceptance criteria, writes them as the
3
- // list `outerlayer emit criteria` takes, records the list, and notes the
4
- // outcome in the build's state file. Needs only Node.
2
+ // Records the criteria the build read from the issue, or drafted for an issue
3
+ // that has none, and notes the outcome in the build's state file. The agent
4
+ // reads the issue and writes the criteria file; this script checks it, gives
5
+ // the criteria ids, runs `outerlayer emit criteria`, and handles its answer.
6
+ // Needs only Node.
5
7
  //
6
- // node record-criteria.mjs --item <number> --issue-file <path>
8
+ // node record-criteria.mjs --item <number> --criteria-file <path> [--drafted]
7
9
  //
8
- // It never edits the issue, never replaces a list a person recorded (the
9
- // gateway answers 409 and the item's list stands), and records nothing when
10
- // the issue holds neither shape.
10
+ // The criteria file is `{ "criteria": [{ "id"?, "text", "proof"? }] }`, in
11
+ // the order the issue lists them. The ids are kept only when every criterion
12
+ // carries one that fits the id grammar; otherwise every criterion is numbered
13
+ // `AC-<item>-NN` in order. A drafted list is always numbered and is recorded
14
+ // with `drafted: true`. An empty list records nothing. The script never edits
15
+ // the issue, and never replaces a list the item already has (the gateway
16
+ // answers 409 and the item's list stands).
11
17
  import { spawnSync } from "node:child_process";
12
18
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
13
19
  import { dirname, join } from "node:path";
@@ -15,118 +21,64 @@ import { pathToFileURL } from "node:url";
15
21
 
16
22
  /** Mirrors ARTIFACT_KINDS in @outerlayer/session-schema (a test pins them equal); this script imports no packages. */
17
23
  export const PROOF_KINDS = ["video", "screenshot", "report", "log", "test", "file"];
18
- const BULLET = /^\s*(?:[-*+]|\d+[.)])\s+(.*)$/;
19
- const HEADING = /^\s{0,3}(#{1,6})\s+(.*?)\s*#*\s*$/;
20
- const ID_ITEM = /^`([A-Za-z0-9_.:-]{1,64})`\s*(.*)$/;
21
- const LABEL = /^\s{0,3}(?:#{1,6}\s+)?(?:\*\*|__)?(acceptance(?: criteria)?|done when)\s*:?\s*(?:\*\*|__)?\s*:?\s*$/i;
24
+ /** Mirrors ArtifactCriterionIdSchema in @outerlayer/session-schema (a test pins them equal). */
25
+ export const CRITERION_ID = /^[A-Za-z0-9_.:-]{1,64}$/;
26
+ /** Mirrors CHECK_BOUND_ARTIFACT_IDS in @outerlayer/session-schema (a test pins them equal): ids that name a check, not a criterion. */
27
+ export const RESERVED_IDS = ["code-review-ran", "acceptance-criteria"];
28
+ const PROOF_IN_TEXT = /\(proof:\s*([a-z]+)\s*\)/i;
22
29
 
23
- /** The lines with the contents of fenced code blocks, and the fences, blanked: a quoted example is not a section. */
24
- function blankFencedLines(lines) {
25
- let fence = null;
26
- return lines.map((line) => {
27
- const opener = /^\s{0,3}(`{3,}|~{3,})/.exec(line);
28
- if (fence === null) {
29
- if (opener === null) return line;
30
- fence = opener[1];
31
- return "";
32
- }
33
- if (opener !== null && opener[1][0] === fence[0] && opener[1].length >= fence.length) fence = null;
34
- return "";
35
- });
36
- }
37
-
38
- /** A bullet and the indented lines continuing it, as one string. */
39
- function collectItems(lines, start) {
40
- const items = [];
41
- let i = start;
42
- for (; i < lines.length; i++) {
43
- const line = lines[i];
44
- const bullet = BULLET.exec(line);
45
- if (bullet) {
46
- items.push(bullet[1].trim());
47
- } else if (line.trim() === "") {
48
- // a blank line ends the list unless another bullet follows
49
- const next = lines.slice(i + 1).find((l) => l.trim() !== "");
50
- if (next === undefined || !BULLET.test(next)) break;
51
- } else if (/^\s+\S/.test(line) && items.length > 0) {
52
- items[items.length - 1] += ` ${line.trim()}`;
53
- } else {
54
- break;
55
- }
56
- }
57
- return items;
58
- }
30
+ /** A criteria file the agent must fix before anything is recorded. */
31
+ export class CriteriaFileError extends Error {}
59
32
 
60
- function stripCheckbox(text) {
61
- return text.replace(/^\[[ xX]\]\s+/, "");
33
+ /** The proof a criterion declares: the file's `proof` when it is an artifact
34
+ * kind, else a `(proof: <kind>)` written in its text, else `null`. */
35
+ function proofOf(entry) {
36
+ if (PROOF_KINDS.includes(entry.proof)) return entry.proof;
37
+ const written = PROOF_IN_TEXT.exec(entry.text)?.[1]?.toLowerCase();
38
+ return PROOF_KINDS.includes(written) ? written : null;
62
39
  }
63
40
 
64
- /** The id-bearing shape: an `## Acceptance criteria` section whose every item starts with a backticked id. */
65
- function readIdSection(lines) {
66
- const at = lines.findIndex((l) => {
67
- const h = HEADING.exec(l);
68
- return h !== null && h[1].length === 2 && /^acceptance criteria$/i.test(h[2]);
69
- });
70
- if (at === -1) return null;
71
- const items = [];
72
- for (let i = at + 1; i < lines.length; i++) {
73
- const h = HEADING.exec(lines[i]);
74
- if (h !== null && h[1].length <= 2) break;
75
- const bullet = BULLET.exec(lines[i]);
76
- if (bullet) items.push(bullet[1].trim());
77
- else if (/^\s+\S/.test(lines[i]) && items.length > 0) items[items.length - 1] += ` ${lines[i].trim()}`;
78
- }
79
- if (items.length === 0) return null;
80
- const parsed = items.map((item) => ID_ITEM.exec(item));
81
- const withId = parsed.filter((m) => m !== null && m[2].trim() !== "").length;
82
- if (withId === 0) return null;
83
- if (withId < parsed.length) return { mixed: true };
84
- return {
85
- criteria: parsed.map((m) => {
86
- const kind = /\(proof:\s*([a-z]+)\s*\)/i.exec(m[2])?.[1]?.toLowerCase();
87
- return { id: m[1], text: m[2].trim(), proof: PROOF_KINDS.includes(kind) ? kind : null };
88
- }),
89
- };
90
- }
91
-
92
- /** The plain shape: an Acceptance / Acceptance criteria / Done when label, then a bullet list. */
93
- function readLabelledBullets(lines) {
94
- for (let i = 0; i < lines.length; i++) {
95
- if (!LABEL.test(lines[i])) continue;
96
- let start = i + 1;
97
- while (start < lines.length && lines[start].trim() === "") start++;
98
- const items = collectItems(lines, start).map(stripCheckbox).filter((t) => t !== "");
99
- if (items.length > 0) return items;
100
- }
41
+ /** Why the written ids cannot be kept, or `null` when they can. */
42
+ function idProblem(entries) {
43
+ const ids = entries.map((entry) => entry.id);
44
+ const missing = ids.filter((id) => typeof id !== "string" || id.trim() === "").length;
45
+ if (missing === ids.length) return "no criterion carried an id";
46
+ if (missing > 0) return "only some criteria carried an id";
47
+ const bad = ids.find((id) => !CRITERION_ID.test(id));
48
+ if (bad !== undefined) return `the id ${JSON.stringify(bad)} does not fit the id grammar`;
49
+ const reserved = ids.find((id) => RESERVED_IDS.includes(id));
50
+ if (reserved !== undefined) return `the id ${JSON.stringify(reserved)} names a check, not a criterion`;
51
+ const repeated = ids.find((id, n) => ids.indexOf(id) !== n);
52
+ if (repeated !== undefined) return `the id ${JSON.stringify(repeated)} appears twice`;
101
53
  return null;
102
54
  }
103
55
 
104
56
  /**
105
- * Finds the criteria in an issue body.
106
- * @returns {{shape: "ids"|"bullets"|"none", criteria: Array<{id:string,text:string,proof:string|null}>, note?: string}}
57
+ * Turns the agent's criteria file into the list `outerlayer emit criteria`
58
+ * takes. Throws {@link CriteriaFileError} for a file the agent must fix.
59
+ * @returns {{criteria: Array<{id:string,text:string,proof:string|null}>, numbered: boolean, numberedBecause?: string}}
107
60
  */
108
- export function parseCriteria(body, item) {
109
- const lines = blankFencedLines(String(body).split(/\r?\n/));
110
- const ids = readIdSection(lines);
111
- if (ids?.criteria) return { shape: "ids", criteria: ids.criteria };
112
- const bullets = readLabelledBullets(lines);
113
- if (ids?.mixed && bullets) {
114
- return {
115
- shape: "none",
116
- criteria: [],
117
- note: "some criteria carry an id and some do not; recording nothing rather than renumbering the written ids",
118
- };
61
+ export function readCriteria(input, item, { drafted = false } = {}) {
62
+ if (typeof input !== "object" || input === null || !Array.isArray(input.criteria)) {
63
+ throw new CriteriaFileError('the criteria file must be { "criteria": [ ... ] }');
119
64
  }
120
- if (bullets) {
121
- return {
122
- shape: "bullets",
123
- criteria: bullets.map((text, n) => ({ id: `AC-${item}-${String(n + 1).padStart(2, "0")}`, text, proof: null })),
124
- };
125
- }
126
- return { shape: "none", criteria: [] };
65
+ const entries = input.criteria.map((entry, n) => {
66
+ if (typeof entry !== "object" || entry === null || typeof entry.text !== "string" || entry.text.trim() === "") {
67
+ throw new CriteriaFileError(`criteria[${n}] needs the criterion's text`);
68
+ }
69
+ return { id: entry.id, text: entry.text.trim(), proof: entry.proof };
70
+ });
71
+ const problem = drafted ? "the build drafted them" : idProblem(entries);
72
+ const numbered = entries.length > 0 && problem !== null;
73
+ const criteria = entries.map((entry, n) => ({
74
+ id: numbered ? `AC-${item}-${String(n + 1).padStart(2, "0")}` : entry.id,
75
+ text: entry.text,
76
+ proof: proofOf(entry),
77
+ }));
78
+ return numbered ? { criteria, numbered, numberedBecause: problem } : { criteria, numbered };
127
79
  }
128
80
 
129
- /** Sorts a failed `emit criteria` into "the item already has a person's list" and any other refusal. */
81
+ /** Sorts a failed `emit criteria` into "the item already has a list" and any other refusal. */
130
82
  export function classifyEmitFailure(message) {
131
83
  // Only the CLI's replace refusal reads "refused (409):". Other answers that
132
84
  // carry a 409, such as a lost race, read "emit failed (409):".
@@ -153,40 +105,39 @@ function readState(path) {
153
105
  }
154
106
 
155
107
  /**
156
- * Records the issue's criteria and notes the outcome in the state file.
157
- * `emit(file)` runs `outerlayer emit criteria <file>` and returns
158
- * `{ ok: true }` or `{ ok: false, message }`.
108
+ * Records the criteria and notes the outcome in the state file. `input` is
109
+ * the parsed criteria file. `emit(file)` runs `outerlayer emit criteria
110
+ * <file>` and returns `{ ok: true }` or `{ ok: false, message }`.
159
111
  */
160
- export async function recordCriteria({ body, item, reportsDir, statePath, emit }) {
161
- const found = parseCriteria(body, item);
112
+ export async function recordCriteria({ input, item, drafted = false, reportsDir, statePath, emit }) {
113
+ const read = readCriteria(input, item, { drafted });
114
+ const numbering = read.numbered ? { numbered: true, numberedBecause: read.numberedBecause } : { numbered: false };
162
115
  let outcome;
163
- if (found.shape === "none") {
164
- outcome = { source: "none", recorded: false, count: 0, list: [], ...(found.note ? { note: found.note } : {}) };
116
+ if (read.criteria.length === 0) {
117
+ outcome = { source: "none", recorded: false, count: 0, list: [] };
165
118
  } else {
166
119
  mkdirSync(reportsDir, { recursive: true });
167
120
  const file = join(reportsDir, "criteria.json");
168
- writeFileSync(file, `${JSON.stringify({ criteria: found.criteria }, null, 2)}\n`);
121
+ const list = drafted ? { criteria: read.criteria, drafted: true } : { criteria: read.criteria };
122
+ writeFileSync(file, `${JSON.stringify(list, null, 2)}\n`);
169
123
  const result = await emit(file);
170
- const base = { count: found.criteria.length, list: found.criteria };
124
+ const source = drafted ? "drafted" : "issue";
125
+ const base = { count: read.criteria.length, list: read.criteria, ...numbering };
171
126
  if (result.ok) {
172
- outcome = { source: found.shape === "ids" ? "issue-ids" : "issue-bullets", recorded: true, ...base };
127
+ outcome = { source, recorded: true, ...base };
173
128
  } else if (classifyEmitFailure(result.message) === "item-list-stands") {
174
- // No command returns the item's own list, so `list` stays empty; the issue's reading goes under `issueReading`.
129
+ // No command returns the item's own list, so `list` stays empty; the build's reading goes under `issueReading`.
175
130
  outcome = {
176
131
  source: "item",
177
132
  recorded: false,
178
- count: found.criteria.length,
133
+ count: read.criteria.length,
179
134
  list: [],
180
- issueReading: found.criteria,
135
+ issueReading: read.criteria,
136
+ ...numbering,
181
137
  note: "the item already has a recorded list; it stands",
182
138
  };
183
139
  } else {
184
- outcome = {
185
- source: found.shape === "ids" ? "issue-ids" : "issue-bullets",
186
- recorded: false,
187
- ...base,
188
- refusal: result.message,
189
- };
140
+ outcome = { source, recorded: false, ...base, refusal: result.message };
190
141
  }
191
142
  }
192
143
  mkdirSync(dirname(statePath), { recursive: true });
@@ -197,12 +148,13 @@ export async function recordCriteria({ body, item, reportsDir, statePath, emit }
197
148
  export function summarize(outcome) {
198
149
  const n = outcome.count;
199
150
  const noun = n === 1 ? "criterion" : "criteria";
200
- if (outcome.source === "none") return `no acceptance criteria found; none recorded${outcome.note ? ` (${outcome.note})` : ""}`;
201
- if (outcome.source === "item") return `the item already has a recorded list; it stands, and the ${n} ${noun} read from the issue were not recorded`;
202
- const shape = outcome.source === "issue-ids" ? "an Acceptance criteria section with ids" : "bullets under an Acceptance heading";
151
+ const ids = outcome.numbered ? `, numbered AC-<item>-NN because ${outcome.numberedBecause}` : ", with the issue's own ids";
152
+ if (outcome.source === "none") return "no criteria in the file; none recorded";
153
+ if (outcome.source === "item") return `the item already has a recorded list; it stands, and the ${n} ${noun} read here were not recorded`;
154
+ const what = outcome.source === "drafted" ? `drafted ${n} ${noun} from the issue's description` : `read ${n} ${noun} from the issue`;
203
155
  return outcome.recorded
204
- ? `recorded ${n} ${noun} from ${shape}`
205
- : `read ${n} ${noun} from ${shape} but the record was refused: ${outcome.refusal}`;
156
+ ? `${what} and recorded them${outcome.source === "drafted" ? " as drafted" : ids}`
157
+ : `${what} but the record was refused: ${outcome.refusal}`;
206
158
  }
207
159
 
208
160
  async function main(argv) {
@@ -211,9 +163,16 @@ async function main(argv) {
211
163
  return at === -1 ? undefined : argv[at + 1];
212
164
  };
213
165
  const item = arg("--item");
214
- const issueFile = arg("--issue-file");
215
- if (!item || !/^\d+$/.test(item) || !issueFile) {
216
- process.stderr.write("usage: record-criteria.mjs --item <number> --issue-file <path>\n");
166
+ const criteriaFile = arg("--criteria-file");
167
+ if (!item || !/^\d+$/.test(item) || !criteriaFile) {
168
+ process.stderr.write("usage: record-criteria.mjs --item <number> --criteria-file <path> [--drafted]\n");
169
+ return 2;
170
+ }
171
+ let input;
172
+ try {
173
+ input = JSON.parse(readFileSync(criteriaFile, "utf8"));
174
+ } catch (err) {
175
+ process.stderr.write(`cannot read the criteria file "${criteriaFile}": ${err.message}\n`);
217
176
  return 2;
218
177
  }
219
178
  const git = spawnSync("git", ["rev-parse", "--absolute-git-dir"], { encoding: "utf8" });
@@ -222,15 +181,22 @@ async function main(argv) {
222
181
  return 2;
223
182
  }
224
183
  const gitDir = git.stdout.trim();
225
- const outcome = await recordCriteria({
226
- body: readFileSync(issueFile, "utf8"),
227
- item,
228
- reportsDir: join(gitDir, "build-reports"),
229
- statePath: join(gitDir, "build-state.json"),
230
- emit: makeEmit(spawnSync, item),
231
- });
232
- process.stdout.write(`${summarize(outcome)}\n`);
233
- return 0;
184
+ try {
185
+ const outcome = await recordCriteria({
186
+ input,
187
+ item,
188
+ drafted: argv.includes("--drafted"),
189
+ reportsDir: join(gitDir, "build-reports"),
190
+ statePath: join(gitDir, "build-state.json"),
191
+ emit: makeEmit(spawnSync, item),
192
+ });
193
+ process.stdout.write(`${summarize(outcome)}\n`);
194
+ return 0;
195
+ } catch (err) {
196
+ if (!(err instanceof CriteriaFileError)) throw err;
197
+ process.stderr.write(`${err.message}; fix the criteria file and run again\n`);
198
+ return 2;
199
+ }
234
200
  }
235
201
 
236
202
  if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) process.exitCode = await main(process.argv.slice(2));
@@ -5,8 +5,10 @@
5
5
  # clean bill) as an .html file. Emit it as a report artifact with no --for:
6
6
  # outerlayer emit artifact review.html --caption "Review of the change and what it found"
7
7
  # Then run `outerlayer sync`, and copy the report's deep link from the pull
8
- # request's evidence comment. Never build the link by hand, and never link a
9
- # pull request comment: a comment can be edited or deleted later.
8
+ # request's evidence comment. The link can take up to a minute to appear
9
+ # after the sync. If it is not there yet, wait a minute and read the comment
10
+ # again; do not give up after one look. Never build the link by hand, and
11
+ # never link a pull request comment: a comment can be edited or deleted later.
10
12
  #
11
13
  # Then record the verdict once, with that link as its proof:
12
14
  # outerlayer emit code-review --item "$OUTERLAYER_WORK" --result pass --link <the report's deep link>
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire } from 'node:module';
3
- import { RUNNER_DIR_MODE, RUNNER_FILE_MODE } from './chunk-ZM2IMMYN.js';
4
- import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs';
5
- import { dirname } from 'path';
6
-
7
- createRequire(import.meta.url);
8
- function readJobFile(path) {
9
- if (!existsSync(path)) return null;
10
- try {
11
- return JSON.parse(readFileSync(path, "utf8"));
12
- } catch {
13
- return null;
14
- }
15
- }
16
- function readJobFileChecked(path) {
17
- if (!existsSync(path)) return { kind: "missing" };
18
- try {
19
- const parsed = JSON.parse(readFileSync(path, "utf8"));
20
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return { kind: "unreadable" };
21
- return { kind: "ok", job: parsed };
22
- } catch {
23
- return { kind: "unreadable" };
24
- }
25
- }
26
- function writeJobFile(path, job) {
27
- mkdirSync(dirname(path), { recursive: true, mode: RUNNER_DIR_MODE });
28
- writeFileSync(path, JSON.stringify(job, null, 2), { mode: RUNNER_FILE_MODE });
29
- }
30
-
31
- export { readJobFile, readJobFileChecked, writeJobFile };