Skip to content

About

plainpatch: edit service configs in plain English. A local LLM on Ollama reads the request; code does the units and math, checks every value, and previews, applies or undoes the JSON Patch

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

plainpatch

Edit service configs in plain English. A local model reads the request; code does the math and checks every value.

Tests Evals: 61/69 Runs on Ollama Python 3.12 License: Apache-2.0

Terminal recording: ppatch previews 'lower the orders cpu limit to 80%' as '~ /workload/container/resources/cpu/limitMilliCPU: 500 → 400'. The same request with --apply saves it as revision #1. 'ppatch history orders' lists the change with author and time, 'ppatch undo orders' reverts it as revision #2 back to 500, and the vague request 'make orders faster' is refused with a 422 that gives the reason.
Real time against qwen2.5:3b on an RTX 4070. Nothing is cut or mocked.

plainpatch turns requests like "lower the orders cpu limit to 80%" into a validated JSON Patch against a service's config. It shows you the diff, and saves it with an audit entry you can undo when you ask. It runs entirely on your machine: three small FastAPI services, a standard-library CLI, and a 3B model on Ollama. The model only extracts what to change. Everything that has to be exact, from units and percentages to which fields exist and whether a value really came from your words, is done and checked by code.

  • The model can't invent fields. Ollama's structured outputs get a grammar built from the current config, so every path is one that exists and every value has the right type.
  • Code does the arithmetic. The model copies "80%", "+512mb" or "1.5 cores" as you wrote it, and code converts by the field's unit (…MiB, …MilliCPU, …Seconds).
  • Every value is grounded in your request. Vague requests ("make it faster") and invented values get a 422 with the reason, never a silent edit.
  • Preview first, then apply, audit and undo. Writes are atomic, concurrent applies can't overwrite each other, and each change records who made it and why.
  • Measured, not guessed. 69 labeled requests scored on the exact resulting config: 39/69 at the start, 61/69 now, at a median of 0.3 s per request (evals).
  • Cheap to run. About 1.2 LLM calls per request, an 800-token prompt that's mostly served from Ollama's cache, and Prometheus metrics for all of it.

Quick start

You need: Docker with Compose v2 and about 4 GB of free RAM. An NVIDIA GPU is optional but makes requests about 10× faster.

git clone https://github.com/metharda/plainpatch.git && cd plainpatch
cp .env.example .env
docker compose up -d                    # first start pulls qwen2.5:3b (~2 GB)
curl -s localhost:7000/health           # {"status":"healthy","circuit_breaker":"closed"}

Then try a change:

alias ppatch="python3 $(pwd)/cli/ppatch.py"
ppatch "lower the orders cpu limit to 80%"            # preview: 500 → 400
ppatch "lower the orders cpu limit to 80%" --apply    # saved as revision #1
ppatch undo orders                                    # back to 500

Tip

Everything the CLI does is one HTTP call: curl -s localhost:7000/edits -H 'Content-Type: application/json' -d '{"text": "give ledger 6gb of memory"}'. See Usage for the walkthrough and API for every field.

How it works

flowchart LR
    req["“lower the orders<br/>cpu limit to 80%”"] --> route["Pick the app<br/>regex, LLM fallback"]
    route --> llm["qwen2.5:3b on Ollama<br/>grammar: existing paths only"]
    llm -- "replace …/limitMilliCPU = “80%”" --> code["intents.py<br/>ground · convert · compute"]
    code -- "replace …/limitMilliCPU = 400" --> check["JSON Schema<br/>+ limit ≥ request"]
    check --> out(["diff preview<br/>or apply + audit"])
    check -. "error fed back, up to 3 tries" .-> llm
Loading
  1. Route. A regex picks the app when the request names one. App names inside values, like storefront:2.0, don't count, and only otherwise is the model asked.
  2. Extract. The model gets the current config and a grammar listing every path that exists. It answers with JSON Patch-style operations and writes quantities exactly as you did.
  3. Compile. bot-server/intents.py checks that every value comes from your request, converts units, applies percentages to the current value, drops no-ops, and clamps requests under a lowered limit.
  4. Validate. The patch is applied in memory and checked against the app's JSON Schema. If anything fails, the exact error goes back to the model, up to three attempts in total.
  5. Respond. You get the diff, the model's raw intent and the resulting config. With --apply, the values service writes atomically and refuses the write if someone else changed the config in the meantime.

