NAME

Skilletor::AgentsMD - The Codex rules file, the pointer block in a Codex AGENTS.md, and the checks of Codex's config.toml

VERSION

version 0.008000

SYNOPSIS

use Skilletor::AgentsMD qw( rules_file_text parse_rules_file pointer_lines with_block inspect_agents_md );

my $text = rules_file_text( project => [ { name => 'k8s', source => 'shared', text => "Use helm.\n" } ] );
my $sections = parse_rules_file($text);    # { k8s => { source => 'shared', text => "Use helm.\n" } }

my $agents = inspect_agents_md("$repo/AGENTS.md");
if ( $agents->{ok} ) {
  my $next = with_block( $agents->{text}, [ pointer_lines( project => '.codex/skilletor-rules.md' ) ] );
}

DESCRIPTION

The reference's agentsmd.ts (spec §14.8): Codex rules on disk.

The rules file (skilletor-rules.md, in $CODEX_HOME for the user scope and <repo>/.codex for a project) is wholly skilletor's: a header line, the managed note, then one section per rule under its marker comment. The SessionStart hook under Codex injects it. AGENTS.md carries only a pointer to it, one managed block between <!-- skilletor:begin --> and <!-- skilletor:end -->; text outside the markers is never modified. Malformed markers, and files skilletor must not write through (a symlink, a directory, an unreadable file), are refused, never repaired.

Codex's config.toml is read line by line, never parsed as TOML, as the reference reads it.

Texts are characters; files are read as UTF-8, an ill-formed byte as U+FFFD, as Node reads them.

normalize_section

Leading blank lines and trailing whitespace (JavaScript's \s) dropped, one final newline added.

rules_file_text

my $text = rules_file_text( $scope, [ { name, source, text }, ... ] );

The rules file of a scope, the sections in the order given; undef without one.

parse_rules_file

my $sections = parse_rules_file($text);   # { name => { source, text } }

The sections of a rules file, whatever its header says.

pointer_lines

my @lines = pointer_lines( $scope, $file );

The lines inside the pointer block; $file is shown as given.

parse_block

my $block = parse_block($text);   # { begin, end, sections } or undef

The managed block of an AGENTS.md: the line numbers of its markers and the rule sections inside it (only the first design wrote any; they are read for the migration). Undef without one; Skilletor::Error::Block when the markers are malformed.

with_block

my $next = with_block( $text, \@body );   # the block holding @body
my $next = with_block( $text, undef );    # the block removed

The file's content with the block, or without one; undef when the file should not exist (no block and nothing but whitespace). $text undef: no file.

inspect_agents_md

my $i = inspect_agents_md($path);
# { ok => 1, text => $text_or_undef, parsed => $block_or_undef } or { ok => 0, reason => $why }

May skilletor keep a block in this file? Never dies.

project_doc_limit

my $bytes = project_doc_limit($codex_home);   # 32768 unless config.toml says otherwise

Codex's project_doc_max_bytes, a top-level key of $codex_home/config.toml.

codex_hook_trusted

codex_hook_trusted($codex_home);   # 1 or 0

Has the user trusted skilletor's Codex SessionStart hook? True when $codex_home/config.toml has a trusted_hash for a hooks.state key starting with skilletor@ and containing :session_start: – as a [hooks.state."<key>"] table, or as a key under [hooks.state]. Whether the hash is current is not checked. Never dies.

BEGIN_MARKER

END_MARKER

NOTE

RULES_FILE

skilletor-rules.md, the rules file's name, and the lock key of every rule section.

RULES_MARKER

How the rules file, and so the hook's message, begins.

MARKER_LINE

A pattern for a skilletor marker line (<!-- skilletor:begin, end, rule, rules), matched against a trimmed line.

SUPPORT

Issues

Please report bugs and feature requests at https://github.com/Getty/skilletor/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)