deskbuddy 0.2.0-beta.23 → 0.2.0-beta.25

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.
@@ -2400,7 +2400,7 @@ function subscribedEvents(registry, tool, fallback) {
2400
2400
  }
2401
2401
 
2402
2402
  // src/wrap/shim.ts
2403
- import { execFileSync as execFileSync5 } from "child_process";
2403
+ import { execFile as execFile3, execFileSync as execFileSync5 } from "child_process";
2404
2404
  import { chmodSync as chmodSync3, existsSync as existsSync12, mkdirSync as mkdirSync10, readdirSync as readdirSync2, readFileSync as readFileSync13, rmdirSync, rmSync as rmSync4, writeFileSync as writeFileSync10 } from "fs";
2405
2405
  import { homedir as homedir4 } from "os";
2406
2406
  import { delimiter as delimiter2, join as join11, resolve as resolve3 } from "path";
@@ -2412,6 +2412,7 @@ var RC_BEGIN = "# >>> deskbuddy >>>";
2412
2412
  var RC_END = "# <<< deskbuddy <<<";
2413
2413
  var RC_FILES = [".zshrc", ".bashrc"];
2414
2414
  var WIN_PENDING = "Windows \u7A97\u53E3\u63A5\u7BA1\u5F85\u9A8C\u8BC1\uFF0C\u6682\u672A\u5F00\u542F";
2415
+ var WIN_PATH_RETRY = "DeskBuddy \u540E\u53F0\u6BCF\u5C0F\u65F6\u4F1A\u81EA\u52A8\u91CD\u8BD5\uFF1B\u4E5F\u53EF\u624B\u52A8\u628A\u5B83\u52A0\u5230\u7528\u6237 PATH \u6700\u524D\u9762";
2415
2416
  function shimDir() {
2416
2417
  return join11(deskbuddyHome(), "bin");
2417
2418
  }
