acpx 0.15.0 → 0.16.0

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 (39) hide show
  1. package/dist/agent-registry-DU6mhZBL.js +785 -0
  2. package/dist/agent-registry-DU6mhZBL.js.map +1 -0
  3. package/dist/agent-registry.d.ts +70 -0
  4. package/dist/agent-registry.d.ts.map +1 -0
  5. package/dist/agent-registry.js +2 -0
  6. package/dist/{cli-Cen2Rb6S.js → cli-BkYIxj_N.js} +6 -14
  7. package/dist/cli-BkYIxj_N.js.map +1 -0
  8. package/dist/cli.d.ts +1 -1
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +137 -333
  11. package/dist/cli.js.map +1 -1
  12. package/dist/{client-Cvz6msGc.d.ts → client-5levcBIs.d.ts} +11 -9
  13. package/dist/client-5levcBIs.d.ts.map +1 -0
  14. package/dist/{flows-D-F3Y2o9.js → flows-Bxs4udrs.js} +205 -277
  15. package/dist/flows-Bxs4udrs.js.map +1 -0
  16. package/dist/flows.d.ts +6 -17
  17. package/dist/flows.d.ts.map +1 -1
  18. package/dist/flows.js +1 -1
  19. package/dist/{flags-CRh8BJre.js → invocation-options-BY4lxkn3.js} +82 -58
  20. package/dist/invocation-options-BY4lxkn3.js.map +1 -0
  21. package/dist/{live-checkpoint-CYRs-D9t.js → live-checkpoint-BEfxBKCh.js} +1033 -1437
  22. package/dist/live-checkpoint-BEfxBKCh.js.map +1 -0
  23. package/dist/{output-CIVecnHU.js → output-uo5a27KB.js} +487 -490
  24. package/dist/output-uo5a27KB.js.map +1 -0
  25. package/dist/runtime.d.ts +105 -22
  26. package/dist/runtime.d.ts.map +1 -1
  27. package/dist/runtime.js +582 -366
  28. package/dist/runtime.js.map +1 -1
  29. package/dist/{session-options-DyIGRNfu.d.ts → session-options-t3d-F4dn.d.ts} +8 -6
  30. package/dist/session-options-t3d-F4dn.d.ts.map +1 -0
  31. package/package.json +27 -25
  32. package/skills/acpx/SKILL.md +19 -17
  33. package/dist/cli-Cen2Rb6S.js.map +0 -1
  34. package/dist/client-Cvz6msGc.d.ts.map +0 -1
  35. package/dist/flags-CRh8BJre.js.map +0 -1
  36. package/dist/flows-D-F3Y2o9.js.map +0 -1
  37. package/dist/live-checkpoint-CYRs-D9t.js.map +0 -1
  38. package/dist/output-CIVecnHU.js.map +0 -1
  39. package/dist/session-options-DyIGRNfu.d.ts.map +0 -1
