Commit graph

597 commits

Author SHA1 Message Date
DEls
5cf828f4e3 feat(ask): read Excel, CSV, PDF, photos and text attachments
Adds src/lib/agent/attachments.ts (parseAttachment/previewForModel/
summarise for xlsx, xls, csv, pdf — text-layer or scanned, via
pdftotext — image and plain text) with fixtures under
src/lib/agent/__fixtures__/, POST /api/chat/attachments (multipart
upload into an append-only ask_messages row, rasterising a scanned
PDF's first pages so they ride along as vision images the same way a
photographed slip does), and the read_attachment / send_to_po_pipeline
tools in tools-actions.ts. send_to_po_pipeline mirrors
/api/purchase-orders/upload's own hash-dedupe-then-create logic
directly against PocketBase rather than a same-process HTTP call (no
reliable base URL to call itself with from a server-side tool handler).

chat-view.tsx gained a second attach control (FileUp icon) alongside
the existing PO-upload paperclip, wired to the new route; pending
attachment chips ride along on the next message the same way pending
photos already do.

Deviation: send_to_po_pipeline takes { id, site } (the plan's { id }
alone can't resolve which site's purchase_orders row to create,
since /api/purchase-orders/upload always required one).

Live browser check skipped: ask_messages doesn't exist yet in the
target PocketBase (pending the user's --apply of Task 1's schema).
Covered by mocked unit tests and real fixture files instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 18:25:45 +02:00
DEls
dc25fb13cd feat(ask): long-term memory
Adds src/lib/agent/memory.ts (remember/forget/listMemories, dedupe by
normalised text, formatMemoriesForPrompt) and wires it in: a
"## What you remember" system-prompt section, the remember/forget/
list_memories tools (src/lib/agent/tools-actions.ts, a per-request
factory since these need the actor unlike the static read-only tool
set), a REST view for the UI (/api/ask/memories), and a Memory drawer
in chat-view.tsx (Mine / Shared with everyone, add, delete).

Adjusted src/lib/agent/read-only.test.ts: its blanket "no mutation
calls under src/lib/agent" contract now allowlists the specific write
seams the plan designates (memory.ts here; tools-actions.ts, gateway.ts
and images.ts to follow) instead of forbidding every file, since
memories/requests are specified to bypass the gateway and write
directly.

Live browser check skipped: ask_log doesn't exist yet in the target
PocketBase (pending the user's --apply of Task 1's schema). Covered by
mocked unit tests instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 18:13:39 +02:00
DEls
7c5df11b84 feat(ask): per-user persistent threads
Adds the "Who's using Ask?" picker (GET /api/ask/users), actor
resolution via x-ask-user (src/lib/agent/context.ts), and thread
persistence (src/lib/chat/threads.ts, /api/chat/threads routes).
/api/chat now accepts { threadId?, message, display?, images? } and
persists each turn as its own append-only ask_messages row; the old
{ history } body still works for one release. chat-view.tsx gained the
picker, a thread sidebar (new/select/rename/archive), and ?thread=<id>
in the URL.

