@staix/agent-hub 0.49.0 → 0.50.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.
@@ -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
- let complex = false;
384
- if (/[^\p{ASCII}]/u.test(text)) for (const { segment } of wrapGraphemes.segment(text)) {
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
- const headerCells = explicitWidths ? head.map((h, i) => wrap(h, Math.max(1, widths[i]!), 0)) : undefined;
1205
- const headers = headerCells ? Array.from({ length: Math.max(...headerCells.map(cell => cell.length)) }, (_, n) => head.map((_, i) => span(headerCells[i]![n] ?? "", "info"))) : [head.map(h => span(h, "info"))];
1206
- return [...headers, ...rows].map(row => row.map((cell, i) => {
1207
- if (i === head.length - 1 && flexible === i) return cell;
1208
- const text = fit(cell.text, widths[i]!);
1209
- return { ...cell, text: text + " ".repeat(Math.max(0, widths[i]! - Bun.stringWidth(text)) + (i === head.length - 1 ? 0 : 2)) };
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/help.ts CHANGED
@@ -220,10 +220,10 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
220
220
  ["ahub facts --hook", "turn-free facts as a Claude Code PreToolUse, PostToolUse and Stop hook (issue #108); never blocks"],
221
221
  ]],
222
222
  ["Dashboard", [
223
- ["ahub ui [--no-open]", "open the local dashboard with configured attention character (or print its one-time link)"],
224
- ["ahub ui --settings [--no-open]", "human only: open it with a settings session, which for 15 minutes may change permission modes, routing, start settings and structural config"],
225
- ["ahub ui --all [--no-open]", "open the unified project dashboard"],
226
- ["ahub ui --all --stop", "stop only the dashboard manager"],
223
+ ["ahub ui [--no-open [--json]]", "open the local dashboard with configured attention character (or print its one-time link; --no-open --json prints readiness)"],
224
+ ["ahub ui --settings [--no-open [--json]]", "human only: open it with a settings session, which for 15 minutes may change permission modes, routing, start settings and structural config"],
225
+ ["ahub ui --all [--no-open [--json]]", "open the unified project dashboard; --no-open --json prints readiness"],
226
+ ["ahub ui --all --stop [--json]", "stop only the dashboard manager; --json prints a stop receipt"],
227
227
  ["ahub manager", "internal: the dashboard manager process that ahub ui --all starts"],
228
228
  ]],
229
229
  ];
package/src/cli/main.ts CHANGED
@@ -273,7 +273,7 @@ const projectConfig = () => {
273
273
  return config;
274
274
  };
275
275
  const stateDir = selected.stateDir;
276
- var operationalAuditReady=false, operationalRefusalRecorded=false;
276
+ var operationalAuditReady=false, operationalRefusalRecorded=false, jsonBlockers=false;
277
277
  const caller = declaredInstances ? detectCliIdentity(process.env, declaredInstances) : unboundCaller;
278
278
  const commandLabel = cmd === "guidance" && args[0] === "probe" && ["register", "start", "show", "receipts", "cancel"].includes(args[1] ?? "")
279
279
  ? `guidance probe ${args[1]}` : cliCommandLabel(cmd, args, projectCatalog);
@@ -600,7 +600,8 @@ function warn(message: string, next?: string): void { warnLine(message, next); }
600
600
  */
601
601
  function fail(message: string, refusalAudited=false, authorityRefused?:boolean, next?: string): never {
602
602
  if(operationalAuditReady && authorityRefused!==false){if(refusalAudited)operationalRefusalRecorded=true;if(!operationalRefusalRecorded)audit("refused");}
603
- console.error(errorLines(message, next, !!process.stderr.isTTY, asciiMarkers(process.env, process.argv.includes("--ascii"))).join("\n"));
603
+ if (jsonBlockers) console.error(errorLines(`blocker: ${terminalText(message)}`, undefined, false, false).join("\n"));
604
+ else console.error(errorLines(message, next, !!process.stderr.isTTY, asciiMarkers(process.env, process.argv.includes("--ascii"))).join("\n"));
604
605
  process.exit(failureExitCode(message));
605
606
  }
606
607
  function operationalIncomplete(result: {complete?:boolean;incompleteReason?:unknown;truncated?:boolean}, history: "log"|"event"): void {
@@ -1181,17 +1182,25 @@ const commands: Record<string, (receiptOutput?: SdlcReceiptOutput) => Promise<vo
1181
1182
  },
1182
1183
 
1183
1184
  ui: async () => {
1184
- if (args.some((arg) => !["--no-open", "--all", "--stop", "--settings"].includes(arg))) fail("usage: ahub ui [--settings] [--no-open] | --all [--no-open] | --all --stop");
1185
+ const display = { json: args.includes("--json") };
1186
+ jsonBlockers = display.json;
1187
+ const all = args.includes("--all");
1188
+ const stop = args.includes("--stop"), noOpen = args.includes("--no-open");
1189
+ const invalid = args.some(arg => !["--no-open", "--all", "--stop", "--settings", "--json"].includes(arg));
1190
+ if (display.json && (invalid || (stop ? !all || noOpen : !noOpen)))
1191
+ fail("usage: ahub ui [--settings] [--no-open [--json]] | --all [--no-open [--json]] | --all --stop [--json]");
1192
+ if (invalid) fail("usage: ahub ui [--settings] [--no-open] | --all [--no-open] | --all --stop");
1185
1193
  // #269: a settings session belongs to one project's hub; the unified dashboard stays an ordinary session.
1186
1194
  const settings = args.includes("--settings");
1187
- if (settings && args.includes("--all")) fail("ahub ui --settings opens one project's dashboard; run it without --all");
1188
- if (args.includes("--stop")) {
1189
- if (!args.includes("--all") || args.includes("--no-open")) fail("usage: ahub ui --all --stop");
1195
+ if (settings && all) fail("ahub ui --settings opens one project's dashboard; run it without --all");
1196
+ if (stop) {
1197
+ if (!all || noOpen) fail("usage: ahub ui --all --stop");
1190
1198
  await stopManager();
1199
+ if (display.json) return console.log(JSON.stringify({ ok: true, stopped: true }));
1191
1200
  return console.log("dashboard manager stopped; project hubs were kept running");
1192
1201
  }
1193
1202
  let url: string;
1194
- if (args.includes("--all")) url = await openManager({ liveTest: !!delegatedPeer });
1203
+ if (all) url = await openManager({ liveTest: !!delegatedPeer });
1195
1204
  else {
1196
1205
  const hub = await connect();
1197
1206
  try {
@@ -1204,6 +1213,9 @@ const commands: Record<string, (receiptOutput?: SdlcReceiptOutput) => Promise<vo
1204
1213
  } finally { hub.close(); }
1205
1214
  }
1206
1215
  if (settings) warn("Settings session: for 15 minutes this dashboard session may change permission modes, routing and start settings");
1216
+ if (display.json) return console.log(JSON.stringify({
1217
+ ok: true, url, origin: new URL(url).origin, mode: all ? "manager" : "hub", settings,
1218
+ }));
1207
1219
  if (args.includes("--no-open")) return console.log(url);
1208
1220
  const opener = process.platform === "darwin" ? "open" : "xdg-open";
1209
1221
  const opened = spawnSync(opener, [url], { stdio: "ignore", timeout: 10_000 });