Switch-Hook Lifecycle, Persistent Terminal Sessions and Worktree Creation UX#23
Conversation
…the hooks and terminals
|
@copilot please address & fix the failing check on this PR |
There was a problem hiding this comment.
Pull request overview
This PR extends SproutGit’s hook and terminal infrastructure to support richer worktree-switch hook behavior (once-per-session + per-context auto-run), passes hook environment variables as structured data, and improves worktree creation UX while making terminal sessions more persistent across UI state changes.
Changes:
- Add switch-hook options (
switchOncePerSession,switchRunOnCreate,switchRunOnDelete) with new workspace DB migrations and a new backend command to run switch hooks with source context. - Introduce terminal session persistence primitives (frontend cache + PTY reattach support) and pass
envVarsthrough the hook-terminal-launch event into terminal spawning. - Refine workspace UI flows: creation placeholder row/spinner, watcher + Changes view suspension to avoid Windows races, modal autofocus, and updated reveal behavior; update E2E selectors accordingly.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/routes/workspace/+page.svelte | Worktree creation placeholder UX, watcher/Changes gating during create, switch-hook execution on load/create/delete, and terminal lifecycle changes. |
| src/routes/+layout.svelte | Applies a global “autocomplete=off” policy to form/text-like inputs via focus + DOM mutation observation. |
| src/lib/workspace-terminals.svelte.ts | Adds a global per-workspace terminal snapshot store (active tab/path, initialized paths, launch requests). |
| src/lib/terminal-session-cache.svelte.ts | Adds an in-memory cache for TerminalContainer sessions/layout keyed by CWD. |
| src/lib/sproutgit.ts | Extends hook/terminal types to include switch-hook flags and hook terminal envVars; adds runWorktreeSwitchHooks and closeTerminalsForPath. |
| src/lib/components/WorkspaceHooksModal.svelte | UI and form normalization for new switch-hook flags; displays badges for these settings. |
| src/lib/components/ToastContainer.svelte | Moves toast stack to bottom-left. |
| src/app.css | Adjusts toast slide animations to match new toast position/direction. |
| src/lib/components/TerminalPanel.svelte | Adds env var support, PTY reattach, optional “preserve on unmount”, and retry for initial command send. |
| src/lib/components/TerminalContainer.svelte | Persists/restores session state, tracks PTY ids, improves add-session UX, and supports env vars per session. |
| src/lib/components/TerminalDock.svelte | New global dock concept for rendering terminal containers across workspaces (not yet wired in). |
| src-tauri/src/terminal.rs | Adds validated env var injection to terminal spawn; tracks initial CWD per PTY; adds close_terminals_for_path. |
| src-tauri/src/lib.rs | Registers new Tauri commands (run_worktree_switch_hooks, close_terminals_for_path). |
| src-tauri/src/hooks.rs | Adds switch-hook flags, once-per-session gating, source-aware filtering, structured env_vars in terminal launch events, and run_worktree_switch_hooks. |
| src-tauri/src/git/operations.rs | Improves Windows worktree delete robustness with fs fallback and clears once-per-session switch-hook keys on delete. |
| src-tauri/src/editor.rs | Returns a friendly editor display name instead of the raw command string. |
| src-tauri/src/db.rs | Registers workspace migrations 006/007 for new hook columns. |
| src-tauri/migrations/workspace/006_hook_switch_once_per_session.sql | Adds switch_once_per_session column with safe default. |
| src-tauri/migrations/workspace/007_hook_switch_auto_run_contexts.sql | Adds switch_run_on_create / switch_run_on_delete columns with safe defaults. |
| e2e/specs/daily-workflow.spec.ts | Updates assertions/selectors to match new terminal tab labeling and removal of the operation header. |
Addressed in commit Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot apply changes based on the comments AND RESPONSES in this thread |
Implemented in Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Switch-Hook Lifecycle, Persistent Terminal Sessions, and Worktree Creation UX
This PR introduces three related improvements: richer worktree-switch hook behaviour, persistent terminal sessions that survive tab switches, and a more polished worktree creation flow.
Switch Hook Enhancements
Switch hooks (
before_worktree_switch/after_worktree_switch) gain two new options:switchOncePerSession): when enabled, the hook fires the first time you switch to a given worktree in an app session and is skipped on subsequent switches. A global in-memory set tracks which(workspace, trigger, hook, worktree)keys have already fired; the key is cleared when the worktree is deleted.switchRunOnCreate/switchRunOnDelete): controls whether the hook fires automatically as part of worktree creation or deletion flows, independently of the once-per-session gate.Switch hooks are also now executed at workspace load for the initially-active worktree (using the
'load'source, which always bypasses the once-per-session guard), and after worktree creation (using'create', which respectsswitchRunOnCreate).Two new workspace DB migrations (006, 007) add the backing columns with safe defaults so existing hook definitions continue working unchanged.
Persistent Terminal Sessions
TerminalContainernow writes its session list, active session ID, and layout to a per-CWD cache (terminal-session-cache.svelte.ts) and restores it on mount. Sessions are no longer torn down when you switch worktrees — switching back to a worktree resumes exactly where you left it. A newworkspace-terminals.svelte.tsmodule manages global per-workspace terminal state (active tab, active terminal path, initialized paths, pending launch requests) so that state is consistent across page-level re-renders.The layout also auto-promotes to grid when two or more hook sessions are active in the same container.
Hook environment variables are now passed as a structured
envVarsmap in thehook-terminal-launchevent (rather than inlined as shell assignments inside the command string), which decouples env injection from command construction and prevents quoting issues across shells.Worktree Creation UX
git status/index.lockraces on Windows.tick()).revealItemInDirinstead ofopenPath.open_in_editorreturns a human-readable editor name instead of the raw command string.Windows Robustness
delete_managed_worktreenow falls back tostd::fs::remove_dir_allon Windows whengit worktree remove --forcefails with "Permission denied", then letsgit worktree pruneclean up the leftover metadata. This handles the case where a file watcher or shell process is still holding a handle to the directory.closeAllTerminalsis replaced withcloseTerminalsForPathso teardown is scoped to a specific worktree path rather than killing all sessions globally.Release Notes
This release adds smarter worktree-switch hook controls, persistent terminal sessions, and a smoother worktree creation experience.
Run once per session), avoiding repeated setup scripts when toggling between worktreesgit worktree remove