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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(browser): nodes an agent opens get their own per-project session jar
Claude Codefaa288a2e4cb
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 548f0ed15..26f8b2215 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -217,6 +217,7 @@ import { buildHibernationCandidates } from '../lib/hibernationCandidates'import { applyLoopDismiss } from '../lib/loopCard'import { prepareQuickOpenFiles, type QuickOpenIndexedFile } from '../lib/quickOpenSearch'import { isSafeQuickOpenRelPath } from '@shared/quick-open-filter'+import { agentBrowserPartition } from '@shared/browser-partition'/** The real `sshProject.connect`, bound once. Passed into `connectHostAttachment` rather than* reached for inside it, so that helper stays testable without an Electron preload. */@@ -585,6 +586,7 @@ function toKanbanSession(n: CanvasNode): KanbanSession | null {color: (n.data.color as string) ?? NODE_COLORS[0],kind: 'browser',url: n.data.url as string | undefined,+ partition: n.data.partition as string | undefined,spawn: {}}}@@ -6947,7 +6949,17 @@ export function Canvas() {reply({ ok: false, error: 'open-browser requires a valid http(s) --url' })return}- const id = addAndConnect(createBrowserNode(nodesRef.current.length, browserUrl, placeBelow()))+ // An agent-opened browser gets its OWN per-project session jar — never the default+ // session the user's own browsing lives in (Probe A: a partition-less <webview> shares+ // session.defaultSession). The project id becomes a persisted storage key, so it must+ // pass isSafeNodeId; agentBrowserPartition returns null when it does not, and we refuse+ // the open rather than fall back to the shared jar (fail-closed).+ const partition = agentBrowserPartition(ctlProject?.id ?? '')+ if (!partition) {+ reply({ ok: false, error: "open-browser: this project's id cannot be used as a browser session key" })+ return+ }+ const id = addAndConnect(createBrowserNode(nodesRef.current.length, browserUrl, placeBelow(), partition))reply({ ok: true, message: `opened browser ${id}`, result: { id } })return}diff --git a/src/renderer/nodes/BrowserNode.tsx b/src/renderer/nodes/BrowserNode.tsxindex 6549aefb8..73fe93327 100644--- a/src/renderer/nodes/BrowserNode.tsx+++ b/src/renderer/nodes/BrowserNode.tsx@@ -45,6 +45,7 @@ export default function BrowserNode({ id, data, selected }: NodeProps<CanvasNode<BrowserSurfacenodeId={id}url={(data.url as string) ?? ''}+ partition={data.partition as string | undefined}onUrlChange={(u) => updateNodeData(id, { url: u })}onTitleChange={(t) => updateNodeData(id, { title: t })}/>diff --git a/src/renderer/nodes/BrowserSurface.tsx b/src/renderer/nodes/BrowserSurface.tsxindex 86da80ffd..11c473752 100644--- a/src/renderer/nodes/BrowserSurface.tsx+++ b/src/renderer/nodes/BrowserSurface.tsx@@ -24,6 +24,15 @@ interface BrowserSurfaceProps {nodeId: string/** Initial URL (seeded once at mount). */url: string+ /**+ * The Electron session partition. Set for an AGENT-opened node+ * (`persist:nt-agent-browser-<projectId>`), absent for a USER-opened node (default session).+ * Applied straight to `<webview partition>`, which is honoured only at attach — the discard/restore+ * remount re-applies the SAME value, so the guest rejoins its jar ([MEASURED, Electron 42.8.1],+ * Probe B). Threaded identically here and in the card modal so the two mounts share one jar+ * (`browser-partition-parity.test.tsx`); a mismatch reads to a user as "my login vanished".+ */+ partition?: string/** Persist the top-level URL after a navigation. */onUrlChange: (url: string) => void/** Persist the page title. */@@ -37,7 +46,7 @@ interface BrowserSurfaceProps {* webview never emits dom-ready, so imperative loadURL before then is a no-op); `did-navigate` only* updates the address, so in-page navigation can't loop.*/-export function BrowserSurface({ nodeId, url, onUrlChange, onTitleChange }: BrowserSurfaceProps) {+export function BrowserSurface({ nodeId, url, partition, onUrlChange, onTitleChange }: BrowserSurfaceProps) {const ref = useRef<WebviewEl | null>(null)const rootRef = useRef<HTMLDivElement | null>(null)const lastUrlRef = useRef('')@@ -256,6 +265,7 @@ export function BrowserSurface({ nodeId, url, onUrlChange, onTitleChange }: Brow<webviewref={ref as unknown as React.Ref<HTMLElement>}src={src || undefined}+ partition={partition || undefined}allowpopups={true}style={{ width: '100%', height: '100%' }}/>diff --git a/src/renderer/state/workspace.browser.test.ts b/src/renderer/state/workspace.browser.test.tsindex a4b791ecf..c3e7621d2 100644--- a/src/renderer/state/workspace.browser.test.ts+++ b/src/renderer/state/workspace.browser.test.ts@@ -13,4 +13,22 @@ describe('browser node', () => {const b = round.find((n) => n.type === 'browser')!expect(b.data.url).toBe('https://a.dev')})++ it('createBrowserNode without a partition is the USER-opened node — unchanged, default session', () => {+ expect(createBrowserNode(0, 'https://x.test/').data.partition).toBeUndefined()+ })++ it('an agent-opened node carries its partition, set once at creation', () => {+ const n = createBrowserNode(0, 'https://x.test/', undefined, 'persist:nt-agent-browser-p1')+ expect(n.data.partition).toBe('persist:nt-agent-browser-p1')+ })++ it("an agent node's partition survives the persistence round-trip; a user node's stays absent", () => {+ // The jar must outlive a reopen, or the agent is logged out on the next app start.+ const agent = createBrowserNode(0, 'https://a.dev', undefined, 'persist:nt-agent-browser-p1')+ const user = createBrowserNode(1, 'https://b.dev')+ const round = nodeStatesToFlow(flowToNodeStates([agent, user]))+ expect(round.find((n) => n.id === agent.id)!.data.partition).toBe('persist:nt-agent-browser-p1')+ expect(round.find((n) => n.id === user.id)!.data.partition).toBeUndefined()+ })})diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.tsindex bc9764be1..bdc748dac 100644--- a/src/renderer/state/workspace.ts+++ b/src/renderer/state/workspace.ts@@ -92,6 +92,14 @@ export interface NodeData {fileMissing?: boolean/** web-only: live URL to load in the web (webview) node. */url?: string+ /**+ * browser-only: the Electron session partition for this <webview>. Set ONCE at creation for an+ * AGENT-opened node (`agentBrowserPartition`, `persist:nt-agent-browser-<projectId>`) and never+ * mutated — [MEASURED, Electron 42.8.1] `partition` is honoured only at attach. Absent (undefined)+ * for a USER-opened node, which keeps the default session (no migration, no lost logins). Carried+ * through persistence untouched on Server Edition / mobile, where a browser node has no <webview>.+ */+ partition?: stringdiffStaged?: booleancommitOid?: string/** dino-only: best score reached in the T-Rex Runner game. */@@ -633,11 +641,20 @@ export function createWebNode(}}-/** Creates a navigable browser node (Electron <webview>) starting at `url` ('' = blank). */+/**+ * Creates a navigable browser node (Electron <webview>) starting at `url` ('' = blank).+ *+ * `partition` is set ONLY for an AGENT-opened node (`open-browser`), to its per-project session jar+ * (`agentBrowserPartition`). A USER-opened node passes none and keeps the default session, unchanged+ * — the zero-migration path, so nobody loses a login on upgrade. It is written once here and never+ * mutated: [MEASURED, Electron 42.8.1] `<webview partition>` is honoured only at attach, so a later+ * change would be a silent no-op anyway (docs/superpowers/probes/2026-08-browser-partition.md).+ */export function createBrowserNode(index: number,url: string,- center?: { x: number; y: number }+ center?: { x: number; y: number },+ partition?: string): CanvasNode {const title = url ? url.replace(/^https?:\/\//, '').slice(0, 40) : 'Browser'return {@@ -651,7 +668,8 @@ export function createBrowserNode(title,color: '#0a84ff',group: null,- ...(url ? { url } : {})+ ...(url ? { url } : {}),+ ...(partition ? { partition } : {})}}}@@ -1307,6 +1325,7 @@ export function nodeStatesToFlow(states: CanvasNodeState[]): CanvasNode[] {filePath: n.filePath,fileMissing: n.fileMissing,url: n.url,+ partition: n.partition,diffStaged: n.diffStaged,commitOid: n.commitOid,highScore: n.highScore,@@ -1375,6 +1394,7 @@ export function flowToNodeStates(nodes: CanvasNode[]): CanvasNodeState[] {filePath: n.data.filePath,fileMissing: n.data.fileMissing,url: n.data.url,+ partition: n.data.partition,diffStaged: n.data.diffStaged,commitOid: n.data.commitOid,highScore: n.data.highScore,diff --git a/src/shared/browser-partition.test.ts b/src/shared/browser-partition.test.tsnew file mode 100644index 000000000..30a78d091--- /dev/null+++ b/src/shared/browser-partition.test.ts@@ -0,0 +1,16 @@+import { describe, it, expect } from 'vitest'+import { agentBrowserPartition } from './browser-partition'++describe('agentBrowserPartition', () => {+ it('is per-project and prefixed persist:', () => {+ expect(agentBrowserPartition('p-1')).toBe('persist:nt-agent-browser-p-1')+ })+ it('REFUSES an id isSafeNodeId refuses — this becomes a persisted storage key', () => {+ // Project ids come from project.json, which travels in cloned repos. A partition name is not a+ // path segment, but it IS a persisted-storage key, and the class of mistake is identical to+ // docs/node-identity.md §"Ids are path segments".+ for (const bad of ['..', '.', '', 'a/b', 'a b', '../../x', 'x'.repeat(300)]) {+ expect(agentBrowserPartition(bad), bad).toBe(null)+ }+ })+})diff --git a/src/shared/browser-partition.ts b/src/shared/browser-partition.tsnew file mode 100644index 000000000..9f540b89f--- /dev/null+++ b/src/shared/browser-partition.ts@@ -0,0 +1,35 @@+import { isSafeNodeId } from './safe-id'++/**+ * The session partition for a browser node an AGENT opened.+ *+ * User-opened nodes keep the default session, unchanged — that is what makes this a zero-migration+ * change: every existing browser node was user-opened (or restored, hence un-owned), so nobody+ * loses a login on upgrade. A blanket per-node partitioning WOULD have logged everyone out once.+ * [MEASURED 2026-08, Electron 42.8.1] a partition-less `<webview>` genuinely shares+ * `session.defaultSession` with the app window — so an agent node left on the default session would+ * read whatever the user is already logged into (see the probe doc, Probe A).+ *+ * PER-PROJECT, not per-node: per-node means re-logging-in for every open-browser, which makes+ * multi-tab agentic work (compare two pages, open a link in a second node) impractical. Not global:+ * a login an agent made for project A has no business being available to an agent in project B.+ *+ * The property this buys, and it is the one the owner asked about: an agent driving node A cannot+ * reach node B's logins, where B is anything the user opened. The cost is the mirror image — the+ * user cannot log in on the agent's behalf from their OWN node; they must log in inside the agent's+ * node, which is where the indicator is.+ *+ * `projectId` is validated because it arrives from git-shared project.json and becomes a PERSISTED+ * STORAGE KEY. Returns null rather than throwing: the caller refuses the open, it does not crash.+ * The guard is load-bearing and pinned by `browser-partition.test.ts` ("REFUSES an id isSafeNodeId+ * refuses"); drop it and that test goes red.+ *+ * [MEASURED 2026-08, Electron 42.8.1 — see docs/superpowers/probes/2026-08-browser-partition.md]+ * A discarded+restored webview rejoins the same named partition (Probe B), and `partition` is+ * honoured only at attach — a post-attach mutation is silently ignored (Probe C) — which is why the+ * node's field is set once at creation and never mutated.+ */+export function agentBrowserPartition(projectId: string): string | null {+ if (!isSafeNodeId(projectId)) return null+ return `persist:nt-agent-browser-${projectId}`+}diff --git a/src/shared/types.ts b/src/shared/types.tsindex 6e0059745..d46655d47 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -285,6 +285,13 @@ export interface CanvasNodeState {fileMissing?: boolean/** web-only: when set, the web node loads this live URL (else it loads `filePath` as local html). */url?: string+ /**+ * browser-only: the Electron session partition for an AGENT-opened browser node+ * (`persist:nt-agent-browser-<projectId>`), set once at creation and never mutated. Absent for a+ * USER-opened node (default session, no migration). Persisted so the jar survives reopen; carried+ * through untouched on Server Edition / mobile, where a browser node renders with no <webview>.+ */+ partition?: string/** diff-only: true = staged diff (HEAD vs index), false = unstaged (index vs working). */diffStaged?: boolean/** diff-only: when set, the diff shows parent (<oid>^) vs commit (<oid>) for a file from history. */