Skip to content

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

Python

fix(skills): a SKILL.md over 8 KB stays in the catalog (#730)

justrachf8e86044dff3
diff --git a/src/skill_docs.zig b/src/skill_docs.zig
index 84cab771..1ec1196b 100644
--- a/src/skill_docs.zig
+++ b/src/skill_docs.zig
@@ -130,7 +130,7 @@ pub const builtins = blk: {
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.
-var g_home: ?[]const u8 = null;
+pub var g_home: ?[]const u8 = null; // pub: split-out tests save/restore it
pub fn load(io: Io, arena: Allocator, home: ?[]const u8) []const Skill {
g_home = home;
@@ -215,7 +215,7 @@ fn loadDir(io: Io, arena: Allocator, list: *std.ArrayList(Skill), dir_path: []co
fn mergeFile(io: Io, arena: Allocator, list: *std.ArrayList(Skill), dir_path: []const u8, path: []const u8, raw_name: []const u8, source: Source) void {
// Prefix only: name + description for the prompt. The body stays on disk
// until `skill name=` / render, same as ADR 0007 and OpenCode's catalog.
- const data = Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(head_cap)) catch return;
+ const data = readHead(io, arena, path) orelse return;
// raw_name points into the directory iterator's buffer, which the next
// entry overwrites — the parsed skill has to own it.
const fallback = arena.dupe(u8, raw_name) catch return;
@@ -231,6 +231,16 @@ fn mergeFile(io: Io, arena: Allocator, list: *std.ArrayList(Skill), dir_path: []
});
}
+/// The first `head_cap` bytes of a SKILL.md, never the whole file. The
+/// catalog used `readFileAlloc(.limited(head_cap))`, which fails with
+/// StreamTooLong at the cap instead of truncating, so every playbook over
+/// 8 KB silently vanished from the catalog and `skill <name>` could not load
+/// it (#730). A truncating read keeps the catalog cheap and the skill present.
+fn readHead(io: Io, arena: Allocator, path: []const u8) ?[]const u8 {
+ const buf = arena.alloc(u8, head_cap) catch return null;
+ return Io.Dir.cwd().readFile(io, path, buf) catch null;
+}
+
/// Append, or replace the same-named skill from a lower tier.
fn insert(arena: Allocator, list: *std.ArrayList(Skill), sk: Skill) void {
for (list.items) |*existing| {
@@ -572,3 +582,7 @@ test "load: catalog keeps name and desc; named skill reads the body from disk" {
try std.testing.expect(!out.is_error);
try std.testing.expect(std.mem.indexOf(u8, out.text, "CATALOG_MUST_NOT_KEEP_THIS_BODY") != null);
}
+
+test { // split-out tests (file cap): unreferenced, they would silently never run
+ _ = @import("skill_docs_tests.zig");
+}
diff --git a/src/skill_docs_tests.zig b/src/skill_docs_tests.zig
new file mode 100644
index 00000000..60809c2d
--- /dev/null
+++ b/src/skill_docs_tests.zig
@@ -0,0 +1,60 @@
+//! skill_docs tests that did not fit under the 600-line cap. Imported from
+//! skill_docs.zig's `test {}` so they stay in the suite.
+
+const std = @import("std");
+const Io = std.Io;
+const skill_docs = @import("skill_docs.zig");
+
+// A playbook larger than the catalog's 8 KB head read must still be listed
+// and load in full (#730). Only the catalog read is capped; the named load
+// reads the whole file.
+test "#730: a SKILL.md over 8 KB stays in the catalog and loads whole" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ const io = std.testing.io;
+ var buf: [std.fs.max_path_bytes]u8 = undefined;
+ const n = try tmp.dir.realPath(io, &buf);
+ const home = try std.fmt.allocPrint(arena, "{s}/home", .{buf[0..n]});
+ const dir = try std.fmt.allocPrint(arena, "{s}/.harness/skills/graphify", .{home});
+ try Io.Dir.cwd().createDirPath(io, dir);
+
+ // 12 KB body: well past head_cap, with a marker only the full read sees.
+ var body: std.Io.Writer.Allocating = .init(arena);
+ try body.writer.writeAll("---\nname: graphify\ndescription: big playbook\n---\n\n");
+ var i: usize = 0;
+ while (i < 200) : (i += 1) try body.writer.print("line {d}: the quick brown fox jumps over the lazy dog again\n", .{i});
+ try body.writer.writeAll("TAIL_MARKER_PAST_THE_HEAD_CAP\n");
+ const text = body.written();
+ try std.testing.expect(text.len > 8 * 1024);
+ try Io.Dir.cwd().writeFile(io, .{
+ .sub_path = try std.fmt.allocPrint(arena, "{s}/SKILL.md", .{dir}),
+ .data = text,
+ });
+
+ const prev_skills = skill_docs.g_skills;
+ const prev_home = skill_docs.g_home;
+ defer {
+ skill_docs.g_skills = prev_skills;
+ skill_docs.g_home = prev_home; // load() pins `home`, which this arena owns
+ }
+ const list = skill_docs.load(io, arena, home);
+ var found = false;
+ for (list) |sk| {
+ if (std.mem.eql(u8, sk.name, "graphify")) {
+ found = true;
+ try std.testing.expectEqualStrings("big playbook", sk.desc);
+ }
+ }
+ try std.testing.expect(found);
+
+ skill_docs.g_skills = list;
+ var obj: std.json.ObjectMap = .empty;
+ try obj.put(arena, "name", .{ .string = "graphify" });
+ const out = try skill_docs.execSkill(std.testing.allocator, io, .{ .object = obj });
+ defer std.testing.allocator.free(out.text);
+ try std.testing.expect(!out.is_error);
+ try std.testing.expect(std.mem.indexOf(u8, out.text, "TAIL_MARKER_PAST_THE_HEAD_CAP") != null);
+}