@mnaimfaizy/agent-kit 1.0.0-beta.14 → 1.0.0-beta.16
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 +22 -4
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +244 -6
- package/package.json +3 -2
- package/src/checks/ci-workflow.mjs +105 -0
- package/src/checks/claude-app.mjs +11 -2
- package/src/checks/custom-harness.mjs +157 -0
- package/src/checks/github-app.mjs +214 -0
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +27 -8
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +583 -36
- package/src/deep-scan/agent.mjs +88 -21
- package/src/deep-scan/credential.mjs +81 -32
- package/src/deep-scan/docker-driver.mjs +105 -42
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +68 -178
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +21 -10
- package/src/deep-scan/preflight.mjs +19 -6
- package/src/deep-scan/recipe.mjs +4 -0
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +224 -39
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +73 -13
- package/src/doctor.mjs +166 -5
- package/src/exec.mjs +14 -5
- package/src/factory/budget/budget.mjs +259 -0
- package/src/factory/build/command.mjs +321 -0
- package/src/factory/build/factory.mjs +473 -0
- package/src/factory/build/findings.mjs +55 -0
- package/src/factory/build/host.mjs +230 -0
- package/src/factory/build/notes.mjs +191 -0
- package/src/factory/build/pull-request.mjs +74 -0
- package/src/factory/bundle.mjs +146 -0
- package/src/factory/checks/allowed-paths.mjs +50 -0
- package/src/factory/checks/plan-header.mjs +296 -0
- package/src/factory/checks/qa.mjs +85 -0
- package/src/factory/checks/review.mjs +73 -0
- package/src/factory/checks/security.mjs +50 -0
- package/src/factory/checks/stage-check.mjs +89 -0
- package/src/factory/claims/command.mjs +187 -0
- package/src/factory/claims/release.mjs +111 -0
- package/src/factory/decision/answers.mjs +103 -0
- package/src/factory/decision/command.mjs +64 -0
- package/src/factory/decision/plan.mjs +99 -0
- package/src/factory/decision/request.mjs +116 -0
- package/src/factory/doctor/files.mjs +329 -0
- package/src/factory/doctor/index.mjs +56 -0
- package/src/factory/doctor/local.mjs +497 -0
- package/src/factory/doctor/orchestrate.mjs +146 -0
- package/src/factory/engine/lease.mjs +146 -0
- package/src/factory/engine/local-engine.mjs +177 -0
- package/src/factory/engine/lockfile.mjs +64 -0
- package/src/factory/engine/workflow-engine.mjs +124 -0
- package/src/factory/gate/comment.mjs +88 -0
- package/src/factory/gate/config.mjs +57 -0
- package/src/factory/gate/gate-core.mjs +250 -0
- package/src/factory/gate/guarded.mjs +17 -0
- package/src/factory/gate/reads.mjs +105 -0
- package/src/factory/gate/task.mjs +193 -0
- package/src/factory/gate/trip-reads.mjs +82 -0
- package/src/factory/gate/trip.mjs +87 -0
- package/src/factory/init/blueprint.mjs +174 -0
- package/src/factory/init/index.mjs +337 -0
- package/src/factory/labels/evidence.mjs +162 -0
- package/src/factory/labels/moves.mjs +32 -0
- package/src/factory/labels/reconcile.mjs +267 -0
- package/src/factory/labels/revert.mjs +87 -0
- package/src/factory/labels/timeline.mjs +72 -0
- package/src/factory/labels/voided.mjs +59 -0
- package/src/factory/limits/harness.mjs +39 -0
- package/src/factory/limits/limits.mjs +123 -0
- package/src/factory/merge/command.mjs +172 -0
- package/src/factory/outbox/check.mjs +240 -0
- package/src/factory/outbox/rulings.mjs +195 -0
- package/src/factory/plan/command.mjs +66 -0
- package/src/factory/plan/comment.mjs +156 -0
- package/src/factory/plan/publish.mjs +149 -0
- package/src/factory/plan/risk.mjs +153 -0
- package/src/factory/qa/command.mjs +163 -0
- package/src/factory/records/engine-record.mjs +133 -0
- package/src/factory/records/main.mjs +96 -0
- package/src/factory/records/record.mjs +226 -0
- package/src/factory/records/sink.mjs +57 -0
- package/src/factory/report/build.mjs +92 -0
- package/src/factory/report/command.mjs +80 -0
- package/src/factory/report/facts.mjs +226 -0
- package/src/factory/report/gate-section.mjs +122 -0
- package/src/factory/report/metrics.mjs +111 -0
- package/src/factory/report/reads.mjs +246 -0
- package/src/factory/report/render.mjs +121 -0
- package/src/factory/report/rollout.mjs +154 -0
- package/src/factory/review/command.mjs +182 -0
- package/src/factory/run/awake.mjs +70 -0
- package/src/factory/run/collect.mjs +77 -0
- package/src/factory/run/command.mjs +490 -0
- package/src/factory/run/gh.mjs +46 -0
- package/src/factory/run/launch.mjs +47 -0
- package/src/factory/run/pipelines.mjs +261 -0
- package/src/factory/run/raw.mjs +96 -0
- package/src/factory/run/restart.mjs +83 -0
- package/src/factory/run/s3.mjs +193 -0
- package/src/factory/run/secrets.mjs +142 -0
- package/src/factory/run/teardown.mjs +242 -0
- package/src/factory/run/token.mjs +68 -0
- package/src/factory/security/command.mjs +157 -0
- package/src/factory/setup/app.mjs +122 -0
- package/src/factory/setup/command.mjs +409 -0
- package/src/factory/setup/labels.mjs +25 -0
- package/src/factory/setup/reads.mjs +129 -0
- package/src/factory/setup/writes.mjs +126 -0
- package/src/factory/snapshot/write.mjs +176 -0
- package/src/factory/stop/command.mjs +136 -0
- package/src/factory/sweep/actions-main.mjs +117 -0
- package/src/factory/sweep/command.mjs +65 -0
- package/src/factory/sweep/knobs.mjs +78 -0
- package/src/factory/sweep/marker-version.mjs +15 -0
- package/src/factory/sweep/markers.mjs +112 -0
- package/src/factory/sweep/overlap.mjs +24 -0
- package/src/factory/sweep/run.mjs +198 -0
- package/src/factory/sweep/shell.mjs +394 -0
- package/src/factory/sweep/split.mjs +104 -0
- package/src/factory/sweep/states.mjs +87 -0
- package/src/factory/sweep/sweep-core.mjs +1781 -0
- package/src/factory/tracker/github.mjs +674 -0
- package/src/factory/tracker/operations.mjs +153 -0
- package/src/factory/upgrade/index.mjs +83 -0
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +8 -1
- package/src/harness/codex.mjs +219 -0
- package/src/harness/cursor.mjs +199 -0
- package/src/harness/custom/registry.mjs +21 -0
- package/src/harness/custom/schema.mjs +90 -0
- package/src/harness/custom.mjs +299 -0
- package/src/harness/facts.mjs +44 -7
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +86 -3
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +151 -3
- package/src/harness-live/assess.mjs +29 -6
- package/src/harness-live/cursor-real.mjs +146 -0
- package/src/harness-live/cursor-version.mjs +70 -0
- package/src/harness-live/cursor.mjs +80 -0
- package/src/harness-live/custom.mjs +91 -0
- package/src/harness-live/fixture-harness.mjs +45 -0
- package/src/harness-live/harnesses.mjs +263 -0
- package/src/harness-live/host.mjs +113 -4
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +87 -7
- package/src/harness-live/run.mjs +101 -20
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +25 -15
- package/src/harness-live/suite.mjs +276 -95
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +374 -36
- package/src/kit-owned-paths.mjs +1 -1
- package/src/model-proxy/core.mjs +128 -20
- package/src/model-proxy/profiles/anthropic.mjs +54 -10
- package/src/model-proxy/profiles/gemini-api.mjs +311 -0
- package/src/model-proxy/profiles/openai.mjs +327 -0
- package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
- package/src/model-proxy/stub-dialects/openai.mjs +173 -0
- package/src/model-proxy/stub.mjs +9 -1
- package/src/stage/audit.mjs +79 -0
- package/src/stage/egress-route.mjs +207 -0
- package/src/stage/implement/carry.mjs +308 -0
- package/src/stage/implement/sandbox.mjs +271 -0
- package/src/stage/implement/verify.mjs +70 -0
- package/src/stage/implement.mjs +218 -0
- package/src/stage/plan.mjs +115 -0
- package/src/stage/review-response.mjs +172 -0
- package/src/stage/review.mjs +185 -0
- package/src/stage/workspace.mjs +274 -0
- package/src/stage.mjs +1087 -0
- package/src/upgrade.mjs +39 -7
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// The Plan header check (spec #500, Contracts; ADR 0034): a pure function from
|
|
2
|
+
// what the planner wrote to either a clean header or a list of refusals. It
|
|
3
|
+
// does no IO, so the trusted step and the tests call the same code. The
|
|
4
|
+
// contract suite is scripts/factory-check-plan-header.test.mjs over the
|
|
5
|
+
// fixtures in scripts/fixtures/factory/plan-header/.
|
|
6
|
+
//
|
|
7
|
+
// The planner writes the header as JSON in one fenced `agent-kit-plan` block
|
|
8
|
+
// of its result. Every object refuses a key it does not name, and the two keys
|
|
9
|
+
// only the trusted step may add (`risk_raised_by`, `superseded_by`) are
|
|
10
|
+
// refused from the planner like any other unknown key. Free text is capped and
|
|
11
|
+
// neutralised: it is untrusted, and it cannot ping anyone or pose as a marker.
|
|
12
|
+
//
|
|
13
|
+
// Later checks sit beside this file as `checks/<name>.mjs`: a function over
|
|
14
|
+
// plain data, returning `{ ok, ... }`, with no IO.
|
|
15
|
+
|
|
16
|
+
export const PLAN_VERSION = 1;
|
|
17
|
+
export const RISKS = Object.freeze(["low", "medium", "high"]);
|
|
18
|
+
export const SIZES = Object.freeze(["s", "m", "l"]);
|
|
19
|
+
export const CHECKS = Object.freeze(["unit", "integration", "e2e", "manual"]);
|
|
20
|
+
|
|
21
|
+
/** The most each kind of text holds, in characters. Past it, the text is cut. */
|
|
22
|
+
export const TEXT_CAPS = Object.freeze({
|
|
23
|
+
risk_reason: 500,
|
|
24
|
+
qa: 500,
|
|
25
|
+
path: 200,
|
|
26
|
+
criterion: 400,
|
|
27
|
+
how: 500,
|
|
28
|
+
question: 500,
|
|
29
|
+
option: 200,
|
|
30
|
+
recommendation: 300,
|
|
31
|
+
evidence: 1000,
|
|
32
|
+
title: 200,
|
|
33
|
+
summary: 1000,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** The most entries each list holds. Past it, the header is refused. */
|
|
37
|
+
export const LIST_CAPS = Object.freeze({
|
|
38
|
+
allowed_paths: 100,
|
|
39
|
+
test_plan: 100,
|
|
40
|
+
questions: 10,
|
|
41
|
+
options: 6,
|
|
42
|
+
split: 10,
|
|
43
|
+
blocked_by: 10,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const ELLIPSIS = "…";
|
|
47
|
+
// Any control character but a tab and a line feed.
|
|
48
|
+
const CONTROL = /[\0-\x08\x0b-\x1f\x7f]/g;
|
|
49
|
+
const HAS_CONTROL = /[\0-\x08\x0b-\x1f\x7f]/;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Agent text made safe to publish: control characters out, no mention that can
|
|
53
|
+
* ping anyone (a zero-width space after the `@`), no HTML comment that could
|
|
54
|
+
* pose as a marker, cut at `cap` characters.
|
|
55
|
+
*/
|
|
56
|
+
export function untrustedText(text, cap) {
|
|
57
|
+
const clean = String(text)
|
|
58
|
+
.replace(/\r\n?/g, "\n")
|
|
59
|
+
.replace(CONTROL, "")
|
|
60
|
+
.replace(/@(?=[A-Za-z0-9])/g, "@")
|
|
61
|
+
.replace(/<!--/g, "<!--")
|
|
62
|
+
.trim();
|
|
63
|
+
return clean.length > cap ? `${clean.slice(0, cap - 1).trimEnd()}${ELLIPSIS}` : clean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
67
|
+
|
|
68
|
+
/** Normal form of a criterion's text, so a copied checkbox line still matches. */
|
|
69
|
+
export const criterionKey = (text) =>
|
|
70
|
+
String(text)
|
|
71
|
+
.replace(/^\s*(?:[-*+]\s*)?(?:\[[ xX]\]\s*)?/, "")
|
|
72
|
+
.replace(/\s+/g, " ")
|
|
73
|
+
.trim()
|
|
74
|
+
.toLowerCase();
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The acceptance criteria of an issue body: the checklist items under its
|
|
78
|
+
* `Acceptance criteria` heading, up to the next heading.
|
|
79
|
+
* @returns {string[]}
|
|
80
|
+
*/
|
|
81
|
+
export function acceptanceCriteria(body) {
|
|
82
|
+
const lines = String(body ?? "").split(/\r?\n/);
|
|
83
|
+
const start = lines.findIndex((l) => /^#{1,6}\s+acceptance criteria\s*$/i.test(l.trim()));
|
|
84
|
+
if (start === -1) return [];
|
|
85
|
+
const out = [];
|
|
86
|
+
for (const line of lines.slice(start + 1)) {
|
|
87
|
+
if (/^#{1,6}\s/.test(line.trim())) break;
|
|
88
|
+
const item = /^\s*[-*+]\s+\[[ xX]\]\s+(.+?)\s*$/.exec(line);
|
|
89
|
+
if (item) out.push(item[1]);
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Collects refusals as one list, so a header is refused with every reason at once. */
|
|
95
|
+
function reader(errors) {
|
|
96
|
+
const fail = (path, message) => errors.push(`${path}: ${message}`);
|
|
97
|
+
const exact = (obj, path, required, optional = []) => {
|
|
98
|
+
const allowed = new Set([...required, ...optional]);
|
|
99
|
+
for (const key of Object.keys(obj)) {
|
|
100
|
+
if (!allowed.has(key)) fail(path, `unknown key \`${key}\``);
|
|
101
|
+
}
|
|
102
|
+
for (const key of required) {
|
|
103
|
+
if (!(key in obj)) fail(path, `missing key \`${key}\``);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const text = (value, path, kind) => {
|
|
107
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
108
|
+
fail(path, "must be a non-empty string");
|
|
109
|
+
return "";
|
|
110
|
+
}
|
|
111
|
+
return untrustedText(value, TEXT_CAPS[kind]);
|
|
112
|
+
};
|
|
113
|
+
const list = (value, path, kind, { min = 0 } = {}) => {
|
|
114
|
+
if (!Array.isArray(value)) {
|
|
115
|
+
fail(path, "must be a list");
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
if (value.length < min) fail(path, "must not be empty");
|
|
119
|
+
if (value.length > LIST_CAPS[kind]) fail(path, `holds more than ${LIST_CAPS[kind]} entries`);
|
|
120
|
+
return value.slice(0, LIST_CAPS[kind]);
|
|
121
|
+
};
|
|
122
|
+
const oneOf = (value, path, options) => {
|
|
123
|
+
if (!options.includes(value)) fail(path, `must be one of ${options.join(", ")}`);
|
|
124
|
+
return value;
|
|
125
|
+
};
|
|
126
|
+
return { fail, exact, text, list, oneOf };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A path the build may change: relative, inside the repository, no backslash or control character. */
|
|
130
|
+
function checkPath(raw, path, r) {
|
|
131
|
+
const value = typeof raw === "string" ? raw.trim() : "";
|
|
132
|
+
if (value === "") {
|
|
133
|
+
r.fail(path, "must be a non-empty string");
|
|
134
|
+
return "";
|
|
135
|
+
}
|
|
136
|
+
if (
|
|
137
|
+
value.startsWith("/") ||
|
|
138
|
+
value.includes("\\") ||
|
|
139
|
+
/^[A-Za-z]:/.test(value) ||
|
|
140
|
+
value.split("/").includes("..") ||
|
|
141
|
+
HAS_CONTROL.test(value)
|
|
142
|
+
) {
|
|
143
|
+
r.fail(path, "must be a relative path inside the repository, with no `..`");
|
|
144
|
+
return "";
|
|
145
|
+
}
|
|
146
|
+
if (value.length > TEXT_CAPS.path) {
|
|
147
|
+
r.fail(path, `is longer than ${TEXT_CAPS.path} characters`);
|
|
148
|
+
return "";
|
|
149
|
+
}
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @param {unknown} value what the planner wrote
|
|
155
|
+
* @param {{ criteria?: string[], trusted?: boolean }} [options] `criteria`: the issue's acceptance
|
|
156
|
+
* criteria, each needing a test plan entry. `trusted`: the header is one the trusted step
|
|
157
|
+
* published, which may also carry the two keys only it adds (`risk_raised_by`, `superseded_by`).
|
|
158
|
+
* @returns {{ ok: true, header: object } | { ok: false, errors: string[] }}
|
|
159
|
+
*/
|
|
160
|
+
export function checkPlanHeader(value, { criteria = [], trusted = false } = {}) {
|
|
161
|
+
const errors = [];
|
|
162
|
+
if (!isObject(value)) return { ok: false, errors: ["header: must be an object"] };
|
|
163
|
+
const r = reader(errors);
|
|
164
|
+
const h = value;
|
|
165
|
+
r.exact(
|
|
166
|
+
h,
|
|
167
|
+
"header",
|
|
168
|
+
["plan_version", "risk", "risk_reason", "allowed_paths", "size", "qa", "test_plan"],
|
|
169
|
+
trusted ? ["questions", "split", "risk_raised_by", "superseded_by"] : ["questions", "split"],
|
|
170
|
+
);
|
|
171
|
+
if (h.plan_version !== PLAN_VERSION) r.fail("plan_version", `must be ${PLAN_VERSION}`);
|
|
172
|
+
const header = { plan_version: PLAN_VERSION };
|
|
173
|
+
if ("risk" in h) header.risk = r.oneOf(h.risk, "risk", RISKS);
|
|
174
|
+
if ("risk_reason" in h) header.risk_reason = r.text(h.risk_reason, "risk_reason", "risk_reason");
|
|
175
|
+
if ("allowed_paths" in h) {
|
|
176
|
+
const paths = r.list(h.allowed_paths, "allowed_paths", "allowed_paths", { min: 1 });
|
|
177
|
+
header.allowed_paths = paths.map((p, i) => checkPath(p, `allowed_paths[${i}]`, r));
|
|
178
|
+
}
|
|
179
|
+
if ("size" in h) header.size = r.oneOf(h.size, "size", SIZES);
|
|
180
|
+
if ("qa" in h) header.qa = r.text(h.qa, "qa", "qa");
|
|
181
|
+
|
|
182
|
+
if ("test_plan" in h) {
|
|
183
|
+
const entries = r.list(h.test_plan, "test_plan", "test_plan");
|
|
184
|
+
header.test_plan = entries.map((entry, i) => {
|
|
185
|
+
const at = `test_plan[${i}]`;
|
|
186
|
+
if (!isObject(entry)) {
|
|
187
|
+
r.fail(at, "must be an object");
|
|
188
|
+
return {};
|
|
189
|
+
}
|
|
190
|
+
r.exact(entry, at, ["criterion", "check", "how"]);
|
|
191
|
+
return {
|
|
192
|
+
criterion: r.text(entry.criterion, `${at}.criterion`, "criterion"),
|
|
193
|
+
check: r.oneOf(entry.check, `${at}.check`, CHECKS),
|
|
194
|
+
how: r.text(entry.how, `${at}.how`, "how"),
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
const covered = new Set(header.test_plan.map((e) => criterionKey(e.criterion ?? "")));
|
|
198
|
+
for (const criterion of criteria) {
|
|
199
|
+
if (!covered.has(criterionKey(criterion))) {
|
|
200
|
+
r.fail(
|
|
201
|
+
"test_plan",
|
|
202
|
+
`has no entry for the acceptance criterion "${untrustedText(criterion, 80)}"`,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if ("questions" in h) {
|
|
209
|
+
const entries = r.list(h.questions, "questions", "questions");
|
|
210
|
+
header.questions = entries.map((entry, i) => {
|
|
211
|
+
const at = `questions[${i}]`;
|
|
212
|
+
if (!isObject(entry)) {
|
|
213
|
+
r.fail(at, "must be an object");
|
|
214
|
+
return {};
|
|
215
|
+
}
|
|
216
|
+
r.exact(entry, at, ["question", "options", "recommendation", "evidence"]);
|
|
217
|
+
const options = r.list(entry.options, `${at}.options`, "options", { min: 2 });
|
|
218
|
+
return {
|
|
219
|
+
question: r.text(entry.question, `${at}.question`, "question"),
|
|
220
|
+
options: options.map((o, j) => r.text(o, `${at}.options[${j}]`, "option")),
|
|
221
|
+
recommendation: r.text(entry.recommendation, `${at}.recommendation`, "recommendation"),
|
|
222
|
+
evidence: r.text(entry.evidence, `${at}.evidence`, "evidence"),
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if ("split" in h) {
|
|
228
|
+
const entries = r.list(h.split, "split", "split");
|
|
229
|
+
const split = entries.map((entry, i) => {
|
|
230
|
+
const at = `split[${i}]`;
|
|
231
|
+
if (!isObject(entry)) {
|
|
232
|
+
r.fail(at, "must be an object");
|
|
233
|
+
return {};
|
|
234
|
+
}
|
|
235
|
+
r.exact(entry, at, ["title", "summary", "allowed_paths", "blocked_by"]);
|
|
236
|
+
const paths = r.list(entry.allowed_paths, `${at}.allowed_paths`, "allowed_paths", { min: 1 });
|
|
237
|
+
const blockedBy = r.list(entry.blocked_by, `${at}.blocked_by`, "blocked_by");
|
|
238
|
+
return {
|
|
239
|
+
title: r.text(entry.title, `${at}.title`, "title"),
|
|
240
|
+
summary: r.text(entry.summary, `${at}.summary`, "summary"),
|
|
241
|
+
allowed_paths: paths.map((p, j) => checkPath(p, `${at}.allowed_paths[${j}]`, r)),
|
|
242
|
+
blocked_by: blockedBy.map((b, j) => r.text(b, `${at}.blocked_by[${j}]`, "title")),
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
// `blocked_by` names sibling children by title: a child does not exist yet to be named by number.
|
|
246
|
+
const titles = new Set(split.map((s) => s.title));
|
|
247
|
+
split.forEach((s, i) => {
|
|
248
|
+
for (const b of s.blocked_by ?? []) {
|
|
249
|
+
if (!titles.has(b))
|
|
250
|
+
r.fail(`split[${i}].blocked_by`, `names no sibling titled "${untrustedText(b, 80)}"`);
|
|
251
|
+
if (b === s.title) r.fail(`split[${i}].blocked_by`, "names itself");
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
header.split = split;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (trusted && "risk_raised_by" in h) {
|
|
258
|
+
const ids = r.list(h.risk_raised_by, "risk_raised_by", "blocked_by");
|
|
259
|
+
header.risk_raised_by = ids.map((id, i) => r.text(id, `risk_raised_by[${i}]`, "title"));
|
|
260
|
+
}
|
|
261
|
+
if (trusted && "superseded_by" in h) {
|
|
262
|
+
if (!Number.isInteger(h.superseded_by) || h.superseded_by < 2) {
|
|
263
|
+
r.fail("superseded_by", "must be a plan number above 1");
|
|
264
|
+
} else {
|
|
265
|
+
header.superseded_by = h.superseded_by;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return errors.length ? { ok: false, errors } : { ok: true, header };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const FENCE = /^```agent-kit-plan[ \t]*\n([\s\S]*?)\n```[ \t]*$/gm;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The header block of a plan's text: exactly one fenced `agent-kit-plan` block
|
|
276
|
+
* holding JSON. `rest` is the text without the block, the prose.
|
|
277
|
+
* @returns {{ ok: true, data: unknown, prose: string } | { ok: false, error: string }}
|
|
278
|
+
*/
|
|
279
|
+
export function parseHeaderBlock(planText) {
|
|
280
|
+
const text = String(planText ?? "").replace(/\r\n?/g, "\n");
|
|
281
|
+
const blocks = [...text.matchAll(FENCE)];
|
|
282
|
+
if (blocks.length === 0) return { ok: false, error: "the plan has no `agent-kit-plan` block" };
|
|
283
|
+
if (blocks.length > 1)
|
|
284
|
+
return { ok: false, error: "the plan has more than one `agent-kit-plan` block" };
|
|
285
|
+
let data;
|
|
286
|
+
try {
|
|
287
|
+
data = JSON.parse(blocks[0][1]);
|
|
288
|
+
} catch {
|
|
289
|
+
return { ok: false, error: "the `agent-kit-plan` block is not valid JSON" };
|
|
290
|
+
}
|
|
291
|
+
const block = blocks[0];
|
|
292
|
+
const prose = `${text.slice(0, block.index)}${text.slice(block.index + block[0].length)}`
|
|
293
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
294
|
+
.trim();
|
|
295
|
+
return { ok: true, data, prose };
|
|
296
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// The QA Stage's check (spec #500, the QA Stage; ADR 0035, ADR 0033): a pure
|
|
2
|
+
// function from the QA Report comment to the `factory/qa` Stage check. The
|
|
3
|
+
// comment is the one `manual-qa` posts, its first line the marker and its next
|
|
4
|
+
// line the strict header, one of two fixed forms:
|
|
5
|
+
//
|
|
6
|
+
// QA Report: result=passed|failed; commit=<sha>; left-for-person=<n>; deferred=<n>
|
|
7
|
+
// QA Report: no manual QA needed; commit=<sha>
|
|
8
|
+
//
|
|
9
|
+
// The check is `pending` at the start, `success` or `failure` only from a valid
|
|
10
|
+
// header whose commit is the head, and `error` with none. Items left for a
|
|
11
|
+
// person are not a failure: the status is `success`, `passed; held <n>`, so the
|
|
12
|
+
// gate reads the held count from the status alone. Deferred items never hold.
|
|
13
|
+
// This reads the same two forms as `.claude/skills/manual-qa/report.mjs`
|
|
14
|
+
// (`parseHeader`), but not its optional `**Stale:**` line: a report `qa-plan`
|
|
15
|
+
// marked stale after a plan revision is no result for the head, so it is an
|
|
16
|
+
// `error` here (the safe side). A test holds the two readers to each other, so the
|
|
17
|
+
// bundle needs no skill. Fixtures: scripts/fixtures/factory/qa/; contract
|
|
18
|
+
// suite: scripts/factory-check-qa.test.mjs.
|
|
19
|
+
|
|
20
|
+
import { STAGE_CHECK_CONTEXTS } from "./stage-check.mjs";
|
|
21
|
+
|
|
22
|
+
export const QA_CONTEXT = STAGE_CHECK_CONTEXTS.qa;
|
|
23
|
+
/** The first line of the one PR comment that carries a QA Report. */
|
|
24
|
+
export const QA_REPORT_MARKER = "<!-- qa-report -->";
|
|
25
|
+
|
|
26
|
+
const COUNT = "(0|[1-9][0-9]{0,5})";
|
|
27
|
+
// Like manual-qa's reader, a header may name a SHA-256 commit; the Stage check
|
|
28
|
+
// itself writes only to a 40-hex head (STAGE_SHA), so such a header is never equal to it.
|
|
29
|
+
const HEAD_HEX = "[0-9a-f]{40}(?:[0-9a-f]{24})?";
|
|
30
|
+
const RESULT_LINE = new RegExp(
|
|
31
|
+
`^QA Report: result=(passed|failed); commit=(${HEAD_HEX}); left-for-person=${COUNT}; deferred=${COUNT}$`,
|
|
32
|
+
);
|
|
33
|
+
const NONE_LINE = new RegExp(`^QA Report: no manual QA needed; commit=(${HEAD_HEX})$`);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The strict header of a QA Report comment, or null. The marker is the first
|
|
37
|
+
* line, the header the first line after it that is not blank, and it is the
|
|
38
|
+
* only line of the comment that starts `QA Report:`: a second one makes the
|
|
39
|
+
* comment unreadable.
|
|
40
|
+
* @returns {{ kind: "result", result: "passed" | "failed", commit: string, leftForPerson: number, deferred: number } | { kind: "none-needed", commit: string } | null}
|
|
41
|
+
*/
|
|
42
|
+
export function parseQaHeader(report) {
|
|
43
|
+
const lines = String(report ?? "")
|
|
44
|
+
.replace(/\r\n/g, "\n")
|
|
45
|
+
.split("\n");
|
|
46
|
+
if (lines[0]?.trim() !== QA_REPORT_MARKER) return null;
|
|
47
|
+
const at = lines.findIndex((line, n) => n > 0 && line.trim() !== "");
|
|
48
|
+
if (at === -1) return null;
|
|
49
|
+
if (lines.filter((line) => line.startsWith("QA Report:")).length !== 1) return null;
|
|
50
|
+
const result = RESULT_LINE.exec(lines[at]);
|
|
51
|
+
if (result) {
|
|
52
|
+
return {
|
|
53
|
+
kind: "result",
|
|
54
|
+
result: /** @type {"passed" | "failed"} */ (result[1]),
|
|
55
|
+
commit: result[2],
|
|
56
|
+
leftForPerson: Number(result[3]),
|
|
57
|
+
deferred: Number(result[4]),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const none = NONE_LINE.exec(lines[at]);
|
|
61
|
+
return none ? { kind: "none-needed", commit: none[1] } : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The QA Stage check.
|
|
66
|
+
* @param {{ started?: boolean, report?: string | null, head?: string }} input
|
|
67
|
+
* `started`: the Stage has just begun, no result yet. Otherwise `report` is
|
|
68
|
+
* the QA Report comment's text (or null when the Stage left none) and `head`
|
|
69
|
+
* the commit the check is for.
|
|
70
|
+
* @returns {{ context: string, state: "pending" | "success" | "failure" | "error", description: string }}
|
|
71
|
+
*/
|
|
72
|
+
export function qaStageCheck({ started = false, report = null, head = "" } = {}) {
|
|
73
|
+
const check = (state, description) => ({ context: QA_CONTEXT, state, description });
|
|
74
|
+
if (started) return check("pending", "qa started");
|
|
75
|
+
const header = parseQaHeader(report);
|
|
76
|
+
if (!header) return check("error", "no valid qa result");
|
|
77
|
+
// A header for another commit judged something else: no result for this head.
|
|
78
|
+
if (header.commit !== head) return check("error", "qa result is for another commit");
|
|
79
|
+
if (header.kind === "none-needed") return check("success", "passed");
|
|
80
|
+
if (header.result === "failed") return check("failure", "failed");
|
|
81
|
+
return check(
|
|
82
|
+
"success",
|
|
83
|
+
header.leftForPerson > 0 ? `passed; held ${header.leftForPerson}` : "passed",
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The review Stage's check (spec #500, the review Stage; ADR 0035): a pure
|
|
2
|
+
// function from the Review report to the `factory/review` Stage check. The
|
|
3
|
+
// report's strict header, written by the trusted publish step and never by the
|
|
4
|
+
// agent, is one line:
|
|
5
|
+
//
|
|
6
|
+
// <!-- agent-kit-review v=1 result=pass|fail head=<40 hex> blocking=<n> -->
|
|
7
|
+
//
|
|
8
|
+
// `blocking` is the count of open Findings above nit on the head. The check is
|
|
9
|
+
// `pending` at the start, `success` or `failure` only from a valid header for
|
|
10
|
+
// this head, and `error` with none. It fails while any open Finding above nit
|
|
11
|
+
// remains, whatever `result` says. Fixtures: scripts/fixtures/factory/review/;
|
|
12
|
+
// contract suite: scripts/factory-check-review.test.mjs.
|
|
13
|
+
|
|
14
|
+
import { rulingFindings } from "../outbox/rulings.mjs";
|
|
15
|
+
import { STAGE_CHECK_CONTEXTS } from "./stage-check.mjs";
|
|
16
|
+
|
|
17
|
+
export const REVIEW_CONTEXT = STAGE_CHECK_CONTEXTS.review;
|
|
18
|
+
|
|
19
|
+
const HEADER_LINE =
|
|
20
|
+
/^<!-- agent-kit-review v=1 result=(pass|fail) head=([0-9a-f]{40}) blocking=(0|[1-9][0-9]{0,5}) -->$/;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The strict header of a Review report, or null. One header line, alone on its
|
|
24
|
+
* line, exactly one in the report: a second one, or any other `agent-kit-review`
|
|
25
|
+
* marker, makes the report unreadable.
|
|
26
|
+
* @returns {{ result: "pass" | "fail", head: string, blocking: number } | null}
|
|
27
|
+
*/
|
|
28
|
+
export function parseReviewHeader(report) {
|
|
29
|
+
const lines = String(report ?? "")
|
|
30
|
+
.replace(/\r\n/g, "\n")
|
|
31
|
+
.split("\n");
|
|
32
|
+
const marked = lines.filter((line) => line.includes("agent-kit-review"));
|
|
33
|
+
if (marked.length !== 1) return null;
|
|
34
|
+
const match = HEADER_LINE.exec(marked[0]);
|
|
35
|
+
if (!match) return null;
|
|
36
|
+
return { result: match[1], head: match[2], blocking: Number(match[3]) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const plural = (n) => `${n} open finding${n === 1 ? "" : "s"} above nit`;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The review Stage check.
|
|
43
|
+
* @param {{ started?: boolean, report?: string | null, head?: string, unheld?: number }} input
|
|
44
|
+
* `started`: the Stage has just begun, no result yet. Otherwise `report` is
|
|
45
|
+
* the Review report's text (or null when the Stage left none) and `head` the
|
|
46
|
+
* commit the check is for. `unheld` (factory mode, ADR 0040): the Rulings in
|
|
47
|
+
* the pull request's trusted block that do not hold against the evidence they
|
|
48
|
+
* cite (`unheldRulings`); each is a Finding above nit, so any fails the check.
|
|
49
|
+
* @returns {{ context: string, state: "pending" | "success" | "failure" | "error", description: string }}
|
|
50
|
+
*/
|
|
51
|
+
export function reviewStageCheck({ started = false, report = null, head = "", unheld = 0 } = {}) {
|
|
52
|
+
const check = (state, description) => ({ context: REVIEW_CONTEXT, state, description });
|
|
53
|
+
if (started) return check("pending", "review started");
|
|
54
|
+
const header = parseReviewHeader(report);
|
|
55
|
+
if (!header) return check("error", "no valid review result");
|
|
56
|
+
// A header for another commit judged something else: no result for this head.
|
|
57
|
+
if (header.head !== head) return check("error", "review result is for another commit");
|
|
58
|
+
const open = header.blocking + (Number.isInteger(unheld) && unheld > 0 ? unheld : 0);
|
|
59
|
+
if (open > 0) return check("failure", `changes requested: ${plural(open)}`);
|
|
60
|
+
if (header.result === "fail") return check("failure", "changes requested");
|
|
61
|
+
return check("success", "passed");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The Rulings a pull request body carries in its trusted block that do not hold
|
|
66
|
+
* against the evidence they cite: the count the review Stage adds to `blocking`.
|
|
67
|
+
* A Ruling is unheld once, however many of its pieces of evidence fail.
|
|
68
|
+
* @param {string} prBody
|
|
69
|
+
* @param {string} repo `owner/name`
|
|
70
|
+
*/
|
|
71
|
+
export function unheldRulings(prBody, repo) {
|
|
72
|
+
return new Set(rulingFindings(prBody, { repo }).map((f) => f.id)).size;
|
|
73
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The security Stage's check (spec #500, the security Stage; ADR 0035): a pure
|
|
2
|
+
// function from the audit's result to the `factory/security` Stage check. The
|
|
3
|
+
// audit's findings go only to the private draft advisory, so this check says
|
|
4
|
+
// nothing about them: its description is exactly one of two plain strings,
|
|
5
|
+
//
|
|
6
|
+
// passed the audit ran and reported nothing
|
|
7
|
+
// held for a maintainer anything else: findings, or an audit that could not run
|
|
8
|
+
//
|
|
9
|
+
// with no count, severity or link, because a public commit status must never
|
|
10
|
+
// leak a vulnerability. The check is `pending` at the start, `success` only when
|
|
11
|
+
// the audit job succeeded and its result output is exactly `clean`, and
|
|
12
|
+
// `failure` otherwise. There is no `error`: an audit that cannot run is held
|
|
13
|
+
// like one that found something, so the two look alike on the head. Fixtures:
|
|
14
|
+
// scripts/fixtures/factory/security/; contract suite:
|
|
15
|
+
// scripts/factory-check-security.test.mjs.
|
|
16
|
+
|
|
17
|
+
import { STAGE_CHECK_CONTEXTS } from "./stage-check.mjs";
|
|
18
|
+
|
|
19
|
+
export const SECURITY_CONTEXT = STAGE_CHECK_CONTEXTS.security;
|
|
20
|
+
export const SECURITY_PASSED = "passed";
|
|
21
|
+
export const SECURITY_HELD = "held for a maintainer";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The security Stage check.
|
|
25
|
+
* @param {{ started?: boolean, jobResult?: string, auditResult?: string }} input
|
|
26
|
+
* `started`: the Stage has just begun, no result yet. Otherwise `jobResult` is
|
|
27
|
+
* the audit job's own result (`success`, `failure`, `cancelled`, `skipped`) and
|
|
28
|
+
* `auditResult` the reusable's bare verdict output (`clean` or `held`).
|
|
29
|
+
* @returns {{ context: string, state: "pending" | "success" | "failure", description: string }}
|
|
30
|
+
*/
|
|
31
|
+
export function securityStageCheck({ started = false, jobResult, auditResult } = {}) {
|
|
32
|
+
const check = (state, description) => ({ context: SECURITY_CONTEXT, state, description });
|
|
33
|
+
if (started) return check("pending", "security started");
|
|
34
|
+
// Only the exact pair passes. Nothing the audit or its inputs say reaches the text.
|
|
35
|
+
if (jobResult === "success" && auditResult === "clean") return check("success", SECURITY_PASSED);
|
|
36
|
+
return check("failure", SECURITY_HELD);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether a Stage check the sweep read (`engineStageCheck`) is a security pass:
|
|
41
|
+
* the engine's `success` whose description is exactly `passed`, or `passed` with
|
|
42
|
+
* the carry-over suffix (ADR 0035). A success with any other text is not one.
|
|
43
|
+
* @param {{ state: string, description: string } | null | undefined} check
|
|
44
|
+
*/
|
|
45
|
+
export function securityPassed(check) {
|
|
46
|
+
return (
|
|
47
|
+
check?.state === "success" &&
|
|
48
|
+
/^passed(?: \(carried from [0-9a-f]{7}\))?$/.test(check.description)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The Stage check, shared by every Stage (ADR 0035): a commit status whose
|
|
2
|
+
// context is `factory/<stage>`, written by a trusted step and read back by its
|
|
3
|
+
// creator. This file is the plain part the review, QA and security checks share:
|
|
4
|
+
// what a valid check is, how it is written, and how the sweep reads one. It
|
|
5
|
+
// decides nothing about a Stage's result: each Stage's own function does that
|
|
6
|
+
// (checks/review.mjs). Contract suite: scripts/factory-check-review.test.mjs.
|
|
7
|
+
|
|
8
|
+
export const STAGE_CHECK_CONTEXTS = Object.freeze({
|
|
9
|
+
review: "factory/review",
|
|
10
|
+
qa: "factory/qa",
|
|
11
|
+
security: "factory/security",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/** `pending` at the start, `success` or `failure` from a valid result, `error` with none. */
|
|
15
|
+
export const STAGE_CHECK_STATES = Object.freeze(["pending", "success", "failure", "error"]);
|
|
16
|
+
|
|
17
|
+
/** GitHub cuts a status description at 140 characters; the check is never longer. */
|
|
18
|
+
export const STAGE_CHECK_DESCRIPTION_CAP = 140;
|
|
19
|
+
|
|
20
|
+
export const STAGE_SHA = /^[0-9a-f]{40}$/;
|
|
21
|
+
export const STAGE_REPO = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
22
|
+
|
|
23
|
+
/** A check that may be written: a known context, a known state, a short plain line. */
|
|
24
|
+
export function validStageCheck({ context, state, description }) {
|
|
25
|
+
if (!Object.values(STAGE_CHECK_CONTEXTS).includes(context)) return false;
|
|
26
|
+
if (!STAGE_CHECK_STATES.includes(state)) return false;
|
|
27
|
+
return (
|
|
28
|
+
typeof description === "string" &&
|
|
29
|
+
description.length > 0 &&
|
|
30
|
+
description.length <= STAGE_CHECK_DESCRIPTION_CAP &&
|
|
31
|
+
// eslint-disable-next-line no-control-regex
|
|
32
|
+
!/[\u0000-\u001f\u007f]/.test(description)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Writes one Stage check on a commit, with the trusted step's token. It throws
|
|
38
|
+
* on a check that is not valid, so nothing malformed ever reaches the tracker.
|
|
39
|
+
* @param {{ gh: (args: string[]) => { status: number | null, stdout: string, stderr: string }, repo: string, sha: string, check: { context: string, state: string, description: string }, targetUrl?: string }} input
|
|
40
|
+
*/
|
|
41
|
+
export function writeStageCheck({ gh, repo, sha, check, targetUrl }) {
|
|
42
|
+
if (!STAGE_REPO.test(repo)) throw new Error(`not a repository: ${JSON.stringify(repo)}`);
|
|
43
|
+
if (!STAGE_SHA.test(sha)) throw new Error(`not a commit sha: ${JSON.stringify(sha)}`);
|
|
44
|
+
if (!validStageCheck(check)) {
|
|
45
|
+
throw new Error(`not a valid Stage check: ${JSON.stringify(check)}`);
|
|
46
|
+
}
|
|
47
|
+
const args = [
|
|
48
|
+
"api",
|
|
49
|
+
// The fields below make it a POST: gh's default for a call that has any.
|
|
50
|
+
`repos/${repo}/statuses/${sha}`,
|
|
51
|
+
"-f",
|
|
52
|
+
`state=${check.state}`,
|
|
53
|
+
"-f",
|
|
54
|
+
`context=${check.context}`,
|
|
55
|
+
"-f",
|
|
56
|
+
`description=${check.description}`,
|
|
57
|
+
];
|
|
58
|
+
if (targetUrl) {
|
|
59
|
+
if (!/^https:\/\/[^\s]+$/.test(targetUrl)) throw new Error("target url is not an https url");
|
|
60
|
+
args.push("-f", `target_url=${targetUrl}`);
|
|
61
|
+
}
|
|
62
|
+
const result = gh(args);
|
|
63
|
+
if (result.status !== 0) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`writing ${check.context} failed: ${String(result.stderr).trim().slice(0, 300)}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A head's Stage check as the sweep may trust it: the newest status of
|
|
72
|
+
* `context` whose creator is the engine's identity. A status of that context
|
|
73
|
+
* from anyone else is ignored, as if it were not there. `statuses` is the
|
|
74
|
+
* tracker's read for the head, `[{ context, state, creator }]`, newest first.
|
|
75
|
+
* @returns {{ state: string, description: string, createdAt?: string } | null}
|
|
76
|
+
*/
|
|
77
|
+
export function engineStageCheck(statuses, context, isEngine) {
|
|
78
|
+
for (const status of statuses ?? []) {
|
|
79
|
+
if (status?.context !== context) continue;
|
|
80
|
+
if (!isEngine(status.creator)) continue;
|
|
81
|
+
if (!STAGE_CHECK_STATES.includes(status.state)) return null;
|
|
82
|
+
return {
|
|
83
|
+
state: status.state,
|
|
84
|
+
description: String(status.description ?? ""),
|
|
85
|
+
...(status.createdAt === undefined ? {} : { createdAt: status.createdAt }),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|