feat(ocr): one-click "Set up local reading for me" — detect Ollama, pull the model over HTTP with progress, fill settings (desktop) #27

Merged
daniel merged 5 commits from agent/ollama-managed-setup into main 2026-10-20 19:56:33 +02:00
Collaborator

Closes #26. Part of #8 (managed local engine). This is a hand-off: the branch is a stub at main, and the implementation agent writes everything below.

Goal

Add a desktop-only settings action, "Set up local reading for me", under Settings → Reading handwriting (OCR). It turns the manual Ollama setup in docs/ocr-endpoint-setup.md into a single click:

  • detect a running Ollama;
  • download the model over Ollama's HTTP API with visible progress, after explicit consent;
  • fill the endpoint and model settings;
  • run the existing Test connection.

The manual endpoint settings remain for advanced users.

Why this approach (decisions already made, do not reopen)

  • No child_process / no shelling out to ollama. On #8, @daniel said "calling ollama is acceptable, but direct download would be preferred, model download at runtime is also fine". Ollama's native API does everything the CLI would do:

    • GET /api/version is the installed-and-running probe.
    • GET /api/tags lists local models.
    • POST /api/pull {"model": "...", "stream": true} streams NDJSON progress lines {status, digest?, total?, completed?}. It ends with {"status":"success"}, or with a line containing {"error": "..."}.

    This keeps us clear of require("child_process"), which scripts/check-bundle.mjs rejects (N7, mobile).

  • Progress needs streaming, and requestUrl cannot stream. obsidianHttp (src/main.ts:2366) wraps requestUrl, which buffers the whole response. The pull therefore goes through a small injected NDJSON streaming client. On desktop it is implemented with Node http/https, reached lazily via window.require and gated by Platform.isDesktopApp. Node http from the renderer sends no Origin: app://obsidian.md, so the pull works even before OLLAMA_ORIGINS is set.

    • Do not add a bundled require("http") import. Do not touch the forbidden list in scripts/check-bundle.mjs.
    • Fallback when window.require is unavailable: pull with obsidianHttp and stream:false, showing an indeterminate "Downloading… (this can take a long time)" message.
  • Mobile stays untouched. manifest.json has isDesktopOnly: false. The action is hidden unless Platform.isDesktopApp, and nothing Node-ish is evaluated at module load.

  • The download is never silent. A confirmation modal states the model name and approximate size (~6 GB) before any pull starts.

  • Out of scope here:

    • Setting OLLAMA_ORIGINS automatically.
    • Downloading or running the Ollama installer.

    Both are in the follow-up child issue of #8, which is blocked by #26. This MR only links to the installer and explains the origin step when Test connection reports the 403.

What to change

1. src/transport/ollama.ts (new, pure, no Obsidian imports, like src/transport/ocr.ts)

  • ollamaBase(endpoint: string): string: derive the server root from an OCR endpoint. Strip trailing / and a trailing /v1. http://localhost:11434/v1 → http://localhost:11434.
  • detectOllama(http: HttpClient, base): Promise<{ running: true; version: string } | { running: false; reason: string }>:
    • GET {base}/api/version.
    • A thrown request (connection refused) or a non-200 response gives running: false. Use the same refusal detection style as send() in ocr.ts.
  • listLocalModels(http, base): Promise<string[]>: GET {base}/api/tags, returning models[].name. A non-200 or malformed body throws TransportError.
  • hasModel(names: string[], model: string): boolean: treat x and x:latest as equal.
  • type NdjsonClient = (request: HttpRequest, onLine: (line: string) => void, signal?: AbortSignal) => Promise<{ status: number; text: string }>. Put it next to HttpClient in src/transport/http.ts or in ollama.ts; the implementer's choice.
  • createLineSplitter(onLine): a pure helper that takes arbitrary string chunks and emits complete, non-empty lines, holding partial lines across chunk boundaries, with a flush(). The desktop adapter uses it. Unit-test it directly.
  • pullModel(stream: NdjsonClient, base, model, onProgress: (p: { status: string; completed: number; total: number }) => void, signal?): Promise<void>:
    • POSTs {model, stream: true}.
    • Parses each line as JSON.
    • Sums completed/total per digest, so the multi-layer download reports one overall byte count.
    • Resolves on status === "success".
    • Throws TransportError on an error line, on a non-200 status, or if the stream ends without success.

2. Desktop NDJSON adapter in src/main.ts (next to obsidianHttp)

  • desktopNdjson: NdjsonClient | null. It is built lazily and only when Platform.isDesktopApp, from (window as unknown as { require?: (m: string) => unknown }).require, picking http or https by URL scheme.
  • It feeds res.on("data") chunks (utf8) into createLineSplitter.
  • It honours AbortSignal (req.destroy()).
  • Match the file's lint style; no any if lint forbids it.
  • Add a plugin method, e.g. setUpLocalOllama(ui), or keep the flow in the settings tab; the implementer's choice. Keep transport logic in ollama.ts.

