Skip to content

Commit adf9222

Browse files
fix(hooks): sync routed tracked worktree branches
1 parent 6c76410 commit adf9222

3 files changed

Lines changed: 44 additions & 10 deletions

File tree

src/daemon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ mod tests {
24282428
let (stream, _addr) = listener.accept().await.expect("accept daemon client");
24292429
let engine = engine.clone();
24302430
tasks.push(tokio::spawn(async move {
2431-
super::serve_socket_client(stream, engine)
2431+
Box::pin(super::serve_socket_client(stream, engine))
24322432
.await
24332433
.expect("serve proxied client");
24342434
}));

src/mcp/hook_events.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ pub(crate) struct HookEvent {
5252
pub(crate) enum HookEventPlan {
5353
SyncFiles(Vec<String>),
5454
AddBranch(String),
55-
AddBranchAt { root: PathBuf, branch: String },
56-
SyncCurrentBranch { branch: String, agent: HookAgent },
55+
AddBranchAt {
56+
root: PathBuf,
57+
branch: String,
58+
agent: HookAgent,
59+
},
60+
SyncCurrentBranch {
61+
branch: String,
62+
agent: HookAgent,
63+
},
5764
DebouncedIncrementalSync(HookAgent),
5865
Noop,
5966
}
@@ -153,14 +160,15 @@ fn plan_shell_hook_event(
153160
};
154161
match crate::hooks::cursor_shell_sync_plan_with_current_branch(command, current_branch) {
155162
crate::hooks::CursorShellSyncPlan::BranchAdd(branch) => {
156-
branch_plan_for_root(project_root, hook_project_root, branch)
163+
branch_plan_for_root(project_root, hook_project_root, branch, event.agent)
157164
}
158165
crate::hooks::CursorShellSyncPlan::WorktreeBranchAdd {
159166
branch,
160167
worktree_path,
161168
} => HookEventPlan::AddBranchAt {
162169
root: crate::hooks::resolve_worktree_add_root(command, cwd, &worktree_path),
163170
branch,
171+
agent: event.agent,
164172
},
165173
crate::hooks::CursorShellSyncPlan::IncrementalSync => {
166174
HookEventPlan::DebouncedIncrementalSync(event.agent)
@@ -175,6 +183,7 @@ fn plan_shell_hook_event(
175183
HookEventPlan::AddBranchAt {
176184
root: hook_project_root,
177185
branch,
186+
agent: event.agent,
178187
}
179188
}
180189
}
@@ -203,13 +212,15 @@ fn branch_plan_for_root(
203212
project_root: &Path,
204213
hook_project_root: PathBuf,
205214
branch: String,
215+
agent: HookAgent,
206216
) -> HookEventPlan {
207217
if paths_same(&hook_project_root, project_root) {
208218
HookEventPlan::AddBranch(branch)
209219
} else {
210220
HookEventPlan::AddBranchAt {
211221
root: hook_project_root,
212222
branch,
223+
agent,
213224
}
214225
}
215226
}
@@ -320,14 +331,20 @@ mod tests {
320331
}
321332

322333
fn assert_add_branch_at(plan: HookEventPlan, expected_root: &Path, expected_branch: &str) {
323-
let HookEventPlan::AddBranchAt { root, branch } = plan else {
334+
let HookEventPlan::AddBranchAt {
335+
root,
336+
branch,
337+
agent,
338+
} = plan
339+
else {
324340
panic!("expected AddBranchAt plan, got {plan:?}");
325341
};
326342
assert!(
327343
super::paths_same(&root, expected_root),
328344
"planned root {root:?} should match expected root {expected_root:?}"
329345
);
330346
assert_eq!(branch, expected_branch);
347+
assert_eq!(agent, HookAgent::Codex);
331348
}
332349

333350
fn write_project_marker(root: &Path) {
@@ -543,6 +560,7 @@ mod tests {
543560
HookEventPlan::AddBranchAt {
544561
root: Path::new("/tmp/wt").to_path_buf(),
545562
branch: "feature/daemon-hooks".to_string(),
563+
agent: HookAgent::Codex,
546564
}
547565
);
548566
}
@@ -576,6 +594,7 @@ mod tests {
576594
HookEventPlan::AddBranchAt {
577595
root: base_root.join("wt"),
578596
branch: "feature/daemon-hooks".to_string(),
597+
agent: HookAgent::Codex,
579598
}
580599
);
581600
}

src/mcp/server.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,14 +1708,29 @@ impl McpServer {
17081708
Err(e) => eprintln!("[tracedecay] hook branch tracking failed: {e}"),
17091709
}
17101710
}
1711-
HookEventPlan::AddBranchAt { root, branch } => {
1712-
// The new worktree root is not this server's checkout, so no
1713-
// reopen or token-map refresh applies here (unlike AddBranch);
1714-
// branch tracking against the shared store is the whole job.
1711+
HookEventPlan::AddBranchAt {
1712+
root,
1713+
branch,
1714+
agent,
1715+
} => {
1716+
// The routed worktree root is not this server's checkout, so
1717+
// reopen/token-map refresh only applies after opening that root.
17151718
match self.add_hook_branch_tracking(&root, &branch, &cg).await {
1719+
Ok(crate::branch::BranchAddOutcome::AlreadyTracked) => {
1720+
match TraceDecay::open_with_options(&root, cg.open_options()).await {
1721+
Ok(worktree_cg) => {
1722+
self.run_hook_incremental_sync(Arc::new(worktree_cg), agent)
1723+
.await;
1724+
}
1725+
Err(e) => {
1726+
eprintln!(
1727+
"[tracedecay] hook worktree branch sync open failed: {e}"
1728+
);
1729+
}
1730+
}
1731+
}
17161732
Ok(
17171733
crate::branch::BranchAddOutcome::Added
1718-
| crate::branch::BranchAddOutcome::AlreadyTracked
17191734
| crate::branch::BranchAddOutcome::Deferred
17201735
| crate::branch::BranchAddOutcome::NotIndexed,
17211736
) => {}

0 commit comments

Comments
 (0)