Documentation
¶
Overview ¶
Package index provides index generation and parsing for context files.
Index ¶
- func GenerateTable(entries []Entry, columnHeader string) string
- func ReindexFile(w io.Writer, filePath, fileName string, updateFunc func(string) string, ...) error
- func Update(content, fileHeader, columnHeader string) string
- func UpdateDecisions(content string) string
- func UpdateLearnings(content string) string
- type Entry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateTable ¶
GenerateTable creates a Markdown table index from entries.
The table has two columns: Date and the specified column header. If there are no entries, returns an empty string.
Parameters:
- entries: Slice of entries to include
- columnHeader: Header for the second column (e.g., "Decision", "Learning")
Returns:
- string: Markdown table (without markers) or empty string
func ReindexFile ¶
func ReindexFile( w io.Writer, filePath, fileName string, updateFunc func(string) string, entryType string, ) error
ReindexFile reads a context file, regenerates its index, and writes it back.
This is a convenience function that handles the common reindex workflow: check the file exists, read content, apply update function, write back, report.
Note: This function uses io.Writer instead of *cobra.Command to keep the index package decoupled from CLI concerns. Callers pass cmd.OutOrStdout() which writes to the same destination as cmd.Printf.
Parameters:
- w: Writer for status output (typically cmd.OutOrStdout())
- filePath: Full path to the context file
- fileName: Display name for error messages (e.g., "DECISIONS.md")
- updateFunc: Function to regenerate the index (e.g., UpdateDecisions)
- entryType: Plural noun for the status message (e.g., "decisions")
Returns:
- error: Non-nil if file operations fail
func Update ¶
Update regenerates the index in file content.
If INDEX:START and INDEX:END markers exist, the content between them is replaced. Otherwise, the index is inserted after the specified header. If there are no entries, any existing index is removed.
Parameters:
- content: The full content of the file
- fileHeader: The main header to insert after (e.g., "# Decisions")
- columnHeader: Header for the table column (e.g., "Decision")
Returns:
- string: Updated content with regenerated index
func UpdateDecisions ¶
UpdateDecisions regenerates the decision index in DECISIONS.md content.
Parameters:
- content: The full content of DECISIONS.md
Returns:
- string: Updated content with regenerated index
func UpdateLearnings ¶
UpdateLearnings regenerates the learning index in LEARNINGS.md content.
Parameters:
- content: The full content of LEARNINGS.md
Returns:
- string: Updated content with regenerated index
Types ¶
type Entry ¶
Entry represents a parsed entry header from a context file.
Fields:
- Timestamp: Full timestamp (YYYY-MM-DD-HHMMSS)
- Date: Date only (YYYY-MM-DD)
- Title: Entry title
func ParseHeaders ¶
ParseHeaders extracts all entries from file content.
It scans for headers matching the pattern "## [YYYY-MM-DD-HHMMSS] Title" and returns them in the order they appear in the file.
Parameters:
- content: The full content of a context file
Returns:
- []Entry: Slice of parsed entries (it may be empty)