@staix/agent-hub 0.51.0 → 0.52.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 +35 -0
- package/README.md +1 -1
- package/docs/adding-an-ai-tool.md +24 -2
- package/docs/agent-notes/adapters.md +1 -0
- package/docs/agent-notes/budget.md +8 -2
- package/docs/agent-notes/daemon.md +13 -8
- package/docs/agent-notes/security-review.md +6 -5
- package/docs/agent-notes/tasks.md +5 -2
- package/docs/agent-notes/tests.md +4 -3
- package/docs/cooperbench.md +1 -1
- package/docs/design/adapters.md +4 -0
- package/docs/design/cli-output-inventory.md +162 -152
- package/docs/design/cli-output.md +4 -3
- package/docs/design/guidance-probes.md +1 -0
- package/docs/design/roadmap.md +2 -0
- package/docs/design/task-board.md +1 -0
- package/docs/dogfood.md +14 -0
- package/docs/events.md +4 -2
- package/docs/memory.md +5 -3
- package/docs/operations.md +210 -16
- package/docs/quickstart.md +12 -2
- package/docs/roles.md +1 -1
- package/docs/sdlc.md +26 -3
- package/docs/security.md +11 -5
- package/docs/specs/2026-09-19-agent-hub-design.md +43 -0
- package/docs/specs/2026-09-19-multi-project-design.md +4 -0
- package/docs/specs/2026-09-20-upgrade-recovery-design.md +17 -0
- package/docs/specs/mcp-endpoint.md +63 -0
- package/docs/verification/2026-11-30-capability-listing-shape-1808.md +45 -0
- package/docs/verification/2026-11-30-upgrade-keep-1807.md +174 -0
- package/docs/verification/2026-12-01-1811-confirmation-receipt.md +19 -0
- package/docs/verification/2026-12-01-1811-orca-agent-list.md +20 -0
- package/docs/verification/2026-12-01-1811-orca-pane-key.md +21 -0
- package/docs/verification/2026-12-02-1819-claude-process-after-renewal.md +54 -0
- package/docs/verification/2026-12-02-agy-1.5.21.md +74 -0
- package/docs/verification/2026-12-02-claude-implementer-2.1.334.md +44 -0
- package/docs/verification/2026-12-02-cli-import-graph.md +33 -0
- package/docs/verification/2026-12-03-0.52.0.md +150 -0
- package/docs/verification/2026-12-03-codex-0173-reviewer-isolation.md +53 -0
- package/docs/verification/2026-12-03-codex-0173-reviewer-tool-call.md +34 -0
- package/docs/verification/2026-12-03-jcode-1.3.0.md +25 -0
- package/docs/verification/agy/README.md +17 -0
- package/docs/verification/agy/cli-surface.ts +68 -0
- package/docs/verification/agy/interactive-bridge.ts +92 -0
- package/docs/verification/agy/interactive-session.ts +131 -0
- package/docs/verification/agy/launcher-nonce.ts +215 -0
- package/docs/verification/agy/native-hooks.ts +210 -0
- package/docs/verification/agy/originals/agent-hub-681/cli-surface.ts +87 -0
- package/docs/verification/agy/originals/agent-hub-681/native-hooks-adapted.ts +91 -0
- package/docs/verification/agy/originals/agent-hub-681/tui-actual.ts +200 -0
- package/docs/verification/agy/originals/agent-hub-684/probe.ts +107 -0
- package/docs/verification/agy/originals.json +25 -0
- package/docs/verification/agy/permission-new-functions.ts +128 -0
- package/docs/verification/agy/run-probe.py +108 -0
- package/docs/verification/agy/runtime.ts +171 -0
- package/docs/verification/agy/tmux-helper-control.ts +6 -0
- package/docs/verification/agy/tmux-session.ts +235 -0
- package/docs/verified.json +82 -41
- package/package.json +3 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/compat.json +157 -0
- package/plugins/agent-hub/kimi-hook.js +621 -865
- package/plugins/agent-hub/server.js +17423 -32962
- package/src/adapters/agy/definition.ts +7 -24
- package/src/adapters/channel-peer.ts +3 -1
- package/src/adapters/claude-channel.ts +38 -257
- package/src/adapters/claude-implementer.ts +3 -1
- package/src/adapters/codex-appserver.ts +77 -15
- package/src/adapters/compat.ts +74 -11
- package/src/adapters/configured-acp.ts +23 -163
- package/src/adapters/configured-adapter-policy.ts +160 -0
- package/src/adapters/configured-pull-entry.ts +53 -0
- package/src/adapters/configured-pull.ts +38 -0
- package/src/adapters/conformance/fakes/app-server.ts +9 -2
- package/src/adapters/declaration-catalog.ts +25 -0
- package/src/adapters/declaration-data.ts +342 -0
- package/src/adapters/declaration-resolution.ts +53 -0
- package/src/adapters/definitions/builtin-metadata.ts +61 -83
- package/src/adapters/definitions/jcode-launch.ts +13 -0
- package/src/adapters/definitions/native-adapter-policy.ts +390 -0
- package/src/adapters/definitions/native-cli-claude-launch.ts +3 -2
- package/src/adapters/definitions/native-cli-codex-launch.ts +2 -1
- package/src/adapters/definitions/native-cli-entry-jcode.ts +4 -2
- package/src/adapters/definitions/native-cli-entry-types.ts +9 -2
- package/src/adapters/definitions/native-cli-launch-common.ts +2 -2
- package/src/adapters/definitions/native-cli-retained.ts +1 -1
- package/src/adapters/definitions/native-configuration.ts +18 -0
- package/src/adapters/definitions/native-help.ts +24 -0
- package/src/adapters/definitions/native-launch-declarations.ts +34 -0
- package/src/adapters/definitions/native-launch-policy.ts +4 -0
- package/src/adapters/definitions/native-launch-settings.ts +72 -0
- package/src/adapters/definitions/native-light-cli.ts +18 -0
- package/src/adapters/definitions/native-light-preview.ts +10 -0
- package/src/adapters/definitions/native-wrapper-launch.ts +10 -0
- package/src/adapters/definitions/qwen.ts +6 -29
- package/src/adapters/definitions/reviewer-variants.ts +7 -8
- package/src/adapters/external-declarations.ts +31 -0
- package/src/adapters/external-modules.ts +4 -29
- package/src/adapters/jcode.ts +3 -12
- package/src/adapters/native-capabilities.ts +18 -8
- package/src/adapters/native-proof-ports.ts +1 -1
- package/src/adapters/presets.ts +136 -0
- package/src/adapters/qwen-dual.ts +2 -2
- package/src/adapters/registry-types.ts +3 -0
- package/src/adapters/registry.ts +20 -81
- package/src/adapters/reviewer-print.ts +26 -9
- package/src/adapters/role-eligibility.ts +2 -1
- package/src/cli/accounts-import.ts +72 -0
- package/src/cli/agents-latest-table.ts +88 -0
- package/src/cli/agents-latest.ts +22 -0
- package/src/cli/agents-output.ts +10 -0
- package/src/cli/agents-presets.ts +100 -0
- package/src/cli/agents.ts +1 -1
- package/src/cli/attention.ts +3 -2
- package/src/cli/autonomy-homes.ts +7 -2
- package/src/cli/budget-renew-guidance.ts +129 -0
- package/src/cli/claude-homes.ts +9 -5
- package/src/cli/command-context.ts +3 -0
- package/src/cli/command-table.ts +123 -0
- package/src/cli/commands/accounts.ts +8 -0
- package/src/cli/commands/agents.ts +18 -0
- package/src/cli/commands/answer.ts +28 -0
- package/src/cli/commands/ask.ts +17 -0
- package/src/cli/commands/autonomy.ts +83 -0
- package/src/cli/commands/backlog.ts +46 -0
- package/src/cli/commands/bench.ts +60 -0
- package/src/cli/commands/board.ts +48 -0
- package/src/cli/commands/broker.ts +9 -0
- package/src/cli/commands/budget.ts +96 -0
- package/src/cli/commands/capabilities.ts +12 -0
- package/src/cli/commands/check-path.ts +55 -0
- package/src/cli/commands/completion.ts +8 -0
- package/src/cli/commands/console.ts +12 -0
- package/src/cli/commands/daemon.ts +8 -0
- package/src/cli/commands/deliverables.ts +25 -0
- package/src/cli/commands/doctor.ts +249 -0
- package/src/cli/commands/down.ts +3 -0
- package/src/cli/commands/export.ts +15 -0
- package/src/cli/commands/facts.ts +15 -0
- package/src/cli/commands/goal.ts +22 -0
- package/src/cli/commands/guidance.ts +102 -0
- package/src/cli/commands/help.ts +17 -0
- package/src/cli/commands/host.ts +45 -0
- package/src/cli/commands/init.ts +121 -0
- package/src/cli/commands/instructed.ts +19 -0
- package/src/cli/commands/instruction-hook.ts +15 -0
- package/src/cli/commands/intake.ts +24 -0
- package/src/cli/commands/kill.ts +15 -0
- package/src/cli/commands/learn.ts +23 -0
- package/src/cli/commands/lineage.ts +30 -0
- package/src/cli/commands/logs.ts +21 -0
- package/src/cli/commands/manager.ts +15 -0
- package/src/cli/commands/memory.ts +21 -0
- package/src/cli/commands/model.ts +25 -0
- package/src/cli/commands/models.ts +40 -0
- package/src/cli/commands/native.ts +39 -0
- package/src/cli/commands/pause.ts +5 -0
- package/src/cli/commands/peer.ts +32 -0
- package/src/cli/commands/permission.ts +26 -0
- package/src/cli/commands/permit.ts +12 -0
- package/src/cli/commands/pet.ts +24 -0
- package/src/cli/commands/projects.ts +49 -0
- package/src/cli/commands/queue.ts +70 -0
- package/src/cli/commands/recovery-run.ts +13 -0
- package/src/cli/commands/recovery.ts +130 -0
- package/src/cli/commands/release.ts +23 -0
- package/src/cli/commands/releases.ts +9 -0
- package/src/cli/commands/remember.ts +6 -0
- package/src/cli/commands/report.ts +27 -0
- package/src/cli/commands/research.ts +53 -0
- package/src/cli/commands/reset.ts +89 -0
- package/src/cli/commands/restart.ts +5 -0
- package/src/cli/commands/results.ts +31 -0
- package/src/cli/commands/resume.ts +5 -0
- package/src/cli/commands/review.ts +24 -0
- package/src/cli/commands/roadmap.ts +21 -0
- package/src/cli/commands/role.ts +34 -0
- package/src/cli/commands/roles.ts +30 -0
- package/src/cli/commands/room.ts +14 -0
- package/src/cli/commands/roster.ts +48 -0
- package/src/cli/commands/route.ts +9 -0
- package/src/cli/commands/say.ts +21 -0
- package/src/cli/commands/schedule.ts +17 -0
- package/src/cli/commands/sdlc.ts +321 -0
- package/src/cli/commands/settings.ts +148 -0
- package/src/cli/commands/setup.ts +89 -0
- package/src/cli/commands/shared-refusals.ts +25 -0
- package/src/cli/commands/smoke.ts +44 -0
- package/src/cli/commands/source.ts +64 -0
- package/src/cli/commands/specs.ts +13 -0
- package/src/cli/commands/status.ts +28 -0
- package/src/cli/commands/stop.ts +17 -0
- package/src/cli/commands/structure.ts +60 -0
- package/src/cli/commands/study.ts +39 -0
- package/src/cli/commands/tail.ts +19 -0
- package/src/cli/commands/task.ts +114 -0
- package/src/cli/commands/title.ts +17 -0
- package/src/cli/commands/turns.ts +10 -0
- package/src/cli/commands/ui.ts +47 -0
- package/src/cli/commands/undo.ts +77 -0
- package/src/cli/commands/up.ts +39 -0
- package/src/cli/commands/upgrade.ts +5 -0
- package/src/cli/commands/usage.ts +33 -0
- package/src/cli/commands/version.ts +5 -0
- package/src/cli/commands/watch.ts +30 -0
- package/src/cli/commands/worktrees.ts +31 -0
- package/src/cli/console-state.ts +5 -138
- package/src/cli/console-versions.ts +1 -1
- package/src/cli/help.ts +37 -15
- package/src/cli/identity.ts +23 -4
- package/src/cli/launch-check.ts +1 -2
- package/src/cli/launch.ts +13 -82
- package/src/cli/light-dispatch.ts +29 -0
- package/src/cli/main.js +8 -1
- package/src/cli/main.ts +233 -2816
- package/src/cli/orca-probe.ts +119 -0
- package/src/cli/output.ts +31 -2
- package/src/cli/preview.ts +10 -5
- package/src/cli/recovery-version-preflight.ts +28 -9
- package/src/cli/replace-process.ts +22 -0
- package/src/cli/report-layout.ts +142 -0
- package/src/cli/roadmap-usage.ts +16 -0
- package/src/cli/roadmap.ts +3 -16
- package/src/cli/sdlc-doctor.ts +27 -0
- package/src/cli/sdlc-output.ts +55 -1
- package/src/cli/setup-homes.ts +1 -1
- package/src/cli/start-agents-run.ts +1 -1
- package/src/cli/statusline-tee.ts +25 -4
- package/src/cli/terminal-recovery.ts +53 -10
- package/src/cli/upgrade-interactive.ts +1 -0
- package/src/cli/upgrade-runtime.ts +11 -0
- package/src/cli/upgrade.ts +4 -15
- package/src/hub/accounts.ts +148 -0
- package/src/hub/addons.ts +20 -0
- package/src/hub/agent-drift.ts +2 -1
- package/src/hub/budget-projection.ts +39 -7
- package/src/hub/budget.ts +231 -16
- package/src/hub/channel-project.ts +3 -3
- package/src/hub/conductor-peer.ts +24 -0
- package/src/hub/conductor.ts +2 -21
- package/src/hub/config-apply.ts +24 -13
- package/src/hub/config-edit.ts +1 -1
- package/src/hub/config-tier.ts +2 -0
- package/src/hub/config.ts +31 -14
- package/src/hub/control-client.ts +48 -0
- package/src/hub/daemon.ts +421 -61
- package/src/hub/events.ts +3 -0
- package/src/hub/home-tag.ts +12 -0
- package/src/hub/host.ts +217 -0
- package/src/hub/hub-tools.ts +2 -1
- package/src/hub/instance-budget.ts +2 -2
- package/src/hub/instance-config.ts +15 -126
- package/src/hub/instances.ts +22 -6
- package/src/hub/instruction-receipt.ts +2 -2
- package/src/hub/kimi-usage.ts +38 -11
- package/src/hub/lifecycle.ts +86 -4
- package/src/hub/mcp-bridge-core.ts +98 -0
- package/src/hub/mcp-channel-push.ts +20 -0
- package/src/hub/mcp-endpoint-serve.ts +178 -0
- package/src/hub/mcp-endpoint.ts +226 -0
- package/src/hub/mcp-tool-call.ts +181 -0
- package/src/hub/operational-settings.ts +2 -0
- package/src/hub/orca-env.ts +6 -0
- package/src/hub/orca-state.ts +84 -0
- package/src/hub/peers.ts +5 -1
- package/src/hub/permission-mode.ts +2 -1
- package/src/hub/project.ts +20 -0
- package/src/hub/protocol-window.ts +58 -0
- package/src/hub/quota-origin.ts +20 -0
- package/src/hub/registry.ts +36 -2
- package/src/hub/report.ts +1 -1
- package/src/hub/research.ts +1 -1
- package/src/hub/review-brief.ts +47 -2
- package/src/hub/roster.ts +6 -3
- package/src/hub/routing.ts +9 -2
- package/src/hub/sdlc-check.ts +205 -0
- package/src/hub/sdlc-sync.ts +146 -0
- package/src/hub/sdlc.ts +33 -4
- package/src/hub/settings.ts +7 -4
- package/src/hub/start-agents.ts +1 -1
- package/src/hub/start-mode.ts +11 -4
- package/src/hub/structure-budget.ts +131 -0
- package/src/hub/structure-scan.ts +149 -0
- package/src/hub/tasks-experiment.ts +455 -0
- package/src/hub/tasks-guidance.ts +606 -0
- package/src/hub/tasks-roadmap-plan.ts +419 -0
- package/src/hub/tasks-roadmap.ts +491 -0
- package/src/hub/tasks-study.ts +661 -0
- package/src/hub/tasks-survey.ts +192 -0
- package/src/hub/tasks.ts +319 -2548
- package/src/hub/terminal-open.ts +5 -3
- package/src/hub/tooling.ts +3 -19
- package/src/hub/usage-rollup.ts +9 -3
- package/src/local/tools.ts +5 -0
- package/src/ui/index.html +1 -1
- package/src/ui/needs.ts +17 -5
- package/src/ui/peer-palette.ts +2 -4
- package/templates/presets/agents.json +60 -0
- package/templates/presets/confirmation-matrix.json +8 -8
package/src/cli/sdlc-output.ts
CHANGED
|
@@ -16,6 +16,52 @@ export function renderSdlcConfiguration(value: unknown, columns?: number, _now =
|
|
|
16
16
|
if (list(row?.lines).length) { out.section("Details"); for (const line of list(row.lines)) out.note(String(line), "value"); }
|
|
17
17
|
return out.lines();
|
|
18
18
|
}
|
|
19
|
+
/** #1856 T2: the audit as the hub built it; every non-ok row names its cause and a runnable next step. */
|
|
20
|
+
export function renderSdlcCheck(value: unknown, columns?: number, _now = Date.now(), ascii = false): Span[][] {
|
|
21
|
+
const report = value as any, rows: any[] = list(report?.rows), counts = report?.counts ?? {};
|
|
22
|
+
const summary = [["fail", counts.fail], ["warn", counts.warn], ["unknown", counts.unknown], ["ok", counts.ok]].filter(([, n]) => Number(n) > 0).map(([name, n]) => `${n} ${name}`).join(", ");
|
|
23
|
+
const out = new LayoutReport(columns, ascii).titled("ahub", "SDLC check", `${report?.offline ? "offline, " : ""}${summary || "no rows"}`);
|
|
24
|
+
const titles: Record<string, string> = { config: "Lifecycle config and roles", repository: "Repository and required checks", bindings: "Active task bindings", roadmap: "Roadmap and issue hygiene" };
|
|
25
|
+
for (const section of ["config", "repository", "bindings", "roadmap"]) {
|
|
26
|
+
const inSection = rows.filter(row => row.section === section);
|
|
27
|
+
if (!inSection.length) continue;
|
|
28
|
+
out.section(titles[section]!);
|
|
29
|
+
for (const row of inSection) {
|
|
30
|
+
out.bullet(row.state === "ok" ? "ok" : row.state === "fail" ? "fail" : row.state === "warn" ? "warn" : "unknown", `${row.id}: ${row.detail}`);
|
|
31
|
+
if (row.cause) out.note(String(row.cause), "hint");
|
|
32
|
+
if (row.next) out.next(String(row.next));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (Number(report?.withheld) > 0) out.note(`${report.withheld} private unsettled task${report.withheld === 1 ? "" : "s"} counted, never described`, "hint");
|
|
36
|
+
return out.lines();
|
|
37
|
+
}
|
|
38
|
+
/** #1856 T3: the sync plan (a preview) or its apply results; every line names what it would write or why it did not. */
|
|
39
|
+
export function renderSdlcSync(value: unknown, columns?: number, _now = Date.now(), ascii = false): Span[][] {
|
|
40
|
+
const report = value as any, applied = report?.apply === true, operations: any[] = list(report?.operations), results: any[] = list(report?.results);
|
|
41
|
+
const out = new LayoutReport(columns, ascii).titled("ahub", "SDLC sync", applied ? `${results.filter(row => row.ok).length} applied, ${results.filter(row => !row.ok).length} refused` : `${operations.length} planned`);
|
|
42
|
+
if (applied) {
|
|
43
|
+
out.section("Applied");
|
|
44
|
+
for (const row of results) out.bullet(row.ok ? "ok" : "fail", `task ${row.task} ${row.kind}${row.ok ? "" : `: ${row.error}`}`);
|
|
45
|
+
if (!results.length) out.note("nothing to apply", "hint");
|
|
46
|
+
} else {
|
|
47
|
+
out.section("Planned repairs");
|
|
48
|
+
for (const op of operations) out.bullet("pending", `task ${op.task} ${op.kind}: ${op.reason}`);
|
|
49
|
+
if (!operations.length && !list(report?.closes).length && !report?.roadmap) out.note("no repair is needed", "hint");
|
|
50
|
+
if (report?.roadmap) out.bullet("pending", `refresh ${list(report.roadmap.files).join(" and ")} in this worktree`);
|
|
51
|
+
if (report?.roadmapSkipped) out.note(`roadmap refresh skipped: ${report.roadmapSkipped}`, "hint");
|
|
52
|
+
for (const close of list(report?.closes)) out.bullet("pending", `gh issue close ${close.issue} --repo ${close.repo}: ${close.reason}`);
|
|
53
|
+
for (const row of list(report?.closeSkipped)) out.note(`${row.issue ? `#${row.issue} stays open` : "more candidates"}: ${row.reason}`, "hint");
|
|
54
|
+
if (list(report?.unavailable).length) out.note(`not read: ${list(report.unavailable).join(", ")}`, "hint");
|
|
55
|
+
}
|
|
56
|
+
const ambiguous: any[] = list(report?.ambiguous), moved: any[] = list(report?.headMoved);
|
|
57
|
+
if (ambiguous.length) { out.section("Ambiguous, never guessed"); for (const row of ambiguous) out.bullet("warn", `task ${row.task}: ${row.reason}`); }
|
|
58
|
+
if (moved.length) { out.section("Review head moved, left as recorded"); for (const row of moved) out.bullet("warn", `task ${row.task}: PR #${row.pr} is at ${String(row.head).slice(0, 12)}, the task records ${String(row.recorded).slice(0, 12)}`); }
|
|
59
|
+
if (Number(report?.withheld) > 0) out.note(`${report.withheld} private task${report.withheld === 1 ? "" : "s"} counted, never described`, "hint");
|
|
60
|
+
const flags = `${report?.options?.writeRoadmap ? " --write-roadmap" : ""}${report?.options?.closeSettled ? " --close-settled-issues" : ""}`;
|
|
61
|
+
if (!applied && (operations.length || list(report?.closes).length || report?.roadmap)) out.next(`ahub sdlc sync${flags} --apply --confirm ${report.fingerprint}`);
|
|
62
|
+
else if (!applied) out.note(`fingerprint ${report?.fingerprint}`, "hint");
|
|
63
|
+
return out.lines();
|
|
64
|
+
}
|
|
19
65
|
/** Survey fields already passed the host's task and security disclosure policy. */
|
|
20
66
|
export function renderSdlcSurvey(value: unknown, columns?: number, _now = Date.now(), ascii = false): Span[][] {
|
|
21
67
|
const row = value as any;
|
|
@@ -181,12 +227,20 @@ function lifecycleView(reply: any, columns: number | undefined, detail: boolean,
|
|
|
181
227
|
const rows = list(reply?.rows);
|
|
182
228
|
const out = new LayoutReport(columns, ascii).titled("ahub", "SDLC lifecycle", `mode ${reply?.mode ?? "unknown"}`);
|
|
183
229
|
if (reply?.securityScan && typeof reply.securityScan === "object") out.section("Security scan").kv([["security scan", Object.entries(reply.securityScan).map(([source, value]) => `${source}: ${value === null ? "unknown" : value}`).join(", ")]]);
|
|
184
|
-
if (!rows.length)
|
|
230
|
+
if (!rows.length) {
|
|
231
|
+
out.note(reply?.unsettledOnly ? "no unsettled task has lifecycle state" : "no task has lifecycle state yet");
|
|
232
|
+
if (reply?.unsettledOnly && Number(reply.hiddenSettled) > 0) out.note(`${plural(Number(reply.hiddenSettled), "settled task")} hidden; pass --all for the historical first 100 or name a task to read one`);
|
|
233
|
+
return out.lines();
|
|
234
|
+
}
|
|
185
235
|
if (!detail || rows.length > 1) {
|
|
186
236
|
out.section("Tasks", String(rows.length)).append(grid(["ID", "STAGE", "READY", "ACTOR", "PR"], rows.map(row => [s(`#${row.id}`, "taskRef"), s(row.stage ?? "unknown"), s(yes(row.ready), readyTone(row.ready)), s(row.actor ?? "-"), s(row.receipt?.pr ? `#${row.receipt.pr}` : "-")]), columns));
|
|
187
237
|
}
|
|
188
238
|
// #1658: the read-back line belongs to one task's view; a list of rows has no single issue body to read it against.
|
|
189
239
|
for (const row of rows) taskBlock(out, row, detail, detail || rows.length === 1);
|
|
240
|
+
if (reply?.unsettledOnly) {
|
|
241
|
+
const hidden = Number(reply.hiddenSettled) || 0;
|
|
242
|
+
out.note(`${plural(hidden, "settled task")} hidden; pass --all for the historical first 100 or name a task to read one`);
|
|
243
|
+
}
|
|
190
244
|
if (reply?.truncated) out.bullet("warn", "showing the first 100 tasks; name a task to read one");
|
|
191
245
|
return out.lines();
|
|
192
246
|
}
|
package/src/cli/setup-homes.ts
CHANGED
|
@@ -25,7 +25,7 @@ export async function setupClaudeHomes(ports: SetupHomesPorts): Promise<void> {
|
|
|
25
25
|
const initial = [];
|
|
26
26
|
for (const home of ports.homes) initial.push(await checkClaudeHome(home, ports.packageRoot, ports.env, ports.probe, undefined, true, ports.hook));
|
|
27
27
|
for (const check of initial) {
|
|
28
|
-
ports.print(`Claude home ${check.home.path}: plugin ${check.plugin.state}; hook ${check.hook.state}${check.hook.outdated ? " (outdated)" : ""}.`);
|
|
28
|
+
ports.print(`Claude home ${check.home.path}${check.home.label !== undefined ? ` (account ${check.home.label})` : ""}: plugin ${check.plugin.state}; hook ${check.hook.state}${check.hook.outdated ? " (outdated)" : ""}.`);
|
|
29
29
|
for (const notice of ("notices" in check.plugin ? check.plugin.notices : undefined) ?? []) ports.print(`${check.home.path}: ${notice}.`);
|
|
30
30
|
if (check.plugin.state === "unknown" || check.hook.state === "refused") throw new Error(`Claude setup cannot safely inspect ${check.home.path}; nothing was changed`);
|
|
31
31
|
if (check.next?.blocked) throw marketplaceRemovalRefusal(check.home.path, check.next.why);
|
|
@@ -5,7 +5,7 @@ import { readAutonomyDefaults, writeMachineStartAgents } from "../hub/autonomy-d
|
|
|
5
5
|
import { configRefusal } from "../hub/config-trust.ts";
|
|
6
6
|
import { START_AGENTS_DEFAULT, parseStartAgents } from "../hub/start-agents.ts";
|
|
7
7
|
import { MAX_COMMAND_MS } from "./terminal-recovery.ts";
|
|
8
|
-
import { definitionOf } from "../adapters/
|
|
8
|
+
import { builtinDeclarationOf as definitionOf } from "../adapters/declaration-catalog.ts";
|
|
9
9
|
import { expectedHubLink, markStarted, type ExpectedLink, type HubCheck } from "../hub/hub-check.ts";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
// command with the same input, so the status line looks exactly as before. It must never fail the render.
|
|
6
6
|
import { spawnSync } from "node:child_process";
|
|
7
7
|
import { chmodSync, mkdirSync, renameSync, writeFileSync } from "node:fs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { isAbsolute, join } from "node:path";
|
|
10
|
+
import { homeTag } from "../hub/home-tag.ts";
|
|
11
|
+
import { claudePeer, claudeStateFile, isClaudeSessionUuid } from "../hub/claude-state.ts";
|
|
10
12
|
|
|
11
13
|
const input = await Bun.stdin.text();
|
|
12
14
|
let own = "";
|
|
@@ -18,13 +20,32 @@ try {
|
|
|
18
20
|
const dir = process.env.AGENTHUB_STATE_DIR;
|
|
19
21
|
// Usage is per account and shared; context and session belong to this peer (#450 I3: a claude-<name> instance).
|
|
20
22
|
const peer = claudePeer(process.env.AGENTHUB_PEER_ID);
|
|
23
|
+
const sessionId = typeof parsed.session_id === "string" ? parsed.session_id : typeof parsed.sessionId === "string" ? parsed.sessionId : "";
|
|
21
24
|
if (limits && dir) {
|
|
22
25
|
mkdirSync(dir, { recursive: true });
|
|
23
26
|
const file = join(dir, "claude-usage.json");
|
|
24
|
-
|
|
27
|
+
const quotaWindow = (window: unknown) => {
|
|
28
|
+
if (!window || typeof window !== "object") return undefined;
|
|
29
|
+
const value = window as { used_percentage?: unknown; resets_at?: unknown };
|
|
30
|
+
const used = value.used_percentage;
|
|
31
|
+
const resets = typeof value.resets_at === "number" || typeof value.resets_at === "string" ? Number(value.resets_at) : NaN;
|
|
32
|
+
if (typeof used !== "number" || !Number.isFinite(used)) return undefined;
|
|
33
|
+
return { used_percentage: used, ...(Number.isFinite(resets) && resets > 0 ? { resets_at: resets } : {}) };
|
|
34
|
+
};
|
|
35
|
+
const rate_limits = { five_hour: quotaWindow(limits.five_hour), seven_day: quotaWindow(limits.seven_day) };
|
|
36
|
+
const launchId = process.env.AGENTHUB_LAUNCH_ID;
|
|
37
|
+
writeFileSync(`${file}.tmp`, JSON.stringify({ at: Date.now(), peer, ...(isClaudeSessionUuid(sessionId) ? { sessionId } : {}),
|
|
38
|
+
...(isClaudeSessionUuid(launchId) ? { launchId } : {}), home: homeTag(process.env.CLAUDE_CONFIG_DIR && isAbsolute(process.env.CLAUDE_CONFIG_DIR) ? process.env.CLAUDE_CONFIG_DIR : join(homedir(), ".claude")), rate_limits }), { mode: 0o600 });
|
|
25
39
|
renameSync(`${file}.tmp`, file);
|
|
40
|
+
// #1810: a session under a configured home also writes that home's own reading, so each declared account has one file the daemon reads by tag. The path is hashed, never written.
|
|
41
|
+
const configHome = process.env.CLAUDE_CONFIG_DIR;
|
|
42
|
+
if (configHome && isAbsolute(configHome)) {
|
|
43
|
+
const tagged = join(dir, `claude-usage.${homeTag(configHome)}.json`);
|
|
44
|
+
writeFileSync(`${tagged}.tmp`, JSON.stringify({ at: Date.now(), peer, rate_limits }), { mode: 0o600 });
|
|
45
|
+
renameSync(`${tagged}.tmp`, tagged);
|
|
46
|
+
}
|
|
26
47
|
}
|
|
27
|
-
|
|
48
|
+
|
|
28
49
|
if (sessionId && dir) {
|
|
29
50
|
// Bind context to the launcher, daemon and native session. Persist no prompts or transcript text.
|
|
30
51
|
mkdirSync(dir, { recursive: true });
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { RecoveryLaunchFailure } from "./recovery-launch.ts";
|
|
2
2
|
import { shellQuote } from "./shell-quote.ts";
|
|
3
3
|
export { shellQuote } from "./shell-quote.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { ORCA_PANE_ENV } from "../hub/orca-env.ts";
|
|
5
|
+
import { builtinDeclarationOf } from "../adapters/declaration-catalog.ts";
|
|
6
|
+
import type { ProjectAdapterCatalog, KindMap } from "../adapters/registry-types.ts";
|
|
7
|
+
|
|
8
|
+
const registry = () => require("../adapters/registry.ts") as typeof import("../adapters/registry.ts");
|
|
9
|
+
const definitionOf: typeof import("../adapters/registry.ts").definitionOf = (...args) => registry().definitionOf(...args);
|
|
10
|
+
const createProjectAdapterCatalog: typeof import("../adapters/registry.ts").createProjectAdapterCatalog = (...args) => registry().createProjectAdapterCatalog(...args);
|
|
5
11
|
import { readInstanceConfig, readInstanceRoleConfig } from "../hub/instance-config.ts";
|
|
6
12
|
import { effectiveInstanceRoles } from "../hub/instances.ts";
|
|
7
13
|
import { resolveInstanceExecutionCwd } from "../hub/instance-execution.ts";
|
|
@@ -190,9 +196,44 @@ export interface RecordedTerminalLaunch {
|
|
|
190
196
|
handle: string;
|
|
191
197
|
incarnationId: string;
|
|
192
198
|
worktreeId: string;
|
|
199
|
+
/** #1811: Orca's stable pane identity, which survives a reassigned handle. Absent outside an Orca pane that exports them. */
|
|
200
|
+
paneKey?: string;
|
|
201
|
+
tabId?: string;
|
|
202
|
+
workspaceId?: string;
|
|
193
203
|
env: Partial<Record<AllowedEnvName, string>>;
|
|
194
204
|
}
|
|
195
205
|
|
|
206
|
+
/** #1811: the optional pane identity of a record, each field a bounded string or absent. */
|
|
207
|
+
const PANE_FIELDS = ["paneKey", "tabId", "workspaceId"] as const;
|
|
208
|
+
const MAX_PANE_FIELD = 256;
|
|
209
|
+
const paneFieldsOf = (source: Record<string, unknown>): Partial<Record<(typeof PANE_FIELDS)[number], string>> =>
|
|
210
|
+
Object.fromEntries(PANE_FIELDS.flatMap((name) => { const v = source[name]; return typeof v === "string" && v.length > 0 && v.length <= MAX_PANE_FIELD ? [[name, v]] : []; }));
|
|
211
|
+
const paneFieldsValid = (row: Record<string, unknown>): boolean => PANE_FIELDS.every((name) => row[name] === undefined || typeof row[name] === "string" && row[name].length <= MAX_PANE_FIELD);
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* #1811: Orca's pane key as a terminal row shows it. Verified on Orca 1.4.283: the list rows carry `tabId` and `leafId`, no
|
|
215
|
+
* `paneKey` and no workspace field, and a pane's `ORCA_PANE_KEY` is its row's `tabId:leafId`. `terminal show` has no pane key.
|
|
216
|
+
*/
|
|
217
|
+
const paneKeyOf = (...rows: Record<string, unknown>[]): string | undefined => {
|
|
218
|
+
for (const row of rows) if (typeof row.tabId === "string" && row.tabId && typeof row.leafId === "string" && row.leafId) return `${row.tabId}:${row.leafId}`;
|
|
219
|
+
return undefined;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* #1811: the record a listed terminal belongs to. The handle, worktree and incarnation match first. When Orca has
|
|
224
|
+
* reassigned the handle, the pane key matches second, inside the same worktree and only when `paneProved`: a different
|
|
225
|
+
* incarnation in the same pane is this peer's only if Orca itself names the peer as the agent in it (`identityFrom`), so a
|
|
226
|
+
* pane the person reused for a plain shell never counts as owned.
|
|
227
|
+
*/
|
|
228
|
+
function recordFor(records: readonly RecordedTerminalLaunch[], peer: TerminalPeer, terminal: Record<string, unknown>, paneProved = false): RecordedTerminalLaunch | undefined {
|
|
229
|
+
const exact = records.find((item) => item.peer === peer && item.handle === terminal.handle && item.worktreeId === terminal.worktreeId && item.incarnationId === terminal.incarnationId);
|
|
230
|
+
if (exact) return exact;
|
|
231
|
+
const key = typeof terminal.paneKey === "string" ? terminal.paneKey : undefined;
|
|
232
|
+
if (!key || !paneProved) return undefined;
|
|
233
|
+
const byPane = records.filter((item) => item.peer === peer && item.paneKey === key && item.worktreeId === terminal.worktreeId);
|
|
234
|
+
return byPane.length === 1 ? byPane[0] : undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
196
237
|
const MAX_WAIT_MS = 10 * 60 * 1000;
|
|
197
238
|
export const MAX_COMMAND_MS = 30_000;
|
|
198
239
|
/** #215: a replacement's readiness is awaited in slices this long, checking between them whether its launcher still runs. */
|
|
@@ -392,7 +433,7 @@ export function recordPath(stateDir: string): string {
|
|
|
392
433
|
|
|
393
434
|
/** Resolve declared terminal roots without treating a launch candidate as daemon ownership proof. */
|
|
394
435
|
function executionRoot(peer: string, projectRoot: string, captured?: string): string {
|
|
395
|
-
const builtin =
|
|
436
|
+
const builtin = builtinDeclarationOf(peer);
|
|
396
437
|
if (builtin?.session.launchRecord) return projectRoot;
|
|
397
438
|
const { instances: declarations, roles, catalog } = readInstanceRoleConfig(projectRoot);
|
|
398
439
|
const definition = catalog.definitionOf(peer, declarations);
|
|
@@ -405,7 +446,7 @@ function executionRoot(peer: string, projectRoot: string, captured?: string): st
|
|
|
405
446
|
|
|
406
447
|
function savedTerminalRoot(binding: Pick<TerminalBinding, "peer" | "projectRoot" | "executionCwd" | "terminalRoot">): string {
|
|
407
448
|
const expected = executionRoot(binding.peer, binding.projectRoot, binding.executionCwd ?? binding.projectRoot);
|
|
408
|
-
if (
|
|
449
|
+
if (builtinDeclarationOf(binding.peer)) return binding.projectRoot;
|
|
409
450
|
const root = binding.terminalRoot ?? binding.projectRoot;
|
|
410
451
|
if (root !== binding.projectRoot && root !== expected) throw new Error(`${binding.peer}: recorded Orca grouping root is not authorized`);
|
|
411
452
|
return root;
|
|
@@ -413,7 +454,7 @@ function savedTerminalRoot(binding: Pick<TerminalBinding, "peer" | "projectRoot"
|
|
|
413
454
|
|
|
414
455
|
function validRecord(item: unknown): item is RecordedTerminalLaunch {
|
|
415
456
|
const row = object(item);
|
|
416
|
-
return typeof row.peer === "string" && typeof row.projectRoot === "string" && (row.executionCwd === undefined || typeof row.executionCwd === "string") && (row.terminalRoot === undefined || typeof row.terminalRoot === "string") && typeof row.instanceId === "string" && typeof row.handle === "string" && typeof row.incarnationId === "string" && typeof row.worktreeId === "string" && typeof row.launcherPid === "number" && typeof row.launcherSignature === "string" && row.launcherSignature.length > 0 && typeof row.launchId === "string" && row.launchId.length > 0;
|
|
457
|
+
return typeof row.peer === "string" && typeof row.projectRoot === "string" && (row.executionCwd === undefined || typeof row.executionCwd === "string") && (row.terminalRoot === undefined || typeof row.terminalRoot === "string") && typeof row.instanceId === "string" && typeof row.handle === "string" && typeof row.incarnationId === "string" && typeof row.worktreeId === "string" && typeof row.launcherPid === "number" && typeof row.launcherSignature === "string" && row.launcherSignature.length > 0 && typeof row.launchId === "string" && row.launchId.length > 0 && paneFieldsValid(row);
|
|
417
458
|
}
|
|
418
459
|
|
|
419
460
|
/**
|
|
@@ -509,7 +550,7 @@ export async function prepareTerminalLaunch(peer: TerminalPeer, projectRoot: str
|
|
|
509
550
|
const handle = process.env.ORCA_TERMINAL_HANDLE;
|
|
510
551
|
const worktreeIdFromEnv = process.env.ORCA_WORKTREE_ID;
|
|
511
552
|
if (!handle || !worktreeIdFromEnv) return undefined;
|
|
512
|
-
if (!
|
|
553
|
+
if (!builtinDeclarationOf(peer) && !config.executionCwd) throw new Error(`${peer}: recording an extra terminal requires its authenticated startup execution root`);
|
|
513
554
|
const expectedRoot = executionRoot(peer, projectRoot, config.executionCwd || undefined);
|
|
514
555
|
const value = await run(config.runner, ["terminal", "show", "--terminal", handle, "--json"]);
|
|
515
556
|
const terminal = terminalObject(value);
|
|
@@ -517,7 +558,7 @@ export async function prepareTerminalLaunch(peer: TerminalPeer, projectRoot: str
|
|
|
517
558
|
const actualHandle = nestedString(terminal, ["handle"]);
|
|
518
559
|
const actualWorktree = nestedString(terminal, ["worktreeId"]);
|
|
519
560
|
const incarnationId = nestedString(terminal, ["incarnationId"]);
|
|
520
|
-
if (actualHandle !== handle || !actualRoot || !(rootMatches(actualRoot, projectRoot) || !
|
|
561
|
+
if (actualHandle !== handle || !actualRoot || !(rootMatches(actualRoot, projectRoot) || !builtinDeclarationOf(peer) && rootMatches(actualRoot, expectedRoot)) || actualWorktree !== worktreeIdFromEnv || !incarnationId) {
|
|
521
562
|
throw new OrcaCommandError(blocker("project-root-mismatch", "Orca launch terminal failed canonical root/worktree readback", peer, handle));
|
|
522
563
|
}
|
|
523
564
|
const launcherSignature = await config.processIdentity(process.pid);
|
|
@@ -525,7 +566,7 @@ export async function prepareTerminalLaunch(peer: TerminalPeer, projectRoot: str
|
|
|
525
566
|
const launchId = randomUUID();
|
|
526
567
|
process.env.AGENTHUB_LAUNCH_ID = launchId;
|
|
527
568
|
process.env.AGENTHUB_INSTANCE_ID = instanceId;
|
|
528
|
-
const row: RecordedTerminalLaunch = { peer, projectRoot, ...(!
|
|
569
|
+
const row: RecordedTerminalLaunch = { peer, projectRoot, ...(!builtinDeclarationOf(peer) ? { executionCwd: expectedRoot, terminalRoot: actualRoot } : {}), stateDir, instanceId, launcherPid: process.pid, launcherSignature, launchId, handle, incarnationId, worktreeId: actualWorktree, ...paneFieldsOf(Object.fromEntries(Object.entries(ORCA_PANE_ENV).map(([field, name]) => [field, process.env[name]]))), env: allowedEnv({ env: process.env }) };
|
|
529
570
|
return row;
|
|
530
571
|
}
|
|
531
572
|
|
|
@@ -538,7 +579,7 @@ export function terminalLaunchCandidate(value: unknown, projectRoot: string, sta
|
|
|
538
579
|
if (value.executionCwd !== undefined && value.executionCwd !== expected || value.terminalRoot !== undefined && value.terminalRoot !== projectRoot && value.terminalRoot !== expected) return undefined;
|
|
539
580
|
return { peer: value.peer, projectRoot, stateDir, instanceId, launcherPid: value.launcherPid, launcherSignature: value.launcherSignature,
|
|
540
581
|
launchId: value.launchId, handle: value.handle, incarnationId: value.incarnationId, worktreeId: value.worktreeId,
|
|
541
|
-
...(value.executionCwd ? { executionCwd: value.executionCwd } : {}), ...(value.terminalRoot ? { terminalRoot: value.terminalRoot } : {}), env: allowedEnv({ env: object(value.env) }) };
|
|
582
|
+
...(value.executionCwd ? { executionCwd: value.executionCwd } : {}), ...(value.terminalRoot ? { terminalRoot: value.terminalRoot } : {}), ...paneFieldsOf(value as unknown as Record<string, unknown>), env: allowedEnv({ env: object(value.env) }) };
|
|
542
583
|
} catch { return undefined; }
|
|
543
584
|
}
|
|
544
585
|
|
|
@@ -850,9 +891,11 @@ export async function inspectTerminals(projectRoot: string, sessions: Partial<Re
|
|
|
850
891
|
}
|
|
851
892
|
// A show readback is required; list can be stale between recovery steps.
|
|
852
893
|
if (!rootMatches(terminal.worktreePath ?? terminal.projectRoot, expectedTerminalRoot)) continue;
|
|
894
|
+
const paneKey = paneKeyOf(terminal, listedTerminal);
|
|
895
|
+
if (paneKey) terminal = { ...terminal, paneKey };
|
|
853
896
|
const identity = identityFrom(terminal, instances, catalog);
|
|
854
897
|
const terminalSession = sessionFrom(terminal);
|
|
855
|
-
const recorded = records
|
|
898
|
+
const recorded = recordFor(records, peer, terminal, identity === peer || extra && identity === adapter.kind);
|
|
856
899
|
// A recorded launcher proves ownership; the daemon's supplied session id is the
|
|
857
900
|
// authoritative session id when Orca omits it from terminal metadata.
|
|
858
901
|
if ((!extra && identity === peer && terminalSession === sessionId) || (recorded !== undefined && (identity === undefined || identity === peer || extra && identity === adapter.kind) && (terminalSession === undefined || terminalSession === sessionId))) peerCandidates.push(terminal);
|
|
@@ -885,7 +928,7 @@ export async function inspectTerminals(projectRoot: string, sessions: Partial<Re
|
|
|
885
928
|
blockers.push(blocker("terminal-unready", `terminal ${handle} is orphaned or disconnected`, peer, handle));
|
|
886
929
|
continue;
|
|
887
930
|
}
|
|
888
|
-
const recorded = records
|
|
931
|
+
const recorded = recordFor(records, peer, terminal, identityFrom(terminal, instances, catalog) === peer || extra && identityFrom(terminal, instances, catalog) === adapter.kind);
|
|
889
932
|
// Orca observation supplies file identity; launch arguments are not observed native session-file evidence.
|
|
890
933
|
const { args: _launchArgs, ...observedTerminal } = terminal;
|
|
891
934
|
const sessionFile = catalog.definitionOf(peer, instances)?.session.crashIdentity?.(observedTerminal).sessionFile;
|
|
@@ -141,6 +141,7 @@ export function planLines(plan: UpgradePlan, current: string): string[] {
|
|
|
141
141
|
}
|
|
142
142
|
if (plan.blockers.length) lines.push("");
|
|
143
143
|
for (const blocker of plan.blockers) lines.push(`blocker: ${blocker}`);
|
|
144
|
+
for (const notice of plan.notices ?? []) lines.push(`note: ${notice}`);
|
|
144
145
|
return lines;
|
|
145
146
|
}
|
|
146
147
|
|
|
@@ -22,6 +22,7 @@ import { awaitStopped, inspectProject } from "../hub/lifecycle.ts";
|
|
|
22
22
|
import type { Project } from "../hub/registry.ts";
|
|
23
23
|
import { canonicalPath, hubHome, realPath } from "../hub/project.ts";
|
|
24
24
|
import { packageDigest, recoveryTargetDigest, preserveRuntimePackage, preserveRuntimeSource, stageCurrentRuntime, registryRelease, runCommand, stageRelease, verifyPackage, type RunCommand } from "./recovery-package.ts";
|
|
25
|
+
import { orcaLastChecked, readOrcaProbe } from "./orca-probe.ts";
|
|
25
26
|
import { inspectSavedTerminal, inspectTerminals, closeTerminal, createTerminal, launcherOf, recordPath, reattachOrphanedTerminal, REATTACH_BOUND_MS, waitForIdle, shellQuote, type OrphanedTerminal, type SessionRef, type TerminalBinding, type TerminalRecoveryOptions } from "./terminal-recovery.ts";
|
|
26
27
|
import { ReattachmentRequired, MissingRecordedSession, FinalRefusal, planFingerprint, recoveryScope, registeredProjects, targetReadsWaivers, type Inspection, type PlannedProject, type ProjectProgress, type RecoveryDriver, type RecoveryOperation, type RecoveryPeer, type UpgradePlan } from "./upgrade.ts";
|
|
27
28
|
import { SHARED_CHANNEL_VERSION_ARGV, nativeRecordedSessionState } from "../adapters/definitions/native-recovery.ts";
|
|
@@ -343,6 +344,7 @@ export async function makeUpgradePlan(kind: "restart" | "upgrade", version: stri
|
|
|
343
344
|
if (recoveryProtocol(manager) === undefined) body.blockers.push("manager requires manual bootstrap with its matching CLI before current-protocol recovery");
|
|
344
345
|
} catch { body.blockers.push("manager ownership manifest is unreadable"); }
|
|
345
346
|
}
|
|
347
|
+
const orcaProjects = new Set<string>();
|
|
346
348
|
for (const project of projects) {
|
|
347
349
|
if (kind === "restart" && selected === undefined || selected !== undefined && project.root !== selected) continue;
|
|
348
350
|
let source: Inspection;
|
|
@@ -403,6 +405,7 @@ export async function makeUpgradePlan(kind: "restart" | "upgrade", version: stri
|
|
|
403
405
|
if (!session) blockers.push(`${peer.id}: saved ACP session identity unavailable; end the peer and make a new recovery plan`);
|
|
404
406
|
} else if (!adapter?.session.freshOnRestore && !adapter?.session.restoreArgs) blockers.push(`${peer.id}: no automatic recovery adapter`);
|
|
405
407
|
}
|
|
408
|
+
if (Object.keys(sessions).length) orcaProjects.add(project.id);
|
|
406
409
|
const terminals = await inspectTerminals(project.root, sessions, {
|
|
407
410
|
...terminalOptions(run), stateDir: project.stateDir, instanceId: source.instanceId,
|
|
408
411
|
});
|
|
@@ -428,6 +431,14 @@ export async function makeUpgradePlan(kind: "restart" | "upgrade", version: stri
|
|
|
428
431
|
}
|
|
429
432
|
body.projects.push({ project, source, terminals: terminals.bindings, blockers, ...(reconnectOnly.length ? { reconnectOnly } : {}), ...(unrecordedTerminals.length ? { unrecordedTerminals } : {}), ...(freshStart.length ? { freshStart } : {}), ...(terminals.orphaned?.length ? { orphanedTerminals: terminals.orphaned } : {}) });
|
|
430
433
|
}
|
|
434
|
+
// #1808 T4: only a plan with Orca rows (a project with a peer whose terminal the recovery looks up) reads Orca's own answers, and only before anything is closed. A failed shape check of the commands
|
|
435
|
+
// the recovery uses blocks those rows; a newer Orca than the last one checked is a note and blocks nothing. A plan with no Orca rows runs no Orca command here.
|
|
436
|
+
const orcaRows = body.projects.filter(planned => orcaProjects.has(planned.project.id));
|
|
437
|
+
if (orcaRows.length) {
|
|
438
|
+
const orca = await readOrcaProbe(async argv => { const result = await run([orcaExecutable(), ...argv], { timeoutMs: 15_000 }); return { code: result.code, stdout: result.stdout }; });
|
|
439
|
+
if (orca.problems.length) for (const planned of orcaRows) planned.blockers.push(`Orca ${orca.version ?? "(version unreadable)"} answers differently from what the recovery reads (${orca.problems.join("; ")}); its Orca terminals cannot be closed or restored safely; next action: update ahub, or install an Orca whose CLI the recovery supports (ahub doctor shows the same check), then make a new plan`);
|
|
440
|
+
else if (orca.newer) body.notices = [`Orca ${orca.version} is newer than ${orcaLastChecked()}, the last version checked; the commands the recovery reads still have the fields it needs`];
|
|
441
|
+
}
|
|
431
442
|
const gated = body.projects.map(planned => ({ planned, gates: recoveryVersionGates(planned, peer => projectDefinition(peer, planned.project.root), configuredCommands(loadConfig(planned.project.root))) })).filter(item => item.gates.length);
|
|
432
443
|
if (gated.length) {
|
|
433
444
|
try {
|
package/src/cli/upgrade.ts
CHANGED
|
@@ -8,11 +8,11 @@ import { LIVE_TEST_PERSON_REFUSAL } from "./identity.ts";
|
|
|
8
8
|
import { checkedSessionPath } from "./recovery-session-file.ts";
|
|
9
9
|
import { canChooseFresh, decodeRestoreReceipt, restoreReceiptStatus } from "./upgrade-restore-state.ts";
|
|
10
10
|
import { databaseBusySite, isDatabaseBusy, RecoveryDatabaseBusy } from "../hub/recovery-error.ts";
|
|
11
|
-
import { Database } from "bun:sqlite";
|
|
12
11
|
import { createHash, randomUUID } from "node:crypto";
|
|
13
12
|
import { existsSync, readFileSync } from "node:fs";
|
|
14
13
|
import { isAbsolute, join } from "node:path";
|
|
15
|
-
import { Registry,
|
|
14
|
+
import { Registry, registeredProjects, type Project } from "../hub/registry.ts";
|
|
15
|
+
export { registeredProjects } from "../hub/registry.ts";
|
|
16
16
|
import { hubHome } from "../hub/project.ts";
|
|
17
17
|
import { readRecoveryWaits } from "./recovery-waits.ts";
|
|
18
18
|
import { acquireRecoveryLock, claimRunner, coordinatorCurrent, operationIdPattern, readOperation, recoveryCommand, recoveryLock, releaseRecoveryLock, writeOperation } from "../hub/recovery-store.ts";
|
|
@@ -82,6 +82,8 @@ export interface UpgradePlan {
|
|
|
82
82
|
projects: PlannedProject[];
|
|
83
83
|
fingerprint: string;
|
|
84
84
|
blockers: string[];
|
|
85
|
+
/** #1808 T4: notes that block nothing (an Orca newer than the last one checked). Absent unless there is one. */
|
|
86
|
+
notices?: string[];
|
|
85
87
|
}
|
|
86
88
|
export interface ProjectProgress {
|
|
87
89
|
id: string;
|
|
@@ -407,19 +409,6 @@ function plannedAttached(op: RecoveryOperation, progress: ProjectProgress, peer:
|
|
|
407
409
|
return !!binding && current?.[projectDefinition(peer, planned?.project.root)?.session.idField ?? "sessionId"] === binding.sessionId;
|
|
408
410
|
}
|
|
409
411
|
|
|
410
|
-
/** Registry reads for planning must not create a registry or run migrations. */
|
|
411
|
-
export function registeredProjects(home = hubHome()): Project[] {
|
|
412
|
-
const path = join(home, "registry.db");
|
|
413
|
-
if (!existsSync(path)) return [];
|
|
414
|
-
const db = new Database(path, { readonly: true });
|
|
415
|
-
try {
|
|
416
|
-
db.run(`PRAGMA busy_timeout = ${REGISTRY_DB_BUSY_TIMEOUT_MS}`);
|
|
417
|
-
// #226: a registry no current release opened yet has no signature column, and this read never migrates.
|
|
418
|
-
const signed = (db.query("PRAGMA table_info(projects)").all() as { name: string }[]).some((c) => c.name === "pid_signature");
|
|
419
|
-
return (db.query(`SELECT ${PROJECT_COLUMNS}${signed ? ", pid_signature" : ""} FROM projects ORDER BY root`).all() as Record<string, unknown>[]).map(projectFromRow);
|
|
420
|
-
} finally { db.close(); }
|
|
421
|
-
}
|
|
422
|
-
|
|
423
412
|
export function planFingerprint(plan: Omit<UpgradePlan, "fingerprint">): string {
|
|
424
413
|
const stable = { ...plan, projects: plan.projects.map((p) => ({ ...p, source: { ...p.source, recovery: undefined,
|
|
425
414
|
peers: p.source.peers.map(({ state, ...peer }) => ({ ...peer, active: state !== "offline" })) } })) };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { statSync } from "node:fs";
|
|
3
|
+
import { isAbsolute, sep } from "node:path";
|
|
4
|
+
import { canonicalHome } from "./instances.ts";
|
|
5
|
+
import { NATIVE_ADAPTER_POLICY } from "../adapters/definitions/native-adapter-policy.ts";
|
|
6
|
+
import { isBuiltinAdapterKind } from "../adapters/definitions/native-help.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* #1810: an account is a label the person declares for a kind and a home, never an identity. The label is what the hub stores, shows and logs. The path stays
|
|
10
|
+
* in `config.local.json` and in this module's return value; no event, log, status reply or CLI output carries it (#1806 AC7).
|
|
11
|
+
*/
|
|
12
|
+
interface AccountDeclaration { readonly kind: string; readonly home: string }
|
|
13
|
+
export type Accounts = Readonly<Record<string, AccountDeclaration>>;
|
|
14
|
+
|
|
15
|
+
/** The label of a peer without a declared account: its budget key stays the bare kind, exactly as before accounts existed. */
|
|
16
|
+
export const DEFAULT_ACCOUNT_LABEL = "default";
|
|
17
|
+
/** The kinds whose home variable the hub already handles (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`). A kind with no confirmed variable stays out. */
|
|
18
|
+
/** The fixed builtin kinds with a native account home: the Claude channel and the Codex app-server. Read from the builtin transport policy. */
|
|
19
|
+
export const isClaudeAccountKind = (kind: string): boolean => isClaudeKind(kind);
|
|
20
|
+
const isClaudeKind = (kind: string): boolean => isBuiltinAdapterKind(kind) && NATIVE_ADAPTER_POLICY[kind].metadata.transport === "claude-channel";
|
|
21
|
+
const isCodexKind = (kind: string): boolean => isBuiltinAdapterKind(kind) && NATIVE_ADAPTER_POLICY[kind].metadata.transport === "codex-appserver";
|
|
22
|
+
export const accountKinds = (): string[] => Object.keys(NATIVE_ADAPTER_POLICY).filter(kind => isClaudeKind(kind) || isCodexKind(kind));
|
|
23
|
+
export const MAX_ACCOUNTS_PER_KIND = 8;
|
|
24
|
+
const LABEL = /^[a-z][a-z0-9-]{0,31}$/;
|
|
25
|
+
const fail = (field: string, reason: string): never => { throw new Error(`${field}: ${reason}`); };
|
|
26
|
+
|
|
27
|
+
/** Own data descriptors only: an accessor, a proxy, a symbol or a custom prototype is not configuration. */
|
|
28
|
+
function plain(value: unknown, field: string): Record<string, PropertyDescriptor> {
|
|
29
|
+
if (!value || typeof value !== "object" || types.isProxy(value) || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value)) || Object.getOwnPropertySymbols(value).length) return fail(field, "must be a plain own-data object");
|
|
30
|
+
const descriptors: Record<string, PropertyDescriptor> = Object.assign(Object.create(null), Object.getOwnPropertyDescriptors(value));
|
|
31
|
+
if (Object.values(descriptors).some(entry => !Object.hasOwn(entry, "value") || !entry.enumerable)) return fail(field, "must contain enumerable data fields only");
|
|
32
|
+
return descriptors;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Validate `accounts` as `jcode_home` is: each home absolute and an existing directory, no two the same directory however they are spelled
|
|
37
|
+
* and none nested in another, at most 8 per kind, and every label a plain word that is not `default`. Throws a message that names the label, never a path.
|
|
38
|
+
*/
|
|
39
|
+
export function readAccounts(raw: unknown): Accounts {
|
|
40
|
+
if (raw === undefined) return Object.freeze({});
|
|
41
|
+
const declared = plain(raw, "accounts");
|
|
42
|
+
const out: Record<string, AccountDeclaration> = {};
|
|
43
|
+
const seen: { label: string; key: string; identity?: string }[] = [];
|
|
44
|
+
const perKind: Record<string, number> = {};
|
|
45
|
+
for (const [label, descriptor] of Object.entries(declared)) {
|
|
46
|
+
const at = `accounts.${label}`;
|
|
47
|
+
if (!LABEL.test(label) || label === DEFAULT_ACCOUNT_LABEL) return fail(at, `the label must be a lowercase word of at most 32 characters and not "${DEFAULT_ACCOUNT_LABEL}"`);
|
|
48
|
+
const entry = plain(descriptor.value, at);
|
|
49
|
+
if (Object.keys(entry).some(key => key !== "kind" && key !== "home")) return fail(at, "only kind and home are accepted");
|
|
50
|
+
const kind: unknown = entry.kind?.value, home: unknown = entry.home?.value;
|
|
51
|
+
if (typeof kind !== "string" || !accountKinds().includes(kind)) return fail(`${at}.kind`, `must be one of ${accountKinds().join(", ")}`);
|
|
52
|
+
if (typeof home !== "string" || !isAbsolute(home) || !home.trim() || Buffer.byteLength(home) > 4096 || /\p{Cc}/u.test(home)) return fail(`${at}.home`, "must be a nonempty control-free absolute path of at most 4096 bytes");
|
|
53
|
+
let info;
|
|
54
|
+
try { info = statSync(home); } catch { /* reported below, without the path */ }
|
|
55
|
+
if (!info?.isDirectory()) return fail(`${at}.home`, "is not an existing directory; the person creates it and signs in there first");
|
|
56
|
+
if ((perKind[kind] = (perKind[kind] ?? 0) + 1) > MAX_ACCOUNTS_PER_KIND) return fail(`accounts`, `at most ${MAX_ACCOUNTS_PER_KIND} ${kind} accounts are supported`);
|
|
57
|
+
const canonical = canonicalHome(home);
|
|
58
|
+
for (const other of seen) {
|
|
59
|
+
if (canonical.key === other.key || (canonical.identity !== undefined && canonical.identity === other.identity)) return fail(`${at}.home`, `is the same directory as accounts.${other.label}`);
|
|
60
|
+
if (canonical.key.startsWith(`${other.key}${sep}`) || other.key.startsWith(`${canonical.key}${sep}`)) return fail(`${at}.home`, `is nested inside or around accounts.${other.label}`);
|
|
61
|
+
}
|
|
62
|
+
seen.push({ label, ...canonical });
|
|
63
|
+
out[label] = Object.freeze({ kind, home });
|
|
64
|
+
}
|
|
65
|
+
return Object.freeze(out);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The label of the declared account whose home is `home` for a kind, or `default` for an undeclared home. The path is compared and discarded here:
|
|
70
|
+
* only a label comes back, so no caller can store, log or show it (#1806 AC7).
|
|
71
|
+
*/
|
|
72
|
+
export function labelForHome(home: unknown, kind: string, accounts: Accounts | undefined): string {
|
|
73
|
+
if (!accounts || typeof home !== "string" || !isAbsolute(home) || Buffer.byteLength(home) > 4096 || /\p{Cc}/u.test(home)) return DEFAULT_ACCOUNT_LABEL;
|
|
74
|
+
const mine = canonicalHome(home);
|
|
75
|
+
for (const [label, declared] of Object.entries(accounts)) {
|
|
76
|
+
if (declared.kind !== kind) continue;
|
|
77
|
+
const other = canonicalHome(declared.home);
|
|
78
|
+
if (mine.key === other.key || (mine.identity !== undefined && mine.identity === other.identity)) return label;
|
|
79
|
+
}
|
|
80
|
+
return DEFAULT_ACCOUNT_LABEL;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A budget key: the bare account for the default label (today's key, so a project without accounts is unchanged), `<account>:<label>` otherwise. A peer id never contains a colon. */
|
|
84
|
+
export function accountKey(account: string, label: string | undefined): string {
|
|
85
|
+
return label === undefined || label === DEFAULT_ACCOUNT_LABEL ? account : `${account}:${label}`;
|
|
86
|
+
}
|
|
87
|
+
/** The account a key was built from: `claude:team` is `claude`. */
|
|
88
|
+
export const baseAccount = (key: string): string => key.split(":", 1)[0]!;
|
|
89
|
+
export { homeTag } from "./home-tag.ts";
|
|
90
|
+
|
|
91
|
+
/** #1810: whether a bare `claude-usage.json` reading came from a declared account's home (its `home` tag). That reading is reported under `claude:<label>`, so the bare key must not take it too. */
|
|
92
|
+
export function isDeclaredReading(homeTagOfReading: unknown, accounts: Accounts | undefined, tagOf: (home: string) => string): boolean {
|
|
93
|
+
if (typeof homeTagOfReading !== "string" || !accounts) return false;
|
|
94
|
+
return Object.values(accounts).some(declared => isClaudeKind(declared.kind) && tagOf(declared.home) === homeTagOfReading);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* #1810 AC3: every `instances.<id>.account` names a declared account of the instance's own kind. Run at configuration load (so a start with an undeclared account or one of another
|
|
99
|
+
* kind is refused before the daemon exists). The message names the instance and the label, never a home.
|
|
100
|
+
*/
|
|
101
|
+
export function checkInstanceAccounts(instances: Readonly<Record<string, { kind: string; account?: string }>> | undefined, accounts: Accounts | undefined): void {
|
|
102
|
+
for (const [id, instance] of Object.entries(instances ?? {})) {
|
|
103
|
+
if (instance.account === undefined) continue;
|
|
104
|
+
const declared = accounts?.[instance.account];
|
|
105
|
+
if (!declared) throw new Error(`instances.${id}.account: "${instance.account}" is not a declared account; the person adds it under accounts in .agenthub/config.local.json`);
|
|
106
|
+
if (declared.kind !== instance.kind) throw new Error(`instances.${id}.account: "${instance.account}" is an account of another kind than ${instance.kind}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** #1810 AC3: the one variable an instance's declared account sets in its child's environment, or nothing. `key` is the kind's own home variable (`session.configDirEnv`). */
|
|
111
|
+
export function instanceAccountEnv(account: string | undefined, accounts: Accounts | undefined, key: string | undefined): NodeJS.ProcessEnv | undefined {
|
|
112
|
+
const home = account === undefined ? undefined : accounts?.[account]?.home;
|
|
113
|
+
return home !== undefined && key !== undefined ? { [key]: home } : undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* #1810 AC6: the peers a paused peer's work must not go to. With `budget.cross_account_handoff` on it is nobody extra (peers of one account are paused together, and two labels
|
|
118
|
+
* of one kind are different accounts). Off, every other peer on the same kind is a sibling whatever its label. `keyOf` is the daemon's `accountOf`.
|
|
119
|
+
*/
|
|
120
|
+
export function handoffSiblings(peer: string, ids: readonly string[], keyOf: (id: string) => string, crossAccount: boolean): string[] {
|
|
121
|
+
if (crossAccount) return [];
|
|
122
|
+
const mine = baseAccount(keyOf(peer));
|
|
123
|
+
return ids.filter(id => id !== peer && baseAccount(keyOf(id)) === mine);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface HandoffMove { to: string | null; role: "owner" | "reviewer" }
|
|
127
|
+
/** The `budget_handoff` events for moves that crossed accounts: peer ids and labels only. A move within one account never produces one. */
|
|
128
|
+
export function handoffEvents(peer: string, moves: readonly HandoffMove[], labelOf: (id: string) => string | undefined, keyOf: (id: string) => string) {
|
|
129
|
+
const events: { type: "budget_handoff"; from: string; to: string; fromLabel: string; toLabel: string; role: "owner" | "reviewer" }[] = [];
|
|
130
|
+
const fromLabel = labelOf(peer) ?? DEFAULT_ACCOUNT_LABEL;
|
|
131
|
+
for (const move of moves) {
|
|
132
|
+
if (!move.to || keyOf(move.to) === keyOf(peer)) continue;
|
|
133
|
+
const toLabel = labelOf(move.to) ?? DEFAULT_ACCOUNT_LABEL;
|
|
134
|
+
if (fromLabel === DEFAULT_ACCOUNT_LABEL && toLabel === DEFAULT_ACCOUNT_LABEL) continue;
|
|
135
|
+
events.push({ type: "budget_handoff", from: peer, to: move.to, fromLabel, toLabel, role: move.role });
|
|
136
|
+
}
|
|
137
|
+
return events;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* #1810: the budget key of a peer, the daemon's one resolver. `definitionAccount` is the registry's budget account for the peer id (absent for an instance id), `declaredKind` the
|
|
142
|
+
* kind an instance declares, `label` the session's or the instance's declared account label. No label keeps the bare account, so a project without accounts is unchanged;
|
|
143
|
+
* a key resolves to itself (the budget requires an idempotent resolver).
|
|
144
|
+
*/
|
|
145
|
+
export function accountKeyFor(peer: string, definitionAccount: string | undefined, declaredKind: string | undefined, label: string | undefined): string {
|
|
146
|
+
if (peer.includes(":")) return peer;
|
|
147
|
+
return accountKey(definitionAccount ?? (label === undefined ? undefined : declaredKind) ?? peer, label);
|
|
148
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// #1778 T2b: the closed add-on list and the on/off/unknown reading, split from tooling.ts so the research records no longer import the adapter registry.
|
|
2
|
+
// tooling.ts re-exports all of it. No behavior change.
|
|
3
|
+
/**
|
|
4
|
+
* #248: which add-ons a peer works with, from a closed list. Names and versions only, read from the machine's plugin
|
|
5
|
+
* inventory and launch settings (Claude Code's installed plugins and `enabledPlugins`, Codex's `config.toml`) and from
|
|
6
|
+
* the executables on PATH; never a plugin's content, settings values, hooks or paths.
|
|
7
|
+
* ponytail: the inventory is the machine's, not the session's: a session started with its own `--settings` or plugin
|
|
8
|
+
* flags can differ. Reading the launch record of each `ahub claude` / `ahub codex` would make it exact.
|
|
9
|
+
*/
|
|
10
|
+
export const ADDONS = ["claude-mem", "ponytail", "ripwire", "open-code-review", "codex-plugin", "dot-admit"] as const;
|
|
11
|
+
export type AddonName = (typeof ADDONS)[number];
|
|
12
|
+
export interface Addon { name: AddonName; version: string | null }
|
|
13
|
+
|
|
14
|
+
/** `on` when any of the peers has the add-on, `off` when every peer's fingerprint is known and none has it, else unknown. */
|
|
15
|
+
export function addonState(name: AddonName, fingerprints: (Addon[] | undefined)[]): "on" | "off" | "unknown" {
|
|
16
|
+
if (fingerprints.some((f) => f?.some((a) => a.name === name))) return "on";
|
|
17
|
+
return fingerprints.length && fingerprints.every((f) => f !== undefined) ? "off" : "unknown";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const isAddon = (name: string): name is AddonName => (ADDONS as readonly string[]).includes(name);
|
package/src/hub/agent-drift.ts
CHANGED
|
@@ -16,7 +16,8 @@ export function driftedAgents(rows: readonly AgentVersionRow[]): DriftedAgent[]
|
|
|
16
16
|
const out: DriftedAgent[] = [];
|
|
17
17
|
for (const row of rows) {
|
|
18
18
|
const { verdict } = row;
|
|
19
|
-
|
|
19
|
+
// #1808: an `observe` entry never refuses and never queues a planner notice; the daily watch and `ahub doctor` report it.
|
|
20
|
+
if (!row.executable || verdict.state === "verified" || verdict.state === "unknown" || verdict.state === "observed") continue;
|
|
20
21
|
const version = verdict.version;
|
|
21
22
|
if (!version || !SAFE_VERSION.test(version)) continue;
|
|
22
23
|
out.push({ id: row.id, version, state: verdict.state, receipt: COMPAT[row.id].receipt });
|