mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add bundle-based OCM mirror sync (#289)
* feat: add bundle-based OCM mirror sync * feat: add OpenCode model editor and HEAD-safe bundle import * fix: consolidate discovery-cache, batch bundle refs, remove dead code (#290) * fix: consolidate discovery-cache, batch bundle refs, remove dead code * refactor: consolidate discovery cache into generic discoverCached, extract spawnGit helper * feat: extract project-id-resolver, add CLI full-fallback prompt, wire lint into root scripts - Extract shared project-id-resolver for origin URL matching (replaces local-repo duplicates) - Add promptYesNo / confirmFullFallback to ocm CLI before slow full mirror - Backend: consolidate opencode-workspaces routes with project-id-resolver - Frontend: fix schedules prompt/global page navigation - CLI: add eslint config, lint/lint:fix scripts, fix no-fallthrough in ocm.ts - Root: wire CLI into build, test, typecheck, lint, lint:fix chains - Fix test lint issues (_code, const, require→import) * fix: replace polynomial regex with linear-time string ops in gitRemoteParts * feat: add divergence guards for push/pull, streaming bundle upload, server-side ancestry check - Backend: GET /:repoId/mirror/head (head+branch+dirty) and GET /:repoId/mirror/contains/:sha (ancestry check) - CLI: checkPushDivergence warns before overwriting server commits; checkPullDivergence warns before discarding local commits; both require confirm or --force - Bundle upload now streams from disk instead of buffering entire file in memory - Version visible in --help and default (no-arg) output - Version bump 0.1.5 → 0.2.0 * fix: show connecting message before fetching repos in default command * fix: update default command messages to reflect actual matching behavior
This commit is contained in:
1 parent
bb1df259b6
commit
01e50a7019
34 files changed
+2060
-316
No files matched your search
@@ -1,3 +1,6 @@
|
||||
import { createReadStream } from 'fs'
|
||||
import { Readable } from 'stream'
|
||||
|
||||
export interface MirrorBeginOpts {
|
||||
force?: boolean
|
||||
create?: { name: string; originUrl: string | null; branch: string | null }
|
||||
@@ -18,6 +21,37 @@ export interface MirrorCommitResult {
|
||||
created: boolean
|
||||
}
|
||||
|
||||
export interface MirrorPatchResult {
|
||||
repoId: number
|
||||
fullPath: string
|
||||
branch: string | null
|
||||
head: string | null
|
||||
created: false
|
||||
applied: true
|
||||
}
|
||||
|
||||
export interface MirrorPatchSnapshot {
|
||||
repoId: number
|
||||
branch: string | null
|
||||
head: string | null
|
||||
patch: string
|
||||
}
|
||||
|
||||
export interface MirrorHead {
|
||||
repoId: number
|
||||
branch: string | null
|
||||
head: string | null
|
||||
dirty: boolean
|
||||
}
|
||||
|
||||
export interface MirrorBundleResult {
|
||||
repoId: number
|
||||
fullPath: string
|
||||
branch: string | null
|
||||
head: string | null
|
||||
created: false
|
||||
}
|
||||
|
||||
export class ManagerApiError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
@@ -115,4 +149,67 @@ export class ManagerApi {
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror download')
|
||||
return res.body!
|
||||
}
|
||||
|
||||
async mirrorPatch(repoId: number, body: { baseHead: string | null; patch: string; force?: boolean }): Promise<MirrorPatchResult> {
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/patch`, {
|
||||
method: 'POST',
|
||||
headers: { ...this.headers(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ baseHead: body.baseHead, patch: body.patch, force: body.force === true }),
|
||||
})
|
||||
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror patch')
|
||||
return (await res.json()) as MirrorPatchResult
|
||||
}
|
||||
|
||||
async mirrorUploadBundle(repoId: number, bundlePath: string, opts: { branch: string | null; force?: boolean }): 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
|
||||
const body = Readable.toWeb(createReadStream(bundlePath)) as ReadableStream<Uint8Array>
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/bundle${query}`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body as BodyInit,
|
||||
duplex: 'half',
|
||||
} as RequestInit & { duplex: 'half' })
|
||||
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror bundle upload')
|
||||
return (await res.json()) as MirrorBundleResult
|
||||
}
|
||||
|
||||
async mirrorHead(repoId: number): Promise<MirrorHead> {
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/head`, {
|
||||
headers: this.headers(),
|
||||
})
|
||||
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror head')
|
||||
return (await res.json()) as MirrorHead
|
||||
}
|
||||
|
||||
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(),
|
||||
})
|
||||
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror contains')
|
||||
return (await res.json()) as { repoId: number; contained: boolean }
|
||||
}
|
||||
|
||||
async mirrorDownloadBundle(repoId: number): Promise<ReadableStream<Uint8Array>> {
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/bundle`, {
|
||||
headers: this.headers(),
|
||||
})
|
||||
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror bundle download')
|
||||
return res.body!
|
||||
}
|
||||
|
||||
async mirrorPatchSnapshot(repoId: number): Promise<MirrorPatchSnapshot> {
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror/patch`, {
|
||||
headers: this.headers(),
|
||||
})
|
||||
|
||||
if (!res.ok) throw await formatErrorResponse(res, 'mirror patch snapshot')
|
||||
return (await res.json()) as MirrorPatchSnapshot
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user