agent-phonon 0.2.7 → 0.2.9

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 CHANGED
@@ -4724,8 +4724,9 @@ ${prompt}`;
4724
4724
  }
4725
4725
  run(args2, stdin, turnId, emit, opts) {
4726
4726
  return new Promise((resolve5) => {
4727
- const child = spawn3("codex", args2, {
4727
+ const child = spawn3(this.env.binPath ?? "codex", args2, {
4728
4728
  cwd: this.cwd,
4729
+ shell: process.platform === "win32",
4729
4730
  env: { ...process.env, ...opts.environment ?? {}, ...this.env.apiKey ? { OPENAI_API_KEY: this.env.apiKey } : {} }
4730
4731
  });
4731
4732
  this.current = child;
@@ -4853,7 +4854,7 @@ var CodexAdapter = class {
4853
4854
  }
4854
4855
  probeVersion() {
4855
4856
  return new Promise((resolve5) => {
4856
- const child = spawn3("codex", ["--version"]);
4857
+ const child = spawn3(this.env.binPath ?? "codex", ["--version"], { shell: process.platform === "win32" });
4857
4858
  let out = "";
4858
4859
  child.stdout.on("data", (d) => out += d.toString());
4859
4860
  child.on("error", () => resolve5(null));
@@ -5163,8 +5164,9 @@ ${prompt}`;
5163
5164
  }
