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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(settings): show the license key, the device count and a release action
enes5bacbe0e5e58
diff --git a/src/renderer/components/settings/sections/LicenseSection.tsx b/src/renderer/components/settings/sections/LicenseSection.tsxindex 3fff071e6..12bbb74ed 100644--- a/src/renderer/components/settings/sections/LicenseSection.tsx+++ b/src/renderer/components/settings/sections/LicenseSection.tsx@@ -1,4 +1,4 @@-import { useState } from 'react'+import { useEffect, useState } from 'react'import { useEntitlement } from '../../../state/entitlement'import { SettingsSection } from '../SettingsSection'import { SearchableRow } from '../SearchableRow'@@ -6,6 +6,7 @@ import { FieldRow } from '../FieldRow'import { ProCompare } from './ProCompare'import { Button } from '@renderer/ui/Button'import { Input } from '@renderer/ui/Input'+import { licenseSentence, canReleaseDevices } from '@renderer/lib/licenseCopy'const ROWS = {license: {@@ -20,7 +21,11 @@ const ROWS = {'compare','core','remote access',- 'quota'+ 'quota',+ 'devices',+ 'seats',+ 'release',+ 'copy key']}}@@ -30,6 +35,22 @@ export function LicenseSection({ isActive }: { isActive: boolean }): React.JSX.Econst ent = useEntitlement()const [licenseKey, setLicenseKey] = useState('')const [upgrading, setUpgrading] = useState(false)+ const [releasing, setReleasing] = useState(false)+ const [releaseFailed, setReleaseFailed] = useState(false)+ // `loadDetail` REJECTS on the Server Edition (`E_UNSUPPORTED` — there is no license layer in+ // src/server), and the store deliberately does not swallow it. Catching here is not optional:+ // uncaught, this is an unhandled rejection on every browser session. And what we show there is+ // NOTHING — a read that could not run is not "no key, 0 devices".+ const [detailUnavailable, setDetailUnavailable] = useState(false)+ useEffect(() => {+ if (!ent.isPremium) return+ void ent.loadDetail().catch(() => setDetailUnavailable(true))+ // `ent.loadDetail` is a stable zustand action; the entitlement becoming premium is the event.+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [ent.isPremium])++ const detail = detailUnavailable ? null : ent.detail+ const sentence = licenseSentence(detail)return (<SettingsSectionid="license"@@ -49,6 +70,61 @@ export function LicenseSection({ isActive }: { isActive: boolean }): React.JSX.E: ''}.</p>+ {detail ? (+ <>+ <FieldRow+ label="License key"+ control={+ <div className="flex items-center gap-2">+ <Input+ className="w-64"+ readOnly+ value={detail.key ?? ''}+ placeholder={detail.key ? undefined : 'not available'}+ />+ <Button+ disabled={!detail.key}+ onClick={() => {+ if (detail.key) void navigator.clipboard.writeText(detail.key)+ }}+ >+ Copy+ </Button>+ </div>+ }+ />+ {sentence ? <p className="text-sm text-muted">{sentence}</p> : null}+ {detail.key ? (+ <p className="text-sm text-muted">+ To use Pro on another Mac, open Settings → License there and paste this key.+ </p>+ ) : null}+ {canReleaseDevices(detail) ? (+ <div className="space-y-2">+ <Button+ disabled={releasing}+ onClick={() => {+ setReleasing(true)+ setReleaseFailed(false)+ void ent+ .releaseOthers()+ // Same uncaught-rejection rule as `loadDetail` above — plus an ordinary+ // IPC failure here would otherwise leave the button stuck on "Releasing…".+ .catch(() => setReleaseFailed(true))+ .finally(() => setReleasing(false))+ }}+ >+ {releasing ? 'Releasing…' : 'Release other devices'}+ </Button>+ {releaseFailed ? (+ <p className="text-sm" style={{ color: '#ff9f0a' }}>+ Could not release the other devices. Nothing was changed.+ </p>+ ) : null}+ </div>+ ) : null}+ </>+ ) : null}<Button onClick={() => void ent.deactivate()}>Deactivate on this device</Button></div>) : (diff --git a/src/renderer/lib/licenseCopy.test.ts b/src/renderer/lib/licenseCopy.test.tsnew file mode 100644index 000000000..0e243dd95--- /dev/null+++ b/src/renderer/lib/licenseCopy.test.ts@@ -0,0 +1,190 @@+import { describe, it, expect } from 'vitest'+import type { LicenseDetail } from '@shared/types'+import { licenseSentence, canReleaseDevices } from './licenseCopy'++// `detail.error` carries TWO families and only the code word separates them: a read that FAILED+// (its counts are placeholder zeros) and a release that was REFUSED (its counts are the last good+// read — real, current, worth showing). Most of what follows exists to pin that seam, because+// every wrong ordering of the checks still produces a plausible-looking sentence.++const keygen = (over: Partial<LicenseDetail> = {}): LicenseDetail => ({+ key: 'NT-KEY-1',+ used: 2,+ seats: 3,+ source: 'keygen',+ error: null,+ ...over+})++describe('licenseSentence — a keygen license that read cleanly', () => {+ it('reports usage against the cap and names phones as devices', () => {+ const s = licenseSentence(keygen({ used: 2, seats: 3 }))+ expect(s).toBe('2 of 3 devices in use — this Mac and each paired phone counts as a device.')+ // The numbers are the DATA's, not a template that happens to read well: a swapped pair or a+ // hardcoded cap would still match a looser assertion.+ expect(licenseSentence(keygen({ used: 1, seats: 5 }))).toBe(+ '1 of 5 devices in use — this Mac and each paired phone counts as a device.'+ )+ })++ it('names the cap being full and points at the release action', () => {+ expect(licenseSentence(keygen({ used: 3, seats: 3 }))).toBe(+ 'All 3 devices are in use. Release the others below to free them up.'+ )+ })++ it('does not claim "all N" when MORE than N are in use (a cap lowered after activation)', () => {+ // `used > seats` is reachable and must not be flattened into the full-cap sentence: "All 3+ // devices are in use" under a 4-device reality is a wrong number stated as a fact. A `>=`+ // that falls through to the full-cap branch passes every other test in this file.+ expect(licenseSentence(keygen({ used: 4, seats: 3 }))).toBe(+ '4 devices are in use, more than the 3 this license allows. Release the others below to free them up.'+ )+ })++ it('is honest when the read succeeded but no key is on file', () => {+ // Legitimate: a keygen policy that hides keys, or a license predating the key column. This is+ // the ONLY case this sentence may appear in — see the apple/free/error tests below.+ expect(licenseSentence(keygen({ key: null }))).toBe(+ 'No key is on file for this license yet — get in touch and we will send yours.'+ )+ })+})++describe('licenseSentence — sources that have no key and no device count', () => {+ it('says an App Store subscription bridged Pro here, and prints no counts', () => {+ const s = licenseSentence({ key: null, used: 0, seats: 0, source: 'apple', error: null })+ expect(s).toBe(+ 'Pro on this Mac comes from the App Store subscription on your paired phone, so there is no license key or device count to show here.'+ )+ // The zeros are "not applicable", not a measurement. Rendering them here is the exact+ // misdirection this branch exists to prevent.+ expect(s).not.toContain('0')+ // …and it must not borrow the keygen "no key on file" line, which would send an App Store+ // subscriber to support asking for a key that will never exist.+ expect(s).not.toContain('get in touch')+ })++ it('says plainly that a `free` source is not backed by a key, inventing no origin story', () => {+ const s = licenseSentence({ key: null, used: 0, seats: 0, source: 'free', error: null })+ expect(s).toBe('Pro on this device is not backed by a license key.')+ expect(s).not.toContain('get in touch')+ expect(s).not.toContain('0')+ })++ it('says nothing when a clean read stated no source at all', () => {+ // Only reachable through a release merge over an empty detail (counts real, source unknown).+ // With no stated source there is no sentence the data supports — so, none.+ expect(licenseSentence({ key: null, used: 1, seats: 3, source: null, error: null })).toBe('')+ })+})++describe('licenseSentence — a read that FAILED', () => {+ // Every code in this family arrives with placeholder zeros and a null key.+ const failures = ['unauthorized', 'inactive', 'offline', 'disabled', 'network'] as const+ const FAILED = 'Could not read this license right now, so the key and device count are unknown. Your Pro access is unaffected.'++ for (const error of failures) {+ it(`renders "${error}" as a failed read, never as a device count`, () => {+ const s = licenseSentence({ key: null, used: 0, seats: 0, source: null, error })+ expect(s).toBe(FAILED)+ // A failed read is not "0 of 0 devices" and not "no key on file".+ expect(s).not.toContain('0 of 0')+ expect(s).not.toContain('get in touch')+ })+ }++ it('still renders the failure when the failed read carried a source and stale-looking counts', () => {+ // ORDERING PIN: if the `source` check ran before the `error` check, this would render the+ // keygen usage sentence over a read that never came back — a fabricated device count.+ const s = licenseSentence({ key: 'NT-KEY-1', used: 2, seats: 3, source: 'keygen', error: 'offline' })+ expect(s).toBe(FAILED)+ expect(s).not.toContain('2 of 3')+ })+})++describe('licenseSentence — a release that was REFUSED', () => {+ it('says when releasing is possible again, in days', () => {+ // ORDERING PIN, the other direction: this detail is a clean keygen read with a refusal code on+ // top. Falling through to the read-failure sentence would tell the user their license could+ // not be read, when in fact it was read fine and only the ACTION was refused.+ const s = licenseSentence(keygen({ error: 'too_soon', retryAfterDays: 12 }))+ expect(s).toBe('You can release devices again in 12 days.')+ expect(s).not.toContain('Could not read')+ })++ it('says "1 day", not "1 days"', () => {+ expect(licenseSentence(keygen({ error: 'too_soon', retryAfterDays: 1 }))).toBe(+ 'You can release devices again in 1 day.'+ )+ })++ it('invents no window when the server stated no retryAfterDays', () => {+ // A default like `?? 30` is a number the server never sent, printed as a date the user will+ // plan around. Degrade to nothing, never to something wrong.+ expect(licenseSentence(keygen({ error: 'too_soon' }))).toBe(+ 'You cannot release devices again yet.'+ )+ expect(licenseSentence(keygen({ error: 'too_soon', retryAfterDays: 0 }))).toBe(+ 'You cannot release devices again yet.'+ )+ })++ it('renders not_applicable as a refused action, not as a failed read', () => {+ // Unreachable through the UI (the release action is shown only for a STATED 'keygen' source,+ // and that is the one source the route never answers 400 for), but a route contract is not a+ // render-time guarantee — so it gets a sentence rather than the failed-read one.+ const s = licenseSentence({ key: null, used: 0, seats: 0, source: 'apple', error: 'not_applicable' })+ expect(s).toBe('Releasing devices does not apply to this license.')+ expect(s).not.toContain('Could not read')+ })+})++describe('licenseSentence — before the first read', () => {+ it('says nothing', () => {+ expect(licenseSentence(null)).toBe('')+ })+})++describe('canReleaseDevices', () => {+ it('is true only for a STATED keygen source', () => {+ expect(canReleaseDevices(keygen())).toBe(true)+ })++ it('is false for every other stated source', () => {+ expect(canReleaseDevices({ key: null, used: 0, seats: 0, source: 'apple', error: null })).toBe(+ false+ )+ expect(canReleaseDevices({ key: null, used: 0, seats: 0, source: 'free', error: null })).toBe(+ false+ )+ })++ it('is false when no source was stated — an unknown source HIDES the action', () => {+ // The gate must be `=== 'keygen'`, never `!== 'apple'`: a null source (every error reply, and+ // the release route's own 200) would then SHOW a release the server can only refuse, and a+ // future source word would inherit the button by default. Both of these pass a `!== 'apple'`.+ expect(canReleaseDevices({ key: null, used: 0, seats: 0, source: null, error: 'offline' })).toBe(+ false+ )+ expect(+ canReleaseDevices({+ key: null,+ used: 0,+ seats: 0,+ source: 'ios' as unknown as LicenseDetail['source'],+ error: null+ })+ ).toBe(false)+ })++ it('is false before the first read', () => {+ expect(canReleaseDevices(null)).toBe(false)+ })++ it('stays true while a release is throttled — the action is refused, not inapplicable', () => {+ // The user must still see the button (and the "in N days" sentence beside it); hiding it here+ // would read as "this license cannot release devices at all".+ expect(canReleaseDevices(keygen({ error: 'too_soon', retryAfterDays: 12 }))).toBe(true)+ })+})diff --git a/src/renderer/lib/licenseCopy.ts b/src/renderer/lib/licenseCopy.tsnew file mode 100644index 000000000..645b2d792--- /dev/null+++ b/src/renderer/lib/licenseCopy.ts@@ -0,0 +1,90 @@+import type { LicenseDetail } from '@shared/types'++/**+ * Settings → License wording, derived from the data in ONE place so a sentence cannot promise+ * something the numbers do not say.+ *+ * Two facts shape every branch below:+ *+ * 1. **`error` carries TWO families and only the code word separates them.** A READ that failed+ * (`unauthorized` | `inactive` | `offline` | `disabled` | `network`) arrives with placeholder+ * zeros and a null key — rendering those as a device count is the bug this module exists to+ * prevent. A refused RELEASE (`too_soon` | `not_applicable`) rides on top of the LAST GOOD+ * read, so its key, source and counts are real; telling that user "could not read your+ * license" would be equally wrong in the other direction. Hence: error first, then which+ * family, then the source.+ * 2. **Seats and devices are the same thing by design**, so the copy says "devices" and names+ * phones explicitly — a paired phone holds a seat too, and a user who does not know that reads+ * the cap as broken.+ */+export function licenseSentence(detail: LicenseDetail | null): string {+ if (!detail) return '' // Before the first read there is nothing to say.++ if (detail.error) {+ // --- Family 2 first: the read was FINE, the action was refused. -----------------------------+ if (detail.error === 'too_soon') {+ const days = detail.retryAfterDays+ // No `?? 30` fallback: a window the server never stated is a date the user would plan+ // around. Degrade to the shape of the fact we do have ("not yet"), never to a made-up number.+ if (typeof days === 'number' && Number.isFinite(days) && days > 0) {+ return `You can release devices again in ${days} ${days === 1 ? 'day' : 'days'}.`+ }+ return 'You cannot release devices again yet.'+ }+ if (detail.error === 'not_applicable') {+ // The panel only offers the release for a stated 'keygen' source, and that is the one source+ // the route never refuses this way — so this should be unreachable. It still gets its own+ // sentence rather than falling into the failed-read one, because a route contract is not a+ // render-time guarantee and "we could not read your license" would be a false alarm.+ return 'Releasing devices does not apply to this license.'+ }++ // --- Family 1: the READ failed. The counts beside this are placeholders, not a measurement. --+ // Deliberately not "could not reach the server": `unauthorized` / `inactive` / `disabled` are+ // answers we DID receive. What is true across the whole family is that we do not know the key+ // or the count — and that Pro keeps working either way (the entitlement is verified locally).+ return 'Could not read this license right now, so the key and device count are unknown. Your Pro access is unaffected.'+ }++ // --- A clean read. What can be said depends entirely on the source the SERVER stated. ---------+ if (detail.source === 'apple') {+ // No keygen call was made for this license, so `used`/`seats` are zeros meaning "not+ // applicable". Printing them would read as a cap that is somehow both empty and full.+ return 'Pro on this Mac comes from the App Store subscription on your paired phone, so there is no license key or device count to show here.'+ }+ if (detail.source === 'free') {+ // A defensive value. Say only what is certain — where it came from is not.+ return 'Pro on this device is not backed by a license key.'+ }+ if (detail.source === 'keygen') {+ if (!detail.key) {+ // Legitimate on a 200: a keygen policy that hides keys, or a license predating the column.+ // This is the only case in which this sentence is true.+ return 'No key is on file for this license yet — get in touch and we will send yours.'+ }+ if (detail.used > detail.seats) {+ // Reachable: a cap lowered after activation. "All N devices are in use" would understate it.+ return `${detail.used} devices are in use, more than the ${detail.seats} this license allows. Release the others below to free them up.`+ }+ if (detail.used === detail.seats) {+ return `All ${detail.seats} devices are in use. Release the others below to free them up.`+ }+ return `${detail.used} of ${detail.seats} devices in use — this Mac and each paired phone counts as a device.`+ }++ // A clean read that stated no source (only reachable by merging a release reply over an empty+ // detail). The counts may be real, but with no source there is no sentence they support.+ return ''+}++/**+ * Whether to offer "Release other devices".+ *+ * Gated on a STATED `'keygen'` — never on `!== 'apple'`. A null source is what every error reply+ * and the release route's own 200 carry, and a source word added later would inherit the button by+ * default; both would offer an action the server can only refuse. A refused release (`too_soon`)+ * still returns true: the action exists, it is merely throttled, and the sentence beside it says so.+ */+export function canReleaseDevices(detail: LicenseDetail | null): boolean {+ return detail?.source === 'keygen'+}