Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7888a34bd9 | |||
|
|
e2a37cdbb9 | ||
|
|
6e9472b5e2 |
@@ -876,7 +876,7 @@ cmd_doctor() {
|
||||
}
|
||||
|
||||
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
|
||||
echo "[ERROR] opencode database not found: $opencode_db"
|
||||
@@ -1107,6 +1107,22 @@ EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local cwd_files=$(ls -A "$PWD" 2>/dev/null | wc -l)
|
||||
local cwd_git=$(git rev-parse --is-inside-work-tree 2>/dev/null || echo "false")
|
||||
if [ "$cwd_files" -gt 0 ] || [ "$cwd_git" = "true" ]; then
|
||||
echo "Warning: Current directory is not empty: $PWD" >&2
|
||||
echo "This may cause project context to contaminate the base session." >&2
|
||||
echo "Consider running kugetsu init from an empty directory." >&2
|
||||
echo "" >&2
|
||||
echo "Files in current directory: $cwd_files" >&2
|
||||
if [ "$cwd_git" = "true" ]; then
|
||||
echo "Git repository detected: $(git rev-parse --show-toplevel 2>/dev/null || echo 'unknown')" >&2
|
||||
fi
|
||||
echo "" >&2
|
||||
echo "Press Ctrl+C to cancel or wait 5 seconds to continue anyway..." >&2
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
echo "Starting TUI to create base session..."
|
||||
echo "Press Ctrl+C to cancel or wait for session to be created"
|
||||
sleep 2
|
||||
@@ -1226,12 +1242,6 @@ cmd_start() {
|
||||
|
||||
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'..."
|
||||
|
||||
# Session-counting: count actual dev sessions, reject if at limit
|
||||
@@ -1246,12 +1256,14 @@ cmd_start() {
|
||||
local fork_log="$SESSIONS_DIR/$session_file.fork.log"
|
||||
local opencode_db="${OPENCODE_DB:-$HOME/.local/share/opencode/opencode.db}"
|
||||
|
||||
> "$fork_log"
|
||||
|
||||
fix_session_permissions
|
||||
|
||||
if [ "$DEBUG_MODE" = true ]; then
|
||||
(cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" 2>&1) | tee "$fork_log" &
|
||||
(cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" --dir "$worktree_path" 2>&1) | tee "$fork_log" &
|
||||
else
|
||||
(cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" 2>&1) >> "$fork_log" &
|
||||
(cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" --dir "$worktree_path" 2>&1) >> "$fork_log" &
|
||||
fi
|
||||
|
||||
local fork_pid=$!
|
||||
@@ -1264,25 +1276,17 @@ cmd_start() {
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
sleep 1
|
||||
|
||||
while IFS= read -r sess; do
|
||||
[ "$sess" = "$base_session_id" ] && continue
|
||||
[ "$sess" = "$pm_agent_session_id" ] && continue
|
||||
new_session_id=$(python3 -c "
|
||||
import sqlite3
|
||||
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
|
||||
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
|
||||
if [ -n "$new_session_id" ] && [ "$new_session_id" != "$base_session_id" ] && [ "$new_session_id" != "$pm_agent_session_id" ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
@@ -1295,21 +1299,6 @@ cmd_start() {
|
||||
done
|
||||
|
||||
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
|
||||
if [ -n "$fork_log_output" ]; then
|
||||
echo "Fork log output:" >&2
|
||||
@@ -1400,9 +1389,9 @@ cmd_continue() {
|
||||
if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then
|
||||
echo "Using worktree: $worktree_path"
|
||||
if [ "$DEBUG_MODE" = true ]; then
|
||||
(cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" 2>&1) | tee "$session_path.debug.log" &
|
||||
opencode run "$message" --continue --session "$opencode_session_id" --dir "$worktree_path" 2>&1 | tee "$session_path.debug.log" &
|
||||
else
|
||||
(cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" 2>&1) &
|
||||
opencode run "$message" --continue --session "$opencode_session_id" --dir "$worktree_path" 2>&1 &
|
||||
fi
|
||||
else
|
||||
if [ "$DEBUG_MODE" = true ]; then
|
||||
|
||||
Reference in New Issue
Block a user