add

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package add provides the "ctx add" command for appending entries to context files.

It supports adding decisions, tasks, learnings, and conventions to their respective files in the .context/ directory. Content can be provided via command argument, --file flag, or stdin pipe.

Supported entry types (defined in config.FileType):

  • decision/decisions: Appends to DECISIONS.md
  • task/tasks: Inserts into TASKS.md under a section header
  • learning/learnings: Appends to LEARNINGS.md
  • convention/conventions: Appends to CONVENTIONS.md

Example usage:

ctx add decision "Use PostgreSQL for primary database"
ctx add task "Implement auth" --priority high --section "Next Up"
ctx add learning --file notes.md
echo "Use camelCase" | ctx add convention

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendEntry

func AppendEntry(
	existing []byte, entry string, fileType string, section string,
) []byte

AppendEntry inserts a formatted entry into existing file content.

For task entries, the function locates the target section header and inserts the entry immediately after it. For all other entry types, the entry is appended to the end of the file with appropriate newline handling.

Parameters:

  • existing: Current file content as bytes
  • entry: Pre-formatted entry text to insert
  • fileType: Entry type (e.g., "task", "decision", "learning", "convention")
  • section: Target section header for tasks; defaults to "## Next Up" if empty; a "## " prefix is added automatically if missing

Returns:

  • []byte: Modified file content with the entry inserted

func Cmd

func Cmd() *cobra.Command

Cmd returns the "ctx add" command for appending entries to context files.

Supported types are defined in config.FileType (both singular and plural forms accepted, e.g., "decision" or "decisions"). Content can be provided via command argument, --file flag, or stdin pipe.

Flags:

  • --priority, -p: Priority level for tasks (high, medium, low)
  • --section, -s: Target section within the file
  • --file, -f: Read content from a file instead of argument

Returns:

  • *cobra.Command: Configured add command with flags registered

func FormatConvention

func FormatConvention(content string) string

FormatConvention formats a convention entry as a simple markdown list item.

Format: "- content"

Parameters:

  • content: Convention description text

Returns:

  • string: Formatted convention line with trailing newline

func FormatDecision

func FormatDecision(content string) string

FormatDecision formats a decision entry as a structured Markdown section.

The output includes a timestamped heading, status, and placeholder sections for context, rationale, and consequences of the ADR format.

Parameters:

  • content: Decision title/summary text

Returns:

  • string: Formatted decision section with placeholders for details

func FormatLearning

func FormatLearning(content string) string

FormatLearning formats a learning entry as a timestamped markdown list item.

Format: "- **[YYYY-MM-DD-HHMMSS]** content"

Parameters:

  • content: Learning description text

Returns:

  • string: Formatted learning line with trailing newline

func FormatTask

func FormatTask(content string, priority string) string

FormatTask formats a task entry as a markdown checkbox item.

The output includes a timestamp tag for session correlation and an optional priority tag. Format: "- [ ] content #priority:level #added:YYYY-MM-DD-HHMMSS"

Parameters:

  • content: Task description text
  • priority: Priority level (high, medium, low); empty string omits the tag

Returns:

  • string: Formatted task line with trailing newline

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL