Skip to content

calternal_notes_core::tasks::extract

extract_task_index — the read-only Task and Checkbox projector for #430.

This is the integration crux of the tasks system: it ties together the frontmatter reader (T3), the inline-line parser (T4), the rollup (T2), and the recurrence normalizer (NLP) into one pure, read-only function.

Two branches:

  • File branch (task-specific frontmatter): one File row + one Inline child row per child checkbox. A matching root mirror is not a second Task, including when its literal title contains Task sigils (#940; DESIGN §40). A folder name never sets the kind.
  • Day/body branch (everything else): one Inline row per checkbox line.

This function NEVER rewrites the markdown. It is a pure projection: same input → same output, no side effects. The write-back lives in:

  • set_task_frontmatter_field (for file status flips)
  • set_task_line_status (for inline checkbox flips)

Write boundaries use has_duplicate_task_ids before they persist text. This keeps invalid block-ID collisions from reaching the Index after a Home write (#531).

Status truth-precedence (file branch — spec §6)

Section titled “Status truth-precedence (file branch — spec §6)”

Evaluated in this order; first match wins:

  1. completed: present in frontmatter → Done (terminal; no override flag)
  2. status: present AND parseable → that value, status_overridden = true
  3. is_project (>1 child) → rollup_status(child_statuses)
  4. Single child → its status; zero children → Todo

An unparseable status: value is treated as absent (falls through to 3/4) and does NOT set status_overridden (contract §6; locked by test unknown_status_value_falls_through_to_rollup).

Source: crates/calternal-notes-core/src/tasks/extract.rs

pub fn extract_task_index(path: &str, text: &str) -> Vec<TaskIndexEntry>

Project a markdown file into zero or more TaskIndexEntry rows.

  • path: Home-relative path (e.g. "Notes/japan.md", "Notes/20260627-dailynote.md").
  • text: raw file contents (UTF-8 string).

Returns an empty Vec for files with no checkbox lines (e.g. pure notes).

Pure and read-only — never panics on any well-formed UTF-8 input (malformed dates, unknown status words, empty files are all handled gracefully with None/default fallbacks).

Source: crates/calternal-notes-core/src/tasks/extract.rs:66

pub fn has_duplicate_task_ids(path: &str, text: &str) -> bool

Return whether a Markdown source projects two Tasks to the same Index ID.

Write boundaries call this before changing the Home. The Index uses (User, Task ID) as a key, so a duplicate must be rejected before the file write instead of failing during the later projection (#531).

Source: crates/calternal-notes-core/src/tasks/extract.rs:79

pub fn is_task_note(text: &str) -> bool

True when frontmatter contains a Task field. Fields shared by ordinary Notes, such as title, created, or calternal-id, do not set the kind.

Source: crates/calternal-notes-core/src/tasks/extract.rs:92

pub fn set_task_body(text: &str, body: Option<&str>) -> Result<String, String>

Replace the free prose in a rich Task while retaining its frontmatter and every checkbox line byte-for-byte. CalDAV DESCRIPTION maps to this region; the Task parser already defines it as prose before the first checkbox.

Source: crates/calternal-notes-core/src/tasks/extract.rs:938