mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* 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
63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
export const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
|
|
|
export function formatBytes(bytes: number): string {
|
|
if (bytes < 1024) {
|
|
return `${bytes} B`
|
|
}
|
|
if (bytes < 1024 * 1024) {
|
|
return `${(bytes / 1024).toFixed(1)} KB`
|
|
}
|
|
if (bytes < 1024 * 1024 * 1024) {
|
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
|
|
}
|
|
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`
|
|
}
|
|
|
|
export interface ProgressSink {
|
|
write(chunk: string): void
|
|
isTTY?: boolean
|
|
}
|
|
|
|
export interface ProgressReporter {
|
|
tick(bytes: number): void
|
|
done(): void
|
|
}
|
|
|
|
export function createProgressReporter(
|
|
label: string,
|
|
out: ProgressSink = process.stderr,
|
|
now: () => number = Date.now,
|
|
): ProgressReporter {
|
|
let finished = false
|
|
let lastRenderAt = -Infinity
|
|
let lastNonTtyTickAt = -Infinity
|
|
let frameIndex = 0
|
|
const isTTY = out.isTTY === true
|
|
|
|
return {
|
|
tick(bytes: number): void {
|
|
if (finished) return
|
|
const t = now()
|
|
|
|
if (isTTY) {
|
|
if (t - lastRenderAt < 80) return
|
|
lastRenderAt = t
|
|
out.write(`\r\x1b[K${label}: ${SPINNER_FRAMES[frameIndex]} ${formatBytes(bytes)}`)
|
|
frameIndex = (frameIndex + 1) % SPINNER_FRAMES.length
|
|
} else {
|
|
if (t - lastNonTtyTickAt < 1000) return
|
|
lastNonTtyTickAt = t
|
|
out.write(`${label}: ${formatBytes(bytes)}\n`)
|
|
}
|
|
},
|
|
|
|
done(): void {
|
|
if (finished) return
|
|
finished = true
|
|
if (isTTY) {
|
|
out.write('\r\x1b[K')
|
|
}
|
|
},
|
|
}
|
|
}
|