Cons.trukt is a construction decision-support project with two connected surfaces:
- the live trench pre-plan, a zero-key browser tool for OSHA soil-condition downgrades, protective-system planning geometry, entry hold points, official citations, and printable field records
- a typed Python document-intelligence pipeline for PDF extraction, OCR fallback, hazard analysis, regulatory retrieval, structured task generation, and optional PostgreSQL persistence
The repository has been hardened from a flat-script prototype into a modular Python package. Legacy script names are still present as compatibility wrappers, but production logic now lives under src/cons_trukt/ with typed configuration, batch ingestion, structured logging, and testable adapters.
| What to check | Why it matters |
|---|---|
| Live trench pre-plan | Runs immediately in the browser and produces a printable, clause-cited field worksheet. |
src/cons_trukt/pipeline/runner.py |
Shows orchestration instead of one-off script execution. |
src/cons_trukt/processing/ and src/cons_trukt/vision/ |
Separates OCR and topographical risk logic. |
src/cons_trukt/intent.py and safety.py |
Rejects non-hazard commands before severity classification. |
src/cons_trukt/retrieval/ |
Chroma retrieval plus a fitted, serializable offline TF-IDF index. |
tests/ |
Lets reviewers validate behavior without local Chroma, Ollama, OCR, or Postgres services. |
benchmarks/hazard_v2/ |
Authoritative edge cases, selective prediction, and OOD rejection. |
benchmarks/retrieval_v2/ |
Official OSHA/FEMA/EPA/ADA sources plus abstention tests. |
Construction teams often make decisions from disconnected PDFs, scans, spreadsheets, permit records, and project-management updates. Cons.trukt explores how to turn that fragmented input into a decision-support workflow that is easier to inspect, test, and review.
For direct field use, the public app intentionally narrows that broad problem to one high-consequence task: planning cave-in protection before a trench is entered. It applies the federal OSHA Subpart P tables conservatively, requires competent-person confirmation, treats freely seeping water as Type C, keeps the under-5-ft exception conditional, and places excavations deeper than 20 ft on an RPE-design hold. The calculator is not a soil classifier or shoring design.
The production pipeline is centered around src/cons_trukt/pipeline/runner.py and the CLI:
-
PDFTextExtractorReads text from a PDF withpdfplumber; if the PDF has no text layer, it usespdf2imageandpytesseractfor OCR. -
HazardAnalyzerDetects site conditions such as steep slopes, contour/topographical signals, water buffers, wetlands, and drainage hazards. -
Precedent retrieval
ChromaPrecedentStoresupports the production memory path. The dependency-freeTfidfPrecedentStoreprovides a fitted, serializable offline path for tests, demos, and benchmark evaluation. -
OllamaTaskBackendPrompts an Ollama-served local model (llama3.2) for a strict JSON task list. Gemini remains an optional backend when explicitly configured. -
PostgresTaskRepositoryand result export Persists generated tasks whenCONS_TRUKT_DB_URLis configured and always exports timestamped JSON results.
flowchart LR
A[Blueprint PDF] --> B[PDF text extractor]
B --> C[OCR fallback]
B --> D[Hazard analyzer]
C --> D
D --> E[Chroma precedent retrieval]
E --> F[Model backend]
D --> F
F --> G[Validated task schema]
G --> H[PostgreSQL repository]
G --> I[Timestamped JSON results]
.
|-- README.md
|-- pyproject.toml
|-- config/
| `-- default.yaml
|-- src/
| `-- cons_trukt/
| |-- cli.py
| |-- config.py
| |-- audit.py
| |-- processing/
| |-- vision/
| |-- retrieval/
| |-- models/
| |-- pipeline/
| |-- storage/
| `-- utils/
|-- tests/
|-- main.py
|-- train_all_data.py
|-- query_os.py
|-- validate_accuracy.py
|-- training_data/
`-- c_os_memory/
The repository ships with a pyproject.toml that separates production dependencies from optional Gemini and development tooling.
pip install -e .
pip install -e ".[dev]"
pip install -e ".[gemini]" # optionalExternal runtime tools and services:
- Ollama
- Tesseract OCR
- Poppler
- PostgreSQL, only if persistence/audits are required
- Git LFS for large datasets and binary artifacts
Pull the local model:
ollama pull llama3.2If cloning fresh, pull large assets:
git lfs install
git lfs pullRuntime behavior is controlled by config/default.yaml plus environment overrides:
CONS_TRUKT_DB_URLfor PostgreSQL persistence and auditsCONS_TRUKT_CHROMA_PATHfor Chroma memory locationCONS_TRUKT_OLLAMA_MODELfor local model selectionCONS_TRUKT_BACKENDfor backend selection (ollamaorgemini)CONS_TRUKT_POPPLER_PATHandCONS_TRUKT_TESSERACT_CMDfor local OCR toolsGOOGLE_API_KEYonly when the optional Gemini backend is explicitly selected
Generate synthetic seed data:
python -m cons_trukt generate-seed-data --config config/default.yaml --output-dir training_data/generatedBuild or refresh Chroma memory:
python -m cons_trukt ingest --config config/default.yaml --data-dir training_dataQuery historical memory:
python -m cons_trukt query --config config/default.yaml "common reasons for plan review rejection on steep slopes"Run the blueprint pipeline:
python -m cons_trukt run --config config/default.yaml --input plan.pdfValidate recent task output:
python -m cons_trukt audit --config config/default.yamlTrain and evaluate the offline hazard baseline:
python scripts/build_v2_benchmarks.py
python -m cons_trukt train-hazard-model \
--dataset benchmarks/hazard_v2/train.jsonl \
--output artifacts/hazard_nb_v2.json
python -m cons_trukt validate-hazards
python -m cons_trukt assess-hazard \
"An eight-foot trench in unstable soil lacks a protective system."Fit, evaluate, and query the offline precedent index:
python -m cons_trukt fit-precedent-index \
--corpus benchmarks/retrieval_v2/corpus.jsonl \
--output artifacts/precedent_tfidf_v2.json
python -m cons_trukt evaluate-retrieval \
--queries benchmarks/retrieval_v2/queries.jsonl \
--model artifacts/precedent_tfidf_v2.json \
--output results/retrieval_v2/evaluation.json
python -m cons_trukt query-offline \
"ladder egress in a trench four feet deep" \
--model artifacts/precedent_tfidf_v2.jsonRun tests:
make verifyEquivalent commands are python -m ruff check src scripts tests,
python -m mypy src, and python -m pytest -q. Run make evaluate to
regenerate the v2 retrieval and hard-OOD hazard reports.
Version 2 combines the original slope/water cases with OSHA excavation
protection and egress, FEMA floodplain elevation review, EPA construction
stormwater controls, ADA ramp screening, threshold distractors, and 12
unrelated requests. The production-facing predictor can accept or escalate;
it does not force every input into Low, Medium, or High.
| Metric | Score |
|---|---|
| Accuracy on accepted cases | 1.000 |
| In-domain coverage | 0.889 |
| High-risk detection | 1.000 |
| Unsafe High-to-Low rate | 0.000 |
| Out-of-domain rejection | 1.000 |
Four of 36 in-domain cases were escalated because confidence did not clear the
acceptance threshold. That is intentional: selective accuracy is safer than
claiming universal coverage. See docs/evaluation/hazard_v2.md.
The v2 index contains nine frozen source summaries derived from official OSHA, FEMA, EPA, and U.S. Department of Justice pages. Its 15-query suite includes paraphrases, neighboring-rule distractors, and four unrelated questions.
| Metric | Score |
|---|---|
| Recall@1 | 1.000 |
| Recall@3 | 1.000 |
| Accuracy when accepted | 1.000 |
| Out-of-domain rejection | 1.000 |
| False acceptance | 0.000 |
These are regression results on a compact curated corpus, not proof that the system covers every jurisdiction or current code edition.
The repository includes a compact synthetic benchmark for three-way site-risk
classification (Low, Medium, High). The split contains 36 training
examples and 18 frozen held-out examples covering numeric slope thresholds,
instability language, water-only constraints, negation, and out-of-scope notes.
| System | Held-out accuracy | Macro F1 | Errors |
|---|---|---|---|
| Deterministic rules | 1.000 | 1.000 | 0 / 18 |
| Trained Naive Bayes baseline | 0.778 | 0.763 | 4 / 18 |
| Conservative hybrid | 1.000 | 1.000 | 0 / 18 |
These results are regression evidence on a small synthetic dataset, not a claim
of field-ready geotechnical accuracy. The full protocol and failure analysis are
in docs/evaluation/hazard_v1.md.
The offline retrieval benchmark contains 12 synthetic construction-guidance
documents and 13 paraphrased queries. It includes a regression case that maps
domain variants such as steep hillside to slope rather than over-ranking
generic documents that merely contain review or construction.
| Metric | Score |
|---|---|
| Recall@1 | 1.000 |
| Recall@3 | 1.000 |
| Mean reciprocal rank | 1.000 |
The score demonstrates deterministic ranking on a compact synthetic fixture, not semantic search quality on real permit archives.
The GitHub Pages surface gives a recruiter-friendly product overview. The local package is now structured so reviewers can inspect package boundaries, run unit tests, and see how OCR, retrieval, LLM reasoning, and persistence are separated.
- Full pipeline execution still requires local runtime dependencies and services.
- There is no lockfile or Docker Compose path yet.
- The v2 benchmark is curated from public requirements but is not yet independently labeled by licensed engineers or code officials.
- Regulatory coverage is federal and narrow; state, local, and project-specific requirements must be added before deployment.
- The lexical precedent benchmark is small and does not replace dense retrieval, reranking, source freshness checks, or jurisdiction filters.
- Real construction, permitting, geotechnical, and environmental decisions require qualified human review.
- Add sample fixtures under
examples/. - Add a Docker Compose path for one-command local review.
- Add richer OCR/vision regression tests.
- Expand Hazard Benchmark v1 with expert-reviewed, de-identified plan excerpts.
- Compare the offline lexical index with dense and hybrid retrieval on de-identified records.
- Add screenshots or a hosted interactive demo with safe synthetic data.
MIT
This is a decision-support prototype, not a replacement for licensed engineering review.