Worktree lifecycle management with PR check #135

Closed
opened 2026-04-05 04:35:45 +02:00 by shoko · 0 comments
Owner

Overview

Improve worktree lifecycle management to persist worktrees until PR is merged/closed, not just when session ends.

Problem

Currently:

  • Worktrees are created in cmd_start
  • Worktrees are destroyed in cmd_destroy or prune
  • Worktree lifecycle is tied to session, not task completion

This causes issues when:

  • Session is destroyed mid-task but PR is still active
  • Parallel agents work on same issue accidentally overwrite each other

Requirements

Session File Enhancement

Add pr_url and branch_name fields to session files at ~/.kugetsu/sessions/<issue-ref>.json:

{
  "type": "forked",
  "issue_ref": "github.com/shoko/kugetsu#14",
  "opencode_session_id": "ses_xyz",
  "worktree_path": "~/.kugetsu/worktrees/...",
  "created_at": "2026-03-29T18:16:10+02:00",
  "state": "idle",
  "pr_url": "https://git.fbrns.co/shoko/kugetsu/pulls/123",
  "branch_name": "fix/issue-14"
}

PR Status Check

kugetsu destroy <issue> without force flag:

  1. Read session file to get pr_url
  2. Check PR status via Gitea API
  3. If PR is open/active: refuse to destroy, show error
  4. If PR is merged/closed: proceed with worktree removal

kugetsu destroy <issue> --force:

  • Bypass PR check, destroy worktree anyway

New Config

# PR status check before destroy (default: true)
WORKTREE_CHECK_PR_STATUS=true

API Integration

Need to determine git server from issue ref and query PR status. Gitea API example:

GET /repos/{owner}/{repo}/pulls/{index}
Response: {"state": "open", "merged": false, ...}
## Overview Improve worktree lifecycle management to persist worktrees until PR is merged/closed, not just when session ends. ## Problem Currently: - Worktrees are created in `cmd_start` - Worktrees are destroyed in `cmd_destroy` or `prune` - Worktree lifecycle is tied to session, not task completion This causes issues when: - Session is destroyed mid-task but PR is still active - Parallel agents work on same issue accidentally overwrite each other ## Requirements ### Session File Enhancement Add `pr_url` and `branch_name` fields to session files at `~/.kugetsu/sessions/<issue-ref>.json`: ```json { "type": "forked", "issue_ref": "github.com/shoko/kugetsu#14", "opencode_session_id": "ses_xyz", "worktree_path": "~/.kugetsu/worktrees/...", "created_at": "2026-03-29T18:16:10+02:00", "state": "idle", "pr_url": "https://git.fbrns.co/shoko/kugetsu/pulls/123", "branch_name": "fix/issue-14" } ``` ### PR Status Check `kugetsu destroy <issue>` without force flag: 1. Read session file to get `pr_url` 2. Check PR status via Gitea API 3. If PR is open/active: refuse to destroy, show error 4. If PR is merged/closed: proceed with worktree removal `kugetsu destroy <issue> --force`: - Bypass PR check, destroy worktree anyway ### New Config ```bash # PR status check before destroy (default: true) WORKTREE_CHECK_PR_STATUS=true ``` ### API Integration Need to determine git server from issue ref and query PR status. Gitea API example: ``` GET /repos/{owner}/{repo}/pulls/{index} Response: {"state": "open", "merged": false, ...} ``` ## Related Issues - Meta issue: #133
han was assigned by shoko 2026-04-05 04:45:01 +02:00
shoko added this to the v0.1.0 milestone 2026-04-05 04:45:01 +02:00
shoko closed this issue 2026-04-05 06:00:15 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/kugetsu#135