Skip to content

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

Python

feat(prompt): pin standing goal in the prefix; add on-demand jspace skill

Cursor Agentd93214eb7fb7
diff --git a/assets/skills/jspace.md b/assets/skills/jspace.md
new file mode 100644
index 00000000..5b22bce2
--- /dev/null
+++ b/assets/skills/jspace.md
@@ -0,0 +1,49 @@
+---
+name: jspace
+description: Long-horizon working-set control. Use when a multi-file task drifts, retries blindly, or claims done without a verifier.
+---
+
+# jspace
+
+A tiny active set. Pull the rest. This is graff's protocol, not a third-party
+suite: do not paste rooms, rosters, or playbooks into every turn.
+
+## Gate
+
+Pick one pass and stay on it:
+
+- **fast** — one checkable step. Do it. No extra machinery.
+- **full** — a few dependent steps, one deliverable. Keep one live item.
+- **loop** — many files, tools, or turns. Use the ledger below.
+
+Do not load this skill's advice twice. Do not invent slash commands.
+
+## Ledger (loop only)
+
+Hold five facts, nothing else. Prefer `todo_write` so they survive compact:
+
+- **Goal** — what done means (already in the system prompt if `--goal` / `/goal` is set)
+- **Core** — the one constraint or name every edit must see
+- **Verified** — what a named check already proved
+- **Open** — unknowns, each with a next probe
+- **Next** — the single next action
+
+When compact runs, re-read Goal and Open from the harness restatement. Do not
+re-derive them from memory.
+
+## Peers
+
+Co-resident sessions are pull. `peer_message action=list` who is live;
+`action=inbox` to read parked inbound; default send to ping. Do not treat a
+`[peer]` wake as the human. Do not dump the JSONL room into history.
+
+## Verify before done
+
+A fluent answer is not completion. `attempt_completion` only after a named
+verifier covers the Goal (test, read-back, or the user's accept). A failed
+tool call retries with the diagnosis, not a blank repeat.
+
+## Density
+
+Think in short internal notes if you must; speak to the user in full
+sentences. Never leak shorthand into files or commits.
diff --git a/build.zig b/build.zig
index eddd27a8..aa34267a 100644
--- a/build.zig
+++ b/build.zig
@@ -129,6 +129,7 @@ pub fn build(b: *std.Build) void {
for ([_]struct { import: []const u8, path: []const u8 }{
.{ .import = "skill_doc_creator", .path = "assets/skills/skill-creator.md" },
.{ .import = "skill_doc_mcp_config", .path = "assets/skills/mcp-config.md" },
+ .{ .import = "skill_doc_jspace", .path = "assets/skills/jspace.md" },
}) |asset| {
exe.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
diff --git a/docs/adr/0005-standing-goal-lives-in-the-prefix.md b/docs/adr/0005-standing-goal-lives-in-the-prefix.md
new file mode 100644
index 00000000..ed041e5d
--- /dev/null
+++ b/docs/adr/0005-standing-goal-lives-in-the-prefix.md
@@ -0,0 +1,31 @@
+# 0005. Standing goal lives in the prefix; user-message steering is change-only
+
+Status: accepted 2026-08-18
+
+## Context
+
+#318 restates `--goal` so the model cannot forget it. The implementation
+injected a long todo-coaching essay on the **user** turn, then refreshed it
+every 8 turns. That is the opposite of a prompt-cache prefix: the essay
+ages out of the cached head and re-enters as a suffix, paying again.
+
+J-Space's useful rule (tiny active set, pull the rest) is the same cut
+ADR 0004 applied to peer speech. The standing objective is a single fact
+the prefix can hold. The essay is onboarding, not a heartbeat.
+
+## Decision
+
+- A one-line `[standing goal: …]` rides the system-prompt funnel
+ (`pinStandingGoal`). Startup and compact re-compose for free; `/goal`
+ change busts the prefix once.
+- `steeringGate` still injects the long essay on first sight and on
+ objective change. `refresh_turns` is 0: no timed re-paste.
+- Long-horizon control beyond that is the bundled `jspace` skill, loaded
+ on demand. Do not vendor a third-party suite into the resident catalog.
+
+## Consequences
+
+- `--goal` still reaches every request (the prefix is on every request).
+- A paused or cleared goal disappears from the prefix.
+- Revisit if a provider ignores the system prompt; then the essay would
+ have to return as a user-turn inject.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index f9622e13..b73dcadd 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -15,6 +15,7 @@ record only when you need the evidence or the edge cases.
| [0002](0002-xai-defaults-to-the-responses-wire.md) | xAI runs on the Responses wire by default (WS turns, lossless server compaction). `GRAFF_XAI_WIRE=chat` opts out; WS stays an explicit provider list. |
| [0003](0003-codegraff-wire-follows-model-capability.md) | Codegraff uses Responses + WS for GPT-5.6 and grok-4.6 aliases; Claude, Gemini, and other aliases stay on Chat Completions. |
| [0004](0004-peer-speech-is-a-working-set.md) | Peer speech is pull: a one-line `[peer]` wake in history, bodies in the inbox ring; compact drops spent injects and never treats them as the human. |
+| [0005](0005-standing-goal-lives-in-the-prefix.md) | Standing goal is one prefix line; the user-message essay injects on change only, never every N turns. |
## When to write one
diff --git a/src/commands_session.zig b/src/commands_session.zig
index 8637635a..5638809a 100644
--- a/src/commands_session.zig
+++ b/src/commands_session.zig
@@ -101,6 +101,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
root.todos.clearRetainingCapacity();
const had_goal = root.goal != null;
resetConversationSteering(root);
+ prompts.pinStandingGoal(root, arena);
prompts.resetSessionCompacted(root, arena); // #445: the save below empties the file the #410 line names
saveSession(root, arena, root.session_name) catch {};
setTerminalTitle(out, "Chat", main_mod.g_cwd_display);
@@ -117,6 +118,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
root.compact_transport_failures = 0;
root.todos.clearRetainingCapacity();
resetConversationSteering(root);
+ prompts.pinStandingGoal(root, arena);
root.session_title = null;
root.ai_title_done = false; // let the new session earn its own AI title
root.title_generation +%= 1;
@@ -168,6 +170,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
root.goal = null; // the checklist PARKS with the goal (#318): items keep their epoch and stay in the session, they just stop being current
goal_state.resetCompletionGate(root);
root.goal_note_fp = 0;
+ prompts.pinStandingGoal(root, arena);
if (root.tracer) |t| t.note("goal", "cleared");
saveSession(root, arena, root.session_name) catch {};
if (open > 0) {
@@ -178,6 +181,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
if (root.goal) |*g| {
g.status = .paused;
g.updated_ms = unixMs(root.io);
+ prompts.pinStandingGoal(root, arena);
saveSession(root, arena, root.session_name) catch {};
try out.print("Goal paused: {s} - turns no longer get goal steering. /goal resume to continue.\n", .{g.objective});
} else try out.writeAll("No active goal to pause. Set one with /goal <objective>.\n");
@@ -186,6 +190,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
g.status = .active;
g.updated_ms = unixMs(root.io);
root.goal_note_fp = 0; // re-state the note on the next turn, not a stale-suppressed repeat
+ prompts.pinStandingGoal(root, arena);
saveSession(root, arena, root.session_name) catch {};
try out.print("\xf0\x9f\x8e\xaf Goal resumed: {s} - steering every turn again.\n", .{g.objective});
} else try out.writeAll("No goal to resume. Set one with /goal <objective>.\n");
@@ -194,6 +199,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
// adopt-or-supersede, gate + fingerprint resets) is
// goal_flow.applyGoalSet; this handler only reports it.
const res = goal_flow.applyGoalSet(root, try arena.dupe(u8, text), unixMs(root.io));
+ prompts.pinStandingGoal(root, arena);
if (res.superseded) |old| {
// Replacement is a supersession boundary (#318): the old
// checklist parks (retained, no longer current) and a one-shot
diff --git a/src/goal_state.zig b/src/goal_state.zig
index 17aca1a5..670d388f 100644
--- a/src/goal_state.zig
+++ b/src/goal_state.zig
@@ -187,8 +187,10 @@ pub fn resetCompletionGate(root: *Agent) void {
}
/// Re-state an unchanged active note after this many suppressed turns, in case
-/// the last statement aged out of the model's effective attention.
+/// LoopListGate: re-paste an unchanged /loop checklist after this many quiet turns.
pub const refresh_turns: u32 = 8;
+/// Standing-goal essay. 0 = never; the objective lives in the prefix (ADR 0005).
+pub const essay_refresh_turns: u32 = 0;
pub const SteeringGate = struct { inject: bool, fp: u64, age: u32 };
@@ -198,7 +200,8 @@ pub const SteeringGate = struct { inject: bool, fp: u64, age: u32 };
pub fn steeringGate(note: []const u8, last_fp: u64, age: u32, refresh_every: u32) SteeringGate {
if (note.len == 0) return .{ .inject = false, .fp = 0, .age = 0 };
const fp = std.hash.Wyhash.hash(0, note);
- if (fp != last_fp or age + 1 >= refresh_every) return .{ .inject = true, .fp = fp, .age = 0 };
+ if (fp != last_fp) return .{ .inject = true, .fp = fp, .age = 0 };
+ if (refresh_every > 0 and age + 1 >= refresh_every) return .{ .inject = true, .fp = fp, .age = 0 };
return .{ .inject = false, .fp = fp, .age = age + 1 };
}
@@ -209,7 +212,7 @@ pub fn applyGoalSteering(arena: Allocator, root: *Agent, base: []const u8) ![]co
if (root.review_mode) return base;
var msg = base;
const note = try repl_glue.goalSteeringNote(arena, root.goal);
- const gate = steeringGate(note, root.goal_note_fp, root.goal_note_age, refresh_turns);
+ const gate = steeringGate(note, root.goal_note_fp, root.goal_note_age, essay_refresh_turns);
root.goal_note_fp = gate.fp;
root.goal_note_age = gate.age;
if (gate.inject) msg = try std.fmt.allocPrint(arena, "{s}\n\n{s}", .{ msg, note });
@@ -519,7 +522,10 @@ test "steeringGate: inject on change, suppress repeats, refresh after the interv
// Changed note (new objective/epoch): inject again.
const g3 = steeringGate("[standing goal: y]", g2.fp, g2.age, 8);
try std.testing.expect(g3.inject);
- // Refresh interval lapse re-states an unchanged note.
+ // refresh_every 0 never time-refreshes (ADR 0005: prefix holds the objective).
+ const held = steeringGate("[standing goal: y]", g3.fp, 99, 0);
+ try std.testing.expect(!held.inject and held.age == 100);
+ // A non-zero interval still re-states when it lapses.
const g4 = steeringGate("[standing goal: y]", g3.fp, 7, 8);
try std.testing.expect(g4.inject and g4.age == 0);
}
diff --git a/src/prompt_snapshot_tests.zig b/src/prompt_snapshot_tests.zig
index 6faa242d..a0814d06 100644
--- a/src/prompt_snapshot_tests.zig
+++ b/src/prompt_snapshot_tests.zig
@@ -588,3 +588,30 @@ test "unattended one-shots are told the REAL approval map up front; attended ses
try std.testing.expect(std.mem.indexOf(u8, unattended, "--yolo") != null);
try std.testing.expect(std.mem.indexOf(u8, unattended, ".harness/settings.json") != null);
}
+
+test "pinStandingGoal: active objective rides the prefix; paused and cleared disarm" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const a = arena_state.allocator();
+ const playbook = @import("playbook.zig");
+ const saved = playbook.g_root_inject;
+ playbook.g_root_inject = false; // composeRoot would need a live io
+ defer playbook.g_root_inject = saved;
+ var agent: agent_mod.Agent = undefined;
+ agent.goal = null;
+ defer {
+ agent.goal = null;
+ prompts.pinStandingGoal(&agent, a);
+ }
+ try prompts.setSystemPrompts(&agent, "BASE", a);
+ try std.testing.expect(std.mem.indexOf(u8, agent.sys_normal, "[standing goal:") == null);
+ agent.goal = .{ .objective = "keep the build green", .status = .active };
+ prompts.pinStandingGoal(&agent, a);
+ try std.testing.expect(std.mem.indexOf(u8, agent.sys_normal, "[standing goal: keep the build green]") != null);
+ try std.testing.expect(std.mem.indexOf(u8, agent.sys_normal, "BASE") != null);
+ agent.goal = .{ .objective = "keep the build green", .status = .paused };
+ prompts.pinStandingGoal(&agent, a);
+ try std.testing.expect(std.mem.indexOf(u8, agent.sys_normal, "[standing goal:") == null);
+ agent.goal = null;
+ prompts.pinStandingGoal(&agent, a);
+}
diff --git a/src/prompts.zig b/src/prompts.zig
index 10ec777f..b934571a 100644
--- a/src/prompts.zig
+++ b/src/prompts.zig
@@ -197,6 +197,7 @@ pub fn baseForSession(arena: Allocator) ![]const u8 {
/// a persona swap cannot drop it. Empty for every non-root agent and every
/// unit test — the same arming discipline playbook.g_root_inject uses.
var g_transcript_note: []const u8 = "";
+var g_goal_line: []const u8 = ""; // ADR 0005: one prefix line; essay is change-only
/// #445: has THIS process's root session compacted at least once? False at
/// startup, set once by noteSessionCompacted, never lowered again. Public only
@@ -318,12 +319,30 @@ pub fn setSystemPrompts(agent: *Agent, base: []const u8, arena: Allocator) !void
// persona, so it re-composes here rather than being baked into a base a
// later set_agent/set_system_prompt would replace (the #326 staleness class).
const composed = if (g_transcript_note.len == 0) with_notes else try std.fmt.allocPrint(arena, "{s}{s}", .{ with_notes, g_transcript_note });
- agent.sys_normal = composed;
- agent.sys_strict = try std.fmt.allocPrint(arena, "{s}{s}", .{ composed, strict_note });
- agent.sys_ultra = try std.fmt.allocPrint(arena, "{s}{s}", .{ composed, ultracode_system_note });
+ const with_goal = if (g_goal_line.len == 0) composed else try std.fmt.allocPrint(arena, "{s}{s}", .{ composed, g_goal_line });
+ agent.sys_normal = with_goal;
+ agent.sys_strict = try std.fmt.allocPrint(arena, "{s}{s}", .{ with_goal, strict_note });
+ agent.sys_ultra = try std.fmt.allocPrint(arena, "{s}{s}", .{ with_goal, ultracode_system_note });
agent.sys_ultra_strict = try std.fmt.allocPrint(arena, "{s}{s}", .{ agent.sys_strict, ultracode_system_note });
}
+/// Pin the live objective into the system-prompt prefix. Empty / paused /
+/// cleared goals disarm the line so a dead goal cannot keep paying tokens.
+/// Re-compose is free at startup (before the first request) and at compact
+/// (#445); a mid-session /goal change busts the prefix once, which is cheaper
+/// than restating the essay every eighth user turn.
+pub fn pinStandingGoal(agent: *Agent, arena: Allocator) void {
+ g_goal_line = "";
+ if (agent.goal) |g| {
+ if (g.status == .active and g.objective.len > 0) {
+ const obj = if (g.objective.len <= 120) g.objective else g.objective[0..120];
+ g_goal_line = std.fmt.allocPrint(arena, "\n\n[standing goal: {s}]\n", .{obj}) catch "";
+ }
+ }
+ if (agent.sys_base.len == 0) return;
+ setSystemPrompts(agent, agent.sys_base, arena) catch {};
+}
+
/// The ROOT's entry to the same funnel, called once by session_run when the
/// root agent is built. Arming here rather than at a global switch keeps the
/// filesystem read strictly on the one code path that has a real session
diff --git a/src/session_run.zig b/src/session_run.zig
index caece926..e44eefc7 100644
--- a/src/session_run.zig
+++ b/src/session_run.zig
@@ -316,6 +316,7 @@ pub fn buildRootAgent(
if (flags.goal_flag) |g| { // --goal is STANDING (#318): every turn (incl. --json/-p/SDK), never model-retired
root.goal_flag = try arena.dupe(u8, g); // kept: re-applied over every loadSession, incl. /resume
root.goal = goal_flow.standingGoalFromFlag(root.goal_flag.?, null, root.todos.items, util.unixMs(io));
+ prompts.pinStandingGoal(&root, arena); // ADR 0005: prefix, not an 8-turn user-message refresh
}
// #469: register this root session so co-resident graffs see it (and it
// them) BEFORE anyone touches the shared tree — a live co-owner is named
@@ -371,7 +372,10 @@ pub fn saveOrResumeSession(root: *agent_mod.Agent, keys: *provider_mod.Keys, are
if (flags.oneshot_prompt != null and flags.resume_flag != null and !flags.new_session_flag and !flags.no_resume_flag) {
session.loadSession(root, keys, arena, root.session_name) catch {};
// loadSession overwrote root.goal; the flag wins, idempotently (#318).
- if (root.goal_flag) |g| root.pending_goal_note = goal_flow.reapplyFlagGoal(arena, root, g, util.unixMs(root.io)) catch null;
+ if (root.goal_flag) |g| {
+ root.pending_goal_note = goal_flow.reapplyFlagGoal(arena, root, g, util.unixMs(root.io)) catch null;
+ prompts.pinStandingGoal(root, arena);
+ }
}
}
@@ -385,7 +389,10 @@ pub fn restoreResumedSession(arena: Allocator, out: *Io.Writer, root: *agent_mod
if (!(flags.oneshot_prompt == null and flags.resume_flag != null and !flags.new_session_flag and !flags.no_resume_flag)) return;
if (session.loadSession(root, keys, arena, root.session_name)) |_| {
// --goal outranks the restored goal here too, idempotently (#318).
- if (root.goal_flag) |g| root.pending_goal_note = goal_flow.reapplyFlagGoal(arena, root, g, util.unixMs(root.io)) catch null;
+ if (root.goal_flag) |g| {
+ root.pending_goal_note = goal_flow.reapplyFlagGoal(arena, root, g, util.unixMs(root.io)) catch null;
+ prompts.pinStandingGoal(root, arena);
+ }
if (root.messages.items.len > 0) {
if (!json_mode) {
// Prefer the saved AI summary; fall back to the first user
diff --git a/src/skill_docs.zig b/src/skill_docs.zig
index 9e510b77..b0ab60d3 100644
--- a/src/skill_docs.zig
+++ b/src/skill_docs.zig
@@ -9,9 +9,9 @@
//! like fleet.zig's agent personas — bundled < personal < project — and
//! disclosure is progressive: only the descriptions ride in the system prompt
//! (promptCatalog), while bodies stay on disk until the `skill` tool loads one
-//! (execSkill). Two skills are embedded in the binary so a fresh install
-//! already knows how to write more (skill-creator) and how to change MCP
-//! config (mcp-config).
+//! (execSkill). Three skills are embedded in the binary so a fresh install
+//! already knows how to write more (skill-creator), how to change MCP
+//! config (mcp-config), and how to run a long-horizon working set (jspace).
const std = @import("std");
const Io = std.Io;
@@ -63,7 +63,7 @@ const desc_cap = 160; // per-skill description budget in the system prompt — t
/// a schema.ToolSpec) so schema.zig's catalog needs one entry and no import
/// cycle. The description must stay free of characters needing JSON escapes.
pub const tool_name = "skill";
-pub const tool_desc = "Load a skill: the full instructions for one kind of task, kept out of your context until you need them. The system prompt lists only skill names and descriptions, so call this to read the body BEFORE doing work a skill covers, then follow it. Omit name to list every available skill. Skills come from .harness/skills/ (this project), ~/.harness/skills/ (yours), .claude/skills/, plus two bundled ones: skill-creator (write and install a new skill) and mcp-config (inspect or change this workspace's MCP servers).";
+pub const tool_desc = "Load a skill: the full instructions for one kind of task, kept out of your context until you need them. The system prompt lists only skill names and descriptions, so call this to read the body BEFORE doing work a skill covers, then follow it. Omit name to list every available skill. Skills come from .harness/skills/ (this project), ~/.harness/skills/ (yours), .claude/skills/, plus bundled skill-creator, mcp-config, and jspace.";
pub const tool_schema =
\\{"type": "object", "properties": {"name": {"type": "string", "description": "Skill name to load; omit to list every available skill"}}}
;
@@ -98,6 +98,7 @@ const Embedded = struct { fallback: []const u8, bytes: []const u8 };
const embedded = [_]Embedded{
.{ .fallback = "skill-creator", .bytes = @embedFile("skill_doc_creator") },
.{ .fallback = "mcp-config", .bytes = @embedFile("skill_doc_mcp_config") },
+ .{ .fallback = "jspace", .bytes = @embedFile("skill_doc_jspace") },
};
/// Skills compiled into the binary: every install has these, no files needed.
@@ -324,9 +325,10 @@ test "parseDoc: no frontmatter keeps the filename and the whole file as body" {
}
test "bundled skills: both parse at comptime with a trigger description" {
- try std.testing.expectEqual(@as(usize, 2), builtins.len);
+ try std.testing.expectEqual(@as(usize, 3), builtins.len);
try std.testing.expectEqualStrings("skill-creator", builtins[0].name);
try std.testing.expectEqualStrings("mcp-config", builtins[1].name);
+ try std.testing.expectEqualStrings("jspace", builtins[2].name);
for (builtins) |sk| {
try std.testing.expect(sk.desc.len > 40); // a trigger, not a topic word
try std.testing.expect(sk.body.len > 500);
@@ -338,12 +340,14 @@ test "bundled skills: both parse at comptime with a trigger description" {
try std.testing.expect(std.mem.indexOf(u8, builtins[0].body, project_dir) != null);
try std.testing.expect(std.mem.indexOf(u8, builtins[1].body, ".mcp.json") != null);
try std.testing.expect(std.mem.indexOf(u8, builtins[1].body, "/mcp trust") != null);
+ try std.testing.expect(std.mem.indexOf(u8, builtins[2].body, "action=inbox") != null);
}
test "tool_desc stays JSON-escape-free (it is spliced into a raw schema string)" {
for (tool_desc) |c| try std.testing.expect(c != '"' and c != '\\' and c >= 0x20);
try std.testing.expect(std.mem.indexOf(u8, tool_desc, "skill-creator") != null);
try std.testing.expect(std.mem.indexOf(u8, tool_desc, "mcp-config") != null);
+ try std.testing.expect(std.mem.indexOf(u8, tool_desc, "jspace") != null);
}
test "insert: a later tier shadows the same name, others append" {