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(worktree): Source Control operates on the selected checkout

enes7e53046385b0
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index f6dd41df2..65e2e1c85 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -102,6 +102,7 @@ import {
type WorktreeEntry
} from '@shared/worktree'
import { normWorktreePath, type BoundGroup } from '@shared/worktree-reconcile'
+import { scmScopes, defaultScmScope } from '@shared/scm-scope'
import { useWorktrees } from '../state/worktrees'
import {
agentConfig,
@@ -391,6 +392,33 @@ export function Canvas() {
),
[nodes]
)
+ // The checkouts Source Control can act on: the project's own, plus every bound worktree on this
+ // canvas. Computed ONCE here so the default handed to the panel is an element of the very list
+ // the panel receives (a default from another array would name a scope it cannot select).
+ const activeProjectCwd = useProjects(
+ (s) => s.projects.find((p) => p.id === s.activeProjectId)?.cwd
+ )
+ const activeProjectName = useProjects(
+ (s) => s.projects.find((p) => p.id === s.activeProjectId)?.name
+ )
+ const scmScopeList = useMemo(
+ () =>
+ scmScopes(
+ { cwd: activeProjectCwd, name: activeProjectName ?? 'repo' },
+ nodes
+ .filter((n) => n.type === 'group' && n.data.worktree)
+ .map((n) => ({ groupId: n.id, worktree: n.data.worktree as GroupWorktree }))
+ ),
+ [activeProjectCwd, activeProjectName, nodes]
+ )
+ // The group the selection points at: a selected group node itself, else a selected node's parent
+ // group. That group's scope is what Source Control opens on (same selection source — `n.selected`
+ // — the context-menu/delete paths read).
+ const selectedGroupIdForScm = useMemo(() => {
+ const sel = nodes.find((n) => n.selected)
+ if (!sel) return null
+ return sel.type === 'group' ? sel.id : (sel.parentId ?? null)
+ }, [nodes])
// Clipboard failures reach us as a window event (the bridge stub has no React handle).
useEffect(() => {
const onToast = (e: Event): void => {
@@ -4214,6 +4242,9 @@ export function Canvas() {
onOpenDiff={openDiff}
onOpenCommitDiff={openCommitDiff}
onExplainCommit={explainCommit}
+ scopes={scmScopeList}
+ defaultScope={defaultScmScope(scmScopeList, selectedGroupIdForScm)}
+ onNewWorktree={() => openWorktreeDialog(null)}
/>
)}
diff --git a/src/renderer/components/SourceControlPanel.tsx b/src/renderer/components/SourceControlPanel.tsx
index c0aa75ffa..b8b13bc29 100644
--- a/src/renderer/components/SourceControlPanel.tsx
+++ b/src/renderer/components/SourceControlPanel.tsx
@@ -11,6 +11,7 @@ import { GitHistoryPanel } from './git-history/GitHistoryPanel'
import { buildCommitMenuItems } from './git-history/git-history-menu'
import { ContextMenu, type MenuItem } from './ContextMenu'
import { PublishDialog } from './PublishDialog'
+import type { ScmScope } from '@shared/scm-scope'
interface SourceControlPanelProps {
onClose: () => void
@@ -18,6 +19,11 @@ interface SourceControlPanelProps {
onOpenDiff: (relPath: string, staged: boolean) => void
onOpenCommitDiff: (relPath: string, commitOid: string) => void
onExplainCommit: (prompt: string) => void
+ /** The checkouts this panel can operate on: the main one, plus every bound worktree. */
+ scopes: ScmScope[]
+ /** The scope to open on (derived from the canvas selection by the caller). */
+ defaultScope?: ScmScope
+ onNewWorktree: () => void
}
const AUTO_FETCH_MS = 180_000
@@ -46,14 +52,25 @@ export function SourceControlPanel({
onRunInTerminal,
onOpenDiff,
onOpenCommitDiff,
- onExplainCommit
+ onExplainCommit,
+ scopes,
+ defaultScope,
+ onNewWorktree
}: SourceControlPanelProps) {
const project = useProjects((s) => s.projects.find((p) => p.id === s.activeProjectId))
// SSH project: git ops run on the remote repo over the master, so the cwd is the project's
// exact remoteCwd (the remote-git registry matches by exact string — must not be transformed).
// Local projects are byte-identical (the SSH branch fires only when `project.ssh` is set).
const isSsh = !!project?.ssh
- const cwd = project?.ssh?.remoteCwd ?? project?.cwd
+ // The panel is mounted per open (`scOpen` in Canvas), so seeding the active scope from the
+ // caller's default here applies the smart default on EVERY open, not just the first.
+ const [scopeId, setScopeId] = useState<string>(() => defaultScope?.id ?? 'main')
+ const [scopeMenu, setScopeMenu] = useState<{ top: number; left: number } | null>(null)
+ // A scope whose group was deleted/unbound while the panel is open falls back to the main
+ // checkout rather than pointing at a checkout that no longer exists.
+ const scope = scopes.find((s) => s.id === scopeId) ?? scopes.find((s) => s.id === 'main')
+ // SSH projects have no worktrees (v1), so the remote cwd is still the whole story there.
+ const cwd = project?.ssh?.remoteCwd ?? scope?.cwd
// For an SSH project the master may still be connecting when the panel mounts; its controlPath
// appears once `setConn` runs (after `setActiveRemote` arms remote routing). Observing it lets the
// refresh re-run when the master connects. Local projects have no entry → undefined → no effect.
@@ -364,7 +381,18 @@ export function SourceControlPanel({
{cwd && status && status.hasRepo && (
<>
<div className="scm-bar">
- <span className="scm-repo">⌥ {status.repoName}</span>
+ {/* The scope chip replaces the static repo-name chip: it names the checkout every
+ action below operates on (main checkout or a bound worktree). */}
+ <button
+ className="scm-scope"
+ title={scope?.cwd}
+ onClick={(e) => {
+ const r = e.currentTarget.getBoundingClientRect()
+ setScopeMenu({ top: r.bottom + 4, left: r.left })
+ }}
+ >
+ ⌥ {scope?.label ?? status.repoName} ⌄
+ </button>
<button
className="scm-branch"
onClick={(e) => {
@@ -492,6 +520,45 @@ export function SourceControlPanel({
</>
)}
+ {scopeMenu &&
+ createPortal(
+ <>
+ <div
+ className="tab-backdrop"
+ style={{ zIndex: 78 }}
+ onClick={() => setScopeMenu(null)}
+ />
+ <div
+ className="tab-menu"
+ style={{ top: scopeMenu.top, left: scopeMenu.left, zIndex: 80 }}
+ >
+ {scopes.map((s) => (
+ <button
+ key={s.id}
+ title={s.cwd}
+ onClick={() => {
+ setScopeMenu(null)
+ setScopeId(s.id)
+ }}
+ >
+ {s.id === scope?.id ? '● ' : ' '}
+ {s.label}
+ </button>
+ ))}
+ <div className="ctx-sep" />
+ <button
+ onClick={() => {
+ setScopeMenu(null)
+ onNewWorktree()
+ }}
+ >
+ New worktree…
+ </button>
+ </div>
+ </>,
+ document.body
+ )}
+
{branchMenu &&
status &&
createPortal(
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 6c5490420..353dbf063 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -2590,6 +2590,26 @@ body,
color: var(--text);
}
+/* Scope chip: which checkout (main or a bound worktree) the panel acts on. */
+.scm-scope {
+ background: rgba(255, 255, 255, 0.06);
+ color: var(--text);
+ border: 1px solid var(--border);
+ border-radius: 7px;
+ padding: 3px 9px;
+ font-family: inherit;
+ font-size: 12px;
+ cursor: pointer;
+ max-width: 220px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.scm-scope:hover {
+ background: rgba(255, 255, 255, 0.12);
+}
+
.scm-branch {
background: rgba(122, 162, 247, 0.15);
color: #a9c0ff;
diff --git a/src/shared/scm-scope.test.ts b/src/shared/scm-scope.test.ts
new file mode 100644
index 000000000..56f58ee57
--- /dev/null
+++ b/src/shared/scm-scope.test.ts
@@ -0,0 +1,42 @@
+import { describe, it, expect } from 'vitest'
+import { scmScopes, defaultScmScope } from './scm-scope'
+import type { BoundGroup } from './worktree-reconcile'
+
+const project = { cwd: '/repo', name: 'nodeterm' }
+const bound = (groupId: string, branch: string, path: string): BoundGroup => ({
+ groupId,
+ worktree: { repoPath: '/repo', branch, baseRef: 'main', path, createdByApp: true }
+})
+
+describe('scmScopes', () => {
+ it('always puts the main checkout first', () => {
+ const scopes = scmScopes(project, [bound('g1', 'feat', '/wt/feat')])
+ expect(scopes[0]).toEqual({ id: 'main', label: 'nodeterm (main checkout)', cwd: '/repo', kind: 'main' })
+ })
+
+ it('adds one scope per bound worktree, keyed by group id', () => {
+ const scopes = scmScopes(project, [bound('g1', 'feat', '/wt/feat')])
+ expect(scopes[1]).toEqual({ id: 'g1', label: 'feat (worktree)', cwd: '/wt/feat', kind: 'worktree' })
+ })
+
+ it('returns nothing when the project has no cwd', () => {
+ expect(scmScopes({ name: 'x' }, [])).toEqual([])
+ })
+})
+
+describe('defaultScmScope', () => {
+ const scopes = scmScopes(project, [bound('g1', 'feat', '/wt/feat'), bound('g2', 'fix', '/wt/fix')])
+
+ it('picks the scope of the selected group', () => {
+ expect(defaultScmScope(scopes, 'g2')?.cwd).toBe('/wt/fix')
+ })
+
+ it('falls back to the main checkout with no selection', () => {
+ expect(defaultScmScope(scopes, null)?.id).toBe('main')
+ })
+
+ // A selected group that is not bound is not an error — it just means "main checkout".
+ it('falls back to the main checkout when the selected group has no worktree', () => {
+ expect(defaultScmScope(scopes, 'g-unbound')?.id).toBe('main')
+ })
+})
diff --git a/src/shared/scm-scope.ts b/src/shared/scm-scope.ts
new file mode 100644
index 000000000..6d525145e
--- /dev/null
+++ b/src/shared/scm-scope.ts
@@ -0,0 +1,33 @@
+import type { BoundGroup } from './worktree-reconcile'
+
+/** One checkout the Source Control panel can operate on. */
+export interface ScmScope {
+ /** 'main' for the project's own checkout, else the bound group's node id. */
+ id: string
+ label: string
+ cwd: string
+ kind: 'main' | 'worktree'
+}
+
+/** The main checkout first, then one scope per bound worktree. */
+export function scmScopes(project: { cwd?: string; name: string }, bound: BoundGroup[]): ScmScope[] {
+ if (!project.cwd) return []
+ return [
+ { id: 'main', label: `${project.name} (main checkout)`, cwd: project.cwd, kind: 'main' },
+ ...bound.map((b) => ({
+ id: b.groupId,
+ label: `${b.worktree.branch} (worktree)`,
+ cwd: b.worktree.path,
+ kind: 'worktree' as const
+ }))
+ ]
+}
+
+/**
+ * The scope to open on: the selected node's bound group, else the main checkout. A selected
+ * group with no worktree is not an error — it simply means the main checkout.
+ */
+export function defaultScmScope(scopes: ScmScope[], selectedGroupId: string | null): ScmScope | undefined {
+ const hit = selectedGroupId ? scopes.find((s) => s.id === selectedGroupId) : undefined
+ return hit ?? scopes.find((s) => s.id === 'main')
+}