Skip to main content

Codebase Map


dp_agent/ package

#FileRoleKey exports
1config.pyFoundation — loads .env, exposes all constants and path objectsCHAT_MODEL, CHEAP_CHAT_MODEL, EMBED_MODEL, POSTGRES_DSN, PROMPTS_DIR, SSL_VERIFY
2adapters/llm.pySingle gateway for all LLM calls — chat + embeddings, cost trackingcall_chat(), call_embed(), get_total_cost()
3adapters/shortcut.pyShortcut REST — fetch and normalise story data, post commentsfetch_story(), post_comment()
4adapters/db.pyPostgreSQL CRUD for patch_sessions — atomic status transitionsget_session(), create_session(), update_status(), append_clarify_result(), append_extraction_round(), update_draft()
5adapters/pgvector_client.pyVector search on patch_corpus (V2)search(), upsert_entry(), init_collection(), count_entries()
5badapters/qdrant_client.pySame interface as above for Qdrant (V1 only — to be deleted after migration)search(), upsert_entry(), init_collection(), count_entries()
6prompt_builder.pyAll LLM message builders + Pydantic output schemas + helper utilitiesbuild_clarify_messages(), build_draft_messages(), build_preprocess_messages(), build_validate_messages(), build_auto_answer_messages(), detect_schema_tables(), format_clarifications_markdown()
7server.pyV2 FastAPI app — webhook routing, state machine orchestration/webhook, /submitextraction, /health
8cli.pyV1 unified CLI entry point (python -m dp_agent <phase>)main()
8bpipeline.pyThin bridge — calls each scripts/test_*.py main()clarify(), auto_answer(), validate(), draft()

dp_agent/prompts/

#FilePhaseModelActive?
clarify.mdClarify — infer template, generate questions, write 01_extract.sqlSonnet
draft.mdDraft — write 02_patch.sql, 03_revert.sql, rationaleSonnet
preprocess.mdPreprocess (V2) — synthesise PM comments + extraction → SessionContextHaiku✅ V2 only
auto_answer.mdAuto-answer (V1) — fill answers directly from extraction dataHaiku✅ V1 only
validate.mdValidate (V1) — assess answer sufficiency, stamp RESOLVED or annotate gapsHaiku✅ V1 only
classify.mdClassify — pick template A–F from rubricSonnet❌ dead code

Each .md file is the system prompt only. prompt_builder.py loads it, wraps it with reference docs (templates.md, rules.md, glossary.md), and formats the story/hits/extraction data as the user message. The .md file never runs standalone — it always goes through its matching build_*_messages() function.


scripts/

#FileRole
9test_clarify.pyV1 clarify — fetch → embed → search → LLM → write output files
10test_auto_answer.pyV1 auto-answer — reads extraction results, fills answers via Haiku
11test_validate.pyV1 validate — Haiku checks sufficiency, stamps RESOLVED or annotates
12test_draft.pyV1 draft — gate check → Sonnet → writes patch + revert SQL
13build_index.pyIndexes examples/raw/*.sql into Qdrant corpus
14sync_schema.pyParses ElementsModel.edmxdata/schema.json
15eval.ps1Runs clarify on 6 held-out stories (one per template A–F)
16update.ps1Full corpus refresh: start Qdrant → sync → INDEX.md → re-index → schema
17build_index.ps1Generates examples/INDEX.md with template labels
18sync_examples.ps1Mirrors .sql files from elements repo into examples/raw/

docs/ — reference documents injected into prompts

FileRoleInjected into
templates.mdDefines the 6 patch templates (A–F) with inputs, target tables, SQL skeletons, and exemplarsclarify, draft, validate
rules.mdHard SQL rules and prohibitions the LLM must followclarify, draft
glossary.mdSystem scope, table acronyms (IVP, IM, ICD, ...), domain vocabularyclarify, draft
review-checklist.mdManual QA checklist — POC/Copilot Chat workflow only, not used by the agent
progression.mdNotes on how the project evolved — context for future developers
codebase-map.mdThis file

alembic/ — database migrations

FileRole
alembic.iniAlembic config — points at env.py, sets migration script location
env.pyMigration environment — reads POSTGRES_DSN from config, connects to DB
versions/0001_init.pyCreates patch_sessions + patch_corpus tables and ivfflat index

Run with: alembic upgrade head


examples/ — SQL corpus

PathRole
raw/All historical SQL patch scripts, synced from elements repo (gitignored locally). Organised by year/month.
stories/Markdown story files for historical tickets — used for manual reference
INDEX.mdAuto-generated table of all corpus files with template labels and table names (built by scripts/build_index.ps1)

copilot/ — POC-era manual workflow (not part of V1/V2 pipeline)

PathRole
copilot-instructions.mdVS Code Copilot system prompt used during the original POC
prompts/Original POC prompts (intake, classify, clarify, draft) — predates dp_agent/prompts/
inputs/SC-XXXXX/Normalised story inputs for the manual POC workflow
outputs/SC-XXXXX/Draft outputs from the manual POC workflow

Infrastructure

FileRole
DockerfileBuilds the app image (python:3.14-slim). CMD runs uvicorn only — migrations are NOT run automatically by the image.
docker-compose.ymlLocal dev: spins up pgvector/pg16 + app. Overrides the image CMD to run alembic upgrade head && uvicorn ... so migrations run on docker compose up.
requirements.txtAll Python dependencies. Contains both V2 deps (fastapi, psycopg, pgvector) and V1 deps (qdrant-client, grpcio) — Qdrant entries can be removed after V1 migration.
alembic.ini(also listed under alembic/ above)