Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 60 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

A working prototype that scores customer-support conversations (RU / KZ / EN, chat and voice) against a **changeable, versioned checklist**, shows the evidence for every score, and lets a reviewer correct or appeal any criterion without losing the original AI result. Built for the CQA hackathon.

## Start here as a reviewer

**[Five-minute demo and proof guide →](docs/REVIEWER_GUIDE.md)** Start with a stored evaluation, follow its evidence, change the checklist, then review or appeal a result. The guide explains what each step demonstrates and how to test a genuinely new input.

The committed DEV snapshot contains **65 conversations, 65 completed evaluations, one failed attempt and five recordings**. [DEV](results/dev/results.json) and [control](results/prod/results.json) submission files contain 65 and 10 records respectively. These are model predictions, not reference labels or an accuracy measurement. No human-reference agreement report is linked in the current repository; [validation protocol and tooling](docs/VALIDATION.md) describe how to produce one.

## What it does

1. **Imports** conversations from the organizer's dataset API (server-side) and keeps transcript text, order, roles, timestamps and audio link intact, adding a stable zero-based index per message.
Expand All @@ -11,9 +17,31 @@ A working prototype that scores customer-support conversations (RU / KZ / EN, ch
5. **Reviews**: reviewers correct a criterion or decide an appeal; the final total is recalculated by code, the initial AI result and the audit history are preserved.
6. **Measures itself**: a CLI compares model output with human labels per criterion and measures run-to-run stability.

## See the product

### Review a conversation and its evidence

![CQA review workspace with a searchable conversation queue, indexed transcript and criterion scores](docs/images/review-workspace.png)

The queue, transcript and evaluation sit side by side. Expand a criterion to follow its evidence; the panel explains lost points and serious violations. **Из прошлой оценки** identifies a reused judgment.

### Change the checklist without changing code

![Checklist editor showing criterion instructions, answer type, weight and N/A condition](docs/images/checklist-editor.png)

Edit the instructions, answer scale, weight and applicability, then save a new checklist version. Previous versions and evaluations remain available.

### See where review is needed

![Statistics page with criterion distributions, language breakdown, evaluation failures and appeal counts](docs/images/quality-statistics.png)

Summarize scores, serious flags, uncertain judgments and review progress across languages. **These figures describe the evaluated conversations; they are not model accuracy against reference labels.**

Screenshots show the supplied running demo, including navigation and data beyond the committed DEV seed. Counts and available sections depend on the revision and local database.

## Run it (5 minutes)

Needs Node ≥ 22 (CI uses 24, `.nvmrc` pins it) and pnpm 10. No API key or `.env` is needed to look around; stored evaluations open without a model, a new evaluation needs `ANTHROPIC_API_KEY`.
Needs Node ≥ 22 (CI uses 24, `.nvmrc` pins it) and pnpm 10. No API key or `.env` is needed to inspect stored evaluations. Fresh semantic evaluation needs `ANTHROPIC_API_KEY`; rules and compatible reused results can complete an evaluation without a model call.

**Install prerequisites (once)**

Expand All @@ -25,9 +53,8 @@ exec $SHELL -l && nvm install 24 && nvm use 24
# Windows (PowerShell): Node 24
winget install OpenJS.NodeJS # then open a new terminal

# pnpm: Corepack ships with Node 24 and picks the exact version pinned in package.json
corepack enable
# without Corepack: npm install -g pnpm@10
# pnpm: install the version pinned in package.json
npm install -g pnpm@10.33.2

git clone https://github.com/unsound-mint/cqa-hackathon.git && cd cqa-hackathon
pnpm install # also fetches the prebuilt better-sqlite3 binary
Expand All @@ -44,19 +71,36 @@ pnpm dev # web http://localhost:5173 with fictional mock data, API on
Full local build, one process on one URL (what the demo uses):

```bash
pnpm seed # installs the committed DEV snapshot: 65 conversations, 66 evaluations, 5 recordings
pnpm seed # installs the DEV snapshot; keeps an existing database unchanged
cp .env.example .env # optional: ANTHROPIC_API_KEY to evaluate new conversations
pnpm start # builds, then serves web + API at http://127.0.0.1:8787
```

Checks: `pnpm typecheck && pnpm test && pnpm build` (no test needs a network or a model). Details, backup advice and troubleshooting: [`docs/RUNBOOK.md`](docs/RUNBOOK.md).

## Reading guide for reviewers
## Model and API cost

The default is **Claude Haiku 5.5** (`claude-haiku-5-5`) through Anthropic's API, with `medium` effort. All 65 completed evaluations in the committed DEV seed record this model; `CQA_MODEL` and `CQA_EFFORT` can override it for new runs.

Standard API prices in **USD per million tokens**, checked **8 November 2026** against [Anthropic's official model pricing](https://platform.claude.com/docs/en/models/haiku-5-5/overview):

| Token category | Prompt up to 100,000 tokens | Prompt over 100,000 tokens |
|---|---:|---:|
| Uncached input | $0.10 | $0.50 |
| Output | $0.50 | $2.50 |
| Cache write (5 minutes) | $0.125 | $0.625 |
| Cache read | $0.01 | $0.05 |

For example, **10,000 uncached input + 2,000 output tokens cost $0.002** at the lower tier (one fifth of a US cent). This illustrates the rate, not a measured cost per conversation. A conversation can require multiple requests and a repair attempt; token counts, caching and retries determine the bill. Rules and compatible reused results avoid model calls. Viewing stored results incurs no model cost.

Each evaluation records token usage and model provenance. The [comparison CLI](evaluation/README.md#3-compare-with-the-model) can estimate cost using supplied input/output rates; treat it as an estimate, not a provider invoice.

## Technical reading guide

| If you want to check… | Look at |
|---|---|
| The big picture, data flow, decisions | [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) |
| That scores are not hardcoded and new input is really analyzed | `apps/api/src/services/evaluation/evaluator.ts` (`planCriteria`, `evaluateConversation`); no code references a conversation id |
| That scores are not hardcoded and new input is really analyzed | [Reviewer proof steps](docs/REVIEWER_GUIDE.md#test-a-new-input); `apps/api/src/services/evaluation/evaluator.ts` (`planCriteria`, `evaluateConversation`) |
| That the model cannot invent evidence or totals | `validateModelOutput` in `evaluator.ts`; `packages/contracts/src/evidence.ts`; `scoring.ts` |
| Arbitrary checklist support | `packages/contracts/src/checklist.ts` (schema, criterion signature), `apps/web/src/features/ChecklistEditor.tsx`, `scoring.ts` (id-agnostic) |
| Original-vs-final, appeals, audit | `apps/api/src/services/appeals.ts`, table `appeals`/`evaluations` in `db/schema.ts` |
Expand All @@ -65,15 +109,7 @@ Checks: `pnpm typecheck && pnpm test && pnpm build` (no test needs a network or
| UI rules | [`docs/DESIGN.md`](docs/DESIGN.md) (a test enforces the 4/8 px grid) |
| Shared types and API | `packages/contracts/src`, [`docs/INTERFACES.md`](docs/INTERFACES.md) |

### Try the main flow

The interface is in Russian; labels below are given as `Russian (English)`.

1. Open **Диалоги (Dialogs)**, pick a conversation. If it has no stored evaluation, press **Оценить диалог (Evaluate dialog)** (needs a model key; the mock data already has results).
2. Click a criterion → the transcript jumps to the exact evidence message; for a call, click the waveform to seek.
3. Open **Чек-лист (Checklist)**, change a criterion's instructions or add one, save, then evaluate again → a new checklist version appears in the version bar; the old evaluation stays.
4. Override a criterion with a reason, or file and decide an appeal in **Апелляции (Appeals)**: the final total changes while the original total and the AI explanation remain visible.
5. Download CSV or print/save PDF from the evaluation panel footer.
The [reviewer guide](docs/REVIEWER_GUIDE.md) provides the UI walkthrough, role changes, expected outcomes and limitations. [RUNBOOK](docs/RUNBOOK.md) covers setup, recovery, submission and Dynamics embedding.

## Architecture in one picture

Expand All @@ -91,7 +127,7 @@ Design principles (each is enforced by code or a test, not only by convention):

- **Deterministic first.** Facts (hold windows, recording pauses, verification events, timings), applicability, tiers, N/A, weighting, rounding and totals are code. The model supplies only semantic judgments and cannot compute a total.
- **Evidence or it did not happen.** A positive verdict needs a verbatim quote from a client-facing operator message; indices and quotes are verified against the stored transcript.
- **Nothing is overwritten.** Conversations, checklist versions, AI results and appeals are immutable/append-only; reviewer actions only change the *final* result.
- **Original and reviewed scores stay separate.** Source conversations and used checklist versions remain stable; original AI results are preserved. Decisions are recorded in appeal/correction history and update the final result.
- **Transcripts are untrusted data**, passed to the model as an inert payload; secrets stay on the server.

## Repository map
Expand All @@ -101,8 +137,11 @@ apps/api/ Fastify API, SQLite (Drizzle), import, evaluation pipeline, a
apps/web/ React + Vite review app (works offline against MockCqaApi)
packages/contracts Zod schemas, shared types, scoring, evidence validation
evaluation/ Human-label sheets, model-vs-human comparison, stability CLI
fixtures/ Fictional demo conversation (only conversation data in git)
data/ git-ignored contents: SQLite, raw dataset, recordings
fixtures/ Fictional demo conversation for mock mode and tests
data/seed/ Published organizer DEV database and five recordings
data/raw/ Ignored raw imports; runtime SQLite is also ignored
data/private/ Ignored runtime recordings
results/ Committed DEV/control predictions in organizer JSON format
docs/ Architecture, rubric, interfaces, design, validation, runbook, workflow
handoffs/ Per-owner onboarding notes from the hackathon kickoff
AGENTS.md Rules the team's coding agents follow (CLAUDE.md imports it)
Expand All @@ -114,8 +153,8 @@ Denis: API, contracts, scoring, providers, integration. Sofia: web app. Eldana:

## Data handling

No signed organizer URL, API key, raw transcript, real audio URL, recording or private label file is committed (`.gitignore` covers `data/`, `.env*`, `evaluation/private/`, `*.sqlite`). Git holds only fabricated fixtures. Real conversations are sent to a hosted model only with confirmed permission.
The organizer-cleared publication exception is `data/seed/`: the DEV database (including transcripts and audio references) and recordings. Submission predictions are in `results/`. Signed import credentials, model keys, other raw imports, control transcripts, runtime recordings and private labels stay in ignored local storage (`.env*`, `data/raw/`, `data/private/`, `*.sqlite`, `evaluation/private/`). Real conversations are sent to a hosted model only with confirmed permission.

## Known limits

Agreement figures in our reports are against team-written human labels, not the organizer's hidden reference. Rounding of halfway cases and the semantic relevance of a quoted operator message are judgment calls documented in [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md#13-known-limits). There is no authentication.
The comparison CLI can measure agreement with independently human-authored labels; its existence alone does not demonstrate accuracy against the organizer's hidden reference. Rounding of halfway cases and the semantic relevance of a quoted operator message are judgment calls documented in [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md#13-known-limits). There is no authentication.
10 changes: 6 additions & 4 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ flowchart LR
| `apps/api` | Fastify routes, SQLite/Drizzle storage, import, evaluation pipeline, jobs, appeals, audio. | contracts |
| `apps/web` | Review workspace, checklist editor, appeals queue, print/export. Talks only to the `CqaApi` interface. | contracts |
| `evaluation` | Human-label sheets, comparison and run-to-run stability reports. A CLI that reads the running API. **Never imported by production code.** | contracts |
| `fixtures/demo.json` | Fictional conversation for the mock client and tests. The only conversation data in git. | – |
| `data/` (contents git-ignored) | SQLite file, raw dataset download, call recordings. Real data lives only here. | – |
| `fixtures/demo.json` | Fictional conversation for mock mode and tests; published DEV data is separate in `data/seed/`. | – |
| `data/seed/` | Published organizer DEV snapshot: database and five recordings. `pnpm seed` copies it into runtime storage. | – |
| Runtime data (git-ignored) | `data/cqa.sqlite`, `data/raw/`, `data/private/`: working database, raw imports and recordings. | – |
| `results/` | DEV/control model predictions in organizer JSON format; not reference labels. | – |
| `docs/` | This documentation. `docs/official/` (organizer PDFs, local only, git-ignored) is not in the repository. | – |

Rule of thumb: contracts ← api, web, evaluation. api and web never import each other.
Expand Down Expand Up @@ -207,7 +209,7 @@ Bumping either invalidates cached results; legacy rows without a cache context a

- Transcripts are untrusted data: sent to the model as a JSON payload field, never concatenated into instructions; model output is validated, never executed.
- Secrets (`DATASET_IMPORT_URL`, `ANTHROPIC_API_KEY`) are unprefixed server env vars; `VITE_*` is public and holds no secret. The importer never logs or returns the URL.
- Raw transcripts, real audio URLs, recordings and the SQLite file are git-ignored (`data/`, `evaluation/private/`). Git contains only fabricated fixtures.
- `data/seed/` is the organizer-cleared publication exception: the DEV database and recordings are committed. Runtime SQLite, other raw imports, recordings and private labels remain ignored (`*.sqlite`, `data/raw/`, `data/private/`, `evaluation/private/`). `results/` contains submitted predictions, not control transcripts or reference labels.
- Real calls are not sent to a hosted model without confirmed permission. Only an Anthropic adapter exists; another provider means one new class implementing `LlmProvider`.
- No hardcoded outputs: nothing keys on conversation id, language or DEV content. Calibration examples are fictional and chosen by criterion signature.

Expand All @@ -229,7 +231,7 @@ Bumping either invalidates cached results; legacy rows without a cache context a

## 13. Known limits

- Reference agreement reported by the tooling is agreement with human labels written by the team (see `docs/VALIDATION.md`), not with the organizer's hidden ground truth.
- The tooling can report agreement with human labels (see [validation protocol](VALIDATION.md)); no human-reference report is linked in the current repository. Stored predictions and format validation do not measure accuracy against the organizer's hidden ground truth.
- Semantic relevance of an operator quote still depends on model judgment; the validators prove the quote is real and operator-authored, not that it is the right quote.
- Voice transcripts are speech-recognition output; absence claims inside recording pauses are capped at medium confidence and flagged for human review.
- Rounding of halfway cases is provisional (§5.3). No authentication: the role is a demo switch that any client can spoof.
Expand Down
Loading
Loading