5164
5165
  run(args2, turnId, emit, opts) {
5165
5166
  return new Promise((resolve5) => {
5166
- const child = spawn5("hermes", args2, {
5167
+ const child = spawn5(this.env.binPath ?? "hermes", args2, {
5167
5168
  cwd: this.cwd,
5169
+ shell: process.platform === "win32",
5168
5170
  env: { ...process.env, ...opts.environment ?? {}, HERMES_PROFILE: this.profile }
5169
5171
  });
5170
5172
  this.current = child;
@@ -5329,7 +5331,7 @@ var HermesAdapter = class {
5329
5331
  /** 枚举 Hermes profile(去 ANSI 色解析 profile list)。 */
5330
5332
  listProfiles() {
5331
5333
  return new Promise((resolve5) => {
5332
- const child = spawn5("hermes", ["profile", "list"]);
5334
+ const child = spawn5(this.env.binPath ?? "hermes", ["profile", "list"], { shell: process.platform === "win32" });
5333
5335
  let out = "";
5334
5336
  child.stdout.on("data", (d) => out += d.toString());
5335
5337
  child.on("error", () => resolve5([{ name: this.defaultProfile }]));
@@ -5349,7 +5351,7 @@ var HermesAdapter = class {
5349
5351
  }
5350
5352
  probeVersion() {
5351
5353
  return new Promise((resolve5) => {
5352
- const child = spawn5("hermes", ["--version"]);
5354
+ const child = spawn5(this.env.binPath ?? "hermes", ["--version"], { shell: process.platform === "win32" });
5353
5355
  let out = "";
5354
5356
  child.stdout.on("data", (d) => out += d.toString());
5355
5357
  child.on("error", () => resolve5(null));
@@ -5584,7 +5586,7 @@ ${prompt}`;
5584
5586
  if (v !== void 0)
5585
5587
  childEnv[k] = v;
5586
5588
  }
5587
- const child = spawn6("claude", args2, { cwd: this.cwd, env: { ...childEnv, ...opts.environment ?? {} } });
5589
+ const child = spawn6(this.env.binPath ?? "claude", args2, { cwd: this.cwd, shell: process.platform === "win32", env: { ...childEnv, ...opts.environment ?? {} } });
5588
5590
  this.current = child;
5589
5591
  let buf = "";
5590
5592
  let acc = "";
@@ -5726,7 +5728,7 @@ var ClaudeCodeAdapter = class {
5726
5728
  }
5727
5729
  probeVersion() {
5728
5730
  return new Promise((resolve5) => {
5729
- const child = spawn6("claude", ["--version"]);
5731
+ const child = spawn6(this.env.binPath ?? "claude", ["--version"], { shell: process.platform === "win32" });
5730
5732
  let out = "";
5731
5733
  child.stdout.on("data", (d) => out += d.toString());
5732
5734
  child.on("error", () => resolve5(null));
@@ -6137,13 +6139,44 @@ function readOpenClawGatewayToken() {
6137
6139
  // src/commands.ts
6138
6140
  import { spawnSync } from "node:child_process";
6139
6141
  import { existsSync as existsSync12, cpSync, mkdirSync as mkdirSync4, rmSync as rmSync3, writeFileSync as writeFileSync4, readFileSync as readFileSync5 } from "node:fs";
6140
- import { homedir as homedir10 } from "node:os";
6141
- import { join as join12, dirname as dirname5 } from "node:path";
6142
+ import { homedir as homedir10, platform as platform2 } from "node:os";
6143
+ import { join as join12, dirname as dirname5, delimiter } from "node:path";
6142
6144
  import { fileURLToPath } from "node:url";
6143
6145
  function probe(bin, args2 = ["--version"]) {
6144
- const r = spawnSync(bin, args2, { timeout: 8e3 });
6146
+ const r = spawnSync(bin, args2, { timeout: 8e3, shell: platform2() === "win32" });
6145
6147
  return { ok: r.status === 0, out: (r.stdout?.toString() ?? "").trim().split("\n")[0] ?? "" };
6146
6148
  }
6149
+ function executableNames(bin) {
6150
+ if (platform2() !== "win32") return [bin];
6151
+ const exts = (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((e) => e.toLowerCase());
6152
+ return [bin, ...exts.map((e) => `${bin}${e}`), ...exts.map((e) => `${bin}${e.toUpperCase()}`)];
6153
+ }
6154
+ function commandPath(bin) {
6155
+ const home = homedir10();
6156
+ const appData = process.env.APPDATA;
6157
+ const localAppData = process.env.LOCALAPPDATA;
6158
+ const dirs = [
6159
+ join12(home, ".npm-global", "bin"),
6160
+ join12(home, ".local", "bin"),
6161
+ join12(home, ".bun", "bin"),
6162
+ join12(home, ".cargo", "bin"),
6163
+ ...appData ? [join12(appData, "npm")] : [],
6164
+ ...localAppData ? [join12(localAppData, "Programs"), join12(localAppData, "Microsoft", "WindowsApps")] : [],
6165
+ "/opt/homebrew/bin",
6166
+ "/usr/local/bin",
6167
+ "/usr/bin",
6168
+ ...(process.env.PATH ?? "").split(delimiter).filter(Boolean)
6169
+ ];
6170
+ for (const dir of dirs) {
6171
+ for (const name of executableNames(bin)) {
6172
+ const p = join12(dir, name);
6173
+ if (existsSync12(p)) return p;
6174
+ }
6175
+ }
6176
+ const r = platform2() === "win32" ? spawnSync("where.exe", [bin], { timeout: 3e3 }) : spawnSync("sh", ["-lc", `command -v ${bin}`], { timeout: 3e3 });
6177
+ const out = (r.stdout?.toString() ?? "").trim().split(/\r?\n/)[0];
6178
+ return r.status === 0 && out ? out : void 0;
6179
+ }
6147
6180
  function gatewayReachable(url) {
6148
6181
  try {
6149
6182
  const u = new URL(url.replace(/^ws/, "http"));
@@ -6154,17 +6187,35 @@ function gatewayReachable(url) {
6154
6187
  }
6155
6188
  }
6156
6189
  function openCodeBin() {
6157
- const bundled = join12(homedir10(), ".opencode", "bin", "opencode");
6158
- return existsSync12(bundled) ? bundled : "opencode";
6190
+ const bundledDir = join12(homedir10(), ".opencode", "bin");
6191
+ for (const name of executableNames("opencode")) {
6192
+ const p = join12(bundledDir, name);
6193
+ if (existsSync12(p)) return p;
6194
+ }
6195
+ return commandPath("opencode") ?? "opencode";
6159
6196
  }
6160
6197
  function autoDetectAdapters(adapters) {
6161
6198
  const out = [...adapters];
6162
6199
  const has = (type2) => out.some((a) => a.type === type2);
6163
- if (!has("hermes") && probe("hermes").ok) out.push({ type: "hermes" });
6200
+ if (!has("hermes")) {
6201
+ const hermesPath = commandPath("hermes");
6202
+ if (hermesPath && probe(hermesPath).ok) out.push({ type: "hermes", hermesBinPath: hermesPath });
6203
+ }
6164
6204
  const ocBin = openCodeBin();
6165
6205
  if (!has("opencode") && probe(ocBin).ok) out.push({ type: "opencode", opencodeBinPath: ocBin === "opencode" ? void 0 : ocBin });
6166
- if (!has("claude-code") && probe("claude").ok) out.push({ type: "claude-code", claudeDefaultModel: "default" });
6167
- if (!has("codex") && probe("codex").ok) out.push({ type: "codex", codexDefaultModel: "default" });
6206
+ for (const a of out) {
6207
+ if (a.type === "hermes" && !a.hermesBinPath) a.hermesBinPath = commandPath("hermes");
6208
+ if (a.type === "claude-code" && !a.claudeBinPath) a.claudeBinPath = commandPath("claude");
6209
+ if (a.type === "codex" && !a.codexBinPath) a.codexBinPath = commandPath("codex");
6210
+ }
6211
+ if (!has("claude-code")) {
6212
+ const claudePath = commandPath("claude");
6213
+ if (claudePath && probe(claudePath).ok) out.push({ type: "claude-code", claudeBinPath: claudePath, claudeDefaultModel: "default" });
6214
+ }
6215
+ if (!has("codex")) {
6216
+ const codexPath = commandPath("codex");
6217
+ if (codexPath && probe(codexPath).ok) out.push({ type: "codex", codexBinPath: codexPath, codexDefaultModel: "default" });
6218
+ }
6168
6219
  return out;
6169
6220
  }
6170
6221
  function cmdDoctor() {
@@ -6218,11 +6269,11 @@ function buildRegistry(adapters) {
6218
6269
  const token = a.gatewayToken ?? readOpenClawGatewayToken();
6219
6270
  if (token) reg.register(new OpenClawGatewayAdapter({ gateway: { baseUrl: a.gatewayUrl ?? "ws://127.0.0.1:18789", token }, defaultAgent: a.defaultAgent ?? "main" }));
6220
6271
  } else if (a.type === "claude-code") {
6221
- reg.register(new ClaudeCodeAdapter({ env: { baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6272
+ reg.register(new ClaudeCodeAdapter({ env: { binPath: a.claudeBinPath, baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6222
6273
  } else if (a.type === "codex") {
6223
- reg.register(new CodexAdapter({ env: { baseUrl: a.codexBaseUrl, apiKey: a.codexApiKey, defaultModel: a.codexDefaultModel ?? "default", models: a.codexModels, wireApi: a.codexWireApi ?? "responses" } }));
6274
+ reg.register(new CodexAdapter({ env: { binPath: a.codexBinPath, baseUrl: a.codexBaseUrl, apiKey: a.codexApiKey, defaultModel: a.codexDefaultModel ?? "default", models: a.codexModels, wireApi: a.codexWireApi ?? "responses" } }));
6224
6275
  } else if (a.type === "hermes") {
6225
- reg.register(new HermesAdapter({ env: { defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6276
+ reg.register(new HermesAdapter({ env: { binPath: a.hermesBinPath, defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6226
6277
  } else if (a.type === "opencode") {
6227
6278
  reg.register(new OpenCodeAdapter({ env: { binPath: a.opencodeBinPath, defaultModel: a.opencodeModel } }));
6228
6279
  }
@@ -6238,13 +6289,13 @@ function cmdAdapterAdd(type2, opts) {
6238
6289
  a = { type: "openclaw-gateway", gatewayUrl: opts.gatewayUrl ?? "ws://127.0.0.1:18789", gatewayToken: opts.token, defaultAgent: opts.defaultAgent ?? "main" };
6239
6290
  break;
6240
6291
  case "claude-code":
6241
- a = { type: "claude-code", claudeBaseUrl: opts.baseUrl, claudeAuthToken: opts.token, claudeDefaultModel: opts.model ?? "default" };
6292
+ a = { type: "claude-code", claudeBinPath: opts.bin, claudeBaseUrl: opts.baseUrl, claudeAuthToken: opts.token, claudeDefaultModel: opts.model ?? "default" };
6242
6293
  break;
6243
6294
  case "codex":
6244
- a = { type: "codex", codexBaseUrl: opts.baseUrl, codexApiKey: opts.apiKey, codexDefaultModel: opts.model ?? "default", codexWireApi: opts.wireApi ?? "responses" };
6295
+ a = { type: "codex", codexBinPath: opts.bin, codexBaseUrl: opts.baseUrl, codexApiKey: opts.apiKey, codexDefaultModel: opts.model ?? "default", codexWireApi: opts.wireApi ?? "responses" };
6245
6296
  break;
6246
6297
  case "hermes":
6247
- a = { type: "hermes", hermesModel: opts.model, hermesProvider: opts.provider };
6298
+ a = { type: "hermes", hermesBinPath: opts.bin, hermesModel: opts.model, hermesProvider: opts.provider };
6248
6299
  break;
6249
6300
  case "opencode":
6250
6301
  a = { type: "opencode", opencodeBinPath: opts.bin, opencodeModel: opts.model };
@@ -6435,11 +6486,11 @@ var PhononDaemon = class {
6435
6486
  this.gatewayAdapters.push(ad);
6436
6487
  this.registry.register(ad);
6437
6488
  } else if (a.type === "claude-code") {
6438
- this.registry.register(new ClaudeCodeAdapter({ env: { baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6489
+ this.registry.register(new ClaudeCodeAdapter({ env: { binPath: a.claudeBinPath, baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6439
6490
  } else if (a.type === "codex") {
6440
- this.registry.register(new CodexAdapter({ env: { baseUrl: a.codexBaseUrl, apiKey: a.codexApiKey, defaultModel: a.codexDefaultModel ?? "default", models: a.codexModels, wireApi: a.codexWireApi ?? "responses" } }));
6491
+ this.registry.register(new CodexAdapter({ env: { binPath: a.codexBinPath, baseUrl: a.codexBaseUrl, apiKey: a.codexApiKey, defaultModel: a.codexDefaultModel ?? "default", models: a.codexModels, wireApi: a.codexWireApi ?? "responses" } }));
6441
6492
  } else if (a.type === "hermes") {
6442
- this.registry.register(new HermesAdapter({ env: { defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6493
+ this.registry.register(new HermesAdapter({ env: { binPath: a.hermesBinPath, defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6443
6494
  } else if (a.type === "opencode") {
6444
6495
  this.registry.register(new OpenCodeAdapter({ env: { binPath: a.opencodeBinPath, defaultModel: a.opencodeModel } }));
6445
6496
  } else if (a.type === "openclaw-cli") {