@staix/agent-hub 0.35.0 → 0.37.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 (165) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +25 -4
  3. package/THIRD_PARTY_NOTICES.md +0 -18
  4. package/docs/agent-notes/README.md +71 -1
  5. package/docs/agent-notes/adapters.md +5 -2
  6. package/docs/agent-notes/bus.md +1 -0
  7. package/docs/agent-notes/daemon.md +7 -6
  8. package/docs/agent-notes/local-worker.md +1 -0
  9. package/docs/agent-notes/models.md +5 -3
  10. package/docs/agent-notes/tasks.md +9 -2
  11. package/docs/agent-notes/tests.md +1 -1
  12. package/docs/contracts/companion-cli-v1.json +70 -0
  13. package/docs/design/adapters.md +115 -2
  14. package/docs/design/agent-hub-architecture.md +10 -2
  15. package/docs/design/bus.md +8 -0
  16. package/docs/design/execution-reference.md +171 -11
  17. package/docs/design/guidance-experiments.md +438 -0
  18. package/docs/design/guidance-probes.md +802 -0
  19. package/docs/design/model-routes.md +1053 -0
  20. package/docs/design/supervision.md +121 -0
  21. package/docs/design/task-board.md +111 -0
  22. package/docs/dogfood.md +24 -15
  23. package/docs/events.md +20 -1
  24. package/docs/memory.md +3 -3
  25. package/docs/operations.md +366 -133
  26. package/docs/profiles.md +2 -2
  27. package/docs/quickstart.md +114 -3
  28. package/docs/research.md +5 -3
  29. package/docs/sdlc.md +113 -7
  30. package/docs/security.md +88 -6
  31. package/docs/specs/2026-09-19-agent-hub-design.md +14 -11
  32. package/docs/specs/2026-10-04-switchyard-source-port-design.md +3 -1
  33. package/docs/verification/2026-10-25-qwen-dual-output-t0.md +22 -0
  34. package/docs/verification/2026-11-08-qwen-0269-model-setter-1317.md +25 -11
  35. package/docs/verification/2026-11-09-qwen-0270-acp.md +181 -0
  36. package/docs/verification/2026-11-09-qwen-0270-model-setter-1317.md +61 -0
  37. package/docs/verification/2026-11-10-0.36.0.md +59 -0
  38. package/docs/verification/2026-11-10-claude-implementer-2.1.322.md +59 -0
  39. package/docs/verification/2026-11-10-qwen-0270-dual-output.md +367 -0
  40. package/docs/verification/2026-11-10-qwen-0271-dual-output.md +101 -0
  41. package/docs/verification/2026-11-11-0.37.0.md +40 -0
  42. package/docs/verification/2026-11-11-guidance-probe-t2-1226.md +153 -0
  43. package/docs/verification/2026-11-11-qwen-setter-suggestions-off.md +167 -0
  44. package/docs/verification/claude-shell-wrapper-native.py +1 -1
  45. package/docs/verified.json +27 -27
  46. package/package.json +3 -4
  47. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  48. package/plugins/agent-hub/kimi-hook.js +3570 -1800
  49. package/plugins/agent-hub/server.js +4112 -1913
  50. package/src/adapters/channel-peer.ts +7 -1
  51. package/src/adapters/claude-channel.ts +7 -4
  52. package/src/adapters/compat.ts +10 -10
  53. package/src/adapters/local-probe.ts +174 -0
  54. package/src/adapters/local-worker.ts +233 -22
  55. package/src/adapters/qwen-dual.ts +324 -44
  56. package/src/cli/console-state.ts +25 -6
  57. package/src/cli/console-versions.ts +99 -0
  58. package/src/cli/console.ts +13 -1
  59. package/src/cli/guidance.ts +67 -0
  60. package/src/cli/help.ts +12 -4
  61. package/src/cli/identity.ts +10 -3
  62. package/src/cli/init-prompt.ts +15 -2
  63. package/src/cli/init-required-checks.ts +122 -0
  64. package/src/cli/init-settings.ts +10 -4
  65. package/src/cli/init.ts +39 -3
  66. package/src/cli/install-paths.ts +7 -2
  67. package/src/cli/lineage.ts +78 -0
  68. package/src/cli/main.ts +171 -14
  69. package/src/cli/runtime-version-warning.ts +2 -2
  70. package/src/cli/sdlc-output.ts +9 -5
  71. package/src/cli/setup-research.ts +10 -0
  72. package/src/hub/autonomy-defaults.ts +20 -9
  73. package/src/hub/board.ts +346 -4
  74. package/src/hub/build-entry.ts +11 -0
  75. package/src/hub/bus.ts +12 -0
  76. package/src/hub/ci-watch.ts +4 -4
  77. package/src/hub/config-apply.ts +6 -3
  78. package/src/hub/config-trust.ts +7 -1
  79. package/src/hub/control-client.ts +5 -2
  80. package/src/hub/daemon.ts +508 -26
  81. package/src/hub/delivery-hints.ts +4 -2
  82. package/src/hub/delivery-journal.ts +50 -2
  83. package/src/hub/delivery-public.ts +51 -0
  84. package/src/hub/dogfood-profile.ts +8 -4
  85. package/src/hub/events.ts +3 -2
  86. package/src/hub/execution-lineage-owner.ts +272 -0
  87. package/src/hub/execution-lineage.ts +52 -8
  88. package/src/hub/execution-links.ts +85 -0
  89. package/src/hub/guidance-probe-store.ts +713 -0
  90. package/src/hub/guidance-probes.ts +358 -0
  91. package/src/hub/guidance-variants.ts +398 -0
  92. package/src/hub/handoff.ts +1 -0
  93. package/src/hub/hub-tools.ts +43 -2
  94. package/src/hub/inference.ts +18 -5
  95. package/src/hub/manager.ts +44 -2
  96. package/src/hub/memory-policy.ts +2 -2
  97. package/src/hub/operational-authority.ts +13 -1
  98. package/src/hub/peers.ts +6 -1
  99. package/src/hub/planning.ts +1 -1
  100. package/src/hub/ports.ts +1 -1
  101. package/src/hub/progress.ts +47 -23
  102. package/src/hub/report.ts +2 -0
  103. package/src/hub/research.ts +1 -0
  104. package/src/hub/restart.ts +20 -0
  105. package/src/hub/roles.ts +26 -0
  106. package/src/hub/routing.ts +4 -1
  107. package/src/hub/sdlc-merge.ts +39 -1
  108. package/src/hub/sdlc-release-authorization.ts +139 -17
  109. package/src/hub/sdlc-release-policy.ts +100 -0
  110. package/src/hub/sdlc-release.ts +60 -8
  111. package/src/hub/sdlc.ts +62 -11
  112. package/src/hub/settings.ts +2 -0
  113. package/src/hub/supervision-proposals.ts +405 -0
  114. package/src/hub/supervision-rules.ts +388 -0
  115. package/src/hub/supervision.ts +2 -0
  116. package/src/hub/task-approval.ts +2 -2
  117. package/src/hub/task-repository.ts +5 -0
  118. package/src/hub/tasks.ts +917 -53
  119. package/src/local/probe-errors.ts +28 -0
  120. package/src/local/probe-sandbox.ts +224 -0
  121. package/src/local/probe-types.ts +108 -0
  122. package/src/local/probe-workspace.ts +237 -0
  123. package/src/local/sandbox.ts +71 -2
  124. package/src/local/tools.ts +135 -9
  125. package/src/memory/capture.ts +2 -2
  126. package/src/models/relay.ts +9 -2
  127. package/src/models/route/advisor-trigger.ts +88 -0
  128. package/src/models/route/config.ts +39 -8
  129. package/src/models/route/conversation-view.ts +179 -0
  130. package/src/models/route/decision-evidence.ts +1 -1
  131. package/src/models/route/decision.ts +193 -26
  132. package/src/models/route/escalation-control.ts +30 -0
  133. package/src/models/route/hub-prompts.ts +97 -0
  134. package/src/models/route/judge-choice.ts +155 -0
  135. package/src/models/route/judge-replies.ts +102 -0
  136. package/src/models/route/labels.ts +14 -70
  137. package/src/models/route/observation-signals.ts +250 -0
  138. package/src/models/route/plan-execute-choice.ts +27 -0
  139. package/src/models/route/relay-selector.ts +10 -9
  140. package/src/models/route/runtime.ts +129 -60
  141. package/src/models/route/stage-diagnostics.ts +22 -0
  142. package/src/models/route/stage-evidence.ts +55 -0
  143. package/src/models/route/stage-fallback.ts +58 -0
  144. package/src/models/route/stage-input.ts +155 -0
  145. package/src/models/route/stage.ts +5 -147
  146. package/src/models/route/turn-state.ts +77 -0
  147. package/src/omniroute/client.ts +3 -0
  148. package/src/ui/guidance-panel.ts +156 -0
  149. package/src/ui/guidance-view.ts +43 -0
  150. package/src/ui/lineage-view.ts +34 -0
  151. package/src/ui/plugin.ts +141 -27
  152. package/src/version.ts +4 -0
  153. package/templates/adec/README.md +32 -0
  154. package/templates/adec/ahub.plan-execute.json +23 -0
  155. package/templates/adec/ahub.stage.json +23 -0
  156. package/LICENSES/Apache-2.0.txt +0 -204
  157. package/src/models/route/advisor.ts +0 -102
  158. package/src/models/route/escalation.ts +0 -82
  159. package/src/models/route/judge.ts +0 -23
  160. package/src/models/route/normalize.ts +0 -103
  161. package/src/models/route/plan-execute.ts +0 -52
  162. package/src/models/route/prompts.ts +0 -8
  163. package/src/models/route/signals.ts +0 -247
  164. package/src/models/route/state.ts +0 -54
  165. package/src/models/route/text.ts +0 -61
