Task Management (Stack)
Manages a LIFO task stack with push, push_next, push_last, pop, promote, reorder, remove, soft-delete, and description editing operations. Data is persisted to the user's home directory.
Requirements
- The system MUST persist active tasks and soft-deleted tasks to a file in the user's home directory.
- The system MUST use atomic writes to prevent data corruption.
- The system MUST store each task with the following fields:
text,created_at,description,events, and optionallydeleted_at. - Each task MUST have an
eventslist of session records. Each event has astarted_attimestamp (set when the task becomes active/position 0) and an optionalended_attimestamp (set when the task leaves the active position). - When a task is moved to position 0, a new event MUST be appended to
eventswithstarted_atset to the current time andended_atleft null. - When a task leaves position 0, the latest event with a null
ended_atMUST have itsended_atset to the current time. - The
started_atproperty MUST be derived from the first event'sstarted_at. - The
last_currentproperty MUST be derived from the last event'sended_at(orstarted_atif the event is still open). - The
durationproperty MUST be computed as the sum ofended_at - started_atacross all closed events. - Active (non-deleted) tasks MUST be listed first in the file, followed by soft-deleted tasks appended at the end.
- The
pushoperation MUST insert a new task at position 0, setcreated_atto the current time, create a new event, and end the current stint of the previous top task. - The
push_nextoperation MUST insert a new task at position 1 (immediately after the current task) without making it current. If no tasks exist, it MUST behave likepush. - The
push_lastoperation MUST insert a new task at the bottom of the active list. If no tasks exist, it MUST mark the new task as current. - The
popoperation MUST remove the task at position 0, record itsdeleted_attimestamp, end its current stint, move it to the deleted history, and mark the new top task as current. - The
removeoperation MUST soft-delete the task at the given index, recordingdeleted_atand ending its stint if it was at position 0. If the removed task was at position 0, the new top task MUST be marked current. - The
promoteoperation MUST move the task at the given index to position 0 and mark it as current. - The
reorderoperation MUST move a task from one index to another, correctly managing stint transitions when tasks enter or leave position 0. - The
update_textoperation MUST update the text of the task at the given index in place. Empty or whitespace-only text MUST be rejected (no change applied). - The
update_descriptionoperation MUST update the description of the task at the given index in place. - The system MUST track cumulative active duration per task as the sum of all closed event durations.
- The
live_durationcomputation MUST return the closed-eventdurationplus the elapsed time since the last event'sstarted_atfor the task currently at position 0 (where the last event is still open). - The system MUST automatically migrate the legacy data file format to the current format on first load, preserving the original as a backup.
- The system SHOULD backfill events for legacy entries by synthesizing a single event from the stored
started_atandlast_currentfields. - The system MAY support
format_timestampwith adaptive precision (year, month, day, hour, minute) based on proximity to the current time. - The system MAY support
format_durationwith two-unit human-readable output (e.g.2h 05m,3d 04h).