Skip to content

Commit d6c76a1

Browse files
authored
(kiloclaw) fix local dev script (#1682)
<!-- PR title format: type(scope): description — e.g., feat(auth): add SSO login --> <!-- Keep the title under 72 characters, use imperative mood, no trailing period. --> ## Summary - Escape backslashes and double quotes in shell commands before interpolating them into AppleScript write text / do script strings - Fixes broken terminal tabs/panes when NVM_PREFIX contains escaped paths (e.g. \"$(nvm which ...)\") - Applied consistently across open_terminal_tab(), open_split_screen(), and the inline split-pane osascript block
2 parents 0e15faa + 326d7bb commit d6c76a1

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

kiloclaw/scripts/dev-start.sh

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,9 @@ refresh_fly_token() {
277277
echo "ERROR: 'fly' CLI not found. Install it: https://fly.io/docs/flyctl/install/"
278278
exit 1
279279
fi
280-
NEW_TOKEN="$(fly tokens create org "$FLY_ORG" 2>&1)"
281-
if [ $? -ne 0 ] || [ -z "$NEW_TOKEN" ]; then
280+
local token_rc=0
281+
NEW_TOKEN="$(fly tokens create org "$FLY_ORG" 2>&1)" || token_rc=$?
282+
if [ "$token_rc" -ne 0 ] || [ -z "$NEW_TOKEN" ]; then
282283
echo "ERROR: Failed to create Fly token. Are you logged in? Try 'fly auth login'."
283284
echo "$NEW_TOKEN"
284285
exit 1
@@ -443,6 +444,10 @@ open_terminal_tab() {
443444
local title="$1"
444445
local cmd="$2"
445446

447+
# Escape backslashes and double quotes so $cmd is safe inside AppleScript strings
448+
local safe_cmd="${cmd//\\/\\\\}"
449+
safe_cmd="${safe_cmd//\"/\\\"}"
450+
446451
if osascript -e 'tell application "System Events" to (name of processes) contains "iTerm2"' 2>/dev/null | grep -q true; then
447452
osascript <<EOF
448453
tell application "iTerm"
@@ -451,7 +456,7 @@ tell application "iTerm"
451456
create tab with default profile
452457
tell current session
453458
set name to "$title"
454-
write text "echo '--- $title ---'; $cmd"
459+
write text "echo '--- $title ---'; $safe_cmd"
455460
end tell
456461
end tell
457462
end tell
@@ -460,7 +465,7 @@ EOF
460465
osascript <<EOF
461466
tell application "Terminal"
462467
activate
463-
do script "printf '\\\\e]0;$title\\\\a'; $cmd"
468+
do script "printf '\\\\e]0;$title\\\\a'; $safe_cmd"
464469
end tell
465470
EOF
466471
fi
@@ -477,6 +482,11 @@ open_split_screen() {
477482
local title2="$3" cmd2="$4"
478483
local title3="$5" cmd3="$6"
479484

485+
# Escape backslashes and double quotes so commands are safe inside AppleScript strings
486+
local safe1="${cmd1//\\/\\\\}"; safe1="${safe1//\"/\\\"}"
487+
local safe2="${cmd2//\\/\\\\}"; safe2="${safe2//\"/\\\"}"
488+
local safe3="${cmd3//\\/\\\\}"; safe3="${safe3//\"/\\\"}"
489+
480490
osascript <<EOF
481491
tell application "iTerm"
482492
activate
@@ -486,7 +496,7 @@ tell application "iTerm"
486496
-- Left pane: tunnel (named "KiloClaw Dev" so the tab title is readable)
487497
tell current session
488498
set name to "KiloClaw Dev"
489-
write text "echo '--- $title1 ---'; $cmd1"
499+
write text "echo '--- $title1 ---'; $safe1"
490500
491501
-- Split right
492502
set rightSession to (split vertically with default profile)
@@ -495,7 +505,7 @@ tell application "iTerm"
495505
-- Top-right pane: Next.js
496506
tell rightSession
497507
set name to "$title2"
498-
write text "echo '--- $title2 ---'; $cmd2"
508+
write text "echo '--- $title2 ---'; $safe2"
499509
500510
-- Split bottom
501511
set bottomRightSession to (split horizontally with default profile)
@@ -504,7 +514,7 @@ tell application "iTerm"
504514
-- Bottom-right pane: worker
505515
tell bottomRightSession
506516
set name to "$title3"
507-
write text "echo '--- $title3 ---'; $cmd3"
517+
write text "echo '--- $title3 ---'; $safe3"
508518
end tell
509519
end tell
510520
end tell
@@ -708,6 +718,8 @@ case "$DISPLAY_MODE" in
708718
"KiloClaw worker" "$WORKER_CMD"
709719
else
710720
# Quick tunnel already running in its own tab; put Next.js + worker in splits
721+
safe_nextjs="${NEXTJS_CMD//\\/\\\\}"; safe_nextjs="${safe_nextjs//\"/\\\"}"
722+
safe_worker="${WORKER_CMD//\\/\\\\}"; safe_worker="${safe_worker//\"/\\\"}"
711723
osascript <<EOF
712724
tell application "iTerm"
713725
activate
@@ -716,13 +728,13 @@ tell application "iTerm"
716728
717729
tell current session
718730
set name to "Next.js"
719-
write text "echo '--- Next.js ---'; $NEXTJS_CMD"
731+
write text "echo '--- Next.js ---'; $safe_nextjs"
720732
set workerSession to (split horizontally with default profile)
721733
end tell
722734
723735
tell workerSession
724736
set name to "KiloClaw worker"
725-
write text "echo '--- KiloClaw worker ---'; $WORKER_CMD"
737+
write text "echo '--- KiloClaw worker ---'; $safe_worker"
726738
end tell
727739
end tell
728740
end tell

0 commit comments

Comments
 (0)