Live browser check skipped: ask_threads/ask_messages/ask_log don't
exist yet in the target PocketBase (Task 1's schema is dry-run only,
pending the user's --apply). Covered by mocked unit tests instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 18:05:01 +02:00
DEls
b211ce1c8b feat(ask): PocketBase schema for threads, messages and log
Additive, dry-run-by-default script creating ask_threads, ask_messages
and ask_log (change/memory/request), following the
pb-add-dn-staged-ingestion.py pattern. --dry-run confirms all three
collections are new; --apply is a human step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 17:51:26 +02:00
DEls
7299f81c63 docs(ask): agent actions plan
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 17:42:46 +02:00
DEls
af71b8534b feat(suppliers): green-row tint, period filter, and KPI tiles
Green when a supplier's ordered > 0 and outstanding === 0 -- the whole
row, not just the number, so a fully-paid-up supplier stands out at a
glance.

Period filter next to the search:
  All time, This week, This month,
  Week 1-4 (of current calendar month, last absorbs any remainder),
  Month 1 (current) / Month 2 (last) / Month 3 (month before),
  Custom range with two date inputs.

Window anchors on delivery_notes.date_received -- liability accrues when
the goods arrive, not when the PO is uploaded ('we only pay what we
received this month'). computeSupplierBalances gains lastDeliveryISO per
row; a pure helper in supplier-period.ts resolves windows in UTC so the
boundary does not drift with the server's timezone.

Four KPI tiles at the top of the page:
  - Total ordered / delivered / outstanding (cumulative, always).
  - Payable this period (delivery value inside the active window).
    Subtitle is honest: 'subtract anything already paid' -- we do not
    track supplier payments, so this is the upper bound.

ui/select.tsx exports a SelectLabel so the period dropdown can group
options.
2026-09-26 17:38:39 +02:00
DEls
16652bb36c fix(auth): remove the ?demo=1 PIN bypass
The query string skipped the PIN gate on any URL. The PIN is now the
only way in. Docs updated; the login plan notes there is no fixed
cutover date while the app is in on-site testing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 17:37:20 +02:00
DEls
46e9e3dbc4 docs(ask): reports and shortcuts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:57:28 +02:00
DEls
534f3b6a85 feat(ask): slash shortcuts for base reports
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:56:21 +02:00
DEls
1dbe719e2c test(chat): import the route statically so a loaded run cannot time out
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:55:18 +02:00
DEls
774eaca13f fix(ask): findings carry their own cross-site totals
A live /findings run showed the model adding per-site and per-item
counts itself. Rules that span sites now return one finding with the
total in the title and the per-site split in the detail, and the prompt
says not to add counts across findings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:52:32 +02:00
DEls
89c73233cb feat(ask): business glossary and report rules in the prompt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:44:37 +02:00
DEls
d81a089a86 feat(ask): rain_outlook tool
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:44:01 +02:00
DEls
648f30c36d feat(ask): plant_equipment_summary tool
Hours and value match the Equipment page (guarded hoursBetweenReadings,
isPlant bucket).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:41:43 +02:00
DEls
e5789f3371 feat(ask): delivery_note_queue tool
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:39:38 +02:00
DEls
4163970cc8 refactor(dn-inbox): move board columns and stage mapping to src/lib/dn-pipeline/board
Moved unchanged; the inbox renders identically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:38:43 +02:00
DEls
10eba6f270 feat(ask): supplier_balances tool
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 09:37:27 +02:00
DEls
771f13967f refactor(suppliers): move supplier balance roll-up to src/lib/metrics
Moved unchanged; the Suppliers page renders identically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:37:40 +02:00
DEls
30b449009b feat(ask): attendance_today tool
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:35:48 +02:00
DEls
db9e6ddfb2 refactor(on-site): move attendance grouping to src/lib/attendance
Moved unchanged; the On-site page renders identically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:34:06 +02:00
DEls
e088f52cb2 feat(ask): improvement report
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:32:08 +02:00
DEls
6aa3837038 feat(ask): problem report
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:29:37 +02:00
DEls
7e506b46e1 feat(ask): site and portfolio report tools with charts
list_sites now reads computeSiteSummaries (moved verbatim, output pinned
by snapshot). The read-only guard also scans src/lib/reports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:25:33 +02:00
DEls
b8e8054725 feat(ask): render report charts inline in answers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:20:01 +02:00
DEls
278d258024 feat(ask): stream chart specs to the browser, not the model
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:14:01 +02:00
DEls
f0736e0e62 feat(ask): chart spec and extraction from tool results
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:12:04 +02:00
DEls
3551e09170 fix(chat): compute today's date per request, not at boot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:11:25 +02:00
DEls
e83a0d302c fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs
- Overview/Plant tiles and pages share one vehicle bucket rule (blank unit_type = fleet)
- Plant landing equipment figures were always 0; hour diffs now reject 0 baselines and >24h/day jumps
- km/L limits on plant (and L/h on vehicles) report unit-mismatch instead of false alerts
- formatPercent/formatDecimal replace display toFixed (en-ZA)
- POST /api/vehicles/[id]/merge + Merge duplicate dialog (dry run first)
- Attention links go to equipment vs vehicles by unit type; PO upload view link fixed
- Conditional hook fixed in DN document view; ESLint flat config (next lint removed in 16)
- Docs: current modules/routes/env vars; login + Ask reports plans

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:04:08 +02:00
DEls
2d998370b8 feat(receipts): edit posted received quantities with audit 2026-09-25 07:39:46 +02:00
DEls
a59a5a86d2 Merge branch 'codex/clock-daily-shifts' 2026-09-25 07:32:46 +02:00
DEls
5cdfaa3128 feat(clock): review missed scan-outs without changing phone flow 2026-09-25 07:27:12 +02:00
DEls
8bdf3754df Revert "feat(clock): add locked shift schema migration"
This reverts commit 5529c3f53d.
2026-09-25 07:06:28 +02:00
DEls
5d712b66c9 Revert "feat(clock): dry-run historical shift pairing"
This reverts commit e01c45765b.
2026-09-25 07:06:28 +02:00
DEls
176b6180bf fix(clock): keep old unmatched scans out of today board 2026-09-25 07:06:24 +02:00
DEls
8d728333f9 fix(clock): start new local day with an in scan 2026-09-25 07:04:45 +02:00
DEls
29edf2e5aa Revert "feat(clock): add named kiosk and supervisor sessions"
This reverts commit b163ce9f94.
2026-09-25 03:22:43 +02:00
DEls
b163ce9f94 feat(clock): add named kiosk and supervisor sessions 2026-09-25 03:19:25 +02:00
DEls
e01c45765b feat(clock): dry-run historical shift pairing 2026-09-25 03:16:08 +02:00
DEls
5529c3f53d feat(clock): add locked shift schema migration 2026-09-25 03:13:06 +02:00
DEls
df201b2a1f feat(receipt-correction): add support for receipt correction form and enhance item editing
Introduced a new secret key for receipt correction in the environment configuration. Enhanced the API for handling item edits in delivery notes, allowing for more granular updates and preserving existing manual overrides. Updated the document detail view to display additional supplier and customer information, and integrated a toggle for skipping customer identity checks. Improved validation for item entries and added tests to ensure robust handling of various edge cases in item editing.
2026-09-25 02:59:16 +02:00
DEls
488eb2af99 feat(clock): define local workday and shift records 2026-09-25 02:03:46 +02:00
DEls
e68e2d5dab docs(clock): plan daily shifts and exception review 2026-09-25 01:56:35 +02:00
DEls
d694dde501 docs(clock): design daily shifts and missed scan review 2026-09-25 01:50:25 +02:00
DEls
47ec4f1d1b feat(purchase-orders): enhance PO handling with improved validation and item management
Updated the purchase order processing to include enhanced validation for item edits, ensuring that all required fields are checked and properly formatted. Introduced new functions for computing item amounts, taking into account discounts and VAT. Refactored the PO detail view to streamline item management, including a new ItemsCard component for better organization of line items. Additionally, improved the handling of PO number sanitization to strip leading and trailing characters, enhancing matching accuracy. This update aims to improve the overall robustness and user experience of the purchase order system.
2026-09-23 23:37:37 +02:00
DEls
844ba8fe12 feat(workforce): enhance on-site dashboard with detailed employee status
Updated the on-site dashboard to provide a clearer overview of employee statuses. Renamed sections for better clarity, changing "On site now" to "On site today" and updated descriptions to reflect current employee activity. Refactored the data handling to categorize employees into three distinct groups: those currently on site, those clocked out today, and those who have not arrived. This change improves the visibility of employee attendance and enhances the overall user experience on the dashboard.
2026-09-23 00:25:33 +02:00
DEls
0edd8503b1 refactor(clock): update ConfirmDialog layout and timing constants
Removed the DialogFooter component and restructured the ConfirmDialog layout for improved usability. Increased AUTO_DISMISS_MS from 5 seconds to 30 seconds and adjusted DOUBLE_CONFIRM_WINDOW_MS from 4 seconds to 6 seconds to enhance user experience during the scanning process. Updated button styles for better visibility and interaction. This change aims to streamline the confirmation flow and reduce accidental dismissals.
2026-09-23 00:08:32 +02:00
DEls
97fe75931d feat(clock): implement two-step QR scanning flow for employee clocking
Enhanced the PersonScanner component to support a two-step flow for scanning employee badges. The new process includes a lookup phase to identify the employee and their last scan status, followed by a confirmation phase where the operator can verify the scan before recording the clock event. This change addresses issues with accidental double scans and improves user feedback with warnings for recent scans. Updated state management and error handling to reflect the new flow, ensuring a smoother user experience.
2026-09-22 23:50:59 +02:00
DEls
f88d5c519e feat(fuel-logs): enhance vehicle auto-creation and error handling
Introduced a new function to infer vehicle unit type from descriptions, improving the auto-creation process for vehicles in the fuel logs. Enhanced error handling for missing identifiers during vehicle creation, providing clearer feedback on the reasons for failures. Updated the SheetJS parsing to prevent date misinterpretation and refined the PlantPage to display all plant vehicles, regardless of cost per hour, ensuring better visibility of available resources.
2026-09-22 23:47:28 +02:00
DEIs
1760f77cff fix(map): isolate Leaflet stacking context so the Topbar dropdown sits above the map
Leaflet's internal panes use z-index 200..1000 (tile, overlay,
marker, popup, controls). The map wrapper had no z-index of its
own, so those values leaked up to the dashboard layout and buried
the Topbar's `All Sites` dropdown — which sits at z-50 by default.
The Topbar itself is in a non-overlapping zone so it looked fine,
but the dropdown's content (portalled into document.body) dropped
into the map area and got hidden behind the tile pane.

Add `isolation: isolate` to the map wrapper so Leaflet's z-index
ladder is contained inside the wrapper as a single atomic unit.
External UI at z-50+ now floats above the map as expected. The
legend and layer switcher inside the wrapper are unchanged (still
z-[400]) — they remain above the tile pane and below the map
controls, which is where they were before.

No-op for every other page; the wrapper is only on /dashboard/plant/map.
2026-09-22 22:12:49 +02:00
DEIs
87f75dd98f feat(plant): fleet map page with GPS-denormalised vehicles, clustering, and tile switcher
Adds /dashboard/plant/map: a Leaflet view of every vehicle scanned from
the MEGA Clock kiosk, plotted at its last known position.

Schema
- vehicles.last_latitude / last_longitude / last_scanned_at /
  last_location_accuracy_m denormalised off fuel_logs so the map page
  renders every vehicle in a single query. Same best-effort pattern as
  attention_dismissed_at; updated by /api/clock/vehicle-scan after every
  successful scan. PB init defaults new number cols to 0 (not null) —
  filter uses 'last_latitude > 0 || last_latitude < 0' to mean 'real fix'.
- Indexed via idx_vehicles_last_scanned.

Map UI
- Custom SVG markers per unit_type: car silhouette for fuel, tractor
  silhouette for plant, 24x24, drop-shadowed.
- Clustering via react-leaflet-cluster over Leaflet.markercluster.
  Cluster icons colour-ramp with size (green->sky->amber->rose) and
  scale 32->54px.
- Three-button base-layer switcher: Street (OSM), Dark (ESRI Dark
  Gray Canvas — CartoDB watermarks tiles without a key), Satellite
  (ESRI World Imagery). Last choice persists in localStorage.
- Site pins: small purple map-marker divIcon, click flies the map to
  zoom level 15.
- Empty-state is a floating chip on the map rather than a full-page
  card so the map is always visible.

APIs
- /api/clock/vehicle-scan: stores the GPS fix on the fuel_logs row
  AND denormalises onto the vehicle when present; missing-coord
  scan leaves last_* untouched.

Sidebar: new Map entry under Plant group.
2026-09-22 21:39:25 +02:00