worktreejournal

package
v0.178.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package worktreejournal owns the local append-only event journal and its repairable derivatives.

Index

Constants

View Source
const (
	JournalRootDirectory  = ".wb"
	JournalLocalDirectory = "local"
)
View Source
const (
	EventsName     = "events.jsonl"
	ProjectionName = "projection.json"
	OutboxName     = "outbox.jsonl"
	LockName       = ".journal.lock"

	LocalEventInit             = "init"
	LocalEventSteer            = "steer"
	LocalEventCheckpoint       = "checkpoint"
	LocalEventRefresh          = "refresh"
	LocalEventRefreshNeed      = "refresh_required"
	LocalEventIntegrate        = "integrate"
	LocalEventHandoff          = "handoff"
	LocalEventRecover          = "recover"
	LocalEventBranchReconciled = "branch_reconciled"
	LocalEventFinalize         = "finalize"
	LocalEventSyncAttempt      = "sync_attempt"
	LocalEventArchive          = "archive"
)

Variables

This section is empty.

Functions

func OpenJournalComponent

func OpenJournalComponent(parentFD int, name string, create bool) (int, error)

func OpenJournalDirectory

func OpenJournalDirectory(worktree string, create bool) (*os.File, error)

func OpenJournalSubdirectory

func OpenJournalSubdirectory(worktree, name string, create bool) (*os.File, error)

Types

type DirectoryStore

type DirectoryStore struct {
	OpenRoot      func(path string, create bool) (*os.File, error)
	OpenComponent func(parentFD int, name string, create bool) (int, error)
	Chmod         func(fd int, mode uint32) error
	Matches       func(path string, directory *os.File) bool
}

DirectoryStore scopes descriptor operations used by secure journal traversal.

func (DirectoryStore) OpenJournalComponent

func (s DirectoryStore) OpenJournalComponent(parentFD int, name string, create bool) (int, error)

func (DirectoryStore) OpenJournalDirectory

func (s DirectoryStore) OpenJournalDirectory(worktree string, create bool) (*os.File, error)

func (DirectoryStore) OpenJournalSubdirectory

func (s DirectoryStore) OpenJournalSubdirectory(worktree, name string, create bool) (*os.File, error)

type LocalGitEvidence

type LocalGitEvidence struct {
	Branch    string `json:"branch,omitempty"`
	Head      string `json:"head,omitempty"`
	Dirty     bool   `json:"dirty"`
	StatusSHA string `json:"status_sha256,omitempty"`
	Status    string `json:"status,omitempty"`
}

LocalGitEvidence is the public Git fingerprint recorded on checkpoints.

type LocalTargetEvidence

type LocalTargetEvidence struct {
	Ref       string    `json:"ref,omitempty"`
	SHA       string    `json:"sha,omitempty"`
	FetchedAt time.Time `json:"fetched_at,omitempty"`
	Ahead     int       `json:"ahead"`
	Behind    int       `json:"behind"`
	Strategy  string    `json:"strategy,omitempty"`
}

LocalTargetEvidence records refresh/integrate observations.

type LocalUsageEvidence

type LocalUsageEvidence struct {
	Discriminator string   `json:"discriminator"`
	InputTokens   *int64   `json:"input_tokens,omitempty"`
	OutputTokens  *int64   `json:"output_tokens,omitempty"`
	TotalTokens   *int64   `json:"total_tokens,omitempty"`
	EstimatedCost *float64 `json:"estimated_cost,omitempty"`
	Currency      string   `json:"currency,omitempty"`
	ProviderRef   string   `json:"provider_ref,omitempty"`
}

LocalUsageEvidence is optional nullable token usage.

type LocalWorkLogEvent

type LocalWorkLogEvent struct {
	Version    int                  `json:"version"`
	Seq        int                  `json:"seq"`
	ID         string               `json:"id"`
	Type       string               `json:"type"`
	At         time.Time            `json:"at"`
	Message    string               `json:"message,omitempty"`
	NextAction string               `json:"next_action,omitempty"`
	Prompt     string               `json:"prompt,omitempty"`
	PromptSHA  string               `json:"prompt_sha256,omitempty"`
	Git        *LocalGitEvidence    `json:"git,omitempty"`
	Target     *LocalTargetEvidence `json:"target,omitempty"`
	Usage      *LocalUsageEvidence  `json:"usage,omitempty"`
	Result     string               `json:"result,omitempty"`
	Conflict   string               `json:"conflict,omitempty"`
	Owner      *OwnerRegistration   `json:"owner,omitempty"`
	Extra      map[string]any       `json:"extra,omitempty"`
}

LocalWorkLogEvent is one append-only journal record under .wb/local/worklog/.

type LocalWorkLogProjection

