mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
feat(ocm-move): plan worktree mirror targets and stream move progress (#345)
* feat(ocm-move): plan worktree mirror targets and stream move progress - Plan/ensure mirror targets per branch via new internal endpoints, creating a worktree repo when the target branch is not checked out in the source repo - Skip branches checked out in other worktrees during bundle import and reset/clean before checkout on both server and CLI - Rewrite workspace paths in message.updated events when replaying moved sessions - Stream live move progress (bundle, upload, import, patch, replay) in the TUI - Prefer branch-matched repos when moving sessions and share push-divergence descriptions * chore(ocm-cli): bump version to 0.2.7 * fix(ocm): harden worktree mirror synchronization * fix(ocm): protect active branch during branchless pull
This commit is contained in:
1 parent
4ed3460759
commit
68d586f183
23 files changed
+2026
-158
No files matched your search
@@ -1,5 +1,11 @@
|
||||
import { createReadStream } from 'fs'
|
||||
import { Readable } from 'stream'
|
||||
import {
|
||||
MirrorTargetEnsureResponseSchema,
|
||||
MirrorTargetPlanResponseSchema,
|
||||
type MirrorTargetEnsureResponse,
|
||||
type MirrorTargetPlanResponse,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
|
||||
export interface MirrorBeginOpts {
|
||||
force?: boolean
|
||||
@@ -175,11 +181,12 @@ export class ManagerApi {
|
||||
async mirrorUploadBundle(
|
||||
repoId: number,
|
||||
bundlePath: string,
|
||||
opts: { branch: string | null; force?: boolean; onProgress?: (bytesSent: number) => void },
|
||||
opts: { branch: string | null; force?: boolean; requireCurrentBranch?: boolean; onProgress?: (bytesSent: number) => void },
|
||||
): Promise<MirrorBundleResult> {
|
||||
const query = opts.force === true ? '?force=1' : ''
|
||||
const headers: Record<string, string> = { ...this.headers(), 'Content-Type': 'application/octet-stream' }
|
||||
if (opts.branch) headers['X-OCM-Branch'] = opts.branch
|
||||
if (opts.requireCurrentBranch === true) headers['X-OCM-Require-Current-Branch'] = '1'
|
||||
const fileStream = Readable.toWeb(createReadStream(bundlePath)) as unknown as ReadableStream<Uint8Array>
|
||||
const body = opts.onProgress ? fileStream.pipeThrough(createByteCounter(opts.onProgress)) : fileStream
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/bundle${query}`, {
|
||||
@@ -202,6 +209,26 @@ export class ManagerApi {
|
||||
return (await res.json()) as MirrorHead
|
||||
}
|
||||
|
||||
async mirrorTargetPlan(repoId: number, branch: string): Promise<MirrorTargetPlanResponse> {
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/target?branch=${encodeURIComponent(branch)}`, {
|
||||
headers: this.headers(),
|
||||
})
|
||||
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror target plan')
|
||||
return MirrorTargetPlanResponseSchema.parse(await res.json())
|
||||
}
|
||||
|
||||
async mirrorEnsureTarget(repoId: number, branch: string): Promise<MirrorTargetEnsureResponse> {
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/target`, {
|
||||
method: 'POST',
|
||||
headers: { ...this.headers(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ branch }),
|
||||
})
|
||||
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror target')
|
||||
return MirrorTargetEnsureResponseSchema.parse(await res.json())
|
||||
}
|
||||
|
||||
async mirrorContains(repoId: number, sha: string): Promise<{ contained: boolean }> {
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/contains/${sha}`, {
|
||||
headers: this.headers(),
|
||||
|
||||
Reference in new issue
Block a user