Skip to content

feat: sync OpenChamber preferences with a per-field newest-wins merge - #108

Open
Rahulsharma0810 wants to merge 1 commit into
iHildy:mainfrom
Rahulsharma0810:feat/openchamber-prefs
Open

Rahulsharma0810 wants to merge 1 commit into
iHildy:mainfrom
Rahulsharma0810:feat/openchamber-prefs

Conversation

@Rahulsharma0810

Copy link
Copy Markdown

Closes #97

What

Opt-in sync of OpenChamber settings, off by default:

{ "openChamber": { "enabled": true, "include": [], "exclude": [], "path": "<optional>" } }

~/.config/openchamber/preferences.json is stored as { "version": 1, "fields": { "<name>": { "value": ..., "updatedAt": ... } } }. This merges it field by field, newest updatedAt wins, in both directions:

  • Push: newer allowlisted local fields are written to config/openchamber/preferences.json in the sync repo (sorted keys, written only when something changed).
  • Pull: newer allowlisted repo fields are applied to the local file. Unrelated and newer local fields are kept.

Safety

  • Allowlist. Default is themes, notification settings, favourite/hidden models, favourite agents, collapsed providers, custom provider icons and a few toggles. include replaces it (a trailing * is a prefix wildcard), exclude removes from it. Selected and recent models, projects and everything else stay local unless added.
  • Credential-like names are always refused, even when listed in include (token, secret, password, credential, private, api key, vapid, identity).
  • surfaces is per-device (for example a theme imported on one machine) and is never written to the repo; local surfaces are preserved on pull.
  • The local file is written atomically, keeps its mode, and gets a one-time preferences.json.pre-opencode-synced backup. A missing local file is never created, a malformed file is skipped, and a version mismatch skips the merge.
  • No other OpenChamber file is read (relay identity, GitHub auth, git identities, projects, chats, search index).

Why not extraConfigPaths

Extra paths copy whole files, so machine-local state (selected model, recents) is overwritten on every pull, the running app can clobber the result, and there is no field allowlist. See #97 for the longer discussion.

Integration

resolveOpenChamberPlan() builds the plan; syncRepoToLocal and syncLocalToRepo take it as an optional option, and the six existing call sites in service.ts pass it. With the feature disabled the plan is null and nothing changes. status prints OpenChamber preferences: enabled|disabled.

Tests

  • openchamber.test.ts: allowlist/include/exclude and wildcard behaviour, credential-like names refused even if included, push copies only allowed fields and drops surfaces, newest-wins in both directions, no rewrite when nothing is newer, missing/malformed/version-mismatched files, backup made once, mode preserved, missing local file not created, plan resolution (disabled, default path, custom ~ path).
  • apply.test.ts: push then pull through syncLocalToRepo/syncRepoToLocal, and no OpenChamber activity without a plan.
  • I also ran the module against a copy of a real preferences.json (69 fields): 17 default fields were synced, the other 52 and all surfaces stayed local, and a second push and a pull were no-ops.
  • bun run check, bun run test (219 passing) and bun run build pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: sync OpenChamber settings (structured preferences.json merge)

1 participant