|
|
|
@@ -194,11 +194,50 @@ cmd_delegate() {
|
|
|
|
|
|
|
|
|
|
|
|
mkdir -p "$LOGS_DIR"
|
|
|
|
mkdir -p "$LOGS_DIR"
|
|
|
|
local log_file="$LOGS_DIR/delegate-$(date +%s).log"
|
|
|
|
local log_file="$LOGS_DIR/delegate-$(date +%s).log"
|
|
|
|
nohup sh -c "GITEA_TOKEN='***' opencode run '$message' --continue --session '$pm_session' >> '$log_file' 2>&1" > /dev/null 2>&1 &
|
|
|
|
load_agent_env "pm-agent"
|
|
|
|
disown
|
|
|
|
nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$message' --continue --session '$pm_session'" >> "$log_file" 2>&1 &
|
|
|
|
echo "Delegated to PM agent (logged to $(basename "$log_file"))"
|
|
|
|
echo "Delegated to PM agent (logged to $(basename "$log_file"))"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build_dev_agent_message() {
|
|
|
|
|
|
|
|
local issue_ref="$1"
|
|
|
|
|
|
|
|
local user_message="${2:-}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local instance=$(echo "$issue_ref" | cut -d'/' -f1 | cut -d'#' -f1)
|
|
|
|
|
|
|
|
local owner=$(echo "$issue_ref" | cut -d'/' -f2)
|
|
|
|
|
|
|
|
local repo=$(echo "$issue_ref" | cut -d'/' -f3 | cut -d'#' -f1)
|
|
|
|
|
|
|
|
local number=$(echo "$issue_ref" | grep -oE '#[0-9]+$' | tr -d '#')
|
|
|
|
|
|
|
|
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local base_message="You are assigned to work on $issue_ref.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Workflow:
|
|
|
|
|
|
|
|
1. Read the issue at $instance/$owner/$repo/issues/$number AND all comments on that issue
|
|
|
|
|
|
|
|
2. Check if a PR already exists for this issue
|
|
|
|
|
|
|
|
- If PR exists and is open, review it and learn from it
|
|
|
|
|
|
|
|
- If PR makes sense to continue, work on it instead
|
|
|
|
|
|
|
|
- If PR is not worth continuing, create a new branch/PR but explain in PR description why you're creating a new one instead of continuing the existing PR
|
|
|
|
|
|
|
|
3. Read README.md (if exists) to understand the general concept of this repository
|
|
|
|
|
|
|
|
4. Read CONTRIBUTING.md (if exists) to understand how to contribute
|
|
|
|
|
|
|
|
- If CONTRIBUTING.md doesn't exist, follow steps 5-9 as your guideline
|
|
|
|
|
|
|
|
5. Explore the repository to understand the codebase
|
|
|
|
|
|
|
|
6. If anything is unclear, post a comment on the issue asking for clarification before implementing
|
|
|
|
|
|
|
|
7. Implement the solution
|
|
|
|
|
|
|
|
8. Create a branch named fix/issue-$number and implement the fix
|
|
|
|
|
|
|
|
9. Create a PR when the implementation is complete
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Work directory: $worktree_path"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$user_message" ]; then
|
|
|
|
|
|
|
|
echo "$base_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Additional instructions from delegator:
|
|
|
|
|
|
|
|
$user_message"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "$base_message"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmd_start() {
|
|
|
|
cmd_start() {
|
|
|
|
local issue_ref="${1:-}"
|
|
|
|
local issue_ref="${1:-}"
|
|
|
|
local message="${2:-}"
|
|
|
|
local message="${2:-}"
|
|
|
|
@@ -246,7 +285,7 @@ cmd_start() {
|
|
|
|
local before_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
|
|
|
|
local before_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
|
|
|
|
local before_set="|$before_sessions|"
|
|
|
|
local before_set="|$before_sessions|"
|
|
|
|
|
|
|
|
|
|
|
|
create_worktree "$issue_ref"
|
|
|
|
create_worktree "$issue_ref" "$WORKTREES_DIR"
|
|
|
|
|
|
|
|
|
|
|
|
local after_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
|
|
|
|
local after_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
|
|
|
|
local new_session_id=""
|
|
|
|
local new_session_id=""
|
|
|
|
@@ -270,6 +309,13 @@ cmd_start() {
|
|
|
|
|
|
|
|
|
|
|
|
add_issue_to_index "$issue_ref" "$session_file"
|
|
|
|
add_issue_to_index "$issue_ref" "$session_file"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local dev_message=$(build_dev_agent_message "$issue_ref" "$message")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
load_agent_env "dev"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cd "$worktree_path"
|
|
|
|
|
|
|
|
nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$dev_message' --continue --session '$new_session_id'" >> "$LOGS_DIR/dev-$new_session_id.log" 2>&1 &
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -315,19 +361,17 @@ cmd_continue() {
|
|
|
|
|
|
|
|
|
|
|
|
local opencode_session_id=$(python3 -c "import json; print(json.load(open('$session_path')).get('opencode_session_id', ''))" 2>/dev/null || echo "")
|
|
|
|
local opencode_session_id=$(python3 -c "import json; print(json.load(open('$session_path')).get('opencode_session_id', ''))" 2>/dev/null || echo "")
|
|
|
|
local worktree_path=$(python3 -c "import json; print(json.load(open('$session_path')).get('worktree_path', ''))" 2>/dev/null || echo "")
|
|
|
|
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 "$message" ]; then
|
|
|
|
|
|
|
|
message=$(build_dev_agent_message "$issue_ref" "")
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then
|
|
|
|
if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then
|
|
|
|
if [ -n "$message" ]; then
|
|
|
|
cd "$worktree_path"
|
|
|
|
(cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" "$@")
|
|
|
|
nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$message' --continue --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
|
|
|
else
|
|
|
|
|
|
|
|
(cd "$worktree_path" && opencode --continue --session "$opencode_session_id" "$@")
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
if [ -n "$message" ]; then
|
|
|
|
nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$message' --continue --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
|
|
|
opencode run "$message" --continue --session "$opencode_session_id" "$@"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
opencode --continue --session "$opencode_session_id" "$@"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -479,10 +523,6 @@ cmd_destroy() {
|
|
|
|
local target="${1:-}"
|
|
|
|
local target="${1:-}"
|
|
|
|
local force=false
|
|
|
|
local force=false
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$target" = "--base" ]; then
|
|
|
|
|
|
|
|
target=""
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$2" = "-y" ]; then
|
|
|
|
if [ "$2" = "-y" ]; then
|
|
|
|
force=true
|
|
|
|
force=true
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|