Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

refactor(tmux): extract session ID resolution to private method

Dev jacob6c1672be381d
diff --git a/cli/src/lib/tmuxBackend.ts b/cli/src/lib/tmuxBackend.ts
index 98348b28f..4fcb742bf 100644
--- a/cli/src/lib/tmuxBackend.ts
+++ b/cli/src/lib/tmuxBackend.ts
@@ -164,12 +164,7 @@ export class TmuxBackend implements TerminalBackend<TmuxRuntimeRef> {
}
async kill(runtime: TmuxRuntimeRef): Promise<TerminalActionResult> {
- const sessionId = await new Promise<string | null>((resolve) => {
- execFile('tmux', ['display-message', '-p', '-t', runtime.paneId, '#{session_id}'], { timeout: 2_000 }, (error, stdout) => {
- const value = stdout.trim()
- resolve(!error && /^\$\d+$/.test(value) ? value : null)
- })
- })
+ const sessionId = await this.resolveSessionId(runtime.paneId)
if (!sessionId) return terminalActionNotStarted('tmux session could not be resolved from pane')
const ok = await new Promise<boolean>((resolve) => {
execFile('tmux', ['kill-session', '-t', sessionId], { timeout: 5_000 }, (error) => resolve(!error))
@@ -186,12 +181,7 @@ export class TmuxBackend implements TerminalBackend<TmuxRuntimeRef> {
*/
async clearEnv(runtime: TmuxRuntimeRef, names: readonly string[]): Promise<TerminalActionResult> {
if (!names.length) return legacyActionResult(true, 'tmux clear environment')
- const sessionId = await new Promise<string | null>((resolve) => {
- execFile('tmux', ['display-message', '-p', '-t', runtime.paneId, '#{session_id}'], { timeout: 2_000 }, (error, stdout) => {
- const value = stdout.trim()
- resolve(!error && /^\$\d+$/.test(value) ? value : null)
- })
- })
+ const sessionId = await this.resolveSessionId(runtime.paneId)
if (!sessionId) return terminalActionNotStarted('tmux session could not be resolved from pane')
const ok = await new Promise<boolean>((resolve) => {
execFile('tmux', clearEnvArgs(sessionId, names), { timeout: 5_000 }, (error) => resolve(!error))
@@ -199,6 +189,16 @@ export class TmuxBackend implements TerminalBackend<TmuxRuntimeRef> {
return legacyActionResult(ok, 'tmux clear environment')
}
+ /** The id of the session that owns [paneId], or null when tmux will not say. */
+ private resolveSessionId(paneId: string): Promise<string | null> {
+ return new Promise((resolve) => {
+ execFile('tmux', ['display-message', '-p', '-t', paneId, '#{session_id}'], { timeout: 2_000 }, (error, stdout) => {
+ const value = stdout.trim()
+ resolve(!error && /^\$\d+$/.test(value) ? value : null)
+ })
+ })
+ }
+
/**
* Re-arm `remain-on-exit` on an already-live pane, mirroring what `create()` does at spawn time.
*