| 1 | # ex:ts=8 sw=4: | ||||||||||||||||||||||||||||||||
| 2 | # $OpenBSD$ | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | # Copyright (c) 2026 Dick Olsson <hi@senzilla.io> | ||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||
| 6 | # Permission to use, copy, modify, and distribute this software for any | ||||||||||||||||||||||||||||||||
| 7 | # purpose with or without fee is hereby granted, provided that the above | ||||||||||||||||||||||||||||||||
| 8 | # copyright notice and this permission notice appear in all copies. | ||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||
| 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||||||||||||||||||||||||||||||
| 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||||||||||||||||||||||||||||||
| 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||||||||||||||||||||||||||||||
| 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||||||||||||||||||||||||||||||
| 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||||||||||||||||||||||||||||||
| 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||||||||||||||||||||||||||||||
| 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | package App::FuguBench::Traces; | ||||||||||||||||||||||||||||||||
| 19 | 117 | our $VERSION = '0.1.1'; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 117 | ▶ | use v5.34; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 117 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 117 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 117 | ▶ | no feature qw(indirect multidimensional bareword_filehandles); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 117 | ▶ | use Cwd (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 117 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | 117 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 29 | 117 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 117 | ▶ | use Fugu::CLI qw(EXIT_SUCCESS EXIT_ERROR); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 32 | 117 | ▶ | use Fugu::Sandbox; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | # App::FuguBench::Traces - the traces verb. | ||||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||||
| 36 | # The verb measures the Claude Code sessions of one checkout. Claude | ||||||||||||||||||||||||||||||||
| 37 | # Code keeps one trace directory for each working directory, under | ||||||||||||||||||||||||||||||||
| 38 | # ~/.claude/projects/. The name of the directory is the absolute path | ||||||||||||||||||||||||||||||||
| 39 | # of the working directory, and the harness replaces each character | ||||||||||||||||||||||||||||||||
| 40 | # outside a letter, a digit and a hyphen with a hyphen. | ||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||
| 42 | # The verb derives that name from the checkout root, it matches the | ||||||||||||||||||||||||||||||||
| 43 | # trace directories of the checkout, and it prints one line for each | ||||||||||||||||||||||||||||||||
| 44 | # session in them that holds a request. | ||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||
| 46 | # The derivation cuts the root at the last .claude/worktrees/ marker, | ||||||||||||||||||||||||||||||||
| 47 | # because a nested checkout holds the marker more than one time | ||||||||||||||||||||||||||||||||
| 48 | # (TRACE-NAME-1). Three name forms belong to one checkout: the | ||||||||||||||||||||||||||||||||
| 49 | # checkout itself, a worktree of it, and a project clone in either of | ||||||||||||||||||||||||||||||||
| 50 | # them. The match takes the exact forms, so a sibling checkout, such | ||||||||||||||||||||||||||||||||
| 51 | # as a backup, stays out (TRACE-NAME-2). | ||||||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||||||
| 53 | # The option --root names a trace root in place of the one under the | ||||||||||||||||||||||||||||||||
| 54 | # home of the operator. The option --name replaces the derived name | ||||||||||||||||||||||||||||||||
| 55 | # (TRACE-NAME-3). | ||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||
| 57 | # The columns are: | ||||||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||||||
| 59 | # session the first eight characters of the session identifier | ||||||||||||||||||||||||||||||||
| 60 | # start the time of the first record of the session, in UTC | ||||||||||||||||||||||||||||||||
| 61 | # reqs the requests of the main session | ||||||||||||||||||||||||||||||||
| 62 | # peak the largest context of one request: the fresh input | ||||||||||||||||||||||||||||||||
| 63 | # tokens, the cache writes and the cache reads | ||||||||||||||||||||||||||||||||
| 64 | # out the output tokens of the main session, thinking | ||||||||||||||||||||||||||||||||
| 65 | # included | ||||||||||||||||||||||||||||||||
| 66 | # panel the rounds of the review panel | ||||||||||||||||||||||||||||||||
| 67 | # edits the file edits of the main session after the first | ||||||||||||||||||||||||||||||||
| 68 | # panel launch: a file inside the checkout, outside | ||||||||||||||||||||||||||||||||
| 69 | # scratch/ and SCRATCHPAD*.md | ||||||||||||||||||||||||||||||||
| 70 | # sub-in the input tokens of every sub-agent of the session | ||||||||||||||||||||||||||||||||
| 71 | # sub-out the output tokens of every sub-agent | ||||||||||||||||||||||||||||||||
| 72 | # rev-peak the largest peak context of one panel reviewer | ||||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||||
| 74 | # One request writes one record for each content block, and each | ||||||||||||||||||||||||||||||||
| 75 | # record carries the usage of the whole request. An early record can | ||||||||||||||||||||||||||||||||
| 76 | # carry a partial count, so the verb takes the usage of the last | ||||||||||||||||||||||||||||||||
| 77 | # record of a request (TRACE-USAGE-1). A tool_use block appears in one | ||||||||||||||||||||||||||||||||
| 78 | # record only, so each block counts one time. | ||||||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||||||
| 80 | # The sub-in and sub-out columns hold every sub-agent together, so | ||||||||||||||||||||||||||||||||
| 81 | # neither one measures one reviewer (TRACE-SUB-1). A panel launch is a | ||||||||||||||||||||||||||||||||
| 82 | # tool_use block with an identifier, and each sub-agent trace has a | ||||||||||||||||||||||||||||||||
| 83 | # sibling <agent>.meta.json that carries the identifier of its launch. | ||||||||||||||||||||||||||||||||
| 84 | # The rev-peak column maps the launch identifiers of the panel to | ||||||||||||||||||||||||||||||||
| 85 | # their traces, and it reports the largest peak of them (TRACE-SUB-2). | ||||||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||||||
| 87 | # This verb and the hook verb hold the Claude Code assumptions of the | ||||||||||||||||||||||||||||||||
| 88 | # program, and every other verb is agent-agnostic (D-10). | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | # The marker of a worktree path, and the trace root of the harness | ||||||||||||||||||||||||||||||||
| 91 | # under the home of the operator. | ||||||||||||||||||||||||||||||||
| 92 | 117 | ▶ | use constant MARKER => '/.claude/worktrees/'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 93 | 117 | ▶ | use constant PROJECTS => '.claude/projects'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | # The format of one line. The columns are session, start, reqs, peak, | ||||||||||||||||||||||||||||||||
| 96 | # out, panel, edits, sub-in, sub-out and rev-peak (TRACE-COLUMNS-2). | ||||||||||||||||||||||||||||||||
| 97 | # The format lives in a variable: on the floor perl, printf reads a | ||||||||||||||||||||||||||||||||
| 98 | # bareword in that place as a filehandle, and the pragma block of the | ||||||||||||||||||||||||||||||||
| 99 | # file forbids one. | ||||||||||||||||||||||||||||||||
| 100 | 117 | my $ROW = "%-8s %-16s %6s %8s %8s %6s %6s %10s %10s %8s\n"; | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | # The tools that change a file. The panel reviews a commit, so an edit | ||||||||||||||||||||||||||||||||
| 103 | # of the main session after the first launch of a round is an edit | ||||||||||||||||||||||||||||||||
| 104 | # that no reviewer saw (TRACE-PANEL-3). | ||||||||||||||||||||||||||||||||
| 105 | 117 | my %EDIT = map { $_ => 1 } qw(Edit Write MultiEdit NotebookEdit); | |||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | # The scratch space of the repository. The panel writes its ledger | ||||||||||||||||||||||||||||||||
| 108 | # under scratch/, an audit writes its findings to a SCRATCHPAD-<N>.md | ||||||||||||||||||||||||||||||||
| 109 | # file, and .gitignore holds both. The name must start a path segment | ||||||||||||||||||||||||||||||||
| 110 | # and the scratchpad must end the path, so myscratch/x.md, | ||||||||||||||||||||||||||||||||
| 111 | # NOTSCRATCHPAD.md and SCRATCHPAD-3.md.bak stay edits. | ||||||||||||||||||||||||||||||||
| 112 | 117 | my $SCRATCH = qr{(?:\A|/)(?:scratch/|SCRATCHPAD[^/]*\.md\z)}; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | # The tools that launch a sub-agent, and the agent types that name no | ||||||||||||||||||||||||||||||||
| 115 | # role. A launch of a catch-all type carries the role of the agent in | ||||||||||||||||||||||||||||||||
| 116 | # its description only (TRACE-PANEL-1). | ||||||||||||||||||||||||||||||||
| 117 | 117 | my %LAUNCH = map { $_ => 1 } qw(Agent Task); | |||||||||||||||||||||||||||||||
| 118 | 117 | my %CATCHALL = map { $_ => 1 } qw(general-purpose claude); | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | # The decoder of one record. It takes the bytes of a line, and it | ||||||||||||||||||||||||||||||||
| 121 | # decodes the UTF-8 itself. An :encoding layer loads the | ||||||||||||||||||||||||||||||||
| 122 | # PerlIO::encoding extension at the first open, and `stdio rpath` | ||||||||||||||||||||||||||||||||
| 123 | # gives no promise for the load of a shared object. | ||||||||||||||||||||||||||||||||
| 124 | 117 | my $JSON = JSON::PP->new->utf8; | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | # App::FuguBench::Traces->command($verb): | ||||||||||||||||||||||||||||||||
| 127 | # The entry of the Fugu::CLI table. The module holds one verb, | ||||||||||||||||||||||||||||||||
| 128 | # so it ignores the name. | ||||||||||||||||||||||||||||||||
| 129 | 117 | ▶ | sub command ( $, $ ) | ||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||||||
| 131 | return { | ||||||||||||||||||||||||||||||||
| 132 | summary => 'measure the sessions of the checkout', | ||||||||||||||||||||||||||||||||
| 133 | usage => '[--root <dir>] [--name <name>]', | ||||||||||||||||||||||||||||||||
| 134 | options => { | ||||||||||||||||||||||||||||||||
| 135 | 'root=s' => 'the trace root, in place of the one' | ||||||||||||||||||||||||||||||||
| 136 | . ' under the home', | ||||||||||||||||||||||||||||||||
| 137 | 'name=s' => 'the checkout name, in place of the' | ||||||||||||||||||||||||||||||||
| 138 | . ' derived one', | ||||||||||||||||||||||||||||||||
| 139 | }, | ||||||||||||||||||||||||||||||||
| 140 | 10 | ▶ | run => sub ( $app, @argv ) { return _run( $app, @argv ) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 141 | 117 | }; | |||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | # App::FuguBench::Traces->unveil_paths($app): | ||||||||||||||||||||||||||||||||
| 145 | # The unveil list of the sandbox row (CLI-SANDBOX-2). The verb | ||||||||||||||||||||||||||||||||
| 146 | # opens the trace files itself and runs no child, so its row | ||||||||||||||||||||||||||||||||
| 147 | # names each path that the verb reads after the entry, and it | ||||||||||||||||||||||||||||||||
| 148 | # names nothing else. | ||||||||||||||||||||||||||||||||
| 149 | # | ||||||||||||||||||||||||||||||||
| 150 | # perl loads a module on an error path, so the list holds the | ||||||||||||||||||||||||||||||||
| 151 | # library directories of the interpreter. Each one is optional, | ||||||||||||||||||||||||||||||||
| 152 | # because the build of a perl records a directory that the host | ||||||||||||||||||||||||||||||||
| 153 | # can omit. | ||||||||||||||||||||||||||||||||
| 154 | # | ||||||||||||||||||||||||||||||||
| 155 | # The trace root is optional too. The verb reports an absent | ||||||||||||||||||||||||||||||||
| 156 | # root itself, with the path in the message, and a required | ||||||||||||||||||||||||||||||||
| 157 | # entry would die in front of that report. | ||||||||||||||||||||||||||||||||
| 158 | # | ||||||||||||||||||||||||||||||||
| 159 | # The verb resolves the real path of the checkout root after the | ||||||||||||||||||||||||||||||||
| 160 | # entry, so the row names the root. The unveil list names that | ||||||||||||||||||||||||||||||||
| 161 | # root, so the walk to the .toolingrc runs here, in front of the | ||||||||||||||||||||||||||||||||
| 162 | # entry. Every run reads the checkout, | ||||||||||||||||||||||||||||||||
| 163 | # because the edit boundary comes from it and --name leaves that | ||||||||||||||||||||||||||||||||
| 164 | # boundary alone (TRACE-PANEL-3). | ||||||||||||||||||||||||||||||||
| 165 | 10 | ▶ | sub unveil_paths ( $, $app ) | ||||||||||||||||||||||||||||||
|
Subroutine
unveil_paths: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||
| 167 | my @paths = | ||||||||||||||||||||||||||||||||
| 168 | 10 | map { [ $_, 'r', { optional => 1 } ] } Fugu::Sandbox->perl_lib_dirs; | |||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 10 | my $checkout = $app->checkout; | |||||||||||||||||||||||||||||||
| 171 | 10 | ▶ | push @paths, [ $checkout->root, 'r' ] if $checkout; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | 10 | push @paths, [ _trace_root($app), 'r', { optional => 1 } ]; | |||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 10 | return @paths; | |||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | # _run($app, @argv): | ||||||||||||||||||||||||||||||||
| 179 | # The body of the verb. It takes no argument, and an argument | ||||||||||||||||||||||||||||||||
| 180 | # is a usage error. | ||||||||||||||||||||||||||||||||
| 181 | # | ||||||||||||||||||||||||||||||||
| 182 | # The rows sort by start time, under one header. A session with | ||||||||||||||||||||||||||||||||
| 183 | # no request gets no row, and a name that matches no directory | ||||||||||||||||||||||||||||||||
| 184 | # gives the one line that says so (TRACE-COLUMNS-1). | ||||||||||||||||||||||||||||||||
| 185 | 10 | ▶ | sub _run ( $app, @argv ) | ||||||||||||||||||||||||||||||
|
Subroutine
_run: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||||||
| 187 | 10 | ▶ | return $app->cli->command_usage_error('traces') if @argv; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | 8 | my $log = $app->cli->log; | |||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | # The checkout comes first. A start under no .toolingrc is a | ||||||||||||||||||||||||||||||||
| 192 | # configuration error (CLI-CHECKOUT-3), and the trace root | ||||||||||||||||||||||||||||||||
| 193 | # under the home of the operator is absent on a host that runs | ||||||||||||||||||||||||||||||||
| 194 | # no Claude Code. The other order hides the configuration | ||||||||||||||||||||||||||||||||
| 195 | # error behind a failure there. | ||||||||||||||||||||||||||||||||
| 196 | 8 | my ( $code, $checkout ) = _checkout_path($app); | |||||||||||||||||||||||||||||||
| 197 | 8 | ▶ | return $code if $code != EXIT_SUCCESS; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 7 | my $root = _trace_root($app); | |||||||||||||||||||||||||||||||
| 200 | 7 | ▶ | unless ( -d $root ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | 1 | $log->error( 'no such trace root: %s', $root ); | |||||||||||||||||||||||||||||||
| 202 | 1 | return EXIT_ERROR; | |||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 6 | ▶ | my $name = $app->cli->option('name') | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$app->cli->option("name") // $checkout =~ s/[^A-Za-z0-9-]/-/gru
MC/DC0%0/2
$app->cli->option("name") // $checkout =~ s/[^A-Za-z0-9-]/-/gru
$app->cli->option("name")
$checkout =~ s/[^A-Za-z0-9-]/-/gru
Truth table66%2/3
A // B
A= $app->cli->option("name")B= $checkout =~ s/[^A-Za-z0-9-]/-/gru
| |||||||||||||||||||||||||||||||||
| 206 | // ( $checkout =~ s/[^A-Za-z0-9-]/-/gr ); | ||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 6 | ▶ | opendir my $dh, $root or do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 209 | 0 | $log->error( 'cannot read %s: %s', $root, $! ); | |||||||||||||||||||||||||||||||
| 210 | 0 | return EXIT_ERROR; | |||||||||||||||||||||||||||||||
| 211 | }; | ||||||||||||||||||||||||||||||||
| 212 | 6 | my $match = _match($name); | |||||||||||||||||||||||||||||||
| 213 | 6 | ▶ | my @dirs = sort grep { /$match/ && -d "$root/$_" } readdir $dh; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
/$match/u && -d "$root/$_"
MC/DC50%1/2
/$match/u && -d "$root/$_"
/$match/u
-d "$root/$_"
Truth table66%2/3
A && B
A= /$match/uB= -d "$root/$_"
| |||||||||||||||||||||||||||||||||
| 214 | 6 | closedir $dh; | |||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | 6 | my @rows; | |||||||||||||||||||||||||||||||
| 217 | 6 | push @rows, _sessions( "$root/$_", $checkout ) for @dirs; | |||||||||||||||||||||||||||||||
| 218 | 6 | ▶ | unless (@rows) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | 3 | say "no session of $name"; | |||||||||||||||||||||||||||||||
| 220 | 3 | return EXIT_SUCCESS; | |||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | 3 | printf $ROW, qw(session start reqs peak out panel edits sub-in | |||||||||||||||||||||||||||||||
| 224 | sub-out rev-peak); | ||||||||||||||||||||||||||||||||
| 225 | 3 | for my $row ( sort { $a->{start} cmp $b->{start} } @rows ) { | |||||||||||||||||||||||||||||||
| 226 | printf $ROW, substr( $row->{id}, 0, 8 ), | ||||||||||||||||||||||||||||||||
| 227 | substr( $row->{start}, 0, 16 ), $row->{reqs}, | ||||||||||||||||||||||||||||||||
| 228 | $row->{peak}, $row->{out}, $row->{panel}, $row->{edits}, | ||||||||||||||||||||||||||||||||
| 229 | 11 | $row->{sub_in}, $row->{sub_out}, $row->{rev_peak}; | |||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 3 | return EXIT_SUCCESS; | |||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | # _trace_root($app): | ||||||||||||||||||||||||||||||||
| 236 | # The trace root of the run: the --root value, or the directory | ||||||||||||||||||||||||||||||||
| 237 | # of the harness under the home of the operator. | ||||||||||||||||||||||||||||||||
| 238 | 17 | ▶ | sub _trace_root ($app) | ||||||||||||||||||||||||||||||
|
Subroutine
_trace_root: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||||
| 240 | 17 | my $root = $app->cli->option('root'); | |||||||||||||||||||||||||||||||
| 241 | 17 | ▶ | return $root if defined $root; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | return File::Spec->catdir( $ENV{HOME} // q{.}, PROJECTS ); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"HOME"} // "."
MC/DC0%0/1
$ENV{"HOME"} // "."
$ENV{"HOME"}
Truth table50%1/2
A
A= $ENV{"HOME"}
| |||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | # _checkout_path($app): | ||||||||||||||||||||||||||||||||
| 247 | # The exit code and the path of the checkout, in that order. The | ||||||||||||||||||||||||||||||||
| 248 | # code is EXIT_SUCCESS when the path holds a value, and the | ||||||||||||||||||||||||||||||||
| 249 | # method reports every failure itself. | ||||||||||||||||||||||||||||||||
| 250 | # | ||||||||||||||||||||||||||||||||
| 251 | # The path is the real path of the checkout root, cut at the | ||||||||||||||||||||||||||||||||
| 252 | # last marker (TRACE-NAME-1). The trace name comes from it, with | ||||||||||||||||||||||||||||||||
| 253 | # each character outside a letter, a digit and a hyphen replaced | ||||||||||||||||||||||||||||||||
| 254 | # by a hyphen. The edits column takes a file inside the path | ||||||||||||||||||||||||||||||||
| 255 | # only, and --name leaves that boundary alone (TRACE-PANEL-3), | ||||||||||||||||||||||||||||||||
| 256 | # so every run reads the checkout. | ||||||||||||||||||||||||||||||||
| 257 | # | ||||||||||||||||||||||||||||||||
| 258 | # A worktree holds a .toolingrc of its own, so the walk stops in | ||||||||||||||||||||||||||||||||
| 259 | # the worktree and the cut reaches the checkout. CLI-CHECKOUT-4 | ||||||||||||||||||||||||||||||||
| 260 | # names this cut as the one exception. | ||||||||||||||||||||||||||||||||
| 261 | 8 | ▶ | sub _checkout_path ($app) | ||||||||||||||||||||||||||||||
|
Subroutine
_checkout_path: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||||||
| 263 | 8 | ▶ | my $checkout = $app->checkout | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 264 | or return Fugu::CLI::EXIT_CONFIG_ERROR(); | ||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||
| 266 | 7 | my $path = Cwd::abs_path( $checkout->root ); | |||||||||||||||||||||||||||||||
| 267 | 7 | ▶ | unless ( defined $path ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 268 | 0 | $app->cli->log->error( 'cannot resolve %s', $checkout->root ); | |||||||||||||||||||||||||||||||
| 269 | 0 | return EXIT_ERROR; | |||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | 7 | my $at = rindex $path, MARKER; | |||||||||||||||||||||||||||||||
| 273 | 7 | ▶ | $path = substr $path, 0, $at if $at >= 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||
| 275 | 7 | return ( EXIT_SUCCESS, $path ); | |||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | # _match($name): | ||||||||||||||||||||||||||||||||
| 279 | # The pattern of the trace directories of one checkout: the | ||||||||||||||||||||||||||||||||
| 280 | # checkout itself, each worktree of it, and each project clone | ||||||||||||||||||||||||||||||||
| 281 | # in either of them (TRACE-NAME-2). The pattern takes the whole | ||||||||||||||||||||||||||||||||
| 282 | # name, so a sibling of the checkout stays out. | ||||||||||||||||||||||||||||||||
| 283 | 6 | ▶ | sub _match ($name) | ||||||||||||||||||||||||||||||
|
Subroutine
_match: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 284 | { | ||||||||||||||||||||||||||||||||
| 285 | 6 | my $token = qr{[A-Za-z0-9-]+}; | |||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 6 | return qr{ | |||||||||||||||||||||||||||||||
| 288 | \A\Q$name\E | ||||||||||||||||||||||||||||||||
| 289 | (?:--claude-worktrees-$token)? | ||||||||||||||||||||||||||||||||
| 290 | (?:-Projects-$token)? | ||||||||||||||||||||||||||||||||
| 291 | \z | ||||||||||||||||||||||||||||||||
| 292 | }x; | ||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | # _sessions($dir, $checkout): | ||||||||||||||||||||||||||||||||
| 296 | # One row for each session of one trace directory. A session | ||||||||||||||||||||||||||||||||
| 297 | # with no request never reached the model, so it gets no row | ||||||||||||||||||||||||||||||||
| 298 | # (TRACE-COLUMNS-1). | ||||||||||||||||||||||||||||||||
| 299 | # | ||||||||||||||||||||||||||||||||
| 300 | # A sub-agent of a workflow gets a directory of its own. The | ||||||||||||||||||||||||||||||||
| 301 | # sub-agent columns hold every sub-agent of the session | ||||||||||||||||||||||||||||||||
| 302 | # (TRACE-SUB-1). The launch identifiers of the panel select the | ||||||||||||||||||||||||||||||||
| 303 | # reviewers among them, so rev-peak takes the largest peak of | ||||||||||||||||||||||||||||||||
| 304 | # one reviewer (TRACE-SUB-2). | ||||||||||||||||||||||||||||||||
| 305 | 5 | ▶ | sub _sessions ( $dir, $checkout ) | ||||||||||||||||||||||||||||||
|
Subroutine
_sessions: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 306 | { | ||||||||||||||||||||||||||||||||
| 307 | 5 | my @rows; | |||||||||||||||||||||||||||||||
| 308 | 5 | for my $path ( _jsonl($dir) ) { | |||||||||||||||||||||||||||||||
| 309 | 12 | my $row = _tally( $path, $checkout ); | |||||||||||||||||||||||||||||||
| 310 | 12 | ▶ | next unless $row->{reqs}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | 11 | my $id = basename($path) =~ s/\.jsonl\z//r; | |||||||||||||||||||||||||||||||
| 313 | 11 | my $sub = "$dir/$id/subagents"; | |||||||||||||||||||||||||||||||
| 314 | 11 | my ( $in, $out, $rev ) = ( 0, 0, 0 ); | |||||||||||||||||||||||||||||||
| 315 | 11 | for my $file ( _jsonl($sub), | |||||||||||||||||||||||||||||||
| 316 | 1 | map { _jsonl($_) } _subdirs("$sub/workflows") ) | |||||||||||||||||||||||||||||||
| 317 | { | ||||||||||||||||||||||||||||||||
| 318 | 4 | my $agent = _tally( $file, $checkout ); | |||||||||||||||||||||||||||||||
| 319 | 4 | $in += $agent->{in}; | |||||||||||||||||||||||||||||||
| 320 | 4 | $out += $agent->{out}; | |||||||||||||||||||||||||||||||
| 321 | $rev = $agent->{peak} | ||||||||||||||||||||||||||||||||
| 322 | if $agent->{peak} > $rev | ||||||||||||||||||||||||||||||||
| 323 | 4 | ▶ | && $row->{launches}{ _meta_id($file) }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$agent->{"peak"} > $rev and $row->{"launches"}{_meta_id($file)}
MC/DC50%1/2
$agent->{"peak"} > $rev and $row->{"launches"}{_meta_id($file)}
$agent->{"peak"} > $rev
$row->{"launches"}{_meta_id($file)}
Truth table66%2/3
A and B
A= $agent->{"peak"} > $revB= $row->{"launches"}{_meta_id($file)}
| |||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||
| 326 | 11 | @{$row}{qw(id sub_in sub_out rev_peak)} = | |||||||||||||||||||||||||||||||
| 327 | ( $id, $in, $out, $rev ); | ||||||||||||||||||||||||||||||||
| 328 | 11 | push @rows, $row; | |||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | 5 | return @rows; | |||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||
| 334 | # _jsonl($dir): | ||||||||||||||||||||||||||||||||
| 335 | # The trace files directly in one directory. A directory that no | ||||||||||||||||||||||||||||||||
| 336 | # reader can open holds none. | ||||||||||||||||||||||||||||||||
| 337 | 17 | ▶ | sub _jsonl ($dir) | ||||||||||||||||||||||||||||||
|
Subroutine
_jsonl: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 338 | { | ||||||||||||||||||||||||||||||||
| 339 | 17 | ▶ | opendir my $dh, $dir or return (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 340 | 8 | ▶ | my @names = sort grep { /\.jsonl\z/ && -f "$dir/$_" } readdir $dh; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
/\.jsonl\z/u && -f "$dir/$_"
MC/DC50%1/2
/\.jsonl\z/u && -f "$dir/$_"
/\.jsonl\z/u
-f "$dir/$_"
Truth table66%2/3
A && B
A= /\.jsonl\z/uB= -f "$dir/$_"
| |||||||||||||||||||||||||||||||||
| 341 | 8 | closedir $dh; | |||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||
| 343 | 8 | return map { "$dir/$_" } @names; | |||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||
| 346 | # _subdirs($dir): | ||||||||||||||||||||||||||||||||
| 347 | # The subdirectories of one directory, without the hidden ones. | ||||||||||||||||||||||||||||||||
| 348 | 11 | ▶ | sub _subdirs ($dir) | ||||||||||||||||||||||||||||||
|
Subroutine
_subdirs: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||||||
| 350 | 11 | ▶ | opendir my $dh, $dir or return (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | my @names = sort grep { !/\A[.]/ && -d "$dir/$_" } readdir $dh; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
!/\A[.]/u && -d "$dir/$_"
MC/DC50%1/2
!/\A[.]/u && -d "$dir/$_"
!/\A[.]/u
-d "$dir/$_"
Truth table66%2/3
not(A) && B
A= !/\A[.]/uB= -d "$dir/$_"
| |||||||||||||||||||||||||||||||||
| 352 | 1 | closedir $dh; | |||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||
| 354 | 1 | return map { "$dir/$_" } @names; | |||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||
| 357 | # _tally($path, $checkout): | ||||||||||||||||||||||||||||||||
| 358 | # The measures of one trace file. A file that no reader can open | ||||||||||||||||||||||||||||||||
| 359 | # gives the empty measures, and the caller drops the session. | ||||||||||||||||||||||||||||||||
| 360 | # | ||||||||||||||||||||||||||||||||
| 361 | # The start time comes from the first record that carries one, | ||||||||||||||||||||||||||||||||
| 362 | # whatever the type of that record. After that the reader | ||||||||||||||||||||||||||||||||
| 363 | # decodes an assistant record only, because a full parse of | ||||||||||||||||||||||||||||||||
| 364 | # every record costs minutes over a long history | ||||||||||||||||||||||||||||||||
| 365 | # (TRACE-USAGE-2). Every usage block and every tool_use block | ||||||||||||||||||||||||||||||||
| 366 | # sits in an assistant record, and every one of those records | ||||||||||||||||||||||||||||||||
| 367 | # holds the word `assistant`, so the filter loses no count. | ||||||||||||||||||||||||||||||||
| 368 | # | ||||||||||||||||||||||||||||||||
| 369 | # A line that fails to decode is no record. | ||||||||||||||||||||||||||||||||
| 370 | # | ||||||||||||||||||||||||||||||||
| 371 | # One request writes one record for each content block, and an | ||||||||||||||||||||||||||||||||
| 372 | # early record of it can carry a partial count, so the tally | ||||||||||||||||||||||||||||||||
| 373 | # keeps the usage of the last record of each request | ||||||||||||||||||||||||||||||||
| 374 | # (TRACE-USAGE-1). | ||||||||||||||||||||||||||||||||
| 375 | 16 | ▶ | sub _tally ( $path, $checkout ) | ||||||||||||||||||||||||||||||
|
Subroutine
_tally: called CC=27 SCAR=33.7
| |||||||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||||||
| 377 | 16 | my %row = ( | |||||||||||||||||||||||||||||||
| 378 | start => q{}, | ||||||||||||||||||||||||||||||||
| 379 | reqs => 0, | ||||||||||||||||||||||||||||||||
| 380 | peak => 0, | ||||||||||||||||||||||||||||||||
| 381 | in => 0, | ||||||||||||||||||||||||||||||||
| 382 | out => 0, | ||||||||||||||||||||||||||||||||
| 383 | panel => 0, | ||||||||||||||||||||||||||||||||
| 384 | edits => 0, | ||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | # The identifiers of the panel launches of the file. | ||||||||||||||||||||||||||||||||
| 387 | launches => {}, | ||||||||||||||||||||||||||||||||
| 388 | ); | ||||||||||||||||||||||||||||||||
| 389 | 16 | ▶ | open my $fh, '<', $path or return \%row; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||
| 391 | 16 | my ( %usage, @order, %round ); | |||||||||||||||||||||||||||||||
| 392 | 16 | my $launched = 0; | |||||||||||||||||||||||||||||||
| 393 | 16 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 394 | 29 | my $rec; | |||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | 29 | ▶ | if ( !length $row{start} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 397 | 16 | $rec = eval { $JSON->decode($line) }; | |||||||||||||||||||||||||||||||
| 398 | 16 | ▶ | $row{start} = $rec->{timestamp} // q{} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$rec->{"timestamp"} // ""
MC/DC0%0/1
$rec->{"timestamp"} // ""
$rec->{"timestamp"}
Truth table50%1/2
A
A= $rec->{"timestamp"}
| |||||||||||||||||||||||||||||||||
| 399 | if ref $rec eq 'HASH'; | ||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | 29 | ▶ | $rec = eval { $JSON->decode($line) } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $rec and index($line, "assistant") != -1
MC/DC100%2/2
not defined $rec and index($line, "assistant") != -1
not defined $rec
index($line, "assistant") != -1
Truth table100%3/3
not(A) and B
A= not defined $recB= index($line, "assistant") != -1
| |||||||||||||||||||||||||||||||||
| 403 | if !defined $rec && index( $line, 'assistant' ) >= 0; | ||||||||||||||||||||||||||||||||
| 404 | next | ||||||||||||||||||||||||||||||||
| 405 | unless ref $rec eq 'HASH' | ||||||||||||||||||||||||||||||||
| 406 | 29 | ▶ | && ( $rec->{type} // q{} ) eq 'assistant'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
ref $rec eq "HASH" and ($rec->{"type"} // "") eq "assistant"
$rec->{"type"} // ""
MC/DC50%1/2
ref $rec eq "HASH" and ($rec->{"type"} // "") eq "assistant"
ref $rec eq "HASH"
$rec->{"type"}
Truth table66%2/3
A and B
A= ref $rec eq "HASH"B= $rec->{"type"}
| |||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | # An old trace carries no requestId, and its records | ||||||||||||||||||||||||||||||||
| 409 | # then count one by one, which is the safe direction. | ||||||||||||||||||||||||||||||||
| 410 | 26 | ▶ | my $req = $rec->{requestId} // $rec->{uuid} // q{}; | ||||||||||||||||||||||||||||||
|
Condition40%2/5
($rec->{"requestId"} // $rec->{"uuid"}) // ""
$rec->{"requestId"} // $rec->{"uuid"}
MC/DC0%0/2
($rec->{"requestId"} // $rec->{"uuid"}) // ""
$rec->{"requestId"}
$rec->{"uuid"}
Truth table33%1/3
A // B
A= $rec->{"requestId"}B= $rec->{"uuid"}
| |||||||||||||||||||||||||||||||||
| 411 | 26 | ▶ | push @order, $req unless exists $usage{$req}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 412 | 26 | $usage{$req} = _usage_of($rec); | |||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | 26 | ▶ | for my $block ( @{ $rec->{message}{content} // [] } ) { | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$rec->{"message"}{"content"} // []
MC/DC0%0/1
$rec->{"message"}{"content"} // []
$rec->{"message"}{"content"}
Truth table50%1/2
A
A= $rec->{"message"}{"content"}
| |||||||||||||||||||||||||||||||||
| 415 | 32 | ▶ | next unless ( $block->{type} // q{} ) eq 'tool_use'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$block->{"type"} // ""
MC/DC0%0/1
$block->{"type"} // ""
$block->{"type"}
Truth table50%1/2
A
A= $block->{"type"}
| |||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||
| 417 | 26 | ▶ | if ( _is_panel($block) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 418 | 8 | $launched = 1; | |||||||||||||||||||||||||||||||
| 419 | 8 | $round{$req} = 1; | |||||||||||||||||||||||||||||||
| 420 | $row{launches}{ $block->{id} } = 1 | ||||||||||||||||||||||||||||||||
| 421 | 8 | ▶ | if length( $block->{id} // q{} ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$block->{"id"} // ""
MC/DC0%0/1
$block->{"id"} // ""
$block->{"id"}
Truth table50%1/2
A
A= $block->{"id"}
| |||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||
| 423 | ▶ | elsif ( $launched | |||||||||||||||||||||||||||||||
|
Condition80%4/5
$launched and $EDIT{$block->{"name"} // ""}
$block->{"name"} // ""
MC/DC100%2/2
$launched and $EDIT{$block->{"name"} // ""}
$launched
$EDIT{$block->{"name"} // ""}
MC/DC0%0/1
$block->{"name"} // ""
$block->{"name"}
Truth table100%3/3
A and B
A= $launchedB= $EDIT{$block->{"name"} // ""}
Truth table50%1/2
A
A= $block->{"name"}
| |||||||||||||||||||||||||||||||||
| 424 | && $EDIT{ $block->{name} // q{} } ) | ||||||||||||||||||||||||||||||||
| 425 | { | ||||||||||||||||||||||||||||||||
| 426 | 12 | ▶ | $row{edits}++ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 427 | if _repo_edit( $block, $checkout ); | ||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||
| 431 | 16 | close $fh; | |||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||
| 433 | 16 | for my $req (@order) { | |||||||||||||||||||||||||||||||
| 434 | 23 | my ( $in, $out ) = @{ $usage{$req} }; | |||||||||||||||||||||||||||||||
| 435 | 23 | $row{in} += $in; | |||||||||||||||||||||||||||||||
| 436 | 23 | $row{out} += $out; | |||||||||||||||||||||||||||||||
| 437 | 23 | ▶ | $row{peak} = $in if $in > $row{peak}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||
| 439 | 16 | $row{reqs} = scalar @order; | |||||||||||||||||||||||||||||||
| 440 | 16 | $row{panel} = scalar keys %round; | |||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||
| 442 | 16 | return \%row; | |||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||
| 445 | # _usage_of($rec): | ||||||||||||||||||||||||||||||||
| 446 | # The context and the output of one request, in that order. The | ||||||||||||||||||||||||||||||||
| 447 | # context is the input that the request paid for: the fresh | ||||||||||||||||||||||||||||||||
| 448 | # input, the cache writes and the cache reads (TRACE-COLUMNS-3). | ||||||||||||||||||||||||||||||||
| 449 | 26 | ▶ | sub _usage_of ($rec) | ||||||||||||||||||||||||||||||
|
Subroutine
_usage_of: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||||||
| 450 | { | ||||||||||||||||||||||||||||||||
| 451 | 26 | ▶ | my $u = $rec->{message}{usage} // {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$rec->{"message"}{"usage"} // {}
MC/DC0%0/1
$rec->{"message"}{"usage"} // {}
$rec->{"message"}{"usage"}
Truth table50%1/2
A
A= $rec->{"message"}{"usage"}
| |||||||||||||||||||||||||||||||||
| 452 | my $in = | ||||||||||||||||||||||||||||||||
| 453 | ( $u->{input_tokens} // 0 ) + | ||||||||||||||||||||||||||||||||
| 454 | ( $u->{cache_creation_input_tokens} // 0 ) + | ||||||||||||||||||||||||||||||||
| 455 | 26 | ▶ | ( $u->{cache_read_input_tokens} // 0 ); | ||||||||||||||||||||||||||||||
|
Condition83%5/6
$u->{"input_tokens"} // 0
$u->{"cache_creation_input_tokens"} // 0
$u->{"cache_read_input_tokens"} // 0
MC/DC0%0/1
$u->{"input_tokens"} // 0
$u->{"input_tokens"}
MC/DC100%1/1
$u->{"cache_creation_input_tokens"} // 0
$u->{"cache_creation_input_tokens"}
MC/DC100%1/1
$u->{"cache_read_input_tokens"} // 0
$u->{"cache_read_input_tokens"}
Truth table50%1/2
A
A= $u->{"input_tokens"}
Truth table100%2/2
A
A= $u->{"cache_creation_input_tokens"}
Truth table100%2/2
A
A= $u->{"cache_read_input_tokens"}
| |||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||
| 457 | 26 | ▶ | return [ $in, $u->{output_tokens} // 0 ]; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$u->{"output_tokens"} // 0
MC/DC0%0/1
$u->{"output_tokens"} // 0
$u->{"output_tokens"}
Truth table50%1/2
A
A= $u->{"output_tokens"}
| |||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||
| 460 | # _repo_edit($block, $checkout): | ||||||||||||||||||||||||||||||||
| 461 | # True when one edit block changes a repository file. The target | ||||||||||||||||||||||||||||||||
| 462 | # is file_path, or notebook_path for a notebook. | ||||||||||||||||||||||||||||||||
| 463 | # | ||||||||||||||||||||||||||||||||
| 464 | # An absolute target must sit inside the checkout, on a | ||||||||||||||||||||||||||||||||
| 465 | # directory boundary, so a write to the home of the operator, or | ||||||||||||||||||||||||||||||||
| 466 | # to a sibling such as <checkout>-backup, is no repository file. | ||||||||||||||||||||||||||||||||
| 467 | # A relative target sits inside it, because the path resolves | ||||||||||||||||||||||||||||||||
| 468 | # against the working directory of the session. A block with no | ||||||||||||||||||||||||||||||||
| 469 | # target counts as an edit, which is the safe direction | ||||||||||||||||||||||||||||||||
| 470 | # (TRACE-PANEL-3). | ||||||||||||||||||||||||||||||||
| 471 | # | ||||||||||||||||||||||||||||||||
| 472 | # A target in scratch space is no repository file: a path under | ||||||||||||||||||||||||||||||||
| 473 | # scratch/, or a SCRATCHPAD*.md file. | ||||||||||||||||||||||||||||||||
| 474 | 12 | ▶ | sub _repo_edit ( $block, $checkout ) | ||||||||||||||||||||||||||||||
|
Subroutine
_repo_edit: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 475 | { | ||||||||||||||||||||||||||||||||
| 476 | 12 | ▶ | my $input = $block->{input} // {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$block->{"input"} // {}
MC/DC0%0/1
$block->{"input"} // {}
$block->{"input"}
Truth table50%1/2
A
A= $block->{"input"}
| |||||||||||||||||||||||||||||||||
| 477 | 12 | ▶ | my $path = $input->{file_path} // $input->{notebook_path} // q{}; | ||||||||||||||||||||||||||||||
|
Condition100%5/5
($input->{"file_path"} // $input->{"notebook_path"}) // ""
$input->{"file_path"} // $input->{"notebook_path"}
MC/DC100%2/2
($input->{"file_path"} // $input->{"notebook_path"}) // ""
$input->{"file_path"}
$input->{"notebook_path"}
Truth table100%3/3
A // B
A= $input->{"file_path"}B= $input->{"notebook_path"}
| |||||||||||||||||||||||||||||||||
| 478 | 12 | ▶ | return 0 if $path =~ m{\A/} && index( $path, "$checkout/" ) != 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$path =~ m[\A/]u and index($path, "$checkout/") != 0
MC/DC100%2/2
$path =~ m[\A/]u and index($path, "$checkout/") != 0
$path =~ m[\A/]u
index($path, "$checkout/") != 0
Truth table100%3/3
A and B
A= $path =~ m[\A/]uB= index($path, "$checkout/") != 0
| |||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | 10 | ▶ | return $path =~ $SCRATCH ? 0 : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | # _is_panel($block): | ||||||||||||||||||||||||||||||||
| 484 | # One launch of one panel member. The type of the agent decides | ||||||||||||||||||||||||||||||||
| 485 | # first: a reviewer is a member, and another role, such as a | ||||||||||||||||||||||||||||||||
| 486 | # fixer, is not one. A catch-all type and an absent type name no | ||||||||||||||||||||||||||||||||
| 487 | # role, so the description decides. The panel of an early | ||||||||||||||||||||||||||||||||
| 488 | # session dispatched a catch-all agent, and the description of | ||||||||||||||||||||||||||||||||
| 489 | # each member names the panel (TRACE-PANEL-1). | ||||||||||||||||||||||||||||||||
| 490 | 26 | ▶ | sub _is_panel ($block) | ||||||||||||||||||||||||||||||
|
Subroutine
_is_panel: called CC=10 SCAR=23.4
| |||||||||||||||||||||||||||||||||
| 491 | { | ||||||||||||||||||||||||||||||||
| 492 | 26 | ▶ | return 0 unless $LAUNCH{ $block->{name} // q{} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$block->{"name"} // ""
MC/DC0%0/1
$block->{"name"} // ""
$block->{"name"}
Truth table50%1/2
A
A= $block->{"name"}
| |||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||
| 494 | 9 | ▶ | my $input = $block->{input} // {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$block->{"input"} // {}
MC/DC0%0/1
$block->{"input"} // {}
$block->{"input"}
Truth table50%1/2
A
A= $block->{"input"}
| |||||||||||||||||||||||||||||||||
| 495 | 9 | ▶ | my $type = $input->{subagent_type} // q{}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$input->{"subagent_type"} // ""
MC/DC100%1/1
$input->{"subagent_type"} // ""
$input->{"subagent_type"}
Truth table100%2/2
A
A= $input->{"subagent_type"}
| |||||||||||||||||||||||||||||||||
| 496 | 9 | ▶ | return 1 if $type eq 'reviewer'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 497 | 8 | ▶ | return 0 if length $type && !$CATCHALL{$type}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $type and not $CATCHALL{$type}
MC/DC100%2/2
length $type and not $CATCHALL{$type}
length $type
not $CATCHALL{$type}
Truth table100%3/3
A and not(B)
A= length $typeB= not $CATCHALL{$type}
| |||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||
| 499 | 7 | ▶ | return ( $input->{description} // q{} ) =~ /panel/i ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$input->{"description"} // ""
MC/DC0%0/1
$input->{"description"} // ""
$input->{"description"}
Truth table50%1/2
A
A= $input->{"description"}
| |||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||
| 502 | # _meta_id($path): | ||||||||||||||||||||||||||||||||
| 503 | # The launch identifier of one sub-agent trace. The trace has a | ||||||||||||||||||||||||||||||||
| 504 | # sibling meta file, and the file names the tool_use block that | ||||||||||||||||||||||||||||||||
| 505 | # launched the sub-agent. A trace with no meta file gives the | ||||||||||||||||||||||||||||||||
| 506 | # empty string, which matches no launch (TRACE-SUB-2). | ||||||||||||||||||||||||||||||||
| 507 | 4 | ▶ | sub _meta_id ($path) | ||||||||||||||||||||||||||||||
|
Subroutine
_meta_id: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||
| 508 | { | ||||||||||||||||||||||||||||||||
| 509 | 4 | my $meta = $path =~ s/\.jsonl\z/.meta.json/r; | |||||||||||||||||||||||||||||||
| 510 | 4 | ▶ | open my $fh, '<', $meta or return q{}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 511 | 4 | my $text = do { local $/ = undef; <$fh> }; | |||||||||||||||||||||||||||||||
| 512 | 4 | close $fh; | |||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||
| 514 | 4 | ▶ | my $rec = eval { $JSON->decode( $text // q{} ) }; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$text // ""
MC/DC0%0/1
$text // ""
$text
Truth table50%1/2
A
A= $text
| |||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||
| 516 | 4 | ▶ | return ref $rec eq 'HASH' ? $rec->{toolUseId} // q{} : q{}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$rec->{"toolUseId"} // ""
MC/DC0%0/1
$rec->{"toolUseId"} // ""
$rec->{"toolUseId"}
Truth table50%1/2
A
A= $rec->{"toolUseId"}
| |||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||
| 519 | 117 | 1; | |||||||||||||||||||||||||||||||