@@ -2568,8 +2569,7 @@ function winKey(p) {
2568
2569
  return p.replace(/\//g, "\\").replace(/\\+$/, "").toLowerCase();
2569
2570
  }
2570
2571
  function addPathEntry(value, dir) {
2571
- const parts = value.split(";");
2572
- if (parts.some((p) => winKey(p) === winKey(dir))) return null;
2572
+ if (hasPathEntry(value, dir)) return null;
2573
2573
  return value === "" ? dir : `${dir};${value}`;
2574
2574
  }
2575
2575
  function removePathEntry(value, dir) {
@@ -2580,27 +2580,94 @@ function removePathEntry(value, dir) {
2580
2580
  }
2581
2581
  var PS_READ = "$k=[Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment');$v='';if($k){$v=$k.GetValue('Path','',[Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)};[Console]::Out.Write([Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes([string]$v)))";
2582
2582
  var PS_WRITE = "$k=[Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment');$kind=[Microsoft.Win32.RegistryValueKind]::ExpandString;try{$kind=$k.GetValueKind('Path')}catch{};if([string]::IsNullOrEmpty($env:DESKBUDDY_NEW_PATH)){$k.DeleteValue('Path',$false)}else{$k.SetValue('Path',$env:DESKBUDDY_NEW_PATH,$kind)};[Environment]::SetEnvironmentVariable('DESKBUDDY_PATH_REFRESH','1','User');[Environment]::SetEnvironmentVariable('DESKBUDDY_PATH_REFRESH',$null,'User')";
2583
- function psWinPath() {
2584
- const ps = (script, env) => execFileSync5("powershell.exe", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script], {
2585
- encoding: "utf8",
2586
- stdio: ["ignore", "pipe", "ignore"],
2587
- windowsHide: true,
2588
- timeout: 15e3,
2589
- env: env ?? process.env
2590
- });
2583
+ var PS_PATH_TIMEOUT_MS = 6e4;
2584
+ function withRetry(fn) {
2585
+ try {
2586
+ return fn();
2587
+ } catch {
2588
+ return fn();
2589
+ }
2590
+ }
2591
+ function psError(e) {
2592
+ const err = e;
2593
+ if (err?.code === "ETIMEDOUT" || err?.signal === "SIGTERM") return `PowerShell ${PS_PATH_TIMEOUT_MS / 1e3} \u79D2\u6CA1\u54CD\u5E94`;
2594
+ return err?.message || String(e);
2595
+ }
2596
+ function psWinPath(exec = execFileSync5) {
2597
+ const ps = (script, env) => String(
2598
+ exec("powershell.exe", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script], {
2599
+ encoding: "utf8",
2600
+ stdio: ["ignore", "pipe", "ignore"],
2601
+ windowsHide: true,
2602
+ timeout: PS_PATH_TIMEOUT_MS,
2603
+ env: env ?? process.env
2604
+ })
2605
+ );
2591
2606
  return {
2592
2607
  read: () => {
2593
2608
  try {
2594
- return Buffer.from(ps(PS_READ).trim(), "base64").toString("utf8");
2609
+ return Buffer.from(withRetry(() => ps(PS_READ)).trim(), "base64").toString("utf8");
2595
2610
  } catch {
2596
2611
  return null;
2597
2612
  }
2598
2613
  },
2599
2614
  write: (v) => {
2600
- ps(PS_WRITE, { ...process.env, DESKBUDDY_NEW_PATH: v });
2615
+ try {
2616
+ withRetry(() => ps(PS_WRITE, { ...process.env, DESKBUDDY_NEW_PATH: v }));
2617
+ } catch (e) {
2618
+ throw new Error(`\u5199\u7528\u6237 PATH \u5931\u8D25\uFF08${psError(e)}\uFF0C\u5DF2\u91CD\u8BD5\u4E00\u6B21\uFF09`);
2619
+ }
2620
+ }
2621
+ };
2622
+ }
2623
+ function psWinPathAsync(exec = execFile3) {
2624
+ const ps = (script, env) => new Promise((done, fail) => {
2625
+ exec(
2626
+ "powershell.exe",
2627
+ ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script],
2628
+ { encoding: "utf8", windowsHide: true, timeout: PS_PATH_TIMEOUT_MS, env: env ?? process.env },
2629
+ (err, stdout2) => err ? fail(err) : done(String(stdout2))
2630
+ );
2631
+ });
2632
+ const retry = async (fn) => {
2633
+ try {
2634
+ return await fn();
2635
+ } catch {
2636
+ return fn();
2637
+ }
2638
+ };
2639
+ return {
2640
+ read: async () => {
2641
+ try {
2642
+ return Buffer.from((await retry(() => ps(PS_READ))).trim(), "base64").toString("utf8");
2643
+ } catch {
2644
+ return null;
2645
+ }
2646
+ },
2647
+ write: async (v) => {
2648
+ try {
2649
+ await retry(() => ps(PS_WRITE, { ...process.env, DESKBUDDY_NEW_PATH: v }));
2650
+ } catch (e) {
2651
+ throw new Error(`\u5199\u7528\u6237 PATH \u5931\u8D25\uFF08${psError(e)}\uFF0C\u5DF2\u91CD\u8BD5\u4E00\u6B21\uFF09`);
2652
+ }
2601
2653
  }
2602
2654
  };
2603
2655
  }
