entity

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package entity defines the core domain types shared across ctx packages. It holds plain data structures with no business logic beyond simple accessors, keeping the dependency graph shallow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddConfig

type AddConfig struct {
	Priority    string
	Section     string
	FromFile    string
	Context     string
	Rationale   string
	Consequence string
	Lesson      string
	Application string
}

AddConfig holds all flags for the add command.

type ArchiveEntry

type ArchiveEntry struct {
	// SourcePath is the absolute path to the directory or file.
	SourcePath string
	// Prefix is the path prefix inside the tar archive.
	Prefix string
	// ExcludeDir is a directory name to skip (e.g. "journal-site").
	ExcludeDir string
	// Optional means a missing source is not an error.
	Optional bool
}

ArchiveEntry describes a directory or file to include in a backup archive.

type BackupResult

type BackupResult struct {
	Scope   string `json:"scope"`
	Archive string `json:"archive"`
	Size    int64  `json:"size"`
	SMBDest string `json:"smb_dest,omitempty"`
}

BackupResult holds the outcome of a single archive creation.

type BlockResponse

type BlockResponse struct {
	Decision string `json:"decision"`
	Reason   string `json:"reason"`
}

BlockResponse is the JSON output for blocked commands.

type BootstrapOutput

type BootstrapOutput struct {
	ContextDir string   `json:"context_dir"`
	Files      []string `json:"files"`
	Rules      []string `json:"rules"`
	NextSteps  []string `json:"next_steps"`
	Warnings   []string `json:"warnings,omitempty"`
}

BootstrapOutput is the JSON output structure for the bootstrap command.

Fields:

  • ContextDir: absolute path to the context directory
  • Files: list of context file names
  • Rules: list of rule strings
  • NextSteps: list of next-step strings
  • Warnings: optional warning strings

type CodeSummary

type CodeSummary struct {
	CommitCount int
	LatestMsg   string
	Dirs        []string
	Authors     []string
}

CodeSummary summarizes code changes since the reference time.

type Context

type Context struct {
	Dir         string
	Files       []FileInfo
	TotalTokens int
	TotalSize   int64
}

Context represents the loaded context from a .context/ directory.

Fields:

  • Dir: Path to the context directory
  • Files: All loaded context files with their metadata
  • TotalTokens: Sum of estimated tokens across all files
  • TotalSize: Sum of file sizes in bytes

func (*Context) File

func (c *Context) File(name string) *FileInfo

File returns the FileInfo with the given name, or nil if not found.

Fields:

  • name: Name of the file to search for.

Returns:

  • *FileInfo: Pointer to the found FileInfo, or nil if not found.

type ContextChange

type ContextChange struct {
	Name    string
	ModTime time.Time
}

ContextChange represents a modified context file.

type DeployParams

type DeployParams struct {
	SubDir     string
	ListErrKey string
	ReadErrKey string
}

DeployParams holds configuration for deploying embedded templates to a subdirectory.

type EntryParams

type EntryParams struct {
	Type        string
	Content     string
	Section     string
	Priority    string
	Context     string
	Rationale   string
	Consequence string
	Lesson      string
	Application string
	ContextDir  string
}

EntryParams contains all parameters needed to add an entry to a context file.

type ExportAction

type ExportAction int

ExportAction describes what will happen to a given file.

const (
	ActionNew        ExportAction = iota // file does not exist yet
	ActionRegenerate                     // file exists and will be rewritten
	ActionSkip                           // file exists and will be left alone
	ActionLocked                         // file is locked: never overwritten
)

type ExportOpts

type ExportOpts struct {
	All, AllProjects, Regenerate, Yes, DryRun bool
	KeepFrontmatter                           bool
}

ExportOpts holds all flag values for the export command.

func (ExportOpts) DiscardFrontmatter

func (o ExportOpts) DiscardFrontmatter() bool

DiscardFrontmatter reports whether frontmatter should be discarded during regeneration.

Returns:

  • bool: True if frontmatter should be discarded

type ExportPlan

type ExportPlan struct {
	Actions     []FileAction
	NewCount    int
	RegenCount  int
	SkipCount   int
	LockedCount int
	RenameOps   []RenameOp
}

ExportPlan is the result of PlanExport: a list of per-file actions plus aggregate counters and any renames that need to happen first.

