claude-codex-wechat 0.1.41 → 0.1.45

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 (2) hide show
  1. package/dist/server/cli.js +96 -12
  2. package/package.json +1 -1
@@ -2806,7 +2806,7 @@ function isTemporaryShim(candidate) {
2806
2806
  const tempDir = tmpdir();
2807
2807
  return candidate.startsWith(tempDir);
2808
2808
  }
2809
- async function findExecutable(command) {
2809
+ async function findExecutable(command, pathEnv) {
2810
2810
  const extensions = executableExtensions();
2811
2811
  if (command.includes("/") || command.includes("\\")) {
2812
2812
  for (const ext of extensions) {
@@ -2814,7 +2814,7 @@ async function findExecutable(command) {
2814
2814
  }
2815
2815
  return void 0;
2816
2816
  }
2817
- const dirs = (process.env.PATH ?? "").split(delimiter).filter(Boolean);
2817
+ const dirs = (pathEnv ?? "").split(delimiter).filter(Boolean);
2818
2818
  let fallback;
2819
2819
  for (const dir of dirs) {
2820
2820
  for (const ext of extensions) {
@@ -2856,6 +2856,71 @@ function statePath(filename) {
2856
2856
  return join9(tmpdir(), filename);
2857
2857
  }
2858
2858
 
2859
+ // src/shared/loginShellEnv.ts
2860
+ import { spawnSync } from "node:child_process";
2861
+ import { delimiter as delimiter2 } from "node:path";
2862
+ var DELIMITER = "__CCW_LOGIN_ENV_DELIM_5f3a2b7c__";
2863
+ function parseEnvBlock(block) {
2864
+ const env = {};
2865
+ let currentKey = null;
2866
+ const normalized = block.replace(/\n$/, "");
2867
+ for (const line of normalized.split("\n")) {
2868
+ const match = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(line);
2869
+ if (match) {
2870
+ currentKey = match[1];
2871
+ env[currentKey] = match[2];
2872
+ } else if (currentKey) {
2873
+ env[currentKey] = `${env[currentKey]}
2874
+ ${line}`;
2875
+ }
2876
+ }
2877
+ return env;
2878
+ }
2879
+ function captureLoginShellEnv(deps = {}) {
2880
+ const platform = deps.platform ?? process.platform;
2881
+ if (platform === "win32") return null;
2882
+ const run = deps.run ?? spawnSync;
2883
+ const shell = deps.shell ?? process.env.SHELL ?? "/bin/zsh";
2884
+ const timeoutMs = deps.timeoutMs ?? 5e3;
2885
+ const command = `printf %s '${DELIMITER}'; env; printf %s '${DELIMITER}'`;
2886
+ try {
2887
+ const result = run(shell, ["-l", "-i", "-c", command], {
2888
+ timeout: timeoutMs,
2889
+ encoding: "utf8",
2890
+ maxBuffer: 8 * 1024 * 1024
2891
+ });
2892
+ const stdout = typeof result.stdout === "string" ? result.stdout : "";
2893
+ const start = stdout.indexOf(DELIMITER);
2894
+ const end = stdout.indexOf(DELIMITER, start + DELIMITER.length);
2895
+ if (start === -1 || end === -1 || end <= start) return null;
2896
+ const block = stdout.slice(start + DELIMITER.length, end);
2897
+ const env = parseEnvBlock(block);
2898
+ if (!env.PATH) return null;
2899
+ return env;
2900
+ } catch {
2901
+ return null;
2902
+ }
2903
+ }
2904
+ var cache;
2905
+ function resolveLoginShellEnv() {
2906
+ if (cache !== void 0) return cache;
2907
+ cache = captureLoginShellEnv();
2908
+ if (cache === null && process.platform !== "win32") {
2909
+ console.warn(
2910
+ "[claude-codex-wechat] \u7EC8\u7AEF\u73AF\u5883\u590D\u523B\u5931\u8D25\uFF0C\u5DF2\u9000\u56DE process.env\uFF08PATH/\u51ED\u8BC1\u53EF\u80FD\u4E0E\u7EC8\u7AEF\u4E0D\u4E00\u81F4\uFF09\u3002\u82E5 provider \u62A5\u300C\u627E\u4E0D\u5230\u300D\u6216\u300C\u4EE4\u724C\u5DF2\u8FC7\u671F\u300D\uFF0C\u8BF7\u4ECE\u4EA4\u4E92\u7EC8\u7AEF\u91CD\u542F daemon\u3002"
2911
+ );
2912
+ }
2913
+ return cache;
2914
+ }
2915
+ function resolveTerminalSearchPath() {
2916
+ return mergeSearchPath(resolveLoginShellEnv()?.PATH, process.env.PATH);
2917
+ }
2918
+ function mergeSearchPath(primary, fallback) {
2919
+ if (!primary) return fallback;
2920
+ if (!fallback) return primary;
2921
+ return `${primary}${delimiter2}${fallback}`;
2922
+ }
2923
+
2859
2924
  // src/providers/claude-code/assistantContent.ts
2860
2925
  function extractAssistantBlocks(message) {
2861
2926
  if (!message || typeof message !== "object") return [];
@@ -2970,12 +3035,12 @@ var BRIDGE_APPEND_SYSTEM_PROMPT = [
2970
3035
 
2971
3036
  // src/providers/claude-code/claudeCapabilities.ts
2972
3037
  import { spawn as spawn2 } from "node:child_process";
2973
- var cache = /* @__PURE__ */ new Map();
3038
+ var cache2 = /* @__PURE__ */ new Map();
2974
3039
  var probeAppendSystemPromptSupport = (command) => {
2975
- const cached = cache.get(command);
3040
+ const cached = cache2.get(command);
2976
3041
  if (cached) return cached;
2977
3042
  const result = runHelpProbe(command);
2978
- cache.set(command, result);
3043
+ cache2.set(command, result);
2979
3044
  return result;
2980
3045
  };
2981
3046
  function runHelpProbe(command) {
@@ -3224,7 +3289,7 @@ function parseJsonLine(line) {
3224
3289
  function defaultClaudeStreamSpawner(call, opts = {}) {
3225
3290
  const stderrCapBytes = opts.stderrCapBytes ?? 64 * 1024;
3226
3291
  const maxLineBytes = opts.maxLineBytes ?? 10 * 1024 * 1024;
3227
- const child = spawn3(call.command, call.args, { cwd: expandTilde(call.cwd) ?? call.cwd, stdio: ["pipe", "pipe", "pipe"], shell: useShellForCli() });
3292
+ const child = spawn3(call.command, call.args, { cwd: expandTilde(call.cwd) ?? call.cwd, stdio: ["pipe", "pipe", "pipe"], shell: useShellForCli(), env: resolveLoginShellEnv() ?? process.env });
3228
3293
  let stderr = "";
3229
3294
  let buffer = "";
3230
3295
  const queue = [];
@@ -3349,7 +3414,8 @@ var CodexAppServerClient = class {
3349
3414
  this.child = spawn4(command, ["app-server", "--listen", "stdio://"], {
3350
3415
  cwd: input.cwd,
3351
3416
  stdio: ["pipe", "pipe", "pipe"],
3352
- shell: useShellForCli()
3417
+ shell: useShellForCli(),
3418
+ env: resolveLoginShellEnv() ?? process.env
3353
3419
  });
3354
3420
  this.child.stdout.on("data", (chunk) => this.onStdout(String(chunk)));
3355
3421
  this.child.stderr.on("data", () => {
@@ -5585,12 +5651,28 @@ async function startDaemon(options) {
5585
5651
  configPath,
5586
5652
  ...options.tunnelProvider ? { tunnelProvider: options.tunnelProvider } : {}
5587
5653
  });
5654
+ const relayAuthToken = ensureRelayAuthTokenSync({ configPath });
5655
+ await persistBridgeDefaultsToConfigFile({
5656
+ configPath,
5657
+ defaultProvider: bridgeDefaults.defaultProvider,
5658
+ defaultWorkspace: bridgeDefaults.defaultWorkspace,
5659
+ tunnel: {
5660
+ relay: {
5661
+ serverUrl: bridgeDefaults.tunnel.relay?.serverUrl ?? "wss://wechat.style520.com/agent",
5662
+ authToken: relayAuthToken
5663
+ }
5664
+ }
5665
+ }).catch((error) => {
5666
+ console.warn("[config] \u5199\u5165 bridge/relay \u9ED8\u8BA4\u503C\u5931\u8D25\uFF1A", error instanceof Error ? error.message : String(error));
5667
+ });
5588
5668
  await options.attachFrontend(app);
5589
5669
  await app.listen({ host, port });
5590
5670
  const address = app.server.address();
5591
5671
  const actualPort = typeof address === "object" && address ? address.port : port;
5592
5672
  if (config.tunnel?.relay?.serverUrl && config.tunnel?.relay?.authToken) {
5593
- await resolvedTunnelProvider?.start().catch(() => void 0);
5673
+ void resolvedTunnelProvider?.start().catch((error) => {
5674
+ console.warn("[relay] \u96A7\u9053\u540E\u53F0\u542F\u52A8\u5931\u8D25\uFF0C\u5C06\u81EA\u52A8\u91CD\u8FDE\uFF1A", error instanceof Error ? error.message : String(error));
5675
+ });
5594
5676
  }
5595
5677
  if (options.enableUpdateCheck) {
5596
5678
  createUpdateChecker({ currentVersion: readClientVersion(), configPath }).start().catch(() => void 0);
@@ -5607,8 +5689,9 @@ function listLanIpv4Addresses() {
5607
5689
  return Object.values(networkInterfaces()).flat().filter((iface) => Boolean(iface)).filter((iface) => iface.family === "IPv4" && !iface.internal).map((iface) => iface.address);
5608
5690
  }
5609
5691
  async function resolveProviderCommands(providers) {
5610
- const claudeCommand = providers?.claude?.command ?? await findExecutable("claude");
5611
- const codexCommand = providers?.codex?.command ?? await findExecutable("codex");
5692
+ const searchPath = resolveTerminalSearchPath();
5693
+ const claudeCommand = providers?.claude?.command ?? await findExecutable("claude", searchPath);
5694
+ const codexCommand = providers?.codex?.command ?? await findExecutable("codex", searchPath);
5612
5695
  if (!claudeCommand && !codexCommand) return void 0;
5613
5696
  return {
5614
5697
  ...claudeCommand ? { claude: { command: claudeCommand } } : {},
@@ -6176,9 +6259,10 @@ async function cmdDoctor() {
6176
6259
  console.log("claude-codex-wechat doctor\n");
6177
6260
  report("\u914D\u7F6E\u6587\u4EF6", existsSync11(configPath) ? configPath : `\u7F3A\u5931 (${configPath})\uFF0C\u9996\u6B21 start \u65F6\u81EA\u52A8\u521B\u5EFA`);
6178
6261
  report("\u524D\u7AEF\u4EA7\u7269", existsSync11(webRoot) ? webRoot : `\u7F3A\u5931 (${webRoot})`);
6179
- const claude = await findExecutable("claude");
6262
+ const searchPath = resolveTerminalSearchPath();
6263
+ const claude = await findExecutable("claude", searchPath);
6180
6264
  report("claude \u53EF\u6267\u884C", claude ?? "\u672A\u627E\u5230\uFF0C\u9700\u5148\u5B89\u88C5\u5E76\u767B\u5F55 Claude Code");
6181
- const codex = await findExecutable("codex");
6265
+ const codex = await findExecutable("codex", searchPath);
6182
6266
  report("codex \u53EF\u6267\u884C", codex ?? "\u672A\u627E\u5230\uFF08\u4EC5\u4F7F\u7528 Claude \u65F6\u53EF\u5FFD\u7565\uFF09");
6183
6267
  if (existsSync11(configPath)) {
6184
6268
  const config = loadBridgeConfig(configPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-codex-wechat",
3
- "version": "0.1.41",
3
+ "version": "0.1.45",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@11.5.0",