3. Settings action in src/settings.ts → ocrActions() (currently L186-211; follow the Test-connection button pattern)

New entry "Set up local reading for me":

  • Description: "Desktop only: finds Ollama on this computer, downloads the handwriting model if needed (you confirm first), and points the plugin at it."
  • Visibility: visible: () => Platform.isDesktopApp, in every OCR mode.

Flow:

  1. detectOllama(obsidianHttp, "http://localhost:11434"). This always targets the local default; it does not reuse a custom remote endpoint.
    • If Ollama is not running, show a modal or notice: "Ollama isn't running on this computer. Install it from ollama.com/download (or start it), then press Set up local reading for me again."
    • Include a button opening https://ollama.com/download via window.open. Stop.
  2. Model to use: settings.ocrModel if non-empty, else DEFAULT_SETTINGS.ocrModel (qwen2.5vl:7b). Check it with listLocalModels and hasModel. If it is present, skip to step 4.
  3. Confirm with an Obsidian Modal: "Download qwen2.5vl:7b (about 6 GB) into Ollama on this computer? It can take a while; you can cancel and resume later." The buttons are Download (cta) and Cancel.
    • On Download, show progress in the modal, throttled to about 2 updates/sec: Downloading qwen2.5vl:7b — 1.2 / 5.9 GB (20%). Show the status text when total is 0.
    • Include a Cancel button that aborts via AbortController. Ollama resumes partial pulls on the next attempt; say so in the cancelled message.
    • Errors go through notify(message, 15000).
  4. Set ocrEndpoint = "http://localhost:11434/v1", ocrModel = <model> and ocrMode = "endpoint". Then saveSettings() and re-render (this.update() / display() as the existing buttons do).
  5. await this.plugin.testOcrConnection().
    • On success, notify "Local reading is set up — at http://localhost:11434/v1."
    • On TransportError, show its message (15 s). The existing mapStatus() in ocr.ts already turns a key-less 403 into the OLLAMA_ORIGINS=app://obsidian.md hint. Append: "See the setup guide: docs/ocr-endpoint-setup.md → step 2."

4. Docs

  • In docs/ocr-endpoint-setup.md, add a short "One-click setup (desktop)" section before "Ollama, step by step". It describes the button, says the manual steps remain the fallback and the advanced path, and notes that the origin step (2) may still be needed.
  • Add a one-line mention in the README "Vision model endpoint" bullet (README L171).

Tests: src/__tests__/ollama.test.ts (new; fake HttpClient as in src/__tests__/ocr.test.ts)

  • ollamaBase: /v1, trailing slash, and no-suffix cases.
  • detectOllama:
    • 200 {"version":"0.6.0"} → running.
    • A rejected promise (ECONNREFUSED) → not running.
    • 404 → not running.
  • listLocalModels and hasModel, including the :latest equivalence and a malformed body → TransportError.
  • createLineSplitter: a JSON line split across 3 chunks, multiple lines in one chunk, a trailing line emitted on flush().
  • pullModel with a fake NdjsonClient emitting a scripted line sequence:
    • two digests → aggregated completed/total;
    • success → resolves;
    • an {"error":"pull model manifest: file does not exist"} line → rejects with that message;
    • a stream ending without success → rejects;
    • non-200 → rejects.

Scope boundary (NOT in this MR)

  • Automatically setting OLLAMA_ORIGINS (launchctl, systemd, setx).
  • Downloading or running the Ollama installer per OS.
  • LM Studio support (detect-and-guide).

These belong to the follow-up child issue of #8, which is gated on #26. This MR also does not change ocr.ts error mapping, the built-in reader (#4) or in-process reader R&D (#5).

Validation contract

There is no flake.nix, so use nixpkgs node: nix shell nixpkgs#nodejs_22 -c <cmd> (run npm ci first).

  • Red gate (fails today): npx vitest run src/__tests__/ollama.test.ts fails, because the module and tests do not exist on main. After the change it passes.
  • npm test passes in full (no regressions in ocr.test.ts / settingschema.test.ts).
  • npm run build exits 0. This covers tsc, the esbuild production build and scripts/check-bundle.mjs, so it proves no forbidden Node builtin require(...) reached main.js.
  • Positive control for that guard: grep -c 'require("child_process")' main.js → 0. Then confirm the lazy lookup really is lazy: grep -n 'window.require\|\.require' main.js shows it only inside the adapter factory.
  • npm run lint exits 0.
  • Manual (desktop, optional if no Ollama is available): with Ollama stopped, the button shows the install link. With Ollama running and the model absent, the confirm modal appears, progress counts up, and Cancel aborts. Afterwards the settings show mode Endpoint, http://localhost:11434/v1 and qwen2.5vl:7b, and Test connection runs.

