@schoolai/shipyard 3.11.0 → 3.11.1

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.
Files changed (60) hide show
  1. package/dist/{auth-GGM253LQ.js → auth-AUY74PMB.js} +3 -3
  2. package/dist/capability-detector-worker.js +8 -8
  3. package/dist/{chunk-R3XQ6W7L.js → chunk-4SYLDZTY.js} +4 -4
  4. package/dist/{chunk-C6QOTETH.js → chunk-5LWD5W7O.js} +24 -10
  5. package/dist/chunk-5LWD5W7O.js.map +1 -0
  6. package/dist/{chunk-IJHF4OM4.js → chunk-5W5N5U2S.js} +2 -2
  7. package/dist/{chunk-L7ELOV3S.js → chunk-FVZ5BDZS.js} +4 -4
  8. package/dist/chunk-FVZ5BDZS.js.map +1 -0
  9. package/dist/{chunk-RW2OTTUA.js → chunk-KYLYGFMH.js} +4 -4
  10. package/dist/{chunk-QJP7JCIS.js → chunk-LRNGLC4V.js} +41 -3
  11. package/dist/chunk-LRNGLC4V.js.map +1 -0
  12. package/dist/{chunk-A2UK6TW2.js → chunk-LZSMNUAI.js} +18 -1
  13. package/dist/{chunk-A2UK6TW2.js.map → chunk-LZSMNUAI.js.map} +1 -1
  14. package/dist/{chunk-Z37T5W6S.js → chunk-P2HZDIN7.js} +12 -7
  15. package/dist/chunk-P2HZDIN7.js.map +1 -0
  16. package/dist/{chunk-ZRJTZLRF.js → chunk-QKJNVVQ3.js} +4 -4
  17. package/dist/{chunk-2EQOL57Z.js → chunk-TFRYQDDG.js} +2 -2
  18. package/dist/{chunk-YXPPZQBJ.js → chunk-VL5RUCRF.js} +164 -37
  19. package/dist/chunk-VL5RUCRF.js.map +1 -0
  20. package/dist/{chunk-3WEEGJJN.js → chunk-X5KCX6ZS.js} +2 -2
  21. package/dist/{chunk-GM6MH4CD.js → chunk-XIEOWUPV.js} +2 -2
  22. package/dist/{chunk-6LINHACK.js → chunk-Y5UWRARP.js} +47 -24
  23. package/dist/chunk-Y5UWRARP.js.map +1 -0
  24. package/dist/cursor-runner.js +88 -62
  25. package/dist/cursor-runner.js.map +1 -1
  26. package/dist/electron-utility.js +5 -5
  27. package/dist/{git-repo-QNGPCJLI.js → git-repo-CTZJS3ER.js} +6 -4
  28. package/dist/index.js +8 -8
  29. package/dist/{logger-2F3CBS3V.js → logger-AN7EUK2B.js} +7 -5
  30. package/dist/{login-U256OVOJ.js → login-YB34LF4L.js} +6 -6
  31. package/dist/{logout-HY3MPOY5.js → logout-GUXVSWLZ.js} +5 -5
  32. package/dist/{mcp-servers-ICHOWXZB.js → mcp-servers-OAPQNDA7.js} +4 -4
  33. package/dist/{roi-YM5OOWHG.js → roi-NXJHL5X2.js} +3 -3
  34. package/dist/{serve-D5GKV2RU.js → serve-P3U2C5YH.js} +1175 -739
  35. package/dist/{serve-D5GKV2RU.js.map → serve-P3U2C5YH.js.map} +1 -1
  36. package/dist/{skills-W2Y6TWHA.js → skills-2UBVHFQ5.js} +2 -2
  37. package/dist/{start-JY26XC5R.js → start-Y34X3WVF.js} +10 -10
  38. package/package.json +1 -1
  39. package/dist/chunk-6LINHACK.js.map +0 -1
  40. package/dist/chunk-C6QOTETH.js.map +0 -1
  41. package/dist/chunk-L7ELOV3S.js.map +0 -1
  42. package/dist/chunk-QJP7JCIS.js.map +0 -1
  43. package/dist/chunk-YXPPZQBJ.js.map +0 -1
  44. package/dist/chunk-Z37T5W6S.js.map +0 -1
  45. /package/dist/{auth-GGM253LQ.js.map → auth-AUY74PMB.js.map} +0 -0
  46. /package/dist/{chunk-R3XQ6W7L.js.map → chunk-4SYLDZTY.js.map} +0 -0
  47. /package/dist/{chunk-IJHF4OM4.js.map → chunk-5W5N5U2S.js.map} +0 -0
  48. /package/dist/{chunk-RW2OTTUA.js.map → chunk-KYLYGFMH.js.map} +0 -0
  49. /package/dist/{chunk-ZRJTZLRF.js.map → chunk-QKJNVVQ3.js.map} +0 -0
  50. /package/dist/{chunk-2EQOL57Z.js.map → chunk-TFRYQDDG.js.map} +0 -0
  51. /package/dist/{chunk-3WEEGJJN.js.map → chunk-X5KCX6ZS.js.map} +0 -0
  52. /package/dist/{chunk-GM6MH4CD.js.map → chunk-XIEOWUPV.js.map} +0 -0
  53. /package/dist/{git-repo-QNGPCJLI.js.map → git-repo-CTZJS3ER.js.map} +0 -0
  54. /package/dist/{logger-2F3CBS3V.js.map → logger-AN7EUK2B.js.map} +0 -0
  55. /package/dist/{login-U256OVOJ.js.map → login-YB34LF4L.js.map} +0 -0
  56. /package/dist/{logout-HY3MPOY5.js.map → logout-GUXVSWLZ.js.map} +0 -0
  57. /package/dist/{mcp-servers-ICHOWXZB.js.map → mcp-servers-OAPQNDA7.js.map} +0 -0
  58. /package/dist/{roi-YM5OOWHG.js.map → roi-NXJHL5X2.js.map} +0 -0
  59. /package/dist/{skills-W2Y6TWHA.js.map → skills-2UBVHFQ5.js.map} +0 -0
  60. /package/dist/{start-JY26XC5R.js.map → start-Y34X3WVF.js.map} +0 -0
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  _resolveBucketForTesting,
4
4
  detectSkills
5
- } from "./chunk-2EQOL57Z.js";
5
+ } from "./chunk-TFRYQDDG.js";
6
6
  import "./chunk-2H7UOFLK.js";
7
7
  export {
8
8
  _resolveBucketForTesting,
9
9
  detectSkills
10
10
  };
11
- //# sourceMappingURL=skills-W2Y6TWHA.js.map
11
+ //# sourceMappingURL=skills-2UBVHFQ5.js.map
@@ -3,20 +3,20 @@ import {
3
3
  createMetricsCollector,
4
4
  decideAction,
5
5
  makeInitialAttemptState
6
- } from "./chunk-L7ELOV3S.js";
6
+ } from "./chunk-FVZ5BDZS.js";
7
7
  import {
8
8
  ensureAuthenticated,
9
9
  getSignalingUrl
10
- } from "./chunk-R3XQ6W7L.js";
10
+ } from "./chunk-4SYLDZTY.js";
11
11
  import {
12
12
  print
13
- } from "./chunk-IJHF4OM4.js";
13
+ } from "./chunk-5W5N5U2S.js";
14
14
  import {
15
15
  loadAuthToken
16
- } from "./chunk-3WEEGJJN.js";
17
- import "./chunk-ZRJTZLRF.js";
16
+ } from "./chunk-X5KCX6ZS.js";
17
+ import "./chunk-QKJNVVQ3.js";
18
18
  import "./chunk-NACJENDW.js";
