mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
refactor(opencode): reload config in place and drop v1 compatibility shims
Route config/skill/AGENTS.md changes through the OpenCode location reload API instead of a full server restart, stop auto-resuming interrupted sessions, remove the restart coordinator and v1 MCP/version shims, and pin support to OpenCode >=2.0.15 <3.0.0. Adds integration-ready retries, service-mode launch, ocm-cli repo proxy, and new frontend form/MCP helpers.
This commit is contained in:
1 parent
7351d5f002
commit
f5d0f0c27e
171 files changed
+5046
-11437
No files matched your search
@@ -36,6 +36,6 @@ export function pushPhaseProgress(phase: MirrorUpFastPhase): MoveProgress {
|
||||
}
|
||||
}
|
||||
|
||||
export function replayProgress(replayed: number, total: number): MoveProgress {
|
||||
return { label: `replaying session ${replayed}/${total} events`, fraction: total > 0 ? replayed / total : null }
|
||||
export function importProgress(imported: number, total: number): MoveProgress {
|
||||
return { label: `importing session ${imported}/${total} messages`, fraction: total > 0 ? imported / total : null }
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import packageJson from '../package.json' with { type: 'json' }
|
||||
|
||||
export const OCM_VERSION = packageJson.version
|
||||
export const MIN_MANAGER_VERSION = '0.19.0'
|
||||
|
||||
export class ManagerTooOldError extends Error {
|
||||
constructor(managerUrl: string) {
|
||||
super(`OpenCode Manager at ${managerUrl} is too old for ocm ${OCM_VERSION}; upgrade the Manager to >= ${MIN_MANAGER_VERSION}`)
|
||||
this.name = 'ManagerTooOldError'
|
||||
}
|
||||
}
|
||||
|
||||
export class RepoProxyNotFoundError extends Error {
|
||||
constructor(managerUrl: string, repoId: number) {
|
||||
super(`repo ${repoId} is not available on OpenCode Manager at ${managerUrl} (missing or not ready)`)
|
||||
this.name = 'RepoProxyNotFoundError'
|
||||
}
|
||||
}
|
||||
|
||||
export type WarmRepoProxyOptions = {
|
||||
attempts?: number
|
||||
fetch?: typeof fetch
|
||||
wait?: (ms: number) => Promise<void>
|
||||
}
|
||||
|
||||
export function repoProxyUrl(managerUrl: string, repoId: number): string {
|
||||
return `${managerUrl}/api/opencode-proxy/repos/${repoId}`
|
||||
}
|
||||
|
||||
function isRepoNotFoundBody(body: string): boolean {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(body)
|
||||
return typeof parsed === 'object' && parsed !== null && (parsed as { error?: unknown }).error === 'Repo not found'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
export async function warmRepoProxy(managerUrl: string, token: string, repoId: number, options: WarmRepoProxyOptions = {}): Promise<void> {
|
||||
const fetchImpl = options.fetch ?? fetch
|
||||
const attempts = options.attempts ?? 3
|
||||
const wait = options.wait ?? delay
|
||||
const url = `${repoProxyUrl(managerUrl, repoId)}/api/session?limit=1`
|
||||
|
||||
for (let attempt = 1; attempt <= attempts; attempt++) {
|
||||
const res = await fetchImpl(url, { headers: { Authorization: `Bearer ${token}` } }).catch(() => null)
|
||||
if (res) {
|
||||
const body = await res.text().catch(() => '')
|
||||
if (res.ok) return
|
||||
if (res.status === 404) {
|
||||
throw isRepoNotFoundBody(body) ? new RepoProxyNotFoundError(managerUrl, repoId) : new ManagerTooOldError(managerUrl)
|
||||
}
|
||||
}
|
||||
if (attempt < attempts) await wait(attempt * 500)
|
||||
}
|
||||
}
|
||||
@@ -65,15 +65,15 @@ export type TransferDeps = {
|
||||
export type TransferInput = { sessionID: string; localRoot: string; remoteDirectory: string }
|
||||
|
||||
export type TransferResult =
|
||||
| { kind: 'moved'; sessionID: string; replayedEvents: number }
|
||||
| { kind: 'replay-failed'; message: string }
|
||||
| { kind: 'moved'; sessionID: string; importedMessages: number }
|
||||
| { kind: 'import-failed'; message: string }
|
||||
|
||||
export async function transferSession(input: TransferInput, deps: TransferDeps): Promise<TransferResult> {
|
||||
let data: SessionTransferData
|
||||
try {
|
||||
data = await deps.exportSession(input.sessionID)
|
||||
} catch (err) {
|
||||
return { kind: 'replay-failed', message: err instanceof Error ? err.message : String(err) }
|
||||
return { kind: 'import-failed', message: err instanceof Error ? err.message : String(err) }
|
||||
}
|
||||
|
||||
const rewritten = rewriteTransferForRemote(data, {
|
||||
@@ -86,11 +86,11 @@ export async function transferSession(input: TransferInput, deps: TransferDeps):
|
||||
try {
|
||||
await deps.importSession(input.remoteDirectory, rewritten)
|
||||
} catch (err) {
|
||||
return { kind: 'replay-failed', message: err instanceof Error ? err.message : String(err) }
|
||||
return { kind: 'import-failed', message: err instanceof Error ? err.message : String(err) }
|
||||
}
|
||||
|
||||
deps.onProgress?.(total, total)
|
||||
return { kind: 'moved', sessionID: input.sessionID, replayedEvents: total }
|
||||
return { kind: 'moved', sessionID: input.sessionID, importedMessages: total }
|
||||
}
|
||||
|
||||
export function moveReminderText(directory: string): string {
|
||||
|
||||
@@ -12,7 +12,8 @@ import { transferSession, moveReminderText } from './session-move.js'
|
||||
import { createManagerSessionTransfer } from './remote-session.js'
|
||||
import { confirmDialog, selectDialog } from './tui-dialogs.js'
|
||||
import { setPendingWarp, runPendingWarp } from './warp.js'
|
||||
import { pushPhaseProgress, replayProgress } from './move-progress.js'
|
||||
import { pushPhaseProgress, importProgress } from './move-progress.js'
|
||||
import { warmRepoProxy } from './repo-proxy.js'
|
||||
import type { MoveProgress } from './move-progress.js'
|
||||
|
||||
export type MoveProgressSetter = (progress: MoveProgress | null) => void
|
||||
@@ -131,6 +132,8 @@ async function runSessionMove(context: Context, setMoveProgress: MoveProgressSet
|
||||
const matchedRepoId = matched.repoId
|
||||
const remoteRepo = repos.find((r) => r.repoId === matchedRepoId)!
|
||||
|
||||
await warmRepoProxy(state.managerUrl, token, matchedRepoId)
|
||||
|
||||
const managerApi = new ManagerApi(state.managerUrl, token)
|
||||
const target = await resolveMoveTarget(managerApi, matched, remoteRepo.directory, localBranch)
|
||||
const discardReasons = target.repoId === null ? [] : await describeRemoteDiscard(plan.repoRoot, managerApi, target.repoId)
|
||||
@@ -161,7 +164,7 @@ async function runSessionMove(context: Context, setMoveProgress: MoveProgressSet
|
||||
{
|
||||
exportSession: (id) => context.client.session.export({ sessionID: id }),
|
||||
importSession: transfer.importSession,
|
||||
onProgress: (transferred, total) => setMoveProgress(replayProgress(transferred, total)),
|
||||
onProgress: (transferred, total) => setMoveProgress(importProgress(transferred, total)),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -172,16 +175,16 @@ async function runSessionMove(context: Context, setMoveProgress: MoveProgressSet
|
||||
setMoveProgress(null)
|
||||
const warp = await confirmDialog(context, { title: 'Attach to moved session?', message: 'Exit this TUI and attach to the moved session on the Manager now?' })
|
||||
if (warp) {
|
||||
await fetch(`${state.managerUrl}/api/opencode-proxy/repos/${pushed.repoId}/api/session?limit=1`, { headers: { authorization: `Bearer ${token}` } }).catch(() => undefined)
|
||||
await warmRepoProxy(state.managerUrl, token, pushed.repoId)
|
||||
setPendingWarp({ managerUrl: state.managerUrl, token, repoId: pushed.repoId, sessionID: result.sessionID, repoName: matched.name })
|
||||
context.keymap.dispatch('app.exit')
|
||||
return
|
||||
}
|
||||
context.ui.toast.show({ variant: 'success', message: `Session moved to Manager (${result.replayedEvents} events). Local copy kept — run \`ocm\` to attach.` })
|
||||
context.ui.toast.show({ variant: 'success', message: `Session moved to Manager (${result.importedMessages} messages). Local copy kept — run \`ocm\` to attach.` })
|
||||
break
|
||||
}
|
||||
case 'replay-failed':
|
||||
context.ui.toast.show({ variant: 'error', message: `Replay failed: ${result.message}` })
|
||||
case 'import-failed':
|
||||
context.ui.toast.show({ variant: 'error', message: `Session import failed: ${result.message}` })
|
||||
break
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { buildRemoteAttachEnv } from './remote-context.js'
|
||||
import { repoProxyUrl } from './repo-proxy.js'
|
||||
|
||||
export type WarpTarget = {
|
||||
managerUrl: string
|
||||
@@ -30,7 +31,7 @@ export function takePendingWarp(): WarpTarget | undefined {
|
||||
export function buildAttachArgs(target: WarpTarget): string[] {
|
||||
return [
|
||||
'--server',
|
||||
`${target.managerUrl}/api/opencode-proxy/repos/${target.repoId}`,
|
||||
repoProxyUrl(target.managerUrl, target.repoId),
|
||||
'--session',
|
||||
target.sessionID,
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user