fix token diagnostics review feedback · Entire
fix token diagnostics review feedback
Sessions
a9f752ac37dfView transcript
Changes
4
cmd/entire/cli
Mcheckpoint_tokens.go+46/-14
Msession_tokens.go+19/-4
Msessions_test.go+50
Dt1.txt-1
37 unmodified lines
Short: "Show token usage and optimization recommendations for a checkpoint", Long: `Show token usage and optimization recommendations for a checkpoint.
The report reads committed checkpoint metadata and is local and deterministic. Checkpoint IDs may be abbreviated as long as the prefix is unambiguous.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { return runCheckpointTokens(cmd.Context(), cmd, args[0], jsonFlag)
```go
func buildCheckpointTokensReport(cpID id.CheckpointID, summary *checkpoint.CheckpointSummary, metas []*checkpoint.CommittedMetadata) checkpointTokensReport {
usage := aggregateCheckpointTokenUsage(metas)
if metadataWarnings > 0 {
report.Limitations = append(report.Limitations, fmt.Sprintf(
"%d checkpoint session metadata file%s could not be read; used root token summary or readable session metadata where available.",
metadataWarnings,
tokenPluralSuffix(metadataWarnings),
))
}
}
func TestCheckpointTokensReport_UsesRootSummaryWhenSessionMetadataIncomplete(t *testing.T) {
cpID := id.MustCheckpointID("abc123abc123")
report := buildCheckpointTokensReport(
cpID,
&checkpoint.CheckpointSummary{
CheckpointID: cpID,
Sessions: []checkpoint.SessionFilePaths{
{Metadata: "0/metadata.json"},
{Metadata: "1/metadata.json"},
},
TokenUsage: &agent.TokenUsage{
InputTokens: 1000,
OutputTokens: 500,
APICallCount: 7,
},
},
[]*checkpoint.CommittedMetadata{
{
SessionID: "readable-session",
TokenUsage: &agent.TokenUsage{
InputTokens: 100,
},
},
},
1,
)
if report.Tokens == nil {
t.Fatalf("expected token data, got nil")
}
}