19
- import "./chunk-GM6MH4CD.js";
19
+ import "./chunk-XIEOWUPV.js";
20
20
  import "./chunk-ZFKJAYAN.js";
21
21
  import "./chunk-RMLQ5DRP.js";
22
22
  import "./chunk-EHQITHQX.js";
@@ -25,10 +25,10 @@ import {
25
25
  } from "./chunk-X3MULCV5.js";
26
26
  import {
27
27
  logger
28
- } from "./chunk-QJP7JCIS.js";
28
+ } from "./chunk-LRNGLC4V.js";
29
29
  import {
30
30
  validateEnv
31
- } from "./chunk-Z37T5W6S.js";
31
+ } from "./chunk-P2HZDIN7.js";
32
32
  import "./chunk-CNR7O5YH.js";
33
33
  import "./chunk-2H7UOFLK.js";
34
34
 
@@ -409,7 +409,7 @@ async function runDaemonChild() {
409
409
  env.SHIPYARD_USER_ID = authResult.userId;
410
410
  env.SHIPYARD_USER_DISPLAY_NAME = authResult.displayName;
411
411
  env.SHIPYARD_SIGNALING_URL = authResult.signalingUrl;
412
- const { serve } = await import("./serve-D5GKV2RU.js");
412
+ const { serve } = await import("./serve-P3U2C5YH.js");
413
413
  return serve({ isDev: env.SHIPYARD_DEV, autoOpenBrowser: !authResult.deviceFlowRan });
414
414
  }
