@adhdev/daemon-core 0.9.1 → 0.9.3

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.
@@ -6,5 +6,26 @@ export interface DaemonUpgradeHelperPayload {
6
6
  cwd?: string;
7
7
  sessionHostAppName?: string;
8
8
  }
9
+ export interface CurrentGlobalInstallSurface {
10
+ npmExecutable: string;
11
+ packageRoot: string | null;
12
+ installPrefix: string | null;
13
+ }
14
+ export interface PinnedGlobalInstallCommand {
15
+ command: string;
16
+ args: string[];
17
+ surface: CurrentGlobalInstallSurface;
18
+ }
19
+ export declare function resolveCurrentGlobalInstallSurface(options: {
20
+ packageName: string;
21
+ currentCliPath?: string;
22
+ nodeExecutable?: string;
23
+ }): CurrentGlobalInstallSurface;
24
+ export declare function buildPinnedGlobalInstallCommand(options: {
25
+ packageName: string;
26
+ targetVersion: string;
27
+ currentCliPath?: string;
28
+ nodeExecutable?: string;
29
+ }): PinnedGlobalInstallCommand;
9
30
  export declare function spawnDetachedDaemonUpgradeHelper(payload: DaemonUpgradeHelperPayload): void;
10
31
  export declare function maybeRunDaemonUpgradeHelperFromEnv(): Promise<boolean>;
package/dist/index.d.ts CHANGED
@@ -42,8 +42,8 @@ export { DaemonCommandHandler } from './commands/handler.js';
42
42
  export type { CommandResult, CommandContext } from './commands/handler.js';
43
43
  export { DaemonCommandRouter } from './commands/router.js';
44
44
  export type { CommandRouterDeps, CommandRouterResult } from './commands/router.js';
45
- export { maybeRunDaemonUpgradeHelperFromEnv, spawnDetachedDaemonUpgradeHelper } from './commands/upgrade-helper.js';
46
- export type { DaemonUpgradeHelperPayload } from './commands/upgrade-helper.js';
45
+ export { maybeRunDaemonUpgradeHelperFromEnv, spawnDetachedDaemonUpgradeHelper, resolveCurrentGlobalInstallSurface, buildPinnedGlobalInstallCommand, } from './commands/upgrade-helper.js';
46
+ export type { DaemonUpgradeHelperPayload, CurrentGlobalInstallSurface, PinnedGlobalInstallCommand, } from './commands/upgrade-helper.js';
47
47
  export { DaemonStatusReporter } from './status/reporter.js';
48
48
  export { buildSessionEntries, findCdpManager, hasCdpManager, isCdpConnected } from './status/builders.js';
49
49
  export { buildStatusSnapshot, buildMachineInfo } from './status/snapshot.js';
