Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ node_modules/
dist/
.DS_Store
tmp_audio_*
project_uploads/
11 changes: 8 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

## Product

DaveLLM is a FastAPI router with an Electron and browser UI for authenticated chat against configured Ollama nodes. The repository preserves conversation and project JSON semantics, SQLite vector/feedback/performance stores, streamed chat, attachments, export, monitoring, and optional local tools.
DaveLLM is a FastAPI router with an Electron and browser UI for authenticated chat against configured Ollama nodes. The repository preserves conversation and core project JSON semantics, normalized SQLite project context plus vector/feedback/performance stores, streamed chat, attachments, export, monitoring, and optional local tools.

## Source layout

- `app.py`: FastAPI routes, persistence, inventory, chat, tools, monitoring
- `project_context.py`: normalized Project Homepage storage, BRAIN revisions, file/artifact retrieval, and bounded request assembly
- `tool_executor.py`: runtime tool registry, schema validation, timing, approval boundaries, and bounded executor loop
- `static/`: runtime HTML, CSS, JavaScript, monitoring, favicon
- `static/vendor/`: pinned browser-only Lucide and GSAP assets with their license notices; no CDN runtime path
- `desktop/`: Electron main process and preload bridge
- `scripts/macos/`: Keychain-backed launcher and local app installer; node addresses are resolved from live Tailscale state
- `tests/`: source-aligned FastAPI, mocked Ollama transport, security, and renderer contract tests
Expand All @@ -27,6 +29,7 @@ DaveLLM is a FastAPI router with an Electron and browser UI for authenticated ch
- The agent loop defaults to eight model steps, returns partial transcripts, and requires per-run approval for mutating or execution tools.
- Global, project, and session instruction layers are visible in the UI and resolve into one exact primary system message.
- Project notepads are plain text in project persistence. Do not add rich text, history, collaboration, or browser note storage.
- Existing-chat project changes must use the explicit attachment endpoint and apply only to future messages.

## Ollama integration

Expand All @@ -39,10 +42,12 @@ Every runtime persistence path is based on `BASE_DIR`, which is derived from `DA
- `dave_conversations.json`
- `dave_projects.json`
- `dave_settings.json`
- `dave_project_context.db`
- `dave_vectors.db`
- `feedback.db`
- `performance.db`
- `cost_log.jsonl`
- `project_uploads/`

Do not import, move, or infer legacy model or data locations.

Expand All @@ -64,7 +69,7 @@ GitHub Actions enforces these checks on every push to `main` and every pull requ
Required checks after relevant changes:

```bash
python -m py_compile app.py
python -m py_compile app.py project_context.py scripts/project_context_cli.py
python -m pytest -q
node --check static/app.js static/prompt-contract.js desktop/main.js desktop/preload.js
bash -n deploy/check-cluster.sh scripts/verify-cluster.sh
Expand All @@ -78,4 +83,4 @@ git diff --check
- Real node reachability, installed model inventory, inference quality, Whisper execution, and hardware performance require cluster access and are not proven by repository tests.
- Electron is pinned to `^44.0.0` (upgraded from `^30.0.0` per audit finding H-1, 2026-08-26). npm audit reports no known vulnerabilities at this line; keep the pin on a supported major.
- FastAPI startup/shutdown event deprecation warnings are known; a lifespan migration is deferred because it is outside the P0 stabilization scope.
- JSON conversation/project persistence is preserved. A SQLite migration is deferred.
- Conversation JSON and core project metadata remain compatible. Project Instructions, BRAIN revisions, uploaded-file indexes, and artifact history are normalized in `dave_project_context.db`; a full conversation migration remains deferred.
16 changes: 14 additions & 2 deletions INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,24 @@ Accepts a message array, inventory-backed node and model, step ceiling, error bu

`GET /projects/{project_id}/notepad` returns the project-scoped plain text. `PUT` autosaves a bounded `content` string. The notepad does not create artifact history, rich text, or browser-persisted note copies.

### Project Homepage and context contracts

`GET /projects/{project_id}/homepage` returns the project record, attached conversation IDs, exact baseline quotas, usage, and four independently owned components: Project Instructions, File Context Uploads, Artifact History, and BRAIN.

- `POST /projects/{project_id}/files`, plus file `PUT`, `reindex`, and `DELETE` routes, own local upload, status, attach/detach, reindex, and deletion. Only attached, successfully indexed UTF-8 text chunks are eligible for requests.
- Artifact list/get/update/delete routes own retained assistant outputs. Attached-chat responses are captured automatically; pinning affects retrieval priority and archiving removes an artifact from request context.
- BRAIN get/update/delete, compact, revisions, and restore routes own tiered durable context. Updates use optimistic revision checks; deletion is soft until the configured recovery window expires.
- `POST /projects/{project_id}/context-preview` returns the exact assembled next-request messages and budget without calling a model or mutating the conversation.
- `PUT /conversations/{conversation_id}/project` is the only route that reattaches an existing chat. It records a future-only context event. A `null` project creates a General chat context.

The request allocator reserves model output, a five-percent safety margin, and non-project history first. Its baseline project split is 25 percent instructions, 25 percent BRAIN, 30 percent files, and 20 percent artifacts. Unused tokens roll forward to BRAIN, files, then artifacts. The payload order is one exact primary system prompt containing global, project, and session instruction layers; BRAIN; ranked file context; ranked artifact history; bounded conversation history; and the current user message.

## Persistence and static serving

