When kugetsu delegate is called without an issue ref, it now runs
interactively and synchronously instead of fire-and-forget with nohup.
This allows users to see PM response immediately for guidance/creation
requests rather than having the interaction run in background.
- fork_agent() now returns exit code instead of echoing status
- cmd_continue() returns exit code 2 when max agents reached
- cmd_continue() returns exit code 1 for general errors (instead of exit 1)
- ensure_worktree() returns exit code 2 for max agents condition
- Add EXITCODES.md documenting all exit codes
Closes#248
- Add KUGETSU_BASE_BRANCH env var (default: origin/main)
- Update check_task_completion() to use configurable base branch
- Update create_worktree() to use configurable base branch
Closes#165
- kugetsu: show only parent commands, not all subcommands inline
- kugetsu <command> help: show help for specific command
- kugetsu queue: show queue subcommands (list, stats, clear, enqueue)
- kugetsu queue-daemon: show daemon subcommands (start, stop, restart, status, logs)
- kugetsu env: show env subcommands (list, get, set, rm)
- kugetsu server: show server subcommands (list, add, remove, default, get)
Closes#244
- Extract conflict_check and delegator_section as conditional variables
- Single heredoc instead of duplicate blocks
- Resolve code duplication raised in PR comment
Dev agent should:
1. Check if PR has merge conflicts before asking for review
2. Read review comments and incorporate feedback
3. Understand review states: APPROVED = ready to merge, COMMENT = feedback to address
This prevents approving a PR that has conflicts, and ensures dev agents
respond to reviewer comments appropriately.
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
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
- Add ensure_worktree() - creates worktree if missing, returns status
- Add ensure_session() - creates session if missing, handles inconsistent states
- Add fork_agent() - extracted agent forking logic
- Refactor cmd_continue() to use ensure_* functions (idempotent)
- Make cmd_start() a thin wrapper calling cmd_continue()
- Simplify daemon to always call cmd_continue (no existence check)
This makes cmd_continue truly idempotent - it will:
- Continue existing session if it exists
- Create session and worktree if they don't exist
- Clean and recreate if state is inconsistent
Closes#168
The for loop was overwriting message each iteration, causing only
the last word to survive. Changed to accumulate all words with
proper spacing.
Fixes#225
Check notified_at timestamp in check_task_completion() and mark tasks
as error if they exceed TASK_TIMEOUT_HOURS (defaults to 1 hour).
When timeout is detected:
- Kill the task process (PID) if running
- Stop the opencode session if exists
- Mark queue item as error state
Fixes#166
Add clear distinction between Task Mode (delegate) and Conversation Mode
(answer directly).
- Add kugetsu start tool with params and when to use
- Add kugetsu continue tool with params and when to use
- Add guidance on how to choose between start vs continue
- Add examples for conversation mode responses
- Improve few-shot examples with mode identification
Fixes#220
cmd_delegate deletes the message file immediately after spawning the
background nohup process, causing a race condition where opencode run
may not have read the file yet.
Error: File not found: msg-ses_xxx.txt
Fix by removing rm -f "$msg_file", consistent with cmd_start and
cmd_continue which write to $worktree_path/.kugetsu-msg.txt and never
delete it. Orphaned msg files in $LOGS_DIR/ are harmless.
Fixes#210
The queue daemon crashes with 'set_debug_mode: command not found'
because cmd_continue() calls set_debug_mode(), but that function
was only defined in the main kugetsu script.
Instead of duplicating the function, move it to kugetsu-config.sh
which is always sourced before kugetsu-session.sh in all contexts.
Fixes#207
The message passed to opencode run contains newlines and special
characters (parentheses, etc.) which break shell parsing when passed
directly in double quotes.
Fix by writing message to temp file and using '@msg_file' syntax
to pass to opencode run. This handles any characters in the message.
cmd_continue:
- If worktree is missing but session exists, remove stale session and call cmd_start automatically
- This allows automatic recovery without user intervention
cmd_start:
- Check BOTH worktree AND session existence
- If only worktree exists (not session): remove worktree, recreate both
- If only session exists (not worktree): remove session, recreate both
- If both exist: tell user to use continue
cmd_init --force:
- Now destroys ALL sessions, worktrees, and logs for a clean slate
- Destroys base, pm-agent, all forked sessions, all worktrees, all logs
Daemon:
- Fixed wrong path in check_task_completion ($HOME/.kugetsu-worktrees -> $WORKTREES_DIR)
When base or pm_agent are not null, they need to be quoted with escaped quotes ("") in write_index calls.
This fixes 'write_index would create malformed JSON' error during init.
- Remove duplicate write_index, get_base_session_id, get_pm_agent_session_id,
get_session_for_issue, set_base_in_index, set_pm_agent_in_index,
add_issue_to_index, remove_issue_from_index from kugetsu
- These functions are already defined in kugetsu-index.sh which is sourced earlier
- The kugetsu versions were shadowing the kugetsu-index.sh ones unnecessarily
- This removes code duplication and ensures consistent behavior
Tests run sequentially to avoid memory exhaustion with too many opencode sessions:
- JSON session list parsing
- Session ID format validation
- create_session returns valid session ID
- create_session creates NEW session (different from base)
- create_session creates different sessions on multiple calls
- create_session accepts optional base session parameter
- Created session visible in opencode session list
- Add create_session() function that forks from base session using JSON session detection
- cmd_delegate: fork new session from base instead of using pm_agent
- cmd_start: use create_session() instead of broken before/after detection
- cmd_continue: use --session instead of --continue (no need to continue existing session)
- Remove pm_agent check from cmd_start (no longer needed)
With set -u, expanding $GITEA_TOKEN fails if not set.
Changed to ${GITEA_TOKEN:-} to provide empty default.
Also initializes $ENV_DIR/default.env during kugetsu init
so users are aware of the env file structure.
1. daemon: use $WORKTREES_DIR instead of $HOME/.kugetsu-worktrees
- Worktrees are created in ~/.kugetsu/worktrees but daemon was checking ~/.kugetsu-worktrees
- This caused cmd_start to be called when cmd_continue should have been
2. load_agent_env: add fallback to pm-agent.env
- When dev.env and default.env don't exist, fallback to pm-agent.env
- Ensures GITEA_TOKEN is available
3. Remove '&& disown' pattern that causes 'no such job' errors
- nohup already makes process immune to SIGHUP
- disown was causing errors because job context was lost