Complete Ralph to Loop rename across entire codebase

Rename all Ralph references to Loop including types, services, hooks,
filenames, KV keys, API routes, frontend components, tests, and docs.

Key changes:
- Types: RalphState → LoopState, RalphConfig → LoopConfig
- Services: ralph.ts → loop.ts with worktree field (inverted from inPlace)
- KV keys: ralph: → loop:, ralph-session: → loop-session:
- API routes: /ralph/* → /loop/*
- Frontend: useLoopStatus, RepoLoopList, getLoopStatus, cancelLoop
- Config backward compatibility: accepts both loop and ralph (prefers loop)
- Automatic KV migration on plugin startup
- memory-plan-execute keeps inPlace parameter (different semantics)

Fixes critical bugs found in code review:
- Backend /loop/cancel route using wrong ralph: KV prefix
- Frontend error messages still referencing Ralph
- Log message consistency
This commit is contained in:
Chris Scott committed 2026-03-27 14:45:54 -04:00
1 parent 00489d9901
commit 2c4a9c9257
31 files changed
+789 -745

No files matched your search

+16 -16
View File
@@ -17,9 +17,9 @@ import {
PluginConfigSchema,
CreateKvEntryRequestSchema,
UpdateKvEntryRequestSchema,
RalphStateSchema,
LoopStateSchema,
type PluginConfig,
type RalphState,
type LoopState,
} from '@opencode-manager/shared/schemas'
function resolveMemoryDataDir(): string {
@@ -528,7 +528,7 @@ export function createMemoryRoutes(db: Database): Hono {
}
})
app.get('/ralph/status', async (c) => {
app.get('/loop/status', async (c) => {
const repoIdParam = c.req.query('repoId')
if (!repoIdParam) {
@@ -554,26 +554,26 @@ export function createMemoryRoutes(db: Database): Hono {
return c.json({ loops: [], projectId: null })
}
const entries = pluginMemory.listKv(projectId, 'ralph:')
const entries = pluginMemory.listKv(projectId, 'loop:')
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)
const result = LoopStateSchema.safeParse(data)
return result.success ? result.data : null
})
.filter((loop): loop is RalphState => loop !== null)
.filter((loop): loop is LoopState => 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)
logger.error('Failed to get Loop:', error)
return c.json({ error: 'Failed to get Loop' }, 500)
}
})
app.post('/ralph/cancel', async (c) => {
app.post('/loop/cancel', async (c) => {
try {
const body = await c.req.json()
const { repoId, worktreeName, sessionId } = body
@@ -599,7 +599,7 @@ export function createMemoryRoutes(db: Database): Hono {
if (worktreeName) {
worktreeNameToUse = worktreeName
} else if (sessionId) {
const sessionMappingEntry = pluginMemory.getKv(projectId, `ralph-session:${sessionId}`)
const sessionMappingEntry = pluginMemory.getKv(projectId, `loop-session:${sessionId}`)
if (!sessionMappingEntry) {
return c.json({ cancelled: false })
}
@@ -610,15 +610,15 @@ export function createMemoryRoutes(db: Database): Hono {
return c.json({ cancelled: false })
}
const kvEntry = pluginMemory.getKv(projectId, `ralph:${worktreeNameToUse}`)
const kvEntry = pluginMemory.getKv(projectId, `loop:${worktreeNameToUse}`)
if (!kvEntry) {
return c.json({ cancelled: false })
}
const result = RalphStateSchema.safeParse(kvEntry.data)
const result = LoopStateSchema.safeParse(kvEntry.data)
if (!result.success) {
logger.warn('Failed to parse Ralph state for cancel:', result.error)
logger.warn('Failed to parse Loop state for cancel:', result.error)
return c.json({ cancelled: false })
}
@@ -635,7 +635,7 @@ export function createMemoryRoutes(db: Database): Hono {
completedAt: new Date().toISOString(),
}
pluginMemory.setKv(projectId, `ralph:${worktreeNameToUse}`, updatedState)
pluginMemory.setKv(projectId, `loop:${worktreeNameToUse}`, updatedState)
try {
const abortUrl = new URL(`${OPENCODE_SERVER_URL}/session/${state.sessionId}/abort`)
@@ -647,8 +647,8 @@ export function createMemoryRoutes(db: Database): Hono {
return c.json({ cancelled: true, worktreeName: state.worktreeName })
} catch (error) {
logger.error('Failed to cancel Ralph loop:', error)
return c.json({ error: 'Failed to cancel Ralph loop' }, 500)
logger.error('Failed to cancel Loop:', error)
return c.json({ error: 'Failed to cancel Loop' }, 500)
}
})
+11 -11
View File
@@ -63,7 +63,7 @@ import { getRepoById } from '../../src/db/queries'
const mockResolveProjectId = resolveProjectId as ReturnType<typeof vi.fn>
const mockGetRepoById = getRepoById as ReturnType<typeof vi.fn>
describe('Memory Routes - Ralph Status', () => {
describe('Memory Routes - Loop Status', () => {
let memoryApp: ReturnType<typeof createMemoryRoutes>
let testDb: any
@@ -77,9 +77,9 @@ describe('Memory Routes - Ralph Status', () => {
memoryApp = createMemoryRoutes(testDb)
})
describe('GET /ralph/status', () => {
describe('GET /loop/status', () => {
it('should return 400 when repoId query param is missing', async () => {
const req = new Request('http://localhost/ralph/status')
const req = new Request('http://localhost/loop/status')
const res = await memoryApp.fetch(req)
expect(res.status).toBe(400)
@@ -88,7 +88,7 @@ describe('Memory Routes - Ralph Status', () => {
})
it('should return 400 when repoId is not a valid number', async () => {
const req = new Request('http://localhost/ralph/status?repoId=abc')
const req = new Request('http://localhost/loop/status?repoId=abc')
const res = await memoryApp.fetch(req)
expect(res.status).toBe(400)
@@ -99,7 +99,7 @@ describe('Memory Routes - Ralph Status', () => {
it('should return 200 with empty loops when repo is not found in DB', async () => {
mockGetRepoById.mockReturnValue(null)
const req = new Request('http://localhost/ralph/status?repoId=1')
const req = new Request('http://localhost/loop/status?repoId=1')
const res = await memoryApp.fetch(req)
expect(res.status).toBe(200)
@@ -122,7 +122,7 @@ describe('Memory Routes - Ralph Status', () => {
})
mockResolveProjectId.mockResolvedValue(null)
const req = new Request('http://localhost/ralph/status?repoId=1')
const req = new Request('http://localhost/loop/status?repoId=1')
const res = await memoryApp.fetch(req)
expect(res.status).toBe(200)
@@ -147,7 +147,7 @@ describe('Memory Routes - Ralph Status', () => {
mockResolveProjectId.mockResolvedValue('test-project-id')
mockListKv.mockReturnValue([
{
key: 'ralph:test-worktree',
key: 'loop:test-worktree',
data: {
active: true,
sessionId: 'session-123',
@@ -168,7 +168,7 @@ describe('Memory Routes - Ralph Status', () => {
},
])
const req = new Request('http://localhost/ralph/status?repoId=1')
const req = new Request('http://localhost/loop/status?repoId=1')
const res = await memoryApp.fetch(req)
expect(res.status).toBe(200)
@@ -235,7 +235,7 @@ describe('Memory Routes - Ralph Status', () => {
},
])
const req = new Request('http://localhost/ralph/status?repoId=1')
const req = new Request('http://localhost/loop/status?repoId=1')
const res = await memoryApp.fetch(req)
expect(res.status).toBe(200)
@@ -249,12 +249,12 @@ describe('Memory Routes - Ralph Status', () => {
throw new Error('Database error')
})
const req = new Request('http://localhost/ralph/status?repoId=1')
const req = new Request('http://localhost/loop/status?repoId=1')
const res = await memoryApp.fetch(req)
expect(res.status).toBe(500)
const json = await res.json() as Record<string, unknown>
expect(json.error).toBe('Failed to get Ralph status')
expect(json.error).toBe('Failed to get Loop')
})
})
})