Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(project-settings): local-over-shared resolver with per-key provenance

enes56f3713404c5
diff --git a/src/shared/project-settings.test.ts b/src/shared/project-settings.test.ts
index 2ec812aaa..230283c3a 100644
--- a/src/shared/project-settings.test.ts
+++ b/src/shared/project-settings.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest'
import {
parseProjectSettingsFile, sanitizeProjectSettingsDoc, sanitizeProjectLocalSettings,
- serializeProjectSettingsFile, sameProjectSettingsContent
+ serializeProjectSettingsFile, sameProjectSettingsContent, resolveProjectSettings
} from './project-settings'
describe('sanitizeProjectSettingsDoc', () => {
@@ -91,3 +91,31 @@ describe('serialize + content equality', () => {
expect(sameProjectSettingsContent(a, c)).toBe(false)
})
})
+
+describe('resolveProjectSettings', () => {
+ const shared = {
+ setup: { setupScript: 'npm ci', waitForSetup: true },
+ terminal: { shell: '/bin/bash', theme: 'dark' }
+ }
+ it('local wins per key; shared fills the rest with provenance', () => {
+ const r = resolveProjectSettings({ terminal: { shell: '/bin/fish' } }, shared)
+ expect(r.terminal.shell).toEqual({ value: '/bin/fish', source: 'local' })
+ expect(r.terminal.theme).toEqual({ value: 'dark', source: 'shared' })
+ expect(r.setup.setupScript).toEqual({ value: 'npm ci', source: 'shared' })
+ })
+ it('ignoreShared blanks a family without needing local values', () => {
+ const r = resolveProjectSettings({ ignoreShared: { setup: true } }, shared)
+ expect(r.setup).toEqual({})
+ expect(r.terminal.shell).toEqual({ value: '/bin/bash', source: 'shared' })
+ })
+ it('ignoreShared still lets a local value through', () => {
+ const r = resolveProjectSettings(
+ { setup: { setupScript: 'make' }, ignoreShared: { setup: true } }, shared)
+ expect(r.setup.setupScript).toEqual({ value: 'make', source: 'local' })
+ expect(r.setup.waitForSetup).toBeUndefined()
+ })
+ it('handles both sides undefined', () => {
+ expect(resolveProjectSettings(undefined, undefined)).toEqual(
+ { setup: {}, worktree: {}, agents: {}, terminal: {} })
+ })
+})
diff --git a/src/shared/project-settings.ts b/src/shared/project-settings.ts
index 33c0573d7..5d891256c 100644
--- a/src/shared/project-settings.ts
+++ b/src/shared/project-settings.ts
@@ -277,3 +277,46 @@ export function sameProjectSettingsContent(a: ProjectSettingsFileV1, b: ProjectS
const { rev: _revB, savedAt: _savedAtB, ...contentB } = b
return JSON.stringify(contentA) === JSON.stringify(contentB)
}
+
+export type ProjectSettingSource = 'local' | 'shared'
+export interface ResolvedProjectSetting<T> {
+ value: T
+ source: ProjectSettingSource
+}
+type R<T> = ResolvedProjectSetting<T>
+export interface ResolvedProjectSettings {
+ setup: { setupScript?: R<string>; archiveScript?: R<string>; waitForSetup?: R<boolean> }
+ worktree: { basePath?: R<string>; baseRef?: R<string>; sharedPaths?: R<string[]> }
+ agents: { defaultAgentId?: R<string>; launchCmd?: R<string>; env?: R<Record<string, string>> }
+ terminal: { shell?: R<string>; theme?: R<string>; fontFamily?: R<string> }
+}
+
+/**
+ * Local-over-shared, per key, with provenance — NOT global/default layering. Consumption sites
+ * apply `?? globalSetting` themselves on top of this (they know their own global); this function
+ * only decides between what THIS project's local and shared docs say. Walks the same
+ * `FAMILY_FIELDS` table the Task 1 sanitizer uses, so a field is still declared exactly once.
+ */
+export function resolveProjectSettings(
+ local: ProjectLocalSettings | undefined,
+ shared: ProjectSettingsDoc | undefined
+): ResolvedProjectSettings {
+ const out = { setup: {}, worktree: {}, agents: {}, terminal: {} } as ResolvedProjectSettings
+ for (const family of KNOWN_FAMILIES) {
+ const localFamily = local?.[family] as Record<string, unknown> | undefined
+ const sharedFamily = shared?.[family] as Record<string, unknown> | undefined
+ const ignoreThisFamily = local?.ignoreShared?.[family] === true
+ const target = out[family] as Record<string, unknown>
+ for (const key of Object.keys(FAMILY_FIELDS[family])) {
+ const localValue = localFamily?.[key]
+ if (localValue !== undefined) {
+ target[key] = { value: localValue, source: 'local' }
+ continue
+ }
+ if (ignoreThisFamily) continue
+ const sharedValue = sharedFamily?.[key]
+ if (sharedValue !== undefined) target[key] = { value: sharedValue, source: 'shared' }
+ }
+ }
+ return out
+}