MEGAINFRA-WEBAPP/src/lib
DEls 5aac22ba8f feat(ask): propose, confirm, apply and undo changes
The gateway (src/lib/agent/gateway.ts) is now the one seam every write
goes through: authorize() (NEVER_WRITABLE + dn_batches lock_*/stage),
planOps (schema validation via schema-cache.ts's new validateOp,
before-snapshots, $ref cross-checks, relation-id existence, the
sites/employees duplicate rule, capped at 500 ops), createPendingAction,
applyAction and undoAction. propose_changes is a registered tool;
apply/reject/undo are confirm-card routes under
/api/agent/actions/[id]/, same-origin only.

/api/chat now streams a full action card (`event: action`) while the
model itself only ever sees {actionId, status, problems} — the same
split extractCharts already does for chart numbers (extractActionCard).
The next user turn gets the outcome of the prior turn's action(s)
prepended to what the model reads (ChatEntry has no system role, so
this is the pragmatic equivalent of a system note). chat-view.tsx
renders action-card.tsx per assistant turn, hydrating from
GET /api/agent/actions/[id] when a thread reopens.

Deviations, both noted for the smallest-sensible-adjustment reason:
- Batches run as sequential individual PocketBase calls, not
  pb.createBatch() — that's what makes $ref resolution exact rather
  than dependent on the batch API's own (version-sensitive) request-
  chaining syntax.
- Re-applying a "failed" action isn't specially deduped against ops
  that already partially succeeded; only the single-attempt path is
  implemented in this session.

Live check skipped: ask_threads/ask_messages/ask_log still don't exist
in the target PocketBase (Task 1's --apply is the user's own step).
Covered by mocked unit tests instead — 17 gateway tests plus the
confirm-card routes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 18:54:06 +02:00
..
agent feat(ask): propose, confirm, apply and undo changes 2026-09-26 18:54:06 +02:00
chat feat(ask): propose, confirm, apply and undo changes 2026-09-26 18:54:06 +02:00
dn-pipeline refactor(dn-inbox): move board columns and stage mapping to src/lib/dn-pipeline/board 2026-09-26 09:38:43 +02:00
metrics feat(suppliers): green-row tint, period filter, and KPI tiles 2026-09-26 17:38:39 +02:00
reports fix(ask): findings carry their own cross-site totals 2026-09-26 09:52:32 +02:00
weather feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
attendance.test.ts refactor(on-site): move attendance grouping to src/lib/attendance 2026-09-25 22:34:06 +02:00
attendance.ts refactor(on-site): move attendance grouping to src/lib/attendance 2026-09-25 22:34:06 +02:00
attention-acknowledged.test.ts feat(fuel): isAlertAcknowledged helper for dismiss filter 2026-08-28 12:35:36 +02:00
attention-acknowledged.ts feat(fuel): isAlertAcknowledged helper for dismiss filter 2026-08-28 12:35:36 +02:00
batch-state.test.ts refactor(batch): drop unused status field, expand test edges 2026-08-19 19:29:35 +02:00
batch-state.ts refactor(batch): drop unused status field, expand test edges 2026-08-19 19:29:35 +02:00
clock-correction.test.ts feat(clock): review missed scan-outs without changing phone flow 2026-09-25 07:27:12 +02:00
clock-correction.ts feat(clock): review missed scan-outs without changing phone flow 2026-09-25 07:27:12 +02:00
clock-day.test.ts feat(clock): define local workday and shift records 2026-09-25 02:03:46 +02:00
clock-day.ts feat(clock): define local workday and shift records 2026-09-25 02:03:46 +02:00
clock-events.test.ts feat(clock): review missed scan-outs without changing phone flow 2026-09-25 07:27:12 +02:00
clock-events.ts feat(clock): review missed scan-outs without changing phone flow 2026-09-25 07:27:12 +02:00
dn-item-row.test.ts fix(dn-pipeline): read a pipe's length off both documents to convert each into metres 2026-09-18 08:54:21 +02:00
dn-item-row.ts fix(dn-pipeline): read a pipe's length off both documents to convert each into metres 2026-09-18 08:54:21 +02:00
dn-page-token.ts feat(dn): flip between the slip and the order it is checked against 2026-09-21 01:44:02 +02:00
document-kind.test.ts fix(financial): an invoice is evidence of delivery, not a reason to discount it 2026-09-18 01:42:27 +02:00
document-kind.ts fix(financial): an invoice is evidence of delivery, not a reason to discount it 2026-09-18 01:42:27 +02:00
document-status.test.ts feat(ingest): add honest document status resolution 2026-09-11 13:43:15 +02:00
document-status.ts feat(ingest): add honest document status resolution 2026-09-11 13:43:15 +02:00
fuel-import-parse.test.ts feat(fuel): drop-in xlsx/csv import for pump sheets 2026-08-24 22:03:08 +02:00
fuel-import-parse.ts refactor(imports): extract shared import-parse helpers + add parseTime 2026-08-28 12:41:59 +02:00
fuel-prices.test.ts feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
fuel-prices.ts feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
fuel-variance.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
image-quality.test.ts feat(clock): photograph a delivery note on site, and check it can be read 2026-09-18 18:36:41 +02:00
image-quality.ts feat(clock): photograph a delivery note on site, and check it can be read 2026-09-18 18:36:41 +02:00
import-parse.test.ts refactor(imports): extract shared import-parse helpers + add parseTime 2026-08-28 12:41:59 +02:00
import-parse.ts refactor(imports): extract shared import-parse helpers + add parseTime 2026-08-28 12:41:59 +02:00
merge-candidates-load.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
merge-candidates.test.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
merge-candidates.ts feat(ask): improvement report 2026-09-25 22:32:08 +02:00
nearest-site.test.ts feat(clock): photograph a delivery note on site, and check it can be read 2026-09-18 18:36:41 +02:00
nearest-site.ts feat(clock): photograph a delivery note on site, and check it can be read 2026-09-18 18:36:41 +02:00
ocr-result-tier.test.ts feat(ocr-result): enhance PO validation and tier resolution logic 2026-08-26 22:07:42 +02:00
ocr-result-tier.ts refactor(schema): rename received_items and timesheets to their real names 2026-09-11 11:01:40 +02:00
pack-size.test.ts fix(dn-pipeline): read a pipe's length off both documents to convert each into metres 2026-09-18 08:54:21 +02:00
pack-size.ts fix(dn-pipeline): read a pipe's length off both documents to convert each into metres 2026-09-18 08:54:21 +02:00
partition-fixed-costs.test.ts test(partition-fixed-costs): add failing tests 2026-08-28 12:50:36 +02:00
partition-fixed-costs.ts feat(lib): add partitionFixedCosts helper 2026-08-28 12:53:38 +02:00
pb-types.ts feat(clock): review missed scan-outs without changing phone flow 2026-09-25 07:27:12 +02:00
pb.ts feat(purchasing): enhance purchasing page with received items tracking 2026-08-26 23:05:05 +02:00
pdf-page-count.ts feat(dn): grab and move the order the same way as the slip 2026-09-21 02:05:31 +02:00
photo-pdf.test.ts feat(clock): photograph several pages, send them as one document 2026-09-18 19:10:16 +02:00
photo-pdf.ts feat(clock): photograph several pages, send them as one document 2026-09-18 19:10:16 +02:00
plant-hours-exception.test.ts fix(plant-hours): exception-report correctness + safety 2026-08-28 13:13:27 +02:00
plant-hours-exception.ts feat(plant-hours): exception-report CSV builder + route 2026-08-28 13:06:17 +02:00
plant-hours-import.test.ts refactor(schema): resolve project_code through site, not a stored copy 2026-09-11 16:01:14 +02:00
plant-hours-import.ts refactor(schema): resolve project_code through site, not a stored copy 2026-09-11 16:01:14 +02:00
plant-hours-schema.test.ts test(plant-hours): cover unknown-QR deviation + value rounding 2026-08-28 12:48:42 +02:00
plant-hours-schema.ts refactor(schema): resolve project_code through site, not a stored copy 2026-09-11 16:01:14 +02:00
plant-hours-template.test.ts feat(plant-hours): template workbook generator + seed file 2026-08-28 12:51:14 +02:00
plant-hours-template.ts fix(plant-hours-template): ESM-safe __dirname + freeze note 2026-08-28 12:55:08 +02:00
po-choices.test.ts feat(delivery-notes): let an operator pick the purchase order themselves 2026-09-18 08:48:38 +02:00
po-choices.ts feat(delivery-notes): let an operator pick the purchase order themselves 2026-09-18 08:48:38 +02:00
po-fulfilment.test.ts fix(financial): an invoice is evidence of delivery, not a reason to discount it 2026-09-18 01:42:27 +02:00
po-fulfilment.ts fix(financial): an invoice is evidence of delivery, not a reason to discount it 2026-09-18 01:42:27 +02:00
po-matching.test.ts feat(purchase-orders): enhance PO handling with improved validation and item management 2026-09-23 23:37:37 +02:00
po-matching.ts fix(dn): resolve supplier and PO within batch site 2026-09-19 07:39:33 +02:00
po-placeholder.test.ts feat(purchasing): create the PO row at upload with a placeholder number 2026-09-11 14:14:19 +02:00
po-placeholder.ts feat(purchasing): create the PO row at upload with a placeholder number 2026-09-11 14:14:19 +02:00
project-calendar.test.ts feat(project-calendar): add work-month/week bucketing with tests 2026-09-11 22:24:37 +02:00
project-calendar.ts feat(timesheets): add project Month/Week badge and filter 2026-09-11 22:27:06 +02:00
purchase-order-document.ts feat(dn): grab and move the order the same way as the slip 2026-09-21 02:05:31 +02:00
purchase-order-schema.test.ts feat(purchase-orders): enhance PO handling with improved validation and item management 2026-09-23 23:37:37 +02:00
purchase-order-schema.ts feat(purchase-orders): enhance PO handling with improved validation and item management 2026-09-23 23:37:37 +02:00
safe-redirect.test.ts feat(auth): add safe-redirect helper for post-PIN navigation 2026-09-12 00:14:35 +02:00
safe-redirect.ts feat(auth): add safe-redirect helper for post-PIN navigation 2026-09-12 00:14:35 +02:00
site-coordinates.ts feat(dashboard): enhance operations dashboard with rain outlook and coordinate support 2026-09-06 19:59:52 +02:00
site-scope-server.ts fix(site-scope): split server-only getSiteScope into site-scope-server.ts 2026-09-11 23:34:34 +02:00
site-scope.test.ts fix(site-scope): close two latent leaks and the stale scope pill 2026-09-11 23:56:28 +02:00
site-scope.ts fix(site-scope): close two latent leaks and the stale scope pill 2026-09-11 23:56:28 +02:00
supplier-ledger.test.ts fix(financial): an invoice is evidence of delivery, not a reason to discount it 2026-09-18 01:42:27 +02:00
supplier-ledger.ts fix(financial): an invoice is evidence of delivery, not a reason to discount it 2026-09-18 01:42:27 +02:00
supplier-period.test.ts feat(suppliers): green-row tint, period filter, and KPI tiles 2026-09-26 17:38:39 +02:00
supplier-period.ts feat(suppliers): green-row tint, period filter, and KPI tiles 2026-09-26 17:38:39 +02:00
timesheet-casual-parse.test.ts feat(timesheets): enhance import functionality with site linking and employee creation 2026-08-26 12:44:02 +02:00
timesheet-casual-parse.ts feat(timesheets): enhance import functionality with site linking and employee creation 2026-08-26 12:44:02 +02:00
timesheet-grid-parse.test.ts feat(timesheets): enhance import functionality to support XLSX and CSV formats 2026-08-25 18:38:02 +02:00
timesheet-grid-parse.ts feat(timesheets): enhance import functionality to support XLSX and CSV formats 2026-08-25 18:38:02 +02:00
units.test.ts feat(units): add closed-table quantity conversion 2026-09-17 12:04:19 +02:00
units.ts feat(units): add closed-table quantity conversion 2026-09-17 12:04:19 +02:00
use-file-drop-zone.ts feat(delivery-notes): enhance delivery note upload and processing 2026-08-26 15:33:30 +02:00
use-inline-edit.ts feat(inline-edit): add wireMap option for snake_case keys; plant Type column 2026-08-31 13:11:10 +02:00
utils.test.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
utils.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
validate-matched-po-items.test.ts feat(ocr-result): enhance PO validation and tier resolution logic 2026-08-26 22:07:42 +02:00
validate-matched-po-items.ts feat(ocr-result): enhance PO validation and tier resolution logic 2026-08-26 22:07:42 +02:00
vehicle-buckets.test.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
vehicle-buckets.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
vehicle-merge.test.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
vehicle-merge.ts fix: overview counts, wrong-unit fuel limits, meter guard, en-ZA numbers, vehicle merge, docs 2026-09-25 22:04:08 +02:00
worker-qr-batch.test.ts feat(worker-qr): real PDF + CSV batch export 2026-09-20 20:43:10 +02:00
worker-qr-batch.ts feat(worker-qr): real PDF + CSV batch export 2026-09-20 20:43:10 +02:00
worker-qr.test.ts feat(workforce): add worker QR payload helper 2026-09-11 20:56:43 +02:00
worker-qr.ts feat(workforce): add worker QR payload helper 2026-09-11 20:56:43 +02:00
workforce-hours.test.ts refactor(workforce): extract shared weekly-hours math with tests 2026-09-11 20:57:03 +02:00
workforce-hours.ts refactor(workforce): extract shared weekly-hours math with tests 2026-09-11 20:57:03 +02:00