mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat: add multi-run fusion and session change walkthroughs
Fuse two to five completed multi-run entries into one synthesized session, and explain a session's diff as ordered walkthrough stops cached by diff hash. - Multi-run fusion service, persistence, routes and FuseRunDialog - Change walkthrough service, persistence, routes and ChangesWalkthroughDialog - Shared unified-diff parser plus bounded text generation, json-extract, text-truncate and service-error helpers
This commit is contained in:
1 parent
90c6ccf236
commit
b36d412ca2
66 files changed
+6228
-468
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { Hono } from 'hono'
|
||||
import { GenerateChangeWalkthroughRequestSchema } from '@opencode-manager/shared/schemas'
|
||||
import type { ChangeWalkthroughService } from '../services/change-walkthroughs'
|
||||
import { handleServiceError, parseJsonBody } from '../utils/route-helpers'
|
||||
import { ServiceError } from '../utils/service-error'
|
||||
|
||||
export function createChangeWalkthroughRoutes(service: ChangeWalkthroughService) {
|
||||
const app = new Hono()
|
||||
|
||||
app.get('/:sessionId', async (c) => {
|
||||
try {
|
||||
const state = await service.getState(c.req.param('sessionId'))
|
||||
return c.json(state)
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to read change walkthrough', ServiceError)
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/:sessionId', async (c) => {
|
||||
const parsed = await parseJsonBody(c, GenerateChangeWalkthroughRequestSchema, { allowEmpty: true })
|
||||
if (!parsed.ok) {
|
||||
return parsed.response
|
||||
}
|
||||
|
||||
try {
|
||||
const { walkthrough, created } = await service.generate(c.req.param('sessionId'), parsed.data)
|
||||
return c.json({ walkthrough }, created ? 201 : 200)
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to generate change walkthrough', ServiceError)
|
||||
}
|
||||
})
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Hono } from 'hono'
|
||||
import { LaunchMultiRunRequestSchema } from '@opencode-manager/shared/schemas'
|
||||
import { FuseMultiRunRequestSchema, LaunchMultiRunRequestSchema } from '@opencode-manager/shared/schemas'
|
||||
import { MultiRunError, type MultiRunService } from '../services/multi-runs'
|
||||
import { handleServiceError, parseId, parseJsonBody } from '../utils/route-helpers'
|
||||
import { ServiceError } from '../utils/service-error'
|
||||
|
||||
export function createMultiRunRoutes(service: MultiRunService) {
|
||||
const app = new Hono()
|
||||
@@ -11,7 +12,7 @@ export function createMultiRunRoutes(service: MultiRunService) {
|
||||
const repoId = parseId(c.req.query('repoId'), 'repoId', MultiRunError)
|
||||
return c.json({ runs: service.list(repoId) })
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to list multi-runs', MultiRunError)
|
||||
return handleServiceError(c, error, 'Failed to list multi-runs', ServiceError)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -25,7 +26,7 @@ export function createMultiRunRoutes(service: MultiRunService) {
|
||||
const run = await service.launch(parsed.data)
|
||||
return c.json({ run }, 201)
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to launch multi-run', MultiRunError)
|
||||
return handleServiceError(c, error, 'Failed to launch multi-run', ServiceError)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -36,7 +37,22 @@ export function createMultiRunRoutes(service: MultiRunService) {
|
||||
const run = await service.discard(multiRunId, entryId)
|
||||
return c.json({ run })
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to discard multi-run entry', MultiRunError)
|
||||
return handleServiceError(c, error, 'Failed to discard multi-run entry', ServiceError)
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/:id/fusions', async (c) => {
|
||||
try {
|
||||
const multiRunId = parseId(c.req.param('id'), 'multi-run id', MultiRunError)
|
||||
const parsed = await parseJsonBody(c, FuseMultiRunRequestSchema)
|
||||
if (!parsed.ok) {
|
||||
return parsed.response
|
||||
}
|
||||
|
||||
const { run, created } = await service.fuse(multiRunId, parsed.data)
|
||||
return c.json({ run }, created ? 201 : 200)
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to fuse multi-run', ServiceError)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { CommitMessageContext } from '../services/git/commit-message-prompt
|
||||
import { RenameBranchRequestSchema, DeleteBranchRequestSchema, StashPushRequestSchema, StashApplyRequestSchema, StashDropRequestSchema, IntegrateBranchRequestSchema } from '@opencode-manager/shared'
|
||||
import type { GitService } from '../services/git/GitService'
|
||||
import type { OpenCodeClient } from '../services/opencode/client'
|
||||
import { GenerateTextTimeoutError, generateTextWithTimeout } from '../services/opencode/generate-text'
|
||||
import type { GitStatusResponse } from '../types/git'
|
||||
import type { Repo } from '../types/repo'
|
||||
import { getErrorMessage } from '../utils/error-utils'
|
||||
@@ -19,13 +20,6 @@ export interface RepoGitRouteOptions {
|
||||
commitMessageTimeoutMs?: number
|
||||
}
|
||||
|
||||
class CommitMessageTimeoutError extends Error {
|
||||
constructor() {
|
||||
super('Commit message generation timed out')
|
||||
this.name = 'CommitMessageTimeoutError'
|
||||
}
|
||||
}
|
||||
|
||||
function parseStashIndex(raw: string | undefined): number | null {
|
||||
if (raw === undefined || !/^\d+$/.test(raw)) {
|
||||
return null
|
||||
@@ -174,25 +168,12 @@ export function createRepoGitRoutes(
|
||||
return c.json({ error: getErrorMessage(error) }, 400)
|
||||
}
|
||||
|
||||
const controller = new AbortController()
|
||||
let timedOut = false
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
const timeout = new Promise<never>((_resolve, reject) => {
|
||||
timer = setTimeout(() => {
|
||||
timedOut = true
|
||||
controller.abort()
|
||||
reject(new CommitMessageTimeoutError())
|
||||
}, commitMessageTimeoutMs)
|
||||
})
|
||||
|
||||
try {
|
||||
const { text } = await Promise.race([
|
||||
openCodeClient.api.generate.text(
|
||||
{ prompt: buildCommitMessagePrompt(context) },
|
||||
{ signal: controller.signal },
|
||||
),
|
||||
timeout,
|
||||
])
|
||||
const text = await generateTextWithTimeout(
|
||||
openCodeClient,
|
||||
{ prompt: buildCommitMessagePrompt(context) },
|
||||
commitMessageTimeoutMs,
|
||||
)
|
||||
const message = normalizeGeneratedCommitMessage(text)
|
||||
|
||||
if (!message) {
|
||||
@@ -201,13 +182,11 @@ export function createRepoGitRoutes(
|
||||
|
||||
return c.json({ message })
|
||||
} catch (error: unknown) {
|
||||
if (timedOut) {
|
||||
if (error instanceof GenerateTextTimeoutError) {
|
||||
return c.json({ error: 'Commit message generation timed out' }, 502)
|
||||
}
|
||||
logger.error('Failed to generate commit message:', error)
|
||||
return c.json({ error: getErrorMessage(error) }, 502)
|
||||
} finally {
|
||||
if (timer) clearTimeout(timer)
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
Reference in new issue
Block a user