mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
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:
1 parent
b0361cd98b
commit
f2e06abb62
23 files changed
+2122
-1736
No files matched your search
@@ -271,7 +271,7 @@ const sessionGoalService = new SessionGoalService(db, openCodeClient, sessionSet
|
||||
})
|
||||
sessionGoalService.loadOpenGoals()
|
||||
|
||||
const multiRunService = new MultiRunService(db, openCodeClient, repoWorkspaces)
|
||||
const multiRunService = new MultiRunService(db, openCodeClient, repoWorkspaces, sessionPermissionModeService)
|
||||
const changeWalkthroughService = new ChangeWalkthroughService(db, openCodeClient)
|
||||
|
||||
sseAggregator.onEvent((directory, event) => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { resolve } from 'node:path'
|
||||
import {
|
||||
isSessionNotFoundError,
|
||||
type FileDiffInfo,
|
||||
@@ -7,6 +8,7 @@ import {
|
||||
FUSION_PROMPT_MAX_LENGTH,
|
||||
type FusionUnavailableSource,
|
||||
type MultiRunFusionSource,
|
||||
type SchedulePermissionRuleset,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import type { MultiRunEntryRecord } from '../db/multi-runs'
|
||||
import { getErrorMessage } from '../utils/error-utils'
|
||||
@@ -42,6 +44,33 @@ const FUSION_REPLY_BUDGET_RATIO = 0.4
|
||||
|
||||
const FUSION_BLOCK_SEPARATOR = '\n\n'
|
||||
|
||||
/**
|
||||
* Builds the OpenCode session permission ruleset that lets a fusion session read
|
||||
* its selected source workspaces while denying any edit to them.
|
||||
*
|
||||
* Each unique directory is normalized with `resolve` before a pair of rules is
|
||||
* emitted: an `external_directory` allow so the session may read outside its own
|
||||
* workspace, followed by an `edit` deny so the read-only reference cannot be
|
||||
* mutated. Deduplication happens after normalization.
|
||||
*/
|
||||
export function buildFusionSourcePermissionRuleset(directories: string[]): SchedulePermissionRuleset {
|
||||
const seen = new Set<string>()
|
||||
const ruleset: SchedulePermissionRuleset = []
|
||||
|
||||
for (const directory of directories) {
|
||||
const normalized = resolve(directory).replaceAll('\\', '/')
|
||||
if (seen.has(normalized)) {
|
||||
continue
|
||||
}
|
||||
|
||||
seen.add(normalized)
|
||||
ruleset.push({ action: 'external_directory', resource: `${normalized}/*`, effect: 'allow' })
|
||||
ruleset.push({ action: 'edit', resource: `${normalized}/*`, effect: 'deny' })
|
||||
}
|
||||
|
||||
return ruleset
|
||||
}
|
||||
|
||||
export class FusionContextLimitError extends ServiceError {
|
||||
constructor(requiredPerSource: number, availablePerSource: number) {
|
||||
super(
|
||||
|
||||
@@ -19,11 +19,12 @@ import { getRepoById } from '../db/queries'
|
||||
import type { Repo } from '../types/repo'
|
||||
import { getErrorMessage } from '../utils/error-utils'
|
||||
import { ServiceError } from '../utils/service-error'
|
||||
import { buildFusionPrompt, collectFusionSources } from './multi-run-fusion'
|
||||
import { buildFusionPrompt, buildFusionSourcePermissionRuleset, collectFusionSources } from './multi-run-fusion'
|
||||
import type { OpenCodeClient } from './opencode/client'
|
||||
import { RepoWorkspaceError } from './repo'
|
||||
import type { RepoWorkspaceService } from './repo-workspace'
|
||||
import { requireReadyRepo, SessionLauncher, SessionLaunchError, type LaunchedSession } from './session-launcher'
|
||||
import type { SessionPermissionModeService } from './session-permission-modes'
|
||||
|
||||
const MULTI_RUN_LIST_LIMIT = 20
|
||||
|
||||
@@ -75,6 +76,7 @@ export class MultiRunService {
|
||||
private readonly db: Database,
|
||||
private readonly openCodeClient: OpenCodeClient,
|
||||
private readonly repoWorkspaces: RepoWorkspaceService,
|
||||
private readonly permissionModes: SessionPermissionModeService,
|
||||
) {
|
||||
this.sessionLauncher = new SessionLauncher(db, openCodeClient, repoWorkspaces)
|
||||
}
|
||||
@@ -194,6 +196,12 @@ export class MultiRunService {
|
||||
}
|
||||
}
|
||||
|
||||
const sourcePermissions = buildFusionSourcePermissionRuleset(
|
||||
selectedEntries
|
||||
.map((entry) => entry.directory)
|
||||
.filter((directory): directory is string => directory !== null),
|
||||
)
|
||||
|
||||
try {
|
||||
await this.sessionLauncher.resolveModel(repo, request.model)
|
||||
} catch (error) {
|
||||
@@ -241,6 +249,7 @@ export class MultiRunService {
|
||||
model: request.model,
|
||||
title: `${record.name} · fusion`,
|
||||
...(request.agent ? { agent: request.agent } : {}),
|
||||
...(sourcePermissions.length > 0 ? { permissions: sourcePermissions } : {}),
|
||||
...(request.isolate
|
||||
? {
|
||||
workspace: {
|
||||
@@ -256,6 +265,8 @@ export class MultiRunService {
|
||||
sessionId: launched.sessionId,
|
||||
directory: launched.directory,
|
||||
})
|
||||
|
||||
await this.permissionModes.applyDefaultMode(launched.sessionId, launched.directory)
|
||||
} catch (error) {
|
||||
const launchError = error instanceof SessionLaunchError ? error : null
|
||||
const workspaceDirectory = launchError?.workspaceDirectory ?? null
|
||||
|
||||
@@ -8,6 +8,8 @@ import type { OpenCodeClient } from './opencode/client'
|
||||
import { resolveOpenCodeModel, type ResolvedOpenCodeModel } from './opencode-models'
|
||||
import type { RepoWorkspaceService } from './repo-workspace'
|
||||
|
||||
type SessionCreateInput = NonNullable<Parameters<OpenCodeClient['api']['session']['create']>[0]>
|
||||
|
||||
interface LaunchSessionInput {
|
||||
repoId: number
|
||||
prompt: string
|
||||
@@ -15,6 +17,7 @@ interface LaunchSessionInput {
|
||||
model?: string
|
||||
agent?: string
|
||||
workspace?: { name?: string; ref?: string }
|
||||
permissions?: SessionCreateInput['permissions']
|
||||
}
|
||||
|
||||
export interface LaunchedSession {
|
||||
@@ -109,6 +112,7 @@ export class SessionLauncher {
|
||||
session = await this.openCodeClient.api.session.create({
|
||||
...(input.title ? { title: input.title } : {}),
|
||||
...(input.agent ? { agent: input.agent } : {}),
|
||||
...(input.permissions ? { permissions: input.permissions } : {}),
|
||||
model: {
|
||||
providerID: model.providerID,
|
||||
id: model.id,
|
||||
|
||||
@@ -126,6 +126,21 @@ export class SessionPermissionModeService {
|
||||
return this.settingsService.getSettings().preferences.sessionDefaults?.permissionMode ?? 'ask'
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the default permission mode for a session after it has been launched
|
||||
* and accepts any permission requests it raised before the mode was stored.
|
||||
*
|
||||
* Does nothing when the default mode is `ask`, since that needs no stored row.
|
||||
*/
|
||||
async applyDefaultMode(sessionId: string, directory: string): Promise<void> {
|
||||
if (this.defaultMode() !== 'auto') {
|
||||
return
|
||||
}
|
||||
|
||||
insertSessionPermissionModeIfAbsent(this.db, sessionId, 'auto')
|
||||
await this.acceptPendingRequestsInDirectory(directory, sessionId)
|
||||
}
|
||||
|
||||
async acceptPendingRequestsForActiveSessions(): Promise<void> {
|
||||
try {
|
||||
const active = await this.openCodeClient.api.session.active()
|
||||
|
||||
Reference in new issue
Block a user