@@ -0,0 +1,388 @@
1
+ import { isClosedTaskState, type HistoryEntry, type TaskState } from "./board.ts";
2
+ import type { DeliverableRecord } from "./deliverables.ts";
3
+
4
+ /**
5
+ * #1221 T1: deterministic supervision rules over facts the public project view already holds.
6
+ *
7
+ * A pure function of admitted records: a task's structured history, the hub's own deliverable measurement and its
8
+ * declared-overlap reading. No note, review finding, transcript, file body or private task is read, there is no clock,
9
+ * no dependency object and no emit path, so an observation cannot turn a worker, write an action or notify anyone.
10
+ * `src/hub/supervision.ts` is the neighbour: it turns board milestones into conductor notices and owns their batching.
11
+ * This module decides only whether one of a closed set of conditions holds, and T2 (unauthorized here) is what would
12
+ * carry a decision to a person. Nothing imports it yet, and that is the point of a shadow rule.
13
+ */
14
+
15
+ export const SUPERVISION_RULES = ["repeated_failure", "deliverable_invalidated_check", "declared_overlap_without_integration"] as const;
16
+ export type SupervisionRuleId = (typeof SUPERVISION_RULES)[number];
17
+ /** Bump one rule when its trigger, refs or reason codes change meaning: a stored observation names the version it was made under. */
18
+ export const SUPERVISION_RULE_VERSION: Readonly<Record<SupervisionRuleId, number>> = { repeated_failure: 1, deliverable_invalidated_check: 1, declared_overlap_without_integration: 1 };
19
+
20
+ /** The existing hub operation an observation names. T1 names one; nothing in this module runs it. */
21
+ export const SUPERVISION_ACTIONS = ["escalate", "recheck", "request_integration"] as const;
22
+ export type SupervisionAction = (typeof SUPERVISION_ACTIONS)[number];
23
+ /** Closed reason codes: an observation says why it fired in a token, never in prose. */
24
+ export const SUPERVISION_REASONS = ["repeated_failure", "stale_check", "unintegrated_overlap"] as const;
25
+ export type SupervisionReasonCode = (typeof SUPERVISION_REASONS)[number];
26
+ /** Why a rule could not decide for one task and revision. A gap is not a trigger and never a zero. */
27
+ export const SUPERVISION_GAPS = ["no-history", "no-deliverable-measurement", "history-truncated"] as const;
28
+ export type SupervisionGapReason = (typeof SUPERVISION_GAPS)[number];
29
+
30
+ /** The only history fields any rule may read: events, times, check codes, deliverable ids and plan revisions. Notes, withheld text and findings are absent from this type. */
31
+ export type SupervisionHistoryFact = Pick<HistoryEntry, "at" | "event"> & Partial<Pick<HistoryEntry, "by" | "checkKey" | "noWrites" | "planRevision" | "evidenceOnly" | "deliverables">>;
32
+
33
+ export interface TaskRevisionFacts {
34
+ id: number;
35
+ state: TaskState;
36
+ /** In history order, as the board appends it. A replayed record is the same record. */
37
+ history: readonly SupervisionHistoryFact[];
38
+ }
39
+
40
+ /** The hub's own deliverable reading (`Tasks.deliverableStatus`): ids and states, never a file body. */
41
+ export interface DeliverableMeasurementFact {
42
+ task: number;
43
+ /** True only when the hub measured the files for this task; an unmeasured row cannot say a file changed. */
44
+ checked: boolean;
45
+ changed: readonly string[];
46
+ missing?: readonly string[];
47
+ }
48
+
49
+ /** The hub's declared-overlap reading for one unordered pair (`Tasks.overlapHits`), one row per pair. */
50
+ export interface DeclaredOverlapFact {
51
+ /** Either side of the pair. The observation binds to the pair's lower task id, so either direction reads the same. */
52
+ task: number;
53
+ other: number;
54
+ }
55
+
56
+ export interface ObservationLimits {
57
+ /** Records the rule read for this observation, inside the current revision. */
58
+ records: number;
59
+ /** True when the revision held more records than a rule reads, so the observation saw a prefix. */
60
+ truncated: boolean;
61
+ }
62
+
63
+ export interface SupervisionObservation {
64
+ rule: SupervisionRuleId;
65
+ version: number;
66
+ task: number;
67
+ /** The work attempt the observation binds to: equal only for the same owner episode and plan revision. */
68
+ revision: string;
69
+ /** One observation per (rule, task, revision, trigger): a replayed or duplicate event keeps this value. */
70
+ trigger: string;
71
+ /** The admitted records that fired it, as `history:<index>`, `deliverable:<id>` or `task:<id>`. Never a note or a file body. */
72
+ refs: string[];
73
+ limits: ObservationLimits;
74
+ action: SupervisionAction;
75
+ reason: SupervisionReasonCode;
76
+ }
77
+
78
+ export interface SupervisionGap {
79
+ rule: SupervisionRuleId;
80
+ version: number;
81
+ task: number;
82
+ revision: string;
83
+ reason: SupervisionGapReason;
84
+ }
85
+
86
+ export interface EvaluatedRevision {
87
+ rule: SupervisionRuleId;
88
+ task: number;
89
+ revision: string;
90
+ }
91
+
92
+ export interface SupervisionEvaluation {
93
+ observations: SupervisionObservation[];
94
+ gap: SupervisionGap[];
95
+ /** Every `(rule, task, revision)` this evaluation read, deduped and in key order. A closed task is not read at all. */
96
+ evaluated: EvaluatedRevision[];
97
+ }
98
+
99
+ export interface SupervisionFacts {
100
+ tasks: readonly TaskRevisionFacts[];
101
+ deliverables?: readonly DeliverableMeasurementFact[];
102
+ overlaps?: readonly DeclaredOverlapFact[];
103
+ }
104
+
105
+ /** Records one rule reads from one revision. A longer revision is read as a prefix and the observation says `truncated`. */
106
+ export const MAX_RECORDS = 64;
107
+ /** Equal classified failures a revision shows before the repetition rule fires: the first is an incident, the second a pattern. */
108
+ export const REPEAT_FLOOR = 2;
109
+ /** Record refs one observation may carry. */
110
+ export const MAX_REFS = 8;
111
+ /** Shadow observations retained by one supervisor, and per task revision: the same bounds the proposal queue uses. */
112
+ export const MAX_OBSERVATIONS = 100;
113
+ export const MAX_PER_REVISION = 3;
114
+
115
+ /** A work attempt starts where an owner takes or retakes the task, or a plan revision begins. */
116
+ const EPISODE_EVENTS: ReadonlySet<string> = new Set(["accepted", "reassigned", "escalated", "reopened"]);
117
+ /** Evidence that clears a failure streak: the check ran again, integration landed, or the work was approved. Ordinary events neither fire nor clear. */
118
+ const RESET_EVENTS: ReadonlySet<string> = new Set(["check passed", "integrated", "approved"]);
119
+ /** Evidence that the pair's overlap was taken up: an attempt counts, a failure of one is the repetition rule's business. */
120
+ const INTEGRATION_EVENTS: ReadonlySet<string> = new Set(["integration requested", "integrated", "integration unresolved"]);
121
+
122
+ export interface TaskRevision {
123
+ revision: string;
124
+ /** First history index inside the current revision. */
125
+ from: number;
126
+ /**
127
+ * History index of the acceptance that still governs this revision, or `-1` when none does. A plan revision keeps the
128
+ * acceptance (the same owner continues) but moves `from` past it, so this can be earlier than `from`.
129
+ */
130
+ accepted: number;
131
+ }
132
+
133
+ /**
134
+ * The work attempt a record belongs to: the number of owner episodes and the host-authored plan revision. It is not
135
+ * `history.length`: unrelated bookkeeping (a check result, a quiet hub entry) must not split one observation into two.
136
+ * A plan revision starts an attempt of its own, so failures recorded under the previous plan are not read as this one's.
137
+ */
138
+ export function taskRevision(task: Pick<TaskRevisionFacts, "history">): TaskRevision {
139
+ let episodes = 0, from = 0, plan = "none", accepted = -1;
140
+ for (const [index, entry] of task.history.entries()) {
141
+ // A reassignment, an escalation or a reopen hands the work to another attempt, so an earlier acceptance stops governing.
142
+ if (EPISODE_EVENTS.has(entry.event)) { episodes += 1; from = index + 1; accepted = entry.event === "accepted" ? index : -1; }
143
+ if (entry.planRevision) { plan = String(entry.planRevision.revision); from = index + 1; }
144
+ }
145
+ return { revision: `${episodes}:${plan}`, from, accepted };
146
+ }
147
+
148
+ /**
149
+ * The history indices one revision governs, when the record set still contains it. `taskRevision` names the current
150
+ * attempt only; this names an attempt the history has moved past, which is the window a stored proposal was read under
151
+ * (an escalation recorded after an acceptance is itself an episode event, so the current revision is no longer that
152
+ * one). A record belongs to the revision in force before it, exactly as `taskRevision` counts it.
153
+ */
154
+ export function revisionSpan(history: readonly SupervisionHistoryFact[], revision: string): { from: number; to: number } | undefined {
155
+ let episodes = 0, plan = "none", from = -1, to = -1;
156
+ for (const [index, entry] of history.entries()) {
157
+ if (`${episodes}:${plan}` === revision) { if (from < 0) from = index; to = index; }
158
+ if (EPISODE_EVENTS.has(entry.event)) episodes += 1;
159
+ if (entry.planRevision) plan = String(entry.planRevision.revision);
160
+ }
161
+ return from < 0 ? undefined : { from, to };
162
+ }
163
+
164
+ /** One classified failure, in a closed vocabulary: the kind of failure, never its text. */
165
+ function failureClass(entry: SupervisionHistoryFact): string | undefined {
166
+ if (entry.event === "check failed") return `check:${entry.checkKey ?? "unknown"}`;
167
+ // #852: a code-scope reviewer's rejection that names no finding is not a defect of the work.
168
+ if (entry.event === "changes_requested") return entry.evidenceOnly ? undefined : "review:changes_requested";
169
+ if (entry.event === "integration unresolved") return "integration:unresolved";
170
+ if (entry.event === "done" && entry.noWrites === true) return "done:no-writes";
171
+ return undefined;
172
+ }
173
+
174
+ interface Side {
175
+ task: TaskRevisionFacts;
176
+ revision: string;
177
+ from: number;
178
+ /** From `taskRevision`: the acceptance still governing this revision, which a plan change can leave before the window. */
179
+ accepted: number;
180
+ window: SupervisionHistoryFact[];
181
+ limits: ObservationLimits;
182
+ }
183
+
184
+ const observationKey = (observation: SupervisionObservation): string => `${observation.rule}:${observation.task}:${observation.revision}:${observation.trigger}`;
185
+ const gapKey = (gap: SupervisionGap): string => `${gap.rule}:${gap.task}:${gap.revision}:${gap.reason}`;
186
+ const evaluatedKey = (evaluated: EvaluatedRevision): string => `${evaluated.rule}:${evaluated.task}:${evaluated.revision}`;
187
+ const gapOf = (rule: SupervisionRuleId, task: number, revision: string, reason: SupervisionGapReason): SupervisionGap => ({ rule, version: SUPERVISION_RULE_VERSION[rule], task, revision, reason });
188
+
189
+ /**
190
+ * Repeated equal classified failures since the last clearing evidence, one observation per class that reached the floor.
191
+ * A class already observed in this revision is not observed twice, so only the per-revision bound can refuse it.
192
+ */
193
+ function repeatedFailures(side: Side): SupervisionObservation[] {
194
+ const found: SupervisionObservation[] = [], seen = new Set<string>();
195
+ let cls: string | undefined, run: string[] = [];
196
+ for (const [offset, entry] of side.window.entries()) {
197
+ if (RESET_EVENTS.has(entry.event)) { cls = undefined; run = []; continue; }
198
+ const next = failureClass(entry);
199
+ if (!next) continue;
200
+ if (next !== cls) { cls = next; run = []; }
201
+ run.push(`history:${side.from + offset}`);
202
+ if (run.length < REPEAT_FLOOR || seen.has(next)) continue;
203
+ seen.add(next);
204
+ found.push({ rule: "repeated_failure", version: SUPERVISION_RULE_VERSION.repeated_failure, task: side.task.id, revision: side.revision, trigger: `failures:${next}`, refs: run.slice(-MAX_REFS), limits: side.limits, action: "escalate", reason: "repeated_failure" });
205
+ }
206
+ return found;
207
+ }
208
+
209
+ interface Reading { observation?: SupervisionObservation; gap?: SupervisionGap }
210
+
211
+ /** A recorded check whose delivered files the hub now measures as changed or missing. */
212
+ function invalidatedCheck(side: Side, measurement: DeliverableMeasurementFact | undefined): Reading {
213
+ let check: number | undefined;
214
+ const recorded = new Set<string>();
215
+ for (const [offset, entry] of side.window.entries()) {
216
+ if (entry.event === "check passed") check = offset;
217
+ for (const record of (entry.deliverables ?? []) as readonly DeliverableRecord[]) recorded.add(record.id);
218
+ }
219
+ if (check === undefined || !recorded.size) return {};
220
+ if (!measurement?.checked) return { gap: gapOf("deliverable_invalidated_check", side.task.id, side.revision, "no-deliverable-measurement") };
221
+ const stale = [...new Set([...measurement.changed, ...(measurement.missing ?? [])])].filter((id) => recorded.has(id)).sort();
222
+ if (!stale.length) return {};
223
+ return { observation: { rule: "deliverable_invalidated_check", version: SUPERVISION_RULE_VERSION.deliverable_invalidated_check, task: side.task.id, revision: side.revision, trigger: `check:${stale.slice(0, MAX_PER_REVISION).join(",")}`, refs: [`history:${side.from + check}`, ...stale.map((id) => `deliverable:${id}`)].slice(0, MAX_REFS), limits: side.limits, action: "recheck", reason: "stale_check" } };
224
+ }
225
+
226
+ /**
227
+ * Integration evidence recorded after an acceptance. A plan change can leave the acceptance before the window, so the
228
+ * read starts at the acceptance when it is inside it and at the window's first record otherwise.
229
+ */
230
+ const integratedAfter = (side: Side, accepted: number): boolean => side.window.slice(Math.max(0, accepted - side.from + 1)).some((entry) => INTEGRATION_EVENTS.has(entry.event));
231
+
232
+ /**
233
+ * Declared overlap that outlived both owners' acceptance of their current revision, with no integration evidence since.
234
+ * Persistence is record-based (both sides accepted), never elapsed time: silence proves nothing. The pair is bound to
235
+ * its lower task id, so the same pair named in either direction is one observation and not two.
236
+ */
237
+ function unintegratedOverlap(pair: DeclaredOverlapFact, sides: Map<number, Side>): { reading: Reading; evaluated?: EvaluatedRevision } {
238
+ const low = Math.min(pair.task, pair.other), high = Math.max(pair.task, pair.other);
239
+ const mine = sides.get(low), theirs = sides.get(high);
240
+ // The pair is read as its lower id under that id's revision; a pair whose low side is absent keeps this as its gap revision.
241
+ // A pair with a closed side is not supervised, like a closed task: no coverage, no gap, no observation.
242
+ if ((mine && isClosedTaskState(mine.task.state)) || (theirs && isClosedTaskState(theirs.task.state))) return { reading: {} };
243
+ const evaluated: EvaluatedRevision = { rule: "declared_overlap_without_integration", task: low, revision: (mine ?? theirs)?.revision ?? "0:none" };
244
+ // Read but undecided: the coverage entry and the gap name the same triple, and the gap wins.
245
+ if (!mine || !theirs) return { evaluated, reading: { gap: gapOf("declared_overlap_without_integration", low, evaluated.revision, "no-history") } };
246
+ const accepted = [mine.accepted, theirs.accepted] as const;
247
+ if (accepted[0] < 0 || accepted[1] < 0) return { evaluated, reading: {} };
248
+ if (integratedAfter(mine, accepted[0]) || integratedAfter(theirs, accepted[1])) return { evaluated, reading: {} };
249
+ // Integration past the read prefix is unknown, not absent: a clipped window cannot report the pair as unintegrated.
250
+ if (mine.limits.truncated || theirs.limits.truncated) return { evaluated, reading: { gap: gapOf("declared_overlap_without_integration", low, mine.revision, "history-truncated") } };
251
+ return {
252
+ evaluated,
253
+ reading: {
254
+ observation: {
255
+ rule: "declared_overlap_without_integration", version: SUPERVISION_RULE_VERSION.declared_overlap_without_integration, task: low, revision: mine.revision,
256
+ trigger: `overlap:${low}:${high}`, refs: [`task:${high}`, `history:${accepted[0]}`, `history:${accepted[1]}`].slice(0, MAX_REFS),
257
+ limits: { records: mine.limits.records + theirs.limits.records, truncated: mine.limits.truncated || theirs.limits.truncated }, action: "request_integration", reason: "unintegrated_overlap",
258
+ },
259
+ },
260
+ };
261
+ }
262
+
263
+ /**
264
+ * Every rule's reading of one fact set, in a stable order, with no side effect of any kind. Closed tasks are not
265
+ * supervised: an approved or cancelled task has nothing left to decide. A gap names the rule and the missing record;
266
+ * elapsed silence alone never produces an observation or a gap. `evaluated` is the coverage of that read: one entry per
267
+ * rule and task revision the evaluator looked at, whether or not it found anything.
268
+ */
269
+ export function evaluateSupervision(facts: SupervisionFacts): SupervisionEvaluation {
270
+ const observations: SupervisionObservation[] = [], gaps: SupervisionGap[] = [], evaluated: EvaluatedRevision[] = [], sides = new Map<number, Side>();
271
+ for (const task of facts.tasks) {
272
+ const { revision, from, accepted } = taskRevision(task);
273
+ const window = task.history.slice(from, from + MAX_RECORDS);
274
+ sides.set(task.id, { task, revision, from, accepted, window, limits: { records: window.length, truncated: task.history.length - from > MAX_RECORDS } });
275
+ }
276
+ const keep = (reading: Reading): void => { if (reading.observation) observations.push(reading.observation); if (reading.gap) gaps.push(reading.gap); };
277
+ const measurements = new Map((facts.deliverables ?? []).map((row) => [row.task, row]));
278
+ for (const side of sides.values()) {
279
+ if (isClosedTaskState(side.task.state)) continue;
280
+ evaluated.push({ rule: "repeated_failure", task: side.task.id, revision: side.revision }, { rule: "deliverable_invalidated_check", task: side.task.id, revision: side.revision });
281
+ const repeated = repeatedFailures(side);
282
+ observations.push(...repeated);
283
+ const check = invalidatedCheck(side, measurements.get(side.task.id));
284
+ keep(check);
285
+ // A clipped revision is missing coverage, not a clean one: a rule that saw only a prefix says so.
286
+ if (!side.limits.truncated) continue;
287
+ if (!repeated.length) gaps.push(gapOf("repeated_failure", side.task.id, side.revision, "history-truncated"));
288
+ if (!check.observation && !check.gap) gaps.push(gapOf("deliverable_invalidated_check", side.task.id, side.revision, "history-truncated"));
289
+ }
290
+ for (const overlap of facts.overlaps ?? []) {
291
+ const pair = unintegratedOverlap(overlap, sides);
292
+ if (pair.evaluated) evaluated.push(pair.evaluated);
293
+ keep(pair.reading);
294
+ }
295
+ // One entry per rule and revision: a pair named twice, or a task listed twice, is one read and not two.
296
+ const coverage = new Map(evaluated.map((entry) => [evaluatedKey(entry), entry]));
297
+ return {
298
+ observations: observations.sort((a, b) => (observationKey(a) < observationKey(b) ? -1 : observationKey(a) > observationKey(b) ? 1 : 0)),
299
+ gap: gaps.sort((a, b) => (gapKey(a) < gapKey(b) ? -1 : gapKey(a) > gapKey(b) ? 1 : 0)),
300
+ evaluated: [...coverage.values()].sort((a, b) => (evaluatedKey(a) < evaluatedKey(b) ? -1 : evaluatedKey(a) > evaluatedKey(b) ? 1 : 0)),
301
+ };
302
+ }
303
+
304
+ export interface ShadowCounts {
305
+ evaluations: number;
306
+ observations: number;
307
+ deduped: number;
308
+ /** Observations and gaps a retention bound refused; they are counted, never stored. */
309
+ suppressed: number;
310
+ gap: number;
311
+ /** Coverage keys a retention bound refused: a bound never reads as "nothing was evaluated". */
312
+ evaluatedSuppressed: number;
313
+ /** AC2: shadow mode has no effect path at all, so these are the literal type zero. */
314
+ workerTurns: 0;
315
+ actionWrites: 0;
316
+ notifications: 0;
317
+ }
318
+
319
+ /**
320
+ * Shadow mode: counts and bounded ids only. It keeps no worker, starts no timer and holds no dependency, so it can
321
+ * record what a rule would have said without producing a turn, an action write or a notification — those counters are
322
+ * the literal `0` and a non-zero value would not typecheck.
323
+ */
324
+ export class ShadowSupervisor {
325
+ private readonly retained = new Map<string, SupervisionObservation>();
326
+ private readonly retainedGaps = new Map<string, SupervisionGap>();
327
+ private readonly retainedEvaluated = new Map<string, EvaluatedRevision>();
328
+ private readonly perRevision = new Map<string, number>();
329
+ private evaluations = 0;
330
+ private deduped = 0;
331
+ private suppressed = 0;
332
+ private evaluatedSuppressed = 0;
333
+
334
+ /** Adds only what is new. Replaying the same facts, or an event that is a duplicate of one already read, adds nothing. */
335
+ observe(facts: SupervisionFacts): SupervisionObservation[] {
336
+ this.evaluations += 1;
337
+ const evaluation = evaluateSupervision(facts), added: SupervisionObservation[] = [];
338
+ for (const entry of evaluation.evaluated) {
339
+ const key = evaluatedKey(entry);
340
+ if (this.retainedEvaluated.has(key)) continue;
341
+ if (this.retainedEvaluated.size >= MAX_OBSERVATIONS) { this.evaluatedSuppressed += 1; continue; }
342
+ this.retainedEvaluated.set(key, entry);
343
+ }
344
+ for (const gap of evaluation.gap) {
345
+ const key = gapKey(gap);
346
+ if (this.retainedGaps.has(key)) continue;
347
+ if (this.retainedGaps.size >= MAX_OBSERVATIONS) { this.suppressed += 1; continue; }
348
+ this.retainedGaps.set(key, gap);
349
+ }
350
+ for (const observation of evaluation.observations) {
351
+ const key = observationKey(observation);
352
+ if (this.retained.has(key)) { this.deduped += 1; continue; }
353
+ const revisionKey = `${observation.rule}:${observation.task}:${observation.revision}`, held = this.perRevision.get(revisionKey) ?? 0;
354
+ if (this.retained.size >= MAX_OBSERVATIONS || held >= MAX_PER_REVISION) { this.suppressed += 1; continue; }
355
+ this.retained.set(key, observation);
356
+ this.perRevision.set(revisionKey, held + 1);
357
+ added.push(observation);
358
+ }
359
+ return added;
360
+ }
361
+
362
+ /** Retained observations in a stable order, for a receipt or a fixture comparison. */
363
+ observations(): SupervisionObservation[] {
364
+ return [...this.retained.values()].sort((a, b) => (observationKey(a) < observationKey(b) ? -1 : observationKey(a) > observationKey(b) ? 1 : 0));
365
+ }
366
+
367
+ /** Retained gaps in the evaluator's own `(rule, task, revision, reason)` order: the order `gapKey` sorts by. */
368
+ gaps(): SupervisionGap[] {
369
+ return [...this.retainedGaps.values()].sort((a, b) => (gapKey(a) < gapKey(b) ? -1 : gapKey(a) > gapKey(b) ? 1 : 0));
370
+ }
371
+
372
+ /** The `(rule, task, revision)` triples this supervisor read, deduped and in `evaluatedKey` order: coverage, not findings. */
373
+ evaluated(): EvaluatedRevision[] {
374
+ return [...this.retainedEvaluated.values()].sort((a, b) => (evaluatedKey(a) < evaluatedKey(b) ? -1 : evaluatedKey(a) > evaluatedKey(b) ? 1 : 0));
375
+ }
376
+
377
+ /**
378
+ * Everything this supervisor holds, as one read: the exported contract a consumer reads (agent-research#63) instead of
379
+ * reaching into the retained maps. A snapshot is a copy, so nothing that happens afterwards reaches it.
380
+ */
381
+ snapshot(): { observations: SupervisionObservation[]; gap: SupervisionGap[]; counts: ShadowCounts; evaluated: EvaluatedRevision[] } {
382
+ return { observations: this.observations(), gap: this.gaps(), counts: this.counts(), evaluated: this.evaluated() };
383
+ }
384
+
385
+ counts(): ShadowCounts {
386
+ return { evaluations: this.evaluations, observations: this.retained.size, deduped: this.deduped, suppressed: this.suppressed, gap: this.retainedGaps.size, evaluatedSuppressed: this.evaluatedSuppressed, workerTurns: 0, actionWrites: 0, notifications: 0 };
387
+ }
388
+ }
@@ -96,6 +96,8 @@ export class SupervisionFeed {
96
96
  else if (event === "approved") {
97
97
  this.milestone(task.id, "review", { ...fields, verdict: "approved" });
98
98
  this.milestone(task.id, "approved", fields);
99
+ } else if (event === "merged outside the hub" && task.state === "approved") {
100
+ this.milestone(task.id, "approved", { by: entry.by, owner: task.owner });
99
101
  } else if (event === "idle sweep" && entry.sweep) this.milestone(task.id, "sweep", { ...fields, sweep: entry.sweep.kind });
100
102
  else if (event === "reassigned") this.milestone(task.id, "moved", fields);
101
103
  else if (["assigned", "accepted", "declined", "escalated"].includes(event)) this.milestone(task.id, event as SupervisionMilestone, fields);
@@ -5,8 +5,8 @@ const fullHead = (value: unknown): string | undefined => typeof value === "strin
5
5
 
6
6
  /** The last approval remains historical evidence after a new delivery or a withdrawal. Unknown legacy heads stay unknown. */
7
7
  export function approvalBinding(task: Task): ApprovalBinding | undefined {
8
- const verdict = task.history.findLast(entry => entry.event === "approved");
9
- if (!verdict) return undefined;
8
+ const verdict = task.history.findLast(entry => entry.event === "approved" || entry.event === "merged outside the hub");
9
+ if (!verdict || verdict.event === "merged outside the hub") return undefined;
10
10
  const head = fullHead(verdict.reviewedHead) ?? fullHead(verdict.reviewFindings?.head)
11
11
  ?? (task.state === "approved" ? fullHead(task.sdlc?.reviewedHead) : undefined);
12
12
  const latestHead = fullHead(task.refs.commit ?? task.sdlc?.head ?? task.sdlc?.localHead);
@@ -104,6 +104,11 @@ export class TaskRepositories {
104
104
  }
105
105
  return this.roots.get(root) ?? { key: `path:${root}`, root, aliases: [root] };
106
106
  }
107
+ /** Read-only consumers never resolve a cold scope or inspect a path. */
108
+ cachedScope(refs: TaskRefs): TaskRepository | undefined {
109
+ return this.scopes.get(JSON.stringify([refs.repo ?? null, (refs.paths ?? []).filter(isAbsolute)]));
110
+ }
111
+
107
112
  /** Resolve only once per refs identity. Default project-only tasks never invoke Git. Negative probes are cached too. */
108
113
  scope(refs: TaskRefs): TaskRepository {
109
114
  const absolute = (refs.paths ?? []).filter(isAbsolute);