mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add Ralph status dialog and session management improvements (#171)
This commit is contained in:
1 parent
27352ea5cf
commit
86613b1ea4
12 files changed
+1132
-65
No files matched your search
@@ -8,6 +8,7 @@ import { resolveProjectId } from '../services/project-id-resolver'
|
||||
import { getRepoById } from '../db/queries'
|
||||
import { getWorkspacePath, getConfigPath } from '@opencode-manager/shared/config/env'
|
||||
import { parseJsonc } from '@opencode-manager/shared/utils'
|
||||
import { OPENCODE_SERVER_URL } from '../services/proxy'
|
||||
import {
|
||||
CreateMemoryRequestSchema,
|
||||
UpdateMemoryRequestSchema,
|
||||
@@ -16,7 +17,9 @@ import {
|
||||
PluginConfigSchema,
|
||||
CreateKvEntryRequestSchema,
|
||||
UpdateKvEntryRequestSchema,
|
||||
RalphStateSchema,
|
||||
type PluginConfig,
|
||||
type RalphState,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
|
||||
function resolveMemoryDataDir(): string {
|
||||
@@ -525,6 +528,51 @@ export function createMemoryRoutes(db: Database): Hono {
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/ralph/status', async (c) => {
|
||||
const repoIdParam = c.req.query('repoId')
|
||||
|
||||
if (!repoIdParam) {
|
||||
return c.json({ error: 'Missing repoId' }, 400)
|
||||
}
|
||||
|
||||
const repoId = parseInt(repoIdParam, 10)
|
||||
|
||||
if (isNaN(repoId)) {
|
||||
return c.json({ error: 'Invalid repoId' }, 400)
|
||||
}
|
||||
|
||||
try {
|
||||
const repo = getRepoById(db, repoId)
|
||||
|
||||
if (!repo) {
|
||||
return c.json({ loops: [], projectId: null })
|
||||
}
|
||||
|
||||
const projectId = await resolveProjectId(repo.fullPath)
|
||||
|
||||
if (!projectId) {
|
||||
return c.json({ loops: [], projectId: null })
|
||||
}
|
||||
|
||||
const entries = pluginMemory.listKv(projectId, 'ralph:')
|
||||
const loops = entries
|
||||
.map(e => e.data)
|
||||
.filter((data): data is Record<string, unknown> =>
|
||||
data !== null && typeof data === 'object' && 'active' in data
|
||||
)
|
||||
.map(data => {
|
||||
const result = RalphStateSchema.safeParse(data)
|
||||
return result.success ? result.data : null
|
||||
})
|
||||
.filter((loop): loop is RalphState => loop !== null)
|
||||
|
||||
return c.json({ loops, projectId })
|
||||
} catch (error) {
|
||||
logger.error('Failed to get Ralph status:', error)
|
||||
return c.json({ error: 'Failed to get Ralph status' }, 500)
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/ralph/cancel', async (c) => {
|
||||
try {
|
||||
const body = await c.req.json()
|
||||
@@ -552,9 +600,16 @@ export function createMemoryRoutes(db: Database): Hono {
|
||||
return c.json({ cancelled: false })
|
||||
}
|
||||
|
||||
const state = kvEntry.data as { active?: boolean; worktreeName?: string } | undefined
|
||||
const result = RalphStateSchema.safeParse(kvEntry.data)
|
||||
|
||||
if (!state?.active) {
|
||||
if (!result.success) {
|
||||
logger.warn('Failed to parse Ralph state for cancel:', result.error)
|
||||
return c.json({ cancelled: false })
|
||||
}
|
||||
|
||||
const state = result.data
|
||||
|
||||
if (!state.active) {
|
||||
return c.json({ cancelled: false })
|
||||
}
|
||||
|
||||
@@ -567,6 +622,14 @@ export function createMemoryRoutes(db: Database): Hono {
|
||||
|
||||
pluginMemory.setKv(projectId, `ralph:${sessionId}`, updatedState)
|
||||
|
||||
try {
|
||||
const abortUrl = new URL(`${OPENCODE_SERVER_URL}/session/${sessionId}/abort`)
|
||||
abortUrl.searchParams.set('directory', repo.fullPath)
|
||||
await fetch(abortUrl.toString(), { method: 'POST' })
|
||||
} catch {
|
||||
// Session may already be idle
|
||||
}
|
||||
|
||||
return c.json({ cancelled: true, worktreeName: state.worktreeName })
|
||||
} catch (error) {
|
||||
logger.error('Failed to cancel Ralph loop:', error)
|
||||
|
||||
Reference in new issue
Block a user