agent-phonon 0.2.5 → 0.2.8

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,7 +4724,7 @@ ${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
4729
  env: { ...process.env, ...opts.environment ?? {}, ...this.env.apiKey ? { OPENAI_API_KEY: this.env.apiKey } : {} }
4730
4730
  });
@@ -4853,7 +4853,7 @@ var CodexAdapter = class {
4853
4853
  }
4854
4854
  probeVersion() {
4855
4855
  return new Promise((resolve5) => {
4856
- const child = spawn3("codex", ["--version"]);
4856
+ const child = spawn3(this.env.binPath ?? "codex", ["--version"]);
4857
4857
  let out = "";
4858
4858
  child.stdout.on("data", (d) => out += d.toString());
4859
4859
  child.on("error", () => resolve5(null));
@@ -5163,7 +5163,7 @@ ${prompt}`;
5163
5163
  }
5164
5164
  run(args2, turnId, emit, opts) {
5165
5165
  return new Promise((resolve5) => {
5166
- const child = spawn5("hermes", args2, {
5166
+ const child = spawn5(this.env.binPath ?? "hermes", args2, {
5167
5167
  cwd: this.cwd,
5168
5168
  env: { ...process.env, ...opts.environment ?? {}, HERMES_PROFILE: this.profile }
5169
5169
  });
@@ -5329,7 +5329,7 @@ var HermesAdapter = class {
5329
5329
  /** 枚举 Hermes profile(去 ANSI 色解析 profile list)。 */
5330
5330
  listProfiles() {
5331
5331
  return new Promise((resolve5) => {
5332
- const child = spawn5("hermes", ["profile", "list"]);
5332
+ const child = spawn5(this.env.binPath ?? "hermes", ["profile", "list"]);
5333
5333
  let out = "";
5334
5334
  child.stdout.on("data", (d) => out += d.toString());
5335
5335
  child.on("error", () => resolve5([{ name: this.defaultProfile }]));
@@ -5349,7 +5349,7 @@ var HermesAdapter = class {
5349
5349
  }
5350
5350
  probeVersion() {
5351
5351
  return new Promise((resolve5) => {
5352
- const child = spawn5("hermes", ["--version"]);
5352
+ const child = spawn5(this.env.binPath ?? "hermes", ["--version"]);
5353
5353
  let out = "";
5354
5354
  child.stdout.on("data", (d) => out += d.toString());
5355
5355
  child.on("error", () => resolve5(null));
@@ -5584,7 +5584,7 @@ ${prompt}`;
5584
5584
  if (v !== void 0)
5585
5585
  childEnv[k] = v;
5586
5586
  }
5587
- const child = spawn6("claude", args2, { cwd: this.cwd, env: { ...childEnv, ...opts.environment ?? {} } });
5587
+ const child = spawn6(this.env.binPath ?? "claude", args2, { cwd: this.cwd, env: { ...childEnv, ...opts.environment ?? {} } });
5588
5588
  this.current = child;
5589
5589
  let buf = "";
5590
5590
  let acc = "";
@@ -5726,7 +5726,7 @@ var ClaudeCodeAdapter = class {
5726
5726
  }
5727
5727
  probeVersion() {
5728
5728
  return new Promise((resolve5) => {
5729
- const child = spawn6("claude", ["--version"]);
5729
+ const child = spawn6(this.env.binPath ?? "claude", ["--version"]);
5730
5730
  let out = "";
5731
5731
  child.stdout.on("data", (d) => out += d.toString());
5732
5732
  child.on("error", () => resolve5(null));
@@ -6144,6 +6144,21 @@ function probe(bin, args2 = ["--version"]) {
6144
6144
  const r = spawnSync(bin, args2, { timeout: 8e3 });
6145
6145
  return { ok: r.status === 0, out: (r.stdout?.toString() ?? "").trim().split("\n")[0] ?? "" };
6146
6146
  }
6147
+ function commandPath(bin) {
6148
+ const candidates = [
6149
+ join12(homedir10(), ".npm-global", "bin", bin),
6150
+ join12(homedir10(), ".local", "bin", bin),
6151
+ join12(homedir10(), ".bun", "bin", bin),
6152
+ join12(homedir10(), ".cargo", "bin", bin),
6153
+ `/opt/homebrew/bin/${bin}`,
6154
+ `/usr/local/bin/${bin}`,
6155
+ `/usr/bin/${bin}`
6156
+ ];
6157
+ for (const p of candidates) if (existsSync12(p)) return p;
6158
+ const r = spawnSync("bash", ["-lc", `command -v ${bin}`], { timeout: 3e3 });
6159
+ const out = (r.stdout?.toString() ?? "").trim().split("\n")[0];
6160
+ return r.status === 0 && out ? out : void 0;
6161
+ }
6147
6162
  function gatewayReachable(url) {
6148
6163
  try {
6149
6164
  const u = new URL(url.replace(/^ws/, "http"));
@@ -6160,11 +6175,25 @@ function openCodeBin() {
6160
6175
  function autoDetectAdapters(adapters) {
6161
6176
  const out = [...adapters];
6162
6177
  const has = (type2) => out.some((a) => a.type === type2);
6163
- if (!has("hermes") && probe("hermes").ok) out.push({ type: "hermes" });
6178
+ if (!has("hermes")) {
6179
+ const hermesPath = commandPath("hermes");
6180
+ if (hermesPath && probe(hermesPath).ok) out.push({ type: "hermes", hermesBinPath: hermesPath });
6181
+ }
6164
6182
  const ocBin = openCodeBin();
6165
6183
  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" });
6184
+ for (const a of out) {
6185
+ if (a.type === "hermes" && !a.hermesBinPath) a.hermesBinPath = commandPath("hermes");
6186
+ if (a.type === "claude-code" && !a.claudeBinPath) a.claudeBinPath = commandPath("claude");
6187
+ if (a.type === "codex" && !a.codexBinPath) a.codexBinPath = commandPath("codex");
6188
+ }
6189
+ if (!has("claude-code")) {
6190
+ const claudePath = commandPath("claude");
6191
+ if (claudePath && probe(claudePath).ok) out.push({ type: "claude-code", claudeBinPath: claudePath, claudeDefaultModel: "default" });
6192
+ }
6193
+ if (!has("codex")) {
6194
+ const codexPath = commandPath("codex");
6195
+ if (codexPath && probe(codexPath).ok) out.push({ type: "codex", codexBinPath: codexPath, codexDefaultModel: "default" });
6196
+ }
6168
6197
  return out;
6169
6198
  }
6170
6199
  function cmdDoctor() {
@@ -6218,11 +6247,11 @@ function buildRegistry(adapters) {
6218
6247
  const token = a.gatewayToken ?? readOpenClawGatewayToken();
6219
6248
  if (token) reg.register(new OpenClawGatewayAdapter({ gateway: { baseUrl: a.gatewayUrl ?? "ws://127.0.0.1:18789", token }, defaultAgent: a.defaultAgent ?? "main" }));
6220
6249
  } 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 } }));
6250
+ reg.register(new ClaudeCodeAdapter({ env: { binPath: a.claudeBinPath, baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6222
6251
  } 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" } }));
6252
+ 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
6253
  } else if (a.type === "hermes") {
6225
- reg.register(new HermesAdapter({ env: { defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6254
+ reg.register(new HermesAdapter({ env: { binPath: a.hermesBinPath, defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6226
6255
  } else if (a.type === "opencode") {
6227
6256
  reg.register(new OpenCodeAdapter({ env: { binPath: a.opencodeBinPath, defaultModel: a.opencodeModel } }));
6228
6257
  }
@@ -6238,13 +6267,13 @@ function cmdAdapterAdd(type2, opts) {
6238
6267
  a = { type: "openclaw-gateway", gatewayUrl: opts.gatewayUrl ?? "ws://127.0.0.1:18789", gatewayToken: opts.token, defaultAgent: opts.defaultAgent ?? "main" };
6239
6268
  break;
6240
6269
  case "claude-code":
6241
- a = { type: "claude-code", claudeBaseUrl: opts.baseUrl, claudeAuthToken: opts.token, claudeDefaultModel: opts.model ?? "default" };
6270
+ a = { type: "claude-code", claudeBinPath: opts.bin, claudeBaseUrl: opts.baseUrl, claudeAuthToken: opts.token, claudeDefaultModel: opts.model ?? "default" };
6242
6271
  break;
6243
6272
  case "codex":
6244
- a = { type: "codex", codexBaseUrl: opts.baseUrl, codexApiKey: opts.apiKey, codexDefaultModel: opts.model ?? "default", codexWireApi: opts.wireApi ?? "responses" };
6273
+ a = { type: "codex", codexBinPath: opts.bin, codexBaseUrl: opts.baseUrl, codexApiKey: opts.apiKey, codexDefaultModel: opts.model ?? "default", codexWireApi: opts.wireApi ?? "responses" };
6245
6274
  break;
6246
6275
  case "hermes":
6247
- a = { type: "hermes", hermesModel: opts.model, hermesProvider: opts.provider };
6276
+ a = { type: "hermes", hermesBinPath: opts.bin, hermesModel: opts.model, hermesProvider: opts.provider };
6248
6277
  break;
6249
6278
  case "opencode":
6250
6279
  a = { type: "opencode", opencodeBinPath: opts.bin, opencodeModel: opts.model };
@@ -6435,11 +6464,11 @@ var PhononDaemon = class {
6435
6464
  this.gatewayAdapters.push(ad);
6436
6465
  this.registry.register(ad);
6437
6466
  } 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 } }));
6467
+ this.registry.register(new ClaudeCodeAdapter({ env: { binPath: a.claudeBinPath, baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6439
6468
  } 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" } }));
6469
+ 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
6470
  } else if (a.type === "hermes") {
6442
- this.registry.register(new HermesAdapter({ env: { defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6471
+ this.registry.register(new HermesAdapter({ env: { binPath: a.hermesBinPath, defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6443
6472
  } else if (a.type === "opencode") {
6444
6473
  this.registry.register(new OpenCodeAdapter({ env: { binPath: a.opencodeBinPath, defaultModel: a.opencodeModel } }));
6445
6474
  } else if (a.type === "openclaw-cli") {