🤖 Generated with Claude Code

Closes #26. Part of #8 (managed local engine). This is a hand-off: the branch is a stub at `main`, and the implementation agent writes everything below. ## Goal Add a desktop-only settings action, **"Set up local reading for me"**, under *Settings → Reading handwriting (OCR)*. It turns the manual Ollama setup in `docs/ocr-endpoint-setup.md` into a single click: - detect a running Ollama; - download the model **over Ollama's HTTP API** with visible progress, after explicit consent; - fill the endpoint and model settings; - run the existing Test connection. The manual endpoint settings remain for advanced users. ## Why this approach (decisions already made, do not reopen) - **No `child_process` / no shelling out to `ollama`.** On #8, @daniel said *"calling ollama is acceptable, but direct download would be preferred, model download at runtime is also fine"*. Ollama's native API does everything the CLI would do: - `GET /api/version` is the installed-and-running probe. - `GET /api/tags` lists local models. - `POST /api/pull {"model": "...", "stream": true}` streams NDJSON progress lines `{status, digest?, total?, completed?}`. It ends with `{"status":"success"}`, or with a line containing `{"error": "..."}`. This keeps us clear of `require("child_process")`, which `scripts/check-bundle.mjs` rejects (N7, mobile). - **Progress needs streaming, and `requestUrl` cannot stream.** `obsidianHttp` (`src/main.ts:2366`) wraps `requestUrl`, which buffers the whole response. The pull therefore goes through a small injected **NDJSON streaming client**. On desktop it is implemented with Node `http`/`https`, reached lazily via `window.require` and gated by `Platform.isDesktopApp`. Node http from the renderer sends no `Origin: app://obsidian.md`, so the pull works even before `OLLAMA_ORIGINS` is set. - Do **not** add a bundled `require("http")` import. Do **not** touch the forbidden list in `scripts/check-bundle.mjs`. - Fallback when `window.require` is unavailable: pull with `obsidianHttp` and `stream:false`, showing an indeterminate "Downloading… (this can take a long time)" message. - **Mobile stays untouched.** `manifest.json` has `isDesktopOnly: false`. The action is hidden unless `Platform.isDesktopApp`, and nothing Node-ish is evaluated at module load. - **The download is never silent.** A confirmation modal states the model name and approximate size (~6 GB) before any pull starts. - **Out of scope here:** - Setting `OLLAMA_ORIGINS` automatically. - Downloading or running the Ollama installer. Both are in the follow-up child issue of #8, which is blocked by #26. This MR only *links* to the installer and *explains* the origin step when Test connection reports the 403. ## What to change ### 1. `src/transport/ollama.ts` (new, pure, no Obsidian imports, like `src/transport/ocr.ts`) - `ollamaBase(endpoint: string): string`: derive the server root from an OCR endpoint. Strip trailing `/` and a trailing `/v1`. `http://localhost:11434/v1` → `http://localhost:11434`. - `detectOllama(http: HttpClient, base): Promise<{ running: true; version: string } | { running: false; reason: string }>`: - `GET {base}/api/version`. - A thrown request (connection refused) or a non-200 response gives `running: false`. Use the same refusal detection style as `send()` in `ocr.ts`. - `listLocalModels(http, base): Promise<string[]>`: `GET {base}/api/tags`, returning `models[].name`. A non-200 or malformed body throws `TransportError`. - `hasModel(names: string[], model: string): boolean`: treat `x` and `x:latest` as equal. - `type NdjsonClient = (request: HttpRequest, onLine: (line: string) => void, signal?: AbortSignal) => Promise<{ status: number; text: string }>`. Put it next to `HttpClient` in `src/transport/http.ts` or in `ollama.ts`; the implementer's choice. - `createLineSplitter(onLine)`: a pure helper that takes arbitrary string chunks and emits complete, non-empty lines, holding partial lines across chunk boundaries, with a `flush()`. The desktop adapter uses it. Unit-test it directly. - `pullModel(stream: NdjsonClient, base, model, onProgress: (p: { status: string; completed: number; total: number }) => void, signal?): Promise<void>`: - POSTs `{model, stream: true}`. - Parses each line as JSON. - Sums `completed`/`total` per `digest`, so the multi-layer download reports one overall byte count. - Resolves on `status === "success"`. - Throws `TransportError` on an `error` line, on a non-200 status, or if the stream ends without `success`. ### 2. Desktop NDJSON adapter in `src/main.ts` (next to `obsidianHttp`) - `desktopNdjson: NdjsonClient | null`. It is built lazily and only when `Platform.isDesktopApp`, from `(window as unknown as { require?: (m: string) => unknown }).require`, picking `http` or `https` by URL scheme. - It feeds `res.on("data")` chunks (utf8) into `createLineSplitter`. - It honours `AbortSignal` (`req.destroy()`). - Match the file's lint style; no `any` if lint forbids it. - Add a plugin method, e.g. `setUpLocalOllama(ui)`, or keep the flow in the settings tab; the implementer's choice. Keep transport logic in `ollama.ts`. ### 3. Settings action in `src/settings.ts` → `ocrActions()` (currently L186-211; follow the Test-connection button pattern) New entry **"Set up local reading for me"**: - **Description:** "Desktop only: finds Ollama on this computer, downloads the handwriting model if needed (you confirm first), and points the plugin at it." - **Visibility:** `visible: () => Platform.isDesktopApp`, in every OCR mode. Flow: 1. `detectOllama(obsidianHttp, "http://localhost:11434")`. This always targets the local default; it does not reuse a custom remote endpoint. - If Ollama is not running, show a modal or notice: "Ollama isn't running on this computer. Install it from ollama.com/download (or start it), then press *Set up local reading for me* again." - Include a button opening `https://ollama.com/download` via `window.open`. Stop. 2. Model to use: `settings.ocrModel` if non-empty, else `DEFAULT_SETTINGS.ocrModel` (`qwen2.5vl:7b`). Check it with `listLocalModels` and `hasModel`. If it is present, skip to step 4. 3. Confirm with an Obsidian `Modal`: "Download *qwen2.5vl:7b* (about 6 GB) into Ollama on this computer? It can take a while; you can cancel and resume later." The buttons are Download (cta) and Cancel. - On Download, show progress in the modal, throttled to about 2 updates/sec: `Downloading qwen2.5vl:7b — 1.2 / 5.9 GB (20%)`. Show the status text when `total` is 0. - Include a Cancel button that aborts via `AbortController`. Ollama resumes partial pulls on the next attempt; say so in the cancelled message. - Errors go through `notify(message, 15000)`. 4. Set `ocrEndpoint = "http://localhost:11434/v1"`, `ocrModel = <model>` and `ocrMode = "endpoint"`. Then `saveSettings()` and re-render (`this.update()` / `display()` as the existing buttons do). 5. `await this.plugin.testOcrConnection()`. - On success, notify "Local reading is set up — <model> at http://localhost:11434/v1." - On `TransportError`, show its message (15 s). The existing `mapStatus()` in `ocr.ts` already turns a key-less 403 into the `OLLAMA_ORIGINS=app://obsidian.md` hint. Append: "See the setup guide: docs/ocr-endpoint-setup.md → step 2." ### 4. Docs - In `docs/ocr-endpoint-setup.md`, add a short "One-click setup (desktop)" section before "Ollama, step by step". It describes the button, says the manual steps remain the fallback and the advanced path, and notes that the origin step (2) may still be needed. - Add a one-line mention in the README "Vision model endpoint" bullet (README L171). ## Tests: `src/__tests__/ollama.test.ts` (new; fake `HttpClient` as in `src/__tests__/ocr.test.ts`) - `ollamaBase`: `/v1`, trailing slash, and no-suffix cases. - `detectOllama`: - 200 `{"version":"0.6.0"}` → running. - A rejected promise (`ECONNREFUSED`) → not running. - 404 → not running. - `listLocalModels` and `hasModel`, including the `:latest` equivalence and a malformed body → `TransportError`. - `createLineSplitter`: a JSON line split across 3 chunks, multiple lines in one chunk, a trailing line emitted on `flush()`. - `pullModel` with a fake `NdjsonClient` emitting a scripted line sequence: - two digests → aggregated `completed`/`total`; - `success` → resolves; - an `{"error":"pull model manifest: file does not exist"}` line → rejects with that message; - a stream ending without `success` → rejects; - non-200 → rejects. ## Scope boundary (NOT in this MR) - Automatically setting `OLLAMA_ORIGINS` (launchctl, systemd, setx). - Downloading or running the Ollama installer per OS. - LM Studio support (detect-and-guide). These belong to the follow-up child issue of #8, which is gated on #26. This MR also does not change `ocr.ts` error mapping, the built-in reader (#4) or in-process reader R&D (#5). ## Validation contract There is no `flake.nix`, so use nixpkgs node: `nix shell nixpkgs#nodejs_22 -c <cmd>` (run `npm ci` first). - **Red gate (fails today):** `npx vitest run src/__tests__/ollama.test.ts` fails, because the module and tests do not exist on `main`. After the change it passes. - `npm test` passes in full (no regressions in `ocr.test.ts` / `settingschema.test.ts`). - `npm run build` exits 0. This covers `tsc`, the esbuild production build and `scripts/check-bundle.mjs`, so it proves no forbidden Node builtin `require(...)` reached `main.js`. - **Positive control for that guard:** `grep -c 'require("child_process")' main.js` → 0. Then confirm the lazy lookup really is lazy: `grep -n 'window.require\|\.require' main.js` shows it only inside the adapter factory. - `npm run lint` exits 0. - **Manual (desktop, optional if no Ollama is available):** with Ollama stopped, the button shows the install link. With Ollama running and the model absent, the confirm modal appears, progress counts up, and Cancel aborts. Afterwards the settings show mode Endpoint, `http://localhost:11434/v1` and `qwen2.5vl:7b`, and Test connection runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude self-assigned this 2026-10-20 19:01:38 +02:00
Author
Collaborator

