Documentation
¶
Overview ¶
Package compact implements the "ctx compact" command for cleaning up and consolidating context files.
The compact command performs maintenance on .context/ files including moving completed tasks to a dedicated section, optionally archiving old content, and removing empty sections.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cmd ¶
Cmd returns the "ctx compact" command for cleaning up context files.
The command moves completed tasks to a "Completed (Recent)" section, optionally archives old content, and removes empty sections from all context files.
Flags:
- --archive: Create .context/archive/ for old completed tasks
Returns:
- *cobra.Command: Configured compact command with flags registered
func RemoveBlocksFromLines ¶ added in v0.2.0
RemoveBlocksFromLines removes the specified blocks from the lines slice.
Blocks must be sorted by StartIndex in ascending order.
Parameters:
- lines: Original lines from the file
- blocks: Task blocks to remove (must be sorted by StartIndex)
Returns:
- []string: New lines with blocks removed
func WriteArchive ¶ added in v0.6.0
WriteArchive writes task content to a dated archive file in .context/archive/.
Creates the archive directory if needed. If a file for today already exists, the new content is appended. Otherwise a new file is created with a header.
Returns the path to the written archive file.
Types ¶
type TaskBlock ¶ added in v0.2.0
type TaskBlock struct {
Lines []string
StartIndex int
EndIndex int
IsCompleted bool
IsArchivable bool
DoneTime *time.Time
}
TaskBlock represents a task and its nested content.
Fields:
- Lines: All lines in the block (parent and children)
- StartIndex: Index of first line in original content
- EndIndex: Index of last line (exclusive)
- IsCompleted: The parent task is checked
- IsArchivable: Completed and no unchecked children
- DoneTime: When the task was marked done (from #done: timestamp), nil if not present
func ParseTaskBlocks ¶ added in v0.2.0
ParseTaskBlocks parses content into task blocks, identifying completed tasks with their nested content.
A task block consists of:
- A parent task line at the top level (no indentation, e.g., "- [x] Task title")
- All following lines that are more indented than the parent
Only top-level tasks (indent=0) are considered for archiving. Nested subtasks are part of their parent block and are not collected as independent blocks.
A block is archivable if: - The parent task is checked [x] - No nested lines contain unchecked tasks [ ]
Parameters:
- lines: Slice of lines from the tasks file
Returns:
- []TaskBlock: All completed top-level task blocks found (outside the Completed section)
func (*TaskBlock) BlockContent ¶ added in v0.2.0
BlockContent returns the full content of a block as a single string.
Returns:
- string: All lines joined with newlines
func (*TaskBlock) OlderThan ¶ added in v0.2.0
OlderThan checks if the task was completed more than the specified days ago.
Parameters:
- days: Number of days threshold
Returns:
- bool: True if DoneTime is set and older than days ago, false otherwise
func (*TaskBlock) ParentTaskText ¶ added in v0.2.0
ParentTaskText extracts just the task text from the parent line.
Returns:
- string: Task text without the checkbox prefix, empty if no lines