Skip to content
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
e00299d
fix(native-chat): a host admits structured sessions by client capabil…
brennanb2025 Sep 30, 2026
8782739
fix(native-chat): the desktop declares structured chat support to pai…
brennanb2025 Sep 30, 2026
1988466
feat(native-chat): open structured chats on the paired server that ow…
brennanb2025 Sep 30, 2026
ffab3a8
fix(native-chat): negotiate client-chosen launch mode so released pho…
brennanb2025 Sep 30, 2026
c4823ed
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Sep 30, 2026
a846f4a
refactor(runtime): keep the Electron client capability list in its ow…
brennanb2025 Sep 30, 2026
875a23f
fix(native-chat): the desktop declares it picks each launch mode itself
brennanb2025 Sep 30, 2026
480897a
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Sep 30, 2026
07946e3
fix(native-chat): pin each structured chat to the host it was launche…
brennanb2025 Sep 30, 2026
5abcba9
fix(native-chat): a paired server that declines a chat opens its term…
brennanb2025 Sep 30, 2026
22d1964
test(native-chat): a provisional chat carries its launch's host and h…
brennanb2025 Sep 30, 2026
a39d226
chore(native-chat): justify the two type assertions this change's lin…
brennanb2025 Sep 30, 2026
58ae4e3
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Sep 30, 2026
2341574
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Sep 30, 2026
b08eddf
test(native-chat): state why each staged test fixture is cast
brennanb2025 Sep 30, 2026
91811d6
fix(native-chat): chats that already exist keep showing whatever the …
brennanb2025 Sep 30, 2026
79dd0dc
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Sep 30, 2026
854e6f8
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Sep 30, 2026
ed6af4f
fix(native-chat): the browser client keeps its host terminal on paire…
brennanb2025 Sep 30, 2026
dad00a3
fix(native-chat): a retried launch a paired server declines opens its…
brennanb2025 Sep 30, 2026
d2b7a9d
Merge remote-tracking branch 'origin/main' into brennanb2025/structur…
brennanb2025 Sep 30, 2026
005c54f
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Sep 30, 2026
d810ca8
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Sep 30, 2026
8fffd01
refactor(native-chat): a paired host's cancelled-chat record ends on …
brennanb2025 Sep 30, 2026
9055c5c
fix(native-chat): a chat's pane and status read from the host recorde…
brennanb2025 Sep 30, 2026
ebbda60
fix(native-chat): "Resume in chat" follows the terminal resume's host…
brennanb2025 Sep 30, 2026
0a8f10a
fix(native-chat): the chat setting says older paired servers keep ter…
brennanb2025 Sep 30, 2026
f99d968
test(native-chat): pin that a host advertises the client-chosen launc…
brennanb2025 Sep 30, 2026
c1df7ee
fix(native-chat): mirror this machine's chats only where it holds them
brennanb2025 Sep 30, 2026
4fee1b7
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Sep 30, 2026
58bd806
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Sep 30, 2026
10dccb6
test(native-chat): route a paired-server launch over the capability l…
brennanb2025 Sep 30, 2026
1b2f895
test(native-chat): record install listeners without a cast
brennanb2025 Sep 30, 2026
72aaea9
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Sep 30, 2026
c4ea414
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Sep 30, 2026
0724426
fix(native-chat): a paired server admits a chat before any of it exis…
brennanb2025 Sep 30, 2026
9799f41
Merge origin/main into brennanb2025/structured-chat-capability-admission
brennanb2025 Sep 30, 2026
81c1ba5
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Sep 30, 2026
8b92f98
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Sep 30, 2026
4bcad89
fix(native-chat): mirror this machine's chats only once it holds one,…
brennanb2025 Oct 1, 2026
00f8412
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Oct 1, 2026
c9bfaf9
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 1, 2026
3d9d275
fix(native-chat): a fork's reveal never seeds a terminal beside the s…
brennanb2025 Oct 1, 2026
41114bf
fix(native-chat): a declined direct launch keeps the caller's CLI arg…
brennanb2025 Oct 1, 2026
356dc4c
fix(native-chat): a declined background create opens its terminal wit…
brennanb2025 Oct 1, 2026
a0e8f02
Merge origin/main into brennanb2025/structured-chat-capability-admission
brennanb2025 Oct 1, 2026
d8947e2
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 1, 2026
0736a37
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Oct 1, 2026
7145de4
test(native-chat): name the launch's host in main's new outbox fence …
brennanb2025 Oct 1, 2026
65c1997
fix(native-chat): a paired server's new chat shows no model until the…
brennanb2025 Oct 1, 2026
8f8b0d6
test(native-chat): seed the paired repo without a cast
brennanb2025 Oct 1, 2026
c64f5d9
feat(native-chat): createSupport reports the saved selection a new ch…
brennanb2025 Oct 1, 2026
3c31e82
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Oct 1, 2026
d4d0138
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 1, 2026
7ab54fa
fix(native-chat): a paired server's new chat shows the selection the …
brennanb2025 Oct 1, 2026
28e03f3
test(native-chat): expect the launch intent's new seed argument in ex…
brennanb2025 Oct 1, 2026
884cfa8
refactor(protocol): move the Electron remote client capability list i…
brennanb2025 Oct 1, 2026
f80482b
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Oct 1, 2026
002e02e
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 1, 2026
d1891ee
Merge remote-tracking branch 'origin/main' into brennanb2025/structur…
brennanb2025 Oct 1, 2026
2d320ef
fix(native-chat): a paired chat with no saved server model is pickabl…
brennanb2025 Oct 1, 2026
6cfb870
test(cross-version): stub the launch seed resolver createSupport now …
brennanb2025 Oct 1, 2026
401da30
test(protocol): pin the desktop capability divergence against what a …
brennanb2025 Oct 1, 2026
b28b740
fix(native-chat): the desktop tells its own host it picks each launch…
brennanb2025 Oct 1, 2026
7fdebc8
docs(native-chat): name the real exit for the released-phone createSu…
brennanb2025 Oct 1, 2026
96747fd
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 1, 2026
b42259d
Merge branch 'brennanb2025/structured-chat-capability-admission' into…
brennanb2025 Oct 1, 2026
b7cb6a4
fix(native-chat): the route reads the capabilities a paired host actu…
brennanb2025 Oct 1, 2026
ccf37e3
test(cross-version): a released client still gets the host-setting cr…
brennanb2025 Oct 1, 2026
b3f91fd
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 1, 2026
ee97f6a
test(native-chat): let main's child-records test resolve each chat's …
brennanb2025 Oct 1, 2026
bfc8cb9
fix(deps): take #24204's lockfile that the merge reverted
brennanb2025 Oct 1, 2026
9421cfb
Merge remote-tracking branch 'origin/brennanb2025/structured-chat-cap…
brennanb2025 Oct 1, 2026
ac8e493
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 1, 2026
dadca41
test(native-chat): let the Codex child-approval e2e unit test resolve…
brennanb2025 Oct 1, 2026
2cf4fb3
Merge remote-tracking branch 'origin/main' into brennanb2025/remote-s…
brennanb2025 Oct 2, 2026
1c6f120
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 2, 2026
78723c8
Merge remote-tracking branch 'origin/main' into brennanb2025/remote-s…
brennanb2025 Oct 3, 2026
4f7ae90
Merge branch 'brennanb2025/remote-structured-chat-drive' into brennan…
brennanb2025 Oct 3, 2026
9b705cb
Merge remote-tracking branch 'origin/main' into brennanb2025/remote-s…
brennanb2025 Oct 3, 2026
6b7492b
Merge remote-tracking branch 'origin/main' into brennanb2025/remote-s…
brennanb2025 Oct 3, 2026
28502e6
test(native-chat): move the close-race launch cases into their own file
brennanb2025 Oct 3, 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
10 changes: 8 additions & 2 deletions src/main/agent-launch/agent-launch-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ const BLOCKER_REASON: Record<
'remote-execution-host': 'remote_execution_host',
'project-runtime': 'wsl_execution_runtime',
'runtime-capability': 'structured_sessions_unavailable',
'runtime-capability-unknown': 'structured_support_unknown'
'runtime-capability-unknown': 'structured_support_unknown',
'client-capability': 'structured_sessions_unavailable'
}

