Commit graph

53 commits

Author SHA1 Message Date
DEls
9b9d7097bb docs(plan): check off Task 20 — all 20 tasks complete 2026-09-11 16:17:41 +02:00
DEls
8eb256360b docs(schema): bring bootstrap and data-model docs back to truth
pb-bootstrap-schema.py -- the script a fresh PocketBase instance would
run against -- had fallen ten migrations behind and still described the
pre-restructure world. Rewrote it field-by-field against a live
production dump (17 collections, every field/required-flag/relation/
index verified). Found and fixed two pre-existing gaps unrelated to this
restructure while verifying: fuel_prices and income_claims were entirely
absent from the bootstrap script.

pb-relax-rules.py's collection list updated to match.

No local PocketBase binary is available in this environment, so the
plan's "bootstrap fresh and diff against production" verification step
was replaced with a manual field-by-field comparison against the live
dump -- same goal, different mechanism, documented as a substitution
rather than silently skipped.

Added site scoping to the one agent tool that still lacked it
(list_imports, backed by loadImportBatches) -- every other list_* tool
already had it. Preparation for the future per-user site-allowlist work,
not part of this restructure itself.

Rewrote docs/data-model.md and docs/data-flows.md end to end: the
site-attribution table, the collection reference, the five ingestion
pipelines, and the schema-drift section that was describing the exact
problem this task fixes. Every remaining data_import_batches reference
in both docs is now historical context, not a current description.

This is the last task of the ingestion restructure
(docs/superpowers/plans/2026-09-11-ingestion-restructure.md).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-11 16:17:41 +02:00
DEls
530d837bd6 docs(plan): check off Task 19 2026-09-11 16:08:34 +02:00
DEls
13f76ac894 perf(schema): index the columns every per-site query filters on
timesheet_entries, fuel_logs and delivery_notes had no indexes at all --
fine at today's row counts, not once site count grows toward the 18-20
target. Added 8 indexes across fuel_logs, timesheet_entries,
delivery_notes, purchase_orders and plant_hours_log, unioned into each
collection's existing index array rather than replacing it.

Verified both pre-existing UNIQUE indexes (idx_po_number, load-bearing
for the placeholder-PO-number scheme; idx_plant_hours_log_qr_start,
prevents duplicate weekly imports) are byte-for-byte unchanged.
Idempotent: a second run touches nothing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-11 16:08:34 +02:00
DEls
f007b5e8fb feat(schema): require site on every ingested collection
Tightened site from optional to required on fuel_logs, timesheet_entries,
delivery_notes and purchase_orders now that every route writes it and
every historical row has been backfilled. plant_hours_log was already
required (matches docs/data-model.md's documented invariant, confirmed
against production). timesheets (the document collection) was already
required from Task 6 -- a no-op here, not a regression.

fuel_sheets.site and plant_hours_sheets.site deliberately stay optional:
those sheets can legitimately span multiple sites.

Verified: creating a fuel_logs row with no site now gets a hard 400
(validation_required) from PocketBase itself.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-11 15:32:48 +02:00
DEls
f184776148 docs(n8n): repoint PO ingest workflow at purchase_orders
Task 15 of the ingestion restructure. Edited the live n8n workflow
(005iI4jX5mq9DsTR) directly via MCP and published the new version.

Repointed Watchdog: List Stuck, Watchdog: Reset Stuck Rows, Fetch Pending
Batches, Atomic Claim, Claim Successful?, Download File and Escalate
Failure from data_import_batches/status onto purchase_orders/
processing_status. Verified zero in-flight rows would be orphaned: all
26 old purchase_orders-type batches were already processed or failed,
and all 24 real PO rows had processing_status unset (won't match the new
pending filter).

Two things found on the live workflow that the plan didn't anticipate:

- Atomic Claim had no ?filter=processing_status="pending" guard at all --
  an unconditional PATCH, despite the workflow's own name and this doc's
  prior description both calling it "atomic". Added while repointing the
  same node.
