Compare commits

..

1 Commits

Author SHA1 Message Date
shokollm
591dcb4285 fix(queue-daemon): make base branch configurable via KUGETSU_BASE_BRANCH
- 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
2026-04-08 06:13:08 +00:00
4 changed files with 91 additions and 167 deletions

View File

@@ -17,122 +17,77 @@ usage() {
kugetsu - OpenCode Session Manager (Issue-Driven) kugetsu - OpenCode Session Manager (Issue-Driven)
Usage: Usage:
kugetsu <command> [subcommand] [options] kugetsu init [--force] Initialize base + pm-agent sessions (requires TTY)
kugetsu start <issue-ref> <message> [--debug] Start task for issue (forks base session)
Commands: kugetsu continue <issue-ref> [message] [--debug] Continue existing task for issue
init [--force] Initialize base + pm-agent sessions (requires TTY) kugetsu delegate <message> Send message to PM agent (fire-and-forget)
start <issue-ref> <message> [--debug] Start task for issue (forks base session) kugetsu logs [n] Show recent delegation logs (default: 10)
continue <issue-ref> [message] [--debug] Continue existing task for issue kugetsu status Check kugetsu initialization status
delegate <message> Send message to PM agent (fire-and-forget) kugetsu doctor [--fix] Diagnose and fix kugetsu issues
logs [n] Show recent delegation logs (default: 10) kugetsu notify [list|clear] Show or clear notifications
status Check kugetsu initialization status kugetsu list List all tracked sessions
doctor [--fix] Diagnose and fix kugetsu issues kugetsu prune [--force] Remove orphaned sessions (keeps base + pm-agent)
notify [list|clear] Show or clear notifications kugetsu destroy <issue-ref> [-y] Delete session for issue
list List all tracked sessions kugetsu destroy --pm-agent [-y] Delete pm-agent session (not recommended)
prune [--force] Remove orphaned sessions kugetsu destroy --base [-y] Delete base session
destroy <target> [-y] Delete session (issue, pm-agent, or base) kugetsu set-pr <issue-ref> <pr-url> Set PR URL for session (for PR tracking)
set-pr <issue-ref> <pr-url> Set PR URL for session kugetsu context <issue-ref> Show context for issue
context <issue-ref> Show context for issue kugetsu queue [list|stats|clear] Show queue status or statistics
queue [subcommand] Queue management kugetsu queue enqueue <issue-ref> <message> Enqueue a task (normally via delegate)
queue-daemon [subcommand] Queue daemon management kugetsu queue-daemon [start|stop|restart|status|logs] Manage queue daemon
env [subcommand] Environment variable management kugetsu env [get|set|list] Manage agent environment variables
server [subcommand] Git server configuration kugetsu server [list|add|remove|default|get] Manage git server configurations
help [command] Show help for a command kugetsu help Show this help
Use 'kugetsu <command> help' for subcommand help.
Example: kugetsu queue help, kugetsu queue-daemon help
Issue Ref Format: Issue Ref Format:
instance/user/repo#number instance/user/repo#number
Example: github.com/shoko/kugetsu#14 Example: github.com/shoko/kugetsu#14
EOF
}
usage_queue() { Commands:
cat << 'EOF' init Create base + pm-agent sessions via TUI. Requires terminal access.
kugetsu queue - Queue management Use --force to reinitialize if sessions exist.
start Fork new session from base for specific issue.
Requires pm-agent to be running (created by init).
continue Continue work on existing issue session.
delegate Send message to PM agent for task coordination.
Fire-and-forget: returns immediately, runs in background.
Use 'kugetsu logs' to check output.
logs Show recent delegation logs.
Default: 10 most recent. Use 'kugetsu logs 20' for more.
status Check if kugetsu is initialized and PM agent is active.
doctor Diagnose kugetsu issues. Use --fix to attempt repairs.
notify Show or clear notifications from PM agent.
Use 'kugetsu notify list' to see unread notifications.
list Show all sessions (base + pm-agent + forked issues).
prune Remove sessions not in index (orphaned from opencode).
Use --force to skip confirmation.
destroy Delete specific issue, pm-agent, or base session.
Usage: Options:
kugetsu queue [subcommand] --debug Show real-time debug output and capture to debug.log
Subcommands: PM Context:
list Show pending tasks (default) kugetsu reads ~/.kugetsu/pm-agent.md (if exists) and injects it
stats Show queue statistics into the PM agent session at init time. This allows customizing PM
clear Clear all queue items behavior without recreating the session.
enqueue <issue-ref> <message> Enqueue a task
help Show this help Notifications:
PM Agent writes task completion notifications to ~/.kugetsu/notifications.json
Use 'kugetsu notify list' to see unread notifications.
Examples: Examples:
kugetsu queue list kugetsu init
kugetsu queue stats kugetsu status
kugetsu queue clear kugetsu delegate "work on issue #5"
kugetsu queue enqueue github.com/shoko/kugetsu#14 "fix bug" kugetsu logs
EOF kugetsu logs 20
} kugetsu doctor
kugetsu doctor --fix
usage_queue_daemon() { kugetsu notify list
cat << 'EOF' kugetsu notify clear
kugetsu queue-daemon - Queue daemon management kugetsu start github.com/shoko/kugetsu#14 "fix bug"
kugetsu continue github.com/shoko/kugetsu#14 "add tests"
Usage: kugetsu list
kugetsu queue-daemon [subcommand]
Subcommands:
start Start the queue daemon
stop Stop the queue daemon
restart Restart the queue daemon
status Check daemon status
logs Show recent daemon logs
help Show this help
Examples:
kugetsu queue-daemon start
kugetsu queue-daemon status
kugetsu queue-daemon logs
EOF
}
usage_env() {
cat << 'EOF'
kugetsu env - Environment variable management
Usage:
kugetsu env [subcommand]
Subcommands:
list List all environment variables
get <key> Get a specific variable
set <key> <value> Set a variable
rm <key> Remove a variable
help Show this help
Examples:
kugetsu env list
kugetsu env get GITEA_TOKEN
kugetsu env set CUSTOM_VAR "value"
kugetsu env rm CUSTOM_VAR
EOF
}
usage_server() {
cat << 'EOF'
kugetsu server - Git server configuration
Usage:
kugetsu server [subcommand]
Subcommands:
list List all configured servers (default)
add <name> <url> Add a new server
remove <name> Remove a server
default [<name>] Get or set default server
get [<name>] Get server URL
help Show this help
Examples:
kugetsu server list
kugetsu server add github.com https://github.com
kugetsu server default github.com
EOF EOF
} }
@@ -910,15 +865,10 @@ find_sessions_by_issue_number() {
} }
cmd_queue() { cmd_queue() {
local action="${1:-}" local action="${1:-list}"
shift
case "$action" in case "$action" in
""|help|--help|-h)
usage_queue
;;
help|--help|-h)
usage_queue
;;
list) list)
local pending_tasks=$(get_pending_tasks 10) local pending_tasks=$(get_pending_tasks 10)
if [ "$pending_tasks" = "[]" ]; then if [ "$pending_tasks" = "[]" ]; then
@@ -948,8 +898,8 @@ cmd_queue() {
echo "Queue cleared." echo "Queue cleared."
;; ;;
enqueue) enqueue)
local issue_ref="${2:-}" local issue_ref="${1:-}"
local message="${3:-}" local message="${2:-}"
if [ -z "$issue_ref" ] || [ -z "$message" ]; then if [ -z "$issue_ref" ] || [ -z "$message" ]; then
echo "Usage: kugetsu queue enqueue <issue-ref> <message>" >&2 echo "Usage: kugetsu queue enqueue <issue-ref> <message>" >&2
exit 1 exit 1
@@ -960,20 +910,16 @@ cmd_queue() {
check_task_timeouts check_task_timeouts
;; ;;
*) *)
echo "Unknown queue subcommand: $action" >&2 echo "Usage: kugetsu queue [list|stats|clear|enqueue]" >&2
usage_queue
exit 1 exit 1
;; ;;
esac esac
} }
cmd_queue_daemon() { cmd_queue_daemon() {
local action="${1:-}" local action="${1:-status}"
case "$action" in case "$action" in
""|help|--help|-h)
usage_queue_daemon
;;
start) start)
if [ -f "$QUEUE_DAEMON_PID_FILE" ]; then if [ -f "$QUEUE_DAEMON_PID_FILE" ]; then
local old_pid=$(cat "$QUEUE_DAEMON_PID_FILE") local old_pid=$(cat "$QUEUE_DAEMON_PID_FILE")
@@ -1032,8 +978,7 @@ cmd_queue_daemon() {
fi fi
;; ;;
*) *)
echo "Unknown queue-daemon subcommand: $action" >&2 echo "Usage: kugetsu queue-daemon [start|stop|restart|status|logs]" >&2
usage_queue_daemon
exit 1 exit 1
;; ;;
esac esac
@@ -1114,12 +1059,10 @@ set_debug_mode() {
} }
cmd_env() { cmd_env() {
local action="${1:-}" local action="${1:-list}"
shift
case "$action" in case "$action" in
""|help|--help|-h)
usage_env
;;
list) list)
echo "Agent environment variables:" echo "Agent environment variables:"
if [ -d "$ENV_DIR" ]; then if [ -d "$ENV_DIR" ]; then
@@ -1137,7 +1080,7 @@ cmd_env() {
fi fi
;; ;;
get) get)
local key="${2:-}" local key="${1:-}"
if [ -z "$key" ]; then if [ -z "$key" ]; then
echo "Usage: kugetsu env get <key>" >&2 echo "Usage: kugetsu env get <key>" >&2
exit 1 exit 1
@@ -1152,8 +1095,8 @@ cmd_env() {
fi fi
;; ;;
set) set)
local key="${2:-}" local key="${1:-}"
local value="${3:-}" local value="${2:-}"
if [ -z "$key" ] || [ -z "$value" ]; then if [ -z "$key" ] || [ -z "$value" ]; then
echo "Usage: kugetsu env set <key> <value>" >&2 echo "Usage: kugetsu env set <key> <value>" >&2
exit 1 exit 1
@@ -1162,8 +1105,8 @@ cmd_env() {
echo "${key}=${value}" >> "$ENV_DIR/default.env" echo "${key}=${value}" >> "$ENV_DIR/default.env"
echo "Set $key in $ENV_DIR/default.env" echo "Set $key in $ENV_DIR/default.env"
;; ;;
rm|remove) rm)
local key="${2:-}" local key="${1:-}"
if [ -z "$key" ]; then if [ -z "$key" ]; then
echo "Usage: kugetsu env rm <key>" >&2 echo "Usage: kugetsu env rm <key>" >&2
exit 1 exit 1
@@ -1174,8 +1117,7 @@ cmd_env() {
fi fi
;; ;;
*) *)
echo "Unknown env subcommand: $action" >&2 echo "Usage: kugetsu env [list|get|set|rm]" >&2
usage_env
exit 1 exit 1
;; ;;
esac esac
@@ -1185,10 +1127,7 @@ cmd_server() {
local action="${1:-}" local action="${1:-}"
case "$action" in case "$action" in
""|help|--help|-h) ""|"list")
usage_server
;;
"list")
if [ -z "${GIT_SERVERS+x}" ]; then if [ -z "${GIT_SERVERS+x}" ]; then
echo "No git servers configured" echo "No git servers configured"
return return
@@ -1265,8 +1204,14 @@ cmd_server() {
fi fi
;; ;;
*) *)
echo "Unknown server subcommand: $action" >&2 echo "Usage: kugetsu server <list|add|remove|default|get>" >&2
usage_server echo "" >&2
echo "Commands:" >&2
echo " list List all configured git servers" >&2
echo " add <name> <url> Add a new git server" >&2
echo " remove <name> Remove a git server" >&2
echo " default [<name>] Get or set default server" >&2
echo " get [<name>] Get URL for a server (default: current default)" >&2
exit 1 exit 1
;; ;;
esac esac
@@ -1376,29 +1321,7 @@ main() {
case "$command" in case "$command" in
help|--help|-h) help|--help|-h)
local subcommand="${1:-}" usage
case "$subcommand" in
queue|"")
usage_queue
;;
queue-daemon)
usage_queue_daemon
;;
env)
usage_env
;;
server)
usage_server
;;
"")
usage
;;
*)
echo "Help not available for '$subcommand'" >&2
usage
exit 1
;;
esac
;; ;;
init) init)
cmd_init "$@" cmd_init "$@"

