@adhdev/daemon-standalone 0.9.2 → 0.9.4

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/index.js CHANGED
@@ -31321,10 +31321,6 @@ ${data.message || ""}`.trim();
31321
31321
  throw new Error(`${this.cliName} is still processing the previous prompt`);
31322
31322
  }
31323
31323
  }
31324
- const blockingModal = this.activeModal || this.getStartupConfirmationModal(this.terminalScreen.getText() || "");
31325
- if (blockingModal || this.currentStatus === "waiting_approval") {
31326
- throw new Error(`${this.cliName} is awaiting confirmation before it can accept a prompt`);
31327
- }
31328
31324
  this.isWaitingForResponse = true;
31329
31325
  this.responseBuffer = "";
31330
31326
  this.finishRetryCount = 0;
@@ -31905,6 +31901,7 @@ ${data.message || ""}`.trim();
31905
31901
  buildChatMessageSignature: () => buildChatMessageSignature,
31906
31902
  buildChatTailDeliverySignature: () => buildChatTailDeliverySignature,
31907
31903
  buildMachineInfo: () => buildMachineInfo2,
31904
+ buildPinnedGlobalInstallCommand: () => buildPinnedGlobalInstallCommand,
31908
31905
  buildRuntimeSystemChatMessage: () => buildRuntimeSystemChatMessage,
31909
31906
  buildSessionEntries: () => buildSessionEntries,
31910
31907
  buildSessionModalDeliverySignature: () => buildSessionModalDeliverySignature,
@@ -31987,6 +31984,7 @@ ${data.message || ""}`.trim();
31987
31984
  resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
31988
31985
  resetState: () => resetState,
31989
31986
  resolveChatMessageKind: () => resolveChatMessageKind,
31987
+ resolveCurrentGlobalInstallSurface: () => resolveCurrentGlobalInstallSurface,
31990
31988
  resolveDebugRuntimeConfig: () => resolveDebugRuntimeConfig,
31991
31989
  resolveSessionHostAppName: () => resolveSessionHostAppName,
31992
31990
  resolveSessionHostAppNameResolution: () => resolveSessionHostAppNameResolution2,
@@ -32625,8 +32623,8 @@ ${data.message || ""}`.trim();
32625
32623
  if ((0, import_fs3.existsSync)(bundledCli)) resolvedCli = bundledCli;
32626
32624
  }
32627
32625
  if (!resolvedCli && appPath && os20 === "win32") {
32628
- const { dirname: dirname6 } = await import("path");
32629
- const appDir = dirname6(appPath);
32626
+ const { dirname: dirname7 } = await import("path");
32627
+ const appDir = dirname7(appPath);
32630
32628
  const candidates = [
32631
32629
  `${appDir}\\\\bin\\\\${def.cli}.cmd`,
32632
32630
  `${appDir}\\\\bin\\\\${def.cli}`,
@@ -45653,9 +45651,82 @@ Run 'adhdev doctor' for detailed diagnostics.`
45653
45651
  } catch {
45654
45652
  }
45655
45653
  }
45656
- function getNpmExecutable() {
45654
+ function resolveSiblingNpmExecutable(nodeExecutable) {
45655
+ const binDir = path16.dirname(nodeExecutable);
45656
+ const candidates = process.platform === "win32" ? ["npm.cmd", "npm.exe", "npm"] : ["npm"];
45657
+ for (const candidate of candidates) {
45658
+ const candidatePath = path16.join(binDir, candidate);
45659
+ if (fs8.existsSync(candidatePath)) {
45660
+ return candidatePath;
45661
+ }
45662
+ }
45657
45663
  return "npm";
45658
45664
  }
45665
+ function findCurrentPackageRoot(currentCliPath, packageName) {
45666
+ if (!currentCliPath) return null;
45667
+ let resolvedPath = currentCliPath;
45668
+ try {
45669
+ resolvedPath = fs8.realpathSync.native(currentCliPath);
45670
+ } catch {
45671
+ }
45672
+ let currentDir = resolvedPath;
45673
+ try {
45674
+ if (fs8.statSync(resolvedPath).isFile()) {
45675
+ currentDir = path16.dirname(resolvedPath);
45676
+ }
45677
+ } catch {
45678
+ currentDir = path16.dirname(resolvedPath);
45679
+ }
45680
+ while (true) {
45681
+ const packageJsonPath = path16.join(currentDir, "package.json");
45682
+ try {
45683
+ if (fs8.existsSync(packageJsonPath)) {
45684
+ const parsed = JSON.parse(fs8.readFileSync(packageJsonPath, "utf8"));
45685
+ if (parsed?.name === packageName) {
45686
+ const normalized = currentDir.replace(/\\/g, "/");
45687
+ return normalized.includes("/node_modules/") ? currentDir : null;
45688
+ }
45689
+ }
45690
+ } catch {
45691
+ }
45692
+ const parentDir = path16.dirname(currentDir);
45693
+ if (parentDir === currentDir) {
45694
+ return null;
45695
+ }
45696
+ currentDir = parentDir;
45697
+ }
45698
+ }
45699
+ function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
45700
+ const nodeModulesDir = packageName.startsWith("@") ? path16.dirname(path16.dirname(packageRoot)) : path16.dirname(packageRoot);
45701
+ if (path16.basename(nodeModulesDir) !== "node_modules") {
45702
+ return null;
45703
+ }
45704
+ const maybeLibDir = path16.dirname(nodeModulesDir);
45705
+ if (path16.basename(maybeLibDir) === "lib") {
45706
+ return path16.dirname(maybeLibDir);
45707
+ }
45708
+ return maybeLibDir;
45709
+ }
45710
+ function resolveCurrentGlobalInstallSurface(options) {
45711
+ const packageRoot = findCurrentPackageRoot(options.currentCliPath || process.argv[1], options.packageName);
45712
+ return {
45713
+ npmExecutable: resolveSiblingNpmExecutable(options.nodeExecutable || process.execPath),
45714
+ packageRoot,
45715
+ installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null
45716
+ };
45717
+ }
45718
+ function buildPinnedGlobalInstallCommand(options) {
45719
+ const surface = resolveCurrentGlobalInstallSurface(options);
45720
+ const args = ["install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
45721
+ if (surface.installPrefix) {
45722
+ args.push("--prefix", surface.installPrefix);
45723
+ }
45724
+ return {
45725
+ command: surface.npmExecutable,
45726
+ args,
45727
+ surface
45728
+ };
45729
+ }
45659
45730
  function getNpmExecOptions() {
45660
45731
  return { shell: process.platform === "win32" };
45661
45732
  }
@@ -45718,11 +45789,12 @@ Run 'adhdev doctor' for detailed diagnostics.`
45718
45789
  } catch {
45719
45790
  }
45720
45791
  }
45721
- function cleanupStaleGlobalInstallDirs(pkgName) {
45792
+ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
45722
45793
  const npmExecOpts = getNpmExecOptions();
45723
- const npmRoot = (0, import_child_process7.execFileSync)(getNpmExecutable(), ["root", "-g"], { encoding: "utf8", ...npmExecOpts }).trim();
45794
+ const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
45795
+ const npmRoot = (0, import_child_process7.execFileSync)(surface.npmExecutable, ["root", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
45724
45796
  if (!npmRoot) return;
45725
- const npmPrefix = (0, import_child_process7.execFileSync)(getNpmExecutable(), ["prefix", "-g"], { encoding: "utf8", ...npmExecOpts }).trim();
45797
+ const npmPrefix = surface.installPrefix || (0, import_child_process7.execFileSync)(surface.npmExecutable, ["prefix", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
45726
45798
  const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
45727
45799
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
45728
45800
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
@@ -45747,7 +45819,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
45747
45819
  }
45748
45820
  if (fs8.existsSync(binDir)) {
45749
45821
  for (const entry of fs8.readdirSync(binDir)) {
45750
- if (![...binNames].some((name) => entry.startsWith(`.${name}-`))) continue;
45822
+ if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
45751
45823
  fs8.rmSync(path16.join(binDir, entry), { recursive: true, force: true });
45752
45824
  appendUpgradeLog(`Removed stale bin staging entry: ${path16.join(binDir, entry)}`);
45753
45825
  }
@@ -45767,19 +45839,27 @@ Run 'adhdev doctor' for detailed diagnostics.`
45767
45839
  async function runDaemonUpgradeHelper(payload) {
45768
45840
  const restartArgv = Array.isArray(payload.restartArgv) ? payload.restartArgv : [];
45769
45841
  const sessionHostAppName = payload.sessionHostAppName || process.env.ADHDEV_SESSION_HOST_NAME || "adhdev";
45842
+ const installCommand = buildPinnedGlobalInstallCommand({
45843
+ packageName: payload.packageName,
45844
+ targetVersion: payload.targetVersion
45845
+ });
45770
45846
  appendUpgradeLog(`Upgrade helper started for ${payload.packageName}@${payload.targetVersion}`);
45847
+ appendUpgradeLog(`Using npm executable: ${installCommand.command}`);
45848
+ if (installCommand.surface.installPrefix) {
45849
+ appendUpgradeLog(`Pinned install prefix: ${installCommand.surface.installPrefix}`);
45850
+ }
45771
45851
  if (Number.isFinite(payload.parentPid) && payload.parentPid > 0) {
45772
45852
  appendUpgradeLog(`Waiting for parent pid ${payload.parentPid} to exit`);
45773
45853
  await waitForPidExit(payload.parentPid, 15e3);
45774
45854
  }
45775
45855
  stopSessionHostProcesses(sessionHostAppName);
45776
45856
  removeDaemonPidFile();
45777
- cleanupStaleGlobalInstallDirs(payload.packageName);
45857
+ cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
45778
45858
  const spec = `${payload.packageName}@${payload.targetVersion || "latest"}`;
45779
45859
  appendUpgradeLog(`Installing ${spec}`);
45780
45860
  const installOutput = (0, import_child_process7.execFileSync)(
45781
- getNpmExecutable(),
45782
- ["install", "-g", spec, "--force"],
45861
+ installCommand.command,
45862
+ installCommand.args,
45783
45863
  {
45784
45864
  encoding: "utf8",
45785
45865
  stdio: "pipe",
@@ -45792,7 +45872,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
45792
45872
  }
45793
45873
  if (process.platform === "win32") {
45794
45874
  await new Promise((resolve12) => setTimeout(resolve12, 500));
45795
- cleanupStaleGlobalInstallDirs(payload.packageName);
45875
+ cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
45796
45876
  appendUpgradeLog("Post-install staging cleanup complete");
45797
45877
  }
45798
45878
  if (restartArgv.length > 0) {