@birdybeep/cli 0.8.1 → 0.8.3

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/dist/bin.cjs CHANGED
@@ -224,10 +224,164 @@ function surfaceRemedy(state, group) {
224
224
  // src/framework.ts
225
225
  var import_node_fs2 = require("fs");
226
226
  var import_agent_core2 = require("@birdybeep/agent-core");
227
+
228
+ // src/presentation.ts
229
+ var BIRD = [
230
+ " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
231
+ " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
232
+ " \u2588\u2588\u2588\u2588\u2594\u2594\u2594\u2594\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
233
+ " \u2588\u2588\u2588\u2588\u2588\u2588 \u25AA \u2588\u2588\u2588\u2588\u2588\u2588",
234
+ "\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
235
+ "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
236
+ " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
237
+ " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
238
+ " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
239
+ " \u2588\u2588 \u2588\u2588",
240
+ " \u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588"
241
+ ].join("\n");
242
+ function presentation(output, env = process.env) {
243
+ const terminal = output.isTTY === true && env.TERM !== "dumb";
244
+ const color = terminal && !env.NO_COLOR;
245
+ const lime = (text) => {
246
+ if (!color) return text;
247
+ const code = /^(truecolor|24bit)$/.test(env.COLORTERM ?? "") ? "38;2;198;242;78" : (env.TERM ?? "").includes("256color") ? "38;5;191" : "92";
248
+ return `\x1B[${code}m${text}\x1B[0m`;
249
+ };
250
+ return {
251
+ lime,
252
+ banner: () => terminal ? `
253
+ ${lime(BIRD)}
254
+
255
+ ` : "",
256
+ help: (text) => text.split("\n").map((line, i) => i === 0 || line.endsWith(":") ? lime(line) : line).join("\n")
257
+ };
258
+ }
259
+
260
+ // src/bird-animation.ts
261
+ function birdFrame(blink = false, lift = 0, pose = "rest") {
262
+ const rows = BIRD.split("\n");
263
+ if (pose === "inhale" || pose === "breathe") {
264
+ rows[8] = pose === "inhale" ? " \u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580" : " \u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580";
265
+ } else if (pose === "crouch" || pose === "land") {
266
+ rows.splice(7, 1);
267
+ rows.unshift("");
268
+ rows[7] = " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
269
+ rows[8] = " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
270
+ rows[9] = " \u2588\u2588 \u2588\u2588";
271
+ } else if (pose === "stretch") {
272
+ rows[4] = " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
273
+ rows[5] = " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
274
+ rows[6] = " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
275
+ rows[7] = " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
276
+ rows[9] = " \u2588\u2588 \u2588\u2588";
277
+ rows[10] = " \u2580\u2580 \u2580\u2580";
278
+ } else if (pose === "flight") {
279
+ rows[4] = "\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
280
+ rows[5] = "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2572\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
281
+ rows[6] = " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2572\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
282
+ rows[7] = " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
283
+ rows[9] = " \u2580\u2580 \u2580\u2580";
284
+ rows[10] = "";
285
+ }
286
+ if (blink)
287
+ rows[pose === "crouch" || pose === "land" ? 4 : 3] = rows[pose === "crouch" || pose === "land" ? 4 : 3].replace(" \u25AA ", " \u2501 ");
288
+ return [...Array(2 - lift).fill(""), ...rows, ...Array(lift).fill("")].join("\n");
289
+ }
290
+ var HOP = [
291
+ { pose: "crouch", lift: 0, ms: 180 },
292
+ { pose: "stretch", lift: 1, ms: 80 },
293
+ { pose: "flight", lift: 2, ms: 130 },
294
+ { pose: "flight", lift: 2, ms: 110 },
295
+ { pose: "stretch", lift: 1, ms: 90 },
296
+ { pose: "land", lift: 0, ms: 140 },
297
+ { pose: "inhale", lift: 0, ms: 120 },
298
+ { pose: "rest", lift: 0, ms: 180 }
299
+ ];
300
+ function createBirdAnimation(output, env = process.env) {
301
+ const allowed = () => output.isTTY === true && env.TERM !== "dumb" && !env.CI && env.BIRDYBEEP_ANIMATION !== "0" && (output.columns ?? 80) >= 26 && (output.rows ?? 40) >= 16;
302
+ const style = presentation(output, env);
303
+ let activeStop;
304
+ const begin = () => {
305
+ activeStop?.();
306
+ if (!allowed()) return void 0;
307
+ let stopped = false;
308
+ let timer;
309
+ const paint = (frame, rewind = false) => {
310
+ output.write(
311
+ (rewind ? "\x1B[13A" : "") + frame.split("\n").map((line) => `\r\x1B[2K${style.lime(line)}
312
+ `).join("")
313
+ );
314
+ };
315
+ const finish = (clear) => {
316
+ if (stopped) return;
317
+ stopped = true;
318
+ if (timer) clearInterval(timer);
319
+ process.off("exit", stop);
320
+ process.stdout.off("resize", resize);
321
+ if (clear) output.write("\x1B[13A" + "\r\x1B[2K\n".repeat(13) + "\x1B[13A\r");
322
+ activeStop = void 0;
323
+ };
324
+ const stop = () => finish(true);
325
+ const resize = () => {
326
+ stopped = true;
327
+ if (timer) clearInterval(timer);
328
+ process.off("exit", stop);
329
+ process.stdout.off("resize", resize);
330
+ activeStop = void 0;
331
+ };
332
+ process.once("exit", stop);
333
+ process.stdout.once("resize", resize);
334
+ activeStop = stop;
335
+ paint(birdFrame());
336
+ return {
337
+ stop,
338
+ settle: () => finish(false),
339
+ draw: (frame) => {
340
+ if (!stopped) {
341
+ paint(frame, true);
342
+ }
343
+ },
344
+ repeat: (callback) => {
345
+ timer = setInterval(callback, 140);
346
+ timer.unref();
347
+ }
348
+ };
349
+ };
350
+ return {
351
+ wait: () => {
352
+ const canvas = begin();
353
+ if (!canvas) return () => {
354
+ };
355
+ let tick = 0;
356
+ canvas.repeat(() => {
357
+ tick += 1;
358
+ const phase = tick % 22;
359
+ const pose = phase >= 8 && phase <= 10 ? "breathe" : phase >= 6 && phase <= 12 ? "inhale" : "rest";
360
+ canvas.draw(birdFrame(phase === 18, 0, pose));
361
+ });
362
+ return canvas.stop;
363
+ },
364
+ celebrate: async () => {
365
+ const canvas = begin();
366
+ if (!canvas) return;
367
+ try {
368
+ for (const { pose, lift, ms } of HOP) {
369
+ canvas.draw(birdFrame(pose === "land", lift, pose));
370
+ await new Promise((resolve) => setTimeout(resolve, ms));
371
+ }
372
+ } finally {
373
+ canvas.settle();
374
+ }
375
+ }
376
+ };
377
+ }
378
+
379
+ // src/framework.ts
227
380
  var EXIT = { OK: 0, ERROR: 1, USAGE: 2 };
228
- function createIo(json, stdout, stderr) {
381
+ function createIo(json, stdout, stderr, animate = false) {
229
382
  return {
230
383
  json,
384
+ ...!json && animate ? { bird: createBirdAnimation(stdout) } : {},
231
385
  line: (text) => {
232
386
  if (!json) stdout.write(`${text}
233
387
  `);
@@ -358,7 +512,8 @@ function renderCommandHelp(path, command) {
358
512
  }
359
513
  async function dispatch(argv, deps) {
360
514
  const { flags, rest } = parseGlobalFlags(argv);
361
- const io = createIo(flags.json, deps.stdout, deps.stderr);
515
+ const io = createIo(flags.json, deps.stdout, deps.stderr, !flags.nonInteractive);
516
+ const style = presentation(deps.stdout);
362
517
  if (deps.ensureConfig !== false) {
363
518
  try {
364
519
  (0, import_node_fs2.mkdirSync)((0, import_agent_core2.birdyBeepConfigDir)(), { recursive: true, mode: 448 });
@@ -386,7 +541,7 @@ async function dispatch(argv, deps) {
386
541
  }
387
542
  }
388
543
  if (rest.length === 0 || flags.help && command === void 0) {
389
- io.emit(renderRootHelp(deps.version, deps.commands), {
544
+ io.emit(style.banner() + style.help(renderRootHelp(deps.version, deps.commands)), {
390
545
  version: deps.version,
391
546
  commands: deps.commands.map((c) => ({
392
547
  name: c.name,
@@ -402,7 +557,7 @@ async function dispatch(argv, deps) {
402
557
  }
403
558
  const path = pathParts.join(" ");
404
559
  if (flags.help) {
405
- io.emit(renderCommandHelp(path, command), {
560
+ io.emit(style.help(renderCommandHelp(path, command)), {
406
561
  name: path,
407
562
  summary: command.summary,
408
563
  usage: command.usage,
@@ -424,6 +579,10 @@ async function dispatch(argv, deps) {
424
579
  }
425
580
  let code;
426
581
  try {
582
+ if (!flags.nonInteractive && (path === "setup" || path === "pair")) {
583
+ const banner = style.banner();
584
+ if (banner) io.line(banner.trimEnd());
585
+ }
427
586
  code = await command.run({ args, flags, io });
428
587
  } catch (err) {
429
588
  if (err instanceof MissingInputError) {
@@ -813,6 +972,7 @@ var import_node_crypto = require("crypto");
813
972
  var import_node_fs4 = require("fs");
814
973
  var import_node_os2 = require("os");
815
974
  var import_node_path2 = require("path");
975
+ var import_node_perf_hooks = require("perf_hooks");
816
976
  var import_agent_core5 = require("@birdybeep/agent-core");
817
977
  var import_claude_code4 = require("@birdybeep/claude-code");
818
978
  var import_codex3 = require("@birdybeep/codex");
@@ -833,6 +993,21 @@ var HOOK_HARNESSES = [
833
993
  "copilot"
834
994
  ];
835
995
  var STDIN_READ_TIMEOUT_MS = 3e3;
996
+ var LEGACY_HOOK_RUNTIME_BUDGET_MS = 9e3;
997
+ function hookRuntimeBudgetMs(configuredTimeoutSeconds) {
998
+ if (configuredTimeoutSeconds === void 0 || !Number.isFinite(configuredTimeoutSeconds) || configuredTimeoutSeconds <= 0) {
999
+ return LEGACY_HOOK_RUNTIME_BUDGET_MS;
1000
+ }
1001
+ const configuredBudgetMs = Math.max(1, Math.floor(configuredTimeoutSeconds * 1e3) - 1e3);
1002
+ return Math.min(LEGACY_HOOK_RUNTIME_BUDGET_MS, configuredBudgetMs);
1003
+ }
1004
+ function configuredHookTimeoutSeconds(harness) {
1005
+ if (harness === "claude") return (0, import_claude_code4.configuredClaudeHookTimeoutSeconds)();
1006
+ if (harness === "codex") return (0, import_codex3.configuredCodexHookTimeoutSeconds)();
1007
+ if (harness === "cursor") return (0, import_cursor4.configuredCursorHookTimeoutSeconds)();
1008
+ if (harness === "copilot") return (0, import_copilot3.configuredCopilotHookTimeoutSeconds)();
1009
+ return void 0;
1010
+ }
836
1011
  function withTimeout(promise, ms, fallback) {
837
1012
  return new Promise((resolve) => {
838
1013
  let settled = false;
@@ -953,15 +1128,22 @@ function detachCodexNotifyWorker(payload) {
953
1128
  }
954
1129
  }
955
1130
  function createHookCommand(deps = {}) {
956
- const makeSender = deps.createSender ?? ((baseUrl) => (0, import_agent_core5.createSender)({ baseUrl }));
1131
+ const makeSender = deps.createSender ?? ((baseUrl, budgetMs) => (0, import_agent_core5.createSender)({
1132
+ baseUrl,
1133
+ timeoutMs: Math.min(import_agent_core5.DEFAULT_SEND_TIMEOUT_MS, budgetMs),
1134
+ totalBudgetMs: budgetMs
1135
+ }));
957
1136
  const readStdin = deps.readStdin ?? readStdinDefault;
958
1137
  const stdinTimeoutMs = deps.stdinTimeoutMs ?? STDIN_READ_TIMEOUT_MS;
1138
+ const now = deps.now ?? (() => import_node_perf_hooks.performance.now());
1139
+ const readConfiguredHookTimeoutSeconds = deps.configuredHookTimeoutSeconds ?? configuredHookTimeoutSeconds;
959
1140
  const detachCodexNotify = deps.detachCodexNotify ?? detachCodexNotifyWorker;
960
1141
  return {
961
1142
  name: "hook",
962
1143
  summary: "Internal: normalize + send an event fired by a harness hook",
963
1144
  usage: "birdybeep hook <claude|codex|opencode|cursor|copilot> [copilot-event]",
964
1145
  run: async (ctx) => {
1146
+ const hookStartedAt = now();
965
1147
  const harness = ctx.args[0];
966
1148
  if (!isHarnessName(harness)) {
967
1149
  ctx.io.errline(`birdybeep hook: expected one of ${HOOK_HARNESSES.join("|")}`);
@@ -1027,7 +1209,10 @@ function createHookCommand(deps = {}) {
1027
1209
  );
1028
1210
  return EXIT.ERROR;
1029
1211
  }
1030
- const sender = makeSender(resolveApiUrl());
1212
+ const runtimeBudgetMs = hookRuntimeBudgetMs(readConfiguredHookTimeoutSeconds(harness));
1213
+ const elapsedMs = Math.max(0, now() - hookStartedAt);
1214
+ const budgetMs = Math.max(1, Math.min(import_agent_core5.DEFAULT_TOTAL_BUDGET_MS, runtimeBudgetMs - elapsedMs));
1215
+ const sender = makeSender(resolveApiUrl(), budgetMs);
1031
1216
  const result = await runHookCommand(harness, payload, sender, copilotEventName);
1032
1217
  ctx.io.result({
1033
1218
  harness: handler,
@@ -1188,7 +1373,7 @@ async function pairTokenPoll(apiUrl, deviceCode, fetchImpl, machineFingerprint,
1188
1373
  }
1189
1374
 
1190
1375
  // src/version.ts
1191
- var CLI_VERSION = "0.8.1".length > 0 ? "0.8.1" : "0.0.0";
1376
+ var CLI_VERSION = "0.8.3".length > 0 ? "0.8.3" : "0.0.0";
1192
1377
 
1193
1378
  // src/commands/setup.ts
1194
1379
  var import_claude_code5 = require("@birdybeep/claude-code");
@@ -1741,32 +1926,39 @@ function createPairingCommand(verb, deps = {}) {
1741
1926
  let lastBeat = startedAt;
1742
1927
  let paired;
1743
1928
  let terminal;
1744
- for (; ; ) {
1745
- const nowMs = clock();
1746
- if (nowMs >= deadline) break;
1747
- await sleep(intervalMs);
1748
- const poll = await pairTokenPoll(
1749
- apiUrl,
1750
- start.device_code,
1751
- fetchImpl,
1752
- identity.fingerprintHash,
1753
- codeVerifier
1754
- // PKCE proof-of-possession (dgxd) — sent on every poll
1755
- );
1756
- if (poll.status === "paired") {
1757
- paired = poll;
1758
- break;
1759
- }
1760
- if (poll.status === "error" && !poll.retryable) {
1761
- terminal = poll;
1762
- break;
1763
- }
1764
- if (!ctx.flags.json && nowMs - lastBeat >= HEARTBEAT_MS) {
1765
- ctx.io.line(
1766
- poll.status === "error" ? ` Backend unavailable (${poll.message}); retrying.` : " Waiting for approval in the BirdyBeep app."
1929
+ let stopBird = ctx.io.bird?.wait();
1930
+ try {
1931
+ for (; ; ) {
1932
+ const nowMs = clock();
1933
+ if (nowMs >= deadline) break;
1934
+ await sleep(intervalMs);
1935
+ const poll = await pairTokenPoll(
1936
+ apiUrl,
1937
+ start.device_code,
1938
+ fetchImpl,
1939
+ identity.fingerprintHash,
1940
+ codeVerifier
1941
+ // PKCE proof-of-possession (dgxd) — sent on every poll
1767
1942
  );
1768
- lastBeat = nowMs;
1943
+ if (poll.status === "paired") {
1944
+ paired = poll;
1945
+ break;
1946
+ }
1947
+ if (poll.status === "error" && !poll.retryable) {
1948
+ terminal = poll;
1949
+ break;
1950
+ }
1951
+ if (!ctx.flags.json && nowMs - lastBeat >= HEARTBEAT_MS) {
1952
+ stopBird?.();
1953
+ ctx.io.line(
1954
+ poll.status === "error" ? ` Backend unavailable (${poll.message}); retrying.` : " Waiting for approval in the BirdyBeep app."
1955
+ );
1956
+ lastBeat = nowMs;
1957
+ stopBird = ctx.io.bird?.wait();
1958
+ }
1769
1959
  }
1960
+ } finally {
1961
+ stopBird?.();
1770
1962
  }
1771
1963
  if (terminal !== void 0) {
1772
1964
  ctx.io.result({ paired: false, reason: terminal.code });
@@ -1814,6 +2006,7 @@ function createPairingCommand(verb, deps = {}) {
1814
2006
  const humanSuffix = approvedBy !== void 0 ? ` to ${approvedBy}` : "";
1815
2007
  const discardedSuffix = discarded > 0 ? ` Discarded ${discarded} event(s) queued before pairing. They will not produce notifications.` : "";
1816
2008
  const nextStep = chain === void 0 ? " Run `birdybeep setup` to install coding-agent hooks." : "";
2009
+ await ctx.io.bird?.celebrate();
1817
2010
  ctx.io.line(`\u2713 Paired${humanSuffix}.${nextStep}${discardedSuffix}`);
1818
2011
  const report = chain !== void 0 ? await runSetupChain(ctx, setupDeps, pairFlags) : void 0;
1819
2012
  ctx.io.result({