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
Showing only changes of commit 636a41f41b - Show all commits

View File

@@ -249,6 +249,11 @@ cmd_start() {
local session_file="$(issue_ref_to_filename "$issue_ref").json"
printf '{"type": "forked", "issue_ref": "%s", "opencode_session_id": "pending", "created_at": "%s", "state": "starting"}\n' \
"$issue_ref" "$(date -Iseconds)" > "$SESSIONS_DIR/$session_file"
add_issue_to_index "$issue_ref" "$session_file"
echo "Forking session for '$issue_ref'..."
local fork_output
if [ "$DEBUG_MODE" = true ]; then
@@ -260,19 +265,19 @@ cmd_start() {
local new_session_id=$(echo "$fork_output" | grep -oP 'A new forked session was created: \Kses_\w+' | tail -1)
if [ -z "$new_session_id" ]; then
new_session_id=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' | grep -v "^$base_session_id$" | tail -1)
new_session_id=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' | grep -v "^$base_session_id$" | head -1)
fi
if [ -z "$new_session_id" ]; then
echo "Error: Could not find newly created session" >&2
printf '{"type": "forked", "issue_ref": "%s", "opencode_session_id": "failed", "created_at": "%s", "state": "failed"}\n' \
"$issue_ref" "$(date -Iseconds)" > "$SESSIONS_DIR/$session_file"
exit 1
fi
printf '{"type": "forked", "issue_ref": "%s", "opencode_session_id": "%s", "created_at": "%s", "state": "idle"}\n' \
"$issue_ref" "$new_session_id" "$(date -Iseconds)" > "$SESSIONS_DIR/$session_file"
add_issue_to_index "$issue_ref" "$session_file"
echo "Session started for '$issue_ref': $new_session_id"
}