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.
Files changed (116) hide show
  1. {codehaven-0.14.1 → codehaven-0.15.0}/PKG-INFO +39 -30
  2. {codehaven-0.14.1 → codehaven-0.15.0}/README.md +38 -29
  3. {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/PKG-INFO +39 -30
  4. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/__init__.py +1 -1
  5. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/documents.py +70 -8
  6. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui.js +5 -3
  7. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui.py +5 -3
  8. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui_arabic.js +2 -2
  9. {codehaven-0.14.1 → codehaven-0.15.0}/pyproject.toml +1 -1
  10. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_documents.py +37 -0
  11. {codehaven-0.14.1 → codehaven-0.15.0}/LICENSE +0 -0
  12. {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/SOURCES.txt +0 -0
  13. {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/dependency_links.txt +0 -0
  14. {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/entry_points.txt +0 -0
  15. {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/requires.txt +0 -0
  16. {codehaven-0.14.1 → codehaven-0.15.0}/codehaven.egg-info/top_level.txt +0 -0
  17. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/__main__.py +0 -0
  18. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/agent.py +0 -0
  19. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/answers.py +0 -0
  20. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/arabic.py +0 -0
  21. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/changes.py +0 -0
  22. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/chats.py +0 -0
  23. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/cli.py +0 -0
  24. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/coder.py +0 -0
  25. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/dependencies.py +0 -0
  26. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/doctor.py +0 -0
  27. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/edits.py +0 -0
  28. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/errors.py +0 -0
  29. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/evaluation.py +0 -0
  30. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/evidence.py +0 -0
  31. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/exclusions.py +0 -0
  32. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/export.py +0 -0
  33. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui.css +0 -0
  34. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/gui.html +0 -0
  35. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/guides.py +0 -0
  36. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/history.py +0 -0
  37. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/index_cache.py +0 -0
  38. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/insights.py +0 -0
  39. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/javascript.py +0 -0
  40. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/knowledge.py +0 -0
  41. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/languages.py +0 -0
  42. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/memory.py +0 -0
  43. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/messages.py +0 -0
  44. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/model.py +0 -0
  45. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/more_languages.py +0 -0
  46. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/ocr.py +0 -0
  47. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/prompts.py +0 -0
  48. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/references/langgraph-approvals.md +0 -0
  49. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/references/langgraph-checkpoints.md +0 -0
  50. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/references/langgraph-graphs.md +0 -0
  51. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/references/langgraph.md +0 -0
  52. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/review.py +0 -0
  53. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/scans.py +0 -0
  54. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/semantic.py +0 -0
  55. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/slash.py +0 -0
  56. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/study.py +0 -0
  57. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/symbols.py +0 -0
  58. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/tasks.py +0 -0
  59. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/test_runner.py +0 -0
  60. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/trace.py +0 -0
  61. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/tracebacks.py +0 -0
  62. {codehaven-0.14.1 → codehaven-0.15.0}/offline_agent/workspace.py +0 -0
  63. {codehaven-0.14.1 → codehaven-0.15.0}/setup.cfg +0 -0
  64. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_agent.py +0 -0
  65. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_arabic.py +0 -0
  66. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_browser.py +0 -0
  67. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_changes.py +0 -0
  68. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_chats.py +0 -0
  69. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_citations.py +0 -0
  70. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_comments.py +0 -0
  71. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_dependencies.py +0 -0
  72. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_doctor.py +0 -0
  73. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_edit_and_paging.py +0 -0
  74. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_edits.py +0 -0
  75. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_evaluation.py +0 -0
  76. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_evidence.py +0 -0
  77. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_exclusions.py +0 -0
  78. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_export.py +0 -0
  79. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_graph.py +0 -0
  80. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_gui.py +0 -0
  81. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_guides.py +0 -0
  82. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_harness.py +0 -0
  83. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_history.py +0 -0
  84. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_index_speed.py +0 -0
  85. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_insights.py +0 -0
  86. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_knowledge.py +0 -0
  87. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_languages.py +0 -0
  88. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_memory.py +0 -0
  89. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_more_languages.py +0 -0
  90. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_ocr.py +0 -0
  91. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_phrases.py +0 -0
  92. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_presentation.py +0 -0
  93. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_prompt_budget.py +0 -0
  94. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_readme.py +0 -0
  95. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_real_evals.py +0 -0
  96. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_repository_rag.py +0 -0
  97. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_retrieval_upgrade.py +0 -0
  98. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_review.py +0 -0
  99. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_run_python.py +0 -0
  100. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_sandbox_integration.py +0 -0
  101. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_sandbox_unit.py +0 -0
  102. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_scans.py +0 -0
  103. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_search.py +0 -0
  104. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_semantic.py +0 -0
  105. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_setup.py +0 -0
  106. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_several_repos.py +0 -0
  107. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_slash.py +0 -0
  108. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_start_ollama.py +0 -0
  109. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_stop.py +0 -0
  110. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_study.py +0 -0
  111. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_symbols.py +0 -0
  112. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_test_runner.py +0 -0
  113. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_trace.py +0 -0
  114. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_tracebacks.py +0 -0
  115. {codehaven-0.14.1 → codehaven-0.15.0}/tests/test_tracing.py +0 -0
  116. {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.14.1
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. Start Ollama with cloud features off (leave this terminal open)
103
- python3 scripts/start_ollama.py
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. 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 .
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
- # 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
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
- # 5. Optional: download an embedding model, so search also works by meaning
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
- # 6. Optional: a PDF reader, only if you want to chat about PDFs
120
- python -m pip install pypdf # or: brew install poppler
115
+ ```sh
116
+ source ~/.codehaven-venv/bin/activate
117
+ codehaven --gui --start-ollama
121
118
  ```
122
119
 
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.
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
- After that, everything works offline. Each time, activate the environment and open the browser page:
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
- source .venv/bin/activate
131
- codehaven --gui --start-ollama
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
- `--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.
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
- **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:
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
- pipx install git+https://github.com/Walid-Ahmed/codehaven.git
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 8 MB. See [Notebooks and PDFs](#notebooks-and-pdfs).
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 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.
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: attach a screenshot of the page instead.
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). 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`.
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. Start Ollama with cloud features off (leave this terminal open)
64
- python3 scripts/start_ollama.py
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. In another terminal, download the default model
67
- ollama pull qwen2.5-coder:7b
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
- # 4. Optional: install Tesseract, only if you want CodeHaven to read code from pictures
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
- # 5. Optional: download an embedding model, so search also works by meaning
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
- # 6. Optional: a PDF reader, only if you want to chat about PDFs
81
- python -m pip install pypdf # or: brew install poppler
76
+ ```sh
77
+ source ~/.codehaven-venv/bin/activate
78
+ codehaven --gui --start-ollama
82
79
  ```
83
80
 
84
- 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.
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
- After that, everything works offline. Each time, activate the environment and open the browser page:
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
- source .venv/bin/activate
92
- codehaven --gui --start-ollama
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
- `--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.
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
- **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:
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
- pipx install git+https://github.com/Walid-Ahmed/codehaven.git
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 8 MB. See [Notebooks and PDFs](#notebooks-and-pdfs).
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 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.
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: attach a screenshot of the page instead.
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). 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`.
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.14.1
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. Start Ollama with cloud features off (leave this terminal open)
103
- python3 scripts/start_ollama.py
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. 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 .
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
- # 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
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
- # 5. Optional: download an embedding model, so search also works by meaning
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
- # 6. Optional: a PDF reader, only if you want to chat about PDFs
120
- python -m pip install pypdf # or: brew install poppler
115
+ ```sh
116
+ source ~/.codehaven-venv/bin/activate
117
+ codehaven --gui --start-ollama
121
118
  ```
122
119
 
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.
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
- After that, everything works offline. Each time, activate the environment and open the browser page:
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
- source .venv/bin/activate
131
- codehaven --gui --start-ollama
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
- `--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.
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
- **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:
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
- pipx install git+https://github.com/Walid-Ahmed/codehaven.git
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 8 MB. See [Notebooks and PDFs](#notebooks-and-pdfs).
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 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.
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: attach a screenshot of the page instead.
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). 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`.
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.14.1"
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; a screenshot of the page can be read instead.
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 = 8_000_000 # The largest notebook or PDF accepted; the text read from it is far smaller.
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 was found in this PDF. It may be scanned pages, which are pictures: attach a "
175
- "screenshot of the page instead and CodeHaven reads the code in it."
176
- if pages else "This PDF has no pages to read.")
177
- note = (f"Read {kept} page{'s' if kept != 1 else ''} of text from the PDF {name}. Each page starts with a line naming "
178
- "its number. Columns, tables, and code can lose their layout, so check anything that matters against the PDF.")
179
- if kept < total:
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
- if (file.size > (picture ? PICTURE_BYTES : UPLOAD_BYTES)) {
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 8 MB.", size)
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
- if not 0 <= length <= ocr.IMAGE_BYTES: # Text files have a smaller limit, checked once the bytes are seen.
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, and pictures, notebooks, and PDFs up "
834
- f"to {ocr.IMAGE_BYTES // 1_000_000} MB, can be uploaded.")
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 8 MB.": "حجم {name} هو {size} ميغابايت؛ يقرأ CodeHaven الدفاتر وملفات PDF حتى 8 ميغابايت.",
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.14.1"
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