@staix/agent-hub 0.49.1 → 0.51.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 (99) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -1
  3. package/docs/adding-an-ai-tool.md +2 -2
  4. package/docs/agent-notes/README.md +1 -0
  5. package/docs/agent-notes/adapters.md +3 -3
  6. package/docs/agent-notes/daemon.md +1 -1
  7. package/docs/agent-notes/local-worker.md +3 -3
  8. package/docs/agent-notes/tasks.md +5 -1
  9. package/docs/design/adapters.md +17 -0
  10. package/docs/design/agent-hub.md +1 -1
  11. package/docs/design/cli-output-inventory.md +24 -19
  12. package/docs/design/cli-output.md +1 -1
  13. package/docs/design/roadmap.md +2 -2
  14. package/docs/design/task-board.md +34 -0
  15. package/docs/dogfood.md +8 -3
  16. package/docs/operations.md +53 -4
  17. package/docs/quickstart.md +26 -2
  18. package/docs/roadmap.json +20 -20
  19. package/docs/roadmap.md +2 -2
  20. package/docs/sdlc.md +3 -2
  21. package/docs/specs/2026-09-19-agent-hub-design.md +1 -0
  22. package/docs/verification/2026-11-29-0.50.0.md +54 -0
  23. package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
  24. package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
  25. package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
  26. package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
  27. package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
  28. package/docs/verification/2026-11-30-0.51.0.md +91 -0
  29. package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
  30. package/docs/verified.json +31 -27
  31. package/package.json +1 -1
  32. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  33. package/plugins/agent-hub/kimi-hook.js +1329 -24629
  34. package/plugins/agent-hub/server.js +638 -414
  35. package/scripts/check-docs.mjs +1 -1
  36. package/src/adapters/acp.ts +13 -13
  37. package/src/adapters/agy/definition.ts +2 -2
  38. package/src/adapters/agy/entry.ts +2 -0
  39. package/src/adapters/claude-channel-evidence.ts +7 -3
  40. package/src/adapters/compat.ts +4 -3
  41. package/src/adapters/definitions/builtin-metadata.ts +2 -2
  42. package/src/adapters/definitions/native-cli-claude-launch.ts +3 -1
  43. package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
  44. package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
  45. package/src/adapters/definitions/native-cli-entry-jcode.ts +2 -0
  46. package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
  47. package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
  48. package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
  49. package/src/adapters/definitions/native-cli-entry-types.ts +3 -1
  50. package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
  51. package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
  52. package/src/adapters/definitions/native-config-defaults.ts +1 -1
  53. package/src/adapters/jcode.ts +16 -0
  54. package/src/adapters/native-facts-hooks.ts +12 -0
  55. package/src/cli/autonomy-offline.ts +1 -1
  56. package/src/cli/bench.ts +1 -1
  57. package/src/cli/claude-profile-hook.ts +31 -11
  58. package/src/cli/commands/releases.ts +82 -0
  59. package/src/cli/conductor-recovery.ts +1 -1
  60. package/src/cli/facts-hook.ts +11 -4
  61. package/src/cli/help.ts +12 -10
  62. package/src/cli/identity.ts +5 -1
  63. package/src/cli/init-prompt.ts +1 -1
  64. package/src/cli/init-settings.ts +4 -35
  65. package/src/cli/init.ts +1 -1
  66. package/src/cli/json-text-spans.ts +57 -0
  67. package/src/cli/launch-check.ts +157 -0
  68. package/src/cli/launch.ts +19 -1
  69. package/src/cli/main.ts +63 -10
  70. package/src/cli/memory.ts +1 -1
  71. package/src/cli/output.ts +14 -1
  72. package/src/cli/preview.ts +1 -1
  73. package/src/cli/recovery-launch.ts +1 -1
  74. package/src/cli/setup-homes.ts +2 -2
  75. package/src/cli/start-agents-run.ts +85 -7
  76. package/src/cli/start-check.ts +28 -0
  77. package/src/cli/upgrade-runtime.ts +1 -1
  78. package/src/cli/warn-line.ts +1 -1
  79. package/src/hub/ci-watch.ts +311 -79
  80. package/src/hub/config-apply.ts +1 -1
  81. package/src/hub/config.ts +518 -0
  82. package/src/hub/control-client.ts +1 -1
  83. package/src/hub/daemon.ts +76 -513
  84. package/src/hub/delivery-public.ts +11 -0
  85. package/src/hub/hub-check.ts +125 -0
  86. package/src/hub/path-policy.ts +1 -1
  87. package/src/hub/permission-mode.ts +3 -40
  88. package/src/hub/permission-paths.ts +41 -0
  89. package/src/hub/recovery-policy.ts +1 -1
  90. package/src/hub/releases-inventory.ts +198 -0
  91. package/src/hub/runtime-capture-prune.ts +25 -3
  92. package/src/hub/runtime-prune-health.ts +8 -1
  93. package/src/hub/sdlc-release-authorization.ts +42 -21
  94. package/src/hub/sdlc-release-diagnostics.ts +5 -0
  95. package/src/hub/sdlc-release-policy.ts +21 -7
  96. package/src/hub/sdlc-release.ts +80 -20
  97. package/src/hub/sdlc.ts +7 -3
  98. package/src/hub/tasks.ts +138 -36
  99. package/src/ui/plugin.ts +1 -1
