@jpcasabiancai/cayenne 0.5.0 → 0.5.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.
Files changed (2) hide show
  1. package/dist/cli.js +59 -10
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1507,10 +1507,10 @@ function assertClaudeDirExists(dir) {
1507
1507
  }
1508
1508
  }
1509
1509
  function claudeEnv(dir) {
1510
- return dir ? { CLAUDE_CONFIG_DIR: dir } : {};
1510
+ return { CLAUDE_CONFIG_DIR: dir };
1511
1511
  }
1512
1512
  function sessionClaudeConfigDir(sessionEnv, daemonEnv = process.env, home = homedir()) {
1513
- return sessionEnv?.CLAUDE_CONFIG_DIR ?? daemonEnv.CLAUDE_CONFIG_DIR ?? join(home, ".claude");
1513
+ return { ...daemonEnv, ...sessionEnv }.CLAUDE_CONFIG_DIR ?? join(home, ".claude");
1514
1514
  }
1515
1515
  function cliHash(text) {
1516
1516
  let hash = 0;
@@ -6847,6 +6847,31 @@ var init_handlers = __esm({
6847
6847
  }
6848
6848
  });
6849
6849
 
6850
+ // src/broadcast.ts
6851
+ import { REALTIME_CHANNEL_STATES } from "@supabase/supabase-js";
6852
+ function sendOnChannel(channel) {
6853
+ return (message, timeoutMs) => canPush(channel) ? channel.send(message, { timeout: timeoutMs }) : sendOverRest(channel, message, timeoutMs);
6854
+ }
6855
+ async function sendOverRest(channel, message, timeoutMs) {
6856
+ let sent;
6857
+ try {
6858
+ sent = await channel.httpSend(message.event, message.payload, { timeout: timeoutMs });
6859
+ } catch (err) {
6860
+ if (isAbort(err)) return "timed out";
6861
+ throw err;
6862
+ }
6863
+ if (sent.success) return "ok";
6864
+ throw new Error(`httpSend ${sent.status}: ${sent.error}`);
6865
+ }
6866
+ var isAbort, canPush;
6867
+ var init_broadcast = __esm({
6868
+ "src/broadcast.ts"() {
6869
+ "use strict";
6870
+ isAbort = (err) => err?.name === "AbortError";
6871
+ canPush = (channel) => channel.state === REALTIME_CHANNEL_STATES.joined && channel.socket.isConnected();
6872
+ }
6873
+ });
6874
+
6850
6875
  // src/documents/paths.ts
6851
6876
  import { realpathSync as realpathSync11 } from "fs";
6852
6877
  import { isAbsolute as isAbsolute12, join as join20, relative as relative6, sep as sep9 } from "path";
