The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(security): confine a plain cwd's folder trust to the projects root (OH-14)
0xken154d08eca3bcdb
diff --git a/cli/src/backendSocket.spec.ts b/cli/src/backendSocket.spec.tsindex 7b24ed320..3cf098ac5 100644--- a/cli/src/backendSocket.spec.ts+++ b/cli/src/backendSocket.spec.ts@@ -1,6 +1,6 @@import * as gitPullRequest from './lib/gitPullRequest.js'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'-import { readFileSync, mkdtempSync, writeFileSync, rmSync } from 'fs'+import { readFileSync, mkdirSync, mkdtempSync, writeFileSync, rmSync } from 'fs'import { homedir, tmpdir } from 'os'import { join } from 'path'import { fileURLToPath } from 'url'@@ -1213,17 +1213,20 @@ describe('BackendSocket outbound queue', () => {})it.each([- { name: 'an empty cwd (the desktop just made it)', contents: [] as string[], trusts: true },- { name: 'a cwd that already has something', contents: ['Makefile'], trusts: false },- ])('records Claude trust for $name when the daemon sees a plain cwd', async ({ contents, trusts }) => {- // A plain cwd on the LOCAL machine is the desktop opening a folder it just made empty; evidence is the- // readdir, never the client's word, so a folder with content (a clone, the person's own repo) stays- // the engine's question.- const dir = mkdtempSync(join(tmpdir(), 'harness-trust-'))+ { name: 'an empty workspace the app just made', contents: [] as string[], nested: false, trusts: true },+ { name: 'a workspace that already has something', contents: ['Makefile'], nested: false, trusts: false },+ { name: 'an empty folder outside the projects root', contents: [] as string[], nested: true, trusts: false },+ ])('records Claude trust for $name: $trusts', async ({ contents, nested, trusts }) => {+ // A plain cwd on the LOCAL machine is the desktop handing over a workspace it just made. Trust is+ // recorded only on evidence (the readdir) and only directly inside the projects root: trust inherits+ // downward, so an empty folder the person merely browsed to would cover everything cloned under it.+ const root = mkdtempSync(join(tmpdir(), 'harness-root-'))+ const dir = nested ? join(root, 'a', 'b') : join(root, 'workspace')+ mkdirSync(dir, { recursive: true })for (const item of contents) writeFileSync(join(dir, item), 'x')+ vi.spyOn(projectFolder, 'projectsRoot').mockReturnValue(root)const socket = new BackendSocket('token')- const frames: Array<Record<string, unknown>> = []- socket.registerLocalClient('local:cwd-trust', { sendFrame: (frame) => { frames.push(frame); return true }, sendBinary: () => true })+ socket.registerLocalClient('local:cwd-trust', { sendFrame: () => true, sendBinary: () => true })vi.mocked(claudeTrust.preTrustClaudeProject).mockClear()socket.onCreateAgent = vi.fn(async () => ({ ok: false as const, error: 'TMUX_UNAVAILABLE' }))try {@@ -1234,16 +1237,23 @@ describe('BackendSocket outbound queue', () => {} finally {await socket.unregisterLocalClient('local:cwd-trust')await socket.stop()- rmSync(dir, { recursive: true, force: true })+ rmSync(root, { recursive: true, force: true })}})- it('does NOT record Claude trust for an empty cwd from a relayed/E2EE frame', async () => {+ it('does NOT record Claude trust for an empty workspace named by a relayed frame', async () => {// agent_create is not backend-only, so a relay frame is E2EE-unwrapped and reaches the same pre-trust- // path. The LOCAL gate is what keeps it from recording trust for an arbitrary empty path on this host.- const dir = mkdtempSync(join(tmpdir(), 'harness-trust-'))+ // path. Everything else about this frame would qualify — the folder is empty AND in the projects root —+ // so the LOCAL gate is the only thing refusing it.+ const root = mkdtempSync(join(tmpdir(), 'harness-root-'))+ const dir = join(root, 'workspace')+ mkdirSync(dir)+ vi.spyOn(projectFolder, 'projectsRoot').mockReturnValue(root)const socket = new BackendSocket('token')- const internals = socket as any+ const internals = socket as unknown as {+ e2ee: { unwrapDown: (connId: string, frame: unknown) => unknown }+ dispatchDown: (frame: unknown, connId: string, transport: string) => Promise<void>+ }vi.spyOn(internals.e2ee, 'unwrapDown').mockReturnValue({type: 'agent_create', payload: { requestId: 'r', creationId: randomUUID(), engine: 'claude', cwd: dir },})@@ -1251,12 +1261,12 @@ describe('BackendSocket outbound queue', () => {socket.onCreateAgent = vi.fn(async () => ({ ok: false as const, error: 'TMUX_UNAVAILABLE' }))try {await internals.dispatchDown({ type: 'agent_create', payload: { __e2e: { v: 1, k: 'p', n: 1, ct: 'fixture' } } }, 'web-1', 'relay')+ // The create ran, so the pre-trust branch was reached and declined — not skipped earlier by the gate.await vi.waitFor(() => expect(socket.onCreateAgent).toHaveBeenCalled())- // onCreateAgent ran, so the pre-trust path executed — but a relay frame is not local: no trust recorded.expect(claudeTrust.preTrustClaudeProject).not.toHaveBeenCalled()} finally {await socket.stop()- rmSync(dir, { recursive: true, force: true })+ rmSync(root, { recursive: true, force: true })}})diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.tsindex a8f938e48..faf9869ca 100644--- a/cli/src/backendSocket.ts+++ b/cli/src/backendSocket.ts@@ -22,7 +22,7 @@ import type { AutonomousDeviceService, AutonomousDeviceFrame } from './lib/autonimport { WebSocket } from 'ws'import { watchSocketLiveness, type LivenessWatch } from './lib/wsLiveness.js'import { stat, readFile, readdir } from 'fs/promises'-import { isAbsolute, join } from 'path'+import { dirname, isAbsolute, join } from 'path'import { hostname, homedir } from 'os'import { env } from './config/env.js'import { AuthSessionManager, AuthSessionError } from './lib/authSession.js'@@ -49,7 +49,7 @@ import { probeEngines } from './lib/engineProbe.js'import { readMachineResources } from './lib/machineResources.js'import { AgentCreationReceipts, AgentCreationReceiptError, creationFingerprint, validCreationId, type AgentCreationStatus } from './lib/agentCreationReceipt.js'import { engineInstallRecipe } from './lib/engineInstall.js'-import { parseProjectFolder, prepareProjectFolder, ProjectFolderError } from './lib/projectFolder.js'+import { parseProjectFolder, prepareProjectFolder, projectsRoot, ProjectFolderError } from './lib/projectFolder.js'import { claudeTrusts, codexTrusts, preTrustClaudeProject, preTrustCodexProject } from './lib/claudeTrust.js'import { projectPreview } from './lib/projectPreview.js'import { readGitProject } from './lib/gitProject.js'@@ -2375,20 +2375,26 @@ export class BackendSocket {engineTrust.record(preparedFolder)}} catch (error) { console.warn(`[agent] pre-trust ${preparedFolder} · ${error instanceof Error ? error.message : error}`) }- } else if (!dsh && local) {- // A plain cwd on the LOCAL machine is the desktop opening a NEW folder: the desktop made it- // empty and hands the path over, it has nothing in it to review, so it is trusted the way a- // `new` project is. The LOCAL gate is the boundary — agent_create is not backend-only, so a- // relayed/E2EE frame would otherwise name any empty path on this host and get it trusted.- // A clone / the person's own repo is never empty (lib/claudeTrust.ts), and evidence beats a- // client's word, so this readdir is the gate. DSH trust is decided in cli.ts where the- // template count is known; leave that to it.+ } else if (!dsh && local && dirname(input.cwd) === projectsRoot()) {+ // On the LOCAL machine the desktop makes a new workspace ITSELF and sends the path as a plain+ // cwd, so `projectFolder` above never sees it. Such a folder is empty and is trusted the way a+ // `new` project is — but only on evidence, and only where those workspaces live:+ //+ // · directly inside the projects root, which is the one folder the app and this daemon+ // create workspaces in. Trust INHERITS downward (claudeTrusts), so recording it for a+ // folder the person merely browsed to — an empty `~/code`, or a home with nothing in it —+ // would silently cover every repo cloned under it later: OH-14 again by another door.+ // · empty as read from disk, never on the client's word. A clone, a worktree or the+ // person's own repo has content, so it stays the engine's question (lib/claudeTrust.ts).+ // · from a LOCAL frame. agent_create is not backend-only, so a relayed peer would otherwise+ // name an empty path on this host and have it trusted.+ //+ // DSH trust is decided in cli.ts, where the template count is known; leave that to it.try {const empty = await readdir(input.cwd).then((names) => names.length === 0, () => false)if (empty) {- const engineTrust = input.engine === 'claude' ? { record: preTrustClaudeProject }- : input.engine === 'codex' ? { record: preTrustCodexProject } : null- if (engineTrust) engineTrust.record(input.cwd)+ if (input.engine === 'claude') preTrustClaudeProject(input.cwd)+ if (input.engine === 'codex') preTrustCodexProject(input.cwd)}} catch (error) { console.warn(`[agent] pre-trust ${input.cwd} · ${error instanceof Error ? error.message : error}`) }}diff --git a/cli/src/lib/projectFolder.ts b/cli/src/lib/projectFolder.tsindex 8392bf0ad..e0dccbf31 100644--- a/cli/src/lib/projectFolder.ts+++ b/cli/src/lib/projectFolder.ts@@ -11,6 +11,12 @@ export type ProjectFolder = { source: 'new'; name?: string } | { source: 'remote| { source: 'worktree'; gitSource: string; branchRef?: string; branchName?: string; existingBranch?: boolean; placeholder?: boolean }| { source: 'branch'; gitSource: string; branchRef?: string; branchName?: string }+/** Where this daemon and the desktop app put the workspaces they make. A folder directly inside it is+ * one of those; anywhere else is a folder the person chose and answers for themselves. */+export function projectsRoot(home = homedir()): string {+ return join(home, 'harnesses')+}+export class ProjectFolderError extends Error {constructor(readonly code: string, message: string) { super(message) }}@@ -89,7 +95,7 @@ export async function prepareProjectFolder(now?: () => Date} = {},): Promise<string> {- const root = options.root ?? join(homedir(), 'harnesses')+ const root = options.root ?? projectsRoot()let staging: string | undefinedtry {if (project.source === 'worktree' || project.source === 'branch') {