mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
* refactor(config): make on-disk opencode.json the single source of truth Make <workspace>/.config/opencode/opencode.json the only store for the active OpenCode configuration. One owner (opencode-config-file.ts) reads, validates, writes, archives, and seeds the file; one owner (opencode-config-apply.ts) decides how an edit is applied: restart pending, or a live patch with recovery. Settings routes, the internal assistant API, the health-watch supervisor, boot, and host import all go through them, so an edit that lands on the file without going through the database is visible immediately instead of at the next Manager boot. Remove the named-config profiles. Migration 019 archives every opencode_configs row to .config/opencode-configs-archive/<name>.json, restores the default row to opencode.json when no file exists, then drops the table, its indexes, and repos.opencode_config_name. The /opencode-configs* and config/switch routes and the CreateConfigDialog/SwitchConfigDialog dialogs are gone, and the ocm tool gains GET/PUT /opencode-config backed by the same apply owner. Harden the write path: serialize and atomically write config updates while preserving the file mode, keep withFileLock usable after a rejection, route reloadConfig's cleaned-config write through the file owner, stop boot from rewriting an existing valid config when importing state, prune the health-watch directory to its newest 20 entries, resolve archive paths with realpath, and share one frontend config query across dialogs. * fix(mirror): canonicalize worktree paths before branch ownership check * refactor(config): unify opencode config apply and rollback paths - share one config route factory between public and internal mounts - capture last-known-good before every config write and restore via one helper - stop auto-restarting on save; flag restart-required fields and live-patch the rest - add CONFIG_PATCH_TIMEOUT_MS for config patch requests - extract canonicalPath helpers, health-watch artifact writer, and useProvidersWithModels hook * refactor(model-state): use OpenCode state file as model state source of truth
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { DatabaseSync } from 'node:sqlite'
|
|
|
|
// Adapter to make node:sqlite compatible with bun:sqlite API
|
|
export class Database {
|
|
private db: DatabaseSync
|
|
|
|
constructor(path: string) {
|
|
this.db = new DatabaseSync(path)
|
|
this.db.exec('PRAGMA foreign_keys = OFF')
|
|
}
|
|
|
|
prepare(sql: string) {
|
|
const stmt = this.db.prepare(sql)
|
|
return {
|
|
run: (...params: unknown[]) => {
|
|
const result = (stmt.run as (...args: unknown[]) => { changes: number; lastInsertRowid: number })(...params)
|
|
return { changes: result.changes, lastInsertRowid: result.lastInsertRowid }
|
|
},
|
|
get: (...params: unknown[]) => (stmt.get as (...args: unknown[]) => unknown)(...params),
|
|
all: (...params: unknown[]) => (stmt.all as (...args: unknown[]) => unknown[])(...params),
|
|
}
|
|
}
|
|
|
|
query(sql: string) {
|
|
return this.prepare(sql)
|
|
}
|
|
|
|
exec(sql: string) {
|
|
this.db.exec(sql)
|
|
}
|
|
|
|
run(sql: string, ...params: unknown[]) {
|
|
const stmt = this.db.prepare(sql)
|
|
const result = (stmt.run as (...args: unknown[]) => { changes: number; lastInsertRowid: number })(...params)
|
|
return { changes: result.changes, lastInsertRowid: result.lastInsertRowid }
|
|
}
|
|
|
|
transaction<T extends (...args: unknown[]) => void>(fn: T) {
|
|
return (...args: unknown[]) => {
|
|
this.db.exec('BEGIN')
|
|
try {
|
|
const result = fn(...args)
|
|
this.db.exec('COMMIT')
|
|
return result
|
|
} catch (e) {
|
|
this.db.exec('ROLLBACK')
|
|
throw e
|
|
}
|
|
}
|
|
}
|
|
|
|
close() {
|
|
this.db.close()
|
|
}
|
|
}
|