Skip to content

The agent that grows with you

feat(desktop): offer one-click local setup as a campaign tip

emozilla7f9d84effd49
diff --git a/apps/desktop/src/components/tips/index.tsx b/apps/desktop/src/components/tips/index.tsx
index 0c95f25ff58..480f889b7cb 100644
--- a/apps/desktop/src/components/tips/index.tsx
+++ b/apps/desktop/src/components/tips/index.tsx
@@ -98,6 +98,7 @@ export function TipHost() {
return (
<TipBubble
+ action={tip.action}
anchor={anchor}
keybind={tip.keybind}
onClose={retireActiveTip}
diff --git a/apps/desktop/src/components/tips/local-setup-offer.test.ts b/apps/desktop/src/components/tips/local-setup-offer.test.ts
new file mode 100644
index 00000000000..a91f57ec1e6
--- /dev/null
+++ b/apps/desktop/src/components/tips/local-setup-offer.test.ts
@@ -0,0 +1,132 @@
+/**
+ * The campaign offer against the live stores: eligibility fetch, the showTip
+ * wiring (button included), retirement, the reshow clock, and the cursor
+ * guard that keeps a campaign showing from restarting the rotation's walk.
+ */
+
+import { cleanup } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+const getLocalModelsStatus = vi.fn()
+const getLocalCatalog = vi.fn()
+
+vi.mock('@/hermes', () => ({
+ getLocalCatalog: (...args: unknown[]) => getLocalCatalog(...args),
+ getLocalModelsStatus: (...args: unknown[]) => getLocalModelsStatus(...args)
+}))
+
+import { en } from '@/i18n/en'
+import { LOCAL_SETUP_TIP_ID } from '@/lib/tips/local-cta'
+import { $connection } from '@/store/session'
+import { $activeTip, $lastTipId, $retiredTips, $tipShownAt } from '@/store/tips'
+
+import { offerLocalSetupTip, resetLocalSetupOfferCache } from './local-setup-offer'
+
+function primeEligibleBackend() {
+ getLocalModelsStatus.mockResolvedValue({ models: [], runtime_installed: false })
+ getLocalCatalog.mockResolvedValue({ models: [{ fits: true, id: 'qwen3.8-27b' }] })
+}
+
+async function flushFetch() {
+ await Promise.resolve()
+ await Promise.resolve()
+ await Promise.resolve()
+}
+
+describe('offerLocalSetupTip', () => {
+ beforeEach(() => {
+ resetLocalSetupOfferCache()
+ $activeTip.set(null)
+ $retiredTips.set([])
+ $tipShownAt.set({})
+ $lastTipId.set(null)
+ $connection.set({ mode: 'local' } as never)
+ getLocalModelsStatus.mockReset()
+ getLocalCatalog.mockReset()
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('holds the first quiet moment while the read flies, then shows on the next', async () => {
+ primeEligibleBackend()
+
+ const openLocalModels = vi.fn()
+
+ // First offer: fetch in flight — the moment is HELD (true, so the
+ // rotation's walk cannot take it and arm the cooldown ahead of the
+ // campaign), but nothing is on screen yet.
+ expect(offerLocalSetupTip(en.tips, openLocalModels)).toBe(true)
+ expect($activeTip.get()).toBeNull()
+ await flushFetch()
+
+ // Second offer: cached yes — bubble goes up with the CTA wired.
+ expect(offerLocalSetupTip(en.tips, openLocalModels)).toBe(true)
+
+ const tip = $activeTip.get()
+
+ expect(tip?.tipId).toBe(LOCAL_SETUP_TIP_ID)
+ expect(tip?.action?.label).toBe(en.tips.items['local-setup'].action)
+
+ tip?.action?.onSelect()
+ expect(openLocalModels).toHaveBeenCalledTimes(1)
+ // The CTA closes the bubble on its way to the pane.
+ expect($activeTip.get()).toBeNull()
+ })
+
+ it('never restarts the rotation walk: the campaign id stays out of the cursor', async () => {
+ primeEligibleBackend()
+ $lastTipId.set('cron')
+
+ offerLocalSetupTip(en.tips, vi.fn())
+ await flushFetch()
+ offerLocalSetupTip(en.tips, vi.fn())
+
+ expect($activeTip.get()?.tipId).toBe(LOCAL_SETUP_TIP_ID)
+ expect($lastTipId.get()).toBe('cron')
+ })
+
+ it('stays quiet on an ineligible machine without refetching', async () => {
+ getLocalModelsStatus.mockResolvedValue({ models: [{ id: 'staged' }], runtime_installed: true })
+ getLocalCatalog.mockResolvedValue({ models: [{ fits: true, id: 'qwen3.8-27b' }] })
+
+ offerLocalSetupTip(en.tips, vi.fn())
+ await flushFetch()
+
+ expect(offerLocalSetupTip(en.tips, vi.fn())).toBe(false)
+ expect($activeTip.get()).toBeNull()
+ expect(getLocalModelsStatus).toHaveBeenCalledTimes(1)
+ })
+
+ it('honors the ✕ forever and the ignored-bubble clock for a week', async () => {
+ primeEligibleBackend()
+
+ $retiredTips.set([LOCAL_SETUP_TIP_ID])
+ expect(offerLocalSetupTip(en.tips, vi.fn())).toBe(false)
+ expect(getLocalModelsStatus).not.toHaveBeenCalled()
+
+ $retiredTips.set([])
+ $tipShownAt.set({ [LOCAL_SETUP_TIP_ID]: Date.now() - 60_000 })
+ expect(offerLocalSetupTip(en.tips, vi.fn())).toBe(false)
+ expect(getLocalModelsStatus).not.toHaveBeenCalled()
+ })
+
+ it('asks nothing of a remote backend', () => {
+ $connection.set({ mode: 'remote' } as never)
+
+ expect(offerLocalSetupTip(en.tips, vi.fn())).toBe(false)
+ expect(getLocalModelsStatus).not.toHaveBeenCalled()
+ })
+
+ it('a failed read stands down for the session instead of retrying', async () => {
+ getLocalModelsStatus.mockRejectedValue(new Error('backend gone'))
+ getLocalCatalog.mockRejectedValue(new Error('backend gone'))
+
+ offerLocalSetupTip(en.tips, vi.fn())
+ await flushFetch()
+
+ expect(offerLocalSetupTip(en.tips, vi.fn())).toBe(false)
+ expect(getLocalModelsStatus).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/apps/desktop/src/components/tips/local-setup-offer.ts b/apps/desktop/src/components/tips/local-setup-offer.ts
new file mode 100644
index 00000000000..a2eac54da37
--- /dev/null
+++ b/apps/desktop/src/components/tips/local-setup-offer.ts
@@ -0,0 +1,118 @@
+/**
+ * The local-setup campaign: one bubble on the model pill for machines that
+ * could run local models and haven't set them up.
+ *
+ * Not a rotation tip — a campaign the rotation CONSULTS first at each quiet
+ * due moment (use-tip-rotation.ts): conditional (most machines qualify or
+ * don't, permanently), actionable (it carries the one button a tip may
+ * have), and perishable (setting up local models — or the ✕ — ends it).
+ * A live "your GPU can run this, free and private" outranks the walk's
+ * "the model name is a button" whenever both are true, and an ignored
+ * bubble may return in a week rather than walking on forever.
+ *
+ * Eligibility is fetched, not assumed: the backend's own fit check (the
+ * same catalog `fits` the Local Models pane prices its hero with) decides
+ * whether this machine qualifies. Reads are lazy — nothing polls for a
+ * bubble. The first quiet due moment kicks one status+catalog read and
+ * holds the turn (no walk tip may spend the cooldown ahead of a pending
+ * campaign); the cached answer serves every later one. Completing
+ * setup flips the next read to ineligible, so the campaign retires itself
+ * without bookkeeping — and the cache dies with a connection change,
+ * because eligibility is a fact about the backend's machine.
+ */
+
+import { getLocalCatalog, getLocalModelsStatus } from '@/hermes'
+import type { Translations } from '@/i18n/types'
+import { LOCAL_SETUP_TIP_ID, localSetupDue, localSetupEligible } from '@/lib/tips/local-cta'
+import { $connection } from '@/store/session'
+import { $retiredTips, $tipShownAt, dismissTip, showTip } from '@/store/tips'
+
+/** The pill the bubble points at — the same handle the rotation's
+ * model-switch tip uses, so the two can never drift to different anchors. */
+const MODEL_PILL_TARGETS = ['[data-tour="model-pill"]'] as const
+
+let eligibilityCache: { eligible: boolean } | null = null
+let eligibilityInFlight = false
+let boundToConnection = false
+
+/** Reset the session cache — tests only. */
+export function resetLocalSetupOfferCache(): void {
+ eligibilityCache = null
+ eligibilityInFlight = false
+}
+
+/**
+ * Offer the campaign the current quiet moment. True = it put its bubble up
+ * and the moment is spent; false = the rotation's walk may have it.
+ */
+export function offerLocalSetupTip(copy: Translations['tips'], openLocalModels: () => void): boolean {
+ if ($retiredTips.get().includes(LOCAL_SETUP_TIP_ID)) {
+ return false
+ }
+
+ if (!localSetupDue(Date.now(), $tipShownAt.get()[LOCAL_SETUP_TIP_ID])) {
+ return false
+ }
+
+ // Local backends only: on a remote connection (cloud resolves to remote)
+ // the models would run on the far machine, and "stays on your computer"
+ // would be promising someone else's computer. Checked before the cache so
+ // a re-home mid-session can't serve a stale yes.
+ if (($connection.get()?.mode ?? null) !== 'local') {
+ return false
+ }
+
+ if (!boundToConnection) {
+ boundToConnection = true
+ $connection.listen(() => resetLocalSetupOfferCache())
+ }
+
+ if (!eligibilityCache) {
+ if (!eligibilityInFlight) {
+ eligibilityInFlight = true
+
+ void Promise.all([getLocalModelsStatus(), getLocalCatalog()])
+ .then(([status, catalog]) => {
+ eligibilityCache = {
+ eligible: localSetupEligible($connection.get()?.mode ?? null, status, catalog.models)
+ }
+ })
+ .catch(() => {
+ // No backend answer, no campaign this session. The next launch —
+ // or the next connection — asks again.
+ eligibilityCache = { eligible: false }
+ })
+ .finally(() => {
+ eligibilityInFlight = false
+ })
+ }
+
+ // Hold the moment while the read flies: nothing shows and no cooldown
+ // arms, so the next tick answers from the cache. Handing this moment to
+ // the rotation instead would put a walk tip up first and park the
+ // campaign behind the six-hour cooldown — the exact inversion of the
+ // priority. Costs an ineligible machine one 30s tick, once per session.
+ return true
+ }
+
+ if (!eligibilityCache.eligible) {
+ return false
+ }
+
+ showTip({
+ action: {
+ label: copy.items['local-setup'].action,
+ onSelect: () => {
+ dismissTip()
+ openLocalModels()
+ }
+ },
+ side: 'top',
+ targets: MODEL_PILL_TARGETS,
+ text: copy.items['local-setup'].text,
+ tipId: LOCAL_SETUP_TIP_ID,
+ title: copy.items['local-setup'].title
+ })
+
+ return true
+}
diff --git a/apps/desktop/src/components/tips/tip-bubble.tsx b/apps/desktop/src/components/tips/tip-bubble.tsx
index 103e39a45e0..760a758b2ab 100644
--- a/apps/desktop/src/components/tips/tip-bubble.tsx
+++ b/apps/desktop/src/components/tips/tip-bubble.tsx
@@ -21,8 +21,11 @@ import { useI18n } from '@/i18n'
import { iconSize, X } from '@/lib/icons'
import { useKeybindHint } from '@/lib/keybinds/use-keybind-hint'
import type { TipSide } from '@/lib/tips/catalog'
+import type { ActiveTip } from '@/store/tips'
export interface TipBubbleProps {
+ /** A call to action rendered as the bubble's one button. See ActiveTip. */
+ action?: ActiveTip['action']
/** The element the arrow points at. */
anchor: HTMLElement
/** Keybind action id; its live combo prints under the text. */
@@ -34,7 +37,7 @@ export interface TipBubbleProps {
title?: string
}
-export function TipBubble({ anchor, keybind, onClose, side, text, title }: TipBubbleProps) {
+export function TipBubble({ action, anchor, keybind, onClose, side, text, title }: TipBubbleProps) {
const { t } = useI18n()
const combo = useKeybindHint(keybind ?? '')
const anchorRef = useRef<HTMLElement | null>(anchor)
@@ -81,6 +84,19 @@ export function TipBubble({ anchor, keybind, onClose, side, text, title }: TipBu
{text}
</p>
{combo && <KbdCombo className="mt-2" combo={combo} size="sm" variant="inverted" />}
+ {action && (
+ // The CTA: still not a focus trap — the button is tabbable when
+ // reached but nothing steals the caret to get there. Inverted
+ // fill against the accent surface, same currentColor discipline
+ // as the rest of the bubble.
+ <button
+ className="mt-2.5 inline-flex cursor-pointer items-center rounded-md bg-current/15 px-2.5 py-1 text-[length:var(--conversation-caption-font-size)] font-semibold transition-colors hover:bg-current/25"
+ onClick={action.onSelect}
+ type="button"
+ >
+ {action.label}
+ </button>
+ )}
</div>
<button
aria-label={t.tips.close}
diff --git a/apps/desktop/src/components/tips/use-tip-rotation.ts b/apps/desktop/src/components/tips/use-tip-rotation.ts
index ff8fe433df2..53a7310ab7e 100644
--- a/apps/desktop/src/components/tips/use-tip-rotation.ts
+++ b/apps/desktop/src/components/tips/use-tip-rotation.ts
@@ -20,7 +20,9 @@
*/
import { useEffect } from 'react'
+import { useNavigate } from 'react-router'
+import { SETTINGS_ROUTE } from '@/app/routes'
import type { Translations } from '@/i18n/types'
import { resolveTipAnchor } from '@/lib/tips/anchor'
import { TIP_CATALOG } from '@/lib/tips/catalog'
@@ -28,6 +30,8 @@ import { nextTip } from '@/lib/tips/rotation'
import { $awaitingResponse, $busy } from '@/store/session'
import { $activeTip, $lastTipId, $nextTipAt, $retiredTips, $tipsEnabled, showTip } from '@/store/tips'
+import { offerLocalSetupTip } from './local-setup-offer'
+
const TICK_MS = 30_000
/** Nothing in the first stretch of a launch, however long the cooldown says
* it's been: you opened the app to do a thing, and the tip can wait until
@@ -60,6 +64,8 @@ function appIsQuiet(lastTypedAt: number): boolean {
/** Drive the ambient rotation for as long as the host is mounted. */
export function useTipRotation(copy: Translations['tips']) {
+ const navigate = useNavigate()
+
useEffect(() => {
let lastTypedAt = 0
let settledAt = Date.now() + SETTLE_MIN_MS + Math.random() * SETTLE_SPREAD_MS
@@ -83,6 +89,18 @@ export function useTipRotation(copy: Translations['tips']) {
return
}
+ // Campaigns outrank the walk: a conditional, actionable tip that is
+ // live right now (the local-setup CTA) says something about THIS
+ // machine, which beats the catalog's standing introduction. It shares
+ // the cooldown, so taking the moment still costs it the usual hours.
+ if (
+ offerLocalSetupTip(copy, () => {
+ navigate(`${SETTINGS_ROUTE}?tab=providers&pview=local`)
+ })
+ ) {
+ return
+ }
+
// Only tips with something on screen to point at are candidates, so the
// rotation never burns a turn on a pane the user isn't showing.
const onScreen = TIP_CATALOG.filter(tip => resolveTipAnchor(document, tip.targets))
@@ -128,5 +146,5 @@ export function useTipRotation(copy: Translations['tips']) {
window.clearInterval(timer)
window.removeEventListener('keydown', noteTyping, true)
}
- }, [copy])
+ }, [copy, navigate])
}
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 6202019c708..bfdf3bb6951 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -2881,6 +2881,11 @@ export const ar = defineLocale({
title: 'بدّل النموذج أثناء المحادثة',
text: 'اسم النموذج زر. غيّره كلما تغيّرت طبيعة العمل.'
},
+ 'local-setup': {
+ title: 'هذا الجهاز يمكنه تشغيل النماذج محليًا',
+ text: 'عتادك قادر على تشغيل نموذج محلي. تبقى محادثاتك على جهازك ولا تكلف شيئًا.',
+ action: 'إعداد الآن'
+ },
'right-pane': {
title: 'لوحة العمل',
text: 'الملفات والطرفية والمراجعة والمتصفح المدمج تتشارك اللوحة الجانبية.'
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 5b04142f096..7346052303a 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -3623,6 +3623,11 @@ export const en: Translations = {
title: 'Switch models mid-thread',
text: 'The model name is a button. Change it whenever the work changes shape.'
},
+ 'local-setup': {
+ title: 'This machine can run models locally',
+ text: 'Your hardware can serve a local model. Chats stay on your computer and cost nothing.',
+ action: 'Set it up'
+ },
'right-pane': {
title: 'The working pane',
text: 'Files, terminal, review and the in-app browser share the right side.'
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 0859566429a..f5a5fe64079 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -3231,6 +3231,11 @@ export const ja = defineLocale({
title: '会話の途中でモデルを変更',
text: 'モデル名はボタンです。作業の性質が変わったら切り替えてください。'
},
+ 'local-setup': {
+ title: 'このマシンはローカルでモデルを実行できます',
+ text: 'お使いのハードウェアでローカルモデルを動かせます。会話はこのコンピュータから出ず、料金もかかりません。',
+ action: 'セットアップ'
+ },
'right-pane': {
title: '作業用ペイン',
text: 'ファイル、ターミナル、レビュー、アプリ内ブラウザはサイドペインにまとまっています。'
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 685db631b8a..cb1bee39ea9 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -3101,8 +3101,12 @@ export interface Translations {
tips: {
close: string
- /** Keyed by `TipId`, so a new tip without copy is a type error. */
- items: Record<TipId, { title: string; text: string }>
+ /** Keyed by `TipId`, so a new tip without copy is a type error. Plus the
+ * campaign tips, which live outside the rotation's catalog: they carry
+ * a button, and `action` is its label. */
+ items: Record<TipId, { title: string; text: string }> & {
+ 'local-setup': { title: string; text: string; action: string }
+ }
}
errors: {
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index d792bd0eee3..a45b3f6f5f8 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -3110,6 +3110,11 @@ export const zhHant = defineLocale({
title: '對話中隨時換模型',
text: '模型名稱就是按鈕。工作性質變了就換一個。'
},
+ 'local-setup': {
+ title: '這台電腦可以本地執行模型',
+ text: '你的硬體可以執行本地模型。對話不離開你的電腦,而且完全免費。',
+ action: '立即設定'
+ },
'right-pane': {
title: '工作面板',
text: '檔案、終端機、審閱與內建瀏覽器都在側邊面板裡。'
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 2e7df6236a4..66b7652672e 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -3763,6 +3763,11 @@ export const zh: Translations = {
title: '对话中随时换模型',
text: '模型名称就是按钮。工作性质变了就换一个。'
},
+ 'local-setup': {
+ title: '这台电脑可以本地运行模型',
+ text: '你的硬件可以运行本地模型。对话不离开你的电脑,而且完全免费。',
+ action: '立即设置'
+ },
'right-pane': {
title: '工作面板',
text: '文件、终端、审阅和内置浏览器都在侧边面板里。'
diff --git a/apps/desktop/src/lib/tips/local-cta.test.ts b/apps/desktop/src/lib/tips/local-cta.test.ts
new file mode 100644
index 00000000000..44c350e68b6
--- /dev/null
+++ b/apps/desktop/src/lib/tips/local-cta.test.ts
@@ -0,0 +1,86 @@
+/**
+ * The local-setup campaign's policy, tested as the pure decisions they are:
+ * who qualifies (eligibility), when the bubble may return (the clock), and
+ * that the campaign cannot corrupt the rotation's cursor.
+ */
+
+import { describe, expect, it } from 'vitest'
+
+import { TIP_CATALOG } from '@/lib/tips/catalog'
+import { LOCAL_SETUP_RESHOW_MS, LOCAL_SETUP_TIP_ID, localSetupDue, localSetupEligible } from '@/lib/tips/local-cta'
+import type { LocalCatalogModel, LocalModelsStatus } from '@/types/hermes'
+
+function status(overrides: Partial<LocalModelsStatus> = {}): LocalModelsStatus {
+ return {
+ active_model_id: null,
+ loading: {},
+ models: [],
+ models_dir: '',
+ placement: null,
+ runtime_installed: false,
+ server_running: false,
+ ...overrides
+ } as LocalModelsStatus
+}
+
+function fittingModel(): LocalCatalogModel {
+ return { fits: true, id: 'qwen3.8-27b' } as LocalCatalogModel
+}
+
+describe('localSetupEligible', () => {
+ it('offers setup to a local backend with a fitting model and nothing staged', () => {
+ expect(localSetupEligible('local', status(), [fittingModel()])).toBe(true)
+ })
+
+ it('never promises local privacy on a remote or cloud backend', () => {
+ for (const mode of ['remote', 'cloud', 'ssh', null]) {
+ expect(localSetupEligible(mode, status(), [fittingModel()])).toBe(false)
+ }
+ })
+
+ it('stays quiet when no catalog model fits the machine', () => {
+ expect(localSetupEligible('local', status(), [{ fits: false } as LocalCatalogModel])).toBe(false)
+ expect(localSetupEligible('local', status(), [])).toBe(false)
+ })
+
+ it('retires itself once the machine is set up', () => {
+ const setUp = status({
+ models: [{ id: 'qwen3.8-27b' }] as LocalModelsStatus['models'],
+ runtime_installed: true
+ })
+
+ expect(localSetupEligible('local', setUp, [fittingModel()])).toBe(false)
+ })
+
+ it('still offers when the runtime exists but no model is staged', () => {
+ expect(localSetupEligible('local', status({ runtime_installed: true }), [fittingModel()])).toBe(true)
+ })
+
+ it('answers false while state is still loading', () => {
+ expect(localSetupEligible('local', null, [fittingModel()])).toBe(false)
+ expect(localSetupEligible('local', status(), null)).toBe(false)
+ })
+})
+
+describe('localSetupDue', () => {
+ it('is due when never shown', () => {
+ expect(localSetupDue(Date.now(), undefined)).toBe(true)
+ })
+
+ it('holds for a week after an ignored showing, then returns', () => {
+ const now = Date.now()
+
+ expect(localSetupDue(now, now - LOCAL_SETUP_RESHOW_MS + 1000)).toBe(false)
+ expect(localSetupDue(now, now - LOCAL_SETUP_RESHOW_MS)).toBe(true)
+ })
+})
+
+describe('campaign identity', () => {
+ it('lives outside the rotation catalog — the walk must never land on it', () => {
+ // TipId already excludes the campaign id at the type level; this guards
+ // the runtime data against someone re-adding it as a catalog entry.
+ const ids: readonly string[] = TIP_CATALOG.map(def => def.id)
+
+ expect(ids).not.toContain(LOCAL_SETUP_TIP_ID)
+ })
+})
diff --git a/apps/desktop/src/lib/tips/local-cta.ts b/apps/desktop/src/lib/tips/local-cta.ts
new file mode 100644
index 00000000000..df667a56b8b
--- /dev/null
+++ b/apps/desktop/src/lib/tips/local-cta.ts
@@ -0,0 +1,55 @@
+/**
+ * The local-setup call to action — eligibility as data in, data out.
+ *
+ * The one campaign tip the app currently runs: a machine that could serve a
+ * local model, on a backend that has none staged, gets one bubble on the
+ * model pill saying so, with the button that starts the already-built
+ * one-click setup. Everything here is a pure decision over fetched state so
+ * the policy is testable without a DOM or a backend.
+ *
+ * Why this is not a rotation tip: the rotation teaches the app the user
+ * already has, on a weeks-long walk. This tip is conditional (most machines
+ * either qualify or don't, permanently), actionable (it carries a button),
+ * and perishable (setting up local models — or ✕ — ends it forever). It
+ * outranks the walk when live because "your GPU can do this" beats "the
+ * model name is a button" every time both are true.
+ */
+
+import type { LocalCatalogModel, LocalModelsStatus } from '@/types/hermes'
+
+/** Retirement/shown-at ledger id. Not a `TipId` — the rotation never walks it. */
+export const LOCAL_SETUP_TIP_ID = 'local-setup'
+
+/** A CTA ignored (timed out) may return, but on a much longer clock than the
+ * rotation's: it is the same message twice, not a tour moving on. */
+export const LOCAL_SETUP_RESHOW_MS = 7 * 24 * 60 * 60_000
+
+/**
+ * Machines qualify when the catalog has a model that FITS (the backend's
+ * physics check, same answer the pane's hero uses) and nothing is servable
+ * yet — no runtime or no staged models. A set-up machine never qualifies, so
+ * completing setup retires this tip without any bookkeeping.
+ *
+ * `connectionMode` must be 'local': on a remote backend (cloud resolves to
+ * remote) the models would run on the far machine, and a bubble promising
+ * "stays on your computer" would be promising someone else's computer.
+ */
+export function localSetupEligible(
+ connectionMode: null | string,
+ status: LocalModelsStatus | null,
+ catalog: readonly LocalCatalogModel[] | null
+): boolean {
+ if (connectionMode !== 'local' || !status || !catalog) {
+ return false
+ }
+
+ const needsSetup = !status.runtime_installed || status.models.length === 0
+
+ return needsSetup && catalog.some(model => model.fits)
+}
+
+/** Due = never shown, or shown long enough ago that repeating it reads as a
+ * reminder rather than a nag. Retirement is the caller's ledger, not ours. */
+export function localSetupDue(now: number, shownAt: number | undefined): boolean {
+ return shownAt === undefined || now - shownAt >= LOCAL_SETUP_RESHOW_MS
+}
diff --git a/apps/desktop/src/store/tips.ts b/apps/desktop/src/store/tips.ts
index e09d605b2a7..f24344e652e 100644
--- a/apps/desktop/src/store/tips.ts
+++ b/apps/desktop/src/store/tips.ts
@@ -25,13 +25,18 @@
import { atom } from 'nanostores'
import { Codecs, persistentAtom } from '@/lib/persisted'
-import type { TipSide } from '@/lib/tips/catalog'
+import { TIP_CATALOG, type TipSide } from '@/lib/tips/catalog'
/** Hours, not minutes. The catalog is ten tips and it should take weeks. */
const COOLDOWN_MS = 6 * 60 * 60_000
/** A tip as the bubble needs it: resolved copy, resolved anchor. */
export interface ActiveTip {
+ /** A call to action: one button under the text. What separates a campaign
+ * tip from the rotation's — the rotation teaches, this one offers to DO
+ * the thing, and the button is the only path (an ambient bubble must
+ * never make its whole face clickable). Clicking closes the tip. */
+ action?: { label: string; onSelect: () => void }
/** Keybind action id whose live combo the bubble prints. */
keybind?: string
side: TipSide
@@ -57,6 +62,23 @@ export const $nextTipAt = persistentAtom<null | number>(
)
export const $activeTip = atom<ActiveTip | null>(null)
+/** When each campaign tip (id outside the rotation catalog) last showed.
+ * Campaign tips re-offer on their own long clock instead of walking on;
+ * `$retiredTips` still owns the hard ✕. */
+export const $tipShownAt = persistentAtom<Record<string, number>>(
+ 'hermes.desktop.tips.shownAt.v1',
+ {},
+ Codecs.json(value => {
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
+ return {}
+ }
+
+ return Object.fromEntries(
+ Object.entries(value).filter((entry): entry is [string, number] => typeof entry[1] === 'number')
+ )
+ })
+)
+
export function setTipsEnabled(enabled: boolean): void {
if (!enabled) {
// Including whichever one is up: the switch is answering a bubble on
@@ -77,7 +99,14 @@ export function resetTips(): void {
/** Put a tip on screen, replacing whatever was there. */
export function showTip(tip: ActiveTip): void {
if (tip.tipId) {
- $lastTipId.set(tip.tipId)
+ // The cursor belongs to the rotation's walk. A campaign tip (an id the
+ // catalog doesn't hold) records when it showed but must not move the
+ // cursor — nextTip treats an unknown id as "start over at the top".
+ if (TIP_CATALOG.some(def => def.id === tip.tipId)) {
+ $lastTipId.set(tip.tipId)
+ }
+
+ $tipShownAt.set({ ...$tipShownAt.get(), [tip.tipId]: Date.now() })
}
// Any tip starts the cooldown, an agent's included: whoever just pointed at