Commit Graph

38 Commits

Author SHA1 Message Date
12a4e197f3 Merge pull request 'worktree-citti-arkiver-tur' (#8) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 43s
Reviewed-on: #8
2026-10-30 12:53:39 +01:00
Henrik Jess Nielsen
dc53fbfb9b feat(stats): compute Kødportioner and Aftensmadsdage from the list
Both tiles were hardcoded. Parse the quantity strings (6 × ½ kg, 3 kg,
~700g, 2 stk.) live: Kødportioner = total Kød & fisk weight / 500g;
Aftensmadsdage = meat portions + pasta/tortelloni packs. Recomputed on
load and whenever a quantity changes, so the trip's food volume is
visible while editing. Defaults now read ~30 portions / ~36 dinners.
2026-10-30 12:51:24 +01:00
Henrik Jess Nielsen
32e6841b8c feat(stats): live 'Estimeret total' reflecting the actual list
Estimeret total was a hardcoded ~4.400. Make it dynamic: every list row
(fixed catalog, added extras, picked Lübeck offers) carries data-est in DKK,
and recalcAll sums them, so the tile updates live when you add/remove items
or pick/unpick offers. 'Faktisk betalt' was already live; the Aftensmadsdage
and Kødportioner tiles stay as illustrative figures.
2026-10-30 12:45:55 +01:00
Henrik Jess Nielsen
a5279bb01d feat(tilbud): 'Gå til seddel' button showing how many offers are selected
Ticking an offer already adds it to the shopping list instantly (it shows in
the Lübeck-tilbud section), but that wasn't visible. Add a fixed 'N valgt ·
Gå til seddel' button that appears once anything is selected, so the link
between the checklist and the list is obvious and you can jump straight to it.
2026-10-30 12:41:28 +01:00
6de7b02aba Merge pull request 'worktree-citti-arkiver-tur' (#7) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 44s
Reviewed-on: #7
2026-10-30 12:28:47 +01:00
Henrik Jess Nielsen
c5e4a326e0 chore(deploy): prefer a dedicated API key over the shared OAuth token
The OAuth token shares one rate budget across everything on the subscription
(incl. interactive Claude Code sessions), so citti's translation is almost
always throttled while coding — hence the page staying German. Template now
emits ANTHROPIC_API_KEY from citti/anthropic_api_key when set (its own rate
budget, no contention), else the OAuth token. Only one var is written so an
empty key can't shadow the token.
2026-10-30 12:19:45 +01:00
Henrik Jess Nielsen
67ffc07a04 fix(offers): background refresh + skip unchanged matching
Two things made Opdater show 'Opdatering fejlede': the refresh ran
synchronously (so a slow, rate-limited translate timed out the browser)
and a 429 returned 502. Now:
- /api/offers/refresh starts the work in a background thread and returns
  immediately; the button says 'Opdaterer i baggrunden' and reloads a bit
  later as batches land. A lock prevents overlapping runs.
- match_offers_ai skips the Claude call when the offer set is unchanged
  since the last successful match (hashed), so it runs ~weekly (when the
  avis turns over), not every daily refresh — fewer calls, less cost, less
  rate pressure.
2026-10-30 12:16:30 +01:00
90ed399cd9 Merge pull request 'fix(offers): survive Claude rate limits (429)' (#6) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 45s
Reviewed-on: #6
2026-10-30 12:09:37 +01:00
Henrik Jess Nielsen
bf5439f7ad fix(offers): survive Claude rate limits (429)
The OAuth token works (429 = authenticated but throttled); subscription
tokens have a tight output-tokens/min limit and the API reserves max_tokens
against it, so the big translate calls 429'd and the error surfaced as a
failed refresh.

- Smaller requests: translate max_tokens 16000->4000, batch 250->100; match
  max_tokens 8000->2000 (less reserved OTPM per call)
- Client max_retries=8 so the SDK waits out 429s (respects retry-after)
- Pace 1.5s between translate batches
- Matching no longer fails the whole refresh on a 429 — it keeps the existing
  matches; translations are cached per batch, so progress persists and the
  next refresh finishes the rest
2026-10-30 12:07:01 +01:00
92fa8df574 Merge pull request 'worktree-citti-arkiver-tur' (#5) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 1m57s
Reviewed-on: #5
2026-10-30 12:00:31 +01:00
Henrik Jess Nielsen
66031345d2 feat(pwa): installable — PNG icons + beforeinstallprompt button
Chrome's install prompt needs 192 and 512 PNG icons (SVG-only often isn't
enough, especially on Android). Add them and reference them in the manifest
(any + maskable). offline.js captures beforeinstallprompt and shows an
'Installér app' button that triggers the native prompt, and clears it on
appinstalled. Bump SW cache to v2 so the new manifest/icons take effect.
2026-10-30 11:58:46 +01:00
Henrik Jess Nielsen
b640d9950c feat(pwa): offline support so the list works in-store with no net
No signal inside the store made the server-rendered app unusable. Make it
an installable PWA:
- service worker (static/sw.js) caches pages (network-first, cache fallback)
  and assets, served from root so scope is /
- offline.js: cittiFetch() queues check-off / price / qty / pick POSTs in
  localStorage when offline and replays them in order on reconnect, with an
  optimistic response and an Offline/Syncing status badge
- manifest + icon for add-to-home-screen; PWA meta tags on the in-store pages
- in-store mutations (saveToServer, pick/unpick) go through cittiFetch;
  archive/refresh/add still need net by design
- Dockerfile copies static/
Open once online first so the SW can cache; then it works offline.
2026-10-30 11:54:38 +01:00
ed2121e4f8 Merge pull request 'worktree-citti-arkiver-tur' (#4) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 46s
Reviewed-on: #4
2026-10-30 11:47:44 +01:00
Henrik Jess Nielsen
1dec3b7bd8 fix(offers): support Claude OAuth token (citti/claude_oauth_token)
The key was provisioned as an OAuth token, not an API key. Read it from
Consul into ANTHROPIC_AUTH_TOKEN (the SDK uses it as a Bearer credential)
and add the required anthropic-beta: oauth-2025-04-20 header on the
messages calls. Credential guards now accept a key or a token. The job no
longer sets ANTHROPIC_API_KEY, since even an empty value would shadow the
token.
2026-10-30 11:46:57 +01:00
Henrik Jess Nielsen
06656ffd4f fix(deploy): reuse blaaai Consul key so citti gets a Claude key
Prod container had no ANTHROPIC_API_KEY (refresh returned 0/0 instantly;
homepage showed only the 9 heuristic matches), so offers stayed German.
The template read citti/anthropic_api_key, a path never set. Fall back to
the existing blaaai Consul key via or(), reusing BlaaAi's key with no new
secret to provision.
2026-10-30 11:28:19 +01:00
b7141d787b Merge pull request 'fix(offers): DE→DA translation returned nothing — disable thinking, batch big' (#3) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 41s
Reviewed-on: #3
2026-10-30 11:23:41 +01:00
Henrik Jess Nielsen
f374088211 fix(offers): DE→DA translation returned nothing — disable thinking, batch big
Prod showed 0 of 467 headings translated while AI matching worked. Cause:
Haiku 5.5 defaults thinking on, which consumed the 4000-token budget on the
40-item translation batches and truncated the JSON, so every batch fell back
to German. Matching (one small response) slipped through.

- Disable thinking on both Claude calls (mechanical JSON tasks), via a shared
  _claude_json helper that retries without the flag if a model rejects it
- Raise max_tokens (16000 translate / 8000 match) so output fits even if
  thinking stays on
- Batch ~all headings in 1-2 calls (250) instead of 40, so the preamble isn't
  repeated per batch and we don't hammer the rate limit (cheaper, as suggested)
2026-10-30 11:19:40 +01:00
21c870189f Merge pull request 'worktree-citti-arkiver-tur' (#2) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 1m4s
Reviewed-on: #2
2026-10-30 11:09:31 +01:00
Henrik Jess Nielsen
c0580fefbc chore(deploy): inject ANTHROPIC_API_KEY from Consul KV into citti job
Reads citti/anthropic_api_key via keyOrDefault so a missing key never
blocks deploy — set it in Consul (copy from blaaai/anthropic_api_key)
to enable Danish translation and AI offer matching.
2026-10-30 11:03:54 +01:00
Henrik Jess Nielsen
8dd435a7d0 feat(offers): Danish translation and AI matching via Claude
Offers come from the German avis, so add Claude-backed language help,
reusing BlaaAi's ANTHROPIC_API_KEY + Haiku pattern. Both degrade
gracefully: without a key, offers stay German and the token heuristic
still matches.

- Translate offer headings DE→DA in the fetch job, cached per heading
  in a translations table (only new headings cost a call). UI shows
  Danish primary + German subtitle for in-store navigation.
- AI match the fixed list against offers (offer_matches table): Claude
  returns same-product matches, far more precise than the token
  heuristic (which false-matched e.g. Nutella jar → advent calendar).
  load_deals() prefers AI matches, falls back to the heuristic.
- Haiku 5.5 by default (MATCH_MODEL/TRANSLATE_MODEL env overridable to
  Sonnet); no temperature param (Haiku 5.5 rejects non-default).
- requirements: add anthropic
2026-10-30 11:02:47 +01:00
b0eef226ce Merge pull request 'worktree-citti-arkiver-tur' (#1) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 1m4s
Reviewed-on: #1
2026-10-30 10:44:55 +01:00
Henrik Jess Nielsen
3b0ea28db5 feat(koeb-nu): read-only "buy now" shopping status vs current offers
Add a /koeb-nu page that analyses the list without touching quantities:
- which fixed items are on offer in Lübeck right now (honest per-unit
  offer price in EUR + DKK, no fabricated saving vs the Danish-origin
  estimate, since the units differ)
- what still needs ticking off, grouped by section (+ picked offers)
- a selection of this week's cheapest Tilbud specials not on the list,
  linking to the full Tilbud page
Header gets a 🛒 Køb nu link. The source carries no pre-price, so no
discount % is shown.
2026-10-30 10:43:22 +01:00
Henrik Jess Nielsen
65a99d2138 feat(offers): live Lübeck offer prices with pick-to-list and deal matching
Fetch CITTI Lübeck offers from the Tjek API (German dealer 3czmZx only —
never the Danish Flensburg booklet) and surface them in the app.

- New offers + offer_meta tables; defensive hotspots parser; upsert by
  offer id, prune per re-fetched catalog while preserving picked rows
- Daily in-process refresh scheduler (data.db lives on the app's own
  Nomad alloc disk, so a separate periodic job can't share it) plus a
  manual POST /api/offers/refresh and an "Opdater" button
- /tilbud page: browse all offers by catalog, search, EUR + DKK, and tick
  offers onto the shopping list; picks appear in a Lübeck-tilbud section
  on the main list and check off as bought via the existing /api/price
- Match the fixed catalog items against current offers and show a
  "på tilbud" badge with the matched offer name (conservative word-
  boundary token match, >=2 tokens for multi-word names)
- Dockerfile: add ca-certificates for urllib HTTPS to the Tjek API
2026-10-30 10:35:43 +01:00
Henrik Jess Nielsen
cf999ae228 feat(trips): archive current list and start a fresh one
Add a "Arkivér & ny liste" button that snapshots the current trip
(checked items, prices, quantities, extras and custom categories)
into a new trips table, then clears the mutable state so the list
resets to the fresh catalog.

- New trips table in init_db() storing a self-contained JSON snapshot
  plus computed totals and item count
- POST /api/archive with a no-op guard against archiving an empty list
- /historik list view and /historik/<id> read-only detail view
- Photo files are kept so archived trips can still show them
2026-10-30 10:15:27 +01:00
Henrik Jess Nielsen
7e5ef3c4b5 fix(mobile): allow pinch-to-zoom by removing maximum-scale restriction
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 40s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:37:05 +02:00
Henrik Jess Nielsen
1570b6eceb feat(items): add German product names for in-store navigation
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 47s
Each item now shows the German name (de field) below the Danish name
so it's easier to find products on shelves in Citti Flensburg.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:33:25 +02:00
Henrik Jess Nielsen
ba936424af fix(deploy): use SHA image tag instead of latest in Nomad
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 42s
Avoids stale image cache issues where Nomad re-uses the old :latest
layer. SHA is injected via nomad -var flag at deploy time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:27:57 +02:00
Henrik Jess Nielsen
7709580cef fix(qty): make quantity input visibly editable with border and tap target
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 26s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:25:05 +02:00
Henrik Jess Nielsen
6ce940759c feat(shopping): editable quantity field per item
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 26s
Each item row now has an editable qty input showing the planned amount
(e.g. "6 × ½ kg"). Changes are auto-saved via debounce to the prices
table and highlighted in accent color when modified from the default.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:18:04 +02:00
Henrik Jess Nielsen
17f39c9503 Switch to ephemeral_disk, no host_volume required
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 40s
sticky+migrate keeps data across restarts and job updates.
DATA_DIR points to NOMAD_ALLOC_DIR/data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:09:44 +02:00
Henrik Jess Nielsen
ff01f4e120 Move Nomad placement to int node (auto-creates volumes)
Some checks failed
Build and Deploy citti / build-and-deploy (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:08:04 +02:00
Henrik Jess Nielsen
e92bdaf44d Add autobox constraint to Nomad job
Some checks failed
Build and Deploy citti / build-and-deploy (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:07:31 +02:00
Henrik Jess Nielsen
d7ab8e02a1 Fix Dockerfile static copy, dynamic port, health endpoint
Some checks failed
Build and Deploy citti / build-and-deploy (push) Has been cancelled
- Remove COPY static/ (runtime uploads live in DATA_DIR/uploads)
- Add /health endpoint
- Read PORT from env (NOMAD_PORT_http in production, 9756 local)
- citti.nomad: dynamic port, canary deploy, Consul/Traefik, health check

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:04:29 +02:00
Henrik Jess Nielsen
77eed9aa50 Fix workflow: use debian-host runner and registry.i80.dk
Some checks failed
Build and Deploy citti / build-and-deploy (push) Failing after 5s
Match BlaaAi deployment pattern: debian-host runner, Harbor registry,
nomad CLI directly, NOMAD_ADDR=https://nomad.i80.dk:4646.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 01:00:04 +02:00
Henrik Jess Nielsen
2edb1b4cca Fix deploy workflow: remove top-level env block
Some checks failed
deploy / deploy (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 00:57:39 +02:00
Henrik Jess Nielsen
e23e9e284b Nomad changes
Some checks failed
deploy / deploy (push) Has been cancelled
2026-06-06 00:55:31 +02:00
Henrik Jess Nielsen
1a3476c4d3 Add Flask shopping app with Nomad deployment
Some checks failed
deploy / deploy (push) Has been cancelled
Flask app serving the Citti shopping list with SQLite persistence,
per-category item addition, dynamic custom categories, photo upload,
and a post-trip price analysis page.

- Port 9756, DATA_DIR env var for persistent volume in Nomad
- Gitea Actions pipeline builds Docker image and deploys via Nomad API
- Makefile targets: run, install, build, push

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 00:54:07 +02:00
Henrik Jess Nielsen
9ef85c327f first commit 2026-06-06 00:28:17 +02:00