agent-phonon 0.2.4 → 0.2.7

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.js CHANGED
@@ -3190,8 +3190,8 @@ var FileManager = class {
3190
3190
  if (abs !== root && !abs.startsWith(root + sep2)) {
3191
3191
  throw new PhononError("errPolicyDenied", `file path escapes project/worktree: ${rel}`);
3192
3192
  }
3193
- const probe = !followFinal && abs !== root ? dirname3(abs) : abs;
3194
- const real = await this.realpathBoundary(probe);
3193
+ const probe2 = !followFinal && abs !== root ? dirname3(abs) : abs;
3194
+ const real = await this.realpathBoundary(probe2);
3195
3195
  if (real !== root && !real.startsWith(root + sep2)) {
3196
3196
  throw new PhononError("errPolicyDenied", `file path escapes project/worktree via symlink: ${rel}`);
3197
3197
  }
@@ -4689,6 +4689,8 @@ var CodexSession = class {
4689
4689
  this.env = env;
4690
4690
  }
4691
4691
  providerArgs() {
4692
+ if (!this.env.baseUrl || !this.env.apiKey)
4693
+ return [];
4692
4694
  const id = this.env.providerId ?? "phonon_gateway";
4693
4695
  const name = this.env.providerName ?? "phonon-gateway";
4694
4696
  return [
@@ -4716,14 +4718,14 @@ var CodexSession = class {
4716
4718
 
4717
4719
  ${prompt}`;
4718
4720
  }
4719
- const args = this.threadId ? ["exec", "resume", this.threadId, "-", "--json", ...this.providerArgs(), "--model", this.model, "--dangerously-bypass-approvals-and-sandbox"] : ["exec", "-", "--json", ...this.providerArgs(), "--model", this.model, "--dangerously-bypass-approvals-and-sandbox"];
4721
+ const args = this.threadId ? ["exec", "resume", this.threadId, "-", "--json", ...this.providerArgs(), ...this.model !== "default" ? ["--model", this.model] : [], "--dangerously-bypass-approvals-and-sandbox"] : ["exec", "-", "--json", ...this.providerArgs(), ...this.model !== "default" ? ["--model", this.model] : [], "--dangerously-bypass-approvals-and-sandbox"];
4720
4722
  await this.run(args, prompt, turnId, emit, opts);
4721
4723
  }
4722
4724
  run(args, stdin, turnId, emit, opts) {
4723
4725
  return new Promise((resolve5) => {
4724
4726
  const child = spawn3("codex", args, {
4725
4727
  cwd: this.cwd,
4726
- env: { ...process.env, ...opts.environment ?? {}, OPENAI_API_KEY: this.env.apiKey }
4728
+ env: { ...process.env, ...opts.environment ?? {}, ...this.env.apiKey ? { OPENAI_API_KEY: this.env.apiKey } : {} }
4727
4729
  });
4728
4730
  this.current = child;
4729
4731
  let buf = "";
@@ -5488,16 +5490,20 @@ var CAPABILITIES5 = {
5488
5490
  limits: { maxConcurrentSessions: 4 }
5489
5491
  };
5490
5492
  function writeSettingsFile(env, model) {
5493
+ if (!env.baseUrl || !env.authToken)
5494
+ return void 0;
5491
5495
  const dir = mkdtempSync(join10(tmpdir2(), "phonon-cc-"));
5492
5496
  const file = join10(dir, "settings.json");
5493
5497
  const content = JSON.stringify({
5494
5498
  env: {
5495
5499
  ANTHROPIC_BASE_URL: env.baseUrl,
5496
5500
  ANTHROPIC_AUTH_TOKEN: env.authToken,
5497
- ANTHROPIC_MODEL: model,
5498
- ANTHROPIC_DEFAULT_OPUS_MODEL: model,
5499
- ANTHROPIC_DEFAULT_SONNET_MODEL: model,
5500
- ANTHROPIC_DEFAULT_HAIKU_MODEL: model,
5501
+ ...model !== "default" ? {
5502
+ ANTHROPIC_MODEL: model,
5503
+ ANTHROPIC_DEFAULT_OPUS_MODEL: model,
5504
+ ANTHROPIC_DEFAULT_SONNET_MODEL: model,
5505
+ ANTHROPIC_DEFAULT_HAIKU_MODEL: model
5506
+ } : {},
5501
5507
  CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1"
5502
5508
  }
5503
5509
  });
@@ -5550,12 +5556,13 @@ ${prompt}`;
5550
5556
  // 最高权限:bypassPermissions 跳过所有权限确认;不限定 allowedTools = 所有工具可用
5551
5557
  // (phonon 定位:全自动执行,牺牲安全换自动化)
5552
5558
  "--permission-mode",
5553
- "bypassPermissions",
5554
- "--settings",
5555
- this.settingsFile(),
5556
- "--model",
5557
- this.model
5559
+ "bypassPermissions"
5558
5560
  ];
5561
+ const settings = this.settingsFile();
5562
+ if (settings)
5563
+ args.push("--settings", settings);
5564
+ if (this.model !== "default")
5565
+ args.push("--model", this.model);
5559
5566
  if (this.started)
5560
5567
  args.push("--resume", this.uuid);
5561
5568
  else
@@ -6075,6 +6082,31 @@ function readOpenClawGatewayToken() {
6075
6082
  }
6076
6083
  }
6077
6084
 
6085
+ // src/commands.ts
6086
+ import { spawnSync } from "node:child_process";
6087
+ 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 { fileURLToPath } from "node:url";
6091
+ function probe(bin, args = ["--version"]) {
6092
+ const r = spawnSync(bin, args, { timeout: 8e3 });
6093
+ return { ok: r.status === 0, out: (r.stdout?.toString() ?? "").trim().split("\n")[0] ?? "" };
6094
+ }
6095
+ function openCodeBin() {
6096
+ const bundled = join12(homedir10(), ".opencode", "bin", "opencode");
6097
+ return existsSync12(bundled) ? bundled : "opencode";
6098
+ }
6099
+ function autoDetectAdapters(adapters) {
6100
+ const out = [...adapters];
6101
+ const has = (type2) => out.some((a) => a.type === type2);
6102
+ if (!has("hermes") && probe("hermes").ok) out.push({ type: "hermes" });
6103
+ const ocBin = openCodeBin();
6104
+ 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" });
6107
+ return out;
6108
+ }
6109
+
6078
6110
  // src/obs-server.ts
6079
6111
  import { createServer as createServer2 } from "node:http";
6080
6112
  var ObsServer = class {
@@ -6202,7 +6234,7 @@ var PhononDaemon = class {
6202
6234
  this.registerAdapters();
6203
6235
  }
6204
6236
  registerAdapters() {
6205
- for (const a of this.cfg.adapters) {
6237
+ for (const a of autoDetectAdapters(this.cfg.adapters)) {
6206
6238
  if (a.type === "openclaw-gateway") {
6207
6239
  const token = a.gatewayToken ?? readOpenClawGatewayToken();
6208
6240
  if (!token) {
@@ -6216,17 +6248,9 @@ var PhononDaemon = class {
6216
6248
  this.gatewayAdapters.push(ad);
6217
6249
  this.registry.register(ad);
6218
6250
  } else if (a.type === "claude-code") {
6219
- if (a.claudeBaseUrl && a.claudeAuthToken) {
6220
- this.registry.register(new ClaudeCodeAdapter({ env: { baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "claude-opus-4.6" } }));
6221
- } else {
6222
- console.warn("[daemon] claude-code adapter skipped: need claudeBaseUrl + claudeAuthToken");
6223
- }
6251
+ this.registry.register(new ClaudeCodeAdapter({ env: { baseUrl: a.claudeBaseUrl, authToken: a.claudeAuthToken, defaultModel: a.claudeDefaultModel ?? "default", models: a.claudeModels } }));
6224
6252
  } else if (a.type === "codex") {
6225
- if (a.codexBaseUrl && a.codexApiKey) {
6226
- this.registry.register(new CodexAdapter({ env: { baseUrl: a.codexBaseUrl, apiKey: a.codexApiKey, defaultModel: a.codexDefaultModel ?? "gpt-5.5", wireApi: a.codexWireApi ?? "responses" } }));
6227
- } else {
6228
- console.warn("[daemon] codex adapter skipped: need codexBaseUrl + codexApiKey");
6229
- }
6253
+ this.registry.register(new CodexAdapter({ env: { baseUrl: a.codexBaseUrl, apiKey: a.codexApiKey, defaultModel: a.codexDefaultModel ?? "default", models: a.codexModels, wireApi: a.codexWireApi ?? "responses" } }));
6230
6254
  } else if (a.type === "hermes") {
6231
6255
  this.registry.register(new HermesAdapter({ env: { defaultModel: a.hermesModel, provider: a.hermesProvider } }));
6232
6256
  } else if (a.type === "opencode") {