AI is interpretation, not a database client#
ai/provider.ts defines the provider interface. openai-compatible.ts implements requests to the user-configured endpoint. The URL, model and credential come from the local ai_state configuration; no real provider key belongs in a release or this wiki.
agent.ts exposes three operations:
| Function | Input | Parsed output |
|---|---|---|
runPlanEdit |
Current plan context and instruction | Typed plan-edit actions |
runRecipeExtraction |
Dictated recipe transcript | Structured recipe candidates |
runNewspaperExtraction |
Leaflet transcript and known context | Extracted deals/shopping/recipe information |
Each operation selects a versioned template from prompts.ts, calls provider.complete, then parses the returned text. The agent returns data and metadata; it does not write domain tables.
Validation and application#
planner.ts builds context and extracts/parses JSON. schemas.ts validates records, scalar types, dates, cents, recipe candidates and supported action shapes.
The provider/orchestration layer resolves those candidates against local entities and uses repository operations to persist allowed changes. Domain rules such as allergies, editable meal targets and batch constraints still belong in services.
Treat a successful HTTP response as only the first step. Invalid JSON, unknown IDs, unsupported actions and structurally valid but domain-invalid suggestions must not become arbitrary writes. The manual path remains fully usable if AI is disabled or unavailable.
AI run records and privacy#
The agent records prompt ID/version, model, available token counts and truncated text in AgentRunMeta. Request text is truncated to 4,000 characters and response text to 8,000 in this layer.
That makes the local ai_runs audit useful for debugging, but it also makes it sensitive: transcripts and plan context can reveal food preferences or household details. API keys must never be included in those strings. Backups can contain user content even when credentials are scrubbed.
Local speech recognition does not make later AI interpretation local. If the user sends the recognized transcript to the configured provider, that text/context leaves the device.
Dictation has a separate pipeline#
microphone or leaflet recording
→ local speech engine
→ transcript
→ optional user-invoked AI extraction
→ validated candidate
→ local repository changes
Relevant implementation boundaries:
ai/android-speech-recognition.ts: native recognition availability, permissions, live transcription and locale selection.ai/use-leaflet-recording.android.ts: recording lifecycle and transcription; the generic variant supplies a non-Android boundary.dictation/native-speech.android.ts: platform engine integration.dictation/whisper.android.ts: local Whisper integration.dictation/model-catalog.ts: approved model metadata and pinned hashes.dictation/model-storage.ts: model download/storage lifecycle.database/dictation-settings.ts: selected dictation configuration.
The approved Whisper choices are multilingual Base/Small Q5_1 models downloaded on explicit request from the public ggerganov/whisper.cpp model repository/CDN. They are not bundled with the APK. Digests must be verified before installation/use, and models remain in Android private no-backup storage.
Audio is not uploaded by the local recognition path. Model weights are not included in ordinary backups or household sync. Native module availability must be tested in the actual Android build; a browser or mocked unit test does not prove a recorder works on a real device.
Retailer providers#
deals/providers.ts maps current store IDs to implementations:
| Store ID | Provider file |
|---|---|
lidl |
lidl.ts |
lidl_hu |
lidl.ts Hungarian provider |
hofer |
hofer.ts |
billa_at |
billa.ts |
spar |
spar.ts |
aldi_hu |
aldi.ts |
This is more extensive than the initial three-retailer design text. Use the registry to determine implemented support; an enabled store record alone does not prove a working provider exists.
Fetch policy and its limits#
openStoreFetcher validates HTTP(S) source URLs, fetches robots.txt, and returns a same-origin page fetcher for that store refresh. Requests have a descriptive user agent, language/accept headers and a 12-second timeout.
isPathAllowed parses robots groups and selects the longest matching rule from the supported matching groups. This is a lightweight implementation, not a claim of complete crawler-standard compliance.
Important current behaviors:
- A successfully retrieved robots file that disallows the initial path blocks the refresh.
- A missing or failed robots fetch does not block the offer request.
- Explicit page URLs must remain on the original origin.
- Providers can load sequential pages; the current implementation is not universally “one offer request per store.”
- Browser CORS and restricted headers can behave differently from native fetch.
Keep those distinctions when debugging or changing fetch policy. The older design summary's one-page assumption is not an accurate description of every current provider.
Refresh and cache failure semantics#
refreshDeals loads enabled/requested stores, ingredient aliases and providers. For each store it:
- Opens the store fetcher with Austrian/German or Hungarian language preferences.
- Invokes provider loading/parsing.
- Treats unsupported providers and network failures as failed audit results.
- Treats loading/parsing problems or zero recognized offers as partial results.
- Replaces the store cache only when recognized offers exist.
- Matches stored deals to ingredients.
- Marks the store scraped and records a
scrape_runsrow.
The source's staleness helper uses a 12-hour threshold. Staleness is a refresh decision, not proof an offer is currently valid.
A fetch/parser failure preserves the last usable cache. Zero parsed offers is usually a markup change, so it does not silently erase every deal. Screens render SQLite data, not raw network responses.
Matching and deal calculations#
matcher.ts maps product text to ingredients using known names/aliases and confidence. deal_matches stores the relationship and user status.
deal-service.ts implements validity windows, savings and best-deal selection. A textual match is not proof of exact package size or interchangeable products. Combined with the shopping price limitations, this is why estimated savings are guidance rather than a guaranteed bill.
Integration tests#
AI tests use fake transports and fixed completion fixtures. Retailer parser tests use saved HTML/data fixtures. Dictation/model tests should cover cancellation, digest mismatch and unsupported native capabilities.
This wiki build makes no AI, retailer, Auth or real-device calls. Production behavior still needs staging/device acceptance, especially with changing public retailer markup.