refactor(session): make cmd_continue idempotent with ensure_* functions #230

Merged
shoko merged 1 commits from fix/issue-168 into main 2026-04-08 00:32:16 +02:00
Owner

Summary

Simplify kugetsu by making cmd_continue the main entry point for session/worktree management. Extract reusable functions so cmd_start becomes a thin wrapper and the daemon can always call cmd_continue without existence checks.

Changes

  • Add ensure_worktree() - creates worktree if missing, returns status
  • Add ensure_session() - creates session if missing, handles inconsistent states
  • Add fork_agent() - extracted agent forking logic
  • Refactor cmd_continue() to use ensure_* functions (idempotent)
  • Make cmd_start() a thin wrapper calling cmd_continue()
  • Simplify daemon to always call cmd_continue (no existence check)

Closes #168

## Summary Simplify kugetsu by making `cmd_continue` the main entry point for session/worktree management. Extract reusable functions so `cmd_start` becomes a thin wrapper and the daemon can always call `cmd_continue` without existence checks. ## Changes - Add `ensure_worktree()` - creates worktree if missing, returns status - Add `ensure_session()` - creates session if missing, handles inconsistent states - Add `fork_agent()` - extracted agent forking logic - Refactor `cmd_continue()` to use ensure_* functions (idempotent) - Make `cmd_start()` a thin wrapper calling `cmd_continue()` - Simplify daemon to always call cmd_continue (no existence check) Closes #168
shoko added 1 commit 2026-04-08 00:26:21 +02:00
- Add ensure_worktree() - creates worktree if missing, returns status
- Add ensure_session() - creates session if missing, handles inconsistent states
- Add fork_agent() - extracted agent forking logic
- Refactor cmd_continue() to use ensure_* functions (idempotent)
- Make cmd_start() a thin wrapper calling cmd_continue()
- Simplify daemon to always call cmd_continue (no existence check)

This makes cmd_continue truly idempotent - it will:
- Continue existing session if it exists
- Create session and worktree if they don't exist
- Clean and recreate if state is inconsistent

Closes #168
han approved these changes 2026-04-08 00:31:11 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko merged commit b09fe8eabc into main 2026-04-08 00:32:16 +02:00
Sign in to join this conversation.