40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
/**
|
|
* 实施 / 规划会话 resume 的落点决策。纯函数,不碰 vscode API,便于单测。
|
|
*
|
|
* 角色由调用方明确传入,不从「有没有 cwd」反推:worktree 被清理后
|
|
* 工单里的 worktreePath 会清空,靠 cwd 推断会把实施会话误判成规划。
|
|
*/
|
|
export type ResumeKind = 'implement' | 'brainstorm'
|
|
|
|
export function resumeSessionRole(kind: ResumeKind): '实施' | '规划' {
|
|
return kind === 'implement' ? '实施' : '规划'
|
|
}
|
|
|
|
export function resumeTerminalName(kind: ResumeKind, sessionId: string, issueNumber?: number): string {
|
|
return issueNumber !== undefined
|
|
? `issue-${issueNumber}-${resumeSessionRole(kind)}`
|
|
: `Claude · ${sessionId.slice(0, 8)}`
|
|
}
|
|
|
|
export interface ResumeCwdInput {
|
|
kind: ResumeKind
|
|
workspaceRoot: string
|
|
/** 已解析成绝对路径的 worktree;工单没记就 undefined */
|
|
worktreeAbs?: string
|
|
worktreeExists: boolean
|
|
}
|
|
|
|
export interface ResumeCwdPlan {
|
|
cwd: string
|
|
/** 实施会话但 worktree 已不在磁盘上(含工单里没记 worktreePath 的情况) */
|
|
worktreeMissing: boolean
|
|
}
|
|
|
|
export function planResumeCwd(input: ResumeCwdInput): ResumeCwdPlan {
|
|
if (input.kind !== 'implement')
|
|
return { cwd: input.workspaceRoot, worktreeMissing: false }
|
|
if (input.worktreeAbs && input.worktreeExists)
|
|
return { cwd: input.worktreeAbs, worktreeMissing: false }
|
|
return { cwd: input.workspaceRoot, worktreeMissing: true }
|
|
}
|