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(check): state the plan so the backend can target paid or free users

reviewdcfae2bf607b
diff --git a/CLAUDE.md b/CLAUDE.md
index eae3d54ef..4669e052f 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -10737,7 +10737,13 @@ Exposed split over two IPC handlers: `announcements.fetch()` → `messages`, `ap
in `localStorage`); `update.mandatory`/`minSupported` flips `UpdateCard` into a blocking required-
update state. The call no-ops under `DO_NOT_TRACK`/`NODETERM_TELEMETRY_DISABLED` or in unpackaged
builds (unless `NODETERM_API_BASE` targets a local server). Schema example:
-`docs/announcements.example.json`. **Telemetry** (`src/main/telemetry.ts`) is a separate opt-out
+`docs/announcements.example.json`. **The request also states `plan=pro|free`** (offline
+`isPremium()`), because the admin console can aim a message at paid or free users and the feed is
+anonymous — the backend cannot look a device's plan up, and matches only on what we send (a build
+that sends no plan sees only audience-less messages). So an answer belongs to the plan it was asked
+with: the 5-min cache is keyed by plan, a failed read after a plan change keeps the update policy but
+NOT the other plan's messages, and the banner re-asks when `useEntitlement.isPremium` flips — else a
+"try Pro" message stays up for six hours after the user pays. **Telemetry** (`src/main/telemetry.ts`) is a separate opt-out
ping to `api.nodeterm.dev/v1/ping` (version/OS on launch + daily), gated on
`settings.telemetryEnabled` + the same build/DNT guards; toggle in Settings → Privacy.
diff --git a/src/core/check.test.ts b/src/core/check.test.ts
index 72ec9f271..3ce4969a8 100644
--- a/src/core/check.test.ts
+++ b/src/core/check.test.ts
@@ -1,5 +1,6 @@
-import { describe, expect, it } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { sanitizeCheckForTest as sanitize } from './check'
+import { fakePlatform } from './platform-fake'
describe('/v1/check sanitize — update notes', () => {
it('carries notes only together with the version they describe', () => {
@@ -28,3 +29,75 @@ describe('/v1/check sanitize — update notes', () => {
expect(sanitize({ update: { notes: 'x'.repeat(50_000), latestVersion: '1' } }).update.notes!.length).toBe(16 * 1024)
})
})
+
+// The feed is anonymous, so the backend can aim a message at paid or free users only by the plan
+// the client states. Read per request and part of the cache key: an "upgrade to Pro" message
+// cached as a free user must not be served for five more minutes to the same user once they pay.
+describe('fetchCheck — reports the plan', () => {
+ const premium = { value: false }
+ let fetchMock: ReturnType<typeof vi.fn>
+
+ const feed = (title: string, minSupported: string | null = null) =>
+ new Response(JSON.stringify({ messages: [{ id: title, title }], update: { minSupported, mandatory: false } }), {
+ status: 200,
+ headers: { 'content-type': 'application/json' }
+ })
+ const planOf = (call: number) => new URL(String(fetchMock.mock.calls[call][0])).searchParams.get('plan')
+ // A fresh module graph per load (the cache is module state), so the platform must be set on the
+ // SAME instance check.ts will import.
+ const loadCheck = async () => {
+ vi.resetModules()
+ ;(await import('./platform')).initPlatform(fakePlatform())
+ return import('./check')
+ }
+
+ beforeEach(() => {
+ vi.doMock('./license', () => ({ isPremium: () => premium.value }))
+ vi.doMock('./device-id', () => ({ getDeviceId: () => '33333333-3333-3333-3333-333333333333' }))
+ vi.stubEnv('NODETERM_API_BASE', 'http://api.test')
+ vi.stubEnv('DO_NOT_TRACK', '')
+ vi.stubEnv('NODETERM_TELEMETRY_DISABLED', '')
+ premium.value = false
+ fetchMock = vi.fn()
+ vi.stubGlobal('fetch', fetchMock)
+ })
+
+ afterEach(() => {
+ vi.unstubAllGlobals()
+ vi.unstubAllEnvs()
+ vi.doUnmock('./license')
+ vi.doUnmock('./device-id')
+ })
+
+ it('sends plan=pro for a Pro install and plan=free otherwise', async () => {
+ fetchMock.mockResolvedValue(feed('x'))
+ premium.value = true
+ await (await loadCheck()).fetchCheck()
+ expect(planOf(0)).toBe('pro')
+
+ premium.value = false
+ await (await loadCheck()).fetchCheck()
+ expect(planOf(1)).toBe('free')
+ })
+
+ it('does not answer a plan change from the other plan’s cache', async () => {
+ const { fetchCheck } = await loadCheck()
+ fetchMock.mockResolvedValueOnce(feed('Try Pro')).mockResolvedValueOnce(feed('Thanks'))
+ expect((await fetchCheck()).messages.map((m) => m.title)).toEqual(['Try Pro'])
+ expect((await fetchCheck()).messages.map((m) => m.title)).toEqual(['Try Pro'])
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+
+ premium.value = true
+ expect((await fetchCheck()).messages.map((m) => m.title)).toEqual(['Thanks'])
+ expect(fetchMock).toHaveBeenCalledTimes(2)
+ expect(planOf(1)).toBe('pro')
+ })
+
+ it('a failed read after a plan change keeps the update policy but not the old plan’s messages', async () => {
+ const { fetchCheck } = await loadCheck()
+ fetchMock.mockResolvedValueOnce(feed('Try Pro', '0.5.0')).mockRejectedValueOnce(new Error('offline'))
+ await fetchCheck()
+ premium.value = true
+ expect(await fetchCheck()).toEqual({ messages: [], update: { minSupported: '0.5.0', mandatory: false } })
+ })
+})
diff --git a/src/core/check.ts b/src/core/check.ts
index 968038bc6..b163c8491 100644
--- a/src/core/check.ts
+++ b/src/core/check.ts
@@ -3,10 +3,13 @@
// banner AND the mandatory-update policy for the Update Card. It also carries the anonymous
// install id (deviceId + os/arch/version), which the backend upserts into `devices` as a
// passive active-install counter — so the version distribution reflects EVERY install, not only
-// the (few) that also opt into the telemetry ping. Nothing personal is sent and the client IP is
-// never stored server-side; a hard opt-out is still DO_NOT_TRACK / NODETERM_TELEMETRY_DISABLED.
+// the (few) that also opt into the telemetry ping. It also states the plan (`pro` | `free`) so a
+// message can be aimed at paid or free users; the backend matches on it and does not store it.
+// Nothing personal is sent and the client IP is never stored server-side; a hard opt-out is still
+// DO_NOT_TRACK / NODETERM_TELEMETRY_DISABLED.
import { platform } from './platform'
import { getDeviceId } from './device-id'
+import { isPremium } from './license'
import type { Announcement, UpdatePolicy } from '../shared/types'
const API_BASE = process.env.NODETERM_API_BASE || 'https://api.nodeterm.dev'
@@ -63,19 +66,31 @@ const NOTES_MAX = 16 * 1024
/** Test seam: the sanitizer is the whole contract with the feed's shape. */
export const sanitizeCheckForTest = sanitize
-let cache: { at: number; data: CheckResult } | null = null
+type Plan = 'pro' | 'free'
+
+// The plan the response was fetched for. The backend aims messages at paid or free users by the
+// plan WE state (the feed is anonymous — it cannot look a device up), so an answer belongs to the
+// plan it was asked with: a purchase or a lapse must not be served the other plan's messages.
+let cache: { at: number; plan: Plan; data: CheckResult } | null = null
export async function fetchCheck(): Promise<CheckResult> {
if (!allowed()) return EMPTY
const now = Date.now()
- if (cache && now - cache.at < CACHE_MS) return cache.data
+ // Offline token verify, so it is cheap to read per call and already right at boot.
+ const plan: Plan = isPremium() ? 'pro' : 'free'
+ if (cache && cache.plan === plan && now - cache.at < CACHE_MS) return cache.data
+ // A failed read keeps the last good answer, except the messages it fetched for another plan.
+ // The update policy does not depend on the plan, so it survives.
+ const fallback = (): CheckResult =>
+ !cache ? EMPTY : cache.plan === plan ? cache.data : { messages: [], update: cache.data.update }
try {
const q = new URLSearchParams({
deviceId: getDeviceId(),
version: platform().appVersion,
os: process.platform,
arch: process.arch,
- channel: 'stable'
+ channel: 'stable',
+ plan
})
const ctrl = new AbortController()
const t = setTimeout(() => ctrl.abort(), 8000)
@@ -83,11 +98,11 @@ export async function fetchCheck(): Promise<CheckResult> {
signal: ctrl.signal,
cache: 'no-cache'
}).finally(() => clearTimeout(t))
- if (!res.ok) return cache?.data ?? EMPTY
+ if (!res.ok) return fallback()
const data = sanitize(await res.json())
- cache = { at: now, data }
+ cache = { at: now, plan, data }
return data
} catch {
- return cache?.data ?? EMPTY
+ return fallback()
}
}
diff --git a/src/renderer/components/AnnouncementBanner.test.tsx b/src/renderer/components/AnnouncementBanner.test.tsx
new file mode 100644
index 000000000..dfde3a9ae
--- /dev/null
+++ b/src/renderer/components/AnnouncementBanner.test.tsx
@@ -0,0 +1,55 @@
+// @vitest-environment jsdom
+import { afterEach, expect, it, vi } from 'vitest'
+import { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { AnnouncementBanner } from './AnnouncementBanner'
+import { useEntitlement } from '../state/entitlement'
+import type { Announcement } from '@shared/types'
+
+// The real store subscribes to the license bridge when it is created; the banner only reads the bit.
+vi.mock('../state/entitlement', async () => {
+ const { create } = await import('zustand')
+ return { useEntitlement: create(() => ({ isPremium: false })) }
+})
+
+const msg = (id: string): Announcement => ({ id, title: id, level: 'info' })
+
+afterEach(() => {
+ useEntitlement.setState({ isPremium: false })
+ localStorage.clear()
+ vi.unstubAllGlobals()
+})
+
+// Main asks the feed with the current plan; the banner has to ask again when the plan changes, or a
+// "try Pro" message aimed at free users stays up for six hours after the user has paid.
+it('re-asks the feed when the plan changes and drops the message the new plan does not get', async () => {
+ const fetch = vi.fn().mockResolvedValueOnce([msg('Try Pro')]).mockResolvedValueOnce([])
+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = { announcements: { fetch } }
+ const el = document.createElement('div')
+ const root = createRoot(el)
+ try {
+ await act(async () => root.render(<AnnouncementBanner />))
+ expect(el.textContent).toContain('Try Pro')
+
+ await act(async () => useEntitlement.setState({ isPremium: true }))
+ expect(fetch).toHaveBeenCalledTimes(2)
+ expect(el.textContent).not.toContain('Try Pro')
+ } finally {
+ await act(async () => root.unmount())
+ }
+})
+
+it('shows the new plan’s message in place of the old one', async () => {
+ const fetch = vi.fn().mockResolvedValueOnce([msg('Try Pro')]).mockResolvedValueOnce([msg('Thanks for paying')])
+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = { announcements: { fetch } }
+ const el = document.createElement('div')
+ const root = createRoot(el)
+ try {
+ await act(async () => root.render(<AnnouncementBanner />))
+ await act(async () => useEntitlement.setState({ isPremium: true }))
+ expect(el.textContent).toContain('Thanks for paying')
+ expect(el.textContent).not.toContain('Try Pro')
+ } finally {
+ await act(async () => root.unmount())
+ }
+})
diff --git a/src/renderer/components/AnnouncementBanner.tsx b/src/renderer/components/AnnouncementBanner.tsx
index 56e083218..5376daeb6 100644
--- a/src/renderer/components/AnnouncementBanner.tsx
+++ b/src/renderer/components/AnnouncementBanner.tsx
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react'
import { IconClose } from './icons'
+import { useEntitlement } from '../state/entitlement'
import type { Announcement } from '@shared/types'
// Polls the remote announcements feed (via the main process) and shows the newest
@@ -27,17 +28,22 @@ function saveSeen(seen: Set<string>): void {
export function AnnouncementBanner(): JSX.Element | null {
const [current, setCurrent] = useState<Announcement | null>(null)
+ // Messages can be aimed at paid or free users, and main asks the feed with the CURRENT plan — so
+ // a purchase or a lapse re-asks now instead of leaving the other plan's message (a "try Pro"
+ // nudge, say) up for six hours.
+ const isPremium = useEntitlement((s) => s.isPremium)
useEffect(() => {
let cancelled = false
const check = async () => {
const items = await window.nodeTerminal.announcements.fetch()
- if (cancelled || !items.length) return
+ if (cancelled) return
const seen = loadSeen()
- // Feed is newest-first; show the first one not yet dismissed.
- const next = items.find((a) => !seen.has(a.id))
- if (next) setCurrent(next)
+ // Feed is newest-first; show the first one not yet dismissed. A message that is no longer in
+ // the feed (deactivated, or aimed at the plan this install just left) comes down with it —
+ // a failed read answers with the last good feed, so going offline does not clear it.
+ setCurrent(items.find((a) => !seen.has(a.id)) ?? null)
}
void check()
@@ -46,7 +52,7 @@ export function AnnouncementBanner(): JSX.Element | null {
cancelled = true
clearInterval(timer)
}
- }, [])
+ }, [isPremium])
if (!current) return null