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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(project-settings): location-keyed content-hash trust store
enesbe0dff2da869
diff --git a/src/core/project-trust-store.test.ts b/src/core/project-trust-store.test.tsnew file mode 100644index 000000000..2cfc53e1b--- /dev/null+++ b/src/core/project-trust-store.test.ts@@ -0,0 +1,62 @@+import { describe, it, expect, beforeEach, afterEach } from 'vitest'+import { promises as fs } from 'fs'+import os from 'os'+import path from 'path'+import { initPlatform, resetPlatformForTests } from './platform'+import { fakePlatform } from './platform-fake'+import { ProjectTrustStore, localTrustKey, sshTrustKey, hashTrustContent } from './project-trust-store'++let userData: string+beforeEach(async () => {+ userData = await fs.mkdtemp(path.join(os.tmpdir(), 'nt-trust-'))+ initPlatform(fakePlatform({ userDataDir: userData }))+})+afterEach(async () => { resetPlatformForTests(); await fs.rm(userData, { recursive: true, force: true }) })++describe('trust keys', () => {+ it('are location identities, distinct per kind and per folder', () => {+ expect(localTrustKey('/a/b')).not.toBe(localTrustKey('/a/c'))+ const ssh = sshTrustKey({ server: { host: 'h', user: 'u' }, remoteCwd: '/srv/x' })+ expect(ssh).toContain('u@h')+ expect(ssh).not.toBe(localTrustKey('/srv/x'))+ })+})++describe('ProjectTrustStore', () => {+ it('approval round-trips and survives a new store instance (persisted)', async () => {+ const key = localTrustKey('/proj')+ const hash = hashTrustContent('npm ci')+ const store = new ProjectTrustStore()+ expect(await store.isTrusted(key, 'setup', hash)).toBe(false)+ await store.record(key, 'setup', hash, '2026-08-19T00:00:00Z')+ expect(await store.isTrusted(key, 'setup', hash)).toBe(true)+ expect(await new ProjectTrustStore().isTrusted(key, 'setup', hash)).toBe(true)+ })+ it('changed content is NOT trusted; other families are independent', async () => {+ const key = localTrustKey('/proj')+ const store = new ProjectTrustStore()+ await store.record(key, 'setup', hashTrustContent('npm ci'), 't')+ expect(await store.isTrusted(key, 'setup', hashTrustContent('npm ci && evil'))).toBe(false)+ expect(await store.isTrusted(key, 'agents', hashTrustContent('npm ci'))).toBe(false)+ })+ it('revoke drops one family or the whole key', async () => {+ const key = localTrustKey('/proj')+ const h = hashTrustContent('x')+ const store = new ProjectTrustStore()+ await store.record(key, 'setup', h, 't')+ await store.record(key, 'shell', h, 't')+ await store.revoke(key, 'setup')+ expect(await store.isTrusted(key, 'setup', h)).toBe(false)+ expect(await store.isTrusted(key, 'shell', h)).toBe(true)+ await store.revoke(key)+ expect(await store.isTrusted(key, 'shell', h)).toBe(false)+ })+ it('a malformed trust file fails closed (empty store), then heals on next record', async () => {+ await fs.writeFile(path.join(userData, 'project-trust.json'), '{oops', 'utf-8')+ const store = new ProjectTrustStore()+ const key = localTrustKey('/proj')+ expect(await store.isTrusted(key, 'setup', hashTrustContent('x'))).toBe(false)+ await store.record(key, 'setup', hashTrustContent('x'), 't')+ expect(await new ProjectTrustStore().isTrusted(key, 'setup', hashTrustContent('x'))).toBe(true)+ })+})diff --git a/src/core/project-trust-store.ts b/src/core/project-trust-store.tsnew file mode 100644index 000000000..08be8523c--- /dev/null+++ b/src/core/project-trust-store.ts@@ -0,0 +1,99 @@+import { promises as fs } from 'fs'+import { createHash } from 'node:crypto'+import path from 'path'+import type { ProjectTrustFamily } from '../shared/project-settings'+import type { SshConnection } from '../shared/ssh'+import { sshHostKey } from '../shared/ssh'+import { platform } from './platform'+import { writeAtomic } from './workspace-store'++export interface ProjectTrustRecord {+ contentHash: string+ approvedAt: string+}++/** Location identity, NEVER a project id (ids are attacker-controlled — hostile-project-json). */+export function localTrustKey(cwd: string): string {+ return `local\0${path.resolve(cwd)}`+}++export function sshTrustKey(ssh: { server: Pick<SshConnection, 'host' | 'user'>; remoteCwd: string }): string {+ return `ssh\0${sshHostKey(ssh.server)}\0${ssh.remoteCwd}`+}++export function hashTrustContent(content: string): string {+ return createHash('sha256').update(content, 'utf-8').digest('hex')+}++type TrustFileEntry = Partial<Record<ProjectTrustFamily, ProjectTrustRecord>>+type TrustFile = Record<string, TrustFileEntry>++/**+ * File: {userData}/project-trust.json. Lazy-loaded, cached; malformed file → empty store (fail+ * closed — an unreadable trust record must never be read back as "trusted").+ *+ * `record`/`revoke` serialize through an internal promise chain: both are read-modify-write over+ * the same in-memory + on-disk store, and two overlapping calls racing the read half would let the+ * later write silently clobber the earlier one's change.+ */+export class ProjectTrustStore {+ private cache: TrustFile | null = null+ private chain: Promise<unknown> = Promise.resolve()++ private get filePath(): string {+ return path.join(platform().userDataDir, 'project-trust.json')+ }++ private async load(): Promise<TrustFile> {+ if (this.cache) return this.cache+ let raw: string+ try {+ raw = await fs.readFile(this.filePath, 'utf-8')+ } catch {+ this.cache = {}+ return this.cache+ }+ try {+ const parsed: unknown = JSON.parse(raw)+ this.cache = parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? (parsed as TrustFile) : {}+ } catch {+ this.cache = {}+ }+ return this.cache+ }++ async isTrusted(key: string, family: ProjectTrustFamily, contentHash: string): Promise<boolean> {+ const store = await this.load()+ return store[key]?.[family]?.contentHash === contentHash+ }++ async record(key: string, family: ProjectTrustFamily, contentHash: string, approvedAt: string): Promise<void> {+ return this.mutate((store) => {+ store[key] = { ...store[key], [family]: { contentHash, approvedAt } }+ })+ }++ async revoke(key: string, family?: ProjectTrustFamily): Promise<void> {+ return this.mutate((store) => {+ if (!store[key]) return+ if (!family) {+ delete store[key]+ return+ }+ const { [family]: _dropped, ...rest } = store[key]+ if (Object.keys(rest).length) store[key] = rest+ else delete store[key]+ })+ }++ private mutate(fn: (store: TrustFile) => void): Promise<void> {+ const run = this.chain.then(async () => {+ const store = await this.load()+ fn(store)+ this.cache = store+ await writeAtomic(this.filePath, JSON.stringify(store, null, 2))+ })+ this.chain = run.catch(() => {})+ return run+ }+}