Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
21a80a6
fix(orchestration): never press Enter on text the person typed into t…
radut Nov 5, 2026
e33cddb
feat(orchestration): deliver mail to Claude terminals as their own tu…
radut Nov 5, 2026
93f751a
fix(orchestration): hold typed delivery five seconds after a keystrok…
radut Nov 5, 2026
176da48
fix(orchestration): settle a pointer whose channel lookup throws, and…
radut Nov 5, 2026
21ccece
fix(orchestration): hand back mail the Claude plugin polled for a ses…
radut Nov 5, 2026
3c93946
fix(orchestration): release mail that never reached the agent, and en…
radut Nov 5, 2026
4e586ba
fix(orchestration): ack polled Claude mail as not submitted when the …
radut Nov 5, 2026
88634b9
Merge remote-tracking branch 'origin/main' into orchestration-pointer…
radut Nov 5, 2026
854558f
Merge remote-tracking branch 'origin/main' into orchestration-pointer…
radut Nov 5, 2026
7c7464e
Merge remote-tracking branch 'origin/main' into orchestration-pointer…
radut Nov 6, 2026
86ec26d
Merge remote-tracking branch 'origin/main' into orchestration-pointer…
radut Nov 6, 2026
e320f39
Merge remote-tracking branch 'origin/main' into HEAD
radut Nov 7, 2026
515d48c
Merge origin/main into orchestration-pointer-typing-race
radut Nov 8, 2026
c25dbc0
Merge origin/main into orchestration-pointer-typing-race
radut Nov 8, 2026
3a6e6aa
Merge remote-tracking branch 'origin/main' into HEAD
radut Nov 9, 2026
0c616fa
fix: follow the hook server and run facts to their new folders
radut Nov 9, 2026
2240a1c
Merge remote-tracking branch 'origin/main' into HEAD
radut Nov 9, 2026
759fc52
Merge remote-tracking branch 'origin/main' into orchestration-pointer…
radut Nov 11, 2026
4d529d4
test(orchestration): drop casts from the parked-pointer and mail-hook…
radut Nov 11, 2026
082b7f0
Merge remote-tracking branch 'origin/main' into HEAD
radut Nov 13, 2026
942dbc1
test(orchestration): build the parked-pointer and typing tests from r…
radut Nov 13, 2026
d1499ce
Merge remote-tracking branch 'origin/main' into HEAD
radut Nov 14, 2026
ad67c08
Merge upstream main 8e693efda41 into orchestration-pointer-typing-race
radut Nov 15, 2026
b426d5e
Merge remote-tracking branch 'origin/main' into orchestration-pointer…
radut Nov 18, 2026
af502ab
Merge upstream main into orchestration-pointer-typing-race
radut Nov 18, 2026
b70717f
Merge remote-tracking branch 'origin/main' into orchestration-pointer…
radut Nov 22, 2026
986dcfd
Merge remote-tracking branch 'origin/main' into fix/orchestration-poi…
radut Nov 22, 2026
9410241
Merge remote-tracking branch 'origin/main' into orchestration-pointer…
radut Nov 23, 2026
56374ab
Merge remote-tracking branch 'origin/main' into fix/orchestration-poi…
radut Nov 23, 2026
88ee049
fix(orchestration): keep runtime-service-state under the line limit
radut Nov 23, 2026
cafb183
Merge orchestration-pointer-typing-race-r7 into orchestration-pointer…
radut Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/agent-hooks/server/server-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { clearAllListenerCaches } from '../../../shared/agent-hook-listener/list
import { trackEmptyPaneKeyHook } from './server-transport-rules'
import { AgentHookServerStatusHookLifecycle } from './server-status-hook-lifecycle'
import { OPENCODE_STARTUP_PROMPT_CLAIM_PATH } from '../../../shared/agent-launch/startup/opencode-startup-prompt'
import { CLAUDE_AGENT_VIEW_PATH } from '../../../shared/claude-agent-view'
import { respondAfterAgentToolPluginHooks } from '../agent-tool-plugin-hooks'

