Repository navigation
feat(cli): pair clients with a running Orca via orca pair
#36469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a924c70
7c7d458
656d8f4
5888cec
e3d24d7
ee863b4
94635fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,7 +168,7 @@ orca-ide serve --port 6768 --pairing-address 100.64.1.20 | |
|
|
||
| Use only one host mode at a time. If the Orca desktop app is already sharing that computer, do not start a second `orca serve` process for the same setup. | ||
|
|
||
| `orca serve` runs on Orca's own Node server (orcad) by default. If orcad can't serve on this computer, it uses the desktop app's server instead and prints one line saying why. On a packaged macOS app it currently always uses the desktop app's server, so paired clients can still update it. To always use the desktop app's server, set `ORCA_SERVE_RUNTIME=electron`. | ||
| `orca serve` runs on Orca's own Node server (orcad) by default. If orcad can't serve on this computer, it uses the desktop app's server instead and prints one line saying why. On a packaged macOS app it uses the desktop app's server, so paired clients can still update it, unless you set `ORCA_SERVE_RUNTIME=orcad` (see [A Mac reached only over SSH](#a-mac-reached-only-over-ssh)). To always use the desktop app's server, set `ORCA_SERVE_RUNTIME=electron`. | ||
|
|
||
| ### Limit terminal memory on a Linux server | ||
|
|
||
|
|
@@ -210,6 +210,27 @@ orca-ide serve --pairing-address 100.64.1.20 --mobile-pairing | |
|
|
||
| Keep the phone on the same tailnet, open Orca Mobile, choose **Pair**, and scan the terminal QR code or paste the printed link. | ||
|
|
||
| ### Pair without restarting the server | ||
|
|
||
| `orca pair` asks the Orca already running on this machine for a new pairing, so you do not have to stop a service or restart `orca serve`. Run it on the server, as the user Orca runs as: | ||
|
|
||
| ```bash | ||
| orca pair --mobile --address 100.64.1.20 # QR code and link for Orca Mobile | ||
| orca pair --address 100.64.1.20 # access link for another Orca | ||
| # Linux | ||
| orca-ide pair --mobile --address 100.64.1.20 | ||
| ``` | ||
|
|
||
| It works the same against the desktop app, a foreground `orca serve`, or `orca serve service install`. Only the machine's own user can run it; paired clients and phones cannot create pairings. | ||
|
|
||
| ### A Mac reached only over SSH | ||
|
|
||
| On a packaged macOS app, `orca serve` uses the desktop app's server, which needs a desktop login: started from an SSH session with nobody logged in, it aborts at startup. To serve such a Mac, ask for Orca's Node server instead. It has no in-app updater, so update the app yourself (for example with `brew upgrade --cask stablyai/orca/orca`) and restart the server: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| ```bash | ||
| ORCA_SERVE_RUNTIME=orcad orca serve --pairing-address 100.64.1.20 | ||
| ``` | ||
|
|
||
| ## Desktop app or `orca serve`? | ||
|
|
||
| | | Desktop app on the server | `orca serve` | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { CommandHandler } from '../dispatch' | ||
| import { getOptionalStringFlag } from '../flags' | ||
| import { printResult } from '../format' | ||
| import { RuntimeClientError } from '../runtime/types' | ||
| import { | ||
| PAIRING_CREATE_OFFER_METHOD, | ||
| type PairingCreateOfferParams, | ||
| type PairingCreateOfferResult | ||
| } from '../../shared/pairing-create-offer-contract' | ||
|
|
||
| export function formatPairingOffer(offer: PairingCreateOfferResult): string { | ||
| if (!offer.available) { | ||
| return `Pairing is unavailable (${offer.reason}). ${offer.guidance}` | ||
| } | ||
| const lines: string[] = [] | ||
| if (offer.scope === 'mobile') { | ||
| if (offer.qr) { | ||
| lines.push(offer.qr.trimEnd(), '') | ||
| } | ||
| lines.push('Scan with Orca Mobile (Pair), or paste this link:', offer.pairingUrl) | ||
| } else { | ||
| lines.push( | ||
| 'Paste this link in Orca: Settings → Remote Orca Servers → Add Server.', | ||
| offer.pairingUrl | ||
| ) | ||
| if (offer.webClientUrl) { | ||
| lines.push('', 'Or open it in a browser:', offer.webClientUrl) | ||
| } | ||
| } | ||
| if (offer.endpoint) { | ||
| lines.push('', `The client will connect to ${offer.endpoint}.`) | ||
| } | ||
| lines.push('Treat the link like a password: it grants access to this Orca.') | ||
| return lines.join('\n') | ||
| } | ||
|
|
||
| export const PAIR_HANDLERS: Record<string, CommandHandler> = { | ||
| pair: async ({ client, flags, json }) => { | ||
| const mobile = flags.get('mobile') === true | ||
| if (flags.get('relay') === true && !mobile) { | ||
| throw new RuntimeClientError('invalid_argument', '--relay applies only with --mobile') | ||
| } | ||
| if (flags.get('grant-desktop-control') === true && mobile) { | ||
| throw new RuntimeClientError( | ||
| 'invalid_argument', | ||
| '--grant-desktop-control applies only to an access link, not --mobile' | ||
| ) | ||
| } | ||
| const params: PairingCreateOfferParams = { | ||
| scope: mobile ? 'mobile' : 'runtime', | ||
| address: getOptionalStringFlag(flags, 'address'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| relay: flags.get('relay') === true, | ||
| grantDesktopControl: flags.get('grant-desktop-control') === true, | ||
| rotate: flags.get('rotate') === true | ||
| } | ||
| const response = await client.call<PairingCreateOfferResult>( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| PAIRING_CREATE_OFFER_METHOD, | ||
| params | ||
| ) | ||
| printResult(response, json, formatPairingOffer) | ||
| if (!response.result.available) { | ||
| process.exitCode = 1 | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import type { ProcessSpec } from '@orca/process-host/process-spec' | |
| import { | ||
| ORCAD_LOCAL_SERVE_SELECTION_ENTRY, | ||
| ORCAD_LOCAL_SERVE_SELECTION_FLAGS as FLAGS, | ||
| SERVE_RUNTIME_ENV, | ||
| parseServeRuntimeSelection, | ||
| type ServeRuntimeSelection | ||
| } from '../../shared/orcad-local-serve-selection' | ||
|
|
@@ -24,11 +25,13 @@ export async function resolveLocalServeRuntime( | |
| appRoot: string | ||
| userDataPath: string | ||
| usesMacUpdateHandoff: boolean | ||
| env?: NodeJS.ProcessEnv | ||
| }, | ||
| run: typeof runProcess = runProcess | ||
| ): Promise<ServeRuntimeSelection> { | ||
| // orcad has no updater; keep Electron for packaged macOS update handoffs. | ||
| if (options.usesMacUpdateHandoff) { | ||
| // orcad has no updater; keep Electron for packaged macOS update handoffs unless orcad is asked for, | ||
| // e.g. over SSH with no desktop login, where Electron cannot start. | ||
| if (options.usesMacUpdateHandoff && (options.env ?? process.env)[SERVE_RUNTIME_ENV] !== 'orcad') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return { | ||
| kind: 'electron', | ||
| reason: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { CommandSpec } from '../args' | ||
| import { GLOBAL_FLAGS } from '../args' | ||
|
|
||
| export const PAIR_COMMAND_SPECS: CommandSpec[] = [ | ||
| { | ||
| path: ['pair'], | ||
| summary: | ||
| 'Pair a phone or another Orca with the Orca already running here, without restarting it', | ||
| usage: | ||
| 'orca pair [--mobile [--relay]] [--address <host>] [--grant-desktop-control] [--rotate] [--json]', | ||
| allowedFlags: [ | ||
| ...GLOBAL_FLAGS, | ||
| 'mobile', | ||
| 'relay', | ||
| 'address', | ||
| 'grant-desktop-control', | ||
| 'rotate' | ||
| ], | ||
| notes: [ | ||
| 'Asks the Orca running for this profile (desktop app, `orca serve`, or its service) for a pairing offer. Nothing restarts and existing clients stay connected.', | ||
| 'Without --mobile it prints an access link for another Orca (Settings → Remote Orca Servers → Add Server). --mobile prints a QR code and link for Orca Mobile.', | ||
| '--address is the host or IP the client should dial, such as a Tailscale address. Without it Orca picks this machine’s default LAN address.', | ||
| 'The first network pairing makes a loopback-only Orca listen on every interface, as pairing from the desktop app does.', | ||
| 'Mobile pairing is LAN-only (same network or tailnet) unless --relay is given; Relay needs a signed-in desktop app.', | ||
| 'An unused offer is reused until --rotate replaces it. Clients that already paired keep their access.', | ||
| "--grant-desktop-control lets the paired Orca drive this machine's desktop (orca computer). It applies only to an access link, not to a phone.", | ||
| 'Only this machine’s own user can run it: paired clients and phones cannot create pairing offers.' | ||
| ], | ||
| examples: [ | ||
| 'orca pair --mobile', | ||
| 'orca pair --mobile --address 100.64.1.20', | ||
| 'orca pair --address 100.64.1.20', | ||
| 'orca pair --mobile --rotate --json' | ||
| ] | ||
| } | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: stablyai/orca
Length of output: 12516
Script executed:
Repository: stablyai/orca
Length of output: 19220
Script executed:
Repository: stablyai/orca
Length of output: 36071
Script executed:
Repository: stablyai/orca
Length of output: 8862
Explain when to use
--rotate.Running the command again can reuse an unused link. If someone shared the link with the wrong person, run
orca pair --rotatefor a runtime link ororca pair --mobile --rotatefor a mobile link. Rotation does not revoke clients that already paired.