Fix Windows task path handling for worktree variables with spaces (#55727)

## Summary
Fixes task variable resolution and Windows shell argument handling when
`$ZED_WORKTREE_ROOT` contains spaces or when tasks are spawned while the
global `tasks.json` buffer is focused.

## Problem
`$ZED_WORKTREE_ROOT` could resolve from the active editor item even when
that item was outside every visible project worktree, such as the global
`tasks.json` file under the Zed config directory. On Windows, paths with
spaces also need to remain one logical argument when terminal shell
commands are constructed.

## Changes
- Only let the active editor item provide the active task context when
it belongs to a visible project worktree.
- Fall back to the selected or first visible project worktree when the
active editor item is external/global.
- Preserve project-file-specific task variables for normal project
buffers.
- Add regression coverage for `$ZED_WORKTREE_ROOT` in `args` and `cwd`
with synthetic Windows-style paths containing spaces.
- Add regression coverage for PowerShell and cmd shell command
construction so a spaced path remains quoted as one shell argument.

## Testing
Ran on Windows with Rust 1.95.0, Visual Studio Build Tools 2022, and
Windows SDK 10.0.26100.0:

- `cargo fmt --all --check`
- `cargo test -p util
shell_builder::test::windows_powershell_preserves_spaced_arg_as_single_shell_argument
-- --exact`
- `cargo test -p util
shell_builder::test::windows_cmd_preserves_spaced_arg_as_single_shell_argument
-- --exact`
- `cargo test -p task
task_template::tests::test_worktree_root_with_spaces_stays_atomic_in_args_and_cwd
-- --exact`
- `cargo test -p tasks_ui
tests::test_non_project_active_editor_uses_visible_worktree_context --
--exact`
- `cargo test -p task`
- `cargo test -p tasks_ui`
- `cargo test -p workspace`

Release Notes:

- Fix Windows task path handling for worktree variables with spaces
- [GPUI] N/A

Co-authored-by: Chris Biscardi <chris@christopherbiscardi.com>
01448f565eIndy Fu committed on 9/19/2026, 1:57:44 AM· committed by GitHubparentc982733
3 files changedLine totals unavailable