src/models/task.ts (Task)
Represents one canonical task markdown file.
Constructor
new Task(params)
Creates an in-memory task instance.
params fields:
id: numberslug: stringtitle: stringlabels: string[]created: stringupdated: stringdescription: stringcomments: TaskComment[]projectPath: stringstatus?: string
Static helpers
Task.idString(id: number): string
Returns 10-digit id string used in frontmatter (example: 1 -> 0000000001).
Task.idPad(id: number): string
Returns 5-digit id string used in filenames/group paths (example: 1 -> 00001).
Task.groupDir(id: number): string
Returns group directory name by bucket (Math.floor((id - 1) / MAX_FILES_PER_DIR), zero-padded to 5).
Task.buildCommentsSeparator(): string
Returns computed markdown separator between description/comments:
\n---\n\n${COMMENTS_HEADER}\n\n
Task.parseBody(content: string): { description: string; comments: TaskComment[] }
Parses markdown body (post-frontmatter) into normalized description + comments.
Task.parseComments(tableText: string): TaskComment[]
Parses comments markdown table rows into TaskComment[].
Task.read(filePath: string, projectPath: string, status?: string): Promise<Task>
Reads markdown file, parses frontmatter/body, and returns hydrated Task.
Instance properties/getters
filename: string (getter)
<idPad>-<slug>.md
filePath: string (getter)
Absolute path: <projectPath>/<ALL_TASKS_DIR>/<groupDir>/<filename>.
groupDirPath: string (getter)
Absolute group directory path for this task.
Instance methods
buildBody(): string
Builds markdown body (Description section + comments table).
buildFileContent(): string
Builds full file text via gray-matter.stringify (frontmatter + body).
write(): Promise<void>
Ensures group dir exists and writes file content.
create(): Promise<void>
First-write lifecycle:
- slug from title (
toSlug) - set
createdandupdated(makeRfc3339) - write file
addComment(comment: string): Promise<void>
Appends comment row, bumps updated, writes.
updateTitle(title: string): Promise<void>
Updates title, bumps updated, writes.
updateDescription(description: string): Promise<void>
Updates description, bumps updated, writes.
updateLabels(labels: string[]): Promise<void>
Replaces labels, bumps updated, writes.
deleteFile(): Promise<void>
Deletes canonical task file only (does not remove status symlinks).
toJSON(): object
Returns plain object for CLI JSON output.