2656
+ async function addWinPathAsync(binDir, ops) {
2657
+ const cur = await ops.read();
2658
+ if (cur === null) return { ok: false, message: `\u7A97\u53E3\u63A5\u7BA1\uFF1A\u8BFB\u4E0D\u5230\u7528\u6237 PATH\uFF08${WIN_PATH_RETRY}\uFF09` };
2659
+ const next = addPathEntry(cur, binDir);
2660
+ if (next === null) return { ok: true, message: "" };
2661
+ try {
2662
+ await ops.write(next);
2663
+ } catch (e) {
2664
+ return { ok: false, message: `\u7A97\u53E3\u63A5\u7BA1\uFF1A${e.message}\uFF08${WIN_PATH_RETRY}\uFF09` };
2665
+ }
2666
+ return { ok: true, message: "\u7A97\u53E3\u63A5\u7BA1\uFF1A\u5DF2\u628A\u57AB\u7247\u76EE\u5F55\u52A0\u5230\u7528\u6237 PATH \u6700\u524D\uFF0C\u65B0\u5F00\u7684\u7EC8\u7AEF\u91CC\u6572 claude \u5C31\u7ECF DeskBuddy \u6253\u5F00" };
2667
+ }
2668
+ function hasPathEntry(value, dir) {
2669
+ return value.split(";").some((p) => winKey(p) === winKey(dir));
2670
+ }
2604
2671
  function winShadowWarning(command, binDir, w) {
2605
2672
  let hit = null;
2606
2673
  try {
@@ -2673,11 +2740,14 @@ function defaultShimEnv(nodePath, cliPath) {
2673
2740
  env
2674
2741
  };
2675
2742
  }
2743
+ function daemonShimEnv(base) {
2744
+ return { ...base, winPath: null, winWhere: null, deferWinPath: base.platform === "win32" };
2745
+ }
2676
2746
  function installShim(tool, e) {
2677
2747
  const command = SHIM_COMMANDS[tool];
2678
2748
  if (!command) return { ok: false, message: "" };
2679
2749
  if (e.platform === "win32" && !WIN_SHIM_ENABLED) return { ok: false, message: WIN_PENDING };
2680
- if (e.platform === "win32" && tool === "codex") return { ok: false, message: WIN_PENDING };
2750
+ if (e.platform === "win32" && tool === "codex") return { ok: false, message: "" };
2681
2751
  const file = shimFile(e.binDir, command, e.platform);
2682
2752
  if (e.platform === "win32") {
2683
2753
  const node = cmdPath(e.nodePath, e.env);
@@ -2693,13 +2763,22 @@ function installShim(tool, e) {
2693
2763
  writeFileSync10(file, shScript(tool, command, e.nodePath, e.cliPath, e.binDir), { encoding: "utf8", mode: 493 });
2694
2764
  chmodSync3(file, 493);
2695
2765
  }
2766
+ if (e.platform === "win32" && e.deferWinPath) {
2767
+ return { ok: true, message: `\u7A97\u53E3\u63A5\u7BA1\uFF1A\u57AB\u7247\u5DF2\u88C5\u5728 ${e.binDir}\uFF0C\u7528\u6237 PATH \u7531\u540E\u53F0\u7A0D\u540E\u8865\u4E0A` };
2768
+ }
2696
2769
  const touched = [];
2697
2770
  if (e.platform === "win32") {
2698
2771
  if (e.winPath) {
2699
2772
  const cur = e.winPath.read();
2700
- if (cur === null) return { ok: false, message: "\u7A97\u53E3\u63A5\u7BA1\uFF1A\u8BFB\u4E0D\u5230\u7528\u6237 PATH\uFF0C\u8BF7\u624B\u52A8\u628A " + e.binDir + " \u52A0\u5230\u7528\u6237 PATH \u6700\u524D\u9762" };
2773
+ if (cur === null) return { ok: false, message: `\u7A97\u53E3\u63A5\u7BA1\uFF1A\u57AB\u7247\u5DF2\u88C5\u5728 ${e.binDir}\uFF0C\u4F46\u8BFB\u4E0D\u5230\u7528\u6237 PATH\uFF08${WIN_PATH_RETRY}\uFF09` };
2701
2774
  const next = addPathEntry(cur, e.binDir);
2702
- if (next !== null) e.winPath.write(next);
2775
+ if (next !== null) {
2776
+ try {
2777
+ e.winPath.write(next);
2778
+ } catch (err) {
2779
+ return { ok: false, message: `\u7A97\u53E3\u63A5\u7BA1\uFF1A\u57AB\u7247\u5DF2\u88C5\u5728 ${e.binDir}\uFF0C\u4F46${err.message}\uFF08${WIN_PATH_RETRY}\uFF09` };
2780
+ }
2781
+ }
2703
2782
  touched.push("\u7528\u6237 PATH");
2704
2783
  }
2705
2784
  } else if (e.rcHome) {
@@ -2752,6 +2831,9 @@ function uninstallShim(tool, e) {
2752
2831
  } catch {
2753
2832
  }
2754
2833
  if (ourShims(e.binDir).length > 0) return { ok: true, message: removed ? `\u5DF2\u5220\u9664\u7A97\u53E3\u63A5\u7BA1\u57AB\u7247 ${file}` : "" };
2834
+ if (e.platform === "win32" && e.deferWinPath) {
2835
+ return { ok: true, message: `\u7A97\u53E3\u63A5\u7BA1\uFF1A\u57AB\u7247\u5DF2\u88C5\u5728 ${e.binDir}\uFF0C\u7528\u6237 PATH \u7531\u540E\u53F0\u7A0D\u540E\u8865\u4E0A` };
2836
+ }
2755
2837
  const touched = [];
2756
2838
  if (e.platform === "win32") {
2757
2839
  if (e.winPath) {
@@ -3020,7 +3102,7 @@ function migrateLegacyQoder(out, detect = () => detectTools()) {
3020
3102
  }
3021
3103
 
3022
3104
  // src/daemon/loginGuide.ts
3023
- import { execFile as execFile5, execFileSync as execFileSync9 } from "child_process";
3105
+ import { execFile as execFile6, execFileSync as execFileSync9 } from "child_process";
3024
3106
  import { chmodSync as chmodSync7, existsSync as existsSync15, mkdirSync as mkdirSync14, readFileSync as readFileSync16, writeFileSync as writeFileSync14 } from "fs";
3025
3107
  import { homedir as homedir6 } from "os";
3026
3108
  import { join as join19 } from "path";
@@ -3288,7 +3370,7 @@ function launchPending(runId) {
3288
3370
  }
3289
3371
 
3290
3372
  // src/daemon/executor.ts
3291
- import { execFile as execFile3, execFileSync as execFileSync7 } from "child_process";
3373
+ import { execFile as execFile4, execFileSync as execFileSync7 } from "child_process";
3292
3374
  import { homedir as homedir5 } from "os";
3293
3375
  import { join as join17 } from "path";
3294
3376
 
@@ -3589,7 +3671,7 @@ function startCommand(plan, tool, limitMs = EXEC_TIMEOUT_MS) {
3589
3671
  };
3590
3672
  let timedOut = false;
3591
3673
  const done = new Promise((resolve4) => {
3592
- child = execFile3(
3674
+ child = execFile4(
3593
3675
  plan.file,
3594
3676
  plan.args,
3595
3677
  {
@@ -3661,7 +3743,7 @@ function killTree(child) {
3661
3743
  }
3662
3744
 
3663
3745
  // src/daemon/openWindow.ts
3664
- import { execFile as execFile4, execFileSync as execFileSync8, spawn as spawn2 } from "child_process";
3746
+ import { execFile as execFile5, execFileSync as execFileSync8, spawn as spawn2 } from "child_process";
3665
3747
  import { chmodSync as chmodSync6, mkdirSync as mkdirSync13, rmSync as rmSync7, writeFileSync as writeFileSync13 } from "fs";
3666
3748
  import { userInfo } from "os";
3667
3749
  import { join as join18 } from "path";
@@ -3751,7 +3833,7 @@ var defaultOpenerDeps = (findWt2) => ({
3751
3833
  platform: process.platform,
3752
3834
  findWt: findWt2,
3753
3835
  run: (file, args) => new Promise((resolve4, reject) => {
3754
- execFile4(file, args, { windowsHide: true, timeout: 15e3 }, (err) => err ? reject(err) : resolve4());
3836
+ execFile5(file, args, { windowsHide: true, timeout: 15e3 }, (err) => err ? reject(err) : resolve4());
3755
3837
  }),
3756
3838
  spawnDetached: (file, args) => {
3757
3839
  const c = spawn2(file, args, { detached: true, stdio: "ignore", shell: false, windowsHide: false });
@@ -3929,7 +4011,7 @@ var defaultProbeRun = (file, args, env, timeoutMs) => new Promise((resolve4) =>
3929
4011
  };
3930
4012
  const win = process.platform === "win32";
3931
4013
  const opts = { env, windowsHide: true, maxBuffer: 8 * 1024 * 1024, detached: !win };
3932
- const child = execFile5(file, args, opts, (err, stdout2, stderr) => {
4014
+ const child = execFile6(file, args, opts, (err, stdout2, stderr) => {
3933
4015
  clearTimeout(timer);
3934
4016
  const e = err;
3935
4017
  done({
@@ -4107,7 +4189,7 @@ var defaultLoginOpenDeps = () => ({
4107
4189
  });
4108
4190
  async function installCodebuddyHooks(log) {
4109
4191
  try {
4110
- const { installTools: installTools2 } = await import("./enable-A2TXGR7H.js");
4192
+ const { installTools: installTools2 } = await import("./enable-GWWMUIV7.js");
4111
4193
  installTools2(["workbuddy"], () => {
4112
4194
  }, null, { auto: true });
4113
4195
  } catch (e) {
@@ -4289,7 +4371,7 @@ async function autoEnableLoginLog(tools, check, log) {
4289
4371
  }
4290
4372
 
4291
4373
  // src/daemon/workbuddySetup.ts
4292
- import { execFile as execFile6, spawn as spawn3 } from "child_process";
4374
+ import { execFile as execFile7, spawn as spawn3 } from "child_process";
4293
4375
  import { existsSync as existsSync16, mkdirSync as mkdirSync15, readFileSync as readFileSync17, rmSync as rmSync8, statSync as statSync6, writeFileSync as writeFileSync15 } from "fs";
4294
4376
  import { dirname as dirname13, join as join20 } from "path";
4295
4377
  var DIALOG_TITLE = "DeskBuddy";
@@ -4310,7 +4392,7 @@ var DIALOG_TEXT = [
4310
4392
  var LIMITED_NOTE = "\u8BBE\u5907\u4E0A\u53EA\u80FD\u770B\u4EFB\u52A1\u72B6\u6001\u3001\u56DE\u7B54\u6388\u6743";
4311
4393
  var defaultRunner = (file, args, opts) => new Promise((resolve4) => {
4312
4394
  try {
4313
- const child = execFile6(
4395
+ const child = execFile7(
4314
4396
  file,
4315
4397
  args,
4316
4398
  { env: opts.env, timeout: opts.timeoutMs, windowsHide: true, maxBuffer: 8 * 1024 * 1024, encoding: "utf8" },
@@ -4674,7 +4756,7 @@ function defaultOfferDeps(log) {
4674
4756
  }),
4675
4757
  openLogin: () => defaultOpenLogin(platform),
4676
4758
  installHooks: async () => {
4677
- const { installTools: installTools2 } = await import("./enable-A2TXGR7H.js");
4759
+ const { installTools: installTools2 } = await import("./enable-GWWMUIV7.js");
4678
4760
  installTools2(["workbuddy"], (l) => log(`[WorkBuddy \u72EC\u7ACB\u7248] ${l}`), null, { auto: true });
4679
4761
  },
4680
4762
  log: (l) => log(`[WorkBuddy \u72EC\u7ACB\u7248] ${l}`),
@@ -4997,10 +5079,17 @@ export {
4997
5079
  SHIM_FALLBACK_EXIT,
4998
5080
  WIN_SHIM_ENABLED,
4999
5081
  SHIM_COMMANDS,
5082
+ SHIM_MARKER,
5000
5083
  WIN_PENDING,
5001
5084
  shimDir,
5085
+ shimFile,
5086
+ psWinPathAsync,
5087
+ addWinPathAsync,
5088
+ hasPathEntry,
5002
5089
  winShadowWarning,
5003
5090
  psWinWhere,
5091
+ daemonShimEnv,
5092
+ installShim,
5004
5093
  uninstallShim,
5005
5094
  shimState,
5006
5095
  migrateLegacyQoder,