Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ Models downloaded at runtime (from the configured host)
- PP-OCRv6 tiny / medium (det + rec ONNX), PaddlePaddle ............ Apache-2.0
- IBM Granite Embedding 311M Multilingual R2 (ONNX q8)
(ibm-granite / onnx-community ports) ............................. Apache-2.0
- IBM Granite 4.0 Nano 350M / 1B Instruct (ONNX-web, transformers.js)
(ibm-granite / onnx-community ports) ............................. Apache-2.0
- Qwen2.5 0.5B / 1.5B Instruct, Qwen3.5 0.8B (MLC builds) .......... Apache-2.0
- WebLLM model libraries (mlc-ai/binary-mlc-llm-libs) .............. Apache-2.0
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ npm run test:e2e # Playwright (fake S3, no real bucket)

Host `dist/` on any **HTTPS** static host. Camera, WebGPU, service worker, and crypto need a secure context.

**Tip:** Filling titles/dates with Qwen needs **WebGPU** (recent Chrome / Edge, or Safari 26 / iOS 26). OCR and meaning search still work without it.
**Tip:** Filling titles/dates is fastest with **WebGPU** (recent Chrome / Edge, or Safari 26 / iOS 26). Granite Nano can fall back to WASM without it; Qwen still needs WebGPU. OCR and meaning search work either way.

## Set up your bucket

Expand Down Expand Up @@ -108,7 +108,7 @@ When you add a document, models download once (then stay cached) and run **local
| Step | What it does | Model |
| --- | --- | --- |
| **Read the page** | Photo/PDF → text | PP-OCRv6 (tiny by default; medium optional) |
| **Fill the filing card** | Suggests title, sender, date, labels | Small Qwen models via WebLLM |
| **Fill the filing card** | Suggests title, sender, date, labels | IBM Granite 4.0 Nano (transformers.js); Qwen via WebLLM still available |
| **Search by meaning** | Finds docs by idea, not exact words | IBM Granite Embedding 311M Multilingual R2 |

Only **one** engine is in memory at a time (so phones stay stable). While models are downloading, new documents wait with a clear banner.
Expand All @@ -126,9 +126,11 @@ Only **one** engine is in memory at a time (so phones stay stable). While models

| Model | Size | Notes |
| --- | --- | --- |
| Qwen2.5 0.5B | ~295 MB | Lightest; safer on phones |
| Qwen3.5 0.8B | ~454 MB | Newer small multilingual Qwen |
| Qwen2.5 1.5B | ~887 MB | Default everyday model |
| Granite 4.0 350M | ~334 MB | Default; IBM Nano via transformers.js (WebGPU / WASM) |
| Granite 4.0 1B | ~1.2 GB | Stronger instruct; heavier |
| Qwen2.5 0.5B | ~295 MB | WebLLM; needs WebGPU |
| Qwen3.5 0.8B | ~454 MB | WebLLM; needs WebGPU |
| Qwen2.5 1.5B | ~887 MB | WebLLM; needs WebGPU |

You can pick a **different model per field**. Labels only come from **your** list — the model does not invent categories.

Expand All @@ -143,7 +145,8 @@ Weights are **not** in git. They download on first use and cache on the device.
| Model | Job | License |
| --- | --- | --- |
| PP-OCRv6 tiny / medium | OCR | Apache-2.0 |
| Qwen2.5 / Qwen3.5 (above) | Metadata | Apache-2.0 |
| Granite 4.0 Nano 350M / 1B | Metadata | Apache-2.0 |
| Qwen2.5 / Qwen3.5 (above) | Metadata (optional) | Apache-2.0 |
| Granite Embedding 311M R2 | Meaning search | Apache-2.0 |

