@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.
- package/dist/commands/upgrade-helper.d.ts +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +97 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -15
- package/dist/index.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +0 -5
- package/src/commands/upgrade-helper.ts +128 -9
- package/src/index.d.ts +2 -2
- package/src/index.ts +11 -2
package/dist/index.mjs
CHANGED
|
@@ -3454,10 +3454,6 @@ ${data.message || ""}`.trim();
|
|
|
3454
3454
|
throw new Error(`${this.cliName} is still processing the previous prompt`);
|
|
3455
3455
|
}
|
|
3456
3456
|
}
|
|
3457
|
-
const blockingModal = this.activeModal || this.getStartupConfirmationModal(this.terminalScreen.getText() || "");
|
|
3458
|
-
if (blockingModal || this.currentStatus === "waiting_approval") {
|
|
3459
|
-
throw new Error(`${this.cliName} is awaiting confirmation before it can accept a prompt`);
|
|
3460
|
-
}
|
|
3461
3457
|
this.isWaitingForResponse = true;
|
|
3462
3458
|
this.responseBuffer = "";
|
|
3463
3459
|
this.finishRetryCount = 0;
|
|
@@ -4630,8 +4626,8 @@ async function detectIDEs(providerLoader) {
|
|
|
4630
4626
|
if (existsSync4(bundledCli)) resolvedCli = bundledCli;
|
|
4631
4627
|
}
|
|
4632
4628
|
if (!resolvedCli && appPath && os20 === "win32") {
|
|
4633
|
-
const { dirname:
|
|
4634
|
-
const appDir =
|
|
4629
|
+
const { dirname: dirname7 } = await import("path");
|
|
4630
|
+
const appDir = dirname7(appPath);
|
|
4635
4631
|
const candidates = [
|
|
4636
4632
|
`${appDir}\\\\bin\\\\${def.cli}.cmd`,
|
|
4637
4633
|
`${appDir}\\\\bin\\\\${def.cli}`,
|
|
@@ -17777,9 +17773,82 @@ function appendUpgradeLog(message) {
|
|
|
17777
17773
|
} catch {
|
|
17778
17774
|
}
|
|
17779
17775
|
}
|
|
17780
|
-
function
|
|
17776
|
+
function resolveSiblingNpmExecutable(nodeExecutable) {
|
|
17777
|
+
const binDir = path16.dirname(nodeExecutable);
|
|
17778
|
+
const candidates = process.platform === "win32" ? ["npm.cmd", "npm.exe", "npm"] : ["npm"];
|
|
17779
|
+
for (const candidate of candidates) {
|
|
17780
|
+
const candidatePath = path16.join(binDir, candidate);
|
|
17781
|
+
if (fs8.existsSync(candidatePath)) {
|
|
17782
|
+
return candidatePath;
|
|
17783
|
+
}
|
|
17784
|
+
}
|
|
17781
17785
|
return "npm";
|
|
17782
17786
|
}
|
|
17787
|
+
function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
17788
|
+
if (!currentCliPath) return null;
|
|
17789
|
+
let resolvedPath = currentCliPath;
|
|
17790
|
+
try {
|
|
17791
|
+
resolvedPath = fs8.realpathSync.native(currentCliPath);
|
|
17792
|
+
} catch {
|
|
17793
|
+
}
|
|
17794
|
+
let currentDir = resolvedPath;
|
|
17795
|
+
try {
|
|
17796
|
+
if (fs8.statSync(resolvedPath).isFile()) {
|
|
17797
|
+
currentDir = path16.dirname(resolvedPath);
|
|
17798
|
+
}
|
|
17799
|
+
} catch {
|
|
17800
|
+
currentDir = path16.dirname(resolvedPath);
|
|
17801
|
+
}
|
|
17802
|
+
while (true) {
|
|
17803
|
+
const packageJsonPath = path16.join(currentDir, "package.json");
|
|
17804
|
+
try {
|
|
17805
|
+
if (fs8.existsSync(packageJsonPath)) {
|
|
17806
|
+
const parsed = JSON.parse(fs8.readFileSync(packageJsonPath, "utf8"));
|
|
17807
|
+
if (parsed?.name === packageName) {
|
|
17808
|
+
const normalized = currentDir.replace(/\\/g, "/");
|
|
17809
|
+
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
17810
|
+
}
|
|
17811
|
+
}
|
|
17812
|
+
} catch {
|
|
17813
|
+
}
|
|
17814
|
+
const parentDir = path16.dirname(currentDir);
|
|
17815
|
+
if (parentDir === currentDir) {
|
|
17816
|
+
return null;
|
|
17817
|
+
}
|
|
17818
|
+
currentDir = parentDir;
|
|
17819
|
+
}
|
|
17820
|
+
}
|
|
17821
|
+
function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
|
|
17822
|
+
const nodeModulesDir = packageName.startsWith("@") ? path16.dirname(path16.dirname(packageRoot)) : path16.dirname(packageRoot);
|
|
17823
|
+
if (path16.basename(nodeModulesDir) !== "node_modules") {
|
|
17824
|
+
return null;
|
|
17825
|
+
}
|
|
17826
|
+
const maybeLibDir = path16.dirname(nodeModulesDir);
|
|
17827
|
+
if (path16.basename(maybeLibDir) === "lib") {
|
|
17828
|
+
return path16.dirname(maybeLibDir);
|
|
17829
|
+
}
|
|
17830
|
+
return maybeLibDir;
|
|
17831
|
+
}
|
|
17832
|
+
function resolveCurrentGlobalInstallSurface(options) {
|
|
17833
|
+
const packageRoot = findCurrentPackageRoot(options.currentCliPath || process.argv[1], options.packageName);
|
|
17834
|
+
return {
|
|
17835
|
+
npmExecutable: resolveSiblingNpmExecutable(options.nodeExecutable || process.execPath),
|
|
17836
|
+
packageRoot,
|
|
17837
|
+
installPrefix: packageRoot ? resolveInstallPrefixFromPackageRoot(packageRoot, options.packageName) : null
|
|
17838
|
+
};
|
|
17839
|
+
}
|
|
17840
|
+
function buildPinnedGlobalInstallCommand(options) {
|
|
17841
|
+
const surface = resolveCurrentGlobalInstallSurface(options);
|
|
17842
|
+
const args = ["install", "-g", `${options.packageName}@${options.targetVersion || "latest"}`, "--force"];
|
|
17843
|
+
if (surface.installPrefix) {
|
|
17844
|
+
args.push("--prefix", surface.installPrefix);
|
|
17845
|
+
}
|
|
17846
|
+
return {
|
|
17847
|
+
command: surface.npmExecutable,
|
|
17848
|
+
args,
|
|
17849
|
+
surface
|
|
17850
|
+
};
|
|
17851
|
+
}
|
|
17783
17852
|
function getNpmExecOptions() {
|
|
17784
17853
|
return { shell: process.platform === "win32" };
|
|
17785
17854
|
}
|
|
@@ -17842,11 +17911,12 @@ function removeDaemonPidFile() {
|
|
|
17842
17911
|
} catch {
|
|
17843
17912
|
}
|
|
17844
17913
|
}
|
|
17845
|
-
function cleanupStaleGlobalInstallDirs(pkgName) {
|
|
17914
|
+
function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
17846
17915
|
const npmExecOpts = getNpmExecOptions();
|
|
17847
|
-
const
|
|
17916
|
+
const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
|
|
17917
|
+
const npmRoot = execFileSync(surface.npmExecutable, ["root", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
|
|
17848
17918
|
if (!npmRoot) return;
|
|
17849
|
-
const npmPrefix = execFileSync(
|
|
17919
|
+
const npmPrefix = surface.installPrefix || execFileSync(surface.npmExecutable, ["prefix", "-g", ...prefixArgs], { encoding: "utf8", ...npmExecOpts }).trim();
|
|
17850
17920
|
const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
|
|
17851
17921
|
const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
|
|
17852
17922
|
const binNames = /* @__PURE__ */ new Set([packageBaseName]);
|
|
@@ -17871,7 +17941,7 @@ function cleanupStaleGlobalInstallDirs(pkgName) {
|
|
|
17871
17941
|
}
|
|
17872
17942
|
if (fs8.existsSync(binDir)) {
|
|
17873
17943
|
for (const entry of fs8.readdirSync(binDir)) {
|
|
17874
|
-
if (!
|
|
17944
|
+
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
17875
17945
|
fs8.rmSync(path16.join(binDir, entry), { recursive: true, force: true });
|
|
17876
17946
|
appendUpgradeLog(`Removed stale bin staging entry: ${path16.join(binDir, entry)}`);
|
|
17877
17947
|
}
|
|
@@ -17891,19 +17961,27 @@ function spawnDetachedDaemonUpgradeHelper(payload) {
|
|
|
17891
17961
|
async function runDaemonUpgradeHelper(payload) {
|
|
17892
17962
|
const restartArgv = Array.isArray(payload.restartArgv) ? payload.restartArgv : [];
|
|
17893
17963
|
const sessionHostAppName = payload.sessionHostAppName || process.env.ADHDEV_SESSION_HOST_NAME || "adhdev";
|
|
17964
|
+
const installCommand = buildPinnedGlobalInstallCommand({
|
|
17965
|
+
packageName: payload.packageName,
|
|
17966
|
+
targetVersion: payload.targetVersion
|
|
17967
|
+
});
|
|
17894
17968
|
appendUpgradeLog(`Upgrade helper started for ${payload.packageName}@${payload.targetVersion}`);
|
|
17969
|
+
appendUpgradeLog(`Using npm executable: ${installCommand.command}`);
|
|
17970
|
+
if (installCommand.surface.installPrefix) {
|
|
17971
|
+
appendUpgradeLog(`Pinned install prefix: ${installCommand.surface.installPrefix}`);
|
|
17972
|
+
}
|
|
17895
17973
|
if (Number.isFinite(payload.parentPid) && payload.parentPid > 0) {
|
|
17896
17974
|
appendUpgradeLog(`Waiting for parent pid ${payload.parentPid} to exit`);
|
|
17897
17975
|
await waitForPidExit(payload.parentPid, 15e3);
|
|
17898
17976
|
}
|
|
17899
17977
|
stopSessionHostProcesses(sessionHostAppName);
|
|
17900
17978
|
removeDaemonPidFile();
|
|
17901
|
-
cleanupStaleGlobalInstallDirs(payload.packageName);
|
|
17979
|
+
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
17902
17980
|
const spec = `${payload.packageName}@${payload.targetVersion || "latest"}`;
|
|
17903
17981
|
appendUpgradeLog(`Installing ${spec}`);
|
|
17904
17982
|
const installOutput = execFileSync(
|
|
17905
|
-
|
|
17906
|
-
|
|
17983
|
+
installCommand.command,
|
|
17984
|
+
installCommand.args,
|
|
17907
17985
|
{
|
|
17908
17986
|
encoding: "utf8",
|
|
17909
17987
|
stdio: "pipe",
|
|
@@ -17916,7 +17994,7 @@ async function runDaemonUpgradeHelper(payload) {
|
|
|
17916
17994
|
}
|
|
17917
17995
|
if (process.platform === "win32") {
|
|
17918
17996
|
await new Promise((resolve12) => setTimeout(resolve12, 500));
|
|
17919
|
-
cleanupStaleGlobalInstallDirs(payload.packageName);
|
|
17997
|
+
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
17920
17998
|
appendUpgradeLog("Post-install staging cleanup complete");
|
|
17921
17999
|
}
|
|
17922
18000
|
if (restartArgv.length > 0) {
|
|
@@ -26602,6 +26680,7 @@ export {
|
|
|
26602
26680
|
buildChatMessageSignature,
|
|
26603
26681
|
buildChatTailDeliverySignature,
|
|
26604
26682
|
buildMachineInfo,
|
|
26683
|
+
buildPinnedGlobalInstallCommand,
|
|
26605
26684
|
buildRuntimeSystemChatMessage,
|
|
26606
26685
|
buildSessionEntries,
|
|
26607
26686
|
buildSessionModalDeliverySignature,
|
|
@@ -26684,6 +26763,7 @@ export {
|
|
|
26684
26763
|
resetDebugRuntimeConfig,
|
|
26685
26764
|
resetState,
|
|
26686
26765
|
resolveChatMessageKind,
|
|
26766
|
+
resolveCurrentGlobalInstallSurface,
|
|
26687
26767
|
resolveDebugRuntimeConfig,
|
|
26688
26768
|
resolveSessionHostAppName,
|
|
26689
26769
|
resolveSessionHostAppNameResolution,
|