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.

fix(project-settings): project launchCmd scopes to the project's OWN default agent

enes7875f73749c7
diff --git a/src/renderer/components/settings/ProjectSettingsFamilies.tsx b/src/renderer/components/settings/ProjectSettingsFamilies.tsx
index 67532a9a9..a94d39421 100644
--- a/src/renderer/components/settings/ProjectSettingsFamilies.tsx
+++ b/src/renderer/components/settings/ProjectSettingsFamilies.tsx
@@ -378,6 +378,16 @@ const SKIP_NOTE: Record<Extract<ProjectSetupRunResult, { status: 'skipped' }>['r
const RUN_LABEL: Record<ProjectSetupKind, string> = { setup: 'Run setup', archive: 'Run archive' }
+/**
+ * A `launchCmd` with no `defaultAgentId` beside it is INERT, and silently so — the launch layer
+ * (`workspace.ts agentLaunchOverride`) consumes a project's launch command only for the agent that
+ * project itself names, and never falls back to this machine's global default agent (that would
+ * make a shared doc type one agent's wrapper into whatever agent the local user happens to prefer).
+ * A setting that does nothing must say it does nothing, on the row where it was typed.
+ */
+export const LAUNCH_CMD_UNPAIRED_NOTE =
+ 'Launch command applies only when a Default agent id is set above.'
+
/** How a finished run reads in the badge. */
function exitNote(state: 'done' | 'failed' | 'cancelled', exitCode: number | undefined): string {
if (state === 'cancelled') return 'Cancelled'
@@ -616,10 +626,24 @@ function FamilySection({
)
}
+ // EFFECTIVE values (local-over-shared, `ignoreShared` respected), like the setup family's run
+ // buttons above: a launch command nothing can consume is reported wherever it was typed — on the
+ // shared row and on its "this machine" twin, since either one alone can be the value that is
+ // sitting there doing nothing. Absence of a resolved `defaultAgentId` is the whole condition;
+ // an id that resolves to no launchable agent is a different (and much louder) problem.
+ const launchCmdUnpaired =
+ family === 'agents' &&
+ resolvedFamily.launchCmd !== undefined &&
+ resolvedFamily.defaultAgentId === undefined
+ /** The caveat WINS over the provenance note ("Active" / "Overridden on this machine"): where the
+ * value comes from hardly matters while nothing consumes it. */
+ const unpairedNote = (f: FieldConfig): string | undefined =>
+ launchCmdUnpaired && f.key === 'launchCmd' ? LAUNCH_CMD_UNPAIRED_NOTE : undefined
+
const renderShared = (f: FieldConfig): React.JSX.Element => {
const overridden = resolvedFamily[f.key]?.source === 'local'
const id = `project-${family}-${f.key}-${projectId}`
- const overrideNote = overridden ? 'Overridden on this machine' : undefined
+ const overrideNote = unpairedNote(f) ?? (overridden ? 'Overridden on this machine' : undefined)
if (f.kind === 'switch') {
return (
<SwitchField
@@ -666,7 +690,7 @@ function FamilySection({
const renderLocal = (f: FieldConfig): React.JSX.Element => {
const active = resolvedFamily[f.key]?.source === 'local'
const id = `project-${family}-${f.key}-local-${projectId}`
- const activeNote = active ? 'Active' : undefined
+ const activeNote = unpairedNote(f) ?? (active ? 'Active' : undefined)
if (f.kind === 'switch') {
return (
<SwitchField
diff --git a/src/renderer/components/settings/project-settings-launch-note.test.tsx b/src/renderer/components/settings/project-settings-launch-note.test.tsx
new file mode 100644
index 000000000..dc20a4823
--- /dev/null
+++ b/src/renderer/components/settings/project-settings-launch-note.test.tsx
@@ -0,0 +1,102 @@
+// @vitest-environment jsdom
+//
+// Settings → Project → Agents: the "this launch command does nothing" caveat.
+//
+// The launch layer (`workspace.ts agentLaunchOverride`) consumes a project's `launchCmd` ONLY for
+// the agent that same project names in `defaultAgentId`, and deliberately never falls back to this
+// machine's global default agent. That makes a launchCmd typed without a default agent id INERT —
+// and an inert setting that looks saved is a lie the panel has to correct on the row itself.
+import { describe, it, expect, beforeEach, afterEach } from 'vitest'
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import type { ResolvedProjectSettings } from '@shared/project-settings'
+import { LAUNCH_CMD_UNPAIRED_NOTE, ProjectFamilyEditors } from './ProjectSettingsFamilies'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+let root: Root
+let host: HTMLElement
+
+const resolved = (agents: ResolvedProjectSettings['agents']): ResolvedProjectSettings => ({
+ setup: {},
+ worktree: {},
+ agents,
+ terminal: {}
+})
+
+function mount(agents: ResolvedProjectSettings['agents']): void {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+ act(() =>
+ root.render(
+ <ProjectFamilyEditors
+ projectId="p1"
+ snapshot={{ shared: null, local: undefined }}
+ resolved={resolved(agents)}
+ conflict={false}
+ sharedEditable
+ canRun
+ saveShared={async () => true}
+ saveLocal={async () => true}
+ reload={() => {}}
+ />
+ )
+ )
+}
+
+/** Every field row whose visible label is `label` (the shared row and its "this machine" twin). */
+function rows(label: string): HTMLElement[] {
+ return [...host.querySelectorAll('label')]
+ .filter((el) => el.textContent === label)
+ .map((el) => el.parentElement as HTMLElement)
+}
+
+const noteCount = (): number => (host.textContent ?? '').split(LAUNCH_CMD_UNPAIRED_NOTE).length - 1
+
+beforeEach(() => {
+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = {}
+})
+
+afterEach(() => {
+ act(() => root.unmount())
+ host.remove()
+})
+
+describe('Agents family — the unpaired launch command note', () => {
+ it('warns on BOTH launch-command rows when a launchCmd is set with no default agent id', () => {
+ mount({ launchCmd: { value: 'nix develop -c claude', source: 'shared' } })
+ const launchRows = rows('Launch command')
+ expect(launchRows).toHaveLength(2) // shared + "this machine"
+ for (const row of launchRows) expect(row.textContent).toContain(LAUNCH_CMD_UNPAIRED_NOTE)
+ // On the launchCmd rows and nowhere else — the caveat is about that field.
+ expect(noteCount()).toBe(2)
+ for (const row of rows('Default agent')) {
+ expect(row.textContent).not.toContain(LAUNCH_CMD_UNPAIRED_NOTE)
+ }
+ })
+
+ it('warns for a launchCmd this machine set locally too — pairing, not provenance', () => {
+ mount({ launchCmd: { value: 'nix develop -c claude', source: 'local' } })
+ expect(noteCount()).toBe(2)
+ })
+
+ it('says nothing once the project also names its default agent', () => {
+ mount({
+ defaultAgentId: { value: 'claude', source: 'shared' },
+ launchCmd: { value: 'nix develop -c claude', source: 'shared' }
+ })
+ expect(noteCount()).toBe(0)
+ // The provenance note the caveat displaces is back where it belongs.
+ expect(rows('Launch command')[0].textContent).not.toContain(LAUNCH_CMD_UNPAIRED_NOTE)
+ })
+
+ it('says nothing when the project sets no launch command at all', () => {
+ mount({ defaultAgentId: { value: 'claude', source: 'shared' } })
+ expect(noteCount()).toBe(0)
+ act(() => root.unmount())
+ host.remove()
+ mount({})
+ expect(noteCount()).toBe(0)
+ })
+})
diff --git a/src/renderer/state/workspace.project-launch.test.ts b/src/renderer/state/workspace.project-launch.test.ts
index c9371f442..7ce4cc9c6 100644
--- a/src/renderer/state/workspace.project-launch.test.ts
+++ b/src/renderer/state/workspace.project-launch.test.ts
@@ -14,9 +14,10 @@ import { DEFAULT_SETTINGS, type Settings } from '@shared/types'
/**
* The PER-PROJECT half of the launch layering (`.nodeterm/settings.json` → `agents`):
* - `launchCmd` — this project's local doc, then its git-SHARED doc but ONLY once that family is
- * trusted, then the user's global Settings → Agents override. Scoped to the agent the project
- * names as its default, because that is exactly what the panel promises ("Overrides how the
- * default agent is launched").
+ * trusted, then the user's global Settings → Agents override. Scoped to the agent THIS PROJECT
+ * names as its default and to no other — never the user's global default, which would let a doc
+ * shipping only a launchCmd follow a mutable local preference into a foreign agent's node. An
+ * unpaired launchCmd is inert: consumed by nothing, prompting for nothing.
* - `defaultAgentId` — what a NON-explicit new node launches, above the global default.
* A launch never blocks and never fails closed: no warm snapshot ⇒ byte-identical to before.
*/
@@ -46,6 +47,17 @@ const settingsWith = (patch: Partial<Settings>): void => {
useSettings.setState({ settings: { ...DEFAULT_SETTINGS, ...patch } })
}
+/** The PAIRED shape a consumable launchCmd needs: the project names its own default agent, and the
+ * launch command is about that agent. `def` defaults to claude — the agent these tests launch. */
+const paired = (
+ cmd: unknown,
+ source: 'local' | 'shared',
+ def: unknown = 'claude'
+): ProjectLaunchInfo['resolved']['agents'] => ({
+ defaultAgentId: { value: def as string, source },
+ launchCmd: { value: cmd as string, source }
+})
+
beforeEach(() => {
resetProjectLaunchInfoForTests()
resetLaunchTrustAsksForTests()
@@ -61,7 +73,7 @@ afterEach(() => {
describe('agentLaunchOverride — per-project launchCmd', () => {
it('is the global override when no project is named', async () => {
settingsWith({ agentLaunchCommands: { claude: 'global-wrap' } })
- await warmProject('p1', info({ launchCmd: { value: 'proj-wrap', source: 'local' } }, true))
+ await warmProject('p1', info(paired('proj-wrap', 'local'), true))
expect(agentLaunchOverride('claude')).toBe('global-wrap')
})
@@ -72,7 +84,7 @@ describe('agentLaunchOverride — per-project launchCmd', () => {
it('lets a project LOCAL launchCmd win over the global override', async () => {
settingsWith({ agentLaunchCommands: { claude: 'global-wrap' } })
- await warmProject('p1', info({ launchCmd: { value: 'local-wrap', source: 'local' } }, false))
+ await warmProject('p1', info(paired('local-wrap', 'local'), false))
expect(agentLaunchOverride('claude', 'p1')).toBe('local-wrap')
// A local value is the user's own typing — never gated, so nothing is ever asked.
expect(requestTrust).not.toHaveBeenCalled()
@@ -80,25 +92,25 @@ describe('agentLaunchOverride — per-project launchCmd', () => {
it('lets a TRUSTED shared launchCmd win over the global override', async () => {
settingsWith({ agentLaunchCommands: { claude: 'global-wrap' } })
- await warmProject('p1', info({ launchCmd: { value: 'shared-wrap', source: 'shared' } }, true))
+ await warmProject('p1', info(paired('shared-wrap', 'shared'), true))
expect(agentLaunchOverride('claude', 'p1')).toBe('shared-wrap')
expect(requestTrust).not.toHaveBeenCalled()
})
it('falls PAST an untrusted shared launchCmd to the global override', async () => {
settingsWith({ agentLaunchCommands: { claude: 'global-wrap' } })
- await warmProject('p1', info({ launchCmd: { value: 'shared-wrap', source: 'shared' } }, false))
+ await warmProject('p1', info(paired('shared-wrap', 'shared'), false))
expect(agentLaunchOverride('claude', 'p1')).toBe('global-wrap')
})
it('falls through to the bare command when there is no global override either', async () => {
- await warmProject('p1', info({ launchCmd: { value: 'shared-wrap', source: 'shared' } }, false))
+ await warmProject('p1', info(paired('shared-wrap', 'shared'), false))
expect(agentLaunchOverride('claude', 'p1')).toBeUndefined()
expect(claudeLaunchCommand('p1')).toBe('claude')
})
it('asks for trust exactly ONCE per project per session, however many launches ask', async () => {
- await warmProject('p1', info({ launchCmd: { value: 'shared-wrap', source: 'shared' } }, false))
+ await warmProject('p1', info(paired('shared-wrap', 'shared'), false))
agentLaunchOverride('claude', 'p1')
agentLaunchOverride('claude', 'p1')
agentLaunchOverride('claude', 'p1')
@@ -109,7 +121,7 @@ describe('agentLaunchOverride — per-project launchCmd', () => {
it('survives a requestTrust that REJECTS — the launch line is still resolved', async () => {
requestTrust.mockImplementation(() => Promise.reject(new Error('no handler')))
settingsWith({ agentLaunchCommands: { claude: 'global-wrap' } })
- await warmProject('p1', info({ launchCmd: { value: 'shared-wrap', source: 'shared' } }, false))
+ await warmProject('p1', info(paired('shared-wrap', 'shared'), false))
expect(agentLaunchOverride('claude', 'p1')).toBe('global-wrap')
await Promise.resolve()
})
@@ -122,54 +134,89 @@ describe('agentLaunchOverride — per-project launchCmd', () => {
it('applies only to the agent the project targets — another agent keeps the global path', async () => {
settingsWith({ agentLaunchCommands: { codex: 'global-codex' }, defaultAgent: 'claude' })
- await warmProject('p1', info({ launchCmd: { value: 'proj-wrap', source: 'local' } }, true))
+ await warmProject('p1', info(paired('proj-wrap', 'local'), true))
expect(agentLaunchOverride('claude', 'p1')).toBe('proj-wrap')
expect(agentLaunchOverride('codex', 'p1')).toBe('global-codex')
})
it('follows the project’s own defaultAgentId when deciding which agent it targets', async () => {
settingsWith({ defaultAgent: 'claude' })
- await warmProject(
- 'p1',
- info(
- {
- defaultAgentId: { value: 'codex', source: 'local' },
- launchCmd: { value: 'proj-wrap', source: 'local' }
- },
- true
- )
- )
+ await warmProject('p1', info(paired('proj-wrap', 'local', 'codex'), true))
expect(agentLaunchOverride('codex', 'p1')).toBe('proj-wrap')
expect(agentLaunchOverride('claude', 'p1')).toBeUndefined()
})
it('does not ask for trust when the shared launchCmd targets another agent', async () => {
settingsWith({ defaultAgent: 'claude' })
- await warmProject('p1', info({ launchCmd: { value: 'shared-wrap', source: 'shared' } }, false))
+ await warmProject('p1', info(paired('shared-wrap', 'shared'), false))
expect(agentLaunchOverride('codex', 'p1')).toBeUndefined()
expect(requestTrust).not.toHaveBeenCalled()
})
it('ignores a blank project launchCmd (and asks nothing for it)', async () => {
settingsWith({ agentLaunchCommands: { claude: 'global-wrap' } })
- await warmProject('p1', info({ launchCmd: { value: ' ', source: 'shared' } }, false))
+ await warmProject('p1', info(paired(' ', 'shared'), false))
expect(agentLaunchOverride('claude', 'p1')).toBe('global-wrap')
expect(requestTrust).not.toHaveBeenCalled()
})
it('ignores a non-string launchCmd from a hostile shared document', async () => {
settingsWith({ agentLaunchCommands: { claude: 'global-wrap' } })
- await warmProject(
- 'p1',
- info({ launchCmd: { value: 42 as unknown as string, source: 'shared' } }, true)
- )
+ await warmProject('p1', info(paired(42, 'shared'), true))
+ expect(agentLaunchOverride('claude', 'p1')).toBe('global-wrap')
+ })
+})
+
+/**
+ * The UNPAIRED case, and the reason the scope comparison is the project's OWN defaultAgentId and
+ * never `resolveNewNodeAgent`'s global fallback: a doc that ships a launchCmd alone would otherwise
+ * chase whatever this machine's global default agent happens to be — a different agent per
+ * teammate, and a different one again after the local user changes an unrelated Setting.
+ */
+describe('agentLaunchOverride — an UNPAIRED launchCmd is inert', () => {
+ const unpaired = (source: 'local' | 'shared'): ProjectLaunchInfo['resolved']['agents'] => ({
+ launchCmd: { value: 'nix develop -c claude', source }
+ })
+
+ it.each(['claude', 'codex', 'gemini', 'custom:x'] as const)(
+ 'is never consumed for %s when the project names no default agent of its own',
+ async (agentId) => {
+ // Every one of these is this machine's global default in turn — the value that must NOT
+ // decide what a shared launch command applies to.
+ settingsWith({
+ defaultAgent: agentId,
+ customAgents: [{ id: 'custom:x', label: 'X', launchCmd: 'x-cli' }] as Settings['customAgents']
+ })
+ await warmProject('p1', info(unpaired('shared'), true))
+ expect(agentLaunchOverride(agentId, 'p1')).toBeUndefined()
+ }
+ )
+
+ it('never prompts for trust on an untrusted shared launchCmd nobody can consume', async () => {
+ settingsWith({ defaultAgent: 'claude' })
+ await warmProject('p1', info(unpaired('shared'), false))
+ expect(agentLaunchOverride('claude', 'p1')).toBeUndefined()
+ expect(requestTrust).not.toHaveBeenCalled()
+ })
+
+ it('is inert for a LOCAL launchCmd too — the pairing rule is about meaning, not provenance', async () => {
+ settingsWith({ agentLaunchCommands: { claude: 'global-wrap' }, defaultAgent: 'claude' })
+ await warmProject('p1', info(unpaired('local'), true))
expect(agentLaunchOverride('claude', 'p1')).toBe('global-wrap')
})
+
+ it('is inert when the project names a default agent this machine cannot launch', async () => {
+ settingsWith({ defaultAgent: 'claude' })
+ await warmProject('p1', info(paired('proj-wrap', 'shared', 'custom:gone'), true))
+ expect(agentLaunchOverride('claude', 'p1')).toBeUndefined()
+ expect(agentLaunchOverride('custom:gone', 'p1')).toBeUndefined()
+ expect(requestTrust).not.toHaveBeenCalled()
+ })
})
describe('createAgentNode — the project launch command reaches the typed line', () => {
it('launches the project’s default agent through the project wrapper', async () => {
- await warmProject('p1', info({ launchCmd: { value: 'proj-wrap', source: 'local' } }, true))
+ await warmProject('p1', info(paired('proj-wrap', 'local'), true))
const node = createAgentNode(
'claude',
0,
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index 1f3af96f1..654dd38aa 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -358,10 +358,19 @@ function askAgentsTrustOnce(projectId: string): void {
* 3. the user's global Settings → Agents → Launch commands entry (builtin-keyed: custom agents
* index past it to undefined — they already own their launchCmd).
*
- * SCOPE: the project's launchCmd applies to the agent that project TARGETS — the panel's own copy
- * is "Overrides how the default agent is launched", and the family holds one launchCmd, not one
- * per agent id. So it is used only when `agentId` is the project's effective default
- * (`resolveNewNodeAgent`); every other agent resolves on the global layer, exactly as before.
+ * SCOPE: the project's launchCmd applies ONLY to the agent that project ITSELF names —
+ * `projectDefaultAgent`, its own valid `agents.defaultAgentId`, never the global default. The
+ * family holds one launchCmd, not one per agent id, and the panel's copy is "Overrides how the
+ * default agent is launched", so it needs an agent to be about; the pair is what makes it
+ * meaningful. Falling back to the GLOBAL default here would have been a cross-agent misfire that
+ * the builtin-KEYED global map made structurally impossible: a doc shipping only `launchCmd` would
+ * follow whatever this user's mutable global default happens to be, so `nix develop -c claude`
+ * could end up typed into a codex node, differently on each teammate's machine, and could change
+ * under a node on cold restore after an unrelated Settings change.
+ *
+ * So an UNPAIRED launchCmd (a project that sets no valid `defaultAgentId` of its own) is a dead
+ * setting: never consumed for any agent, and never prompts for trust. The Agents panel says so
+ * on the row itself (`ProjectSettingsFamilies.tsx`) rather than leaving it silently inert.
*
* Fails OPEN in the ordinary sense: no project id, or no warm snapshot for it
* (`projectLaunchInfoNow` is synchronous by design — see its module doc), resolves layer 3 alone,
@@ -374,11 +383,10 @@ export function agentLaunchOverride(agentId: AgentId, projectId?: string): strin
if (!info) return global
const entry = info.resolved.agents.launchCmd
if (!entry) return global
- // Scope check BEFORE anything else: an agent this project does not target consumes nothing here,
+ // Scope check BEFORE anything else: an agent this project does not name consumes nothing here,
// so it must not even raise a trust prompt about a value it would never use.
- if (agentId !== resolveNewNodeAgent(undefined, projectId, useSettings.getState().settings)) {
- return global
- }
+ const target = projectDefaultAgent(projectId, useSettings.getState().settings)
+ if (!target || target !== agentId) return global
// `.nodeterm/settings.json` is hand-editable, git-shared, hostile input (see @shared/project-settings):
// a non-string that slipped through is simply not a launch command.
const cmd = typeof entry.value === 'string' ? entry.value.trim() : ''
@@ -406,31 +414,43 @@ export function claudeLaunchCommand(projectId?: string): string {
}
/**
- * The agent a NEW node launches: an explicit pick always wins, then the project's own
- * `agents.defaultAgentId`, then the global default.
+ * The agent THIS PROJECT names as its own default (`agents.defaultAgentId`), or undefined when it
+ * names none — deliberately WITHOUT any global fallback, so a caller can tell "the project chose
+ * this agent" from "nobody chose, so the app's default applies". `agentLaunchOverride`'s scoping
+ * turns on exactly that difference; `resolveNewNodeAgent` adds the fallback on top.
*
- * The project value is VALIDATED against what this machine can actually launch — a known builtin,
- * or a custom agent the user still has — and against `disabledAgents`: `.nodeterm/settings.json`
- * is git-shared and hand-editable, so it may name an agent that was removed, never existed, or
- * that this user deliberately switched off, and none of those may become the id typed into a
- * shell (`resolveAgent`'s unknown-id fallback launches the id itself — the same failure
+ * VALIDATED against what this machine can actually launch — a known builtin, or a custom agent the
+ * user still has — and against `disabledAgents`: `.nodeterm/settings.json` is git-shared and
+ * hand-editable, so it may name an agent that was removed, never existed, or that this user
+ * deliberately switched off, and none of those may become the id typed into a shell
+ * (`resolveAgent`'s unknown-id fallback launches the id itself — the same failure
* `launchableDefaultAgent` exists to prevent for the global setting).
*
* Deliberately NOT trust-gated: naming which of the user's own installed agents to open is not
* executable content (`projectTrustContent('agents', …)` hashes launchCmd + env, not this), and
* every id it can select resolves to a command the user already configured themselves.
*/
+function projectDefaultAgent(
+ projectId: string | undefined,
+ settings: Settings
+): AgentId | undefined {
+ const raw = projectId ? projectLaunchInfoNow(projectId)?.resolved.agents.defaultAgentId : undefined
+ const id = typeof raw?.value === 'string' ? raw.value.trim() : ''
+ if (!id) return undefined
+ const known = !!agentConfig(id) || settings.customAgents.some((c) => c.id === id)
+ return known && isAgentEnabled(settings, id) ? id : undefined
+}
+
+/**
+ * The agent a NEW node launches: an explicit pick always wins, then the project's own validated
+ * `agents.defaultAgentId` (`projectDefaultAgent`), then the global default.
+ */
export function resolveNewNodeAgent(
explicit: AgentId | undefined,
projectId: string | undefined,
settings: Settings
): AgentId {
- if (explicit) return explicit
- const raw = projectId ? projectLaunchInfoNow(projectId)?.resolved.agents.defaultAgentId : undefined
- const id = typeof raw?.value === 'string' ? raw.value.trim() : ''
- const known = !!id && (!!agentConfig(id) || settings.customAgents.some((c) => c.id === id))
- if (known && isAgentEnabled(settings, id)) return id
- return launchableDefaultAgent(settings)
+ return explicit ?? projectDefaultAgent(projectId, settings) ?? launchableDefaultAgent(settings)
}
/** Fallback color for custom / unknown agents that have no config-provided color. */