Files
opencode-manager/ocm-cli/src/progress.ts
T
Chris Scott 68d586f183 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
2026-09-01 22:14:48 -04:00

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')
}
},
}
}