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.
package/dist/cli/index.js CHANGED
@@ -8,7 +8,7 @@ import { Command, InvalidArgumentError } from "commander";
8
8
 
9
9
  // src/package-info.ts
10
10
  var AISNITCH_PACKAGE_NAME = "aisnitch";
11
- var AISNITCH_VERSION = "0.2.0";
11
+ var AISNITCH_VERSION = "0.2.2";
12
12
  var AISNITCH_DESCRIPTION = "Universal bridge for AI coding tool activity \u2014 capture, normalize, stream.";
13
13
 
14
14
  // src/core/events/schema.ts
@@ -686,7 +686,7 @@ async function canBindPort(port, host) {
686
686
  }
687
687
  async function resolveAvailablePort(requestedPort, options = {}) {
688
688
  const host = options.host ?? "127.0.0.1";
689
- const maxAttempts = options.maxAttempts ?? 10;
689
+ const maxAttempts = options.maxAttempts ?? 100;
690
690
  for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
691
691
  const candidatePort = requestedPort + attempt;
692
692
  const available = await canBindPort(candidatePort, host);
@@ -2304,7 +2304,7 @@ function toConfigPathOptions(options) {
2304
2304
  // src/cli/runtime.ts
2305
2305
  import { execFile as execFileCallback11, spawn as spawnChildProcess2 } from "child_process";
2306
2306
  import { closeSync, openSync } from "fs";
2307
- import { mkdtemp, rename, rm as rm4, writeFile as writeFile5 } from "fs/promises";
2307
+ import { mkdtemp, readFile as readFile11, rename, rm as rm4, writeFile as writeFile5 } from "fs/promises";
2308
2308
  import { createConnection as createConnection3 } from "net";
2309
2309
  import { tmpdir } from "os";
2310
2310
  import { basename as basename8, join as join13 } from "path";
@@ -11926,6 +11926,10 @@ function createCliRuntime(dependencies = {}) {
11926
11926
  };
11927
11927
  }
11928
11928
  }
11929
+ const loggedFailure = await readDaemonStartupFailure(pathOptions);
11930
+ if (loggedFailure !== null) {
11931
+ throw new Error(loggedFailure);
11932
+ }
11929
11933
  await sleep(DAEMON_READY_POLL_INTERVAL_MS);
11930
11934
  }
11931
11935
  throw new Error(
@@ -11934,6 +11938,34 @@ function createCliRuntime(dependencies = {}) {
11934
11938
  )}.`
11935
11939
  );
11936
11940
  }
11941
+ async function readDaemonStartupFailure(pathOptions) {
11942
+ try {
11943
+ const daemonLog = await readFile11(getDaemonLogPath(pathOptions), "utf8");
11944
+ const logLines = daemonLog.split(/\r?\n/u).map((line) => line.trim()).filter((line) => line.length > 0);
11945
+ const lastLine = logLines.at(-1);
11946
+ if (!lastLine) {
11947
+ return null;
11948
+ }
11949
+ if (lastLine.startsWith("AISnitch CLI failed:")) {
11950
+ return lastLine;
11951
+ }
11952
+ const structuredFailure = parseStructuredDaemonFailure(lastLine);
11953
+ return structuredFailure === null ? null : `AISnitch daemon startup failed: ${structuredFailure}`;
11954
+ } catch {
11955
+ return null;
11956
+ }
11957
+ }
11958
+ function parseStructuredDaemonFailure(logLine) {
11959
+ try {
11960
+ const parsedLog = JSON.parse(logLine);
11961
+ if (typeof parsedLog.level !== "number" || parsedLog.level < 50) {
11962
+ return null;
11963
+ }
11964
+ return typeof parsedLog.msg === "string" && parsedLog.msg.length > 0 ? parsedLog.msg : logLine;
11965
+ } catch {
11966
+ return null;
11967
+ }
11968
+ }
11937
11969
  async function waitForProcessExit(pid) {
11938
11970
  const deadline = Date.now() + DAEMON_STOP_TIMEOUT_MS;
11939
11971
  while (Date.now() < deadline) {