Documentation
¶
Overview ¶
Package scratch reclaims throwaway workspaces nobody is using.
Every blank shell and every project-less session gets its own directory under the target's scratch root, and nothing ever removed one. Most are empty the day they are made and stay that way; a few hold work somebody meant to file under a project and never did. The sweep tells those apart, moves the empty ones to a trash it empties later, and leaves anything that looks like work for a person to decide about.
It fails closed: a directory is removed only when every signal could be read and all of them say nothing happened there.
Index ¶
- Constants
- func HistoryMentions(ctx context.Context, run Runner, paths []string) (map[string]bool, error)
- func MarkKeep(ctx context.Context, run Runner, name string) error
- func Purge(ctx context.Context, run Runner, days float64, now int64) (int, error)
- func SafeName(name string) bool
- func Trash(ctx context.Context, run Runner, names []string, now int64) ([]string, error)
- type Dir
- type Entry
- type Result
- type Runner
- type Session
- type Sweeper
- type TargetReport
- type Verdict
Constants ¶
const KeepMarker = ".lectern-keep"
KeepMarker is the file that exempts a directory from the sweep for good.
const RootExpr = `` /* 231-byte string literal not displayed */
RootExpr resolves the scratch root on the target. A target that was set up under the old name still has its workspaces in ~/agentdeck-scratch, and a sweep that looked elsewhere would silently stop covering them; so the old directory is used until a new one exists.
Variables ¶
This section is empty.
Functions ¶
func HistoryMentions ¶
HistoryMentions searches Codex's recorded conversations for each path. Claude files its history by directory, which Inspect already measured; Codex files by date, so finding a directory means reading them. A search that errors or times out reports a hit: not knowing is not the same as nothing being there.
func Purge ¶
Purge deletes trash entries older than days. Only names this package stamped are eligible, so nothing else that finds its way into the trash is removed.
Types ¶
type Dir ¶
type Dir struct {
Name string `json:"name"`
Path string `json:"path"`
Mtime float64 `json:"mtime"`
Files int `json:"files"`
Commits int `json:"commits"`
ClaudeBytes int64 `json:"claude_bytes"`
SizeKB int64 `json:"size_kb"`
Keep bool `json:"keep"`
// Unreadable is set when any signal could not be measured. Such a directory
// is treated as holding work, whatever the other signals say.
Unreadable bool `json:"unreadable,omitempty"`
}
Dir is what the target reported about one scratch directory.
type Entry ¶
type Entry struct {
Dir
TargetID int64 `json:"target_id"`
TargetName string `json:"target_name"`
Sessions []Session `json:"sessions"`
AgeDays float64 `json:"age_days"`
Verdict Verdict `json:"verdict"`
Reasons []string `json:"reasons"`
// NeedsHistoryCheck marks an otherwise-removable directory whose agent
// history has not been searched yet. That search reads every recorded
// conversation, so it is only run for directories that pass everything else.
NeedsHistoryCheck bool `json:"-"`
}
Entry is one directory with its verdict and the evidence for it.
type Result ¶
type Result struct {
DryRun bool `json:"dry_run"`
Days float64 `json:"days"`
Targets []TargetReport `json:"targets"`
Trashed []string `json:"trashed"`
Purged int `json:"purged"`
}
Result is what a sweep did, or with DryRun what it would do.
type Session ¶
type Session struct {
ID int64 `json:"id"`
Name string `json:"name"`
Agent string `json:"agent"`
Workdir string `json:"-"`
Project bool `json:"-"`
Live bool `json:"-"`
LastSeen float64 `json:"-"`
NativeID bool `json:"-"` // the agent recorded a conversation identity
CanResume bool `json:"can_resume"`
}
Session is the part of a session row the decision needs.
type Sweeper ¶
type Sweeper struct {
DB *store.DB
Reg *executor.Registry
Log *slog.Logger
Days float64 // idle days before an empty directory is removed
TrashDays float64 // days a removed directory stays recoverable
}
Sweeper applies the sweep across every target that has hosted a session.
func (*Sweeper) Discard ¶
Discard trashes a directory a person has decided against. It is recoverable until the purge, and refused outright while a session or a project owns it.
type TargetReport ¶
type TargetReport struct {
TargetID int64 `json:"target_id"`
TargetName string `json:"target_name"`
Root string `json:"root"`
Entries []Entry `json:"entries"`
Error string `json:"error,omitempty"`
}
TargetReport is one target's scratch root, or why it could not be read.
type Verdict ¶
type Verdict string
Verdict is what the sweep concluded about one directory.
const ( Live Verdict = "live" // a session is running in it Project Verdict = "project" // a session there belongs to a project Kept Verdict = "kept" // a person marked it to keep Work Verdict = "work" // something happened there; a person decides Recent Verdict = "recent" // empty, but not yet old enough to remove Empty Verdict = "empty" // empty and old: the sweep removes it )