codehaven 0.14.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codehaven-0.14.0.dist-info/METADATA +686 -0
- codehaven-0.14.0.dist-info/RECORD +57 -0
- codehaven-0.14.0.dist-info/WHEEL +5 -0
- codehaven-0.14.0.dist-info/entry_points.txt +3 -0
- codehaven-0.14.0.dist-info/licenses/LICENSE +21 -0
- codehaven-0.14.0.dist-info/top_level.txt +1 -0
- offline_agent/__init__.py +2 -0
- offline_agent/__main__.py +4 -0
- offline_agent/agent.py +815 -0
- offline_agent/answers.py +438 -0
- offline_agent/arabic.py +106 -0
- offline_agent/changes.py +228 -0
- offline_agent/chats.py +121 -0
- offline_agent/cli.py +379 -0
- offline_agent/coder.py +199 -0
- offline_agent/dependencies.py +132 -0
- offline_agent/doctor.py +190 -0
- offline_agent/documents.py +189 -0
- offline_agent/edits.py +204 -0
- offline_agent/errors.py +41 -0
- offline_agent/evaluation.py +284 -0
- offline_agent/evidence.py +187 -0
- offline_agent/exclusions.py +95 -0
- offline_agent/export.py +27 -0
- offline_agent/gui.css +237 -0
- offline_agent/gui.html +177 -0
- offline_agent/gui.js +1213 -0
- offline_agent/gui.py +967 -0
- offline_agent/gui_arabic.js +226 -0
- offline_agent/guides.py +203 -0
- offline_agent/history.py +126 -0
- offline_agent/index_cache.py +78 -0
- offline_agent/insights.py +333 -0
- offline_agent/javascript.py +200 -0
- offline_agent/knowledge.py +569 -0
- offline_agent/languages.py +396 -0
- offline_agent/memory.py +192 -0
- offline_agent/messages.py +51 -0
- offline_agent/model.py +498 -0
- offline_agent/more_languages.py +253 -0
- offline_agent/ocr.py +204 -0
- offline_agent/prompts.py +130 -0
- offline_agent/references/langgraph-approvals.md +38 -0
- offline_agent/references/langgraph-checkpoints.md +37 -0
- offline_agent/references/langgraph-graphs.md +42 -0
- offline_agent/references/langgraph.md +49 -0
- offline_agent/review.py +205 -0
- offline_agent/scans.py +325 -0
- offline_agent/semantic.py +264 -0
- offline_agent/slash.py +53 -0
- offline_agent/study.py +210 -0
- offline_agent/symbols.py +201 -0
- offline_agent/tasks.py +164 -0
- offline_agent/test_runner.py +264 -0
- offline_agent/trace.py +239 -0
- offline_agent/tracebacks.py +98 -0
- offline_agent/workspace.py +419 -0
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codehaven
|
|
3
|
+
Version: 0.14.0
|
|
4
|
+
Summary: CodeHaven: a read-only, offline assistant for understanding code. Your code. Your machine. No API fees.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/Walid-Ahmed/codehaven
|
|
7
|
+
Project-URL: Documentation, https://github.com/Walid-Ahmed/codehaven#readme
|
|
8
|
+
Project-URL: Issues, https://github.com/Walid-Ahmed/codehaven/issues
|
|
9
|
+
Keywords: code assistant,offline,ollama,local llm,code search,rag
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: langgraph<2,>=1.0
|
|
19
|
+
Requires-Dist: langsmith<1,>=0.3
|
|
20
|
+
Requires-Dist: tree-sitter<0.26,>=0.25
|
|
21
|
+
Requires-Dist: tree-sitter-javascript<0.26,>=0.23
|
|
22
|
+
Requires-Dist: tree-sitter-typescript<0.24,>=0.23
|
|
23
|
+
Requires-Dist: tree-sitter-go<0.26,>=0.23
|
|
24
|
+
Requires-Dist: tree-sitter-java<0.24,>=0.23
|
|
25
|
+
Requires-Dist: tree-sitter-rust<0.25,>=0.23
|
|
26
|
+
Requires-Dist: pathspec<1,>=0.12
|
|
27
|
+
Requires-Dist: tree-sitter-c<0.25,>=0.23
|
|
28
|
+
Requires-Dist: tree-sitter-cpp<0.24,>=0.23
|
|
29
|
+
Requires-Dist: tree-sitter-c-sharp<0.25,>=0.23
|
|
30
|
+
Requires-Dist: tree-sitter-ruby<0.24,>=0.23
|
|
31
|
+
Requires-Dist: tree-sitter-php<0.26,>=0.23
|
|
32
|
+
Requires-Dist: tree-sitter-kotlin<2,>=1.0
|
|
33
|
+
Requires-Dist: tree-sitter-swift<0.8,>=0.6
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
36
|
+
Requires-Dist: playwright<2,>=1.40; extra == "dev"
|
|
37
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# CodeHaven
|
|
41
|
+
|
|
42
|
+
**Ask your codebase anything. Nothing leaves your machine.**
|
|
43
|
+
|
|
44
|
+
*Your code. Your machine. No API fees.*
|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+
CodeHaven is a read-only assistant for understanding code. Point it at a project, ask a question in plain English, and get an answer that cites the exact lines it relies on. One click shows you those lines. It runs on a local [Ollama](https://ollama.com/) model (`qwen2.5-coder:7b` by default), so there is no cloud service, no account, and no bill.
|
|
49
|
+
|
|
50
|
+
| | |
|
|
51
|
+
|---|---|
|
|
52
|
+
| **Private** | Your code is sent only to Ollama on `127.0.0.1`. No cloud inference, no telemetry, no tracing. |
|
|
53
|
+
| **Read-only** | It never changes, creates, or deletes your files. Ask for a fix and it explains what to change and where. |
|
|
54
|
+
| **Checked** | Line numbers are looked up in the real file, never taken from the model. An answer it cannot back up is marked **Unverified**. |
|
|
55
|
+
| **Free** | It runs on a model you download once. After that it works with the network unplugged. |
|
|
56
|
+
|
|
57
|
+

|
|
58
|
+
|
|
59
|
+
Watch the [narrated demo video on YouTube](https://youtu.be/d18wHCz8LFs) (or the [video file](docs/assets/codehaven-demo.mp4) in this repository), or read on.
|
|
60
|
+
|
|
61
|
+
## What you can ask
|
|
62
|
+
|
|
63
|
+
| You ask | You get |
|
|
64
|
+
|---|---|
|
|
65
|
+
| "Explain this project" | An overview with citations to the code behind each point |
|
|
66
|
+
| "Which function calls `checkout_total`?" | Every caller, with the function each one is in |
|
|
67
|
+
| "Fix `Store.low_stock` so items at the threshold are included" | The lines to change and the new code. Your file is left untouched |
|
|
68
|
+
| "Explain my uncommitted changes" | [Your Git diff, explained](#explain-your-git-changes) with citations to the changed lines |
|
|
69
|
+
| "Review `inventory/store.py`" | [Likely bugs](#review-a-file), one function at a time, most serious first |
|
|
70
|
+
| "Which functions have no tests?" | [A list of test gaps](#test-gaps-and-a-project-tour), instantly, with no model |
|
|
71
|
+
| "Give me a project tour" | An ordered reading list of up to 8 files |
|
|
72
|
+
| "Write a project report" | One Markdown report: reading order, a Mermaid diagram of the imports, libraries, untested functions, and a security scan |
|
|
73
|
+
| "Which libraries does this project use?" | What the manifests declare and what the code imports, with what no manifest declares |
|
|
74
|
+
| "Scan for secrets" | Hard-coded keys and passwords (masked), eval, shell and SQL built from strings, each cited |
|
|
75
|
+
| "What breaks if I change `apply_discount`?" | Its callers, the files that import it, and the tests that mention it |
|
|
76
|
+
| "Why is `pricing.py:2` here?" | The commits that last changed the lines, from git blame, and what their messages say |
|
|
77
|
+
| "Review my changes" | Only the functions your diff touched, reviewed one at a time |
|
|
78
|
+
| A pasted stack trace | Its frames matched to your files, innermost first, and the likely cause |
|
|
79
|
+
| "Write a commit message for my changes" | A message (or a PR description) to copy; nothing is committed |
|
|
80
|
+
| "I'm new to this project" | An onboarding guide: how to run and test it, what it uses, and what to read first |
|
|
81
|
+
| "Trace `checkout_total`" | [The calls below it](#trace-a-function), step by step, and who calls it |
|
|
82
|
+
| "اشرح الدالة `checkout_total`" | [The answer in Arabic](#ask-in-arabic), with the same checked citations |
|
|
83
|
+
|
|
84
|
+
In the browser page you can also draw a **structure map** of your files, make **flashcards** to study them, chat about a [notebook or PDF](#notebooks-and-pdfs), and turn a [screenshot of code](#read-code-from-a-picture) into a file. CodeHaven [remembers checked answers](#long-term-memory) and [your chats](#saved-chats) between sessions, on your computer only.
|
|
85
|
+
|
|
86
|
+
## Contents
|
|
87
|
+
|
|
88
|
+
- [Get started](#get-started)
|
|
89
|
+
- [How it is built](#how-it-is-built)
|
|
90
|
+
- [Chat in your browser](#chat-in-your-browser)
|
|
91
|
+
- [Use it from the terminal](#use-it-from-the-terminal)
|
|
92
|
+
- Features: [Git changes](#explain-your-git-changes) · [File review](#review-a-file) · [Test gaps and project tour](#test-gaps-and-a-project-tour) · [Call trace](#trace-a-function) · [Notebooks and PDFs](#notebooks-and-pdfs) · [Pictures of code](#read-code-from-a-picture) · [Long-term memory](#long-term-memory) · [Saved chats](#saved-chats) · [Search by meaning](#search-by-meaning) · [Arabic](#ask-in-arabic) · [VS Code](#use-it-from-vs-code)
|
|
93
|
+
- Reference: [Choosing a model](#choosing-a-model) · [Ollama and offline use](#ollama-and-offline-use) · [What v0.14 does](#what-v014-does) · [File exclusions](#file-exclusions) · [RAG](#local-reference-knowledge-base-rag) · [Speed](#local-inference-speed) · [Search](#search-file-contents) · [Isolated tests](#run-isolated-project-tests) · [Limits](#current-limits)
|
|
94
|
+
- [Development](#development)
|
|
95
|
+
- [Technical report](docs/TECHNICAL_REPORT.md)
|
|
96
|
+
|
|
97
|
+
## Get started
|
|
98
|
+
|
|
99
|
+
You need Python 3.10+ and [Ollama](https://ollama.com/). While you are online, do this once:
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
# 1. Start Ollama with cloud features off (leave this terminal open)
|
|
103
|
+
python3 scripts/start_ollama.py
|
|
104
|
+
|
|
105
|
+
# 2. In another terminal, download the default model
|
|
106
|
+
ollama pull qwen2.5-coder:7b
|
|
107
|
+
|
|
108
|
+
# 3. Install CodeHaven in a virtual environment
|
|
109
|
+
python3 -m venv .venv
|
|
110
|
+
source .venv/bin/activate # Windows PowerShell: .venv\Scripts\Activate.ps1
|
|
111
|
+
python -m pip install -e .
|
|
112
|
+
|
|
113
|
+
# 4. Optional: install Tesseract, only if you want CodeHaven to read code from pictures
|
|
114
|
+
brew install tesseract # Ubuntu or Debian: sudo apt install tesseract-ocr
|
|
115
|
+
|
|
116
|
+
# 5. Optional: download an embedding model, so search also works by meaning
|
|
117
|
+
ollama pull nomic-embed-text
|
|
118
|
+
|
|
119
|
+
# 6. Optional: a PDF reader, only if you want to chat about PDFs
|
|
120
|
+
python -m pip install pypdf # or: brew install poppler
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Step 4 is needed only for [pictures of code](#read-code-from-a-picture). Ollama runs the chat model; Tesseract is a second, separate local program that reads the text in a picture. It is not an Ollama model, so `ollama pull` does not install it. On Windows, use an installer from the [Tesseract installation page](https://tesseract-ocr.github.io/tessdoc/Installation.html) and make sure `tesseract --version` works in a new terminal.
|
|
124
|
+
|
|
125
|
+
**Or let CodeHaven do steps 1, 2, and 5 for you.** After installing Ollama and CodeHaven, run `codehaven --setup`. It starts Ollama if needed, suggests a model for this computer's memory (`qwen2.5-coder:3b` under 12 GB, the tested `qwen2.5-coder:7b` up to 32 GB, `qwen2.5:14b` above), and downloads it with `ollama pull` only if you answer `y`. That download is the only time CodeHaven uses the internet. `codehaven --doctor` also names the suggested model.
|
|
126
|
+
|
|
127
|
+
After that, everything works offline. Each time, activate the environment and open the browser page:
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
source .venv/bin/activate
|
|
131
|
+
codehaven --gui --start-ollama
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`--start-ollama` starts Ollama for this run if it is not already running, on `127.0.0.1` with its cloud features off, and stops it when CodeHaven exits, so step 1 is needed only the first time. If something is missing, `codehaven --doctor` says what and prints the command that fixes it: Ollama itself, the model, and the optional tools for pictures, PDFs, isolated tests, and Git changes.
|
|
135
|
+
|
|
136
|
+
**A shorter install.** With [pipx](https://pipx.pypa.io/) you can skip the virtual environment and get the `codehaven` command everywhere. This downloads CodeHaven from GitHub once:
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
pipx install git+https://github.com/Walid-Ahmed/codehaven.git
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## How it is built
|
|
143
|
+
|
|
144
|
+

|
|
145
|
+
|
|
146
|
+
CodeHaven is one agent, five tools, and a set of purpose-built helpers. The [technical report](docs/TECHNICAL_REPORT.md) covers each part in depth.
|
|
147
|
+
|
|
148
|
+
### The workflow
|
|
149
|
+
|
|
150
|
+
1. **You ask**, in the browser page or the terminal.
|
|
151
|
+
2. **A router picks the path.** This is plain code, not a model. A request with a known shape, such as "explain my last commit", goes to a helper built for it. Every other question goes to the agent.
|
|
152
|
+
3. **Plain code gathers context first.** It retrieves relevant passages, preloads files the question names, and searches for the code names, quoted settings, and dotted names (`express.static`) it mentions. A small model often skips these steps when left alone.
|
|
153
|
+
4. **The agent loops.** The local model picks one action per step. The tool runs, and its result goes back to the model, until the model returns `finish`.
|
|
154
|
+
5. **The answer is checked.** Line numbers are looked up in the real file, and every citation must match code that was actually read.
|
|
155
|
+
6. **You get a cited answer.** Checked answers are saved for later sessions.
|
|
156
|
+
|
|
157
|
+
### The agent
|
|
158
|
+
|
|
159
|
+
There is one agent, not several. It is a [LangGraph](https://docs.langchain.com/oss/python/langgraph/graph-api) loop around a single local model. A small model that plans, delegates, and merges results spends its steps on coordination, so CodeHaven keeps the model's job narrow: pick the next action, then explain what the evidence shows.
|
|
160
|
+
|
|
161
|
+
### The tools
|
|
162
|
+
|
|
163
|
+
| Tool | What it does |
|
|
164
|
+
|---|---|
|
|
165
|
+
| `read` | Reads a project file, in pages for long files |
|
|
166
|
+
| `search` | Finds exact text and names the function each match is in |
|
|
167
|
+
| `retrieve` | Fetches ranked passages from the local index |
|
|
168
|
+
| `run_tests` | Runs unittest or pytest in a Docker container with networking off, after you approve |
|
|
169
|
+
| `run_python` | Off unless you start with `--allow-python`. Runs a short Python snippet the model writes, after you approve the code it shows you, in the same Docker sandbox as `run_tests` |
|
|
170
|
+
| `finish` | Returns the answer and the code parts it relies on |
|
|
171
|
+
|
|
172
|
+
No tool writes files. `edit` and `write` do not exist, and the model is corrected if it asks for them.
|
|
173
|
+
|
|
174
|
+
### The helpers
|
|
175
|
+
|
|
176
|
+
| Helper | Uses the model | How it works |
|
|
177
|
+
|---|---|---|
|
|
178
|
+
| Git changes | Yes | Reads the diff with read-only git commands, then explains it |
|
|
179
|
+
| File review | Yes | One function per model call, because a small model shown a whole file says "looks fine" |
|
|
180
|
+
| Project tour | Yes | The order comes from the import graph; the model adds one sentence per file |
|
|
181
|
+
| Call trace | Yes | The calls and callers come from parsed code; the model adds one sentence per function |
|
|
182
|
+
| Flashcards | Yes | The model writes the cards; the lines each answer is about are looked up |
|
|
183
|
+
| Test gaps | No | Lists public functions that no test file mentions |
|
|
184
|
+
| Structure map | No | Draws calls and imports from parsed code |
|
|
185
|
+
| Picture to code | No | Tesseract reads the picture and indentation is rebuilt |
|
|
186
|
+
|
|
187
|
+
### Local knowledge
|
|
188
|
+
|
|
189
|
+
Passages reach the model four ways: keyword ranking (BM25), definition lookup for names in the question, import following across Python, JavaScript, TypeScript, Go, Java, Rust, C, C++, C#, Ruby, PHP, Kotlin, and Swift, and optional [search by meaning](#search-by-meaning) with a local embedding model.
|
|
190
|
+
|
|
191
|
+
### The agent loop in detail
|
|
192
|
+
|
|
193
|
+

|
|
194
|
+
|
|
195
|
+
A high-resolution [PNG version](docs/assets/how-codehaven-works.png) is available for slides.
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
START -> model -> read, search, retrieve, or run_tests -> model
|
|
199
|
+
|-> invalid reply -> correction message -> model (once)
|
|
200
|
+
\-> finish -> END
|
|
201
|
+
tool at action limit -> limit -> END
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The graph holds conversation messages, the current action, the action count, and the exit code in memory. It uses conditional edges to dispatch actions. There is no node that writes files. The action limit counts model responses, not internal graph nodes. Graph recursion has a separate guard sized to that limit. This version does not add persistent checkpoints.
|
|
205
|
+
|
|
206
|
+
If the model returns invalid JSON, an unknown action (including `edit` or `write`, which do not exist), missing fields, or a reply cut off at the token limit, no tool runs. The model gets one correction message explaining what was wrong, and the retry counts as a step. A second invalid reply in a row stops the task with exit code 1. Failures to reach Ollama are never retried.
|
|
207
|
+
|
|
208
|
+
Small models at temperature 0 sometimes repeat the same sentences until they hit the token limit. Replies are always streamed from Ollama, so a final answer that keeps repeating a phrase is stopped as soon as the loop is detected. The text before the repetition is kept as the answer, marked with a note. An answer that reaches its length limit ends at its last complete sentence, also with a note.
|
|
209
|
+
|
|
210
|
+
Identical actions are caught anywhere in a task, not only back to back, so alternating lookups stop early instead of using every step. An action may be repeated after compaction has removed its earlier result.
|
|
211
|
+
|
|
212
|
+
Implementation follows the [LangGraph graph API](https://docs.langchain.com/oss/python/langgraph/graph-api). Remote tracing is not supported. Every run is wrapped in [`tracing_context(enabled=False)`](https://docs.langchain.com/langsmith/trace-without-env-vars), so `LANGSMITH_TRACING`, `LANGCHAIN_TRACING_V2`, or an API key in your environment cannot turn uploads on. No tracing client is ever created. For timing and token details, use the local `Ollama metrics:` line printed after each model call.
|
|
213
|
+
|
|
214
|
+
## Chat in your browser
|
|
215
|
+
|
|
216
|
+
`codehaven --gui` opens a page in your browser:
|
|
217
|
+
|
|
218
|
+
1. **Pick a repository.** Type its path or click **Browse…** (Git repositories are marked), then click **Index**. Indexing a typical project takes a few seconds, and the page shows how many files it indexed. While it runs, **Index** becomes **Stop**: click it to end indexing, and the project that was open before stays open. Recent repositories are listed for one-click reopening.
|
|
219
|
+
**Or upload a single file.** No folder needed for a quick question: click **Upload a file…** or drop a file anywhere on the page. Any UTF-8 text file up to 64 KB works, and every question is about that file, so "What does this file do?" works without naming it. The file is sent only to the local server, which reads a copy kept in a private temporary folder and deletes it when you open something else or stop the server; your original file is never touched. Hidden files such as `.env`, and names matched by `--exclude`, are refused. The paperclip button beside the question box and pasting a copied file do the same, and the conversation is kept when a file is opened this way.
|
|
220
|
+
**Or download a GitHub repository (opt-in).** Start with `codehaven --gui --allow-clone` and the sidebar shows a box for an address such as `github.com/owner/repository`. This is the only time CodeHaven uses the internet, and only when you click **Download and index**: git on your computer downloads the latest snapshot (no history, tags, submodules, or Git LFS files; stopped after 3 minutes or 500 MB) into `~/CodeHaven/repos/owner/repository` (change it with `--clone-dir`). Nothing of yours is uploaded. The copy stays on your computer, so later it opens offline from **Recent**, and asking for the same address again opens it without downloading. Without `--allow-clone` the box is hidden, the server refuses to clone, and CodeHaven stays fully offline.
|
|
221
|
+
**Private repositories.** CodeHaven never asks for, sees, or stores a GitHub password or token, and refuses addresses that contain one. A private repository downloads only if git on this computer is already signed in to an account that can read it: a credential helper (for example after `gh auth login`), or an SSH key with a `git@github.com:owner/repository.git` address. git is not allowed to prompt for a password or passphrase. Otherwise, clone it yourself with your usual tools and index the folder.
|
|
222
|
+
**Or upload a notebook or a PDF.** The same button and drop area take a Jupyter notebook (`.ipynb`) or a PDF, up to 8 MB. See [Notebooks and PDFs](#notebooks-and-pdfs).
|
|
223
|
+
**Or upload a picture of code.** The same button and drop area take a screenshot or photo of code, which CodeHaven turns into a file you can chat about and save. See [Read code from a picture](#read-code-from-a-picture).
|
|
224
|
+
2. **Pick a model.** **Settings** in the sidebar lists the chat models installed in Ollama on this computer, with `qwen2.5-coder:7b` selected when it is installed. That default is the model all of CodeHaven's tests were tuned and measured on; other models may answer differently, and the first answer after switching is slower while the model loads. Cloud-backed and embedding-only models are never offered.
|
|
225
|
+
3. **Ask questions.** Answers stream in as they are written. While one is being written, the **Ask** button becomes **Stop**: click it to end the answer at once, even while the model is still loading. The text written so far stays on the page, and a stopped question is not remembered by follow-ups or saved. **Make flashcards** turns into **Stop** the same way, and keeps the cards already made. Follow-up questions see your earlier questions and answers, and **New chat** starts over. Try "Explain this project", "Which function calls `checkout_total`?", or "Explain `src/app.py`".
|
|
226
|
+
**Save a chat.** **Save chat…** in the sidebar saves the questions and answers on the page as a Markdown file, through your browser. Nothing is sent anywhere.
|
|
227
|
+
4. **Check the code.** Click a citation such as `inventory/store.py:27-29` to open those lines, highlighted, beside the chat. **Open in VS Code** above the code opens the same file at that line in VS Code, if it is installed; it is a link to a program on this computer, and nothing is sent anywhere.
|
|
228
|
+
5. **See how it got there.** Each answer can show the steps CodeHaven took. If a citation could not be checked against what was actually read, a yellow **Unverified** box says so.
|
|
229
|
+
6. **Study one file or a group of files.** The tabs above the chat add two study aids. Click **Choose files…** to tick the files they are about; with an uploaded file, that file is used.
|
|
230
|
+
- **Map** draws the structure. For one file it shows its functions, classes, and methods as boxes, with an arrow from each caller to what it calls; for several files it shows which file imports which, with files you did not choose as dashed boxes, and clicking a file opens its inside view. Click a box to see its code. The map comes from parsing the code (never running it) and uses no model, so it appears at once. Imports are followed for Python, JavaScript, TypeScript, Go, Java, Rust, C, C++, C#, Ruby, PHP, Kotlin, and Swift; up to 40 files per map. Functions, methods, and types in Go, Java, Rust, C, C++, C#, Ruby, PHP, Kotlin, and Swift are found with the same kind of parser as JavaScript; their imports are read with line patterns (Swift files of one module need no imports, so none are drawn), so unusual import layouts and macros can be missed.
|
|
231
|
+
- **Flashcards** asks the local model for question-and-answer cards, 3 to 6 per file for up to 8 files, one file at a time. Click a card or press Space to turn it over, use the arrow keys to move, and **Shuffle** or **Copy all as text** when you want. **Save for Anki…** saves the cards as a text file with one card per line, which Anki and most flashcard apps import. Each answer links to the lines it is about; those line numbers are looked up in the file from the name the model gave, so they are never invented. A card whose named part cannot be found says so.
|
|
232
|
+
|
|
233
|
+
7. **Come back to a chat.** Chats about a repository are saved on this computer and listed under **Saved chats** in the sidebar. Click one to reopen it: the page shows it again and follow-up questions remember it. See [Saved chats](#saved-chats).
|
|
234
|
+
|
|
235
|
+
Tips for good answers: name files and functions exactly (`Store.low_stock`, not "the stock function"), and ask one thing at a time.
|
|
236
|
+
|
|
237
|
+
**How follow-up memory works.** Each new question is sent with a short record of the conversation, not the whole chat, so the model keeps room for the code itself. The last two answers are kept nearly whole (up to 1,000 characters each), because follow-ups such as "and what does *it* return?" refer to them. Up to six older questions are kept as the question plus the first sentence of its answer. The whole record stays under about 3 KB, a quarter of the default prompt budget; the oldest questions are dropped first. The file paths and line ranges found so far are also carried forward, so follow-ups can cite them without searching again. Detailed tool output, such as file text read for an earlier question, is not carried over; the model reads it again if needed. The sidebar shows how many earlier questions are remembered. **New chat**, or reloading the page, starts with an empty memory; start one whenever you change topic, because an old topic can steer a new answer.
|
|
238
|
+
|
|
239
|
+
**Private and offline by design.** The page is served from `127.0.0.1` only and loads nothing from the internet: its Content-Security-Policy blocks any outside script, style, or font. Requests must carry a secret token from the link printed in the terminal and name this machine in their Host header, so other websites open in your browser cannot use the server to read your files. Only with `--allow-clone`, and only when you ask, does the server reach the internet, to download a GitHub repository. The page never runs tests. Only the list of recent repositories is kept, in your browser's local storage.
|
|
240
|
+
|
|
241
|
+
Options: `--workspace /path/to/repo` indexes a repository at startup, `--model NAME` picks the starting model, `--port 8737` sets a fixed port, `--no-browser` prints the link instead of opening it, and `--allow-clone` (with optional `--clone-dir FOLDER`) turns on downloading GitHub repositories. Ctrl+C in the terminal stops the server.
|
|
242
|
+
|
|
243
|
+
If every answer takes a minute or more, another program is probably using a different Ollama model at the same time; see [Local inference speed](#local-inference-speed).
|
|
244
|
+
|
|
245
|
+
## Explain your Git changes
|
|
246
|
+
|
|
247
|
+
Ask about your own work and CodeHaven reads the diff with git, then explains it with citations to the changed lines:
|
|
248
|
+
|
|
249
|
+
```sh
|
|
250
|
+
codehaven --workspace ~/dev/project 'Explain my uncommitted changes'
|
|
251
|
+
codehaven --workspace ~/dev/project 'What changed in my last commit?'
|
|
252
|
+
codehaven --workspace ~/dev/project 'Explain commit 8ec6e4f'
|
|
253
|
+
codehaven --workspace ~/dev/project 'Explain the staged changes'
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
In the browser page, a Git repository gets **My changes** and **Last commit** buttons on the empty chat.
|
|
257
|
+
|
|
258
|
+
- **Read-only.** Only `git diff`, `git log`, `git rev-parse`, and `git ls-files` are run. Nothing is staged, committed, checked out, or fetched, git is told not to refresh its index, and nothing uses the network.
|
|
259
|
+
- **Hidden files stay hidden.** Changes to files the workspace rules hide, such as `.env` or `--exclude` patterns, are counted but never shown to the model.
|
|
260
|
+
- **Large diffs.** The diff must fit in half the prompt budget. Files the question names come first, then the smallest changes; the answer says which files were not fully shown, and you can ask about one by name ("Explain the changes to `store.py` in my last commit").
|
|
261
|
+
- **No changes, no model.** "There are no uncommitted changes" is answered at once from git.
|
|
262
|
+
- **Not remembered.** "My last commit" means something else tomorrow, so these answers are never saved to long-term memory.
|
|
263
|
+
- **Line numbers** are those of the file after the change. For an older commit the file may have changed since, and a citation that no longer matches is marked **Unverified**.
|
|
264
|
+
|
|
265
|
+
## Review a file
|
|
266
|
+
|
|
267
|
+
```sh
|
|
268
|
+
codehaven --workspace ~/dev/project 'Review inventory/store.py'
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
CodeHaven checks the file one function at a time, up to 12 functions with one model call each, and lists likely bugs, missing checks, and unclear names, most serious first. Each finding cites the lines of the function it is about; those lines come from parsing the file, not from the model. With an uploaded file, the **Review** button does the same.
|
|
272
|
+
|
|
273
|
+
Shown a whole file, a small model tends to answer "looks fine". Shown one function and asked to state what it promises and what it really does, it notices when the two differ, such as a docstring that says "at or below" above code that uses `<`. A review is still a list of leads to verify, not proof: the model can miss a bug or flag correct code, and it sees one function at a time. Under that function it is shown the first lines (the signature and the docstring's first line) of the functions it calls in the same file, so it can notice a call with the wrong arguments; it does not see their bodies, or functions in other files. Nothing is changed; fixes are described, never applied.
|
|
274
|
+
|
|
275
|
+
## Test gaps and a project tour
|
|
276
|
+
|
|
277
|
+
Two answers come from parsing the whole project rather than from searching it:
|
|
278
|
+
|
|
279
|
+
- **Test gaps.** "Which functions have no tests?" lists every public function and method whose name appears in no test file, grouped so the files with the most gaps come first. No model is used, so it is instant. It is a name check, not coverage measurement: a function reached only through another function is still listed.
|
|
280
|
+
- **Project tour.** "Give me a project tour" returns an ordered reading list of up to 8 files: the README, then the entry point (the file that reaches the most of the project through its imports), then what it imports, most widely used first. The order and the reason for each step come from the import graph; the local model adds one sentence per file. Tests are left out. Imports are followed for Python, JavaScript, TypeScript, Go, Java, Rust, C, C++, C#, Ruby, PHP, Kotlin, and Swift.
|
|
281
|
+
|
|
282
|
+
Both have buttons on the empty chat in the browser page, and neither is saved to long-term memory, because a saved copy would not notice a new test or file.
|
|
283
|
+
|
|
284
|
+
## Trace a function
|
|
285
|
+
|
|
286
|
+
```sh
|
|
287
|
+
codehaven --workspace ~/dev/project 'Trace checkout_total'
|
|
288
|
+
codehaven --workspace ~/dev/project 'What happens when Store.add is called?'
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
CodeHaven lists the functions the named one calls, the functions those call, and where it is called from:
|
|
292
|
+
|
|
293
|
+
```text
|
|
294
|
+
Call path of checkout_total: 3 functions, up to 3 calls deep, found by parsing the code.
|
|
295
|
+
1. inventory/pricing.py:15-18 checkout_total: Applies the discount to the subtotal and returns it with tax.
|
|
296
|
+
2. inventory/pricing.py:5-8 apply_discount (called by checkout_total): ...
|
|
297
|
+
3. inventory/pricing.py:11-12 with_tax (called by checkout_total): ...
|
|
298
|
+
Called from: app/main.py:21 in checkout
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
- **The path is parsed, not guessed.** The order, the line ranges, and the callers come from the parsed code. The local model writes only the one sentence after each function, from that function alone.
|
|
302
|
+
- **Limits.** Up to 3 calls deep and 8 functions; the answer says how many calls were left out, and you can trace one of them by name.
|
|
303
|
+
- **What is followed.** A call to a function in the same file, in a file it imports, or to the only function of that name in the project. `self.add()` means the same class. A call on another object, such as `file.flush()`, is not followed, and neither are calls through a variable, a decorator, or inheritance. A name inside a string or a comment is not a call.
|
|
304
|
+
- **Same name twice.** Name the method with its class (`Store.add`); otherwise the first match is traced and the others are listed.
|
|
305
|
+
- Works for Python, JavaScript, TypeScript, Go, Java, Rust, C, C++, C#, Ruby, PHP, Kotlin, and Swift. A question with a condition, such as "what happens when `add` is called with a negative price?", is answered by the normal workflow instead.
|
|
306
|
+
|
|
307
|
+
## Notebooks and PDFs
|
|
308
|
+
|
|
309
|
+
Upload, drop, attach, or paste a Jupyter notebook (`.ipynb`) or a PDF, up to 8 MB, and chat about it like any single file. It is read into a text file on this computer, which you can view and save from the page; your original is never changed.
|
|
310
|
+
|
|
311
|
+
- **Notebook.** Code and Markdown cells become one file (`analysis.ipynb` becomes `analysis.py` for a Python notebook). Each cell starts with a `# %% Cell 3` line, Markdown becomes comments, and `%magic` and `!shell` lines are commented out so the file stays valid Python. Outputs and pictures are left out.
|
|
312
|
+
- **PDF.** The text of each page is kept under a `===== Page 3 =====` line, with indentation preserved where the PDF allows. This needs either the `pypdf` package or the `pdftotext` program (Poppler) on this computer; if neither is there, CodeHaven says how to install one and everything else keeps working. Columns and tables can lose their layout. A scanned PDF holds pictures, not text: attach a screenshot of the page instead.
|
|
313
|
+
- **Length.** CodeHaven reads 64 KB of text at once, so a longer document is cut at a cell or page boundary and the note says how much was kept.
|
|
314
|
+
|
|
315
|
+
## Read code from a picture
|
|
316
|
+
|
|
317
|
+
CodeHaven can read the code in a screenshot or photo and turn it into a `.py` file, offline. This needs [Tesseract](https://tesseract-ocr.github.io/tessdoc/Installation.html) installed on this computer (step 4 of [Get started](#get-started)); check with `tesseract --version`. If it is missing, CodeHaven says so and shows the install command, and everything else keeps working.
|
|
318
|
+
|
|
319
|
+
**In the browser page:**
|
|
320
|
+
|
|
321
|
+
1. Start `codehaven --gui`.
|
|
322
|
+
2. Give it the picture in any of four ways: click the paperclip button beside the question box, paste a copied screenshot with Cmd+V (Ctrl+V on Windows and Linux), drop the picture anywhere on the page, or click **Upload a file…** in the sidebar. PNG and JPEG pictures up to 8 MB and 40 megapixels work.
|
|
323
|
+
3. After a few seconds a note in the chat and in the sidebar says how many lines were read, for example `Read 18 lines from the picture shot.png into shot.py`, and the chat is now about the new file `shot.py`. A pasted screenshot has no name of its own, so it becomes `image.py`.
|
|
324
|
+
4. Check the text. The note lists the lines to compare with the picture; click a line number, or **View shot.py**, to see it. For Python it also says whether the file is valid Python and, if not, the first line that is wrong.
|
|
325
|
+
5. Click **Save shot.py…** to save the file through your browser, or ask questions about it first ("What does this file do?"), draw its map, or make flashcards.
|
|
326
|
+
|
|
327
|
+
The picture is read as soon as it arrives; you do not need to ask for it in the chat, and typing "I will send a picture" does nothing by itself. The conversation is kept: earlier questions and answers stay on the page and follow-up questions still remember them. Because the picture's file replaces what was open before, citations in those earlier answers no longer open, and questions are now answered from the new file. Click **New chat** to start over.
|
|
328
|
+
|
|
329
|
+
**From the terminal**, without the browser or the model:
|
|
330
|
+
|
|
331
|
+
```sh
|
|
332
|
+
codehaven --ocr /path/to/shot.png # writes /path/to/shot.py
|
|
333
|
+
codehaven --ocr /path/to/shot.png --out ~/code/area.py # choose the file to write
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
The command prints the lines to check and never replaces a file: if the target exists, it stops and asks for another name with `--out`.
|
|
337
|
+
|
|
338
|
+
What to expect:
|
|
339
|
+
|
|
340
|
+
- **The file name.** `shot.png` becomes `shot.py`. A picture named after its code, such as `cart.js.png`, keeps that name (`cart.js`); only `.py` files get the Python check.
|
|
341
|
+
- **Indentation is kept.** Tesseract returns each word with its position, and CodeHaven rebuilds the leading spaces, the spacing between words, and blank lines from those positions. An editor's line-number column is dropped.
|
|
342
|
+
- **Mistakes happen.** Reading a picture is never perfect: a quote, colon, or look-alike character (`l` and `1`, `O` and `0`) can be wrong, so compare the listed lines before running the code. Two common misreadings are repaired and listed: curly quotes and long dashes become plain ones, and `@` becomes `0`, because coding fonts draw zero with a slash (decorators such as `@property` are left alone).
|
|
343
|
+
- **Best results.** Use a sharp screenshot cropped to the code, light or dark theme. Photos of a screen, small text, and pictures with menus or several columns read poorly. Only English letters and code symbols are read.
|
|
344
|
+
- **Private.** Tesseract runs on this computer on a temporary copy of the picture, which is deleted as soon as it is read. In the browser page the text is kept in the same private temporary folder as any uploaded file and deleted when you open something else. Your picture is never changed.
|
|
345
|
+
|
|
346
|
+
## Long-term memory
|
|
347
|
+
|
|
348
|
+
CodeHaven keeps answers about a repository on this computer and uses them again in later sessions, in the browser page and in the terminal. It is on by default; start with `--no-remember` and nothing is saved to disk:
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
codehaven --gui --no-remember
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
- **What is saved.** Only answers that passed the answer checks and cite lines of code. Unverified answers, and answers about an uploaded file, are never saved.
|
|
355
|
+
- **Where.** One file per repository in `~/CodeHaven/memory` (change it with `--memory-dir`), readable by your user only. Nothing is written inside the repository, and nothing leaves the computer.
|
|
356
|
+
- **When it is used.** A new question brings back at most two saved answers that share its key words, shown to the model as notes from earlier sessions.
|
|
357
|
+
- **When it is dropped.** Each saved answer records a fingerprint of the files it cites. If any of them has changed, the answer is deleted instead of being trusted. Up to 200 answers are kept per repository; the oldest go first.
|
|
358
|
+
- **Forgetting.** Click **Forget this project** under **Settings** in the page's sidebar, or run `codehaven --forget --workspace ~/dev/project`.
|
|
359
|
+
|
|
360
|
+
## Saved chats
|
|
361
|
+
|
|
362
|
+
The browser page keeps your chats about a repository on this computer, so a reloaded page or a restarted server does not lose them. It is on by default, and `--no-remember` saves nothing.
|
|
363
|
+
|
|
364
|
+
- **Where.** One file per repository in `~/CodeHaven/chats` (change it with `--chats-dir`), readable by your user only. Up to 30 chats per repository, 60 questions each; the oldest go first.
|
|
365
|
+
- **Reopening.** Click a chat under **Saved chats**. Follow-up questions remember it the same way as when it was live. A reloaded page still starts a new chat, so follow-ups never use context you cannot see.
|
|
366
|
+
- **Stale code.** A saved chat records what was said, not a checked fact. The code may have changed since, so its citations open the files as they are now.
|
|
367
|
+
- **Deleting.** The × beside a chat deletes it. **Forget this project** under **Settings**, or `codehaven --forget`, deletes all of them along with the saved answers.
|
|
368
|
+
- Chats about an uploaded file are never saved.
|
|
369
|
+
|
|
370
|
+
## Search by meaning
|
|
371
|
+
|
|
372
|
+
Key-word search finds "late fee" only where those words appear. With a local embedding model installed, CodeHaven also compares the meaning of your question with every indexed passage, so "what stops the model from repeating itself?" finds a class named `RepetitionGuard`. The two rankings are mixed, so exact names still win.
|
|
373
|
+
|
|
374
|
+
```sh
|
|
375
|
+
ollama pull nomic-embed-text # once, while online
|
|
376
|
+
codehaven --doctor # prints "Meaning search: nomic-embed-text:latest"
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
- **Local.** The embedding model is a second, small Ollama model on this computer, reached over loopback like the chat model. Nothing leaves the machine. Cloud-backed models are never used.
|
|
380
|
+
- **Automatic.** It is on when an embedding model is installed and off otherwise. `--no-semantic` turns it off, and `--embed-model NAME` picks one; without it, the first installed of `nomic-embed-text`, `embeddinggemma`, `mxbai-embed-large`, `bge-m3`, `snowflake-arctic-embed`, and `all-minilm` is used.
|
|
381
|
+
- **First run.** Every passage is embedded once, at roughly 20 passages a second on a laptop, so a mid-sized project takes under a minute. The command waits up to 60 seconds and the page up to 15; the rest is prepared in the background while you ask questions, which use what is ready.
|
|
382
|
+
- **Saved vectors.** Vectors are kept in `~/CodeHaven/index` (change it with `--index-dir`), one file per repository, readable by your user only, so later runs embed only changed passages. The file holds numbers and hashes, never code text. With `--no-remember` nothing is written and vectors live in memory only.
|
|
383
|
+
- **Saved keyword index.** The keyword index is kept beside the vectors, one `.keywords` file per repository, readable by your user only. It holds each file's size, modification time, and text hash, the word counts of its passages, and its parsed outline (names, line numbers, imports), never a passage's text. Each file is read again and its hash compared, so a changed file is always indexed afresh. `--no-remember` writes nothing, and `--forget` or **Forget this project** deletes it.
|
|
384
|
+
- **Failure is harmless.** If the embedding model stops answering, a one-line note says so and search goes back to key words for the session.
|
|
385
|
+
- **Memory.** A small embedding model (about 300 MB) normally fits beside the chat model. On a machine short of memory Ollama may swap the two, which slows every step; use `--no-semantic` there. See [Local inference speed](#local-inference-speed).
|
|
386
|
+
|
|
387
|
+
The evaluation harness keeps using key-word search alone, so its results stay comparable from run to run.
|
|
388
|
+
|
|
389
|
+
## Ask in Arabic
|
|
390
|
+
|
|
391
|
+
Ask in Arabic and CodeHaven answers in Arabic, in the browser page and in the terminal:
|
|
392
|
+
|
|
393
|
+
```sh
|
|
394
|
+
codehaven --workspace ~/dev/project 'اشرح الدالة `checkout_total`'
|
|
395
|
+
codehaven --workspace ~/dev/project 'ما الذي تغير في آخر commit؟'
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
- **Nothing to switch on.** A question written mostly in Arabic is answered in Arabic. Quoted text, file paths, and code names do not count when the language is decided, so an English question that names an Arabic file stays English.
|
|
399
|
+
- **Citations stay as they are.** File paths, names from the code, and `path:line` citations are kept in Latin letters and Western digits, and are checked the same way as for English.
|
|
400
|
+
- **The same requests work.** Asking in Arabic for your Git changes, a file review, test gaps, or a project tour reaches the same helper as in English.
|
|
401
|
+
- **Spelling variants match.** Short vowels, the forms of alef, a final ى or ة, and Arabic-Indic digits are folded to one spelling, and "ال" and common endings are dropped, so الدوال finds دوال.
|
|
402
|
+
- **Right to left.** The page lays out Arabic questions and answers right to left, while code and citations stay left to right.
|
|
403
|
+
- **The page in Arabic.** The **العربية** button in the top bar shows the whole page in Arabic, laid out right to left, with Arabic suggested questions; **English** switches back. English stays the default, and the choice is remembered in your browser only. In the Arabic page, flashcards are written in Arabic too.
|
|
404
|
+
- **Reports in Arabic.** A file review, the test-gap list, and the project tour asked for in Arabic come back in Arabic, including the sentences CodeHaven writes itself. Error messages from the server and the step log under an answer stay in English.
|
|
405
|
+
- **Finding code.** Code is written in Latin letters, so an Arabic question finds it through the names it mentions, through Arabic comments and documentation in the project, and through [search by meaning](#search-by-meaning) when the embedding model handles Arabic (`bge-m3` does).
|
|
406
|
+
- **Expect less polish.** The default 7B model writes weaker Arabic than English, and the evals measure English questions only. English questions get exactly the same prompts as before.
|
|
407
|
+
|
|
408
|
+
## Use it from the terminal
|
|
409
|
+
|
|
410
|
+
The same assistant works without the browser. Check that Ollama and the model are ready, then ask a question:
|
|
411
|
+
|
|
412
|
+
```sh
|
|
413
|
+
codehaven --doctor
|
|
414
|
+
codehaven --workspace /absolute/path/to/project 'Explain this project'
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
Ask for a change and you get an explanation, not an edit:
|
|
418
|
+
|
|
419
|
+
```sh
|
|
420
|
+
codehaven --workspace /absolute/path/to/project \
|
|
421
|
+
'Fix Store.low_stock so items exactly at the threshold are included'
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
The answer names the lines to change (here `inventory/store.py:27-29`), says what to change them to (`<` becomes `<=`), and leaves your file untouched.
|
|
425
|
+
|
|
426
|
+
For several questions in a row, start an interactive session. Follow-ups remember up to eight earlier questions, the same way as in the browser page, and the index refreshes between questions. A single `codehaven 'question'` command has no memory. Type `/reset` to forget earlier answers and `exit` to quit:
|
|
427
|
+
|
|
428
|
+
```sh
|
|
429
|
+
codehaven --workspace /absolute/path/to/project --interactive
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Typed at a terminal with no question, plain `codehaven` starts the same session in the current folder.
|
|
433
|
+
|
|
434
|
+
To ask across several repositories at once, such as a backend and its frontend, add each extra one with `--also`: `codehaven --workspace ~/dev/api --also ~/dev/web -i`. They are indexed together and paths are shown from their common parent (`api/server.py`, `web/src/client.js`); nothing else under that parent is read. On the page, put the full paths in the folder box separated by `;`.
|
|
435
|
+
|
|
436
|
+
In a session, and in the page's question box, slash commands are short forms of the requests below: `/trace name`, `/review file`, `/why path:line`, `/impact name`, `/explain name`, `/tour`, `/onboard`, `/diagram [name]`, `/deps`, `/scan`, `/gaps`, `/changes`, `/review-changes`, `/commit`, `/pr`, `/export`, and `/undo`. `/help` lists them. The up and down arrows bring back earlier questions.
|
|
437
|
+
|
|
438
|
+
To let the model check something by running it, such as what a function returns for a sample input, add `--allow-python`. The model can then ask to run a short Python snippet (up to 8,000 bytes). CodeHaven prints the code and runs it only if you answer `y`, in the same Docker container as [isolated tests](#run-isolated-project-tests): no network, a read-only copy of the project as its working directory, 30 seconds, and only the packages in the test image. It cannot change your files. Without the flag the action does not exist and the prompts are exactly as before. The browser page does not offer it yet, because it has no way to ask you to approve the code.
|
|
439
|
+
|
|
440
|
+
If something goes wrong that CodeHaven did not expect, it says so in one sentence and the session carries on. Set `CODEHAVEN_DEBUG=1` to also print the full traceback, for a bug report.
|
|
441
|
+
|
|
442
|
+
Answers stream to the terminal as the model writes them; add `--no-stream` to print each answer only once it is complete. `codehaven`, `offline-agent`, and `python -m offline_agent` are the same command (on Windows, use `python -m offline_agent`). Reinstall the package after updating to register the commands.
|
|
443
|
+
|
|
444
|
+
## Use it from VS Code
|
|
445
|
+
|
|
446
|
+
The [VS Code extension](editors/vscode) adds commands to ask about the open folder, explain the file or the selected lines, and trace the function under the cursor. It turns every `path:line` citation in a terminal into a link that opens the cited lines. It runs the `codehaven` command on this computer and holds no model of its own; see [its README](editors/vscode/README.md) to install it. Its logic is tested without VS Code, but it has not yet been tried inside a running VS Code.
|
|
447
|
+
|
|
448
|
+
## Choosing a model
|
|
449
|
+
|
|
450
|
+
`qwen2.5-coder:7b` is the default and the tested model. To use another installed local model, choose it in the browser page or pass `--model`:
|
|
451
|
+
|
|
452
|
+
```sh
|
|
453
|
+
codehaven --model qwen2.5:14b --workspace /path/to/project 'Explain this project'
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Measured on 34 questions about three real libraries (see [docs/EVALS.md](docs/EVALS.md)), with the same code and one run each:
|
|
457
|
+
|
|
458
|
+
| Model | Size on disk | Correct | Verified | Time for 34 questions | Per question |
|
|
459
|
+
|---|---|---|---|---|---|
|
|
460
|
+
| `qwen2.5-coder:7b` (the default) | 4.7 GB | 31/34 (91%) | 21/34 | 1,188 s | 35 s |
|
|
461
|
+
| `qwen2.5:14b` | 9.0 GB | 31/34 (91%) | 28/34 | 2,031 s | 60 s |
|
|
462
|
+
| `llama3` (8B) | 4.7 GB | 25/34 (74%) | 25/34 | 909 s | 27 s |
|
|
463
|
+
| `qwen2.5:0.5b` | 0.4 GB | 13/34 (38%) | 9/34 | 479 s | 14 s |
|
|
464
|
+
|
|
465
|
+
"Correct" means the answer holds the facts; "verified" means every citation in it also points at lines the model was shown. The default gets as many answers right as the 14B model in a little over half the time. The 14B model is the more careful one: use it if you have about 10 GB of memory to spare and would rather wait than re-check a citation. The prompts were tuned on the default, so the others are measured on prompts written for a different model.
|
|
466
|
+
|
|
467
|
+
Names of cloud models (ending in `-cloud` or `:cloud`) are refused, and so are models Ollama reports as remote-backed or embedding-only. With `--gui`, if the default model is not installed, CodeHaven starts with another installed chat model.
|
|
468
|
+
|
|
469
|
+
## Ollama and offline use
|
|
470
|
+
|
|
471
|
+
The [startup script](scripts/start_ollama.py) sets `OLLAMA_NO_CLOUD=1` and binds the server to `127.0.0.1:11434`, following [Ollama's local-only instructions](https://docs.ollama.com/faq). Run it from this repository on macOS, Linux, or Windows (use `python` if that is your Python command). Leave that terminal open; Ctrl+C stops the server. Check its logs for `Ollama cloud disabled: true`.
|
|
472
|
+
|
|
473
|
+
If Ollama is already running, the script checks its local API, prints a friendly message, and exits successfully without launching a second server. It cannot change or verify that server's cloud setting. To enforce `OLLAMA_NO_CLOUD=1`, quit the existing desktop app or stop its service, then run the script again. An unrecognized listener on the port still produces an error. These environment settings apply only to a server launched by the script.
|
|
474
|
+
|
|
475
|
+
After downloading a model, disconnect from the internet to use it offline. Disabling cloud features does not block model downloads or all network traffic. CodeHaven checks that the model is installed and rejects remote-backed and cloud models; a loopback URL alone cannot guarantee how a separately configured server performs inference. Installation downloads LangGraph and its dependencies; runtime does not require internet access. Reading code from a picture runs Tesseract, a separate program installed once; it works offline and makes no network connection.
|
|
476
|
+
|
|
477
|
+
## What v0.14 does
|
|
478
|
+
|
|
479
|
+
Also new in 0.14: CodeHaven can change code when you start it with `--allow-edits`, always after you approve the diff, with undo (see [Change code](#change-code-opt-in)). New answers made by plain code: libraries, a security and secrets scan, what a change would break, why a line is there (git blame), an onboarding guide, Mermaid diagrams, and a one-file project report. It explains a pasted stack trace, reviews only the functions your changes touched, writes commit messages and PR descriptions, saves answers as Markdown, asks across several repositories (`--also`), takes slash commands (`/help`), and parses C, C++, C#, Ruby, PHP, Kotlin, and Swift. An answer that fails its checks is sent back to the model once. `codehaven --setup` gets a new computer ready, and the VS Code extension has a chat panel.
|
|
480
|
+
|
|
481
|
+
New in 0.14: faster on large projects and clearer when something goes wrong. The keyword index is saved between runs, so a large repository reopens in about a quarter of the time (FastAPI, 2,400 files: 8.5 s on 0.13, 2.0 s), and after you edit a file only that file is indexed again (8.5 s to 2.8 s). Listing, searching, and checking for changed files are two to three times faster. An answer whose cited lines use code that is not in the repository, such as a library or a file that was never checked in, says so under its own heading. When preloaded files leave too little room in the prompt, the reference excerpts are retrieved again to fit, instead of being gathered and then compacted away. Plain `codehaven` at a terminal starts an interactive session with arrow-key history. An unexpected problem is explained in a sentence in the terminal and on the page, never as a traceback or a bare "Failed to fetch".
|
|
482
|
+
|
|
483
|
+
New in 0.13: looks for each value an answer reports (a quoted string or a number) in the code the model was shown. A value on the lines the answer cites needs nothing; a value shown on another line gets a citation of that line; a value on no shown line was not read from the code, and the answer is marked **Unverified**. On the seven real repositories this flags two wrong answers the citation checks passed, including an OpenAPI version of `3.0.2` (it is `3.1.0`), and one correct answer whose quoted code the model made up. No correct answer was lost. See [the eval results](docs/EVALS.md).
|
|
484
|
+
|
|
485
|
+
New in 0.12: searches for quoted settings and dotted names a question mentions, so an answer that is one line somewhere in the project is found; checks citations against every line the model was shown, and cites the code names an uncited answer mentions; sees project files of up to 1 MB, where files over 64 KB, often a project's central modules, were invisible before; stops indexing and downloads from the page; and is measured on a fourth, much larger repository. On the real repositories nearly every correct answer now passes the answer checks (39 of 41, from 26 of 40). The checks confirm that an answer cites lines the model was shown, not that it read them right, so read **Unverified** as "a citation does not hold" and a checked answer as "quick to check at the cited lines". See [the eval results](docs/EVALS.md).
|
|
486
|
+
|
|
487
|
+
New in 0.11: shows the model the definitions a question names, with the constants they use, before it answers; traces a function's calls and callers; stops an answer in progress; indexes projects of up to 5,000 files and keeps the index while nothing changes; parses Go, Java, and Rust with Tree-sitter; starts Ollama for a run and says what is missing; saves chats and flashcards; adds a VS Code extension; and is tested on macOS, Windows, and Linux, with evals on three real repositories.
|
|
488
|
+
|
|
489
|
+
New in 0.10: explains Git changes, reviews a file one function at a time, lists functions with no tests, suggests a reading order, reads notebooks and PDFs, saves chats, searches by meaning with a local embedding model, and follows Go, Java, and Rust imports.
|
|
490
|
+
|
|
491
|
+
- Never changes files. The only actions are `read`, `search`, `retrieve`, `run_tests`, and `finish`, and the workspace layer has no write method. The one file CodeHaven writes for you is the new file `--ocr` makes from a picture, and it refuses to replace an existing file.
|
|
492
|
+
- Lists up to 5,000 visible project files and lets the model read selected UTF-8 files.
|
|
493
|
+
- Reads long files in pages. Content such as `120-180` asks for a line range. A read that would not fit in half the prompt budget returns whole lines up to that size and names the next range to request, so evidence is never silently truncated.
|
|
494
|
+
- Preloads up to two files that your task names, such as `explain chapter-06/gateway/app/main.py`, with line numbers for citing. The model starts with the file's lines instead of spending steps finding and reading it, and those lines count as evidence for citations. A file too long to fit shows its start, its end, and the lines around any code-like name in the task, such as `SKU-0042`, because the answer is often not on the first page. A plain file name like `store.py` counts only if exactly one file has that name. Hidden and excluded files are never preloaded.
|
|
495
|
+
- Searches the project for code names in a question, such as `apply_discount` or `applyCoupon`, before the model's first step, and shows each match with the function it is in. Left alone, the model often answered "who calls X?" from the definition without searching.
|
|
496
|
+
- Also searches for a question's quoted settings and dotted names, because their answer is often one line somewhere in the project: `'trust proxy'` finds `this.set('trust proxy', false)`, and `express.static` finds `exports.static = require('serve-static')`. A dotted name is searched as an assignment (`.static =`) and as a quoted key (`'static'`). Only matches in source files are shown for these, source files are listed before tests and docs for code names too, and keyword retrieval, which brings examples and documentation first, is no longer the only way in.
|
|
497
|
+
- Adds citations to an answer that has none, for the code names it mentions, taken from lines the model was actually shown and listed under their own heading. The model often writes a correct sentence about `checkout_total` without citing it. A name that appears on no shown line adds nothing, so nothing is made up, and a citation the model wrote itself is still checked as before.
|
|
498
|
+
- Shows the model the code a question names before its first step. A function, method, or class that the question names in backticks, with a dot (`Response.ok`, `app.listen`), an underscore, camelCase, or as a capitalised class name is looked up in the parsed code, and its lines are put in the prompt with their numbers. A definition too long to show whole, usually a class, is shown as its start, its end, and the lines around the question's own words. Under it come the values of the constants those lines use (`DEFAULT_POOLSIZE = 10`, from whichever file sets it) and, for a class, the classes that inherit from it. On real repositories the model answers from what it is shown at its first step, and without these lines it guessed. Plain English words are never looked up.
|
|
499
|
+
- Cites a line the model was shown when it names the right thing in the wrong place, such as the file that imports a constant instead of the file that sets it. The answer is then checkable instead of being marked unverified.
|
|
500
|
+
- Answers questions and change requests in a stricter format: an answer plus up to 10 points. Each point names a part of the code: a function, class, `Class.method`, variable, route such as `/health`, `imports`, a whole file, or a line such as a table row. CodeHaven finds that part's real lines and prints `path:start-end` from them, because small models describe code well but make up line numbers. Python files are parsed, never run; other names match the first line that mentions them. A point naming a file beside the wrong folder is matched to the one file with that name. A range is narrowed to the lines the model actually saw. A name that cannot be found is shown as not found and flagged. Explaining a named file limits the overview to a short paragraph.
|
|
501
|
+
- Search results name the enclosing function or class of each match and mark definitions.
|
|
502
|
+
- Draws a structure map of one file (its parts and which call which) or of several files (which imports which) by parsing the code, without the model.
|
|
503
|
+
- Writes flashcards about chosen files with the local model, and looks up the lines each answer is about instead of trusting the model's numbers.
|
|
504
|
+
- Reads the code in a PNG or JPEG picture into a new file with Tesseract on this computer, rebuilding indentation and listing the lines to check.
|
|
505
|
+
- Remembers checked, cited answers per repository between sessions, and deletes a saved answer as soon as a file it cites changes.
|
|
506
|
+
- Runs unittest or pytest in isolated Docker containers after approval, with networking disabled, read-only project snapshots, a 30-second timeout, and bounded output. Tests cannot change your project.
|
|
507
|
+
- Keeps long tasks within the prompt budget by first replacing older tool results and file contents with one-line stubs, oldest first, such as `Tool result for read big.py … [Older result compacted: 9,412 bytes omitted]`. Older messages are dropped only if that is not enough.
|
|
508
|
+
- Lists, searches, indexes, and reads project files of up to 1 MB, in pages of at most 64 KB, and limits tasks to 12 steps by default (maximum 30). Large projects keep their central modules in big files: FastAPI's `routing.py` is 176 KB.
|
|
509
|
+
- Rejects traversal, hidden paths, and symlinks.
|
|
510
|
+
- Connects only to numeric HTTP loopback endpoints, with proxies and redirects disabled.
|
|
511
|
+
|
|
512
|
+
Use `--endpoint http://127.0.0.1:11434` for a different local port and `--max-steps 20` for longer tasks. Exit codes: 0 finished/doctor passed, 1 error, 2 step limit or unverified answer, 130 interrupted. A checked answer is not proof that the explanation is right; read the cited lines.
|
|
513
|
+
|
|
514
|
+
## File exclusions
|
|
515
|
+
|
|
516
|
+
File listing, search, RAG indexing, dependency retrieval, and direct reads respect root and nested `.gitignore` / `.agentignore` rules. Add persistent agent-only rules to `.agentignore`, or pass extra patterns:
|
|
517
|
+
|
|
518
|
+
```sh
|
|
519
|
+
codehaven --workspace /path/to/repo \
|
|
520
|
+
--exclude 'private/**' --exclude '*.pem' 'Explain this project'
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
Hidden/built-in paths stay blocked. User exclusions add restrictions; they cannot undo Git ignores. Rules apply to tracked files too. [Exclusion details](docs/EXCLUSIONS.md) cover precedence, negation, root scope, and reference libraries.
|
|
524
|
+
|
|
525
|
+
## Change code (opt-in)
|
|
526
|
+
|
|
527
|
+
CodeHaven answers a change request by explaining the change, unless you start it with `--allow-edits` (in the terminal, or with `--gui`). Then it can make the change, always after showing you the diff: in the terminal you answer `y` or `n`, and on the page you click **Apply** or **Decline** under the diff. **Undo last change** in the page's sidebar does the same as `/undo`.
|
|
528
|
+
|
|
529
|
+
| You ask | What happens |
|
|
530
|
+
|---|---|
|
|
531
|
+
| "Fix `low_stock` in store.py so items at the threshold count" | The model proposes exact replacements; you see the diff and answer `y` or `n` |
|
|
532
|
+
| "Fix the code until the tests pass" | The tests run in the Docker sandbox; a failure goes back to the model, up to 3 rounds, each diff approved by you |
|
|
533
|
+
| "Write tests for `low_stock`" | New tests in a new or existing test file, in the style of your other tests |
|
|
534
|
+
| "Add docstrings to store.py" | Docstrings for the functions and classes that have none, and no other change |
|
|
535
|
+
| "Rename `low_stock` to `below_threshold`" | Done by plain code, not the model: whole-word replacement in every code file that uses the name |
|
|
536
|
+
| "Write a README" / "Write architecture notes" | Written from the project tour and the libraries list |
|
|
537
|
+
| "Apply the review findings in store.py" | The file is reviewed function by function, and the model fixes what the review found |
|
|
538
|
+
|
|
539
|
+
An edit must copy the text it replaces exactly, and that text must occur once, in a file CodeHaven may read: hidden, excluded, linked, and outside files are never changed. A file that changed while you were reading the diff is not overwritten. Every applied change is recorded outside the repository, in `~/CodeHaven/undo`, so `/undo` in a session, or `codehaven --undo`, puts the files back, unless you changed them again since. Everything stays offline.
|
|
540
|
+
|
|
541
|
+
## Code that is not in the repository
|
|
542
|
+
|
|
543
|
+
When the lines an answer cites use code the repository does not hold, the answer says so under the heading "Code these lines use that is not in this repository". It lists each import: a library, such as `requests` or `jsonwebtoken`, or a relative import of a file that is not there, with the line that imports it. Only imports whose name appears on the cited lines are listed, and Python's standard library and Node's built-in modules are left out, because the model already knows them. Imports are found by parsing Python, JavaScript, and TypeScript; nothing is run. The note is not a citation, so it never makes an answer unverified; it tells you where the answer stops being able to show you the code.
|
|
544
|
+
|
|
545
|
+
## Local reference knowledge base (RAG)
|
|
546
|
+
|
|
547
|
+
The repository selected by `--workspace` is automatically indexed for RAG. CodeHaven retrieves relevant source code, README/documentation, and common configuration/build files before answering, with citations such as `repo/src/orders.py:1-25`. No separate indexing command is needed. For Python and JavaScript/TypeScript, retrieval also follows local imports up to two hops and adds relevant dependency passages, even when they do not match the question keywords.
|
|
548
|
+
|
|
549
|
+
```sh
|
|
550
|
+
codehaven --workspace /path/to/repo 'Explain how order validation works'
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
**You can also add your own reference documents.** Put `.md`, `.txt`, or `.rst` files in your project's `knowledge/` folder, or use `--knowledge-base /path/to/references`. Bundled LangGraph documentation notes cover graph construction, checkpointing, and approval interrupts, with official source links. They are available to RAG automatically, offline, and are project-authored notes rather than the complete official manual. Reference folders inside the workspace must be allowed by its ignore rules. If `knowledge/` is ignored (as in this repository), use an external reference library instead.
|
|
554
|
+
|
|
555
|
+
```sh
|
|
556
|
+
codehaven --workspace /path/to/project --knowledge-base /path/to/references \
|
|
557
|
+
'Use my references to explain LangGraph conditional edges'
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
The model can call `retrieve` for more passages, with source and line citations. Indexing and retrieval run entirely on your device using BM25 keyword ranking. No vector database, embeddings, extra model, or internet access is needed. Startup reports the repository-file count and warns if index limits were reached. The index is built at the start of each run. Between questions in a session CodeHaven lists the files again and rebuilds the index only if a file was added, removed, or changed, so edits you make yourself are picked up and an unchanged project costs almost nothing. A project at the 5,000-file limit takes about 8 seconds to index and about 1 second to check. For a larger project, open the subfolder you are working in. See [how to add manuals and your own references](docs/KNOWLEDGE_BASE.md) for supported formats, limits, and examples.
|
|
561
|
+
|
|
562
|
+
## Dependency-aware retrieval and complete functions
|
|
563
|
+
|
|
564
|
+
If `orders.py` imports a helper from `pricing.py`, retrieval can include the pricing definition too. Python AST and local Tree-sitter JavaScript/TypeScript parsers analyze code without executing it. Supported JS/TS imports include relative ES imports, re-exports, literal `require()`, directory `index` files, and common `.js` specifiers pointing to `.ts` source. Package imports, computed/dynamic paths, and tsconfig/bundler aliases remain unresolved.
|
|
565
|
+
|
|
566
|
+
Retrieval prefers complete parsed functions, methods, classes, and supported TS declarations when they fit. Results mark `symbol_complete: true` for full symbols or `false` when falling back to a partial excerpt. A symbol also carries the values of up to three module constants it uses, such as `MAX_GUESTS = 4`, because the answer is often the value rather than the name. Retrieval considers different files before repeatedly selecting chunks from one file, reserves space for dependencies, and skips candidates that cannot fit instead of ending retrieval immediately.
|
|
567
|
+
|
|
568
|
+
Words are reduced to simple stems and identifiers are split at underscores and camelCase, so "restocking" finds `restock` and "apply discount" finds both `applyDiscount` and `apply_discount`. The bundled LangGraph notes are left out of results when a question does not mention LangGraph and the project has matches of its own.
|
|
569
|
+
|
|
570
|
+
Up to four keyword matches and four dependency passages share a configurable UTF-8 JSON budget (CLI default 4,000 bytes). For example:
|
|
571
|
+
|
|
572
|
+
```sh
|
|
573
|
+
codehaven --workspace /path/to/repo --retrieval-budget 8000 \
|
|
574
|
+
'Explain checkout_total and its imported helpers'
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
`--retrieval-budget` accepts 2,000–16,000 bytes. It controls retrieved context only; it does not measure model tokens or cap accumulated conversation history. Imports are followed up to two hops over already indexed files. See [retrieval details](docs/KNOWLEDGE_BASE.md#retrieval-budgets-and-complete-symbols) for metadata and limitations.
|
|
578
|
+
|
|
579
|
+
## Local inference speed
|
|
580
|
+
|
|
581
|
+
**Check this first if every step takes a minute or more.** Ollama unloads a model when another one needs the memory. If another program is using a different model at the same time and both do not fit, Ollama swaps them on every request, and most of each step goes to reloading. This has been measured at 35–113 seconds of loading per step on a 24 GB machine. CodeHaven warns at startup when another model is loaded, and warns during a run when a later step had to reload. Check with `ollama ps`, and stop the other program for much faster runs.
|
|
582
|
+
|
|
583
|
+
Model requests wait up to 10 minutes for a response, so a slow reload does not fail the task.
|
|
584
|
+
|
|
585
|
+
CodeHaven sends a task-ranked sample of at most 40 paths / 2,000 bytes instead of the entire file list. Ollama requests keep the model loaded for 30 minutes and preserve the conversation prefix until compaction is necessary, allowing server prompt-cache reuse when available. The keyword index is kept on disk, so a repository reopens quickly (see [Search by meaning](#search-by-meaning) for what it holds), and only sessions (`--interactive` or the browser page) carry recent answers between questions. Another client or model unloading can prevent reuse.
|
|
586
|
+
|
|
587
|
+
`--prompt-budget` bounds message content plus a small per-message allowance (default 12,000 UTF-8 bytes). Older evidence is omitted when necessary; oversized recent evidence is marked incomplete. System rules and the original task stay. This is a byte budget, not an exact token count. Full graph history stays in RAM. Requests reserve a context window of at least 8,192 tokens, increasing with the configured budgets; larger settings consume more memory and may run slower.
|
|
588
|
+
|
|
589
|
+
Responses are limited to 1,024 tokens per action. A response stopped by that limit is rejected before any action is executed. For longer answers, raise the limits:
|
|
590
|
+
|
|
591
|
+
```sh
|
|
592
|
+
codehaven --max-output-tokens 4096 --prompt-budget 24000 \
|
|
593
|
+
--workspace /path/to/project 'Explain the whole request pipeline'
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
Output limits accept 256–8,192 tokens; prompt budgets accept 8,000–64,000 bytes. Small tasks with the defaults should require less prompt processing, but performance still depends on hardware, context, and Ollama. No fixed speed improvement is guaranteed.
|
|
597
|
+
|
|
598
|
+
Progress lines such as `Step 1 (max 12): read inventory/store.py` show the actual action and target alongside the model's narration. An identical repeated action is skipped and triggers one finish-only recovery call, within the action limit. If the model ignores recovery, the run stops with exit code 2. A step-limit exit also means the task is incomplete; intermediate tool narration is not a final answer. This guard catches repeated lookup requests, not every possible reasoning loop or incorrect answer.
|
|
599
|
+
|
|
600
|
+
The final call in `--max-steps` is reserved for an answer: a four-step run permits up to three tool actions and one final response. The final response must summarize available evidence and disclose gaps. With `--max-steps 1`, no tools can run. If the model ignores the finish-only schema, the run exits incomplete without executing its proposed tool. This reserves time to answer; it cannot guarantee that the model's answer is correct or complete.
|
|
601
|
+
|
|
602
|
+
Search, read, and retrieved evidence is retained with paths, line ranges, short snippets, and heuristic labels (`service`, `test`, `stub`, `reference`, `source`). The bounded list holds up to 50 records / 4,000 bytes. When space runs low, snippets go first; then each file's records are merged into continuous line ranges, which keeps every observed line covered; only then are the oldest records dropped, because an answer usually cites the newest evidence. It is supplied again on the final reserved call, so older discoveries survive conversation trimming. Classification is a hint, not a deployment guarantee.
|
|
603
|
+
|
|
604
|
+
Explicit requests to find/list/identify FastAPI entry points use a local discovery node: search broadly for the exact literal `FastAPI(`, classify matches, then request one cited summary. It scans eligible files beyond the RAG document limit, within the search tool's bounds, and avoids a model-driven read of every match. Other tasks keep the normal tool workflow. This first planner does not detect aliased constructors, application factories without this literal, or other frameworks. It never proves that every entry point has been found.
|
|
605
|
+
|
|
606
|
+
Final-answer checks require observed path:line citations for questions and change requests when evidence exists, reject citation ranges that include a line the model was never shown (a range may span two adjacent passages), and flag a singular-entry-point claim when multiple service candidates were found. Planned discovery also checks that each retained service candidate has a supported citation. Answers with detected gaps are displayed as **unverified** and exit with code 2. These are bounded syntax and coverage checks, not semantic verification of every claim; evidence can be partial. Final answers print once, without duplicating progress narration.
|
|
607
|
+
|
|
608
|
+
Discovery summaries use a short dedicated prompt and a bounded response schema. Checks also flag repeated substantial lines and test/stub paths listed under a conflicting recognized heading. If a discovery summary fails checks, it is withheld and replaced with the classified source inventory plus the specific warnings. The raw model reply remains in run state; the source inventory does not silently turn a rejected model summary into a verified answer.
|
|
609
|
+
|
|
610
|
+
After each model response, CodeHaven shows the timing fields Ollama supplies: model loading, prompt evaluation, generation and total seconds, prompt/generated token counts, and generation tokens per second. `cached_tokens` is a reported count when present, or `null` when Ollama does not report it. Missing cache metrics never imply a cache hit. Timings are per request, not an end-to-end task benchmark. See the [Ollama response fields](https://docs.ollama.com/api/chat).
|
|
611
|
+
|
|
612
|
+
## Search file contents
|
|
613
|
+
|
|
614
|
+
```sh
|
|
615
|
+
codehaven --workspace /absolute/path/to/project 'Search for validate_order and explain where it is used'
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
The model can call `search` with the literal query in `content` and an optional relative file or directory in `path`. An empty path searches the workspace. Search needs no approval. Matching is case-sensitive, single-line, and literal (no regex); queries must be nonblank and at most 256 characters.
|
|
619
|
+
|
|
620
|
+
Results contain relative paths, 1-based line numbers, up to 320 characters of text around the first match on each matching line, and the function or class each match is in. Search returns at most 50 matching lines and 16,000 bytes of JSON. It considers up to 5,000 eligible files per scope and skips hidden/excluded paths, symlinks, files over 1 MB, binary data, unreadable files, and invalid UTF-8. Narrow the scope when a limit is reported. `files_searched` and `files_skipped` describe attempted candidates; `limit_reached` and `candidate_limit_reached` flag potentially incomplete results. A no-match result only describes the files actually searched. Search uses the same ignore and exclusion policy as file listing and RAG. The terminal shows a short summary (counts, limits, and up to 20 `path:line` matches); the model always receives the full JSON.
|
|
621
|
+
|
|
622
|
+
Search results also report the exact `query`, `scope`, and `literal: true`. Queries are source text, not filename filters: searching for `FastAPI(` finds constructors; `FastAPI(.py` searches for those exact characters and will usually find nothing. File extensions and globs must not be appended to the query.
|
|
623
|
+
|
|
624
|
+
## Run isolated project tests
|
|
625
|
+
|
|
626
|
+
Start a local Docker Linux-container runtime and prepare the image once while online:
|
|
627
|
+
|
|
628
|
+
```sh
|
|
629
|
+
docker build -t offline-agent-tests:0.7.0 sandbox
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
Then request either unittest (the default) or pytest:
|
|
633
|
+
|
|
634
|
+
```sh
|
|
635
|
+
codehaven --workspace /path/to/project --test-runner pytest \
|
|
636
|
+
'Run tests and explain failures'
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
CodeHaven asks for approval before each run. Tests receive a filtered, read-only project copy, disabled networking, and a writable temporary area. They cannot change the original project through the mounted filesystem. Host environment variables and the Docker socket are not exposed. Time/resource/output limits and forced container cleanup apply.
|
|
640
|
+
|
|
641
|
+
**No host fallback:** Docker and a prepared local image are required. CodeHaven never pulls images or installs packages during a test run. For project dependencies, prepare an image and select `--test-image my-project-tests:local`. See [isolated test setup and limits](docs/ISOLATED_TESTS.md).
|
|
642
|
+
|
|
643
|
+
## Current limits
|
|
644
|
+
|
|
645
|
+
CodeHaven is read-only, but its file tools are not an OS sandbox: they rely on path checks, which are not hardened against hostile filesystem races. Avoid moving files or directories around while it runs. It runs only the fixed test commands described above and cannot accept arbitrary commands or install dependencies.
|
|
646
|
+
|
|
647
|
+
Hidden files are skipped, but visible files can still contain secrets. Only point CodeHaven at projects you intend to expose to your local model. Conversation context accumulates within a task. Compaction keeps it within `--prompt-budget`, but stubbed results must be read again if the model needs them. Sessions remember up to eight recent questions, with older answers reduced to their first sentence, and the cited locations found so far. Between sessions, only long-term memory's saved answers are kept on disk, and `--no-remember` turns that off (see Long-term memory). Model prose is untrusted and may make unsupported claims, so read the cited lines.
|
|
648
|
+
|
|
649
|
+
## Development
|
|
650
|
+
|
|
651
|
+
```sh
|
|
652
|
+
python3 -m unittest discover -s tests -v
|
|
653
|
+
python3 -m compileall -q offline_agent tests
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
Tests include a simulated agent workflow, a real loopback HTTP fixture, and the browser page's server, without downloading a model. With the dev extras installed (`python -m pip install -e '.[dev]'`), `tests/test_browser.py` also drives the page in your installed Google Chrome with Playwright: it opens a repository, asks a question, follows a citation, and checks that the page shows no script errors. It downloads no browser and is skipped when Playwright or Chrome is missing.
|
|
657
|
+
|
|
658
|
+
### Evaluate the local model
|
|
659
|
+
|
|
660
|
+
To measure whether a prompt or tool change actually helps the model, run the fixed eval tasks against your local Ollama:
|
|
661
|
+
|
|
662
|
+
```sh
|
|
663
|
+
python3 -m offline_agent.evaluation
|
|
664
|
+
python3 -m offline_agent.evaluation --only low-stock-bug --only last-product
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
To check that a change is not fitted to those tasks, also run the [second set](evals/bookings_tasks.json) over a [different small repository](evals/bookings_repo). Results are recorded in [the plan](docs/PLAN.md):
|
|
668
|
+
|
|
669
|
+
```sh
|
|
670
|
+
python3 -m offline_agent.evaluation --tasks evals/bookings_tasks.json --repo evals/bookings_repo
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
[evals/tasks.json](evals/tasks.json) holds 12 questions over the small [sample repository](evals/sample_repo), including a paged read of a 600-line file, entry-point discovery, and explaining a bug and its fix. Every task is a question checked by regexes on the answer; three tasks also ask follow-up questions in the same session ("What tax rate does *that function* add?"), each checked on its own answer, to test the follow-up memory. Each task runs on a fresh temporary copy with test runs declined, and **a task fails if any file in the copy changed**, so the evals also check that CodeHaven stays read-only. The run prints a table of pass/fail, exit code, steps, tokens, and time, and writes the full report, including each task's run log, raw model replies, and changed files, to `evals/results/latest.json`, which Git ignores. The summary separately counts tasks that also passed CodeHaven's own answer checks (exit code 0), and warns if model reloads made the timings unrepresentative. Use `--model` to score another installed model. Like normal use, evaluation talks only to loopback Ollama. Compare reports before and after a change. Results vary between runs, so look at trends rather than one pass or fail.
|
|
674
|
+
|
|
675
|
+
See [the implementation plan and roadmap](docs/PLAN.md) for architecture, acceptance criteria, and next steps. API integration follows [Ollama chat](https://docs.ollama.com/api/chat) and [structured outputs](https://docs.ollama.com/capabilities/structured-outputs).
|
|
676
|
+
|
|
677
|
+
**Real repositories.** Six more question sets run on real open-source libraries, each pinned to one release: requests, click, and express, and a held-out group of flask, cobra, and axios whose questions were written before any change was tried on them. They are not kept in this repository, so download them once, while online:
|
|
678
|
+
|
|
679
|
+
```sh
|
|
680
|
+
python3 scripts/fetch_eval_repos.py
|
|
681
|
+
python3 -m offline_agent.evaluation --suite requests
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
The script is a developer tool and the only eval step that uses the internet; the installed package never runs it. Scores for every set, and what they do not measure, are recorded in [docs/EVALS.md](docs/EVALS.md).
|
|
685
|
+
|
|
686
|
+
Automated tests use fake model responses and a loopback HTTP fixture, so they do not establish answer quality. The local evals measure the real model on short questions with one right answer; they do not establish quality on whole-project explanations or on large monorepos.
|