Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Create `~/.config/opencode/opencode-synced.jsonc`:
"includeModelFavorites": true,
"includeOpencodeSkills": true,
"includeAgentsDir": true,
"openChamber": { "enabled": false },
"extraSecretPaths": [],
"extraConfigPaths": [],
}
Expand All @@ -155,6 +156,43 @@ Create `~/.config/opencode/opencode-synced.jsonc`:
Review it before syncing, keep the sync repository private when needed, or set
`"includeAgentsDir": false` to opt out.

### OpenChamber preferences

If you use [OpenChamber](https://github.com/openchamber/openchamber) as the opencode UI, its settings
can be synced too. This is off by default:

```jsonc
{
"openChamber": {
"enabled": true,
// optional: replace the default field list, "*" at the end is a prefix wildcard
"include": ["darkThemeId", "lightThemeId", "notifyOn*", "favoriteModels", "fontSize"],
// optional: never sync these
"exclude": ["customProviderIcons"],
// optional: defaults to <config dir>/openchamber/preferences.json
"path": "~/.config/openchamber/preferences.json"
}
}
```

OpenChamber stores `preferences.json` as `{ "fields": { "<name>": { "value": ..., "updatedAt": ... } } }`.
Fields are merged one by one and the **newest `updatedAt` wins**, in both directions, so two machines never
overwrite each other's unrelated settings.

- Default fields: themes, notification settings, favourite and hidden models, favourite agents,
collapsed model providers, custom provider icons, and a few behaviour toggles. Selected and recent
models, projects and everything else stay local unless you add them to `include`.
- Field names that look like credentials (`token`, `secret`, `password`, `credential`, `private`,
`api key`, `vapid`, `identity`) are never synced, even if listed in `include`.
- Per-device `surfaces` data (for example a theme imported on one machine) is never written to the repo
and is preserved locally on pull.
- The repo copy lives at `config/openchamber/preferences.json`. The local file is only changed when a
repo field is newer; it is written atomically, keeps its permissions, and a one-time
`preferences.json.pre-opencode-synced` backup is kept. A missing local file is never created, a
malformed file is skipped, and a `version` mismatch skips the merge.
- Other OpenChamber files (relay identity, GitHub auth, git identities, projects, chat history,
search index) are never read.

Disable default directory sync by setting:
- `"includeOpencodeSkills": false` to skip `~/.config/opencode/skills/`
- `"includeAgentsDir": false` to skip `~/.agents/`
Expand Down
56 changes: 56 additions & 0 deletions src/sync/apply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,59 @@ describe('MCP secret scrub round trip', () => {
});
});
});

describe('OpenChamber preferences in the sync flow', () => {
it('pushes allowlisted fields to the repo and pulls newer ones back', async () => {
await withTempDir(async (root) => {
const repoRoot = path.join(root, 'repo');
const homeDir = path.join(root, 'home');
const plan = createPlan(repoRoot, homeDir, []);
const localPath = path.join(homeDir, '.config', 'openchamber', 'preferences.json');
const repoPath = path.join(repoRoot, 'config', 'openchamber', 'preferences.json');
const openChamber = { localPath, repoPath, include: [], exclude: [] };
await fs.mkdir(path.dirname(localPath), { recursive: true });
await fs.writeFile(
localPath,
JSON.stringify({
version: 1,
fields: {
darkThemeId: { value: 'dark-a', updatedAt: 1 },
lastSelectedModel: { value: 'private/model', updatedAt: 1 },
},
}),
'utf8'
);

await syncLocalToRepo(plan, null, { openChamber });
const pushed = JSON.parse(await fs.readFile(repoPath, 'utf8'));
expect(Object.keys(pushed.fields)).toEqual(['darkThemeId']);

pushed.fields.darkThemeId = { value: 'dark-b', updatedAt: 5 };
await fs.writeFile(repoPath, JSON.stringify(pushed), 'utf8');
await syncRepoToLocal(plan, null, { openChamber });
const pulled = JSON.parse(await fs.readFile(localPath, 'utf8'));
expect(pulled.fields.darkThemeId.value).toBe('dark-b');
expect(pulled.fields.lastSelectedModel.value).toBe('private/model');
});
});

it('leaves OpenChamber alone when no plan is passed', async () => {
await withTempDir(async (root) => {
const repoRoot = path.join(root, 'repo');
const homeDir = path.join(root, 'home');
const localPath = path.join(homeDir, '.config', 'openchamber', 'preferences.json');
await fs.mkdir(repoRoot, { recursive: true });
await fs.mkdir(path.dirname(localPath), { recursive: true });
await fs.writeFile(
localPath,
'{"version":1,"fields":{"darkThemeId":{"value":"x","updatedAt":1}}}'
);

await syncLocalToRepo(createPlan(repoRoot, homeDir, []), null);

await expect(
fs.access(path.join(repoRoot, 'config', 'openchamber', 'preferences.json'))
).rejects.toThrow();
});
});
});
15 changes: 14 additions & 1 deletion src/sync/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import {
mergeOverrides,
stripOverrideKeys,
} from './mcp-secrets.js';
import {
type OpenChamberPlan,
pullOpenChamberPreferences,
pushOpenChamberPreferences,
} from './openchamber.js';
import type { ExtraPathPlan, SyncItem, SyncPlan } from './paths.js';
import { fromPortablePath, normalizePath, toPortablePath } from './paths.js';

