2.6 KiB
TASK time-fragment-parser: parse #t=04:12 link subpaths into milliseconds (Media timestamp links)
Runs through OpenCode (specs/agents/opencode-runbook.md is attached automatically). Task 1 of specs/plugins-parity/media-timestamps/tasks.md.
OWNS
crates/markdown/src/timefrag.rs(new), onemod timefrag;+pub use timefrag::{MEDIA_EXTS, TimeFragment, format_time, parse_time_fragment};incrates/markdown/src/lib.rs(ifcrates/markdown/src/already holds 12 loose.rsfiles, createcrates/markdown/src/timefrag/mod.rsand say so)crates/markdown/tests/timefrag.rs
FILES TO OPEN
specs/plugins-parity/media-timestamps/spec.mdD1crates/markdown/src/links.rs(LinkTarget.subpath: no leading#)crates/markdown/src/lib.rs(export block near line 47)
GOAL / API
Write crates/markdown/src/timefrag.rs in your SECOND tool call (stub + one failing test).
pub struct TimeFragment { pub start_ms: u64, pub end_ms: Option<u64> }
pub const MEDIA_EXTS: &[&str]; // lowercase: mp3 wav ogg m4a flac opus aac 3gp mp4 webm mov mkv m4v (copy the audio list from crates/ui-egui/src/widgets/tabs/kind.rs AUDIO_EXTS and the video list next to it)
pub fn parse_time_fragment(subpath: &str) -> Option<TimeFragment>;
pub fn format_time(ms: u64) -> String; // "4:12", "1:02:03"; seconds truncated, not rounded
pub fn is_media_ext(ext: &str) -> bool; // case-insensitive
subpath is the text after # (t=04:12). Grammar: t= + optional npt: + time + optional , + time. Time = S[.f], M:SS[.f] or H:MM:SS[.f]; fraction 1..=3 digits; with colons, MM/SS must be < 60 (in M:SS the minutes may be any number up to 6000, in H:MM:SS hours up to 100); total <= 100 h; whole input <= 64 bytes; end must be > start, else None. Anything else (empty, negative, exponent, spaces, extra & params, non-ASCII digits) -> None. Use checked_* arithmetic and split_once/get, never [i] or [a..b]. No panics.
TESTS
t=04:12 = 252000; t=252; t=1:02:03 = 3723000; t=npt:10.5; t=10,20; t=20,10 None; t=99:99; t=1:75; t=; t=-1; t=1e3; t=1.2345; 65-byte input; 100 h boundary ok and +1 ms None; format_time(252000) = 4:12, format_time(3723000) = 1:02:03, format_time(0) = 0:00; round trip for 1 000 values; is_media_ext("MP3").
VERIFY
export PATH="$HOME/.cargo/bin:$PATH"
cargo test -p notescraft-markdown --test timefrag
cargo clippy -p notescraft-markdown --all-targets -- -D warnings
rustfmt --edition 2024 crates/markdown/src/timefrag.rs crates/markdown/tests/timefrag.rs
DO NOT
Edit Cargo files or links.rs; add a dependency; touch index, lint or UI (tasks 2-4).