The details, including why each check exists, are in Intents and Architecture.

Evals

Stage Score (69 requests) Median Edit prompt
Structured outputs, full schema in the prompt 39/69 0.49 s ~2,560 tokens
+ regex router, request-last prompt, cache 53/69 0.35 s ~2,600
+ grammar of existing paths, schema dropped from the prompt 58/69 0.36 s ~600
+ code does units and arithmetic, values grounded in the request 61/69 0.32 s ~780

These are qwen2.5:3b numbers on an RTX 4070, scored on exact configs with no LLM judge, across three sets, two of them written later as held-out checks. Seven of the eight misses are refusals with a reason. One is a wrong edit, a two-field timeout request that hit the probe timeouts instead, and the evals page explains it along with the method and the ideas that didn't work. Reproduce with make eval.

Note

Ten parallel testers then probed a live stack with about 500 adversarial requests (routing, units, injection, concurrency, the API, the CLI). Everything they broke is fixed and tested (details).

Day to day

Task Command
Preview a change ppatch "set ledger replicas to 3"
Apply it ppatch "set ledger replicas to 3" --apply --author you
See what changed ppatch history ledger
Undo the last change ppatch undo ledger
Add an env var ppatch "add env LOG_LEVEL=debug to storefront"
Watch the LLM metrics docker compose --profile monitoring up -d → Grafana on :3000
Put nginx in front docker compose --profile gateway up -d (rate limited, /values/ read-only)
Run the tests / the evals make test · make eval

Requirements

Runtime Docker with Compose v2, or Python 3.12 to run the services directly
Model qwen2.5:3b on Ollama 0.30 or newer (pulled automatically by Compose)
Memory 4 GB free; the model uses about 2.5 GB of RAM or VRAM
GPU Optional. Median 0.3 s per request on an RTX 4070; expect several seconds on CPU

Limitations

  • It edits fields that already exist, plus new env vars. It doesn't create new sections of a config.
  • One app per request. Requests that name several apps are refused with a message.
  • Multi-field requests whose field names overlap, such as "read and send timeouts" next to probe timeouts, are the weakest spot (see known misses).
  • No authentication. author is self-reported. Run it on a trusted network or behind your own auth (Security).
  • Undo restores the snapshot taken before a change, so hand edits made to a values file in between are overwritten.

How it compares

Approach Good for Trade-off
plainpatch Plain-English edits to schema-backed configs, with preview, audit and undo, on local hardware Needs a schema and a running model; edits existing fields only
Editing YAML/JSON by hand, kubectl patch Full control, no moving parts You do the unit math and remember every path
Asking a chat assistant to rewrite the file Any format, no setup Rewrites the whole file, can't be validated before you paste it, and the data leaves your machine
Helm values / Kustomize overlays Repeatable, reviewed changes in Git Not conversational; each change is a manual edit
instructor, outlines Building blocks for structured LLM output Libraries, not an end-to-end editor with grounding and audit

Documentation

Document What's in it
Usage Walkthrough, every CLI command and flag, HTTP examples
API Every endpoint, field, response and status code
Intents The grammar, quantity parsing, grounding, routing and LLM settings, and why each exists
Architecture Components, request flow, code map, invariants, design decisions
Evals Method, results per stage, failed ideas, known misses, how to run and extend
Operations Configuration, compose profiles, monitoring, metrics, errors and what to do
Security Threat model and how to report a vulnerability
Development Working on the code, adding an app, re-recording the demo
Research notes The cited research behind the design

License

Apache License 2.0. See LICENSE and NOTICE.

About

plainpatch: edit service configs in plain English. A local LLM on Ollama reads the request; code does the units and math, checks every value, and previews, applies or undoes the JSON Patch

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages