add API-only token brief guidance · Entire

add API-only token brief guidance

7481fd1·

Sessions

210fe202c7caView transcript

Changes

2

445 unmodified lines

446
447
448
449
450
451
452
453

445 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

1257 unmodified lines

1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
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

1257 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)