(input)
| 75 | renderToolUseMessage, |
| 76 | renderToolResultMessage, |
| 77 | async call(input) { |
| 78 | // Validate not already in a worktree created by this session |
| 79 | if (getCurrentWorktreeSession()) { |
| 80 | throw new Error('Already in a worktree session') |
| 81 | } |
| 82 | |
| 83 | // Resolve to main repo root so worktree creation works from within a worktree |
| 84 | const mainRepoRoot = findCanonicalGitRoot(getCwd()) |
| 85 | if (mainRepoRoot && mainRepoRoot !== getCwd()) { |
| 86 | process.chdir(mainRepoRoot) |
| 87 | setCwd(mainRepoRoot) |
| 88 | } |
| 89 | |
| 90 | const slug = input.name ?? getPlanSlug() |
| 91 | |
| 92 | const worktreeSession = await createWorktreeForSession(getSessionId(), slug) |
| 93 | |
| 94 | process.chdir(worktreeSession.worktreePath) |
| 95 | setCwd(worktreeSession.worktreePath) |
| 96 | setOriginalCwd(getCwd()) |
| 97 | saveWorktreeState(worktreeSession) |
| 98 | // Clear cached system prompt sections so env_info_simple recomputes with worktree context |
| 99 | clearSystemPromptSections() |
| 100 | // Clear memoized caches that depend on CWD |
| 101 | clearMemoryFileCaches() |
| 102 | getPlansDirectory.cache.clear?.() |
| 103 | |
| 104 | logEvent('tengu_worktree_created', { |
| 105 | mid_session: true, |
| 106 | }) |
| 107 | |
| 108 | const branchInfo = worktreeSession.worktreeBranch |
| 109 | ? ` on branch ${worktreeSession.worktreeBranch}` |
| 110 | : '' |
| 111 | |
| 112 | return { |
| 113 | data: { |
| 114 | worktreePath: worktreeSession.worktreePath, |
| 115 | worktreeBranch: worktreeSession.worktreeBranch, |
| 116 | message: `Created worktree at ${worktreeSession.worktreePath}${branchInfo}. The session is now working in the worktree. Use ExitWorktree to leave mid-session, or exit the session to be prompted.`, |
| 117 | }, |
| 118 | } |
| 119 | }, |
| 120 | mapToolResultToToolResultBlockParam({ message }, toolUseID) { |
| 121 | return { |
| 122 | type: 'tool_result', |
nothing calls this directly
no test coverage detected