The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(chat): der Docs-Knopf sperrt niemanden aus und verspricht nichts Falsches
purplea9a1973a506e
diff --git a/src/api/__tests__/embed-lane-names-the-host.test.ts b/src/api/__tests__/embed-lane-names-the-host.test.tsnew file mode 100644index 00000000..75bd52fa--- /dev/null+++ b/src/api/__tests__/embed-lane-names-the-host.test.ts@@ -0,0 +1,120 @@+/**+ * Review B2, 2026-09-02: the Docs panel was about to tell every Cloud-mode user+ * "your documents are indexed on this computer and stay here". That is true on+ * the bundled lane and on a loopback Ollama. It is FALSE the moment someone+ * points LU at another machine, which the app fully supports (the GUI endpoint+ * field, or OLLAMA_HOST at startup): indexing pushes every chunk of every+ * document to that host, not just the passages a question matches.+ *+ * A privacy sentence that is wrong in a supported configuration is worse than+ * no sentence. So the probe reports the LANE, and the wording follows it.+ *+ * Run: npx vitest run src/api/__tests__/embed-lane-names-the-host.test.ts+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'++let embedRunning = false+let bundled: { name: string; path: string }[] = []+let ollamaUp = true+let ollamaModels: { name: string }[] = []+let base = 'http://localhost:11434'++vi.mock('../backend', () => ({+ backendCall: async (cmd: string) => {+ if (cmd === 'bundled_embed_status') return { running: embedRunning, healthy: embedRunning }+ if (cmd === 'list_bundled_models') return { dir: '/models', models: bundled }+ return null+ },+ localFetch: async () => new Response('{}', { status: 200 }),+ ollamaUrl: (p: string) => `${base}/api${p}`,+ isTauri: () => false,+ getOllamaBase: () => base,+ isOllamaLocal: () => {+ const h = new URL(base).hostname.toLowerCase()+ return h === 'localhost' || h === '127.0.0.1' || h === '::1' || h === '0.0.0.0'+ },+}))++vi.mock('../ollama', () => ({+ checkConnection: async () => ollamaUp,+ listModels: async () => ollamaModels,+}))++// The built-in engine is NOT the active backend in these cases, so the probe+// falls through to the bundled-server check and then to Ollama.+vi.mock('../../stores/providerStore', () => ({+ useProviderStore: {+ getState: () => ({ providers: { openai: { enabled: false, managed: false } } }),+ },+}))++import { embeddingLane, embeddingBackendReady, laneIsOnThisMachine } from '../embed-availability'++beforeEach(() => {+ embedRunning = false+ bundled = []+ ollamaUp = true+ ollamaModels = []+ base = 'http://localhost:11434'+})++describe('the probe reports WHERE the text would go, not just whether it can go', () => {+ it('the bundled embeddings server is the bundled lane, and it never leaves the box', async () => {+ embedRunning = true+ const info = await embeddingLane('nomic-embed-text')+ expect(info).toEqual({ lane: 'bundled', endpoint: null })+ expect(laneIsOnThisMachine(info.lane)).toBe(true)+ })++ it('loopback Ollama is a local lane and names no host', async () => {+ ollamaModels = [{ name: 'nomic-embed-text:latest' }]+ const info = await embeddingLane('nomic-embed-text')+ expect(info).toEqual({ lane: 'ollama-local', endpoint: null })+ expect(laneIsOnThisMachine(info.lane)).toBe(true)+ })++ it('127.0.0.1 counts as local too, spelled either way', async () => {+ base = 'http://127.0.0.1:11434'+ ollamaModels = [{ name: 'nomic-embed-text' }]+ expect((await embeddingLane('nomic-embed-text')).lane).toBe('ollama-local')+ })++ it('a LAN Ollama is a REMOTE lane and hands back the host it would ship to', async () => {+ base = 'http://192.168.0.54:11434'+ ollamaModels = [{ name: 'nomic-embed-text' }]+ const info = await embeddingLane('nomic-embed-text')+ expect(info.lane).toBe('ollama-remote')+ expect(info.endpoint).toBe('http://192.168.0.54:11434')+ // The claim the panel must not make in this configuration.+ expect(laneIsOnThisMachine(info.lane)).toBe(false)+ })++ it('a named remote host is remote as well, not just a raw IP', async () => {+ base = 'http://dd.local:11434'+ ollamaModels = [{ name: 'nomic-embed-text' }]+ expect((await embeddingLane('nomic-embed-text')).lane).toBe('ollama-remote')+ })++ it('nothing installed anywhere is no lane at all', async () => {+ ollamaModels = [{ name: 'llama3.1:8b' }]+ expect(await embeddingLane('nomic-embed-text')).toEqual({ lane: 'none', endpoint: null })+ })++ it('Ollama unreachable is no lane either, and no host is invented', async () => {+ ollamaUp = false+ const info = await embeddingLane('nomic-embed-text')+ expect(info.lane).toBe('none')+ expect(info.endpoint).toBeNull()+ })++ it('the yes/no question still answers the same way for every working lane', async () => {+ // Negative control: the richer return value must not have changed the+ // upload pre-flight's answer in any case.+ ollamaModels = [{ name: 'nomic-embed-text' }]+ expect(await embeddingBackendReady('nomic-embed-text')).toBe(true)+ base = 'http://192.168.0.54:11434'+ expect(await embeddingBackendReady('nomic-embed-text')).toBe(true)+ ollamaModels = []+ expect(await embeddingBackendReady('nomic-embed-text')).toBe(false)+ })+})diff --git a/src/api/embed-availability.ts b/src/api/embed-availability.tsindex 6de7832f..fc9f8bbd 100644--- a/src/api/embed-availability.ts+++ b/src/api/embed-availability.ts@@ -1,10 +1,10 @@/**- * Can this machine embed a document right now.+ * Can this machine embed a document right now, and WHERE would the text go.** One question, one answer, for every surface that needs it: the RAG upload- * pre-flight (hooks/useRAG), the RAG panel's install card, and the Docs button- * in the composer (hooks/useDocsAvailability). It lived inside useRAG before- * A9, which is why the composer could not ask it and hid the button on+ * pre-flight (hooks/useRAG), the RAG panel's install card and privacy line, and+ * the Docs button in the composer (hooks/useEmbedLane). It lived inside useRAG+ * before A9, which is why the composer could not ask it and hid the button on* `appMode === 'cloud'` instead.** It asks the lane that will ACTUALLY run (api/rag.ts routes the same way):@@ -13,6 +13,13 @@* 2026-08-15 bug. Ollama had nomic-embed-text pulled, the bundled lane had no* embedding GGUF at all, and nobody asked the lane that ran.*+ * The lane, not just a yes/no, because the honest sentence depends on it.+ * Ollama's base URL is user-configurable (GUI `set_ollama_host`, or OLLAMA_HOST+ * at startup), so "your documents stay on this computer" is simply false when+ * the user pointed LU at a LAN box: indexing sends EVERY chunk of every+ * document to that host, not just the passages that match a question. Review+ * finding B2, 2026-09-02.+ ** Nothing here reads appMode. The embeddings server is a local sidecar and the* app resumes it in Cloud mode too (useModels.resumeEmbedServer).*/@@ -22,6 +29,34 @@ import {bundledEmbedLaneReady,} from './engine'import { checkConnection, listModels } from './ollama'+import { getOllamaBase, isOllamaLocal } from './backend'++/**+ * Where indexing would send the text.+ *+ * - `bundled` the app's own llama-server on 127.0.0.1:8128. Never leaves the box.+ * - `ollama-local` Ollama on loopback. Never leaves the box either.+ * - `ollama-remote` Ollama on a LAN or remote host the user configured. The+ * whole document goes there to be indexed.+ * - `none` nothing can embed. The panel offers the install.+ */+export type EmbedLane = 'bundled' | 'ollama-local' | 'ollama-remote' | 'none'++export interface EmbedLaneInfo {+ lane: EmbedLane+ /** The host the text would travel to, set only for `ollama-remote`. */+ endpoint: string | null+}++/** True when the lane can index. The three working lanes all can. */+export function laneCanEmbed(lane: EmbedLane): boolean {+ return lane !== 'none'+}++/** True when the text never leaves this machine. */+export function laneIsOnThisMachine(lane: EmbedLane): boolean {+ return lane === 'bundled' || lane === 'ollama-local'+}/*** True when the bundled lane can serve indexing without Ollama: its server is@@ -40,23 +75,35 @@ export async function builtinEmbedReady(): Promise<boolean> {}/**- * True when SOME embedding backend on this machine can index a document.+ * Which lane would index a document right now, and where it points.*- * False when missing, and callers then surface the in-app install prompt (RAG panel) or- * a tooltip (Docs button) rather than blocking.+ * `none` when missing, and callers then surface the in-app install prompt (RAG+ * panel) or the needs-setup state on the Docs button, rather than blocking.*/-export async function embeddingBackendReady(embeddingModel: string): Promise<boolean> {- if (await builtinEmbedReady()) return true+export async function embeddingLane(embeddingModel: string): Promise<EmbedLaneInfo> {+ if (await builtinEmbedReady()) return { lane: 'bundled', endpoint: null }// The bundled lane is the only one rag.ts will use here, so a pulled Ollama// model is not an answer to this question.- if (isManagedBuiltinActive()) return false- if (!(await checkConnection())) return false+ if (isManagedBuiltinActive()) return { lane: 'none', endpoint: null }+ if (!(await checkConnection())) return { lane: 'none', endpoint: null }try {const models = await listModels()- return models.some(+ const has = models.some((m) => m.name === embeddingModel || m.name === embeddingModel + ':latest',)+ if (!has) return { lane: 'none', endpoint: null }+ return isOllamaLocal()+ ? { lane: 'ollama-local', endpoint: null }+ : { lane: 'ollama-remote', endpoint: getOllamaBase() }} catch {- return false+ return { lane: 'none', endpoint: null }}}++/**+ * True when SOME embedding backend on this machine can index a document.+ * Kept as the narrow question the upload pre-flight asks.+ */+export async function embeddingBackendReady(embeddingModel: string): Promise<boolean> {+ return laneCanEmbed((await embeddingLane(embeddingModel)).lane)+}diff --git a/src/components/chat/ChatView.tsx b/src/components/chat/ChatView.tsxindex 923384b7..b2bb64a8 100644--- a/src/components/chat/ChatView.tsx+++ b/src/components/chat/ChatView.tsx@@ -9,6 +9,7 @@ import { MessageList } from './MessageList'import { ChatInput } from './ChatInput'import { RAGPanel } from './RAGPanel'import { DocsButton } from './DocsButton'+import { RetrievalErrorBar } from './RetrievalErrorBar'import { useDocsAvailability } from '../../hooks/useDocsAvailability'import { AgentModeToggle } from './AgentModeToggle'import { AgentWorkspaceBadge } from './AgentWorkspaceBadge'@@ -385,7 +386,7 @@ export function ChatView() {// Commands need the tool catalog to drive, which only Agent// mode has here. Plain chat leaves "/cmd" as ordinary text.slashCommands={isAgentActive}- onAttachDocs={docs.enabled ? () => setRagPanelOpen(true) : undefined}+ onAttachDocs={() => setRagPanelOpen(true)}composerModel={/* What this chat's answers were written by rides on thepicker itself now, as a dot plus a tooltip, instead of a@@ -396,7 +397,7 @@ export function ChatView() {// No plan lives here. The prompt window is the prompt window// (David, 2026-08-22): the plan band sits under the header row// above, next to the other standing status controls.- composerAbove={<><LoopBar onStop={stopGeneration} /><GoalBar /><GroupCostHint /></>}+ composerAbove={<><RetrievalErrorBar /><LoopBar onStop={stopGeneration} /><GoalBar /><GroupCostHint /></>}composerActions={<>{/* Documents (RAG), shown in both modes since A9. Indiff --git a/src/components/chat/DocsButton.tsx b/src/components/chat/DocsButton.tsxindex acbea151..bc92054a 100644--- a/src/components/chat/DocsButton.tsx+++ b/src/components/chat/DocsButton.tsx@@ -20,23 +20,24 @@ interface Props {export function DocsButton({ availability, open, ragEnabled, docCount, onToggle }: Props) {if (!availability.visible) return null- const active = availability.enabled && (open || ragEnabled)+ const active = open || ragEnabledreturn (<buttondata-testid="docs-toggle"- onClick={availability.enabled ? onToggle : undefined}+ data-needs-setup={availability.needsSetup ? 'true' : 'false'}+ onClick={onToggle}disabled={!availability.enabled}title={availability.title}className={'flex items-center gap-1 px-2 py-1.5 rounded-md transition-all shrink-0 text-[0.6rem] font-medium ' +(active? 'bg-green-500/15 text-green-400 border border-green-500/30'- : availability.enabled- ? 'text-gray-500 hover:text-gray-300 hover:bg-white/5'- : // Present, readable, and plainly not pressable. Hiding it was the- // bug; a button that looks alive and does nothing would be the- // next one.- 'text-gray-600 opacity-50 cursor-not-allowed')+ : availability.needsSetup+ ? // Damped, not dead. The panel behind this button is the only+ // place that can install the embedding engine, so disabling it+ // would lock the door to the repair shop (review B1).+ 'text-gray-600 hover:text-gray-400 hover:bg-white/5 opacity-60'+ : 'text-gray-500 hover:text-gray-300 hover:bg-white/5')}><FileText size={11} />diff --git a/src/components/chat/RAGPanel.tsx b/src/components/chat/RAGPanel.tsxindex 3f4b8dce..abfb93f9 100644--- a/src/components/chat/RAGPanel.tsx+++ b/src/components/chat/RAGPanel.tsx@@ -21,6 +21,8 @@ import { useShallow } from 'zustand/react/shallow'import { useRAG } from '../../hooks/useRAG'import { useRAGStore } from '../../stores/ragStore'import { useSettingsStore } from '../../stores/settingsStore'+import { useEmbedLane } from '../../hooks/useEmbedLane'+import { laneIsOnThisMachine } from '../../api/embed-availability'import { formatBytes } from '../../lib/formatters'interface Props {@@ -89,6 +91,9 @@ export function RAGPanel({ conversationId, onClose }: Props) {function RAGPanelInner({ conversationId, onClose }: { conversationId: string; onClose?: () => void }) {const cloudMode = useSettingsStore((s) => s.settings.appMode) === 'cloud'+ // Same one measurement the composer's Docs button reads (hooks/useEmbedLane),+ // so the button's tooltip and this paragraph can never say different things.+ const lane = useEmbedLane(cloudMode)const rag = useRAG(conversationId)const documents = rag.documents ?? []const isEnabled = rag.isEnabled ?? false@@ -132,13 +137,14 @@ function RAGPanelInner({ conversationId, onClose }: { conversationId: string; on// eslint-disable-next-line react-hooks/exhaustive-deps}, [ensureEmbeddingModel])- const { embeddingModelReactive, lastRetrievedChunksReactive, embeddingPullProgress, embeddingInstallPrompt, embeddingQueuedCount } = useRAGStore(+ const { embeddingModelReactive, lastRetrievedChunksReactive, embeddingPullProgress, embeddingInstallPrompt, embeddingQueuedCount, retrievalError } = useRAGStore(useShallow((s) => ({embeddingModelReactive: s.embeddingModel,lastRetrievedChunksReactive: s.lastRetrievedChunks,embeddingPullProgress: s.embeddingPullProgress,embeddingInstallPrompt: s.embeddingInstallPrompt,embeddingQueuedCount: s.embeddingQueuedFiles.length,+ retrievalError: s.retrievalError,})))@@ -270,18 +276,45 @@ function RAGPanelInner({ conversationId, onClose }: { conversationId: string; on)}</div>- {/* Where the files stay, said in Cloud mode because in Cloud mode it is a- fair question (A9). Indexing runs on this machine on 127.0.0.1:8128;- only the passages that match the question travel with the prompt. */}- {cloudMode && (+ {/* Where the text actually goes, said in Cloud mode because in Cloud mode+ it is a fair question (A9). The sentence follows the measured lane:+ promising "stays on this computer" while indexing ships every chunk to+ a LAN Ollama would be a comfortable lie (review B2). */}+ {cloudMode && lane && lane.lane !== 'none' && (<div className="px-3 pt-2">- <p- data-testid="rag-cloud-privacy"- className="text-[0.6rem] leading-snug text-gray-500 dark:text-gray-400"- >- Your documents are indexed on this computer and stay here. Only the passages- that match your question are sent to the cloud model as context.- </p>+ {laneIsOnThisMachine(lane.lane) ? (+ <p+ data-testid="rag-cloud-privacy"+ className="text-[0.6rem] leading-snug text-gray-500 dark:text-gray-400"+ >+ Your documents are indexed on this computer and stay here. Only the passages+ that match your question are sent to the cloud model as context.+ </p>+ ) : (+ <p+ data-testid="rag-cloud-privacy-remote"+ className="flex items-start gap-1.5 text-[0.6rem] leading-snug text-amber-600 dark:text-amber-400"+ >+ <AlertTriangle size={11} className="shrink-0 mt-0.5" />+ <span>+ Indexing runs on {lane.endpoint ?? 'your configured Ollama host'}, so the full+ text of every document you add is sent there. The passages that match your+ question are then sent to the cloud model as context.+ </span>+ </p>+ )}+ </div>+ )}++ {/* The last turn went out without the documents (review S4). */}+ {retrievalError && (+ <div className="px-3 pt-2">+ <div className="flex items-start gap-1.5 p-2 rounded-lg bg-amber-500/10 border border-amber-500/20">+ <AlertTriangle size={12} className="text-amber-500 shrink-0 mt-0.5" />+ <span data-testid="rag-retrieval-error" className="text-[0.6rem] text-amber-600 dark:text-amber-400 leading-tight">+ {retrievalError}+ </span>+ </div></div>)}diff --git a/src/components/chat/__tests__/docs-in-cloud-chat.test.ts b/src/components/chat/__tests__/docs-in-cloud-chat.test.tsindex 2975644c..f817d421 100644--- a/src/components/chat/__tests__/docs-in-cloud-chat.test.ts+++ b/src/components/chat/__tests__/docs-in-cloud-chat.test.ts@@ -11,14 +11,14 @@* system prompt, which every provider takes.** So the rule is not about the mode any more, it is about the embedding lane.- * Three states, each rendered for real, plus the negative controls that keep- * the fix from turning into "always enabled, never honest":+ * Every state is rendered for real here, including the two the review of+ * 2026-09-02 turned up:*- * local -> visible, pressable, unchanged- * cloud + embeddings present -> visible, pressable, tooltip says where the- * files stay- * cloud + no embeddings -> visible, NOT pressable, tooltip names the- * missing part instead of hiding the feature+ * B1 no lane at all must NOT disable the button. The panel behind it holds+ * the install card, and that card is the only way to get a lane, so a+ * disabled button is a locked door to the repair shop.+ * B2 the tooltip may not promise "stays on this computer" when indexing+ * would ship whole documents to a LAN Ollama.** Run: npx vitest run src/components/chat/__tests__/docs-in-cloud-chat.test.ts*/@@ -29,16 +29,22 @@ import { DocsButton } from '../DocsButton'import {docsAvailability,DOCS_TITLE_PLAIN,- DOCS_TITLE_CLOUD,+ DOCS_TITLE_CLOUD_LOCAL,DOCS_TITLE_NO_EMBEDDINGS,} from '../../../lib/docs-availability'+import type { EmbedLaneInfo } from '../../../api/embed-availability'++const BUNDLED: EmbedLaneInfo = { lane: 'bundled', endpoint: null }+const OLLAMA_LOCAL: EmbedLaneInfo = { lane: 'ollama-local', endpoint: null }+const OLLAMA_REMOTE: EmbedLaneInfo = { lane: 'ollama-remote', endpoint: 'http://192.168.0.54:11434' }+const NONE: EmbedLaneInfo = { lane: 'none', endpoint: null }afterEach(() => cleanup())-function show(appMode: 'local' | 'cloud', embedReady: boolean | null, onToggle = () => {}) {+function show(appMode: 'local' | 'cloud', info: EmbedLaneInfo | null, onToggle = () => {}) {return render(createElement(DocsButton, {- availability: docsAvailability(appMode, embedReady),+ availability: docsAvailability(appMode, info),open: false,ragEnabled: false,docCount: 0,@@ -50,102 +56,128 @@ function show(appMode: 'local' | 'cloud', embedReady: boolean | null, onToggle =const docs = () => screen.queryByTestId('docs-toggle') as HTMLButtonElement | nulldescribe('the rule that decides the Docs button', () => {- it('local mode is untouched: there, pressable, plain tooltip', () => {+ it('local mode is untouched: there, pressable, plain tooltip, no lane read', () => {expect(docsAvailability('local', null)).toEqual({visible: true,enabled: true,+ needsSetup: false,+ lane: null,title: DOCS_TITLE_PLAIN,})})- it('local mode does not care what the embedding probe says, in either direction', () => {+ it('local mode does not care what the lane probe says, in any direction', () => {// Negative control for the probe: local mode never measured it before the// fix and must not start depending on it now.- expect(docsAvailability('local', false).enabled).toBe(true)- expect(docsAvailability('local', true).enabled).toBe(true)+ for (const info of [BUNDLED, OLLAMA_REMOTE, NONE]) {+ expect(docsAvailability('local', info).needsSetup).toBe(false)+ expect(docsAvailability('local', info).title).toBe(DOCS_TITLE_PLAIN)+ }})- it('cloud with an embedding lane: there and pressable, which is the whole bug report', () => {- const a = docsAvailability('cloud', true)- expect(a.visible).toBe(true)- expect(a.enabled).toBe(true)- expect(a.title).toBe(DOCS_TITLE_CLOUD)+ it('cloud on the bundled lane: there, pressable, and the tooltip says files stay put', () => {+ const a = docsAvailability('cloud', BUNDLED)+ expect(a).toMatchObject({ visible: true, enabled: true, needsSetup: false, lane: 'bundled' })+ expect(a.title).toBe(DOCS_TITLE_CLOUD_LOCAL)})- it('cloud without one: still there, but off, and it says why', () => {- expect(docsAvailability('cloud', false)).toEqual({+ it('cloud on a loopback Ollama says the same thing, because it is equally true', () => {+ expect(docsAvailability('cloud', OLLAMA_LOCAL).title).toBe(DOCS_TITLE_CLOUD_LOCAL)+ })++ it('cloud on a REMOTE Ollama names the host instead of promising the opposite (B2)', () => {+ const a = docsAvailability('cloud', OLLAMA_REMOTE)+ expect(a.title).toContain('http://192.168.0.54:11434')+ expect(a.title).toContain('whole documents are sent there')+ // Negative control on the wording: the comfortable lie must be absent.+ expect(a.title).not.toContain('stay on this computer')+ expect(a.title).not.toContain('Files stay on this computer')+ })++ it('cloud with no lane: needs setup, and STILL pressable (B1)', () => {+ const a = docsAvailability('cloud', NONE)+ expect(a).toEqual({visible: true,- enabled: false,+ enabled: true,+ needsSetup: true,+ lane: 'none',title: DOCS_TITLE_NO_EMBEDDINGS,})+ expect(a.title).toContain('Documents need the local embeddings engine')+ expect(a.title).toContain('Click to install it.')})- it('cloud while the probe is still running keeps it pressable, not dead-then-alive', () => {- // A button that starts disabled and wakes up a moment later reads as- // broken. Unknown is not "no".- expect(docsAvailability('cloud', null).enabled).toBe(true)+ it('cloud while the probe is still running is plain and pressable, not a flicker', () => {+ expect(docsAvailability('cloud', null)).toMatchObject({+ needsSetup: false,+ enabled: true,+ title: DOCS_TITLE_PLAIN,+ })})- it('never hides the button again, in any state', () => {+ it('never hides the button and never disables it, in any state', () => {for (const mode of ['local', 'cloud'] as const) {- for (const ready of [true, false, null]) {- expect(docsAvailability(mode, ready).visible).toBe(true)+ for (const info of [BUNDLED, OLLAMA_LOCAL, OLLAMA_REMOTE, NONE, null]) {+ const a = docsAvailability(mode, info)+ expect(a.visible).toBe(true)+ expect(a.enabled).toBe(true)}}})})describe('the button as it actually renders', () => {- it('cloud with embeddings: present, enabled, and clicking opens the panel', () => {+ it('cloud with a lane: present, enabled, clicking opens the panel', () => {const onToggle = vi.fn()- show('cloud', true, onToggle)- const b = docs()- expect(b).not.toBeNull()- expect(b!.disabled).toBe(false)- expect(b!.getAttribute('title')).toBe(DOCS_TITLE_CLOUD)- expect(b!.getAttribute('title')).toContain('stay here')- fireEvent.click(b!)+ show('cloud', BUNDLED, onToggle)+ const b = docs()!+ expect(b.disabled).toBe(false)+ expect(b.getAttribute('data-needs-setup')).toBe('false')+ expect(b.getAttribute('title')).toBe(DOCS_TITLE_CLOUD_LOCAL)+ fireEvent.click(b)expect(onToggle).toHaveBeenCalledTimes(1)})- it('cloud without embeddings: present, disabled, tooltip names the engine, click does nothing', () => {+ it('cloud without a lane: damped, but the click still reaches the install card (B1)', () => {const onToggle = vi.fn()- show('cloud', false, onToggle)- const b = docs()- expect(b).not.toBeNull()- expect(b!.disabled).toBe(true)- expect(b!.getAttribute('title')).toBe('Documents need the local embeddings engine')- fireEvent.click(b!)- expect(onToggle).not.toHaveBeenCalled()+ show('cloud', NONE, onToggle)+ const b = docs()!+ expect(b.disabled).toBe(false)+ expect(b.getAttribute('data-needs-setup')).toBe('true')+ expect(b.getAttribute('title')).toContain('Documents need the local embeddings engine')+ expect(b.className).toContain('opacity-60')+ fireEvent.click(b)+ // This is the whole point of B1: the dead end is gone.+ expect(onToggle).toHaveBeenCalledTimes(1)+ })++ it('a working lane is not damped, so the damping means something', () => {+ // Negative control on the styling.+ show('cloud', BUNDLED)+ expect(docs()!.className).not.toContain('opacity-60')})it('local: present and enabled, exactly as before the fix', () => {const onToggle = vi.fn()show('local', null, onToggle)- const b = docs()- expect(b).not.toBeNull()- expect(b!.disabled).toBe(false)- expect(b!.textContent).toContain('Docs')- fireEvent.click(b!)+ const b = docs()!+ expect(b.disabled).toBe(false)+ expect(b.textContent).toContain('Docs')+ expect(b.getAttribute('data-needs-setup')).toBe('false')+ fireEvent.click(b)expect(onToggle).toHaveBeenCalledTimes(1)})- it('the document count still rides along, and a disabled button never looks active', () => {- cleanup()+ it('the document count still rides along', () => {render(createElement(DocsButton, {- availability: docsAvailability('cloud', false),- open: true,- ragEnabled: true,+ availability: docsAvailability('cloud', NONE),+ open: false,+ ragEnabled: false,docCount: 3,onToggle: () => {},}),)- const b = docs()!- expect(b.textContent).toContain('3')- // Negative control on the styling: open + ragEnabled would normally paint- // the button green. A button that cannot be pressed must not claim to be on.- expect(b.className).not.toContain('bg-green-500/15')- expect(b.className).toContain('cursor-not-allowed')+ expect(docs()!.textContent).toContain('3')})})diff --git a/src/hooks/__tests__/the-install-card-has-a-working-path.test.ts b/src/hooks/__tests__/the-install-card-has-a-working-path.test.tsnew file mode 100644index 00000000..02687ea0--- /dev/null+++ b/src/hooks/__tests__/the-install-card-has-a-working-path.test.ts@@ -0,0 +1,87 @@+/**+ * @vitest-environment jsdom+ *+ * Review B1, second half: the Docs button now always opens the RAG panel, and+ * the panel's install card is the only thing in the app that can give a user an+ * embedding lane from inside a chat. That card therefore has to work on every+ * box it can be reached from.+ *+ * It did not. `pullEmbeddingModel` sent everyone who is not on the managed+ * built-in engine to `ollama pull`. On a box with LM Studio, a plain+ * openai-compat backend, or nothing but LU Cloud, there is no Ollama to pull+ * from, so the card spun and changed nothing. The bundled GGUF is the lane+ * api/rag.ts would take there anyway, so that is where the install goes.+ *+ * Run: npx vitest run src/hooks/__tests__/the-install-card-has-a-working-path.test.ts+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'+import { renderHook, act } from '@testing-library/react'++let managed = false+let ollamaUp = true+const installBundled = vi.fn(async () => {})+const pullTauri = vi.fn(() => ({ promise: Promise.resolve(), cancel: () => {} }))++vi.mock('../../api/engine', () => ({+ isManagedBuiltinActive: () => managed,+}))+vi.mock('../../api/embed-availability', () => ({+ builtinEmbedReady: async () => false,+ embeddingBackendReady: async () => false,+}))+vi.mock('../../api/embed-install', () => ({+ installBundledEmbedModel: (...a: any[]) => installBundled(...(a as [])),+}))+vi.mock('../../api/ollama', () => ({+ checkConnection: async () => ollamaUp,+ getModelContext: async () => 8192,+ pullModelTauri: (...a: any[]) => pullTauri(...(a as [])),+}))+vi.mock('../../api/rag', () => ({+ indexDocument: async () => ({ chunks: [] }),+ retrieveContext: async () => ({ context: { chunks: [] }, scoredChunks: [] }),+}))++import { useRAG } from '../useRAG'++beforeEach(() => {+ managed = false+ ollamaUp = true+ installBundled.mockClear()+ pullTauri.mockClear()+})++async function install() {+ const { result } = renderHook(() => useRAG('conv-1'))+ let ok = false+ await act(async () => {+ ok = await result.current.pullEmbeddingModel()+ })+ return ok+}++describe('the install card reaches a real shop from wherever it was opened', () => {+ it('built-in engine: the bundled GGUF, as before', async () => {+ managed = true+ expect(await install()).toBe(true)+ expect(installBundled).toHaveBeenCalledTimes(1)+ expect(pullTauri).not.toHaveBeenCalled()+ })++ it('no Ollama reachable: the bundled GGUF instead of a pull that cannot start (B1)', async () => {+ managed = false+ ollamaUp = false+ expect(await install()).toBe(true)+ expect(installBundled).toHaveBeenCalledTimes(1)+ expect(pullTauri).not.toHaveBeenCalled()+ })++ it('Ollama running: still `ollama pull`, because that is the lane rag.ts would use', async () => {+ // Negative control: the new fallback must not hijack the case that worked.+ managed = false+ ollamaUp = true+ expect(await install()).toBe(true)+ expect(pullTauri).toHaveBeenCalledTimes(1)+ expect(installBundled).not.toHaveBeenCalled()+ })+})diff --git a/src/hooks/useRAG.ts b/src/hooks/useRAG.tsindex e93481ae..c9b02514 100644--- a/src/hooks/useRAG.ts+++ b/src/hooks/useRAG.ts@@ -122,7 +122,15 @@ export function useRAG(conversationId: string | null) {// The install has to feed the same lane the embedder reads from. On a// built-in-engine box `ollama pull` fills a shop rag.ts never visits, so// the card would spin, report success and change nothing.- if (isManagedBuiltinActive()) {+ //+ // The same is true one step further out (review B1): with no Ollama running+ // at all, `ollama pull` cannot even start, and the user who onboarded LM+ // Studio or a plain openai-compat backend and skipped the embeddings step+ // had no working install path from this card. Ask whether Ollama is+ // actually reachable, and fall to the bundled GGUF when it is not, which is+ // the lane rag.ts would take anyway.+ const ollamaReachable = isManagedBuiltinActive() ? false : await checkConnection()+ if (isManagedBuiltinActive() || !ollamaReachable) {try {await installBundledEmbedModel((completed, total) =>setEmbeddingPullProgress({ completed, total, status: "downloading" }),diff --git a/src/lib/docs-availability.ts b/src/lib/docs-availability.tsindex ee353cb8..5fac89c1 100644--- a/src/lib/docs-availability.ts+++ b/src/lib/docs-availability.ts@@ -1,5 +1,5 @@/**- * Who gets the Docs button, and when it can be pressed.+ * Who gets the Docs button, how it looks, and what its tooltip may honestly say.** A9 (aldrich_ironhart, Discord #general 2026-09-01): "There's no document tab* in cloud chat to add documents and audio clips". He was right, and the@@ -11,55 +11,81 @@* system prompt is the one thing every provider takes. So nothing about Cloud* mode stops Document Chat; the button was hidden on the wrong question.*- * The rule below asks the right one. Local mode is untouched. Cloud mode shows- * the button and lets the missing part, if any, say so in a tooltip instead of- * hiding the feature and leaving the user to guess.+ * Two things the first cut got wrong, both from the review of 2026-09-02:+ *+ * B1. A missing embedding lane disabled the button, and the RAG panel is the+ * only place that can INSTALL an embedding lane (its install card drives+ * useRAG.installEmbeddingAndDrainQueue). Disabling the only door to the+ * repair shop left anyone who onboarded the built-in engine without the+ * embeddings step in a cloud-mode dead end, while local mode let them in.+ * So the button stays pressable and carries a third state instead:+ * `needsSetup`, damped, and a click opens the panel with the install card.+ *+ * B2. "Your documents stay on this computer" is not true on every lane.+ * Ollama's base URL is user-configurable, and indexing sends EVERY chunk of+ * a document to it, not just the passages a question matches. On a LAN or+ * remote Ollama the sentence has to name the host instead of promising the+ * opposite of what happens.*/import type { AppMode } from '../types/settings'+import type { EmbedLane, EmbedLaneInfo } from '../api/embed-availability'export interface DocsAvailability {/** Render the button at all. Always true now, which is the fix. */visible: boolean- /** Clickable. False only in Cloud mode with no embedding backend on the box. */+ /** Pressable. Also always true: the panel behind it is the repair shop (B1). */enabled: boolean- /** The button's tooltip. Carries the reason when disabled, and the privacy- * statement when Cloud mode is about to send passages upstream. */+ /** No embedding lane yet. Damped look, and the click goes to the install card. */+ needsSetup: boolean+ /** The measured lane, or null in local mode and while the probe is running. */+ lane: EmbedLane | null+ /** The button's tooltip. */title: string}/** Local mode, and Cloud mode before the probe answers. */export const DOCS_TITLE_PLAIN = 'Document Chat (RAG)'-/**- * Cloud mode with a working embedding lane. It says where the files stay,- * because in Cloud mode that is a fair question and the answer is good news:- * indexing runs on this machine, and only the passages that match the question- * travel with the prompt.- */-export const DOCS_TITLE_CLOUD =- 'Document Chat (RAG). Your files are indexed on this computer and stay here. ' +- 'Only the passages that match your question are sent to the cloud model as context.'+/** Cloud mode, indexing on this machine. Short on purpose (review N2); the+ * panel carries the full statement once it is open. */+export const DOCS_TITLE_CLOUD_LOCAL =+ 'Document Chat (RAG). Files stay on this computer, only matching passages go to the cloud model.'++/** Cloud mode, indexing on a remote Ollama. Names the host, because that is+ * where whole documents would go (B2). */+export function docsTitleRemote(endpoint: string | null): string {+ return `Document Chat (RAG). Indexing runs on ${endpoint ?? 'your configured Ollama host'}, so whole documents are sent there. Matching passages then go to the cloud model.`+}-/** Cloud mode with no embedding backend. The exact wording David asked for. */-export const DOCS_TITLE_NO_EMBEDDINGS = 'Documents need the local embeddings engine'+/** No embedding lane. The wording David asked for, plus the way out. */+export const DOCS_TITLE_NO_EMBEDDINGS =+ 'Documents need the local embeddings engine. Click to install it.'/*** @param appMode the global Local/Cloud switch- * @param embedReady result of the embedding-lane probe, or `null` while it is- * still running. Unknown counts as available on purpose: a button that starts- * dead and comes alive a moment later reads as broken, and the RAG panel- * carries its own install card for the case the probe then says no.+ * @param info the measured embedding lane, or `null` while the probe is still+ * running (and always in local mode, which does not measure). Unknown counts+ * as fine on purpose: a button that starts damped and settles a moment later+ * reads as flicker, and nothing is lost because the panel behind it is the+ * same panel either way.*/-export function docsAvailability(appMode: AppMode, embedReady: boolean | null): DocsAvailability {+export function docsAvailability(+ appMode: AppMode,+ info: EmbedLaneInfo | null,+): DocsAvailability {if (appMode !== 'cloud') {- return { visible: true, enabled: true, title: DOCS_TITLE_PLAIN }+ return { visible: true, enabled: true, needsSetup: false, lane: null, title: DOCS_TITLE_PLAIN }}- if (embedReady === false) {- return { visible: true, enabled: false, title: DOCS_TITLE_NO_EMBEDDINGS }+ if (info === null) {+ return { visible: true, enabled: true, needsSetup: false, lane: null, title: DOCS_TITLE_PLAIN }}- return {- visible: true,- enabled: true,- title: embedReady === true ? DOCS_TITLE_CLOUD : DOCS_TITLE_PLAIN,+ const base = { visible: true as const, enabled: true as const, lane: info.lane }+ switch (info.lane) {+ case 'none':+ return { ...base, needsSetup: true, title: DOCS_TITLE_NO_EMBEDDINGS }+ case 'ollama-remote':+ return { ...base, needsSetup: false, title: docsTitleRemote(info.endpoint) }+ default:+ return { ...base, needsSetup: false, title: DOCS_TITLE_CLOUD_LOCAL }}}