Skip to content

fix: improve implicit queue path resolution in worktrees - #2

Merged
DerekStride merged 2 commits into
mainfrom
worktree-aware
Mar 17, 2026
Merged

fix: improve implicit queue path resolution in worktrees#2
DerekStride merged 2 commits into
mainfrom
worktree-aware

Conversation

@DerekStride

@DerekStride DerekStride commented Mar 15, 2026

Copy link
Copy Markdown
Owner

Summary

This changes implicit queue path resolution to follow git worktree semantics instead of treating the default queue path as purely cwd-relative.

Resolution order is now:

  1. respect --queue exactly
  2. respect SQ_QUEUE_PATH exactly
  3. otherwise, if inside a git worktree, search upward from the current directory to the current worktree root for the nearest existing .sift/issues.jsonl
  4. if none exists in the current worktree and this is a linked worktree (git-dir != git-common-dir), mirror that same upward search in the main worktree
  5. if still none exists, fall back to <cwd>/.sift/issues.jsonl
  6. outside git, fall back to .sift/issues.jsonl under the current directory

Why

The old default of .sift/issues.jsonl worked like a cwd-relative path. That caused two problems:

  • running sq from a nested directory could accidentally create a new queue instead of finding an existing project or subproject queue
  • in linked git worktrees, the intended queue may exist in the main worktree while being absent from the linked checkout

Implementation notes

  • queue resolution logic was separated from git command execution so the behavior is testable as pure path-selection logic
  • git shelling remains only in the thin adapter that gathers:
    • --show-toplevel
    • --git-dir
    • --git-common-dir
  • the lookup behavior itself is now covered by unit tests instead of integration tests that shell out to real git

Examples

Simple linked-worktree example

Consider:

  • main worktree root: /projects/sq
  • linked worktree root: /projects/sq.feature
  • cwd: /projects/sq.feature
  • existing queue: /projects/sq/.sift/issues.jsonl

sq first checks the linked worktree itself:

  • /projects/sq.feature/.sift/issues.jsonl

If that file does not exist, it mirrors the cwd into the main worktree and checks:

  • /projects/sq/.sift/issues.jsonl

Since that queue exists, sq uses /projects/sq/.sift/issues.jsonl.

Example: Nested Directories

For linked worktrees, git rev-parse --git-dir and git rev-parse --git-common-dir distinguish whether the current checkout is the main worktree or a linked one.

Consider:

  • current worktree root: /trees/feature
  • main worktree root: /repo
  • cwd: /trees/feature/src/packages/alpha/client

First, sq searches upward in the current worktree for the nearest existing queue:

  • /trees/feature/src/packages/alpha/client/.sift/issues.jsonl
  • /trees/feature/src/packages/alpha/.sift/issues.jsonl
  • /trees/feature/src/packages/.sift/issues.jsonl
  • /trees/feature/src/.sift/issues.jsonl
  • /trees/feature/.sift/issues.jsonl

That covers the nested-directory case: if a narrower queue already exists in the current worktree, it will be found and used.

If none of those exist and this is a linked worktree, sq mirrors the relative path src/packages/alpha/client into the main worktree and performs the same upward search there:

  • /repo/src/packages/alpha/client/.sift/issues.jsonl
  • /repo/src/packages/alpha/.sift/issues.jsonl
  • /repo/src/packages/.sift/issues.jsonl
  • /repo/src/.sift/issues.jsonl
  • /repo/.sift/issues.jsonl

If /repo/src/packages/.sift/issues.jsonl exists, that file is used.

If nothing exists in either place, sq falls back to the current working directory:

  • /trees/feature/src/packages/alpha/client/.sift/issues.jsonl

@DerekStride
DerekStride merged commit 489f03a into main Mar 17, 2026
1 check passed
@DerekStride
DerekStride deleted the worktree-aware branch March 17, 2026 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant