mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
* feat(ocm-cli): add file and keychain credential backends with auth commands * feat(ocm-cli): refactor credentials into async TokenStore architecture Replace the credential-backend module with a TokenStore interface and file/keychain implementations behind an internal facade. Convert token get/set/delete to async, add env-token precedence warnings on login and logout, and surface store availability in status. Add token-store tests and helpers; remove the old credential modules and tests. Bump to 0.2.6. * fix(ocm-cli): keep tokens out of security argv and stop masking config read errors Route every macOS Keychain call through `security -i`, sending the quoted command on stdin so the token is never visible in process arguments. Reject arguments containing line breaks, which would otherwise inject additional security commands. Let unexpected state file read failures propagate so a broken config dir is reported instead of being reduced to "no manager configured", and stop consuming the install notice when reading it fails unexpectedly. --------- Co-authored-by: CS <chris@chriswritescode.dev>
66 lines
1.5 KiB
TypeScript
66 lines
1.5 KiB
TypeScript
import { existsSync, unlinkSync } from 'fs'
|
|
import { homedir } from 'os'
|
|
import { join } from 'path'
|
|
import { readJsonFile, writeJsonFileAtomic } from './json-store.js'
|
|
|
|
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 getConfigDir(): string {
|
|
return STATE_DIR
|
|
}
|
|
|
|
export function getStatePath(): string {
|
|
return STATE_FILE
|
|
}
|
|
|
|
export function readState(): OcmState | null {
|
|
const parsed = readJsonFile<OcmState>(STATE_FILE)
|
|
return parsed?.managerUrl ? parsed : null
|
|
}
|
|
|
|
export function writeState(state: OcmState): void {
|
|
writeJsonFileAtomic(STATE_FILE, { ...state, updatedAt: Date.now() })
|
|
}
|
|
|
|
export function clearState(): void {
|
|
if (existsSync(STATE_FILE)) {
|
|
writeJsonFileAtomic(STATE_FILE, {})
|
|
}
|
|
}
|
|
|
|
export function readInstallNotice(): InstallNotice | null {
|
|
let parsed: InstallNotice | null
|
|
try {
|
|
parsed = readJsonFile<InstallNotice>(INSTALL_NOTICE_FILE)
|
|
} catch {
|
|
return null
|
|
}
|
|
deleteInstallNotice()
|
|
return parsed?.link && parsed.binDir ? parsed : null
|
|
}
|
|
|
|
function deleteInstallNotice(): void {
|
|
try {
|
|
unlinkSync(INSTALL_NOTICE_FILE)
|
|
} catch {
|
|
return
|
|
}
|
|
}
|