Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(pairing): honour the phone's own name, fall back to 'Phone' (iOS app keeps 'iPhone')

review0cdcc1b3cac6
diff --git a/src/main/pairing-core.test.ts b/src/main/pairing-core.test.ts
index 1b1d6b94d..bd35e51c6 100644
--- a/src/main/pairing-core.test.ts
+++ b/src/main/pairing-core.test.ts
@@ -6,6 +6,9 @@ import {
LEGACY_DEVICE_KEY_COMMENT_PREFIX,
deviceCommentFor,
deviceCommentsFor,
+ DEVICE_NAME_MAX,
+ IOS_APP_KEY_COMMENT,
+ keyCommentOf,
filterAuthorizedKeys,
isValidEd25519PublicKey,
normalizeAuthorizedKeysLine,
@@ -279,15 +282,50 @@ describe('filterAuthorizedKeys', () => {
})
})
+describe('keyCommentOf', () => {
+ it('returns everything after type + blob, whitespace-collapsed', () => {
+ expect(keyCommentOf('ssh-ed25519 AAAA nodeterm-ios')).toBe('nodeterm-ios')
+ expect(keyCommentOf(' ssh-ed25519 AAAA a b \n')).toBe('a b')
+ expect(keyCommentOf('ssh-ed25519 AAAA')).toBe('')
+ expect(keyCommentOf('')).toBe('')
+ })
+})
+
describe('normalizeDeviceName', () => {
- it('trims a provided name', () => {
+ it('honours the name the phone sends, trimmed', () => {
expect(normalizeDeviceName(" Enes's iPhone ")).toBe("Enes's iPhone")
+ expect(normalizeDeviceName('Android', 'ssh-ed25519 AAAA nodeterm-android')).toBe('Android')
+ expect(normalizeDeviceName('Pixel 9 Pro', 'ssh-ed25519 AAAA nodeterm-ios')).toBe('Pixel 9 Pro')
+ })
+
+ it('falls back to the neutral "Phone" for missing / blank / non-string names', () => {
+ expect(normalizeDeviceName(undefined)).toBe('Phone')
+ expect(normalizeDeviceName(' ')).toBe('Phone')
+ expect(normalizeDeviceName(42)).toBe('Phone')
+ expect(normalizeDeviceName(undefined, 'ssh-ed25519 AAAA nodeterm-android')).toBe('Phone')
+ })
+
+ it('keeps "iPhone" for the iOS app, which sends no name but always the nodeterm-ios comment', () => {
+ expect(IOS_APP_KEY_COMMENT).toBe('nodeterm-ios')
+ expect(normalizeDeviceName(undefined, 'ssh-ed25519 AAAA nodeterm-ios')).toBe('iPhone')
+ expect(normalizeDeviceName(' ', ' ssh-ed25519 AAAA nodeterm-ios\n')).toBe('iPhone')
+ // Exact match only: a different or extended comment is not the iOS app.
+ expect(normalizeDeviceName(undefined, 'ssh-ed25519 AAAA nodeterm-ios-x')).toBe('Phone')
+ expect(normalizeDeviceName(undefined, 'ssh-ed25519 AAAA phone@ios')).toBe('Phone')
+ })
+
+ it('flattens control characters and newlines into single spaces', () => {
+ expect(normalizeDeviceName('My\nPhone\t\u0007 2')).toBe('My Phone 2')
+ expect(normalizeDeviceName('\u0000\u001b')).toBe('Phone')
})
- it('defaults to iPhone for missing / blank / non-string names', () => {
- expect(normalizeDeviceName(undefined)).toBe('iPhone')
- expect(normalizeDeviceName(' ')).toBe('iPhone')
- expect(normalizeDeviceName(42)).toBe('iPhone')
+ it(`caps at ${64} code points without splitting a surrogate pair`, () => {
+ expect(DEVICE_NAME_MAX).toBe(64)
+ expect(normalizeDeviceName('x'.repeat(5000))).toBe('x'.repeat(64))
+ const emoji = '📱'.repeat(70)
+ const out = normalizeDeviceName(emoji)
+ expect(Array.from(out)).toHaveLength(64)
+ expect(out).toBe('📱'.repeat(64))
})
})
diff --git a/src/main/pairing-core.ts b/src/main/pairing-core.ts
index b56e48bcb..7402f360b 100644
--- a/src/main/pairing-core.ts
+++ b/src/main/pairing-core.ts
@@ -180,13 +180,33 @@ export interface DeviceEntry {
/** The device shape safe to expose to the renderer (no `token`). */
export type PublicDevice = Omit<DeviceEntry, 'token'>
-/** Default device name when the phone didn't send one (or sent blank). */
-export function normalizeDeviceName(name: unknown): string {
+/** The comment the shipped iOS app puts on the key it generates (nodeterm-ios PairingService). */
+export const IOS_APP_KEY_COMMENT = 'nodeterm-ios'
+
+/** A phone-sent name is shown in Settings and sent as the relay label; keep it one short line. */
+export const DEVICE_NAME_MAX = 64
+
+/** The comment part of a public-key line (everything after type + blob), whitespace-collapsed. */
+export function keyCommentOf(publicKey: string): string {
+ return normalizeAuthorizedKeysLine(publicKey).split(' ').slice(2).join(' ')
+}
+
+/**
+ * The name a paired phone is listed (and relay-labelled) under.
+ *
+ * The name the phone sends wins — Android sends one. Control characters and newlines collapse to
+ * single spaces and the result is capped at DEVICE_NAME_MAX code points (never splitting an emoji).
+ * With no usable name the fallback is the neutral 'Phone' — EXCEPT for the iOS app, which has
+ * never sent a name: it is recognised by its fixed key comment and keeps the 'iPhone' every iPhone
+ * paired so far was given. Without that branch every newly paired iPhone would silently become
+ * "Phone".
+ */
+export function normalizeDeviceName(name: unknown, publicKey = ''): string {
if (typeof name === 'string') {
- const trimmed = name.trim()
- if (trimmed) return trimmed
+ const flat = name.replace(/\p{Cc}/gu, ' ').replace(/\s+/g, ' ').trim()
+ if (flat) return Array.from(flat).slice(0, DEVICE_NAME_MAX).join('').trim()
}
- return 'iPhone'
+ return keyCommentOf(publicKey) === IOS_APP_KEY_COMMENT ? 'iPhone' : 'Phone'
}
/**
diff --git a/src/main/pairing-service.test.ts b/src/main/pairing-service.test.ts
index b1c604d04..9439c3939 100644
--- a/src/main/pairing-service.test.ts
+++ b/src/main/pairing-service.test.ts
@@ -149,7 +149,7 @@ function gateReads(watched: string[]): void {
}
/** A key line the phone could really have sent: OpenSSH wire format the validator decodes. */
-function freshEd25519Line(): string {
+function freshEd25519Line(comment = 'phone@ios'): string {
const name = Buffer.from('ssh-ed25519', 'ascii')
const len = (n: number): Buffer => {
const b = Buffer.alloc(4)
@@ -157,7 +157,7 @@ function freshEd25519Line(): string {
return b
}
const blob = Buffer.concat([len(name.length), name, len(32), randomBytes(32)])
- return `ssh-ed25519 ${blob.toString('base64')} phone@ios`
+ return `ssh-ed25519 ${blob.toString('base64')} ${comment}`
}
/** POST /pair the way the phone does (plaintext branch — no host key, so no `epk` envelope). */
@@ -415,3 +415,52 @@ describe('pairing remembers the phone’s relay device id', () => {
}
})
})
+
+describe('pairing names the phone platform-neutrally', () => {
+ const nameOf = (id: string): string | undefined =>
+ ((agentJson().devices as DeviceEntry[] | undefined) ?? []).find((d) => d.id === id)?.name
+
+ async function pairWith(body: Record<string, unknown>): Promise<string> {
+ const service = createPairingService()
+ try {
+ const started = await service.start(() => {})
+ const { token, pairPort } = JSON.parse(started.payload) as { token: string; pairPort: number }
+ const respText = await post(pairPort, { token, ...body })
+ return (JSON.parse(respText) as { deviceId: string }).deviceId
+ } finally {
+ service.stop()
+ }
+ }
+
+ it('an iOS app pairing (no deviceName, nodeterm-ios key) is still listed as iPhone', async () => {
+ const deviceId = await pairWith({ publicKey: freshEd25519Line('nodeterm-ios') })
+ expect(nameOf(deviceId)).toBe('iPhone')
+ // ...and its key is stamped with the NEW comment, not the phone's own one.
+ expect(authKeys()).toContain(`nodeterm-mobile-${deviceId}`)
+ expect(authKeys()).not.toContain(`nodeterm-ios-${deviceId}`)
+ })
+
+ it('an Android pairing keeps the name it sent', async () => {
+ const deviceId = await pairWith({
+ publicKey: freshEd25519Line('nodeterm-android'),
+ deviceName: 'Android'
+ })
+ expect(nameOf(deviceId)).toBe('Android')
+ })
+
+ it('a nameless pairing from an unknown client is "Phone", never "iPhone"', async () => {
+ const deviceId = await pairWith({ publicKey: freshEd25519Line('someone@else') })
+ expect(nameOf(deviceId)).toBe('Phone')
+ })
+
+ it('a hostile multi-line name lands as one capped line', async () => {
+ const deviceId = await pairWith({
+ publicKey: freshEd25519Line('nodeterm-android'),
+ deviceName: `Evil\nName\r\n${'y'.repeat(500)}`
+ })
+ const stored = nameOf(deviceId) ?? ''
+ expect(stored).not.toMatch(/[\r\n]/)
+ expect(Array.from(stored).length).toBeLessThanOrEqual(64)
+ expect(stored.startsWith('Evil Name y')).toBe(true)
+ })
+})
diff --git a/src/main/pairing-service.ts b/src/main/pairing-service.ts
index 08ecc18bb..ebdf88fa3 100644
--- a/src/main/pairing-service.ts
+++ b/src/main/pairing-service.ts
@@ -751,7 +751,7 @@ export function createPairingService(
// the agentToken is the phone's bearer for the host-agent WebSocket (stored in its Keychain).
const deviceId = randomUUID()
const agentToken = randomBytes(24).toString('base64url')
- const name = normalizeDeviceName(body.deviceName)
+ const name = normalizeDeviceName(body.deviceName, publicKey)
// The phone's OWN id — the key the relay backend stores its device row under, and the
// only one it would recognize in a later revoke. Resolved here rather than at the mint
// below so the registry entry can carry it; the fallback (phone sent none ⇒ our id) is