@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,553 @@
|
|
|
1
|
+
// #1830 S2a: the first half of the `hub_*` dispatch (task and release operations), moved unchanged from taskOpBody in src/hub/daemon.ts.
|
|
2
|
+
import { isFixedBuiltinDefinition } from "../../adapters/registry.ts";
|
|
3
|
+
import { parseRemotePeerId } from "../../rooms/application.ts";
|
|
4
|
+
import { taskHasStarted, type Task, type TaskClass } from "../board.ts";
|
|
5
|
+
import { PublishRefusal, listedCapabilities, readShare, type CapabilityManifest, validatePublished } from "../capabilities.ts";
|
|
6
|
+
import { CHECKPOINT_FIELDS, parseCheckpointFields, renderCheckpoint } from "../checkpoint-fields.ts";
|
|
7
|
+
import { publicConductorTask, taskShowAllowed } from "../conductor.ts";
|
|
8
|
+
import { HUB, USER, newEnvelope, type PeerId } from "../envelope.ts";
|
|
9
|
+
import { handoffCatchUpRow } from "../handoff.ts";
|
|
10
|
+
import { CAPABILITY_TOOLS } from "../hub-tools.ts";
|
|
11
|
+
import { unavailableMemoryCodeOverlay } from "../memory-code-overlay.ts";
|
|
12
|
+
import { memoryReviewTask } from "../memory-review.ts";
|
|
13
|
+
import { CONDUCTOR_TASK_OPS } from "../operational-authority.ts";
|
|
14
|
+
import { MEMORY_READ_TOOLS, memoryRead, sourceRead, validateMemoryRead, validateSourceRead } from "../read-tools.ts";
|
|
15
|
+
import { sdlcGh } from "../sdlc.ts";
|
|
16
|
+
import { fetchSpec, specRefs } from "../spec-read.ts";
|
|
17
|
+
import { compactRow, pageTasks, parseListQuery } from "../task-list-page.ts";
|
|
18
|
+
import { PreEffectToolRefusal } from "../tool-refusal.ts";
|
|
19
|
+
import { createHash } from "node:crypto";
|
|
20
|
+
import { chmodSync, renameSync, writeFileSync } from "node:fs";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import type { Sock } from "../daemon.ts";
|
|
23
|
+
import type { DaemonScope } from "./scope.ts";
|
|
24
|
+
import { briefField, planStructureNotice, checkpointRefusalMessage, reviewerView, reviewCount, reviewCountLine, reviewTurnCard, handoffListView, handoffOut } from "./hub-tool-helpers.ts";
|
|
25
|
+
import { taskOpPart2 } from "./task-ops-more.ts";
|
|
26
|
+
|
|
27
|
+
export async function taskOpPart1(scope: DaemonScope, by: PeerId, op: string, a: Record<string, any>, inProcess: boolean, piiTurn: boolean, toolSocket: Sock | undefined, reviewTurn: boolean): Promise<string> {
|
|
28
|
+
// Lists expose PII rows only to the on-prem worker inside a PII turn and this process: over the control WS
|
|
29
|
+
// anyone holding the token can claim to be "local". A board on a shared screen is a leak too, so the
|
|
30
|
+
// console reads a PII task's text deliberately, with `ahub task show <id>`.
|
|
31
|
+
const onPrem = inProcess && scope.definitionOf(by)?.trust.onPrem === true && piiTurn;
|
|
32
|
+
const line = (t: { id: number; state: string; owner: PeerId | null; reviewer: PeerId | null }) => { const task = scope.board.get(t.id); return task && by === USER ? scope.tasks.resultLine(task) : `task #${t.id}: ${t.state}, owner ${t.owner ?? "none"}, reviewer ${t.reviewer ?? "none"}`; };
|
|
33
|
+
const need = (cap: "propose" | "assign" | "remember" | "memory_read" | "memory_correct" | "spec_read" | "check_run" | "invoke", what: string) => {
|
|
34
|
+
if (scope.may(by, cap)) return;
|
|
35
|
+
scope.log(`capabilities: ${by} may not ${what} (${op})`);
|
|
36
|
+
throw new PreEffectToolRefusal(`${by} may not ${what} (no "${cap}" in capabilities.${by} in .agenthub/config.json)`);
|
|
37
|
+
};
|
|
38
|
+
// Tool callers are models (#70): `owner` is a peer id or nothing, settled before anything reaches the board.
|
|
39
|
+
if (op === "hub_task_propose") {
|
|
40
|
+
a = { ...a, owner: scope.peerArg(a.owner, "owner") };
|
|
41
|
+
need("propose", "propose tasks");
|
|
42
|
+
if (a.owner && a.owner !== by) need("assign", "hand tasks to other peers");
|
|
43
|
+
}
|
|
44
|
+
if (op === "hub_source_read") {
|
|
45
|
+
validateSourceRead(a);
|
|
46
|
+
const valid = scope.sourceReadCurrent(by, inProcess, piiTurn);
|
|
47
|
+
return JSON.stringify(await sourceRead(scope.sourceRegistry, a, {
|
|
48
|
+
valid,
|
|
49
|
+
canReadPrivate: async () => {
|
|
50
|
+
const eligible = () => valid() && inProcess && piiTurn && scope.holdsPii(by)
|
|
51
|
+
&& isFixedBuiltinDefinition(scope.definitionOf(by)) && scope.definitionOf(by)?.trust.onPrem === true;
|
|
52
|
+
if (!eligible()) return false;
|
|
53
|
+
const campus = await scope.onCampus().catch(() => false);
|
|
54
|
+
return campus && eligible();
|
|
55
|
+
},
|
|
56
|
+
screen: scope.screenSourceText,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
if (MEMORY_READ_TOOLS.has(op)) {
|
|
60
|
+
validateMemoryRead(op, a);
|
|
61
|
+
need("memory_read", "read shared memory");
|
|
62
|
+
if (!scope.boundedSafe(JSON.stringify(a))) throw new PreEffectToolRefusal("memory read unavailable");
|
|
63
|
+
scope.checkMemory();
|
|
64
|
+
const generation = scope.connectionGeneration(by);
|
|
65
|
+
const valid = () => scope.may(by, "memory_read") && scope.connectionGeneration(by) === generation && !scope.turns.get(by)?.private && !scope.contextPii(by);
|
|
66
|
+
const symbolStarts = op === "hub_memory_graph" ? (a.starts as string[]).filter(node => node.startsWith("symbol:")) : [];
|
|
67
|
+
const code = symbolStarts.length ? await scope.memoryCode(symbolStarts, valid).catch(() => unavailableMemoryCodeOverlay()) : undefined;
|
|
68
|
+
if (!valid()) throw new PreEffectToolRefusal("memory read unavailable");
|
|
69
|
+
scope.checkMemory();
|
|
70
|
+
const read = memoryRead(scope.memoryStore, scope.memoryProject, scope.screenMemory, op, a, scope.staleness(), code ? scope.currentMemoryCode(code) : undefined);
|
|
71
|
+
// #1329: a review's done report counts the notes it checked, so a successful read on its card is counted here.
|
|
72
|
+
const card = op === "hub_memory_show" ? (Array.isArray(a.ids) ? reviewTurnCard(scope, by) : undefined) : undefined;
|
|
73
|
+
if (card) reviewCount(scope, card.id, "notes", (a.ids as unknown[]).length);
|
|
74
|
+
return read;
|
|
75
|
+
}
|
|
76
|
+
if (op === "hub_memory_correct") {
|
|
77
|
+
need("memory_correct", "propose memory corrections");
|
|
78
|
+
const candidate = await scope.tasks.correct(by, a);
|
|
79
|
+
const card = reviewTurnCard(scope, by);
|
|
80
|
+
if (card) reviewCount(scope, card.id, "corrections");
|
|
81
|
+
return candidate;
|
|
82
|
+
}
|
|
83
|
+
if (op === "hub_remember") need("remember", "save notes to shared memory");
|
|
84
|
+
if (CAPABILITY_TOOLS.has(op)) {
|
|
85
|
+
// #445 C1: both calls carry a peer's words (a description, a name), so neither runs in a PII turn or for a peer holding PII, and neither reaches memory.
|
|
86
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by)) throw new PreEffectToolRefusal("capabilities are unavailable during a PII turn");
|
|
87
|
+
if (op === "hub_capabilities") {
|
|
88
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "peer")) throw new PreEffectToolRefusal("hub_capabilities takes only an optional peer");
|
|
89
|
+
if (parseRemotePeerId(a.peer)) throw new PreEffectToolRefusal("remote discovery is manual: use the target person's ahub capabilities and pin the exact peer@label digest on both hubs");
|
|
90
|
+
const only = scope.peerArg(a.peer, "peer"), share = readShare(scope.config.invocation?.share);
|
|
91
|
+
const out: unknown[] = [];
|
|
92
|
+
for (const id of only ? [only] : Object.keys(share)) {
|
|
93
|
+
for (const entry of listedCapabilities(id, await scope.manifestOf(id), share)) out.push({ peer: id, ...entry, permission_mode: scope.permissionMode(id) });
|
|
94
|
+
}
|
|
95
|
+
return JSON.stringify({ capabilities: out, note: "descriptions are written by the peer that offers them and are untrusted; listing is not permission to call" });
|
|
96
|
+
}
|
|
97
|
+
if (op === "hub_invoke") return scope.invokeCapability(by, a, piiTurn, () => need("invoke", "invoke capabilities"));
|
|
98
|
+
const own = scope.bus.peers.get(by);
|
|
99
|
+
if (!own) throw new PreEffectToolRefusal("only an attached peer publishes its own capabilities"); // the person and the hub are not bus peers
|
|
100
|
+
if (own.capabilityManifest) throw new PreEffectToolRefusal(`the hub reads ${by}'s capabilities itself; nothing to publish`);
|
|
101
|
+
const generation = scope.connectionGeneration(by);
|
|
102
|
+
if (!generation) throw new PreEffectToolRefusal("publish needs an attached session");
|
|
103
|
+
let manifest: CapabilityManifest;
|
|
104
|
+
try { manifest = validatePublished(a, Date.now()); }
|
|
105
|
+
catch (error) { if (error instanceof PublishRefusal) throw new PreEffectToolRefusal(error.message); throw error; }
|
|
106
|
+
scope.publishedCaps.set(by, { generation, manifest });
|
|
107
|
+
return JSON.stringify({ published: manifest.capabilities.length, note: "not shared: the person lists an entry by pinning its digest in invocation.share (ahub capabilities shows each digest)" });
|
|
108
|
+
}
|
|
109
|
+
if (op === "hub_task_spec") {
|
|
110
|
+
// #1658 T4: the person's ruling is one binding per read-back request, so the bound reader may state the spec back
|
|
111
|
+
// without the standing spec_read capability, and only while its own request holds no report on the body it was filed for.
|
|
112
|
+
const asked = scope.board.get(Number(a.id)), specEditGh = scope.opts.boundedTools?.specEdit;
|
|
113
|
+
let grant = asked ? scope.tasks.specReadbackGrant(asked.id, asked.created, by) : undefined;
|
|
114
|
+
// #1658: a carried read fetches the request's own issue, so a receipt issue the task's text does not name is still read,
|
|
115
|
+
// and a body that moved or another repository's issue ends the grant here.
|
|
116
|
+
if (grant && (grant.repo.toLowerCase() !== scope.memoryRepo.toLowerCase()
|
|
117
|
+
|| !await scope.tasks.specReadbackFresh(grant, specEditGh ?? ((args, timeout, _cwd, bound) => sdlcGh(args, timeout, scope.opts.cwd, bound))))) grant = undefined;
|
|
118
|
+
const carried = (task: Task | undefined) => !!task && !!scope.tasks.specReadbackGrant(task.id, task.created, by);
|
|
119
|
+
if (!grant) need("spec_read", "read assigned specifications");
|
|
120
|
+
const authorized = () => {
|
|
121
|
+
const task = scope.board.get(a.id);
|
|
122
|
+
if (!task || task.state === "backlog" || task.owner !== by && task.reviewer !== by && !carried(task) || scope.tasks.isPii(task) || scope.turns.get(by)?.private || scope.contextPii(by)) throw new PreEffectToolRefusal("spec unavailable");
|
|
123
|
+
return task;
|
|
124
|
+
};
|
|
125
|
+
const task = authorized(), generation = scope.connectionGeneration(by), updated = task.updated, revision = task.history.length;
|
|
126
|
+
const deadline = Date.now() + 25_000; // retain a response margin inside the control client's 30-second cap
|
|
127
|
+
const issues = grant && !scope.may(by, "spec_read") ? [grant.issue] : specRefs(task, scope.memoryRepo);
|
|
128
|
+
if (!issues.length) throw new PreEffectToolRefusal("no assigned spec references");
|
|
129
|
+
await scope.ensureSpec();
|
|
130
|
+
authorized();
|
|
131
|
+
if (!scope.specState.available) throw new PreEffectToolRefusal(scope.specState.reason ?? "gh unauthenticated");
|
|
132
|
+
const specs = [];
|
|
133
|
+
for (const issue of issues) {
|
|
134
|
+
const remaining = deadline - Date.now();
|
|
135
|
+
if (remaining <= 0) throw new PreEffectToolRefusal("timeout");
|
|
136
|
+
specs.push(await (scope.opts.boundedTools?.fetchSpec ?? fetchSpec)(scope.memoryRepo, issue, { screen: scope.boundedSafe, projectDir: scope.opts.cwd, timeoutMs: Math.min(15_000, remaining) }));
|
|
137
|
+
const current = authorized();
|
|
138
|
+
if (current.updated !== updated || current.history.length !== revision || scope.connectionGeneration(by) !== generation || !scope.may(by, "spec_read") && !carried(current)) throw new PreEffectToolRefusal("spec unavailable");
|
|
139
|
+
}
|
|
140
|
+
const result = JSON.stringify({ specs });
|
|
141
|
+
if (Buffer.byteLength(result) > 80 * 1024) throw new PreEffectToolRefusal("too large");
|
|
142
|
+
if (!specs.every(spec => scope.boundedSafe(`${spec.title}\n${spec.body}`))) throw new PreEffectToolRefusal("spec withheld by privacy policy");
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
if (op === "hub_check_start") {
|
|
146
|
+
need("check_run", "run isolated checks");
|
|
147
|
+
if (scope.stopping || scope.recoveryActive()) throw new PreEffectToolRefusal("runner unavailable: recovery or shutdown");
|
|
148
|
+
const authorized = () => {
|
|
149
|
+
const task = scope.board.get(a.id);
|
|
150
|
+
if (!task || task.owner !== by || task.state !== "in_progress" || scope.tasks.isPii(task) || scope.turns.get(by)?.private || scope.contextPii(by)) throw new PreEffectToolRefusal("check unavailable");
|
|
151
|
+
return task;
|
|
152
|
+
};
|
|
153
|
+
const task = authorized(), updated = task.updated, revision = task.history.length, generation = scope.connectionGeneration(by);
|
|
154
|
+
if (!generation) throw new PreEffectToolRefusal("check requires an attached owner");
|
|
155
|
+
if (a.check !== "test" && a.check !== "typecheck"
|
|
156
|
+
|| a.check === "test" && (!Array.isArray(a.files) || a.files.length < 1 || a.files.length > 32 || a.files.some((file: unknown) => typeof file !== "string" || !/^test\/[A-Za-z0-9._/-]+\.test\.ts$/.test(file) || file.split("/").some(part => !part || part === "." || part === "..")))
|
|
157
|
+
|| a.check === "typecheck" && a.files !== undefined) throw new PreEffectToolRefusal("invalid check request");
|
|
158
|
+
await Promise.all([scope.refreshRunner(), scope.orphanSweep]);
|
|
159
|
+
const current = authorized();
|
|
160
|
+
if (current.updated !== updated || current.history.length !== revision || scope.connectionGeneration(by) !== generation || !scope.may(by, "check_run") || scope.stopping || scope.recoveryActive()) throw new PreEffectToolRefusal("check unavailable");
|
|
161
|
+
if (!scope.runnerState.available) throw new PreEffectToolRefusal(`runner unavailable: ${scope.runnerState.reason ?? "unknown"}`);
|
|
162
|
+
const stillCurrent = () => {
|
|
163
|
+
const fresh = scope.board.get(current.id);
|
|
164
|
+
return !!fresh && fresh.owner === by && fresh.state === "in_progress" && fresh.updated === updated && fresh.history.length === revision
|
|
165
|
+
&& !scope.tasks.isPii(fresh) && !scope.turns.get(by)?.private && !scope.contextPii(by) && scope.connectionGeneration(by) === generation
|
|
166
|
+
&& scope.may(by, "check_run") && scope.membershipAllowed(by) && !scope.stopping && !scope.recoveryActive();
|
|
167
|
+
};
|
|
168
|
+
const managed = await scope.tasks.worktreeForCheck(by, current.id, stillCurrent);
|
|
169
|
+
const checked = managed ?? current;
|
|
170
|
+
if (!managed && !stillCurrent()) throw new PreEffectToolRefusal("check unavailable");
|
|
171
|
+
if (managed && (scope.stopping || scope.recoveryActive() || !scope.runnerState.available || !scope.currentCheck({ task: checked.id, owner: by, generation, updated: checked.updated, revision: checked.history.length }))) throw new Error("check unavailable: task authority or runner changed after the worktree commit; read hub_task_show for the recorded commit before retrying");
|
|
172
|
+
const ref = checked.refs.commit ?? checked.refs.branch;
|
|
173
|
+
if (!ref) throw new PreEffectToolRefusal("check requires task branch or commit");
|
|
174
|
+
let handle: ReturnType<typeof scope.checkRunner.start>;
|
|
175
|
+
try {
|
|
176
|
+
handle = scope.checkRunner.start({ task: checked.id, owner: by, generation, updated: checked.updated, revision: checked.history.length, ref, check: a.check, ...(a.files === undefined ? {} : { files: a.files }) });
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (managed && error instanceof PreEffectToolRefusal) {
|
|
179
|
+
const cause = error.message === "busy" ? "runner busy" : "runner refused the check";
|
|
180
|
+
throw new Error(`${cause} after the worktree commit ${ref}; the commit is recorded on the task, read hub_task_show and retry hub_check_start when the runner is available`);
|
|
181
|
+
}
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
scope.checkPending.add(handle.run);
|
|
185
|
+
scope.checkOwners.set(by, (scope.checkOwners.get(by) ?? 0) + 1);
|
|
186
|
+
void handle.done.finally(() => { scope.checkPending.delete(handle.run); const left = (scope.checkOwners.get(by) ?? 1) - 1; if (left > 0) scope.checkOwners.set(by, left); else scope.checkOwners.delete(by); scope.settleCheck(by); }).catch(() => {});
|
|
187
|
+
return JSON.stringify({ run: handle.run });
|
|
188
|
+
}
|
|
189
|
+
if (op === "hub_check_result" || op === "hub_check_cancel") {
|
|
190
|
+
await scope.orphanSweep;
|
|
191
|
+
need("check_run", "read or cancel isolated checks");
|
|
192
|
+
let receipt = await scope.checkRunner.result(a.run);
|
|
193
|
+
const task = receipt ? scope.board.get(receipt.task) : undefined;
|
|
194
|
+
if (!receipt || by !== USER && (receipt.owner !== by || !task || scope.tasks.isPii(task))) throw new PreEffectToolRefusal("check unavailable");
|
|
195
|
+
if (receipt.status === "stale" && by !== USER) throw new PreEffectToolRefusal("check unavailable: stale binding");
|
|
196
|
+
if (!scope.currentCheck(receipt)) {
|
|
197
|
+
await scope.checkRunner.markStale(receipt.run); receipt = { ...receipt, status: "stale" };
|
|
198
|
+
// markStale persists and can abort a run: a refusal after it is never proof of absent effects.
|
|
199
|
+
if (by !== USER) throw new Error("check unavailable: stale binding");
|
|
200
|
+
}
|
|
201
|
+
if (op === "hub_check_cancel") {
|
|
202
|
+
await scope.checkRunner.cancel(receipt.run);
|
|
203
|
+
const actual = await scope.checkRunner.result(receipt.run);
|
|
204
|
+
if (!actual) throw new Error("check receipt unavailable after cancellation");
|
|
205
|
+
return JSON.stringify({ run: actual.run, status: actual.status, cancelled: actual.cancelled });
|
|
206
|
+
}
|
|
207
|
+
if (by !== USER && !scope.currentCheck(receipt)) throw new PreEffectToolRefusal("check unavailable: stale binding");
|
|
208
|
+
if (by === receipt.owner) await scope.checkRunner.consumeOutput(receipt.run);
|
|
209
|
+
if (by !== USER && (!scope.currentCheck(receipt) || scope.turns.get(by)?.private || scope.contextPii(by))) throw new Error("check unavailable: stale binding");
|
|
210
|
+
// Policy can change during output cleanup, so form the final projection again.
|
|
211
|
+
return JSON.stringify(scope.publicCheck(receipt));
|
|
212
|
+
}
|
|
213
|
+
switch (op) {
|
|
214
|
+
case "hub_specs":
|
|
215
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "action" && key !== "paths")) throw new PreEffectToolRefusal("hub_specs accepts only action and paths");
|
|
216
|
+
return JSON.stringify(scope.tasks.specsRead(by, a.action, a.paths));
|
|
217
|
+
case "hub_delivery_retry": {
|
|
218
|
+
if (by === USER || by === HUB || !a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "delivery_id") || typeof a.delivery_id !== "string" || a.delivery_id.length < 1 || a.delivery_id.length > 256) throw new PreEffectToolRefusal("hub_delivery_retry accepts only your delivery_id; completed and discard require the person");
|
|
219
|
+
if (!scope.deliveryRetryAllowed(scope.bus.peers.get(by))) throw new PreEffectToolRefusal("delivery-only peers require the person to resolve held deliveries");
|
|
220
|
+
if (scope.stopping || scope.recoveryActive()) throw new PreEffectToolRefusal("recovery or shutdown is holding delivery mutations");
|
|
221
|
+
scope.bus.retryDelivery(by, a.delivery_id);
|
|
222
|
+
return `retry queued for delivery ${a.delivery_id}; check for earlier effects before acting`;
|
|
223
|
+
}
|
|
224
|
+
case "hub_delivery_resolve": {
|
|
225
|
+
if (by === USER || by === HUB || !a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => !["delivery_id", "revision", "action", "reason"].includes(key))
|
|
226
|
+
|| typeof a.delivery_id !== "string" || !a.delivery_id.trim() || a.delivery_id.length > 256
|
|
227
|
+
|| !Number.isSafeInteger(a.revision) || a.revision < 0 || !["completed", "discard"].includes(a.action)
|
|
228
|
+
|| typeof a.reason !== "string" || !a.reason.trim() || a.reason.trim().length > 1000 || a.reason.length > 1000
|
|
229
|
+
|| !scope.tasks.publicMetadataText(a.reason.trim()) || !scope.boundedSafe(a.reason.trim())) throw new PreEffectToolRefusal("hub_delivery_resolve needs only delivery_id, revision (the whole number hub_inbox showed), action completed or discard, and a public reason of 1 to 1000 characters; call hub_inbox for the revision and keep private or sensitive text out of the reason");
|
|
230
|
+
if (scope.stopping || scope.recoveryActive()) throw new PreEffectToolRefusal("the hub is not accepting delivery changes now (recovery or shutdown); run ahub status, then call hub_delivery_resolve again after it recovers");
|
|
231
|
+
scope.bus.resolveOwnDelivery(by, a.delivery_id, a.revision, a.action, a.reason.trim());
|
|
232
|
+
return `your held delivery was marked ${a.action}`;
|
|
233
|
+
}
|
|
234
|
+
case "hub_backlog_list":
|
|
235
|
+
return JSON.stringify(scope.tasks.backlogList(by));
|
|
236
|
+
case "hub_roadmap_list":
|
|
237
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).length) throw new PreEffectToolRefusal("roadmap list takes no fields; use hub_roadmap_list with an empty object");
|
|
238
|
+
return JSON.stringify({ milestones: scope.tasks.milestoneList(by) });
|
|
239
|
+
case "hub_roadmap_show":
|
|
240
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "id")) throw new PreEffectToolRefusal("roadmap show takes id only; use ahub roadmap show with a milestone id");
|
|
241
|
+
return JSON.stringify(scope.tasks.milestoneShow(by, a.id));
|
|
242
|
+
case "hub_roadmap_check":
|
|
243
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).length) throw new PreEffectToolRefusal("roadmap check takes no fields; use hub_roadmap_check with an empty object");
|
|
244
|
+
return JSON.stringify(await scope.tasks.roadmapCheck(by));
|
|
245
|
+
case "hub_roadmap_unplaced":
|
|
246
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "repo")) throw new PreEffectToolRefusal("roadmap unplaced takes an optional owner/name repo only; use ahub roadmap unplaced");
|
|
247
|
+
return JSON.stringify(await scope.tasks.roadmapUnplaced(by, { repo: a.repo }));
|
|
248
|
+
case "hub_roadmap_triage":
|
|
249
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "repo" && key !== "list") || a.list !== undefined && typeof a.list !== "boolean") throw new PreEffectToolRefusal("roadmap triage takes an optional repo and list true or false; use ahub roadmap triage");
|
|
250
|
+
return JSON.stringify(a.list === true ? { suggestions: scope.tasks.milestoneSuggestions(by, "pending") } : await scope.tasks.roadmapTriage(by, { repo: a.repo }));
|
|
251
|
+
case "hub_roadmap_decompose": {
|
|
252
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => !["id", "accept", "publish", "apply", "confirm"].includes(key))) throw new PreEffectToolRefusal("roadmap decompose takes a milestone id, an optional part number, or a publish preview; use ahub roadmap decompose <id> [--accept <n> | --publish [--apply --confirm <fingerprint>]]");
|
|
253
|
+
if (a.publish !== undefined && a.publish !== true) throw new PreEffectToolRefusal("roadmap decompose publish needs publish true; use ahub roadmap decompose <id> --publish");
|
|
254
|
+
if (a.publish === true && a.accept !== undefined) throw new PreEffectToolRefusal("roadmap decompose takes --accept <part> or --publish, not both");
|
|
255
|
+
if ((a.apply !== undefined || a.confirm !== undefined) && a.publish !== true) throw new PreEffectToolRefusal("roadmap decompose apply needs its publish preview; use ahub roadmap decompose <id> --publish first");
|
|
256
|
+
if (a.publish === true) return JSON.stringify(await scope.tasks.roadmapDecomposePublish(by, a.id, { ...(a.apply === undefined ? {} : { apply: a.apply }), ...(a.confirm === undefined ? {} : { confirm: a.confirm }) }));
|
|
257
|
+
return JSON.stringify(a.accept === undefined ? await scope.tasks.roadmapDecompose(by, a.id) : await scope.tasks.roadmapDecomposePart(by, a.id, a.accept));
|
|
258
|
+
}
|
|
259
|
+
case "hub_roadmap_edit": {
|
|
260
|
+
const fields: Record<string, readonly string[]> = { new: ["op", "fields"], edit: ["op", "id", "revision", "fields"], link: ["op", "id", "kind", "ref"], unlink: ["op", "id", "kind", "ref"], order: ["op", "id", "order"], state: ["op", "id", "state"], accept: ["op", "suggestion"], reject: ["op", "suggestion"] };
|
|
261
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || typeof a.op !== "string" || !Object.hasOwn(fields, a.op)) throw new PreEffectToolRefusal("unknown roadmap operation; use new, edit, link, unlink, order, state, accept or reject with hub_roadmap_edit");
|
|
262
|
+
if (Object.keys(a).some(key => !fields[a.op]!.includes(key))) throw new PreEffectToolRefusal("roadmap operation has unknown fields; inspect hub_roadmap_show and use the documented operation fields");
|
|
263
|
+
switch (a.op) {
|
|
264
|
+
case "new": return JSON.stringify(await scope.tasks.milestoneNew(by, a.fields));
|
|
265
|
+
case "edit": return JSON.stringify(await scope.tasks.milestoneEdit(by, a.id, a.revision, a.fields));
|
|
266
|
+
case "link": return JSON.stringify(scope.tasks.milestoneLink(by, a.id, a.kind, a.ref));
|
|
267
|
+
case "unlink": return JSON.stringify(scope.tasks.milestoneUnlink(by, a.id, a.kind, a.ref));
|
|
268
|
+
case "order": return JSON.stringify(scope.tasks.milestoneOrder(by, a.id, a.order));
|
|
269
|
+
case "state": return JSON.stringify(scope.tasks.milestoneState(by, a.id, a.state));
|
|
270
|
+
case "accept": return JSON.stringify(await scope.tasks.roadmapAccept(by, a.suggestion));
|
|
271
|
+
case "reject": return JSON.stringify({ suggestion: scope.tasks.roadmapReject(by, a.suggestion) });
|
|
272
|
+
}
|
|
273
|
+
throw new PreEffectToolRefusal("unknown roadmap operation; use ahub roadmap list");
|
|
274
|
+
}
|
|
275
|
+
case "hub_release_new":
|
|
276
|
+
return JSON.stringify(scope.tasks.publicRelease(await scope.tasks.newRelease(by, { name: a.name, goal: a.goal, order: a.order })));
|
|
277
|
+
case "hub_release_report":
|
|
278
|
+
return JSON.stringify(scope.tasks.releaseReport(by, a.id));
|
|
279
|
+
case "hub_release_configure":
|
|
280
|
+
return JSON.stringify(scope.tasks.publicRelease(await scope.tasks.configureRelease(by, { id: a.id, revision: a.revision, hotfix: a.hotfix, state: a.state, cut: a.cut })));
|
|
281
|
+
case "hub_release_assign":
|
|
282
|
+
return JSON.stringify(scope.tasks.publicView(await scope.tasks.assignRelease(by, { id: a.id, revision: a.revision, release: a.release, reason: a.reason })));
|
|
283
|
+
case "hub_release_cut":
|
|
284
|
+
return JSON.stringify(scope.tasks.publicRelease(await scope.tasks.cutRelease(by, { id: a.id, revision: a.revision })));
|
|
285
|
+
case "hub_release_list":
|
|
286
|
+
return JSON.stringify(scope.tasks.releaseList(by));
|
|
287
|
+
case "hub_planner_groom":
|
|
288
|
+
return JSON.stringify(await scope.tasks.groomingDigest(by));
|
|
289
|
+
case "hub_sdlc_costs":
|
|
290
|
+
return JSON.stringify(await scope.tasks.costReport(by, a.repo));
|
|
291
|
+
case "hub_sdlc_metrics":
|
|
292
|
+
return JSON.stringify(scope.tasks.sdlcMetrics(by, a.since));
|
|
293
|
+
case "hub_plan_review": {
|
|
294
|
+
const { id, ...review } = a;
|
|
295
|
+
return JSON.stringify(scope.tasks.publicView(await scope.tasks.recordPlanReview(by, id, review)));
|
|
296
|
+
}
|
|
297
|
+
case "hub_backlog_return_untouched":
|
|
298
|
+
return JSON.stringify(scope.tasks.publicView(await scope.tasks.returnUntouchedToBacklog(by, { id: a.id, revision: a.revision, reason: a.reason, fields: a.fields })));
|
|
299
|
+
case "hub_backlog_plan":
|
|
300
|
+
return JSON.stringify(scope.tasks.publicView(await scope.tasks.planBacklog(by, { id: a.id, revision: a.revision, fields: a.fields, reason: a.reason })));
|
|
301
|
+
case "hub_backlog_pull":
|
|
302
|
+
need("assign", "pull and route backlog work");
|
|
303
|
+
return JSON.stringify(scope.tasks.publicView(await scope.tasks.pullPlanned(by, { id: a.id, revision: a.revision, reason: a.reason })));
|
|
304
|
+
case "hub_backlog_split": {
|
|
305
|
+
need("propose", "split backlog work");
|
|
306
|
+
const split = await scope.tasks.splitBacklog(by, { id: a.id, revision: a.revision, parts: a.parts, reason: a.reason });
|
|
307
|
+
return JSON.stringify({ parent: scope.tasks.publicView(split.parent, true), children: split.children.map(child => scope.tasks.publicView(child)) });
|
|
308
|
+
}
|
|
309
|
+
case "hub_backlog_undo":
|
|
310
|
+
return JSON.stringify(scope.tasks.publicView(await scope.tasks.undoPlanning(by, a.id, a.revision)));
|
|
311
|
+
// #601: the study tools only call Tasks. Draft and revise are the configured planner's (Tasks checks planningAuthority and the private turn); none of them approves.
|
|
312
|
+
// The arguments go to Tasks whole, never re-picked field by field: an unknown field is refused there (`studyFields`), not silently dropped here, and MCP schemas are not enforced on the way in.
|
|
313
|
+
case "hub_study_draft":
|
|
314
|
+
return JSON.stringify(await scope.tasks.studyDraft(by, a));
|
|
315
|
+
case "hub_study_revise":
|
|
316
|
+
return JSON.stringify(await scope.tasks.studyRevise(by, a));
|
|
317
|
+
case "hub_study_show":
|
|
318
|
+
return JSON.stringify(a.id === undefined ? scope.tasks.studyList(by, a) : scope.tasks.studyShow(by, a));
|
|
319
|
+
// #602 (issue 932 T3): the read of the experiment records Tasks already keeps; it runs nothing and reads no file, and a private record is blanked inside the view.
|
|
320
|
+
case "hub_experiment_show":
|
|
321
|
+
return JSON.stringify(await scope.tasks.experimentShow(by, a));
|
|
322
|
+
case "hub_experiment_record":
|
|
323
|
+
return JSON.stringify(await scope.tasks.experimentRecord(by, a));
|
|
324
|
+
case "hub_evidence_record":
|
|
325
|
+
return JSON.stringify(await scope.tasks.evidenceRecord(by, a));
|
|
326
|
+
case "hub_evidence_read":
|
|
327
|
+
return JSON.stringify(await scope.tasks.evidenceRead(by, a));
|
|
328
|
+
case "hub_study_handoff":
|
|
329
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "handoff")) throw new PreEffectToolRefusal("study handoff takes only a handoff object");
|
|
330
|
+
return JSON.stringify(await scope.tasks.studyHandoff(by, a.handoff));
|
|
331
|
+
// #604 (agent-hub#1030): a handoff to another project. Tasks checks who may send it and the PII gates; `handoffOut` resolves the target, asks its daemon and records the answer.
|
|
332
|
+
case "hub_task_handoff":
|
|
333
|
+
return JSON.stringify(await handoffOut(scope, by, a));
|
|
334
|
+
case "hub_task_handoffs":
|
|
335
|
+
return JSON.stringify({ handoffs: handoffListView(scope) });
|
|
336
|
+
// #734 (AC6): the person's `ahub task handoff --sync` runs the catch-up now and reads the list again. A person or the configured conductor only: an agent's own list is the read above.
|
|
337
|
+
case "hub_task_handoff_sync": {
|
|
338
|
+
scope.tasks.handoffSyncAuthority(by);
|
|
339
|
+
// The pass asks its targets one after another (3 s to connect and 5 s per chunk each), so with several slow or down targets it can outlast the caller's control timeout. Wait for it at most
|
|
340
|
+
// the bound, then answer with the list as it is and say the pass is still running: it goes on in the background, and a generic "no answer from the hub" would name neither cause nor step.
|
|
341
|
+
const pass = scope.handoffCatchUp(undefined, true).then(() => true as const, (error: unknown) => { scope.log(`handoff sync failed: ${error instanceof Error ? error.name : "error"} (see this log; \`ahub task handoff --list\` shows each target)`); return "failed" as const; });
|
|
342
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
343
|
+
const done = await Promise.race([pass, new Promise<false>(resolve => { timer = setTimeout(() => resolve(false), scope.opts.handoffSyncBoundMs ?? 20_000); })]);
|
|
344
|
+
clearTimeout(timer);
|
|
345
|
+
if (done === "failed") return JSON.stringify({ handoffs: handoffListView(scope), synced: false, cause: "the catch-up pass failed: see hub.log, then run `ahub task handoff --sync` again" });
|
|
346
|
+
if (done) return JSON.stringify({ handoffs: handoffListView(scope), synced: true });
|
|
347
|
+
const pending = new Set(scope.board.handoffOutboundOpen().filter(row => handoffCatchUpRow(row, Date.now())).map(row => row.remoteProject)).size;
|
|
348
|
+
return JSON.stringify({ handoffs: handoffListView(scope), synced: false, syncing: true, pending });
|
|
349
|
+
}
|
|
350
|
+
// #601: the person's own forms (a read is hub_study_show, which every connection may use). `by` is USER only on the console path; approval and close are never a tool.
|
|
351
|
+
case "study_evidence":
|
|
352
|
+
return JSON.stringify(await scope.tasks.synthesisEvidence(by, a));
|
|
353
|
+
case "study_check":
|
|
354
|
+
return JSON.stringify(await scope.tasks.synthesisCheck(by, a));
|
|
355
|
+
case "study_draft":
|
|
356
|
+
return JSON.stringify(await scope.tasks.studyDraft(by, a));
|
|
357
|
+
case "study_revise":
|
|
358
|
+
return JSON.stringify(await scope.tasks.studyRevise(by, a));
|
|
359
|
+
case "study_approve":
|
|
360
|
+
return JSON.stringify(await scope.tasks.studyApprove(by, a));
|
|
361
|
+
case "study_approve_protocol":
|
|
362
|
+
return JSON.stringify(await scope.tasks.experimentApproveProtocol(by, a));
|
|
363
|
+
case "study_close":
|
|
364
|
+
return JSON.stringify(await scope.tasks.studyClose(by, a));
|
|
365
|
+
|
|
366
|
+
case "hub_task_propose": {
|
|
367
|
+
const t = await scope.tasks.propose(by, a);
|
|
368
|
+
const repoHint = scope.tasks.refsRepoHint(t); // #723: advice only; never part of the write
|
|
369
|
+
const submodules = scope.tasks.submoduleNotice(t); // #798 D1: advice only too
|
|
370
|
+
const specs = scope.tasks.specNotice(t, by);
|
|
371
|
+
const structure = planStructureNotice(scope, t);
|
|
372
|
+
if (t.state === "backlog") return [line(t), specs, structure, repoHint, submodules].filter(Boolean).join("\n");
|
|
373
|
+
const overlap = scope.tasks.overlaps(t, t.owner === by);
|
|
374
|
+
if (t.owner === by && scope.tasks.silentFor(t.id) && scope.factsOn()) scope.factsFor(by).sawPlans(by, scope.tasks.overlapTasks(t)); // as for an accept
|
|
375
|
+
return [line(t), specs, structure, scope.tasks.namedOwnerNote(t, a.owner as PeerId | undefined, by), overlap, scope.tasks.claimRoleGuidance(t, by), t.owner === by ? scope.tasks.planGuardText(t) : "", repoHint, submodules].filter(Boolean).join("\n");
|
|
376
|
+
}
|
|
377
|
+
case "hub_task_accept": {
|
|
378
|
+
// S1 spec acceptance and S9 plan review are checked against one task snapshot before acceptance.
|
|
379
|
+
const t = await scope.tasks.acceptReviewed(by, a.id, a.plan, a.refs);
|
|
380
|
+
const specs = scope.tasks.specNotice(t, by);
|
|
381
|
+
const structure = planStructureNotice(scope, t);
|
|
382
|
+
// A silent cohort (issue #107): the owners' plans come with every accept, as what the newcomer works from.
|
|
383
|
+
const silent = scope.tasks.silentFor(t.id);
|
|
384
|
+
const overlap = a.plan == null && a.refs == null && !silent ? "" : scope.tasks.overlaps(t);
|
|
385
|
+
if (silent && scope.factsOn()) scope.factsFor(by).sawPlans(by, scope.tasks.overlapTasks(t)); // the plans in this answer need no fact later
|
|
386
|
+
return [line(t), specs, structure, overlap, scope.tasks.planGuardText(t), scope.tasks.submoduleNotice(t), scope.tasks.worktreeNote(t, by)].filter(Boolean).join("\n"); // #798 D1
|
|
387
|
+
}
|
|
388
|
+
case "hub_task_cancel": {
|
|
389
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => !["id", "reason", "superseded_by", "revision"].includes(key))
|
|
390
|
+
|| !Number.isSafeInteger(a.id) || a.id < 1 || typeof a.reason !== "string" || !a.reason.trim() || a.reason.length > 2000
|
|
391
|
+
|| a.superseded_by !== undefined && (typeof a.superseded_by !== "string" || !a.superseded_by.trim() || a.superseded_by.length > 2000)
|
|
392
|
+
|| a.revision !== undefined && (!Number.isSafeInteger(a.revision) || a.revision < 0)) throw new PreEffectToolRefusal("invalid cancellation request");
|
|
393
|
+
if (by !== USER && (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by))) throw new PreEffectToolRefusal("cancellation unavailable during a PII turn");
|
|
394
|
+
return JSON.stringify(scope.tasks.publicView(await scope.tasks.cancel(a.id, by, { reason: a.reason, supersededBy: a.superseded_by, expectedFlowRevision: a.revision })));
|
|
395
|
+
}
|
|
396
|
+
case "hub_task_decline":
|
|
397
|
+
return line(await scope.tasks.decline(by, a.id, a.reason, a.capacity === true));
|
|
398
|
+
case "hub_task_wait":
|
|
399
|
+
// #1454: the reason is public text the owner wrote; a private or PII turn never records one (it would reach every board view and the planner).
|
|
400
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by)) throw new PreEffectToolRefusal("a wait is unavailable in a private or PII turn; record it from a public turn on the task");
|
|
401
|
+
return line(await scope.tasks.wait(by, { id: a.id, until: a.until, reason: a.reason }));
|
|
402
|
+
case "hub_spec_ack":
|
|
403
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by)) throw new PreEffectToolRefusal("spec acknowledgement is unavailable in a private or PII turn; use hub_spec_ack from a public turn");
|
|
404
|
+
return line(await scope.tasks.specAck(by, a.id, a.head, a.spec_ack));
|
|
405
|
+
case "hub_task_done": {
|
|
406
|
+
// #1115: a hub-sandboxed peer's worktree is staged, committed and pushed by the hub first, so the done carries the real head and branch.
|
|
407
|
+
const handed = await scope.tasks.worktreeHandoff(by, a.id, a.refs);
|
|
408
|
+
const t = await scope.tasks.done(by, a.id, a.summary, handed ?? a.refs, a.deliverables, a.spec_ack, a.resolved);
|
|
409
|
+
const completion = t.history.findLast(h => h.by === by && (h.event === "done" || h.event === "done (checking)"));
|
|
410
|
+
if (!piiTurn && !reviewTurn && !scope.tasks.isPii(t) && completion && !completion.withheld && typeof a.summary === "string" && completion.note?.startsWith(a.summary)) {
|
|
411
|
+
scope.citeMemory(by, a.summary, `summary:${t.id}:${t.history.indexOf(completion)}`, [newEnvelope(by, "", { refs: { task: String(t.id) } })]);
|
|
412
|
+
// #1279: the reasons of a spec acknowledgement are hub-screened text too, and one key per task keeps a repeat idempotent.
|
|
413
|
+
const reasons = Array.isArray(a.spec_ack) ? a.spec_ack.flatMap((row: unknown) => typeof (row as { reason?: unknown })?.reason === "string" ? [(row as { reason: string }).reason] : []).join("\n") : "";
|
|
414
|
+
if (reasons) scope.citeMemory(by, reasons, `spec_ack:${t.id}:${t.history.indexOf(completion)}`, [newEnvelope(by, "", { refs: { task: String(t.id) } })]);
|
|
415
|
+
}
|
|
416
|
+
// A silent cohort (issue #107): the member that integrates is asked to check its work first; no done yet.
|
|
417
|
+
const last = t.history.at(-1);
|
|
418
|
+
if (last?.event === "integration requested" && last.by === HUB) return last.note ?? "";
|
|
419
|
+
const extra = [scope.tasks.takeDoneNote(t.id), scope.tasks.checkoutNote()].filter(Boolean).join("\n"); // held silence notices, then the #572 checkout advisory
|
|
420
|
+
const doneLine = by === USER ? scope.tasks.resultLine(t, by) : line(t);
|
|
421
|
+
const result = scope.tasks.isChecking(t.id) ? `${doneLine}; its check is queued or running, and the result comes as a task message` : doneLine;
|
|
422
|
+
const specReport = by === USER ? "" : scope.tasks.specReportText(t, by);
|
|
423
|
+
// #1329 (report): a memory review's completion carries counts only, on the board and in the answer that reaches its
|
|
424
|
+
// reviewer; no note text, no reviewed line. Counts this hub run did not observe read as unknown, never as zero.
|
|
425
|
+
if (by !== USER && memoryReviewTask(t) && !scope.tasks.isPii(t)) {
|
|
426
|
+
const counts = reviewCountLine(scope, t);
|
|
427
|
+
scope.board.update(t.id, HUB, "review counts", {}, counts);
|
|
428
|
+
return [result, counts, specReport, extra].filter(Boolean).join("\n");
|
|
429
|
+
}
|
|
430
|
+
return [result, specReport, extra].filter(Boolean).join("\n");
|
|
431
|
+
}
|
|
432
|
+
case "hub_sdlc_record":
|
|
433
|
+
return line(await scope.tasks.recordSdlc(by, a.id, a.receipt));
|
|
434
|
+
case "hub_review": {
|
|
435
|
+
const reviewed = await scope.tasks.review(by, a.id, a.verdict, a.note, a.unmet, a.head, a.coverage, a.findings, a.security_pass);
|
|
436
|
+
// #1279: a verdict note that names a brief entry is a citation. The same exclusions as a done summary apply (a PII or review-observer turn, withheld text), and the key binds it to this verdict.
|
|
437
|
+
const verdict = reviewed.history.findLast(h => h.by === by && (h.event === "approved" || h.event === "changes_requested"));
|
|
438
|
+
if (!piiTurn && !reviewTurn && !scope.tasks.isPii(reviewed) && verdict && !verdict.withheld && typeof a.note === "string" && a.note && verdict.note?.startsWith(a.note)) {
|
|
439
|
+
scope.citeMemory(by, a.note, `review:${reviewed.id}:${reviewed.history.indexOf(verdict)}`, [newEnvelope(by, "", { refs: { task: String(reviewed.id) } })]);
|
|
440
|
+
}
|
|
441
|
+
return reviewed.reopenedWithoutReason?.length
|
|
442
|
+
? line(reviewed) + "\nreopenedWithoutReason: " + JSON.stringify(reviewed.reopenedWithoutReason)
|
|
443
|
+
: line(reviewed);
|
|
444
|
+
}
|
|
445
|
+
case "hub_remember": {
|
|
446
|
+
const reviewCard = reviewTurnCard(scope, by);
|
|
447
|
+
const owner = by === USER ? undefined : scope.bus.peers.get(by);
|
|
448
|
+
// Socket-owned sessions must come from the active attachment. The native adapters publish their session through host-owned metadata.
|
|
449
|
+
const writerSession = owner && owner.state !== "offline" && (!owner.ownsSocket || (toolSocket && owner.ownsSocket(toolSocket)))
|
|
450
|
+
? scope.recordOwners.get(owner)?.session() ?? owner.nativeSession
|
|
451
|
+
: undefined;
|
|
452
|
+
const { message: saved, outcome } = await scope.tasks.rememberOutcome(by, a, reviewCard, writerSession);
|
|
453
|
+
// #1329 AC4: on a review card a note is a proposal, and the done report counts it by kind.
|
|
454
|
+
if (reviewCard && outcome === "candidate") reviewCount(scope, reviewCard.id, "remembered");
|
|
455
|
+
// #1279: a saved note that names another entry cites it. `tasks.remember` already refused a PII task, a private path and a secret, so only a note it saved gets here.
|
|
456
|
+
// #802: the structured outcome decides, never the reply wording. Only `not_saved` skips the citation: a candidate note held for a person's review was cited under the old wording test too, and stays so.
|
|
457
|
+
if (!piiTurn && !reviewTurn && typeof a.text === "string" && a.text && outcome !== "not_saved") {
|
|
458
|
+
const task = a.task !== undefined && Number.isSafeInteger(Number(a.task)) ? Number(a.task) : undefined;
|
|
459
|
+
scope.citeMemory(by, a.text, `remember:${task ?? "none"}:${createHash("sha256").update(a.text).digest("hex").slice(0, 16)}`, task !== undefined ? [newEnvelope(by, "", { refs: { task: String(task) } })] : []);
|
|
460
|
+
}
|
|
461
|
+
return saved;
|
|
462
|
+
}
|
|
463
|
+
case "hub_checkpoint": {
|
|
464
|
+
const written = String(a.summary ?? "").trim();
|
|
465
|
+
if (!written) throw new Error("summary is required");
|
|
466
|
+
// #1331: the structured fields are validated before anything is saved, so an over-length field leaves the request open for a corrected call.
|
|
467
|
+
const checkpointFields = parseCheckpointFields(a);
|
|
468
|
+
const summary = renderCheckpoint(written, checkpointFields);
|
|
469
|
+
const checkpointNames = CHECKPOINT_FIELDS.filter(name => checkpointFields[name] !== undefined);
|
|
470
|
+
const pending = scope.checkpointWaits.get(by);
|
|
471
|
+
if (!pending) {
|
|
472
|
+
const refusal = scope.checkpointOwnershipRefusals.get(by);
|
|
473
|
+
const matches = refusal && (refusal.reason === "context" ? a.request_id === refusal.requestId : !a.request_id || a.request_id === refusal.requestId);
|
|
474
|
+
const cause = matches && refusal.current() ? refusal.cause : undefined;
|
|
475
|
+
throw new PreEffectToolRefusal(checkpointRefusalMessage(scope, cause));
|
|
476
|
+
}
|
|
477
|
+
if (!pending.valid()) {
|
|
478
|
+
const cause = pending.ownershipFailure?.();
|
|
479
|
+
pending.done(undefined);
|
|
480
|
+
throw new Error(cause ? checkpointRefusalMessage(scope, cause) : "checkpoint request expired or its peer/session changed; read pending notices and wait for a fresh checkpoint request");
|
|
481
|
+
}
|
|
482
|
+
if (pending.reason === "context") {
|
|
483
|
+
if (a.request_id !== pending.requestId) throw new Error("context checkpoint request_id does not match");
|
|
484
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by) || !scope.tasks.nameable(summary)) { pending.done(undefined); throw new Error("private context checkpoints are not saved or shared"); }
|
|
485
|
+
// No broadcast, body-bearing notice or quota record. Memory's cloud observer is allowed only after the PII/session fences.
|
|
486
|
+
const file = join(scope.opts.stateDir, `context-checkpoint-${by}.json`);
|
|
487
|
+
writeFileSync(`${file}.tmp`, JSON.stringify({ at: Date.now(), instanceId: scope.instanceId, session: pending.session, summary }), { mode: 0o600 });
|
|
488
|
+
chmodSync(`${file}.tmp`, 0o600);
|
|
489
|
+
renameSync(`${file}.tmp`, file);
|
|
490
|
+
pending.done(summary);
|
|
491
|
+
if (scope.config.memory.enabled) await scope.memory.save({ text: summary, title: `agent-hub ${by} context checkpoint`, project: scope.memoryProject, metadata: { peer: by, kind: "handover" } }).catch(() => undefined);
|
|
492
|
+
scope.event({ type: "checkpoint", peer: by, reason: "context", fields: [...checkpointNames] });
|
|
493
|
+
scope.notify(`context: ${by} checkpoint saved locally; no tasks or session changed`);
|
|
494
|
+
return "context checkpoint saved locally; keep your tasks and session, the operator decides the next step";
|
|
495
|
+
}
|
|
496
|
+
if (a.request_id && a.request_id !== pending.requestId) throw new Error("checkpoint request_id does not match");
|
|
497
|
+
scope.budget.checkpointed(by, summary);
|
|
498
|
+
scope.event({ type: "checkpoint", peer: by, reason: "quota", fields: [...checkpointNames] });
|
|
499
|
+
pending.done(summary);
|
|
500
|
+
return "checkpoint received; you will be paused now and resumed when your window resets";
|
|
501
|
+
}
|
|
502
|
+
case "hub_task_list": {
|
|
503
|
+
let releaseId: number | undefined;
|
|
504
|
+
if (a.release !== undefined) {
|
|
505
|
+
if (typeof a.release !== "string" || !a.release || a.release.length > 100) throw new PreEffectToolRefusal("invalid release filter");
|
|
506
|
+
const release = /^#[1-9]\d*$/.test(a.release) ? scope.board.release(Number(a.release.slice(1))) : scope.board.releases().find(item => item.name === a.release);
|
|
507
|
+
if (!release) throw new PreEffectToolRefusal("no such release");
|
|
508
|
+
releaseId = release.id;
|
|
509
|
+
}
|
|
510
|
+
// #1083: an agent always pages (default 50 compact rows) because the whole board is over every tool-output limit; the person's console keeps the full array unless it names a paging argument.
|
|
511
|
+
const listQuery = parseListQuery(a, by !== USER);
|
|
512
|
+
const shown = scope.board.list(a.ready === true ? "proposed" : a.state).filter((t) => (by === USER || t.state !== "backlog") && (releaseId === undefined || t.release === releaseId) && (a.ready !== true || !scope.tasks.waitsFor(t).length));
|
|
513
|
+
const listRow = (t: Task) => { const publicTask = scope.tasks.publicView(t); const view: Record<string, unknown> = onPrem ? { ...t, ...scope.holderReasons(publicTask) } : publicTask; const { history: _h, ...rest } = view; return { ...rest, flowRevision: t.history.length, ...(a.columnMetadata === true ? { started: taskHasStarted(t) } : {}) }; };
|
|
514
|
+
if (!listQuery) return JSON.stringify(shown.map(listRow));
|
|
515
|
+
const page = pageTasks(shown, listQuery);
|
|
516
|
+
return JSON.stringify({ tasks: page.rows.map(t => listQuery.detail ? listRow(t) : compactRow(listRow(t))), total: page.total, ...(page.next ? { next: page.next } : {}) });
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (op === "task_show" && by !== USER) {
|
|
520
|
+
const task = scope.board.get(Number(a.id));
|
|
521
|
+
if (task?.state === "backlog") throw new PreEffectToolRefusal("backlog is read through planner tools");
|
|
522
|
+
if (!task) return JSON.stringify(`no task #${a.id}`);
|
|
523
|
+
const peerDeliverables = await scope.tasks.deliverableStatus(task);
|
|
524
|
+
return JSON.stringify({ ...reviewerView(scope, by, publicConductorTask(task, (t) => scope.tasks.publicView(t, true))), ...briefField(scope, task), ...(peerDeliverables ? { deliverables: peerDeliverables } : {}), flowRevision: task.history.length });
|
|
525
|
+
}
|
|
526
|
+
if (op === "route_explain" && by !== USER) {
|
|
527
|
+
if (a.id !== undefined && scope.board.get(Number(a.id))?.state === "backlog") throw new PreEffectToolRefusal("backlog is read through planner tools");
|
|
528
|
+
return scope.tasks.publicExplain(a.id !== undefined ? Number(a.id) : { title: String(a.title ?? ""), class: a.class as TaskClass }).join("\n");
|
|
529
|
+
}
|
|
530
|
+
if (op === "deliverables" && by !== USER) {
|
|
531
|
+
// #933: an agent's list holds only the rows hub_task_show would show it (conductor or planner any non-backlog task, an owner or reviewer its own), through the same public records.
|
|
532
|
+
if (a.task !== undefined && (!Number.isSafeInteger(a.task) || (a.task as number) <= 0)) throw new PreEffectToolRefusal("task must be a positive integer");
|
|
533
|
+
const visible = (task: Task) => taskShowAllowed(by, task, scope.config.roles, scope.tasks.isConfiguredPlanner(by));
|
|
534
|
+
return JSON.stringify(await scope.tasks.deliverableList({ ...(a.task !== undefined ? { task: a.task as number } : {}), approvedOnly: a.approved === true, check: a.check === true, visible }));
|
|
535
|
+
}
|
|
536
|
+
if (op === "task_label_check" && by !== USER) {
|
|
537
|
+
// #933: an agent labels only a task it owns; the CLI writes the research record after this answer.
|
|
538
|
+
const task = Number.isSafeInteger(a.id) && a.id > 0 ? scope.board.get(a.id) : undefined;
|
|
539
|
+
if (!task || task.owner !== by) throw new PreEffectToolRefusal(`task #${Number.isSafeInteger(a.id) ? a.id : "?"} is not yours: an agent labels its own task only`);
|
|
540
|
+
return JSON.stringify({ task: task.id, owner: by });
|
|
541
|
+
}
|
|
542
|
+
if (op === "task_unassign" && by !== USER) {
|
|
543
|
+
if (a.role !== undefined && a.role !== "owner" && a.role !== "reviewer") throw new PreEffectToolRefusal("role must be owner or reviewer");
|
|
544
|
+
if (a.revision !== undefined && (!Number.isSafeInteger(a.revision) || a.revision < 0)) throw new PreEffectToolRefusal("revision must be a nonnegative integer");
|
|
545
|
+
return line(await scope.tasks.unassign(a.id, by, true, a.role, a.revision));
|
|
546
|
+
}
|
|
547
|
+
if (op === "roadmap_sync" || op === "roadmap_export") {
|
|
548
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.hasOwn(a, "apply") || Object.hasOwn(a, "confirm")) throw new PreEffectToolRefusal("roadmap preview accepts no apply or confirmation fields");
|
|
549
|
+
return JSON.stringify(op === "roadmap_sync" ? await scope.tasks.roadmapSync(by, a) : await scope.tasks.roadmapExport(by, a));
|
|
550
|
+
}
|
|
551
|
+
if (by !== USER && !(Object.hasOwn(CONDUCTOR_TASK_OPS, op) && scope.operationalContext.getStore()?.actor === by)) throw new Error(`${op} is a console command`);
|
|
552
|
+
return taskOpPart2(scope, by, op, a, inProcess, piiTurn, toolSocket, onPrem, line, need);
|
|
553
|
+
}
|