@rallycry/conveyor-agent 10.7.4 → 10.7.5

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.
@@ -4403,9 +4403,9 @@ function extractSpawn(mod) {
4403
4403
  }
4404
4404
  async function loadPtySpawn() {
4405
4405
  const mod = await import("node-pty");
4406
- const spawn3 = extractSpawn(mod);
4407
- if (!spawn3) throw new Error("node-pty: spawn export not found");
4408
- return spawn3;
4406
+ const spawn2 = extractSpawn(mod);
4407
+ if (!spawn2) throw new Error("node-pty: spawn export not found");
4408
+ return spawn2;
4409
4409
  }
4410
4410
  function inheritedEnv(socketPath) {
4411
4411
  const env = {};
@@ -4907,8 +4907,8 @@ var PtySession = class {
4907
4907
  // server doesn't load).
4908
4908
  ...this.mcpConfigPath ? { mcpConfigPath: this.mcpConfigPath } : {}
4909
4909
  });
4910
- const spawn3 = await loadPtySpawn();
4911
- const pty = spawn3(spec.file, spec.args, {
4910
+ const spawn2 = await loadPtySpawn();
4911
+ const pty = spawn2(spec.file, spec.args, {
4912
4912
  name: "xterm-color",
4913
4913
  cols: this.cols,
4914
4914
  rows: this.rows,
@@ -9604,10 +9604,21 @@ function readAgentVersion() {
9604
9604
  return null;
9605
9605
  }
9606
9606
 
9607
+ // src/execution/usage-sampler.ts
9608
+ import { existsSync as existsSync3 } from "fs";
9609
+
9607
9610
  // src/usage/parse-usage.ts
9611
+ var ESC = "\\u001b";
9612
+ var ANSI_CSI2 = new RegExp(`${ESC}\\[[0-9;?]*[ -/]*[@-~]`, "g");
9613
+ var ANSI_OSC = new RegExp(`${ESC}\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\)`, "g");
9614
+ var BAR_GLYPHS = /[─-▟]/g;
9615
+ function normalizeUsageText(stdout) {
9616
+ return stdout.replace(ANSI_CSI2, "").replace(ANSI_OSC, "").replace(BAR_GLYPHS, " ").replace(/\r/g, "");
9617
+ }
9608
9618
  function parseUsageGauges(stdout) {
9609
- const session = stdout.match(/Current session:\s*(\d+(?:\.\d+)?)%\s*used/i);
9610
- const weekly = [...stdout.matchAll(/Current week[^:\n]*:\s*(\d+(?:\.\d+)?)%\s*used/gi)];
9619
+ const text = normalizeUsageText(stdout);
9620
+ const session = text.match(/Current session[^%\n]*?(\d+(?:\.\d+)?)\s*%(?:\s*used)?/i);
9621
+ const weekly = [...text.matchAll(/Current week[^%\n]*?(\d+(?:\.\d+)?)\s*%(?:\s*used)?/gi)];
9611
9622
  return {
9612
9623
  sessionUsage: session ? Number(session[1]) / 100 : null,
9613
9624
  weeklyUsage: weekly.length ? Math.max(...weekly.map((m) => Number(m[1]))) / 100 : null
@@ -9615,54 +9626,116 @@ function parseUsageGauges(stdout) {
9615
9626
  }
9616
9627
 
9617
9628
  // src/usage/run-probe.ts
9618
- import { spawn } from "child_process";
9619
- var PROBE_TIMEOUT_MS = 15e3;
9629
+ var PROBE_TIMEOUT_MS = 3e4;
9630
+ var FIRST_SEND_MS = 5e3;
9631
+ var RESEND_INTERVAL_MS = 4e3;
9632
+ var MAX_SENDS = 5;
9633
+ var RENDER_SETTLE_MS = 900;
9620
9634
  function buildProbeEnv(env = process.env) {
9621
- const { CLAUDE_CODE_OAUTH_TOKEN: _oauth, ANTHROPIC_API_KEY: _apiKey, ...rest } = env;
9622
- return rest;
9623
- }
9624
- function runUsageProbe(binary = resolveClaudeBinary(), args = ["-p", "/usage"]) {
9635
+ const clean = {};
9636
+ for (const [key, value] of Object.entries(env)) {
9637
+ if (typeof value === "string") clean[key] = value;
9638
+ }
9639
+ delete clean.CLAUDE_CODE_OAUTH_TOKEN;
9640
+ delete clean.ANTHROPIC_API_KEY;
9641
+ return clean;
9642
+ }
9643
+ function panelRendering(buf) {
9644
+ return /Current session/i.test(buf) && /%/.test(buf);
9645
+ }
9646
+ var UsageProbeRun = class {
9647
+ constructor(resolve, timing) {
9648
+ this.resolve = resolve;
9649
+ this.timing = timing;
9650
+ }
9651
+ resolve;
9652
+ timing;
9653
+ buf = "";
9654
+ settled = false;
9655
+ sends = 0;
9656
+ child = null;
9657
+ hardTimer = null;
9658
+ resendTimer = null;
9659
+ settleTimer = null;
9660
+ start(child, timeoutMs) {
9661
+ this.child = child;
9662
+ child.onData((data) => this.onData(data));
9663
+ child.onExit(() => this.finishBestEffort());
9664
+ this.hardTimer = setTimeout(() => this.finishBestEffort(), timeoutMs);
9665
+ this.hardTimer.unref?.();
9666
+ const first = setTimeout(() => this.trySend(), this.timing.firstSendMs);
9667
+ first.unref?.();
9668
+ this.resendTimer = setInterval(() => this.trySend(), this.timing.resendIntervalMs);
9669
+ this.resendTimer.unref?.();
9670
+ }
9671
+ trySend() {
9672
+ if (this.settled || this.sends >= MAX_SENDS) return;
9673
+ this.sends += 1;
9674
+ try {
9675
+ this.child?.write("/usage\r");
9676
+ } catch {
9677
+ }
9678
+ }
9679
+ onData(chunk) {
9680
+ this.buf += chunk;
9681
+ if (this.settleTimer || !panelRendering(this.buf)) return;
9682
+ this.settleTimer = setTimeout(() => this.finish(this.buf), this.timing.settleMs);
9683
+ }
9684
+ finishBestEffort() {
9685
+ this.finish(panelRendering(this.buf) ? this.buf : "");
9686
+ }
9687
+ finish(out) {
9688
+ if (this.settled) return;
9689
+ this.settled = true;
9690
+ if (this.hardTimer) clearTimeout(this.hardTimer);
9691
+ if (this.resendTimer) clearInterval(this.resendTimer);
9692
+ if (this.settleTimer) clearTimeout(this.settleTimer);
9693
+ try {
9694
+ this.child?.kill();
9695
+ } catch {
9696
+ }
9697
+ this.resolve(out);
9698
+ }
9699
+ };
9700
+ async function runUsageProbe(deps = {}) {
9701
+ let spawn2 = deps.spawn;
9702
+ if (!spawn2) {
9703
+ try {
9704
+ spawn2 = await loadPtySpawn();
9705
+ } catch {
9706
+ return "";
9707
+ }
9708
+ }
9709
+ const binary = deps.binary ?? resolveClaudeBinary();
9710
+ const cwd = deps.cwd ?? process.cwd();
9711
+ const timeoutMs = deps.timeoutMs ?? PROBE_TIMEOUT_MS;
9712
+ const timing = {
9713
+ firstSendMs: deps.firstSendMs ?? FIRST_SEND_MS,
9714
+ resendIntervalMs: deps.resendIntervalMs ?? RESEND_INTERVAL_MS,
9715
+ settleMs: deps.settleMs ?? RENDER_SETTLE_MS
9716
+ };
9625
9717
  return new Promise((resolve) => {
9626
- let stdout = "";
9627
- let settled = false;
9628
- const finish = (out) => {
9629
- if (settled) return;
9630
- settled = true;
9631
- resolve(out);
9632
- };
9633
9718
  let child;
9634
9719
  try {
9635
- child = spawn(binary, args, { stdio: ["ignore", "pipe", "ignore"], env: buildProbeEnv() });
9720
+ child = spawn2(binary, [], {
9721
+ name: "xterm-256color",
9722
+ cols: 120,
9723
+ rows: 45,
9724
+ cwd,
9725
+ env: buildProbeEnv()
9726
+ });
9636
9727
  } catch {
9637
- finish("");
9728
+ resolve("");
9638
9729
  return;
9639
9730
  }
9640
- const timer = setTimeout(() => {
9641
- try {
9642
- child.kill("SIGKILL");
9643
- } catch {
9644
- }
9645
- finish("");
9646
- }, PROBE_TIMEOUT_MS);
9647
- timer.unref?.();
9648
- child.stdout?.on("data", (d) => {
9649
- stdout += d.toString();
9650
- });
9651
- child.on("error", () => {
9652
- clearTimeout(timer);
9653
- finish("");
9654
- });
9655
- child.on("close", (code) => {
9656
- clearTimeout(timer);
9657
- finish(code === 0 ? stdout : "");
9658
- });
9731
+ new UsageProbeRun(resolve, timing).start(child, timeoutMs);
9659
9732
  });
9660
9733
  }
9661
9734
 
9662
9735
  // src/execution/usage-sampler.ts
9663
9736
  var logger4 = createServiceLogger("usage-sampler");
9664
- async function sampleKeyUsage(token, probe = runUsageProbe) {
9665
- if (!token) return [];
9737
+ async function sampleKeyUsage(token, probe = () => runUsageProbe(), hasSubscriptionCredentials = () => existsSync3(claudeCredentialsPath())) {
9738
+ if (!token && !hasSubscriptionCredentials()) return [];
9666
9739
  try {
9667
9740
  const stdout = await probe();
9668
9741
  const { sessionUsage, weeklyUsage } = parseUsageGauges(stdout);
@@ -11003,7 +11076,7 @@ function loadConveyorConfig() {
11003
11076
  }
11004
11077
 
11005
11078
  // src/setup/commands.ts
11006
- import { spawn as spawn2, execSync } from "child_process";
11079
+ import { spawn, execSync } from "child_process";
11007
11080
  var PROCESS_TERMINATION_GRACE_MS = 5e3;
11008
11081
  function abortError2() {
11009
11082
  const error = new Error("Operation aborted");
@@ -11044,7 +11117,7 @@ function terminateProcessGroup(child, graceMs = PROCESS_TERMINATION_GRACE_MS) {
11044
11117
  function runSetupCommand(cmd, cwd, onOutput, signal) {
11045
11118
  if (signal?.aborted) return Promise.reject(abortError2());
11046
11119
  return new Promise((resolve, reject) => {
11047
- const child = spawn2("sh", ["-c", cmd], {
11120
+ const child = spawn("sh", ["-c", cmd], {
11048
11121
  cwd,
11049
11122
  stdio: ["ignore", "pipe", "pipe"],
11050
11123
  detached: true,
@@ -11100,7 +11173,7 @@ function runAuthTokenCommand(cmd, userEmail, cwd) {
11100
11173
  }
11101
11174
  }
11102
11175
  function runStartCommand(cmd, cwd, onOutput) {
11103
- const child = spawn2("sh", ["-c", cmd], {
11176
+ const child = spawn("sh", ["-c", cmd], {
11104
11177
  cwd,
11105
11178
  stdio: ["ignore", "pipe", "pipe"],
11106
11179
  detached: true,
@@ -11174,4 +11247,4 @@ export {
11174
11247
  runStartCommand,
11175
11248
  unshallowRepo
11176
11249
  };
11177
- //# sourceMappingURL=chunk-WJWMLZKR.js.map
11250
+ //# sourceMappingURL=chunk-CWTQXS34.js.map