worklog

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 10 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 worklog records the worktrees the app made for pull requests and issues, which item each is for and the sessions started in it, and the worktrees it cleaned up. It owns the worktree_records and worktree_cleanups tables.

The worktrees service records a worktree when it makes one for a launch, or finds one on an item's branch, and the launcher records each session started in it. The worktrees service reads the records to link each worktree to its item exactly, to resume it on the next launch, and to find the clones its automatic cleanup checks, and it checks every record against git each time, dropping one whose worktree is gone. A record is only a pointer: whether a worktree may be removed is always decided from git and GitHub at the time.

The worktrees service records a cleanup once the worktree is gone, whether the user asked for it or the automatic sweep did it, so the Worktrees view can show what was removed and when, across restarts. Only the newest KeepCleanups records are kept.

Index

Constants

View Source
const KeepCleanups = 100

KeepCleanups is how many cleanups are kept; recording one more drops the oldest.

View Source
const LegacyDir = ".claude/worktrees"

LegacyDir is where, under a clone, Claude Code made the worktrees of launches before the app made them itself: <clone>/.claude/worktrees/<name>.

Variables

View Source
var (
	// ErrInvalidRecord is returned for a worktree record missing a field, or with an
	// unknown kind, a number that is not positive, or a relative path.
	ErrInvalidRecord = errors.New("invalid worktree record")

	// ErrNotRecorded is returned when touching a worktree that has no record.
	ErrNotRecorded = errors.New("the worktree is not recorded")
)
View Source
var ErrInvalidCleanup = errors.New("invalid worktree cleanup")

ErrInvalidCleanup is returned for a cleanup without a repository or worktree name.

Functions

This section is empty.

Types

type Cleanup

type Cleanup struct {
	// ID identifies the record; RecordCleanup ignores it.
	ID int64

	// CleanedAt is when the worktree was removed.
	CleanedAt time.Time

	// Automatic reports a cleanup by the sweep rather than by the user.
	Automatic bool

	// Repo is the clone's directory name, and Worktree the worktree's, e.g. "pr-184".
	Repo     string
	Worktree string

	// DisplayPath is the worktree's path relative to home with ~.
	DisplayPath string

	// DeletedBranch is the branch deleted with it, or "" when it was kept.
	DeletedBranch string

	// Head is the commit the worktree had checked out.
	Head string

	// The pull request or issue it was for: kind ("pr" or "issue"), repository, number,
	// title, URL, and state ("merged" or "closed").
	ItemKind   string
	ItemOwner  string
	ItemName   string
	ItemNumber int
	ItemTitle  string
	ItemURL    string
	ItemState  string
}

Cleanup is one worktree the app cleaned up.

type Record

type Record struct {
	// ClonePath is the clone the worktree belongs to.
	ClonePath string

	// Worktree is the item's worktree name, pr-<n> or issue-<n>.
	Worktree string

	// Path is the worktree's absolute directory, or "" for a record kept before the app
	// made worktrees itself (see Dir).
	Path string

	// Branch is the branch the worktree was made on, worktree-<name>.
	Branch string

	// Owner and Name are the item's repository.
	Owner string
	Name  string

	// Kind is the item's kind.
	Kind item.Kind

	// Number is the item's number.
	Number int

	// Agent is the agent of the latest session started there, or agent.Inherit when none
	// has started.
	Agent agent.ID

	// CreatedAt is when the worktree was made or first recorded.
	CreatedAt time.Time

	// LastAgentAt is when the latest session started, or zero when none has.
	LastAgentAt time.Time

	// Launches counts the sessions started there.
	Launches int

	// FetchedHead is the commit the app made the worktree at, just fetched from GitHub: a
	// pull request's head, or the default branch an issue's worktree starts from; "" for
	// a worktree it found, or added on a branch left from an earlier one. Every commit it
	// reaches came from GitHub. Record keeps the one stored when this is "".
	FetchedHead string
}

Record is one worktree the app made for a pull request or issue, or found on its branch: where it is, the item it is for, and the sessions started in it.

func (Record) Dir

func (r Record) Dir() string

Dir returns the worktree's directory: Path, or for a record kept before the app made worktrees itself, the directory Claude Code made under the clone.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store reads and writes the launch and cleanup records.

func New

func New(db *sql.DB) *Store

New returns a Store over the pool db.

func (*Store) ClearCleanups

func (s *Store) ClearCleanups(ctx context.Context) error

ClearCleanups forgets every cleanup.

func (*Store) Forget

func (s *Store) Forget(ctx context.Context, clonePath, worktree string) error

Forget removes the record of a clone's worktree, if there is one.

func (*Store) RecentCleanups

func (s *Store) RecentCleanups(ctx context.Context, limit int) ([]Cleanup, error)

RecentCleanups returns up to limit cleanups, newest first. A negative limit returns every one kept.

func (*Store) Record

func (s *Store) Record(ctx context.Context, r Record) error

Record stores where a clone's worktree for an item is, and the item it is for, replacing the place an earlier record of the same worktree named. A worktree recorded already keeps when it was made and its sessions, and its FetchedHead unless r names one.

func (*Store) RecordCleanup

func (s *Store) RecordCleanup(ctx context.Context, c Cleanup) error

RecordCleanup stores a cleanup and drops the oldest records past KeepCleanups, in one transaction.

func (*Store) Touch

func (s *Store) Touch(ctx context.Context, clonePath, worktree string, id agent.ID, at time.Time) error

Touch records a session the agent with id started at at in a clone's recorded worktree. It returns ErrNotRecorded when the worktree has no record.

func (*Store) Worktrees

func (s *Store) Worktrees(ctx context.Context) ([]Record, error)

Worktrees returns every recorded worktree, oldest first.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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