This repository is Clausewise, a governance-gated policy intelligence system. Treat approved policy documents as the canonical source of truth and preserve the separation between UI, retrieval, governance, and generation.
The production app is the Vite/TanStack frontend plus Python API path:
frontend/ React 19, TanStack Router, TanStack Query, Vite
frontend/src/lib/ Browser-only types, product config, API client
frontend/src/components/ui/
shadcn-style local UI components
api/ Python API, policy pipeline, Gemini index builder
data/ Markdown policy corpus and generated JSON search index
docs/ Architecture and deployment documentation
evaluation/ Offline pipeline checks
Do not reintroduce deleted prototype app surfaces or inactive AI backends unless the task explicitly asks for an architecture migration.
- Clausewise answers only from approved policy evidence.
- Owner scoping must happen before retrieval results are used.
- Latest-version policy documents should dominate older versions.
- Governance decisions must remain explicit:
SAFE,REFUSE_POLICY,REFUSE_INVALID, orESCALATE. - Generated answers should include sources, supporting clauses, confidence, and grounding status.
- Do not silently remove refusals, escalations, source validation, or grounding checks to make demos look smoother.
The live query flow is:
Browser
-> Vite React UI
-> TanStack Query mutation
-> Python POST /api/query
-> Python Groq intent detection
-> deterministic owner routing
-> Python Gemini query embedding
-> cosine retrieval over data/search-index.json
-> owner/latest-version constraints
-> Python Groq governance classification
-> Python Groq answer or refusal generation
-> lexical grounding check
-> JSON response
Key files:
frontend/src/screens/home.tsxowns the main UI.frontend/src/sections/query-console.tsxowns the live query console.frontend/src/lib/api.tscalls the Python API.api/index.pyexposes the FastAPI app to Vercel Python Functions.api/main.pyvalidates request input and returns pipeline output.api/pipeline.pyowns intent detection, routing, constraints, governance, generation, and grounding orchestration.api/build_search_index.pygenerates the static embedding index.
Required:
GROQ_API_KEY
GEMINI_API_KEYOptional:
GROQ_MODEL=llama-3.3-70b-versatile
GEMINI_EMBEDDING_MODEL=gemini-embedding-001Never commit real API keys. Keep .env, .env.local, and secret files untracked.
Use the repo's Node package manager setup. In this Codex environment, system npm may be unavailable; use the bundled Node/Pnpm path if needed.
pnpm install
pip install -r requirements.txt
pnpm run build:index
pnpm run dev:api
pnpm run dev
pnpm run build
pnpm run build:vercelnpm run build:index, pnpm run build:index, and pnpm run build:vercel use GEMINI_API_KEY when it is configured. Without the key, index generation is skipped and the API uses lexical fallback retrieval.
Deploy as one Vercel project. The frontend is emitted to dist/, and /api/* rewrites to api/index.py, which imports api.main:app. Keep VITE_API_BASE_URL unset for this same-origin deployment.
- Keep the first screen product-like and polished, but preserve access to the live query console.
- Prefer dense, credible operational UI over decorative marketing sections.
- Keep cards at
16pxradius or below unless there is a strong visual reason. - Keep text readable on mobile; avoid fixed-width content that can overflow.
- Use
frontend/src/lib/product.tsfor product name, tagline, domains, and sample prompts. - Do not hardcode
Clausewiseor the brand mark in components if it can come from config.
- Keep browser API contracts typed with
frontend/src/lib/types.ts. - Keep browser-only code out of server-only modules.
- Keep secret usage in Python only.
- Keep generated retrieval indexes separate from raw policy documents.
- Prefer simple deterministic code over clever abstractions for policy gates.
- If changing document metadata semantics, update
api/build_search_index.py,api/pipeline.py, and the docs together. - If changing output shape, update Python responses,
PipelineResult,ResultPanel, README examples, and any tests together.
- Make small, meaningful commits when possible.
- Keep unrelated macOS metadata such as
.DS_Storeout of commits. - Do not rewrite public history unless the user explicitly asks for it.
- If the user requests dated commits, set both author and committer dates consistently.
Before handing off code changes:
pnpm run buildWhen retrieval docs change:
pnpm run build:indexThe index build creates semantic embeddings only when GEMINI_API_KEY is configured.