✅ Agent run completed

1m38s · 10 turns · $2.03 · pushed agent/ollama-managed-setup · session saved — new comments resume this run

⚠️ Verification gate not satisfied: awaiting intent review. Outcome parked — not marked done.

✅ **Agent run completed** _1m38s · 10 turns · $2.03 · pushed `agent/ollama-managed-setup` · session saved — new comments resume this run_ ⚠️ _Verification gate not satisfied: awaiting intent review. Outcome parked — not marked done._
Detect a running Ollama, list its models, and pull one with streamed
NDJSON progress summed across layers — no shelling out to the CLI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Desktop-only action: detect Ollama, confirm and pull the model with
streamed progress and Cancel, fill the OCR settings, run Test
connection. The streaming client reaches Node http lazily through
window.require, so nothing Node-only is bundled for mobile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Editing a setting replaces the settings object, so a reference captured
when the action started could be a stale copy by the time it is saved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Collaborator

What changed

  • src/transport/ollama.ts (new, no Obsidian imports): ollamaBase, detectOllama, listLocalModels, hasModel (treats x and x:latest as the same model), createLineSplitter, and pullModel, which sums progress across layers and resolves on success. It throws TransportError on an error line, a non-200 status, a stream that ends without success, or a cancel. Also pullModelBuffered (the stream:false fallback) and describePull (Downloading qwen2.5vl:7b — 1.2 / 5.9 GB (20%)).
  • Desktop streaming client: the body lives in src/transport/nodestream.ts (nodeNdjson(require), structural Node types, no imports). desktopNdjson() in main.ts gates it on Platform.isDesktopApp and passes window.require. It picks http or https per URL, feeds utf8 chunks into the line splitter, and req.destroy()s on abort.
    • I moved the body out of main.ts (the hand-off put it there) so it can be tested against a real HTTP server.
  • "Set up local reading for me" (src/ollamasetup.ts, wired into ocrActions(), desktop only, every OCR mode):
    • If Ollama isn't running, a modal opens with Open ollama.com/download and Check again.
    • If the model is missing, a confirm modal opens with the size, then shows progress (~2 updates/s) with a Cancel. Closing the modal also cancels, so no download keeps going out of sight.
    • It then sets the endpoint, model and ocrMode = endpoint, saves, re-renders and runs Test connection.
  • Docs: a "One-click setup (desktop)" section in docs/ocr-endpoint-setup.md, a line in the README, and a CHANGELOG-INK.md entry.

