fix(kugetsu): detect session via DB query instead of opencode session list
opencode session list doesn't show sessions in ~/.kugetsu-worktrees/ directories. This caused detection to fail even though sessions were being created. Now we query the database directly for sessions matching the worktree path. Also fixed database path in fix_session_permissions (was ~/.opencode/, should be ~/.local/share/opencode/).
This commit is contained in:
@@ -876,7 +876,7 @@ cmd_doctor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fix_session_permissions() {
|
fix_session_permissions() {
|
||||||
local opencode_db="${OPENCODE_DB:-$HOME/.opencode/opencode.db}"
|
local opencode_db="${OPENCODE_DB:-$HOME/.local/share/opencode/opencode.db}"
|
||||||
|
|
||||||
if [ ! -f "$opencode_db" ]; then
|
if [ ! -f "$opencode_db" ]; then
|
||||||
echo "[ERROR] opencode database not found: $opencode_db"
|
echo "[ERROR] opencode database not found: $opencode_db"
|
||||||
@@ -1226,12 +1226,6 @@ cmd_start() {
|
|||||||
|
|
||||||
local session_file="$(issue_ref_to_filename "$issue_ref").json"
|
local session_file="$(issue_ref_to_filename "$issue_ref").json"
|
||||||
|
|
||||||
# Get list of sessions before fork to compare against after
|
|
||||||
declare -a before_sessions=()
|
|
||||||
while IFS= read -r sess; do
|
|
||||||
before_sessions+=("$sess")
|
|
||||||
done < <(opencode session list 2>/dev/null | grep -oP '^ses_\w+')
|
|
||||||
|
|
||||||
echo "Forking session for '$issue_ref'..."
|
echo "Forking session for '$issue_ref'..."
|
||||||
|
|
||||||
# Session-counting: count actual dev sessions, reject if at limit
|
# Session-counting: count actual dev sessions, reject if at limit
|
||||||
@@ -1264,25 +1258,17 @@ cmd_start() {
|
|||||||
while [ $attempt -le $max_attempts ]; do
|
while [ $attempt -le $max_attempts ]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
while IFS= read -r sess; do
|
new_session_id=$(python3 -c "
|
||||||
[ "$sess" = "$base_session_id" ] && continue
|
import sqlite3
|
||||||
[ "$sess" = "$pm_agent_session_id" ] && continue
|
conn = sqlite3.connect('$opencode_db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(\"SELECT id FROM session WHERE directory = '$worktree_path' ORDER BY time_created DESC LIMIT 1\")
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if result:
|
||||||
|
print(result[0])
|
||||||
|
" 2>/dev/null || echo "")
|
||||||
|
|
||||||
local existed_before=false
|
if [ -n "$new_session_id" ] && [ "$new_session_id" != "$base_session_id" ] && [ "$new_session_id" != "$pm_agent_session_id" ]; then
|
||||||
for before_sess in "${before_sessions[@]}"; do
|
|
||||||
if [ "$sess" = "$before_sess" ]; then
|
|
||||||
existed_before=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$existed_before" = false ]; then
|
|
||||||
new_session_id="$sess"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done < <(opencode session list 2>/dev/null | grep -oP '^ses_\w+')
|
|
||||||
|
|
||||||
if [ -n "$new_session_id" ]; then
|
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1295,21 +1281,6 @@ cmd_start() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$new_session_id" ]; then
|
if [ -z "$new_session_id" ]; then
|
||||||
if [ -f "$opencode_db" ]; then
|
|
||||||
local db_sessions=$(python3 -c "
|
|
||||||
import sqlite3
|
|
||||||
conn = sqlite3.connect('$opencode_db')
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(\"SELECT id FROM session WHERE parent_id IS NOT NULL ORDER BY time_created DESC LIMIT 5\")
|
|
||||||
for row in cursor.fetchall():
|
|
||||||
print(row[0])
|
|
||||||
" 2>/dev/null || echo "")
|
|
||||||
if [ -n "$db_sessions" ]; then
|
|
||||||
echo "Recent forked sessions in DB:" >&2
|
|
||||||
echo "$db_sessions" >&2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Error: Could not find newly created session after ${max_attempts}s" >&2
|
echo "Error: Could not find newly created session after ${max_attempts}s" >&2
|
||||||
if [ -n "$fork_log_output" ]; then
|
if [ -n "$fork_log_output" ]; then
|
||||||
echo "Fork log output:" >&2
|
echo "Fork log output:" >&2
|
||||||
|
|||||||
Reference in New Issue
Block a user