Expand description
§Module: backlog
Pure functions for parsing and mutating the agent:backlog component body.
Each pending item carries:
- a GFM task-list checkbox (
- [ ]/1. [ ]or- [x]/1. [x]) - an id prefix rendered as
[#xxxx](generated hash or caller-provided custom id) - free-form text
Canonical unordered form: - [ ] [#a3f2] refactor preflight commit path
Canonical ordered form: 1. [ ] [#a3f2] refactor preflight commit path
This module is I/O-free. Callers (backlog_cmd.rs, preflight.rs, write.rs)
handle reading/writing files, locking, and git commits.
§Spec
- Parser accepts legacy forms and normalizes via
backfill. - IDs are stable across edits/reorders; generated once (or supplied on insert), preserved thereafter.
reapremoves- [x]items.detect_reorderdiffs id order between snapshot/current.- Mutation ops (
op_add/done/edit/clear/reorder) return a new body string, never mutate in place.
Structs§
- Dropped
Backlog Item - Dropped
Backlog Report - Execution
Context - Machine-readable execution-context attributes parsed from a backlog item’s
text (
#goqueuestall). - Explicit
IdCollision - Malformed
Pending Item Line - Malformed
Tracked Item Ref - Pending
AddBatch Item Outcome - Pending
AddBatch Outcome - Pending
AddOutcome - Pending
Item - A parsed pending list item.
- Shadow
Pending Item - Shadow
Pending Report - Symptom
Dedupe Key - Tracked
Component Item Drop
Enums§
- AddPosition
- Insert a new item at the beginning of the body. Binary assigns hash and
[ ](or[/]ifgated). Returns(new_body, assigned_id).#ah0s: explicit insertion position for a newly added pending item. The backlog is a priority-ordered pool with id-based consumption (not a stack or queue), so position encodes author intent and is set explicitly when it matters.Firstis the cheap default used by--pending-add. - Pending
List Marker - Pending
Op - Mutating operation on a pending item — used by the state-transition matrix.
- Pending
State - Lifecycle state for a pending item, encoded by its GFM checkbox.
- Tracked
Work List - Transition
Result - Outcome of
validate_transition.NoOpmeans “already in target state, do nothing”.
Constants§
- CLEAN_
SESSION_ TAG - Author-controlled execution-context tag literals on a backlog item
(
#goqueuestall). They live as bracketed tokens in the item text alongside markers like[recommended]/[TOP], and gate whether ago-mode queue may auto-drain the item in the current session type. - FOCUSED_
CYCLE_ TAG - IN_
PROGRESS_ MARKER - OPERATOR_
VERIFY_ TAG - PRIORITY_
RANK_ UNSET - Rank an item’s priority from a
priority=<1..9>token anywhere in its text (#backlog-priority-attribute).1is the highest priority and sorts first;9is the lowest numbered priority. An item with no validpriority=token ranks10— below every numbered item — so unprioritized items sort last while preserving their authored relative order under a stable sort.
Functions§
- active_
enqueue_ item_ ids - Active open backlog item ids marked for one-shot queue insertion.
- active_
item_ after_ deps - Active (open) backlog item ids paired with their
after=#iddependency ids, in document order. Feeds the auto-dag queue ordering (#queue-auto-dag-priority). - active_
item_ execution_ contexts - Active (open) backlog item ids paired with their parsed execution context,
in document order (
#goqueuestall). Feeds the go-mode backlog→queue sync skip and the queue-continuation drainable-head computation. - active_
item_ ids - Active (open
[ ], not gated, not done) backlog item ids in document order. - active_
item_ priorities - Active (open) backlog item ids paired with their priority rank, in document
order. Used to priority-order a synced
agent:queue(#backlog-priority-attribute). - backfill
- Lazy backfill: ensure every item has a hash id and a checkbox.
- canonicalize_
preserving_ non_ item_ lines - canonicalize_
tracked_ work_ body - Render a tracked-work component body in canonical form, assigning any missing ids against an otherwise empty active-id registry.
- completed_
items - completed_
tracked_ items_ in_ components - completed_
tracked_ items_ in_ content - component_
matches_ tracked_ surface - content_
has_ resolved_ tracked_ work_ id - detect_
dropped_ from_ history - Compare current document against a baseline to find open backlog items that existed in the baseline but are completely absent from the current document.
- detect_
dropped_ from_ history_ with_ extra_ current_ ids - detect_
identity_ collisions - Collect identities that resolve under more than one active source.
- detect_
malformed_ item_ lines - Find lines that look like tracked checklist items but are not parseable as live pending items. These lines are dangerous during closeout because guards that operate on parsed items would otherwise treat the matching id as absent.
- detect_
reorder - Detect reorder: returns
Some(current_order)when id-sets match but order differs. ReturnsNonewhen id-sets differ or order is identical. - detect_
shadow_ open_ items - document_
active_ identities - Build the active document identity registry for tracked-work lookup.
- dropped_
tracked_ component_ items - Return non-exchange components whose tracked checklist item count decreased.
- ensure_
new_ item_ explicit_ id_ available - Enforce that an explicit new tracked-work id has exactly one active meaning in the document after insertion.
- ensure_
no_ completed_ tracked_ items - ensure_
no_ new_ leading_ custom_ id_ prefix - explicit_
custom_ id - Return the explicit, caller-provided custom id from a
--pending-additem string (id=<id> <text>or[#<id>] <text>), normalized (lowercase, no#). ReturnsNonefor auto-id items (no explicit prefix) and for malformed prefixes — callers that need the strict parse error use the add path itself. Used by mutation-time collision enforcement (#preset-item-id-collision-enforce) so an explicit id that collides with a prompt preset or active item id is rejected before the add is written. - explicit_
new_ item_ id_ collision - Return existing active sources that a new explicit item id would collide
with. Auto-id adds (no
id=<custom>/[#custom]prefix) never collide. - extract_
done_ item_ own_ ids - Extract only each done/archive item’s own
#id— the FIRST[#id]on a list-item line (- <date> [#id] …/- [x] [#id] …) — and ignore any other[#id]cited in that item’s prose. - extract_
items_ by_ id - Remove specific tracked items by id while preserving surrounding non-item
structure in the source body. Returns
(remaining_body, moved_body, matched_ids). - extract_
pending_ hash_ ids - Ordered unique bare
#idreferences in free text. - extract_
pending_ ids_ from_ text - find_
open_ tracked_ work_ component_ in_ content - find_
tracked_ work_ component_ in_ content - format_
dropped_ refs - format_
shadow_ refs - generate_
hash_ n - Generate a stable variable-width base32 hash.
widthis clamped to[4, 8]— the spec §1 ceiling on collision extension. - identity_
collision_ for_ new_ id - Return existing active sources that a new explicit id would collide with.
- is_
valid_ pending_ id - item_
after_ deps - Parse
after=#iddependency tokens from an item’s text (#queue-auto-dag-priority). Declares that this item must be ordered after each named id. Accepts repeated tokens and comma lists:after=#a,after=#a,#b,after=#a after=#b. Ids are normalized lowercase with#/[/]stripped; only valid pending ids are kept. Theafter=token must start at a word boundary so prose likehereafter=does not match. - item_
clean_ session_ required - True when the item text carries a
[clean-session]tag token (#goqueuestall). Matched case-insensitively as a whitespace-delimited bracketed token so prose mentions of the word do not trip it. - item_
execution_ context - Parse all execution-context tags from an item’s text (
#goqueuestall/#qstallguard). - item_
focused_ cycle_ required - True when the item text carries a
[focused-cycle]tag token (#qstallguardLayer A). - item_
not_ before_ day - Parse a
not-before=YYYY-MM-DDscheduling precondition from an item’s text (#backlog-not-before). Returns the threshold as a day number (days since 1970-01-01) so callers can compare it againsttoday_civil_day. The token must start at a word boundary so prose does not match, and only a strict zero-or-more-digitYYYY-MM-DDis accepted; a malformed value is ignored (the item is then treated as having no precondition rather than silently held). - item_
operator_ verify_ required - True when the item text carries an
[operator-verify]tag token (#goqueuestall). - item_
precondition_ unmet - True when an item’s
not-before=scheduling precondition is still in the future relative totoday(so it must be held out of the backlog→queue sync). An item with nonot-before=token, or with a threshold on/<=today, is eligible (#backlog-not-before). - item_
priority_ rank - maintenance_
surface_ label - malformed_
tracked_ item_ interruption_ message - malformed_
tracked_ item_ refs - malformed_
tracked_ item_ refs_ in_ components - merge_
partial_ backlog_ prefix - normalize_
pending_ id - op_add
- op_
add_ at - Position-aware variant of
op_add(#ah0s). Assigns/validates the id and dedups exactly likeop_add, then inserts the new item atposition.After/Beforeerror if the anchor id is absent. - op_
add_ at_ with_ outcome - Add a pending item and report whether it inserted a new item or attached evidence to an existing symptom with the same de-duplication key.
- op_
add_ with_ outcome - op_
append_ items - Append existing tracked items after the current item list, preserving order.
- op_
clear - Clear all items from the body. Non-item lines, including headers, are preserved.
- op_
dedupe_ identical_ items - Collapse runs of identical same-id entries to a single representative, preserving first-seen order. Two items are “identical” when their id, state, gate type, text, and continuation all match — this targets the exact-dup shape an interleaved finalize produces, never distinct items that merely share an id (those remain so an ambiguity warning still surfaces). Returns the rewritten body and the ids that had duplicates removed.
- op_done
- Mark an item
[x]by id. Phase 1: state-machine validation lives in the upcomingbacklog_cmdlayer; this primitive forces Done unconditionally. - op_edit
- Edit an item’s text, preserving its hash id.
- op_
edit_ many - Apply multiple text edits in order to one tracked-work body.
- op_gate
- Transition an item to
Gated([/]) by id. - op_
insert_ item_ first - Insert an existing tracked item at the first item slot of a component body.
- op_
prepend_ many_ with_ outcomes - Prepend multiple new tracked-work items while preserving caller order.
- op_
remove_ matching_ tracked_ line - op_
reorder - Reorder items by id. Listed ids come first (in the given order); unlisted ids keep their relative order and follow.
- op_
resolve_ gate - Resolve all gated items matching a typed gate. Finds items with
[/<gate_type>]and flips them to[x]. Returns(new_body, resolved_ids). - op_
set_ gate_ type - Set a typed gate on a gated item. The item must already be in
[/]state. Transitions[/] → [/<gate_type>]. Errors if the item is not gated. - op_
set_ gate_ verify - Set (or replace) a typed proof/disproof verify predicate on a gated item
(
#optverify/#optv1). The item must already be in[/]state. The predicate is stored as an inline<!-- gate-verify ... -->annotation in the item text (seecrate::gate_verify);set_atstamps the gate-set time so the later ops.log scan only counts markers emitted at/after it. - op_
take_ active_ items_ by_ ids - Extract non-done items with ids in
ids, returning the updated body and removed items. - op_
take_ all_ by_ id - Remove every item whose id matches
id, returning the rewritten body and the removed items. Unlikeop_take_item(which keeps a single representative and errors on a miss), this collapses duplicate-id entries in one pass and returns them all — used by--review-removeso a duplicated review id (e.g. an interleaved finalize that wrote the same#idtwice) can be cleared without an ambiguous edit-by-id. - op_
take_ item - Remove a tracked item by id and return the updated body plus the removed item.
- op_
take_ items_ by_ state - Extract all items matching
state, returning the updated body and removed items. - op_
ungate - Transition an item to
Open([ ]) by id. - open_
backlog_ ids_ in_ content - open_
tracked_ work_ component_ name_ in_ content - open_
tracked_ work_ ids_ in_ content - parse_
items - Parse the pending component body into (prelude, items, postlude).
- preserves_
non_ item_ structure - printable_
tracked_ work_ lines - Non-empty tracked-work body lines as rendered by the CLI list command.
- reap
- Reap
[x]items.[/](gated) items are never reaped. Returns(new_body, removed_ids). - reap_
with_ items - Reap
[x]items and return the removed items (with text), not just ids. Used by preflight to archive reaped items to anagent:donecomponent. - render_
items - Serialize items back to a body string.
- review_
counts - set_
in_ progress_ item_ ids - Set the ephemeral in-progress marker on exactly the requested tracked item ids, clearing stale markers from every other parsed item in the body.
- should_
reap_ already_ done_ mirrors - should_
reap_ ops_ proof_ completions - sort_
by_ priority - Stable-sort the item lines of a pending body by per-item priority
(
#backlog-priority-attribute), preserving every non-item segment (blank lines, prose, ordered-list separators) at its original position. ReturnsSome(new_body)when the order changes,Noneotherwise (idempotent). - strip_
execution_ context_ tags - Remove the
[clean-session]/[operator-verify]execution-context tags from display text (#goqueuestall), collapsing the whitespace they leave behind. Mirrors how machine-only markers are kept out of rendered prose. - symptom_
dedupe_ key_ from_ text - today_
civil_ day - Today as a day number (days since 1970-01-01, UTC) from the system clock,
for evaluating
not-before=scheduling preconditions. Best-effort: a clock before the epoch clamps to day 0. - tracked_
body_ for_ reorder - tracked_
component_ item_ counts - Count tracked checklist items in every non-exchange component.
- tracked_
item_ ref - tracked_
item_ refs - tracked_
work_ ids_ for_ target - tracked_
work_ ids_ from_ component_ body - trim_
tracked_ parent_ prefix - validate_
transition - Apply the state-machine matrix from
specs/pending-system.md§4.