package/src/hub/tasks.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { requireConductor } from "./conductor.ts";
1
+ import { conductorPeer, requireConductor } from "./conductor.ts";
2
2
  import { instructedExecution, instructedHistory } from "./instructed-exact.ts";
3
3
  import { managedTaskPullRequest } from "./task-pr.ts";
4
4
  import { parseMilestoneInput, parseMilestonePatch, milestoneId, milestoneRevision, milestoneLinkRef, githubRepo, MILESTONE_STATES, type Milestone, type MilestoneLinkKind, type MilestonePatch, type MilestoneState, type MilestoneSuggestion, type SuggestionItemKind, type DecomposePart, type DecomposeIntake, type MilestoneDecomposition, type DecompositionAccept } from "./roadmap.ts";
@@ -138,7 +138,7 @@ import type { SpecsCheckReport, SpecsCoverReport } from "./specs.ts";
138
138
  import { definitionOf as builtinDefinitionOf } from "../adapters/registry.ts";
139
139
  import { ADAPTERS, DEFAULT_REVIEW_POOL, definitionOf, familyOf, type ProjectAdapterCatalog } from "../adapters/registry.ts";
140
140
  import { plannerGrooming, nextSweep, plannedStartPending, taskSweepConfig, taskWait, TASK_WAIT_MAX_MS, TASK_WAIT_REASON_MAX, type TaskSweepConfig, type SweepRecord } from "./task-sweep.ts";
141
- import { CiWatchers, pollCi, type CiOutcome, type CiWatch } from "./ci-watch.ts";
141
+ import { CiWatchers, pollCi, type CiOutcome, type CiRetryDecision, type CiShardRetry, type CiSnapshot, type CiWatch } from "./ci-watch.ts";
142
142
  import { acceptedSpecEdit, planningIssueReceipt, linkedReceipt, openPrFor, readPrCostHistory, readReviewReadiness, reviewReadinessFromEvidence, type PrEvidence, type ReviewReadiness, readPlanIssueMetadata, canonicalStage, checklistOf, readSdlcPr, readSdlcPrHead, readSpecEdit, sdlcConfig, sdlcReceipt, sdlcStatus, specState, SPEC_STATE_TEXT, stageDefinition, lifecycleStage, type SdlcConfig, type MergeRecord, type ReadbackMergeRecord, type PlanIssueMetadata, sdlcGh, type SdlcGh, type SdlcStatus, type SpecEdit, type SpecState, localSupersedingTask, storedSpecAcceptance, carriedSpecAcceptance } from "./sdlc.ts";
143
143
  import { missingReadbackRefs, parseSpecReadbackReport, type ReadbackView, type SpecReadbackReport } from "./spec-readback.ts";
144
144
 
