Documentation

HalfTime docs

HalfTime reads a jail's court papers, finds every undertrial who has already served the Section 479 share of their sentence, shows its working, and drafts the application a legal-aid lawyer signs. These pages explain how it does that, and how to check it.

What HalfTime is

Section 479 of the Bharatiya Nagarik Suraksha Sanhita (BNSS) says that an undertrial who has been in custody for half the maximum sentence for the offence (one-third for a first-time offender) is to be released on bail, and that the jail superintendent must apply to the court (479(3)). The arithmetic is simple. The facts it needs are written in court papers, often in Hindi, often scanned, one file per person.

HalfTime splits the job along one line: the model reads, code decides. Claude reports what the papers say, and every fact must carry the exact sentence it came from. Code checks each quote against the papers, drops anything it cannot find, and a tested rules engine applies the law to what is left. The output is a lane, a rule trace and a draft. It never says “eligible”, and a lawyer signs everything.

Quick start by role

Legal-aid lawyer

  1. Open /sweep. The twelve constructed sample orders are sorted into lanes; or add your own papers (text PDFs are read in your browser; reading needs your own Anthropic key, see Security).
  2. Open a case, for example /case/S01. Every fact is marked in the order. Facts the verifier rejected are listed separately. You can edit facts, such as days of delay caused by the accused, and the verdict is recomputed.
  3. For anyone past the line, download the 479(3) application in English or Hindi (DOCX, or print to PDF). It is marked as a draft for your review. Flagged cases need your judgement on 479(2) first.
  4. The Know your line notice on each case page is a one-page explanation for the undertrial or the family, in Hindi or English.

Jail superintendent or DLSA secretary

  1. On /sweep, sweep the papers and download the jail pack: one ZIP with the docket in priority order (CSV and a printable report), every 479(3) draft in English and Hindi, a records-request letter for every “can't tell” case, and a notice for every person.
  2. Use the “what if today is…” slider to see who crosses the line before the next review meeting.
  3. The docket agent does the same sweep as a tool-using agent and asks for missing records itself. See The docket agent.

Developer

Run it locally
git clone https://github.com/Prashant-thakur77/HalfTime
cd HalfTime
pnpm install
pnpm test                      # law engine, reader, agent, MCP server, web routes
pnpm --filter web dev          # http://localhost:3000

Then read How it works, the HTTP API and Self-hosting. The law engine (packages/law) is pure TypeScript with no I/O and can be used on its own.

Claude user

Add a custom connector in claude.ai or Claude Desktop with the URL https://halftime.prashantthakur.dev/mcp, or in Claude Code:

Claude Code
claude mcp add --transport http halftime https://halftime.prashantthakur.dev/mcp

Then ask, for example, “Use halftime to sweep the 12 sample orders and show me the lanes.” No API key is involved: the Claude you are talking to reads the papers, and HalfTime's tools check the quotes and apply the law. Details in MCP server.

Five-minute review

For anyone assessing the project. Each step names what to open and what to look for.

OpenLook for
/sweepTwelve orders in lanes. The flagged lane: past the line, but more than one offence or other cases, so a lawyer decides. Nothing says “eligible”.
/case/S01The Hindi order with each quote marked, the rule trace with statute sources, and the two flags. Change a fact and watch the verdict move.
/playgroundPaste a quote that is not in the order, or change one digit of a date: the verifier rejects it.
/agentThe recorded agent run: a quote rejected with the verifier's reason, then fixed on retry; records requested; drafts only for past-the-line cases.
/resultsThe constructed-data notice, every number, and every miss listed in full.
/statusThe health self-test, the MCP endpoint and every main page, checked from your browser.

Then, from a clone of the repository (no key, no network for the second command):

Terminal
pnpm install && pnpm test     # every unit test
pnpm eval:offline              # replays the recorded model responses; must equal eval/report.json

And against the live site:

curl
curl -s https://halftime.prashantthakur.dev/api/health
curl -s https://halftime.prashantthakur.dev/mcp -H 'content-type: application/json' \
  -H 'accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

What to check

  • Every fact on a case page has a quote that can be found in the order.
  • A missing or rejected fact leads to “can't tell”, never to “past the line”.
  • Multi-offence cases are flagged, not decided.
  • pnpm eval:offline exits cleanly, so the published numbers come from the committed code and recordings.

The site, page by page

PageWhat it does
/The problem, the register of undertrials, the Ledger of Days, the twelve sample files and how it works.
/sweepSweep the sample jail or your own papers into lanes; CSV, the jail pack (.zip) and a “what if today is…” slider.
/agentThe docket agent: the recorded run replayed step by step, the priority docket, and a run on your own papers.
/case/S01One person: the order with every quote marked, editable facts, the rule trace, the 479(3) draft and the Know your line notice.
/playgroundTry the span verifier on any quote and the law engine on any facts, in the browser.
/vs-chatbotThe same model asked plainly, beside HalfTime, on every sample.
/resultsThe evaluation, every miss, and the real-judgment benchmark.
/lawSection 479 in plain words, with the tables and their sources.
/storyWhy it exists: the numbers, the law over time, who it is for.
/connectAdd HalfTime to claude.ai, Claude Desktop or Claude Code.
/statusLive checks of the health self-test, the MCP endpoint and every main page.

The repository

PathWhat it holds
packages/lawThe Section 479 engine, the IPC, BNS and special-act tables, and the IPC→BNS map. No I/O.
packages/readerDate normaliser (Hindi and English), span verifier, extraction schema and prompts, the Claude client, the regex baseline, 479(3) drafts, the Know your line notice, the docket agent.
packages/mcpThe MCP server: stdio for Claude Desktop and Claude Code; the same tools over Streamable HTTP at /mcp.
apps/webThe Next.js 15 site and API, deployed on Cloudflare Workers through OpenNext.
eval/The constructed test set and its generator, the evaluation runner, the report, recorded responses for offline replay, and the InLegalNER benchmark.
data/samples, data/demo-jailThe twelve constructed sample orders; five of them as .txt files for the MCP folder sweep.
scripts/Builders for facts.json, the sample pre-runs and the agent run, and checks.

All docs pages

  • How it works

    The pipeline from court papers to drafts, the trust boundaries, and the five verdicts.

  • How Section 479 is computed

    Fractions, rounding, first-time status, accused delay, pre-July-2024 cases, the 479(2) flag, exclusions and the statute tables, with a worked example.

  • The docket agent

    The tool-using agent that sweeps a jail's files: its tools, its loop, the guard rails code enforces, and the recorded run.

  • HTTP API

    Every route: request and response shapes, limits, status codes, errors and curl examples.

  • MCP server

    Connecting from claude.ai, Claude Desktop and Claude Code, and every tool with its inputs and an example output.

  • Evaluation

    Datasets, metric definitions, results, misses, how to reproduce them, and their limits.

  • Security and privacy

    Bring-your-own-key data flow, headers, limits, prompt-injection defence, what is stored, and reporting.

  • Self-hosting

    Deploying on Cloudflare Workers, the KV binding, secrets, local development, tests and CI.

  • FAQ and glossary

    Common questions, the terms the site uses, and what HalfTime cannot do.