mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
refactor(config): make on-disk opencode.json the single source of truth (#354)
* 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
This commit is contained in:
1 parent
7a3c5229df
commit
295d24ced7
116 files changed
+10291
-4208
No files matched your search
@@ -58,6 +58,8 @@ The `path` is relative to the internal API base (for example `/settings` or `/re
|
||||
```
|
||||
GET /settings
|
||||
PATCH /settings
|
||||
GET /opencode-config
|
||||
PUT /opencode-config
|
||||
POST /assistant/reload
|
||||
GET /repos
|
||||
GET /repos/*/git-info
|
||||
@@ -200,6 +202,50 @@ Returns the updated settings object.
|
||||
- `400`: Invalid request body or disallowed key
|
||||
- `401`: Missing or invalid bearer token
|
||||
|
||||
### OpenCode Configuration
|
||||
|
||||
The OpenCode configuration file at `getOpenCodeConfigFilePath()` is the source of truth, and this endpoint is the only supported way to change it. The endpoint applies the same restart and live-patch rules as the Settings UI: changes to `agent`, `plugin`, `skills`, or `provider` mark an OpenCode server restart as required, and any other change is live-patched into the running OpenCode server.
|
||||
|
||||
**GET `/api/internal/opencode-config`**
|
||||
|
||||
Read the current configuration file state.
|
||||
|
||||
**Response (`OpenCodeConfigFile`):**
|
||||
```ts
|
||||
{
|
||||
path: string // Absolute path of the configuration file
|
||||
content: object // Parsed configuration
|
||||
rawContent: string // Raw file content, including comments
|
||||
isValid: boolean // Whether the file passes schema validation
|
||||
validationIssues?: Array<{ path: string, message: string }>
|
||||
updatedAt: number // Unix timestamp of the last write
|
||||
}
|
||||
```
|
||||
|
||||
**Status Codes:**
|
||||
- `200`: Configuration file state returned
|
||||
- `401`: Missing or invalid bearer token
|
||||
- `404`: No config file found
|
||||
- `500`: Server error
|
||||
|
||||
**PUT `/api/internal/opencode-config`**
|
||||
|
||||
Persist a complete configuration. Read the file first, change only the keys the user asked for, and send the complete object back.
|
||||
|
||||
**Request Body:**
|
||||
```ts
|
||||
{ content: object } // The complete configuration to persist
|
||||
```
|
||||
|
||||
**Response:**
|
||||
Returns the written `OpenCodeConfigFile`. Adds `restartRequired: true` when the change needs an OpenCode server restart, and `removedFields` when OpenCode dropped fields it does not accept.
|
||||
|
||||
**Status Codes:**
|
||||
- `200`: Configuration written (live-patched or restart pending)
|
||||
- `400`: Invalid request body, or configuration rejected with `validationIssues`
|
||||
- `401`: Missing or invalid bearer token
|
||||
- `500`: Server error
|
||||
|
||||
### Assistant
|
||||
|
||||
**POST `/api/internal/assistant/reload`**
|
||||
@@ -251,7 +297,6 @@ Retrieve a list of all managed repositories, ordered by the user's repo preferen
|
||||
clonedAt: number // Timestamp when repo was cloned
|
||||
lastPulled?: number // Timestamp of last pull
|
||||
lastAccessedAt?: number // Timestamp of last access
|
||||
openCodeConfigName?: string // Associated OpenCode config name
|
||||
isWorktree?: boolean // Whether repo is a worktree
|
||||
isLocal?: boolean // Whether repo is local-only
|
||||
}>
|
||||
@@ -269,7 +314,7 @@ The assistant workspace includes four skills that document these capabilities:
|
||||
|
||||
1. **Schedule Management** (`.opencode/skills/schedule-management/SKILL.md`) — manage schedule jobs and runs through the `ocm` `request` action.
|
||||
2. **Notifications** (`.opencode/skills/notifications/SKILL.md`) — send push notifications through the `ocm` `send_notification` action.
|
||||
3. **Manager Settings** (`.opencode/skills/manager-settings/SKILL.md`) — read and patch user preferences and reload the assistant workspace through the `ocm` `request` action.
|
||||
3. **Manager Settings** (`.opencode/skills/manager-settings/SKILL.md`) — read and patch user preferences, read and update the OpenCode configuration file, and reload the assistant workspace through the `ocm` `request` action.
|
||||
4. **Repo Management** (`.opencode/skills/repo-management/SKILL.md`) — list managed repositories through the `ocm` `request` action.
|
||||
|
||||
These skills are automatically provisioned when assistant mode is initialized and contain detailed examples and usage patterns.
|
||||
Reference in new issue
Block a user