mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 2: Phase 2: Session permission mode storage, resolution and API
This commit is contained in:
1 parent
a3aaba8515
commit
66e6c20f8e
13 files changed
+489
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import type { Migration } from '../migration-runner'
|
||||
import { ensureSessionPermissionModesTable } from '../session-permission-modes'
|
||||
|
||||
const migration: Migration = {
|
||||
version: 25,
|
||||
name: 'session-permission-modes',
|
||||
up(db) {
|
||||
ensureSessionPermissionModesTable(db)
|
||||
},
|
||||
down(db) {
|
||||
db.run('DROP TABLE IF EXISTS session_permission_modes')
|
||||
},
|
||||
}
|
||||
|
||||
export default migration
|
||||
@@ -23,6 +23,7 @@ import migration021 from './021-drop-schedule-run-workspace-id'
|
||||
import migration022 from './022-schedule-runs-session-index'
|
||||
import migration023 from './023-schedule-mcp-servers'
|
||||
import migration024 from './024-schedule-runs-viewed-at'
|
||||
import migration025 from './025-session-permission-modes'
|
||||
|
||||
export const allMigrations: Migration[] = [
|
||||
migration001,
|
||||
@@ -49,4 +50,5 @@ export const allMigrations: Migration[] = [
|
||||
migration022,
|
||||
migration023,
|
||||
migration024,
|
||||
migration025,
|
||||
]
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { Database } from 'bun:sqlite'
|
||||
import type { SessionPermissionMode } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export function ensureSessionPermissionModesTable(db: Database): void {
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS session_permission_modes (
|
||||
session_id TEXT PRIMARY KEY,
|
||||
mode TEXT NOT NULL CHECK(mode IN ('ask','auto')),
|
||||
updated_at INTEGER NOT NULL
|
||||
)
|
||||
`)
|
||||
}
|
||||
|
||||
export function getSessionPermissionMode(db: Database, sessionId: string): SessionPermissionMode | null {
|
||||
const row = db
|
||||
.prepare('SELECT mode FROM session_permission_modes WHERE session_id = ?')
|
||||
.get(sessionId) as { mode: SessionPermissionMode } | undefined
|
||||
return row ? row.mode : null
|
||||
}
|
||||
|
||||
export function setSessionPermissionMode(db: Database, sessionId: string, mode: SessionPermissionMode): void {
|
||||
db.prepare(`
|
||||
INSERT INTO session_permission_modes(session_id, mode, updated_at)
|
||||
VALUES(?,?,?)
|
||||
ON CONFLICT(session_id) DO UPDATE SET mode=excluded.mode, updated_at=excluded.updated_at
|
||||
`).run(sessionId, mode, Date.now())
|
||||
}
|
||||
|
||||
export function insertSessionPermissionModeIfAbsent(db: Database, sessionId: string, mode: SessionPermissionMode): void {
|
||||
db.prepare(`
|
||||
INSERT OR IGNORE INTO session_permission_modes(session_id, mode, updated_at)
|
||||
VALUES(?,?,?)
|
||||
`).run(sessionId, mode, Date.now())
|
||||
}
|
||||
|
||||
export function deleteSessionPermissionMode(db: Database, sessionId: string): void {
|
||||
db.prepare('DELETE FROM session_permission_modes WHERE session_id = ?').run(sessionId)
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import { createAuth } from './auth'
|
||||
import { createAuthMiddleware } from './auth/middleware'
|
||||
import { createPromptTemplateRoutes } from './routes/prompt-templates'
|
||||
import { createSessionPinRoutes } from './routes/session-pins'
|
||||
import { createSessionPermissionModeRoutes } from './routes/session-permission-modes'
|
||||
import { createLogRoutes } from './routes/logs'
|
||||
import { createInternalRoutes } from './routes/internal'
|
||||
import { sweepStaleUploadSessions } from './routes/internal/repo-mirror-helpers'
|
||||
@@ -44,6 +45,7 @@ import { createAuthenticatedOpenCodeProxyRoutes } from './routes/opencode-auth-p
|
||||
import { sseAggregator } from './services/sse-aggregator'
|
||||
import { ensureDirectoryExists, writeFileContent, fileExists } from './services/file-operations'
|
||||
import { SettingsService } from './services/settings'
|
||||
import { SessionPermissionModeService } from './services/session-permission-modes'
|
||||
import { opencodeServerManager } from './services/opencode-single-server'
|
||||
import { createOpenCodeClient } from './services/opencode/client'
|
||||
import { NotificationService } from './services/notification'
|
||||
@@ -227,6 +229,7 @@ const scheduleService = new ScheduleService(db, openCodeClient, scheduleWorktree
|
||||
const scheduleRunnerInstance = new ScheduleRunner(scheduleService)
|
||||
|
||||
const notificationService = new NotificationService(db)
|
||||
const sessionPermissionModeService = new SessionPermissionModeService(db, openCodeClient, settingsServiceForSchedules)
|
||||
|
||||
if (ENV.VAPID.PUBLIC_KEY && ENV.VAPID.PRIVATE_KEY) {
|
||||
if (!ENV.VAPID.SUBJECT) {
|
||||
@@ -283,6 +286,7 @@ protectedApi.route('/ssh', createSSHRoutes(gitAuthService))
|
||||
protectedApi.route('/notifications', createNotificationRoutes(notificationService))
|
||||
protectedApi.route('/prompt-templates', createPromptTemplateRoutes(db))
|
||||
protectedApi.route('/session-pins', createSessionPinRoutes(db))
|
||||
protectedApi.route('/session-permission-modes', createSessionPermissionModeRoutes(sessionPermissionModeService))
|
||||
protectedApi.route('/schedules', createScheduleRoutes(scheduleService))
|
||||
protectedApi.route('/logs', createLogRoutes())
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Hono } from 'hono'
|
||||
import { SetSessionPermissionModeRequestSchema } from '@opencode-manager/shared/schemas'
|
||||
import { SessionPermissionModeError, type SessionPermissionModeService } from '../services/session-permission-modes'
|
||||
import { handleServiceError } from '../utils/route-helpers'
|
||||
|
||||
export function createSessionPermissionModeRoutes(service: SessionPermissionModeService) {
|
||||
const app = new Hono()
|
||||
|
||||
app.get('/:sessionId', async (c) => {
|
||||
try {
|
||||
const state = await service.getEffectiveMode(c.req.param('sessionId'))
|
||||
return c.json(state)
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to read session permission mode', SessionPermissionModeError)
|
||||
}
|
||||
})
|
||||
|
||||
app.put('/:sessionId', async (c) => {
|
||||
let body: unknown
|
||||
try {
|
||||
body = await c.req.json()
|
||||
} catch {
|
||||
return c.json({ error: 'Invalid request' }, 400)
|
||||
}
|
||||
|
||||
const parsed = SetSessionPermissionModeRequestSchema.safeParse(body)
|
||||
if (!parsed.success) {
|
||||
return c.json({ error: 'Invalid request' }, 400)
|
||||
}
|
||||
|
||||
try {
|
||||
const state = await service.setMode(c.req.param('sessionId'), parsed.data.mode, parsed.data.directory)
|
||||
return c.json(state)
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to set session permission mode', SessionPermissionModeError)
|
||||
}
|
||||
})
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import type { Database } from 'bun:sqlite'
|
||||
import type {
|
||||
SessionPermissionMode,
|
||||
SessionPermissionModeState,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import { getScheduleRunBySessionId } from '../db/schedules'
|
||||
import { getSessionPermissionMode, setSessionPermissionMode } from '../db/session-permission-modes'
|
||||
import type { OpenCodeClient } from './opencode/client'
|
||||
import type { SettingsService } from './settings'
|
||||
|
||||
const MAX_PARENT_HOPS = 10
|
||||
|
||||
export class SessionPermissionModeError extends Error {
|
||||
status: number
|
||||
|
||||
constructor(message: string, status: number) {
|
||||
super(message)
|
||||
this.status = status
|
||||
}
|
||||
}
|
||||
|
||||
export class SessionPermissionModeService {
|
||||
private readonly parentBySession = new Map<string, string | null>()
|
||||
|
||||
constructor(
|
||||
private readonly db: Database,
|
||||
private readonly openCodeClient: OpenCodeClient,
|
||||
private readonly settingsService: SettingsService,
|
||||
) {}
|
||||
|
||||
rememberParent(sessionId: string, parentId: string | null | undefined): void {
|
||||
this.parentBySession.set(sessionId, parentId ?? null)
|
||||
}
|
||||
|
||||
async resolveRootSessionId(sessionId: string): Promise<string> {
|
||||
let current = sessionId
|
||||
|
||||
for (let hops = 0; hops < MAX_PARENT_HOPS; hops += 1) {
|
||||
const parentId = await this.getParentId(current)
|
||||
if (!parentId) {
|
||||
return current
|
||||
}
|
||||
current = parentId
|
||||
}
|
||||
|
||||
return current
|
||||
}
|
||||
|
||||
async getEffectiveMode(sessionId: string): Promise<SessionPermissionModeState> {
|
||||
let rootSessionId: string
|
||||
|
||||
try {
|
||||
rootSessionId = await this.resolveRootSessionId(sessionId)
|
||||
} catch {
|
||||
return { sessionId, rootSessionId: sessionId, mode: 'ask', inherited: false }
|
||||
}
|
||||
|
||||
const inherited = rootSessionId !== sessionId
|
||||
|
||||
if (getScheduleRunBySessionId(this.db, rootSessionId)) {
|
||||
return { sessionId, rootSessionId, mode: 'ask', inherited }
|
||||
}
|
||||
|
||||
const stored = getSessionPermissionMode(this.db, rootSessionId)
|
||||
return { sessionId, rootSessionId, mode: stored ?? 'ask', inherited }
|
||||
}
|
||||
|
||||
async setMode(sessionId: string, mode: SessionPermissionMode, directory: string): Promise<SessionPermissionModeState> {
|
||||
void directory
|
||||
|
||||
const rootSessionId = await this.resolveRootSessionId(sessionId)
|
||||
if (rootSessionId !== sessionId) {
|
||||
throw new SessionPermissionModeError(
|
||||
'Child sessions inherit the permission mode of their parent session',
|
||||
400,
|
||||
)
|
||||
}
|
||||
|
||||
if (getScheduleRunBySessionId(this.db, rootSessionId)) {
|
||||
throw new SessionPermissionModeError(
|
||||
'Scheduled runs use their own permission configuration',
|
||||
409,
|
||||
)
|
||||
}
|
||||
|
||||
setSessionPermissionMode(this.db, sessionId, mode)
|
||||
return { sessionId, rootSessionId, mode, inherited: false }
|
||||
}
|
||||
|
||||
defaultMode(): SessionPermissionMode {
|
||||
return this.settingsService.getSettings().preferences.sessionDefaults?.permissionMode ?? 'ask'
|
||||
}
|
||||
|
||||
private async getParentId(sessionId: string): Promise<string | null> {
|
||||
if (this.parentBySession.has(sessionId)) {
|
||||
return this.parentBySession.get(sessionId) ?? null
|
||||
}
|
||||
|
||||
const session = await this.openCodeClient.api.session.get({ sessionID: sessionId })
|
||||
const parentId = session.parentID ?? null
|
||||
this.parentBySession.set(sessionId, parentId)
|
||||
return parentId
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { OpenCodeClient } from '../../src/services/opencode/client'
|
||||
|
||||
export interface FakeSessionPermissionClientOptions {
|
||||
parents?: Record<string, string | null>
|
||||
failSessionGet?: boolean
|
||||
}
|
||||
|
||||
export function createFakeSessionPermissionClient(
|
||||
options: FakeSessionPermissionClientOptions = {},
|
||||
): OpenCodeClient {
|
||||
const parents = options.parents ?? {}
|
||||
|
||||
return {
|
||||
api: {
|
||||
session: {
|
||||
get: async ({ sessionID }: { sessionID: string }) => {
|
||||
if (options.failSessionGet) {
|
||||
throw new Error('upstream unavailable')
|
||||
}
|
||||
return { parentID: parents[sessionID] ?? undefined }
|
||||
},
|
||||
},
|
||||
},
|
||||
forwardRaw: async () => new Response(),
|
||||
} as unknown as OpenCodeClient
|
||||
}
|
||||
@@ -153,6 +153,18 @@ describe('internal/settings routes', () => {
|
||||
expect(res.status).toBe(400)
|
||||
})
|
||||
|
||||
it('PATCH /api/internal/settings with { sessionDefaults: { permissionMode: "auto" } } returns 400 (strict reject)', async () => {
|
||||
const res = await app.request('/api/internal/settings', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ sessionDefaults: { permissionMode: 'auto' } }),
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
expect(res.status).toBe(400)
|
||||
})
|
||||
|
||||
it('PATCH /api/internal/settings with { theme: "rainbow" } returns 400 (enum reject)', async () => {
|
||||
const res = await app.request('/api/internal/settings', {
|
||||
method: 'PATCH',
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { Hono } from 'hono'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { migrate } from '../../src/db/migration-runner'
|
||||
import { allMigrations } from '../../src/db/migrations'
|
||||
import { SettingsService } from '../../src/services/settings'
|
||||
import { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import { createSessionPermissionModeRoutes } from '../../src/routes/session-permission-modes'
|
||||
import { createFakeSessionPermissionClient } from '../helpers/fake-session-permission-client'
|
||||
|
||||
function createTestApp(db: Database, parents: Record<string, string | null> = {}): Hono {
|
||||
const app = new Hono()
|
||||
const service = new SessionPermissionModeService(db, createFakeSessionPermissionClient({ parents }), new SettingsService(db))
|
||||
app.route('/session-permission-modes', createSessionPermissionModeRoutes(service))
|
||||
return app
|
||||
}
|
||||
|
||||
function createTestDb(): Database {
|
||||
const db = new Database(':memory:')
|
||||
migrate(db, allMigrations)
|
||||
return db
|
||||
}
|
||||
|
||||
describe('session permission mode routes', () => {
|
||||
let db: Database
|
||||
|
||||
beforeEach(() => {
|
||||
db = createTestDb()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
db.close()
|
||||
})
|
||||
|
||||
it('GET returns ask for a session with no stored mode', async () => {
|
||||
const app = createTestApp(db)
|
||||
|
||||
const res = await app.request('/session-permission-modes/ses_root')
|
||||
expect(res.status).toBe(200)
|
||||
await expect(res.json()).resolves.toEqual({
|
||||
sessionId: 'ses_root',
|
||||
rootSessionId: 'ses_root',
|
||||
mode: 'ask',
|
||||
inherited: false,
|
||||
})
|
||||
})
|
||||
|
||||
it('PUT stores a mode and GET reads it back', async () => {
|
||||
const app = createTestApp(db)
|
||||
|
||||
const putRes = await app.request('/session-permission-modes/ses_root', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ directory: '/abs/repo', mode: 'auto' }),
|
||||
})
|
||||
expect(putRes.status).toBe(200)
|
||||
await expect(putRes.json()).resolves.toEqual({
|
||||
sessionId: 'ses_root',
|
||||
rootSessionId: 'ses_root',
|
||||
mode: 'auto',
|
||||
inherited: false,
|
||||
})
|
||||
|
||||
const getRes = await app.request('/session-permission-modes/ses_root')
|
||||
const body = await getRes.json() as { mode: string }
|
||||
expect(body.mode).toBe('auto')
|
||||
})
|
||||
|
||||
it('PUT rejects an invalid mode with 400', async () => {
|
||||
const app = createTestApp(db)
|
||||
|
||||
const res = await app.request('/session-permission-modes/ses_root', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ directory: '/abs/repo', mode: 'always' }),
|
||||
})
|
||||
expect(res.status).toBe(400)
|
||||
})
|
||||
|
||||
it('PUT rejects malformed JSON with 400', async () => {
|
||||
const app = createTestApp(db)
|
||||
|
||||
const res = await app.request('/session-permission-modes/ses_root', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: '{not json',
|
||||
})
|
||||
expect(res.status).toBe(400)
|
||||
})
|
||||
|
||||
it('PUT rejects setting the mode of a child session with 400', async () => {
|
||||
const app = createTestApp(db, { ses_child: 'ses_root', ses_root: null })
|
||||
|
||||
const res = await app.request('/session-permission-modes/ses_child', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ directory: '/abs/repo', mode: 'auto' }),
|
||||
})
|
||||
expect(res.status).toBe(400)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,112 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { migrate } from '../../src/db/migration-runner'
|
||||
import { allMigrations } from '../../src/db/migrations'
|
||||
import { createRepo } from '../../src/db/queries'
|
||||
import { createScheduleRun, updateScheduleRunMetadata } from '../../src/db/schedules'
|
||||
import { getSessionPermissionMode, setSessionPermissionMode } from '../../src/db/session-permission-modes'
|
||||
import { SettingsService } from '../../src/services/settings'
|
||||
import { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import { createFakeSessionPermissionClient } from '../helpers/fake-session-permission-client'
|
||||
|
||||
function createTestDb(): Database {
|
||||
const db = new Database(':memory:')
|
||||
migrate(db, allMigrations)
|
||||
return db
|
||||
}
|
||||
|
||||
describe('SessionPermissionModeService', () => {
|
||||
let db: Database
|
||||
|
||||
beforeEach(() => {
|
||||
db = createTestDb()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
db.close()
|
||||
})
|
||||
|
||||
it('treats a root session with no stored row as ask', async () => {
|
||||
const service = new SessionPermissionModeService(db, createFakeSessionPermissionClient(), new SettingsService(db))
|
||||
|
||||
await expect(service.getEffectiveMode('ses_root')).resolves.toEqual({
|
||||
sessionId: 'ses_root',
|
||||
rootSessionId: 'ses_root',
|
||||
mode: 'ask',
|
||||
inherited: false,
|
||||
})
|
||||
})
|
||||
|
||||
it('applies a stored auto root mode to its child and marks it inherited', async () => {
|
||||
setSessionPermissionMode(db, 'ses_root', 'auto')
|
||||
const client = createFakeSessionPermissionClient({ parents: { ses_child: 'ses_root', ses_root: null } })
|
||||
const service = new SessionPermissionModeService(db, client, new SettingsService(db))
|
||||
|
||||
await expect(service.getEffectiveMode('ses_child')).resolves.toEqual({
|
||||
sessionId: 'ses_child',
|
||||
rootSessionId: 'ses_root',
|
||||
mode: 'auto',
|
||||
inherited: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('always reports ask for a schedule-run session even when a mode is stored', async () => {
|
||||
createRepo(db, {
|
||||
localPath: 'repo-one',
|
||||
sourcePath: '/abs/repo',
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: Date.now(),
|
||||
isLocal: true,
|
||||
})
|
||||
const run = createScheduleRun(db, {
|
||||
jobId: 1,
|
||||
repoId: 1,
|
||||
triggerSource: 'schedule',
|
||||
status: 'running',
|
||||
startedAt: Date.now(),
|
||||
createdAt: Date.now(),
|
||||
})
|
||||
updateScheduleRunMetadata(db, 1, 1, run.id, { sessionId: 'ses_scheduled' })
|
||||
setSessionPermissionMode(db, 'ses_scheduled', 'auto')
|
||||
|
||||
const service = new SessionPermissionModeService(db, createFakeSessionPermissionClient(), new SettingsService(db))
|
||||
|
||||
await expect(service.getEffectiveMode('ses_scheduled')).resolves.toEqual({
|
||||
sessionId: 'ses_scheduled',
|
||||
rootSessionId: 'ses_scheduled',
|
||||
mode: 'ask',
|
||||
inherited: false,
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects setMode for a child session', async () => {
|
||||
const client = createFakeSessionPermissionClient({ parents: { ses_child: 'ses_root', ses_root: null } })
|
||||
const service = new SessionPermissionModeService(db, client, new SettingsService(db))
|
||||
|
||||
await expect(service.setMode('ses_child', 'auto', '/abs/repo')).rejects.toMatchObject({ status: 400 })
|
||||
expect(getSessionPermissionMode(db, 'ses_child')).toBeNull()
|
||||
expect(getSessionPermissionMode(db, 'ses_root')).toBeNull()
|
||||
})
|
||||
|
||||
it('fails closed to ask when parent resolution fails', async () => {
|
||||
const service = new SessionPermissionModeService(db, createFakeSessionPermissionClient({ failSessionGet: true }), new SettingsService(db))
|
||||
|
||||
await expect(service.getEffectiveMode('ses_root')).resolves.toEqual({
|
||||
sessionId: 'ses_root',
|
||||
rootSessionId: 'ses_root',
|
||||
mode: 'ask',
|
||||
inherited: false,
|
||||
})
|
||||
})
|
||||
|
||||
it('reads the default mode from session settings', () => {
|
||||
const settingsService = new SettingsService(db)
|
||||
const service = new SessionPermissionModeService(db, createFakeSessionPermissionClient(), settingsService)
|
||||
|
||||
expect(service.defaultMode()).toBe('ask')
|
||||
|
||||
settingsService.updateSettings({ sessionDefaults: { permissionMode: 'auto' } })
|
||||
expect(service.defaultMode()).toBe('auto')
|
||||
})
|
||||
})
|
||||
@@ -11,4 +11,5 @@ export * from './schedule'
|
||||
export * from './skills'
|
||||
export * from './internal-assistant'
|
||||
export * from './session-pins'
|
||||
export * from './session-permissions'
|
||||
export * from './logs'
|
||||
@@ -0,0 +1,21 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const SessionPermissionModeSchema = z.enum(["ask", "auto"]);
|
||||
|
||||
export type SessionPermissionMode = z.infer<typeof SessionPermissionModeSchema>;
|
||||
|
||||
export const SetSessionPermissionModeRequestSchema = z.object({
|
||||
directory: z.string().min(1),
|
||||
mode: SessionPermissionModeSchema,
|
||||
});
|
||||
|
||||
export type SetSessionPermissionModeRequest = z.infer<typeof SetSessionPermissionModeRequestSchema>;
|
||||
|
||||
export const SessionPermissionModeStateSchema = z.object({
|
||||
sessionId: z.string(),
|
||||
rootSessionId: z.string(),
|
||||
mode: SessionPermissionModeSchema,
|
||||
inherited: z.boolean(),
|
||||
});
|
||||
|
||||
export type SessionPermissionModeState = z.infer<typeof SessionPermissionModeStateSchema>;
|
||||
@@ -2,6 +2,7 @@ import { z } from "zod";
|
||||
import { NotificationPreferencesSchema, DEFAULT_NOTIFICATION_PREFERENCES } from "./notifications";
|
||||
import { OPENCODE_CONFIG_SOURCE_NAMES } from "../config/defaults";
|
||||
import { ColorThemeIdSchema, MANAGER_COLOR_THEME_ID } from "../themes";
|
||||
import { SessionPermissionModeSchema } from "./session-permissions";
|
||||
|
||||
export const CustomCommandSchema = z.object({
|
||||
name: z.string(),
|
||||
@@ -142,6 +143,16 @@ export const DEFAULT_SANDBOX_PREFERENCES: SandboxPreferences = {
|
||||
gitCredentials: false,
|
||||
};
|
||||
|
||||
export const SessionDefaultsSchema = z.object({
|
||||
permissionMode: SessionPermissionModeSchema,
|
||||
});
|
||||
|
||||
export type SessionDefaults = z.infer<typeof SessionDefaultsSchema>;
|
||||
|
||||
export const DEFAULT_SESSION_DEFAULTS: SessionDefaults = {
|
||||
permissionMode: 'ask',
|
||||
};
|
||||
|
||||
export const UserPreferencesSchema = z.object({
|
||||
theme: z.enum(["dark", "light", "system"]),
|
||||
colorTheme: ColorThemeIdSchema.optional(),
|
||||
@@ -168,6 +179,7 @@ export const UserPreferencesSchema = z.object({
|
||||
repoSortMode: z.enum(['recent', 'manual', 'name']).optional(),
|
||||
serverEnvVars: z.array(ServerEnvVarSchema).optional(),
|
||||
sandbox: SandboxPreferencesSchema.optional(),
|
||||
sessionDefaults: SessionDefaultsSchema.optional(),
|
||||
disabledDefaultServerEnvVars: z.array(z.string()).optional(),
|
||||
});
|
||||
|
||||
@@ -220,6 +232,7 @@ export const DEFAULT_USER_PREFERENCES = {
|
||||
repoSortMode: 'recent' as const,
|
||||
serverEnvVars: [] as ServerEnvVar[],
|
||||
sandbox: DEFAULT_SANDBOX_PREFERENCES,
|
||||
sessionDefaults: DEFAULT_SESSION_DEFAULTS,
|
||||
};
|
||||
|
||||
export const SettingsResponseSchema = z.object({
|
||||
|
||||
Reference in new issue
Block a user