Skip to content

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.

Merge batch 11-06 k1625: #3348 (#3408)

0xken154fce80b7ba9a
diff --git a/cli/src/engines/kit/folderTrust.spec.ts b/cli/src/engines/kit/folderTrust.spec.ts
index c5e369ce5..a3641355d 100644
--- a/cli/src/engines/kit/folderTrust.spec.ts
+++ b/cli/src/engines/kit/folderTrust.spec.ts
@@ -15,6 +15,17 @@ const codexTrusts = (path: string, codexHome?: string | null) => trustsIn(codex.
const preTrustCodexProject = (cwd: string, codexHome?: string | null) => recordTrustIn(codex.trust!, join(launchCodexHome(codexHome), codex.trust!.file), cwd)
describe('preTrustClaudeProject', () => {
+ it('creates the file holding only that folder when asked, for a machine Claude Code never ran on', () => {
+ const home = mkdtempSync(join(tmpdir(), 'trust-'))
+ const file = join(home, '.claude.json')
+ expect(recordTrustIn(claude.trust!, file, '/w')).toBe('skipped')
+ expect(readdirSync(home)).toEqual([])
+ expect(recordTrustIn(claude.trust!, file, '/w', { create: true })).toBe('trusted')
+ expect(JSON.parse(readFileSync(file, 'utf8'))).toEqual({ projects: { '/w': { allowedTools: [], hasTrustDialogAccepted: true } } })
+ expect(recordTrustIn(claude.trust!, file, '/w', { create: true })).toBe('already')
+ expect(readdirSync(home)).toEqual(['.claude.json'])
+ })
+
it('records trust for a new folder the way Claude Code does, keeping everything else', () => {
const home = mkdtempSync(join(tmpdir(), 'trust-'))
writeFileSync(join(home, '.claude.json'), JSON.stringify({ numStartups: 4, projects: { '/old': { allowedTools: ['Bash'], hasTrustDialogAccepted: true } } }))
diff --git a/cli/src/engines/kit/folderTrust.ts b/cli/src/engines/kit/folderTrust.ts
index 5b7eb5b5c..ec17633e5 100644
--- a/cli/src/engines/kit/folderTrust.ts
+++ b/cli/src/engines/kit/folderTrust.ts
@@ -30,9 +30,11 @@ export function trustsIn(trust: TrustContract, file: string, path: string): bool
return trust.format === 'json' ? jsonTrusts(trust, file, path) : tomlTrusts(trust, file, path)
}
-/** Record trust in `cwd` in `file`. */
-export function recordTrustIn(trust: TrustContract, file: string, cwd: string): 'trusted' | 'already' | 'skipped' {
- return trust.format === 'json' ? recordJson(trust, file, cwd) : recordToml(trust, file, cwd)
+/** Record trust in `cwd` in `file`. `create`: the engine has never run here, so there is no `file` to extend; a JSON one is
+ * made holding that folder's entry alone (a Buddy's own folder, superTabs/buddyHome.ts). Without it a missing file is left
+ * missing: the engine writes it on its first run, and a caller that did not make the folder has no business starting it. */
+export function recordTrustIn(trust: TrustContract, file: string, cwd: string, options: { create?: boolean } = {}): 'trusted' | 'already' | 'skipped' {
+ return trust.format === 'json' ? recordJson(trust, file, cwd, options.create === true) : recordToml(trust, file, cwd)
}
/** A folder as this platform compares it. DESKTOP-0TFH0OJ, 2026-10-23: a Swarm worktree's source came as
@@ -74,8 +76,18 @@ export function replaceConfigFile(file: string, text: string): void {
renameSync(tmp, target)
}
-function recordJson(trust: JsonTrust, file: string, cwd: string): 'trusted' | 'already' | 'skipped' {
- if (!existsSync(file)) return 'skipped'
+function recordJson(trust: JsonTrust, file: string, cwd: string, create = false): 'trusted' | 'already' | 'skipped' {
+ if (!existsSync(file)) {
+ if (!create) return 'skipped'
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 })
+ try {
+ writeFileSync(file, JSON.stringify({ [trust.projects]: { [cwd]: { ...structuredClone(trust.entry), [trust.accepted]: true } } }, null, 2), { mode: 0o600, flag: 'wx' })
+ return 'trusted'
+ } catch (error) {
+ // Made meanwhile, by the engine itself: its file is extended below, never replaced.
+ if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error
+ }
+ }
let config: unknown
try {
config = JSON.parse(readFileSync(file, 'utf8'))
diff --git a/cli/src/engines/launchPrep.ts b/cli/src/engines/launchPrep.ts
index 0ca4af5ed..e2ff6e307 100644
--- a/cli/src/engines/launchPrep.ts
+++ b/cli/src/engines/launchPrep.ts
@@ -18,8 +18,9 @@ import type { AgentEngine } from './types.js'
export interface FolderTrust {
/** Whether the engine already trusts `path`. */
trusts(path: string): boolean
- /** Record trust in `path`: never removes anything, and leaves a file it cannot safely extend alone. */
- record(path: string): 'trusted' | 'already' | 'skipped'
+ /** 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'
}
/**
@@ -37,9 +38,9 @@ export function folderTrust(engine: AgentEngine, profile?: string | null, enviro
const network = (): boolean => homeIsNetworkOrDevice(home())
return {
trusts: (path) => !network() && trustsIn(trust, file(), path),
- record: (path) => {
+ record: (path, options) => {
if (network()) return 'skipped'
- const recorded = recordTrustIn(trust, file(), path)
+ const recorded = recordTrustIn(trust, file(), path, options)
// The folder's other question, asked as the engine starts there: the MCP servers it inherits from above. A folder
// Harness trusts for its agent is one whose questions are Harness's, so it is answered here too, by its default.
const mcp = contract.inheritedMcp
diff --git a/cli/src/superTabs/buddyHome.spec.ts b/cli/src/superTabs/buddyHome.spec.ts
index 6c6f708ed..788653bd3 100644
--- a/cli/src/superTabs/buddyHome.spec.ts
+++ b/cli/src/superTabs/buddyHome.spec.ts
@@ -3,6 +3,9 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, st
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
+// The login shell's environment is captured once and kept for minutes: each test here moves the engine homes in its own process.env.
+vi.mock('../engines/kit/launchExecutable.js', async (original) => ({ ...await original<object>(),
+ launchEnvironment: async () => Object.fromEntries(['HOME', 'CLAUDE_CONFIG_DIR', 'CODEX_HOME'].filter(k => process.env[k] !== undefined).map(k => [k, process.env[k]])) }))
import { BUDDY_COPIES_FILE, buddyProjectsOf, folderName, prepareBuddyHome, pruneBuddyHome, buddyHomeDue, refreshBuddyHome, removeBuddyHome, trustBuddyHome } from './buddyHome.js'
// A person's one Buddy's folder (spec 2026-10-31-one-buddy-per-swarm, Folder): one worktree per project checkout on the
@@ -52,6 +55,22 @@ describe('a person\'s one Buddy\'s folder', () => {
}
})
+ // The reported machine (tuan.dev, 11-06): Claude Code never ran, so there is no .claude.json to extend and its trust question
+ // was asked in a terminal nobody sees.
+ it('trusts the folder alone on a computer where Claude Code never ran', async () => {
+ const claude = root(), home = join(root(), 'home')
+ mkdirSync(home)
+ const moved = process.env.CLAUDE_CONFIG_DIR
+ process.env.CLAUDE_CONFIG_DIR = claude
+ try {
+ await trustBuddyHome(home, 'claude')
+ const saved = JSON.parse(readFileSync(join(claude, '.claude.json'), 'utf8')).projects as Record<string, { hasTrustDialogAccepted: boolean }>
+ expect(saved).toEqual({ [home]: { allowedTools: [], hasTrustDialogAccepted: true } })
+ } finally {
+ if (moved === undefined) delete process.env.CLAUDE_CONFIG_DIR; else process.env.CLAUDE_CONFIG_DIR = moved
+ }
+ })
+
it('holds a worktree of each project checkout on this machine, each its own project\'s, and names the ones not here', async () => {
const r = root(), web = checkout(r, 'web-src'), app = checkout(r, 'app-src'), home = join(r, 'home')
const result = await prepareBuddyHome(home, [{ id: 'web', name: 'Web', cwd: web }, { id: 'app', name: 'App', cwd: app },
diff --git a/cli/src/superTabs/buddyHome.ts b/cli/src/superTabs/buddyHome.ts
index 75d34a6f8..3aef886d3 100644
--- a/cli/src/superTabs/buddyHome.ts
+++ b/cli/src/superTabs/buddyHome.ts
@@ -250,11 +250,12 @@ export async function pruneBuddyHome(home: string, readable: ReadonlySet<string>
* This is an exception to "never a folder with content" (engines/kit/folderTrust.ts): the folder is Harness's, made for the
* start its person pressed, and what the question guards against cannot happen in it: its own root holds no project's settings,
* hooks or MCP servers (each project's copy is a folder below it), and the folder goes with the Buddy. Claude Code and Codex
- * alike, as both run a Buddy (task #2832). A failure here only leaves the question.
+ * alike, as both run a Buddy (task #2832). On a computer where Claude Code never ran there is no settings file to extend: it is
+ * made, holding this folder alone (task #3737). A failure here only leaves the question.
*/
export async function trustBuddyHome(home: string, engine: unknown): Promise<void> {
if (engine !== 'claude' && engine !== 'codex') return
- try { folderTrust(engine, undefined, await launchEnvironment() ?? undefined)?.record(home) }
+ try { folderTrust(engine, undefined, await launchEnvironment() ?? undefined)?.record(home, { create: true }) }
catch (error) { console.warn(`[super-tabs] could not answer the folder question for a Buddy: ${(error as Error).message}`) }
}
diff --git a/cli/src/superTabs/start.spec.ts b/cli/src/superTabs/start.spec.ts
index 125d295d4..2f8d631a7 100644
--- a/cli/src/superTabs/start.spec.ts
+++ b/cli/src/superTabs/start.spec.ts
@@ -1,13 +1,13 @@
import { AGENT_FOLDER_MARK, agentFolderFor } from './agentFolder.js'
import { projectsRoot } from '../lib/projectFolder.js'
-import { describe, expect, it, vi } from 'vitest'
+import { afterEach, describe, expect, it, vi } from 'vitest'
import { dirname, join } from 'node:path'
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
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_NOT_OWN_MACHINE, HEAVY_NOT_RECORDED, HEAVY_REFUSED, inspectCapacity, MODEL_REPORT_WAIT_MS, startAgent } from './start.js'
+import { BUDDY_CLAUDE_SIGNED_OUT, BUDDY_NOT_OWN_MACHINE, HEAVY_NOT_RECORDED, HEAVY_REFUSED, inspectCapacity, MODEL_REPORT_WAIT_MS, startAgent } from './start.js'
import { buildEngineCommandArgv } from '../lib/engineLaunch.js'
import { readCapacityDisk } from './disk.js'
import { SuperTabHostError } from './wire.js'
@@ -15,6 +15,9 @@ import { PM_HOMES } from './teamDaemon.js'
const teamDaemon = vi.hoisted(() => ({ value: false, relayed: true, offered: null as null | { slugs: string[]; listed: string[] } }))
vi.mock('./teamDaemon.js', async (original) => ({ ...await original<object>(), isTeamDaemon: () => teamDaemon.value }))
vi.mock('../team/relay.js', async (original) => ({ ...await original<object>(), teamRelayed: () => teamDaemon.relayed, offeredCodexModels: async () => teamDaemon.offered }))
+// What this computer's Claude Code reads as: signed in unless a test says otherwise (lib/engineAccount.ts).
+const claudeAccount = vi.hoisted(() => ({ signedIn: true as boolean | null }))
+vi.mock('../lib/engineAccount.js', async (original) => ({ ...await original<object>(), engineAccount: async () => ({ signedIn: claudeAccount.signedIn, lastUsedAt: null }) }))
const prepared = vi.hoisted(() => ({ value: { ready: [] as string[], missing: [] as string[] } }))
vi.mock('./buddyHome.js', async (original) => ({ ...await original<object>(), prepareBuddyHome: async () => prepared.value, trustBuddyHome: async () => {} }))
const where = { port: 14001, machineId: 'lead-machine', dataDir: '/fixture' }
@@ -559,6 +562,41 @@ describe('a Buddy launches only on its owner\'s own machine', () => {
rmSync(mark, { force: true })
})
+ // Task #3737 (tuan.dev, 11-06): on a computer where Claude Code is not signed in, a Claude Buddy stopped on its sign-in screen
+ // in a terminal nobody sees, and its chat went quiet. Refused before anything is reserved or launched, in words to act on.
+ describe('with Claude Code signed out on this computer', () => {
+ // A start that launches records its folder's owner (security review 2 of #2832): left behind, it fails the refusals' checks below.
+ afterEach(() => rmSync(buddyOwnerFile(env.ADAPTER_DATA_DIR, worktreeFolderName('super-tab/start')), { force: true }))
+ const start = async (f: ReturnType<typeof fixture>, id: string) => startAgent({ action: 'start', tabId: 'tab', operationId: id, request: f.start.request, hostDispatch: true, signedIn: 'peer' } as never, f.scoped, where, f.open)
+ it('refuses a Claude Buddy with the sign-in sentence, before anything is reserved or launched', async () => {
+ claudeAccount.signedIn = false
+ try {
+ const f = fixture()
+ ownStart(f, 'claude')
+ const result = await start(f, 'signed-out')
+ expect(result).toMatchObject({ error: 'START_FAILED', detail: BUDDY_CLAUDE_SIGNED_OUT })
+ expect(BUDDY_CLAUDE_SIGNED_OUT).toBe('Sign in to Claude Code on this computer first')
+ expect(launches(f)).toBe(false)
+ expect(f.request.mock.calls.some(call => call[0] === 'super_tabs' && (call[1] as Record<string, unknown>)?.action === 'reserveCapacity')).toBe(false)
+ expect(f.scoped).toHaveBeenCalledWith(expect.objectContaining({ command: expect.objectContaining({ type: 'agent.startFailed', error: BUDDY_CLAUDE_SIGNED_OUT }) }))
+ } finally { claudeAccount.signedIn = true }
+ })
+ it.each([
+ ['a Codex Buddy', 'codex', {}],
+ ['a Claude Buddy on a grid model, which does not use Claude Code\'s sign-in', 'claude', { gridModel: 'm' }],
+ ['a Claude Buddy on a machine that cannot say', 'claude', {}],
+ ])('still starts %s', async (_case, engine, extra) => {
+ claudeAccount.signedIn = _case.includes('cannot say') ? null : false
+ try {
+ const f = fixture()
+ ownStart(f, engine, extra)
+ const result = await start(f, `still-${engine}`)
+ expect(result.error).toBeUndefined()
+ expect(launches(f)).toBe(true)
+ } finally { claudeAccount.signedIn = true }
+ })
+ })
+
const refusals: [string, (f: ReturnType<typeof fixture>) => Record<string, unknown>][] = [
['not dispatched by its machine\'s own host', () => ({})],
['in a Harness Team account', () => { teamDaemon.value = true; return { hostDispatch: true, signedIn: 'peer' } }],
diff --git a/cli/src/superTabs/start.ts b/cli/src/superTabs/start.ts
index b52d83617..b5e5ee6b8 100644
--- a/cli/src/superTabs/start.ts
+++ b/cli/src/superTabs/start.ts
@@ -16,6 +16,7 @@ import { projectsRoot } from '../lib/projectFolder.js'
import { worktreeFolderName } from '../lib/agentNames.js'
import { join as joinPath } from 'node:path'
import { markBuddyOwner } from '../lib/buddyGuard.js'
+import { engineAccount } from '../lib/engineAccount.js'
import { codexModelNotOffered, NO_PM_RELAY, offeredCodexModels, teamRelayed } from '../team/relay.js'
type Json = Record<string, unknown>
@@ -104,6 +105,9 @@ function projectSessionPrompt(tabId: string, chat: string, thread: string, mode:
/** Why a thread session that is not Claude Code's never starts. */
/** Why a Buddy start launched nothing on this machine: the server's own words (backend buddyContract.ts BUDDY_OWN_MACHINE_REFUSAL). */
export const BUDDY_NOT_OWN_MACHINE = 'A Buddy runs only on your own machine. Pick one of yours.'
+/** Why a Claude Code Buddy start launched nothing: its engine would stop on its sign-in screen, in a terminal no Swarm view shows
+ * (task #3737). The person signs in to Claude Code on that computer and starts the Buddy again. */
+export const BUDDY_CLAUDE_SIGNED_OUT = 'Sign in to Claude Code on this computer first'
/**
* Whether this machine may launch the Buddy a start names (Ken, 11-04, task #2832): a Buddy runs with its owner's full rights,
@@ -375,6 +379,13 @@ async function startOnce(input: Json, scoped: ScopedRequest, where: Where, open:
requireSuccess(await scoped({ action: 'command', operationId: `refused-${startId}`, command: { type: 'agent.startFailed', startId, error: BUDDY_NOT_OWN_MACHINE } }))
return { error: 'START_FAILED', startId, detail: BUDDY_NOT_OWN_MACHINE }
}
+ // Claude Code that is not signed in on this computer asks to be, on a screen nobody sees, and the Buddy's chat goes quiet. A
+ // grid Buddy runs on the grid's key instead, and a computer that cannot say (null) refuses nothing (lib/engineAccount.ts).
+ if (request.buddyOf !== undefined && request.engine === 'claude' && request.gridModel === undefined && request.gridName === undefined
+ && (await engineAccount('claude', { lastUsed: false })).signedIn === false) {
+ requireSuccess(await scoped({ action: 'command', operationId: `refused-${startId}`, command: { type: 'agent.startFailed', startId, error: BUDDY_CLAUDE_SIGNED_OUT } }))
+ return { error: 'START_FAILED', startId, detail: BUDDY_CLAUDE_SIGNED_OUT }
+ }
const resources = await inspectCapacity(target, request)
if (resources.capacity.error === 'GUEST_NOT_ALLOWED') return {
error: 'CONTRIBUTION_REQUIRED', startId,
diff --git a/docs/plans/2026-11-06-buddy-trust-signin-plan.md b/docs/plans/2026-11-06-buddy-trust-signin-plan.md
new file mode 100644
index 000000000..7964b9202
--- /dev/null
+++ b/docs/plans/2026-11-06-buddy-trust-signin-plan.md
@@ -0,0 +1,33 @@
+# A Buddy never goes silent on Claude's trust or sign-in screen — Plan
+
+**Goal:** On a computer where Claude Code was never used or is not signed in, a Buddy no longer stops on Claude's "trust this folder?" or sign-in screen with a silent chat.
+
+**Architecture:** `trustBuddyHome` already records Claude's trust for the Buddy's own Harness-made folder, but `recordTrustIn` does nothing when `~/.claude.json` does not exist (Claude never ran here), which is exactly the reported machine. A `create` option lets that one caller write the file holding only that folder's entry. A Buddy start whose Claude reads signed out (`engineAccount('claude')`) is refused before anything is reserved or launched.
+
+**Tech Stack:** TypeScript, vitest (cli/src).
+
+**Spec:** task #3737. Works the same on Windows: the key written is the folder as the engine compares it (`folderText`), no process is started.
+
+## Global Constraints
+- Trust only the Buddy's own Harness-made folder, never a parent or home folder.
+- #3713 (PR #3341, `superTabs/agentFolder.ts`) records trust for Swarm agent folders the same way; it gets the new `create` option by calling `record(path, { create: true })`, not by a second copy of this code. This plan touches `start.ts` only at the Buddy lines.
+- The refusal never applies to a Buddy on a grid model (it does not use Claude's sign-in) or to a Codex Buddy.
+
+## Review Focus
+- `create` never overwrites or rewrites an existing file; a race with Claude Code writing its own file loses to Claude's (`wx`).
+- The refusal reads presence only (`engineAccount`), never a secret.
+
+## Task 1: trust file created for the Buddy's folder
+**Files:** `cli/src/engines/kit/folderTrust.ts`, `cli/src/engines/launchPrep.ts`, `cli/src/superTabs/buddyHome.ts`; tests `folderTrust.spec.ts`, `buddyHome.spec.ts`.
+**Interfaces:** `recordTrustIn(trust, file, cwd, { create?: boolean })`; `FolderTrust.record(path, { create?: boolean })`.
+- [ ] Failing tests: `create` writes a missing `.claude.json` with only the folder's entry; without it the answer is still `skipped`; `trustBuddyHome` on a machine with no `.claude.json` trusts the home.
+- [ ] Implement.
+
+## Task 2: Buddy start refused when Claude is signed out
+**Files:** `cli/src/superTabs/start.ts`; test `start.spec.ts`.
+**Interfaces:** `BUDDY_CLAUDE_SIGNED_OUT = 'Sign in to Claude Code on this computer first'`.
+- [ ] Failing tests: a Claude Buddy start with `signedIn: false` is refused with that sentence, nothing reserved; signed in, signed-out Codex, signed-out grid Buddy all start.
+- [ ] Implement after the own-machine check.
+
+## Task 3: Desktop/phone prompt note
+Split to its own task: the desktop pieces (`desktop/lib/`) need Flutter widget tests, and this machine has no Flutter.