mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* 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
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { getRepoRoot } from './local-repo.js'
|
|
|
|
export interface TargetRepo {
|
|
repoId: number
|
|
name: string
|
|
branch: string | null
|
|
directory: string
|
|
projectId?: string | null
|
|
}
|
|
|
|
export type ResolveResult =
|
|
| { kind: 'cwd-match'; repo: TargetRepo; repoRoot: string }
|
|
| { kind: 'last'; repo: TargetRepo }
|
|
| { kind: 'cwd-ambiguous'; matches: TargetRepo[]; localProjectId: string; repoRoot: string }
|
|
| { kind: 'local'; reason: 'no-match' | 'no-target'; repoRoot: string | null }
|
|
|
|
export interface ResolveInput {
|
|
cwd: string
|
|
repos: TargetRepo[]
|
|
localProjectId: string | null
|
|
last?: { repoId: number; name: string; directory: string; branch: string | null }
|
|
}
|
|
|
|
export function resolveTarget(input: ResolveInput): ResolveResult {
|
|
const repoRoot = getRepoRoot(input.cwd)
|
|
|
|
if (repoRoot) {
|
|
if (input.localProjectId) {
|
|
const matches = input.repos.filter((r) => r.projectId && r.projectId === input.localProjectId)
|
|
if (matches.length === 1) {
|
|
return { kind: 'cwd-match', repo: matches[0]!, repoRoot }
|
|
}
|
|
if (matches.length > 1) {
|
|
return { kind: 'cwd-ambiguous', matches, localProjectId: input.localProjectId, repoRoot }
|
|
}
|
|
}
|
|
return { kind: 'local', reason: 'no-match', repoRoot }
|
|
}
|
|
|
|
if (input.last) {
|
|
return { kind: 'last', repo: toTarget(input.last) }
|
|
}
|
|
return { kind: 'local', reason: 'no-target', repoRoot }
|
|
}
|
|
|
|
function toTarget(last: NonNullable<ResolveInput['last']>): TargetRepo {
|
|
return {
|
|
repoId: last.repoId,
|
|
name: last.name,
|
|
branch: last.branch,
|
|
directory: last.directory,
|
|
}
|
|
}
|