import type { HookServerStartOptions } from './server-types'
Expand Down Expand Up @@ -103,9 +102,10 @@ export abstract class AgentHookServerLifecycle extends AgentHookServerStatusHook
res.end()
return
}
if (pathname === CLAUDE_AGENT_VIEW_PATH) {
const claudePluginReply = this.receiveClaudePlugin(pathname, body)
if (claudePluginReply) {
res.writeHead(200, { 'content-type': 'application/json' })
res.end(JSON.stringify(this.claudeAgentViews.receive(body)))
res.end(JSON.stringify(claudePluginReply))
return
}
await this.initializeStatusHookOwner()
Expand Down Expand Up @@ -247,7 +247,7 @@ export abstract class AgentHookServerLifecycle extends AgentHookServerStatusHook
/** Quit retains status until chat teardown reads resumable child and background work. */
stop(options?: { keepStatus?: boolean }): void {
this.startup.stop()
this.claudeAgentViews.clear()
this.clearClaudePlugins()
// Terminal status may still have a pending write while hook ingress is disabled.
if (this.statusHooksEnabled || this.statusPersistTimer) {
this.flushStatusPersistSync()
Expand Down
21 changes: 20 additions & 1 deletion src/main/agent-hooks/server/server-status-hook-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@ import {
import { hookRootAnswerDeadline } from '../../../shared/agent-hook-listener/presence/hook-root-attempts'
import { AgentHookServerRuntimeEnv } from './server-runtime-env'
import { ClaudeAgentViewBridge } from '../../claude/agent-view/agent-view-bridge'
import { ClaudeTerminalMailBridge } from '../../claude/terminal-mail/claude-terminal-mail-bridge'
import {
CLAUDE_AGENT_VIEW_PATH,
CLAUDE_TERMINAL_MAIL_PATH
} from '../../../shared/claude-agent-view'

export abstract class AgentHookServerStatusHookLifecycle extends AgentHookServerRuntimeEnv {
readonly claudeAgentViews = new ClaudeAgentViewBridge()
readonly claudeTerminalMail = new ClaudeTerminalMailBridge()
private statusHookInitialization: Promise<void> | null = null

/** The reply to a request from Orca's Claude plugin, or null when `pathname` is not one of its. */
protected receiveClaudePlugin(pathname: string, body: unknown): object | null {
if (pathname === CLAUDE_AGENT_VIEW_PATH) {
return this.claudeAgentViews.receive(body)
}
return pathname === CLAUDE_TERMINAL_MAIL_PATH ? this.claudeTerminalMail.receive(body) : null
}

protected clearClaudePlugins(): void {
this.claudeAgentViews.clear()
this.claudeTerminalMail.clear()
}

setStatusHooksEnabled(enabled: boolean): void {
if (enabled === this.statusHooksEnabled) {
return
}
this.statusHookGeneration += 1
if (!enabled) {
this.claudeAgentViews.clear()
this.clearClaudePlugins()
this.flushStatusPersistSync()
this.stopOpenCodeBinderLoop()
for (const timer of this.assistantMessageRetryTimers.values()) {
Expand Down
72 changes: 72 additions & 0 deletions src/main/claude/agent-view/agent-view-mod-source-mail.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { runInNewContext } from 'node:vm'
import { expect, it, vi } from 'vitest'
import { CLAUDE_TERMINAL_MAIL_PATH } from '../../../shared/claude-agent-view'
import { CLAUDE_AGENT_VIEW_MOD_SOURCE } from './agent-view-mod-source'

type Hook = (api: unknown, event: object, next: () => Promise<object>) => Promise<unknown>
type On = (
event: string,
matcherOrHook: Hook | { command: string } | { component: string },
hook?: Hook
) => void

it('submits polled orchestration mail as a prompt of its own and acknowledges it', async () => {
const handlers = new Map<string, Hook>()
const register: (on: On) => void = runInNewContext(
`${CLAUDE_AGENT_VIEW_MOD_SOURCE.replace('export function register', 'function register')}\nregister`
)
register((event, matcherOrHook, hook) => {
const handler = typeof matcherOrHook === 'function' ? matcherOrHook : hook
if (handler) {
handlers.set(event, handler)
}
})
const timers: { ms: number; tick: () => Promise<unknown> }[] = []
const posts: { url: string; body: Record<string, unknown> }[] = []
const submit = vi.fn(async () => ({ text: 'ok' }))
const api = {
// No Claude config dir: the agent view stays off, mail still flows.
env: {
get: async (key: string) =>
({
ORCA_PANE_KEY: 'tab:11111111-1111-4111-8111-111111111111',
ORCA_AGENT_HOOK_PORT: '1234',
ORCA_AGENT_HOOK_TOKEN: 'test-token'
})[key]
},
session: { id: async () => 'session-1' },
clock: {
now: async () => 1_700_000_000_000,
every: (ms: number, tick: () => Promise<unknown>) => timers.push({ ms, tick })
},
prompt: { submit },
http: {
fetch: async (url: string, options: { body: string }) => {
const body = JSON.parse(options.body)
posts.push({ url, body })
const reply =
body.action === 'poll'
? { submissions: [{ id: 'sub-1', text: 'You have 1 message.' }] }
: {}
return { ok: true, text: JSON.stringify(reply) }
}
}
}

await handlers.get('session.start')?.(
api,
{ isInteractive: true, surface: 'terminal' },
async () => ({})
)
const mailTick = timers.find((timer) => timer.ms === 1000)
await mailTick?.tick()

expect(submit).toHaveBeenCalledWith({ text: 'You have 1 message.' })
expect(
posts.map(({ url, body }) => [url.endsWith(CLAUDE_TERMINAL_MAIL_PATH), body.action])
).toEqual([
[true, 'poll'],
[true, 'ack']
])
expect(posts[1]?.body).toMatchObject({ id: 'sub-1', submitted: true, sessionId: 'session-1' })
})
44 changes: 41 additions & 3 deletions src/main/claude/agent-view/agent-view-mod-source.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { CLAUDE_AGENT_VIEW_PATH } from '../../../shared/claude-agent-view'
import {
CLAUDE_AGENT_VIEW_PATH,
CLAUDE_TERMINAL_MAIL_PATH
} from '../../../shared/claude-agent-view'
import { parseAgentHookEndpointFile } from '../../../shared/agent-hook-listener/transport/agent-hook-endpoint-file'

export const CLAUDE_AGENT_VIEW_MOD_SOURCE = String.raw`
Expand All @@ -10,8 +13,11 @@ let paneKey
let endedSessionId
let observedView
let viewRevision = 0
let mailIdentity
let mailPolling = false
let mailTimerStarted = false

async function post($, action, data = {}, session = identity) {
async function post($, action, data = {}, session = identity, path = ${JSON.stringify(CLAUDE_AGENT_VIEW_PATH)}) {
if (!session) return {}
let port = await $.env.get('ORCA_AGENT_HOOK_PORT')
let token = await $.env.get('ORCA_AGENT_HOOK_TOKEN')
Expand All @@ -24,7 +30,7 @@ let viewRevision = 0
} catch {}
}
if (!token || !/^[0-9]+$/.test(String(port)) || Number(port) < 1 || Number(port) > 65535) return {}
const response = await $.http.fetch('http://127.0.0.1:' + port + ${JSON.stringify(CLAUDE_AGENT_VIEW_PATH)}, {
const response = await $.http.fetch('http://127.0.0.1:' + port + path, {
method: 'POST',
headers: { 'content-type': 'application/json', 'x-orca-agent-hook-token': token },
body: JSON.stringify({ ...session, action, ...data })
Expand Down Expand Up @@ -57,6 +63,32 @@ let viewRevision = 0
}
}

// Orchestration mail arrives as a turn of its own: nothing is typed into the terminal.
async function pollMail($) {
if (mailPolling || !paneKey) return
mailPolling = true
try {
const sessionId = await $.session.id()
if (sessionId === endedSessionId) return
if (!mailIdentity || mailIdentity.sessionId !== sessionId) {
mailIdentity = { paneKey, sessionId, instanceId: String(await $.clock.now()) + '-' + String(Math.random()) }
}
const session = mailIdentity
const reply = await post($, 'poll', {}, session, ${JSON.stringify(CLAUDE_TERMINAL_MAIL_PATH)})
for (const item of Array.isArray(reply.submissions) ? reply.submissions : []) {
let submitted = false
try {
const result = await $.prompt.submit({ text: String(item.text) })
submitted = !result || !result.drop
} catch {}
await post($, 'ack', { id: String(item.id), submitted }, session, ${JSON.stringify(CLAUDE_TERMINAL_MAIL_PATH)})
}
} catch {
} finally {
mailPolling = false
}
}

export function register(on) {
on('ui.render', { component: 'AbovePrompt' }, async ($, event, next) => {
if (!paneKey) return next(event)
Expand All @@ -79,6 +111,10 @@ export function register(on) {
const targetPane = await $.env.get('ORCA_PANE_KEY')
if (!event.isInteractive || event.surface !== 'terminal' || !targetPane) return result
paneKey = targetPane
if (!mailTimerStarted) {
mailTimerStarted = true
$.clock.every(1000, () => pollMail($))
}
configDir = await $.env.get('CLAUDE_CONFIG_DIR') || await $.env.get('ORCA_CLAUDE_CONFIG_DIR')
if (!configDir) return result
endedSessionId = undefined
Expand Down Expand Up @@ -109,6 +145,8 @@ export function register(on) {
const session = identity
const result = await next(event)
void post($, 'end', {}, session).catch(() => {})
void post($, 'end', {}, mailIdentity, ${JSON.stringify(CLAUDE_TERMINAL_MAIL_PATH)}).catch(() => {})
mailIdentity = undefined
endedSessionId = event.sessionId
identity = undefined
if (event.reason !== 'clear' && event.reason !== 'resume') paneKey = undefined
Expand Down
47 changes: 47 additions & 0 deletions src/main/claude/terminal-mail/claude-terminal-mail-bridge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { ClaudeTerminalMailBridge } from './claude-terminal-mail-bridge'

const pane = {
paneKey: 'tab-1:11111111-1111-4111-8111-111111111111',
sessionId: 's1',
instanceId: 'i1'
}

describe('Claude terminal mail bridge', () => {
afterEach(() => vi.useRealTimers())

it('hands a submission to the polling plugin and settles it on its ack', async () => {
const bridge = new ClaudeTerminalMailBridge()
bridge.receive({ ...pane, action: 'poll' })
const outcome = bridge.submit(pane.paneKey, 'You have 1 orchestration message.')

const { submissions } = bridge.receive({ ...pane, action: 'poll' })
expect(submissions).toEqual([
{ id: expect.any(String), text: 'You have 1 orchestration message.' }
])
expect(bridge.receive({ ...pane, action: 'poll' }).submissions).toEqual([])
bridge.receive({ ...pane, action: 'ack', id: submissions?.[0]?.id, submitted: true })
await expect(outcome).resolves.toBe('submitted')
})

it('refuses a pane whose plugin is not polling, so delivery can take another way', async () => {
vi.useFakeTimers()
const bridge = new ClaudeTerminalMailBridge()
await expect(bridge.submit(pane.paneKey, 'x')).resolves.toBe('refused')
bridge.receive({ ...pane, action: 'poll' })
vi.advanceTimersByTime(6000)
expect(bridge.isLive(pane.paneKey)).toBe(false)
})

it('reports a taken submission as unverifiable when its Claude session goes away', async () => {
const bridge = new ClaudeTerminalMailBridge()
bridge.receive({ ...pane, action: 'poll' })
const taken = bridge.submit(pane.paneKey, 'polled')
bridge.receive({ ...pane, action: 'poll' })
const untaken = bridge.submit(pane.paneKey, 'after the poll')
bridge.receive({ ...pane, sessionId: 's2', action: 'poll' })

await expect(taken).resolves.toBe('unverifiable')
await expect(untaken).resolves.toBe('refused')
})
})
Loading