Documentation
¶
Index ¶
- func AllRulePaths(baseDir, homeDir string) []string
- func AllTaskSearchPaths(baseDir, homeDir string) []string
- func DownloadedRulePaths(dir string) []string
- func DownloadedTaskSearchPaths(dir string) []string
- func ParseMarkdownFile(path string, frontmatter any) (string, error)
- type Agent
- type Context
- type FrontMatter
- type Markdown
- type Option
- func WithAgent(agent TargetAgent) Option
- func WithEmitTaskFrontmatter(emit bool) Option
- func WithLogger(logger *slog.Logger) Option
- func WithParams(params Params) Option
- func WithRemotePaths(paths []string) Option
- func WithResume(resume bool) Option
- func WithSelectors(selectors Selectors) Option
- func WithWorkDir(dir string) Option
- type Params
- type Result
- type Selectors
- type TargetAgent
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllRulePaths ¶
AllRulePaths returns the standard search paths for rule files baseDir is the working directory to resolve relative paths from
func AllTaskSearchPaths ¶
AllTaskSearchPaths returns the standard search paths for task files baseDir is the working directory to resolve relative paths from
func DownloadedRulePaths ¶
DownloadedRulePaths returns the search paths for rule files in downloaded directories
func DownloadedTaskSearchPaths ¶
DownloadedTaskSearchPaths returns the search paths for task files in downloaded directories
func ParseMarkdownFile ¶
ParseMarkdownFile parses a markdown file into frontmatter and content
Example ¶
ExampleParseMarkdownFile demonstrates how to parse a markdown file with frontmatter into a custom struct.
package main
import (
"fmt"
"log"
"github.com/kitproj/coding-context-cli/pkg/codingcontext"
)
func main() {
// Define your custom struct with yaml tags
type TaskFrontmatter struct {
TaskName string `yaml:"task_name"`
Resume bool `yaml:"resume"`
Priority string `yaml:"priority"`
Tags []string `yaml:"tags"`
}
// Parse the markdown file
var frontmatter TaskFrontmatter
content, err := codingcontext.ParseMarkdownFile("path/to/task.md", &frontmatter)
if err != nil {
log.Fatal(err)
}
// Access the parsed frontmatter
fmt.Printf("Task: %s\n", frontmatter.TaskName)
fmt.Printf("Resume: %v\n", frontmatter.Resume)
fmt.Printf("Priority: %s\n", frontmatter.Priority)
fmt.Printf("Tags: %v\n", frontmatter.Tags)
// Access the content
fmt.Printf("Content length: %d\n", len(content))
}
Types ¶
type Agent ¶ added in v0.0.17
type Agent string
Agent represents an AI coding agent
const ( AgentCursor Agent = "cursor" AgentOpenCode Agent = "opencode" AgentCopilot Agent = "copilot" AgentClaude Agent = "claude" AgentGemini Agent = "gemini" AgentAugment Agent = "augment" AgentWindsurf Agent = "windsurf" AgentCodex Agent = "codex" )
Supported agents
func ParseAgent ¶ added in v0.0.17
ParseAgent parses a string into an Agent type
func (Agent) MatchesPath ¶ added in v0.0.17
MatchesPath returns true if the given path matches any of the agent's patterns
func (Agent) PathPatterns ¶ added in v0.0.17
PathPatterns returns the path patterns associated with this agent
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds the configuration and state for assembling coding context
type FrontMatter ¶
FrontMatter represents parsed YAML frontmatter from markdown files
type Markdown ¶
type Markdown struct {
Path string // Path to the markdown file
FrontMatter FrontMatter // Parsed YAML frontmatter
Content string // Expanded content of the markdown
Tokens int // Estimated token count
}
Markdown represents a markdown file with frontmatter and content
func (*Markdown) BootstrapPath ¶
BootstrapPath returns the path to the bootstrap script for this markdown file, if it exists. Returns empty string if the path is empty.
func (*Markdown) ParseFrontmatter ¶ added in v0.0.17
ParseFrontmatter unmarshals the frontmatter into the provided struct. The target parameter should be a pointer to a struct with yaml tags. Returns an error if the frontmatter cannot be unmarshaled into the target.
Example:
type TaskMeta struct {
TaskName string `yaml:"task_name"`
Resume bool `yaml:"resume"`
Priority string `yaml:"priority"`
}
var meta TaskMeta
if err := markdown.ParseFrontmatter(&meta); err != nil {
// handle error
}
Example ¶
ExampleMarkdown_ParseFrontmatter demonstrates how to parse task frontmatter into a custom struct when using the coding-context library.
package main
import (
"context"
"fmt"
"log"
"github.com/kitproj/coding-context-cli/pkg/codingcontext"
)
// TaskMetadata represents the custom frontmatter structure for a task
type TaskMetadata struct {
TaskName string `yaml:"task_name"`
Resume bool `yaml:"resume"`
Priority string `yaml:"priority"`
Environment string `yaml:"environment"`
Selectors map[string]any `yaml:"selectors"`
}
func main() {
// Create a context and run it to get a result
// In a real application, you would configure this properly
cc := codingcontext.New(
codingcontext.WithWorkDir("."),
)
// Assuming there's a task file with frontmatter like:
// ---
// task_name: deploy
// priority: high
// environment: production
// ---
result, err := cc.Run(context.Background(), "deploy")
if err != nil {
log.Fatal(err)
}
// Parse the task frontmatter into your custom struct
var taskMeta TaskMetadata
if err := result.Task.ParseFrontmatter(&taskMeta); err != nil {
log.Fatal(err)
}
// Now you can use the strongly-typed task metadata
fmt.Printf("Task: %s\n", taskMeta.TaskName)
fmt.Printf("Priority: %s\n", taskMeta.Priority)
fmt.Printf("Environment: %s\n", taskMeta.Environment)
// You can also parse rule frontmatter the same way
for _, rule := range result.Rules {
var ruleMeta struct {
Language string `yaml:"language"`
Stage string `yaml:"stage"`
}
if err := rule.ParseFrontmatter(&ruleMeta); err == nil {
fmt.Printf("Rule: language=%s, stage=%s\n", ruleMeta.Language, ruleMeta.Stage)
}
}
}
type Option ¶
type Option func(*Context)
Option is a functional option for configuring a Context
func WithAgent ¶ added in v0.0.17
func WithAgent(agent TargetAgent) Option
WithAgent sets the target agent (which excludes other agents' rules)
func WithEmitTaskFrontmatter ¶
WithEmitTaskFrontmatter enables task frontmatter emission
func WithRemotePaths ¶
WithRemotePaths sets the remote paths
func WithSelectors ¶
WithSelectors sets the selectors
type Params ¶
Params is a map of parameter key-value pairs for template substitution
type Result ¶
type Result struct {
Rules []Markdown // List of included rule files
Task Markdown // Task file with frontmatter and content
}
Result holds the assembled context from running a task
type Selectors ¶
Selectors stores selector key-value pairs where values are stored in inner maps Multiple values for the same key use OR logic (match any value in the inner map) Each value can be represented exactly once per key
func (*Selectors) GetValue ¶
GetValue returns true if the given value exists in the inner map for the given key. Returns false if the key doesn't exist or the value is not present.
func (*Selectors) MatchesIncludes ¶
func (includes *Selectors) MatchesIncludes(frontmatter FrontMatter) bool
MatchesIncludes returns true if the frontmatter matches all include selectors If a key doesn't exist in frontmatter, it's allowed Multiple values for the same key use OR logic (matches if frontmatter value is in the inner map)
type TargetAgent ¶ added in v0.0.17
type TargetAgent string
TargetAgent represents the agent being used, which excludes that agent's own rules Empty string means no agent specified
func (TargetAgent) IsSet ¶ added in v0.0.17
func (t TargetAgent) IsSet() bool
IsSet returns true if a target agent has been specified
func (*TargetAgent) Set ¶ added in v0.0.17
func (t *TargetAgent) Set(value string) error
Set implements the flag.Value interface for TargetAgent
func (TargetAgent) ShouldExcludePath ¶ added in v0.0.17
func (t TargetAgent) ShouldExcludePath(path string) bool
ShouldExcludePath returns true if the given path should be excluded based on target agent
func (TargetAgent) String ¶ added in v0.0.17
func (t TargetAgent) String() string
String implements the fmt.Stringer interface for TargetAgent