@staix/agent-hub 0.38.0 → 0.39.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 +45 -0
- package/README.md +17 -7
- package/docs/adding-an-ai-tool.md +6 -4
- package/docs/agent-notes/README.md +16 -0
- package/docs/agent-notes/adapters.md +4 -2
- package/docs/agent-notes/budget.md +8 -0
- package/docs/agent-notes/daemon.md +15 -8
- package/docs/agent-notes/local-worker.md +1 -1
- package/docs/agent-notes/security-review.md +55 -0
- package/docs/agent-notes/tasks.md +15 -4
- package/docs/agent-notes/tests.md +3 -2
- package/docs/design/adapters.md +51 -0
- package/docs/design/agent-hub-architecture.md +29 -1
- package/docs/design/task-board.md +151 -5
- package/docs/dogfood.md +20 -6
- package/docs/events.md +3 -3
- package/docs/memory.md +5 -5
- package/docs/operations.md +177 -28
- package/docs/profiles.md +100 -8
- package/docs/quickstart.md +32 -4
- package/docs/research.md +6 -3
- package/docs/roles.md +52 -0
- package/docs/sdlc.md +187 -1
- package/docs/security.md +50 -11
- package/docs/text-projection.md +1 -0
- package/docs/verification/2026-11-13-claude-implementer-2.1.323.md +59 -0
- package/docs/verification/2026-11-13-codex-01672-reviewer-isolation.md +69 -0
- package/docs/verification/2026-11-14-0.39.0.md +51 -0
- package/docs/verified.json +48 -25
- package/package.json +3 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +1953 -460
- package/plugins/agent-hub/server.js +2019 -498
- package/src/adapters/acp-model-policy.ts +1 -1
- package/src/adapters/acp-session-model.ts +35 -0
- package/src/adapters/acp.ts +14 -0
- package/src/adapters/agy/definition.ts +1 -1
- package/src/adapters/agy/hooks.ts +7 -0
- package/src/adapters/claude-channel.ts +1 -1
- package/src/adapters/claude-implementer.ts +8 -0
- package/src/adapters/claude-print-child.ts +26 -2
- package/src/adapters/claude-print.ts +4 -0
- package/src/adapters/codex-appserver.ts +90 -16
- package/src/adapters/codex-review-isolation.ts +2 -0
- package/src/adapters/compat.ts +4 -4
- package/src/adapters/conformance/fakes/acp-server.ts +11 -2
- package/src/adapters/conformance/fakes/app-server.ts +5 -1
- package/src/adapters/conformance/fakes/pi-rpc.ts +1 -1
- package/src/adapters/definitions/builtin-metadata.ts +6 -6
- package/src/adapters/definitions/native-cli-jcode-mcp.ts +18 -3
- package/src/adapters/definitions/native-quota.ts +122 -0
- package/src/adapters/definitions/native-recovery.ts +3 -0
- package/src/adapters/definitions/qwen.ts +1 -1
- package/src/adapters/kimi-review.ts +23 -0
- package/src/adapters/kimi-wire-usage.ts +39 -16
- package/src/adapters/local-worker.ts +6 -3
- package/src/adapters/pi-state-model.ts +12 -0
- package/src/adapters/pi.ts +22 -0
- package/src/adapters/print-result-model.ts +24 -0
- package/src/adapters/registry-types.ts +10 -1
- package/src/adapters/registry.ts +19 -2
- package/src/adapters/reviewer-print.ts +130 -15
- package/src/adapters/role-eligibility.ts +99 -0
- package/src/adapters/same-directory.ts +16 -0
- package/src/cli/agy-mcp.ts +18 -7
- package/src/cli/console-state.ts +3 -1
- package/src/cli/free-text.ts +20 -0
- package/src/cli/handoff-args.ts +1 -1
- package/src/cli/help.ts +61 -6
- package/src/cli/identity.ts +10 -4
- package/src/cli/init-prompt.ts +31 -2
- package/src/cli/init-roles.ts +156 -0
- package/src/cli/init-settings.ts +24 -2
- package/src/cli/init.ts +139 -17
- package/src/cli/main.ts +194 -49
- package/src/cli/model.ts +1 -1
- package/src/cli/output.ts +56 -1
- package/src/cli/preview.ts +1 -1
- package/src/cli/recovery-launch.ts +114 -0
- package/src/cli/recovery-package.ts +14 -7
- package/src/cli/recovery-version-preflight.ts +104 -0
- package/src/cli/role-doctor.ts +39 -0
- package/src/cli/sdlc-output.ts +66 -1
- package/src/cli/study-output.ts +54 -0
- package/src/cli/study.ts +14 -1
- package/src/cli/terminal-recovery.ts +14 -0
- package/src/cli/upgrade-presentation.ts +4 -0
- package/src/cli/upgrade-restore-state.ts +12 -3
- package/src/cli/upgrade-runtime.ts +40 -2
- package/src/cli/upgrade.ts +8 -4
- package/src/hub/advisor-survey.ts +139 -0
- package/src/hub/audit-source.ts +66 -0
- package/src/hub/board.ts +479 -14
- package/src/hub/budget.ts +54 -4
- package/src/hub/conductor.ts +14 -8
- package/src/hub/config-apply.ts +2 -1
- package/src/hub/config-edit-host.ts +77 -5
- package/src/hub/considered-findings.ts +47 -0
- package/src/hub/control-client.ts +1 -1
- package/src/hub/daemon.ts +343 -58
- package/src/hub/deliverable-files.ts +17 -1
- package/src/hub/dogfood-profile.ts +3 -2
- package/src/hub/events.ts +23 -2
- package/src/hub/folder-trigger.ts +11 -4
- package/src/hub/hub-tools.ts +88 -16
- package/src/hub/kimi-usage.ts +34 -2
- package/src/hub/lifecycle-schema.ts +3 -3
- package/src/hub/memory-profile.ts +9 -1
- package/src/hub/memory-sync-state.ts +1 -0
- package/src/hub/model-overrides.ts +2 -1
- package/src/hub/no-writes.ts +2 -0
- package/src/hub/operational-authority.ts +6 -1
- package/src/hub/operational-view.ts +5 -1
- package/src/hub/peers.ts +2 -0
- package/src/hub/plan-conformance.ts +20 -2
- package/src/hub/quota-account.ts +34 -0
- package/src/hub/recovery-policy.ts +18 -4
- package/src/hub/research-evidence.ts +51 -3
- package/src/hub/research.ts +77 -13
- package/src/hub/restart.ts +14 -0
- package/src/hub/review-budget.ts +88 -0
- package/src/hub/review-findings.ts +93 -12
- package/src/hub/reviewer-pool-config.ts +6 -2
- package/src/hub/reviewer-pool.ts +39 -6
- package/src/hub/routing.ts +7 -3
- package/src/hub/sdlc-merge.ts +1 -1
- package/src/hub/sdlc-queue.ts +14 -4
- package/src/hub/sdlc-release.ts +1 -1
- package/src/hub/sdlc.ts +10 -6
- package/src/hub/security-audit.ts +178 -0
- package/src/hub/security-pass.ts +115 -0
- package/src/hub/settings.ts +11 -5
- package/src/hub/source-read.ts +80 -2
- package/src/hub/sources.ts +57 -9
- package/src/hub/startup-event-seeds.ts +5 -3
- package/src/hub/startup-timing.ts +1 -0
- package/src/hub/synthesis-readiness.ts +279 -0
- package/src/hub/tasks.ts +1083 -69
- package/src/hub/text-projection.ts +11 -1
- package/src/memory/capture.ts +2 -1
- package/src/ui/index.html +3 -0
- package/src/ui/office-model.ts +11 -3
- package/src/ui/office-space.ts +50 -30
- package/src/ui/plugin.ts +21 -11
|
@@ -3,6 +3,8 @@ import { sanitize } from "./envelope.ts";
|
|
|
3
3
|
import { parseReviewAnchor } from "./review-anchor.ts";
|
|
4
4
|
import type { ReviewAnchor } from "@staix/agent-console/contract";
|
|
5
5
|
|
|
6
|
+
/** #1403 A1: the four things a security finding must name: who is lower-trust, the control meant to hold, the resource affected and the result observed. */
|
|
7
|
+
export interface FindingBoundary { principal: string; control: string; resource: string; result: string }
|
|
6
8
|
export interface ReviewFinding {
|
|
7
9
|
id: string;
|
|
8
10
|
pass: "bugs" | "security" | "compliance";
|
|
@@ -11,18 +13,32 @@ export interface ReviewFinding {
|
|
|
11
13
|
disposition: "open" | "fixed" | "false_positive" | "accepted";
|
|
12
14
|
rationale?: string;
|
|
13
15
|
anchor?: ReviewAnchor;
|
|
16
|
+
/** #1403 A1, important security findings only (an enabled lifecycle). `needs_validation` is a source-grounded hypothesis blocked on `blocker`; it never blocks approval. */
|
|
17
|
+
state?: "confirmed" | "needs_validation";
|
|
18
|
+
boundary?: FindingBoundary;
|
|
19
|
+
blocker?: string;
|
|
20
|
+
/** #1403 B4 (an enabled lifecycle). Absent reads as `introduced`; an open `pre_existing` Important never blocks and never carries across heads. */
|
|
21
|
+
origin?: "introduced" | "pre_existing";
|
|
14
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* How `parseReviewFindings` treats the #1403 fields. `off` (the default, lifecycle off): they are unknown fields, refused as before. `required` (advise and enforce): accepted, and an
|
|
25
|
+
* open important security finding must carry `state` and `boundary`. `stored`: a report this hub already validated, read back: the shapes are checked, nothing is required again.
|
|
26
|
+
*/
|
|
27
|
+
export type FindingContract = "off" | "required" | "stored";
|
|
15
28
|
export interface ReviewFindingSet { head?: string; items: ReviewFinding[] }
|
|
16
|
-
|
|
29
|
+
/** `openImportant` counts only findings that block approval; `needsValidation` and `preExisting` (open Important that do not) appear only when nonzero, so an off-mode readback is unchanged. */
|
|
30
|
+
export interface ReviewFindingTally { important: number; nit: number; openImportant: number; openNit: number; fixed: number; falsePositive: number; accepted: number; needsValidation?: number; preExisting?: number }
|
|
17
31
|
export const DEFAULT_MAX_NITS = 5;
|
|
18
32
|
const MAX_ITEMS = 64, MAX_BYTES = 64 * 1024;
|
|
19
33
|
const fail = (reason: string): never => { throw new Error("review findings: " + reason); };
|
|
20
|
-
|
|
34
|
+
const BASE_FIELDS = ["id", "pass", "severity", "path", "disposition", "rationale", "anchor"], SECURITY_FIELDS = ["state", "boundary", "blocker", "origin"];
|
|
35
|
+
const BOUNDARY_FIELDS = ["principal", "control", "resource", "result"] as const;
|
|
36
|
+
function fields(raw: unknown, allowed: readonly string[] = BASE_FIELDS): Record<string, PropertyDescriptor> {
|
|
21
37
|
if (!raw || typeof raw !== "object" || types.isProxy(raw) || Array.isArray(raw)
|
|
22
38
|
|| ![Object.prototype, null].includes(Object.getPrototypeOf(raw)) || Object.getOwnPropertySymbols(raw).length) return fail("plain own-data finding required");
|
|
23
39
|
const descriptors: Record<string, PropertyDescriptor> = Object.assign(Object.create(null), Object.getOwnPropertyDescriptors(raw));
|
|
24
40
|
if (Object.values(descriptors).some(field => !Object.hasOwn(field, "value") || !field.enumerable)) return fail("accessors and hidden fields refused");
|
|
25
|
-
if (Object.keys(descriptors).some(key => !
|
|
41
|
+
if (Object.keys(descriptors).some(key => !allowed.includes(key))) return fail("unknown finding field");
|
|
26
42
|
return descriptors;
|
|
27
43
|
}
|
|
28
44
|
function text(raw: unknown, max: number, path: boolean): string {
|
|
@@ -32,9 +48,17 @@ function text(raw: unknown, max: number, path: boolean): string {
|
|
|
32
48
|
if (Buffer.byteLength(clean) > max) return fail("sanitized finding text exceeds its bound");
|
|
33
49
|
return clean;
|
|
34
50
|
}
|
|
51
|
+
function boundaryOf(raw: unknown): FindingBoundary {
|
|
52
|
+
const given = fields(raw, BOUNDARY_FIELDS);
|
|
53
|
+
if (BOUNDARY_FIELDS.some(key => given[key] === undefined)) return fail("boundary needs principal, control, resource and result");
|
|
54
|
+
return Object.fromEntries(BOUNDARY_FIELDS.map(key => [key, text(given[key]!.value, 512, false)])) as unknown as FindingBoundary;
|
|
55
|
+
}
|
|
56
|
+
const NEEDS_SECURITY_FIELDS = "an important security finding needs state (confirmed or needs_validation) and boundary {principal, control, resource, result}: the lower-trust principal, the control that was meant to hold, the resource affected and the result observed; a missing best practice or a guessed deployment fact is not a finding";
|
|
35
57
|
/** Supplied findings are validated independently of lifecycle mode, before any board effect. */
|
|
36
|
-
export function parseReviewFindings(raw: unknown, options: { person: boolean; maxNits: number }): ReviewFinding[] {
|
|
58
|
+
export function parseReviewFindings(raw: unknown, options: { person: boolean; maxNits: number; contract?: FindingContract }): ReviewFinding[] {
|
|
37
59
|
if (typeof options.person !== "boolean" || !Number.isSafeInteger(options.maxNits) || options.maxNits < 0 || options.maxNits > MAX_ITEMS) return fail("invalid finding authority or nit limit");
|
|
60
|
+
const contract = options.contract ?? "off";
|
|
61
|
+
if (contract !== "off" && contract !== "required" && contract !== "stored") return fail("invalid finding contract");
|
|
38
62
|
if (raw === undefined) return [];
|
|
39
63
|
if (!Array.isArray(raw) || types.isProxy(raw) || Object.getPrototypeOf(raw) !== Array.prototype
|
|
40
64
|
|| Object.getOwnPropertySymbols(raw).length || raw.length > MAX_ITEMS) return fail("at most 64 own-data findings required");
|
|
@@ -44,7 +68,7 @@ export function parseReviewFindings(raw: unknown, options: { person: boolean; ma
|
|
|
44
68
|
const result = Array.from({ length: raw.length }, (_, index): ReviewFinding => {
|
|
45
69
|
const entry = descriptors[String(index)];
|
|
46
70
|
if (!entry || !Object.hasOwn(entry, "value") || !entry.enumerable) return fail("finding array accessors refused");
|
|
47
|
-
const item = fields(entry.value), id: unknown = item.id?.value, pass: unknown = item.pass?.value;
|
|
71
|
+
const item = fields(entry.value, contract === "off" ? BASE_FIELDS : [...BASE_FIELDS, ...SECURITY_FIELDS]), id: unknown = item.id?.value, pass: unknown = item.pass?.value;
|
|
48
72
|
const severity: unknown = item.severity?.value, disposition: unknown = item.disposition?.value;
|
|
49
73
|
if (typeof id !== "string" || !/^[A-Za-z0-9._:-]+$/.test(id) || Buffer.byteLength(id) > 96 || ids.has(id)) return fail("invalid or duplicate finding id");
|
|
50
74
|
ids.add(id);
|
|
@@ -56,19 +80,61 @@ export function parseReviewFindings(raw: unknown, options: { person: boolean; ma
|
|
|
56
80
|
const anchor = item.anchor ? parseReviewAnchor(item.anchor.value) : undefined;
|
|
57
81
|
if (path !== undefined && anchor && path !== anchor.path) return fail("path and anchor.path differ; use the same task-scoped file path");
|
|
58
82
|
if (disposition === "accepted" && (!options.person || !rationale)) return fail("accepted findings require a person and rationale");
|
|
59
|
-
|
|
83
|
+
// #1403: only an enabled lifecycle reaches here with these fields (off refused them as unknown above).
|
|
84
|
+
const state: unknown = item.state?.value, origin: unknown = item.origin?.value;
|
|
85
|
+
if (item.state && state !== "confirmed" && state !== "needs_validation") return fail("invalid finding state");
|
|
86
|
+
if (item.origin && origin !== "introduced" && origin !== "pre_existing") return fail("invalid finding origin");
|
|
87
|
+
const boundary = item.boundary ? boundaryOf(item.boundary.value) : undefined;
|
|
88
|
+
const blocker = item.blocker ? text(item.blocker.value, 512, false) : undefined;
|
|
89
|
+
if ((state !== undefined || boundary !== undefined || blocker !== undefined) && !(pass === "security" && severity === "important")) return fail("state, boundary and blocker apply only to important security findings");
|
|
90
|
+
if (contract === "required" && pass === "security" && severity === "important" && disposition === "open") {
|
|
91
|
+
if (state === undefined || boundary === undefined) return fail(NEEDS_SECURITY_FIELDS);
|
|
92
|
+
if (state === "needs_validation" && blocker === undefined) return fail("a needs_validation finding names its blocker: the missing fact that settles it");
|
|
93
|
+
if (state === "confirmed" && blocker !== undefined) return fail("a confirmed finding carries no blocker; use needs_validation for a hypothesis blocked on a named fact");
|
|
94
|
+
}
|
|
95
|
+
return { id, pass, severity, disposition, ...(path !== undefined ? { path } : {}), ...(rationale !== undefined ? { rationale } : {}), ...(anchor ? { anchor } : {}),
|
|
96
|
+
...(state !== undefined ? { state } : {}), ...(boundary !== undefined ? { boundary } : {}), ...(blocker !== undefined ? { blocker } : {}), ...(origin !== undefined ? { origin } : {}) } as ReviewFinding;
|
|
60
97
|
});
|
|
61
98
|
if (result.filter(item => item.severity === "nit").length > options.maxNits) return fail("nit limit exceeded");
|
|
62
99
|
if (Buffer.byteLength(JSON.stringify(result)) > MAX_BYTES) return fail("finding report exceeds 64 KiB");
|
|
63
100
|
return result;
|
|
64
101
|
}
|
|
65
102
|
|
|
103
|
+
/**
|
|
104
|
+
* #1436: a positional finding id is a review-local label (N1, F5, B1, nit-1, 3): a reviewer numbers its findings per review, so the same label on two tasks names two unrelated findings.
|
|
105
|
+
* Only a label word or a single letter followed by digits counts, so a semantic id (compliance:hub-task-id-written-as-github-ref, sha256-pin) still can recur across tasks. REVIEW.md asks for semantic ids.
|
|
106
|
+
*/
|
|
107
|
+
export function positionalFindingId(id: string): boolean {
|
|
108
|
+
const local = id.replace(/^(?:bugs|security|compliance)[-_.:]/i, "");
|
|
109
|
+
return /^(?:[a-z]|nits?|imp(?:ortant)?|finding|issue|bug|comment|note|item|sec|fix|review)?[-_.:]?\d{1,4}$/i.test(local);
|
|
110
|
+
}
|
|
111
|
+
|
|
66
112
|
/** Prefer live artifact identity, skipping malformed historical candidates rather than hiding a valid fallback. */
|
|
67
113
|
export function findingHead(receipt?: { head?: string; reviewedHead?: string; localHead?: string }, evidence?: { head: string }, commit?: string): string | undefined {
|
|
68
114
|
return [evidence?.head, receipt?.head, receipt?.reviewedHead, receipt?.localHead, commit]
|
|
69
115
|
.find((head): head is string => typeof head === "string" && /^[a-f0-9]{40}$/.test(head));
|
|
70
116
|
}
|
|
71
117
|
|
|
118
|
+
/** An open Important blocks approval unless it is a hypothesis awaiting a named fact (`needs_validation`) or debt the change did not introduce (`pre_existing`). */
|
|
119
|
+
export const blocksApproval = (item: ReviewFinding): boolean =>
|
|
120
|
+
item.severity === "important" && item.disposition === "open" && item.state !== "needs_validation" && item.origin !== "pre_existing";
|
|
121
|
+
/** What carries across heads: Important, except debt the reviewed change did not introduce. */
|
|
122
|
+
const carries = (item: ReviewFinding): boolean => item.severity === "important" && item.origin !== "pre_existing";
|
|
123
|
+
const SECURITY_KEYS = ["state", "boundary", "blocker", "origin"] as const;
|
|
124
|
+
/**
|
|
125
|
+
* A later report of an id, over its earlier one. The #1403 fields belong to the report that states them: a later report that omits `state`, `boundary`, `blocker` or `origin` has none of them
|
|
126
|
+
* (an omitted origin means introduced), so a reclassification (a hypothesis re-reported as a bug, a pre_existing one re-reported as introduced) blocks as reported. The one exception: a report
|
|
127
|
+
* that still says open cannot lower a finding that blocks approval, so that finding keeps its severity and its own four fields; only an explicit disposition settles it.
|
|
128
|
+
*/
|
|
129
|
+
function merged(prior: ReviewFinding | undefined, item: ReviewFinding): ReviewFinding {
|
|
130
|
+
const next: ReviewFinding = { ...prior, ...item };
|
|
131
|
+
for (const key of SECURITY_KEYS) if (item[key] === undefined) delete next[key];
|
|
132
|
+
if (prior && blocksApproval(prior) && item.disposition === "open" && !blocksApproval(item)) {
|
|
133
|
+
next.severity = "important";
|
|
134
|
+
for (const key of SECURITY_KEYS) { if (prior[key] === undefined) delete next[key]; else Object.assign(next, { [key]: prior[key] }); }
|
|
135
|
+
}
|
|
136
|
+
return next;
|
|
137
|
+
}
|
|
72
138
|
/**
|
|
73
139
|
* Nits belong only to their head bucket, including the explicit undefined bucket.
|
|
74
140
|
* Open Important is an obligation across heads until an explicit disposition resolves its ID globally.
|
|
@@ -81,11 +147,11 @@ export function findingsForHead(sets: readonly ReviewFindingSet[], head?: string
|
|
|
81
147
|
const key = item.id, position = order++;
|
|
82
148
|
if (set.head === head) current.set(key, { item: { ...current.get(key)?.item, ...item }, order: position });
|
|
83
149
|
const prior = important.get(key);
|
|
84
|
-
if (item
|
|
85
|
-
important.set(key, { item:
|
|
150
|
+
if (carries(item)) {
|
|
151
|
+
important.set(key, { item: merged(prior?.item, item), order: position });
|
|
86
152
|
} else if (prior && (prior.item.disposition === "open" || item.disposition !== "open")) {
|
|
87
|
-
// A nit/open reclassification cannot discharge Important. An explicit disposition can.
|
|
88
|
-
important.set(key, { item: { ...prior.item,
|
|
153
|
+
// A nit/open reclassification (a nit, or #1403 pre_existing) cannot discharge Important. An explicit disposition can.
|
|
154
|
+
important.set(key, { item: { ...merged(prior.item, item), severity: "important" }, order: position });
|
|
89
155
|
}
|
|
90
156
|
}
|
|
91
157
|
for (const [key, entry] of important) {
|
|
@@ -102,8 +168,23 @@ export function findingTally(items: readonly ReviewFinding[]): ReviewFindingTall
|
|
|
102
168
|
const tally: ReviewFindingTally = { important: 0, nit: 0, openImportant: 0, openNit: 0, fixed: 0, falsePositive: 0, accepted: 0 };
|
|
103
169
|
for (const item of items) {
|
|
104
170
|
tally[item.severity]++;
|
|
105
|
-
if (item.disposition === "open")
|
|
106
|
-
|
|
171
|
+
if (item.disposition === "open") {
|
|
172
|
+
if (item.severity === "nit") tally.openNit++;
|
|
173
|
+
else if (blocksApproval(item)) tally.openImportant++;
|
|
174
|
+
else if (item.state === "needs_validation") tally.needsValidation = (tally.needsValidation ?? 0) + 1;
|
|
175
|
+
else tally.preExisting = (tally.preExisting ?? 0) + 1;
|
|
176
|
+
} else tally[item.disposition === "false_positive" ? "falsePositive" : item.disposition]++;
|
|
107
177
|
}
|
|
108
178
|
return tally;
|
|
109
179
|
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* #1403: the open Important findings that do not block approval and so get one follow-up card on approval, over every report of the task (a hypothesis or debt is head-local or settled later, so
|
|
183
|
+
* the current head's view would lose it). `validation`: needs_validation, which wins over pre_existing; `preExisting`: debt the change did not introduce.
|
|
184
|
+
*/
|
|
185
|
+
export function findingFollowUps(sets: readonly ReviewFindingSet[]): { validation: ReviewFinding[]; preExisting: ReviewFinding[] } {
|
|
186
|
+
const latest = new Map<string, ReviewFinding>();
|
|
187
|
+
for (const set of sets) for (const item of set.items) latest.set(item.id, merged(latest.get(item.id), item));
|
|
188
|
+
const open = [...latest.values()].filter(item => item.severity === "important" && item.disposition === "open");
|
|
189
|
+
return { validation: open.filter(item => item.state === "needs_validation"), preExisting: open.filter(item => item.state !== "needs_validation" && item.origin === "pre_existing") };
|
|
190
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { MAX_REVIEW_MINUTES, type ReviewGate, type ReviewUnknownQuota } from "./review-budget.ts";
|
|
2
|
+
export interface ReviewerPoolConfig { pool: string[]; rerotate: boolean; sameFamily?: "never"; gate?: ReviewGate; unknownQuota?: ReviewUnknownQuota; maxMinutes?: number }
|
|
2
3
|
|
|
3
4
|
/** Kind order is project policy; capability and isolation evidence remain host-owned registry facts. */
|
|
4
5
|
export function reviewerPoolConfig(raw: unknown, defaults: readonly string[], known: readonly string[]): ReviewerPoolConfig {
|
|
@@ -8,5 +9,8 @@ export function reviewerPoolConfig(raw: unknown, defaults: readonly string[], kn
|
|
|
8
9
|
if (!Array.isArray(pool) || pool.length < 1 || pool.length > 16 || pool.some(kind => typeof kind !== "string" || !/^[a-z][a-z0-9-]{0,31}$/.test(kind) || !known.includes(kind)) || new Set(pool).size !== pool.length) throw new Error("review.pool must list 1..16 distinct known kinds");
|
|
9
10
|
if (value.rerotate !== undefined && typeof value.rerotate !== "boolean") throw new Error("review.rerotate must be a boolean");
|
|
10
11
|
if (value.same_family !== undefined && value.same_family !== "fallback" && value.same_family !== "never") throw new Error("review.same_family must be \"fallback\" or \"never\"");
|
|
11
|
-
|
|
12
|
+
if (value.gate !== undefined && value.gate !== "off" && (typeof value.gate !== "number" || !Number.isFinite(value.gate) || value.gate < 0 || value.gate > 1)) throw new Error('review.gate must be "off" or a finite number in 0..1');
|
|
13
|
+
if (value.unknown_quota !== undefined && value.unknown_quota !== "skip" && value.unknown_quota !== "pass") throw new Error('review.unknown_quota must be "skip" or "pass"');
|
|
14
|
+
if (value.max_minutes !== undefined && (typeof value.max_minutes !== "number" || !Number.isFinite(value.max_minutes) || value.max_minutes <= 0 || value.max_minutes > MAX_REVIEW_MINUTES)) throw new Error("review.max_minutes must be positive and within the timer bound");
|
|
15
|
+
return { pool: [...pool], rerotate: value.rerotate === true, ...(value.same_family === "never" ? { sameFamily: "never" as const } : {}), ...(value.gate === undefined ? {} : { gate: value.gate as ReviewGate }), ...(value.unknown_quota === undefined ? {} : { unknownQuota: value.unknown_quota as ReviewUnknownQuota }), ...(value.max_minutes === undefined ? {} : { maxMinutes: value.max_minutes as number }) };
|
|
12
16
|
}
|
package/src/hub/reviewer-pool.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { reviewBudgetAdmission, type ReviewBudgetSnapshot } from "./review-budget.ts";
|
|
1
2
|
export type ReviewerPoolReason = "rotation" | "implementer skip" | "unavailable skip" | "same-family fallback";
|
|
2
3
|
export interface ReviewerPoolCandidate { id: string; kind: string; family: string; blocked?: string }
|
|
3
4
|
export interface ReviewerPoolInput {
|
|
@@ -10,13 +11,17 @@ export interface ReviewerPoolInput {
|
|
|
10
11
|
failed?: readonly string[];
|
|
11
12
|
/** `never` (#820): an implementer-family candidate is never selected, not even as the last resort. */
|
|
12
13
|
sameFamily?: "fallback" | "never";
|
|
14
|
+
budget?: ReviewBudgetSnapshot;
|
|
15
|
+
waitForReset?: boolean;
|
|
13
16
|
}
|
|
14
17
|
export interface ReviewerPoolSelection {
|
|
15
18
|
reviewer: string | null;
|
|
16
19
|
family?: string;
|
|
17
20
|
reason?: ReviewerPoolReason;
|
|
21
|
+
admissionRule?: string;
|
|
18
22
|
walk: readonly { id: string; kind: string; family: string; reason: string }[];
|
|
19
23
|
blocked?: "no reviewer can run";
|
|
24
|
+
quotaWait?: { resetsAt: number; candidates: readonly { id: string; state: "paused" | "floor"; resetsAt: number }[] };
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/** Pure selection: caller supplies declared candidates and current availability, never inferred authority. */
|
|
@@ -28,7 +33,21 @@ export function selectReviewerPool(input: ReviewerPoolInput): ReviewerPoolSelect
|
|
|
28
33
|
// Blocked declarations still own their slot: current availability never changes the denominator.
|
|
29
34
|
const declaredKinds = kinds.filter(kind => input.candidates.some(candidate => candidate.kind === kind));
|
|
30
35
|
const undeclared = kinds.filter(kind => !declaredKinds.includes(kind)).map(kind => ({ id: "", kind, family: "", reason: "no declared reviewer" }));
|
|
31
|
-
const finish = (selection: Omit<ReviewerPoolSelection, "walk">): ReviewerPoolSelection =>
|
|
36
|
+
const finish = (selection: Omit<ReviewerPoolSelection, "walk">): ReviewerPoolSelection => {
|
|
37
|
+
let quotaWait: ReviewerPoolSelection["quotaWait"];
|
|
38
|
+
if (selection.reviewer === null && input.budget && input.budget.gate !== "off" && input.waitForReset !== false) {
|
|
39
|
+
const candidates = input.candidates.filter(candidate => kinds.includes(candidate.kind)), failed = new Set(input.failed ?? []);
|
|
40
|
+
const waiting = candidates.map(candidate => ({ candidate, reading: reviewBudgetAdmission(candidate.id, input.budget!) }));
|
|
41
|
+
if (waiting.length && waiting.every(({ candidate, reading }) => !failed.has(candidate.id)
|
|
42
|
+
&& !(input.sameFamily === "never" && candidate.family === input.implementerFamily)
|
|
43
|
+
&& (candidate.blocked === undefined || candidate.blocked === "paused" && reading.state === "paused" || candidate.blocked === "quota exhausted" && (reading.state === "paused" || reading.state === "floor"))
|
|
44
|
+
&& (reading.state === "paused" || reading.state === "floor") && reading.resetsAt !== undefined)) {
|
|
45
|
+
const rows = waiting.map(({ candidate, reading }) => ({ id: candidate.id, state: reading.state as "paused" | "floor", resetsAt: reading.resetsAt! }));
|
|
46
|
+
quotaWait = { resetsAt: Math.min(...rows.map(row => row.resetsAt)), candidates: rows };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { ...selection, walk: [...walk, ...undeclared], ...(quotaWait ? { quotaWait } : {}) };
|
|
50
|
+
};
|
|
32
51
|
if (!declaredKinds.length) return finish({ reviewer: null, blocked: "no reviewer can run" });
|
|
33
52
|
const seed = Number.isSafeInteger(input.seed) ? input.seed : 0;
|
|
34
53
|
const start = ((seed % declaredKinds.length) + declaredKinds.length) % declaredKinds.length;
|
|
@@ -43,7 +62,19 @@ export function selectReviewerPool(input: ReviewerPoolInput): ReviewerPoolSelect
|
|
|
43
62
|
if (continuity) ordered = [...ordered.filter(candidate => candidate.family === input.continuityFamily), ...ordered.filter(candidate => candidate.family !== input.continuityFamily)];
|
|
44
63
|
const failed = new Set(input.failed ?? []);
|
|
45
64
|
let skippedOwner = false, skippedUnavailable = false;
|
|
46
|
-
const unavailable = (candidate: ReviewerPoolCandidate) =>
|
|
65
|
+
const unavailable = (candidate: ReviewerPoolCandidate) => {
|
|
66
|
+
if (failed.has(candidate.id)) return "start failed for this review";
|
|
67
|
+
const quota = input.budget ? reviewBudgetAdmission(candidate.id, input.budget) : undefined;
|
|
68
|
+
const numericQuotaDisabled = candidate.blocked === "quota exhausted" && input.budget?.gate === "off" && quota?.state === "available";
|
|
69
|
+
if (candidate.blocked !== undefined && !numericQuotaDisabled && !(candidate.blocked === "paused" && quota?.state === "paused")
|
|
70
|
+
&& !(candidate.blocked === "quota exhausted" && (quota?.state === "paused" || quota?.state === "floor"))) return candidate.blocked;
|
|
71
|
+
return quota && quota.state !== "available" ? quota.reason : numericQuotaDisabled ? undefined : candidate.blocked;
|
|
72
|
+
};
|
|
73
|
+
const admissionRule = (candidate: ReviewerPoolCandidate) => input.budget ? reviewBudgetAdmission(candidate.id, input.budget).rule : undefined;
|
|
74
|
+
const selectedRule = (candidate: ReviewerPoolCandidate, prefix: string) => {
|
|
75
|
+
const rule = admissionRule(candidate);
|
|
76
|
+
return rule ? `${prefix}; admitted by ${rule}` : prefix;
|
|
77
|
+
};
|
|
47
78
|
const record = (candidate: ReviewerPoolCandidate, reason: string) => { walk.push({ id: candidate.id, kind: candidate.kind, family: candidate.family, reason }); };
|
|
48
79
|
for (const candidate of ordered) {
|
|
49
80
|
if (!candidate.id) {
|
|
@@ -63,8 +94,9 @@ export function selectReviewerPool(input: ReviewerPoolInput): ReviewerPoolSelect
|
|
|
63
94
|
continue;
|
|
64
95
|
}
|
|
65
96
|
const reason: ReviewerPoolReason = skippedUnavailable ? "unavailable skip" : skippedOwner ? "implementer skip" : "rotation";
|
|
66
|
-
record(candidate, `selected (${continuity && candidate.family === input.continuityFamily ? "continuity" : reason})`);
|
|
67
|
-
|
|
97
|
+
record(candidate, selectedRule(candidate, `selected (${continuity && candidate.family === input.continuityFamily ? "continuity" : reason})`));
|
|
98
|
+
const rule = admissionRule(candidate);
|
|
99
|
+
return finish({ reviewer: candidate.id, family: candidate.family, reason, ...(rule ? { admissionRule: rule } : {}) });
|
|
68
100
|
}
|
|
69
101
|
// The caller supplies separate fresh reviewer instances; this does not authorize an implementer's own session.
|
|
70
102
|
if (input.sameFamily === "never") return finish({ reviewer: null, blocked: "no reviewer can run" });
|
|
@@ -72,8 +104,9 @@ export function selectReviewerPool(input: ReviewerPoolInput): ReviewerPoolSelect
|
|
|
72
104
|
if (!candidate.id || input.implementerFamily === undefined || candidate.family !== input.implementerFamily) continue;
|
|
73
105
|
const blocked = unavailable(candidate);
|
|
74
106
|
if (blocked !== undefined) { record(candidate, `unavailable skip: ${blocked}`); continue; }
|
|
75
|
-
record(candidate, "selected (same-family fallback)");
|
|
76
|
-
|
|
107
|
+
record(candidate, selectedRule(candidate, "selected (same-family fallback)"));
|
|
108
|
+
const rule = admissionRule(candidate);
|
|
109
|
+
return finish({ reviewer: candidate.id, family: candidate.family, reason: "same-family fallback", ...(rule ? { admissionRule: rule } : {}) });
|
|
77
110
|
}
|
|
78
111
|
return finish({ reviewer: null, blocked: "no reviewer can run" });
|
|
79
112
|
}
|
package/src/hub/routing.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { contextHeadroom, type ContextAdmission } from "./context-window.ts";
|
|
2
2
|
import { queueBackpressure, type QueueBackpressureCode, type QueueBackpressurePolicy, type QueuePressure } from "./queue-backpressure.ts";
|
|
3
3
|
import { selectReviewerPool, type ReviewerPoolSelection } from "./reviewer-pool.ts";
|
|
4
|
+
import type { ReviewBudgetSnapshot } from "./review-budget.ts";
|
|
4
5
|
import { ADAPTERS, definitionOf, kindOf, familyOf, type ProjectAdapterCatalog } from "../adapters/registry.ts";
|
|
5
6
|
import { readFileSync, statSync } from "node:fs";
|
|
6
7
|
import { join, resolve } from "node:path";
|
|
@@ -444,7 +445,7 @@ export function assign(
|
|
|
444
445
|
namedPlanner?: PeerId;
|
|
445
446
|
/** The planner already recorded on the task (525-2): kept while it is still a holder. */
|
|
446
447
|
keptPlanner?: PeerId;
|
|
447
|
-
reviewPool?: { pool: readonly string[]; rerotate?: boolean; failed?: readonly string[]; required?: boolean; sameFamily?: "fallback" | "never" };
|
|
448
|
+
reviewPool?: { pool: readonly string[]; rerotate?: boolean; failed?: readonly string[]; required?: boolean; sameFamily?: "fallback" | "never"; budget?: ReviewBudgetSnapshot; waitForReset?: boolean };
|
|
448
449
|
candidates?: PeerId[];
|
|
449
450
|
notReviewer?: PeerId;
|
|
450
451
|
waitsFor?: number[];
|
|
@@ -674,10 +675,13 @@ export function assign(
|
|
|
674
675
|
const continuityFamily = last && "reviewerFamily" in last && typeof last.reviewerFamily === "string" ? last.reviewerFamily : last ? (opts.adapterCatalog?.familyOf ?? familyOf)(last.by, opts.instances) : undefined;
|
|
675
676
|
const pr = task.sdlc?.pr;
|
|
676
677
|
const seed = typeof pr === "number" && Number.isSafeInteger(pr) && pr > 0 ? pr : task.id ?? 0;
|
|
677
|
-
reviewSelection = selectReviewerPool({ pool: opts.reviewPool!.pool, candidates: declaredPool, seed, implementerFamily: ownerFamily, continuityFamily, rerotate: opts.reviewPool!.rerotate, failed: opts.reviewPool!.failed, ...(neverSame ? { sameFamily: "never" as const } : {}) });
|
|
678
|
+
reviewSelection = selectReviewerPool({ pool: opts.reviewPool!.pool, candidates: declaredPool, seed, implementerFamily: ownerFamily, continuityFamily, rerotate: opts.reviewPool!.rerotate, failed: opts.reviewPool!.failed, waitForReset: opts.reviewPool!.waitForReset, ...(opts.reviewPool!.budget ? { budget: opts.reviewPool!.budget } : {}), ...(neverSame ? { sameFamily: "never" as const } : {}) });
|
|
678
679
|
for (const row of reviewSelection.walk) trace.push(row.id ? ` reviewer pool candidate ${row.id} (${row.family}): ${row.reason}` : ` reviewer pool kind ${row.kind}: ${row.reason}`);
|
|
679
680
|
reviewer = reviewSelection.reviewer ?? "user";
|
|
680
|
-
if (reviewSelection.
|
|
681
|
+
if (reviewSelection.quotaWait) {
|
|
682
|
+
reviewBlocked = true;
|
|
683
|
+
trace.push(` waiting for reviewer quota; reset recheck at ${new Date(reviewSelection.quotaWait.resetsAt).toISOString()}`);
|
|
684
|
+
} else if (reviewSelection.blocked) {
|
|
681
685
|
trace.push("blocked: no reviewer can run");
|
|
682
686
|
// Optional defaults retain the legacy planner escape when no fresh reviewer can run.
|
|
683
687
|
const planners = opts.reviewPool?.required && !neverSame ? [] : automatic.filter(peer => peer !== reviewOwner && peerEntry(opts.roles, peer)?.includes("planner") && (!neverSame || peerEntry(opts.roles, peer)?.includes("reviewer") === true) && !(opts.adapterCatalog?.definitionOf ?? definitionOf)(peer, opts.instances)?.routing?.reviewOnly && !blocked(peer, "reviewer"));
|
package/src/hub/sdlc-merge.ts
CHANGED
|
@@ -57,7 +57,7 @@ const REPO = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
|
57
57
|
* threads, draft). Its other blockers (identity, local gate, GitHub approval) are the lifecycle's, not this merge's, and are not repeated here.
|
|
58
58
|
*/
|
|
59
59
|
const QUEUE_BLOCKERS = [/^touching PRs require a person order$/, /^dependency /, /^artifact dependency cycle/, /^open PR /, /^PR file coverage is incomplete/,
|
|
60
|
-
/^required check .*: not successful on current head$/, /^review requests pending or unknown$/, /^review threads unresolved or unknown$/, /^PR is draft or draft status is unknown
|
|
60
|
+
/^required check .*: not successful on current head$/, /^review requests pending or unknown$/, /^review threads unresolved or unknown$/, /^PR is draft or draft status is unknown$/, /^security pass (required|applicability unknown)/];
|
|
61
61
|
|
|
62
62
|
/** The mode that applies to one repository: its own table first, then the top-level key, default off. */
|
|
63
63
|
export function mergeModeFor(config: SdlcConfig, repo: string | undefined): AutoMergeMode {
|
package/src/hub/sdlc-queue.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { publicTestIntegrity, parseIssueLabels, readTestIntegrity, testIntegrity
|
|
|
2
2
|
import { planConformance, planConformanceBlockers } from "./plan-conformance.ts";
|
|
3
3
|
import { evalGapBlockers, evalGateView, readEvalFor, type EvalGate } from "./eval-gate.ts";
|
|
4
4
|
import { findingsForHead, findingHead, findingTally, type ReviewFindingSet, type ReviewFindingTally } from "./review-findings.ts";
|
|
5
|
+
import { securityPassBlockers, securityPassView, type SecurityPassRecord, type SecurityPassView } from "./security-pass.ts";
|
|
5
6
|
import type { CriteriaView } from "./workflow.ts";
|
|
6
7
|
import { parsePrEvidence, readSdlcPr, sdlcGh, sdlcStatus, type PrEvidence, type SdlcConfig, type SdlcGh, type SdlcReceipt } from "./sdlc.ts";
|
|
7
8
|
export interface DeliveryTask {
|
|
@@ -9,10 +10,15 @@ export interface DeliveryTask {
|
|
|
9
10
|
latestHead?: string;
|
|
10
11
|
/** Host-derived verdict binding, never inferred from a mutable lifecycle receipt. */
|
|
11
12
|
approval?: { head?: string; latestHead?: string; mismatch: boolean; current: boolean };
|
|
12
|
-
plan?: { paths?: string[]; revision: number; fingerprint: string; accepted: { repo: string; pr: number; head: string; revision: number; fingerprint: string; paths: string[] }[] };
|
|
13
|
+
plan?: { paths?: string[]; out_of_scope?: string[]; revision: number; fingerprint: string; accepted: { repo: string; pr: number; head: string; revision: number; fingerprint: string; paths: string[] }[] };
|
|
13
14
|
findings?: readonly ReviewFindingSet[]; id: number; after: number[]; private: boolean; receipt?: SdlcReceipt; phase?: CriteriaView;
|
|
15
|
+
/** #1403 A2: the latest security pass an approving or rejecting verdict recorded, bound to the head it reviewed. */
|
|
16
|
+
securityPass?: SecurityPassRecord;
|
|
14
17
|
}
|
|
15
|
-
export interface MergeQueueRow { evalGate?: EvalGate; testIntegrity?: (TestIntegrity & { task?: number })[]; planConformance?: { task?: number; state: string; outside: number; untouched: number; accepted: boolean }[]; findings?: ReviewFindingTally; pr: number; tasks: number[]; head?: string; private?: true; ready: boolean; blockers: string[]; after: number[]; }
|
|
18
|
+
export interface MergeQueueRow { /** #1403 A2: required | recorded | not_required | unknown for this PR across its holders; the worst one wins. */ securityPass?: SecurityPassView; evalGate?: EvalGate; testIntegrity?: (TestIntegrity & { task?: number })[]; planConformance?: { task?: number; state: string; outside: number; untouched: number; accepted: boolean }[]; findings?: ReviewFindingTally; pr: number; tasks: number[]; head?: string; private?: true; ready: boolean; blockers: string[]; after: number[]; }
|
|
19
|
+
const SECURITY_ORDER: Record<SecurityPassView["state"], number> = { not_required: 0, recorded: 1, unknown: 2, required: 3 };
|
|
20
|
+
/** The stricter of two views of the same PR: a holder that left a required pass unrecorded decides the row. */
|
|
21
|
+
function worseSecurity(held: SecurityPassView | undefined, next: SecurityPassView): SecurityPassView { return held && SECURITY_ORDER[held.state] >= SECURITY_ORDER[next.state] ? held : next; }
|
|
16
22
|
export interface MergeConflict { left: number; right: number; files: number; order: "dependency" | "person_required"; }
|
|
17
23
|
export interface MergeQueue { repo: string; rows: MergeQueueRow[]; order: number[]; unordered?: number[]; conflicts: MergeConflict[]; complete: boolean; truncated: boolean; }
|
|
18
24
|
const validRepo = (value: string) => /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(value) && !value.startsWith("-");
|
|
@@ -83,7 +89,7 @@ export async function readMergeQueue(repo: string, config: SdlcConfig, tasks: De
|
|
|
83
89
|
if (!items.length) continue;
|
|
84
90
|
const tally = findingTally(items);
|
|
85
91
|
row.findings ??= findingTally([]);
|
|
86
|
-
for (const key of Object.keys(tally) as (keyof ReviewFindingTally)[]) row.findings[key]
|
|
92
|
+
for (const key of Object.keys(tally) as (keyof ReviewFindingTally)[]) row.findings[key] = (row.findings[key] ?? 0) + (tally[key] ?? 0);
|
|
87
93
|
}
|
|
88
94
|
if (!read.pathsComplete) row.blockers.push("PR file coverage is incomplete or unknown");
|
|
89
95
|
if (read.draft !== false) row.blockers.push("PR is draft or draft status is unknown");
|
|
@@ -91,7 +97,7 @@ export async function readMergeQueue(repo: string, config: SdlcConfig, tasks: De
|
|
|
91
97
|
const linked = holders.length ? holders : [undefined];
|
|
92
98
|
if (config.mode === "enforce" && row.findings?.openImportant) row.blockers.push("open important review findings: " + row.findings.openImportant);
|
|
93
99
|
for (const holder of linked) {
|
|
94
|
-
const conformance = holder?.plan ? { ...planConformance(holder.plan.paths, read), accepted: holder.plan.accepted.some(item => item.repo === holder.receipt?.repo && item.pr === holder.receipt?.pr && item.head === read.head && item.revision === holder.plan!.revision && item.fingerprint === holder.plan!.fingerprint && JSON.stringify([...item.paths].sort()) === JSON.stringify([...read.paths].sort())) } : undefined;
|
|
100
|
+
const conformance = holder?.plan ? { ...planConformance(holder.plan.paths, read, holder.plan.out_of_scope), accepted: holder.plan.accepted.some(item => item.repo === holder.receipt?.repo && item.pr === holder.receipt?.pr && item.head === read.head && item.revision === holder.plan!.revision && item.fingerprint === holder.plan!.fingerprint && JSON.stringify([...item.paths].sort()) === JSON.stringify([...read.paths].sort())) } : undefined;
|
|
95
101
|
if (holder && conformance && config.mode !== "off") (row.planConformance ??= []).push({ task: holder.id, state: conformance.state, outside: conformance.outside.length, untouched: conformance.untouched.length, accepted: conformance.accepted });
|
|
96
102
|
const rawIntegrity = config.mode !== "off" && holder?.receipt ? await readTestIntegrity(holder.receipt, read, bounded) : undefined;
|
|
97
103
|
if (rawIntegrity && holder?.receipt?.issue) {
|
|
@@ -112,8 +118,12 @@ export async function readMergeQueue(repo: string, config: SdlcConfig, tasks: De
|
|
|
112
118
|
if (gate) { row.evalGate = gate; if (config.mode === "enforce") row.blockers.push(...evalGapBlockers(gate)); }
|
|
113
119
|
}
|
|
114
120
|
if (config.mode === "enforce") row.blockers.push(...planConformanceBlockers(conformance), ...testIntegrityBlockers(integrity));
|
|
121
|
+
// #1403 A2: readable from the same complete inventory; a PR with several holders shows the strictest state. `unknown` is never softened to `not_required`.
|
|
122
|
+
const security = config.mode !== "off" ? securityPassView(config.security, read, holder?.securityPass) : undefined;
|
|
123
|
+
if (security) row.securityPass = worseSecurity(row.securityPass, security);
|
|
115
124
|
}
|
|
116
125
|
}
|
|
126
|
+
if (config.mode === "enforce") for (const row of result.rows) row.blockers.push(...securityPassBlockers(row.securityPass));
|
|
117
127
|
const dependencyEvidence = new Map<number, PrEvidence | undefined>(); let dependencyReads = 0;
|
|
118
128
|
for (const row of result.rows) {
|
|
119
129
|
if (row.private) continue;
|
package/src/hub/sdlc-release.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface ReleaseReportPolicy {
|
|
|
31
31
|
authorization: ReleaseReportAuthorizationState;
|
|
32
32
|
version?: string;
|
|
33
33
|
}
|
|
34
|
-
export interface ReleaseReadiness { /** #481 AC12: interval, approval-to-release lead time and hotfix rate over shipped releases, filled by Tasks.releaseReadiness. */ releaseMetrics?: ReturnType<typeof releaseMetrics>; releasePolicy?: ReleaseReportPolicy; repo: string; head?: string; version?: string; tag?: string; tagCommit?: string; commits: string[]; mergedPrs: { pr: number; commit: string }[]; documents?: DocEvidence; liveIssues: { id: number; state: "open" | "closed" | "unknown" }[]; blockers: string[]; sourceReady: boolean; native: "unverified"; ready: false; }
|
|
34
|
+
export interface ReleaseReadiness { /** #1403 A4: the newest security audit as counts only (ref, profile, partial, unit states, finding tallies); never a path, a finding or a blocker. */ securityAudit?: import("./security-audit.ts").AuditSummary; /** #481 AC12: interval, approval-to-release lead time and hotfix rate over shipped releases, filled by Tasks.releaseReadiness. */ releaseMetrics?: ReturnType<typeof releaseMetrics>; releasePolicy?: ReleaseReportPolicy; repo: string; head?: string; version?: string; tag?: string; tagCommit?: string; commits: string[]; mergedPrs: { pr: number; commit: string }[]; documents?: DocEvidence; liveIssues: { id: number; state: "open" | "closed" | "unknown" }[]; blockers: string[]; sourceReady: boolean; native: "unverified"; ready: false; }
|
|
35
35
|
export type ReleaseGit = (args: string[]) => { code: number; stdout: string };
|
|
36
36
|
export interface ReleaseReaders { gh?: SdlcGh; git?: ReleaseGit; docs?: (root: string, timeoutMs: number) => Promise<DocEvidence | undefined>; /** Host-only selected authorization/config metadata; absent preserves standalone package.json behavior. */ reportPolicy?: (head: string, repo: string) => ReleaseReportPolicy | undefined; /** Test seam (#1120): the checker program the default docs reader spawns. */ checker?: string; }
|
|
37
37
|
const SHA = /^[0-9a-f]{40}$/;
|
package/src/hub/sdlc.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { controlWriteSpan } from "./control-write-trace.ts";
|
|
|
4
4
|
import { DEFAULT_MAX_NITS, findingsForHead, findingHead, findingTally, type ReviewFindingSet, type ReviewFindingTally } from "./review-findings.ts";
|
|
5
5
|
import type { CostPlan } from "./cost-governance.ts";
|
|
6
6
|
import { bandsConfig, type BandsConfig } from "./sdlc-metrics.ts";
|
|
7
|
+
import { securityPassBlockers, securityPolicy, type SecurityPassView, type SecurityPolicy } from "./security-pass.ts";
|
|
7
8
|
import { configPathList, evalGapBlockers, evalGateView, evalRequiredChecks, type EvalGate, type EvalResult } from "./eval-gate.ts";
|
|
8
9
|
import { SECURITY_SOURCES, type SecuritySource } from "./security-baseline.ts";
|
|
9
10
|
import { criteriaReceipt, type CriteriaReceipt, type CriteriaView, type LegacyPhaseReceipt } from "./workflow.ts";
|
|
@@ -43,7 +44,7 @@ export const AUTO_MERGE_MODES: readonly AutoMergeMode[] = ["off", "dry-run", "on
|
|
|
43
44
|
export interface SecurityScanConfig { everyH: number; sources: SecuritySource[]; repo?: string }
|
|
44
45
|
/** #786: one repository's own gate: its required checks (before the top-level list) and its own merge mode. */
|
|
45
46
|
export interface RepoMergePolicy { requiredChecks?: string[]; autoMerge?: AutoMergeMode }
|
|
46
|
-
export interface SdlcConfig { workflow?: "gsd-lite"; maxNits?: number; /** #481 S7: optional control bands per metric; absent means none. */ bands?: BandsConfig; /** #481 S7: the scheduled security-scan baseline; absent means none is scheduled. */ securityScan?: SecurityScanConfig; /** #481 S5: the one check a configuration PR needs; no default, the person names it. */ evalCheck?: string; /** #481 S5: patterns that mark a PR as a configuration change; absent reads as the defaults in eval-gate.ts, an empty list turns the gate off. */ configPaths?: string[]; mode: SdlcMode; requiredChecks: string[]; /** #786: absent reads as "off"; written only when the file names it. */ autoMerge?: AutoMergeMode; /** #786: per-repository tables, keyed by lowercase owner/name. */ repos?: Record<string, RepoMergePolicy>; stages: SdlcStage[]; definitions?: Record<string, StageDefinition>; deprecations?: string[]; }
|
|
47
|
+
export interface SdlcConfig { workflow?: "gsd-lite"; maxNits?: number; /** #481 S7: optional control bands per metric; absent means none. */ bands?: BandsConfig; /** #481 S7: the scheduled security-scan baseline; absent means none is scheduled. */ securityScan?: SecurityScanConfig; /** #481 S5: the one check a configuration PR needs; no default, the person names it. */ evalCheck?: string; /** #481 S5: patterns that mark a PR as a configuration change; absent reads as the defaults in eval-gate.ts, an empty list turns the gate off. */ configPaths?: string[]; /** #1403 A2: sensitive paths that need a recorded security pass, and the review companions that apply; absent means the feature is off. */ security?: SecurityPolicy; mode: SdlcMode; requiredChecks: string[]; /** #786: absent reads as "off"; written only when the file names it. */ autoMerge?: AutoMergeMode; /** #786: per-repository tables, keyed by lowercase owner/name. */ repos?: Record<string, RepoMergePolicy>; stages: SdlcStage[]; definitions?: Record<string, StageDefinition>; deprecations?: string[]; }
|
|
47
48
|
export interface PlanReviewReceipt {
|
|
48
49
|
planner: string;
|
|
49
50
|
planAuthor?: string | null;
|
|
@@ -201,7 +202,7 @@ export function sdlcConfig(value: unknown, version?: string): SdlcConfig {
|
|
|
201
202
|
if (value === undefined) return { mode: "off", requiredChecks: [], stages: [...SDLC_STAGES] };
|
|
202
203
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("sdlc: expected a table");
|
|
203
204
|
const raw = value as Record<string, unknown>;
|
|
204
|
-
for (const key of Object.keys(raw)) if (!["mode", "required_checks", "stages", "workflow", "definitions", "max_nits", "bands", "auto_merge", "repos", "eval_check", "config_paths", "security_scan"].includes(key)) throw new Error(`sdlc.${key}: unknown field`);
|
|
205
|
+
for (const key of Object.keys(raw)) if (!["mode", "required_checks", "stages", "workflow", "definitions", "max_nits", "bands", "auto_merge", "repos", "eval_check", "config_paths", "security_scan", "security"].includes(key)) throw new Error(`sdlc.${key}: unknown field`);
|
|
205
206
|
const maxNits = raw.max_nits === undefined ? DEFAULT_MAX_NITS : raw.max_nits;
|
|
206
207
|
if (typeof maxNits !== "number" || !Number.isSafeInteger(maxNits) || maxNits < 0 || maxNits > 64) throw new Error("sdlc.max_nits: expected an integer from 0 to 64");
|
|
207
208
|
const bands = bandsConfig(raw.bands), bandConfig = Object.keys(bands).length ? { bands } : {};
|
|
@@ -209,7 +210,7 @@ export function sdlcConfig(value: unknown, version?: string): SdlcConfig {
|
|
|
209
210
|
...(raw.eval_check === undefined ? {} : { evalCheck: evalCheckName(raw.eval_check) }),
|
|
210
211
|
...(raw.config_paths === undefined ? {} : { configPaths: configPathList(raw.config_paths, "sdlc.config_paths") }),
|
|
211
212
|
};
|
|
212
|
-
const findingConfig = { ...(raw.max_nits === undefined ? {} : { maxNits }), ...bandConfig, ...evalConfig, ...(raw.security_scan === undefined ? {} : { securityScan: securityScanConfig(raw.security_scan) }) };
|
|
213
|
+
const findingConfig = { ...(raw.max_nits === undefined ? {} : { maxNits }), ...bandConfig, ...evalConfig, ...(raw.security_scan === undefined ? {} : { securityScan: securityScanConfig(raw.security_scan) }), ...(raw.security === undefined ? {} : { security: securityPolicy(raw.security) }) };
|
|
213
214
|
const mode = raw.mode ?? "off";
|
|
214
215
|
if (mode !== "off" && mode !== "advise" && mode !== "enforce") throw new Error("sdlc.mode: expected off, advise or enforce");
|
|
215
216
|
// ponytail: the #481 S8 window is a fixed version; delete `workflow`, the phase aliases and their tests once it passes.
|
|
@@ -387,10 +388,10 @@ export const SPEC_STATE_TEXT: Record<Exclude<SpecState, "current">, string> = {
|
|
|
387
388
|
changed: "spec changed after acceptance: the person re-accepts with ahub sdlc accept <task> --issue <n>",
|
|
388
389
|
unknown: "spec edit time unknown: the issue could not be read",
|
|
389
390
|
};
|
|
390
|
-
export interface SdlcStatus { evalGate?: EvalGate; testIntegrity?: TestIntegrity; planConformance?: PlanConformance & { accepted?: boolean; earlierPushes?: "unknown"; revisionsAfterFirstObservedPush?: number }; findings?: ReviewFindingTally; spec?: { issue: number; state: SpecState }; playbook?: string; criteria?: CriteriaView; mode: SdlcMode; stage: SdlcStage; definition?: StageDefinition; entry?: string[]; exit?: string[]; blockers: string[]; ready: boolean; actor: string; next: string; }
|
|
391
|
+
export interface SdlcStatus { /** #1403 A2: shown only for an enabled lifecycle that configures `[security]`. */ securityPass?: SecurityPassView; evalGate?: EvalGate; testIntegrity?: TestIntegrity; planConformance?: PlanConformance & { accepted?: boolean; earlierPushes?: "unknown"; revisionsAfterFirstObservedPush?: number }; findings?: ReviewFindingTally; spec?: { issue: number; state: SpecState }; playbook?: string; criteria?: CriteriaView; mode: SdlcMode; stage: SdlcStage; definition?: StageDefinition; entry?: string[]; exit?: string[]; blockers: string[]; ready: boolean; actor: string; next: string; }
|
|
391
392
|
/** The acceptance-criteria checklist (#481 S8, Compliance pass) counts once recorded, and on every task under the retired gsd-lite setting. Off keeps #257's output. */
|
|
392
393
|
export const criteriaRequired = (config: SdlcConfig, receipt: SdlcReceipt | undefined): boolean => config.workflow === "gsd-lite" || (config.mode !== "off" && !!checklistOf(receipt));
|
|
393
|
-
export function sdlcStatus(config: SdlcConfig, receipt: SdlcReceipt | undefined, evidence?: PrEvidence, criteria?: CriteriaView, specEdit?: SpecEdit, sets: readonly ReviewFindingSet[] = [], commit?: string, plan?: SdlcStatus["planConformance"], integrity?: TestIntegrity, evalResult?: EvalResult): SdlcStatus {
|
|
394
|
+
export function sdlcStatus(config: SdlcConfig, receipt: SdlcReceipt | undefined, evidence?: PrEvidence, criteria?: CriteriaView, specEdit?: SpecEdit, sets: readonly ReviewFindingSet[] = [], commit?: string, plan?: SdlcStatus["planConformance"], integrity?: TestIntegrity, evalResult?: EvalResult, securityPass?: SecurityPassView): SdlcStatus {
|
|
394
395
|
const stage = receipt?.stage ?? config.stages[0] ?? "spec", blockers: string[] = [];
|
|
395
396
|
const definition = stageDefinition(config, stage);
|
|
396
397
|
const evalGate = evidence ? evalGateView(config, evidence, evalResult) : undefined;
|
|
@@ -398,6 +399,9 @@ export function sdlcStatus(config: SdlcConfig, receipt: SdlcReceipt | undefined,
|
|
|
398
399
|
const findings = items.length ? findingTally(items) : undefined;
|
|
399
400
|
if (config.mode === "enforce" && findings?.openImportant) blockers.push("open important review findings: " + findings.openImportant);
|
|
400
401
|
if (config.mode === "enforce") blockers.push(...planConformanceBlockers(plan), ...testIntegrityBlockers(integrity));
|
|
402
|
+
// #1403 A2: a required pass that is not recorded, or an applicability the inventory cannot settle, blocks only in enforce; advise shows it in `securityPass` and the advice notice.
|
|
403
|
+
const security = config.mode !== "off" ? securityPass : undefined;
|
|
404
|
+
if (config.mode === "enforce") blockers.push(...securityPassBlockers(security));
|
|
401
405
|
if (!definition) blockers.push("lifecycle stage definition unknown");
|
|
402
406
|
if (!receipt?.repo || !receipt.issue) blockers.push("issue identity missing");
|
|
403
407
|
if (!receipt?.pr) blockers.push("PR identity missing");
|
|
@@ -426,7 +430,7 @@ export function sdlcStatus(config: SdlcConfig, receipt: SdlcReceipt | undefined,
|
|
|
426
430
|
const shown = criteria && (criteriaRequired(config, receipt) || definition && [...definition.entry_gates, ...definition.exit_gates].includes("criteria"));
|
|
427
431
|
// Shown, not counted as a readiness blocker: the spec gate is build entry (#481 S1).
|
|
428
432
|
const spec = config.mode !== "off" && receipt?.issue ? { spec: { issue: receipt.issue, state: specState(receipt, specEdit) } } : {};
|
|
429
|
-
return { ...spec, ...(evalGate ? { evalGate } : {}), ...(config.mode !== "off" && integrity ? { testIntegrity: integrity } : {}), ...(config.mode !== "off" && plan ? { planConformance: plan } : {}), ...(findings ? { findings } : {}), ...(config.mode !== "off" && definition && playbookStage(definition.base) ? { playbook: playbookStage(definition.base) } : {}), ...(shown ? { criteria } : {}), ...(custom ? { definition, ...custom } : {}), mode: config.mode, stage, blockers, ready: blockers.length === 0,
|
|
433
|
+
return { ...spec, ...(security ? { securityPass: security } : {}), ...(evalGate ? { evalGate } : {}), ...(config.mode !== "off" && integrity ? { testIntegrity: integrity } : {}), ...(config.mode !== "off" && plan ? { planConformance: plan } : {}), ...(findings ? { findings } : {}), ...(config.mode !== "off" && definition && playbookStage(definition.base) ? { playbook: playbookStage(definition.base) } : {}), ...(shown ? { criteria } : {}), ...(custom ? { definition, ...custom } : {}), mode: config.mode, stage, blockers, ready: blockers.length === 0,
|
|
430
434
|
actor: !definition ? "person" : shown && criteria.blockers.length ? "reviewer/person" : config.definitions ? definition.actor : baseActor(definition.base),
|
|
431
435
|
// #694: the identity blocker keeps its exact text for gate matching; the next step says how to supply it.
|
|
432
436
|
next: blockers[0] === "issue identity missing" ? "issue identity missing: name one issue (title #N, refs or hub_sdlc_record)" : blockers[0] ?? "person may inspect merge readiness; no automatic merge" };
|