From 99d09c7dda9475c1d1b36e5ac8b8125e3e36a32c Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Mon, 6 Apr 2026 08:05:42 +0000 Subject: [PATCH] fix: cmd_start and cmd_continue now fork dev agent to work on task (issue #187) - Added build_dev_agent_message() function to generate default workflow prompt - cmd_start now forks the agent after creating session (fire-and-forget) - cmd_continue now uses default message when empty and forks agent (fire-and-forget) - Both commands log output to $LOGS_DIR/dev-$session_id.log --- skills/kugetsu/scripts/kugetsu-session.sh | 62 +++++++++++++++++++---- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/skills/kugetsu/scripts/kugetsu-session.sh b/skills/kugetsu/scripts/kugetsu-session.sh index 8066948..293e58e 100755 --- a/skills/kugetsu/scripts/kugetsu-session.sh +++ b/skills/kugetsu/scripts/kugetsu-session.sh @@ -199,6 +199,45 @@ cmd_delegate() { 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() { local issue_ref="${1:-}" local message="${2:-}" @@ -270,6 +309,12 @@ cmd_start() { 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 &) && disown + echo "Session started for '$issue_ref': $new_session_id" echo "Worktree: $worktree_path" } @@ -315,19 +360,16 @@ 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 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 "$message" ]; then - (cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" "$@") - else - (cd "$worktree_path" && opencode --continue --session "$opencode_session_id" "$@") - fi + (cd "$worktree_path" && nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$message' --continue --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &) && disown else - if [ -n "$message" ]; then - opencode run "$message" --continue --session "$opencode_session_id" "$@" - else - opencode --continue --session "$opencode_session_id" "$@" - fi + nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run '$message' --continue --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 & && disown fi }