@rigxyz/tapd 0.6.2 → 0.6.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.
@@ -1930,6 +1930,7 @@ import { join as join10 } from "path";
1930
1930
  import chokidar from "chokidar";
1931
1931
 
1932
1932
  // src/claude-code.ts
1933
+ import { spawnSync } from "child_process";
1933
1934
  import { existsSync as existsSync6, readdirSync as readdirSync4, readFileSync as readFileSync9, statSync as statSync3 } from "fs";
1934
1935
  import { homedir } from "os";
1935
1936
  import { join as join9, relative as relative3, sep as sep3 } from "path";
@@ -1990,6 +1991,10 @@ function toRigRelative(absPath, rootDir) {
1990
1991
  }
1991
1992
  return sep3 === "/" ? rel : rel.replaceAll(sep3, "/");
1992
1993
  }
1994
+ function isWithin2(absPath, base) {
1995
+ const rel = relative3(base, absPath);
1996
+ return rel === "" || !(rel.startsWith("..") || sep3 !== "/" && rel.includes(".." + sep3));
1997
+ }
1993
1998
  var PROMPT_SNIPPET_MAX = 2e3;
1994
1999
  function num(v) {
1995
2000
  return typeof v === "number" && Number.isFinite(v) ? v : 0;
@@ -2025,6 +2030,9 @@ function parseSessions(transcriptPath, rootDir, opts = {}) {
2025
2030
  } catch {
2026
2031
  continue;
2027
2032
  }
2033
+ if (opts.expectedCwd && typeof line.cwd === "string" && line.cwd) {
2034
+ if (!isWithin2(line.cwd, opts.expectedCwd)) return [];
2035
+ }
2028
2036
  const type = line.type;
2029
2037
  if (type === "ai-title" && typeof line.aiTitle === "string") {
2030
2038
  aiTitle = line.aiTitle.trim() || aiTitle;
@@ -2088,8 +2096,29 @@ function parseSessions(transcriptPath, rootDir, opts = {}) {
2088
2096
  }));
2089
2097
  }
2090
2098
  var parseCache = /* @__PURE__ */ new Map();
2091
- function listSessions(rootDir, opts = {}) {
2092
- const dir = join9(opts.projectsRoot ?? defaultClaudeProjectsRoot(), claudeProjectDirName(rootDir));
2099
+ var WORKTREE_TTL_MS = 3e4;
2100
+ var worktreeCache = /* @__PURE__ */ new Map();
2101
+ function gitWorktrees(rootDir) {
2102
+ const now = Date.now();
2103
+ const cached = worktreeCache.get(rootDir);
2104
+ if (cached && now - cached.at < WORKTREE_TTL_MS) return cached.paths;
2105
+ let paths = [];
2106
+ try {
2107
+ const res = spawnSync("git", ["worktree", "list", "--porcelain"], {
2108
+ cwd: rootDir,
2109
+ encoding: "utf8",
2110
+ timeout: 2e3,
2111
+ windowsHide: true
2112
+ });
2113
+ if (res.status === 0 && typeof res.stdout === "string") {
2114
+ paths = res.stdout.split("\n").filter((l) => l.startsWith("worktree ")).map((l) => l.slice("worktree ".length).trim()).filter((p) => p !== "" && p !== rootDir);
2115
+ }
2116
+ } catch {
2117
+ }
2118
+ worktreeCache.set(rootDir, { at: now, paths });
2119
+ return paths;
2120
+ }
2121
+ function sessionsInDir(dir, base) {
2093
2122
  if (!existsSync6(dir)) return [];
2094
2123
  let files;
2095
2124
  try {
@@ -2111,10 +2140,22 @@ function listSessions(rootDir, opts = {}) {
2111
2140
  out.push(...cached.bouts);
2112
2141
  continue;
2113
2142
  }
2114
- const bouts = parseSessions(abs, rootDir);
2143
+ const bouts = parseSessions(abs, base, { expectedCwd: base });
2115
2144
  parseCache.set(abs, { mtimeMs: st.mtimeMs, size: st.size, bouts });
2116
2145
  out.push(...bouts);
2117
2146
  }
2147
+ return out;
2148
+ }
2149
+ function listSessions(rootDir, opts = {}) {
2150
+ const projectsRoot = opts.projectsRoot ?? defaultClaudeProjectsRoot();
2151
+ const out = [];
2152
+ const seen = /* @__PURE__ */ new Set();
2153
+ for (const base of [rootDir, ...gitWorktrees(rootDir)]) {
2154
+ const dir = join9(projectsRoot, claudeProjectDirName(base));
2155
+ if (seen.has(dir)) continue;
2156
+ seen.add(dir);
2157
+ out.push(...sessionsInDir(dir, base));
2158
+ }
2118
2159
  out.sort((a, b) => (a.lastTs ?? "").localeCompare(b.lastTs ?? ""));
2119
2160
  return out;
2120
2161
  }
@@ -2454,4 +2495,4 @@ export {
2454
2495
  scanAndPush,
2455
2496
  start
2456
2497
  };
2457
- //# sourceMappingURL=chunk-RKOWUM3D.js.map
2498
+ //# sourceMappingURL=chunk-54AIKODH.js.map