All persistence artifacts, including `dave_settings.json`, resolve under `DAVE_DATA_DIR`, with the current directory retained as the unset default. Runtime UI files are served only from `static/`. Requests for source, `.git`, JSON, SQLite, and log paths return `404` unless a separately declared API route owns the path.
All persistence artifacts, including `dave_settings.json`, `dave_project_context.db`, and `project_uploads/`, resolve under `DAVE_DATA_DIR`, with the current directory retained as the unset default. Runtime UI files are served only from `static/`. Requests for source, `.git`, JSON, SQLite, and log paths return `404` unless a separately declared API route owns the path.

## Verified versus runtime-dependent

Automated tests verify auth states, static isolation, Ollama-compatible inventory and chat transports, stream success and failure events, templates, export, tools default-off behavior, title generation, raw embedding indexes, exact effective-prompt construction, and data-directory containment.
Automated tests verify auth states, static isolation, Ollama-compatible inventory and chat transports, stream success and failure events, templates, export, tools default-off behavior, title generation, raw embedding indexes, exact effective-prompt construction, Project Homepage lifecycles, request-context order and preview, BRAIN compaction/recovery, token rollover, and data-directory containment.

Real cluster reachability, actual model inventory, Whisper binaries, inference performance, and end-to-end hardware behavior remain runtime-dependent and require an authorized cluster check.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ The repository intentionally contains no real node addresses or verified model i

## Data and tools

`DAVE_DATA_DIR` relocates all seven persistence artifacts. When unset, the current working directory remains the default.
`DAVE_DATA_DIR` relocates all eight persistence files and the project-upload directory. When unset, the current working directory remains the default.

- `dave_conversations.json`
- `dave_projects.json`
- `dave_settings.json`
- `dave_project_context.db`
- `dave_vectors.db`
- `feedback.db`
- `performance.db`
- `cost_log.jsonl`
- `project_uploads/`

Tools are disabled by default. To enable them, set `DAVE_ENABLE_TOOLS=true` and provide `DAVE_TOOL_ROOTS` as a JSON array of absolute paths. File read, write, and append operations share the same containment check. `shell.exec` remains disabled unless `DAVE_ENABLE_SHELL_TOOL=true` is also set. `web.fetch` accepts only bounded public HTTP/HTTPS responses and validates DNS plus each redirect target.

Expand All @@ -104,6 +106,32 @@ The Chat header opens a layered instruction editor. It shows the global default,

Completed user and assistant messages expose keyboard-reachable Copy and Add to notepad actions. Copy preserves raw message source. The plain-text notepad persists per project, autosaves, stays inside Chat, can accept a selection from either message role, and can send its full contents as one user message.

## Project Homepage and BRAIN

Project Home is the inspectable owner for exactly four request-context components: Project Instructions, File Context Uploads, Artifact History, and BRAIN. Its baseline budget is deterministic: 25 percent instructions, 25 percent BRAIN, 30 percent files, and 20 percent artifacts. Unused capacity rolls forward to BRAIN, then files, then artifacts; instructions and protected BRAIN text are rejected instead of silently truncated. Preview context assembles the exact next-request messages without calling a model.

BRAIN stores pinned facts, active work, and compactable recent context in `dave_project_context.db`. Threshold and explicit compaction create immutable revisions; duplicate, resolved, superseded, and raw tool-log lines can be removed while pinned and active tiers remain verbatim. Delete is recoverable for `DAVE_BRAIN_RECOVERY_DAYS`, after which the daily worker permanently clears old content and starts a fresh revision history.

The authenticated local CLI uses the running router and `DAVE_API_KEY`:

```bash
python scripts/project_context_cli.py show <project-id>
python scripts/project_context_cli.py pin <project-id> --text 'Decision: verify before release.'
python scripts/project_context_cli.py compact <project-id>
python scripts/project_context_cli.py revisions <project-id>
python scripts/project_context_cli.py restore <project-id> 2
```

Project-context configuration:

- `DAVE_MODEL_CONTEXT_DEFAULT` — fallback model window, default `32768`.
- `DAVE_MODEL_CONTEXT_WINDOWS` — JSON object of model IDs to context-window tokens.
- `DAVE_PROJECT_CONTEXT_TOKENS` — new-project context budget, default `16384`.
- `DAVE_BRAIN_COMPACT_TOKENS` — new-project compaction threshold, default `3072`.
- `DAVE_BRAIN_RECOVERY_DAYS` — soft-delete recovery window, default `30`.

The Project Homepage uses a vendored GSAP 3.15.0 core timeline for its precision-control-deck reveal and context-preview feedback. It animates transform and opacity only, switches directly to final states under `prefers-reduced-motion: reduce`, and performs no CDN request. The vendored notice is in `static/vendor/gsap/NOTICE.md`.

## Local suggestions and mobile navigation

The browser client derives at most three deterministic Suggested next actions from the current composer, attachment type, validated project/node/model selection, and response shape. Prediction generation lives in `static/anticipation.js`; it performs no network, DOM, or storage work, and suggestion chips never submit or change context without a visible user action. Valid last-used selections may be restored only on the empty startup state after inventory and node-health checks, with a visible status and immediate Undo. The client no longer calls `/route/decision` while sending a message, so the selected model remains under manual control.
Expand All @@ -115,6 +143,7 @@ Suggestion preferences use the versioned `davellm_anticipation_v1` local-storage
```bash
source venv/bin/activate
python -m py_compile app.py
python -m py_compile project_context.py scripts/project_context_cli.py
python -m py_compile tool_executor.py
python -m pytest -q
node --check static/app.js
Expand Down
Loading
Loading