---
path: /domains/veritas/nlp
surface: customer
domain: veritas
auth: signed-in
source: apps/oshun/web/src/app/domains/veritas/nlp/page.tsx
status: walked
last_walked: >
  2026-05-29 automated runtime walk (Playwright headless) — render, /v1 data
  (2xx), console/page-errors, expected content, screenshot verified; live
  screen-reader, touch, offline, and telemetry-delivery checks pending a manual
  AT pass. Evidence: WALKTHROUGH/results/runtime-sweep-2026-05-29.md. 2026-06-28
  Codex NLP Tools addendum — signed-in input defaults, text-mode analysis,
  URL-mode analysis, disabled results tab, Samples tab, keyboard sample loading,
  result-section expansion/collapse, propaganda/fallacy/readability/
  entity/keyword panels, reduced-motion handling, sentiment contrast,
  close/back, standalone PWA launch, offline mobile use, no-horizontal-overflow
  checks, and serious axe scan are covered by the E2E evidence below.
---

# NLP Tools · Veritas

## Purpose

The Veritas NLP Tools — a full-screen overlay that takes raw text or a URL, runs
a local simulated `NLPAnalysis`, exposes fixture sample analyses, and renders
collapsible sections for sentiment, entities, readability, language complexity,
propaganda techniques, logical fallacies, and keywords.

## Entry points

- **`/domains/veritas`** index — verify the internal-namespace tool grid links
  here
- **Linked from `/domains/veritas/articles`** — article analysis is a sibling
  workflow; no direct handoff from this route is verified here
- **Direct URL / bookmark** — yes (auth required)

## Layout regions

