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-setup): worktree lifecycle triggers + waitForSetup arming

enes9d5ae5464799
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index f4949d71c..c467c1518 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -267,6 +267,7 @@ import {
pastedFiles
} from '../terminal/file-drop'
import { useWorktrees } from '../state/worktrees'
+import { useProjectSetup } from '../state/projectSetup'
import { activeSessionApi } from '../session/session'
import {
agentConfig,
@@ -720,6 +721,31 @@ function StatusAwareMiniMap({ onNodeDoubleClick }: { onNodeDoubleClick: (node: N
)
}
+/**
+ * `window.nodeTerminal` rather than the session `api`: the run store's `subscribeProject` listens on
+ * the LOCAL core's channel, so raising a run anywhere else would leave its events unheard — the chip
+ * would sit blank over a script that is really running.
+ */
+function setupApi(): typeof window.nodeTerminal.projectSetup {
+ return window.nodeTerminal.projectSetup
+}
+
+/**
+ * The setup gate an armed node asks about (`PendingLaunch.awaitSetupGroup`): may a node opened into
+ * this worktree frame run its command yet?
+ *
+ * NO ENTRY counts as DONE. The run store is rebuilt from live events, so a group with nothing on
+ * record is either a worktree whose setup never ran or one whose run predates this app start — in
+ * both cases no event is ever coming, and reading that as "still preparing" would strand the node
+ * forever. A FAILED or CANCELLED run is not done: the checkout is in whatever half-state the script
+ * left it, so the node keeps holding its launch until a re-run from the settings panel reports
+ * `done` (or the user fires it by hand from the node's QUEUED badge).
+ */
+function setupDoneForGroup(groupId: string): boolean {
+ const run = useProjectSetup.getState().runForGroup(groupId)
+ return !run || run.state === 'done'
+}
+
export function Canvas() {
// This canvas's core api (a context read — stable for the session, no store subscription).
// For the local session it IS window.nodeTerminal, so every call resolves identically.
@@ -1301,6 +1327,19 @@ export function Canvas() {
}
return sig
})
+ // The same trick for the OTHER gate: a signature over the setup-run state of every group an armed
+ // node is waiting on, so a run going `done` re-runs the launch effect. Subscribing to the whole
+ // store would re-render the canvas on every output chunk of every script.
+ const armedSetupSig = useProjectSetup((s) => {
+ let sig = ''
+ for (const n of nodesRef.current) {
+ const g = n.data.pendingLaunch?.awaitSetupGroup
+ if (!g) continue
+ const runKey = s.groupRunKey[g]
+ sig += `${n.id}:${g}=${runKey === undefined ? '-' : (s.byRunKey[runKey]?.state ?? '')}|`
+ }
+ return sig
+ })
// Bumped to re-run the launch effect after a refused delivery (see LAUNCH_RETRY_MS).
const [launchRetry, setLaunchRetry] = useState(0)
// Ids whose held launch has been handed to the pty. An id stays here FOREVER once delivery
@@ -1316,7 +1355,8 @@ export function Canvas() {
const ready = launchesToFire(
nodes as unknown as ArmedNode[],
useAgentStatus.getState().byId,
- live
+ live,
+ setupDoneForGroup
).filter((f) => !launchInFlight.current.has(f.id))
for (const f of ready) {
launchInFlight.current.add(f.id)
@@ -1340,8 +1380,8 @@ export function Canvas() {
}
})
}
- // eslint-disable-next-line react-hooks/exhaustive-deps -- armedDepSig/launchRetry are the triggers
- }, [nodes, armedDepSig, launchRetry])
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- armedDepSig/armedSetupSig/launchRetry are the triggers
+ }, [nodes, armedDepSig, armedSetupSig, launchRetry])
// Selection state for ephemeral nodes (they live outside React Flow's managed nodes), owned by
// the agent-nodes store so the cards themselves can set it — see `selectable: false` below.
@@ -3899,6 +3939,88 @@ export function Canvas() {
[setNodes, markDirty, activeProjectId]
)
+ // ---- project setup/archive scripts on the worktree lifecycle ----
+ //
+ // The event channel is per PROJECT and ref-counted in preload, so one subscription per project
+ // covers every worktree of it; the unsubscribes are held here and released on unmount.
+ const setupSubsRef = useRef<Map<string, () => void>>(new Map())
+ // Groups whose CURRENT setup run was acked with `waitForSetup` — the only groups that arm the
+ // nodes opened into them. Runtime-only by design: after a restart there is no run to hear from,
+ // and `launchesToFire`'s probe then reads the missing entry as done rather than stranding a node.
+ const setupWaitGroupsRef = useRef<Set<string>>(new Set())
+ useEffect(
+ () => () => {
+ setupSubsRef.current.forEach((off) => off())
+ setupSubsRef.current.clear()
+ },
+ []
+ )
+ /** Subscribe BEFORE the run is raised — the head of a script's output must not be lost to the
+ * gap between the ack and the first listener. Idempotent per project. */
+ const ensureSetupSubscription = useCallback((projectId: string): void => {
+ if (setupSubsRef.current.has(projectId)) return
+ setupSubsRef.current.set(projectId, useProjectSetup.getState().subscribeProject(projectId))
+ }, [])
+ /**
+ * Kick a worktree's `setup` script and hand the run to the group's chip. Asked UNCONDITIONALLY:
+ * the service answers `no-script` cheaply, and reading the project's settings here would put a
+ * file read (SSH: a network round-trip) on the hot path of creating a worktree.
+ *
+ * Fire-and-observe — nothing awaits the script. What the ack decides is only (a) which run the
+ * frame's chip reports, and (b) whether nodes opened into this group meanwhile hold their launch.
+ */
+ const startWorktreeSetup = useCallback(
+ (groupId: string, worktreePath: string): void => {
+ const projectId = useProjects.getState().activeProjectId
+ if (!projectId) return
+ ensureSetupSubscription(projectId)
+ void setupApi()
+ .run(projectId, 'setup', worktreePath)
+ .then((res) => {
+ if (res.status !== 'started') {
+ // no-script / declined / unavailable: nothing runs, so nothing may wait on it.
+ setupWaitGroupsRef.current.delete(groupId)
+ return
+ }
+ useProjectSetup.getState().attachGroup(groupId, res.runKey)
+ // Only `waitForSetup` holds launches. Without it the script runs alongside whatever the
+ // user opens — which is the default, and the honest reading of a project that never asked
+ // its collaborators to wait.
+ if (res.waitForSetup) setupWaitGroupsRef.current.add(groupId)
+ else setupWaitGroupsRef.current.delete(groupId)
+ })
+ .catch(() => {
+ setupWaitGroupsRef.current.delete(groupId)
+ })
+ },
+ [ensureSetupSubscription]
+ )
+ /**
+ * Kick the `archive` script for a worktree that is about to be unbound or removed.
+ *
+ * TRADEOFF, deliberate: this awaits the LAUNCH RESULT (`started`/`skipped`) and nothing more. The
+ * script keeps running while the binding is dropped, and its completion is observed through the
+ * store like any other run. Awaiting completion instead would let a hung archive script trap the
+ * user in a group they asked to close — the removal is their decision, not the script's. The cost
+ * is that a slow script can still be writing when a `--delete from disk` removal pulls the
+ * directory out from under it; it then exits non-zero and says so in the chip.
+ */
+ const runWorktreeArchive = useCallback(
+ async (groupId: string, worktreePath: string): Promise<void> => {
+ const projectId = useProjects.getState().activeProjectId
+ if (!projectId) return
+ ensureSetupSubscription(projectId)
+ const res = await setupApi()
+ .run(projectId, 'archive', worktreePath)
+ .catch(() => null)
+ // The group is on its way out, so this attachment only serves the moment the chip is still
+ // on screen — and it must not be left pointing at the finished SETUP run while an archive
+ // script is live.
+ if (res?.status === 'started') useProjectSetup.getState().attachGroup(groupId, res.runKey)
+ },
+ [ensureSetupSubscription]
+ )
+
/**
* Everything a group owes the world when its worktree BINDING is dropped — minus the dropping
* itself, which each caller does its own way (clear `data.worktree`, dissolve the frame, delete
@@ -3928,6 +4050,9 @@ export function Canvas() {
async (groupId: string): Promise<void> => {
const wt = nodesRef.current.find((n) => n.id === groupId)?.data.worktree
if (!wt || isSshProject) return
+ // The project's `archive` script gets its chance BEFORE anything else — this is the one place
+ // every unbinding path passes through. Only the launch is awaited (see `runWorktreeArchive`).
+ await runWorktreeArchive(groupId, wt.path)
if (!useWorktrees.getState().staleGroupIds.includes(groupId)) return
resetDisplacedCwd(groupId, wt.path, false)
// A failed prune must still let the binding go — dropping it is the user's ask, and a
@@ -3936,7 +4061,7 @@ export function Canvas() {
.worktreeRemove(wt.repoPath, wt.path, false, true)
.catch(() => {})
},
- [isSshProject, resetDisplacedCwd]
+ [isSshProject, resetDisplacedCwd, runWorktreeArchive]
)
// ---- multi-node actions (context menu) ----
@@ -4227,11 +4352,15 @@ export function Canvas() {
}
markDirty()
refreshWorktreeStore({ bind: { groupId, worktree: wt } })
+ // A fresh checkout is the moment the project's `setup` script exists for: this is the single
+ // shared post-create point (the dialog AND agent-control's open-worktree land here), so the
+ // trigger lives here rather than being repeated — and never diverging — at each caller.
+ startWorktreeSetup(groupId, wt.path)
// The bound group's id (fresh one when created here) — nodesRef lags setNodes, so
// callers that need the id (agent-control's open-worktree reply) take it from here.
return groupId
},
- [setNodes, markDirty, viewCenter, refreshWorktreeStore]
+ [setNodes, markDirty, viewCenter, refreshWorktreeStore, startWorktreeSetup]
)
const createWorktreeAndGroup = useCallback(
@@ -4401,6 +4530,10 @@ export function Canvas() {
setNotice({ kind: 'info', text: `Unbound ${wt.branch}. The worktree is still on disk.` })
return
}
+ // 0) The `archive` script's last chance — after step 1 the directory is gone. Only its LAUNCH is
+ // awaited (see `runWorktreeArchive`), so a hung script cannot hold the removal hostage; the
+ // unbind-only branch above gets the same call through `releaseWorktreeBinding`.
+ await runWorktreeArchive(t.groupId, wt.path)
// 1) Remove the worktree FIRST; only delete the branch if the branch is ours (we created it).
// The sessions are killed after, not before: `worktreeRemove` can still REFUSE (a dangerous
// path, a locked worktree, EPERM), and killing every child terminal's tmux session up front
@@ -4446,7 +4579,14 @@ export function Canvas() {
resetDisplacedCwd(t.groupId, wt.path, true)
clearWorktreeBinding(t.groupId)
setNotice({ kind: res.ok ? 'info' : 'error', text: res.message })
- }, [removeTarget, deleteFromDisk, clearWorktreeBinding, resetDisplacedCwd, releaseWorktreeBinding])
+ }, [
+ removeTarget,
+ deleteFromDisk,
+ clearWorktreeBinding,
+ resetDisplacedCwd,
+ releaseWorktreeBinding,
+ runWorktreeArchive
+ ])
// Confirmed merge. The push is passed explicitly: `worktreeMerge` never publishes on its own, so
// what the dialog said is exactly what runs — and the result banner names the push either way.
@@ -6771,9 +6911,23 @@ export function Canvas() {
// `extraLive` names nodes being created in this same tick — `verify` arms its judge on
// reviewers that are not on the canvas yet, and without this they would look DELETED,
// which counts as satisfied, and the judge would fire before a single review existed.
- const armAfter = (node: CanvasNode, after: string[], extraLive?: Iterable<string>): CanvasNode => {
+ // `intoGroup` adds the SECOND reason to hold a launch: the node is being opened into a
+ // worktree frame whose project setup script is still preparing the checkout (and said
+ // `waitForSetup`). Same mechanism, same escape hatch on the node — see `awaitSetupGroup`.
+ const armAfter = (
+ node: CanvasNode,
+ after: string[],
+ extraLive?: Iterable<string>,
+ intoGroup?: string | null
+ ): CanvasNode => {
const command = node.data.initialCommand as string | undefined
- if (!after.length || !command) return node
+ if (!command) return node
+ // A group only counts while its acked run said `waitForSetup` AND that run has not finished.
+ const awaitSetupGroup =
+ intoGroup && setupWaitGroupsRef.current.has(intoGroup) && !setupDoneForGroup(intoGroup)
+ ? intoGroup
+ : undefined
+ if (!after.length && !awaitSetupGroup) return node
// If the wait is ALREADY over, don't arm at all — leave the command as the node's
// `initialCommand` so its own mount path delivers it through `writeWhenShellReady`
// (which waits for the shell prompt and echo-verifies). Arming would instead hand
@@ -6785,10 +6939,14 @@ export function Canvas() {
useAgentStatus.getState().byId,
live
)
- if (!unmet.length) return node
+ if (!unmet.length && !awaitSetupGroup) return node
return {
...node,
- data: { ...node.data, initialCommand: undefined, pendingLaunch: { after, command } }
+ data: {
+ ...node.data,
+ initialCommand: undefined,
+ pendingLaunch: { after, command, ...(awaitSetupGroup ? { awaitSetupGroup } : {}) }
+ }
}
}
// Open `count` nodes INTO a group frame: grow the frame FIRST (extent:'parent' would
@@ -6862,7 +7020,9 @@ export function Canvas() {
args.cmd,
sshFor(termCwd)
),
- after ?? []
+ after ?? [],
+ undefined,
+ intoGroupId
)
const ids = intoGroupId
? addGrouped(intoGroupId, count, make)
@@ -6913,7 +7073,9 @@ export function Canvas() {
account,
activePermissionMode(agentId)
),
- after ?? []
+ after ?? [],
+ undefined,
+ intoGroupId
)
const ids = intoGroupId
? addGrouped(intoGroupId, count, make)
diff --git a/src/renderer/lib/pendingLaunch.test.ts b/src/renderer/lib/pendingLaunch.test.ts
index 7966b2c66..bdc20e1eb 100644
--- a/src/renderer/lib/pendingLaunch.test.ts
+++ b/src/renderer/lib/pendingLaunch.test.ts
@@ -50,6 +50,59 @@ describe('launchesToFire', () => {
})
})
+describe('launchesToFire — awaitSetupGroup (a worktree whose setup script must land first)', () => {
+ const live = new Set(['a', 'c'])
+ const armedForSetup = (id: string, groupId: string, after: string[] = []): ArmedNode => ({
+ id,
+ data: { pendingLaunch: { after, command: `echo ${id}`, awaitSetupGroup: groupId } }
+ })
+
+ it('holds the launch while the group’s setup run is not done', () => {
+ expect(launchesToFire([armedForSetup('c', 'g1')], {}, live, () => false)).toEqual([])
+ })
+
+ it('fires once the group’s setup run is done', () => {
+ expect(launchesToFire([armedForSetup('c', 'g1')], {}, live, () => true)).toEqual([
+ { id: 'c', command: 'echo c' }
+ ])
+ })
+
+ it('with no setupDone probe at all, the gate is open — an absent probe never strands a node', () => {
+ // Reached after an app restart: the run store is empty, and a node armed before the restart
+ // would otherwise wait forever for a run nobody is going to report on again.
+ expect(launchesToFire([armedForSetup('c', 'g1')], {}, live)).toEqual([
+ { id: 'c', command: 'echo c' }
+ ])
+ })
+
+ it('asks the probe about THIS node’s group', () => {
+ const asked: string[] = []
+ launchesToFire([armedForSetup('c', 'g-seven')], {}, live, (g) => {
+ asked.push(g)
+ return true
+ })
+ expect(asked).toEqual(['g-seven'])
+ })
+
+ it('needs BOTH gates: setup done AND every `after` dep satisfied', () => {
+ const node = [armedForSetup('c', 'g1', ['a'])]
+ // setup done, dep still working
+ expect(launchesToFire(node, { a: { state: 'working' } }, live, () => true)).toEqual([])
+ // dep done, setup still running
+ expect(launchesToFire(node, { a: { state: 'done' } }, live, () => false)).toEqual([])
+ // both
+ expect(launchesToFire(node, { a: { state: 'done' } }, live, () => true)).toEqual([
+ { id: 'c', command: 'echo c' }
+ ])
+ })
+
+ it('leaves a node with no awaitSetupGroup alone even while some setup is running', () => {
+ expect(launchesToFire([armed('c', [])], {}, live, () => false)).toEqual([
+ { id: 'c', command: 'echo c' }
+ ])
+ })
+})
+
describe('unmetDeps', () => {
it('reports only the deps still outstanding', () => {
const live = new Set(['a', 'b', 'c'])
diff --git a/src/renderer/lib/pendingLaunch.ts b/src/renderer/lib/pendingLaunch.ts
index 936ffc10f..1bbd8de73 100644
--- a/src/renderer/lib/pendingLaunch.ts
+++ b/src/renderer/lib/pendingLaunch.ts
@@ -45,16 +45,29 @@ function depSatisfied(depId: string, status: StatusById, live: ReadonlySet<strin
* Which armed nodes are ready to launch, given the live canvas and the current agent states.
* `live` is passed in (rather than derived from `nodes`) because the caller already holds the
* full node list while `nodes` here may be pre-filtered.
+ *
+ * `setupDone` is the SECOND gate, for a node opened into a worktree frame whose project runs a
+ * setup script with `waitForSetup`: the node's command must not race an `npm ci` that is still
+ * writing node_modules underneath it. It answers per group id, and the two gates are ANDed —
+ * a node can be waiting on both its upstream stations and its checkout being ready.
+ *
+ * An ABSENT probe (`setupDone` not passed) means the gate is open. That is the honest default,
+ * not laxness: the run store is rebuilt from live events, so after an app restart a node armed
+ * with `awaitSetupGroup` has no run to hear from ever again, and reading "nothing known" as
+ * "still running" would strand it forever — the same reasoning as a deleted dependency counting
+ * as satisfied. (The caller's probe applies the same rule to a group with no entry.)
*/
export function launchesToFire(
nodes: readonly ArmedNode[],
status: StatusById,
- live: ReadonlySet<string>
+ live: ReadonlySet<string>,
+ setupDone?: (groupId: string) => boolean
): LaunchToFire[] {
const out: LaunchToFire[] = []
for (const n of nodes) {
const p = n.data.pendingLaunch
if (!p || !p.command) continue
+ if (p.awaitSetupGroup && !(setupDone?.(p.awaitSetupGroup) ?? true)) continue
if (p.after.every((d) => depSatisfied(d, status, live))) out.push({ id: n.id, command: p.command })
}
return out
diff --git a/src/renderer/nodes/GroupNode.tsx b/src/renderer/nodes/GroupNode.tsx
index d81871cb1..89a0cbeb3 100644
--- a/src/renderer/nodes/GroupNode.tsx
+++ b/src/renderer/nodes/GroupNode.tsx
@@ -4,6 +4,7 @@ import { NODE_MIN_SIZES } from '../lib/nodeSizing'
import { NODE_COLORS, ungroupNodes, type CanvasNode } from '../state/workspace'
import { useProjects } from '../state/projects'
import { useWorktrees, WORKTREE_STATUS_POLL_MS } from '../state/worktrees'
+import { useProjectSetup } from '../state/projectSetup'
export type WorktreeAction = 'merge' | 'remove' | 'unbind'
@@ -37,6 +38,14 @@ export function GroupNode({ id, data, selected }: NodeProps<CanvasNode>) {
// (WORKTREE_STATUS_THROTTLE_MS) and is epoch-guarded, so asking often is free.
const status = useWorktrees((s) => (wt ? s.statusByPath[wt.path] : undefined))
const stale = useWorktrees((s) => (wt ? s.staleGroupIds.includes(id) : false))
+ // The project setup/archive script Canvas launched for THIS checkout, resolved through the
+ // attachment its ack made (an event carries no lane — see the store's header). Selected as the
+ // entry itself, so a render happens only when this group's run changes, not on every chunk of
+ // every other project's script.
+ const setupRun = useProjectSetup((s) => {
+ const runKey = s.groupRunKey[id]
+ return runKey === undefined ? undefined : s.byRunKey[runKey]
+ })
// On an SSH project the poll is OFF, not merely useless: `git status <path>` would be answered by
// the LOCAL filesystem for a project whose checkout lives on the host (remote git routing is
@@ -211,6 +220,25 @@ export function GroupNode({ id, data, selected }: NodeProps<CanvasNode>) {
)}
</span>
)}
+ {setupRun && (
+ // What the project's script is doing to this checkout. Status only — the OUTPUT lives
+ // in the settings panel's run box (this is a frame header, not a log viewer), and the
+ // failed state is the one that has to be visible here: a node armed behind a failed
+ // setup is still holding its launch, and nothing else on the canvas says why.
+ <span
+ className={`group-node__setup group-node__setup--${setupRun.state}`}
+ title={
+ `${setupRun.kind === 'archive' ? 'Archive' : 'Setup'} script: ${setupRun.state}` +
+ (setupRun.exitCode === undefined ? '' : ` (exit ${setupRun.exitCode})`) +
+ (setupRun.state === 'failed'
+ ? '\nNodes waiting on it keep holding their launch — re-run it from Project settings.'
+ : '')
+ }
+ >
+ {setupRun.kind === 'archive' ? 'archive' : 'setup'}
+ {setupRun.state === 'running' ? ' …' : setupRun.state === 'done' ? ' ✓' : ' ✕'}
+ </span>
+ )}
{!stale && (
<button
className="group-node__wt-btn"
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index c1059e0c3..32bee2790 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -1383,9 +1383,14 @@ export function TerminalNode({
// it is armed, and by WHAT it is blocked — dep titles read straight off the live canvas, since
// "waits for term-17" tells the user nothing.
const pendingLaunch = data.pendingLaunch as PendingLaunch | undefined
- const pendingWaitingOn = (pendingLaunch?.after ?? [])
- .map((depId) => ((getNode(depId) as CanvasNode | undefined)?.data.title as string) || depId)
- .join(', ')
+ const pendingWaitingOn = [
+ ...(pendingLaunch?.after ?? []).map(
+ (depId) => ((getNode(depId) as CanvasNode | undefined)?.data.title as string) || depId
+ ),
+ // The other thing a launch can be held on: this worktree's project setup script. Named, or the
+ // tooltip on a setup-only hold would read "Waiting for to finish".
+ ...(pendingLaunch?.awaitSetupGroup ? ['the project setup script'] : [])
+ ].join(', ')
// Use the chat panel only for a chat-capable agent with a known session; otherwise the
// markdown-of-output view (computed in the capture effect below) is shown as a fallback.
const useChat = mdMode && showChat && !!status?.sessionId
diff --git a/src/renderer/state/projectSetup.test.ts b/src/renderer/state/projectSetup.test.ts
index 6ac9035d7..e1d6b4c23 100644
--- a/src/renderer/state/projectSetup.test.ts
+++ b/src/renderer/state/projectSetup.test.ts
@@ -145,6 +145,21 @@ describe('useProjectSetup — lane attachment', () => {
expect(useProjectSetup.getState().runForGroup('g1')!.tail).toBe('worktree\n')
})
+ it('a group lane follows its run through running → done (what the frame’s chip reads)', () => {
+ useProjectSetup.getState().attachGroup('g1', 'rk')
+ apply(ev({ seq: 1, chunk: 'npm ci\n' }))
+ expect(useProjectSetup.getState().runForGroup('g1')!.state).toBe('running')
+ apply(ev({ seq: 2, state: 'done', exitCode: 0 }))
+ const run = useProjectSetup.getState().runForGroup('g1')!
+ expect(run.state).toBe('done')
+ expect(run.exitCode).toBe(0)
+ // …and a FAILED archive run attached later replaces it, so the chip reports the newer one.
+ useProjectSetup.getState().attachGroup('g1', 'rk-archive')
+ apply(ev({ runKey: 'rk-archive', runId: 'run-c', kind: 'archive', seq: 1, state: 'failed', exitCode: 3 }))
+ expect(useProjectSetup.getState().runForGroup('g1')!.kind).toBe('archive')
+ expect(useProjectSetup.getState().runForGroup('g1')!.state).toBe('failed')
+ })
+
it('re-attaching moves a lane to the newer run', () => {
apply(ev({ seq: 1, chunk: 'old\n' }))
attachProject('p1', 'rk')
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index febb27922..d8386946c 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -5441,6 +5441,24 @@ body,
color: var(--warn);
}
+/* Project setup/archive script state for this checkout — same quiet weight as the status
+ suffixes above; only a failure earns a color. */
+.group-node__setup {
+ font-size: 12px;
+ font-weight: 600;
+ color: var(--muted);
+ cursor: help;
+}
+
+.group-node__setup--done {
+ color: var(--success);
+}
+
+.group-node__setup--failed,
+.group-node__setup--cancelled {
+ color: var(--warn);
+}
+
.group-node__wt-btn {
background: var(--surface-sunken);
border: 1px solid var(--border);
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 659f72d14..4dc4ba5f2 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -214,6 +214,16 @@ export interface PendingLaunch {
after: string[]
/** Delivered to the node's shell once the wait is over (agent CLI + prompt, or a plain command). */
command: string
+ /**
+ * Also wait for this worktree GROUP's project setup script to finish (`waitForSetup`). Set when
+ * the node is opened into a frame whose checkout is still being prepared — running a command in a
+ * half-installed worktree is the failure this gate exists to prevent. It names a group id, never
+ * a command: nothing here is ever executed, it only selects a run to ask about.
+ *
+ * A group with no run on record counts as done (`launchesToFire`), so a persisted arming that
+ * outlives the run's event stream — an app restart — releases rather than strands the node.
+ */
+ awaitSetupGroup?: string
}
export interface CanvasNodeState {