Decisions to check:

  • The "See the setup guide … step 2" suffix is added to every TransportError from the post-setup Test connection, as the spec says.
  • A model other than the default has no known size, so the confirm modal says "several GB".
  • The requestUrl fallback can't be cancelled. Closing its modal tells the user that Ollama keeps downloading in the background.

Verify

Run locally with the system node:

  • npm test: 723/723 pass, including the new ollama.test.ts (red before the module existed) and nodestream.test.ts.
    • nodestream.test.ts runs a real local server: chunks split mid-JSON, no Origin header, a non-200 body, abort mid-download (the server sees the socket close) and connection refused.
    • Mutation check: removing the abort listener makes the abort test fail.
  • npm run build and npm run lint exit 0.
  • grep -c 'require("child_process")' main.js gives 0, and window.require appears once, inside desktopNdjson().
  • Positive control: planting require("child_process") in a copy of main.js makes check-bundle exit 1.

No CI pipeline has run on this branch. I had no Ollama or Obsidian desktop, so the manual desktop check has not been done.

Follow-ups

  • Setting OLLAMA_ORIGINS automatically, the per-OS installer, and LM Studio stay in the #8 follow-up child, which is blocked by #26.
  • Environment note: under nix shell nixpkgs#nodejs_22, vitest fails at startup because the glibc node can't load rolldown's musl binding on this Alpine runner. The system node works.
