From e2a37cdbb9788f98e0ac56a1f4562e02b50f6267 Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:19:49 +0000 Subject: [PATCH] fix(kugetsu): warn if init run from non-empty directory Warn users if running kugetsu init from a directory with files or git repository. This prevents project context from contaminating the base session, which causes forked sessions to have unwanted context. --- skills/kugetsu/scripts/kugetsu | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/skills/kugetsu/scripts/kugetsu b/skills/kugetsu/scripts/kugetsu index 69c5d97..a7c02ec 100755 --- a/skills/kugetsu/scripts/kugetsu +++ b/skills/kugetsu/scripts/kugetsu @@ -1107,6 +1107,22 @@ EOF exit 1 fi + local cwd_files=$(ls -A "$PWD" 2>/dev/null | wc -l) + local cwd_git=$(git rev-parse --is-inside-work-tree 2>/dev/null || echo "false") + if [ "$cwd_files" -gt 0 ] || [ "$cwd_git" = "true" ]; then + echo "Warning: Current directory is not empty: $PWD" >&2 + echo "This may cause project context to contaminate the base session." >&2 + echo "Consider running kugetsu init from an empty directory." >&2 + echo "" >&2 + echo "Files in current directory: $cwd_files" >&2 + if [ "$cwd_git" = "true" ]; then + echo "Git repository detected: $(git rev-parse --show-toplevel 2>/dev/null || echo 'unknown')" >&2 + fi + echo "" >&2 + echo "Press Ctrl+C to cancel or wait 5 seconds to continue anyway..." >&2 + sleep 5 + fi + echo "Starting TUI to create base session..." echo "Press Ctrl+C to cancel or wait for session to be created" sleep 2 @@ -1236,16 +1252,18 @@ cmd_start() { remove_worktree_for_issue "$issue_ref" "$parent_dir" exit 1 fi - + local fork_log="$SESSIONS_DIR/$session_file.fork.log" local opencode_db="${OPENCODE_DB:-$HOME/.local/share/opencode/opencode.db}" + > "$fork_log" + fix_session_permissions if [ "$DEBUG_MODE" = true ]; then - (cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" 2>&1) | tee "$fork_log" & + (cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" --dir "$worktree_path" 2>&1) | tee "$fork_log" & else - (cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" 2>&1) >> "$fork_log" & + (cd "$worktree_path" && opencode run "$message" --fork --session "$base_session_id" --dir "$worktree_path" 2>&1) >> "$fork_log" & fi local fork_pid=$! @@ -1371,9 +1389,9 @@ cmd_continue() { if [ -n "$worktree_path" ] && [ -d "$worktree_path" ]; then echo "Using worktree: $worktree_path" if [ "$DEBUG_MODE" = true ]; then - (cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" 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 - (cd "$worktree_path" && opencode run "$message" --continue --session "$opencode_session_id" 2>&1) & + opencode run "$message" --continue --session "$opencode_session_id" --dir "$worktree_path" 2>&1 & fi else if [ "$DEBUG_MODE" = true ]; then