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
fix(control): run the authorization belt before resolving open-agent --issue #N
review31e8ef99d8f1
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 511f221a8..2f06b146d 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -480,7 +480,7 @@ import {type IssueRef} from '@shared/github-issue-ref'import { runEndedEntry, runStartedEntry } from '../lib/issueRuns'-import { resolveIssueFlagFor, type IssueFlagResult } from '../lib/issueFlag'+import { resolveIssueFlagForCall, type IssueFlagResult } from '../lib/issueFlag'import type { GitHubIssueCardView } from '@shared/github-issues'import { branchClaudeSession } from '../lib/claudeBranch'import {@@ -10461,13 +10461,6 @@ export function Canvas() {// asked of the core that owns the project). No board repository = `#N` is refused and told// the full form; nothing is guessed. The issue's own text is never fetched here: the launch// prompt carries only the reference (`issueLaunchPrompt`).- const resolveIssueFlag = (projectId: string | undefined): Promise<IssueFlagResult> =>- resolveIssueFlagFor(- args.issue,- verb,- projectId ? useProjects.getState().getProject(projectId) : undefined,- (id) => api.githubControl.status(id).then((view) => view.project?.repository ?? null)- )/** The node, bound to the issue (display + run history only — its launch line is already built). */const bindIssue = (node: CanvasNode, ref: IssueRef | undefined): CanvasNode =>ref ? { ...node, data: { ...node.data, issueRef: ref } } : node@@ -10491,15 +10484,21 @@ export function Canvas() {// #443 class) or report a node as queued that the next commit dropped. The project `#N` is// resolved against is the one the node opens in: the `--project` target, else the source's own// project (the live canvas's when the source is on it, else the stored project owning it).+ // The authorization belt runs FIRST (`resolveIssueFlagForCall`): a caller the paths would+ // refuse gets their refusal and never makes the host look up a project's board.const issueOpen = verb === 'open-agent' || verb === 'open-claude'const issuePre: IssueFlagResult = issueOpen- ? await resolveIssueFlag(- args.project ??- (nodesRef.current.some((n) => n.id === sourceNodeId)- ? useProjects.getState().activeProjectId- : useProjects- .getState()- .projects.find((p) => p.nodes.some((n) => n.id === sourceNodeId))?.id)+ ? await resolveIssueFlagForCall(+ {+ raw: args.issue,+ verb,+ targetId: args.project,+ sourceNodeId,+ liveNodes: nodesRef.current,+ projects: useProjects.getState().projects,+ activeProjectId: useProjects.getState().activeProjectId+ },+ (id) => api.githubControl.status(id).then((view) => view.project?.repository ?? null)): { ok: true }if (!issuePre.ok) {diff --git a/src/renderer/canvas/issue-binding.source.test.ts b/src/renderer/canvas/issue-binding.source.test.tsindex 06ac03d11..0fdb234ce 100644--- a/src/renderer/canvas/issue-binding.source.test.ts+++ b/src/renderer/canvas/issue-binding.source.test.ts@@ -41,7 +41,7 @@ describe('--issue in the desktop control dispatch', () => {// `#N` may cost a host round trip. An await inside a path (after it captured the store) let a// tab switch in that window write the node into the wrong project — the #443 class.const body = code(src)- const calls = body.match(/resolveIssueFlag\(/g) ?? []+ const calls = body.match(/resolveIssueFlagForCall\(/g) ?? []expect(calls, 'called exactly once').toHaveLength(1)const pre = body.indexOf('const issuePre: IssueFlagResult = issueOpen')expect(pre).toBeGreaterThan(-1)@@ -54,7 +54,7 @@ describe('--issue in the desktop control dispatch', () => {it('the live open path uses the pre-resolved reference and composes through issueLaunchPrompt', () => {const body = code(between("case 'open-agent': {", "case 'show-image': {"))- expect(body).not.toContain('resolveIssueFlag(')+ expect(body).not.toContain('resolveIssueFlagForCall(')expect(body).toContain('const issueRef = issueRefPre')expect(body).toContain('bound to GitHub issue ${formatIssueRef(issueRef)}')// The launch prompt is composed by the one function allowed to turn a reference into text.@@ -65,7 +65,7 @@ describe('--issue in the desktop control dispatch', () => {it('the cold-open path uses the pre-resolved reference (resolved against the OWNING project)', () => {const body = code(between('if (canColdOpen(verb)) {', '// ── OFF CANVAS'))- expect(body).not.toContain('resolveIssueFlag(')+ expect(body).not.toContain('resolveIssueFlagForCall(')expect(body).toContain('const coldIssueRef = coldTerminal ? undefined : issueRefPre')expect(body).toContain('bound to GitHub issue ${formatIssueRef(coldIssueRef)}')expect(body).toMatch(/coldIssueRef \? issueLaunchPrompt\(coldIssueRef, args\.prompt\) : args\.prompt/)@@ -74,12 +74,13 @@ describe('--issue in the desktop control dispatch', () => {it('the --project path uses the pre-resolved reference (resolved against the TARGET project)', () => {const body = code(between("args.project !== undefined\n ) {", '// ── end of the early-handled'))- expect(body).not.toContain('resolveIssueFlag(')+ expect(body).not.toContain('resolveIssueFlagForCall(')expect(body).toContain('const tgIssueRef = tgIsTerminal ? undefined : issueRefPre')expect(body).toMatch(/tgIssueRef \? issueLaunchPrompt\(tgIssueRef, args\.prompt\) : args\.prompt/)expect(body).toContain('logRunsStarted(target.id, tgMade, tgIssueRef)')- // The pre-resolution names the `--project` target first.- expect(code(src)).toMatch(/await resolveIssueFlag\(\s*args\.project \?\?/)+ // The pre-resolution is handed the `--project` target, which it judges before asking anyone+ // (`resolveIssueFlagForCall` runs the renderer's authorization belt first — lib/issueFlag.test).+ expect(code(src)).toMatch(/await resolveIssueFlagForCall\(\s*\{[^}]*targetId: args\.project,/)})it('no path splices the raw --issue value into a prompt or a launch line', () => {diff --git a/src/renderer/lib/issueFlag.test.ts b/src/renderer/lib/issueFlag.test.tsindex e0083b5b9..4d09a05dc 100644--- a/src/renderer/lib/issueFlag.test.ts+++ b/src/renderer/lib/issueFlag.test.ts@@ -1,5 +1,5 @@import { describe, expect, it, vi } from 'vitest'-import { resolveIssueFlagFor } from './issueFlag'+import { resolveIssueFlagFor, resolveIssueFlagForCall } from './issueFlag'const withBoard = (repository?: string) => ({id: 'p1',@@ -84,3 +84,76 @@ describe('resolveIssueFlagFor (open-agent --issue on the desktop)', () => {expect(r.ok).toBe(false)})})++describe('resolveIssueFlagForCall (the gates run before anybody is asked)', () => {+ // Two projects, both with a GitHub board: a lookup against either would run the host controller+ // (`git remote`, `gh auth`) and the answer would tell the caller whether that project has one.+ const board = { github: { repository: 'o/r' } }+ const projects = [+ {+ id: 'mine',+ nodes: [+ { id: 'agent', agentId: 'claude' },+ { id: 'shell' }+ ],+ kanban: board+ },+ { id: 'theirs', nodes: [{ id: 'other', agentId: 'claude' }], kanban: board },+ { id: 'remote', ssh: { host: 'h' }, nodes: [], kanban: board },+ { id: 'parked', closed: true, nodes: [{ id: 'parked-agent', agentId: 'codex' }], kanban: board }+ ]+ const live = (ids: Array<[string, string | undefined]>) =>+ ids.map(([id, agentId]) => ({ id, data: agentId ? { agentId } : {} }))+ const call = (over: Partial<Parameters<typeof resolveIssueFlagForCall>[0]>) => ({+ raw: '#9',+ verb: 'open-agent',+ targetId: undefined,+ sourceNodeId: 'agent',+ liveNodes: live([['agent', 'claude'], ['shell', undefined]]),+ projects,+ activeProjectId: 'mine',+ ...over+ })++ it('resolves against the caller own project, then asks', async () => {+ const ask = vi.fn(async () => 'o/r')+ expect(await resolveIssueFlagForCall(call({}), ask)).toMatchObject({ ok: true, ref: { number: 9 } })+ expect(ask).toHaveBeenCalledWith('mine')+ })++ it('resolves against an authorized --project target', async () => {+ const ask = vi.fn(async () => 'o/r')+ expect(await resolveIssueFlagForCall(call({ targetId: 'theirs' }), ask)).toMatchObject({ ok: true })+ expect(ask).toHaveBeenCalledWith('theirs')+ })++ it('resolves against the stored project owning a source that is not on screen', async () => {+ const ask = vi.fn(async () => 'o/r')+ expect(await resolveIssueFlagForCall(call({ sourceNodeId: 'parked-agent' }), ask)).toMatchObject({ ok: true })+ expect(ask).toHaveBeenCalledWith('parked')+ })++ it.each([+ ['a plain terminal, own project', { sourceNodeId: 'shell' }, 'source node is not a control-capable agent'],+ ['a plain terminal naming another project', { sourceNodeId: 'shell', targetId: 'theirs' },+ 'source node is not a control-capable agent'],+ ['an unknown source', { sourceNodeId: 'ghost' }, 'source node is not on an open canvas'],+ ['an unknown source naming a project', { sourceNodeId: 'ghost', targetId: 'theirs' },+ 'source node is not in any open project'],+ ['an SSH target', { targetId: 'remote' },+ 'project-target-ssh-unsupported: opening sessions into an SSH project is not supported — do not retry'],+ ['a target this renderer does not know', { targetId: 'nowhere' },+ 'project-target-refused: the target project is not available here — try again']+ ])('refuses %s with the path refusal and asks nobody', async (_label, over, error) => {+ const ask = vi.fn(async () => 'o/r')+ expect(await resolveIssueFlagForCall(call(over), ask)).toEqual({ ok: false, error })+ expect(ask).not.toHaveBeenCalled()+ })++ it('leaves an open without --issue to the paths (no gate, nobody asked)', async () => {+ const ask = vi.fn(async () => 'o/r')+ expect(await resolveIssueFlagForCall(call({ raw: undefined, sourceNodeId: 'ghost' }), ask)).toEqual({ ok: true })+ expect(ask).not.toHaveBeenCalled()+ })++})diff --git a/src/renderer/lib/issueFlag.ts b/src/renderer/lib/issueFlag.tsindex bbb177405..6d3060b9e 100644--- a/src/renderer/lib/issueFlag.ts+++ b/src/renderer/lib/issueFlag.ts@@ -9,6 +9,8 @@// renderer never trusts that the gate in front of it ran.import { parseIssueArg, resolveIssueArg, type IssueRef } from '@shared/github-issue-ref'+import { routeControlSource, sourceIsControlCapable, type ControlProject } from './controlRouting'+import { resolveProjectTarget, type ProjectTargetProject } from './projectOpen'export interface IssueFlagProject {id: string@@ -41,3 +43,82 @@ export async function resolveIssueFlagFor(const resolved = resolveIssueArg(raw, repository)return resolved.ok ? { ok: true, ref: resolved.ref } : { ok: false, error: `${verb}: ${resolved.error}` }}++/**+ * `resolveIssueFlagFor`, behind the renderer's authorization belt. A `#N` lookup runs the GitHub+ * host controller for a project (`git remote`, `gh auth`) and its answer tells the caller whether+ * that project has a board — so it runs only for a call the open paths would ACCEPT: a source that+ * is a known control-capable agent, and a `--project` target `resolveProjectTarget` allows (the very+ * call the `--project` path makes). A call the paths would refuse is refused HERE, with the path's+ * own sentence, before anybody is asked. Main's `gateProjectTarget` (identity + own-or-granted) has+ * already run on the desktop; this is the renderer not depending on it, the order the Server+ * Edition keeps too. It stays ahead of the paths because each of them snapshots the projects store+ * synchronously, and an await inside one lets a tab switch land in between (#443 class).+ * An open without `--issue` is not gated here: nothing is asked for it, and its path judges it.+ */+export type IssueFlagCallProject = IssueFlagProject & ProjectTargetProject & ControlProject++export async function resolveIssueFlagForCall(+ input: {+ raw: string | undefined+ verb: string+ /** The `--project` flag, when given. */+ targetId: string | undefined+ sourceNodeId: string+ /** React Flow's nodes — the ACTIVE project's. */+ liveNodes: readonly { id: string; data: { agentId?: unknown } }[]+ projects: readonly IssueFlagCallProject[]+ activeProjectId: string+ },+ boardRepository: (projectId: string) => Promise<string | null>+): Promise<IssueFlagResult> {+ if (input.raw === undefined) return { ok: true }+ const scope = issueFlagScope(input)+ if (!scope.ok) return scope+ return resolveIssueFlagFor(+ input.raw,+ input.verb,+ input.projects.find((project) => project.id === scope.projectId),+ boardRepository+ )+}++/** Which project `#N` is resolved against — the one the node opens in — or the refusal the open+ * paths would give this call. */+function issueFlagScope<P extends ProjectTargetProject & ControlProject>(input: {+ targetId: string | undefined+ sourceNodeId: string+ liveNodes: readonly { id: string; data: { agentId?: unknown } }[]+ projects: readonly P[]+ activeProjectId: string+}): { ok: true; projectId: string } | { ok: false; error: string } {+ if (input.targetId !== undefined) {+ const target = resolveProjectTarget({+ targetId: input.targetId,+ sourceNodeId: input.sourceNodeId,+ liveNodes: input.liveNodes,+ projects: input.projects,+ activeProjectId: input.activeProjectId,+ sshVerbWord: 'opening'+ })+ if (target.kind === 'refused') return { ok: false, error: target.error }+ if (target.kind === 'target') return { ok: true, projectId: target.project.id }+ // 'own': the path falls through to the legacy routing below, and so does this.+ }+ const live = input.liveNodes.find((node) => node.id === input.sourceNodeId)+ if (live) {+ return sourceIsControlCapable(live.data.agentId)+ ? { ok: true, projectId: input.activeProjectId }+ : { ok: false, error: 'source node is not a control-capable agent' }+ }+ const route = routeControlSource(input.projects, input.activeProjectId, input.sourceNodeId)+ if (route.kind === 'unknown' || route.kind === 'blocked') {+ return { ok: false, error: 'source node is not on an open canvas' }+ }+ const ownerId = route.kind === 'active' ? input.activeProjectId : route.projectId+ const stored = input.projects.find((project) => project.id === ownerId)?.nodes+ .find((node) => node.id === input.sourceNodeId)+ return stored && sourceIsControlCapable(stored.agentId)+ ? { ok: true, projectId: ownerId }+ : { ok: false, error: 'source node is not a control-capable agent' }+}diff --git a/src/server/headless-node-factory.issue.test.ts b/src/server/headless-node-factory.issue.test.tsindex 358572414..ec87555fd 100644--- a/src/server/headless-node-factory.issue.test.ts+++ b/src/server/headless-node-factory.issue.test.ts@@ -83,6 +83,7 @@ describe('Server Edition open-agent --issue', () => {let log: Array<{ projectId: string; entry: BoardLogEntry }>let factory: HeadlessNodeFactorylet boardRepository: string | null+ let lookups: string[]const settings = (): Settings => ({ ...DEFAULT_SETTINGS, claudePermissionMode: 'manual' })@@ -125,6 +126,7 @@ describe('Server Edition open-agent --issue', () => {pty = new FakePty()log = []boardRepository = 'eneskirca/nodeterm'+ lookups = []factory = new HeadlessNodeFactory({workspaceStore: store,ptyManager: pty,@@ -135,7 +137,10 @@ describe('Server Edition open-agent --issue', () => {codexSharedIdentity: async () => false,stateOf: () => undefined,launchTiming: { quietMs: 0, capMs: 0 },- issueRepository: async () => boardRepository,+ issueRepository: async (projectId) => {+ lookups.push(projectId)+ return boardRepository+ },appendBoardLog: async (projectId, entry) => {log.push({ projectId, entry })return true@@ -194,6 +199,27 @@ describe('Server Edition open-agent --issue', () => {)})+ it('asks for the board repository only after the identity, source and target gates', async () => {+ await seed(true)+ // An unverified caller, a caller naming a project that is not its own, and a source that is+ // not in the workspace: each is refused by its gate, and none of them makes the host look up a+ // board (the answer would tell the caller whether that project has one).+ for (const [nodeId, args, verified] of [+ ['term-source', { agent: 'claude', issue: '#42' }, false],+ ['term-source', { agent: 'claude', issue: '#42', project: 'project-elsewhere' }, true],+ ['ghost', { agent: 'claude', issue: '#42' }, true]+ ] as const) {+ const reply = await factory.openAgent(nodeId, { ...args }, verified)+ expect(reply.ok).toBe(false)+ expect(reply.error).not.toMatch(/issue|repository/i)+ }+ expect(lookups).toEqual([])+ expect(pty.creates).toEqual([])+ // The same call from an accepted caller does ask, against the project the node opens in.+ expect((await factory.openAgent('term-source', { agent: 'claude', issue: '#42' }, true)).ok).toBe(true)+ expect(lookups).toEqual(['project-1'])+ })+it('refuses #N when the board syncs with no repository, and opens nothing', async () => {await seed(false)const reply = await factory.openAgent('term-source', { agent: 'claude', issue: '#42' }, true)