- Build Callback Payload sent the extracted PO number as `po_number`.
  process-batch's validator requires the field named exactly
  `purchase_order_number` -- the old field name would have failed
  validation on every single real upload, a total silent outage. Fixed
  before publishing, verified against the route's actual validateExtracted().

Also removed the n8n-side duplicate short-circuit: the old
Build Callback Payload queried purchase_orders and PATCHed the batch row
directly from n8n code to pre-empt process-batch's own dedup logic.
process-batch's merge branch (Task 14) already does this correctly,
server-side, tested. Keeping both meant the same decision made twice in
two places that could disagree. Is Duplicate? node removed; Build
Callback Payload connects straight to Send Callback.

Published as the active version and verified by reading the workflow
back in full -- every repointed node confirmed, connections confirmed,
zero validation warnings.

Rewrote docs/n8n/purchase-order-ingest-implementation.md end to end to
describe the deployed shape rather than the retired one. Flagged (not
fixed, separate decision) a plaintext PB superuser password baked into
the Auth PB Admin node.

Marked Tasks 1-15 complete in the plan's own checkboxes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 14:46:57 +02:00
DEls
3a71e7e884 feat(schema): add timesheets, fuel_sheets, plant_hours_sheets documents
Three document collections replacing data_import_batches for the
spreadsheet importers. Each owns its source file and carries honest
outcome counters (rows_total/created/failed, row_errors) — the counts the
current importers compute and then discard.

site is required on timesheets (a wage sheet belongs to one site) and
optional on the other two, which legitimately span sites since the fuel
importer resolves a site per row. cascadeDelete is false on all three, so
deleting a site cannot destroy its source spreadsheets.

Widened source_file mimeTypes beyond the plan's three entries to match
the pool being replaced. Browsers label CSVs text/csv, application/csv or
text/plain interchangeably and the importers branch on file extension,
not MIME — so the narrower list would have parsed a CSV successfully then
rejected it on write. The 2026-08-24 migration exists because that
already happened once.

