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
CLI: Team-written folder trust leaves with its worktree, and never on the main checkout (#4353) (#3498)
0xken1526fb1b8dfd5d
diff --git a/cli/src/engines/kit/folderTrust.spec.ts b/cli/src/engines/kit/folderTrust.spec.tsindex 7f9ab5089..d649a858d 100644--- a/cli/src/engines/kit/folderTrust.spec.ts+++ b/cli/src/engines/kit/folderTrust.spec.ts@@ -5,7 +5,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'import { launchClaudeConfigDir, launchCodexHome } from '../../lib/engineHomes.js'import { launch as claude } from '../claude/launch.js'import { launch as codex } from '../codex/launch.js'-import { recordTrustIn, trustsIn } from './folderTrust.js'+import { forgetTrustIn, recordTrustIn, trustsIn } from './folderTrust.js'/** Whether this account may link to a file: Windows lets it only with Developer Mode or as an administrator (Window of Tim,* #3815), and a person there with neither has no such link to write through. */@@ -92,6 +92,60 @@ describe('preTrustClaudeProject', () => {})})+// Task #4353: the trust a Team-written start saved for its worktree goes with that worktree, and nothing else does.+describe('forgetTrustIn', () => {+ it('clears the trust flag of that one folder and keeps every other key of the file', () => {+ const home = mkdtempSync(join(tmpdir(), 'forget-'))+ const file = join(home, '.claude.json')+ try {+ writeFileSync(file, JSON.stringify({ userID: 'u', projects: {+ '/repo': { hasTrustDialogAccepted: true, allowedTools: ['Bash'] },+ '/repo/worktree': { hasTrustDialogAccepted: true, allowedTools: [], lastCost: 1 },+ '/other': { hasTrustDialogAccepted: true } } }, null, 2))+ expect(forgetTrustIn(claude.trust!, file, '/repo/worktree')).toBe('forgotten')+ expect(JSON.parse(readFileSync(file, 'utf8'))).toEqual({ userID: 'u', projects: {+ '/repo': { hasTrustDialogAccepted: true, allowedTools: ['Bash'] },+ '/repo/worktree': { allowedTools: [], lastCost: 1 },+ '/other': { hasTrustDialogAccepted: true } } })+ // Nothing left to clear: the file is not written again.+ const before = readFileSync(file, 'utf8')+ expect(forgetTrustIn(claude.trust!, file, '/repo/worktree')).toBe('absent')+ expect(forgetTrustIn(claude.trust!, file, '/never')).toBe('absent')+ expect(readFileSync(file, 'utf8')).toBe(before)+ } finally { rmSync(home, { recursive: true, force: true }) }+ })++ it('leaves a file that is missing, unreadable or not the engine\'s shape as it is, and skips a TOML engine', () => {+ const home = mkdtempSync(join(tmpdir(), 'forget-'))+ const file = join(home, '.claude.json')+ try {+ expect(forgetTrustIn(claude.trust!, file, '/w')).toBe('skipped')+ expect(readdirSync(home)).toEqual([])+ for (const text of ['{not json', '[]', '{"projects":[]}', '{"projects":{"/w":"yes"}}']) {+ writeFileSync(file, text)+ expect(forgetTrustIn(claude.trust!, file, '/w')).toBe('skipped')+ expect(readFileSync(file, 'utf8')).toBe(text)+ }+ const toml = join(home, 'config.toml'), config = '[projects."/w"]\ntrust_level = "trusted"\n'+ writeFileSync(toml, config)+ expect(forgetTrustIn(codex.trust!, toml, '/w')).toBe('skipped')+ expect(readFileSync(toml, 'utf8')).toBe(config)+ } finally { rmSync(home, { recursive: true, force: true }) }+ })++ it.skipIf(!canLinkFiles)('writes through a linked settings file, keeping the link', () => {+ const home = mkdtempSync(join(tmpdir(), 'forget-'))+ try {+ const real = join(home, 'dotfiles.json'), file = join(home, '.claude.json')+ writeFileSync(real, JSON.stringify({ projects: { '/w': { hasTrustDialogAccepted: true } } }))+ symlinkSync(real, file, 'file')+ expect(forgetTrustIn(claude.trust!, file, '/w')).toBe('forgotten')+ expect(lstatSync(file).isSymbolicLink()).toBe(true)+ expect(JSON.parse(readFileSync(real, 'utf8'))).toEqual({ projects: { '/w': {} } })+ } finally { rmSync(home, { recursive: true, force: true }) }+ })+})+describe('preTrustCodexProject', () => {const codexHome = (config?: string): string => {const home = mkdtempSync(join(tmpdir(), 'trust-'))diff --git a/cli/src/engines/kit/folderTrust.ts b/cli/src/engines/kit/folderTrust.tsindex af5982e88..af57ef2e5 100644--- a/cli/src/engines/kit/folderTrust.ts+++ b/cli/src/engines/kit/folderTrust.ts@@ -15,8 +15,8 @@* The callers decide (core/agents/create.ts, launches.ts). A worktree only inherits the answer its source* repo already has.*- * Only ever ADDS trust, never removes anything, and does nothing when the engine has never run here (no- * file), when the file does not parse, or when it already says yes.+ * Recording only ever ADDS trust, and does nothing when the engine has never run here (no file), when the file does not+ * parse, or when it already says yes. The one removal is `forgetTrustIn`: the flag of a folder Harness made and is deleting.*/import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from 'node:fs'import { dirname, posix, win32 } from 'node:path'@@ -37,6 +37,30 @@ export function recordTrustIn(trust: TrustContract, file: string, cwd: string, oreturn trust.format === 'json' ? recordJson(trust, file, cwd, options.create === true) : recordToml(trust, file, cwd)}+/**+ * Clears the trust flag of `path` itself, and only it, when Harness deletes a folder whose trust it saved: a Team-written+ * start's worktree (superTabs/machines.ts, task #4353). Its folder was new at that start, so the flag was saved in its life;+ * the person's own answers are under other keys (its repository, a folder above it) and stay. The rest of its entry stays+ * too. One atomic write; a file it cannot read as the engine's shape is left as it is. JSON engines only: a Codex start of+ * this kind runs in an engine home of its own.+ */+export function forgetTrustIn(trust: TrustContract, file: string, path: string): 'forgotten' | 'absent' | 'skipped' {+ if (trust.format !== 'json' || !existsSync(file)) return 'skipped'+ let config: unknown+ try { config = JSON.parse(readFileSync(file, 'utf8')) } catch { return 'skipped' }+ if (!isPlainObject(config)) return 'skipped'+ const projects = config[trust.projects]+ if (projects === undefined) return 'absent'+ if (!isPlainObject(projects)) return 'skipped'+ const entry = projects[path]+ if (entry === undefined) return 'absent'+ if (!isPlainObject(entry)) return 'skipped'+ if (!(trust.accepted in entry)) return 'absent'+ delete entry[trust.accepted]+ replaceConfigFile(file, JSON.stringify(config, null, 2))+ return 'forgotten'+}+/** A folder as this platform compares it. DESKTOP-0TFH0OJ, 2026-10-23: a Swarm worktree's source came as* `C:\…\<tab>/<project>` (the Lead joins with "/") and its trust was recorded as `C:\…\<tab>\<project>`; compared as* text, every Swarm start on Windows stopped at the engine's trust prompt. On Windows any separator and any case is thediff --git a/cli/src/engines/launchPrep.ts b/cli/src/engines/launchPrep.tsindex a53830c6a..b9d80418f 100644--- a/cli/src/engines/launchPrep.ts+++ b/cli/src/engines/launchPrep.ts@@ -8,7 +8,7 @@import { join } from 'node:path'import { homeRoots, launchHomeOf } from '../lib/engineHomes.js'import { homeIsNetworkOrDevice } from './kit/homeAdoption.js'-import { recordTrustIn, trustsIn } from './kit/folderTrust.js'+import { forgetTrustIn, recordTrustIn, trustsIn } from './kit/folderTrust.js'import { recordInheritedMcp } from './kit/inheritedMcp.js'import { repairHistory } from './kit/resumeRepair.js'import { launchContract } from './launches.js'@@ -21,6 +21,8 @@ export interface FolderTrust {/** Record trust in `path`: never removes anything, and leaves a file it cannot safely extend alone. `create`: also on a* computer where the engine never ran, making the file (a JSON one) with this folder alone. */record(path: string, options?: { create?: boolean }): 'trusted' | 'already' | 'skipped'+ /** Clear the trust flag of `path` itself, for a folder Harness made and is deleting (kit/folderTrust.ts `forgetTrustIn`). */+ forget(path: string): 'forgotten' | 'absent' | 'skipped'}/**@@ -52,6 +54,7 @@ export function folderTrust(engine: AgentEngine, profile?: string | null, enviro}return recorded},+ forget: (path) => network() ? 'skipped' : forgetTrustIn(trust, file(), path),}}diff --git a/cli/src/superTabs/machines.spec.ts b/cli/src/superTabs/machines.spec.tsindex 57ed11ea4..0ff91653e 100644--- a/cli/src/superTabs/machines.spec.ts+++ b/cli/src/superTabs/machines.spec.ts@@ -2111,6 +2111,71 @@ describe('removed machine cleanup', () => {writeFileSync(file, JSON.stringify({ ...saved, worktrees: [...saved.worktrees, row] }))}+ // Task #4353: a Team-written start saved Claude trust for its worktree in the person's own settings, so it did not stall at+ // the trust question. That trust goes with the worktree, and nothing else in the file does: the person's own answer for+ // the repository stays.+ describe('the trust a Team-written start saved', () => {+ const trustFile = (m: ReturnType<typeof machine>) => join(m.home, '.claude.json')+ const saveTrust = (m: ReturnType<typeof machine>, folders: string[]) => writeFileSync(trustFile(m), JSON.stringify({ userID: 'u',+ projects: Object.fromEntries(folders.map(folder => [folder, { hasTrustDialogAccepted: true, allowedTools: [] }])) }, null, 2))+ const trusted = (m: ReturnType<typeof machine>) => Object.entries(JSON.parse(readFileSync(trustFile(m), 'utf8')).projects as Record<string, { hasTrustDialogAccepted?: boolean }>)+ .filter(([, entry]) => entry.hasTrustDialogAccepted === true).map(([folder]) => folder).sort()+ const markTeamWritten = (m: ReturnType<typeof machine>) => {+ const file = swarmWorktreesFile(m.data, 'host'), saved = JSON.parse(readFileSync(file, 'utf8'))+ writeFileSync(file, JSON.stringify({ ...saved, worktrees: saved.worktrees.map((w: { startId: string }) => w.startId === 'recorded' ? { ...w, teamWritten: true } : w) }))+ }+ const removable = (m: ReturnType<typeof machine>) => {+ m.setLive([])+ rmSync(join(m.recorded, 'unpushed.txt'))+ git(m.clone, 'config', 'branch.super-tab/recorded.harness', 'placeholder')+ }++ it('is cleared when its stopped worker\'s worktree goes, and kept while the worktree stays', async () => {+ const m = machine()+ markTeamWritten(m)+ saveTrust(m, [m.recorded, m.clone])+ const host = m.open()+ // Its session still runs there: the worktree stays, and so does its trust.+ await host.removeStoppedWorktree('tab', 'h-recorded')+ expect(trusted(m)).toEqual([m.clone, m.recorded].sort())+ removable(m)+ await host.removeStoppedWorktree('tab', 'h-recorded')+ expect(existsSync(m.recorded)).toBe(false)+ expect(trusted(m)).toEqual([m.clone])+ const saved = JSON.parse(readFileSync(trustFile(m), 'utf8'))+ expect(saved.userID).toBe('u')+ expect(saved.projects[m.recorded]).toEqual({ allowedTools: [] })+ })++ it('is cleared when its worktree folder is already gone', async () => {+ const m = machine()+ markTeamWritten(m)+ saveTrust(m, [m.recorded, m.clone])+ m.setLive([])+ rmSync(m.recorded, { recursive: true, force: true })+ await m.open().removeStoppedWorktree('tab', 'h-recorded')+ expect(trusted(m)).toEqual([m.clone])+ })++ it('is cleared when the machine leaves the Swarm, for a recorded worktree and one known from its start', async () => {+ const m = machine()+ markTeamWritten(m)+ Object.assign(m.starts[0].request, { projectSettings: 'off' })+ saveTrust(m, [m.recorded, m.earlier, m.unproven, m.own])+ await m.open().clean('tab', 'removal')+ expect(trusted(m)).toEqual([m.own, m.unproven].sort())+ })++ it('leaves a normal start\'s trust as it was', async () => {+ const m = machine()+ saveTrust(m, [m.recorded])+ removable(m)+ await m.open().removeStoppedWorktree('tab', 'h-recorded')+ expect(existsSync(m.recorded)).toBe(false)+ expect(trusted(m)).toEqual([m.recorded])+ })+ })+// Diego, 10-30: a worktree folder deleted by hand kept its record for good, so every later stop tried it again.it('drops the record of a stopped worker whose worktree folder is gone, and keeps every other record', async () => {const m = machine()@@ -2550,6 +2615,21 @@ describe('removed machine cleanup', () => {expect(backend.mock.calls.some(c => JSON.stringify(c[3] ?? '').includes('agent.startSettled'))).toBe(true)})+ // Task #4353: its removal clears the trust a Team-written start saved, so the record says which start it was.+ it('marks the worktree of a Team-written start', async () => {+ const root = mkdtempSync(join(tmpdir(), 'swarm-record-')); roots.push(root)+ const core = fakeCore({ dataDir: root, agents: { byAgent: vi.fn(id => id === 'h-new' ? session('h-new', '/worktrees/project/new', 'agent') : undefined) } })+ const pool = { tabId: 'tab', machine: { machineId: 'host', generation: 'grant', cwd: '/repo', engines: ['claude'], paused: false },+ harnessIds: [], starts: [{ id: 'new', dispatched: true, request: { worktree: true, cwd: '/clone', projectSettings: 'off' } }], paused: false }+ const backend = vi.fn(async (_core: unknown, _method: string, path: string, _body?: unknown): Promise<unknown> => path.includes('/hosts/host/changes') ? hostForm([], { pools: [pool] }) : { revision: 1 })+ const open = vi.fn(async () => ({ machineId: 'host', request: vi.fn(async () => ({})), close: vi.fn() }))+ const start = vi.fn(async () => ({ ok: true, harnessId: 'h-new' }))+ await new ContributedMachines(core, 'host', { backend, open, start, now: () => 0,+ capabilities: vi.fn(async () => ({ ok: true, resources: {}, tools: {} })) } as never).tick()+ expect(JSON.parse(readFileSync(swarmWorktreesFile(root, 'host'), 'utf8')).worktrees).toEqual([+ { tabId: 'tab', startId: 'new', harnessId: 'h-new', source: '/clone', path: '/worktrees/project/new', teamWritten: true }])+ })+// Scholes, 2026-10-30: work is assigned only after the settle, so the settle carries the model the start saw.it('settles with what the agent runs, and without it on a backend that refuses the field', async () => {const reading = { engine: 'codex', model: 'gpt-6.1-sol', effort: 'auto', contextWindow: null, engineVersion: '0.165.0' }diff --git a/cli/src/superTabs/machines.ts b/cli/src/superTabs/machines.tsindex 2bb3a7b40..c85cdec4e 100644--- a/cli/src/superTabs/machines.ts+++ b/cli/src/superTabs/machines.ts@@ -29,6 +29,7 @@ import { cleanupClosed } from './cleanupCloses.js'import { listClaudeProfiles, codexReportLabel, profileId } from '../lib/claudeProfiles.js'import { defaultCodexHome, listCodexProfiles } from '../lib/codexProfiles.js'import { usageTarget, validModelTokens, validUsageTarget, type ModelTokens } from '../lib/agentUsageWire.js'+import { folderTrust } from '../engines/launchPrep.js'const finite = (v: unknown) => typeof v === 'number' && Number.isFinite(v) ? v : nullconst list = (v: unknown) => Array.isArray(v) ? v.map(object) : []@@ -80,7 +81,8 @@ const POOLS_FRESH_MS = 2_000/** The worktrees this machine's Swarm starts made, by tab: what a removal may delete besides the tab's Swarm folders. */export const swarmWorktreesFile = (dataDir: string, machineId: string) => join(dataDir, 'super-tabs', `swarm-worktrees-${machineId}.json`)/** `kind: 'agent-folder'`: a folder Harness made for an agent whose start named a temporary one (agentFolder.ts, #3713). */-type SwarmWorktree = { tabId: string; startId: string; harnessId: string; source: string; path: string; kind?: 'agent-folder' }+/** `teamWritten`: a Team-written start's (task #4353), whose removal also clears the folder trust it saved. */+type SwarmWorktree = { tabId: string; startId: string; harnessId: string; source: string; path: string; kind?: 'agent-folder'; teamWritten?: true }function readWorktrees(file: string): SwarmWorktree[] {let saved: unknowntry { saved = JSON.parse(readFileSync(file, 'utf8')) } catch { return [] }@@ -1112,11 +1114,11 @@ export class ContributedMachines {if (!record) return// Diego, 10-30: a folder deleted by hand kept its record for good, and every later stop tried it again. Only a folder// that is not there drops it; one that cannot be read for any other reason keeps it. Nothing on disk is touched.- if (await folderGone(record.path)) return writeWorktrees(file, readWorktrees(file).filter(w => !mine(w)))+ if (await folderGone(record.path)) return this.removed(file, record, mine)if (record.kind === 'agent-folder') return this.removeAgentFolder(file, record, mine)if (!await swarmWorktree(record.path, record.source, record.startId)) {// The record no longer proves this belongs to Harness. Keep it; never loosen the proof to recover it.- if (await folderGone(record.path)) return writeWorktrees(file, readWorktrees(file).filter(w => !mine(w)))+ if (await folderGone(record.path)) return this.removed(file, record, mine)this.log('Kept a Swarm worktree: WORKTREE_UNPROVEN')return}@@ -1132,9 +1134,26 @@ export class ContributedMachines {if (!await sweepOne(record.path, Date.now(), 0, unused).catch(error => {this.log(`Kept a Swarm worktree: ${error instanceof WorktreeKept ? error.code : 'WORKTREE_CHECK_FAILED'}`); return false})) return+ this.removed(file, record, mine)+ }++ /** A worktree gone: its record goes, and so does the folder trust a Team-written start saved for it. */+ private removed(file: string, record: SwarmWorktree, mine: (w: SwarmWorktree) => boolean) {+ if (record.teamWritten) this.forgetTrust(record.path)writeWorktrees(file, readWorktrees(file).filter(w => !mine(w)))}+ /**+ * Clears the Claude folder trust a Team-written start saved for its worktree (core/agents/launches.ts `swarmCheckout`),+ * now that the worktree is gone (task #4353). Left, the person's later Claude sessions in that folder would load the+ * branch's own settings and hooks without asking. The folder was new at that start, so its flag was saved in its life; the+ * person's own answers (its repository, a folder above it) are other keys and stay. The same home the start saved it in.+ */+ private forgetTrust(path: string) {+ try { folderTrust('claude')?.forget(path) }+ catch (error) { this.log(`Could not clear the folder trust of a Team-written worktree: ${(error as NodeJS.ErrnoException).code ?? 'TRUST_WRITE_FAILED'}`) }+ }+/** An agent's own folder (#3713), only when it is still the one Harness made and marked in its agent-home folder, and no* session, live or paused, works in it: it holds nothing but that agent's own work. A record that no longer proves that* is kept, its folder untouched; the log names no path. */@@ -1158,7 +1177,7 @@ export class ContributedMachines {try {const file = swarmWorktreesFile(this.core.dataDir, this.machineId), worktrees = readWorktrees(file)if (!worktrees.some(w => w.tabId === tabId && w.startId === startId)) writeWorktrees(file, [...worktrees, { tabId, startId, harnessId,- source: request.cwd, path, ...(agentFolder ? { kind: 'agent-folder' as const } : {}) }])+ source: request.cwd, path, ...(agentFolder ? { kind: 'agent-folder' as const } : {}), ...(request.projectSettings === 'off' ? { teamWritten: true as const } : {}) }])} catch (error) { this.log(`Could not record the worktree of Swarm start ${startId}: ${error instanceof Error ? error.message : String(error)}`) }}private log(message: string) { (this.deps.log ?? (line => console.warn(`[super-tabs] ${line}`)))(message) }@@ -1239,7 +1258,7 @@ export class ContributedMachines {const swarm = new Set(recorded.map(w => w.harnessId))/** Each Swarm start's receipt on this machine, by the agent it names: what lets the core close one its host no longer retains. */const receipts = new Map<string, string>()- const candidates = recorded.map(w => ({ source: w.source, path: w.path, startId: w.startId, proven: true }))+ const candidates = recorded.map(w => ({ source: w.source, path: w.path, startId: w.startId, proven: true, teamWritten: w.teamWritten === true }))for (const start of starts) {const request = object(start.request)if (request.machineId !== this.machineId || !identifier(start.id) || !identifier(start.harnessId) || !identifier(start.creationId)) continue@@ -1248,7 +1267,8 @@ export class ContributedMachines {if (proven) { swarm.add(start.harnessId); receipts.set(start.harnessId, start.creationId) }const agent = this.core.agents.all().find(a => a.agentId === start.harnessId)if (request.worktree === true && typeof request.cwd === 'string' && agent?.cwd && !candidates.some(c => c.path === agent.cwd)) {- candidates.push({ source: request.cwd, path: agent.cwd, startId: start.id, proven: proven && agent.startedBy === 'agent' })+ candidates.push({ source: request.cwd, path: agent.cwd, startId: start.id, proven: proven && agent.startedBy === 'agent',+ teamWritten: request.projectSettings === 'off' })}}const worktrees: string[] = []@@ -1282,10 +1302,11 @@ export class ContributedMachines {kept.add(basename(target)); continue}if (addedAgain(await read())) return- const source = candidates.find(c => c.path === target)?.source+ const candidate = candidates.find(c => c.path === target)// git forgets the worktree in its repository too; a folder it refuses (a submodule, a lock) is deleted as a folder.- if (source) await git(source, ['worktree', 'remove', '--force', target]).catch(() => null)+ if (candidate) await git(candidate.source, ['worktree', 'remove', '--force', target]).catch(() => null)await rm(target, { recursive: true, force: true })+ if (candidate?.teamWritten) this.forgetTrust(target)}// Diego 10-29: a folder kept for a live session was confirmed cleaned anyway and its records dropped, so nothing ever// tried it again. Unconfirmed, the cleanup row stays and the next try comes on clean()'s backoff.diff --git a/cli/src/superTabs/start.spec.ts b/cli/src/superTabs/start.spec.tsindex a7e3f82e0..da85df99f 100644--- a/cli/src/superTabs/start.spec.ts+++ b/cli/src/superTabs/start.spec.ts@@ -7,7 +7,7 @@ import { buddyOwnerFile, buddyOwnerOf } from '../lib/buddyGuard.js'import { worktreeFolderName } from '../lib/agentNames.js'import { env } from '../config/env.js'import { homedir, tmpdir } from 'node:os'-import { BUDDY_CLAUDE_SIGNED_OUT, BUDDY_NOT_OWN_MACHINE, HEAVY_NOT_RECORDED, HEAVY_REFUSED, inspectCapacity, MODEL_REPORT_WAIT_MS, startAgent, TEAM_WRITTEN_CLAUDE_ONLY } from './start.js'+import { BUDDY_CLAUDE_SIGNED_OUT, BUDDY_NOT_OWN_MACHINE, HEAVY_NOT_RECORDED, HEAVY_REFUSED, inspectCapacity, MODEL_REPORT_WAIT_MS, startAgent, TEAM_WRITTEN_CLAUDE_ONLY, TEAM_WRITTEN_WORKTREE_ONLY } from './start.js'import { buildEngineCommandArgv } from '../lib/engineLaunch.js'import { readCapacityDisk } from './disk.js'import { SuperTabHostError } from './wire.js'@@ -241,6 +241,16 @@ describe('Swarm permission mode', () => {expect(existsSync(join(homedir(), PM_HOMES, f.start.creationId))).toBe(false)})+ // Task #4353: its Claude trust is saved for the folder it runs in and cleared with the worktree Harness made for it. The+ // owner's main checkout is neither Harness's to trust for it nor to delete, so it never runs there.+ it('refuses Team-written work that names no worktree, the owner\'s main checkout, before anything is made', async () => {+ const f = fixture()+ Object.assign(f.start.request, { engine: 'claude', projectSettings: 'off', worktree: false, cwd: '/repo' })+ expect(await startAgent({ action: 'resume', tabId: 'tab', startId: 'start' }, f.scoped, where, f.open)).toMatchObject({ error: 'START_FAILED', detail: TEAM_WRITTEN_WORKTREE_ONLY })+ expect(f.request.mock.calls.some(c => c[0] === 'agent_create')).toBe(false)+ expect(f.start.error).toContain('worktree')+ })+it('gives a normal Codex start no engine home of its own', async () => {const f = fixture()Object.assign(f.start.request, { engine: 'codex' })diff --git a/cli/src/superTabs/start.ts b/cli/src/superTabs/start.tsindex 736c2c8fb..cc95fee8f 100644--- a/cli/src/superTabs/start.ts+++ b/cli/src/superTabs/start.ts@@ -24,6 +24,8 @@ const number = (v: unknown) => typeof v === 'number' && Number.isFinite(v) ? v :// unknown failures deliberately stay uncertain: they cannot prove no launch./** Why Team-written work starts only on Claude Code off a Team daemon (task #4307). */export const TEAM_WRITTEN_CLAUDE_ONLY = 'A Harness Team agent wrote this task\'s code, so on this computer it runs only on Claude Code, which keeps the branch\'s own settings out. Codex would need a sign-in of its own for that, which Harness never makes from yours. Choose Claude Code for this task.'+/** Why Team-written work starts only in a worktree Harness makes for it (task #4353). */+export const TEAM_WRITTEN_WORKTREE_ONLY = 'A Harness Team agent wrote this task\'s code, so on this computer it runs only in a worktree Harness makes for it and removes with it, never in the project\'s own checkout. Start it with a worktree.'const PRE_DISPATCH_REFUSALS = new Set(['INVALID_ENGINE', 'INVALID_CWD', 'INVALID_PROJECT_SOURCE', 'INVALID_REPOSITORY','INVALID_GRID', 'INVALID_CODEX_HOME', 'INVALID_DSH', 'INVALID_PROMPT',@@ -392,6 +394,12 @@ async function startOnce(input: Json, scoped: ScopedRequest, where: Where, open:requireSuccess(await scoped({ action: 'command', operationId: `refused-${startId}`, command: { type: 'agent.startFailed', startId, error: TEAM_WRITTEN_CLAUDE_ONLY } }))return { error: 'START_FAILED', startId, detail: TEAM_WRITTEN_CLAUDE_ONLY }}+ // Its Claude trust is saved for the folder it runs in and cleared when Harness removes its worktree (machines.ts, task+ // #4353). The owner's main checkout is neither Harness's to trust for it nor to remove: refused there.+ if (projectSettingsOff && !team && request.worktree !== true) {+ requireSuccess(await scoped({ action: 'command', operationId: `refused-${startId}`, command: { type: 'agent.startFailed', startId, error: TEAM_WRITTEN_WORKTREE_ONLY } }))+ return { error: 'START_FAILED', startId, detail: TEAM_WRITTEN_WORKTREE_ONLY }+ }// Both direct and contributed-host starts reach this boundary. Existing// native receipts are read above and never have their permissions changed.// Engines without a full mode retain their existing approving launch flags.diff --git a/docs/plans/2026-11-07-team-written-trust-cleanup-plan.md b/docs/plans/2026-11-07-team-written-trust-cleanup-plan.mdnew file mode 100644index 000000000..c91ec5b36--- /dev/null+++ b/docs/plans/2026-11-07-team-written-trust-cleanup-plan.md@@ -0,0 +1,62 @@+# Team-written trust leaves with its worktree Plan++**Goal:** The Claude folder trust a Team-written start saves in the person's own Claude settings is removed when Harness+removes that start's worktree, and a Team-written start never runs, so never saves trust, in the owner's main checkout+(task #4353, follow-up of #4307 / PR #3485).++**Architecture:** A Team-written Claude start saves trust only for the worktree Harness made for it+(`core/agents/launches.ts` `swarmCheckout`), a path that did not exist before the start, so any trust entry for that exact+path was saved during its life. The person's own answers live under other keys (the main repository, a folder above it),+and are never touched. `cli/src/superTabs/machines.ts` marks a Team-written start's worktree record, and wherever it+removes that worktree (a stopped worker, a folder already gone, a machine removed from the Swarm) it clears the trust flag of+that exact path, with one atomic write of the settings file (`engines/kit/folderTrust.ts` `forgetTrustIn`). A+Team-written start that names no worktree (the owner's main checkout) is refused in `cli/src/superTabs/start.ts` before+anything is made, saying why.++**Tech Stack:** TypeScript, Node `fs`, vitest.++**Spec:** the task brief of #4353.++This plan is implemented by its Engineer, task by task, test first.++## Global Constraints++- CLI only. Never read or copy a Claude login or credential.+- Change only the one trust flag Harness saved, for that exact folder, written atomically through `replaceConfigFile`.+- No other start or removal path changes.++## Review Focus++- Only the flag of the removed worktree's exact path is cleared; a person's earlier trust (main repository, parent folder)+ stays; no other key of the settings file changes; the write is atomic.+- A Team-written start never runs in, or saves trust for, the owner's main checkout.++## Task 1: Forget one folder's trust++**Files:** `cli/src/engines/kit/folderTrust.ts`, `cli/src/engines/kit/folderTrust.spec.ts`, `cli/src/engines/launchPrep.ts`++**Interfaces:** `forgetTrustIn(trust, file, path): 'forgotten' | 'absent' | 'skipped'`; `FolderTrust.forget(path)`.++- [ ] Write failing specs: a recorded folder's flag is cleared and every other key of the file is kept; a folder above it,+ another folder and the rest of the entry stay; a file that is missing, unreadable or not the engine's shape is left as+ it is; a TOML engine is skipped.+- [ ] Watch them fail, then add `forgetTrustIn` and `FolderTrust.forget`.++## Task 2: Remove it with the worktree++**Files:** `cli/src/superTabs/machines.ts`, `cli/src/superTabs/machines.spec.ts`++- [ ] Write failing specs: a Team-written start's worktree record is marked; its trust is saved by the start and cleared+ when the stopped worker's worktree is removed, when its folder is already gone, and when the machine is removed from+ the Swarm; a worktree kept (work or a session in it) keeps its trust; a normal start's trust and the person's own+ trust on the main repository stay.+- [ ] Watch them fail, then mark the record and forget the trust at each removal.++## Task 3: Never the owner's main checkout++**Files:** `cli/src/superTabs/start.ts`, `cli/src/superTabs/start.spec.ts`++- [ ] Write a failing spec: a Team-written Claude start off a Team daemon that names no worktree is refused before+ anything is made, saying why; one with a worktree starts as before.+- [ ] Watch it fail, then refuse it.+- [ ] Run the changed specs, the specs of what imports them, and the local checks `scripts/local-checks.py --list` names.