kleene@sql

Research digest

Sources behind docs/PLAN.md, gathered 2026-09-11. Grouped by the decision they informed. Where a primary source was unreachable from the build sandbox the item is marked (snippet).

Recursive Language Models

Aura LLM Gateway (one gateway option; its routing and pricing shapes are copied)

  • Repo: https://github.com/UmaiTech/aura-llm-gateway (Rust, MIT, 0.18.0, Rust 1.91+). SDKs aura-llm on PyPI (0.18.0) and npm (0.18.0). Docs at https://aura-llm.dev. Design write-up: https://www.umai-tech.com/blog/building-aura-an-agentic-llm-gateway-in-rust
  • Implements the Open Responses API: POST /v1/responses, items (message, function_call, function_call_output, reasoning), status lifecycle, SSE with semantic events (response.output_text.delta, response.function_call.done, response.completed), previous_response_id threading. Also an OpenAI-compatible /v1 endpoint.
  • Nine providers (OpenAI, Anthropic, Google, Mistral, Together, Fireworks, Ollama, HF TGI, Bedrock), eight routing strategies plus circuit breaker, Redis response cache, per-request usage.cost_usd with input/output/cached/ reasoning token breakdown, metadata.aura with provider and latency, prompt compression (TOON, AISP, YAML, JSON), response validation (logprobs, self-consistency, best-of-N, confidence thresholds), multi-tenancy and scoped API keys, Prometheus metrics.
  • Crates: aura-types (Open Responses types; deps serde, serde_json, uuid, chrono, thiserror, utoipa; light enough to depend on via git), aura-core (providers, SmartRouter, AutoRouter, FallbackChain, CostCalculator, compression; depends on aura-db with SQLx/Postgres, Redis and the AWS SDK, so too heavy to embed), aura-db, aura-proxy. None are published on crates.io.
  • Provider trait in aura-core: name, models, supports_model, complete(CreateResponseRequest) -> Response, complete_stream, health_check.
  • CreateResponseRequest fields: model, input, instructions, max_output_tokens, temperature, top_p, stream, previous_response_id, tools, tool_choice, user, metadata, validation, consistency, compression, routing. No reasoning-effort, JSON-schema output or cache-control field yet; these are the upstream proposals in PLAN.md 3.8. Usage has cached_tokens and cost_usd.

Long-running and continual harnesses

  • Anthropic reference code for long-running agents: https://github.com/anthropics/cwc-long-running-agents — feature list, progress file, default-FAIL test contract, commit-on-stop hooks, git log as audit trail.
  • OpenAI Unrolling the Codex agent loop and Harness engineering (snippet): compaction items, sandbox, approvals; Agents SDK RunState snapshot and rehydrate, tracing spans.
  • Curated index: https://github.com/ai-boost/awesome-harness-engineering
  • Common pattern across all: append-only event log plus externalised state plus checkpoints, re-read on resume. Kleene makes the state a database.

Prime Intellect

  • Prime Agent (Aug 2026, MIT): https://github.com/PrimeIntellect-ai/prime-agent — TypeScript host plus Python kernel, not Rust. Borrowed: one programmatic tool with a typed host-request bridge; spawn returns a handle and results come back as messages; tree-structured JSONL session files with child_usage_attributed entries; daemon supervisor with generation-aware event cursors and snapshot streaming for reconnect; /tree fold view; budgets and quality gates for autonomous mode; rlm.harness ledger with /refine CRUD edits and rollback.
  • verifiers v1: https://github.com/PrimeIntellect-ai/verifiers — Taskset / Harness / Runtime / Toolset / Trace separation; an intercepting model proxy as the universal trace recorder.
  • prime-rl: https://github.com/PrimeIntellect-ai/prime-rl — orchestrator, inference and trainer as separate processes; rollouts persisted to the filesystem. Relevant only if Kleene traces are later used for training.

Headlong

TUI references

  • Codex CLI (Rust, ratatui): https://github.com/openai/codex/tree/main/codex-rs/tui — history cells plus one mutable streaming cell, bottom pane with context percentage, status indicator with elapsed timer.
  • tau (Rust, ratatui): https://github.com/tau-agent/tau — agent server plus thin TUI over a Unix socket, detach and reattach. Closest analogue.
  • pi footer (tokens/cost/context), opencode sidebar, crush compact mode below 120×30, bottom’s tree mode keys, gitui’s context-sensitive key bar.
  • Crates verified compatible with ratatui 0.30: tui-tree-widget 0.24.1, tui-markdown 0.3.9, tui-logger 0.18.3, tui-scrollview 0.6.7, ratatui-flow 0.1.1 (DAG boxes, very new).
  • Async pattern: https://ratatui.rs/tutorials/counter-async-app/

SQL as the LLM interface (prior art)

Complexity results cited in the plan

Hard-instance generation

Rust crates (versions checked on crates.io, 2026-09-11)

CrateVersionRole
sqlparser0.62.0parser; recursive CTEs, EXISTS, LATERAL, table functions, visitor feature
datafusion55.0.0rejected for v1 (async UDFs only under projection/filter, plan-time table-function args, heavy build)
tokio1.53.1runtime
duckdb1.10505.0 (DuckDB 1.5)session store, memo, trace, analytics, differential oracle; bundled build is slow, cache it
ratatui0.30.2TUI
crossterm0.29.0terminal backend
tui-tree-widget0.24.1call tree
tui-markdown0.3.9streaming output rendering
hakoniwa1.7.2sandbox for shell
genai0.6.5considered for multi-provider; not needed while we speak the Messages API directly
rig-core0.42.0considered; heavier abstraction than we want
ascent / datafrog0.8.1 / 2.0.1not needed; semi-naive evaluation is written by hand

Notes: no official Anthropic Rust SDK exists (confirmed May 2026). birdcage was archived in July 2026, so it is not used.

Benchmarks considered

Naming

kleene is taken on npm and GitHub by a small JavaScript library (https://github.com/fluture-js/kleene); crates.io and PyPI are free. HardQL, RLMQL, RelationalLM are free everywhere, but rllm (relationLLM) is a real PyTorch library near the last one.