Files
Marcos Paulo b32650767c
ci / ci (macos-latest) (push) Has been cancelled
ci / ci (ubuntu-latest) (push) Has been cancelled
ci / ci (windows-latest) (push) Has been cancelled
docs: specs and briefs for smart folders, version diff, media timestamps, clean paste, link cards, spaced repetition
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-21 12:18:00 -03:00

2.7 KiB

TASK smart-folder-model: saved-query folder definitions, validation and JSON (Smart folders)

Runs through OpenCode (specs/agents/opencode-runbook.md is attached automatically). Task 1 of specs/plugins-parity/smart-folders/tasks.md.

OWNS

  • crates/engine/src/smart_folders/mod.rs (new, //! doc, mod model; pub use model::{...};), crates/engine/src/smart_folders/model.rs (new), one mod smart_folders; in crates/engine/src/lib.rs
  • unit tests inside model.rs (#[cfg(test)]), because the module stays pub(crate)

FILES TO OPEN

  • specs/plugins-parity/smart-folders/spec.md D1
  • crates/engine/src/activity/outbox.rs (versioned JSON file pattern)
  • crates/engine/src/lib.rs (how modules are declared), crates/engine/src/error.rs (add ONE variant SmartFolder(String) only if no fitting one exists)

GOAL / API

Write crates/engine/src/smart_folders/model.rs in your SECOND tool call (stub + one failing test first).

pub struct SmartFolder { pub id: String, pub name: String, pub icon: Option<String>, pub source: Source, pub limit: Option<usize> }
pub enum Source { Yaml(String), Base { path: String, view: Option<String> } }
pub struct Store { pub folders: Vec<SmartFolder> }
impl Store { pub fn parse(json: &str) -> Result<Store>; pub fn to_json(&self) -> String; pub fn upsert(&mut self, f: SmartFolder) -> Result<()>; pub fn remove(&mut self, id: &str) -> bool; }
pub fn validate(f: &SmartFolder) -> Result<()>;
pub fn new_id(existing: &[SmartFolder]) -> String;   // "sf_" + 6 chars [a-z0-9], unique among existing, deterministic given a counter, no rand dependency: hash of (len, time ms)

JSON shape is spec D1 (yaml xor path). Limits: 200 folders, name 1..80 chars (trimmed, no control chars), yaml <= 16 KiB and must parse with notescraft_bases::Base::parse, path must end .base and not start with .obsidian/ or .notescraft/, id sf_[a-z0-9]{4,12}, limit 1..=2000. Unknown version -> Err. All problems return Err; nothing is clamped or fixed. No [i], no [a..b], no panics.

TESTS

Round trip; yaml+path both -> Err; neither -> Err; 201 folders; name 81 chars and empty and control char; yaml 16 KiB+1; yaml that does not parse; path x.md, .notescraft/a.base; bad id; limit 0 and 2001; unknown version; corrupt JSON; new_id avoids collisions.

VERIFY

export PATH="$HOME/.cargo/bin:$PATH"
cargo test -p notescraft-engine smart_folders
cargo clippy -p notescraft-engine --all-targets -- -D warnings
rustfmt --edition 2024 crates/engine/src/smart_folders/mod.rs crates/engine/src/smart_folders/model.rs

DO NOT

Edit Cargo files; read or write any file (task 2 does IO); register commands; touch the UI or the Bases crate; add a dependency.