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.

feat(project-settings): consume worktree defaults at creation + honest panel copy

enescca5e7a314f3
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 59c00a0cc..1355253cd 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -245,6 +245,8 @@ import {
computeWorktreePath,
resolveWorktreePath,
displacedByWorktree,
+ effectiveWorktreeBaseRef,
+ effectiveWorktreeTemplate,
isRemoteSessionNode,
resolveBaseRef,
sanitizeWorktreeBranch,
@@ -268,7 +270,11 @@ import {
} from '../terminal/file-drop'
import { useWorktrees } from '../state/worktrees'
import { setupAckDecision, setupGateDone, useProjectSetup } from '../state/projectSetup'
-import { ensureProjectLaunchInfo, invalidateProjectLaunchInfo } from '../state/projectLaunchInfo'
+import {
+ ensureProjectLaunchInfo,
+ invalidateProjectLaunchInfo,
+ projectLaunchInfoNow
+} from '../state/projectLaunchInfo'
import { activeSessionApi } from '../session/session'
import {
agentConfig,
@@ -1177,6 +1183,15 @@ export function Canvas() {
}, [getViewport, setViewport])
const activeProjectId = useProjects((s) => s.activeProjectId)
+ // Project-level worktree defaults (basePath/baseRef) for the active project, read from the warmed
+ // launch-info cache. Fed to the "New worktree" dialog defaults below; the open-worktree verb reads
+ // its own project's entry separately. Absent (project never warmed, or it sets neither) → the
+ // `effectiveWorktree*` resolvers fall back to entries/global, i.e. today's exact behavior.
+ const activeWorktreePw = projectLaunchInfoNow(activeProjectId ?? '')?.resolved.worktree
+ const activeWorktreeDefaults = {
+ basePath: activeWorktreePw?.basePath?.value,
+ baseRef: activeWorktreePw?.baseRef?.value
+ }
// Bumped by `requestReload()`; a dependency of the project-load effect so an in-place reload of
// the ALREADY-active project actually re-runs it (see reloadActiveProject).
const reloadNonce = useProjects((s) => s.reloadNonce)
@@ -7733,14 +7748,22 @@ export function Canvas() {
}
bindGroupId = g.id
}
- const baseRef = args.base?.trim() || resolveBaseRef(entries)
+ // Project-level worktree defaults (basePath/baseRef) from the warmed launch-info cache,
+ // same as the "New worktree" dialog. Fail-open: no cached entry → `effectiveWorktree*`
+ // reduce to entries/global exactly as before. An explicit `--base` still wins.
+ const pw = projectLaunchInfoNow(project?.id ?? '')?.resolved.worktree
+ const projectDefaults = { basePath: pw?.basePath?.value, baseRef: pw?.baseRef?.value }
+ const baseRef = args.base?.trim() || effectiveWorktreeBaseRef(projectDefaults, entries)
// Resolve from this session's repo root, so a relay tab still produces a path on the
// same host/filesystem where the `api.git` operation below runs.
const wtPath = await resolveWorktreePath({
explicitPath: args.path,
repoRoot,
branch,
- template: useSettings.getState().settings.worktreePathTemplate
+ template: effectiveWorktreeTemplate(
+ projectDefaults,
+ useSettings.getState().settings.worktreePathTemplate
+ )
})
if (!wtPath) {
reply({ ok: false, error: 'open-worktree: could not derive a worktree path — pass --path' })
@@ -10178,13 +10201,13 @@ export function Canvas() {
intent={worktreeDialog.groupId ? 'bind' : 'create'}
repoPath={worktreeRepoRoot ?? ''}
existing={worktreeOrphans.filter((e) => !boundWorktreePaths.has(normWorktreePath(e.path)))}
- defaultBaseRef={resolveBaseRef(worktreeEntries)}
+ defaultBaseRef={effectiveWorktreeBaseRef(activeWorktreeDefaults, worktreeEntries)}
branches={worktreeBranches}
defaultPath={(repoPath, branch) =>
computeWorktreePath(
repoPath,
branch,
- settings.worktreePathTemplate
+ effectiveWorktreeTemplate(activeWorktreeDefaults, settings.worktreePathTemplate)
)
}
busy={worktreeBusy}
diff --git a/src/renderer/components/settings/ProjectSettingsFamilies.tsx b/src/renderer/components/settings/ProjectSettingsFamilies.tsx
index 2894aefc1..673392d3b 100644
--- a/src/renderer/components/settings/ProjectSettingsFamilies.tsx
+++ b/src/renderer/components/settings/ProjectSettingsFamilies.tsx
@@ -104,7 +104,16 @@ const FAMILY_CONFIG: Record<ProjectSettingsFamily, FamilyConfig> = {
worktree: {
title: 'Worktree',
fields: [
- { key: 'basePath', label: 'Base path', kind: 'input' },
+ {
+ key: 'basePath',
+ label: 'Base path',
+ // NB: no literal "project" in this searchable copy — see `fieldEntry` / the "project" query
+ // guard in ProjectSettingsSection.test.tsx. "Local checkouts only" carries the same meaning
+ // as the SSH-inert note without the trap word.
+ description:
+ 'Directory new worktrees are created under; overrides the global template. Local checkouts only.',
+ kind: 'input'
+ },
{
key: 'baseRef',
label: 'Base ref',
@@ -113,8 +122,11 @@ const FAMILY_CONFIG: Record<ProjectSettingsFamily, FamilyConfig> = {
},
{
key: 'sharedPaths',
+ // Honest now that the linker exists (core/worktree-shared-paths.ts): it does not error on a
+ // missing source or a target that already exists — it SKIPS them (SharedPathResult).
label: 'Shared paths',
- description: 'One relative path per line, symlinked into every worktree.',
+ description:
+ 'Relative paths symlinked into each new worktree — e.g. .env, node_modules. Skipped when the source is missing or the target already exists.',
kind: 'list'
}
]
@@ -476,6 +488,16 @@ const RUN_LABEL: Record<ProjectSetupKind, string> = { setup: 'Run setup', archiv
export const LAUNCH_CMD_UNPAIRED_NOTE =
'Launch command applies only when a Default agent id is set above.'
+/**
+ * The whole worktree family is INERT on an SSH project: `git worktree` runs against the local
+ * filesystem, and an SSH project has no local checkout to create worktrees in (both creation sites —
+ * the "New worktree" dialog and the `open-worktree` verb — refuse SSH outright). Shown on every
+ * worktree row so a value typed there does not look as if it will ever take effect. Unlike the
+ * searchable field copy this note may say "project" — it is a `note`, not part of any search entry.
+ */
+export const WORKTREE_SSH_INERT_NOTE =
+ 'Worktree settings apply to local projects; this is an SSH project.'
+
/** How a finished run reads in the badge. */
function exitNote(state: 'done' | 'failed' | 'cancelled', exitCode: number | undefined): string {
if (state === 'cancelled') return 'Cancelled'
@@ -629,6 +651,7 @@ function FamilySection({
ready,
sharedEditable,
canRun,
+ ssh,
saveShared,
saveLocal,
reload
@@ -654,6 +677,9 @@ function FamilySection({
* shared-editing gate entirely (a machine-local script on a folderless project still cannot
* run). */
canRun: boolean
+ /** SSH project → the whole `worktree` family is inert (no local checkout). Drives the per-row
+ * caveat below; ignored by every other family. */
+ ssh: boolean
saveShared: (doc: ProjectSettingsDoc) => Promise<boolean>
saveLocal: (
update: (current: ProjectLocalSettings | undefined) => ProjectLocalSettings | undefined
@@ -723,15 +749,21 @@ function FamilySection({
family === 'agents' &&
resolvedFamily.launchCmd !== undefined &&
resolvedFamily.defaultAgentId === undefined
+ // The whole worktree family cannot take effect on an SSH project (no local checkout) — every row
+ // of it carries the caveat, not just one.
+ const worktreeInert = family === 'worktree' && ssh
/** 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 caveatNote = (f: FieldConfig): string | undefined => {
+ if (worktreeInert) return WORKTREE_SSH_INERT_NOTE
+ if (launchCmdUnpaired && f.key === 'launchCmd') return LAUNCH_CMD_UNPAIRED_NOTE
+ return undefined
+ }
const renderShared = (f: FieldConfig): React.JSX.Element => {
const overridden = resolvedFamily[f.key]?.source === 'local'
const id = `project-${family}-${f.key}-${projectId}`
- const overrideNote = unpairedNote(f) ?? (overridden ? 'Overridden on this machine' : undefined)
+ const overrideNote = caveatNote(f) ?? (overridden ? 'Overridden on this machine' : undefined)
if (f.kind === 'switch') {
return (
<SwitchField
@@ -792,7 +824,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 = unpairedNote(f) ?? (active ? 'Active' : undefined)
+ const activeNote = caveatNote(f) ?? (active ? 'Active' : undefined)
if (f.kind === 'switch') {
return (
<SwitchField
@@ -905,6 +937,7 @@ export function ProjectFamilyEditors({
conflict,
sharedEditable,
canRun,
+ ssh = false,
saveShared,
saveLocal,
reload
@@ -926,6 +959,9 @@ export function ProjectFamilyEditors({
/** See `FamilySection`'s `canRun`: where a PROCESS may be spawned, which is a different question
* from where the shared file may be written. */
canRun: boolean
+ /** SSH project → the worktree family is inert (local-only feature). Defaults false; forwarded to
+ * each `FamilySection` for its per-row caveat. */
+ ssh?: boolean
saveShared: (doc: ProjectSettingsDoc) => Promise<boolean>
saveLocal: (
update: (current: ProjectLocalSettings | undefined) => ProjectLocalSettings | undefined
@@ -959,6 +995,7 @@ export function ProjectFamilyEditors({
ready={ready}
sharedEditable={sharedEditable}
canRun={canRun}
+ ssh={ssh}
saveShared={saveShared}
saveLocal={saveLocal}
reload={reload}
diff --git a/src/renderer/components/settings/project-settings-worktree-panel.test.tsx b/src/renderer/components/settings/project-settings-worktree-panel.test.tsx
new file mode 100644
index 000000000..f22babddf
--- /dev/null
+++ b/src/renderer/components/settings/project-settings-worktree-panel.test.tsx
@@ -0,0 +1,115 @@
+// @vitest-environment jsdom
+//
+// Settings → Project → Worktree: honest field copy + the "inert on SSH" caveat.
+//
+// Worktrees are LOCAL-only (`git worktree` runs against the project's own filesystem), so on an SSH
+// project none of these settings can take effect. An inert setting that looks editable is a lie the
+// panel has to correct on the row itself — same mechanism as the Agents family's unpaired launchCmd
+// note. The base-path / shared-paths descriptions are also asserted here: they must describe what
+// the code actually does, and must avoid the literal substring "project" (the searchable copy would
+// otherwise make the non-discriminating query "project" match the whole pane).
+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 { WORKTREE_SSH_INERT_NOTE, ProjectFamilyEditors } from './ProjectSettingsFamilies'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+let root: Root
+let host: HTMLElement
+
+const EMPTY_RESOLVED: ResolvedProjectSettings = { setup: {}, worktree: {}, agents: {}, terminal: {} }
+
+function mount({ ssh = false }: { ssh?: boolean } = {}): void {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+ act(() =>
+ root.render(
+ <ProjectFamilyEditors
+ projectId="p1"
+ snapshot={{ shared: null, local: undefined }}
+ resolved={EMPTY_RESOLVED}
+ conflict={false}
+ sharedEditable
+ canRun
+ ssh={ssh}
+ 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(WORKTREE_SSH_INERT_NOTE).length - 1
+
+beforeEach(() => {
+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = {}
+})
+
+afterEach(() => {
+ act(() => root.unmount())
+ host.remove()
+})
+
+describe('Worktree family — honest field copy', () => {
+ it('describes shared paths by what the linker actually does', () => {
+ mount()
+ const sharedPaths = rows('Shared paths')[0]
+ expect(sharedPaths.textContent).toContain('symlinked into each new worktree')
+ // The honest caveats: missing source / pre-existing target are SKIPPED, not errors.
+ expect(sharedPaths.textContent).toContain('Skipped when the source is missing')
+ expect(sharedPaths.textContent).toContain('the target already exists')
+ })
+
+ it('gives the base path a description saying it overrides the global template', () => {
+ mount()
+ const basePath = rows('Base path')[0]
+ expect(basePath.textContent).toContain('new worktrees are created under')
+ expect(basePath.textContent).toContain('overrides the global template')
+ })
+
+ it('keeps its searchable copy free of the literal "project" substring', () => {
+ // The non-discriminating query "project" must not match every worktree field (it would mount
+ // every open project's pane). Descriptions are searchable, so they carry no "project".
+ mount()
+ for (const label of ['Base path', 'Base ref', 'Shared paths']) {
+ const desc = rows(label)[0].querySelector('p')?.textContent ?? ''
+ expect(desc.toLowerCase()).not.toContain('project')
+ }
+ })
+})
+
+describe('Worktree family — the SSH-inert caveat', () => {
+ it('warns on EVERY worktree row (shared + this machine) for an SSH project', () => {
+ mount({ ssh: true })
+ for (const label of ['Base path', 'Base ref', 'Shared paths']) {
+ const labelRows = rows(label)
+ expect(labelRows).toHaveLength(2) // shared + "this machine"
+ for (const row of labelRows) expect(row.textContent).toContain(WORKTREE_SSH_INERT_NOTE)
+ }
+ // Six worktree rows, and only those.
+ expect(noteCount()).toBe(6)
+ })
+
+ it('says nothing for a local project', () => {
+ mount({ ssh: false })
+ expect(noteCount()).toBe(0)
+ })
+
+ it('does not leak the worktree caveat onto other families', () => {
+ mount({ ssh: true })
+ for (const row of rows('Shell')) {
+ expect(row.textContent).not.toContain(WORKTREE_SSH_INERT_NOTE)
+ }
+ })
+})
diff --git a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx b/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
index 51f5adb51..0df8e6980 100644
--- a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
+++ b/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
@@ -345,6 +345,9 @@ function EditableProjectSection({
// Same predicate today, deliberately a separate prop: this one gates SPAWNING a setup
// script, not writing the shared file — see `FamilySection`'s `canRun`.
canRun={Boolean(project.cwd || project.ssh)}
+ // An SSH project has no local checkout, so the worktree family is inert — the panel says so
+ // on each of its rows (both creation sites already refuse SSH).
+ ssh={Boolean(project.ssh)}
saveShared={settings.saveShared}
saveLocal={settings.saveLocal}
reload={settings.reload}