@staix/agent-hub 0.50.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 +51 -0
- package/README.md +1 -1
- package/docs/adding-an-ai-tool.md +26 -4
- package/docs/agent-notes/README.md +1 -0
- package/docs/agent-notes/adapters.md +4 -3
- package/docs/agent-notes/budget.md +8 -2
- package/docs/agent-notes/daemon.md +13 -8
- package/docs/agent-notes/local-worker.md +3 -3
- package/docs/agent-notes/security-review.md +6 -5
- package/docs/agent-notes/tasks.md +10 -3
- package/docs/agent-notes/tests.md +4 -3
- package/docs/cooperbench.md +1 -1
- package/docs/design/adapters.md +21 -0
- package/docs/design/cli-output-inventory.md +165 -150
- package/docs/design/cli-output.md +4 -3
- package/docs/design/guidance-probes.md +1 -0
- package/docs/design/roadmap.md +3 -1
- package/docs/design/task-board.md +35 -0
- package/docs/dogfood.md +21 -3
- package/docs/events.md +4 -2
- package/docs/memory.md +5 -3
- package/docs/operations.md +259 -19
- package/docs/quickstart.md +29 -2
- package/docs/roadmap.json +20 -20
- package/docs/roadmap.md +2 -2
- package/docs/roles.md +1 -1
- package/docs/sdlc.md +29 -5
- package/docs/security.md +11 -5
- package/docs/specs/2026-09-19-agent-hub-design.md +44 -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-29-agy-1.5.20.md +33 -0
- package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
- package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
- package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
- package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
- package/docs/verification/2026-11-30-0.51.0.md +91 -0
- package/docs/verification/2026-11-30-account-switch-1806.md +445 -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 +87 -42
- 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 +1416 -24985
- package/plugins/agent-hub/server.js +17415 -32755
- package/scripts/check-docs.mjs +1 -1
- package/src/adapters/acp.ts +13 -13
- package/src/adapters/agy/definition.ts +9 -26
- package/src/adapters/agy/entry.ts +2 -0
- package/src/adapters/channel-peer.ts +3 -1
- package/src/adapters/claude-channel-evidence.ts +7 -3
- 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 +78 -14
- 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 +62 -84
- 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 +6 -3
- package/src/adapters/definitions/native-cli-codex-launch.ts +2 -1
- package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
- package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-jcode.ts +6 -2
- package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-types.ts +12 -3
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
- package/src/adapters/definitions/native-cli-launch-common.ts +2 -2
- package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
- package/src/adapters/definitions/native-cli-retained.ts +1 -1
- package/src/adapters/definitions/native-config-defaults.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 +19 -12
- package/src/adapters/native-capabilities.ts +18 -8
- package/src/adapters/native-facts-hooks.ts +12 -0
- 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/autonomy-offline.ts +1 -1
- package/src/cli/bench.ts +1 -1
- package/src/cli/budget-renew-guidance.ts +129 -0
- package/src/cli/claude-homes.ts +9 -5
- package/src/cli/claude-profile-hook.ts +31 -11
- 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 +91 -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/conductor-recovery.ts +1 -1
- package/src/cli/console-state.ts +5 -138
- package/src/cli/console-versions.ts +1 -1
- package/src/cli/facts-hook.ts +11 -4
- package/src/cli/help.ts +44 -20
- package/src/cli/identity.ts +27 -4
- package/src/cli/init-prompt.ts +1 -1
- package/src/cli/init-settings.ts +4 -35
- package/src/cli/init.ts +1 -1
- package/src/cli/json-text-spans.ts +57 -0
- package/src/cli/launch-check.ts +156 -0
- package/src/cli/launch.ts +19 -70
- package/src/cli/light-dispatch.ts +29 -0
- package/src/cli/main.js +8 -1
- package/src/cli/main.ts +257 -2799
- package/src/cli/memory.ts +1 -1
- package/src/cli/orca-probe.ts +119 -0
- package/src/cli/output.ts +45 -3
- package/src/cli/preview.ts +11 -6
- package/src/cli/recovery-launch.ts +1 -1
- 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 +2 -2
- package/src/cli/start-agents-run.ts +85 -7
- package/src/cli/start-check.ts +28 -0
- 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 +12 -1
- package/src/cli/upgrade.ts +4 -15
- package/src/cli/warn-line.ts +1 -1
- 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/ci-watch.ts +311 -79
- package/src/hub/conductor-peer.ts +24 -0
- package/src/hub/conductor.ts +2 -21
- package/src/hub/config-apply.ts +25 -14
- package/src/hub/config-edit.ts +1 -1
- package/src/hub/config-tier.ts +2 -0
- package/src/hub/config.ts +535 -0
- package/src/hub/control-client.ts +49 -1
- package/src/hub/daemon.ts +492 -569
- package/src/hub/delivery-public.ts +11 -0
- 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-check.ts +125 -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/path-policy.ts +1 -1
- package/src/hub/peers.ts +5 -1
- package/src/hub/permission-mode.ts +5 -41
- package/src/hub/permission-paths.ts +41 -0
- 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/recovery-policy.ts +1 -1
- package/src/hub/registry.ts +36 -2
- package/src/hub/releases-inventory.ts +198 -0
- 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/runtime-capture-prune.ts +25 -3
- package/src/hub/runtime-prune-health.ts +8 -1
- package/src/hub/sdlc-check.ts +205 -0
- package/src/hub/sdlc-release-authorization.ts +42 -21
- package/src/hub/sdlc-release-diagnostics.ts +5 -0
- package/src/hub/sdlc-release-policy.ts +21 -7
- package/src/hub/sdlc-release.ts +80 -20
- package/src/hub/sdlc-sync.ts +146 -0
- package/src/hub/sdlc.ts +38 -5
- 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 +457 -2584
- 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/src/ui/plugin.ts +1 -1
- package/templates/presets/agents.json +60 -0
- package/templates/presets/confirmation-matrix.json +8 -8
package/src/cli/agents-output.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentVersionRow } from "./agents.ts";
|
|
2
|
+
import type { CompatId } from "../adapters/compat.ts";
|
|
2
3
|
import { Report, type Span } from "./console-state.ts";
|
|
3
4
|
import { grid, s } from "./sdlc-output.ts";
|
|
4
5
|
|
|
@@ -11,3 +12,12 @@ export function renderAgents(rows: readonly AgentVersionRow[], columns?: number,
|
|
|
11
12
|
return new Report(columns, ascii).titled("ahub", "Agents")
|
|
12
13
|
.section("Versions", String(rows.length)).append(grid(["AGENT", "VERSION", "STATE", "POLICY", "DETAIL"], items, columns)).lines();
|
|
13
14
|
}
|
|
15
|
+
|
|
16
|
+
export interface LatestRow { id: CompatId; version?: string; state: string; answer: string }
|
|
17
|
+
/** #1808 T5: what `ahub agents --latest` prints: per CLI, whether the newest release verifies the version installed here. Advice only. */
|
|
18
|
+
export function renderAgentsLatest(rows: readonly LatestRow[], release: string, columns?: number, ascii = false): Span[][] {
|
|
19
|
+
const items = rows.map(({ id, version, state, answer }) => [s(id, "info"), s(version ?? "-"), s(state, state === "refused" ? "attention" : "info"), s(answer, answer.startsWith("verified") ? "success" : "info")]);
|
|
20
|
+
return new Report(columns, ascii).titled("ahub", "Agents against the newest release")
|
|
21
|
+
.section("Release", release).append(grid(["AGENT", "VERSION", "STATE", "NEWEST RELEASE"], items, columns))
|
|
22
|
+
.note("Advice only: this changes nothing here. A version the newest release verifies is accepted after you move to that release; until then ahub agents trust <id> <version> accepts one exact version on this machine.").lines();
|
|
23
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { BRIDGE_BUNDLE, loadPresets, parseProbeVersion, presetDeclaration, presetPullDeclaration, presetRows, readJsonFile, registrationText, type AgentPreset } from "../adapters/presets.ts";
|
|
5
|
+
import { readConfiguredAdapters } from "../adapters/configured-adapter-policy.ts";
|
|
6
|
+
import { KNOWN_PEERS } from "../adapters/registry.ts";
|
|
7
|
+
import { childEnv } from "../hub/child-process.ts";
|
|
8
|
+
import { configTracked } from "../hub/config-trust.ts";
|
|
9
|
+
import { withoutOrcaEnv } from "../hub/orca-env.ts";
|
|
10
|
+
import { atomicPrivateJSON } from "../hub/recovery-store.ts";
|
|
11
|
+
import { Report, asciiMarkers, resolveColor, streamEnv } from "./console-state.ts";
|
|
12
|
+
import { outputWidth } from "./output.ts";
|
|
13
|
+
import { grid, s } from "./sdlc-output.ts";
|
|
14
|
+
|
|
15
|
+
type Fail = (message: string) => never;
|
|
16
|
+
|
|
17
|
+
/** The installed executable and its version, read with one bounded probe in a scrubbed environment; undefined for either when the CLI is not there or prints none. */
|
|
18
|
+
function installed(preset: AgentPreset): { path?: string; version?: string } {
|
|
19
|
+
const path = Bun.which(preset.executable, { PATH: process.env.PATH ?? "" }) ?? undefined;
|
|
20
|
+
if (!path) return {};
|
|
21
|
+
const run = spawnSync(path, preset.versionArgs, { encoding: "utf8", timeout: 10_000, maxBuffer: 64 * 1024, env: withoutOrcaEnv(childEnv(process.env)) });
|
|
22
|
+
return { path, ...(run.status === 0 ? { version: parseProbeVersion(run.stdout ?? "") } : {}) };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function printer(): { print: (report: Report) => void; columns: number | undefined; ascii: boolean } {
|
|
26
|
+
const isTTY = !!process.stdout.isTTY;
|
|
27
|
+
const columns = outputWidth({ isTTY, columns: process.stdout.columns, COLUMNS: process.env.COLUMNS });
|
|
28
|
+
const ascii = asciiMarkers(process.env), color = resolveColor(undefined, streamEnv(isTTY), "ahub") === true;
|
|
29
|
+
return { print: (report) => console.log(report.render(color).join("\n")), columns, ascii };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** `ahub agents presets [--json]`: each preset with the version installed here and its status. Reads and runs a version probe; changes nothing. */
|
|
33
|
+
export function runAgentsPresets(args: string[], fail: Fail): void {
|
|
34
|
+
if (args.some(arg => arg !== "--json")) fail("usage: ahub agents presets [--json]");
|
|
35
|
+
const presets = loadPresets();
|
|
36
|
+
const rows = presetRows(presets).map(row => {
|
|
37
|
+
const found = installed(presets.find(preset => preset.id === row.id)!);
|
|
38
|
+
return { ...row, installed: found.path !== undefined, version: found.version ?? null };
|
|
39
|
+
});
|
|
40
|
+
if (args.includes("--json")) return console.log(JSON.stringify(rows.map(row => ({ id: row.id, displayName: row.displayName, executable: row.executable, installed: row.installed, version: row.version, headless: row.acp, status: row.status, receipt: row.receipt })), null, 2));
|
|
41
|
+
const { print, columns, ascii } = printer();
|
|
42
|
+
const items = rows.map(row => [s(row.id, "info"), s(row.installed ? row.version ?? "installed" : "not installed"), s(row.acp ? "headless" : "no headless line"), s(row.status, row.status === "verified" ? "success" : "attention")]);
|
|
43
|
+
print(new Report(columns, ascii).titled("ahub", "Agent presets").section("Presets", String(rows.length)).append(grid(["PRESET", "VERSION", "HEADLESS", "STATUS"], items, columns))
|
|
44
|
+
.note("untested means no receipt is committed for this preset; it gets exactly the limits a hand-written kind has. ahub agents add <preset> writes its declaration.").next("ahub agents add <preset> [--as <kind>]"));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* `ahub agents add <preset> [--as <kind>]` (person only: src/cli/identity.ts refuses every `agents` form but a bare listing to an agent shell and to
|
|
49
|
+
* `--live-test`). It writes `adapters.<kind>` to the untracked `.agenthub/config.local.json` and nothing else, after the same validation a hand-written
|
|
50
|
+
* declaration gets, and writes nothing when any check fails. The hub reads the declaration at start, so the person restarts it.
|
|
51
|
+
*/
|
|
52
|
+
export function runAgentsAdd(args: string[], cwd: string, fail: Fail, presets: readonly AgentPreset[] = loadPresets()): void {
|
|
53
|
+
const usage = "usage: ahub agents add <preset> [--as <kind>] [--pull]";
|
|
54
|
+
let id: string | undefined, as: string | undefined, pull = false;
|
|
55
|
+
for (let index = 0; index < args.length; index++) {
|
|
56
|
+
const arg = args[index]!;
|
|
57
|
+
if (arg === "--as") { as = args[++index]; if (!as) fail(usage); }
|
|
58
|
+
else if (arg.startsWith("--as=")) as = arg.slice(5);
|
|
59
|
+
else if (arg === "--pull") pull = true;
|
|
60
|
+
else if (arg.startsWith("-") || id !== undefined) fail(usage);
|
|
61
|
+
else id = arg;
|
|
62
|
+
}
|
|
63
|
+
const preset = presets.find(row => row.id === id);
|
|
64
|
+
if (!id) fail(usage);
|
|
65
|
+
if (!preset) return fail(`unknown preset ${id}: the presets are ${presets.map(row => row.id).join(", ")} (ahub agents presets)`);
|
|
66
|
+
if (!preset.acp && !pull) return fail(`${preset.id} has no headless launch line: ${preset.displayName} lists no ACP mode, so it can only join as a pull peer (ahub agents add ${preset.id} --pull)`);
|
|
67
|
+
const found = installed(preset);
|
|
68
|
+
if (!found.path) return fail(`${preset.executable} was not found on PATH, so nothing was written; install ${preset.displayName} first`);
|
|
69
|
+
if (!found.version && !pull) return fail(`${preset.executable} printed no version this command could read, so no identity pin can be written and nothing was written`);
|
|
70
|
+
const kind = as ?? preset.id;
|
|
71
|
+
const file = join(cwd, ".agenthub", "config.local.json");
|
|
72
|
+
// The hub ignores `adapters` in any file git does not confirm as untracked, so a write it would ignore is refused, never made.
|
|
73
|
+
if (configTracked(cwd, "config.local.json") !== false) return fail("git cannot confirm that .agenthub/config.local.json is untracked here, and the hub ignores adapters in a file it cannot confirm, so nothing was written; run this in a git repository that does not track that file");
|
|
74
|
+
let existing: Record<string, unknown> | undefined;
|
|
75
|
+
try { existing = readJsonFile(file); } catch (error) { return fail(`${(error as Error).message}; fix or move it, nothing was written`); }
|
|
76
|
+
const adapters = (existing?.adapters ?? {}) as Record<string, unknown>;
|
|
77
|
+
if (!adapters || typeof adapters !== "object" || Array.isArray(adapters)) return fail("adapters in .agenthub/config.local.json is not an object, so nothing was written");
|
|
78
|
+
if (Object.hasOwn(adapters, kind)) return fail(`adapters.${kind} already exists in .agenthub/config.local.json; nothing was changed (use --as <kind> for another name)`);
|
|
79
|
+
const merged = { ...adapters, [kind]: pull ? presetPullDeclaration(preset, found.path) : presetDeclaration(preset, found.path, found.version!) };
|
|
80
|
+
try { readConfiguredAdapters(merged, [...KNOWN_PEERS]); } catch (error) { return fail(`${(error as Error).message}; nothing was written`); }
|
|
81
|
+
mkdirSync(join(cwd, ".agenthub"), { recursive: true });
|
|
82
|
+
atomicPrivateJSON(file, { ...(existing ?? {}), adapters: merged });
|
|
83
|
+
const { print, columns, ascii } = printer();
|
|
84
|
+
if (pull) {
|
|
85
|
+
// The hub never writes another tool's configuration: the registration is printed for the person to run (#1809 AC6).
|
|
86
|
+
print(new Report(columns, ascii).titled("ahub", "Agent preset (pull)")
|
|
87
|
+
.section("Result").bullet("ok", `wrote adapters.${kind} as a pull kind from the ${preset.id} preset (${preset.status === "verified" ? "verified" : "untested"})`)
|
|
88
|
+
.kv([["file", ".agenthub/config.local.json"], ["command", found.path]])
|
|
89
|
+
.note(`Register the hub's bridge in ${preset.displayName} yourself; this command ran nothing and wrote nothing outside .agenthub: ${registrationText(preset, process.execPath, BRIDGE_BUNDLE)}`)
|
|
90
|
+
.note("Restart the hub (ahub restart) to load the kind. It starts off roster, as a cloud peer that owns no task and is never pushed to.")
|
|
91
|
+
.next(`ahub roster add ${kind}`));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!preset.acp) return fail(`${preset.id} has no headless launch line`);
|
|
95
|
+
print(new Report(columns, ascii).titled("ahub", "Agent preset")
|
|
96
|
+
.section("Result").bullet("ok", `wrote adapters.${kind} from the ${preset.id} preset (${preset.status === "verified" ? "verified" : "untested"})`)
|
|
97
|
+
.kv([["file", ".agenthub/config.local.json"], ["command", found.path], ["pinned identity", `${preset.acp.identity.name} ${found.version}`]])
|
|
98
|
+
.note("The hub reads declarations at start: restart it (ahub restart) to load the kind. It starts off roster, headless, as a cloud peer that gets no PII work.")
|
|
99
|
+
.next(`ahub roster add ${kind}`));
|
|
100
|
+
}
|
package/src/cli/agents.ts
CHANGED
|
@@ -106,7 +106,7 @@ export function runAgents(args: string[], commands: Partial<Record<CompatId, rea
|
|
|
106
106
|
print(receipt);
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
|
-
if (sub !== undefined) fail("usage: ahub agents [--json] | ahub agents trust <id> <version> [--revoke]");
|
|
109
|
+
if (sub !== undefined) fail("usage: ahub agents [--json] | ahub agents --latest [--json] | ahub agents trust <id> <version> [--revoke] | ahub agents presets [--json] | ahub agents add <preset> [--as <kind>] [--pull]");
|
|
110
110
|
const rows = agentVersions(commands);
|
|
111
111
|
if (args.includes("--json")) return console.log(JSON.stringify(rows.map(row => ({ id: row.id, executable: row.executable ?? null, ...row.verdict, policy: row.policy })), null, 2));
|
|
112
112
|
print(new Report(columns, ascii).append(renderAgents(rows, columns, ascii)));
|
package/src/cli/attention.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface AttentionState {
|
|
|
4
4
|
approvals: readonly { id: string; peer?: string; expiresAt: number }[];
|
|
5
5
|
permissionDefaults: readonly { peer: string }[];
|
|
6
6
|
peers: Record<string, { state?: string; attached?: boolean; needsReview?: number; heldBy?: string }>;
|
|
7
|
-
budget:
|
|
7
|
+
budget: NonNullable<NeedsInput["budget"]>;
|
|
8
8
|
attentionMessages?: readonly { id?: string; peer?: string; important: boolean; since?: number }[];
|
|
9
9
|
storageBlocked?: boolean;
|
|
10
10
|
recoveryNeed?: { id?: string; running: boolean; since?: number };
|
|
@@ -17,7 +17,7 @@ export interface AttentionState {
|
|
|
17
17
|
}
|
|
18
18
|
/** Allowlisted adapter between console-owned facts and the shared body-free model. */
|
|
19
19
|
export function consoleNeeds(state: AttentionState, now: number): Needs {
|
|
20
|
-
const input: NeedsInput = { approvals: state.approvals.map(row => ({ id: row.id, peer: row.peer, expiresAt: row.expiresAt })), defaults: state.permissionDefaults.map(row => ({ peer: row.peer })), peers: Object.fromEntries(Object.entries(state.peers).map(([peer,row]) => [peer,{ state: row.state, attached: row.attached, needsReview: row.needsReview, heldBy: row.heldBy }])), budget: Object.fromEntries(Object.entries(state.budget).map(([peer,row]) => [peer,{ ...(row.paused ? { paused: { since: row.paused.since, resetsAt: row.paused.resetsAt } } : {}) }])), messages: (state.attentionMessages ?? []).map(row => ({ id: row.id, peer: row.peer, important: row.important, since: row.since })), storageBlocked: state.storageBlocked, recovery: state.recoveryNeed, questions: (state.questions ?? []).map(row => ({ set: row.set, peer: row.peer, since: row.created })) };
|
|
20
|
+
const input: NeedsInput = { approvals: state.approvals.map(row => ({ id: row.id, peer: row.peer, expiresAt: row.expiresAt })), defaults: state.permissionDefaults.map(row => ({ peer: row.peer })), peers: Object.fromEntries(Object.entries(state.peers).map(([peer,row]) => [peer,{ state: row.state, attached: row.attached, needsReview: row.needsReview, heldBy: row.heldBy }])), budget: Object.fromEntries(Object.entries(state.budget).map(([peer,row]) => [peer,{ ...(row.paused ? { paused: { since: row.paused.since, resetsAt: row.paused.resetsAt } } : {}), ...(Array.isArray(row.warnings) ? { warnings: row.warnings.map(w => ({ window: w.window, at: w.at })) } : {}) }])), messages: (state.attentionMessages ?? []).map(row => ({ id: row.id, peer: row.peer, important: row.important, since: row.since })), storageBlocked: state.storageBlocked, recovery: state.recoveryNeed, questions: (state.questions ?? []).map(row => ({ set: row.set, peer: row.peer, since: row.created })) };
|
|
21
21
|
const result = needs({ ...input, facts: state.attentionFacts, results: state.results }, now);
|
|
22
22
|
// Panel snapshots know each held row; enrich only ids, without changing the status-derived count.
|
|
23
23
|
const used = new Set<string | number>();
|
|
@@ -70,6 +70,7 @@ export function attentionCommand(item: NeedItem): string {
|
|
|
70
70
|
if (item.kind === "delivery") return `ahub queue list${item.id ? `; ahub queue show ${item.id}` : ""}`;
|
|
71
71
|
if (item.kind === "review") return `ahub task show ${item.id}; ahub review ${item.id} approved|changes_requested`;
|
|
72
72
|
if (item.kind === "offline") return `ahub status; ahub task show ${item.id}; ahub task assign ${item.id} <peer>`;
|
|
73
|
+
if (item.kind === "pane") return `${item.peer} waits for you in Orca: orca terminal switch --terminal ${item.id}`;
|
|
73
74
|
if (item.kind === "storage") return "ahub doctor";
|
|
74
75
|
if (item.kind === "recovery") return `ahub recovery status${item.id ? ` ${item.id}` : ""}`;
|
|
75
76
|
if (item.kind === "budget") return "ahub budget";
|
|
@@ -5,10 +5,15 @@ import { checkClaudeHome, discoverClaudeHomes, type ClaudeHomeProject, type Clau
|
|
|
5
5
|
import { checkClaudeProfileHook } from "./claude-profile-hook.ts";
|
|
6
6
|
|
|
7
7
|
export async function usedClaudeHomes(registry: Registry, home: string, env: NodeJS.ProcessEnv) {
|
|
8
|
-
const projects: ClaudeHomeProject[] = [], notices: string[] = [];
|
|
8
|
+
const projects: ClaudeHomeProject[] = [], notices: string[] = [], declared: { label: string; home: string }[] = [];
|
|
9
9
|
const registered = registry.list();
|
|
10
10
|
if (registered.length > 256) notices.push("Claude profile discovery is limited to the first 256 registered projects.");
|
|
11
11
|
for (const project of registered.slice(0, 256)) {
|
|
12
|
+
// #1810: a declared Claude home counts whether or not this project's hub is running.
|
|
13
|
+
try {
|
|
14
|
+
const scope = readInstanceRoleConfig(project.root);
|
|
15
|
+
for (const [label, account] of Object.entries(scope.accounts ?? {})) if (scope.catalog.definitionOf(account.kind, scope.instances)?.transport === "claude-channel") declared.push({ label, home: account.home });
|
|
16
|
+
} catch { /* an unreadable project config is reported below, only if its hub is running */ }
|
|
12
17
|
const control = readControl(project.stateDir);
|
|
13
18
|
if (!control?.instanceId) continue;
|
|
14
19
|
try {
|
|
@@ -18,7 +23,7 @@ export async function usedClaudeHomes(registry: Registry, home: string, env: Nod
|
|
|
18
23
|
projects.push({ root: project.root, stateDir: project.stateDir, instanceId: control.instanceId, claudePeers });
|
|
19
24
|
} catch { notices.push(`Claude profile evidence is unavailable for project ${project.id}.`); }
|
|
20
25
|
}
|
|
21
|
-
const found = await discoverClaudeHomes({ home, env, projects });
|
|
26
|
+
const found = await discoverClaudeHomes({ home, env, projects, declared });
|
|
22
27
|
return { ...found, complete: found.complete && !notices.length, notices: [...notices, ...found.notices] };
|
|
23
28
|
}
|
|
24
29
|
export async function autonomyHomeStatus(registry: Registry, home: string, env: NodeJS.ProcessEnv, packageRoot: string, probe: ClaudeHomeProbe) {
|
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { planAutonomy, autonomyRemovalKeys, autonomyStatus, autonomyPreset, type AutonomyOperation, type AutonomyPeer, type AutonomyFloorStatus } from "../hub/autonomy.ts";
|
|
4
4
|
import { configFingerprint, configSourceTexts } from "../hub/config-reload.ts";
|
|
5
5
|
import { configRefusal } from "../hub/config-trust.ts";
|
|
6
|
-
import { loadConfig } from "../hub/
|
|
6
|
+
import { loadConfig } from "../hub/config.ts";
|
|
7
7
|
import { validateEffectiveConfig } from "../hub/config-apply.ts";
|
|
8
8
|
import { readInstanceConfigLayers, readInstanceRoleConfig } from "../hub/instance-config.ts";
|
|
9
9
|
import { checkSettingValue, settingDef, settingText, writeAutonomyPreset } from "../hub/settings.ts";
|
package/src/cli/bench.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { taskRecords } from "../hub/research.ts";
|
|
|
10
10
|
import { appendBench, BENCH_SCHEMA, memoryMode, type MemoryMode, parseSuite, suiteHash, type Attempt, type AttemptError, type AttemptMetrics, type Fingerprint, type Outcome, type SuiteTask } from "../hub/bench.ts";
|
|
11
11
|
import { hubHome, realPath } from "../hub/project.ts";
|
|
12
12
|
import { processSignature } from "../pi/process-signature.ts";
|
|
13
|
-
import { loadConfig } from "../hub/
|
|
13
|
+
import { loadConfig } from "../hub/config.ts";
|
|
14
14
|
import { addonState, detectTooling, type Addon, type AddonName } from "../hub/tooling.ts";
|
|
15
15
|
import { VERSION } from "../version.ts";
|
|
16
16
|
import { warnLine } from "./warn-line.ts";
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { AdapterDefinition } from "../adapters/registry-types.ts";
|
|
2
|
+
|
|
3
|
+
const peerId = (value: unknown): value is string => typeof value === "string" && /^[a-z][a-z0-9-]*$/.test(value);
|
|
4
|
+
const errors = [
|
|
5
|
+
"only the person may renew quota; run ahub budget renew in a person terminal",
|
|
6
|
+
"renew requires a peer and exactly one mode; run ahub budget renew <peer> --reset or --switched",
|
|
7
|
+
"unknown peer; choose a peer shown by ahub budget",
|
|
8
|
+
"this peer has no renewable quota; inspect ahub budget",
|
|
9
|
+
"quota was not renewed during recovery or shutdown; retry when the hub is ready",
|
|
10
|
+
"quota renewal did not finish; inspect ahub budget and retry when the hub is ready",
|
|
11
|
+
"budget renewal was not saved; a task handoff may still be running. Check ahub status and retry ahub budget renew after the handoff settles",
|
|
12
|
+
];
|
|
13
|
+
const codexUnverified = "Codex thread continuity after switching accounts is unverified. Check the checkpoint and task board before restarting.";
|
|
14
|
+
|
|
15
|
+
interface RenewStatus {
|
|
16
|
+
projectId?: unknown;
|
|
17
|
+
peers?: Record<string, { state?: string }>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface BudgetRenewalView {
|
|
21
|
+
ok: boolean;
|
|
22
|
+
account?: string;
|
|
23
|
+
mode: "reset" | "switched";
|
|
24
|
+
homes?: { peer: string; result: "different" | "unknown" }[];
|
|
25
|
+
moved?: { id: number; role: "owner" | "reviewer"; to: string | null; from?: string }[];
|
|
26
|
+
lines: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function budgetRenewalScope(projectId: unknown): string | undefined {
|
|
30
|
+
if (typeof projectId === "string" && /^p_[0-9a-f]+$/.test(projectId)) return `ahub --project ${projectId}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function budgetRenewalView(input: {
|
|
34
|
+
peer: string;
|
|
35
|
+
mode: BudgetRenewalView["mode"];
|
|
36
|
+
reply: any;
|
|
37
|
+
status: RenewStatus;
|
|
38
|
+
callerHomeIssue?: string;
|
|
39
|
+
definition: (peer: string) => AdapterDefinition | undefined;
|
|
40
|
+
}): BudgetRenewalView {
|
|
41
|
+
const { peer, mode, reply, status, callerHomeIssue, definition } = input;
|
|
42
|
+
const scope = budgetRenewalScope(status.projectId);
|
|
43
|
+
const lines: string[] = [];
|
|
44
|
+
const readStatus = scope && `${scope} status`;
|
|
45
|
+
const renew = scope && `${scope} budget renew ${peer} --${mode}`;
|
|
46
|
+
const account = peerId(reply.account) ? reply.account : undefined;
|
|
47
|
+
const active = Object.entries(status.peers ?? {}).filter(([id, row]) =>
|
|
48
|
+
peerId(id) && ["idle", "busy", "paused", "starting"].includes(row?.state ?? ""));
|
|
49
|
+
const launch = (id: string): string | undefined => {
|
|
50
|
+
const def = definition(id);
|
|
51
|
+
const command = def?.cli.command;
|
|
52
|
+
if (!scope || !peerId(command) || !def?.cli.entry) return undefined;
|
|
53
|
+
return `${scope} ${command}${id === command ? "" : ` --as ${id}`}`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (reply.ok !== true) {
|
|
57
|
+
const homes: NonNullable<BudgetRenewalView["homes"]> = Array.isArray(reply.homes)
|
|
58
|
+
? reply.homes.flatMap((row: any) => peerId(row?.peer) && (row.result === "different" || row.result === "unknown")
|
|
59
|
+
? [{ peer: row.peer, result: row.result }] : [])
|
|
60
|
+
: [];
|
|
61
|
+
if (!homes.length) {
|
|
62
|
+
lines.push(errors.find(error => error === reply.error) ?? "Quota was not renewed. Check the running hub with ahub status and upgrade it if it does not support budget renewal.");
|
|
63
|
+
return { ok: false, mode, lines };
|
|
64
|
+
}
|
|
65
|
+
lines.push("Codex quota was not renewed. Any existing budget pause stays in place.");
|
|
66
|
+
for (const row of homes) lines.push(`${row.peer}: Codex home ${row.result}.`);
|
|
67
|
+
if (homes.some(row => row.result === "unknown")) {
|
|
68
|
+
lines.push(callerHomeIssue ?? "At least one hub-side home could not be verified. Wait for any active Codex review to finish and check the selected home before retrying.");
|
|
69
|
+
if (renew) lines.push(`Retry from the shell where the Codex home is selected: ${renew}`);
|
|
70
|
+
return { ok: false, mode, homes, lines };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
lines.push(codexUnverified,
|
|
74
|
+
"This stops the whole project hub. Hub-run agents stop and running turns may be interrupted. Down waits for shutdown, not for turns to finish. It can refuse if hub ownership or lifecycle admission is unavailable. Finish active turns first.");
|
|
75
|
+
const codex = active.filter(([id]) => definition(id)?.start.daemonPort === "codex-appserver").map(([id]) => id);
|
|
76
|
+
if (definition(peer)?.start.daemonPort === "codex-appserver" && !codex.includes(peer)) codex.push(peer);
|
|
77
|
+
if (!codex.length) codex.push("codex");
|
|
78
|
+
const firstId = codex[0]!;
|
|
79
|
+
const first = launch(firstId);
|
|
80
|
+
if (!scope || !renew || !first) {
|
|
81
|
+
lines.push("The project or Codex startup command could not be verified. Use ahub status to check the project, then retry renewal.");
|
|
82
|
+
return { ok: false, mode, homes, lines };
|
|
83
|
+
}
|
|
84
|
+
const down = `${scope} down`, up = `${scope} up --no-agents --no-console`;
|
|
85
|
+
lines.push("Run this outside any agent session, in the same shell where the new Codex home is selected.",
|
|
86
|
+
`${down} && ${up} && ${renew} && ${first}`,
|
|
87
|
+
`If down fails or refuses, check the hub before retrying: ${readStatus}`,
|
|
88
|
+
`If up fails after down, the renewal has not run. Check ${readStatus}, then retry ${up} before ${renew}.`,
|
|
89
|
+
`If renewal refuses, the new hub is running with no default agents started. Check the cause, then retry ${renew}. Only launch Codex after it succeeds.`,
|
|
90
|
+
`If the Codex launch fails after renewal succeeded, check ${readStatus} for its process and quota. Retry ${first} when the peer is offline.`);
|
|
91
|
+
const others = active.map(([id]) => id).filter(id =>
|
|
92
|
+
id !== firstId && definition(id)?.start.daemonPort !== "reviewer-print");
|
|
93
|
+
if (others.length) lines.push("Reopen non-Codex sessions even if renewal needs another attempt. Launch remaining Codex peers after renewal succeeds, from the new-home shell. Use another terminal if a launch takes over this one.");
|
|
94
|
+
for (const id of others) {
|
|
95
|
+
const adapter = definition(id);
|
|
96
|
+
const command = adapter?.start.daemonPort === "codex-appserver" || adapter?.start.forms.length === 1 ? launch(id) : undefined;
|
|
97
|
+
lines.push(command ? `${id}: ${command}` : `${id}: reopen or reconnect its session; the hub could not verify a start command. Check ${readStatus}.`);
|
|
98
|
+
if (command && adapter?.transport === "claude-channel") lines.push("This Claude command does not request the earlier conversation.");
|
|
99
|
+
}
|
|
100
|
+
return { ok: false, mode, homes, lines };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const moved: NonNullable<BudgetRenewalView["moved"]> = Array.isArray(reply.moved)
|
|
104
|
+
? reply.moved.flatMap((row: any) => Number.isSafeInteger(row?.id) && row.id > 0 && (row.role === "owner" || row.role === "reviewer")
|
|
105
|
+
? [{ id: row.id, role: row.role, to: peerId(row.to) ? row.to : null, ...(peerId(row.from) ? { from: row.from } : {}) }] : [])
|
|
106
|
+
: [];
|
|
107
|
+
const claudeSoftGateOff = mode === "switched" && typeof reply.softQuota === "string";
|
|
108
|
+
lines.push(`${account ?? peer} quota renewed.${claudeSoftGateOff ? "" : " The budget gate remains active."}`);
|
|
109
|
+
for (const row of moved) {
|
|
110
|
+
lines.push(`Task ${row.id}: ${row.role} stays with ${row.to ?? "no assigned peer"}.`);
|
|
111
|
+
if (scope && row.from && definition(row.from)) lines.push(`After checking the board, take it back with: ${scope} task assign ${row.id} ${row.from} --role ${row.role}`);
|
|
112
|
+
else if (scope) lines.push(`The earlier peer is unavailable or was not recorded. Check the task before reassigning: ${scope} task show ${row.id}`);
|
|
113
|
+
}
|
|
114
|
+
if (claudeSoftGateOff) {
|
|
115
|
+
lines.push("Claude quota stays unknown after switching. Its soft gate is off. A hard refusal still pauses Claude, and you can supply a value with ahub budget set.");
|
|
116
|
+
}
|
|
117
|
+
if (reply.homeComparison === "same") {
|
|
118
|
+
const pending = Array.isArray(reply.pending) ? reply.pending.filter(peerId) : [];
|
|
119
|
+
lines.push(codexUnverified, "Matching homes do not prove that an existing app-server loaded the new login. Its soft readings are ignored until a process started after renewal reports quota.");
|
|
120
|
+
for (const id of pending) {
|
|
121
|
+
const command = launch(id);
|
|
122
|
+
if (!command) continue;
|
|
123
|
+
if (active.some(([activeId]) => activeId === id)) {
|
|
124
|
+
lines.push(`${id}: finish or stop its current turn, exit its own Codex TUI, and wait for offline in ${readStatus}. Then run: ${command}`);
|
|
125
|
+
} else lines.push(`${id}: start it when needed with: ${command}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { ok: true, ...(account ? { account } : {}), mode, moved, lines };
|
|
129
|
+
}
|
package/src/cli/claude-homes.ts
CHANGED
|
@@ -5,8 +5,9 @@ import { launcherOf, recordPath, MAX_COMMAND_MS, type ProcessIdentity } from "./
|
|
|
5
5
|
import { CLAUDE_PLUGIN_INVENTORY, PLUGIN, nextStep, pluginState, type InstalledPlugin, type Marketplace, type PluginState, type SetupStep } from "./setup.ts";
|
|
6
6
|
import { checkClaudeProfileHook, type ClaudeProfileHookCheck, type ClaudeProfileHookOptions } from "./claude-profile-hook.ts";
|
|
7
7
|
|
|
8
|
-
export type ClaudeHomeSource = "environment" | "default" | "recorded-launch";
|
|
9
|
-
|
|
8
|
+
export type ClaudeHomeSource = "environment" | "default" | "recorded-launch" | "declared";
|
|
9
|
+
/** `label` (#1810) is the declared account label of a home the person declared in `accounts`; setup shows it beside the home and the hub never derives one. */
|
|
10
|
+
export interface ClaudeHome { path: string; exists: boolean; sources: ClaudeHomeSource[]; label?: string }
|
|
10
11
|
/** The caller selects Claude channel peers from the resolved project catalog, never from an id spelling. */
|
|
11
12
|
export interface ClaudeHomeProject { root: string; stateDir: string; instanceId: string; claudePeers: readonly string[] }
|
|
12
13
|
export interface ClaudeHomeDiscovery { homes: ClaudeHome[]; notices: string[]; complete: boolean }
|
|
@@ -15,6 +16,8 @@ export interface ClaudeHomeDiscoveryInput {
|
|
|
15
16
|
env: NodeJS.ProcessEnv;
|
|
16
17
|
projects?: readonly ClaudeHomeProject[];
|
|
17
18
|
processIdentity?: ProcessIdentity;
|
|
19
|
+
/** #1810: declared Claude account homes, added to the homes discovered below. A declared home is selected whether or not it exists yet, and no profile directory is scanned. */
|
|
20
|
+
declared?: readonly { label: string; home: string }[];
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
// ponytail: 128 live launch candidates and 1 MiB per private record file bound local discovery;
|
|
@@ -28,7 +31,7 @@ export async function discoverClaudeHomes(input: ClaudeHomeDiscoveryInput): Prom
|
|
|
28
31
|
const homes = new Map<string, ClaudeHome>(), notices: string[] = [];
|
|
29
32
|
let complete = true, candidates = 0;
|
|
30
33
|
const unavailable = (message: string) => { complete = false; if (!notices.includes(message)) notices.push(message); };
|
|
31
|
-
const add = (value: unknown, source: ClaudeHomeSource, requireExisting = false) => {
|
|
34
|
+
const add = (value: unknown, source: ClaudeHomeSource, requireExisting = false, label?: string) => {
|
|
32
35
|
if (!validPath(value)) { unavailable("A Claude configuration home path is invalid; no home was selected from that evidence."); return; }
|
|
33
36
|
try {
|
|
34
37
|
const info = statSync(value, { throwIfNoEntry: false });
|
|
@@ -36,14 +39,15 @@ export async function discoverClaudeHomes(input: ClaudeHomeDiscoveryInput): Prom
|
|
|
36
39
|
if (!info && requireExisting) return;
|
|
37
40
|
const path = info ? realPath(value) : value;
|
|
38
41
|
const previous = homes.get(path);
|
|
39
|
-
if (previous) { if (!previous.sources.includes(source)) previous.sources.push(source); }
|
|
40
|
-
else homes.set(path, { path, exists: !!info, sources: [source] });
|
|
42
|
+
if (previous) { if (!previous.sources.includes(source)) previous.sources.push(source); if (label !== undefined && previous.label === undefined) previous.label = label; }
|
|
43
|
+
else homes.set(path, { path, exists: !!info, sources: [source], ...(label !== undefined ? { label } : {}) });
|
|
41
44
|
} catch { unavailable("A selected Claude configuration home could not be inspected."); }
|
|
42
45
|
};
|
|
43
46
|
if (input.env.CLAUDE_CONFIG_DIR !== undefined && input.env.CLAUDE_CONFIG_DIR !== "") add(input.env.CLAUDE_CONFIG_DIR, "environment");
|
|
44
47
|
else if (validPath(input.home)) add(join(input.home, ".claude"), "default", true);
|
|
45
48
|
else unavailable("The user home is unavailable; no default Claude home was selected.");
|
|
46
49
|
|
|
50
|
+
for (const declared of input.declared ?? []) add(declared.home, "declared", false, declared.label);
|
|
47
51
|
for (const project of input.projects ?? []) {
|
|
48
52
|
if (++candidates > MAX_CANDIDATES) { unavailable("Claude home discovery reached its live-launch candidate limit."); break; }
|
|
49
53
|
if (!validPath(project.root) || !validPath(project.stateDir) || !project.instanceId || project.instanceId.length > 256) {
|
|
@@ -2,12 +2,13 @@ import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, lstatSync, mkdi
|
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { dirname, isAbsolute, join } from "node:path";
|
|
4
4
|
import { factsHook } from "./facts-hook.ts";
|
|
5
|
+
import { replaceJsonValue } from "./json-text-spans.ts";
|
|
5
6
|
import { shellQuote } from "./shell-quote.ts";
|
|
6
7
|
import { stableBunRuntime, stablePackageRoot } from "./install-paths.ts";
|
|
7
8
|
import type { ClaudeHome } from "./claude-homes.ts";
|
|
8
9
|
|
|
9
10
|
export interface ClaudeProfileHookOptions { script?: string; runtime?: string; instruction?: boolean }
|
|
10
|
-
export interface ClaudeProfileHookCheck { state: "installed" | "missing" | "refused"; reason: string }
|
|
11
|
+
export interface ClaudeProfileHookCheck { state: "installed" | "missing" | "refused"; reason: string; outdated?: true }
|
|
11
12
|
export interface ClaudeProfileHookInstall extends ClaudeProfileHookCheck { changed: boolean }
|
|
12
13
|
const MAX_SETTINGS_BYTES = 1024 * 1024;
|
|
13
14
|
const validPath = (value: unknown): value is string => typeof value === "string" && value.length > 0 && value.length <= 4096 && isAbsolute(value) && !/[\x00-\x1f\x7f]/.test(value);
|
|
@@ -24,10 +25,21 @@ interface HookPlan {
|
|
|
24
25
|
source?: { info: Stats; digest: string };
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
const PROFILE_GUARD = 'if [ -n "${AGENTHUB_STATE_DIR-}" ] && [ -n "${AGENTHUB_PEER_ID-}" ] && [ -z "${AGENTHUB_LAUNCH_ID+x}" ]; then exec ';
|
|
29
|
+
const PROFILE_GUARD_END = "; fi";
|
|
30
|
+
|
|
31
|
+
function profileInvocation(runtime: string, script: string): string {
|
|
32
|
+
return `${shellQuote(runtime)} ${shellQuote(script)} --run`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function profileCommand(runtime: string, script: string): string {
|
|
36
|
+
return `${PROFILE_GUARD}${profileInvocation(runtime, script)}${PROFILE_GUARD_END}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
function hookEntry(options: ClaudeProfileHookOptions): Record<string, unknown> {
|
|
28
40
|
const script = options.script ?? join(stablePackageRoot(join(import.meta.dir, "../..")), "src/cli/claude-profile-hook.ts"), runtime = options.runtime ?? stableBunRuntime();
|
|
29
41
|
if (!validPath(script) || !validPath(runtime)) throw new Error("invalid profile hook command");
|
|
30
|
-
return { matcher: "*", hooks: [{ type: "command", command:
|
|
42
|
+
return { matcher: "*", hooks: [{ type: "command", command: profileCommand(runtime, script), timeout: 5 }] };
|
|
31
43
|
}
|
|
32
44
|
|
|
33
45
|
function instructionEntry(options: ClaudeProfileHookOptions): Record<string, unknown> {
|
|
@@ -53,11 +65,13 @@ function managedProfileHook(candidate: unknown): ManagedProfileHook | undefined
|
|
|
53
65
|
if (!object(candidate) || !Array.isArray(candidate.hooks) || candidate.hooks.length !== 1) return;
|
|
54
66
|
const hook = candidate.hooks[0];
|
|
55
67
|
if (!object(hook) || hook.type !== "command" || typeof hook.command !== "string") return;
|
|
56
|
-
const
|
|
68
|
+
const guarded = hook.command.startsWith(PROFILE_GUARD) && hook.command.endsWith(PROFILE_GUARD_END);
|
|
69
|
+
const invocation = guarded ? hook.command.slice(PROFILE_GUARD.length, -PROFILE_GUARD_END.length) : hook.command;
|
|
70
|
+
const match = /^'((?:[^']|'\\'')*)' '((?:[^']|'\\'')*)' --run$/.exec(invocation);
|
|
57
71
|
if (!match) return;
|
|
58
72
|
const runtime = match[1]!.replace(/'\\''/g, "'"), script = match[2]!.replace(/'\\''/g, "'");
|
|
59
73
|
if (!validPath(runtime) || !validPath(script) || !script.endsWith("/src/cli/claude-profile-hook.ts")
|
|
60
|
-
|| hook.command !==
|
|
74
|
+
|| hook.command !== (guarded ? profileCommand(runtime, script) : profileInvocation(runtime, script))) return;
|
|
61
75
|
return { entry: candidate, hook, runtime, script };
|
|
62
76
|
}
|
|
63
77
|
|
|
@@ -65,7 +79,7 @@ function hookPathPresent(file: string): boolean {
|
|
|
65
79
|
try { return statSync(file).isFile(); } catch { return false; }
|
|
66
80
|
}
|
|
67
81
|
|
|
68
|
-
function settingsSource(file: string): { value: Record<string, unknown>; source?: HookPlan["source"] } {
|
|
82
|
+
function settingsSource(file: string): { value: Record<string, unknown>; text?: string; source?: HookPlan["source"] } {
|
|
69
83
|
let fd: number | undefined;
|
|
70
84
|
try {
|
|
71
85
|
fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
@@ -73,9 +87,9 @@ function settingsSource(file: string): { value: Record<string, unknown>; source?
|
|
|
73
87
|
if (!info.isFile() || info.nlink !== 1 || !owned(info) || info.size > MAX_SETTINGS_BYTES) throw new Error("unsafe settings");
|
|
74
88
|
const bytes = Buffer.alloc(MAX_SETTINGS_BYTES + 1), count = readSync(fd, bytes, 0, bytes.length, 0);
|
|
75
89
|
if (count > MAX_SETTINGS_BYTES) throw new Error("oversized settings");
|
|
76
|
-
const content = bytes.subarray(0, count), value: unknown = JSON.parse(
|
|
90
|
+
const content = bytes.subarray(0, count), text = content.toString("utf8"), value: unknown = JSON.parse(text);
|
|
77
91
|
if (!object(value)) throw new Error("invalid settings");
|
|
78
|
-
return { value, source: { info, digest: createHash("sha256").update(content).digest("hex") } };
|
|
92
|
+
return { value, text, source: { info, digest: createHash("sha256").update(content).digest("hex") } };
|
|
79
93
|
} catch (error) {
|
|
80
94
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") return { value: {} };
|
|
81
95
|
throw error;
|
|
@@ -96,7 +110,7 @@ function planClaudeProfileHook(home: ClaudeHome, options: ClaudeProfileHookOptio
|
|
|
96
110
|
parent = lstatSync(dirname(home.path), { throwIfNoEntry: false });
|
|
97
111
|
if (!parent?.isDirectory() || parent.isSymbolicLink() || !owned(parent)) return refuse("The selected Claude home's parent is unsafe or unavailable.");
|
|
98
112
|
}
|
|
99
|
-
const { value, source } = settingsSource(file);
|
|
113
|
+
const { value, text, source } = settingsSource(file);
|
|
100
114
|
if (value.disableAllHooks === true) return refuse("Claude has disableAllHooks enabled; the profile hook cannot be installed.");
|
|
101
115
|
if (value.disableAllHooks !== undefined && typeof value.disableAllHooks !== "boolean") return refuse("Claude's hook enablement setting is malformed.");
|
|
102
116
|
if (value.hooks !== undefined && !object(value.hooks)) return refuse("Claude's hook configuration is malformed.");
|
|
@@ -106,6 +120,8 @@ function planClaudeProfileHook(home: ClaudeHome, options: ClaudeProfileHookOptio
|
|
|
106
120
|
const managed = existing.map(managedProfileHook), first = managed.find(candidate => candidate !== undefined);
|
|
107
121
|
const count = managed.filter(candidate => candidate !== undefined).length;
|
|
108
122
|
const stale = managed.some(candidate => candidate && (!hookPathPresent(candidate.runtime) || !hookPathPresent(candidate.script)));
|
|
123
|
+
const legacy = count === 1 && first !== undefined && first.hook.command === profileInvocation(first.runtime, first.script);
|
|
124
|
+
const outdated = legacy && !stale && profileCommand(first.runtime, first.script) === expectedCommand;
|
|
109
125
|
const configured = count === 1 && first?.hook.command === expectedCommand && !stale;
|
|
110
126
|
const normalized = existing.flatMap((candidate, index) => {
|
|
111
127
|
const owned = managed[index];
|
|
@@ -133,13 +149,17 @@ function planClaudeProfileHook(home: ClaudeHome, options: ClaudeProfileHookOptio
|
|
|
133
149
|
nextHooks[event] = rewritten;
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
|
-
const next = configured && instructionConfigured ? undefined
|
|
152
|
+
const next = configured && instructionConfigured ? undefined
|
|
153
|
+
: legacy && instructionConfigured && text !== undefined
|
|
154
|
+
? replaceJsonValue(text, ["hooks", "PreToolUse", managed.indexOf(first), "hooks", 0, "command"], expectedCommand)
|
|
155
|
+
: `${JSON.stringify({ ...value, hooks: nextHooks }, null, 2)}\n`;
|
|
137
156
|
if (next !== undefined && Buffer.byteLength(next, "utf8") > MAX_SETTINGS_BYTES) return refuse("Claude's settings would exceed the bounded profile settings size.");
|
|
138
157
|
let reason = "The project-neutral profile hook is not configured for this install; run ahub setup.";
|
|
139
158
|
if (count > 1) reason = "Duplicate managed profile hooks need normalization; run ahub setup.";
|
|
140
159
|
if (stale) reason = "A managed profile hook script or runtime is missing; run ahub setup to refresh the selected home's hook.";
|
|
160
|
+
if (outdated) reason = "The installed project-neutral profile hook is outdated; run ahub setup to add the shell guard.";
|
|
141
161
|
if (configured) reason = "The project-neutral profile hook is configured; this does not prove live permission enforcement.";
|
|
142
|
-
return { file, home: directory, parent, source, next, check: { state: configured && instructionConfigured ? "installed" : "missing", reason } };
|
|
162
|
+
return { file, home: directory, parent, source, next, check: { state: (configured || outdated) && instructionConfigured ? "installed" : "missing", reason, ...(outdated ? { outdated: true as const } : {}) } };
|
|
143
163
|
} catch { return refuse("Claude profile settings could not be safely inspected; no settings were changed."); }
|
|
144
164
|
}
|
|
145
165
|
|
|
@@ -150,7 +170,7 @@ export function checkClaudeProfileHook(home: ClaudeHome, options: ClaudeProfileH
|
|
|
150
170
|
/** Only the selected home is created; unrelated profile directories and settings are never touched. */
|
|
151
171
|
export function installClaudeProfileHook(home: ClaudeHome, options: ClaudeProfileHookOptions = {}): ClaudeProfileHookInstall {
|
|
152
172
|
const plan = planClaudeProfileHook(home, options);
|
|
153
|
-
if (plan.
|
|
173
|
+
if (plan.next === undefined) return { ...plan.check, changed: false };
|
|
154
174
|
const temporary = join(home.path, `.agent-hub-profile-hook-${randomUUID()}.tmp`);
|
|
155
175
|
let created: Stats | undefined;
|
|
156
176
|
try {
|