Documentation
¶
Overview ¶
Package filetrack records file changes made by agent tools so sessions can expose a cumulative diff (baseline = file state at first touch in a session). Bulky before/after contents live in a dedicated SQLite database as content-addressed compressed blobs, keeping the main sessions DB slim.
Index ¶
- Constants
- func CountAddsDels(oldContent, newContent []byte) (adds, dels int)
- type Change
- type ChangeRecord
- type CumulativeChange
- type DiffLine
- type FileDiffContent
- type Hunk
- type Options
- type Recorder
- type Store
- func (s *Store) Close() error
- func (s *Store) GC(ctx context.Context, sessionsDBPath string, maxAgeDays int) error
- func (s *Store) GetFileDiffContent(ctx context.Context, sessionID, path string) (*FileDiffContent, error)
- func (s *Store) ListSessionChanges(ctx context.Context, sessionID string) ([]CumulativeChange, error)
- func (s *Store) MaxFileBytes() int
- func (s *Store) RecordChange(ctx context.Context, rec ChangeRecord) (*Change, error)
- func (s *Store) SessionPaths(ctx context.Context, sessionID string) ([]string, error)
Constants ¶
const ( DefaultMaxFileBytes = 2 * 1024 * 1024 // per-file content cap DefaultMaxSessionBytes = 100 * 1024 * 1024 // retained-content budget per session DefaultMaxTotalBytes = int64(1024 * 1024 * 1024) // whole-database size cap (across sessions) )
Default caps, overridable via config.
const ( KindCreate = "create" KindModify = "modify" KindDelete = "delete" )
Change kinds.
Variables ¶
This section is empty.
Functions ¶
func CountAddsDels ¶
CountAddsDels counts added and removed lines between two contents. Empty/nil sides are treated as a missing file (pure create/delete).
Types ¶
type Change ¶
type Change struct {
Seq int64
Path string
Kind string
ToolName string
ToolCallID string
BeforeHash string // empty when absent/unknown/not retained
AfterHash string
BeforeSize int64
AfterSize int64
Adds int
Dels int
Truncated bool
IsBinary bool
}
Change is one recorded change row.
type ChangeRecord ¶
type ChangeRecord struct {
SessionID string
ToolName string
ToolCallID string
Path string // absolute path
Before []byte // content before the change (ignored when BeforeMissing/BeforeUnknown)
After []byte // content after the change (ignored when AfterMissing/AfterUnknown)
BeforeMissing bool // file did not exist before the change
AfterMissing bool // file does not exist after the change (deletion)
BeforeUnknown bool // file existed before but its content was not captured
AfterUnknown bool // file exists after but its content was not captured (e.g. oversized)
// Size hints for unknown-content sides (from stat); ignored when the
// corresponding content is provided.
BeforeSizeHint int64
AfterSizeHint int64
}
ChangeRecord describes one before→after file transition to record.
type CumulativeChange ¶
type CumulativeChange struct {
Path string `json:"path"`
Kind string `json:"kind"`
Adds int `json:"adds"`
Dels int `json:"dels"`
Truncated bool `json:"truncated"`
Seq int64 `json:"seq"` // latest change sequence for this path in the session
}
CumulativeChange summarizes a file's net change relative to the session baseline.
type DiffLine ¶
type DiffLine struct {
T string `json:"t"` // "ctx" | "add" | "del"
S string `json:"s"` // line text without the diff prefix
}
DiffLine is one row of a structured diff hunk.
type FileDiffContent ¶
FileDiffContent holds the baseline and current contents for one file.
type Hunk ¶
type Hunk struct {
OldStart int `json:"old_start"`
NewStart int `json:"new_start"`
Lines []DiffLine `json:"lines"`
}
Hunk is one contiguous block of a structured diff.
func BuildHunks ¶
BuildHunks computes a structured diff between two file contents. Returns nil when the contents are identical.
type Options ¶
type Options struct {
MaxFileBytes int // 0 = DefaultMaxFileBytes
MaxSessionBytes int // 0 = DefaultMaxSessionBytes
MaxTotalBytes int64 // 0 = DefaultMaxTotalBytes; whole-database size cap enforced by GC
}
Options configures a Store.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder adapts a Store to the tools-facing FileChangeRecorder interface. Recording is best-effort: failures are reported once on stderr and never surface to the calling tool — tracking must not break editing.
func NewRecorder ¶
NewRecorder wraps a store in a Recorder.
func (*Recorder) MaxFileBytes ¶
MaxFileBytes returns the per-file content cap.
func (*Recorder) RecordChange ¶
func (r *Recorder) RecordChange(ctx context.Context, rec ChangeRecord) *llm.FileChange
RecordChange persists one before→after transition. Returns nil when the change is a no-op or recording fails.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists file-change history in a dedicated SQLite database.
func (*Store) GC ¶
GC removes change rows for sessions that no longer exist in the sessions DB (and rows older than maxAgeDays when > 0), then sweeps unreferenced blobs.
func (*Store) GetFileDiffContent ¶
func (s *Store) GetFileDiffContent(ctx context.Context, sessionID, path string) (*FileDiffContent, error)
GetFileDiffContent returns the baseline and current contents for one path in a session, or nil when the path has no net change recorded.
func (*Store) ListSessionChanges ¶
func (s *Store) ListSessionChanges(ctx context.Context, sessionID string) ([]CumulativeChange, error)
ListSessionChanges returns the cumulative per-file changes for a session, sorted by path. Net no-ops are omitted.
func (*Store) MaxFileBytes ¶
MaxFileBytes returns the per-file content cap.
func (*Store) RecordChange ¶
RecordChange records one file transition and returns metadata for event emission. Returns (nil, nil) for no-ops (identical content, missing→missing, or empty session ID).