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/daemon.d.ts CHANGED
@@ -24,17 +24,20 @@ interface AdapterConfig {
24
24
  /** 默认 OpenClaw sub-agent。 */
25
25
  defaultAgent?: string;
26
26
  /** claude-code:网关 baseUrl/token/默认模型。 */
27
+ claudeBinPath?: string;
27
28
  claudeBaseUrl?: string;
28
29
  claudeAuthToken?: string;
29
30
  claudeDefaultModel?: string;
30
31
  claudeModels?: ModelInfo[];
31
32
  /** codex:网关 baseUrl(/v1)/key/默认模型/wireApi。 */
33
+ codexBinPath?: string;
32
34
  codexBaseUrl?: string;
33
35
  codexApiKey?: string;
34
36
  codexDefaultModel?: string;
35
37
  codexModels?: ModelInfo[];
36
38
  codexWireApi?: "responses" | "chat";
37
39
  /** hermes:默认模型/provider(用现有 hermes config)。 */
40
+ hermesBinPath?: string;
38
41
  hermesModel?: string;
39
42
  hermesProvider?: string;
40
43
  /** opencode:binary 路径/默认模型。 */
package/dist/daemon.js CHANGED
@@ -4723,8 +4723,9 @@ ${prompt}`;
4723
4723
  }
4724
4724
  run(args, stdin, turnId, emit, opts) {
4725
4725
  return new Promise((resolve5) => {
4726
- const child = spawn3("codex", args, {
4726
+ const child = spawn3(this.env.binPath ?? "codex", args, {
4727
4727
  cwd: this.cwd,
4728
+ shell: process.platform === "win32",
4728
4729
  env: { ...process.env, ...opts.environment ?? {}, ...this.env.apiKey ? { OPENAI_API_KEY: this.env.apiKey } : {} }
4729
4730
  });
4730
4731
  this.current = child;
@@ -4852,7 +4853,7 @@ var CodexAdapter = class {
4852
4853
  }
4853
4854
  probeVersion() {
4854
4855
  return new Promise((resolve5) => {
4855
- const child = spawn3("codex", ["--version"]);
4856
+ const child = spawn3(this.env.binPath ?? "codex", ["--version"], { shell: process.platform === "win32" });
4856
4857
  let out = "";
4857
4858
  child.stdout.on("data", (d) => out += d.toString());
4858
4859
  child.on("error", () => resolve5(null));
@@ -5162,8 +5163,9 @@ ${prompt}`;
5162
5163
  }
