Cogneris
Environmental Compliance & Inspection

Intent · Every environmental obligation current and evidenced — zero reportable exceedances at Woodbine (UTS).

Operating tolerance: issues closed in ≤ 5 days · no repeat findings · every permit condition met.

← Documentsdocs/GAP-ANALYSIS-console-vs-build.md2,957 words

Gap Analysis and Plan — the deployed console vs. what is built

Question asked: compare and contrast http://esg.cogneris.com with what this repository actually contains, against BRD-field-processes.md, FRD-field-processes.md and ARCHITECTURE-and-process-models.md. Companion: UX-simplicity-design-and-plan.md — the simplicity standard applied to these surfaces, and the UX gates folded into §4. Read it before building anything in Phase 1 or 4; it argues for reducing the console from twelve destinations to four rather than making all twelve dynamic. Date: 2026-07-29. Assessed against: feat/rn-app-parity (working tree, including uncommitted files) and main. Status: draft for review.

This document does not restate the BRD/FRD gap registers. It reports what changes when the deployed artifact is compared with the repository, and what those three documents get wrong or leave out.


0. What could and could not be verified

esg.cogneris.com could not be observed. Every path probed returns HTTP 302 to cogneris.cloudflareaccess.com — /, /app, /demoapp, /inspections, /api/inspections, /favicon.ico and static assets alike. There is no Access-exempt route on the hostname. This machine reaches the edge over WARP and is recognised as a device (is_warp: true), but the Access policy records auth_status: NONE, and no Access token is cached in ~/.cloudflared.

So the assertion in BRD §2.2 — "the console source in this repository (app/) … is that deployment" — remains unverified, and the FRD/BRD statements that it returned 403 are imprecise: it returns 302, and did so for every path, not just the root.

Everything below is therefore derived from the deployed source, with one identification that is strong but not proof:

EvidenceReading
wrangler.jsonc declares one worker, esg-web, main: .open-next/worker.jsthe console is the only thing deployable to that host from this repo
apps/esg-field/app/index.tsx:4 — "a React Native port of the shell at https://esg.cogneris.com/app"the live site serves /app
On main the route is app/app/page.tsx; on this branch it is renamed to app/demoapp/the live site is main, not this branch
apps/esg-field/HANDOFF.md:19 cites esg.cogneris.com/demoappforward-looking; that path does not exist on main

Conclusion: esg.cogneris.com ≈ app/ at main. Three ways to close this gap properly are listed in §5.


1. What the live console is, surface by surface

Twelve navigation entries on main (app/components/ConsoleShell.tsx) — the BRD counted eleven. Data source is the load-bearing column:

Nav labelRouteData sourceOn the live site
Live Brief/briefapp/lib/brief.ts — hardcodedStatic
My Work/my-workapp/lib/mywork.ts — hardcodedStatic
Conversations/conversationsapp/lib/conversations.ts — hardcodedStatic
Compliance/complianceapp/lib/compliance.ts — hardcodedStatic
Permits/permitsapp/lib/permits.ts — hardcodedStatic
Decision Log/ledgerapp/lib/ledger.ts — hardcodedStatic
Obligations/obligationsapp/lib/obligations.ts — hardcodedStatic
Reporting/dashboardapp/lib/mock.ts — hardcodedStatic
Inspections/inspectionsfetch('/api/inspections') → node:sqliteBroken — see GA-1
Field app/appin-page demo flowStatic
Voice/vuibrowser SpeechRecognitionPartly live
Field App/appduplicate of row 10Duplicate entry
(unlisted)/adminfetch('/api/admin') → node:sqlite404 by design — see GA-2

Only two of thirteen routes read or write anything. Both are the two that cannot work in production.

The BRD calls the console "a thin inspection tool". That is generous in one direction and unfair in the other: it is a mock-data demo shell of nine surfaces, plus one persistence-backed inspection surface that the deployment cannot run.


2. Three products, one repository