type LocalWorkLogProjection struct {
	Version        int                  `json:"version"`
	EffortID       string               `json:"effort_id,omitempty"`
	RunID          string               `json:"run_id,omitempty"`
	ClaimID        string               `json:"claim_id,omitempty"`
	Lifecycle      string               `json:"lifecycle"`
	LastSeq        int                  `json:"last_seq"`
	LastEventID    string               `json:"last_event_id,omitempty"`
	LastType       string               `json:"last_type,omitempty"`
	LastMessage    string               `json:"last_message,omitempty"`
	LastNextAction string               `json:"last_next_action,omitempty"`
	LastCheckpoint *LocalGitEvidence    `json:"last_checkpoint,omitempty"`
	LastTarget     *LocalTargetEvidence `json:"last_target,omitempty"`
	Conflict       string               `json:"conflict,omitempty"`
	UpdatedAt      time.Time            `json:"updated_at"`
}

LocalWorkLogProjection is the derived current-state cache for the local journal.

func ProjectionFromEvents

func ProjectionFromEvents(events []LocalWorkLogEvent) LocalWorkLogProjection

ProjectionFromEvents folds local events without I/O or validation. Storage and identity enrichment remain the responsibility of its callers.

type OwnerRegistration

type OwnerRegistration struct {
	Agent     string `json:"agent,omitempty"`
	Model     string `json:"model,omitempty"`
	Effort    string `json:"effort,omitempty"`
	Initiator string `json:"initiator,omitempty"`
	// PID is the declared agent session's process, never WB's own. WB is a
	// short-lived CLI: its PID is dead moments after it would be written, and
	// once recycled it would report an abandoned worktree as active. An
	// absent PID therefore reads as unknown, which is the honest answer.
	PID int `json:"pid,omitempty"`
	// WBVersion and Command are always populated, because WB always knows
	// them. They give a worktree provenance even when no agent identity was
	// declared.
	WBVersion string    `json:"wb_version,omitempty"`
	Command   string    `json:"command,omitempty"`
	At        time.Time `json:"at"`
}

type Store

type Store struct {
	OpenDirectory   func(worktree string, create bool) (*os.File, error)
	Project         func(worktree string, events []LocalWorkLogEvent) (LocalWorkLogProjection, error)
	WriteJournal    func(directory *os.File, name string, content []byte, mode os.FileMode) error
	ReadFile        func(directory *os.File, name string) ([]byte, error)
	WriteFile       func(directory *os.File, name string, content []byte, mode os.FileMode) error
	WriteProjection func(directory *os.File, name string, value any, mode os.FileMode) error
	Flock           func(fd int, how int) error
}

Store binds a local journal to facade-owned directory setup and projection enrichment. A Store is a value so failure seams stay scoped to one operation or test.

func (Store) AppendLocalEventUnderLock

func (s Store) AppendLocalEventUnderLock(worktree string, directory *os.File, event LocalWorkLogEvent) (LocalWorkLogEvent, LocalWorkLogProjection, error)

func (Store) CountLocalOutbox

func (s Store) CountLocalOutbox(worktree string) (int, error)

func (Store) EncodeLocalEvents

func (s Store) EncodeLocalEvents(events []LocalWorkLogEvent) ([]byte, error)

func (Store) LocalEventID

func (s Store) LocalEventID(existing []LocalWorkLogEvent, event LocalWorkLogEvent) string

func (Store) LockLocalWorkLog

func (s Store) LockLocalWorkLog(directory *os.File) (func(), error)

func (Store) ParseLocalEvents

func (s Store) ParseLocalEvents(content []byte) ([]LocalWorkLogEvent, error)

func (Store) ParseLocalEventsForRepair

func (s Store) ParseLocalEventsForRepair(content []byte) ([]LocalWorkLogEvent, bool, error)

func (Store) ReadLocalEvents

func (s Store) ReadLocalEvents(worktree string) ([]LocalWorkLogEvent, error)

func (Store) ReadLocalEventsForAppend

func (s Store) ReadLocalEventsForAppend(directory *os.File) ([]LocalWorkLogEvent, bool, error)

func (Store) ReadLocalProjection

func (s Store) ReadLocalProjection(worktree string) (LocalWorkLogProjection, error)

func (Store) ReadLocalWorkLogBytes

func (s Store) ReadLocalWorkLogBytes(worktree, name string) ([]byte, error)

func (Store) RebuildLocalProjection

func (s Store) RebuildLocalProjection(events []LocalWorkLogEvent) (LocalWorkLogProjection, error)

func (Store) RepairCurrentLocalProjection

func (s Store) RepairCurrentLocalProjection(worktree string) (LocalWorkLogProjection, error)

func (Store) RepairLocalEventDerivatives

func (s Store) RepairLocalEventDerivatives(worktree string, directory *os.File, events []LocalWorkLogEvent) (LocalWorkLogProjection, error)

func (Store) RepairLocalOutbox

func (s Store) RepairLocalOutbox(directory *os.File, events []LocalWorkLogEvent) error

func (Store) RewriteLocalEventJournal

func (s Store) RewriteLocalEventJournal(directory *os.File, events []LocalWorkLogEvent) error

func (Store) SameLocalEvent

func (s Store) SameLocalEvent(first, second LocalWorkLogEvent) bool

func (Store) ValidateLocalEventForSequence

func (s Store) ValidateLocalEventForSequence(event LocalWorkLogEvent, existing []LocalWorkLogEvent) error

Jump to

Keyboard shortcuts

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