agent: move TokenUsage and SkillEvent to the leaf types package · Entire
agent: move TokenUsage and SkillEvent to the leaf types package
61d2fb5·
Soph·4w ago·5 files·+87 added/-64 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 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)
All ~34 existing agent.TokenUsage / agent.SkillEvent references keep compiling unchanged via the aliases; the constants and SkillEventExtractor interface stay in agent. checkpoint.go now references types.* and no longer imports agent — the prerequisite for the api/checkpoint relocation (next in the stack).
Sessions
1170c7943a20View transcript
Changes
5
cmd/entire/cli
agent
Mskill_events.go+12/-40
Mtypes.go+9/-17
types
Askill_events.go+42
Atoken_usage.go+18
checkpoint
Mcheckpoint.go+6/-7
package agent
import "github.com/entireio/cli/cmd/entire/cli/agent/types"
// Skill event types recorded in checkpoint metadata.
const (
SkillEventTypePromptInvocation = "prompt_invocation"
SkillCollapseTargetToolPair = "tool_pair"
)
// 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"`
}
// The skill-event types live in the leaf agent/types package so the checkpoint
// contract can reference them without importing the full agent package. These
// aliases keep existing agent.SkillEvent* references working.
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.
package agent
import "time"
// HookType represents agent lifecycle events
type HookType string
// 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
package types
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"`
}
package types