Skip to main content

Module element

Module element 

Source
Expand description

§Module: element

§Spec

  • Defines Component, the parsed representation of a bounded document region delimited by <!-- agent:name [attrs...] --> (open) and <!-- /agent:name --> (close) HTML comments.
  • parse(doc) scans the raw document bytes for <!-- / --> comment pairs, builds a stack-based nesting model, and returns all Component values sorted by open_start.
  • Markers that appear inside fenced code blocks (backtick or tilde) or inline code spans are skipped; find_code_ranges(doc) uses the pulldown-cmark AST (CommonMark-compliant) to locate these regions.
  • is_agent_marker(comment_text) classifies whether the inner text of a comment is an agent open/close marker vs. an ordinary HTML comment.
  • Component names must match [a-zA-Z0-9][a-zA-Z0-9-]*; invalid names, unmatched opens, unmatched closes, and mismatched open/close pairs all return Err.
  • boundary:* prefixed markers (<!-- agent:boundary:ID -->) are recognised and skipped during component parsing; they are not treated as component open tags.
  • Opening markers may carry space-separated key=value inline attributes (e.g., patch=append). patch= takes precedence over the legacy mode= alias; patch_mode() encapsulates this lookup.
  • The non-agent comment fast path only previews comment text on UTF-8 char boundaries, so ordinary prose comments near multibyte glyphs never panic the parser.
  • Marker open_end / close_end byte offsets include a trailing newline when present, so that content slices are clean.
  • replace_content(doc, new_content) rebuilds the document preserving both markers, replacing only the bytes between them.
  • append_with_caret(doc, content, caret_offset) appends content after existing text, or inserts before the caret line when the caret falls inside the component.
  • append_with_boundary(doc, content, boundary_id) locates <!-- agent:boundary:ID --> inside the component (skipping any occurrence that lives inside a code block), replaces it with the new content, and re-inserts a fresh boundary marker; falls back to append_with_caret when no boundary is found.

§Agentic Contracts

  • parse is pure and deterministic: identical input always yields identical output.
  • All byte offsets (open_start, open_end, close_start, close_end) are valid UTF-8 char boundaries within the document string they were parsed from.
  • content(doc) returns exactly &doc[open_end..close_start] — no allocation.
  • replace_content and append_with_* never mutate the original &str; they return a new String with all offsets consistent for a fresh parse call.
  • Markers inside any code region (fenced block or inline span) are never parsed as components and never mutated by any append/replace operation.
  • append_with_boundary always re-inserts a boundary marker with a fresh UUID, preserving the invariant that exactly one boundary exists inside the component after each write.
  • Unknown or malformed key=value tokens in inline attributes are silently discarded; they never cause a parse error.

§Evals

  • single_range: doc with one component → one Component, correct name and content slice
  • nested_ranges: outer + inner components → two entries sorted outer-first
  • siblings: two adjacent components → two entries, each with correct content
  • no_ranges: plain markdown → empty vec, no error
  • unmatched_open_error: open without close → Err containing “unclosed component”
  • unmatched_close_error: close without open → Err containing “without matching open”
  • mismatched_names_error: <!-- agent:foo -->…<!-- /agent:bar -->Err “mismatched”
  • invalid_name: name starting with -Err “invalid component name”
  • markers_in_fenced_code_block_ignored: marker inside ``` block → not parsed as component
  • markers_in_inline_code_ignored: marker inside `…` span → not parsed
  • markers_in_tilde_fence_ignored: marker inside ~~~ block → not parsed
  • markers_in_indented_fenced_code_block_ignored: up-to-3-space-indented fence → not parsed
  • double_backtick_comment_before_agent_marker: `<!--` followed by real marker → one component
  • parse_component_with_patch_attr: patch=append on opening tag → patch_mode() = “append”
  • patch_attr_takes_precedence_over_mode: both patch= and mode= present → patch= wins
  • mode_attr_backward_compat: only mode=append present → patch_mode() = “append”
  • replace_roundtrip: replace content, re-parse → one component with new content
  • append_with_boundary_no_code_block: boundary found → content inserted, old ID consumed, new boundary present
  • append_with_boundary_skips_code_block: boundary inside code block skipped, real boundary used

Structs§

Component
A parsed component in a document.

Constants§

BACKLOG_ALIAS
Legacy alias for the backlog component.
BACKLOG_COMPONENT
Canonical component name for the backlog/pending component.
BACKLOG_DONE_COMPONENT
Canonical component name for the completed/reaped backlog archive.
ICEBOX_COMPONENT
Canonical component name for the icebox component.
REVIEW_COMPONENT
Canonical component name for tracked work awaiting human review.

Functions§

converge_queue_auto
Converge the agent:queue opening-tag auto attribute to want_auto.
find_code_ranges
Find byte ranges of code regions (fenced code blocks + inline code spans). Markers inside these ranges are treated as literal text, not component markers.
find_comment_end
Find the end of an HTML comment (-->), returning byte offset past >.
find_non_agent_html_comment_ranges
Find byte ranges for ordinary HTML comments, skipping code spans/blocks and preserving agent: markers for the component parser.
find_quoted_ranges
Find byte ranges of same-line double-quoted spans ("...") — #0kjc/#mdastquote.
is_agent_marker
True if the text inside <!-- ... --> is an agent component marker.
is_backlog_component
Check whether a component name refers to the backlog component (accepts both canonical "backlog" and legacy "pending").
is_backlog_done_component
Check whether a component name refers to the completed/reaped backlog archive.
is_icebox_component
Check whether a component name refers to the icebox component.
is_review_component
Check whether a component name refers to the review component.
is_tracked_work_component
Check whether a component name refers to tracked work that participates in do #id closeout (agent:backlog / legacy agent:pending, agent:review, and agent:icebox).
malformed_agent_comment_reason
Detect agent-looking HTML comment markers that were truncated before their same-line --> terminator. The normal parser only sees complete comments, so a CRDT/editor split like <!-- /agent:exchange -- can otherwise be skipped or consume a later unrelated terminator.
parse
Parse all components from a document.
parse_attrs
Parse key=value pairs from the attribute portion of an opening marker.
strip_backlog_patch_attr
Strip deprecated patch=... (and legacy mode=...) attributes from backlog/pending component opening tags. The backlog component’s patch mode is always replace by built-in default; the inline attribute is redundant since the binary owns all backlog mutations via --pending-* flags.
strip_comments
Strip comments from document content for diff comparison.
structural_corruption_reason
Detect structural corruption that must never be adopted as a snapshot base (#dupcontent). Returns Some(reason) when the document is corrupt: