@staix/agent-hub 0.43.0 → 0.45.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +3 -8
  3. package/docs/agent-notes/adapters.md +2 -2
  4. package/docs/agent-notes/daemon.md +4 -4
  5. package/docs/agent-notes/local-worker.md +2 -1
  6. package/docs/agent-notes/security-review.md +1 -1
  7. package/docs/agent-notes/tasks.md +5 -2
  8. package/docs/agent-notes/tests.md +4 -3
  9. package/docs/design/adapters.md +4 -2
  10. package/docs/design/agent-hub-architecture.md +2 -0
  11. package/docs/design/agent-hub.md +1 -1
  12. package/docs/design/roadmap.md +75 -2
  13. package/docs/design/supervision.md +34 -2
  14. package/docs/design/task-board.md +36 -2
  15. package/docs/dogfood.md +20 -5
  16. package/docs/events.md +9 -3
  17. package/docs/influences.md +7 -0
  18. package/docs/memory.md +4 -4
  19. package/docs/operations.md +84 -31
  20. package/docs/quickstart.md +14 -2
  21. package/docs/research.md +18 -0
  22. package/docs/roadmap.json +4 -0
  23. package/docs/roadmap.md +9 -0
  24. package/docs/sdlc.md +19 -4
  25. package/docs/security.md +4 -4
  26. package/docs/verification/2026-11-11-supervision-pilot-1221.md +864 -0
  27. package/docs/verification/2026-11-19-0.44.0.md +60 -0
  28. package/docs/verification/2026-11-19-claude-implementer-2.1.328.md +49 -0
  29. package/docs/verification/2026-11-20-claude-implementer-2.1.329.md +49 -0
  30. package/docs/verification/2026-11-20-sdlc-metrics-diagnosis.md +7 -0
  31. package/docs/verification/2026-11-21-0.45.0.md +69 -0
  32. package/docs/verification/2026-11-22-codex-0171-reviewer-isolation.md +47 -0
  33. package/docs/verified.json +32 -26
  34. package/package.json +2 -2
  35. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  36. package/plugins/agent-hub/kimi-hook.js +585 -264
  37. package/plugins/agent-hub/kimi-review-policy-worker.js +5 -5
  38. package/plugins/agent-hub/server.js +629 -293
  39. package/scripts/check-docs.mjs +9 -1
  40. package/src/adapters/acp.ts +11 -1
  41. package/src/adapters/compat.ts +3 -3
  42. package/src/adapters/definitions/builtin-metadata.ts +2 -2
  43. package/src/adapters/definitions/native-context.ts +10 -0
  44. package/src/adapters/jcode.ts +10 -0
  45. package/src/adapters/local-worker.ts +3 -2
  46. package/src/adapters/pi.ts +15 -4
  47. package/src/cli/console-state.ts +3 -1
  48. package/src/cli/help.ts +3 -1
  49. package/src/cli/identity.ts +2 -1
  50. package/src/cli/main.ts +12 -6
  51. package/src/cli/output.ts +2 -2
  52. package/src/cli/recovery-package.ts +16 -3
  53. package/src/cli/roadmap-write.ts +59 -0
  54. package/src/cli/roadmap.ts +81 -4
  55. package/src/cli/sdlc-output.ts +11 -1
  56. package/src/cli/upgrade-runtime.ts +10 -6
  57. package/src/cli/upgrade.ts +9 -3
  58. package/src/hub/agent-mem-range.ts +43 -0
  59. package/src/hub/board.ts +116 -2
  60. package/src/hub/bus.ts +4 -0
  61. package/src/hub/check-runner.ts +25 -1
  62. package/src/hub/claude-shell-wrapper.ts +2 -1
  63. package/src/hub/config-apply.ts +4 -2
  64. package/src/hub/config-trust.ts +1 -1
  65. package/src/hub/context-window.ts +1 -1
  66. package/src/hub/control-write-trace.ts +39 -2
  67. package/src/hub/cost-governance.ts +11 -7
  68. package/src/hub/daemon.ts +318 -53
  69. package/src/hub/dogfood-read.ts +4 -2
  70. package/src/hub/edit-guard.ts +100 -0
  71. package/src/hub/events.ts +79 -8
  72. package/src/hub/facts.ts +85 -2
  73. package/src/hub/hub-tools.ts +3 -1
  74. package/src/hub/lifecycle.ts +6 -1
  75. package/src/hub/log-rotation.ts +130 -0
  76. package/src/hub/memory-profile.ts +137 -21
  77. package/src/hub/no-writes.ts +1 -0
  78. package/src/hub/operational-authority.ts +3 -2
  79. package/src/hub/operational-settings.ts +2 -2
  80. package/src/hub/quota-events.ts +40 -0
  81. package/src/hub/recovery-store.ts +70 -24
  82. package/src/hub/report.ts +1 -1
  83. package/src/hub/research-experiments.ts +132 -0
  84. package/src/hub/research-quality.ts +13 -3
  85. package/src/hub/research-record.ts +38 -2
  86. package/src/hub/research.ts +128 -28
  87. package/src/hub/restart.ts +49 -2
  88. package/src/hub/roadmap-check.ts +65 -0
  89. package/src/hub/roadmap-decompose.ts +80 -0
  90. package/src/hub/roadmap-export.ts +27 -0
  91. package/src/hub/roadmap-sync.ts +97 -0
  92. package/src/hub/roadmap.ts +40 -0
  93. package/src/hub/runtime-capture-prune.ts +9 -1
  94. package/src/hub/runtime-prune-health.ts +5 -1
  95. package/src/hub/sdlc-branch-ci.ts +128 -0
  96. package/src/hub/sdlc-merge.ts +12 -5
  97. package/src/hub/sdlc-metrics.ts +33 -10
  98. package/src/hub/sdlc.ts +90 -10
  99. package/src/hub/settings.ts +1 -0
  100. package/src/hub/snapshots.ts +56 -1
  101. package/src/hub/startup-event-seeds.ts +21 -15
  102. package/src/hub/startup-timing.ts +3 -1
  103. package/src/hub/supervision-proposals.ts +10 -2
  104. package/src/hub/supervision-rules.ts +27 -4
  105. package/src/hub/supervision.ts +7 -0
  106. package/src/hub/task-pr.ts +47 -0
  107. package/src/hub/task-shell-command.ts +124 -0
  108. package/src/hub/task-worktree.ts +18 -11
  109. package/src/hub/tasks.ts +617 -45
  110. package/src/hub/usage-rollup.ts +35 -20
  111. package/src/hub/worktree-shelf.ts +2 -1
  112. package/src/local/sandbox.ts +2 -1
  113. package/src/local/shell-environment.ts +6 -0
  114. package/src/local/tools.ts +13 -1
  115. package/src/memory/brief.ts +10 -1
  116. package/src/memory/client.ts +3 -2
  117. package/src/pi/extension.ts +15 -3
  118. package/src/pi/tool-receipts.ts +26 -0
