@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,114 @@
|
|
|
1
|
+
// #1830 S2d: exact control message labels, with shared handlers for the original case groups.
|
|
2
|
+
import { titleMessage, queueMessage, deliveryHoldsMessage, deliveryReceiptMessage, inboxMessage, deliveryCompleteMessage, sendMessage, askMessage } from "./delivery-messages.ts";
|
|
3
|
+
import { silencedMessage, watchMessage, tailMessage, uiMessage, statusMessage, cliAuditAckMessage, uiSnapshotMessage, uiActionMessage, autonomyMessage, modelMessage, settingsGetMessage, settingsReloadMessage, settingsPreviewMessage, settingsSetMessage, settingsUndoMessage, configEditGetMessage, configEditPreviewMessage, configEditApplyMessage } from "./dashboard-messages.ts";
|
|
4
|
+
import { peerTakeoverMessage, kimiLaunchEndMessage, terminalLaunchMessage, nativeTuiLaunchMessage, peerStartMessage, peerStopMessage, startMessage, resumeMessage, killMessage } from "./peer-messages.ts";
|
|
5
|
+
import { roomMessage, budgetRenewMessage, budgetMessage, usageMessage, permitMessage, answerMessage, questionsMessage, resultSeenMessage, resultsMessage, worktreesRefreshPrsMessage } from "./operations-messages.ts";
|
|
6
|
+
import { nativeHookLaunchMessage, nativeFactsMessage, instructionExecuteMessage, instructionHookMessage, factsMessage } from "./native-messages.ts";
|
|
7
|
+
import { requestCancelMessage, permissionFailureProbeMessage, permissionRequestMessage, permissionDefaultMessage, permissionMessage, executionBudgetMessage, recoveryRestoreMessage, recoveryAuthorityMessage, recoveryMessage } from "./recovery-messages.ts";
|
|
8
|
+
import { boardRevision, conductorOperational, goalLink, guidanceMessage, guidanceProbeMessage, lineageMessage, reviewBlob, reviewCommentWrite, reviewCommentsRead, taskCatalogRole, taskHandoff, taskHandoffByKey, taskHandoffEvent, taskHandoffStates, taskMessage } from "./board-messages.ts";
|
|
9
|
+
import { sdlcMessage } from "./sdlc-messages.ts";
|
|
10
|
+
import type { ControlMessage, DaemonScope } from "./scope.ts";
|
|
11
|
+
|
|
12
|
+
const handlers = Object.freeze({
|
|
13
|
+
request_cancel: requestCancelMessage,
|
|
14
|
+
permission_failure_probe: permissionFailureProbeMessage,
|
|
15
|
+
permission_request: permissionRequestMessage,
|
|
16
|
+
conductor_operational: conductorOperational,
|
|
17
|
+
permission_default: permissionDefaultMessage,
|
|
18
|
+
permission: permissionMessage,
|
|
19
|
+
title: titleMessage,
|
|
20
|
+
queue: queueMessage,
|
|
21
|
+
delivery_holds: deliveryHoldsMessage,
|
|
22
|
+
delivery_receipt: deliveryReceiptMessage,
|
|
23
|
+
inbox: inboxMessage,
|
|
24
|
+
delivery_complete: deliveryCompleteMessage,
|
|
25
|
+
execution_budget: executionBudgetMessage,
|
|
26
|
+
recovery_restore: recoveryRestoreMessage,
|
|
27
|
+
recovery_authority: recoveryAuthorityMessage,
|
|
28
|
+
recovery: recoveryMessage,
|
|
29
|
+
send: sendMessage,
|
|
30
|
+
native_hook_launch: nativeHookLaunchMessage,
|
|
31
|
+
native_facts: nativeFactsMessage,
|
|
32
|
+
instruction_execute: instructionExecuteMessage,
|
|
33
|
+
instruction_hook: instructionHookMessage,
|
|
34
|
+
facts: factsMessage,
|
|
35
|
+
silenced: silencedMessage,
|
|
36
|
+
watch: watchMessage,
|
|
37
|
+
tail: tailMessage,
|
|
38
|
+
ui: uiMessage,
|
|
39
|
+
sdlc: sdlcMessage,
|
|
40
|
+
room: roomMessage,
|
|
41
|
+
status: statusMessage,
|
|
42
|
+
peer_takeover: peerTakeoverMessage,
|
|
43
|
+
cli_audit_ack: cliAuditAckMessage,
|
|
44
|
+
review_comment_put: reviewCommentWrite,
|
|
45
|
+
review_comment_delete: reviewCommentWrite,
|
|
46
|
+
review_comment_send: reviewCommentWrite,
|
|
47
|
+
review_comments: reviewCommentsRead,
|
|
48
|
+
review_blob: reviewBlob,
|
|
49
|
+
ui_snapshot: uiSnapshotMessage,
|
|
50
|
+
ui_action: uiActionMessage,
|
|
51
|
+
task_catalog_role: taskCatalogRole,
|
|
52
|
+
autonomy: autonomyMessage,
|
|
53
|
+
guidance_list: guidanceMessage,
|
|
54
|
+
guidance_show: guidanceMessage,
|
|
55
|
+
guidance_create: guidanceMessage,
|
|
56
|
+
guidance_withdraw: guidanceMessage,
|
|
57
|
+
guidance_probe_register: guidanceProbeMessage,
|
|
58
|
+
guidance_probe_start: guidanceProbeMessage,
|
|
59
|
+
guidance_probe_show: guidanceProbeMessage,
|
|
60
|
+
guidance_probe_receipts: guidanceProbeMessage,
|
|
61
|
+
guidance_probe_cancel: guidanceProbeMessage,
|
|
62
|
+
lineage_show: lineageMessage,
|
|
63
|
+
lineage_link: lineageMessage,
|
|
64
|
+
model: modelMessage,
|
|
65
|
+
settings_get: settingsGetMessage,
|
|
66
|
+
settings_reload: settingsReloadMessage,
|
|
67
|
+
settings_preview: settingsPreviewMessage,
|
|
68
|
+
settings_set: settingsSetMessage,
|
|
69
|
+
settings_undo: settingsUndoMessage,
|
|
70
|
+
config_edit_get: configEditGetMessage,
|
|
71
|
+
config_edit_preview: configEditPreviewMessage,
|
|
72
|
+
config_edit_apply: configEditApplyMessage,
|
|
73
|
+
kimi_launch_end: kimiLaunchEndMessage,
|
|
74
|
+
terminal_launch: terminalLaunchMessage,
|
|
75
|
+
native_tui_launch: nativeTuiLaunchMessage,
|
|
76
|
+
peer_start: peerStartMessage,
|
|
77
|
+
peer_stop: peerStopMessage,
|
|
78
|
+
start: startMessage,
|
|
79
|
+
task: taskMessage,
|
|
80
|
+
pause: resumeMessage,
|
|
81
|
+
resume: resumeMessage,
|
|
82
|
+
goal_link: goalLink,
|
|
83
|
+
ask: askMessage,
|
|
84
|
+
budget_renew: budgetRenewMessage,
|
|
85
|
+
budget: budgetMessage,
|
|
86
|
+
usage: usageMessage,
|
|
87
|
+
permit: permitMessage,
|
|
88
|
+
answer: answerMessage,
|
|
89
|
+
questions: questionsMessage,
|
|
90
|
+
// #1635: the board's write counter alone, for acon's revision polling. A console-role read of one bare number: no task, title or text, and no board write. An older hub answers an unknown message with ok:false, which the plugin maps to "0" (always fetch).
|
|
91
|
+
board_revision: boardRevision,
|
|
92
|
+
result_seen: resultSeenMessage,
|
|
93
|
+
results: resultsMessage,
|
|
94
|
+
kill: killMessage,
|
|
95
|
+
worktrees: worktreesRefreshPrsMessage,
|
|
96
|
+
worktree_override_set: worktreesRefreshPrsMessage,
|
|
97
|
+
worktree_override_clear: worktreesRefreshPrsMessage,
|
|
98
|
+
worktrees_refresh_prs: worktreesRefreshPrsMessage,
|
|
99
|
+
// #604 (agent-hub#1030): another project's daemon hands us a task, or reports a state change of one we handed it. Console role only (the same token and the same machine user as every
|
|
100
|
+
// control message): an agent connection never reaches these. The origin peer named in the request is a record, never an identity here, and nothing in it grants a role.
|
|
101
|
+
task_handoff: taskHandoff,
|
|
102
|
+
task_handoff_event: taskHandoffEvent,
|
|
103
|
+
task_handoff_by_key: taskHandoffByKey,
|
|
104
|
+
task_handoff_states: taskHandoffStates,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export function dispatchControlMessage(scope: DaemonScope, message: ControlMessage): void {
|
|
108
|
+
const { msg, reply } = message;
|
|
109
|
+
const type = msg.t;
|
|
110
|
+
const handle = typeof type === "string" && Object.hasOwn(handlers, type) ? handlers[type as keyof typeof handlers] : undefined;
|
|
111
|
+
if (handle) return handle(scope, message);
|
|
112
|
+
// A newer CLI talking to an older hub must get an answer, not wait forever.
|
|
113
|
+
if (msg.rid !== undefined) reply({ t: String(msg.t), ok: false, error: `this hub does not know "${msg.t}" (restart it: ahub kill && ahub up)` });
|
|
114
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// #1830 S2a: the closures only `taskOpBody` used, with the daemon's scope as their first parameter.
|
|
2
|
+
import { registeredProjects } from "../../cli/upgrade.ts";
|
|
3
|
+
import { ensureMlx } from "../../models/mlx.ts";
|
|
4
|
+
import { parseRemotePeerId } from "../../rooms/application.ts";
|
|
5
|
+
import { type Task } from "../board.ts";
|
|
6
|
+
import { ControlClient, HANDOFF_CONNECT_MS, HANDOFF_REQUEST_MS, readControl } from "../control-client.ts";
|
|
7
|
+
import { HUB, USER, newEnvelope, sanitize, type Envelope, type PeerId } from "../envelope.ts";
|
|
8
|
+
import { HandoffRefusal, checkTarget, handoffAge, handoffConnectFailure, handoffOutcomeUnknown, handoffReach, parseHandoff, resolveTarget } from "../handoff.ts";
|
|
9
|
+
import { DIGEST, screenPii } from "../inference.ts";
|
|
10
|
+
import { isReviewObserverExcluded } from "../memory-policy.ts";
|
|
11
|
+
import { memoryReviewCountLine } from "../memory-review.ts";
|
|
12
|
+
import { canonicalPath, hubHome } from "../project.ts";
|
|
13
|
+
import { structureNotice } from "../structure-budget.ts";
|
|
14
|
+
import { readStructureBaseline, scanStructure } from "../structure-scan.ts";
|
|
15
|
+
import { PreEffectToolRefusal } from "../tool-refusal.ts";
|
|
16
|
+
import { resolveVisualAssets } from "../visual-assets.ts";
|
|
17
|
+
import { type VisualRecord, validateVisualInput, validateVisualPayload } from "../visual.ts";
|
|
18
|
+
import { randomUUID } from "node:crypto";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import type { DaemonScope, VisualFilePolicy } from "./scope.ts";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export function planStructureNotice(scope: DaemonScope, task: Task): string | undefined {
|
|
24
|
+
try {
|
|
25
|
+
const rules = scope.readSdlcFile().structure;
|
|
26
|
+
if (!rules) return;
|
|
27
|
+
const plan = scope.tasks.publicView(task).plan as { paths?: string[] } | undefined;
|
|
28
|
+
if (!plan?.paths?.length) return;
|
|
29
|
+
const baseline = readStructureBaseline(join(scope.opts.cwd, rules.baseline));
|
|
30
|
+
if (!baseline) return;
|
|
31
|
+
const paths = plan.paths.filter(path => Object.hasOwn(baseline.sizes, path));
|
|
32
|
+
if (!paths.length) return;
|
|
33
|
+
return structureNotice(rules, baseline, scanStructure(scope.opts.cwd, { ...rules, roots: paths, shared: [] }), paths);
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** #520: a task under review shows its review brief to whoever may read it (owner, reviewer, conductor). */
|
|
39
|
+
export const briefField = (scope: DaemonScope, task: Task): { brief?: string } => { if (task.state !== "in_review") return {}; const text = scope.tasks.briefText(task); return text ? { brief: text } : {}; };
|
|
40
|
+
/** #223 R2: a review-only instance reads the spec, refs and earlier verdicts of a task, never the builder's narrative. */
|
|
41
|
+
export const reviewerView = (scope: DaemonScope, peer: string, view: Record<string, unknown>): Record<string, unknown> => {
|
|
42
|
+
if (!scope.reviewOnlyPeer(peer) || !Array.isArray(view.history)) return view;
|
|
43
|
+
const task = typeof view.id === "number" && Number.isSafeInteger(view.id) ? scope.board.get(view.id) : undefined;
|
|
44
|
+
// Public task views retain full original history order. A filtered/stale view cannot prove an original index.
|
|
45
|
+
const history = view.history as { event?: unknown; note?: unknown; by?: unknown; at?: unknown }[];
|
|
46
|
+
const rulings = new Map((task && history.length === task.history.length ? scope.tasks.plannerRulings(task, peer) : []).map(ruling => [ruling.historyIndex, ruling]));
|
|
47
|
+
return { ...view, history: history.map(({ note, ...entry }, historyIndex) => {
|
|
48
|
+
if (entry.event === "approved" || entry.event === "changes_requested") return { ...entry, note };
|
|
49
|
+
const ruling = rulings.get(historyIndex), original = task?.history[historyIndex];
|
|
50
|
+
return ruling && original && entry.event === "plan reviewed" && entry.by === original.by && entry.at === original.at
|
|
51
|
+
? { ...entry, note: ruling.note } : entry;
|
|
52
|
+
}) };
|
|
53
|
+
};
|
|
54
|
+
export const checkpointRefusalMessage = (scope: DaemonScope, cause?: string) => cause
|
|
55
|
+
? `checkpoint refused because ${cause}; read the move or cancel notice and call hub_task_list before answering a fresh checkpoint request`
|
|
56
|
+
: "checkpoint request expired or absent; read pending notices and wait for a fresh checkpoint request";
|
|
57
|
+
export const reviewCount = (scope: DaemonScope, task: number, field: "notes" | "corrections" | "remembered", by = 1): void => {
|
|
58
|
+
const row = scope.reviewCounts.get(task) ?? { notes: 0, corrections: 0, remembered: 0 };
|
|
59
|
+
row[field] += by; scope.reviewCounts.set(task, row);
|
|
60
|
+
};
|
|
61
|
+
export const reviewCountLine = (scope: DaemonScope, card: Task): string => memoryReviewCountLine({ ...(scope.reviewCounts.get(card.id) ?? { notes: 0, corrections: 0, remembered: 0 }), tokens: scope.reviewCountedTokens([card.id]) });
|
|
62
|
+
/**
|
|
63
|
+
* #1329 AC3: the review card the caller's current turn is bound to. The turn's own attribution names it: the card is
|
|
64
|
+
* delivered to its owner, `Tasks.ownerTurnTasks` excludes a `review` card, and a call made outside that turn - the
|
|
65
|
+
* reviewer's, or the owner's work on another task - is not in the review's scope.
|
|
66
|
+
*/
|
|
67
|
+
export const reviewTurnCard = (scope: DaemonScope, by: PeerId): Task | undefined => scope.tasks.reviewCardFor(by, scope.turns.get(by)?.attribution.task);
|
|
68
|
+
/**
|
|
69
|
+
* #734 (AC6): the person's list of handoffs this project made, each with its age since the last report and whether its target can be reached now: `reachable`, `unreachable` with the cause
|
|
70
|
+
* (the last failure this hub logged, else what the registry and the target's descriptor say) or `moved` (the project id is not in the registry). Read from the registry and the descriptor
|
|
71
|
+
* files only: a list never opens a connection, so it answers at once and a slow target cannot hold it.
|
|
72
|
+
*/
|
|
73
|
+
export const handoffListView = (scope: DaemonScope) => {
|
|
74
|
+
const now = Date.now(), projects = registeredProjects(hubHome());
|
|
75
|
+
return scope.tasks.handoffList().map(row => {
|
|
76
|
+
const project = projects.find(candidate => candidate.id === row.remoteProject);
|
|
77
|
+
const descriptor = project && readControl(project.stateDir);
|
|
78
|
+
const failure = scope.handoffFailures.get(row.remoteProject);
|
|
79
|
+
const reach = handoffReach({ registered: project !== undefined, descriptor: descriptor && { ...(descriptor.features ? { features: descriptor.features } : {}) }, ...(failure ? { lastFailure: failure.cause } : {}) });
|
|
80
|
+
return { ...row, age: handoffAge(now - row.updatedAt), ageMs: Math.max(0, now - row.updatedAt), ...reach };
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* #604 ORIGIN side. Order matters: the caller's authority and the PII gates run first (nothing has left this project), then the target is resolved from the machine registry and its own
|
|
85
|
+
* status descriptor is read, and only then is the request sent. The target answers with the task id it created, which is recorded here. A refusal at any step leaves no row in either board.
|
|
86
|
+
*/
|
|
87
|
+
export async function handoffOut(scope: DaemonScope, by: PeerId, input: unknown): Promise<{ project: string; task: number; state: string; note?: string }> {
|
|
88
|
+
const request = parseHandoff(input);
|
|
89
|
+
const own = request.task === undefined ? undefined : scope.board.get(request.task);
|
|
90
|
+
if (request.task !== undefined && !own) throw new HandoffRefusal("invalid", `no task #${request.task} in this project to hand off from`);
|
|
91
|
+
scope.tasks.handoffOutAuthority(by, own);
|
|
92
|
+
const self = { id: scope.projectId, root: scope.opts.cwd };
|
|
93
|
+
const target = resolveTarget(request.project, registeredProjects(hubHome()).map(project => ({ id: project.id, root: project.root, stateDir: project.stateDir })), self, canonicalPath);
|
|
94
|
+
const descriptor = readControl(target.stateDir);
|
|
95
|
+
checkTarget(target, descriptor && { ...(descriptor.features ? { features: descriptor.features } : {}), ...(descriptor.projectId ? { projectId: descriptor.projectId } : {}) });
|
|
96
|
+
// #731 (agent-hub#1203): the request carries a key this origin minted (or the caller passed to retry), so the target files it once however many times it arrives. Only a target that advertises
|
|
97
|
+
// `task_handoff_key` is sent one: an older target refuses the unknown field, and keeps today's behavior without it.
|
|
98
|
+
const keyed = descriptor!.features?.includes("task_handoff_key") === true;
|
|
99
|
+
const { project: _project, task: originTask, handoffKey: given, ...body } = request;
|
|
100
|
+
const key = keyed ? given ?? randomUUID() : undefined;
|
|
101
|
+
const requestMs = scope.opts.handoffRequestMs ?? HANDOFF_REQUEST_MS;
|
|
102
|
+
const attempt = async (): Promise<{ reply: any } | { unreachable: unknown }> => {
|
|
103
|
+
let client: ControlClient;
|
|
104
|
+
try { client = await ControlClient.connect(target.stateDir, { role: "console", projectRoot: descriptor!.cwd ?? target.root }, HANDOFF_CONNECT_MS); }
|
|
105
|
+
catch (error) { return { unreachable: error }; }
|
|
106
|
+
try { return { reply: await client.request({ t: "task_handoff", origin: { projectId: scope.projectId, peer: by, ...(originTask === undefined ? {} : { taskId: originTask }) }, request: key === undefined ? body : { ...body, handoffKey: key } }, requestMs) }; }
|
|
107
|
+
finally { client.close(); }
|
|
108
|
+
};
|
|
109
|
+
const result = await attempt();
|
|
110
|
+
if ("unreachable" in result) {
|
|
111
|
+
// #734 (H8): a wire-version or instance-pin refusal is named for what it is, with the target's upgrade step, and never reported as "not running".
|
|
112
|
+
const failure = handoffConnectFailure(result.unreachable, target);
|
|
113
|
+
scope.handoffLog(target.id, failure.cause, `handoff to ${target.id} failed: ${failure.cause}`);
|
|
114
|
+
throw new HandoffRefusal(failure.code, failure.message);
|
|
115
|
+
}
|
|
116
|
+
// A timeout or a closed connection is not a refusal: the target may have written the task. With a key the same request is sent once more (the target answers a key it has with its task);
|
|
117
|
+
// then the target is asked by key, and only then is the outcome reported as unknown, naming the key to retry with. The first attempt keeps running on the target after the origin stopped waiting, so
|
|
118
|
+
// a refusal of the RESEND settles nothing about it (the resend's PII screen may refuse while the first one's still pending and later files the task): it is kept as a note, and the lookup still runs.
|
|
119
|
+
let reply = result.reply, resendRefused: string | undefined;
|
|
120
|
+
if (key !== undefined && handoffOutcomeUnknown(reply)) {
|
|
121
|
+
const again = await attempt();
|
|
122
|
+
if ("reply" in again) {
|
|
123
|
+
if (again.reply.ok === true || handoffOutcomeUnknown(again.reply)) reply = again.reply;
|
|
124
|
+
else resendRefused = sanitize(String(again.reply.error ?? "the resend was refused")).slice(0, 160);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (key !== undefined && handoffOutcomeUnknown(reply)) {
|
|
128
|
+
const found = await scope.handoffStateByKey(target, descriptor!.cwd ?? target.root, key);
|
|
129
|
+
if (found) reply = { ok: true, task: found.task, state: found.state, byKey: found };
|
|
130
|
+
}
|
|
131
|
+
if (handoffOutcomeUnknown(reply)) {
|
|
132
|
+
const cause = sanitize(String(reply.error)).slice(0, 120) + (resendRefused ? `; the resend was refused: ${resendRefused}` : "");
|
|
133
|
+
throw new HandoffRefusal("outcome_unknown", key === undefined
|
|
134
|
+
? `the hub of ${target.id} did not confirm the handoff (${cause}); it may exist on its board: check \`ahub board\` there before handing it off again. That hub is too old to take a handoff key (run \`ahub upgrade\` in ${target.root}), so a retry could file a second task`
|
|
135
|
+
: `the hub of ${target.id} did not confirm the handoff (${cause}); it may exist on its board. Retry with the same key and it is filed once: --key ${key} (handoffKey ${key} in hub_task_handoff)`);
|
|
136
|
+
}
|
|
137
|
+
if (!reply.ok) {
|
|
138
|
+
const text = sanitize(String(reply.error ?? "the target refused the handoff")).slice(0, 300);
|
|
139
|
+
// #1175: a target from before the duplicate check refuses the new field as unknown; name the step instead of repeating its closed-shape error.
|
|
140
|
+
if (request.duplicate_ok !== undefined && /unknown field: duplicate_ok/.test(text)) throw new HandoffRefusal("older_target", `the hub of ${target.id} predates duplicate_ok: run \`ahub upgrade\` in ${target.root}, or hand the task off without duplicate_ok`);
|
|
141
|
+
throw new HandoffRefusal("invalid", text);
|
|
142
|
+
}
|
|
143
|
+
const remote = Number(reply.task);
|
|
144
|
+
if (!Number.isSafeInteger(remote) || remote < 1) throw new HandoffRefusal("invalid", "the target answered without a task id");
|
|
145
|
+
scope.tasks.handoffSent(by, { projectId: target.id }, remote, request.title, request.task);
|
|
146
|
+
// An answer that came from the by-key lookup, or a replay, may already be past "proposed": record where the target says it stands, so the origin is not behind until some later event.
|
|
147
|
+
const known = reply.byKey ?? (reply.replayed === true ? await scope.handoffStateByKey(target, descriptor!.cwd ?? target.root, key) : undefined);
|
|
148
|
+
if (known && known.state !== "proposed") scope.tasks.handoffCaughtUp(target.id, [known]);
|
|
149
|
+
return { project: target.id, task: remote, state: String(reply.state ?? "proposed"), ...(typeof reply.note === "string" && reply.note ? { note: sanitize(reply.note).slice(0, 300) } : {}) };
|
|
150
|
+
}
|
|
151
|
+
// Routing can skip a sandboxed owner that needs the issue. The board's read-only tools remain available while auth is probed.
|
|
152
|
+
export const specRoutingOps = new Set(["hub_task_propose", "hub_task_accept", "hub_task_decline", "hub_task_cancel", "hub_task_wait",
|
|
153
|
+
"hub_roadmap_decompose", "hub_backlog_pull", "hub_backlog_split", "task_assign", "task_assign_checked", "task_unassign", "task_escalate", "route_explain"]);
|
|
154
|
+
export async function visualTool(scope: DaemonScope, by: PeerId, op: string, a: Record<string, unknown>, piiTurn: boolean): Promise<string> {
|
|
155
|
+
if (!a || typeof a !== "object" || Array.isArray(a)) throw new PreEffectToolRefusal("visual arguments must be an object; retry with the documented fields");
|
|
156
|
+
const authority = scope.childToolAuthority.getStore();
|
|
157
|
+
const actor = (publishing: boolean) => {
|
|
158
|
+
if (scope.stopping) throw scope.visualOperational("stopping");
|
|
159
|
+
let current = false;
|
|
160
|
+
try { current = !authority || authority.by === by && authority.current(); } catch { /* stale authority */ }
|
|
161
|
+
if (!current) throw scope.visualOperational("authority");
|
|
162
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by)) throw scope.visualUnavailable();
|
|
163
|
+
if (!scope.membershipAllowed(by)) throw scope.visualOperational("membership");
|
|
164
|
+
if (!publishing) return;
|
|
165
|
+
if (scope.recoveryActive() || scope.bus.isRecoveryHeld) throw scope.visualOperational("recovery");
|
|
166
|
+
if (scope.readOnlyPeer(by) || !scope.may(by, "remember")) throw scope.visualOperational("role");
|
|
167
|
+
if (scope.reviewObserverHeld(by) || scope.bus.lastDeliveredTo(by).some(isReviewObserverExcluded)) throw scope.visualOperational("observer");
|
|
168
|
+
if (!scope.bus.deliveryJournalAvailable()) throw scope.visualOperational("storage");
|
|
169
|
+
};
|
|
170
|
+
actor(op !== "hub_visual_show");
|
|
171
|
+
if (op === "hub_visual_show") {
|
|
172
|
+
if (Object.keys(a).some(key => key !== "id")) throw new PreEffectToolRefusal("visual show takes only id; retry with a visual id");
|
|
173
|
+
const record = scope.visualRecord(a.id, scope.visualFilePolicy());
|
|
174
|
+
if (!record) throw scope.visualUnavailable();
|
|
175
|
+
return JSON.stringify(scope.visualView(record));
|
|
176
|
+
}
|
|
177
|
+
if (Object.keys(a).some(key => !["payload", "task", "to"].includes(key))) throw new PreEffectToolRefusal("visual has an unsupported field; use payload, task and to only");
|
|
178
|
+
if (a.task !== undefined && (!Number.isSafeInteger(a.task) || Number(a.task) < 1)) throw new PreEffectToolRefusal("visual task must be a positive integer; retry with a task id");
|
|
179
|
+
const task = a.task as number | undefined, before = task === undefined ? undefined : scope.board.get(task);
|
|
180
|
+
if (task !== undefined && !before) throw new PreEffectToolRefusal("visual task is unavailable; choose an existing public task and retry");
|
|
181
|
+
const generation = scope.connectionGeneration(by), turn = scope.turns.get(by);
|
|
182
|
+
const policyVersion = (filePolicy: VisualFilePolicy) => JSON.stringify({ revision: scope.configRevision, filePolicy, pii: scope.config.pii, deny: scope.config.local.deny, signals: scope.activeRouting().signals, constraints: scope.activeRouting().constraints, mlx: scope.config.mlx, model: scope.activeRouting().local.fixed_model });
|
|
183
|
+
const initialPolicy = scope.visualFilePolicy(), policy = policyVersion(initialPolicy);
|
|
184
|
+
const current = (): VisualFilePolicy => {
|
|
185
|
+
actor(true);
|
|
186
|
+
const filePolicy = scope.visualFilePolicy();
|
|
187
|
+
if (policyVersion(filePolicy) !== policy || scope.connectionGeneration(by) !== generation || scope.turns.get(by) !== turn)
|
|
188
|
+
throw scope.visualOperational("concurrency");
|
|
189
|
+
if (task !== undefined) {
|
|
190
|
+
const now = scope.board.get(task);
|
|
191
|
+
if (!before || !now || now.created !== before.created || now.updated !== before.updated || now.history.length !== before.history.length)
|
|
192
|
+
throw scope.visualOperational("concurrency");
|
|
193
|
+
}
|
|
194
|
+
if (!scope.visualTaskPublic(task, filePolicy)) throw scope.visualUnavailable();
|
|
195
|
+
return filePolicy;
|
|
196
|
+
};
|
|
197
|
+
current();
|
|
198
|
+
const recipients = typeof a.to === "string" && a.to.length ? [a.to] : a.to;
|
|
199
|
+
if (a.to !== undefined && (!Array.isArray(recipients) || recipients.some(id => typeof id !== "string" || !id.length)))
|
|
200
|
+
throw new PreEffectToolRefusal("visual to must be a peer id or array of peer ids; retry with local recipients");
|
|
201
|
+
const to = a.to === undefined ? [USER] : Array.isArray(recipients) && recipients.length ? [...new Set(recipients as string[])] : scope.bus.knownPeers().filter(id => !parseRemotePeerId(id));
|
|
202
|
+
if (to.some(id => id !== USER && (!scope.bus.knownPeers().includes(id) || parseRemotePeerId(id)))) throw new PreEffectToolRefusal("visual recipient unavailable; choose a known local peer or user and retry");
|
|
203
|
+
const id = randomUUID(), priority = a.to === undefined ? "fyi" : "status";
|
|
204
|
+
const early = newEnvelope(by, `[visual ${id}]`, { priority, to, refs: { visual: id, ...(task === undefined ? {} : { task: String(task) }) } });
|
|
205
|
+
const preflight = (stub: Envelope, dry: boolean) => {
|
|
206
|
+
try { scope.bus.checkRemotePublication(stub); } catch { throw new PreEffectToolRefusal("visual delivery unavailable; choose local recipients and retry"); }
|
|
207
|
+
const offRoster = scope.bus.offRosterRecipients(stub).filter(peer => peer !== USER);
|
|
208
|
+
const audience = new Set(stub.to?.filter(peer => peer !== by && peer !== USER));
|
|
209
|
+
if (offRoster.length && offRoster.length === audience.size) throw new PreEffectToolRefusal("visual recipients are off roster; choose an available local peer and retry");
|
|
210
|
+
const hushed = scope.bus.hushed(stub);
|
|
211
|
+
if (hushed.length && hushed.length === scope.bus.audience(stub).length) throw new PreEffectToolRefusal("visual delivery is held by the current silence policy; wait for the hold to clear");
|
|
212
|
+
const effective = offRoster.length ? { ...stub, to: stub.to!.filter(peer => !offRoster.includes(peer)) } : stub;
|
|
213
|
+
const refused = dry
|
|
214
|
+
? (by === USER || by === HUB || by === DIGEST || stub.priority === "fyi" ? undefined : scope.limiter.peek(by, effective.to, effective.priority, effective.body))
|
|
215
|
+
: scope.admit(effective);
|
|
216
|
+
if (refused) throw new PreEffectToolRefusal("visual delivery is rate limited; wait before retrying");
|
|
217
|
+
};
|
|
218
|
+
// No screen, image read, or consuming admission has occurred at this point.
|
|
219
|
+
preflight(early, true);
|
|
220
|
+
const input = validateVisualInput(a.payload, text => scope.visualSafeText(text, initialPolicy));
|
|
221
|
+
if (scope.tasks.screenOn()) {
|
|
222
|
+
const screen = scope.opts.piiScreen ?? ((value: string) => screenPii(value, { ...(scope.config.mlx.enabled === false ? {} : { device: () => ensureMlx(scope.config.mlx) }), onCampus: scope.onCampus, omni: scope.omni, fixedModel: () => scope.activeRouting().local.fixed_model }));
|
|
223
|
+
const verdict = await screen(JSON.stringify(input)).catch(() => undefined);
|
|
224
|
+
current();
|
|
225
|
+
if (verdict?.label === "pii") throw scope.visualUnavailable();
|
|
226
|
+
if (verdict?.label !== "clear") throw scope.visualOperational("screen");
|
|
227
|
+
}
|
|
228
|
+
const beforeRead = current(), resolved = await resolveVisualAssets(input, id, scope.visualPorts(beforeRead));
|
|
229
|
+
const finalPolicy = current();
|
|
230
|
+
const payload = validateVisualPayload(resolved.payload, text => scope.visualSafeText(text, finalPolicy));
|
|
231
|
+
const title = "title" in payload ? payload.title ?? "" : "caption" in payload ? payload.caption ?? "" : "";
|
|
232
|
+
const record: VisualRecord = { id, ...(task === undefined ? {} : { task }), from: by, kind: payload.kind, title, payload, files: resolved.files, created: Date.now() };
|
|
233
|
+
if (!scope.visualPublic(record, finalPolicy) || resolved.files.some(file => !scope.visualPathPublic(file.path, finalPolicy))) throw scope.visualUnavailable();
|
|
234
|
+
const stub = newEnvelope(by, `[visual ${id}] ${payload.kind}: ${sanitize(title)}`, { priority, to, refs: { visual: id, ...(task === undefined ? {} : { task: String(task) }) } });
|
|
235
|
+
preflight(stub, false); // Recheck after every await; consume shared admission exactly once.
|
|
236
|
+
if (!scope.recoveryActive() && !scope.bus.isRecoveryHeld) scope.visuals.prune(scope.config.visuals.retention_days, Date.now(), task => !!scope.board.get(task));
|
|
237
|
+
scope.visuals.insert(record);
|
|
238
|
+
try {
|
|
239
|
+
scope.event({ type: "visual", id, kind: payload.kind, bytes: Buffer.byteLength(JSON.stringify(payload)), files: resolved.files.length, ...(task === undefined ? {} : { task }) });
|
|
240
|
+
scope.bus.publish(stub);
|
|
241
|
+
} catch { throw new Error(`visual ${id} was stored but its stub delivery failed; inspect the visual before posting again`); }
|
|
242
|
+
return `visual ${id}`;
|
|
243
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// #1830 S2a: the `hub_*` tool dispatch moved out of startDaemon. Every name it read from the daemon's scope is a field of `scope` (src/hub/control/scope.ts).
|
|
2
|
+
import { conductorPeer } from "../conductor.ts";
|
|
3
|
+
import { USER, type PeerId } from "../envelope.ts";
|
|
4
|
+
import { parseGuidanceCreateInput, parseGuidanceIdQuery } from "../guidance-variants.ts";
|
|
5
|
+
import { BOUNDED_TASK_TOOLS, CONDUCTOR_TOOL_NAMES, GUIDANCE_TOOL_NAMES, LINEAGE_TOOL_NAMES } from "../hub-tools.ts";
|
|
6
|
+
import { correctionInput } from "../memory-candidates.ts";
|
|
7
|
+
import { isReviewObserverExcluded, reviewCaptureExcluded } from "../memory-policy.ts";
|
|
8
|
+
import { memoryReviewScope } from "../memory-review.ts";
|
|
9
|
+
import { MEMORY_READ_TOOLS, validateMemoryRead } from "../read-tools.ts";
|
|
10
|
+
import { PreEffectToolRefusal } from "../tool-refusal.ts";
|
|
11
|
+
import type { Sock } from "../daemon.ts";
|
|
12
|
+
import type { DaemonScope } from "./scope.ts";
|
|
13
|
+
import { briefField, reviewTurnCard, reviewerView, specRoutingOps, visualTool } from "./hub-tool-helpers.ts";
|
|
14
|
+
import { taskOpPart1 } from "./task-ops.ts";
|
|
15
|
+
|
|
16
|
+
export async function taskOpBody(scope: DaemonScope, by: PeerId, op: string, a: Record<string, any>, inProcess = false, piiTurn = false, toolSocket?: Sock): Promise<string> {
|
|
17
|
+
if (scope.startupSpecPending() && specRoutingOps.has(op)) {
|
|
18
|
+
await scope.firstSpecProbe;
|
|
19
|
+
// refusal:by-design world-action: routing is held by the hub until it finishes stopping or recovering.
|
|
20
|
+
if (scope.stopping || scope.recoveryActive()) throw new PreEffectToolRefusal("task routing is held by recovery or shutdown");
|
|
21
|
+
}
|
|
22
|
+
if (op === "hub_visual" || op === "hub_visual_show") return visualTool(scope, by, op, a, piiTurn);
|
|
23
|
+
// #1646 T3: a brief file read is the reviewer's read of the commit it approves. A PII or private turn reads none: its words
|
|
24
|
+
// may carry the PII, and the file body would be a second carrier of it.
|
|
25
|
+
if (op === "hub_review_file") {
|
|
26
|
+
// refusal:by-design operator-knowledge: whether this turn is private or PII is the console operator's setting, so no command the caller runs lifts it.
|
|
27
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by)) throw new PreEffectToolRefusal("review brief files are unavailable during a PII or private turn; read them in a turn without the private task");
|
|
28
|
+
return await scope.tasks.reviewFile(by, a);
|
|
29
|
+
}
|
|
30
|
+
const reviewTurn = scope.reviewObserverHeld(by) || scope.bus.lastDeliveredTo(by).some(isReviewObserverExcluded);
|
|
31
|
+
if (reviewTurn || op === "hub_review" && reviewCaptureExcluded(op, JSON.stringify(a))) scope.progress.clearPeer(by);
|
|
32
|
+
if (op === "hub_readback_report") {
|
|
33
|
+
// #1658 T4: the report is the bound reader's; a private, PII or review-observer turn writes none.
|
|
34
|
+
// refusal:by-design operator-knowledge: whether a turn is private, PII or a review observer's is the console operator's setting, so no command the caller runs lifts it.
|
|
35
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by) || reviewTurn || scope.reviewObserverInput(by)) throw new PreEffectToolRefusal("read-back reports are unavailable in private or review input; retry in a public reader turn");
|
|
36
|
+
// refusal:by-design world-action: recovery and shutdown are the hub's own state, released by the hub, so the write waits for that release rather than a caller command.
|
|
37
|
+
if (scope.stopping || scope.recoveryActive() || scope.bus.isRecoveryHeld) throw new PreEffectToolRefusal("recovery or shutdown holds read-back writes; wait for release and retry");
|
|
38
|
+
return JSON.stringify(await scope.tasks.specReadbackReport(by, a, () => scope.stopping || scope.recoveryActive() || scope.bus.isRecoveryHeld ? "read-back write held by recovery or shutdown" : undefined));
|
|
39
|
+
}
|
|
40
|
+
if (op === "hub_survey_report") {
|
|
41
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by) || reviewTurn || scope.reviewObserverInput(by)) throw new PreEffectToolRefusal("survey reports are unavailable in private or review input; retry in a public current-owner context");
|
|
42
|
+
if (scope.stopping || scope.recoveryActive() || scope.bus.isRecoveryHeld) throw new PreEffectToolRefusal("recovery or shutdown holds survey writes; wait for release and retry");
|
|
43
|
+
return JSON.stringify(await scope.tasks.surveyReport(by, a, () => scope.stopping || scope.recoveryActive() || scope.bus.isRecoveryHeld ? "survey write held by recovery or shutdown" : undefined));
|
|
44
|
+
}
|
|
45
|
+
if (op === "hub_audit_report") {
|
|
46
|
+
// #1403 A4, A5: finding text of an open important security finding is the auditor's and a reviewer's to read, never a PII turn's, a review observer's or memory's.
|
|
47
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by) || reviewTurn || scope.reviewObserverInput(by)) throw new PreEffectToolRefusal("audit reports are unavailable in private or review input; retry in a public current-owner context");
|
|
48
|
+
if (scope.stopping || scope.recoveryActive() || scope.bus.isRecoveryHeld) throw new PreEffectToolRefusal("recovery or shutdown is holding audit writes; wait for release and read the audit before retrying");
|
|
49
|
+
return JSON.stringify(await scope.tasks.auditReport(by, a));
|
|
50
|
+
}
|
|
51
|
+
if (GUIDANCE_TOOL_NAMES.has(op)) {
|
|
52
|
+
if (op === "hub_guidance_list" || op === "hub_guidance_show") return JSON.stringify(scope.guidanceRead(by, op === "hub_guidance_list" ? "list" : "show", a, piiTurn));
|
|
53
|
+
const excluded = piiTurn || !!scope.turns.get(by)?.private || scope.contextPii(by) || reviewTurn || scope.reviewObserverInput(by);
|
|
54
|
+
if (excluded) throw new PreEffectToolRefusal("guidance writes are unavailable in private or review input; retry in a public current-owner context");
|
|
55
|
+
if (scope.stopping || scope.recoveryActive() || scope.bus.isRecoveryHeld) throw new PreEffectToolRefusal("recovery or shutdown is holding guidance writes; wait for release and inspect the task before retrying");
|
|
56
|
+
if (op === "hub_guidance_create") {
|
|
57
|
+
let variant; try { variant = parseGuidanceCreateInput(a); } catch { throw new PreEffectToolRefusal("guidance create accepts only a complete bounded V1 variant; remove unknown wrapper fields before retrying"); }
|
|
58
|
+
return JSON.stringify({ ok: true, receipt: await scope.tasks.guidanceVariantCreate(by, variant) });
|
|
59
|
+
}
|
|
60
|
+
let selector; try { selector = parseGuidanceIdQuery(a, true); } catch { throw new PreEffectToolRefusal("guidance withdrawal needs task epoch, current flow and variant id only; refresh the selected task before retrying"); }
|
|
61
|
+
return JSON.stringify({ ok: true, receipt: await scope.tasks.guidanceVariantWithdraw(by, selector) });
|
|
62
|
+
}
|
|
63
|
+
if (LINEAGE_TOOL_NAMES.has(op)) {
|
|
64
|
+
const excluded = piiTurn || !!scope.turns.get(by)?.private || scope.contextPii(by) || reviewTurn || scope.reviewObserverInput(by);
|
|
65
|
+
if (op === "hub_lineage_show") return JSON.stringify(scope.executionLineageRead(by, a, piiTurn));
|
|
66
|
+
if (excluded) throw new PreEffectToolRefusal("execution reference linking is unavailable in a private or review-observer context; retry only in a public task context");
|
|
67
|
+
if (scope.stopping || scope.recoveryActive() || scope.bus.isRecoveryHeld) throw new PreEffectToolRefusal("recovery or shutdown is holding execution reference links; wait for release and retry");
|
|
68
|
+
return JSON.stringify({ ok: true, link: await scope.tasks.linkExecutionReference(by, a) });
|
|
69
|
+
}
|
|
70
|
+
if (op === "hub_ask_answer") {
|
|
71
|
+
if (by === USER || conductorPeer(scope.config.roles) !== by) throw new PreEffectToolRefusal("only the configured conductor may record an instructed answer; the person can use ahub console");
|
|
72
|
+
if (scope.childToolAuthority.getStore()) throw new PreEffectToolRefusal("delegated runs cannot record person answers; use ahub console");
|
|
73
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by) || scope.reviewObserverInput(by)) throw new PreEffectToolRefusal("private or observer context cannot record person answers; use ahub console");
|
|
74
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => !["set", "answers", "instruction"].includes(key))) throw new PreEffectToolRefusal("answer takes set, answers and instruction only; correct the fields or use ahub console");
|
|
75
|
+
const result = scope.questionDesk.instructedAnswer(a.set, a.answers, a.instruction, by);
|
|
76
|
+
if (!result.ok) throw new PreEffectToolRefusal(result.error);
|
|
77
|
+
return JSON.stringify({ ok: true, questionSet: result.row.set, state: result.row.state, actor: by, instructed: true });
|
|
78
|
+
}
|
|
79
|
+
if (op === "hub_ask") {
|
|
80
|
+
// #1053: a structured question for the person. Refused before any row for a read-only instance, a PII turn's own words are marked private by the desk's `isPrivate`.
|
|
81
|
+
if (by === USER) throw new PreEffectToolRefusal("hub_ask is for the agents of this project; the person answers with the console (ahub status shows open questions)");
|
|
82
|
+
if (scope.recoveryActive() || scope.stopping) throw new PreEffectToolRefusal("recovery or shutdown is holding questions; ask again once the hub is back");
|
|
83
|
+
const signal = scope.invocationRequestSignal.getStore()?.signal;
|
|
84
|
+
const result = await scope.questionDesk.ask(by, a, { ...(signal ? { signal } : {}), piiTurn });
|
|
85
|
+
return JSON.stringify(result);
|
|
86
|
+
}
|
|
87
|
+
if (op === "hub_set_title") {
|
|
88
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "title")) return JSON.stringify({ ok: false, reason: "invalid", error: "hub_set_title accepts only title; provide a public name of 1-80 normalized characters" });
|
|
89
|
+
return JSON.stringify(await scope.setSessionTitle(by, a.title, true, piiTurn));
|
|
90
|
+
}
|
|
91
|
+
if (op === "hub_supervision_list" || op === "hub_supervision_accept" || op === "hub_supervision_dismiss") {
|
|
92
|
+
// #1221 T2: the queue carries public board facts only, so a private turn neither reads nor decides one.
|
|
93
|
+
if (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by)) throw new PreEffectToolRefusal("supervision proposals are unavailable during a private or PII turn");
|
|
94
|
+
if (op === "hub_supervision_list") {
|
|
95
|
+
if (a && (typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "task") || a.task !== undefined && (!Number.isSafeInteger(a.task) || a.task < 1)))
|
|
96
|
+
throw new PreEffectToolRefusal("hub_supervision_list takes only an optional task id");
|
|
97
|
+
const rows = await scope.supervisionProposals.read(by, a?.task);
|
|
98
|
+
// `refused` is the queue's own count of readings a bound refused instead of storing: a full queue is visible here.
|
|
99
|
+
return JSON.stringify({ mode: scope.supervisionMode(), proposals: rows.map(scope.proposalView), refused: scope.supervisionProposals.refusedReadings(),
|
|
100
|
+
...(rows.length ? {} : { note: scope.supervisionMode() === "off" ? "supervision is off; a person turns it on with `ahub settings set supervision.mode advisory`" : "no supervision proposal is pending on your tasks" }) });
|
|
101
|
+
}
|
|
102
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => key !== "id") || typeof a.id !== "string")
|
|
103
|
+
throw new PreEffectToolRefusal(`${op} takes only a proposal id`);
|
|
104
|
+
if (scope.stopping || scope.recoveryActive()) throw new PreEffectToolRefusal("recovery or shutdown is holding supervision decisions");
|
|
105
|
+
const decision = await scope.supervisionProposals.decide(by, a.id, op === "hub_supervision_accept" ? "accept" : "dismiss");
|
|
106
|
+
if (!decision.ok) throw new PreEffectToolRefusal(decision.error);
|
|
107
|
+
return JSON.stringify({ ok: true, proposal: scope.proposalView(decision.proposal), ...(decision.receipt ? { receipt: decision.receipt } : {}) });
|
|
108
|
+
}
|
|
109
|
+
if (inProcess && (op === "hub_task_propose" || op === "hub_review") && a && typeof a === "object" && Object.hasOwn(a, "request_id")) throw new PreEffectToolRefusal("request_id replay keys require the control-protocol task transport");
|
|
110
|
+
if (BOUNDED_TASK_TOOLS.has(op)) {
|
|
111
|
+
const keys = op === "hub_task_spec" ? ["id"] : op === "hub_check_start" ? ["id", "check", "files"] : ["run"];
|
|
112
|
+
if (!a || typeof a !== "object" || Array.isArray(a) || Object.keys(a).some(key => !keys.includes(key))
|
|
113
|
+
|| (keys.includes("id") ? !Number.isSafeInteger(a.id) || a.id < 1 : typeof a.run !== "string" || !/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(a.run))) throw new PreEffectToolRefusal("invalid bounded task request");
|
|
114
|
+
if (by !== USER && (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by))) throw new PreEffectToolRefusal("bounded task tools unavailable during a PII turn");
|
|
115
|
+
}
|
|
116
|
+
if (op === "hub_specs" && (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by))) throw new PreEffectToolRefusal("spec inspection unavailable during a private turn");
|
|
117
|
+
// #1329 part 2 (AC3): while a turn is bound to a memory-review card its owner holds, the card's tool scope is enforced
|
|
118
|
+
// here, on every call, before anything is written. The scope is a name rule in `memory-review.ts`; this only decides
|
|
119
|
+
// whether this call runs in the review's turn, and an ordinary turn resolves no card at all.
|
|
120
|
+
if (by !== USER) {
|
|
121
|
+
const reviewCard = reviewTurnCard(scope, by), refused = reviewCard && memoryReviewScope(op);
|
|
122
|
+
if (reviewCard && refused) throw new PreEffectToolRefusal(`task #${reviewCard.id}: ${refused}; read the card with ahub task show ${reviewCard.id}, and run that work in a turn outside this review`);
|
|
123
|
+
}
|
|
124
|
+
if (MEMORY_READ_TOOLS.has(op)) validateMemoryRead(op, a);
|
|
125
|
+
if (op === "hub_memory_correct") correctionInput(a);
|
|
126
|
+
if (op === "hub_task_propose" && by !== USER && (piiTurn || scope.turns.get(by)?.private)) {
|
|
127
|
+
throw new PreEffectToolRefusal("hub_task_propose is not available while working on a PII task: its text must not leave this machine");
|
|
128
|
+
}
|
|
129
|
+
if (CONDUCTOR_TOOL_NAMES.has(op)) {
|
|
130
|
+
if (piiTurn && ["hub_task_assign", "hub_task_escalate", "hub_peer_start"].includes(op)) throw new PreEffectToolRefusal("conductor mutations are unavailable during a PII turn");
|
|
131
|
+
const result = await scope.conductor.execute(by, op, a);
|
|
132
|
+
const shown = op === "hub_task_show" && result && typeof result === "object" ? scope.board.get(Number(a.id)) : undefined;
|
|
133
|
+
return JSON.stringify(shown ? { ...reviewerView(scope, by, result as Record<string, unknown>), ...briefField(scope, shown) } : result);
|
|
134
|
+
}
|
|
135
|
+
// Inside a PII turn the worker's words may carry the PII whatever they are attached to: a note would go to
|
|
136
|
+
// shared memory and a new task could be routed to a cloud peer without matching any pattern.
|
|
137
|
+
if (op === "hub_experiment_record" && (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by))) throw new PreEffectToolRefusal(`${op} is not available while working on a PII task: its text must not leave this machine`);
|
|
138
|
+
if (op === "hub_evidence_record" && (piiTurn || scope.turns.get(by)?.private || scope.contextPii(by))) throw new PreEffectToolRefusal("evidence recording is unavailable in a private or PII context; keep private work on-prem and record only public evidence outside that context");
|
|
139
|
+
if (piiTurn && (MEMORY_READ_TOOLS.has(op) || op === "hub_memory_correct" || op === "hub_remember" || op === "hub_task_propose" || op === "hub_sdlc_record" || op === "hub_plan_review" || op === "hub_sdlc_costs" || op === "hub_sdlc_metrics" || op.startsWith("hub_release_") || op === "hub_roadmap_edit" || op === "hub_roadmap_triage" || op === "hub_roadmap_decompose" || op === "hub_backlog_return_untouched" || op === "hub_task_wait" || op === "hub_backlog_plan" || op === "hub_backlog_undo" || op === "hub_backlog_pull" || op === "hub_backlog_split" || op === "release_new" || op === "hub_study_draft" || op === "hub_study_revise")) throw new PreEffectToolRefusal(`${op} is not available while working on a PII task: its text must not leave this machine`);
|
|
140
|
+
// The same words attached to an ordinary task would reach its reviewer, its owner, overlapping owners (a plan, the
|
|
141
|
+
// completed-change notice) and shared memory. A turn that holds a PII task acts on ordinary tasks in a turn of its own.
|
|
142
|
+
if (piiTurn && (op === "hub_task_done" || op === "hub_review" || (op === "hub_task_accept" && (a.plan != null || a.refs != null)))) {
|
|
143
|
+
const target = scope.board.get(Number(a.id));
|
|
144
|
+
if (target && !scope.tasks.isPii(target)) throw new PreEffectToolRefusal(`${op} on task #${target.id} is not available while working on a PII task: its text would reach other peers; do it in a turn without the PII task`);
|
|
145
|
+
}
|
|
146
|
+
return taskOpPart1(scope, by, op, a, inProcess, piiTurn, toolSocket, reviewTurn);
|
|
147
|
+
}
|