@staix/agent-hub 0.48.4 → 0.49.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 +20 -0
- package/README.md +1 -1
- package/docs/agent-notes/daemon.md +2 -2
- package/docs/agent-notes/tasks.md +1 -1
- package/docs/design/adapters.md +5 -7
- package/docs/design/agent-hub-architecture.md +2 -1
- package/docs/design/agent-hub.md +2 -1
- package/docs/design/bus.md +3 -2
- package/docs/design/cli-output-inventory.md +39 -38
- package/docs/design/cli-output.md +9 -4
- package/docs/design/execution-reference.md +1 -0
- package/docs/design/guidance-experiments.md +4 -1
- package/docs/design/guidance-probes.md +34 -31
- package/docs/design/model-routes.md +12 -14
- package/docs/design/roadmap.md +11 -9
- package/docs/design/supervision.md +7 -6
- package/docs/design/task-board.md +3 -2
- package/docs/dogfood.md +1 -1
- package/docs/memory.md +3 -3
- package/docs/operations.md +14 -9
- package/docs/quickstart.md +20 -2
- package/docs/roadmap.json +519 -1
- package/docs/roadmap.md +94 -0
- package/docs/security.md +4 -2
- package/docs/verification/2026-11-26-compat-pi-1.6.1.md +28 -0
- package/docs/verification/2026-11-28-0.49.0.md +53 -0
- package/docs/verification/2026-11-29-0.49.1.md +50 -0
- package/docs/verified.json +19 -19
- package/package.json +3 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +324 -98
- package/plugins/agent-hub/server.js +334 -104
- package/src/adapters/channel-peer.ts +5 -2
- package/src/adapters/claude-channel.ts +1 -0
- package/src/adapters/compat.ts +4 -4
- package/src/adapters/definitions/native-cli-entry-claude.ts +22 -1
- package/src/cli/agents-output.ts +13 -0
- package/src/cli/agents.ts +16 -7
- package/src/cli/answer-output.ts +67 -0
- package/src/cli/broker.ts +9 -2
- package/src/cli/console-state.ts +12 -39
- package/src/cli/launch.ts +1 -1
- package/src/cli/main.ts +96 -127
- package/src/cli/recovery-package.ts +78 -26
- package/src/cli/reset-output.ts +50 -0
- package/src/cli/sdlc-output.ts +57 -0
- package/src/cli/settings-output.ts +80 -0
- package/src/hub/check-runner.ts +7 -3
- package/src/hub/claude-launch-proof.ts +12 -2
- package/src/hub/claude-state.ts +3 -0
- package/src/hub/control-client.ts +2 -0
- package/src/hub/daemon.ts +102 -40
- package/src/hub/roadmap-export.ts +12 -9
- package/src/hub/roadmap-issue-states.ts +35 -0
- package/src/hub/runtime-capture-prune.ts +21 -6
- package/src/hub/runtime-package-assets.ts +6 -0
- package/src/hub/supervision-proposals.ts +3 -3
- package/src/hub/supervision-rules.ts +2 -2
- package/src/hub/task-sweep.ts +1 -1
- package/src/hub/tasks.ts +37 -20
|
@@ -7,7 +7,7 @@ import type { ClaudeChannelEvidence } from "./claude-channel-evidence.ts";
|
|
|
7
7
|
/** Only the control socket operations the peer owns; authentication remains in the daemon. */
|
|
8
8
|
export interface ChannelSocket {
|
|
9
9
|
readyState: number;
|
|
10
|
-
data: { launchId?: string; protocol?: number; standbyId?: string; retainStandby?: boolean; clientPid?: number; clientVersion?: string; channel?: boolean; channelEvidence?: ClaudeChannelEvidence; cwd?: string; peerGeneration?: string | number; detachedByPerson?: boolean };
|
|
10
|
+
data: { launchId?: string; claudeSessionId?: string; protocol?: number; standbyId?: string; retainStandby?: boolean; clientPid?: number; clientVersion?: string; channel?: boolean; channelEvidence?: ClaudeChannelEvidence; cwd?: string; peerGeneration?: string | number; detachedByPerson?: boolean };
|
|
11
11
|
send(data: string): unknown;
|
|
12
12
|
close(code?: number, reason?: string): void;
|
|
13
13
|
}
|
|
@@ -23,6 +23,7 @@ export class WsPeer extends BasePeer {
|
|
|
23
23
|
private static readonly MAX_STANDBY_SESSIONS = 8;
|
|
24
24
|
readonly acceptedSettlement = "explicit" as const;
|
|
25
25
|
readonly form: StartForm = "tui";
|
|
26
|
+
constructor(id: string, private readonly nativeSessionAtAttach?: (socket: ChannelSocket) => string | undefined) { super(id); }
|
|
26
27
|
private generation = crypto.randomUUID();
|
|
27
28
|
// Checkpoints become stale at hello/claim, before asynchronous recall finishes and attach changes delivery generation.
|
|
28
29
|
private claimGeneration = crypto.randomUUID();
|
|
@@ -86,7 +87,7 @@ export class WsPeer extends BasePeer {
|
|
|
86
87
|
if (!facts || facts.socket !== this.sock || !this.attached) return undefined;
|
|
87
88
|
const native = (this as { nativeSession?: string }).nativeSession;
|
|
88
89
|
return { ...(facts.ownerPid !== undefined ? { ownerPid: facts.ownerPid } : {}), attachedAt: facts.attachedAt,
|
|
89
|
-
...(typeof native === "string" && NATIVE_SESSION_ID.test(native) ? { nativeSessionId: native } : {}) };
|
|
90
|
+
...(!this.nativeSessionAtAttach && typeof native === "string" && NATIVE_SESSION_ID.test(native) ? { nativeSessionId: native } : {}) };
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
/** A session that shows pushes holds the peer or is arriving: a session without them must not take it (issue #205). */
|
|
@@ -166,6 +167,8 @@ export class WsPeer extends BasePeer {
|
|
|
166
167
|
this.delivered.clear();
|
|
167
168
|
this.nativeTurnSession = undefined;
|
|
168
169
|
delete (this as { nativeSession?: string }).nativeSession;
|
|
170
|
+
const nativeSession = this.nativeSessionAtAttach?.(sock);
|
|
171
|
+
if (nativeSession) this.bindNativeSession(nativeSession);
|
|
169
172
|
this.nativeActive = false;
|
|
170
173
|
this.pullOnly = this.claimedPullOnly; // before idle: the idle transition drains
|
|
171
174
|
this.attachMode = this.pullOnly ? "tools-only" : "channel";
|
|
@@ -315,6 +315,7 @@ async function connectLoop(): Promise<void> {
|
|
|
315
315
|
const client = await ControlClient.connect(stateDir, { role: toolsMode || sessionJoin ? "tools" : "peer", peer: peerId, ...(toolsMode || sessionJoin ? {} : { channel, channelEvidence }),
|
|
316
316
|
...(!toolsMode && !sessionJoin ? { retainStandby: true, clientPid: process.pid } : {}),
|
|
317
317
|
...(sessionJoin ? { session: sessionJoin.label } : {}),
|
|
318
|
+
...(process.env.CLAUDE_CODE_SESSION_ID ? { claudeSessionId: process.env.CLAUDE_CODE_SESSION_ID } : {}),
|
|
318
319
|
...(process.env.AGENTHUB_LAUNCH_ID ? { launchId: process.env.AGENTHUB_LAUNCH_ID } : {}),
|
|
319
320
|
...(executionCwd !== undefined ? { cwd: executionCwd } : {}),
|
|
320
321
|
...(!toolsMode && standingBy ? { standby: true } : {}),
|
package/src/adapters/compat.ts
CHANGED
|
@@ -29,11 +29,11 @@ export interface CompatPolicy {
|
|
|
29
29
|
|
|
30
30
|
const plain = (text: string) => text.length <= 64 && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(text) ? text : undefined;
|
|
31
31
|
export const COMPAT = {
|
|
32
|
-
// Receipts: docs/verification/2026-10-26-pi-140-compat.md (1.4.0); docs/verification/2026-11-03-pi-150-compat.md (1.5.0); docs/verification/2026-11-14-pi-152-compat.md (1.5.2); docs/verification/2026-11-25-pi-160-compat.md (1.6.0)
|
|
33
|
-
pi: { label: "Pi", verified: ["1.4.0", "1.5.0", "1.5.2", "1.6.0"], gate: "contract", probe: ["pi", "--version"], config: "pi.cmd",
|
|
32
|
+
// Receipts: docs/verification/2026-10-26-pi-140-compat.md (1.4.0); docs/verification/2026-11-03-pi-150-compat.md (1.5.0); docs/verification/2026-11-14-pi-152-compat.md (1.5.2); docs/verification/2026-11-25-pi-160-compat.md (1.6.0); docs/verification/2026-11-26-compat-pi-1.6.1.md (1.6.1)
|
|
33
|
+
pi: { label: "Pi", verified: ["1.4.0", "1.5.0", "1.5.2", "1.6.0", "1.6.1"], gate: "contract", probe: ["pi", "--version"], config: "pi.cmd",
|
|
34
34
|
parse: out => plain(out.trim()),
|
|
35
|
-
trustNote: "The model-free extension load, RPC session identity and managed tool receipt path were checked on 1.4.0, 1.5.0, 1.5.2 and 1.6.
|
|
36
|
-
receipt: "docs/verification/2026-11-
|
|
35
|
+
trustNote: "The model-free extension load, RPC session identity and managed tool receipt path were checked on 1.4.0, 1.5.0, 1.5.2, 1.6.0 and 1.6.1. Permissions remain host-owned; account-backed inference and another version's extension contract are unverified.",
|
|
36
|
+
receipt: "docs/verification/2026-11-26-compat-pi-1.6.1.md" },
|
|
37
37
|
// Transport receipts: docs/verification/2026-10-23-headless-claude-permissions.md; 2.1.310: docs/verification/2026-10-26-claude-implementer-2.1.310.md; 2.1.314 (transport and wrapper): docs/verification/2026-10-31-claude-implementer-2.1.314.md; 2.1.316: docs/verification/2026-10-31-claude-implementer-2.1.316.md; 2.1.318: docs/verification/2026-11-05-claude-implementer-2.1.318.md; 2.1.319: docs/verification/2026-11-06-claude-implementer-2.1.319.md; 2.1.322: docs/verification/2026-11-10-claude-implementer-2.1.322.md; 2.1.323: docs/verification/2026-11-13-claude-implementer-2.1.323.md; 2.1.328: docs/verification/2026-11-19-claude-implementer-2.1.328.md; 2.1.329: docs/verification/2026-11-20-claude-implementer-2.1.329.md; 2.1.332: docs/verification/2026-11-25-claude-implementer-2.1.332.md; host-wrapper receipt below repeats with them.
|
|
38
38
|
"claude-implementer": { label: "Claude headless implementer", verified: ["2.1.309", "2.1.310", "2.1.314", "2.1.316", "2.1.318", "2.1.319", "2.1.322", "2.1.323", "2.1.328", "2.1.329", "2.1.332"], gate: "contract", probe: ["claude", "--version"],
|
|
39
39
|
parse: out => plain(out.trim().replace(/ \(Claude Code\)$/, "")),
|
|
@@ -4,7 +4,26 @@ import { join } from "node:path";
|
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import type { ClaudeLaunchRecord } from "../../cli/launch.ts";
|
|
6
6
|
import type { NativeCliEntryContext } from "./native-cli-entry-types.ts";
|
|
7
|
-
import { claudeStateFile } from "../../hub/claude-state.ts";
|
|
7
|
+
import { claudeStateFile, isClaudeSessionUuid } from "../../hub/claude-state.ts";
|
|
8
|
+
|
|
9
|
+
/** Preserve native selectors. A picker, continuation or fork without an explicit id stays unattested. */
|
|
10
|
+
function managedSession(nativeArgs: string[]): string | undefined {
|
|
11
|
+
const separator = nativeArgs.indexOf("--");
|
|
12
|
+
const options = separator < 0 ? nativeArgs : nativeArgs.slice(0, separator);
|
|
13
|
+
const values = (names: readonly string[]) => options.flatMap((arg, index) => {
|
|
14
|
+
if (names.includes(arg)) return [options[index + 1]];
|
|
15
|
+
const name = names.find(value => arg.startsWith(value + "="));
|
|
16
|
+
return name ? [arg.slice(name.length + 1)] : [];
|
|
17
|
+
});
|
|
18
|
+
const explicit = values(["--session-id"]);
|
|
19
|
+
const resume = values(["--resume", "-r"]);
|
|
20
|
+
if (explicit.length) return explicit.length === 1 && isClaudeSessionUuid(explicit[0]) ? explicit[0] : undefined;
|
|
21
|
+
if (options.some(arg => ["-c", "--continue", "--from-pr", "--teleport", "--fork-session"].some(flag => arg === flag || arg.startsWith(flag + "=")))) return;
|
|
22
|
+
if (resume.length) return resume.length === 1 && isClaudeSessionUuid(resume[0]) ? resume[0] : undefined;
|
|
23
|
+
const id = randomUUID();
|
|
24
|
+
nativeArgs.unshift("--session-id", id);
|
|
25
|
+
return id;
|
|
26
|
+
}
|
|
8
27
|
|
|
9
28
|
export async function runClaudeEntry(ctx: NativeCliEntryContext): Promise<void> {
|
|
10
29
|
const { args, cwd, stateDir, cliDir, unattendedEnv, projectConfig, fail } = ctx;
|
|
@@ -64,6 +83,8 @@ export async function runClaudeEntry(ctx: NativeCliEntryContext): Promise<void>
|
|
|
64
83
|
if (control?.instanceId) {
|
|
65
84
|
// Publish only the final launch's installed hook and effective permission flags.
|
|
66
85
|
launchRecord = { ...(ctx.instance ? { peer, executionCwd } : {}), instanceId: control.instanceId, launchId: process.env.AGENTHUB_LAUNCH_ID!, permissionHook: launch.permissionHook === true, hookPurpose: launch.hookPurpose, settingsFile: launch.settingsFile, launcherPid: process.pid, launcherSignature: processSignature(process.pid), unattended: launch.unattended === true };
|
|
86
|
+
const nativeSessionId = managedSession(launch.args);
|
|
87
|
+
if (nativeSessionId) launchRecord.nativeSessionId = nativeSessionId;
|
|
67
88
|
recordClaudeLaunch(stateDir, launchRecord);
|
|
68
89
|
cleanupStaleClaudeSettings(stateDir, previousLaunch);
|
|
69
90
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentVersionRow } from "./agents.ts";
|
|
2
|
+
import { Report, type Span } from "./console-state.ts";
|
|
3
|
+
import { grid, s } from "./sdlc-output.ts";
|
|
4
|
+
|
|
5
|
+
export function renderAgents(rows: readonly AgentVersionRow[], columns?: number, ascii = false): Span[][] {
|
|
6
|
+
if (!rows.length) return [[{ text: "no native agents" }]];
|
|
7
|
+
const items = rows.map(({ id, verdict, policy }) => [
|
|
8
|
+
s(id, "info"), s(verdict.version ?? "-"), s(verdict.state, verdict.ok ? "success" : "attention"),
|
|
9
|
+
s(policy), s(verdict.ok ? verdict.note ?? "" : verdict.reason),
|
|
10
|
+
]);
|
|
11
|
+
return new Report(columns, ascii).titled("ahub", "Agents")
|
|
12
|
+
.section("Versions", String(rows.length)).append(grid(["AGENT", "VERSION", "STATE", "POLICY", "DETAIL"], items, columns)).lines();
|
|
13
|
+
}
|
package/src/cli/agents.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { assessVersion, COMPAT, describe, isCompatId, readTrust, trustFile, writeTrust, type CompatId, type CompatVerdict } from "../adapters/compat.ts";
|
|
3
3
|
import { childEnv } from "../hub/child-process.ts";
|
|
4
4
|
import { withoutOrcaEnv } from "../hub/orca-env.ts";
|
|
5
|
+
import { Report, asciiMarkers, resolveColor, streamEnv } from "./console-state.ts";
|
|
6
|
+
import { outputWidth } from "./output.ts";
|
|
7
|
+
import { renderAgents } from "./agents-output.ts";
|
|
5
8
|
|
|
6
9
|
/** #691: what `ahub agents` and `ahub doctor` show for each gated native CLI. */
|
|
7
10
|
export interface AgentVersionRow { id: CompatId; executable?: string; verdict: CompatVerdict; policy: string }
|
|
@@ -82,23 +85,29 @@ export async function agentVersionsAsync(commands: Partial<Record<CompatId, read
|
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
export function runAgents(args: string[], commands: Partial<Record<CompatId, readonly string[]>>, fail: (message: string) => never): void {
|
|
88
|
+
const isTTY = !!process.stdout.isTTY;
|
|
89
|
+
const columns = outputWidth({ isTTY, columns: process.stdout.columns, COLUMNS: process.env.COLUMNS });
|
|
90
|
+
const ascii = asciiMarkers(process.env);
|
|
91
|
+
const color = resolveColor(undefined, streamEnv(isTTY), "ahub") === true;
|
|
92
|
+
const print = (report: Report) => console.log(report.render(color).join("\n"));
|
|
85
93
|
const [sub, id, version, ...rest] = args.filter(arg => arg !== "--json");
|
|
86
94
|
if (sub === "trust") {
|
|
87
95
|
const revoke = rest.includes("--revoke");
|
|
88
96
|
if (!isCompatId(id) || !version || rest.some(arg => arg !== "--revoke")) fail(`usage: ahub agents trust <${Object.keys(COMPAT).join("|")}> <version> [--revoke]`);
|
|
89
97
|
// The issue requires saying what trust covers before it is recorded.
|
|
90
|
-
if (!revoke)
|
|
98
|
+
if (!revoke) print(new Report(columns, ascii).titled("ahub", "Agent trust")
|
|
99
|
+
.section("Scope").note(`${COMPAT[id].label} ${version}: ${COMPAT[id].trustNote}`, "value"));
|
|
91
100
|
let rows;
|
|
92
101
|
try { rows = writeTrust(id, version, revoke); } catch (error) { fail((error as Error).message); }
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
const receipt = new Report(columns, ascii).titled("ahub", "Agent trust")
|
|
103
|
+
.section("Result").bullet("ok", revoke ? `revoked: ${id} ${version}` : `trusted on this machine: ${COMPAT[id].label} ${version}`)
|
|
104
|
+
.note(`${rows.length} trusted on this machine`).kv([["trust file", trustFile()]]);
|
|
105
|
+
receipt.next(`ahub agents trust ${id} ${version}${revoke ? "" : " --revoke"}`);
|
|
106
|
+
print(receipt);
|
|
95
107
|
return;
|
|
96
108
|
}
|
|
97
109
|
if (sub !== undefined) fail("usage: ahub agents [--json] | ahub agents trust <id> <version> [--revoke]");
|
|
98
110
|
const rows = agentVersions(commands);
|
|
99
111
|
if (args.includes("--json")) return console.log(JSON.stringify(rows.map(row => ({ id: row.id, executable: row.executable ?? null, ...row.verdict, policy: row.policy })), null, 2));
|
|
100
|
-
|
|
101
|
-
const v = row.verdict;
|
|
102
|
-
console.log(`${row.id.padEnd(13)} ${(v.version ?? "-").padEnd(10)} ${v.state.padEnd(9)} ${row.policy}${v.ok ? (v.note ? `\n${" ".repeat(14)}${v.note}` : "") : `\n${" ".repeat(14)}${v.reason}`}`);
|
|
103
|
-
}
|
|
112
|
+
print(new Report(columns, ascii).append(renderAgents(rows, columns, ascii)));
|
|
104
113
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { AskResult } from "../hub/ask.ts";
|
|
2
|
+
import type { QuestionRow } from "../hub/questions.ts";
|
|
3
|
+
import { Report, cellWidth, fit, terminalText, type Span } from "./console-state.ts";
|
|
4
|
+
|
|
5
|
+
const EVIDENCE_WIDTH = 150;
|
|
6
|
+
const lines = (text: string): Span[][] => text.split("\n").map(line => [{ text: line }]);
|
|
7
|
+
|
|
8
|
+
export function renderAskAnswer(view: AskResult & { saved?: string }, columns?: number, _now = Date.now(), ascii = false): Span[][] {
|
|
9
|
+
const report = new Report(columns, ascii).titled("ahub", "Ask").section("Answer")
|
|
10
|
+
.append(lines(terminalText(view.answer ?? `(${view.note})`)));
|
|
11
|
+
// Evidence alone must not look like an answer when the search found nothing.
|
|
12
|
+
if (view.evidence.length && (view.found || view.note)) {
|
|
13
|
+
report.section("Evidence");
|
|
14
|
+
for (const item of view.evidence) {
|
|
15
|
+
const text = item.text.slice(0, EVIDENCE_WIDTH);
|
|
16
|
+
report.append(lines(` ${item.id.padEnd(12)} ${cellWidth(text) > EVIDENCE_WIDTH ? fit(text, EVIDENCE_WIDTH) : text}`));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (view.pii) report.section("Privacy").append(lines("(PII is involved: shown here only, not saved anywhere)"));
|
|
20
|
+
if (view.saved) report.section("Saved").append(lines(view.saved));
|
|
21
|
+
return report.lines();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function renderQuestions(rows: readonly Pick<QuestionRow, "set" | "peer" | "private" | "questions">[], columns?: number, _now = Date.now(), ascii = false): Span[][] {
|
|
25
|
+
const report = new Report(columns, ascii);
|
|
26
|
+
if (!rows.length) return report.append(lines("no open questions")).lines();
|
|
27
|
+
report.titled("ahub", "Questions");
|
|
28
|
+
for (const row of rows) {
|
|
29
|
+
report.section(`${row.set} ${row.peer} asks${row.private ? " (private)" : ""}`);
|
|
30
|
+
for (const question of row.questions) {
|
|
31
|
+
report.append(lines(` ${question.id}: ${terminalText(String(question.prompt))}${question.multi ? " (choose any)" : ""}${question.allowOther ? " (or --other <text>)" : ""}`));
|
|
32
|
+
for (const option of question.options)
|
|
33
|
+
report.append(lines(` ${option.id} ${terminalText(String(option.label))}${option.description ? ` - ${terminalText(String(option.description))}` : ""}`));
|
|
34
|
+
}
|
|
35
|
+
report.next(`ahub answer ${row.set} ${row.questions.map(question => `${question.id}=${question.options[0]?.id ?? "<option>"}`).join(" ")}`);
|
|
36
|
+
}
|
|
37
|
+
return report.lines();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type Receipt =
|
|
41
|
+
| { kind: "answer"; set: string; actor?: string }
|
|
42
|
+
| { kind: "read"; id: string }
|
|
43
|
+
| { kind: "read-all"; marked: number }
|
|
44
|
+
| { kind: "unread-last"; unread: number };
|
|
45
|
+
|
|
46
|
+
export function renderAnswerReceipt(view: Receipt): Span[][] {
|
|
47
|
+
const report = new Report();
|
|
48
|
+
switch (view.kind) {
|
|
49
|
+
case "answer": return report.append(lines(`answered ${view.set}${view.actor === undefined ? "" : `; answered by ${terminalText(view.actor)} on the person's instruction`}`)).lines();
|
|
50
|
+
case "read": return report.append(lines(`marked ${view.id} read`)).lines();
|
|
51
|
+
case "read-all": return report.append(lines(`marked ${view.marked} ${view.marked === 1 ? "result" : "results"} read`)).lines();
|
|
52
|
+
case "unread-last": return report.append(lines(`marked ${view.unread} unread again`)).lines();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ResultRow { id: string; read: boolean; title: string; settledAt: number; ms: number }
|
|
57
|
+
export function renderResults(view: { rows: readonly ResultRow[]; unread: boolean; more: number }): Span[][] {
|
|
58
|
+
const report = new Report();
|
|
59
|
+
if (!view.rows.length) return report.append(lines(view.unread ? "no unread results" : "no results")).lines();
|
|
60
|
+
// Keep exactly one line per result, including the unread prefix used by terminal readers.
|
|
61
|
+
for (const row of view.rows) {
|
|
62
|
+
const time = new Date(Number(row.settledAt)).toISOString().replace("T", " ").slice(0, 16);
|
|
63
|
+
report.append(lines(`${row.read ? " " : "*"} ${row.id} ${terminalText(String(row.title))} ${time} ${Math.round(Number(row.ms) / 1000)}s${row.read ? "" : ` ahub results --read ${row.id}`}`));
|
|
64
|
+
}
|
|
65
|
+
if (view.more > 0) report.append(lines(`... and ${view.more} older unread; ahub results --read-all marks them all, or read the newest ones first`));
|
|
66
|
+
return report.lines();
|
|
67
|
+
}
|
package/src/cli/broker.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { BrokerStore, BrokerStoreError } from "../broker/store.ts";
|
|
|
4
4
|
import { decodeBase64url, RoomCryptoError } from "../rooms/crypto.ts";
|
|
5
5
|
import { startBroker, BrokerServerError, type BrokerOptions } from "../broker/server.ts";
|
|
6
6
|
import { warnLine } from "./warn-line.ts";
|
|
7
|
+
import { Report, asciiMarkers, terminalText } from "./console-state.ts";
|
|
7
8
|
|
|
8
9
|
export const BROKER_USAGE = "usage: ahub broker serve [--hostname <host>] [--port <0..65535>] [--public-url <ws[s]://host/>] [--owner <fingerprint>]... [--state-dir <dir>] | broker room drop <room> --yes [--state-dir <dir>]";
|
|
9
10
|
export function brokerOptions(args: readonly string[], stateDir: string): BrokerOptions {
|
|
@@ -36,16 +37,22 @@ export function brokerDropOptions(args: readonly string[], stateDir: string): {
|
|
|
36
37
|
return { room, stateDir: selected };
|
|
37
38
|
}
|
|
38
39
|
export async function runBrokerCommand(args: readonly string[], stateDir: string): Promise<void> {
|
|
40
|
+
const print = (report: Report) => { process.stdout.write(report.render(false).join("\n") + "\n"); };
|
|
39
41
|
if (args[0] === "room") {
|
|
40
42
|
const drop = brokerDropOptions(args, stateDir);
|
|
41
43
|
const store = await BrokerStore.open({ stateDir: drop.stateDir, create: false });
|
|
42
|
-
try {
|
|
44
|
+
try {
|
|
45
|
+
const { removed } = store.dropRoom(drop.room);
|
|
46
|
+
print(new Report(undefined, asciiMarkers(process.env)).titled("ahub", "Broker room")
|
|
47
|
+
.section("Result").bullet(removed ? "ok" : "unknown", `broker room ${removed ? "dropped" : "not found"}: ${drop.room}`));
|
|
48
|
+
}
|
|
43
49
|
finally { store.close(); }
|
|
44
50
|
return;
|
|
45
51
|
}
|
|
46
52
|
const options = brokerOptions(args, stateDir);
|
|
47
53
|
const broker = await startBroker(options);
|
|
48
|
-
|
|
54
|
+
// A machine-readable readiness line is intentionally unwrapped and uncolored.
|
|
55
|
+
print(new Report().header("ahub", `broker listening at ${terminalText(broker.publicUrl)} (ciphertext relay; application delivery is not acknowledged here)`));
|
|
49
56
|
const stop = () => { void broker.stop().catch(() => { process.exitCode = 1; warnLine("broker: stop failed"); }); };
|
|
50
57
|
process.once("SIGINT", stop); process.once("SIGTERM", stop);
|
|
51
58
|
try { await broker.closed; }
|
package/src/cli/console-state.ts
CHANGED
|
@@ -375,40 +375,11 @@ export function fit(value: unknown, columns: number): string {
|
|
|
375
375
|
* at whitespace, which they drop; only a word longer than a whole line is split. A tab counts as one space.
|
|
376
376
|
* Lines come out sanitized: a width counts the `> ` that sanitize() puts before a line starting like a hub header.
|
|
377
377
|
*/
|
|
378
|
-
const wrapGraphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
379
378
|
export function wrap(value: unknown, columns: number, hang = 4): string[] {
|
|
380
|
-
const text = terminalText(value);
|
|
381
379
|
// A bare chunk ending in "--- from" becomes a header marker when table padding follows it.
|
|
382
380
|
const quoteChunk = (chunk: string) => sanitize(chunk + " ").slice(0, -1);
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (segment !== Array.from(segment)[0]) { complex = true; break; }
|
|
386
|
-
}
|
|
387
|
-
if (Number.isFinite(columns) && columns >= 1 && !complex) return sharedWrap(text, columns, hang, quoteChunk);
|
|
388
|
-
// Retain code-point splitting and non-positive widths for legacy output: STAIxBWLB/cli-output#36.
|
|
389
|
-
const lines: string[] = [];
|
|
390
|
-
const half = Math.floor(columns / 2);
|
|
391
|
-
const width = (chunk: string) => Bun.stringWidth(quoteChunk(chunk));
|
|
392
|
-
for (const part of text.replace(/\t/g, " ").split("\n")) {
|
|
393
|
-
const indent = /^\s*/.exec(part)![0];
|
|
394
|
-
const lead = Math.min(Bun.stringWidth(indent), half);
|
|
395
|
-
const pad = " ".repeat(Math.min(lead + hang, half));
|
|
396
|
-
const first = lines.length;
|
|
397
|
-
let start = " ".repeat(lead);
|
|
398
|
-
let line = start;
|
|
399
|
-
const push = () => { lines.push(quoteChunk(line.trimEnd())); line = start = pad; };
|
|
400
|
-
for (const token of part.slice(indent.length).match(/\s+|\S+/g) ?? []) {
|
|
401
|
-
if (width(line + token) <= columns) { line += token; continue; }
|
|
402
|
-
if (line !== start) push();
|
|
403
|
-
if (/^\s/.test(token)) continue;
|
|
404
|
-
for (const char of token) {
|
|
405
|
-
if (line !== start && width(line + char) > columns) push();
|
|
406
|
-
line += char;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if (line !== start || lines.length === first) lines.push(quoteChunk(line.trimEnd()));
|
|
410
|
-
}
|
|
411
|
-
return lines;
|
|
381
|
+
// Code-point splitting keeps legacy output for every width, including the non-positive ones.
|
|
382
|
+
return sharedWrap(terminalText(value), columns, hang, quoteChunk, false, "codepoint");
|
|
412
383
|
}
|
|
413
384
|
export const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
414
385
|
/** `45s`, `12m`, `3h05m`, `2d03h`. */
|
|
@@ -1186,7 +1157,6 @@ function roomDetail(row: RoomStatusView): Record<string, unknown> {
|
|
|
1186
1157
|
* widest cell or header (Bun.stringWidth, at most a third of the width, wider cells cut with the marker); the last column
|
|
1187
1158
|
* takes the rest. One-shot callers may supply widths for already-wrapped cells; console defaults stay unchanged.
|
|
1188
1159
|
*/
|
|
1189
|
-
// Local tables retain styled separators, untouched final cells and narrow STAGE geometry: STAIxBWLB/cli-output#37.
|
|
1190
1160
|
export function table(head: string[], rows: Span[][], columns: number, explicitWidths?: readonly number[]): Span[][] {
|
|
1191
1161
|
const cap = Math.max(24, Math.floor(columns / 3));
|
|
1192
1162
|
const width = (cell: Span | undefined) => Bun.stringWidth(flat(cell?.text));
|
|
@@ -1201,13 +1171,16 @@ export function table(head: string[], rows: Span[][], columns: number, explicitW
|
|
|
1201
1171
|
}
|
|
1202
1172
|
widths[flexible] = Math.max(0, room());
|
|
1203
1173
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1174
|
+
// The hub owns the geometry above; the shared table lays the cells out. Caller-supplied widths wrap their headers.
|
|
1175
|
+
// Cells are cleaned the hub's way first: the package reads a bare CR as a line break, the hub drops it.
|
|
1176
|
+
const report = new SharedReport(undefined, false, { sanitize, sanitizeChunks: true, split: "codepoint" });
|
|
1177
|
+
// A STAGE table without TITLE has no flexible column: every cell, the last one too, is clipped and padded.
|
|
1178
|
+
report.table(head, rows.map(row => row.map(({ tone, text, ...cell }) => ({ ...cell, text: terminalText(text), ...(tone ? { style: tone } : {}) }))), flexible >= 0 ? flexible : head.length - 1, {
|
|
1179
|
+
headingStyle: "info", headerCase: "preserve", emptyCell: "blank", dropEmptyColumns: false, indent: 0,
|
|
1180
|
+
separatorStyle: "preceding", rawLastCell: flexible === head.length - 1, prewrapped: explicitWidths ? "body" : "all", widths,
|
|
1181
|
+
});
|
|
1182
|
+
// Drop the indent span and map styles back to console tones.
|
|
1183
|
+
return report.lines().map(line => line.slice(1).map(({ style, ...cell }) => ({ ...cell, ...(style ? { tone: style as Tone } : {}) })));
|
|
1211
1184
|
}
|
|
1212
1185
|
/** Keep the status/quota columns visible instead of clipping them behind optional peer metadata. */
|
|
1213
1186
|
function optionalTable(head: string[], rows: Span[][], columns: number, drop = ["DOING", "MODEL", "WIP", "PAUSE", "REVIEW", "AHUB", "LINK", "Q", "!", "MODE"]): Span[][] {
|
package/src/cli/launch.ts
CHANGED
|
@@ -112,7 +112,7 @@ export function cleanupStaleClaudeSettings(stateDir: string, previous: unknown,
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
export interface ClaudeLaunchRecord extends Record<string, unknown> {
|
|
115
|
-
instanceId: string; launchId: string; settingsFile?: string; launcherPid: number; launcherSignature?: string;
|
|
115
|
+
instanceId: string; launchId: string; nativeSessionId?: string; settingsFile?: string; launcherPid: number; launcherSignature?: string;
|
|
116
116
|
/** A claude-<name> instance (#450 I3); absent for the builtin claude peer, whose file keeps its original name. */
|
|
117
117
|
peer?: string;
|
|
118
118
|
/** Validated terminal instance root; absent for legacy/canonical launches. */
|