@adhdev/daemon-core 0.9.82-rc.313 → 0.9.82-rc.314

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.82-rc.313",
3
+ "version": "0.9.82-rc.314",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -46,7 +46,7 @@
46
46
  "author": "vilmire",
47
47
  "license": "AGPL-3.0-or-later",
48
48
  "dependencies": {
49
- "@adhdev/mesh-shared": "0.9.82-rc.313",
49
+ "@adhdev/mesh-shared": "0.9.82-rc.314",
50
50
  "@adhdev/session-host-core": "*",
51
51
  "@agentclientprotocol/sdk": "^0.16.1",
52
52
  "ajv": "^8.20.0",
@@ -321,42 +321,64 @@ function removeDaemonPidFile(): void {
321
321
  }
322
322
  }
323
323
 
324
- function cleanupStaleGlobalInstallDirs(pkgName: string, surface: CurrentGlobalInstallSurface): void {
325
- const prefixArgs = surface.installPrefix ? ['--prefix', surface.installPrefix] : [];
326
- const npmRoot = String(execNpmCommandSync(['root', '-g', ...prefixArgs], { encoding: 'utf8' }, surface)).trim();
327
- if (!npmRoot) return;
328
- const npmPrefix = surface.installPrefix
329
- || String(execNpmCommandSync(['prefix', '-g', ...prefixArgs], { encoding: 'utf8' }, surface)).trim();
330
- const binDir = process.platform === 'win32' ? npmPrefix : path.join(npmPrefix, 'bin');
331
- const packageBaseName = pkgName.startsWith('@') ? pkgName.split('/')[1] : pkgName;
332
- const binNames = new Set<string>([packageBaseName]);
333
- if (pkgName === '@adhdev/daemon-standalone') {
334
- binNames.add('adhdev-standalone');
324
+ /**
325
+ * Best-effort removal of a leftover npm staging entry.
326
+ *
327
+ * A stale staging dir can hold a locked native binary — e.g. `ghostty-vt.dll`
328
+ * from `@adhdev/ghostty-vt-node` still mapped by a lingering session-host
329
+ * process which makes `rmSync` throw `EPERM` on Windows. Staging cleanup is
330
+ * only housekeeping: the leftover is inert and npm creates its own fresh
331
+ * staging dir for the real install, so a lock on an old leftover must NOT abort
332
+ * the upgrade. Log and continue instead of letting the error propagate.
333
+ */
334
+ export function safeRemoveStaleEntry(target: string, label: string): void {
335
+ try {
336
+ fs.rmSync(target, { recursive: true, force: true });
337
+ appendUpgradeLog(`${label}: ${target}`);
338
+ } catch (error: any) {
339
+ appendUpgradeLog(`Skipped locked stale entry (${error?.code || 'error'}): ${target} — ${error?.message || String(error)}`);
335
340
  }
341
+ }
336
342
 
337
- if (pkgName.startsWith('@')) {
338
- const [scope, name] = pkgName.split('/');
339
- const scopeDir = path.join(npmRoot, scope);
340
- if (!fs.existsSync(scopeDir)) return;
341
- for (const entry of fs.readdirSync(scopeDir)) {
342
- if (!entry.startsWith(`.${name}-`)) continue;
343
- fs.rmSync(path.join(scopeDir, entry), { recursive: true, force: true });
344
- appendUpgradeLog(`Removed stale scoped staging dir: ${path.join(scopeDir, entry)}`);
343
+ export function cleanupStaleGlobalInstallDirs(pkgName: string, surface: CurrentGlobalInstallSurface): void {
344
+ // The whole routine is housekeeping — never let it throw out and abort the
345
+ // upgrade (npm root/prefix probing or readdir can fail for unrelated reasons).
346
+ try {
347
+ const prefixArgs = surface.installPrefix ? ['--prefix', surface.installPrefix] : [];
348
+ const npmRoot = String(execNpmCommandSync(['root', '-g', ...prefixArgs], { encoding: 'utf8' }, surface)).trim();
349
+ if (!npmRoot) return;
350
+ const npmPrefix = surface.installPrefix
351
+ || String(execNpmCommandSync(['prefix', '-g', ...prefixArgs], { encoding: 'utf8' }, surface)).trim();
352
+ const binDir = process.platform === 'win32' ? npmPrefix : path.join(npmPrefix, 'bin');
353
+ const packageBaseName = pkgName.startsWith('@') ? pkgName.split('/')[1] : pkgName;
354
+ const binNames = new Set<string>([packageBaseName]);
355
+ if (pkgName === '@adhdev/daemon-standalone') {
356
+ binNames.add('adhdev-standalone');
345
357
  }
346
- } else {
347
- for (const entry of fs.readdirSync(npmRoot)) {
348
- if (!entry.startsWith(`.${pkgName}-`)) continue;
349
- fs.rmSync(path.join(npmRoot, entry), { recursive: true, force: true });
350
- appendUpgradeLog(`Removed stale staging dir: ${path.join(npmRoot, entry)}`);
358
+
359
+ if (pkgName.startsWith('@')) {
360
+ const [scope, name] = pkgName.split('/');
361
+ const scopeDir = path.join(npmRoot, scope);
362
+ if (!fs.existsSync(scopeDir)) return;
363
+ for (const entry of fs.readdirSync(scopeDir)) {
364
+ if (!entry.startsWith(`.${name}-`)) continue;
365
+ safeRemoveStaleEntry(path.join(scopeDir, entry), 'Removed stale scoped staging dir');
366
+ }
367
+ } else {
368
+ for (const entry of fs.readdirSync(npmRoot)) {
369
+ if (!entry.startsWith(`.${pkgName}-`)) continue;
370
+ safeRemoveStaleEntry(path.join(npmRoot, entry), 'Removed stale staging dir');
371
+ }
351
372
  }
352
- }
353
373
 
354
- if (fs.existsSync(binDir)) {
355
- for (const entry of fs.readdirSync(binDir)) {
356
- if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
357
- fs.rmSync(path.join(binDir, entry), { recursive: true, force: true });
358
- appendUpgradeLog(`Removed stale bin staging entry: ${path.join(binDir, entry)}`);
374
+ if (fs.existsSync(binDir)) {
375
+ for (const entry of fs.readdirSync(binDir)) {
376
+ if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
377
+ safeRemoveStaleEntry(path.join(binDir, entry), 'Removed stale bin staging entry');
378
+ }
359
379
  }
380
+ } catch (error: any) {
381
+ appendUpgradeLog(`Stale staging cleanup skipped (${error?.code || 'error'}): ${error?.message || String(error)}`);
360
382
  }
361
383
  }
362
384