Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e9472b5e2 | ||
|
|
775f73348a |
@@ -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"
|
||||
@@ -1226,12 +1226,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
|
||||
@@ -1264,25 +1258,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
|
||||
|
||||
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+')
|
||||
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 "")
|
||||
|
||||
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 +1281,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
|
||||
@@ -1319,6 +1290,17 @@ for row in cursor.fetchall():
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Updating permissions for new session: $new_session_id"
|
||||
python3 -c "
|
||||
import sqlite3
|
||||
conn = sqlite3.connect('$opencode_db')
|
||||
cursor = conn.cursor()
|
||||
PERMISSION_JSON = '[{\"permission\":\"question\",\"pattern\":\"*\",\"action\":\"deny\"},{\"permission\":\"plan_enter\",\"pattern\":\"*\",\"action\":\"deny\"},{\"permission\":\"plan_exit\",\"pattern\":\"*\",\"action\":\"deny\"},{\"permission\":\"external_directory\",\"pattern\":\"*\",\"action\":\"allow\"}]'
|
||||
cursor.execute('UPDATE session SET permission = ? WHERE id = ?', (PERMISSION_JSON, '$new_session_id'))
|
||||
conn.commit()
|
||||
print('[OK] Session permissions updated')
|
||||
"
|
||||
|
||||
if [ "$DEBUG_MODE" = true ]; then
|
||||
echo "[DEBUG] Forked session permissions check:"
|
||||
python3 -c "
|
||||
|
||||
Reference in New Issue
Block a user