@staix/agent-hub 0.19.0 → 0.21.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 +70 -3
- package/README.md +2 -2
- package/docs/agent-notes/README.md +11 -0
- package/docs/agent-notes/adapters.md +10 -5
- package/docs/agent-notes/benchmarks.md +27 -0
- package/docs/agent-notes/budget.md +2 -1
- package/docs/agent-notes/bus.md +3 -3
- package/docs/agent-notes/daemon.md +20 -7
- package/docs/agent-notes/local-worker.md +5 -0
- package/docs/agent-notes/models.md +2 -0
- package/docs/agent-notes/tasks.md +20 -10
- package/docs/agent-notes/tests.md +13 -5
- package/docs/bench.md +1 -1
- package/docs/data-policy.md +2 -0
- package/docs/dogfood.md +41 -5
- package/docs/events.md +2 -1
- package/docs/memory.md +9 -3
- package/docs/operations.md +598 -63
- package/docs/profiles.md +13 -1
- package/docs/quickstart.md +18 -9
- package/docs/research.md +7 -4
- package/docs/sdlc.md +66 -10
- package/docs/security.md +397 -35
- package/docs/smoke.md +127 -0
- package/docs/specs/2026-09-19-agent-hub-design.md +1149 -19
- package/docs/verification/2026-10-27-0.19.0.md +5 -5
- package/docs/verification/2026-10-27-0.20.0.md +75 -0
- package/docs/verification/2026-10-28-claude-2.1.311-2.1.312-bash-permission.json +635 -0
- package/docs/verification/2026-10-28-claude-2.1.311-2.1.312-permission-transport.json +403 -0
- package/docs/verification/2026-10-28-claude-implementer-permission-triage.md +123 -0
- package/docs/verification/2026-10-28-jcode-0.99.1-usage.md +41 -0
- package/docs/verification/2026-10-28-realpath-name-audit.md +222 -0
- package/docs/verification/2026-10-28-routing-f0bb8ad0.md +1000 -0
- package/docs/verification/2026-10-29-0.21.0.md +61 -0
- package/docs/verification/2026-10-29-model-effort-capabilities.md +123 -0
- package/docs/verification/2026-10-29-modelrouting-b152ddb9.md +953 -0
- package/docs/verification/claude-implementer-permission-triage.ts +160 -0
- package/docs/verification/claude-permission-transport-native.py +71 -14
- package/docs/verification/profiles/YYYY-MM-DD-research.md +1 -1
- package/docs/verified.json +26 -18
- package/package.json +2 -2
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/server.js +1116 -284
- package/src/adapters/acp.ts +87 -3
- package/src/adapters/channel-peer.ts +11 -5
- package/src/adapters/claude-channel.ts +13 -6
- package/src/adapters/claude-implementer.ts +61 -7
- package/src/adapters/codex-appserver.ts +88 -5
- package/src/adapters/conformance/enrollment.ts +4 -4
- package/src/adapters/conformance/factories.ts +2 -1
- package/src/adapters/conformance/fakes/jcode-agent.ts +6 -2
- package/src/adapters/conformance/kit.ts +10 -6
- package/src/adapters/definitions/builtin-metadata.ts +3 -114
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/definitions/native-config-policy.ts +3 -2
- package/src/adapters/definitions/native-context.ts +12 -0
- package/src/adapters/external-metadata.ts +48 -0
- package/src/adapters/external-modules.ts +63 -3
- package/src/adapters/jcode.ts +6 -2
- package/src/adapters/local-worker.ts +42 -25
- package/src/adapters/native-proof-ports.ts +10 -0
- package/src/adapters/pi.ts +7 -0
- package/src/adapters/registry-types.ts +4 -0
- package/src/adapters/reviewer-print.ts +1 -0
- package/src/broker/protocol.ts +203 -0
- package/src/broker/server.ts +314 -0
- package/src/broker/store.ts +548 -0
- package/src/cli/bench.ts +3 -2
- package/src/cli/broker.ts +58 -0
- package/src/cli/conductor-recovery.ts +142 -0
- package/src/cli/configured-acp-entry.ts +26 -6
- package/src/cli/console-state.ts +59 -17
- package/src/cli/console.ts +17 -2
- package/src/cli/facts-hook.ts +3 -1
- package/src/cli/help.ts +28 -16
- package/src/cli/identity.ts +23 -10
- package/src/cli/init.ts +34 -7
- package/src/cli/intake-output.ts +33 -0
- package/src/cli/main.ts +314 -71
- package/src/cli/output.ts +41 -1
- package/src/cli/recovery-package.ts +18 -1
- package/src/cli/role-holders.ts +35 -0
- package/src/cli/room.ts +304 -0
- package/src/cli/say-input.ts +16 -0
- package/src/cli/schedule-output.ts +49 -0
- package/src/cli/sdlc-output.ts +44 -6
- package/src/cli/smoke-pty-bridge.ts +33 -0
- package/src/cli/smoke-pty.ts +145 -0
- package/src/cli/smoke-run.ts +139 -0
- package/src/cli/smoke-target.ts +130 -0
- package/src/cli/source-output.ts +29 -0
- package/src/cli/task-output.ts +3 -2
- package/src/cli/upgrade-runtime.ts +98 -16
- package/src/cli/upgrade.ts +66 -7
- package/src/hub/ask.ts +76 -12
- package/src/hub/board.ts +132 -22
- package/src/hub/bus.ts +399 -56
- package/src/hub/child-process.ts +2 -0
- package/src/hub/ci-watch.ts +162 -0
- package/src/hub/claude-failure-stage.ts +85 -0
- package/src/hub/claude-launch-proof.ts +67 -2
- package/src/hub/claude-shell-wrapper.ts +11 -5
- package/src/hub/conductor.ts +17 -4
- package/src/hub/config-apply.ts +32 -5
- package/src/hub/config-reload.ts +7 -5
- package/src/hub/config-trust.ts +8 -1
- package/src/hub/context-window.ts +33 -3
- package/src/hub/control-client.ts +14 -2
- package/src/hub/corpus-config.ts +34 -0
- package/src/hub/corpus-evidence.ts +184 -0
- package/src/hub/corpus.ts +373 -0
- package/src/hub/cost-governance.ts +26 -0
- package/src/hub/daemon.ts +1228 -242
- package/src/hub/deliverable-files.ts +8 -2
- package/src/hub/delivery-journal.ts +123 -17
- package/src/hub/dogfood-profile.ts +32 -5
- package/src/hub/dogfood-read.ts +6 -2
- package/src/hub/envelope.ts +11 -0
- package/src/hub/eval-gate.ts +131 -0
- package/src/hub/events.ts +1 -1
- package/src/hub/external-instance.ts +69 -0
- package/src/hub/facts.ts +15 -5
- package/src/hub/folder-trigger.ts +223 -0
- package/src/hub/hub-tools.ts +2 -1
- package/src/hub/inference.ts +20 -5
- package/src/hub/instance-config.ts +69 -3
- package/src/hub/instance-execution.ts +6 -2
- package/src/hub/instances.ts +32 -4
- package/src/hub/intake.ts +125 -0
- package/src/hub/learning.ts +85 -0
- package/src/hub/lifecycle.ts +7 -3
- package/src/hub/limits.ts +12 -5
- package/src/hub/native-permission-request.ts +77 -0
- package/src/hub/operational-authority.ts +63 -5
- package/src/hub/operational-settings.ts +76 -0
- package/src/hub/operational-view.ts +1 -1
- package/src/hub/packs.ts +132 -0
- package/src/hub/path-policy.ts +7 -0
- package/src/hub/peer-doing.ts +130 -0
- package/src/hub/peers.ts +46 -0
- package/src/hub/queue-backpressure.ts +58 -0
- package/src/hub/read-tools.ts +2 -0
- package/src/hub/recovery-authority.ts +151 -0
- package/src/hub/recovery-policy.ts +220 -0
- package/src/hub/research.ts +24 -14
- package/src/hub/restart.ts +7 -0
- package/src/hub/routing.ts +54 -11
- package/src/hub/schedules.ts +266 -0
- package/src/hub/sdlc-merge.ts +38 -14
- package/src/hub/sdlc-metrics.ts +32 -10
- package/src/hub/sdlc-queue.ts +7 -1
- package/src/hub/sdlc-release.ts +1 -1
- package/src/hub/sdlc.ts +37 -7
- package/src/hub/security-baseline.ts +38 -0
- package/src/hub/settings.ts +7 -1
- package/src/hub/shipped-packs.ts +8 -0
- package/src/hub/snapshots.ts +72 -6
- package/src/hub/source-read.ts +160 -0
- package/src/hub/sources.ts +311 -0
- package/src/hub/task-shell-default.ts +3 -2
- package/src/hub/tasks.ts +1047 -115
- package/src/hub/workflow.ts +1 -1
- package/src/local/deny.ts +21 -0
- package/src/local/doc-read.ts +69 -0
- package/src/local/proxy.ts +4 -13
- package/src/local/sandbox.ts +3 -1
- package/src/local/tools.ts +37 -3
- package/src/local/web-fetch-config.ts +43 -0
- package/src/local/web-fetch.ts +183 -0
- package/src/memory/brief.ts +85 -13
- package/src/memory/capture.ts +1 -1
- package/src/rooms/application.ts +114 -0
- package/src/rooms/boundary.ts +103 -0
- package/src/rooms/commands.ts +294 -0
- package/src/rooms/crypto.ts +371 -0
- package/src/rooms/link.ts +584 -0
- package/src/rooms/policy.ts +82 -0
- package/src/rooms/remote-peer.ts +80 -0
- package/src/rooms/service.ts +426 -0
- package/src/rooms/status.ts +146 -0
- package/src/rooms/store.ts +1210 -0
- package/src/rooms/wire.ts +465 -0
- package/src/ui/index.html +91 -4
- package/templates/packs/example.pack.json +13 -0
package/src/hub/sdlc-metrics.ts
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
// A metric that cannot be derived is `unknown` and counted as such, never 0.
|
|
3
3
|
// `first_pass_check` reads the hub's own completion check (`check passed` / `check failed` at hub_task_done), not PR CI: it is unknown where completion checks are off.
|
|
4
4
|
|
|
5
|
-
export const BAND_METRICS = ["acceptance_to_plan_ms", "acceptance_to_first_review_ms", "first_pass_approval", "rework_rounds", "first_pass_check", "stale_head_re_reviews"] as const;
|
|
5
|
+
export const BAND_METRICS = ["acceptance_to_plan_ms", "acceptance_to_first_review_ms", "first_pass_approval", "rework_rounds", "first_pass_check", "stale_head_re_reviews", "hotfix_rate", "security_open_alerts"] as const;
|
|
6
6
|
export type BandMetric = typeof BAND_METRICS[number];
|
|
7
|
+
/** Metrics whose series is not made of tasks: one value per shipped release (`hotfix_rate`, 1 for a hotfix) or per recorded security scan (`security_open_alerts`). The caller supplies them; the point's `task` is then a release or scan id. */
|
|
8
|
+
export const EXTERNAL_METRICS: readonly BandMetric[] = ["hotfix_rate", "security_open_alerts"];
|
|
9
|
+
export type SeriesPoint = { value: number; task: number };
|
|
7
10
|
export const BAND_TIERS = ["ok", "log", "diagnose", "propose"] as const;
|
|
8
11
|
export type BandTier = typeof BAND_TIERS[number];
|
|
9
12
|
|
|
@@ -30,6 +33,10 @@ export interface TaskSample {
|
|
|
30
33
|
first_pass_check: 0 | 1 | null;
|
|
31
34
|
same_head_ci_reruns: number | null;
|
|
32
35
|
stale_head_re_reviews: number | null;
|
|
36
|
+
/** #481 S7 merge-time readback: review handoffs (dones) up to the merge, CI runs of the merged PR and GitHub reviews on it. Null where the merge was not read. */
|
|
37
|
+
review_rounds_at_merge: number | null;
|
|
38
|
+
ci_runs_at_merge: number | null;
|
|
39
|
+
github_reviews_at_merge: number | null;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
export interface Summary { n: number; unknown: number; mean: number | null; median: number | null; p90: number | null; max: number | null }
|
|
@@ -50,20 +57,23 @@ export interface BandResult {
|
|
|
50
57
|
lastTask: number | null;
|
|
51
58
|
/** The task whose value started the run of non-ok values this one belongs to, else null: one breach episode has one card. */
|
|
52
59
|
episode: number | null;
|
|
60
|
+
/** What `lastTask` and `episode` number: a task unless the metric is an external series (a release or a security scan). */
|
|
61
|
+
subject?: "task" | "release" | "scan";
|
|
53
62
|
}
|
|
63
|
+
export const SUBJECT: Partial<Record<BandMetric, "release" | "scan">> = { hotfix_rate: "release", security_open_alerts: "scan" };
|
|
54
64
|
|
|
55
65
|
/** Which way is worse. A rate that falls and a time that grows are both breaches. */
|
|
56
66
|
export const BAD_DIRECTION: Record<BandMetric, "up" | "down"> = {
|
|
57
|
-
acceptance_to_plan_ms: "up", acceptance_to_first_review_ms: "up", first_pass_approval: "down", rework_rounds: "up", first_pass_check: "down", stale_head_re_reviews: "up",
|
|
67
|
+
acceptance_to_plan_ms: "up", acceptance_to_first_review_ms: "up", first_pass_approval: "down", rework_rounds: "up", first_pass_check: "down", stale_head_re_reviews: "up", hotfix_rate: "up", security_open_alerts: "up",
|
|
58
68
|
};
|
|
59
69
|
const HOUR = 3_600_000;
|
|
60
70
|
/** Per-metric floor on the absolute deviation, so a flat baseline does not make every wobble a breach. */
|
|
61
71
|
export const DEFAULT_MIN_DELTA: Record<BandMetric, number> = {
|
|
62
|
-
acceptance_to_plan_ms: HOUR, acceptance_to_first_review_ms: HOUR, first_pass_approval: 0.5, rework_rounds: 1, first_pass_check: 0.5, stale_head_re_reviews: 1,
|
|
72
|
+
acceptance_to_plan_ms: HOUR, acceptance_to_first_review_ms: HOUR, first_pass_approval: 0.5, rework_rounds: 1, first_pass_check: 0.5, stale_head_re_reviews: 1, hotfix_rate: 0.5, security_open_alerts: 1,
|
|
63
73
|
};
|
|
64
74
|
/** Per-metric floor on the baseline deviation: a flat baseline (every value the same) must not turn one step into thousands of deviations. */
|
|
65
75
|
export const SD_FLOOR: Record<BandMetric, number> = {
|
|
66
|
-
acceptance_to_plan_ms: HOUR / 2, acceptance_to_first_review_ms: HOUR / 2, first_pass_approval: 0.5, rework_rounds: 0.5, first_pass_check: 0.5, stale_head_re_reviews: 0.5,
|
|
76
|
+
acceptance_to_plan_ms: HOUR / 2, acceptance_to_first_review_ms: HOUR / 2, first_pass_approval: 0.5, rework_rounds: 0.5, first_pass_check: 0.5, stale_head_re_reviews: 0.5, hotfix_rate: 0.5, security_open_alerts: 0.5,
|
|
67
77
|
};
|
|
68
78
|
export const DEFAULT_BAND: Omit<BandConfig, "minDelta"> = { window: 20, minSamples: 8, logSigma: 2, diagnoseSigma: 3, proposeSigma: 4, driftRun: 6 };
|
|
69
79
|
|
|
@@ -91,7 +101,7 @@ function staleHeadRounds(history: MetricTask["history"]): number | null {
|
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
/** One task's values from its own history. A private task never reaches here. */
|
|
94
|
-
export function taskSample(task: MetricTask, extra: { mergedAt?: number; ciReruns?: number | null } = {}): TaskSample {
|
|
104
|
+
export function taskSample(task: MetricTask, extra: { mergedAt?: number; ciReruns?: number | null; ciRuns?: number | null; reviews?: number | null } = {}): TaskSample {
|
|
95
105
|
const history = [...task.history].filter(entry => Number.isFinite(entry.at) && entry.at >= 0).sort((a, b) => a.at - b.at);
|
|
96
106
|
const view: MetricTask = { id: task.id, history };
|
|
97
107
|
const accepted = first(view, ["accepted"]);
|
|
@@ -116,6 +126,10 @@ export function taskSample(task: MetricTask, extra: { mergedAt?: number; ciRerun
|
|
|
116
126
|
rework_rounds: dones.length && approvedAt !== null ? history.filter(entry => entry.event === "changes_requested" && entry.evidenceOnly !== true).length : null,
|
|
117
127
|
first_pass_check: ci ? (ci.event === "check passed" ? 1 : 0) : null,
|
|
118
128
|
same_head_ci_reruns: extra.ciReruns === undefined ? null : extra.ciReruns,
|
|
129
|
+
// Counted only for a merged PR whose figures were read: a done before the merge is one review round.
|
|
130
|
+
review_rounds_at_merge: extra.mergedAt !== undefined && Number.isFinite(extra.mergedAt) ? dones.filter(entry => entry.at <= extra.mergedAt!).length : null,
|
|
131
|
+
ci_runs_at_merge: extra.ciRuns === undefined ? null : extra.ciRuns,
|
|
132
|
+
github_reviews_at_merge: extra.reviews === undefined ? null : extra.reviews,
|
|
119
133
|
stale_head_re_reviews: approvedAt !== null ? staleHeadRounds(history) : null,
|
|
120
134
|
};
|
|
121
135
|
}
|
|
@@ -131,7 +145,8 @@ export function summarize(values: readonly (number | null)[]): Summary {
|
|
|
131
145
|
const round = (value: number) => Math.round(value * 1000) / 1000;
|
|
132
146
|
|
|
133
147
|
/** The values of one metric in the order they happened, unknown ones left out. */
|
|
134
|
-
export
|
|
148
|
+
export type TaskMetric = Exclude<BandMetric, "hotfix_rate" | "security_open_alerts">;
|
|
149
|
+
export function series(samples: readonly TaskSample[], metric: TaskMetric): SeriesPoint[] {
|
|
135
150
|
const final = metric === "rework_rounds" || metric === "stale_head_re_reviews";
|
|
136
151
|
const when = (sample: TaskSample) => final ? sample.approved_at ?? sample.at : sample.at;
|
|
137
152
|
return [...samples].sort((a, b) => when(a) - when(b) || a.id - b.id).flatMap(sample => sample[metric] === null ? [] : [{ value: sample[metric] as number, task: sample.id }]);
|
|
@@ -172,7 +187,8 @@ export const EPISODE_LOOKBACK = 200;
|
|
|
172
187
|
* key for as long as it lasts, and it is derived from history alone, so it survives a restart.
|
|
173
188
|
*/
|
|
174
189
|
export function controlEpisode(points: readonly { value: number; task: number }[], metric: BandMetric, config: BandConfig): BandResult {
|
|
175
|
-
const
|
|
190
|
+
const subject = SUBJECT[metric];
|
|
191
|
+
const now = { ...controlBands(points, metric, config), ...(subject ? { subject } : {}) };
|
|
176
192
|
if (now.tier === "ok") return now;
|
|
177
193
|
let start = points.length - 1;
|
|
178
194
|
for (let end = points.length - 2; end >= 0 && points.length - 1 - end <= EPISODE_LOOKBACK; end--) {
|
|
@@ -193,7 +209,10 @@ export interface MetricsReport {
|
|
|
193
209
|
first_pass_check: { n: number; unknown: number; rate: number | null };
|
|
194
210
|
same_head_ci_reruns: Summary;
|
|
195
211
|
stale_head_re_reviews: Summary;
|
|
212
|
+
review_rounds_at_merge: Summary; ci_runs_at_merge: Summary; github_reviews_at_merge: Summary;
|
|
196
213
|
};
|
|
214
|
+
/** Merged PRs whose review and CI figures were read at merge, and how many of the counted tasks have none (unknown, never 0). */
|
|
215
|
+
merged: { read: number; unknown: number };
|
|
197
216
|
stalls: StallCounts;
|
|
198
217
|
bands: BandResult[] | "off";
|
|
199
218
|
}
|
|
@@ -207,12 +226,12 @@ const rate = (values: readonly (number | null)[]) => {
|
|
|
207
226
|
* The whole report from board tasks. `since` keeps samples that count at or after it; `mergedAt` and `ciReruns` come from bounded
|
|
208
227
|
* PR readbacks keyed by task id and are optional. Private tasks are counted as withheld and read for nothing else.
|
|
209
228
|
*/
|
|
210
|
-
export function sdlcMetrics(tasks: readonly MetricTask[], opts: { since?: number; bands?: BandsConfig; stalls?: StallCounts; mergedAt?: Readonly<Record<number, number>>; ciReruns?: Readonly<Record<number, number | null>> } = {}): MetricsReport {
|
|
229
|
+
export function sdlcMetrics(tasks: readonly MetricTask[], opts: { since?: number; bands?: BandsConfig; stalls?: StallCounts; mergedAt?: Readonly<Record<number, number>>; ciReruns?: Readonly<Record<number, number | null>>; ciRuns?: Readonly<Record<number, number | null>>; reviews?: Readonly<Record<number, number | null>>; external?: Partial<Record<BandMetric, readonly SeriesPoint[]>> } = {}): MetricsReport {
|
|
211
230
|
const visible = tasks.filter(task => !task.private);
|
|
212
|
-
const all = visible.map(task => taskSample(task, { mergedAt: opts.mergedAt?.[task.id], ciReruns: opts.ciReruns?.[task.id] }));
|
|
231
|
+
const all = visible.map(task => taskSample(task, { mergedAt: opts.mergedAt?.[task.id], ciReruns: opts.ciReruns?.[task.id], ciRuns: opts.ciRuns?.[task.id], reviews: opts.reviews?.[task.id] }));
|
|
213
232
|
const samples = opts.since === undefined ? all : all.filter(sample => sample.at >= opts.since!);
|
|
214
233
|
const bands: BandResult[] | "off" = opts.bands && Object.keys(opts.bands).length
|
|
215
|
-
? BAND_METRICS.flatMap(metric => opts.bands![metric] ? [controlEpisode(series(samples, metric), metric, opts.bands![metric]!)] : [])
|
|
234
|
+
? BAND_METRICS.flatMap(metric => opts.bands![metric] ? [controlEpisode(EXTERNAL_METRICS.includes(metric) ? [...(opts.external?.[metric] ?? [])] : series(samples, metric as TaskMetric), metric, opts.bands![metric]!)] : [])
|
|
216
235
|
: "off";
|
|
217
236
|
return {
|
|
218
237
|
since: opts.since ?? null, tasks: samples.length, withheldPrivate: tasks.length - visible.length,
|
|
@@ -222,7 +241,10 @@ export function sdlcMetrics(tasks: readonly MetricTask[], opts: { since?: number
|
|
|
222
241
|
first_pass_approval: rate(samples.map(s => s.first_pass_approval)), rework_rounds: summarize(samples.map(s => s.rework_rounds)),
|
|
223
242
|
first_pass_check: rate(samples.map(s => s.first_pass_check)), same_head_ci_reruns: summarize(samples.map(s => s.same_head_ci_reruns)),
|
|
224
243
|
stale_head_re_reviews: summarize(samples.map(s => s.stale_head_re_reviews)),
|
|
244
|
+
review_rounds_at_merge: summarize(samples.map(s => s.review_rounds_at_merge)), ci_runs_at_merge: summarize(samples.map(s => s.ci_runs_at_merge)),
|
|
245
|
+
github_reviews_at_merge: summarize(samples.map(s => s.github_reviews_at_merge)),
|
|
225
246
|
},
|
|
247
|
+
merged: { read: samples.filter(s => s.ci_runs_at_merge !== null || s.github_reviews_at_merge !== null).length, unknown: samples.filter(s => s.ci_runs_at_merge === null && s.github_reviews_at_merge === null).length },
|
|
226
248
|
stalls: opts.stalls ?? { open: 0, byKind: {}, doneWithoutWrites: 0 }, bands,
|
|
227
249
|
};
|
|
228
250
|
}
|
package/src/hub/sdlc-queue.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { publicTestIntegrity, parseIssueLabels, readTestIntegrity, testIntegrityBlockers, type TestIntegrity } from "./test-integrity.ts";
|
|
2
2
|
import { planConformance, planConformanceBlockers } from "./plan-conformance.ts";
|
|
3
|
+
import { evalGapBlockers, evalGateView, readEvalFor, type EvalGate } from "./eval-gate.ts";
|
|
3
4
|
import { findingsForHead, findingHead, findingTally, type ReviewFindingSet, type ReviewFindingTally } from "./review-findings.ts";
|
|
4
5
|
import type { CriteriaView } from "./workflow.ts";
|
|
5
6
|
import { parsePrEvidence, readSdlcPr, sdlcGh, sdlcStatus, type PrEvidence, type SdlcConfig, type SdlcGh, type SdlcReceipt } from "./sdlc.ts";
|
|
6
7
|
export interface DeliveryTask { plan?: { paths?: string[]; revision: number; fingerprint: string; accepted: { repo: string; pr: number; head: string; revision: number; fingerprint: string; paths: string[] }[] }; findings?: readonly ReviewFindingSet[]; id: number; after: number[]; private: boolean; receipt?: SdlcReceipt; phase?: CriteriaView; }
|
|
7
|
-
export interface MergeQueueRow { 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[]; }
|
|
8
|
+
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[]; }
|
|
8
9
|
export interface MergeConflict { left: number; right: number; files: number; order: "dependency" | "person_required"; }
|
|
9
10
|
export interface MergeQueue { repo: string; rows: MergeQueueRow[]; order: number[]; unordered?: number[]; conflicts: MergeConflict[]; complete: boolean; truncated: boolean; }
|
|
10
11
|
const validRepo = (value: string) => /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(value) && !value.startsWith("-");
|
|
@@ -93,6 +94,11 @@ export async function readMergeQueue(repo: string, config: SdlcConfig, tasks: De
|
|
|
93
94
|
const integrity = rawIntegrity ? publicTestIntegrity(rawIntegrity, readableMetadata) : undefined;
|
|
94
95
|
if (integrity) (row.testIntegrity ??= []).push({ task: holder!.id, ...integrity });
|
|
95
96
|
row.blockers.push(...sdlcStatus(config, holder?.receipt, read, holder?.phase).blockers);
|
|
97
|
+
// #481 S5: the eval check itself is a required check inside sdlcStatus; its recorded pass rate and suite are read once per PR here.
|
|
98
|
+
if (!row.evalGate) {
|
|
99
|
+
const gate = evalGateView(config, read, await readEvalFor(config, read, repo, bounded));
|
|
100
|
+
if (gate) { row.evalGate = gate; if (config.mode === "enforce") row.blockers.push(...evalGapBlockers(gate)); }
|
|
101
|
+
}
|
|
96
102
|
if (config.mode === "enforce") row.blockers.push(...planConformanceBlockers(conformance), ...testIntegrityBlockers(integrity));
|
|
97
103
|
}
|
|
98
104
|
}
|
package/src/hub/sdlc-release.ts
CHANGED
|
@@ -21,7 +21,7 @@ const sdlcGh: SdlcGh = async (...args) => {
|
|
|
21
21
|
catch { return { code: 1, stdout: "" }; }
|
|
22
22
|
};
|
|
23
23
|
export interface DocEvidence { schemaVersion: 1; head?: string; version?: string; documents: { path?: string; state: "fresh" | "stale" | "nonancestor" | "unknown"; verifiedAgainst?: string; commits?: number; dirty?: boolean }[]; errors: number; fresh: boolean; }
|
|
24
|
-
export interface ReleaseReadiness { 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; }
|
|
24
|
+
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>; 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; }
|
|
25
25
|
export type ReleaseGit = (args: string[]) => { code: number; stdout: string };
|
|
26
26
|
export interface ReleaseReaders { gh?: SdlcGh; git?: ReleaseGit; docs?: (root: string, timeoutMs: number) => Promise<DocEvidence | undefined>; }
|
|
27
27
|
const SHA = /^[0-9a-f]{40}$/;
|
package/src/hub/sdlc.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { planConformanceBlockers, type PlanConformance } from "./plan-conformanc
|
|
|
3
3
|
import { DEFAULT_MAX_NITS, findingsForHead, findingHead, findingTally, type ReviewFindingSet, type ReviewFindingTally } from "./review-findings.ts";
|
|
4
4
|
import type { CostPlan } from "./cost-governance.ts";
|
|
5
5
|
import { bandsConfig, type BandsConfig } from "./sdlc-metrics.ts";
|
|
6
|
+
import { configPathList, evalGapBlockers, evalGateView, evalRequiredChecks, type EvalGate, type EvalResult } from "./eval-gate.ts";
|
|
7
|
+
import { SECURITY_SOURCES, type SecuritySource } from "./security-baseline.ts";
|
|
6
8
|
import { criteriaReceipt, type CriteriaReceipt, type CriteriaView, type LegacyPhaseReceipt } from "./workflow.ts";
|
|
7
9
|
import { constants, openSync, fstatSync, readSync, closeSync } from "node:fs";
|
|
8
10
|
import { join } from "node:path";
|
|
@@ -36,9 +38,11 @@ export type SdlcMode = "off" | "advise" | "enforce";
|
|
|
36
38
|
/** #786: `off` never merges, `dry-run` reports the decision and runs nothing, `on` runs the guarded `gh pr merge`. */
|
|
37
39
|
export type AutoMergeMode = "off" | "dry-run" | "on";
|
|
38
40
|
export const AUTO_MERGE_MODES: readonly AutoMergeMode[] = ["off", "dry-run", "on"];
|
|
41
|
+
/** #481 S7: which GitHub alert sources the scan reads, how often, and for which repository (absent: the project repository). */
|
|
42
|
+
export interface SecurityScanConfig { everyH: number; sources: SecuritySource[]; repo?: string }
|
|
39
43
|
/** #786: one repository's own gate: its required checks (before the top-level list) and its own merge mode. */
|
|
40
44
|
export interface RepoMergePolicy { requiredChecks?: string[]; autoMerge?: AutoMergeMode }
|
|
41
|
-
export interface SdlcConfig { workflow?: "gsd-lite"; maxNits?: number; /** #481 S7: optional control bands per metric; absent means none. */ bands?: BandsConfig; 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[]; }
|
|
45
|
+
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[]; }
|
|
42
46
|
export interface PlanReviewReceipt {
|
|
43
47
|
planner: string;
|
|
44
48
|
planAuthor?: string | null;
|
|
@@ -56,6 +60,8 @@ export interface MergeRecord {
|
|
|
56
60
|
cleanup: "not_started" | "claimed" | "deleted" | "already_gone" | "skipped" | "unknown";
|
|
57
61
|
reason?: "not_merged" | "missing_commit" | "metadata_unknown" | "identity_changed" | "protected_branch" | "default_branch" | "head_changed" | "authority_changed" | "delete_unconfirmed";
|
|
58
62
|
ownerNotice: "not_started" | "claimed" | "sent" | "unknown";
|
|
63
|
+
/** #481 S7: the merged PR's review and CI figures, read once at merge by the host. Absent when the PR could not be read; fields inside are null when unknown. */
|
|
64
|
+
cost?: import("./cost-governance.ts").MergeCost;
|
|
59
65
|
}
|
|
60
66
|
export interface SdlcReceipt {
|
|
61
67
|
merge?: MergeRecord;
|
|
@@ -152,6 +158,22 @@ const checkList = (value: unknown, what: string): string[] => {
|
|
|
152
158
|
if (!Array.isArray(value) || value.length > 32 || value.some(c => typeof c !== "string" || !c.trim() || c.length > 120 || /[\r\n\x00-\x1f]/.test(c)) || new Set(value).size !== value.length) throw new Error(`${what}: expected at most 32 unique nonempty names`);
|
|
153
159
|
return [...value] as string[];
|
|
154
160
|
};
|
|
161
|
+
const evalCheckName = (value: unknown): string => {
|
|
162
|
+
if (typeof value !== "string" || !value.trim() || value.length > 120 || /[\r\n\x00-\x1f]/.test(value)) throw new Error("sdlc.eval_check: expected one nonempty check name");
|
|
163
|
+
return value;
|
|
164
|
+
};
|
|
165
|
+
const securityScanConfig = (value: unknown): SecurityScanConfig => {
|
|
166
|
+
const fail = (path: string, why: string): never => { throw new Error(`sdlc.security_scan${path}: ${why}`); };
|
|
167
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return fail("", "expected a table");
|
|
168
|
+
const raw = value as Record<string, unknown>;
|
|
169
|
+
for (const key of Object.keys(raw)) if (!["every_h", "sources", "repo"].includes(key)) fail(`.${key}`, "unknown field");
|
|
170
|
+
const everyH = raw.every_h === undefined ? 24 : raw.every_h;
|
|
171
|
+
if (typeof everyH !== "number" || !Number.isSafeInteger(everyH) || everyH < 1 || everyH > 720) fail(".every_h", "expected an integer number of hours from 1 to 720");
|
|
172
|
+
const sources = raw.sources;
|
|
173
|
+
if (!Array.isArray(sources) || !sources.length || sources.length > SECURITY_SOURCES.length || new Set(sources).size !== sources.length || sources.some(s => !SECURITY_SOURCES.includes(s as SecuritySource))) fail(".sources", `expected a nonempty list of unique names from ${SECURITY_SOURCES.join(", ")}; the scan has no default source`);
|
|
174
|
+
if (raw.repo !== undefined && !repo(raw.repo)) fail(".repo", "expected owner/repository");
|
|
175
|
+
return { everyH: everyH as number, sources: [...sources as SecuritySource[]], ...(raw.repo === undefined ? {} : { repo: raw.repo as string }) };
|
|
176
|
+
};
|
|
155
177
|
const autoMergeMode = (value: unknown, what: string): AutoMergeMode => {
|
|
156
178
|
if (!AUTO_MERGE_MODES.includes(value as AutoMergeMode)) throw new Error(`${what}: expected off, dry-run or on`);
|
|
157
179
|
return value as AutoMergeMode;
|
|
@@ -178,11 +200,15 @@ export function sdlcConfig(value: unknown, version?: string): SdlcConfig {
|
|
|
178
200
|
if (value === undefined) return { mode: "off", requiredChecks: [], stages: [...SDLC_STAGES] };
|
|
179
201
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("sdlc: expected a table");
|
|
180
202
|
const raw = value as Record<string, unknown>;
|
|
181
|
-
for (const key of Object.keys(raw)) if (!["mode", "required_checks", "stages", "workflow", "definitions", "max_nits", "bands", "auto_merge", "repos"].includes(key)) throw new Error(`sdlc.${key}: unknown field`);
|
|
203
|
+
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`);
|
|
182
204
|
const maxNits = raw.max_nits === undefined ? DEFAULT_MAX_NITS : raw.max_nits;
|
|
183
205
|
if (typeof maxNits !== "number" || !Number.isSafeInteger(maxNits) || maxNits < 0 || maxNits > 64) throw new Error("sdlc.max_nits: expected an integer from 0 to 64");
|
|
184
206
|
const bands = bandsConfig(raw.bands), bandConfig = Object.keys(bands).length ? { bands } : {};
|
|
185
|
-
const
|
|
207
|
+
const evalConfig = {
|
|
208
|
+
...(raw.eval_check === undefined ? {} : { evalCheck: evalCheckName(raw.eval_check) }),
|
|
209
|
+
...(raw.config_paths === undefined ? {} : { configPaths: configPathList(raw.config_paths, "sdlc.config_paths") }),
|
|
210
|
+
};
|
|
211
|
+
const findingConfig = { ...(raw.max_nits === undefined ? {} : { maxNits }), ...bandConfig, ...evalConfig, ...(raw.security_scan === undefined ? {} : { securityScan: securityScanConfig(raw.security_scan) }) };
|
|
186
212
|
const mode = raw.mode ?? "off";
|
|
187
213
|
if (mode !== "off" && mode !== "advise" && mode !== "enforce") throw new Error("sdlc.mode: expected off, advise or enforce");
|
|
188
214
|
// ponytail: the #481 S8 window is a fixed version; delete `workflow`, the phase aliases and their tests once it passes.
|
|
@@ -336,12 +362,13 @@ export const SPEC_STATE_TEXT: Record<Exclude<SpecState, "current">, string> = {
|
|
|
336
362
|
changed: "spec changed after acceptance: the person re-accepts with ahub sdlc accept <task> --issue <n>",
|
|
337
363
|
unknown: "spec edit time unknown: the issue could not be read",
|
|
338
364
|
};
|
|
339
|
-
export interface SdlcStatus { 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; }
|
|
365
|
+
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; }
|
|
340
366
|
/** 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. */
|
|
341
367
|
export const criteriaRequired = (config: SdlcConfig, receipt: SdlcReceipt | undefined): boolean => config.workflow === "gsd-lite" || (config.mode !== "off" && !!checklistOf(receipt));
|
|
342
|
-
export function sdlcStatus(config: SdlcConfig, receipt: SdlcReceipt | undefined, evidence?: PrEvidence, criteria?: CriteriaView, specEdit?: SpecEdit, sets: readonly ReviewFindingSet[] = [], commit?: string, plan?: SdlcStatus["planConformance"], integrity?: TestIntegrity): SdlcStatus {
|
|
368
|
+
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 {
|
|
343
369
|
const stage = receipt?.stage ?? config.stages[0] ?? "spec", blockers: string[] = [];
|
|
344
370
|
const definition = stageDefinition(config, stage);
|
|
371
|
+
const evalGate = evidence ? evalGateView(config, evidence, evalResult) : undefined;
|
|
345
372
|
const items = findingsForHead(sets, findingHead(receipt, evidence, commit));
|
|
346
373
|
const findings = items.length ? findingTally(items) : undefined;
|
|
347
374
|
if (config.mode === "enforce" && findings?.openImportant) blockers.push("open important review findings: " + findings.openImportant);
|
|
@@ -355,10 +382,13 @@ export function sdlcStatus(config: SdlcConfig, receipt: SdlcReceipt | undefined,
|
|
|
355
382
|
if (receipt?.reviewedHead !== evidence.head) blockers.push("current head has not been reviewed");
|
|
356
383
|
if (receipt?.localHead !== evidence.head || receipt.localResult !== "passed") blockers.push("local gate on current head missing or failed");
|
|
357
384
|
if (!config.requiredChecks.length) blockers.push("required check set unknown");
|
|
358
|
-
|
|
385
|
+
// #481 S5: a configuration PR also needs the configured eval check; a code-only PR is unaffected.
|
|
386
|
+
for (const name of [...new Set([...config.requiredChecks, ...evalRequiredChecks(config, evidence)])]) {
|
|
359
387
|
const matches = evidence.checks.filter(c => c.name === name);
|
|
360
388
|
if (!matches.length || matches.some(c => c.state !== "passed")) blockers.push(`required check ${name}: not successful on current head`);
|
|
361
389
|
}
|
|
390
|
+
// Gaps in the eval evidence block only in enforce; advise shows them in `evalGate` and the advice notice (never a silent pass, never an advise block).
|
|
391
|
+
if (config.mode === "enforce") blockers.push(...evalGapBlockers(evalGate));
|
|
362
392
|
if (evidence.review !== "approved") blockers.push("GitHub review approval missing or changes requested");
|
|
363
393
|
if (evidence.pendingReviews !== 0) blockers.push("review requests pending or unknown");
|
|
364
394
|
if (evidence.unresolved !== 0) blockers.push("review threads unresolved or unknown");
|
|
@@ -371,7 +401,7 @@ export function sdlcStatus(config: SdlcConfig, receipt: SdlcReceipt | undefined,
|
|
|
371
401
|
const shown = criteria && (criteriaRequired(config, receipt) || definition && [...definition.entry_gates, ...definition.exit_gates].includes("criteria"));
|
|
372
402
|
// Shown, not counted as a readiness blocker: the spec gate is build entry (#481 S1).
|
|
373
403
|
const spec = config.mode !== "off" && receipt?.issue ? { spec: { issue: receipt.issue, state: specState(receipt, specEdit) } } : {};
|
|
374
|
-
return { ...spec, ...(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,
|
|
404
|
+
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,
|
|
375
405
|
actor: !definition ? "person" : shown && criteria.blockers.length ? "reviewer/person" : config.definitions ? definition.actor : baseActor(definition.base),
|
|
376
406
|
// #694: the identity blocker keeps its exact text for gate matching; the next step says how to supply it.
|
|
377
407
|
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" };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { SdlcGh } from "./sdlc.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* #481 S7: the scheduled security-scan baseline. The hub runs no scanner and invents no control: it reads the open-alert counts GitHub already holds for the
|
|
5
|
+
* repository (Dependabot, secret scanning, code scanning), records one scan row each interval, and the existing control-band path judges the series. A source that
|
|
6
|
+
* is not enabled, not permitted or unreadable counts as unknown, never as zero alerts, so a repository with no source configured records nothing.
|
|
7
|
+
*/
|
|
8
|
+
export const SECURITY_SOURCES = ["dependabot", "secret_scanning", "code_scanning"] as const;
|
|
9
|
+
export type SecuritySource = typeof SECURITY_SOURCES[number];
|
|
10
|
+
export interface SecurityScan { repo: string; sources: SecuritySource[]; counts: Partial<Record<SecuritySource, number | null>>; total: number | null }
|
|
11
|
+
const PATH: Record<SecuritySource, string> = { dependabot: "dependabot/alerts", secret_scanning: "secret-scanning/alerts", code_scanning: "code-scanning/alerts" };
|
|
12
|
+
const REPO = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
13
|
+
const MAX_ALERTS = 1000;
|
|
14
|
+
|
|
15
|
+
/** Open alerts of one source, exactly (paged to the cap), or null when the source cannot be read completely. Counts only: no alert text, name or location is kept. */
|
|
16
|
+
async function openAlerts(repo: string, source: SecuritySource, run: SdlcGh, deadline: number): Promise<number | null> {
|
|
17
|
+
let total = 0;
|
|
18
|
+
for (let page = 1; page <= MAX_ALERTS / 100; page++) {
|
|
19
|
+
const left = deadline - performance.now();
|
|
20
|
+
if (left <= 0) return null;
|
|
21
|
+
const reply = await run(["api", `repos/${repo}/${PATH[source]}?state=open&per_page=100&page=${page}`, "--jq", "length"], Math.min(10_000, left), undefined, 256).catch(() => undefined);
|
|
22
|
+
if (!reply || reply.code !== 0) return null;
|
|
23
|
+
const n = Number(reply.stdout.trim());
|
|
24
|
+
if (!Number.isSafeInteger(n) || n < 0 || n > 100) return null;
|
|
25
|
+
total += n;
|
|
26
|
+
if (n < 100) return total;
|
|
27
|
+
}
|
|
28
|
+
return null; // more than the cap: unknown, not a clipped number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Fixed argv, bounded time and output. The total is known only when every named source was read. */
|
|
32
|
+
export async function readSecurityScan(repo: string, sources: readonly SecuritySource[], run: SdlcGh): Promise<SecurityScan | undefined> {
|
|
33
|
+
if (!REPO.test(repo) || repo.startsWith("-") || !sources.length || sources.some(source => !SECURITY_SOURCES.includes(source))) return undefined;
|
|
34
|
+
const deadline = performance.now() + 20_000, counts: SecurityScan["counts"] = {};
|
|
35
|
+
for (const source of sources) counts[source] = await openAlerts(repo, source, run, deadline);
|
|
36
|
+
const known = sources.every(source => counts[source] !== null && counts[source] !== undefined);
|
|
37
|
+
return { repo, sources: [...sources], counts, total: known ? sources.reduce((sum, source) => sum + counts[source]!, 0) : null };
|
|
38
|
+
}
|
package/src/hub/settings.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { OPERATIONAL_NUMBERS } from "./operational-settings.ts";
|
|
2
|
+
import { QUEUE_BACKPRESSURE_LIMITS } from "./queue-backpressure.ts";
|
|
1
3
|
import { operationalRosterSetting, operationalSetting } from "./operational-authority.ts";
|
|
2
4
|
import { ACTION_CLASSES } from "./action-class.ts";
|
|
3
5
|
import { definitionOf, type KindMap, type ProjectAdapterCatalog, ADAPTERS, PLANNER_PEERS, SUPPORTED_PEERS, START_MODE_PEERS } from "../adapters/registry.ts";
|
|
@@ -57,6 +59,10 @@ export const SETTINGS: readonly SettingDef[] = [
|
|
|
57
59
|
...["interval_s", "unaccepted_min", "idle_min", "review_min", "ready_min", "ladder_min"].map((key): SettingDef => ({ key: `task_sweep.${key}`, group: "Switches", label: `Task sweep: ${key}`, type: "number", min: 1, max: 2_147_483_647 / (key === "interval_s" ? 1000 : 60_000), store: "config", applies: "live", risk: "raises", path: ["task_sweep", key] })),
|
|
58
60
|
...SETTING_PEERS.map((peer): SettingDef => ({ key: `tasks.wip_limits.${peer}`, group: "Routing", label: `${peer}: planner WIP limit`, type: "integer", min: 0, max: 32, store: "config", applies: "live", risk: "raises", floor: 0, path: ["tasks", "wip_limits", peer] })),
|
|
59
61
|
{ key: "tasks.escalate_after", group: "Routing", label: "Escalate after N consecutive changes_requested", type: "integer", min: 1, max: 10, store: "config", applies: "live", risk: "raises", path: ["tasks", "escalate_after"] },
|
|
62
|
+
...OPERATIONAL_NUMBERS.map(({ defaultValue, unit, inventory, ...def }): SettingDef => def),
|
|
63
|
+
{ key: "tasks.auto_pull", group: "Switches", label: "Auto-pull the top reserved ready card when a planner slot frees", type: "boolean", store: "config", applies: "live", risk: "raises", floor: false, path: ["tasks", "auto_pull"] },
|
|
64
|
+
{ key: "tasks.queue_backpressure.max_queued", group: "Routing", label: "Automatic offers: max queued envelopes (0 disables)", type: "integer", min: 0, max: QUEUE_BACKPRESSURE_LIMITS.max_queued, store: "config", applies: "live", risk: "raises", path: ["tasks", "queue_backpressure", "max_queued"] },
|
|
65
|
+
{ key: "tasks.queue_backpressure.max_oldest_s", group: "Routing", label: "Automatic offers: max oldest queued age in seconds (0 disables)", type: "integer", min: 0, max: QUEUE_BACKPRESSURE_LIMITS.max_oldest_s, store: "config", applies: "live", risk: "raises", path: ["tasks", "queue_backpressure", "max_oldest_s"] },
|
|
60
66
|
{ key: "planner", group: "Roles", label: "Planners (task-local selection)", type: "peers", values: PLANNER_PEERS, store: "config", applies: "live", risk: "raises", path: ["planner"] },
|
|
61
67
|
...SETTING_PEERS.map((peer): SettingDef => ({ key: `catalog_roles.${peer}`, group: "Roles", label: `${peer}: catalog guidance`, type: "roles", store: "config", applies: "next use", risk: "safe", path: ["catalog_roles", peer] })),
|
|
62
68
|
{ key: "scoped_grants.protect_instructions", group: "Permissions", label: "Ask before writing instruction files", type: "boolean", store: "config", applies: "live", risk: "raises", floor: true, path: ["protect_instruction_files"] },
|
|
@@ -79,7 +85,7 @@ export const SETTINGS: readonly SettingDef[] = [
|
|
|
79
85
|
* Never editable from settings, whatever the session: these choose what the hub executes or where secrets and task
|
|
80
86
|
* text go. A key equal to an entry, or below it, is refused by name.
|
|
81
87
|
*/
|
|
82
|
-
export const NEVER_EDITABLE = ["kimi_cmd", "qwen_cmd", "jcode_cmd", "jcode_home", "jcode_provider_profile", "codex_bin", "pi.cmd", "checks", "mlx", "omniroute", "memory.worker_url", "local.read_allow", "local.bash_network", "local.network_allow", "bench.enabled", "terminal", "instances", "adapters", "adapter_modules"] as const;
|
|
88
|
+
export const NEVER_EDITABLE = ["kimi_cmd", "qwen_cmd", "jcode_cmd", "jcode_home", "jcode_provider_profile", "codex_bin", "pi.cmd", "checks", "mlx", "omniroute", "memory.worker_url", "local.read_allow", "local.bash_network", "local.network_allow", "bench.enabled", "terminal", "schedules", "folder_triggers", "corpus", "rooms", "instances", "adapters", "adapter_modules", "local.doc_read", "local.web_fetch"] as const;
|
|
83
89
|
|
|
84
90
|
/** Derive project-bound rows from the same builtin templates used by lookup, without registering aliases globally. */
|
|
85
91
|
export function projectSettings(instances?: KindMap, adapterCatalog?: ProjectAdapterCatalog): readonly SettingDef[] {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import example from "../../templates/packs/example.pack.json" with { type: "text" };
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The packs the hub ships (#513a), by file name without `.pack.json`. Imported as text so the bundle carries them, as `shipped-roles.ts` carries the role catalog.
|
|
5
|
+
* Only the format example is here: the writing, analysis and ops packs are #513b, which adds a file to `templates/packs/` and a line here.
|
|
6
|
+
*/
|
|
7
|
+
// TypeScript types a `.json` import as its parsed shape even with `type: "text"`; Bun hands over the file text, which `parsePack` parses and bounds itself.
|
|
8
|
+
export const SHIPPED_PACKS: Readonly<Record<string, string>> = { example: example as unknown as string };
|
package/src/hub/snapshots.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Database } from "bun:sqlite";
|
|
2
|
-
import { closeSync, constants, copyFileSync, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readSync, readdirSync, rmSync, statSync, utimesSync, writeFileSync, type Stats } from "node:fs";
|
|
2
|
+
import { closeSync, constants, copyFileSync, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, rmSync, statSync, utimesSync, writeFileSync, type Stats } from "node:fs";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
@@ -26,6 +26,15 @@ export const budgetNow = (budget: SnapshotBudget): number => budget.now ? budget
|
|
|
26
26
|
export class SnapshotBudgetExceeded extends Error {
|
|
27
27
|
constructor() { super("snapshot burst budget exhausted; boundary evidence is unknown"); }
|
|
28
28
|
}
|
|
29
|
+
const SNAPSHOT_TIMEOUT_MS = 10_000;
|
|
30
|
+
/**
|
|
31
|
+
* The wall-clock timeout of one git child. Production (no `budget.now`): the remaining budget, between 1 ms and the 10 s ceiling, so a child is killed at the budget.
|
|
32
|
+
* ponytail: a host-held clock (`budget.now`, only the host-only snapshotClock seam sets it) holds the deadline, so the child's timeout is the 10 s ceiling, not the remaining budget:
|
|
33
|
+
* with the clock fixed the remaining budget never shrinks, and 250 ms of real time per child timed a slow git out under load (#554). Production never sets `now`, so its child is still killed
|
|
34
|
+
* at the budget. A child past the 10 s ceiling still reports ETIMEDOUT and the evidence stays unknown. Upgrade path: a fake spawn seam, if a held clock ever needs to model a slow child.
|
|
35
|
+
*/
|
|
36
|
+
export const childTimeoutMs = (budget?: SnapshotBudget): number =>
|
|
37
|
+
budget?.now ? SNAPSHOT_TIMEOUT_MS : Math.max(1, Math.min(SNAPSHOT_TIMEOUT_MS, Math.floor(budget ? budget.deadline - budgetNow(budget) : SNAPSHOT_TIMEOUT_MS)));
|
|
29
38
|
const git = (top: string | Repo, args: string[], env: Record<string, string> = {}, budget?: SnapshotBudget, maxBuffer?: number, input?: string | Buffer) => {
|
|
30
39
|
const argv = repoGitArgs(top, args);
|
|
31
40
|
const remaining = budget ? budget.deadline - budgetNow(budget) : SNAPSHOT_TIMEOUT_MS;
|
|
@@ -33,12 +42,11 @@ const git = (top: string | Repo, args: string[], env: Record<string, string> = {
|
|
|
33
42
|
const result = hubGitSync(argv, {
|
|
34
43
|
encoding: "utf8", env: { ...repoGitEnv(top), ...env }, ...(maxBuffer === undefined ? {} : { maxBuffer }),
|
|
35
44
|
...(input === undefined ? {} : { input }),
|
|
36
|
-
timeout:
|
|
45
|
+
timeout: childTimeoutMs(budget),
|
|
37
46
|
});
|
|
38
47
|
if (budget && (budgetNow(budget) >= budget.deadline || (result.error as NodeJS.ErrnoException | undefined)?.code === "ETIMEDOUT")) throw new SnapshotBudgetExceeded();
|
|
39
48
|
return result;
|
|
40
49
|
};
|
|
41
|
-
const SNAPSHOT_TIMEOUT_MS = 10_000;
|
|
42
50
|
|
|
43
51
|
/** A repository and where the project sits in it: `prefix` is "" at the top level, else "sub/dir/". */
|
|
44
52
|
export interface Repo {
|
|
@@ -543,6 +551,8 @@ export interface TurnRecord {
|
|
|
543
551
|
start_tree: string | null;
|
|
544
552
|
end_tree: string | null;
|
|
545
553
|
changed: string[];
|
|
554
|
+
/** Dirty submodules at the turn's end, whose contents nothing here observes (#798 D2). Absent: not recorded (an older turn, or git could not answer), which is unknown, never none. */
|
|
555
|
+
unobserved?: string[];
|
|
546
556
|
native: string | null;
|
|
547
557
|
}
|
|
548
558
|
|
|
@@ -606,6 +616,43 @@ export function dirtySubmodules(repo: Repo, budget?: SnapshotBudget): string[] |
|
|
|
606
616
|
return result.status === 0 ? parseDirtySubmodules(result.stdout) : undefined;
|
|
607
617
|
}
|
|
608
618
|
|
|
619
|
+
/**
|
|
620
|
+
* One git-config value as git reads it: an unquoted `#` or `;` starts a comment, a quoted run keeps them, quotes are dropped, and `\"` and `\\` are unescaped inside a quoted
|
|
621
|
+
* run. ponytail: other escapes (`\t`, octal) are kept as the character after the backslash; use `git config -f .gitmodules --get-regexp path` if a name needs them.
|
|
622
|
+
*/
|
|
623
|
+
function configValue(raw: string): string {
|
|
624
|
+
let out = "", keep = 0, quoted = false;
|
|
625
|
+
for (let i = 0; i < raw.length; i++) {
|
|
626
|
+
const c = raw[i]!;
|
|
627
|
+
if (quoted && c === "\\" && i + 1 < raw.length) { out += raw[++i]; keep = out.length; continue; }
|
|
628
|
+
if (c === '"') { quoted = !quoted; keep = out.length; continue; }
|
|
629
|
+
if (!quoted && (c === "#" || c === ";")) break;
|
|
630
|
+
if (!quoted && out.length === 0 && /\s/.test(c)) continue; // leading blanks
|
|
631
|
+
out += c;
|
|
632
|
+
if (quoted || !/\s/.test(c)) keep = out.length; // trailing blanks outside quotes are not part of the value
|
|
633
|
+
}
|
|
634
|
+
return out.slice(0, keep);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* The submodule paths a project declares, relative to the project (#798 D1), read from `.gitmodules` with no git call. Empty without the file, and for a shadow
|
|
639
|
+
* repository. A path outside the project's own directory in a larger repository is not the project's. A path git quotes (`"a\tb"`) is taken as written, never
|
|
640
|
+
* unescaped beyond `\"` and `\\`: see `configValue`.
|
|
641
|
+
*/
|
|
642
|
+
export function submodulePaths(repo: Repo): string[] {
|
|
643
|
+
if (repo.shadow) return [];
|
|
644
|
+
let text: string;
|
|
645
|
+
try { text = readFileSync(join(repo.top, ".gitmodules"), "utf8"); } catch { return []; }
|
|
646
|
+
const found = new Set<string>();
|
|
647
|
+
for (const line of text.split(/\r?\n/)) {
|
|
648
|
+
const match = /^\s*path\s*=(.*)$/.exec(line);
|
|
649
|
+
let path = match ? configValue(match[1]!) : "";
|
|
650
|
+
path = path.replace(/\/+$/, "");
|
|
651
|
+
if (path && !path.startsWith("/") && !path.split("/").includes("..") && path.startsWith(repo.prefix)) found.add(path.slice(repo.prefix.length));
|
|
652
|
+
}
|
|
653
|
+
return [...found].sort();
|
|
654
|
+
}
|
|
655
|
+
|
|
609
656
|
/** Turn records in hub.db: the daemon writes them, `ahub turns` and `ahub undo` read them. */
|
|
610
657
|
export class Turns {
|
|
611
658
|
private readonly db: Database;
|
|
@@ -623,6 +670,7 @@ export class Turns {
|
|
|
623
670
|
this.db.run("CREATE TABLE IF NOT EXISTS touches (task INTEGER NOT NULL, peer TEXT NOT NULL, path TEXT NOT NULL, at INTEGER NOT NULL, PRIMARY KEY (task, peer, path))");
|
|
624
671
|
this.db.run("CREATE INDEX IF NOT EXISTS touches_path ON touches (path)"); // the PreToolUse hook looks up one path
|
|
625
672
|
this.db.run("CREATE TABLE IF NOT EXISTS turn_workspaces (turn TEXT PRIMARY KEY, root TEXT NOT NULL, start_tree TEXT, end_tree TEXT, changed TEXT NOT NULL DEFAULT '[]')");
|
|
673
|
+
this.db.run("CREATE TABLE IF NOT EXISTS turn_unobserved (turn TEXT PRIMARY KEY, paths TEXT NOT NULL)");
|
|
626
674
|
this.db.run("CREATE TABLE IF NOT EXISTS task_snapshots (task INTEGER NOT NULL, proposed_at INTEGER NOT NULL, start_tree TEXT, PRIMARY KEY (task, proposed_at))");
|
|
627
675
|
}
|
|
628
676
|
/** A proposal's original project snapshot; task ids may be reused after reset. Never repair a missing baseline later. */
|
|
@@ -665,8 +713,9 @@ export class Turns {
|
|
|
665
713
|
native(id: string, native: string): void {
|
|
666
714
|
this.db.query("UPDATE turns SET native = ? WHERE id = ? AND native IS NULL").run(native, id);
|
|
667
715
|
}
|
|
668
|
-
end(id: string, endTree: string | undefined, changed: string[], keep: number): void {
|
|
716
|
+
end(id: string, endTree: string | undefined, changed: string[], keep: number, unobserved?: string[]): void {
|
|
669
717
|
this.db.transaction(() => {
|
|
718
|
+
if (unobserved !== undefined) this.db.query("INSERT OR REPLACE INTO turn_unobserved (turn, paths) VALUES (?, ?)").run(id, JSON.stringify(unobserved));
|
|
670
719
|
const scoped = this.workspace(id) !== undefined;
|
|
671
720
|
// Older CLIs do not know workspace receipts. Leave their canonical-checkout snapshot view unknown.
|
|
672
721
|
this.db.query("UPDATE turns SET ended = ?, end_tree = ?, changed = ? WHERE id = ?").run(Date.now(), scoped ? null : endTree ?? null, scoped ? "[]" : JSON.stringify(changed), id);
|
|
@@ -675,18 +724,35 @@ export class Turns {
|
|
|
675
724
|
const peer = (this.db.query("SELECT peer FROM turns WHERE id = ?").get(id) as { peer: string } | null)?.peer;
|
|
676
725
|
if (peer) this.db.query("DELETE FROM turns WHERE peer = ? AND id NOT IN (SELECT id FROM turns WHERE peer = ? ORDER BY started DESC, rowid DESC LIMIT ?)").run(peer, peer, keep);
|
|
677
726
|
this.db.run("DELETE FROM turn_workspaces WHERE turn NOT IN (SELECT id FROM turns)");
|
|
727
|
+
this.db.run("DELETE FROM turn_unobserved WHERE turn NOT IN (SELECT id FROM turns)");
|
|
728
|
+
}
|
|
729
|
+
/** The dirty submodules recorded when the turn ended; undefined when none were recorded (unknown, not "none"). */
|
|
730
|
+
unobserved(id: string): string[] | undefined {
|
|
731
|
+
try {
|
|
732
|
+
const row = this.db.query("SELECT paths FROM turn_unobserved WHERE turn = ?").get(id) as { paths: string } | null;
|
|
733
|
+
if (!row) return undefined;
|
|
734
|
+
const paths = JSON.parse(row.paths);
|
|
735
|
+
return Array.isArray(paths) && paths.every(path => typeof path === "string") ? paths : undefined;
|
|
736
|
+
} catch (error) {
|
|
737
|
+
if (/no such table/.test((error as Error).message)) return undefined;
|
|
738
|
+
throw error;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
private withUnobserved<T extends { id: string }>(record: T): T & { unobserved?: string[] } {
|
|
742
|
+
const unobserved = this.unobserved(record.id);
|
|
743
|
+
return unobserved === undefined ? record : { ...record, unobserved };
|
|
678
744
|
}
|
|
679
745
|
list(peer?: string, limit = 20): TurnRecord[] {
|
|
680
746
|
const rows = (peer
|
|
681
747
|
? this.db.query("SELECT * FROM turns WHERE peer = ? ORDER BY started DESC, rowid DESC LIMIT ?").all(peer, limit)
|
|
682
748
|
: this.db.query("SELECT * FROM turns ORDER BY started DESC, rowid DESC LIMIT ?").all(limit)) as (Omit<TurnRecord, "changed"> & { changed: string })[];
|
|
683
|
-
return rows.map(row => this.snapshotFields(row)).map((r) => ({ ...r, changed: JSON.parse(r.changed) as string[] }));
|
|
749
|
+
return rows.map(row => this.snapshotFields(row)).map((r) => this.withUnobserved({ ...r, changed: JSON.parse(r.changed) as string[] }));
|
|
684
750
|
}
|
|
685
751
|
get(id: string): TurnRecord | undefined {
|
|
686
752
|
const r = this.db.query("SELECT * FROM turns WHERE id = ?").get(id) as (Omit<TurnRecord, "changed"> & { changed: string }) | null;
|
|
687
753
|
if (!r) return undefined;
|
|
688
754
|
const record = this.snapshotFields(r);
|
|
689
|
-
return { ...record, changed: JSON.parse(record.changed) as string[] };
|
|
755
|
+
return this.withUnobserved({ ...record, changed: JSON.parse(record.changed) as string[] });
|
|
690
756
|
}
|
|
691
757
|
/**
|
|
692
758
|
* Other peers' turns that overlapped this one in time: their changes are in this turn's diff too. `unknown` lists
|