Compare commits
12 Commits
fix/issue-
...
v0.2.7
| Author | SHA1 | Date | |
|---|---|---|---|
| 80a3228be9 | |||
|
|
d68a63af41 | ||
| 56310755b8 | |||
|
|
fb33be3a64 | ||
| 1b19c9a92c | |||
|
|
85a4239383 | ||
|
|
91b51f62c0 | ||
| 7234837284 | |||
|
|
59f6a4883e | ||
| 9667c3e800 | |||
|
|
796e1fe454 | ||
| 84c59a3b64 |
@@ -6,6 +6,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [v0.2.4] - 2026-04-06
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Queue daemon: Locking to prevent daemon vs manual conflicts
|
||||||
|
- Queue daemon: Proper error handling for failed tasks
|
||||||
|
- Queue daemon: Fix GITEA_TOKEN loading from pm-agent.env
|
||||||
|
- cmd_delegate: Enqueue tasks instead of bypassing queue
|
||||||
|
- Notifications: Call kugetsu_add_notification from bash instead of os.system()
|
||||||
|
- kugetsu: Remove duplicate update_queue_item_state that overwrote fixed version
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Queue functions moved to kugetsu-index.sh for daemon access
|
||||||
|
- kugetsu-session.sh sources required modules for daemon use
|
||||||
|
|
||||||
|
## [v0.2.3] - 2026-04-06
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- get_pending_tasks() returns proper JSON array instead of concatenated JSON objects
|
||||||
|
|
||||||
## [v0.2.1] - 2026-04-03
|
## [v0.2.1] - 2026-04-03
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ EOF
|
|||||||
|
|
||||||
ensure_dirs() {
|
ensure_dirs() {
|
||||||
mkdir -p "$SESSIONS_DIR"
|
mkdir -p "$SESSIONS_DIR"
|
||||||
|
mkdir -p "$LOGS_DIR"
|
||||||
|
mkdir -p "$WORKTREES_DIR"
|
||||||
|
mkdir -p "$QUEUE_DIR"
|
||||||
|
mkdir -p "$QUEUE_ITEMS_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_worktree_dir() {
|
ensure_worktree_dir() {
|
||||||
@@ -257,7 +261,9 @@ PYEOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensure_queue_dirs() {
|
ensure_queue_dirs() {
|
||||||
|
mkdir -p "$QUEUE_DIR"
|
||||||
mkdir -p "$QUEUE_ITEMS_DIR"
|
mkdir -p "$QUEUE_ITEMS_DIR"
|
||||||
|
mkdir -p "$LOGS_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_queue_id() {
|
generate_queue_id() {
|
||||||
@@ -361,55 +367,6 @@ get_queue_stats() {
|
|||||||
echo "{\"total\": $total, \"pending\": $pending, \"notified\": $notified, \"completed\": $completed, \"error\": $error}"
|
echo "{\"total\": $total, \"pending\": $pending, \"notified\": $notified, \"completed\": $completed, \"error\": $error}"
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
check_task_timeouts() {
|
check_task_timeouts() {
|
||||||
if [ ! -d "$QUEUE_ITEMS_DIR" ]; then
|
if [ ! -d "$QUEUE_ITEMS_DIR" ]; then
|
||||||
return
|
return
|
||||||
@@ -897,6 +854,11 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_issue_ref_from_message() {
|
parse_issue_ref_from_message() {
|
||||||
|
# DEPRECATED: This function is not called anywhere.
|
||||||
|
# The active implementation is extract_issue_ref_from_message()
|
||||||
|
# in kugetsu-session.sh which is used by cmd_delegate.
|
||||||
|
# This function is kept for backwards compatibility and will
|
||||||
|
# be removed in a future release.
|
||||||
local message="$1"
|
local message="$1"
|
||||||
|
|
||||||
local gitserver=""
|
local gitserver=""
|
||||||
@@ -904,21 +866,20 @@ parse_issue_ref_from_message() {
|
|||||||
local repo=""
|
local repo=""
|
||||||
local issue_number=""
|
local issue_number=""
|
||||||
|
|
||||||
if echo "$message" | grep -qE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(issues|pull)/[0-9]+'; then
|
if [[ "$message" =~ (https?://)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)/(issues|pull)/([0-9]+) ]]; then
|
||||||
gitserver=$(echo "$message" | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+' | head -1 | sed 's/\/[^/]*\/[^/]*$//')
|
gitserver="${BASH_REMATCH[2]}"
|
||||||
local full_path=$(echo "$message" | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(issues|pull)/[0-9]+' | head -1)
|
owner="${BASH_REMATCH[3]}"
|
||||||
owner=$(echo "$full_path" | cut -d'/' -f2)
|
repo="${BASH_REMATCH[4]}"
|
||||||
repo=$(echo "$full_path" | cut -d'/' -f3)
|
issue_number="${BASH_REMATCH[6]}"
|
||||||
issue_number=$(echo "$full_path" | grep -oE '[0-9]+$' | head -1)
|
elif [[ "$message" =~ (https?://)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)#([0-9]+) ]]; then
|
||||||
elif echo "$message" | grep -qE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+#[0-9]+'; then
|
gitserver="${BASH_REMATCH[2]}"
|
||||||
gitserver=$(echo "$message" | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+' | head -1)
|
owner="${BASH_REMATCH[3]}"
|
||||||
owner=$(echo "$gitserver" | cut -d'/' -f2)
|
repo="${BASH_REMATCH[4]}"
|
||||||
repo=$(echo "$gitserver" | cut -d'/' -f3)
|
issue_number="${BASH_REMATCH[5]}"
|
||||||
issue_number=$(echo "$message" | grep -oE '#[0-9]+' | grep -oE '[0-9]+' | head -1)
|
elif [[ "$message" =~ ([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)#([0-9]+) ]]; then
|
||||||
elif echo "$message" | grep -qE '[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+#([0-9]+)'; then
|
owner="${BASH_REMATCH[1]}"
|
||||||
owner=$(echo "$message" | grep -oE '[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+#' | sed 's/#$//' | cut -d'/' -f1)
|
repo="${BASH_REMATCH[2]}"
|
||||||
repo=$(echo "$message" | grep -oE '[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+#' | sed 's/#$//' | cut -d'/' -f2)
|
issue_number="${BASH_REMATCH[3]}"
|
||||||
issue_number=$(echo "$message" | grep -oE '#[0-9]+' | grep -oE '[0-9]+' | head -1)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${gitserver}|${owner}|${repo}|${issue_number}"
|
echo "${gitserver}|${owner}|${repo}|${issue_number}"
|
||||||
|
|||||||
@@ -202,9 +202,10 @@ update_queue_item_state() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local issue_ref=$(python3 -c "import json; print(json.load(open('$item_file')).get('issue_ref', ''))" 2>/dev/null || echo "")
|
||||||
|
|
||||||
python3 << PYEOF
|
python3 << PYEOF
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
item_file = "$item_file"
|
item_file = "$item_file"
|
||||||
@@ -215,8 +216,6 @@ pid = "$pid"
|
|||||||
with open(item_file, 'r') as f:
|
with open(item_file, 'r') as f:
|
||||||
item = json.load(f)
|
item = json.load(f)
|
||||||
|
|
||||||
issue_ref = item.get('issue_ref', '')
|
|
||||||
|
|
||||||
item['state'] = new_state
|
item['state'] = new_state
|
||||||
|
|
||||||
if new_state == "notified":
|
if new_state == "notified":
|
||||||
@@ -227,14 +226,18 @@ if new_state == "notified":
|
|||||||
item['pid'] = int(pid) if pid.isdigit() else None
|
item['pid'] = int(pid) if pid.isdigit() else None
|
||||||
elif new_state == "completed":
|
elif new_state == "completed":
|
||||||
item['completed_at'] = datetime.now().isoformat() + "Z"
|
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":
|
elif new_state == "error":
|
||||||
item['error'] = datetime.now().isoformat() + "Z"
|
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:
|
with open(item_file, 'w') as f:
|
||||||
json.dump(item, f, indent=2)
|
json.dump(item, f, indent=2)
|
||||||
|
|
||||||
print(f"Updated $queue_id to state: $new_state")
|
print(f"Updated $queue_id to state: $new_state")
|
||||||
PYEOF
|
PYEOF
|
||||||
|
|
||||||
|
if [ "$new_state" = "completed" ]; then
|
||||||
|
kugetsu_add_notification "task_completed" "Task completed: $issue_ref" "$issue_ref"
|
||||||
|
elif [ "$new_state" = "error" ]; then
|
||||||
|
kugetsu_add_notification "task_error" "Task error: $issue_ref" "$issue_ref"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,15 +43,24 @@ kugetsu_add_notification() {
|
|||||||
notifications=$(cat "$NOTIFICATIONS_FILE")
|
notifications=$(cat "$NOTIFICATIONS_FILE")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local new_notification=$(python3 -c "import json; print(json.dumps({
|
notifications=$(echo "$notifications" | python3 -c "
|
||||||
'type': '$notification_type',
|
import json
|
||||||
'message': '$message',
|
import sys
|
||||||
'issue_ref': '$issue_ref',
|
|
||||||
'timestamp': '$timestamp',
|
notifications = json.load(sys.stdin)
|
||||||
'read': False
|
new_notification = {
|
||||||
}))")
|
'type': '$notification_type',
|
||||||
|
'message': '''$message'''.replace('\"', '\"'),
|
||||||
notifications=$(python3 -c "import json; n=json.loads('$notifications'); n.append(json.loads('$new_notification')); print(json.dumps(n[-50:] if len(n)>50 else n, indent=2))")
|
'issue_ref': '$issue_ref' if '$issue_ref' else None,
|
||||||
|
'timestamp': '$timestamp',
|
||||||
|
'read': False
|
||||||
|
}
|
||||||
|
|
||||||
|
notifications.append(new_notification)
|
||||||
|
notifications = notifications[-50:] if len(notifications) > 50 else notifications
|
||||||
|
|
||||||
|
print(json.dumps(notifications, indent=2))
|
||||||
|
")
|
||||||
|
|
||||||
echo "$notifications" > "$NOTIFICATIONS_FILE"
|
echo "$notifications" > "$NOTIFICATIONS_FILE"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,9 +81,20 @@ EOF
|
|||||||
echo "Press Ctrl+C to cancel or wait for session to be created"
|
echo "Press Ctrl+C to cancel or wait for session to be created"
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
|
local before_sessions=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' || true)
|
||||||
|
|
||||||
opencode
|
opencode
|
||||||
|
|
||||||
local session_ids=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' | tail -1)
|
local after_sessions=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' || true)
|
||||||
|
local session_ids=""
|
||||||
|
while IFS= read -r line; do
|
||||||
|
local sid=$(echo "$line" | awk '{print $1}')
|
||||||
|
if [ -n "$sid" ] && ! echo "$before_sessions" | grep -q "^${sid}$"; then
|
||||||
|
session_ids="$sid"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done <<< "$after_sessions"
|
||||||
|
|
||||||
if [ -z "$session_ids" ]; then
|
if [ -z "$session_ids" ]; then
|
||||||
echo "Error: Could not find newly created session" >&2
|
echo "Error: Could not find newly created session" >&2
|
||||||
exit 1
|
exit 1
|
||||||
@@ -95,9 +106,20 @@ EOF
|
|||||||
echo "Base session created: $session_ids"
|
echo "Base session created: $session_ids"
|
||||||
echo "Starting PM agent..."
|
echo "Starting PM agent..."
|
||||||
|
|
||||||
|
before_sessions="$after_sessions"
|
||||||
|
|
||||||
opencode
|
opencode
|
||||||
|
|
||||||
local pm_session_ids=$(opencode session list 2>/dev/null | grep -E '^ses_' | grep -v "$session_ids" | tail -1)
|
after_sessions=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' || true)
|
||||||
|
local pm_session_ids=""
|
||||||
|
while IFS= read -r line; do
|
||||||
|
local sid=$(echo "$line" | awk '{print $1}')
|
||||||
|
if [ -n "$sid" ] && ! echo "$before_sessions" | grep -q "^${sid}$"; then
|
||||||
|
pm_session_ids="$sid"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done <<< "$after_sessions"
|
||||||
|
|
||||||
if [ -z "$pm_session_ids" ]; then
|
if [ -z "$pm_session_ids" ]; then
|
||||||
echo "Warning: Could not find separate PM agent session" >&2
|
echo "Warning: Could not find separate PM agent session" >&2
|
||||||
pm_session_ids="$session_ids"
|
pm_session_ids="$session_ids"
|
||||||
@@ -134,13 +156,11 @@ extract_issue_ref_from_message() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$message" =~ (https?://[a-zA-Z0-9.-]+/[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+/(issues|pull)/[0-9]+) ]]; then
|
if [[ "$message" =~ (https?://)?([a-zA-Z0-9.-]+)/([a-zA-Z0-9._-]+)/([a-zA-Z0-9._-]+)/(issues|pull)/([0-9]+) ]]; then
|
||||||
local url="${BASH_REMATCH[1]}"
|
local instance="${BASH_REMATCH[2]}"
|
||||||
local path=$(echo "$url" | sed 's|https\?://||' | cut -d'/' -f2-)
|
local owner="${BASH_REMATCH[3]}"
|
||||||
local instance=$(echo "$path" | cut -d'/' -f1)
|
local repo="${BASH_REMATCH[4]}"
|
||||||
local owner=$(echo "$path" | cut -d'/' -f2)
|
local num="${BASH_REMATCH[6]}"
|
||||||
local repo=$(echo "$path" | cut -d'/' -f3)
|
|
||||||
local num=$(echo "$path" | grep -oE '[0-9]+$')
|
|
||||||
echo "${instance}/${owner}/${repo}#${num}"
|
echo "${instance}/${owner}/${repo}#${num}"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user