Repository navigation
feat(terminal): allow configuring the interactive shell #37924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
39d0fcc
a70f6da
24525d6
5571fab
b7e96ac
e8f6b02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ import { makeKeyedCoalescingWorker } from "@t3tools/shared/KeyedCoalescingWorker | |
| import * as KeyedLock from "@t3tools/shared/KeyedLock"; | ||
| import { AgentScope } from "@t3tools/shared/AgentScope"; | ||
| import * as HostProcess from "@t3tools/shared/HostProcess"; | ||
| import { mergePathEntries } from "@t3tools/shared/shell"; | ||
| import { SpawnExecutableResolution, mergePathEntries } from "@t3tools/shared/shell"; | ||
|
|
||
| import { acpRegistryManagedBinaryDirectories } from "@t3tools/provider-acp-registry/server"; | ||
| import { getTerminalLabel } from "@t3tools/shared/terminalLabels"; | ||
|
|
@@ -601,6 +601,9 @@ function shellCandidateFromCommand( | |
| if (platform === "win32" && (shellName === "pwsh.exe" || shellName === "powershell.exe")) { | ||
| return { shell: command, args: ["-NoLogo", "-NoExit", "-Command", POWERSHELL_UTF8_SETUP] }; | ||
| } | ||
| if (platform === "win32" && (shellName === "bash.exe" || shellName === "bash")) { | ||
| return { shell: command, args: ["--login", "-i"] }; | ||
| } | ||
| if (platform !== "win32" && shellName === "zsh") { | ||
| return { shell: command, args: ["-o", "nopromptsp"] }; | ||
| } | ||
|
|
@@ -651,14 +654,18 @@ const resolveShellCandidates = Effect.fn("terminal.resolveShellCandidates")(func | |
| shellResolver: () => string, | ||
| platform: NodeJS.Platform, | ||
| env: NodeJS.ProcessEnv, | ||
| terminalShell: string | undefined, | ||
| ) { | ||
| // This is an executable path, not a command line; spaces belong to the path. | ||
| const configured = shellCandidateFromCommand(terminalShell?.trim() || null, platform); | ||
| const requested = shellCandidateFromCommand( | ||
| yield* normalizeShellCommand(shellResolver(), platform), | ||
| platform, | ||
| ); | ||
|
|
||
| if (platform === "win32") { | ||
| return uniqueShellCandidates([ | ||
| configured, | ||
| requested, | ||
| shellCandidateFromCommand("pwsh.exe", platform), | ||
| shellCandidateFromCommand(windowsPowerShellPath(env), platform), | ||
|
|
@@ -670,6 +677,7 @@ const resolveShellCandidates = Effect.fn("terminal.resolveShellCandidates")(func | |
| } | ||
|
|
||
| return uniqueShellCandidates([ | ||
| configured, | ||
| requested, | ||
| shellCandidateFromCommand(yield* normalizeShellCommand(env.SHELL, platform), platform), | ||
| shellCandidateFromCommand("/bin/zsh", platform), | ||
|
|
@@ -1781,6 +1789,7 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func | |
| const platform = yield* HostProcess.Platform; | ||
| const architecture = yield* HostProcess.Architecture; | ||
| const agentScope = yield* AgentScope; | ||
| const resolveExecutable = yield* SpawnExecutableResolution; | ||
| // Inherit the full environment minus createTerminalSpawnEnv's blocklist; allowlists silently drop user tooling variables. | ||
| const baseEnv = options.env ?? process.env; | ||
| const shellResolver = options.shellResolver ?? (() => defaultShellResolver(platform, baseEnv)); | ||
|
|
@@ -2728,8 +2737,41 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func | |
| ); | ||
| } | ||
|
|
||
| // PATH lookup must use the child's working directory, not the server's. | ||
| const lookupEnv = | ||
| platform === "win32" | ||
| ? spawnEnv | ||
| : { | ||
| ...spawnEnv, | ||
| PATH: (spawnEnv.PATH ?? spawnEnv.Path ?? spawnEnv.path ?? "") | ||
| .split(":") | ||
| // An empty entry means the working directory, which resolve("") yields. | ||
| .map((entry) => path.resolve(session.cwd, entry.replace(/^"+|"+$/g, ""))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium When 🚀 Reply "fix it for me" or copy this AI Prompt for your agent: |
||
| .join(":"), | ||
| }; | ||
| // POSIX node-pty can return a PTY before exec fails, so validate before accepting a candidate. | ||
| const executable = | ||
| platform !== "win32" | ||
| ? resolveExecutable( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve executables without blocking the server event loop. The default resolver uses Use asynchronous filesystem resolution, or an isolated resolver with a bounded lifetime. An Effect timeout around this synchronous call cannot interrupt the blocked event loop. (nodejs.org)
|
||
| candidate.shell.includes("/") | ||
| ? path.resolve(session.cwd, candidate.shell) | ||
| : candidate.shell, | ||
| platform, | ||
| lookupEnv, | ||
| ) | ||
| : candidate.shell; | ||
| if (executable === undefined) { | ||
| return yield* trySpawn( | ||
| shellCandidates, | ||
| spawnEnv, | ||
| session, | ||
| index + 1, | ||
| new PtyAdapter.PtySpawnError({ adapter: "terminal-manager", shell: candidate.shell }), | ||
| ); | ||
| } | ||
|
|
||
| const launch = yield* agentScope.wrap({ | ||
| command: candidate.shell, | ||
| command: executable, | ||
| args: candidate.args ?? [], | ||
| name: "terminal", | ||
| env: spawnEnv, | ||
|
|
@@ -2806,6 +2848,7 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func | |
| shellResolver, | ||
| platform, | ||
| baseEnv, | ||
| session.runtimeEnv?.T3CODE_TERMINAL_SHELL ?? baseEnv.T3CODE_TERMINAL_SHELL, | ||
| ).pipe(Effect.provideService(FileSystem.FileSystem, fileSystem)); | ||
| const terminalEnv = createTerminalSpawnEnv( | ||
| baseEnv, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not map an absent PATH to the working directory.
If
SHELLand every PATH spelling are unset,defaultShellResolverreturns the bare namebash. The lookup environment atapps/server/src/terminal/Manager.ts:2746turns the absent PATH into"", andpath.resolve(session.cwd, "")returnssession.cwd. Abashexecutable in the worktree can then resolve and launch when the terminal opens, without an explicit shell preference. The terminal already starts in that directory, so the added exposure is this automatic launch.Treat an absent PATH as having no entries. An explicitly empty PATH keeps its working-directory semantics. With PATH absent, the bare-name candidate is skipped, and
trySpawncontinues with the next candidate.Suggested fix