Skip to content

Instantly share code, notes, and snippets.

@wware
wware / gitops_reconciler.md
Last active September 1, 2026 15:08
A Minimal Multi-Backend GitOps Reconciler

A Minimal Multi-Backend GitOps Reconciler

Full implementation on GitHub with tests, type checking, and comprehensive documentation.

# Quick start
uv sync --all-extras
uv run pytest  # 75 tests, 84% coverage

Can one auto-scale affordably on a single machine?

Suppose I want to avoid k8s and operate on a single physical machine but I still want to do load based auto scaling of docker containers. Doable?

Yes — you don't need k8s for this on a single box. This guide shows when single-box autoscaling makes sense, how to implement it, and when to graduate to Kubernetes.

Decision Matrix: Single Box vs Kubernetes

Criteria Single Box Kubernetes

base.py is the whole formal model expressed as a Pydantic class hierarchy — the point is that mypy + Pydantic do the enforcing, so there's essentially no hand-written validation code. Four layers:

1. Vocabulary + provenance (base.py:28-52)

TruthStatus and ExtractionMethod are closed Literal unions, so values can't drift into "inference"/"derived" variants. Provenance is a frozen sub-model requiring both source and extraction_method — that's what makes R10's all-or-nothing rule structural: you either have a complete record or None.

2. The sorts: V and its partition (base.py:55-73)

@wware
wware / make-pdf.sh
Last active August 18, 2026 16:22
make-pdf.sh
#!/bin/sh
if [ "$#" -eq 0 ]; then
set -- README
fi
TMPFILE=$(mktemp /tmp/unicode-chars.XXXXXX.tex)
cat > "$TMPFILE" << 'EOF'
\catcode`→=\active
\catcode`∈=\active

The saga of Graphwright

This work began as an exploration of Graph RAG for medical literature. It quickly became clear that the needs of researchers and clinicians marked this as a "high stakes" area of reasoning and retrieval, and that this would be an important consideration in every decision in the design of a suitable system. Specifically three principles emerged as significant requirements.

  1. The knowledge graph should use types and type-checking tools as a guard against meaningless contents. These aid in the ingestion of source documents, offering guidance in parsing ambiguous input.
  2. The medical field has accumulated a number of authoritative ontologies for diseases, drugs,
@wware
wware / Guardrails.md
Last active July 9, 2026 15:17
Guardrails for AI-generated code

Guardrails for AI-generated code

This is a topic that any post-2022 software engineer has to take seriously. So here is my take on things. First let's review what the dangers are that we are trying to avoid here.

  1. LLMs hallucinate, and frequently have a shallow (yet very confidently stated) understanding of the problem domain.
  2. LLMs become easily confused when navigating complex structures, such as deeply nested JSON structures.
  3. LLM-generated code is produced quickly and in large volume, and it becomes a coma-inducing wall of text. We need a way to stay in control, make sure it's doing what it's supposed to do, while allowing the LLM to play to its strengths.
@wware
wware / graph_lp_lang.md
Last active July 8, 2026 20:38
A literate-programming-friendly language for typed graphs

Datalog-with-types language (working name TBD)

Core motivation. Datalog with strict typing gets you ~90% of what the Graphwright typed-graph formalism (T, Φ, V, τ) already wants, and gives you a second, declarative language to embed in literate-programming markdown blocks — one where the code reads as the prose rather than fighting it.

Syntax sketch so far:

Type declarations, Haskell/OCaml-flavored, with an extends addition for hierarchy (not present in vanilla Haskell ADTs, needed because your $T_{ent}$ has real subtyping structure):

data Agent = Agent { name: String }

Multi-stage Docker images

Multi-stage builds work by separating build-time tools from runtime needs. You define multiple stages with separate FROM statements, build your application in early stages with all necessary compilers and dependencies, then copy only the final artifacts into a minimal runtime image. This eliminates the bulk of build tools from your final container.

Key principles:

  • Separate concerns: Early stages handle compilation, testing, and build processes. The final stage includes only what's needed to run the app.
  • Use COPY --from: Pull artifacts from earlier stages or external images into your final stage.
  • Pick lean base images for runtime: Use distroless images, Alpine, or scratch for the final stage to minimize size.
  • Language-specific patterns: Compiled languages (Go, Rust, C) benefit most—copy the binary alone. Interpreted languages (Python, Node, Ruby) can minify code in one stage and copy production files to another.

GQLib: Graph Traversal and Analysis Query Library

kgraph_api is a single typed Python library over GraphDbInterface. It exposes two tiers of operation against a typed graph:

  • Traversal — the four primitives an agent uses to orient itself and explore: describe_schema, search_instances, bfs_query, describe_instance.
  • Analysis — higher-level primitives that compute an answer instead of handing back a subgraph to be reasoned over: paths, intersection, ranking, comparison, conflict detection, clustering, summarization.