type FileAction

type FileAction struct {
	Session    *Session
	Filename   string
	Path       string
	Part       int
	TotalParts int
	StartIdx   int
	EndIdx     int
	Action     ExportAction
	Messages   []Message
	Slug       string
	Title      string
	BaseName   string
}

FileAction describes the planned action for a single export file (one part of one session).

type FileInfo

type FileInfo struct {
	Name    string
	Path    string
	Size    int64
	ModTime time.Time
	Content []byte
	IsEmpty bool
	Tokens  int
	Summary string
}

FileInfo represents metadata about a context file.

Fields:

  • Name: Filename (e.g., "TASKS.md")
  • Path: Full path to the file
  • Size: File size in bytes
  • ModTime: Last modification time
  • Content: Raw file content
  • IsEmpty: True if the file has no meaningful content (only headers/whitespace)
  • Tokens: Estimated token count for the content
  • Summary: Brief description generated from the content

type FileTokenEntry

type FileTokenEntry struct {
	Name   string
	Tokens int
}

FileTokenEntry tracks per-file token counts during context injection.

type GroupedIndex

type GroupedIndex struct {
	Key     string
	Entries []JournalEntry
	Popular bool
}

GroupedIndex holds entries aggregated by a string key, sorted by count desc then alphabetically. Used by BuildTopicIndex and BuildKeyFileIndex.

type HookInput

type HookInput struct {
	SessionID string    `json:"session_id"`
	ToolInput ToolInput `json:"tool_input"`
}

HookInput represents the JSON payload that Claude Code sends to hook commands via stdin.

type ImportResult

type ImportResult struct {
	Conventions int
	Decisions   int
	Learnings   int
	Tasks       int
	Skipped     int
	Dupes       int
}

ImportResult tracks per-type counts for memory import operations.

Fields:

  • Conventions: convention entries imported
  • Decisions: decision entries imported
  • Learnings: learning entries imported
  • Tasks: task entries imported
  • Skipped: entries skipped (unclassified)
  • Dupes: duplicate entries skipped

func (ImportResult) Total

func (r ImportResult) Total() int

Total returns the number of entries actually imported (excludes skips and duplicates).

Returns:

  • int: sum of conventions, decisions, learnings, and tasks

type JournalEntry

type JournalEntry struct {
	Filename   string
	Title      string
	Date       string
	Time       string
	Project    string
	SessionID  string
	Model      string
	TokensIn   int
	TokensOut  int
	Path       string
	Size       int64
	Suggestive bool
	Topics     []string
	Type       string
	Outcome    string
	KeyFiles   []string
	Summary    string
}

JournalEntry represents a parsed journal file.

type JournalFrontmatter

type JournalFrontmatter struct {
	Title     string   `yaml:"title"`
	Date      string   `yaml:"date"`
	Time      string   `yaml:"time,omitempty"`
	Project   string   `yaml:"project,omitempty"`
	SessionID string   `yaml:"session_id,omitempty"`
	Model     string   `yaml:"model,omitempty"`
	TokensIn  int      `yaml:"tokens_in,omitempty"`
	TokensOut int      `yaml:"tokens_out,omitempty"`
	Type      string   `yaml:"type"`
	Outcome   string   `yaml:"outcome"`
	Topics    []string `yaml:"topics"`
	KeyFiles  []string `yaml:"key_files"`
	Summary   string   `yaml:"summary,omitempty"`
}

JournalFrontmatter represents YAML frontmatter in enriched journal entries.

type KeyFileData

type KeyFileData struct {
	Path    string
	Entries []JournalEntry
	Popular bool
}

KeyFileData holds aggregated data for a single file path.

func (KeyFileData) IsPopular

func (kf KeyFileData) IsPopular() bool

IsPopular reports whether this key file is popular.

type MergeParams

type MergeParams struct {
	Filename        string
	MarkerStart     string
	MarkerEnd       string
	TemplateContent []byte
	Force           bool
	AutoMerge       bool
	ConfirmPrompt   string
	UpdateTextKey   string
}

MergeParams holds configuration for create-or-merge file operations.

type Message

