feat(kugetsu): add lock mechanism for worktree coordination #90

Closed
shoko wants to merge 1 commits from feat/issue-71-lock-mechanism into main

1 Commits

Author SHA1 Message Date
shokollm
3fa9bee166 feat(kugetsu): add lock mechanism for worktree coordination
Add lock mechanism to prevent concurrent access to worktrees:

- Add LOCKS_DIR constant (\~/.kugetsu/locks)
- Add acquire_lock() - acquires lock file with PID, session_id, timestamp
- Add release_lock() - releases lock if held by current process
- Add release_all_locks() - releases all locks for a session
- Add check_lock() - check if issue is locked
- Modify cmd_start to acquire lock before creating worktree
- Modify cmd_destroy to release lock when destroying session
- Add trap for cleanup on EXIT/INT/TERM

Lock files are named after issue ref with format:
  <issue-ref>.lock
Contains: PID:session_id:timestamp

Stale lock detection: if PID no longer exists, lock is considered stale.

This prevents concurrent processes from modifying the same worktree.

Fixes #71
2026-04-01 23:26:22 +00:00