( worktreeSession: PersistedWorktreeSession | null, )
| 2971 | * so --resume knows not to cd back into it. |
| 2972 | */ |
| 2973 | export function saveWorktreeState( |
| 2974 | worktreeSession: PersistedWorktreeSession | null, |
| 2975 | ): void { |
| 2976 | // Strip ephemeral fields (creationDurationMs, usedSparsePaths) that callers |
| 2977 | // may pass via full WorktreeSession objects — TypeScript structural typing |
| 2978 | // allows this, but we don't want them serialized to the transcript. |
| 2979 | const stripped: PersistedWorktreeSession | null = worktreeSession |
| 2980 | ? { |
| 2981 | originalCwd: worktreeSession.originalCwd, |
| 2982 | worktreePath: worktreeSession.worktreePath, |
| 2983 | worktreeName: worktreeSession.worktreeName, |
| 2984 | worktreeBranch: worktreeSession.worktreeBranch, |
| 2985 | originalBranch: worktreeSession.originalBranch, |
| 2986 | originalHeadCommit: worktreeSession.originalHeadCommit, |
| 2987 | sessionId: worktreeSession.sessionId, |
| 2988 | tmuxSessionName: worktreeSession.tmuxSessionName, |
| 2989 | hookBased: worktreeSession.hookBased, |
| 2990 | } |
| 2991 | : null |
| 2992 | const project = getProject() |
| 2993 | project.currentSessionWorktree = stripped |
| 2994 | // Write eagerly when the file already exists (mid-session enter/exit). |
| 2995 | // For --worktree startup, sessionFile is null — materializeSessionFile |
| 2996 | // will write it on the first message via reAppendSessionMetadata. |
| 2997 | if (project.sessionFile) { |
| 2998 | appendEntryToFile(project.sessionFile, { |
| 2999 | type: 'worktree-state', |
| 3000 | worktreeSession: stripped, |
| 3001 | sessionId: getSessionId(), |
| 3002 | }) |
| 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | /** |
| 3007 | * Extracts the session ID from a log. |
no test coverage detected