runAgent integration — swap mkdtemp+clone for worktree #5

Closed
opened 2026-04-16 22:44:22 +00:00 by claude-desktop · 0 comments
Collaborator

User story

As a worker, I want runAgent to acquire a persistent worktree from the workdir module instead of cloning into a fresh mkdtemp directory each task, so that Forgejo is no longer re-cloned per dispatch and worktree state carries across turns for the same (agent, branch).

Acceptance criteria

runAgent rewrite (src/main.ts)

  • Remove the mkdtemp(...) + git clone block
  • Derive the branch name deterministically from (agent.branch_prefix, issue_number) to match the skill template (e.g. boss/4-event-sourcing); document the derivation in a single helper
  • Call acquireWorktree(repo, agent, branch) to get the workdir
  • Pass the merged gitIdentityEnv(agent) + gitAuthEnv(agent) into query({ env })
  • Replace the finally { rm(workdir, ...) } block with releaseWorktree(repo, agent, branch, { keep: true })
  • Wire the cleanup webhook handlers (from the cleanup-webhooks story) so closing an issue / merging a PR triggers releaseWorktree({ keep: false }) for each agent
  • Existing git config user.name / user.email setup commands in runAgent are removed (env vars now own this)

Smoke / integration check

  • Manual: dispatch a test issue twice in succession; verify the worktree directory is reused (mtime preserved) and no fresh clone happens (Forgejo access log shows fetch only)
  • Manual: close the test issue; verify releaseWorktree({ keep: false }) runs and the directory is gone

Failure handling

  • If acquireWorktree throws, the task fails fast with a useful error in the dashboard event stream (not a silent retry loop)
  • If the agent leaves the worktree dirty (uncommitted changes, detached HEAD, etc.), the next dispatch inherits that state — log it as a warning at task start so it's visible

Out of scope

  • Session resumption (next story)
  • Periodic sweeper (later story)
  • Disk-usage observability (later story)

References

  • Discussion: chat history, "Phase 1 — runAgent integration"

Dependencies

  • Blocked by: #3 (workdir module API), #4 (cleanup hooks call into releaseWorktree)
  • Blocks: #6, #8
  • Branch off: issue-3-workdir-module (rebase #4 on top via cherry-pick, or wait for both to merge)
  • Full graph: #10
## User story As a **worker**, I want `runAgent` to acquire a persistent worktree from the workdir module instead of cloning into a fresh `mkdtemp` directory each task, so that Forgejo is no longer re-cloned per dispatch and worktree state carries across turns for the same `(agent, branch)`. ## Acceptance criteria ### `runAgent` rewrite (`src/main.ts`) - [ ] Remove the `mkdtemp(...)` + `git clone` block - [ ] Derive the branch name deterministically from `(agent.branch_prefix, issue_number)` to match the skill template (e.g. `boss/4-event-sourcing`); document the derivation in a single helper - [ ] Call `acquireWorktree(repo, agent, branch)` to get the workdir - [ ] Pass the merged `gitIdentityEnv(agent)` + `gitAuthEnv(agent)` into `query({ env })` - [ ] Replace the `finally { rm(workdir, ...) }` block with `releaseWorktree(repo, agent, branch, { keep: true })` - [ ] Wire the cleanup webhook handlers (from the cleanup-webhooks story) so closing an issue / merging a PR triggers `releaseWorktree({ keep: false })` for each agent - [ ] Existing `git config user.name` / `user.email` setup commands in `runAgent` are removed (env vars now own this) ### Smoke / integration check - [ ] Manual: dispatch a test issue twice in succession; verify the worktree directory is reused (mtime preserved) and no fresh clone happens (Forgejo access log shows fetch only) - [ ] Manual: close the test issue; verify `releaseWorktree({ keep: false })` runs and the directory is gone ### Failure handling - [ ] If `acquireWorktree` throws, the task fails fast with a useful error in the dashboard event stream (not a silent retry loop) - [ ] If the agent leaves the worktree dirty (uncommitted changes, detached HEAD, etc.), the next dispatch inherits that state — log it as a warning at task start so it's visible ## Out of scope - Session resumption (next story) - Periodic sweeper (later story) - Disk-usage observability (later story) ## References - Discussion: chat history, "Phase 1 — runAgent integration" ## Dependencies - **Blocked by:** #3 (workdir module API), #4 (cleanup hooks call into releaseWorktree) - **Blocks:** #6, #8 - **Branch off:** `issue-3-workdir-module` (rebase #4 on top via cherry-pick, or wait for both to merge) - **Full graph:** #10
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/claude-hooks#5
No description provided.