opencode-model-router 2.7.0 → 2.9.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/CHANGELOG.md +583 -0
- package/README.md +20 -0
- package/package.json +5 -1
- package/src/commands/approvals.ts +354 -0
- package/src/commands/output.ts +34 -1
- package/src/compat/background.ts +2439 -0
- package/src/compat/child-session.ts +6 -0
- package/src/compat/turn-state.ts +215 -0
- package/src/compat/v2-client.ts +136 -17
- package/src/compat/v2-hooks.ts +2853 -109
- package/src/compat/v2-observations.ts +328 -0
- package/src/executor/capacity.ts +362 -0
- package/src/executor/child-guards.ts +40 -0
- package/src/executor/command.ts +265 -0
- package/src/executor/compile/edges.ts +809 -0
- package/src/executor/compile/estimate.ts +158 -0
- package/src/executor/compile/footprint.ts +829 -0
- package/src/executor/compile/index.ts +1080 -0
- package/src/executor/compile/parse.ts +1492 -0
- package/src/executor/compile/residue.ts +706 -0
- package/src/executor/compile/validate.ts +280 -0
- package/src/executor/create.ts +672 -0
- package/src/executor/expand.ts +551 -0
- package/src/executor/git.ts +1214 -0
- package/src/executor/host-preamble.ts +17 -0
- package/src/executor/instructions.ts +35 -0
- package/src/executor/integrate/bisect.ts +73 -0
- package/src/executor/integrate/checks.ts +1086 -0
- package/src/executor/integrate/land.ts +177 -0
- package/src/executor/integrate/phase-suite.ts +407 -0
- package/src/executor/integrate/queue.ts +3083 -0
- package/src/executor/integrate/run-resolver.ts +19 -0
- package/src/executor/launch.ts +652 -0
- package/src/executor/ledger.ts +2208 -0
- package/src/executor/observations.ts +212 -0
- package/src/executor/paths.ts +159 -0
- package/src/executor/platform.ts +39 -0
- package/src/executor/process-identity.ts +19 -0
- package/src/executor/qa-loop.ts +470 -0
- package/src/executor/recovery.ts +403 -0
- package/src/executor/runtime.ts +6233 -0
- package/src/executor/schedule.ts +246 -0
- package/src/executor/slots/env.ts +145 -0
- package/src/executor/slots/pool.ts +1564 -0
- package/src/executor/slots/provision.ts +853 -0
- package/src/executor/tool.ts +534 -0
- package/src/executor/types.ts +2064 -0
- package/src/executor/unattended.ts +488 -0
- package/src/guard/store.ts +3 -1
- package/src/index.ts +1789 -288
- package/src/router/config.ts +823 -26
- package/src/router/dispatch-header.ts +95 -2
- package/src/router/git-tools.ts +266 -19
- package/src/router/leases.ts +1469 -0
- package/src/router/logger.ts +44 -32
- package/src/router/protocol.ts +44 -10
- package/src/router/role-agents.ts +334 -20
- package/src/router/roles-config.ts +93 -1
- package/src/router/roles.ts +1 -1
- package/src/router/run-tools.ts +56 -4
- package/src/router/sessions.ts +11 -0
- package/src/router/tool-paths.ts +308 -0
- package/src/router/work-roots.ts +86 -0
- package/src/routing/advisor/findings.ts +25 -5
- package/src/routing/classify/index.ts +7 -1
- package/src/routing/classify/route-line.ts +96 -5
- package/src/routing/classify/rules.ts +11 -0
- package/src/routing/classify/types.ts +26 -0
- package/src/routing/commands/stats.ts +2 -2
- package/src/routing/outcomes/durations.ts +225 -0
- package/src/routing/outcomes/index.ts +59 -2
- package/src/routing/outcomes/persist.ts +409 -0
- package/src/routing/outcomes/signals.ts +17 -0
- package/src/routing/outcomes/stats.ts +170 -11
- package/src/routing/outcomes/timings.ts +836 -0
- package/src/routing/outcomes/types.ts +98 -0
- package/src/routing/roles/admission.ts +1028 -0
- package/src/routing/roles/approvals.ts +957 -0
- package/src/routing/roles/binding.ts +116 -13
- package/src/routing/roles/check-placement.ts +112 -0
- package/src/routing/roles/git-root.ts +500 -0
- package/src/routing/roles/orphans.ts +68 -0
- package/src/routing/roles/policy.ts +30 -3
- package/src/routing/roles/read-set.ts +325 -0
- package/src/routing/roles/work-root.ts +12 -2
- package/src/routing/wire/dispatch.ts +697 -30
- package/src/routing/wire/hint.ts +56 -8
- package/src/routing/wire/working-set.ts +58 -0
- package/src/util/linear-trim.ts +32 -0
- package/src/v2.ts +94 -49
- package/src/verify/batch.ts +7 -2
- package/src/verify/branch.ts +141 -0
- package/src/verify/canonical-path.ts +35 -0
- package/src/verify/deterministic.ts +268 -17
- package/src/verify/dispatch.ts +348 -37
- package/src/verify/dod.ts +46 -0
- package/src/verify/edges.ts +817 -0
- package/src/verify/exec.ts +52 -9
- package/src/verify/gate.ts +349 -16
- package/src/verify/git-top.ts +43 -0
- package/src/verify/head.ts +107 -0
- package/src/verify/pending.ts +1846 -18
- package/src/verify/perimeter.ts +1186 -0
- package/src/verify/pin.ts +109 -0
- package/src/verify/plan-task.ts +729 -0
- package/src/verify/reference.ts +297 -8
- package/src/verify/risk.ts +16 -3
- package/src/verify/runner.ts +706 -32
- package/src/verify/tree.ts +372 -16
- package/src/verify/types.ts +66 -2
- package/src/verify/wiring.ts +1594 -46
package/src/verify/reference.ts
CHANGED
|
@@ -731,6 +731,9 @@ import { tmpdir as osTmpdir } from "node:os";
|
|
|
731
731
|
import { posix as pathPosix, win32 as pathWin32 } from "node:path";
|
|
732
732
|
import type { ArgvSeam, ExecOptions, ExecResult } from "./types";
|
|
733
733
|
import type { TreeSnapshot } from "./dispatch";
|
|
734
|
+
import { gitTopOf, perimeterKey } from "./git-top";
|
|
735
|
+
// Type-only: pin.ts imports perimeter.ts, which imports this module; samePin is loaded lazily in step 7.
|
|
736
|
+
import type { LinkPin, PinWhy } from "./pin";
|
|
734
737
|
import type { PluginLogger } from "../router/logger";
|
|
735
738
|
|
|
736
739
|
// --- Seams --------------------------------------------------------------------
|
|
@@ -804,6 +807,11 @@ export interface ReferenceDeps extends CaptureDeps {
|
|
|
804
807
|
randomSuffix?: () => string;
|
|
805
808
|
/** Default HEARTBEAT_INTERVAL_MS: how often a materialized dir's mtime is refreshed while in use. */
|
|
806
809
|
heartbeatMs?: number;
|
|
810
|
+
/**
|
|
811
|
+
* Cross-repo P2.6: the current pin of a link target's repository top, computed by the caller (pin.ts pinTarget). With
|
|
812
|
+
* DispatchReference.pins, a package link into a pinned repository unchanged since dispatch is exact instead of external-link.
|
|
813
|
+
*/
|
|
814
|
+
pinNow?: (root: string) => Promise<LinkPin>;
|
|
807
815
|
}
|
|
808
816
|
|
|
809
817
|
// --- Data types ---------------------------------------------------------------
|
|
@@ -823,6 +831,154 @@ export interface DispatchReference {
|
|
|
823
831
|
readonly captureReasons: readonly InexactReason[];
|
|
824
832
|
/** now() when the capture resolved. */
|
|
825
833
|
readonly capturedAt: number;
|
|
834
|
+
/** Cross-repo P2.6: the dispatch-time pins of linked repositories (pin.ts); see ReferenceDeps.pinNow. */
|
|
835
|
+
readonly pins?: readonly LinkPin[];
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** JSON-safe form of a DispatchReference (pending.jsonl, phase 2.1 section 11). */
|
|
839
|
+
export interface SerializedReference {
|
|
840
|
+
readonly root: string;
|
|
841
|
+
readonly head: string;
|
|
842
|
+
readonly commit: string;
|
|
843
|
+
readonly untracked: Readonly<Record<string, string>>;
|
|
844
|
+
readonly tracked: Readonly<Record<string, string>>;
|
|
845
|
+
readonly captureReasons: readonly InexactReason[];
|
|
846
|
+
readonly capturedAt: number;
|
|
847
|
+
/** Absolute node_modules links the materialized dir held (link path -> target); re-created on materialize. */
|
|
848
|
+
readonly links?: Readonly<Record<string, string>>;
|
|
849
|
+
/** DispatchReference.pins, when present (QA-SYNC1-9: a restart keeps the dispatch-time pins of linked repositories). */
|
|
850
|
+
readonly pins?: readonly LinkPin[];
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
export function serializeReference(
|
|
854
|
+
ref: DispatchReference,
|
|
855
|
+
links?: Readonly<Record<string, string>>,
|
|
856
|
+
): SerializedReference {
|
|
857
|
+
return {
|
|
858
|
+
root: ref.root,
|
|
859
|
+
head: ref.head,
|
|
860
|
+
commit: ref.commit,
|
|
861
|
+
untracked: Object.fromEntries(ref.untracked),
|
|
862
|
+
tracked: Object.fromEntries(ref.tracked),
|
|
863
|
+
captureReasons: ref.captureReasons.map((r) => ({ cause: r.cause, path: r.path })),
|
|
864
|
+
capturedAt: ref.capturedAt,
|
|
865
|
+
...(links !== undefined && Object.keys(links).length > 0 ? { links: { ...links } } : {}),
|
|
866
|
+
...(ref.pins !== undefined ? { pins: ref.pins.map(copyPin) } : {}),
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/** A plain copy of `pin` (only the LinkPin fields, nested pins included). */
|
|
871
|
+
function copyPin(pin: LinkPin): LinkPin {
|
|
872
|
+
return pin.kind === "pinned"
|
|
873
|
+
? { kind: "pinned", root: pin.root, head: pin.head, fingerprint: pin.fingerprint, ignored: pin.ignored, nested: pin.nested.map(copyPin) }
|
|
874
|
+
: { kind: "unpinnable", root: pin.root, why: pin.why };
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
function digestMap(v: unknown): Map<string, string> | undefined {
|
|
878
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return undefined;
|
|
879
|
+
const out = new Map<string, string>();
|
|
880
|
+
for (const [k, d] of Object.entries(v)) {
|
|
881
|
+
if (typeof d !== "string") return undefined;
|
|
882
|
+
out.set(k, d);
|
|
883
|
+
}
|
|
884
|
+
return out;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/** The links recorded by serializeReference; empty when absent or malformed. */
|
|
888
|
+
export function serializedReferenceLinks(json: unknown): Readonly<Record<string, string>> {
|
|
889
|
+
const raw = typeof json === "string" ? safeParse(json) : json;
|
|
890
|
+
if (typeof raw !== "object" || raw === null) return {};
|
|
891
|
+
const links = digestMap((raw as Record<string, unknown>).links);
|
|
892
|
+
return links === undefined ? {} : Object.fromEntries(links);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function safeParse(text: string): unknown {
|
|
896
|
+
try {
|
|
897
|
+
return JSON.parse(text);
|
|
898
|
+
} catch {
|
|
899
|
+
return undefined;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
const INEXACT_CAUSES: ReadonlySet<string> = new Set<InexactCause>([
|
|
904
|
+
"untracked-deleted",
|
|
905
|
+
"untracked-modified",
|
|
906
|
+
"untracked-not-file",
|
|
907
|
+
"untracked-unreadable",
|
|
908
|
+
"untracked-symlink",
|
|
909
|
+
"untracked-unsafe-path",
|
|
910
|
+
"dependency-drift",
|
|
911
|
+
"workspace-link-drift",
|
|
912
|
+
"external-link",
|
|
913
|
+
"root-link",
|
|
914
|
+
"index-flags",
|
|
915
|
+
"checkout-conversion",
|
|
916
|
+
]);
|
|
917
|
+
|
|
918
|
+
const PIN_WHYS: ReadonlySet<string> = new Set<PinWhy>(["not-observed", "not-admitted", "not-git", "over-bounds", "deep-link"]);
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* One serialized LinkPin, or undefined when malformed. `nestedAllowed` mirrors pin.ts pinTarget: only a top-level pin
|
|
922
|
+
* carries nested pins (one level), so a nested pin with nested pins of its own is malformed.
|
|
923
|
+
*/
|
|
924
|
+
function deserializePin(v: unknown, nestedAllowed: boolean): LinkPin | undefined {
|
|
925
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return undefined;
|
|
926
|
+
const p = v as Record<string, unknown>;
|
|
927
|
+
if (typeof p.root !== "string") return undefined;
|
|
928
|
+
if (p.kind === "unpinnable") {
|
|
929
|
+
if (typeof p.why !== "string" || !PIN_WHYS.has(p.why)) return undefined;
|
|
930
|
+
return { kind: "unpinnable", root: p.root, why: p.why as PinWhy };
|
|
931
|
+
}
|
|
932
|
+
if (p.kind !== "pinned") return undefined;
|
|
933
|
+
if (typeof p.head !== "string" || typeof p.fingerprint !== "string" || typeof p.ignored !== "string") return undefined;
|
|
934
|
+
if (!Array.isArray(p.nested) || (!nestedAllowed && p.nested.length > 0)) return undefined;
|
|
935
|
+
const nested: LinkPin[] = [];
|
|
936
|
+
for (const n of p.nested) {
|
|
937
|
+
const pin = deserializePin(n, false);
|
|
938
|
+
if (pin === undefined) return undefined;
|
|
939
|
+
nested.push(pin);
|
|
940
|
+
}
|
|
941
|
+
return { kind: "pinned", root: p.root, head: p.head, fingerprint: p.fingerprint, ignored: p.ignored, nested };
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/** Inverse of serializeReference. Accepts a JSON string or the parsed object; undefined when malformed. */
|
|
945
|
+
export function deserializeReference(json: unknown): DispatchReference | undefined {
|
|
946
|
+
const raw: unknown = typeof json === "string" ? safeParse(json) : json;
|
|
947
|
+
if (typeof raw !== "object" || raw === null) return undefined;
|
|
948
|
+
const o = raw as Record<string, unknown>;
|
|
949
|
+
if (typeof o.root !== "string" || typeof o.head !== "string" || typeof o.commit !== "string") return undefined;
|
|
950
|
+
if (typeof o.capturedAt !== "number" || !Number.isFinite(o.capturedAt)) return undefined;
|
|
951
|
+
const untracked = digestMap(o.untracked);
|
|
952
|
+
const tracked = digestMap(o.tracked);
|
|
953
|
+
if (untracked === undefined || tracked === undefined) return undefined;
|
|
954
|
+
const reasons: InexactReason[] = [];
|
|
955
|
+
if (!Array.isArray(o.captureReasons)) return undefined;
|
|
956
|
+
for (const r of o.captureReasons) {
|
|
957
|
+
if (typeof r !== "object" || r === null) return undefined;
|
|
958
|
+
const rr = r as Record<string, unknown>;
|
|
959
|
+
if (typeof rr.cause !== "string" || !INEXACT_CAUSES.has(rr.cause) || typeof rr.path !== "string") return undefined;
|
|
960
|
+
reasons.push({ cause: rr.cause as InexactCause, path: rr.path });
|
|
961
|
+
}
|
|
962
|
+
let pins: LinkPin[] | undefined;
|
|
963
|
+
if (o.pins !== undefined) {
|
|
964
|
+
if (!Array.isArray(o.pins)) return undefined;
|
|
965
|
+
pins = [];
|
|
966
|
+
for (const v of o.pins) {
|
|
967
|
+
const pin = deserializePin(v, true);
|
|
968
|
+
if (pin === undefined) return undefined;
|
|
969
|
+
pins.push(pin);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return {
|
|
973
|
+
root: o.root,
|
|
974
|
+
head: o.head,
|
|
975
|
+
commit: o.commit,
|
|
976
|
+
untracked,
|
|
977
|
+
tracked,
|
|
978
|
+
captureReasons: reasons,
|
|
979
|
+
capturedAt: o.capturedAt,
|
|
980
|
+
...(pins !== undefined ? { pins } : {}),
|
|
981
|
+
};
|
|
826
982
|
}
|
|
827
983
|
|
|
828
984
|
export type InexactCause =
|
|
@@ -834,6 +990,8 @@ export type InexactCause =
|
|
|
834
990
|
| "untracked-unsafe-path"
|
|
835
991
|
| "dependency-drift"
|
|
836
992
|
| "workspace-link-drift"
|
|
993
|
+
| "external-link"
|
|
994
|
+
| "root-link"
|
|
837
995
|
| "index-flags"
|
|
838
996
|
| "checkout-conversion";
|
|
839
997
|
|
|
@@ -903,6 +1061,20 @@ const ADD_LOCK_UNSUPPORTED = /unknown option\W+(?:reason|lock)\b/;
|
|
|
903
1061
|
export const STALE_REFERENCE_AGE_MS = 60 * 60 * 1000;
|
|
904
1062
|
/** A live reference dir's mtime is refreshed this often, far below STALE_REFERENCE_AGE_MS (QA-1.5-4). */
|
|
905
1063
|
export const HEARTBEAT_INTERVAL_MS = 5 * 60 * 1000;
|
|
1064
|
+
/**
|
|
1065
|
+
* Package-store layouts (pnpm `.pnpm/x@1/node_modules/x`, a global virtual store, a custom virtualStoreDir) all place the
|
|
1066
|
+
* package directly under a node_modules dir (or its @scope): a package link whose real path is such a directory is store-like
|
|
1067
|
+
* (P0.4, step 7 below; cross-repo P1.8 link discovery, perimeter.ts).
|
|
1068
|
+
*/
|
|
1069
|
+
export function isStoreLikeLink(real: string, platform: string): boolean {
|
|
1070
|
+
const p = platform === "win32" ? pathWin32 : pathPosix;
|
|
1071
|
+
const fold = (s: string): string => (platform === "win32" ? s.toLowerCase() : s);
|
|
1072
|
+
const parent = p.dirname(real);
|
|
1073
|
+
const parentName = fold(p.basename(parent));
|
|
1074
|
+
if (parentName === "node_modules") return true;
|
|
1075
|
+
return parentName.startsWith("@") && fold(p.basename(p.dirname(parent))) === "node_modules";
|
|
1076
|
+
}
|
|
1077
|
+
|
|
906
1078
|
/** Equals the baselineTimeoutMs default (§1.4); callers pass the configured value. */
|
|
907
1079
|
export const DEFAULT_CAPTURE_TIMEOUT_MS = 15_000;
|
|
908
1080
|
export const DEFAULT_MATERIALIZE_TIMEOUT_MS = 30_000;
|
|
@@ -1778,6 +1950,8 @@ export async function materialize(
|
|
|
1778
1950
|
}
|
|
1779
1951
|
|
|
1780
1952
|
// 5. Discovery of ignored entries; nothing ignored is ever copied.
|
|
1953
|
+
// A directory-only pattern (`node_modules/`) never matches a symlink, so a symlinked node_modules
|
|
1954
|
+
// it does not ignore is an untracked entry (inexact via its untracked reason), never a link candidate.
|
|
1781
1955
|
const ignored = await git(["ls-files", "--others", "--ignored", "--exclude-standard", "--directory", "-z"]);
|
|
1782
1956
|
if (budget.spent()) return await abandon("aborted", "aborted during ignored-file discovery");
|
|
1783
1957
|
if (!ignored || ignored.code !== 0) return await abandon("error", ignored?.stderr.trim() ?? "ignored-file discovery failed");
|
|
@@ -1790,7 +1964,9 @@ export async function materialize(
|
|
|
1790
1964
|
}
|
|
1791
1965
|
|
|
1792
1966
|
// 6. Link node_modules (section 5), parents before children (git's order).
|
|
1793
|
-
|
|
1967
|
+
// Each target keeps the root-relative path of the candidate node_modules it came from,
|
|
1968
|
+
// so drift reasons never leak a path outside root (a node_modules that is itself a link).
|
|
1969
|
+
const linkTargets: { readonly target: string; readonly label: string }[] = [];
|
|
1794
1970
|
for (const entry of candidates) {
|
|
1795
1971
|
if (budget.spent()) return await abandon("aborted", "aborted while linking node_modules");
|
|
1796
1972
|
const rel = entry.replace(/\/$/, "");
|
|
@@ -1822,7 +1998,7 @@ export async function materialize(
|
|
|
1822
1998
|
}
|
|
1823
1999
|
links.push(linkPath);
|
|
1824
2000
|
await fs.symlink(target, linkPath, platform === "win32" ? "junction" : "dir");
|
|
1825
|
-
linkTargets.push(target);
|
|
2001
|
+
linkTargets.push({ target, label: rel });
|
|
1826
2002
|
}
|
|
1827
2003
|
|
|
1828
2004
|
// 7. Drift checks (section 2 c and d). Porcelain `git diff` rewrites the index
|
|
@@ -1849,8 +2025,45 @@ export async function materialize(
|
|
|
1849
2025
|
for (const rel of splitZ(diff.stdout)) changed.add(rel);
|
|
1850
2026
|
for (const rel of splitZ(nowUntracked.stdout)) if (!ref.untracked.has(rel)) changed.add(rel);
|
|
1851
2027
|
const realRoot = p.resolve(await fs.realpath(root));
|
|
2028
|
+
const fold = (s: string) => (platform === "win32" ? s.toLowerCase() : s);
|
|
1852
2029
|
const workspaceDirs = new Set<string>();
|
|
1853
|
-
|
|
2030
|
+
// P0.4: package links whose real path is outside the repository (and not a store-like
|
|
2031
|
+
// path under a node_modules segment) load code the reference cannot pin.
|
|
2032
|
+
const externalLinks = new Set<string>();
|
|
2033
|
+
// A package link to the root itself, or to an ancestor of it, would load the live tree.
|
|
2034
|
+
const rootLinks = new Set<string>();
|
|
2035
|
+
// Package-store layouts (pnpm `.pnpm/x@1/node_modules/x`, a global virtual store, a custom
|
|
2036
|
+
// virtualStoreDir) all place the package directly under a node_modules dir (or its @scope).
|
|
2037
|
+
const storeLike = (real: string): boolean => isStoreLikeLink(real, platform);
|
|
2038
|
+
// Cross-repo P2.6 (OD3, fail closed): an outside link whose git top was pinned at dispatch (ref.pins) and has the same
|
|
2039
|
+
// pin now (deps.pinNow) is exact. No pin, an unpinnable or changed pin, no pinNow, or a throw keeps external-link.
|
|
2040
|
+
const pins = ref.pins ?? [];
|
|
2041
|
+
const pinNow = deps.pinNow;
|
|
2042
|
+
const usePins = pins.length > 0 && pinNow !== undefined;
|
|
2043
|
+
const pinVerdicts = new Map<string, Promise<boolean>>();
|
|
2044
|
+
const pinnedUnchanged = async (real: string): Promise<boolean> => {
|
|
2045
|
+
try {
|
|
2046
|
+
if (pinNow === undefined) return false;
|
|
2047
|
+
const top = gitTopOf(real);
|
|
2048
|
+
if (top === undefined) return false;
|
|
2049
|
+
const key = perimeterKey(top);
|
|
2050
|
+
const dispatchPin = pins.find((pin) => perimeterKey(pin.root) === key);
|
|
2051
|
+
if (dispatchPin === undefined || dispatchPin.kind !== "pinned") return false;
|
|
2052
|
+
let verdict = pinVerdicts.get(key);
|
|
2053
|
+
if (verdict === undefined) {
|
|
2054
|
+
verdict = (async () => {
|
|
2055
|
+
// Lazy: a static import would close the cycle reference -> pin -> perimeter -> reference.
|
|
2056
|
+
const { samePin } = await import("./pin");
|
|
2057
|
+
return samePin(dispatchPin, await pinNow(dispatchPin.root));
|
|
2058
|
+
})().catch(() => false);
|
|
2059
|
+
pinVerdicts.set(key, verdict);
|
|
2060
|
+
}
|
|
2061
|
+
return await verdict;
|
|
2062
|
+
} catch {
|
|
2063
|
+
return false;
|
|
2064
|
+
}
|
|
2065
|
+
};
|
|
2066
|
+
for (const { target, label } of linkTargets) {
|
|
1854
2067
|
for (const entry of await packageEntries(fs, target, platform)) {
|
|
1855
2068
|
const stats = await lstatOrMissing(fs, entry);
|
|
1856
2069
|
if (!stats || !stats.isSymbolicLink()) continue;
|
|
@@ -1862,12 +2075,21 @@ export async function materialize(
|
|
|
1862
2075
|
continue;
|
|
1863
2076
|
}
|
|
1864
2077
|
const base = [realRoot, root].find((candidateRoot) => isStrictlyInside(real, candidateRoot, platform));
|
|
1865
|
-
if (!base)
|
|
2078
|
+
if (!base) {
|
|
2079
|
+
// Dot-entries (`.cache`, `.bin`) are tool state, not packages.
|
|
2080
|
+
if (!p.basename(entry).startsWith(".")) {
|
|
2081
|
+
const entryLabel = [label, ...p.relative(target, entry).split(p.sep)].join("/");
|
|
2082
|
+
if (insideOrEqual(realRoot, real, platform) || insideOrEqual(root, real, platform)) rootLinks.add(entryLabel);
|
|
2083
|
+
else if (!storeLike(real) && !(usePins && (await pinnedUnchanged(real)))) externalLinks.add(entryLabel);
|
|
2084
|
+
}
|
|
2085
|
+
continue;
|
|
2086
|
+
}
|
|
1866
2087
|
const rel = p.relative(base, real).split(p.sep).join("/");
|
|
1867
2088
|
if (!rel.split("/").includes("node_modules")) workspaceDirs.add(rel);
|
|
1868
2089
|
}
|
|
1869
2090
|
}
|
|
1870
|
-
const
|
|
2091
|
+
for (const rel of [...rootLinks].sort(byCodeUnit)) reasons.push({ cause: "root-link", path: rel });
|
|
2092
|
+
for (const rel of [...externalLinks].sort(byCodeUnit)) reasons.push({ cause: "external-link", path: rel });
|
|
1871
2093
|
// Section 2 (c) and (d) over a set of drifted paths; run on the step-7 set and, in step 7b, on
|
|
1872
2094
|
// the paths its re-diff adds (#88), so a late edit is judged like any other drift.
|
|
1873
2095
|
const driftReasons = (paths: readonly string[]) => {
|
|
@@ -2017,6 +2239,73 @@ function parseWorktreeList(stdout: string): WorktreeEntry[] {
|
|
|
2017
2239
|
return entries;
|
|
2018
2240
|
}
|
|
2019
2241
|
|
|
2242
|
+
/**
|
|
2243
|
+
* Reference dirs reloaded from pending.jsonl by a later process (phase 2.1 section 11.3): the dir
|
|
2244
|
+
* name still carries the dead owner's pid, so GC must skip them while the pending entry lives.
|
|
2245
|
+
* Keyed by basename (REF_DIR_PATTERN); the value is the last known absolute dir, if given.
|
|
2246
|
+
*/
|
|
2247
|
+
const KEPT = processWideSet("omr.reference.kept");
|
|
2248
|
+
/** Absolute dirs of KEPT names whose path is known: refreshed by the keep heartbeat. */
|
|
2249
|
+
const KEPT_DIRS = new Map<string, string>();
|
|
2250
|
+
let keptBeat: ReturnType<typeof setInterval> | undefined;
|
|
2251
|
+
|
|
2252
|
+
function keptName(key: string): string | undefined {
|
|
2253
|
+
const name = key.replace(/[\\/]+$/, "").split(/[\\/]/).pop() ?? "";
|
|
2254
|
+
return REF_DIR_PATTERN.test(name) ? name : undefined;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
/** True when `key` (a dir path or basename) was passed to keepReferences and not released. */
|
|
2258
|
+
export function isReferenceKept(key: string): boolean {
|
|
2259
|
+
const name = keptName(key);
|
|
2260
|
+
return name !== undefined && KEPT.has(name);
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
export interface KeepReferencesOptions {
|
|
2264
|
+
/** Default nodeReferenceFs. */
|
|
2265
|
+
fs?: Pick<ReferenceFs, "utimes">;
|
|
2266
|
+
/** Default HEARTBEAT_INTERVAL_MS. */
|
|
2267
|
+
heartbeatMs?: number;
|
|
2268
|
+
logger?: Pick<PluginLogger, "warn">;
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
/**
|
|
2272
|
+
* Marks reloaded reference dirs active: gcStaleReferences skips them, and dirs given as absolute paths
|
|
2273
|
+
* are heartbeated under this process's pid (their name still carries the dead owner's). Keys are absolute
|
|
2274
|
+
* dir paths or bare `omr-ref-<pid>-<16 hex>` names; anything else is ignored. The returned function
|
|
2275
|
+
* releases exactly these keys.
|
|
2276
|
+
*/
|
|
2277
|
+
export function keepReferences(keys: Iterable<string>, opts: KeepReferencesOptions = {}): () => void {
|
|
2278
|
+
const added: string[] = [];
|
|
2279
|
+
for (const key of keys) {
|
|
2280
|
+
const name = keptName(key);
|
|
2281
|
+
if (name === undefined) continue;
|
|
2282
|
+
KEPT.add(name);
|
|
2283
|
+
if (/[\\/]/.test(key)) KEPT_DIRS.set(name, key);
|
|
2284
|
+
added.push(name);
|
|
2285
|
+
}
|
|
2286
|
+
if (keptBeat === undefined && KEPT_DIRS.size > 0) {
|
|
2287
|
+
const fs = opts.fs ?? nodeReferenceFs;
|
|
2288
|
+
keptBeat = setInterval(() => {
|
|
2289
|
+
const now = new Date();
|
|
2290
|
+
for (const dir of KEPT_DIRS.values()) {
|
|
2291
|
+
fs.utimes(dir, now, now).catch((error: unknown) =>
|
|
2292
|
+
opts.logger?.warn("reference keep heartbeat failed", { dir, error: describeError(error) }));
|
|
2293
|
+
}
|
|
2294
|
+
}, opts.heartbeatMs ?? HEARTBEAT_INTERVAL_MS);
|
|
2295
|
+
keptBeat.unref();
|
|
2296
|
+
}
|
|
2297
|
+
return () => {
|
|
2298
|
+
for (const name of added) {
|
|
2299
|
+
KEPT.delete(name);
|
|
2300
|
+
KEPT_DIRS.delete(name);
|
|
2301
|
+
}
|
|
2302
|
+
if (KEPT_DIRS.size === 0 && keptBeat !== undefined) {
|
|
2303
|
+
clearInterval(keptBeat);
|
|
2304
|
+
keptBeat = undefined;
|
|
2305
|
+
}
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2020
2309
|
/** Section 11. Never throws; touches only stale omr-ref-* dirs directly under a tmp root. */
|
|
2021
2310
|
export async function gcStaleReferences(root: string, deps: ReferenceDeps): Promise<GcReport> {
|
|
2022
2311
|
const report = { removed: [] as string[], kept: [] as string[], failed: [] as string[] };
|
|
@@ -2082,7 +2371,7 @@ async function gcInner(
|
|
|
2082
2371
|
const key = comparable(dir, platform);
|
|
2083
2372
|
const keys = [key];
|
|
2084
2373
|
const ownLock = entry.locked && isOwnLockReason(dir, entry.lockReason, platform);
|
|
2085
|
-
if ((entry.locked && !ownLock) || ACTIVE.has(key)) {
|
|
2374
|
+
if ((entry.locked && !ownLock) || ACTIVE.has(key) || isReferenceKept(dir)) {
|
|
2086
2375
|
report.kept.push(dir);
|
|
2087
2376
|
continue;
|
|
2088
2377
|
}
|
|
@@ -2159,7 +2448,7 @@ async function gcInner(
|
|
|
2159
2448
|
continue;
|
|
2160
2449
|
}
|
|
2161
2450
|
const keys = [comparable(dir, platform), comparable(realDir, platform)];
|
|
2162
|
-
if (keys.some((k) => registered.has(k) || ACTIVE.has(k))) continue;
|
|
2451
|
+
if (isReferenceKept(name) || keys.some((k) => registered.has(k) || ACTIVE.has(k))) continue;
|
|
2163
2452
|
if (!stale(parsed.pid, stats, keys)) {
|
|
2164
2453
|
report.kept.push(dir);
|
|
2165
2454
|
continue;
|
|
@@ -2182,4 +2471,4 @@ async function gcInner(
|
|
|
2182
2471
|
}
|
|
2183
2472
|
}
|
|
2184
2473
|
}
|
|
2185
|
-
}
|
|
2474
|
+
}
|
package/src/verify/risk.ts
CHANGED
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
* | 7 | a test file (incl. snapshots) was modified (added, changed, renamed) | medium |
|
|
34
34
|
* | 8 | a non-test file was deleted or any file was renamed | medium |
|
|
35
35
|
* | 9 | config / lock / CI / test-setup file changed (see isConfigPath) | medium |
|
|
36
|
-
* | 10 | scoping impossible (Unverifiable, S6)
|
|
36
|
+
* | 10 | scoping impossible (Unverifiable, S6), or the full suite runs | medium |
|
|
37
|
+
* | | (FullScopePlan: REASONS.fullScope instead) | |
|
|
37
38
|
* | 11 | producer tier "fast" | medium |
|
|
38
39
|
* | 12 | no reference captured | +1 step (max high) |
|
|
39
40
|
*
|
|
@@ -50,12 +51,22 @@ import type { ChangedPath, StaticScoping } from "./runner";
|
|
|
50
51
|
export type RiskLevel = "low" | "medium" | "high";
|
|
51
52
|
export type ProducerTier = "fast" | "medium" | "heavy" | (string & {});
|
|
52
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Cross-repo P2e (QA-1 #6): the scoping "plan" of a DoD whose every testsPass check runs the full suite (`scope=full`, or the
|
|
56
|
+
* dispatch's full scope): nothing is planned, so it is neither scoped nor S6. Row 10 then rates it medium with the neutral
|
|
57
|
+
* REASONS.fullScope instead of REASONS.unverifiable.
|
|
58
|
+
*/
|
|
59
|
+
export interface FullScopePlan {
|
|
60
|
+
readonly fullScope: true;
|
|
61
|
+
}
|
|
62
|
+
export const FULL_SCOPE_PLAN: FullScopePlan = { fullScope: true };
|
|
63
|
+
|
|
53
64
|
export interface RiskInput {
|
|
54
65
|
readonly changedFiles: readonly ChangedPath[];
|
|
55
66
|
/** Whether a reference (baseline) exists for this delegation. Only presence matters. */
|
|
56
67
|
readonly reference: boolean;
|
|
57
68
|
readonly producerTier: ProducerTier;
|
|
58
|
-
readonly scopingPlan: StaticScoping;
|
|
69
|
+
readonly scopingPlan: StaticScoping | FullScopePlan;
|
|
59
70
|
/** Git root; absolute changed paths are made relative to it before classification. */
|
|
60
71
|
readonly root?: string;
|
|
61
72
|
}
|
|
@@ -79,6 +90,7 @@ export const REASONS = {
|
|
|
79
90
|
deletedOrRenamed: "files were deleted or renamed",
|
|
80
91
|
configChanged: "config, lock or CI files changed",
|
|
81
92
|
unverifiable: "scoping impossible (S6): the change cannot be verified by scoped tests",
|
|
93
|
+
fullScope: "the full suite runs (scope=full)",
|
|
82
94
|
noAffected: "no affected tests found by static scoping",
|
|
83
95
|
fastTier: "produced by the fast tier",
|
|
84
96
|
noReference: "no reference captured: risk raised one step",
|
|
@@ -257,7 +269,8 @@ export function assessRisk(input: RiskInput): RiskAssessment {
|
|
|
257
269
|
hit("medium", REASONS.configChanged);
|
|
258
270
|
}
|
|
259
271
|
|
|
260
|
-
if ("
|
|
272
|
+
if ("fullScope" in scopingPlan && scopingPlan.fullScope === true) hit("medium", REASONS.fullScope);
|
|
273
|
+
else if ("unverifiable" in scopingPlan && scopingPlan.unverifiable === true) hit("medium", REASONS.unverifiable);
|
|
261
274
|
else if ("noAffected" in scopingPlan && scopingPlan.noAffected === true) reasons.push(REASONS.noAffected);
|
|
262
275
|
|
|
263
276
|
if (producerTier === "fast") hit("medium", REASONS.fastTier);
|