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.

refactor(chat): picker labels wait out the unconfirmed send; one upload-scope rule

reviewf793c834ba6e
diff --git a/src/renderer/components/kanban/CardModal.tsx b/src/renderer/components/kanban/CardModal.tsx
index d70fcfa09..a43f49f3c 100644
--- a/src/renderer/components/kanban/CardModal.tsx
+++ b/src/renderer/components/kanban/CardModal.tsx
@@ -34,10 +34,9 @@ import { useSession } from '../../session/session'
// use — NOT a bespoke resume path, so a click here gets the same WakeInputBuffer protection and
// retries. Importing one function out of the canvas node module is safe: TerminalNode.tsx already
// imports from `components/kanban/*`, and none of those re-import CardModal.
-import { sshConnectionScope, wakeHibernatedNode } from '../../nodes/TerminalNode'
+import { nodeUploadScope, wakeHibernatedNode } from '../../nodes/TerminalNode'
import { droppedPaths } from '../../terminal/file-drop'
import { requestTerminalFocusOnExit } from '../../terminal/useMdModeFocus'
-import { useProjects } from '../../state/projects'
import type { ProjectKanban } from '@shared/types'
import type { KanbanSession } from './KanbanView'
import { BoardLogPanel } from './BoardLogPanel'
@@ -553,11 +552,7 @@ export function CardModal({ session, columnTitle, board, onChangeBoard, onClose,
pathsForFiles={(files) =>
droppedPaths(files, {
sshRemoteTmux: !!session.spawn.sshRemoteTmux,
- projectId: session.spawn.sshRemoteTmux
- ? session.spawn.ssh
- ? sshConnectionScope(session.spawn.ssh)
- : useProjects.getState().activeProjectId
- : ''
+ projectId: session.spawn.sshRemoteTmux ? nodeUploadScope(session.spawn.ssh) : ''
})
}
onShowTerminal={() => {
diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsx
index a58b8b463..e5d168529 100644
--- a/src/renderer/components/kanban/ModalTerminal.tsx
+++ b/src/renderer/components/kanban/ModalTerminal.tsx
@@ -48,6 +48,7 @@ import {
} from '../../terminal/terminal-config'
import { useXtermVisualSettings } from '../../terminal/useXtermVisualSettings'
import {
+ nodeUploadScope,
owningProjectId,
resolveSshRemote,
reportSshDrop,
@@ -473,9 +474,7 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch, covere
let paths: string[]
if (spawn.sshRemoteTmux) {
// Uploads go over the master this card's PTY runs on — its scope, not the project's.
- const projectId = spawn.ssh
- ? sshConnectionScope(spawn.ssh)
- : useProjects.getState().activeProjectId
+ const projectId = nodeUploadScope(spawn.ssh)
setUploading(true)
try {
paths = await droppedPaths(files, { sshRemoteTmux: true, projectId })
diff --git a/src/renderer/nodes/ChatComposer.tsx b/src/renderer/nodes/ChatComposer.tsx
index 8dbbb3de0..0f055092a 100644
--- a/src/renderer/nodes/ChatComposer.tsx
+++ b/src/renderer/nodes/ChatComposer.tsx
@@ -38,6 +38,13 @@ export interface ChatComposerProps {
disabled: boolean
/** A picker command the pane refused outright (`sendText` → false): the session is not writable. */
onWriteRefused: () => void
+ /**
+ * A message was just sent and no hook event has confirmed the turn yet (ChatPanel's `optimistic`,
+ * #953). The gate still reads `done` in that window, but the agent is about to be working — a
+ * `/model` typed now would land in (or queue behind) the turn being started. The picker labels
+ * stand down until the real state speaks.
+ */
+ sendUnconfirmed?: boolean
/** See ChatPanelProps. */
pathsForFiles?: (files: File[]) => Promise<string[]>
/** See ChatPanelProps. */
@@ -61,6 +68,7 @@ export function ChatComposer({
placeholder,
disabled,
onWriteRefused,
+ sendUnconfirmed = false,
pathsForFiles,
onShowTerminal
}: ChatComposerProps) {
@@ -83,6 +91,8 @@ export function ChatComposer({
// plus Enter INTO the picker the first one just opened, and Enter confirms its highlighted
// option. The ref is the guard (read synchronously); the state only renders it.
const pickerBusyRef = useRef(false)
+ const sendUnconfirmedRef = useRef(sendUnconfirmed)
+ sendUnconfirmedRef.current = sendUnconfirmed
const [pickerBusy, setPickerBusy] = useState(false)
const labels = composerLabels({ agentId, model: usage?.model, effort: usage?.effort, width: composerWidth })
@@ -199,7 +209,7 @@ export function ChatComposer({
// answer it; into a shell it would run) — then flip to the terminal so the picker is in view.
const openPicker = useCallback(
async (picker: ComposerPicker) => {
- if (pickerBusyRef.current) return
+ if (pickerBusyRef.current || sendUnconfirmedRef.current) return
const command = composerPickerCommand(agentId, picker)
if (!command || !onShowTerminal) return
if (chatSendRefusal(agentId, useAgentStatus.getState().byId[nodeId] ?? {}) !== null) return
@@ -240,7 +250,7 @@ export function ChatComposer({
onSend()
}
- const labelDisabled = disabled || pickerBusy
+ const labelDisabled = disabled || pickerBusy || sendUnconfirmed
return (
<div className="term-chat__compose">
diff --git a/src/renderer/nodes/ChatPanel.composer.test.tsx b/src/renderer/nodes/ChatPanel.composer.test.tsx
index 52d503952..2ef32bd0e 100644
--- a/src/renderer/nodes/ChatPanel.composer.test.tsx
+++ b/src/renderer/nodes/ChatPanel.composer.test.tsx
@@ -394,6 +394,24 @@ describe('model / effort labels', () => {
expect(onShowTerminal).toHaveBeenCalledTimes(1)
})
+ it('stands the labels down in the unconfirmed-send window (#953): the turn is starting, not idle', async () => {
+ setUsage('claude-opus-5', 'high')
+ setAgentState('done')
+ await mount()
+ await act(async () => type(textarea(), 'go'))
+ await act(async () => {
+ textarea().dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }))
+ })
+ await flush()
+ expect(sendText).toHaveBeenCalledWith(NODE, 'go')
+ expect(modelBtn()!.disabled).toBe(true)
+ expect(effortBtn()!.disabled).toBe(true)
+ // The real state speaks (the turn ran and finished): the labels come back.
+ await act(async () => setAgentState('working'))
+ await act(async () => setAgentState('done'))
+ expect(modelBtn()!.disabled).toBe(false)
+ })
+
it('drops the effort label first, then the model label, as the composer narrows', async () => {
// Every observer (the thread's and the composer's) hears the resize, like the real thing.
const cbs: Array<(entries: Array<{ contentRect: { width: number } }>) => void> = []
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index f6eaef03f..69f6ba8bd 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -543,7 +543,12 @@ export function ChatPanel({
// the turn's last message. `now` is ONE clock for every row's relative time, ticked once a minute
// (a per-row timer would be a timer per turn for a label that changes once a minute).
const turnEnds = useMemo(() => assistantTurnEnds(messages), [messages])
- const latestTurnEnd = useMemo(() => Math.max(-1, ...turnEnds.keys()), [turnEnds])
+ // The last key IS the latest turn end: `assistantTurnEnds` inserts in thread order.
+ const latestTurnEnd = useMemo(() => {
+ let last = -1
+ for (const k of turnEnds.keys()) last = k
+ return last
+ }, [turnEnds])
const [now, setNow] = useState(() => Date.now())
useEffect(() => {
const t = setInterval(() => setNow(Date.now()), 60_000)
@@ -712,6 +717,7 @@ export function ChatPanel({
})}
disabled={readonly || refusal !== null}
onWriteRefused={onWriteRefused}
+ sendUnconfirmed={optimistic}
pathsForFiles={pathsForFiles}
onShowTerminal={onShowTerminal}
/>
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 5547dd74f..a56095395 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -293,6 +293,16 @@ export function sshConnectionScope(conn: SshConnection): string {
return sshConnectionIdForProject(activeProjectId, conn, getProject(activeProjectId)?.ssh?.server)
}
+/**
+ * Which ControlMaster a node's file uploads go over: its OWN connection's scope (for an attached
+ * node, the host attachment — not the local project), else the active project. ONE definition for
+ * the terminal drop, the card modal's live viewer and the ⌘M composer's attach, so the three can
+ * never upload one file to two different machines.
+ */
+export function nodeUploadScope(ssh: SshConnection | undefined): string {
+ return ssh ? sshConnectionScope(ssh) : useProjects.getState().activeProjectId
+}
+
/**
* The project whose per-project settings apply to a node in THIS canvas — for the launch-command
* layer (`agentLaunchOverride`) on relaunch, restart and wake.
@@ -5113,13 +5123,8 @@ export function TerminalNode({
const rt = e.relatedTarget as Node | null
if (!rt || !(e.currentTarget as HTMLElement).contains(rt)) setDropping(false)
}
- // Uploads go over the master this node's PTY runs on — its scope, which for an attached node is
- // the host attachment, not the (local) project. Shared by the terminal drop and the ⌘M composer's
- // attach, so the two can never upload one file to two different machines.
- const dropProjectId = (): string => {
- const dropConn = data.ssh as SshConnection | undefined
- return dropConn ? sshConnectionScope(dropConn) : useProjects.getState().activeProjectId
- }
+ // Uploads go over the master this node's PTY runs on (`nodeUploadScope`).
+ const dropProjectId = (): string => nodeUploadScope(data.ssh as SshConnection | undefined)
/**
* Files arriving by DROP or by PASTE become paths in the terminal — what a native terminal does
* on a drop, and the only thing a shell (or an agent reading its prompt) can act on. Shared so
diff --git a/src/renderer/nodes/uploadScope.source.test.ts b/src/renderer/nodes/uploadScope.source.test.ts
new file mode 100644
index 000000000..600299136
--- /dev/null
+++ b/src/renderer/nodes/uploadScope.source.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+
+/**
+ * One definition of which ControlMaster a node's file uploads go over (`nodeUploadScope`,
+ * TerminalNode.tsx). The terminal drop, the card modal's live viewer and the ⌘M composer's attach
+ * each spelled it inline once; a drift between the copies would upload one file to two machines.
+ * Source pins: none of the three can be mounted here.
+ */
+const read = (rel: string) => readFileSync(resolve(__dirname, rel), 'utf8').replace(/\r\n/g, '\n')
+
+describe('nodeUploadScope is the one upload-scope rule', () => {
+ it('is defined once, in TerminalNode, and the node drop path uses it', () => {
+ const src = read('./TerminalNode.tsx')
+ expect(src).toMatch(/export function nodeUploadScope\(ssh: SshConnection \| undefined\): string/)
+ expect(src).toMatch(/const dropProjectId = \(\): string => nodeUploadScope\(/)
+ })
+
+ it('the card modal viewer and the card modal composer attach use it too', () => {
+ expect(read('../components/kanban/ModalTerminal.tsx')).toMatch(/const projectId = nodeUploadScope\(spawn\.ssh\)/)
+ expect(read('../components/kanban/CardModal.tsx')).toMatch(/nodeUploadScope\(session\.spawn\.ssh\)/)
+ })
+})