V0.2 DRAFT
orchestration cognition runtime

OCR Runtime

OCR is the execution governor — not optical character recognition. It is a compiled, self-contained Go runtime that loads project truth, classifies tasks, binds skills to bounded workers, verifies output, and controls writeback before anything touches your repo.

Why OCR exists

OCR stops agent drift during real project work. It gives the agent a project constitution and a loop it must obey — authority is enforced at the binary level, not requested in a prompt.

problem

Agents improvise

They skip files, invent completion, ignore prior constraints, and rewrite the mission unless the work is bounded.

runtime answer

Governed loop

Classify intent, bind a skill, execute bounded work, verify against invariants, then control the writeback.

output

Traceable execution

The result is not just an answer. It is an auditable state transition with proof attached.

What OCR is

OCR is the Go port of the OCR governed runtime — behaviour identical to the Python reference, but distributable and fast. Five properties define it.

truth-driven

Loads project truth

Reads YAML truth packs from .ocr/ — project identity, constraints, decisions, and ontology — plus current project state.

governor-enforced

Deterministic pipeline

Task classification, worker selection, skill binding, and verification run as a deterministic governor, not a prompt suggestion.

non-sovereign workers

Bounded authority

Workers execute narrow tasks but can never define or redefine truth. Authority is enforced at the binary level.

llm-callback

No hardcoded provider

Skill execution delegates to an external LLM through a clean executor interface — provider local, api, or mock.

single binary

Zero-dependency deploy

One compiled binary; the only external dependency is gopkg.in/yaml.v3. Cross-compiles to linux and darwin (amd64/arm64).

requires

Go 1.22+

Build once, run anywhere. The governor enforces the rules whether the LLM is local, remote, or mocked.

Runtime loop

Every governed task runs the same five-phase pipeline. The governor — not the worker — decides what happens at each gate.

01 // classify

Intent analysis

The governor maps the task description to a worker role and policy path using heuristics and truth rules.

02 // bind

Truth & skill loading

The runtime loads .ocr/ truth and state, then resolves the skills for the selected worker profile.

03 // execute

Bounded workers

Workers perform narrow tasks via the LLM callback. They can propose changes, but they cannot redefine project truth.

04 // verify

State validation

Nine deterministic check handlers test the output — protected assets, truth conflict, escalation, boot status, and more.

05 // writeback

Controlled mutation

On a PASS verdict, candidate writes are cleared against protected assets, truth, and path traversal before disk mutation. Failures enter a bounded repair loop.

Engine capabilities

Every capability below is finalized in the Go engine and tested without a running LLM (mockable).

Truth + state
Loads identity, constraints, decisions, and project state from .ocr/ — YAML-driven, matching the Python truth_loader.py.
Classification
Governor deterministically maps task descriptions to worker roles and policy paths.
Skill binding
Skills resolved per worker profile from OCR project contracts in .ocr/skills/.
Verification
Nine deterministic check handlers — protected assets, truth conflict, escalation, boot status, and policy checks.
Repair loop
Recoverable failures are retried with bounded limits and blocked-reason tracking.
Writeback control
Governor.CheckWritebackPaths clears every target against protected assets, truth, runtime/governor, and path traversal before mutation.
Hook dispatch
Hook actions are parsed and executed: deny / escalate gate the writeback; invoke / bind emit telemetry.
AI logging
Appends and size-bounds AI_LOG.md writes.
Providers
Registry-validated local / api / mock; HTTPS required except loopback, API key mandatory for api.

How to use it

Build the binary, then point it at a project. --resume is read-only inspection; --task runs the full classify → bind → execute → verify → writeback pipeline.

# build the binary
$ go build ./cmd/ocr-go

# inspect project status (read-only)
$ ./ocr-go --resume --repo-root /path/to/project

# run a governed task without writeback
$ ./ocr-go --task "Refactor error handling" \
    --dry-run --repo-root /path/to/project

# run against a remote API LLM
$ ./ocr-go --task "Refactor error handling" \
    --llm-provider api \
    --llm-base-url https://api.openai.com/v1 \
    --llm-api-key $OPENAI_API_KEY \
    --llm-model gpt-4 --repo-root /path/to/project

# onboard a new project (interactive)
$ ./ocr-go --onboard --repo-root /path/to/new-project
--resume
Print OCR project status and exit (no execution).
--task "…"
Execute a governed task through the full pipeline.
--dry-run
Run governance without applying writeback.
--onboard
Run the interactive OCR onboarding skill.
--llm-provider
local or api for --task.
--llm-base-url
Endpoint URL for the selected provider.
--llm-model
Model name (default local-model / gpt-4).
--repo-root
Path to the OCR project root (default .).
Config precedence: CLI flags > .ocr-go.yaml repo config > built-in defaults. Use .ocr-go.yaml for team defaults and flags for per-run overrides; within config, api_key_env is preferred over a literal api_key.

Download the engine

Grab the compiled OCR Go engine console package, unzip, and build with go build ./cmd/ocr-go.

go engine
ocr-go-engine-console

The full OCR governed runtime: governor, executor pipeline, LLM client abstraction, YAML truth loader, interactive onboarding skill, and the cmd/ocr-go CLI entrypoint. Single binary, Go 1.22+.

in the box
  • cmd/ocr-go — CLI entrypoint
  • pkg/governor — classify, bind, verify, writeback
  • pkg/executor — task pipeline & repair loop
  • pkg/llm — local / api / mock clients
  • runtime/ — governor policies

Ecosystem

OCR governs execution. Its sibling, CRP, governs the reasoning that decides what to execute in the first place.