From 479e2c1b5b9efeeeb0effb35a7b6d37b83ae8e57 Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 29 Nov 2026 13:40:38 -0800 Subject: [PATCH] feat(container): ask every container to clean up test artifacts and build caches The host's Docker daemon is shared and never pruned for the user. Leftover test images, build cache and language caches from finished work reached ~1.35 TB on one machine (one home volume held 258 GB of go-build cache). Add a built-in CLEANUP_INSTRUCTIONS section, appended to every container's CLAUDE.md like the file-link section, naming what to clean and the app's own resources (triple-c-* containers, snapshot/sandbox images, home/config volumes) that must never be touched. Part of the instructions fingerprint, so each container is recreated once on its next start. Co-Authored-By: Claude Opus 5.5 --- app/src-tauri/src/docker/container.rs | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/app/src-tauri/src/docker/container.rs b/app/src-tauri/src/docker/container.rs index 220bd04..3d7e5e8 100644 --- a/app/src-tauri/src/docker/container.rs +++ b/app/src-tauri/src/docker/container.rs @@ -136,6 +136,26 @@ const FILE_LINK_INSTRUCTIONS: &str = r#"## Referring to files The user can click a file path in this terminal to open it in a viewer (while a program holds the mouse: Shift+click, or Option+click on macOS). Paths relative to the project work. When you mention a file outside the project (for example in `/tmp`, including your scratchpad directory, or under `~`), print its full absolute path, not a shortened or relative one, so it can be opened."#; +/// Every container talks to the host's Docker daemon, which is shared with the +/// user's other projects and is never pruned for them. Test images, build cache +/// and language build caches left behind by finished work were measured at +/// well over a terabyte on one machine (a single home volume held 258 GB of +/// `go-build` cache), so every container is asked to clean up after itself. +/// The keep-list names what the app itself depends on so the cleanup never +/// reaches a project's container, snapshot or saved files. Part of the +/// instructions fingerprint, so adding or changing it recreates each container +/// once on its next start. +const CLEANUP_INSTRUCTIONS: &str = r#"## Cleaning up after yourself + +The Docker daemon reachable through `/var/run/docker.sock` belongs to the host. It is shared with the user's other projects, and nothing prunes it automatically, so leftovers from finished work fill the user's disk. When a piece of work is done (tests passed, the PR is open, or the experiment is over): + +- **Docker test artifacts:** remove the containers, images, volumes and networks you created for tests or experiments (`docker rm -f`, `docker rmi`, `docker volume rm`, `docker network rm`). Give test images and containers a recognisable name when you create them so they are easy to find afterwards. +- **Build cache:** after Docker builds, run `docker builder prune -f`; remove any buildx builder you created with `docker buildx rm NAME`. +- **Language build caches:** clear caches the work grew that are no longer needed, such as `go clean -cache`, `cargo clean` in throwaway checkouts, and `npm cache clean --force`. +- **Worktrees and temp files:** remove finished git worktrees (`git worktree remove`) and delete temporary files you wrote. + +Never remove what Triple-C itself depends on: `triple-c-*` containers, `triple-c-snapshot-*` and `triple-c-sandbox` images, and `triple-c-home-*` / `triple-c-claude-config-*` volumes. Don't remove anything you did not create; if you are unsure whether something is yours, ask the user first. If this container has no Docker access, the Docker items do not apply."#; + /// Build the full CLAUDE_INSTRUCTIONS value by merging global + project /// instructions, appending port mapping docs, and appending scheduler docs. /// Used by both create_container() and container_needs_recreation() to ensure @@ -180,6 +200,11 @@ pub(super) fn build_claude_instructions( None => FILE_LINK_INSTRUCTIONS.to_string(), }); + combined = Some(match combined { + Some(existing) => format!("{}\n\n{}", existing, CLEANUP_INSTRUCTIONS), + None => CLEANUP_INSTRUCTIONS.to_string(), + }); + if sandbox_enabled { combined = Some(match combined { Some(existing) => format!("{}\n\n{}", existing, SANDBOX_INSTRUCTIONS), @@ -3979,6 +4004,28 @@ mod tests { assert!(FILE_LINK_INSTRUCTIONS.contains("Option+click on macOS")); } + /// The host's daemon is shared and never pruned for the user, so every + /// container is asked to clean up its test artifacts and build caches — + /// and told which of the app's own resources it must never touch. + #[test] + fn every_container_is_asked_to_clean_up_and_to_spare_the_apps_own_resources() { + for (global, project, sandbox) in [(None, None, false), (Some("g"), Some("p"), true)] { + let s = build_claude_instructions(global, project, &[], false, sandbox).unwrap(); + assert!(s.contains(CLEANUP_INSTRUCTIONS), "{:?}", (global, project, sandbox)); + } + for needle in [ + "docker builder prune", + "go clean -cache", + "git worktree remove", + "triple-c-snapshot-*", + "triple-c-home-*", + "triple-c-claude-config-*", + "did not create", + ] { + assert!(CLEANUP_INSTRUCTIONS.contains(needle), "missing {needle}"); + } + } + fn aliases(model: Option<&str>, haiku: Option<&str>) -> Vec<(&'static str, String)> { compute_model_aliases(model, haiku) }