fix API-call-only token reports · Entire
fix API-call-only token reports
70ab794→main·
peyton-alt·1mo ago·3 files·+58 added/-5 removed
Sessions
9682839e2ddcView transcript
?\ CLI Token Usage Visibility AnalysisCodex·GPT-5.5·21 steps
Changes
3
cmd/entire/cli
Mcheckpoint_group.go+1/-1
Msession_tokens.go+4/-1
Msessions_test.go+53/-3
7 unmodified lines
8
9
10
11
11
12
13
14
7 unmodified lines
)
// newCheckpointGroupCmd builds the `entire checkpoint` parent command and
// registers list/explain/search as children, plus the deprecated rewind.
// registers list/explain/tokens/search as children, plus the deprecated rewind.
func newCheckpointGroupCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "checkpoint",
Mcmd/entire/cli/checkpoint_group.go+1/-1
202 unmodified lines
203
204
205
206
207
208
209
207
210
211
212
213
202 unmodified lines
}
func buildSessionTokensUsage(usage *agent.TokenUsage) *sessionTokensUsage {
if usage == nil {
return nil
}
total := totalTokens(usage)
if total == 0 {
if total == 0 && usage.APICallCount == 0 {
return nil
}
return &sessionTokensUsage{
Mcmd/entire/cli/session_tokens.go+4/-1
1114 unmodified lines
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
179 unmodified lines
1350
1351
1352
1303
1353
1354
1355
1356
55 unmodified lines
1412
1413
1414
1365
1415
1416
1417
1418
71 unmodified lines
1490
1491
1492
1443
1493
1494
1495
1496
1114 unmodified lines
}
}
func TestTokensCmd_JSONOutputReportsAPICallOnlyUsage(t *testing.T) {
setupStopTestRepo(t)
ctx := context.Background()
state := makeSessionState("test-tokens-api-only", session.PhaseActive)
state.AgentType = testAgentClaude
state.TokenUsage = &agent.TokenUsage{
APICallCount: 25,
}
if err := strategy.SaveSessionState(ctx, state); err != nil {
t.Fatalf("SaveSessionState() error = %v", err)
}
cmd := newTokensCmd()
var stdout bytes.Buffer
cmd.SetOut(&stdout)
cmd.SetArgs([]string{"test-tokens-api-only", "--json"})
if err := cmd.ExecuteContext(ctx); err != nil {
t.Fatalf("expected no error, got: %v", err)
}
var result sessionTokensReport
if err := json.Unmarshal(stdout.Bytes(), &result); err != nil {
t.Fatalf("expected valid JSON, got parse error: %v\noutput: %s", err, stdout.String())
}
if result.Tokens == nil {
t.Fatalf("expected API-call-only token usage to be reported")
}
if result.Tokens.Total != 0 || result.Tokens.APICalls != 25 {
t.Fatalf("unexpected token usage: %+v", result.Tokens)
}
if reportHasSessionRecommendation(result, "no-token-data") {
t.Fatalf("expected API-call-only usage to avoid no-token-data recommendation, got %+v", result.Recommendations)
}
if !reportHasSessionRecommendation(result, "api-call-amplification") {
t.Fatalf("expected api-call-amplification recommendation, got %+v", result.Recommendations)
}
}
func reportHasSessionRecommendation(report sessionTokensReport, id string) bool {
for _, rec := range report.Recommendations {
if rec.ID == id {
return true
}
}
return false
}
func TestSessionsCmd_TokensSubcommand(t *testing.T) {
setupStopTestRepo(t)
179 unmodified lines
repo, _ := runExplainAutoTestRepo(t)
ctx := context.Background()
cpID := id.MustCheckpointID("beefbeefcafe")
if err := checkpoint.NewGitStore(repo).WriteCommitted(ctx, checkpoint.WriteCommittedOptions{
if err := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs()).WriteCommitted(ctx, checkpoint.WriteCommittedOptions{
CheckpointID: cpID,
SessionID: "checkpoint-token-session",
Strategy: strategy.StrategyNameManualCommit,
55 unmodified lines
func TestCheckpointTokensCmd_TextOutputWithMultipleSessionsUsesAggregateScope(t *testing.T) {
repo, _ := runExplainAutoTestRepo(t)
ctx := context.Background()
store := checkpoint.NewGitStore(repo)
store := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs())
cpID := id.MustCheckpointID("feedfeedcafe")
if err := store.WriteCommitted(ctx, checkpoint.WriteCommittedOptions{
71 unmodified lines
repo, _ := runExplainAutoTestRepo(t)
ctx := context.Background()
cpID := id.MustCheckpointID("cafe00001234")
if err := checkpoint.NewGitStore(repo).WriteCommitted(ctx, checkpoint.WriteCommittedOptions{
if err := checkpoint.NewGitStore(repo, checkpoint.DefaultV1Refs()).WriteCommitted(ctx, checkpoint.WriteCommittedOptions{
CheckpointID: cpID,
SessionID: "checkpoint-token-json",
Strategy: strategy.StrategyNameManualCommit,