Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

feat(rlm): make RLM the default loop; --old restores structured-only

Cursor Agent634d4760fab3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01ac2b15..92646ba4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,16 @@ The release workflow uses a tag's section here as its release notes (a
hand-written `docs/releases/<tag>.md` wins if present), so keeping this file
current is part of cutting a release.
+## v0.0.276 (2026-08-25)
+
+- `rlm` (Zhang/Khattab RLM + alexzhang13 spec-ptc, Zig — not Prime's
+ IPython kernel) is the default loop. `--old` / `--no-rlm` (or
+ `GRAFF_OLD=1` / `GRAFF_RLM=0`) restore the structured-only catalog.
+ `--rlm` stays as an explicit on. Last CLI flag wins; env does not
+ clobber `--old` / `--rlm`.
+- The spec stays folded behind `load_tool_schemas`. `--schema` / the
+ 64-cell tool-catalog kernel do not grow a new tool.
+
## v0.0.274 (2026-08-23)
- Rate-limit and 5xx retries no longer dump the provider's raw error JSON
diff --git a/docs/adr/0022-rlm-is-opt-in-speculative-ptc.md b/docs/adr/0022-rlm-is-opt-in-speculative-ptc.md
index d2e2d68e..7747855e 100644
--- a/docs/adr/0022-rlm-is-opt-in-speculative-ptc.md
+++ b/docs/adr/0022-rlm-is-opt-in-speculative-ptc.md
@@ -1,6 +1,6 @@
-# 0022. `rlm` is opt-in speculative programmatic tool calling
+# 0022. RLM + spec-ptc is the default loop; `--old` restores structured-only
-Status: accepted 2026-08-25
+Status: accepted 2026-08-25; default flipped 2026-08-25
## Context
@@ -14,24 +14,35 @@ calls, and `runTools` fans a *finished* batch across the pool. That is
parallelism after the arguments close, not speculation from partial source.
Dropping spec-ptc's Python shadow REPL into the default catalog would change
-every prefix and the 64-cell tool-catalog kernel. A first cut has to be
-measurable against the native loop without that cost.
+every prefix and the 64-cell tool-catalog kernel. The first cut stayed
+opt-in so it was measurable against the native loop without that cost.
+Scatter and persist then won by enough that the loop itself became the
+default; `--old` is the escape hatch, not a second implementation.
## Decision
-`rlm` is an opt-in native tool (`--rlm` / `GRAFF_RLM=1`). Off, the catalog is
-unchanged. On, the spec joins the `native_fold` stack (the same meta-tool
-listing as `workflow` / `subagent`): name only on `load_tool_schemas` until
-the model loads or calls it, so `--rlm -p` (lean) does not pay the full
+`rlm` is the default native tool. `--old` / `--no-rlm` / `GRAFF_OLD=1` /
+`GRAFF_RLM=0` restore the structured-only catalog. `--rlm` / `GRAFF_RLM=1`
+force it on. Last CLI flag wins; env does not clobber `--old` or `--rlm`.
+
+This is **Alex Zhang's spec-ptc + RLM**, implemented in Zig — not Prime
+Agent's IPython/ZeroMQ kernel, and not a Python fan-out process. Prime's
+shape we kept: persistent binds across `rlm` calls and `subagent("task")`
+via graff's existing `subagent` tool.
+
+The spec joins the `native_fold` stack (the same meta-tool listing as
+`workflow` / `subagent`): name only on `load_tool_schemas` until the model
+loads or calls it, so default `-p` (lean) does not pay the full
description on every turn. The REPL's functions *are* graff tools
-(`read_file`, `codedb`) plus `sleep_ms` / `llm_query` / `print`. The
-speculator is Zig (`src/spec_ptc.zig` + `rlm.feedLive`): closed statements
-with literal args launch as the `code` argument streams (including `-p`,
-where `Agent.out` is null), then `runScript` claims the futures. Default
-structured tools stay the main harness.
+(`read_file`, `codedb`, `bash`, `webfetch`) plus `sleep_ms` / `llm_query`
+/ `print` / `subagent`. The speculator is Zig (`src/spec_ptc.zig` +
+`rlm.feedLive`): closed statements with literal args launch as the `code`
+argument streams (including `-p`, where `Agent.out` is null), then
+`runScript` claims the futures. `--schema` and the 64-cell tool-catalog
+kernel do not grow a new always-on tool.
A live comparison is `scripts/compare-ptc.py`. The eval A/B is
-`graff-evals/run.py --harness graff-dev,graff-dev-rlm`.
+`graff-evals/run.py --harness graff-dev-old,graff-dev`.
Measured 2026-08-25 on grok-4.6 (SuperGrok login, one rep, full
`graff-evals` suite). Both harnesses **12/12** in both catalog shapes.
@@ -63,13 +74,14 @@ regression* without a catalog tax. Per-task swings are one-rep variance.
## Consequences
- Mid-stream speculation is on the SSE path even when the one-shot frontend
- is quiet (`printDelta` still feeds `ArgLive` for `rlm` when `--rlm` is set).
+ is quiet (`printDelta` still feeds `ArgLive` for `rlm` when it is on).
`rlm` is *not* visible-prose for the WS stall signal (SSE does not grow
`partial_text` for `code`).
- `llm_query` is a bounded tools-off sub-call on the session provider
(`src/rlm_query.zig`). Nested spend is real; the host function exists so
sPTC can overlap an expensive sub-LM with the rest of the script.
-- SDK / `--schema` do not list `rlm` until it graduates off the flag.
+- SDK / `--schema` do not list `rlm` as a catalog tool (fold + `maybeAppend`
+ only). Launch flags `--rlm` / `--old` are in the `--schema` flags list.
- Semicolons (outside strings) are statements, so a one-line script still
speculates. Host positional fields include `bash` / `webfetch`. `print(a, b)`
joins binds. A short system note is spliced only while the flag is on so
@@ -93,7 +105,10 @@ regression* without a catalog tax. Per-task swings are one-rep variance.
summed per-task wall native **624s / 822k in / 9.7M RSS** vs `--rlm`
**652s / 816k in / 9.4M RSS**. `map-conflict` was the only clear
`--rlm` win (84s → 52s). Same pass rate, no memory win, no wall win
- on this suite — RLM stays opt-in.
+ on this suite — `--old` stays as the structured-only escape. Default
+ flipped anyway because scatter (`needle-files` 62.8s → 5.6s) and Prime
+ persist (`bind-reuse` 97.5s → 41.4s) are the loops that matter, and
+ core/swe did not regress.
- Prime persist (`bind-reuse`): grok-4.6 one rep. `--rlm` **41.4s /
6 calls / 30.9k in** and the model actually did `s = read_file(...)`
then a second script `print(s)`. Native **97.5s / 12 calls / 145k
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 8f851c3b..5f135d56 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -32,7 +32,7 @@ record only when you need the evidence or the edge cases.
| [0019](0019-codedb-one-shot-over-hop-chains.md) | Advertise only `context` / `around` / `callpath` / `list_dir` / `status`; hop verbs stay callable, not on the menu. |
| [0020](0020-transcript-shows-decisions.md) | Transcript shows decisions: one interpreted tool line, collapsed infra failures, compact WORKING; raw output is `/debug` / TUI-fold. |
| [0021](0021-transcript-is-the-task-not-the-bus.md) | Transcript is the task, not the event bus: bookkeeping is silent, todos are WORKING, subagents are scouts. |
-| [0022](0022-rlm-is-opt-in-speculative-ptc.md) | `rlm` is opt-in RLM + mid-stream spec-ptc (`--rlm` / `GRAFF_RLM=1`). Default catalog unchanged. Zig subset of Prime's model: persistent binds + `subagent("task")`. |
+| [0022](0022-rlm-is-opt-in-speculative-ptc.md) | `rlm` (Alex Zhang spec-ptc + RLM, Zig) is the default loop. `--old` restores structured-only. Prime persist + `subagent()` only — no IPython. |
## When to write one
diff --git a/docs/releases/v0.0.276.md b/docs/releases/v0.0.276.md
new file mode 100644
index 00000000..af88add5
--- /dev/null
+++ b/docs/releases/v0.0.276.md
@@ -0,0 +1,15 @@
+# v0.0.276 (2026-08-25)
+
+RLM + mid-stream spec-ptc is the default harness loop.
+
+`graff` now advertises the `rlm` REPL (persistent binds, `subagent()`,
+`llm_query`, speculated host calls as the script streams). `--old` /
+`--no-rlm` restore the previous structured-only catalog.
+
+This is the Zig port of [alexzhang13/spec-ptc](https://github.com/alexzhang13/spec-ptc)
+and [alexzhang13/rlm](https://github.com/alexzhang13/rlm). Prime Agent's
+IPython/ZeroMQ kernel is not in the process; persist + `subagent("task")`
+are the only Prime-shaped pieces, still in Zig.
+
+`--schema` and the 64-cell tool-catalog kernel do not list `rlm` as a
+new always-on tool — it still folds behind `load_tool_schemas`.
diff --git a/graff-evals/README.md b/graff-evals/README.md
index 7aecbe23..93866edc 100644
--- a/graff-evals/README.md
+++ b/graff-evals/README.md
@@ -18,12 +18,12 @@ harness under test spends model calls.
| suite | what it measures |
|---|---|
| `core` | sequential single-file work (instruction, debug, git, schema, …) |
-| `rlm` | scatter-gather / multi-file reads (where `--rlm` can overlap) |
+| `rlm` | scatter-gather / multi-file reads (where default rlm can overlap) |
| `swe` | DeepSWE-shaped multi-file bugfixes, distilled from [deepswe.datacurve.ai/run](https://deepswe.datacurve.ai/run) (no Harbor/Docker) |
```sh
-./run.py --suite swe --harness graff-dev,graff-dev-rlm --model grok-4.6 -j 12
-./run.py --suite core,rlm,swe --harness graff-dev,graff-dev-rlm -j 8
+./run.py --suite swe --harness graff-dev-old,graff-dev --model grok-4.6 -j 12
+./run.py --suite core,rlm,swe --harness graff-dev-old,graff-dev -j 8
```
## Run it
diff --git a/graff-evals/harnesses.json b/graff-evals/harnesses.json
index 323871a6..49cb9897 100644
--- a/graff-evals/harnesses.json
+++ b/graff-evals/harnesses.json
@@ -32,7 +32,17 @@
"schema_args": ["--output-schema", "{schema}"],
"env": {"GRAFF_POST_DEADLINE_SECS": "90"},
"default_model": "grok-4.6",
- "note": "same as graff-dev plus --rlm (RLM REPL + mid-stream spec-ptc)"
+ "note": "explicit --rlm (same as graff-dev after RLM became the default)"
+ },
+ "graff-dev-old": {
+ "cmd": ["{repo}/zig-out/bin/graff", "-p", "{prompt}", "--model", "{model}", "--yolo", "--old"],
+ "answer": "stdout",
+ "usage": "graff-stderr",
+ "capabilities": ["output-schema"],
+ "schema_args": ["--output-schema", "{schema}"],
+ "env": {"GRAFF_POST_DEADLINE_SECS": "90"},
+ "default_model": "grok-4.6",
+ "note": "pre-rlm structured-only catalog (--old)"
},
"grok": {
"cmd": ["grok", "-p", "{prompt}", "-m", "{model}", "--always-approve", "--output-format", "streaming-messages-json"],
diff --git a/graff-evals/run.py b/graff-evals/run.py
index 39f8b1d0..708ec3fd 100755
--- a/graff-evals/run.py
+++ b/graff-evals/run.py
@@ -8,8 +8,8 @@ time / first-output latency / token usage / peak RSS / CPU, verifies the
outcome, and writes JSONL results plus a summary table.
./run.py --harness graff --model grok-4.6 # full suite (core + rlm + swe)
- ./run.py --suite rlm --harness graff-dev,graff-dev-rlm # scatter-gather A/B
- ./run.py --suite swe --harness graff-dev,graff-dev-rlm -j 12 # DeepSWE-shaped A/B, parallel
+ ./run.py --suite rlm --harness graff-dev-old,graff-dev # scatter-gather A/B
+ ./run.py --suite swe --harness graff-dev-old,graff-dev -j 12 # DeepSWE-shaped A/B, parallel
./run.py --harness grok --task fix-fib --reps 3 # one task, 3 reps
./run.py --interactive # pick + watch live
"""
diff --git a/scripts/compare-ptc.py b/scripts/compare-ptc.py
index e2a399ec..0cd7eca2 100755
--- a/scripts/compare-ptc.py
+++ b/scripts/compare-ptc.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-"""Compare native structured tool calls vs --rlm (spec-ptc) on the same prompt.
+"""Compare --old structured tool calls vs default rlm (spec-ptc) on the same prompt.
Runs graff twice against a three-file fixture and prints tool_call shape +
timing. Default binary: zig-out/bin/graff, then $PATH graff.
@@ -92,11 +92,11 @@ def main() -> int:
Path(td, "b.txt").write_text("bravo-first\nrest-b\n")
Path(td, "c.txt").write_text("charlie-first\nrest-c\n")
print(f"graff={args.graff}", flush=True)
- print("=== native (structured tools) ===", flush=True)
- native = run(args.graff, [], PROMPT, td)
+ print("=== old (structured tools, --old) ===", flush=True)
+ native = run(args.graff, ["--old"], PROMPT, td)
print(json.dumps({k: native[k] for k in ("ok", "ms", "names", "tools", "finished_ms", "usage")}, indent=2))
- print("=== rlm (--rlm, speculated reads) ===", flush=True)
- rlm = run(args.graff, ["--rlm"], PROMPT + RLM_HINT, td)
+ print("=== rlm (default, speculated reads) ===", flush=True)
+ rlm = run(args.graff, [], PROMPT + RLM_HINT, td)
print(json.dumps({k: rlm[k] for k in ("ok", "ms", "names", "tools", "finished_ms", "usage")}, indent=2))
print("=== answers ===")
print("native:\n", native.get("answer") or native.get("stderr"))
diff --git a/src/args.zig b/src/args.zig
index f3d99f39..67a73eeb 100644
--- a/src/args.zig
+++ b/src/args.zig
@@ -175,9 +175,9 @@ pub fn parse(init: std.process.Init) !Flags {
} else if (std.mem.eql(u8, arg, "--clock-sleep")) {
main_mod.g_clock_sleep = true; // #225: opt in to the root-only clock_sleep meta tool (also GRAFF_CLOCK_SLEEP=1)
} else if (std.mem.eql(u8, arg, "--rlm")) {
- @import("rlm.zig").available = true; // ADR 0022: opt-in programmatic tool calling (also GRAFF_RLM=1)
- @import("rlm.zig").sync();
- @import("rlm.zig").sync();
+ @import("rlm.zig").setFromCli(true); // ADR 0022: default RLM; last flag wins vs --old
+ } else if (std.mem.eql(u8, arg, "--old") or std.mem.eql(u8, arg, "--no-rlm")) {
+ @import("rlm.zig").setFromCli(false); // structured-only catalog (also GRAFF_OLD=1 / GRAFF_RLM=0)
} else if (std.mem.eql(u8, arg, "--no-autocommit")) {
main_mod.g_worktree_autocommit = false;
} else if (std.mem.eql(u8, arg, "--schema")) {
diff --git a/src/cli.zig b/src/cli.zig
index 91d00056..2e6f0973 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -21,6 +21,9 @@ const harness_version = root.harness_version;
pub const changelog_text =
\\What's new
\\──────────
+ \\0.0.276
+ \\ • rlm (RLM + mid-stream spec-ptc) is the default loop; --old / --no-rlm restores structured-only
+ \\
\\0.0.275
\\ • OpenRouter requests carry app attribution (categories: cli-agent, programming-app)
\\ • TUI: Esc with a draft in the composer never kills a live turn
@@ -245,7 +248,8 @@ pub const usage_text =
\\ --context-limit name=N cap a named prefix: skill_catalog_bytes|mcp_schema_bytes|agents_md_bytes
\\ --no-autocommit with -w, don't auto-commit each turn (default on; land work with `graff worktree merge`)
\\ --yolo skip all permission prompts for the session
- \\ --rlm advertise the rlm REPL (persistent binds, subagent(), llm_query, mid-stream spec-ptc; GRAFF_RLM=1)
+ \\ --rlm advertise the rlm REPL (default; persistent binds, subagent(), llm_query, mid-stream spec-ptc; GRAFF_RLM=1)
+ \\ --old, --no-rlm restore the pre-rlm structured-only catalog (GRAFF_OLD=1 or GRAFF_RLM=0)
\\ --lean slim tool surface (9 core tools) + MCP deferred behind load_tool_schemas — the DEFAULT for -p one-shots (GRAFF_LEAN=1)
\\ --no-lean opt a one-shot out of the implied --lean: full tool surface + eager MCP, the pre-default -p behavior
\\ --no-local-tools embedder mode: hard-disable the built-in bash/bash_output/bash_kill/read_file/edit_file/write_file/codedb tools for the whole process (subagents included), so graff can run outside the sandbox and get its coding tools from an MCP server instead; webfetch, orchestration and MCP tools still work (GRAFF_NO_LOCAL_TOOLS=1)
diff --git a/src/native_fold.zig b/src/native_fold.zig
index 1c334654..9cb1e46f 100644
--- a/src/native_fold.zig
+++ b/src/native_fold.zig
@@ -55,14 +55,14 @@ pub const folded = [_][]const u8{
"agent_output",
"skill",
"webfetch",
- // Opt-in (ADR 0022). isFolded is false until --rlm so the default
+ // ADR 0022: isFolded is false under --old so the structured-only
// load_tool_schemas listing stays byte-stable.
"rlm",
};
/// A name test only, independent of whether the fold is on.
-/// `rlm` joins the stack only while `--rlm` / GRAFF_RLM=1 is set — otherwise
-/// the default catalog and the meta-tool listing stay unchanged (ADR 0022).
+/// `rlm` joins the stack while available (default); `--old` drops it so the
+/// structured-only catalog and the meta-tool listing stay unchanged.
pub fn isFolded(name: []const u8) bool {
if (std.mem.eql(u8, name, "rlm")) return @import("rlm_spec.zig").available;
for (folded) |tool| {
@@ -371,7 +371,7 @@ test "explicit native loads rebuild the active provider catalog (#492)" {
try std.testing.expectEqual(@as(usize, 1), agent.rebuilds);
}
-test "rlm joins the fold only while --rlm is on" {
+test "rlm joins the fold only while available (off under --old)" {
const rlm_spec = @import("rlm_spec.zig");
const saved_avail = rlm_spec.available;
const saved_enabled = enabled;
diff --git a/src/no_local_tools.zig b/src/no_local_tools.zig
index f58a1141..67ca4e34 100644
--- a/src/no_local_tools.zig
+++ b/src/no_local_tools.zig
@@ -314,7 +314,7 @@ test "#330: neither catalog advertises a local tool under the gate, and webfetch
if (std.mem.eql(u8, spec.name, "webfetch")) kept_webfetch = true;
if (std.mem.eql(u8, spec.name, "subagent")) kept_subagent = true;
}
- try std.testing.expectEqual(open.len - gated_tools.len, gated.len);
+ try std.testing.expectEqual(open.len - gated_tools.len - 1, gated.len); // rlm also drops under #330
try std.testing.expect(kept_webfetch); // pure host HTTP: no sandbox to escape
try std.testing.expect(kept_subagent); // orchestration stays; the child inherits the gate
diff --git a/src/rlm.zig b/src/rlm.zig
index 5ac3d0fb..db5b5452 100644
--- a/src/rlm.zig
+++ b/src/rlm.zig
@@ -1,10 +1,10 @@
-//! Opt-in `rlm` tool: one programmatic-tool-calling REPL per call.
+//! Default `rlm` tool: one programmatic-tool-calling REPL per call (ADR 0022).
//!
-//! Off unless `--rlm` / `GRAFF_RLM=1`. The default catalog stays byte-stable
-//! (ADR 0022). Host functions: `read_file`, `codedb` (real graff tools),
-//! `sleep_ms` (overlap proof), `llm_query` (RLM tools-off sub-LM), `print`
-//! (answer). Closed literal calls launch as the `code` argument streams
-//! (spec-ptc) and again at exec for anything the stream missed.
+//! On unless `--old` / `--no-rlm` / `GRAFF_OLD=1` / `GRAFF_RLM=0`. `--rlm`
+//! and `GRAFF_RLM=1` force it back on. Host functions: `read_file`, `codedb`
+//! (real graff tools), `sleep_ms` (overlap proof), `llm_query` (RLM tools-off
+//! sub-LM), `print` (answer). Closed literal calls launch as the `code`
+//! argument streams (spec-ptc) and again at exec for anything the stream missed.
const std = @import("std");
const Io = std.Io;
@@ -26,16 +26,26 @@ pub const tool_schema =
\\{"type": "object", "properties": {"code": {"type": "string", "description": "Python-like script: name = read_file(\"path\") / codedb(\"command\") / bash(\"cmd\") / sleep_ms(ms) / llm_query(\"prompt\") / subagent(\"task\"); print(...) is the result. Assignments persist across rlm calls. Semicolons or newlines separate statements."}}, "required": ["code"]}
;
-/// Process-global: `--rlm` / GRAFF_RLM=1. Never flipped mid-session.
-/// Keep in sync with rlm_spec.available (`sync`) so the SSE path can see it
-/// without importing this file (exec.zig would cycle through Agent).
-pub var available: bool = false;
+/// Process-global: on by default. `--old` / `--no-rlm` turn it off; `--rlm`
+/// turns it on. Never flipped mid-session. Keep in sync with
+/// rlm_spec.available (`sync`) so the SSE path can see it without importing
+/// this file (exec.zig would cycle through Agent).
+pub var available: bool = true;
+/// True after `--rlm` / `--old` / `--no-rlm` so env knobs cannot clobber CLI.
+pub var cli_set: bool = false;
pub fn sync() void {
rlm_spec.available = available;
rlm_spec.run_host = runHost;
}
+/// Last CLI flag wins. Marks `cli_set` so GRAFF_RLM / GRAFF_OLD stay off this path.
+pub fn setFromCli(on: bool) void {
+ available = on;
+ cli_set = true;
+ sync();
+}
+
pub fn resetLive(gpa: Allocator, io: Io) void {
sync();
rlm_spec.resetLive(gpa, io);
@@ -47,10 +57,10 @@ pub fn feedLive(ctx: ToolCtx, delta: []const u8) void {
rlm_spec.feedLive(ctx, delta);
}
-/// Append `rlm` after the lean/no-local filters so `--rlm -p` still sees it.
-/// The spec is folded behind `load_tool_schemas` (native_fold) until the
-/// model loads or calls it — the prefix stays the lean catalog plus a name.
-/// No-op when the flag is off or embedder mode stripped host tools.
+/// Append `rlm` after the lean/no-local filters so the default `-p` still
+/// sees it. The spec is folded behind `load_tool_schemas` (native_fold)
+/// until the model loads or calls it — the prefix stays the lean catalog
+/// plus a name. No-op when `--old` or embedder mode stripped host tools.
pub fn maybeAppend(comptime Spec: type, arena: Allocator, specs: []const Spec) ![]const Spec {
sync();
if (!available or no_local_tools.enabled) return specs;
@@ -63,7 +73,7 @@ pub fn maybeAppend(comptime Spec: type, arena: Allocator, specs: []const Spec) !
pub fn exec(ctx: ToolCtx, input: Value) !ToolOutput {
sync();
- if (!available) return .{ .text = try ctx.gpa.dupe(u8, "rlm is off — pass --rlm (or GRAFF_RLM=1)"), .is_error = true };
+ if (!available) return .{ .text = try ctx.gpa.dupe(u8, "rlm is off — pass --rlm or drop --old"), .is_error = true };
if (no_local_tools.enabled) return .{ .text = try ctx.gpa.dupe(u8, "rlm is a host tool and is disabled under --no-local-tools"), .is_error = true };
const code = tools.strField(input, "code") orelse return tools.missingArg(ctx.gpa, "code");
return runScript(ctx, code);
@@ -223,7 +233,7 @@ fn testCtx(gpa: Allocator, io: Io, client: *std.http.Client) ToolCtx {
};
}
-test "maybeAppend is a no-op until --rlm, and refuses to double-append" {
+test "maybeAppend is a no-op when --old, and refuses to double-append" {
const gpa = std.testing.allocator;
var arena_state = std.heap.ArenaAllocator.init(gpa);
defer arena_state.deinit();
diff --git a/src/rlm_spec.zig b/src/rlm_spec.zig
index d59720f6..04801795 100644
--- a/src/rlm_spec.zig
+++ b/src/rlm_spec.zig
@@ -1,6 +1,6 @@
//! Mid-stream spec-ptc cache for `rlm`. Leaf on purpose: the SSE / ArgLive
//! path must feed closed lines without importing exec.zig (that would cycle
-//! through Agent). `run_host` is installed by rlm.zig once `--rlm` is on.
+//! through Agent). `run_host` is installed by rlm.zig (`sync` / `setFromCli`).
const std = @import("std");
const Io = std.Io;
@@ -11,11 +11,11 @@ const tools = @import("tools.zig");
const ToolCtx = tools.ToolCtx;
const ToolOutput = tools.ToolOutput;
-pub var available: bool = false;
+pub var available: bool = true;
pub var run_host: ?*const fn (ToolCtx, spec_ptc.Call) ToolOutput = null;
/// Cheap discovery while the full spec stays folded (ADR 0022). Startup
-/// splices this only when `--rlm` is on.
+/// splices this only while `available` (off under `--old`).
///
/// Graff's rlm is a Zig subset of Prime Agent's programming model: assignments
/// persist across rlm calls (context as variables, not an IPython kernel), and
diff --git a/src/schema.zig b/src/schema.zig
index e6fd9171..2aac1d8a 100644
--- a/src/schema.zig
+++ b/src/schema.zig
@@ -535,13 +535,13 @@ test "effectiveRootSpecs: drops clock_sleep from the root tool catalog unless th
root.g_clock_sleep = false;
const off_specs = try effectiveRootSpecs(a);
- try std.testing.expectEqual(root_specs.len - 1, off_specs.len);
+ try std.testing.expectEqual(root_specs.len, off_specs.len); // -clock_sleep +rlm
for (off_specs) |t| try std.testing.expect(!std.mem.eql(u8, t.name, "clock_sleep"));
- try std.testing.expectEqual(@as(usize, 0), arena_state.queryCapacity());
+ try std.testing.expect(arena_state.queryCapacity() > 0); // maybeAppend copies to append rlm
root.g_clock_sleep = true;
const on_specs = try effectiveRootSpecs(a);
- try std.testing.expectEqual(root_specs.len, on_specs.len);
+ try std.testing.expectEqual(root_specs.len + 1, on_specs.len); // +rlm
var found = false;
for (on_specs) |t| {
if (std.mem.eql(u8, t.name, "clock_sleep")) found = true;
@@ -551,7 +551,7 @@ test "effectiveRootSpecs: drops clock_sleep from the root tool catalog unless th
root.g_clock_sleep = false;
learn_store.active_agent_loaded = false;
const minimal_specs = try effectiveRootSpecs(a);
- try std.testing.expectEqual(root_specs.len - 2, minimal_specs.len);
+ try std.testing.expectEqual(root_specs.len - 1, minimal_specs.len); // -clock -learn +rlm
for (minimal_specs) |tool| try std.testing.expect(!std.mem.eql(u8, tool.name, "learn_candidate"));
}
test "learn_candidate is root-only and cannot become a subagent tool" {
diff --git a/src/schema_protocol.zig b/src/schema_protocol.zig
index c12273b9..f350156c 100644
--- a/src/schema_protocol.zig
+++ b/src/schema_protocol.zig
@@ -15,6 +15,8 @@ pub const flags =
\\ {"flag": "--allow-cross-provider-subagents", "arg": null, "description": "explicitly consent to sending worker prompts, code, and tool results to a provider different from the root"},
\\ {"flag": "--no-subagent-tier", "arg": null, "description": "opt out of the default worker tier ladder; workers inherit the root model unless an explicit --subagent-model is given"},
\\ {"flag": "--yolo", "arg": null, "description": "skip all permission prompts for the session"},
+ \\ {"flag": "--rlm", "arg": null, "description": "advertise the rlm REPL (default). Last flag wins vs --old. GRAFF_RLM=1 is the env form"},
+ \\ {"flag": "--old", "arg": null, "description": "restore the pre-rlm structured-only catalog. --no-rlm is an alias. GRAFF_OLD=1 or GRAFF_RLM=0"},
\\ {"flag": "--lean", "arg": null, "description": "slim the tool surface to 8 core tools and connect MCP servers DEFERRED behind the load_tool_schemas meta tool (names + one-line descriptions up front, full schemas on demand) instead of paying every server's schemas in every model turn. DEFAULT for -p one-shots; GRAFF_LEAN=1 forces it on anywhere"},
\\ {"flag": "--no-lean", "arg": null, "description": "opt a one-shot out of the implied --lean: full tool surface and eager MCP schemas, the pre-default -p behavior"},
\\ {"flag": "--add-dir", "arg": "path", "description": "extra workspace root file tools may touch (repeatable, max 16). Complementary to workspace switch; extra roots do not contribute skills or sessions"},
diff --git a/src/session_settings.zig b/src/session_settings.zig
index 6bd64d34..fdb77903 100644
--- a/src/session_settings.zig
+++ b/src/session_settings.zig
@@ -113,10 +113,25 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {
if (environ_map.get("GRAFF_CLOCK_SLEEP")) |v| {
main_mod.g_clock_sleep = main_mod.g_clock_sleep or std.mem.eql(u8, v, "1") or std.ascii.eqlIgnoreCase(v, "true") or std.ascii.eqlIgnoreCase(v, "on") or std.ascii.eqlIgnoreCase(v, "yes");
}
- if (environ_map.get("GRAFF_RLM")) |v| {
+ {
+ // Always query so session_settings_tests can catch a dropped parse.
+ // CLI (`--rlm` / `--old`) wins: env must not clobber an explicit flag.
const rlm = @import("rlm.zig");
- rlm.available = rlm.available or std.mem.eql(u8, v, "1") or std.ascii.eqlIgnoreCase(v, "true") or std.ascii.eqlIgnoreCase(v, "on") or std.ascii.eqlIgnoreCase(v, "yes");
- rlm.sync();
+ const old_v = environ_map.get("GRAFF_OLD");
+ const rlm_v = environ_map.get("GRAFF_RLM");
+ if (!rlm.cli_set) {
+ if (old_v) |v| {
+ if (std.mem.eql(u8, v, "1") or std.ascii.eqlIgnoreCase(v, "true") or std.ascii.eqlIgnoreCase(v, "on") or std.ascii.eqlIgnoreCase(v, "yes"))
+ rlm.available = false;
+ }
+ if (rlm_v) |v| {
+ const off = std.mem.eql(u8, v, "0") or std.ascii.eqlIgnoreCase(v, "false") or std.ascii.eqlIgnoreCase(v, "off") or std.ascii.eqlIgnoreCase(v, "no");
+ const on = std.mem.eql(u8, v, "1") or std.ascii.eqlIgnoreCase(v, "true") or std.ascii.eqlIgnoreCase(v, "on") or std.ascii.eqlIgnoreCase(v, "yes");
+ if (off) rlm.available = false;
+ if (on) rlm.available = true; // GRAFF_RLM=1 wins over GRAFF_OLD=1
+ }
+ rlm.sync();
+ }
}
if (environ_map.get("GRAFF_NO_LOCAL_TOOLS")) |v| no_local_tools.enabled = no_local_tools.enabled or no_local_tools.envEnables(v);
// GRAFF_LEAN: presence-based, exactly matching session_start.leanSkipsMcp
diff --git a/src/session_settings_tests.zig b/src/session_settings_tests.zig
index e0228a55..9683a601 100644
--- a/src/session_settings_tests.zig
+++ b/src/session_settings_tests.zig
@@ -42,6 +42,7 @@ const knobs = [_]Knob{
.{ .name = "GRAFF_CODEX_WS", .value = "off" },
.{ .name = "GRAFF_CLOCK_SLEEP", .value = "1" },
.{ .name = "GRAFF_RLM", .value = "1" },
+ .{ .name = "GRAFF_OLD", .value = "1" },
.{ .name = "GRAFF_NO_LOCAL_TOOLS", .value = "1" },
.{ .name = "GRAFF_CODEX_WS_IDLE_SECS", .value = "11" },
.{ .name = "GRAFF_CONTEXT", .value = "123456" },
@@ -84,6 +85,7 @@ const Saved = struct {
codex_ws: bool,
clock_sleep: bool,
rlm: bool,
+ rlm_cli: bool,
stream_stall_ms: u64,
post_deadline_ms: u64,
codex_ws_idle_ms: i64,
@@ -106,6 +108,7 @@ const Saved = struct {
.codex_ws = main_mod.g_codex_ws,
.clock_sleep = main_mod.g_clock_sleep,
.rlm = @import("rlm.zig").available,
+ .rlm_cli = @import("rlm.zig").cli_set,
.stream_stall_ms = http.stream_stall_ms,
.post_deadline_ms = http.post_deadline_ms,
.codex_ws_idle_ms = agent_ws.codex_ws_idle_ms,
@@ -129,6 +132,7 @@ const Saved = struct {
main_mod.g_codex_ws = s.codex_ws;
main_mod.g_clock_sleep = s.clock_sleep;
@import("rlm.zig").available = s.rlm;
+ @import("rlm.zig").cli_set = s.rlm_cli;
@import("rlm.zig").sync();
http.stream_stall_ms = s.stream_stall_ms;
http.post_deadline_ms = s.post_deadline_ms;
@@ -176,6 +180,7 @@ test "applyEnvKnobs actually applies the values it reads" {
main_mod.g_codex_ws = true;
main_mod.g_clock_sleep = false;
@import("rlm.zig").available = false;
+ @import("rlm.zig").cli_set = false;
@import("rlm.zig").sync();
no_local_tools.enabled = false;
ws.g_debug = false;
@@ -204,3 +209,38 @@ test "applyEnvKnobs actually applies the values it reads" {
try std.testing.expectEqual(@as(u8, 3), ws.g_force_connect_failure_count);
try std.testing.expect(plugins.disabled);
}
+
+const PairEnv = struct {
+ pairs: []const Knob,
+ pub fn get(self: PairEnv, name: []const u8) ?[]const u8 {
+ for (self.pairs) |k| {
+ if (std.mem.eql(u8, k.name, name)) return k.value;
+ }
+ return null;
+ }
+};
+
+test "GRAFF_OLD / GRAFF_RLM=0 turn default rlm off; --old is not clobbered by env" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const saved = Saved.capture();
+ defer saved.restore();
+ const rlm = @import("rlm.zig");
+
+ rlm.available = true;
+ rlm.cli_set = false;
+ rlm.sync();
+ try session_settings.applyEnvKnobs(arena_state.allocator(), PairEnv{ .pairs = &.{.{ .name = "GRAFF_OLD", .value = "1" }} });
+ try std.testing.expect(!rlm.available);
+
+ rlm.available = true;
+ rlm.cli_set = false;
+ rlm.sync();
+ try session_settings.applyEnvKnobs(arena_state.allocator(), PairEnv{ .pairs = &.{.{ .name = "GRAFF_RLM", .value = "0" }} });
+ try std.testing.expect(!rlm.available);
+
+ rlm.setFromCli(false);
+ try session_settings.applyEnvKnobs(arena_state.allocator(), PairEnv{ .pairs = &.{.{ .name = "GRAFF_RLM", .value = "1" }} });
+ try std.testing.expect(!rlm.available);
+ try std.testing.expect(rlm.cli_set);
+}
diff --git a/src/spec_catalog_conformance.zig b/src/spec_catalog_conformance.zig
index 68d05c13..48e73f68 100644
--- a/src/spec_catalog_conformance.zig
+++ b/src/spec_catalog_conformance.zig
@@ -53,18 +53,26 @@ test "spec/tool_catalog: implementation matches executable semantics" {
var parsed = try std.json.parseFromSlice(std.json.Value, gpa, fixtures_json, .{});
defer parsed.deinit();
+ const rlm = @import("rlm.zig");
const saved_local = no_local_tools.enabled;
const saved_lean = no_local_tools.lean;
const saved_img = imagegen.available;
const saved_clock = root.g_clock_sleep;
const saved_learn = learn_store.active_agent_loaded;
+ const saved_rlm = rlm.available;
defer {
no_local_tools.enabled = saved_local;
no_local_tools.lean = saved_lean;
imagegen.available = saved_img;
root.g_clock_sleep = saved_clock;
learn_store.active_agent_loaded = saved_learn;
+ rlm.available = saved_rlm;
+ rlm.sync();
}
+ // The 64-cell kernel is the structured catalog (`--old`). rlm is a
+ // session overlay (ADR 0022) and must not grow this cube.
+ rlm.available = false;
+ rlm.sync();
const cases = parsed.value.object.get("cases").?.array.items;
try std.testing.expect(cases.len == 64);