View File

@@ -28,6 +28,7 @@ TASK_TIMEOUT_HOURS="${TASK_TIMEOUT_HOURS:-1}"
NETWORK_RETRY_ATTEMPTS="${NETWORK_RETRY_ATTEMPTS:-3}" NETWORK_RETRY_ATTEMPTS="${NETWORK_RETRY_ATTEMPTS:-3}"
NETWORK_RETRY_DELAY_SECONDS="${NETWORK_RETRY_DELAY_SECONDS:-5}" NETWORK_RETRY_DELAY_SECONDS="${NETWORK_RETRY_DELAY_SECONDS:-5}"
KUGETSU_BASE_BRANCH="${KUGETSU_BASE_BRANCH:-origin/main}"
# Load user config overrides (~/.kugetsu/config) # Load user config overrides (~/.kugetsu/config)
if [ -f "$KUGETSU_DIR/config" ]; then if [ -f "$KUGETSU_DIR/config" ]; then

View File

@@ -75,7 +75,7 @@ check_task_completion() {
local has_commits=false local has_commits=false
if [ -d "$worktree_path" ] && [ -d "$worktree_path/.git" ]; then if [ -d "$worktree_path" ] && [ -d "$worktree_path/.git" ]; then
if [ -n "$(git -C "$worktree_path" log --oneline origin/main..HEAD 2>/dev/null)" ]; then if [ -n "$(git -C "$worktree_path" log --oneline "$KUGETSU_BASE_BRANCH..HEAD" 2>/dev/null)" ]; then
has_commits=true has_commits=true
fi fi
fi fi
@@ -95,7 +95,7 @@ check_task_completion() {
local has_commits=false local has_commits=false
if [ -d "$worktree_path" ] && [ -d "$worktree_path/.git" ]; then if [ -d "$worktree_path" ] && [ -d "$worktree_path/.git" ]; then
if [ -n "$(git -C "$worktree_path" log --oneline origin/main..HEAD 2>/dev/null)" ]; then if [ -n "$(git -C "$worktree_path" log --oneline "$KUGETSU_BASE_BRANCH..HEAD" 2>/dev/null)" ]; then
has_commits=true has_commits=true
fi fi
fi fi

View File

@@ -109,7 +109,7 @@ create_worktree() {
fi fi
echo "Creating branch '$branch_name'..." echo "Creating branch '$branch_name'..."
if git -C "$worktree_path" checkout -b "$branch_name" origin/main 2>/dev/null; then if git -C "$worktree_path" checkout -b "$branch_name" "$KUGETSU_BASE_BRANCH" 2>/dev/null; then
: :
elif git -C "$worktree_path" checkout -b "$branch_name" main 2>/dev/null; then elif git -C "$worktree_path" checkout -b "$branch_name" main 2>/dev/null; then
: :