Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: Stacker News analysis and voice fallback use the configured Ollama daemon (#12407)
[._.]/ Adam Eivy034418af0630
diff --git a/server/lib/README.md b/server/lib/README.mdindex 7efc0b1c1f..fc59201d90 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -603,7 +603,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `localLlmDisk.js` | Pure on-disk reasoning for the migrate "copy GGUF locally instead of re-downloading" fast-path (Ollama manifest/blob parsing, LM Studio path layout, MLX/projector/shard detection) plus the Hugging Face registry addressing used to finish an abandoned Ollama pull. || `specDecodePresets.js` | Curated llama-server launch presets (target + optional drafter GGUF paths, `--spec-type`, and the Hugging Face repo/quant each file comes from) plus `findSpecDecodePreset` / `specDecodeSource` / `hfSearchUrl`. A preset whose spec type drafts with nothing (`none`, any `ngram-*`) carries an empty `draftModel` and is just a launch line for one checkpoint — which is what makes this the home for a model only llama-server can load, e.g. `ternary-bonsai-2-27b`, whose ternary packs stock llama.cpp (and therefore Ollama and LM Studio) cannot run. Also owns the `--spec-type` vocabulary: `SPEC_TYPE_SUGGESTIONS` (published to the launcher card), `parseSpecTypes` (the flag is a comma-separated list) and `isDraftSpecType` (the `draft-` prefix is what needs a drafter GGUF — every `ngram-*` type runs without one). Server-owned so the launcher card can offer a Download button per file. Pure. || `llamaCppInstall.js` | Where a llama.cpp install comes from on this host, for `services/llamaServerManager.js`. `llamaCppInstallPlan(platform)` → the frozen descriptor for that platform's package manager — Homebrew on macOS/Linux (`brew install llama.cpp`), winget on Windows (`winget install ggml.llamacpp`) — carrying `manager`, `managerLabel`, `packageId`, `installCommand`, the install/upgrade (and, for winget, list/upgrade-check) argv, and the three refusal strings a caller would otherwise hardcode: `missingManagerError`, `notInstalledError`, `pathRepairHint`. The LLMs page renders `installCommand` out of the llama-server status payload, which is what stopped a Windows install prompt from telling the user to run Homebrew. Also the winget-side readers Homebrew needs no equivalent for: `parseWingetPackageFields(stdout, id)` (winget has NO machine-readable output mode and LOCALIZED table headers, so fields are read positionally from the tokens after the id token — `Version [Available] [Source]`; `null` = not installed), `wingetLinkDirs(env)` (the portable-shim directories winget adds to the USER PATH, which an already-running server has not inherited) and `isWingetManagedPath` (counterpart of the manager's `isHomebrewLlamaServer`: a source build earlier on PATH must not be offered a `winget upgrade`). Every WinGet path is reasoned about with `path.win32` regardless of host, so both branches are coverable from a macOS/Linux checkout. Pure. |-| `ollamaContext.js` | Ollama runtime context-window reasoning. `resolveOllamaContextLength(provider, env)` → the window PortOS should hold the daemon at (`provider.numCtx`, then `OLLAMA_CONTEXT_LENGTH`, then `null` = leave Ollama's VRAM-based auto-pick alone); `withOllamaContextEnv(env, n)` builds the `ollama serve` child env; `parseOllamaContextOverflow(text)` recognizes the `exceed_context_size_error` rejection and pulls `{ promptTokens, contextLength }` out of either the JSON body or the human message; `describeOllamaContextOverflow` / `describeOllamaContextTooSmall` render the actionable one-liners; `isSameOllamaDaemon(providerBase, managedBase)` compares host+port so a provider pointed at a *remote* Ollama never triggers a local-daemon reload, with `managedOllamaBaseUrl(env)` supplying the managed side (`OLLAMA_URL` → `OLLAMA_HOST` → the stock local daemon); `managedOllamaContextLength(provider, env)` is `resolveOllamaContextLength` gated on that comparison, and `withOllamaRuntimeContextWindow(provider, env)` stamps it onto an in-memory provider projection as `runtimeContextWindow` — how the env rung reaches the vendored toolkit’s `clampToRuntimeContextWindow`, which may not import out here (#7472); `OLLAMA_AGENT_MIN_CONTEXT` is the window below which an agent harness is warned. Pure — the daemon side lives in `services/ollamaManager.js` (`ensureContextWindow`), the pre-spawn enforcement in `services/ollamaAgentContext.js`. |+| `ollamaContext.js` | Ollama runtime context-window reasoning. `resolveOllamaContextLength(provider, env)` → the window PortOS should hold the daemon at (`provider.numCtx`, then `OLLAMA_CONTEXT_LENGTH`, then `null` = leave Ollama's VRAM-based auto-pick alone); `withOllamaContextEnv(env, n)` builds the `ollama serve` child env; `parseOllamaContextOverflow(text)` recognizes the `exceed_context_size_error` rejection and pulls `{ promptTokens, contextLength }` out of either the JSON body or the human message; `describeOllamaContextOverflow` / `describeOllamaContextTooSmall` render the actionable one-liners; `normalizeOllamaBaseUrl(raw)` (scheme, no trailing slash, no `/v1`), `isSameOllamaDaemon(providerBase, managedBase)` compares host+port so a provider pointed at a *remote* Ollama never triggers a local-daemon reload, with `managedOllamaBaseUrl(env)` supplying the managed side (`OLLAMA_URL` → `OLLAMA_HOST` → the stock local daemon); `managedOllamaContextLength(provider, env)` is `resolveOllamaContextLength` gated on that comparison, and `withOllamaRuntimeContextWindow(provider, env)` stamps it onto an in-memory provider projection as `runtimeContextWindow` — how the env rung reaches the vendored toolkit’s `clampToRuntimeContextWindow`, which may not import out here (#7472); `OLLAMA_AGENT_MIN_CONTEXT` is the window below which an agent harness is warned. Pure — the daemon side lives in `services/ollamaManager.js` (`ensureContextWindow`), the pre-spawn enforcement in `services/ollamaAgentContext.js`. || `localModelHeuristics.js` | Capability heuristics for untyped local (Ollama/LM Studio) models. `isEmbeddingModel`/`isGenerationModel` (so a generation/fallback run never picks an embedding model like `nomic-embed-text`); `isVisionModel(model)` (string id or model card — prefers explicit `type:'vlm'`/`capabilities:['vision']` metadata, falls back to id regex; used by the LoRA captioner); `recommendEditorialModel(models, { measured })` ranks installed models for editorial review/editing, dropping any a fresh measurement proved cannot run here. Pure — `client/src/utils/localModelHeuristics.js` re-exports `isEmbeddingModel`/`isVisionModel`/`isToolUseModel` from here. || `localModelAssessment.js` | Scoring for MEASURED local-model assessments (recorded by `services/localModelAssessments.js`): `classifyFitVerdict` (`fits`/`does-not-fit`/`incompatible`/`unknown`), `summarizePerformance` (mean/peak chars-per-second AND tokens-per-second, prefill rate, TTFT, max working context, cross-context degradation), `scoreAssessment` + `scoreForIntent` + `rankByIntent` for the balanced/smartest/fastest/lightweight pickers, `explainAssessment`, `compareEnvironments`/`describeStaleness` (is a stored reading still valid for THIS machine?), `buildThroughputReport` (every measurement as one tokens/s table, fastest first, per-context readings intact), `selectSweepTargets`/`summarizeSweepScopes`/`SWEEP_SCOPES` (which measurements a "measure everything" run covers, and how many), and `measuredFitVerdict`/`reconcileFit` (fold a measurement into the catalog's size-estimate fit badge, keeping the disagreement). Pure. `null` strictly means NOT MEASURED — never 0, never "failed". || `localModelTuning.js` | Launch/runtime tuning knobs for the measurable local runtimes — ONLY knobs PortOS can actually apply. A knob is defined by its transport, and `applies` + the user-facing `note` are DERIVED from it: `config` (llama.cpp's `-b`/`-ub`/`-t`/`--parallel`/`--flash-attn`/`--cache-type-k\|v`/`--spec-draft-n-max`, via `launchConfig`), `env` (Ollama's `OLLAMA_CONTEXT_LENGTH`/`_FLASH_ATTENTION`/`_KV_CACHE_TYPE`/`_NUM_PARALLEL`, via `launchEnv`), `cli` (a flag on the launch line of a daemon PortOS re-runs — LM Studio's `lms load --context-length`/`--gpu`/`--parallel`, and MTPLX's `mtplx serve --context-window`/`--depth`/`--generation-mode`/`--kv-quant`/`--batching-preset`/`--profile` — via `launchArgs`), or `wire` (a request-body field, via `requestBody` — currently no members). vLLM declares none: PortOS does not start it, so there is no launch line to put a flag on. Read the MTPLX verification note in the module before adding an `mtplx serve` flag — it exits before it binds on one it does not recognize. Also `normalizeTuning` (coerce + clamp + drop unknown keys), `tuningSignature` (stable identity — `''` for backend defaults, so pre-tuning store keys keep resolving), `describeTuning`, `launchTuning`, and `compareTunings` (which tuning won per model using exact tokens/s when all variants have tokenizer counts and chars/s otherwise, labelled from each record's persisted `tuningLabel`, with a `deltaPercent` against the winner), and `tuningGridFor` (the candidate grid a tuning sweep runs — backend defaults plus one variant per knob declaring a `sweep` value, capped by `maxVariants`; `sweepWith` carries a knob's documented prerequisite). Pure. |diff --git a/server/lib/ollamaContext.js b/server/lib/ollamaContext.jsindex b7d2ee0f5f..f9ae6d3db4 100644--- a/server/lib/ollamaContext.js+++ b/server/lib/ollamaContext.js@@ -81,6 +81,19 @@ export function managedOllamaBaseUrl(env = process.env) {return raw || 'http://localhost:11434'}+/**+ * Normalize an Ollama base URL to a scheme, no trailing slash and no `/v1`.+ * `OLLAMA_HOST` is conventionally a bare `host:port`.+ *+ * @param {string} raw+ * @returns {string}+ */+export function normalizeOllamaBaseUrl(raw) {+ let url = String(raw || '').trim().replace(/\/+$/, '').replace(/\/v1$/, '')+ if (url && !/^https?:\/\//i.test(url)) url = `http://${url}`+ return url || 'http://localhost:11434'+}+/*** The window PortOS holds `provider`'s daemon at, or `null` when it holds it at* none (Ollama's VRAM auto-pick stands).diff --git a/server/services/ollamaManager.js b/server/services/ollamaManager.jsindex e8e4777eac..c513ee8bd7 100644--- a/server/services/ollamaManager.js+++ b/server/services/ollamaManager.js@@ -35,7 +35,7 @@ import { buildHfAuthHeaders, buildHfResolveUrl, HF_API } from '../lib/huggingfacimport { isEmbeddingModel } from '../lib/localModelHeuristics.js'import { commandExists } from '../lib/commandExists.js'import {- OLLAMA_AGENT_MIN_CONTEXT, OLLAMA_CONTEXT_ENV_VAR, managedOllamaBaseUrl, resolveOllamaContextLength, withOllamaContextEnv+ OLLAMA_AGENT_MIN_CONTEXT, OLLAMA_CONTEXT_ENV_VAR, managedOllamaBaseUrl, normalizeOllamaBaseUrl, resolveOllamaContextLength, withOllamaContextEnv} from '../lib/ollamaContext.js'import { compareSemver } from '../lib/versionUtils.js'import { isSafeHfRepoRelativePath } from '../lib/hfCache.js'@@ -81,11 +81,7 @@ const DEFAULT_CONFIG = {timeout: DEFAULT_REQUEST_TIMEOUT_MS}-function normalizeBaseUrl(raw) {- let url = String(raw || '').trim().replace(/\/+$/, '').replace(/\/v1$/, '')- if (url && !/^https?:\/\//i.test(url)) url = `http://${url}`- return url || 'http://localhost:11434'-}+const normalizeBaseUrl = normalizeOllamaBaseUrllet config = { ...DEFAULT_CONFIG }let isAvailable = nulldiff --git a/server/services/stackerNews.js b/server/services/stackerNews.jsindex 8ea43c9047..bcbd376e47 100644--- a/server/services/stackerNews.js+++ b/server/services/stackerNews.js@@ -3,6 +3,7 @@ import { query, withTransaction } from '../lib/db.js';import { decryptValue, encryptValue, ensureVaultKey } from '../lib/vaultCrypto.js';import { executeStackerNewsBrowserRead, executeStackerNewsOperation, stackerNewsCapabilities } from '../integrations/stackerNews/index.js';import { fetchWithTimeout } from '../lib/fetchWithTimeout.js';+import { managedOllamaBaseUrl, normalizeOllamaBaseUrl } from '../lib/ollamaContext.js';import { UNTRUSTED_CONTENT_INSTRUCTIONS, formatUntrustedContent } from '../lib/untrustedContent.js';import { fetchAndNormalizeStackerNewsImage, hashRemoteMediaUrl } from './stackerNewsMedia.js';import { getStackerNewsBrowserIdentity, openStackerNewsHandoff } from './stackerNewsBrowser.js';@@ -28,7 +29,6 @@ const INJECTION_PATTERNS = [/(?:run|execute) (?:this |the )?(?:command|script)/i,/<\/?(?:system|instruction|prompt)>/i,];-const OLLAMA_ENDPOINT = 'http://127.0.0.1:11434/api/chat';// The ingress name this source screens under at the shared phase-1 boundary.// Public community content, so it is deliberately absent from// PRIVATE_UNTRUSTED_CONTENT_SOURCES: a cloud classifier is eligible for it,@@ -406,7 +406,7 @@ const ANALYSIS_CONTRACT = 'Classify untrusted community content. Return exactly:async function runOllamaAnalysis(model, content, rules, images = []) {if (!model) return null;- const response = await fetchWithTimeout(OLLAMA_ENDPOINT, {+ const response = await fetchWithTimeout(`${normalizeOllamaBaseUrl(managedOllamaBaseUrl())}/api/chat`, {method: 'POST',headers: { 'content-type': 'application/json' },body: JSON.stringify({diff --git a/server/services/stackerNewsScreening.test.js b/server/services/stackerNewsScreening.test.jsindex 00f2367aac..20c2644d96 100644--- a/server/services/stackerNewsScreening.test.js+++ b/server/services/stackerNewsScreening.test.js@@ -61,6 +61,26 @@ beforeEach(() => {};});+describe('Stacker News analysis endpoint', () => {+ it.each([+ [{ OLLAMA_HOST: '127.0.0.1:11500' }, 'http://127.0.0.1:11500/api/chat'],+ [{}, 'http://localhost:11434/api/chat'],+ ])('posts to the configured Ollama daemon %j', async (env, url) => {+ const saved = { OLLAMA_URL: process.env.OLLAMA_URL, OLLAMA_HOST: process.env.OLLAMA_HOST };+ delete process.env.OLLAMA_URL; delete process.env.OLLAMA_HOST;+ Object.assign(process.env, env);+ try {+ screenUntrustedContent.mockResolvedValue({ ok: true, safe: true });+ item.image_urls = [];+ fetchWithTimeout.mockResolvedValue(ollamaResponse(allowed));+ await analyzeItem('item');+ expect(fetchWithTimeout.mock.calls[0][0]).toBe(url);+ } finally {+ for (const [k, v] of Object.entries(saved)) { if (v === undefined) delete process.env[k]; else process.env[k] = v; }+ }+ });+});+describe('Stacker News phase-1 screening', () => {it('reaches no model — text or vision — when screening blocks the item', async () => {screenUntrustedContent.mockResolvedValue({ ok: false, safe: false, code: 'untrusted-content-blocked', message: 'flagged' });diff --git a/server/services/voice/llm.js b/server/services/voice/llm.jsindex 8218864292..587b6fa4a8 100644--- a/server/services/voice/llm.js+++ b/server/services/voice/llm.js@@ -8,6 +8,7 @@import { getProviderById } from '../providers.js';import { DEFAULT_VOICE_BACKEND } from './config.js';+import { managedOllamaBaseUrl } from '../../lib/ollamaContext.js';import { normalizeOpenAiBaseUrl } from '../../lib/localProviderRuntime.js';import { assertSecretEndpoint } from '../../lib/aiToolkit/endpointGuard.js';@@ -19,9 +20,7 @@ const LM_STUDIO_API_BASE = () => normalizeOpenAiBaseUrl(process.env.LM_STUDIO_UR// `host:port` with no scheme (that is how .env.example documents it), so this// must go through the shared normalizer rather than string-concatenating// `/v1` onto it — `localhost:11434/v1` is not a fetchable URL.-const OLLAMA_API_BASE = () => normalizeOpenAiBaseUrl(- process.env.OLLAMA_URL || process.env.OLLAMA_HOST || 'http://localhost:11434'-);+const OLLAMA_API_BASE = () => normalizeOpenAiBaseUrl(managedOllamaBaseUrl());// Last-resort endpoints when the configured provider resolves to nothing// usable. Keyed by the built-in local backends so the fallback follows