Compare commits
6 Commits
fix/issue-
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f6a30f01c | ||
|
|
f39e39156a | ||
| deb18f1e32 | |||
|
|
cbfc8a0646 | ||
|
|
7fa669b4c3 | ||
| acb503471d |
@@ -99,17 +99,6 @@ ensure_worktree_dir() {
|
||||
mkdir -p "$WORKTREES_DIR"
|
||||
}
|
||||
|
||||
issue_ref_to_filename() {
|
||||
local issue_ref="$1"
|
||||
echo "$issue_ref" | sed 's/[\/:]/-/g' | sed 's/#/-/'
|
||||
}
|
||||
|
||||
filename_to_issue_ref() {
|
||||
local filename="$1"
|
||||
local name="${filename%.json}"
|
||||
echo "$name" | sed 's/-\([0-9]*\)$/#\1/' | sed 's/-/\//g'
|
||||
}
|
||||
|
||||
issue_ref_to_context_file() {
|
||||
local issue_ref="$1"
|
||||
local context_filename=$(issue_ref_to_filename "$issue_ref")
|
||||
@@ -321,12 +310,31 @@ get_pending_tasks() {
|
||||
return
|
||||
fi
|
||||
|
||||
find "$QUEUE_ITEMS_DIR" -name "*.json" -type f 2>/dev/null | while read -r file; do
|
||||
local state=$(python3 -c "import json; print(json.load(open('$file')).get('state', ''))" 2>/dev/null || echo "")
|
||||
if [ "$state" = "pending" ]; then
|
||||
cat "$file"
|
||||
fi
|
||||
done | head -"$limit"
|
||||
python3 -c "
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
queue_dir = os.environ.get('QUEUE_ITEMS_DIR', '')
|
||||
limit = int(sys.argv[1]) if len(sys.argv) > 1 else 10
|
||||
|
||||
items = []
|
||||
if os.path.isdir(queue_dir):
|
||||
for filename in os.listdir(queue_dir):
|
||||
if filename.endswith('.json'):
|
||||
filepath = os.path.join(queue_dir, filename)
|
||||
try:
|
||||
with open(filepath) as f:
|
||||
data = json.load(f)
|
||||
if data.get('state') == 'pending':
|
||||
items.append(data)
|
||||
if len(items) >= limit:
|
||||
break
|
||||
except:
|
||||
pass
|
||||
|
||||
print(json.dumps(items))
|
||||
" "$limit"
|
||||
}
|
||||
|
||||
get_queue_stats() {
|
||||
|
||||
@@ -133,3 +133,16 @@ with open(session_path, 'w') as f:
|
||||
print(f"Updated PR URL for $issue_ref: $pr_url")
|
||||
PYEOF
|
||||
}
|
||||
|
||||
# Convert issue ref to session filename
|
||||
issue_ref_to_filename() {
|
||||
local issue_ref="$1"
|
||||
echo "$issue_ref" | sed 's/[\/:]/-/g' | sed 's/#/-/'
|
||||
}
|
||||
|
||||
# Convert session filename back to issue ref
|
||||
filename_to_issue_ref() {
|
||||
local filename="$1"
|
||||
local name="${filename%.json}"
|
||||
echo "$name" | sed 's-\([0-9]*\)$-#\1-' | sed 's/-/\//g'
|
||||
}
|
||||
|
||||
30
skills/kugetsu/scripts/kugetsu-queue-daemon.sh
Executable file → Normal file
30
skills/kugetsu/scripts/kugetsu-queue-daemon.sh
Executable file → Normal file
@@ -8,7 +8,9 @@ source "$SCRIPT_DIR/kugetsu-index.sh"
|
||||
source "$SCRIPT_DIR/kugetsu-worktree.sh"
|
||||
source "$SCRIPT_DIR/kugetsu-log.sh"
|
||||
|
||||
# Check if a notified task has completed (session ended or has new commits)
|
||||
load_agent_env "pm-agent"
|
||||
|
||||
# Check if a notified task has completed (forked session ended or has new commits)
|
||||
check_task_completion() {
|
||||
local item="$1"
|
||||
local queue_id=$(basename "$item" .json)
|
||||
@@ -16,15 +18,16 @@ check_task_completion() {
|
||||
|
||||
[ "$state" = "notified" ] || return 0
|
||||
|
||||
local session_id=$(python3 -c "import json; print(json.load(open('$item')).get('session_id', ''))" 2>/dev/null)
|
||||
# Use opencode_session_id (the forked session, not the parent pm_session)
|
||||
local session_id=$(python3 -c "import json; print(json.load(open('$item')).get('opencode_session_id', ''))" 2>/dev/null)
|
||||
local issue_ref=$(python3 -c "import json; print(json.load(open('$item')).get('issue_ref', ''))" 2>/dev/null)
|
||||
|
||||
# If no session tracked, skip
|
||||
[ -n "$session_id" ] || return 0
|
||||
|
||||
# Check if session still exists in opencode
|
||||
# Check if forked session still exists in opencode
|
||||
if ! opencode session list 2>/dev/null | grep -q "$session_id"; then
|
||||
# Session ended — check if work was done
|
||||
# Forked session ended — check if work was done
|
||||
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref" "$HOME/.kugetsu-worktrees")
|
||||
local has_commits=false
|
||||
|
||||
@@ -62,12 +65,23 @@ while true; do
|
||||
issue_ref=$(python3 -c "import json; print(json.load(open('$item')).get('issue_ref', ''))" 2>/dev/null)
|
||||
message=$(python3 -c "import json; print(json.load(open('$item')).get('message', ''))" 2>/dev/null)
|
||||
|
||||
pm_session=$(get_pm_agent_session_id)
|
||||
if [ -n "$pm_session" ] && [ "$pm_session" != "null" ]; then
|
||||
# Source session management and use cmd_start/cmd_continue
|
||||
source "$SCRIPT_DIR/kugetsu-session.sh"
|
||||
|
||||
if worktree_exists "$issue_ref" "$HOME/.kugetsu-worktrees" || [ -f "$SESSIONS_DIR/$(issue_ref_to_filename "$issue_ref").json" ]; then
|
||||
# Continue existing session
|
||||
log_file="$LOGS_DIR/delegate-$(date +%s).log"
|
||||
nohup env GITEA_TOKEN="$GITEA_TOKEN" sh -c "opencode run '$message' --continue --session '$pm_session' >> '$log_file' 2>&1" > /dev/null 2>&1 &
|
||||
cmd_continue "$issue_ref" "$message" >> "$log_file" 2>&1 &
|
||||
pid=$!
|
||||
update_queue_item_state "$queue_id" "notified" "$pm_session" "$pid"
|
||||
update_queue_item_state "$queue_id" "notified" "" "$pid"
|
||||
echo "Task $queue_id continued for $issue_ref"
|
||||
else
|
||||
# Start new session
|
||||
log_file="$LOGS_DIR/delegate-$(date +%s).log"
|
||||
cmd_start "$issue_ref" "$message" >> "$log_file" 2>&1 &
|
||||
pid=$!
|
||||
update_queue_item_state "$queue_id" "notified" "" "$pid"
|
||||
echo "Task $queue_id started for $issue_ref"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user