mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(ocm-cli): workspace repo sync and manager token targeting (#233)
This commit is contained in:
1 parent
e12f319592
commit
a86e4b1238
69 files changed
+4858
-161
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { existsSync, mkdirSync, readFileSync, 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
|
||||
}
|
||||
|
||||
const STATE_DIR = join(homedir(), '.config', 'opencode-manager')
|
||||
const STATE_FILE = join(STATE_DIR, 'state.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 })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user