Compare commits

...

2 Commits

Author SHA1 Message Date
7888a34bd9 Merge pull request 'fix(kugetsu): warn if init run from non-empty directory' (#112) from fix/init-directory-warning into main 2026-04-02 15:21:30 +02:00
shokollm
e2a37cdbb9 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.
2026-04-02 13:19:49 +00:00

View File

@@ -1107,6 +1107,22 @@ EOF
exit 1 exit 1
fi 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 "Starting TUI to create base session..."
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
@@ -1240,12 +1256,14 @@ cmd_start() {
local fork_log="$SESSIONS_DIR/$session_file.fork.log" local fork_log="$SESSIONS_DIR/$session_file.fork.log"
local opencode_db="${OPENCODE_DB:-$HOME/.local/share/opencode/opencode.db}" local opencode_db="${OPENCODE_DB:-$HOME/.local/share/opencode/opencode.db}"
> "$fork_log"
fix_session_permissions fix_session_permissions
if [ "$DEBUG_MODE" = true ]; then 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 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 fi
local fork_pid=$! local fork_pid=$!
@@ -1371,9 +1389,9 @@ cmd_continue() {
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" 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" 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