@@ -9760,6 +9785,7 @@ var init_manager = __esm({
9760
9785
  "src/sessions/manager.ts"() {
9761
9786
  "use strict";
9762
9787
  init_src();
9788
+ init_broadcast();
9763
9789
  init_claude_dir();
9764
9790
  init_config();
9765
9791
  init_paths2();
@@ -11573,7 +11599,7 @@ var init_manager = __esm({
11573
11599
  channel,
11574
11600
  relay: new SessionRelay({
11575
11601
  sessionId,
11576
- send: (message, timeout) => channel.send(message, { timeout }),
11602
+ send: sendOnChannel(channel),
11577
11603
  log: this.deps.log
11578
11604
  }),
11579
11605
  seq,
@@ -11944,10 +11970,10 @@ var init_manager = __esm({
11944
11970
  /**
11945
11971
  * Join `session:{id}` without waiting for it (chat latency follow-up, protocol §3).
11946
11972
  *
11947
- * The runner only sends on this channel, and realtime-js sends a channel that cannot push over
11948
- * its REST fallback, which the relay bounds. So a join that fails, or that nobody answers while
11949
- * the socket is down, costs relay subscribers the socket path and never the session: before
11950
- * this, it failed every `session.start` and every resume for as long as Realtime was down.
11973
+ * The runner only sends on this channel, and the relay sends a channel that cannot push over
11974
+ * REST (`sendOnChannel`), within the same bound. So a join that fails, or that nobody answers
11975
+ * while the socket is down, costs relay subscribers the socket path and never the session:
11976
+ * before this, it failed every `session.start` and every resume for as long as Realtime was down.
11951
11977
  *
11952
11978
  * A join that errors or times out is the client's to retry: it rejoins this instance on its own
11953
11979
  * timer while the socket is up, and as soon as the socket reopens. So the instance is kept, not
@@ -12492,7 +12518,21 @@ function createTerminalChannels({
12492
12518
  if (m.type === "output" && manager.relaySuppressed(terminalId)) return;
12493
12519
  const entry = joined.get(terminalId);
12494
12520
  if (!entry) return;
12495
- const sent = entry.channel.send({ type: "broadcast", event: TERMINAL_OUT_EVENT, payload: m }).then(
12521
+ if (m.type !== "exit" && !canPush(entry.channel)) {
12522
+ if (entry.skipped === 0) {
12523
+ log.warn(
12524
+ { terminalId, state: entry.channel.state },
12525
+ "terminal channel cannot push; skipping output until it can"
12526
+ );
12527
+ }
12528
+ entry.skipped += 1;
12529
+ return;
12530
+ }
12531
+ if (entry.skipped > 0 && canPush(entry.channel)) {
12532
+ log.info({ terminalId, skipped: entry.skipped }, "terminal channel pushing again");
12533
+ entry.skipped = 0;
12534
+ }
12535
+ const sent = entry.send({ type: "broadcast", event: TERMINAL_OUT_EVENT, payload: m }, BROADCAST_SEND_TIMEOUT_MS).then(
12496
12536
  (result) => {
12497
12537
  if (result !== "ok")
12498
12538
  log.warn({ terminalId, type: m.type, result }, "terminal frame not sent");
@@ -12541,7 +12581,12 @@ function createTerminalChannels({
12541
12581
  log.warn({ terminalId, err: messageOf5(err) }, "terminal message refused");
12542
12582
  }
12543
12583
  });
12544
- joined.set(terminalId, { channel, pending: /* @__PURE__ */ new Set() });
12584
+ joined.set(terminalId, {
12585
+ channel,
12586
+ send: sendOnChannel(channel),
12587
+ pending: /* @__PURE__ */ new Set(),
12588
+ skipped: 0
12589
+ });
12545
12590
  try {
12546
12591
  await new Promise((resolve5, reject) => {
12547
12592
  let settled = false;
@@ -12574,6 +12619,7 @@ var init_channels = __esm({
12574
12619
  "src/terminal/channels.ts"() {
12575
12620
  "use strict";
12576
12621
  init_src();
12622
+ init_broadcast();
12577
12623
  messageOf5 = (err) => err instanceof Error ? err.message : String(err);
12578
12624
  }
12579
12625
  });
@@ -12589,7 +12635,10 @@ function terminalEnv(base, { runnerOwner, claudeConfigDir }) {
12589
12635
  if (!runnerOwner && !MEMBER_ENV_KEYS.has(key) && !LOCALE_ENV.test(key)) continue;
12590
12636
  env[key] = value;
12591
12637
  }
12592
- if (runnerOwner && claudeConfigDir) env.CLAUDE_CONFIG_DIR = claudeConfigDir;
12638
+ if (runnerOwner) {
12639
+ if (claudeConfigDir) env.CLAUDE_CONFIG_DIR = claudeConfigDir;
12640
+ else delete env.CLAUDE_CONFIG_DIR;
12641
+ }
12593
12642
  return {
12594
12643
  ...env,
12595
12644
  TERM: "xterm-256color",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jpcasabiancai/cayenne",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "files": [
5
5
  "dist/cli.js"
6
6
  ],