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:
| Evidence | Reading |
|---|---|
wrangler.jsonc declares one worker, esg-web, main: .open-next/worker.js | the 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/demoapp | forward-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 label | Route | Data source | On the live site |
|---|---|---|---|
| Live Brief | /brief | app/lib/brief.ts — hardcoded | Static |
| My Work | /my-work | app/lib/mywork.ts — hardcoded | Static |
| Conversations | /conversations | app/lib/conversations.ts — hardcoded | Static |
| Compliance | /compliance | app/lib/compliance.ts — hardcoded | Static |
| Permits | /permits | app/lib/permits.ts — hardcoded | Static |
| Decision Log | /ledger | app/lib/ledger.ts — hardcoded | Static |
| Obligations | /obligations | app/lib/obligations.ts — hardcoded | Static |
| Reporting | /dashboard | app/lib/mock.ts — hardcoded | Static |
| Inspections | /inspections | fetch('/api/inspections') → node:sqlite | Broken — see GA-1 |
| Field app | /app | in-page demo flow | Static |
| Voice | /vui | browser SpeechRecognition | Partly live |
| Field App | /app | duplicate of row 10 | Duplicate entry |
| (unlisted) | /admin | fetch('/api/admin') → node:sqlite | 404 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/) | |
|---|---|---|---|
| Size | 13 routes, ~3,600 lines of page code | 12 workers, 16 packages | RN app, 15 screens, 12 lib/ modules |
| Persistence | node:sqlite file, 3 flat tables, open → submitted | append-only hash-chained event store (D1), CQRS | append-only SQLite event log + relational store |
| Vocabulary | its 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 workers | not shipped to a store |
Governed by @esg/*? | no | yes | no |
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.
GA-8 · NEW · Every diagram link in the ARCHITECTURE doc is broken
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)
| # | Action | Closes | Independent |
|---|---|---|---|
| 0.1 | Obtain Access for the analyst (service token, or cloudflared access login), observe the live site, and record what it actually serves | §0 | yes |
| 0.2 | Run opennextjs-cloudflare build and one live POST /api/inspections; record whether it fails at build or at runtime | GA-1 | yes |
| 0.3 | Correct the FRD status column for FR-NCR-*; reconcile it with ARCHITECTURE §3 | GA-3 | yes |
| 0.4 | Fix the diagram paths — publish SVG at diagrams/esg/, or repoint the doc at docs/diagrams/*.png; correct docs/diagrams/README.md | GA-8 | yes |
| 0.5 | Commit docs/, diagrams/, lib/ncr/ticket.ts, screens/ncr/, tests. Decide dev-ip-bypass.ts separately — it is an auth change, not a doc change | GA-9 | yes |
| 0.6 | Rebase or merge main into feat/rn-app-parity; 15 commits of drift will not get cheaper | GA-9 | yes |
Phase 1 — Make the deployed console honest (one PR each, no coordination)
| # | Action | Closes |
|---|---|---|
| 1.1 | Delete the duplicate /app nav entry | GA-5 |
| 1.2 | Ship a /app → /demoapp redirect with the rename, or drop the rename | GA-6 |
| 1.3 | Decide 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 have | GA-1 |
| 1.4 | Give /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 tool | GA-2 |
1.3(a) is the smaller change than it looks: the three tables in
db.tsalready 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:
| # | Action | Note |
|---|---|---|
| 2.1 | Publish one ingest worker with a route. Nothing is addressable today (GA-7); this is a prerequisite the FRD assumed away | code + ops |
| 2.2 | Resolve the device credential: Access service token for the handset, or an Access-exempt ingest path with its own authentication | ops decision — BRD DP-1 / AS-5 |
| 2.3 | Reconcile apps/esg-field/lib/sync with the endpoint that actually exists (routes and body shape currently do not match workers/esg-sync) | code |
| 2.4 | Prove it: one inspection captured offline on a handset, visible in the console with no manual step | acceptance 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
| # | Action | Closes |
|---|---|---|
| 3.1 | Route NcrInbox and NcrRaise into the shell; make raise reachable standalone and from a walk finding (FR-NCR-3) | GA-4 |
| 3.2 | Tests asserting each refusal and that nothing was appended (FRD §11) | FR-NCR-8/10/12/13 |
| 3.3 | Console NCR inbox, once Phase 1.3 gives the console a store | FR-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.1 | Remove 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.2 | Incident capture against the contracted @esg/events-incident vocabulary — occurredAt and reportedAt separate, immediate actions recorded |
| 6.3 | investigation/{id} as a case: evidence, statements, timeline, root cause with stated method |
| 6.4 | Investigation 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
| ID | Decision | Blocking |
|---|---|---|
| GD-1 | How 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-2 | Is the deployed console a demo or a product? GA-1 has no correct fix until this is settled — bind D1, or stop claiming a store | 1.3, and the whole framing of §1 |
| GD-3 | Ship the IP bypass, or gate /admin properly? | 1.4, GA-2 |
| GD-4 | Which single worker becomes the published ingest, and on what hostname? | 2.1 |
| GD-5 | Does 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.
- 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). - 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.