feat(kugetsu): implement fire-and-forget delegation
- cmd_delegate now runs in background with nohup + disown - Output logged to ~/.kugetsu/logs/delegate-<timestamp>.log - Added cmd_logs to view recent delegation logs - Log rotation: logs older than 7 days auto-deleted Issue #41: #41
This commit is contained in:
@@ -7,6 +7,7 @@ WORKTREES_DIR="$KUGETSU_DIR/worktrees"
|
||||
REPOS_CONFIG="$KUGETSU_DIR/repos.json"
|
||||
INDEX_FILE="$KUGETSU_DIR/index.json"
|
||||
NOTIFICATIONS_FILE="$KUGETSU_DIR/notifications.json"
|
||||
LOGS_DIR="$KUGETSU_DIR/logs"
|
||||
|
||||
usage() {
|
||||
cat << 'EOF'
|
||||
@@ -16,7 +17,8 @@ Usage:
|
||||
kugetsu init [--force] Initialize base + pm-agent sessions (requires TTY)
|
||||
kugetsu start <issue-ref> <message> [--debug] Start task for issue (forks base session)
|
||||
kugetsu continue <issue-ref> [message] [--debug] Continue existing task for issue
|
||||
kugetsu delegate <message> Send message to PM agent
|
||||
kugetsu delegate <message> Send message to PM agent (fire-and-forget)
|
||||
kugetsu logs [n] Show recent delegation logs (default: 10)
|
||||
kugetsu status Check kugetsu initialization status
|
||||
kugetsu doctor [--fix] Diagnose and fix kugetsu issues
|
||||
kugetsu notify [list|clear] Show or clear notifications
|
||||
@@ -38,7 +40,10 @@ Commands:
|
||||
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.
|
||||
PM context is loaded once at init time.
|
||||
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.
|
||||
@@ -64,6 +69,8 @@ Examples:
|
||||
kugetsu init
|
||||
kugetsu status
|
||||
kugetsu delegate "work on issue #5"
|
||||
kugetsu logs
|
||||
kugetsu logs 20
|
||||
kugetsu doctor
|
||||
kugetsu doctor --fix
|
||||
kugetsu notify list
|
||||
@@ -493,7 +500,27 @@ cmd_delegate() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
opencode run --continue --session "$pm_session" "$message" 2>&1
|
||||
mkdir -p "$LOGS_DIR"
|
||||
local log_file="$LOGS_DIR/delegate-$(date +%s).log"
|
||||
nohup opencode run --continue --session "$pm_session" "$message" > "$log_file" 2>&1 &
|
||||
disown
|
||||
echo "Delegated to PM agent (logged to $(basename "$log_file"))"
|
||||
}
|
||||
|
||||
cmd_logs() {
|
||||
local count="${1:-10}"
|
||||
|
||||
if [ ! -d "$LOGS_DIR" ]; then
|
||||
echo "No logs found."
|
||||
return
|
||||
fi
|
||||
|
||||
# Log rotation: delete logs older than 7 days
|
||||
find "$LOGS_DIR" -type f -mtime +7 -delete 2>/dev/null
|
||||
|
||||
ls -lt "$LOGS_DIR" | head -$((count + 1)) | tail -$count | while read line; do
|
||||
echo "$line"
|
||||
done
|
||||
}
|
||||
|
||||
cmd_doctor() {
|
||||
@@ -1092,6 +1119,10 @@ main() {
|
||||
delegate)
|
||||
cmd_delegate "$@"
|
||||
;;
|
||||
logs)
|
||||
shift
|
||||
cmd_logs "$@"
|
||||
;;
|
||||
status)
|
||||
cmd_status
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user