Documentation
¶
Overview ¶
Package index generates and parses indexes for context file entries.
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
- type EntryBlock
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: Entity noun for the status message (e.g., "decision")
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)
type EntryBlock ¶ added in v0.8.0
EntryBlock represents a parsed entry block from a knowledge file (DECISIONS.md or LEARNINGS.md).
Fields:
- Entry: The parsed header metadata (timestamp, date, title)
- Lines: All lines belonging to this entry (header + body)
- StartIndex: Zero-based line index where this entry starts
- EndIndex: Zero-based line index where this entry ends (exclusive)
func ParseEntryBlocks ¶ added in v0.8.0
func ParseEntryBlocks(content string) []EntryBlock
ParseEntryBlocks splits file content into discrete entry blocks.
Each block starts at a "## [YYYY-MM-DD-HHMMSS] Title" header and extends to the line before the next entry header or end of content.
Parameters:
- content: The full file content
Returns:
- []EntryBlock: Parsed entry blocks in file order (may be empty)
func (*EntryBlock) BlockContent ¶ added in v0.8.0
func (eb *EntryBlock) BlockContent() string
BlockContent joins the entry's lines into a single string.
Returns:
- string: The full entry content with lines joined by newlines
func (*EntryBlock) IsSuperseded ¶ added in v0.8.0
func (eb *EntryBlock) IsSuperseded() bool
IsSuperseded checks whether this entry has been marked as superseded.
An entry is superseded when its body contains a line starting with "~~Superseded" (strikethrough prefix).
Returns:
- bool: True if the entry contains a superseded marker