mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
* loop: ocm-session-move completed after 7 iterations * feat(ocm-cli): add session move with local history export and TUI plugin * docs(ocm-cli): update plugin config to tui-only entry and clarify session history source * fix(ocm-cli): replace raw postinstall output with TUI toast notification
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs'
|
|
import { homedir } from 'os'
|
|
import { dirname, join } from 'path'
|
|
|
|
export interface OcmState {
|
|
managerUrl: string
|
|
lastRepoId?: number
|
|
lastRepoName?: string
|
|
lastRepoDir?: string
|
|
lastRepoBranch?: string | null
|
|
updatedAt?: number
|
|
}
|
|
|
|
export interface InstallNotice {
|
|
link: string
|
|
binDir: string
|
|
pathMissing: boolean
|
|
}
|
|
|
|
const STATE_DIR = join(homedir(), '.config', 'opencode-manager')
|
|
const STATE_FILE = join(STATE_DIR, 'state.json')
|
|
const INSTALL_NOTICE_FILE = join(STATE_DIR, 'install-notice.json')
|
|
|
|
export function getStatePath(): string {
|
|
return STATE_FILE
|
|
}
|
|
|
|
export function readState(): OcmState | null {
|
|
if (!existsSync(STATE_FILE)) return null
|
|
try {
|
|
const raw = readFileSync(STATE_FILE, 'utf-8')
|
|
const parsed = JSON.parse(raw) as OcmState
|
|
if (!parsed.managerUrl) return null
|
|
return parsed
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function writeState(state: OcmState): void {
|
|
mkdirSync(dirname(STATE_FILE), { recursive: true })
|
|
const next: OcmState = { ...state, updatedAt: Date.now() }
|
|
writeFileSync(STATE_FILE, JSON.stringify(next, null, 2), { mode: 0o600 })
|
|
}
|
|
|
|
export function clearState(): void {
|
|
if (existsSync(STATE_FILE)) {
|
|
writeFileSync(STATE_FILE, '{}', { mode: 0o600 })
|
|
}
|
|
}
|
|
|
|
export function readInstallNotice(): InstallNotice | null {
|
|
if (!existsSync(INSTALL_NOTICE_FILE)) return null
|
|
try {
|
|
const raw = readFileSync(INSTALL_NOTICE_FILE, 'utf-8')
|
|
const parsed = JSON.parse(raw) as InstallNotice
|
|
if (!parsed.link || !parsed.binDir) return null
|
|
return parsed
|
|
} catch {
|
|
return null
|
|
} finally {
|
|
deleteInstallNotice()
|
|
}
|
|
}
|
|
|
|
function deleteInstallNotice(): void {
|
|
try {
|
|
unlinkSync(INSTALL_NOTICE_FILE)
|
|
} catch {
|
|
return
|
|
}
|
|
}
|