(tool_input: dict[str, Any], context: ToolContext)
| 13 | |
| 14 | |
| 15 | def _enter_worktree_call(tool_input: dict[str, Any], context: ToolContext) -> ToolResult: |
| 16 | if context.worktree_root is not None: |
| 17 | raise ToolPermissionError("already in a worktree session") |
| 18 | name = tool_input.get("name") |
| 19 | if name is not None: |
| 20 | if not isinstance(name, str) or not name.strip(): |
| 21 | raise ToolInputError("name must be a non-empty string when provided") |
| 22 | if len(name) > 64 or not _NAME_RE.match(name): |
| 23 | raise ToolInputError("invalid worktree name") |
| 24 | slug = name |
| 25 | else: |
| 26 | slug = "worktree" |
| 27 | |
| 28 | root = context.workspace_root / ".clawcodex" / "worktrees" / slug |
| 29 | root.mkdir(parents=True, exist_ok=True) |
| 30 | context.worktree_root = root |
| 31 | context.cwd = root |
| 32 | return ToolResult( |
| 33 | name="EnterWorktree", |
| 34 | output={ |
| 35 | "worktreePath": str(root), |
| 36 | "worktreeBranch": None, |
| 37 | "message": f"Created worktree at {root}. The session is now working in the worktree.", |
| 38 | }, |
| 39 | ) |
| 40 | |
| 41 | |
| 42 | EnterWorktreeTool: Tool = build_tool( |
nothing calls this directly
no test coverage detected