## What changed - **`src/transport/ollama.ts`** (new, no Obsidian imports): `ollamaBase`, `detectOllama`, `listLocalModels`, `hasModel` (treats `x` and `x:latest` as the same model), `createLineSplitter`, and `pullModel`, which sums progress across layers and resolves on `success`. It throws `TransportError` on an error line, a non-200 status, a stream that ends without `success`, or a cancel. Also `pullModelBuffered` (the `stream:false` fallback) and `describePull` (`Downloading qwen2.5vl:7b — 1.2 / 5.9 GB (20%)`). - **Desktop streaming client:** the body lives in `src/transport/nodestream.ts` (`nodeNdjson(require)`, structural Node types, no imports). `desktopNdjson()` in `main.ts` gates it on `Platform.isDesktopApp` and passes `window.require`. It picks http or https per URL, feeds utf8 chunks into the line splitter, and `req.destroy()`s on abort. - I moved the body out of `main.ts` (the hand-off put it there) so it can be tested against a real HTTP server. - **"Set up local reading for me"** (`src/ollamasetup.ts`, wired into `ocrActions()`, desktop only, every OCR mode): - If Ollama isn't running, a modal opens with *Open ollama.com/download* and *Check again*. - If the model is missing, a confirm modal opens with the size, then shows progress (~2 updates/s) with a Cancel. Closing the modal also cancels, so no download keeps going out of sight. - It then sets the endpoint, model and `ocrMode = endpoint`, saves, re-renders and runs Test connection. - **Docs:** a "One-click setup (desktop)" section in `docs/ocr-endpoint-setup.md`, a line in the README, and a `CHANGELOG-INK.md` entry. **Decisions to check:** - The "See the setup guide … step 2" suffix is added to every `TransportError` from the post-setup Test connection, as the spec says. - A model other than the default has no known size, so the confirm modal says "several GB". - The `requestUrl` fallback can't be cancelled. Closing its modal tells the user that Ollama keeps downloading in the background. ## Verify Run locally with the system node: - `npm test`: 723/723 pass, including the new `ollama.test.ts` (red before the module existed) and `nodestream.test.ts`. - `nodestream.test.ts` runs a real local server: chunks split mid-JSON, no `Origin` header, a non-200 body, abort mid-download (the server sees the socket close) and connection refused. - Mutation check: removing the abort listener makes the abort test fail. - `npm run build` and `npm run lint` exit 0. - `grep -c 'require("child_process")' main.js` gives 0, and `window.require` appears once, inside `desktopNdjson()`. - Positive control: planting `require("child_process")` in a copy of `main.js` makes `check-bundle` exit 1. No CI pipeline has run on this branch. I had no Ollama or Obsidian desktop, so the manual desktop check has not been done. ## Follow-ups - Setting `OLLAMA_ORIGINS` automatically, the per-OS installer, and LM Studio stay in the #8 follow-up child, which is blocked by #26. - Environment note: under `nix shell nixpkgs#nodejs_22`, vitest fails at startup because the glibc node can't load rolldown's musl binding on this Alpine runner. The system `node` works.
Author
Collaborator

Since my last update: I merged origin/main into the branch to clear the conflict, and pushed it as merge commit 6db5bc5. The only conflict was in CHANGELOG-INK.md, where both sides had added an Unreleased entry, so I kept both. After the merge, locally: npm test passes all 742 tests in 64 files, npm run build and npm run lint exit 0, main.js still has no require("child_process"), and window.require still appears only inside desktopNdjson(). No CI pipeline has run on this branch yet.

Since my last update: I merged `origin/main` into the branch to clear the conflict, and pushed it as merge commit `6db5bc5`. The only conflict was in `CHANGELOG-INK.md`, where both sides had added an *Unreleased* entry, so I kept both. After the merge, locally: `npm test` passes all 742 tests in 64 files, `npm run build` and `npm run lint` exit 0, `main.js` still has no `require("child_process")`, and `window.require` still appears only inside `desktopNdjson()`. No CI pipeline has run on this branch yet.
Author
Collaborator

✅ Agent run completed

2m8s · 16 turns · $0.47

✅ **Agent run completed** _2m8s · 16 turns · $0.47_
Author
Collaborator

Acceptance-intent assessment

