Skip to main content
Glama
diligence-kernel
by mfbaig35r

diligence-kernel

A matter-scoped M&A diligence vault and review-table execution engine, over MCP.

It ingests a data room, classifies and tags every file, assembles review units, and then runs the review-table prompt corpus against them — filling cells with evidence attached, so the analysis persists for higher-level M&A work and drafting.

Documentation: project wiki — architecture, the corpus, ingestion, running a table, standards, findings reference, operations.

What it is

files → extract → classify (Table 05) → assemble review units
      → chunk + embed → vault
      → run a table: retrieve in-scope evidence, fill each cell in dependency order
      → persist cells + evidence + provenance
      → derived artifacts: consent schedule, coverage register, issues list

The prompt corpus in review-table-prompts/ is the schema: 24 table inventories, 591 columns, 591 prompts. The markdown is the source of truth. The database is derived and rebuildable from it.

Related MCP server: Conflict-Check MCP

What it is not

It does not draft prompts — the legal-review-table-builder skill does that. It does not make legal determinations. It does no arithmetic: 00a section 7 is enforced, not requested, so every figure is reported as stated and reconciliation happens outside.

prompt-graph remains the authoring and evaluation companion. This engine holds its own parsed copy of the corpus because it needs prompt text, dependency order, and retrieved evidence in-process; MCP servers cannot call each other.

Standards it enforces

From 00a-build-plan-and-standards.md, checked on every cell before it persists:

  • the five-state fallback vocabulary, and the banned synonyms (N/A, None, Silent, …)

  • Not stated restricted to Date, Number, Currency and Duration columns

  • Classify answers restricted to configured options

  • ISO dates with partial precision preserved

  • no markdown, no citations, and no computed figures in a cell

  • Verbatim cells must reproduce text that actually appears in the review unit

Tools

Matter — matter_open, matter_status Vault — vault_ingest, vault_search, classification_record Rows — units_propose, units_assemble Execution — run_estimate, run_table, run_status Review — table_read, cell_evidence, cell_review Corpus — table_describe, column_prompt, columns_find Artifacts — artifact_list, artifact_build

A matter, end to end

matter_open("Project Cedar", as_of_date="2026-09-01")   # loads 24 tables, 591 columns
vault_ingest("/path/to/dataroom")                        # extract, chunk, offsets, embed
units_assemble("05") ; run_table("05")                   # intake classifies and routes
units_assemble("01") ; run_table("01")                   # a workstream table
table_read("01", only_flagged=True)                      # what breached the standards
cell_evidence(unit_id, "Assignment Language")            # the sentences behind a cell
cell_review(unit_id, "...", review_status="Verified", materiality="Critical")
artifact_build("consent_schedule")                       # a filter, not a fresh question

Build order is 00a section 12: start at 05, then 06, then 01, and stop when the matter is covered. table_describe reports the pairs that must be built together.

Real documents

PDF, DOCX, XLSX, CSV, HTML and email (.eml, .msg) are read by default — a data room is not a folder of text files. Anything produced but unreadable (.xls, .doc, .pptx, archives) is reported, not skipped in silence: an unread file must not look like an absent one. Three things happen on the way in that matter more than they sound:

  • Running headers and footers are stripped. An extractor emits them in reading order, so a clause spanning a page break arrives with Confidential Page 1 of 3 inside the sentence. Lines repeating at the top or bottom of most pages are removed, with page numbers masked so Page 1 of 3 and Page 2 of 3 count as the same line.

  • Offsets survive. The full text is rebuilt from the cleaned pages, so every chunk's character span and page range is exact, and evidence can point at it.

  • Scans are read by OCR. A PDF page with no text layer is transcribed locally with tesseract, so nothing leaves the machine. Set DILIGENCE_KERNEL_OCR to tesseract (default), vision, or off. Without OCR available, the file still ingests and reports itself rather than disappearing.

Spreadsheets are read as tables, not prose

00a classifies cap tables, stock ledgers, employee censuses and loss runs as Records — they report facts as at a date, and the as-of date is what makes one usable. Flattening a sheet into prose loses two things a reader cannot recover:

  • Column headers. A chunk holding rows 27 to 52 of a census, with the header left behind in an earlier chunk, is a grid of unlabelled numbers — nothing can tell salary from bonus.

  • Sheet boundaries. A cap table followed by a census reads as one table that changes shape halfway through.