type Message struct {
	ID        string    `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Role      string    `json:"role"`

	Text        string       `json:"text,omitempty"`
	Thinking    string       `json:"thinking,omitempty"`
	ToolUses    []ToolUse    `json:"tool_uses,omitempty"`
	ToolResults []ToolResult `json:"tool_results,omitempty"`

	TokensIn  int `json:"tokens_in,omitempty"`
	TokensOut int `json:"tokens_out,omitempty"`
}

Message represents a single message in a session.

This is tool-agnostic - all parsers normalize to this format.

Fields:

Identity:

  • ID: Unique message identifier
  • Timestamp: When the message was created
  • Role: Message role ("user" or "assistant")

Content:

  • Text: Main text content
  • Thinking: Reasoning content (if available)
  • ToolUses: Tool invocations in this message
  • ToolResults: Results from tool invocations

Token Usage:

  • TokensIn: Input tokens for this message (if available)
  • TokensOut: Output tokens for this message (if available)

func (*Message) BelongsToAssistant

func (m *Message) BelongsToAssistant() bool

BelongsToAssistant returns true if this is an assistant message.

Returns:

  • bool: True if Role is "assistant"

func (*Message) BelongsToUser

func (m *Message) BelongsToUser() bool

BelongsToUser returns true if this is a user message.

Returns:

  • bool: True if Role is "user"

func (*Message) Preview

func (m *Message) Preview(maxLen int) string

Preview returns a truncated preview of the message text.

Parameters:

  • maxLen: Maximum length before truncation (adds "..." if exceeded)

Returns:

  • string: The text, truncated with "..." suffix if longer than maxLen

func (*Message) UsesTools

func (m *Message) UsesTools() bool

UsesTools returns true if this message contains tool invocations.

Returns:

  • bool: True if ToolUses slice is non-empty

type MessageListEntry

type MessageListEntry struct {
	Hook         string   `json:"hook"`
	Variant      string   `json:"variant"`
	Category     string   `json:"category"`
	Description  string   `json:"description"`
	TemplateVars []string `json:"template_vars"`
	HasOverride  bool     `json:"has_override"`
}

MessageListEntry holds the data for a single row in the message list output.

type PopularSplittable

type PopularSplittable interface {
	IsPopular() bool
}

PopularSplittable is implemented by MOC data types that can be split into popular and long-tail groups.

type RenameOp

type RenameOp struct {
	OldBase  string
	NewBase  string
	NumParts int
}

RenameOp describes a dedup rename (old slug → new slug).

type Session

type Session struct {
	ID   string `json:"id"`
	Slug string `json:"slug,omitempty"`

	Tool       string `json:"tool"`
	SourceFile string `json:"source_file"`

	CWD       string `json:"cwd,omitempty"`
	Project   string `json:"project,omitempty"`
	GitBranch string `json:"git_branch,omitempty"`

	StartTime time.Time     `json:"start_time"`
	EndTime   time.Time     `json:"end_time"`
	Duration  time.Duration `json:"duration"`

	Messages  []Message `json:"messages"`
	TurnCount int       `json:"turn_count"`

	TotalTokensIn  int `json:"total_tokens_in,omitempty"`
	TotalTokensOut int `json:"total_tokens_out,omitempty"`
	TotalTokens    int `json:"total_tokens,omitempty"`

	HasErrors    bool   `json:"has_errors,omitempty"`
	FirstUserMsg string `json:"first_user_msg,omitempty"`
	Model        string `json:"model,omitempty"`
}

Session represents a reconstructed conversation session.

This is the tool-agnostic output type that all parsers produce. It contains common fields that make sense across different AI tools.

Fields:

Identity:

  • ID: Unique session identifier
  • Slug: URL-friendly session identifier

Source:

  • Tool: Source tool ("claude-code", "aider", "cursor", etc.)
  • SourceFile: Original file path

Context:

  • CWD: Working directory when session started
  • Project: Project name (derived from last component of CWD)
  • GitBranch: Git branch name if available

Timing:

  • StartTime: When the session started
  • EndTime: When the session ended
  • Duration: Total session duration

Messages:

  • Messages: All messages in the session
  • TurnCount: Count of user messages

Token Statistics:

  • TotalTokensIn: Input tokens used (if available)
  • TotalTokensOut: Output tokens used (if available)
  • TotalTokens: Total tokens used (if available)

Derived:

  • HasErrors: True if any tool errors occurred
  • FirstUserMsg: Preview text of first user message (truncated)
  • Model: Primary model used in the session

func (*Session) AllToolUses

func (s *Session) AllToolUses() []ToolUse

AllToolUses returns all tool uses across all messages.

Returns:

  • []ToolUse: Aggregated list of all tool invocations in the session

func (*Session) AssistantMessages

func (s *Session) AssistantMessages() []Message

AssistantMessages returns only assistant messages from the session.

Returns:

  • []Message: Filtered list containing only messages with Role "assistant"

func (*Session) UserMessages

func (s *Session) UserMessages() []Message

UserMessages returns only user messages from the session.

Returns:

  • []Message: Filtered list containing only messages with Role "user"

type StaleEntry

type StaleEntry struct {
	// Path is the relative file path.
	Path string
	// Desc is the human-readable file description.
	Desc string
	// ReviewURL is the optional URL for reviewing the file against upstream.
	ReviewURL string
	// Days is the number of days since last modification.
	Days int
}

StaleEntry describes a file that has not been modified within the configured freshness window.

type Stats

type Stats struct {
	Timestamp  string `json:"ts"`
	Prompt     int    `json:"prompt"`
	Tokens     int    `json:"tokens"`
	Pct        int    `json:"pct"`
	WindowSize int    `json:"window"`
	Model      string `json:"model,omitempty"`
	Event      string `json:"event"`
}

Stats holds the fields written to the per-session stats JSONL file.

type TaskBlock

type TaskBlock struct {
	Lines        []string
	StartIndex   int
	EndIndex     int
	IsCompleted  bool
	IsArchivable bool
	DoneTime     *time.Time
}

TaskBlock represents a task and its nested content.

Fields:

  • Lines: All lines in the block (parent and children)
  • StartIndex: Index of first line in original content
  • EndIndex: Index of last line (exclusive)
  • IsCompleted: The parent task is checked
  • IsArchivable: Completed and no unchecked children
  • DoneTime: When the task was marked done (from #done: timestamp), nil if not present

func (*TaskBlock) BlockContent

func (b *TaskBlock) BlockContent() string

BlockContent returns the full content of a block as a single string.

Returns:

  • string: All lines joined with newlines

func (*TaskBlock) OlderThan

func (b *TaskBlock) OlderThan(days int) bool

OlderThan checks if the task was completed more than the specified days ago.

Parameters:

  • days: Number of days threshold

Returns:

  • bool: True if DoneTime is set and older than days ago, false otherwise

func (*TaskBlock) ParentTaskText

func (b *TaskBlock) ParentTaskText() string

ParentTaskText extracts just the task text from the parent line.

Returns:

  • string: Task text without the checkbox prefix, empty if no lines

type TokenInfo

type TokenInfo struct {
	Tokens int    // Total input tokens (input + cache_creation + cache_read)
	Model  string // Model ID from the last assistant message, or ""
}

TokenInfo holds token usage and model information extracted from a session's JSONL file.

type ToolInput

type ToolInput struct {
	Command string `json:"command"`
}

ToolInput contains the tool-specific fields from a Claude Code hook invocation. For Bash hooks, Command holds the shell command.

type ToolResult

type ToolResult struct {
	ToolUseID string `json:"tool_use_id"`
	Content   string `json:"content"`
	IsError   bool   `json:"is_error,omitempty"`
}

ToolResult represents the result of a tool invocation.

Fields:

  • ToolUseID: ID of the ToolUse this result corresponds to
  • Content: The tool's output content
  • IsError: True if the tool execution failed

type ToolUse

type ToolUse struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Input string `json:"input"`
}

ToolUse represents a tool invocation by the assistant.

Fields:

  • ID: Unique identifier for this tool use
  • Name: Tool name (e.g., "Bash", "Read", "Write", "Grep")
  • Input: JSON string of input parameters passed to the tool

type TopicData

type TopicData struct {
	Name    string
	Entries []JournalEntry
	Popular bool
}

TopicData holds aggregated data for a single topic.

func (TopicData) IsPopular

func (t TopicData) IsPopular() bool

IsPopular reports whether this topic is popular.

type TypeData

type TypeData struct {
	Name    string
	Entries []JournalEntry
}

TypeData holds aggregated data for a session type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL