journal

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package journal tracks per-session file reads and persists file change metadata in SQLite paired with content-addressable snapshots in the session's blobs directory, enabling on-demand diff generation, point-in-time recovery, and conflict-aware 3-way baseline reversion.

Architecture

A Journal (created via New) is scoped to a single session and backed by two SQLite tables:

  • `journal_files`: one row per tracked file, recording the baseline hash and binary flag.
  • `journal_entries`: one row per change event, recording the before/after hashes, scope metadata (turn, message, tool call), source, kind, and line-diff statistics.

Content snapshots are stored as SHA-256-addressed blob files under the session's `blobs/` directory. The journal maintains an in-memory index of current file hashes for fast Read-Before-Overwrite and Compare-And-Swap verification via [Journal.LastHash] and [Journal.LastContent].

Recording Changes

[Journal.RecordChange] persists a std.FileChange atomically: it writes before/after content blobs, inserts the file tracking row and the change entry in a single transaction, and updates the in-memory hash index. When the change source is github.com/masterkeysrd/tasksmith/api.SourceAgent and a scope.Scope is present in the context, the journal propagates turn, message, tool-call, and tool-name metadata from the scope onto the change.

[Journal.RecordRead] records an observed content hash in memory only (no SQLite write), supporting the Read-Before-Overwrite invariant enforced by std.Std.

Diffing & Recovery

  • Journal.DiffEntry computes a unified diff for a specific entry or for the whole file relative to the session baseline.
  • Journal.RecoverAt restores a file to its state immediately before or after a given entry by writing the corresponding blob to the sandbox.
  • Journal.RevertToBaseline reverts agent changes back to the session baseline, performing a 3-way merge when force is false and returning ErrRevertConflict on conflicting external edits.
  • Journal.RevertSession reverts all tracked files to their baselines.

Metrics Integration

When configured with WithMetrics, the journal records a metrics.KindFileChange record for every [Journal.RecordChange] call, enabling usage reporting and per-tool code-change attribution.

Integration

github.com/masterkeysrd/tasksmith/internal/daemon/session.Session creates one Journal per session and exposes it via [Session.Journal]. The journal implements github.com/masterkeysrd/tasksmith/internal/daemon/std.FileTracker and is injected into github.com/masterkeysrd/tasksmith/internal/daemon/std.Std to enforce CAS safety on all mutating filesystem operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig  = errors.New("journal: invalid configuration")
	ErrNotFound       = errors.New("journal: file change journal not found")
	ErrEntryNotFound  = errors.New("journal: journal entry not found")
	ErrBlobNotFound   = errors.New("journal: file snapshot blob not found")
	ErrRevertConflict = errors.New("journal: revert conflict with external changes")
)

Functions

func Migrate

func Migrate(ctx context.Context, db *sql.DB) error

Migrate executes SQLite migrations for the journal schema.

Types

type Journal

type Journal interface {
	std.FileTracker

	Changes(ctx context.Context) ([]api.FileChange, error)
	ChangesForPath(ctx context.Context, path string) ([]api.FileChange, error)
	DiffEntry(ctx context.Context, path, entryID string) (string, error)
	RecoverAt(ctx context.Context, fsys sandbox.FS, path, entryID string, before bool) error
	RevertToBaseline(ctx context.Context, fsys sandbox.FS, path string, force bool) error
	RevertSession(ctx context.Context, fsys sandbox.FS, force bool) error
	Delete(ctx context.Context) error
}

Journal tracks per-session file reads (CAS) and persists file change metadata in SQLite paired with content-addressable snapshots in the session's blobsDir.

func New

func New(ctx context.Context, db *sql.DB, sessionID, blobsDir string, opts ...Option) (Journal, error)

New loads or initializes the Journal for a session, running schema migrations and restoring in-memory CAS tracked file state from SQLite metadata.

type Option

type Option func(*sqliteJournal)

Option configures a journal created by New.

func WithMetrics

func WithMetrics(r metrics.Recorder) Option

WithMetrics makes the journal record a file_change metric for every recorded change. A nil recorder disables them.

Jump to

Keyboard shortcuts

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