Something went wrong. Try again.
source dump of claude code forked from oppi.li/claude-code
Something went wrong. Try again.
2.1 kB · 75 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import { sep } from 'path'import { getOriginalCwd } from '../bootstrap/state.js'import type { LogOption } from '../types/logs.js'import { quote } from './bash/shellQuote.js'import { getSessionIdFromLog } from './sessionStorage.js'
export type CrossProjectResumeResult = | { isCrossProject: false } | { isCrossProject: true isSameRepoWorktree: true projectPath: string } | { isCrossProject: true isSameRepoWorktree: false command: string projectPath: string }
/** * Check if a log is from a different project directory and determine * whether it's a related worktree or a completely different project. * * For same-repo worktrees, we can resume directly without requiring cd. * For different projects, we generate the cd command. */export function checkCrossProjectResume( log: LogOption, showAllProjects: boolean, worktreePaths: string[],): CrossProjectResumeResult { const currentCwd = getOriginalCwd()
if (!showAllProjects || !log.projectPath || log.projectPath === currentCwd) { return { isCrossProject: false } }
// Gate worktree detection to ants only for staged rollout if (process.env.USER_TYPE !== 'ant') { const sessionId = getSessionIdFromLog(log) const command = `cd ${quote([log.projectPath])} && claude --resume ${sessionId}` return { isCrossProject: true, isSameRepoWorktree: false, command, projectPath: log.projectPath, } }
// Check if log.projectPath is under a worktree of the same repo const isSameRepo = worktreePaths.some( wt => log.projectPath === wt || log.projectPath!.startsWith(wt + sep), )
if (isSameRepo) { return { isCrossProject: true, isSameRepoWorktree: true, projectPath: log.projectPath, } }
// Different repo - generate cd command const sessionId = getSessionIdFromLog(log) const command = `cd ${quote([log.projectPath])} && claude --resume ${sessionId}` return { isCrossProject: true, isSameRepoWorktree: false, command, projectPath: log.projectPath, }}