|
|
|
|
@@ -309,26 +309,44 @@ cmd_start() {
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local session_file=$(issue_ref_to_filename "$issue_ref")
|
|
|
|
|
local session_path="$SESSIONS_DIR/$session_file"
|
|
|
|
|
local worktree_exists=false
|
|
|
|
|
|
|
|
|
|
if worktree_exists "$issue_ref"; then
|
|
|
|
|
echo "Issue '$issue_ref' already has a worktree. Use 'kugetsu continue' instead."
|
|
|
|
|
worktree_exists=true
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local session_exists=false
|
|
|
|
|
if [ -f "$session_path" ]; then
|
|
|
|
|
session_exists=true
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if $worktree_exists && $session_exists; then
|
|
|
|
|
echo "Issue '$issue_ref' already has a worktree and session." >&2
|
|
|
|
|
echo "Use 'kugetsu continue $issue_ref' to continue work." >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if $worktree_exists && ! $session_exists; then
|
|
|
|
|
echo "Warning: Worktree exists but session is missing. Removing worktree to recreate both..." >&2
|
|
|
|
|
remove_worktree_for_issue "$issue_ref"
|
|
|
|
|
worktree_exists=false
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if ! $worktree_exists && $session_exists; then
|
|
|
|
|
echo "Warning: Session exists but worktree is missing. Removing stale session to recreate both..." >&2
|
|
|
|
|
rm -f "$session_path"
|
|
|
|
|
remove_issue_from_index "$issue_ref"
|
|
|
|
|
session_exists=false
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local active_count=$(count_active_dev_sessions)
|
|
|
|
|
if [ "$active_count" -ge "${MAX_CONCURRENT_AGENTS:-3}" ]; then
|
|
|
|
|
echo "Error: Max concurrent agents (${MAX_CONCURRENT_AGENTS:-3}) reached. Use 'kugetsu continue' or wait for an agent to finish." >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local session_file=$(issue_ref_to_filename "$issue_ref")
|
|
|
|
|
local session_path="$SESSIONS_DIR/$session_file"
|
|
|
|
|
|
|
|
|
|
if [ -f "$session_path" ]; then
|
|
|
|
|
echo "Session file already exists: $session_file"
|
|
|
|
|
echo "Use 'kugetsu continue $issue_ref' to continue work."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
create_worktree "$issue_ref" "$WORKTREES_DIR"
|
|
|
|
|
|
|
|
|
|
local new_session_id=$(create_session "$base_session_id")
|
|
|
|
|
@@ -400,16 +418,21 @@ cmd_continue() {
|
|
|
|
|
local worktree_path=$(python3 -c "import json; print(json.load(open('$session_path')).get('worktree_path', ''))" 2>/dev/null || echo "")
|
|
|
|
|
local issue_ref=$(python3 -c "import json; print(json.load(open('$session_path')).get('issue_ref', ''))" 2>/dev/null || echo "")
|
|
|
|
|
|
|
|
|
|
if [ -z "$worktree_path" ] || [ ! -d "$worktree_path" ]; then
|
|
|
|
|
echo "Error: Worktree is missing for '$session_name'" >&2
|
|
|
|
|
echo "Removing stale session file..." >&2
|
|
|
|
|
rm -f "$session_path"
|
|
|
|
|
remove_issue_from_index "$session_name"
|
|
|
|
|
echo "Use 'kugetsu start $session_name' to create a new session." >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "$message" ]; then
|
|
|
|
|
message=$(build_dev_agent_message "$issue_ref" "")
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then
|
|
|
|
|
cd "$worktree_path"
|
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
|
|
|
|
else
|
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
|
|
|
|
fi
|
|
|
|
|
cd "$worktree_path"
|
|
|
|
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_list() {
|
|
|
|
|
|