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
fix(license): a 2xx we could not read is an error, never "0 devices"
enes5cca8d5ec140
diff --git a/src/core/license.test.ts b/src/core/license.test.tsindex 74ed77896..511ff287b 100644--- a/src/core/license.test.ts+++ b/src/core/license.test.ts@@ -486,6 +486,9 @@ describe('license detail + release', () => {// server makes zero keygen calls for it and answers 200 with no key and no machines — those// zeros mean "device counting does not apply here", NOT "the read failed". `source` is the// only thing that tells the two apart, and the UI hides the release action on it.+ //+ // This is also the fixture that stops the malformed-2xx guard below from OVER-firing: these+ // zeros are stated numbers, so they must still read as a success.storeToken()await boot(vi.fn(async () => jsonResponse({ key: null, used: 0, seats: 0, source: 'apple' })))@@ -586,15 +589,33 @@ describe('license detail + release', () => {expect(d.seats).toBe(3)})- it('accepts only real numbers as counts, so nothing renders as NaN or as a string', async () => {- // The contract says numbers. A body that says otherwise is malformed, and `json.used ?? 0`- // would forward whatever it holds — "3" into a meter, or NaN out of arithmetic on it.+ it('a 2xx whose counts are not numbers is a FAILED READ, not a license with no devices', async () => {+ // The scenario: a captive portal or corporate proxy answers the POST with a 200 HTML page, or+ // a bad deploy answers `200 {}` / `200 {"used":"3"}`. Coercing those to zeros with error null+ // renders "0 of 0 devices" and an empty key as fact — a subscriber told they have no license.storeToken()await boot(vi.fn(async () => jsonResponse({ key: 'K', used: '3', seats: null, source: 'keygen' })))- const d = await detail()- expect(d.used).toBe(0)- expect(d.seats).toBe(0)+ expect(await detail()).toEqual({+ key: null,+ used: 0,+ seats: 0,+ source: null,+ error: 'network'+ })++ // The 200 HTML page: the body does not parse at all.+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => ({+ ok: true,+ status: 200,+ json: async () => {+ throw new SyntaxError('Unexpected token <')+ }+ }))+ )+ expect((await detail()).error).toBe('network')})it('refuses to call the server with no stored entitlement', async () => {@@ -635,6 +656,11 @@ describe('license detail + release', () => {await boot(vi.fn(async () => jsonResponse({ key: 'K', used: 1, seats: 3, source: 'paddle' })))- expect((await detail()).source).toBeNull()+ const d = await detail()+ expect(d.source).toBeNull()+ // …and it stays a SUCCESS. Stamping an error here would hide the whole panel over a reply that+ // carried a perfectly good key and device count.+ expect(d.error).toBeNull()+ expect(d.key).toBe('K')})})diff --git a/src/core/license.ts b/src/core/license.tsindex 2dff0f53a..04b4e7d90 100644--- a/src/core/license.ts+++ b/src/core/license.ts@@ -119,8 +119,10 @@ function licenseSourceOf(v: unknown): LicenseSource | null {return typeof v === 'string' && LICENSE_SOURCES.includes(v) ? (v as LicenseSource) : null}-function countOf(v: unknown): number {- return typeof v === 'number' && Number.isFinite(v) ? v : 0+/** A count the server actually stated. A string, null or NaN is not one — see the 2xx guard in+ * `licenseCall`, where "we could not read the body" must stay distinct from "no devices". */+function isCount(v: unknown): v is number {+ return typeof v === 'number' && Number.isFinite(v)}function statusFrom(token: string | undefined, error: string | null = null): LicenseStatus {@@ -253,20 +255,29 @@ export function initLicense(onChange?: () => void): void {// The server's own reason code (401 unauthorized / 402 inactive / 429 too_soon /// 400 not_applicable) is kept verbatim: the UI tells those four apart. `retryAfterDays`// rides only 429 and is the whole content of that answer.- const days = countOf(json.retryAfterDays)+ const days = isCount(json.retryAfterDays) ? json.retryAfterDays : 0return {...EMPTY_DETAIL,error: typeof json.error === 'string' && json.error ? json.error : 'network',...(days > 0 ? { retryAfterDays: days } : {})}}+ // A 2xx we could not READ is a failed read, not a license with no devices. A captive portal+ // or corporate proxy answers this POST with a 200 HTML page, and a bad deploy can answer+ // `200 {}` or `200 {"used":"3"}` — coercing any of those to 0 while leaving `error` null+ // renders "0 of 0 devices" and an empty key AS FACT, which is the one thing this route+ // exists to prevent. Both counts must be real numbers; the legitimate non-keygen 200 states+ // exactly that (`{key:null, used:0, seats:0, source:'apple'}`) and is untouched.+ if (!isCount(json.used) || !isCount(json.seats)) {+ return { ...EMPTY_DETAIL, error: 'network' }+ }return {// `key: null` on a 200 is a real state (a keygen policy that hides keys, a license older// than the column, a non-keygen source) — a success, not a failed read.key: typeof json.key === 'string' ? json.key : null,// Never clamped against seats: a cap lowered after activation makes used > seats real.- used: countOf(json.used),- seats: countOf(json.seats),+ used: json.used,+ seats: json.seats,source: licenseSourceOf(json.source),error: null}diff --git a/src/renderer/bridge/stubs.test.ts b/src/renderer/bridge/stubs.test.tsindex e8097800a..9cd7f4858 100644--- a/src/renderer/bridge/stubs.test.ts+++ b/src/renderer/bridge/stubs.test.ts@@ -72,6 +72,11 @@ describe('bridge stubs', () => {await expect(s.sessionMemory.read()).resolves.toEqual({ ok: false, rows: [], mem: null })await expect(s.sessionMemory.host()).resolves.toBeNull()await expect(s.license.getStatus()).rejects.toMatchObject({ code: E_UNSUPPORTED })+ // The license layer runs only in src/main, so the key + device cap cannot be read here. These+ // must REJECT rather than resolve a fabricated LicenseDetail — an `{used:0, seats:0}` with a+ // null error would render "0 of 0 devices" and an empty key as fact in Settings → License.+ await expect(s.license.detail()).rejects.toMatchObject({ code: E_UNSUPPORTED })+ await expect(s.license.releaseOthers()).rejects.toMatchObject({ code: E_UNSUPPORTED })})it('shell.openExternal opens a new browser tab; reveal/openPath are documented no-ops', () => {diff --git a/src/renderer/state/entitlement.test.ts b/src/renderer/state/entitlement.test.tsindex 2f17e56f4..05dabb7e1 100644--- a/src/renderer/state/entitlement.test.ts+++ b/src/renderer/state/entitlement.test.ts@@ -135,6 +135,12 @@ describe('entitlement store — detail read vs release merge', () => {const useEntitlement = await freshStore()detail.mockResolvedValue(LOADED)await useEntitlement.getState().loadDetail()+ // Leave an OPTIONAL field in state first. Every other field is stated by the incoming reply,+ // so `{...prev, ...next}` is byte-identical to a replace and nothing could tell them apart;+ // `retryAfterDays` is the one thing a merge would carry over, so it is the discriminator.+ releaseOthers.mockResolvedValue({ ...ZEROS, error: 'too_soon', retryAfterDays: 12 })+ await useEntitlement.getState().releaseOthers()+ expect(useEntitlement.getState().detail!.retryAfterDays).toBe(12)// The same install re-read after the entitlement moved to an App Store purchase: no key, no// machines, source 'apple'. Merging here would keep a key that is no longer this license's@@ -144,12 +150,15 @@ describe('entitlement store — detail read vs release merge', () => {await useEntitlement.getState().loadDetail()expect(useEntitlement.getState().detail).toEqual(apple)+ expect(useEntitlement.getState().detail!.retryAfterDays).toBeUndefined()})it('a failed read replaces too — its error is the state, not a footnote on stale counts', async () => {const useEntitlement = await freshStore()detail.mockResolvedValue(LOADED)await useEntitlement.getState().loadDetail()+ releaseOthers.mockResolvedValue({ ...ZEROS, error: 'too_soon', retryAfterDays: 12 })+ await useEntitlement.getState().releaseOthers()detail.mockResolvedValue({ ...ZEROS, error: 'offline' })await useEntitlement.getState().loadDetail()@@ -160,5 +169,7 @@ describe('entitlement store — detail read vs release merge', () => {// read's own answer, so the store forwards them rather than papering over with the last ones.expect(d.key).toBeNull()expect(d.used).toBe(0)+ // …and the refused release's retry window does not survive a fresh read (see above).+ expect(d.retryAfterDays).toBeUndefined()})})diff --git a/src/renderer/state/entitlement.ts b/src/renderer/state/entitlement.tsindex 051a301a5..61f8b09e3 100644--- a/src/renderer/state/entitlement.ts+++ b/src/renderer/state/entitlement.ts@@ -8,8 +8,19 @@ interface EntitlementState {/** Team seat cap (premium → max(3, N), premium-no-field → 3 = Pro's free seats, free/inactive* → 0). Mirrors `status.seats` so the Team seats section can select it directly. */seats: number- /** The license key + device usage, or null before the first read. `detail.error` is the read's- * verdict: non-null means we could not look, and its zeros are NOT a device count. */+ /**+ * The license key + device usage, or null before the first read.+ *+ * **`detail.error` carries TWO different facts, and only the code word separates them:**+ * - **The read failed** — `unauthorized` | `inactive` | `offline` | `disabled` | `network`.+ * Everything beside it is a placeholder: the zeros are NOT a device count and the null key is+ * not "no key". Render the failure, never the numbers.+ * - **The read was fine; the RELEASE was refused** — `too_soon` (with `retryAfterDays`) |+ * `not_applicable`. These ride on top of the last good read (see `releaseOthers`), so `key`,+ * `source` and the counts are real and worth showing — say the action was refused, not that+ * the license could not be read. (The counts are the last good read's; if nothing was ever+ * read successfully they are still EMPTY_DETAIL's zeros, so call `loadDetail` first.)+ */detail: LicenseDetail | nullhydrate(): Promise<void>/** Open Stripe checkout for this device; Pro arrives via onChange when the purchase lands.@@ -18,9 +29,13 @@ interface EntitlementState {activate(key: string): Promise<void>deactivate(): Promise<void>/** Read the key + device usage (token-authorized). Replaces `detail` wholesale — it is the one- * call that states every field. */+ * call that states every field.+ * **REJECTS on the Server Edition** (`E_UNSUPPORTED` from the bridge stub — there is no license+ * layer in `src/server`), and neither this nor `releaseOthers` catches it. A caller that fires+ * this on mount must `.catch(…)`, or it is an unhandled rejection on every browser session. */loadDetail(): Promise<void>- /** Deactivate every other device on this license, then fold the new counts into `detail`. */+ /** Deactivate every other device on this license, then fold the new counts into `detail`.+ * Rejects on the Server Edition exactly like `loadDetail` — see there. */releaseOthers(): Promise<void>}