add API-only token brief guidance · Entire

add API-only token brief guidance

83bcc81·

peyton-alt·3w ago·2 files·+43 added/-0 removed

Sessions

210fe202c7caView transcript

Changes

2

452 unmodified lines

453
454
455
456
457
458
459
460

452 unmodified lines

switch {
    case hasTokenRecommendation(report, "context-replay-hotspot") && hasTokenRecommendation(report, "api-call-amplification"):
        return "Summarize the useful findings, then batch the next diagnostic step. Avoid more exploratory reads until you have a narrowed hypothesis."
    case hasTokenRecommendation(report, "api-call-amplification"):
        return "Batch the next diagnostic step around one narrowed hypothesis before making more tool calls."
    case hasTokenRecommendation(report, "context-replay-hotspot"):
        return "Summarize the current useful findings before continuing, and keep the next prompt narrow."
    case hasTokenRecommendation(report, "no-token-data"):

Mcmd/entire/cli/session_tokens.go+2

1276 unmodified lines

1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323

1276 unmodified lines

}
}

func TestTokensCmd_AgentBriefHighAPICallsWithoutCacheReplay(t *testing.T) {
    setupStopTestRepo(t)

ctx := context.Background()
    state := makeSessionState("test-tokens-brief-api-only", session.PhaseActive)
    state.AgentType = testAgentClaude
    state.TokenUsage = &agent.TokenUsage{
        InputTokens:  10_000,
        OutputTokens: 1_000,
        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-brief-api-only", "--agent-brief"})

if err := cmd.ExecuteContext(ctx); err != nil {
        t.Fatalf("expected no error, got: %v", err)
    }

out := stdout.String()
    checks := []string{
        "Token usage: 11k total; 25 API calls.",
        "Batch the next diagnostic step around one narrowed hypothesis before making more tool calls.",
        "- API call count is high for one session.",
    }
    for _, check := range checks {
        if !strings.Contains(out, check) {
            t.Errorf("expected %q in output, got:\n%s", check, out)
        }
    }
    if strings.Contains(out, "Continue normally") {
        t.Fatalf("expected high API calls to avoid continue-normally action, got:\n%s", out)
    }
}

func TestTokensCmd_AgentBriefNoTokenData(t *testing.T) {
    setupStopTestRepo(t)