@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
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { COMPAT } from "../adapters/compat.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* #1808 T4: a read-only check of the Orca CLI answers the upgrade recovery depends on (`src/cli/terminal-recovery.ts`, `src/cli/upgrade-runtime.ts`).
|
|
5
|
+
* It runs `orca --version`, `orca terminal list --json` and `orca worktree list --json` and compares field NAMES and types only: a handle, a path or an id never
|
|
6
|
+
* appears in a result, a message or a log. It changes nothing in Orca and decides nothing by itself: a caller turns a shape problem into a doctor row or a plan blocker.
|
|
7
|
+
* A command that failed, or an answer that is not Orca's `ok: true` JSON, is `unreadable`, never a shape problem: the recovery's own Orca calls report that.
|
|
8
|
+
*/
|
|
9
|
+
interface OrcaProbeResult {
|
|
10
|
+
/** `orca --version` as plain semver, or undefined when it could not be read. */
|
|
11
|
+
version?: string;
|
|
12
|
+
/** The version is newer than the last one in `COMPAT["orca-cli"].verified`. Never a refusal. */
|
|
13
|
+
newer: boolean;
|
|
14
|
+
/** Each names a command and a missing or mistyped field. Empty when every answered shape is what the recovery reads. */
|
|
15
|
+
problems: string[];
|
|
16
|
+
/** Commands that did not answer with Orca's JSON; they are not shape problems. */
|
|
17
|
+
unreadable: string[];
|
|
18
|
+
}
|
|
19
|
+
type OrcaProbeRunner = (argv: string[]) => Promise<{ code: number | null | undefined; stdout: string | undefined }>;
|
|
20
|
+
|
|
21
|
+
const MAX_ROWS = 2000;
|
|
22
|
+
const plain = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
|
|
23
|
+
const text = (value: unknown): boolean => typeof value === "string" && value.length > 0;
|
|
24
|
+
const triple = (version: string): number[] | undefined => /^(\d+)\.(\d+)\.(\d+)$/.exec(version)?.slice(1).map(Number);
|
|
25
|
+
|
|
26
|
+
/** The newest version a receipt covers. */
|
|
27
|
+
export const orcaLastChecked = (): string => COMPAT["orca-cli"].verified.reduce((best, version) => {
|
|
28
|
+
const a = triple(version), b = triple(best);
|
|
29
|
+
return a && b && (a[0]! - b[0]! || a[1]! - b[1]! || a[2]! - b[2]!) > 0 ? version : best;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/** Whether `version` is newer than the last Orca version a receipt checked. An unreadable or non-semver one is never newer. */
|
|
33
|
+
function orcaVersionIsNewer(version: string | undefined): boolean {
|
|
34
|
+
const seen = version === undefined ? undefined : triple(version), known = triple(orcaLastChecked());
|
|
35
|
+
return !!seen && !!known && (seen[0]! - known[0]! || seen[1]! - known[1]! || seen[2]! - known[2]!) > 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** `answer` is a parsed `--json` answer; undefined means the command was not read, and nothing is checked for it. */
|
|
39
|
+
function rowProblems(command: string, list: unknown, names: readonly string[], listKeys: readonly string[], rowFields: readonly (readonly [string, ...string[]])[], listRequired: boolean): string[] {
|
|
40
|
+
if (!plain(list) || list.ok !== true) return [];
|
|
41
|
+
const result = plain(list.result) ? list.result : {};
|
|
42
|
+
const key = listKeys.find(name => Array.isArray(result[name]));
|
|
43
|
+
// ponytail: `worktree list` is read by the start path only, and fakes of it in older tests answer with another list, so a missing list is a problem for `terminal list` alone; a row field is checked on both.
|
|
44
|
+
if (key === undefined) return listRequired ? [`orca ${command}: the answer has no ${names.join(" or ")} list`] : [];
|
|
45
|
+
const rows = (result[key] as unknown[]).slice(0, MAX_ROWS);
|
|
46
|
+
const problems: string[] = [];
|
|
47
|
+
for (const alternatives of rowFields) {
|
|
48
|
+
const missing = rows.filter(row => !plain(row) || !alternatives.some(name => text(row[name]))).length;
|
|
49
|
+
if (missing) problems.push(`orca ${command}: ${alternatives.length === 1 ? `field ${alternatives[0]}` : `field ${alternatives.join(" or ")}`} is missing or not text on ${missing} of ${rows.length} rows`);
|
|
50
|
+
}
|
|
51
|
+
return problems;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The fields the recovery reads. `terminal list`: the handle, incarnation and worktree ids it binds a terminal to, and the worktree path it matches (`worktreePath`,
|
|
56
|
+
* else `projectRoot`). `worktree list`: the id and path it matches a project root with. A field that is optional for the recovery (`agentIdentity`, `orphaned`) is not checked.
|
|
57
|
+
* An empty list has no row to check and is not a problem.
|
|
58
|
+
*/
|
|
59
|
+
function orcaShapeProblems(terminalList: unknown, worktreeList: unknown): string[] {
|
|
60
|
+
return [
|
|
61
|
+
...rowProblems("terminal list --json", terminalList, ["terminals", "items"], ["terminals", "items"], [["handle"], ["incarnationId"], ["worktreeId"], ["worktreePath", "projectRoot"]], true),
|
|
62
|
+
...rowProblems("worktree list --json", worktreeList, ["worktrees"], ["worktrees"], [["id"], ["path"]], false),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const parsed = (stdout: string | undefined): unknown => { try { return stdout === undefined ? undefined : JSON.parse(stdout); } catch { return undefined; } };
|
|
67
|
+
|
|
68
|
+
/** One probe over a runner the caller supplies (a child process, or the upgrade's injected command port). Never throws. */
|
|
69
|
+
export async function readOrcaProbe(run: OrcaProbeRunner): Promise<OrcaProbeResult> {
|
|
70
|
+
const answer = async (argv: string[]): Promise<{ ok: boolean; stdout: string }> => {
|
|
71
|
+
try { const result = await run(argv); return { ok: result.code === 0 && typeof result.stdout === "string", stdout: result.stdout ?? "" }; }
|
|
72
|
+
catch { return { ok: false, stdout: "" }; }
|
|
73
|
+
};
|
|
74
|
+
const unreadable: string[] = [];
|
|
75
|
+
const versionAnswer = await answer(["--version"]);
|
|
76
|
+
const rawVersion = versionAnswer.ok ? versionAnswer.stdout.trim().split("\n")[0]!.trim() : "";
|
|
77
|
+
const version = triple(rawVersion) ? rawVersion : undefined;
|
|
78
|
+
if (version === undefined) unreadable.push("orca --version");
|
|
79
|
+
const read = async (argv: string[]): Promise<unknown> => {
|
|
80
|
+
const result = await answer(argv), value = result.ok ? parsed(result.stdout) : undefined;
|
|
81
|
+
if (!plain(value) || value.ok !== true) { unreadable.push(`orca ${argv.slice(0, 2).join(" ")} --json`); return undefined; }
|
|
82
|
+
return value;
|
|
83
|
+
};
|
|
84
|
+
const terminals = await read(["terminal", "list", "--json"]);
|
|
85
|
+
const worktrees = await read(["worktree", "list", "--json"]);
|
|
86
|
+
return { ...(version === undefined ? {} : { version }), newer: orcaVersionIsNewer(version), problems: orcaShapeProblems(terminals, worktrees), unreadable };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const PROBE_OUTPUT_CAP = 4 * 1024 * 1024;
|
|
90
|
+
/** A runner over one Orca executable with a deadline and an output cap, for `ahub doctor`. The upgrade preflight passes its own command port instead. */
|
|
91
|
+
export function orcaProbeRunner(executable: string, timeoutMs = 5_000): OrcaProbeRunner {
|
|
92
|
+
return async argv => {
|
|
93
|
+
const child = Bun.spawn([executable, ...argv], { stdout: "pipe", stderr: "ignore", stdin: "ignore", timeout: timeoutMs, killSignal: "SIGKILL" });
|
|
94
|
+
const reader = child.stdout.getReader();
|
|
95
|
+
const chunks: Uint8Array[] = [];
|
|
96
|
+
let total = 0, overflow = false;
|
|
97
|
+
try {
|
|
98
|
+
for (;;) {
|
|
99
|
+
const { done, value } = await reader.read();
|
|
100
|
+
if (done) break;
|
|
101
|
+
total += value.byteLength;
|
|
102
|
+
if (total > PROBE_OUTPUT_CAP) { overflow = true; child.kill("SIGKILL"); break; }
|
|
103
|
+
chunks.push(value);
|
|
104
|
+
}
|
|
105
|
+
} catch { /* a failed read ends the probe with what was counted */ }
|
|
106
|
+
const code = await child.exited;
|
|
107
|
+
return { code: overflow ? 1 : code, stdout: overflow ? undefined : Buffer.concat(chunks).toString("utf8") };
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The `ahub doctor` row for an Orca that is installed: failed (a field the recovery reads is missing), a note (newer version, or an answer that could not be read), or ok. */
|
|
112
|
+
export function orcaDoctorRow(result: OrcaProbeResult): { ok: boolean | undefined; name: string; detail: string } {
|
|
113
|
+
const seen = result.version ?? "version unreadable";
|
|
114
|
+
if (result.problems.length) return { ok: false, name: "orca cli", detail: `${seen}: ${result.problems.join("; ")}; the upgrade recovery would read these answers wrongly and blocks its Orca terminals until this is fixed (update ahub or Orca)` };
|
|
115
|
+
const last = orcaLastChecked();
|
|
116
|
+
if (result.newer) return { ok: undefined, name: "orca cli", detail: `${seen} is newer than ${last}, the last version checked; the commands the recovery reads still have the fields it needs` };
|
|
117
|
+
if (result.unreadable.length) return { ok: undefined, name: "orca cli", detail: `${seen}: could not read ${result.unreadable.join(", ")} (is Orca running?); nothing was changed` };
|
|
118
|
+
return { ok: true, name: "orca cli", detail: `${seen}: the commands the recovery reads have the fields it needs` };
|
|
119
|
+
}
|
package/src/cli/output.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import type { NeedItem } from "../ui/needs.ts";
|
|
2
|
+
import { attentionCommand } from "./attention.ts";
|
|
1
3
|
import type { ReviewGate, ReviewUnknownQuota } from "../hub/review-budget.ts";
|
|
2
4
|
import { projectionText } from "../hub/budget-projection.ts";
|
|
3
5
|
import { quotaAccountReading } from "../hub/quota-account.ts";
|
|
4
6
|
import { projectModelStatus } from "./model.ts";
|
|
5
7
|
import type { RuntimeModelStatus } from "../hub/model-overrides.ts";
|
|
6
8
|
import type { QueueBackpressureStatus } from "../hub/queue-backpressure.ts";
|
|
7
|
-
import { definitionOf } from "../adapters/
|
|
9
|
+
import { builtinDeclarationOf as definitionOf } from "../adapters/declaration-catalog.ts";
|
|
8
10
|
import { windowKind } from "../hub/window-kind.ts";
|
|
9
11
|
import { boardColumns, type BoardPeerInput } from "../ui/task-board.ts";
|
|
10
12
|
import { peerStyle } from "../ui/peer-palette.ts";
|
|
@@ -19,7 +21,13 @@ import type { SpecsStatus } from "../hub/specs-task.ts";
|
|
|
19
21
|
import { queueResolveChoices, queueResolveCommand } from "../hub/person-command.ts";
|
|
20
22
|
|
|
21
23
|
export interface DoctorCheck { section: "Tools" | "Hub" | "Config" | "Models" | "Memory"; level: "ok" | "warn" | "fail" | "unknown"; name: string; detail: string }
|
|
24
|
+
|
|
22
25
|
export interface StatusOutput {
|
|
26
|
+
attentionItems?: readonly NeedItem[];
|
|
27
|
+
/** #1807: a new hub reports its startup-bound range and whether settings reach below its floor. */
|
|
28
|
+
protocolMin?: number;
|
|
29
|
+
protocolMax?: number;
|
|
30
|
+
bridgeProtocolFloorLimited?: boolean;
|
|
23
31
|
/** #1798: the daemon's one hub check; every surface renders it and none recomputes it. */
|
|
24
32
|
hubCheck?: import("../hub/hub-check.ts").HubCheck;
|
|
25
33
|
runtimeModels?: RuntimeModelStatus[];
|
|
@@ -267,6 +275,11 @@ function contextText(p: any, now: number): string {
|
|
|
267
275
|
if (!c) return "unknown";
|
|
268
276
|
return `${c.used === null || c.used === undefined ? "unknown" : `${Math.round(c.used * 100)}%`}${c.freshness === "stale" ? " stale" : ""}${typeof c.measuredAt === "number" ? ` ${relative(c.measuredAt, now)}` : ""}${c.source ? ` ${c.source}` : ""}`;
|
|
269
277
|
}
|
|
278
|
+
function bridgeProtocolStatus(data: StatusOutput): string | undefined {
|
|
279
|
+
const { bridgeProtocolFloorLimited, protocolMin, protocolMax } = data;
|
|
280
|
+
if (typeof bridgeProtocolFloorLimited !== "boolean" || !Number.isSafeInteger(protocolMin) || !Number.isSafeInteger(protocolMax)) return;
|
|
281
|
+
return `${protocolMin} to ${protocolMax}${bridgeProtocolFloorLimited ? ` (settings stop at the implemented floor ${protocolMin})` : ""}`;
|
|
282
|
+
}
|
|
270
283
|
export function renderStatus(data: StatusOutput, columns?: number, now = Date.now(), full = false, ascii = false): Span[][] {
|
|
271
284
|
if (data.roleInfo) data = { ...data, peers: Object.fromEntries(Object.entries(data.peers).map(([peer, value]) => [peer, { ...value, ...data.roleInfo?.[peer] }])) };
|
|
272
285
|
// #1654 T3: the shared header, then a section mark per group. Every detail line below keeps its text, so a search for one still finds it.
|
|
@@ -274,6 +287,8 @@ export function renderStatus(data: StatusOutput, columns?: number, now = Date.no
|
|
|
274
287
|
const mark = (name: string, count?: string) => { out.push(...(out.length && out.at(-1)!.length ? [[]] : []), ...new LayoutReport(columns, ascii).section(name, count).lines()); };
|
|
275
288
|
const hubStart = out.length; // the Hub section opens here only if a row below lands in it
|
|
276
289
|
if (data.cwd) out.push(...detail("project", data.cwd, columns));
|
|
290
|
+
const bridgeProtocol = bridgeProtocolStatus(data);
|
|
291
|
+
if (bridgeProtocol) out.push(...detail("bridge protocols", bridgeProtocol, columns));
|
|
277
292
|
if (data.runtimeModelsUnavailable === true) out.push(...lines("Runtime models unavailable: could not read a bounded model catalog; run ahub model list for the cause. For a known peer, use ahub model set <peer> <model> or ahub model clear <peer>; repair storage or reduce the retained peer catalog as indicated before listing again.", columns, "attention"));
|
|
278
293
|
else if (Array.isArray(data.runtimeModels)) out.push(...renderRuntimeModels(data.runtimeModels.map(projectModelStatus).filter((row): row is RuntimeModelStatus => row !== null), columns));
|
|
279
294
|
const timing = data.controlWriteTiming;
|
|
@@ -393,6 +408,7 @@ export function renderStatus(data: StatusOutput, columns?: number, now = Date.no
|
|
|
393
408
|
if (typeof p.reviewerUnavailable === "string" && p.reviewerUnavailable) out.push(...detail("reviewer", flat(p.reviewerUnavailable), columns, "failure")); // #722: the cause class, never a path
|
|
394
409
|
if (p.ownerIsolationNote) out.push(...detail("owner isolation", p.ownerIsolationNote, columns, "attention"));
|
|
395
410
|
if (p.permissionNote) out.push(...detail("permission", p.permissionNote, columns, "muted"));
|
|
411
|
+
if (typeof p.preset?.id === "string" && (p.preset.status === "verified" || p.preset.status === "untested")) out.push(...detail("preset", `${p.preset.id} (${p.preset.status})`, columns, p.preset.status === "verified" ? "muted" : "attention")); // #1809
|
|
396
412
|
if (typeof p.statusNotice?.message === "string" && p.statusNotice.message) out.push(...detail("status notice", p.statusNotice.message, columns, "attention"));
|
|
397
413
|
if (p.refusedHello && typeof p.refusedHello.at === "number") out.push(...detail("refused hello", `${refusedHelloText(p.refusedHello)}; the owned launch is serving, so ${id} is not detached`, columns, "attention")); // #1795
|
|
398
414
|
if (typeof p.detached?.cause === "string" && p.detached.cause) out.push(...detail("detached", `${p.detached.cause}${typeof p.detached.command === "string" && p.detached.command ? `; relaunch it with ${p.detached.command}` : ""}`, columns, "attention"));
|
|
@@ -456,6 +472,12 @@ export function statusAttention(data: StatusOutput, now = Date.now()): Attention
|
|
|
456
472
|
for (const warning of data.isolatedChecks?.orphans ?? []) add("warn", `isolated check: ${warning}`);
|
|
457
473
|
for (const id of data.isolatedChecks?.unknownReceipts ?? []) add("warn", `check receipt ${id}: unknown; receipt storage unavailable`);
|
|
458
474
|
if (data.isolatedChecks?.maintenanceUnavailable) add("warn", "check maintenance unavailable; saved run outcomes are unchanged");
|
|
475
|
+
for (const warning of data.attentionItems ?? []) {
|
|
476
|
+
if (warning.kind !== "budget" || warning.level !== "watch" || typeof warning.peer !== "string"
|
|
477
|
+
|| !/^[a-z0-9][a-z0-9-]*$/.test(warning.peer) || typeof warning.id !== "string"
|
|
478
|
+
|| !["5h", "week", "tokens"].includes(warning.id) || typeof warning.until !== "number" || warning.until < now) continue;
|
|
479
|
+
add("warn", `${warning.peer} ${warning.id} quota is projected to run out ${relative(warning.until, now)}`, attentionCommand(warning));
|
|
480
|
+
}
|
|
459
481
|
for (const [id, p] of Object.entries(data.peers)) {
|
|
460
482
|
for (const session of Array.isArray(p.standbySessions) ? p.standbySessions : []) {
|
|
461
483
|
if (!session || typeof session.id !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(session.id)) continue;
|
|
@@ -468,7 +490,7 @@ export function statusAttention(data: StatusOutput, now = Date.now()): Attention
|
|
|
468
490
|
const budgetPause = data.budget?.[id]?.paused;
|
|
469
491
|
const text = budgetPause ? `budget: ${budgetPause.reason ?? "threshold"}${typeof budgetPause.resetsAt === "number" ? `; resets ${relative(budgetPause.resetsAt, now)}` : "; reset unknown"}`
|
|
470
492
|
: typeof p.paused === "object" ? `${p.paused.by ?? "paused"}${p.paused.reason ? `: ${p.paused.reason}` : ""}` : flat(p.paused);
|
|
471
|
-
add("warn", `${id} is paused (${text})`, budgetPause ? "
|
|
493
|
+
add("warn", `${id} is paused (${text})`, budgetPause ? attentionCommand({ kind: "budget", level: "watch", peer: id }) : `ahub resume ${id}`);
|
|
472
494
|
}
|
|
473
495
|
if (typeof p.reviewerUnavailable === "string" && p.reviewerUnavailable) add("fail", `${id} reviewer unavailable: ${flat(p.reviewerUnavailable)}`);
|
|
474
496
|
if (p.ownerIsolationNote) add("warn", `${id} owner isolation: ${p.ownerIsolationNote}`);
|
|
@@ -505,6 +527,8 @@ export function renderStatusDefault(data: StatusOutput, columns?: number, now =
|
|
|
505
527
|
if (!attention.length) report.bullet("ok", "nothing needs attention");
|
|
506
528
|
for (const item of attention) { report.bullet(item.marker, item.text); if (item.next) report.next(item.next); }
|
|
507
529
|
const hub: [string, unknown][] = [["version", data.version ?? "unknown"], ["pid", data.pid ?? "unknown"], ["control", `127.0.0.1:${data.controlPort ?? "unknown"}`], ["project", data.cwd ?? ""]];
|
|
530
|
+
const bridgeProtocol = bridgeProtocolStatus(data);
|
|
531
|
+
if (bridgeProtocol) hub.push(["bridge protocols", bridgeProtocol]);
|
|
508
532
|
if (data.planner) hub.push(["planner", `${data.planner.peers?.join(", ") || "nobody"} (${data.planner.source ?? "unknown"})`]);
|
|
509
533
|
if (data.memoryProfile) hub.push(["memory", `${data.memoryProfile.profile === "generation" ? `generation ${data.memoryProfile.generation?.slice(0, 8) ?? "unknown"}` : data.memoryProfile.profile ?? "unbound"}; ${data.memoryProfile.state ?? "unknown"}`]);
|
|
510
534
|
const specs = data.specs;
|
|
@@ -646,6 +670,11 @@ export function renderBudget(data: BudgetOutput, columns?: number, now = Date.no
|
|
|
646
670
|
// A peer with no number says why, in its own line, so a peer without quota is not mistaken for one that has not reported.
|
|
647
671
|
for (const note of data.peers ?? []) out.push(...detail(note.peer, note.note, columns, peerTone(note.peer)));
|
|
648
672
|
for (const [peer, b] of Object.entries(data.budget)) if (b.paused) out.push(...detail(`paused ${peer}`, `${b.paused.reason ?? "budget"}${typeof b.paused.resetsAt === "number" ? `; resumes ${relative(b.paused.resetsAt, now)}` : ""}`, columns, "attention"));
|
|
673
|
+
for (const [peer, b] of Object.entries(data.budget)) {
|
|
674
|
+
if (b.renewable !== true || !/^[a-z0-9][a-z0-9-]*$/.test(peer) || !(b.paused || b.warnings?.length)) continue;
|
|
675
|
+
out.push(...detail("Same account after resetting its quota", `ahub budget renew ${peer} --reset`, columns));
|
|
676
|
+
out.push(...detail("After switching accounts", `ahub budget renew ${peer} --switched`, columns));
|
|
677
|
+
}
|
|
649
678
|
for (const [peer, b] of Object.entries(data.budget)) {
|
|
650
679
|
const info = b.paused ? quotaAccountReading(b.accountUsage) : undefined;
|
|
651
680
|
if (!info) continue;
|
package/src/cli/preview.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lightNativePreview } from "../adapters/definitions/native-light-preview.ts";
|
|
2
|
+
import { builtinDeclarationOf } from "../adapters/declaration-catalog.ts";
|
|
2
3
|
import { loadConfig } from "../hub/config.ts";
|
|
3
4
|
import { childEnv } from "../hub/child-process.ts";
|
|
4
5
|
import { startModeOf } from "../hub/start-mode.ts";
|
|
5
6
|
import { instanceLaunchArguments, buildLaunch, buildKimiLaunch, buildKimiTuiLaunch, nativeLaunchEnv, claudeObservationHooks } from "./launch.ts";
|
|
6
7
|
import { kimiMcpPlan } from "./kimi-mcp.ts";
|
|
7
|
-
import { jcodeCommand, jcodeTuiCommand } from "../adapters/jcode.ts";
|
|
8
|
-
import { qwenSessionId } from "../
|
|
8
|
+
import { jcodeCommand, jcodeTuiCommand } from "../adapters/definitions/jcode-launch.ts";
|
|
9
|
+
import { qwenSessionId } from "../adapters/definitions/qwen-native.ts";
|
|
9
10
|
import { relayModelIds } from "../models/relay.ts";
|
|
10
|
-
|
|
11
|
+
const buildPiLaunch: typeof import("../pi/launch.ts").buildPiLaunch =
|
|
12
|
+
(...args) => (require("../pi/launch.ts") as typeof import("../pi/launch.ts")).buildPiLaunch(...args);
|
|
13
|
+
|
|
11
14
|
|
|
12
15
|
/** Read-only builtin preview. Native redaction uses the same launch builders as actual startup. */
|
|
13
16
|
export function launcherPreview(tool: string, raw: string[], cwd: string, stateDir: string, unattended: boolean, requestedInstance?: string) {
|
|
14
17
|
const config = loadConfig(cwd);
|
|
15
18
|
const selected = instanceLaunchArguments(tool, requestedInstance ? ["--as", requestedInstance, ...raw] : raw, config.instances);
|
|
16
19
|
const args = selected.args.filter(arg => !["--print-command", "--dry-run", "--json"].includes(arg));
|
|
17
|
-
const
|
|
20
|
+
const light = lightNativePreview(tool);
|
|
21
|
+
const runtime = light ? undefined : require("../adapters/registry.ts") as typeof import("../adapters/registry.ts");
|
|
22
|
+
const definition = light ? builtinDeclarationOf(tool) : runtime?.definitionOf(tool), preview = light ?? runtime?.builtinPreviewOf(tool);
|
|
18
23
|
if (!definition || !preview) throw new Error("native preview definition unavailable");
|
|
19
24
|
if (selected.instance && definition.start.explicitHeadlessMode) {
|
|
20
25
|
const mode = args.indexOf("--mode");
|
|
@@ -68,10 +68,13 @@ export async function readRecoveryVersionPreflight(
|
|
|
68
68
|
|| gate.command !== undefined && !words(gate.command))) throw new Error("invalid recovery version preflight scope");
|
|
69
69
|
const module = JSON.stringify(join(targetRoot, "src/adapters/compat.ts"));
|
|
70
70
|
const env = withoutOrcaEnv(childEnv({ ...process.env, JCODE_NO_TELEMETRY: "1", JCODE_DISABLE_CLAUDE_MCP: "1", AGY_CLI_DISABLE_AUTO_UPDATE: "1" }));
|
|
71
|
+
// A changed authority or target is its own error: nothing below may catch it as a failed probe, and once seen it ends the whole preflight as unknown even if it changes back.
|
|
72
|
+
class AuthorityChanged extends Error {}
|
|
73
|
+
const still = () => { if (!ports.current()) throw new AuthorityChanged("recovery version preflight authority changed"); };
|
|
71
74
|
const run = async (argv: string[], input?: string) => {
|
|
72
|
-
|
|
75
|
+
still();
|
|
73
76
|
const result = await ports.run(argv, { cwd: projectRoot, env, timeoutMs: PROBE_TIMEOUT_MS, pipeExitGraceMs: PROBE_EXIT_GRACE_MS, ...(input === undefined ? {} : { input }) });
|
|
74
|
-
|
|
77
|
+
still();
|
|
75
78
|
if (result.code !== 0 || typeof result.stdout !== "string" || Buffer.byteLength(result.stdout) > MAX_OUTPUT_BYTES) return undefined;
|
|
76
79
|
return result.stdout;
|
|
77
80
|
};
|
|
@@ -79,24 +82,40 @@ export async function readRecoveryVersionPreflight(
|
|
|
79
82
|
for (const gate of gates) {
|
|
80
83
|
let observation = unknown(gate);
|
|
81
84
|
try {
|
|
85
|
+
observation = await (async (): Promise<RecoveryVersionObservation> => {
|
|
86
|
+
let observation = unknown(gate);
|
|
82
87
|
// This target import is allowed only after the caller verified the package's retained root and digest.
|
|
83
|
-
const policyText = await run([process.execPath, "-e", `// recovery-version-policy\nimport { COMPAT } from ${module}; const id = ${JSON.stringify(gate.compatId)}; const p = Object.hasOwn(COMPAT, id) ? COMPAT[id] : undefined; console.log(JSON.stringify(p ? { probe: p.probe } : null));`]);
|
|
88
|
+
const policyText = await run([process.execPath, "-e", `// recovery-version-policy\nimport { COMPAT } from ${module}; const id = ${JSON.stringify(gate.compatId)}; const p = Object.hasOwn(COMPAT, id) ? COMPAT[id] : undefined; console.log(JSON.stringify(p ? { probe: p.probe, gate: p.gate } : null));`]);
|
|
84
89
|
const policy: unknown = policyText === undefined ? undefined : JSON.parse(policyText);
|
|
85
|
-
if (!plain(policy) || !words(policy.probe))
|
|
90
|
+
if (!plain(policy) || !words(policy.probe)) return observation;
|
|
86
91
|
const [executable, ...prefix] = gate.command ?? [policy.probe[0]!];
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
// #1808: an `observe` entry never refuses, so a version probe that fails, times out or throws must not block a restore. Only the target's own policy says "observe";
|
|
93
|
+
// a missing gate (an older target), any other gate or an unreadable policy stays unknown. An authority change is never a probe failure: it is rethrown, and it is checked again right before an unreadable version is accepted and after every gate.
|
|
94
|
+
const watched = policy.gate === "observe";
|
|
95
|
+
const unreadable = (): RecoveryVersionObservation => (still(), { ...observation, state: "accepted", message: `${gate.peer}: target only watches this CLI and its version could not be read; nothing is refused` });
|
|
96
|
+
let native: string | undefined;
|
|
97
|
+
try { native = await run([executable!, ...prefix, ...policy.probe.slice(1)]); }
|
|
98
|
+
catch (error) { if (error instanceof AuthorityChanged) throw error; if (watched) return unreadable(); throw new Error("version probe failed"); }
|
|
99
|
+
if (native === undefined) return watched ? unreadable() : observation;
|
|
89
100
|
const assessment = await run([process.execPath, "-e", `// recovery-version-assess\nimport { COMPAT, assessVersion, readTrust } from ${module}; const id = ${JSON.stringify(gate.compatId)}; const p = Object.hasOwn(COMPAT, id) ? COMPAT[id] : undefined; const observed = await Bun.stdin.text(); const v = p ? assessVersion(id, p.parse(observed), readTrust()) : undefined; console.log(JSON.stringify(v ? { ok: v.ok, state: v.state, version: v.version } : null));`], native);
|
|
90
101
|
const verdict: unknown = assessment === undefined ? undefined : JSON.parse(assessment);
|
|
91
|
-
|
|
102
|
+
// #1808: an `observe` entry never refuses, so an observed verdict (even one whose version could not be read) never blocks recovery.
|
|
103
|
+
if (plain(verdict) && verdict.ok === true && verdict.state === "observed") observation = { ...observation, state: "accepted",
|
|
104
|
+
...(typeof verdict.version === "string" && verdict.version.length <= 64 && SEMVER.test(verdict.version) ? { version: verdict.version } : {}),
|
|
105
|
+
message: `${gate.peer}: target only watches this CLI; nothing is refused` };
|
|
106
|
+
else if (plain(verdict) && typeof verdict.version === "string" && verdict.version.length <= 64 && SEMVER.test(verdict.version)) {
|
|
92
107
|
const version = verdict.version;
|
|
93
108
|
if (verdict.ok === true && ["verified", "trusted", "in-line"].includes(String(verdict.state))) observation = { ...observation, state: "accepted", version,
|
|
94
109
|
message: `${gate.peer}: target accepts installed version ${version}` };
|
|
95
110
|
else if (verdict.ok === false && verdict.state === "refused") observation = { ...observation, state: "refused", version,
|
|
96
111
|
message: `${gate.peer}: target refuses installed version ${version}; install a verified version, or accept this exact version on this machine with: ahub agents trust ${gate.compatId} ${version}` };
|
|
97
112
|
}
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
return observation;
|
|
114
|
+
})();
|
|
115
|
+
} catch (error) {
|
|
116
|
+
// A failed policy/probe is unknown, never accepted or a leaked native exception. A changed authority or target invalidates every observation, earlier ones too.
|
|
117
|
+
if (error instanceof AuthorityChanged) return gates.map(unknown);
|
|
118
|
+
}
|
|
100
119
|
if (!ports.current()) return gates.map(unknown);
|
|
101
120
|
results.push(observation);
|
|
102
121
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { accessSync, constants } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
/** The absolute program spawn would run: execve never searches PATH. Undefined when the runtime has no execve or the program cannot be found and executed (the caller then spawns and reports the error as before). */
|
|
5
|
+
function replaceTarget(bin: string, env: NodeJS.ProcessEnv, cwd: string, hasExecve = typeof process.execve === "function"): string | undefined {
|
|
6
|
+
if (!hasExecve) return undefined;
|
|
7
|
+
const found = bin.includes("/") ? resolve(cwd, bin) : Bun.which(bin, { PATH: env.PATH ?? "", cwd }) ?? undefined;
|
|
8
|
+
if (!found) return undefined;
|
|
9
|
+
try { accessSync(found, constants.X_OK); return found; } catch { return undefined; }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* #1778 T6a: the wrapper becomes the agent. The process at the wrapper's pid is then the agent, no ahub process stays resident, and the agent's exit status or terminating signal reaches the caller directly.
|
|
14
|
+
* Returns only when execve is not available for this program, so the caller takes its spawn path; a failed execve is reported through `fail`.
|
|
15
|
+
* The caller closes every hub handle before calling: execve keeps an inherited descriptor open, and the hub client is the one the wrapper holds.
|
|
16
|
+
*/
|
|
17
|
+
export function replaceProcess(bin: string, argv: string[], env: NodeJS.ProcessEnv, cwd: string, fail: (message: string) => never, hasExecve?: boolean): void {
|
|
18
|
+
const target = replaceTarget(bin, env, cwd, hasExecve);
|
|
19
|
+
if (!target) return;
|
|
20
|
+
try { process.chdir(cwd); process.execve!(target, [bin, ...argv], env as Record<string, string>); }
|
|
21
|
+
catch (error) { fail(`cannot run ${bin}: ${error instanceof Error ? error.message : String(error)}`); }
|
|
22
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Report as SharedReport, paint as sharedPaint, wrap as sharedWrap } from "@staix/cli-output";
|
|
2
|
+
import { PEER_PALETTE } from "../ui/peer-palette.ts";
|
|
3
|
+
import { sanitize } from "../hub/envelope.ts";
|
|
4
|
+
import { TONE_SGR, MARKERS, MARKER_COLUMN, cellWidth, markerCell, type MarkerName, type Role } from "./output-standard.ts";
|
|
5
|
+
|
|
6
|
+
/** Strip terminal controls before any daemon or child output reaches a terminal. Preserve printable Unicode. */
|
|
7
|
+
// Preserve the hub's control and header policy for non-Report output.
|
|
8
|
+
export function terminalText(value: unknown): string {
|
|
9
|
+
return sanitize(String(value ?? "")
|
|
10
|
+
.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\|$)/g, "")
|
|
11
|
+
.replace(/\x1b[P_X^][\s\S]*?(?:\x1b\\|$)/g, "")
|
|
12
|
+
.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "")
|
|
13
|
+
.replace(/\x1b[^\n]?/g, "").replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, ""));
|
|
14
|
+
}
|
|
15
|
+
export type Tone = "info" | "strong" | "success" | "attention" | "failure" | "muted" | "peerClaude" | "peerCodex" | "taskKeyword" | "number" | "issueRef" | "taskRef";
|
|
16
|
+
/** A report span names a semantic role (CLI output standard v1, docs/design/cli-output.md) or, for the console, a tone; a role wins. */
|
|
17
|
+
export interface Span { text: string; tone?: Tone; role?: Role }
|
|
18
|
+
export const PALETTE: Readonly<Record<Tone, string>> = Object.freeze({
|
|
19
|
+
info: PEER_PALETTE.hub.ansi, strong: TONE_SGR.strong, success: PEER_PALETTE.local.ansi, attention: PEER_PALETTE.pi.ansi, failure: TONE_SGR.failure, muted: PEER_PALETTE.other.ansi,
|
|
20
|
+
peerClaude: PEER_PALETTE.claude.ansi, peerCodex: PEER_PALETTE.codex.ansi,
|
|
21
|
+
taskKeyword: PEER_PALETTE.kimi.ansi, number: TONE_SGR.number, issueRef: TONE_SGR.issueRef, taskRef: TONE_SGR.taskRef,
|
|
22
|
+
});
|
|
23
|
+
/** The console's tones onto roles. A tone that is not here names an identity (a peer, a task keyword, a reference), never a status. */
|
|
24
|
+
export const TONE_ROLE: Readonly<Partial<Record<Tone, Role>>> = Object.freeze({
|
|
25
|
+
info: "accent", strong: "header", success: "success", attention: "warning", failure: "error", muted: "hint", number: "value",
|
|
26
|
+
});
|
|
27
|
+
export function paint(line: Span[], color: boolean): string {
|
|
28
|
+
return sharedPaint(line.map(({ tone, ...span }) => ({ ...span, text: terminalText(span.text), ...(tone ? { style: tone } : {}) })), color, PALETTE);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The layout grammar of standard v1 as one builder, so every report has the same header, section, key/value row, bullet row, next step
|
|
33
|
+
* and summary line. Blank lines follow the standard: exactly one before each section, none after it, never two in a row, none at the
|
|
34
|
+
* end. Lines are Span arrays; `paint(line, color)` prints them. The builder never colors by itself: it names roles.
|
|
35
|
+
*/
|
|
36
|
+
// Shared Report supplies matching primitives; layout uses shared wrapping with the legacy fallback below.
|
|
37
|
+
export class Report {
|
|
38
|
+
private readonly out: Span[][] = [];
|
|
39
|
+
/** `columns` undefined means no wrap width: standard v1 wraps on a pipe only when COLUMNS is set, so a script reading `ahub doctor | grep` gets whole lines. */
|
|
40
|
+
constructor(readonly columns: number | undefined = undefined, readonly ascii = false) {}
|
|
41
|
+
/** The text as lines at most `room` cells wide, or as one line per source line when there is no wrap width. */
|
|
42
|
+
private fit(text: string, room: number): string[] {
|
|
43
|
+
return this.columns === undefined ? terminalText(text).split("\n").map(line => line.replace(/\t/g, " ")) : wrap(text, Math.max(10, room), 0);
|
|
44
|
+
}
|
|
45
|
+
private push(line: Span[]) { this.out.push(line); }
|
|
46
|
+
/** ` <tool> <Report>` in `header`, then one line of context in `hint` on the same line. At most one per report. */
|
|
47
|
+
header(tool: string, name: string, context?: string): this {
|
|
48
|
+
this.out.push(...new SharedReport(this.columns, this.ascii).header(tool, name, context).lines());
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* #1654 AC3: the one header-fit rule. The header line does not wrap, so a name that fits the terminal stays in it and a longer
|
|
53
|
+
* one moves to a wrapped line under a short header. `context` follows the name after two spaces in `hint`; with `inline` it
|
|
54
|
+
* joins the name by one space (`Merge queue owner/repo`) and moves in `value`. A name too wide for any header keeps its first
|
|
55
|
+
* word there and repeats in full on the wrapped line. No wrap width means no moving.
|
|
56
|
+
*/
|
|
57
|
+
titled(tool: string, name: string, context?: string, inline = false): this {
|
|
58
|
+
const fits = (text: string) => this.columns === undefined || cellWidth(` ${tool} ${text}`) <= this.columns;
|
|
59
|
+
const joined = !context ? name : inline ? `${name} ${context}` : `${name} ${context}`;
|
|
60
|
+
if (fits(joined)) return inline && context ? this.header(tool, joined) : this.header(tool, name, context || undefined);
|
|
61
|
+
if (context && fits(name)) return this.header(tool, name).note(context, inline ? "value" : "hint");
|
|
62
|
+
return this.header(tool, name.split(" ")[0]!).note(joined, "value");
|
|
63
|
+
}
|
|
64
|
+
/** One blank line, then `▸ <Name>` (ASCII `> <Name>`) in `section`, with an optional count in `hint`. */
|
|
65
|
+
section(name: string, count?: string): this {
|
|
66
|
+
if (this.out.length && this.out.at(-1)!.length) this.push([]);
|
|
67
|
+
this.out.push(...new SharedReport(this.columns, this.ascii).section(name, count).lines());
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Key/value rows of one section: two-space indent, `Key:` padded to the widest key, two spaces, value. A key wider than 28 cells
|
|
72
|
+
* puts its value on the next line at a four-space indent. An empty value is `(unset)` in `hint`.
|
|
73
|
+
*/
|
|
74
|
+
kv(rows: readonly (readonly [string, unknown])[], indent = 2, options: { colon?: boolean } = {}): this {
|
|
75
|
+
const suffix = options.colon === false ? "" : ":";
|
|
76
|
+
const keys = rows.map(([key]) => cellWidth(`${terminalText(key)}${suffix}`));
|
|
77
|
+
const pad = Math.max(0, ...keys.filter(width => width <= 28));
|
|
78
|
+
for (const [index, [key, raw]] of rows.entries()) {
|
|
79
|
+
const label = `${terminalText(key)}${suffix}`, text = terminalText(raw ?? "").trim();
|
|
80
|
+
const value = (line: string): Span => text ? { text: line, role: "value" } : { text: "(unset)", role: "hint" };
|
|
81
|
+
const lead = " ".repeat(indent);
|
|
82
|
+
// a terminal too narrow to leave 10 cells beside the label stacks the value under its key, like a key wider than 28
|
|
83
|
+
// stacked when fewer than 10 cells remain beside the label, or when the value's longest word does not fit there
|
|
84
|
+
const longest = Math.max(0, ...text.split(/\s+/).map(word => cellWidth(word)));
|
|
85
|
+
const narrow = keys[index]! <= 28 && this.columns !== undefined && (indent + pad + 2 + 10 > this.columns || longest > this.columns - indent - pad - 2 && longest <= this.columns - indent);
|
|
86
|
+
if (keys[index]! > 28 || narrow) {
|
|
87
|
+
// a terminal too narrow for the label column keeps the value at the key's own indent, so a long word is not broken by the hang
|
|
88
|
+
const hang = narrow ? 0 : 2;
|
|
89
|
+
this.push([{ text: `${lead}${label}`, role: "key" }]);
|
|
90
|
+
for (const line of text ? this.fit(text, (this.columns ?? 0) - indent - hang) : [""]) this.push([{ text: `${lead}${" ".repeat(hang)}` }, value(line)]);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const gap = " ".repeat(pad - keys[index]! + 2), room = (this.columns ?? 0) - indent - pad - 2;
|
|
94
|
+
const lines = text ? this.fit(text, room) : [""];
|
|
95
|
+
this.push([{ text: lead }, { text: label, role: "key" }, { text: gap }, value(lines[0]!)]);
|
|
96
|
+
for (const line of lines.slice(1)) this.push([{ text: " ".repeat(indent + pad + 2) }, value(line)]);
|
|
97
|
+
}
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
/** ` <marker> <text>`; a nested detail line uses four spaces. The text carries the state word, so meaning survives without color. */
|
|
101
|
+
bullet(name: MarkerName, text: string, nested = false): this {
|
|
102
|
+
const indent = nested ? " " : " ", lead = indent.length + MARKER_COLUMN + 1;
|
|
103
|
+
const lines = this.fit(text, (this.columns ?? 0) - lead);
|
|
104
|
+
this.push([{ text: indent }, { text: markerCell(name, this.ascii), role: MARKERS[name].role }, { text: " " }, { text: lines[0]! }]);
|
|
105
|
+
for (const line of lines.slice(1)) this.push([{ text: " ".repeat(lead) + line }]);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/** Lines another renderer built (a table), placed as they are. A section's blank line is still added by `section()`. */
|
|
109
|
+
append(lines: readonly Span[][]): this { for (const line of lines) this.push([...line]); return this; }
|
|
110
|
+
/** A free line in one role, indented two cells (a pointer to more detail, a note). */
|
|
111
|
+
note(text: string, role: Role = "hint"): this {
|
|
112
|
+
for (const line of this.fit(text, (this.columns ?? 0) - 2)) this.push([{ text: " " }, { text: line, role }]);
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
/** ` → <command>` in `accent`: complete and copyable, never shortened. */
|
|
116
|
+
next(command: string): this {
|
|
117
|
+
this.out.push(...new SharedReport(this.columns, this.ascii, { sanitize: terminalText, sanitizeFirst: true, wrapNext: false }).next(command).lines());
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/** The last line of a check command: `✗ 2 failed ⚠ 3 warnings ✓ 18 ok`, zero counts omitted, unknowns as `? 2 unknown`. */
|
|
121
|
+
summary(counts: { failed?: number; warnings?: number; unknown?: number; ok?: number }): this {
|
|
122
|
+
const lines = new SharedReport(this.columns, this.ascii).summary(counts).lines();
|
|
123
|
+
if (lines.length) { if (this.out.length) this.push([]); this.out.push(...lines); }
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
lines(): Span[][] { return this.out.map(line => line.map(item => ({ ...item }))); }
|
|
127
|
+
/** The report as text: one painted string per line, no trailing blank line. */
|
|
128
|
+
render(color: boolean): string[] { return this.out.map(line => paint(line, color)); }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A source line keeps its indent and its continuations hang `hang` columns deeper, both capped at half the width, so
|
|
133
|
+
* below that cap wrapped untrusted text never starts where its source line, or a hub line at that indent, starts. Breaks fall
|
|
134
|
+
* at whitespace, which they drop; only a word longer than a whole line is split. A tab counts as one space.
|
|
135
|
+
* Lines come out sanitized: a width counts the `> ` that sanitize() puts before a line starting like a hub header.
|
|
136
|
+
*/
|
|
137
|
+
export function wrap(value: unknown, columns: number, hang = 4): string[] {
|
|
138
|
+
// A bare chunk ending in "--- from" becomes a header marker when table padding follows it.
|
|
139
|
+
const quoteChunk = (chunk: string) => sanitize(chunk + " ").slice(0, -1);
|
|
140
|
+
// Code-point splitting keeps legacy output for every width, including the non-positive ones.
|
|
141
|
+
return sharedWrap(terminalText(value), columns, hang, quoteChunk, false, "codepoint");
|
|
142
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const optionalFields = "[--horizon now|next|later] [--order <n>] [--target <date>|none] [--parent <id>|none]";
|
|
2
|
+
export const ROADMAP_FORMS = {
|
|
3
|
+
list: "[list] [--json]", show: "show <id> [--json]",
|
|
4
|
+
new: `new --title <text> --outcome <text> ${optionalFields}`,
|
|
5
|
+
edit: `edit <id> --revision <n> [--title <text>] [--outcome <text>] ${optionalFields}`,
|
|
6
|
+
link: "link <id> <spec|issue|task|release> <ref>", unlink: "unlink <id> <kind> <ref>",
|
|
7
|
+
order: "order <id> <n>", state: "state <id> <proposed|planned|active|done|dropped>",
|
|
8
|
+
unplaced: "unplaced [--repo <owner/name>] [--json]",
|
|
9
|
+
triage: "triage [--repo <owner/name>] [--list] [--json]",
|
|
10
|
+
decompose: "decompose <id> [--accept <part>] [--publish [--apply --confirm <fingerprint>]] [--json]",
|
|
11
|
+
accept: "accept <suggestion>", reject: "reject <suggestion>",
|
|
12
|
+
importGithub: "import-github [--repo <owner/name>] [--apply] [--json]",
|
|
13
|
+
check: "check [--json]", sync: "sync [--apply --confirm <fingerprint>] [--json]",
|
|
14
|
+
export: "export [--write | --issue <n> [--apply --confirm <fingerprint>]] [--json]",
|
|
15
|
+
} as const;
|
|
16
|
+
export const ROADMAP_USAGE = `usage: ${Object.values(ROADMAP_FORMS).map(form => `ahub roadmap ${form}`).join(" | ")}`;
|
package/src/cli/roadmap.ts
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
import { milestoneId, milestoneRevision, milestoneLinkRef, parseMilestoneInput, parseMilestonePatch, githubRepo, type MilestoneLinkKind } from "../hub/roadmap.ts";
|
|
2
2
|
import { terminalText, wrap } from "./console-state.ts";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
new: `new --title <text> --outcome <text> ${optionalFields}`,
|
|
8
|
-
edit: `edit <id> --revision <n> [--title <text>] [--outcome <text>] ${optionalFields}`,
|
|
9
|
-
link: "link <id> <spec|issue|task|release> <ref>", unlink: "unlink <id> <kind> <ref>",
|
|
10
|
-
order: "order <id> <n>", state: "state <id> <proposed|planned|active|done|dropped>",
|
|
11
|
-
unplaced: "unplaced [--repo <owner/name>] [--json]",
|
|
12
|
-
triage: "triage [--repo <owner/name>] [--list] [--json]",
|
|
13
|
-
decompose: "decompose <id> [--accept <part>] [--publish [--apply --confirm <fingerprint>]] [--json]",
|
|
14
|
-
accept: "accept <suggestion>", reject: "reject <suggestion>",
|
|
15
|
-
importGithub: "import-github [--repo <owner/name>] [--apply] [--json]",
|
|
16
|
-
check: "check [--json]", sync: "sync [--apply --confirm <fingerprint>] [--json]",
|
|
17
|
-
export: "export [--write | --issue <n> [--apply --confirm <fingerprint>]] [--json]",
|
|
18
|
-
} as const;
|
|
19
|
-
export const ROADMAP_USAGE = `usage: ${Object.values(ROADMAP_FORMS).map(form => `ahub roadmap ${form}`).join(" | ")}`;
|
|
4
|
+
import { ROADMAP_USAGE } from "./roadmap-usage.ts";
|
|
5
|
+
export { ROADMAP_FORMS, ROADMAP_USAGE } from "./roadmap-usage.ts";
|
|
6
|
+
|
|
20
7
|
export interface RoadmapArgs {
|
|
21
8
|
op: "hub_roadmap_list" | "hub_roadmap_show" | "hub_roadmap_check" | "hub_roadmap_edit" | "hub_roadmap_unplaced" | "hub_roadmap_triage" | "hub_roadmap_decompose" | "roadmap_import_github" | "roadmap_sync" | "roadmap_sync_apply" | "roadmap_export" | "roadmap_export_apply";
|
|
22
9
|
args: Record<string, unknown>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// #1856 T2 AC2: the single offline `sdlc` row of `ahub doctor`. It reads the file on disk and, when the hub is up, the hub's own offline audit; it never calls GitHub.
|
|
2
|
+
import type { DoctorCheck } from "./output.ts";
|
|
3
|
+
import { loadSdlc } from "../hub/sdlc.ts";
|
|
4
|
+
import type { SdlcCheckReport } from "../hub/sdlc-check.ts";
|
|
5
|
+
|
|
6
|
+
/** Pure: the running hub's offline report (when reachable) and the file's parse state in, one Config row out. Only a file that does not parse fails the row. */
|
|
7
|
+
export function sdlcDoctorRow(input: { report?: Pick<SdlcCheckReport, "rows" | "withheld">; file: { present: boolean; mode?: string; error?: string }; hubUp: boolean }): DoctorCheck {
|
|
8
|
+
const name = "sdlc", section = "Config" as const, next = "run ahub sdlc check for the causes and next steps";
|
|
9
|
+
if (input.file.error) return { name, section, level: "fail", detail: `.agenthub/sdlc.toml does not parse: ${input.file.error.slice(0, 160)}; fix it and run ahub restart, then ${next}` };
|
|
10
|
+
const parts = [input.file.present ? `mode ${input.file.mode}` : "no .agenthub/sdlc.toml (lifecycle off)"];
|
|
11
|
+
const rows = input.report?.rows ?? [];
|
|
12
|
+
const restart = rows.find(row => row.id === "restart");
|
|
13
|
+
if (restart?.state === "warn") parts.push("restart pending");
|
|
14
|
+
const bindings = rows.filter(row => row.section === "bindings" && row.state === "warn").length;
|
|
15
|
+
if (bindings) parts.push(`${bindings} binding warning${bindings === 1 ? "" : "s"}`);
|
|
16
|
+
const roles = rows.filter(row => row.id.startsWith("role ") && row.state === "warn").length;
|
|
17
|
+
if (roles) parts.push(`${roles} role${roles === 1 ? "" : "s"} unrostered`);
|
|
18
|
+
if (!input.hubUp) parts.push("hub not running, so restart and bindings are not read");
|
|
19
|
+
const warn = !input.file.present || input.file.mode === "off" || restart?.state === "warn" || bindings > 0 || roles > 0 || !input.hubUp;
|
|
20
|
+
return { name, section, level: warn ? "warn" : "ok", detail: `${parts.join("; ")}${warn ? `; ${next}` : ""}` };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The file's own state, read without a hub or a network call. */
|
|
24
|
+
export function readSdlcFile(cwd: string, version?: string): { present: boolean; mode?: string; error?: string } {
|
|
25
|
+
try { const config = loadSdlc(cwd, version); return { present: Bun.file(`${cwd}/.agenthub/sdlc.toml`).size > 0 || config.mode !== "off", mode: config.mode }; }
|
|
26
|
+
catch (error) { return { present: true, error: error instanceof Error ? error.message : "unreadable" }; }
|
|
27
|
+
}
|