@@ -11,6 +11,7 @@ import { shellQuote } from "../cli/shell-quote.ts";
11
11
  import { readProcessTable, stopOwnedProcess, trackGroup } from "./child-process.ts";
12
12
  import { realPath } from "./project.ts";
13
13
  import { sbplString } from "../local/deny.ts";
14
+ import { sandboxCommandEnvironment } from "../local/shell-environment.ts";
14
15
 
15
16
  export interface ShellGrant {
16
17
  peer: string; task: number; generation: string; root: string; branch: string;
@@ -233,7 +234,7 @@ export class HostShellWrapper {
233
234
  try {
234
235
  if (!unchanged(ticket) || !this.stable(ticket.root.path) || !this.sandboxStable(grant, ticket.root.path) || !same(grant.root, ticket.root, true) || !same(grant.executable, ticket.executable)) throw fail();
235
236
  const temp = mkdtempSync(join(this.directory.path, "r-")); chmodSync(temp, 0o700); temporary = execution.temporary = stamp(temp, true);
236
- const env = { ...grant.env, TMPDIR: `${temporary.path}/` };
237
+ const env = grant.sandbox ? sandboxCommandEnvironment(grant.env, temporary.path) : { ...grant.env, TMPDIR: `${temporary.path}/` };
237
238
  // Identical own-temp allow suffix and data.readonly broad-write guard to sandboxedExec.
238
239
  if (grant.sandbox?.readOnlyData && /\(allow file-write\* \(subpath /.test(grant.sandbox.profile)) throw fail();
239
240
  const sandbox = grant.sandbox && `${grant.sandbox.profile}\n(allow file-read* ${grant.sandbox.readOnlyData ? "" : "file-write* "}process-exec (subpath ${sbplString(temporary.path)}))`;
@@ -210,6 +210,8 @@ const schema: Record<string, Check> = {
210
210
  budget: block({ gate: number(0, 1), stale_min: timerMinutes, poll_min: timerMinutes, checkpoint_timeout_s: timerSeconds, kimi_tokens_5h: number(0), wait_max_min: number(0) }),
211
211
  context: block({ gate: number(0, 1), stale_min: timerMinutes, max_assignment_used: number(0, 1) }),
212
212
  supervision: block({ mode: words(["off", "shadow", "advisory"]) }),
213
+ edit_governance: block({ arm: words(["baseline", "route_guard", "occ_guard", "combined_guard"]) }),
214
+ roadmap: block({ github_mirror: bool, github_write: words(["off", "conductor"]) }),
213
215
  bus: block({ max_attempts: operationalNumberCheck("bus.max_attempts"), digest_max: operationalNumberCheck("bus.digest_max"), pull_budget_bytes: operationalNumberCheck("bus.pull_budget_bytes"), notes_kept: operationalNumberCheck("bus.notes_kept"), terminal_history_limit: operationalNumberCheck("bus.terminal_history_limit"), accepted_settle_ms: operationalNumberCheck("bus.accepted_settle_ms") }),
214
216
  adapter_timing: block({ acp_tool_ceiling_min: operationalNumberCheck("adapter_timing.acp_tool_ceiling_min"), acp_activity_batch_ms: operationalNumberCheck("adapter_timing.acp_activity_batch_ms"), jcode_steer_timeout_s: operationalNumberCheck("adapter_timing.jcode_steer_timeout_s") }),
215
217
  model_relay: block({ cooldown_failures: operationalNumberCheck("model_relay.cooldown_failures"), cooldown_s: operationalNumberCheck("model_relay.cooldown_s"), cooldown_cap_s: operationalNumberCheck("model_relay.cooldown_cap_s"), terminal_history_limit: operationalNumberCheck("model_relay.terminal_history_limit") }),
@@ -279,9 +281,9 @@ const restart: Record<string, string> = {
279
281
  checks: "Bounded runner and completion-check contracts are constructed together",
280
282
  pii: "Existing native sessions retain their startup privacy boundary", data: "Existing native sessions retain their startup read-only policy",
281
283
  profile: "Session tool schemas and profile contracts are bound at startup", profile_overrides: "Session tool schemas and profile contracts are bound at startup",
282
- text_projection: "Converter and cache ownership are bound at startup", corpus: "The corpus index is bound to its roots at startup", terminal: "Terminal provider is supplied by the daemon lifecycle", bench: "Benchmark execution environment is selected before work starts",
284
+ text_projection: "Converter and cache ownership are bound at startup", corpus: "The corpus index is bound to its roots at startup", roadmap: "GitHub mirror authority is bound at startup", terminal: "Terminal provider is supplied by the daemon lifecycle", bench: "Benchmark execution environment is selected before work starts",
283
285
  };
284
- const live = new Set(["visuals", "action_policy", "permission", "roster", "roles", "planner", "conductor", "protect_instruction_files", "task_sweep", "capabilities", "invocation", "research", "snapshots", "worktrees", "tasks.wip_limits", "tasks.escalate_after", "tasks.auto_pull", "tasks.queue_backpressure", "schedules", "approvals.notify", "questions", "pet", "specs", "supervision"]);
286
+ const live = new Set(["visuals", "action_policy", "permission", "roster", "roles", "planner", "conductor", "protect_instruction_files", "task_sweep", "capabilities", "invocation", "research", "snapshots", "worktrees", "tasks.wip_limits", "tasks.escalate_after", "tasks.auto_pull", "tasks.queue_backpressure", "schedules", "approvals.notify", "questions", "pet", "specs", "supervision", "edit_governance"]);
285
287
  const nextMemory = new Set(["memory.inject_tokens", "memory.brief_items", "memory.suggest_edges", "memory.preface_unused_after"]);
286
288
  /** Closed top-level schema; leaf overrides retain the existing session/runtime boundaries. */
287
289
  export function configApply(key: string, scopes: readonly ConfigIdentityScope[] = []): ApplyRule {
@@ -37,7 +37,7 @@ export const MACHINE_LOCAL = [
37
37
  "invocation", // #445 C1: what another agent may be offered from this machine's agents (a digest-pinned allowlist); a committed config may not share a person's agents' commands with someone else's peers
38
38
  ] as const;
39
39
  /** Legacy exported field list stays compatible; new policies use the complete list below. */
40
- export const ALL_MACHINE_LOCAL = [...MACHINE_LOCAL, "research.runners", "rooms", "tasks.queue_backpressure", "context.max_assignment_used", "action_policy", "protect_instruction_files", "qwen_cmd", "jcode_cmd", "jcode_home", "jcode_provider_profile", "start.agents", "adapters", "adapter_modules", "text_projection", "instances"] as const;
40
+ export const ALL_MACHINE_LOCAL = [...MACHINE_LOCAL, "edit_governance.arm", "roadmap.github_mirror", "roadmap.github_write", "research.runners", "rooms", "tasks.queue_backpressure", "context.max_assignment_used", "action_policy", "protect_instruction_files", "qwen_cmd", "jcode_cmd", "jcode_home", "jcode_provider_profile", "start.agents", "adapters", "adapter_modules", "text_projection", "instances"] as const;
41
41
  /** An empty list of these is a value (`start.agents` empty starts no agent), not "the default", so the empty-value drop below skips them. */
42
42
  const EMPTY_IS_VALUE: readonly string[] = ["start.agents"];
43
43
 
@@ -9,7 +9,7 @@ export function readNativeContext(definition: AdapterDefinition | undefined, val
9
9
 
10
10
  /** Native active-context occupancy, separate from accumulated billable usage (#185). */
11
11
  export interface ContextReading {
12
- source: "claude_statusline" | "codex_token_usage" | "acp_usage_update" | "jcode_usage_update";
12
+ source: "claude_statusline" | "codex_token_usage" | "acp_usage_update" | "jcode_usage_update" | "pi_usage";
13
13
  sessionId: string;
14
14
  measuredAt: number;
15
15
  tokens: number | null;
@@ -24,6 +24,8 @@ const MAX_ACTIVE_SPANS = 256;
24
24
  const MAX_RECENT_SPANS = 512;
25
25
  const MAX_LOOP_SPANS = 8;
26
26
  const MIN_SYNC_PREFIX_MS = 10;
27
+ /** Microtask hops one request may spend following its async spans after their first await, shared by all of them: bounds the loop work this telemetry adds (#1545). */
28
+ const MAX_REQUEST_HOPS = 16;
27
29
  const MAX_EMITS_PER_MINUTE = 60;
28
30
  const RATE_LIMIT_MS = 1_000;
29
31
  const RATE_KEYS = ["slow", "loop"] as const;
@@ -51,6 +53,7 @@ interface RequestTrace {
51
53
  phaseOrder: ControlWritePhase[];
52
54
  settled: boolean;
53
55
  privacySuppressed: boolean;
56
+ hopsLeft: number;
54
57
  }
55
58
  interface SpanTrace {
56
59
  id?: number;
@@ -60,6 +63,8 @@ interface SpanTrace {
60
63
  async: boolean;
61
64
  finished: boolean;
62
65
  prefixRecorded: boolean;
66
+ /** Loop turn the span began in (see turn): a span that finishes in the same turn never let the loop go idle. */
67
+ turn: number;
63
68
  }
64
69
  interface SpanInterval {
65
70
  kind: ControlWriteKind;
@@ -135,6 +140,7 @@ export function controlWriteSpan<T>(phase: ControlWritePhase, fn: () => T): T {
135
140
  if (!isThenable(result)) { request.telemetry.finishSpan(span); return result; }
136
141
  span.async = true;
137
142
  request.telemetry.recordSyncPrefix(span);
143
+ request.telemetry.followSpan(span);
138
144
  return Promise.resolve(result).then(
139
145
  value => { request.telemetry.finishSpan(span); return value; },
140
146
  error => { request.telemetry.finishSpan(span); throw error; },
@@ -158,6 +164,10 @@ export class ControlWriteTelemetry {
158
164
  private timer: ReturnType<typeof setInterval> | undefined;
159
165
  private nextSampleAt: number | undefined;
160
166
  private lastNow = 0;
167
+ private hops = 0;
168
+ /** Counts event-loop turns (one setImmediate marker, only while spans are being traced). */
169
+ private turn = 0;
170
+ private turnPending = false;
161
171
  private stopped = false;
162
172
  private completedRequests = 0;
163
173
  private expiredRequests = 0;
@@ -198,7 +208,7 @@ export class ControlWriteTelemetry {
198
208
  if (!inputVisible) return fn();
199
209
  const request: RequestTrace = {
200
210
  telemetry: this, metadata: safeMetadata, privacyCurrent,
201
- startedAt: now, phases: new Map(), phaseOrder: [], settled: false, privacySuppressed: false,
211
+ startedAt: now, phases: new Map(), phaseOrder: [], settled: false, privacySuppressed: false, hopsLeft: MAX_REQUEST_HOPS,
202
212
  logPrivacy: () => false,
203
213
  };
204
214
  request.logPrivacy = () => !request.privacySuppressed && this.privateNow(request.privacyCurrent);
@@ -298,7 +308,8 @@ export class ControlWriteTelemetry {
298
308
  }
299
309
 
300
310
  beginSpan(request: RequestTrace, phase: ControlWritePhase): SpanTrace {
301
- const span: SpanTrace = { request, phase, startedAt: this.readNow(), async: false, finished: false, prefixRecorded: false };
311
+ if (!this.turnPending && !this.stopped) { this.turnPending = true; setImmediate(() => { this.turn++; this.turnPending = false; }).unref?.(); }
312
+ const span: SpanTrace = { request, phase, startedAt: this.readNow(), async: false, finished: false, prefixRecorded: false, turn: this.turn };
302
313
  if (this.spans.size >= this.maxActiveSpans) { this.droppedSpans++; return span; }
303
314
  span.id = this.nextSpanId++;
304
315
  this.spans.set(span.id, span);
@@ -317,6 +328,9 @@ export class ControlWriteTelemetry {
317
328
  if (!request.phaseOrder.includes(span.phase)) request.phaseOrder.push(span.phase);
318
329
  request.phases.set(span.phase, prior + durationMs);
319
330
  if (!span.async && !span.prefixRecorded) this.rememberSyncInterval(span, endedAt);
331
+ // An async span that began and settled inside one loop turn never yielded: every ms of it was loop-busy time, so it is a synchronous
332
+ // slice (microtask chains). A span that yielded is a wait; overlap with a blocked window alone is presence, never cause.
333
+ else if (span.async && span.turn === this.turn && endedAt - span.startedAt >= MIN_SYNC_PREFIX_MS) this.rememberSyncInterval(span, endedAt);
320
334
  }
321
335
 
322
336
  /** Preserve a long synchronous prelude inside an async function for the delayed loop probe. */
@@ -328,6 +342,29 @@ export class ControlWriteTelemetry {
328
342
  this.rememberSyncInterval(span, endedAt);
329
343
  }
330
344
 
345
+ /** Hops spent following spans: the measured extra work, bounded per request. */
346
+ followedHops(): number { return this.hops; }
347
+
348
+ /**
349
+ * After a span's first await, look at the next few microtask turns of its request (a shared budget of MAX_REQUEST_HOPS, so the added
350
+ * loop work is bounded per request however many spans it has). A gap between two hops is time a continuation ran synchronously and is
351
+ * remembered as a synchronous slice. A block after a real I/O await is out of reach: the budget is spent by then, and Bun has no
352
+ * per-continuation hook, so such a slice is only a lower bound.
353
+ */
354
+ followSpan(span: SpanTrace): void {
355
+ let last = this.readNow();
356
+ const hop = (): void => {
357
+ const request = span.request;
358
+ if (span.finished || request.settled || this.stopped || request.hopsLeft <= 0) return;
359
+ request.hopsLeft--; this.hops++;
360
+ const now = this.readNow();
361
+ if (now - last >= MIN_SYNC_PREFIX_MS) this.rememberSyncInterval({ ...span, startedAt: last }, now);
362
+ last = now;
363
+ queueMicrotask(hop);
364
+ };
365
+ queueMicrotask(hop);
366
+ }
367
+
331
368
  private rememberSyncInterval(span: SpanTrace, endedAt: number): void {
332
369
  const request = span.request;
333
370
  this.recent.push({ kind: request.metadata.kind, ...(request.metadata.task === undefined ? {} : { task: request.metadata.task }), phase: span.phase, startedAt: span.startedAt, endedAt, async: false, privacyCurrent: request.logPrivacy });
@@ -3,8 +3,8 @@ export interface ReviewScope { scope: "none" | "delta" | "full"; reviewers: numb
3
3
  export interface CostPlan { review?: ReviewScope; ci?: "focused" | "full" | "reuse" }
4
4
  export interface ReviewCost extends CostPlan { head?: string }
5
5
  export interface CostTask { repo: string; pr: number; private?: boolean; history: { event: string; at: number; reviewCost?: ReviewCost }[] }
6
- export interface CostPr { repo: string; pr: number; state: "OPEN" | "CLOSED" | "MERGED"; mergedAt?: number; complete: boolean; ciRuns?: { id: number; attempt: number }[]; reviews?: number }
7
- export interface CostRow { repo: string; pr: number; reviewRounds: number; ciRuns: number | null; ciReruns: number | null; fullReReviews: number; deltaReviews: number; reviewMs: number | null; unknownReviewScopes: number; githubReviews: number | null; complete: boolean }
6
+ export interface CostPr { repo: string; pr: number; state: "OPEN" | "CLOSED" | "MERGED"; mergedAt?: number; complete: boolean; ciRuns?: { id: number; attempt: number }[]; reviews?: number; fullGateRuns?: number; successfulGateRuns?: number; failedGateRuns?: number; cancelledGateRuns?: number; otherGateRuns?: number; macosShardRuns?: number; firstPass?: 0 | 1 | null }
7
+ export interface CostRow { repo: string; pr: number; reviewRounds: number; ciRuns: number | null; ciReruns: number | null; fullReReviews: number; deltaReviews: number; reviewMs: number | null; unknownReviewScopes: number; githubReviews: number | null; complete: boolean; fullGateRuns?: number; successfulGateRuns?: number; failedGateRuns?: number; cancelledGateRuns?: number; otherGateRuns?: number; macosShardRuns?: number }
8
8
  export interface CostReport { rows: CostRow[]; truncated: boolean }
9
9
  /**
10
10
  * #1087: why a cost scope was refused. The message is fixed text that names the field and its allowed values and never the value given, so a call site may show it
@@ -43,7 +43,7 @@ export function cleanCostPlan(input: unknown, field: string | { review: string;
43
43
  * #481 S7: what the guarded merge records about a merged PR, from the PR read once at merge. Every field is `null` when the read could not establish it, never 0.
44
44
  * CI figures need the complete read (runs linked by every head of the PR); a rerun is an attempt after the first of one run id, i.e. the same head run again.
45
45
  */
46
- export interface MergeCost { mergedAt: number | null; ciRuns: number | null; ciReruns: number | null; reviews: number | null }
46
+ export interface MergeCost { mergedAt: number | null; ciRuns: number | null; ciReruns: number | null; reviews: number | null; fullGateRuns?: number | null; successfulGateRuns?: number | null; failedGateRuns?: number | null; cancelledGateRuns?: number | null; otherGateRuns?: number | null; macosShardRuns?: number | null; firstPass?: 0 | 1 | null }
47
47
  export function ciRunCounts(runs: readonly { id: number; attempt: number }[] | undefined): { runs: number; reruns: number } | null {
48
48
  if (!runs || runs.length > 100) return null;
49
49
  const attempts = new Map<number, number>();
@@ -57,13 +57,15 @@ export function mergeCostFrom(pr: CostPr | undefined): MergeCost | undefined {
57
57
  if (!pr || pr.state !== "MERGED") return undefined;
58
58
  const counts = pr.complete ? ciRunCounts(pr.ciRuns) : null;
59
59
  return { mergedAt: Number.isSafeInteger(pr.mergedAt) && pr.mergedAt! >= 0 ? pr.mergedAt! : null, ciRuns: counts?.runs ?? null, ciReruns: counts?.reruns ?? null,
60
- reviews: Number.isSafeInteger(pr.reviews) && pr.reviews! >= 0 ? pr.reviews! : null };
60
+ reviews: Number.isSafeInteger(pr.reviews) && pr.reviews! >= 0 ? pr.reviews! : null,
61
+ ...(pr.complete && pr.fullGateRuns !== undefined ? { fullGateRuns: pr.fullGateRuns, successfulGateRuns: pr.successfulGateRuns ?? null, failedGateRuns: pr.failedGateRuns ?? null, cancelledGateRuns: pr.cancelledGateRuns ?? null, otherGateRuns: pr.otherGateRuns ?? null, macosShardRuns: pr.macosShardRuns ?? null, firstPass: pr.firstPass ?? null } : {}) };
61
62
  }
62
63
  /** Bounded, finite or absent: a stored record is data, never trusted shape. */
63
64
  export function cleanMergeCost(value: unknown): MergeCost | undefined {
64
65
  if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
65
66
  const raw = value as Record<string, unknown>, field = (key: string) => Number.isSafeInteger(raw[key]) && (raw[key] as number) >= 0 ? raw[key] as number : null;
66
- return { mergedAt: field("mergedAt"), ciRuns: field("ciRuns"), ciReruns: field("ciReruns"), reviews: field("reviews") };
67
+ return { mergedAt: field("mergedAt"), ciRuns: field("ciRuns"), ciReruns: field("ciReruns"), reviews: field("reviews"),
68
+ ...(Object.hasOwn(raw, "fullGateRuns") ? { fullGateRuns: field("fullGateRuns"), successfulGateRuns: field("successfulGateRuns"), failedGateRuns: field("failedGateRuns"), cancelledGateRuns: field("cancelledGateRuns"), otherGateRuns: field("otherGateRuns"), macosShardRuns: field("macosShardRuns"), firstPass: raw.firstPass === 0 || raw.firstPass === 1 ? raw.firstPass : null } : {}) };
67
69
  }
68
70
  const validRepo = (repo: string) => /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo) && !repo.startsWith("-");
69
71
  const key = (repo: string, pr: number) => `${repo.toLowerCase()}#${pr}`;
@@ -99,12 +101,14 @@ export function costMetrics(tasks: CostTask[], prs: CostPr[]): CostReport {
99
101
  }
100
102
  if (pr.ciRuns && pr.ciRuns.length > 100) { complete = false; truncated = true; }
101
103
  if (!pr.ciRuns || pr.reviews === undefined || rounds.some(round => round.elapsed === undefined || round.scope === undefined)) complete = false;
104
+ const ci = pr.complete ? ciRunCounts(pr.ciRuns) : null;
102
105
  rows.push({ repo: pr.repo.toLowerCase(), pr: pr.pr, reviewRounds: rounds.length,
103
- ciRuns: pr.ciRuns ? attempts.size : null, ciReruns: pr.ciRuns ? [...attempts.values()].reduce((sum, n) => sum + n - 1, 0) : null,
106
+ ciRuns: ci?.runs ?? null, ciReruns: ci?.reruns ?? null,
104
107
  fullReReviews: rounds.filter((round, index) => index > 0 && round.scope === "full").length,
105
108
  deltaReviews: rounds.filter(round => round.scope === "delta").length,
106
109
  reviewMs: rounds.every(round => round.elapsed !== undefined) ? rounds.reduce((sum, round) => sum + round.elapsed!, 0) : null,
107
- unknownReviewScopes: rounds.filter(round => round.scope === undefined).length, githubReviews: pr.reviews ?? null, complete });
110
+ unknownReviewScopes: rounds.filter(round => round.scope === undefined).length, githubReviews: pr.reviews ?? null, complete,
111
+ ...(pr.complete && pr.fullGateRuns !== undefined ? { fullGateRuns: pr.fullGateRuns, successfulGateRuns: pr.successfulGateRuns, failedGateRuns: pr.failedGateRuns, cancelledGateRuns: pr.cancelledGateRuns, otherGateRuns: pr.otherGateRuns, macosShardRuns: pr.macosShardRuns } : {}) });
108
112
  }
109
113
  return { rows: rows.sort((a, b) => a.repo.localeCompare(b.repo) || a.pr - b.pr), truncated };
110
114
  }