Repository navigation
Description
Important
Problem — There is no agent-accessible way to list, remove, or reset git worktrees. Slice 1 creates worktrees on session spawn, but orphans can accumulate (partial failures, abandoned sessions, completed work not cleaned up). The develop skill needs a cleanup step after merging branches, and power users need to manage worktrees explicitly.
Approach — Add an amicode_workspace tool to amicode_tools_core.ts that wraps the existing engine worktree CRUD APIs (GET/DELETE/POST reset /experimental/worktree). Three actions: list (returns active worktrees with their directories and branches), remove (deletes a worktree by directory), reset (resets a worktree to the default branch for reuse).
Scope — in: new tool definition, handler for list/remove/reset, tests · out: worktree creation (handled by Slice 1's workspace parameter on amicode_session), skill prompt updates (Slice 2)
Acceptance Criteria
-
amicode_workspacetool is registered inAMICODE_TOOLSwith actionslist,remove, andreset -
listaction callsGET /experimental/worktree, returns worktree directories and branches in a readable format, and includes a count ("3 active worktrees") -
removeaction accepts adirectoryparameter, callsDELETE /experimental/worktreewith that directory, and returns confirmation or error -
resetaction accepts adirectoryparameter, callsPOST /experimental/worktree/resetwith that directory, and returns confirmation or error - All three actions translate API rejections (feature gate off, worktree not found, remove failed) into actionable error messages
- The tool degrades to a clear error when the engine client is absent (MCP transport), matching
amicode_session's pattern -
EngineClientShapeworktree methods (added in Slice 1) are sufficient for this tool — no additional interface extensions needed
Testing Decisions
Extend the mock engine from Slice 1's test infrastructure:
- New:
workspace_lifecycle.test.ts— focused tests:list→ mock returns 3 worktrees → readable output with countlist→ mock returns empty → "no active worktrees" messageremovewith valid directory → mockremovecalled, confirmation returnedremovewith non-existent directory → error translated to actionable messageresetwith valid directory → mockresetcalled, confirmation returnedreset+ API rejection → error message- All actions without engine client → refusal message
Key Decisions
-
Three actions, one tool.
list,remove, andresetare one tool with anactionparameter, not three separate tools. This keeps the tool count manageable and groups related operations. -
No
createaction. Worktree creation is handled byamicode_session'sworkspace: "create"parameter (Slice 1). Creating a worktree without immediately binding a session to it is an edge case — if needed, the user can use the UI's "New workspace" button. -
Directory as the identifier. Worktrees are identified by their filesystem directory, matching the engine API's
RemoveInputandResetInputschemas. Thelistoutput includes directories so the agent can pass them toremove/reset.
Constraints & Invariants
- The tool consumes the same engine worktree APIs as Slice 1 — no new engine endpoints
- The
EngineClientShape.worktreeinterface from Slice 1 must not be modified — this slice only reads it - The tool must work with the experimental feature gate in the same way as Slice 1 (API is authoritative, tool translates errors)
Prior Art
packages/extension/src/amicode_tools_core.ts— the tool registry (add alongsideamicode_session)packages/opencode/src/server/routes/instance/httpapi/groups/experimental.ts— theGET/DELETE/POST resetworktree endpointspackages/opencode/src/worktree/index.ts—Worktree.Servicelist/remove/reset interfaces- Slice 1's
EngineClientShapeextension and mock engine pattern
Source
Part of #1059 · Blocked by Slice 1
Activity
workspaceparameter toamicode_sessiontool #1060feat(workspace): add amicode_workspace lifecycle management tool (#1062)
feat: agent-initiated workspace isolation — wire amicode_session to t…
jeonghun-jj-lee commentedon Sep 14, 2026
Landed in #1063 (
5b25681a) — Slice 3:amicode_workspacelifecycle management tool. Shipped as part of the single-PR #1059 implementation. Closing now.