Skip to content
1        10        20        30        40        50        60        70        801//! The skill payload and its Markdown helpers.2const std = @import("std");3const build_options = @import("build_options");45/// Directory name and file name of the installed skill.6pub const name = "silen-infra";7pub const file_name = "SKILL.md";89/// The full skill, including YAML frontmatter, embedded at build time.10pub const full: []const u8 = build_options.skill;1112/// Marker wrapped around an appended copy. It makes repeated runs idempotent13/// even when the skill was appended to a file that already had content.14pub const marker = "<!-- any:skill silen-infra -->";15pub const end_marker = "<!-- /any:skill silen-infra -->";1617/// The Markdown body without the YAML frontmatter.18pub fn body() []const u8 {19    if (!std.mem.startsWith(u8, full, "---\n")) return full;20    const rest = full[4..];21    const end = std.mem.indexOf(u8, rest, "\n---\n") orelse return full;22    return std.mem.trimStart(u8, rest[end + 5 ..], "\n");23}2425/// Whether `text` already contains this skill, either as the whole file or as26/// a section appended by a previous run.27pub fn contains(text: []const u8) bool {28    return std.mem.indexOf(u8, text, marker) != null or29        std.mem.indexOf(u8, text, full) != null;30}3132/// Builds the content used when the target already exists and should not be33/// replaced: keep the existing text, then append the skill body under a marker.34pub fn appended(allocator: std.mem.Allocator, existing: []const u8) ![]u8 {35    return std.fmt.allocPrint(allocator, "{s}\n\n{s}\n{s}\n{s}\n", .{36        std.mem.trimEnd(u8, existing, "\n"),37        marker,38        body(),39        end_marker,40    });41}4243test "body strips frontmatter" {44    try std.testing.expect(std.mem.startsWith(u8, body(), "# silen infra"));45    try std.testing.expect(std.mem.indexOf(u8, body(), "name: silen-infra") == null);46}4748test "full skill is detected" {49    try std.testing.expect(contains(full));50    try std.testing.expect(!contains("# some other skill\n"));51}5253test "appending keeps existing text and adds a marker" {54    const text = try appended(std.testing.allocator, "# Project notes\n");55    defer std.testing.allocator.free(text);56    try std.testing.expect(std.mem.startsWith(u8, text, "# Project notes\n"));57    try std.testing.expect(std.mem.indexOf(u8, text, marker) != null);58    try std.testing.expect(std.mem.indexOf(u8, text, "# silen infra") != null);59    try std.testing.expect(contains(text));60}