Skip to main content

write_note

Function write_note 

Source
pub fn write_note(
    root: &Path,
    rel: &str,
    content: &str,
    now: OffsetDateTime,
) -> Result<WriteOutcome, FrontmatterError>
Expand description

Write a note to root / rel using the §6 exclusion rule.

Path hardening: rel must be a vault-relative POSIX path (no .., no leading //\, no null). Otherwise we return Err(FrontmatterError::Io(InvalidInput)) without touching the filesystem (mirrors VirtualFs::safe_path).

  • System path (Chat.md, anything non-.md, anything inside a SYSTEM_DIR) → raw atomic_write. We never synthesize frontmatter. If the bytes match the existing file, we return WriteOutcome::NoOp without touching the file.

  • Memo path → routed through oxi-frontmatter::write_document with the body’s frontmatter pre-parsed:

    • If content parses as Memo{table, body} (caller supplied a frontmatter block), we write body to the file with the incoming table as basewrite_document carries its id/created/unknown keys forward, and our oxios: map is merged in alongside them. This is how editor-supplied tags or aliases survive a knowledge-write pass.

    • If content parses as BodyOnly, the whole content is the body and the file’s existing table becomes the base (write_document reads it). This is the “missing frontmatter ⇒ synthesize” path.

    In both cases write_document synthesizes id/created if the resulting table lacks them, bumps updated only on a real write, and returns WriteOutcome::NoOp when the parsed form is identical to what was on disk.

now is injected for testability.