@@ -48,6 +48,7 @@ import type { SkillTool } from "@/tool/skill" |
48 | 48 | import { useKeyboard, useRenderer, useTerminalDimensions, type JSX } from "@opentui/solid" |
49 | 49 | import { useSDK } from "@tui/context/sdk" |
50 | 50 | import { useCommandDialog } from "@tui/component/dialog-command" |
| 51 | +import type { DialogContext } from "@tui/ui/dialog" |
51 | 52 | import { useKeybind } from "@tui/context/keybind" |
52 | 53 | import { Header } from "./header" |
53 | 54 | import { parsePatch } from "diff" |
@@ -226,6 +227,8 @@ export function Session() { |
226 | 227 | let scroll: ScrollBoxRenderable |
227 | 228 | let prompt: PromptRef |
228 | 229 | const keybind = useKeybind() |
| 230 | + const dialog = useDialog() |
| 231 | + const renderer = useRenderer() |
229 | 232 |
|
230 | 233 | // Allow exit when in child session (prompt is hidden) |
231 | 234 | const exit = useExit() |
@@ -312,19 +315,40 @@ export function Session() { |
312 | 315 |
|
313 | 316 | const local = useLocal() |
314 | 317 |
|
| 318 | + function moveFirstChild() { |
| 319 | + if (children().length === 1) return |
| 320 | + const next = children().find((x) => !!x.parentID) |
| 321 | + if (next) { |
| 322 | + navigate({ |
| 323 | + type: "session", |
| 324 | + sessionID: next.id, |
| 325 | + }) |
| 326 | + } |
| 327 | + } |
| 328 | + |
315 | 329 | function moveChild(direction: number) { |
316 | 330 | if (children().length === 1) return |
317 | | - let next = children().findIndex((x) => x.id === session()?.id) + direction |
318 | | - if (next >= children().length) next = 0 |
319 | | - if (next < 0) next = children().length - 1 |
320 | | - if (children()[next]) { |
| 331 | + |
| 332 | + const sessions = children().filter((x) => !!x.parentID) |
| 333 | + let next = sessions.findIndex((x) => x.id === session()?.id) + direction |
| 334 | + |
| 335 | + if (next >= sessions.length) next = 0 |
| 336 | + if (next < 0) next = sessions.length - 1 |
| 337 | + if (sessions[next]) { |
321 | 338 | navigate({ |
322 | 339 | type: "session", |
323 | | - sessionID: children()[next].id, |
| 340 | + sessionID: sessions[next].id, |
324 | 341 | }) |
325 | 342 | } |
326 | 343 | } |
327 | 344 |
|
| 345 | + function childSessionHandler(func: (dialog: DialogContext) => void) { |
| 346 | + return (dialog: DialogContext) => { |
| 347 | + if (!session()?.parentID || dialog.stack.length > 0) return |
| 348 | + func(dialog) |
| 349 | + } |
| 350 | + } |
| 351 | + |
328 | 352 | const command = useCommandDialog() |
329 | 353 | command.register(() => [ |
330 | 354 | { |
@@ -884,24 +908,13 @@ export function Session() { |
884 | 908 | }, |
885 | 909 | }, |
886 | 910 | { |
887 | | - title: "Next child session", |
888 | | - value: "session.child.next", |
889 | | - keybind: "session_child_cycle", |
890 | | - category: "Session", |
891 | | - hidden: true, |
892 | | - onSelect: (dialog) => { |
893 | | - moveChild(1) |
894 | | - dialog.clear() |
895 | | - }, |
896 | | - }, |
897 | | - { |
898 | | - title: "Previous child session", |
899 | | - value: "session.child.previous", |
900 | | - keybind: "session_child_cycle_reverse", |
| 911 | + title: "Go to child session", |
| 912 | + value: "session.child.first", |
| 913 | + keybind: "session_child_first", |
901 | 914 | category: "Session", |
902 | 915 | hidden: true, |
903 | 916 | onSelect: (dialog) => { |
904 | | - moveChild(-1) |
| 917 | + moveFirstChild() |
905 | 918 | dialog.clear() |
906 | 919 | }, |
907 | 920 | }, |
@@ -911,7 +924,7 @@ export function Session() { |
911 | 924 | keybind: "session_parent", |
912 | 925 | category: "Session", |
913 | 926 | hidden: true, |
914 | | - onSelect: (dialog) => { |
| 927 | + onSelect: childSessionHandler((dialog) => { |
915 | 928 | const parentID = session()?.parentID |
916 | 929 | if (parentID) { |
917 | 930 | navigate({ |
@@ -920,7 +933,29 @@ export function Session() { |
920 | 933 | }) |
921 | 934 | } |
922 | 935 | dialog.clear() |
923 | | - }, |
| 936 | + }), |
| 937 | + }, |
| 938 | + { |
| 939 | + title: "Next child session", |
| 940 | + value: "session.child.next", |
| 941 | + keybind: "session_child_cycle", |
| 942 | + category: "Session", |
| 943 | + hidden: true, |
| 944 | + onSelect: childSessionHandler((dialog) => { |
| 945 | + moveChild(1) |
| 946 | + dialog.clear() |
| 947 | + }), |
| 948 | + }, |
| 949 | + { |
| 950 | + title: "Previous child session", |
| 951 | + value: "session.child.previous", |
| 952 | + keybind: "session_child_cycle_reverse", |
| 953 | + category: "Session", |
| 954 | + hidden: true, |
| 955 | + onSelect: childSessionHandler((dialog) => { |
| 956 | + moveChild(-1) |
| 957 | + dialog.clear() |
| 958 | + }), |
924 | 959 | }, |
925 | 960 | ]) |
926 | 961 |
|
@@ -971,9 +1006,6 @@ export function Session() { |
971 | 1006 | } |
972 | 1007 | }) |
973 | 1008 |
|
974 | | - const dialog = useDialog() |
975 | | - const renderer = useRenderer() |
976 | | - |
977 | 1009 | // snap to bottom when session changes |
978 | 1010 | createEffect(on(() => route.sessionID, toBottom)) |
979 | 1011 |
|
@@ -1933,7 +1965,7 @@ function Task(props: ToolProps<typeof TaskTool>) { |
1933 | 1965 | </box> |
1934 | 1966 | <Show when={props.metadata.sessionId}> |
1935 | 1967 | <text fg={theme.text}> |
1936 | | - {keybind.print("session_child_cycle")} |
| 1968 | + {keybind.print("session_child_first")} |
1937 | 1969 | <span style={{ fg: theme.textMuted }}> view subagents</span> |
1938 | 1970 | </text> |
1939 | 1971 | </Show> |
|