The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 18:30 UTC
fix(server): worktree setup no longer hangs when the shell is Nushell (#29461)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Ken Johnson committed
Nov 12, 2026 at 17:16 UTC
12a62edd6709b4cbfae09752b414c945924aa0fd
2 files changed
+49
-6
apps/server/src/project/ProjectSetupScriptRunner.test.ts
+29
-1
@@ -38,6 +38,7 @@ const openSnapshot = (history: string): TerminalSessionSnapshot => ({
38
});
39
40
const makeHarness = Effect.fn(function* (options: {
41
+ readonly command?: string;
42
readonly history?: string;
43
readonly opening?: Deferred.Deferred<void>;
44
readonly shell?: string | null;
@@ -88,7 +89,7 @@ const makeHarness = Effect.fn(function* (options: {
89
{
90
id: "setup",
91
name: "Setup",
91
- command: "vp i",
92
+ command: options.command ?? "vp i",
93
icon: "configure",
94
runOnWorktreeCreate: true,
95
},
@@ -102,6 +103,7 @@ const makeHarness = Effect.fn(function* (options: {
103
104
const setup = Effect.fn(function* (
105
options: {
106
+ readonly command?: string;
107
readonly history?: string;
108
readonly shell?: string | null;
109
} = {},
@@ -123,6 +125,32 @@ describe("ProjectSetupScriptRunner", () => {
125
}),
126
);
127
128
+ it.effect("types an escaped Nushell wrapper once its line editor starts", () =>
129
+ Effect.gen(function* () {
130
+ const command =
131
+ 'print "quoted"; print \'C:\\tools\'; print "$env.PATH"\nexit 7 # comment\r\n\t';
132
+ const escaped =
133
+ 'print \\"quoted\\"; print \'C:\\\\tools\'; print \\"$env.PATH\\"\\u{a}exit 7 # comment\\u{d}\\u{a}\\u{9}';
134
+ const { writes, emit } = yield* setup({ shell: "/opt/homebrew/bin/nu", command });
135
+ yield* TestClock.adjust("1 second");
136
+ expect(yield* Queue.size(writes)).toBe(0);
137
+ yield* emit({ ...event, type: "output", data: "> \x1b[?2004h" });
138
+ const written = yield* Queue.take(writes);
139
+ const sentinel = written.match(/__T3_SETUP_DONE___[0-9a-f]{32}:/)?.[0];
140
+ expect(sentinel).toBeDefined();
141
+ expect(written).toBe(
142
+ ` ${[
143
+ "$env.LAST_EXIT_CODE = 0",
144
+ "let __t3f = try { mktemp --tmpdir-path $env.T3CODE_WORKTREE_PATH --suffix .nu .t3-setup-XXXXXXXX } catch {|e| print -e $e.msg; null }",
145
+ `if $__t3f == null { $env.LAST_EXIT_CODE = 1 } else { try { [$"rm --permanent ($__t3f | to nuon)" "${escaped}"] | str join (char newline) | save --force --raw $__t3f; ^$nu.current-exe --login --commands $"cd $env.T3CODE_WORKTREE_PATH; source ($__t3f | to nuon)" } catch {|e| if $e != null and $e.exit_code? == null { print -e $e.msg }; if $env.LAST_EXIT_CODE == 0 { $env.LAST_EXIT_CODE = 1 } } }`,
146
+ "let __t3c = $env.LAST_EXIT_CODE",
147
+ "try { if $__t3f != null and ($__t3f | path exists) { rm --permanent $__t3f } } catch {|e| print -e $e.msg }",
148
+ `print $"\\n${sentinel}($__t3c)"`,
149
+ ].join("; ")}\r`,
150
+ );
151
+ }),
152
+ );
153
+
154
it.effect("shows a startup prompt and types only once the line editor starts", () =>
155
Effect.gen(function* () {
156
const { result, writes, outputLines, emit } = yield* setup();
apps/server/src/project/ProjectSetupScriptRunner.ts
+20
-5
@@ -154,7 +154,7 @@ function stripTerminalControl(text: string): string {
154
.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "");
155
}
156
157
-// Line editors (zsh, fish, bash 5.1+) enable bracketed paste when they start reading a command.
157
+// Line editors (zsh, fish, nu, bash 5.1+) enable bracketed paste when they start reading a command.
158
const BRACKETED_PASTE_ON = "\x1b[?2004h";
159
const BRACKETED_PASTE_OFF = "\x1b[?2004l";
160
// Longer than one subprocess poll plus its ps timeout, so a startup prompt is seen as busy first.
@@ -166,12 +166,13 @@ function lineEditorReading(text: string, previous: boolean): boolean {
166
return on === off ? previous : on > off;
167
}
168
169
-type CompletionShell = "posix" | "fish" | "powershell";
169
+type CompletionShell = "posix" | "fish" | "nushell" | "powershell";
170
171
function resolveCompletionShell(shell: string): CompletionShell | null {
172
const name = (shell.split(/[/\\]/).at(-1) ?? shell).toLowerCase().replace(/\.exe$/, "");
173
if (name === "cmd") return null;
174
if (name === "fish") return "fish";
175
+ if (name === "nu") return "nushell";
176
if (name === "pwsh" || name === "powershell") return "powershell";
177
return "posix";
178
}
@@ -188,6 +189,20 @@ function wrapCommandForCompletion(
189
return `$global:LASTEXITCODE = $null; & {\r${body}\r}; if ($null -ne $LASTEXITCODE) { $__t3c = $LASTEXITCODE } elseif ($?) { $__t3c = 0 } else { $__t3c = 1 }; Write-Host "${sentinel}$__t3c"`;
190
case "fish":
191
return `begin\r${body}\rend; printf '\\n${sentinel}%s\\n' $status`;
192
+ case "nushell": {
193
+ const escaped = command.replace(/["\\\x00-\x1f]/g, (char) =>
194
+ char === '"' || char === "\\" ? `\\${char}` : `\\u{${char.charCodeAt(0).toString(16)}}`,
195
+ );
196
+ // Nu resolves imports before running cd; source a file rooted in the worktree.
197
+ return [
198
+ "$env.LAST_EXIT_CODE = 0",
199
+ "let __t3f = try { mktemp --tmpdir-path $env.T3CODE_WORKTREE_PATH --suffix .nu .t3-setup-XXXXXXXX } catch {|e| print -e $e.msg; null }",
200
+ `if $__t3f == null { $env.LAST_EXIT_CODE = 1 } else { try { [$"rm --permanent ($__t3f | to nuon)" "${escaped}"] | str join (char newline) | save --force --raw $__t3f; ^$nu.current-exe --login --commands $"cd $env.T3CODE_WORKTREE_PATH; source ($__t3f | to nuon)" } catch {|e| if $e != null and $e.exit_code? == null { print -e $e.msg }; if $env.LAST_EXIT_CODE == 0 { $env.LAST_EXIT_CODE = 1 } } }`,
201
+ "let __t3c = $env.LAST_EXIT_CODE",
202
+ "try { if $__t3f != null and ($__t3f | path exists) { rm --permanent $__t3f } } catch {|e| print -e $e.msg }",
203
+ `print $"\\n${sentinel}($__t3c)"`,
204
+ ].join("; ");
205
+ }
206
case "posix":
207
return `( ${body}\r); printf '\\n${sentinel}%s\\n' "$?"`;
208
}
@@ -517,9 +532,9 @@ export const make = Effect.gen(function* () {
532
// Return once the terminal exists so callers can show it while a startup prompt waits.
533
// PowerShell and cmd have no line-editor signal.
534
yield* (
520
- completionShell === "posix" || completionShell === "fish"
521
- ? readiness.wait
522
- : Effect.succeed("ready" as const)
535
+ completionShell === "powershell" || completionShell === null
536
+ ? Effect.succeed("ready" as const)
537
+ : readiness.wait
538
).pipe(
539
Effect.flatMap((shell) =>
540
shell === "exited" || commandLine === null