pocket-tutor 0.0.0-stage → 1.0.0

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 (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +171 -2
  3. package/bin/pocket-tutor.js +57 -0
  4. package/config.example.json +12 -0
  5. package/docs/CLIP_RULES.md +38 -0
  6. package/package.json +74 -4
  7. package/scripts/build-ui.mjs +25 -0
  8. package/scripts/clip-judge.js +106 -0
  9. package/scripts/doctor.js +58 -0
  10. package/scripts/setup-visuals.js +27 -0
  11. package/scripts/visual_scene.py +279 -0
  12. package/src/astryx-themes.js +18 -0
  13. package/src/browser.js +38 -0
  14. package/src/config.js +84 -0
  15. package/src/graph.js +114 -0
  16. package/src/helper.ps1 +67 -0
  17. package/src/main.js +490 -0
  18. package/src/model.js +283 -0
  19. package/src/native.js +50 -0
  20. package/src/place.js +29 -0
  21. package/src/preload.js +17 -0
  22. package/src/privacy.js +40 -0
  23. package/src/project.js +252 -0
  24. package/src/search.js +111 -0
  25. package/src/themes/lens/lens.css +1165 -0
  26. package/src/themes/lens/lens.css.d.ts +9 -0
  27. package/src/themes/lens/lens.d.ts +14 -0
  28. package/src/themes/lens/lens.fonts.css +2 -0
  29. package/src/themes/lens/lens.js +627 -0
  30. package/src/themes/lens/lens.variants.d.ts +22 -0
  31. package/src/themes/lens/lensTheme.doc.mjs +10 -0
  32. package/src/themes/lens/lensTheme.ts +2 -0
  33. package/src/ui/app.jsx +268 -0
  34. package/src/ui/dist/assets/KaTeX_AMS-Regular-CYEKBG2K.woff +0 -0
  35. package/src/ui/dist/assets/KaTeX_AMS-Regular-JKX5W2C4.ttf +0 -0
  36. package/src/ui/dist/assets/KaTeX_AMS-Regular-U6PRYMIZ.woff2 +0 -0
  37. package/src/ui/dist/assets/KaTeX_Caligraphic-Bold-5QL5CMTE.woff2 +0 -0
  38. package/src/ui/dist/assets/KaTeX_Caligraphic-Bold-WZ3QSGD3.woff +0 -0
  39. package/src/ui/dist/assets/KaTeX_Caligraphic-Bold-ZTS3R3HK.ttf +0 -0
  40. package/src/ui/dist/assets/KaTeX_Caligraphic-Regular-3LKEU76G.woff +0 -0
  41. package/src/ui/dist/assets/KaTeX_Caligraphic-Regular-A7XRTZ5Q.ttf +0 -0
  42. package/src/ui/dist/assets/KaTeX_Caligraphic-Regular-KX5MEWCF.woff2 +0 -0
  43. package/src/ui/dist/assets/KaTeX_Fraktur-Bold-2QVFK6NQ.woff2 +0 -0
  44. package/src/ui/dist/assets/KaTeX_Fraktur-Bold-T4SWXBMT.woff +0 -0
  45. package/src/ui/dist/assets/KaTeX_Fraktur-Bold-WGHVTYOR.ttf +0 -0
  46. package/src/ui/dist/assets/KaTeX_Fraktur-Regular-2PEIFJSJ.woff2 +0 -0
  47. package/src/ui/dist/assets/KaTeX_Fraktur-Regular-5U4OPH2X.ttf +0 -0
  48. package/src/ui/dist/assets/KaTeX_Fraktur-Regular-PQMHCIK6.woff +0 -0
  49. package/src/ui/dist/assets/KaTeX_Main-Bold-2GA4IZIN.woff +0 -0
  50. package/src/ui/dist/assets/KaTeX_Main-Bold-W5FBVCZM.ttf +0 -0
  51. package/src/ui/dist/assets/KaTeX_Main-Bold-YP5VVQRP.woff2 +0 -0
  52. package/src/ui/dist/assets/KaTeX_Main-BoldItalic-4P4C7HJH.woff +0 -0
  53. package/src/ui/dist/assets/KaTeX_Main-BoldItalic-N4V3DX7S.woff2 +0 -0
  54. package/src/ui/dist/assets/KaTeX_Main-BoldItalic-ODMLBJJQ.ttf +0 -0
  55. package/src/ui/dist/assets/KaTeX_Main-Italic-I43T2HSR.ttf +0 -0
  56. package/src/ui/dist/assets/KaTeX_Main-Italic-RELBIK7M.woff2 +0 -0
  57. package/src/ui/dist/assets/KaTeX_Main-Italic-SASNQFN2.woff +0 -0
  58. package/src/ui/dist/assets/KaTeX_Main-Regular-ARRPAO67.woff2 +0 -0
  59. package/src/ui/dist/assets/KaTeX_Main-Regular-P5I74A2A.woff +0 -0
  60. package/src/ui/dist/assets/KaTeX_Main-Regular-W74P5G27.ttf +0 -0
  61. package/src/ui/dist/assets/KaTeX_Math-BoldItalic-6EBV3DK5.woff +0 -0
  62. package/src/ui/dist/assets/KaTeX_Math-BoldItalic-K4WTGH3J.woff2 +0 -0
  63. package/src/ui/dist/assets/KaTeX_Math-BoldItalic-VB447A4D.ttf +0 -0
  64. package/src/ui/dist/assets/KaTeX_Math-Italic-6KGCHLFN.woff2 +0 -0
  65. package/src/ui/dist/assets/KaTeX_Math-Italic-KKK3USB2.woff +0 -0
  66. package/src/ui/dist/assets/KaTeX_Math-Italic-SON4MRCA.ttf +0 -0
  67. package/src/ui/dist/assets/KaTeX_SansSerif-Bold-RRNVJFFW.woff2 +0 -0
  68. package/src/ui/dist/assets/KaTeX_SansSerif-Bold-STQ6RXC7.ttf +0 -0
  69. package/src/ui/dist/assets/KaTeX_SansSerif-Bold-X5M5EMOD.woff +0 -0
  70. package/src/ui/dist/assets/KaTeX_SansSerif-Italic-HMPFTM52.woff2 +0 -0
  71. package/src/ui/dist/assets/KaTeX_SansSerif-Italic-PSN4QKYX.woff +0 -0
  72. package/src/ui/dist/assets/KaTeX_SansSerif-Italic-WTBAZBGY.ttf +0 -0
  73. package/src/ui/dist/assets/KaTeX_SansSerif-Regular-2TL3USAE.ttf +0 -0
  74. package/src/ui/dist/assets/KaTeX_SansSerif-Regular-OQCII6EP.woff +0 -0
  75. package/src/ui/dist/assets/KaTeX_SansSerif-Regular-XIQ62X4E.woff2 +0 -0
  76. package/src/ui/dist/assets/KaTeX_Script-Regular-72OLXYNA.ttf +0 -0
  77. package/src/ui/dist/assets/KaTeX_Script-Regular-A5IFOEBS.woff +0 -0
  78. package/src/ui/dist/assets/KaTeX_Script-Regular-APUWIHLP.woff2 +0 -0
  79. package/src/ui/dist/assets/KaTeX_Size1-Regular-4HRHTS65.woff +0 -0
  80. package/src/ui/dist/assets/KaTeX_Size1-Regular-5LRUTBFT.woff2 +0 -0
  81. package/src/ui/dist/assets/KaTeX_Size1-Regular-7K6AASVL.ttf +0 -0
  82. package/src/ui/dist/assets/KaTeX_Size2-Regular-222HN3GT.ttf +0 -0
  83. package/src/ui/dist/assets/KaTeX_Size2-Regular-K5ZHAIS6.woff +0 -0
  84. package/src/ui/dist/assets/KaTeX_Size2-Regular-LELKET5D.woff2 +0 -0
  85. package/src/ui/dist/assets/KaTeX_Size3-Regular-TLFPAHDE.woff +0 -0
  86. package/src/ui/dist/assets/KaTeX_Size3-Regular-UFCO6WCA.ttf +0 -0
  87. package/src/ui/dist/assets/KaTeX_Size3-Regular-WQRQ47UD.woff2 +0 -0
  88. package/src/ui/dist/assets/KaTeX_Size4-Regular-7PGNVPQK.ttf +0 -0
  89. package/src/ui/dist/assets/KaTeX_Size4-Regular-CDMV7U5C.woff2 +0 -0
  90. package/src/ui/dist/assets/KaTeX_Size4-Regular-PKMWZHNC.woff +0 -0
  91. package/src/ui/dist/assets/KaTeX_Typewriter-Regular-3F5K6SQ6.ttf +0 -0
  92. package/src/ui/dist/assets/KaTeX_Typewriter-Regular-MJMFSK64.woff +0 -0
  93. package/src/ui/dist/assets/KaTeX_Typewriter-Regular-VBYJ4NRC.woff2 +0 -0
  94. package/src/ui/dist/assets/figtree-latin-400-normal-PORFSHKN.woff2 +0 -0
  95. package/src/ui/dist/assets/figtree-latin-500-normal-AHYR5JKA.woff2 +0 -0
  96. package/src/ui/dist/assets/figtree-latin-600-normal-5C6Z7QEI.woff2 +0 -0
  97. package/src/ui/dist/assets/figtree-latin-700-normal-M33EANAW.woff2 +0 -0
  98. package/src/ui/dist/assets/figtree-latin-ext-400-normal-CK4ZBFIX.woff2 +0 -0
  99. package/src/ui/dist/assets/figtree-latin-ext-500-normal-M4H6A6MQ.woff2 +0 -0
  100. package/src/ui/dist/assets/figtree-latin-ext-600-normal-KUZFNAIE.woff2 +0 -0
  101. package/src/ui/dist/assets/figtree-latin-ext-700-normal-U3DQVDYX.woff2 +0 -0
  102. package/src/ui/dist/popup.css +1 -0
  103. package/src/ui/dist/popup.js +546 -0
  104. package/src/ui/popup.html +13 -0
  105. package/src/ui/state.js +89 -0
  106. package/src/visual.js +229 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pocket Tutor contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,172 @@
1
- # Temporary Holding Version
1
+ # Pocket Tutor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An AI search box for your whole laptop. Press **Ctrl+Alt+Space** in any Windows app. If you have text selected, a small box opens at your cursor and explains it in plain English. If nothing is selected, the box opens as a question line, and you can ask anything. It works on a word in a PDF, an error message in a terminal, a line of code you didn't write, or a formula on a lecture slide. It is built for people who code with AI help and keep running into things they don't understand.
4
+
5
+ It talks to any OpenAI-compatible model: OpenAI, OpenRouter, a free Nemotron key from Vercel, or a model on your own machine through Ollama (no key, and nothing leaves your laptop). There is also a terminal command, `pocket-tutor explain`, that works on macOS and Linux too.
6
+
7
+ ## Install
8
+
9
+ You need [Node.js 24 or newer](https://nodejs.org). The tray app needs Windows 10 or 11.
10
+
11
+ ```powershell
12
+ npm install -g pocket-tutor
13
+ pocket-tutor doctor # checks your model, web search and git
14
+ pocket-tutor # starts the tray app
15
+ ```
16
+
17
+ Or run it from a clone:
18
+
19
+ ```powershell
20
+ git clone https://github.com/advaithsarva/pocket-tutor.git
21
+ cd pocket-tutor
22
+ npm install
23
+ npm start
24
+ ```
25
+
26
+ The package installs Electron, so the first install downloads about 100 MB.
27
+
28
+ ## Pick a model
29
+
30
+ Set one of these, then run `pocket-tutor doctor`. Use `setx` if you want a variable to survive a restart.
31
+
32
+ | You have | Set |
33
+ |---|---|
34
+ | An OpenAI key | `OPENAI_API_KEY` (default model `gpt-4o-mini`) |
35
+ | An OpenRouter key | `OPENROUTER_API_KEY` |
36
+ | A free Vercel AI Gateway key | `AI_GATEWAY_API_KEY` (Nemotron 3.5 Lightning) |
37
+ | A Gemini or Groq key | `GEMINI_API_KEY` or `GROQ_API_KEY` |
38
+ | Ollama or LM Studio on this machine | `POCKET_TUTOR_BASE_URL=http://localhost:11434/v1` and `POCKET_TUTOR_MODEL=llama3.2`. No key needed. |
39
+ | Any other OpenAI-compatible server | `POCKET_TUTOR_BASE_URL`, `POCKET_TUTOR_MODEL`, and `POCKET_TUTOR_LLM_KEY` (or `OPENAI_API_KEY`) |
40
+
41
+ `POCKET_TUTOR_MODEL` changes the model for any provider. If you name no provider, the first key found wins, in the order of the table. Some newer OpenAI models reject `max_tokens` or a custom `temperature`. Pocket Tutor reads the error, drops that setting and retries, so there is nothing to configure.
42
+
43
+ The free Nemotron model is served through NVIDIA, which [may keep prompts and replies to improve its models](https://vercel.com/ai-gateway/models/nemotron-3.5-lightning-free). That includes your selection and any code snippets sent with it. Use your own key or a local model for private work.
44
+
45
+ ## Use it
46
+
47
+ 1. Select text anywhere.
48
+ 2. Press **Ctrl+Alt+Space**.
49
+ 3. Read the answer. The box keeps the size it opened at, and a long answer scrolls.
50
+
51
+ **To ask a question instead**, press the hotkey with nothing selected. The box opens with the cursor in a question line, and your question gets the same treatment as a selection: your project, your earlier lookups and the web.
52
+
53
+ The box has four controls:
54
+
55
+ - **The text line at the bottom** is for questions. If the answer didn't make sense, type what confuses you and press Enter. An empty Enter asks for the same thing again, simpler. It remembers your last four questions about that lookup.
56
+ - **Explain in detail** opens a larger window with a full lesson of 1,200 to 2,000 words: an analogy, the steps, the maths with small numbers, a commented example, a comparison table and a few practice questions. It also lists the code it found and links to read more.
57
+ - **Minimize** shrinks the box to a small "0". Click it to bring the box back.
58
+ - **Close**, or press Esc.
59
+
60
+ From a terminal, on any system:
61
+
62
+ ```bash
63
+ pocket-tutor explain "what is a mutex"
64
+ echo "KeyError: 'user_id'" | pocket-tutor explain
65
+ ```
66
+
67
+ ## It finds your workspace for you
68
+
69
+ You never say which project you mean. When you press the hotkey, Pocket Tutor looks at the window you are in:
70
+
71
+ - **VS Code, Cursor, Windsurf, VSCodium:** it reads the project folder from the title bar and finds its path from the editor's recent folders. If the title shows no folder, it uses the folder that editor had open last.
72
+ - **Terminals:** it reads the folder from the window title when the title shows one.
73
+ - **Any other app:** no workspace, so it answers from the text, your earlier lookups and the web.
74
+
75
+ With a workspace, the model gets a short overview (the project name, its dependencies and the start of the README) and snippets found with `git grep`, which includes Markdown notes and files you haven't committed. Answers point to `path:line`, which opens in your editor.
76
+
77
+ It also keeps a small graph of what you looked up before (idea names, one-sentence summaries, file paths), so a later answer can build on an earlier one. The graph lives in `%USERPROFILE%\.pocket-tutor\graph.json`. Choose **Forget saved context** in the tray menu to delete it.
78
+
79
+ ## Math animations with ManimGL
80
+
81
+ For a formula, Pocket Tutor can draw a short animation: the formula is typeset, built piece by piece, and each part gets a colour and a plain-English note. It uses [ManimGL](https://github.com/3b1b/manim), the animation engine Grant Sanderson (3Blue1Brown) wrote for his videos. It is MIT licensed, and it is not the separate Manim Community Edition.
82
+
83
+ The animation is off until you install it, because it needs Python 3.12 and a few hundred MB of packages:
84
+
85
+ ```powershell
86
+ pocket-tutor setup-visuals
87
+ ```
88
+
89
+ After that, it runs when the model decides the selection is a formula or an equation. Ordinary words and code never trigger it. The model only fills in a small JSON description (formula, parts, notes), and one fixed scene file, `scripts/visual_scene.py`, draws it, so nothing the model writes is run as code. The rules a clip must meet are in [docs/CLIP_RULES.md](docs/CLIP_RULES.md).
90
+
91
+ ## Privacy
92
+
93
+ - Nothing is read until you press the hotkey. Then it copies the selection and reads the window title.
94
+ - Password managers and private browser windows are skipped, and nothing is copied from them.
95
+ - Keys, tokens, passwords, private keys and email addresses are masked in the selection and in code snippets before they leave your computer. Files such as `.env`, `*.pem` and `id_rsa` are never searched.
96
+ - The model receives the selection, the window title, up to six code snippets and a few lines from your graph. For a short prose selection (25 words or fewer, not code), the first ten words also go to DuckDuckGo, or to the search engine you chose.
97
+ - Your clipboard is restored after each copy.
98
+ - API keys stay on your machine, in environment variables or in `%USERPROFILE%\.pocket-tutor\config.json`.
99
+
100
+ ## Settings
101
+
102
+ Everything is optional. The file is `%USERPROFILE%\.pocket-tutor\config.json` (see `config.example.json`):
103
+
104
+ | Key | Default | What it does |
105
+ |---|---|---|
106
+ | `hotkey` | `CommandOrControl+Alt+Space` | Any [Electron accelerator](https://www.electronjs.org/docs/latest/api/accelerator) |
107
+ | `provider` | the first key found | `vercel`, `openai`, `openrouter`, `gemini`, `groq`, `ollama` or `custom` |
108
+ | `base_url`, `model`, `plan_model` | from the provider | Any OpenAI-compatible server. `plan_model` does the small planning step and can be a cheaper model. |
109
+ | `roots` | `["C:\\Projects"]` | Folders searched for the project named in the editor's title |
110
+ | `max_snippets`, `web_results` | 6, 5 | How much context goes to the model |
111
+ | `search_engine` | `brave` if a key is set, else `searxng` if a URL is set, else `duckduckgo` | Where web context comes from. See below. |
112
+ | `visuals` | `true` | Math animations, once ManimGL is installed |
113
+ | `remember` | `true` | Keep the graph of earlier lookups |
114
+
115
+ Choose **Reload settings** in the tray menu after editing.
116
+
117
+ ### Web search engines
118
+
119
+ Web results only feed the answer, and only for short prose selections. Code is never sent to a search engine. Pick one:
120
+
121
+ | Engine | Set | Notes |
122
+ |---|---|---|
123
+ | DuckDuckGo | nothing | The default. No key. |
124
+ | Brave | `BRAVE_API_KEY` | Has a free tier. |
125
+ | SearXNG | `SEARXNG_URL` | Your own instance, with `json` listed under `search.formats` in its settings. |
126
+
127
+ Set `search_engine` (or `POCKET_TUTOR_SEARCH`) to choose one explicitly. If the chosen engine fails, for example a wrong key or a used-up quota, that lookup falls back to DuckDuckGo.
128
+
129
+ ## Frequently asked questions
130
+
131
+ **Does it only work in VS Code?** No. It works in any app where you can select text and copy it. VS Code, Cursor, Windsurf and VSCodium also get answers that refer to your own project.
132
+
133
+ **Can I use a local model?** Yes. Start Ollama, set `POCKET_TUTOR_BASE_URL=http://localhost:11434/v1`, and set `POCKET_TUTOR_MODEL` to a model you have pulled. No key is needed.
134
+
135
+ **Does it run on macOS or Linux?** The tray app does not yet, because it uses Windows calls to find the active window and copy the selection. `pocket-tutor explain` runs anywhere Node runs.
136
+
137
+ **Why Ctrl+Alt+Space?** Ctrl+Shift+Space is taken by VS Code's parameter hints and several input tools. Ctrl+Alt+Space is rarely bound. Pick your own with `hotkey`.
138
+
139
+ **The hotkey does nothing.** Another app may already use it. The tray tooltip says so. Set a different `hotkey` and choose **Reload settings**.
140
+
141
+ **It says no model is set up.** Run `pocket-tutor doctor`. It names what is missing.
142
+
143
+ **Why are there no math animations?** Either you haven't run `pocket-tutor setup-visuals`, or the selection wasn't a formula. `pocket-tutor doctor` reports whether ManimGL is installed.
144
+
145
+ ## Develop
146
+
147
+ ```powershell
148
+ npm test # unit tests and a fake OpenAI-compatible server; no key or network
149
+ npm run build # bundles the box into src/ui/dist
150
+ npm run judge-clips # measures rendered math clips (needs ManimGL)
151
+ $env:POCKET_TUTOR_SELFTEST="$env:TEMP\box.png"; npx electron . # renders a sample box to a PNG
152
+ ```
153
+
154
+ | File | Job |
155
+ |---|---|
156
+ | `bin/pocket-tutor.js` | The command line |
157
+ | `src/main.js` | Hotkey, clipboard, the explain pipeline, the box and the tray |
158
+ | `src/helper.ps1`, `src/native.js` | A PowerShell helper that finds the active window and presses Ctrl+C |
159
+ | `src/model.js` | Prompts and an OpenAI-compatible streaming client that adapts to each server |
160
+ | `src/config.js` | Provider presets, keys and settings |
161
+ | `src/project.js`, `src/graph.js`, `src/search.js` | Code search, the graph of earlier lookups, web search |
162
+ | `src/privacy.js` | Blocked apps, secret files, masking |
163
+ | `src/visual.js`, `scripts/visual_scene.py` | Math animations with ManimGL |
164
+ | `src/ui/` | The box, built with Astryx components |
165
+
166
+ ## Credits
167
+
168
+ [ManimGL](https://github.com/3b1b/manim) for the math animations, [KaTeX](https://katex.org) for typesetting, [Astryx](https://www.npmjs.com/package/@astryxdesign/core) for the interface, [Electron](https://www.electronjs.org) for the window.
169
+
170
+ ## License
171
+
172
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ // pocket-tutor: the command line for the package.
3
+ // pocket-tutor start the tray app (Windows): select text anywhere, press the hotkey
4
+ // pocket-tutor explain [text] explain text in the terminal (any OS); reads stdin when no text is given
5
+ // pocket-tutor doctor check the model, web search, math clips and git
6
+ // pocket-tutor setup-visuals optional: install ManimGL for math animations
7
+ const path = require('path')
8
+ const { spawn } = require('child_process')
9
+
10
+ const ROOT = path.join(__dirname, '..')
11
+ const HELP = `Pocket Tutor: select any text, get a short explanation in plain English.
12
+
13
+ pocket-tutor start the tray app (Windows). Select text, press Ctrl+Alt+Space
14
+ pocket-tutor explain [text] explain text here in the terminal; reads stdin if no text is given
15
+ pocket-tutor doctor check the model, web search, math animations and git
16
+ pocket-tutor setup-visuals optional: install ManimGL, which draws math animations
17
+
18
+ Model: any OpenAI-compatible server. Examples (PowerShell):
19
+ $env:OPENAI_API_KEY="..." OpenAI
20
+ $env:POCKET_TUTOR_BASE_URL="http://localhost:11434/v1"; $env:POCKET_TUTOR_MODEL="llama3.2" Ollama, no key
21
+ $env:AI_GATEWAY_API_KEY="..." free Nemotron through Vercel
22
+ More: https://github.com/advaithsarva/pocket-tutor`
23
+
24
+ async function explain(args) {
25
+ const config = require('../src/config')
26
+ const model = require('../src/model')
27
+ const { mask } = require('../src/privacy')
28
+ let text = args.join(' ').trim()
29
+ if (!text && !process.stdin.isTTY) { let s = ''; for await (const c of process.stdin) s += c; text = s.trim() }
30
+ if (!text) { console.error('Nothing to explain. Pass some text, or pipe it in: echo "RMSNorm" | pocket-tutor explain'); return 2 }
31
+ const cfg = config.load()
32
+ if (!cfg.llm_key) { console.error('No model set up. Run: pocket-tutor doctor'); return 2 }
33
+ const selection = mask(text).slice(0, model.MAX_SELECTION)
34
+ let shown = 0
35
+ try {
36
+ const out = await model.chat(cfg, cfg.model, model.answerMessages(selection, { label: 'terminal' }, [], [], []), {
37
+ maxTokens: 1200, onChunk: (t) => { process.stdout.write(t.slice(shown)); shown = t.length } })
38
+ process.stdout.write(out.slice(shown) + '\n')
39
+ return 0
40
+ } catch (e) { console.error(`Could not explain this: ${e.message}`); return 1 }
41
+ }
42
+
43
+ async function main() {
44
+ const [cmd, ...rest] = process.argv.slice(2)
45
+ if (cmd === 'help' || cmd === '--help' || cmd === '-h') return console.log(HELP)
46
+ if (cmd === 'explain') return process.exit(await explain(rest))
47
+ if (cmd === 'doctor') return require('../scripts/doctor.js')
48
+ if (cmd === 'setup-visuals') return require('../scripts/setup-visuals.js')
49
+ if (cmd && cmd !== 'start') { console.error(`Unknown command "${cmd}".\n\n${HELP}`); return process.exit(2) }
50
+ if (process.platform !== 'win32') { console.error('The tray app needs Windows (it reads the selection with Windows APIs). The terminal command works everywhere: pocket-tutor explain "text"'); return process.exit(1) }
51
+ // a detached Electron process, so the terminal is free again
52
+ const child = spawn(require('electron'), [ROOT], { detached: true, stdio: 'ignore', windowsHide: false })
53
+ child.unref()
54
+ console.log('Pocket Tutor is running in the system tray. Select text anywhere and press Ctrl+Alt+Space.')
55
+ }
56
+
57
+ main()
@@ -0,0 +1,12 @@
1
+ {
2
+ "hotkey": "CommandOrControl+Alt+Space",
3
+ "provider": "vercel",
4
+ "model": "nvidia/nemotron-3.5-lightning-free",
5
+ "plan_model": "nvidia/nemotron-3.5-lightning-free",
6
+ "roots": ["C:\\Projects"],
7
+ "max_snippets": 6,
8
+ "web_results": 5,
9
+ "search_engine": "duckduckgo",
10
+ "visuals": true,
11
+ "remember": true
12
+ }
@@ -0,0 +1,38 @@
1
+ # Math clip rules
2
+
3
+ The math clip is Pocket Tutor's short ManimGL animation for a formula. It should teach the way a 3Blue1Brown video does: the formula is typeset properly and written piece by piece; then each part in turn gets its own colour, a brace and a few plain words while the rest dims; it ends on the one line worth remembering.
4
+
5
+ These rules came from a clip that failed every one of them (2026-11-24). The selection read "Forward pass requires O(N_L(Ld^2 + L^2 d)) FLOPs". The clip showed `4 * L * d * (d + L)`, a formula the model made up, in Consolas, inside one yellow box labelled "total FLOPs per layer", on a mostly empty 640×360 frame. The text box above it showed raw `$L^2 d$`.
6
+
7
+ Each rule names the bug it prevents and what enforces it:
8
+ - **Prompt:** the model-facing lines in `model.formulaMessages`.
9
+ - **checkSpec:** `visual.checkSpec`, run on every reply. Problems go back to the model for one retry.
10
+ - **Scene:** fixed behaviour of `scripts/visual_scene.py`.
11
+ - **Judge:** `npm run judge-clips`, which measures rendered frames.
12
+
13
+ | # | Rule | Prevents | Enforced by |
14
+ |---|---|---|---|
15
+ | R1 | **Faithful.** If the selection contains a formula, the clip shows that formula, with the same symbols. It may be rewritten in proper LaTeX, but never swapped for a different, simpler or "equivalent" one. Only a selection without a formula gets the standard formula for the idea. | The screenshot clip: `4·L·d·(d+L)` for a selection about `O(N_L(Ld²+L²d))`. The model had never been shown the selection. | Prompt; checkSpec (the selection's single-letter variables and Greek names must be ≥ 75% present in the formula, and ≥ 40% of the formula's must come from the selection); the selection is now passed in |
16
+ | R2 | **Typeset.** The formula is LaTeX math in the subset that matplotlib's mathtext renders with STIX. No `*`. Function names go in `\mathrm{}`. | Consolas ASCII (`4 * L * d`); `\le` and `\ge`, which mathtext can't render (it can render `\leq` and `\geq`). | checkSpec (`TEX_OK` allow-list, measured by rendering each command; balanced braces; no `*`); the scene repairs an unknown name (`\softmax` → `\mathrm{softmax}`) and only as a last resort draws readable Unicode |
17
+ | R3 | **One colour per part.** 1–4 parts, each a whole group (a whole `\frac{..}{..}`, `\sqrt{..}`, or a symbol with its `^` and `_`), never cut from inside `{ }`, never overlapping. Each part keeps its colour to the end. | One box around everything; a part that can't be cut out and silently vanishes. | Prompt; checkSpec (inside-braces, cut-off script, overlap); the scene drops a part it can't typeset alone rather than faking it; the judge counts the part colours by hue |
18
+ | R4 | **Notes are meaning, not symbols.** At most 8 plain words on what the part does ("every token looks at every other token"), never the symbols read aloud. | "total FLOPs per layer" as the only explanation. | Prompt; checkSpec (at most 9 words, never empty) |
19
+ | R5 | **Big.** The formula is as large as the frame allows: up to 11.5 × 2.6 of the 14.2 × 8 frame units. | A small formula on an empty frame. | Scene; the judge requires ≥ 50% of the frame width or ≥ 16% of its height |
20
+ | R6 | **Inside the frame.** Nothing touches the edges. Braces hang from the formula's bottom line, notes sit under the braces, and both are slid back inside the frame. | A note centred under the last part ran off the right edge; the note under `g` sat on top of the tall fraction beside it. | Scene (`inside`, braces on the formula's floor); the judge allows no ink in the outer 2% of any frame |
21
+ | R7 | **Ends on a takeaway.** One line, at most 70 characters, giving the consequence (how it scales, what it trades off), with the formula still coloured above it. | A clip that just stops; a takeaway that only repeats the title. | Prompt; checkSpec (needed when there are 2+ parts); the judge checks for a line near the bottom of the last frame |
22
+ | R8 | **Budget.** Rendered in ≤ 12 s, ≤ 500 KB, 5–24 s long, at 960×540 and 24 fps. | Sending the box a slow or huge clip; a 4-second loop that flashes past. | `visual.render` settings; the judge |
23
+ | R9 | **3b1b's moves, in this order.** Write the formula left to right; then for each part, colour it, dim the rest, grow a brace and fade the note in; at the end, bring everything back in its colours. Lone brackets are stretched to the fraction they enclose, as `\left( \right)` would be. | The whole formula appearing at once; short brackets beside a tall fraction. | Scene |
24
+ | R10 | **A wrong clip is worse than none.** One retry with the problems listed. After that, parts that still break a rule are dropped, and a formula that still breaks one means no clip at all. | Showing a confident, wrong animation under a correct explanation. | `main.js` with `visual.settle` |
25
+ | R11 | **The spec is data.** The model writes JSON only. The scene is fixed code, and mathtext only parses. | A prompt injected through a web page or selection running Python on the laptop. | `visual.cleanSpec`; the scene file (already a project rule) |
26
+
27
+ ## The same rule in the text box
28
+
29
+ The explanation's math is typeset too. The answer and detail prompts ask for `$…$` and `$$…$$`, and the box renders them with KaTeX (`trust: false`, so no `\href`). If KaTeX can't read a formula, it is shown as code, never as raw dollar signs.
30
+
31
+ ## Checking a change
32
+
33
+ ```bash
34
+ npm test # checkSpec and settle on the screenshot spec and the other cases
35
+ npm run judge-clips # renders test/clips/cases.json and measures the frames; all must pass
36
+ ```
37
+
38
+ The judge writes a contact sheet (`<name>.png`, 12 frames) for each case to `%TEMP%\pocket-tutor-judge`. Look at them as well: a frame can pass every measurement and still look wrong. Add a case to `test/clips/cases.json` whenever a real clip fails in a way the judge missed.
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "pocket-tutor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Select any text, press a hotkey, get a plain-English explanation. Works with any OpenAI-compatible model, including local Ollama. Windows tray app plus a terminal command.",
5
+ "main": "src/main.js",
6
+ "scripts": {
7
+ "build": "node scripts/build-ui.mjs",
8
+ "start": "npm run build && electron .",
9
+ "test": "node --test \"test/*.test.js\"",
10
+ "doctor": "node scripts/doctor.js",
11
+ "setup-visuals": "node scripts/setup-visuals.js",
12
+ "judge-clips": "node scripts/clip-judge.js",
13
+ "prepublishOnly": "npm run build && npm test"
14
+ },
15
+ "devDependencies": {
16
+ "esbuild": "^0.28.2",
17
+ "@astryxdesign/cli": "0.7.17",
18
+ "@astryxdesign/core": "0.7.17",
19
+ "@astryxdesign/theme-neutral": "0.7.17",
20
+ "@stylexjs/stylex": "0.19.2",
21
+ "katex": "0.19.1",
22
+ "react": "19.3.1",
23
+ "react-dom": "19.3.1"
24
+ },
25
+ "dependencies": {
26
+ "electron": "^42.2.0"
27
+ },
28
+ "license": "MIT",
29
+ "keywords": [
30
+ "ai-tutor",
31
+ "cli",
32
+ "code-explainer",
33
+ "desktop",
34
+ "electron",
35
+ "explain",
36
+ "learning",
37
+ "llm",
38
+ "math",
39
+ "nemotron",
40
+ "ollama",
41
+ "openai",
42
+ "openrouter",
43
+ "selected-text",
44
+ "students",
45
+ "study-tool",
46
+ "vscode",
47
+ "windows"
48
+ ],
49
+ "engines": {
50
+ "node": ">=24"
51
+ },
52
+ "bin": {
53
+ "pocket-tutor": "bin/pocket-tutor.js"
54
+ },
55
+ "files": [
56
+ "bin",
57
+ "src",
58
+ "scripts/doctor.js",
59
+ "scripts/setup-visuals.js",
60
+ "scripts/visual_scene.py",
61
+ "scripts/clip-judge.js",
62
+ "scripts/build-ui.mjs",
63
+ "docs",
64
+ "config.example.json",
65
+ "LICENSE",
66
+ "README.md"
67
+ ],
68
+ "homepage": "https://github.com/advaithsarva/pocket-tutor#readme",
69
+ "repository": {
70
+ "type": "git",
71
+ "url": "git+https://github.com/advaithsarva/pocket-tutor.git"
72
+ },
73
+ "bugs": {
74
+ "url": "https://github.com/advaithsarva/pocket-tutor/issues"
75
+ }
76
+ }
@@ -0,0 +1,25 @@
1
+ // npm run build: bundles the popup (src/ui/app.jsx + Astryx + the lens theme) into src/ui/dist/.
2
+ // `npm start` runs this first.
3
+ import * as esbuild from 'esbuild'
4
+ import { fileURLToPath } from 'node:url'
5
+ import path from 'node:path'
6
+
7
+ const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
8
+
9
+ await esbuild.build({
10
+ absWorkingDir: root,
11
+ entryPoints: { popup: 'src/ui/app.jsx' },
12
+ outdir: 'src/ui/dist',
13
+ bundle: true,
14
+ minify: true,
15
+ sourcemap: false,
16
+ format: 'iife',
17
+ platform: 'browser',
18
+ target: 'chrome130',
19
+ jsx: 'automatic',
20
+ define: { 'process.env.NODE_ENV': '"production"' },
21
+ loader: { '.woff2': 'file', '.woff': 'file', '.ttf': 'file', '.otf': 'file', '.svg': 'file', '.png': 'file' },
22
+ assetNames: 'assets/[name]-[hash]',
23
+ logLevel: 'warning',
24
+ })
25
+ console.log('built src/ui/dist/popup.js and popup.css')
@@ -0,0 +1,106 @@
1
+ // npm run judge-clips: the outside judge for the math clip. It renders every case in test/clips/cases.json
2
+ // through the app's own visual.render, decodes the frames with ffmpeg and measures them, so "the clip is
3
+ // good" is a number, not an opinion. Rules it checks are in docs/CLIP_RULES.md (R-numbers below).
4
+ // node scripts/clip-judge.js [case-name ...] → a table, contact sheets in <tmp>/pocket-tutor-judge, exit 1 on a failure
5
+ // Needs `pocket-tutor setup-visuals`. Doesn't call any model and needs no key.
6
+ const fs = require('fs')
7
+ const os = require('os')
8
+ const path = require('path')
9
+ const { execFileSync } = require('child_process')
10
+ const visual = require('../src/visual')
11
+
12
+ const ROOT = path.join(__dirname, '..')
13
+ const FFMPEG = path.join(require('../src/config').HOME, 'venv', 'Scripts', 'ffmpeg.exe')
14
+ const OUT = path.join(os.tmpdir(), 'pocket-tutor-judge')
15
+ const W = 320, H = 180, FPS = 6
16
+ const PALETTE = [[0x58, 0xC4, 0xDD], [0xF4, 0xD3, 0x45], [0x83, 0xC1, 0x67], [0xFC, 0x62, 0x55]]
17
+ // hue in degrees, or null for pixels too dark or too grey to have one (black, white, the dimmed formula)
18
+ function hue(r, g, b) {
19
+ const max = Math.max(r, g, b), min = Math.min(r, g, b), c = max - min
20
+ if (max < 70 || c / max < 0.35) return null
21
+ const h = max === r ? ((g - b) / c) % 6 : max === g ? (b - r) / c + 2 : (r - g) / c + 4
22
+ return (h * 60 + 360) % 360
23
+ }
24
+ const PAL_HUES = PALETTE.map(([r, g, b]) => hue(r, g, b))
25
+ const LIMITS = { renderMs: 12000, bytes: 500 * 1024, minS: 5, maxS: 24, minWidth: 0.5, minHeight: 0.16, edge: 0.02 }
26
+
27
+ function frames(mp4) {
28
+ const raw = execFileSync(FFMPEG, ['-v', 'error', '-i', mp4, '-vf', `fps=${FPS},scale=${W}:${H}`, '-f', 'rawvideo', '-pix_fmt', 'rgb24', 'pipe:1'],
29
+ { maxBuffer: 1 << 28 })
30
+ const n = Math.floor(raw.length / (W * H * 3))
31
+ return Array.from({ length: n }, (_, i) => raw.subarray(i * W * H * 3, (i + 1) * W * H * 3))
32
+ }
33
+
34
+ function measure(fr) {
35
+ const ink = (f, x, y) => { const i = (y * W + x) * 3; return f[i] + f[i + 1] + f[i + 2] > 150 }
36
+ const ex = Math.ceil(W * LIMITS.edge), ey = Math.ceil(H * LIMITS.edge)
37
+ let edgeHits = 0, bestW = 0, bestH = 0
38
+ const colourFrames = PALETTE.map(() => 0)
39
+ for (const f of fr) {
40
+ // R6: nothing touches the frame's edge
41
+ for (let y = 0; y < H; y++) for (let x = 0; x < W; x++) {
42
+ if ((x < ex || x >= W - ex || y < ey || y >= H - ey) && ink(f, x, y)) edgeHits++
43
+ }
44
+ // R5: the formula is big: ink extent in the formula band (between the title and the notes)
45
+ let x0 = W, x1 = -1, y0 = H, y1 = -1
46
+ for (let y = Math.floor(H * 0.16); y < Math.floor(H * 0.62); y++) for (let x = 0; x < W; x++) {
47
+ if (ink(f, x, y)) { if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y }
48
+ }
49
+ if (x1 >= 0) { bestW = Math.max(bestW, (x1 - x0) / W); bestH = Math.max(bestH, (y1 - y0) / H) }
50
+ // R3: each part gets its own colour. Matched by hue, not RGB distance: small antialiased text (a yellow g,
51
+ // its note) is blended with black at this size, so an exact-colour match missed a part that was plainly there.
52
+ const hits = PALETTE.map(() => 0)
53
+ for (let i = 0; i < f.length; i += 3) {
54
+ const h = hue(f[i], f[i + 1], f[i + 2])
55
+ if (h == null) continue
56
+ PAL_HUES.forEach((ph, k) => { if (Math.min(Math.abs(h - ph), 360 - Math.abs(h - ph)) < 16) hits[k]++ })
57
+ }
58
+ hits.forEach((n, k) => { if (n >= 12) colourFrames[k]++ })
59
+ }
60
+ // R7: the last frame has the takeaway line near the bottom
61
+ const last = fr[fr.length - 1]
62
+ let bottomInk = 0
63
+ for (let y = Math.floor(H * 0.78); y < H - ey; y++) for (let x = 0; x < W; x++) if (ink(last, x, y)) bottomInk++
64
+ return { edgeHits, bestW, bestH, colours: colourFrames.filter((c) => c >= 2).length, bottomInk }
65
+ }
66
+
67
+ async function judge(c) {
68
+ const t = Date.now()
69
+ let bytes
70
+ try { bytes = await visual.render(visual.cleanSpec(c.spec) || c.spec) } catch (e) { return { name: c.name, fail: [`render failed: ${e.message}`] } }
71
+ const ms = Date.now() - t
72
+ const mp4 = path.join(OUT, `${c.name}.mp4`)
73
+ fs.writeFileSync(mp4, bytes)
74
+ const fr = frames(mp4)
75
+ const secs = fr.length / FPS
76
+ const m = measure(fr)
77
+ execFileSync(FFMPEG, ['-v', 'error', '-y', '-i', mp4, '-vf', `fps=${(12 / secs).toFixed(3)},scale=480:-1,tile=3x4:padding=4:color=gray`, '-frames:v', '1', path.join(OUT, `${c.name}.png`)])
78
+ const fail = []
79
+ if (ms > LIMITS.renderMs) fail.push(`R8 render ${ms} ms > ${LIMITS.renderMs}`)
80
+ if (bytes.length > LIMITS.bytes) fail.push(`R8 ${Math.round(bytes.length / 1024)} KB > ${LIMITS.bytes / 1024}`)
81
+ if (secs < LIMITS.minS || secs > LIMITS.maxS) fail.push(`R8 length ${secs.toFixed(1)} s outside ${LIMITS.minS}-${LIMITS.maxS}`)
82
+ if (m.edgeHits > 0) fail.push(`R6 ink touches the frame edge (${m.edgeHits} px)`)
83
+ if (m.bestW < LIMITS.minWidth && m.bestH < LIMITS.minHeight) fail.push(`R5 formula too small (${Math.round(m.bestW * 100)}% wide, ${Math.round(m.bestH * 100)}% tall)`)
84
+ if (m.colours < c.expect.colours) fail.push(`R3 ${m.colours} part colours seen, want ${c.expect.colours}`)
85
+ if (c.expect.takeaway && m.bottomInk < 40) fail.push('R7 no takeaway line on the last frame')
86
+ return { name: c.name, ms, kb: Math.round(bytes.length / 1024), secs, ...m, fail }
87
+ }
88
+
89
+ async function main() {
90
+ if (!visual.available()) { console.log('ManimGL is not set up: run pocket-tutor setup-visuals'); process.exit(2) }
91
+ fs.mkdirSync(OUT, { recursive: true })
92
+ const only = process.argv.slice(2)
93
+ const cases = JSON.parse(fs.readFileSync(path.join(ROOT, 'test', 'clips', 'cases.json'), 'utf8')).filter((c) => !only.length || only.includes(c.name))
94
+ let bad = 0
95
+ for (const c of cases) {
96
+ const r = await judge(c)
97
+ const stats = r.ms ? `${(r.ms / 1000).toFixed(1)} s render · ${r.kb} KB · ${r.secs.toFixed(1)} s clip · ${Math.round(r.bestW * 100)}% wide · ${r.colours} colours` : ''
98
+ console.log(`${r.fail.length ? 'FAIL' : 'pass'} ${c.name.padEnd(26)} ${stats}`)
99
+ for (const f of r.fail) console.log(` ${f}`)
100
+ bad += r.fail.length ? 1 : 0
101
+ }
102
+ console.log(`\n${cases.length - bad}/${cases.length} clips pass. Contact sheets: ${OUT}`)
103
+ process.exit(bad ? 1 : 0)
104
+ }
105
+
106
+ main()
@@ -0,0 +1,58 @@
1
+ // pocket-tutor doctor: checks the settings, the model key and model name, web search, the math clips, the
2
+ // context graph, Chrome and git. Prints which keys are set, never the keys themselves.
3
+ const fs = require('fs')
4
+ const { execFileSync } = require('child_process')
5
+ const config = require('../src/config')
6
+ const model = require('../src/model')
7
+ const graph = require('../src/graph')
8
+ const visual = require('../src/visual')
9
+ const { findChrome } = require('../src/browser')
10
+ const { webSearch } = require('../src/search')
11
+
12
+ const ok = (m) => console.log(` ok ${m}`)
13
+ const bad = (m) => console.log(` FIX ${m}`)
14
+ const KEYS = { vercel: 'vercel.com → AI Gateway → API Keys (free)', gemini: 'aistudio.google.com/apikey (free)', groq: 'console.groq.com/keys' }
15
+
16
+ async function main() {
17
+ const cfg = config.load()
18
+ console.log(`Pocket Tutor doctor (settings: ${config.FILE})`)
19
+ console.log(` hotkey ${cfg.hotkey} · ${cfg.provider}: ${cfg.model}${cfg.plan_model !== cfg.model ? ` (planner ${cfg.plan_model})` : ''} · roots ${cfg.roots.join(', ')}`)
20
+
21
+ if (!cfg.llm_key) bad(`no model set up. Any OpenAI-compatible server works. Pick one:
22
+ OPENAI_API_KEY (OpenAI) · OPENROUTER_API_KEY · AI_GATEWAY_API_KEY (free Nemotron: ${KEYS.vercel})
23
+ or a local server with no key: POCKET_TUTOR_BASE_URL=http://localhost:11434/v1 and POCKET_TUTOR_MODEL=llama3.2 (Ollama)`)
24
+ else {
25
+ try {
26
+ // one tiny request through the app's own client: proves the key, the model name and that there is credit left
27
+ await model.chat(cfg, cfg.model, [{ role: 'user', content: 'Say ok.' }], { maxTokens: 200, timeoutMs: 30000 })
28
+ ok(`model ${cfg.model} answered (${cfg.base_url})`)
29
+ } catch (e) { bad(`model ${cfg.model} at ${cfg.base_url}: ${e.message}`) }
30
+ }
31
+
32
+ try {
33
+ const r = await webSearch('rotary position embedding', cfg, 3)
34
+ ;(r.length ? ok : bad)(`web search (${cfg.search_engine}) gave ${r.length} results`)
35
+ } catch (e) { bad(`web search failed: ${e.message}`) }
36
+
37
+ if (!cfg.visuals) ok('math clips are off ("visuals": false)')
38
+ else if (!visual.available()) bad('math clips need ManimGL (optional): run pocket-tutor setup-visuals once')
39
+ else {
40
+ try {
41
+ const t = Date.now()
42
+ const mp4 = await visual.render({ title: 'Check', formula: 'a² + b² = c²', parts: [{ text: 'c²', note: 'the long side, squared' }] })
43
+ ok(`ManimGL rendered a test clip (${Math.round(mp4.length / 1024)} KB in ${((Date.now() - t) / 1000).toFixed(1)} s)`)
44
+ } catch (e) { bad(`ManimGL failed: ${e.message}`) }
45
+ }
46
+
47
+ if (!cfg.remember) ok('context graph is off ("remember": false)')
48
+ else {
49
+ const g = graph.load(config.GRAPH)
50
+ ok(`context graph: ${Object.keys(g.nodes).length} nodes, ${g.edges.length} links${fs.existsSync(config.GRAPH) ? ` (${config.GRAPH})` : ' (made on the first lookup)'}`)
51
+ }
52
+
53
+ const chrome = findChrome(cfg.browser)
54
+ chrome ? ok(`Chrome: ${chrome}`) : bad('Chrome not found; links will open in the default browser')
55
+ try { ok(`git: ${execFileSync('git', ['--version'], { encoding: 'utf8' }).trim()}`) } catch { bad('git not found; code search falls back to a slower file walk') }
56
+ }
57
+
58
+ main()
@@ -0,0 +1,27 @@
1
+ // pocket-tutor setup-visuals: once, for the math clips. Makes a Python venv in the settings folder with ManimGL
2
+ // (https://github.com/3b1b/manim) and a bundled ffmpeg.
3
+ // Uses uv when it's installed (fast), else python -m venv + pip. No LaTeX needed: matplotlib's mathtext typesets the formulas.
4
+ const fs = require('fs')
5
+ const path = require('path')
6
+ const { execFileSync } = require('child_process')
7
+
8
+ const ROOT = path.join(__dirname, '..')
9
+ const VENV = path.join(require('../src/config').HOME, 'venv')
10
+ const PY = path.join(VENV, 'Scripts', 'python.exe')
11
+ // manimgl still imports pkg_resources, which setuptools 80+ no longer ships
12
+ const PACKAGES = ['manimgl', 'matplotlib', 'imageio-ffmpeg', 'setuptools<80'] // matplotlib typesets the formula (mathtext)
13
+
14
+ const run = (cmd, args) => { console.log(`> ${cmd} ${args.join(' ')}`); execFileSync(cmd, args, { stdio: 'inherit', cwd: ROOT }) }
15
+ const has = (cmd) => { try { execFileSync(cmd, ['--version'], { stdio: 'ignore' }); return true } catch { return false } }
16
+
17
+ if (has('uv')) {
18
+ if (!fs.existsSync(PY)) run('uv', ['venv', VENV, '--python', '3.12'])
19
+ run('uv', ['pip', 'install', '--python', PY, ...PACKAGES])
20
+ } else {
21
+ if (!fs.existsSync(PY)) run('python', ['-m', 'venv', VENV])
22
+ run(PY, ['-m', 'pip', 'install', ...PACKAGES])
23
+ }
24
+ // manimgl calls "ffmpeg" from PATH; visual.js puts the venv's Scripts folder first, so a copy there is enough
25
+ const ffmpeg = execFileSync(PY, ['-c', 'import imageio_ffmpeg; print(imageio_ffmpeg.get_ffmpeg_exe())'], { encoding: 'utf8' }).trim()
26
+ fs.copyFileSync(ffmpeg, path.join(VENV, 'Scripts', 'ffmpeg.exe'))
27
+ console.log('ManimGL is ready. Run pocket-tutor doctor to check.')