feat(multi-run): add a runs sheet with inline fusion

Replace the centered Multi-run dialog and the stacked Fusion dialog with one
right-side runs sheet, turn fusion into an inline selection mode, and
pre-approve each selected source workspace for the fusion session.

- Move MultiRunDialog into a SideDrawer with Runs / New run tabs; add
  MultiRunCard, FusionComposer and an optimistic starting fusion.
- Add buildFusionSourcePermissionRuleset (external_directory allow, edit deny)
  and thread permissions through SessionLauncher.launch.
- Apply the default permission mode to fusion sessions after launch.
- Let ModelCombobox and BranchCombobox take a listClassName; make SideDrawer
  ignore an Escape already handled by a nested layer.
This commit is contained in:
Chris Scott committed 2026-10-07 11:36:36 -04:00
1 parent b0361cd98b
commit f2e06abb62
23 files changed
+2122 -1736

No files matched your search

+112 -2
View File
@@ -4,10 +4,13 @@ import { createRepo, deleteRepo } from '../../src/db/queries'
import { migrate } from '../../src/db/migration-runner'
import { allMigrations } from '../../src/db/migrations'
import { createMultiRunWithEntries } from '../../src/db/multi-runs'
import { getSessionPermissionMode } from '../../src/db/session-permission-modes'
import { FusionContextLimitError } from '../../src/services/multi-run-fusion'
import { MultiRunError, MultiRunService } from '../../src/services/multi-runs'
import { RepoWorkspaceError } from '../../src/services/repo'
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
import { SessionPermissionModeService } from '../../src/services/session-permission-modes'
import { SettingsService } from '../../src/services/settings'
import type { Repo } from '../../src/types/repo'
import type { OpenCodeClient } from '../../src/services/opencode/client'
import { assistantMessage } from '../helpers/stub-schedule-api'
@@ -109,6 +112,9 @@ function createClient(sessions: Record<string, FakeSessionConfig> = {}): FakeMul
const sessionDiff = vi.fn(async () => [])
const permissionRequestList = vi.fn(async () => ({ data: [] }))
const permissionReply = vi.fn(async () => ({}))
const client = {
api: {
session: {
@@ -119,6 +125,10 @@ function createClient(sessions: Record<string, FakeSessionConfig> = {}): FakeMul
diff: sessionDiff,
},
message: { list: messageList },
permission: {
request: { list: permissionRequestList },
reply: permissionReply,
},
},
} as unknown as OpenCodeClient
@@ -198,8 +208,16 @@ describe('MultiRunService', () => {
return repo.id
}
function createService(client: OpenCodeClient, repoWorkspaces: RepoWorkspaceService): MultiRunService {
return new MultiRunService(db, client, repoWorkspaces)
function createService(
client: OpenCodeClient,
repoWorkspaces: RepoWorkspaceService,
permissionModes: SessionPermissionModeService = new SessionPermissionModeService(
db,
client,
new SettingsService(db),
),
): MultiRunService {
return new MultiRunService(db, client, repoWorkspaces, permissionModes)
}
it('launches one session per model, each in its own workspace named from the group', async () => {
@@ -641,6 +659,98 @@ describe('MultiRunService', () => {
).toEqual(before)
})
it('grants read access to the selected source workspaces and denies edits when fusing', async () => {
const repoId = readyRepo()
const { client, sessionCreate } = createClient()
const repoWorkspaces = createRepoWorkspaces()
const service = createService(client, repoWorkspaces.service)
const run = await service.launch({
repoId,
name: 'Sweep',
prompt: 'go',
models: ['openai/a', 'openai/b', 'openai/c'],
isolate: true,
})
const entryIds = run.entries.map((entry) => entry.id)
sessionCreate.mockClear()
await service.fuse(run.id, {
requestId: FUSE_REQUEST_ID,
entryIds: [entryIds[0]!, entryIds[2]!],
model: 'openai/d',
isolate: true,
})
expect(sessionCreate).toHaveBeenCalledTimes(1)
expect(sessionCreate.mock.calls[0]![0].permissions).toEqual([
{ action: 'external_directory', resource: '/worktrees/Sweep-1/*', effect: 'allow' },
{ action: 'edit', resource: '/worktrees/Sweep-1/*', effect: 'deny' },
{ action: 'external_directory', resource: '/worktrees/Sweep-3/*', effect: 'allow' },
{ action: 'edit', resource: '/worktrees/Sweep-3/*', effect: 'deny' },
])
const serializedPermissions = JSON.stringify(sessionCreate.mock.calls[0]![0].permissions)
expect(serializedPermissions).not.toContain('Sweep-2')
expect(serializedPermissions).not.toContain('Sweep-fusion-1')
})
it('stores the default auto mode on the fusion session', async () => {
const repoId = readyRepo()
const { client, sessionCreate } = createClient()
const repoWorkspaces = createRepoWorkspaces()
const settingsService = new SettingsService(db)
settingsService.updateSettings({ sessionDefaults: { permissionMode: 'auto' } })
const permissionModes = new SessionPermissionModeService(db, client, settingsService)
const service = createService(client, repoWorkspaces.service, permissionModes)
const run = await service.launch({
repoId,
name: 'Sweep',
prompt: 'go',
models: ['openai/a', 'openai/b'],
isolate: true,
})
const entryIds = run.entries.map((entry) => entry.id)
sessionCreate.mockClear()
const { run: fused } = await service.fuse(run.id, {
requestId: FUSE_REQUEST_ID,
entryIds,
model: 'openai/c',
isolate: false,
})
const fusionSessionId = fused.fusions[0]!.sessionId!
expect(getSessionPermissionMode(db, fusionSessionId)).toBe('auto')
})
it('stores no mode on the fusion session when the default is ask', async () => {
const repoId = readyRepo()
const { client, sessionCreate } = createClient()
const repoWorkspaces = createRepoWorkspaces()
const service = createService(client, repoWorkspaces.service)
const run = await service.launch({
repoId,
name: 'Sweep',
prompt: 'go',
models: ['openai/a', 'openai/b'],
isolate: true,
})
const entryIds = run.entries.map((entry) => entry.id)
sessionCreate.mockClear()
const { run: fused } = await service.fuse(run.id, {
requestId: FUSE_REQUEST_ID,
entryIds,
model: 'openai/c',
isolate: false,
})
const fusionSessionId = fused.fusions[0]!.sessionId!
expect(getSessionPermissionMode(db, fusionSessionId)).toBeNull()
})
it('returns the same fusion for a repeated requestId and launches once', async () => {
const repoId = readyRepo()
const { client, sessionCreate } = createClient()
@@ -122,6 +122,32 @@ describe('SessionLauncher', () => {
})
})
it('forwards a permission ruleset to session creation when provided', async () => {
const repoId = readyRepo()
const { client, create } = createClient()
const { service } = createRepoWorkspaces()
const launcher = new SessionLauncher(db, client, service)
const permissions = [
{ action: 'external_directory', resource: '/repos/source/*', effect: 'allow' as const },
{ action: 'edit', resource: '/repos/source/*', effect: 'deny' as const },
]
await launcher.launch({ repoId, prompt: 'hello', permissions })
expect(create).toHaveBeenCalledWith(expect.objectContaining({ permissions }))
})
it('omits the permissions key from session creation when none are given', async () => {
const repoId = readyRepo()
const { client, create } = createClient()
const { service } = createRepoWorkspaces()
const launcher = new SessionLauncher(db, client, service)
await launcher.launch({ repoId, prompt: 'hello' })
expect(create.mock.calls[0]![0]).not.toHaveProperty('permissions')
})
it('launches in a new workspace and prompts there', async () => {
const repoId = readyRepo()
const { client, create } = createClient()
@@ -177,6 +177,54 @@ describe('SessionPermissionModeService', () => {
expect(service.defaultMode()).toBe('auto')
})
it('stores the default auto mode for a launched session', async () => {
const settingsService = new SettingsService(db)
settingsService.updateSettings({ sessionDefaults: { permissionMode: 'auto' } })
const service = new SessionPermissionModeService(db, createFakeSessionPermissionClient(), settingsService)
await service.applyDefaultMode('ses_launched', DIRECTORY)
expect(getSessionPermissionMode(db, 'ses_launched')).toBe('auto')
})
it('stores no mode for a launched session when the default is ask', async () => {
const service = new SessionPermissionModeService(db, createFakeSessionPermissionClient(), new SettingsService(db))
await service.applyDefaultMode('ses_launched', DIRECTORY)
expect(getSessionPermissionMode(db, 'ses_launched')).toBeNull()
})
it('does not override an existing stored ask when applying the default auto mode', async () => {
const settingsService = new SettingsService(db)
settingsService.updateSettings({ sessionDefaults: { permissionMode: 'auto' } })
setSessionPermissionMode(db, 'ses_launched', 'ask')
const service = new SessionPermissionModeService(db, createFakeSessionPermissionClient(), settingsService)
await service.applyDefaultMode('ses_launched', DIRECTORY)
expect(getSessionPermissionMode(db, 'ses_launched')).toBe('ask')
})
it('accepts a pending request raised before the launched session mode was recorded', async () => {
const settingsService = new SettingsService(db)
settingsService.updateSettings({ sessionDefaults: { permissionMode: 'auto' } })
const client = createFakeSessionPermissionClient({
parents: { ses_launched: null },
pendingRequests: { [DIRECTORY]: [{ id: 'perm-launched', sessionID: 'ses_launched' }] },
})
const service = new SessionPermissionModeService(db, client, settingsService)
await service.applyDefaultMode('ses_launched', DIRECTORY)
expect(client.replyPermission).toHaveBeenCalledTimes(1)
expect(client.replyPermission).toHaveBeenCalledWith({
sessionID: 'ses_launched',
requestID: 'perm-launched',
decision: 'once',
})
})
it('auto-accepts a permission request for an auto root session', async () => {
setSessionPermissionMode(db, 'ses_root', 'auto')
const client = createFakeSessionPermissionClient({ parents: { ses_root: null } })