Compare commits

..

7 Commits

Author SHA1 Message Date
shokollm
c9eb8badea feat(session): add kugetsu_context_dump call in cmd_continue
Integrates the existing kugetsu_context_dump() function to capture
the initial user prompt before forking the agent.

Closes #212
2026-04-08 02:17:27 +00:00
shokollm
24dd91d0e1 fix: remove duplicate fi in cmd_continue 2026-04-08 01:04:43 +00:00
c8b2ab6b12 Merge pull request 'fix: always use base workflow with user message' (#232) from fix/issue-229-user-message-with-base-workflow into main 2026-04-08 02:33:22 +02:00
shokollm
87434d1bca fix: always use base workflow and add user message to it
Previously when a user message was provided, cmd_continue would only
use the user message without the base agent workflow. Now both cases
build the full workflow and append the user message.

Changes:
- cmd_continue now always calls build_dev_agent_message even when
  message is provided
- User message is appended at the end with 'Delegator's message:'
- Both with/without message cases now use the same workflow structure

Fixes #229
2026-04-08 00:11:03 +00:00
ae8f1433a7 Merge pull request 'fix(session): remove incorrect worktree removal in ensure_session' (#231) from fix/issue-229-ensure-session-worktree-bug into main 2026-04-08 01:52:08 +02:00
shokollm
b16a97514e fix(session): remove incorrect worktree removal in ensure_session
When worktree exists but session is missing, ensure_session was
incorrectly removing the worktree before recreating. This caused
issues when cmd_continue called ensure_worktree first (creating the
worktree) then ensure_session (which wrongly removed it).

The fix removes the block that removes worktree when session is missing.
If worktree exists, just create the session without touching the worktree.

Fixes #229
2026-04-07 23:39:18 +00:00
b09fe8eabc Merge pull request 'refactor(session): make cmd_continue idempotent with ensure_* functions' (#230) from fix/issue-168 into main 2026-04-08 00:32:16 +02:00
2 changed files with 31 additions and 22 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ results/
*/results/ */results/
*.pyc *.pyc
.kugetsu/

View File

@@ -272,29 +272,39 @@ build_dev_agent_message() {
if [ -n "$user_message" ]; then if [ -n "$user_message" ]; then
cat <<EOF cat <<EOF
You are continuing work on $issue_ref. A PR likely already exists. You are assigned to work on $issue_ref.
IMPORTANT - Review workflow: IMPORTANT: Follow the workflow below as your guideline, but prioritize the delegator's message.
1. First, check if PR exists: curl -s "https://$instance/api/v1/repos/$owner/$repo/pulls?state=open" -H "Authorization: Bearer \$GITEA_TOKEN" | grep -i "$number"
2. Get PR comments: curl -s "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN"
3. Get PR reviews: curl -s "https://$instance/api/v1/repos/$owner/$repo/pulls/$number/reviews" -H "Authorization: Bearer \$GITEA_TOKEN"
You may need to: Workflow:
- Make code changes and push to the same branch 1. Read the issue at $instance/$owner/$repo/issues/$number AND all comments on that issue
- Reply to PR comments using: curl -X POST "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN" -H "Content-Type: application/json" -d '{"body":"Your reply here"}' 2. Check if a PR already exists for this issue
- Or do both - 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 using: tea pr create --repo $owner/$repo --title "Your PR title" --body "PR description"
- Make sure you are logged in with: tea login add --name gitea --token \$GITEA_TOKEN --url https://$instance
- If tea is not available, use: curl -X POST "https://$instance/api/v1/repos/$owner/$repo/pulls" -H "Authorization: Bearer \$GITEA_TOKEN" -H "Content-Type: application/json" -d '{"title":"PR Title","head":"branch-name","base":"main","body":"PR description"}'
MERGING: If instructed to merge, you MUST confirm approval first before merging: Tools for PR interaction:
- Check for PR approval via: curl -s "https://$instance/api/v1/repos/$owner/$repo/pulls/$number/reviews" -H "Authorization: Bearer \$GITEA_TOKEN" - Post issue/PR comment: curl -X POST "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN" -H "Content-Type: application/json" -d '{"body":"Your comment"}'
- Check for "lgtm" or "approved" in comments: curl -s "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN" - List PR comments: curl -s "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN"
- Only merge if you see approval OR the instruction explicitly says to merge (e.g., "merge the PR", "please merge", "go ahead and merge") - List PR reviews: curl -s "https://$instance/api/v1/repos/$owner/$repo/pulls/$number/reviews" -H "Authorization: Bearer \$GITEA_TOKEN"
- To merge: tea pr merge --repo $owner/$repo $number --style merge - Merge PR (only with approval): tea pr merge --repo $owner/$repo $number --style merge
- If no approval yet, reply asking for review/approval first - MERGING requires approval first! Check for: approval in reviews, OR "lgtm"/"approved" in comments
- If no approval, ask reviewer to approve first before merging
Delegator's message: Delegator's message:
$user_message $user_message
Work directory: $worktree_path (already on the fix branch) Work directory: $worktree_path
EOF EOF
else else
cat <<EOF cat <<EOF
@@ -386,12 +396,6 @@ ensure_session() {
return 0 return 0
fi fi
if $worktree_exists && ! $session_exists; then
log "warn" "ensure_session" "Worktree exists but session is missing. Removing worktree to recreate both..."
remove_worktree_for_issue "$issue_ref"
worktree_exists=false
fi
if ! $worktree_exists && $session_exists; then if ! $worktree_exists && $session_exists; then
log "warn" "ensure_session" "Session exists but worktree is missing. Removing stale session..." log "warn" "ensure_session" "Session exists but worktree is missing. Removing stale session..."
rm -f "$session_path" rm -f "$session_path"
@@ -481,6 +485,8 @@ cmd_continue() {
if [ -z "$message" ]; then if [ -z "$message" ]; then
message=$(build_dev_agent_message "$issue_ref" "") message=$(build_dev_agent_message "$issue_ref" "")
else
message=$(build_dev_agent_message "$issue_ref" "$message")
fi fi
local worktree_status=$(ensure_worktree "$issue_ref") local worktree_status=$(ensure_worktree "$issue_ref")
@@ -495,6 +501,8 @@ cmd_continue() {
exit 1 exit 1
fi fi
kugetsu_context_dump "$issue_ref" "$message" "$(issue_ref_to_branch_name "$issue_ref")"
local session_file=$(issue_ref_to_filename "$issue_ref") local session_file=$(issue_ref_to_filename "$issue_ref")
local session_path="$SESSIONS_DIR/$session_file" local session_path="$SESSIONS_DIR/$session_file"
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 "")