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

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.
@@ -40,5 +40,17 @@ export declare function buildPinnedGlobalInstallCommand(options: {
40
40
  export declare function getNpmExecOptions(platform?: NodeJS.Platform): NpmExecOptions;
41
41
  export declare function execNpmCommandSync(args: string[], options?: ExecFileSyncOptions, surface?: Pick<CurrentGlobalInstallSurface, 'npmExecutable' | 'npmArgsPrefix' | 'execOptions'>): Buffer | string;
42
42
  export declare function stopSessionHostProcesses(appName: string): void;
43
+ /**
44
+ * Best-effort removal of a leftover npm staging entry.
45
+ *
46
+ * A stale staging dir can hold a locked native binary — e.g. `ghostty-vt.dll`
47
+ * from `@adhdev/ghostty-vt-node` still mapped by a lingering session-host
48
+ * process — which makes `rmSync` throw `EPERM` on Windows. Staging cleanup is
49
+ * only housekeeping: the leftover is inert and npm creates its own fresh
50
+ * staging dir for the real install, so a lock on an old leftover must NOT abort
51
+ * the upgrade. Log and continue instead of letting the error propagate.
52
+ */
53
+ export declare function safeRemoveStaleEntry(target: string, label: string): void;
54
+ export declare function cleanupStaleGlobalInstallDirs(pkgName: string, surface: CurrentGlobalInstallSurface): void;
43
55
  export declare function spawnDetachedDaemonUpgradeHelper(payload: DaemonUpgradeHelperPayload): void;
44
56
  export declare function maybeRunDaemonUpgradeHelperFromEnv(): Promise<boolean>;
package/dist/index.js CHANGED
@@ -316,10 +316,10 @@ function readInjected(value) {
316
316
  }
317
317
  function getDaemonBuildInfo() {
318
318
  if (cached) return cached;
319
- const commit = readInjected(true ? "ed3b7279be8ea9fa191f854f7e9b6ce969159e67" : void 0) ?? "unknown";
320
- const commitShort = readInjected(true ? "ed3b7279" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
321
- const version = readInjected(true ? "0.9.82-rc.313" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
322
- const builtAt = readInjected(true ? "2026-06-18T00:14:56.582Z" : void 0);
319
+ const commit = readInjected(true ? "e28347641639c9d0a1e46a6141e3cfed2bc90ac2" : void 0) ?? "unknown";
320
+ const commitShort = readInjected(true ? "e2834764" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
321
+ const version = readInjected(true ? "0.9.82-rc.315" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
322
+ const builtAt = readInjected(true ? "2026-06-18T05:47:44.462Z" : void 0);
323
323
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
324
324
  return cached;
325
325
  }
@@ -31399,6 +31399,7 @@ function collectStableSizes(when, sizes) {
31399
31399
  var fs12 = __toESM(require("fs"));
31400
31400
  var os17 = __toESM(require("os"));
31401
31401
  var path21 = __toESM(require("path"));
31402
+ init_logger();
31402
31403
  var UUID_RE = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i;
31403
31404
  function executeNativeHistory(cfg, input) {
31404
31405
  if (!cfg?.source) return null;
@@ -31431,8 +31432,33 @@ function executeJsonl(src, input) {
31431
31432
  if (!sourcePath && hasDateTemplateSegment(src.path)) {
31432
31433
  sourcePath = pickExactSessionFileAcrossDateWindow(src.path, input, filePat, requestedSessionId) || (requestedSessionId ? null : pickSessionBoundFileAcrossDateWindow(src.path, input, filePat, windowMs, sessionFloor, workspaceHint)) || (requestedSessionId ? null : newestRecentFileAcrossDateWindow(src.path, input, filePat, windowMs, sessionFloor));
31433
31434
  }
31435
+ if (!sourcePath && !hasDateTemplateSegment(src.path)) {
31436
+ const resolvedRaw = expandPath2(src.path, input, { skipWorkspaceRealpath: true });
31437
+ if (resolvedRaw && resolvedRaw !== resolved) {
31438
+ try {
31439
+ const rawStat = fs12.statSync(resolvedRaw);
31440
+ if (rawStat.isFile()) sourcePath = resolvedRaw;
31441
+ else if (rawStat.isDirectory()) {
31442
+ sourcePath = pickExactSessionFile(resolvedRaw, filePat, requestedSessionId) || (requestedSessionId ? null : newestRecentFile(resolvedRaw, filePat, windowMs, sessionFloor));
31443
+ }
31444
+ } catch {
31445
+ }
31446
+ }
31447
+ }
31448
+ if (!sourcePath && requestedSessionId) {
31449
+ sourcePath = scanProjectsRootForSessionFile(src.path, input, requestedSessionId);
31450
+ }
31451
+ }
31452
+ if (!sourcePath) {
31453
+ const wsRaw = typeof input.workspace === "string" ? input.workspace : "";
31454
+ let wsReal = wsRaw;
31455
+ try {
31456
+ if (wsRaw) wsReal = fs12.realpathSync(wsRaw);
31457
+ } catch {
31458
+ }
31459
+ LOG.debug("NativeHistory", `jsonl unresolved: tried=${JSON.stringify(resolved)} sessionId=${requestedSessionId || "(none)"} wsRaw=${JSON.stringify(wsRaw)} wsReal=${JSON.stringify(wsReal)} rawSlug=${JSON.stringify(claudeProjectDirName(wsRaw))} realSlug=${JSON.stringify(claudeProjectDirName(wsReal))} (concrete miss + raw-slug retry + projects scan all failed)`);
31460
+ return null;
31434
31461
  }
31435
- if (!sourcePath) return null;
31436
31462
  const mtime = safeMtimeMs(sourcePath);
31437
31463
  const lines = readJsonlLines(sourcePath);
31438
31464
  if (lines.length === 0) return null;
@@ -31551,7 +31577,7 @@ function executeSqlite(src, input) {
31551
31577
  }
31552
31578
  }
31553
31579
  }
31554
- function expandPath2(template, input) {
31580
+ function expandPath2(template, input, opts) {
31555
31581
  if (!template) return null;
31556
31582
  let out = template;
31557
31583
  if (out.startsWith("~/") || out === "~") {
@@ -31565,7 +31591,7 @@ function expandPath2(template, input) {
31565
31591
  const now = /* @__PURE__ */ new Date();
31566
31592
  const workspaceRaw = input.workspace ?? "";
31567
31593
  let workspaceResolved = workspaceRaw;
31568
- if (workspaceRaw) {
31594
+ if (workspaceRaw && !opts?.skipWorkspaceRealpath) {
31569
31595
  try {
31570
31596
  workspaceResolved = fs12.realpathSync(workspaceRaw);
31571
31597
  } catch {
@@ -31592,6 +31618,50 @@ function expandPath2(template, input) {
31592
31618
  function claudeProjectDirName(workspace) {
31593
31619
  return workspace.replace(/[^A-Za-z0-9_-]/g, "-");
31594
31620
  }
31621
+ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
31622
+ if (!requestedSessionId) return null;
31623
+ let head = template;
31624
+ if (head.startsWith("~/") || head === "~") head = path21.join(os17.homedir(), head.slice(2));
31625
+ const segs = head.split("/");
31626
+ const baseParts = [];
31627
+ for (const seg of segs) {
31628
+ if (/[{}*?]/.test(seg)) break;
31629
+ baseParts.push(seg);
31630
+ }
31631
+ const base = baseParts.join("/");
31632
+ if (!base) return null;
31633
+ let baseStat = null;
31634
+ try {
31635
+ baseStat = fs12.statSync(base);
31636
+ } catch {
31637
+ return null;
31638
+ }
31639
+ if (!baseStat.isDirectory()) return null;
31640
+ const needle = `${requestedSessionId.toLowerCase()}.jsonl`;
31641
+ const dirsToScan = [base];
31642
+ try {
31643
+ for (const entry of fs12.readdirSync(base, { withFileTypes: true })) {
31644
+ if (entry.isDirectory()) dirsToScan.push(path21.join(base, entry.name));
31645
+ }
31646
+ } catch {
31647
+ }
31648
+ for (const dir of dirsToScan) {
31649
+ let entries;
31650
+ try {
31651
+ entries = fs12.readdirSync(dir, { withFileTypes: true });
31652
+ } catch {
31653
+ continue;
31654
+ }
31655
+ for (const entry of entries) {
31656
+ if (!entry.isFile()) continue;
31657
+ if (entry.name.toLowerCase() !== needle) continue;
31658
+ const found = path21.join(dir, entry.name);
31659
+ LOG.debug("NativeHistory", `jsonl scan-fallback hit: sessionId=${requestedSessionId} resolved via projects-root scan \u2192 ${JSON.stringify(found)} (slug-derived path missed; likely realpath/slug divergence)`);
31660
+ return found;
31661
+ }
31662
+ }
31663
+ return null;
31664
+ }
31595
31665
  function globToRegex(pattern) {
31596
31666
  const re = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]");
31597
31667
  return new RegExp(`^${re}$`);
@@ -42167,39 +42237,48 @@ function removeDaemonPidFile() {
42167
42237
  } catch {
42168
42238
  }
42169
42239
  }
42240
+ function safeRemoveStaleEntry(target, label) {
42241
+ try {
42242
+ fs24.rmSync(target, { recursive: true, force: true });
42243
+ appendUpgradeLog(`${label}: ${target}`);
42244
+ } catch (error) {
42245
+ appendUpgradeLog(`Skipped locked stale entry (${error?.code || "error"}): ${target} \u2014 ${error?.message || String(error)}`);
42246
+ }
42247
+ }
42170
42248
  function cleanupStaleGlobalInstallDirs(pkgName, surface) {
42171
- const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
42172
- const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
42173
- if (!npmRoot) return;
42174
- const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
42175
- const binDir = process.platform === "win32" ? npmPrefix : path35.join(npmPrefix, "bin");
42176
- const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
42177
- const binNames = /* @__PURE__ */ new Set([packageBaseName]);
42178
- if (pkgName === "@adhdev/daemon-standalone") {
42179
- binNames.add("adhdev-standalone");
42180
- }
42181
- if (pkgName.startsWith("@")) {
42182
- const [scope, name] = pkgName.split("/");
42183
- const scopeDir = path35.join(npmRoot, scope);
42184
- if (!fs24.existsSync(scopeDir)) return;
42185
- for (const entry of fs24.readdirSync(scopeDir)) {
42186
- if (!entry.startsWith(`.${name}-`)) continue;
42187
- fs24.rmSync(path35.join(scopeDir, entry), { recursive: true, force: true });
42188
- appendUpgradeLog(`Removed stale scoped staging dir: ${path35.join(scopeDir, entry)}`);
42189
- }
42190
- } else {
42191
- for (const entry of fs24.readdirSync(npmRoot)) {
42192
- if (!entry.startsWith(`.${pkgName}-`)) continue;
42193
- fs24.rmSync(path35.join(npmRoot, entry), { recursive: true, force: true });
42194
- appendUpgradeLog(`Removed stale staging dir: ${path35.join(npmRoot, entry)}`);
42249
+ try {
42250
+ const prefixArgs = surface.installPrefix ? ["--prefix", surface.installPrefix] : [];
42251
+ const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
42252
+ if (!npmRoot) return;
42253
+ const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
42254
+ const binDir = process.platform === "win32" ? npmPrefix : path35.join(npmPrefix, "bin");
42255
+ const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
42256
+ const binNames = /* @__PURE__ */ new Set([packageBaseName]);
42257
+ if (pkgName === "@adhdev/daemon-standalone") {
42258
+ binNames.add("adhdev-standalone");
42259
+ }
42260
+ if (pkgName.startsWith("@")) {
42261
+ const [scope, name] = pkgName.split("/");
42262
+ const scopeDir = path35.join(npmRoot, scope);
42263
+ if (!fs24.existsSync(scopeDir)) return;
42264
+ for (const entry of fs24.readdirSync(scopeDir)) {
42265
+ if (!entry.startsWith(`.${name}-`)) continue;
42266
+ safeRemoveStaleEntry(path35.join(scopeDir, entry), "Removed stale scoped staging dir");
42267
+ }
42268
+ } else {
42269
+ for (const entry of fs24.readdirSync(npmRoot)) {
42270
+ if (!entry.startsWith(`.${pkgName}-`)) continue;
42271
+ safeRemoveStaleEntry(path35.join(npmRoot, entry), "Removed stale staging dir");
42272
+ }
42195
42273
  }
42196
- }
42197
- if (fs24.existsSync(binDir)) {
42198
- for (const entry of fs24.readdirSync(binDir)) {
42199
- if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
42200
- fs24.rmSync(path35.join(binDir, entry), { recursive: true, force: true });
42201
- appendUpgradeLog(`Removed stale bin staging entry: ${path35.join(binDir, entry)}`);
42274
+ if (fs24.existsSync(binDir)) {
42275
+ for (const entry of fs24.readdirSync(binDir)) {
42276
+ if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
42277
+ safeRemoveStaleEntry(path35.join(binDir, entry), "Removed stale bin staging entry");
42278
+ }
42202
42279
  }
42280
+ } catch (error) {
42281
+ appendUpgradeLog(`Stale staging cleanup skipped (${error?.code || "error"}): ${error?.message || String(error)}`);
42203
42282
  }
42204
42283
  }
42205
42284
  function spawnDetachedDaemonUpgradeHelper(payload) {