|
|
|
@@ -83,10 +83,9 @@ EOF
|
|
|
|
if [ -n "$existing_base" ] && [ "$existing_base" != "null" ]; then
|
|
|
|
if [ -n "$existing_base" ] && [ "$existing_base" != "null" ]; then
|
|
|
|
if [ "$force" = true ]; then
|
|
|
|
if [ "$force" = true ]; then
|
|
|
|
echo "Warning: Reinitializing sessions (force mode)" >&2
|
|
|
|
echo "Warning: Reinitializing sessions (force mode)" >&2
|
|
|
|
echo "Destroying all sessions, worktrees, and logs..." >&2
|
|
|
|
echo "Destroying existing sessions..." >&2
|
|
|
|
cmd_destroy --base -y 2>/dev/null || true
|
|
|
|
cmd_destroy --base -y 2>/dev/null || true
|
|
|
|
cmd_destroy --pm-agent -y 2>/dev/null || true
|
|
|
|
cmd_destroy --pm-agent -y 2>/dev/null || true
|
|
|
|
rm -f "$LOGS_DIR"/*.log 2>/dev/null || true
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
echo "Error: Base session already exists: $existing_base" >&2
|
|
|
|
echo "Error: Base session already exists: $existing_base" >&2
|
|
|
|
echo "Use --force to reinitialize" >&2
|
|
|
|
echo "Use --force to reinitialize" >&2
|
|
|
|
@@ -225,10 +224,7 @@ cmd_delegate() {
|
|
|
|
exit 1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
local msg_file="$LOGS_DIR/msg-$new_session.txt"
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$new_session'" >> "$log_file" 2>&1 &
|
|
|
|
printf '%s' "$message" > "$msg_file"
|
|
|
|
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$new_session'" >> "$log_file" 2>&1 &
|
|
|
|
|
|
|
|
rm -f "$msg_file"
|
|
|
|
|
|
|
|
echo "Delegated to new session (logged to $(basename "$log_file"))"
|
|
|
|
echo "Delegated to new session (logged to $(basename "$log_file"))"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -241,47 +237,24 @@ create_session() {
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
local before_json=$(opencode session list --format=json 2>/dev/null)
|
|
|
|
local before_json=$(opencode session list --format=json 2>/dev/null)
|
|
|
|
local before_set=$(echo "$before_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print('|'.join(s['id'] for s in sessions))" 2>/dev/null || echo "|")
|
|
|
|
local before_ids=$(echo "$before_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print(' '.join(s['id'] for s in sessions))" 2>/dev/null || echo "")
|
|
|
|
|
|
|
|
|
|
|
|
opencode run --fork --session "$base_session" "new session" >/dev/null 2>&1
|
|
|
|
opencode run --fork --session "$base_session" "new session" 2>/dev/null
|
|
|
|
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local after_json=$(opencode session list --format=json 2>/dev/null)
|
|
|
|
local after_json=$(opencode session list --format=json 2>/dev/null)
|
|
|
|
local after_sessions=$(echo "$after_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); [print(s['id']) for s in sessions]" 2>/dev/null || true)
|
|
|
|
local after_ids=$(echo "$after_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print(' '.join(s['id'] for s in sessions))" 2>/dev/null || echo "")
|
|
|
|
|
|
|
|
|
|
|
|
local new_session_id=""
|
|
|
|
local new_session_id=""
|
|
|
|
while IFS= read -r sess; do
|
|
|
|
for sess in $after_ids; do
|
|
|
|
if [[ -n "$sess" ]] && [[ ! "$before_set" =~ \|${sess}\| ]]; then
|
|
|
|
if [[ ! " $before_ids " =~ " $sess " ]] && [[ "$sess" != "$base_session" ]]; then
|
|
|
|
new_session_id="$sess"
|
|
|
|
new_session_id="$sess"
|
|
|
|
break
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done <<< "$after_sessions"
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
echo "$new_session_id"
|
|
|
|
echo "$new_session_id"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
load_session_context() {
|
|
|
|
|
|
|
|
local opencode_session_id="$1"
|
|
|
|
|
|
|
|
local sanitized_id=$(echo "$opencode_session_id" | sed 's/[^a-zA-Z0-9_-]/_/g')
|
|
|
|
|
|
|
|
local log_file="$LOGS_DIR/dev-$sanitized_id.log"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ ! -f "$log_file" ]; then
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local context_summary="Previous session context (work was in progress, session may have crashed or been interrupted):\n\n"
|
|
|
|
|
|
|
|
context_summary+=$(tail -100 "$log_file" 2>/dev/null | while IFS= read -r line; do
|
|
|
|
|
|
|
|
line=$(strip_ansi_codes "$line")
|
|
|
|
|
|
|
|
echo " $line"
|
|
|
|
|
|
|
|
done | head -50)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context_summary+="\n\nPlease review this context and continue the work appropriately."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "$context_summary"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build_dev_agent_message() {
|
|
|
|
build_dev_agent_message() {
|
|
|
|
local issue_ref="$1"
|
|
|
|
local issue_ref="$1"
|
|
|
|
local user_message="${2:-}"
|
|
|
|
local user_message="${2:-}"
|
|
|
|
@@ -399,11 +372,7 @@ cmd_start() {
|
|
|
|
load_agent_env "dev"
|
|
|
|
load_agent_env "dev"
|
|
|
|
|
|
|
|
|
|
|
|
cd "$worktree_path"
|
|
|
|
cd "$worktree_path"
|
|
|
|
local sanitized_id=$(echo "$new_session_id" | sed 's/[^a-zA-Z0-9_-]/_/g')
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$dev_message' --session '$new_session_id'" >> "$LOGS_DIR/dev-$new_session_id.log" 2>&1 &
|
|
|
|
local msg_file="$LOGS_DIR/msg-$sanitized_id.txt"
|
|
|
|
|
|
|
|
printf '%s' "$dev_message" > "$msg_file"
|
|
|
|
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$new_session_id'" >> "$LOGS_DIR/dev-$sanitized_id.log" 2>&1 &
|
|
|
|
|
|
|
|
rm -f "$msg_file"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "Session started for '$issue_ref': $new_session_id"
|
|
|
|
echo "Session started for '$issue_ref': $new_session_id"
|
|
|
|
echo "Worktree: $worktree_path"
|
|
|
|
echo "Worktree: $worktree_path"
|
|
|
|
@@ -454,16 +423,9 @@ cmd_continue() {
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$worktree_path" ] || [ ! -d "$worktree_path" ]; then
|
|
|
|
if [ -z "$worktree_path" ] || [ ! -d "$worktree_path" ]; then
|
|
|
|
echo "Warning: Worktree is missing for '$session_name'. Recovering..." >&2
|
|
|
|
echo "Warning: Worktree is missing for '$session_name'. Recovering..." >&2
|
|
|
|
local previous_context=$(load_session_context "$opencode_session_id")
|
|
|
|
|
|
|
|
rm -f "$session_path"
|
|
|
|
rm -f "$session_path"
|
|
|
|
remove_issue_from_index "$session_name"
|
|
|
|
remove_issue_from_index "$session_name"
|
|
|
|
if [ -n "$previous_context" ]; then
|
|
|
|
echo "Calling cmd_start to create new session and worktree..." >&2
|
|
|
|
message="$previous_context"
|
|
|
|
|
|
|
|
if [ -n "$message" ]; then
|
|
|
|
|
|
|
|
message="$message"$'\n\n'"Additional user message: $message"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Calling cmd_start to create new session and worktree with context..." >&2
|
|
|
|
|
|
|
|
cmd_start "$session_name" "$message"
|
|
|
|
cmd_start "$session_name" "$message"
|
|
|
|
return $?
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
@@ -473,11 +435,7 @@ cmd_continue() {
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
cd "$worktree_path"
|
|
|
|
cd "$worktree_path"
|
|
|
|
local sanitized_id=$(echo "$opencode_session_id" | sed 's/[^a-zA-Z0-9_-]/_/g')
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
|
|
|
local msg_file="$LOGS_DIR/msg-$sanitized_id.txt"
|
|
|
|
|
|
|
|
printf '%s' "$message" > "$msg_file"
|
|
|
|
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$sanitized_id.log" 2>&1 &
|
|
|
|
|
|
|
|
rm -f "$msg_file"
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmd_list() {
|
|
|
|
cmd_list() {
|
|
|
|
|