@staix/agent-hub 0.50.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/README.md +1 -1
- package/docs/adding-an-ai-tool.md +26 -4
- package/docs/agent-notes/README.md +1 -0
- package/docs/agent-notes/adapters.md +4 -3
- package/docs/agent-notes/budget.md +8 -2
- package/docs/agent-notes/daemon.md +13 -8
- package/docs/agent-notes/local-worker.md +3 -3
- package/docs/agent-notes/security-review.md +6 -5
- package/docs/agent-notes/tasks.md +10 -3
- package/docs/agent-notes/tests.md +4 -3
- package/docs/cooperbench.md +1 -1
- package/docs/design/adapters.md +21 -0
- package/docs/design/cli-output-inventory.md +165 -150
- package/docs/design/cli-output.md +4 -3
- package/docs/design/guidance-probes.md +1 -0
- package/docs/design/roadmap.md +3 -1
- package/docs/design/task-board.md +35 -0
- package/docs/dogfood.md +21 -3
- package/docs/events.md +4 -2
- package/docs/memory.md +5 -3
- package/docs/operations.md +259 -19
- package/docs/quickstart.md +29 -2
- package/docs/roadmap.json +20 -20
- package/docs/roadmap.md +2 -2
- package/docs/roles.md +1 -1
- package/docs/sdlc.md +29 -5
- package/docs/security.md +11 -5
- package/docs/specs/2026-09-19-agent-hub-design.md +44 -0
- package/docs/specs/2026-09-19-multi-project-design.md +4 -0
- package/docs/specs/2026-09-20-upgrade-recovery-design.md +17 -0
- package/docs/specs/mcp-endpoint.md +63 -0
- package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
- package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
- package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
- package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
- package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
- package/docs/verification/2026-11-30-0.51.0.md +91 -0
- package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
- package/docs/verification/2026-11-30-capability-listing-shape-1808.md +45 -0
- package/docs/verification/2026-11-30-upgrade-keep-1807.md +174 -0
- package/docs/verification/2026-12-01-1811-confirmation-receipt.md +19 -0
- package/docs/verification/2026-12-01-1811-orca-agent-list.md +20 -0
- package/docs/verification/2026-12-01-1811-orca-pane-key.md +21 -0
- package/docs/verification/2026-12-02-1819-claude-process-after-renewal.md +54 -0
- package/docs/verification/2026-12-02-agy-1.5.21.md +74 -0
- package/docs/verification/2026-12-02-claude-implementer-2.1.334.md +44 -0
- package/docs/verification/2026-12-02-cli-import-graph.md +33 -0
- package/docs/verification/2026-12-03-0.52.0.md +150 -0
- package/docs/verification/2026-12-03-codex-0173-reviewer-isolation.md +53 -0
- package/docs/verification/2026-12-03-codex-0173-reviewer-tool-call.md +34 -0
- package/docs/verification/2026-12-03-jcode-1.3.0.md +25 -0
- package/docs/verification/agy/README.md +17 -0
- package/docs/verification/agy/cli-surface.ts +68 -0
- package/docs/verification/agy/interactive-bridge.ts +92 -0
- package/docs/verification/agy/interactive-session.ts +131 -0
- package/docs/verification/agy/launcher-nonce.ts +215 -0
- package/docs/verification/agy/native-hooks.ts +210 -0
- package/docs/verification/agy/originals/agent-hub-681/cli-surface.ts +87 -0
- package/docs/verification/agy/originals/agent-hub-681/native-hooks-adapted.ts +91 -0
- package/docs/verification/agy/originals/agent-hub-681/tui-actual.ts +200 -0
- package/docs/verification/agy/originals/agent-hub-684/probe.ts +107 -0
- package/docs/verification/agy/originals.json +25 -0
- package/docs/verification/agy/permission-new-functions.ts +128 -0
- package/docs/verification/agy/run-probe.py +108 -0
- package/docs/verification/agy/runtime.ts +171 -0
- package/docs/verification/agy/tmux-helper-control.ts +6 -0
- package/docs/verification/agy/tmux-session.ts +235 -0
- package/docs/verified.json +87 -42
- package/package.json +3 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/compat.json +157 -0
- package/plugins/agent-hub/kimi-hook.js +1416 -24985
- package/plugins/agent-hub/server.js +17415 -32755
- package/scripts/check-docs.mjs +1 -1
- package/src/adapters/acp.ts +13 -13
- package/src/adapters/agy/definition.ts +9 -26
- package/src/adapters/agy/entry.ts +2 -0
- package/src/adapters/channel-peer.ts +3 -1
- package/src/adapters/claude-channel-evidence.ts +7 -3
- package/src/adapters/claude-channel.ts +38 -257
- package/src/adapters/claude-implementer.ts +3 -1
- package/src/adapters/codex-appserver.ts +77 -15
- package/src/adapters/compat.ts +78 -14
- package/src/adapters/configured-acp.ts +23 -163
- package/src/adapters/configured-adapter-policy.ts +160 -0
- package/src/adapters/configured-pull-entry.ts +53 -0
- package/src/adapters/configured-pull.ts +38 -0
- package/src/adapters/conformance/fakes/app-server.ts +9 -2
- package/src/adapters/declaration-catalog.ts +25 -0
- package/src/adapters/declaration-data.ts +342 -0
- package/src/adapters/declaration-resolution.ts +53 -0
- package/src/adapters/definitions/builtin-metadata.ts +62 -84
- package/src/adapters/definitions/jcode-launch.ts +13 -0
- package/src/adapters/definitions/native-adapter-policy.ts +390 -0
- package/src/adapters/definitions/native-cli-claude-launch.ts +6 -3
- package/src/adapters/definitions/native-cli-codex-launch.ts +2 -1
- package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
- package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-jcode.ts +6 -2
- package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-types.ts +12 -3
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
- package/src/adapters/definitions/native-cli-launch-common.ts +2 -2
- package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
- package/src/adapters/definitions/native-cli-retained.ts +1 -1
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/definitions/native-configuration.ts +18 -0
- package/src/adapters/definitions/native-help.ts +24 -0
- package/src/adapters/definitions/native-launch-declarations.ts +34 -0
- package/src/adapters/definitions/native-launch-policy.ts +4 -0
- package/src/adapters/definitions/native-launch-settings.ts +72 -0
- package/src/adapters/definitions/native-light-cli.ts +18 -0
- package/src/adapters/definitions/native-light-preview.ts +10 -0
- package/src/adapters/definitions/native-wrapper-launch.ts +10 -0
- package/src/adapters/definitions/qwen.ts +6 -29
- package/src/adapters/definitions/reviewer-variants.ts +7 -8
- package/src/adapters/external-declarations.ts +31 -0
- package/src/adapters/external-modules.ts +4 -29
- package/src/adapters/jcode.ts +19 -12
- package/src/adapters/native-capabilities.ts +18 -8
- package/src/adapters/native-facts-hooks.ts +12 -0
- package/src/adapters/native-proof-ports.ts +1 -1
- package/src/adapters/presets.ts +136 -0
- package/src/adapters/qwen-dual.ts +2 -2
- package/src/adapters/registry-types.ts +3 -0
- package/src/adapters/registry.ts +20 -81
- package/src/adapters/reviewer-print.ts +26 -9
- package/src/adapters/role-eligibility.ts +2 -1
- package/src/cli/accounts-import.ts +72 -0
- package/src/cli/agents-latest-table.ts +88 -0
- package/src/cli/agents-latest.ts +22 -0
- package/src/cli/agents-output.ts +10 -0
- package/src/cli/agents-presets.ts +100 -0
- package/src/cli/agents.ts +1 -1
- package/src/cli/attention.ts +3 -2
- package/src/cli/autonomy-homes.ts +7 -2
- package/src/cli/autonomy-offline.ts +1 -1
- package/src/cli/bench.ts +1 -1
- package/src/cli/budget-renew-guidance.ts +129 -0
- package/src/cli/claude-homes.ts +9 -5
- package/src/cli/claude-profile-hook.ts +31 -11
- package/src/cli/command-context.ts +3 -0
- package/src/cli/command-table.ts +123 -0
- package/src/cli/commands/accounts.ts +8 -0
- package/src/cli/commands/agents.ts +18 -0
- package/src/cli/commands/answer.ts +28 -0
- package/src/cli/commands/ask.ts +17 -0
- package/src/cli/commands/autonomy.ts +83 -0
- package/src/cli/commands/backlog.ts +46 -0
- package/src/cli/commands/bench.ts +60 -0
- package/src/cli/commands/board.ts +48 -0
- package/src/cli/commands/broker.ts +9 -0
- package/src/cli/commands/budget.ts +96 -0
- package/src/cli/commands/capabilities.ts +12 -0
- package/src/cli/commands/check-path.ts +55 -0
- package/src/cli/commands/completion.ts +8 -0
- package/src/cli/commands/console.ts +12 -0
- package/src/cli/commands/daemon.ts +8 -0
- package/src/cli/commands/deliverables.ts +25 -0
- package/src/cli/commands/doctor.ts +249 -0
- package/src/cli/commands/down.ts +3 -0
- package/src/cli/commands/export.ts +15 -0
- package/src/cli/commands/facts.ts +15 -0
- package/src/cli/commands/goal.ts +22 -0
- package/src/cli/commands/guidance.ts +102 -0
- package/src/cli/commands/help.ts +17 -0
- package/src/cli/commands/host.ts +45 -0
- package/src/cli/commands/init.ts +121 -0
- package/src/cli/commands/instructed.ts +19 -0
- package/src/cli/commands/instruction-hook.ts +15 -0
- package/src/cli/commands/intake.ts +24 -0
- package/src/cli/commands/kill.ts +15 -0
- package/src/cli/commands/learn.ts +23 -0
- package/src/cli/commands/lineage.ts +30 -0
- package/src/cli/commands/logs.ts +21 -0
- package/src/cli/commands/manager.ts +15 -0
- package/src/cli/commands/memory.ts +21 -0
- package/src/cli/commands/model.ts +25 -0
- package/src/cli/commands/models.ts +40 -0
- package/src/cli/commands/native.ts +39 -0
- package/src/cli/commands/pause.ts +5 -0
- package/src/cli/commands/peer.ts +32 -0
- package/src/cli/commands/permission.ts +26 -0
- package/src/cli/commands/permit.ts +12 -0
- package/src/cli/commands/pet.ts +24 -0
- package/src/cli/commands/projects.ts +49 -0
- package/src/cli/commands/queue.ts +70 -0
- package/src/cli/commands/recovery-run.ts +13 -0
- package/src/cli/commands/recovery.ts +130 -0
- package/src/cli/commands/release.ts +23 -0
- package/src/cli/commands/releases.ts +91 -0
- package/src/cli/commands/remember.ts +6 -0
- package/src/cli/commands/report.ts +27 -0
- package/src/cli/commands/research.ts +53 -0
- package/src/cli/commands/reset.ts +89 -0
- package/src/cli/commands/restart.ts +5 -0
- package/src/cli/commands/results.ts +31 -0
- package/src/cli/commands/resume.ts +5 -0
- package/src/cli/commands/review.ts +24 -0
- package/src/cli/commands/roadmap.ts +21 -0
- package/src/cli/commands/role.ts +34 -0
- package/src/cli/commands/roles.ts +30 -0
- package/src/cli/commands/room.ts +14 -0
- package/src/cli/commands/roster.ts +48 -0
- package/src/cli/commands/route.ts +9 -0
- package/src/cli/commands/say.ts +21 -0
- package/src/cli/commands/schedule.ts +17 -0
- package/src/cli/commands/sdlc.ts +321 -0
- package/src/cli/commands/settings.ts +148 -0
- package/src/cli/commands/setup.ts +89 -0
- package/src/cli/commands/shared-refusals.ts +25 -0
- package/src/cli/commands/smoke.ts +44 -0
- package/src/cli/commands/source.ts +64 -0
- package/src/cli/commands/specs.ts +13 -0
- package/src/cli/commands/status.ts +28 -0
- package/src/cli/commands/stop.ts +17 -0
- package/src/cli/commands/structure.ts +60 -0
- package/src/cli/commands/study.ts +39 -0
- package/src/cli/commands/tail.ts +19 -0
- package/src/cli/commands/task.ts +114 -0
- package/src/cli/commands/title.ts +17 -0
- package/src/cli/commands/turns.ts +10 -0
- package/src/cli/commands/ui.ts +47 -0
- package/src/cli/commands/undo.ts +77 -0
- package/src/cli/commands/up.ts +39 -0
- package/src/cli/commands/upgrade.ts +5 -0
- package/src/cli/commands/usage.ts +33 -0
- package/src/cli/commands/version.ts +5 -0
- package/src/cli/commands/watch.ts +30 -0
- package/src/cli/commands/worktrees.ts +31 -0
- package/src/cli/conductor-recovery.ts +1 -1
- package/src/cli/console-state.ts +5 -138
- package/src/cli/console-versions.ts +1 -1
- package/src/cli/facts-hook.ts +11 -4
- package/src/cli/help.ts +44 -20
- package/src/cli/identity.ts +27 -4
- package/src/cli/init-prompt.ts +1 -1
- package/src/cli/init-settings.ts +4 -35
- package/src/cli/init.ts +1 -1
- package/src/cli/json-text-spans.ts +57 -0
- package/src/cli/launch-check.ts +156 -0
- package/src/cli/launch.ts +19 -70
- package/src/cli/light-dispatch.ts +29 -0
- package/src/cli/main.js +8 -1
- package/src/cli/main.ts +257 -2799
- package/src/cli/memory.ts +1 -1
- package/src/cli/orca-probe.ts +119 -0
- package/src/cli/output.ts +45 -3
- package/src/cli/preview.ts +11 -6
- package/src/cli/recovery-launch.ts +1 -1
- package/src/cli/recovery-version-preflight.ts +28 -9
- package/src/cli/replace-process.ts +22 -0
- package/src/cli/report-layout.ts +142 -0
- package/src/cli/roadmap-usage.ts +16 -0
- package/src/cli/roadmap.ts +3 -16
- package/src/cli/sdlc-doctor.ts +27 -0
- package/src/cli/sdlc-output.ts +55 -1
- package/src/cli/setup-homes.ts +2 -2
- package/src/cli/start-agents-run.ts +85 -7
- package/src/cli/start-check.ts +28 -0
- package/src/cli/statusline-tee.ts +25 -4
- package/src/cli/terminal-recovery.ts +53 -10
- package/src/cli/upgrade-interactive.ts +1 -0
- package/src/cli/upgrade-runtime.ts +12 -1
- package/src/cli/upgrade.ts +4 -15
- package/src/cli/warn-line.ts +1 -1
- package/src/hub/accounts.ts +148 -0
- package/src/hub/addons.ts +20 -0
- package/src/hub/agent-drift.ts +2 -1
- package/src/hub/budget-projection.ts +39 -7
- package/src/hub/budget.ts +231 -16
- package/src/hub/channel-project.ts +3 -3
- package/src/hub/ci-watch.ts +311 -79
- package/src/hub/conductor-peer.ts +24 -0
- package/src/hub/conductor.ts +2 -21
- package/src/hub/config-apply.ts +25 -14
- package/src/hub/config-edit.ts +1 -1
- package/src/hub/config-tier.ts +2 -0
- package/src/hub/config.ts +535 -0
- package/src/hub/control-client.ts +49 -1
- package/src/hub/daemon.ts +492 -569
- package/src/hub/delivery-public.ts +11 -0
- package/src/hub/events.ts +3 -0
- package/src/hub/home-tag.ts +12 -0
- package/src/hub/host.ts +217 -0
- package/src/hub/hub-check.ts +125 -0
- package/src/hub/hub-tools.ts +2 -1
- package/src/hub/instance-budget.ts +2 -2
- package/src/hub/instance-config.ts +15 -126
- package/src/hub/instances.ts +22 -6
- package/src/hub/instruction-receipt.ts +2 -2
- package/src/hub/kimi-usage.ts +38 -11
- package/src/hub/lifecycle.ts +86 -4
- package/src/hub/mcp-bridge-core.ts +98 -0
- package/src/hub/mcp-channel-push.ts +20 -0
- package/src/hub/mcp-endpoint-serve.ts +178 -0
- package/src/hub/mcp-endpoint.ts +226 -0
- package/src/hub/mcp-tool-call.ts +181 -0
- package/src/hub/operational-settings.ts +2 -0
- package/src/hub/orca-env.ts +6 -0
- package/src/hub/orca-state.ts +84 -0
- package/src/hub/path-policy.ts +1 -1
- package/src/hub/peers.ts +5 -1
- package/src/hub/permission-mode.ts +5 -41
- package/src/hub/permission-paths.ts +41 -0
- package/src/hub/project.ts +20 -0
- package/src/hub/protocol-window.ts +58 -0
- package/src/hub/quota-origin.ts +20 -0
- package/src/hub/recovery-policy.ts +1 -1
- package/src/hub/registry.ts +36 -2
- package/src/hub/releases-inventory.ts +198 -0
- package/src/hub/report.ts +1 -1
- package/src/hub/research.ts +1 -1
- package/src/hub/review-brief.ts +47 -2
- package/src/hub/roster.ts +6 -3
- package/src/hub/routing.ts +9 -2
- package/src/hub/runtime-capture-prune.ts +25 -3
- package/src/hub/runtime-prune-health.ts +8 -1
- package/src/hub/sdlc-check.ts +205 -0
- package/src/hub/sdlc-release-authorization.ts +42 -21
- package/src/hub/sdlc-release-diagnostics.ts +5 -0
- package/src/hub/sdlc-release-policy.ts +21 -7
- package/src/hub/sdlc-release.ts +80 -20
- package/src/hub/sdlc-sync.ts +146 -0
- package/src/hub/sdlc.ts +38 -5
- package/src/hub/settings.ts +7 -4
- package/src/hub/start-agents.ts +1 -1
- package/src/hub/start-mode.ts +11 -4
- package/src/hub/structure-budget.ts +131 -0
- package/src/hub/structure-scan.ts +149 -0
- package/src/hub/tasks-experiment.ts +455 -0
- package/src/hub/tasks-guidance.ts +606 -0
- package/src/hub/tasks-roadmap-plan.ts +419 -0
- package/src/hub/tasks-roadmap.ts +491 -0
- package/src/hub/tasks-study.ts +661 -0
- package/src/hub/tasks-survey.ts +192 -0
- package/src/hub/tasks.ts +457 -2584
- package/src/hub/terminal-open.ts +5 -3
- package/src/hub/tooling.ts +3 -19
- package/src/hub/usage-rollup.ts +9 -3
- package/src/local/tools.ts +5 -0
- package/src/ui/index.html +1 -1
- package/src/ui/needs.ts +17 -5
- package/src/ui/peer-palette.ts +2 -4
- package/src/ui/plugin.ts +1 -1
- package/templates/presets/agents.json +60 -0
- package/templates/presets/confirmation-matrix.json +8 -8
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { terminalText } from "../console-state.ts";
|
|
2
|
+
import { parseSettingsEditArgs, runSettingsEdit, SETTINGS_EDIT_USAGE } from "../settings-edit.ts";
|
|
3
|
+
import { renderSdlcSetting, renderSettingsConfirmation, renderSettingsPreview, renderSettingsReceipt, renderSettingsRejected, renderSettingsRows } from "../settings-output.ts";
|
|
4
|
+
import { parseSettingText, settingDef, undoableDef, type SettingRow } from "../../hub/settings.ts";
|
|
5
|
+
import { createInterface } from "node:readline/promises";
|
|
6
|
+
import { refuseNeverAskWithoutYes } from "../commands/shared-refusals.ts";
|
|
7
|
+
import { asciiMarkers, permissionBoundary, type Span } from "../console-state.ts";
|
|
8
|
+
import type { CommandContext } from "../command-context.ts";
|
|
9
|
+
|
|
10
|
+
export async function run(context: CommandContext) {
|
|
11
|
+
const { args, caller, connect, liveTest, localDeclarations, outputOptions, printOutput, warn } = context;
|
|
12
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
13
|
+
const display = outputOptions([]);
|
|
14
|
+
const ascii = asciiMarkers(process.env, process.argv.includes("--ascii"));
|
|
15
|
+
const show = <T>(render: (data: T, columns?: number, now?: number, ascii?: boolean) => Span[][], data: T) =>
|
|
16
|
+
printOutput(render(data, display.columns, Date.now(), ascii), display.color);
|
|
17
|
+
const receipt = (title: string, ...lines: string[]) => show(renderSettingsReceipt, { title, lines });
|
|
18
|
+
// #689: structural config edits (instances, review, snapshots, approvals, context.gate, sdlc.toml) and their backups. The hub validates and writes.
|
|
19
|
+
if (args[0] === "edit" || args[0] === "backups") {
|
|
20
|
+
// A command line the parser refuses never reaches the hub, not even as a connection.
|
|
21
|
+
const early = args[0] === "backups" ? (args.length > 2 || (args[1] !== undefined && args[1] !== "--json") ? SETTINGS_EDIT_USAGE : undefined) : (() => { const parsed = parseSettingsEditArgs(args.slice(1)); return typeof parsed === "string" ? parsed : undefined; })();
|
|
22
|
+
if (early) fail(early);
|
|
23
|
+
const hub = await connect();
|
|
24
|
+
try {
|
|
25
|
+
const rl = process.stdin.isTTY ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
26
|
+
const lines: string[] = [];
|
|
27
|
+
const jsonBackups = args[0] === "backups" && args[1] === "--json";
|
|
28
|
+
const flush = () => {
|
|
29
|
+
if (lines.length) show(renderSettingsReceipt, { title: args[0] === "backups" ? "Settings backups" : "Settings edit", lines: lines.splice(0) });
|
|
30
|
+
};
|
|
31
|
+
const usage = await runSettingsEdit(args, {
|
|
32
|
+
request: async message => {
|
|
33
|
+
flush();
|
|
34
|
+
const reply = await hub.request(message, 35_000);
|
|
35
|
+
if (reply.ok !== true) {
|
|
36
|
+
const error = String(reply.error ?? "config edit refused");
|
|
37
|
+
fail(/unknown (?:control )?(?:message|request|command)(?:\b|:)|this hub does not know "config_edit/i.test(error) ? `${error}; upgrade and restart the running hub to use ahub settings edit` : error);
|
|
38
|
+
}
|
|
39
|
+
return reply;
|
|
40
|
+
},
|
|
41
|
+
ask: async prompt => { flush(); if (!rl) return null; try { return await rl.question(prompt); } catch { return null; } },
|
|
42
|
+
print: line => {
|
|
43
|
+
if (jsonBackups) process.stdout.write(terminalText(line) + "\n");
|
|
44
|
+
else lines.push(terminalText(line));
|
|
45
|
+
},
|
|
46
|
+
}).finally(() => { flush(); rl?.close(); });
|
|
47
|
+
if (usage) fail(usage);
|
|
48
|
+
} finally { hub.close(); }
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const usage = "usage: ahub settings [list] [--json] | get <key> [--json] | set <key> <value|inherit> [--yes] [--preview] | undo | reload | edit <file> ... | backups";
|
|
52
|
+
const flags = args.filter((arg) => arg.startsWith("--")), [sub = "list", key, text, ...extra] = args.filter((arg) => !arg.startsWith("--"));
|
|
53
|
+
const allowed: Record<string, string[]> = { list: ["--json"], get: ["--json"], set: ["--yes", "--preview", "--now"], undo: [], reload: [] };
|
|
54
|
+
if (!Object.hasOwn(allowed, sub) || flags.some((flag) => !allowed[sub]!.includes(flag)) || extra.length) fail(usage);
|
|
55
|
+
if ((sub === "get" && (!key || text !== undefined)) || (sub === "set" && (!key || text === undefined)) || ((sub === "list" || sub === "undo" || sub === "reload") && key !== undefined)) fail(usage);
|
|
56
|
+
const { scope: settingScope, error: settingScopeError } = localDeclarations();
|
|
57
|
+
const sdlcRead = sub === "get" && ["sdlc.mode", "sdlc.required_checks"].includes(key ?? "");
|
|
58
|
+
const def = key === undefined || sdlcRead ? undefined : settingDef(key, settingScope.instances, settingScope.catalog);
|
|
59
|
+
if (typeof def === "string") fail(settingScopeError && def.startsWith("unknown setting") ? `${key}: ${def}; the project config could not be read: ${settingScopeError}` : `${key}: ${def}`);
|
|
60
|
+
if (flags.includes("--now") && (typeof def !== "object" || def.group !== "Roster")) fail(usage);
|
|
61
|
+
if (sub === "set" && key === "instructed.mode" && (caller.role !== "console" || liveTest || !process.stdin.isTTY)) fail("instructed.mode is changed only by the person in a terminal");
|
|
62
|
+
const value = sub === "set" ? parseSettingText(def!, text!) : undefined;
|
|
63
|
+
const peer = def?.group === "Permissions" || def?.group === "Roster" ? def.path.at(-1)! : undefined;
|
|
64
|
+
if (sub === "set" && value === "never-ask" && !flags.includes("--preview")) {
|
|
65
|
+
if (!flags.includes("--yes")) refuseNeverAskWithoutYes(fail);
|
|
66
|
+
warn(`never-ask: ${permissionBoundary(peer!, settingScope.instances, settingScope.catalog)}: approval prompts are disabled`);
|
|
67
|
+
}
|
|
68
|
+
const hub = await connect();
|
|
69
|
+
try {
|
|
70
|
+
const request = async (message: Record<string, unknown>) => {
|
|
71
|
+
const reply = await hub.request(message, 35_000);
|
|
72
|
+
if (reply.ok !== true) {
|
|
73
|
+
const error = String(reply.error ?? "settings request refused");
|
|
74
|
+
fail(/unknown (?:control )?(?:message|request|command)(?:\b|:)|this hub does not know "settings_/i.test(error) ? `${error}; upgrade the running hub to use ahub settings` : error,reply.refusalAudited===true,reply.authorityRefused);
|
|
75
|
+
}
|
|
76
|
+
return reply;
|
|
77
|
+
};
|
|
78
|
+
if (sdlcRead) {
|
|
79
|
+
const view = await request({ t: "settings_get" }), entry = view.sdlc?.[key!];
|
|
80
|
+
if (!entry || !Object.hasOwn(entry, "value") || !Object.hasOwn(entry, "fileValue")) fail("running hub lacks SDLC settings reads; upgrade and restart it first");
|
|
81
|
+
if (flags.includes("--json")) return console.log(JSON.stringify({ key, ...entry }, null, 2));
|
|
82
|
+
return show(renderSdlcSetting, { key: key!, value: entry.value, fileValue: entry.fileValue, problem: entry.problem });
|
|
83
|
+
}
|
|
84
|
+
if (sub === "reload") {
|
|
85
|
+
let result = await request({ t: "settings_reload" });
|
|
86
|
+
const confirmation = result.confirmation;
|
|
87
|
+
if (Array.isArray(result.rejected) && result.rejected.length) show(renderSettingsRejected, result.rejected);
|
|
88
|
+
if (confirmation !== undefined) {
|
|
89
|
+
if (!confirmation || typeof confirmation.token !== "string" || !confirmation.token || confirmation.token.length > 256 || !Array.isArray(confirmation.keys) || !confirmation.keys.length || confirmation.keys.length > 200 || confirmation.keys.some((key: unknown) => typeof key !== "string" || key.length > 160)) fail("invalid reload confirmation; guarded settings were not applied");
|
|
90
|
+
const fullValue = (value: unknown): boolean => {
|
|
91
|
+
if (typeof value !== "string" || Buffer.byteLength(value, "utf8") > 16_384) return false;
|
|
92
|
+
if (value === "(unset)") return true;
|
|
93
|
+
try { JSON.parse(value); return true; } catch { return false; }
|
|
94
|
+
};
|
|
95
|
+
if (Buffer.byteLength(JSON.stringify(result), "utf8") > 131_072 || new Set(confirmation.keys).size !== confirmation.keys.length || !Array.isArray(confirmation.changes) || confirmation.changes.length !== confirmation.keys.length || confirmation.changes.some((change: unknown, index: number) => {
|
|
96
|
+
if (!change || typeof change !== "object" || Array.isArray(change)) return true;
|
|
97
|
+
const row = change as Record<string, unknown>;
|
|
98
|
+
return row.key !== confirmation.keys[index] || !fullValue(row.before) || !fullValue(row.after) || (row.effect !== undefined && (typeof row.effect !== "string" || Buffer.byteLength(row.effect, "utf8") > 2048));
|
|
99
|
+
})) fail("reload preview is incomplete or unavailable; upgrade the running hub and run ahub settings reload again to review every full value; guarded settings were not applied");
|
|
100
|
+
const token = confirmation.token;
|
|
101
|
+
show(renderSettingsConfirmation, confirmation.changes);
|
|
102
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) fail("guarded settings need an interactive person's terminal; run ahub settings reload there; guarded settings were not applied");
|
|
103
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: false });
|
|
104
|
+
const ended = new AbortController();
|
|
105
|
+
rl.once("close", () => ended.abort());
|
|
106
|
+
let accepted = false;
|
|
107
|
+
try { accepted = (await rl.question("Apply guarded settings? [y/N] ", { signal: AbortSignal.any([AbortSignal.timeout(30_000), ended.signal]) })).trim().toLowerCase() === "y"; }
|
|
108
|
+
catch { /* EOF, cancellation and a missed confirmation deadline grant nothing. */ }
|
|
109
|
+
finally { rl.close(); }
|
|
110
|
+
if (!accepted) return receipt("Settings reload", "guarded settings were not applied");
|
|
111
|
+
result = await request({ t: "settings_reload", confirm: token });
|
|
112
|
+
if (result.confirmation !== undefined) fail("reload candidate changed; run ahub settings reload again to review it; guarded settings were not applied");
|
|
113
|
+
if (Array.isArray(result.rejected) && result.rejected.length) show(renderSettingsRejected, result.rejected);
|
|
114
|
+
}
|
|
115
|
+
return receipt("Settings reload", result.text ?? "configuration reloaded");
|
|
116
|
+
}
|
|
117
|
+
if (sub === "undo") {
|
|
118
|
+
const view = await request({ t: "settings_get" }), undoDef = undoableDef(view.undo, settingScope.instances, settingScope.catalog);
|
|
119
|
+
// A roster undo of a declared peer needs its confirmation prompt; without readable declarations, refuse rather than skip it.
|
|
120
|
+
if (typeof undoDef === "string" && settingScopeError) fail(`pending undo ${String(view.undo)}: ${undoDef}; the project config could not be read: ${settingScopeError}`);
|
|
121
|
+
const rosterPeer = typeof undoDef !== "string" && undoDef.group === "Roster" ? undoDef.path[1] : undefined;
|
|
122
|
+
let confirm: string | undefined;
|
|
123
|
+
if (typeof undoDef !== "string" && undoDef.managed === "autonomy") {
|
|
124
|
+
if (!process.stdin.isTTY) fail("undoing project autonomy requires a person's terminal confirmation");
|
|
125
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
126
|
+
try { confirm = (await rl.question("Type autonomy to undo the complete preset change: ")).trim(); } finally { rl.close(); }
|
|
127
|
+
}
|
|
128
|
+
if (rosterPeer) {
|
|
129
|
+
if (!process.stdin.isTTY) fail("undoing a roster setting needs confirmation in a terminal; use ahub settings set for an explicit scripted change");
|
|
130
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
131
|
+
try { confirm = (await rl.question(`Type ${rosterPeer} to confirm this roster undo: `)).trim(); } finally { rl.close(); }
|
|
132
|
+
}
|
|
133
|
+
return receipt("Settings undo", (await request({ t: "settings_undo", ...(confirm ? { confirm } : {}) })).text ?? "setting restored");
|
|
134
|
+
}
|
|
135
|
+
if (sub === "set" && flags.includes("--preview")) {
|
|
136
|
+
const preview = await request({ t: "settings_preview", key, value });
|
|
137
|
+
return show(renderSettingsPreview, preview);
|
|
138
|
+
}
|
|
139
|
+
if (sub === "set") {
|
|
140
|
+
const reply = await request({ t: "settings_set", key, value, now: flags.includes("--now"), ...(flags.includes("--yes") && peer ? { confirm: peer } : {}) });
|
|
141
|
+
return receipt("Settings set", reply.text ?? "setting saved", ...(typeof reply.note === "string" && reply.note ? [reply.note] : []));
|
|
142
|
+
}
|
|
143
|
+
const view = await request({ t: "settings_get" });
|
|
144
|
+
const rows = (view.rows as SettingRow[]).filter((row) => sub === "list" || row.key === key);
|
|
145
|
+
if (flags.includes("--json")) return console.log(JSON.stringify(sub === "get" ? rows[0] : { rows, pendingRestart: view.pendingRestart ?? [], ...(view.undo ? { undo: view.undo } : {}) }, null, 2));
|
|
146
|
+
show(renderSettingsRows, { rows, detail: sub === "get", ...(sub === "list" ? { pendingRestart: view.pendingRestart, undo: view.undo } : {}) });
|
|
147
|
+
} finally { hub.close(); }
|
|
148
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { terminalText } from "../console-state.ts";
|
|
2
|
+
import { usedClaudeHomes } from "../autonomy-homes.ts";
|
|
3
|
+
import { discoverClaudeHomes } from "../claude-homes.ts";
|
|
4
|
+
import { setupClaudeHomes } from "../setup-homes.ts";
|
|
5
|
+
import { setupResearchDefault } from "../setup-research.ts";
|
|
6
|
+
import { registerAconPlugin } from "../acon-register.ts";
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { loadConfig } from "../../hub/config.ts";
|
|
11
|
+
import { hubHome } from "../../hub/project.ts";
|
|
12
|
+
import { Registry } from "../../hub/registry.ts";
|
|
13
|
+
import { installHubSkills } from "../skills-install.ts";
|
|
14
|
+
import { installHubSkillsInJcodeHomes, jcodeSkillHomes } from "../../adapters/definitions/native-cli-jcode-home-init.ts";
|
|
15
|
+
import { createInterface } from "node:readline/promises";
|
|
16
|
+
import { assertLifecycleAvailable } from "../../hub/recovery-store.ts";
|
|
17
|
+
import { setupStartAgents } from "../start-agents-run.ts";
|
|
18
|
+
import type { CommandContext } from "../command-context.ts";
|
|
19
|
+
|
|
20
|
+
export async function run(context: CommandContext) {
|
|
21
|
+
const { args, cliDir, cwd, delegatedPeer, dispatchCommand, liveTest, recoveryLauncherCurrent, setDoctorExit, startupDiagnostic, takeFlags } = context;
|
|
22
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
23
|
+
// Keep these local names for the source fixture that pins the setup-to-doctor handoff.
|
|
24
|
+
let doctorSetsExit: boolean = true;
|
|
25
|
+
const commands = { doctor: () => { setDoctorExit(doctorSetsExit); return dispatchCommand("doctor"); } };
|
|
26
|
+
recoveryLauncherCurrent?.();
|
|
27
|
+
assertLifecycleAvailable(cwd);
|
|
28
|
+
const root = join(cliDir, "..", "..");
|
|
29
|
+
if (args.includes("--research") && args.includes("--no-research")) fail("--research conflicts with --no-research; give one; nothing was written");
|
|
30
|
+
const research = args.includes("--research") ? true : args.includes("--no-research") ? false : undefined;
|
|
31
|
+
const setupFlags = takeFlags(args.filter(arg => !["--yes", "--research", "--no-research", "--undo"].includes(arg)), ["--agents"], []);
|
|
32
|
+
if (setupFlags.rest.length) fail("usage: ahub setup [--yes] [--agents <a,b>] [--research|--no-research] [--undo]");
|
|
33
|
+
if (args.includes("--undo")) {
|
|
34
|
+
if (research !== undefined || setupFlags.one["--agents"] !== undefined) fail("--undo removes the hub's own skill trees only; drop --research and --agents; nothing was written");
|
|
35
|
+
// #1622: remove only the trees the hub wrote and nobody edited; a modified, foreign or linked tree is reported and kept.
|
|
36
|
+
const undoReader = process.stdin.isTTY ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
37
|
+
try {
|
|
38
|
+
await installHubSkills({ undo: true, yes: args.includes("--yes"),
|
|
39
|
+
ask: async prompt => { try { return undoReader ? await undoReader.question(prompt) : null; } catch { return null; } },
|
|
40
|
+
print: line => console.log(terminalText(line)) });
|
|
41
|
+
// #1627 AC1b: the hub-owned jcode homes (the configured one and each instance's), under the same marker contract.
|
|
42
|
+
await installHubSkillsInJcodeHomes({ undo: true, homes: jcodeSkillHomes(loadConfig(cwd), process.env), yes: args.includes("--yes"),
|
|
43
|
+
ask: async prompt => { try { return undoReader ? await undoReader.question(prompt) : null; } catch { return null; } },
|
|
44
|
+
print: line => console.log(terminalText(line)) });
|
|
45
|
+
} finally { undoReader?.close(); }
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (research !== undefined && (liveTest || delegatedPeer || recoveryLauncherCurrent)) fail("the machine research default requires the person's own ahub setup; nothing was written");
|
|
49
|
+
const registry = new Registry(), rl = process.stdin.isTTY ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
50
|
+
let machineRoots = [cwd];
|
|
51
|
+
let homesFailed = false, homesFailure: unknown;
|
|
52
|
+
try {
|
|
53
|
+
const found = recoveryLauncherCurrent || delegatedPeer ? await discoverClaudeHomes({ home: homedir(), env: process.env }) : await usedClaudeHomes(registry, homedir(), process.env);
|
|
54
|
+
for (const notice of found.notices) console.log(terminalText(notice));
|
|
55
|
+
try {
|
|
56
|
+
await setupClaudeHomes({ homes: found.homes, env: process.env, packageRoot: root, yes: args.includes("--yes"), hook: { instruction: true },
|
|
57
|
+
interactive: !!rl,
|
|
58
|
+
current: () => { recoveryLauncherCurrent?.(); assertLifecycleAvailable(cwd); },
|
|
59
|
+
print: line => console.log(terminalText(line)), ask: async prompt => rl ? rl.question(prompt) : null,
|
|
60
|
+
probe: (argv, options) => { recoveryLauncherCurrent?.(); const result = spawnSync(argv[0]!, argv.slice(1), { encoding: "utf8", env: options.env, timeout: options.timeoutMs, maxBuffer: 1024 * 1024 }); recoveryLauncherCurrent?.(); return { status: result.status ?? -1, stdout: result.stdout ?? "" }; },
|
|
61
|
+
run: async (argv, env) => { recoveryLauncherCurrent?.(); const result = spawnSync(argv[0]!, argv.slice(1), { stdio: "inherit", env, timeout: 30_000 }); recoveryLauncherCurrent?.(); return result.status ?? -1; },
|
|
62
|
+
});
|
|
63
|
+
} catch (error) { homesFailed = true; homesFailure = error; }
|
|
64
|
+
// #608: the one question about the default agent set, after the Claude homes and before doctor.
|
|
65
|
+
if (!recoveryLauncherCurrent && !delegatedPeer) {
|
|
66
|
+
assertLifecycleAvailable(cwd);
|
|
67
|
+
const refused = await setupStartAgents({ home: hubHome(), roots: [...registry.list().map(row => row.root), cwd], ...(setupFlags.one["--agents"] !== undefined ? { flag: setupFlags.one["--agents"] } : {}), yes: args.includes("--yes"),
|
|
68
|
+
...(rl ? { ask: async (prompt: string) => { try { return await rl.question(prompt); } catch { return null; } } } : {}), print: line => console.log(terminalText(line)) });
|
|
69
|
+
if (refused) fail(refused);
|
|
70
|
+
}
|
|
71
|
+
// #1622: the hub's own skills for every other installed agent host, under the marker contract.
|
|
72
|
+
assertLifecycleAvailable(cwd);
|
|
73
|
+
await installHubSkills({ source: join(root, "plugins", "agent-hub", "skills"), yes: args.includes("--yes"),
|
|
74
|
+
ask: async prompt => { try { return rl ? await rl.question(prompt) : null; } catch { return null; } },
|
|
75
|
+
print: line => console.log(terminalText(line)) });
|
|
76
|
+
await installHubSkillsInJcodeHomes({ source: join(root, "plugins", "agent-hub", "skills"), homes: jcodeSkillHomes(loadConfig(cwd), process.env), yes: args.includes("--yes"),
|
|
77
|
+
ask: async prompt => { try { return rl ? await rl.question(prompt) : null; } catch { return null; } },
|
|
78
|
+
print: line => console.log(terminalText(line)) });
|
|
79
|
+
if (research !== undefined) machineRoots = [...registry.list().map(row => row.root), cwd];
|
|
80
|
+
} finally { registry.close(); rl?.close(); }
|
|
81
|
+
if (homesFailed) fail(startupDiagnostic(homesFailure));
|
|
82
|
+
try { if (research !== undefined) assertLifecycleAvailable(cwd); const line = setupResearchDefault(hubHome(), machineRoots, research); if (line) console.log(terminalText(line)); }
|
|
83
|
+
catch (error) { return fail((error as Error).message); }
|
|
84
|
+
// #935: register the acon console plugin (acon reads it at its next start; no acon install is needed for this).
|
|
85
|
+
const acon = registerAconPlugin(hubHome(), join(root, "src", "ui", "plugin.ts"));
|
|
86
|
+
console.log("error" in acon ? `acon plugin not registered: ${acon.error}` : acon.changed ? `acon plugin registered: ${acon.path}` : `acon plugin up to date: ${acon.path}`);
|
|
87
|
+
if (recoveryLauncherCurrent) recoveryLauncherCurrent();
|
|
88
|
+
else { doctorSetsExit = false; await commands.doctor!(); }
|
|
89
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type Refuse = (message: string) => never;
|
|
2
|
+
|
|
3
|
+
export function refuseNeverAskWithoutYes(fail: Refuse): never {
|
|
4
|
+
return fail("never-ask requires --yes; nothing was changed");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function refuseSynthesisTaskMismatch(fail: Refuse): never {
|
|
8
|
+
return fail("synthesis manifest names another task; refresh its task binding and retry");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function refuseRepeatedProjectSelector(fail: Refuse): never {
|
|
12
|
+
return fail("--project may appear only once");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function refuseMissingProjectSelector(fail: Refuse): never {
|
|
16
|
+
return fail("--project needs a path or project ID");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function refuseUnsupportedExportFormat(fail: Refuse): never {
|
|
20
|
+
return fail("--format takes jsonl or csv");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function refuseMissingFlagValue(fail: Refuse, flag: string | undefined): never {
|
|
24
|
+
return fail(`${flag} needs a value`);
|
|
25
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { registeredProjects } from "../upgrade.ts";
|
|
3
|
+
import { recordCliAudit } from "../identity-audit.ts";
|
|
4
|
+
import type { CommandContext } from "../command-context.ts";
|
|
5
|
+
|
|
6
|
+
export async function run(context: CommandContext) {
|
|
7
|
+
const { args, assertDelegatedAuditConsumer, caller, commandLabel, cwd, invokedFrom, liveTest, outputOptions, selector, stateDir } = context;
|
|
8
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
9
|
+
// Log every live-test invocation, including syntax/target refusals; native output never joins the audit.
|
|
10
|
+
if (liveTest && caller.role === "console") {
|
|
11
|
+
try { recordCliAudit(stateDir, "user", commandLabel, "run"); }
|
|
12
|
+
catch { return fail("smoke audit unavailable; nothing was executed"); }
|
|
13
|
+
}
|
|
14
|
+
const options = outputOptions();
|
|
15
|
+
const operands = args.filter(arg => arg !== "--json");
|
|
16
|
+
const usage = "usage: ahub --live-test smoke run qwen-dual-output --project-id <id> --receipt <file.json> [--timeout-ms <100..120000>] [--json]";
|
|
17
|
+
const values = new Map<string, string>();
|
|
18
|
+
if (operands[0] !== "run" || operands[1] !== "qwen-dual-output") return fail(usage);
|
|
19
|
+
for (let n = 2; n < operands.length; n += 2) {
|
|
20
|
+
const key = operands[n], value = operands[n + 1];
|
|
21
|
+
if (!key || !["--project-id", "--receipt", "--timeout-ms"].includes(key) || !value || value.startsWith("--") || values.has(key)) return fail(usage);
|
|
22
|
+
values.set(key, value);
|
|
23
|
+
}
|
|
24
|
+
if (!values.has("--project-id") || !values.has("--receipt")) return fail(usage);
|
|
25
|
+
const home = process.env.AGENTHUB_HOME;
|
|
26
|
+
if (!liveTest || !home) return fail("smoke target refused");
|
|
27
|
+
const { validateSmokeTarget } = await import("../smoke-target.ts");
|
|
28
|
+
const { runSmoke } = await import("../smoke-run.ts");
|
|
29
|
+
const project = registeredProjects(home).find(project => project.root === cwd && project.stateDir === stateDir);
|
|
30
|
+
if (!project) return fail("smoke target refused");
|
|
31
|
+
// Keep path spelling for the guard: project selection above canonicalizes symlinks for ordinary CLI commands.
|
|
32
|
+
const smokeCwd = selector && selector !== project.id ? resolve(invokedFrom, selector) : cwd;
|
|
33
|
+
const checked = validateSmokeTarget({ cwd: smokeCwd, hubHome: home, project, expectedProjectId: values.get("--project-id")!, liveTest });
|
|
34
|
+
const target = { ...checked, check: () => { checked.check(); assertDelegatedAuditConsumer(); } };
|
|
35
|
+
const abort = new AbortController();
|
|
36
|
+
const interrupted = () => abort.abort();
|
|
37
|
+
process.on("SIGINT", interrupted); process.on("SIGTERM", interrupted);
|
|
38
|
+
try {
|
|
39
|
+
const result = await runSmoke(target, { leg: "qwen-dual-output", receipt: values.get("--receipt")!, timeoutMs: Number(values.get("--timeout-ms") ?? "60000"), signal: abort.signal });
|
|
40
|
+
process.exitCode = result.outcome === "passed" ? 0 : 1;
|
|
41
|
+
if (options.json) return console.log(JSON.stringify(result));
|
|
42
|
+
console.log(`smoke ${result.outcome} (${result.reason}): ${result.counts.submits} submits, ${result.counts.stops} stops; cleanup ${result.checks.cleaned ? "confirmed" : "unconfirmed"}`);
|
|
43
|
+
} finally { process.removeListener("SIGINT", interrupted); process.removeListener("SIGTERM", interrupted); }
|
|
44
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { matchesPolicy } from "../../hub/path-policy.ts";
|
|
2
|
+
import { TextProjections, type ProjectedText } from "../../hub/text-projection.ts";
|
|
3
|
+
import { fetchSourceUrl, MAX_SOURCE_BYTES, screenRegistration, sourceProjectionReceipt, SourceRegistry } from "../../hub/sources.ts";
|
|
4
|
+
import { renderSourceAdd, renderSourceList } from "../source-output.ts";
|
|
5
|
+
import { currentRouting } from "../../hub/routing.ts";
|
|
6
|
+
import { closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
|
|
7
|
+
import { join, resolve } from "node:path";
|
|
8
|
+
import { realPath } from "../../hub/project.ts";
|
|
9
|
+
import { asciiMarkers } from "../console-state.ts";
|
|
10
|
+
import type { CommandContext } from "../command-context.ts";
|
|
11
|
+
|
|
12
|
+
export async function run(context: CommandContext) {
|
|
13
|
+
const { SOURCE_USAGE, args, cwd, outputOptions, printOutput, projectConfig, stateDir, warn } = context;
|
|
14
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
15
|
+
// #508: the source registry. `add` is the person's or the configured conductor's (#933: admitted and audited by the daemon before this runs) and local:
|
|
16
|
+
// it reads and writes the hub state dir directly and needs no daemon. A URL is fetched here, once, by this process; no hub tool or agent ever fetches one.
|
|
17
|
+
const options = outputOptions();
|
|
18
|
+
const operands = args.filter(arg => arg !== "--json" && arg !== "--full" && !arg.startsWith("--color="));
|
|
19
|
+
const [sub, ...rest] = operands;
|
|
20
|
+
const registry = new SourceRegistry(stateDir);
|
|
21
|
+
if (sub === "list" && rest.length === 0) {
|
|
22
|
+
const rows = registry.list();
|
|
23
|
+
if (options.json) return console.log(JSON.stringify(rows, null, 2));
|
|
24
|
+
return printOutput(renderSourceList(rows, options.columns, Date.now(), asciiMarkers(process.env, process.argv.includes("--ascii"))), options.color);
|
|
25
|
+
}
|
|
26
|
+
if (sub !== "add" || rest.length !== 1 || !rest[0]) return fail(SOURCE_USAGE);
|
|
27
|
+
const target = rest[0], config = projectConfig();
|
|
28
|
+
const isUrl = /^[a-z][a-z0-9+.-]*:\/\//i.test(target);
|
|
29
|
+
let bytes: Buffer, origin: string, kind: "file" | "url", absolute: string | undefined;
|
|
30
|
+
try {
|
|
31
|
+
if (isUrl) {
|
|
32
|
+
const fetched = await fetchSourceUrl(target);
|
|
33
|
+
bytes = fetched.bytes; origin = fetched.finalUrl; kind = "url";
|
|
34
|
+
} else {
|
|
35
|
+
absolute = realPath(resolve(cwd, target));
|
|
36
|
+
const fd = openSync(absolute, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
37
|
+
try {
|
|
38
|
+
const st = fstatSync(fd);
|
|
39
|
+
if (!st.isFile()) throw new Error("not a regular file");
|
|
40
|
+
if (st.size > MAX_SOURCE_BYTES) throw new Error(`file is ${st.size} bytes, over the ${MAX_SOURCE_BYTES} byte cap (MAX_PROJECTION_INPUT); nothing was stored`);
|
|
41
|
+
bytes = Buffer.alloc(st.size); let got = 0;
|
|
42
|
+
while (got < bytes.length) { const n = readSync(fd, bytes, got, bytes.length - got, got); if (!n) break; got += n; }
|
|
43
|
+
if (got !== st.size) throw new Error("the file changed while it was read");
|
|
44
|
+
} finally { closeSync(fd); }
|
|
45
|
+
origin = absolute; kind = "file";
|
|
46
|
+
}
|
|
47
|
+
} catch (error) { return fail(`cannot register ${isUrl ? "that URL" : target}: ${(error as Error).message}`); }
|
|
48
|
+
const projections = new TextProjections({ cwd, stateDir, config: config.text_projection ?? {}, deny: config.local.deny, readAllow: config.local.read_allow, log: line => warn(line) });
|
|
49
|
+
const extension = /\.[A-Za-z0-9]{1,16}$/.exec(isUrl ? new URL(origin).pathname : origin)?.[0] ?? "";
|
|
50
|
+
let converted: ProjectedText | undefined;
|
|
51
|
+
const verdict = screenRegistration({ bytes, kind, ...(absolute ? { path: absolute, typedPath: resolve(cwd, target) } : {}) }, {
|
|
52
|
+
piiPaths: config.pii?.paths ?? [], piiPatterns: currentRouting(cwd).signals.pii_patterns, cwd, matchesPolicy,
|
|
53
|
+
project: data => { converted = extension ? projections.projectBytes(join(cwd, `source${extension.toLowerCase()}`), data) : undefined; return converted?.text; },
|
|
54
|
+
});
|
|
55
|
+
const projection = sourceProjectionReceipt(bytes, verdict.text, converted ? { extension: extension.toLowerCase(), value: converted } : undefined);
|
|
56
|
+
let added;
|
|
57
|
+
try { added = registry.add({ bytes, kind, origin, private: verdict.private, ...(verdict.text !== undefined ? { text: verdict.text } : {}), ...(projection ? { projection } : {}) }); }
|
|
58
|
+
catch (error) { return fail(`cannot register ${isUrl ? "that URL" : target}: ${(error as Error).message}`); }
|
|
59
|
+
const meta = registry.get(added.id);
|
|
60
|
+
if (!meta) return fail(`the record for ${added.id} cannot be read after it was registered; inspect ${join(stateDir, "sources")}`);
|
|
61
|
+
const result = { id: added.id, created: added.created, upgraded: added.upgraded, kind: meta.kind, origin: meta.origin, sha256: meta.sha256, bytes: meta.bytes, private: meta.private, text: added.text, reasons: verdict.reasons };
|
|
62
|
+
if (options.json) return console.log(JSON.stringify(result, null, 2));
|
|
63
|
+
printOutput(renderSourceAdd(result, options.columns, Date.now(), asciiMarkers(process.env, process.argv.includes("--ascii"))), options.color);
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { loadConfig } from "../../hub/config.ts";
|
|
2
|
+
import { createInterface } from "node:readline/promises";
|
|
3
|
+
import { runSpecs, runSpecsStamp } from "../specs.ts";
|
|
4
|
+
import type { CommandContext } from "../command-context.ts";
|
|
5
|
+
|
|
6
|
+
export async function run({ args, cwd }: CommandContext) {
|
|
7
|
+
if (args[0] !== "stamp") { process.exitCode = runSpecs(args, cwd, loadConfig(cwd).specs); return; }
|
|
8
|
+
// #1064 T3: person only. An agent identity never gets here (stamp is a `console` command in classifyPeerCommand); runSpecsStamp also refuses a run with no terminal.
|
|
9
|
+
const rl = process.stdin.isTTY && process.stdout.isTTY ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
10
|
+
try {
|
|
11
|
+
process.exitCode = await runSpecsStamp(args.slice(1), cwd, loadConfig(cwd).specs, { isTTY: !!rl, ask: async question => /^y(es)?$/i.test((await rl!.question(`${question} [y/N] `)).trim()) });
|
|
12
|
+
} finally { rl?.close(); }
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { petView, renderPet } from "../pet.ts";
|
|
2
|
+
import { loadPetConfig } from "../pet-config.ts";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { hubHome } from "../../hub/project.ts";
|
|
5
|
+
import { goalCommand } from "../memory.ts";
|
|
6
|
+
import { memoryIndexExists } from "../../hub/memory-profile.ts";
|
|
7
|
+
import { asciiMarkers } from "../console-state.ts";
|
|
8
|
+
import { renderStatus, renderStatusDefault } from "../output.ts";
|
|
9
|
+
import type { CommandContext } from "../command-context.ts";
|
|
10
|
+
|
|
11
|
+
export async function run({ args, connect, cwd, outputOptions, printOutput, printProjects }: CommandContext) {
|
|
12
|
+
const options = outputOptions();
|
|
13
|
+
if (args.includes("--all")) return printProjects(options);
|
|
14
|
+
const hub = await connect();
|
|
15
|
+
try {
|
|
16
|
+
const { status } = await hub.request({ t: "status", specs: true });
|
|
17
|
+
if (options.json) return console.log(JSON.stringify(status, null, 2));
|
|
18
|
+
const quota = await hub.request({ t: "budget" });
|
|
19
|
+
// CLI output standard v1: the default view answers "is it OK, and what do I do next"; every detail the older view printed stays behind --verbose (and --full, which adds the long ids).
|
|
20
|
+
const data = { ...status, budget: quota.budget ?? {} };
|
|
21
|
+
printOutput(options.verbose || options.full ? renderStatus(data, options.columns, Date.now(), options.full, asciiMarkers(process.env, args.includes("--ascii"))) : renderStatusDefault(data, options.columns, Date.now(), asciiMarkers(process.env, args.includes("--ascii"))), options.color);
|
|
22
|
+
if (status.needs) { const pet = loadPetConfig(cwd); if (pet.enabled) console.log(renderPet(petView(status), false, pet.character)); }
|
|
23
|
+
// #258: open long-term tasks and who holds them, as of this machine's last memory sync.
|
|
24
|
+
if (status.memoryProfile ? status.memoryProfile.state === "ready" : memoryIndexExists(join(hubHome(), "memory"))) {
|
|
25
|
+
try { const lines = await goalCommand(["list"], cwd); if (!lines.startsWith("no open")) console.log(`\nlong-term tasks\n${lines}`); } catch { /* memory unreadable: status goes on */ }
|
|
26
|
+
}
|
|
27
|
+
} finally { hub.close(); }
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CommandContext } from "../command-context.ts";
|
|
2
|
+
|
|
3
|
+
export async function run(context: CommandContext) {
|
|
4
|
+
const { args, connect } = context;
|
|
5
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
6
|
+
const peer = args[0];
|
|
7
|
+
if (args.length !== 1 || !peer || !/^[a-z][a-z0-9-]{0,31}$/.test(peer)) fail("usage: ahub stop <peer>");
|
|
8
|
+
const hub = await connect();
|
|
9
|
+
try {
|
|
10
|
+
const reply = await hub.request({ t: "peer_stop", peer }, 35_000);
|
|
11
|
+
if (reply.ok !== true) {
|
|
12
|
+
const error = String(reply.error ?? "peer stop request refused");
|
|
13
|
+
fail(/unknown (?:control )?(?:message|request|command)(?:\b|:)|this hub does not know "peer_stop"/i.test(error) ? `${error}; upgrade the running hub to use ahub stop` : error,reply.refusalAudited===true,reply.authorityRefused);
|
|
14
|
+
}
|
|
15
|
+
console.log(`${peer}: ${reply.state}`);
|
|
16
|
+
} finally { hub.close(); }
|
|
17
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { linkSync, lstatSync, mkdtempSync, renameSync, rmSync, writeFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { loadSdlc } from "../../hub/sdlc.ts";
|
|
4
|
+
import { checkStructureBudget, updateStructureBaseline } from "../../hub/structure-budget.ts";
|
|
5
|
+
import { readStructureBaseline, scanStructure } from "../../hub/structure-scan.ts";
|
|
6
|
+
import type { CommandContext } from "../command-context.ts";
|
|
7
|
+
|
|
8
|
+
const snippet = '[structure] | roots = ["src"] | max_lines = 800 | max_bytes = 65536 | shared = [] | baseline = "structure-baseline.json" | grow = "warn"';
|
|
9
|
+
|
|
10
|
+
export function run({ args, cwd, fail, printOutput }: CommandContext): void {
|
|
11
|
+
const check = args[0] === "check" && (args.length === 1 || args.length === 2 && args[1] === "--json");
|
|
12
|
+
const write = args[0] === "baseline" && args.length === 2 && args[1] === "--write";
|
|
13
|
+
if (!check && !write) return fail("Use ahub structure check [--json] or ahub structure baseline --write.");
|
|
14
|
+
const line = (text: string): void => printOutput([[{ text }]], false);
|
|
15
|
+
try {
|
|
16
|
+
const rules = loadSdlc(cwd).structure;
|
|
17
|
+
if (!rules) return line(`Structure rules are not configured. Add to .agenthub/sdlc.toml (replace each | with a newline): ${snippet}`);
|
|
18
|
+
const path = join(cwd, rules.baseline);
|
|
19
|
+
for (let dir = dirname(path); dir !== cwd; dir = dirname(dir)) {
|
|
20
|
+
if (!lstatSync(dir, { throwIfNoEntry: false })?.isDirectory()) {
|
|
21
|
+
return fail(`Structure baseline directory is missing or is a symlink. Check [structure] in .agenthub/sdlc.toml and run ahub help structure.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (write) {
|
|
25
|
+
const lock = path + ".lock";
|
|
26
|
+
try { mkdirSync(lock); }
|
|
27
|
+
catch (error) {
|
|
28
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
29
|
+
return fail(`Structure baseline lock exists at ${lock}. Once no other ahub structure baseline --write is running, remove that lock and rerun ahub structure baseline --write.`);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const baseline = readStructureBaseline(path);
|
|
33
|
+
const next = updateStructureBaseline(rules, baseline, scanStructure(cwd, rules));
|
|
34
|
+
const scratch = mkdtempSync(join(lock, "write-"));
|
|
35
|
+
const pending = join(scratch, "baseline.json");
|
|
36
|
+
writeFileSync(pending, JSON.stringify(next, null, 2) + "\n", { flag: "wx" });
|
|
37
|
+
if (baseline) renameSync(pending, path);
|
|
38
|
+
else linkSync(pending, path);
|
|
39
|
+
line(`Structure baseline: ${Object.keys(next.sizes).length} size ceilings, ${next.sharedNames.length} shared-name entries.`);
|
|
40
|
+
if (!baseline) line("initial baseline: review it before committing");
|
|
41
|
+
} finally {
|
|
42
|
+
rmSync(lock, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const baseline = readStructureBaseline(path);
|
|
47
|
+
const files = scanStructure(cwd, rules);
|
|
48
|
+
const result = checkStructureBudget(rules, baseline ?? { sizes: {}, sharedNames: [] }, files);
|
|
49
|
+
if (args[1] === "--json") line(JSON.stringify(result));
|
|
50
|
+
else {
|
|
51
|
+
for (const [severity, items] of [["warning", result.warnings], ["finding", result.findings]] as const) {
|
|
52
|
+
for (const item of items) line(`${severity} ${item.kind} ${item.path}: ${item.detail}. ${item.next}`);
|
|
53
|
+
}
|
|
54
|
+
if (!result.findings.length && !result.warnings.length) line("Structure check passed.");
|
|
55
|
+
}
|
|
56
|
+
if (result.findings.length) process.exitCode = 1;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return fail(`${error instanceof Error ? error.message : String(error)}. Check [structure] in .agenthub/sdlc.toml and run ahub help structure.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { parseSynthesisManifest } from "../../hub/synthesis-readiness.ts";
|
|
2
|
+
import { parseStudyArgs } from "../study.ts";
|
|
3
|
+
import { renderStudyEvidence, renderSynthesisReadiness, renderExperiments, renderStudyList, renderStudyReceipt, renderStudyShow } from "../study-output.ts";
|
|
4
|
+
import { refuseSynthesisTaskMismatch } from "../commands/shared-refusals.ts";
|
|
5
|
+
import type { CommandContext } from "../command-context.ts";
|
|
6
|
+
|
|
7
|
+
export async function run(context: CommandContext) {
|
|
8
|
+
const { args, contract, outputOptions, showToolText, splitPresentation, taskOp } = context;
|
|
9
|
+
const fail: CommandContext["fail"] = context.fail;
|
|
10
|
+
// #601: research campaigns. The hub keeps every campaign and decides every rule (Tasks.study*); this process parses argv, reads the contract file the person names and asks.
|
|
11
|
+
// Person only for draft, revise, approve and close (a console control op the daemon refuses on any other connection, and `study` has no agent form in classifyPeerCommand besides the
|
|
12
|
+
// read-only `show`); an agent drafts through the hub_study_* tools. `show` is a read: for a private campaign, task or source the hub sends ids, counts and states only.
|
|
13
|
+
const split = splitPresentation(args, { edges: true });
|
|
14
|
+
const present = outputOptions(split.flags); // before any request: an invalid --color must refuse before a mutation is sent
|
|
15
|
+
const parsed = parseStudyArgs(split.operands);
|
|
16
|
+
if ("usage" in parsed) return fail(parsed.usage);
|
|
17
|
+
|
|
18
|
+
if (parsed.op === "evidence") return showToolText((data, _c, now, ascii) => renderStudyEvidence(data, present.columns, now, ascii), await taskOp("hub_evidence_read", { id: parsed.id, ...(parsed.revision === undefined ? {} : { revision: parsed.revision }) }), present);
|
|
19
|
+
if (parsed.op === "evidence_inventory") return showToolText((data, _c, now, ascii) => renderStudyEvidence(data, present.columns, now, ascii), await taskOp("study_evidence", { taskId: parsed.taskId }), present);
|
|
20
|
+
if (parsed.op === "check") {
|
|
21
|
+
const manifest = parseSynthesisManifest(contract(parsed.file, "manifest"));
|
|
22
|
+
if (manifest.taskId !== parsed.taskId) return refuseSynthesisTaskMismatch(fail);
|
|
23
|
+
const text = await taskOp("study_check", { taskId: parsed.taskId, manifest });
|
|
24
|
+
showToolText((data, _c, now, ascii) => renderSynthesisReadiness(data, present.columns, now, ascii), text, present);
|
|
25
|
+
if (JSON.parse(text).status !== "ready") process.exitCode = 1;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (parsed.op === "experiments") {
|
|
29
|
+
// A read of the records Tasks keeps (hub_experiment_show): it runs no command and reads no file, and the hub blanks a private record itself.
|
|
30
|
+
const args = parsed.attempt ? { attemptId: parsed.attempt, ...(parsed.eventsAfter === undefined ? {} : { eventAfter: parsed.eventsAfter }) } : parsed.plan ? { planHash: parsed.plan, baselineAttemptId: parsed.baseline, variantAttemptId: parsed.variant } : { campaignId: parsed.campaign, ...(parsed.after === undefined ? {} : { after: parsed.after }) };
|
|
31
|
+
return showToolText((data, _c, now, ascii) => renderExperiments(data, present.columns, now, ascii), await taskOp("hub_experiment_show", args), present);
|
|
32
|
+
}
|
|
33
|
+
if (parsed.op === "show") return showToolText((data, _c, now, ascii) => parsed.id ? renderStudyShow(data, present.columns, now, ascii) : renderStudyList(data, present.columns, now, ascii), await taskOp("hub_study_show", parsed.id ? { id: parsed.id } : parsed.after ? { after: parsed.after } : {}), present);
|
|
34
|
+
const request = parsed.op === "draft" ? { parentTaskId: parsed.parentTaskId, contract: contract(parsed.file) }
|
|
35
|
+
: parsed.op === "revise" ? { id: parsed.id, revision: parsed.revision, contract: contract(parsed.file) }
|
|
36
|
+
: parsed.op === "approve_protocol" ? { hash: parsed.hash }
|
|
37
|
+
: parsed.op === "approve" ? { id: parsed.id, revision: parsed.revision } : { id: parsed.id, revision: parsed.revision, reason: parsed.reason };
|
|
38
|
+
return showToolText((data, _c, now, ascii) => renderStudyReceipt(parsed.op, data, present.columns, now, ascii), await taskOp(`study_${parsed.op}`, request, false, undefined, parsed.op === "approve" ? 90_000 : undefined), present);
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { contextLine } from "../status-lines.ts";
|
|
2
|
+
import { renderTailEvent } from "../tail-render.ts";
|
|
3
|
+
import type { CommandContext } from "../command-context.ts";
|
|
4
|
+
|
|
5
|
+
export async function run({ connect }: CommandContext) {
|
|
6
|
+
const hub = await connect();
|
|
7
|
+
hub.onPush = (msg) => {
|
|
8
|
+
if (msg.t === "event") console.log(renderTailEvent(msg.e));
|
|
9
|
+
else if (msg.t === "context") console.log(` ${msg.peer}: ${contextLine(msg.reading)}`);
|
|
10
|
+
else if (msg.t === "notice") console.log(` * ${msg.line}`);
|
|
11
|
+
else if (msg.t === "permission") {
|
|
12
|
+
const options = msg.options.map((o: any) => `${o.optionId} (${o.name})`).join(", ");
|
|
13
|
+
console.log(` ? ${msg.peer} asks permission: ${String(msg.title).replace(/\n/g, "\n | ")}\n answer with: ahub permit ${msg.id} <${options}> | deny`);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
hub.onClose = () => process.exit(0);
|
|
17
|
+
hub.send({ t: "tail" });
|
|
18
|
+
await new Promise(() => {});
|
|
19
|
+
}
|