From b1028a65560e9c76ffc700141c29b0473eb030ea Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Sun, 5 Apr 2026 22:17:59 +0000 Subject: [PATCH] fix(kugetsu): move queue functions to kugetsu-index.sh for daemon access The daemon (kugetsu-queue-daemon.sh) sources kugetsu-index.sh but not the main kugetsu script. Move update_queue_item_state and kugetsu_add_notification to kugetsu-index.sh so the daemon can use these functions when processing tasks. --- skills/kugetsu/scripts/kugetsu-index.sh | 92 +++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/skills/kugetsu/scripts/kugetsu-index.sh b/skills/kugetsu/scripts/kugetsu-index.sh index eb85d26..eba8a90 100755 --- a/skills/kugetsu/scripts/kugetsu-index.sh +++ b/skills/kugetsu/scripts/kugetsu-index.sh @@ -146,3 +146,95 @@ filename_to_issue_ref() { local name="${filename%.json}" echo "$name" | sed 's-\([0-9]*\)$-#\1-' | sed 's/-/\//g' } + +# Add notification to notifications file +kugetsu_add_notification() { + local type="$1" + local message="$2" + local issue_ref="${3:-}" + local gitea_url="${4:-}" + + mkdir -p "$(dirname "$NOTIFICATIONS_FILE")" + + python3 << PYEOF +import json +import os +from datetime import datetime + +notification = { + "type": "$type", + "message": "$message", + "issue_ref": "$issue_ref" if "$issue_ref" else None, + "gitea_url": "$gitea_url" if "$gitea_url" else None, + "timestamp": datetime.now().isoformat(), + "read": False +} + +file_path = os.path.expanduser("$NOTIFICATIONS_FILE") +notifications = [] + +if os.path.exists(file_path): + try: + with open(file_path, 'r') as f: + notifications = json.load(f) + except: + notifications = [] + +notifications.append(notification) + +with open(file_path, 'w') as f: + json.dump(notifications, f, indent=2) + +print("Notification added") +PYEOF +} + +# Update queue item state +update_queue_item_state() { + local queue_id="$1" + local new_state="$2" + local session_id="${3:-}" + local pid="${4:-}" + + local item_file="$QUEUE_ITEMS_DIR/${queue_id}.json" + if [ ! -f "$item_file" ]; then + echo "Error: Queue item not found: $queue_id" >&2 + return 1 + fi + + python3 << PYEOF +import json +import os +from datetime import datetime + +item_file = "$item_file" +new_state = "$new_state" +session_id = "$session_id" +pid = "$pid" + +with open(item_file, 'r') as f: + item = json.load(f) + +issue_ref = item.get('issue_ref', '') + +item['state'] = new_state + +if new_state == "notified": + item['notified_at'] = datetime.now().isoformat() + "Z" + if session_id: + item['opencode_session_id'] = session_id + if pid: + item['pid'] = int(pid) if pid.isdigit() else None +elif new_state == "completed": + item['completed_at'] = datetime.now().isoformat() + "Z" + os.system(f"kugetsu_add_notification 'task_completed' 'Task completed: {issue_ref}' '{issue_ref}'") +elif new_state == "error": + item['error'] = datetime.now().isoformat() + "Z" + os.system(f"kugetsu_add_notification 'task_error' 'Task error: {issue_ref}' '{issue_ref}'") + +with open(item_file, 'w') as f: + json.dump(item, f, indent=2) + +print(f"Updated $queue_id to state: $new_state") +PYEOF +}