@conveno/cli 0.2.0-rc.6 → 0.2.0-rc.8

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.
@@ -40,11 +40,16 @@ async function findHostPid(ctx, client, cli, local) {
40
40
  * the message on stderr (Claude Code's `asyncRewake`). They stop on their own when the host CLI
41
41
  * exits, the session goes offline, or a newer listener replaces them.
42
42
  */
43
+ /** After a timeout, the hook gets this many more timeouts' worth of time to finish recording. */
44
+ const FINISH_GRACE_FACTOR = 2;
45
+ /** How long before the hook's timeout its messages count as too late to print. */
46
+ const DEADLINE_MARGIN_MS = 300;
43
47
  async function runHook(ctx, argv) {
44
48
  const [cli, event] = argv;
45
49
  const adapter = ctx.adapters.find((a) => a.cli === cli);
46
50
  if (!adapter || !event) return 0;
47
51
  const listener = adapter.listenEvents?.includes(event) === true;
52
+ const deadline = listener ? void 0 : Date.now() + ctx.hookTimeoutMs - DEADLINE_MARGIN_MS;
48
53
  let client;
49
54
  let timer;
50
55
  const early = ctx.hostLookup ? void 0 : ctx.ancestry(HOOK_ANCESTRY_TIMEOUT_MS);
@@ -65,7 +70,8 @@ async function runHook(ctx, argv) {
65
70
  client,
66
71
  hostPid,
67
72
  cli: adapter.cli,
68
- isAlive: ctx.isAlive
73
+ isAlive: ctx.isAlive,
74
+ ...deadline === void 0 ? {} : { deadline }
69
75
  });
70
76
  })();
71
77
  const timeout = listener ? new Promise(() => void 0) : new Promise((resolve) => {
@@ -74,6 +80,7 @@ async function runHook(ctx, argv) {
74
80
  let code = 0;
75
81
  try {
76
82
  const out = await Promise.race([work, timeout]);
83
+ if (out === NOTHING && !listener) await Promise.race([work.catch(() => void 0), new Promise((r) => setTimeout(r, ctx.hookTimeoutMs * FINISH_GRACE_FACTOR))]);
77
84
  if (out.stdout) ctx.out(out.stdout.endsWith("\n") ? out.stdout : `${out.stdout}\n`);
78
85
  if (listener && out.stderr) ctx.err(out.stderr.endsWith("\n") ? out.stderr : `${out.stderr}\n`);
79
86
  if (listener) code = out.exitCode;
@@ -0,0 +1 @@
1
+ export { i as runHookEntry } from "./hook-entry-pHJioNgN.js";