Expose workspace env vars to project hooks; run cleanup on every worktree destruction#705
Merged
Merged
Conversation
…orktree destruction Project hook scripts (setupScript / devScript / cleanupScript) now receive DEV3_PROJECT_PATH, DEV3_PROJECT_NAME, DEV3_TASK_ID, DEV3_TASK_TITLE, DEV3_WORKTREE_PATH and DEV3_BRANCH_NAME. DEV3_PROJECT_PATH is the load-bearing one: a git-ignored .dev3/config.local.json exists only at the project root, so hooks it references must be resolvable as "$DEV3_PROJECT_PATH/.dev3/<hook>.sh" from inside a fresh worktree. This mirrors the Superset workspace-hook contract (SUPERSET_ROOT_PATH / SUPERSET_WORKSPACE_NAME / SUPERSET_WORKSPACE_PATH) so tooling like the b44 CLI can drive per-worktree environments on both runners with the same scripts. The cleanup hook now fires on every worktree-destruction path, not just completed/cancelled column moves: deleting an active task runs it with DEV3_TASK_STATUS=deleted, and cancelling task preparation runs it with DEV3_TASK_STATUS=todo. Task deletion also releases allocated ports and stops the task dev server (both previously leaked). Docs updated: dev3-project-config skill (new step 3b documenting hook env vars and the git-ignored-hooks pattern) and the cleanup script description in all three locales.
88eb28f to
d45d078
Compare
h0x91b
approved these changes
Jun 27, 2026
h0x91b
left a comment
Owner
There was a problem hiding this comment.
Hey, Claude here — the AI assistant working on this branch with Arseny. Rebased onto latest main (was 27 commits behind, with conflicts in task-lifecycle.ts from the new virtual/Operations work). Resolved the conflicts to follow the same canonical teardown order main already uses in moveTask: runCleanupScript runs unconditionally (git + virtual), and only the dir removal is branched (git.removeWorktree vs managed rm). Backend suite is green (1616 passed) and lint is clean. Leaving the mainview test gate to CI. LGTM.
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.
Why
dev3's per-task git worktrees are a natural fit for per-worktree dev environments (each worktree gets its own backend/app container, ports, etc.). Tooling like Base44's
b44CLI already does this for Superset via a gitignored.superset/hook folder (config.json+setup.sh+teardown.sh) that resolves its scripts from$SUPERSET_ROOT_PATH. dev3 already has the equivalent plumbing —setupScript/cleanupScriptand root-first config resolution (.dev3/config.local.jsonat the repo root drives every worktree) — but two gaps stopped the same hooks from working here.What
1. Workspace env vars for hook scripts.
setupScript,devScript, andcleanupScript(and the agent session) now receive:DEV3_PROJECT_PATHDEV3_PROJECT_NAMEDEV3_TASK_IDDEV3_TASK_TITLEDEV3_WORKTREE_PATHDEV3_BRANCH_NAMEDEV3_PROJECT_PATHis the load-bearing one (the analog of$SUPERSET_ROOT_PATH): a gitignored.dev3/config.local.jsonand any scripts it references live only at the project root, so a fresh worktree has no copy. Referencing a hook asbash "$DEV3_PROJECT_PATH/.dev3/setup.sh"lets every worktree find it while cwd stays the worktree. (The cleanup hook already had most of these; this centralizes them via abuildTaskLifecycleEnvhelper and addsDEV3_BRANCH_NAME.)2. Cleanup hook now fires on every worktree-destruction path. Previously
cleanupScriptran only oncompleted/cancelledcolumn moves. It now also runs when:DEV3_TASK_STATUS=deletedDEV3_TASK_STATUS=todoWithout this, deleting a task or cancelling its preparation tore down the worktree silently, leaking any per-worktree resources the setup hook had created (e.g. dev containers). Task deletion now also releases allocated ports and stops the dev-server session, both of which previously leaked on that path.
Docs updated: the embedded
dev3-project-configskill gains a step documenting the hook env vars + the gitignored-hooks pattern, and the cleanup-script description is updated in all three locales.Test instructions
New unit tests cover: the
deletedtransition env, cleanup-runs-before-removeWorktree ordering on delete, cleanup-failure tolerance, port release on delete, andDEV3_BRANCH_NAMEin the cleanup env.