So a table is chunked by rows, and every chunk restates its sheet name and header:

# Sheet: Employee Census (continued)
Employee ID  Name         Title        Location        Hire Date   Base Salary  ...
E1032        Employee 32  Engineer II  Austin, TX      2022-06-15  125200       ...

The repetition is written into the stored text too, the way a printed schedule repeats its headings on each page, which keeps every chunk an exact slice and offsets true.

Email is correspondence, and it carries documents

Tables 17, 23 and 25 are built around correspondence, and their review unit is a matter of several communications — so one message is one document, and unit assembly groups them.

  • Headers are normalized into the text, because From, Cc, Date and Subject are what Table 05 routes on.

  • The quoted chain is separated and labelled. A reply carrying twelve earlier messages otherwise duplicates their text into every later file, which distorts retrieval and makes "the most recently dated document" meaningless. The history is kept — it is evidence — but marked as repeated.

  • Attachments are extracted and ingested in their own right, linked back to the message that carried them, because in a data room the attachment is usually the agreement. Signature images, calendar items and smime.p7s are recognised as mail furniture.

  • Privilege markings are reported. 00a: report the marking and stop, never assess whether privilege applies — "a privileged document reaching the wrong reviewer is a handling problem." Detection runs on every document, not only email.

The Verbatim check tolerates what extraction does to text — ligatures, soft hyphens, hyphenated line breaks, wrapping, smart quotes, dashes, non-breaking spaces — while still rejecting paraphrase.

OCR text is a transcription, not the document

A document read by OCR records that fact, its engine and its confidence, and the whole system stays honest about it:

  • the model is told which documents are transcriptions, and not to correct a garbled word

  • cell_evidence reports the source of every quotation it shows a reviewer

  • a Verbatim cell drawn from a transcribed unit is flagged VERBATIM_FROM_OCR, because matching a quotation against OCR output compares one reading with another and cannot show the words are the document's

tesseract is the default rather than vision for a specific reason: tesseract garbles, which is visible, while a vision model transcribes fluently, so its misreadings look like ordinary text. On a control that a partner will rely on, a legible failure beats a plausible one.

brew install tesseract poppler          # macOS
uv pip install -e ".[ocr]"

The prompt corpus and prompt-graph

review-table-prompts/ is the source of truth. prompt-graph holds the versioned history, the cross-table dependency graph and the evaluation log, and is rebuilt from the markdown:

python scripts/sync_prompt_graph.py --dry-run    # parse and report, write nothing
python scripts/sync_prompt_graph.py              # replay the corpus into prompt-graph

Re-syncing unchanged markdown reports every column unchanged and writes nothing. Edit prompts in the markdown; use prompt-graph to see what a change would break (impact_of_change), what the suite looks like as a whole (suite_check), and to hold the evaluation log.

Corpus linting lives there, not here. The kernel validates answers at execution time; it does not lint prompts.

The firm playbook

Held in its own private repository — it carries the practice's methodology, which is a different class of material from the engine that runs it. The kernel reads it by path and runs perfectly well without it; the crosswalk is analysis, not runtime.

export DILIGENCE_KERNEL_PLAYBOOK=/absolute/path/to/diligence-playbook

See the crosswalk.

Providers

OpenAI by default; Anthropic behind the same interface. Both make the identical call — a cached prefix, a short varying instruction, and a schema the answer must satisfy — so switching is one environment variable.

export DILIGENCE_KERNEL_PROVIDER=openai        # or anthropic
export DILIGENCE_KERNEL_MODEL=gpt-5            # default: gpt-5
export DILIGENCE_KERNEL_EFFORT=medium          # low | medium | high | xhigh | max
export DILIGENCE_KERNEL_CONCURRENCY=6          # model calls in flight, within a stage

Columns of the same stage are filled concurrently and the run waits at each stage boundary, so a downstream prompt always sees its upstream answers. 338 of the 591 columns are stage 1. The first call of each unit runs alone to populate the prompt cache; firing a whole stage at once would make every request miss it.

The default is gpt-5.4. Cost is modelled from the published rates: cached input at a tenth of fresh, cache writes at each model's own rate (free on gpt-5.4 and gpt-5.5, a premium on the gpt-5.6 family), and the long-context tier at roughly double above ~128k tokens.

Output dominates this workload — a cell spends ~1,145 output tokens against ~693 fresh input — so the output rate is what you are really choosing between. The spread is wide: gpt-5.6-luna runs the same work for about a twelfth of gpt-5.4.

