Platform v2 step 1.5 (APPS_PLATFORM D-7, D-17, §3, §6.1).
- user_permissions(user_id, key); revision 0005 copies existing v1 flags into
keys (frozen mapping) and drops the perm_* columns; can_cancel_orders gone
- core/access: check() = module effective + key held (superadmin implicit,
override keys wired for 1.9); holds()/can(); markers require/require_any/
public/require_device; role templates from manifests; queries.holders_filter
replaces User.perm_x == True; legacy.py projects/accepts the v1 booleans
for the current manager/waiter UIs only (§3.3, temporary)
- routers.deps: require_manager/... are now aliases of require("<key>");
history endpoints use history.view; superadmin-only = core.system.admin;
get_current_user carries the "signed_in" marker
- every inline perm_* read in routers/services converted to holds()
- staff API: permission catalogue by module with role templates, get/set a
user's keys, reset to role template; legacy flag toggles still work; a
non-superadmin can only grant keys they hold (access.cannot_grant)
- setup wizard creates the first account as owner (v1: store_manager, who
couldn't change settings); demo/seed manager is owner
- roles.py keeps only the role list and labels
- guards: every route has an access marker (19 open routes marked public()
on purpose; /waiters/roles now needs sign-in), no perm_* attribute reads
- tests: check matrix, templates, projection, staff permission API, grant
guard, 0005 data copy; pack rule CS-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Platform v2 step 1.4 (APPS_PLATFORM D-3..D-6, D-21, §5).
- core/modules/entitlements.py: compute() turns the evaluated license into
per-module grants: the v2 token's `modules` map (own `exp` with the 5-day
grace, never cut mid-service) + the free tier; no/invalid token, expired
after grace, inactive, locked or clock tampering -> free tier only; core
always. limit(module, name) with token value -> manifest licensed_default ->
free value; None = unlimited. LICENSE_MODE=off (dev/test only) = everything
- module gating says why: module.not_licensed (402, the first unlicensed
module in the dependency chain) before module.disabled (403)
- services/license.py accepts only v2 tokens with a modules map; the v1
"legacy unsigned 72h" path is gone
- apply_license() always installs entitlements (startup before workers,
every heartbeat, workday close); workers follow license changes
- the global license middleware is deleted (no more whole-API 402/423);
license_state moved to services/license_state.py
- history_days enforced in every report/history endpoint: lower date bounds
clamped (also when no "from" is given), and business days older than the
limit refused by id (license.history_limited); data is never deleted
- bootstrap/modules API show license mode, entitlement source and limit values
- LICENSE_MODE=off in docker-compose.dev.yml and the e2e launchers; sites
default to enforced
- tests: entitlement rules, limits, the three done-when checks, signed-token
apply_license path; license tests moved to v2 tokens
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Platform v2 step 1.3 (APPS_PLATFORM §4, §5.3, D-4, D-19).
- core/modules: Module/Perm/Limit/SettingDef/DeviceApp/Mount model; registry
that discovers modules/<key>/manifest.py and validates it (keys, kinds,
dependencies and cycles, permission prefixes and roles, unique settings,
each router claimed once and importable, device_app only on apps, workers);
free_tier.py (D-5 constant, used from 1.4)
- 25 manifests (the §4.2 map) with permission keys + default roles derived
from today's perm_* meaning, limits, device apps and the 55 settings
- main.py mounts every router from the manifests; non-core routers carry
Depends(module_required(key)) -> 403 module.disabled while off
- site_modules table (revision 0004), cached enablement; disabling a module
also turns off modules that depend on it; core can't be disabled
- worker supervisor: connect_menu / connect_orders / connect_remote are now
separate workers (v1's single _connect_loop split), started and stopped as
their modules turn on and off; crashes are logged and restarted
- GET /api/platform/bootstrap (venue name/tz/language/currency, effective
modules, user, language, role-template permission keys), GET /modules,
PUT /modules/{key}
- settings API derives its key list and defaults from the manifests
- reports router split: history endpoints on history_router (`history`
module, free tier later) under the same /api/reports prefix
- tests: registry validation, mount coverage, toggle round-trip, dependency
propagation, bootstrap/catalogue shape, supervisor; pack rule CS-13
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Platform v2 step 1.1 (APPS_PLATFORM D-11, §7, D-24).
- core/timeutil.py: utcnow, venue_tz (venue.timezone, cached, invalidated on
change - no restart), to_venue/venue_date/venue_strftime, parse_api_datetime
(offset -> UTC; naive = venue-local; date = venue midnight), business_date_of
/business_date_window (rollover hour, default 06:00), LocalClock + is_within,
UTCDateTime column type (naive writes raise, reads are aware UTC), iso_z
- every model column is UTCDateTime; Pydantic UTCDatetime emits "...Z"
- business_days.business_date set at open; revision 0002 adds it (backfilled)
and makes sync_events.created_at a UTCDateTime (AUTOINCREMENT restated)
- tz.py deleted; system.timezone setting replaced by venue.timezone (validated)
+ business_day.rollover_hour; manager timezone picker writes venue.timezone
- fixes: price-group schedules/time_range used the container's zone (happy
hour bug); traffic report bucketed by UTC hour; reports' "date" meant the UTC
calendar day, now the business date; reservations stored venue-local naive
times (no-show check 2-3 h off) and listed by func.date; schedule week used
UTC midnights; fiscal file names used container-local time
- seed.py/demo_seed.py create store_manager with role permissions (regression
from step 1.0: v1's startup ALTER list used to rename/grant role 'manager')
- tzdata dependency; guard tests/guards/test_no_naive_time.py (AST scan);
tests/test_timeutil.py covers the §7.3 DST cases and the API checks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Platform v2 step 0.4 (APPS_PLATFORM §10). New core/logging.py:
- root logger -> stderr + <db dir>/logs/xenia-YYYY-MM-DD.log (UTC date,
/app/data/logs in Docker, $LOG_DIR overrides); files older than the
system.log_retention_days setting (default 30) are pruned
- line format: UTC ISO time, level, logger, [req= user= device=], message
- RequestContextMiddleware (pure ASGI): request id per request, X-Request-ID
response header, one http line per request (DEBUG for plain reads)
- auth tags the user via set_log_context; uvicorn loggers routed through ours
Print jobs now log created / attempt / success / failed / abandoned with the
job id, so a missing ticket can be traced. Removed cloud_sync's basicConfig.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before KI-006 an install without CLOUD_URL (dev, demos, test stacks) was
simply licensed; after it, a SITE_ID without a cloud counted as
'unverified' and blocked everything. Real sites always have both set, and
blanking CLOUD_URL is no stronger than blanking SITE_ID (already possible).
verify_token() now reads the built-in public key at call time so the e2e
suite can swap it in-process for a throwaway key (never via configuration).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- services/license.py: verifies the cloud's Ed25519-signed license token
(public key built in) and decides purely: valid → licensed until expiry,
then a 5-day grace, then blocked - never mid-service (deferred while a
workday is open, applied at close). Works offline for as long as the
license lasts: the "unlicensed after 72h without heartbeat" rule is gone.
- Tamper resistance: an edited token fails the signature ("unverified");
a clock earlier than the latest provable time (token issued_at, newest
order in the DB, stored high-water mark; 1 day tolerance) → "clock".
- apply_license() re-evaluates from the stored token at startup, after
every heartbeat attempt and when a workday closes. Cloud lock/unlock from
the token keeps the workday-deferred behaviour. Transition: a cloud
without tokens is trusted 72h per successful heartbeat.
- FIX: the promised 5-day grace after expiry never happened - the cloud's
licensed=false was applied immediately (402 on everything).
- FIX: license_state.json lived inside the container and was lost on every
re-creation; it now lives in the data volume (old path read once).
- /api/system/status: offline_days, license_verified, license_problem,
grace_over; lock_reason "clock"/"unverified"; grace days from the license
module (rounded up).
Tests: 18 unit checks (signature, tamper, other site/key, 364 days
offline, grace ±workday, inactive, clock rollback, transition) + 17 E2E
checks with a real cloud + site process (400 days offline, tampered file →
402, clock behind newest order, expiry deferred until workday close,
renewal, remote lock/unlock).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The backend's bridge network can't see the host's NICs, so HOST_IP from
install.sh went stale silently after a DHCP change. Now:
- services/netinfo_helper.py runs as a new `netinfo` service (same backend
image, network_mode: host): every 60s it picks the PHYSICAL LAN address
(main-table default-route NIC if real hardware, else first real NIC with
IPv4; never WireGuard/Tailscale/ZeroTier/bridges/veths, ignores 169.254)
and writes it to the shared `netinfo` volume. Stdlib only. On Docker
Desktop (linuxkit/WSL2 kernel) it reports "unsupported" instead of the
VM's meaningless address.
- services/lan_ip.py: one resolver used by /api/system/status (lan_ip +
lan_ip_info), the pairing QR and the cloud heartbeat's local_ip:
override (pos_settings network.lan_ip_override) → live detection (ignored
when older than 5 min) → HOST_IP. Flags `mismatch` when a pinned address
is no longer on any of the machine's NICs.
- PUT /api/system/lan-ip-override (manager): set a private IPv4 or null to
return to automatic; public/loopback/link-local/IPv6 rejected (422).
- cloud_sync._get_local_ip uses the resolver (no more socket trick that
returned the container IP).
Tested: helper selection on a fake sysfs/route table (8 cases incl. VPN
default routes) + real ioctl/route parsing on a Linux kernel; resolver
priority/staleness/mismatch/validation (18 cases); isolated full stack:
HOST_IP fallback on Docker Desktop, override save/validate/auth, simulated
Linux detection incl. DHCP change and dead helper, heartbeat IP.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
local_backend now uploads each product's image file to cloud_backend
during the existing ~5 min menu sync, so the QR menu can show real
photos without needing a manually-set digital_image_url. Only
re-uploads images whose content hash changed since the last push
(Product.cloud_image_hash), to avoid re-sending unchanged binaries
every cycle.
Also adds a manual "sync now" trigger (POST /api/system/sync-menu) and
a matching button in Settings → Operation, for pushing menu/price/image
changes immediately instead of waiting for the next automatic cycle.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Snapshot of in-progress work across local_backend, manager_dashboard,
and waiter_pwa (pricing, chat, fiscal, prep zones, recovery codes, CRM,
inventory, permissions), plus the nginx/docker-compose deploy fixes for
the Unraid + NPM reverse-proxy setup.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- New reservations module: model, schema, router (CRUD + status updates + upcoming alerts)
and background task for auto-expiring stale reservations
- Reports: print_products, print_categories, print_tables analytics endpoints
plus meta_products and business_day_summary for workday close/view flow
- printer_service: configurable font sizes/weights, donut/bar chart print layout helpers,
analytics print blocks per printer
- tables/schemas: surfaced color, zone, and other new fields on Table, Product, User, Printer
- demo_seed.py for quick dev DB population; wipe_database.py utility
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
_connect_loop now waits up to 30 seconds for the heartbeat to return
site_numeric_id, then immediately pushes the menu snapshot and stats
before entering the regular poll loop. Previously the first push
wouldn't fire until 5 minutes after startup, making the menu
unavailable until then.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds _push_stats_snapshot() to cloud_sync.py. Every 5 minutes
(piggybacked on the existing _connect_loop push tick alongside the
menu snapshot) it queries the local DB and POSTs a JSON stats blob
to POST /api/remote/snapshot (site API key auth).
Stats collected:
- open_tables: count of open/partially_paid POS orders
- today_revenue: sum of active+paid item prices on orders
closed today
- today_orders: count of paid/closed POS orders today
- online_orders_pending: online orders awaiting acceptance
- online_orders_today: all online orders opened today
- current_shift: active waiter shift info (waiter_id, started_at)
if a business day is open; null otherwise
- as_of: UTC timestamp of the snapshot
The remote manager dashboard reads this via
GET /api/remote/sites/{id}/snapshot (manager JWT).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Phase 4 _mirror_status_to_cloud function had no way to look up the
cloud order's numeric id once it was marked synced (not in the pending
list anymore), so status updates from local staff could silently fail.
Fix:
- models/order.py: online_order_cloud_id INTEGER column added to Order
- main.py: migration for the new column
- schemas/order.py: online_order_cloud_id exposed in OrderOut
- cloud_sync.py: stores cloud_order["id"] as online_order_cloud_id
when creating the local order during the pull
- connect_orders.py: _mirror_status_to_cloud now takes the integer
cloud id directly — no more pending-list lookup; function body
reduced from ~50 lines to ~15
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4.1 — cloud_sync.py
- _push_menu_snapshot(): serializes digital-visible products+categories
and POSTs to cloud /api/menu/sync every 5 minutes
- _pull_pending_orders(): polls cloud /api/orders/pending/{site_id}
every CONNECT_SYNC_INTERVAL_SECONDS (default 30s); creates local
Order + OrderItem rows, marks synced on cloud, broadcasts SSE event
- _connect_loop(): second asyncio task running the fast poll loop;
piggybacked menu push fires every 5 min regardless of poll interval
- _sync_once(): captures site_numeric_id from heartbeat response and
stores it in license_state so Connect loops can use it
- start_cloud_sync(): now creates and returns both tasks
4.2 — orders model/schema/migrations
- models/order.py: table_id made nullable (online orders have no
table); 7 new online_* columns added to Order
- schemas/order.py: OrderOut table_id Optional, all 7 online_* fields
added
- main.py: 8 additive ALTER TABLE migrations for orders table
4.3 — routers/connect_orders.py (NEW)
GET /api/connect/orders/incoming — pending online orders (any auth)
POST /api/connect/orders/{id}/accept — accept (manager)
POST /api/connect/orders/{id}/reject — reject with optional reason (manager)
POST /api/connect/orders/{id}/status — progress through lifecycle (manager)
All state changes mirror to cloud via background task and broadcast SSE
4.4 — main.py router registration
connect_orders router registered at /api/connect
config.py
CONNECT_SYNC_INTERVAL_SECONDS setting added (default 30)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Includes all work to date:
- local_backend: FastAPI backend with products, orders, tables, shifts, cloud sync
- manager_dashboard: React manager UI with product/category management, reports, settings
- waiter_pwa: React PWA for waiter devices
- Category reparent endpoint and UI
- Waiter domain: local_ip sent on heartbeat, waiter_domain persisted from cloud response
- QR code modal in AppInfoTab for waiter domain
- Product form: number input spinners removed, category pre-selected on new product
- Category row: count badge moved to far right
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>