templates/skills/languages/zig/SKILL.md
Execute these commands after EVERY implementation (see AGENT_AUTOMATION module for full workflow).
npx skillsauth add hivellm/rulebook ZigInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
CRITICAL: Execute these commands after EVERY implementation (see AGENT_AUTOMATION module for full workflow).
# Complete quality check sequence:
zig fmt --check . # Format check
zig build # Build verification
zig build test # All tests (100% pass)
# No standard security audit tool for Zig yet
CRITICAL: Use Zig 0.11+ with strict compilation and comprehensive testing.
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Library
const lib = b.addStaticLibrary(.{
.name = "your-lib",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);
// Executable
const exe = b.addExecutable(.{
.name = "your-app",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
// Tests
const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const run_main_tests = b.addRunArtifact(main_tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
// Run command
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
CRITICAL: After implementing ANY feature, you MUST run these commands in order.
IMPORTANT: These commands MUST match your GitHub Actions workflows to prevent CI/CD failures!
# Pre-Commit Checklist (MUST match .github/workflows/*.yml)
# 1. Format check (matches workflow)
zig fmt --check src/ tests/
# 2. Build (MUST pass - matches workflow)
zig build -Doptimize=ReleaseFast
# 3. Build with all optimizations (matches workflow)
zig build -Doptimize=ReleaseSmall
zig build -Doptimize=ReleaseSafe
# 4. Run all tests (MUST pass 100% - matches workflow)
zig build test
# 5. Test with different targets (matches workflow)
zig build test -Dtarget=x86_64-linux
zig build test -Dtarget=x86_64-windows
zig build test -Dtarget=aarch64-macos
# 6. Check for memory leaks (matches workflow)
zig build test -Doptimize=Debug --summary all
# If ANY fails: ❌ DO NOT COMMIT - Fix first!
If ANY of these fail, you MUST fix the issues before committing.
Why This Matters:
zig fmt src/ locally but zig fmt --check src/ in CI = failurezig test/testsExample test structure:
const std = @import("std");
const testing = std.testing;
const DataProcessor = @import("processor.zig").DataProcessor;
test "DataProcessor: basic functionality" {
var processor = DataProcessor.init(0.5);
defer processor.deinit();
const input = [_]i32{ 1, 2, 3, 4, 5 };
const result = try processor.process(&input);
defer testing.allocator.free(result);
try testing.expect(result.len > 0);
try testing.expectEqual(@as(usize, 3), result.len);
}
test "DataProcessor: handles empty input" {
var processor = DataProcessor.init(0.5);
defer processor.deinit();
const input = [_]i32{};
const result = try processor.process(&input);
defer testing.allocator.free(result);
try testing.expectEqual(@as(usize, 0), result.len);
}
test "DataProcessor: memory management" {
// Test that all allocations are freed
const allocator = testing.allocator;
var processor = try DataProcessor.initWithAllocator(allocator, 0.5);
defer processor.deinit();
const input = try allocator.alloc(i32, 1000);
defer allocator.free(input);
for (input, 0..) |*item, i| {
item.* = @intCast(i);
}
const result = try processor.process(input);
defer allocator.free(result);
// If we reach here without leaks, test passes
try testing.expect(result.len > 0);
}
CRITICAL: Zig provides compile-time safety - use it!
// ✅ GOOD: Safe memory management
const std = @import("std");
pub fn processData(allocator: std.mem.Allocator, input: []const i32) ![]i32 {
var result = std.ArrayList(i32).init(allocator);
defer result.deinit(); // Always cleanup!
for (input) |value| {
if (value > 0) {
try result.append(value * 2);
}
}
return result.toOwnedSlice();
}
// Usage with proper cleanup
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const input = [_]i32{ 1, 2, 3, 4, 5 };
const result = try processData(allocator, &input);
defer allocator.free(result); // Free returned memory!
for (result) |value| {
std.debug.print("{}\n", .{value});
}
}
// ❌ BAD: Memory leaks
pub fn processDataLeaky(allocator: std.mem.Allocator) ![]i32 {
var result = std.ArrayList(i32).init(allocator);
// Missing defer result.deinit()!
try result.append(42);
return result.toOwnedSlice(); // Leaks ArrayList memory!
}
Must include GitHub Actions workflows:
Testing (zig-test.yml):
Linting (zig-lint.yml):
research
Create structured analyses with numbered findings, execution plans, and task materialization
research
Author a rulebook task spec interactively — research, draft, ask the user clarifying questions, confirm, then create the tasks in rulebook ready for /rulebook-driver. Use when the user wants to plan/spec a feature before implementing.
development
Behavioral guidelines to reduce common LLM coding mistakes — overcomplication, sloppy refactors, hidden assumptions, weak goals. Use when writing, reviewing, or refactoring code. Auto-applies; invoke explicitly via /karpathy-guidelines or 'follow karpathy discipline'.
data-ai
Autonomous AI agent loop for iterative task implementation (@hivehub/rulebook ralph)