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.

Merge branch 'feat/headless-launch-core' into feat/headless-run-now

review82c674a4b599
diff --cc src/core/canvas-control-core.ts
index 106561136,f897b4a0c..dd6617b1c
--- a/src/core/canvas-control-core.ts
+++ b/src/core/canvas-control-core.ts
@@@ -433,9 -484,9 +492,9 @@@ export function buildCanvasControlInstr
'Verbs:',
'- `list` — current nodes (id, kind, title). Start here when you need a node id.',
'- `help` — print the verb list. Answered by the shim itself, so it works even if the app is down.',
- '- `open-terminal [--count N] [--cwd P] [--cmd C] [--group <id>] [--after <id,id>] [--project <id>]` — open N plain terminals. `--cmd` requires verified node identity.',
- '- `open-claude [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--issue <owner/repo#N | #N>]` — open N Claude sessions.',
- `- \`open-agent --agent ${agentChoices} [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--issue <owner/repo#N | #N>]\` — open`,
+ '- `open-terminal [--count N] [--cwd P] [--cmd C] [--group <id>] [--after <id,id>] [--project <id>] [--run-now]` — open N plain terminals. `--cmd` requires verified node identity.',
- '- `open-claude [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--run-now]` — open N Claude sessions.',
- `- \`open-agent --agent ${agentChoices} [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--run-now]\` — open`,
++ '- `open-claude [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--issue <owner/repo#N | #N>] [--run-now]` — open N Claude sessions.',
++ `- \`open-agent --agent ${agentChoices} [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--issue <owner/repo#N | #N>] [--run-now]\` — open`,
' any agent CLI. `--group` parents the node(s) into a group frame; a worktree-bound group also',
' hands its worktree path down as the cwd. `--after <id,id>` opens the node ARMED: it does not',
' start until every listed station has finished a turn SUCCESSFULLY. It is',
@@@ -917,9 -944,9 +978,9 @@@ Verbs
not seven. It clears itself the moment that station completes another turn.
- \`help\` — print the verb list. The shim answers this itself, without reaching the app, so it
is also what to run when you are unsure whether the control endpoint is alive.
-- \`open-terminal [--count N] [--cwd P] [--cmd C] [--group <id>] [--after <id,id>] [--project <id>]\` — open N plain terminals (default 1). \`--cmd\` requires verified node identity.
-- \`open-claude [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--issue <owner/repo#N | #N>]\` — open N Claude sessions (default 1).
-- \`open-agent --agent ${agentChoices} [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--issue <owner/repo#N | #N>]\` — open N sessions of any agent CLI.
+- \`open-terminal [--count N] [--cwd P] [--cmd C] [--group <id>] [--after <id,id>] [--project <id>] [--run-now]\` — open N plain terminals (default 1). \`--cmd\` requires verified node identity.
- - \`open-claude [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--run-now]\` — open N Claude sessions (default 1).
- - \`open-agent --agent ${agentChoices} [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--run-now]\` — open N sessions of any agent CLI.
++- \`open-claude [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--issue <owner/repo#N | #N>] [--run-now]\` — open N Claude sessions (default 1).
++- \`open-agent --agent ${agentChoices} [--count N] [--cwd P] [--prompt T | --prompt-file F] [--model M] [--group <id>] [--after <id,id>] [--project <id>] [--issue <owner/repo#N | #N>] [--run-now]\` — open N sessions of any agent CLI.
\`--group\` parents the node(s) into an existing group frame; a worktree-bound group also
hands its worktree path down as the cwd.
\`--after <id,id>\` opens the node **armed**: it does NOT start yet, and launches itself once
diff --cc src/renderer/canvas/Canvas.tsx
index c935e31ed,9cb4bc57e..a3d49d9b3
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@@ -10372,25 -10628,47 +10668,28 @@@ export function Canvas()
return
}
const tgStore = useProjects.getState()
- const tgLiveSrc = nodesRef.current.find((n) => n.id === sourceNodeId)
- const tgStoredSrc = tgStore.projects
- .flatMap((p) => p.nodes.map((n) => ({ node: n, projectId: p.id })))
- .find((x) => x.node.id === sourceNodeId)
- const callerProjectId = tgLiveSrc ? tgStore.activeProjectId : tgStoredSrc?.projectId
- if (targetId !== callerProjectId) {
- if (!tgLiveSrc && !tgStoredSrc) {
- reply({ ok: false, error: 'source node is not in any open project' })
- return
- }
- if (!sourceIsControlCapable(tgLiveSrc?.data.agentId ?? tgStoredSrc?.node.agentId)) {
- reply({ ok: false, error: 'source node is not a control-capable agent' })
- return
- }
- // Belt only — main already refused every stranger id with one byte-identical sentence
- // (no existence oracle). This fires for a target main authorized that this renderer's
- // store cannot see yet (mid-hydration), so it is worded transient.
- const target = tgStore.getProject(targetId)
- if (!target) {
- reply({
- ok: false,
- error: 'project-target-refused: the target project is not available here — try again'
- })
- return
- }
- // Belt for the SSH invariant: a granted SSH id cannot exist (grants are minted only by
- // local open-project) and main refuses ungranted ones — but if that ever breaks, the
- // target is refused, not opened. A relay tab is another machine's project entirely.
- if (target.ssh || target.remote) {
- reply({
- ok: false,
- error:
- 'project-target-ssh-unsupported: opening sessions into an SSH project is not supported — do not retry'
- })
- return
- }
+ // The source and target belt is ONE definition, shared with `run --project`
+ // (resolveProjectTarget, lib/projectOpen — the order and every sentence are pinned there).
+ // `own` falls through to the legacy path below.
+ const tgResolved = resolveProjectTarget({
+ targetId,
+ sourceNodeId,
+ liveNodes: nodesRef.current,
+ projects: tgStore.projects,
+ activeProjectId: tgStore.activeProjectId,
+ sshVerbWord: 'opening'
+ })
+ if (tgResolved.kind === 'refused') {
+ reply({ ok: false, error: tgResolved.error })
+ return
+ }
+ if (tgResolved.kind === 'target') {
+ const target = tgResolved.project
const tgAgentId = (verb === 'open-agent' ? args.agent : 'claude') as AgentId
const tgIsTerminal = verb === 'open-terminal'
+ // `#N` was resolved against the TARGET project above (`issuePre`) — the node opens there.
+ const tgIssueRef = tgIsTerminal ? undefined : issueRefPre
+ const tgPrompt = tgIssueRef ? issueLaunchPrompt(tgIssueRef, args.prompt) : args.prompt
const tgCount = Math.max(
1,
Math.min(tgIsTerminal ? 8 : 5, parseInt(args.count || '1', 10) || 1)
@@@ -10750,12 -10997,9 +11055,13 @@@
` in "${owner.name}"` +
(coldGroup.groupId ? ` in group ${coldGroup.groupId}` : '') +
(coldCwd ? `, cwd ${coldCwd}` : ''),
+ ...(coldIssueRef ? [`bound to GitHub issue ${formatIssueRef(coldIssueRef)}`] : []),
...(coldAfterIds.length ? [`armed to wait for: ${coldAfterIds.join(', ')}`] : []),
- 'That project is not on screen, so the session(s) would be queued and start when it is next viewed.'
+ // #925: `--run-now` starts it headless instead — except on an SSH project, whose
+ // nodes a headless start refuses (they start on view, over SSH).
+ runNowRequested(args) && !owner.ssh
+ ? 'That project is not on screen, so the session(s) would start now, headless.'
+ : 'That project is not on screen, so the session(s) would be queued and start when it is next viewed.'
].join('\n'),
result: {
dryRun: true,
@@@ -10891,10 -11137,11 +11199,11 @@@
const coldBridges = [...coldPlan.edges, ...coldDepPlans.flatMap((p) => p.edges)]
coldStore.appendCanvasLinks(owner.id, { bridges: coldBridges, ropes: coldRopes })
void writeDisk()
+ logRunsStarted(owner.id, coldMade, coldIssueRef)
const coldWhat = coldTerminal ? 'terminal' : coldAgentId
const coldDepLinked = coldDepPlans.flatMap((p) => p.linked)
- reply({
- ok: true,
+ const coldReply = {
+ ok: true as const,
message:
coldOpenMessage(coldCount, coldWhat, owner.name, coldIds, {
closed: route.kind === 'reopen'
@@@ -10914,24 -11162,11 +11224,25 @@@
projectId: owner.id,
linked: coldPlan.linked,
after: coldAfterIds,
+ ...(coldIssueRef ? { issue: formatIssueRef(coldIssueRef) } : {}),
queued: true,
queuedIds: coldIds
- }
- })
+ } as Record<string, unknown>
+ }
+ // #925 `--run-now`: start the held launches now, headless (`--after` never reaches here
+ // with it — refused before any node was built). The nodes were upserted above in this
+ // same tick; a CLOSED owner (`reopen`) gets its tab back, not the focus. A batch with
+ // nothing held (a bare `open-terminal`) has nothing to start: the plain reply stands.
+ const held = runNowRequested(args)
+ ? coldIds
+ .map((id) => useProjects.getState().getProject(owner.id)?.nodes.find((n) => n.id === id))
+ .filter((n): n is CanvasNodeState => !!n?.pendingLaunch)
+ : []
+ if (held.length) {
+ reply(mergeRunNow(coldReply, await startNodesHeadlessRef.current(owner, held)))
+ return
+ }
+ reply(coldReply)
return
}
// ── OFF CANVAS ──────────────────────────────────────────────────────────────────
diff --cc src/server/headless-node-factory.ts
index 11e0ed13f,acaf61d58..a1fe15884
--- a/src/server/headless-node-factory.ts
+++ b/src/server/headless-node-factory.ts
@@@ -36,8 -36,9 +36,11 @@@ import
import { assembleLaunchCommand } from '../shared/agents/launch'
import type { AgentState, NormalizedAgentEvent } from '../shared/agents/normalize'
import { oneLine } from '../shared/one-line'
+import { RUN_NOW_AFTER_REFUSAL, runNowRequested } from '../shared/control-verbs'
+import { isRemoteSessionNode } from '../shared/worktree'
+ import { issueLaunchPrompt, resolveIssueArg, type IssueRef } from '../shared/github-issue-ref'
+ import { runEndedEvent, runStartedEvent } from '../shared/issue-runs'
+ import type { BoardLogEntry } from '../shared/types'
import { UNKNOWN_CODEX_CLI_CAPS } from '../shared/types'
import type {
BridgeLink,
@@@ -1187,16 -1130,11 +1229,16 @@@ export class HeadlessNodeFactory
return this.runExclusive(async () => {
const flagError = unsupportedFlags(
args,
+ // `run-now` (#925) is a no-op, since a server open already delivers immediately; only its
+ // pairing with `--after` is refused, just below.
verb === 'open-terminal'
- ? new Set(['count', 'cwd', 'cmd', 'after', 'project'])
- : new Set(['agent', 'count', 'cwd', 'prompt', 'after', 'project', 'model', 'issue'])
+ ? new Set(['count', 'cwd', 'cmd', 'after', 'project', 'run-now'])
- : new Set(['agent', 'count', 'cwd', 'prompt', 'after', 'project', 'model', 'run-now'])
++ : new Set(['agent', 'count', 'cwd', 'prompt', 'after', 'project', 'model', 'issue', 'run-now'])
)
if (flagError) return { ok: false, error: `${verb}: ${flagError}` }
+ // "Start now" and "start when X is done" contradict each other: refused in the desktop's
+ // words, before anything is created, rather than silently opening an armed node.
+ if (runNowRequested(args) && args.after) return { ok: false, error: RUN_NOW_AFTER_REFUSAL }
if (!verified) {
return {
ok: false,
@@@ -1360,15 -1312,18 +1416,25 @@@
this.ownership.record(node.id, { sourceNodeId, projectId: target.id })
}
this.publish(target, created)
+ if (issueRef) {
+ for (const node of created) {
+ await this.logRun(target.id, runStartedEvent(issueRef, {
+ id: node.id,
+ title: node.title,
+ agentId: node.agentId,
+ agentSessionId: node.agentSessionId
+ }))
+ }
+ }
const failed: string[] = []
+ // Why each one failed, reported per id (#925): a reply that says only "retained for Run now"
+ // hides the reason Run now would repeat (`line-too-long`).
+ const reasons: Record<string, HeadlessLaunchFailure> = {}
+ const fail = (id: string, reason: HeadlessLaunchFailure): void => {
+ failed.push(id)
+ reasons[id] = reason
+ }
for (const node of created) {
try {
const command = commands.get(node.id)