415
415
  async function runSupervisor() {
@@ -491,4 +491,4 @@ async function createSupervisorMetrics(env) {
491
491
  export {
492
492
  startCommand
493
493
  };
494
- //# sourceMappingURL=start-JY26XC5R.js.map
494
+ //# sourceMappingURL=start-Y34X3WVF.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schoolai/shipyard",
3
- "version": "3.11.0",
3
+ "version": "3.11.1",
4
4
  "description": "Shipyard daemon - Claude Agent SDK + Loro CRDT sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/shared/capabilities/git-repo.ts","../src/shared/capabilities/environments-cache.ts","../src/shared/capabilities/repo-paths-cache.ts","../src/shared/capabilities/shell.ts"],"sourcesContent":["import { readdir, readFile } from 'node:fs/promises';\nimport { basename, join } from 'node:path';\nimport type { GitRepoInfo } from '@shipyard/session';\nimport { logger } from '../logger.js';\nimport {\n type CacheEntry,\n type GitCacheFingerprint,\n getGitCacheFingerprint,\n isCacheValid,\n loadCache,\n resolveHeadPath,\n saveCache,\n} from './environments-cache.js';\nimport { gitExecSafe } from './git-pool.js';\nimport { getCachedRepoPaths, setCachedRepoPaths } from './repo-paths-cache.js';\nimport { run, runWithTimeout, TIMEOUT_MS } from './shell.js';\n\n/**\n * Per-path hard timeout for the environments walk. Lowered from\n * `TIMEOUT_MS` (5s) so a single hung path (NFS stall, symlink loop,\n * dead network drive — the May 2026 detect_environments wedge scenario)\n * can't pin the whole detector for tens of seconds. The walk continues\n * past timed-out paths; the per-path slow log surfaces the culprit on\n * the next investigation.\n */\nconst GIT_PROBE_TIMEOUT_MS = 3_000;\n\n/** Single-path duration past which we emit a slow-log event for diagnosis. */\nconst SLOW_PATH_LOG_THRESHOLD_MS = 2_000;\n\n/**\n * Race `op` against a `timeoutMs` deadline. On timeout, resolves to `null`\n * — the walker treats this the same as a git-call failure (skip the path\n * but continue the walk). Used so a single hung NFS path can't pin the\n * whole environments walk.\n */\nasync function withProbeTimeout<T>(op: Promise<T>, timeoutMs: number): Promise<T | null> {\n return new Promise<T | null>((resolve) => {\n const timer = setTimeout(() => resolve(null), timeoutMs);\n timer.unref?.();\n op.then(\n (v) => {\n clearTimeout(timer);\n resolve(v);\n },\n () => {\n clearTimeout(timer);\n resolve(null);\n }\n );\n });\n}\n\n/**\n * Negative cache TTL for `isGitRepo`. A directory that is not yet a git\n * repo may become one (`git init`) during the daemon lifetime; positives\n * are permanent (a work-tree never stops being one) but negatives must\n * expire so we re-probe periodically.\n */\nexport const NEGATIVE_CACHE_TTL_MS = 5_000;\n\ntype GitRepoCacheEntry = { isRepo: boolean; expiresAt?: number };\n\n/** Cache of directory paths to whether they are inside a git repository. */\nexport const gitRepoCache = new Map<string, GitRepoCacheEntry>();\n\nfunction readGitRepoCache(cwd: string, now = Date.now()): boolean | undefined {\n const cached = gitRepoCache.get(cwd);\n if (cached === undefined) return undefined;\n if (cached.isRepo) return true;\n if (cached.expiresAt !== undefined && now >= cached.expiresAt) {\n gitRepoCache.delete(cwd);\n return undefined;\n }\n return false;\n}\n\n/**\n * Check whether the given directory is inside a git work-tree.\n * Results are cached per directory so repeated calls (e.g. during\n * debounced diff captures) do not re-spawn git processes.\n */\nexport async function isGitRepo(cwd: string): Promise<boolean> {\n const cached = readGitRepoCache(cwd);\n if (cached !== undefined) return cached;\n try {\n await runWithTimeout('git', ['rev-parse', '--git-dir'], cwd, TIMEOUT_MS);\n gitRepoCache.set(cwd, { isRepo: true });\n return true;\n } catch {\n gitRepoCache.set(cwd, {\n isRepo: false,\n expiresAt: Date.now() + NEGATIVE_CACHE_TTL_MS,\n });\n return false;\n }\n}\n\nlet ghAvailableCache = false;\n\nexport async function isGhAvailable(): Promise<boolean> {\n if (ghAvailableCache) return true;\n try {\n await run('which', ['gh']);\n ghAvailableCache = true;\n return true;\n } catch {\n return false;\n }\n}\n\nconst topLevelCache = new Map<string, string>();\n\nexport async function getGitTopLevel(cwd: string): Promise<string> {\n const cached = topLevelCache.get(cwd);\n if (cached !== undefined) return cached;\n const topLevel = (\n await runWithTimeout('git', ['rev-parse', '--show-toplevel'], cwd, TIMEOUT_MS)\n ).trim();\n topLevelCache.set(cwd, topLevel);\n return topLevel;\n}\n\nexport function parseOwnerRepo(remoteUrl: string): { owner: string; repo: string } | null {\n const match = remoteUrl.match(/github\\.com[:/]([^/]+)\\/([^/.]+)/);\n if (!match?.[1] || !match[2]) return null;\n return { owner: match[1], repo: match[2] };\n}\n\n/**\n * Look up the repo's default branch via the `origin/HEAD` symbolic ref.\n * Returns the branch name (e.g. `main`) or null when the symbolic ref\n * isn't set (rare — happens for repos cloned without `git remote\n * set-head` or local-only repos).\n *\n * The result is cached for 5 seconds via the per-cwd OneShotPool in\n * git-pool.ts so repeated calls from serve-factory and stack-detection\n * per request coalesce to a single subprocess.\n */\nexport async function getRepoDefaultBranch(cwd: string): Promise<string | null> {\n const head = await gitExecSafe(cwd, ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']);\n if (!head) return null;\n return head.replace(/^origin\\//, '') || null;\n}\n\nexport async function isAncestor(\n ancestor: string,\n descendant: string,\n cwd: string\n): Promise<boolean> {\n try {\n await runWithTimeout('git', ['merge-base', '--is-ancestor', ancestor, descendant], cwd, 5_000);\n return true;\n } catch {\n return false;\n }\n}\n\nconst EXCLUDE_DIRS = new Set([\n 'node_modules',\n 'Library',\n 'Applications',\n 'Pictures',\n 'Music',\n 'Movies',\n 'go',\n '.Trash',\n]);\n\nconst MAX_DEPTH = 4;\nconst WORKTREE_DISCOVERY_CONCURRENCY = 8;\nconst REPO_METADATA_CONCURRENCY = 16;\n\nasync function mapLimit<T, R>(\n items: readonly T[],\n limit: number,\n mapper: (item: T, index: number) => Promise<R>\n): Promise<R[]> {\n const results = new Array<R>(items.length);\n const indexedItems = items.map((item, index) => ({ item, index }));\n let nextIndex = 0;\n const workerCount = Math.min(Math.max(1, limit), items.length);\n\n await Promise.all(\n Array.from({ length: workerCount }, async () => {\n for (;;) {\n const next = indexedItems[nextIndex];\n nextIndex += 1;\n if (!next) return;\n results[next.index] = await mapper(next.item, next.index);\n }\n })\n );\n\n return results;\n}\n\nexport async function findGitRepos(dir: string, depth = 0): Promise<string[]> {\n if (depth > MAX_DEPTH) return [];\n\n try {\n const entries = await readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n if (entry.name === '.git') {\n return [dir];\n }\n }\n\n if (depth >= MAX_DEPTH) return [];\n\n const promises: Promise<string[]>[] = [];\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n if (entry.name.startsWith('.')) continue;\n if (EXCLUDE_DIRS.has(entry.name)) continue;\n promises.push(findGitRepos(join(dir, entry.name), depth + 1));\n }\n\n const results = await Promise.all(promises);\n return results.flat();\n } catch {\n return [];\n }\n}\n\n/**\n * Read the current branch name by parsing `.git/HEAD` directly.\n *\n * Format of `.git/HEAD`:\n * - Checked-out branch: `ref: refs/heads/<branch>\\n`\n * - Detached HEAD: `<sha>\\n`\n *\n * First attempts to read `.git/HEAD` directly (fast path for normal repos).\n * Falls back to `resolveHeadPath` for linked worktrees where `.git` is a\n * file pointing to a gitdir rather than a directory.\n */\nasync function readBranchFromHead(repoPath: string): Promise<string> {\n const directHeadPath = join(repoPath, '.git', 'HEAD');\n try {\n const direct = await readFile(directHeadPath, 'utf8');\n const trimmed = direct.trim();\n if (trimmed.startsWith('ref: refs/heads/')) {\n return trimmed.slice('ref: refs/heads/'.length);\n }\n if (!trimmed.startsWith('gitdir:')) {\n return 'HEAD';\n }\n } catch {}\n\n try {\n const headPath = await resolveHeadPath(repoPath);\n if (!headPath) return 'HEAD';\n const contents = await readFile(headPath, 'utf8');\n const trimmed2 = contents.trim();\n if (trimmed2.startsWith('ref: refs/heads/')) {\n return trimmed2.slice('ref: refs/heads/'.length);\n }\n return 'HEAD';\n } catch {\n return 'HEAD';\n }\n}\n\nexport async function getRepoMetadata(\n repoPath: string,\n cached?: CacheEntry\n): Promise<GitRepoInfo | null> {\n try {\n if (cached) {\n return {\n path: repoPath,\n name: basename(repoPath),\n branch: cached.branch,\n ...(cached.remote !== null && { remote: cached.remote }),\n };\n }\n\n /**\n * Both reads are bounded by `GIT_PROBE_TIMEOUT_MS`. `gitExecSafe`\n * already has the 5s `OneShotPool` TTL but no hard kill — a hung\n * `git remote get-url` would pin the walker indefinitely without\n * this race. `readBranchFromHead` is plain `fs.readFile` and is\n * usually fast, but the timeout is cheap insurance against an NFS\n * stall on the HEAD file itself.\n */\n const [branchResult, remoteResult] = await Promise.all([\n withProbeTimeout(readBranchFromHead(repoPath), GIT_PROBE_TIMEOUT_MS),\n withProbeTimeout(\n gitExecSafe(repoPath, ['remote', 'get-url', 'origin']),\n GIT_PROBE_TIMEOUT_MS\n ),\n ]);\n const branch = branchResult ?? 'HEAD';\n const remote = remoteResult ? remoteResult || undefined : undefined;\n\n return {\n path: repoPath,\n name: basename(repoPath),\n branch,\n ...(remote && { remote }),\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Process a single repo path during the environments walk: resolve cache hit,\n * run the timed metadata probe, update `nextCache`, and emit slow/timeout logs.\n * Extracted from the `mapLimit` callback in `detectEnvironments` to keep that\n * function under the cognitive-complexity ceiling.\n */\nasync function processRepoPaths(\n path: string,\n idx: number,\n fingerprints: GitCacheFingerprint[],\n prevCache: Map<string, CacheEntry>,\n nextCache: Map<string, CacheEntry>\n): Promise<GitRepoInfo | null> {\n const currentFingerprint = fingerprints[idx] ?? { headMtimeMs: null, configMtimeMs: null };\n const prev = prevCache.get(path);\n const cacheHit =\n prev !== undefined &&\n currentFingerprint.headMtimeMs !== null &&\n isCacheValid(prev, currentFingerprint);\n\n const start = Date.now();\n const info = await withProbeTimeout(\n getRepoMetadata(path, cacheHit ? prev : undefined),\n GIT_PROBE_TIMEOUT_MS\n );\n const durationMs = Date.now() - start;\n\n if (info === null && durationMs >= GIT_PROBE_TIMEOUT_MS * 0.9) {\n logger.warn(\n { event: 'environments_walk_path_timed_out', path, durationMs },\n 'environments walk skipped path past per-path timeout'\n );\n } else if (durationMs >= SLOW_PATH_LOG_THRESHOLD_MS) {\n logger.warn(\n { event: 'environments_walk_path_slow', path, durationMs },\n 'environments walk path resolved slowly'\n );\n }\n\n if (info !== null && currentFingerprint.headMtimeMs !== null) {\n nextCache.set(path, {\n path,\n branch: info.branch,\n remote: info.remote ?? null,\n headMtimeMs: currentFingerprint.headMtimeMs,\n configMtimeMs: currentFingerprint.configMtimeMs,\n cachedAt: cacheHit && prev ? prev.cachedAt : Date.now(),\n });\n }\n return info;\n}\n\n/**\n * Detect git environments under $HOME.\n *\n * `lastKnown` preserves the previously-detected environment list when the\n * underlying `findGitRepos` walk returns `[]` for a non-authoritative reason\n * (root readdir failure: EMFILE, EACCES, EBUSY). Without this, a transient\n * filesystem hiccup in the 30s capability-refresh tick collapses environments\n * to `[]`, which `applyFreshCapabilities` writes wholesale, and the browser\n * briefly renders \"No environment\" until the next successful tick. Mirror of\n * the `lastKnownAgents` pattern in `agents.ts`.\n *\n * Discrimination: a successful walk that genuinely finds zero repos is\n * indistinguishable from a swallowed-error walk in the current shape (the\n * inner `try/catch` in `findGitRepos` returns `[]` on readdir failure). The\n * `lastKnown.length > 0` guard means we only preserve when there's something\n * worth preserving; a clean machine that genuinely has zero repos still gets\n * `[]`.\n */\nexport async function detectEnvironments(lastKnown?: GitRepoInfo[]): Promise<GitRepoInfo[]> {\n const { homedir } = await import('node:os');\n\n /**\n * The repo-paths cache (`repo-paths-cache.ts`) holds the result of the\n * `findGitRepos(homedir())` walk and the N parallel `git worktree list`\n * spawns — together ~12-15s on a busy machine. Per-repo branch info is\n * still resolved fresh below via `getRepoMetadata` (cached separately by\n * git HEAD + config mtimes in `environments-cache.ts`). The list cache lives\n * for the daemon lifetime; `invalidateRepoPaths()` is called by\n * worktree-service (add/remove), capability-watcher (FSEvents rescan),\n * and explicit force-refresh paths.\n */\n const cachedPaths = getCachedRepoPaths();\n let repoPaths: string[];\n let worktreePaths: string[];\n\n if (cachedPaths) {\n repoPaths = cachedPaths.repos;\n worktreePaths = cachedPaths.worktrees;\n } else {\n try {\n repoPaths = await findGitRepos(homedir());\n } catch (err) {\n if (lastKnown && lastKnown.length > 0) {\n const { logger } = await import('../logger.js');\n logger.warn(\n { err, lastKnownCount: lastKnown.length },\n 'detectEnvironments findGitRepos threw — preserving lastKnown'\n );\n return lastKnown;\n }\n return [];\n }\n\n if (repoPaths.length === 0 && lastKnown && lastKnown.length > 0) {\n /**\n * Walk returned empty but we know there used to be repos — almost\n * certainly a transient root-readdir error swallowed inside\n * `findGitRepos`. Preserve rather than wipe.\n */\n const { logger } = await import('../logger.js');\n logger.warn(\n { lastKnownCount: lastKnown.length },\n 'detectEnvironments walk empty but lastKnown non-empty — preserving lastKnown'\n );\n return lastKnown;\n }\n\n worktreePaths = await discoverWorktrees(repoPaths);\n setCachedRepoPaths(repoPaths, worktreePaths);\n }\n\n const allPaths = [...new Set([...repoPaths, ...worktreePaths])];\n\n const prevCache = await loadCache();\n const fingerprints = await mapLimit(allPaths, REPO_METADATA_CONCURRENCY, getGitCacheFingerprint);\n const nextCache = new Map<string, CacheEntry>();\n\n /**\n * Per-path timing + hard timeout. Walk continues past timed-out paths so\n * one bad mount (NFS, dead symlink, removed volume) can't pin the entire\n * environments slice. Slow paths log a structured event for diagnosis.\n */\n const resolved = await mapLimit(allPaths, REPO_METADATA_CONCURRENCY, (path, idx) =>\n processRepoPaths(path, idx, fingerprints, prevCache, nextCache)\n );\n\n await saveCache(nextCache);\n\n return resolved.filter((info): info is GitRepoInfo => info !== null);\n}\n\n/**\n * For each repo, run `git worktree list --porcelain` to discover\n * linked worktrees (which may live in dot-directories like .claude/worktrees/).\n *\n * Dedupes across repos: linked worktrees that are themselves git repos get\n * walked AGAIN by `findGitRepos`, and running `git worktree list` from each\n * one reports the same set of paths back. Without dedupe the cache grew to\n * 7,420 entries on a machine with only 149 unique worktrees (2026-05-14\n * boot wedge investigation). `dedupePerRepoWorktreeOutputs` collapses to\n * unique paths while preserving the first-seen ordering for determinism.\n */\nexport async function discoverWorktrees(repoPaths: string[]): Promise<string[]> {\n const results = await mapLimit(\n repoPaths,\n WORKTREE_DISCOVERY_CONCURRENCY,\n async (repoPath): Promise<PromiseSettledResult<string[]>> => {\n try {\n return { status: 'fulfilled', value: await listLinkedWorktrees(repoPath) };\n } catch (reason) {\n return { status: 'rejected', reason };\n }\n }\n );\n return dedupePerRepoWorktreeOutputs(results);\n}\n\nfunction dedupePerRepoWorktreeOutputs(results: PromiseSettledResult<string[]>[]): string[] {\n const seen = new Set<string>();\n const out: string[] = [];\n for (const r of results) {\n if (r.status !== 'fulfilled') continue;\n for (const wt of r.value) {\n if (seen.has(wt)) continue;\n seen.add(wt);\n out.push(wt);\n }\n }\n return out;\n}\n\n/**\n * Enumerate linked worktrees for a git repository by reading the\n * `.git/worktrees/` directory directly rather than spawning a git subprocess.\n *\n * Git's on-disk format (gitrepository-layout(5), stable since git 2.5):\n * .git/worktrees/<name>/gitdir — contains the path to the worktree's\n * `.git` file, e.g. `/path/to/wt/.git`\n *\n * Stripping `/.git` from that content yields the worktree path. Missing\n * `.git/worktrees/` directory means no linked worktrees — return [].\n * Orphaned entries (gitdir file missing/unreadable) are silently skipped.\n */\nasync function listLinkedWorktrees(repoPath: string): Promise<string[]> {\n const gitWorktreesDir = join(repoPath, '.git', 'worktrees');\n let entries: string[];\n try {\n entries = await readdir(gitWorktreesDir);\n } catch {\n return [];\n }\n\n const paths = await Promise.all(\n entries.map(async (name) => {\n try {\n const gitdirFile = join(gitWorktreesDir, name, 'gitdir');\n const content = await readFile(gitdirFile, 'utf8');\n const wtGitPath = content.trim();\n if (wtGitPath.endsWith('/.git')) {\n return wtGitPath.slice(0, -'/.git'.length);\n }\n return null;\n } catch {\n return null;\n }\n })\n );\n\n return paths.filter((p): p is string => p !== null && p !== repoPath);\n}\n\n/** @internal kept for tests that exercise parse logic on porcelain output */\nfunction parseWorktreeListOutput(output: string, repoPath: string): string[] {\n const paths: string[] = [];\n for (const line of output.split('\\n')) {\n if (line.startsWith('worktree ')) {\n const wt = line.slice('worktree '.length).trim();\n if (wt && wt !== repoPath) paths.push(wt);\n }\n }\n return paths;\n}\n\nexport const _testing = {\n parseWorktreeListOutput,\n dedupePerRepoWorktreeOutputs,\n listLinkedWorktrees,\n readBranchFromHead,\n mapLimit,\n withProbeTimeout,\n GIT_PROBE_TIMEOUT_MS,\n SLOW_PATH_LOG_THRESHOLD_MS,\n NEGATIVE_CACHE_TTL_MS,\n readGitRepoCache,\n resetGitRepoCache: () => {\n gitRepoCache.clear();\n },\n resetGhAvailableCache: () => {\n ghAvailableCache = false;\n },\n};\n","import { mkdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport { z } from 'zod';\nimport { getShipyardHome } from '../env.js';\nimport { isEnoent } from '../fs-utils.js';\nimport { logger } from '../logger.js';\n\nconst CacheEntrySchema = z.object({\n path: z.string(),\n branch: z.string(),\n remote: z.string().nullable(),\n headMtimeMs: z.number(),\n /**\n * Added after the original cache shape. Optional so old disk caches parse,\n * but `isCacheValid` treats missing as invalid and refreshes once.\n */\n configMtimeMs: z.number().nullable().optional(),\n cachedAt: z.number(),\n});\n\nconst CacheFileSchema = z.object({\n entries: z.record(z.string(), CacheEntrySchema),\n});\n\nexport type CacheEntry = z.infer<typeof CacheEntrySchema>;\ntype CacheFile = z.infer<typeof CacheFileSchema>;\nexport interface GitCacheFingerprint {\n headMtimeMs: number | null;\n configMtimeMs: number | null;\n}\n\nfunction cacheFilePath(): string {\n return join(getShipyardHome(), 'data', 'environments-cache.json');\n}\n\nlet cacheMigrationDone = false;\n\nexport async function loadCache(): Promise<Map<string, CacheEntry>> {\n const filePath = cacheFilePath();\n try {\n const raw = await readFile(filePath, 'utf8');\n const parsed: unknown = JSON.parse(raw);\n const result = CacheFileSchema.safeParse(parsed);\n if (!result.success) {\n logger.debug({ path: filePath }, 'environments-cache: malformed, treating as empty');\n cacheMigrationDone = true;\n return new Map();\n }\n const cache = new Map(Object.entries(result.data.entries));\n if (!cacheMigrationDone) {\n cacheMigrationDone = true;\n await migrateConfigMtimes(cache);\n }\n return cache;\n } catch (err) {\n if (isEnoent(err)) {\n cacheMigrationDone = true;\n return new Map();\n }\n logger.debug({ err }, 'environments-cache: read failed, treating as empty');\n return new Map();\n }\n}\n\n/**\n * One-shot migration: entries written before #3619 lack `configMtimeMs`.\n * `isCacheValid` would force a re-spawn for every such entry, creating a\n * git subprocess storm on first boot after upgrade. Backfill the field by\n * reading `.git/config` mtimes directly, then persist so subsequent boots\n * hit the cache normally.\n */\nasync function migrateConfigMtimes(cache: Map<string, CacheEntry>): Promise<void> {\n const stale = [...cache.values()].filter((e) => e.configMtimeMs === undefined);\n if (stale.length === 0) return;\n await Promise.all(\n stale.map(async (entry) => {\n const fp = await getGitCacheFingerprint(entry.path);\n cache.set(entry.path, { ...entry, configMtimeMs: fp.configMtimeMs });\n })\n );\n logger.info({ count: stale.length }, 'environments-cache: cache_migration_seeded');\n await saveCache(cache);\n}\n\n/**\n * Resolve git metadata paths for a repository or linked worktree.\n *\n * - If `<path>/.git` is a directory, metadata lives inside that directory.\n * - If `<path>/.git` is a file, it contains `gitdir: <path>`. HEAD lives in\n * that worktree gitdir, while remotes live in the common git dir's config.\n * - Returns null on any error (missing, unreadable, malformed).\n */\nasync function readGitdirFile(dotGitPath: string): Promise<string | null> {\n const contents = await readFile(dotGitPath, 'utf8');\n const match = contents.match(/^gitdir:\\s*(.+)\\s*$/m);\n if (!match?.[1]) return null;\n const gitdirRaw = match[1].trim();\n return isAbsolute(gitdirRaw) ? gitdirRaw : resolve(dirname(dotGitPath), gitdirRaw);\n}\n\nasync function resolveCommonGitDir(gitdir: string): Promise<string> {\n try {\n const raw = await readFile(join(gitdir, 'commondir'), 'utf8');\n const commonDirRaw = raw.trim();\n if (commonDirRaw === '') return gitdir;\n return isAbsolute(commonDirRaw) ? commonDirRaw : resolve(gitdir, commonDirRaw);\n } catch {\n return gitdir;\n }\n}\n\nexport async function resolveHeadPath(worktreePath: string): Promise<string | null> {\n const paths = await resolveGitMetadataPaths(worktreePath);\n return paths?.headPath ?? null;\n}\n\nexport async function resolveGitMetadataPaths(\n worktreePath: string\n): Promise<{ headPath: string; configPath: string | null } | null> {\n const dotGitPath = join(worktreePath, '.git');\n try {\n const dotGitStat = await stat(dotGitPath);\n if (dotGitStat.isDirectory()) {\n return { headPath: join(dotGitPath, 'HEAD'), configPath: join(dotGitPath, 'config') };\n }\n if (dotGitStat.isFile()) {\n const gitdir = await readGitdirFile(dotGitPath);\n if (!gitdir) return null;\n const commonGitDir = await resolveCommonGitDir(gitdir);\n return { headPath: join(gitdir, 'HEAD'), configPath: join(commonGitDir, 'config') };\n }\n return null;\n } catch {\n return null;\n }\n}\n\nasync function getPathMtime(path: string | null): Promise<number | null> {\n if (!path) return null;\n try {\n const pathStat = await stat(path);\n return pathStat.mtimeMs;\n } catch {\n return null;\n }\n}\n\nexport async function getGitCacheFingerprint(worktreePath: string): Promise<GitCacheFingerprint> {\n const paths = await resolveGitMetadataPaths(worktreePath);\n if (!paths) return { headMtimeMs: null, configMtimeMs: null };\n const [headMtimeMs, configMtimeMs] = await Promise.all([\n getPathMtime(paths.headPath),\n getPathMtime(paths.configPath),\n ]);\n return { headMtimeMs, configMtimeMs };\n}\n\nexport function isCacheValid(entry: CacheEntry, current: GitCacheFingerprint): boolean {\n /**\n * `.git/HEAD` invalidates branch, and `.git/config` invalidates remote.\n * Entries without `configMtimeMs` are soft-migrated at `loadCache` time\n * (see `migrateConfigMtimes`), so by the time this is called the field\n * is always present. Treat `undefined` the same as `null` for safety.\n */\n return (\n entry.headMtimeMs === current.headMtimeMs &&\n (entry.configMtimeMs ?? null) === current.configMtimeMs\n );\n}\n\nexport async function saveCache(entries: Map<string, CacheEntry>): Promise<void> {\n const filePath = cacheFilePath();\n const tmpPath = `${filePath}.tmp`;\n try {\n await mkdir(dirname(filePath), { recursive: true });\n /**\n * Merge-on-save: re-read disk immediately before writing so a concurrent\n * saveCache call's entries are preserved rather than erased (new entries\n * win for paths present in both — they are fresher).\n */\n const current = await loadCache();\n for (const [path, entry] of entries) {\n current.set(path, entry);\n }\n const payload: CacheFile = { entries: Object.fromEntries(current) };\n await writeFile(tmpPath, JSON.stringify(payload), 'utf8');\n await rename(tmpPath, filePath);\n } catch (err) {\n logger.debug({ err, filePath }, 'environments-cache: save failed');\n void unlink(tmpPath).catch(() => {});\n }\n}\n","/**\n * In-memory cache of the list of git repo paths under $HOME and the linked\n * worktree paths discovered via `git worktree list --porcelain` for each.\n *\n * Distinct from `environments-cache.ts` (which caches per-repo branch/remote\n * info on disk, keyed by git HEAD + config mtimes). This one caches the LIST of repos and\n * worktrees — i.e. the `findGitRepos(homedir())` walk and the N parallel\n * `git worktree list` spawns. Those are the ~12-50s cost on a busy machine.\n *\n * Lifetime: persisted to disk at `~/.shipyard/data/repo-paths-cache.json`\n * and rehydrated on every daemon boot. The previous implementation rejected\n * the disk cache outright when its age exceeded 1h — which is almost every\n * reboot in practice — and forced the 30s `findGitRepos($HOME)` walk to fire\n * on each cold boot. We now serve any structurally-valid cache regardless of\n * age and kick off a background re-walk when the cache is older than 5\n * minutes. Boot time drops from 30-50s to milliseconds; freshness is\n * restored ~10-30s after boot when the background walk completes.\n *\n * Invalidation:\n * - `invalidateRepoPaths()` — called by:\n * * capability-watcher.ts (FSEvents rescan + escalation paths)\n * * explicit force-refresh control message\n * - `addWorktreeToCache()` / `removeWorktreeFromCache()` — incremental\n * update used by worktree create/remove. Avoids the cold-walk recompute\n * storm that otherwise stalls the event loop 12-15s and kills the\n * daemon's WebRTC + control channels mid-creation. If there is no\n * active cache (boot before first walk), the call is a no-op — the\n * next cold walk picks up the new state.\n *\n * The walk + worktree spawns ARE NOT triggered by the capability-watcher's\n * normal events: scoped re-detect (`refreshMcpServers` etc.) skips\n * `detectEnvironments` entirely and reuses the existing `daemon.capabilities\n * ?.environments`. The cache is only consulted by full `detectCapabilities`\n * runs (manual Refresh button, boot, cwd-changed).\n */\n\nimport { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { z } from 'zod';\nimport { getShipyardHome } from '../env.js';\nimport { isEnoent } from '../fs-utils.js';\nimport type { createChildLogger } from '../logger.js';\nimport { logger } from '../logger.js';\n\nexport {\n getCachedRepoPaths,\n hydrateAndLogRepoPathsCache,\n hydrateRepoPathsCacheFromDisk,\n setCachedRepoPaths,\n invalidateRepoPaths,\n addWorktreeToCache,\n removeWorktreeFromCache,\n};\n\nexport type { HydrateResult };\n\ninterface CachedEntry {\n repos: string[];\n worktrees: string[];\n populatedAt: number;\n}\n\ninterface HydrateResult {\n hit: boolean;\n stale: boolean;\n}\n\nconst RepoPathsDiskSchema = z.object({\n repos: z.array(z.string()),\n worktrees: z.array(z.string()),\n populatedAt: z.number(),\n});\n\nconst STALE_AFTER_MS_DEFAULT = 5 * 60 * 1000;\n\nlet cache: CachedEntry | null = null;\n/**\n * Monotonic counter incremented on every mutating call. Async disk operations\n * capture the generation at the moment they were scheduled and no-op when\n * the generation has changed by the time they get to the syscall. Without\n * this, `invalidateRepoPaths()` (which fires `void unlinkDisk()`) racing\n * with a subsequent `setCachedRepoPaths()` (which fires `void persistDisk()`)\n * could leave the disk in either state — and if `unlinkDisk` wins after\n * `persistDisk`'s rename succeeds, the next daemon restart pays the full\n * cold-walk cost despite a valid cache having just been written.\n */\nlet cacheGeneration = 0;\nlet backgroundRefreshInFlight = false;\n\nfunction cacheFilePath(): string {\n return join(getShipyardHome(), 'data', 'repo-paths-cache.json');\n}\n\nfunction getCachedRepoPaths(): { repos: string[]; worktrees: string[] } | null {\n if (!cache) return null;\n return { repos: cache.repos, worktrees: cache.worktrees };\n}\n\nfunction setCachedRepoPaths(repos: string[], worktrees: string[], now: number = Date.now()): void {\n cache = { repos, worktrees, populatedAt: now };\n cacheGeneration += 1;\n void persistDisk(cache, cacheGeneration);\n}\n\nfunction invalidateRepoPaths(): void {\n cache = null;\n cacheGeneration += 1;\n void unlinkDisk(cacheGeneration);\n}\n\n/**\n * Best-effort hydrate the in-memory cache from disk on daemon boot. Always\n * accepts a structurally-valid on-disk entry regardless of age — the boot\n * path needs the data immediately and any staleness is repaired by a\n * background re-walk scheduled by `hydrateAndLogRepoPathsCache`. Returns\n * `{ hit, stale }` so the caller knows whether to schedule that refresh.\n *\n * The `staleAfterMs` threshold defines when the cache is \"old enough to\n * re-walk in the background\" — not when it's \"too old to serve\". Default\n * 5 minutes; data older than that triggers a background refresh but is\n * still returned to the boot path so `detect_environments` sees a populated\n * cache and skips the 30s `findGitRepos` walk + `git worktree list` storm.\n *\n * Wired from `serve.ts` BEFORE `createSignalingHandle()` so the first\n * `detectEnvironments` call inside the background `runCapabilityDetection`\n * (#3360 — detection moved off the boot path) sees the populated in-memory\n * cache. Without this, every daemon restart pays the full cold-walk cost —\n * observed at 30-50s on busy machines and the dominant component of 42.5s\n * worst-case boot.\n */\nasync function hydrateRepoPathsCacheFromDisk(opts?: {\n staleAfterMs?: number;\n}): Promise<HydrateResult> {\n if (cache !== null) return { hit: false, stale: false };\n const filePath = cacheFilePath();\n let raw: string;\n try {\n raw = await readFile(filePath, 'utf8');\n } catch (err: unknown) {\n if (isEnoent(err)) return { hit: false, stale: false };\n logger.debug({ err, filePath }, 'repo-paths-cache: read failed');\n return { hit: false, stale: false };\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return { hit: false, stale: false };\n }\n const result = RepoPathsDiskSchema.safeParse(parsed);\n if (!result.success) return { hit: false, stale: false };\n\n /**\n * Race-safe: another caller may have populated the slot between our\n * `cache !== null` check and the disk read. Don't clobber the live entry.\n */\n if (cache !== null) return { hit: false, stale: false };\n\n const staleAfterMs = opts?.staleAfterMs ?? STALE_AFTER_MS_DEFAULT;\n const ageMs = Math.max(0, Date.now() - result.data.populatedAt);\n const stale = ageMs > staleAfterMs;\n\n cache = result.data;\n logger.info(\n { repos: result.data.repos.length, worktrees: result.data.worktrees.length, ageMs, stale },\n 'repo-paths-cache: hydrated from disk'\n );\n return { hit: true, stale };\n}\n\nasync function persistDisk(entry: CachedEntry, generation: number): Promise<void> {\n const filePath = cacheFilePath();\n const tmpPath = `${filePath}.tmp`;\n try {\n await mkdir(dirname(filePath), { recursive: true });\n await writeFile(tmpPath, JSON.stringify(entry), 'utf8');\n /**\n * Drop the write if a later mutation (set/invalidate/add/remove) raced\n * us. The successor's persist/unlink will reach the rename target with\n * the right state. Without this, an in-flight rename can clobber the\n * successor's just-written file or, worse, race a fresh persist after\n * an invalidate.\n */\n if (generation !== cacheGeneration) {\n await unlink(tmpPath).catch(() => {});\n return;\n }\n await rename(tmpPath, filePath);\n } catch (err: unknown) {\n logger.debug({ err, filePath }, 'repo-paths-cache: save failed');\n void unlink(tmpPath).catch(() => {});\n }\n}\n\nasync function unlinkDisk(generation: number): Promise<void> {\n /**\n * Drop the unlink if a later `setCachedRepoPaths` already raced us — its\n * `persistDisk` will write the fresh file and the file the unlink would\n * have removed is the predecessor's. Without this generation check, an\n * `invalidate → set` sequence can end up with NO disk file even though\n * `set` persisted one.\n */\n if (generation !== cacheGeneration) return;\n try {\n await unlink(cacheFilePath());\n } catch {\n /** No-op — file may not exist yet. */\n }\n}\n\n/**\n * Append a freshly-created worktree to the existing cached result. Source\n * repo path is also added (deduped) because a brand-new repo can host a\n * brand-new worktree, and the next `detectEnvironments` call needs to see\n * both. No-op when there is no cache yet — the next cold walk will discover\n * the new entries naturally.\n */\nfunction addWorktreeToCache(worktreePath: string, sourceRepoPath: string): void {\n if (!cache) return;\n const repos = cache.repos.includes(sourceRepoPath)\n ? cache.repos\n : [...cache.repos, sourceRepoPath];\n const worktrees = cache.worktrees.includes(worktreePath)\n ? cache.worktrees\n : [...cache.worktrees, worktreePath];\n cache = { repos, worktrees, populatedAt: cache.populatedAt };\n cacheGeneration += 1;\n void persistDisk(cache, cacheGeneration);\n}\n\n/**\n * Splice a worktree path out of the cached worktree list. The source repo\n * stays — removing a single linked worktree never deletes its source. No-op\n * when there is no cache yet.\n */\nfunction removeWorktreeFromCache(worktreePath: string): void {\n if (!cache) return;\n const next = cache.worktrees.filter((p) => p !== worktreePath);\n if (next.length === cache.worktrees.length) return;\n cache = { repos: cache.repos, worktrees: next, populatedAt: cache.populatedAt };\n cacheGeneration += 1;\n void persistDisk(cache, cacheGeneration);\n}\n\n/**\n * Re-walk `$HOME` and rewrite the cache. Fired by `hydrateAndLogRepoPathsCache`\n * on boot when the hydrated cache is stale, restoring freshness ~10-30s after\n * the user is already interactive. Single-flight: a second call while one is\n * in progress is a no-op. Generation-guarded: if any synchronous mutation\n * (`setCachedRepoPaths`, `addWorktreeToCache`, `removeWorktreeFromCache`,\n * `invalidateRepoPaths`) lands while the walk is in flight, the refresh\n * result is dropped so it does not clobber a more-recent incremental update.\n *\n * Lazy-imports `./git-repo.js` to break the import cycle (`git-repo` already\n * imports this module).\n */\nasync function refreshRepoPathsInBackground(\n log: ReturnType<typeof createChildLogger>\n): Promise<void> {\n if (backgroundRefreshInFlight) return;\n backgroundRefreshInFlight = true;\n const startGen = cacheGeneration;\n const start = Date.now();\n try {\n const { findGitRepos, discoverWorktrees } = await import('./git-repo.js');\n const { homedir } = await import('node:os');\n const repos = await findGitRepos(homedir());\n const worktrees = await discoverWorktrees(repos);\n if (cacheGeneration !== startGen) {\n log.debug(\n { event: 'repo_paths_cache_refresh_dropped' },\n 'repo-paths-cache: background refresh dropped (cache mutated mid-walk)'\n );\n return;\n }\n /**\n * Defense in depth: a transient root-readdir failure inside\n * `findGitRepos` returns `[]`, indistinguishable from \"no repos exist\".\n * If the prior cache had entries, preserve it rather than wipe — the\n * next refresh (capability-watcher tick) will retry. Mirrors the same\n * guard inside `detectEnvironments`.\n */\n if (repos.length === 0 && cache && cache.repos.length > 0) {\n log.warn(\n {\n event: 'repo_paths_cache_refresh_empty_preserved',\n prevRepos: cache.repos.length,\n },\n 'repo-paths-cache: background refresh returned empty; preserving prior cache'\n );\n return;\n }\n setCachedRepoPaths(repos, worktrees);\n log.info(\n {\n event: 'repo_paths_cache_refresh_complete',\n repos: repos.length,\n worktrees: worktrees.length,\n durationMs: Date.now() - start,\n },\n 'repo-paths-cache: background refresh complete'\n );\n } catch (err) {\n log.warn(\n { err, event: 'repo_paths_cache_refresh_failed', durationMs: Date.now() - start },\n 'repo-paths-cache: background refresh failed'\n );\n } finally {\n backgroundRefreshInFlight = false;\n }\n}\n\n/**\n * Hydrate from disk and log the hit/miss outcome. Boot callers wrap this in\n * `bootstrapPhase('repo_paths_cache_hydrate', ...)` — the wrapper always\n * records `outcome: 'success'` because hydrate returns a result object (no\n * throw on ENOENT). The explicit log here is what surfaces whether the\n * upcoming `detect_environments` will pay the cold walk and whether a\n * background refresh was scheduled.\n */\nasync function hydrateAndLogRepoPathsCache(\n log: ReturnType<typeof createChildLogger>\n): Promise<boolean> {\n const result = await hydrateRepoPathsCacheFromDisk();\n log.info(\n {\n event: 'repo_paths_cache_hydrate_result',\n hit: result.hit,\n stale: result.stale,\n },\n result.hit\n ? result.stale\n ? 'repo-paths cache hydrated from disk (stale; background refresh scheduled)'\n : 'repo-paths cache hydrated from disk (fresh)'\n : 'repo-paths cache cold (walk will fire inside detect_environments)'\n );\n if (result.hit && result.stale) {\n void refreshRepoPathsInBackground(log);\n }\n return result.hit;\n}\n\nexport const _testing = {\n reset: invalidateRepoPaths,\n inspect: () => cache,\n refreshRepoPathsInBackground,\n cacheFilePath,\n isBackgroundRefreshInFlight: () => backgroundRefreshInFlight,\n};\n","import { execFile } from 'node:child_process';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\nexport const TIMEOUT_MS = 5_000;\n/**\n * Cap on `claude auth status --json` during capability detection. Healthy\n * CLI responds in well under 1s; 15s was a worst-case-CLI-cold-start\n * accommodation that singlehandedly added up to 15s of boot stall when the\n * subprocess hung. 5s is generous slack while keeping the bootstrap\n * `detectCapabilities → signaling register` path bounded. See issue #3267.\n */\nexport const AUTH_STATUS_TIMEOUT_MS = 5_000;\n\n/**\n * Build the version-manager and user-local binary dirs for macOS.\n * These paths are absent when the daemon is launched from Finder/Spotlight\n * because macOS GUI apps inherit a stripped PATH that skips the user's\n * shell profile (where nvm/volta/mise/asdf entries normally live).\n *\n * Listed from most commonly needed (nvm, volta) to least common (cargo).\n * All are idempotently filtered by augmentPath — already-present entries\n * are never duplicated.\n */\nfunction buildDarwinVersionManagerPaths(home: string): string[] {\n return [\n join(home, '.nvm', 'current', 'bin'),\n join(home, '.volta', 'bin'),\n join(home, '.local', 'bin'),\n join(home, '.cargo', 'bin'),\n '/opt/homebrew/opt/node/bin',\n ];\n}\n\nexport const STANDARD_PATHS_BY_PLATFORM: Partial<Record<NodeJS.Platform, readonly string[]>> = {\n darwin: [\n '/usr/bin',\n '/usr/local/bin',\n '/opt/homebrew/bin',\n ...buildDarwinVersionManagerPaths(homedir()),\n ],\n linux: ['/usr/bin', '/usr/local/bin'],\n};\n\n/**\n * Daemons launched from Finder/Spotlight on macOS get a stripped PATH that may\n * omit /usr/bin where git lives. Prepend standard locations idempotently so\n * `execFile('git', ...)` resolves the binary. User-customized PATH entries\n * stay preferred — we only prepend dirs that aren't already present.\n */\nexport function augmentPath(currentPath: string, platform: NodeJS.Platform): string {\n const standardPaths = STANDARD_PATHS_BY_PLATFORM[platform];\n if (!standardPaths) return currentPath;\n\n const existing = currentPath.length > 0 ? currentPath.split(':') : [];\n const existingSet = new Set(existing);\n const toPrepend = standardPaths.filter((p) => !existingSet.has(p));\n if (toPrepend.length === 0) return currentPath;\n return existing.length > 0 ? `${toPrepend.join(':')}:${currentPath}` : toPrepend.join(':');\n}\n\nconst augmentedPath = augmentPath(process.env.PATH ?? '', process.platform);\nif (augmentedPath.length > 0) {\n process.env.PATH = augmentedPath;\n}\n\nexport function run(\n command: string,\n args: string[],\n cwd?: string,\n timeoutMs: number = TIMEOUT_MS\n): Promise<string> {\n return new Promise((resolve, reject) => {\n execFile(command, args, { timeout: timeoutMs, cwd }, (error, stdout) => {\n if (error) {\n reject(error);\n return;\n }\n resolve(stdout.trim());\n });\n });\n}\n\nexport function runWithTimeout(\n command: string,\n args: string[],\n cwd: string,\n timeoutMs: number\n): Promise<string> {\n return new Promise((resolve, reject) => {\n execFile(\n command,\n args,\n { timeout: timeoutMs, cwd, maxBuffer: 10 * 1024 * 1024 },\n (error, stdout) => {\n if (error) {\n reject(error);\n return;\n }\n resolve(stdout.trim());\n }\n );\n });\n}\n\nexport const DIFF_TIMEOUT_MS = 15_000;\nexport const MAX_DIFF_SIZE = 500_000;\n\nexport function isMaxBufferError(err: unknown): boolean {\n return err instanceof Error && err.message.includes('maxBuffer');\n}\n\nexport const BUFFER_OVERFLOW_MSG = '... diff too large (exceeded buffer limit) ...\\n';\n\nexport function truncateDiff(result: string): string {\n if (result.length <= MAX_DIFF_SIZE) return result;\n const boundary = result.lastIndexOf('\\ndiff --git ', MAX_DIFF_SIZE);\n const cutoff = boundary > 0 ? boundary : MAX_DIFF_SIZE;\n return `${result.slice(0, cutoff)}\\n\\n... diff truncated (exceeds 500KB) ...\\n`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,YAAAA,iBAAgB;AAClC,SAAS,UAAU,QAAAC,aAAY;;;ACD/B,SAAS,OAAO,UAAU,QAAQ,MAAM,QAAQ,iBAAiB;AACjE,SAAS,SAAS,YAAY,MAAM,eAAe;AAMnD,IAAM,mBAAmB,iBAAE,OAAO;AAAA,EAChC,MAAM,iBAAE,OAAO;AAAA,EACf,QAAQ,iBAAE,OAAO;AAAA,EACjB,QAAQ,iBAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,aAAa,iBAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtB,eAAe,iBAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC9C,UAAU,iBAAE,OAAO;AACrB,CAAC;AAED,IAAM,kBAAkB,iBAAE,OAAO;AAAA,EAC/B,SAAS,iBAAE,OAAO,iBAAE,OAAO,GAAG,gBAAgB;AAChD,CAAC;AASD,SAAS,gBAAwB;AAC/B,SAAO,KAAK,gBAAgB,GAAG,QAAQ,yBAAyB;AAClE;AAEA,IAAI,qBAAqB;AAEzB,eAAsB,YAA8C;AAClE,QAAM,WAAW,cAAc;AAC/B,MAAI;AACF,UAAM,MAAM,MAAM,SAAS,UAAU,MAAM;AAC3C,UAAM,SAAkB,KAAK,MAAM,GAAG;AACtC,UAAM,SAAS,gBAAgB,UAAU,MAAM;AAC/C,QAAI,CAAC,OAAO,SAAS;AACnB,aAAO,MAAM,EAAE,MAAM,SAAS,GAAG,kDAAkD;AACnF,2BAAqB;AACrB,aAAO,oBAAI,IAAI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,SAAS,OAAO,GAAG;AAC/B,iBAAO,UAAU,MAAM,GAAG,CAAC,QAAQ,MAAM;AAAA,QAC3C;AACA,eAAO;AAAA,MACT,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,MAAM,OAAO,CAAC,MAAmB,MAAM,QAAQ,MAAM,QAAQ;AACtE;AAGA,SAAS,wBAAwB,QAAgB,UAA4B;AAC3E,QAAM,QAAkB,CAAC;AACzB,aAAW,QAAQ,OAAO,MAAM,IAAI,GAAG;AACrC,QAAI,KAAK,WAAW,WAAW,GAAG;AAChC,YAAM,KAAK,KAAK,MAAM,YAAY,MAAM,EAAE,KAAK;AAC/C,UAAI,MAAM,OAAO,SAAU,OAAM,KAAK,EAAE;AAAA,IAC1C;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,WAAW;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAmB,MAAM;AACvB,iBAAa,MAAM;AAAA,EACrB;AAAA,EACA,uBAAuB,MAAM;AAC3B,uBAAmB;AAAA,EACrB;AACF;","names":["readFile","join","cache","mkdir","readFile","rename","unlink","writeFile","dirname","join","cacheFilePath","join","cacheFilePath","readFile","mkdir","dirname","writeFile","unlink","rename","findGitRepos","discoverWorktrees","homedir","join","resolve","resolve","join","readFile","homedir","logger"]}