codehaven 0.14.1__tar.gz → 0.15.0__tar.gz
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.1 → codehaven-0.15.0}/PKG-INFO +39 -30
- {codehaven-0.14.1 → codehaven-0.15.0}/README.md +38 -29
- {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/PKG-INFO +39 -30
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/__init__.py +1 -1
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/documents.py +70 -8
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui.js +5 -3
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui.py +5 -3
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui_arabic.js +2 -2
- {codehaven-0.14.1 → codehaven-0.15.0}/pyproject.toml +1 -1
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_documents.py +37 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/LICENSE +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/SOURCES.txt +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/dependency_links.txt +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/entry_points.txt +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/requires.txt +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/top_level.txt +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/__main__.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/agent.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/answers.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/arabic.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/changes.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/chats.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/cli.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/coder.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/dependencies.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/doctor.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/edits.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/errors.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/evaluation.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/evidence.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/exclusions.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/export.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui.css +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui.html +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/guides.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/history.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/index_cache.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/insights.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/javascript.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/knowledge.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/languages.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/memory.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/messages.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/model.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/more_languages.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/ocr.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/prompts.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/references/langgraph-approvals.md +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/references/langgraph-checkpoints.md +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/references/langgraph-graphs.md +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/references/langgraph.md +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/review.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/scans.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/semantic.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/slash.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/study.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/symbols.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/tasks.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/test_runner.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/trace.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/tracebacks.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/workspace.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/setup.cfg +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_agent.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_arabic.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_browser.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_changes.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_chats.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_citations.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_comments.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_dependencies.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_doctor.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_edit_and_paging.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_edits.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_evaluation.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_evidence.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_exclusions.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_export.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_graph.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_gui.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_guides.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_harness.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_history.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_index_speed.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_insights.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_knowledge.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_languages.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_memory.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_more_languages.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_ocr.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_phrases.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_presentation.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_prompt_budget.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_readme.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_real_evals.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_repository_rag.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_retrieval_upgrade.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_review.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_run_python.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_sandbox_integration.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_sandbox_unit.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_scans.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_search.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_semantic.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_setup.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_several_repos.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_slash.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_start_ollama.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_stop.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_study.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_symbols.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_test_runner.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_trace.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_tracebacks.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_tracing.py +0 -0
- {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_wording.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codehaven
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.0
|
|
4
4
|
Summary: CodeHaven: a read-only, offline assistant for understanding code. Your code. Your machine. No API fees.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/Walid-Ahmed/codehaven
|
|
@@ -96,47 +96,56 @@ In the browser page you can also draw a **structure map** of your files, make **
|
|
|
96
96
|
|
|
97
97
|
## Get started
|
|
98
98
|
|
|
99
|
-
You need Python 3.10+ and [Ollama](https://ollama.com/). While you are online, do this once:
|
|
99
|
+
You need Python 3.10+ and [Ollama](https://ollama.com/). While you are online, do this once, in any folder:
|
|
100
100
|
|
|
101
101
|
```sh
|
|
102
|
-
# 1.
|
|
103
|
-
python3
|
|
102
|
+
# 1. Install CodeHaven in a virtual environment
|
|
103
|
+
python3 -m venv ~/.codehaven-venv
|
|
104
|
+
source ~/.codehaven-venv/bin/activate # Windows PowerShell: ~\.codehaven-venv\Scripts\Activate.ps1
|
|
105
|
+
python -m pip install codehaven
|
|
104
106
|
|
|
105
|
-
# 2.
|
|
106
|
-
|
|
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 .
|
|
107
|
+
# 2. Start Ollama if needed, pick a model for this computer's memory, and download it (asks first)
|
|
108
|
+
codehaven --setup
|
|
109
|
+
```
|
|
112
110
|
|
|
113
|
-
|
|
114
|
-
brew install tesseract # Ubuntu or Debian: sudo apt install tesseract-ocr
|
|
111
|
+
`codehaven --setup` starts Ollama if it is not running, 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. With [pipx](https://pipx.pypa.io/), `pipx install codehaven` replaces step 1 and puts the `codehaven` command on your path without a virtual environment.
|
|
115
112
|
|
|
116
|
-
|
|
117
|
-
ollama pull nomic-embed-text
|
|
113
|
+
After that, everything works offline. Each time, activate the environment and open the browser page:
|
|
118
114
|
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
```sh
|
|
116
|
+
source ~/.codehaven-venv/bin/activate
|
|
117
|
+
codehaven --gui --start-ollama
|
|
121
118
|
```
|
|
122
119
|
|
|
123
|
-
|
|
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.
|
|
120
|
+
`--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. If Ollama is already running, for example the desktop app, CodeHaven uses it as it is. 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.
|
|
126
121
|
|
|
127
|
-
|
|
122
|
+
**Optional extras**, each only if you want the feature. None of them needs a particular folder. Run the `pip` line with CodeHaven's environment activated, so `pypdf` goes where CodeHaven can use it; `brew`, `apt`, and `ollama` install for the whole computer.
|
|
128
123
|
|
|
129
124
|
```sh
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
# Read code from pictures and scanned PDFs: Tesseract, a separate local program (not an Ollama model)
|
|
126
|
+
brew install tesseract # Ubuntu or Debian: sudo apt install tesseract-ocr
|
|
127
|
+
|
|
128
|
+
# Search by meaning: a local embedding model
|
|
129
|
+
ollama pull nomic-embed-text
|
|
130
|
+
|
|
131
|
+
# Chat about PDFs: a PDF reader
|
|
132
|
+
python -m pip install pypdf # with the environment activated; or: brew install poppler
|
|
133
|
+
# Scanned PDFs need both Poppler and Tesseract: brew install poppler tesseract
|
|
132
134
|
```
|
|
133
135
|
|
|
134
|
-
|
|
136
|
+
Tesseract is needed only for [pictures of code](#read-code-from-a-picture). 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.
|
|
135
137
|
|
|
136
|
-
**
|
|
138
|
+
**From a clone of this repository**, for working on CodeHaven itself, run these from the repository's own folder, because the paths are relative to it:
|
|
137
139
|
|
|
138
140
|
```sh
|
|
139
|
-
|
|
141
|
+
git clone https://github.com/Walid-Ahmed/codehaven.git
|
|
142
|
+
cd codehaven
|
|
143
|
+
python3 scripts/start_ollama.py # leave this terminal open; Ctrl+C stops the server
|
|
144
|
+
# in another terminal, in the same folder:
|
|
145
|
+
python3 -m venv .venv
|
|
146
|
+
source .venv/bin/activate
|
|
147
|
+
python -m pip install -e .
|
|
148
|
+
ollama pull qwen2.5-coder:7b
|
|
140
149
|
```
|
|
141
150
|
|
|
142
151
|
## How it is built
|
|
@@ -219,7 +228,7 @@ Implementation follows the [LangGraph graph API](https://docs.langchain.com/oss/
|
|
|
219
228
|
**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
229
|
**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
230
|
**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
|
|
231
|
+
**Or upload a notebook or a PDF.** The same button and drop area take a Jupyter notebook (`.ipynb`) or a PDF, up to 200 MB. See [Notebooks and PDFs](#notebooks-and-pdfs).
|
|
223
232
|
**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
233
|
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
234
|
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`".
|
|
@@ -306,10 +315,10 @@ Called from: app/main.py:21 in checkout
|
|
|
306
315
|
|
|
307
316
|
## Notebooks and PDFs
|
|
308
317
|
|
|
309
|
-
Upload, drop, attach, or paste a Jupyter notebook (`.ipynb`) or a PDF, up to
|
|
318
|
+
Upload, drop, attach, or paste a Jupyter notebook (`.ipynb`) or a PDF, up to 200 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
319
|
|
|
311
320
|
- **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:
|
|
321
|
+
- **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, so CodeHaven reads its pages itself: each page is drawn as a picture by Poppler's `pdftoppm` and read by Tesseract, several pages at once, on this computer. A 29-page, 23 MB scan takes about 20 seconds. This needs Poppler and Tesseract (`brew install poppler tesseract`; Ubuntu or Debian: `sudo apt install poppler-utils tesseract-ocr`); without them, CodeHaven says how to get them.
|
|
313
322
|
- **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
323
|
|
|
315
324
|
## Read code from a picture
|
|
@@ -468,7 +477,7 @@ Names of cloud models (ending in `-cloud` or `:cloud`) are refused, and so are m
|
|
|
468
477
|
|
|
469
478
|
## Ollama and offline use
|
|
470
479
|
|
|
471
|
-
The [startup script](https://github.com/Walid-Ahmed/codehaven/blob/main/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).
|
|
480
|
+
The [startup script](https://github.com/Walid-Ahmed/codehaven/blob/main/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). It is in the repository, not in the installed package, so run it from the root of a clone, on macOS, Linux, or Windows (use `python` if that is your Python command). With an installed `codehaven`, `codehaven --start-ollama` does the same for one run. Leave that terminal open; Ctrl+C stops the server. Check its logs for `Ollama cloud disabled: true`.
|
|
472
481
|
|
|
473
482
|
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
483
|
|
|
@@ -57,47 +57,56 @@ In the browser page you can also draw a **structure map** of your files, make **
|
|
|
57
57
|
|
|
58
58
|
## Get started
|
|
59
59
|
|
|
60
|
-
You need Python 3.10+ and [Ollama](https://ollama.com/). While you are online, do this once:
|
|
60
|
+
You need Python 3.10+ and [Ollama](https://ollama.com/). While you are online, do this once, in any folder:
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
|
-
# 1.
|
|
64
|
-
python3
|
|
63
|
+
# 1. Install CodeHaven in a virtual environment
|
|
64
|
+
python3 -m venv ~/.codehaven-venv
|
|
65
|
+
source ~/.codehaven-venv/bin/activate # Windows PowerShell: ~\.codehaven-venv\Scripts\Activate.ps1
|
|
66
|
+
python -m pip install codehaven
|
|
65
67
|
|
|
66
|
-
# 2.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
# 3. Install CodeHaven in a virtual environment
|
|
70
|
-
python3 -m venv .venv
|
|
71
|
-
source .venv/bin/activate # Windows PowerShell: .venv\Scripts\Activate.ps1
|
|
72
|
-
python -m pip install -e .
|
|
68
|
+
# 2. Start Ollama if needed, pick a model for this computer's memory, and download it (asks first)
|
|
69
|
+
codehaven --setup
|
|
70
|
+
```
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
brew install tesseract # Ubuntu or Debian: sudo apt install tesseract-ocr
|
|
72
|
+
`codehaven --setup` starts Ollama if it is not running, 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. With [pipx](https://pipx.pypa.io/), `pipx install codehaven` replaces step 1 and puts the `codehaven` command on your path without a virtual environment.
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
ollama pull nomic-embed-text
|
|
74
|
+
After that, everything works offline. Each time, activate the environment and open the browser page:
|
|
79
75
|
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
```sh
|
|
77
|
+
source ~/.codehaven-venv/bin/activate
|
|
78
|
+
codehaven --gui --start-ollama
|
|
82
79
|
```
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
**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.
|
|
81
|
+
`--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. If Ollama is already running, for example the desktop app, CodeHaven uses it as it is. 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.
|
|
87
82
|
|
|
88
|
-
|
|
83
|
+
**Optional extras**, each only if you want the feature. None of them needs a particular folder. Run the `pip` line with CodeHaven's environment activated, so `pypdf` goes where CodeHaven can use it; `brew`, `apt`, and `ollama` install for the whole computer.
|
|
89
84
|
|
|
90
85
|
```sh
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
# Read code from pictures and scanned PDFs: Tesseract, a separate local program (not an Ollama model)
|
|
87
|
+
brew install tesseract # Ubuntu or Debian: sudo apt install tesseract-ocr
|
|
88
|
+
|
|
89
|
+
# Search by meaning: a local embedding model
|
|
90
|
+
ollama pull nomic-embed-text
|
|
91
|
+
|
|
92
|
+
# Chat about PDFs: a PDF reader
|
|
93
|
+
python -m pip install pypdf # with the environment activated; or: brew install poppler
|
|
94
|
+
# Scanned PDFs need both Poppler and Tesseract: brew install poppler tesseract
|
|
93
95
|
```
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
Tesseract is needed only for [pictures of code](#read-code-from-a-picture). 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.
|
|
96
98
|
|
|
97
|
-
**
|
|
99
|
+
**From a clone of this repository**, for working on CodeHaven itself, run these from the repository's own folder, because the paths are relative to it:
|
|
98
100
|
|
|
99
101
|
```sh
|
|
100
|
-
|
|
102
|
+
git clone https://github.com/Walid-Ahmed/codehaven.git
|
|
103
|
+
cd codehaven
|
|
104
|
+
python3 scripts/start_ollama.py # leave this terminal open; Ctrl+C stops the server
|
|
105
|
+
# in another terminal, in the same folder:
|
|
106
|
+
python3 -m venv .venv
|
|
107
|
+
source .venv/bin/activate
|
|
108
|
+
python -m pip install -e .
|
|
109
|
+
ollama pull qwen2.5-coder:7b
|
|
101
110
|
```
|
|
102
111
|
|
|
103
112
|
## How it is built
|
|
@@ -180,7 +189,7 @@ Implementation follows the [LangGraph graph API](https://docs.langchain.com/oss/
|
|
|
180
189
|
**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.
|
|
181
190
|
**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.
|
|
182
191
|
**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.
|
|
183
|
-
**Or upload a notebook or a PDF.** The same button and drop area take a Jupyter notebook (`.ipynb`) or a PDF, up to
|
|
192
|
+
**Or upload a notebook or a PDF.** The same button and drop area take a Jupyter notebook (`.ipynb`) or a PDF, up to 200 MB. See [Notebooks and PDFs](#notebooks-and-pdfs).
|
|
184
193
|
**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).
|
|
185
194
|
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.
|
|
186
195
|
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`".
|
|
@@ -267,10 +276,10 @@ Called from: app/main.py:21 in checkout
|
|
|
267
276
|
|
|
268
277
|
## Notebooks and PDFs
|
|
269
278
|
|
|
270
|
-
Upload, drop, attach, or paste a Jupyter notebook (`.ipynb`) or a PDF, up to
|
|
279
|
+
Upload, drop, attach, or paste a Jupyter notebook (`.ipynb`) or a PDF, up to 200 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.
|
|
271
280
|
|
|
272
281
|
- **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.
|
|
273
|
-
- **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:
|
|
282
|
+
- **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, so CodeHaven reads its pages itself: each page is drawn as a picture by Poppler's `pdftoppm` and read by Tesseract, several pages at once, on this computer. A 29-page, 23 MB scan takes about 20 seconds. This needs Poppler and Tesseract (`brew install poppler tesseract`; Ubuntu or Debian: `sudo apt install poppler-utils tesseract-ocr`); without them, CodeHaven says how to get them.
|
|
274
283
|
- **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.
|
|
275
284
|
|
|
276
285
|
## Read code from a picture
|
|
@@ -429,7 +438,7 @@ Names of cloud models (ending in `-cloud` or `:cloud`) are refused, and so are m
|
|
|
429
438
|
|
|
430
439
|
## Ollama and offline use
|
|
431
440
|
|
|
432
|
-
The [startup script](https://github.com/Walid-Ahmed/codehaven/blob/main/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).
|
|
441
|
+
The [startup script](https://github.com/Walid-Ahmed/codehaven/blob/main/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). It is in the repository, not in the installed package, so run it from the root of a clone, on macOS, Linux, or Windows (use `python` if that is your Python command). With an installed `codehaven`, `codehaven --start-ollama` does the same for one run. Leave that terminal open; Ctrl+C stops the server. Check its logs for `Ollama cloud disabled: true`.
|
|
433
442
|
|
|
434
443
|
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.
|
|
435
444
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codehaven
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.0
|
|
4
4
|
Summary: CodeHaven: a read-only, offline assistant for understanding code. Your code. Your machine. No API fees.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/Walid-Ahmed/codehaven
|
|
@@ -96,47 +96,56 @@ In the browser page you can also draw a **structure map** of your files, make **
|
|
|
96
96
|
|
|
97
97
|
## Get started
|
|
98
98
|
|
|
99
|
-
You need Python 3.10+ and [Ollama](https://ollama.com/). While you are online, do this once:
|
|
99
|
+
You need Python 3.10+ and [Ollama](https://ollama.com/). While you are online, do this once, in any folder:
|
|
100
100
|
|
|
101
101
|
```sh
|
|
102
|
-
# 1.
|
|
103
|
-
python3
|
|
102
|
+
# 1. Install CodeHaven in a virtual environment
|
|
103
|
+
python3 -m venv ~/.codehaven-venv
|
|
104
|
+
source ~/.codehaven-venv/bin/activate # Windows PowerShell: ~\.codehaven-venv\Scripts\Activate.ps1
|
|
105
|
+
python -m pip install codehaven
|
|
104
106
|
|
|
105
|
-
# 2.
|
|
106
|
-
|
|
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 .
|
|
107
|
+
# 2. Start Ollama if needed, pick a model for this computer's memory, and download it (asks first)
|
|
108
|
+
codehaven --setup
|
|
109
|
+
```
|
|
112
110
|
|
|
113
|
-
|
|
114
|
-
brew install tesseract # Ubuntu or Debian: sudo apt install tesseract-ocr
|
|
111
|
+
`codehaven --setup` starts Ollama if it is not running, 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. With [pipx](https://pipx.pypa.io/), `pipx install codehaven` replaces step 1 and puts the `codehaven` command on your path without a virtual environment.
|
|
115
112
|
|
|
116
|
-
|
|
117
|
-
ollama pull nomic-embed-text
|
|
113
|
+
After that, everything works offline. Each time, activate the environment and open the browser page:
|
|
118
114
|
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
```sh
|
|
116
|
+
source ~/.codehaven-venv/bin/activate
|
|
117
|
+
codehaven --gui --start-ollama
|
|
121
118
|
```
|
|
122
119
|
|
|
123
|
-
|
|
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.
|
|
120
|
+
`--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. If Ollama is already running, for example the desktop app, CodeHaven uses it as it is. 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.
|
|
126
121
|
|
|
127
|
-
|
|
122
|
+
**Optional extras**, each only if you want the feature. None of them needs a particular folder. Run the `pip` line with CodeHaven's environment activated, so `pypdf` goes where CodeHaven can use it; `brew`, `apt`, and `ollama` install for the whole computer.
|
|
128
123
|
|
|
129
124
|
```sh
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
# Read code from pictures and scanned PDFs: Tesseract, a separate local program (not an Ollama model)
|
|
126
|
+
brew install tesseract # Ubuntu or Debian: sudo apt install tesseract-ocr
|
|
127
|
+
|
|
128
|
+
# Search by meaning: a local embedding model
|
|
129
|
+
ollama pull nomic-embed-text
|
|
130
|
+
|
|
131
|
+
# Chat about PDFs: a PDF reader
|
|
132
|
+
python -m pip install pypdf # with the environment activated; or: brew install poppler
|
|
133
|
+
# Scanned PDFs need both Poppler and Tesseract: brew install poppler tesseract
|
|
132
134
|
```
|
|
133
135
|
|
|
134
|
-
|
|
136
|
+
Tesseract is needed only for [pictures of code](#read-code-from-a-picture). 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.
|
|
135
137
|
|
|
136
|
-
**
|
|
138
|
+
**From a clone of this repository**, for working on CodeHaven itself, run these from the repository's own folder, because the paths are relative to it:
|
|
137
139
|
|
|
138
140
|
```sh
|
|
139
|
-
|
|
141
|
+
git clone https://github.com/Walid-Ahmed/codehaven.git
|
|
142
|
+
cd codehaven
|
|
143
|
+
python3 scripts/start_ollama.py # leave this terminal open; Ctrl+C stops the server
|
|
144
|
+
# in another terminal, in the same folder:
|
|
145
|
+
python3 -m venv .venv
|
|
146
|
+
source .venv/bin/activate
|
|
147
|
+
python -m pip install -e .
|
|
148
|
+
ollama pull qwen2.5-coder:7b
|
|
140
149
|
```
|
|
141
150
|
|
|
142
151
|
## How it is built
|
|
@@ -219,7 +228,7 @@ Implementation follows the [LangGraph graph API](https://docs.langchain.com/oss/
|
|
|
219
228
|
**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
229
|
**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
230
|
**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
|
|
231
|
+
**Or upload a notebook or a PDF.** The same button and drop area take a Jupyter notebook (`.ipynb`) or a PDF, up to 200 MB. See [Notebooks and PDFs](#notebooks-and-pdfs).
|
|
223
232
|
**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
233
|
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
234
|
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`".
|
|
@@ -306,10 +315,10 @@ Called from: app/main.py:21 in checkout
|
|
|
306
315
|
|
|
307
316
|
## Notebooks and PDFs
|
|
308
317
|
|
|
309
|
-
Upload, drop, attach, or paste a Jupyter notebook (`.ipynb`) or a PDF, up to
|
|
318
|
+
Upload, drop, attach, or paste a Jupyter notebook (`.ipynb`) or a PDF, up to 200 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
319
|
|
|
311
320
|
- **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:
|
|
321
|
+
- **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, so CodeHaven reads its pages itself: each page is drawn as a picture by Poppler's `pdftoppm` and read by Tesseract, several pages at once, on this computer. A 29-page, 23 MB scan takes about 20 seconds. This needs Poppler and Tesseract (`brew install poppler tesseract`; Ubuntu or Debian: `sudo apt install poppler-utils tesseract-ocr`); without them, CodeHaven says how to get them.
|
|
313
322
|
- **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
323
|
|
|
315
324
|
## Read code from a picture
|
|
@@ -468,7 +477,7 @@ Names of cloud models (ending in `-cloud` or `:cloud`) are refused, and so are m
|
|
|
468
477
|
|
|
469
478
|
## Ollama and offline use
|
|
470
479
|
|
|
471
|
-
The [startup script](https://github.com/Walid-Ahmed/codehaven/blob/main/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).
|
|
480
|
+
The [startup script](https://github.com/Walid-Ahmed/codehaven/blob/main/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). It is in the repository, not in the installed package, so run it from the root of a clone, on macOS, Linux, or Windows (use `python` if that is your Python command). With an installed `codehaven`, `codehaven --start-ollama` does the same for one run. Leave that terminal open; Ctrl+C stops the server. Check its logs for `Ollama cloud disabled: true`.
|
|
472
481
|
|
|
473
482
|
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
483
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""Local-only coding assistant."""
|
|
2
|
-
__version__ = "0.
|
|
2
|
+
__version__ = "0.15.0"
|
|
@@ -9,29 +9,39 @@ Outputs, pictures, and widget state are left out. A Python notebook becomes a .p
|
|
|
9
9
|
|
|
10
10
|
A PDF's text is read by pypdf when that package is installed, or else by the pdftotext program (part of
|
|
11
11
|
Poppler). Either works offline. Each page starts with a "===== Page N =====" line, so a cited line can be
|
|
12
|
-
found on its page. A scanned PDF holds pictures, not text
|
|
12
|
+
found on its page. A scanned PDF holds pictures, not text: when no page has text, each page is drawn as a
|
|
13
|
+
picture by pdftoppm (also part of Poppler) and read by Tesseract, the same local program that reads screenshots.
|
|
13
14
|
|
|
14
15
|
A document longer than CodeHaven reads at once (64 KB of text) is cut at a cell or page boundary, and the
|
|
15
16
|
result says how much was kept.
|
|
16
17
|
"""
|
|
17
18
|
import io
|
|
18
19
|
import json
|
|
20
|
+
import os
|
|
19
21
|
import re
|
|
20
22
|
import shutil
|
|
21
23
|
import subprocess
|
|
22
24
|
import tempfile
|
|
25
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
23
26
|
from pathlib import Path
|
|
24
27
|
|
|
25
28
|
from .workspace import MAX_BYTES
|
|
26
29
|
|
|
27
|
-
DOCUMENT_BYTES =
|
|
30
|
+
DOCUMENT_BYTES = 200_000_000 # The largest notebook or PDF accepted; scans are large, and the text read from them is small.
|
|
28
31
|
# The most pages read from one PDF, and the longest pdftotext may run.
|
|
29
32
|
PDF_PAGES, PDF_SECONDS = 300, 60
|
|
33
|
+
# A scanned PDF: the most pages read by Tesseract, the resolution each page is drawn at, and the longest one page may take.
|
|
34
|
+
SCAN_PAGES, SCAN_DPI, SCAN_SECONDS = 60, 200, 90
|
|
35
|
+
SCAN_WORKERS = 6 # Pages read at the same time, at most one per processor core.
|
|
30
36
|
EXTENSIONS = {"python": ".py", "javascript": ".js", "typescript": ".ts", "r": ".r", "julia": ".jl", "ruby": ".rb",
|
|
31
37
|
"scala": ".scala", "bash": ".sh", "go": ".go", "rust": ".rs", "java": ".java", "kotlin": ".kt"}
|
|
32
38
|
PDF_HELP = ("Reading a PDF needs pypdf or pdftotext on this computer, and neither was found. Install one once while "
|
|
33
39
|
"online: `python -m pip install pypdf`, or Poppler (`brew install poppler`; Ubuntu or Debian: "
|
|
34
40
|
"`sudo apt install poppler-utils`). Everything else keeps working.")
|
|
41
|
+
SCAN_HELP = ("No text was found in this PDF, so it is probably scanned pages, which are pictures. CodeHaven can read them "
|
|
42
|
+
"with two free programs on this computer, installed once while online: Poppler and Tesseract (macOS: "
|
|
43
|
+
"`brew install poppler tesseract`; Ubuntu or Debian: `sudo apt install poppler-utils tesseract-ocr`). "
|
|
44
|
+
"After that it works offline.")
|
|
35
45
|
|
|
36
46
|
|
|
37
47
|
def kind(name, data):
|
|
@@ -150,11 +160,58 @@ def pdf_pages(data):
|
|
|
150
160
|
return pages, len(pages)
|
|
151
161
|
|
|
152
162
|
|
|
163
|
+
def scanned_pages(data, room, total):
|
|
164
|
+
"""The text of a scanned PDF's first pages, until room bytes are used or SCAN_PAGES are read. Returns (pages, total).
|
|
165
|
+
|
|
166
|
+
Each page is drawn as a grey picture by pdftoppm and read by Tesseract as ordinary text. Several pages are read
|
|
167
|
+
at once, one Tesseract per processor core, in order, so the text stays in page order.
|
|
168
|
+
"""
|
|
169
|
+
drawer, reader = shutil.which("pdftoppm"), shutil.which("tesseract")
|
|
170
|
+
if drawer is None or reader is None:
|
|
171
|
+
raise ValueError(SCAN_HELP)
|
|
172
|
+
# One thread per Tesseract: several single-threaded readers are faster than one that splits a page.
|
|
173
|
+
env = {**os.environ, "OMP_THREAD_LIMIT": "1"}
|
|
174
|
+
with tempfile.TemporaryDirectory(prefix="codehaven-scan-") as folder: # Readable by this user only; deleted after.
|
|
175
|
+
copy = Path(folder, "document.pdf")
|
|
176
|
+
copy.write_bytes(data)
|
|
177
|
+
|
|
178
|
+
def page_text(number):
|
|
179
|
+
"""One page's text, or None when it cannot be drawn or read."""
|
|
180
|
+
picture = Path(folder, f"page-{number}")
|
|
181
|
+
try:
|
|
182
|
+
drawn = subprocess.run([drawer, "-f", str(number), "-l", str(number), "-r", str(SCAN_DPI), "-gray",
|
|
183
|
+
"-png", "-singlefile", str(copy), str(picture)],
|
|
184
|
+
capture_output=True, timeout=SCAN_SECONDS, stdin=subprocess.DEVNULL, cwd=folder)
|
|
185
|
+
if drawn.returncode != 0 or not picture.with_suffix(".png").exists():
|
|
186
|
+
return None
|
|
187
|
+
done = subprocess.run([reader, str(picture.with_suffix(".png")), "stdout", "-l", "eng"], env=env,
|
|
188
|
+
capture_output=True, timeout=SCAN_SECONDS, stdin=subprocess.DEVNULL, cwd=folder)
|
|
189
|
+
return done.stdout.decode("utf-8", "replace") if done.returncode == 0 else None
|
|
190
|
+
except (subprocess.TimeoutExpired, OSError):
|
|
191
|
+
return None
|
|
192
|
+
finally:
|
|
193
|
+
picture.with_suffix(".png").unlink(missing_ok=True)
|
|
194
|
+
|
|
195
|
+
pages, size, workers = [], 0, max(1, min(SCAN_WORKERS, os.cpu_count() or 1))
|
|
196
|
+
last = min(total or SCAN_PAGES, SCAN_PAGES)
|
|
197
|
+
with ThreadPoolExecutor(max_workers=workers) as pool:
|
|
198
|
+
for start in range(1, last + 1, workers):
|
|
199
|
+
for text in pool.map(page_text, range(start, min(start + workers, last + 1))):
|
|
200
|
+
if text is None or size > room:
|
|
201
|
+
return pages, total
|
|
202
|
+
pages.append(text)
|
|
203
|
+
size += len(text.encode()) + 32
|
|
204
|
+
return pages, total
|
|
205
|
+
|
|
206
|
+
|
|
153
207
|
def read_pdf(name, data):
|
|
154
208
|
"""Turn a PDF's text into one text file. Returns {"name", "text", "source", "kind", "note"}."""
|
|
155
209
|
if len(data) > DOCUMENT_BYTES:
|
|
156
210
|
raise ValueError(f"Only PDFs up to {DOCUMENT_BYTES // 1_000_000} MB can be read.")
|
|
157
211
|
pages, total = pdf_pages(data)
|
|
212
|
+
scanned = bool(pages) and not any(page.strip() for page in pages)
|
|
213
|
+
if scanned:
|
|
214
|
+
pages, total = scanned_pages(data, MAX_BYTES, total)
|
|
158
215
|
blocks, kept, size = [], 0, 0
|
|
159
216
|
for number, page in enumerate(pages, 1):
|
|
160
217
|
lines = [line.rstrip() for line in page.replace("\0", "").splitlines()]
|
|
@@ -171,12 +228,17 @@ def read_pdf(name, data):
|
|
|
171
228
|
size += len(block.encode()) + 1
|
|
172
229
|
kept += 1
|
|
173
230
|
if not any(block.split("\n", 1)[1].strip() for block in blocks):
|
|
174
|
-
raise ValueError("No text
|
|
175
|
-
"
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
"its number. Columns, tables, and code can lose their layout
|
|
179
|
-
|
|
231
|
+
raise ValueError("No text could be read from the scanned pages of this PDF; the scan may be too faint or blurred."
|
|
232
|
+
if scanned else "No text was found in this PDF." if pages else "This PDF has no pages to read.")
|
|
233
|
+
note = (f"Read {kept} page{'s' if kept != 1 else ''} of text from the PDF {name}"
|
|
234
|
+
+ (" with Tesseract, because its pages are scanned pictures" if scanned else "")
|
|
235
|
+
+ ". Each page starts with a line naming its number. Columns, tables, and code can lose their layout"
|
|
236
|
+
+ (", and scanned text can have misread words" if scanned else "")
|
|
237
|
+
+ ", so check anything that matters against the PDF.")
|
|
238
|
+
if scanned and kept < total:
|
|
239
|
+
note += (f" Pages 1-{kept} of {total} were read, the most that fit in the {MAX_BYTES // 1000} KB CodeHaven reads at "
|
|
240
|
+
f"once (at most {SCAN_PAGES} scanned pages).")
|
|
241
|
+
elif kept < total:
|
|
180
242
|
note += f" Only pages 1-{kept} of {total} fit in the {MAX_BYTES // 1000} KB CodeHaven reads at once."
|
|
181
243
|
return {"name": stem(name) + ".txt", "text": "\n".join(blocks), "source": name, "kind": "pdf", "note": note}
|
|
182
244
|
|
|
@@ -12,6 +12,7 @@ let indexing = "";
|
|
|
12
12
|
let repoRoot = null;
|
|
13
13
|
const UPLOAD_BYTES = 64000; // The same limit as every file CodeHaven reads.
|
|
14
14
|
const PICTURE_BYTES = 8000000; // A picture of code is read into text by Tesseract on this computer.
|
|
15
|
+
const DOCUMENT_BYTES = 200000000; // A notebook or PDF; scanned PDFs are large.
|
|
15
16
|
const isDocument = (file) => /\.(ipynb|pdf)$/i.test(file.name) || file.type === "application/pdf";
|
|
16
17
|
const isPicture = (file) => /^image\/(png|jpeg)$/.test(file.type) || /\.(png|jpe?g)$/i.test(file.name);
|
|
17
18
|
// ---- Language: English, or Arabic chosen with the button in the top bar and remembered in this browser only.
|
|
@@ -493,15 +494,16 @@ async function uploadFile(file, fromChat = false) {
|
|
|
493
494
|
note = note || addMessage("note");
|
|
494
495
|
note.classList.toggle("error", failed); note.textContent = text; scrollDown();
|
|
495
496
|
};
|
|
496
|
-
|
|
497
|
+
const limit = isDocument(file) ? DOCUMENT_BYTES : picture ? PICTURE_BYTES : UPLOAD_BYTES;
|
|
498
|
+
if (file.size > limit) {
|
|
497
499
|
const size = {name: file.name, size: Math.ceil(file.size / (picture ? 1000000 : 1000))};
|
|
498
|
-
report(isDocument(file) ? t("{name} is {size} MB; CodeHaven reads notebooks and PDFs up to
|
|
500
|
+
report(isDocument(file) ? t("{name} is {size} MB; CodeHaven reads notebooks and PDFs up to 200 MB.", size)
|
|
499
501
|
: picture ? t("{name} is {size} MB; CodeHaven reads pictures up to 8 MB. Crop it to the code.", size)
|
|
500
502
|
: t("{name} is {size} KB; CodeHaven reads text files up to 64 KB. Index its folder instead to ask about part of it.", size), true);
|
|
501
503
|
return;
|
|
502
504
|
}
|
|
503
505
|
busy = true; updateComposer();
|
|
504
|
-
report(t(isDocument(file) ? "Reading {name} into text…" : picture ? "Reading the code in {name}… this takes a few seconds." : "Reading {name}…", {name: file.name}));
|
|
506
|
+
report(t(isDocument(file) ? "Reading {name} into text… a scanned PDF takes a few seconds a page." : picture ? "Reading the code in {name}… this takes a few seconds." : "Reading {name}…", {name: file.name}));
|
|
505
507
|
try {
|
|
506
508
|
const response = await reach("/api/upload?name=" + encodeURIComponent(file.name),
|
|
507
509
|
{method: "POST", headers: {"Content-Type": "application/octet-stream", "X-CodeHaven-Token": TOKEN}, body: file});
|
|
@@ -828,10 +828,12 @@ def make_handler(app, token, port_holder):
|
|
|
828
828
|
def upload(self):
|
|
829
829
|
"""The raw bytes of an uploaded file. Bodies over the picture limit are refused without being read."""
|
|
830
830
|
length = int(self.headers.get("Content-Length") or 0)
|
|
831
|
-
|
|
831
|
+
# The largest kind of upload; text files and pictures have smaller limits, checked once the bytes are seen.
|
|
832
|
+
if not 0 <= length <= max(ocr.IMAGE_BYTES, documents.DOCUMENT_BYTES):
|
|
832
833
|
self.close_connection = True # The body is not read, so the connection cannot be reused.
|
|
833
|
-
raise ValueError(f"Only text files up to {MAX_BYTES // 1000} KB,
|
|
834
|
-
f"
|
|
834
|
+
raise ValueError(f"Only text files up to {MAX_BYTES // 1000} KB, pictures up to "
|
|
835
|
+
f"{ocr.IMAGE_BYTES // 1_000_000} MB, and notebooks and PDFs up to "
|
|
836
|
+
f"{documents.DOCUMENT_BYTES // 1_000_000} MB can be uploaded.")
|
|
835
837
|
return self.rfile.read(length)
|
|
836
838
|
|
|
837
839
|
def do_POST(self):
|
|
@@ -140,10 +140,10 @@ const ARABIC = {
|
|
|
140
140
|
"Now chatting about ": "المحادثة الآن عن ",
|
|
141
141
|
" The chat above is kept and follow-up questions still remember it, but its citations point to what was open before, so they no longer open.": " المحادثة أعلاه باقية وأسئلة المتابعة ما زالت تتذكرها، لكن إشاراتها تخص ما كان مفتوحًا من قبل، لذلك لم تعد تُفتح.",
|
|
142
142
|
"View {name}": "اعرض {name}",
|
|
143
|
-
"{name} is {size} MB; CodeHaven reads notebooks and PDFs up to
|
|
143
|
+
"{name} is {size} MB; CodeHaven reads notebooks and PDFs up to 200 MB.": "حجم {name} هو {size} ميغابايت؛ يقرأ CodeHaven الدفاتر وملفات PDF حتى 200 ميغابايت.",
|
|
144
144
|
"{name} is {size} MB; CodeHaven reads pictures up to 8 MB. Crop it to the code.": "حجم {name} هو {size} ميغابايت؛ يقرأ CodeHaven الصور حتى 8 ميغابايت. قص الصورة على الكود فقط.",
|
|
145
145
|
"{name} is {size} KB; CodeHaven reads text files up to 64 KB. Index its folder instead to ask about part of it.": "حجم {name} هو {size} كيلوبايت؛ يقرأ CodeHaven الملفات النصية حتى 64 كيلوبايت. فهرس مجلده بدلًا من ذلك لتسأل عن جزء منه.",
|
|
146
|
-
"Reading {name} into text…": "جارٍ قراءة {name} إلى نص…",
|
|
146
|
+
"Reading {name} into text… a scanned PDF takes a few seconds a page.": "جارٍ قراءة {name} إلى نص… يستغرق ملف PDF الممسوح ضوئيًا بضع ثوانٍ لكل صفحة.",
|
|
147
147
|
"Reading the code in {name}… this takes a few seconds.": "جارٍ قراءة الكود في {name}… يستغرق هذا بضع ثوانٍ.",
|
|
148
148
|
"Reading {name}…": "جارٍ قراءة {name}…",
|
|
149
149
|
"Drop one file at a time, or index the folder that holds them.": "أفلت ملفًا واحدًا في كل مرة، أو فهرس المجلد الذي يحتويها.",
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "codehaven"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.15.0"
|
|
8
8
|
description = "CodeHaven: a read-only, offline assistant for understanding code. Your code. Your machine. No API fees."
|
|
9
9
|
requires-python = ">=3.10"
|
|
10
10
|
readme = "README.md"
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import importlib.util
|
|
3
3
|
import json
|
|
4
4
|
import shutil
|
|
5
|
+
import subprocess
|
|
5
6
|
import tempfile
|
|
6
7
|
import unittest
|
|
7
8
|
from pathlib import Path
|
|
@@ -132,6 +133,42 @@ class PdfTests(unittest.TestCase):
|
|
|
132
133
|
with self.assertRaisesRegex(ValueError, "pip install pypdf"):
|
|
133
134
|
documents.read_pdf("paper.pdf", pdf(self.PAGES))
|
|
134
135
|
|
|
136
|
+
def test_a_scanned_pdf_is_read_page_by_page_with_tesseract(self):
|
|
137
|
+
calls = []
|
|
138
|
+
|
|
139
|
+
def run(command, **options):
|
|
140
|
+
"""pdftoppm draws page N into page-N.png; Tesseract reads it back as "Text of page N"."""
|
|
141
|
+
calls.append(command)
|
|
142
|
+
if command[0] == "pdftoppm":
|
|
143
|
+
number = int(command[command.index("-f") + 1])
|
|
144
|
+
if number > 3:
|
|
145
|
+
return subprocess.CompletedProcess(command, 1, b"", b"")
|
|
146
|
+
Path(command[-1] + ".png").write_bytes(b"png")
|
|
147
|
+
return subprocess.CompletedProcess(command, 0, b"", b"")
|
|
148
|
+
number = Path(command[1]).stem.split("-")[1]
|
|
149
|
+
self.assertEqual(options["env"]["OMP_THREAD_LIMIT"], "1")
|
|
150
|
+
return subprocess.CompletedProcess(command, 0, f"Text of page {number}\n".encode(), b"")
|
|
151
|
+
|
|
152
|
+
with patch.object(documents, "pdf_pages", return_value=(["", "", ""], 3)), \
|
|
153
|
+
patch.object(documents.shutil, "which", side_effect=lambda name: name), \
|
|
154
|
+
patch.object(documents.subprocess, "run", side_effect=run):
|
|
155
|
+
found = documents.read_pdf("scan.pdf", b"%PDF-1.4" + b"x" * (documents.DOCUMENT_BYTES // 4))
|
|
156
|
+
lines = found["text"].splitlines()
|
|
157
|
+
self.assertEqual([line for line in lines if line], ["===== Page 1 =====", "Text of page 1", "===== Page 2 =====",
|
|
158
|
+
"Text of page 2", "===== Page 3 =====", "Text of page 3"])
|
|
159
|
+
self.assertIn("with Tesseract, because its pages are scanned pictures", found["note"])
|
|
160
|
+
self.assertEqual(sum(command[0] == "tesseract" for command in calls), 3)
|
|
161
|
+
|
|
162
|
+
def test_without_the_scan_tools_the_message_says_how_to_get_them(self):
|
|
163
|
+
with patch.object(documents, "pdf_pages", return_value=(["", " \n"], 2)), \
|
|
164
|
+
patch.object(documents.shutil, "which", return_value=None):
|
|
165
|
+
with self.assertRaisesRegex(ValueError, "brew install poppler tesseract"):
|
|
166
|
+
documents.read_pdf("scan.pdf", b"%PDF-1.4")
|
|
167
|
+
|
|
168
|
+
def test_large_scans_are_accepted_and_the_limit_is_named(self):
|
|
169
|
+
self.assertGreaterEqual(documents.DOCUMENT_BYTES, 100_000_000) # A 23 MB scan of 29 pages was refused at 8 MB.
|
|
170
|
+
with self.assertRaisesRegex(ValueError, "200 MB"):
|
|
171
|
+
documents.read_pdf("huge.pdf", b"%PDF-1.4" + b"x" * documents.DOCUMENT_BYTES)
|
|
135
172
|
|
|
136
173
|
if __name__ == "__main__":
|
|
137
174
|
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|