forgedock 1.59.1 → 1.60.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.
- package/bin/engine/outcome-codes.mjs +3 -3
- package/bin/engine-cli.mjs +50 -10
- package/bin/labels.json +5 -0
- package/bin/lean/batch.mjs +21 -2
- package/bin/lean/batch.test.mjs +116 -1
- package/bin/lean/conformance.mjs +12 -5
- package/bin/lean/conformance.test.mjs +30 -2
- package/bin/lean/depcache.mjs +34 -15
- package/bin/lean/depcache.test.mjs +100 -1
- package/bin/lean/design-gate.mjs +15 -10
- package/bin/lean/design-gate.test.mjs +21 -0
- package/bin/lean/effects.mjs +18 -2
- package/bin/lean/execution.mjs +23 -5
- package/bin/lean/execution.test.mjs +81 -1
- package/bin/lean/gatewatch.test.mjs +5 -5
- package/bin/lean/issuewatch-triage.mjs +68 -0
- package/bin/lean/issuewatch-triage.test.mjs +98 -0
- package/bin/lean/issuewatch.mjs +34 -6
- package/bin/lean/issuewatch.test.mjs +11 -0
- package/bin/lean/lanelock.mjs +5 -4
- package/bin/lean/lean.mjs +123 -17
- package/bin/lean/lean.test.mjs +154 -6
- package/bin/lean/orchestrate-cancel.test.mjs +33 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +41 -0
- package/bin/lean/orchestrate-recovering.test.mjs +42 -0
- package/bin/lean/orchestrate.mjs +23 -10
- package/bin/lean/pagegate.mjs +50 -12
- package/bin/lean/pagegate.test.mjs +38 -1
- package/bin/lean/phaseledger.mjs +65 -2
- package/bin/lean/phaseledger.test.mjs +70 -2
- package/bin/lean/preflight.mjs +5 -2
- package/bin/lean/preflight.test.mjs +7 -0
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/recovery.test.mjs +11 -6
- package/bin/lean/release-classify.mjs +143 -0
- package/bin/lean/release-classify.test.mjs +130 -0
- package/bin/lean/release-conductor.mjs +163 -0
- package/bin/lean/release-conductor.test.mjs +194 -0
- package/bin/lean/release-config.mjs +60 -8
- package/bin/lean/release-config.test.mjs +43 -1
- package/bin/lean/release-control.mjs +22 -5
- package/bin/lean/release-control.test.mjs +22 -0
- package/bin/lean/release-credentials.mjs +40 -0
- package/bin/lean/release-credentials.test.mjs +42 -0
- package/bin/lean/release-deploy.mjs +3 -3
- package/bin/lean/release-deploy.test.mjs +8 -0
- package/bin/lean/release-docs.test.mjs +93 -0
- package/bin/lean/release-fence.mjs +2 -0
- package/bin/lean/release-gate.mjs +88 -0
- package/bin/lean/release-gate.test.mjs +116 -0
- package/bin/lean/release-gates.mjs +5 -1
- package/bin/lean/release-ledger.mjs +47 -1
- package/bin/lean/release-ledger.test.mjs +33 -1
- package/bin/lean/release-mergeback.mjs +148 -0
- package/bin/lean/release-mergeback.test.mjs +129 -0
- package/bin/lean/release-p0.mjs +193 -0
- package/bin/lean/release-p0.test.mjs +127 -0
- package/bin/lean/release-plan.mjs +267 -0
- package/bin/lean/release-plan.test.mjs +202 -0
- package/bin/lean/release-preflight.mjs +16 -0
- package/bin/lean/release-regate.mjs +141 -0
- package/bin/lean/release-regate.test.mjs +149 -0
- package/bin/lean/release-review.mjs +5 -3
- package/bin/lean/release-rollback.mjs +277 -0
- package/bin/lean/release-rollback.test.mjs +245 -0
- package/bin/lean/release-snapshot.mjs +48 -9
- package/bin/lean/release-snapshot.test.mjs +43 -1
- package/bin/lean/release-start.mjs +164 -0
- package/bin/lean/release-start.test.mjs +171 -0
- package/bin/lean/release-status.mjs +6 -2
- package/bin/lean/release-train.mjs +159 -0
- package/bin/lean/release-train.test.mjs +139 -0
- package/bin/lean/release.mjs +127 -5
- package/bin/lean/release.test.mjs +80 -0
- package/bin/lean/sandbox-remote.mjs +2 -0
- package/bin/lean/schedd-load.test.mjs +82 -0
- package/bin/lean/schedd.mjs +67 -31
- package/bin/lean/schedd.test.mjs +80 -1
- package/bin/lean/validate-catalog.mjs +94 -0
- package/bin/lean/validate-catalog.test.mjs +42 -0
- package/bin/pool/agent.mjs +4 -1
- package/bin/pool/lane-tools.mjs +115 -0
- package/bin/pool/lane-tools.test.mjs +26 -0
- package/bin/pool/warm.mjs +1 -1
- package/docs/CONFIG.md +225 -1
- package/docs/ISSUE-WATCH.md +1 -0
- package/docs/design/visual-gate.md +10 -0
- package/docs/eval/adversarial-bench.md +1 -0
- package/package.json +5 -2
- package/pool/README.md +2 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +2 -1
- package/templates/github-actions/forge-conductor.scopes.json +7 -0
- package/templates/github-actions/forge-conductor.yml +57 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* `mode: triage` of `forgedock issue-watch` (#5558, epic #5549 Phase 1): filing an issue never starts work. The tick only
|
|
5
|
+
* classifies new open issues text-only (one injected `io.triageClassify` call each, capped per hour) and labels them. It is
|
|
6
|
+
* handed no claim, lane-launch or batch seam, so it cannot claim or build. Deterministic first: the `needs-info` check, the
|
|
7
|
+
* labels, the record rules (confidence cap, migrations never `none`) and the idempotence marker are all script facts.
|
|
8
|
+
*/
|
|
9
|
+
import { buildClassifyRecord, validateClassification, renderClassify, deriveFacts, ReleaseClassifyTYPES } from "./release-classify.mjs";
|
|
10
|
+
import { noComments } from "./render.mjs";
|
|
11
|
+
|
|
12
|
+
export const CLASSIFY_MARKER = "<!-- FORGE:CLASSIFY -->";
|
|
13
|
+
export const NEEDS_INFO_LABEL = "needs-info";
|
|
14
|
+
export const DEFAULT_TRIAGE_PER_HOUR = 10;
|
|
15
|
+
const HOUR = 3600000;
|
|
16
|
+
const ACCEPT_HEADING = /^\s{0,3}#{1,6}\s*(acceptance( criteria)?|definition of done)\b/im;
|
|
17
|
+
const CHECKLIST = /^\s*[-*]\s+\[[ xX]\]\s+\S/m;
|
|
18
|
+
|
|
19
|
+
/** True when the body has no acceptance criteria: no `Acceptance` / `Definition of done` heading and no checklist item. */
|
|
20
|
+
export function needsInfo(body) {
|
|
21
|
+
const b = noComments(String(body ?? ""));
|
|
22
|
+
return !(ACCEPT_HEADING.test(b) || CHECKLIST.test(b));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Suggestion labels only: `type:*`, `priority:*` and (when not `none`) `lane:*`. */
|
|
26
|
+
export const triageLabels = (rec) => [`type:${rec.type}`, `priority:${rec.severity}`, rec.lane_hint && rec.lane_hint !== "none" ? `lane:${rec.lane_hint}` : null].filter(Boolean);
|
|
27
|
+
|
|
28
|
+
const hasClassify = (i) => (i.comments ?? []).some((c) => String(c?.body ?? "").includes("FORGE:CLASSIFY"));
|
|
29
|
+
|
|
30
|
+
/** Cap per hour: the watch's `triage.max_per_hour`, else the policy's `classify.triage_max_per_hour`, else the default. */
|
|
31
|
+
export const maxPerHour = (watch, policy) => watch.triage_max_per_hour ?? policy?.classify?.triage_max_per_hour ?? DEFAULT_TRIAGE_PER_HOUR;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* One pass. `listOpen() → issues` (with `comments`), `trusted(issue) → bool`, `io.{gh, now, triageClassify(issue) → {type, severity, exists_in?, lane_hint?, confidence?}, pause?() → null|{reason}}`.
|
|
35
|
+
* `state.triage.calls` holds the model-call times of the last hour. Returns `{paused?, classified[], skipped[], calls}`.
|
|
36
|
+
*/
|
|
37
|
+
export async function triageTick({ watch, repo, io, state, listOpen, trusted = () => false, policy = null }) {
|
|
38
|
+
const out = { classified: [], skipped: [], calls: 0 };
|
|
39
|
+
if (watch.mode !== "triage") return out; // zero GitHub writes outside triage mode
|
|
40
|
+
const paused = await io.pause?.();
|
|
41
|
+
if (paused) return { ...out, paused: paused.reason ?? true };
|
|
42
|
+
const now = io.now();
|
|
43
|
+
const t = (state.triage ??= { calls: [], errors: {} });
|
|
44
|
+
t.calls = (t.calls ?? []).filter((at) => now - at < HOUR);
|
|
45
|
+
const cap = maxPerHour(watch, policy);
|
|
46
|
+
const facts = deriveFacts(policy, []);
|
|
47
|
+
for (const issue of await listOpen()) {
|
|
48
|
+
const n = issue.number;
|
|
49
|
+
if (hasClassify(issue)) continue;
|
|
50
|
+
if (!trusted(issue)) { out.skipped.push({ n, why: "untrusted author" }); continue; }
|
|
51
|
+
if (t.calls.length >= cap) { out.skipped.push({ n, why: "cap" }); continue; } // waits for the next tick
|
|
52
|
+
t.calls.push(now); out.calls++;
|
|
53
|
+
try {
|
|
54
|
+
const llm = { ...(await io.triageClassify(issue)) };
|
|
55
|
+
if (llm.severity === "P0") llm.severity = "P1"; // text alone never proves production impact
|
|
56
|
+
llm.exists_in ??= "unknown"; llm.severity ??= "P3";
|
|
57
|
+
const rec = { ...buildClassifyRecord(llm, policy, facts, { text: true }), set_by: "issue-watch-triage" };
|
|
58
|
+
const bad = validateClassification(rec);
|
|
59
|
+
if (bad.length || !ReleaseClassifyTYPES.includes(rec.type)) throw new Error(`invalid classification: ${bad.join("; ") || "type"}`);
|
|
60
|
+
const labels = [...triageLabels(rec), ...(needsInfo(issue.body) ? [NEEDS_INFO_LABEL] : [])];
|
|
61
|
+
await io.gh(["issue", "edit", String(n), "-R", repo, "--add-label", labels.join(",")]);
|
|
62
|
+
await io.gh(["issue", "comment", String(n), "-R", repo, "--body", `${CLASSIFY_MARKER}\n${renderClassify(rec)}`]); // the marker last: a failed label retries
|
|
63
|
+
delete t.errors[n]; out.classified.push({ n, labels });
|
|
64
|
+
} catch (e) { t.errors[n] = String(e?.message ?? e).slice(0, 200); out.skipped.push({ n, why: t.errors[n] }); }
|
|
65
|
+
}
|
|
66
|
+
state.triage.last = { at: new Date(now).toISOString(), classified: out.classified.length, calls: out.calls };
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { test } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { triageTick, needsInfo, triageLabels, maxPerHour } from "./issuewatch-triage.mjs";
|
|
6
|
+
import { validateWatch } from "./issuewatch.mjs";
|
|
7
|
+
|
|
8
|
+
const W = (o = {}) => validateWatch("t", { mode: "triage", ...o });
|
|
9
|
+
const iss = (n, o = {}) => ({ number: n, title: `t${n}`, body: "## Goal\nx\n\n## Acceptance\n- [ ] works", labels: [], comments: [], author: { login: "me" }, ...o });
|
|
10
|
+
const setup = (issues, o = {}) => {
|
|
11
|
+
const writes = [], models = [], seams = [];
|
|
12
|
+
const io = { now: () => 1e12, gh: async (a) => { writes.push(a); return ""; }, triageClassify: async (i) => { models.push(i.number); return { type: "bug", severity: "P2", migrations: "none", confidence: 0.9, lane_hint: "none", ...o.llm }; }, pause: o.pause,
|
|
13
|
+
claim: () => { seams.push("claim"); throw new Error("claim"); }, launch: () => { seams.push("launch"); throw new Error("launch"); }, batch: { add: () => { seams.push("batch"); throw new Error("batch"); } } };
|
|
14
|
+
return { io, writes, models, seams, run: (extra = {}) => triageTick({ watch: o.watch ?? W(), repo: "o/r", io, state: o.state ?? {}, listOpen: async () => issues, trusted: () => true, ...extra }) };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
test("a new issue gets labels and a text-only FORGE:CLASSIFY comment; no needs-info with acceptance criteria", async () => {
|
|
18
|
+
const s = setup([iss(1)]);
|
|
19
|
+
const r = await s.run();
|
|
20
|
+
assert.equal(r.classified.length, 1);
|
|
21
|
+
const edit = s.writes.find((a) => a[1] === "edit"), com = s.writes.find((a) => a[1] === "comment");
|
|
22
|
+
assert.equal(edit[edit.indexOf("--add-label") + 1], "type:bug,priority:P2");
|
|
23
|
+
const body = com[com.indexOf("--body") + 1];
|
|
24
|
+
assert.match(body, /FORGE:CLASSIFY/);
|
|
25
|
+
const rec = JSON.parse(body.slice(body.indexOf("{"), body.lastIndexOf("}") + 1));
|
|
26
|
+
assert.equal(rec.source, "text-only"); assert.ok(rec.confidence <= 0.5); assert.notEqual(rec.migrations, "none");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("needs-info and lane label: body without criteria, lane_hint release", async () => {
|
|
30
|
+
const s = setup([iss(2, { body: "it is broken" })], { llm: { lane_hint: "release" } });
|
|
31
|
+
await s.run();
|
|
32
|
+
const edit = s.writes.find((a) => a[1] === "edit");
|
|
33
|
+
assert.equal(edit[edit.indexOf("--add-label") + 1], "type:bug,priority:P2,lane:release,needs-info");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("needsInfo: heading or checklist counts, comments do not", () => {
|
|
37
|
+
assert.equal(needsInfo("## Acceptance criteria\nx"), false);
|
|
38
|
+
assert.equal(needsInfo("- [x] done"), false);
|
|
39
|
+
assert.equal(needsInfo("plain"), true);
|
|
40
|
+
assert.equal(needsInfo("<!-- ## Acceptance -->\nplain"), true);
|
|
41
|
+
assert.deepEqual(triageLabels({ type: "chore", severity: "P3", lane_hint: "none" }), ["type:chore", "priority:P3"]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("spies: no claim, launch or batch add, also when the cap is hit", async () => {
|
|
45
|
+
const s = setup([1, 2, 3].map((n) => iss(n)), { watch: W({ "triage.max_per_hour": 1 }) });
|
|
46
|
+
await s.run();
|
|
47
|
+
assert.deepEqual(s.seams, []);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("paused intake: no model call and no write", async () => {
|
|
51
|
+
const s = setup([iss(1)], { pause: async () => ({ reason: "intake paused" }) });
|
|
52
|
+
const r = await s.run();
|
|
53
|
+
assert.ok(r.paused); assert.equal(s.models.length, 0); assert.equal(s.writes.length, 0);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("cap: max_per_hour 2 with 5 issues makes exactly 2 model calls; the rest wait for the next tick", async () => {
|
|
57
|
+
const state = {};
|
|
58
|
+
const s = setup([1, 2, 3, 4, 5].map((n) => iss(n)), { watch: W({ "triage.max_per_hour": 2 }), state });
|
|
59
|
+
await s.run();
|
|
60
|
+
assert.equal(s.models.length, 2);
|
|
61
|
+
await s.run();
|
|
62
|
+
assert.equal(s.models.length, 2, "same hour: still capped");
|
|
63
|
+
s.io.now = () => 1e12 + 3700000;
|
|
64
|
+
await s.run();
|
|
65
|
+
assert.equal(s.models.length, 4);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("policy classify.triage_max_per_hour is the fallback cap", () => {
|
|
69
|
+
assert.equal(maxPerHour(W(), { classify: { triage_max_per_hour: 3 } }), 3);
|
|
70
|
+
assert.equal(maxPerHour(W({ "triage.max_per_hour": 7 }), { classify: { triage_max_per_hour: 3 } }), 7);
|
|
71
|
+
assert.equal(maxPerHour(W(), null), 10);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("idempotent and trust: classified and untrusted issues are skipped", async () => {
|
|
75
|
+
const s = setup([iss(1, { comments: [{ body: "<!-- FORGE:CLASSIFY -->\n{}" }] }), iss(2), iss(3)]);
|
|
76
|
+
await s.run({ trusted: (i) => i.number !== 3 });
|
|
77
|
+
assert.deepEqual(s.models, [2]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("a non-triage watch makes no write and no call", async () => {
|
|
81
|
+
const s = setup([iss(1)], { watch: validateWatch("p", {}) });
|
|
82
|
+
await s.run();
|
|
83
|
+
assert.equal(s.writes.length + s.models.length, 0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("a failing model call is recorded, counted against the cap and does not stop the pass", async () => {
|
|
87
|
+
const s = setup([iss(1), iss(2)]);
|
|
88
|
+
let n = 0; const ok = s.io.triageClassify;
|
|
89
|
+
s.io.triageClassify = async (i) => { if (!n++) throw new Error("boom"); return ok(i); };
|
|
90
|
+
const r = await s.run();
|
|
91
|
+
assert.equal(r.classified.length, 1); assert.equal(r.calls, 2);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("P0 from text alone is clamped to P1", async () => {
|
|
95
|
+
const s = setup([iss(1)], { llm: { severity: "P0" } });
|
|
96
|
+
await s.run();
|
|
97
|
+
assert.match(s.writes.find((a) => a[1] === "edit").join(" "), /priority:P1/);
|
|
98
|
+
});
|
package/bin/lean/issuewatch.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* watches. Selectors, caps and the lane rule are pure functions; gh, the clock and lane/batch launching are injected (`io`).
|
|
8
8
|
* `mode: per-issue` runs `forgedock run-issue` per claim; `mode: batch` `--add`s claims into one long-lived orchestrate
|
|
9
9
|
* batch (batch.mjs `addIssues`, so K, the `Depends on` DAG and the report apply) and starts a new one after it reports.
|
|
10
|
-
* No LLM calls.
|
|
10
|
+
* No LLM calls, except `mode: triage` (#5558, issuewatch-triage.mjs), which only classifies and labels and never claims.
|
|
11
11
|
*/
|
|
12
12
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmdirSync } from "node:fs";
|
|
13
13
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
@@ -19,6 +19,7 @@ import { milestoneSlug, readBranches, isDefaultLane, defaultBranches, DEFAULT_ST
|
|
|
19
19
|
import { postDeployOnly } from "./prefilter.mjs";
|
|
20
20
|
import { designHold } from "./pagegate.mjs"; // #5442
|
|
21
21
|
import { releaseTick, formatDryRun } from "./issuewatch-release.mjs";
|
|
22
|
+
import { triageTick } from "./issuewatch-triage.mjs";
|
|
22
23
|
import { releaseRoot } from "./release.mjs";
|
|
23
24
|
import { loadPolicy } from "./decision-engine.mjs";
|
|
24
25
|
import { decisionContext, decisionsActive, decisionStep, decisionCounts, formatDecisionDryRun, claimsUsed } from "./issuewatch-decisions.mjs";
|
|
@@ -29,7 +30,7 @@ import { listAssociations } from "./gh-assoc.mjs";
|
|
|
29
30
|
import { verifyMerge, verifyComment } from "./issuewatch-verify.mjs";
|
|
30
31
|
import { DEFAULT_SKIP_LABELS, isPullRequest, searchesPullRequests, skipLabelHit, closingPrIssues, releaseInFlight, watchLiveness, alertDeadWatches, resolveOnPath } from "./issuewatch-parity.mjs";
|
|
31
32
|
|
|
32
|
-
const WATCH_KEYS = ["milestone", "labels", "exclude_labels", "search", "title_regex", "since", "version", "lane", "max_issues", "max_inflight", "until", "mode", "parallel", "include_followups", "postdeploy_rollup", "threshold", "immediate", "max_release_issues", "theme_map", "tracker", "sweep_needs_human", "max_launches", "trust_app", "trust_app_labels", "skip_labels", "release_pause", "max_remediations"];
|
|
33
|
+
const WATCH_KEYS = ["milestone", "labels", "exclude_labels", "search", "title_regex", "since", "version", "lane", "max_issues", "max_inflight", "until", "mode", "parallel", "include_followups", "postdeploy_rollup", "threshold", "immediate", "max_release_issues", "theme_map", "tracker", "sweep_needs_human", "max_launches", "trust_app", "trust_app_labels", "skip_labels", "release_pause", "max_remediations", "triage.max_per_hour", "triage"];
|
|
33
34
|
export const TRUSTED = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
34
35
|
const NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
35
36
|
const RETRIES = 3;
|
|
@@ -89,13 +90,19 @@ export function validateWatch(name, cfg = {}) {
|
|
|
89
90
|
sweep_needs_human: cfg.sweep_needs_human === true || String(cfg.sweep_needs_human).toLowerCase() === "true",
|
|
90
91
|
trust_app: cfg.trust_app === true || String(cfg.trust_app).toLowerCase() === "true", trust_app_labels: list(cfg.trust_app_labels),
|
|
91
92
|
skip_labels: cfg.skip_labels === undefined ? (cfg.mode === "batch" ? DEFAULT_SKIP_LABELS : []) : list(cfg.skip_labels), // #5313: the bash watcher's skip list; batch watches take it by default
|
|
92
|
-
release_pause: cfg.release_pause === undefined ? cfg.mode
|
|
93
|
+
release_pause: cfg.release_pause === undefined ? ["batch", "triage"].includes(cfg.mode) : /^true$/i.test(String(cfg.release_pause)) };
|
|
93
94
|
if (cfg.sweep_needs_human !== undefined && !/^(true|false)$/i.test(String(cfg.sweep_needs_human))) throw new Error(`watch ${name}: sweep_needs_human must be true or false`);
|
|
94
95
|
if (cfg.release_pause !== undefined && !/^(true|false)$/i.test(String(cfg.release_pause))) throw new Error(`watch ${name}: release_pause must be true or false`);
|
|
95
96
|
if (searchesPullRequests(w.search)) throw new Error(`watch ${name}: search must not select pull requests (a watch claims issues only)`);
|
|
96
97
|
if (cfg.trust_app !== undefined && !/^(true|false)$/i.test(String(cfg.trust_app))) throw new Error(`watch ${name}: trust_app must be true or false`);
|
|
97
98
|
if (w.trust_app_labels.length && !w.trust_app) throw new Error(`watch ${name}: trust_app_labels needs trust_app: true`);
|
|
98
|
-
if (!["per-issue", "batch", "release"].includes(w.mode)) throw new Error(`watch ${name}: mode must be per-issue, batch or
|
|
99
|
+
if (!["per-issue", "batch", "release", "triage"].includes(w.mode)) throw new Error(`watch ${name}: mode must be per-issue, batch, release or triage`);
|
|
100
|
+
const tcfg = cfg.triage && typeof cfg.triage === "object" ? cfg.triage : {}; // #5558: `triage.max_per_hour` (flat key) or `triage: {max_per_hour: n}`
|
|
101
|
+
const tph = cfg["triage.max_per_hour"] ?? tcfg.max_per_hour;
|
|
102
|
+
for (const k of Object.keys(tcfg)) if (k !== "max_per_hour") throw new Error(`watch ${name}: unknown triage key ${k}`);
|
|
103
|
+
if (tph !== undefined && !(Number.isInteger(Number(tph)) && Number(tph) >= 1)) throw new Error(`watch ${name}: triage.max_per_hour must be a positive integer`);
|
|
104
|
+
if (tph !== undefined && w.mode !== "triage") throw new Error(`watch ${name}: triage.max_per_hour needs mode: triage`);
|
|
105
|
+
w.triage_max_per_hour = tph === undefined ? null : Number(tph);
|
|
99
106
|
if (w.mode === "release") validateRelease(name, cfg, w, int);
|
|
100
107
|
else for (const k of ["threshold", "immediate", "max_release_issues", "theme_map", "tracker"]) if (cfg[k] !== undefined) throw new Error(`watch ${name}: ${k} needs mode: release`);
|
|
101
108
|
if (!["none", "defer-only"].includes(w.include_followups)) throw new Error(`watch ${name}: include_followups must be none or defer-only`);
|
|
@@ -492,6 +499,22 @@ async function releaseStep({ watch, repo, io, state, dir, branches = {}, default
|
|
|
492
499
|
policy: { path: p.policyPath, text: p.policyText }, dryRun });
|
|
493
500
|
}
|
|
494
501
|
|
|
502
|
+
/** `mode: triage` pass (#5558): lists new open issues and hands them to triageTick, which gets no claim, launch or batch seam. */
|
|
503
|
+
async function triageStep({ watch, repo, io, state, defaults = [], cwd = process.cwd() }) {
|
|
504
|
+
let policy = io.triagePolicy ?? null;
|
|
505
|
+
if (!policy) {
|
|
506
|
+
try { const { readPolicy } = await import("./release-config.mjs"); policy = readPolicy({ io: { git: (a) => execFileSync("git", a, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }) }, defaultBranch: defaults[0] ?? "main", cwd }).policy; } catch { /* no policy: defaults */ }
|
|
507
|
+
}
|
|
508
|
+
const args = ["issue", "list", "-R", repo, "--state", "open", "--limit", "100", "--json", "number,title,body,labels,author,createdAt,comments"];
|
|
509
|
+
if (watch.search) args.push("--search", watch.search);
|
|
510
|
+
let assoc = new Map();
|
|
511
|
+
const listOpen = async () => {
|
|
512
|
+
assoc = await listAssociations(io.gh, repo);
|
|
513
|
+
return JSON.parse(String(await io.gh(args))).filter((i) => !isPullRequest(i) && matchesSelectors(i, watch)).map((i) => ({ ...i, authorAssociation: assoc.get(i.number) }));
|
|
514
|
+
};
|
|
515
|
+
return triageTick({ watch, repo, io: { gh: io.gh, now: io.now, triageClassify: io.triageClassify, pause: io.triagePause }, state, listOpen, trusted: (i) => classifyIssue(i, watch) === "claim", policy });
|
|
516
|
+
}
|
|
517
|
+
|
|
495
518
|
/** Append a post-deploy-only follow-up to the rollup issue's checklist, once per follow-up. */
|
|
496
519
|
async function fold({ issue, watch, repo, io, state }) {
|
|
497
520
|
if (state.folded.includes(issue.number)) return;
|
|
@@ -577,12 +600,12 @@ export async function runWatch({ watch, repo, io, dir, branches, defaults, once
|
|
|
577
600
|
await io.sleep(intervalMs); continue;
|
|
578
601
|
}
|
|
579
602
|
state.paused = null;
|
|
580
|
-
if (state.phase === "running" && decisionsActive(watch, ctx.policy)) { // #4793: a failed round must not stop the watch
|
|
603
|
+
if (state.phase === "running" && watch.mode !== "triage" && decisionsActive(watch, ctx.policy)) { // triage never decides or launches (#5558); // #4793: a failed round must not stop the watch
|
|
581
604
|
try { await decisionStep({ watch, repo, io, state, ctx, shared, launch }); state.decisionError = null; } catch (e) { state.decisionError = String(e?.message ?? e).slice(0, 200); }
|
|
582
605
|
}
|
|
583
606
|
let passErr = null;
|
|
584
607
|
try { // #5425: an error in one pass is recorded and shown by `status`; the next pass runs
|
|
585
|
-
if (watch.mode === "release") await releaseStep({ watch, repo, io, state, dir, branches, defaults, cwd }); else await tick({ watch, repo, io, state, dir, branches, defaults, handles });
|
|
608
|
+
if (watch.mode === "triage") await triageStep({ watch, repo, io, state, defaults, cwd }); else if (watch.mode === "release") await releaseStep({ watch, repo, io, state, dir, branches, defaults, cwd }); else await tick({ watch, repo, io, state, dir, branches, defaults, handles });
|
|
586
609
|
state.passError = null;
|
|
587
610
|
} catch (e) {
|
|
588
611
|
passErr = e; state.passError = `${new Date(io.now()).toISOString()} ${String(e?.message ?? e).slice(0, 200)}`;
|
|
@@ -609,6 +632,10 @@ function realIo(repo, env = process.env) {
|
|
|
609
632
|
const prompt = `Classify each GitHub issue into exactly one theme of [${themes.join(", ")}], or "general" when none fits. Reply with only a JSON object {"<number>": "<theme>"}.\n\n${issues.map((i) => `#${i.number} ${i.title}\n${String(i.body ?? "").slice(0, 600)}`).join("\n---\n")}`;
|
|
610
633
|
return JSON.parse(/\{[\s\S]*\}/.exec(execFileSync("claude", ["--print"], { input: prompt, encoding: "utf8", maxBuffer: 8 * 1024 * 1024 }))[0]);
|
|
611
634
|
},
|
|
635
|
+
triageClassify: (issue) => { // #5558: the one small model call of triage mode, text only
|
|
636
|
+
const prompt = `Classify this GitHub issue from its text alone. Reply with only a JSON object {"type":"bug|feature|chore|docs|infra|incident","severity":"P0|P1|P2|P3","lane_hint":"none|release|hotfix|train|integration","confidence":0..1}.\n\n#${issue.number} ${issue.title}\n${String(issue.body ?? "").slice(0, 4000)}`;
|
|
637
|
+
return JSON.parse(/\{[^{}]*\}/.exec(execFileSync("claude", ["--print"], { input: prompt, encoding: "utf8", maxBuffer: CLAUDE_MAX_BUFFER, timeout: JUDGE_TIMEOUT_MS }))[0]);
|
|
638
|
+
},
|
|
612
639
|
judge: ({ decision, options, policy, policyPath, precedent }) => { // #4793: the one LLM judgment of the decision stage
|
|
613
640
|
const prompt = judgePrompt({ decision, options, policy, policyPath, precedent });
|
|
614
641
|
return JSON.parse(/\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}/.exec(execFileSync("claude", ["--print"], { input: prompt, encoding: "utf8", maxBuffer: CLAUDE_MAX_BUFFER, timeout: JUDGE_TIMEOUT_MS }))[0]);
|
|
@@ -737,6 +764,7 @@ export async function issueWatchFromCli(argv, deps = {}) {
|
|
|
737
764
|
return { ok: true };
|
|
738
765
|
}
|
|
739
766
|
const ctx = decisionContext({ loadPolicy, readFile, cwd }), shared = { matches: matchesSelectors, fold, labelNames, isBot, TRUSTED };
|
|
767
|
+
if (argv.includes("--dry-run") && watch.mode === "triage") { print("triage mode: classifies and labels new issues only; a dry run makes no model call and no write"); return { ok: true, dryRun: { triage: true } }; }
|
|
740
768
|
if (argv.includes("--dry-run") && watch.mode !== "release") { // #5088 would-claim/skip with reasons, then #4793 the needs-human classification; nothing written
|
|
741
769
|
const real = deps.io ?? realIo(repo, env), branches = readBranches(cwd);
|
|
742
770
|
const defaults = await defaultBranches({ repo, io: { gh: async (a) => real.gh(a) }, branches });
|
|
@@ -811,3 +811,14 @@ test("#5529 the running watcher records whether it resolves claude and status wa
|
|
|
811
811
|
assert.equal(state.claude, join(bin, "claude"));
|
|
812
812
|
assert.doesNotMatch(formatStatus(state, watch, io.now()), /cannot resolve claude/);
|
|
813
813
|
});
|
|
814
|
+
|
|
815
|
+
test("mode: triage parses, with triage.max_per_hour (flat or nested); other modes are unchanged", () => {
|
|
816
|
+
const w = validateWatch("t", { mode: "triage", "triage.max_per_hour": "4", trust_app: true });
|
|
817
|
+
assert.equal(w.mode, "triage"); assert.equal(w.triage_max_per_hour, 4); assert.equal(w.release_pause, true);
|
|
818
|
+
assert.equal(validateWatch("t", { mode: "triage", triage: { max_per_hour: 2 } }).triage_max_per_hour, 2);
|
|
819
|
+
assert.equal(loadWatches("issue_watch:\n watches:\n t:\n mode: triage\n triage.max_per_hour: 3\n").t.triage_max_per_hour, 3);
|
|
820
|
+
assert.throws(() => validateWatch("t", { mode: "triage", "triage.max_per_hour": 0 }), /positive integer/);
|
|
821
|
+
assert.throws(() => validateWatch("t", { "triage.max_per_hour": 2 }), /needs mode: triage/);
|
|
822
|
+
assert.throws(() => validateWatch("t", { mode: "nope" }), /per-issue, batch, release or triage/);
|
|
823
|
+
assert.equal(validateWatch("t", {}).mode, "per-issue"); assert.equal(validateWatch("t", {}).release_pause, false);
|
|
824
|
+
});
|
package/bin/lean/lanelock.mjs
CHANGED
|
@@ -7,21 +7,22 @@ import { parseState } from "../engine/state.mjs";
|
|
|
7
7
|
import { MAX_LEASE_TTL_MS } from "../engine/projector.mjs";
|
|
8
8
|
|
|
9
9
|
/** The live lease on an issue body held by someone other than `selfId` (null: none, expired, ours or implausibly far out). */
|
|
10
|
-
export function foreignLease(body, { selfId = null, now = Date.now() } = {}) {
|
|
10
|
+
export function foreignLease(body, { selfId = null, selfBatch = null, now = Date.now() } = {}) {
|
|
11
11
|
const l = parseState(body)?.lease;
|
|
12
12
|
if (!l || !Number.isFinite(l.until) || l.until <= now || l.until > now + MAX_LEASE_TTL_MS) return null;
|
|
13
|
+
if (selfBatch && l.batch === selfBatch) return null; // #5654: a run of this same batch (its stale lease), not another lane's
|
|
13
14
|
return l.by && l.by !== selfId ? l : null;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
|
-
* @param {{gh: Function, repo: string, issue: number, branch?: string, selfId?: string|null, ownPr?: number|null, now?: number, checkLease?: boolean, checkPr?: boolean}} a
|
|
18
|
+
* @param {{gh: Function, repo: string, issue: number, branch?: string, selfId?: string|null, selfBatch?: string|null, ownPr?: number|null, now?: number, checkLease?: boolean, checkPr?: boolean}} a
|
|
18
19
|
* @returns {Promise<{kind: "lease"|"pr", detail: string}|null>} null when nothing else owns it or GitHub is unreadable (fail-open)
|
|
19
20
|
*/
|
|
20
|
-
export async function otherLaneOwner({ gh, repo, issue, branch = `feat/issue-${issue}-lean`, selfId = null, ownPr = null, now = Date.now(), checkLease = true, checkPr = true }) {
|
|
21
|
+
export async function otherLaneOwner({ gh, repo, issue, branch = `feat/issue-${issue}-lean`, selfId = null, selfBatch = null, ownPr = null, now = Date.now(), checkLease = true, checkPr = true }) {
|
|
21
22
|
const json = async (args) => { try { return JSON.parse(String(await gh(args))); } catch { return null; } };
|
|
22
23
|
if (checkLease) {
|
|
23
24
|
const iss = await json(["issue", "view", String(issue), "-R", repo, "--json", "body"]);
|
|
24
|
-
const l = foreignLease(iss?.body ?? "", { selfId, now });
|
|
25
|
+
const l = foreignLease(iss?.body ?? "", { selfId, selfBatch, now });
|
|
25
26
|
if (l) return { kind: "lease", detail: `issue ${issue} leased by ${l.by} until ${new Date(l.until).toISOString()}` };
|
|
26
27
|
}
|
|
27
28
|
if (!checkPr) return null;
|