diff --git a/ocm-cli/README.md b/ocm-cli/README.md index 244a9cc1..0f88ab20 100644 --- a/ocm-cli/README.md +++ b/ocm-cli/README.md @@ -168,8 +168,9 @@ attached Manager repo through `ocm`: optional base ref. `ctrl+s` launches, and the started sessions open in tabs. With no prompt, `/multirun` opens the runs browser for the attached repo: pick a run, open entry or fusion sessions, discard entries (`d` twice), select - results with `space`, and press `f` to fuse them with a synthesis model. A - fusion always runs in a new worktree. + results with `space`, and press `f` to fuse them with a synthesis model. On + the run list, `f` fuses every started result of the highlighted run. A fusion + always runs in a new worktree. Both commands need an OpenCode Manager release that exposes `/api/internal/session-goals` and `/api/internal/multi-runs`. An older Manager diff --git a/ocm-cli/src/tui-multi-run-dialogs.tsx b/ocm-cli/src/tui-multi-run-dialogs.tsx index d6252ca9..a55ecceb 100644 --- a/ocm-cli/src/tui-multi-run-dialogs.tsx +++ b/ocm-cli/src/tui-multi-run-dialogs.tsx @@ -281,6 +281,11 @@ function MultiRunsDialog(props: MultiRunsDialogProps & { context: Context }) { if ((name === 'return' || name === 'right') && current) { event.preventDefault() setPane('details') + return + } + if (name === 'f') { + event.preventDefault() + startFusion() } return } @@ -326,7 +331,7 @@ function MultiRunsDialog(props: MultiRunsDialogProps & { context: Context }) { const hints = createMemo(() => { if (pane() === 'fuse') return [['tab', 'next field'], ['enter', 'pick model'], ['ctrl+s', 'fuse'], ['ctrl+b', 'back']] as const - if (pane() === 'runs') return [['↑↓', 'select run'], ['enter', 'open run'], ['n', 'new multi-run'], ['r', 'refresh']] as const + if (pane() === 'runs') return [['↑↓', 'select run'], ['enter', 'open run'], ['f', 'fuse results'], ['n', 'new multi-run'], ['r', 'refresh']] as const return [ ['↑↓', 'move'], ['enter', 'open session'], diff --git a/ocm-cli/src/tui-multi-run.ts b/ocm-cli/src/tui-multi-run.ts index cef219be..4b099be5 100644 --- a/ocm-cli/src/tui-multi-run.ts +++ b/ocm-cli/src/tui-multi-run.ts @@ -141,12 +141,12 @@ export function canDiscard(entry: MultiRunEntry): boolean { return entry.status === 'started' || entry.status === 'failed' } -/** Toggles an entry in the fusion selection, ignoring non-source entries and selections past the model limit. */ +/** Toggles an entry in the fusion selection, keeping run order and ignoring non-sources and selections past the model limit. */ export function toggleFusionSource(run: MultiRun, selected: readonly number[], entryId: number): number[] { - if (selected.includes(entryId)) return selected.filter((id) => id !== entryId) - if (!startedEntries(run).some((entry) => entry.id === entryId)) return [...selected] - if (selected.length >= MULTI_RUN_MAX_MODELS) return [...selected] - return [...selected, entryId] + const sourceIds = startedEntries(run).map((entry) => entry.id) + if (selected.includes(entryId)) return sourceIds.filter((id) => id !== entryId && selected.includes(id)) + if (!sourceIds.includes(entryId) || selected.length >= MULTI_RUN_MAX_MODELS) return sourceIds.filter((id) => selected.includes(id)) + return sourceIds.filter((id) => id === entryId || selected.includes(id)) } export function parseLaunchForm(form: LaunchFormInput, repoId: number): ActionResult { diff --git a/ocm-cli/test/tui-multi-run.test.ts b/ocm-cli/test/tui-multi-run.test.ts index 6e5db33d..803503c6 100644 --- a/ocm-cli/test/tui-multi-run.test.ts +++ b/ocm-cli/test/tui-multi-run.test.ts @@ -298,6 +298,11 @@ describe('toggleFusionSource', () => { expect(toggleFusionSource(run, [1, 2], 1)).toEqual([2]) }) + it('keeps the selection in run order regardless of toggle order', () => { + expect(toggleFusionSource(run, [4], 1)).toEqual([1, 4]) + expect(toggleFusionSource(run, [5, 2], 4)).toEqual([2, 4, 5]) + }) + it('ignores entries that are not started and selections past the model limit', () => { expect(toggleFusionSource(run, [], 3)).toEqual([]) expect(toggleFusionSource(run, [1, 2, 4, 5, 6], 99)).toEqual([1, 2, 4, 5, 6])