acpx 0.1.11 → 0.1.12

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 +92 -38
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { Command, CommanderError, InvalidArgumentError as InvalidArgumentError3 } from "commander";
5
5
  import { realpathSync } from "fs";
6
6
  import fs6 from "fs/promises";
7
- import path7 from "path";
7
+ import path8 from "path";
8
8
  import { pathToFileURL } from "url";
9
9
  import { findSkillsRoot, maybeHandleSkillflag } from "skillflag";
10
10
 
@@ -1053,12 +1053,12 @@ function formatLocations(locations) {
1053
1053
  }
1054
1054
  const unique = /* @__PURE__ */ new Set();
1055
1055
  for (const location of locations) {
1056
- const path8 = location.path?.trim();
1057
- if (!path8) {
1056
+ const path9 = location.path?.trim();
1057
+ if (!path9) {
1058
1058
  continue;
1059
1059
  }
1060
1060
  const line = typeof location.line === "number" && Number.isFinite(location.line) ? `:${Math.max(1, Math.trunc(location.line))}` : "";
1061
- unique.add(`${path8}${line}`);
1061
+ unique.add(`${path9}${line}`);
1062
1062
  }
1063
1063
  const items = [...unique];
1064
1064
  if (items.length === 0) {
@@ -1071,15 +1071,15 @@ function formatLocations(locations) {
1071
1071
  }
1072
1072
  return `${visible.join(", ")}, +${hidden} more`;
1073
1073
  }
1074
- function summarizeDiff(path8, oldText, newText) {
1074
+ function summarizeDiff(path9, oldText, newText) {
1075
1075
  const oldLines = oldText ? oldText.split("\n").length : 0;
1076
1076
  const newLines = newText.split("\n").length;
1077
1077
  const delta = newLines - oldLines;
1078
1078
  if (delta === 0) {
1079
- return `diff ${path8} (line count unchanged)`;
1079
+ return `diff ${path9} (line count unchanged)`;
1080
1080
  }
1081
1081
  const signedDelta = `${delta > 0 ? "+" : ""}${delta}`;
1082
- return `diff ${path8} (${signedDelta} lines)`;
1082
+ return `diff ${path9} (${signedDelta} lines)`;
1083
1083
  }
1084
1084
  function textFromContentBlock(content) {
1085
1085
  switch (content.type) {
@@ -1639,7 +1639,7 @@ function createOutputFormatter(format, options = {}) {
1639
1639
 
1640
1640
  // src/session-runtime.ts
1641
1641
  import fs5 from "fs/promises";
1642
- import path6 from "path";
1642
+ import path7 from "path";
1643
1643
 
1644
1644
  // src/client.ts
1645
1645
  import {
@@ -1648,7 +1648,7 @@ import {
1648
1648
  ndJsonStream
1649
1649
  } from "@agentclientprotocol/sdk";
1650
1650
  import { spawn as spawn2 } from "child_process";
1651
- import path3 from "path";
1651
+ import path4 from "path";
1652
1652
  import { Readable, Writable } from "stream";
1653
1653
 
1654
1654
  // src/filesystem.ts
@@ -2011,6 +2011,60 @@ function extractAgentSessionId(meta) {
2011
2011
  return void 0;
2012
2012
  }
2013
2013
 
2014
+ // src/version.ts
2015
+ import { readFileSync } from "fs";
2016
+ import path3 from "path";
2017
+ import { fileURLToPath } from "url";
2018
+ var UNKNOWN_VERSION = "0.0.0-unknown";
2019
+ var MODULE_DIR = path3.dirname(fileURLToPath(import.meta.url));
2020
+ var cachedVersion = null;
2021
+ function parseVersion(value) {
2022
+ if (typeof value !== "string") {
2023
+ return null;
2024
+ }
2025
+ const trimmed = value.trim();
2026
+ return trimmed.length > 0 ? trimmed : null;
2027
+ }
2028
+ function readPackageVersion(packageJsonPath) {
2029
+ try {
2030
+ const parsed = JSON.parse(readFileSync(packageJsonPath, "utf8"));
2031
+ return parseVersion(parsed.version);
2032
+ } catch {
2033
+ return null;
2034
+ }
2035
+ }
2036
+ function resolveVersionFromAncestors(startDir) {
2037
+ let current = startDir;
2038
+ while (true) {
2039
+ const packageVersion = readPackageVersion(path3.join(current, "package.json"));
2040
+ if (packageVersion) {
2041
+ return packageVersion;
2042
+ }
2043
+ const parent = path3.dirname(current);
2044
+ if (parent === current) {
2045
+ return null;
2046
+ }
2047
+ current = parent;
2048
+ }
2049
+ }
2050
+ function resolveAcpxVersion(params) {
2051
+ const envVersion = parseVersion((params?.env ?? process.env).npm_package_version);
2052
+ if (envVersion) {
2053
+ return envVersion;
2054
+ }
2055
+ if (params?.packageJsonPath) {
2056
+ return readPackageVersion(params.packageJsonPath) ?? UNKNOWN_VERSION;
2057
+ }
2058
+ return resolveVersionFromAncestors(MODULE_DIR) ?? UNKNOWN_VERSION;
2059
+ }
2060
+ function getAcpxVersion() {
2061
+ if (cachedVersion) {
2062
+ return cachedVersion;
2063
+ }
2064
+ cachedVersion = resolveAcpxVersion();
2065
+ return cachedVersion;
2066
+ }
2067
+
2014
2068
  // src/terminal.ts
2015
2069
  import { spawn } from "child_process";
2016
2070
  import { randomUUID } from "crypto";
@@ -2477,7 +2531,7 @@ function splitCommandLine(value) {
2477
2531
  };
2478
2532
  }
2479
2533
  function asAbsoluteCwd(cwd) {
2480
- return path3.resolve(cwd);
2534
+ return path4.resolve(cwd);
2481
2535
  }
2482
2536
  function toEnvToken(value) {
2483
2537
  return value.trim().replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toUpperCase();
@@ -2685,7 +2739,7 @@ var AcpClient = class {
2685
2739
  },
2686
2740
  clientInfo: {
2687
2741
  name: "acpx",
2688
- version: "0.1.0"
2742
+ version: getAcpxVersion()
2689
2743
  }
2690
2744
  });
2691
2745
  await this.authenticateIfRequired(connection, initResult.authMethods ?? []);
@@ -3112,25 +3166,25 @@ var AcpClient = class {
3112
3166
  import { createHash } from "crypto";
3113
3167
  import fs3 from "fs/promises";
3114
3168
  import os2 from "os";
3115
- import path4 from "path";
3169
+ import path5 from "path";
3116
3170
  var PROCESS_EXIT_GRACE_MS = 1500;
3117
3171
  var PROCESS_POLL_MS = 50;
3118
3172
  var QUEUE_OWNER_STALE_HEARTBEAT_MS = 15e3;
3119
3173
  function queueBaseDir() {
3120
- return path4.join(os2.homedir(), ".acpx", "queues");
3174
+ return path5.join(os2.homedir(), ".acpx", "queues");
3121
3175
  }
3122
3176
  function queueKeyForSession(sessionId) {
3123
3177
  return createHash("sha256").update(sessionId).digest("hex").slice(0, 24);
3124
3178
  }
3125
3179
  function queueLockFilePath(sessionId) {
3126
- return path4.join(queueBaseDir(), `${queueKeyForSession(sessionId)}.lock`);
3180
+ return path5.join(queueBaseDir(), `${queueKeyForSession(sessionId)}.lock`);
3127
3181
  }
3128
3182
  function queueSocketPath(sessionId) {
3129
3183
  const key = queueKeyForSession(sessionId);
3130
3184
  if (process.platform === "win32") {
3131
3185
  return `\\\\.\\pipe\\acpx-${key}`;
3132
3186
  }
3133
- return path4.join(queueBaseDir(), `${key}.sock`);
3187
+ return path5.join(queueBaseDir(), `${key}.sock`);
3134
3188
  }
3135
3189
  function parseQueueOwnerRecord(raw) {
3136
3190
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
@@ -4773,14 +4827,14 @@ import { spawn as spawn3 } from "child_process";
4773
4827
  import { statSync } from "fs";
4774
4828
  import fs4 from "fs/promises";
4775
4829
  import os3 from "os";
4776
- import path5 from "path";
4830
+ import path6 from "path";
4777
4831
  var DEFAULT_HISTORY_LIMIT = 20;
4778
4832
  function sessionFilePath(id) {
4779
4833
  const safeId = encodeURIComponent(id);
4780
- return path5.join(sessionBaseDir(), `${safeId}.json`);
4834
+ return path6.join(sessionBaseDir(), `${safeId}.json`);
4781
4835
  }
4782
4836
  function sessionBaseDir() {
4783
- return path5.join(os3.homedir(), ".acpx", "sessions");
4837
+ return path6.join(os3.homedir(), ".acpx", "sessions");
4784
4838
  }
4785
4839
  async function ensureSessionDir() {
4786
4840
  await fs4.mkdir(sessionBaseDir(), { recursive: true });
@@ -4899,7 +4953,7 @@ async function resolveSessionRecord(sessionId) {
4899
4953
  throw new SessionNotFoundError(sessionId);
4900
4954
  }
4901
4955
  function hasGitDirectory(dir) {
4902
- const gitPath = path5.join(dir, ".git");
4956
+ const gitPath = path6.join(dir, ".git");
4903
4957
  try {
4904
4958
  return statSync(gitPath).isDirectory();
4905
4959
  } catch {
@@ -4907,15 +4961,15 @@ function hasGitDirectory(dir) {
4907
4961
  }
4908
4962
  }
4909
4963
  function isWithinBoundary(boundary, target) {
4910
- const relative = path5.relative(boundary, target);
4911
- return relative.length === 0 || !relative.startsWith("..") && !path5.isAbsolute(relative);
4964
+ const relative = path6.relative(boundary, target);
4965
+ return relative.length === 0 || !relative.startsWith("..") && !path6.isAbsolute(relative);
4912
4966
  }
4913
4967
  function absolutePath(value) {
4914
- return path5.resolve(value);
4968
+ return path6.resolve(value);
4915
4969
  }
4916
4970
  function findGitRepositoryRoot(startDir) {
4917
4971
  let current = absolutePath(startDir);
4918
- const root = path5.parse(current).root;
4972
+ const root = path6.parse(current).root;
4919
4973
  for (; ; ) {
4920
4974
  if (hasGitDirectory(current)) {
4921
4975
  return current;
@@ -4923,7 +4977,7 @@ function findGitRepositoryRoot(startDir) {
4923
4977
  if (current === root) {
4924
4978
  return void 0;
4925
4979
  }
4926
- const parent = path5.dirname(current);
4980
+ const parent = path6.dirname(current);
4927
4981
  if (parent === current) {
4928
4982
  return void 0;
4929
4983
  }
@@ -4948,7 +5002,7 @@ async function listSessions() {
4948
5002
  if (!entry.isFile() || !entry.name.endsWith(".json")) {
4949
5003
  continue;
4950
5004
  }
4951
- const fullPath = path5.join(sessionBaseDir(), entry.name);
5005
+ const fullPath = path6.join(sessionBaseDir(), entry.name);
4952
5006
  try {
4953
5007
  const payload = await fs4.readFile(fullPath, "utf8");
4954
5008
  const parsed = parseSessionRecord(JSON.parse(payload));
@@ -5009,7 +5063,7 @@ async function findSessionByDirectoryWalk(options) {
5009
5063
  if (dir === walkBoundary) {
5010
5064
  return void 0;
5011
5065
  }
5012
- const parent = path5.dirname(dir);
5066
+ const parent = path6.dirname(dir);
5013
5067
  if (parent === dir) {
5014
5068
  return void 0;
5015
5069
  }
@@ -6027,9 +6081,9 @@ async function isLikelyMatchingProcess(pid, agentCommand) {
6027
6081
  if (argv.length === 0) {
6028
6082
  return false;
6029
6083
  }
6030
- const executableBase = path6.basename(argv[0]);
6031
- const expectedBase = path6.basename(expectedToken);
6032
- return executableBase === expectedBase || argv.some((entry) => path6.basename(entry) === expectedBase);
6084
+ const executableBase = path7.basename(argv[0]);
6085
+ const expectedBase = path7.basename(expectedToken);
6086
+ return executableBase === expectedBase || argv.some((entry) => path7.basename(entry) === expectedBase);
6033
6087
  } catch {
6034
6088
  return true;
6035
6089
  }
@@ -6153,7 +6207,7 @@ async function readPromptInputFromStdin() {
6153
6207
  }
6154
6208
  async function readPrompt(promptParts, filePath, cwd) {
6155
6209
  if (filePath) {
6156
- const source = filePath === "-" ? await readPromptInputFromStdin() : await fs6.readFile(path7.resolve(cwd, filePath), "utf8");
6210
+ const source = filePath === "-" ? await readPromptInputFromStdin() : await fs6.readFile(path8.resolve(cwd, filePath), "utf8");
6157
6211
  const pieces = [source.trim(), promptParts.join(" ").trim()].filter(
6158
6212
  (value) => value.length > 0
6159
6213
  );
@@ -6294,7 +6348,7 @@ function resolveAgentInvocation(explicitAgentName, globalFlags, config) {
6294
6348
  return {
6295
6349
  agentName,
6296
6350
  agentCommand,
6297
- cwd: path7.resolve(globalFlags.cwd)
6351
+ cwd: path8.resolve(globalFlags.cwd)
6298
6352
  };
6299
6353
  }
6300
6354
  function printSessionsByFormat(sessions, format) {
@@ -6433,19 +6487,19 @@ function formatSessionLabel(record) {
6433
6487
  return record.name ?? "cwd";
6434
6488
  }
6435
6489
  function formatRoutedFrom(sessionCwd, currentCwd) {
6436
- const relative = path7.relative(sessionCwd, currentCwd);
6490
+ const relative = path8.relative(sessionCwd, currentCwd);
6437
6491
  if (!relative || relative === ".") {
6438
6492
  return void 0;
6439
6493
  }
6440
- return relative.startsWith(".") ? relative : `.${path7.sep}${relative}`;
6494
+ return relative.startsWith(".") ? relative : `.${path8.sep}${relative}`;
6441
6495
  }
6442
6496
  function sessionConnectionStatus(record) {
6443
6497
  return isProcessAlive(record.pid) ? "connected" : "needs reconnect";
6444
6498
  }
6445
6499
  function formatPromptSessionBannerLine(record, currentCwd) {
6446
6500
  const label = formatSessionLabel(record);
6447
- const normalizedSessionCwd = path7.resolve(record.cwd);
6448
- const normalizedCurrentCwd = path7.resolve(currentCwd);
6501
+ const normalizedSessionCwd = path8.resolve(record.cwd);
6502
+ const normalizedCurrentCwd = path8.resolve(currentCwd);
6449
6503
  const routedFrom = normalizedSessionCwd === normalizedCurrentCwd ? void 0 : formatRoutedFrom(normalizedSessionCwd, normalizedCurrentCwd);
6450
6504
  const status = sessionConnectionStatus(record);
6451
6505
  if (routedFrom) {
@@ -7257,14 +7311,14 @@ function detectInitialCwd(argv) {
7257
7311
  if (token === "--cwd") {
7258
7312
  const next = argv[index + 1];
7259
7313
  if (next && next !== "--") {
7260
- return path7.resolve(next);
7314
+ return path8.resolve(next);
7261
7315
  }
7262
7316
  break;
7263
7317
  }
7264
7318
  if (token.startsWith("--cwd=")) {
7265
7319
  const value = token.slice("--cwd=".length).trim();
7266
7320
  if (value.length > 0) {
7267
- return path7.resolve(value);
7321
+ return path8.resolve(value);
7268
7322
  }
7269
7323
  break;
7270
7324
  }
@@ -7365,7 +7419,7 @@ async function main(argv = process.argv) {
7365
7419
  DEFAULT_QUEUE_OWNER_TTL_MS
7366
7420
  );
7367
7421
  const program = new Command();
7368
- program.name("acpx").description("Headless CLI client for the Agent Client Protocol").enablePositionalOptions().showHelpAfterError();
7422
+ program.name("acpx").description("Headless CLI client for the Agent Client Protocol").version(getAcpxVersion()).enablePositionalOptions().showHelpAfterError();
7369
7423
  if (requestedJsonStrict) {
7370
7424
  program.configureOutput({
7371
7425
  writeOut: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acpx",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Headless CLI client for the Agent Client Protocol (ACP) — talk to coding agents from the command line",
5
5
  "type": "module",
6
6
  "files": [