Compare commits

...

1 Commits

Author SHA1 Message Date
shokollm
0a2baf99d5 fix: session ID collision in cmd_start + delegate issue ref extraction
- Fix session ID detection in cmd_start to exclude pm_agent_session_id
  (prevents forked sessions from getting same ID as pm-agent)
- Add extract_issue_ref_from_message function for parsing issue refs
  from short format (git.fbrns.co/user/repo#123) or URLs
- Update cmd_delegate to call cmd_start when issue ref is found
- Pass GITEA_TOKEN to opencode run for API access
- Fixes #81
2026-04-01 23:04:14 +00:00

View File

@@ -15,6 +15,33 @@ if [ -f "$KUGETSU_DIR/config" ]; then
source "$KUGETSU_DIR/config"
fi
extract_issue_ref_from_message() {
local message="$1"
if [ -z "$message" ]; then
echo ""
return
fi
if [[ "$message" =~ ^([a-zA-Z0-9.-]+/[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+#[0-9]+) ]]; then
echo "${BASH_REMATCH[1]}"
return
fi
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 path=$(echo "$url" | sed 's|https\?://||' | cut -d'/' -f2-)
local instance=$(echo "$path" | cut -d'/' -f1)
local owner=$(echo "$path" | cut -d'/' -f2)
local repo=$(echo "$path" | cut -d'/' -f3)
local num=$(echo "$path" | grep -oE '[0-9]+$')
echo "${instance}/${owner}/${repo}#${num}"
return
fi
echo ""
}
count_active_dev_sessions() {
local count=0
if [ -d "$SESSIONS_DIR" ]; then
@@ -515,6 +542,13 @@ cmd_delegate() {
exit 1
fi
local issue_ref=$(extract_issue_ref_from_message "$message")
if [ -n "$issue_ref" ] && [[ "$issue_ref" =~ \#[0-9]+$ ]]; then
cmd_start "$issue_ref" "$message"
return
fi
local pm_session=$(get_pm_agent_session_id)
if [ -z "$pm_session" ] || [ "$pm_session" = "null" ] || [ "$pm_session" = "None" ]; then
echo "Error: PM agent session not found. Run 'kugetsu init' first." >&2
@@ -523,7 +557,7 @@ cmd_delegate() {
mkdir -p "$LOGS_DIR"
local log_file="$LOGS_DIR/delegate-$(date +%s).log"
nohup sh -c "opencode run '$message' --continue --session '$pm_session' >> '$log_file' 2>&1" > /dev/null 2>&1 &
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --continue --session '$pm_session' >> '$log_file' 2>&1" > /dev/null 2>&1 &
disown
echo "Delegated to PM agent (logged to $(basename "$log_file"))"
}
@@ -852,7 +886,7 @@ cmd_start() {
local after_sessions=$(opencode session list 2>/dev/null | grep -oP '^ses_\w+' | sort)
local new_session_id=""
while IFS= read -r sess; do
if [[ ! "$before_set" =~ \|${sess}\| ]] && [[ "$sess" != "$base_session_id" ]]; then
if [[ ! "$before_set" =~ \|${sess}\| ]] && [[ "$sess" != "$base_session_id" ]] && [[ "$sess" != "$pm_agent_session_id" ]]; then
new_session_id="$sess"
break
fi