@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,114 @@
|
|
|
1
|
+
import { parseSynthesisManifest, synthesisManifestHash } from "../../hub/synthesis-readiness.ts";
|
|
2
|
+
import { renderHandoffReceipt, renderHandoffs } from "../handoff-output.ts";
|
|
3
|
+
import { parseHandoffArgs } from "../handoff-args.ts";
|
|
4
|
+
import { resolveProfile } from "../../hub/profiles.ts";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { CLASSES } from "../../hub/board.ts";
|
|
7
|
+
import { unknownOption, unknownOptionRefusal, withoutSeparator } from "../free-text.ts";
|
|
8
|
+
import { readEvents } from "../../hub/events.ts";
|
|
9
|
+
import { appendRecords, LABELS, labelTarget, RESEARCH_SCHEMA, projectKey, readStores, type Label, type TaskRecord } from "../../hub/research.ts";
|
|
10
|
+
import { refuseSynthesisTaskMismatch } from "../commands/shared-refusals.ts";
|
|
11
|
+
import { type Span } from "../console-state.ts";
|
|
12
|
+
import { subcommandUsage } from "../help.ts";
|
|
13
|
+
import { renderTaskCancel, renderTaskShow } from "../task-output.ts";
|
|
14
|
+
import type { CommandContext } from "../command-context.ts";
|
|
15
|
+
|
|
16
|
+
export async function run(context: CommandContext) {
|
|
17
|
+
const { args, connect, contract, identity, missingTaskText, outputOptions, projectConfig, researchProject, showToolText, splitPresentation, stateDir, takeFlags, taskOp, warn } = context;
|
|
18
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
19
|
+
const presentation = splitPresentation(args, { valueFlags: ["--reason", "--superseded-by", "--revision"], edges: true });
|
|
20
|
+
const shownTask = (render: (data: any, columns?: number, now?: number, ascii?: boolean) => Span[][]) => async (text: Promise<string>) => showToolText(render, await text, outputOptions(presentation.flags));
|
|
21
|
+
// task show and task cancel read their presentation options before the request goes out (a refusal after a cancel would invite a retry of work already done)
|
|
22
|
+
if (["show", "cancel"].includes(args[0] ?? "")) outputOptions(presentation.flags);
|
|
23
|
+
const [sub, ...rest] = ["show", "cancel"].includes(args[0] ?? "") ? presentation.operands : args;
|
|
24
|
+
if (sub === "role") {
|
|
25
|
+
if (rest.length !== 2 || !/^[1-9]\d*$/.test(rest[0]!)) fail("usage: ahub task role <id> <role|none>");
|
|
26
|
+
const hub = await connect();
|
|
27
|
+
try { const reply = await hub.request({ t: "task_catalog_role", id: Number(rest[0]), role: rest[1] === "none" ? null : rest[1] }); if (!reply.ok) fail(reply.error); console.log(reply.text); }
|
|
28
|
+
finally { hub.close(); }
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (sub === "cancel") {
|
|
32
|
+
const { one, rest: positional } = takeFlags(rest, ["--reason", "--superseded-by", "--revision"], []);
|
|
33
|
+
const revision = one["--revision"] === undefined ? undefined : Number(one["--revision"]);
|
|
34
|
+
if (positional.length !== 1 || !/^[1-9]\d*$/.test(positional[0]!) || !one["--reason"]?.trim() || (revision !== undefined && (!/^\d+$/.test(one["--revision"]!) || !Number.isSafeInteger(revision)))) fail("usage: ahub task cancel <id> --reason <text> [--superseded-by <ref>] [--revision N]");
|
|
35
|
+
return shownTask(renderTaskCancel)(taskOp("hub_task_cancel", { id: Number(positional[0]), reason: one["--reason"], ...(one["--superseded-by"] === undefined ? {} : { superseded_by: one["--superseded-by"] }), ...(revision === undefined ? {} : { revision }) }));
|
|
36
|
+
}
|
|
37
|
+
if (sub === "show") {
|
|
38
|
+
// a stray operand (for example the value of a `--color always` that is not the `--color=` form) is a usage error, never silently ignored
|
|
39
|
+
if (rest.length !== 1) fail("usage: ahub task show <id> [--json] [--full] [--color=auto|always|never]");
|
|
40
|
+
// CLI output standard v1: a lookup that finds nothing is a failure (stderr, exit 1), not a successful print. The daemon answers a missing id with a JSON string
|
|
41
|
+
// (`"no task #N"`) while a found task is an object. The exit code is the standard's and is set apart from the format: `--json` keeps printing the hub's own document
|
|
42
|
+
// byte for byte on stdout, and exits 1 like the human path, which prints the error and a next step on stderr instead.
|
|
43
|
+
const shown = taskOp("task_show", { id: rest[0] });
|
|
44
|
+
const missing = missingTaskText(await shown);
|
|
45
|
+
if (missing !== undefined && !outputOptions(presentation.flags).json) return fail(missing, false, undefined, "ahub board");
|
|
46
|
+
await shownTask(renderTaskShow)(shown);
|
|
47
|
+
if (missing !== undefined) process.exitCode = 1; // --json printed the hub's document above; a lookup that found nothing still fails
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (sub === "claim") {
|
|
51
|
+
// #901: a person's verdict on one declared plan claim. The claim is named by its 1-based slot and its text is never typed, stored or printed here.
|
|
52
|
+
const { one, rest: positional } = takeFlags(rest, ["--model", "--model-said", "--manifest", "--disposition"], []);
|
|
53
|
+
if (positional.length !== 3 || !/^[1-9]\d*$/.test(positional[0]!) || !/^[1-9]\d*$/.test(positional[1]!) || !["supported", "unsupported", "unclear"].includes(positional[2]!)
|
|
54
|
+
|| (one["--manifest"] === undefined) !== (one["--disposition"] === undefined)
|
|
55
|
+
|| one["--manifest"] !== undefined && !["resolved", "qualified"].includes(one["--disposition"]!)) fail("usage: ahub task claim <id> <slot> <supported|unsupported|unclear> [--model <label>] [--model-said <supported|unsupported|unclear>] [--manifest <manifest.json> --disposition <resolved|qualified>]");
|
|
56
|
+
const manifest = one["--manifest"] === undefined ? undefined : parseSynthesisManifest(contract(one["--manifest"], "manifest"));
|
|
57
|
+
if (manifest && manifest.taskId !== Number(positional[0])) return refuseSynthesisTaskMismatch(fail);
|
|
58
|
+
const reply = JSON.parse(await taskOp("claim_verdict", { id: Number(positional[0]), slot: Number(positional[1]), verdict: positional[2], ...(one["--model"] === undefined ? {} : { model: one["--model"] }), ...(one["--model-said"] === undefined ? {} : { modelVerdict: one["--model-said"] }), ...(manifest === undefined ? {} : { manifest, synthesis: { manifestSha256: synthesisManifestHash(manifest), disposition: one["--disposition"] } }) })) as { task: number; recorded?: { slot: number; verdict: string; model?: string; modelVerdict?: string; synthesis?: { manifestSha256: string; disposition: string } } };
|
|
59
|
+
return console.log(`task #${reply.task}: claim ${reply.recorded?.slot} recorded as ${reply.recorded?.verdict}${reply.recorded?.model ? ` (model ${reply.recorded.model}` : ""}${reply.recorded?.modelVerdict ? `${reply.recorded?.model ? ", " : " ("}model said ${reply.recorded.modelVerdict}` : ""}${reply.recorded?.model || reply.recorded?.modelVerdict ? ")" : ""}${reply.recorded?.synthesis ? `; synthesis ${reply.recorded.synthesis.disposition} @ ${reply.recorded.synthesis.manifestSha256}` : ""}`);
|
|
60
|
+
}
|
|
61
|
+
if (sub === "escalate") return console.log(await taskOp("task_escalate", { id: rest[0] }));
|
|
62
|
+
if (sub === "assign") {
|
|
63
|
+
const { one, rest: positional } = takeFlags(rest, ["--role", "--revision"], []);
|
|
64
|
+
const role = one["--role"] ?? "owner", rawRevision = one["--revision"], revision = rawRevision === undefined ? undefined : Number(rawRevision);
|
|
65
|
+
if (positional.length !== 2 || !["owner", "reviewer", "planner"].includes(role) || (rawRevision !== undefined && (!/^\d+$/.test(rawRevision) || !Number.isSafeInteger(revision)))) fail("usage: ahub task assign <id> <peer> [--role owner|reviewer|planner] [--revision N]");
|
|
66
|
+
return console.log(await taskOp(revision === undefined ? "task_assign" : "task_assign_checked", { id: positional[0], peer: positional[1], ...(role !== "owner" ? { role } : {}), ...(revision === undefined ? {} : { revision }) }));
|
|
67
|
+
}
|
|
68
|
+
if (sub === "unassign") {
|
|
69
|
+
const { one, rest: positional } = takeFlags(rest, ["--role", "--revision"], []);
|
|
70
|
+
const role = one["--role"] ?? "owner", rawRevision = one["--revision"], revision = rawRevision === undefined ? undefined : Number(rawRevision);
|
|
71
|
+
if (positional.length !== 1 || !["owner", "reviewer"].includes(role) || (rawRevision !== undefined && (!/^\d+$/.test(rawRevision) || !Number.isSafeInteger(revision)))) fail("usage: ahub task unassign <id> [--role owner|reviewer] [--revision N]");
|
|
72
|
+
return console.log(await taskOp("task_unassign", { id: positional[0], role, ...(revision === undefined ? {} : { revision }) }));
|
|
73
|
+
}
|
|
74
|
+
if (sub === "label") {
|
|
75
|
+
// #247: a later verdict on an approved task, for research records (#933: an agent's own task only, attributed to it).
|
|
76
|
+
const { one, rest: positional } = takeFlags(rest, ["--created"], []);
|
|
77
|
+
const id = Number(positional[0]), label = positional[1] as Label;
|
|
78
|
+
if (positional.length !== 2 || !/^[1-9]\d*$/.test(positional[0]!) || !Number.isSafeInteger(id) || !(LABELS as readonly string[]).includes(label)) fail(`usage: ahub task label <id> ${LABELS.join("|")} [--created <time from ahub research export>]`);
|
|
79
|
+
// #933: the daemon checks the current board row only, so an agent never names an earlier task with this id from before a reset.
|
|
80
|
+
if (identity.role === "tools" && one["--created"] !== undefined) fail("--created names an earlier task with this id; only the person labels it (ahub console or a terminal)");
|
|
81
|
+
const project = researchProject();
|
|
82
|
+
// #933: an agent labels only its own task, which the daemon checks by role; its record names it, so it never reads as the person's verdict.
|
|
83
|
+
if (identity.role === "tools") await taskOp("task_label_check", { id });
|
|
84
|
+
let record: TaskRecord;
|
|
85
|
+
try { record = labelTarget(readStores(project.id), readEvents(join(stateDir, "events.jsonl")), id, one["--created"]); } catch (error) { fail((error as Error).message); }
|
|
86
|
+
appendRecords(project.id, [{ schema: RESEARCH_SCHEMA, kind: "label", project: projectKey(project.id), task: id, createdAt: record!.createdAt!, label, at: new Date().toISOString(), ...(identity.role === "tools" ? { by: identity.peer } : {}) }]);
|
|
87
|
+
return console.log(`task #${id} (approved ${record!.approvedAt}) labelled ${label} in the research records`);
|
|
88
|
+
}
|
|
89
|
+
if (sub === "handoff") {
|
|
90
|
+
// #604: work that belongs to ANOTHER project that runs agent-hub goes onto that project's board. The person's form (a console command: the classifier gives an agent `console` for it, and an
|
|
91
|
+
// agent uses hub_task_handoff); the hub resolves the target, asks its daemon and records the answer. Nothing is queued: a target that is not running is named with the action.
|
|
92
|
+
const present = outputOptions(splitPresentation(rest, { valueFlags: ["--project", "--path", "--issue", "--task", "--detail", "--duplicate-ok", "--key"], edges: true }).flags);
|
|
93
|
+
const parsed = parseHandoffArgs(splitPresentation(rest, { valueFlags: ["--project", "--path", "--issue", "--task", "--detail", "--duplicate-ok", "--key"], edges: true }).operands);
|
|
94
|
+
if ("usage" in parsed) return fail(parsed.usage);
|
|
95
|
+
// #734: the person's list (age and reachability of each target) and sync (ask the targets now); both read the same rows `ahub board --handoffs` shows.
|
|
96
|
+
if ("view" in parsed) return showToolText((data, _c, now, ascii) => renderHandoffs(data, present.columns, now, ascii), await taskOp(parsed.view === "sync" ? "hub_task_handoff_sync" : "hub_task_handoffs", {}), present);
|
|
97
|
+
const text = await taskOp("hub_task_handoff", { ...parsed });
|
|
98
|
+
return showToolText((data, _c, now, ascii) => renderHandoffReceipt(data, present.columns, now, ascii), text, present);
|
|
99
|
+
}
|
|
100
|
+
if (sub !== "propose" || rest.length < 1) fail("usage: ahub task propose [<class>] <title...> | show <id> | assign <id> <peer> | unassign <id> | cancel <id> --reason <text> | escalate <id> | handoff --project <root|id> <title...>");
|
|
101
|
+
// `--class` is the explicit form. A first word that is a class name is still taken as the class (the documented
|
|
102
|
+
// short form), but said out loud: "review the auth module" would otherwise be filed as class review, silently.
|
|
103
|
+
const urgent = rest.includes("--urgent"), backlog = rest.includes("--backlog"), needsNetwork = rest.includes("--needs-network"), needsWorktree = rest.includes("--needs-worktree");
|
|
104
|
+
const flags = takeFlags(rest.filter((a) => a !== "--urgent" && a !== "--backlog" && a !== "--needs-network" && a !== "--needs-worktree"), ["--owner", "--detail", "--class"], ["--path", "--after"]);
|
|
105
|
+
const positional = !flags.one["--class"] && ((CLASSES as readonly string[]).includes(flags.rest[0] ?? "") || Object.hasOwn((() => { const config = projectConfig(); return resolveProfile(config.profile, config.profile_overrides); })().classes, flags.rest[0] ?? "")) && flags.rest.length > 1;
|
|
106
|
+
// #1433: a title word that is an option the command does not know, or -h, is refused before anything is filed. A lone `--` ends the options, so a title that starts with dashes can still be typed.
|
|
107
|
+
const stray = unknownOption(flags.rest);
|
|
108
|
+
if (stray) fail(unknownOptionRefusal(stray, "ahub task propose", subcommandUsage("task", "propose")));
|
|
109
|
+
const textWords = withoutSeparator(flags.rest);
|
|
110
|
+
const cls = flags.one["--class"] ?? (positional ? textWords[0] : undefined);
|
|
111
|
+
const title = (positional ? textWords.slice(1) : textWords).join(" ");
|
|
112
|
+
if (positional) warn(`"${cls}" was taken as the class and left out of the title`, "use --class <c> when the title itself starts with that word");
|
|
113
|
+
console.log(await taskOp("hub_task_propose", { ...(cls ? { class: cls } : {}), title, owner: flags.one["--owner"], detail: flags.one["--detail"], ...(flags.many["--path"]?.length ? { refs: { paths: flags.many["--path"] } } : {}), ...(flags.many["--after"]?.length ? { after: flags.many["--after"].map(Number) } : {}), ...(urgent ? { urgent: true } : {}), ...(needsNetwork ? { needs_network: true } : {}), ...(needsWorktree ? { needs_worktree: true } : {}), ...(backlog ? { backlog: true } : {}) }));
|
|
114
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { shellQuote } from "../shell-quote.ts";
|
|
2
|
+
import type { CommandContext } from "../command-context.ts";
|
|
3
|
+
|
|
4
|
+
export async function run(context: CommandContext) {
|
|
5
|
+
const { args, connect, cwd } = context;
|
|
6
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
7
|
+
const [peer, ...words] = args;
|
|
8
|
+
if (!peer || !words.length) fail("usage: ahub title <peer> <text...>");
|
|
9
|
+
const hub = await connect();
|
|
10
|
+
try {
|
|
11
|
+
const reply = await hub.request({ t: "title", peer, title: words.join(" ") }, 35_000).catch(() => ({ ok: false, error: "session title result is unconfirmed; the title may have been applied; check ahub status before retrying" }));
|
|
12
|
+
if (reply.ok === false && reply.error === "no answer from the hub within 35 s") fail("session title request timed out; the title may have been applied; check ahub status before retrying");
|
|
13
|
+
if (reply.ok !== true) fail(String(reply.error ?? `session title refused: ${String(reply.reason ?? "invalid")}; refresh ahub status, then retry`));
|
|
14
|
+
console.log(`${peer}: session title updated`);
|
|
15
|
+
if (typeof reply.previousTitle === "string") console.log(`To restore the previous title in a terminal:\ncd ${shellQuote(cwd)} && ahub title ${shellQuote(peer!)} ${shellQuote(reply.previousTitle)}`);
|
|
16
|
+
} finally { hub.close(); }
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { renderTurns } from "../output.ts";
|
|
2
|
+
import type { CommandContext } from "../command-context.ts";
|
|
3
|
+
|
|
4
|
+
export function run({ outputArguments, outputOptions, printOutput, takeFlags, turnRecords }: CommandContext) {
|
|
5
|
+
const options = outputOptions();
|
|
6
|
+
const { one, rest } = takeFlags(outputArguments(), ["--limit"], []);
|
|
7
|
+
const turns = turnRecords(t => t.list(rest[0], Number(one["--limit"]) || 20), []);
|
|
8
|
+
if (options.json) return console.log(JSON.stringify(turns, null, 2));
|
|
9
|
+
printOutput(renderTurns(turns, options.columns, Date.now()), options.color);
|
|
10
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { openManager, stopManager } from "../../hub/manager.ts";
|
|
3
|
+
import type { CommandContext } from "../command-context.ts";
|
|
4
|
+
|
|
5
|
+
export async function run(context: CommandContext) {
|
|
6
|
+
const { args, connect, delegatedPeer, setJsonBlockers, warn } = context;
|
|
7
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
8
|
+
const display = { json: args.includes("--json") };
|
|
9
|
+
setJsonBlockers(display.json);
|
|
10
|
+
const all = args.includes("--all");
|
|
11
|
+
const stop = args.includes("--stop"), noOpen = args.includes("--no-open");
|
|
12
|
+
const invalid = args.some(arg => !["--no-open", "--all", "--stop", "--settings", "--json"].includes(arg));
|
|
13
|
+
if (display.json && (invalid || (stop ? !all || noOpen : !noOpen)))
|
|
14
|
+
fail("usage: ahub ui [--settings] [--no-open [--json]] | --all [--no-open [--json]] | --all --stop [--json]");
|
|
15
|
+
if (invalid) fail("usage: ahub ui [--settings] [--no-open] | --all [--no-open] | --all --stop");
|
|
16
|
+
// #269: a settings session belongs to one project's hub; the unified dashboard stays an ordinary session.
|
|
17
|
+
const settings = args.includes("--settings");
|
|
18
|
+
if (settings && all) fail("ahub ui --settings opens one project's dashboard; run it without --all");
|
|
19
|
+
if (stop) {
|
|
20
|
+
if (!all || noOpen) fail("usage: ahub ui --all --stop");
|
|
21
|
+
await stopManager();
|
|
22
|
+
if (display.json) return console.log(JSON.stringify({ ok: true, stopped: true }));
|
|
23
|
+
return console.log("dashboard manager stopped; project hubs were kept running");
|
|
24
|
+
}
|
|
25
|
+
let url: string;
|
|
26
|
+
if (all) url = await openManager({ liveTest: !!delegatedPeer });
|
|
27
|
+
else {
|
|
28
|
+
const hub = await connect();
|
|
29
|
+
try {
|
|
30
|
+
const res = await hub.request({ t: "ui", ...(settings ? { settings: true } : {}), ...(delegatedPeer ? { liveTest: true } : {}) }, 10_000);
|
|
31
|
+
if (!res.ok) fail(res.error);
|
|
32
|
+
if (delegatedPeer && res.liveTest !== true) fail("this hub cannot restrict delegated dashboard content; use a live-test-capable hub");
|
|
33
|
+
// A hub older than #269 ignores the field and would hand out an ordinary session without saying so.
|
|
34
|
+
if (settings && res.settings !== true) fail("this hub does not open settings sessions; upgrade the running hub to use ahub ui --settings");
|
|
35
|
+
url = res.url;
|
|
36
|
+
} finally { hub.close(); }
|
|
37
|
+
}
|
|
38
|
+
if (settings) warn("Settings session: for 15 minutes this dashboard session may change permission modes, routing and start settings");
|
|
39
|
+
if (display.json) return console.log(JSON.stringify({
|
|
40
|
+
ok: true, url, origin: new URL(url).origin, mode: all ? "manager" : "hub", settings,
|
|
41
|
+
}));
|
|
42
|
+
if (args.includes("--no-open")) return console.log(url);
|
|
43
|
+
const opener = process.platform === "darwin" ? "open" : "xdg-open";
|
|
44
|
+
const opened = spawnSync(opener, [url], { stdio: "ignore", timeout: 10_000 });
|
|
45
|
+
if (opened.error || opened.status !== 0) console.log(`Open this one-time link within 60 seconds:\n${url}`);
|
|
46
|
+
else console.log("Dashboard opened. The session expires in one hour; run ahub ui to reopen it.");
|
|
47
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { effectiveInstanceRoles } from "../../hub/instances.ts";
|
|
2
|
+
import { resolveInstanceExecutionCwd } from "../../hub/instance-execution.ts";
|
|
3
|
+
import { readInstanceConfig } from "../../hub/instance-config.ts";
|
|
4
|
+
import { matchesPolicy } from "../../hub/path-policy.ts";
|
|
5
|
+
import { projectedDiff } from "../../hub/projected-diff.ts";
|
|
6
|
+
import { TextProjections } from "../../hub/text-projection.ts";
|
|
7
|
+
import { terminalText } from "../console-state.ts";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { realPath } from "../../hub/project.ts";
|
|
10
|
+
import { hasTree, planUndo, repoOf, restore } from "../../hub/snapshots.ts";
|
|
11
|
+
import { asciiMarkers } from "../console-state.ts";
|
|
12
|
+
import { renderLifecycleReceipt, renderUndoPlan } from "../reset-output.ts";
|
|
13
|
+
import type { CommandContext } from "../command-context.ts";
|
|
14
|
+
|
|
15
|
+
export async function run(context: CommandContext) {
|
|
16
|
+
const { args, cwd, printOutput, projectConfig, stateDir, taskOp, turnRecords, warn } = context;
|
|
17
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
18
|
+
const id = args.find((a) => !a.startsWith("--")) ?? fail("usage: ahub undo <turn> [--yes] [--context]");
|
|
19
|
+
const turn = turnRecords((t) => t.get(id), undefined) ?? fail(`no turn ${id} recorded (ahub turns lists them)`);
|
|
20
|
+
if (!turn.ended) fail(`turn ${id} is still running`);
|
|
21
|
+
const { start_tree: startTree, end_tree: endTree } = turn;
|
|
22
|
+
if (!startTree || !endTree) fail(`turn ${id} has no ${startTree ? "end" : "start"} snapshot: the hub stopped during it, or a snapshot failed (see hub.log)`);
|
|
23
|
+
const recordedWorkspace = turnRecords(t => t.workspace(id), undefined);
|
|
24
|
+
const undoWorkspace = (): string => {
|
|
25
|
+
// Old turns, including external peers and ids declared only later, belong to the canonical checkout.
|
|
26
|
+
if (recordedWorkspace === undefined) return cwd;
|
|
27
|
+
const { instances: declarations, catalog } = readInstanceConfig(cwd);
|
|
28
|
+
if (!declarations || !Object.hasOwn(declarations, turn.peer)) fail(`turn ${id}'s recorded instance is no longer declared; nothing was restored`);
|
|
29
|
+
const config = projectConfig();
|
|
30
|
+
const current = resolveInstanceExecutionCwd(cwd, turn.peer, declarations, effectiveInstanceRoles(turn.peer, declarations, config.roles, catalog), catalog);
|
|
31
|
+
if (realPath(current) !== realPath(recordedWorkspace)) fail(`turn ${id}'s recorded execution workspace changed; nothing was restored`);
|
|
32
|
+
return current;
|
|
33
|
+
};
|
|
34
|
+
const undoCwd = undoWorkspace();
|
|
35
|
+
const requireUndoWorkspace = () => {
|
|
36
|
+
if (realPath(undoWorkspace()) !== realPath(undoCwd)) fail(`turn ${id}'s execution workspace changed; nothing was restored`);
|
|
37
|
+
};
|
|
38
|
+
const repo = repoOf(undoCwd) ?? fail(`${undoCwd} is not in a git work tree`);
|
|
39
|
+
if (!hasTree(repo, startTree) || !hasTree(repo, endTree)) fail(`turn ${id}'s snapshots are gone from the git object store (git gc prunes them after two weeks)`);
|
|
40
|
+
// Another peer's turn that overlapped this one in time has its changes in this turn's diff as well.
|
|
41
|
+
const undoConfig = projectConfig();
|
|
42
|
+
const keep = Math.max(1, Number(undoConfig.snapshots.keep) || 20);
|
|
43
|
+
const overlapping = turnRecords((t) => t.overlapping(turn, keep), { paths: [] as string[], unknown: [] as string[] });
|
|
44
|
+
if (overlapping.unknown.length) fail(`refusing to undo ${id}: these turns of other peers ran at the same time and their changes are not known (still running, cut short, or not snapshotted): ${overlapping.unknown.join(", ")}`);
|
|
45
|
+
let reverted = false;
|
|
46
|
+
const plan = () => {
|
|
47
|
+
const p = planUndo(repo, { start_tree: startTree, end_tree: endTree, changed: turn.changed }, overlapping.paths);
|
|
48
|
+
if (p.undone) return p;
|
|
49
|
+
const why = [
|
|
50
|
+
p.changedSince.length ? `these files changed again after it ended, and restoring them would lose that work:\n ${p.changedSince.join("\n ")}` : "",
|
|
51
|
+
p.concurrent.length ? `these files were also changed by another peer's turn running at the same time, so the change may be theirs:\n ${p.concurrent.join("\n ")}` : "",
|
|
52
|
+
].filter(Boolean);
|
|
53
|
+
if (why.length) fail(`refusing to undo ${id}: ${why.join("\n")}${reverted ? "\nCodex's conversation was already reverted; restore the files later with ahub undo without --context" : ""}`);
|
|
54
|
+
return p;
|
|
55
|
+
};
|
|
56
|
+
// #798 D3: the hub saw these submodules dirty when the turn ended and cannot see inside them: they are never restored, and never counted as "no change".
|
|
57
|
+
const unobserved = turn.unobserved ?? [];
|
|
58
|
+
const first = plan();
|
|
59
|
+
printOutput(renderUndoPlan({ id, restore: first.restore, unobserved, undone: first.undone }, undefined, undefined, asciiMarkers(process.env)), false);
|
|
60
|
+
if (first.undone) return;
|
|
61
|
+
const projections = new TextProjections({ cwd: undoCwd, stateDir, config: undoConfig.text_projection ?? {}, deny: undoConfig.local.deny, readAllow: undoConfig.local.read_allow, log: line => warn(line) });
|
|
62
|
+
const preview = projectedDiff({ repo, from: endTree, to: startTree, paths: first.restore, projections, deny: undoConfig.local.deny, privatePath: path => matchesPolicy(undoCwd, join(repo.top, path), undoConfig.pii?.paths ?? []) });
|
|
63
|
+
if (preview) printOutput(renderLifecycleReceipt({ lines: [terminalText("Undo preview (end snapshot to start snapshot):\n" + preview)] }), false);
|
|
64
|
+
|
|
65
|
+
if (!args.includes("--yes")) return printOutput(renderLifecycleReceipt({ lines: ["nothing was changed; add --yes to restore these files"] }), false);
|
|
66
|
+
requireUndoWorkspace();
|
|
67
|
+
if (args.includes("--context")) {
|
|
68
|
+
printOutput(renderLifecycleReceipt({ lines: [await taskOp("turn_revert", { turn: id })] }), false);
|
|
69
|
+
reverted = true;
|
|
70
|
+
}
|
|
71
|
+
// A peer may have written meanwhile (the revert alone can take seconds): plan again right before restoring.
|
|
72
|
+
const second = plan();
|
|
73
|
+
if (second.restore.join("\0") !== first.restore.join("\0")) fail(`the project changed while undoing; nothing was restored, run ahub undo again${reverted ? " without --context (Codex's conversation was already reverted)" : ""}`);
|
|
74
|
+
requireUndoWorkspace();
|
|
75
|
+
restore(repo, startTree, second.restore);
|
|
76
|
+
if (second.restore.length) printOutput(renderLifecycleReceipt({ lines: [`restored to their state before ${id}`] }), false);
|
|
77
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { terminalText } from "../console-state.ts";
|
|
2
|
+
import { loadConfig } from "../../hub/config.ts";
|
|
3
|
+
import { hubHome } from "../../hub/project.ts";
|
|
4
|
+
import { startProject } from "../../hub/lifecycle.ts";
|
|
5
|
+
import { UNATTENDED_WARNING } from "../launch.ts";
|
|
6
|
+
import { personEnv } from "../../hub/child-process.ts";
|
|
7
|
+
import { effectiveStartAgents, startProjectAgents } from "../start-agents-run.ts";
|
|
8
|
+
import { runConsole } from "../console.ts";
|
|
9
|
+
import type { CommandContext } from "../command-context.ts";
|
|
10
|
+
|
|
11
|
+
export async function run(context: CommandContext) {
|
|
12
|
+
const { args, caller, connect, consoleInstalled, continuationId, continuationPeer, cwd, identity, liveTest, recoveryLauncherCurrent, registeredProject, stateDir, unattendedEnv, upHubCheck, upJsonDocument, warn } = context;
|
|
13
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
14
|
+
// #1798: --wait is checked before the hub or any agent starts, so a bad value costs nothing (`upWait` is the one place it is read).
|
|
15
|
+
const waitIndex = args.indexOf("--wait"), waitText = waitIndex >= 0 ? args[waitIndex + 1] : undefined;
|
|
16
|
+
const upWaitS = waitIndex < 0 ? 15 : waitText === undefined || !/^\d+$/.test(waitText) ? NaN : Number(waitText);
|
|
17
|
+
if (!(upWaitS <= 600)) return fail(`--wait needs a whole number of seconds from 0 to 600, got ${waitText === undefined || waitText === "" ? "nothing" : `"${terminalText(waitText)}"`}; nothing was started. Next: ahub up --wait 15`);
|
|
18
|
+
const unattended = unattendedEnv || args.includes("--unattended");
|
|
19
|
+
if (unattended) console.error(UNATTENDED_WARNING);
|
|
20
|
+
const status = await startProject(registeredProject(), { unattended, liveTest, starting: pid => console.error(`ahub: hub is still starting, pid ${pid}; waiting for readiness, run ahub status in another terminal to inspect progress`), ...(recoveryLauncherCurrent ? { current: recoveryLauncherCurrent, env: { ...personEnv(process.env), AGENTHUB_RECOVERY_OPERATION: continuationId, AGENTHUB_PEER_ID: continuationPeer, AGENTHUB_RECOVERY_CONDUCTOR: continuationPeer, AGENTHUB_RECOVERY_CONTINUATION: continuationId } } : {}) });
|
|
21
|
+
// #1798: under --json stdout holds exactly one JSON document, so the banner and the start lines go to stderr; their text is unchanged.
|
|
22
|
+
const upJson = args.includes("--json") && !recoveryLauncherCurrent, stdoutLog = console.log;
|
|
23
|
+
if (upJson) console.log = (...parts: unknown[]) => { process.stderr.write(`${parts.join(" ")}\n`); };
|
|
24
|
+
console.log(`ahub up (ws://127.0.0.1:${status.controlPort}), state in ${stateDir}`);
|
|
25
|
+
if (recoveryLauncherCurrent) { recoveryLauncherCurrent(); return; }
|
|
26
|
+
// #608: the default agent set, only for a person's own `ahub up` (never an agent's, a live test's, or an upgrade or recovery relaunch, which set AGENTHUB_RECOVERY_OPERATION).
|
|
27
|
+
let upAgents: readonly string[] | undefined;
|
|
28
|
+
if (!args.includes("--no-agents") && !liveTest && caller.role === "console" && identity.role === "console" && !process.env.AGENTHUB_RECOVERY_OPERATION) {
|
|
29
|
+
try {
|
|
30
|
+
const chosen = effectiveStartAgents(cwd, loadConfig(cwd).start.agents, hubHome(), [cwd]);
|
|
31
|
+
if (chosen.notice) warn(chosen.notice);
|
|
32
|
+
for (const line of await startProjectAgents({ root: cwd, stateDir }, chosen.agents)) console.log(terminalText(line));
|
|
33
|
+
upAgents = chosen.agents;
|
|
34
|
+
} catch (error) { warn(`default agents were not started: ${terminalText((error as Error).message)}`); }
|
|
35
|
+
}
|
|
36
|
+
const upCheck = upAgents && await upHubCheck(upAgents, upWaitS, upJson);
|
|
37
|
+
if (upJson) { console.log = stdoutLog; await upJsonDocument(upCheck); return; }
|
|
38
|
+
if (process.stdin.isTTY && process.stdout.isTTY && !args.includes("--no-console")) await runConsole({ client: await connect(), cwd, stateDir, liveTest, installed: consoleInstalled() });
|
|
39
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { refuseMissingFlagValue } from "./shared-refusals.ts";
|
|
2
|
+
import { USAGE_GROUPS, LIMITS_MAX } from "../../hub/usage-rollup.ts";
|
|
3
|
+
import { renderUsage, renderLimits, renderTotal } from "../output.ts";
|
|
4
|
+
import type { CommandContext } from "../command-context.ts";
|
|
5
|
+
|
|
6
|
+
export async function run(context: CommandContext) {
|
|
7
|
+
const { args, connect, outputArguments, outputOptions, printOutput, since } = context;
|
|
8
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
9
|
+
const options = outputOptions();
|
|
10
|
+
const rest = outputArguments();
|
|
11
|
+
const sub = rest[0] !== undefined && !rest[0].startsWith("--") ? rest[0] : undefined;
|
|
12
|
+
if (sub !== undefined && !["limits", "total"].includes(sub)) fail("usage: ahub usage [--since 7d|<iso>] [--by peer|task|issue|pr|release|day|model] [--json] | limits [--peer <id>] [--limit <n>] [--json] | total [--json]");
|
|
13
|
+
const flags = sub === undefined ? rest : rest.slice(1);
|
|
14
|
+
const valueFlags = sub === "limits" ? ["--peer", "--limit"] : sub === undefined ? ["--since", "--by"] : [];
|
|
15
|
+
for (let i = 0; i < flags.length; i++) {
|
|
16
|
+
if (!valueFlags.includes(flags[i]!)) fail(`unknown argument ${JSON.stringify(flags[i]!.slice(0, 40))}; run ahub help`);
|
|
17
|
+
if (flags[++i] === undefined || flags[i]!.startsWith("--")) refuseMissingFlagValue(fail, flags[i - 1]);
|
|
18
|
+
}
|
|
19
|
+
const value = (flag: string) => { const at = args.indexOf(flag); return at >= 0 ? args[at + 1] : undefined; };
|
|
20
|
+
const by = value("--by"), peer = value("--peer"), limitText = value("--limit");
|
|
21
|
+
const limit = limitText === undefined ? undefined : /^\d+$/.test(limitText) ? Number(limitText) : NaN;
|
|
22
|
+
if (limit !== undefined && !(limit >= 1 && limit <= LIMITS_MAX)) fail(`--limit takes a whole number from 1 to ${LIMITS_MAX}`);
|
|
23
|
+
if (by !== undefined && !(USAGE_GROUPS as readonly string[]).includes(by)) fail(`--by takes ${USAGE_GROUPS.join(", ")}`);
|
|
24
|
+
const from = since();
|
|
25
|
+
const hub = await connect();
|
|
26
|
+
const reply = await hub.request(sub === "limits" ? { t: "usage", op: "limits", ...(peer ? { peer } : {}), ...(limit !== undefined ? { limit } : {}) } : sub === "total" ? { t: "usage", op: "total" }
|
|
27
|
+
: { t: "usage", op: "query", by: by ?? "peer", ...(from ? { since: from } : {}) }, 35_000);
|
|
28
|
+
hub.close();
|
|
29
|
+
if (!reply.ok) return fail(String(reply.error ?? "usage refused"));
|
|
30
|
+
if (reply.behind) process.stderr.write("ahub: the usage roll-up is still catching up with the event log: these numbers are partial; run it again in a few seconds\n");
|
|
31
|
+
if (options.json) return console.log(JSON.stringify(sub === "limits" ? { limits: reply.limits, current: reply.current } : sub === "total" ? reply.total : reply.usage, null, 2));
|
|
32
|
+
printOutput(sub === "limits" ? renderLimits(reply.limits, reply.current, options.columns) : sub === "total" ? renderTotal(reply.total, options.columns) : renderUsage(reply.usage, options.columns), options.color);
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { attachWatch } from "../watch.ts";
|
|
2
|
+
import { resolveColor, streamEnv } from "../console-state.ts";
|
|
3
|
+
import type { CommandContext } from "../command-context.ts";
|
|
4
|
+
|
|
5
|
+
export async function run(context: CommandContext) {
|
|
6
|
+
const { args, connect, peerDefinition } = context;
|
|
7
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
8
|
+
const peer = args[0];
|
|
9
|
+
if (typeof peer !== "string" || !peerDefinition(peer)?.capabilities?.watch) fail("usage: ahub watch kimi|qwen [--no-thoughts] [--color=auto|always|never]");
|
|
10
|
+
if (args.slice(1).some(arg => arg !== "--no-thoughts" && !/^--color=(auto|always|never)$/.test(arg))) fail("unsupported watch option");
|
|
11
|
+
const color = resolveColor(args.find(arg => arg.startsWith("--color="))?.slice(8), streamEnv(!!process.stdout.isTTY), "ahub");
|
|
12
|
+
if (color instanceof Error) fail(color.message);
|
|
13
|
+
const hub = await connect();
|
|
14
|
+
const input = process.stdin;
|
|
15
|
+
const raw = !!input.isRaw;
|
|
16
|
+
let leave = () => {};
|
|
17
|
+
const closed = new Promise<void>(resolve => { leave = resolve; });
|
|
18
|
+
const key = (chunk: Buffer) => { if (chunk.includes(3) || chunk.toString().includes("q")) leave(); };
|
|
19
|
+
hub.onClose = leave;
|
|
20
|
+
process.on("SIGINT", leave);
|
|
21
|
+
try {
|
|
22
|
+
await attachWatch(hub, peer, line => console.log(line), { columns: () => process.stdout.columns || 80, color, noThoughts: args.includes("--no-thoughts") });
|
|
23
|
+
if (input.isTTY) { input.setRawMode(true); input.on("data", key); input.resume(); }
|
|
24
|
+
await closed;
|
|
25
|
+
} finally {
|
|
26
|
+
input.off("data", key); process.off("SIGINT", leave);
|
|
27
|
+
if (input.isTTY) input.setRawMode(raw);
|
|
28
|
+
input.pause(); hub.close();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { hubGitSync, hubGitEnv } from "../../hub/git.ts";
|
|
2
|
+
import { confirmTidy, planTidy, realTidyGit, rowsFromReply, type TidyGit } from "../worktree-tidy.ts";
|
|
3
|
+
import { renderTidyPreview, renderTidyResult, renderWorktrees } from "../worktrees-output.ts";
|
|
4
|
+
import { asciiMarkers } from "../console-state.ts";
|
|
5
|
+
import type { CommandContext } from "../command-context.ts";
|
|
6
|
+
|
|
7
|
+
export async function run(context: CommandContext) {
|
|
8
|
+
const { connect, cwd, outputArguments, outputOptions, printOutput } = context;
|
|
9
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
10
|
+
const options = outputOptions();
|
|
11
|
+
const rest = outputArguments();
|
|
12
|
+
const sub = rest[0] === "tidy" ? "tidy" : undefined;
|
|
13
|
+
const flags = sub ? rest.slice(1) : rest;
|
|
14
|
+
const at = flags.indexOf("--confirm");
|
|
15
|
+
const fingerprint = at >= 0 ? flags[at + 1] : undefined;
|
|
16
|
+
const known = flags.every((arg, i) => arg === "--confirm" || i === at + 1 && at >= 0);
|
|
17
|
+
if ((rest.length && !sub && rest.some(arg => !arg.startsWith("--"))) || !known || (at >= 0 && (!sub || fingerprint === undefined || fingerprint.startsWith("--"))) || (sub === undefined && at >= 0)) fail("usage: ahub worktrees [--json] | tidy [--json] | tidy --confirm <fingerprint>");
|
|
18
|
+
const hub = await connect();
|
|
19
|
+
const reply = await hub.request({ t: "worktrees" }, 20_000);
|
|
20
|
+
hub.close();
|
|
21
|
+
if (!reply.ok) return fail(String(reply.error ?? "the worktree shelf is unavailable"));
|
|
22
|
+
if (!sub) return options.json ? console.log(JSON.stringify({ live: reply.live, settled: reply.settled, complete: reply.complete }, null, 2)) : printOutput(renderWorktrees(reply, options.columns, Date.now(), asciiMarkers(process.env, process.argv.includes("--ascii"))), options.color);
|
|
23
|
+
// tidy: read-only git in this process to decide what is safe; the daemon only said which rows are settled.
|
|
24
|
+
const git: TidyGit = realTidyGit((argv, dir) => { const run = hubGitSync(argv, { cwd: dir, encoding: "utf8", timeout: 20_000, maxBuffer: 4 * 1024 * 1024, env: hubGitEnv(process.env, { repositoryIsolation: true }) }); return run.error ? undefined : { status: run.status, stdout: String(run.stdout ?? "") }; });
|
|
25
|
+
const plan = planTidy(rowsFromReply(reply.settled ?? [], cwd, git), cwd, git);
|
|
26
|
+
if (at < 0) return options.json ? console.log(JSON.stringify({ entries: plan.entries, removable: plan.removable, fingerprint: plan.fingerprint }, null, 2)) : printOutput(renderTidyPreview(plan, options.columns, Date.now(), asciiMarkers(process.env, process.argv.includes("--ascii"))), options.color);
|
|
27
|
+
const result = confirmTidy(plan, fingerprint!, cwd, git);
|
|
28
|
+
if (!result.ok) return fail(result.error);
|
|
29
|
+
if (options.json) return console.log(JSON.stringify({ outcomes: result.outcomes }, null, 2));
|
|
30
|
+
printOutput(renderTidyResult(result.outcomes, options.columns, Date.now(), asciiMarkers(process.env, process.argv.includes("--ascii"))), options.color);
|
|
31
|
+
}
|
package/src/cli/console-state.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { Report as SharedReport
|
|
1
|
+
import { Report as SharedReport } from "@staix/cli-output";
|
|
2
|
+
import { terminalText, paint, wrap, type Span, type Tone } from "./report-layout.ts";
|
|
3
|
+
export { terminalText, paint, wrap, Report, PALETTE, TONE_ROLE, type Span, type Tone } from "./report-layout.ts";
|
|
2
4
|
import { consoleNeeds, characterAttentionLine, attentionCommand } from "./attention.ts";
|
|
3
5
|
import { CHARACTERS, petFrame, petSize, petFooterRows, type CharacterId, type PetSize, type PetPose } from "../pet/frame.ts";
|
|
4
|
-
import { PEER_PALETTE } from "../ui/peer-palette.ts";
|
|
5
6
|
import { SGR_RESET, TONE_SGR, ROLE_SGR, MARKERS, MARKER_COLUMN, SECTION_MARKER, cellWidth, markerCell, resolveColor, asciiMarkers, streamEnv, MARKER_NAMES, type Role, type MarkerName, type ColorEnv } from "./output-standard.ts";
|
|
6
7
|
export { SGR_RESET, TONE_SGR, ROLE_SGR, MARKERS, MARKER_COLUMN, SECTION_MARKER, cellWidth, markerCell, resolveColor, asciiMarkers, streamEnv, MARKER_NAMES, type Role, type MarkerName, type ColorEnv };
|
|
7
8
|
import { PERMISSION_MODES, permissionBoundary } from "../hub/permission-mode.ts";
|
|
8
|
-
import { PLANNER_PEERS, definitionOf,
|
|
9
|
+
import { DECLARATION_PLANNER_PEERS as PLANNER_PEERS, builtinDeclarationOf as definitionOf, createProjectDeclarationCatalog as createProjectAdapterCatalog } from "../adapters/declaration-catalog.ts";
|
|
10
|
+
import { nativeStreamTone } from "../adapters/definitions/native-display.ts";
|
|
9
11
|
import { taskProgress } from "../ui/task-progress.ts";
|
|
10
12
|
import type { ProgressStage } from "../ui/task-progress.ts";
|
|
11
13
|
import { sanitize } from "../hub/envelope.ts";
|
|
@@ -135,30 +137,6 @@ export function syncPermissionDefaults(s: ConsoleState, rows: unknown): boolean
|
|
|
135
137
|
export function permissionDefaultText(row: Pick<PermissionDefault, "peer" | "source">): string {
|
|
136
138
|
return `never-ask default for ${row.peer} from ${quoted(row.source)}\n${permissionBoundary(row.peer, undefined, createProjectAdapterCatalog())}\nUntil you answer y, this default stays ask. y enables; n cancels for this hub; Esc defers.`;
|
|
137
139
|
}
|
|
138
|
-
/** Strip terminal controls before any daemon or child output reaches a terminal. Preserve printable Unicode. */
|
|
139
|
-
// Preserve the hub's control and header policy for non-Report output.
|
|
140
|
-
export function terminalText(value: unknown): string {
|
|
141
|
-
return sanitize(String(value ?? "")
|
|
142
|
-
.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\|$)/g, "")
|
|
143
|
-
.replace(/\x1b[P_X^][\s\S]*?(?:\x1b\\|$)/g, "")
|
|
144
|
-
.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "")
|
|
145
|
-
.replace(/\x1b[^\n]?/g, "").replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, ""));
|
|
146
|
-
}
|
|
147
|
-
export type Tone = "info" | "strong" | "success" | "attention" | "failure" | "muted" | "peerClaude" | "peerCodex" | "taskKeyword" | "number" | "issueRef" | "taskRef";
|
|
148
|
-
/** 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. */
|
|
149
|
-
export interface Span { text: string; tone?: Tone; role?: Role }
|
|
150
|
-
export const PALETTE: Readonly<Record<Tone, string>> = Object.freeze({
|
|
151
|
-
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,
|
|
152
|
-
peerClaude: PEER_PALETTE.claude.ansi, peerCodex: PEER_PALETTE.codex.ansi,
|
|
153
|
-
taskKeyword: PEER_PALETTE.kimi.ansi, number: TONE_SGR.number, issueRef: TONE_SGR.issueRef, taskRef: TONE_SGR.taskRef,
|
|
154
|
-
});
|
|
155
|
-
/** 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. */
|
|
156
|
-
export const TONE_ROLE: Readonly<Partial<Record<Tone, Role>>> = Object.freeze({
|
|
157
|
-
info: "accent", strong: "header", success: "success", attention: "warning", failure: "error", muted: "hint", number: "value",
|
|
158
|
-
});
|
|
159
|
-
export function paint(line: Span[], color: boolean): string {
|
|
160
|
-
return sharedPaint(line.map(({ tone, ...span }) => ({ ...span, text: terminalText(span.text), ...(tone ? { style: tone } : {}) })), color, PALETTE);
|
|
161
|
-
}
|
|
162
140
|
/** Console stream headers only. Tokenize sanitized text; bodies and command output stay plain. */
|
|
163
141
|
export function streamTokens(value: string, eventTone?: Tone, kind?: string): Span[] {
|
|
164
142
|
const text = terminalText(value);
|
|
@@ -236,105 +214,6 @@ export function wrapStreamTokens(value: string, columns: number, tone?: Tone, ki
|
|
|
236
214
|
return out;
|
|
237
215
|
});
|
|
238
216
|
}
|
|
239
|
-
/**
|
|
240
|
-
* The layout grammar of standard v1 as one builder, so every report has the same header, section, key/value row, bullet row, next step
|
|
241
|
-
* and summary line. Blank lines follow the standard: exactly one before each section, none after it, never two in a row, none at the
|
|
242
|
-
* end. Lines are Span arrays; `paint(line, color)` prints them. The builder never colors by itself: it names roles.
|
|
243
|
-
*/
|
|
244
|
-
// Shared Report supplies matching primitives; layout uses shared wrapping with the legacy fallback below.
|
|
245
|
-
export class Report {
|
|
246
|
-
private readonly out: Span[][] = [];
|
|
247
|
-
/** `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. */
|
|
248
|
-
constructor(readonly columns: number | undefined = undefined, readonly ascii = false) {}
|
|
249
|
-
/** The text as lines at most `room` cells wide, or as one line per source line when there is no wrap width. */
|
|
250
|
-
private fit(text: string, room: number): string[] {
|
|
251
|
-
return this.columns === undefined ? terminalText(text).split("\n").map(line => line.replace(/\t/g, " ")) : wrap(text, Math.max(10, room), 0);
|
|
252
|
-
}
|
|
253
|
-
private push(line: Span[]) { this.out.push(line); }
|
|
254
|
-
/** ` <tool> <Report>` in `header`, then one line of context in `hint` on the same line. At most one per report. */
|
|
255
|
-
header(tool: string, name: string, context?: string): this {
|
|
256
|
-
this.out.push(...new SharedReport(this.columns, this.ascii).header(tool, name, context).lines());
|
|
257
|
-
return this;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* #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
|
|
261
|
-
* one moves to a wrapped line under a short header. `context` follows the name after two spaces in `hint`; with `inline` it
|
|
262
|
-
* joins the name by one space (`Merge queue owner/repo`) and moves in `value`. A name too wide for any header keeps its first
|
|
263
|
-
* word there and repeats in full on the wrapped line. No wrap width means no moving.
|
|
264
|
-
*/
|
|
265
|
-
titled(tool: string, name: string, context?: string, inline = false): this {
|
|
266
|
-
const fits = (text: string) => this.columns === undefined || cellWidth(` ${tool} ${text}`) <= this.columns;
|
|
267
|
-
const joined = !context ? name : inline ? `${name} ${context}` : `${name} ${context}`;
|
|
268
|
-
if (fits(joined)) return inline && context ? this.header(tool, joined) : this.header(tool, name, context || undefined);
|
|
269
|
-
if (context && fits(name)) return this.header(tool, name).note(context, inline ? "value" : "hint");
|
|
270
|
-
return this.header(tool, name.split(" ")[0]!).note(joined, "value");
|
|
271
|
-
}
|
|
272
|
-
/** One blank line, then `▸ <Name>` (ASCII `> <Name>`) in `section`, with an optional count in `hint`. */
|
|
273
|
-
section(name: string, count?: string): this {
|
|
274
|
-
if (this.out.length && this.out.at(-1)!.length) this.push([]);
|
|
275
|
-
this.out.push(...new SharedReport(this.columns, this.ascii).section(name, count).lines());
|
|
276
|
-
return this;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Key/value rows of one section: two-space indent, `Key:` padded to the widest key, two spaces, value. A key wider than 28 cells
|
|
280
|
-
* puts its value on the next line at a four-space indent. An empty value is `(unset)` in `hint`.
|
|
281
|
-
*/
|
|
282
|
-
kv(rows: readonly (readonly [string, unknown])[], indent = 2, options: { colon?: boolean } = {}): this {
|
|
283
|
-
const suffix = options.colon === false ? "" : ":";
|
|
284
|
-
const keys = rows.map(([key]) => cellWidth(`${terminalText(key)}${suffix}`));
|
|
285
|
-
const pad = Math.max(0, ...keys.filter(width => width <= 28));
|
|
286
|
-
for (const [index, [key, raw]] of rows.entries()) {
|
|
287
|
-
const label = `${terminalText(key)}${suffix}`, text = terminalText(raw ?? "").trim();
|
|
288
|
-
const value = (line: string): Span => text ? { text: line, role: "value" } : { text: "(unset)", role: "hint" };
|
|
289
|
-
const lead = " ".repeat(indent);
|
|
290
|
-
// a terminal too narrow to leave 10 cells beside the label stacks the value under its key, like a key wider than 28
|
|
291
|
-
// stacked when fewer than 10 cells remain beside the label, or when the value's longest word does not fit there
|
|
292
|
-
const longest = Math.max(0, ...text.split(/\s+/).map(word => cellWidth(word)));
|
|
293
|
-
const narrow = keys[index]! <= 28 && this.columns !== undefined && (indent + pad + 2 + 10 > this.columns || longest > this.columns - indent - pad - 2 && longest <= this.columns - indent);
|
|
294
|
-
if (keys[index]! > 28 || narrow) {
|
|
295
|
-
// 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
|
|
296
|
-
const hang = narrow ? 0 : 2;
|
|
297
|
-
this.push([{ text: `${lead}${label}`, role: "key" }]);
|
|
298
|
-
for (const line of text ? this.fit(text, (this.columns ?? 0) - indent - hang) : [""]) this.push([{ text: `${lead}${" ".repeat(hang)}` }, value(line)]);
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
const gap = " ".repeat(pad - keys[index]! + 2), room = (this.columns ?? 0) - indent - pad - 2;
|
|
302
|
-
const lines = text ? this.fit(text, room) : [""];
|
|
303
|
-
this.push([{ text: lead }, { text: label, role: "key" }, { text: gap }, value(lines[0]!)]);
|
|
304
|
-
for (const line of lines.slice(1)) this.push([{ text: " ".repeat(indent + pad + 2) }, value(line)]);
|
|
305
|
-
}
|
|
306
|
-
return this;
|
|
307
|
-
}
|
|
308
|
-
/** ` <marker> <text>`; a nested detail line uses four spaces. The text carries the state word, so meaning survives without color. */
|
|
309
|
-
bullet(name: MarkerName, text: string, nested = false): this {
|
|
310
|
-
const indent = nested ? " " : " ", lead = indent.length + MARKER_COLUMN + 1;
|
|
311
|
-
const lines = this.fit(text, (this.columns ?? 0) - lead);
|
|
312
|
-
this.push([{ text: indent }, { text: markerCell(name, this.ascii), role: MARKERS[name].role }, { text: " " }, { text: lines[0]! }]);
|
|
313
|
-
for (const line of lines.slice(1)) this.push([{ text: " ".repeat(lead) + line }]);
|
|
314
|
-
return this;
|
|
315
|
-
}
|
|
316
|
-
/** Lines another renderer built (a table), placed as they are. A section's blank line is still added by `section()`. */
|
|
317
|
-
append(lines: readonly Span[][]): this { for (const line of lines) this.push([...line]); return this; }
|
|
318
|
-
/** A free line in one role, indented two cells (a pointer to more detail, a note). */
|
|
319
|
-
note(text: string, role: Role = "hint"): this {
|
|
320
|
-
for (const line of this.fit(text, (this.columns ?? 0) - 2)) this.push([{ text: " " }, { text: line, role }]);
|
|
321
|
-
return this;
|
|
322
|
-
}
|
|
323
|
-
/** ` → <command>` in `accent`: complete and copyable, never shortened. */
|
|
324
|
-
next(command: string): this {
|
|
325
|
-
this.out.push(...new SharedReport(this.columns, this.ascii, { sanitize: terminalText, sanitizeFirst: true, wrapNext: false }).next(command).lines());
|
|
326
|
-
return this;
|
|
327
|
-
}
|
|
328
|
-
/** The last line of a check command: `✗ 2 failed ⚠ 3 warnings ✓ 18 ok`, zero counts omitted, unknowns as `? 2 unknown`. */
|
|
329
|
-
summary(counts: { failed?: number; warnings?: number; unknown?: number; ok?: number }): this {
|
|
330
|
-
const lines = new SharedReport(this.columns, this.ascii).summary(counts).lines();
|
|
331
|
-
if (lines.length) { if (this.out.length) this.push([]); this.out.push(...lines); }
|
|
332
|
-
return this;
|
|
333
|
-
}
|
|
334
|
-
lines(): Span[][] { return this.out.map(line => line.map(item => ({ ...item }))); }
|
|
335
|
-
/** The report as text: one painted string per line, no trailing blank line. */
|
|
336
|
-
render(color: boolean): string[] { return this.out.map(line => paint(line, color)); }
|
|
337
|
-
}
|
|
338
217
|
export function stateTone(state: string): Tone | undefined {
|
|
339
218
|
if (state === "idle" || state === "approved") return "success";
|
|
340
219
|
if (["busy", "paused", "in_review", "changes_requested", "ready"].includes(state)) return "attention";
|
|
@@ -369,18 +248,6 @@ export function fitLine(line: Span[], columns: number): Span[] {
|
|
|
369
248
|
export function fit(value: unknown, columns: number): string {
|
|
370
249
|
return paint(fitLine([span(value)], columns), false);
|
|
371
250
|
}
|
|
372
|
-
/**
|
|
373
|
-
* A source line keeps its indent and its continuations hang `hang` columns deeper, both capped at half the width, so
|
|
374
|
-
* below that cap wrapped untrusted text never starts where its source line, or a hub line at that indent, starts. Breaks fall
|
|
375
|
-
* at whitespace, which they drop; only a word longer than a whole line is split. A tab counts as one space.
|
|
376
|
-
* Lines come out sanitized: a width counts the `> ` that sanitize() puts before a line starting like a hub header.
|
|
377
|
-
*/
|
|
378
|
-
export function wrap(value: unknown, columns: number, hang = 4): string[] {
|
|
379
|
-
// A bare chunk ending in "--- from" becomes a header marker when table padding follows it.
|
|
380
|
-
const quoteChunk = (chunk: string) => sanitize(chunk + " ").slice(0, -1);
|
|
381
|
-
// Code-point splitting keeps legacy output for every width, including the non-positive ones.
|
|
382
|
-
return sharedWrap(terminalText(value), columns, hang, quoteChunk, false, "codepoint");
|
|
383
|
-
}
|
|
384
251
|
export const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
385
252
|
/** `45s`, `12m`, `3h05m`, `2d03h`. */
|
|
386
253
|
export function duration(ms: number): string {
|