5163
5164
  run(args, turnId, emit, opts) {
5164
5165
  return new Promise((resolve5) => {
5165
- const child = spawn5("hermes", args, {
5166
+ const child = spawn5(this.env.binPath ?? "hermes", args, {
5166
5167
  cwd: this.cwd,
5168
+ shell: process.platform === "win32",
5167
5169
  env: { ...process.env, ...opts.environment ?? {}, HERMES_PROFILE: this.profile }
5168
5170
  });
5169
5171
  this.current = child;
@@ -5328,7 +5330,7 @@ var HermesAdapter = class {
5328
5330
  /** 枚举 Hermes profile(去 ANSI 色解析 profile list)。 */
5329
5331
  listProfiles() {
5330
5332
  return new Promise((resolve5) => {
5331
- const child = spawn5("hermes", ["profile", "list"]);
5333
+ const child = spawn5(this.env.binPath ?? "hermes", ["profile", "list"], { shell: process.platform === "win32" });
5332
5334
  let out = "";
5333
5335
  child.stdout.on("data", (d) => out += d.toString());
5334
5336
  child.on("error", () => resolve5([{ name: this.defaultProfile }]));
@@ -5348,7 +5350,7 @@ var HermesAdapter = class {
5348
5350
  }
5349
5351
  probeVersion() {
5350
5352
  return new Promise((resolve5) => {
5351
- const child = spawn5("hermes", ["--version"]);
5353
+ const child = spawn5(this.env.binPath ?? "hermes", ["--version"], { shell: process.platform === "win32" });
5352
5354
  let out = "";
5353
5355
  child.stdout.on("data", (d) => out += d.toString());
5354
5356
  child.on("error", () => resolve5(null));
@@ -5583,7 +5585,7 @@ ${prompt}`;
5583
5585
  if (v !== void 0)
5584
5586
  childEnv[k] = v;
5585
5587
  }
5586
- const child = spawn6("claude", args, { cwd: this.cwd, env: { ...childEnv, ...opts.environment ?? {} } });
5588
+ const child = spawn6(this.env.binPath ?? "claude", args, { cwd: this.cwd, shell: process.platform === "win32", env: { ...childEnv, ...opts.environment ?? {} } });
5587
5589
  this.current = child;
5588
5590
  let buf = "";
5589
5591
  let acc = "";
@@ -5725,7 +5727,7 @@ var ClaudeCodeAdapter = class {
5725
5727
  }
5726
5728
  probeVersion() {
5727
5729
  return new Promise((resolve5) => {
5728
- const child = spawn6("claude", ["--version"]);
5730
+ const child = spawn6(this.env.binPath ?? "claude", ["--version"], { shell: process.platform === "win32" });
5729
5731
  let out = "";
5730
5732
  child.stdout.on("data", (d) => out += d.toString());
5731
5733
  child.on("error", () => resolve5(null));
@@ -6085,25 +6087,74 @@ function readOpenClawGatewayToken() {
6085
6087
  // src/commands.ts
6086
6088
  import { spawnSync } from "node:child_process";
6087
6089
  import { existsSync as existsSync12, cpSync, mkdirSync as mkdirSync4, rmSync as rmSync3, writeFileSync as writeFileSync4, readFileSync as readFileSync5 } from "node:fs";
6088
- import { homedir as homedir10 } from "node:os";
6089
- import { join as join12, dirname as dirname5 } from "node:path";
6090
+ import { homedir as homedir10, platform as platform2 } from "node:os";
6091
+ import { join as join12, dirname as dirname5, delimiter } from "node:path";
6090
6092
  import { fileURLToPath } from "node:url";
6091
6093
  function probe(bin, args = ["--version"]) {
6092
- const r = spawnSync(bin, args, { timeout: 8e3 });
6094
+ const r = spawnSync(bin, args, { timeout: 8e3, shell: platform2() === "win32" });
6093
6095
  return { ok: r.status === 0, out: (r.stdout?.toString() ?? "").trim().split("\n")[0] ?? "" };
6094
6096
  }
6097
+ function executableNames(bin) {
6098
+ if (platform2() !== "win32") return [bin];
6099
+ const exts = (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((e) => e.toLowerCase());
6100
+ return [bin, ...exts.map((e) => `${bin}${e}`), ...exts.map((e) => `${bin}${e.toUpperCase()}`)];
6101
+ }
6102
+ function commandPath(bin) {
6103
+ const home = homedir10();
6104
+ const appData = process.env.APPDATA;
6105
+ const localAppData = process.env.LOCALAPPDATA;
6106
+ const dirs = [
6107
+ join12(home, ".npm-global", "bin"),
6108
+ join12(home, ".local", "bin"),
6109
+ join12(home, ".bun", "bin"),
6110
+ join12(home, ".cargo", "bin"),
6111
+ ...appData ? [join12(appData, "npm")] : [],
6112
+ ...localAppData ? [join12(localAppData, "Programs"), join12(localAppData, "Microsoft", "WindowsApps")] : [],
6113
+ "/opt/homebrew/bin",
6114
+ "/usr/local/bin",
6115
+ "/usr/bin",
6116
+ ...(process.env.PATH ?? "").split(delimiter).filter(Boolean)
6117
+ ];
6118
+ for (const dir of dirs) {
6119
+ for (const name of executableNames(bin)) {
6120
+ const p = join12(dir, name);
6121
+ if (existsSync12(p)) return p;
6122
+ }
6123
+ }
6124
+ const r = platform2() === "win32" ? spawnSync("where.exe", [bin], { timeout: 3e3 }) : spawnSync("sh", ["-lc", `command -v ${bin}`], { timeout: 3e3 });
6125
+ const out = (r.stdout?.toString() ?? "").trim().split(/\r?\n/)[0];
6126
+ return r.status === 0 && out ? out : void 0;
6127
+ }
6095
6128
  function openCodeBin() {
6096
- const bundled = join12(homedir10(), ".opencode", "bin", "opencode");
6097
- return existsSync12(bundled) ? bundled : "opencode";
6129
+ const bundledDir = join12(homedir10(), ".opencode", "bin");
6130
+ for (const name of executableNames("opencode")) {
6131
+ const p = join12(bundledDir, name);
6132
+ if (existsSync12(p)) return p;
6133
+ }
6134
+ return commandPath("opencode") ?? "opencode";
6098
6135
  }
6099
6136
  function autoDetectAdapters(adapters) {
6100
6137
  const out = [...adapters];
6101
6138
  const has = (type2) => out.some((a) => a.type === type2);
6102
- if (!has("hermes") && probe("hermes").ok) out.push({ type: "hermes" });
6139
+ if (!has("hermes")) {
6140
+ const hermesPath = commandPath("hermes");
6141
+ if (hermesPath && probe(hermesPath).ok) out.push({ type: "hermes", hermesBinPath: hermesPath });
6142
+ }
6103
6143
  const ocBin = openCodeBin();
6104
6144
  if (!has("opencode") && probe(ocBin).ok) out.push({ type: "opencode", opencodeBinPath: ocBin === "opencode" ? void 0 : ocBin });
6105
- if (!has("claude-code") && probe("claude").ok) out.push({ type: "claude-code", claudeDefaultModel: "default" });
6106
- if (!has("codex") && probe("codex").ok) out.push({ type: "codex", codexDefaultModel: "default" });
6145
+ for (const a of out) {
6146
+ if (a.type === "hermes" && !a.hermesBinPath) a.hermesBinPath = commandPath("hermes");
6147
+ if (a.type === "claude-code" && !a.claudeBinPath) a.claudeBinPath = commandPath("claude");
6148
+ if (a.type === "codex" && !a.codexBinPath) a.codexBinPath = commandPath("codex");
6149
+ }
6150
+ if (!has("claude-code")) {
6151
+ const claudePath = commandPath("claude");
6152
+ if (claudePath && probe(claudePath).ok) out.push({ type: "claude-code", claudeBinPath: claudePath, claudeDefaultModel: "default" });
6153
+ }
6154
+ if (!has("codex")) {
6155
+ const codexPath = commandPath("codex");
6156
+ if (codexPath && probe(codexPath).ok) out.push({ type: "codex", codexBinPath: codexPath, codexDefaultModel: "default" });
6157
+ }
6107
6158
  return out;
6108
6159
  }
6109
6160
 
@@ -6248,11 +6299,11 @@ var PhononDaemon = class {
6248
6299
  this.gatewayAdapters.push(ad);
6249
6300
  this.registry.register(ad);
6250
6301
  } else if (a.type === "claude-code") {
6251
- this.registry.register(new ClaudeCodeAdapter({ env: { baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6302
+ this.registry.register(new ClaudeCodeAdapter({ env: { binPath: a.claudeBinPath, baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6252
6303
  } else if (a.type === "codex") {
6253
- this.registry.register(new CodexAdapter({ env: { baseUrl: a.codexBaseUrl, apiKey: a.codexApiKey, defaultModel: a.codexDefaultModel ?? "default", models: a.codexModels, wireApi: a.codexWireApi ?? "responses" } }));
6304
+ 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" } }));
6254
6305
  } else if (a.type === "hermes") {
6255
- this.registry.register(new HermesAdapter({ env: { defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6306
+ this.registry.register(new HermesAdapter({ env: { binPath: a.hermesBinPath, defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6256
6307
  } else if (a.type === "opencode") {
6257
6308
  this.registry.register(new OpenCodeAdapter({ env: { binPath: a.opencodeBinPath, defaultModel: a.opencodeModel } }));
6258
6309
  } else if (a.type === "openclaw-cli") {