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)
- 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
- 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
cmd_start was calling create_worktree without passing $WORKTREES_DIR,
causing worktrees to be created in $PWD (daemon's working directory)
instead of ~/.kugetsu-worktrees/
Removed erroneous code that set target="" when target="--base".
This caused the early exit at 'if [ -z "$target" ]' to trigger
before reaching the actual --base handling at line 517.
Fix issue where full URLs like #158
were incorrectly parsed to 'shoko/kugetsu/issues#158' instead of
'git.fbrns.co/shoko/kugetsu#158'.
The regex now correctly extracts instance, owner, repo, and number
using bash regex capture groups instead of fragile sed/cut pipeline.
The init script used 'tail -1' to find newly created sessions, which
fails when old sessions exist because it picks an existing session
instead of the newly created one.
The fix captures session IDs before and after creating new sessions,
then diffs to identify newly created sessions.
Fixes#172
When daemon sources kugetsu-session.sh to call cmd_start/cmd_continue,
it needs access to functions from kugetsu-config.sh, kugetsu-index.sh,
kugetsu-worktree.sh, and kugetsu-log.sh. Add sourcing at top of
kugetsu-session.sh.
When cmd_delegate detects an issue ref with number (e.g. git.fbrns.co/shoko/kugetsu#158),
it was calling cmd_start directly which tries to create worktree and clone.
This breaks the queue-based workflow where daemon should handle task execution.
Now cmd_delegate calls enqueue_task to add to queue, and daemon processes
tasks by calling cmd_start/cmd_continue as appropriate.
Split the monolithic kugetsu script into modular components:
Modules created:
- kugetsu-config.sh - Config/env loading and global variables
- kugetsu-index.sh - Index.json read/write via JSON
- kugetsu-worktree.sh - Git worktree operations
- kugetsu-log.sh - Structured logging and notifications
- kugetsu-session.sh - Session create/fork/destroy logic
- kugetsu-queue-daemon.sh - Queue daemon subprocess
Main script (kugetsu) is now a thin dispatcher that sources all modules.
Acceptance Criteria:
- All existing commands work exactly as before
- Main script sources modules
- Each module is independently testable
Fixes#116