feat(kugetsu): implement issue-driven session management #15

Merged
shoko merged 7 commits from feat/issue-14-session-management into main 2026-03-30 05:13:10 +02:00
Owner

Summary

Implements issue-driven session management for kugetsu based on Issue #14 research findings.

Changes

  • New storage format: Directory files + index.json for O(1) issue lookups
  • New commands: init, start, continue, list, prune, destroy
  • Issue ref format: instance/user/repo#number (e.g., github.com/shoko/kugetsu#14)

Architecture

  • Base session created once via TUI (requires TTY)
  • Per-issue forked sessions via opencode run --fork --session <base> (headless)
  • Issue-to-session mapping stored in index.json

Commands

Command Description
kugetsu init [--force] Create base session via TUI
kugetsu start <issue-ref> <msg> Fork from base for issue
kugetsu continue <issue-ref> <msg> Continue forked session
kugetsu list List all tracked sessions
kugetsu prune [--force] Remove orphaned sessions
kugetsu destroy <issue-ref> [-y] Delete issue session
kugetsu destroy --base [-y] Delete base session

Testing Plan

  • Test kugetsu init (requires TTY)
  • Test kugetsu start from headless environment
  • Test kugetsu continue on existing forked session
  • Test kugetsu list output
  • Test kugetsu prune orphaned cleanup
  • Test kugetsu destroy

Closes #14

## Summary Implements issue-driven session management for kugetsu based on Issue #14 research findings. ### Changes - **New storage format**: Directory files + index.json for O(1) issue lookups - **New commands**: `init`, `start`, `continue`, `list`, `prune`, `destroy` - **Issue ref format**: `instance/user/repo#number` (e.g., `github.com/shoko/kugetsu#14`) ### Architecture - Base session created once via TUI (requires TTY) - Per-issue forked sessions via `opencode run --fork --session <base>` (headless) - Issue-to-session mapping stored in `index.json` ### Commands | Command | Description | |---------|-------------| | `kugetsu init [--force]` | Create base session via TUI | | `kugetsu start <issue-ref> <msg>` | Fork from base for issue | | `kugetsu continue <issue-ref> <msg>` | Continue forked session | | `kugetsu list` | List all tracked sessions | | `kugetsu prune [--force]` | Remove orphaned sessions | | `kugetsu destroy <issue-ref> [-y]` | Delete issue session | | `kugetsu destroy --base [-y]` | Delete base session | ### Testing Plan - [ ] Test `kugetsu init` (requires TTY) - [ ] Test `kugetsu start` from headless environment - [ ] Test `kugetsu continue` on existing forked session - [ ] Test `kugetsu list` output - [ ] Test `kugetsu prune` orphaned cleanup - [ ] Test `kugetsu destroy` Closes #14
shoko added 1 commit 2026-03-29 21:52:11 +02:00
- Add kugetsu init to create base session via TUI
- Add kugetsu start/continue for issue-based task handling
- Add kugetsu list/prune/destroy for session lifecycle
- Implement directory files + index.json storage pattern
- Use issue ref format: instance/user/repo#number
- Fork from base session enables headless operation

Solves: opencode headless CLI limitation discovered in issue #14
shoko added 1 commit 2026-03-29 21:53:51 +02:00
The function call inside ${} syntax was invalid. Changed to use
command substitution $(...) instead.
shoko added 1 commit 2026-03-29 22:00:23 +02:00
shoko added 1 commit 2026-03-29 22:01:26 +02:00
shoko added 1 commit 2026-03-29 22:16:59 +02:00
The --fork flag outputs the new session ID. Parse that instead of
relying on session list which may return wrong session when multiple
exist. Added fallback to session list parsing.
shoko added 1 commit 2026-03-29 22:19:45 +02:00
Create placeholder session file and add to index BEFORE running
opencode. This ensures we have a record even if opencode takes
long time or times out. Update with real session ID after fork.
shoko added 1 commit 2026-03-29 22:25:48 +02:00
Compare session list before and after fork to reliably detect which
session is the newly created one. Avoids relying on parsing output
that may not contain session ID.
han approved these changes 2026-03-30 05:00:03 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko merged commit 3e0144ea7c into main 2026-03-30 05:13:10 +02:00
Sign in to join this conversation.