Support worktree-based workflows via session-path targeting#118
Support worktree-based workflows via session-path targeting#118danielstarman wants to merge 1 commit intomodem-dev:mainfrom
Conversation
95c52e4 to
c0d8ffe
Compare
Greptile SummaryThis PR adds first-class worktree support to Hunk's session-targeting model by introducing Key changes:
One issue was found: the fallback error message in Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as CLI (hunk session reload)
participant SC as session/commands.ts
participant HTTP as HTTP Daemon API
participant DS as daemonState.ts
participant WS as WebSocket → TUI
participant APP as App.tsx (reloadSession)
participant LDR as loaders.ts (loadAppBootstrap)
CLI->>CLI: resolveReloadSelector(sessionId?, sessionPath?, repoRoot?, source?)
note right of CLI: produces { selector, sourcePath }
CLI->>SC: runSessionCommand({ selector: {sessionPath}, sourcePath, nextInput })
SC->>SC: normalizeSessionSelector (resolve paths)
SC->>HTTP: POST /session-api { action:"reload", selector, sourcePath, nextInput }
HTTP->>DS: sendReloadSession({ sessionPath, sourcePath, nextInput })
DS->>DS: resolveSessionTarget → match session.cwd === sessionPath
DS->>WS: send { command:"reload_session", input:{ sourcePath, nextInput } }
WS->>APP: reloadIncomingSession({ sourcePath, nextInput })
APP->>APP: resolveConfiguredCliInput(nextInput, { cwd: sourcePath })
APP->>LDR: loadAppBootstrap(configuredInput, { cwd: sourcePath })
LDR->>LDR: resolveGitRepoRoot / runGitText with cwd=sourcePath
LDR-->>APP: AppBootstrap (changeset from source repo)
APP-->>WS: ReloadedSessionResult
WS-->>HTTP: command-result
HTTP-->>SC: { result: ReloadedSessionResult }
SC-->>CLI: formatted output
|
Add sessionPath as a new session selector that matches on the TUI cwd, and sourcePath on reload to load diffs from a different directory than the session own. This enables worktree-first workflows where agents work in isolated worktrees while the reviewer runs hunk elsewhere. - sessionPath selector threaded through daemon state, commands, and CLI - --session-path and --source as distinct CLI flags on reload - cwd parameter threaded through the loader chain for cross-directory reloads - Tests across CLI parsing, daemon state, server, session commands, and loaders Closes modem-dev#95
c0d8ffe to
7c5c4e7
Compare
|
@danielstarman Thanks for submitting this. I'm going to need time to review/parse it, but I'll get to it. |
Following up on #95. I use a worktree-first workflow where agents work in isolated worktrees while I review from a separate terminal. Session matching by
repoRootbreaks here because each worktree has a different path.My first attempt used
git rev-parse --git-common-dirto resolve all worktrees to a shared root. It worked for my setup, but session resolution gets messy when multiple sessions are open against the same repo, which is exactly the scenario worktrees enable.So I went a different direction: target sessions by their working directory (
--session-path) and provide a separate--sourceflag for reload to specify where the diff comes from. This keeps each selector unambiguous regardless of how many sessions are open.What is here:
sessionPathas a new session selector (matches on the TUI cwd)sourcePathon reload (load diff from a different directory than the session own)--session-pathand--sourceas distinct CLI flags (no overloading of--repo)cwdthreaded through the loader chain so reloads resolve files from the source directoryHappy to adjust the approach if you have a different direction in mind.