package/dist/index.js CHANGED
@@ -3457,10 +3457,6 @@ ${data.message || ""}`.trim();
3457
3457
  throw new Error(`${this.cliName} is still processing the previous prompt`);
3458
3458
  }
3459
3459
  }
3460
- const blockingModal = this.activeModal || this.getStartupConfirmationModal(this.terminalScreen.getText() || "");
3461
- if (blockingModal || this.currentStatus === "waiting_approval") {
3462
- throw new Error(`${this.cliName} is awaiting confirmation before it can accept a prompt`);
3463
- }
3464
3460
  this.isWaitingForResponse = true;
3465
3461
  this.responseBuffer = "";
3466
3462
  this.finishRetryCount = 0;
@@ -4043,6 +4039,7 @@ __export(index_exports, {
4043
4039
  buildChatMessageSignature: () => buildChatMessageSignature,
4044
4040
  buildChatTailDeliverySignature: () => buildChatTailDeliverySignature,
4045
4041
  buildMachineInfo: () => buildMachineInfo,
4042
+ buildPinnedGlobalInstallCommand: () => buildPinnedGlobalInstallCommand,
4046
4043
  buildRuntimeSystemChatMessage: () => buildRuntimeSystemChatMessage,
4047
4044
  buildSessionEntries: () => buildSessionEntries,
4048
4045
  buildSessionModalDeliverySignature: () => buildSessionModalDeliverySignature,
@@ -4125,6 +4122,7 @@ __export(index_exports, {
4125
4122
  resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
4126
4123
  resetState: () => resetState,
4127
4124
  resolveChatMessageKind: () => resolveChatMessageKind,
4125
+ resolveCurrentGlobalInstallSurface: () => resolveCurrentGlobalInstallSurface,
4128
4126
  resolveDebugRuntimeConfig: () => resolveDebugRuntimeConfig,
4129
4127
  resolveSessionHostAppName: () => resolveSessionHostAppName,
4130
4128
  resolveSessionHostAppNameResolution: () => resolveSessionHostAppNameResolution,
@@ -4781,8 +4779,8 @@ async function detectIDEs(providerLoader) {
4781
4779
  if ((0, import_fs3.existsSync)(bundledCli)) resolvedCli = bundledCli;
4782
4780
  }
4783
4781
  if (!resolvedCli && appPath && os20 === "win32") {
4784
- const { dirname: dirname6 } = await import("path");
4785
- const appDir = dirname6(appPath);
4782
+ const { dirname: dirname7 } = await import("path");
4783
+ const appDir = dirname7(appPath);
4786
4784
  const candidates = [
4787
4785
  `${appDir}\\\\bin\\\\${def.cli}.cmd`,
4788
4786
  `${appDir}\\\\bin\\\\${def.cli}`,
@@ -17923,9 +17921,82 @@ function appendUpgradeLog(message) {
17923
17921
  } catch {
17924
17922
  }
17925
17923
  }
17926
- function getNpmExecutable() {
17924
+ function resolveSiblingNpmExecutable(nodeExecutable) {
17925
+ const binDir = path16.dirname(nodeExecutable);
17926
+ const candidates = process.platform === "win32" ? ["npm.cmd", "npm.exe", "npm"] : ["npm"];
17927
+ for (const candidate of candidates) {
17928
+ const candidatePath = path16.join(binDir, candidate);
17929
+ if (fs8.existsSync(candidatePath)) {
17930
+ return candidatePath;
17931
+ }
17932
+ }
17927
17933
  return "npm";
17928
17934
  }
17935
+ function findCurrentPackageRoot(currentCliPath, packageName) {
17936
+ if (!currentCliPath) return null;
17937
+ let resolvedPath = currentCliPath;
17938
+ try {
17939
+ resolvedPath = fs8.realpathSync.native(currentCliPath);
17940
+ } catch {
17941
+ }
17942
+ let currentDir = resolvedPath;
17943
+ try {
17944
+ if (fs8.statSync(resolvedPath).isFile()) {
17945
+ currentDir = path16.dirname(resolvedPath);
17946
+ }
17947
+ } catch {
17948
+ currentDir = path16.dirname(resolvedPath);
17949
+ }
17950
+ while (true) {
17951
+ const packageJsonPath = path16.join(currentDir, "package.json");
17952
+ try {
17953
+ if (fs8.existsSync(packageJsonPath)) {
17954
+ const parsed = JSON.parse(fs8.readFileSync(packageJsonPath, "utf8"));
17955
+ if (parsed?.name === packageName) {
17956
+ const normalized = currentDir.replace(/\\/g, "/");
17957
+ return normalized.includes("/node_modules/") ? currentDir : null;
17958
+ }
17959
+ }
17960
+ } catch {
17961
+ }
17962
+ const parentDir = path16.dirname(currentDir);
17963
+ if (parentDir === currentDir) {
17964
+ return null;
17965
+ }
17966
+ currentDir = parentDir;
17967
+ }
17968
+ }
17969
+ function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
17970
+ const nodeModulesDir = packageName.startsWith("@") ? path16.dirname(path16.dirname(packageRoot)) : path16.dirname(packageRoot);
17971
+ if (path16.basename(nodeModulesDir) !== "node_modules") {
17972
+ return null;
17973
+ }
17974
+ const maybeLibDir = path16.dirname(nodeModulesDir);
17975
+ if (path16.basename(maybeLibDir) === "lib") {
17976
+ return path16.dirname(maybeLibDir);
17977
+ }
17978
+ return maybeLibDir;
17979
+ }
17980
+ function resolveCurrentGlobalInstallSurface(options) {
17981
+ const packageRoot = findCurrentPackageRoot(options.currentCliPath || process.argv[1], options.packageName);
17982
+ return {
17983
+ npmExecutable: resolveSiblingNpmExecutable(options.nodeExecutable || process.execPath),
17984
+ packageRoot,
17985
+ installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null
17986
+ };
17987
+ }
17988
+ function buildPinnedGlobalInstallCommand(options) {
17989
+ const surface = resolveCurrentGlobalInstallSurface(options);
17990
+ const args = ["install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
17991
+ if (surface.installPrefix) {
17992
+ args.push("--prefix", surface.installPrefix);
17993
+ }
17994
+ return {
17995
+ command: surface.npmExecutable,
17996
+ args,
17997
+ surface
17998
+ };
17999
+ }
17929
18000
  function getNpmExecOptions() {
17930
18001
  return { shell: process.platform === "win32" };
17931
18002
  }
@@ -17988,11 +18059,12 @@ function removeDaemonPidFile() {
17988
18059
  } catch {
17989
18060
  }
17990
18061
  }
17991
- function cleanupStaleGlobalInstallDirs(pkgName) {
18062
+ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
17992
18063
  const npmExecOpts = getNpmExecOptions();
17993
- const npmRoot = (0, import_child_process7.execFileSync)(getNpmExecutable(), ["root", "-g"], { encoding: "utf8", ...npmExecOpts }).trim();
18064
+ const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
18065
+ const npmRoot = (0, import_child_process7.execFileSync)(surface.npmExecutable, ["root", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
17994
18066
  if (!npmRoot) return;
17995
- const npmPrefix = (0, import_child_process7.execFileSync)(getNpmExecutable(), ["prefix", "-g"], { encoding: "utf8", ...npmExecOpts }).trim();
18067
+ const npmPrefix = surface.installPrefix || (0, import_child_process7.execFileSync)(surface.npmExecutable, ["prefix", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
17996
18068
  const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
17997
18069
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
17998
18070
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
@@ -18017,7 +18089,7 @@ function cleanupStaleGlobalInstallDirs(pkgName) {
18017
18089
  }
18018
18090
  if (fs8.existsSync(binDir)) {
18019
18091
  for (const entry of fs8.readdirSync(binDir)) {
18020
- if (![...binNames].some((name) => entry.startsWith(`.${name}-`))) continue;
18092
+ if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
18021
18093
  fs8.rmSync(path16.join(binDir, entry), { recursive: true, force: true });
18022
18094
  appendUpgradeLog(`Removed stale bin staging entry: ${path16.join(binDir, entry)}`);
18023
18095
  }
@@ -18037,19 +18109,27 @@ function spawnDetachedDaemonUpgradeHelper(payload) {
18037
18109
  async function runDaemonUpgradeHelper(payload) {
18038
18110
  const restartArgv = Array.isArray(payload.restartArgv) ? payload.restartArgv : [];
18039
18111
  const sessionHostAppName = payload.sessionHostAppName || process.env.ADHDEV_SESSION_HOST_NAME || "adhdev";
18112
+ const installCommand = buildPinnedGlobalInstallCommand({
18113
+ packageName: payload.packageName,
18114
+ targetVersion: payload.targetVersion
18115
+ });
18040
18116
  appendUpgradeLog(`Upgrade helper started for ${payload.packageName}@${payload.targetVersion}`);
18117
+ appendUpgradeLog(`Using npm executable: ${installCommand.command}`);
18118
+ if (installCommand.surface.installPrefix) {
18119
+ appendUpgradeLog(`Pinned install prefix: ${installCommand.surface.installPrefix}`);
18120
+ }
18041
18121
  if (Number.isFinite(payload.parentPid) && payload.parentPid > 0) {
18042
18122
  appendUpgradeLog(`Waiting for parent pid ${payload.parentPid} to exit`);
18043
18123
  await waitForPidExit(payload.parentPid, 15e3);
18044
18124
  }
18045
18125
  stopSessionHostProcesses(sessionHostAppName);
18046
18126
  removeDaemonPidFile();
18047
- cleanupStaleGlobalInstallDirs(payload.packageName);
18127
+ cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
18048
18128
  const spec = `${payload.packageName}@${payload.targetVersion || "latest"}`;
18049
18129
  appendUpgradeLog(`Installing ${spec}`);
18050
18130
  const installOutput = (0, import_child_process7.execFileSync)(
18051
- getNpmExecutable(),
18052
- ["install", "-g", spec, "--force"],
18131
+ installCommand.command,
18132
+ installCommand.args,
18053
18133
  {
18054
18134
  encoding: "utf8",
18055
18135
  stdio: "pipe",
@@ -18062,7 +18142,7 @@ async function runDaemonUpgradeHelper(payload) {
18062
18142
  }
18063
18143
  if (process.platform === "win32") {
18064
18144
  await new Promise((resolve12) => setTimeout(resolve12, 500));
18065
- cleanupStaleGlobalInstallDirs(payload.packageName);
18145
+ cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
18066
18146
  appendUpgradeLog("Post-install staging cleanup complete");
18067
18147
  }
18068
18148
  if (restartArgv.length > 0) {
@@ -26744,6 +26824,7 @@ async function shutdownDaemonComponents(components) {
26744
26824
  buildChatMessageSignature,
26745
26825
  buildChatTailDeliverySignature,
26746
26826
  buildMachineInfo,
26827
+ buildPinnedGlobalInstallCommand,
26747
26828
  buildRuntimeSystemChatMessage,
26748
26829
  buildSessionEntries,
26749
26830
  buildSessionModalDeliverySignature,
@@ -26826,6 +26907,7 @@ async function shutdownDaemonComponents(components) {
26826
26907
  resetDebugRuntimeConfig,
26827
26908
  resetState,
26828
26909
  resolveChatMessageKind,
26910
+ resolveCurrentGlobalInstallSurface,
26829
26911
  resolveDebugRuntimeConfig,
26830
26912
  resolveSessionHostAppName,
26831
26913
  resolveSessionHostAppNameResolution,