index

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package index provides index generation and parsing for context files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTable

func GenerateTable(entries []Entry, columnHeader string) string

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

func Update(content, fileHeader, columnHeader string) string

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

func UpdateDecisions(content string) string

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

func UpdateLearnings(content string) string

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

type Entry struct {
	Timestamp string
	Date      string
	Title     string
}

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

func ParseHeaders(content string) []Entry

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)

Jump to

Keyboard shortcuts

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