| 1 | package Skilletor::Convert; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A Claude agent as a Codex agent role, a rule as its section of the Codex rules file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 400 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 400 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 400 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 400 | ▶ | use Scalar::Util qw( blessed reftype ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 400 | ▶ | use Skilletor::AgentsMD qw( RULES_FILE MARKER_LINE normalize_section ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 400 | ▶ | use Skilletor::Error::Convert; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 400 | ▶ | use Skilletor::FSUtil qw( decode_utf8_lossy encode_text ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 400 | ▶ | use Skilletor::Frontmatter qw( split_frontmatter is_yaml_float ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 400 | ▶ | use Skilletor::JSON qw( js_number js_ordered js_stringify js_type ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 400 | ▶ | use Skilletor::JSString qw( js_trim ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 400 | ▶ | use Skilletor::TOML qw( stringify_toml toml_float ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 400 | our $VERSION = '0.008000'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 400 | our @EXPORT_OK = qw( codex_agent_toml codex_rule_section convert_for_target ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 93 | ▶ | sub _fail { Skilletor::Error::Convert->throw( $_[0] ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # split_frontmatter; unreadable frontmatter is a conversion error with the reader's message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1437 | ▶ | sub _split { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1437 | my ( $markdown ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1437 | my $fm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1437 | ▶ | return $fm if eval { $fm = split_frontmatter($markdown); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 12 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 12 | ▶ | _fail( $err->message ) if blessed $err && $err->isa('Skilletor::Error::Frontmatter'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($err) and $err->isa("Skilletor::Error::Frontmatter")
MC/DC0%0/2
builtin::blessed($err) and $err->isa("Skilletor::Error::Frontmatter")
builtin::blessed($err)
$err->isa("Skilletor::Error::Frontmatter")
Truth table33%1/3
A and B
A= builtin::blessed($err)B= $err->isa("Skilletor::Error::Frontmatter")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | die $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 672 | ▶ | sub _is_mapping { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_mapping: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 672 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 672 | ▶ | return ref $v && ( reftype $v // '' ) eq 'HASH' && !is_yaml_float($v) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
ref $v and (builtin::reftype($v) // "") eq "HASH" and not is_yaml_float($v)
ref $v and (builtin::reftype($v) // "") eq "HASH"
builtin::reftype($v) // ""
MC/DC66%2/3
ref $v and (builtin::reftype($v) // "") eq "HASH" and not is_yaml_float($v)
ref $v
builtin::reftype($v)
not is_yaml_float($v)
Truth table75%3/4
A and B and not(C)
A= ref $vB= builtin::reftype($v)C= not is_yaml_float($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # A YAML value as a TOML scalar or string array: ( $value ), or ( undef, $reason ) when it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # cannot be one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 122 | ▶ | sub _toml_leaf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_toml_leaf: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 122 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 122 | ▶ | return ( toml_float( $v->value ) ) if is_yaml_float($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 96 | my $type = js_type($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 96 | ▶ | return ($v) if $type eq 'string' || $type eq 'boolean' || $type eq 'number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$type eq "string" or $type eq "boolean" or $type eq "number"
$type eq "string" or $type eq "boolean"
MC/DC100%3/3
$type eq "string" or $type eq "boolean" or $type eq "number"
$type eq "string"
$type eq "boolean"
$type eq "number"
Truth table100%4/4
A or B or C
A= $type eq "string"B= $type eq "boolean"C= $type eq "number"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 28 | ▶ | return ( undef, 'null has no TOML form' ) if $type eq 'null'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 21 | ▶ | if ( $type eq 'array' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 19 | ▶ | return ( undef, 'only arrays of strings are supported' ) if grep { js_type($_) ne 'string' } @$v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 13 | return ($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | return ( undef, 'nested tables are not supported' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # String(v) of a scalar, undef for null, a list, a mapping or a float (all objects there). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 431 | ▶ | sub _as_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_as_text: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 431 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 431 | my $type = js_type($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 431 | ▶ | return $v ? 'true' : 'false' if $type eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 426 | ▶ | return js_number($v) if $type eq 'number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 419 | ▶ | return $type eq 'string' ? $v : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # String(v) of a YAML value that is no list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 27 | ▶ | sub _js_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_js_string: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 27 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 27 | ▶ | return '[object Object]' if is_yaml_float($v) || _is_mapping($v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_yaml_float($v) or _is_mapping($v)
MC/DC100%2/2
is_yaml_float($v) or _is_mapping($v)
is_yaml_float($v)
_is_mapping($v)
Truth table100%3/3
A or B
A= is_yaml_float($v)B= _is_mapping($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 24 | ▶ | return defined $v ? _as_text($v) : 'null'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # JSON.stringify(v) of a YAML scalar; a float is the object it is in the reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 21 | ▶ | sub _json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_json: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 21 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 21 | ▶ | return js_stringify( is_yaml_float($v) ? js_ordered( value => $v->value ) : $v ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # A briefing skill name the comment line cannot carry: `"`, `\`, `]`, or any control character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # (line breaks included; TOML allows none but tab in a comment). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 400 | my $BAD_SKILL_CHAR = qr/["\\\]\x00-\x1F\x7F]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # briefing.skills as the comment line the briefing plugin reads for Codex (spec ยง14.7): Codex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # drops a role with any unknown key, so a [briefing] table is not an option. Undef when there | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # is nothing to declare. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 204 | ▶ | sub _briefing_comment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_briefing_comment: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 204 | my ( $briefing ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 204 | ▶ | return undef unless _is_mapping($briefing) && exists $briefing->{skills}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_is_mapping($briefing) and exists $briefing->{"skills"}
MC/DC100%2/2
_is_mapping($briefing) and exists $briefing->{"skills"}
_is_mapping($briefing)
exists $briefing->{"skills"}
Truth table100%3/3
A and B
A= _is_mapping($briefing)B= exists $briefing->{"skills"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 35 | my $skills = $briefing->{skills}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 35 | ▶ | _fail('briefing.skills must be a list of skill names') unless js_type($skills) eq 'array'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 28 | ▶ | return undef unless @$skills; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 27 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 27 | for my $s (@$skills) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 46 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 46 | ▶ | next if js_type($s) eq 'string' && $s ne '' && $s !~ $BAD_SKILL_CHAR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
js_type($s) eq "string" and $s ne "" and not $s =~ /$BAD_SKILL_CHAR/
js_type($s) eq "string" and $s ne ""
MC/DC100%3/3
js_type($s) eq "string" and $s ne "" and not $s =~ /$BAD_SKILL_CHAR/
js_type($s) eq "string"
$s ne ""
not $s =~ /$BAD_SKILL_CHAR/
Truth table100%4/4
A and B and not(C)
A= js_type($s) eq "string"B= $s ne ""C= not $s =~ /$BAD_SKILL_CHAR/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 21 | _fail( 'briefing.skills item '.$i.' ('._json($s).') must be a non-empty string ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | .'without a double quote, backslash, ] or line break' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | return '# briefing: skills = ['.join( ', ', map { '"'.$_.'"' } @$skills )."]\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 213 | ▶ | sub codex_agent_toml { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
codex_agent_toml: called CC=26 SCAR=32.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 213 | my ( $markdown, $item_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 213 | my $fm = _split($markdown); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 204 | my ( $data, $body ) = @{$fm}{qw( data body )}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 204 | my @warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 204 | my $name = _as_text( $data->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | my $top = js_ordered( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | name => defined $name && $name ne '' ? $name : $item_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 204 | ▶ | description => _as_text( $data->{description} ) // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
defined $name and $name ne ""
_as_text($data->{"description"}) // ""
MC/DC100%2/2
defined $name and $name ne ""
defined $name
$name ne ""
MC/DC100%1/1
_as_text($data->{"description"}) // ""
_as_text($data->{"description"})
Truth table100%3/3
A and B
A= defined $nameB= $name ne ""
Truth table100%2/2
A
A= _as_text($data->{"description"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 204 | my $tables = js_ordered(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 204 | my $briefing = _briefing_comment( $data->{briefing} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 176 | my $instructions = $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 176 | my $codex = $data->{codex}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 176 | ▶ | if ( exists $data->{codex} && !_is_mapping($codex) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
exists $data->{"codex"} and not _is_mapping($codex)
MC/DC100%2/2
exists $data->{"codex"} and not _is_mapping($codex)
exists $data->{"codex"}
not _is_mapping($codex)
Truth table100%3/3
A and not(B)
A= exists $data->{"codex"}B= not _is_mapping($codex)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | push @warnings, 'codex: must be a mapping; ignored'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif ( _is_mapping($codex) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 42 | for my $key ( keys %$codex ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 117 | my $v = $codex->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 117 | ▶ | if ( $key eq 'briefing' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | _fail( 'codex.briefing: would become a [briefing] table, and Codex ignores a role with one; ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | .'declare skills in the top-level briefing.skills' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 114 | ▶ | if ( _is_mapping($v) && ( exists $top->{$key} || $key eq 'developer_instructions' || exists $tables->{$key} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
_is_mapping($v) and exists $top->{$key} || $key eq "developer_instructions" || exists $tables->{$key}
exists $top->{$key} or $key eq "developer_instructions" or exists $tables->{$key}
exists $top->{$key} or $key eq "developer_instructions"
MC/DC75%3/4
_is_mapping($v) and exists $top->{$key} || $key eq "developer_instructions" || exists $tables->{$key}
_is_mapping($v)
exists $top->{$key}
$key eq "developer_instructions"
exists $tables->{$key}
Truth table80%4/5
A and B or C or D
A= _is_mapping($v)B= exists $top->{$key}C= $key eq "developer_instructions"D= exists $tables->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | push @warnings, "codex.$key: a table cannot replace the $key key; dropped"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 111 | ▶ | if ( _is_mapping($v) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 17 | my $t = js_ordered(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 17 | for my $sk ( keys %$v ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 28 | my ( $leaf, $reason ) = _toml_leaf( $v->{$sk} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 28 | ▶ | if ( defined $reason ) { push @warnings, "codex.$key.$sk: $reason; dropped" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 22 | else { $t->{$sk} = $leaf } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 17 | $tables->{$key} = $t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 17 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 94 | my ( $leaf, $reason ) = _toml_leaf($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 94 | ▶ | if ( defined $reason ) { push @warnings, "codex.$key: $reason; dropped" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 8 | elsif ( $key eq 'developer_instructions' ) { $instructions = $leaf } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 77 | else { $top->{$key} = $leaf } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 173 | ▶ | _fail('name must be a non-empty string') unless js_type( $top->{name} ) eq 'string' && js_trim( $top->{name} ) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
js_type($top->{"name"}) eq "string" and js_trim($top->{"name"}) ne ""
MC/DC100%2/2
js_type($top->{"name"}) eq "string" and js_trim($top->{"name"}) ne ""
js_type($top->{"name"}) eq "string"
js_trim($top->{"name"}) ne ""
Truth table100%3/3
A and B
A= js_type($top->{"name"}) eq "string"B= js_trim($top->{"name"}) ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 160 | ▶ | unless ( js_type( $top->{description} ) eq 'string' && js_trim( $top->{description} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
js_type($top->{"description"}) eq "string" and js_trim($top->{"description"}) ne ""
MC/DC100%2/2
js_type($top->{"description"}) eq "string" and js_trim($top->{"description"}) ne ""
js_type($top->{"description"}) eq "string"
js_trim($top->{"description"}) ne ""
Truth table100%3/3
A and B
A= js_type($top->{"description"}) eq "string"B= js_trim($top->{"description"}) ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 17 | _fail('has no description (Codex rejects an agent role without one)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 143 | ▶ | _fail('developer_instructions must be a string') unless js_type($instructions) eq 'string'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 140 | ▶ | return { warnings => \@warnings } if js_trim($instructions) eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # $top holds no tables, so its keys come out first; the briefing line sits between them and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # developer_instructions, never inside the multi-line string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 127 | my $rest = js_ordered( developer_instructions => $instructions ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 127 | $rest->{$_} = $tables->{$_} for keys %$tables; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 127 | ▶ | my $text = stringify_toml($top).( $briefing // '' ).stringify_toml( $rest, { multiline => ['developer_instructions'] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$briefing // ""
MC/DC100%1/1
$briefing // ""
$briefing
Truth table100%2/2
A
A= $briefing
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 124 | return { toml => $text, warnings => \@warnings }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1224 | ▶ | sub codex_rule_section { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
codex_rule_section: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1224 | my ( $markdown, $item_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1224 | my $fm = _split($markdown); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1221 | ▶ | return undef if js_trim( $fm->{body} ) eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1218 | ▶ | if ( grep { js_trim($_) =~ MARKER_LINE } split /\n/, $fm->{body}, -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 14 | _fail( 'rule '.$item_name.' contains a skilletor marker line; it would break the rules file' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1204 | my $raw = $fm->{data}{paths}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1204 | ▶ | my @paths = map { _js_string($_) } js_type($raw) eq 'array' ? @$raw : defined $raw ? ($raw) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1204 | ▶ | my $lead = @paths ? 'Applies when working with files matching: '.join( ', ', map { "`$_`" } @paths ).".\n\n" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1204 | return normalize_section( $lead.$fm->{body} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1186 | ▶ | sub _file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_file: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1186 | my ( $output, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1186 | for my $f (@$output) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1185 | ▶ | return $f->[1] if $f->[0] eq $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 5202 | ▶ | sub convert_for_target { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_for_target: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 5202 | my ( $harness, $type, $name, $output ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 5202 | ▶ | if ( $harness eq 'codex' && $type eq 'rule' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$harness eq "codex" and $type eq "rule"
MC/DC100%2/2
$harness eq "codex" and $type eq "rule"
$harness eq "codex"
$type eq "rule"
Truth table100%3/3
A and B
A= $harness eq "codex"B= $type eq "rule"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1160 | my $md = _file( $output, "rules/$name.md" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1160 | ▶ | _fail("rules/$name.md missing from the build") unless defined $md; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1159 | my $section = codex_rule_section( decode_utf8_lossy($md), $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1157 | ▶ | output => [ defined $section ? [ RULES_FILE, encode_text($section) ] : () ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | skipped => defined $section ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | warnings => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4042 | ▶ | return { output => $output, skipped => 0, warnings => [] } unless $harness eq 'codex' && $type eq 'agent'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$harness eq "codex" and $type eq "agent"
MC/DC100%2/2
$harness eq "codex" and $type eq "agent"
$harness eq "codex"
$type eq "agent"
Truth table100%3/3
A and B
A= $harness eq "codex"B= $type eq "agent"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 26 | my $md = _file( $output, "agents/$name.md" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 26 | ▶ | _fail("agents/$name.md missing from the build") unless defined $md; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 24 | my $conv = codex_agent_toml( decode_utf8_lossy($md), $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 22 | my $toml = $conv->{toml}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | output => [ defined $toml ? [ "agents/$name.toml", encode_text($toml) ] : () ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | skipped => defined $toml ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | warnings => $conv->{warnings}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 22 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 400 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||