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 23, 00:30 UTC
fix(desktop): stop dev cleanup from terminating other worktrees (#18397)
Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Oct 20, 2026 at 00:27 UTC
b05ff173ad2b285d343c327583aeb2fd765e451b
2 files changed
+101
-3
apps/desktop/scripts/dev-electron.mjs
+8
-3
@@ -94,9 +94,14 @@ function cleanupStaleDevApps() {
94
return;
95
}
96
97
- NodeChildProcess.spawnSync("pkill", ["-f", "--", `--t3code-dev-root=${desktopDir}`], {
98
- stdio: "ignore",
99
- });
97
+ const escapedDesktopDir = desktopDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
98
+ NodeChildProcess.spawnSync(
99
+ "pkill",
100
+ ["-f", "--", `(^| )--t3code-dev-root=${escapedDesktopDir}( |$)`],
101
+ {
102
+ stdio: "ignore",
103
+ },
104
+ );
105
}
106
107
function startApp() {
apps/desktop/scripts/electron-launcher.test.mjs
+93
@@ -1,6 +1,9 @@
1
+import * as NodeChildProcess from "node:child_process";
2
+import * as NodeEvents from "node:events";
3
import * as NodeFS from "node:fs";
4
import * as NodeOS from "node:os";
5
import * as NodePath from "node:path";
6
+import * as NodeVM from "node:vm";
7
8
import { assert, describe, it } from "vite-plus/test";
9
@@ -151,3 +154,93 @@ describe("electron development launcher", () => {
154
assert.equal(production.generatedIconPath, "/runtime/icon-prod.icns");
155
});
156
});
157
+
158
+async function startupCleanupPattern(desktopDir) {
159
+ const source = NodeFS.readFileSync(new URL("./dev-electron.mjs", import.meta.url), "utf8");
160
+ let pattern;
161
+ // Supply inert imports so the real startup runs without launching Electron or signalling processes.
162
+ await NodeVM.runInNewContext(
163
+ `(async () => { ${source.replace(/^import\s[\s\S]*?;\n/gm, "")} })()`,
164
+ {
165
+ NodeChildProcess: {
166
+ execFileSync: () => undefined,
167
+ spawnSync: (command, args) => {
168
+ if (command === "pkill" && args.includes("-f")) pattern = args.at(-1);
169
+ },
170
+ spawn: () => new NodeEvents.EventEmitter(),
171
+ },
172
+ NodeFS: { watch: () => ({ close: () => undefined }) },
173
+ NodeOS: { platform: () => "linux" },
174
+ NodePath,
175
+ desktopDir,
176
+ resolveDevProtocolClient: () => null,
177
+ resolveElectronLaunchCommand: (args) => ({ electronPath: "electron", args }),
178
+ waitForResources: async () => undefined,
179
+ URL,
180
+ process: {
181
+ env: { VITE_DEV_SERVER_URL: "http://localhost:1234" },
182
+ execPath: "node",
183
+ once: () => undefined,
184
+ },
185
+ },
186
+ );
187
+ assert.isString(pattern);
188
+ return pattern;
189
+}
190
+
191
+it
192
+ // oxlint-disable-next-line t3code/no-global-process-runtime -- Native pgrep is unavailable on Windows.
193
+ .skipIf(NodeOS.platform() === "win32")
194
+ .each([
195
+ "/tmp/t3-feature.one/apps/desktop",
196
+ "/tmp/t3-feature.one [two](three)+?^${four}|back\\slash*/apps/desktop",
197
+ ])("dev cleanup matches only the literal root argument: %s", async (desktopDir) => {
198
+ const pattern = await startupCleanupPattern(desktopDir);
199
+ const flag = `--t3code-dev-root=${desktopDir}`;
200
+ const argvCases = [
201
+ [flag],
202
+ [flag, "main.cjs"],
203
+ [flag.replace(".one", "Xone")],
204
+ [`${flag}-two`],
205
+ [`prefix${flag}`],
206
+ [`--t3code-dev-root=/other${desktopDir}`],
207
+ ];
208
+ const children = [];
209
+ try {
210
+ for (const args of argvCases) {
211
+ const child = NodeChildProcess.spawn(
212
+ process.execPath,
213
+ ["-e", "process.send('ready'); setInterval(() => {}, 1000)", "--", ...args],
214
+ { stdio: ["ignore", "ignore", "inherit", "ipc"] },
215
+ );
216
+ children.push(child);
217
+ await Promise.race([
218
+ NodeEvents.once(child, "message"),
219
+ NodeEvents.once(child, "exit").then(() => {
220
+ throw new Error("Fixture exited before readiness");
221
+ }),
222
+ ]);
223
+ }
224
+ // Use the native ERE engine, but never execute the launcher's signal-producing command.
225
+ const result = NodeChildProcess.spawnSync(
226
+ "pgrep",
227
+ ["-P", String(process.pid), "-f", "--", pattern],
228
+ { encoding: "utf8" },
229
+ );
230
+ assert.equal(result.status, 0, result.stderr);
231
+ const matches = result.stdout.trim().split(/\s+/).map(Number);
232
+ assert.sameMembers(
233
+ matches,
234
+ children.slice(0, 2).map((child) => child.pid),
235
+ );
236
+ } finally {
237
+ await Promise.all(
238
+ children.map(async (child) => {
239
+ if (child.exitCode !== null || child.signalCode !== null) return;
240
+ const exited = NodeEvents.once(child, "exit");
241
+ child.kill("SIGTERM");
242
+ await exited;
243
+ }),
244
+ );
245
+ }
246
+});