aisnitch 0.2.0 → 0.2.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.
@@ -41,7 +41,7 @@ var import_commander = require("commander");
41
41
 
42
42
  // src/package-info.ts
43
43
  var AISNITCH_PACKAGE_NAME = "aisnitch";
44
- var AISNITCH_VERSION = "0.2.0";
44
+ var AISNITCH_VERSION = "0.2.2";
45
45
  var AISNITCH_DESCRIPTION = "Universal bridge for AI coding tool activity \u2014 capture, normalize, stream.";
46
46
 
47
47
  // src/core/events/schema.ts
@@ -719,7 +719,7 @@ async function canBindPort(port, host) {
719
719
  }
720
720
  async function resolveAvailablePort(requestedPort, options = {}) {
721
721
  const host = options.host ?? "127.0.0.1";
722
- const maxAttempts = options.maxAttempts ?? 10;
722
+ const maxAttempts = options.maxAttempts ?? 100;
723
723
  for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
724
724
  const candidatePort = requestedPort + attempt;
725
725
  const available = await canBindPort(candidatePort, host);
@@ -11957,6 +11957,10 @@ function createCliRuntime(dependencies = {}) {
11957
11957
  };
11958
11958
  }
11959
11959
  }
11960
+ const loggedFailure = await readDaemonStartupFailure(pathOptions);
11961
+ if (loggedFailure !== null) {
11962
+ throw new Error(loggedFailure);
11963
+ }
11960
11964
  await sleep(DAEMON_READY_POLL_INTERVAL_MS);
11961
11965
  }
11962
11966
  throw new Error(
@@ -11965,6 +11969,34 @@ function createCliRuntime(dependencies = {}) {
11965
11969
  )}.`
11966
11970
  );
11967
11971
  }
11972
+ async function readDaemonStartupFailure(pathOptions) {
11973
+ try {
11974
+ const daemonLog = await (0, import_promises15.readFile)(getDaemonLogPath(pathOptions), "utf8");
11975
+ const logLines = daemonLog.split(/\r?\n/u).map((line) => line.trim()).filter((line) => line.length > 0);
11976
+ const lastLine = logLines.at(-1);
11977
+ if (!lastLine) {
11978
+ return null;
11979
+ }
11980
+ if (lastLine.startsWith("AISnitch CLI failed:")) {
11981
+ return lastLine;
11982
+ }
11983
+ const structuredFailure = parseStructuredDaemonFailure(lastLine);
11984
+ return structuredFailure === null ? null : `AISnitch daemon startup failed: ${structuredFailure}`;
11985
+ } catch {
11986
+ return null;
11987
+ }
11988
+ }
11989
+ function parseStructuredDaemonFailure(logLine) {
11990
+ try {
11991
+ const parsedLog = JSON.parse(logLine);
11992
+ if (typeof parsedLog.level !== "number" || parsedLog.level < 50) {
11993
+ return null;
11994
+ }
11995
+ return typeof parsedLog.msg === "string" && parsedLog.msg.length > 0 ? parsedLog.msg : logLine;
11996
+ } catch {
11997
+ return null;
11998
+ }
11999
+ }
11968
12000
  async function waitForProcessExit(pid) {
11969
12001
  const deadline = Date.now() + DAEMON_STOP_TIMEOUT_MS;
11970
12002
  while (Date.now() < deadline) {