Plan corrected: its TypeScript edit added a second `expand` property to
an interface that already had one, which does not compile.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 11:09:14 +02:00
DEls
9117b73cd4 fix(fuel): backfill site on 147 orphaned fuel logs
147 of 320 fuel_logs had no site relation; their only attribution was the
denormalised project_code text, which Task 18 deletes. Backfilled before
that column goes, resolving each row twice (by project_code and via the
vehicle's own site) and writing only on agreement.

147/147 written, 0 skipped, 0 remaining.

Recorded a caveat the dry run exposed: with one site in production both
resolvers draw from a candidate set of size one, so "both agree" is
guaranteed rather than evidence. The write is still the only possible
correct value, but the guard only bites once more sites exist.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 10:44:19 +02:00
DEls
5274ac4981 fix(migration): separate download failures from missing files
Review found a transient 500 during download landed in the "no stored
file" bucket, so a broken run printed as a clean one and exited 0. Now
counted separately and exits non-zero.

Also: 404 is no longer swallowed on mutations (a PATCH against a deleted
record was counted as written), the target host and mode are printed, the
apply path reports a final written count, and filenames quote with
safe="".

Plan Task 1 Step 4 still carried the superseded copy-from-batch code
block under the rewritten prose, contradicting it. Replaced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 10:39:54 +02:00
DEls
147ce7e77a feat(schema): hash entity files directly instead of copying batch hashes
Production disproved the copy-from-batch approach in two ways:
- 10 delivery-note batches carry no file_hash at all (they predate
  78fa8da), and all 10 sit inside the 30-day dedup window, so copying
  would have left a live gap rather than a historical one
- one PO row was produced from two different files with different
  hashes via the dedup-by-PO-number branch, so copying gives
  last-write-wins on an arbitrary one

Hashing the stored bytes has neither problem and does not depend on the
collection we are about to delete. 56/56 records covered, none skipped.

Immediately surfaced a real duplicate the old path missed: two delivery
notes numbered IN132202 with identical bytes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 10:32:41 +02:00
DEls
9a8d637ff1 docs(plan): ingestion restructure implementation plan
20 tasks across four phases, each phase ending at a shippable state.
Phase 1 additive only, Phase 2 renames and document collections, Phase 3
route cutover, Phase 4 drops. Nothing is deleted before Phase 4, so every
earlier phase is reversible.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 10:21:29 +02:00
DEls
8075f6798a docs(spec): add PO fulfilment model — outstanding is computed, not stored
Partial deliveries against a PO line are the reason qty_outstanding is
dropped rather than wired: a stored counter must be decremented correctly
on every receipt, OCR re-run and correction, and PocketBase has no real
transactions to guarantee that. The sum over delivery_note_items cannot
drift.

Records the relation chain, the two invariants (unmatched lines count
toward nothing; over-delivery is legal), and the fulfilment test cases.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 10:09:12 +02:00
DEls
2814061b28 docs(spec): ingestion restructure — per-entity documents, honest status
Replaces the data_import_batches upload pool with five typed document
collections that each own their file, makes upload status reflect what
actually happened, puts a real site on every ingested row, and removes
the project_code duplication.

Audited against production on 2026-09-11:
- 19 plant_hours batches marked 'processed'; plant_hours_log has 1 row
- 147 of 320 fuel_logs have no site relation
- purchase_orders.project_code holds requisition numbers and site names,
  not project codes — automatic site matching succeeds ~8% of the time
- PLANT collection and two data_import_batches fields have zero readers

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 10:02:42 +02:00
DEls
08ed89d9c8 feat(dashboard): enhance operations dashboard with rain outlook and coordinate support
Updated the operations dashboard to include a rain outlook feature, providing users with a 7-day forecast based on site coordinates. Added latitude and longitude fields to the site form for better weather data integration. Enhanced the fuel log and site management functionalities to utilize dynamic fuel pricing based on historical data. Improved overall data handling and user experience across various dashboard components.
2026-09-06 19:59:52 +02:00
DEls
2ea87ce56d docs(plan): implement vehicle unit_type inline-edit UI on Fleet + Plant 2026-08-31 12:57:18 +02:00
DEls
31c86b5b89 docs(spec): vehicle unit_type inline-edit UI (fleet + plant)
The vehicles PB collection already has a unit_type field (fuel |
plant, default fuel, made optional on 2026-08-28) and the
PATCH /api/vehicles/[id] endpoint accepts it with full test
coverage. Today there is no UI surface for assigning or changing a
vehicle's unit_type on either the Fleet page (/dashboard/fuel) or
the Plant page (/dashboard/plant), so the 53 currently mis-classified
vehicles cannot be triaged from the UI.

This spec adds that surface via the existing inline-edit pattern
already used on both pages for description editing: a Type column
renders a 'Fleet (L)' / 'Plant (h)' badge in display mode and a
Select in edit mode. Saving a flip calls PATCH /api/vehicles/[id];
on success router.refresh() re-pulls the page and the row drops
out of the page's filter, effectively moving it to the other page.

Scope is intentionally tight:
- Server-side filter on each page (Fleet: unit_type=fuel or empty;
  Plant: unit_type=plant AND cost_per_hour > 0).
- New Type column on the existing Fleet and Plant tables (no new
  pages, no new top-level nav).
- New shared <UnitTypePill> / <UnitTypeSelect> cell components.
- Reuses the generic useInlineEdit<K extends keyof T> hook (no
  hook changes needed).
- No schema migration, no API changes, no new tests.

Spec self-review pass: tightened two claims (pb-types.ts UnitType
line 37 not 48; useInlineEdit is already generic so no hook edit).
2026-08-31 12:48:57 +02:00
DEls
e0e2feb61c docs(pwa): manual install verification steps for real devices 2026-08-30 22:42:55 +02:00
DEls
055387cc6d docs(plan): MEGA Ask vs MEGA OPS PWA split-install icon plan 2026-08-30 22:12:30 +02:00
DEls
459905758f docs(spec): MEGA Ask vs MEGA OPS PWA split-install icon design 2026-08-30 22:11:02 +02:00
DEls
b2b72dacfe docs(plan): agent coverage gaps, vision and PDF export
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-30 12:27:38 +02:00
DEls
410e2f6606 docs(plan): chat detail tools, PO upload and standalone PWA
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-30 08:27:49 +02:00
DEls
ca262cc789 docs(plan): chat UI + provider abstraction (phase 3)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 20:33:03 +02:00
DEls
e82754ee38 docs(plan): agent tool layer + read-only MCP server (phase 2B)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 20:13:39 +02:00
DEls
15206fa650 docs(plan): fuel attention extraction plan (phase 2A)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 20:04:51 +02:00
DEls
2d36e9b1cd fix(vehicles): handle empty unit_type during updates
Updated the vehicles API to allow PATCH requests with an empty unit_type. This change ensures that existing records with unit_type='' can be updated without validation errors, while maintaining the default value of 'fuel' for new inserts. This adjustment resolves issues with updating pre-existing vehicle records that lack a unit_type field.
2026-08-29 19:17:14 +02:00
DEls
71eb1c00cc docs(plan): fix byDateDesc to return 0 on equal dates 2026-08-28 12:54:02 +02:00
DEls
dc966086bd docs(plan): mark backfill migration as required after schema deploy 2026-08-28 12:47:02 +02:00
DEls
45e2cd7827 docs(plan): clarify Burn by category stays monthly-only 2026-08-28 12:37:53 +02:00
DEls
574df58011 docs(plan): site overhead monthly + one-off implementation plan 2026-08-28 12:37:29 +02:00
DEls
ccaeee6896 docs(spec): clarify card subtitle covers monthly + one-off 2026-08-28 12:33:53 +02:00
DEls
2fac85e79d docs(spec): site overhead monthly vs one-off design 2026-08-28 12:33:39 +02:00
DEls
2204989a3c docs(plan): plant hours weekly log implementation plan
Bite-sized TDD task decomposition covering 13 tasks:
1. PocketBase schema (vehicles.unit_type + plant_hours_log)
2. Type updates (UnitType, PlantHoursLogRecord, BatchType)
3. Shared import-parse helpers + parseTime
4. Per-row validator + derived fields
5. Template generator + seed script
6. GET /api/plant-hours/template
7. Exception-report CSV builder + route
8. POST /api/plant-hours/import
9. DELETE /api/plant-hours/[id]
10. PATCH /api/vehicles/[id] accepts unit_type
11. ImportPlantHoursButton component
12. /dashboard/plant page extension
13. End-to-end smoke test

Each task has files, failing tests, implementation code, run commands,
and commit step. Follows the approved design spec.
2026-08-28 12:26:35 +02:00
DEls
c5230190d0 docs(plan): fuel attention dismissal implementation plan
7-task TDD plan: PB migration, API route + tests, isAlertAcknowledged
helper + tests, server mapper + filter, Dismiss button + optimistic
overlay, Dismissed pill + Restore on detail page, full verification
with Agent Browser. Steps use checkbox syntax for subagent-driven
or inline execution.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-28 12:24:14 +02:00
DEls
cc0abfdc2c docs(plant-hours): weekly log import + exception report design
Adds a design doc for capturing weekly plant-equipment hours via an Excel
template against the existing /dashboard/plant page. One new
plant_hours_log collection, one vehicles.unit_type field, three new
routes (import, template download, exception report CSV), and an
extension to PlantView.

Spec covers: lenient import with per-row errors, downloadable exception
report for fix-and-retry, snapshot of vehicle.unit_type on each row,
over-budget flag against a per-week budget, and a symmetric attention
panel on /dashboard/plant for type mismatches.
2026-08-28 12:20:58 +02:00
DEls
0e13720fa7 docs(spec): fuel attention dismissal design
Per-vehicle 'I've seen this' control on the Fuel dashboard. Stamps
attention_dismissed_at on the vehicles collection; auto-undismisses when
a flagged fuel log with date_logged > dismissal arrives. Timestamp only,
no reason field. Tiny POST/DELETE route + filter line in page mapper +
Dismiss button on alert rows + Dismissed/Restore pill on vehicle detail.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-28 12:19:59 +02:00
DEls
58f2ca6a7b docs(plan): PO supplier edit + DN collapse implementation
5 tasks: API route (TDD), SupplierEditor component, wire into
PoDetailView with state, wrap received items in <details>,
final verification with Agent Browser.
2026-08-27 00:50:44 +02:00
DEls
6c00676343 docs(spec): PO detail supplier edit + DN items collapse
Two scoped follow-ups to the supplier-unknown flag (9897f47):
- Edit supplier on detail page when flagged as unknown
- Collapse received items per delivery note by default
2026-08-27 00:49:42 +02:00
DEls
a8e67faf3d docs(plans): purchasing UI tweaks — 4 small tasks with TDD-friendly bite-sized steps 2026-08-26 23:58:30 +02:00
DEls
7020449853 docs(specs): purchasing UI tweaks — shorter upload labels, unlinked-DN styling, view PO PDF, fulfillment bug 2026-08-26 23:56:34 +02:00
DEls
417723628f docs(specs): fix stale URL example, 'above' wording, and add recordId notes 2026-08-26 23:34:10 +02:00
DEls
0c95243ecf docs(specs): screenshot of compact needs-review modal with working PDF 2026-08-26 23:33:33 +02:00
DEls
aded006b9f docs(plans): PDF URL fix + modal compact 2026-08-26 23:21:26 +02:00
DEls
5e86fadc38 docs(specs): PDF URL fix + compact needs-review modal 2026-08-26 23:20:08 +02:00
DEls
6df78d8ccd docs(plans): needs-review modal resize + inline PDF viewer 2026-08-26 23:00:10 +02:00
DEls
988ffc6377 docs(specs): needs-review modal resize + inline PDF viewer 2026-08-26 22:58:11 +02:00
DEls
8dbf393446 feat(delivery-notes): enhance delivery note upload and processing
- Updated the delivery note upload API to include site ID for better project association.
- Modified the delivery note schema to support additional fields such as processing status, OCR confidence, and received by name.
- Enhanced the UI components for uploading delivery notes to allow file drop functionality and improved user feedback during file selection.
- Refactored purchasing page to integrate delivery notes that require review, providing better visibility and management of pending items.
- Added new KPIs to track active purchase orders and fulfillment percentages, improving overall dashboard insights.
2026-08-26 15:33:30 +02:00
DEls
84ff4c25b2 docs: add PO import queue spec/plan, ignore cooler.env, rewrite n8n ingest impl
Captures the async-queue redesign of the PO/DN import pipeline (see
spec + plan) and rewrites the n8n implementation doc to match the
new cron-driven architecture (workflow 005iI4jX5mq9DsTR). Also
gitignores cooler.env so the local-only deployment reference is no
longer tracked.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-19 22:03:39 +02:00
DEls
34f272f520 docs(n8n): mark old webhook-sync flow as superseded
Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-19 20:03:11 +02:00
DEls
e45fa11c74 docs(deploy): document POCKETBASE_ADMIN_TOKEN for process-batch + n8n
Both Next.js /api/purchase-orders/process-batch and the n8n cron
workflow need a PocketBase admin token (generated via PocketBase
admin > Settings > Admins). The existing template only documented
email+password auth.

Add a new 'POCKETBASE (Next.js process-batch + n8n cron)' section
with the token variable, the generation instructions, and the
warning that Next.js env and the n8n workflow's hardcoded token
value must match.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-19 20:01:45 +02:00
DEls
109a6938da Enhance PO upload error handling and validation
- Implement improved error handling for the purchase order upload process, ensuring that failures from n8n are properly surfaced to the user.
- Introduce a timeout mechanism for the n8n fetch request to handle potential delays more effectively.
- Refine the validation logic for the purchase order payload to ensure stricter adherence to expected formats and values.
2026-08-19 15:03:48 +02:00