Commit Graph
1 Commits
Author SHA1 Message Date
Mohamed Boudra d154df3165 Let plugins manage worktree creation, removal, and restoration (#10278)
* feat(plugins): let plugins manage worktree create, remove, and restore

Adds server.registerWorktreeManager({ create, remove?, restore? }) so external worktree tools such as Worktrunk can own Git worktree creation, removal, and restoration instead of overloading worktree.create.before.

Keeping worktree.create.before purely transformative preserves multi-plugin chaining, rollback, and the 30s hook budget, while giving manager operations a 120s budget matching git worktree commands. Paseo snapshots existing worktrees before create so managers cannot hijack pre-existing user worktrees, writes comparison-base and owning plugin metadata into paseo/worktree.json and the workspace record, saves refs/paseo/kept-commits before removal so restore stays safe, and falls back to built-in Git if a manager declines or is disabled.

* fix(plugins): harden worktree manager lifecycle, rollback, and schema

* fix(plugins): pass untrusted on create, clean up rejected worktrees, and sync docs

* refactor(plugins): unify worktree manager checkout flow and metadata rules

* fix(plugins): verify managed worktree ownership and restore targets

A failed callback does not establish ownership of worktrees created during its call. Require the manager to identify the checkout before Paseo attempts rollback, and verify the requested Git target before reopening a restored workspace.

* fix(plugins): preserve worktree setup on retry and refresh branch bases

A failed setup could leave a new branch behind and send the retry through the built-in checkout. Use the manager's reported branch creation status during rollback. Share base preparation so both checkout paths start from the updated remote-tracking ref.

* fix(plugins): preserve managed checkout targets and rollback

Keep branch creation ownership with the linked checkout so a failed after-hook can be retried with the same branch. Leave same-repository change requests with a local branch collision to the checkout path that fetches the change request head. Use the worktree timeout for compatibility commands.

* fix(worktrees): carry source trust and await managed creation

Preserve fork provenance for manager callbacks and the workspace record. Honor tracking branch creation in the manager example and let the CLI wait on the existing workspace creation lifecycle.

* fix(plugins): verify PR head commits, restore CLI worktree RPC, and fix Windows rollback paths

* fix(plugins): pre-resolve PR head, use NUL worktree snapshots, and wait on CLI worktree create

* fix(plugins): unify worktree list reader with Git 2.35 fallback and fetch PR head once

* fix(plugins): require exact worktree snapshot for managers and configure PR push remotes on adoption

* fix(server): coordinate workspace restores across daemon sessions

* fix(server): coordinate archive, undo, and restore across daemon checkout boundary

* fix: serialize open-project with checkout archive, sync sibling owners, lift client timeouts, bump plugin version

* fix: forbid nested secondary worktrees, preserve nested checkouts on archive, wait on openProject

* fix(server): refuse deleting a worktree containing a live nested Git worktree

* test(server): normalize Windows paths and teardown command in worktree-manager E2E

* fix(server): guard cross-repo nested checkouts on delete and share checkout trust across sibling workspaces

* fix(worktrees): scope nested checkout protection to managed worktrees

The removal scan treated dependency clones and recursive submodules as independent worktrees. Identify linked worktrees through Git metadata and use the scan only for manager-owned removals.

* test(worktrees): accept native line endings in archive fixtures

The nested submodule fixture checks that Git populated the checkout. The README line endings depend on the runner's Git configuration.

* docs(plugins): document the example manager Git requirement

* fix(worktrees): name the manager that returns an invalid path

The destination validator serves both creation hooks and managers. Keep its errors about the path so the caller can identify the plugin and operation.
2026-11-21 13:51:28 +07:00