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
refactor(local-llm): simplify pass — reuse readJSONFile, drop dead code
Adam Eivy0a0d41c45399
diff --git a/PLAN.md b/PLAN.mdindex 539224f2af..287ab8f3d1 100644--- a/PLAN.md+++ b/PLAN.md@@ -8,6 +8,7 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [.changel## Next Up+- [ ] [prune-unused-local-llm-models-route] **Decide the fate of `GET /api/local-llm/models`.** `server/routes/localLlm.js` exposes a per-backend installed-model list, but nothing consumes it: the UI reads installed models from `/status`, and the `/simplify` pass removed the only client wrapper (`getLocalLlmModels`). It's a coherent REST surface (cheap to keep) but currently dead and untested. Either delete the route (~6 lines, never shipped so safe) or add a thin test if it's meant to stay a public endpoint. Flagged during the `[local-llm-backend-management]` simplify pass as a judgment call, not auto-removed since dropping an HTTP endpoint is an API-design decision.- [ ] [extract-shared-env-file-helper] **Extract a shared `.env` parse/set-key helper.** `parseEnvFile()` + single-key upsert logic is now duplicated three ways: `scripts/setup-db.js` (`setPgMode`), `scripts/setup-llm.js` (`parseEnvFile`/`setBackend`), and `server/services/localLlm.js` (`readEnv`/`writeBackend`). Deferred from the `[local-llm-backend-management]` simplify pass because the two setup scripts are intentionally dependency-light/standalone (run before/around `npm install`) and shouldn't import from `server/lib`. Cleanest fix: a tiny `scripts/lib/envFile.js` shared only between the setup scripts (parse + `upsertEnvKey(path, key, value)`); leave `localLlm.js`'s copy or have it import the same helper if the script→server boundary is acceptable. ~15 lines each.- [ ] [migrate-taskitem-formatattachmentsize-to-formatbytes] **Migrate `TaskItem.jsx`'s local `formatAttachmentSize` to shared `formatBytes`.** `client/src/components/cos/tabs/TaskItem.jsx` still defines a local `formatAttachmentSize(bytes)` (B/KB/MB with `.toFixed(1)`) that duplicates `formatBytes` in `client/src/utils/formatters.js`. Surfaced by gemini review during the `[migrate-two-remaining-local-formatters]` claim 2026-05-24; deferred as out-of-scope for that item (which named only `formatDateTime` + `formatDurationMin`). Note the edge-case semantics differ: the local helper returns `''` for falsy/0 size (used inside an attachment `title` like `(1.5 KB)`), while `formatBytes(0)` returns `'0 B'` — preserve the empty-on-missing behavior with a guard (`att.size ? formatBytes(att.size) : ''`) so the title doesn't render `(0 B)` for sizeless attachments.diff --git a/client/src/services/README.md b/client/src/services/README.mdindex 5fb8f5e750..cac509e1e0 100644--- a/client/src/services/README.md+++ b/client/src/services/README.md@@ -42,7 +42,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire| `apiCommands.js` | CLI command dispatch. || `apiDashboard.js` | Dashboard state. || `apiDatabase.js` | Database introspection. |-| `apiLocalLlm.js` | Local LLM backends (Ollama / LM Studio): status, model list/catalog/install/delete, backend install (Homebrew/script), switch/migrate. |+| `apiLocalLlm.js` | Local LLM backends (Ollama / LM Studio): status (incl. installed models), catalog, model install/delete, backend install (Homebrew/script), switch/migrate. || `apiGit.js` | Git operations. || `apiGithub.js` | GitHub repo metadata. || `apiHistory.js` | Historical logs / runs. |diff --git a/client/src/services/apiLocalLlm.js b/client/src/services/apiLocalLlm.jsindex 10bda56747..c365634c00 100644--- a/client/src/services/apiLocalLlm.js+++ b/client/src/services/apiLocalLlm.js@@ -1,11 +1,9 @@import { request } from './apiCore.js';// Local LLM backends (Ollama / LM Studio) — status, model management, migrate.+// Installed models per backend come back inside getLocalLlmStatus().export const getLocalLlmStatus = () => request('/local-llm/status');-export const getLocalLlmModels = (backend) =>- request(`/local-llm/models?backend=${encodeURIComponent(backend)}`);-export const getLocalLlmCatalog = (backend, q = '') =>request(`/local-llm/catalog?backend=${encodeURIComponent(backend)}${q ? `&q=${encodeURIComponent(q)}` : ''}`);diff --git a/server/lib/localLlmCatalog.js b/server/lib/localLlmCatalog.jsindex 373bf54476..17a3190bc7 100644--- a/server/lib/localLlmCatalog.js+++ b/server/lib/localLlmCatalog.js@@ -181,8 +181,7 @@ const normalizeLmStudioId = (id) => String(id || '').split('/').pop().trim().toLowerCase()- .replace(/[-.]gguf$/i, '')- .replace(/-gguf$/i, '');+ .replace(/[-.]gguf$/i, '');const normalizeFor = (backend, id) =>backend === 'ollama' ? normalizeOllamaId(id) : normalizeLmStudioId(id);diff --git a/server/services/lmStudioManager.js b/server/services/lmStudioManager.jsindex b1508cb8ae..b31dbee8b8 100644--- a/server/services/lmStudioManager.js+++ b/server/services/lmStudioManager.js@@ -523,7 +523,6 @@ export {getStatus,updateConfig,resetCache,- getModelsDir,resolveLocalModel,importModelFromGguf,DEFAULT_CONFIGdiff --git a/server/services/ollamaManager.js b/server/services/ollamaManager.jsindex 01f653fcd0..cdef804259 100644--- a/server/services/ollamaManager.js+++ b/server/services/ollamaManager.js@@ -16,8 +16,9 @@import { homedir } from 'os'import { join } from 'path'-import { readFile, readdir, stat } from 'fs/promises'+import { readdir, stat } from 'fs/promises'import { fetchWithTimeout } from '../lib/fetchWithTimeout.js'+import { readJSONFile } from '../lib/fileUtils.js'import {parseOllamaManifest, parseOllamaModelRef, ollamaManifestRelPath, digestToBlobFilename, buildModelfile} from '../lib/localLlmDisk.js'@@ -233,13 +234,13 @@ function getModelsDir() {}const fileExists = (p) => stat(p).then((s) => s.isFile()).catch(() => false)-const readJson = (p) => readFile(p, 'utf8').then((t) => JSON.parse(t)).catch(() => null)+const readManifest = (p) => readJSONFile(p, null, { logError: false })// The canonical manifest path covers registry-pulled models; fall back to a// shallow scan of manifests/<registry>/<namespace>/<name>/<tag> for custom// registries/namespaces we didn't guess.async function findManifest(modelsDir, ref) {- const direct = await readJson(join(modelsDir, ...ollamaManifestRelPath(ref).split('/')))+ const direct = await readManifest(join(modelsDir, ...ollamaManifestRelPath(ref).split('/')))if (direct) return directconst manifestsDir = join(modelsDir, 'manifests')const registries = await readdir(manifestsDir).catch(() => [])@@ -247,7 +248,7 @@ async function findManifest(modelsDir, ref) {const namespaces = await readdir(join(manifestsDir, registry)).catch(() => [])for (const ns of namespaces) {const candidate = join(manifestsDir, registry, ns, ref.name, ref.tag)- const m = await readJson(candidate)+ const m = await readManifest(candidate)if (m) return m}}@@ -324,7 +325,6 @@ export {pullModel,deleteModel,getStatus,- getModelsDir,resolveLocalModel,importModelFromGguf}