@@ -273,7 +273,7 @@ export interface TasksDeps {
273
273
  */
274
274
  reviewerCheckout?: (peer: PeerId) => AuditSource | undefined;
275
275
  /** #785 P1b: the per-head CI watcher's bounds; tests shorten them, the defaults are `CI_WATCH_*` in `ci-watch.ts`. */
276
- ciWatch?: { deadlineMs?: number; pollMs?: number };
276
+ ciWatch?: { deadlineMs?: number; missingRunMs?: number; pollMs?: number };
277
277
  /** #785 P1c: `tasks.auto_pull`, read for every automatic pull trigger; absent or false pulls nothing. */
278
278
  autoPull?: () => boolean;
279
279
  briefs?: Briefs;
@@ -936,9 +936,10 @@ export class Tasks {
936
936
  constructor(private readonly d: TasksDeps) {
937
937
  this.ciWatchers = new CiWatchers({
938
938
  ...d.ciWatch,
939
- poll: watch => pollCi(watch, watch.head, d.sdlc ? requiredChecksFor(d.sdlc.config(), watch.repo) : [], d.sdlc?.gh ?? sdlcGh),
939
+ poll: watch => pollCi(watch, watch.head, d.sdlc ? requiredChecksFor(d.sdlc.config(), watch.repo) : [], d.sdlc?.gh ?? sdlcGh, true),
940
940
  current: watch => this.ciWatchCurrent(watch),
941
- finish: (watch, outcome) => this.ciCompleted(watch, outcome),
941
+ retry: (watch, retry, completed, mergeable) => this.retryCiShard(watch, retry, completed, mergeable),
942
+ finish: (watch, outcome, snapshot) => this.ciCompleted(watch, outcome, snapshot),
942
943
  });
943
944
  d.board.trackPlanRevisions = () => (d.sdlc?.config().mode ?? "off") !== "off";
944
945
  this.repositories = new TaskRepositories(d.cwd, d.repository);
@@ -1157,6 +1158,7 @@ export class Tasks {
1157
1158
  const task = validate();
1158
1159
  if (task.history.length !== revision) refuse(`task #${task.id}: it changed while the reason was screened; read it with hub_task_show and record the wait again`);
1159
1160
  const next = this.d.board.update(task.id, by, "wait recorded", {}, reason, { wait: { until, owner: task.owner! }, ...(pii || withheld ? { withheld: true as const } : {}) }, revision);
1161
+ this.watchCi(next);
1160
1162
  this.d.notify(`task ${this.publicTitle(next)}: wait recorded by ${by} until ${new Date(until).toISOString()}`);
1161
1163
  return next;
1162
1164
  }
@@ -3273,12 +3275,13 @@ export class Tasks {
3273
3275
  private writePlannerNotices(task: Task, before: ReadonlyMap<PeerId, number>, approved = false): void {
3274
3276
  this.releaseNotice(`task #${task.id}: could not notify planner about ready work`, () => {
3275
3277
  const now = this.d.now?.() ?? Date.now();
3276
- const changes = new Map<PeerId, { capacity: Set<PeerId>; ready: Set<number> }>();
3277
- const add = (planner: PeerId, peer?: PeerId, id?: number) => {
3278
+ const changes = new Map<PeerId, { capacity: Set<PeerId>; ready: Set<number>; owned: Set<number> }>();
3279
+ const add = (planner: PeerId, peer?: PeerId, id?: number, owned?: number) => {
3278
3280
  if (!this.d.bus.isRostered(planner)) return;
3279
- const change = changes.get(planner) ?? { capacity: new Set<PeerId>(), ready: new Set<number>() };
3281
+ const change = changes.get(planner) ?? { capacity: new Set<PeerId>(), ready: new Set<number>(), owned: new Set<number>() };
3280
3282
  if (peer) change.capacity.add(peer);
3281
3283
  if (id !== undefined) change.ready.add(id);
3284
+ if (owned !== undefined) change.owned.add(owned);
3282
3285
  changes.set(planner, change);
3283
3286
  };
3284
3287
  const released = new Set<PeerId>();
@@ -3290,6 +3293,8 @@ export class Tasks {
3290
3293
  if (card.reserved) readied.add(card.reserved);
3291
3294
  }
3292
3295
  }
3296
+ // #1801: a dependent that already has an owner is ready too; the planner sees it beside the reserved ready ones.
3297
+ if (approved) for (const card of this.ownedReadyDependents(task)) for (const planner of this.taskPlanner(card)) add(planner, undefined, undefined, card.id);
3293
3298
  for (const [planner, change] of changes) this.releaseNotice(`could not notify planner ${planner} about ready work`, () => {
3294
3299
  const pending = this.d.bus.pendingEnvelopes(planner).filter(env => env.from === HUB && env.kind === "task" && env.body.startsWith("Planner work ready:"));
3295
3300
  // The bus retains these hub-written lines across restart; an in-memory cache would lose unsettled events.
@@ -3298,6 +3303,8 @@ export class Tasks {
3298
3303
  if (capacity) change.capacity.add(capacity[1]!);
3299
3304
  const ready = /^backlog_ready: #(\d+)$/.exec(line);
3300
3305
  if (ready && Number.isSafeInteger(Number(ready[1]))) change.ready.add(Number(ready[1]));
3306
+ const owned = /^owned_ready: #(\d+) \(\S+\)$/.exec(line);
3307
+ if (owned && Number.isSafeInteger(Number(owned[1]))) change.owned.add(Number(owned[1]));
3301
3308
  }
3302
3309
  const lines: string[] = [];
3303
3310
  for (const peer of change.capacity) {
@@ -3309,6 +3316,11 @@ export class Tasks {
3309
3316
  if (card?.state === "backlog" && this.taskPlanner(card).includes(planner) && !this.waitsFor(card).length && !plannedStartPending(card, now)) lines.push(`backlog_ready: #${id}`);
3310
3317
  else change.ready.delete(id);
3311
3318
  }
3319
+ for (const id of change.owned) {
3320
+ const card = this.d.board.get(id);
3321
+ if (card?.owner && this.ownedReadyNow(card) && this.taskPlanner(card).includes(planner)) lines.push(`owned_ready: #${id} (${card.owner})`);
3322
+ else change.owned.delete(id);
3323
+ }
3312
3324
  for (const env of pending) this.d.bus.withdraw(env.id);
3313
3325
  const env = newEnvelope(HUB, sanitize(`Planner work ready:\n${lines.join("\n")}\nRead the current board before planning or pulling work.`), { to: [planner], kind: "task" });
3314
3326
  if (!this.d.bus.publish(env).includes(planner)) throw new Error("the notice was not queued");
@@ -3319,6 +3331,16 @@ export class Tasks {
3319
3331
  });
3320
3332
  }
3321
3333
 
3334
+ /** #1801: an owned dependent that has not started and has nothing left to wait for. */
3335
+ private ownedReadyNow(card: Task): boolean {
3336
+ return !!card.owner && (card.state === "proposed" || card.state === "in_progress") && !taskHasStarted(card) && !this.waitsFor(card).length
3337
+ && !plannedStartPending(card, this.d.now?.() ?? Date.now());
3338
+ }
3339
+
3340
+ private ownedReadyDependents(approved: Task): Task[] {
3341
+ return this.d.board.list().filter(card => card.deps?.includes(approved.id) && this.ownedReadyNow(card));
3342
+ }
3343
+
3322
3344
  /** The top card explicitly reserved for `peer` that this planner may pull now; the notice and the opt-in pull read the same rule. `pullable` keeps the staged backlog cards only. */
3323
3345
  private topReservedReady(peer: PeerId, planner?: PeerId, pullable = false): Task | undefined {
3324
3346
  const now = this.d.now?.() ?? Date.now();
@@ -5927,9 +5949,16 @@ export class Tasks {
5927
5949
  private async releaseDependents(approved: Task): Promise<void> {
5928
5950
  try {
5929
5951
  // Its dependents and, as its owner's slot just freed (#655), that owner's held ready tasks: one list in priority order.
5952
+ const alreadyOwned = this.ownedReadyDependents(approved); // before the offers below give unowned dependents an owner
5930
5953
  const ready = this.d.board.list("proposed").filter(t => !t.owner && !this.waitsFor(t).length
5931
5954
  && (t.deps?.includes(approved.id) || !!approved.owner && t.reserved === approved.owner && this.isHeld(t))).sort(this.readyOrder);
5932
5955
  for (const t of ready) await this.offerReady(t, t.deps?.includes(approved.id) ? `#${approved.id} approved` : "owner slot freed");
5956
+ // #1801: an owned dependent is never offered again; its owner hears once per approval that nothing is left to wait for.
5957
+ for (const t of alreadyOwned) {
5958
+ if (!t.owner || t.owner === HUB || t.owner === USER) continue;
5959
+ this.releaseNotice(`task #${t.id}: could not tell ${t.owner} it is ready`, () => this.d.bus.publish(newEnvelope(HUB,
5960
+ `ready: hub task ${approved.id} approved; nothing left to wait for\nRead hub_task_show for the task before acting.`, { to: [t.owner!], kind: "task", priority: "status", refs: { task: String(t.id) } })));
5961
+ }
5933
5962
  } catch (e) {
5934
5963
  this.releaseNotice(`task #${approved.id}: could not release dependents: ${e instanceof Error ? e.message : String(e)}`);
5935
5964
  }
@@ -8088,7 +8117,9 @@ export class Tasks {
8088
8117
  if (next.reviewedHead !== undefined && (next.reviewedHead !== task.sdlc?.reviewedHead || (suppliedHead && artifactChanged))) this.mine(task, by, "reviewer", true);
8089
8118
  const departure = task.history.findLast(h => h.by === USER && h.planDeparture)?.planDeparture;
8090
8119
  const invalidatesDeparture = !!departure && (artifactChanged || next.localHead !== task.sdlc?.localHead && next.localHead !== undefined && next.localHead !== departure.head || next.reviewedHead !== task.sdlc?.reviewedHead && next.reviewedHead !== undefined && next.reviewedHead !== departure.head);
8091
- return this.commitSpecCarry(by, specCarry, task.id, by, "lifecycle", { sdlc: next }, undefined, { ...this.planObservation({ ...task, sdlc: next }), ...(invalidatesDeparture ? { planDepartureInvalidated: true } : {}), ...(deliverables ? { deliverables } : {}) });
8120
+ const recorded = this.commitSpecCarry(by, specCarry, task.id, by, "lifecycle", { sdlc: next }, undefined, { ...this.planObservation({ ...task, sdlc: next }), ...(invalidatesDeparture ? { planDepartureInvalidated: true } : {}), ...(deliverables ? { deliverables } : {}) });
8121
+ this.watchCi(recorded);
8122
+ return recorded;
8092
8123
  }
8093
8124
 
8094
8125
  /** The board as the merge queue and the guarded merge read it (#786): ids, dependencies, privacy, receipts, findings and plans. */
@@ -10180,7 +10211,8 @@ export class Tasks {
10180
10211
  this.warmRepository({ ...task, refs: { ...task.refs, ...checkedRefs } });
10181
10212
  this.assertSpecInspection(specInspection, { ...task, refs: storedRefs }, by);
10182
10213
  const pending = write(task.id, by, "done (checking)", { ...(refresh ? { state: "in_progress" as const } : {}), ...(refresh?.state === "approved" && !task.reviewer ? { reviewer: USER } : {}), codeSymbols: this.observedCodeSymbols({ ...task, refs: storedRefs }), refs: checkedRefs, ...(task.sdlc ? { sdlc: task.sdlc } : {}) }, summary, { withheld: withheld || undefined, ...(records ? { deliverables: records } : {}), ...(specInspection.report ? { specReport: specInspection.report, specRefBinding: this.specRefBinding({ refs: storedRefs }) } : {}) }, task.history.length, HOST_CODE_SYMBOLS);
10183
- if (refresh) { this.ciWatchers.cancel(pending.id); this.heldReviews.delete(pending.id); }
10214
+ if (refresh) this.heldReviews.delete(pending.id);
10215
+ this.watchCi(pending);
10184
10216
  this.releaseNotice(`task ${this.publicTitle(pending)} done by ${by}; its check is queued or running: ${command}`);
10185
10217
  const seen = { events: pending.history.length, owner: pending.owner };
10186
10218
  this.pendingChecks++;
@@ -10397,7 +10429,8 @@ export class Tasks {
10397
10429
  const next = this.d.board.update(task.id, by, "done", { codeSymbols: this.observedCodeSymbols({ ...task, refs: storedRefs }), state: reviewer ? "in_review" : "approved", ...(selection || refresh?.state === "approved" ? { reviewer: quotaWaiting ? null : reviewer ?? USER } : {}), ...(task.sdlc ? { sdlc: { ...withoutRisk(task.sdlc), stage: lifecycleStage(this.d.sdlc?.config() ?? sdlcConfig(undefined), reviewer ? "review" : "merge"), ...(risk ? { risk } : {}) } } : {}), refs: completedRefs }, checkOutput ? `${routedSummary ?? ""}\n${checkOutput}`.trim() : routedSummary, { ...(resolvedReviewComments?.length ? { resolvedReviewComments: this.reviewCommentResolve(by, task, resolvedReviewComments) } : {}), ...this.planObservation(task), withheld: withheld || undefined, ...(specInspection?.report ? { specReport: specInspection.report, specRefBinding: this.specRefBinding({ refs: storedRefs }) } : {}), ...(noWrites ? { noWrites: true as const } : {}), ...this.reviewMetadata(selection, { ...task, state: "in_review", refs: storedRefs }), ...(reviewCost ? { reviewCost } : {}), ...(requestHead ? { requestHead } : {}), ...(records ? { deliverables: records } : {}) }, task.history.length, HOST_CODE_SYMBOLS);
10398
10430
  this.queueReviewWritten(next);
10399
10431
  this.writePlannerNotices(next, capacity, next.state === "approved");
10400
- this.ciWatchers.cancel(next.id); this.heldReviews.delete(next.id); // a newer head or a move ends the old head's watcher (#785 P1b)
10432
+ this.heldReviews.delete(next.id);
10433
+ this.watchCi(next, !!reviewer && admission?.ready === true && admission.head === this.reviewHead(next));
10401
10434
  this.cohorts.closed(next.id); // its owner's next native turn end settles it in its cohort (issue #107)
10402
10435
  const memorySymbols = this.completionMemorySymbols(next);
10403
10436
  this.note(next, by, "finding", `Task #${next.id} done by ${by}: ${next.title}\nChanged-symbol memory anchors: ${memorySymbols.state === "known" ? memorySymbols.nodes.length : "unknown (no complete code facts)"}\n${summary ?? ""}`, withheld || reviewObserverExcluded, memorySymbols);
@@ -10411,7 +10444,6 @@ export class Tasks {
10411
10444
  else if (quotaWaiting) this.releaseNotice(`task ${this.publicTitle(next)}: waiting for reviewer quota reset`);
10412
10445
  else if (reviewer === USER) this.releaseNotice(`task ${this.publicTitle(next)} done by ${by}: review it in the ahub console (Tasks, select #${next.id}, press r) or with ahub review ${next.id} approved|changes_requested [note]`);
10413
10446
  else this.releaseNotice(`task ${this.publicTitle(next)}: could not send the review request to ${reviewer}`, () => this.sendReview(next, reviewer, "", admission));
10414
- if (reviewer && !quotaWaiting && !(admission?.ready && admission.head === this.reviewHead(next))) this.watchCi(next);
10415
10447
  return next;
10416
10448
  }
10417
10449
 
@@ -10721,39 +10753,107 @@ export class Tasks {
10721
10753
  } catch { /* optional bookkeeping never fails a review path */ }
10722
10754
  }
10723
10755
 
10724
- /** #785 P1b AC3: start the one watcher for this task's exact head. Not for private work, an unlinked PR or a lifecycle that is off; never throws. */
10725
- private watchCi(task: Task): void {
10756
+ private ciWatchTarget(task: Task): Omit<CiWatch, "deadlineAt"> | undefined {
10757
+ if (!this.d.sdlc || this.d.sdlc.config().mode === "off" || this.isPii(task)
10758
+ || !["in_progress", "in_review", "approved", "changes_requested"].includes(task.state) || task.sdlc?.mergeReadback?.state === "merged") return;
10759
+ const repo = task.sdlc?.repo, pr = task.sdlc?.pr, submitted = this.reviewHead(task);
10760
+ const recorded = task.history.findLast(entry => entry.event === "lifecycle" || entry.event === "done" || entry.event === "done (checking)");
10761
+ const ownerPhase = task.state === "in_progress" || task.state === "changes_requested";
10762
+ const useLocalHead = ownerPhase && recorded?.event !== "done (checking)" || recorded?.event === "lifecycle";
10763
+ const local = useLocalHead ? task.sdlc?.localHead : undefined;
10764
+ const head = local ?? submitted;
10765
+ if (!repo || !pr || !head || !/^[0-9a-f]{40}$/.test(head)) return;
10766
+ const phase = ownerPhase || head !== submitted ? "draft" : task.state === "approved" ? "approved" : "review";
10767
+ return { id: task.id, head, repo, pr, phase };
10768
+ }
10769
+
10770
+ private watchCi(task: Task, alreadyPassed = false): void {
10726
10771
  try {
10727
- const head = this.reviewHead(task), repo = task.sdlc?.repo, pr = task.sdlc?.pr;
10728
- if (!this.d.sdlc || this.d.sdlc.config().mode === "off" || this.isPii(task) || task.state !== "in_review" || !head || !/^[0-9a-f]{40}$/.test(head) || !repo || !pr) return;
10729
- this.ciWatchers.start({ id: task.id, head, repo, pr });
10730
- } catch { /* a watcher that cannot start leaves the review path as it was */ }
10772
+ const target = this.ciWatchTarget(task);
10773
+ if (target) this.ciWatchers.start(target, alreadyPassed);
10774
+ else this.ciWatchers.cancel(task.id);
10775
+ } catch { /* Optional bookkeeping never fails a task transition. */ }
10731
10776
  }
10732
10777
 
10733
- /** The watcher's own check before every read and every notice: the task must still be in review at this exact head and PR. */
10734
10778
  private ciWatchCurrent(watch: CiWatch): boolean {
10779
+ const task = this.d.board.get(watch.id), target = task && this.ciWatchTarget(task);
10780
+ return !!target && target.head === watch.head && target.repo === watch.repo && target.pr === watch.pr && target.phase === watch.phase;
10781
+ }
10782
+
10783
+ private async retryCiShard(watch: CiWatch, retry: CiShardRetry, completed: boolean, mergeable: boolean): Promise<CiRetryDecision> {
10735
10784
  const task = this.d.board.get(watch.id);
10736
- return !!task && task.state === "in_review" && !this.isPii(task) && this.reviewHead(task) === watch.head && task.sdlc?.repo === watch.repo && task.sdlc?.pr === watch.pr
10737
- && (this.d.sdlc?.config().mode ?? "off") !== "off";
10785
+ const limit = this.d.sdlc?.config().ciShardRetries ?? 0;
10786
+ if (!task || watch.phase === "draft" || !this.ciWatchCurrent(watch)
10787
+ || this.d.repository?.toLowerCase() !== watch.repo.toLowerCase() || !this.publicMetadataText(retry.job)) return "ineligible";
10788
+ const scope = `${watch.repo.toLowerCase()} PR #${watch.pr} head ${watch.head} job `;
10789
+ const key = `${scope}${retry.job} run `;
10790
+ const attemptKey = `${key}${retry.run} attempt ${retry.attempt}`;
10791
+ const attempts = task.history.flatMap(entry => {
10792
+ const note = entry.note;
10793
+ if (entry.by !== HUB || entry.event !== "ci shard rerun" || !note?.startsWith(scope)) return [];
10794
+ if (retry.aggregateOnly) {
10795
+ if (!note.includes(` run ${retry.run} attempt `) || !note.includes(`; aggregate ${retry.job};`)) return [];
10796
+ } else if (!note.startsWith(key)) return [];
10797
+ return [note];
10798
+ });
10799
+ const last = attempts.at(-1);
10800
+ if (last) {
10801
+ const stamp = retry.aggregateOnly ? /; aggregateStartedAt (\d+);/ : /; startedAt (\d+);/;
10802
+ const previous = Number(stamp.exec(last)?.[1]);
10803
+ if (!Number.isSafeInteger(previous) || retry.startedAt === undefined || retry.startedAt <= previous) {
10804
+ const reservation = last.split(";")[0];
10805
+ return task.history.some(entry => entry.by === HUB && entry.event === "ci shard rerun unconfirmed" && entry.note === reservation)
10806
+ ? "stale-unconfirmed" : "stale";
10807
+ }
10808
+ }
10809
+ if (!limit || !mergeable || attempts.length >= limit || retry.aggregateOnly || attempts.some(note => note.startsWith(`${attemptKey};`))) return last ? "final" : "ineligible";
10810
+ if (retry.startedAt === undefined) return "ineligible";
10811
+ if (!completed) return "waiting";
10812
+ const number = attempts.length + 1;
10813
+ const aggregateEvidence = retry.aggregateStartedAt === undefined ? "" : ` aggregateStartedAt ${retry.aggregateStartedAt};`;
10814
+ const evidence = `startedAt ${retry.startedAt}; aggregate ${retry.aggregate};${aggregateEvidence}`;
10815
+ // Save the check's own start before dispatch. GitHub stamps copied check rows with the current run attempt.
10816
+ this.d.board.update(task.id, HUB, "ci shard rerun", {}, `${attemptKey}; ${evidence} retry ${number} of ${limit}`, undefined, task.history.length);
10817
+ if (!this.ciWatchCurrent(watch)) return "reserved";
10818
+ let confirmed = false;
10819
+ try {
10820
+ const response = await (this.d.sdlc?.gh ?? sdlcGh)(["run", "rerun", String(retry.run), "--failed", "--repo", watch.repo], 10_000);
10821
+ confirmed = response.code === 0;
10822
+ } catch { /* The reserved attempt stays counted when dispatch cannot be confirmed. */ }
10823
+ if (!this.ciWatchCurrent(watch)) return "reserved";
10824
+ if (!confirmed) this.d.board.update(task.id, HUB, "ci shard rerun unconfirmed", {}, attemptKey);
10825
+ const outcome = confirmed ? "requested" : "unconfirmed";
10826
+ this.tellCi(watch, [task.owner, conductorPeer(this.d.roles) ?? USER], `ci_rerun: #${task.id} head ${watch.head} PR #${watch.pr} ${retry.job} retry ${number} of ${limit} ${outcome}`);
10827
+ return confirmed ? "confirmed" : "unconfirmed";
10828
+ }
10829
+
10830
+ private tellCi(watch: CiWatch, recipients: readonly (PeerId | null | undefined)[], line: string): void {
10831
+ for (const peer of new Set(recipients)) {
10832
+ if (!peer || peer === HUB) continue;
10833
+ if (peer === USER) { this.releaseNotice(line); continue; }
10834
+ this.releaseNotice(`task #${watch.id}: could not tell ${peer} the CI result`, () => this.d.bus.publish(newEnvelope(HUB, sanitize(`${line}\nRead hub_task_show for the task before acting.`), { to: [peer], kind: "task", priority: "status", refs: { task: String(watch.id), commit: watch.head } })));
10835
+ }
10738
10836
  }
10739
10837
 
10740
- /**
10741
- * #785 P1b: the result of the exact head's CI, told once to the owner and the reviewer (one ids-only task envelope each, `status` weight: `fyi` is recorded but never delivered to the peer),
10742
- * then a review held as premature is offered once more after a fresh readiness read. A deadline tells the console only.
10743
- */
10744
- private async ciCompleted(watch: CiWatch, outcome: CiOutcome): Promise<void> {
10838
+ /** #1801: report exact-head metadata only, with one set of recipients per phase. */
10839
+ private async ciCompleted(watch: CiWatch, outcome: CiOutcome, snapshot?: CiSnapshot): Promise<void> {
10745
10840
  const task = this.d.board.get(watch.id);
10746
10841
  if (!task || !this.ciWatchCurrent(watch)) return;
10747
10842
  const label = `#${task.id} head ${watch.head.slice(0, 12)}`;
10748
10843
  if (outcome === "deadline") { this.releaseNotice(`task ${label}: CI did not finish within the watch deadline; no further reads`); return; }
10749
- const line = `ci_completed: ${label} ${outcome}`;
10750
- for (const peer of new Set([task.owner, task.reviewer])) {
10751
- if (!peer || peer === HUB) continue;
10752
- if (peer === USER) { this.releaseNotice(`task ${label}: CI ${outcome} at its exact head`); continue; }
10753
- this.releaseNotice(`task ${label}: could not tell ${peer} the CI result`, () => this.d.bus.publish(newEnvelope(HUB, `${line}\nRead hub_task_show for the task before acting.`, { to: [peer], kind: "task", priority: "status", refs: { task: String(task.id), commit: watch.head } })));
10754
- }
10755
- if (outcome === "failed") return;
10756
- await this.reofferHeldReview(task, watch);
10844
+ const conductor = conductorPeer(this.d.roles) ?? USER;
10845
+ const headNotice = outcome === "conflicting" || outcome === "missing-run"
10846
+ || outcome === "failed" && snapshot?.retryWorkflowFailure === true;
10847
+ const recipients = headNotice ? [task.owner, conductor]
10848
+ : watch.phase === "approved" ? [task.reviewer, conductor] : watch.phase === "draft" ? [task.owner] : [task.owner, task.reviewer];
10849
+ const safeChecks = snapshot?.failedChecks?.filter(name => /^[a-z0-9 _().:/-]+$/i.test(name) && this.publicMetadataText(name));
10850
+ const details = outcome === "conflicting" ? `PR #${watch.pr} conflicts with main; GitHub runs no CI on it; rebase onto main and push once.`
10851
+ : outcome === "missing-run" ? `PR #${watch.pr} has no observed CI run for this head; check Actions and trigger CI for the current head.`
10852
+ : watch.phase === "approved" && outcome === "passed" ? `PR #${watch.pr} is merge ready; required checks passed and no review thread is unresolved.`
10853
+ : outcome === "failed" ? `PR #${watch.pr} failed ${safeChecks?.length ? safeChecks.join(", ") : "a required check"}.` : "";
10854
+ const line = `ci_completed: ${label} ${outcome}${details ? `\n${details}` : ""}`;
10855
+ this.tellCi(watch, recipients, line);
10856
+ if (watch.phase === "review" && (outcome === "passed" || outcome === "incomplete")) await this.reofferHeldReview(task, watch);
10757
10857
  }
10758
10858
 
10759
10859
  /** The held review of this exact head and request, once: only while it is still the same reviewer, head and revision, and a fresh admission says it is ready. */
@@ -11199,8 +11299,9 @@ export class Tasks {
11199
11299
  ? { ...saved, reopenedWithoutReason } : saved;
11200
11300
  if (verdict === "approved") {
11201
11301
  const capacity = this.capacityBefore(task);
11202
- this.ciWatchers.cancel(task.id); this.heldReviews.delete(task.id);
11302
+ this.heldReviews.delete(task.id);
11203
11303
  const next = this.d.board.update(task.id, by, "approved", { state: "approved", rejections: 0, ...(reviewedHead && task.sdlc ? { sdlc: { ...task.sdlc, reviewedHead, stage: lifecycleStage(this.d.sdlc?.config() ?? sdlcConfig(undefined), "merge") } } : {}) }, note, flag);
11304
+ this.watchCi(next);
11204
11305
  notifyAcceptedReopens();
11205
11306
  this.recordConsideredAfter(next, parsed.filter(finding => finding.disposition === "false_positive"), "review", findingHead ?? reviewedHead);
11206
11307
  this.writePlannerNotices(next, capacity, next.state === "approved");
@@ -11224,8 +11325,9 @@ export class Tasks {
11224
11325
  this.releaseNotice(`task #${next.id}: review saved but recurring-criterion proposal unavailable`, () => { this.proposeCriterionCandidates(next, by, withheld); this.proposeRemovalCandidates(by, withheld); });
11225
11326
  return result(next);
11226
11327
  }
11227
- this.ciWatchers.cancel(task.id); this.heldReviews.delete(task.id);
11328
+ this.heldReviews.delete(task.id);
11228
11329
  const rejected = this.d.board.update(task.id, by, "changes_requested", { state: "changes_requested", rejections: evidenceOnly ? task.rejections : task.rejections + 1 }, note, flag, task.history.length);
11330
+ this.watchCi(rejected);
11229
11331
  notifyAcceptedReopens();
11230
11332
  this.recordConsideredAfter(rejected, parsed.filter(finding => finding.disposition === "false_positive"), "review", findingHead ?? reviewedHead);
11231
11333
  void this.mirrorVerdict(rejected, by, "changes_requested", reviewedHead ?? rejected.sdlc?.reviewedHead, note, withheld || observerExcluded);
package/src/ui/plugin.ts CHANGED
@@ -590,7 +590,7 @@ export function createProvider(options: { visualPolicy?: (cwd: string) => Promis
590
590
  const before = await metadata() as { id: string; task?: number; from: string; created: number; file: VisualFile } | null;
591
591
  if (!before || before.file?.asset !== asset || before.id !== asset.split(":")[0]) return null;
592
592
  const policy = options.visualPolicy ?? (async (cwd: string): Promise<DeliverablePorts> => {
593
- const { loadConfig } = await import("../hub/daemon.ts");
593
+ const { loadConfig } = await import("../hub/config.ts");
594
594
  const config = loadConfig(cwd); return { cwd, deny: config.local.deny, private: file => matchesPolicy(cwd, file, config.pii?.paths ?? [], true) };
595
595
  });
596
596
  const initialPolicy = await policy(project.root);