feat(context): add context dump/load for session isolation #139

Merged
shoko merged 1 commits from feat/context-dump-load into main 2026-04-05 06:23:40 +02:00
Owner

Overview

Implements #136 - Context dump/load for session isolation.

Changes

Configuration

CONTEXT_DIR="${CONTEXT_DIR:-$KUETSU_DIR/context}"
ENABLE_CONTEXT_DUMP="${ENABLE_CONTEXT_DUMP:-true}"

Context File Format

Stored at ~/.kugetsu/context/<issue-ref>.json:

{
  "issue_ref": "github.com/shoko/kugetsu#14",
  "current_branch": "fix/issue-14",
  "created_at": "2026-04-01T10:00:00Z",
  "updated_at": "2026-04-05T14:30:00Z",
  "last_message": "I've fixed the login bug...",
  "conversation_history": [
    {"role": "user", "content": "...", "timestamp": "..."},
    {"role": "assistant", "content": "...", "timestamp": "..."}
  ]
}

New Functions

  • issue_ref_to_context_file() - Derives context file path from issue ref
  • kugetsu_context_load() - Loads previous context and formats for injection
  • kugetsu_context_dump() - Saves context on session start
  • kugetsu_context_update_message() - Appends messages to conversation history

Integration

  • kugetsu start <issue> <msg> - Loads existing context before forking, dumps on start
  • kugetsu continue <issue> <msg> - Loads context, prepends to message, updates after

New Command

kugetsu context <issue-ref>

Shows context file for an issue.

Rationale

By tying context to issue-ref instead of session ID:

  • Same issue always resumes with same context
  • Different issues have isolated contexts
  • Even if opencode session gets "poisoned", context remains correct

Closes #136

## Overview Implements #136 - Context dump/load for session isolation. ## Changes ### Configuration ```bash CONTEXT_DIR="${CONTEXT_DIR:-$KUETSU_DIR/context}" ENABLE_CONTEXT_DUMP="${ENABLE_CONTEXT_DUMP:-true}" ``` ### Context File Format Stored at `~/.kugetsu/context/<issue-ref>.json`: ```json { "issue_ref": "github.com/shoko/kugetsu#14", "current_branch": "fix/issue-14", "created_at": "2026-04-01T10:00:00Z", "updated_at": "2026-04-05T14:30:00Z", "last_message": "I've fixed the login bug...", "conversation_history": [ {"role": "user", "content": "...", "timestamp": "..."}, {"role": "assistant", "content": "...", "timestamp": "..."} ] } ``` ### New Functions - `issue_ref_to_context_file()` - Derives context file path from issue ref - `kugetsu_context_load()` - Loads previous context and formats for injection - `kugetsu_context_dump()` - Saves context on session start - `kugetsu_context_update_message()` - Appends messages to conversation history ### Integration - `kugetsu start <issue> <msg>` - Loads existing context before forking, dumps on start - `kugetsu continue <issue> <msg>` - Loads context, prepends to message, updates after ### New Command ```bash kugetsu context <issue-ref> ``` Shows context file for an issue. ## Rationale By tying context to issue-ref instead of session ID: - Same issue always resumes with same context - Different issues have isolated contexts - Even if opencode session gets "poisoned", context remains correct ## Related Issues Closes #136
shoko added 1 commit 2026-04-05 04:55:14 +02:00
- Add CONTEXT_DIR and ENABLE_CONTEXT_DUMP config options
- Add issue_ref_to_context_file() to derive context file path
- Add kugetsu_context_load() to load previous context
- Add kugetsu_context_dump() to save context on start
- Add kugetsu_context_update_message() to append to history
- Integrate context loading into cmd_start and cmd_continue
- Add kugetsu context command to view context for issue

Context is stored in ~/.kugetsu/context/<issue-ref>.json with:
- issue_ref, current_branch, updated_at
- last_message summary
- conversation_history (last 20 messages)

Closes #136
han approved these changes 2026-04-05 06:06:32 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko added 1 commit 2026-04-05 06:12:43 +02:00
Combines context dump/load feature with worktree lifecycle features:
- CONTEXT_DIR and ENABLE_CONTEXT_DUMP config
- Context functions: kugetsu_context_load/dump/update_message
- WORKTREE_CHECK_PR_STATUS config
- check_pr_status() and update_session_pr_url() functions
- set-pr and context commands
shoko added 1 commit 2026-04-05 06:14:00 +02:00
shoko force-pushed feat/context-dump-load from 66bbe53d3d to 61f06f825f 2026-04-05 06:23:34 +02:00 Compare
shoko merged commit e763ceb0ad into main 2026-04-05 06:23:40 +02:00
Sign in to join this conversation.