feat(ocr): download the official Ollama installer, verify it, open it, then continue setup (desktop: macOS/Windows; Linux guide) #33

Merged
daniel merged 8 commits from agent/ollama-installer-download into main 2026-10-21 00:56:15 +02:00
Collaborator

Closes #28 (item 1, installer download; items 2 and 3 are !31 and !32). Part of #8.

When "Set up local reading for me" finds no Ollama, v1 only links to ollama.com/download (OllamaMissingModal in src/ollamasetup.ts). @daniel on #8: "direct download would be preferred". This MR adds that: one click downloads the official, signed installer, checks its published SHA-256, opens it with the OS, waits for Ollama to come up, and carries on into v1's flow (model pull, settings, Test connection).

Research (done on #28; verified 2026-10-20)

  • Official URLs. https://ollama.com/download/{Ollama.dmg,OllamaSetup.exe} → 307 → https://github.com/ollama/ollama/releases/latest/download/<asset> → 302 → release-assets.githubusercontent.com. Latest is v0.40.6.
    • Ollama.dmg is 214 MB.
    • OllamaSetup.exe is 1.58 GB (GPU runtimes included). Tell the user the size before downloading.
  • Integrity. GET https://api.github.com/repos/ollama/ollama/releases/latest returns tag_name and assets[], each with name, size, browser_download_url and digest: "sha256:<hex>". Each release also ships sha256sum.txt, with lines <hex> ./<name> (includes ./Ollama.dmg and ./OllamaSetup.exe). The API digest for Ollama.dmg matches sha256sum.txt.
  • Signing.
    • OllamaSetup.exe is Authenticode-signed by "Ollama Inc." (Toronto) with a DigiCert EV code-signing cert, RFC 3161 timestamped. Checked by reading the PE security directory.
    • macOS: scripts/build_darwin.sh codesigns with the Developer ID (--options=runtime), then notarises with notarytool and staples.
  • Linux. install.sh needs sudo and sets up a systemd service, so it stays guide-only: a copyable curl -fsSL https://ollama.com/install.sh | sh.
  • Launching without child_process. require("electron").shell.openPath(path) (renderer, non-sandboxed, which Obsidian is; electron is already external in esbuild.config.mjs). It resolves "" on success, otherwise an error string.
    • macOS: opening the DMG mounts it and shows Finder's drag-to-Applications window.
    • Windows: it runs the Inno Setup installer, which installs per-user and starts Ollama when it finishes.
  • Why not requestUrl for the download: it buffers the whole body (1.58 GB in memory) and reports no progress. Use a streaming Node client, as v1 does for the pull.

What to change

  1. New src/transport/ollamarelease.ts. Pure over HttpClient (requestUrl, which follows redirects):
    • installerAsset(os: "macos" | "windows" | "linux" | "other"): string | null → "Ollama.dmg" / "OllamaSetup.exe" / null / null.
    • latestInstaller(http, asset): Promise<{ version, url, size, sha256 }>. It GETs the releases/latest API with Accept: application/vnd.github+json and finds the asset by exact name.
      • The checksum comes from digest (strip sha256:, lower-case, must be 64 hex chars). If digest is missing, fall back to fetching the same release's sha256sum.txt asset and parsing it.
      • Pin the URL: url must start with https://github.com/ollama/ollama/releases/download/. Anything else throws.
      • Use the version-pinned browser_download_url, never …/latest/download/…, so a release landing mid-download cannot swap the file under a known checksum.
    • Errors are TransportErrors with readable text. Cases: a non-200 (a 403/429 from GitHub means "GitHub's rate limit, try again later or download by hand"), the asset missing, or no checksum.
  2. New src/transport/nodedownload.ts. Same pattern as src/transport/nodestream.ts: nothing imports Node, and the caller injects load.
    • nodeDownload(load) returns (url, dest, expect: { size, sha256 }, onProgress({ received, total }), signal?) => Promise<void>.
    • Modules come only through load("https") / load("http") (picked per URL, as nodestream does, so tests can use a local http server), load("fs") and load("crypto"). Type them with minimal local interfaces, as nodestream does.
    • Follow redirects: 301/302/303/307/308, at most 5 hops. Reject a redirect that downgrades https: to http:.
    • Stream to dest + ".part" with fs.createWriteStream, feeding each chunk to crypto.createHash("sha256").
      • Respect backpressure: if write() returns false, pause() the response, then resume() on drain.
      • total comes from content-length, else expect.size.
    • At the end: size and hex digest must equal expect. On a match, rename .part → dest. On a mismatch, unlink .part and reject with a clear "checksum mismatch".
    • On abort or error: destroy the request, close the stream, unlink .part, reject. No partial file may be left behind.
  3. New src/ollamainstall.ts. The UI, in the style of OllamaPullModal.
    • OllamaInstallModal, step 1, confirm: "Download the official Ollama installer (<version>, <size>) from GitHub and open it? It is saved to <dir>. You finish the installation in the installer." Buttons: Download and open (CTA) and Cancel. Never download silently.
    • Step 2, progress: a ProgressBarComponent and status text such as Downloading the Ollama installer — 0.1 / 0.2 GB (40%), throttled like v1 (PROGRESS_INTERVAL_MS). Cancel aborts. Closing the modal while downloading also aborts, as v1 does.
    • Step 3, open and wait: call open(file). A non-empty result string is an error, which goes to the fallback. Then show "Finish installing Ollama in the installer that just opened", with the macOS hint "drag Ollama to Applications, then open it".
      • Poll detectOllama(host.http, OLLAMA_LOCAL) every 3 s for up to 10 min while the modal is open. When Ollama is running, close and resolve "installed".
      • Buttons: Check again and Close.
    • Fallback, at any failure (release lookup, download, checksum, openPath): notify() the reason and return to the missing modal, where v1's Open ollama.com/download link stays available.
    • Download dir: <os.tmpdir()>/remarkable-ink-ollama/, created recursive. Remove stale *.part files there before a new download. Keep the finished installer, because the DMG may still be mounted.
  4. src/main.ts (plugin edge). Add desktopInstaller() next to desktopNdjson() (line ~2414), with the same guard: Platform.isDesktopApp plus typeof window.require === "function", else null.
    • It returns { os, dir, download: nodeDownload(load), open: (file) => electron.shell.openPath(file) }.
    • os comes from Obsidian's Platform.isMacOS / Platform.isWin / Platform.isLinux, not process.platform.
    • dir uses load("os").tmpdir() and load("path").join.
    • If electron.shell?.openPath is not a function, return null (link fallback).
    • Pass it into the host object built in setUpLocalOllama() (line ~1964).
  5. src/ollamasetup.ts.
    • Add installer: DesktopInstaller | null to OllamaSetupHost.
    • In OllamaMissingModal:
      • when installer !== null and installerAsset(os) is non-null, add a CTA "Download and install Ollama". It runs latestInstaller → OllamaInstallModal; on "installed", recurse into setUpLocalOllama(host, refresh), so v1's model pull and test follow on their own;
      • make "Open ollama.com/download" a secondary button;
      • on Linux, show the command curl -fsSL https://ollama.com/install.sh | sh in a <pre><code>, with a Copy command button (navigator.clipboard.writeText, then notify("Copied")), plus one line: it asks for your password (sudo) and installs Ollama as a system service.
    • Do not change OllamaPullModal, pullModel or the rest of v1's flow.
  6. Disclosure (Obsidian developer policy: network use and files outside the vault must be stated in the README). Add a sentence to README.md → ## Privacy: only when you press Download and install Ollama, the plugin contacts api.github.com and GitHub's release downloads for Ollama's official installer, saves it to your system's temp folder (outside the vault), and opens it.
  7. Docs:
    • docs/ocr-endpoint-setup.md → One-click setup (desktop): replace the "links to ollama.com/download" bullet with the download, verify, open and wait flow, plus the Linux command.
    • CHANGELOG-INK.md → Unreleased: one bullet.

Constraints and decisions — please read, @daniel

  • Bundle guard unchanged; no child_process. scripts/check-bundle.mjs must not be edited.

    • Node modules (fs, crypto, os, path, https) are reached only lazily, on desktop, through the injected load (window.require), exactly as v1's nodestream.ts does for http.
    • No literal require("fs") (or any window.require("fs"), which the guard regex would also match) appears in source or bundle. Say this explicitly in the MR when you hand it in, for @daniel's review.
  • Plugin-review risk, flagged for @daniel's decision. Obsidian's developer policies say plugins must not "install or update themselves or their dependencies". This flow does not install anything itself:

    • it downloads the vendor's signed installer on an explicit click;
    • it verifies GitHub's published SHA-256;
    • it hands the file to the OS, and the user runs the installer.

    The plugin is currently installed by hand (README → Getting started), so the directory policies are good practice rather than binding. A reviewer could still read the policy strictly. Separately, the submission rule "Node/Electron APIs → isDesktopOnly: true" already sits in tension with v1's lazy http; this MR does not change manifest.json.

  • Decided against:

    • Ollama-darwin.zip: opening it extracts into the temp dir rather than /Applications.
    • requestUrl: it buffers the whole file.
    • running install.sh: it needs sudo, and the guard rules out child_process.
    • …/latest/download/ URLs: checksum race.
    • downloading into the vault: it would sync a 1.6 GB file.
  • Out of scope: !31 (OLLAMA_ORIGINS docs) and !32 (LM Studio detect, which also edits the not-running branch of setUpLocalOllama). Merge origin/main before finishing and resolve overlaps. Do not touch #4 or #5.

Validation contract

  • Red gate: write the two test files first. npx vitest run src/__tests__/ollamarelease.test.ts src/__tests__/nodedownload.test.ts FAILS on main (the modules do not exist).
    • ollamarelease.test.ts, with a fake HttpClient per URL:
      • digest parsed;
      • missing digest → sha256sum.txt fallback;
      • asset missing → throws;
      • a non-github browser_download_url → throws;
      • a GitHub 403 → readable TransportError;
      • installerAsset mapping.
    • nodedownload.test.ts, with a local http server and Node's createRequire as load, like src/__tests__/nodestream.test.ts, writing into fs.mkdtempSync(os.tmpdir()):
      • 302 → 200 chain with the right checksum → file present, no .part;
      • wrong checksum → rejects, neither file present;
      • abort mid-stream → rejects, no .part;
      • six redirects → rejects;
      • progress monotonic, ending at size.
  • After: npm ci && npx vitest run src/__tests__/ollamarelease.test.ts src/__tests__/nodedownload.test.ts → PASS. Then:
    • npx vitest run → whole suite PASS;
    • npm run lint → exit 0;
    • npm run build → exit 0, ending with check-bundle's "bundle clean" line;
    • git diff --exit-code origin/main -- scripts/check-bundle.mjs manifest.json → exit 0;
    • grep -nE 'require\(\s*["'"'"'\](fs|path|stream|child_process)' main.js→ no output. Prove that grep can see a hit first, e.g. against a scratch file containingrequire("fs")`.
  • openPath and the installers cannot run in CI. State plainly in the MR that the macOS/Windows end-to-end path is untested and needs a manual try on each OS.
  • (No flake.nix in this repo; use plain npm/npx.)

🤖 Generated with Claude Code

Closes #28 (item 1, installer download; items 2 and 3 are !31 and !32). Part of #8. When "Set up local reading for me" finds no Ollama, v1 only links to ollama.com/download (`OllamaMissingModal` in `src/ollamasetup.ts`). @daniel on #8: *"direct download would be preferred"*. This MR adds that: one click downloads the **official, signed** installer, checks its **published SHA-256**, opens it with the OS, waits for Ollama to come up, and carries on into v1's flow (model pull, settings, Test connection). ## Research (done on #28; verified 2026-10-20) - **Official URLs.** `https://ollama.com/download/{Ollama.dmg,OllamaSetup.exe}` → 307 → `https://github.com/ollama/ollama/releases/latest/download/<asset>` → 302 → `release-assets.githubusercontent.com`. Latest is v0.40.6. - `Ollama.dmg` is 214 MB. - `OllamaSetup.exe` is **1.58 GB** (GPU runtimes included). Tell the user the size before downloading. - **Integrity.** `GET https://api.github.com/repos/ollama/ollama/releases/latest` returns `tag_name` and `assets[]`, each with `name`, `size`, `browser_download_url` and `digest: "sha256:<hex>"`. Each release also ships `sha256sum.txt`, with lines `<hex> ./<name>` (includes `./Ollama.dmg` and `./OllamaSetup.exe`). The API digest for `Ollama.dmg` matches `sha256sum.txt`. - **Signing.** - `OllamaSetup.exe` is Authenticode-signed by **"Ollama Inc."** (Toronto) with a DigiCert EV code-signing cert, RFC 3161 timestamped. Checked by reading the PE security directory. - macOS: `scripts/build_darwin.sh` codesigns with the Developer ID (`--options=runtime`), then notarises with `notarytool` and staples. - **Linux.** `install.sh` needs sudo and sets up a systemd service, so it stays **guide-only**: a copyable `curl -fsSL https://ollama.com/install.sh | sh`. - **Launching without `child_process`.** `require("electron").shell.openPath(path)` (renderer, non-sandboxed, which Obsidian is; `electron` is already external in `esbuild.config.mjs`). It resolves `""` on success, otherwise an error string. - macOS: opening the DMG mounts it and shows Finder's drag-to-Applications window. - Windows: it runs the Inno Setup installer, which installs per-user and starts Ollama when it finishes. - **Why not `requestUrl` for the download:** it buffers the whole body (1.58 GB in memory) and reports no progress. Use a streaming Node client, as v1 does for the pull. ## What to change 1. **New `src/transport/ollamarelease.ts`.** Pure over `HttpClient` (`requestUrl`, which follows redirects): - `installerAsset(os: "macos" | "windows" | "linux" | "other"): string | null` → `"Ollama.dmg"` / `"OllamaSetup.exe"` / `null` / `null`. - `latestInstaller(http, asset): Promise<{ version, url, size, sha256 }>`. It GETs the releases/latest API with `Accept: application/vnd.github+json` and finds the asset by exact `name`. - The checksum comes from `digest` (strip `sha256:`, lower-case, must be 64 hex chars). If `digest` is missing, fall back to fetching the same release's `sha256sum.txt` asset and parsing it. - **Pin the URL:** `url` must start with `https://github.com/ollama/ollama/releases/download/`. Anything else throws. - Use the version-pinned `browser_download_url`, never `…/latest/download/…`, so a release landing mid-download cannot swap the file under a known checksum. - Errors are `TransportError`s with readable text. Cases: a non-200 (a 403/429 from GitHub means "GitHub's rate limit, try again later or download by hand"), the asset missing, or no checksum. 2. **New `src/transport/nodedownload.ts`.** Same pattern as `src/transport/nodestream.ts`: nothing imports Node, and the caller injects `load`. - `nodeDownload(load)` returns `(url, dest, expect: { size, sha256 }, onProgress({ received, total }), signal?) => Promise<void>`. - Modules come only through `load("https")` / `load("http")` (picked per URL, as nodestream does, so tests can use a local http server), `load("fs")` and `load("crypto")`. Type them with minimal local interfaces, as nodestream does. - **Follow redirects:** 301/302/303/307/308, at most 5 hops. Reject a redirect that downgrades `https:` to `http:`. - Stream to `dest + ".part"` with `fs.createWriteStream`, feeding each chunk to `crypto.createHash("sha256")`. - **Respect backpressure:** if `write()` returns false, `pause()` the response, then `resume()` on `drain`. - `total` comes from `content-length`, else `expect.size`. - At the end: size and hex digest must equal `expect`. On a match, rename `.part` → `dest`. On a mismatch, unlink `.part` and reject with a clear "checksum mismatch". - On abort or error: destroy the request, close the stream, unlink `.part`, reject. **No partial file may be left behind.** 3. **New `src/ollamainstall.ts`.** The UI, in the style of `OllamaPullModal`. - `OllamaInstallModal`, step 1, confirm: "Download the official Ollama installer (`<version>`, `<size>`) from GitHub and open it? It is saved to `<dir>`. You finish the installation in the installer." Buttons: **Download and open** (CTA) and **Cancel**. Never download silently. - Step 2, progress: a `ProgressBarComponent` and status text such as `Downloading the Ollama installer — 0.1 / 0.2 GB (40%)`, throttled like v1 (`PROGRESS_INTERVAL_MS`). **Cancel** aborts. Closing the modal while downloading also aborts, as v1 does. - Step 3, open and wait: call `open(file)`. A non-empty result string is an error, which goes to the fallback. Then show "Finish installing Ollama in the installer that just opened", with the macOS hint "drag Ollama to Applications, then open it". - Poll `detectOllama(host.http, OLLAMA_LOCAL)` every 3 s for up to 10 min while the modal is open. When Ollama is running, close and resolve "installed". - Buttons: **Check again** and **Close**. - **Fallback, at any failure** (release lookup, download, checksum, `openPath`): `notify()` the reason and return to the missing modal, where v1's **Open ollama.com/download** link stays available. - Download dir: `<os.tmpdir()>/remarkable-ink-ollama/`, created recursive. Remove stale `*.part` files there before a new download. Keep the finished installer, because the DMG may still be mounted. 4. **`src/main.ts` (plugin edge).** Add `desktopInstaller()` next to `desktopNdjson()` (line ~2414), with the same guard: `Platform.isDesktopApp` plus `typeof window.require === "function"`, else `null`. - It returns `{ os, dir, download: nodeDownload(load), open: (file) => electron.shell.openPath(file) }`. - `os` comes from Obsidian's `Platform.isMacOS` / `Platform.isWin` / `Platform.isLinux`, not `process.platform`. - `dir` uses `load("os").tmpdir()` and `load("path").join`. - If `electron.shell?.openPath` is not a function, return null (link fallback). - Pass it into the host object built in `setUpLocalOllama()` (line ~1964). 5. **`src/ollamasetup.ts`.** - Add `installer: DesktopInstaller | null` to `OllamaSetupHost`. - In `OllamaMissingModal`: - when `installer !== null` and `installerAsset(os)` is non-null, add a CTA **"Download and install Ollama"**. It runs `latestInstaller` → `OllamaInstallModal`; on "installed", recurse into `setUpLocalOllama(host, refresh)`, so v1's model pull and test follow on their own; - make "Open ollama.com/download" a secondary button; - on **Linux**, show the command `curl -fsSL https://ollama.com/install.sh | sh` in a `<pre><code>`, with a **Copy command** button (`navigator.clipboard.writeText`, then `notify("Copied")`), plus one line: it asks for your password (sudo) and installs Ollama as a system service. - **Do not change** `OllamaPullModal`, `pullModel` or the rest of v1's flow. 6. **Disclosure** (Obsidian developer policy: network use and files outside the vault must be stated in the README). Add a sentence to `README.md` → `## Privacy`: only when you press *Download and install Ollama*, the plugin contacts `api.github.com` and GitHub's release downloads for Ollama's official installer, saves it to your system's temp folder (outside the vault), and opens it. 7. **Docs:** - `docs/ocr-endpoint-setup.md` → *One-click setup (desktop)*: replace the "links to ollama.com/download" bullet with the download, verify, open and wait flow, plus the Linux command. - `CHANGELOG-INK.md` → *Unreleased*: one bullet. ## Constraints and decisions — please read, @daniel - **Bundle guard unchanged; no `child_process`.** `scripts/check-bundle.mjs` must not be edited. - Node modules (`fs`, `crypto`, `os`, `path`, `https`) are reached only lazily, on desktop, through the injected `load` (`window.require`), exactly as v1's `nodestream.ts` does for `http`. - No literal `require("fs")` (or any `window.require("fs")`, which the guard regex would also match) appears in source or bundle. Say this explicitly in the MR when you hand it in, for @daniel's review. - **Plugin-review risk, flagged for @daniel's decision.** Obsidian's developer policies say plugins must not *"install or update themselves or their dependencies"*. This flow does not install anything itself: - it downloads the vendor's signed installer on an explicit click; - it verifies GitHub's published SHA-256; - it hands the file to the OS, and the user runs the installer. The plugin is currently installed by hand (README → *Getting started*), so the directory policies are good practice rather than binding. A reviewer could still read the policy strictly. Separately, the submission rule "Node/Electron APIs → `isDesktopOnly: true`" already sits in tension with v1's lazy `http`; this MR does not change `manifest.json`. - **Decided against:** - `Ollama-darwin.zip`: opening it extracts into the temp dir rather than `/Applications`. - `requestUrl`: it buffers the whole file. - running `install.sh`: it needs sudo, and the guard rules out `child_process`. - `…/latest/download/` URLs: checksum race. - downloading into the vault: it would sync a 1.6 GB file. - Out of scope: !31 (`OLLAMA_ORIGINS` docs) and !32 (LM Studio detect, which also edits the not-running branch of `setUpLocalOllama`). Merge `origin/main` before finishing and resolve overlaps. Do not touch #4 or #5. ## Validation contract - **Red gate:** write the two test files first. `npx vitest run src/__tests__/ollamarelease.test.ts src/__tests__/nodedownload.test.ts` FAILS on main (the modules do not exist). - `ollamarelease.test.ts`, with a fake `HttpClient` per URL: - `digest` parsed; - missing `digest` → `sha256sum.txt` fallback; - asset missing → throws; - a non-github `browser_download_url` → throws; - a GitHub 403 → readable `TransportError`; - `installerAsset` mapping. - `nodedownload.test.ts`, with a local `http` server and Node's `createRequire` as `load`, like `src/__tests__/nodestream.test.ts`, writing into `fs.mkdtempSync(os.tmpdir())`: - 302 → 200 chain with the right checksum → file present, no `.part`; - wrong checksum → rejects, neither file present; - abort mid-stream → rejects, no `.part`; - six redirects → rejects; - progress monotonic, ending at `size`. - After: `npm ci && npx vitest run src/__tests__/ollamarelease.test.ts src/__tests__/nodedownload.test.ts` → PASS. Then: - `npx vitest run` → whole suite PASS; - `npm run lint` → exit 0; - `npm run build` → exit 0, ending with check-bundle's "bundle clean" line; - `git diff --exit-code origin/main -- scripts/check-bundle.mjs manifest.json` → exit 0; - `grep -nE 'require\(\s*["'"'"'\`](fs|path|stream|child_process)' main.js` → no output. Prove that grep can see a hit first, e.g. against a scratch file containing `require("fs")`. - `openPath` and the installers cannot run in CI. State plainly in the MR that the macOS/Windows end-to-end path is untested and needs a manual try on each OS. - (No `flake.nix` in this repo; use plain `npm`/`npx`.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude self-assigned this 2026-10-20 20:06:52 +02:00
Author
Collaborator

✅ Agent run completed

6m46s · 33 turns · $2.49 · pushed agent/ollama-installer-download · session saved — new comments resume this run

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

✅ **Agent run completed** _6m46s · 33 turns · $2.49 · pushed `agent/ollama-installer-download` · session saved — new comments resume this run_ ⚠️ _Verification gate not satisfied: awaiting intent review. Outcome parked — not marked done._
Author
Collaborator

What changed

  • src/transport/ollamarelease.ts: installerAsset(os) and latestInstaller(http, asset).
    • Reads GitHub's releases/latest and takes the SHA-256 from digest, falling back to sha256sum.txt.
    • Pins the URL to https://github.com/ollama/ollama/releases/download/ (…/latest/download/, other hosts and http are refused).
    • Errors are readable TransportErrors; a 403/429 is explained as GitHub's rate limit, with a pointer to download by hand.
  • src/transport/nodedownload.ts: nodeDownload(load) streams to <dest>.part.
    • Follows 301/302/303/307/308 redirects (at most 5) and refuses https→http.
    • Hashes as it writes and respects backpressure (pause on a full write, resume on drain).
    • Checks size and SHA-256, then renames to dest. Any mismatch, error or abort closes the stream and unlinks the .part, so no partial file is left.
    • nodePrepareDir creates <tmpdir>/remarkable-ink-ollama/ and clears stale *.part files.
  • src/ollamainstall.ts, ollamasetup.ts and main.ts:
    • Install dialogue: confirm (shows version, size and folder) → progress with Cancel (closing the dialogue also cancels) → shell.openPath → "Finish installing Ollama…" (with the macOS drag-to-Applications hint) → checks for Ollama every 3 s for 10 min, plus Check again and Close buttons → carries on into v1's model pull and Test connection.
    • Fallback: any failure shows the reason and returns to "Ollama isn't running", where Open ollama.com/download is now a secondary button.
    • Linux: the dialogue shows curl -fsSL https://ollama.com/install.sh | sh with Copy command and the sudo/system-service line.
    • main.ts: desktopInstaller() sits next to desktopNdjson() with the same guard. It returns null when there is no electron.shell.openPath, and the dialogue then keeps only the link.
    • OllamaPullModal and pullModel are unchanged.
  • Docs: README → Privacy disclosure; docs/ocr-endpoint-setup.md → One-click setup; a CHANGELOG-INK bullet. origin/main (including !31) is merged in with no conflicts.

@daniel, please review:

  • No literal require("fs"), and no child_process. Node modules (fs, crypto, os, path, http/https) and electron are reached only lazily, on desktop, through the injected load (window.require), as nodestream.ts does.
    • No require("fs") or window.require("fs") appears in source or bundle.
    • The bundle has load("fs"), load("path") etc., which the guard regex does not match, and check-bundle.mjs is unchanged.
  • Plugin-review risk, your decision. Obsidian's policy says plugins must not "install or update themselves or their dependencies".
    • This flow downloads the vendor's signed installer on an explicit click, checks GitHub's published SHA-256, and hands it to the OS. The user runs the installer.
    • A strict reviewer could still object. manifest.json is unchanged (isDesktopOnly: false, the same tension as v1's lazy http).
  • The real macOS/Windows path is untested. shell.openPath and the actual installers cannot run in CI or this sandbox. The download, folder, open and wait steps are covered only against a local server and fakes. Please try "Download and install Ollama" by hand once on macOS (DMG mount → drag to Applications) and once on Windows (1.58 GB OllamaSetup.exe).

Verify

  • Ran locally:
    • npx vitest run src/__tests__/ollamarelease.test.ts src/__tests__/nodedownload.test.ts: 24 pass. Both files failed before the modules existed.
    • New src/__tests__/ollamainstall.test.ts (8 tests) drives the dialogues from "Ollama isn't running" back into v1's flow, including the open-fails, checksum-fails, rate-limit and cancel fallbacks. Mutating the openPath error check makes it fail, so it does catch regressions.
    • Whole npx vitest run: 794/794 pass.
    • npm run lint: exit 0. npm run build: exit 0, ending with "bundle clean".
    • git diff --exit-code origin/main -- scripts/check-bundle.mjs manifest.json: exit 0.
    • The require\((fs|path|stream|child_process) grep on main.js finds nothing. Run against a scratch file containing require("fs"), it does find the hit.
  • CI: no pipeline has run for this branch.

Follow-ups

  • A manual end-to-end try on macOS and on Windows (above).
  • !32 (LM Studio) also edits the not-running branch of setUpLocalOllama, so expect a small conflict there when one of the two lands after the other.
## What changed - **`src/transport/ollamarelease.ts`**: `installerAsset(os)` and `latestInstaller(http, asset)`. - Reads GitHub's `releases/latest` and takes the SHA-256 from `digest`, falling back to `sha256sum.txt`. - Pins the URL to `https://github.com/ollama/ollama/releases/download/` (`…/latest/download/`, other hosts and http are refused). - Errors are readable `TransportError`s; a 403/429 is explained as GitHub's rate limit, with a pointer to download by hand. - **`src/transport/nodedownload.ts`**: `nodeDownload(load)` streams to `<dest>.part`. - Follows 301/302/303/307/308 redirects (at most 5) and refuses https→http. - Hashes as it writes and respects backpressure (pause on a full write, resume on `drain`). - Checks size and SHA-256, then renames to `dest`. Any mismatch, error or abort closes the stream and unlinks the `.part`, so no partial file is left. - `nodePrepareDir` creates `<tmpdir>/remarkable-ink-ollama/` and clears stale `*.part` files. - **`src/ollamainstall.ts`, `ollamasetup.ts` and `main.ts`**: - **Install dialogue:** confirm (shows version, size and folder) → progress with Cancel (closing the dialogue also cancels) → `shell.openPath` → "Finish installing Ollama…" (with the macOS drag-to-Applications hint) → checks for Ollama every 3 s for 10 min, plus **Check again** and **Close** buttons → carries on into v1's model pull and Test connection. - **Fallback:** any failure shows the reason and returns to "Ollama isn't running", where **Open ollama.com/download** is now a secondary button. - **Linux:** the dialogue shows `curl -fsSL https://ollama.com/install.sh | sh` with **Copy command** and the sudo/system-service line. - **`main.ts`:** `desktopInstaller()` sits next to `desktopNdjson()` with the same guard. It returns null when there is no `electron.shell.openPath`, and the dialogue then keeps only the link. - `OllamaPullModal` and `pullModel` are unchanged. - **Docs:** README → Privacy disclosure; `docs/ocr-endpoint-setup.md` → One-click setup; a CHANGELOG-INK bullet. `origin/main` (including !31) is merged in with no conflicts. **@daniel, please review:** - **No literal `require("fs")`, and no `child_process`.** Node modules (`fs`, `crypto`, `os`, `path`, `http`/`https`) and `electron` are reached only lazily, on desktop, through the injected `load` (`window.require`), as `nodestream.ts` does. - No `require("fs")` or `window.require("fs")` appears in source or bundle. - The bundle has `load("fs")`, `load("path")` etc., which the guard regex does not match, and `check-bundle.mjs` is unchanged. - **Plugin-review risk, your decision.** Obsidian's policy says plugins must not *"install or update themselves or their dependencies"*. - This flow downloads the vendor's signed installer on an explicit click, checks GitHub's published SHA-256, and hands it to the OS. The user runs the installer. - A strict reviewer could still object. `manifest.json` is unchanged (`isDesktopOnly: false`, the same tension as v1's lazy `http`). - **The real macOS/Windows path is untested.** `shell.openPath` and the actual installers cannot run in CI or this sandbox. The download, folder, open and wait steps are covered only against a local server and fakes. Please try "Download and install Ollama" by hand once on macOS (DMG mount → drag to Applications) and once on Windows (1.58 GB `OllamaSetup.exe`). ## Verify - Ran locally: - `npx vitest run src/__tests__/ollamarelease.test.ts src/__tests__/nodedownload.test.ts`: 24 pass. Both files failed before the modules existed. - New `src/__tests__/ollamainstall.test.ts` (8 tests) drives the dialogues from "Ollama isn't running" back into v1's flow, including the open-fails, checksum-fails, rate-limit and cancel fallbacks. Mutating the `openPath` error check makes it fail, so it does catch regressions. - Whole `npx vitest run`: 794/794 pass. - `npm run lint`: exit 0. `npm run build`: exit 0, ending with "bundle clean". - `git diff --exit-code origin/main -- scripts/check-bundle.mjs manifest.json`: exit 0. - The `require\((fs|path|stream|child_process)` grep on `main.js` finds nothing. Run against a scratch file containing `require("fs")`, it does find the hit. - CI: no pipeline has run for this branch. ## Follow-ups - A manual end-to-end try on macOS and on Windows (above). - !32 (LM Studio) also edits the not-running branch of `setUpLocalOllama`, so expect a small conflict there when one of the two lands after the other.
Author
Collaborator

✅ Agent run completed

1m9s · 15 turns · $0.50

✅ **Agent run completed** _1m9s · 15 turns · $0.50_
Author
Collaborator

Acceptance-intent assessment

#28 is a "decide and research, then split into MR hand-offs" issue. The research is answered on #28 (note 45129) and the work is split three ways: item 2 → !31 (already on origin/main as 665992f), item 3 → !32, and item 1 → this MR, which that note names as the one that closes #28. This diff delivers all of item 1: it downloads the official installer, verifies its checksum, opens it, waits for Ollama, and falls back to v1's link on failure. It also stays inside the issue's constraints (desktop-only, no child_process, guard unchanged, v1's pull flow untouched).

Criteria

  • PASS: Item 1, installer download per OS (macOS Ollama.dmg, Windows OllamaSetup.exe, opened with shell.openPath).
    • installerAsset maps macos → Ollama.dmg, windows → OllamaSetup.exe, linux/other → null.
    • desktopInstaller() in src/main.ts opens the file with electron.shell.openPath.
    • OllamaInstallModal treats a non-empty result string as a failure.
  • PASS: Linux is guide-only. OllamaMissingModal shows curl -fsSL https://ollama.com/install.sh | sh in <pre><code>, with a Copy command button and the sudo/system-service line. Linux gets no download.
  • PASS: Official URLs and signing verified. This is research, recorded on #28 and in the MR description. The code pins every download to https://github.com/ollama/ollama/releases/download/ (version-pinned, never /latest/download/), and a test checks that other URLs are refused.
  • PASS: Where to store the download. <os.tmpdir()>/remarkable-ink-ollama/, outside the vault. nodePrepareDir creates it recursively, clears stale *.part files and keeps finished installers.
  • PASS: How to show progress. A streaming Node download (nodedownload.ts, same injected-load pattern as v1's nodestream.ts) drives a ProgressBarComponent and Downloading the Ollama installer — x / y GB (n%) text, throttled at PROGRESS_INTERVAL_MS. Cancel aborts, and so does closing the modal.
  • PASS: How to verify integrity.
    • The checksum comes from the API digest, falling back to sha256sum.txt, and must be 64 hex chars.
    • The download hashes while it writes and checks both size and SHA-256 before renaming .part → dest.
    • A mismatch, error or abort unlinks the .part. Tests cover the checksum mismatch, size mismatch, abort, redirect limit and https→http refusal.
  • PASS: Fallback when any step fails is v1's link.
    • Lookup failures (including GitHub's 403/429 rate limit), download or checksum failures and openPath errors all notify() the reason and return "failed".
    • setUpLocalOllama then goes back to OllamaMissingModal, where Open ollama.com/download stays as a secondary button.
    • On "installed" it recurses into v1's flow (model pull, then Test connection).
  • PASS: Feasibility and acceptability for plugin review. Answered and flagged explicitly for @daniel: the plugin downloads the vendor's signed installer only on an explicit click, and the user runs it.
  • PASS: Item 2, OLLAMA_ORIGINS. Answered on #28 (not needed) and delivered by !31, already merged into main. Correctly out of scope here.
  • PASS: Item 3, LM Studio detect-and-guide. Answered on #28 and handed off to !32 ("Part of #28"), as the issue's "split into MR hand-offs" asks. Correctly out of scope here.
  • PASS: Known constraints.
    • The desktop-only gate is Platform.isDesktopApp plus window.require, and returns null otherwise.
    • All Node modules come through the injected load. A grep of src finds require("fs") only inside comments.
    • git diff --exit-code origin/main -- scripts/check-bundle.mjs manifest.json exits 0.
    • No child_process.
  • PASS: Scope boundary. v1's pull/progress flow (OllamaPullModal, pullModel) is untouched. The ollamasetup.ts hunks only touch the not-running branch and OllamaMissingModal. #4 and #5 are untouched.

I re-ran ollamarelease, nodedownload and ollamainstall tests: 32 passed, 0 failed.

Notes (not blocking):

  1. Merging this MR auto-closes #28 while !32 (item 3) is still open. That follows the split recorded on #28, but item 3 is then tracked only by !32 itself.
  2. The real macOS and Windows openPath installer path is untested in CI, and the MR says so. It needs the manual try on each OS before release.

Verdict

Approved

## Acceptance-intent assessment #28 is a "decide and research, then split into MR hand-offs" issue. The research is answered on #28 (note 45129) and the work is split three ways: item 2 → !31 (already on `origin/main` as 665992f), item 3 → !32, and item 1 → this MR, which that note names as the one that closes #28. This diff delivers all of item 1: it downloads the official installer, verifies its checksum, opens it, waits for Ollama, and falls back to v1's link on failure. It also stays inside the issue's constraints (desktop-only, no `child_process`, guard unchanged, v1's pull flow untouched). ## Criteria - **PASS: Item 1, installer download per OS (macOS `Ollama.dmg`, Windows `OllamaSetup.exe`, opened with `shell.openPath`).** - `installerAsset` maps macos → `Ollama.dmg`, windows → `OllamaSetup.exe`, linux/other → null. - `desktopInstaller()` in `src/main.ts` opens the file with `electron.shell.openPath`. - `OllamaInstallModal` treats a non-empty result string as a failure. - **PASS: Linux is guide-only.** `OllamaMissingModal` shows `curl -fsSL https://ollama.com/install.sh | sh` in `<pre><code>`, with a **Copy command** button and the sudo/system-service line. Linux gets no download. - **PASS: Official URLs and signing verified.** This is research, recorded on #28 and in the MR description. The code pins every download to `https://github.com/ollama/ollama/releases/download/` (version-pinned, never `/latest/download/`), and a test checks that other URLs are refused. - **PASS: Where to store the download.** `<os.tmpdir()>/remarkable-ink-ollama/`, outside the vault. `nodePrepareDir` creates it recursively, clears stale `*.part` files and keeps finished installers. - **PASS: How to show progress.** A streaming Node download (`nodedownload.ts`, same injected-`load` pattern as v1's `nodestream.ts`) drives a `ProgressBarComponent` and `Downloading the Ollama installer — x / y GB (n%)` text, throttled at `PROGRESS_INTERVAL_MS`. **Cancel** aborts, and so does closing the modal. - **PASS: How to verify integrity.** - The checksum comes from the API `digest`, falling back to `sha256sum.txt`, and must be 64 hex chars. - The download hashes while it writes and checks both size and SHA-256 before renaming `.part` → dest. - A mismatch, error or abort unlinks the `.part`. Tests cover the checksum mismatch, size mismatch, abort, redirect limit and https→http refusal. - **PASS: Fallback when any step fails is v1's link.** - Lookup failures (including GitHub's 403/429 rate limit), download or checksum failures and `openPath` errors all `notify()` the reason and return "failed". - `setUpLocalOllama` then goes back to `OllamaMissingModal`, where **Open ollama.com/download** stays as a secondary button. - On "installed" it recurses into v1's flow (model pull, then Test connection). - **PASS: Feasibility and acceptability for plugin review.** Answered and flagged explicitly for @daniel: the plugin downloads the vendor's signed installer only on an explicit click, and the user runs it. - **PASS: Item 2, `OLLAMA_ORIGINS`.** Answered on #28 (not needed) and delivered by !31, already merged into `main`. Correctly out of scope here. - **PASS: Item 3, LM Studio detect-and-guide.** Answered on #28 and handed off to !32 ("Part of #28"), as the issue's "split into MR hand-offs" asks. Correctly out of scope here. - **PASS: Known constraints.** - The desktop-only gate is `Platform.isDesktopApp` plus `window.require`, and returns null otherwise. - All Node modules come through the injected `load`. A grep of `src` finds `require("fs")` only inside comments. - `git diff --exit-code origin/main -- scripts/check-bundle.mjs manifest.json` exits 0. - No `child_process`. - **PASS: Scope boundary.** v1's pull/progress flow (`OllamaPullModal`, `pullModel`) is untouched. The `ollamasetup.ts` hunks only touch the not-running branch and `OllamaMissingModal`. #4 and #5 are untouched. I re-ran `ollamarelease`, `nodedownload` and `ollamainstall` tests: 32 passed, 0 failed. Notes (not blocking): 1. Merging this MR auto-closes #28 while !32 (item 3) is still open. That follows the split recorded on #28, but item 3 is then tracked only by !32 itself. 2. The real macOS and Windows `openPath` installer path is untested in CI, and the MR says so. It needs the manual try on each OS before release. ## Verdict Approved
Owner

@claude resolve merge conflicts

@claude resolve merge conflicts
Author
Collaborator

🤖 Agent is working on this — turn 40

Last activity: assistant message — updated 22:46:10 UTC

Last message:

I merged origin/main into the branch, resolved the conflicts and pushed it (7dc3cfc). Nearly all of the overlap was with !32, the LM Studio change.

  • src/ollamasetup.ts: when Ollama isn't running, the setup now checks for LM Studio first, as main does. If LM Studio isn't running either, or you choose Use Ollama instead, you get this MR's "Ollama isn't running" dialogue with Download and install Ollama. Once the install works, the setup runs again, finds Ollama and carries on into the model pull.
  • Test helper (src/__tests__/helpers/obsidian.ts): it now has main's additions (Modal.opened, Notice, DropdownComponent) as well as this branch's progress bar and close-only-once modal. The install tests now use Modal.opened.
  • LM Studio tests: two of them failed after the merge because their fake setup had no installer field. I added installer: null and they pass.
  • CHANGELOG-INK.md and docs/ocr-endpoint-setup.md: I kept both sides' entries.

Checks run locally:

  • All 838 tests pass, and lint and build succeed; the build ends with "bundle clean".
  • scripts/check-bundle.mjs and manifest.json are unchanged from main.
  • The built main.js contains no require("fs")-style calls; the same search does find one I planted in a scratch file.

CI hasn't run on the new commit yet. Installing on a real Mac or Windows machine is still untested and needs a manual try on each. I posted an update on the MR saying all this.

🤖 **Agent is working on this** — turn 40 _Last activity: assistant message — updated 22:46:10 UTC_ **Last message:** > I merged `origin/main` into the branch, resolved the conflicts and pushed it (7dc3cfc). Nearly all of the overlap was with !32, the LM Studio change. > > - **`src/ollamasetup.ts`:** when Ollama isn't running, the setup now checks for LM Studio first, as main does. If LM Studio isn't running either, or you choose *Use Ollama instead*, you get this MR's "Ollama isn't running" dialogue with *Download and install Ollama*. Once the install works, the setup runs again, finds Ollama and carries on into the model pull. > - **Test helper (`src/__tests__/helpers/obsidian.ts`):** it now has main's additions (`Modal.opened`, `Notice`, `DropdownComponent`) as well as this branch's progress bar and close-only-once modal. The install tests now use `Modal.opened`. > - **LM Studio tests:** two of them failed after the merge because their fake setup had no `installer` field. I added `installer: null` and they pass. > - **`CHANGELOG-INK.md` and `docs/ocr-endpoint-setup.md`:** I kept both sides' entries. > > **Checks run locally:** > - All 838 tests pass, and lint and build succeed; the build ends with "bundle clean". > - `scripts/check-bundle.mjs` and `manifest.json` are unchanged from main. > - The built `main.js` contains no `require("fs")`-style calls; the same search does find one I planted in a scratch file. > > CI hasn't run on the new commit yet. Installing on a real Mac or Windows machine is still untested and needs a manual try on each. I posted an update on the MR saying all this.
Resolve overlaps with !32 (LM Studio detect-and-guide):
- setUpLocalOllama: when Ollama is not running, offer LM Studio first, then
  the installer-aware "Ollama isn't running" dialogue.
- Test stand-in: keep main's Modal.opened, Notice and DropdownComponent, plus
  this branch's ProgressBarComponent and close-once guard; ollamainstall tests
  now use Modal.opened.
- LM Studio tests' host gains installer: null.
- CHANGELOG-INK and ocr-endpoint-setup: keep both entries.

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

Since my last update: I merged origin/main into the branch and resolved the conflicts (7dc3cfc). Most of the overlap was with !32 (LM Studio):

  • src/ollamasetup.ts: when Ollama isn't running, setUpLocalOllama now checks for LM Studio first, as on main. If LM Studio isn't running, or you press Use Ollama instead, you get the "Ollama isn't running" dialogue, which still has Download and install Ollama (macOS/Windows), the Linux command and the link. A successful install starts the flow again from the top, finds Ollama running and carries on into the model pull.
  • Test stand-in (helpers/obsidian.ts): it now uses main's Modal.opened, Notice and DropdownComponent, plus this branch's ProgressBarComponent and the rule that a modal's close only runs once. ollamainstall.test.ts now uses Modal.opened. Two LM Studio tests failed after the merge because their fake host had no installer field; I added installer: null and they pass.
  • CHANGELOG-INK.md and docs/ocr-endpoint-setup.md: both sides' entries are kept.

Checked locally:

  • npx vitest run: 838 pass, 0 fail.
  • npm run lint: exit 0.
  • npm run build: exit 0, ends with "bundle clean".
  • check-bundle.mjs and manifest.json are unchanged from main.
  • The require("fs"|"path"|…) grep finds nothing in main.js (the same grep does find a planted require("fs") in a scratch file).

No pipeline has run on the new head yet. Installing on real macOS and Windows still needs a manual try.

Since my last update: I merged `origin/main` into the branch and resolved the conflicts (7dc3cfc). Most of the overlap was with !32 (LM Studio): - **`src/ollamasetup.ts`:** when Ollama isn't running, `setUpLocalOllama` now checks for LM Studio first, as on main. If LM Studio isn't running, or you press *Use Ollama instead*, you get the "Ollama isn't running" dialogue, which still has *Download and install Ollama* (macOS/Windows), the Linux command and the link. A successful install starts the flow again from the top, finds Ollama running and carries on into the model pull. - **Test stand-in (`helpers/obsidian.ts`):** it now uses main's `Modal.opened`, `Notice` and `DropdownComponent`, plus this branch's `ProgressBarComponent` and the rule that a modal's close only runs once. `ollamainstall.test.ts` now uses `Modal.opened`. Two LM Studio tests failed after the merge because their fake host had no `installer` field; I added `installer: null` and they pass. - **`CHANGELOG-INK.md` and `docs/ocr-endpoint-setup.md`:** both sides' entries are kept. Checked locally: - `npx vitest run`: 838 pass, 0 fail. - `npm run lint`: exit 0. - `npm run build`: exit 0, ends with "bundle clean". - `check-bundle.mjs` and `manifest.json` are unchanged from main. - The `require("fs"|"path"|…)` grep finds nothing in `main.js` (the same grep does find a planted `require("fs")` in a scratch file). No pipeline has run on the new head yet. Installing on real macOS and Windows still needs a manual try.
daniel merged commit bee2787c9c into main 2026-10-21 00:56:15 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!33
No description provided.