Compare commits
1 Commits
v0.2.25
...
8ba7242861
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ba7242861 |
@@ -475,6 +475,104 @@ read_index() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write_index() {
|
||||||
|
local base="$1"
|
||||||
|
local pm_agent="$2"
|
||||||
|
local issues_json="$3"
|
||||||
|
local temp_file="$INDEX_FILE.tmp.$$"
|
||||||
|
printf '{"base": %s, "pm_agent": %s, "issues": %s}\n' "$base" "$pm_agent" "$issues_json" > "$temp_file"
|
||||||
|
|
||||||
|
if ! python3 -c "import json; json.load(open('$temp_file'))" 2>/dev/null; then
|
||||||
|
echo "Error: write_index would create malformed JSON, aborting. base=$base, pm_agent=$pm_agent, issues_json=$issues_json" >&2
|
||||||
|
rm -f "$temp_file"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv "$temp_file" "$INDEX_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_base_session_id() {
|
||||||
|
local index=$(read_index)
|
||||||
|
echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d.get('base') or '')"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_pm_agent_session_id() {
|
||||||
|
local index=$(read_index)
|
||||||
|
echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d.get('pm_agent') or '')"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_session_for_issue() {
|
||||||
|
local issue_ref="$1"
|
||||||
|
local index=$(read_index)
|
||||||
|
echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d['issues'].get('$issue_ref') or '')"
|
||||||
|
}
|
||||||
|
|
||||||
|
set_base_in_index() {
|
||||||
|
local base_session_id="$1"
|
||||||
|
local pm_agent=$(get_pm_agent_session_id)
|
||||||
|
local issues_json=$(read_index | python3 -c "import sys, json; d=json.load(sys.stdin); print(json.dumps(d['issues']))")
|
||||||
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
||||||
|
write_index "\"$base_session_id\"" "null" "$issues_json"
|
||||||
|
else
|
||||||
|
write_index "\"$base_session_id\"" "\"$pm_agent\"" "$issues_json"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
set_pm_agent_in_index() {
|
||||||
|
local pm_agent_session_id="$1"
|
||||||
|
local base=$(get_base_session_id)
|
||||||
|
local issues_json=$(read_index | python3 -c "import sys, json; d=json.load(sys.stdin); print(json.dumps(d['issues']))")
|
||||||
|
if [ -z "$base" ] || [ "$base" = "null" ]; then
|
||||||
|
write_index "null" "\"$pm_agent_session_id\"" "$issues_json"
|
||||||
|
else
|
||||||
|
write_index "\"$base\"" "\"$pm_agent_session_id\"" "$issues_json"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
add_issue_to_index() {
|
||||||
|
local issue_ref="$1"
|
||||||
|
local session_file="$2"
|
||||||
|
local index=$(read_index)
|
||||||
|
local base=$(get_base_session_id)
|
||||||
|
local pm_agent=$(get_pm_agent_session_id)
|
||||||
|
local issues=$(echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); print(json.dumps(d['issues']))")
|
||||||
|
local new_issues=$(echo "$issues" | python3 -c "import sys, json; d=json.load(sys.stdin); d['$issue_ref']='$session_file'; print(json.dumps(d))")
|
||||||
|
if [ -z "$base" ] || [ "$base" = "null" ]; then
|
||||||
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
||||||
|
write_index "null" "null" "$new_issues"
|
||||||
|
else
|
||||||
|
write_index "null" "\"$pm_agent\"" "$new_issues"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
||||||
|
write_index "\"$base\"" "null" "$new_issues"
|
||||||
|
else
|
||||||
|
write_index "\"$base\"" "\"$pm_agent\"" "$new_issues"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_issue_from_index() {
|
||||||
|
local issue_ref="$1"
|
||||||
|
local index=$(read_index)
|
||||||
|
local base=$(get_base_session_id)
|
||||||
|
local pm_agent=$(get_pm_agent_session_id)
|
||||||
|
local new_issues=$(echo "$index" | python3 -c "import sys, json; d=json.load(sys.stdin); d['issues'].pop('$issue_ref', None); print(json.dumps(d['issues']))")
|
||||||
|
if [ -z "$base" ] || [ "$base" = "null" ]; then
|
||||||
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
||||||
|
write_index "null" "null" "$new_issues"
|
||||||
|
else
|
||||||
|
write_index "null" "\"$pm_agent\"" "$new_issues"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ -z "$pm_agent" ] || [ "$pm_agent" = "null" ]; then
|
||||||
|
write_index "\"$base\"" "null" "$new_issues"
|
||||||
|
else
|
||||||
|
write_index "\"$base\"" "\"$pm_agent\"" "$new_issues"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
validate_issue_ref() {
|
validate_issue_ref() {
|
||||||
local issue_ref="$1"
|
local issue_ref="$1"
|
||||||
if [[ ! "$issue_ref" =~ ^[^/]+/[^/]+/[^#]+#[0-9]+$ ]]; then
|
if [[ ! "$issue_ref" =~ ^[^/]+/[^/]+/[^#]+#[0-9]+$ ]]; then
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ if [ -f "$KUGETSU_DIR/config" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
mask_sensitive_vars() {
|
mask_sensitive_vars() {
|
||||||
local line="${1:-}"
|
local line="$1"
|
||||||
for var in GITEA_TOKEN GITHUB_TOKEN GITLAB_TOKEN API_KEY PASSWORD TOKEN SECRET; do
|
for var in GITEA_TOKEN GITHUB_TOKEN GITLAB_TOKEN API_KEY PASSWORD TOKEN SECRET; do
|
||||||
if [[ "$line" =~ $var ]]; then
|
if [[ "$line" =~ $var ]]; then
|
||||||
line=$(echo "$line" | sed -E "s/=.*/=***MASKED***/")
|
line=$(echo "$line" | sed -E "s/=.*/=***MASKED***/")
|
||||||
@@ -41,11 +41,6 @@ mask_sensitive_vars() {
|
|||||||
echo "$line"
|
echo "$line"
|
||||||
}
|
}
|
||||||
|
|
||||||
strip_ansi_codes() {
|
|
||||||
local line="${1:-}"
|
|
||||||
echo "$line" | sed 's/\x1b\[[0-9;]*m//g' | sed 's/\x1b\[[0-9;]*[a-zA-Z]//g'
|
|
||||||
}
|
|
||||||
|
|
||||||
load_agent_env() {
|
load_agent_env() {
|
||||||
local agent_type="${1:-base}"
|
local agent_type="${1:-base}"
|
||||||
local env_file="$ENV_DIR/${agent_type}.env"
|
local env_file="$ENV_DIR/${agent_type}.env"
|
||||||
@@ -64,26 +59,3 @@ load_agent_env() {
|
|||||||
set +a
|
set +a
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
set_debug_mode() {
|
|
||||||
local filtered_args=()
|
|
||||||
local debug_mode=false
|
|
||||||
|
|
||||||
for arg in "$@"; do
|
|
||||||
case "$arg" in
|
|
||||||
--debug)
|
|
||||||
debug_mode=true
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
filtered_args+=("$arg")
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$debug_mode" = true ]; then
|
|
||||||
export KUGETSU_VERBOSITY="debug"
|
|
||||||
echo "[DEBUG] Debug mode enabled" >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${filtered_args[@]}"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -50,11 +50,7 @@ set_base_in_index() {
|
|||||||
if [ "$session_id" = "null" ]; then
|
if [ "$session_id" = "null" ]; then
|
||||||
write_index "null" "$pm_agent" "$issues"
|
write_index "null" "$pm_agent" "$issues"
|
||||||
else
|
else
|
||||||
if [ "$pm_agent" = "null" ]; then
|
write_index "\"$session_id\"" "$pm_agent" "$issues"
|
||||||
write_index "\"$session_id\"" "null" "$issues"
|
|
||||||
else
|
|
||||||
write_index "\"$session_id\"" "\"$pm_agent\"" "$issues"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +63,7 @@ set_pm_agent_in_index() {
|
|||||||
if [ "$session_id" = "null" ]; then
|
if [ "$session_id" = "null" ]; then
|
||||||
write_index "$base" "null" "$issues"
|
write_index "$base" "null" "$issues"
|
||||||
else
|
else
|
||||||
if [ "$base" = "null" ]; then
|
write_index "$base" "\"$session_id\"" "$issues"
|
||||||
write_index "null" "\"$session_id\"" "$issues"
|
|
||||||
else
|
|
||||||
write_index "\"$base\"" "\"$session_id\"" "$issues"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,19 +79,7 @@ add_issue_to_index() {
|
|||||||
|
|
||||||
issues=$(python3 -c "import sys, json; d=json.load(sys.stdin); d['$issue_ref']='$session_file'; print(json.dumps(d))" <<< "$issues")
|
issues=$(python3 -c "import sys, json; d=json.load(sys.stdin); d['$issue_ref']='$session_file'; print(json.dumps(d))" <<< "$issues")
|
||||||
|
|
||||||
if [ "$base" = "null" ]; then
|
write_index "$base" "$pm_agent" "$issues"
|
||||||
if [ "$pm_agent" = "null" ]; then
|
|
||||||
write_index "null" "null" "$issues"
|
|
||||||
else
|
|
||||||
write_index "null" "\"$pm_agent\"" "$issues"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ "$pm_agent" = "null" ]; then
|
|
||||||
write_index "\"$base\"" "null" "$issues"
|
|
||||||
else
|
|
||||||
write_index "\"$base\"" "\"$pm_agent\"" "$issues"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_issue_from_index() {
|
remove_issue_from_index() {
|
||||||
@@ -113,19 +93,7 @@ remove_issue_from_index() {
|
|||||||
|
|
||||||
issues=$(python3 -c "import sys, json; d=json.load(sys.stdin); d.pop('$issue_ref', None); print(json.dumps(d))" <<< "$issues")
|
issues=$(python3 -c "import sys, json; d=json.load(sys.stdin); d.pop('$issue_ref', None); print(json.dumps(d))" <<< "$issues")
|
||||||
|
|
||||||
if [ "$base" = "null" ]; then
|
write_index "$base" "$pm_agent" "$issues"
|
||||||
if [ "$pm_agent" = "null" ]; then
|
|
||||||
write_index "null" "null" "$issues"
|
|
||||||
else
|
|
||||||
write_index "null" "\"$pm_agent\"" "$issues"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ "$pm_agent" = "null" ]; then
|
|
||||||
write_index "\"$base\"" "null" "$issues"
|
|
||||||
else
|
|
||||||
write_index "\"$base\"" "\"$pm_agent\"" "$issues"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_issue_ref() {
|
validate_issue_ref() {
|
||||||
|
|||||||
@@ -24,9 +24,7 @@ cmd_logs() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo "--- $log ---"
|
echo "--- $log ---"
|
||||||
tail -20 "$LOGS_DIR/$log" | while read line; do
|
tail -20 "$LOGS_DIR/$log" | while read line; do
|
||||||
line=$(strip_ansi_codes "$line")
|
echo " $(mask_sensitive_vars "$line")"
|
||||||
line=$(mask_sensitive_vars "$line")
|
|
||||||
echo " $line"
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ check_task_completion() {
|
|||||||
|
|
||||||
if [ -n "$pid" ] && [ "$pid" != "None" ]; then
|
if [ -n "$pid" ] && [ "$pid" != "None" ]; then
|
||||||
if ! kill -0 "$pid" 2>/dev/null; then
|
if ! kill -0 "$pid" 2>/dev/null; then
|
||||||
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref" "$WORKTREES_DIR")
|
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref" "$HOME/.kugetsu-worktrees")
|
||||||
local has_commits=false
|
local has_commits=false
|
||||||
|
|
||||||
if [ -d "$worktree_path" ] && [ -d "$worktree_path/.git" ]; then
|
if [ -d "$worktree_path" ] && [ -d "$worktree_path/.git" ]; then
|
||||||
@@ -64,7 +64,7 @@ check_task_completion() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -n "$session_id" ] && ! opencode session list 2>/dev/null | grep -q "$session_id"; then
|
if [ -n "$session_id" ] && ! opencode session list 2>/dev/null | grep -q "$session_id"; then
|
||||||
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref" "$WORKTREES_DIR")
|
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref" "$HOME/.kugetsu-worktrees")
|
||||||
local has_commits=false
|
local has_commits=false
|
||||||
|
|
||||||
if [ -d "$worktree_path" ] && [ -d "$worktree_path/.git" ]; then
|
if [ -d "$worktree_path" ] && [ -d "$worktree_path/.git" ]; then
|
||||||
|
|||||||
@@ -83,10 +83,6 @@ EOF
|
|||||||
if [ -n "$existing_base" ] && [ "$existing_base" != "null" ]; then
|
if [ -n "$existing_base" ] && [ "$existing_base" != "null" ]; then
|
||||||
if [ "$force" = true ]; then
|
if [ "$force" = true ]; then
|
||||||
echo "Warning: Reinitializing sessions (force mode)" >&2
|
echo "Warning: Reinitializing sessions (force mode)" >&2
|
||||||
echo "Destroying all sessions, worktrees, and logs..." >&2
|
|
||||||
cmd_destroy --base -y 2>/dev/null || true
|
|
||||||
cmd_destroy --pm-agent -y 2>/dev/null || true
|
|
||||||
rm -f "$LOGS_DIR"/*.log 2>/dev/null || true
|
|
||||||
else
|
else
|
||||||
echo "Error: Base session already exists: $existing_base" >&2
|
echo "Error: Base session already exists: $existing_base" >&2
|
||||||
echo "Use --force to reinitialize" >&2
|
echo "Use --force to reinitialize" >&2
|
||||||
@@ -225,9 +221,7 @@ cmd_delegate() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local msg_file="$LOGS_DIR/msg-$new_session.txt"
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$new_session'" >> "$log_file" 2>&1 &
|
||||||
printf '%s' "$message" > "$msg_file"
|
|
||||||
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$new_session'" >> "$log_file" 2>&1 &
|
|
||||||
echo "Delegated to new session (logged to $(basename "$log_file"))"
|
echo "Delegated to new session (logged to $(basename "$log_file"))"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,22 +234,20 @@ create_session() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local before_json=$(opencode session list --format=json 2>/dev/null)
|
local before_json=$(opencode session list --format=json 2>/dev/null)
|
||||||
local before_set=$(echo "$before_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print('|'.join(s['id'] for s in sessions))" 2>/dev/null || echo "|")
|
local before_ids=$(echo "$before_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print(' '.join(s['id'] for s in sessions))" 2>/dev/null || echo "")
|
||||||
|
|
||||||
opencode run --fork --session "$base_session" "new session" >/dev/null 2>&1
|
opencode run --fork --session "$base_session" "new session" 2>/dev/null
|
||||||
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
local after_json=$(opencode session list --format=json 2>/dev/null)
|
local after_json=$(opencode session list --format=json 2>/dev/null)
|
||||||
local after_sessions=$(echo "$after_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); [print(s['id']) for s in sessions]" 2>/dev/null || true)
|
local after_ids=$(echo "$after_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print(' '.join(s['id'] for s in sessions))" 2>/dev/null || echo "")
|
||||||
|
|
||||||
local new_session_id=""
|
local new_session_id=""
|
||||||
while IFS= read -r sess; do
|
for sess in $after_ids; do
|
||||||
if [[ -n "$sess" ]] && [[ ! "$before_set" =~ \|${sess}\| ]]; then
|
if [[ ! " $before_ids " =~ " $sess " ]] && [[ "$sess" != "$base_session" ]]; then
|
||||||
new_session_id="$sess"
|
new_session_id="$sess"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done <<< "$after_sessions"
|
done
|
||||||
|
|
||||||
echo "$new_session_id"
|
echo "$new_session_id"
|
||||||
}
|
}
|
||||||
@@ -317,44 +309,26 @@ cmd_start() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local session_file=$(issue_ref_to_filename "$issue_ref")
|
|
||||||
local session_path="$SESSIONS_DIR/$session_file"
|
|
||||||
local worktree_exists=false
|
|
||||||
|
|
||||||
if worktree_exists "$issue_ref"; then
|
if worktree_exists "$issue_ref"; then
|
||||||
worktree_exists=true
|
echo "Issue '$issue_ref' already has a worktree. Use 'kugetsu continue' instead."
|
||||||
fi
|
|
||||||
|
|
||||||
local session_exists=false
|
|
||||||
if [ -f "$session_path" ]; then
|
|
||||||
session_exists=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $worktree_exists && $session_exists; then
|
|
||||||
echo "Issue '$issue_ref' already has a worktree and session." >&2
|
|
||||||
echo "Use 'kugetsu continue $issue_ref' to continue work." >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $worktree_exists && ! $session_exists; then
|
|
||||||
echo "Warning: Worktree exists but session is missing. Removing worktree to recreate both..." >&2
|
|
||||||
remove_worktree_for_issue "$issue_ref"
|
|
||||||
worktree_exists=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! $worktree_exists && $session_exists; then
|
|
||||||
echo "Warning: Session exists but worktree is missing. Removing stale session to recreate both..." >&2
|
|
||||||
rm -f "$session_path"
|
|
||||||
remove_issue_from_index "$issue_ref"
|
|
||||||
session_exists=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
local active_count=$(count_active_dev_sessions)
|
local active_count=$(count_active_dev_sessions)
|
||||||
if [ "$active_count" -ge "${MAX_CONCURRENT_AGENTS:-3}" ]; then
|
if [ "$active_count" -ge "${MAX_CONCURRENT_AGENTS:-3}" ]; then
|
||||||
echo "Error: Max concurrent agents (${MAX_CONCURRENT_AGENTS:-3}) reached. Use 'kugetsu continue' or wait for an agent to finish." >&2
|
echo "Error: Max concurrent agents (${MAX_CONCURRENT_AGENTS:-3}) reached. Use 'kugetsu continue' or wait for an agent to finish." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local session_file=$(issue_ref_to_filename "$issue_ref")
|
||||||
|
local session_path="$SESSIONS_DIR/$session_file"
|
||||||
|
|
||||||
|
if [ -f "$session_path" ]; then
|
||||||
|
echo "Session file already exists: $session_file"
|
||||||
|
echo "Use 'kugetsu continue $issue_ref' to continue work."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
create_worktree "$issue_ref" "$WORKTREES_DIR"
|
create_worktree "$issue_ref" "$WORKTREES_DIR"
|
||||||
|
|
||||||
local new_session_id=$(create_session "$base_session_id")
|
local new_session_id=$(create_session "$base_session_id")
|
||||||
@@ -377,10 +351,7 @@ cmd_start() {
|
|||||||
load_agent_env "dev"
|
load_agent_env "dev"
|
||||||
|
|
||||||
cd "$worktree_path"
|
cd "$worktree_path"
|
||||||
local sanitized_id=$(echo "$new_session_id" | sed 's/[^a-zA-Z0-9_-]/_/g')
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$dev_message' --session '$new_session_id'" >> "$LOGS_DIR/dev-$new_session_id.log" 2>&1 &
|
||||||
local msg_file="$worktree_path/.kugetsu-msg.txt"
|
|
||||||
printf '%s' "$dev_message" > "$msg_file"
|
|
||||||
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$new_session_id'" >> "$LOGS_DIR/dev-$sanitized_id.log" 2>&1 &
|
|
||||||
|
|
||||||
echo "Session started for '$issue_ref': $new_session_id"
|
echo "Session started for '$issue_ref': $new_session_id"
|
||||||
echo "Worktree: $worktree_path"
|
echo "Worktree: $worktree_path"
|
||||||
@@ -429,24 +400,16 @@ cmd_continue() {
|
|||||||
local worktree_path=$(python3 -c "import json; print(json.load(open('$session_path')).get('worktree_path', ''))" 2>/dev/null || echo "")
|
local worktree_path=$(python3 -c "import json; print(json.load(open('$session_path')).get('worktree_path', ''))" 2>/dev/null || echo "")
|
||||||
local issue_ref=$(python3 -c "import json; print(json.load(open('$session_path')).get('issue_ref', ''))" 2>/dev/null || echo "")
|
local issue_ref=$(python3 -c "import json; print(json.load(open('$session_path')).get('issue_ref', ''))" 2>/dev/null || echo "")
|
||||||
|
|
||||||
if [ -z "$worktree_path" ] || [ ! -d "$worktree_path" ]; then
|
|
||||||
echo "Warning: Worktree is missing for '$session_name'. Recovering..." >&2
|
|
||||||
rm -f "$session_path"
|
|
||||||
remove_issue_from_index "$session_name"
|
|
||||||
echo "Calling cmd_start to create new session and worktree..." >&2
|
|
||||||
cmd_start "$session_name" "$message"
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$message" ]; then
|
if [ -z "$message" ]; then
|
||||||
message=$(build_dev_agent_message "$issue_ref" "")
|
message=$(build_dev_agent_message "$issue_ref" "")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$worktree_path"
|
if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then
|
||||||
local sanitized_id=$(echo "$opencode_session_id" | sed 's/[^a-zA-Z0-9_-]/_/g')
|
cd "$worktree_path"
|
||||||
local msg_file="$worktree_path/.kugetsu-msg.txt"
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
||||||
printf '%s' "$message" > "$msg_file"
|
else
|
||||||
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$sanitized_id.log" 2>&1 &
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_list() {
|
cmd_list() {
|
||||||
|
|||||||
Reference in New Issue
Block a user