fix(tmux): prefer split-or-defer with FIFO deferred attach
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
import type { PaneAction } from "./types"
|
||||
import { applyLayout, spawnTmuxPane, closeTmuxPane, enforceMainPaneWidth, replaceTmuxPane } from "../../shared/tmux"
|
||||
import type { TmuxConfig } from "../../config/schema"
|
||||
import type { PaneAction, WindowState } from "./types"
|
||||
import {
|
||||
applyLayout,
|
||||
spawnTmuxPane,
|
||||
closeTmuxPane,
|
||||
enforceMainPaneWidth,
|
||||
replaceTmuxPane,
|
||||
} from "../../shared/tmux"
|
||||
import { getTmuxPath } from "../../tools/interactive-bash/tmux-path-resolver"
|
||||
import { queryWindowState } from "./pane-state-querier"
|
||||
import { log } from "../../shared"
|
||||
import type {
|
||||
ActionExecutorDeps,
|
||||
ActionResult,
|
||||
ExecuteContext,
|
||||
ActionExecutorDeps,
|
||||
} from "./action-executor-core"
|
||||
import { executeActionWithDeps } from "./action-executor-core"
|
||||
|
||||
export type { ActionExecutorDeps, ActionResult, ExecuteContext } from "./action-executor-core"
|
||||
export type { ActionExecutorDeps, ActionResult } from "./action-executor-core"
|
||||
|
||||
export interface ExecuteActionsResult {
|
||||
success: boolean
|
||||
@@ -16,19 +23,92 @@ export interface ExecuteActionsResult {
|
||||
results: Array<{ action: PaneAction; result: ActionResult }>
|
||||
}
|
||||
|
||||
const DEFAULT_DEPS: ActionExecutorDeps = {
|
||||
spawnTmuxPane,
|
||||
closeTmuxPane,
|
||||
replaceTmuxPane,
|
||||
applyLayout,
|
||||
enforceMainPaneWidth,
|
||||
export interface ExecuteContext {
|
||||
config: TmuxConfig
|
||||
serverUrl: string
|
||||
windowState: WindowState
|
||||
sourcePaneId?: string
|
||||
}
|
||||
|
||||
async function enforceMainPane(
|
||||
windowState: WindowState,
|
||||
config: TmuxConfig,
|
||||
): Promise<void> {
|
||||
if (!windowState.mainPane) return
|
||||
await enforceMainPaneWidth(windowState.mainPane.paneId, windowState.windowWidth, {
|
||||
mainPaneSize: config.main_pane_size,
|
||||
mainPaneMinWidth: config.main_pane_min_width,
|
||||
agentPaneMinWidth: config.agent_pane_min_width,
|
||||
})
|
||||
}
|
||||
|
||||
async function enforceLayoutAndMainPane(ctx: ExecuteContext): Promise<void> {
|
||||
const sourcePaneId = ctx.sourcePaneId
|
||||
if (!sourcePaneId) {
|
||||
await enforceMainPane(ctx.windowState, ctx.config)
|
||||
return
|
||||
}
|
||||
|
||||
const latestState = await queryWindowState(sourcePaneId)
|
||||
if (!latestState?.mainPane) {
|
||||
await enforceMainPane(ctx.windowState, ctx.config)
|
||||
return
|
||||
}
|
||||
|
||||
const tmux = await getTmuxPath()
|
||||
if (tmux) {
|
||||
await applyLayout(tmux, ctx.config.layout, ctx.config.main_pane_size)
|
||||
}
|
||||
|
||||
await enforceMainPane(latestState, ctx.config)
|
||||
}
|
||||
|
||||
export async function executeAction(
|
||||
action: PaneAction,
|
||||
ctx: ExecuteContext
|
||||
): Promise<ActionResult> {
|
||||
return executeActionWithDeps(action, ctx, DEFAULT_DEPS)
|
||||
if (action.type === "close") {
|
||||
const success = await closeTmuxPane(action.paneId)
|
||||
if (success) {
|
||||
await enforceLayoutAndMainPane(ctx)
|
||||
}
|
||||
return { success }
|
||||
}
|
||||
|
||||
if (action.type === "replace") {
|
||||
const result = await replaceTmuxPane(
|
||||
action.paneId,
|
||||
action.newSessionId,
|
||||
action.description,
|
||||
ctx.config,
|
||||
ctx.serverUrl
|
||||
)
|
||||
if (result.success) {
|
||||
await enforceLayoutAndMainPane(ctx)
|
||||
}
|
||||
return {
|
||||
success: result.success,
|
||||
paneId: result.paneId,
|
||||
}
|
||||
}
|
||||
|
||||
const result = await spawnTmuxPane(
|
||||
action.sessionId,
|
||||
action.description,
|
||||
ctx.config,
|
||||
ctx.serverUrl,
|
||||
action.targetPaneId,
|
||||
action.splitDirection
|
||||
)
|
||||
|
||||
if (result.success) {
|
||||
await enforceLayoutAndMainPane(ctx)
|
||||
}
|
||||
|
||||
return {
|
||||
success: result.success,
|
||||
paneId: result.paneId,
|
||||
}
|
||||
}
|
||||
|
||||
export async function executeActions(
|
||||
|
||||
Reference in New Issue
Block a user