@mnaimfaizy/agent-kit 1.0.0-beta.1 → 1.0.0-beta.10
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.
- package/README.md +8 -3
- package/package.json +1 -1
- package/src/callers.mjs +35 -10
- package/src/checks/kit-owned-trees.mjs +45 -2
- package/src/checks/review-response.mjs +205 -0
- package/src/checks/rulesets.mjs +7 -2
- package/src/checks/scan-recipe.mjs +56 -0
- package/src/checks/secrets-and-variables.mjs +65 -15
- package/src/cli.mjs +163 -8
- package/src/deep-scan/agent.mjs +410 -0
- package/src/deep-scan/claude-code.mjs +25 -0
- package/src/deep-scan/credential.mjs +215 -0
- package/src/deep-scan/docker-driver.mjs +696 -0
- package/src/deep-scan/egress.mjs +150 -0
- package/src/deep-scan/lifecycle.mjs +703 -0
- package/src/deep-scan/limits.mjs +126 -0
- package/src/deep-scan/model-proxy.mjs +378 -0
- package/src/deep-scan/preflight.mjs +78 -0
- package/src/deep-scan/recipe.mjs +447 -0
- package/src/deep-scan/relay-script.mjs +98 -0
- package/src/deep-scan/relay.mjs +130 -0
- package/src/deep-scan/runtime.mjs +181 -0
- package/src/deep-scan/sbx-driver.mjs +501 -0
- package/src/deep-scan/steps.mjs +47 -0
- package/src/deep-scan/tar.mjs +84 -0
- package/src/deep-scan/verify.mjs +272 -0
- package/src/deep-scan.mjs +474 -0
- package/src/doctor.mjs +14 -10
- package/src/exec.mjs +222 -33
- package/src/init.mjs +35 -9
- package/src/kit-owned-paths.mjs +5 -3
- package/src/kit-tag.mjs +12 -3
- package/src/local-tree.mjs +69 -4
- package/src/local-writes.mjs +4 -33
- package/src/templates.mjs +12 -8
- package/src/workflow-call.mjs +3 -5
- package/src/yaml-subset.mjs +134 -24
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// What a sandbox lifecycle step can end with, shared by the lifecycle and
|
|
2
|
+
// its drivers: a failed step (the run ends before the agent step, with what
|
|
3
|
+
// to show), or an interrupt (SIGINT or SIGTERM).
|
|
4
|
+
|
|
5
|
+
import { firstLine } from "../exec.mjs";
|
|
6
|
+
|
|
7
|
+
export class StepFailed extends Error {
|
|
8
|
+
/** @param {string[]} lines */
|
|
9
|
+
constructor(lines) {
|
|
10
|
+
super(lines[0]);
|
|
11
|
+
this.lines = lines;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class Interrupted extends Error {
|
|
16
|
+
/** @param {string} signal */
|
|
17
|
+
constructor(signal) {
|
|
18
|
+
super(`interrupted by ${signal}`);
|
|
19
|
+
this.signal = signal;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const ENDS_HERE = "The run ends here, before the agent step.";
|
|
24
|
+
|
|
25
|
+
/** The step failure for a command that did not succeed. */
|
|
26
|
+
export function failed(what, r, { showOutput = false, extra = [] } = {}) {
|
|
27
|
+
return new StepFailed([
|
|
28
|
+
`FAILED ${what}: ${firstLine(r.stderr) || `exit ${r.status}`}`,
|
|
29
|
+
...(showOutput ? outputLines(r) : []),
|
|
30
|
+
...extra,
|
|
31
|
+
ENDS_HERE,
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** `r` unchanged when it succeeded, else its step failure, thrown. */
|
|
36
|
+
export function must(r, what, opts) {
|
|
37
|
+
if (r.status === 0) return r;
|
|
38
|
+
throw failed(what, r, opts);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A command's output, indented, for a failure message. */
|
|
42
|
+
export function outputLines(r) {
|
|
43
|
+
const text = `${r.stdout.toString("utf8")}${r.stderr}`.trimEnd();
|
|
44
|
+
return text ? ["Output:", ...indent(text)] : ["(no output)"];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const indent = (text) => text.split(/\r\n|\r|\n/).map((l) => ` ${l}`);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The tar streams the Deep scan launcher moves across the sandbox boundary,
|
|
2
|
+
// in Node core (ADR 0001). In: a ustar archive of files the launcher wrote
|
|
3
|
+
// itself (the grounding it fetched). Out: the one report file, read from the
|
|
4
|
+
// archive `tar -c` writes from the sandbox through `docker exec`, refusing anything that is
|
|
5
|
+
// not exactly one regular file.
|
|
6
|
+
|
|
7
|
+
const BLOCK = 512;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A ustar archive of `entries`, each a folder (`dir: true`) or a file with
|
|
11
|
+
* its bytes. Paths are relative, use `/`, and fit in 100 bytes.
|
|
12
|
+
* @param {Array<{ path: string, dir?: boolean, data?: Buffer }>} entries
|
|
13
|
+
* @returns {Buffer}
|
|
14
|
+
*/
|
|
15
|
+
export function tarOf(entries) {
|
|
16
|
+
const parts = [];
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const name = entry.dir ? `${entry.path.replace(/\/$/, "")}/` : entry.path;
|
|
19
|
+
if (Buffer.byteLength(name) > 100 || name.startsWith("/") || name.split("/").includes("..")) {
|
|
20
|
+
throw new Error(`tar entry name not allowed: ${JSON.stringify(name)}`);
|
|
21
|
+
}
|
|
22
|
+
const data = entry.dir ? Buffer.alloc(0) : (entry.data ?? Buffer.alloc(0));
|
|
23
|
+
const header = Buffer.alloc(BLOCK);
|
|
24
|
+
header.write(name, 0, 100, "utf8");
|
|
25
|
+
header.write(octal(entry.dir ? 0o755 : 0o644, 8), 100, "ascii");
|
|
26
|
+
header.write(octal(0, 8), 108, "ascii");
|
|
27
|
+
header.write(octal(0, 8), 116, "ascii");
|
|
28
|
+
header.write(octal(data.length, 12), 124, "ascii");
|
|
29
|
+
header.write(octal(0, 12), 136, "ascii");
|
|
30
|
+
header.write(" ", 148, "ascii");
|
|
31
|
+
header.write(entry.dir ? "5" : "0", 156, "ascii");
|
|
32
|
+
header.write("ustar\u000000", 257, "binary");
|
|
33
|
+
let sum = 0;
|
|
34
|
+
for (const byte of header) sum += byte;
|
|
35
|
+
header.write(`${sum.toString(8).padStart(6, "0")}\u0000 `, 148, "binary");
|
|
36
|
+
parts.push(header, data, Buffer.alloc(padding(data.length)));
|
|
37
|
+
}
|
|
38
|
+
parts.push(Buffer.alloc(BLOCK * 2));
|
|
39
|
+
return Buffer.concat(parts);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The one regular file in a tar archive, or why there is not exactly one.
|
|
44
|
+
* PAX extended headers are skipped; a folder, a link or a second file is
|
|
45
|
+
* refused, as is a file larger than `maxBytes`.
|
|
46
|
+
* @param {Buffer} archive
|
|
47
|
+
* @param {{ maxBytes: number }} opts
|
|
48
|
+
* @returns {{ name: string, data: Buffer } | { error: string }}
|
|
49
|
+
*/
|
|
50
|
+
export function singleFileOf(archive, { maxBytes }) {
|
|
51
|
+
const files = [];
|
|
52
|
+
let offset = 0;
|
|
53
|
+
while (offset + BLOCK <= archive.length) {
|
|
54
|
+
const header = archive.subarray(offset, offset + BLOCK);
|
|
55
|
+
if (header.every((b) => b === 0)) break;
|
|
56
|
+
const name = text(header, 0, 100);
|
|
57
|
+
const size = parseInt(text(header, 124, 12).trim() || "0", 8);
|
|
58
|
+
const type = text(header, 156, 1) || "0";
|
|
59
|
+
if (!Number.isFinite(size) || size < 0) return { error: "the archive is not a tar archive" };
|
|
60
|
+
offset += BLOCK;
|
|
61
|
+
if (type === "x" || type === "g") {
|
|
62
|
+
offset += size + padding(size);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (type !== "0") {
|
|
66
|
+
return { error: `${name || "the entry"} is not a regular file (tar type ${type})` };
|
|
67
|
+
}
|
|
68
|
+
if (size > maxBytes) return { error: `it is larger than ${maxBytes / 1024 / 1024} MiB` };
|
|
69
|
+
if (offset + size > archive.length) return { error: "the archive is cut short" };
|
|
70
|
+
files.push({ name, data: Buffer.from(archive.subarray(offset, offset + size)) });
|
|
71
|
+
offset += size + padding(size);
|
|
72
|
+
}
|
|
73
|
+
if (files.length === 0) return { error: "the archive holds no file" };
|
|
74
|
+
if (files.length > 1) return { error: `the archive holds ${files.length} files, not one` };
|
|
75
|
+
return files[0];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const octal = (n, width) => `${n.toString(8).padStart(width - 1, "0")}\u0000`;
|
|
79
|
+
const padding = (size) => (BLOCK - (size % BLOCK)) % BLOCK;
|
|
80
|
+
const text = (buf, start, length) => {
|
|
81
|
+
const field = buf.subarray(start, start + length);
|
|
82
|
+
const end = field.indexOf(0);
|
|
83
|
+
return field.subarray(0, end === -1 ? length : end).toString("utf8");
|
|
84
|
+
};
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// The Verification run (#372): `deep-scan --verify <file> --ref <ref>`
|
|
2
|
+
// re-attempts the Reproduction of known findings on a ref the maintainer
|
|
3
|
+
// chose, to check whether a fix holds. It is local only (refused in CI, where
|
|
4
|
+
// a concept id under response would enter a log), and confirm-only: the
|
|
5
|
+
// agent is handed the Verification-run procedure from DEEP.md, not the full
|
|
6
|
+
// deep procedure, and the finding file. The report stays on the machine.
|
|
7
|
+
//
|
|
8
|
+
// This module reads and checks the finding file on the host, cuts the
|
|
9
|
+
// Verification-run procedure out of DEEP.md, writes the agent's brief, and
|
|
10
|
+
// checks the report that comes out against the findings given.
|
|
11
|
+
|
|
12
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
13
|
+
import { CLI_VERSION } from "../tags.mjs";
|
|
14
|
+
import { stripBom } from "../yaml-subset.mjs";
|
|
15
|
+
import {
|
|
16
|
+
DISCOVERED,
|
|
17
|
+
fence,
|
|
18
|
+
groundingLines,
|
|
19
|
+
SETUP_DONE,
|
|
20
|
+
SKILL_DIR,
|
|
21
|
+
threatPackAndRecipe,
|
|
22
|
+
} from "./agent.mjs";
|
|
23
|
+
|
|
24
|
+
export const VERIFY_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CLI_VERSION}/docs/security-audit.md#verification-run`;
|
|
25
|
+
|
|
26
|
+
/** Where the finding file goes in the sandbox, beside the brief. */
|
|
27
|
+
export const FINDINGS_PATH = "/agent-kit/in/findings.md";
|
|
28
|
+
|
|
29
|
+
export const MAX_FINDING_FILE_BYTES = 512 * 1024;
|
|
30
|
+
|
|
31
|
+
/** A concept id as report-format.md gives it: kebab-case. */
|
|
32
|
+
const CONCEPT_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
33
|
+
|
|
34
|
+
/** A ref as `--ref` takes it: no option, no space, no control character. */
|
|
35
|
+
export const REF_NAME = /^[^\s\x00-\x1f\x7f-][^\s\x00-\x1f\x7f]*$/;
|
|
36
|
+
|
|
37
|
+
const FIELD = /^[ \t]*[-*][ \t]+\*\*([A-Za-z ]+):\*\*[ \t]*(.*)$/;
|
|
38
|
+
const FENCE = /^[ \t]*(`{3,}|~{3,})/;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Markdown's `###` sections, outside code fences, each with its fields
|
|
42
|
+
* (`- **Name:** value`), keyed by name.
|
|
43
|
+
* @returns {Array<{ heading: string, fields: Record<string, string> }>}
|
|
44
|
+
*/
|
|
45
|
+
function sections(text) {
|
|
46
|
+
const out = [];
|
|
47
|
+
let open = null;
|
|
48
|
+
for (const line of text.split(/\r?\n/)) {
|
|
49
|
+
const f = FENCE.exec(line);
|
|
50
|
+
if (open !== null) {
|
|
51
|
+
if (f && f[1][0] === open[0] && f[1].length >= open.length) open = null;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (f) {
|
|
55
|
+
open = f[1];
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const h = /^(#{1,3})[ \t]+(.*)$/.exec(line);
|
|
59
|
+
if (h) {
|
|
60
|
+
out.push({ heading: h[2].trim(), fields: {}, level: h[1].length });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const m = FIELD.exec(line);
|
|
64
|
+
const current = out.at(-1);
|
|
65
|
+
if (m && current && current.level === 3 && !(m[1] in current.fields)) {
|
|
66
|
+
current.fields[m[1]] = m[2].trim();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return out.filter((s) => s.level === 3);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A field's value without the backticks around it: its first `code span`, if any. */
|
|
73
|
+
const unquote = (value) => /`([^`]*)`/.exec(value)?.[1].trim() ?? value.trim();
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Read and check the finding file on the host, before anything runs.
|
|
77
|
+
* @param {string} file an absolute path
|
|
78
|
+
* @returns {{ findings: Finding[], data: Buffer } | { refused: string[] }}
|
|
79
|
+
*
|
|
80
|
+
* @typedef {{ conceptId: string, location: string }} Finding
|
|
81
|
+
*/
|
|
82
|
+
export function readFindingFile(file) {
|
|
83
|
+
const cannot = (why) => ({ refused: [`Cannot read the finding file ${file}: ${why}.`] });
|
|
84
|
+
if (!existsSync(file)) return cannot("it does not exist");
|
|
85
|
+
let data;
|
|
86
|
+
try {
|
|
87
|
+
const st = statSync(file);
|
|
88
|
+
if (!st.isFile()) return cannot("it is not a regular file");
|
|
89
|
+
if (st.size > MAX_FINDING_FILE_BYTES) {
|
|
90
|
+
return cannot(`it is larger than ${MAX_FINDING_FILE_BYTES / 1024} KiB`);
|
|
91
|
+
}
|
|
92
|
+
data = readFileSync(file);
|
|
93
|
+
// It may have grown since the stat: what goes in is what was checked.
|
|
94
|
+
if (data.length > MAX_FINDING_FILE_BYTES) {
|
|
95
|
+
return cannot(`it is larger than ${MAX_FINDING_FILE_BYTES / 1024} KiB`);
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
return cannot(e?.code ?? e?.message ?? String(e));
|
|
99
|
+
}
|
|
100
|
+
let text;
|
|
101
|
+
try {
|
|
102
|
+
text = stripBom(new TextDecoder("utf-8", { fatal: true }).decode(data));
|
|
103
|
+
} catch {
|
|
104
|
+
text = null;
|
|
105
|
+
}
|
|
106
|
+
if (text === null || text.includes("\0")) return cannot("it is not text (UTF-8 Markdown)");
|
|
107
|
+
|
|
108
|
+
const problems = [];
|
|
109
|
+
const findings = [];
|
|
110
|
+
const seen = new Set();
|
|
111
|
+
for (const { heading, fields } of sections(text)) {
|
|
112
|
+
if (!("Concept id" in fields)) continue;
|
|
113
|
+
const conceptId = unquote(fields["Concept id"]);
|
|
114
|
+
if (!CONCEPT_ID.test(conceptId)) {
|
|
115
|
+
problems.push(
|
|
116
|
+
`${heading}: its concept id ${JSON.stringify(conceptId)} is not kebab-case (lowercase letters and digits, joined by -).`,
|
|
117
|
+
);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const name = `\`${conceptId}\` (${heading})`;
|
|
121
|
+
for (const field of ["Location", "Observation"]) {
|
|
122
|
+
if (!fields[field]) problems.push(`${name} has no ${field}.`);
|
|
123
|
+
}
|
|
124
|
+
if (seen.has(conceptId)) problems.push(`\`${conceptId}\` is given more than once.`);
|
|
125
|
+
seen.add(conceptId);
|
|
126
|
+
findings.push({ conceptId, location: fields.Location ?? "" });
|
|
127
|
+
}
|
|
128
|
+
if (!findings.length && !problems.length) {
|
|
129
|
+
return {
|
|
130
|
+
refused: [
|
|
131
|
+
`The finding file ${file} has no findings. A Verification run needs at least one \`###\` finding with a **Concept id**, a **Location** and an **Observation**, as a deep report gives them.`,
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (problems.length) {
|
|
136
|
+
return {
|
|
137
|
+
refused: [
|
|
138
|
+
`The finding file ${file} is not in the expected shape:`,
|
|
139
|
+
...problems.map((p) => ` - ${p}`),
|
|
140
|
+
"Each finding is a `###` section with `- **Concept id:**`, `- **Location:**` and `- **Observation:**` lines, as a deep report gives them.",
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return { findings, data };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The Verification-run procedure, cut from DEEP.md: its hard rules, the
|
|
149
|
+
* procedure steps the Verification run section keeps (1, 2 and 6), and that
|
|
150
|
+
* section. Null for each part DEEP.md lacks, named in `missing`.
|
|
151
|
+
* @returns {{ procedure: string } | { missing: string[] }}
|
|
152
|
+
*/
|
|
153
|
+
export function verificationProcedure(deepMd) {
|
|
154
|
+
const parts = new Map();
|
|
155
|
+
for (const chunk of lfOf(deepMd).split(/^(?=## )/m)) {
|
|
156
|
+
const title = /^## (.+)$/m.exec(chunk)?.[1].trim();
|
|
157
|
+
if (title) parts.set(title, chunk.replace(/\n+$/, "\n"));
|
|
158
|
+
}
|
|
159
|
+
const missing = ["Hard rules", "Procedure", "Verification run"].filter((t) => !parts.has(t));
|
|
160
|
+
if (missing.length) return { missing };
|
|
161
|
+
const items = [];
|
|
162
|
+
for (const line of parts.get("Procedure").split("\n").slice(1)) {
|
|
163
|
+
const n = /^(\d+)\.[ \t]/.exec(line);
|
|
164
|
+
if (n) items.push({ n: Number(n[1]), lines: [line] });
|
|
165
|
+
else if (items.length) items.at(-1).lines.push(line);
|
|
166
|
+
}
|
|
167
|
+
const kept = items.filter((i) => [1, 2, 6].includes(i.n));
|
|
168
|
+
if (kept.length !== 3) return { missing: ["Procedure steps 1, 2 and 6"] };
|
|
169
|
+
const steps = kept.map((i) => i.lines.join("\n").replace(/\n+$/, "")).join("\n");
|
|
170
|
+
return {
|
|
171
|
+
procedure: [
|
|
172
|
+
parts.get("Hard rules").trimEnd(),
|
|
173
|
+
"",
|
|
174
|
+
"## Procedure (the steps a Verification run keeps)",
|
|
175
|
+
"",
|
|
176
|
+
steps,
|
|
177
|
+
"",
|
|
178
|
+
parts.get("Verification run").trimEnd(),
|
|
179
|
+
"",
|
|
180
|
+
].join("\n"),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const lfOf = (text) => text.replace(/\r\n?/g, "\n");
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The brief for a Verification run: confirm-only, on the ref the maintainer
|
|
188
|
+
* named, with the finding file.
|
|
189
|
+
* @param {{
|
|
190
|
+
* ref: string,
|
|
191
|
+
* short: string,
|
|
192
|
+
* findings: Finding[],
|
|
193
|
+
* procedure: string,
|
|
194
|
+
* recipePath: string,
|
|
195
|
+
* recipeText: string,
|
|
196
|
+
* handIn: import("./agent.mjs").HandIn,
|
|
197
|
+
* grounding: Array<{ source: string, at: string }>,
|
|
198
|
+
* paths: { workspace: string, grounding: string, report: string },
|
|
199
|
+
* discovers?: boolean,
|
|
200
|
+
* }} opts `discovers`: Claude Code runs without `--bare` (the
|
|
201
|
+
* subscription path), so the brief says what it discovers.
|
|
202
|
+
*/
|
|
203
|
+
export function verificationBrief({
|
|
204
|
+
ref,
|
|
205
|
+
short,
|
|
206
|
+
findings,
|
|
207
|
+
procedure,
|
|
208
|
+
recipePath,
|
|
209
|
+
recipeText,
|
|
210
|
+
handIn,
|
|
211
|
+
grounding,
|
|
212
|
+
paths,
|
|
213
|
+
discovers = false,
|
|
214
|
+
}) {
|
|
215
|
+
return [
|
|
216
|
+
"# Verification run brief, from the agent-kit deep-scan launcher",
|
|
217
|
+
"",
|
|
218
|
+
"This is the launcher's brief. You are running inside the closed, disposable sandbox that `agent-kit deep-scan --verify` started for a Verification run: re-attempt the Reproduction of each finding in the finding file, by the Verification-run procedure below, and nothing more. Your only network route is the launcher's model proxy, and the web tools (WebFetch, WebSearch) are off.",
|
|
219
|
+
"",
|
|
220
|
+
"## Where things are",
|
|
221
|
+
"",
|
|
222
|
+
`- The repository: \`${paths.workspace}\`, an export of \`${ref}\` at ${short}, the ref the maintainer chose to verify (name it as the report's Scope).`,
|
|
223
|
+
`- The finding file: \`${FINDINGS_PATH}\`. Its findings, in the order to report them:`,
|
|
224
|
+
...findings.map((f) => ` - \`${f.conceptId}\` at ${f.location}`),
|
|
225
|
+
...groundingLines(grounding, paths),
|
|
226
|
+
`- The report: write it to \`${paths.report}\`, in the Verification-run variant of the report format below, early, and update it as each answer lands. It is the only file that leaves the sandbox.`,
|
|
227
|
+
SETUP_DONE,
|
|
228
|
+
...(discovers ? [DISCOVERED] : []),
|
|
229
|
+
"",
|
|
230
|
+
`## The Verification-run procedure, from ${SKILL_DIR}/DEEP.md`,
|
|
231
|
+
"",
|
|
232
|
+
`Read every link in it as relative to \`${paths.workspace}/${SKILL_DIR}/\`.`,
|
|
233
|
+
"",
|
|
234
|
+
...fence(procedure),
|
|
235
|
+
"",
|
|
236
|
+
`## ${SKILL_DIR}/report-format.md`,
|
|
237
|
+
"",
|
|
238
|
+
"Use its Verification-run variant.",
|
|
239
|
+
"",
|
|
240
|
+
...fence(handIn.skill["report-format.md"]),
|
|
241
|
+
"",
|
|
242
|
+
...threatPackAndRecipe({ handIn, recipePath, recipeText }),
|
|
243
|
+
].join("\n");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Check a Verification run's report against the findings given: the
|
|
248
|
+
* variant's Mode line, and a `Reproduced: yes | no` entry for each.
|
|
249
|
+
* @param {string} text
|
|
250
|
+
* @param {Finding[]} findings
|
|
251
|
+
* @returns {{ answers: Array<{ conceptId: string, reproduced: string }>, problems: string[] }}
|
|
252
|
+
*/
|
|
253
|
+
export function checkVerificationReport(text, findings) {
|
|
254
|
+
const problems = [];
|
|
255
|
+
if (!/^[ \t]*[-*][ \t]+\*\*Mode:\*\*[ \t]*deep \(Verification run\)[ \t]*$/m.test(text)) {
|
|
256
|
+
problems.push("it has no `- **Mode:** deep (Verification run)` line");
|
|
257
|
+
}
|
|
258
|
+
const entries = new Map();
|
|
259
|
+
for (const { heading, fields } of sections(text)) {
|
|
260
|
+
const id = unquote(heading);
|
|
261
|
+
if (!entries.has(id)) entries.set(id, fields);
|
|
262
|
+
}
|
|
263
|
+
const answers = [];
|
|
264
|
+
for (const { conceptId } of findings) {
|
|
265
|
+
const fields = entries.get(conceptId);
|
|
266
|
+
const reproduced = /^(yes|no)\b/.exec(fields?.Reproduced ?? "")?.[1];
|
|
267
|
+
if (!fields) problems.push(`it has no entry for \`${conceptId}\``);
|
|
268
|
+
else if (!reproduced) problems.push(`\`${conceptId}\`'s entry has no Reproduced: yes or no`);
|
|
269
|
+
else answers.push({ conceptId, reproduced });
|
|
270
|
+
}
|
|
271
|
+
return { answers, problems };
|
|
272
|
+
}
|