# agent: move TokenUsage and SkillEvent to the leaf types package

`8ff1f70`→[main](/content/gh/entireio/cli/commits/main/index.html)·
Soph·4w ago·5 files·+120 added/-82 removed

The checkpoint contract DTOs embed TokenUsage and SkillEvent, but both lived in the heavy agent package — so any package referencing the checkpoint metadata types transitively pulled in agent (and its TUI/launch/review dependencies). That blocks relocating the contract to a standalone api/checkpoint package.

Move the type definitions (and the SkillEvent string constants) into the existing leaf agent/types package (which has no imports) and leave transparent aliases in agent:

type TokenUsage = types.TokenUsage
type SkillEvent = types.SkillEvent (+ the four Skill\* sub-types)
const SkillEventTypePromptInvocation = types.SkillEventTypePromptInvocation (+ the rest)

All ~34 existing agent.TokenUsage / agent.SkillEvent references keep compiling unchanged via the aliases. The SkillEventExtractor interface stays in agent (it's agent-implementation behavior, not contract data); the constants move alongside the structs so the leaf package is self-contained for constructing skill events. checkpoint.go now references types.* and no longer imports agent — the prerequisite for the api/checkpoint relocation (next in the stack).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

## Sessions

44f690c46059View transcript

[?\
can you run simplify on each PR?Claude Code·Opus 4.8[1m]·5 steps](/content/gh/entireio/cli/session/345ffa6b-bd28-4afc-953f-78cb65a1c2eb#timeline-44f690c46059/index.html)

## Changes

5

- cmd/entire/cli

- agent

- Mskill_events.go+21/-58

- Mtypes.go+9/-17

- types

- Askill_events.go+66

- Atoken_usage.go+18

- checkpoint

- Mcheckpoint.go+6/-7

```
1
2
3
4
5
6
7
3
4
9
5
6
7
8
9
11
12
13
14
10
11
12
16
17
18
19
13
14
15
16
21
22
23
24
17
18
19
20
21
22
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
23
24
25
26
27
28
29
30
31
32
```

package agent

// Skill event types recorded in checkpoint metadata.
const (
    SkillEventTypePromptInvocation = "prompt_invocation"
    SkillEventTypeToolInvocation   = "tool_invocation"
)
import "github.com/entireio/cli/cmd/entire/cli/agent/types";

// Skill event source signals.
// The skill-event types and their constants live in the leaf agent/types
// package so the checkpoint contract can construct and reference skill events
// without importing the full agent package. These aliases keep existing
// agent.SkillEvent* references working.
const (
    SkillSignalPiInputSlashCommand = "input_slash_command"
    SkillSignalPromptSlashCommand  = "prompt_slash_command"
    SkillSignalClaudeSkillToolUse  = "skill_tool_use"
);
    SkillEventTypePromptInvocation = types.SkillEventTypePromptInvocation
    SkillEventTypeToolInvocation   = types.SkillEventTypeToolInvocation

// Skill event confidence values.
const (
    SkillConfidenceExplicit = "explicit"
);
    SkillSignalPiInputSlashCommand = types.SkillSignalPiInputSlashCommand
    SkillSignalPromptSlashCommand  = types.SkillSignalPromptSlashCommand
    SkillSignalClaudeSkillToolUse  = types.SkillSignalClaudeSkillToolUse

// Skill event collapse targets.
const (
    SkillCollapseTargetUserMessage = "user_message"
    SkillCollapseTargetToolPair    = "tool_pair"
    SkillConfidenceExplicit = types.SkillConfidenceExplicit

SkillCollapseTargetUserMessage = types.SkillCollapseTargetUserMessage
    SkillCollapseTargetToolPair    = types.SkillCollapseTargetToolPair
);

// SkillEvent records a native agent skill signal without rewriting the raw transcript.
// Consumers use TranscriptAnchor/Native to locate the underlying raw event and Collapse
// to decide whether/how to hide verbose skill material by default.
type SkillEvent struct {
    ID        string           `json:"id,omitempty"`
    EventType string           `json:"event_type"`
    Skill     SkillEventSkill  `json:"skill"`
    Source    SkillEventSource `json:"source"`

TurnID    string `json:"turn_id,omitempty"`
    Timestamp string `json:"timestamp,omitempty"`

TranscriptAnchor *SkillEventTranscriptAnchor `json:"transcript_anchor,omitempty"`
    Native           map[string]string           `json:"native,omitempty"`
    Collapse         SkillEventCollapse          `json:"collapse"`
}

type SkillEventSkill struct {
    Name string `json:"name"`
}

type SkillEventSource struct {
    Agent      string `json:"agent"`
    Signal     string `json:"signal"`
    Confidence string `json:"confidence"`
}

type SkillEventTranscriptAnchor struct {
    Unit      string   `json:"unit,omitempty"`
    Start     int      `json:"start,omitempty"`
    End       int      `json:"end,omitempty"`
    EntryIDs  []string `json:"entry_ids,omitempty"`
    ToolUseID string   `json:"tool_use_id,omitempty"`
}

type SkillEventCollapse struct {
    Target           string `json:"target"`
    Label            string `json:"label,omitempty"`
    DefaultCollapsed bool   `json:"default_collapsed"`
}
type (
    SkillEvent                 = types.SkillEvent
    SkillEventSkill            = types.SkillEventSkill
    SkillEventSource           = types.SkillEventSource
    SkillEventTranscriptAnchor = types.SkillEventTranscriptAnchor
    SkillEventCollapse         = types.SkillEventCollapse
)

// SkillEventExtractor is implemented by agents that can derive native skill events
// from their transcript format.
```

Mcmd/entire/cli/agent/skill_events.go+21/-58

```
1
2
3
3
4
5
6
7
8
9
10
36 unmodified lines

47
48
49
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
50
51
52
53
```

package agent

import "time"
import (
	"time"

"github.com/entireio/cli/cmd/entire/cli/agent/types"
)

// HookType represents agent lifecycle events
type HookType string
36 unmodified lines

Timestamp  time.Time
}

// TokenUsage represents aggregated token usage for a checkpoint.
// This is agent-agnostic and can be populated by any agent that tracks token usage.
type TokenUsage struct {
	// InputTokens is the number of input tokens (fresh, not from cache)
	InputTokens int `json:"input_tokens"`
	// CacheCreationTokens is tokens written to cache (billable at cache write rate)
	CacheCreationTokens int `json:"cache_creation_tokens"`
	// CacheReadTokens is tokens read from cache (discounted rate)
	CacheReadTokens int `json:"cache_read_tokens"`
	// OutputTokens is the number of output tokens generated
	OutputTokens int `json:"output_tokens"`
	// APICallCount is the number of API calls made
	APICallCount int `json:"api_call_count"`
	// SubagentTokens contains token usage from spawned subagents (if any)
	SubagentTokens *TokenUsage `json:"subagent_tokens,omitempty"`
}
// TokenUsage is defined in the leaf agent/types package so the checkpoint
// contract can reference it without importing the full agent package. The
// alias keeps existing agent.TokenUsage references working.
type TokenUsage = types.TokenUsage
``

Mcmd/entire/cli/agent/types.go+9/-17

```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
```

package types

// Skill event types recorded in checkpoint metadata.
const (
    SkillEventTypePromptInvocation = "prompt_invocation"
    SkillEventTypeToolInvocation   = "tool_invocation"
)

// Skill event source signals.
const (
    SkillSignalPiInputSlashCommand = "input_slash_command"
    SkillSignalPromptSlashCommand  = "prompt_slash_command"
    SkillSignalClaudeSkillToolUse  = "skill_tool_use"
)

// Skill event confidence values.
const (
    SkillConfidenceExplicit = "explicit"
)

// Skill event collapse targets.
const (
    SkillCollapseTargetUserMessage = "user_message"
    SkillCollapseTargetToolPair    = "tool_pair"
)

TurnID    string `json:"turn_id,omitempty"`
    Timestamp string `json:"timestamp,omitempty"`

type SkillEventSkill struct {
    Name string `json:"name"`
}

type SkillEventSource struct {
    Agent      string `json:"agent"`
    Signal     string `json:"signal"`
    Confidence string `json:"confidence"`
}

type SkillEventCollapse struct {
    Target           string `json:"target"`
    Label            string `json:"label,omitempty"`
    DefaultCollapsed bool   `json:"default_collapsed"`
}
```

Acmd/entire/cli/agent/types/skill_events.go+66

```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

package types

Acmd/entire/cli/agent/types/token_usage.go+18

```
11 unmodified lines

12
13
14
15
15
16
17
231 unmodified lines

249
250
251
253
252
253
254
256
255
256
257
258
78 unmodified lines

337
338
339
341
340
341
342
343
124 unmodified lines

468
469
470
472
471
472
473
474
475
477
476
477
478
479
76 unmodified lines

556
557
558
560
559
560
561
562

11 unmodified lines

"errors"
	time".

"github.com/entireio/cli/cmd/entire/cli/agent"
	"github.com/entireio/cli/cmd/entire/cli/agent/types"
	"github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
	"github.com/entireio/cli/redact"
	231 unmodified lines

// and the deprecated CommittedMetadata.TranscriptLinesAtStart for backward compatibility.

// TokenUsage contains the token usage for this checkpoint
	TokenUsage *agent.TokenUsage
	TokenUsage *types.TokenUsage

// SkillEvents records explicit native skill signals observed in this session.
	SkillEvents []agent.SkillEvent
	SkillEvents []types.SkillEvent

// SessionMetrics contains hook-provided session metrics (duration, turns, context usage)
	SessionMetrics *SessionMetrics
	78 unmodified lines

Agent types.AgentType

// SkillEvents replaces the session metadata skill_events when non-empty.
	SkillEvents []agent.SkillEvent
	SkillEvents []types.SkillEvent

// PrecomputedBlobs, if non-nil, provides chunk blob hashes and the
	// content-hash blob hash computed once for this transcript. When set,
	124 unmodified lines

TranscriptLinesAtStart int `json:"transcript_lines_at_start,omitempty"`

// Token usage for this checkpoint
	TokenUsage *agent.TokenUsage `json:"token_usage,omitempty"`
	TokenUsage *types.TokenUsage `json:"token_usage,omitempty"`

// SkillEvents records explicit native skill signals observed in this session.
	// Consumers use these anchors to collapse skill-related raw transcript events.
	SkillEventsVersion int                `json:"skill_events_version,omitempty"`
	SkillEvents        []agent.SkillEvent `json:"skill_events,omitempty"`
	SkillEvents        []types.SkillEvent `json:"skill_events,omitempty"`

// SessionMetrics contains hook-provided session metrics (duration, turns, context usage).
	// Populated for agents that provide these metrics via hooks (e.g., Cursor).
	76 unmodified lines

CheckpointsCount    int                 `json:"checkpoints_count"`
	FilesTouched        []string            `json:"files_touched"`
	Sessions            []SessionFilePaths  `json:"sessions"`
	TokenUsage          *agent.TokenUsage   `json:"token_usage,omitempty"`
	TokenUsage          *types.TokenUsage   `json:"token_usage,omitempty"`
	CombinedAttribution *InitialAttribution `json:"combined_attribution,omitempty"`

// HasReview is the umbrella "any review happened" flag: true when at least

```

Mcmd/entire/cli/checkpoint/checkpoint.go+6/-7
