acpx 0.1.11 → 0.1.13
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.js +94 -38
- 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
|
|
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
|
|
1057
|
-
if (!
|
|
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(`${
|
|
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(
|
|
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 ${
|
|
1079
|
+
return `diff ${path9} (line count unchanged)`;
|
|
1080
1080
|
}
|
|
1081
1081
|
const signedDelta = `${delta > 0 ? "+" : ""}${delta}`;
|
|
1082
|
-
return `diff ${
|
|
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
|
|
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
|
|
1651
|
+
import path4 from "path";
|
|
1652
1652
|
import { Readable, Writable } from "stream";
|
|
1653
1653
|
|
|
1654
1654
|
// src/filesystem.ts
|
|
@@ -2011,6 +2011,62 @@ 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 env = params?.env ?? process.env;
|
|
2052
|
+
const envPackageName = parseVersion(env.npm_package_name);
|
|
2053
|
+
const envVersion = parseVersion(env.npm_package_version);
|
|
2054
|
+
if (envPackageName === "acpx" && envVersion) {
|
|
2055
|
+
return envVersion;
|
|
2056
|
+
}
|
|
2057
|
+
if (params?.packageJsonPath) {
|
|
2058
|
+
return readPackageVersion(params.packageJsonPath) ?? UNKNOWN_VERSION;
|
|
2059
|
+
}
|
|
2060
|
+
return resolveVersionFromAncestors(MODULE_DIR) ?? UNKNOWN_VERSION;
|
|
2061
|
+
}
|
|
2062
|
+
function getAcpxVersion() {
|
|
2063
|
+
if (cachedVersion) {
|
|
2064
|
+
return cachedVersion;
|
|
2065
|
+
}
|
|
2066
|
+
cachedVersion = resolveAcpxVersion();
|
|
2067
|
+
return cachedVersion;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2014
2070
|
// src/terminal.ts
|
|
2015
2071
|
import { spawn } from "child_process";
|
|
2016
2072
|
import { randomUUID } from "crypto";
|
|
@@ -2477,7 +2533,7 @@ function splitCommandLine(value) {
|
|
|
2477
2533
|
};
|
|
2478
2534
|
}
|
|
2479
2535
|
function asAbsoluteCwd(cwd) {
|
|
2480
|
-
return
|
|
2536
|
+
return path4.resolve(cwd);
|
|
2481
2537
|
}
|
|
2482
2538
|
function toEnvToken(value) {
|
|
2483
2539
|
return value.trim().replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toUpperCase();
|
|
@@ -2685,7 +2741,7 @@ var AcpClient = class {
|
|
|
2685
2741
|
},
|
|
2686
2742
|
clientInfo: {
|
|
2687
2743
|
name: "acpx",
|
|
2688
|
-
version:
|
|
2744
|
+
version: getAcpxVersion()
|
|
2689
2745
|
}
|
|
2690
2746
|
});
|
|
2691
2747
|
await this.authenticateIfRequired(connection, initResult.authMethods ?? []);
|
|
@@ -3112,25 +3168,25 @@ var AcpClient = class {
|
|
|
3112
3168
|
import { createHash } from "crypto";
|
|
3113
3169
|
import fs3 from "fs/promises";
|
|
3114
3170
|
import os2 from "os";
|
|
3115
|
-
import
|
|
3171
|
+
import path5 from "path";
|
|
3116
3172
|
var PROCESS_EXIT_GRACE_MS = 1500;
|
|
3117
3173
|
var PROCESS_POLL_MS = 50;
|
|
3118
3174
|
var QUEUE_OWNER_STALE_HEARTBEAT_MS = 15e3;
|
|
3119
3175
|
function queueBaseDir() {
|
|
3120
|
-
return
|
|
3176
|
+
return path5.join(os2.homedir(), ".acpx", "queues");
|
|
3121
3177
|
}
|
|
3122
3178
|
function queueKeyForSession(sessionId) {
|
|
3123
3179
|
return createHash("sha256").update(sessionId).digest("hex").slice(0, 24);
|
|
3124
3180
|
}
|
|
3125
3181
|
function queueLockFilePath(sessionId) {
|
|
3126
|
-
return
|
|
3182
|
+
return path5.join(queueBaseDir(), `${queueKeyForSession(sessionId)}.lock`);
|
|
3127
3183
|
}
|
|
3128
3184
|
function queueSocketPath(sessionId) {
|
|
3129
3185
|
const key = queueKeyForSession(sessionId);
|
|
3130
3186
|
if (process.platform === "win32") {
|
|
3131
3187
|
return `\\\\.\\pipe\\acpx-${key}`;
|
|
3132
3188
|
}
|
|
3133
|
-
return
|
|
3189
|
+
return path5.join(queueBaseDir(), `${key}.sock`);
|
|
3134
3190
|
}
|
|
3135
3191
|
function parseQueueOwnerRecord(raw) {
|
|
3136
3192
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
@@ -4773,14 +4829,14 @@ import { spawn as spawn3 } from "child_process";
|
|
|
4773
4829
|
import { statSync } from "fs";
|
|
4774
4830
|
import fs4 from "fs/promises";
|
|
4775
4831
|
import os3 from "os";
|
|
4776
|
-
import
|
|
4832
|
+
import path6 from "path";
|
|
4777
4833
|
var DEFAULT_HISTORY_LIMIT = 20;
|
|
4778
4834
|
function sessionFilePath(id) {
|
|
4779
4835
|
const safeId = encodeURIComponent(id);
|
|
4780
|
-
return
|
|
4836
|
+
return path6.join(sessionBaseDir(), `${safeId}.json`);
|
|
4781
4837
|
}
|
|
4782
4838
|
function sessionBaseDir() {
|
|
4783
|
-
return
|
|
4839
|
+
return path6.join(os3.homedir(), ".acpx", "sessions");
|
|
4784
4840
|
}
|
|
4785
4841
|
async function ensureSessionDir() {
|
|
4786
4842
|
await fs4.mkdir(sessionBaseDir(), { recursive: true });
|
|
@@ -4899,7 +4955,7 @@ async function resolveSessionRecord(sessionId) {
|
|
|
4899
4955
|
throw new SessionNotFoundError(sessionId);
|
|
4900
4956
|
}
|
|
4901
4957
|
function hasGitDirectory(dir) {
|
|
4902
|
-
const gitPath =
|
|
4958
|
+
const gitPath = path6.join(dir, ".git");
|
|
4903
4959
|
try {
|
|
4904
4960
|
return statSync(gitPath).isDirectory();
|
|
4905
4961
|
} catch {
|
|
@@ -4907,15 +4963,15 @@ function hasGitDirectory(dir) {
|
|
|
4907
4963
|
}
|
|
4908
4964
|
}
|
|
4909
4965
|
function isWithinBoundary(boundary, target) {
|
|
4910
|
-
const relative =
|
|
4911
|
-
return relative.length === 0 || !relative.startsWith("..") && !
|
|
4966
|
+
const relative = path6.relative(boundary, target);
|
|
4967
|
+
return relative.length === 0 || !relative.startsWith("..") && !path6.isAbsolute(relative);
|
|
4912
4968
|
}
|
|
4913
4969
|
function absolutePath(value) {
|
|
4914
|
-
return
|
|
4970
|
+
return path6.resolve(value);
|
|
4915
4971
|
}
|
|
4916
4972
|
function findGitRepositoryRoot(startDir) {
|
|
4917
4973
|
let current = absolutePath(startDir);
|
|
4918
|
-
const root =
|
|
4974
|
+
const root = path6.parse(current).root;
|
|
4919
4975
|
for (; ; ) {
|
|
4920
4976
|
if (hasGitDirectory(current)) {
|
|
4921
4977
|
return current;
|
|
@@ -4923,7 +4979,7 @@ function findGitRepositoryRoot(startDir) {
|
|
|
4923
4979
|
if (current === root) {
|
|
4924
4980
|
return void 0;
|
|
4925
4981
|
}
|
|
4926
|
-
const parent =
|
|
4982
|
+
const parent = path6.dirname(current);
|
|
4927
4983
|
if (parent === current) {
|
|
4928
4984
|
return void 0;
|
|
4929
4985
|
}
|
|
@@ -4948,7 +5004,7 @@ async function listSessions() {
|
|
|
4948
5004
|
if (!entry.isFile() || !entry.name.endsWith(".json")) {
|
|
4949
5005
|
continue;
|
|
4950
5006
|
}
|
|
4951
|
-
const fullPath =
|
|
5007
|
+
const fullPath = path6.join(sessionBaseDir(), entry.name);
|
|
4952
5008
|
try {
|
|
4953
5009
|
const payload = await fs4.readFile(fullPath, "utf8");
|
|
4954
5010
|
const parsed = parseSessionRecord(JSON.parse(payload));
|
|
@@ -5009,7 +5065,7 @@ async function findSessionByDirectoryWalk(options) {
|
|
|
5009
5065
|
if (dir === walkBoundary) {
|
|
5010
5066
|
return void 0;
|
|
5011
5067
|
}
|
|
5012
|
-
const parent =
|
|
5068
|
+
const parent = path6.dirname(dir);
|
|
5013
5069
|
if (parent === dir) {
|
|
5014
5070
|
return void 0;
|
|
5015
5071
|
}
|
|
@@ -6027,9 +6083,9 @@ async function isLikelyMatchingProcess(pid, agentCommand) {
|
|
|
6027
6083
|
if (argv.length === 0) {
|
|
6028
6084
|
return false;
|
|
6029
6085
|
}
|
|
6030
|
-
const executableBase =
|
|
6031
|
-
const expectedBase =
|
|
6032
|
-
return executableBase === expectedBase || argv.some((entry) =>
|
|
6086
|
+
const executableBase = path7.basename(argv[0]);
|
|
6087
|
+
const expectedBase = path7.basename(expectedToken);
|
|
6088
|
+
return executableBase === expectedBase || argv.some((entry) => path7.basename(entry) === expectedBase);
|
|
6033
6089
|
} catch {
|
|
6034
6090
|
return true;
|
|
6035
6091
|
}
|
|
@@ -6153,7 +6209,7 @@ async function readPromptInputFromStdin() {
|
|
|
6153
6209
|
}
|
|
6154
6210
|
async function readPrompt(promptParts, filePath, cwd) {
|
|
6155
6211
|
if (filePath) {
|
|
6156
|
-
const source = filePath === "-" ? await readPromptInputFromStdin() : await fs6.readFile(
|
|
6212
|
+
const source = filePath === "-" ? await readPromptInputFromStdin() : await fs6.readFile(path8.resolve(cwd, filePath), "utf8");
|
|
6157
6213
|
const pieces = [source.trim(), promptParts.join(" ").trim()].filter(
|
|
6158
6214
|
(value) => value.length > 0
|
|
6159
6215
|
);
|
|
@@ -6294,7 +6350,7 @@ function resolveAgentInvocation(explicitAgentName, globalFlags, config) {
|
|
|
6294
6350
|
return {
|
|
6295
6351
|
agentName,
|
|
6296
6352
|
agentCommand,
|
|
6297
|
-
cwd:
|
|
6353
|
+
cwd: path8.resolve(globalFlags.cwd)
|
|
6298
6354
|
};
|
|
6299
6355
|
}
|
|
6300
6356
|
function printSessionsByFormat(sessions, format) {
|
|
@@ -6433,19 +6489,19 @@ function formatSessionLabel(record) {
|
|
|
6433
6489
|
return record.name ?? "cwd";
|
|
6434
6490
|
}
|
|
6435
6491
|
function formatRoutedFrom(sessionCwd, currentCwd) {
|
|
6436
|
-
const relative =
|
|
6492
|
+
const relative = path8.relative(sessionCwd, currentCwd);
|
|
6437
6493
|
if (!relative || relative === ".") {
|
|
6438
6494
|
return void 0;
|
|
6439
6495
|
}
|
|
6440
|
-
return relative.startsWith(".") ? relative : `.${
|
|
6496
|
+
return relative.startsWith(".") ? relative : `.${path8.sep}${relative}`;
|
|
6441
6497
|
}
|
|
6442
6498
|
function sessionConnectionStatus(record) {
|
|
6443
6499
|
return isProcessAlive(record.pid) ? "connected" : "needs reconnect";
|
|
6444
6500
|
}
|
|
6445
6501
|
function formatPromptSessionBannerLine(record, currentCwd) {
|
|
6446
6502
|
const label = formatSessionLabel(record);
|
|
6447
|
-
const normalizedSessionCwd =
|
|
6448
|
-
const normalizedCurrentCwd =
|
|
6503
|
+
const normalizedSessionCwd = path8.resolve(record.cwd);
|
|
6504
|
+
const normalizedCurrentCwd = path8.resolve(currentCwd);
|
|
6449
6505
|
const routedFrom = normalizedSessionCwd === normalizedCurrentCwd ? void 0 : formatRoutedFrom(normalizedSessionCwd, normalizedCurrentCwd);
|
|
6450
6506
|
const status = sessionConnectionStatus(record);
|
|
6451
6507
|
if (routedFrom) {
|
|
@@ -7257,14 +7313,14 @@ function detectInitialCwd(argv) {
|
|
|
7257
7313
|
if (token === "--cwd") {
|
|
7258
7314
|
const next = argv[index + 1];
|
|
7259
7315
|
if (next && next !== "--") {
|
|
7260
|
-
return
|
|
7316
|
+
return path8.resolve(next);
|
|
7261
7317
|
}
|
|
7262
7318
|
break;
|
|
7263
7319
|
}
|
|
7264
7320
|
if (token.startsWith("--cwd=")) {
|
|
7265
7321
|
const value = token.slice("--cwd=".length).trim();
|
|
7266
7322
|
if (value.length > 0) {
|
|
7267
|
-
return
|
|
7323
|
+
return path8.resolve(value);
|
|
7268
7324
|
}
|
|
7269
7325
|
break;
|
|
7270
7326
|
}
|
|
@@ -7365,7 +7421,7 @@ async function main(argv = process.argv) {
|
|
|
7365
7421
|
DEFAULT_QUEUE_OWNER_TTL_MS
|
|
7366
7422
|
);
|
|
7367
7423
|
const program = new Command();
|
|
7368
|
-
program.name("acpx").description("Headless CLI client for the Agent Client Protocol").enablePositionalOptions().showHelpAfterError();
|
|
7424
|
+
program.name("acpx").description("Headless CLI client for the Agent Client Protocol").version(getAcpxVersion()).enablePositionalOptions().showHelpAfterError();
|
|
7369
7425
|
if (requestedJsonStrict) {
|
|
7370
7426
|
program.configureOutput({
|
|
7371
7427
|
writeOut: () => {
|