Documentation
¶
Overview ¶
Package checklist is a working copy's checklist on disk: the list of what a session is working on, what it waits on and what it has promised, kept in the local tier so it survives compaction and crashes (itd-2610170638184486, spc-2610230805429429 step 1). This file holds the v1 schema, its strict decode and its validation; store.go holds the checked write and the falling-back read.
The file is JSON with typed fields rather than prose, so it can be validated and scanned for secrets field by field (the spec's "Settled here"). A credential is recorded only by its kind, scope and expiry, each from a closed vocabulary or a timestamp, never as free text (adr-2610222026265719, brief invariant 24).
No refusal in this package repeats the value it refused. A value that fails the schema is untrusted, and a secret pasted into the wrong field is exactly what the schema would see first; naming the field and the rule is enough to find it.
Index ¶
- Constants
- Variables
- func RecordCompaction(repoRoot, trigger string, at time.Time) error
- func Render(res Result, budget int) string
- func Update(repoRoot string, change func(Result) (Checklist, error)) error
- func WriteForTest(repoRoot string, c Checklist) error
- type Checklist
- type Credential
- type CredentialKind
- type CredentialScope
- type Event
- type FieldError
- type Item
- type Promise
- type Result
- type SecretError
- type Source
- type State
Constants ¶
const ( TriggerManual = "manual" TriggerAuto = "auto" TriggerOther = "other" )
The triggers a compaction line records. The host names "manual" (the person's /compact) or "auto" (a full context); any other value is recorded as TriggerOther, so text from the payload is never copied into the file.
const ( FileRelPath = TierRelPath + "/checklist.json" LastGoodRelPath = TierRelPath + "/checklist.last-good.json" )
FileRelPath is the checklist, one per working copy (dcn-2610180913444971), and LastGoodRelPath the copy only a checked write produces (spc-2610230805429429, "The write").
const EventCompact = "compact"
EventCompact is the one event recorded: the host is about to compact the session's context.
const EventsRelPath = TierRelPath + "/checklist.events.jsonl"
EventsRelPath is the sidecar, beside the checklist in the local tier.
const EventsSchema = "abcd/checklist-events/v1"
EventsSchema names each line's shape.
const LockRelPath = TierRelPath + "/checklist.lock"
LockRelPath is the lock every read-change-write of the checklist holds.
const MaxTitleRunes = 200
MaxTitleRunes caps an item's title, in characters (the spec's "The file").
const NoExpiry = "none"
NoExpiry is the expiry of a credential that does not expire: the ADR's "or that it has none", spelt as a word rather than an absent field so a forgotten expiry is a refusal, not a silent "never".
const Schema = "abcd/checklist/v1"
Schema is the v1 schema's name, carried in every file's `schema` field. A reader meeting any other value refuses the file rather than guessing at it.
const TierRelPath = ".abcd/.work.local"
TierRelPath is the local tier the checklist lives in, repo-relative and slash-separated (an os.Root path). As for the mode store, its presence is the managed-only property: the writer requires it and never creates it.
Variables ¶
var ErrEventsNotKept = errors.New("checklist: checklist.events.jsonl is not a plain file this account owns, readable by it alone")
ErrEventsNotKept is RecordCompaction's refusal for a sidecar that is not a plain file this account owns, with one name and no bit for group or others: something other than the hook made it, and nothing is appended to it.
var ErrLockHeld = errors.New("checklist: another writer holds the checklist's lock, or its lock file is not a plain file; nothing was written")
ErrLockHeld is Update's refusal when another writer held the checklist's lock past the wait, or the lock file is not a plain file: nothing was written.
var ErrNoLocalTier = errors.New("checklist: no local-ephemeral tier")
ErrNoLocalTier is the write's refusal when the checkout has no local tier.
var ErrNotKept = errors.New("checklist: the checklist file here does not keep the owner-only mode or the owner the reader requires, so the list cannot be kept in this working copy; remove checklist.json (or chmod it 600 as its owner) and add again, on a filesystem that keeps both")
ErrNotKept is the write's refusal when the checklist the reader would see is one it refuses for its mode or owner: a filesystem that does not keep the 0600 mode or the owner, or a file changed by something other than the verb. A write the next read refuses loses every item, so none is made.
ErrScannerUnavailable is the refusal when the native secret scanner cannot be built or runs degraded. Both the write and the read fail closed on it: a file that could not be checked is never written, and never shown.
var ErrTracked = errors.New("checklist: git tracks the checklist in this checkout; untrack it with `git rm --cached` first")
ErrTracked is the write's refusal when git tracks a checklist file: a write would change the committed file, and the reader refuses a tracked file, so every item written would be lost to the next read.
Functions ¶
func RecordCompaction ¶ added in v0.17.0
RecordCompaction appends one compaction line, at and the host's trigger, to the sidecar under an already-resolved checkout root, creating the file 0600 in a plain local tier, never the tier itself. It goes through the checkout's os.Root, so a tier swapped for a link cannot carry the write out of the checkout, and one write of one short line with O_APPEND, so two sessions compacting at once each add their own whole line. Every refusal comes before any byte is written: an absent or linked tier (ErrNoLocalTier) and a sidecar something else made (ErrEventsNotKept).
The opened file is checked, not only its path: a sidecar already there is judged by its Lstat, opened without creating, and its handle must be that same file and pass the same judgement; an absent one is created exclusively, so the open never lands on a file something else put there meanwhile, and its handle is judged too. O_NONBLOCK keeps a FIFO from holding the open.
func Render ¶
Render is the checklist as the text a session's context is given, within budget bytes: the reader's reason first when it did not read checklist.json clean, then the open items (working, waiting), then the done and dropped ones, each group newest first, one line an item.
"Newest" is file order read backwards: an item carries no time of its own, and the verbs append each new item to the end of the list.
Over budget, the render keeps the reason and the newest open items, drops the rest from the end (the closed items before any open one), and ends with a line saying how many it left out and that `abcd checklist` shows them all. The budget is in bytes, which never undercounts a host that measures in characters. An empty list that does not fit renders as the reason alone. When not even the reason fits, the render is empty; a FromNothing result renders as the reason line alone.
Every field the reader passed is one line with no control character (Validate), so each prints as it stands.
func Update ¶
Update is the one read-change-write cycle: it reads the checklist as Read does, hands the result to change, and writes what change returns through write, holding the checklist's lock across all three. Every writer that builds on what is there goes through it.
WHY a lock: a session's verb, its stop hook and sub-agents sharing the worktree write one checklist, and two unlocked cycles that read the same list each write back their own item over the other's, losing one; a lost item is the failure the checklist exists to prevent. The lock is fsutil's one inter-process primitive (iss-129), the one `abcd decide` and the memory store take, never a lock of this package's own.
func WriteForTest ¶
WriteForTest writes c as write does, for a test outside this package that needs a checklist on disk; production writes go through Update.
Types ¶
type Checklist ¶
type Checklist struct {
Schema string `json:"schema"`
UpdatedAt string `json:"updated_at"`
// UpdatedBy is the host's session id for the session that last wrote.
UpdatedBy string `json:"updated_by"`
Items []Item `json:"items"`
}
Checklist is the v1 file. Timestamps are kept as RFC 3339 strings and parsed by Validate, not by the decoder: encoding/json's time error quotes the value it could not parse, and a refusal here never quotes a value.
type Credential ¶
type Credential struct {
Kind CredentialKind `json:"kind"`
Scope []CredentialScope `json:"scope"`
Expiry string `json:"expiry"`
}
Credential names a credential an item needs by its kind, scope and expiry only (adr-2610222026265719). There is deliberately no field for anything else, and the strict decode refuses one in the file.
type CredentialKind ¶
type CredentialKind string
CredentialKind is what sort of credential an item needs. The list is the three adr-2610222026265719 names as examples; the ADR fixes that the list is closed, not its members, so a new kind is an edit here.
const ( AppInstallationToken CredentialKind = "app-installation-token" ModelServiceKey CredentialKind = "model-service-key" SigningKey CredentialKind = "signing-key" )
type CredentialScope ¶
type CredentialScope string
CredentialScope is one thing a credential reaches. adr-2610222026265719 describes scope as "a repository and the acts allowed, a service" and requires a fixed list; it gives none, so this one is defined here: the acts an App installation token is granted on a repository, a model service, and signing. The repository itself is not recorded, because a fixed list cannot hold its name and the ADR allows no free text in a credential.
const ( ScopeContentsRead CredentialScope = "contents-read" ScopeContentsWrite CredentialScope = "contents-write" ScopePullRequests CredentialScope = "pull-requests" ScopeIssues CredentialScope = "issues" ScopeReleases CredentialScope = "releases" ScopeWorkflows CredentialScope = "workflows" ScopeModelService CredentialScope = "model-service" ScopeSigning CredentialScope = "signing" )
type Event ¶ added in v0.17.0
type Event struct {
Schema string `json:"schema"`
At time.Time `json:"at"`
Event string `json:"event"`
Trigger string `json:"trigger"`
}
Event is one line of the sidecar.
type FieldError ¶
FieldError is a schema refusal. Field is the path to the offending field (`items[2].state`), Problem the rule it breaks; neither carries the value.
func (*FieldError) Error ¶
func (e *FieldError) Error() string
type Item ¶
type Item struct {
// ID is a short stable slug the verbs address the item by.
ID string `json:"id"`
Title string `json:"title"`
State State `json:"state"`
// WaitsOn is a record id, `pr:<n>`, `person:<role>` or `slot:<kind>`.
WaitsOn string `json:"waits_on,omitempty"`
NextLook string `json:"next_look,omitempty"`
// Promise is a trigger and the act it promises; the remainder of the spec
// types the trigger, and step 1 keeps both as one-line text.
Promise *Promise `json:"promise,omitempty"`
// OwnerRefs names the work the item is about: a record id (a reservation),
// `pr:<n>` or `branch:<name>`.
OwnerRefs []string `json:"owner_refs,omitempty"`
Credential *Credential `json:"credential,omitempty"`
}
Item is one entry. WaitsOn, NextLook, Promise, OwnerRefs and Credential are optional.
type Result ¶
Result is a Read's answer: the checklist (zero for FromNothing), the file it came from, and the reason as one sentence a render can print as it stands. The reason names files, fields and bundled pattern kinds, never a value.
WHY the reason is fixed text: the session-start hook injects it into every session's context, where nothing taken from the repository may go (iss-2608241115201044, cli.go's session-start notices). So no clause carries an error's text, which can quote the tracked .abcd/config/pii.json or name the checkout's absolute path, nor a pattern kind that file declared; each names a file abcd defines and a cause in abcd's own words.
func Read ¶
Read reads the checklist under an already-resolved checkout root. The reader is the enforcement (the spec's "Settled here"): a file written past the verb, by a shell or an editor, reaches it unchecked, so it validates and scans FileRelPath, and on any failure validates and scans LastGoodRelPath, and on a second failure answers FromNothing. It never writes, so a read never promotes a file to last-good. A temp file a killed writer left is never read: only the two named paths are.
func ReadContext ¶ added in v0.17.0
ReadContext is Read with its git calls bound to ctx, the tracked check and the scanner's identity probe: when ctx ends, git is killed and the read answers as for a git that could not say, or a scanner that could not run, FromNothing. A hook reads under its own deadline through it.
type SecretError ¶
SecretError is the write's refusal for a field the native scanner matched (adr-2610222026265719): the field's path and the pattern kind, never the match.
func (*SecretError) Error ¶
func (e *SecretError) Error() string
type Source ¶
type Source string
Source says which file a Read used.
const ( // FromFile is the checklist itself. FromFile Source = "checklist" // FromLastGood is the last copy a checked write produced, used because the // checklist itself failed. FromLastGood Source = "last-good" // FromNothing means neither file passed; the result carries no checklist. FromNothing Source = "nothing" )