Repository navigation
Revert "#14863 refactor(shell): one portable Unix startup dialect instead of shell detection" - #14975
Conversation
… shell d…" This reverts commit b6ea3f1.
📝 WalkthroughWalkthroughThe change removes fish-specific and worktree-scoped terminal-history handling across local, remote, daemon, relay, and cleanup paths. PTY history-isolation options and cleanup APIs are removed. SSH reattachment uses an exit-fenced flow. Relay shell wrappers are generated locally. Startup-shell handling adds explicit Fish support, simplifies environment clearing, and standardizes POSIX quoting. Resume-shell selection now distinguishes local client-login-shell execution from remote and platform-mismatched execution. Merge Risk: 🟡 Moderate · up to The revert restores prior shell and history behavior, but the current code still has concrete launch and session risks: Fish commands can retain stale resume or prefill state, custom Zsh startup files can be skipped, worktree handling can fail, and Windows history paths can be constructed incorrectly. Merge should wait for these bounded correctness issues to be fixed or explicitly accepted by the owners. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
src/shared/tui-agent-startup-shell.ts (1)
3-4: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCorrect the Fish dialect comment.
Fish does not use POSIX field splitting after variable expansion. Limit this comment to the shared behavior used here. Keep the comment to one line. (fishshell.com)
Proposed change
-// Why: fish shares POSIX word splitting, quoting and `;` chaining, so it is a -// separate dialect only where its grammar actually diverges (env clearing). +// Fish uses this shared path; only environment clearing differs here.As per coding guidelines: “Comments must be concise, non-obvious, and brief.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 87b205e1-7dd3-49a8-80ef-d1f25ce9441b
📒 Files selected for processing (58)
.github/workflows/pr.ymlconfig/scripts/pr-workflow-parallelism.test.mjssrc/main/daemon/daemon-pty-adapter.tssrc/main/daemon/daemon-zsh-shell-ready-rcfile.tssrc/main/daemon/shell-ready.tssrc/main/fish-history-session.test.tssrc/main/fish-history-session.tssrc/main/ipc/pty.tssrc/main/ipc/worktrees.tssrc/main/providers/local-pty-provider.tssrc/main/providers/local-pty-shell-ready-wrapper-generation.tssrc/main/providers/pty-provider-contract.tssrc/main/providers/ssh-pty-provider.test.tssrc/main/providers/ssh-pty-provider.tssrc/main/providers/ssh-pty-session-reattach.tssrc/main/providers/ssh-pty-spawn-request.tssrc/main/remote-worktree-history-cleanup.test.tssrc/main/remote-worktree-history-cleanup.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/shell-templates.tssrc/main/terminal-history-deletion.tssrc/main/terminal-history-fish-session.node-pty.test.tssrc/main/terminal-history-gc.tssrc/main/terminal-history-id.tssrc/main/terminal-history-paths.tssrc/main/terminal-history-tombstone-retry.test.tssrc/main/terminal-history.test.tssrc/main/terminal-history.tssrc/main/wsl-fish-history-cleanup.test.tssrc/main/wsl-fish-history-cleanup.tssrc/main/zsh-scoped-histfile.live-shell.test.tssrc/relay/pty-handler.tssrc/relay/pty-shell-launch.tssrc/relay/pty-shell-overlay-wrappers.tssrc/relay/terminal-history.test.tssrc/relay/terminal-history.tssrc/renderer/src/components/settings/CliSkillRuntimeSetup.tsxsrc/renderer/src/components/sidebar/folder-workspace-composer-submit.test.tssrc/renderer/src/components/terminal-pane/pty-connection-cold-restore-agent-resume.test.tssrc/renderer/src/lib/ai-vault-resume-command.test.tssrc/renderer/src/lib/ai-vault-resume-command.tssrc/renderer/src/lib/ai-vault-resume-shell.test.tssrc/renderer/src/lib/ai-vault-resume-shell.tssrc/renderer/src/lib/launch-agent-background-session.test.tssrc/renderer/src/lib/launch-agent-in-new-tab-windows-quoting.test.tssrc/renderer/src/lib/launch-work-item-direct.test.tssrc/renderer/src/lib/resume-sleeping-agent-session.test.tssrc/renderer/src/lib/tui-agent-startup.test.tssrc/shared/agent-resume-launch-command.tssrc/shared/ai-vault-resume-command.tssrc/shared/global-settings-types.tssrc/shared/hermes-startup-query.tssrc/shared/startup-shell-portability.live-shell.test.tssrc/shared/tui-agent-startup-session-options.test.tssrc/shared/tui-agent-startup-shell.test.tssrc/shared/tui-agent-startup-shell.tssrc/shared/tui-agent-startup.test.ts
💤 Files with no reviewable changes (19)
- src/main/remote-worktree-history-cleanup.ts
- src/main/terminal-history-id.ts
- src/main/remote-worktree-history-cleanup.test.ts
- src/main/providers/ssh-pty-spawn-request.ts
- config/scripts/pr-workflow-parallelism.test.mjs
- src/relay/pty-shell-overlay-wrappers.ts
- src/main/fish-history-session.test.ts
- src/main/providers/ssh-pty-session-reattach.ts
- src/relay/terminal-history.ts
- src/main/wsl-fish-history-cleanup.ts
- src/main/providers/pty-provider-contract.ts
- .github/workflows/pr.yml
- src/main/wsl-fish-history-cleanup.test.ts
- src/shared/startup-shell-portability.live-shell.test.ts
- src/main/fish-history-session.ts
- src/main/zsh-scoped-histfile.live-shell.test.ts
- src/main/terminal-history-fish-session.node-pty.test.ts
- src/main/runtime/orca-runtime.ts
- src/relay/terminal-history.test.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.
| // Replace the filename portion of the HISTFILE path. | ||
| const dir = spawnEnv.HISTFILE.replace(/[/\\][^/\\]+$/, '') | ||
| spawnEnv.HISTFILE = `${dir}/${newFilename}` |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use the matching path API for HISTFILE.
Line 166 appends / to a value that can be a native Windows path. Select path.win32 or path.posix from the existing path format, then join newFilename with that API. Add a Windows-style fallback test.
As per coding guidelines, “Use path.join or Electron/Node path utilities for file paths; never assume / or \.”
Source: Coding guidelines
| const worktreeId = env?.ORCA_WORKTREE_ID | ||
| const worktreePath = worktreeId ? splitWorktreeId(worktreeId)?.worktreePath : undefined |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -u
echo '--- target file outline ---'
if command -v ast-grep >/dev/null 2>&1; then
ast-grep outline src/relay/pty-handler.ts | sed -n '1,220p'
else
wc -l src/relay/pty-handler.ts
fi
echo '--- target snippets ---'
sed -n '1350,1425p' src/relay/pty-handler.ts
sed -n '1560,1620p' src/relay/pty-handler.ts
echo '--- symbol and field references ---'
rg -n --hidden --glob '!node_modules' --glob '!dist' \
'splitWorktreeId|spawnOnce|ORCA_WORKTREE_ID|pty\.spawn|worktreeId' .Repository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -u
echo '--- target sections ---'
sed -n '1370,1410p' src/relay/pty-handler.ts
sed -n '1575,1605p' src/relay/pty-handler.ts
echo '--- exact definitions and calls in source ---'
rg -n -g '*.{ts,tsx,js,jsx}' \
'splitWorktreeId|spawnOnce|ORCA_WORKTREE_ID|pty\.spawn' \
src/relay src/main src/preload src/renderer/src 2>/dev/null | \
grep -vE '(/|\.)(test|spec)\.' | head -n 400
echo '--- likely request schemas ---'
rg -n -g '*.{ts,tsx,js,jsx}' \
'Spawn|spawn.*Schema|schema|params\.env|env:.*Record|worktreeId' \
src/relay src/main src/preload 2>/dev/null | \
grep -vE '(/|\.)(test|spec)\.' | head -n 500Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -u
echo '--- splitWorktreeId implementation ---'
rg -n -g '*.{ts,tsx,js,jsx}' \
'export function splitWorktreeId|function splitWorktreeId|splitWorktreeId\s*=' \
src/shared src 2>/dev/null | head -n 40
split_file=$(rg -l -g '*.{ts,tsx,js,jsx}' \
'export function splitWorktreeId|function splitWorktreeId|splitWorktreeId\s*=' \
src/shared src 2>/dev/null | head -n 1 || true)
if [ -n "$split_file" ]; then
echo "FILE: $split_file"
sed -n '1,180p' "$split_file"
fi
echo '--- spawn admission and physical spawn path ---'
sed -n '1220,1380p' src/relay/pty-handler.ts
sed -n '1465,1595p' src/relay/pty-handler.ts
echo '--- dispatcher request handling ---'
sed -n '1,240p' src/relay/dispatcher.ts
echo '--- PTY spawn request type and IPC forwarding ---'
sed -n '1,90p' src/preload/api/pty-api.ts
sed -n '930,1010p' src/main/ipc/pty.ts
sed -n '1930,1980p' src/main/ipc/pty.ts
sed -n '6240,6310p' src/main/ipc/pty.tsRepository: stablyai/orca
Length of output: 34436
🏁 Script executed:
#!/bin/bash
set -u
echo '--- dispatcher handler invocation ---'
rg -n -A35 -B20 \
'requestHandlers\.get|handler\(.*params|onRequest|parseJsonRpcMessage|params' \
src/relay/dispatcher.ts | head -n 260
echo '--- relay PTY request forwarding ---'
rg -n -A25 -B20 \
"callRequest\\('pty\\.spawn'|request\\('pty\\.spawn'|pty\\.spawn.*params|mux\\.request\\('pty\\.spawn'" \
src/main src/relay src/renderer/src 2>/dev/null | head -n 300
echo '--- all explicit ORCA_WORKTREE_ID assignments near spawn construction ---'
rg -n -A12 -B12 \
'ORCA_WORKTREE_ID\s*:' \
src/main src/renderer/src src/relay 2>/dev/null | \
grep -vE '(/|\.)(test|spec)\.' | head -n 300
echo '--- standalone parser behavior probe ---'
python3 - <<'PY'
SEPARATOR = '::'
def split_worktree_id(value):
# Mirrors src/shared/worktree/id.ts:20-28.
separator_idx = value.index(SEPARATOR)
return value[:separator_idx], value[separator_idx + len(SEPARATOR):]
cases = {
'valid string': 'repo::/worktree',
'empty string': '',
'number': 7,
'boolean': True,
'object': {},
'array': [],
}
for label, value in cases.items():
try:
print(label, '=>', split_worktree_id(value) if value else None)
except Exception as exc:
print(label, '=>', type(exc).__name__ + ': ' + str(exc))
PYRepository: stablyai/orca
Length of output: 50369
Guard ORCA_WORKTREE_ID before parsing.
splitWorktreeId calls .indexOf, so a truthy non-string value throws before pty.spawn runs. Use the runtime string guard already used at Line 1594.
| export ORCA_USER_ZDOTDIR="\${ZDOTDIR:-\${ORCA_ORIG_ZDOTDIR:-$HOME}}" | ||
| case "\${ORCA_USER_ZDOTDIR%/}" in | ||
| */shell-ready/zsh) export ORCA_USER_ZDOTDIR="$HOME" ;; | ||
| esac |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
ORCA_USER_ZDOTDIR falls back to $HOME and drops a custom user ZDOTDIR.
At .zshenv time ZDOTDIR is already the wrapper directory, because getRelayShellLaunchConfig exports ZDOTDIR: join(root, 'zsh') (Line 309). If the user .zshenv does not re-export ZDOTDIR, line 95 captures the wrapper directory, and the */shell-ready/zsh case then rewrites ORCA_USER_ZDOTDIR to $HOME.
Every downstream homeExpression prefers ORCA_USER_ZDOTDIR (Lines 104, 110, 121, 127, 135), so ORCA_ORIG_ZDOTDIR never applies. A user with ZDOTDIR=$HOME/.config/zsh then loses .zprofile, .zshrc, and .zlogin sourcing on relay sessions.
Fall back to the already-normalized ORCA_ORIG_ZDOTDIR instead of $HOME.
🐛 Proposed fix
export ORCA_USER_ZDOTDIR="\${ZDOTDIR:-\${ORCA_ORIG_ZDOTDIR:-$HOME}}"
case "\${ORCA_USER_ZDOTDIR%/}" in
- */shell-ready/zsh) export ORCA_USER_ZDOTDIR="$HOME" ;;
+ */shell-ready/zsh) export ORCA_USER_ZDOTDIR="\${ORCA_ORIG_ZDOTDIR:-$HOME}" ;;
esac📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export ORCA_USER_ZDOTDIR="\${ZDOTDIR:-\${ORCA_ORIG_ZDOTDIR:-$HOME}}" | |
| case "\${ORCA_USER_ZDOTDIR%/}" in | |
| */shell-ready/zsh) export ORCA_USER_ZDOTDIR="$HOME" ;; | |
| esac | |
| export ORCA_USER_ZDOTDIR="\${ZDOTDIR:-\${ORCA_ORIG_ZDOTDIR:-$HOME}}" | |
| case "\${ORCA_USER_ZDOTDIR%/}" in | |
| */shell-ready/zsh) export ORCA_USER_ZDOTDIR="\${ORCA_ORIG_ZDOTDIR:-$HOME}" ;; | |
| esac |
| // Why: `NAME=value cmd` is posix-only syntax; on cmd/PowerShell such a | ||
| // token is just a bogus executable name, not a prefix to skip. | ||
| (shell === 'posix' && /^[A-Za-z_][A-Za-z0-9_]*=/.test(token)) || | ||
| (shell === 'powershell' && token === '&' && i === 0) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- target file ---'
wc -l src/shared/agent-resume-launch-command.ts
cat -n src/shared/agent-resume-launch-command.ts
printf '%s\n' '--- predicate definitions and usages ---'
rg -n --glob '*.{ts,tsx,js,jsx}' 'isPosixStartupShell|buildClaudeResumeLaunchCommand|claude.*resume|resume.*selector' .Repository: stablyai/orca
Length of output: 50372
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- candidate startup-shell files ---'
git ls-files | grep -E 'tui-agent-startup-shell|agent-resume-launch-command|startup-shell'
printf '%s\n' '--- shell type and predicate references ---'
rg -n --glob '*.ts' --glob '*.tsx' 'AgentStartupShell|isPosixStartupShell|fish|powershell|shell === .posix' src/shared src | head -200
printf '%s\n' '--- startup shell outline ---'
startup_file="$(git ls-files | grep -E '(^|/)tui-agent-startup-shell\.(ts|tsx)$' | head -1)"
if [ -n "$startup_file" ]; then
ast-grep outline "$startup_file"
wc -l "$startup_file"
cat -n "$startup_file"
fiRepository: stablyai/orca
Length of output: 28466
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- tokenizer definition ---'
rg -n -A180 -B20 'function tokenizeCustomCommandTemplate|export function tokenizeCustomCommandTemplate' src/shared/commit-message-prompt.ts
printf '%s\n' '--- resume tests ---'
rg -n -A18 -B8 'fish|assignment|NAME=|FOO=|resume|continue|wrapper|executable' src/shared/agent-resume-launch-command.test.tsRepository: stablyai/orca
Length of output: 31433
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
import re
def tokenize(value):
tokens, spans = [], []
current = []
in_token = False
token_start = 0
quote = None
i = 0
while i < len(value):
ch = value[i]
if quote:
if ch == quote:
quote = None
i += 1
in_token = True
continue
current.append(ch)
i += 1
continue
if ch in "'\"":
quote = ch
if not in_token:
token_start = i
in_token = True
i += 1
continue
if ch == '\\' and i + 1 < len(value):
current.append(value[i + 1])
if not in_token:
token_start = i
in_token = True
i += 2
continue
if ch.isspace():
if in_token:
tokens.append(''.join(current))
spans.append((token_start, i))
current = []
in_token = False
i += 1
continue
if not in_token:
token_start = i
current.append(ch)
in_token = True
i += 1
if quote:
return None
if in_token:
tokens.append(''.join(current))
spans.append((token_start, len(value)))
return tokens, spans
def is_claude(token):
return re.fullmatch(r'claude(?:\.(?:exe|cmd|bat|ps1))?', token, re.I) is not None
def is_selector(token):
return (
token in ('--resume', '--continue', '-r', '-c')
or any(token.startswith(p) for p in ('--resume=', '--continue=', '-r=', '-c='))
)
def build(base, shell, posix_predicate=False):
tokenized = tokenize(base)
tokens, spans = tokenized
command_position = True
claude_index = -1
for i, token in enumerate(tokens):
if command_position:
if is_claude(token):
claude_index = i
break
assignment = re.match(r'^[A-Za-z_][A-Za-z0-9_]*=', token)
if ((shell == 'posix' if not posix_predicate else shell in ('posix','fish')) and assignment):
continue
command_position = False
if token == '--':
command_position = True
resume = "'--resume' 'claude-session-1'"
if claude_index == -1:
return f"{base} {resume}", tokens
cuts = []
for i in range(claude_index + 1, len(tokens)):
if is_selector(tokens[i]):
start = spans[i][0]
while start > spans[i-1][1] and base[start-1] in ' \t':
start -= 1
end = spans[i][1]
if tokens[i] in ('--resume','-r') and i+1 < len(tokens) and not tokens[i+1].startswith('-'):
end = spans[i+1][1]
cuts.append((start,end))
result = base
for start,end in reversed(cuts):
result = result[:start] + result[end:]
return f"{result} {resume}", tokens
base = "FOO=bar claude --resume old"
for shell in ('posix','fish'):
print(shell, build(base, shell, False))
print('fish with shared predicate', build(base, 'fish', True))
PYRepository: stablyai/orca
Length of output: 475
🌐 Web query:
Fish shell documentation environment variable assignment before command NAME=value command``
💡 Result:
Since fish shell version 3.1, you can set an environment variable for a single command using the same NAME=value command syntax used in POSIX-compliant shells like Bash [1][2]. In fish, this syntax functions by setting the variable specifically for that command [3][4]. Unlike some other shells where the variable might not be visible to the shell's own expansion mechanism, fish allows the variable to be accessed within the command line provided [1][2]. For example, running key=value echo $key in fish will output value [1][2]. Before fish 3.1, or if you prefer an alternative approach, you can use the following methods: 1. The env command: You can use env NAME=value command, which sets the environment variable specifically for the execution of that external command [5][6]. This method is often used for portability [7]. 2. The begin block: You can use a scoped block to set a local, exported variable that persists only for the duration of that block [3][6]: begin set -lx NAME value command end These methods ensure the environment variable does not persist in the shell session after the command completes [5][8].
Citations:
- 1: https://fishshell.com/docs/4.5/faq.html
- 2: https://fishshell.com/docs/current/faq.html
- 3: https://fishshell.com/docs/current/cmds/set.html
- 4: https://fishshell.com/docs/current/cmds/set
- 5: https://stackoverflow.com/questions/22819577/is-there-a-way-to-prepend-a-command-with-a-variable-assignment-like-in-bash
- 6: https://serverfault.com/questions/164305/how-can-i-set-environment-variable-for-just-one-command-in-fish-shell
- 7: https://news.ycombinator.com/item?id=9566441
- 8: https://github.com/tobert/kaish/blob/369a91a96fc38ff7ef6c7473d6081680d038a758/docs/LANGUAGE.md
Treat Fish assignment prefixes as command prefixes.
Fish supports NAME=value command syntax. With FOO=bar claude --resume old, the current scan misses claude, keeps the stale selector, and appends another --resume. Import isPosixStartupShell and use it for the assignment-prefix check.
| // Contract-only: no POSIX caller threads a shell into buildAgentDraftLaunchPlan yet | ||
| // (`selectedRepoStartupShell` is Windows-only), so fish users still get `unset` here. | ||
| it('clears an agent draft prefill variable with fish syntax', () => { | ||
| const plan = buildAgentDraftLaunchPlan({ | ||
| agent: 'pi', | ||
| draft: 'hello', | ||
| cmdOverrides: {}, | ||
| platform: 'darwin' | ||
| platform: 'darwin', | ||
| shell: 'fish' | ||
| }) | ||
|
|
||
| expect(plan?.launchCommand).toBe( | ||
| `pi; command test -n "$fish_pid" && set --erase -g ORCA_PI_PREFILL; command test -z "$fish_pid" && unset ORCA_PI_PREFILL; true` | ||
| ) | ||
| expect(plan?.launchCommand).toBe('pi; set -e ORCA_PI_PREFILL') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- candidate files ---'
git ls-files | grep -E '(^|/)(tui-agent-startup(-shell)?\.(ts|tsx|js|jsx))$' || true
printf '%s\n' '--- relevant symbols and shell fields ---'
rg -n -S \
'buildAgentDraftLaunchPlan|selectedRepoStartupShell|launchCommand|login-shell|shell:' \
src/shared/tui-agent-startup-shell.test.ts \
src/shared/tui-agent-startup.test.ts \
src --glob '*.{ts,tsx,js,jsx}' \
| head -n 300
printf '%s\n' '--- AST outlines ---'
ast-grep outline src/shared/tui-agent-startup-shell.test.ts || true
ast-grep outline src/shared/tui-agent-startup.test.ts || trueRepository: stablyai/orca
Length of output: 30553
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- startup implementation files ---'
rg -l -S 'buildAgentDraftLaunchPlan|selectedRepoStartupShell|ORCA_.*PREFILL' src --glob '*.{ts,tsx,js,jsx}' \
| sort
printf '%s\n' '--- production call sites ---'
rg -n -S 'buildAgentDraftLaunchPlan|selectedRepoStartupShell' src --glob '*.{ts,tsx,js,jsx}' \
| head -n 300Repository: stablyai/orca
Length of output: 5919
🏁 Script executed:
#!/bin/bash
set -eu
for f in src/shared/tui-agent-startup-shell.test.ts src/shared/tui-agent-startup.test.ts; do
if [ -f "$f" ]; then
printf '%s\n' "--- $f (relevant ranges) ---"
case "$f" in
*shell.test.ts) sed -n '1,150p' "$f" ;;
*startup.test.ts) sed -n '780,900p' "$f" ;;
esac
fi
doneRepository: stablyai/orca
Length of output: 8655
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- shared startup shell implementation ---'
sed -n '1,360p' src/shared/tui-agent-startup-shell.ts
printf '%s\n' '--- shared startup planner ---'
sed -n '1,360p' src/shared/tui-agent-startup.ts
printf '%s\n' '--- renderer startup planner and shell resolution ---'
sed -n '1,140p' src/renderer/src/lib/tui-agent-startup.ts
sed -n '1,120p' src/renderer/src/lib/agent-resume-launch-target.ts
sed -n '850,920p' src/renderer/src/hooks/useComposerState.ts
sed -n '4360,4460p' src/renderer/src/hooks/useComposerState.tsRepository: stablyai/orca
Length of output: 30018
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- renderer draft-launch call sites ---'
sed -n '40,90p' src/renderer/src/lib/launch-work-item-direct-agent.ts
sed -n '80,135p' src/renderer/src/lib/source-control-agent-action-plan.ts
sed -n '1,80p' src/renderer/src/lib/launch-agent-startup-prompt-plan.ts
sed -n '80,125p' src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts
printf '%s\n' '--- main runtime draft-launch boundaries ---'
sed -n '22570,22675p' src/main/runtime/orca-runtime.ts
sed -n '26720,26810p' src/main/runtime/orca-runtime.ts
sed -n '27750,27825p' src/main/runtime/orca-runtime.ts
printf '%s\n' '--- shell type and environment sources ---'
rg -n -S 'AgentStartupShell|resolveLoginShellStartupDialect|client.*shell|platformInfo.*shell|clientEnvironment|queuedShell|startupArgs' \
src/shared src/renderer/src src/main/runtime/orca-runtime.ts \
--glob '*.{ts,tsx}' | head -n 400Repository: stablyai/orca
Length of output: 28962
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- all callers with argument blocks ---'
python3 - <<'PY'
from pathlib import Path
terms = ('buildAgentDraftLaunchPlan({',)
for p in Path('src').rglob('*.ts'):
text = p.read_text(errors='replace')
for term in terms:
start = 0
while True:
i = text.find(term, start)
if i < 0:
break
line = text.count('\n', 0, i) + 1
end = text.find('})', i)
if end < 0:
end = min(len(text), i + 500)
else:
end += 2
block = text[i:end]
print(f'--- {p}:{line} ---')
print(block[:1200])
start = i + len(term)
PYRepository: stablyai/orca
Length of output: 6196
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- shell override resolver ---'
cat -n src/shared/windows-terminal-shell.ts
printf '%s\n' '--- new-tab launch path ---'
sed -n '1,175p' src/renderer/src/lib/launch-agent-in-new-tab.ts
printf '%s\n' '--- background launch path ---'
sed -n '55,135p' src/renderer/src/lib/launch-agent-background-session.ts
printf '%s\n' '--- client login shell and platform info ---'
cat -n src/renderer/src/lib/client-login-shell.ts
sed -n '1,90p' src/renderer/src/lib/client-environment-info.ts
sed -n '600,645p' src/preload/index.ts
printf '%s\n' '--- direct-agent caller context ---'
sed -n '1,125p' src/renderer/src/lib/launch-work-item-direct-agent.tsRepository: stablyai/orca
Length of output: 22533
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
files = [
Path('src/renderer/src/lib/launch-work-item-direct-agent.ts'),
Path('src/renderer/src/lib/launch-agent-startup-prompt-plan.ts'),
Path('src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts'),
Path('src/renderer/src/hooks/useComposerState.ts'),
Path('src/main/runtime/orca-runtime.ts'),
]
for path in files:
text = path.read_text()
for m in re.finditer(r'buildAgentDraftLaunchPlan\(', text):
start = m.start()
# Capture enough source to identify whether shell is forwarded in this call.
block = text[start:min(len(text), start + 700)]
print(f'--- {path}:{text.count(chr(10), 0, start)+1} ---')
print('has_shell_property=', bool(re.search(r'\bshell\s*:', block)))
print(block.replace('\n', ' ')[:700])
PYRepository: stablyai/orca
Length of output: 4877
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- source-control plan inputs and callers ---'
sed -n '1,145p' src/renderer/src/lib/source-control-agent-action-plan.ts
rg -n -S 'buildSourceControlAgentActionPlan|terminalWindowsShell|shell:' \
src/renderer/src --glob '*.{ts,tsx}' | head -n 250
printf '%s\n' '--- folder workspace shell derivation ---'
sed -n '175,220p' src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts
rg -n -S 'buildFolderWorkspaceLinkedStartupPlan|resolveFolderWorkspaceLaunchDraft' \
src/renderer/src --glob '*.{ts,tsx}' | head -n 120
printf '%s\n' '--- direct work-item plan callers and launch platform construction ---'
rg -n -S 'buildDirectWorkItemAgentStartupPlan|launchPlatform:' \
src/renderer/src --glob '*.{ts,tsx}' | head -n 250Repository: stablyai/orca
Length of output: 40242
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
def resolve_startup_shell(platform, shell=None):
return shell or ('powershell' if platform == 'win32' else 'posix')
def clear_env(name, shell):
if shell == 'fish':
return f'set -e {name}'
if shell == 'powershell':
return f'Remove-Item Env:{name} -ErrorAction SilentlyContinue'
if shell == 'cmd':
return f'set "{name}="'
return f'unset {name}'
# Behavioral probe for the exact planner branches in the inspected source.
assert resolve_startup_shell('darwin') == 'posix'
assert resolve_startup_shell('darwin', 'fish') == 'fish'
assert clear_env('ORCA_PI_PREFILL', resolve_startup_shell('darwin')) == \
'unset ORCA_PI_PREFILL'
assert clear_env('ORCA_PI_PREFILL', resolve_startup_shell('darwin', 'fish')) == \
'set -e ORCA_PI_PREFILL'
assert clear_env('ORCA_OMP_PREFILL', resolve_startup_shell('linux')) == \
'unset ORCA_OMP_PREFILL'
# Static call-graph check: identify draft callers that do and do not forward shell.
files = [
'src/renderer/src/lib/launch-work-item-direct-agent.ts',
'src/renderer/src/lib/launch-agent-startup-prompt-plan.ts',
'src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts',
'src/renderer/src/hooks/useComposerState.ts',
'src/main/runtime/orca-runtime.ts',
]
for name in files:
text = Path(name).read_text()
for match in re.finditer(r'buildAgentDraftLaunchPlan\(', text):
block = text[match.start():match.start()+750]
line = text.count('\n', 0, match.start()) + 1
print(f'{name}:{line}: shell_forwarded={bool(re.search(r"\\bshell\\s*:", block))}')
print('behavioral_probe=pass')
PYRepository: stablyai/orca
Length of output: 418
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- existing client-login-shell pattern ---'
cat -n src/renderer/src/lib/ai-vault-resume-shell.ts
cat -n src/renderer/src/lib/ai-vault-resume-shell.test.ts
printf '%s\n' '--- direct work-item caller context ---'
sed -n '235,305p' src/renderer/src/lib/launch-work-item-direct.ts
sed -n '140,185p' src/renderer/src/components/right-sidebar/source-control/ai/recovery-launch.ts
printf '%s\n' '--- source-control delivery boundary ---'
sed -n '1,100p' src/renderer/src/components/right-sidebar/buildSourceControlAgentDeliveryPlan.ts
sed -n '70,130p' src/renderer/src/components/right-sidebar/source-control/panel/dialog-layer.tsx
printf '%s\n' '--- startup shell tests around production callers ---'
rg -n -S 'fish|buildDirectWorkItemAgentStartupPlan|planLaunchAgentStartupPrompt|planSourceControlAgentActionLaunch' \
src/renderer/src/lib src/renderer/src/components --glob '*.{test.ts,test.tsx}' | head -n 250Repository: stablyai/orca
Length of output: 28274
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
def resolve_startup_shell(platform, shell=None):
return shell or ('powershell' if platform == 'win32' else 'posix')
def clear_env(name, shell):
return {
'fish': f'set -e {name}',
'powershell': f'Remove-Item Env:{name} -ErrorAction SilentlyContinue',
'cmd': f'set "{name}="',
'posix': f'unset {name}',
}[shell]
assert resolve_startup_shell('darwin') == 'posix'
assert resolve_startup_shell('darwin', 'fish') == 'fish'
assert clear_env('ORCA_PI_PREFILL', resolve_startup_shell('darwin')) == 'unset ORCA_PI_PREFILL'
assert clear_env('ORCA_PI_PREFILL', resolve_startup_shell('darwin', 'fish')) == 'set -e ORCA_PI_PREFILL'
assert clear_env('ORCA_OMP_PREFILL', resolve_startup_shell('linux')) == 'unset ORCA_OMP_PREFILL'
for name in [
'src/renderer/src/lib/launch-work-item-direct-agent.ts',
'src/renderer/src/lib/launch-agent-startup-prompt-plan.ts',
'src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts',
'src/renderer/src/hooks/useComposerState.ts',
'src/main/runtime/orca-runtime.ts',
]:
text = Path(name).read_text()
for match in re.finditer(r'buildAgentDraftLaunchPlan\(', text):
block = text[match.start():match.start()+750]
line = text.count('\n', 0, match.start()) + 1
forwarded = bool(re.search(r'\bshell\s*:', block))
print(f'{name}:{line}: shell_forwarded={forwarded}')
print('behavioral_probe=pass')
PYRepository: stablyai/orca
Length of output: 627
Forward the Fish dialect for local POSIX draft launches.
Local non-Windows paths currently default to posix and emit unset ORCA_*_PREFILL. Fish rejects unset, so the exported prefill remains set. Resolve the shell that parses each local command with resolveLoginShellStartupDialect; retain posix for remote or unknown hosts.
Update src/renderer/src/lib/launch-agent-in-new-tab.ts, src/renderer/src/lib/launch-work-item-direct-agent.ts, and src/main/runtime/orca-runtime.ts. Add a production-path Fish regression test. Keep the OMP expectation as unset for the POSIX case.
📍 Affects 2 files
src/shared/tui-agent-startup-shell.test.ts#L100-L111(this comment)src/shared/tui-agent-startup.test.ts#L859-L859
…uses fixed (#15018) * reland: portable startup-shell dialect, with the two revert causes fixed Relands #14863 (reverted by #14975) with fixes for both regressions the revert cited. 1. History GC deleted folder-workspace shell history. The live set was built from `getAllWorktreeMeta()` alone, but a folder workspace's PTY carries `folder:<id>` as its worktree id, so every live folder workspace looked orphaned. `getKnownWorktreeIdsForHistoryGc` now unions in `getFolderWorkspaces()`. Both consumers — the history-directory prune and the fish-history sweep — read that one set, so the fix covers bash, zsh and fish history alike. The directory prune had this gap since #1524; #14863 only widened its blast radius to fish files. 2. A copied Codex resume command aborted under `set -u`. Its leading clear statement has to test `$fish_pid`, and that unbound expansion takes the whole line — including the agent launch — down with it. Copied text runs in a shell Orca never spawned, so nothing can seed that variable first. The removal now rides on the agent itself as `env -u`, which needs no shell syntax and no expansion. Verified byte-identical under `set -u` in sh, bash, zsh, dash, ksh and fish. `env` cannot run the `cd` builtin, and a child `cd` would not move the agent, so the prefix is placed on the agent rather than on the whole `cd … && agent` chain. cmd and PowerShell have no nounset hazard and keep their clear ahead of the `cd`, which preserves `cd … && agent` — a failed `cd` still cannot launch the agent in the wrong directory. * fix(history-gc): stop three more paths from deleting live shell history Found by adversarial review of the reland. All three are the same class as the bug that caused the revert: a live set that is missing a category of real workspace, so the GC reads it as orphaned. 1. Profiles. The history root is `userData/terminal-history`, which has no profile segment, but the Store the GC consults is per-profile. So after a profile switch the live set condemned every other profile's history — and fish history, which lands in the user's own fish data dir, is shared by every profile on the machine. The live set now unions in the inactive profiles' worktrees and folder workspaces, read from their data files. A profile whose ids cannot be read reports the empty set rather than one that condemns real history. 2. No empty-set guard on the tree scan. `sweepOrphanedFishHistoryFiles` refuses an empty live set because it cannot be told apart from a store that failed to hydrate; the directory scan, which deletes more, had no such guard. A store that fell back to default state would have taken every worktree's bash and zsh history with it, across all roots including WSL. Four existing tests passed `new Set()` and relied on "empty means everything is orphaned" — exactly the behavior being removed — so they now pass a real live set. 3. Relay fish history. The relay isolates its history tree under its own root but wrote fish history into the shared fish data dir under the desktop naming, keyed by the CLIENT's worktree ids. On a machine running both Orca and a relay host, the desktop sweep deleted remote sessions' history once it went stale. Relay files are now `orca_relay_<hash>`, which the sweep's pattern deliberately does not match; the relay still deletes them by exact name when the worktree goes away. * fix(resume): enforce the env-removal invariants instead of documenting them Both found by adversarial review; both were unreachable from today's callers and silent if reached, which is exactly how they would survive to a caller that does reach them. - A pinned CODEX_HOME and the removal named the same variable, and `env -u` strips what the assignment just set — so the agent would have resumed against the real home and not found the session. The removal list now excludes any name the prefix pins, keeping the assignment authoritative as the old `clear…; CODEX_HOME=x agent` ordering did. Same fix in the git-bash twin. The PowerShell branch already clears before it assigns, so it was never affected. - Placement was keyed on the platform while the grammar it selects is keyed on the shell, so `platform: 'linux'` with `shell: 'powershell'` emitted POSIX `env -u` into a PowerShell line. PowerShell now routes to the PowerShell builder whatever the host, and the POSIX/cmd split below asks the shell rather than the platform.
…uses fixed (stablyai#15018) * reland: portable startup-shell dialect, with the two revert causes fixed Relands stablyai#14863 (reverted by stablyai#14975) with fixes for both regressions the revert cited. 1. History GC deleted folder-workspace shell history. The live set was built from `getAllWorktreeMeta()` alone, but a folder workspace's PTY carries `folder:<id>` as its worktree id, so every live folder workspace looked orphaned. `getKnownWorktreeIdsForHistoryGc` now unions in `getFolderWorkspaces()`. Both consumers — the history-directory prune and the fish-history sweep — read that one set, so the fix covers bash, zsh and fish history alike. The directory prune had this gap since stablyai#1524; stablyai#14863 only widened its blast radius to fish files. 2. A copied Codex resume command aborted under `set -u`. Its leading clear statement has to test `$fish_pid`, and that unbound expansion takes the whole line — including the agent launch — down with it. Copied text runs in a shell Orca never spawned, so nothing can seed that variable first. The removal now rides on the agent itself as `env -u`, which needs no shell syntax and no expansion. Verified byte-identical under `set -u` in sh, bash, zsh, dash, ksh and fish. `env` cannot run the `cd` builtin, and a child `cd` would not move the agent, so the prefix is placed on the agent rather than on the whole `cd … && agent` chain. cmd and PowerShell have no nounset hazard and keep their clear ahead of the `cd`, which preserves `cd … && agent` — a failed `cd` still cannot launch the agent in the wrong directory. * fix(history-gc): stop three more paths from deleting live shell history Found by adversarial review of the reland. All three are the same class as the bug that caused the revert: a live set that is missing a category of real workspace, so the GC reads it as orphaned. 1. Profiles. The history root is `userData/terminal-history`, which has no profile segment, but the Store the GC consults is per-profile. So after a profile switch the live set condemned every other profile's history — and fish history, which lands in the user's own fish data dir, is shared by every profile on the machine. The live set now unions in the inactive profiles' worktrees and folder workspaces, read from their data files. A profile whose ids cannot be read reports the empty set rather than one that condemns real history. 2. No empty-set guard on the tree scan. `sweepOrphanedFishHistoryFiles` refuses an empty live set because it cannot be told apart from a store that failed to hydrate; the directory scan, which deletes more, had no such guard. A store that fell back to default state would have taken every worktree's bash and zsh history with it, across all roots including WSL. Four existing tests passed `new Set()` and relied on "empty means everything is orphaned" — exactly the behavior being removed — so they now pass a real live set. 3. Relay fish history. The relay isolates its history tree under its own root but wrote fish history into the shared fish data dir under the desktop naming, keyed by the CLIENT's worktree ids. On a machine running both Orca and a relay host, the desktop sweep deleted remote sessions' history once it went stale. Relay files are now `orca_relay_<hash>`, which the sweep's pattern deliberately does not match; the relay still deletes them by exact name when the worktree goes away. * fix(resume): enforce the env-removal invariants instead of documenting them Both found by adversarial review; both were unreachable from today's callers and silent if reached, which is exactly how they would survive to a caller that does reach them. - A pinned CODEX_HOME and the removal named the same variable, and `env -u` strips what the assignment just set — so the agent would have resumed against the real home and not found the session. The removal list now excludes any name the prefix pins, keeping the assignment authoritative as the old `clear…; CODEX_HOME=x agent` ordering did. Same fix in the git-bash twin. The PowerShell branch already clears before it assigns, so it was never affected. - Placement was keyed on the platform while the grammar it selects is keyed on the shell, so `platform: 'linux'` with `shell: 'powershell'` emitted POSIX `env -u` into a PowerShell line. PowerShell now routes to the PowerShell builder whatever the host, and the POSIX/cmd split below asks the shell rather than the platform.
… shell d…" (stablyai#14975) This reverts commit fd7b7bb.
…uses fixed (stablyai#15018) * reland: portable startup-shell dialect, with the two revert causes fixed Relands stablyai#14863 (reverted by stablyai#14975) with fixes for both regressions the revert cited. 1. History GC deleted folder-workspace shell history. The live set was built from `getAllWorktreeMeta()` alone, but a folder workspace's PTY carries `folder:<id>` as its worktree id, so every live folder workspace looked orphaned. `getKnownWorktreeIdsForHistoryGc` now unions in `getFolderWorkspaces()`. Both consumers — the history-directory prune and the fish-history sweep — read that one set, so the fix covers bash, zsh and fish history alike. The directory prune had this gap since stablyai#1524; stablyai#14863 only widened its blast radius to fish files. 2. A copied Codex resume command aborted under `set -u`. Its leading clear statement has to test `$fish_pid`, and that unbound expansion takes the whole line — including the agent launch — down with it. Copied text runs in a shell Orca never spawned, so nothing can seed that variable first. The removal now rides on the agent itself as `env -u`, which needs no shell syntax and no expansion. Verified byte-identical under `set -u` in sh, bash, zsh, dash, ksh and fish. `env` cannot run the `cd` builtin, and a child `cd` would not move the agent, so the prefix is placed on the agent rather than on the whole `cd … && agent` chain. cmd and PowerShell have no nounset hazard and keep their clear ahead of the `cd`, which preserves `cd … && agent` — a failed `cd` still cannot launch the agent in the wrong directory. * fix(history-gc): stop three more paths from deleting live shell history Found by adversarial review of the reland. All three are the same class as the bug that caused the revert: a live set that is missing a category of real workspace, so the GC reads it as orphaned. 1. Profiles. The history root is `userData/terminal-history`, which has no profile segment, but the Store the GC consults is per-profile. So after a profile switch the live set condemned every other profile's history — and fish history, which lands in the user's own fish data dir, is shared by every profile on the machine. The live set now unions in the inactive profiles' worktrees and folder workspaces, read from their data files. A profile whose ids cannot be read reports the empty set rather than one that condemns real history. 2. No empty-set guard on the tree scan. `sweepOrphanedFishHistoryFiles` refuses an empty live set because it cannot be told apart from a store that failed to hydrate; the directory scan, which deletes more, had no such guard. A store that fell back to default state would have taken every worktree's bash and zsh history with it, across all roots including WSL. Four existing tests passed `new Set()` and relied on "empty means everything is orphaned" — exactly the behavior being removed — so they now pass a real live set. 3. Relay fish history. The relay isolates its history tree under its own root but wrote fish history into the shared fish data dir under the desktop naming, keyed by the CLIENT's worktree ids. On a machine running both Orca and a relay host, the desktop sweep deleted remote sessions' history once it went stale. Relay files are now `orca_relay_<hash>`, which the sweep's pattern deliberately does not match; the relay still deletes them by exact name when the worktree goes away. * fix(resume): enforce the env-removal invariants instead of documenting them Both found by adversarial review; both were unreachable from today's callers and silent if reached, which is exactly how they would survive to a caller that does reach them. - A pinned CODEX_HOME and the removal named the same variable, and `env -u` strips what the assignment just set — so the agent would have resumed against the real home and not found the session. The removal list now excludes any name the prefix pins, keeping the assignment authoritative as the old `clear…; CODEX_HOME=x agent` ordering did. Same fix in the git-bash twin. The PowerShell branch already clears before it assigns, so it was never affected. - Placement was keyed on the platform while the grammar it selects is keyed on the shell, so `platform: 'linux'` with `shell: 'powershell'` emitted POSIX `env -u` into a PowerShell line. PowerShell now routes to the PowerShell builder whatever the host, and the POSIX/cmd split below asks the shell rather than the platform.
This reverts #14863 because it introduced a launch-blocking regression.
Folder-workspace Fish history can be deleted on a later startup, and Unix cleanup/resume commands can abort under
set -u.We will reland with a fix: https://linear.app/stably/issue/STA-4566/reland-14863-portable-unix-startup-dialect-after-revert-14975