feat(ocm-cli): add session warp with progress reporting (#314)

* feat(ocm-cli): add session warp with progress reporting

Add warp functionality for moving sessions between local and remote
Managers. Includes TUI dialogs, remote replay, progress reporting
during event transfer, and comprehensive test coverage.

* feat(ocm-cli): add granular push progress with phase reporting and upload tracking

* chore(ocm-cli): bump version to 0.2.5

* docs(ocm-cli): document push progress phases in README
This commit is contained in:
Chris Scott authored and GitHub committed 2026-07-16 17:36:54 -04:00
1 parent 4519bcd2e9
commit adf6bd2921
16 files changed
+759 -30

No files matched your search

+60 -11
View File
@@ -4,9 +4,13 @@ import { getToken } from './keychain.js'
import { fetchRepos, toRemoteRepoSummaries } from './manager-repos.js'
import { ManagerApi, ManagerApiError } from './manager-api.js'
import { prepareMirror, checkPushDivergence, mirrorUpFast } from './mirror.js'
import { transferSession } from './session-move.js'
import { createManagerReplay } from './remote-replay.js'
import type { MirrorPlan, MirrorUpFastPhase } from './mirror.js'
import { formatBytes } from './progress.js'
import { transferSession, moveReminderText } from './session-move.js'
import { createManagerReplay, createManagerPromptAsync } from './remote-replay.js'
import { readSessionEvents } from './local-history.js'
import { confirmDialog, selectDialog } from './tui-dialogs.js'
import { setPendingWarp, runPendingWarp } from './warp.js'
export async function setupOcm(api: TuiPluginApi): Promise<void> {
showInstallNotice(api)
@@ -23,6 +27,7 @@ export async function setupOcm(api: TuiPluginApi): Promise<void> {
},
],
})
api.lifecycle.onDispose(() => runPendingWarp())
}
function showInstallNotice(api: TuiPluginApi): void {
@@ -39,6 +44,31 @@ function showInstallNotice(api: TuiPluginApi): void {
})
}
function pushPhaseMessage(phase: MirrorUpFastPhase): string {
switch (phase.kind) {
case 'bundling':
return 'Pushing repo state: creating git bundle…'
case 'uploading':
return `Pushing repo state: uploading ${formatBytes(phase.bytesSent)} / ${formatBytes(phase.totalBytes)}…`
case 'processing':
return 'Pushing repo state: waiting for server to import bundle…'
case 'patching':
return 'Pushing repo state: applying local changes…'
}
}
function createPushPhaseToaster(api: TuiPluginApi): (phase: MirrorUpFastPhase) => void {
let lastUploadToastAt = 0
return (phase) => {
if (phase.kind === 'uploading') {
const now = Date.now()
if (now - lastUploadToastAt < 1000) return
lastUploadToastAt = now
}
api.ui.toast({ message: pushPhaseMessage(phase) })
}
}
async function runSessionMove(api: TuiPluginApi): Promise<void> {
try {
const current = api.route.current
@@ -74,17 +104,19 @@ async function runSessionMove(api: TuiPluginApi): Promise<void> {
return
}
let matched = plan.matched[0]!
if (plan.matched.length > 1) {
const names = plan.matched.map((r) => `${r.name} (id=${r.repoId})`).join(', ')
api.ui.toast({ variant: 'error', message: `Multiple Manager repos match: ${names}` })
return
const chosen = await selectDialog(api, 'Move session to Manager repo', plan.matched.map((r) => ({ title: r.name, description: `id=${r.repoId}`, value: r })))
if (!chosen) return
matched = chosen
}
const matched = plan.matched[0]!
const repoId = matched.repoId
const remoteRepo = repos.find((r) => r.repoId === repoId)
const remoteDirectory = remoteRepo!.directory
const proceed = await confirmDialog(api, { title: 'Move session to Manager', message: `Push repo state and move this session to ${matched.name} (${remoteDirectory})?` })
if (!proceed) return
const managerApi = new ManagerApi(state.managerUrl, token)
try {
@@ -97,18 +129,35 @@ async function runSessionMove(api: TuiPluginApi): Promise<void> {
if (!(error instanceof ManagerApiError && error.status === 404)) throw error
}
api.ui.toast({ message: 'Pushing repo state…' })
await mirrorUpFast(plan, { api: managerApi, force: false })
const selectedPlan: MirrorPlan = { ...plan, matched: [matched] }
await mirrorUpFast(selectedPlan, {
api: managerApi,
force: false,
onPhase: createPushPhaseToaster(api),
})
const result = await transferSession(
{ sessionID, localRoot: plan.repoRoot, remoteDirectory },
{ fetchLocalHistory: () => readSessionEvents(sessionID), replayEvents: createManagerReplay(state.managerUrl, token) },
{
fetchLocalHistory: () => readSessionEvents(sessionID),
replayEvents: createManagerReplay(state.managerUrl, token),
onProgress: (replayed, total) => api.ui.toast({ message: `Moving session… ${replayed}/${total} events`, duration: 2000 }),
},
)
switch (result.kind) {
case 'moved':
case 'moved': {
await createManagerPromptAsync(state.managerUrl, token)(remoteDirectory, result.sessionID, moveReminderText(remoteDirectory)).catch(() => undefined)
const warp = await confirmDialog(api, { 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/session?directory=${encodeURIComponent(remoteDirectory)}`, { headers: { authorization: `Bearer ${token}` } }).catch(() => undefined)
setPendingWarp({ managerUrl: state.managerUrl, token, directory: remoteDirectory, sessionID: result.sessionID, repoName: matched.name })
api.keymap.dispatchCommand('app.exit')
return
}
api.ui.toast({ variant: 'success', message: `Session moved to Manager (${result.replayedEvents} events). Local copy kept — run \`ocm\` to attach.` })
break
}
case 'not-found':
api.ui.toast({ variant: 'error', message: 'No durable history found for this session' })
break