`page.tsx` is a `'use client'` component that renders an `sr-only` `<h1>` ("NLP
Tools · Veritas · OSHUN") then mounts
`<VeritasNLPTools onClose={() => router.back()} />`. Overlay is fixed
full-screen.

- **Header**: title "NLP Tools", 44px-minimum Close button
  (`aria-label="Close NLP Tools"`), responsive wrap behavior, and tablist for
  `input | results | samples`.
- **Nav tablist**: `role="tab"` buttons expose `aria-selected`; the `results`
  tab is disabled until a result exists.
- **Body**: focusable scrollable region labelled "NLP tools workspace"; current
  view is driven by `view: NLPView`.
  - **Input** (`input`) — text/URL mode toggle, textarea or URL field, live word
    count for text mode, Analyze action, and fixture sample cards
  - **Results** (`results`) — populated `NLPAnalysis` overview and collapsible
    analysis sections
  - **Samples** (`samples`) — dedicated fixture sample library, each keyboard
    selectable

State drivers: `view`, `inputMode`, `textInput`, `urlInput`, `analyzing`,
`result`, and `expandedSections`.

## States

- [x] **Loading** — overlay renders synchronously; no async skeleton.
- [x] **Input view, text mode** — default mode renders textarea, live word
      count, disabled Analyze action, and sample cards.
- [x] **Input view, URL mode** — URL field renders, Enter starts analysis, and
      result carries `inputUrl`.
- [x] **Analyzing** — local simulated `setTimeout` sets `analyzing=true`,
      changes the button label to "Analyzing...", then switches to results.
- [x] **Results view, populated** — custom text/URL results and sample fixture
      results render from `result`.
- [x] **Results tab disabled when no `result`** — verified via disabled tab
      state.
- [x] **Samples view** — dedicated sample library is reachable by tab and cards
      load fixture results by click/Enter/Space.
- [x] **No propaganda / no fallacy branches** — factual fixture renders empty
      "No ... detected" states.
- [x] **Propaganda / fallacy populated branches** — manipulative fixture renders
      every technique and fallacy row from `SAMPLE_NLP_ANALYSES`.
- [x] **Offline** — URL-mode analysis and Samples navigation remain usable after
      `context.setOffline(true)` because no analysis endpoint is fetched.
- [x] **Standalone PWA** — `/?surface=pwa` restores to `/domains/veritas/nlp`
      and matches standalone display-mode.
- [x] **Reduced motion** — E2E emulates reduced motion and verifies overview,
      metric-fill, and sentiment segment transitions/animations are effectively
      zero.
- [x] **Serious accessibility scan** — route passes the automatic serious axe
      gate; sentiment segment text now uses contrast-safe `readableInk`.

## Interactions

### Header

- [x] **Close NLP Tools** (button, `aria-label="Close NLP Tools"`, X icon)
  - Function: keyboard Enter calls `onClose()` → `router.back()`
- [x] **Nav tablist**:
  - `input` — returns to the input workspace
  - `results` — disabled until `result` exists; then shows current result
  - `samples` — opens the dedicated sample library

### Input view

- [x] **Input mode toggle** — switches `inputMode` between `text` and `url`.
- [x] **Text input** — textarea accepts pasted text and displays a live token
      count.
- [x] **URL input** — text input accepts a URL; pressing Enter runs analysis.
- [x] **Analyze** — disabled until the active input has content; click/Enter
      starts local analysis, sets `result`, and switches to `results`.
- [x] **Input sample card** — click/Enter/Space loads the fixture sample into
      `result` and switches to `results`.

### Samples view

- [x] **Sample card** — click/Enter/Space calls `handleLoadSample(sample)`.
- [x] **Enter custom text** — returns to the input workspace.

### Results view

- [x] **New Analysis** — returns to `input` without clearing the last result.
- [x] **Overview** — sentiment, word/sentence count, detected language,
      readability grade, text preview, and overall assessment render.
- [x] **Section header** — click toggles the section id in `expandedSections`.
- [x] **Sentiment Spectrum** — negative/neutral/positive segments and compound
      marker render; segment contrast and reduced motion are verified.
- [x] **Entity Recognition** — grouped entities render with category and
      confidence band labels.
- [x] **Readability Metrics** — Flesch, Fog, Coleman-Liau, SMOG, ARI, grade
      level, average sentence length, and syllables-per-word render.
- [x] **Language Complexity** — vocabulary, lexical diversity, passive voice,
      sentence complexity, technical terms, jargon density, nominalizations, and
      hedging metrics render.
- [x] **Propaganda Technique Detection** — empty and populated branches are
      verified against fixture data.
- [x] **Logical Fallacy Identification** — empty and populated branches are
      verified against fixture data.
- [x] **Top Keywords** — one chip per fixture keyword renders with frequency and
      TF-IDF hooks.

## Current E2E evidence

- `apps/oshun/web/e2e/veritas-nlp-tools.spec.ts` —
  `renders input defaults, runs a custom text analysis, toggles sections, and closes by keyboard`
  covers signed-in navigation from `/library`, default text input state,
  disabled results tab, sample count, live word count, Analyze disabled/enabled
  states, analyzing label, populated custom result, all default-open sections,
  factual empty propaganda/fallacy branches, entity/keyword counts, section
  collapse/reopen, New Analysis, and keyboard close/back.
- `apps/oshun/web/e2e/veritas-nlp-tools.spec.ts` —
  `loads a fixture from Samples by keyboard and verifies manipulative-language results with reduced motion`
  covers the dedicated Samples tab, keyboard sample loading, manipulative
  fixture result id, propaganda/fallacy counts and row text, reduced-motion
  overview/metric/sentiment transitions, and the serious axe contrast scan.
- `apps/oshun/web/e2e/veritas-nlp-tools.spec.ts` —
  `runs URL-mode analysis while offline in standalone mobile without horizontal overflow`
  covers standalone PWA restoration, offline URL-mode analysis via Enter,
  `inputUrl` result state, text preview for fetched-content placeholder, offline
  Samples navigation, mobile no-horizontal-overflow checks, and standalone
  display-mode.

## Data & contracts

- **Reads**: `SAMPLE_NLP_ANALYSES` from
  `@/lib/veritas/veritas-extended-simulation`.
- **Writes**: none externally; all analysis, sample loading, and section
  expansion is local component state.
- **Realtime**: none.
- **Caching**: not applicable.
- **Auth/role check**: shell middleware (verify).
- **Telemetry**: no `track*` imports in this file.
- **Page metadata**: not set (client component); sr-only `<h1>` reads "NLP Tools
  · Veritas · OSHUN".

## Cross-references

- Component: `apps/oshun/web/src/components/domains/veritas/VeritasNLPTools.tsx`
- Type: `NLPView = 'input' | 'results' | 'samples'`
- Route E2E: `apps/oshun/web/e2e/veritas-nlp-tools.spec.ts`
- Sibling tools:
  - [`domains-veritas-articles.md`](./domains-veritas-articles.md) — full
    article analyzer
  - [`domains-veritas-knowledge-graph.md`](./domains-veritas-knowledge-graph.md),
    [`domains-veritas-research.md`](./domains-veritas-research.md)
- Customer-facing Veritas hub: [`veritas.md`](./veritas.md)
- Feature spec: [`V1/features.md`](../../../V1/features.md#veritas)

## Open questions / known gaps

- [ ] Analysis pipeline is local/simulated; verify whether V1 wires to a Sophia
      or Veritas backend NLP service.
- [ ] No telemetry on mode switch, analysis submission, sample loading, or
      section expansion.
- [ ] Entry links from `/domains/veritas`, `/domains/veritas/articles`, and
      `/veritas` are not covered by this route-specific E2E; keep or add
      coverage in their route specs.
- [ ] Live screen-reader and touch-device AT passes remain pending beyond the
      automated keyboard/Playwright coverage here.
