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
- Variables
- type Cleanup
- type Record
- type Store
- func (s *Store) ClearCleanups(ctx context.Context) error
- func (s *Store) Forget(ctx context.Context, clonePath, worktree string) error
- func (s *Store) RecentCleanups(ctx context.Context, limit int) ([]Cleanup, error)
- func (s *Store) Record(ctx context.Context, r Record) error
- func (s *Store) RecordCleanup(ctx context.Context, c Cleanup) error
- func (s *Store) Touch(ctx context.Context, clonePath, worktree string, id agent.ID, at time.Time) error
- func (s *Store) Worktrees(ctx context.Context) ([]Record, error)
Constants ¶
const KeepCleanups = 100
KeepCleanups is how many cleanups are kept; recording one more drops the oldest.
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 ¶
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") )
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
}
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.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes the launch and cleanup records.
func (*Store) ClearCleanups ¶
ClearCleanups forgets every cleanup.
func (*Store) RecentCleanups ¶
RecentCleanups returns up to limit cleanups, newest first. A negative limit returns every one kept.
func (*Store) Record ¶
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.
func (*Store) RecordCleanup ¶
RecordCleanup stores a cleanup and drops the oldest records past KeepCleanups, in one transaction.