Anything absent from the built-in price table reports its cost as unknown rather than guessing; price it yourself with:

export DILIGENCE_KERNEL_PRICE_IN=1.25          # USD per million input tokens
export DILIGENCE_KERNEL_PRICE_OUT=10.00        # USD per million output tokens

On OpenAI, run_estimate needs no credentials and no network — tiktoken counts locally.

Credentials

The server is launched by its MCP client, not from a shell, so it inherits nothing from your terminal. Put the key in a .env at the project root rather than in the MCP config:

cp .env.example .env      # then edit it

.env is gitignored, and an environment variable already set always wins over it.

Install

uv venv .venv
uv pip install --python .venv/bin/python -e ".[dev,all]"      # OpenAI
uv pip install --python .venv/bin/python -e ".[dev,anthropic]" # adds Anthropic

Smoke test

Verify the live model path on the smallest possible run. Safe by default — with no flags it checks credentials and estimates cost using the free token-counting endpoint, and spends nothing.

.venv/bin/python scripts/smoke_test.py          # free: credentials + cost estimate
.venv/bin/python scripts/smoke_test.py --run    # spends: fills 4 cells on one row

It works on a throwaway database in a temp directory, never a real matter, and refuses to fill more than 12 cells. --run prints each cell's value, the sentences it was drawn from with their offsets, and any standards violation.

For a real run, run_estimate reports what run_table would cost before you start it, with and without the cached unit prefix.

Configure

One matter is one database file.

claude mcp add diligence-kernel \
  -e DILIGENCE_KERNEL_DB=/absolute/path/to/matters/acme.db \
  -e DILIGENCE_KERNEL_CORPUS=/absolute/path/to/review-table-prompts \
  -e OPENAI_API_KEY=... \
  -- /absolute/path/to/diligence-kernel/.venv/bin/diligence-kernel

The database holds client-confidential material: document text, extracted cells, entity names. Treat the file like a matter file, and keep the -wal and -shm sidecars with it.

Available Tools

19 tools
artifact_buildB

Build a derived artifact by filtering cells that already exist.

00a: never re-derive a schedule by asking a fresh question, so that the schedule and its sources cannot disagree. Each artifact reports how many of its rows are still unreviewed or carry a standards violation.

Inputs: artifact (required), min_review_status. Returns: object

artifact_listA

List the derived artifacts and what each is built from.

Inputs: no named parameters. Returns: object

cell_evidenceA

Show a cell's value and the sentences it was drawn from, with document and offsets.

This is how a reviewer checks a cell without opening the whole document. A cell whose evidence list is empty was filled from no quoted text.

Inputs: column (required), unit_id (required). Returns: object

cell_reviewA

Record a human's judgment on a cell: verification, correction, materiality, consequence.

Materiality and deal consequence are human columns by design; the engine never fills them. A verified or locked cell is not overwritten by a later run.

Inputs: column (required), unit_id (required), lock, value, +4 more. Returns: object

classification_recordA

Store Table 05 classification for files, which is what routes them to every other table.

Use this when you have classified files yourself. Running Table 05 through run_table writes the same records. A file with no workstream is invisible to every workstream table.

Inputs: records (required). Returns: object

column_promptA

Return one column's full prompt text, with its upstream and downstream columns.

Inputs: table (required), column (required). Returns: object

columns_findA

Find columns across all 24 tables by name, purpose, or prompt text.

Inputs: query (required), limit, native_type. Returns: object

matter_openA

Open the matter in this database and load the review-table prompt corpus.

One matter is one database file. Loading the corpus is idempotent: unchanged inventories are skipped, a changed one is re-parsed. Call this before anything else.

Inputs: name (required), side, objective, as_of_date. Returns: object

matter_parameters_setA

Record the entities named in the Table Instructions, so their placeholders bind.

The corpus ships templates: [Project name], [Exact legal name] ([jurisdiction and entity type]; [role in the group]), [Buyer legal name]. Left unbound, a prompt asks the model to decide whether a document's party is a review subject against a list of square brackets — and Unable to determine becomes the correct answer to the wrong question. Call this before any run, and it reports any placeholder still unbound.

Inputs: entities (required), replace. Returns: object

matter_statusA

Report what the matter holds: documents, classification, units, and cells filled per table.

Reports documents that carry no classification, because no table can see those.

