Compare commits

..

1 Commits

Author SHA1 Message Date
shokollm
78ed3bde7f fix(kugetsu): init creates base session in ~/.kugetsu-worktrees and adds context to forked sessions
1. Init: cd to ~/.kugetsu-worktrees before creating base session
   This keeps all worktrees inside a predictable directory structure
   and avoids external_directory permission issues

2. Fork context: Add kugetsu_get_fork_context() that provides:
   - Important working rules (stop on error, don't pivot)
   - Repository configuration from repos.json
   - Environment file location info

3. Fork message: Prepend context to user message when forking session
2026-04-02 14:29:16 +00:00

View File

@@ -1123,11 +1123,6 @@ EOF
echo "Created pm-agent env file: $ENV_DIR/pm-agent.env" echo "Created pm-agent env file: $ENV_DIR/pm-agent.env"
fi fi
if [ -d "$LOGS_DIR" ]; then
echo "Cleaning up old logs..."
rm -rf "$LOGS_DIR"/*.log 2>/dev/null || true
fi
local existing_base=$(get_base_session_id) local existing_base=$(get_base_session_id)
local existing_pm=$(get_pm_agent_session_id) local existing_pm=$(get_pm_agent_session_id)
@@ -1439,13 +1434,12 @@ cmd_continue() {
echo "Continuing session for '$session_name'..." echo "Continuing session for '$session_name'..."
# Note: --continue always allowed (existing sessions don't count toward limit) # Note: --continue always allowed (existing sessions don't count toward limit)
# Wrap in subshell with cd to ensure worktree directory is set correctly in session DB
if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then
echo "Using worktree: $worktree_path" echo "Using worktree: $worktree_path"
if [ "$DEBUG_MODE" = true ]; then if [ "$DEBUG_MODE" = true ]; then
(cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" --dir "$worktree_path" 2>&1) | tee "$session_path.debug.log" & opencode run "$message" --continue --session "$opencode_session_id" --dir "$worktree_path" 2>&1 | tee "$session_path.debug.log" &
else else
(cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" --dir "$worktree_path" 2>&1) & opencode run "$message" --continue --session "$opencode_session_id" --dir "$worktree_path" 2>&1 &
fi fi
else else
if [ "$DEBUG_MODE" = true ]; then if [ "$DEBUG_MODE" = true ]; then
@@ -1603,21 +1597,19 @@ cmd_destroy() {
if [ "$target" = "base" ]; then if [ "$target" = "base" ]; then
if [ "$force" = true ]; then if [ "$force" = true ]; then
local base_session_id=$(get_base_session_id) local base_session_id=$(get_base_session_id)
local pm_agent_session_id=$(get_pm_agent_session_id)
rm -f "$SESSIONS_DIR/base.json" rm -f "$SESSIONS_DIR/base.json"
rm -f "$SESSIONS_DIR/pm-agent.json" local pm_agent=$(get_pm_agent_session_id)
rm -f "$SESSIONS_DIR/issue-"*.json 2>/dev/null || true if [ -n "$pm_agent" ] && [ "$pm_agent" != "null" ]; then
echo '{"base": null, "pm_agent": null, "issues": {}}' > "$INDEX_FILE" rm -f "$SESSIONS_DIR/pm-agent.json"
echo '{"base": null, "pm_agent": null, "issues": {}}' > "$INDEX_FILE"
else
echo '{"base": null, "pm_agent": null, "issues": {}}' > "$INDEX_FILE"
fi
if [ -n "$base_session_id" ] && [ "$base_session_id" != "null" ]; then if [ -n "$base_session_id" ] && [ "$base_session_id" != "null" ]; then
echo "Deleting base session: $base_session_id" echo "Deleting opencode session: $base_session_id"
opencode session delete "$base_session_id" 2>/dev/null || echo "Warning: Could not delete base session" opencode session delete "$base_session_id" 2>/dev/null || echo "Warning: Could not delete session from opencode (may already be deleted)"
fi fi
if [ -n "$pm_agent_session_id" ] && [ "$pm_agent_session_id" != "null" ]; then echo "Base session destroyed"
echo "Deleting PM agent session: $pm_agent_session_id"
opencode session delete "$pm_agent_session_id" 2>/dev/null || echo "Warning: Could not delete PM agent session"
fi
echo "Base and PM agent sessions destroyed"
else else
echo "Error: destroying base session requires --base -y" >&2 echo "Error: destroying base session requires --base -y" >&2
exit 1 exit 1