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:
Chris Scott authored and GitHub committed 2026-06-28 11:57:38 -04:00
1 parent bb1df259b6
commit 01e50a7019
34 files changed
+2060 -316

No files matched your search

+46 -5
View File
@@ -16,11 +16,11 @@ export function normalizeToBaseUrl(endpoint: string): string {
.replace(/\/$/, '')
}
export async function ensureDiscoveryCacheDir(): Promise<void> {
async function ensureDiscoveryCacheDir(): Promise<void> {
await mkdir(DISCOVERY_CACHE_DIR, { recursive: true })
}
export async function getCachedDiscovery<T>(cacheKey: string): Promise<T | null> {
async function getCachedDiscovery<T>(cacheKey: string): Promise<T | null> {
try {
const filePath = join(DISCOVERY_CACHE_DIR, `${cacheKey}.json`)
const fileStat = await stat(filePath)
@@ -37,7 +37,7 @@ export async function getCachedDiscovery<T>(cacheKey: string): Promise<T | null>
}
}
export async function cacheDiscovery<T>(cacheKey: string, data: T): Promise<void> {
async function cacheDiscovery<T>(cacheKey: string, data: T): Promise<void> {
try {
await ensureDiscoveryCacheDir()
const filePath = join(DISCOVERY_CACHE_DIR, `${cacheKey}.json`)
@@ -47,13 +47,13 @@ export async function cacheDiscovery<T>(cacheKey: string, data: T): Promise<void
}
}
export function generateDiscoveryCacheKey(baseUrl: string, apiKey: string, type: string): string {
function generateDiscoveryCacheKey(baseUrl: string, apiKey: string, type: string): string {
const hash = createHash('sha256')
hash.update(`${baseUrl}|${apiKey}|${type}`)
return hash.digest('hex')
}
export async function fetchAvailableModels(
async function fetchAvailableModels(
baseUrl: string,
apiKey: string,
filterPattern: RegExp,
@@ -103,3 +103,44 @@ export async function fetchAvailableModels(
return defaultModels
}
export async function discoverCached<T>(opts: {
baseUrl: string
apiKey: string
type: string
forceRefresh: boolean
fetcher: () => Promise<T>
}): Promise<{ value: T; cached: boolean }> {
const cacheKey = generateDiscoveryCacheKey(opts.baseUrl, opts.apiKey, opts.type)
if (!opts.forceRefresh) {
const cached = await getCachedDiscovery<T>(cacheKey)
if (cached) return { value: cached, cached: true }
}
await ensureDiscoveryCacheDir()
logger.info(`Discovering ${opts.type} from ${opts.baseUrl}`)
const value = await opts.fetcher()
await cacheDiscovery(cacheKey, value)
return { value, cached: false }
}
export async function discoverModelsCached(opts: {
baseUrl: string
apiKey: string
type: string
filterPattern: RegExp
defaultModels: string[]
forceRefresh: boolean
}): Promise<{ models: string[]; cached: boolean }> {
const { value, cached } = await discoverCached({
baseUrl: opts.baseUrl,
apiKey: opts.apiKey,
type: opts.type,
forceRefresh: opts.forceRefresh,
fetcher: () => fetchAvailableModels(opts.baseUrl, opts.apiKey, opts.filterPattern, opts.defaultModels),
})
return { models: value, cached }
}