Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(question): tell the window an agent is blocked, not just the device

0xdiego25e8b86e1ef42a
diff --git a/cli/src/backendSocket.spec.ts b/cli/src/backendSocket.spec.ts
index de3f56837..20f19d705 100644
--- a/cli/src/backendSocket.spec.ts
+++ b/cli/src/backendSocket.spec.ts
@@ -326,6 +326,40 @@ describe('BackendSocket outbound queue', () => {
await socket.stop()
})
+ it('hands a blocked agent to the window without putting the question on the cloud leg', async () => {
+ const socket = new BackendSocket('token')
+ expect(socket.hasLocalClient()).toBe(false)
+ const frames: Array<Record<string, unknown>> = []
+ socket.registerLocalClient('local:window', {
+ sendFrame: (frame) => { frames.push(frame); return true },
+ sendBinary: () => true,
+ })
+ // The watcher's whole gate: polling a pane for a dialog is waste with nobody rendering it, and
+ // "nobody" used to mean "no device" — which is what kept the window in the dark.
+ expect(socket.hasLocalClient()).toBe(true)
+
+ socket.connect()
+ const ws = wsMock.instances[0]
+ ws.open()
+ const asked = {
+ type: 'commander_question',
+ agentId: 'a1',
+ dbSessionId: 's1',
+ payload: { requestId: 'q_1', questions: [{ key: 'Which theme?', q: 'Which theme?', options: ['Blue', 'Red'], multi: false }] },
+ }
+ socket.sendLocal(asked)
+
+ // The window reads it in the clear, which is what loopback is for...
+ expect(frames).toContainEqual(asked)
+ // ...and it never reaches the relay. `commander_question` is deliberately NOT in ENCRYPTED_UP_TYPES,
+ // so `send()` here would have travelled the cloud leg as plaintext question text and option labels.
+ expect(parseSent(ws).some((item) => (item.frame as { type?: string })?.type === 'commander_question')).toBe(false)
+
+ await socket.unregisterLocalClient('local:window')
+ expect(socket.hasLocalClient()).toBe(false)
+ await socket.stop()
+ })
+
it('routes local terminal binary directly and preserves local streams when cloud disconnects', async () => {
vi.useFakeTimers()
const socket = new BackendSocket('token')
diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.ts
index 67f8df60a..d10ee5349 100644
--- a/cli/src/backendSocket.ts
+++ b/cli/src/backendSocket.ts
@@ -357,6 +357,16 @@ export class BackendSocket {
return this.commanderActive == null ? this.hasCommander() : this.commanderActive > 0
}
+ /** True while a desktop window on THIS computer is attached over loopback.
+ *
+ * Separate from `hasCommander()` on purpose: a device and a window are different audiences that
+ * happen to want some of the same work done. The question watcher is the first thing to need it —
+ * polling a pane for a dialog is pointless with nobody rendering it, but "nobody" used to mean
+ * "no device", which left the window unable to learn that an agent was blocked. */
+ hasLocalClient(): boolean {
+ return this.localClients.size > 0
+ }
+
/** True after a paired device has completed the E2EE hello/welcome session. */
deviceE2eeConnected(): boolean {
return this.e2ee.deviceConnected()
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 5374da035..a41ead4f6 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -1103,6 +1103,8 @@ async function runForeground(session: AuthSession): Promise<void> {
const cableWatchingLocal = (): boolean => cableRef?.isConnected === true
const deviceIsWatching = (): boolean => backend.hasCommander() || cableWatchingLocal()
+ /** Anyone who can DRAW a question: a device, a cabled dial, or a desktop window on this computer. */
+ const someoneCanAnswer = (): boolean => deviceIsWatching() || backend.hasLocalClient()
const terminalStreams = new TerminalStreamManager({
terminals,
resolveAgent: (agentId) => registry.resolve(agentId),
@@ -1594,29 +1596,47 @@ async function runForeground(session: AuthSession): Promise<void> {
const questionWatcher = new QuestionWatcher({
getSession: (id) => registry.resolve(id),
capture: captureTerminal,
- hasDevice: () => deviceIsWatching(),
+ hasDevice: () => someoneCanAnswer(),
isDriving: (sessionId) => questions.isDriving(sessionId),
onQuestion: (sessionId, requestId, shaped) => {
questions.remember(requestId, sessionId)
showAwaitingAnswer(sessionId)
- backend.sendCommander({
+ const asked = {
type: 'commander_question',
agentId: agentIdFor(sessionId),
dbSessionId: sessionId,
payload: { requestId, questions: shaped },
- })
+ }
+ backend.sendCommander(asked)
+ // ...and to the window on this computer. `sendCommander` is `webEligible: false`, so until this
+ // second call the app could not learn that an agent was blocked even though the question had
+ // already been shaped for the dial.
+ //
+ // `sendLocal`, not `send`: the question and its option labels are user content, and the only
+ // audience `send` would add beyond loopback is the cloud leg, where this frame would travel
+ // PLAINTEXT — `commander_question` is deliberately absent from ENCRYPTED_UP_TYPES, and putting it
+ // there means re-deriving an interop hash pinned by the browser client and the device firmware in
+ // two other repositories. Loopback needs no envelope, and it costs nothing that is reachable
+ // today: a remote machine's watcher is gated on ITS OWN audience, which a window attached over
+ // here is not part of either way.
+ backend.sendLocal(asked)
console.log(`[question] ${sid(sessionId)} asking the user · "${preview(shaped[0]?.q ?? '')}" · req=${requestId}`)
},
// Answered somewhere else — the app, or the pane by hand. Every client drawing it is told to stop
// waiting, down the SAME path the question itself took, so the dial and the WiFi device cannot
// disagree about whether a question is still open.
onQuestionGone: (sessionId, requestId) => {
- backend.sendCommander({
+ const closed = {
type: 'commander_question_close',
agentId: agentIdFor(sessionId),
dbSessionId: sessionId,
payload: { requestId },
- })
+ }
+ backend.sendCommander(closed)
+ // Down the SAME two paths the question took, so no client is left drawing a dialog that another
+ // one already answered. This is the mechanism behind "answer anywhere": the dial is cabled to
+ // this very computer, so the dial and this window are always the same machine's audience.
+ backend.sendLocal(closed)
console.log(`[question] ${sid(sessionId)} answered elsewhere · closing on every client · req=${requestId}`)
},
})