@staix/agent-hub 0.45.0 → 0.46.1
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 +32 -0
- package/README.md +10 -4
- package/docs/adding-an-ai-tool.md +1 -0
- package/docs/agent-notes/adapters.md +33 -4
- package/docs/agent-notes/budget.md +2 -1
- package/docs/agent-notes/daemon.md +5 -1
- package/docs/agent-notes/security-review.md +3 -2
- package/docs/agent-notes/tasks.md +3 -1
- package/docs/agent-notes/tests.md +1 -1
- package/docs/design/adapters.md +16 -0
- package/docs/design/agent-hub-architecture.md +12 -0
- package/docs/design/cli-output.md +2 -0
- package/docs/design/roadmap.md +86 -5
- package/docs/design/task-board.md +2 -2
- package/docs/dogfood.md +15 -0
- package/docs/events.md +2 -2
- package/docs/operations.md +103 -21
- package/docs/quickstart.md +15 -3
- package/docs/security.md +7 -5
- package/docs/smoke.md +1 -1
- package/docs/verification/2026-11-05-hardcoded-values-classification-rules.md +28 -0
- package/docs/verification/2026-11-22-agy-1.5.14.md +27 -0
- package/docs/verification/2026-11-22-claude-instruction-hook.md +35 -0
- package/docs/verification/2026-11-22-instructed-ipc.md +9 -0
- package/docs/verification/2026-11-22-jcode-1.0.3.md +71 -0
- package/docs/verification/2026-11-22-jcode-separate-home.md +14 -0
- package/docs/verification/2026-11-22-qwen-0283-acp.md +28 -0
- package/docs/verification/2026-11-22-qwen-0283-dual-output.md +33 -0
- package/docs/verification/2026-11-22-roadmap-r5-view-receipt.md +63 -0
- package/docs/verification/2026-11-23-0.46.0.md +44 -0
- package/docs/verification/2026-11-24-0.46.1.md +48 -0
- package/docs/verification/assets/1483-r5-detail-1440-light.png +0 -0
- package/docs/verification/assets/1483-r5-detail-390-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-1440-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-1440-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-390-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-390-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-820-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-820-light.png +0 -0
- package/docs/verified.json +23 -23
- package/package.json +3 -2
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +6053 -5509
- package/plugins/agent-hub/server.js +1300 -1087
- package/plugins/agent-hub/skills/ahub/SKILL.md +17 -0
- package/plugins/agent-hub/skills/ahub-manage/SKILL.md +37 -0
- package/plugins/agent-hub/skills/ahub-status/SKILL.md +14 -0
- package/plugins/agent-hub/skills/ahub-use/SKILL.md +12 -0
- package/src/adapters/claude-channel.ts +2 -1
- package/src/adapters/compat.ts +12 -11
- package/src/adapters/definitions/native-cli-claude-setup.ts +9 -1
- package/src/adapters/definitions/native-cli-doctor.ts +8 -5
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +158 -0
- package/src/adapters/definitions/native-cli-jcode-home.ts +72 -0
- package/src/adapters/definitions/native-cli-jcode-mcp.ts +20 -0
- package/src/adapters/definitions/native-cli-skills.ts +29 -0
- package/src/cli/claude-profile-hook.ts +40 -3
- package/src/cli/console-state.ts +55 -26
- package/src/cli/console-usage.ts +5 -3
- package/src/cli/console.ts +35 -4
- package/src/cli/help.ts +15 -10
- package/src/cli/identity.ts +2 -1
- package/src/cli/instruction-hook.ts +28 -0
- package/src/cli/jcode-mcp.ts +2 -1
- package/src/cli/main.js +8 -0
- package/src/cli/main.ts +138 -18
- package/src/cli/output-standard.ts +3 -55
- package/src/cli/output.ts +8 -2
- package/src/cli/recovery-package.ts +53 -12
- package/src/cli/roadmap.ts +37 -3
- package/src/cli/setup-homes.ts +1 -0
- package/src/cli/setup.ts +1 -1
- package/src/cli/skills-install.ts +463 -0
- package/src/cli/task-output.ts +1 -1
- package/src/cli/upgrade-presentation-flags.ts +1 -1
- package/src/hub/board.ts +42 -4
- package/src/hub/budget-projection.ts +99 -0
- package/src/hub/claude-launch-proof.ts +5 -1
- package/src/hub/conductor.ts +8 -3
- package/src/hub/config-apply.ts +3 -2
- package/src/hub/config-tier.ts +1 -1
- package/src/hub/config-trust.ts +1 -1
- package/src/hub/control-client.ts +9 -2
- package/src/hub/daemon.ts +457 -26
- package/src/hub/events.ts +1 -1
- package/src/hub/execution-budget.ts +29 -8
- package/src/hub/hub-tools.ts +2 -2
- package/src/hub/inference.ts +1 -1
- package/src/hub/instances.ts +10 -1
- package/src/hub/instructed-exact.ts +95 -0
- package/src/hub/instructed-intent.ts +64 -0
- package/src/hub/instructed-ipc.ts +33 -0
- package/src/hub/instructed-runtime.ts +19 -0
- package/src/hub/instruction-receipt.ts +218 -0
- package/src/hub/manager.ts +46 -3
- package/src/hub/registry.ts +1 -1
- package/src/hub/roadmap-decompose.ts +60 -1
- package/src/hub/roadmap-sync.ts +2 -2
- package/src/hub/roadmap.ts +19 -1
- package/src/hub/routing.ts +18 -1
- package/src/hub/runtime-capture-prune.ts +2 -1
- package/src/hub/settings.ts +2 -1
- package/src/hub/tasks.ts +194 -12
- package/src/hub/ui.ts +6 -2
- package/src/hub/usage-rollup.ts +42 -2
- package/src/ui/index.html +342 -8
- package/src/ui/plugin.ts +6 -2
- package/src/ui/roadmap-model.ts +70 -0
package/src/cli/main.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
+
import { INSTRUCTION_CONTROL_TIMEOUT_MS } from "../hub/instructed-exact.ts";
|
|
2
3
|
import { assertConductorOperationLocal, authorizeConductorOperation, authorizeConductorLaunch, issueConductorOperation, preflightConductorRecovery, retireConductorOperation } from "./conductor-recovery.ts";
|
|
3
4
|
import { runtimePruneHealth } from "../hub/runtime-prune-health.ts";
|
|
4
5
|
import { conductorLocalOperation, conductorOperation, OPERATIONAL_PERSON_GUIDANCE } from "../hub/operational-authority.ts";
|
|
@@ -58,13 +59,13 @@ import { projectProfile, resolveProfile } from "../hub/profiles.ts";
|
|
|
58
59
|
import { catalogAssignments, loadRoleCatalog, selectedRoles } from "../hub/roles.ts";
|
|
59
60
|
import { attachWatch } from "./watch.ts";
|
|
60
61
|
import { verifiedJcodeCommand } from "../adapters/jcode.ts";
|
|
61
|
-
import { configureJcodeMcp, jcodeExtraMcpServers } from "./jcode-mcp.ts";
|
|
62
|
+
import { configureJcodeMcp, jcodeExtraMcpServers, splitJcodeMcpServers } from "./jcode-mcp.ts";
|
|
62
63
|
import { qwenSessionId } from "../hub/crash.ts";
|
|
63
64
|
import { isPermissionMode } from "../hub/permission-mode.ts";
|
|
64
65
|
import { parseSettingText, settingDef, settingText, undoableDef, type SettingRow } from "../hub/settings.ts";
|
|
65
66
|
import { startModeOf } from "../hub/start-mode.ts";
|
|
66
67
|
import { rolesRow } from "./role-doctor.ts";
|
|
67
|
-
import { currentRouting, OVERLAY_FILE, parseOverlay, parseRouting, routingText, type Routing, type RoutingOverlay } from "../hub/routing.ts";
|
|
68
|
+
import { classListRow, currentRouting, loadRouting, OVERLAY_FILE, parseOverlay, parseRouting, routingText, type Routing, type RoutingOverlay } from "../hub/routing.ts";
|
|
68
69
|
import { spawn, spawnSync } from "node:child_process";
|
|
69
70
|
import { chmodSync, closeSync, constants, existsSync, fstatSync, openSync, readFileSync, readSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
70
71
|
import { randomUUID } from "node:crypto";
|
|
@@ -73,6 +74,7 @@ import { basename, dirname, join, relative, resolve } from "node:path";
|
|
|
73
74
|
import { retryLaunchConnect, ControlClient, readControl } from "../hub/control-client.ts";
|
|
74
75
|
import { loadConfig } from "../hub/daemon.ts";
|
|
75
76
|
import { factsHook } from "./facts-hook.ts";
|
|
77
|
+
import { parseInstructionHook } from "./instruction-hook.ts";
|
|
76
78
|
import { hubHome, projectContext, projectRoot, realPath } from "../hub/project.ts";
|
|
77
79
|
import { Registry, type Project } from "../hub/registry.ts";
|
|
78
80
|
import { datasetInputFor, exportResearchDataset, projectFamilyOf } from "../hub/research-dataset.ts";
|
|
@@ -90,7 +92,9 @@ import { loadPacks } from "../hub/packs.ts";
|
|
|
90
92
|
import { launcherPreview } from "./preview.ts";
|
|
91
93
|
import { instanceLaunchArguments, requirePeerInstances, requireActiveInstance, cleanupStaleClaudeSettings, cleanupClaudeSettings, buildLaunch, buildKimiTuiLaunch, claudeObservationHooks, nativeLaunchEnv, recordClaudeLaunch, runClaudeLaunch, type ClaudeLaunchRecord, UNATTENDED_WARNING } from "./launch.ts";
|
|
92
94
|
import { configureKimiMcp } from "./kimi-mcp.ts";
|
|
93
|
-
import { nextStep, parseList, pluginState, type InstalledPlugin, type Marketplace } from "./setup.ts";
|
|
95
|
+
import { HUB_SKILL_NAMES, hubSkillsPresent, nextStep, parseList, pluginState, type InstalledPlugin, type Marketplace } from "./setup.ts";
|
|
96
|
+
import { installHubSkills, skillHostStates, skillStateRow } from "./skills-install.ts";
|
|
97
|
+
import { applyJcodeHome, installHubSkillsInJcodeHomes, installSkillsInJcodeHome, jcodeHomeBlocked, jcodeHomeSkillStates, jcodeSkillHomes, planJcodeHomeInit, rosterPreflight, rosterPreflightLines, writeJcodeHomeConfig } from "../adapters/definitions/native-cli-jcode-home-init.ts";
|
|
94
98
|
import { CLASSES } from "../hub/board.ts";
|
|
95
99
|
import { VERSION } from "../version.ts";
|
|
96
100
|
import { freeText, unknownOption, unknownOptionRefusal, withoutSeparator } from "./free-text.ts";
|
|
@@ -353,7 +357,7 @@ try { process.chdir(cwd); } catch { fail(`project directory is unavailable: ${cw
|
|
|
353
357
|
function outputOptions(source: readonly string[] = args) {
|
|
354
358
|
const flags = source.filter(arg => arg.startsWith("--color="));
|
|
355
359
|
if (flags.length > 1 || source.includes("--color")) fail(`usage: ahub ${cmd} [--color=auto|always|never] [--json] [--full]`);
|
|
356
|
-
const color = resolveColor(flags[0]?.slice("--color=".length), streamEnv(!!process.stdout.isTTY));
|
|
360
|
+
const color = resolveColor(flags[0]?.slice("--color=".length), streamEnv(!!process.stdout.isTTY), "ahub");
|
|
357
361
|
if (color instanceof Error) fail(`usage: ahub ${cmd} [--color=auto|always|never] [--json] [--full]`);
|
|
358
362
|
return { color: color === true, json: source.includes("--json"), full: source.includes("--full"), verbose: source.includes("--verbose"),
|
|
359
363
|
columns: outputWidth({ isTTY: !!process.stdout.isTTY, columns: process.stdout.columns, COLUMNS: process.env.COLUMNS }) };
|
|
@@ -414,6 +418,11 @@ const connect = async (timeoutMs = 3000) => {
|
|
|
414
418
|
|
|
415
419
|
const connectLaunch = () => retryLaunchConnect(connect, () => console.error("hub busy, retrying"));
|
|
416
420
|
|
|
421
|
+
/** #1627 A: what init does for the hub-owned jcode home, read-only. */
|
|
422
|
+
function initJcodeHome() {
|
|
423
|
+
const config = loadConfig(cwd);
|
|
424
|
+
return planJcodeHomeInit({ cwd, stateDir, bundle: join(import.meta.dir, "..", "..", "plugins", "agent-hub", "server.js"), hubHome: hubHome(), config, env: process.env, installed: !!Bun.which(config.jcode_cmd[0] ?? "jcode") });
|
|
425
|
+
}
|
|
417
426
|
function registeredProject(): Project {
|
|
418
427
|
const registry = new Registry();
|
|
419
428
|
try { return registry.register(cwd, stateDir); }
|
|
@@ -1098,7 +1107,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1098
1107
|
else if (conductorPeer) retireConductorOperation(result, conductorPeer);
|
|
1099
1108
|
},
|
|
1100
1109
|
help: () => {
|
|
1101
|
-
const color = resolveColor(undefined, streamEnv(!!process.stdout.isTTY)) === true;
|
|
1110
|
+
const color = resolveColor(undefined, streamEnv(!!process.stdout.isTTY), "ahub") === true;
|
|
1102
1111
|
const topic = asksHelp(args[0]) ? undefined : args[0];
|
|
1103
1112
|
const text = topic && !definitionOf(topic) && projectCatalog.definitionOf(topic)?.permission.genericAcp !== undefined
|
|
1104
1113
|
? configuredAcpHelp(topic) : renderHelp(process.stdout.columns ?? 80, color, topic, undefined, asciiMarkers(process.env, args.includes("--ascii")));
|
|
@@ -1173,8 +1182,23 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1173
1182
|
const root = join(import.meta.dir, "..", "..");
|
|
1174
1183
|
if (args.includes("--research") && args.includes("--no-research")) fail("--research conflicts with --no-research; give one; nothing was written");
|
|
1175
1184
|
const research = args.includes("--research") ? true : args.includes("--no-research") ? false : undefined;
|
|
1176
|
-
const setupFlags = takeFlags(args.filter(arg => !["--yes", "--research", "--no-research"].includes(arg)), ["--agents"], []);
|
|
1177
|
-
if (setupFlags.rest.length) fail("usage: ahub setup [--yes] [--agents <a,b>] [--research|--no-research]");
|
|
1185
|
+
const setupFlags = takeFlags(args.filter(arg => !["--yes", "--research", "--no-research", "--undo"].includes(arg)), ["--agents"], []);
|
|
1186
|
+
if (setupFlags.rest.length) fail("usage: ahub setup [--yes] [--agents <a,b>] [--research|--no-research] [--undo]");
|
|
1187
|
+
if (args.includes("--undo")) {
|
|
1188
|
+
if (research !== undefined || setupFlags.one["--agents"] !== undefined) fail("--undo removes the hub's own skill trees only; drop --research and --agents; nothing was written");
|
|
1189
|
+
// #1622: remove only the trees the hub wrote and nobody edited; a modified, foreign or linked tree is reported and kept.
|
|
1190
|
+
const undoReader = process.stdin.isTTY ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
1191
|
+
try {
|
|
1192
|
+
await installHubSkills({ undo: true, yes: args.includes("--yes"),
|
|
1193
|
+
ask: async prompt => { try { return undoReader ? await undoReader.question(prompt) : null; } catch { return null; } },
|
|
1194
|
+
print: line => console.log(terminalText(line)) });
|
|
1195
|
+
// #1627 AC1b: the hub-owned jcode homes (the configured one and each instance's), under the same marker contract.
|
|
1196
|
+
await installHubSkillsInJcodeHomes({ undo: true, homes: jcodeSkillHomes(loadConfig(cwd), process.env), yes: args.includes("--yes"),
|
|
1197
|
+
ask: async prompt => { try { return undoReader ? await undoReader.question(prompt) : null; } catch { return null; } },
|
|
1198
|
+
print: line => console.log(terminalText(line)) });
|
|
1199
|
+
} finally { undoReader?.close(); }
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1178
1202
|
if (research !== undefined && (liveTest || delegatedPeer || recoveryLauncherCurrent)) fail("the machine research default requires the person's own ahub setup; nothing was written");
|
|
1179
1203
|
const registry = new Registry(), rl = process.stdin.isTTY ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
1180
1204
|
let machineRoots = [cwd];
|
|
@@ -1183,7 +1207,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1183
1207
|
const found = recoveryLauncherCurrent || delegatedPeer ? await discoverClaudeHomes({ home: homedir(), env: process.env }) : await usedClaudeHomes(registry, homedir(), process.env);
|
|
1184
1208
|
for (const notice of found.notices) console.log(terminalText(notice));
|
|
1185
1209
|
try {
|
|
1186
|
-
await setupClaudeHomes({ homes: found.homes, env: process.env, packageRoot: root, yes: args.includes("--yes"),
|
|
1210
|
+
await setupClaudeHomes({ homes: found.homes, env: process.env, packageRoot: root, yes: args.includes("--yes"), hook: { instruction: true },
|
|
1187
1211
|
interactive: !!rl,
|
|
1188
1212
|
current: () => { recoveryLauncherCurrent?.(); assertLifecycleAvailable(cwd); },
|
|
1189
1213
|
print: line => console.log(terminalText(line)), ask: async prompt => rl ? rl.question(prompt) : null,
|
|
@@ -1198,6 +1222,14 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1198
1222
|
...(rl ? { ask: async (prompt: string) => { try { return await rl.question(prompt); } catch { return null; } } } : {}), print: line => console.log(terminalText(line)) });
|
|
1199
1223
|
if (refused) fail(refused);
|
|
1200
1224
|
}
|
|
1225
|
+
// #1622: the hub's own skills for every other installed agent host, under the marker contract.
|
|
1226
|
+
assertLifecycleAvailable(cwd);
|
|
1227
|
+
await installHubSkills({ source: join(root, "plugins", "agent-hub", "skills"), yes: args.includes("--yes"),
|
|
1228
|
+
ask: async prompt => { try { return rl ? await rl.question(prompt) : null; } catch { return null; } },
|
|
1229
|
+
print: line => console.log(terminalText(line)) });
|
|
1230
|
+
await installHubSkillsInJcodeHomes({ source: join(root, "plugins", "agent-hub", "skills"), homes: jcodeSkillHomes(loadConfig(cwd), process.env), yes: args.includes("--yes"),
|
|
1231
|
+
ask: async prompt => { try { return rl ? await rl.question(prompt) : null; } catch { return null; } },
|
|
1232
|
+
print: line => console.log(terminalText(line)) });
|
|
1201
1233
|
if (research !== undefined) machineRoots = [...registry.list().map(row => row.root), cwd];
|
|
1202
1234
|
} finally { registry.close(); rl?.close(); }
|
|
1203
1235
|
if (homesFailed) fail(startupDiagnostic(homesFailure));
|
|
@@ -1214,7 +1246,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1214
1246
|
// #1065 T1: the settings flags come out first (a value flag takes the next word), then the older flags as before.
|
|
1215
1247
|
let settings: ReturnType<typeof parseInitSettings>;
|
|
1216
1248
|
try { settings = parseInitSettings(args); } catch (error) { return fail((error as Error).message); }
|
|
1217
|
-
const flags = takeFlags(settings.rest.filter(arg => arg !== "--dry-run" && arg !== "--json" && arg !== "--shadow" && arg !== "--release-guard" && arg !== "--yes"), ["--profile"], []);
|
|
1249
|
+
const flags = takeFlags(settings.rest.filter(arg => arg !== "--dry-run" && arg !== "--json" && arg !== "--shadow" && arg !== "--release-guard" && arg !== "--yes" && arg !== "--no-jcode-home"), ["--profile"], []);
|
|
1218
1250
|
if (flags.rest.length) fail(INIT_USAGE);
|
|
1219
1251
|
// A pack is a project file in .agenthub/roles/<name>.pack.json (#513a); init resolves the name and refuses an unknown one with the profiles and packs it knows.
|
|
1220
1252
|
let requestedProfile = flags.one["--profile"];
|
|
@@ -1260,6 +1292,9 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1260
1292
|
const inherit = inheritAutonomy ? autonomyInheritanceChange(cwd, defaults.enabled, request.autonomy) : undefined;
|
|
1261
1293
|
if (inherit) plan.push(inherit);
|
|
1262
1294
|
if (defaults.notice) console.error(defaults.notice);
|
|
1295
|
+
// #1627 A: the hub-owned jcode home is part of the plan, never written by a dry run.
|
|
1296
|
+
const homePlan = args.includes("--no-jcode-home") ? undefined : initJcodeHome();
|
|
1297
|
+
if (homePlan?.applicable) for (const line of homePlan.lines) plan.push({ action: homePlan.plan?.exists ? "modify" : "create", path: homePlan.plan!.home, reason: line.trim() });
|
|
1263
1298
|
// Without a settings flag the preview is the bare list of file rows, as it always was; with one it is { changes, settings }.
|
|
1264
1299
|
if (args.includes("--json")) return console.log(JSON.stringify(asked ? { changes: plan, settings: rows } : plan, null, 2));
|
|
1265
1300
|
const settingLines = rows.map(row => ` ${row.key}: ${row.from === undefined ? "(not set)" : JSON.stringify(row.from)} -> ${JSON.stringify(row.to)} (${row.file})`);
|
|
@@ -1271,6 +1306,24 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1271
1306
|
try { nextSteps = initNextSteps(cwd, request); changed = init(cwd, requestedProfile, shadow, releaseGuard, request); } catch (error) { return fail((error as Error).message); }
|
|
1272
1307
|
const project = registeredProject();
|
|
1273
1308
|
console.log(changed.length ? changed.map((p) => `${existsSync(p) ? "wrote" : "removed"} ${p}`).join("\n") : "already up to date");
|
|
1309
|
+
// #1627 A: the hub-owned jcode home, after the project files exist. The person's own home is never written; a rerun reports drift only.
|
|
1310
|
+
if (!args.includes("--no-jcode-home")) {
|
|
1311
|
+
const homeInit = initJcodeHome();
|
|
1312
|
+
if (homeInit.applicable && homeInit.plan) {
|
|
1313
|
+
for (const line of homeInit.lines) console.log(terminalText(line));
|
|
1314
|
+
if (homeInit.switchHome) { try { writeJcodeHomeConfig(cwd, homeInit.plan.home); console.log(`jcode_home now points at ${homeInit.plan.home}`); } catch (error) { console.error((error as Error).message); process.exitCode = 1; } }
|
|
1315
|
+
if (!homeInit.plan.exists) {
|
|
1316
|
+
if (jcodeHomeBlocked(homeInit.plan.home)) console.error(`jcode home ${homeInit.plan.home} is not a plain directory; nothing was created there`);
|
|
1317
|
+
else {
|
|
1318
|
+
try {
|
|
1319
|
+
applyJcodeHome(homeInit.plan);
|
|
1320
|
+
const installed = installSkillsInJcodeHome(join(import.meta.dir, "..", "..", "plugins", "agent-hub", "skills"), homeInit.plan.home);
|
|
1321
|
+
console.log(`wrote ${homeInit.plan.home}; hub skills: ${installed.filter(entry => entry.action === "install" || entry.action === "replace").length} installed`);
|
|
1322
|
+
} catch (error) { console.error(`jcode home was not fully set up: ${(error as Error).message}`); process.exitCode = 1; }
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1274
1327
|
if (newProject) {
|
|
1275
1328
|
if (inheritAutonomy) {
|
|
1276
1329
|
const registry = new Registry();
|
|
@@ -1294,7 +1347,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1294
1347
|
|
|
1295
1348
|
console: async () => {
|
|
1296
1349
|
if (args.some(arg => arg !== "--panels" && arg !== "--no-pet" && !arg.startsWith("--color=")) || args.filter(arg => arg.startsWith("--color=")).length > 1) fail("usage: ahub console [--panels] [--no-pet] [--color=auto|always|never]");
|
|
1297
|
-
const color = resolveColor(args.find(arg => arg.startsWith("--color="))?.slice("--color=".length), streamEnv(!!process.stdin.isTTY && !!process.stdout.isTTY));
|
|
1350
|
+
const color = resolveColor(args.find(arg => arg.startsWith("--color="))?.slice("--color=".length), streamEnv(!!process.stdin.isTTY && !!process.stdout.isTTY), "ahub");
|
|
1298
1351
|
if (color instanceof Error) return fail("usage: ahub console [--panels] [--no-pet] [--color=auto|always|never]");
|
|
1299
1352
|
await runConsole({ client: await connect(), cwd, stateDir, liveTest, panels: args.includes("--panels"), noPet: args.includes("--no-pet"), color, installed: consoleInstalled() });
|
|
1300
1353
|
},
|
|
@@ -1597,7 +1650,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1597
1650
|
const peer = args[0];
|
|
1598
1651
|
if (typeof peer !== "string" || !peerDefinition(peer)?.capabilities?.watch) fail("usage: ahub watch kimi|qwen [--no-thoughts] [--color=auto|always|never]");
|
|
1599
1652
|
if (args.slice(1).some(arg => arg !== "--no-thoughts" && !/^--color=(auto|always|never)$/.test(arg))) fail("unsupported watch option");
|
|
1600
|
-
const color = resolveColor(args.find(arg => arg.startsWith("--color="))?.slice(8), streamEnv(!!process.stdout.isTTY));
|
|
1653
|
+
const color = resolveColor(args.find(arg => arg.startsWith("--color="))?.slice(8), streamEnv(!!process.stdout.isTTY), "ahub");
|
|
1601
1654
|
if (color instanceof Error) fail(color.message);
|
|
1602
1655
|
const hub = await connect();
|
|
1603
1656
|
const input = process.stdin;
|
|
@@ -1640,8 +1693,11 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1640
1693
|
const op = outputArguments()[1] ?? "status";
|
|
1641
1694
|
let request: Record<string, unknown> = { t: "execution_budget", op, ...(outputArguments()[2] ? { id: outputArguments()[2] } : {}) };
|
|
1642
1695
|
if (op === "configure") {
|
|
1643
|
-
|
|
1644
|
-
|
|
1696
|
+
// #1513 AC3: the reason is optional; without one the budget is configured exactly as before.
|
|
1697
|
+
const flags = takeFlags(outputArguments().slice(2), ["--reason"], []);
|
|
1698
|
+
const configPath = flags.rest[0];
|
|
1699
|
+
if (!configPath || flags.rest.length > 1) { hub.close(); fail("usage: ahub budget execution configure <config.json> [--reason <text>]"); }
|
|
1700
|
+
try { request = { t: "execution_budget", op, config: JSON.parse(readFileSync(configPath, "utf8")), ...(flags.one["--reason"] ? { reason: flags.one["--reason"] } : {}) }; }
|
|
1645
1701
|
catch { hub.close(); fail("cannot read execution budget JSON configuration"); }
|
|
1646
1702
|
}
|
|
1647
1703
|
const result = await hub.request(request); hub.close();
|
|
@@ -2442,6 +2498,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
2442
2498
|
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");
|
|
2443
2499
|
if (reply.ok !== true) fail(String(reply.error ?? `session title refused: ${String(reply.reason ?? "invalid")}; refresh ahub status, then retry`));
|
|
2444
2500
|
console.log(`${peer}: session title updated`);
|
|
2501
|
+
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)}`);
|
|
2445
2502
|
} finally { hub.close(); }
|
|
2446
2503
|
},
|
|
2447
2504
|
|
|
@@ -2471,7 +2528,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
2471
2528
|
roster: async () => {
|
|
2472
2529
|
const options = outputOptions(), flags = args.filter(arg => arg.startsWith("--")), positional = outputArguments().filter(arg => arg !== "--yes" && arg !== "--now");
|
|
2473
2530
|
const [sub = "list", peer, ...extra] = positional;
|
|
2474
|
-
if (!["list", "add", "remove"].includes(sub) || extra.length || (sub === "list" ? peer !== undefined : !peerDefinition(peer) && !(sub === "remove" && typeof peer === "string" && staleInstanceKey(peer, projectCatalog))) || flags.some(flag => !["--json", "--full", "--yes", "--now"].includes(flag) && !flag.startsWith("--color=")) || (sub !== "list" && options.json) || (sub
|
|
2531
|
+
if (!["list", "add", "remove"].includes(sub) || extra.length || (sub === "list" ? peer !== undefined : !peerDefinition(peer) && !(sub === "remove" && typeof peer === "string" && staleInstanceKey(peer, projectCatalog))) || flags.some(flag => !["--json", "--full", "--yes", "--now"].includes(flag) && !flag.startsWith("--color=")) || (sub !== "list" && options.json) || (sub === "list" && flags.some(flag => ["--yes", "--now"].includes(flag))) || (sub === "add" && flags.includes("--now"))) fail("usage: ahub roster [--json] | add <peer> [--yes] | remove <peer> [--yes] [--now]");
|
|
2475
2532
|
const hub = await connect();
|
|
2476
2533
|
try {
|
|
2477
2534
|
requireNamedPeerFeature(hub, peer);
|
|
@@ -2485,6 +2542,17 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
2485
2542
|
const key = `roster.${peer}`, stale = sub === "remove" && !peerDefinition(peer) && staleInstanceKey(peer!, projectCatalog), value = stale ? null : sub === "add";
|
|
2486
2543
|
const preview = await request({ t: "settings_preview", key, value });
|
|
2487
2544
|
printOutput((preview.lines ?? []).map((text: string) => [{ text }]), options.color);
|
|
2545
|
+
// #1627 B: adding a peer shows what it would start with, and asks first. Without a terminal and without --yes nothing is changed; a conductor that passes --yes keeps today's authority.
|
|
2546
|
+
if (sub === "add") {
|
|
2547
|
+
const config = loadConfig(cwd), kind = peerDefinition(peer)?.kind ?? peer!;
|
|
2548
|
+
printOutput(rosterPreflightLines(peer!, rosterPreflight(peer!, kind, cwd, config, process.env)).map(text => [{ text }]), options.color);
|
|
2549
|
+
if (!flags.includes("--yes")) {
|
|
2550
|
+
if (!process.stdin.isTTY) fail(`not a terminal: nothing was changed; rerun with: cd ${shellQuote(cwd)} && ahub roster add ${peer} --yes`);
|
|
2551
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
2552
|
+
let answer: string; try { answer = await rl.question(`Add ${peer} to the roster? [y/N] `); } finally { rl.close(); }
|
|
2553
|
+
if (!/^(y|yes)$/i.test(answer.trim())) return console.log("nothing was changed");
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2488
2556
|
if (sub === "remove" && !flags.includes("--yes")) {
|
|
2489
2557
|
if (!process.stdin.isTTY) fail("not a terminal: nothing was changed; rerun with --yes after reviewing the preview");
|
|
2490
2558
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -2593,6 +2661,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
2593
2661
|
const def = key === undefined || sdlcRead ? undefined : settingDef(key, settingScope.instances, settingScope.catalog);
|
|
2594
2662
|
if (typeof def === "string") fail(settingScopeError && def.startsWith("unknown setting") ? `${key}: ${def}; the project config could not be read: ${settingScopeError}` : `${key}: ${def}`);
|
|
2595
2663
|
if (flags.includes("--now") && (typeof def !== "object" || def.group !== "Roster")) fail(usage);
|
|
2664
|
+
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");
|
|
2596
2665
|
const value = sub === "set" ? parseSettingText(def!, text!) : undefined;
|
|
2597
2666
|
const peer = def?.group === "Permissions" || def?.group === "Roster" ? def.path.at(-1)! : undefined;
|
|
2598
2667
|
if (sub === "set" && value === "never-ask" && !flags.includes("--preview")) {
|
|
@@ -2693,7 +2762,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
2693
2762
|
if (sub === "list" && row.group !== group) console.log(`${group ? "\n" : ""}${group = row.group}`);
|
|
2694
2763
|
const facts = [`from ${row.source}`, `file: ${settingText(row.fileValue === undefined ? row.pending ?? row.value : row.fileValue)}`, row.applies === "live" ? "applies at once" : row.applies === "next use" ? "applies at next use" : "pending restart", ...(row.restartReason ? [row.restartReason] : []), ...(row.note ? [row.note] : [])];
|
|
2695
2764
|
console.log(` ${row.key.padEnd(width)} ${settingText(row.value).padEnd(valueWidth)} ${facts.join("; ")}`);
|
|
2696
|
-
if (sub === "get") console.log(` ${row.label}; written to ${row.file}; takes ${row.type === "boolean" ? "true, false" : row.type === "number-or-off" ? `off or a number from ${row.min ?? 0} to ${row.max ?? "the configured bound"}` : row.type === "integer" || row.type === "number" ? `a number from ${row.min ?? 0} to ${row.max ?? "the configured bound"}` : row.type === "peers" ? "a comma list of peer ids" : row.type === "roles" ? "up to two comma-separated catalog ids" : (row.values ?? []).join(", ")}${row.file === "this hub run" ? "" : ", or inherit to remove the machine-local value"}${row.risk === "raises" ? "; a dashboard needs a settings session (ahub ui --settings) to raise it" : ""}`);
|
|
2765
|
+
if (sub === "get") console.log(` ${row.label}; written to ${row.file}; takes ${row.type === "boolean" ? "true, false" : row.type === "number-or-off" ? `off or a number from ${row.min ?? 0} to ${row.max ?? "the configured bound"}` : row.type === "integer" || row.type === "number" ? `a number from ${row.min ?? 0} to ${row.max ?? "the configured bound"}` : row.type === "peers" ? "a comma list of peer ids" : row.type === "roles" ? "up to two comma-separated catalog ids" : (row.values ?? []).join(", ")}${row.file === "this hub run" || row.key === "instructed.mode" ? "" : ", or inherit to remove the machine-local value"}${row.risk === "raises" ? "; a dashboard needs a settings session (ahub ui --settings) to raise it" : ""}`);
|
|
2697
2766
|
}
|
|
2698
2767
|
if (sub === "list" && view.pendingRestart?.length) console.log(`\npending restart: ${view.pendingRestart.map((entry: { key: string }) => entry.key).join(", ")}`);
|
|
2699
2768
|
if (sub === "list" && view.undo) console.log(`\nahub settings undo puts back the last write (${view.undo})`);
|
|
@@ -3050,6 +3119,32 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
3050
3119
|
if (options.json) return console.log(JSON.stringify(sub === "limits" ? { limits: reply.limits, current: reply.current } : sub === "total" ? reply.total : reply.usage, null, 2));
|
|
3051
3120
|
printOutput(sub === "limits" ? renderLimits(reply.limits, reply.current, options.columns) : sub === "total" ? renderTotal(reply.total, options.columns) : renderUsage(reply.usage, options.columns), options.color);
|
|
3052
3121
|
},
|
|
3122
|
+
instructed: async () => {
|
|
3123
|
+
if (args[0] === "run") {
|
|
3124
|
+
const session = process.env.CLAUDE_CODE_SESSION_ID;
|
|
3125
|
+
if (caller.role !== "tools" || !session || liveTest) return fail("instruction requires the current managed Claude session");
|
|
3126
|
+
const hub = await connect();
|
|
3127
|
+
try {
|
|
3128
|
+
const result = await hub.request({ t: "instruction_execute", session, ...(args.length > 1 ? { argv: args.slice(1) } : {}) }, INSTRUCTION_CONTROL_TIMEOUT_MS);
|
|
3129
|
+
if (typeof result.output === "string") process.stdout.write(result.output);
|
|
3130
|
+
if (result.ok !== true) fail(String(result.error ?? "instruction was not completed"));
|
|
3131
|
+
} finally { hub.close(); }
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
return fail("usage: ahub instructed run [<operation> <args...>]");
|
|
3135
|
+
},
|
|
3136
|
+
"instruction-hook": async () => {
|
|
3137
|
+
if (args.length || caller.role !== "tools" || liveTest) return;
|
|
3138
|
+
try {
|
|
3139
|
+
const chunks: Buffer[] = []; let size = 0;
|
|
3140
|
+
for await (const chunk of process.stdin) { const bytes = Buffer.from(chunk); size += bytes.length; if (size > 1024 * 1024) return; chunks.push(bytes); }
|
|
3141
|
+
const input = Buffer.concat(chunks).toString("utf8");
|
|
3142
|
+
const message = parseInstructionHook(input, process.env);
|
|
3143
|
+
if (!message) return;
|
|
3144
|
+
const hub = await connect(2000);
|
|
3145
|
+
try { await hub.request(message, 2000); } finally { hub.close(); }
|
|
3146
|
+
} catch { /* Hook failure never alters the native prompt or reveals it. */ }
|
|
3147
|
+
},
|
|
3053
3148
|
facts: async () => {
|
|
3054
3149
|
if (!args.includes("--hook")) return fail("usage: ahub facts --hook (a Claude Code PreToolUse, PostToolUse and Stop hook)");
|
|
3055
3150
|
try {
|
|
@@ -3353,6 +3448,18 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
3353
3448
|
const config = loadConfig(cwd), assigned = catalogAssignments(config.catalog_roles);
|
|
3354
3449
|
for (const peer of Object.keys(assigned)) selectedRoles(peer, config.roles, assigned, catalog);
|
|
3355
3450
|
} catch { row(false, "catalog roles", "invalid assignment id, shape or flow base"); }
|
|
3451
|
+
// #1626 C: a rostered peer that can implement but sits in no class list never gets a task from routing. A warning, like the rows above.
|
|
3452
|
+
try {
|
|
3453
|
+
const config = loadConfig(cwd), scope = readInstanceRoleConfig(cwd);
|
|
3454
|
+
const roster = (peer: string) => rosterAllows(config.roster, peer, config.pi.enabled, scope.instances, scope.catalog);
|
|
3455
|
+
const implementers = [...new Set([...Object.keys(config.roles), ...Object.keys(config.roster)])]
|
|
3456
|
+
.filter(peer => roster(peer) && ((config.roles[peer] ?? []).includes("implementer") || [...(definitionOf(peer, scope.instances)?.roles ?? [])].includes("implementer")))
|
|
3457
|
+
.sort();
|
|
3458
|
+
const file = join(cwd, ".agenthub", "routing.toml");
|
|
3459
|
+
const result = classListRow(implementers, loadRouting(cwd), file, existsSync(file));
|
|
3460
|
+
// An advisory row, so it warns rather than failing: only a row the person must repair is a fail.
|
|
3461
|
+
checks.push({ name: "routing classes", section: "Config", level: result.ok === undefined ? "warn" : result.ok ? "ok" : "fail", detail: result.detail });
|
|
3462
|
+
} catch (error) { row(undefined, "routing classes", `could not be checked: ${error instanceof Error ? error.message : "unknown error"}`); }
|
|
3356
3463
|
for (const bin of DOCTOR_TOOL_PROBES) {
|
|
3357
3464
|
const v = version(bin);
|
|
3358
3465
|
row(!!v, bin, v ?? "not found on PATH");
|
|
@@ -3378,8 +3485,19 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
3378
3485
|
}
|
|
3379
3486
|
} finally { hub.close(); }
|
|
3380
3487
|
}
|
|
3381
|
-
const
|
|
3488
|
+
const plugins = parseList<InstalledPlugin>(spawnSync(DOCTOR_PLUGIN_PROBE.command, [...DOCTOR_PLUGIN_PROBE.argv], { encoding: "utf8" }).stdout ?? "");
|
|
3489
|
+
const plugin = pluginState(plugins, join(import.meta.dir, "..", ".."));
|
|
3382
3490
|
row(plugin.state === "current", DOCTOR_PLUGIN_PROBE.name, plugin.state === "missing" ? "missing: run ahub setup" : plugin.state === "current" ? `agent-hub@agent-hub ${plugin.version}` : `agent-hub@agent-hub is stale (${plugin.why}): run ahub setup`);
|
|
3491
|
+
// #1622: one row for the hub's own skills, in the Claude plugin and on every other installed host; a tree the hub will not touch is a warning.
|
|
3492
|
+
const skillsPresent = hubSkillsPresent(plugins);
|
|
3493
|
+
const hostSkills = skillStateRow(skillHostStates({ home: homedir(), env: process.env }, HUB_SKILL_NAMES));
|
|
3494
|
+
const claudeSkills = skillsPresent ? "Claude plugin skills present" : `missing from Claude user plugin; repair: cd ${shellQuote(cwd)} && ${plugin.state === "missing" ? "ahub setup" : "claude plugin uninstall agent-hub@agent-hub --scope user && ahub setup"}`;
|
|
3495
|
+
const hostRepair = hostSkills.ok === false ? `; repair: cd ${shellQuote(cwd)} && ahub setup` : "";
|
|
3496
|
+
// #1627 AC1b: the hub-owned jcode homes carry the skills too; a missing or stale tree there is the same repair.
|
|
3497
|
+
const ownedHomes = jcodeHomeSkillStates(jcodeSkillHomes(loadConfig(cwd), process.env), HUB_SKILL_NAMES);
|
|
3498
|
+
const ownedBad = ownedHomes.filter(state => state.state === "missing" || state.state === "stale" || state.state === "failed");
|
|
3499
|
+
const ownedText = ownedHomes.length ? `; hub-owned jcode ${ownedHomes.map(state => `${state.home} ${state.state}`).join(", ")}${ownedBad.length ? `; repair: cd ${shellQuote(cwd)} && ahub setup` : ""}` : "";
|
|
3500
|
+
row(skillsPresent ? (ownedBad.length ? false : hostSkills.ok) : false, "hub skills", `${claudeSkills}; ${hostSkills.detail}${hostRepair}${ownedText}`);
|
|
3383
3501
|
let profileRegistry: Registry | undefined;
|
|
3384
3502
|
try {
|
|
3385
3503
|
profileRegistry = new Registry();
|
|
@@ -3409,8 +3527,10 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
3409
3527
|
if (probe.kind === "source-identity") row(verifiedJcodeCommand(probe.command, cwd), probe.name, probe.detail);
|
|
3410
3528
|
else if (probe.kind === "jcode-mcp") {
|
|
3411
3529
|
const { servers, unreadable } = jcodeExtraMcpServers(cwd, probe.home);
|
|
3412
|
-
|
|
3413
|
-
|
|
3530
|
+
const { allowed, refused } = splitJcodeMcpServers(servers, probe.allow ?? []);
|
|
3531
|
+
row(refused.length || unreadable.length ? false : true, probe.name,
|
|
3532
|
+
[refused.length ? `${refused.length} besides the hub's own would load in the hub-owned jcode and are not allowed (${refused.join(", ")}); jcode has no switch to choose them, so remove them from its config, use another JCODE_HOME, or accept them by name in jcode_mcp_allow in .agenthub/config.local.json` : "",
|
|
3533
|
+
allowed.length ? `allowed by the person: ${allowed.join(", ")}` : "",
|
|
3414
3534
|
unreadable.length ? `unreadable or unsafe, not listed: ${unreadable.join(", ")}` : ""].filter(Boolean).join("; ") || "none besides the hub's own");
|
|
3415
3535
|
} else {
|
|
3416
3536
|
const verdict = assessVersion(probe.compat, COMPAT[probe.compat].parse(version(probe.command[0]!) ?? ""));
|
|
@@ -1,56 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Human-output code names a role or a marker, never an SGR code or a glyph literal.
|
|
3
|
-
/**
|
|
4
|
-
* The nine semantic roles of CLI output standard v1 on the 16 ANSI colors, so a terminal theme decides the shades. Code names a role,
|
|
5
|
-
* never an SGR code (`test/cli-output-conformance.test.ts` fails on a raw SGR literal in `src/cli/` and `src/hub/`). `value` is the
|
|
6
|
-
* default foreground and carries no SGR. Bold is only for `header`, `section` and the three status roles; no backgrounds.
|
|
7
|
-
*/
|
|
8
|
-
/** End of every painted span. */
|
|
9
|
-
export const SGR_RESET = "\x1b[0m";
|
|
10
|
-
/** SGR of the console tones that are not an identity palette entry; the role table above is the standard, these are the TUI's own. */
|
|
1
|
+
// Hub-specific TUI tones; the portable standard is provided by @staix/cli-output.
|
|
11
2
|
export const TONE_SGR = Object.freeze({ strong: "\x1b[1;36m", failure: "\x1b[31m", number: "\x1b[1m", issueRef: "\x1b[4m", taskRef: "\x1b[4;35m" } as const);
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
header: "\x1b[1;34m", section: "\x1b[1;35m", key: "\x1b[34m", value: "", success: "\x1b[1;32m", warning: "\x1b[1;33m", error: "\x1b[1;31m", hint: "\x1b[90m", accent: "\x1b[36m",
|
|
15
|
-
});
|
|
16
|
-
export const MARKER_NAMES = ["ok", "fail", "warn", "absent", "unknown", "pending", "active", "next"] as const;
|
|
17
|
-
export type MarkerName = (typeof MARKER_NAMES)[number];
|
|
18
|
-
/** Semantic glyphs, each with its ASCII form and the one role that colors it. Code names a marker, never a glyph literal. */
|
|
19
|
-
export const MARKERS: Readonly<Record<MarkerName, { glyph: string; ascii: string; role: Role }>> = Object.freeze({
|
|
20
|
-
ok: { glyph: "\u2713", ascii: "ok", role: "success" }, fail: { glyph: "\u2717", ascii: "x", role: "error" }, warn: { glyph: "\u26a0", ascii: "!", role: "warning" },
|
|
21
|
-
absent: { glyph: "-", ascii: "-", role: "hint" }, unknown: { glyph: "?", ascii: "?", role: "hint" }, pending: { glyph: "~", ascii: "~", role: "hint" },
|
|
22
|
-
active: { glyph: "*", ascii: "*", role: "success" }, next: { glyph: "\u2192", ascii: "->", role: "accent" },
|
|
23
|
-
});
|
|
24
|
-
export const SECTION_MARKER = { glyph: "\u25b8", ascii: ">" } as const;
|
|
25
|
-
export const MARKER_COLUMN = 2;
|
|
26
|
-
/** Cells a string occupies: East Asian Ambiguous characters count as 1, so a Korean or CJK terminal keeps the same alignment. */
|
|
27
|
-
export const cellWidth = (text: string): number => Bun.stringWidth(text, { ambiguousIsNarrow: true });
|
|
28
|
-
/** A marker padded to the 2-cell marker column (ASCII `ok` and `->` fill it). */
|
|
29
|
-
export function markerCell(name: MarkerName, ascii: boolean): string {
|
|
30
|
-
const text = ascii ? MARKERS[name].ascii : MARKERS[name].glyph;
|
|
31
|
-
return text + " ".repeat(Math.max(0, MARKER_COLUMN - cellWidth(text)));
|
|
32
|
-
}
|
|
33
|
-
/** The environment one output stream's color decision reads (`streamEnv` builds it). */
|
|
34
|
-
export interface ColorEnv { isTTY: boolean; TERM?: string; NO_COLOR?: string; FORCE_COLOR?: string; CLICOLOR?: string; CLICOLOR_FORCE?: string }
|
|
35
|
-
/** `isTTY` of the stream that is decided (stdout and stderr are decided separately) plus the color variables of `env`. */
|
|
36
|
-
export function streamEnv(isTTY: boolean, env: Readonly<Record<string, string | undefined>> = process.env): ColorEnv {
|
|
37
|
-
return { isTTY, TERM: env.TERM, NO_COLOR: env.NO_COLOR, FORCE_COLOR: env.FORCE_COLOR, CLICOLOR: env.CLICOLOR, CLICOLOR_FORCE: env.CLICOLOR_FORCE };
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Color for one stream, first rule wins (standard v1): `--color=never|always`; non-empty NO_COLOR off; FORCE_COLOR or CLICOLOR_FORCE
|
|
41
|
-
* non-empty and not `0` on; FORCE_COLOR=0 or CLICOLOR=0 off; a TTY whose TERM is not `dumb` on; otherwise off. `auto` and no flag
|
|
42
|
-
* apply rules 2 to 6. An unknown flag value is a usage error. `--json` is never colored: the caller does not ask.
|
|
43
|
-
*/
|
|
44
|
-
export function resolveColor(flag: string | undefined, env: ColorEnv): boolean | Error {
|
|
45
|
-
if (flag === "always") return true;
|
|
46
|
-
if (flag === "never") return false;
|
|
47
|
-
if (flag !== undefined && flag !== "auto") return new Error("usage: ahub <command> [--color=auto|always|never]");
|
|
48
|
-
if (env.NO_COLOR) return false;
|
|
49
|
-
if ((env.FORCE_COLOR && env.FORCE_COLOR !== "0") || (env.CLICOLOR_FORCE && env.CLICOLOR_FORCE !== "0")) return true;
|
|
50
|
-
if (env.FORCE_COLOR === "0" || env.CLICOLOR === "0") return false;
|
|
51
|
-
return env.isTTY && env.TERM !== "dumb";
|
|
52
|
-
}
|
|
53
|
-
/** ASCII markers when `--ascii` is given or the locale (`LC_ALL`, then `LC_CTYPE`, then `LANG`) is not UTF-8. */
|
|
54
|
-
export function asciiMarkers(env: Readonly<Record<string, string | undefined>> = process.env, flag = false): boolean {
|
|
55
|
-
return flag || !/utf-?8/i.test(env.LC_ALL || env.LC_CTYPE || env.LANG || "");
|
|
56
|
-
}
|
|
3
|
+
export { SGR_RESET, ROLE_SGR, MARKER_NAMES, MARKERS, SECTION_MARKER, MARKER_COLUMN, cellWidth, markerCell, streamEnv, resolveColor, asciiMarkers } from "@staix/cli-output";
|
|
4
|
+
export type { Role, MarkerName, ColorEnv } from "@staix/cli-output";
|
package/src/cli/output.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReviewGate, ReviewUnknownQuota } from "../hub/review-budget.ts";
|
|
2
|
+
import { projectionText } from "../hub/budget-projection.ts";
|
|
2
3
|
import { quotaAccountReading } from "../hub/quota-account.ts";
|
|
3
4
|
import { projectModelStatus } from "./model.ts";
|
|
4
5
|
import type { RuntimeModelStatus } from "../hub/model-overrides.ts";
|
|
@@ -616,8 +617,13 @@ export function renderBudget(data: BudgetOutput, columns?: number, now = Date.no
|
|
|
616
617
|
if (data.review) out.push(...detail("Reviewer admission", data.review.rule, columns));
|
|
617
618
|
// KIND names what the number is (#285): the provider's own (native), tokens the hub counted against a ceiling (count), or a person's (manual).
|
|
618
619
|
// A window without a kind, from an older hub, is classified by `windowKind`. A fresh window that does not gate says so in STATE.
|
|
619
|
-
|
|
620
|
-
|
|
620
|
+
// #1513 AC2: LEFT and REACHES are the same fields the dashboard and the console render, from the same window view.
|
|
621
|
+
const windows = Object.entries(data.budget).flatMap(([peer, b]) => (b.windows ?? []).map((w: any) => [span(peer, peerTone(peer)), span(w.id), span(`${Math.round(w.used * 100)}%`, "number"),
|
|
622
|
+
span(typeof w.left === "number" ? `${Math.round(w.left * 100)}%` : "unknown", typeof w.left === "number" ? "number" : "muted"),
|
|
623
|
+
span(typeof w.resetsAt === "number" ? relative(w.resetsAt, now) : "-", "muted"),
|
|
624
|
+
span(w.projection ? projectionText(w.projection, at => relative(at, now)) : "unknown", w.projection?.state === "projected" ? undefined : "muted"),
|
|
625
|
+
span(windowKind({ id: w.id, source: w.source ?? "", kind: w.kind }), "muted"), span(w.source ?? "unknown", "muted"), span(typeof w.at === "number" ? relative(w.at, now) : "unknown", "muted"), span(w.stale ? "stale" : w.superseded ? "info only" : "fresh", w.stale ? "attention" : undefined)]));
|
|
626
|
+
if (windows.length) out.push(...rows(["PEER", "WINDOW", "USED", "LEFT", "RESETS", "REACHES", "KIND", "SOURCE", "MEASURED", "STATE"], windows, columns));
|
|
621
627
|
else if (!data.peers?.length) out.push(...lines(`no quota readings yet (gate ${data.gate ?? "unknown"}). Sources: Codex rate limits, Claude's status line (ahub claude), ahub budget set.`, columns));
|
|
622
628
|
// A peer with no number says why, in its own line, so a peer without quota is not mistaken for one that has not reported.
|
|
623
629
|
for (const note of data.peers ?? []) out.push(...detail(note.peer, note.note, columns, peerTone(note.peer)));
|
|
@@ -43,8 +43,9 @@ export function exactVersion(version: string): string {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const MEMORY_ASSETS = ["src", "bin", "package.json", "README.md", "LICENSE"] as const;
|
|
46
|
+
const OUTPUT_ASSETS = ["src", "package.json", "README.md", "LICENSE"] as const;
|
|
46
47
|
|
|
47
|
-
/**
|
|
48
|
+
/** Runtime dependencies are limited to the reviewed first-party packages, never an arbitrary dependency tree. */
|
|
48
49
|
function memoryRuntime(root: string, dependencyRoot?: string): string | undefined {
|
|
49
50
|
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
50
51
|
const deps = pkg.dependencies ?? {};
|
|
@@ -52,7 +53,7 @@ function memoryRuntime(root: string, dependencyRoot?: string): string | undefine
|
|
|
52
53
|
const declared = deps["@staix/agent-mem"];
|
|
53
54
|
// #1611: a current package declares a floor range `>=X.Y.Z <M.0.0`; a package staged under #1605 declares `~X.Y.Z` and one before it an exact
|
|
54
55
|
// version, so a cached release still verifies (legacy forms need no host API); compound ranges, `^`, `*` and prereleases stay refused.
|
|
55
|
-
if (Object.keys(deps).
|
|
56
|
+
if (Object.keys(deps).some(name => !["@staix/agent-mem", "@staix/cli-output"].includes(name)) || typeof declared !== "string" || !(/^~?\d+\.\d+\.\d+$/.test(declared) || isAgentMemFloorRange(declared))) throw new Error("unsupported runtime dependencies in recovery package");
|
|
56
57
|
let dir = dependencyRoot ? join(dependencyRoot, "node_modules/@staix/agent-mem")
|
|
57
58
|
: dirname(createRequire(join(root, "package.json")).resolve("@staix/agent-mem"));
|
|
58
59
|
if (dependencyRoot && !existsSync(dir)) throw new Error("memory runtime dependency is unavailable");
|
|
@@ -74,7 +75,12 @@ function memoryRuntime(root: string, dependencyRoot?: string): string | undefine
|
|
|
74
75
|
if (!agentMemHostApiOk(host.min, host.version))
|
|
75
76
|
throw new Error(`memory runtime host API ${host.min ?? "missing"}..${host.version ?? "missing"} does not intersect the supported ${AGENT_MEM_HOST_API_RANGE[0]}..${AGENT_MEM_HOST_API_RANGE[1]}`);
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
+
// #1664: agent-mem 0.37.0+ declares exactly the hub's own pinned @staix/cli-output (hashed once by outputRuntime); nothing else, and no nested node_modules the digest would not cover.
|
|
79
|
+
const memoryDeps = Object.entries(memory.dependencies ?? {}), outputPin = deps["@staix/cli-output"];
|
|
80
|
+
// A ranged hub pin is the output package's refusal to make, not a memory mismatch (outputRuntime says the same).
|
|
81
|
+
if (memoryDeps.length && typeof outputPin === "string" && !/^\d+\.\d+\.\d+$/.test(outputPin)) throw new Error("output runtime dependency must be an exact version");
|
|
82
|
+
const depsOk = memoryDeps.length === 0 || (memoryDeps.length === 1 && typeof outputPin === "string" && memoryDeps[0]?.[0] === "@staix/cli-output" && memoryDeps[0][1] === outputPin);
|
|
83
|
+
if (!accepted || !depsOk || (memoryDeps.length > 0 && existsSync(join(dir, "node_modules")))) throw new Error("memory runtime dependency identity/version mismatch");
|
|
78
84
|
return realPath(dir);
|
|
79
85
|
}
|
|
80
86
|
}
|
|
@@ -84,14 +90,43 @@ function memoryRuntime(root: string, dependencyRoot?: string): string | undefine
|
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
/** Resolve only the declared exact output package, including in an isolated retained or staged install. */
|
|
94
|
+
function outputRuntime(root: string, dependencyRoot?: string): string | undefined {
|
|
95
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
96
|
+
const declared = pkg.dependencies?.["@staix/cli-output"];
|
|
97
|
+
if (declared === undefined) return undefined;
|
|
98
|
+
if (typeof declared !== "string" || !/^\d+\.\d+\.\d+$/.test(declared)) throw new Error("output runtime dependency must be an exact version");
|
|
99
|
+
let dir = dependencyRoot ? join(dependencyRoot, "node_modules/@staix/cli-output")
|
|
100
|
+
: dirname(createRequire(join(root, "package.json")).resolve("@staix/cli-output"));
|
|
101
|
+
if (dependencyRoot && !existsSync(dir)) throw new Error("output runtime dependency is unavailable");
|
|
102
|
+
if (dependencyRoot) for (const name of ["node_modules", "node_modules/@staix", "node_modules/@staix/cli-output"]) {
|
|
103
|
+
if (lstatSync(join(dependencyRoot, name)).isSymbolicLink()) throw new Error("runtime package must not contain symlinks");
|
|
104
|
+
}
|
|
105
|
+
for (;;) {
|
|
106
|
+
const manifest = join(dir, "package.json");
|
|
107
|
+
if (existsSync(manifest)) {
|
|
108
|
+
const output = JSON.parse(readFileSync(manifest, "utf8"));
|
|
109
|
+
if (output.name === "@staix/cli-output") {
|
|
110
|
+
if (output.version !== declared || Object.keys(output.dependencies ?? {}).length) throw new Error("output runtime dependency identity/version mismatch");
|
|
111
|
+
return realPath(dir);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const parent = dirname(dir);
|
|
115
|
+
if (dependencyRoot || parent === dir) throw new Error("output runtime dependency is unavailable");
|
|
116
|
+
dir = parent;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
87
120
|
export function preserveRuntimeDependencies(root: string, destination: string): void {
|
|
88
|
-
const memory = memoryRuntime(root);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
121
|
+
const memory = memoryRuntime(root), output = outputRuntime(root);
|
|
122
|
+
for (const [source, packageName, assets] of [[memory, "agent-mem", MEMORY_ASSETS], [output, "cli-output", OUTPUT_ASSETS]] as const) {
|
|
123
|
+
if (!source) continue;
|
|
124
|
+
const target = join(destination, "node_modules/@staix", packageName);
|
|
125
|
+
mkdirSync(target, { recursive: true });
|
|
126
|
+
for (const name of assets) {
|
|
127
|
+
if (lstatSync(join(source, name)).isSymbolicLink()) throw new Error("runtime package must not contain symlinks");
|
|
128
|
+
cpSync(join(source, name), join(target, name), { recursive: true, dereference: false });
|
|
129
|
+
}
|
|
95
130
|
}
|
|
96
131
|
}
|
|
97
132
|
|
|
@@ -106,7 +141,7 @@ export function packageDigest(root: string, options: { ownDependencies?: boolean
|
|
|
106
141
|
else file(join(directory, item.name), name);
|
|
107
142
|
}
|
|
108
143
|
};
|
|
109
|
-
// Only runtime assets and the
|
|
144
|
+
// Only runtime assets and the resolved first-party packages; never private state or unrelated dependencies.
|
|
110
145
|
for (const name of ["src", "plugins", "templates", ".claude-plugin"]) visit(join(root, name), `${name}/`);
|
|
111
146
|
hash.update(readFileSync(join(root, "package.json")));
|
|
112
147
|
const memory = memoryRuntime(root, options.ownDependencies ? root : options.dependencyRoot);
|
|
@@ -115,6 +150,12 @@ export function packageDigest(root: string, options: { ownDependencies?: boolean
|
|
|
115
150
|
if (stat.isSymbolicLink()) throw new Error("runtime package must not contain symlinks");
|
|
116
151
|
if (stat.isDirectory()) visit(path, `${prefix}/`); else file(path, prefix);
|
|
117
152
|
}
|
|
153
|
+
const output = outputRuntime(root, options.ownDependencies ? root : options.dependencyRoot);
|
|
154
|
+
if (output) for (const name of OUTPUT_ASSETS) {
|
|
155
|
+
const path = join(output, name), stat = lstatSync(path), prefix = `node_modules/@staix/cli-output/${name}`;
|
|
156
|
+
if (stat.isSymbolicLink()) throw new Error("runtime package must not contain symlinks");
|
|
157
|
+
if (stat.isDirectory()) visit(path, `${prefix}/`); else file(path, prefix);
|
|
158
|
+
}
|
|
118
159
|
return hash.digest("hex");
|
|
119
160
|
}
|
|
120
161
|
|
|
@@ -131,7 +172,7 @@ export function recoveryPackageOptions(kind: "restart" | "upgrade", root: string
|
|
|
131
172
|
if (kind === "restart") return { ownDependencies: true };
|
|
132
173
|
if (kind !== "upgrade") throw new Error("unsupported recovery package kind");
|
|
133
174
|
const canonical = realPath(root);
|
|
134
|
-
// Project captures own
|
|
175
|
+
// Project captures own their resolved dependencies and keep the registry install separate below this version.
|
|
135
176
|
if (canonical === root && /^source-[a-f0-9]{64}$/.test(basename(canonical)) && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(basename(dirname(canonical)))
|
|
136
177
|
&& basename(dirname(dirname(canonical))) === "releases") return { ownDependencies: true };
|
|
137
178
|
const dependencyRoot = resolve(canonical, "../../..");
|