@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
|
@@ -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) {
|
|
@@ -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) {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { NativeCliDispatchEntry } from "../adapters/definitions/native-cli-entry-types.ts";
|
|
2
|
+
import type { CommandContext, SdlcReceiptOutput } from "./command-context.ts";
|
|
3
|
+
|
|
4
|
+
type Loader = () => Promise<{ run(context: CommandContext, receiptOutput?: SdlcReceiptOutput): void | Promise<void> }>;
|
|
5
|
+
|
|
6
|
+
const commandLoaders: Readonly<Partial<Record<string, Loader>>> = Object.freeze({
|
|
7
|
+
ui: () => import("./commands/ui.ts"),
|
|
8
|
+
setup: () => import("./commands/setup.ts"),
|
|
9
|
+
sdlc: () => import("./commands/sdlc.ts"),
|
|
10
|
+
down: () => import("./commands/down.ts"),
|
|
11
|
+
doctor: () => import("./commands/doctor.ts"),
|
|
12
|
+
recovery: () => import("./commands/recovery.ts"),
|
|
13
|
+
up: () => import("./commands/up.ts"),
|
|
14
|
+
backlog: () => import("./commands/backlog.ts"),
|
|
15
|
+
roadmap: () => import("./commands/roadmap.ts"),
|
|
16
|
+
structure: () => import("./commands/structure.ts"),
|
|
17
|
+
study: () => import("./commands/study.ts"),
|
|
18
|
+
task: () => import("./commands/task.ts"),
|
|
19
|
+
permission: () => import("./commands/permission.ts"),
|
|
20
|
+
autonomy: () => import("./commands/autonomy.ts"),
|
|
21
|
+
settings: () => import("./commands/settings.ts"),
|
|
22
|
+
permit: () => import("./commands/permit.ts"),
|
|
23
|
+
answer: () => import("./commands/answer.ts"),
|
|
24
|
+
results: () => import("./commands/results.ts"),
|
|
25
|
+
pet: () => import("./commands/pet.ts"),
|
|
26
|
+
roles: () => import("./commands/roles.ts"),
|
|
27
|
+
status: () => import("./commands/status.ts"),
|
|
28
|
+
logs: () => import("./commands/logs.ts"),
|
|
29
|
+
export: () => import("./commands/export.ts"),
|
|
30
|
+
bench: () => import("./commands/bench.ts"),
|
|
31
|
+
memory: () => import("./commands/memory.ts"),
|
|
32
|
+
goal: () => import("./commands/goal.ts"),
|
|
33
|
+
research: () => import("./commands/research.ts"),
|
|
34
|
+
report: () => import("./commands/report.ts"),
|
|
35
|
+
specs: () => import("./commands/specs.ts"),
|
|
36
|
+
worktrees: () => import("./commands/worktrees.ts"),
|
|
37
|
+
usage: () => import("./commands/usage.ts"),
|
|
38
|
+
instructed: () => import("./commands/instructed.ts"),
|
|
39
|
+
"instruction-hook": () => import("./commands/instruction-hook.ts"),
|
|
40
|
+
facts: () => import("./commands/facts.ts"),
|
|
41
|
+
"check-path": () => import("./commands/check-path.ts"),
|
|
42
|
+
turns: () => import("./commands/turns.ts"),
|
|
43
|
+
undo: () => import("./commands/undo.ts"),
|
|
44
|
+
kill: () => import("./commands/kill.ts"),
|
|
45
|
+
reset: () => import("./commands/reset.ts"),
|
|
46
|
+
role: () => import("./commands/role.ts"),
|
|
47
|
+
agents: () => import("./commands/agents.ts"),
|
|
48
|
+
accounts: () => import("./commands/accounts.ts"),
|
|
49
|
+
upgrade: () => import("./commands/upgrade.ts"),
|
|
50
|
+
restart: () => import("./commands/restart.ts"),
|
|
51
|
+
"recovery-run": () => import("./commands/recovery-run.ts"),
|
|
52
|
+
help: () => import("./commands/help.ts"),
|
|
53
|
+
projects: () => import("./commands/projects.ts"),
|
|
54
|
+
manager: () => import("./commands/manager.ts"),
|
|
55
|
+
init: () => import("./commands/init.ts"),
|
|
56
|
+
daemon: () => import("./commands/daemon.ts"),
|
|
57
|
+
host: () => import("./commands/host.ts"),
|
|
58
|
+
console: () => import("./commands/console.ts"),
|
|
59
|
+
guidance: () => import("./commands/guidance.ts"),
|
|
60
|
+
lineage: () => import("./commands/lineage.ts"),
|
|
61
|
+
model: () => import("./commands/model.ts"),
|
|
62
|
+
models: () => import("./commands/models.ts"),
|
|
63
|
+
say: () => import("./commands/say.ts"),
|
|
64
|
+
queue: () => import("./commands/queue.ts"),
|
|
65
|
+
watch: () => import("./commands/watch.ts"),
|
|
66
|
+
tail: () => import("./commands/tail.ts"),
|
|
67
|
+
budget: () => import("./commands/budget.ts"),
|
|
68
|
+
release: () => import("./commands/release.ts"),
|
|
69
|
+
releases: () => import("./commands/releases.ts"),
|
|
70
|
+
smoke: () => import("./commands/smoke.ts"),
|
|
71
|
+
room: () => import("./commands/room.ts"),
|
|
72
|
+
broker: () => import("./commands/broker.ts"),
|
|
73
|
+
source: () => import("./commands/source.ts"),
|
|
74
|
+
schedule: () => import("./commands/schedule.ts"),
|
|
75
|
+
capabilities: () => import("./commands/capabilities.ts"),
|
|
76
|
+
learn: () => import("./commands/learn.ts"),
|
|
77
|
+
intake: () => import("./commands/intake.ts"),
|
|
78
|
+
deliverables: () => import("./commands/deliverables.ts"),
|
|
79
|
+
board: () => import("./commands/board.ts"),
|
|
80
|
+
review: () => import("./commands/review.ts"),
|
|
81
|
+
remember: () => import("./commands/remember.ts"),
|
|
82
|
+
ask: () => import("./commands/ask.ts"),
|
|
83
|
+
route: () => import("./commands/route.ts"),
|
|
84
|
+
pause: () => import("./commands/pause.ts"),
|
|
85
|
+
resume: () => import("./commands/resume.ts"),
|
|
86
|
+
stop: () => import("./commands/stop.ts"),
|
|
87
|
+
peer: () => import("./commands/peer.ts"),
|
|
88
|
+
title: () => import("./commands/title.ts"),
|
|
89
|
+
roster: () => import("./commands/roster.ts"),
|
|
90
|
+
completion: () => import("./commands/completion.ts"),
|
|
91
|
+
"--version": () => import("./commands/version.ts"),
|
|
92
|
+
version: () => import("./commands/version.ts"),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/** Resolve built-in commands and native entry keys without importing a command body. */
|
|
96
|
+
export function commandLoader(name: string, nativeEntries: readonly NativeCliDispatchEntry[]): Loader | undefined {
|
|
97
|
+
if (Object.hasOwn(commandLoaders, name)) return commandLoaders[name];
|
|
98
|
+
const native = nativeEntries.find(entry => entry.command === name);
|
|
99
|
+
if (!native) return undefined;
|
|
100
|
+
return async () => {
|
|
101
|
+
const { runNative } = await import("./commands/native.ts");
|
|
102
|
+
return { run: context => runNative(context, native) };
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type Refuse = (message: string) => never;
|
|
107
|
+
export function selectCommand(raw: readonly string[], fail: Refuse,
|
|
108
|
+
repeatedProject: (fail: Refuse) => never, missingProject: (fail: Refuse) => never): { argv: string[]; selector?: string; liveTest: boolean; given: string } {
|
|
109
|
+
const argv = [...raw];
|
|
110
|
+
let selector: string | undefined;
|
|
111
|
+
let liveTest = false;
|
|
112
|
+
while (argv[0] === "--project" || argv[0] === "--live-test") {
|
|
113
|
+
if (argv.shift() === "--live-test") {
|
|
114
|
+
if (liveTest) fail("--live-test may appear only once");
|
|
115
|
+
liveTest = true;
|
|
116
|
+
} else {
|
|
117
|
+
if (selector !== undefined) repeatedProject(fail);
|
|
118
|
+
selector = argv.shift();
|
|
119
|
+
if (!selector || selector.startsWith("--")) missingProject(fail);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { argv, selector, liveTest, given: argv[0] ?? "help" };
|
|
123
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { runAccountsImport } from "../accounts-import.ts";
|
|
2
|
+
import type { CommandContext } from "../command-context.ts";
|
|
3
|
+
|
|
4
|
+
export function run(context: CommandContext) {
|
|
5
|
+
// #1811 T4: person only through src/cli/identity.ts; it reads Orca once and writes nothing.
|
|
6
|
+
if (context.args[0] === "import") return runAccountsImport(context.args.slice(1), context.fail);
|
|
7
|
+
return context.fail("usage: ahub accounts import --from orca");
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { runAgents } from "../agents.ts";
|
|
2
|
+
import { runAgentsLatest } from "../agents-latest.ts";
|
|
3
|
+
import { runAgentsAdd, runAgentsPresets } from "../agents-presets.ts";
|
|
4
|
+
import { configuredCommands } from "../../adapters/compat.ts";
|
|
5
|
+
import { loadConfig } from "../../hub/config.ts";
|
|
6
|
+
import type { CommandContext } from "../command-context.ts";
|
|
7
|
+
|
|
8
|
+
export function run(context: CommandContext) {
|
|
9
|
+
const { args, cwd } = context;
|
|
10
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
11
|
+
// #1809 T1: both forms are person-only through src/cli/identity.ts (any `agents` argument but --json); neither loads the project config.
|
|
12
|
+
if (args[0] === "presets") return runAgentsPresets(args.slice(1), fail);
|
|
13
|
+
if (args[0] === "add") return runAgentsAdd(args.slice(1), cwd, fail);
|
|
14
|
+
const commands = configuredCommands(loadConfig(cwd));
|
|
15
|
+
// #1808 T5: the one network read, person-run (src/cli/identity.ts keeps an agent shell out of every `agents` form but a plain listing).
|
|
16
|
+
if (args.includes("--latest")) return runAgentsLatest(args, commands, fail);
|
|
17
|
+
return runAgents(args, commands, fail);
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { parseAnswerArgs } from "../answer-args.ts";
|
|
2
|
+
import { asciiMarkers } from "../console-state.ts";
|
|
3
|
+
import { renderAnswerReceipt, renderQuestions } from "../answer-output.ts";
|
|
4
|
+
import type { CommandContext } from "../command-context.ts";
|
|
5
|
+
|
|
6
|
+
export async function run(context: CommandContext) {
|
|
7
|
+
const { args, connect, outputOptions, printOutput } = context;
|
|
8
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
9
|
+
const options = outputOptions();
|
|
10
|
+
const operands = args.filter(arg => arg !== "--json" && !arg.startsWith("--color=") && arg !== "--full");
|
|
11
|
+
const hub = await connect();
|
|
12
|
+
try {
|
|
13
|
+
if (!operands.length) {
|
|
14
|
+
const reply = await hub.request({ t: "questions" });
|
|
15
|
+
if (reply.ok === false) return fail(String(reply.error ?? "questions are unavailable"));
|
|
16
|
+
const rows = Array.isArray(reply.questions) ? reply.questions : [];
|
|
17
|
+
if (options.json) return console.log(JSON.stringify(rows, null, 2));
|
|
18
|
+
return printOutput(renderQuestions(rows, options.columns, undefined, asciiMarkers(process.env)), options.color);
|
|
19
|
+
}
|
|
20
|
+
const parsed = parseAnswerArgs(operands);
|
|
21
|
+
if (!parsed.ok) return fail(parsed.error);
|
|
22
|
+
const reply = await hub.request({ t: "answer", surface: "terminal", questionSet: parsed.value.set, answers: parsed.value.answers, ...(parsed.value.instruction === undefined ? {} : { instructed: parsed.value.instruction }) });
|
|
23
|
+
if (reply.ok === false) return fail(String(reply.error ?? "the answer was refused"));
|
|
24
|
+
if (options.json) return console.log(JSON.stringify({ ok: true, questionSet: reply.questionSet, state: reply.state, ...(reply.instructed ? { actor: reply.actor, instructed: true } : {}) }));
|
|
25
|
+
printOutput(renderAnswerReceipt({ kind: "answer", set: reply.questionSet ?? parsed.value.set,
|
|
26
|
+
actor: reply.instructed && typeof reply.actor === "string" ? reply.actor : undefined }), options.color);
|
|
27
|
+
} finally { hub.close(); }
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { asciiMarkers } from "../console-state.ts";
|
|
2
|
+
import { renderAskAnswer } from "../answer-output.ts";
|
|
3
|
+
import type { CommandContext } from "../command-context.ts";
|
|
4
|
+
|
|
5
|
+
export async function run(context: CommandContext) {
|
|
6
|
+
const { args, connect, outputOptions, printOutput } = context;
|
|
7
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
8
|
+
const remember = args.includes("--remember");
|
|
9
|
+
const question = args.filter((a) => a !== "--remember").join(" ");
|
|
10
|
+
if (!question.trim()) fail("usage: ahub ask [--remember] <question...>");
|
|
11
|
+
const hub = await connect();
|
|
12
|
+
const res = await hub.request({ t: "ask", question, remember }, 75_000); // above the hub's own budget (probe + 45 s model call)
|
|
13
|
+
hub.close();
|
|
14
|
+
if (!res.ok) fail(res.error);
|
|
15
|
+
const options = outputOptions([]);
|
|
16
|
+
printOutput(renderAskAnswer(res, options.columns, undefined, asciiMarkers(process.env)), options.color);
|
|
17
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { terminalText } from "../console-state.ts";
|
|
2
|
+
import { autonomyEnvironment, runAutonomy } from "../autonomy.ts";
|
|
3
|
+
import { readAutonomyDefaults, writeAutonomyDefaults } from "../../hub/autonomy-defaults.ts";
|
|
4
|
+
import { prepareAutonomyProject, runAllProjectAutonomy, type PreparedAutonomyProject } from "../autonomy-projects.ts";
|
|
5
|
+
import { offlineAutonomyStatus } from "../autonomy-offline.ts";
|
|
6
|
+
import { autonomyHomeStatus } from "../autonomy-homes.ts";
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { ControlClient } from "../../hub/control-client.ts";
|
|
12
|
+
import { hubHome } from "../../hub/project.ts";
|
|
13
|
+
import { Registry } from "../../hub/registry.ts";
|
|
14
|
+
import { inspectProject } from "../../hub/lifecycle.ts";
|
|
15
|
+
import { createInterface } from "node:readline/promises";
|
|
16
|
+
import { assertLifecycleAvailable } from "../../hub/recovery-store.ts";
|
|
17
|
+
import type { CommandContext } from "../command-context.ts";
|
|
18
|
+
|
|
19
|
+
export async function run(context: CommandContext) {
|
|
20
|
+
const { args, cliDir, connect, cwd, registeredProject, stateDir } = context;
|
|
21
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
22
|
+
let hub: ControlClient | undefined;
|
|
23
|
+
let prepared: PreparedAutonomyProject | undefined, previewToken: string | undefined;
|
|
24
|
+
const registry = new Registry();
|
|
25
|
+
const rl = process.stdin.isTTY ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
26
|
+
try {
|
|
27
|
+
const environment = autonomyEnvironment(process.env, !!process.stdin.isTTY), home = hubHome();
|
|
28
|
+
if (args.includes("--all-projects")) {
|
|
29
|
+
assertLifecycleAvailable(cwd);
|
|
30
|
+
for (const project of registry.list()) assertLifecycleAvailable(project.root);
|
|
31
|
+
await runAllProjectAutonomy(args, { home, environment, projects: registry.list(),
|
|
32
|
+
prepare: (project, enabled) => prepareAutonomyProject(project, environment, enabled, registry),
|
|
33
|
+
ask: async prompt => rl ? rl.question(prompt) : null, print: line => console.log(terminalText(line)),
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const roots = [...registry.list().map(project => project.root), cwd], defaults = readAutonomyDefaults(home, roots);
|
|
38
|
+
const usage = await runAutonomy(args, {
|
|
39
|
+
environment,
|
|
40
|
+
request: async message => {
|
|
41
|
+
if (message.action === "preview") {
|
|
42
|
+
prepared?.close();
|
|
43
|
+
prepared = await prepareAutonomyProject(registeredProject(), environment, true, registry);
|
|
44
|
+
previewToken = randomUUID();
|
|
45
|
+
return { ok: true, confirmation: previewToken, lines: prepared.lines };
|
|
46
|
+
}
|
|
47
|
+
if (message.action === "on") {
|
|
48
|
+
if (!prepared || message.confirmation !== previewToken) return { ok: false, error: "autonomy preview is stale or missing" };
|
|
49
|
+
previewToken = undefined;
|
|
50
|
+
return { ok: true, lines: await prepared.apply() };
|
|
51
|
+
}
|
|
52
|
+
if (message.action === "off") {
|
|
53
|
+
prepared = await prepareAutonomyProject(registeredProject(), environment, false, registry);
|
|
54
|
+
return { ok: true, lines: await prepared.apply() };
|
|
55
|
+
}
|
|
56
|
+
const project = registry.list().find(row => row.root === cwd && row.stateDir === stateDir);
|
|
57
|
+
if (project && (await inspectProject(project)).state === "stopped") return offlineAutonomyStatus(project, environment);
|
|
58
|
+
hub ??= await connect(); return hub.request(message, 35_000);
|
|
59
|
+
},
|
|
60
|
+
ask: async prompt => { if (!rl) return null; try { return await rl.question(prompt); } catch { return null; } },
|
|
61
|
+
print: line => console.log(terminalText(line)),
|
|
62
|
+
contextLines: [...(defaults.notice ? [defaults.notice] : []), "On/off also changes this machine's autonomy default for new projects; --all-projects applies the change to every registered project."],
|
|
63
|
+
confirmPrompt: "Apply this project's preset and this machine's autonomy default? [y/N] ",
|
|
64
|
+
beforeApply: action => {
|
|
65
|
+
assertLifecycleAvailable(cwd);
|
|
66
|
+
if (action === "off" && defaults.fingerprint === "untrusted") console.log("Unsafe machine defaults are already ignored; their file was left unchanged.");
|
|
67
|
+
else writeAutonomyDefaults(home, action === "on", defaults.fingerprint, roots);
|
|
68
|
+
console.log(`Machine autonomy default: ${action}.`);
|
|
69
|
+
},
|
|
70
|
+
decorateStatus: async reply => {
|
|
71
|
+
const machine = readAutonomyDefaults(home, roots);
|
|
72
|
+
const profiles = await autonomyHomeStatus(registry, homedir(), process.env, join(cliDir, "..", ".."), (argv, options) => {
|
|
73
|
+
const result = spawnSync(argv[0]!, argv.slice(1), { encoding: "utf8", env: options.env, timeout: options.timeoutMs, maxBuffer: 1024 * 1024 });
|
|
74
|
+
return { status: result.status ?? -1, stdout: result.stdout ?? "" };
|
|
75
|
+
});
|
|
76
|
+
return { ...reply, status: { ...(reply.status as Record<string, unknown>), machineDefault: { enabled: machine.enabled, ...(machine.notice ? { notice: machine.notice } : {}) }, claudeHomes: profiles.homes, claudeHomeDiscoveryComplete: profiles.complete, claudeHomeNotices: profiles.notices },
|
|
77
|
+
lines: [...(reply.lines as string[]), `Machine autonomy default: ${machine.enabled ? "on" : "off"}.`, ...(machine.notice ? [machine.notice] : []), ...profiles.notices,
|
|
78
|
+
...profiles.homes.map(profile => `Claude home ${profile.home.path}: plugin ${profile.plugin.state}; hook ${profile.hook.state}. ${profile.hook.reason}`)] };
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
if (usage) fail(usage);
|
|
82
|
+
} finally { prepared?.close(); rl?.close(); hub?.close(); registry.close(); }
|
|
83
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parseBacklogReturn } from "../backlog-return-args.ts";
|
|
2
|
+
import { type Span } from "../console-state.ts";
|
|
3
|
+
import { renderBacklog } from "../output.ts";
|
|
4
|
+
import { renderBacklogResult, renderGroom } from "../task-output.ts";
|
|
5
|
+
import type { CommandContext } from "../command-context.ts";
|
|
6
|
+
|
|
7
|
+
export async function run(context: CommandContext) {
|
|
8
|
+
const { args, outputArguments, outputOptions, printOutput, showToolText, splitPresentation, taskOp } = context;
|
|
9
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
10
|
+
const split = splitPresentation(args, { edges: true }), operands = split.operands;
|
|
11
|
+
const [sub, id, revision, value, ...reason] = operands;
|
|
12
|
+
const present = outputOptions(split.flags); // before any request: an invalid --color must refuse before a mutation is sent
|
|
13
|
+
const shown = (render: (data: any, columns?: number, now?: number, ascii?: boolean) => Span[][]) => async (text: Promise<string>) => showToolText(render, await text, present);
|
|
14
|
+
if (sub === "list" && outputArguments().length === 1) {
|
|
15
|
+
// #399: a table by default; --json prints the hub's listing unchanged, and a refusal is printed as it came.
|
|
16
|
+
const options = outputOptions(), raw = await taskOp("hub_backlog_list", {});
|
|
17
|
+
if (options.json) return console.log(raw);
|
|
18
|
+
let cards: unknown;
|
|
19
|
+
try { cards = JSON.parse(raw); } catch { return console.log(raw); }
|
|
20
|
+
if (!Array.isArray(cards)) return console.log(raw);
|
|
21
|
+
return printOutput(renderBacklog(cards, options.columns, Date.now(), options.full), options.color);
|
|
22
|
+
}
|
|
23
|
+
if (sub === "groom" && operands.length === 1) return shown(renderGroom)(taskOp("hub_planner_groom", {}));
|
|
24
|
+
if (["return", "return-untouched"].includes(sub ?? "") && /^[1-9]\d*$/.test(id ?? "") && /^\d+$/.test(revision ?? "") && operands.length >= 4) {
|
|
25
|
+
// #1177: `--reserved <peer>` / `--unreserve` edit the reservation atomically with the return (fields.reserved); with neither, the arguments are what they always were.
|
|
26
|
+
const returned = parseBacklogReturn(operands.slice(3));
|
|
27
|
+
if (!returned.ok) return fail(returned.error);
|
|
28
|
+
return shown((data, columns, now, ascii) => renderBacklogResult("return-untouched", data, columns, now, ascii))(taskOp("hub_backlog_return_untouched", { id: Number(id), revision: Number(revision), reason: returned.value.reason, ...(returned.value.fields ? { fields: returned.value.fields } : {}) }));
|
|
29
|
+
}
|
|
30
|
+
if (sub === "add" && args.length >= 3) return console.log(await taskOp("hub_task_propose", { class: id, title: args.slice(2).join(" "), backlog: true }));
|
|
31
|
+
if (!/^[1-9]\d*$/.test(id ?? "")) fail("usage: ahub backlog list|add <class> <title...>|pull|return <id>|plan|pin <id> <revision> <value> <reason...>|undo <id> <revision>");
|
|
32
|
+
if (["pull", "return"].includes(sub ?? "") && operands.length === 2) return console.log(await taskOp(sub === "pull" ? "backlog_pull" : "backlog_return", { id }));
|
|
33
|
+
if (!/^\d+$/.test(revision ?? "")) fail("planning revision is required");
|
|
34
|
+
if (sub === "pull-ready" && operands.length >= 4) return shown((data, columns, now, ascii) => renderBacklogResult("pull-ready", data, columns, now, ascii))(taskOp("hub_backlog_pull", { id: Number(id), revision: Number(revision), reason: operands.slice(3).join(" ") }));
|
|
35
|
+
if (sub === "split" && value && reason.length) {
|
|
36
|
+
let parts: unknown;try { parts=JSON.parse(value); } catch { return fail("split parts must be JSON"); }
|
|
37
|
+
return shown((data, columns, now, ascii) => renderBacklogResult("split", data, columns, now, ascii))(taskOp("hub_backlog_split", { id: Number(id), revision: Number(revision), parts, reason: reason.join(" ") }));
|
|
38
|
+
}
|
|
39
|
+
if (sub === "undo" && operands.length === 3) return shown((data, columns, now, ascii) => renderBacklogResult("undo", data, columns, now, ascii))(taskOp("hub_backlog_undo", { id: Number(id), revision: Number(revision) }));
|
|
40
|
+
if (!["plan", "pin", "person"].includes(sub ?? "") || !value || !reason.length) fail("planning needs fields and a reason");
|
|
41
|
+
let fields: unknown;
|
|
42
|
+
try { fields = sub === "pin" ? { pinned: value === "true" ? true : value === "false" ? false : undefined } : sub === "person" ? { needsPerson: value === "true" ? true : value === "false" ? false : undefined } : JSON.parse(value); }
|
|
43
|
+
catch { return fail("planning fields must be JSON"); }
|
|
44
|
+
if ((sub === "pin" || sub === "person") && value !== "true" && value !== "false") fail(`${sub} must be true or false`);
|
|
45
|
+
return shown((data, columns, now, ascii) => renderBacklogResult(sub === "person" ? "plan" : sub as "plan" | "pin", data, columns, now, ascii))(taskOp("hub_backlog_plan", { id: Number(id), revision: Number(revision), fields, reason: reason.join(" ") }));
|
|
46
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { refuseUnsupportedExportFormat } from "./shared-refusals.ts";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { loadConfig } from "../../hub/config.ts";
|
|
4
|
+
import { armRuns, benchCompare, benchCsv, benchReport, formatCompare, formatReport as formatBenchReport, formatRuns, readRuns, runSummary, sameSuite, type MemoryMode } from "../../hub/bench.ts";
|
|
5
|
+
import { benchPreflight, defaultIo, runBench } from "../bench.ts";
|
|
6
|
+
import type { CommandContext } from "../command-context.ts";
|
|
7
|
+
|
|
8
|
+
export async function run(context: CommandContext) {
|
|
9
|
+
const { args, benchRunArgs, cwd, identity, invokedFrom, stateDir, takeFlags } = context;
|
|
10
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
11
|
+
// #251: benchmark suites run against the peers attached here, and their comparison across arms.
|
|
12
|
+
const json = args.includes("--json");
|
|
13
|
+
const [sub, ...rest] = args.filter((a) => a !== "--json");
|
|
14
|
+
if (sub === "run") {
|
|
15
|
+
const { one, addons, suite, repeat } = benchRunArgs(rest);
|
|
16
|
+
await benchPreflight(cwd, loadConfig(cwd).bench.enabled); // the suite's refs are checked once it is read
|
|
17
|
+
let interrupted = false;
|
|
18
|
+
const stop = () => { interrupted = true; console.log("stopping at the next check: the attempt in progress is recorded as interrupted (a task still open is named)"); };
|
|
19
|
+
process.on("SIGINT", stop);
|
|
20
|
+
try {
|
|
21
|
+
const run = await runBench({ cwd, stateDir, suitePath: resolve(invokedFrom, suite!), arm: one["--arm"]!.trim(), repeat, addons, ...(one["--memory"] ? { memory: one["--memory"] as MemoryMode } : {}), only: one["--tasks"]?.split(",").map((t) => t.trim()).filter(Boolean), stopped: () => interrupted }, defaultIo(stateDir, cwd, identity.role === "tools" ? identity.peer : undefined));
|
|
22
|
+
return console.log(formatBenchReport(benchReport(readRuns().filter((r) => r.header.run === run))).join("\n"));
|
|
23
|
+
} finally { process.off("SIGINT", stop); }
|
|
24
|
+
}
|
|
25
|
+
const runs = readRuns();
|
|
26
|
+
if (sub === undefined || sub === "list") return console.log(json ? JSON.stringify(runs.map(runSummary), null, 2) : formatRuns(runs).join("\n"));
|
|
27
|
+
if (sub === "status") {
|
|
28
|
+
const live = runs.filter((r) => r.state === "running" || r.state === "unknown");
|
|
29
|
+
return console.log(json ? JSON.stringify(live.map(runSummary), null, 2) : live.length ? formatRuns(live).join("\n") : "no benchmark run is running");
|
|
30
|
+
}
|
|
31
|
+
if (sub === "report") {
|
|
32
|
+
const run = runs.find((r) => r.header.run === rest[0]) ?? fail(`usage: ahub bench report <run> (ahub bench list shows the runs)`);
|
|
33
|
+
const r = benchReport([run]);
|
|
34
|
+
return console.log(json ? JSON.stringify(r, null, 2) : formatBenchReport(r).join("\n"));
|
|
35
|
+
}
|
|
36
|
+
if (sub === "compare") {
|
|
37
|
+
const mixed = rest.includes("--mixed");
|
|
38
|
+
const { one, rest: picks } = takeFlags(rest.filter((a) => a !== "--mixed"), ["--suite"], []);
|
|
39
|
+
const scoped = one["--suite"] ? runs.filter((r) => r.header.suite === one["--suite"]) : runs;
|
|
40
|
+
const groups = picks.map((pick) => {
|
|
41
|
+
const byRun = scoped.filter((r) => r.header.run === pick);
|
|
42
|
+
const chosen = byRun.length ? byRun : armRuns(scoped, pick);
|
|
43
|
+
if (!chosen.length) fail(`no run, or arm with a run that is over, named ${pick}${one["--suite"] ? ` in suite ${one["--suite"]}` : ""}`);
|
|
44
|
+
return { arm: byRun.length ? `${pick} [${byRun[0]!.header.arm}]` : pick, runs: chosen };
|
|
45
|
+
});
|
|
46
|
+
if (groups.length < 2) fail("usage: ahub bench compare <run|arm> <run|arm>... [--suite <name>] [--mixed] [--json]");
|
|
47
|
+
const differs = sameSuite(groups);
|
|
48
|
+
if (differs && !mixed) fail(`${differs}; compare runs of one suite file (name runs by id, or --suite when the names differ), or pass --mixed to compare them anyway`);
|
|
49
|
+
const c = benchCompare(groups);
|
|
50
|
+
return console.log(json ? JSON.stringify(c, null, 2) : formatCompare(c).join("\n"));
|
|
51
|
+
}
|
|
52
|
+
if (sub === "export") {
|
|
53
|
+
const format = rest.includes("--format") ? rest[rest.indexOf("--format") + 1] : "jsonl";
|
|
54
|
+
if (format !== "jsonl" && format !== "csv") refuseUnsupportedExportFormat(fail);
|
|
55
|
+
if (format === "csv") return void process.stdout.write(benchCsv(runs));
|
|
56
|
+
for (const r of runs) for (const record of [r.header, ...r.attempts, ...(r.end ? [r.end] : [])]) console.log(JSON.stringify(record));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
fail("usage: ahub bench run|list|status|report|compare|export (ahub help bench)");
|
|
60
|
+
}
|