Libraries and attribution: [NOTICE](NOTICE).
Expand All @@ -155,7 +158,7 @@ flowchart LR
subgraph Device["Your browser"]
UI[App UI] --> Q[Processing queue]
Q --> OCR["OCR"]
Q --> LLM["Qwen via WebLLM"]
Q --> LLM["Granite / Qwen metadata"]
Q --> EMB["Granite Embedding"]
UI --> IDB[("Encrypted keys + settings")]
UI --> ST["S3 client"]
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/0001-browser-only-pwa-with-direct-s3-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ or keys.
deleted on start.
- The S3 keys are encrypted with a user password: PBKDF2-SHA-256 (600,000 rounds) → AES-256-GCM, stored in
IndexedDB. The app shows an unlock screen on every open and forgets the plain keys after 15 minutes idle.
- OCR (PP-OCRv6 via onnxruntime-web), metadata (WebLLM / Qwen) and meaning-search
- OCR (PP-OCRv6 via onnxruntime-web), metadata (IBM Granite 4.0 Nano via transformers.js; optional Qwen via WebLLM) and meaning-search
embeddings (**IBM Granite Embedding 311M Multilingual R2** via transformers.js, Apache-2.0) all run on the device.
Models download from Hugging Face / official WebLLM libs on first use and are cached in the browser (not in the document bucket).
- Memory rules for phones: one model in memory at a time, downloads one file at a time streamed into the cache,
Expand Down
Binary file added docs/images/05-setup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion e2e/capture-demo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test.describe("docs media capture", () => {
// 1× CSS pixels → sharper GIF (2× retina looked muddy after palette quantisation).
await page.setViewportSize({ width: 1120, height: 720 });
await page.goto("/");
await expect(page.getByTestId("app-shell").or(page.getByTestId("unlock-screen")).or(page.getByTestId("app-booting"))).toBeVisible({ timeout: 20_000 });
await expect(page.getByTestId("app-shell").or(page.getByTestId("unlock-screen")).or(page.getByTestId("setup-screen")).or(page.getByTestId("app-booting"))).toBeVisible({ timeout: 20_000 });
await seedStorageSettings(page);
await seedVault(page);
await page.reload();
Expand Down
78 changes: 63 additions & 15 deletions e2e/first-run.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,78 @@
import { test, expect } from "@playwright/test";
import { FakeBucket, FAKE_BUCKET, FAKE_ENDPOINT, FAKE_REGION, installFakeS3 } from "./helpers/fakeS3";
import { blockModelDownloads } from "./helpers/seed";

test.describe("first run (no vault)", () => {
test.beforeEach(async ({ page }) => {
await blockModelDownloads(page);
await page.goto("/");
await expect(page.getByTestId("app-shell")).toBeVisible({ timeout: 15_000 });
await expect(page.getByTestId("setup-screen")).toBeVisible({ timeout: 15_000 });
});

test("shows empty state and storage setup hint", async ({ page }) => {
await expect(page.getByTestId("empty-state")).toBeVisible();
await expect(page.getByText(/Set up .*Storage/i)).toBeVisible();
await expect(page.getByRole("heading", { name: "No documents found" })).toBeVisible();
});

test("opens settings and storage section", async ({ page }) => {
await page.getByRole("complementary", { name: "Folders" }).getByRole("button", { name: /Storage/i }).click();
await expect(page.getByRole("dialog", { name: /Settings/i })).toBeVisible();
test("shows setup page with storage fields", async ({ page }) => {
await expect(page.getByRole("heading", { name: /Documents Manager/i })).toBeVisible();
await expect(page.getByText(/OCR and AI run on this device/i)).toBeVisible();
await expect(page.getByTestId("s3-endpoint")).toBeVisible();
await expect(page.getByTestId("s3-save-keys")).toBeVisible();
await expect(page.getByTestId("s3-save-keys")).toContainText(/Save and continue/i);
});

test("shows what you need beforehand", async ({ page }) => {
await page.getByText(/What you need beforehand/i).click();
await expect(page.getByText(/CORS rule/i)).toBeVisible();
});

test("stays on setup when passwords do not match", async ({ page }) => {
await page.getByTestId("s3-endpoint").fill(FAKE_ENDPOINT);
await page.getByTestId("s3-bucket").fill(FAKE_BUCKET);
await page.getByTestId("s3-access-key").fill("AKIA_TEST_KEY_0001");
await page.getByTestId("s3-secret-key").fill("test-secret-key-value");
await page.getByTestId("s3-password").fill("test-password-123");
await page.getByTestId("s3-password-repeat").fill("different-password");
await page.getByTestId("s3-save-keys").click();

await expect(page.getByTestId("setup-screen")).toBeVisible();
await expect(page.getByTestId("s3-status")).toContainText(/do not match/i);
await expect(page.getByTestId("app-shell")).toHaveCount(0);
});

test("stays on setup when the bucket cannot be reached", async ({ page }) => {
// No fake S3 route — the browser cannot reach s3.test.local.
await page.getByTestId("s3-endpoint").fill(FAKE_ENDPOINT);
await page.getByTestId("s3-bucket").fill(FAKE_BUCKET);
await page.getByTestId("s3-region").fill(FAKE_REGION);
await page.getByTestId("s3-path-style").check();
await page.getByTestId("s3-access-key").fill("AKIA_TEST_KEY_0001");
await page.getByTestId("s3-secret-key").fill("test-secret-key-value");
await page.getByTestId("s3-password").fill("test-password-123");
await page.getByTestId("s3-password-repeat").fill("test-password-123");
await page.getByTestId("s3-save-keys").click();

await expect(page.getByTestId("s3-status")).toContainText(/❌/, { timeout: 30_000 });
await expect(page.getByTestId("setup-screen")).toBeVisible();
await expect(page.getByTestId("app-shell")).toHaveCount(0);
});

test("opens scan picker", async ({ page }) => {
await page.getByTestId("open-scan").click();
await expect(page.getByRole("dialog", { name: /Add a document/i })).toBeVisible();
await expect(page.getByText("Scan with camera")).toBeVisible();
await expect(page.getByText(/Upload PDF/i)).toBeVisible();
test("completes setup into the main app", async ({ page }) => {
const bucket = new FakeBucket();
bucket.seedMeta([]);
await installFakeS3(page, bucket);
// Routes are live for this page; reload so settings start clean with the fake endpoint ready.
await page.reload();
await expect(page.getByTestId("setup-screen")).toBeVisible({ timeout: 15_000 });

await page.getByTestId("s3-endpoint").fill(FAKE_ENDPOINT);
await page.getByTestId("s3-bucket").fill(FAKE_BUCKET);
await page.getByTestId("s3-region").fill(FAKE_REGION);
await page.getByTestId("s3-path-style").check();
await page.getByTestId("s3-access-key").fill("AKIA_TEST_KEY_0001");
await page.getByTestId("s3-secret-key").fill("test-secret-key-value");
await page.getByTestId("s3-password").fill("test-password-123");
await page.getByTestId("s3-password-repeat").fill("test-password-123");
await page.getByTestId("s3-save-keys").click();

await expect(page.getByTestId("app-shell")).toBeVisible({ timeout: 60_000 });
await expect(page.getByTestId("empty-state")).toBeVisible();
await expect(page.getByRole("heading", { name: "No documents found" })).toBeVisible();
});
});
2 changes: 1 addition & 1 deletion e2e/helpers/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function openUnlockedApp(page: Page, docs = DEMO_DOCS): Promise<Fak
await blockModelDownloads(page);

await page.goto("/");
await expect(page.getByTestId("app-shell").or(page.getByTestId("unlock-screen")).or(page.getByTestId("app-booting"))).toBeVisible({ timeout: 15_000 });
await expect(page.getByTestId("app-shell").or(page.getByTestId("unlock-screen")).or(page.getByTestId("setup-screen")).or(page.getByTestId("app-booting"))).toBeVisible({ timeout: 15_000 });

await seedStorageSettings(page);
await seedVault(page);
Expand Down
2 changes: 1 addition & 1 deletion e2e/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test.describe("meaning search", () => {
await blockModelDownloads(page);

await page.goto("/");
await expect(page.getByTestId("app-shell").or(page.getByTestId("unlock-screen")).or(page.getByTestId("app-booting"))).toBeVisible({ timeout: 15_000 });
await expect(page.getByTestId("app-shell").or(page.getByTestId("unlock-screen")).or(page.getByTestId("setup-screen")).or(page.getByTestId("app-booting"))).toBeVisible({ timeout: 15_000 });
await seedStorageSettings(page);
await seedVault(page);
await page.reload();
Expand Down
13 changes: 8 additions & 5 deletions e2e/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import { FakeBucket, FAKE_BUCKET, FAKE_ENDPOINT, FAKE_REGION, installFakeS3 } fr
import { blockModelDownloads } from "./helpers/seed";

test.describe("storage setup", () => {
test("saves keys and tests the fake bucket connection", async ({ page }) => {
test("saves keys and tests the fake bucket connection from setup", async ({ page }) => {
const bucket = new FakeBucket();
bucket.seedMeta([]);
await installFakeS3(page, bucket);
await blockModelDownloads(page);

await page.goto("/");
await expect(page.getByTestId("app-shell")).toBeVisible({ timeout: 15_000 });

await page.getByRole("complementary", { name: "Folders" }).getByRole("button", { name: /Storage/i }).click();
await expect(page.getByTestId("setup-screen")).toBeVisible({ timeout: 15_000 });

await page.getByTestId("s3-endpoint").fill(FAKE_ENDPOINT);
await page.getByTestId("s3-bucket").fill(FAKE_BUCKET);
Expand All @@ -25,8 +23,13 @@ test.describe("storage setup", () => {
await page.getByTestId("s3-password-repeat").fill("test-password-123");
await page.getByTestId("s3-save-keys").click();

await expect(page.getByTestId("s3-status")).toContainText(/Saved/i, { timeout: 60_000 });
await expect(page.getByTestId("app-shell")).toBeVisible({ timeout: 60_000 });

// Settings → Storage still exposes Save keys / Test for returning edits
await page.getByRole("complementary", { name: "Folders" }).getByRole("button", { name: /Storage/i }).click();
await expect(page.getByRole("dialog", { name: /Settings/i })).toBeVisible();
await expect(page.getByTestId("s3-endpoint")).toHaveValue(FAKE_ENDPOINT);
await expect(page.getByTestId("s3-test")).toBeVisible();
await page.getByTestId("s3-test").click();
await expect(page.getByTestId("s3-status")).toContainText(/Connected/i, { timeout: 15_000 });
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/unlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.describe("unlock", () => {
await blockModelDownloads(page);

await page.goto("/");
await expect(page.getByTestId("app-shell").or(page.getByTestId("unlock-screen")).or(page.getByTestId("app-booting"))).toBeVisible({ timeout: 15_000 });
await expect(page.getByTestId("app-shell").or(page.getByTestId("unlock-screen")).or(page.getByTestId("setup-screen")).or(page.getByTestId("app-booting"))).toBeVisible({ timeout: 15_000 });

await seedStorageSettings(page);
await seedVault(page);
Expand Down
8 changes: 6 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
/* App shell: boot settings + vault, then unlock gate or the main document UI. */
/* App shell: boot settings + vault, then unlock / setup gate or the main document UI. */
import { useEffect, useState } from "react";
import { MainScreen } from "./app/MainScreen";
import { Setup } from "./components/Setup";
import { Unlock } from "./components/Unlock";
import { cleanupOldData } from "./lib/db";
import { initSettings } from "./lib/settings";
import { initSettings, useSettings } from "./lib/settings";
import { storageConfigured } from "./lib/files";
import { initVault, startIdleLock, useVault } from "./lib/vault";

export type { Toast } from "./app/MainScreen";

export default function App() {
const [ready, setReady] = useState(false);
const vault = useVault();
useSettings(); // re-render when storage settings change during setup
useEffect(() => {
(async () => {
await initSettings();
Expand All @@ -22,5 +25,6 @@ export default function App() {
}, []);
if (!ready) return <div data-testid="app-booting" aria-busy="true" />;
if (vault.hasVault && !vault.unlocked) return <Unlock />;
if (!storageConfigured() || !vault.hasVault) return <Setup />;
return <MainScreen />;
}
9 changes: 7 additions & 2 deletions src/components/ModelsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ export function ModelsCard() {
{ use: "📝 OCR", kind: "ocr", key: ocr.key, name: ocr.emoji + " " + ocr.name, size: ocr.approx, runs: "✅" },
...(["title", "from", "date", "labels"] as const).map((f) => {
const m = LLM_BY_KEY[s.metaModels[f]];
return { use: { title: "📝 Title", from: "📨 From", date: "📅 Date", labels: "🏷️ Labels" }[f], kind: "meta" as const, key: m.key, name: m.emoji + " " + m.name, size: m.approx,
runs: !gpu ? "…" : !gpu.webgpu ? "❌ no WebGPU" : isPhone() && m.desktopOnly ? "❌ too big for a phone" : m.phoneRisk && isPhone() ? "⚠️ may crash" : "✅" };
const runs = !gpu ? "…"
: isPhone() && m.desktopOnly ? "❌ too big for a phone"
: m.phoneRisk && isPhone() ? "⚠️ may crash"
: m.runtime === "transformers"
? (gpu.webgpu ? "✅" : "✅ WASM (slower)")
: !gpu.webgpu ? "❌ no WebGPU" : "✅";
return { use: { title: "📝 Title", from: "📨 From", date: "📅 Date", labels: "🏷️ Labels" }[f], kind: "meta" as const, key: m.key, name: m.emoji + " " + m.name, size: m.approx, runs };
}),
(() => { const m = SEARCH_BY_KEY[s.searchModel]; return { use: "🔍 Search", kind: "search" as const, key: m.key, name: m.emoji + " " + m.name, size: m.approx, runs: "✅" }; })(),
];
Expand Down
Loading
Loading