Compare commits

..

1 Commits

Author SHA1 Message Date
shokollm
b28ad78bd8 fix(queue): add --format=json and --limit flags to queue list 2026-04-08 06:20:52 +00:00
2 changed files with 56 additions and 29 deletions

View File

@@ -364,14 +364,10 @@ kugetsu queue-daemon logs # Show recent daemon logs
**Daemon Behavior:** **Daemon Behavior:**
1. Runs at configurable interval (default: 5 minutes) 1. Runs at configurable interval (default: 5 minutes)
2. Checks queue for pending items 2. Checks if active agents < MAX_CONCURRENT_AGENTS
3. For each pending item: 3. Picks 1-N pending items (configurable batch size)
- Acquires lock to prevent duplicate processing 4. Forks PM session for each picked item
- Sources kugetsu-session.sh and calls `cmd_continue` 5. PM decides whether to use `start` or `continue`
- `cmd_continue` handles worktree/session creation and forks dev agent from base session
- Updates queue item state to "notified"
4. Uses per-issue locking to prevent race conditions
5. Implements timeout for tasks that don't complete (marks as "error" after TASK_TIMEOUT_HOURS)
**Queue Directory:** **Queue Directory:**
``` ```
@@ -530,13 +526,6 @@ The script will:
See [docs/kugetsu-setup.md](../../docs/kugetsu-setup.md) for full Tailscale setup documentation. See [docs/kugetsu-setup.md](../../docs/kugetsu-setup.md) for full Tailscale setup documentation.
## Version History
### v0.2.3
- **Queue daemon context drift fix** (issue #156): Daemon now sources kugetsu-session.sh and calls `cmd_continue` directly instead of forking PM session. This fixes context drift where daemon would lose track of task state.
- **Daemon locking**: Added per-issue locking to prevent race conditions when multiple daemon instances run.
- **Timeout handling**: Tasks that don't complete within TASK_TIMEOUT_HOURS are marked as "error".
## Without kugetsu ## Without kugetsu
If kugetsu is not available, use opencode directly: If kugetsu is not available, use opencode directly:

View File

@@ -56,14 +56,21 @@ Usage:
kugetsu queue [subcommand] kugetsu queue [subcommand]
Subcommands: Subcommands:
list Show pending tasks (default) list [--limit=N] [--format=json] Show pending tasks (default: 10 items, text format)
stats Show queue statistics stats Show queue statistics
clear Clear all queue items clear Clear all queue items
enqueue <issue-ref> <message> Enqueue a task enqueue <issue-ref> <message> Enqueue a task
help Show this help help Show this help
Options for list:
--limit=N Number of items to return (default: 10)
--format=json Output in JSON format with stats
Examples: Examples:
kugetsu queue list kugetsu queue list
kugetsu queue list --limit=50
kugetsu queue list --format=json
kugetsu queue list --limit=20 --format=json
kugetsu queue stats kugetsu queue stats
kugetsu queue clear kugetsu queue clear
kugetsu queue enqueue github.com/shoko/kugetsu#14 "fix bug" kugetsu queue enqueue github.com/shoko/kugetsu#14 "fix bug"
@@ -355,19 +362,25 @@ PYEOF
get_pending_tasks() { get_pending_tasks() {
local limit="${1:-10}" local limit="${1:-10}"
local format="${2:-text}"
if [ ! -d "$QUEUE_ITEMS_DIR" ]; then if [ ! -d "$QUEUE_ITEMS_DIR" ]; then
echo "[]" if [ "$format" = "json" ]; then
echo '{"items": [], "total": 0, "pending": 0}'
else
echo "No pending tasks in queue."
fi
return return
fi fi
python3 -c " python3 << PYEOF
import json import json
import os import os
import sys import sys
queue_dir = os.environ.get('QUEUE_ITEMS_DIR', '') queue_dir = os.environ.get('QUEUE_ITEMS_DIR', '')
limit = int(sys.argv[1]) if len(sys.argv) > 1 else 10 limit = int(sys.argv[1]) if len(sys.argv) > 1 else 10
format_type = sys.argv[2] if len(sys.argv) > 2 else 'text'
items = [] items = []
if os.path.isdir(queue_dir): if os.path.isdir(queue_dir):
@@ -379,13 +392,27 @@ if os.path.isdir(queue_dir):
data = json.load(f) data = json.load(f)
if data.get('state') == 'pending': if data.get('state') == 'pending':
items.append(data) items.append(data)
if len(items) >= limit:
break
except: except:
pass pass
print(json.dumps(items)) items.sort(key=lambda x: x.get('pending_since', ''))
" "$limit"
if format_type == 'json':
output = {
"items": items[:limit],
"total": len(items),
"pending": len(items)
}
print(json.dumps(output))
else:
if not items:
print("No pending tasks in queue.")
else:
print("Pending tasks:")
for t in items[:limit]:
msg = t.get('message', '')[:50]
print(f" {t.get('id')}: {t.get('issue_ref')} - {msg}...")
PYEOF
} }
get_queue_stats() { get_queue_stats() {
@@ -920,13 +947,24 @@ cmd_queue() {
usage_queue usage_queue
;; ;;
list) list)
local pending_tasks=$(get_pending_tasks 10) local limit="10"
if [ "$pending_tasks" = "[]" ]; then local format="text"
echo "No pending tasks in queue."
else while [ $# -gt 0 ]; do
echo "Pending tasks:" case "$1" in
echo "$pending_tasks" | python3 -c "import sys, json; [print(f\" {t.get('id')}: {t.get('issue_ref')} - {t.get('message', '')[:50]}...\") for t in json.load(sys.stdin)]" --limit=*)
fi limit="${1#*=}"
;;
--format=json)
format="json"
;;
*)
;;
esac
shift
done
get_pending_tasks "$limit" "$format"
;; ;;
stats) stats)
local stats=$(get_queue_stats) local stats=$(get_queue_stats)