Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .cubil/done/deepen-the-task-document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
created: 2026-11-12
---

# Deepen the Task document

Create a Task document module that parses and renders the whole Task file: frontmatter, title and body.

## Problem
`new.rs` writes the title as the first H1, and `core/roadmap.rs` (read_task_title) reads it back. `assemble` and `read_body` exist in both `commands/new.rs` and `commands/roadmap/new.rs`. `list.rs` reparses frontmatter on its own.

## Scope
- Interface: TaskDoc::new(title, body, date), TaskDoc::parse(text), .title(), .meta(), .render().
- Absorb `core/frontmatter.rs`.
- Share one read_body helper between both new commands.

## Done when
- The H1 title rule lives in one module.
- Round-trip tests run through the interface.

Depends on: deepen-the-roadmap-module.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ src/
│ ├── root.rs Find the .cubil/ directory from any working directory
│ ├── slug.rs Slugify titles into kebab-case slugs
│ ├── store.rs Task store: find, list, create, move and remove tasks
│ ├── frontmatter.rs YAML frontmatter parse and assemble
│ ├── task_doc.rs Task document: frontmatter, H1 title, body
│ ├── roadmap.rs Roadmap line grammar: task lines, headings, milestones
│ ├── updater.rs Self-update: target detection, download, atomic replace
│ └── error.rs CubilError and its Display
Expand Down
7 changes: 4 additions & 3 deletions src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::cmp::Ordering;
use std::fmt::Write as _;

use crate::core::error::{CubilError, Result};
use crate::core::frontmatter::parse_frontmatter;
use crate::core::store::{TaskEntry, TaskStore};
use crate::core::task_doc::TaskDoc;

const DONE: &str = "done";

Expand Down Expand Up @@ -47,12 +47,13 @@ fn collect_rows(store: &TaskStore, all: bool, status: Option<&str>) -> Result<Ve
continue;
}
let src = std::fs::read_to_string(&path)?;
let (meta, _body) = parse_frontmatter(&src);
let doc = TaskDoc::parse(&src);
let meta = doc.meta();
rows.push(Row {
slug,
status: entry_status,
priority: meta.priority,
created: meta.created,
created: meta.created.clone(),
});
}
rows.sort_by(|a, b| {
Expand Down
75 changes: 2 additions & 73 deletions src/commands/new.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::io::Read;
use std::path::Path;

use crate::core::error::{CubilError, Result};
use crate::core::frontmatter::{TaskMeta, render_frontmatter};
use crate::core::slug::slugify;
use crate::core::store::TaskStore;
use crate::core::task_doc::{TaskDoc, read_body};

/// Create a new task file under `.cubil/backlog/`.
///
Expand All @@ -25,51 +24,14 @@ pub fn run(title: &str, message: Option<String>, file: Option<&Path>) -> Result<

let body = read_body(message, file)?;

let meta = TaskMeta {
created: Some(today_iso()),
priority: None,
extra: Vec::new(),
};

let contents = assemble(&meta, title, &body);
let contents = TaskDoc::new(title, &body, &today_iso()).render();

store.create(&slug, &contents)?;

println!("{slug}");
Ok(())
}

fn read_body(message: Option<String>, file: Option<&Path>) -> Result<String> {
if let Some(m) = message {
return Ok(m);
}
let Some(path) = file else {
return Ok(String::new());
};
if path.as_os_str() == "-" {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf)?;
return Ok(buf);
}
Ok(std::fs::read_to_string(path)?)
}

fn assemble(meta: &TaskMeta, title: &str, body: &str) -> String {
let mut out = render_frontmatter(meta);
out.push('\n');
out.push_str("# ");
out.push_str(title);
out.push('\n');
if !body.is_empty() {
out.push('\n');
out.push_str(body);
if !body.ends_with('\n') {
out.push('\n');
}
}
out
}

/// Today's date in ISO 8601 (`YYYY-MM-DD`), in the **user's local timezone**.
///
/// A personal task tool should agree with the user's wall clock — writing
Expand Down Expand Up @@ -98,37 +60,4 @@ mod tests {
assert!(s[5..7].chars().all(|c| c.is_ascii_digit()));
assert!(s[8..10].chars().all(|c| c.is_ascii_digit()));
}

#[test]
fn assemble_empty_body_has_no_trailing_blank_line() {
let meta = TaskMeta {
created: Some("2026-04-19".into()),
priority: None,
extra: Vec::new(),
};
let out = assemble(&meta, "Hello World", "");
assert_eq!(out, "---\ncreated: 2026-04-19\n---\n\n# Hello World\n");
}

#[test]
fn assemble_with_body_adds_trailing_newline_when_missing() {
let meta = TaskMeta {
created: Some("2026-04-19".into()),
priority: None,
extra: Vec::new(),
};
let out = assemble(&meta, "T", "line");
assert_eq!(out, "---\ncreated: 2026-04-19\n---\n\n# T\n\nline\n");
}

#[test]
fn assemble_preserves_body_trailing_newlines() {
let meta = TaskMeta {
created: Some("2026-04-19".into()),
priority: None,
extra: Vec::new(),
};
let out = assemble(&meta, "T", "line\n\n");
assert_eq!(out, "---\ncreated: 2026-04-19\n---\n\n# T\n\nline\n\n");
}
}
57 changes: 2 additions & 55 deletions src/commands/roadmap/new.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::io::Read;
use std::path::Path;

use crate::core::error::{CubilError, Result};
use crate::core::roadmap::{ensure_roadmaps_dir, roadmap_path};
use crate::core::root::find_root;
use crate::core::slug::slugify;
use crate::core::task_doc::{read_body, titled_body};

/// Create a new roadmap file under `.cubil/roadmaps/`.
///
Expand All @@ -23,62 +23,9 @@ pub fn run(title: &str, message: Option<String>, file: Option<&Path>) -> Result<
}

let body = read_body(message, file)?;
let contents = assemble(title, &body);
let contents = titled_body(title, &body);
std::fs::write(&path, contents)?;

println!("{slug}");
Ok(())
}

fn read_body(message: Option<String>, file: Option<&Path>) -> Result<String> {
if let Some(m) = message {
return Ok(m);
}
let Some(path) = file else {
return Ok(String::new());
};
if path.as_os_str() == "-" {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf)?;
return Ok(buf);
}
Ok(std::fs::read_to_string(path)?)
}

fn assemble(title: &str, body: &str) -> String {
let mut out = String::new();
out.push_str("# ");
out.push_str(title);
out.push('\n');
if !body.is_empty() {
out.push('\n');
out.push_str(body);
if !body.ends_with('\n') {
out.push('\n');
}
}
out
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn assemble_empty_body() {
assert_eq!(assemble("Migrate", ""), "# Migrate\n");
}

#[test]
fn assemble_with_body_adds_blank_line_and_trailing_newline() {
assert_eq!(
assemble("Migrate", "Narrative."),
"# Migrate\n\nNarrative.\n"
);
}

#[test]
fn assemble_preserves_body_trailing_newlines() {
assert_eq!(assemble("Migrate", "line\n\n"), "# Migrate\n\nline\n\n");
}
}
Loading
Loading