Add cost-proxy token guidance · Entire

Add cost-proxy token guidance

e7f9ff3· peyton-alt·3w ago·3 files·+504 added/-27 removed

Sessions

e46d5e136530View transcript

Changes

3

2 unmodified lines

3
4
5
6
7
8
9

28 unmodified lines

38
39
40
41
42
43
44
45
46
47

21 unmodified lines

69
70
71
72
73
74
75

10 unmodified lines

86
87
88
84
89
90
91
92
93
94
95
96
97
98
99
100
101
93
102
103
104
105

16 unmodified lines

122
123
124
125
126
127
128
129
130
131

271 unmodified lines

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448

119 unmodified lines

568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612

4 unmodified lines

617
618
619
620
621
622
623
624
625
626

2 unmodified lines

import (
    "context"
    "encoding/json"
    "errors"
    "fmt"
    "io"
    "strconv"

28 unmodified lines

TargetCheckpointID   string                       `json:"target_checkpoint_id"`
    Status               string                       `json:"status"`
    Total                *checkpointTokensMetricDelta `json:"total,omitempty"`
    Input                *checkpointTokensMetricDelta `json:"input,omitempty"`
    CacheRead            *checkpointTokensMetricDelta `json:"cache_read,omitempty"`
    CacheWrite           *checkpointTokensMetricDelta `json:"cache_write,omitempty"`
    Output               *checkpointTokensMetricDelta `json:"output,omitempty"`
    APICalls             *checkpointTokensMetricDelta `json:"api_calls,omitempty"`
    Qualification        string                       `json:"qualification"`
    Limitations          []string                     `json:"limitations,omitempty"`
21 unmodified lines

func newCheckpointTokensCmd() *cobra.Command {
    var jsonFlag bool
    var compareFlag string
    var agentBriefFlag bool

cmd := &cobra.Command{
        Use:   "tokens <checkpoint-id>",

10 unmodified lines

checkpoint and qualify observed token reduction or increase.

Args: cobra.ExactArgs(1),
    RunE: func(cmd *cobra.Command, args []string) error {
        return runCheckpointTokens(cmd.Context(), cmd, args[0], jsonFlag, compareFlag)
        if jsonFlag && agentBriefFlag {
            return errors.New("--json and --agent-brief are mutually exclusive")
        }
        return runCheckpointTokens(cmd.Context(), cmd, args[0], jsonFlag, compareFlag, agentBriefFlag)
    },

}

cmd.Flags().BoolVar(&jsonFlag, "json", false, "Output as JSON")
    cmd.Flags().StringVar(&compareFlag, "compare", "", "Compare against a baseline checkpoint ID")
    cmd.Flags().BoolVar(&agentBriefFlag, "agent-brief", false, "Output compact next-step guidance for agents")
    return cmd
}

func runCheckpointTokens(ctx context.Context, cmd *cobra.Command, checkpointIDPrefix string, jsonOutput bool, comparePrefix string) error {
func runCheckpointTokens(ctx context.Context, cmd *cobra.Command, checkpointIDPrefix string, jsonOutput bool, comparePrefix string, agentBrief bool) error {
    report, lookup, err := loadCheckpointTokensReport(ctx, cmd, checkpointIDPrefix)
    if lookup != nil {
        defer lookup.Close()
16 unmodified lines

if jsonOutput {
        return writeCheckpointTokensJSON(cmd.OutOrStdout(), report)
    }
    if agentBrief {
        writeCheckpointTokensAgentBrief(cmd.OutOrStdout(), report)
        return nil
    }
    writeCheckpointTokensText(cmd.OutOrStdout(), report)
    return nil
}

...