@staix/agent-hub 0.52.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +4 -3
- package/docs/addons/open-code-review.md +3 -6
- package/docs/agent-notes/README.md +1 -1
- package/docs/agent-notes/adapters.md +5 -4
- package/docs/agent-notes/budget.md +2 -2
- package/docs/agent-notes/bus.md +1 -0
- package/docs/agent-notes/daemon.md +6 -5
- package/docs/agent-notes/models.md +1 -1
- package/docs/agent-notes/tasks.md +3 -3
- package/docs/agent-notes/tests.md +4 -4
- package/docs/contracts/companion-cli-v2.json +90 -0
- package/docs/contracts/companion-cli-v3.json +348 -0
- package/docs/design/adapters.md +1 -1
- package/docs/design/agent-hub-architecture.md +8 -5
- package/docs/design/bus.md +1 -1
- package/docs/design/cli-output-inventory.md +4 -2
- package/docs/design/execution-reference.md +1 -1
- package/docs/design/guidance-experiments.md +1 -0
- package/docs/design/guidance-probes.md +1 -0
- package/docs/design/model-routes.md +20 -5
- package/docs/design/roadmap.md +6 -4
- package/docs/design/task-board.md +21 -2
- package/docs/dogfood.md +13 -6
- package/docs/events.md +1 -1
- package/docs/memory.md +2 -2
- package/docs/operations.md +158 -50
- package/docs/quickstart.md +14 -2
- package/docs/security.md +17 -9
- package/docs/specs/2026-09-19-agent-hub-design.md +5 -3
- package/docs/specs/2026-09-19-multi-project-design.md +1 -1
- package/docs/specs/2026-09-20-upgrade-recovery-design.md +24 -0
- package/docs/specs/2026-12-04-arev-adoption-design.md +84 -0
- package/docs/specs/mcp-endpoint.md +15 -4
- package/docs/specs/relay-contract.md +38 -0
- package/docs/verification/2026-12-04-host-shared-receipts.md +43 -0
- package/docs/verification/2026-12-05-0.53.0.md +101 -0
- package/docs/verification/2026-12-05-agy-1.5.24.md +55 -0
- package/docs/verification/2026-12-05-claude-implementer-2.1.337.md +43 -0
- package/docs/verification/2026-12-06-0.54.0.md +76 -0
- package/docs/verification/2026-12-06-codex-0174-reviewer-isolation.md +43 -0
- package/docs/verification/2026-12-06-codex-0174-reviewer-tool-call.md +34 -0
- package/docs/verification/2026-12-06-compat-codex-capabilities-0.174.0.md +25 -0
- package/docs/verification/2026-12-06-compat-pi-1.8.0.md +23 -0
- package/docs/verified.json +38 -29
- package/package.json +9 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/.mcp.json +1 -1
- package/plugins/agent-hub/compat.json +9 -5
- package/plugins/agent-hub/kimi-hook.js +892 -874
- package/plugins/agent-hub/relay-launcher.js +24 -0
- package/plugins/agent-hub/server.js +27271 -25146
- package/src/adapters/acp-session-model.ts +1 -1
- package/src/adapters/acp.ts +5 -4
- package/src/adapters/agy/definition.ts +1 -1
- package/src/adapters/agy/hooks.ts +1 -1
- package/src/adapters/channel-peer.ts +3 -1
- package/src/adapters/claude-channel-evidence.ts +26 -1
- package/src/adapters/claude-channel.ts +27 -30
- package/src/adapters/claude-connection-policy.ts +62 -0
- package/src/adapters/claude-relay.ts +255 -0
- package/src/adapters/codex-review-isolation.ts +1 -2
- package/src/adapters/compat.ts +28 -18
- package/src/adapters/definitions/native-cli-preview-pi.ts +2 -1
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/definitions/native-context.ts +1 -2
- package/src/adapters/definitions/native-factories.ts +4 -1
- package/src/adapters/definitions/native-quota.ts +1 -1
- package/src/adapters/definitions/native-recovery.ts +3 -1
- package/src/adapters/external-modules.ts +2 -2
- package/src/adapters/kimi-review.ts +1 -1
- package/src/adapters/kimi-tui-facts.ts +1 -1
- package/src/adapters/local-worker.ts +3 -3
- package/src/adapters/native-capabilities.ts +1 -1
- package/src/adapters/pi.ts +26 -7
- package/src/adapters/registry-types.ts +2 -0
- package/src/adapters/relay-launcher.ts +27 -0
- package/src/adapters/reviewer-mcp.ts +1 -1
- package/src/cli/agents.ts +20 -8
- package/src/cli/agy-mcp.ts +1 -1
- package/src/cli/claude-profile-hook.ts +1 -1
- package/src/cli/command-table.ts +1 -0
- package/src/cli/commands/agents.ts +18 -1
- package/src/cli/commands/doctor.ts +18 -4
- package/src/cli/commands/launch-line.ts +32 -0
- package/src/cli/commands/status.ts +14 -3
- package/src/cli/help.ts +7 -4
- package/src/cli/identity.ts +1 -1
- package/src/cli/init-roles.ts +1 -1
- package/src/cli/init-settings.ts +1 -1
- package/src/cli/launch-line-plan.ts +82 -0
- package/src/cli/launch-line-project.ts +13 -0
- package/src/cli/main.ts +10 -9
- package/src/cli/pi-steps-warning.ts +14 -0
- package/src/cli/recovery-package.ts +60 -6
- package/src/cli/reset.ts +1 -1
- package/src/cli/shell-quote.ts +1 -3
- package/src/cli/upgrade-interactive.ts +7 -2
- package/src/cli/upgrade-keep-plan.ts +47 -0
- package/src/cli/upgrade-restore-state.ts +1 -1
- package/src/cli/upgrade-runtime.ts +119 -18
- package/src/cli/upgrade.ts +17 -2
- package/src/hub/accounts.ts +8 -4
- package/src/hub/action-class.ts +1 -3
- package/src/hub/adec-triage.ts +105 -0
- package/src/hub/autonomy.ts +1 -1
- package/src/hub/board.ts +3 -27
- package/src/hub/bus.ts +39 -6
- package/src/hub/capabilities.ts +1 -1
- package/src/hub/channel-project-base.ts +46 -0
- package/src/hub/channel-project.ts +21 -46
- package/src/hub/config-apply.ts +1 -1
- package/src/hub/config-edit.ts +1 -1
- package/src/hub/config-tier.ts +1 -1
- package/src/hub/config.ts +2 -2
- package/src/hub/confirmation-matrix.ts +1 -1
- package/src/hub/control/board-messages.ts +415 -0
- package/src/hub/control/dashboard-messages.ts +221 -0
- package/src/hub/control/delivery-messages.ts +356 -0
- package/src/hub/control/dispatch.ts +114 -0
- package/src/hub/control/hub-tool-helpers.ts +243 -0
- package/src/hub/control/hub-tools.ts +147 -0
- package/src/hub/control/native-messages.ts +665 -0
- package/src/hub/control/operations-messages.ts +269 -0
- package/src/hub/control/peer-messages.ts +126 -0
- package/src/hub/control/recovery-messages.ts +391 -0
- package/src/hub/control/recovery-operation.ts +480 -0
- package/src/hub/control/scope.ts +460 -0
- package/src/hub/control/sdlc-messages.ts +373 -0
- package/src/hub/control/task-ops-more.ts +245 -0
- package/src/hub/control/task-ops.ts +553 -0
- package/src/hub/control/ui-actions.ts +241 -0
- package/src/hub/control-write-trace.ts +1 -4
- package/src/hub/daemon.ts +485 -4324
- package/src/hub/delivery-hints.ts +2 -0
- package/src/hub/delivery-journal.ts +17 -6
- package/src/hub/events.ts +2 -1
- package/src/hub/execution-reference.ts +1 -1
- package/src/hub/host.ts +41 -9
- package/src/hub/hub-tools.ts +3 -4
- package/src/hub/invocations.ts +1 -1
- package/src/hub/lifecycle.ts +4 -3
- package/src/hub/mcp-endpoint-serve.ts +4 -3
- package/src/hub/mcp-endpoint.ts +15 -6
- package/src/hub/memory-profile-check.ts +1 -1
- package/src/hub/no-writes.ts +1 -1
- package/src/hub/peers.ts +2 -0
- package/src/hub/pi-exit-policy.ts +27 -0
- package/src/hub/progress.ts +1 -1
- package/src/hub/project-runtime-state.ts +17 -4
- package/src/hub/project-runtime.ts +3 -1
- package/src/hub/protocol-window.ts +1 -1
- package/src/hub/recovery-continuity.ts +3 -3
- package/src/hub/recovery-kept-roster.ts +50 -0
- package/src/hub/review-anchor.ts +13 -181
- package/src/hub/review-brief.ts +78 -28
- package/src/hub/review-findings.ts +15 -193
- package/src/hub/review-ledger.ts +162 -0
- package/src/hub/review-material.ts +3 -3
- package/src/hub/reviewer-pool.ts +4 -2
- package/src/hub/roadmap-issue-states.ts +65 -14
- package/src/hub/roadmap-sync.ts +39 -14
- package/src/hub/routing.ts +9 -0
- package/src/hub/runtime-capture-prune.ts +8 -2
- package/src/hub/runtime-package-assets.ts +3 -0
- package/src/hub/sdlc-release-policy.ts +1 -2
- package/src/hub/settings.ts +1 -1
- package/src/hub/spec-ack-tool.ts +4 -0
- package/src/hub/spec-report-history.ts +36 -0
- package/src/hub/specs.ts +1 -4
- package/src/hub/supervision.ts +33 -6
- package/src/hub/tasks-audit.ts +390 -0
- package/src/hub/tasks-backlog.ts +522 -0
- package/src/hub/tasks-handoff.ts +208 -0
- package/src/hub/tasks-release.ts +257 -0
- package/src/hub/tasks-roadmap.ts +17 -3
- package/src/hub/tasks-specs.ts +672 -0
- package/src/hub/tasks-types.ts +334 -0
- package/src/hub/tasks.ts +286 -1961
- package/src/hub/upgrade-session-contract.ts +11 -0
- package/src/local/probe-sandbox.ts +1 -2
- package/src/local/probe-workspace.ts +1 -1
- package/src/models/route/config.ts +4 -4
- package/src/models/route/decision.ts +18 -10
- package/src/models/route/observation-signals.ts +1 -2
- package/src/models/route/runtime.ts +8 -5
- package/src/npm-artifact.ts +76 -0
- package/src/omniroute/client.ts +6 -0
- package/src/pi/extension.ts +5 -2
- package/src/pi/install.ts +77 -0
- package/src/pi/pin.ts +49 -0
- package/src/primitives.ts +14 -0
- package/src/version.ts +2 -0
- package/templates/adec/README.md +10 -6
- package/templates/config.json +1 -1
- package/templates/specs.block.md +1 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// #1830 S4e-3: the cross-project handoff methods. Tasks owns the board writes and supplies the host operations.
|
|
2
|
+
import { taskHasStarted, taskHasWorkEvidence, type Board, type Task, type TaskPlan, type TaskRefs } from "./board.ts";
|
|
3
|
+
import { HUB, newEnvelope, sanitize, USER, type PeerId } from "./envelope.ts";
|
|
4
|
+
import { HANDOFF_EVENTS, HANDOFF_KEY, HandoffRefusal, duplicateIssueTasks, duplicateRefusalText, followBackLine, handoffEventFor, handoffRequestDigest, parseHandoff, type HandoffEvent } from "./handoff.ts";
|
|
5
|
+
import type { PiiVerdict } from "./inference.ts";
|
|
6
|
+
import type { detectSignals } from "./routing.ts";
|
|
7
|
+
import type { TasksDeps } from "./tasks-types.ts";
|
|
8
|
+
|
|
9
|
+
interface HandoffHost {
|
|
10
|
+
assignOwner: (task: Task, by: PeerId, opts: Record<string, never>) => Promise<Task>;
|
|
11
|
+
configuredManualConductor: (by: PeerId) => boolean;
|
|
12
|
+
readonly isPii: (task: Pick<Task, "signals">) => boolean;
|
|
13
|
+
linkOnWrite: (task: Task) => Task;
|
|
14
|
+
publicTitle: (task: Task) => string;
|
|
15
|
+
requireLocalTaskPeer: (peer: unknown) => void;
|
|
16
|
+
/** Board writes stay behind Tasks: the proposal with its origin row, and the outbound row. */
|
|
17
|
+
saveHandoffOutbound: Board["recordHandoffOutbound"];
|
|
18
|
+
saveHandoffProposal: Board["proposeHandoff"];
|
|
19
|
+
screenCall: (text: string) => Promise<PiiVerdict>;
|
|
20
|
+
readonly screenOn: () => boolean;
|
|
21
|
+
screenText: (task: { title: string; detail: string; plan?: TaskPlan; external?: Task["external"] }) => string;
|
|
22
|
+
signalsFor: (task: Pick<Task, "title" | "detail" | "refs"> & { plan?: TaskPlan }) => ReturnType<typeof detectSignals>;
|
|
23
|
+
/** The saved task of an assignment whose delivery failed after its write; undefined for any other error. */
|
|
24
|
+
undelivered: (error: unknown) => Task | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class HandoffDomain {
|
|
28
|
+
constructor(private readonly d: TasksDeps, private readonly host: HandoffHost) {}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* #604 (agent-hub#1030), ORIGIN side. Who may hand work to another project: the person, or a configured planner, or the conductor. The host (the daemon) has already resolved and
|
|
32
|
+
* checked the target; this is the authority and privacy gate before anything leaves this project, so a refusal here leaves no row in either board.
|
|
33
|
+
*/
|
|
34
|
+
handoffOutAuthority(by: PeerId, piiTask?: Task): void {
|
|
35
|
+
this.host.requireLocalTaskPeer(by);
|
|
36
|
+
if (by !== USER && this.d.privateTurn?.(by)) throw new HandoffRefusal("pii_turn", "a handoff is unavailable during a private turn: nothing from it may leave this project");
|
|
37
|
+
if (piiTask && this.host.isPii(piiTask)) throw new HandoffRefusal("pii_task", "a [pii] task is not handed off: nothing about it leaves this project");
|
|
38
|
+
if (by !== USER && !this.d.roles?.[by]?.includes("planner") && this.d.operational?.(by) !== true) throw new HandoffRefusal("no_authority", "a handoff needs the person, a configured planner or the conductor");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* #734 (AC6): who may ask the origin to catch up now (`ahub task handoff --sync`). The person, or the conductor acting on the person's instruction: the same bar as `handoffOutAuthority`
|
|
43
|
+
* without the planner role, because a sync starts no work and files nothing, but it does ask other projects' hubs, which a planner agent has no need to trigger.
|
|
44
|
+
*/
|
|
45
|
+
handoffSyncAuthority(by: PeerId): void {
|
|
46
|
+
this.host.requireLocalTaskPeer(by);
|
|
47
|
+
if (by !== USER && this.d.operational?.(by) !== true) throw new HandoffRefusal("no_authority", "a handoff sync is the person's or the conductor's: ask them to run `ahub task handoff --sync`");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** ORIGIN side: remember what was handed over, once the target answered with its task id. */
|
|
51
|
+
handoffSent(by: PeerId, target: { projectId: string }, remoteTask: number, title: string, localTask?: number): void {
|
|
52
|
+
// #731: a row that already exists is never reset to "proposed": a replayed answer can arrive after the target's own event for the same task was recorded.
|
|
53
|
+
if (this.d.board.handoffOutboundFor(target.projectId, remoteTask)) return;
|
|
54
|
+
this.host.saveHandoffOutbound({ remoteProject: target.projectId, remoteTask, originPeer: by, ...(localTask === undefined ? {} : { localTask }), title: title.slice(0, 300), state: "proposed" });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* TARGET side. The origin peer gets no identity or authority here: the task is an ownerless proposal made by the hub on the origin's behalf, with the origin recorded in its own table.
|
|
59
|
+
* The request was parsed closed by the origin and is parsed again here, because a control message is data from another process: the body is bounded, control characters are refused and the
|
|
60
|
+
* text is sanitized before it is stored. A `[pii]` result is refused whole, and nothing is left behind.
|
|
61
|
+
*/
|
|
62
|
+
async handoffIn(origin: { projectId: unknown; peer: unknown; taskId?: unknown }, input: unknown, fence: () => string | undefined = () => undefined): Promise<{ task: number; state: string; note?: string; replayed?: true }> {
|
|
63
|
+
const request = parseHandoff({ ...(input && typeof input === "object" && !Array.isArray(input) ? input as Record<string, unknown> : { invalid: true }), project: "local" });
|
|
64
|
+
if (typeof origin.projectId !== "string" || !origin.projectId || origin.projectId.length > 200 || typeof origin.peer !== "string" || !/^[a-z][a-z0-9-]{0,31}$/.test(origin.peer)
|
|
65
|
+
|| origin.taskId !== undefined && (!Number.isSafeInteger(origin.taskId) || (origin.taskId as number) < 1)) throw new HandoffRefusal("invalid", "handoff origin is malformed");
|
|
66
|
+
if (origin.projectId === this.d.project) throw new HandoffRefusal("same_project", "that is this project: a task for this project goes through hub_task_propose");
|
|
67
|
+
// The fence is asked right before the board write and after every await: a recovery that began while the PII screen was pending must find nothing written (agent-hub#1030, review).
|
|
68
|
+
const held = (): void => { const reason = fence(); if (reason) throw new HandoffRefusal("invalid", reason); };
|
|
69
|
+
held();
|
|
70
|
+
// #731 (agent-hub#1203): a request key this origin already used answers with the task it made, before the duplicate check (which would refuse it as a duplicate of itself) and before any PII screen
|
|
71
|
+
// or write. The same key for a different request is refused, never answered with a task the caller did not ask for.
|
|
72
|
+
const key = request.handoffKey, digest = handoffRequestDigest(request, origin.taskId as number | undefined);
|
|
73
|
+
const replay = (): { task: number; state: string; replayed: true } | undefined => {
|
|
74
|
+
const existing = key === undefined ? undefined : this.d.board.handoffOriginByKey(origin.projectId as string, key);
|
|
75
|
+
const task = existing && this.d.board.get(existing.taskId);
|
|
76
|
+
if (!existing || !task) return undefined;
|
|
77
|
+
if (existing.digest !== null && existing.digest !== digest) throw new HandoffRefusal("invalid", "that handoff key was already used for a different request: hand the task off again with a new key");
|
|
78
|
+
return { task: task.id, state: task.state, replayed: true };
|
|
79
|
+
};
|
|
80
|
+
const early = replay();
|
|
81
|
+
if (early) return early;
|
|
82
|
+
// The spec issue the caller named is kept in the task itself, as its own line: the target's planner reads it from the detail, and `ahub task show` shows it there.
|
|
83
|
+
const issueLine = request.issue === undefined ? "" : `spec issue: #${request.issue} in this repository`;
|
|
84
|
+
const detail = sanitize([request.detail, issueLine, request.duplicate_ok === undefined ? "" : `duplicate acknowledged by the sender: ${request.duplicate_ok}`, `[handed off from project ${origin.projectId} by ${origin.peer}${origin.taskId === undefined ? "" : ` (their task #${origin.taskId})`}]`].filter(Boolean).join("\n\n"));
|
|
85
|
+
const refs: TaskRefs = { ...(request.paths.length ? { paths: request.paths } : {}) };
|
|
86
|
+
const signals = this.host.signalsFor({ title: request.title, detail, refs, plan: {} });
|
|
87
|
+
if (signals.includes("pii")) throw new HandoffRefusal("pii_task", "the handed-off text matches a PII pattern; it is not stored here");
|
|
88
|
+
const screening = this.host.screenOn();
|
|
89
|
+
const screened = screening ? await this.host.screenCall(this.host.screenText({ title: request.title, detail: [detail, ...request.paths].join("\n"), plan: {} })) : undefined;
|
|
90
|
+
held();
|
|
91
|
+
if (screening && (!screened || screened.label !== "clear")) throw new HandoffRefusal("pii_task", "the handed-off text could not be cleared by the PII screen; it is not stored here");
|
|
92
|
+
// The first attempt may have committed while this one waited for the screen (the origin's timeout does not stop it): ask again, with nothing awaited between here and the write below.
|
|
93
|
+
const late = replay();
|
|
94
|
+
if (late) return late;
|
|
95
|
+
// #1175: a spec issue that already has open work here is refused before any row exists, so a duplicate is never offered to an owner or escalated by the sweep. This runs after the last
|
|
96
|
+
// await and writes nothing before it, so the check and the proposal below see one board; a `[pii]` task is left out, so no private task id is named to another project.
|
|
97
|
+
if (request.issue !== undefined && request.duplicate_ok === undefined) {
|
|
98
|
+
const open = duplicateIssueTasks(this.d.board.list().filter(row => !this.host.isPii(row)).map(row => ({ id: row.id, state: row.state, title: row.title, detail: row.detail, refs: row.refs, external: row.external, sdlc: row.sdlc })), request.issue, this.d.repository);
|
|
99
|
+
if (open.length) throw new HandoffRefusal("duplicate", duplicateRefusalText(request.issue, open));
|
|
100
|
+
}
|
|
101
|
+
// #731 (H9): the proposal and its origin row are one board transaction. A request with no key (an older origin) is written the same way, without a key, so it is never left without its origin either.
|
|
102
|
+
const made = this.host.saveHandoffProposal(HUB, { title: request.title, detail, class: request.class, refs, plan: {}, signals },
|
|
103
|
+
{ projectId: origin.projectId, peer: origin.peer, ...(origin.taskId === undefined ? {} : { originTask: origin.taskId as number }), ...(key === undefined ? {} : { key, digest }) });
|
|
104
|
+
if (made.replayed) return { task: made.task.id, state: made.task.state, replayed: true };
|
|
105
|
+
let task = made.task;
|
|
106
|
+
// From here the task and its origin are saved, so nothing below may fail the handoff: the origin must learn the task id, or the target keeps work nobody can track.
|
|
107
|
+
try { task = this.host.linkOnWrite(task); } catch { /* the lifecycle link is advice */ }
|
|
108
|
+
try { this.d.notify(`task ${this.host.publicTitle(task)} handed off from project ${origin.projectId} by ${origin.peer}`); } catch { /* never throw after a board write */ }
|
|
109
|
+
let note: string | undefined;
|
|
110
|
+
try { task = await this.host.assignOwner(task, HUB, {}); }
|
|
111
|
+
catch (error) {
|
|
112
|
+
const undelivered = this.host.undelivered(error);
|
|
113
|
+
if (undelivered) { task = undelivered; note = "the assignment is saved but its delivery is not confirmed yet; this hub retries it"; }
|
|
114
|
+
else note = "the task is saved but was not offered to an owner yet; this hub's routing offers it"; // a routing refusal leaves an ordinary proposal for the planner
|
|
115
|
+
}
|
|
116
|
+
return { task: task.id, state: task.state, ...(note ? { note } : {}) };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** TARGET side: the origin recorded for a task, for `ahub task show` and the board. */
|
|
120
|
+
handoffOriginOf(taskId: number): { projectId: string; peer: string; originTask: number | null } | undefined {
|
|
121
|
+
const origin = this.d.board.handoffOrigin(taskId);
|
|
122
|
+
return origin ? { projectId: origin.projectId, peer: origin.peer, originTask: origin.originTask } : undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* ORIGIN side: the target reported a state change. Records it and tells the origin peer with one `kind: task` envelope. Idempotent: a state already recorded sends nothing.
|
|
127
|
+
* #733: an event may carry `seq`, the target task's flow revision. One that is not newer than the stored sequence changes nothing and sends nothing (an `in_review` that arrives after
|
|
128
|
+
* `approved` cannot reopen the row), decided inside the board write; an event without one (an older target) applies as before.
|
|
129
|
+
*/
|
|
130
|
+
handoffEvent(input: unknown): { recorded: boolean } {
|
|
131
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) throw new HandoffRefusal("invalid", "handoff event must be a data object");
|
|
132
|
+
const e = input as Record<string, unknown>;
|
|
133
|
+
if (typeof e.projectId !== "string" || !e.projectId || e.projectId.length > 200 || !Number.isSafeInteger(e.remoteTask) || (e.remoteTask as number) < 1
|
|
134
|
+
|| typeof e.state !== "string" || !(HANDOFF_EVENTS as readonly string[]).includes(e.state)
|
|
135
|
+
|| e.seq !== undefined && (!Number.isSafeInteger(e.seq) || (e.seq as number) < 1)) throw new HandoffRefusal("invalid", "handoff event is malformed");
|
|
136
|
+
const row = this.d.board.handoffOutboundFor(e.projectId, e.remoteTask as number);
|
|
137
|
+
if (!row) throw new HandoffRefusal("invalid", "no handoff of ours is recorded for that task");
|
|
138
|
+
const seq = e.seq as number | undefined;
|
|
139
|
+
const pr = Number.isSafeInteger(e.pr) && (e.pr as number) > 0 ? e.pr as number : undefined, head = typeof e.head === "string" && /^[0-9a-f]{40}$/.test(e.head) ? e.head : undefined;
|
|
140
|
+
if (seq !== undefined && row.seq !== null && seq <= row.seq) return { recorded: false };
|
|
141
|
+
if (row.state === e.state && (pr === undefined || pr === row.pr) && (head === undefined || head === row.head)) {
|
|
142
|
+
// Nothing to tell the peer, but a newer sequence is still kept, so a later stale event is judged against it.
|
|
143
|
+
if (seq !== undefined && (row.seq === null || seq > row.seq)) this.host.saveHandoffOutbound({ remoteProject: row.remoteProject, remoteTask: row.remoteTask, originPeer: row.originPeer, ...(row.localTask === null ? {} : { localTask: row.localTask }), title: row.title, state: row.state, seq });
|
|
144
|
+
return { recorded: false };
|
|
145
|
+
}
|
|
146
|
+
const written = this.host.saveHandoffOutbound({ remoteProject: row.remoteProject, remoteTask: row.remoteTask, originPeer: row.originPeer, ...(row.localTask === null ? {} : { localTask: row.localTask }), title: row.title, state: e.state, ...(pr === undefined ? {} : { pr }), ...(head === undefined ? {} : { head }), ...(seq === undefined ? {} : { seq }) });
|
|
147
|
+
if (!written.applied) return { recorded: false }; // a newer event won the race between the read above and this write
|
|
148
|
+
const body = followBackLine(row.remoteTask, e.state as HandoffEvent, { pr, head });
|
|
149
|
+
if (row.originPeer !== USER && row.originPeer !== HUB) {
|
|
150
|
+
// #731 (H3): the envelope names the REMOTE task and no local one. `refs.task` made the bus judge it against whatever local task has that number (or the origin's own task it came from), so a
|
|
151
|
+
// cancelled or approved local task of the same number dropped a state change that was about another project's task.
|
|
152
|
+
try { this.d.bus.publish(newEnvelope(HUB, body, { to: [row.originPeer], kind: "task", priority: "important", refs: { handoff: { project: row.remoteProject, task: row.remoteTask } } })); }
|
|
153
|
+
catch { /* never throw after a board write */ }
|
|
154
|
+
}
|
|
155
|
+
return { recorded: true };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* TARGET side, catch-up (#1030 design 4): the origin asks for the current state of the tasks it handed us, by id, after it was down. Answers only for tasks whose recorded origin IS the asking
|
|
160
|
+
* project, and only with the same fields a live event carries (the event name, a PR number, a full head), so an origin learns nothing it could not have been told live.
|
|
161
|
+
*/
|
|
162
|
+
handoffStatesFor(projectId: unknown, taskIds: unknown): { task: number; state: HandoffEvent | "proposed"; pr?: number; head?: string; seq: number }[] {
|
|
163
|
+
if (typeof projectId !== "string" || !projectId || projectId.length > 200 || !Array.isArray(taskIds) || taskIds.length > 200 || !taskIds.every(id => Number.isSafeInteger(id) && id > 0)) throw new HandoffRefusal("invalid", "handoff state request is malformed");
|
|
164
|
+
const out: { task: number; state: HandoffEvent | "proposed"; pr?: number; head?: string; seq: number }[] = [];
|
|
165
|
+
for (const id of taskIds as number[]) {
|
|
166
|
+
const origin = this.d.board.handoffOrigin(id), task = origin?.projectId === projectId ? this.d.board.get(id) : undefined;
|
|
167
|
+
if (!task) continue;
|
|
168
|
+
const entry = task.history.findLast(h => handoffEventFor(h.event, task.state) !== undefined);
|
|
169
|
+
const state = entry ? handoffEventFor(entry.event, task.state) ?? "proposed" : "proposed";
|
|
170
|
+
const pr = typeof task.sdlc?.pr === "number" && Number.isSafeInteger(task.sdlc.pr) && task.sdlc.pr > 0 ? task.sdlc.pr : undefined;
|
|
171
|
+
const rawHead = task.refs.commit ?? task.sdlc?.head ?? task.sdlc?.localHead, head = typeof rawHead === "string" && /^[0-9a-f]{40}$/.test(rawHead) ? rawHead : undefined; // the owner's commit, else the receipt's head; only a full SHA crosses
|
|
172
|
+
// #733: the task's current flow revision (its history length), the same number a live event carries, so a catch-up answer and a late live event are ordered against each other.
|
|
173
|
+
out.push({ task: id, state, ...(pr === undefined ? {} : { pr }), ...(head === undefined ? {} : { head }), seq: Math.max(1, task.history.length) });
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* TARGET side (#731): where the task a handoff key made stands, for an origin whose request got no answer. Answers only the asking project, and only the fields a live event carries; nothing is
|
|
180
|
+
* written. `undefined` means this target holds no task for that key.
|
|
181
|
+
*/
|
|
182
|
+
handoffStateByKey(projectId: unknown, key: unknown): { task: number; state: HandoffEvent | "proposed"; pr?: number; head?: string; seq: number } | undefined {
|
|
183
|
+
if (typeof projectId !== "string" || !projectId || projectId.length > 200 || typeof key !== "string" || !HANDOFF_KEY.test(key)) throw new HandoffRefusal("invalid", "handoff key lookup is malformed");
|
|
184
|
+
const found = this.d.board.handoffOriginByKey(projectId, key);
|
|
185
|
+
return found ? this.handoffStatesFor(projectId, [found.taskId])[0] : undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** ORIGIN side: record what a target answered to the catch-up, and tell the origin peer about a change this project missed while it was down. */
|
|
189
|
+
handoffCaughtUp(projectId: string, rows: { task: number; state: string; pr?: number; head?: string; seq?: number }[]): number {
|
|
190
|
+
let changed = 0;
|
|
191
|
+
for (const row of rows) {
|
|
192
|
+
if (!(HANDOFF_EVENTS as readonly string[]).includes(row.state)) continue;
|
|
193
|
+
try { if (this.handoffEvent({ projectId, remoteTask: row.task, state: row.state, ...(row.pr === undefined ? {} : { pr: row.pr }), ...(row.head === undefined ? {} : { head: row.head }), ...(row.seq === undefined ? {} : { seq: row.seq }) }).recorded) changed++; }
|
|
194
|
+
catch { /* a row we hold no handoff for is not ours */ }
|
|
195
|
+
}
|
|
196
|
+
return changed;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* #1175: the receiving project's configured conductor may cancel a task another project handed it, while nobody has accepted it and it has no execution evidence (the same bar as the
|
|
201
|
+
* planner's own-work rule, `taskHasStarted` and `taskHasWorkEvidence`). It is re-asked inside both validations of `cancel`, so authority that ended during the privacy screen writes
|
|
202
|
+
* nothing. The origin hears the cancel through the existing follow-back, which reads the history entry and carries no text.
|
|
203
|
+
*/
|
|
204
|
+
conductorHandoffCancel(by: PeerId, task: Task): boolean {
|
|
205
|
+
return this.host.configuredManualConductor(by) && this.d.bus.isRostered(by) && this.d.board.handoffOrigin(task.id) !== undefined && ["proposed", "backlog"].includes(task.state)
|
|
206
|
+
&& !taskHasStarted(task) && !taskHasWorkEvidence(task) && !this.host.isPii(task);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// #1830 S4d-1: release planning and readback. Tasks owns the board writes and supplies the host operations.
|
|
2
|
+
import { isClosedTaskState, type Board, type Task } from "./board.ts";
|
|
3
|
+
import { USER, type PeerId } from "./envelope.ts";
|
|
4
|
+
import type { PiiVerdict } from "./inference.ts";
|
|
5
|
+
import { matchesPolicy } from "./path-policy.ts";
|
|
6
|
+
import { actualTaskDates, type Release, type ReleaseState } from "./planning.ts";
|
|
7
|
+
import { RELEASE_TRAIN_HISTORY_LIMIT, readReleaseReadiness, releaseMetrics, releaseTrainData, releaseTrainReadiness } from "./sdlc-release.ts";
|
|
8
|
+
import type { Tasks, TasksDeps } from "./tasks.ts";
|
|
9
|
+
import { PreEffectToolRefusal } from "./tool-refusal.ts";
|
|
10
|
+
|
|
11
|
+
interface ReleaseHost {
|
|
12
|
+
auditLine: Tasks["auditLine"];
|
|
13
|
+
costReport: Tasks["costReport"];
|
|
14
|
+
freezeRelease: Board["freezeRelease"];
|
|
15
|
+
readonly isPii: Tasks["isPii"];
|
|
16
|
+
readonly nameable: Tasks["nameable"];
|
|
17
|
+
newRelease: Board["newRelease"];
|
|
18
|
+
plan: Board["plan"];
|
|
19
|
+
plannerWriteAuthority: (by: PeerId, row?: Pick<Task, "planner">) => void;
|
|
20
|
+
planningAuthority: (by: PeerId, row?: Pick<Task, "planner">) => void;
|
|
21
|
+
planningRecorded: (change: { by: string; task?: number; release?: number; fields: string[]; revision: number }) => void;
|
|
22
|
+
releaseNotice: (line: string) => void;
|
|
23
|
+
screenCall: (text: string) => Promise<PiiVerdict>;
|
|
24
|
+
readonly screenOn: Tasks["screenOn"];
|
|
25
|
+
updateRelease: Board["updateRelease"];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class ReleaseDomain {
|
|
29
|
+
constructor(private readonly d: TasksDeps, private readonly host: ReleaseHost) {}
|
|
30
|
+
|
|
31
|
+
releaseList(by: PeerId): Record<string, unknown>[] {
|
|
32
|
+
this.host.planningAuthority(by);
|
|
33
|
+
const scopes = new Map<number, { id: number; state: Task["state"]; deps: number[] }[]>();
|
|
34
|
+
type Approval = { id: number; release: Task["release"]; doneAt: number | null };
|
|
35
|
+
const approved: Approval[] = [], owned = new Map<number, Approval[]>();
|
|
36
|
+
for (const task of this.d.board.list()) {
|
|
37
|
+
if (typeof task.release === "number") {
|
|
38
|
+
const scope = scopes.get(task.release) ?? [];
|
|
39
|
+
scope.push({ id: task.id, state: task.state, deps: task.deps ?? [] }); scopes.set(task.release, scope);
|
|
40
|
+
}
|
|
41
|
+
if (task.state !== "approved") continue;
|
|
42
|
+
const row = { id: task.id, release: task.release, doneAt: actualTaskDates(task).doneAt };
|
|
43
|
+
approved.push(row);
|
|
44
|
+
if (typeof task.release === "number") { const rows = owned.get(task.release) ?? []; rows.push(row); owned.set(task.release, rows); }
|
|
45
|
+
}
|
|
46
|
+
const compare = (a: Approval, b: Approval) => a.doneAt! - b.doneAt! || a.id - b.id;
|
|
47
|
+
const known = approved.filter(task => task.doneAt !== null).sort(compare), unknown = approved.filter(task => task.doneAt === null);
|
|
48
|
+
const after = (rows: Approval[], cut: number) => {
|
|
49
|
+
let low = 0, high = rows.length;
|
|
50
|
+
while (low < high) { const mid = Math.floor((low + high) / 2); if (rows[mid]!.doneAt! <= cut) low = mid + 1; else high = mid; }
|
|
51
|
+
return low;
|
|
52
|
+
};
|
|
53
|
+
// ponytail: audit previews show 32 ids plus exact counts; add a paginated audit endpoint for exhaustive lists.
|
|
54
|
+
const outsideIds = (rows: Approval[], start: number, release: number) => {
|
|
55
|
+
const result: number[] = [];
|
|
56
|
+
for (let i = start; i < rows.length && result.length < 32; i++) if (rows[i]!.release !== release) result.push(rows[i]!.id);
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
return this.d.board.releases().map(release => {
|
|
60
|
+
const own = owned.get(release.id) ?? [], ownKnown = own.filter(task => task.doneAt !== null).sort(compare);
|
|
61
|
+
const cutStart = release.cut === null ? known.length : after(known, release.cut);
|
|
62
|
+
const unknownPool = release.cut === null ? approved : unknown;
|
|
63
|
+
return { ...this.publicRelease(release),
|
|
64
|
+
name: this.host.nameable(release.name) ? release.name : "[withheld]",
|
|
65
|
+
goal: this.host.nameable(release.goal) ? release.goal : "[withheld]",
|
|
66
|
+
tasks: scopes.get(release.id) ?? [],
|
|
67
|
+
afterCutUnknown: outsideIds(unknownPool, 0, release.id),
|
|
68
|
+
afterCutUnknownCount: release.cut === null ? approved.length - own.length : unknown.length - (own.length - ownKnown.length),
|
|
69
|
+
afterCut: release.cut === null ? null : outsideIds(known, cutStart, release.id),
|
|
70
|
+
afterCutCount: release.cut === null ? null : known.length - cutStart - (ownKnown.length - after(ownKnown, release.cut)),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
/** Release assignment changes no execution role, dependency, reservation or state. */
|
|
77
|
+
async assignRelease(by: PeerId, input: { id: number; revision: number; release: number | null; reason: string }): Promise<Task> {
|
|
78
|
+
this.host.plannerWriteAuthority(by);
|
|
79
|
+
if (typeof input.reason !== "string" || !input.reason.trim() || Buffer.byteLength(input.reason) > 1000) throw new PreEffectToolRefusal("release assignment needs a bounded reason");
|
|
80
|
+
if (!Number.isSafeInteger(input.id) || input.id <= 0 || !Number.isSafeInteger(input.revision) || input.revision < 0 || input.release !== null && (!Number.isSafeInteger(input.release) || input.release <= 0)) throw new PreEffectToolRefusal("invalid release assignment");
|
|
81
|
+
const validate = () => {
|
|
82
|
+
this.host.plannerWriteAuthority(by);
|
|
83
|
+
const task = this.d.board.get(input.id);
|
|
84
|
+
if (!task || (task.planningRevision ?? 0) !== input.revision) throw new PreEffectToolRefusal("release assignment changed");
|
|
85
|
+
this.host.plannerWriteAuthority(by, task);
|
|
86
|
+
if (by !== USER && (this.host.isPii(task) || task.pinned)) throw new PreEffectToolRefusal("private or pinned release scope requires the person");
|
|
87
|
+
for (const id of new Set([task.release, input.release])) if (id != null) {
|
|
88
|
+
const release = this.d.board.release(id);
|
|
89
|
+
if (!release || ["frozen", "shipped", "dropped"].includes(release.state)) throw new PreEffectToolRefusal("release scope is frozen or final");
|
|
90
|
+
this.host.plannerWriteAuthority(by, release);
|
|
91
|
+
}
|
|
92
|
+
return task;
|
|
93
|
+
};
|
|
94
|
+
const before = validate(), signature = JSON.stringify(before), privateScope = this.host.isPii(before);
|
|
95
|
+
if (!privateScope && (!this.host.nameable(input.reason) || this.host.screenOn() && (await this.host.screenCall(input.reason)).label !== "clear")) throw new PreEffectToolRefusal("release reason was not cleared for public planning");
|
|
96
|
+
if (JSON.stringify(validate()) !== signature) throw new PreEffectToolRefusal("release assignment changed during screening");
|
|
97
|
+
const result = this.host.plan(input.id, by, { release: input.release }, input.revision, input.reason.trim(), privateScope);
|
|
98
|
+
this.host.planningRecorded({ by, task: input.id, fields: ["release"], revision: result.planningRevision! });
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async configureRelease(by: PeerId, input: { id: number; revision: number; hotfix?: unknown; state?: "active"; cut?: number }): Promise<Release> {
|
|
104
|
+
this.host.plannerWriteAuthority(by);
|
|
105
|
+
const validate = () => {
|
|
106
|
+
this.host.plannerWriteAuthority(by);
|
|
107
|
+
if (!Number.isSafeInteger(input.id) || input.id <= 0 || !Number.isSafeInteger(input.revision) || input.revision < 0) throw new PreEffectToolRefusal("invalid release identity or revision");
|
|
108
|
+
const release = this.d.board.release(input.id);
|
|
109
|
+
if (!release || release.revision !== input.revision || !["planning", "active"].includes(release.state)) throw new PreEffectToolRefusal("release revision changed or scope frozen");
|
|
110
|
+
this.host.plannerWriteAuthority(by, release);
|
|
111
|
+
if (input.state !== undefined && input.state !== "active") throw new PreEffectToolRefusal("invalid train state");
|
|
112
|
+
if (input.cut !== undefined && (!Number.isSafeInteger(input.cut) || input.cut <= 0 || input.cut > 8_640_000_000_000_000)) throw new PreEffectToolRefusal("release cut must be a positive safe UTC timestamp");
|
|
113
|
+
const dates = [release.plannedStart, input.cut ?? release.cut, release.ship].filter((date): date is number => date !== null);
|
|
114
|
+
if (dates.some((date, index) => index > 0 && dates[index - 1]! > date)) throw new PreEffectToolRefusal("invalid release planned dates");
|
|
115
|
+
if ((input.state ?? release.state) === "active" && this.d.board.releases().some(row => row.id !== input.id && ["active", "frozen"].includes(row.state))) throw new PreEffectToolRefusal("one open release train at a time");
|
|
116
|
+
return release;
|
|
117
|
+
};
|
|
118
|
+
const release = validate();
|
|
119
|
+
let train;
|
|
120
|
+
try { train = releaseTrainData({ ...(release.train ?? { history: [] }), ...(input.hotfix === undefined ? {} : { hotfix: input.hotfix }) }); }
|
|
121
|
+
catch (error) { throw new PreEffectToolRefusal((error as Error).message); }
|
|
122
|
+
if (train.hotfix && (!this.host.nameable(train.hotfix.reason) || this.host.screenOn() && (await this.host.screenCall(train.hotfix.reason)).label !== "clear")) throw new PreEffectToolRefusal("hotfix reason was not cleared");
|
|
123
|
+
const validatedRelease = validate();
|
|
124
|
+
if (JSON.stringify(validatedRelease) !== JSON.stringify(release)) throw new PreEffectToolRefusal("release changed during screening");
|
|
125
|
+
if (release.train && JSON.stringify(train) === JSON.stringify(release.train) && (input.state ?? release.state) === release.state && (input.cut ?? release.cut) === release.cut) return validatedRelease;
|
|
126
|
+
if (train.history.length >= RELEASE_TRAIN_HISTORY_LIMIT - 2) throw new PreEffectToolRefusal("release train history full; keep the remaining slots for cut and ship");
|
|
127
|
+
train.history.push({ at: Date.now(), by, event: "configured" });
|
|
128
|
+
const updated = this.host.updateRelease(input.id, { train: releaseTrainData(train), ...(input.state ? { state: input.state } : {}), ...(input.cut === undefined ? {} : { cut: input.cut }) }, input.revision);
|
|
129
|
+
this.host.planningRecorded({ by, release: input.id, fields: ["train"], revision: updated.revision });
|
|
130
|
+
return updated;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
publicRelease(release: Release): Release {
|
|
135
|
+
return { ...release, name: this.host.nameable(release.name) ? release.name : "[withheld]", goal: this.host.nameable(release.goal) ? release.goal : "[withheld]", ...(release.train?.hotfix && !this.host.nameable(release.train.hotfix.reason) ? { train: { ...release.train, hotfix: { ...release.train.hotfix, reason: "[withheld]" } } } : {}) };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
releaseReport(by: PeerId, id: number) {
|
|
140
|
+
this.host.planningAuthority(by);
|
|
141
|
+
if (by !== USER && this.d.privateTurn?.(by)) throw new PreEffectToolRefusal("release report unavailable during a private turn");
|
|
142
|
+
const release = Number.isSafeInteger(id) && id > 0 ? this.d.board.release(id) : undefined;
|
|
143
|
+
// refusal:by-design operator-knowledge: the caller must supply the intended release id.
|
|
144
|
+
if (!release) throw new PreEffectToolRefusal("no such release");
|
|
145
|
+
const all = this.d.board.list(), publicTasks = all.filter(task => !this.host.isPii(task));
|
|
146
|
+
if (all.some(task => task.release === id && this.host.isPii(task))) throw new PreEffectToolRefusal("release scope contains private work; public readiness unavailable");
|
|
147
|
+
return { release: this.publicRelease(release), readiness: releaseTrainReadiness(release, publicTasks), metrics: releaseMetrics(this.d.board.releases().filter(row => !all.some(task => task.release === row.id && this.host.isPii(task))), publicTasks), native: "unverified" as const };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
/** Scope freeze only. This never tags, publishes, upgrades, or authorizes a release. */
|
|
152
|
+
async cutRelease(by: PeerId, input: { id: number; revision: number }): Promise<Release> {
|
|
153
|
+
const validate = () => {
|
|
154
|
+
this.host.plannerWriteAuthority(by);
|
|
155
|
+
if (!Number.isSafeInteger(input.id) || input.id <= 0 || !Number.isSafeInteger(input.revision) || input.revision < 0) throw new PreEffectToolRefusal("invalid release identity or revision");
|
|
156
|
+
const release = this.d.board.release(input.id);
|
|
157
|
+
if (!release || release.revision !== input.revision || release.state !== "active") throw new PreEffectToolRefusal("release revision changed or train is not active");
|
|
158
|
+
this.host.plannerWriteAuthority(by, release);
|
|
159
|
+
if (this.d.board.releases().some(row => row.id !== input.id && ["active", "frozen"].includes(row.state))) throw new PreEffectToolRefusal("one open release train at a time");
|
|
160
|
+
if ((release.train?.history.length ?? 0) > RELEASE_TRAIN_HISTORY_LIMIT - 2) throw new PreEffectToolRefusal("release train history full; cut needs slots for cut and ship, drop this train and create a replacement");
|
|
161
|
+
const report = this.releaseReport(by, input.id);
|
|
162
|
+
if (report.readiness.blockers.length) throw new PreEffectToolRefusal(`release cut blocked: ${report.readiness.blockers.join("; ")}`);
|
|
163
|
+
return { release, scope: this.d.board.list().filter(task => task.release === input.id) };
|
|
164
|
+
};
|
|
165
|
+
const before = validate(), signature = JSON.stringify(before);
|
|
166
|
+
const expected = new Set(before.scope.flatMap(task => task.sdlc?.repo && task.sdlc.pr ? [`${task.sdlc.repo.toLowerCase()}#${task.sdlc.pr}`] : []));
|
|
167
|
+
let ciRuns: number | undefined;
|
|
168
|
+
if (expected.size && before.scope.every(task => task.sdlc?.repo && /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(task.sdlc.repo) && !task.sdlc.repo.startsWith("-") && Number.isSafeInteger(task.sdlc.pr) && task.sdlc.pr! > 0)) {
|
|
169
|
+
const repositories = [...new Set(before.scope.flatMap(task => task.sdlc?.repo ? [task.sdlc.repo] : []))];
|
|
170
|
+
if (repositories.length === 1 && expected.size <= 16) {
|
|
171
|
+
try {
|
|
172
|
+
const costs = await this.host.costReport(by, repositories[0], before.scope.map(task => task.sdlc!.pr!)), rows = costs.rows as import("./cost-governance.ts").CostRow[];
|
|
173
|
+
const selected = rows.filter(row => expected.has(`${row.repo.toLowerCase()}#${row.pr}`));
|
|
174
|
+
if (!costs.truncated && selected.length === expected.size && selected.every(row => row.ciRuns !== null && row.ciReruns !== null)) ciRuns = selected.reduce((sum, row) => sum + row.ciRuns! + row.ciReruns!, 0);
|
|
175
|
+
} catch { /* Optional cost evidence stays unknown; validation below still rechecks scope and authority. */ }
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (JSON.stringify(validate()) !== signature) throw new PreEffectToolRefusal("release scope changed during cost readback");
|
|
179
|
+
const window = await this.d.releaseWindow?.();
|
|
180
|
+
try {
|
|
181
|
+
if (JSON.stringify({ release: this.d.board.release(input.id), scope: this.d.board.list().filter(task => task.release === input.id) }) !== signature) throw new PreEffectToolRefusal("release scope changed during admission");
|
|
182
|
+
const freshScope = validate();
|
|
183
|
+
if (!window || !Number.isFinite(window.at) || Date.now() - window.at > 5000 || window.at > Date.now() || window.host !== true || window.quota !== true || window.current?.() === false) throw new PreEffectToolRefusal(`release cut deferred: ${window?.reasons?.join("; ") || "host or peer quota evidence unavailable"}; inspect ahub budget and ahub budget set <peer> <0..1>; stop or resume the paused peer; the person can use ahub release drop or explicitly disable lifecycle mode before retrying`);
|
|
184
|
+
const scope = freshScope.scope.map(task => task.id).sort((a, b) => a - b), train = releaseTrainData(freshScope.release.train ?? { history: [] });
|
|
185
|
+
train.scope = scope; train.history.push({ at: Date.now(), by, event: "cut", scope, reviews: freshScope.scope.reduce((sum, task) => sum + task.history.filter(row => ["approved", "changes_requested"].includes(row.event)).length, 0), ...(ciRuns === undefined ? {} : { ciRuns }) });
|
|
186
|
+
const updated = this.host.freezeRelease(input.id, input.revision, freshScope.scope, releaseTrainData(train));
|
|
187
|
+
this.host.planningRecorded({ by, release: input.id, fields: ["state", "train"], revision: updated.revision });
|
|
188
|
+
return updated;
|
|
189
|
+
} finally {
|
|
190
|
+
try { await window?.close?.(); }
|
|
191
|
+
catch { this.host.releaseNotice(`release #${input.id}: admission cleanup incomplete; inspect the host lease before retrying`); }
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
async newRelease(by: PeerId, input: { name: string; goal: string; order: number }): Promise<Release> {
|
|
197
|
+
this.host.plannerWriteAuthority(by);
|
|
198
|
+
if (typeof input.name !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(input.name) || typeof input.goal !== "string" || !input.goal.trim() || input.goal.length > 1000 || !Number.isSafeInteger(input.order) || input.order < 0) throw new PreEffectToolRefusal("invalid release name, goal or order");
|
|
199
|
+
const text = input.name + "\n" + input.goal;
|
|
200
|
+
if (!this.host.nameable(text) || this.host.screenOn() && (await this.host.screenCall(text)).label !== "clear") throw new PreEffectToolRefusal("release text was not cleared for public planning");
|
|
201
|
+
this.host.plannerWriteAuthority(by); // Privacy and planner identity may change while screening.
|
|
202
|
+
if (this.d.board.releases().some(release => release.name === input.name)) throw new PreEffectToolRefusal("release name already exists");
|
|
203
|
+
const release = this.host.newRelease(input.name, input.goal.trim(), input.order, by === USER ? null : by);
|
|
204
|
+
this.host.planningRecorded({ by, release: release.id, fields: ["created"], revision: release.revision });
|
|
205
|
+
return release;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
changeRelease(by: PeerId, input: { id: number; revision: number; state?: ReleaseState; plannedStart?: number | null; cut?: number | null; ship?: number | null }): Release {
|
|
210
|
+
this.host.planningAuthority(by);
|
|
211
|
+
const release = this.d.board.release(input.id);
|
|
212
|
+
if (!Number.isSafeInteger(input.id) || input.id <= 0 || !Number.isSafeInteger(input.revision) || !release || release.revision !== input.revision) throw new PreEffectToolRefusal("release revision changed");
|
|
213
|
+
this.host.planningAuthority(by, release);
|
|
214
|
+
if (["shipped", "dropped"].includes(release.state)) throw new PreEffectToolRefusal("settled release is final");
|
|
215
|
+
if (by !== USER && (release.state === "frozen" || input.state === "frozen" || input.state === "shipped" || input.state === "dropped")) throw new PreEffectToolRefusal("freeze, ship, drop and frozen changes require a person");
|
|
216
|
+
if (input.state === "shipped" && this.d.board.list().some(task => task.release === release.id && !isClosedTaskState(task.state))) throw new PreEffectToolRefusal("every release task must be approved, cancelled, or moved out before ship");
|
|
217
|
+
if (input.state === "active" && (release.train || (this.d.sdlc?.config().mode ?? "off") !== "off" || this.d.board.releases().some(row => row.train && ["active", "frozen"].includes(row.state))) && this.d.board.releases().some(row => row.id !== release.id && ["active", "frozen"].includes(row.state))) throw new PreEffectToolRefusal("one open release train at a time");
|
|
218
|
+
if (input.state === "frozen" && (release.train || (this.d.sdlc?.config().mode ?? "off") !== "off")) throw new PreEffectToolRefusal("use the resource-admitted release cut operation");
|
|
219
|
+
if (input.state === "shipped" && release.train) {
|
|
220
|
+
if (release.train.history.length >= RELEASE_TRAIN_HISTORY_LIMIT) throw new PreEffectToolRefusal("release train history full; ship needs one history slot, drop this train and create a replacement");
|
|
221
|
+
const readiness = releaseTrainReadiness(release, this.d.board.list());
|
|
222
|
+
if (readiness.blockers.length) throw new PreEffectToolRefusal(`release ship blocked: ${readiness.blockers.join("; ")}`);
|
|
223
|
+
}
|
|
224
|
+
const { id, revision, ...patch } = input;
|
|
225
|
+
if (!Object.keys(patch).length || Object.keys(patch).some(key => !["state", "plannedStart", "cut", "ship"].includes(key))) throw new PreEffectToolRefusal("unknown or empty release fields");
|
|
226
|
+
const trained = release.train && input.state === "shipped" ? releaseTrainData({ ...release.train, history: [...release.train.history, { at: Date.now(), by, event: "shipped" }] }) : undefined;
|
|
227
|
+
const updated = this.host.updateRelease(id, { ...patch, ...(trained ? { train: trained } : {}) }, revision);
|
|
228
|
+
this.host.planningRecorded({ by, release: id, fields: Object.keys(patch), revision: updated.revision });
|
|
229
|
+
return updated; // a failed readback may follow a durable release write
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async releaseReadiness(repo: string, liveIssues: number[]) {
|
|
233
|
+
const report = await readReleaseReadiness(this.d.cwd, repo, liveIssues, { gh: this.d.sdlc?.gh, reportPolicy: this.d.sdlc?.reportPolicy });
|
|
234
|
+
if (report.documents) report.documents.documents = report.documents.documents.map(d => {
|
|
235
|
+
if (d.path && (!this.host.nameable(d.path) || matchesPolicy(this.d.cwd, d.path, this.d.piiPaths ?? [], true))) { const { path: _privatePath, ...metadata } = d; return metadata; }
|
|
236
|
+
return d;
|
|
237
|
+
});
|
|
238
|
+
// #481 AC12: release interval, lead time from approval to release and hotfix rate, from the shipped releases' recorded history; unknown stays null (never 0).
|
|
239
|
+
// Releases whose scope holds private work are left out, like the per-release report does.
|
|
240
|
+
const rowsNow = this.d.board.list();
|
|
241
|
+
const publicShipped = this.d.board.releases().filter(release => !rowsNow.some(task => task.release === release.id && this.host.isPii(task)));
|
|
242
|
+
const metrics = publicShipped.some(release => release.state === "shipped") ? releaseMetrics(publicShipped, rowsNow.filter(task => !this.host.isPii(task))) : undefined;
|
|
243
|
+
if (metrics) report.releaseMetrics = metrics;
|
|
244
|
+
const audit = this.host.auditLine();
|
|
245
|
+
if (audit) report.securityAudit = audit;
|
|
246
|
+
const trains = this.d.board.releases().filter(release => release.train && ["active", "frozen"].includes(release.state));
|
|
247
|
+
if (trains.length) {
|
|
248
|
+
const planned = trains.map(release => {
|
|
249
|
+
try { return this.releaseReport(USER, release.id); }
|
|
250
|
+
catch { return { release: { id: release.id }, readiness: { trigger: "waiting", tasks: [], blockers: ["release scope unavailable"] } }; }
|
|
251
|
+
});
|
|
252
|
+
if (planned.some(row => row.readiness.blockers.length)) { report.sourceReady = false; report.blockers.push("planned release scope is not approved or available"); }
|
|
253
|
+
return { ...report, trains: planned };
|
|
254
|
+
}
|
|
255
|
+
return report;
|
|
256
|
+
}
|
|
257
|
+
}
|
package/src/hub/tasks-roadmap.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { instructedHistory } from "./instructed-exact.ts";
|
|
4
4
|
import { parseMilestoneInput, parseMilestonePatch, milestoneId, milestoneRevision, milestoneLinkRef, githubRepo, MILESTONE_STATES, type Milestone, type MilestoneLinkKind, type MilestonePatch, type MilestoneState } from "./roadmap.ts";
|
|
5
5
|
import { milestoneViews, type MilestoneView, type RoadmapSnapshot } from "./roadmap-view.ts";
|
|
6
|
-
import { readMirrorSnapshot, planRoadmapMirror, recoverMirrorBinding } from "./roadmap-sync.ts";
|
|
6
|
+
import { type MirrorScope, readMirrorSnapshot, planRoadmapMirror, recoverMirrorBinding } from "./roadmap-sync.ts";
|
|
7
7
|
import { roadmapExport } from "./roadmap-export.ts";
|
|
8
8
|
import { roadmapIssueStates } from "./roadmap-issue-states.ts";
|
|
9
9
|
import { checkRoadmap, type DriftMilestone, type RoadmapDrift } from "./roadmap-check.ts";
|
|
@@ -212,6 +212,18 @@ export class RoadmapDomain {
|
|
|
212
212
|
throw new PreEffectToolRefusal("GitHub roadmap writes require the person or the configured conductor with roadmap.github_write enabled");
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
/** What the scoped mirror read needs: bound milestone numbers, recovery markers and the desired issue numbers of this repository. */
|
|
216
|
+
mirrorScope(repo: string, views: ReturnType<Tasks["milestoneList"]>): MirrorScope {
|
|
217
|
+
const boundNumbers: number[] = [], markers: { marker: string; title: string }[] = [], desired = new Set<number>();
|
|
218
|
+
for (const view of views) {
|
|
219
|
+
const bound = this.d.board.mirrorMilestone(repo, view.id);
|
|
220
|
+
if (bound !== undefined) boundNumbers.push(bound);
|
|
221
|
+
else markers.push({ marker: `<!-- ahub-roadmap:${this.d.project}:${view.id} -->`, title: view.title });
|
|
222
|
+
for (const issue of view.issues) if (issue.ref.startsWith(`${repo}#`)) desired.add(Number(issue.ref.slice(repo.length + 1)));
|
|
223
|
+
}
|
|
224
|
+
return { boundNumbers, markers, desiredIssues: [...desired] };
|
|
225
|
+
}
|
|
226
|
+
|
|
215
227
|
roadmapIssueRefs(views: ReturnType<Tasks["milestoneList"]>): Set<string> {
|
|
216
228
|
const refs = new Set<string>();
|
|
217
229
|
for (const view of views) {
|
|
@@ -296,7 +308,8 @@ export class RoadmapDomain {
|
|
|
296
308
|
current();
|
|
297
309
|
let mirror: Awaited<ReturnType<typeof readMirrorSnapshot>> | undefined, repo: string | undefined;
|
|
298
310
|
if (config.github_mirror) {
|
|
299
|
-
try { repo = this.roadmapRepository();
|
|
311
|
+
try { repo = this.roadmapRepository(); const scopeRepo = repo;
|
|
312
|
+
mirror = await readMirrorSnapshot(repo, this.mirrorScope(scopeRepo, views.filter(view => !view.withheld && view.title !== "[withheld]")), this.roadmapGh()); }
|
|
300
313
|
catch { /* partial or unavailable evidence stays unknown */ }
|
|
301
314
|
current();
|
|
302
315
|
}
|
|
@@ -407,8 +420,9 @@ export class RoadmapDomain {
|
|
|
407
420
|
const stamp = () => createHash("sha256").update(JSON.stringify([this.d.board.milestones(), this.d.board.milestoneLinks(), this.d.board.list(), views.map(view => [view.id, this.d.board.mirrorMilestone(repo, view.id)]), this.d.roadmapConfig?.(), this.d.routing(), this.d.piiPaths, this.d.deny])).digest("hex");
|
|
408
421
|
let before = stamp(); const check = this.host.requestCheck(by, () => this.d.sweepHeld?.() || this.d.bus.isRecoveryHeld || this.d.bus.storageError ? "roadmap is held by recovery or storage" : undefined);
|
|
409
422
|
const current = () => { check(); this.roadmapReadAuthority(by); if (input.apply) this.roadmapApplyAuthority(by); if (this.roadmapRepository() !== repo || stamp() !== before) throw new PreEffectToolRefusal("roadmap, origin or authority changed; preview sync again"); };
|
|
423
|
+
for (const view of views) if (view.withheld || view.title === "[withheld]" || view.outcome === "[withheld]") throw new PreEffectToolRefusal("roadmap mirror contains withheld membership or metadata; inspect privacy before syncing");
|
|
410
424
|
const run = this.roadmapGh();
|
|
411
|
-
const snapshot = await readMirrorSnapshot(repo, async (...args) => { current(); const result = await run(...args); current(); return result; });
|
|
425
|
+
const snapshot = await readMirrorSnapshot(repo, this.mirrorScope(repo, views), async (...args) => { current(); const result = await run(...args); current(); return result; });
|
|
412
426
|
current();
|
|
413
427
|
const bindings: { milestone: number; number: number }[] = [], calls: string[][] = [], createIds: (number | undefined)[] = [], issueOwners = new Set<number>();
|
|
414
428
|
for (const view of views) for (const issue of view.issues) if (issue.ref.startsWith(`${repo}#`)) {
|