Add mobile terminal shortcut bar customization (#3012)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo Hong
2026-05-29 16:39:52 -07:00
committed by GitHub
co-authored by Orca
parent 431b336f1b
commit 30a09f3bd9
28 changed files with 4103 additions and 2423 deletions
+11 -5
View File
@@ -16,7 +16,7 @@ describe('pairing offer', () => {
it('encode then decode round-trips correctly', () => {
const url = encodePairingOffer(offer)
expect(url).toMatch(/^orca:\/\/pair#/)
expect(url).toMatch(/^orca:\/\/pair\?code=/)
const decoded = decodePairingOffer(url)
expect(decoded).toEqual(offer)
@@ -24,18 +24,24 @@ describe('pairing offer', () => {
it('encoded URL uses base64url (no +, /, or = characters)', () => {
const url = encodePairingOffer(offer)
const fragment = url.split('#')[1]!
expect(fragment).not.toMatch(/[+/=]/)
const code = new URLSearchParams(url.slice(url.indexOf('?') + 1)).get('code')!
expect(code).not.toMatch(/[+/=]/)
})
it('rejects URLs with wrong scheme', () => {
expect(() => decodePairingOffer('https://example.com#abc')).toThrow('Invalid pairing URL')
})
it('rejects URLs without fragment', () => {
it('rejects URLs without a pairing code', () => {
expect(() => decodePairingOffer('orca://pair')).toThrow('Invalid pairing URL')
})
it('decodes legacy hash URLs', () => {
const url = encodePairingOffer(offer)
const code = new URLSearchParams(url.slice(url.indexOf('?') + 1)).get('code')!
expect(decodePairingOffer(`orca://pair#${code}`)).toEqual(offer)
})
it('rejects payloads with missing fields', () => {
const partial = { v: 2, endpoint: 'ws://host:1234' }
const base64 = Buffer.from(JSON.stringify(partial)).toString('base64')
@@ -70,7 +76,7 @@ describe('parsePairingCode', () => {
it('parses a bare base64url payload (without scheme prefix)', () => {
const url = encodePairingOffer(offer)
const base64url = url.split('#')[1]!
const base64url = new URLSearchParams(url.slice(url.indexOf('?') + 1)).get('code')!
expect(parsePairingCode(base64url)).toEqual(offer)
})
+28 -6
View File
@@ -20,18 +20,40 @@ export function encodePairingOffer(offer: PairingOffer): string {
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '')
return `orca://pair#${base64url}`
// Why: Android camera intents and Expo Router preserve query params more
// reliably than URL fragments when launching a custom-scheme app.
return `orca://pair?code=${base64url}`
}
export function decodePairingOffer(url: string): PairingOffer {
const hashIndex = url.indexOf('#')
if (!url.startsWith('orca://pair') || hashIndex === -1) {
throw new Error('Invalid pairing URL: must start with orca://pair#')
const code = extractPairingCodeFromUrl(url)
if (!code) {
throw new Error('Invalid pairing URL: must start with orca://pair and include a pairing code')
}
return decodePairingBase64(url.slice(hashIndex + 1))
return decodePairingBase64(code)
}
// Why: accept either an `orca://pair#<base64>` URL or the bare base64
function extractPairingCodeFromUrl(url: string): string | null {
if (!url.startsWith('orca://pair')) {
return null
}
const queryIndex = url.indexOf('?')
if (queryIndex !== -1) {
const query = url.slice(queryIndex + 1).split('#')[0] ?? ''
const params = new URLSearchParams(query)
const code = params.get('code')
if (code) {
return code
}
}
const hashIndex = url.indexOf('#')
if (hashIndex !== -1) {
return url.slice(hashIndex + 1) || null
}
return null
}
// Why: accept either an `orca://pair?...` URL or the bare base64
// string so the mobile paste-pair flow can take whichever the user
// actually copied from desktop.
export function parsePairingCode(input: string): PairingOffer | null {
+1 -1
View File
@@ -42,7 +42,7 @@ export function addEnvironmentFromPairingCode(
if (!offer) {
throw new RuntimeEnvironmentStoreError(
'invalid_argument',
'Invalid pairing code. Expected an orca://pair#... URL or bare pairing payload.'
'Invalid pairing code. Expected an orca://pair?... URL or bare pairing payload.'
)
}
const store = readEnvironmentStore(userDataPath)
+2
View File
@@ -1,3 +1,5 @@
/* eslint-disable max-lines -- Why: telemetry schema tests keep related event
invariants together so cross-event payload rules stay easy to audit. */
// Schema round-trip coverage for the event map. Fail-closed invariants that
// must hold: agent_error is enum-only (error_message / error_stack rejected
// by `.strict()`), unknown enum values fail, and any well-formed payload