#26 asks for a desktop-only "Set up local reading for me" action that does five things: detect Ollama, list its models, pull qwen2.5vl:7b over the HTTP API with progress after explicit consent, fill the endpoint settings, and run Test connection. When Ollama is absent it should offer an installer link and "Check again". The diff delivers all of it, along with the more detailed hand-off spec in the MR description (pure transport/ollama.ts, lazy window.require adapter, stream:false fallback, docs, tests). I re-ran the validation contract on 6db5bc5:

  • ollama.test.ts and nodestream.test.ts: 29/29 pass.
  • npm test: 742/742 pass in 64 files.
  • npm run build exits 0, and check-bundle reports "no Node builtins".
  • npm run lint exits 0.
  • main.js contains 0 require("child_process"), and window.require appears exactly once, inside desktopNdjson() behind Platform.isDesktopApp.

Criteria

#26 scope

  • PASS: desktop-only settings action. ocrActions() gains "Set up local reading for me" with visible: () => Platform.isDesktopApp and no mode gate. The description text matches the spec.
  • PASS: detect running Ollama with GET /api/version. detectOllama always probes http://localhost:11434. Throws and non-200 responses give running:false, using the same refusal regex style as ocr.ts.
  • PASS: list local models with GET /api/tags. listLocalModels returns models[].name. A non-200 or malformed body throws TransportError. hasModel treats x and x:latest as equal.
  • PASS: explicit confirmation before a pull. OllamaPullModal asks "Download qwen2.5vl:7b (about 6 GB) into Ollama on this computer? …" with Download (cta) and Cancel. Nothing is pulled before the click. The issue said ~5 GB; the MR spec's ~6 GB is used.
  • PASS: pull over POST /api/pull with NDJSON progress, no shelling out.
    • pullModel POSTs {model, stream:true} and sums completed/total per digest.
    • It resolves on success and throws TransportError on an error line, a non-200 status, or a stream that ends without success.
    • The progress UI is throttled to 500 ms and shows Downloading … — x / y GB (n%), falling back to the status text when the total is 0.
    • Cancel aborts through AbortController, and the cancelled message says the download resumes.
    • No child_process reaches the bundle (verified).
  • PASS: fill settings, switch to endpoint mode, run Test connection.
    • The action sets ocrEndpoint = http://localhost:11434/v1, ocrModel and ocrMode = "endpoint", then calls saveSettings() and re-renders.
    • It then runs testOcrConnection(). On success it shows a notice; on a TransportError it shows a 15 s notice with the "docs/ocr-endpoint-setup.md → step 2" suffix.
  • PASS: installer link and "Check again" when Ollama is not running. OllamaMissingModal shows the spec's text, a button that runs window.open("https://ollama.com/download"), and "Check again", which re-runs the flow.

MR hand-off spec

  • PASS: streaming client. The streaming body lives in transport/nodestream.ts (its own imports are type-only Node shapes plus createLineSplitter from ollama.ts, nothing from Node or Obsidian). It is reached only through desktopNdjson() in main.ts, which is gated on Platform.isDesktopApp and uses the lazy window.require.
    • It picks http or https by URL scheme, feeds utf8 chunks into createLineSplitter, and calls req.destroy() on abort.
    • The MR spec put this body in main.ts itself. Moving it out is a disclosed placement change that keeps the intent: nothing Node-ish is evaluated at module load.
  • PASS: fallback when window.require is unavailable. pullModelBuffered pulls with stream:false while the modal shows an indeterminate "Downloading… (this can take a long time)".
  • PASS: docs. docs/ocr-endpoint-setup.md gains a "One-click setup (desktop)" section before "Ollama, step by step". It says the manual steps remain the fallback and that step 2 (OLLAMA_ORIGINS) may still be needed. The README "Vision model endpoint" bullet gains a one-line mention.
  • PASS: tests. ollama.test.ts covers every case the spec lists:
    • ollamaBase: /v1, trailing slash, no suffix;
    • detectOllama: 200, refused, 404;
    • tags and :latest, plus a malformed body;
    • the line splitter: 3 chunks, multiple lines, flush;
    • pullModel: digest aggregation, success, error line, no success, non-200.
  • PASS: scope boundary respected. Nothing sets OLLAMA_ORIGINS, no installer is downloaded, there is no LM Studio support, and ocr.ts error mapping is unchanged.

Not verified: the manual desktop check (Ollama + Obsidian), which the contract marks optional, has not been run. No CI pipeline has run on the branch.

Verdict

Approved

