2026-08-21 21:37:28 +03:00
|
|
|
import path from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
|
|
|
|
|
/** Repository root (this file is at <root>/config.ts). */
|
|
|
|
|
export const ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
|
2026-09-17 15:32:28 +03:00
|
|
|
/**
|
|
|
|
|
* THE data-location seam (the Electron contract, 2026-09-17): LH_DATA_DIR
|
|
|
|
|
* relocates every MUTABLE record — chat sessions, graph ledgers, the
|
|
|
|
|
* embedding model cache — when set. The desktop shell points it at
|
|
|
|
|
* userData so nothing is written inside the read-only .app bundle
|
|
|
|
|
* (macOS translocation guarantees the bundle is read-only anyway).
|
|
|
|
|
* Unset (plain web dev / repo work) it resolves to the repo's data/,
|
|
|
|
|
* byte-for-byte as before. Read-only assets (prompts) stay ROOT-anchored
|
|
|
|
|
* on purpose: they ship inside the app bundle by design.
|
|
|
|
|
*/
|
|
|
|
|
const DATA_ROOT = process.env.LH_DATA_DIR
|
|
|
|
|
? path.resolve(process.env.LH_DATA_DIR)
|
|
|
|
|
: path.join(ROOT, "data");
|
|
|
|
|
|
2026-08-21 21:37:28 +03:00
|
|
|
export const PATHS = {
|
|
|
|
|
root: ROOT,
|
2026-08-22 02:18:27 +03:00
|
|
|
/** Teacher system prompt — the agent's instructions (src/agent/). */
|
|
|
|
|
teacherPrompt: path.join(ROOT, "src", "agent", "system-prompt.md"),
|
2026-09-17 15:32:28 +03:00
|
|
|
data: DATA_ROOT,
|
2026-08-22 02:18:27 +03:00
|
|
|
/** Chat sessions (AI SDK UIMessage transcripts, one JSON file per chat). */
|
2026-09-17 15:32:28 +03:00
|
|
|
chats: path.join(DATA_ROOT, "chats"),
|
|
|
|
|
graph: path.join(DATA_ROOT, "graph"),
|
2026-10-04 20:21:18 +03:00
|
|
|
/** Debug artifacts (env-gated): data/debug/provider-events/<chatId>.jsonl
|
|
|
|
|
* raw provider stream recordings (src/agent/provider-events.ts). */
|
|
|
|
|
debug: path.join(DATA_ROOT, "debug"),
|
2026-08-21 21:37:28 +03:00
|
|
|
} as const;
|
|
|
|
|
|
2026-09-01 01:47:47 +03:00
|
|
|
// ─── Models ────────────────────────────────────────────────────────────────
|
2026-09-22 16:58:25 +03:00
|
|
|
// BYOK ALL THE WAY DOWN (owner, 2026-09-22): there are NO factory default
|
|
|
|
|
// models. Every engine resolves from the user's model slots (settings.json
|
|
|
|
|
// models section: strong/cheap/vision) over per-role/ChatSettings overrides,
|
|
|
|
|
// and a chain that ends empty REFUSES honestly (503 models_not_configured).
|
|
|
|
|
// .env stays for secrets (API keys) only. What remains here are ENGINE
|
|
|
|
|
// CONSTRUCTION FACTS: the thinking-level scale and the default order.
|
2026-09-01 01:47:47 +03:00
|
|
|
|
2026-09-12 06:02:40 +03:00
|
|
|
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
2026-09-01 01:47:47 +03:00
|
|
|
|
2026-09-22 16:58:25 +03:00
|
|
|
/** Every agent role in the app. The conversation pair (prober/teacher)
|
|
|
|
|
* resolves chat.model → strong slot; background roles resolve their own
|
|
|
|
|
* override → tier slot (core/settings-resolution.ts ROLE_SLOT). */
|
|
|
|
|
export type ModelRole =
|
|
|
|
|
| "prober"
|
|
|
|
|
| "teacher"
|
|
|
|
|
| "researcher"
|
|
|
|
|
| "demoBuilder"
|
|
|
|
|
| "visualMaker"
|
|
|
|
|
| "pdfReader"
|
|
|
|
|
| "extractor"
|
2026-10-04 21:34:24 +03:00
|
|
|
| "auditor";
|
2026-09-01 01:47:47 +03:00
|
|
|
|
2026-08-31 22:36:41 +03:00
|
|
|
/**
|
|
|
|
|
* The LIVE graph store (src/store/graph.ts) — owned by the app's extraction
|
2026-09-30 03:22:52 +03:00
|
|
|
* pipeline. Line shapes: src/core/contracts.ts. CHAINS ARE THE STORED
|
|
|
|
|
* TRUTH (owner, 2026-09-30): edges are a derived view, never stored.
|
2026-08-22 10:11:58 +03:00
|
|
|
*/
|
2026-08-21 21:37:28 +03:00
|
|
|
export const LEDGER_FILES = {
|
|
|
|
|
nodes: path.join(PATHS.graph, "nodes.jsonl"),
|
2026-09-30 03:22:52 +03:00
|
|
|
chains: path.join(PATHS.graph, "chains.jsonl"),
|
2026-08-21 21:37:28 +03:00
|
|
|
sessions: path.join(PATHS.graph, "sessions.jsonl"),
|
2026-09-15 17:41:56 +03:00
|
|
|
/** Per-message extraction coverage (contracts/graph.ts CoverageEntry;
|
|
|
|
|
* the checkpoint's replacement for chat extractions — notes keep
|
|
|
|
|
* sessions.jsonl, whole-file as they are). */
|
|
|
|
|
coverage: path.join(PATHS.graph, "coverage.jsonl"),
|
2026-08-21 21:37:28 +03:00
|
|
|
} as const;
|
2026-09-13 02:08:55 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Notes-import bookkeeping (NOT a ledger): one JSON map, src-id → NotesSource
|
|
|
|
|
* record (contracts/graph.ts) — the file path + import time + the run's usage
|
|
|
|
|
* log. Read-modify-write like a chat file, not append-only like the ledgers.
|
|
|
|
|
*/
|
|
|
|
|
export const SOURCES_FILE = path.join(PATHS.graph, "sources.json");
|
2026-09-13 08:35:42 +03:00
|
|
|
/** The layout ledger (read-modify-write like sources.json): nodeId →
|
|
|
|
|
* {x,y} resting positions from the incremental settle (core/layout.ts).
|
|
|
|
|
* Carries an updatedAt stamp for future live-physics conflict handling. */
|
|
|
|
|
export const POSITIONS_FILE = path.join(PATHS.graph, "positions.json");
|
2026-09-13 05:56:27 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Graph render settings (the settings-panel controls): one small JSON blob,
|
|
|
|
|
* read-modify-write. Shared shape/sanitizer: src/core/render-settings.ts.
|
|
|
|
|
*/
|
|
|
|
|
export const RENDER_SETTINGS_FILE = path.join(PATHS.graph, "render-settings.json");
|
2026-09-18 09:25:40 +03:00
|
|
|
|
2026-09-19 18:05:30 +03:00
|
|
|
/**
|
|
|
|
|
* THE USER SETTINGS RECORD (settings-storage wave, 2026-09-19): one
|
|
|
|
|
* versioned, DELTA-shaped JSON blob at the data-dir seam holding every
|
2026-09-28 23:30:11 +03:00
|
|
|
* non-secret product preference — general, agent (background
|
2026-09-19 18:05:30 +03:00
|
|
|
* model/thinking overrides + tool toggles + prompt-override switches),
|
|
|
|
|
* appearance, graph. Explicit user choices only: ABSENT keys resolve to the
|
|
|
|
|
* factory defaults compiled into src/core/settings.ts (FACTORY_SETTINGS), so
|
|
|
|
|
* a software update that adds a knob (new tool, new role, new appearance
|
|
|
|
|
* field) needs no migration — old records simply lack the new keys. The
|
|
|
|
|
* version field is a PRIVATE schema counter for breaking shape changes
|
|
|
|
|
* only (field renamed/meaning changed), unrelated to the app release
|
|
|
|
|
* version. Secrets (API keys, login tokens) NEVER live here — auth.json /
|
2026-09-28 23:30:11 +03:00
|
|
|
* .env.local keep that role. (The `chat` default-settings section died
|
|
|
|
|
* with per-session models, owner 2026-09-28 — sessions own their model
|
|
|
|
|
* from birth, stamped from the strong slot.)
|
2026-09-19 18:05:30 +03:00
|
|
|
*/
|
|
|
|
|
export const SETTINGS_FILE = path.join(DATA_ROOT, "settings.json");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* User prompt-override files (settings-storage wave, 2026-09-19): the
|
|
|
|
|
* per-segment system-prompt overrides mirroring the SOURCE layout
|
|
|
|
|
* (src/agent/prompts/) — the shared base as prompts/system-prompt.md,
|
|
|
|
|
* fragments as prompts/teacher/<file> / prompts/prober/<file>. File
|
|
|
|
|
* PRESENCE alone is not the override: settings.json's agent.prompts map
|
|
|
|
|
* (segmentPath → boolean) is the explicit switch, so a user can keep a
|
|
|
|
|
* customized file on disk but run the source default to compare. The
|
|
|
|
|
* segment list itself is ALWAYS derived from source at runtime (the
|
|
|
|
|
* loader in src/store/prompt-overrides.ts) — code updates that add,
|
|
|
|
|
* remove, or reorder fragments adapt automatically; an override keyed to
|
|
|
|
|
* a vanished segment stops composing but stays on disk.
|
|
|
|
|
*/
|
|
|
|
|
export const PROMPTS_OVERRIDE_DIR = path.join(DATA_ROOT, "prompts");
|
2026-09-19 20:54:16 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* THE AUTH/KEY STORE (auth-keys wave, 2026-09-19): BYOK provider keys in a
|
|
|
|
|
* flat {VAR: value} JSON map — the SAME file the Electron app has always
|
|
|
|
|
* hand-edited (owner decision: option A, zero migration). Desktop main.cjs
|
|
|
|
|
* passes LH_AUTH_FILE pointing at userData/auth.json (mode 0600); in dev
|
|
|
|
|
* (no Electron) the default is the repo-root auth.json (gitignored, same
|
|
|
|
|
* pattern as .env.local — a worktree may symlink it to the master copy).
|
|
|
|
|
* The SERVER reads/writes this file directly at call time (no restart to
|
|
|
|
|
* change a key); it reflects the values into process.env at boot with
|
|
|
|
|
* FILL-GAP precedence — real environment variables (incl. .env.local in
|
|
|
|
|
* dev) always win (src/server/keys.ts). Hand-edits still work: the file is
|
|
|
|
|
* re-read from disk on every API access. Secrets NEVER go in settings.json
|
|
|
|
|
* — this file keeps that role, alongside .env.local.
|
|
|
|
|
*/
|
|
|
|
|
export const AUTH_FILE = process.env.LH_AUTH_FILE
|
|
|
|
|
? path.resolve(process.env.LH_AUTH_FILE)
|
|
|
|
|
: path.join(ROOT, "auth.json");
|