forgedock 1.53.0 → 1.54.1
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/.claude-plugin/marketplace.json +51 -0
- package/README.md +8 -2
- package/bin/auth/app-manifest.mjs +89 -0
- package/bin/auth/app-manifest.test.mjs +75 -0
- package/bin/auth/app-token.mjs +258 -0
- package/bin/auth/app-token.test.mjs +240 -0
- package/bin/brand.mjs +7 -0
- package/bin/config-history.mjs +151 -0
- package/bin/config-schema.mjs +115 -0
- package/bin/demo.mjs +65 -11
- package/bin/engine/outcome-codes.mjs +6 -3
- package/bin/engine/telemetry-seam.mjs +8 -2
- package/bin/engine/telemetry-seam.test.mjs +17 -0
- package/bin/engine-cli.mjs +57 -20
- package/bin/first-run.mjs +122 -0
- package/bin/forgedock.mjs +128 -146
- package/bin/help-text.mjs +144 -0
- package/bin/hooks/pre-tool-use.mjs +7 -0
- package/bin/journey.mjs +82 -83
- package/bin/lean/acceptance.mjs +313 -0
- package/bin/lean/acceptance.test.mjs +215 -0
- package/bin/lean/activation.mjs +18 -0
- package/bin/lean/activation.test.mjs +23 -1
- package/bin/lean/batch-health.mjs +74 -1
- package/bin/lean/batch-health.test.mjs +54 -1
- package/bin/lean/batch.test.mjs +11 -9
- package/bin/lean/branchlock.mjs +54 -0
- package/bin/lean/branchlock.test.mjs +49 -0
- package/bin/lean/ceiling.mjs +72 -0
- package/bin/lean/ceiling.test.mjs +54 -0
- package/bin/lean/ci-budget.mjs +366 -0
- package/bin/lean/ci-budget.test.mjs +167 -0
- package/bin/lean/conformance.e2e.test.mjs +7 -0
- package/bin/lean/conformance.mjs +77 -19
- package/bin/lean/conformance.test.mjs +129 -3
- package/bin/lean/context.mjs +35 -6
- package/bin/lean/context.test.mjs +27 -1
- package/bin/lean/depcache.mjs +25 -1
- package/bin/lean/depcache.test.mjs +26 -0
- package/bin/lean/e2e.mjs +18 -2
- package/bin/lean/e2e.test.mjs +26 -1
- package/bin/lean/effects.mjs +40 -11
- package/bin/lean/execution.test.mjs +24 -0
- package/bin/lean/facts.mjs +3 -3
- package/bin/lean/facts.test.mjs +5 -0
- package/bin/lean/fixround.mjs +14 -0
- package/bin/lean/fixround.test.mjs +25 -2
- package/bin/lean/gh-assoc.test.mjs +2 -1
- package/bin/lean/integration.mjs +100 -9
- package/bin/lean/integration.test.mjs +98 -0
- package/bin/lean/issuewatch-parity.mjs +64 -0
- package/bin/lean/issuewatch-parity.test.mjs +127 -0
- package/bin/lean/issuewatch-release.test.mjs +1 -1
- package/bin/lean/issuewatch.mjs +34 -5
- package/bin/lean/issuewatch.test.mjs +3 -2
- package/bin/lean/lean.mjs +316 -74
- package/bin/lean/lean.test.mjs +397 -24
- package/bin/lean/mechfix.mjs +136 -0
- package/bin/lean/mechfix.test.mjs +95 -0
- package/bin/lean/orchestrate.mjs +20 -2
- package/bin/lean/phaseledger.mjs +47 -5
- package/bin/lean/phaseledger.test.mjs +30 -1
- package/bin/lean/precheck.mjs +23 -4
- package/bin/lean/precheck.test.mjs +14 -1
- package/bin/lean/prereq.mjs +28 -0
- package/bin/lean/prereq.test.mjs +20 -0
- package/bin/lean/probe.mjs +4 -2
- package/bin/lean/prodparity.mjs +52 -0
- package/bin/lean/prodparity.test.mjs +67 -0
- package/bin/lean/prompts.mjs +69 -12
- package/bin/lean/recovery.test.mjs +1 -1
- package/bin/lean/release-io.test.mjs +42 -0
- package/bin/lean/release-postmerge.mjs +6 -0
- package/bin/lean/release-preflight.mjs +58 -0
- package/bin/lean/release-preflight.test.mjs +114 -0
- package/bin/lean/release-rehearsal.mjs +8 -7
- package/bin/lean/release-review.mjs +67 -11
- package/bin/lean/release-review.test.mjs +128 -1
- package/bin/lean/release-snapshot.mjs +188 -0
- package/bin/lean/release-snapshot.test.mjs +190 -0
- package/bin/lean/release.mjs +87 -13
- package/bin/lean/release.test.mjs +104 -0
- package/bin/lean/render.mjs +1 -1
- package/bin/lean/replan.mjs +184 -0
- package/bin/lean/replan.test.mjs +110 -0
- package/bin/lean/resume.mjs +9 -7
- package/bin/lean/resume.test.mjs +16 -0
- package/bin/lean/schedd.mjs +34 -1
- package/bin/lean/schedd.test.mjs +21 -1
- package/bin/lean/selfreview.mjs +94 -0
- package/bin/lean/selfreview.test.mjs +58 -1
- package/bin/lean/selftest-gate.mjs +22 -0
- package/bin/lean/selftest-gate.test.mjs +18 -1
- package/bin/lean/selftest-journey.mjs +234 -0
- package/bin/lean/selftest-journey.test.mjs +130 -0
- package/bin/lean/selftest-live.mjs +2 -1
- package/bin/lean/seqlease.mjs +35 -1
- package/bin/lean/seqlease.test.mjs +15 -0
- package/bin/lean/seqreserve.e2e.test.mjs +135 -0
- package/bin/lean/seqreserve.mjs +73 -0
- package/bin/lean/seqreserve.test.mjs +134 -0
- package/bin/lean/sequence.mjs +35 -6
- package/bin/lean/seqversioned.mjs +147 -0
- package/bin/lean/stagestamp.mjs +28 -0
- package/bin/lean/stagestamp.test.mjs +32 -0
- package/bin/lean/surfaces.mjs +75 -0
- package/bin/lean/surfaces.test.mjs +59 -0
- package/bin/lean/toolplace.mjs +28 -0
- package/bin/lean/toolplace.test.mjs +24 -0
- package/bin/lean/toolstats.mjs +3 -1
- package/bin/lean/toolstats.test.mjs +11 -0
- package/bin/lean/validatebest.mjs +28 -0
- package/bin/lean/validatebest.test.mjs +27 -0
- package/bin/pool/agent.mjs +9 -0
- package/bin/pool/docker.mjs +5 -0
- package/bin/pool/router.mjs +8 -4
- package/bin/prereqs.mjs +111 -0
- package/bin/replay-timelapse.mjs +149 -0
- package/bin/review-staging.mjs +100 -16
- package/bin/review-staging.test.mjs +18 -0
- package/bin/runner.mjs +49 -7
- package/bin/splash-install.mjs +157 -0
- package/bin/stats/aggregate.mjs +8 -1
- package/bin/stats/conformance-outcomes.mjs +100 -19
- package/bin/stats/conformance-outcomes.test.mjs +87 -1
- package/bin/stats/depth.mjs +88 -31
- package/bin/stats/depth.test.mjs +63 -38
- package/bin/stats/efficiency.mjs +26 -5
- package/bin/stats/efficiency.test.mjs +45 -1
- package/bin/stats/first-review.mjs +77 -0
- package/bin/stats/first-review.test.mjs +36 -0
- package/bin/stats/firstmerge.mjs +40 -0
- package/bin/stats/firstmerge.test.mjs +41 -0
- package/bin/stats/github-source.mjs +51 -13
- package/bin/stats/index.mjs +91 -15
- package/bin/stats/local-source.mjs +1 -0
- package/bin/stats/origin.mjs +80 -0
- package/bin/stats/origin.test.mjs +58 -0
- package/bin/stats/render.mjs +3 -1
- package/bin/stats/scoreboard.mjs +137 -0
- package/bin/stats/scoreboard.test.mjs +87 -0
- package/bin/stats/stats.test.mjs +80 -0
- package/bin/tui.mjs +3 -2
- package/commands/bootstrap.md +15 -14
- package/commands/deploy-pr.md +18 -3
- package/commands/forge-stats.md +1 -1
- package/commands/forgedock-ci-setup.md +28 -0
- package/commands/forgedock-init.md +4 -5
- package/commands/issue.md +2 -0
- package/commands/milestone.md +9 -1
- package/commands/replay.md +2 -0
- package/commands/review-pr-staging.md +4 -1
- package/commands/work-on/close.md +8 -0
- package/docs/CI.md +1 -1
- package/docs/CONFIG.md +105 -10
- package/docs/ISSUE-WATCH.md +23 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/REPLAY.md +9 -0
- package/docs/SELFTEST.md +11 -0
- package/docs/STATS.md +19 -2
- package/docs/eval/README.md +6 -0
- package/docs/eval/adversarial-bench.md +68 -0
- package/docs/eval/corpus/adversarial-v1.json +285 -0
- package/docs/eval/feature-bench.md +42 -0
- package/docs/eval/feature-specs/crud-auth/journeys/notes-crud-isolated.mjs +21 -0
- package/docs/eval/feature-specs/crud-auth/journeys/register-login.mjs +12 -0
- package/docs/eval/feature-specs/crud-auth/spec.md +15 -0
- package/docs/site/start-a-new-project.md +2 -1
- package/package.json +5 -2
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +10 -0
- package/plugins/forgedock-splash/README.md +27 -0
- package/plugins/forgedock-splash/hooks/hooks.json +1 -0
- package/plugins/forgedock-splash/hooks/register.tsx +74 -0
- package/plugins/forgedock-splash/hooks/scene.ts +222 -0
- package/plugins/forgedock-splash/types/index.d.ts +10 -0
- package/scripts/bench-adversarial.mjs +216 -0
- package/scripts/bench-feature.mjs +170 -0
- package/scripts/bench-lightlane.mjs +2 -2
- package/scripts/bootstrap-create.mjs +2 -2
- package/scripts/bootstrap-validate.mjs +35 -2
- package/scripts/check-spec-size.sh +4 -3
- package/scripts/check-spec-size.test.sh +3 -0
- package/scripts/plan-validate-live.mjs +40 -6
- package/scripts/review-pr-staging-scope.test.sh +1 -1
- package/scripts/review-staging-post.sh +23 -0
- package/scripts/review-staging-post.test.sh +8 -0
package/bin/lean/context.mjs
CHANGED
|
@@ -38,6 +38,8 @@ export const MAX_LINKS = 20;
|
|
|
38
38
|
export const MAX_LEDGER_PRS = 8;
|
|
39
39
|
/** #4401: FORGE:FACTS records (earlier lanes) read into one pack: this issue's own attempts first, then the file-path ledger. */
|
|
40
40
|
export const MAX_FACT_LANES = 6;
|
|
41
|
+
/** #5340: sibling issues whose comments are read for FORGE:FACTS, and in-flight declarations kept, per pack. */
|
|
42
|
+
export const MAX_SIBLING_READS = 12;
|
|
41
43
|
/** #5085: subject-history bounds per pack: GitHub searches run, rows kept. */
|
|
42
44
|
export const MAX_SUBJECT_QUERIES = 3;
|
|
43
45
|
export const MAX_SUBJECT_ITEMS = 8;
|
|
@@ -65,6 +67,17 @@ export function parseContextPackConfig({ mode, sources, bytes, days, pitfallLane
|
|
|
65
67
|
return { mode: CONTEXT_MODES.includes(m) ? m : "shadow", sources: picked, budgetBytes: pos(bytes, DEFAULT_CONTEXT_BYTES), days: pos(days, DEFAULT_LEDGER_DAYS), pitfallLanes: pos(pitfallLanes, DEFAULT_PITFALL_LANES) };
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
/**
|
|
71
|
+
* #5340: the mode of a lane once its milestone and parent are known. An explicit forge.yaml engine.context_pack (any valid
|
|
72
|
+
* mode, `ab` included) always wins; unset, a lane with a milestone or a parent epic gets `on` so it sees its siblings,
|
|
73
|
+
* and every other lane keeps the shadow default. `cfg` is parseContextPackConfig's result (after any ab arm).
|
|
74
|
+
*/
|
|
75
|
+
export function resolveContextMode(raw, cfg, { milestone = null, parent = null } = {}) {
|
|
76
|
+
const explicit = CONTEXT_MODES.includes(String(raw?.mode ?? "").trim().toLowerCase());
|
|
77
|
+
if (explicit || cfg.mode !== "shadow") return cfg.mode;
|
|
78
|
+
return milestone || parent ? "on" : cfg.mode;
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
/**
|
|
69
82
|
* #4444: the effective mode of one lane. In `ab` the arm comes from a stable hash of `repo#issue`, so every rerun of an
|
|
70
83
|
* issue stays in its arm and the arms are random, matched cohorts per lane type; any other mode passes through.
|
|
@@ -302,8 +315,8 @@ async function recallStatus(io, dirs, index) {
|
|
|
302
315
|
* base ref; `checkout` (the main checkout, optional) is where repo-fact files absent from the worktree are looked up.
|
|
303
316
|
* Every source is independent and best effort: a failing source is listed in `errors` and contributes nothing.
|
|
304
317
|
*/
|
|
305
|
-
export async function gatherContextFacts({ io, repo, issue, iss, comments = [], cwd, checkout = null, base, sources = CONTEXT_SOURCES, days = DEFAULT_LEDGER_DAYS, now = Date.now(), pitfalls = [], recallIndex = RECALL_INDEX }) {
|
|
306
|
-
const facts = { issue: Number(issue), links: [], attempts: [], pitfalls: [], ledger: [], facts: [], lanes: [], errors: [], recall: null };
|
|
318
|
+
export async function gatherContextFacts({ io, repo, issue, iss, comments = [], cwd, checkout = null, base, sources = CONTEXT_SOURCES, days = DEFAULT_LEDGER_DAYS, now = Date.now(), pitfalls = [], recallIndex = RECALL_INDEX, milestone = null }) {
|
|
319
|
+
const facts = { issue: Number(issue), links: [], attempts: [], pitfalls: [], ledger: [], facts: [], lanes: [], siblings: [], inflight: [], errors: [], recall: null };
|
|
307
320
|
const body = String(iss?.body ?? "");
|
|
308
321
|
const on = new Set(sources);
|
|
309
322
|
const step = async (name, fn) => { if (!on.has(name)) return; try { await fn(); } catch (e) { facts.errors.push(`${name}: ${oneLine(e?.message ?? e, 120)}`); } };
|
|
@@ -332,6 +345,7 @@ export async function gatherContextFacts({ io, repo, issue, iss, comments = [],
|
|
|
332
345
|
for (const s of [...new Set(subs)].sort(byNum)) if (s !== Number(issue) && !rel.has(s)) rel.set(s, "sibling");
|
|
333
346
|
} catch (e) { facts.errors.push(`graph: siblings ${oneLine(e?.message ?? e, 80)}`); }
|
|
334
347
|
}
|
|
348
|
+
facts.siblings = [...rel.entries()].filter(([, r]) => r === "sibling").map(([n]) => n);
|
|
335
349
|
const order = { parent: 0, "depends-on": 1, link: 2, "cross-ref": 3, sibling: 4 };
|
|
336
350
|
const picked = [...rel.entries()].sort((a, b) => order[a[1]] - order[b[1]] || a[0] - b[0]).slice(0, MAX_LINKS);
|
|
337
351
|
for (const [n, r] of picked) {
|
|
@@ -435,6 +449,15 @@ export async function gatherContextFacts({ io, repo, issue, iss, comments = [],
|
|
|
435
449
|
facts.lanes.push({ ref, issue: n, pr, ...rec });
|
|
436
450
|
};
|
|
437
451
|
for (const c of [...comments].reverse()) if (trusted(c)) add(parseFactsComment(c?.body), `#${issue} earlier attempt`, Number(issue), null);
|
|
452
|
+
// #5340: siblings first: the FORGE:FACTS of the lane's siblings (same parent, same milestone), whatever files they touched,
|
|
453
|
+
// and what in-flight sibling lanes declared they will add on shared surfaces (host declarations).
|
|
454
|
+
let ms = [];
|
|
455
|
+
if (milestone) { try { ms = JSON.parse(String(await io.gh(["issue", "list", "-R", repo, "--milestone", String(milestone), "--state", "all", "--limit", "40", "--json", "number"]))).map((x) => Number(x?.number)); } catch (e) { facts.errors.push(`facts: milestone ${oneLine(e?.message ?? e, 80)}`); } }
|
|
456
|
+
facts.siblings = [...new Set([...facts.siblings, ...ms])].filter((n) => Number.isSafeInteger(n) && n > 0 && n !== Number(issue)).sort(byNum);
|
|
457
|
+
for (const n of facts.siblings.slice(0, MAX_SIBLING_READS)) {
|
|
458
|
+
try { for (const c of [...(await readComments(io.gh, repo, n))].reverse().filter(trusted)) add(parseFactsComment(c?.body), `#${n} sibling`, n, null); } catch (e) { facts.errors.push(`facts: sibling #${n} ${oneLine(e?.message ?? e, 80)}`); }
|
|
459
|
+
}
|
|
460
|
+
try { facts.inflight = ((await io.declared?.({ repo, except: issue })) ?? []).slice(0, MAX_SIBLING_READS); } catch (e) { facts.errors.push(`facts: in-flight ${oneLine(e?.message ?? e, 80)}`); }
|
|
438
461
|
const overlaps = (files) => files.some((f) => paths.some((p) => f === p || f.startsWith(`${p.replace(/\/+$/, "")}/`) || p.startsWith(`${f}/`)));
|
|
439
462
|
let prs = [];
|
|
440
463
|
try { prs = await ledgerPrs(); } catch (e) { facts.errors.push(`facts: ledger ${oneLine(e?.message ?? e, 80)}`); }
|
|
@@ -463,6 +486,9 @@ const linkLine = (l) => { const fails = (Array.isArray(l.failures) ? l.failures
|
|
|
463
486
|
const pitfallLine = (p) => `- [${p.trigger}] ${oneLine(p.lesson, 160)}${p.globs?.length ? ` (${p.globs.join(", ")})` : ""}; seen ${p.count}×`;
|
|
464
487
|
const ledgerLine = (p) => `- ${p.pr ? `PR #${p.pr}` : "commit"} ${p.sha}${p.revert ? " [revert]" : ""}${p.reverted ? ` [reverted by ${p.reverted}]` : ""} "${p.title}"${p.files?.length ? ` (${p.files.join(", ")})` : ""}${p.notes?.length ? ` — ${p.notes.join("; ")}` : ""}`;
|
|
465
488
|
|
|
489
|
+
/** #5347: the files earlier merged PRs on the issue's symbols touched (the ledger's), unique, at most 8: the builder's cheap answer to "where to look". */
|
|
490
|
+
const packFiles = (facts) => [...new Set((facts.ledger ?? []).flatMap((p) => p.files ?? []))].slice(0, 8);
|
|
491
|
+
|
|
466
492
|
/**
|
|
467
493
|
* The pack text for `facts`, ranked: explicit links (parent > Depends on > body links > cross-references > siblings),
|
|
468
494
|
* prior attempts, recurring pitfalls of the repo (#4375, in the engine's selected order), the symbol ledger (newest first), repo-fact pointers. One line per item; a parent or dependency also
|
|
@@ -479,13 +505,16 @@ export function compileContextPack(facts, { budgetBytes = DEFAULT_CONTEXT_BYTES,
|
|
|
479
505
|
if (on.has("ledger")) for (const p of facts?.ledger ?? []) cand.push({ src: "ledger", line: ledgerLine(p) });
|
|
480
506
|
if (on.has("facts")) {
|
|
481
507
|
// #4401: earlier lanes' facts by kind (rejected approaches first, across lanes), then the repo-fact file pointers
|
|
482
|
-
|
|
483
|
-
for (const
|
|
508
|
+
// #5340: siblings first: what in-flight siblings declared they will add, then merged siblings' facts, then the rest
|
|
509
|
+
for (const d of facts?.inflight ?? []) cand.push({ src: "facts", line: oneLine(`- #${d.issue} (in flight, sibling) will touch shared surface ${(d.surfaces ?? []).join(", ")}${d.paths?.length ? `: ${d.paths.slice(0, 6).join(", ")}` : ""}`) });
|
|
510
|
+
const sib = new Set(facts?.siblings ?? []);
|
|
511
|
+
const all = (facts?.lanes ?? []).map((l) => ({ sib: sib.has(l.issue), lines: factsLines(l, l.ref) }));
|
|
512
|
+
for (const group of [all.filter((l) => l.sib), all.filter((l) => !l.sib)]) for (const k of FACTS_RANK) for (const l of group) for (const line of l.lines[k]) cand.push({ src: "facts", line: oneLine(line) });
|
|
484
513
|
for (const f of facts?.facts ?? []) cand.push({ src: "facts", line: `- ${f} (repo facts file; read it if relevant)` });
|
|
485
514
|
}
|
|
486
515
|
const found = Object.fromEntries(CONTEXT_SOURCES.map((s) => [s, cand.filter((c) => c.src === s).length]));
|
|
487
516
|
const recall = facts?.recall && typeof facts.recall === "object" ? { present: Boolean(facts.recall.present), reason: oneLine(facts.recall.reason ?? "", 80) } : null;
|
|
488
|
-
const empty = { text: "", bytes: 0, items: 0, truncated: 0, sources: Object.fromEntries(CONTEXT_SOURCES.map((s) => [s, 0])), found, hash: null, pitfalls: [], recall };
|
|
517
|
+
const empty = { text: "", bytes: 0, items: 0, truncated: 0, sources: Object.fromEntries(CONTEXT_SOURCES.map((s) => [s, 0])), found, hash: null, pitfalls: [], recall, files: [] };
|
|
489
518
|
if (!cand.length) return empty;
|
|
490
519
|
const titles = { graph: "Linked issues and PRs", attempts: "Prior attempts (this issue and the same subject)", pitfalls: "Recurring pitfalls in this repo (past rework)", ledger: "Merged PRs on the same symbols (reverts, decisions, findings)", facts: "Facts from earlier lanes and repo facts" };
|
|
491
520
|
const head = `Context pack for #${facts.issue}`;
|
|
@@ -506,7 +535,7 @@ export function compileContextPack(facts, { budgetBytes = DEFAULT_CONTEXT_BYTES,
|
|
|
506
535
|
if (rows.length) parts.push(`\n${titles[s]}:`, ...rows.map((r) => r.text));
|
|
507
536
|
}
|
|
508
537
|
const text = parts.join("\n");
|
|
509
|
-
return { text, bytes: size(text), items: kept.length, truncated, sources: Object.fromEntries(CONTEXT_SOURCES.map((s) => [s, kept.filter((k) => k.src === s).length])), found, hash: hash12(text), pitfalls: kept.filter((k) => k.pit).map((k) => k.pit), recall };
|
|
538
|
+
return { text, bytes: size(text), items: kept.length, truncated, sources: Object.fromEntries(CONTEXT_SOURCES.map((s) => [s, kept.filter((k) => k.src === s).length])), found, hash: hash12(text), pitfalls: kept.filter((k) => k.pit).map((k) => k.pit), recall, files: packFiles(facts) };
|
|
510
539
|
}
|
|
511
540
|
|
|
512
541
|
/** The pack text without its pitfalls section (#4375: pitfalls are local only and never posted). */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { normaliseFacts, renderFactsRecord, FACTS_MARKER } from "./facts.mjs";
|
|
6
|
-
import { closedResult, gatherContextFacts, compileContextPack, contextPackFor, contextArm, contextPackCacheKey, linkStateStamp, LINK_STAMP_MAX, parseContextPackConfig, laneType, priorAttempts, issueSymbols, bodyLinks, parentOf, renderContextRecord, DEFAULT_CONTEXT_BYTES, noComments, subjectTerms, subjectHistory, MAX_SUBJECT_ITEMS, MAX_SUBJECT_QUERIES } from "./context.mjs";
|
|
6
|
+
import { closedResult, gatherContextFacts, compileContextPack, contextPackFor, contextArm, contextPackCacheKey, linkStateStamp, LINK_STAMP_MAX, parseContextPackConfig, resolveContextMode, laneType, priorAttempts, issueSymbols, bodyLinks, parentOf, renderContextRecord, DEFAULT_CONTEXT_BYTES, noComments, subjectTerms, subjectHistory, MAX_SUBJECT_ITEMS, MAX_SUBJECT_QUERIES } from "./context.mjs";
|
|
7
7
|
|
|
8
8
|
const REPO = "o/r";
|
|
9
9
|
const BOT = { author_association: "NONE", user: { type: "Bot", login: "forge[bot]" } };
|
|
@@ -35,6 +35,7 @@ function fakes(o = {}) {
|
|
|
35
35
|
102: [],
|
|
36
36
|
103: [{ id: 3, body: "<!-- FORGE:DECISION -->\nUnrelated decision about logging.", ...BOT }],
|
|
37
37
|
33: [{ id: 4, body: "<!-- FORGE:CONTRACT -->\nx", ...BOT }, ...(o.facts33 ?? [])],
|
|
38
|
+
51: o.facts51 ?? [],
|
|
38
39
|
};
|
|
39
40
|
const prs = { 101: { title: "feat: ranking", body: "Closes #33", head: "feat/issue-33-lean" }, 102: { title: "feat: speedup", body: "", head: "feat/issue-34-lean" }, 103: { title: "chore: logs", body: "", head: "x" } };
|
|
40
41
|
const log = [
|
|
@@ -595,3 +596,28 @@ describe("#5152 builder context: delivered or moved scope never reads as dropped
|
|
|
595
596
|
assert.equal(closedResult({ stateReason: null }), "closed");
|
|
596
597
|
});
|
|
597
598
|
});
|
|
599
|
+
|
|
600
|
+
describe("#5340 sibling-aware context", () => {
|
|
601
|
+
const base = (raw) => parseContextPackConfig(raw ?? {});
|
|
602
|
+
it("a milestone or parent lane defaults to on; explicit modes win; other lanes stay shadow; the parse default is unchanged", () => {
|
|
603
|
+
assert.equal(parseContextPackConfig({}).mode, "shadow");
|
|
604
|
+
assert.equal(resolveContextMode(undefined, base(), { milestone: "M1" }), "on");
|
|
605
|
+
assert.equal(resolveContextMode({}, base(), { parent: 7 }), "on");
|
|
606
|
+
assert.equal(resolveContextMode(undefined, base(), {}), "shadow");
|
|
607
|
+
for (const mode of ["shadow", "off", "ab"]) assert.equal(resolveContextMode({ mode }, base({ mode }), { milestone: "M1" }), mode);
|
|
608
|
+
});
|
|
609
|
+
it("sibling facts and in-flight declarations rank before other lanes' facts; milestone issues are read", async () => {
|
|
610
|
+
const rec = (file, approach) => `<!-- ${FACTS_MARKER} -->\n${renderFactsRecord(normaliseFacts({ facts: { rejected: [{ approach, why: "w" }], hotspots: [{ at: `${file}:1`, why: "h" }] } }, { files: [file] }))}`;
|
|
611
|
+
const BOTC = { author: { login: "forge[bot]" }, authorAssociation: "NONE" };
|
|
612
|
+
const f = fakes({ facts33: [{ id: 5, body: rec("bin/lean/context.mjs", "overlap approach"), ...BOTC }], facts51: [{ id: 6, body: rec("other/file.md", "sibling approach"), ...BOTC }] });
|
|
613
|
+
const gh = f.io.gh;
|
|
614
|
+
f.io.gh = async (a) => (a[0] === "issue" && a[1] === "list" ? JSON.stringify([{ number: 52 }]) : gh(a));
|
|
615
|
+
f.io.declared = async () => [{ issue: 62, surfaces: ["api/routes.ts"], paths: ["api/routes.ts"] }];
|
|
616
|
+
const facts = await gather(f, { milestone: "M1" });
|
|
617
|
+
assert.ok(facts.siblings.includes(51) && facts.siblings.includes(52));
|
|
618
|
+
const t = compileContextPack(facts).text;
|
|
619
|
+
const at = (s) => { const i = t.indexOf(s); assert.ok(i >= 0, `missing ${s}\n${t}`); return i; };
|
|
620
|
+
assert.ok(at("#62 (in flight, sibling) will touch shared surface api/routes.ts") < at("sibling approach"));
|
|
621
|
+
assert.ok(at("sibling approach") < at("overlap approach"), t);
|
|
622
|
+
});
|
|
623
|
+
});
|
package/bin/lean/depcache.mjs
CHANGED
|
@@ -57,6 +57,26 @@ function detect(fs, wt) {
|
|
|
57
57
|
}
|
|
58
58
|
if (has("uv.lock")) out.push({ eco: "uv", lock: "uv.lock" });
|
|
59
59
|
else if (has("poetry.lock")) out.push({ eco: "poetry", lock: "poetry.lock" });
|
|
60
|
+
else out.push(...serviceLocks(fs, wt));
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const SERVICE_ROOTS = ["services", "packages", "apps"];
|
|
65
|
+
const SERVICE_CAP = 8;
|
|
66
|
+
/** #5331: Python lockfiles one level down (services/<name>/uv.lock|poetry.lock) when the root has none; each is prepared in its own dir. */
|
|
67
|
+
function serviceLocks(fs, wt) {
|
|
68
|
+
const out = [];
|
|
69
|
+
for (const root of SERVICE_ROOTS) {
|
|
70
|
+
let names = [];
|
|
71
|
+
try { names = fs.readdirSync(join(wt, root)).sort(); } catch { continue; }
|
|
72
|
+
for (const n of names) {
|
|
73
|
+
const dir = `${root}/${n}`;
|
|
74
|
+
for (const [eco, lock] of [["uv", "uv.lock"], ["poetry", "poetry.lock"]]) {
|
|
75
|
+
if (out.length >= SERVICE_CAP) return out;
|
|
76
|
+
try { if (fs.existsSync(join(wt, dir, lock))) { out.push({ eco, lock, dir }); break; } } catch { /* unreadable: skip */ }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
60
80
|
return out;
|
|
61
81
|
}
|
|
62
82
|
|
|
@@ -108,6 +128,7 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
108
128
|
|
|
109
129
|
async function keyOf(wt, d, pkgs) {
|
|
110
130
|
const h = createHash("sha256").update(`v1\0${d.eco}\0${process.platform}-${process.arch}\0`);
|
|
131
|
+
if (d.dir) h.update(`${d.dir}\0`);
|
|
111
132
|
h.update(await runtime(JS.has(d.eco) ? "node" : "python3")).update("\0");
|
|
112
133
|
const files = JS.has(d.eco) ? [d.lock, ...pkgs, "pnpm-workspace.yaml", ".npmrc", ".yarnrc.yml"] : [d.lock, "pyproject.toml", ".python-version"];
|
|
113
134
|
for (const f of files) {
|
|
@@ -281,7 +302,10 @@ export function makeDepCache({ root = depcacheRoot(), exec, fs = nodeFs, now = (
|
|
|
281
302
|
const keyRoot = join(root, safeSegment(repoKey ?? "repo"));
|
|
282
303
|
const out = [];
|
|
283
304
|
for (const d of found) {
|
|
284
|
-
try {
|
|
305
|
+
try {
|
|
306
|
+
const r = await prepareOne(d.dir ? join(wt, d.dir) : wt, keyRoot, d, laneEnv && typeof laneEnv === "object" ? laneEnv : undefined);
|
|
307
|
+
out.push(d.dir ? { ...r, dir: d.dir } : r);
|
|
308
|
+
} catch (e) { out.push({ status: "failed", eco: d.eco, key: null, ms: 0, reason: msg(e) }); }
|
|
285
309
|
}
|
|
286
310
|
return out;
|
|
287
311
|
}
|
|
@@ -423,3 +423,29 @@ describe("depcache (#4347): installs and repairs run with the lane toolchain env
|
|
|
423
423
|
assert.equal(seen[1].env.npm_config_cache, cache.env().npm_config_cache);
|
|
424
424
|
});
|
|
425
425
|
});
|
|
426
|
+
|
|
427
|
+
describe("depcache (#5331): per-service Python lockfiles", () => {
|
|
428
|
+
for (const eco of ["poetry", "uv"]) {
|
|
429
|
+
it(`services/<name>/${eco === "uv" ? "uv" : "poetry"}.lock is prepared in its own dir, never "skipped: no lockfile"`, async () => {
|
|
430
|
+
const { cache, lane, base } = setup(eco);
|
|
431
|
+
const wt = join(base, "wt", "svc");
|
|
432
|
+
mkdirSync(wt, { recursive: true });
|
|
433
|
+
FIXTURES[eco](join(wt, "services/api"));
|
|
434
|
+
const res = await cache.prepare({ wt, repoKey: "repo-svc" });
|
|
435
|
+
assert.equal(res.length, 1, JSON.stringify(res));
|
|
436
|
+
assert.notEqual(res[0].reason, "no lockfile");
|
|
437
|
+
assert.equal(res[0].eco, eco);
|
|
438
|
+
assert.equal(res[0].dir, "services/api");
|
|
439
|
+
assert.ok(["miss-installed", "hit"].includes(res[0].status), JSON.stringify(res[0]));
|
|
440
|
+
assert.ok(existsSync(join(wt, "services/api/.venv")));
|
|
441
|
+
void lane;
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
it("a repo with no lockfile anywhere is still skipped", async () => {
|
|
445
|
+
const { cache, base } = setup("poetry");
|
|
446
|
+
const wt = join(base, "wt", "none");
|
|
447
|
+
mkdirSync(join(wt, "services/api"), { recursive: true });
|
|
448
|
+
const [r] = await cache.prepare({ wt, repoKey: "repo-none" });
|
|
449
|
+
assert.equal(r.reason, "no lockfile");
|
|
450
|
+
});
|
|
451
|
+
});
|
package/bin/lean/e2e.mjs
CHANGED
|
@@ -34,19 +34,35 @@ export function parseE2e(sec = {}) {
|
|
|
34
34
|
|
|
35
35
|
/** Changed files (minus the engine's hand-off files) that are e2e specs per `cfg.paths`. */
|
|
36
36
|
export const e2eSpecs = (files, cfg = parseE2e({})) => verifiableFiles(files).filter((f) => (cfg.paths ?? []).some((g) => matchesGlob(f, g)));
|
|
37
|
-
/** True when a contract requirement quote carries a `[type:e2e]` criterion. */
|
|
38
|
-
export const contractWantsE2e = (contract) => (Array.isArray(contract?.requirements) ? contract.requirements : []).some((r) => /\[type:e2e\]/i.test(String(r?.quote ?? "")));
|
|
37
|
+
/** True when a contract requirement quote carries a `[type:e2e]` or `[type:manual]` criterion (#5339). */
|
|
38
|
+
export const contractWantsE2e = (contract) => (Array.isArray(contract?.requirements) ? contract.requirements : []).some((r) => /\[type:(?:e2e|manual)\]/i.test(String(r?.quote ?? "")));
|
|
39
|
+
|
|
40
|
+
/** #5339: markers of a test that fakes the thing it claims to prove (mocked modules, patched I/O, fake/stub fixtures). */
|
|
41
|
+
const FAKE_RE = /\b(?:vi|jest)\.(?:mock|fn|spyOn)\(|\bmonkeypatch\b|\bunittest\.mock\b|\bmock\.patch\b|\bMagicMock\b|\bsinon\.stub\b|\b(?:fake|mock|stub)[_-]?[a-z]\w*|\b(?:Fake|Mock|Stub)[A-Z]\w*/i;
|
|
42
|
+
/** #5339: the `paths` whose content (via `read`) carries a fake marker; an unreadable path is not faked. Deterministic, no model call. */
|
|
43
|
+
export function fakedPaths(paths, read) {
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const p of paths ?? []) { let t = null; try { t = read(p); } catch { /* unreadable */ } if (typeof t === "string" && FAKE_RE.test(t)) out.push(p); }
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const UI_FILE_RE = /\.(?:tsx|jsx|vue|svelte)$/i;
|
|
50
|
+
const UI_INTERACTIVE_RE = /(?:dialog|modal|popover|drawer|cta|button|menu|trigger|layout|hero|header|nav)/i;
|
|
51
|
+
/** #5285: changed non-test UI component files that alter interactive elements (dialogs, CTAs, layout containers); jsdom cannot see layout or clicks. */
|
|
52
|
+
export const uiInteractiveChanged = (files) => verifiableFiles(files).filter((f) => UI_FILE_RE.test(f) && UI_INTERACTIVE_RE.test(f) && !/\.(?:test|spec|stories)\./i.test(f));
|
|
39
53
|
|
|
40
54
|
/** Whether this lane runs the e2e gate: {run, reason, specs}. */
|
|
41
55
|
export function e2eWanted({ cfg, files, contract } = {}) {
|
|
42
56
|
const c = cfg ?? parseE2e({});
|
|
43
57
|
const specs = e2eSpecs(files, c);
|
|
58
|
+
const ui = uiInteractiveChanged(files);
|
|
44
59
|
if (c.mode === "never") return { run: false, reason: "verify.e2e: never", specs };
|
|
45
60
|
if (!c.label && !c.workflow) return { run: false, reason: NO_TRIGGER, specs };
|
|
46
61
|
if (c.mode === "always") {
|
|
47
62
|
return skipsCi(files, DEFAULT_SKIP_PATHS) ? { run: false, reason: "docs-only change", specs } : { run: true, reason: "verify.e2e: always", specs };
|
|
48
63
|
}
|
|
49
64
|
if (specs.length) return { run: true, reason: `${specs.length} e2e spec(s) changed`, specs };
|
|
65
|
+
if (ui.length) return { run: true, reason: `interactive UI changed (${ui.slice(0, 3).join(", ")}): real-browser check`, specs, ui };
|
|
50
66
|
if (contractWantsE2e(contract)) return { run: true, reason: "contract has [type:e2e] criteria", specs };
|
|
51
67
|
return { run: false, reason: "no e2e spec changed and no [type:e2e] criteria", specs };
|
|
52
68
|
}
|
package/bin/lean/e2e.test.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { parseE2e, e2eSpecs, contractWantsE2e, e2eWanted, ownFailures, runE2eGate, E2E_DEFAULT_PATHS, NO_TRIGGER } from "./e2e.mjs";
|
|
5
|
+
import { parseE2e, e2eSpecs, contractWantsE2e, e2eWanted, uiInteractiveChanged, ownFailures, runE2eGate, fakedPaths, E2E_DEFAULT_PATHS, NO_TRIGGER } from "./e2e.mjs";
|
|
6
6
|
import { VERIFY_CHECK_NAME } from "./verify.mjs";
|
|
7
7
|
|
|
8
8
|
const HEAD = "abc123abc123abc123";
|
|
@@ -84,3 +84,28 @@ describe("runE2eGate (#4403)", () => {
|
|
|
84
84
|
assert.deepEqual(f.dispatched, [{ workflow: "e2e.yml", ref: "feat/issue-7-lean", inputs: { specs: "e2e/a.spec.ts" } }]);
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
|
+
|
|
88
|
+
describe("interactive UI real-browser check (#5285)", () => {
|
|
89
|
+
const cfg = { ...parseE2e({ e2e_label: "e2e" }) };
|
|
90
|
+
it("flags dialog/CTA/layout components, not tests or plain logic", () => {
|
|
91
|
+
assert.deepEqual(uiInteractiveChanged(["web/components/SignupDialog.tsx", "web/components/SignupDialog.test.tsx", "web/lib/price.ts"]), ["web/components/SignupDialog.tsx"]);
|
|
92
|
+
});
|
|
93
|
+
it("e2eWanted runs the gate for an interactive UI change when a trigger is configured; skips with a reason otherwise", () => {
|
|
94
|
+
const w = e2eWanted({ cfg, files: ["web/components/HeroCta.tsx"] });
|
|
95
|
+
assert.equal(w.run, true);
|
|
96
|
+
assert.match(w.reason, /real-browser/);
|
|
97
|
+
assert.equal(e2eWanted({ cfg: parseE2e({}), files: ["web/components/HeroCta.tsx"] }).run, false);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("fakedPaths and [type:manual] (#5339)", () => {
|
|
102
|
+
it("flags test files that fake or mock the real path, not clean ones or unreadable ones", () => {
|
|
103
|
+
const files = { "a.test.mjs": "const depts = fake_departments();", "b.test.mjs": "vi.mock('./render')", "c.e2e.mjs": "await page.goto(url); expect(film).toExist()", "d.py": "def test(monkeypatch): ..." };
|
|
104
|
+
const read = (p) => { if (!(p in files)) throw new Error("ENOENT"); return files[p]; };
|
|
105
|
+
assert.deepEqual(fakedPaths(["a.test.mjs", "b.test.mjs", "c.e2e.mjs", "d.py", "gone.mjs"], read), ["a.test.mjs", "b.test.mjs", "d.py"]);
|
|
106
|
+
});
|
|
107
|
+
it("contractWantsE2e covers manual", () => {
|
|
108
|
+
assert.equal(contractWantsE2e({ requirements: [{ quote: "Restore works [type:manual]" }] }), true);
|
|
109
|
+
assert.equal(contractWantsE2e({ requirements: [{ quote: "Restore works [type:unit]" }] }), false);
|
|
110
|
+
});
|
|
111
|
+
});
|
package/bin/lean/effects.mjs
CHANGED
|
@@ -23,6 +23,8 @@ import { duplicateExports } from "./postmerge.mjs";
|
|
|
23
23
|
import { englishCopies } from "./i18n.mjs";
|
|
24
24
|
import { scopedChecks } from "./checks.mjs";
|
|
25
25
|
import { makeSequenceLeaseIo } from "./seqlease.mjs";
|
|
26
|
+
import { reserveForBuild } from "./seqreserve.mjs";
|
|
27
|
+
import { parseVersioned } from "./seqversioned.mjs";
|
|
26
28
|
import { followupMap } from "./conformance.mjs";
|
|
27
29
|
import { toolStats } from "./toolstats.mjs";
|
|
28
30
|
import { detectApiShape } from "./apishape.mjs";
|
|
@@ -110,7 +112,7 @@ export const leanSettingsFlags = ({ subagentModel = null, reread = false, guard
|
|
|
110
112
|
};
|
|
111
113
|
|
|
112
114
|
export function makeLeanRunner({ runCli = runCliBackendAsync, probe = systemdRunAvailable, subagentModel = null, sandboxed = inSandbox() } = {}) {
|
|
113
|
-
return async ({ role, issue, cwd, model, resume, system, prompt, readOnly = false, noTools = false, rereadNudge = false, maxTurns = null, agents = null, env = null, idleMs = 0, maxMs = 0, laneLimits = null, control = null, onSpawn = null, contextMax = 0, turnMax = 0, busy = null, busyMs = 0, onIdleExtend = null, bin: pinnedBin = null }) => {
|
|
115
|
+
return async ({ role, issue, cwd, model, resume, system, prompt, readOnly = false, noTools = false, rereadNudge = false, maxTurns = null, agents = null, env = null, idleMs = 0, maxMs = 0, laneLimits = null, control = null, onSpawn = null, session = null, contextMax = 0, turnMax = 0, busy = null, busyMs = 0, onIdleExtend = null, bin: pinnedBin = null }) => {
|
|
114
116
|
// #5205: a rotation relaunch pins the real claude past the tokenbaton shim; absent, the usual resolution
|
|
115
117
|
const bin = pinnedBin || resolveClaudeCliBinary(cwd) || "claude";
|
|
116
118
|
const caps = getClaudeCliCapabilities(cwd);
|
|
@@ -122,7 +124,7 @@ export function makeLeanRunner({ runCli = runCliBackendAsync, probe = systemdRun
|
|
|
122
124
|
const r = await runCli({ spec: { name: `core-${role}` }, userMessage: prompt, systemPrompt: resume ? "" : system,
|
|
123
125
|
args: [String(issue)], cwd, bin, model, maxTurns: caps?.maxTurns ? maxTurns : null, env, sessionFlags: flags, extraArgs: [...(resume ? ["--resume", resume] : []), ...settings],
|
|
124
126
|
logger: { log() {} },
|
|
125
|
-
idleMs, maxMs, stream: idleMs > 0, control, onSpawn, busy, busyMs, onIdleExtend, ...(contextMax > 0 ? { contextMax } : {}), ...(turnMax > 0 ? { turnMax } : {}), wrap: probe() ? (b, a) => wrapLaneLimits(b, a, laneLimits) : null });
|
|
127
|
+
idleMs, maxMs, stream: idleMs > 0, control, onSpawn, session, busy, busyMs, onIdleExtend, ...(contextMax > 0 ? { contextMax } : {}), ...(turnMax > 0 ? { turnMax } : {}), wrap: probe() ? (b, a) => wrapLaneLimits(b, a, laneLimits) : null });
|
|
126
128
|
// #4395: a resumed session's first turn carries the prior history, so only a fresh session reports a baseline.
|
|
127
129
|
return { text: r.text, sessionId: r.sessionId, usage: r.usage, costUsd: r.costUsd, durationMs: r.durationMs, turns: r.turns, model: r.cliModel ?? "default",
|
|
128
130
|
baselineTokens: resume ? null : (r.baselineTokens ?? null), tools: toolStats(r.toolUses) }; // #4410: tool calls per turn, re-reads
|
|
@@ -241,9 +243,10 @@ export function makeHostProbe() {
|
|
|
241
243
|
/**
|
|
242
244
|
* Required status checks for `lane` (#4158): the union of classic branch protection (contexts + checks) and the
|
|
243
245
|
* repository rulesets that apply to the branch (`rules/branches/{lane}`, type required_status_checks). Each source
|
|
244
|
-
* fails independently to [] (
|
|
246
|
+
* fails independently to [] (so one never hides the other); `unreadable` is set when a source failed for a reason other than a 404 (#5382).
|
|
247
|
+
* `requiredChecksFor` is the names only.
|
|
245
248
|
*/
|
|
246
|
-
export async function
|
|
249
|
+
export async function requiredChecksRead({ gh, repo, lane }) {
|
|
247
250
|
const classic = async () => {
|
|
248
251
|
const j = JSON.parse(String(await gh(["api", `repos/${repo}/branches/${lane}/protection/required_status_checks`])));
|
|
249
252
|
return [...(j.contexts ?? []), ...(j.checks ?? []).map((c) => c?.context)];
|
|
@@ -254,11 +257,15 @@ export async function requiredChecksFor({ gh, repo, lane }) {
|
|
|
254
257
|
"--jq", '.[] | select(.type == "required_status_checks") | .parameters.required_status_checks[]?.context']));
|
|
255
258
|
return out.split("\n").map((x) => x.trim());
|
|
256
259
|
};
|
|
257
|
-
|
|
260
|
+
// A 404 is an answer (no protection, no rulesets); any other failure (403 for a non-admin token, network) is an unreadable source.
|
|
261
|
+
let unreadable = false;
|
|
262
|
+
const safe = async (f) => { try { const v = await f(); return Array.isArray(v) ? v : []; } catch (e) { if (!/\b404\b|not found|not protected/i.test(String(e?.message ?? e))) unreadable = true; return []; } };
|
|
258
263
|
const all = [...(await safe(classic)), ...(await safe(rulesets))];
|
|
259
|
-
return [...new Set(all.filter((x) => typeof x === "string" && x))];
|
|
264
|
+
return { checks: [...new Set(all.filter((x) => typeof x === "string" && x))], unreadable };
|
|
260
265
|
}
|
|
261
266
|
|
|
267
|
+
export const requiredChecksFor = async (opts) => (await requiredChecksRead(opts)).checks;
|
|
268
|
+
|
|
262
269
|
/** Combined stdout+stderr kept per declared check command (tail). */
|
|
263
270
|
const CHECK_OUTPUT_CAP = 64000;
|
|
264
271
|
/** #4240: run a forge.yaml declared check command locally (no gh, no Actions); {rc, output}, rc 124 on timeout. `env` (#4323) is merged over process.env. */
|
|
@@ -307,7 +314,16 @@ export function makeGhCache({ root = null, tmp = tmpdir() } = {}) {
|
|
|
307
314
|
|
|
308
315
|
export function makeLeanIo({ repo, subagentModel = readSubagentModel() }) {
|
|
309
316
|
const base = makeIo();
|
|
317
|
+
const seqLeaseIo = makeSequenceLeaseIo(); // #5340: one instance: sequence leases, surface leases and declarations
|
|
310
318
|
const run = (bin) => async (args, opts = {}) => (await pexec(bin, args, { cwd: opts.cwd, maxBuffer: 100 * 1024 * 1024, timeout: 120000, ...(opts.env ? { env: { ...process.env, ...opts.env } } : {}) })).stdout;
|
|
319
|
+
/** #5235: paths the other open PRs on `lane` carry (gh only, no fetch); [] on any failure. */
|
|
320
|
+
const openPrFiles = async (cwd, lane) => {
|
|
321
|
+
try {
|
|
322
|
+
const me = String(await run("git")(["rev-parse", "--abbrev-ref", "HEAD"], { cwd })).trim();
|
|
323
|
+
const prs = JSON.parse(await run("gh")(["pr", "list", "--state", "open", "--base", lane, "--limit", "100", "--json", "headRefName,files"], { cwd }));
|
|
324
|
+
return prs.filter((p) => p?.headRefName !== me).flatMap((p) => (p?.files ?? []).map((f) => String(f?.path ?? "")));
|
|
325
|
+
} catch { return []; }
|
|
326
|
+
};
|
|
311
327
|
return {
|
|
312
328
|
ghCache: (root) => makeGhCache({ root }),
|
|
313
329
|
gh: run("gh"), git: run("git"), docker: run("docker"), killGroup: async (pid, marker) => killLedgerPid(pid, marker), ledger: (opts) => makeLedger(opts), runTmp: makeRunTmp(), host: makeHostProbe(), heavy: makeHeavyIo({ host: makeHostProbe() }), projector: makeProjector({ gh: base.gh }, { repo }), runner: makeLeanRunner({ subagentModel }), waitCiGreen: base.waitCiGreen,
|
|
@@ -409,7 +425,7 @@ export function makeLeanIo({ repo, subagentModel = readSubagentModel() }) {
|
|
|
409
425
|
/** #4375: the repo's learned-pitfall ledger, local only (~/.forge/pitfalls, FORGE_PITFALLS_DIR). */
|
|
410
426
|
pitfalls: makePitfallStore(),
|
|
411
427
|
/** forge#4275: the context pack's facts for one issue (bin/lean/context.mjs), from gh and git only; sources fail independently. */
|
|
412
|
-
contextFacts: (args) => gatherContextFacts({ ...args, io: { gh: run("gh"), git: run("git"), exists: async (p) => existsSync(p) } }),
|
|
428
|
+
contextFacts: (args) => gatherContextFacts({ ...args, io: { gh: run("gh"), git: run("git"), exists: async (p) => existsSync(p), declared: (a) => seqLeaseIo.declared(a) } }), // #5340: in-flight sibling declarations
|
|
413
429
|
/** forge#4195: scripts/hotspots.sh facts for `paths` in cwd (growth since base when given; config = the host forge.yaml, #5163); null on any failure. */
|
|
414
430
|
async hotspots({ cwd, base = null, paths = [], config = null }) {
|
|
415
431
|
const args = [script("hotspots.sh"), ...(config ? ["--config", config] : []), ...(base ? ["--base", base] : []), "--", ...paths];
|
|
@@ -419,11 +435,24 @@ export function makeLeanIo({ repo, subagentModel = readSubagentModel() }) {
|
|
|
419
435
|
enumeratingTests: ({ cwd, paths = [] }) => enumeratingTests({ git: (a) => run("git")(a, { cwd }), cwd, paths }),
|
|
420
436
|
enumeratingMissing: ({ cwd, base }) => missingEntries({ git: (a) => run("git")(a, { cwd }), cwd, base }),
|
|
421
437
|
/** #4322: sequence-numbered files the lane shares with the base (bin/lean/sequence.mjs); snapshot before, verify after a renumber. */
|
|
422
|
-
|
|
438
|
+
// #5340: also against the default branch(es) in `extraBases`, which a milestone lane would otherwise not see
|
|
439
|
+
sequenceCheck: async ({ cwd, base, extraBases = [], versioned }) => {
|
|
440
|
+
const git = (a) => run("git")(a, { cwd });
|
|
441
|
+
const out = [...(await sequenceCollisions({ git, base, versioned }))];
|
|
442
|
+
for (const b of extraBases) { try { out.push(...(await sequenceCollisions({ git, base: b, versioned }))); } catch { /* fail-open */ } }
|
|
443
|
+
return out;
|
|
444
|
+
},
|
|
423
445
|
sequenceSnapshot: ({ cwd, base }) => snapshotLane({ git: (a) => run("git")(a, { cwd }), base }),
|
|
424
|
-
sequenceVerify: ({ cwd, base, before, moves }) => verifyRenumber({ git: (a) => run("git")(a, { cwd }), base, before, moves }),
|
|
446
|
+
sequenceVerify: ({ cwd, base, before, moves, versioned }) => verifyRenumber({ git: (a) => run("git")(a, { cwd }), base, before, moves: moves?.filter((m) => !m.versioned), versioned }),
|
|
425
447
|
/** #4386: the deterministic renumber, sequence-only base-sync resolution, and the host sequence lease at the merge gate. */
|
|
426
|
-
sequenceRenumber: ({ cwd, base, laneRef, regenerate, reserve, openNumbers }) => renumberLane({ git: (a) => run("git")(a, { cwd }), base, cwd, laneRef, regenerate, reserve, openNumbers }),
|
|
448
|
+
sequenceRenumber: ({ cwd, base, laneRef, regenerate, reserve, openNumbers, versioned }) => renumberLane({ git: (a) => run("git")(a, { cwd }), base, cwd, laneRef, regenerate, reserve, openNumbers, versioned }),
|
|
449
|
+
/** #5235: reserve the numbers / versions the frozen contract's deliverables need before the build (bin/lean/seqreserve.mjs); [] on failure. */
|
|
450
|
+
sequenceReserveBuild: ({ cwd, base, lane, repo, issue, deliverables, versioned }) => reserveForBuild({
|
|
451
|
+
git: (a) => run("git")(a, { cwd }), base, deliverables, versioned,
|
|
452
|
+
reserve: (x) => seqLeaseIo.reserve({ repo, lane, issue, ...x }),
|
|
453
|
+
openNumbers: async ({ dir }) => (await openPrFiles(cwd, lane)).filter((f) => dirname(f) === dir).map((f) => Number(seqNumber(f))).filter(Number.isFinite),
|
|
454
|
+
openVersions: async ({ cls }) => { const [c] = parseVersioned([cls]); return (await openPrFiles(cwd, lane)).map((f) => c.re.exec(dirname(f).slice(c.dir ? c.dir.length + 1 : 0).split("/")[0])?.[1]).filter(Boolean).map(Number); },
|
|
455
|
+
}),
|
|
427
456
|
sequenceResolve: ({ cwd, files, partial }) => resolveSequenceConflicts({ git: (a) => run("git")(a, { cwd }), files, partial }),
|
|
428
457
|
/** #4732: numbers the other open PRs on `lane` already carry in `dir` (gh only, no fetch); [] on any failure. */
|
|
429
458
|
async sequenceOpenNumbers({ cwd, lane, dir }) {
|
|
@@ -435,7 +464,7 @@ export function makeLeanIo({ repo, subagentModel = readSubagentModel() }) {
|
|
|
435
464
|
},
|
|
436
465
|
/** #4588: deterministic base-merge resolution of union / JSON-map / generated files (bin/lean/conflictres.mjs). */
|
|
437
466
|
conflictResolve: ({ cwd, files, cfg }) => resolveBaseConflicts({ git: (a) => run("git")(a, { cwd }), cwd, files, cfg }),
|
|
438
|
-
sequenceLease:
|
|
467
|
+
sequenceLease: seqLeaseIo,
|
|
439
468
|
/** #4591: lane-added migrations the repo's generator did not produce (no journal entry or snapshot); [] on failure. */
|
|
440
469
|
/** #4661: plus journal `when` stamps not above the base max (newest-only migrators skip them). */
|
|
441
470
|
migrationGenerator: async ({ cwd, base }) => { const git = (a) => run("git")(a, { cwd }); return [...await generatorProblems({ git, base }), ...await journalOrderProblems({ git, base })]; },
|
|
@@ -891,6 +891,30 @@ describe("host capabilities in placement (#4542)", () => {
|
|
|
891
891
|
assert.equal(rows.find((r) => r.issue === 5).outcome, "merged");
|
|
892
892
|
});
|
|
893
893
|
|
|
894
|
+
it("#5371 orchestrate: a remote env.validate_placement or mechanical failure is requeued on a different placement", async () => {
|
|
895
|
+
for (const code of ["env.validate_placement", "env.repro_unrunnable"]) {
|
|
896
|
+
const calls = [];
|
|
897
|
+
const rows = await orchestrate({ issues: [5], parallel: 2, recovery: { maxAttempts: 1 }, readBody: async () => "",
|
|
898
|
+
remote: { max: 2, isRemote: () => true, place: () => ({ where: "remote", reason: "mode remote" }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
|
|
899
|
+
runOne: async (n, _l, ctx = {}) => {
|
|
900
|
+
calls.push([ctx.placement?.where, ctx.recover?.code ?? null]);
|
|
901
|
+
return ctx.recover ? { terminalReason: "merged", pr: 9 } : { terminalReason: "needs-human", code, detail: "x" };
|
|
902
|
+
} });
|
|
903
|
+
assert.deepEqual(calls, [["remote", null], ["local", code]], code);
|
|
904
|
+
assert.equal(rows.find((r) => r.issue === 5).outcome, "merged");
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
it("#5331 orchestrate: a lane whose frozen contract names a tool the sandbox lacks is placed locally before it starts", async () => {
|
|
909
|
+
const calls = [];
|
|
910
|
+
const contract = { validate: [{ id: "V3", command: "promtool check rules a.yml" }] };
|
|
911
|
+
const rows = await orchestrate({ issues: [5], parallel: 2, readBody: async () => "",
|
|
912
|
+
remote: { max: 2, isRemote: () => true, lacks: ["promtool"], contractOf: () => contract, place: () => ({ where: "remote", reason: "mode remote" }), admit: () => ({ ok: true }), onBudget: "stop", costPerMinute: 0 },
|
|
913
|
+
runOne: async (n, _l, ctx = {}) => { calls.push([ctx.placement?.where, ctx.placement?.reason]); return { terminalReason: "merged", pr: 9 }; } });
|
|
914
|
+
assert.deepEqual(calls, [["local", "host tool: sandbox lacks promtool"]]);
|
|
915
|
+
assert.equal(rows.find((r) => r.issue === 5).outcome, "merged");
|
|
916
|
+
});
|
|
917
|
+
|
|
894
918
|
it("orchestrate: a remote lane that ends env.capability_remote is relaunched locally once", async () => {
|
|
895
919
|
const calls = [];
|
|
896
920
|
const rows = await orchestrate({ issues: [5], parallel: 2, recovery: { maxAttempts: 1 }, readBody: async () => "",
|
package/bin/lean/facts.mjs
CHANGED
|
@@ -32,7 +32,7 @@ function clean(raw) {
|
|
|
32
32
|
.filter((f) => f && AT_RE.test(f) && !f.startsWith(".forge-lean/") && !f.split("/").includes("..")), (x) => x).slice(0, FACTS_FILES_MAX);
|
|
33
33
|
const rejected = uniqBy(list(r.rejected).map((x) => ({ approach: one(x?.approach), why: one(x?.why) })).filter((x) => x.approach && x.why), (x) => x.approach).slice(0, FACTS_LIST_MAX);
|
|
34
34
|
const hotspots = uniqBy(list(r.hotspots).map((x) => ({ at: one(x?.at, 200), why: one(x?.why) })).filter((x) => x.at && x.why && AT_RE.test(x.at) && !x.at.split("/").includes("..")), (x) => x.at).slice(0, FACTS_LIST_MAX);
|
|
35
|
-
const baselines = uniqBy(list(r.baselines).map((x) => ({ command: one(x?.command, 200), exit: x?.exit })).filter((x) => x.command && Number.isInteger(x.exit)), (x) => x.command).slice(0, FACTS_LIST_MAX);
|
|
35
|
+
const baselines = uniqBy(list(r.baselines).map((x) => ({ command: one(x?.command, 200), exit: x?.exit, ...(typeof x?.head === "string" && /^[0-9a-f]{7,40}$/.test(x.head) ? { head: x.head } : {}) })).filter((x) => x.command && Number.isInteger(x.exit)), (x) => x.command).slice(0, FACTS_LIST_MAX);
|
|
36
36
|
return { v: 1, files, decisions: strs(r.decisions), rejected, hotspots, conventions: strs(r.conventions), baselines };
|
|
37
37
|
}
|
|
38
38
|
const hasContent = (f) => KINDS.some((k) => f[k].length > 0);
|
|
@@ -41,10 +41,10 @@ const hasContent = (f) => KINDS.some((k) => f[k].length > 0);
|
|
|
41
41
|
* The lane's FORGE:FACTS record, or null when it would carry nothing. `result` is result.json (its `facts` and
|
|
42
42
|
* `validation`), `files` the lane's changed files, `contract` the frozen contract (decision fallback).
|
|
43
43
|
*/
|
|
44
|
-
export function normaliseFacts(result, { files = [], contract = null } = {}) {
|
|
44
|
+
export function normaliseFacts(result, { files = [], contract = null, head = "" } = {}) {
|
|
45
45
|
const raw = result?.facts && typeof result.facts === "object" ? result.facts : {};
|
|
46
46
|
const decisions = list(raw.decisions).some((d) => one(d)) ? raw.decisions : list(contract?.decisions).map((d) => d?.choice);
|
|
47
|
-
const baselines = list(result?.validation).map((v) => ({ command: v?.command, exit: v?.exit }));
|
|
47
|
+
const baselines = list(result?.validation).map((v) => ({ command: v?.command, exit: v?.exit, head })); // #5331: the head the result was recorded on
|
|
48
48
|
const f = clean({ ...raw, decisions, baselines, files });
|
|
49
49
|
return hasContent(f) ? f : null;
|
|
50
50
|
}
|
package/bin/lean/facts.test.mjs
CHANGED
|
@@ -63,4 +63,9 @@ describe("FORGE:FACTS record (#4401)", () => {
|
|
|
63
63
|
assert.deepEqual(l.hotspots, ["- hot spot src/a.js:12: retry loop (#33, PR #101)"]);
|
|
64
64
|
assert.deepEqual(l.baselines, ["- baseline: `node --test a.test.mjs` exit 0 (#33, PR #101)"]);
|
|
65
65
|
});
|
|
66
|
+
it("#5331 baselines record the head they were recorded on; a malformed head is dropped", () => {
|
|
67
|
+
const v = [{ id: "V1", command: "node --test a.test.mjs", exit: 0 }];
|
|
68
|
+
assert.equal(normaliseFacts({ validation: v }, { head: "abc1234" }).baselines[0].head, "abc1234");
|
|
69
|
+
assert.equal("head" in normaliseFacts({ validation: v }, { head: "not a sha" }).baselines[0], false);
|
|
70
|
+
});
|
|
66
71
|
});
|
package/bin/lean/fixround.mjs
CHANGED
|
@@ -15,6 +15,20 @@ export const MECHANICAL_KINDS = Object.freeze(["precheck", "ci", "docs", "struct
|
|
|
15
15
|
export const FIX_PROMPT_MAX = 60000;
|
|
16
16
|
export const FIX_CAPS = Object.freeze({ task: 20000, diff: 24000, contract: 8000, summary: 1500 });
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* #5348: the narrow profile (enumerating and duplicate-export fixes): contract excerpt, failing check output and the named
|
|
20
|
+
* files only. A session starts under NARROW_BASELINE_TOKENS; the prompt gets a quarter of that (NARROW_PROMPT_MAX chars at
|
|
21
|
+
* ~4 chars/token), the rest is the fixed system prompt and tool schemas. The budget test pins the cap.
|
|
22
|
+
*/
|
|
23
|
+
export const NARROW_BASELINE_TOKENS = 12000;
|
|
24
|
+
export const NARROW_PROMPT_MAX = 12000;
|
|
25
|
+
export const NARROW_CAPS = Object.freeze({ task: 6000, contract: 2500, files: 1200 });
|
|
26
|
+
|
|
27
|
+
/** One task for every pending narrow fix of a stage: [{title, text}] -> sections, empty ones dropped. */
|
|
28
|
+
export function mergeNarrowTasks(pending) {
|
|
29
|
+
return (pending ?? []).filter((x) => x && String(x.text ?? "").trim()).map((x) => `### ${x.title}\n${String(x.text).trim()}`).join("\n\n");
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
const FILE_LINE_RE = /[\w.@/-]+\.[A-Za-z0-9]+:\d+/;
|
|
19
33
|
|
|
20
34
|
/** True only for a non-empty list whose every failure (a string, or `f.detail`) cites a `path.ext:N`. */
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { MECHANICAL_KINDS, FIX_PROMPT_MAX, citesFileLine, freshFix, issueSummary, capText, TRIGGERS, REWORK_TRIGGERS, firstPassOf, formatFirstPassSummary, sessionCostDelta } from "./fixround.mjs";
|
|
6
|
-
import { fixSessionPrompt, ciFailurePrompt } from "./prompts.mjs";
|
|
5
|
+
import { MECHANICAL_KINDS, FIX_PROMPT_MAX, citesFileLine, freshFix, issueSummary, capText, TRIGGERS, REWORK_TRIGGERS, firstPassOf, formatFirstPassSummary, sessionCostDelta, NARROW_PROMPT_MAX, NARROW_BASELINE_TOKENS, mergeNarrowTasks } from "./fixround.mjs";
|
|
6
|
+
import { fixSessionPrompt, ciFailurePrompt, narrowFixPrompt } from "./prompts.mjs";
|
|
7
7
|
|
|
8
8
|
describe("#4363 fresh fix sessions: which rounds, and the prompt caps", () => {
|
|
9
9
|
it("every mechanical kind is fresh; block/contract/conflict kinds are not", () => {
|
|
@@ -123,3 +123,26 @@ describe("#4987 CI fix prompt: unrelated failures", () => {
|
|
|
123
123
|
assert.match(p, /unknown amendment kinds are rejected/);
|
|
124
124
|
});
|
|
125
125
|
});
|
|
126
|
+
|
|
127
|
+
describe("#5348 narrow fix profile: prompt budget", () => {
|
|
128
|
+
const big = "x".repeat(200000);
|
|
129
|
+
const contract = { requirements: [{ id: "R1", quote: big }], deliverables: Array.from({ length: 200 }, (_, i) => ({ id: `D${i}`, path: `p/${i}.mjs`, change: big })), preserve: [{ id: "P1", what: big }], validate: [{ id: "V1", command: big }] };
|
|
130
|
+
it("stays under the cap and the 12k-token baseline on worst-case inputs (4 chars/token, 8k tokens left for system and tools)", () => {
|
|
131
|
+
const p = narrowFixPrompt({ task: big, contract, files: Array.from({ length: 500 }, (_, i) => `dir/file-${i}.test.mjs`) });
|
|
132
|
+
assert.ok(p.length <= NARROW_PROMPT_MAX, `${p.length} chars`);
|
|
133
|
+
assert.ok(Math.ceil(p.length / 4) + 8000 <= NARROW_BASELINE_TOKENS, "prompt tokens plus the fixed system overhead fit the baseline");
|
|
134
|
+
});
|
|
135
|
+
it("carries the contract excerpt, the failure and the files, and none of the diff, summary or lane text", () => {
|
|
136
|
+
const p = narrowFixPrompt({ task: "enumerating test a.test.mjs misses `foo`", contract: { deliverables: [{ id: "D1", path: "bin/x.mjs", change: "add foo" }], requirements: [{ quote: "SECRET-QUOTE" }] }, files: ["a.test.mjs"] });
|
|
137
|
+
assert.match(p, /bin\/x\.mjs/); assert.match(p, /misses `foo`/); assert.match(p, /- a\.test\.mjs/);
|
|
138
|
+
assert.doesNotMatch(p, /SECRET-QUOTE|## Diff|## Issue/);
|
|
139
|
+
});
|
|
140
|
+
it("is far smaller than the diff-carrying fix prompt", () => {
|
|
141
|
+
const diff = "+line\n".repeat(20000);
|
|
142
|
+
assert.ok(narrowFixPrompt({ task: "t", contract, files: ["a"] }).length < fixSessionPrompt({ task: "t", diff, contract }).length / 2);
|
|
143
|
+
});
|
|
144
|
+
it("mergeNarrowTasks: one task, a section per pending fix, empty ones dropped", () => {
|
|
145
|
+
assert.equal(mergeNarrowTasks([{ title: "A", text: "fix a" }, { title: "B", text: " " }, { title: "C", text: "fix c" }]), "### A\nfix a\n\n### C\nfix c");
|
|
146
|
+
assert.equal(mergeNarrowTasks(null), "");
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -25,6 +25,7 @@ const sources = (d) => readdirSync(d).flatMap((f) => {
|
|
|
25
25
|
/** Strict gh: rejects unknown --json fields the way gh does; REST serves the association. */
|
|
26
26
|
const strictGh = (issues) => async (a) => {
|
|
27
27
|
const j = a.indexOf("--json");
|
|
28
|
+
if (a[0] === "pr" && a[1] === "list") return "[]"; // #5313: open PRs and their closing issues (pr fields, not issue fields)
|
|
28
29
|
if (j >= 0) for (const f of a[j + 1].split(",")) if (!ISSUE_JSON_FIELDS.includes(f)) throw new Error(`Unknown JSON field: "${f}"`);
|
|
29
30
|
if (a[0] === "api") {
|
|
30
31
|
const m = /issues\/(\d+)$/.exec(a[1]);
|
|
@@ -68,7 +69,7 @@ test("orchestrate --add adds an open issue on a gh that rejects unknown fields",
|
|
|
68
69
|
const id = newBatchId();
|
|
69
70
|
openBatch(root, id).writePlan({ repo: "o/r" });
|
|
70
71
|
const io = { gh: strictGh({ 5: { assoc: "OWNER", body: "Blocked by #6" }, 6: { assoc: "OWNER" }, 9: { assoc: "NONE", body: "Blocked by #6" } }) };
|
|
71
|
-
const out = await orchestrateFromCli(["--add", id, "5", "6", "9"], { io });
|
|
72
|
+
const out = await orchestrateFromCli(["--add", id, "5", "6", "9"], { io }).catch((e) => { if (e.code === "batch.not-hosted") return e.result; throw e; }); // #5314: unhosted add fails loudly, result rides the error
|
|
72
73
|
assert.ok(!out.skipped.some((s) => s.reason === "unreadable"), JSON.stringify(out.skipped));
|
|
73
74
|
assert.deepEqual(out.added, [5, 6, 9]);
|
|
74
75
|
assert.deepEqual(out.edges, [{ from: 5, to: 6 }]); // the untrusted #9 adds no edge
|