@@ -0,0 +1,785 @@
1
+ import fs from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ import path from "node:path";
4
+ import { execFile } from "node:child_process";
5
+ //#region src/acp/client-process.ts
6
+ const PROCESS_HELPER_TIMEOUT_MS = 8e3;
7
+ async function runTimedExecFile(command, args, options = {}) {
8
+ const timeoutMs = Math.max(1, Math.round(options.timeoutMs ?? 8e3));
9
+ return await new Promise((resolve, reject) => {
10
+ let settled = false;
11
+ let timer;
12
+ const child = execFile(command, [...args], {
13
+ encoding: "utf8",
14
+ maxBuffer: options.maxBufferBytes ?? 33554432,
15
+ killSignal: "SIGKILL",
16
+ windowsHide: options.windowsHide
17
+ }, (error, stdout) => {
18
+ if (settled) return;
19
+ settled = true;
20
+ if (timer) clearTimeout(timer);
21
+ if (error) {
22
+ reject(error);
23
+ return;
24
+ }
25
+ resolve(stdout);
26
+ });
27
+ timer = setTimeout(() => {
28
+ if (settled) return;
29
+ settled = true;
30
+ const killed = child.kill("SIGKILL");
31
+ child.stdout?.destroy();
32
+ child.stderr?.destroy();
33
+ child.unref();
34
+ reject(Object.assign(/* @__PURE__ */ new Error(`${command} timed out after ${timeoutMs}ms`), {
35
+ code: "ETIMEDOUT",
36
+ killed,
37
+ signal: "SIGKILL"
38
+ }));
39
+ }, timeoutMs);
40
+ });
41
+ }
42
+ function normalizeAgentCommandInput(value) {
43
+ if (typeof value === "string") return { agentCommand: value };
44
+ const parts = toCommandParts([...value]);
45
+ const argv = [parts.command, ...parts.args];
46
+ return {
47
+ agentCommand: renderArgvIdentity(argv),
48
+ agentArgv: argv
49
+ };
50
+ }
51
+ const IDENTITY_SAFE_ARG_RE = /^[A-Za-z0-9_@%+=:,./^~-]+$/u;
52
+ function renderArgvIdentity(argv) {
53
+ return argv.map((arg) => IDENTITY_SAFE_ARG_RE.test(arg) ? arg : JSON.stringify(arg)).join(" ");
54
+ }
55
+ function isoNow() {
56
+ return (/* @__PURE__ */ new Date()).toISOString();
57
+ }
58
+ function waitForSpawn(child) {
59
+ return new Promise((resolve, reject) => {
60
+ const onSpawn = () => {
61
+ child.off("error", onError);
62
+ resolve();
63
+ };
64
+ const onError = (error) => {
65
+ child.off("spawn", onSpawn);
66
+ reject(error);
67
+ };
68
+ child.once("spawn", onSpawn);
69
+ child.once("error", onError);
70
+ });
71
+ }
72
+ function isChildProcessRunning(child) {
73
+ return child.exitCode == null && child.signalCode == null;
74
+ }
75
+ function requireAgentStdio(child) {
76
+ if (!child.stdin || !child.stdout || !child.stderr) throw new Error("ACP agent must be spawned with piped stdin/stdout/stderr");
77
+ return child;
78
+ }
79
+ function waitForChildExit(child, timeoutMs) {
80
+ if (!isChildProcessRunning(child)) return Promise.resolve(true);
81
+ return new Promise((resolve) => {
82
+ let settled = false;
83
+ const timer = setTimeout(() => {
84
+ finish(false);
85
+ }, Math.max(0, timeoutMs));
86
+ const finish = (value) => {
87
+ if (settled) return;
88
+ settled = true;
89
+ child.off("close", onExitLike);
90
+ child.off("exit", onExitLike);
91
+ clearTimeout(timer);
92
+ resolve(value);
93
+ };
94
+ const onExitLike = () => {
95
+ finish(true);
96
+ };
97
+ child.once("close", onExitLike);
98
+ child.once("exit", onExitLike);
99
+ });
100
+ }
101
+ function resolveAgentCommandParts(value, argv, platform = process.platform) {
102
+ if (argv) {
103
+ const parts = toCommandParts([...argv]);
104
+ assertWindowsLaunchableCommand(parts.command, platform);
105
+ return parts;
106
+ }
107
+ if (platform === "win32") throw new Error("Raw agent command strings are not supported on Windows. Configure the agent with an argv array, for example: \"argv\": [\"agent.exe\", \"--acp\"]. Legacy agents.<name>.args arrays are migrated automatically. Existing sessions without saved argv must be closed and recreated.");
108
+ return splitCommandLine(value);
109
+ }
110
+ function assertWindowsLaunchableCommand(command, platform) {
111
+ if (platform === "win32" && path.extname(command).toLowerCase() === ".sh") throw new Error(`Windows cannot launch shell script executable "${command}" directly. Configure an explicit interpreter argv, for example: "argv": ["bash", "${command}"]. acpx does not infer interpreters.`);
112
+ }
113
+ function splitCommandLine(value) {
114
+ const state = {
115
+ current: "",
116
+ quote: null,
117
+ escaping: false,
118
+ parts: [],
119
+ hasPart: false
120
+ };
121
+ for (const ch of value) readCommandLineChar(state, ch);
122
+ if (state.escaping) {
123
+ state.current += "\\";
124
+ state.hasPart = true;
125
+ }
126
+ if (state.quote) throw new Error("Invalid --agent command: unterminated quote");
127
+ flushCommandLinePart(state);
128
+ return toCommandParts(state.parts);
129
+ }
130
+ function toCommandParts(parts) {
131
+ if (parts.length === 0 || parts[0] === "") throw new Error("Invalid --agent command: empty command");
132
+ return {
133
+ command: parts[0],
134
+ args: parts.slice(1)
135
+ };
136
+ }
137
+ function readCommandLineChar(state, ch) {
138
+ if (state.escaping) {
139
+ state.current += ch;
140
+ state.escaping = false;
141
+ state.hasPart = true;
142
+ } else if (ch === "\\" && state.quote !== "'") state.escaping = true;
143
+ else if (state.quote) {
144
+ if (ch === state.quote) state.quote = null;
145
+ else state.current += ch;
146
+ state.hasPart = true;
147
+ } else readUnquotedCommandLineChar(state, ch);
148
+ }
149
+ function readUnquotedCommandLineChar(state, ch) {
150
+ if (ch === "'" || ch === "\"") {
151
+ state.quote = ch;
152
+ state.hasPart = true;
153
+ } else if (/\s/.test(ch)) flushCommandLinePart(state);
154
+ else {
155
+ state.current += ch;
156
+ state.hasPart = true;
157
+ }
158
+ }
159
+ function flushCommandLinePart(state) {
160
+ if (state.hasPart) {
161
+ state.parts.push(state.current);
162
+ state.current = "";
163
+ state.hasPart = false;
164
+ }
165
+ }
166
+ function asAbsoluteCwd(cwd) {
167
+ return path.resolve(cwd);
168
+ }
169
+ async function resolveAgentSessionCwd(cwd, agentCommand, options = {}) {
170
+ const resolved = asAbsoluteCwd(cwd);
171
+ if (!shouldTranslateWslWindowsCwd(agentCommand, options)) return resolved;
172
+ const translated = (await (options.runWslpath ?? runWslpath)(resolved)).trim();
173
+ if (!translated) throw new Error(`wslpath returned an empty Windows path for cwd: ${resolved}`);
174
+ return translated;
175
+ }
176
+ function shouldTranslateWslWindowsCwd(agentCommand, options) {
177
+ if (!isWsl(options)) return false;
178
+ try {
179
+ const { command } = splitCommandLine(agentCommand);
180
+ return isWindowsExecutableCommand(command);
181
+ } catch {
182
+ return false;
183
+ }
184
+ }
185
+ function isWsl(options) {
186
+ if ((options.platform ?? process.platform) !== "linux") return false;
187
+ return (options.existsSync ?? fs.existsSync)("/proc/sys/fs/binfmt_misc/WSLInterop");
188
+ }
189
+ const WINDOWS_EXECUTABLE_EXTENSION_RE = /\.(?:exe|cmd|bat)$/u;
190
+ function isWindowsExecutableCommand(command) {
191
+ const normalized = command.toLowerCase();
192
+ return WINDOWS_EXECUTABLE_EXTENSION_RE.test(normalized);
193
+ }
194
+ async function runWslpath(cwd) {
195
+ return await runTimedExecFile("wslpath", ["-w", cwd]);
196
+ }
197
+ function basenameToken(value) {
198
+ return path.basename(value).toLowerCase().replace(/\.(cmd|exe|bat)$/u, "");
199
+ }
200
+ //#endregion
201
+ //#region src/spawn-command-options.ts
202
+ function readWindowsEnvValue(env, key) {
203
+ const matchedKey = Object.keys(env).find((entry) => entry.toUpperCase() === key);
204
+ return matchedKey ? env[matchedKey] : void 0;
205
+ }
206
+ function windowsExecutableExtensions(env) {
207
+ return (readWindowsEnvValue(env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((value) => value.trim().toLowerCase()).filter((value) => value.length > 0);
208
+ }
209
+ function commandCandidates(command, env) {
210
+ if (path.extname(command).length > 0) return [command];
211
+ return windowsExecutableExtensions(env).map((extension) => `${command}${extension}`);
212
+ }
213
+ function commandHasPath(command) {
214
+ return command.includes("/") || command.includes("\\") || path.isAbsolute(command);
215
+ }
216
+ function resolveWindowsPathCommand(command, env) {
217
+ const candidates = commandCandidates(command, env);
218
+ const pathValue = readWindowsEnvValue(env, "PATH");
219
+ if (!pathValue) return;
220
+ for (const directory of pathValue.split(";")) {
221
+ const resolved = findExistingCommandInDirectory(directory, candidates);
222
+ if (resolved) return resolved;
223
+ }
224
+ }
225
+ function findExistingCommandInDirectory(directory, candidates) {
226
+ const trimmedDirectory = directory.trim();
227
+ if (trimmedDirectory.length === 0) return;
228
+ return candidates.map((candidate) => path.join(trimmedDirectory, candidate)).find((resolved) => fs.existsSync(resolved));
229
+ }
230
+ function resolveWindowsWrapperToken(token, wrapperPath) {
231
+ const relative = token.match(/%~?dp0%?\s*[\\/]*(.*)$/i)?.[1]?.trim();
232
+ if (!relative) return;
233
+ const candidate = path.resolve(path.dirname(wrapperPath), relative.replace(/[\\/]+/g, path.sep).replace(/^[\\/]+/, ""));
234
+ return path.extname(candidate).toLowerCase() === ".exe" && fs.existsSync(candidate) ? candidate : void 0;
235
+ }
236
+ function resolveWindowsWrapperExecutable(wrapperPath) {
237
+ if (!fs.existsSync(wrapperPath)) return;
238
+ try {
239
+ return [...fs.readFileSync(wrapperPath, "utf8").matchAll(/"([^"\r\n]*)"/g)].map((match) => resolveWindowsWrapperToken(match[1] ?? "", wrapperPath)).find((candidate) => candidate !== void 0);
240
+ } catch {
241
+ return;
242
+ }
243
+ }
244
+ function resolveWindowsCommand(command, env = process.env) {
245
+ const candidates = commandCandidates(command, env);
246
+ if (commandHasPath(command)) return candidates.find((candidate) => fs.existsSync(candidate));
247
+ return resolveWindowsPathCommand(command, env);
248
+ }
249
+ /**
250
+ * Resolve a Windows command to a native executable suitable for direct spawn.
251
+ *
252
+ * Batch and PowerShell shims are intentionally rejected unless they point at a
253
+ * real `.exe` entrypoint. Callers that need shell execution should use the
254
+ * command-specific shell policy instead.
255
+ */
256
+ function resolveWindowsExecutablePath(command, env = process.env) {
257
+ const resolved = resolveWindowsCommand(command, env);
258
+ if (!resolved) return;
259
+ const absolute = path.resolve(resolved);
260
+ const extension = path.extname(absolute).toLowerCase();
261
+ if (extension === ".exe") return absolute;
262
+ if (extension !== ".cmd" && extension !== ".bat" && extension !== ".ps1") return;
263
+ const siblingExecutable = `${absolute.slice(0, -extension.length)}.exe`;
264
+ return fs.existsSync(siblingExecutable) ? siblingExecutable : resolveWindowsWrapperExecutable(absolute);
265
+ }
266
+ function shouldUseWindowsBatchShell(command, platform = process.platform, env = process.env) {
267
+ if (platform !== "win32") return false;
268
+ const resolvedCommand = resolveWindowsCommand(command, env) ?? command;
269
+ const ext = path.extname(resolvedCommand).toLowerCase();
270
+ return ext === ".cmd" || ext === ".bat";
271
+ }
272
+ const CMD_META_CHAR_RE = /([()\][%!^"`<>&|;, *?])/gu;
273
+ const CMD_BACKSLASH_QUOTE_RE = /(?=(\\+?)?)\1"/gu;
274
+ const CMD_TRAILING_BACKSLASH_RE = /(?=(\\+?)?)\1$/gu;
275
+ const CMD_SHIM_RE = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/iu;
276
+ function escapeCmdCommand(value) {
277
+ return value.replace(CMD_META_CHAR_RE, "^$1");
278
+ }
279
+ function escapeCmdArgument(value, doubleEscapeMeta) {
280
+ const escaped = `"${value.replace(CMD_BACKSLASH_QUOTE_RE, "$1$1\\\"").replace(CMD_TRAILING_BACKSLASH_RE, "$1$1")}"`.replace(CMD_META_CHAR_RE, "^$1");
281
+ return doubleEscapeMeta ? escaped.replace(CMD_META_CHAR_RE, "^$1") : escaped;
282
+ }
283
+ function buildAgentSpawnCommand(command, args, platform = process.platform, env = process.env) {
284
+ if (!shouldUseWindowsBatchShell(command, platform, env)) return {
285
+ command,
286
+ args: [...args]
287
+ };
288
+ const resolvedCommand = path.win32.normalize(resolveWindowsCommand(command, env) ?? command);
289
+ const doubleEscapeMeta = CMD_SHIM_RE.test(resolvedCommand);
290
+ const shellCommand = [escapeCmdCommand(resolvedCommand), ...args.map((arg) => escapeCmdArgument(arg, doubleEscapeMeta))].join(" ");
291
+ return {
292
+ command: readWindowsEnvValue(env, "COMSPEC") ?? "cmd.exe",
293
+ args: [
294
+ "/d",
295
+ "/s",
296
+ "/c",
297
+ `"${shellCommand}"`
298
+ ],
299
+ windowsVerbatimArguments: true
300
+ };
301
+ }
302
+ function buildSpawnCommandOptions(command, options, platform = process.platform, env = process.env) {
303
+ if (!shouldUseWindowsBatchShell(command, platform, env)) return options;
304
+ return {
305
+ ...options,
306
+ shell: true
307
+ };
308
+ }
309
+ function buildTerminalSpawnCommand(command, args) {
310
+ return {
311
+ command,
312
+ args: args ?? [],
313
+ killProcessGroup: false
314
+ };
315
+ }
316
+ function buildTerminalShellSpawnCommand(command, platform = process.platform) {
317
+ if (platform === "win32") return {
318
+ command: "cmd.exe",
319
+ args: [
320
+ "/d",
321
+ "/s",
322
+ "/c",
323
+ command
324
+ ],
325
+ killProcessGroup: true
326
+ };
327
+ return {
328
+ command: "/bin/sh",
329
+ args: ["-c", command],
330
+ killProcessGroup: true
331
+ };
332
+ }
333
+ /** Finds an installed entrypoint without executing it. */
334
+ function resolveInstalledExecutable(command) {
335
+ if (process.platform === "win32") {
336
+ const resolved = resolveWindowsCommand(command);
337
+ return resolved && fs.statSync(resolved, { throwIfNoEntry: false })?.isFile() ? path.resolve(resolved) : void 0;
338
+ }
339
+ return (command.includes("/") ? [path.resolve(command)] : (process.env.PATH ?? "").split(path.delimiter).map((directory) => path.resolve(directory, command))).find((candidate) => {
340
+ try {
341
+ fs.accessSync(candidate, fs.constants.X_OK);
342
+ return fs.statSync(candidate).isFile();
343
+ } catch {
344
+ return false;
345
+ }
346
+ });
347
+ }
348
+ //#endregion
349
+ //#region src/agent-registry.ts
350
+ const ACP_ADAPTER_PACKAGE_RANGES = {
351
+ pi: "^0.0.33",
352
+ codex: "^1.1.5",
353
+ claude: "^0.76.0",
354
+ mux: "^0.28.0"
355
+ };
356
+ const AGENT_DEFINITIONS = {
357
+ pi: {
358
+ name: "Pi",
359
+ argv: ["npx", `pi-acp@${ACP_ADAPTER_PACKAGE_RANGES.pi}`],
360
+ installedArgv: ["pi-acp"],
361
+ requiredCommands: ["pi"],
362
+ package: {
363
+ packageName: "pi-acp",
364
+ packageRange: ACP_ADAPTER_PACKAGE_RANGES.pi,
365
+ preferredBinName: "pi-acp"
366
+ }
367
+ },
368
+ openclaw: {
369
+ name: "OpenClaw",
370
+ argv: ["openclaw", "acp"]
371
+ },
372
+ codex: {
373
+ name: "Codex",
374
+ argv: [
375
+ "npx",
376
+ "-y",
377
+ `@agentclientprotocol/codex-acp@${ACP_ADAPTER_PACKAGE_RANGES.codex}`
378
+ ],
379
+ installedArgv: ["codex-acp"],
380
+ package: {
381
+ packageName: "@agentclientprotocol/codex-acp",
382
+ packageRange: ACP_ADAPTER_PACKAGE_RANGES.codex,
383
+ preferredBinName: "codex-acp",
384
+ legacyFallbackCommands: []
385
+ },
386
+ packageExecFallback: true
387
+ },
388
+ claude: {
389
+ name: "Claude Code",
390
+ argv: [
391
+ "npx",
392
+ "-y",
393
+ `@agentclientprotocol/claude-agent-acp@${ACP_ADAPTER_PACKAGE_RANGES.claude}`
394
+ ],
395
+ installedArgv: ["claude-agent-acp"],
396
+ package: {
397
+ packageName: "@agentclientprotocol/claude-agent-acp",
398
+ packageRange: ACP_ADAPTER_PACKAGE_RANGES.claude,
399
+ preferredBinName: "claude-agent-acp",
400
+ legacyFallbackCommands: [`npm exec @agentclientprotocol/claude-agent-acp@${ACP_ADAPTER_PACKAGE_RANGES.claude}`]
401
+ },
402
+ packageExecFallback: true
403
+ },
404
+ gemini: {
405
+ name: "Gemini CLI",
406
+ argv: ["gemini", "--acp"]
407
+ },
408
+ cursor: {
409
+ name: "Cursor",
410
+ argv: ["cursor-agent", "acp"]
411
+ },
412
+ copilot: {
413
+ name: "GitHub Copilot",
414
+ argv: [
415
+ "copilot",
416
+ "--acp",
417
+ "--stdio"
418
+ ]
419
+ },
420
+ devin: {
421
+ name: "Devin",
422
+ argv: ["devin", "acp"]
423
+ },
424
+ droid: {
425
+ name: "Factory Droid",
426
+ argv: [
427
+ "droid",
428
+ "exec",
429
+ "--output-format",
430
+ "acp"
431
+ ]
432
+ },
433
+ "fast-agent": {
434
+ name: "Fast Agent",
435
+ argv: [
436
+ "uvx",
437
+ "fast-agent-mcp",
438
+ "acp"
439
+ ]
440
+ },
441
+ fx: {
442
+ name: "fx",
443
+ argv: ["fx", "acp"]
444
+ },
445
+ "grok-build": {
446
+ name: "Grok Build",
447
+ argv: [
448
+ "grok",
449
+ "agent",
450
+ "stdio"
451
+ ]
452
+ },
453
+ iflow: {
454
+ name: "iFlow",
455
+ argv: ["iflow", "--experimental-acp"]
456
+ },
457
+ junie: {
458
+ name: "Junie",
459
+ argv: ["junie", "--acp=true"]
460
+ },
461
+ kilocode: {
462
+ name: "Kilo Code",
463
+ argv: [
464
+ "npx",
465
+ "-y",
466
+ "@kilocode/cli",
467
+ "acp"
468
+ ],
469
+ installedArgv: ["kilo", "acp"]
470
+ },
471
+ kimi: {
472
+ name: "Kimi Code",
473
+ argv: ["kimi", "acp"]
474
+ },
475
+ kiro: {
476
+ name: "Kiro",
477
+ argv: ["kiro-cli-chat", "acp"]
478
+ },
479
+ mcode: {
480
+ name: "MCode",
481
+ argv: ["mcode", "acp"]
482
+ },
483
+ mux: {
484
+ name: "Mux",
485
+ argv: [
486
+ "npx",
487
+ "-y",
488
+ `mux@${ACP_ADAPTER_PACKAGE_RANGES.mux}`,
489
+ "acp"
490
+ ]
491
+ },
492
+ opencode: {
493
+ name: "OpenCode",
494
+ argv: [
495
+ "npx",
496
+ "-y",
497
+ "opencode-ai",
498
+ "acp"
499
+ ],
500
+ installedArgv: ["opencode", "acp"]
501
+ },
502
+ pool: {
503
+ name: "Poolside",
504
+ argv: ["pool", "acp"]
505
+ },
506
+ qoder: {
507
+ name: "Qoder",
508
+ argv: ["qodercli", "--acp"]
509
+ },
510
+ qwen: {
511
+ name: "Qwen Code",
512
+ argv: ["qwen", "--acp"]
513
+ },
514
+ trae: {
515
+ name: "Trae",
516
+ argv: [
517
+ "traecli",
518
+ "acp",
519
+ "serve"
520
+ ]
521
+ },
522
+ zeroclaw: {
523
+ name: "ZeroClaw",
524
+ argv: ["zeroclaw", "acp"]
525
+ }
526
+ };
527
+ const AGENT_ARGV_REGISTRY = Object.fromEntries(Object.entries(AGENT_DEFINITIONS).map(([id, definition]) => [id, [...definition.argv]]));
528
+ const AGENT_REGISTRY = Object.fromEntries(Object.entries(AGENT_DEFINITIONS).map(([id, definition]) => [id, definition.argv.join(" ")]));
529
+ const BUILT_IN_AGENT_PACKAGES = Object.fromEntries(Object.entries(AGENT_DEFINITIONS).flatMap(([id, definition]) => definition.packageExecFallback && definition.package ? [[id, {
530
+ ...definition.package,
531
+ fallbackCommand: definition.argv.join(" ")
532
+ }]] : []));
533
+ function isPackageExecution(argv) {
534
+ const command = path.win32.basename(argv[0]).toLowerCase().replace(/\.(cmd|exe|bat)$/, "");
535
+ if ([
536
+ "npx",
537
+ "uvx",
538
+ "npm",
539
+ "pnpm",
540
+ "bunx"
541
+ ].includes(command)) return true;
542
+ switch (command) {
543
+ case "bun": return argv[1] === "x";
544
+ case "uv": return argv[1] === "tool" && argv[2] === "run";
545
+ case "node": return /(?:npm|npx)-cli\.js$/u.test(argv[1] ?? "");
546
+ default: return false;
547
+ }
548
+ }
549
+ function inspectionDefinition(id, override) {
550
+ const definition = Object.hasOwn(AGENT_DEFINITIONS, id) ? AGENT_DEFINITIONS[id] : void 0;
551
+ if (!override) return definition;
552
+ let argv = override;
553
+ if (typeof argv === "string") {
554
+ const parsed = splitCommandLine(argv);
555
+ argv = [parsed.command, ...parsed.args];
556
+ }
557
+ return {
558
+ name: definition?.name ?? id,
559
+ argv
560
+ };
561
+ }
562
+ function inspectAgent(agentId, override, options = {}) {
563
+ const id = resolveCanonicalAgentName(agentId);
564
+ const definition = inspectionDefinition(id, override);
565
+ if (!definition) return;
566
+ const argv = definition.installedArgv ?? definition.argv;
567
+ if (isPackageExecution(argv)) return;
568
+ const launch = inspectLaunch(argv, definition.package ? {
569
+ ...definition.package,
570
+ fallbackCommand: definition.argv.join(" ")
571
+ } : void 0, options);
572
+ return {
573
+ id,
574
+ name: definition.name,
575
+ launch: inspectPrerequisites(launch, definition.requiredCommands ?? [], options)
576
+ };
577
+ }
578
+ function inspectPrerequisites(launch, requiredCommands, options) {
579
+ const resolveExecutable = options.resolveExecutable ?? resolveInstalledExecutable;
580
+ const missingCommands = requiredCommands.filter((command) => !resolveExecutable(command)).map((name) => ({
581
+ kind: "command",
582
+ name
583
+ }));
584
+ if (missingCommands.length === 0) return launch;
585
+ return {
586
+ kind: "missing",
587
+ requirements: [...launch.kind === "missing" ? launch.requirements : [], ...missingCommands]
588
+ };
589
+ }
590
+ function inspectLaunch(argv, spec, options) {
591
+ const command = (options.resolveExecutable ?? resolveInstalledExecutable)(argv[0]);
592
+ if (command) return {
593
+ kind: "installed",
594
+ argv: [command, ...argv.slice(1)]
595
+ };
596
+ if (!spec) return {
597
+ kind: "missing",
598
+ requirements: [{
599
+ kind: "command",
600
+ name: argv[0]
601
+ }]
602
+ };
603
+ const installed = resolveInstalledBuiltInAgentLaunchForSpec(spec, options);
604
+ return installed ? {
605
+ kind: "installed",
606
+ argv: [installed.command, ...installed.args]
607
+ } : {
608
+ kind: "missing",
609
+ requirements: [{
610
+ kind: "package",
611
+ name: spec.packageName
612
+ }]
613
+ };
614
+ }
615
+ const AGENT_ALIASES = {
616
+ "factory-droid": "droid",
617
+ factorydroid: "droid"
618
+ };
619
+ const DEFAULT_AGENT_NAME = "codex";
620
+ function normalizeAgentName(value) {
621
+ return value.trim().toLowerCase();
622
+ }
623
+ function resolveCanonicalAgentName(value) {
624
+ const normalized = normalizeAgentName(value);
625
+ return Object.hasOwn(AGENT_ALIASES, normalized) ? AGENT_ALIASES[normalized] : normalized;
626
+ }
627
+ function mergeAgentRegistry(overrides) {
628
+ if (!overrides) return { ...AGENT_REGISTRY };
629
+ const merged = { ...AGENT_REGISTRY };
630
+ for (const [name, command] of Object.entries(overrides)) {
631
+ const normalized = normalizeAgentName(name);
632
+ if (!normalized || !command.trim()) continue;
633
+ merged[normalized] = command.trim();
634
+ }
635
+ return merged;
636
+ }
637
+ function resolveAgentCommand(agentName, overrides) {
638
+ const normalized = normalizeAgentName(agentName);
639
+ const registry = mergeAgentRegistry(overrides);
640
+ return registry[normalized] ?? registry[AGENT_ALIASES[normalized] ?? normalized] ?? agentName;
641
+ }
642
+ function resolveAgentArgv(agentName) {
643
+ const normalized = normalizeAgentName(agentName);
644
+ const argv = AGENT_ARGV_REGISTRY[normalized] ?? AGENT_ARGV_REGISTRY[resolveCanonicalAgentName(agentName)];
645
+ return argv ? [...argv] : void 0;
646
+ }
647
+ function findBuiltInAgentPackage(agentCommand) {
648
+ const normalized = agentCommand.trim();
649
+ return Object.values(BUILT_IN_AGENT_PACKAGES).find((spec) => spec.fallbackCommand === normalized || spec.legacyFallbackCommands?.includes(normalized));
650
+ }
651
+ function defaultResolvePackageRoot(packageName) {
652
+ const segments = packageName.split("/");
653
+ let cursor = path.dirname(fileURLToPath(import.meta.url));
654
+ while (true) {
655
+ const candidateRoot = path.join(cursor, "node_modules", ...segments);
656
+ const manifestPath = path.join(candidateRoot, "package.json");
657
+ if (fs.existsSync(manifestPath)) try {
658
+ if (JSON.parse(fs.readFileSync(manifestPath, "utf8")).name === packageName) return candidateRoot;
659
+ } catch {}
660
+ const parent = path.dirname(cursor);
661
+ if (parent === cursor) throw new Error(`Built-in agent package not found: ${packageName}`);
662
+ cursor = parent;
663
+ }
664
+ }
665
+ function resolvePackageBin(spec, manifest) {
666
+ if (typeof manifest.bin === "string") return manifest.bin;
667
+ if (!manifest.bin || typeof manifest.bin !== "object") return;
668
+ return manifest.bin[spec.preferredBinName] ?? (Object.keys(manifest.bin).length === 1 ? Object.values(manifest.bin)[0] : void 0);
669
+ }
670
+ function defaultResolveNpmCliPath(execPath) {
671
+ const candidate = path.resolve(path.dirname(execPath), "..", "lib", "node_modules", "npm", "bin", "npm-cli.js");
672
+ if (!fs.existsSync(candidate)) throw new Error(`npm CLI not found for execPath: ${execPath}`);
673
+ return candidate;
674
+ }
675
+ function resolveInstalledBuiltInAgentLaunch(agentCommand, options = {}) {
676
+ const spec = findBuiltInAgentPackage(agentCommand);
677
+ if (!spec) return;
678
+ return resolveInstalledBuiltInAgentLaunchForSpec(spec, options);
679
+ }
680
+ function resolveInstalledBuiltInAgentLaunchForSpec(spec, options) {
681
+ const readFileSync = options.readFileSync ?? fs.readFileSync;
682
+ const existsSync = options.existsSync ?? fs.existsSync;
683
+ const resolvePackageRoot = options.resolvePackageRoot ?? defaultResolvePackageRoot;
684
+ try {
685
+ const resolved = resolveInstalledBuiltInAgentPackage(spec, {
686
+ readFileSync,
687
+ existsSync,
688
+ resolvePackageRoot
689
+ });
690
+ if (!resolved) return;
691
+ return {
692
+ source: "installed",
693
+ command: process.execPath,
694
+ args: [resolved.binPath],
695
+ packageName: spec.packageName,
696
+ packageRange: spec.packageRange,
697
+ packageVersion: resolved.packageVersion,
698
+ binPath: resolved.binPath
699
+ };
700
+ } catch {
701
+ return;
702
+ }
703
+ }
704
+ function resolveInstalledBuiltInAgentPackage(spec, options) {
705
+ const packageRoot = options.resolvePackageRoot(spec.packageName);
706
+ if (!packageRoot) return;
707
+ const manifest = JSON.parse(options.readFileSync(path.join(packageRoot, "package.json"), "utf8"));
708
+ if (manifest.name !== spec.packageName) return;
709
+ const relativeBinPath = resolvePackageBin(spec, manifest);
710
+ if (!relativeBinPath) return;
711
+ const binPath = path.resolve(packageRoot, relativeBinPath);
712
+ return options.existsSync(binPath) ? {
713
+ packageVersion: manifest.version,
714
+ binPath
715
+ } : void 0;
716
+ }
717
+ function resolvePackageExecBuiltInAgentLaunch(agentCommand, options = {}) {
718
+ const spec = findBuiltInAgentPackage(agentCommand);
719
+ if (!spec) return;
720
+ const existsSync = options.existsSync ?? fs.existsSync;
721
+ const execPath = options.execPath ?? process.execPath;
722
+ const resolveNpmCliPath = options.resolveNpmCliPath ?? defaultResolveNpmCliPath;
723
+ try {
724
+ const npmCliPath = resolveNpmCliPath(execPath);
725
+ if (!existsSync(npmCliPath)) return;
726
+ return {
727
+ source: "package-exec",
728
+ command: execPath,
729
+ args: [
730
+ npmCliPath,
731
+ "exec",
732
+ "--yes",
733
+ `--package=${spec.packageName}@${spec.packageRange}`,
734
+ "--",
735
+ spec.preferredBinName
736
+ ],
737
+ packageName: spec.packageName,
738
+ packageRange: spec.packageRange,
739
+ npmCliPath
740
+ };
741
+ } catch {
742
+ return;
743
+ }
744
+ }
745
+ function resolveBuiltInAgentLaunch(agentCommand, options = {}) {
746
+ return resolveInstalledBuiltInAgentLaunch(agentCommand, options) ?? resolvePackageExecBuiltInAgentLaunch(agentCommand, options);
747
+ }
748
+ function listBuiltInAgents(overrides) {
749
+ return [.../* @__PURE__ */ new Set([...Object.keys(AGENT_REGISTRY), ...Object.keys(overrides ?? {})])];
750
+ }
751
+ function createAgentRegistry(params) {
752
+ const overrides = normalizeRegistryOverrides(params?.overrides);
753
+ return {
754
+ resolve(agentName) {
755
+ const normalizedAgentName = normalizeAgentName(agentName);
756
+ return overrides[normalizedAgentName] ?? overrides[resolveCanonicalAgentName(agentName)] ?? resolveAgentArgv(agentName) ?? resolveAgentCommand(agentName);
757
+ },
758
+ list() {
759
+ return listBuiltInAgents(overrides);
760
+ },
761
+ inspect(agentId) {
762
+ const normalized = normalizeAgentName(agentId);
763
+ const canonical = resolveCanonicalAgentName(agentId);
764
+ return inspectAgent(agentId, Object.hasOwn(overrides, normalized) ? overrides[normalized] : Object.hasOwn(overrides, canonical) ? overrides[canonical] : void 0, params);
765
+ }
766
+ };
767
+ }
768
+ function normalizeRegistryOverrides(values) {
769
+ const normalized = {};
770
+ for (const [name, value] of Object.entries(values ?? {})) {
771
+ const normalizedName = normalizeAgentName(name);
772
+ if (!normalizedName) continue;
773
+ const normalizedValue = normalizeRegistryOverride(value);
774
+ if (normalizedValue) normalized[normalizedName] = normalizedValue;
775
+ }
776
+ return normalized;
777
+ }
778
+ function normalizeRegistryOverride(value) {
779
+ if (typeof value === "string") return value.trim() || void 0;
780
+ return value.length > 0 && value[0]?.length ? [...value] : void 0;
781
+ }
782
+ //#endregion
783
+ export { resolveAgentCommandParts as A, asAbsoluteCwd as C, normalizeAgentCommandInput as D, isoNow as E, waitForSpawn as F, runTimedExecFile as M, splitCommandLine as N, renderArgvIdentity as O, waitForChildExit as P, PROCESS_HELPER_TIMEOUT_MS as S, isChildProcessRunning as T, buildSpawnCommandOptions as _, createAgentRegistry as a, readWindowsEnvValue as b, mergeAgentRegistry as c, resolveAgentCommand as d, resolveBuiltInAgentLaunch as f, buildAgentSpawnCommand as g, resolvePackageExecBuiltInAgentLaunch as h, DEFAULT_AGENT_NAME as i, resolveAgentSessionCwd as j, requireAgentStdio as k, normalizeAgentName as l, resolveInstalledBuiltInAgentLaunch as m, AGENT_REGISTRY as n, findBuiltInAgentPackage as o, resolveCanonicalAgentName as p, BUILT_IN_AGENT_PACKAGES as r, listBuiltInAgents as s, AGENT_ARGV_REGISTRY as t, resolveAgentArgv as u, buildTerminalShellSpawnCommand as v, basenameToken as w, resolveWindowsExecutablePath as x, buildTerminalSpawnCommand as y };
784
+
785
+ //# sourceMappingURL=agent-registry-DU6mhZBL.js.map