@sjawhar/pi-envoy 16.22.0 → 16.24.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.
package/dist/dispatch.js CHANGED
@@ -17460,9 +17460,12 @@ async function tryExec(exec, file, args, cwd, limitMs) {
17460
17460
  exec(file, args, { cwd, signal: controller.signal }),
17461
17461
  expired.promise
17462
17462
  ]);
17463
- return answer?.stdout ?? null;
17463
+ if (answer === null) {
17464
+ return { failure: "timedOut", ok: false };
17465
+ }
17466
+ return { ok: true, stdout: answer.stdout };
17464
17467
  } catch {
17465
- return null;
17468
+ return { failure: "refused", ok: false };
17466
17469
  } finally {
17467
17470
  clearTimeout(timer);
17468
17471
  }
@@ -17503,13 +17506,13 @@ function parseGitHubRemoteUrl(url) {
17503
17506
  return null;
17504
17507
  }
17505
17508
  async function resolveCwdRepo(cwd, exec) {
17506
- const jjOutput = await tryExec(exec, "jj", ["git", "remote", "list"], cwd, REMOTE_LOOKUP_MS);
17507
- if (jjOutput !== null) {
17508
- const url = selectRemoteUrl(parseRemoteList(jjOutput));
17509
+ const remoteList = await tryExec(exec, "jj", ["git", "remote", "list"], cwd, REMOTE_LOOKUP_MS);
17510
+ if (remoteList.ok) {
17511
+ const url = selectRemoteUrl(parseRemoteList(remoteList.stdout));
17509
17512
  return url ? parseGitHubRemoteUrl(url) : null;
17510
17513
  }
17511
- const originUrl = await tryExec(exec, "git", ["remote", "get-url", "origin"], cwd, REMOTE_LOOKUP_MS);
17512
- return originUrl ? parseGitHubRemoteUrl(originUrl) : null;
17514
+ const originRemote = await tryExec(exec, "git", ["remote", "get-url", "origin"], cwd, REMOTE_LOOKUP_MS);
17515
+ return originRemote.ok ? parseGitHubRemoteUrl(originRemote.stdout) : null;
17513
17516
  }
17514
17517
  async function resolveOrigin(env, exec, cwd) {
17515
17518
  const origin = {
@@ -17518,8 +17521,8 @@ async function resolveOrigin(env, exec, cwd) {
17518
17521
  };
17519
17522
  const pane = env.TMUX_PANE;
17520
17523
  if (pane) {
17521
- const output = await tryExec(exec, "tmux", ["display-message", "-p", "-t", pane, "#S:#I.#P #{pane_id}"], cwd, TMUX_PANE_LOOKUP_MS);
17522
- const [target, paneId] = output?.trim().split(" ") ?? [];
17524
+ const answer = await tryExec(exec, "tmux", ["display-message", "-p", "-t", pane, "#S:#I.#P #{pane_id}"], cwd, TMUX_PANE_LOOKUP_MS);
17525
+ const [target, paneId] = answer.ok ? answer.stdout.trim().split(" ") : [];
17523
17526
  if (target)
17524
17527
  origin.tmux = target;
17525
17528
  if (paneId)
@@ -25920,12 +25923,17 @@ function dispatchTarget(env, config) {
25920
25923
  var DEFAULT_ENVOY_URL = "http://127.0.0.1:9020";
25921
25924
  var DEFAULT_HEARTBEAT_MS = SESSION_HEARTBEAT_MS;
25922
25925
  var MIN_PASS_DEADLINE_MS = 30000;
25926
+ var DEFAULT_TMUX_PLACE_CACHE_MS = 30000;
25923
25927
  var MIN_INTERVAL_MS = 25;
25924
25928
  var MAX_INTERVAL_MS = 2147483647;
25925
25929
  function namedInterval(raw) {
25926
25930
  const parsed = Number(raw);
25927
25931
  return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
25928
25932
  }
25933
+ function resolvedInterval(raw, fallback) {
25934
+ const named = namedInterval(raw);
25935
+ return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
25936
+ }
25929
25937
  function natsSeedFromEnvironment(env) {
25930
25938
  const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
25931
25939
  if (file !== undefined) {
@@ -26016,8 +26024,8 @@ function envoySettings(env, config, options = {}) {
26016
26024
  inbound = { off: messageFor(error) };
26017
26025
  }
26018
26026
  }
26019
- const namedHeartbeatMs = namedInterval(env.ENVOY_HEARTBEAT_MS);
26020
- const heartbeatMs = namedHeartbeatMs === undefined ? DEFAULT_HEARTBEAT_MS : Math.min(Math.max(namedHeartbeatMs, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
26027
+ const heartbeatMs = resolvedInterval(env.ENVOY_HEARTBEAT_MS, DEFAULT_HEARTBEAT_MS);
26028
+ const tmuxPlaceCacheMs = resolvedInterval(env.ENVOY_TMUX_PLACE_CACHE_MS, DEFAULT_TMUX_PLACE_CACHE_MS);
26021
26029
  const namedPassDeadlineMs = namedInterval(env.ENVOY_PASS_DEADLINE_MS);
26022
26030
  return {
26023
26031
  enabled: true,
@@ -26025,6 +26033,7 @@ function envoySettings(env, config, options = {}) {
26025
26033
  credential,
26026
26034
  inbound,
26027
26035
  heartbeatMs,
26036
+ tmuxPlaceCacheMs,
26028
26037
  passDeadlineMs: Math.min(Math.max(namedPassDeadlineMs ?? MIN_PASS_DEADLINE_MS, heartbeatMs), MAX_INTERVAL_MS),
26029
26038
  passDeadlineRaisedFrom: namedPassDeadlineMs !== undefined && namedPassDeadlineMs < heartbeatMs ? namedPassDeadlineMs : undefined
26030
26039
  };
@@ -26365,6 +26374,7 @@ function createEnvoyClient(config) {
26365
26374
  ...input.delivery === undefined ? {} : { delivery: input.delivery },
26366
26375
  ...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID },
26367
26376
  host: machineID(),
26377
+ ...input.place === undefined ? {} : { tmux_place: input.place },
26368
26378
  plugin: input.plugin.name,
26369
26379
  plugin_version: input.plugin.version
26370
26380
  }, { actingSession: input.sessionID }))),
package/dist/envoy.js CHANGED
@@ -29687,6 +29687,7 @@ function answerNotKept(status, replayed, body) {
29687
29687
  var IDEMPOTENCY_KEY_TTL_MS = 24 * 60 * 60 * 1000;
29688
29688
  var IDEMPOTENCY_LEASE_MS = 60 * 1000;
29689
29689
  var DELIVERY_DUPLICATE_WINDOW_MS = 72 * 60 * 60 * 1000;
29690
+ var TMUX_LAYOUT_MAX = 2000;
29690
29691
  var IssueDeployedEventPayloadSchema = strictObject({
29691
29692
  repo: string2(),
29692
29693
  number: number2().int().positive(),
@@ -37808,6 +37809,7 @@ function fileBearer(bearer, url, section, env, commands = "run") {
37808
37809
  var DEFAULT_ENVOY_URL = "http://127.0.0.1:9020";
37809
37810
  var DEFAULT_HEARTBEAT_MS = SESSION_HEARTBEAT_MS;
37810
37811
  var MIN_PASS_DEADLINE_MS = 30000;
37812
+ var DEFAULT_TMUX_PLACE_CACHE_MS = 30000;
37811
37813
  var MIN_INTERVAL_MS = 25;
37812
37814
  var MAX_INTERVAL_MS = 2147483647;
37813
37815
  var REGISTRATION_SETTLE_MS = 5000;
@@ -37821,6 +37823,10 @@ function namedInterval(raw) {
37821
37823
  const parsed = Number(raw);
37822
37824
  return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
37823
37825
  }
37826
+ function resolvedInterval(raw, fallback) {
37827
+ const named = namedInterval(raw);
37828
+ return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
37829
+ }
37824
37830
  function natsSeedFromEnvironment(env) {
37825
37831
  const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
37826
37832
  if (file !== undefined) {
@@ -37911,8 +37917,8 @@ function envoySettings(env, config, options = {}) {
37911
37917
  inbound = { off: messageFor(error) };
37912
37918
  }
37913
37919
  }
37914
- const namedHeartbeatMs = namedInterval(env.ENVOY_HEARTBEAT_MS);
37915
- const heartbeatMs = namedHeartbeatMs === undefined ? DEFAULT_HEARTBEAT_MS : Math.min(Math.max(namedHeartbeatMs, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
37920
+ const heartbeatMs = resolvedInterval(env.ENVOY_HEARTBEAT_MS, DEFAULT_HEARTBEAT_MS);
37921
+ const tmuxPlaceCacheMs = resolvedInterval(env.ENVOY_TMUX_PLACE_CACHE_MS, DEFAULT_TMUX_PLACE_CACHE_MS);
37916
37922
  const namedPassDeadlineMs = namedInterval(env.ENVOY_PASS_DEADLINE_MS);
37917
37923
  return {
37918
37924
  enabled: true,
@@ -37920,6 +37926,7 @@ function envoySettings(env, config, options = {}) {
37920
37926
  credential,
37921
37927
  inbound,
37922
37928
  heartbeatMs,
37929
+ tmuxPlaceCacheMs,
37923
37930
  passDeadlineMs: Math.min(Math.max(namedPassDeadlineMs ?? MIN_PASS_DEADLINE_MS, heartbeatMs), MAX_INTERVAL_MS),
37924
37931
  passDeadlineRaisedFrom: namedPassDeadlineMs !== undefined && namedPassDeadlineMs < heartbeatMs ? namedPassDeadlineMs : undefined
37925
37932
  };
@@ -38246,6 +38253,7 @@ function createEnvoyClient(config) {
38246
38253
  ...input.delivery === undefined ? {} : { delivery: input.delivery },
38247
38254
  ...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID },
38248
38255
  host: machineID(),
38256
+ ...input.place === undefined ? {} : { tmux_place: input.place },
38249
38257
  plugin: input.plugin.name,
38250
38258
  plugin_version: input.plugin.version
38251
38259
  }, { actingSession: input.sessionID }))),
@@ -39783,6 +39791,88 @@ function activeDispatchSettings(resolution) {
39783
39791
  return null;
39784
39792
  }
39785
39793
 
39794
+ // ../envoy-client/src/dispatch-cwd.ts
39795
+ import { execFile } from "child_process";
39796
+ import { promisify } from "util";
39797
+ var execFileAsync = promisify(execFile);
39798
+ var defaultExec = (file, args, { cwd, signal }) => {
39799
+ const call = execFileAsync(file, args, { cwd, signal });
39800
+ const kill = () => call.child.kill("SIGKILL");
39801
+ if (signal.aborted)
39802
+ kill();
39803
+ else
39804
+ signal.addEventListener("abort", kill, { once: true });
39805
+ return call;
39806
+ };
39807
+ var REMOTE_LOOKUP_MS = 5000;
39808
+ var TMUX_PANE_LOOKUP_MS = 1000;
39809
+ async function tryExec(exec, file, args, cwd, limitMs) {
39810
+ const controller = new AbortController;
39811
+ const expired = Promise.withResolvers();
39812
+ const timer = setTimeout(() => {
39813
+ controller.abort();
39814
+ expired.resolve(null);
39815
+ }, limitMs);
39816
+ try {
39817
+ const answer = await Promise.race([
39818
+ exec(file, args, { cwd, signal: controller.signal }),
39819
+ expired.promise
39820
+ ]);
39821
+ if (answer === null) {
39822
+ return { failure: "timedOut", ok: false };
39823
+ }
39824
+ return { ok: true, stdout: answer.stdout };
39825
+ } catch {
39826
+ return { failure: "refused", ok: false };
39827
+ } finally {
39828
+ clearTimeout(timer);
39829
+ }
39830
+ }
39831
+ function parseRemoteList(stdout) {
39832
+ const remotes = new Map;
39833
+ for (const line of stdout.split(`
39834
+ `)) {
39835
+ const trimmed = line.trim();
39836
+ if (!trimmed)
39837
+ continue;
39838
+ const match = trimmed.match(/^(\S+)\s+(\S+)/);
39839
+ const [, name, url] = match ?? [];
39840
+ if (name && url)
39841
+ remotes.set(name, url);
39842
+ }
39843
+ return remotes;
39844
+ }
39845
+ function selectRemoteUrl(remotes) {
39846
+ const origin = remotes.get("origin");
39847
+ if (origin)
39848
+ return origin;
39849
+ const candidates = [...remotes.entries()].filter(([name]) => name !== "upstream");
39850
+ return candidates.length === 1 ? candidates[0]?.[1] ?? null : null;
39851
+ }
39852
+ var GITHUB_REMOTE_PATTERNS = [
39853
+ /^https:\/\/(?:[^@/\s]+@)?github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
39854
+ /^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
39855
+ /^ssh:\/\/git@github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i
39856
+ ];
39857
+ function parseGitHubRemoteUrl(url) {
39858
+ const trimmed = url.trim();
39859
+ for (const pattern of GITHUB_REMOTE_PATTERNS) {
39860
+ const match = trimmed.match(pattern);
39861
+ if (match)
39862
+ return canonicalRepo(match[1] ?? "", match[2] ?? "");
39863
+ }
39864
+ return null;
39865
+ }
39866
+ async function resolveCwdRepo(cwd, exec) {
39867
+ const remoteList = await tryExec(exec, "jj", ["git", "remote", "list"], cwd, REMOTE_LOOKUP_MS);
39868
+ if (remoteList.ok) {
39869
+ const url = selectRemoteUrl(parseRemoteList(remoteList.stdout));
39870
+ return url ? parseGitHubRemoteUrl(url) : null;
39871
+ }
39872
+ const originRemote = await tryExec(exec, "git", ["remote", "get-url", "origin"], cwd, REMOTE_LOOKUP_MS);
39873
+ return originRemote.ok ? parseGitHubRemoteUrl(originRemote.stdout) : null;
39874
+ }
39875
+
39786
39876
  // ../envoy-client/src/dispatch-first.ts
39787
39877
  import { readFileSync as readFileSync4 } from "fs";
39788
39878
  import { join as join3 } from "path";
@@ -39993,84 +40083,6 @@ import {
39993
40083
  } from "fs";
39994
40084
  import { join as join6 } from "path";
39995
40085
 
39996
- // ../envoy-client/src/dispatch-cwd.ts
39997
- import { execFile } from "child_process";
39998
- import { promisify } from "util";
39999
- var execFileAsync = promisify(execFile);
40000
- var defaultExec = (file, args, { cwd, signal }) => {
40001
- const call = execFileAsync(file, args, { cwd, signal });
40002
- const kill = () => call.child.kill("SIGKILL");
40003
- if (signal.aborted)
40004
- kill();
40005
- else
40006
- signal.addEventListener("abort", kill, { once: true });
40007
- return call;
40008
- };
40009
- var REMOTE_LOOKUP_MS = 5000;
40010
- async function tryExec(exec, file, args, cwd, limitMs) {
40011
- const controller = new AbortController;
40012
- const expired = Promise.withResolvers();
40013
- const timer = setTimeout(() => {
40014
- controller.abort();
40015
- expired.resolve(null);
40016
- }, limitMs);
40017
- try {
40018
- const answer = await Promise.race([
40019
- exec(file, args, { cwd, signal: controller.signal }),
40020
- expired.promise
40021
- ]);
40022
- return answer?.stdout ?? null;
40023
- } catch {
40024
- return null;
40025
- } finally {
40026
- clearTimeout(timer);
40027
- }
40028
- }
40029
- function parseRemoteList(stdout) {
40030
- const remotes = new Map;
40031
- for (const line of stdout.split(`
40032
- `)) {
40033
- const trimmed = line.trim();
40034
- if (!trimmed)
40035
- continue;
40036
- const match = trimmed.match(/^(\S+)\s+(\S+)/);
40037
- const [, name, url] = match ?? [];
40038
- if (name && url)
40039
- remotes.set(name, url);
40040
- }
40041
- return remotes;
40042
- }
40043
- function selectRemoteUrl(remotes) {
40044
- const origin = remotes.get("origin");
40045
- if (origin)
40046
- return origin;
40047
- const candidates = [...remotes.entries()].filter(([name]) => name !== "upstream");
40048
- return candidates.length === 1 ? candidates[0]?.[1] ?? null : null;
40049
- }
40050
- var GITHUB_REMOTE_PATTERNS = [
40051
- /^https:\/\/(?:[^@/\s]+@)?github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
40052
- /^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
40053
- /^ssh:\/\/git@github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i
40054
- ];
40055
- function parseGitHubRemoteUrl(url) {
40056
- const trimmed = url.trim();
40057
- for (const pattern of GITHUB_REMOTE_PATTERNS) {
40058
- const match = trimmed.match(pattern);
40059
- if (match)
40060
- return canonicalRepo(match[1] ?? "", match[2] ?? "");
40061
- }
40062
- return null;
40063
- }
40064
- async function resolveCwdRepo(cwd, exec) {
40065
- const jjOutput = await tryExec(exec, "jj", ["git", "remote", "list"], cwd, REMOTE_LOOKUP_MS);
40066
- if (jjOutput !== null) {
40067
- const url = selectRemoteUrl(parseRemoteList(jjOutput));
40068
- return url ? parseGitHubRemoteUrl(url) : null;
40069
- }
40070
- const originUrl = await tryExec(exec, "git", ["remote", "get-url", "origin"], cwd, REMOTE_LOOKUP_MS);
40071
- return originUrl ? parseGitHubRemoteUrl(originUrl) : null;
40072
- }
40073
-
40074
40086
  // ../envoy-client/src/session-answers.ts
40075
40087
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync5 } from "fs";
40076
40088
  import { join as join5 } from "path";
@@ -41464,6 +41476,183 @@ function allowedAPIURL(value) {
41464
41476
  return url.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname);
41465
41477
  }
41466
41478
 
41479
+ // ../envoy-client/src/process-ancestry.ts
41480
+ import { execFileSync } from "child_process";
41481
+ import { readFileSync as readFileSync7 } from "fs";
41482
+ var MAX_ANCESTORS = 64;
41483
+ var PARENT_LOOKUP_MS = 1000;
41484
+ function procParentPid(pid) {
41485
+ try {
41486
+ const stat = readFileSync7(`/proc/${pid}/stat`, "utf8");
41487
+ const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
41488
+ return Number.isInteger(parent) ? parent : undefined;
41489
+ } catch {
41490
+ return;
41491
+ }
41492
+ }
41493
+ function processTable() {
41494
+ const table = new Map;
41495
+ try {
41496
+ const listing = execFileSync("ps", ["-Ao", "pid=,ppid="], {
41497
+ encoding: "utf8",
41498
+ killSignal: "SIGKILL",
41499
+ timeout: PARENT_LOOKUP_MS
41500
+ });
41501
+ for (const line of listing.split(`
41502
+ `)) {
41503
+ const [, pid = "", parent = ""] = line.match(/^\s*(\d+)\s+(\d+)\s*$/) ?? [];
41504
+ if (pid !== "")
41505
+ table.set(Number(pid), Number(parent));
41506
+ }
41507
+ } catch {}
41508
+ return table;
41509
+ }
41510
+ function isAncestor(candidate, pid = process.pid) {
41511
+ let table;
41512
+ const parentPid = (child) => {
41513
+ if (process.platform === "linux")
41514
+ return procParentPid(child);
41515
+ table ??= processTable();
41516
+ return table.get(child);
41517
+ };
41518
+ let current = pid;
41519
+ for (let step = 0;current !== undefined && current > 1 && step < MAX_ANCESTORS; step++) {
41520
+ if (String(current) === candidate)
41521
+ return true;
41522
+ current = parentPid(current);
41523
+ }
41524
+ return false;
41525
+ }
41526
+
41527
+ // ../envoy-client/src/tmux-server.ts
41528
+ function tmuxServer(value) {
41529
+ const parts = (value ?? "").split(",");
41530
+ return { serverPid: parts.at(-2) ?? "", socket: parts.slice(0, -2).join(",") };
41531
+ }
41532
+
41533
+ // ../envoy-client/src/tmux-place.ts
41534
+ var PLACE_FORMAT = [
41535
+ "#{session_name}",
41536
+ "#{window_id}",
41537
+ "#{window_index}",
41538
+ "#{window_name}",
41539
+ "#{pane_id}",
41540
+ "#{pane_index}",
41541
+ "#{pid}",
41542
+ "#{pane_pid}",
41543
+ "#{window_layout}",
41544
+ "#{window_zoomed_flag}"
41545
+ ].join("\t");
41546
+ var PLACE_FIELDS = 10;
41547
+ function tmuxIndex(value) {
41548
+ return /^\d+$/.test(value) ? Number(value) : undefined;
41549
+ }
41550
+ async function readTmuxPlace(env, exec) {
41551
+ const { serverPid, socket } = tmuxServer(env.TMUX);
41552
+ const pane = env.TMUX_PANE?.trim() ?? "";
41553
+ if (socket === "" || serverPid === "" || pane === "")
41554
+ return { kind: "refused" };
41555
+ const answer = await tryExec(exec, "tmux", ["-u", "-S", socket, "display-message", "-p", "-t", pane, PLACE_FORMAT], "/", TMUX_PANE_LOOKUP_MS);
41556
+ if (!answer.ok)
41557
+ return answer.failure === "timedOut" ? { kind: "timedOut" } : { kind: "refused" };
41558
+ const fields = answer.stdout.replace(/\r?\n$/, "").split("\t");
41559
+ if (fields.length !== PLACE_FIELDS)
41560
+ return { kind: "refused" };
41561
+ const [
41562
+ sessionName = "",
41563
+ windowId = "",
41564
+ windowIndex = "",
41565
+ windowName = "",
41566
+ paneId = "",
41567
+ paneIndex = "",
41568
+ pid = "",
41569
+ panePid = "",
41570
+ layout = "",
41571
+ zoomedFlag = ""
41572
+ ] = fields;
41573
+ if (pid !== serverPid || paneId === "" || !isAncestor(panePid))
41574
+ return { kind: "refused" };
41575
+ const window2 = tmuxIndex(windowIndex);
41576
+ const index = tmuxIndex(paneIndex);
41577
+ if (window2 === undefined || index === undefined)
41578
+ return { kind: "refused" };
41579
+ return {
41580
+ kind: "place",
41581
+ place: {
41582
+ socket,
41583
+ server_pid: serverPid,
41584
+ session_name: sessionName,
41585
+ window_id: windowId,
41586
+ window_index: window2,
41587
+ window_name: windowName,
41588
+ pane_id: paneId,
41589
+ pane_index: index,
41590
+ ...layout.length > TMUX_LAYOUT_MAX ? {} : { layout },
41591
+ zoomed: zoomedFlag === "1"
41592
+ }
41593
+ };
41594
+ }
41595
+
41596
+ // ../envoy-client/src/tmux-place-cache.ts
41597
+ function createTmuxPlaceCache(options) {
41598
+ const now = options.now ?? Date.now;
41599
+ const repeat = options.every ?? every2;
41600
+ let held;
41601
+ let readAt;
41602
+ let reading = false;
41603
+ let shuttingDown = false;
41604
+ let stopRefreshing;
41605
+ const startReading = () => {
41606
+ if (reading || shuttingDown)
41607
+ return;
41608
+ reading = true;
41609
+ (async () => {
41610
+ try {
41611
+ const answer = await options.read();
41612
+ if (shuttingDown)
41613
+ return;
41614
+ if (answer.kind === "place")
41615
+ held = answer.place;
41616
+ else if (answer.kind === "refused")
41617
+ held = undefined;
41618
+ readAt = now();
41619
+ } catch (error) {
41620
+ if (shuttingDown)
41621
+ return;
41622
+ options.onFailure?.(error);
41623
+ readAt = now();
41624
+ } finally {
41625
+ reading = false;
41626
+ }
41627
+ })().catch(() => {
41628
+ return;
41629
+ });
41630
+ };
41631
+ const keepFresh = () => {
41632
+ if (stopRefreshing !== undefined || shuttingDown)
41633
+ return;
41634
+ stopRefreshing = repeat(options.lifetimeMs(), startReading);
41635
+ };
41636
+ return {
41637
+ place: () => {
41638
+ keepFresh();
41639
+ if (readAt === undefined || now() - readAt >= options.lifetimeMs())
41640
+ startReading();
41641
+ return held;
41642
+ },
41643
+ shutDown: () => {
41644
+ shuttingDown = true;
41645
+ stopRefreshing?.();
41646
+ stopRefreshing = undefined;
41647
+ }
41648
+ };
41649
+ }
41650
+ function every2(ms, callback) {
41651
+ const timer = setInterval(callback, ms);
41652
+ timer.unref?.();
41653
+ return () => clearInterval(timer);
41654
+ }
41655
+
41467
41656
  // ../envoy-client/src/tool-contract.ts
41468
41657
  var SESSION_STATE_GUIDE = "A session is live, unresponsive or gone, by how long ago it last registered: live within 5 " + "minutes, unresponsive after that and within an hour, gone past the hour or with no record at " + `all. ${UNRESPONSIVE_RULE} A session named with no state is live.`;
41469
41658
  var DELIVERY_CONTRACT = "Delivery is at-least-once, possibly out of order across topics; use id for dedupe and at for freshness.";
@@ -41934,7 +42123,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
41934
42123
 
41935
42124
  // package.json
41936
42125
  var name = "@sjawhar/pi-envoy";
41937
- var version2 = "16.22.0";
42126
+ var version2 = "16.24.0";
41938
42127
  var package_default = {
41939
42128
  name,
41940
42129
  version: version2,
@@ -48982,7 +49171,12 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
48982
49171
  }
48983
49172
  await registrationState.deregister(id);
48984
49173
  };
48985
- const registrationInput = (asking) => {
49174
+ const tmuxPlaces = createTmuxPlaceCache({
49175
+ read: () => readTmuxPlace(process.env, defaultExec),
49176
+ lifetimeMs: () => active?.settings.tmuxPlaceCacheMs ?? DEFAULT_TMUX_PLACE_CACHE_MS,
49177
+ onFailure: (error) => logger3.debug("envoy: the tmux place reading failed", { error: messageFor(error) })
49178
+ });
49179
+ const registrationInput = (asking, place) => {
48986
49180
  const own = agentSubject(sessionID);
48987
49181
  const topics = [
48988
49182
  ...new Set([
@@ -49002,17 +49196,18 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
49002
49196
  driving: false,
49003
49197
  selfSubscribed: true,
49004
49198
  plugin: { name, version: version2 },
49005
- ...asking === undefined ? {} : { delivery: asking.delivery.registration() }
49199
+ ...asking === undefined ? {} : { delivery: asking.delivery.registration() },
49200
+ ...place === undefined ? {} : { place }
49006
49201
  };
49007
49202
  };
49008
- const sendRegistration = (send) => {
49203
+ const sendRegistration = async (send) => {
49204
+ const place = tmuxPlaces.place();
49009
49205
  const registeringFor = sessionID;
49010
49206
  const asking = relay?.sessionID === registeringFor && relay.subscription !== undefined && replay?.startPending() !== true ? relay : undefined;
49011
- const input = registrationInput(asking);
49012
- return send(input).then((result) => {
49013
- takeDeliveryAnswer(registeringFor, input.topics, asking, result);
49014
- return result;
49015
- });
49207
+ const input = registrationInput(asking, place);
49208
+ const result = await send(input);
49209
+ takeDeliveryAnswer(registeringFor, input.topics, asking, result);
49210
+ return result;
49016
49211
  };
49017
49212
  const registerSession = () => trackRegistration(sessionID, sendRegistration(registrationState.refreshRegistration));
49018
49213
  const ensureHeartbeat = (context) => {
@@ -49482,6 +49677,7 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
49482
49677
  pi.on("session_before_branch", async (_event, context) => announce(undefined, context));
49483
49678
  pi.on("session_shutdown", async (_event, context) => {
49484
49679
  shuttingDown = true;
49680
+ tmuxPlaces.shutDown();
49485
49681
  cardWake.cancel();
49486
49682
  if (publishedInterface !== undefined) {
49487
49683
  const bound = publishedInterface.roleClaim.instances.indexOf(claimInstance);
@@ -33,7 +33,7 @@ report, a disclosure, and a reply to a maintainer who wrote first.
33
33
 
34
34
  Hold an extremely high bar. Optimise every upstream report, patch or public post for a human
35
35
  reader and for being received well, so each one builds the company's reputation rather than a
36
- name for slop.
36
+ reputation for low-quality or careless submissions.
37
37
 
38
38
  ## The four steps
39
39
 
@@ -95,7 +95,9 @@ review batch, never a per-message "can I send this" ask. Write its entry — wha
95
95
  serious; who receives it and what they do; the exact text or patch; its evidence; a non-author
96
96
  reviewer's APPROVE under your stream's reviewer-model rule; what the operator decides; its owner
97
97
  — into the batch, add it under the batch's Waiting list, and tell the batch owner. Your stream's
98
- brief names the batch and its owner.
98
+ brief names the batch and its owner. Where your stream's brief names no batch, ask the operator
99
+ for one, or hold the entry until there is a batch; a missing batch is not a reason to send a
100
+ per-message ask.
99
101
 
100
102
  ## What this skill does not cover
101
103
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-envoy",
3
- "version": "16.22.0",
3
+ "version": "16.24.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "omp": {