graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
perf(plugins): Codex .codex-plugin and a cache-stable skill prefix
Cursor Agentfcc3ef9354b8
diff --git a/docs/adr/0007-plugins-are-read-in-place.md b/docs/adr/0007-plugins-are-read-in-place.mdindex 2a9b37d0..7dd6a7bd 100644--- a/docs/adr/0007-plugins-are-read-in-place.md+++ b/docs/adr/0007-plugins-are-read-in-place.md@@ -22,7 +22,11 @@ config.globs named skill trees; grok-build lists immediate children). `cache/` and`marketplaces/` are not walked. Cache installs come from Claude/Cursor`installed_plugins.json` `installPath` entries, the same index grok-build- reads. A directory is a plugin if it has `.cursor-plugin/plugin.json`,+ reads. Codex installs live under `~/.codex/plugins/cache/` via its store,+ not a walk; we take `.codex/plugins/installed_plugins.json` when present+ and recognize `.codex-plugin/plugin.json` first (Codex's manifest order).+ A directory is a plugin if it has `.codex-plugin/plugin.json`,+ `.cursor-plugin/plugin.json`,`.claude-plugin/plugin.json`, `.grok-plugin/plugin.json`, `plugin.json`,`.mcp.json`, `mcp.json`, `skills/`, `agents/`, Claude's `commands/`, or aroot `SKILL.md`. The listing name comes from the registry key or the@@ -52,9 +56,12 @@ config.- Discover classifies with one readdir per visited directory (not a stat permarker) and stores skill/agent dirs on the plugin so later merges do notinspect again. MCP merge only opens plugin trees that already have MCP.- The skill catalog reads an 8 KB frontmatter prefix (name + description);- bodies stay on disk until `skill name=`. A named load hits the session- catalog and then reads that one file; a miss or a list still rescans.+ The skill catalog reads an 8 KB frontmatter prefix (name + description),+ sorts by name, and omits file paths so the system-prompt prefix is+ byte-stable for prompt cache (Codex's rule: the old prompt is an exact+ prefix of the new one). Bodies stay on disk until `skill name=`. A named+ load hits the session catalog and then reads that one file; a miss or a+ list still rescans without rewriting the prefix.Production caches the first walk (MCP + fleet + skills share it); testsdo not. `/plugins` and the interactive boot line print wall time so aslow home directory is visible. A plugin that lives only under `cache/`diff --git a/src/plugin_layout.zig b/src/plugin_layout.zigindex 423a592d..f383347c 100644--- a/src/plugin_layout.zig+++ b/src/plugin_layout.zig@@ -16,7 +16,9 @@ const Allocator = std.mem.Allocator;const file_cap: std.Io.Limit = .limited(1 << 20);const reserved = "smolify";+/// Codex's order: `.codex-plugin` first, then Claude, then Cursor.const manifest_files = [_][]const u8{+ ".codex-plugin/plugin.json",".claude-plugin/plugin.json",".cursor-plugin/plugin.json",".grok-plugin/plugin.json",@@ -172,6 +174,7 @@ pub fn inspect(io: Io, arena: Allocator, plugin_path: []const u8) Layout {var has_commands = false;var has_mcp = false;var saw_root_skill = false;+ var saw_codex = false;var saw_claude = false;var saw_cursor = false;var saw_grok = false;@@ -193,6 +196,8 @@ pub fn inspect(io: Io, arena: Allocator, plugin_path: []const u8) Layout {saw_root_skill = true;} else if (std.mem.eql(u8, entry.name, "mcp.json") or std.mem.eql(u8, entry.name, ".mcp.json")) {has_mcp = true;+ } else if (std.mem.eql(u8, entry.name, ".codex-plugin")) {+ saw_codex = true;} else if (std.mem.eql(u8, entry.name, ".claude-plugin")) {saw_claude = true;} else if (std.mem.eql(u8, entry.name, ".cursor-plugin")) {@@ -204,7 +209,7 @@ pub fn inspect(io: Io, arena: Allocator, plugin_path: []const u8) Layout {}}- const manifest_rel: ?[]const u8 = if (saw_claude) ".claude-plugin/plugin.json" else if (saw_cursor) ".cursor-plugin/plugin.json" else if (saw_grok) ".grok-plugin/plugin.json" else if (saw_plugin_json) "plugin.json" else null;+ const manifest_rel: ?[]const u8 = if (saw_codex) ".codex-plugin/plugin.json" else if (saw_claude) ".claude-plugin/plugin.json" else if (saw_cursor) ".cursor-plugin/plugin.json" else if (saw_grok) ".grok-plugin/plugin.json" else if (saw_plugin_json) "plugin.json" else null;const manifest = if (manifest_rel) |rel| readOneManifest(io, arena, plugin_path, rel) else null;if (manifest) |v| {collectPaths(arena, &skills, io, plugin_path, v.object.get("skills"));@@ -285,6 +290,14 @@ test "inspect: commands/ and root SKILL.md follow Claude defaults" {try testing.expect(lone_lay.root_skill != null);try testing.expectEqualStrings("solo", lone_lay.root_skill.?.name);try testing.expectEqual(@as(usize, 0), lone_lay.skill_dirs.len);++ const cx = join(arena, base, "host");+ try Io.Dir.cwd().createDirPath(io, join(arena, cx, ".codex-plugin"));+ try Io.Dir.cwd().createDirPath(io, join(arena, cx, "skills"));+ try Io.Dir.cwd().writeFile(io, .{ .sub_path = join(arena, cx, ".codex-plugin/plugin.json"), .data = "{\"name\":\"host\"}" });+ const cx_lay = inspect(io, arena, cx);+ try testing.expectEqualStrings("host", cx_lay.name);+ try testing.expectEqual(@as(usize, 1), cx_lay.skill_dirs.len);}test "mergeMcp: inline servers expand CLAUDE_PLUGIN_ROOT; extra file paths work" {diff --git a/src/plugins.zig b/src/plugins.zigindex 82bf599d..45885b4d 100644--- a/src/plugins.zig+++ b/src/plugins.zig@@ -64,7 +64,8 @@ fn skipped(name: []const u8) bool {/// True when this directory entry is enough to treat the parent as a plugin,/// so the walk does not `stat` ten marker paths per visited folder.fn pluginMarker(name: []const u8) bool {- return std.mem.eql(u8, name, ".cursor-plugin") or+ return std.mem.eql(u8, name, ".codex-plugin") or+ std.mem.eql(u8, name, ".cursor-plugin") orstd.mem.eql(u8, name, ".claude-plugin") orstd.mem.eql(u8, name, ".grok-plugin") orstd.mem.eql(u8, name, "plugin.json") or@@ -178,6 +179,7 @@ pub fn discoverFresh(io: Io, arena: Allocator, home: ?[]const u8, project: Io.Di}takeInstalled(io, arena, &list, join(arena, h, ".claude/plugins/installed_plugins.json"), "claude", true, cwd);takeInstalled(io, arena, &list, join(arena, h, ".cursor/plugins/installed_plugins.json"), "cursor", true, cwd);+ takeInstalled(io, arena, &list, join(arena, h, ".codex/plugins/installed_plugins.json"), "codex", true, cwd);};if (cwd.len > 0) {for (project_roots) |spec| {@@ -185,6 +187,7 @@ pub fn discoverFresh(io: Io, arena: Allocator, home: ?[]const u8, project: Io.Di}takeInstalled(io, arena, &list, join(arena, cwd, ".claude/plugins/installed_plugins.json"), "claude", false, cwd);takeInstalled(io, arena, &list, join(arena, cwd, ".cursor/plugins/installed_plugins.json"), "cursor", false, cwd);+ takeInstalled(io, arena, &list, join(arena, cwd, ".codex/plugins/installed_plugins.json"), "codex", false, cwd);}last_visits = visits;return list.items;diff --git a/src/skill_docs.zig b/src/skill_docs.zigindex 897f3e9c..785539bd 100644--- a/src/skill_docs.zig+++ b/src/skill_docs.zig@@ -123,10 +123,9 @@ pub const builtins = blk: {break :blk out;};-/// This session's skills, in precedence order — loaded from the session arena-/// each time startup.buildSystemPrompt composes a prompt. Read by the system-/// prompt and `/skills`; the tool itself rescans instead, so a skill written-/// mid-session is loadable without a restart.+/// This session's skills, in precedence order — loaded once into the+/// system-prompt prefix at session start (prompt-cache stability). `/skills`+/// and a named `skill` miss rescan without rewriting that prefix.pub var g_skills: []const Skill = &builtins;/// Resolved HOME for the personal tier, so execSkill's rescan finds the same/// set the startup scan did.@@ -265,13 +264,24 @@ fn dropDisabled(list: *std.ArrayList(Skill), cfg: std.json.ObjectMap) void {}/// The progressive-disclosure catalog for the system prompt: one line per-/// skill, names + trigger descriptions only. "" when there's nothing to-/// advertise (every skill disabled).+/// skill, names + trigger descriptions only. Sorted by name so a rebuild+/// cannot shuffle the cached prefix (Codex's rule: the old prompt must be+/// an exact prefix of the new one). No file paths — Codex prints those and+/// they bust the first 256-token cache hash when a plugin moves. "" when+/// there's nothing to advertise.pub fn promptCatalog(arena: Allocator, list: []const Skill) []const u8 {if (list.len == 0) return "";+ const order = arena.alloc(usize, list.len) catch return "";+ for (order, 0..) |*o, i| o.* = i;+ std.mem.sort(usize, order, list, struct {+ fn lessThan(ctx: []const Skill, a: usize, b: usize) bool {+ return std.mem.order(u8, ctx[a].name, ctx[b].name) == .lt;+ }+ }.lessThan);var aw: Io.Writer.Allocating = .init(arena);- aw.writer.writeAll("# Skills\nInstalled playbooks; only triggers are listed here. Call `skill` with a name to load the full instructions — do that BEFORE starting work it covers. A loaded skill is the user's own instructions. `skill` with no name re-lists, including any added this session.\n") catch return "";- for (list) |sk| {+ aw.writer.writeAll("# Skills\nName + trigger only. `skill name=` loads the body. `skill` with no name re-lists, including any added this session.\n") catch return "";+ for (order) |i| {+ const sk = list[i];aw.writer.print("- {s} ({s}): {s}\n", .{ sk.name, sk.source.label(), util.utf8Prefix(sk.desc, desc_cap) }) catch return "";}return aw.writer.buffered();@@ -430,7 +440,17 @@ test "promptCatalog: names + descriptions only, never bodies" {try std.testing.expect(std.mem.indexOf(u8, text, "deploy (project): ship a release") != null);try std.testing.expect(std.mem.indexOf(u8, text, "SECRET-BODY-TEXT") == null);try std.testing.expect(std.mem.indexOf(u8, text, "`skill`") != null);+ try std.testing.expect(std.mem.indexOf(u8, text, "/") == null); // no file paths — they move and bust the cache prefixtry std.testing.expectEqualStrings("", promptCatalog(arena, &.{}));++ const shuffled = [_]Skill{+ .{ .name = "zeta", .desc = "z", .body = "", .source = .personal },+ .{ .name = "alpha", .desc = "a", .body = "", .source = .plugin },+ };+ const ordered = promptCatalog(arena, &shuffled);+ const alpha_at = std.mem.indexOf(u8, ordered, "alpha (plugin)") orelse return error.TestUnexpectedResult;+ const zeta_at = std.mem.indexOf(u8, ordered, "zeta (personal)") orelse return error.TestUnexpectedResult;+ try std.testing.expect(alpha_at < zeta_at);}test "promptCatalog: an over-long description is capped on a codepoint boundary" {diff --git a/src/startup.zig b/src/startup.zigindex 49a1ffd8..277bf3df 100644--- a/src/startup.zig+++ b/src/startup.zig@@ -146,10 +146,10 @@ pub fn buildSystemPrompt(try out.print("imagegen: Codex skill found — tool enabled ({s}), playbook at {s}\n", .{ imagegen.engineSummary(), imagegen.skill_dir });try out.flush();}- // Markdown skills (skill_docs.zig): names + trigger descriptions only. The- // bodies stay on disk until the model calls the `skill` tool, so a large- // installed skill set costs a line each rather than its full text. Loaded- // here rather than in session_run so every prompt rebuild rescans the tiers.+ // Markdown skills (skill_docs.zig): names + trigger descriptions only.+ // Pinned once into the system-prompt prefix so later turns hit the+ // prompt cache (Codex: old prompt is an exact prefix of the new one).+ // The `skill` tool rescans without rewriting this prefix.skill_docs.g_skills = skill_docs.load(io, arena, fleet.g_home);const skill_catalog = skill_docs.promptCatalog(arena, skill_docs.g_skills);if (skill_catalog.len > 0) {