From db581fef00e84e63e15893b12941f9c0161b94b5 Mon Sep 17 00:00:00 2001 From: Jean du Plessis Date: Tue, 31 Mar 2026 21:13:25 +0200 Subject: [PATCH 1/2] chore: add worktree prepare script Adds a scripts/worktree-prepare.sh that automates setting up a git worktree: installs deps, links the Vercel project, and copies .env.development.local from the main worktree. Exposed as pnpm worktree:prepare. --- package.json | 3 ++- scripts/worktree-prepare.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100755 scripts/worktree-prepare.sh diff --git a/package.json b/package.json index 5accbda8e7..cd1bc81fbe 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "test:e2e:ui": "playwright test --ui", "test:e2e:debug": "playwright test --debug", "promo": "pnpm -s script src/scripts/encrypt-promo-codes.ts", - "dev:discord-gateway-cron": "tsx dev/discord-gateway-cron.ts" + "dev:discord-gateway-cron": "tsx dev/discord-gateway-cron.ts", + "worktree:prepare": "bash scripts/worktree-prepare.sh" }, "packageManager": "pnpm@10.27.0+sha512.72d699da16b1179c14ba9e64dc71c9a40988cbdc65c264cb0e489db7de917f20dcf4d64d8723625f2969ba52d4b7e2a1170682d9ac2a5dcaeaab732b7e16f04a", "dependencies": { diff --git a/scripts/worktree-prepare.sh b/scripts/worktree-prepare.sh new file mode 100755 index 0000000000..86f4bb74df --- /dev/null +++ b/scripts/worktree-prepare.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail +# Prepares a git worktree by installing dependencies, linking the Vercel +# project, and copying .env.development.local from the main worktree. + +MAIN_WORKTREE="$(git worktree list --porcelain | head -1 | sed 's/^worktree //')" +ENV_FILE=".env.development.local" + +if command -v nvm &>/dev/null || [ -s "${NVM_DIR:-$HOME/.nvm}/nvm.sh" ]; then + echo "==> Switching to correct Node version…" + # nvm is a shell function, not a binary — source it if needed + if ! command -v nvm &>/dev/null; then + source "${NVM_DIR:-$HOME/.nvm}/nvm.sh" + fi + nvm use +fi + +echo "==> Installing dependencies…" +pnpm install + +echo "==> Linking Vercel project…" +vercel link --yes --project kilocode-app --scope kilocode + +if [ -f "$MAIN_WORKTREE/$ENV_FILE" ]; then + echo "==> Copying $ENV_FILE from main worktree…" + cp "$MAIN_WORKTREE/$ENV_FILE" "./$ENV_FILE" +fi + +echo "==> Worktree ready." From b192698b6e5f6ec41a737ab067e5e7979308e026 Mon Sep 17 00:00:00 2001 From: Jean du Plessis Date: Tue, 31 Mar 2026 21:22:36 +0200 Subject: [PATCH 2/2] fix: skip env copy when running from primary worktree cp fails on self-copy under set -e when the main worktree is also the current directory. Guard the copy step with a path comparison. --- scripts/worktree-prepare.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/worktree-prepare.sh b/scripts/worktree-prepare.sh index 86f4bb74df..604ebda4b4 100755 --- a/scripts/worktree-prepare.sh +++ b/scripts/worktree-prepare.sh @@ -21,7 +21,9 @@ pnpm install echo "==> Linking Vercel project…" vercel link --yes --project kilocode-app --scope kilocode -if [ -f "$MAIN_WORKTREE/$ENV_FILE" ]; then +if [ "$(cd "$MAIN_WORKTREE" && pwd -P)" = "$(pwd -P)" ]; then + echo "==> Skipping $ENV_FILE copy (already in primary worktree)" +elif [ -f "$MAIN_WORKTREE/$ENV_FILE" ]; then echo "==> Copying $ENV_FILE from main worktree…" cp "$MAIN_WORKTREE/$ENV_FILE" "./$ENV_FILE" fi