## Acceptance-intent assessment #26 asks for a desktop-only "Set up local reading for me" action that does five things: detect Ollama, list its models, pull `qwen2.5vl:7b` over the HTTP API with progress after explicit consent, fill the endpoint settings, and run Test connection. When Ollama is absent it should offer an installer link and "Check again". The diff delivers all of it, along with the more detailed hand-off spec in the MR description (pure `transport/ollama.ts`, lazy `window.require` adapter, `stream:false` fallback, docs, tests). I re-ran the validation contract on `6db5bc5`: - `ollama.test.ts` and `nodestream.test.ts`: 29/29 pass. - `npm test`: 742/742 pass in 64 files. - `npm run build` exits 0, and `check-bundle` reports "no Node builtins". - `npm run lint` exits 0. - `main.js` contains 0 `require("child_process")`, and `window.require` appears exactly once, inside `desktopNdjson()` behind `Platform.isDesktopApp`. ## Criteria **#26 scope** - **PASS: desktop-only settings action.** `ocrActions()` gains "Set up local reading for me" with `visible: () => Platform.isDesktopApp` and no mode gate. The description text matches the spec. - **PASS: detect running Ollama with `GET /api/version`.** `detectOllama` always probes `http://localhost:11434`. Throws and non-200 responses give `running:false`, using the same refusal regex style as `ocr.ts`. - **PASS: list local models with `GET /api/tags`.** `listLocalModels` returns `models[].name`. A non-200 or malformed body throws `TransportError`. `hasModel` treats `x` and `x:latest` as equal. - **PASS: explicit confirmation before a pull.** `OllamaPullModal` asks "Download *qwen2.5vl:7b* (about 6 GB) into Ollama on this computer? …" with Download (cta) and Cancel. Nothing is pulled before the click. The issue said ~5 GB; the MR spec's ~6 GB is used. - **PASS: pull over `POST /api/pull` with NDJSON progress, no shelling out.** - `pullModel` POSTs `{model, stream:true}` and sums `completed`/`total` per digest. - It resolves on `success` and throws `TransportError` on an error line, a non-200 status, or a stream that ends without `success`. - The progress UI is throttled to 500 ms and shows `Downloading … — x / y GB (n%)`, falling back to the status text when the total is 0. - Cancel aborts through `AbortController`, and the cancelled message says the download resumes. - No `child_process` reaches the bundle (verified). - **PASS: fill settings, switch to endpoint mode, run Test connection.** - The action sets `ocrEndpoint = http://localhost:11434/v1`, `ocrModel` and `ocrMode = "endpoint"`, then calls `saveSettings()` and re-renders. - It then runs `testOcrConnection()`. On success it shows a notice; on a `TransportError` it shows a 15 s notice with the "docs/ocr-endpoint-setup.md → step 2" suffix. - **PASS: installer link and "Check again" when Ollama is not running.** `OllamaMissingModal` shows the spec's text, a button that runs `window.open("https://ollama.com/download")`, and "Check again", which re-runs the flow. **MR hand-off spec** - **PASS: streaming client.** The streaming body lives in `transport/nodestream.ts` (its own imports are type-only Node shapes plus `createLineSplitter` from `ollama.ts`, nothing from Node or Obsidian). It is reached only through `desktopNdjson()` in `main.ts`, which is gated on `Platform.isDesktopApp` and uses the lazy `window.require`. - It picks `http` or `https` by URL scheme, feeds utf8 chunks into `createLineSplitter`, and calls `req.destroy()` on abort. - The MR spec put this body in `main.ts` itself. Moving it out is a disclosed placement change that keeps the intent: nothing Node-ish is evaluated at module load. - **PASS: fallback when `window.require` is unavailable.** `pullModelBuffered` pulls with `stream:false` while the modal shows an indeterminate "Downloading… (this can take a long time)". - **PASS: docs.** `docs/ocr-endpoint-setup.md` gains a "One-click setup (desktop)" section before "Ollama, step by step". It says the manual steps remain the fallback and that step 2 (`OLLAMA_ORIGINS`) may still be needed. The README "Vision model endpoint" bullet gains a one-line mention. - **PASS: tests.** `ollama.test.ts` covers every case the spec lists: - `ollamaBase`: `/v1`, trailing slash, no suffix; - `detectOllama`: 200, refused, 404; - tags and `:latest`, plus a malformed body; - the line splitter: 3 chunks, multiple lines, flush; - `pullModel`: digest aggregation, success, error line, no success, non-200. - **PASS: scope boundary respected.** Nothing sets `OLLAMA_ORIGINS`, no installer is downloaded, there is no LM Studio support, and `ocr.ts` error mapping is unchanged. Not verified: the manual desktop check (Ollama + Obsidian), which the contract marks optional, has not been run. No CI pipeline has run on the branch. ## Verdict Approved
daniel merged commit 7a021f888a into main 2026-10-20 19:56:33 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
daniel/obsidian-remarkable-round-trip!27
No description provided.