Inputs: no named parameters. Returns: object

run_estimateA

Report what run_table would cost, without running it or spending anything.

Counts the exact requests the run would send. Cells that are already filled, locked, or reviewed are excluded, because a run would skip them. Reports the cost both with and without the cached unit prefix, so the saving from that design is visible.

Call this before any run over more than a handful of rows.

Inputs: table (required), model, refill, columns, +2 more. Returns: object

run_statusA

Report a run's progress, token spend, and any error that stopped it.

Inputs: run_id. Returns: object

run_tableA

Fill a review table's cells, in dependency order, from the documents in each row.

The run is durable: every cell commits as it is filled, so calling again after a failure resumes rather than restarting. Already-filled cells are skipped unless refill is set, and a locked or human-corrected cell is never overwritten.

Each cell is checked against the 00a standards before it persists: the fallback vocabulary, Classify options, ISO dates, no markdown, no arithmetic, and for Verbatim columns that the quoted text actually appears in the row's documents. Violations are recorded on the cell and returned as findings.

This spends money. A 27-column table over 40 rows is roughly 1,080 model calls.

Inputs: table (required), model, reason, refill, +4 more. Returns: object

table_describeB

Describe a table: its review unit, grouping, Table Instructions, and every column.

Each column reports its native type, execution stage, configured options, and any pre-run verification caveat the inventory recorded against its type.

Inputs: table (required). Returns: object

table_readB

Read a filled table: one entry per row, with each cell's value, review status, and violations.

Inputs: table (required), limit, columns, only_flagged. Returns: object

units_assembleB

Write the review units for a table. Units a human assembled are never replaced.

Inputs: table (required), replace. Returns: object

units_proposeA

Show the rows a table would run over, without writing them.

Grouped tables assemble a family from a base document plus everything issued under it. Reports dependents whose base is absent or ambiguous: 00a warns that a family missing an amendment produces a confidently wrong row and nothing else detects it.

Inputs: table (required). Returns: object

vault_ingestA

Extract, chunk, and store every supported file under a directory.

Idempotent by content hash: an unchanged file is skipped. A PDF page with no text layer is a scan, and is read by OCR — locally with tesseract by default, so nothing leaves the machine. A document read that way records that its text is a transcription rather than the document's own, reports the engine and its confidence, and any Verbatim cell drawn from it is flagged: the quotation was checked against a reading of the page, not the page.

vision sends page images to the model instead. It reads harder scans, but it transcribes fluently, so a misreading looks like ordinary text — opt in deliberately.

Inputs: path (required), ocr, force, recursive. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 19 tools

    Disambiguation5/5

    Each tool has a distinct responsibility: opening a matter, describing tables, setting parameters, ingesting/searching documents, recording classifications, assembling units, running/estimating/monitoring table runs, reading/reviewing cells, and managing prompts/artifacts. There is no meaningful overlap or ambiguity between tool names and their purposes.

    Naming Consistency4/5

    Most tools follow a clear `object_verb` pattern (table_describe, vault_ingest, units_propose, cell_review), but `run_table`, `run_estimate`, and `run_status` invert to `verb_object`, and a few names like `cell_evidence` and `artifact_list` are noun-noun. The pattern is predictable overall with minor deviations.

    Tool Count4/5

    At 19 tools, the server is slightly above the typical well-scoped range, but the count is justified by the breadth of the due-diligence workflow: ingestion, classification, table execution, evidence review, and artifact building. Each tool addresses a real step with no obvious redundancy.

    Completeness5/5

    The tool set covers the full review lifecycle: ingest documents, classify them, assemble review units, run table prompts, inspect evidence, record human review decisions, and build derived artifacts. There are no obvious dead ends—every produced object can be read, checked, or acted upon by another tool.

    Maintenance

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables automated dataset processing and onboarding using Google Drive integration. Provides metadata extraction, data quality assessment, and contract generation for CSV/Excel files through natural language interactions.
      1
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables natural language conflict-of-interest checks, historical relationship analysis, and contract review using Verdantas project data and Deltek records.
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables dealmaking research for AI assistants, providing company intelligence, transaction data, and research deliverables via MCP.
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables evaluation of synthetic tender requirements against supplier evidence by loading tenders, building compliance matrices, flagging unresolved risks, and preparing draft evidence packs with preserved provenance. Finalization stays blocked behind a mandatory human approval gate, so no award decision is made autonomously.
      MIT