Expand Down Expand Up @@ -51,7 +56,7 @@ interface ExtraPathManifest {
export async function syncRepoToLocal(
plan: SyncPlan,
overrides: Record<string, unknown> | null,
options: { chunkOptions?: ChunkOptions } = {}
options: { chunkOptions?: ChunkOptions; openChamber?: OpenChamberPlan | null } = {}
): Promise<void> {
for (const item of plan.items) {
if (item.chunkLargeFiles) {
Expand All @@ -64,6 +69,10 @@ export async function syncRepoToLocal(
await applyExtraPaths(plan, plan.extraConfigs);
await applyExtraPaths(plan, plan.extraSecrets);

if (options.openChamber) {
await pullOpenChamberPreferences(options.openChamber);
}

if (overrides && Object.keys(overrides).length > 0) {
await applyOverridesToLocalConfig(plan, overrides);
}
Expand Down Expand Up @@ -93,6 +102,7 @@ export async function syncLocalToRepo(
overridesPath?: string;
allowMcpSecrets?: boolean;
chunkOptions?: ChunkOptions;
openChamber?: OpenChamberPlan | null;
} = {}
): Promise<void> {
const configItems = plan.items.filter((item) => item.isConfigFile);
Expand Down Expand Up @@ -148,6 +158,9 @@ export async function syncLocalToRepo(

await writeExtraPathManifest(plan, plan.extraConfigs);
await writeExtraPathManifest(plan, plan.extraSecrets);
if (options.openChamber) {
await pushOpenChamberPreferences(options.openChamber);
}
await cleanupUnreferencedChunkStores(plan.repoRoot);
}

Expand Down
36 changes: 36 additions & 0 deletions src/sync/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ export interface SecretsBackendConfig {

export type SessionBackendType = 'git' | 'turso';

export interface OpenChamberSettings {
enabled?: boolean;
/** Override for the local preferences file. Defaults to `<config dir>/openchamber/preferences.json`. */
path?: string;
/** Field names (a trailing `*` is a prefix wildcard) to sync instead of the default list. */
include?: string[];
/** Field names (a trailing `*` is a prefix wildcard) that are never synced. */
exclude?: string[];
}

export interface NormalizedOpenChamberSettings {
enabled: boolean;
path?: string;
include: string[];
exclude: string[];
}

export interface TursoSessionBackendSettings {
database?: string;
url?: string;
Expand Down Expand Up @@ -61,6 +78,7 @@ export interface SyncConfig {
includeModelFavorites?: boolean;
includeOpencodeSkills?: boolean;
includeAgentsDir?: boolean;
openChamber?: OpenChamberSettings;
secretsBackend?: SecretsBackendConfig;
extraSecretPaths?: string[];
extraConfigPaths?: string[];
Expand All @@ -75,6 +93,7 @@ export interface NormalizedSyncConfig extends SyncConfig {
includeModelFavorites: boolean;
includeOpencodeSkills: boolean;
includeAgentsDir: boolean;
openChamber: NormalizedOpenChamberSettings;
secretsBackend?: SecretsBackendConfig;
extraSecretPaths: string[];
extraConfigPaths: string[];
Expand Down Expand Up @@ -168,6 +187,22 @@ export function normalizeSessionBackend(
};
}

function normalizeStringList(input: unknown): string[] {
if (!Array.isArray(input)) return [];
return input.filter((item): item is string => typeof item === 'string' && item.trim() !== '');
}

export function normalizeOpenChamber(input: unknown): NormalizedOpenChamberSettings {
const settings = isPlainObject(input) ? input : {};
const customPath = typeof settings.path === 'string' ? settings.path.trim() : '';
return {
enabled: settings.enabled === true,
path: customPath || undefined,
include: normalizeStringList(settings.include),
exclude: normalizeStringList(settings.exclude),
};
}

export function isTursoSessionBackend(config: SyncConfig | NormalizedSyncConfig): boolean {
if (!config.includeSessions) return false;
const normalized = normalizeSessionBackend(config.sessionBackend);
Expand All @@ -188,6 +223,7 @@ export function normalizeSyncConfig(config: SyncConfig): NormalizedSyncConfig {
includeModelFavorites,
includeOpencodeSkills,
includeAgentsDir,
openChamber: normalizeOpenChamber(config.openChamber),
secretsBackend: normalizeSecretsBackend(config.secretsBackend),
extraSecretPaths: Array.isArray(config.extraSecretPaths) ? config.extraSecretPaths : [],
extraConfigPaths: Array.isArray(config.extraConfigPaths) ? config.extraConfigPaths : [],
Expand Down
Loading
Loading