Files
orca/src/shared/protocol-version.ts
T
Neil b0a4b33908 feat(pairing): let clients exchange a pairing code for their own token (#38937)
* feat(pairing): let clients exchange a pairing code for their own token

New offers are marked as tickets. A client signed in with the pairing token
can call pairing.exchangeTicket with a token it generated; the host stores it
durably and keeps accepting the pairing token until the client first signs in
with the new one. That sign-in retires the pairing token and cuts sockets
still using it. Advertised as pairing.ticket-exchange.v1; clients that never
call it keep working exactly as before.

* fix(pairing): never retire a code other clients may already rely on

Exchange is offered only within 10 minutes of a ticket's first sign-in;
after that the code may be in use by several older clients and stays a
plain token. The first client to propose keeps its claim: a different
proposal is refused (that client keeps the code) instead of displacing it,
so two clients pairing at once can't lock out the first. Adds cross-version
tests against the pinned release: downgrade keeps exchanged and unexchanged
phones working, rows from an older host are never single-use, and the older
host doesn't advertise the exchange.
2026-11-06 23:57:05 -08:00

155 lines
7.4 KiB
TypeScript

import { EMULATOR_RUNTIME_CAPABILITIES } from './emulator-runtime-capabilities'
import { ACCOUNT_RUNTIME_CAPABILITIES } from './account-runtime-capabilities'
import * as agentLaunchCapabilities from './agent-launch/contracts/agent-launch-runtime-capability'
import {
AGENT_SESSION_BOUNDARY_RUNTIME_CAPABILITY,
AGENT_SESSION_RUNTIME_CAPABILITIES
} from './agent-session/agent-session-runtime-capabilities'
import { AI_VAULT_RUNTIME_CAPABILITIES } from './ai-vault/contracts/ai-vault-runtime-capabilities'
import {
AUTOMATION_RUNTIME_CAPABILITIES,
AUTOMATION_RUNTIME_CLIENT_CAPABILITIES
} from './automation-runtime-capabilities'
import { BROWSER_RUNTIME_CAPABILITIES } from './browser-runtime-capabilities'
import {
DEVICE_KEY_RUNTIME_CAPABILITIES,
E2EE_V2_TOKEN_CAPABILITIES_RUNTIME_CAPABILITY
} from './remote-runtime/pairing/device-key-capability'
import { PAIRING_TICKET_EXCHANGE_RUNTIME_CAPABILITIES } from './remote-runtime/pairing/ticket-exchange-capability'
import { FILES_RUNTIME_CAPABILITIES } from './files-runtime-capabilities'
import { HOST_RUNTIME_CAPABILITIES } from './host-runtime-capabilities'
import { MOBILE_RUNTIME_CAPABILITIES } from './mobile-runtime-capabilities'
import { ORCAD_RUNTIME_CAPABILITIES } from './orcad-runtime-capabilities'
import { ORCHESTRATION_RUNTIME_CAPABILITIES } from './orchestration-runtime-capabilities'
import { PREFLIGHT_RUNTIME_CAPABILITIES } from './preflight-runtime-capabilities'
import {
SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY,
SESSION_TABS_RUNTIME_CAPABILITIES
} from './session-tabs-runtime-capabilities'
import { SKILL_RUNTIME_CAPABILITIES } from './skill-install-capability'
import { SOURCE_CONTROL_RUNTIME_CAPABILITIES } from './source-control/runtime/source-control-runtime-capabilities'
import { TASK_SOURCE_RUNTIME_CAPABILITIES } from './task-source-runtime-capabilities'
import { TERMINAL_RUNTIME_CAPABILITIES } from './terminal/runtime-policy/terminal-runtime-capabilities'
import { WORKSPACE_PORTS_RUNTIME_CAPABILITIES } from './workspace-ports-runtime-capabilities'
import {
REPO_SEARCH_QUALIFIED_REFS_RUNTIME_CAPABILITY,
WORKTREE_GITHUB_PR_SUPPRESSION_RUNTIME_CAPABILITY,
WORKTREE_RUNTIME_CAPABILITIES,
WORKTREE_VISIBILITY_DEFAULTS_RUNTIME_CAPABILITY,
WORKTREE_VISIBILITY_SOURCE_DEFAULTS_RUNTIME_CAPABILITY
} from './worktree-runtime-capabilities'
// Runtime protocol ranges permit app-version drift across desktop/server/CLI/mobile. Bump for removed methods/required params,
// changed field meaning (units/nullability), framing or auth; optional fields, new methods and ignorable events are additive.
// Raise minimum client/server versions to refuse unsupported peers; never require equal app versions.
export const RUNTIME_PROTOCOL_VERSION = 3
export const MIN_COMPATIBLE_RUNTIME_CLIENT_VERSION = 2
export const MIN_COMPATIBLE_RUNTIME_SERVER_VERSION = 2
// Why stars: importers keep reading every capability from here while each area owns its module.
export * from './browser-runtime-capabilities'
export * from './files-runtime-capabilities'
export * from './host-runtime-capabilities'
export * from './mobile-runtime-capabilities'
export * from './preflight-runtime-capabilities'
export * from './task-source-runtime-capabilities'
export * from './workspace-ports-runtime-capabilities'
export * from './worktree-runtime-capabilities'
export { REMOTE_SERVER_UPDATE_CAPABILITY } from './remote-server-update'
export {
AUTOMATION_LIST_HOST_SCOPE_RUNTIME_CAPABILITY,
AUTOMATION_LIST_HOST_SCOPE_UPDATE_REQUIRED_MESSAGE,
AUTOMATION_OWNER_FENCING_RUNTIME_CAPABILITY,
AUTOMATION_OWNER_FENCING_UPDATE_REQUIRED_MESSAGE,
AUTOMATION_CREATE_IDEMPOTENCY_RUNTIME_CAPABILITY,
AUTOMATION_EXTRA_AGENT_ARGS_RUNTIME_CAPABILITY,
AUTOMATION_SETUP_CHOICE_RUNTIME_CAPABILITY,
AUTOMATION_SURFACE_RUNTIME_CAPABILITY,
AUTOMATION_LAUNCH_SETUP_RUNTIME_CAPABILITY
} from './automation-runtime-capabilities'
export {
ORCHESTRATION_FEDERATION_RUNTIME_CAPABILITY,
ORCHESTRATION_FEDERATION_CONTROL_MAIL_RUNTIME_CAPABILITY,
ORCHESTRATION_FEDERATION_LIFECYCLE_SETTLEMENT_RUNTIME_CAPABILITY,
ORCHESTRATION_WORKER_STOP_VERDICT_RUNTIME_CAPABILITY,
ORCHESTRATION_WORKER_LAUNCH_PREFERENCES_RUNTIME_CAPABILITY,
ORCHESTRATION_FEDERATION_STRUCTURED_READ_RUNTIME_CAPABILITY,
ORCHESTRATION_FEDERATION_FLEET_SNAPSHOT_RUNTIME_CAPABILITY,
ORCHESTRATION_FEDERATION_RELEASE_ARCHIVE_RUNTIME_CAPABILITY,
ORCHESTRATION_WORKER_AUTO_RELEASE_RUNTIME_CAPABILITY,
ORCHESTRATION_WORKER_START_IMPLICIT_RUN_RUNTIME_CAPABILITY,
ORCHESTRATION_RETAINED_RUN_BINDINGS_RUNTIME_CAPABILITY,
ORCHESTRATION_WORKER_TURN_STOP_REPORTS_RUNTIME_CAPABILITY,
ORCHESTRATION_ASK_RETURNS_AT_ONCE_RUNTIME_CAPABILITY,
ORCHESTRATION_FEDERATION_CONTROL_MAIL_PROTOCOL_VERSION,
ORCHESTRATION_FEDERATION_LIFECYCLE_SETTLEMENT_PROTOCOL_VERSION,
ORCHESTRATION_CONTRACT_VERSION,
ORCHESTRATION_CONTRACT_RUNTIME_CAPABILITY
} from './orchestration-runtime-capabilities'
export {
AGENT_STATUS_RESTORED_UNCONFIRMED_RUNTIME_CAPABILITY,
SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY,
SESSION_TABS_AUTHORITATIVE_INVENTORY_RUNTIME_CAPABILITY,
SESSION_TABS_RETIREMENT_PROOF_DELTA_RUNTIME_CAPABILITY,
SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY,
SESSION_TABS_TAB_DELTA_RUNTIME_CAPABILITY
} from './session-tabs-runtime-capabilities'
// Native clients include the CLI, which cannot place Electron browser pages.
export const NATIVE_REMOTE_RUNTIME_CLIENT_CAPABILITIES = [
SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY,
AGENT_SESSION_BOUNDARY_RUNTIME_CAPABILITY,
WORKTREE_VISIBILITY_DEFAULTS_RUNTIME_CAPABILITY,
WORKTREE_VISIBILITY_SOURCE_DEFAULTS_RUNTIME_CAPABILITY,
WORKTREE_GITHUB_PR_SUPPRESSION_RUNTIME_CAPABILITY,
REPO_SEARCH_QUALIFIED_REFS_RUNTIME_CAPABILITY,
...AUTOMATION_RUNTIME_CLIENT_CAPABILITIES,
agentLaunchCapabilities.AGENT_LAUNCH_RUNTIME_CAPABILITY
] as const
// Each area lists what it publishes in its own module; a new capability edits only that module.
export const SAVED_RESUME_ORIGIN_RUNTIME_CAPABILITY =
'agent-session.saved-resume-origin.v1' as const
// Individual protocol exports must not retain the unused host capability aggregate.
export const RUNTIME_CAPABILITIES = /* @__PURE__ */ (() =>
[
...EMULATOR_RUNTIME_CAPABILITIES,
SAVED_RESUME_ORIGIN_RUNTIME_CAPABILITY,
...HOST_RUNTIME_CAPABILITIES,
...DEVICE_KEY_RUNTIME_CAPABILITIES,
E2EE_V2_TOKEN_CAPABILITIES_RUNTIME_CAPABILITY,
...PAIRING_TICKET_EXCHANGE_RUNTIME_CAPABILITIES,
...MOBILE_RUNTIME_CAPABILITIES,
...ORCAD_RUNTIME_CAPABILITIES,
...ORCHESTRATION_RUNTIME_CAPABILITIES,
...agentLaunchCapabilities.AGENT_LAUNCH_RUNTIME_CAPABILITIES,
...AGENT_SESSION_RUNTIME_CAPABILITIES,
...ACCOUNT_RUNTIME_CAPABILITIES,
...SKILL_RUNTIME_CAPABILITIES,
...AUTOMATION_RUNTIME_CAPABILITIES,
...WORKTREE_RUNTIME_CAPABILITIES,
...PREFLIGHT_RUNTIME_CAPABILITIES,
...WORKSPACE_PORTS_RUNTIME_CAPABILITIES,
...SESSION_TABS_RUNTIME_CAPABILITIES,
...TERMINAL_RUNTIME_CAPABILITIES,
...FILES_RUNTIME_CAPABILITIES,
...BROWSER_RUNTIME_CAPABILITIES,
...SOURCE_CONTROL_RUNTIME_CAPABILITIES,
...TASK_SOURCE_RUNTIME_CAPABILITIES,
...AI_VAULT_RUNTIME_CAPABILITIES
] as const)()
export type RuntimeCapability = (typeof RUNTIME_CAPABILITIES)[number] | (string & {})
// COMPAT(mobileProtocolAliases): added 2026-05-15 for mobile builds that
// still read desktop/mobile names; remove once mobile reads runtime names.
export const DESKTOP_PROTOCOL_VERSION = RUNTIME_PROTOCOL_VERSION
export const MIN_COMPATIBLE_MOBILE_VERSION = MIN_COMPATIBLE_RUNTIME_CLIENT_VERSION