@birdybeep/cli 0.8.1 → 0.8.2

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/index.cjs CHANGED
@@ -837,6 +837,7 @@ var import_node_crypto = require("crypto");
837
837
  var import_node_fs4 = require("fs");
838
838
  var import_node_os2 = require("os");
839
839
  var import_node_path2 = require("path");
840
+ var import_node_perf_hooks = require("perf_hooks");
840
841
  var import_agent_core5 = require("@birdybeep/agent-core");
841
842
  var import_claude_code4 = require("@birdybeep/claude-code");
842
843
  var import_codex3 = require("@birdybeep/codex");
@@ -857,6 +858,21 @@ var HOOK_HARNESSES = [
857
858
  "copilot"
858
859
  ];
859
860
  var STDIN_READ_TIMEOUT_MS = 3e3;
861
+ var LEGACY_HOOK_RUNTIME_BUDGET_MS = 9e3;
862
+ function hookRuntimeBudgetMs(configuredTimeoutSeconds) {
863
+ if (configuredTimeoutSeconds === void 0 || !Number.isFinite(configuredTimeoutSeconds) || configuredTimeoutSeconds <= 0) {
864
+ return LEGACY_HOOK_RUNTIME_BUDGET_MS;
865
+ }
866
+ const configuredBudgetMs = Math.max(1, Math.floor(configuredTimeoutSeconds * 1e3) - 1e3);
867
+ return Math.min(LEGACY_HOOK_RUNTIME_BUDGET_MS, configuredBudgetMs);
868
+ }
869
+ function configuredHookTimeoutSeconds(harness) {
870
+ if (harness === "claude") return (0, import_claude_code4.configuredClaudeHookTimeoutSeconds)();
871
+ if (harness === "codex") return (0, import_codex3.configuredCodexHookTimeoutSeconds)();
872
+ if (harness === "cursor") return (0, import_cursor4.configuredCursorHookTimeoutSeconds)();
873
+ if (harness === "copilot") return (0, import_copilot3.configuredCopilotHookTimeoutSeconds)();
874
+ return void 0;
875
+ }
860
876
  function withTimeout(promise, ms, fallback) {
861
877
  return new Promise((resolve) => {
862
878
  let settled = false;
@@ -977,15 +993,22 @@ function detachCodexNotifyWorker(payload) {
977
993
  }
978
994
  }
979
995
  function createHookCommand(deps = {}) {
980
- const makeSender = deps.createSender ?? ((baseUrl) => (0, import_agent_core5.createSender)({ baseUrl }));
996
+ const makeSender = deps.createSender ?? ((baseUrl, budgetMs) => (0, import_agent_core5.createSender)({
997
+ baseUrl,
998
+ timeoutMs: Math.min(import_agent_core5.DEFAULT_SEND_TIMEOUT_MS, budgetMs),
999
+ totalBudgetMs: budgetMs
1000
+ }));
981
1001
  const readStdin = deps.readStdin ?? readStdinDefault;
982
1002
  const stdinTimeoutMs = deps.stdinTimeoutMs ?? STDIN_READ_TIMEOUT_MS;
1003
+ const now = deps.now ?? (() => import_node_perf_hooks.performance.now());
1004
+ const readConfiguredHookTimeoutSeconds = deps.configuredHookTimeoutSeconds ?? configuredHookTimeoutSeconds;
983
1005
  const detachCodexNotify = deps.detachCodexNotify ?? detachCodexNotifyWorker;
984
1006
  return {
985
1007
  name: "hook",
986
1008
  summary: "Internal: normalize + send an event fired by a harness hook",
987
1009
  usage: "birdybeep hook <claude|codex|opencode|cursor|copilot> [copilot-event]",
988
1010
  run: async (ctx) => {
1011
+ const hookStartedAt = now();
989
1012
  const harness = ctx.args[0];
990
1013
  if (!isHarnessName(harness)) {
991
1014
  ctx.io.errline(`birdybeep hook: expected one of ${HOOK_HARNESSES.join("|")}`);
@@ -1051,7 +1074,10 @@ function createHookCommand(deps = {}) {
1051
1074
  );
1052
1075
  return EXIT.ERROR;
1053
1076
  }
1054
- const sender = makeSender(resolveApiUrl());
1077
+ const runtimeBudgetMs = hookRuntimeBudgetMs(readConfiguredHookTimeoutSeconds(harness));
1078
+ const elapsedMs = Math.max(0, now() - hookStartedAt);
1079
+ const budgetMs = Math.max(1, Math.min(import_agent_core5.DEFAULT_TOTAL_BUDGET_MS, runtimeBudgetMs - elapsedMs));
1080
+ const sender = makeSender(resolveApiUrl(), budgetMs);
1055
1081
  const result = await runHookCommand(harness, payload, sender, copilotEventName);
1056
1082
  ctx.io.result({
1057
1083
  harness: handler,
@@ -1212,7 +1238,7 @@ async function pairTokenPoll(apiUrl, deviceCode, fetchImpl, machineFingerprint,
1212
1238
  }
1213
1239
 
1214
1240
  // src/version.ts
1215
- var CLI_VERSION = "0.8.1".length > 0 ? "0.8.1" : "0.0.0";
1241
+ var CLI_VERSION = "0.8.2".length > 0 ? "0.8.2" : "0.0.0";
1216
1242
 
1217
1243
  // src/commands/setup.ts
1218
1244
  var import_claude_code5 = require("@birdybeep/claude-code");