feat: add commands for removing devcontainers#128
Open
darttie wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
/devcontainer rm <branch>and/devcontainer rm allcommands to fully tear down devcontainer workspaces, with pre-removal warnings for uncommitted changes and other active sessions.What it does
Remove commands
/devcontainer rm <branch>— Finds the Docker container for the workspace, stops and removes it, removes the image, releases the port, deletes the job entry, removes the override config, deletes the clone folder, and cleans up session files./devcontainer rm all— Same cleanup applied to every tracked devcontainer (collected from clones directory,ports.json, andjobs.json).Confirmation flow
Before removing, the tool checks for:
getWorkspaceStatus()(which runsgit status --porcelain)If any warnings are found, the tool returns a message stating that explicit user confirmation is required. The LLM asks the user, and if they agree, calls the tool again with
confirmed: trueto proceed.For
rm all, the check is optimized: scans all entries until it finds one with uncommitted changes, and checks for any other session files regardless of workspace.Implementation
plugin/core/devcontainer.jsremove()— Orchestrates full 10-step cleanup: find container → stop → get image ref →docker rm→docker rmi→ release port → remove job → delete override → delete clone → clean sessions. Returns a detailed summary of what was done.findContainerId()— Finds Docker container ID for a workspace using thedevcontainer.local_folderlabel.cleanupWorkspaceSessions()— Scans all session files in~/.cache/opencode-devcontainers/opencode-sessions/and deletes any whose.workspacematches the given path.plugin/core/jobs.jsremoveJob()— New export. Removes a job entry for a workspace, returnstrueif one existed.plugin/index.jshandleRemoveSingle()andhandleRemoveAll()— Orchestrate the rm flow: resolve workspace, run pre-removal warnings, callremove(), clear current session.countOtherSessions()— Counts session files (excluding current) by workspace path (or all ifnull).formatRemoveSummary()— Formats the remove result for display.confirmedparameter added to the devcontainer tool definition.remove,listClones,readPorts,readJobsfrom core modules.Tests
test/unit/devcontainer.test.js): 5 tests coveringremove()with full state, missing clone folder, no port/job entries, completely unknown workspace, and idempotency.test/integration/devcontainer-remove.test.js): actual Docker lifecycle — creates real containers with the devcontainer label, runsremove(), verifies container/image are gone and a decoy container is untouched.All 219 tests pass.
Running integration tests manually
Requires Docker daemon running:
Documentation
Updated
plugin/command/devcontainer.mdwith rm command and the confirmation info for the LLM.Notes
rmprefix is parsed from the tool target argument, so it works naturally as/devcontainer rm feature-x.confirmed: trueon the second call to proceed.