Deployed console (app/, main)Server estate (workers/, packages/)Field client (apps/esg-field/)
Size13 routes, ~3,600 lines of page code12 workers, 16 packagesRN app, 15 screens, 12 lib/ modules
Persistencenode:sqlite file, 3 flat tables, open → submittedappend-only hash-chained event store (D1), CQRSappend-only SQLite event log + relational store
Vocabularyits own local types (app/lib/capture.ts)@esg/events-*its own local types (lib/store/events.ts)
Deployed?yes (behind Access)no route declared on 11 of 12 workersnot shipped to a store
Governed by @esg/*?noyesno

The three do not share a type, a store, or a lifecycle. The ARCHITECTURE doc names this ("three independent layers … they do not meet"); what it does not say is that the layer users can actually reach is the weakest of the three, and the two stronger ones are undeployed.


3. Gap register — what is new or wrong relative to the existing docs

Ordered by consequence. NEW = absent from the BRD/FRD/ARCH gap registers. CORRECTS = contradicts them.

GA-1 · NEW · The live console's only working surface cannot work in production

app/lib/db.ts opens a SQLite file with DatabaseSync from node:sqlite and mkdirSync(./.data). The deployment target is a Cloudflare Worker via @opennextjs/cloudflare, and wrangler.jsonc declares zero bindings — no D1, no KV, no R2:

{ "name": "esg-web", "main": ".open-next/worker.js",
  "compatibility_flags": ["nodejs_compat"],
  "assets": { "directory": ".open-next/assets", "binding": "ASSETS" } }

node:sqlite is not part of workerd's nodejs_compat surface, and a Worker has no writable filesystem for ./.data/esg.db regardless. app/admin/page.tsx:68 already concedes the intent — "*the same surfaces point at D1 + R2 in production*" — but nothing implements that path, and no binding exists to implement it against.

Consequence: on esg.cogneris.com, capturing a finding at /inspections fails. Every persistence claim about the console in the BRD (§2.2, "persists three flat tables") is true of a developer's laptop only. The delivery boundary the ARCHITECTURE doc draws at device → console is in fact severed one hop further in: the console has no server-side store at all.

Confidence: high, but not executed. Verify with pnpm build && npx opennextjs-cloudflare build and one POST /api/inspections against the deployed instance.

GA-2 · NEW · /admin is a 404 on the deployed site by design

middleware.ts gates /admin and /api/admin, and app/lib/admin-access.ts:19 admits only localhost / 127.0.0.1 / ::1. Non-local callers get 404 — the surface is not merely denied, it is hidden. The uncommitted app/lib/dev-ip-bypass.ts exists to relieve exactly this, but it is off unless two flags are set (ESG_DEV_AUTH_BYPASS=1 plus ESG_DEV_AUTH_BYPASS_IN_PRODUCTION=1 in production), and its allowlist is two WARP egress addresses that the file itself documents as shared and rotating.

Neither the BRD nor the FRD mentions /admin at all. It is the only surface that inspects what capture wrote, and on the live site it does not exist.

GA-3 · CORRECTS · The NCR ticket lifecycle is built — the FRD says it is not

FRD §2 marks FR-NCR-1 through FR-NCR-17 as ❌ absent. The working tree contains 444 lines implementing precisely that ladder — untracked, at apps/esg-field/lib/ncr/ticket.ts:

foldNcr, readNcr, listNcrs, isOverdue, raiseNcr, assignNcr, recordCorrectiveAction, verifyNcr, closeNcr, reopenNcr, plus NcrStatus and a typed NcrErrorCode for the refusals FR-NCR-8/10/12/17 require.

ARCHITECTURE §3 already describes it as implemented ("*the one lifecycle now implemented on the device, in apps/esg-field/lib/ncr/ticket.ts*"). The FRD and the ARCHITECTURE doc contradict each other on the single highest-priority requirement family in the specification. The FRD status column is stale.

GA-4 · NEW · The NCR screens are reachable from nowhere

apps/esg-field/screens/ncr/NcrInbox.tsx and NcrRaise.tsx exist and import lib/ncr correctly. No file in app/, screens/ or ui/ references either of them. They are untracked, unrouted, and unreachable — a complete FR-NCR-16 ticket inbox that no operator can open.

This is the difference between "built" and "delivered", and it is the cheapest gap in this document to close.

GA-5 · NEW · Duplicate navigation entry on the live site

SURFACES in app/components/ConsoleShell.tsx lists /app twice — "Field app · On-site phone capture" and "Field App · Mobile · Hey Brian fork". isActive matches the first, so the second is dead. This is visible to every user of the deployed console.

GA-6 · NEW · This branch renames the route the live site serves

main serves /app; feat/rn-app-parity renames it to /demoapp (the only app/ change on the branch besides two ConsoleShell lines). Merging silently 404s the URL the RN app's own source cites as its reference shell, and the one HANDOFF.md describes the demo app as replicating. Either a redirect ships with the rename, or the rename does not ship.

GA-7 · NEW · The server estate is not deployed

Eleven of twelve workers declare no route or custom domain; only workers/esg-memory does. The CQRS write plane, the projection runner, the query front door, esg-sync — none is addressable. The ARCHITECTURE doc says the server side "is scaffolded and boots green"; it does not say nothing is published, which changes what FR-IF-1 costs. Fixing the Access problem alone would not produce a reachable ingest, because there is no deployed ingest to reach.

The doc references ../diagrams/esg/*.svg for all nine figures. diagrams/esg/ does not exist. The figures exist as PNG at docs/diagrams/*.png (527K–883K each), and docs/diagrams/README.md itself claims "SVG only, in the same house style as ../svg/" while listing nine .svg filenames that are not present — and diagrams/svg/ does not exist either (the house-style SVGs sit flat in diagrams/).

Nine broken images, a README that misdescribes its own contents, and a rasterised departure from the SVG house style. The document set does not render.

GA-9 · NEW · The entire analysis is uncommitted, on a diverged branch

docs/, diagrams/, apps/esg-field/lib/ncr/ticket.ts, screens/ncr/, app/lib/dev-ip-bypass.ts and the NCR/report tests are all untracked. feat/rn-app-parity is 15 commits behind and 11 ahead of main — diverged, not ahead. The BRD, FRD, architecture models and the NCR implementation exist on one working tree and nowhere else.

GA-10 · Confirmed as stated · Audit, incident and investigation

The BRD/FRD findings hold on inspection: no audit/ aggregate or vocabulary package anywhere; no incident capture; no investigation aggregate. One detail sharpens: apps/esg-field/screens/inspect/InspectApp.tsx presents a "New investigation" button beside "New inspection", creating an investigation as a template-less walk. The wrong axis is not only in the type (TaskKind) — it is on screen, offered to operators.


4. Plan

Each step is independently mergeable and preserves compatibility for concurrent work, per the CDT independence rule in AGENTS.md. Phase 0 is hours, not days, and every later phase is cheaper once it is done.

Phase 0 — Truth-up (no new features; unblocks the rest)

#ActionClosesIndependent
0.1Obtain Access for the analyst (service token, or cloudflared access login), observe the live site, and record what it actually serves§0yes
0.2Run opennextjs-cloudflare build and one live POST /api/inspections; record whether it fails at build or at runtimeGA-1yes
0.3Correct the FRD status column for FR-NCR-*; reconcile it with ARCHITECTURE §3GA-3yes
0.4Fix the diagram paths — publish SVG at diagrams/esg/, or repoint the doc at docs/diagrams/*.png; correct docs/diagrams/README.mdGA-8yes
0.5Commit docs/, diagrams/, lib/ncr/ticket.ts, screens/ncr/, tests. Decide dev-ip-bypass.ts separately — it is an auth change, not a doc changeGA-9yes
0.6Rebase or merge main into feat/rn-app-parity; 15 commits of drift will not get cheaperGA-9yes

Phase 1 — Make the deployed console honest (one PR each, no coordination)

#ActionCloses
1.1Delete the duplicate /app nav entryGA-5
1.2Ship a /app → /demoapp redirect with the rename, or drop the renameGA-6
1.3Decide GA-1 explicitly — either (a) bind D1 in wrangler.jsonc and give app/lib/db.ts a D1 driver behind the same function signatures, or (b) label /inspections a demo surface and stop claiming persistence. Do not leave it claiming a store it does not haveGA-1
1.4Give /admin a real gate (Access service token or the esg-auth session JWT) instead of an IP allowlist, or state in the doc set that it is a localhost-only developer toolGA-2

1.3(a) is the smaller change than it looks: the three tables in db.ts already mirror the D1 read model, and the API route calls five named functions. It is a driver swap plus a binding, not a rewrite. It is also the first thing that makes the console capable of receiving anything.

Phase 2 — A reachable ingest (FR-IF-1 — the gate on BO-6)

Ordered, because GA-7 changes the sequence the FRD proposed:

#ActionNote
2.1Publish one ingest worker with a route. Nothing is addressable today (GA-7); this is a prerequisite the FRD assumed awaycode + ops
2.2Resolve the device credential: Access service token for the handset, or an Access-exempt ingest path with its own authenticationops decision — BRD DP-1 / AS-5
2.3Reconcile apps/esg-field/lib/sync with the endpoint that actually exists (routes and body shape currently do not match workers/esg-sync)code
2.4Prove it: one inspection captured offline on a handset, visible in the console with no manual stepacceptance of BO-6

Start 2.2 now, in parallel with everything else — it is the only item here that a developer cannot unblock.

Phase 3 — Deliver the NCR ticket that already exists

#ActionCloses
3.1Route NcrInbox and NcrRaise into the shell; make raise reachable standalone and from a walk finding (FR-NCR-3)GA-4
3.2Tests asserting each refusal and that nothing was appended (FRD §11)FR-NCR-8/10/12/13
3.3Console NCR inbox, once Phase 1.3 gives the console a storeFR-IF-4

Phase 4 — Split coverage from conformity (FR-DM-2)

AreaInspected.status fuses "walked it, nothing wrong" with "nobody reached it". This is a breaking change to a committed event shape, so it needs a compatibility seam: a new coverage event alongside the existing status, with the report (apps/esg-field/lib/report/inspectionIR.ts) preferring the explicit fact and falling back to the honest "not stated". Prerequisite for an audit that does not lie about scope.

Phase 5 — Audit, on the walk engine

Blocked on BRD DP-2 (the standard/clause set). Build as the same walk engine discriminated by kind, per the FRD's design direction — not a second engine. Needs a new @esg/events-audit vocabulary, because the grading ladder (major / minor / observation / OFI) is not an inspection verdict and not an NCR severity.

Phase 6 — Incident → investigation → report

#Action
6.1Remove the "New investigation" button until an investigation is a case, not a walk (GA-10). Offering the wrong model is worse than offering nothing
6.2Incident capture against the contracted @esg/events-incident vocabulary — occurredAt and reportedAt separate, immediate actions recorded
6.3investigation/{id} as a case: evidence, statements, timeline, root cause with stated method
6.4Investigation report folded from the event stream, reusing the lib/report pattern

Cross-cutting, whenever any of the above touches the device

Bind the field app to the @esg/* vocabularies, or state as a decision that the device owns its own shapes and the sync tier translates. Today it is neither — it restates them by hand, silently.


5. Decisions needed

IDDecisionBlocking
GD-1How does the analyst (and CI) reach esg.cogneris.com? Service token, WARP device posture, or a staging hostname outside Access§0, 0.1, 0.2 — every claim about the live site stays inferred until this is answered
GD-2Is the deployed console a demo or a product? GA-1 has no correct fix until this is settled — bind D1, or stop claiming a store1.3, and the whole framing of §1
GD-3Ship the IP bypass, or gate /admin properly?1.4, GA-2
GD-4Which single worker becomes the published ingest, and on what hostname?2.1
GD-5Does the field app adopt @esg/*, or is device-local vocabulary the settled design?cross-cutting

Open business decisions OD-1…OD-5 and dependencies DP-1…DP-4 in the BRD are unchanged and still stand.


6. The short version

The BRD's headline — "no process in scope completes end to end; work captured on a device stays on that device" — is right, and understated in two ways this comparison exposes.

  1. It is worse at the office end than documented. The console is not a thin tool with a small store; it is nine mock surfaces plus one persistence-backed surface whose store (node:sqlite, no bindings) cannot exist on the deployment target. Work would have nowhere to land even if the device could send it (GA-1), and eleven of twelve workers are not published at all (GA-7).
  2. It is better on the device than documented. The NCR ticket lifecycle the FRD marks entirely absent is implemented — 444 lines, the full ladder with typed refusals — and merely unrouted and uncommitted (GA-3, GA-4, GA-9).

The most valuable next hour is Phase 0. Half this document exists because a document set, an implementation and a deployment each described a different system, and nobody could see the third one.