Skip to content

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

Python

perf(plugins): do not walk cache; read installed_plugins.json

Cursor Agente9725376259a
diff --git a/docs/adr/0007-plugins-are-read-in-place.md b/docs/adr/0007-plugins-are-read-in-place.md
index 155c3e75..975eacb3 100644
--- a/docs/adr/0007-plugins-are-read-in-place.md
+++ b/docs/adr/0007-plugins-are-read-in-place.md
@@ -17,14 +17,16 @@ config.
- Discover plugin roots in place: `~/.cursor/plugins/`, `~/.claude/plugins/`,
`~/.grok/plugins/`, `~/.codex/plugins/`, `~/.codegraff/plugins/`, and the
- project `.cursor/.claude/.grok/.codex/.harness/plugins/` trees (including
- Cursor/Claude `plugins/cache/…`). A directory is a plugin if it has
- `.cursor-plugin/plugin.json`, `.claude-plugin/plugin.json`,
- `.grok-plugin/plugin.json`, `plugin.json`, `.mcp.json`, `mcp.json`,
- `skills/`, or `agents/`. The listing name comes from the manifest when
- present (Cursor cache folders are content hashes). Skip `marketplaces/`.
- Cap 32. A directory is also a plugin if it has Claude's `commands/` or a
- root `SKILL.md`.
+ project `.cursor/.claude/.grok/.codex/.harness/plugins/` trees. Parent dirs
+ are listed two levels deep so Cursor `local/<name>/` is visible (OpenCode
+ 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`,
+ `.claude-plugin/plugin.json`, `.grok-plugin/plugin.json`, `plugin.json`,
+ `.mcp.json`, `mcp.json`, `skills/`, `agents/`, Claude's `commands/`, or a
+ root `SKILL.md`. The listing name comes from the registry key or the
+ manifest (Cursor cache folders are content hashes). Cap 32.
- Skills from those trees (and `~/.agents/skills`, `~/.grok/skills`,
`~/.codex/skills`, `~/.cursor/skills-cursor`, `~/.cursor/skills`) join the
existing on-demand `skill` catalog. Claude `commands/*.md` and a plugin-root
@@ -52,5 +54,7 @@ config.
inspect again. A named `skill` load hits the session catalog; a miss or a
list still rescans. Production caches the first walk (MCP + fleet + skills
share it); tests do not. `/plugins` and the interactive boot line print
- wall time so a slow home directory is visible.
+ wall time so a slow home directory is visible. A plugin that lives only
+ under `cache/` and is missing from `installed_plugins.json` is invisible
+ until the other harness records it — same as grok-build.
- Revisit if a user needs to disable one plugin without `GRAFF_NO_PLUGINS`.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index f6f1d6f2..e78e0920 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -17,7 +17,7 @@ record only when you need the evidence or the edge cases.
| [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. |
| [0006](0006-workspace-switch-is-a-tool.md) | Mid-session worktree switch is a real `workspace` tool; a skill cannot move file-tool cwd. |
-| [0007](0007-plugins-are-read-in-place.md) | Cursor/Claude/Grok/Codex plugins and MCP are read in place; skills stay on-demand; MCP stays consent-gated. |
+| [0007](0007-plugins-are-read-in-place.md) | Cursor/Claude/Grok/Codex plugins and MCP are read in place (cache via installed_plugins.json, never walked); skills stay on-demand; MCP stays consent-gated. |
| [0008](0008-synthetic-evals-use-external-verifiers.md) | Synthetic coding evals promote only external-verifier passes; model judges may tiebreak correctness, never decide it. |
## When to write one
diff --git a/docs/skills.md b/docs/skills.md
index d3ba3abb..2d6d375a 100644
--- a/docs/skills.md
+++ b/docs/skills.md
@@ -20,7 +20,7 @@ Two kinds of thing are called "skills" in graff, and `/skills` lists both:
| `~/.claude/skills/` | you, every project (compatibility) |
| `~/.harness/skills/` | you, every project |
| `~/.grok/skills/`, `~/.codex/skills/`, `~/.agents/skills/`, `~/.cursor/skills-cursor/` | you, every project (other harnesses, in place) |
-| `~/.cursor/plugins/*/skills/` and `~/.claude/plugins/*/skills/` (and Grok/Codex/graff plugin trees, plus Claude `commands/*.md` and a plugin-root `SKILL.md`) | you, every project (ADR 0007) |
+| `~/.cursor/plugins/*/skills/` and `~/.claude/plugins/*/skills/` (and Grok/Codex/graff plugin trees, plus Claude `commands/*.md`, a plugin-root `SKILL.md`, and cache installs named in `installed_plugins.json`) | you, every project (ADR 0007) |
| `.claude/skills/` | this project (compatibility) |
| `.grok/skills/`, `.codex/skills/` | this project |
| `.claude/plugins/*/skills/` (and project plugin trees) | this project |
diff --git a/evals/harness_behavior.jsonl b/evals/harness_behavior.jsonl
index 51515a0c..dda3b83d 100644
--- a/evals/harness_behavior.jsonl
+++ b/evals/harness_behavior.jsonl
@@ -51,7 +51,7 @@
{"id": "peer-message-list-names-live-peer", "why": "#563: action=list is ListAgents. With a live peer the tool result must name that they are live, not error, and not require text.", "live_peer": true, "args": [], "prompt": "who else is here", "script": [{"tool": "peer_message", "arguments": {"action": "list"}}, {"text": "saw them"}], "assert": [{"event": {"type": "tool_call", "name": "peer_message"}}, {"request_contains": {"index": 1, "text": "live"}}]}
{"id": "peer-message-inbox-empty-when-quiet", "why": "#563: action=inbox is the mailbox. With nothing parked it must say so in the tool result — never invent a body, never require text.", "args": [], "prompt": "check the peer inbox", "script": [{"tool": "peer_message", "arguments": {"action": "inbox"}}, {"text": "nothing waiting"}], "assert": [{"event": {"type": "tool_call", "name": "peer_message"}}, {"request_contains": {"index": 1, "text": "inbox empty"}}]}
{"id": "readonly-exact-key-prefers-one-search", "why": "Named-file guidance forced a whole-file read before an exact-key search, adding avoidable context and a provider round trip. A read-only keyed lookup should call read_file once with contains set to the exact key, answer from the numbered match, and never read the entire file.", "args": [], "workspace_seed": {"catalog.py": "SKU0001 = {'price': 100, 'stock': 1}\nSKU0002 = {'price': 200, 'stock': 2}\nSKU0420 = {'price': 31415, 'stock': 27}\nSKU0900 = {'price': 900, 'stock': 9}\n"}, "prompt": "Read catalog.py without editing it. Find SKU0420. Reply with exactly one line in the format SKU0420|price=<price>|stock=<stock> and nothing else.", "script": [{"tool": "read_file", "arguments": {"path": "catalog.py", "contains": "SKU0420"}}, {"text": "SKU0420|price=31415|stock=27"}], "assert": [{"request_contains": {"index": 0, "text": "contains set to the exact key"}}, {"event": {"type": "tool_call", "name": "read_file"}}, {"events_at_most": {"match": {"type": "tool_call"}, "count": 1}}, {"final_text_contains": "SKU0420|price=31415|stock=27"}]}
-{"id": "plugin-skill-on-demand", "why": "ADR 0007: a Cursor cache plugin skill must appear in the catalog as (plugin) without its body, and skill name= loads the body. The regression is copying/adopting (body always in the prompt) or never walking plugins/cache/.", "args": [], "workspace_seed": {".cursor/plugins/cache/cursor-public/evalfix/2a8044425c7bddf429c3bdedf3ab61e791d34d65/.cursor-plugin/plugin.json": "{\"name\":\"eval-gmail\"}\n", ".cursor/plugins/cache/cursor-public/evalfix/2a8044425c7bddf429c3bdedf3ab61e791d34d65/skills/plugin-secret/SKILL.md": "---\nname: plugin-secret\ndescription: load before using the plugin secret handshake\n---\n\n# Plugin Secret\n\nPLUGIN_SKILL_BODY_TOKEN_9f3a\n", ".cursor/skills-cursor/env-setup/SKILL.md": "---\nname: env-setup\ndescription: personal skills-cursor playbook that survives GRAFF_NO_PLUGINS\n---\n\n# Env Setup\n\nPERSONAL_SKILL_BODY_TOKEN_c2e1\n"}, "prompt": "list available skills, then load plugin-secret", "script": [{"tool": "load_tool_schemas", "arguments": {"tools": ["skill"]}}, {"tool": "skill", "arguments": {}}, {"tool": "skill", "arguments": {"name": "plugin-secret"}}, {"text": "loaded the plugin secret playbook"}], "assert": [{"request_contains": {"index": 0, "text": "plugin-secret (plugin)"}}, {"request_contains": {"index": 0, "text": "env-setup (personal)"}}, {"request_lacks": {"index": 0, "text": "PLUGIN_SKILL_BODY_TOKEN_9f3a"}}, {"request_lacks": {"index": 0, "text": "PERSONAL_SKILL_BODY_TOKEN_c2e1"}}, {"event": {"type": "tool_call", "name": "skill"}}, {"request_contains": {"index": -1, "text": "PLUGIN_SKILL_BODY_TOKEN_9f3a"}}, {"final_text_contains": "loaded the plugin secret playbook"}]}
+{"id": "plugin-skill-on-demand", "why": "ADR 0007: a Cursor cache plugin skill named in installed_plugins.json must appear in the catalog as (plugin) without its body, and skill name= loads the body. The regression is copying/adopting (body always in the prompt) or walking plugins/cache/ instead of the index.", "args": [], "workspace_seed": {".cursor/plugins/installed_plugins.json": "{\"plugins\":{\"eval-gmail@cursor-public\":[{\"installPath\":\"cache/cursor-public/evalfix/2a8044425c7bddf429c3bdedf3ab61e791d34d65\"}]}}\n", ".cursor/plugins/cache/cursor-public/evalfix/2a8044425c7bddf429c3bdedf3ab61e791d34d65/.cursor-plugin/plugin.json": "{\"name\":\"eval-gmail\"}\n", ".cursor/plugins/cache/cursor-public/evalfix/2a8044425c7bddf429c3bdedf3ab61e791d34d65/skills/plugin-secret/SKILL.md": "---\nname: plugin-secret\ndescription: load before using the plugin secret handshake\n---\n\n# Plugin Secret\n\nPLUGIN_SKILL_BODY_TOKEN_9f3a\n", ".cursor/skills-cursor/env-setup/SKILL.md": "---\nname: env-setup\ndescription: personal skills-cursor playbook that survives GRAFF_NO_PLUGINS\n---\n\n# Env Setup\n\nPERSONAL_SKILL_BODY_TOKEN_c2e1\n"}, "prompt": "list available skills, then load plugin-secret", "script": [{"tool": "load_tool_schemas", "arguments": {"tools": ["skill"]}}, {"tool": "skill", "arguments": {}}, {"tool": "skill", "arguments": {"name": "plugin-secret"}}, {"text": "loaded the plugin secret playbook"}], "assert": [{"request_contains": {"index": 0, "text": "plugin-secret (plugin)"}}, {"request_contains": {"index": 0, "text": "env-setup (personal)"}}, {"request_lacks": {"index": 0, "text": "PLUGIN_SKILL_BODY_TOKEN_9f3a"}}, {"request_lacks": {"index": 0, "text": "PERSONAL_SKILL_BODY_TOKEN_c2e1"}}, {"event": {"type": "tool_call", "name": "skill"}}, {"request_contains": {"index": -1, "text": "PLUGIN_SKILL_BODY_TOKEN_9f3a"}}, {"final_text_contains": "loaded the plugin secret playbook"}]}
{"id": "plugin-off-keeps-personal-skills", "why": "GRAFF_NO_PLUGINS must drop plugin-tree skills while ~/.cursor/skills-cursor stays personal. The regression is treating skills-cursor as a plugin (it vanishes) or ignoring the opt-out (plugin-secret still loads).", "args": [], "env": {"GRAFF_NO_PLUGINS": "1"}, "workspace_seed": {".cursor/plugins/cache/cursor-public/evalfix/2a8044425c7bddf429c3bdedf3ab61e791d34d65/.cursor-plugin/plugin.json": "{\"name\":\"eval-gmail\"}\n", ".cursor/plugins/cache/cursor-public/evalfix/2a8044425c7bddf429c3bdedf3ab61e791d34d65/skills/plugin-secret/SKILL.md": "---\nname: plugin-secret\ndescription: load before using the plugin secret handshake\n---\n\n# Plugin Secret\n\nPLUGIN_SKILL_BODY_TOKEN_9f3a\n", ".cursor/skills-cursor/env-setup/SKILL.md": "---\nname: env-setup\ndescription: personal skills-cursor playbook that survives GRAFF_NO_PLUGINS\n---\n\n# Env Setup\n\nPERSONAL_SKILL_BODY_TOKEN_c2e1\n"}, "prompt": "load the handshake playbook if it exists", "script": [{"tool": "skill", "arguments": {"name": "plugin-secret"}}, {"text": "plugin skill is gone; personal env-setup remains"}], "assert": [{"request_contains": {"index": 0, "text": "env-setup (personal)"}}, {"request_lacks": {"index": 0, "text": "plugin-secret"}}, {"request_lacks": {"index": 0, "text": "plugin-secret (plugin)"}}, {"request_lacks": {"index": 0, "text": "PLUGIN_SKILL_BODY_TOKEN_9f3a"}}, {"event": {"type": "tool_call", "name": "skill"}}, {"request_contains": {"index": -1, "text": "no skill named 'plugin-secret'"}}, {"final_text_contains": "plugin skill is gone"}]}
{"id": "workspace-list-use", "why": "ADR 0006: workspace is a folded tool that must list real git worktrees and chdir the session. A skill cannot move file-tool cwd; bash-cd is not enough. Guards load_tool_schemas unfold + use by folder name.", "args": [], "env": {"GRAFF_NO_CODEDB_GUARD": "1"}, "prompt": "create a feature worktree, list workspaces, switch into it", "script": [{"tool": "bash", "arguments": {"command": "git init && git config user.email eval@invalid && git config user.name Eval && echo x > README && git add README && git commit -m init && git worktree add wt-feature -b feature && echo seeded-worktree"}}, {"tool": "load_tool_schemas", "arguments": {"tools": ["workspace"]}}, {"tool": "workspace", "arguments": {"action": "list"}}, {"tool": "workspace", "arguments": {"action": "use", "path": "wt-feature"}}, {"tool": "bash", "arguments": {"command": "basename \"$(pwd)\""}}, {"text": "switched into wt-feature"}], "assert": [{"event": {"type": "tool_call", "name": "load_tool_schemas"}}, {"event": {"type": "tool_call", "name": "workspace"}}, {"request_contains": {"index": -1, "text": "wt-feature"}}, {"request_contains": {"index": -1, "text": "now at"}}, {"final_text_contains": "switched into wt-feature"}]}
{"id": "plugin-command-as-skill", "why": "Claude plugins ship playbooks as commands/*.md, not only skills/. A Claude tree must appear in the skill catalog as (plugin) without the body, and skill name= loads it — the same first-class load Claude uses.", "args": [], "workspace_seed": {".claude/plugins/greet/.claude-plugin/plugin.json": "{\"name\":\"greet\"}\n", ".claude/plugins/greet/commands/hello.md": "---\nname: hello\ndescription: Claude command playbook for the handshake\n---\n\n# Hello\n\nCLAUDE_COMMAND_BODY_TOKEN_7c1e\n"}, "prompt": "list skills, then load the hello playbook", "script": [{"tool": "skill", "arguments": {}}, {"tool": "skill", "arguments": {"name": "hello"}}, {"text": "loaded the Claude command playbook"}], "assert": [{"request_contains": {"index": 0, "text": "hello (plugin)"}}, {"request_lacks": {"index": 0, "text": "CLAUDE_COMMAND_BODY_TOKEN_7c1e"}}, {"event": {"type": "tool_call", "name": "skill"}}, {"request_contains": {"index": -1, "text": "CLAUDE_COMMAND_BODY_TOKEN_7c1e"}}, {"final_text_contains": "loaded the Claude command playbook"}]}
diff --git a/evals/plugins_oob/run.py b/evals/plugins_oob/run.py
index 59fb2fb1..d2d5e0c4 100644
--- a/evals/plugins_oob/run.py
+++ b/evals/plugins_oob/run.py
@@ -47,6 +47,11 @@ def seed_home(home: Path) -> None:
"---\nname: plugin-secret\ndescription: fixture playbook\n---\n\nbody\n",
encoding="utf-8",
)
+ (home / ".cursor/plugins").mkdir(parents=True, exist_ok=True)
+ (home / ".cursor/plugins/installed_plugins.json").write_text(
+ json.dumps({"plugins": {"eval-gmail@cursor-public": [{"installPath": str(plug)}]}}) + "\n",
+ encoding="utf-8",
+ )
claude = home / ".claude/plugins/demo"
(claude / ".claude-plugin").mkdir(parents=True)
diff --git a/evals/plugins_oob/test_eval.py b/evals/plugins_oob/test_eval.py
index 7b6e351a..86b5abd7 100644
--- a/evals/plugins_oob/test_eval.py
+++ b/evals/plugins_oob/test_eval.py
@@ -37,6 +37,7 @@ class PluginOobTests(unittest.TestCase):
(home / ".cursor/plugins/cache/cursor-public/evalfix" / CURSOR_HASH / ".cursor-plugin/plugin.json").is_file()
)
self.assertIn("eval-gmail", (home / ".cursor/plugins/cache/cursor-public/evalfix" / CURSOR_HASH / ".cursor-plugin/plugin.json").read_text())
+ self.assertIn("installPath", (home / ".cursor/plugins/installed_plugins.json").read_text())
self.assertIn("graff-wins", (home / ".codegraff/mcp.json").read_text())
def test_assertions_reject_the_wrong_listing(self) -> None:
diff --git a/src/plugin_index.zig b/src/plugin_index.zig
new file mode 100644
index 00000000..28a88795
--- /dev/null
+++ b/src/plugin_index.zig
@@ -0,0 +1,129 @@
+//! Claude/Cursor `installed_plugins.json` (grok-build's cheap path).
+//!
+//! OpenCode glob-scans `.claude/skills` and `.opencode/`; grok-build never
+//! walks `plugins/cache/`. It reads this registry's `installPath` entries
+//! (which happen to live under cache/) and only shallow-lists plugin parent
+//! dirs. Walking hashed version trees is what made graff's scan a second.
+
+const std = @import("std");
+const Io = std.Io;
+const Value = std.json.Value;
+const Allocator = std.mem.Allocator;
+
+pub const Entry = struct {
+ name: []const u8,
+ path: []const u8,
+};
+
+fn strField(obj: std.json.ObjectMap, key: []const u8) []const u8 {
+ const v = obj.get(key) orelse return "";
+ return if (v == .string) v.string else "";
+}
+
+/// User/unscoped always surface. `local`/`project` (or any entry with a
+/// projectPath) only when `cwd` is that project or a subdirectory.
+fn visible(obj: std.json.ObjectMap, cwd: []const u8) bool {
+ const scope = strField(obj, "scope");
+ const project = strField(obj, "projectPath");
+ const gated = std.mem.eql(u8, scope, "local") or std.mem.eql(u8, scope, "project") or project.len > 0;
+ if (!gated) return true;
+ if (project.len == 0 or cwd.len == 0) return false;
+ if (std.mem.eql(u8, cwd, project)) return true;
+ if (!std.mem.startsWith(u8, cwd, project)) return false;
+ return project[project.len - 1] == '/' or cwd[project.len] == '/';
+}
+
+fn nameFromKey(key: []const u8) []const u8 {
+ return if (std.mem.indexOfScalar(u8, key, '@')) |i| key[0..i] else key;
+}
+
+fn resolvePath(arena: Allocator, json_path: []const u8, install: []const u8) []const u8 {
+ if (install.len == 0) return "";
+ if (std.fs.path.isAbsolute(install)) return install;
+ const dir = std.fs.path.dirname(json_path) orelse return install;
+ return std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, install }) catch "";
+}
+
+/// Parse one registry. Empty on missing/invalid file. Caps at 32.
+pub fn load(io: Io, arena: Allocator, json_path: []const u8, cwd: []const u8) []const Entry {
+ const text = Io.Dir.cwd().readFileAlloc(io, json_path, arena, .limited(1 << 20)) catch return &.{};
+ const parsed = std.json.parseFromSliceLeaky(Value, arena, text, .{ .allocate = .alloc_always }) catch return &.{};
+ if (parsed != .object) return &.{};
+ const plugins_v = parsed.object.get("plugins") orelse return &.{};
+ if (plugins_v != .object) return &.{};
+ var out: std.ArrayList(Entry) = .empty;
+ var it = plugins_v.object.iterator();
+ while (it.next()) |e| {
+ if (out.items.len >= 32) break;
+ const items = switch (e.value_ptr.*) {
+ .array => |a| a.items,
+ else => continue,
+ };
+ const name = nameFromKey(e.key_ptr.*);
+ for (items) |item| {
+ if (out.items.len >= 32) break;
+ if (item != .object) continue;
+ if (!visible(item.object, cwd)) continue;
+ const raw = strField(item.object, "installPath");
+ const path = resolvePath(arena, json_path, raw);
+ if (path.len == 0) continue;
+ out.append(arena, .{ .name = name, .path = path }) catch {};
+ }
+ }
+ return out.items;
+}
+
+const testing = std.testing;
+
+fn tmpBase(io: Io, tmp: *testing.TmpDir, arena: Allocator) ![]const u8 {
+ var buf: [std.fs.max_path_bytes]u8 = undefined;
+ const n = try tmp.dir.realPath(io, &buf);
+ return arena.dupe(u8, buf[0..n]);
+}
+
+test "load: names and installPath; project scope is cwd-gated" {
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ const io = testing.io;
+ const base = try tmpBase(io, &tmp, arena);
+ const json_path = std.fmt.allocPrint(arena, "{s}/installed_plugins.json", .{base}) catch return error.OutOfMemory;
+ const user_plug = std.fmt.allocPrint(arena, "{s}/user-plug", .{base}) catch return error.OutOfMemory;
+ const proj_plug = std.fmt.allocPrint(arena, "{s}/proj-plug", .{base}) catch return error.OutOfMemory;
+ const project = std.fmt.allocPrint(arena, "{s}/repo", .{base}) catch return error.OutOfMemory;
+ try Io.Dir.cwd().writeFile(io, .{
+ .sub_path = json_path,
+ .data = try std.fmt.allocPrint(arena,
+ \\{{"plugins":{{"gmail@cursor":[{{"installPath":"{s}"}}],"pack@official":[{{"installPath":"{s}","scope":"project","projectPath":"{s}"}}]}}}}
+ , .{ user_plug, proj_plug, project }),
+ });
+
+ const user_only = load(io, arena, json_path, "/elsewhere");
+ try testing.expectEqual(@as(usize, 1), user_only.len);
+ try testing.expectEqualStrings("gmail", user_only[0].name);
+ try testing.expectEqualStrings(user_plug, user_only[0].path);
+
+ const both = load(io, arena, json_path, project);
+ try testing.expectEqual(@as(usize, 2), both.len);
+}
+
+test "load: relative installPath is next to the json" {
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ const io = testing.io;
+ const base = try tmpBase(io, &tmp, arena);
+ const json_path = std.fmt.allocPrint(arena, "{s}/installed_plugins.json", .{base}) catch return error.OutOfMemory;
+ try Io.Dir.cwd().writeFile(io, .{
+ .sub_path = json_path,
+ .data = "{\"plugins\":{\"pack@official\":[{\"installPath\":\"cache/pack/1.0.0\"}]}}",
+ });
+ const got = load(io, arena, json_path, base);
+ try testing.expectEqual(@as(usize, 1), got.len);
+ try testing.expectEqualStrings("pack", got[0].name);
+ try testing.expect(std.mem.endsWith(u8, got[0].path, "cache/pack/1.0.0"));
+}
diff --git a/src/plugins.zig b/src/plugins.zig
index 5d80cea9..d7fd436c 100644
--- a/src/plugins.zig
+++ b/src/plugins.zig
@@ -1,9 +1,8 @@
//! In-place plugins and foreign-harness MCP (ADR 0007).
//!
-//! Grok-build's trick is that it never copies Claude/Codex/Cursor trees into
-//! its own folders: it reads `skills/`, `agents/`, and `.mcp.json` where the
-//! other harness already installed them. graff's first-run `adopt` copies once
-//! and then ignores anything added later. This module is the live scan.
+//! Grok-build never walks `plugins/cache/` (OpenCode never does either — it
+//! globs `.claude/skills/**/SKILL.md` and `.opencode/`). Cache installs come
+//! from `installed_plugins.json` `installPath`. This module is the live scan.
//!
//! Skills stay on-demand (`skill` tool / `/skills`), including Claude
//! `commands/*.md` and a plugin-root `SKILL.md`. MCP still needs `/mcp
@@ -16,7 +15,9 @@ const Allocator = std.mem.Allocator;
const layout = @import("plugin_layout.zig");
const plugin_cap = 32;
-const walk_depth: u8 = 4;
+/// Immediate children plus one more for Cursor `local/<name>/`. Never
+/// `cache/` — that tree is hashed and is what made a scan take a second.
+const walk_depth: u8 = 2;
const visit_cap = 256;
const file_cap: std.Io.Limit = .limited(1 << 20);
const reserved = "smolify";
@@ -55,6 +56,7 @@ fn join(arena: Allocator, a: []const u8, b: []const u8) []const u8 {
fn skipped(name: []const u8) bool {
return std.mem.eql(u8, name, "marketplaces") or
+ std.mem.eql(u8, name, "cache") or
std.mem.eql(u8, name, ".git") or
std.mem.eql(u8, name, "node_modules");
}
@@ -91,20 +93,7 @@ fn walk(io: Io, arena: Allocator, list: *std.ArrayList(Plugin), path: []const u8
children.append(arena, child) catch {};
}
if (plugin_here) {
- const lay = layout.inspect(io, arena, path);
- list.append(arena, .{
- .name = if (lay.name.len > 0) lay.name else std.fs.path.basename(path),
- .path = path,
- .origin = origin,
- .personal = personal,
- .skills = lay.skill_dirs.len > 0 or lay.root_skill != null,
- .agents = lay.agent_dirs.len > 0,
- .mcp = lay.has_mcp,
- .commands = lay.has_commands,
- .skill_dirs = lay.skill_dirs,
- .agent_dirs = lay.agent_dirs,
- .root_skill = lay.root_skill,
- }) catch {};
+ adopt(io, arena, list, path, origin, personal, "");
return; // do not treat a plugin's skills/ as a nested plugin
}
if (depth == 0) return;
@@ -115,6 +104,34 @@ fn walk(io: Io, arena: Allocator, list: *std.ArrayList(Plugin), path: []const u8
}
}
+fn adopt(io: Io, arena: Allocator, list: *std.ArrayList(Plugin), path: []const u8, origin: []const u8, personal: bool, json_name: []const u8) void {
+ if (list.items.len >= plugin_cap) return;
+ for (list.items) |p| if (std.mem.eql(u8, p.path, path)) return;
+ const lay = layout.inspect(io, arena, path);
+ if (lay.skill_dirs.len == 0 and lay.agent_dirs.len == 0 and !lay.has_mcp and !lay.has_commands and lay.root_skill == null)
+ return;
+ const name = if (json_name.len > 0) json_name else if (lay.name.len > 0) lay.name else std.fs.path.basename(path);
+ list.append(arena, .{
+ .name = name,
+ .path = path,
+ .origin = origin,
+ .personal = personal,
+ .skills = lay.skill_dirs.len > 0 or lay.root_skill != null,
+ .agents = lay.agent_dirs.len > 0,
+ .mcp = lay.has_mcp,
+ .commands = lay.has_commands,
+ .skill_dirs = lay.skill_dirs,
+ .agent_dirs = lay.agent_dirs,
+ .root_skill = lay.root_skill,
+ }) catch {};
+}
+
+fn takeInstalled(io: Io, arena: Allocator, list: *std.ArrayList(Plugin), json_path: []const u8, origin: []const u8, personal: bool, cwd: []const u8) void {
+ for (@import("plugin_index.zig").load(io, arena, json_path, cwd)) |e| {
+ adopt(io, arena, list, e.path, origin, personal, e.name);
+ }
+}
+
const Spec = struct { rel: []const u8, origin: []const u8 };
const user_roots = [_]Spec{
@@ -152,20 +169,22 @@ pub fn discoverFresh(io: Io, arena: Allocator, home: ?[]const u8, project: Io.Di
if (off()) return &.{};
var list: std.ArrayList(Plugin) = .empty;
var visits: usize = 0;
+ var buf: [std.fs.max_path_bytes]u8 = undefined;
+ const n = project.realPath(io, &buf) catch 0;
+ const cwd = if (n > 0) arena.dupe(u8, buf[0..n]) catch "" else "";
if (home) |h| if (h.len > 0) {
for (user_roots) |spec| {
walk(io, arena, &list, join(arena, h, spec.rel), spec.origin, true, walk_depth, &visits);
}
+ 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);
};
- var buf: [std.fs.max_path_bytes]u8 = undefined;
- const n = project.realPath(io, &buf) catch 0;
- if (n > 0) {
- const root = arena.dupe(u8, buf[0..n]) catch "";
- if (root.len > 0) {
- for (project_roots) |spec| {
- walk(io, arena, &list, join(arena, root, spec.rel), spec.origin, false, walk_depth, &visits);
- }
+ if (cwd.len > 0) {
+ for (project_roots) |spec| {
+ walk(io, arena, &list, join(arena, cwd, spec.rel), spec.origin, false, walk_depth, &visits);
}
+ 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);
}
last_visits = visits;
return list.items;
@@ -388,7 +407,7 @@ test "discover: a Claude plugin.json tree is a plugin; marketplaces are not" {
try testing.expect(std.mem.endsWith(u8, dirs[0], "demo/skills"));
}
-test "discover: walks Claude plugins/cache two levels down" {
+test "discover: installed_plugins.json names a cache installPath; cache/ is not walked" {
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
@@ -401,7 +420,10 @@ test "discover: walks Claude plugins/cache two levels down" {
try Io.Dir.cwd().createDirPath(io, join(arena, nested, "agents"));
try Io.Dir.cwd().writeFile(io, .{ .sub_path = join(arena, nested, "plugin.json"), .data = "{\"name\":\"pack\"}" });
try Io.Dir.cwd().writeFile(io, .{ .sub_path = join(arena, nested, "agents/reviewer.md"), .data = "---\nname: pack-reviewer\n---\nbe careful\n" });
+ try testing.expectEqual(@as(usize, 0), discover(io, arena, home, tmp.dir).len);
+ const json = try std.fmt.allocPrint(arena, "{{\"plugins\":{{\"pack@official\":[{{\"installPath\":\"{s}\"}}]}}}}", .{nested});
+ try Io.Dir.cwd().writeFile(io, .{ .sub_path = join(arena, home, ".claude/plugins/installed_plugins.json"), .data = json });
const list = discover(io, arena, home, tmp.dir);
try testing.expectEqual(@as(usize, 1), list.len);
try testing.expectEqualStrings("pack", list[0].name);
@@ -525,6 +547,8 @@ test "discover: Cursor cache uses .cursor-plugin + mcp.json; name from manifest"
.sub_path = join(arena, plug, "mcp.json"),
.data = "{\"mcpServers\":{\"gmail\":{\"url\":\"https://gmailmcp.googleapis.com/mcp/v1\"}}}",
});
+ const idx = try std.fmt.allocPrint(arena, "{{\"plugins\":{{\"gmail@cursor-public\":[{{\"installPath\":\"{s}\"}}]}}}}", .{plug});
+ try Io.Dir.cwd().writeFile(io, .{ .sub_path = join(arena, home, ".cursor/plugins/installed_plugins.json"), .data = idx });
const list = discover(io, arena, home, tmp.dir);
try testing.expectEqual(@as(usize, 1), list.len);
diff --git a/src/test_hooks.zig b/src/test_hooks.zig
index f61bf607..791fa27e 100644
--- a/src/test_hooks.zig
+++ b/src/test_hooks.zig
@@ -130,6 +130,7 @@ const workspace_switch = @import("workspace_switch.zig"); // ADR 0006 mid-sessio
const plugins = @import("plugins.zig"); // ADR 0007 in-place plugin / foreign MCP discovery
const plugin_layout = @import("plugin_layout.zig"); // Claude commands/ + inline MCP + ${CLAUDE_PLUGIN_ROOT}
const plugin_scan = @import("plugin_scan.zig"); // timed discover + production cache
+const plugin_index = @import("plugin_index.zig"); // Claude/Cursor installed_plugins.json
// #345: the global-vs-project MCP config merge. mcp.zig does reference its
// decls, but the hook makes the coverage explicit rather than contingent on
@@ -265,6 +266,7 @@ test {
_ = plugins;
_ = plugin_layout;
_ = plugin_scan;
+ _ = plugin_index;
_ = shutdown_trace;
_ = credential_store;
_ = engine_events;