/** The host's own create-support verdict (`agentSession.createSupport`) in this vocabulary. */
Expand Down Expand Up @@ -138,11 +139,16 @@ export function decideAgentLaunchMode(args: {
detail: `Started ${vocabulary.terminal}, the default for new agent tabs in your settings.`
}
}
// A worker placed on another runtime starts through federation, which creates terminal agents
// only; this host cannot answer for that runtime's structured support.
if (placement.on) {
return downgraded('remote_execution_host', vocabulary)
}
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: an unrecognized agent name is handled rather than trusted; isAgentSessionHandleProvider rejects it and the launch downgrades to a terminal.
const agent = placement.agent as TuiAgent
const support = resolveStructuredNativeChatSupport({
agent,
executionHostId: placement.on ? `runtime:${placement.on}` : 'local',
executionHostId: 'local',
reusesTerminal: Boolean(placement.terminal),
hostCapabilities: RUNTIME_CAPABILITIES,
// The floating workspace has nowhere to keep a session, so it is decided here rather than left
Expand Down
69 changes: 36 additions & 33 deletions src/main/ipc/desktop-renderer-runtime-capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@
import { describe, expect, it } from 'vitest'
import {
AGENT_LAUNCH_RUNTIME_CAPABILITY,
AGENT_SESSION_BACKGROUND_TASK_ROW_STOP_CAPABILITY,
AGENT_SESSION_BACKGROUND_TASK_STOP_CAPABILITY,
AGENT_SESSION_BOUNDARY_RUNTIME_CAPABILITY,
AGENT_SESSION_TURN_ITEM_CAPABILITY,
AUTOMATION_CREATE_IDEMPOTENCY_RUNTIME_CAPABILITY,
AUTOMATION_OWNER_FENCING_RUNTIME_CAPABILITY,
BROWSER_CLIENT_HOST_RUNTIME_CAPABILITY,
BROWSER_CLIENT_PAGE_METADATA_RUNTIME_CAPABILITY,
CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY,
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY,
SESSION_TABS_AUTHORITATIVE_INVENTORY_RUNTIME_CAPABILITY,
SESSION_TABS_RETIREMENT_PROOF_DELTA_RUNTIME_CAPABILITY,
STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY,
SKILL_INSTALL_RESULT_V2_CAPABILITY,
WORKTREE_BACKGROUND_REMOVAL_RUNTIME_CAPABILITY,
WORKTREE_GITHUB_PR_SUPPRESSION_RUNTIME_CAPABILITY,
WORKTREE_VISIBILITY_DEFAULTS_RUNTIME_CAPABILITY,
WORKTREE_VISIBILITY_SOURCE_DEFAULTS_RUNTIME_CAPABILITY,
type RuntimeCapability
} from '../../shared/protocol-version'
import { AGENT_SESSION_BACKGROUND_TASK_CHILD_VIEWS_CAPABILITY } from '../../shared/agent-session-background-task-child-views-capability'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import { remoteRuntimeClientCapabilities } from '../../shared/remote-runtime-client-capabilities'
import { supportsAgentLaunch } from '../runtime/rpc/methods/agent-launch'
import { createSupportFollowsHostSetting } from '../runtime/rpc/methods/structured-agent-session-policy'
import { DESKTOP_RENDERER_RUNTIME_CLIENT_CAPABILITIES } from './desktop-renderer-runtime-capabilities'

// Every paired transport sends the shared base plus the Electron list, so compare the union.
const PAIRED_HOST_RECEIVES = remoteRuntimeClientCapabilities(
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES
)

/** Advertised to a remote host and deliberately NOT to main: each would change local behaviour or
* has no local meaning. Adding to this set is a decision; leaving it out of both lists is not. */
const REMOTE_ONLY_BY_DECISION: readonly RuntimeCapability[] = [
Expand All @@ -52,19 +55,12 @@ const REMOTE_ONLY_BY_DECISION: readonly RuntimeCapability[] = [
SESSION_TABS_RETIREMENT_PROOF_DELTA_RUNTIME_CAPABILITY,
// Main marks `removing` on its own worktree IPC listings unconditionally; the renderer never
// lists its own host's worktrees over runtime RPC, where this capability decides mark vs omit.
WORKTREE_BACKGROUND_REMOVAL_RUNTIME_CAPABILITY
]

/** Gates the renderer must pass against its own main process. The Electron remote list omits all
* six; mobile advertises the structured ones, so this is an Electron-remote gap rather than a
* statement that no remote client wants them. Why it is one is not recorded here. */
const LOCAL_ONLY_BY_DECISION: readonly RuntimeCapability[] = [
AGENT_SESSION_BACKGROUND_TASK_STOP_CAPABILITY,
AGENT_SESSION_BACKGROUND_TASK_ROW_STOP_CAPABILITY,
AGENT_SESSION_BACKGROUND_TASK_CHILD_VIEWS_CAPABILITY,
AGENT_SESSION_TURN_ITEM_CAPABILITY,
STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY,
CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY
WORKTREE_BACKGROUND_REMOVAL_RUNTIME_CAPABILITY,
// `skills.install` reaches a host only from main's remote install service, never over runtime:call.
SKILL_INSTALL_RESULT_V2_CAPABILITY,
// Unsettled, not a decision: the local tabs sync reads the census's `authoritative` label
// (local-structured-session-tabs-sync/inventory-refresh.ts), which main drops without this.
SESSION_TABS_AUTHORITATIVE_INVENTORY_RUNTIME_CAPABILITY
]

function missingFrom(
Expand Down Expand Up @@ -92,18 +88,25 @@ describe('desktop renderer runtime client capabilities', () => {
).toBe(false)
})

it('diverges from the remote Electron list only where a decision was recorded', () => {
expect(
missingFrom(
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
DESKTOP_RENDERER_RUNTIME_CLIENT_CAPABILITIES
)
).toEqual([...REMOTE_ONLY_BY_DECISION].sort())
expect(
missingFrom(
DESKTOP_RENDERER_RUNTIME_CLIENT_CAPABILITIES,
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES
)
).toEqual([...LOCAL_ONLY_BY_DECISION].sort())
// The desktop routes a launch on its own settings. A paired host answering createSupport from its
// own setting would fail a chat the user asked for; main shares the desktop's setting, so locally
// this only lets Retry on an existing chat relaunch after the setting is turned off.
it.each([
['a paired host', PAIRED_HOST_RECEIVES],
['its own main process', DESKTOP_RENDERER_RUNTIME_CLIENT_CAPABILITIES]
] as const)('tells %s that it picks each launch mode itself', (_host, clientCapabilities) => {
expect(createSupportFollowsHostSetting({ clientKind: 'runtime', clientCapabilities })).toBe(
false
)
})

it('diverges from what a paired host receives only where a decision was recorded', () => {
expect(missingFrom(PAIRED_HOST_RECEIVES, DESKTOP_RENDERER_RUNTIME_CLIENT_CAPABILITIES)).toEqual(
[...REMOTE_ONLY_BY_DECISION].sort()
)
// The same renderer reads structured chats on either host, so it claims nothing only locally.
expect(missingFrom(DESKTOP_RENDERER_RUNTIME_CLIENT_CAPABILITIES, PAIRED_HOST_RECEIVES)).toEqual(
[]
)
})
})
2 changes: 2 additions & 0 deletions src/main/ipc/desktop-renderer-runtime-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AGENT_SESSION_PENDING_SEND_RESULT_RUNTIME_CAPABILITY,
AGENT_SESSION_TURN_ITEM_CAPABILITY,
CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY,
STRUCTURED_AGENT_SESSION_CLIENT_LAUNCH_MODE_CAPABILITY,
STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY,
type RuntimeCapability
} from '../../shared/protocol-version'
Expand Down Expand Up @@ -33,6 +34,7 @@ export const DESKTOP_RENDERER_RUNTIME_CLIENT_CAPABILITIES: readonly RuntimeCapab
AGENT_SESSION_BACKGROUND_TASK_CHILD_VIEWS_CAPABILITY,
STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY,
CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY,
STRUCTURED_AGENT_SESSION_CLIENT_LAUNCH_MODE_CAPABILITY,
// Without this `supportsAgentLaunch` refuses the renderer outright, while the same renderer
// targeting a remote host is admitted — the asymmetry this constant exists to close.
AGENT_LAUNCH_RUNTIME_CAPABILITY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { encodePairingOffer } from '../../shared/pairing'
import {
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY
} from '../../shared/protocol-version'
import { REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import { addEnvironmentFromPairingCode } from '../../shared/runtime-environment-store'

const { sendRemoteRuntimeRequestMock, sendRemoteRuntimeSharedControlRequestMock } = vi.hoisted(
Expand Down
2 changes: 1 addition & 1 deletion src/main/ipc/runtime-environment-pairing-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../shared/remote-pairing-verification'
import { RemoteRuntimeClientError } from '../../shared/remote-runtime-client-error'
import { sendRemoteRuntimeRequest } from '../../shared/remote-runtime-client'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import { redactRuntimeEnvironment } from '../../shared/runtime-environments'
import type { RuntimeStatus } from '../../shared/runtime-types'

Expand Down
2 changes: 1 addition & 1 deletion src/main/ipc/runtime-environment-request-connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getPreferredPairingOffer } from '../../shared/runtime-environments'
import type { RuntimeHostStatusOwner } from '../../shared/runtime-host-status-owner'
import type { RuntimeStatus } from '../../shared/runtime-types'
import { createRuntimeEnvironmentStatusOwner } from './runtime-environment-status-owner'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import type {
RuntimeOrchestrationEnvelope,
RuntimeRpcResponse
Expand Down
6 changes: 2 additions & 4 deletions src/main/ipc/runtime-environment-status-owner.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { BrowserWindow } from 'electron'
import { sendRemoteRuntimeRequest } from '../../shared/remote-runtime-client'
import {
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY
} from '../../shared/protocol-version'
import { REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import {
getPreferredPairingOffer,
type KnownRuntimeEnvironment
Expand Down
2 changes: 1 addition & 1 deletion src/main/ipc/runtime-environment-support-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { KnownRuntimeEnvironment } from '../../shared/runtime-environments'
import { getPreferredPairingOffer } from '../../shared/runtime-environments'
import { markEnvironmentUsed, resolveEnvironment } from '../../shared/runtime-environment-store'
import { recordRuntimeEnvironmentUsage } from './runtime-environment-usage-record'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import {
subscribeRemoteRuntimeRequest,
type RemoteRuntimeSubscription
Expand Down
2 changes: 1 addition & 1 deletion src/main/ipc/runtime-environment-transport-routing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPreferredPairingOffer } from '../../shared/runtime-environments'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import { resolveEnvironment, markEnvironmentUsed } from '../../shared/runtime-environment-store'
import { recordRuntimeEnvironmentUsage } from './runtime-environment-usage-record'
import { isOrchestrationMutation } from '../../shared/orchestration-rpc-contract'
Expand Down
6 changes: 2 additions & 4 deletions src/main/ipc/runtime-environments-call-routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY
} from '../../shared/protocol-version'
import { REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import * as environmentStore from '../../shared/runtime-environment-store'
import { RemoteRuntimeClientError } from '../../shared/remote-runtime-client-error'
import { RuntimeRpcCallQueueOverloadError } from '../../shared/runtime-rpc-call-queue'
Expand Down
6 changes: 2 additions & 4 deletions src/main/ipc/runtime-environments-pairing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
MIN_COMPATIBLE_RUNTIME_SERVER_VERSION
} from '../../shared/protocol-version'
import { MIN_COMPATIBLE_RUNTIME_SERVER_VERSION } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import * as environmentStore from '../../shared/runtime-environment-store'
import { RemoteRuntimeClientError } from '../../shared/remote-runtime-client-error'

Expand Down
6 changes: 2 additions & 4 deletions src/main/ipc/runtime-environments-status-diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY
} from '../../shared/protocol-version'
import { REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'

const {
handleMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'
import * as environmentStore from '../../shared/runtime-environment-store'

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES,
REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY
} from '../../shared/protocol-version'
import { REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY } from '../../shared/protocol-version'
import { ELECTRON_REMOTE_RUNTIME_CLIENT_CAPABILITIES } from '../../shared/electron-remote-runtime-client-capabilities'

const {
handleMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ export class StructuredAgentSessionHost {
showSessionTabs = (sessionIds: readonly string[]) => this.deps.store.showSessionTabs(sessionIds)
/** The records file could not be read this launch, so chats it holds are not listed yet. */
legacyRecordImportOwed = (): boolean => this.deps.journalDatabase.legacyRecordImportOwed === true
/** This runtime holds a chat: a record, or the records file's chats still owed their copy. */
holdsSessions = (): boolean => this.deps.store.holdsRecords() || this.legacyRecordImportOwed()
onSessionsHeld = (listener: () => void): (() => void) => this.deps.store.onFirstRecord(listener)

setSessionTabVisibility = async (
sessionId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { StructuredAgentSessionHost } from './structured-agent-session-host'
import {
getStructuredAgentSessionHost,
onStructuredAgentSessionsHeldChanged,
setStructuredAgentSessionHost,
structuredAgentSessionsHeld
} from './structured-agent-session-registry'

function fakeHost(initiallyHeld: boolean): {
host: StructuredAgentSessionHost
recordFirstChat: () => void
} {
let holds = initiallyHeld
const watchers = new Set<() => void>()
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the registry reads only these two members.
const host = {
holdsSessions: () => holds,
onSessionsHeld: (listener: () => void) => {
watchers.add(listener)
return () => watchers.delete(listener)
}
} as unknown as StructuredAgentSessionHost
return {
host,
recordFirstChat: () => {
holds = true
watchers.forEach((watcher) => watcher())
}
}
}

afterEach(() => {
setStructuredAgentSessionHost(null)
vi.restoreAllMocks()
})

// The renderer mirrors this machine's chats once one exists, e.g. when a paired client creates the
// first chat here while the chat setting is off. Building the host is not holding a chat.
describe("the structured host's held-chats signal", () => {
it('stays false when a host is built over a profile with no chat', () => {
const listener = vi.fn()
const stop = onStructuredAgentSessionsHeldChanged(listener)

setStructuredAgentSessionHost(fakeHost(false).host)

expect(structuredAgentSessionsHeld()).toBe(false)
expect(listener).not.toHaveBeenCalled()
stop()
})

it('turns true once, when the first chat is recorded', () => {
const listener = vi.fn()
const stop = onStructuredAgentSessionsHeldChanged(listener)
const { host, recordFirstChat } = fakeHost(false)
setStructuredAgentSessionHost(host)

recordFirstChat()
recordFirstChat()

expect(structuredAgentSessionsHeld()).toBe(true)
expect(listener.mock.calls).toEqual([[true]])
stop()
})

it('is true as soon as a host restores saved chats', () => {
const listener = vi.fn()
const stop = onStructuredAgentSessionsHeldChanged(listener)

setStructuredAgentSessionHost(fakeHost(true).host)

expect(listener.mock.calls).toEqual([[true]])
stop()
})

it('never fails the install when a listener throws', () => {
vi.spyOn(console, 'warn').mockImplementation(() => undefined)
const stopThrowing = onStructuredAgentSessionsHeldChanged(() => {
throw new Error('webContents destroyed')
})
const later = vi.fn()
const stopLater = onStructuredAgentSessionsHeldChanged(later)
const { host } = fakeHost(true)

expect(() => setStructuredAgentSessionHost(host)).not.toThrow()
expect(getStructuredAgentSessionHost()).toBe(host)
expect(later).toHaveBeenCalledWith(true)
stopThrowing()
stopLater()
})
})
Loading
Loading