mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
* feat(layout): add the dark layout.apply channel and route pane splits through main behind ORCA_LAYOUT_OWNER A build made with ORCA_LAYOUT_OWNER=main registers layout.apply: main applies the window's layout command to the stored partition through the shared applyLayoutCommand, minting new ids. A user split then waits for main's answer and mounts the pane id main minted. Every other build substitutes 'window', so neither branch is compiled in. * fix(layout): write only the records a layout.apply command touched A load-then-save rewrite also normalizes records the command never touched. The command's effect is now the diff between the save before and after it, written onto the stored partition record by record. A split whose main reply says a paired server holds the tab splits as today. * fix(layout): write a load-supplied record whole and check that patched partitions reload to the command's result * feat(layout): close, rename and equalize panes through main behind ORCA_LAYOUT_OWNER In a layout-owner build the window's pane close, title change and equalize go through layout.apply and the window shows main's answer. A window pane close keeps the legacy close's rules: the tab's last pane is refused, a pane restarted since main read the close is left alone, every partition holding the tab closes it, and the tab's remote session id follows the remaining pane. The rules sit behind a command field only layout.apply sets. * fix(layout): close the tab when a racing pane close leaves the window one pane * fix(layout): leave an unmounted tab alone when main refuses its last pane * feat(layout): move panes and save divider ratios through main behind ORCA_LAYOUT_OWNER Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125 * test(layout): a taken pane drop whose pane closed does nothing Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125 * test(layout): pin the window's pane move to main's saved tree, and the drops main cannot take Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125 * fix(layout): close a user's pane even if its terminal restarted, as today Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125 * test(layout): pin the restarted-pane close directly, not through a made-up profile state Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125 * fix(layout): leave a split to today's path only when the workspace's row names a paired server The split switch point asked which host to route to with a helper that falls back to the focused server, so a focused server could claim a workspace whose row names no owner. Use the same owner test the tab mirror uses. * test(layout): type the split owner mock without a cast * test(layout): type the layout-owner command mocks with the real signature * test(layout): type the gesture command mock with the real signature * fix(layout): close the dark path's gaps: unmounted split panes, refused or failed splits and moves, ratios during a move, release guard - A pane main saved but the window could not mount (source pane or manager gone during the await) is closed again in main, so it does not come back on restart. - A split main refuses because its copy lacks the workspace, tab or pane, or a failed call, splits as today; a refused or failed move moves as today. - Divider ratios committed while a move is in flight wait for the window's move, then go to main. - The orcad bundle gets the ORCA_LAYOUT_OWNER define when the switch is on. - Packaging and the orcad template refuse ORCA_LAYOUT_OWNER=main and any output a dark build marked. - workspace-layout-record-patch.ts: no non-null assertions; plain comment for the map depth. * test(layout): count a split pane as mounted from the split mock's own results * fix(layout): act as today whenever main lacks the target or the call throws, not just for splits - sendPaneCommandToLayoutOwner runs asToday for workspace/tab/pane_not_found and a thrown call, so close, rename and equalize fall back like split and move; a handler that throws no longer runs the fallback too. - A close main refuses as its last pane, while this window still has others, closes as today. - A move whose local step throws still releases held divider ratios. - Drop the orcad output marker: nothing read it; the template build refuses the switch itself. * test(layout): plain names for the last-pane fallback test and the marker comment * docs(layout): say plainly what an indeterminate write can leave behind * fix(layout): finish the main merge with this branch's versions of the layout-owner files * test(build): copy the layout-owner build guard into the compiler-cache checkout fixture * fix(layout): write a folded legacy row in its loaded form when a layout.apply command touches its claim A legacy terminal row the load folds into a tab-bar tab stays stored as is. Closing the tab it repeats, or giving it a tab-bar entry by moving it, let the next load resolve the claim the other way: the row came back or took the other tab's terminal. Such a command now writes the row as the load had it; every other record still stays as stored. * feat(layout): accept tab moves, group splits and group sizes on layout.apply Group sizes have no tab, so they go to the workspace's routed partition. * refactor(layout): move the window's layout.apply sender out of the terminal pane folder Tab groups send through it too; it now also acts as today when main lacks the group. * feat(layout): reorder, move and split tab groups, and save group sizes, through main behind ORCA_LAYOUT_OWNER A tab drop and Move Tab to Split wait for main's answer and then show main's placement, with main's new group id; group divider sizes are drawn while dragging and saved by main when the drag ends. Closing an empty group needs no command: main never holds an empty group. * fix(layout): review fixes for tab moves through main - Read a folded row's terminals with the loader's own claim rule, so rows sharing only an SSH session are covered too, and drop the row's remote session entry with it. - The record-patch test allows a folded row only in its loaded form. - A tab drag ends at once; main's answer shows the move after. - A lone group main moved whole is placed so only when this window's group is lone too. * refactor(layout): adopt only a folded row's pane layout beside its row A row's remote session entry is carried through load and save unchanged, so adopting it from the load changed nothing (the earlier commit's message overstated it). * feat(layout): record a window's terminal tab close through layout.apply closeTabs can now record each terminal tab it closes, or does not find, as closed for the given reason (pruned as a partition's records are), so a start that commits later is refused, as today's close records it. layout.apply takes one tab's close with the window's reason: main forces it in every holder partition, marks a user close's launches, stops no terminal (the window already did, sparing any another tab shares), and leaves a workspace it lacks to today's close. A sibling the load supplied that the close only renumbered is no longer written. * feat(layout): send the window's terminal tab close to main behind ORCA_LAYOUT_OWNER The window still closes the tab and stops its terminals itself; main records the close through layout.apply instead of the close intent, which stays for paired servers and when main lacks the workspace. * fix(layout): review fixes for the tab close through main - The window's close sends through a store-free sender, so the store no longer imports itself. - Main marks a user close's launches by the terminal's own id. - A recorded close prunes the whole partition's close records, as today, not one workspace's.
92 lines
3.9 KiB
TypeScript
92 lines
3.9 KiB
TypeScript
// Store-free so store slices can send; `layout-owner-command` reads the store for other callers.
|
|
import { getExplicitRuntimeEnvironmentIdForWorktree } from '@/lib/worktree-runtime-owner'
|
|
import { callRuntimeRpc } from '@/runtime/runtime-rpc-client'
|
|
import type { TabGroupLayoutNode } from '../../../shared/tab-types'
|
|
import type { TerminalPaneLayoutNode } from '../../../shared/terminal-tab-types'
|
|
import type { PaneSide } from '../../../shared/workspace-layout/terminal-pane-tree'
|
|
import type {
|
|
GroupSide,
|
|
LayoutApplyReply,
|
|
LayoutCommandResult,
|
|
LayoutRefusalCode
|
|
} from '../../../shared/workspace-layout/workspace-layout-command-types'
|
|
|
|
/** The commands a window sends `layout.apply`; main mints any new id. */
|
|
export type WindowLayoutCommand =
|
|
| { type: 'splitPane'; tabId: string; leafId: string; direction: 'vertical' | 'horizontal' }
|
|
| { type: 'closePane'; tabId: string; leafId: string }
|
|
| { type: 'renamePane'; tabId: string; leafId: string; title: string | null }
|
|
| { type: 'equalizePanes'; tabId: string }
|
|
| { type: 'movePane'; tabId: string; leafId: string; targetLeafId: string; side: PaneSide }
|
|
| { type: 'setPaneRatios'; tabId: string; root: TerminalPaneLayoutNode }
|
|
| { type: 'moveTab'; tabId: string; toGroupId: string; index: number }
|
|
| { type: 'splitGroup'; tabId: string; besideGroupId: string; direction: GroupSide }
|
|
| { type: 'setGroupRatios'; groupLayout: TabGroupLayoutNode }
|
|
| { type: 'closeTabs'; tabIds: [string]; recordClose: 'user' | 'cleanup' }
|
|
|
|
export type LayoutApplyHandlers = {
|
|
apply: (result: LayoutCommandResult) => void
|
|
asToday: () => void
|
|
refused?: (code: LayoutRefusalCode) => void
|
|
}
|
|
|
|
/**
|
|
* A layout command in a layout-owner build: main applies it first, then `apply` shows main's
|
|
* result. `asToday` runs instead when main cannot act on it: a paired server holds the tab
|
|
* (#18202), main's copy lacks the workspace, tab, pane or group, or the call threw. `refused` on
|
|
* any other refusal. False when a paired server owns the workspace's layout; the caller acts as
|
|
* today.
|
|
*/
|
|
export function sendLayoutApply(
|
|
state: Parameters<typeof getExplicitRuntimeEnvironmentIdForWorktree>[0],
|
|
worktreeId: string,
|
|
command: WindowLayoutCommand,
|
|
handlers: LayoutApplyHandlers
|
|
): boolean {
|
|
// Why: the same owner test that mirrors a workspace's tabs from a paired server; a focused
|
|
// server must not claim a workspace whose row names no owner.
|
|
if (getExplicitRuntimeEnvironmentIdForWorktree(state, worktreeId)) {
|
|
return false
|
|
}
|
|
void callRuntimeRpc<LayoutApplyReply>({ kind: 'local' }, 'layout.apply', {
|
|
command: { ...command, workspace: worktreeId }
|
|
})
|
|
.then(
|
|
(reply) => {
|
|
if (reply.ok) {
|
|
handlers.apply(reply.result)
|
|
} else if (reply.code === 'host_not_owned' || mainLacksTarget(reply.code)) {
|
|
// Why lacking: main's copy lags the window's here (the window still saves its own).
|
|
handlers.asToday()
|
|
} else {
|
|
console.warn(`[layout-owner] ${command.type} refused:`, reply.code)
|
|
handlers.refused?.(reply.code)
|
|
}
|
|
},
|
|
(error: unknown) => {
|
|
// Why as today: a thrown write is rolled back. An indeterminate disk write is not, and may
|
|
// leave a pane main minted; accepted until main is the only writer.
|
|
console.warn(`[layout-owner] ${command.type} failed:`, errorMessage(error))
|
|
handlers.asToday()
|
|
}
|
|
)
|
|
// A throwing handler is not a failed call; it must not run the fallback too.
|
|
.catch((error: unknown) => {
|
|
console.warn(`[layout-owner] ${command.type} handler threw:`, errorMessage(error))
|
|
})
|
|
return true
|
|
}
|
|
|
|
function mainLacksTarget(code: LayoutRefusalCode): boolean {
|
|
return (
|
|
code === 'workspace_not_found' ||
|
|
code === 'tab_not_found' ||
|
|
code === 'pane_not_found' ||
|
|
code === 'group_not_found'
|
|
)
|
|
}
|
|
|
|
function errorMessage(error: unknown): unknown {
|
|
return error instanceof Error ? error.message : error
|
|
}
|