@@ -27,7 +27,7 @@ import (
2727func main () {
2828 // Create a new context with options
2929 ctx := codingcontext.New (
30- codingcontext.WithWorkDir ( " . " ),
30+ codingcontext.WithSearchPaths ( " file://. " , " file:// " +os. Getenv ( " HOME " ) ),
3131 codingcontext.WithParams (codingcontext.Params {
3232 " issue_number" : " 123" ,
3333 " feature" : " authentication" ,
@@ -73,15 +73,18 @@ func main() {
7373
7474 // Create context with all options
7575 ctx := codingcontext.New (
76- codingcontext.WithWorkDir (" ." ),
76+ codingcontext.WithSearchPaths (
77+ " file://." ,
78+ " git::https://github.com/org/repo//path/to/rules" ,
79+ ),
7780 codingcontext.WithParams (codingcontext.Params {
7881 " issue_number" : " 123" ,
7982 }),
8083 codingcontext.WithSelectors (selectors),
81- codingcontext.WithRemotePaths ([] string {
82- " https://github.com/org/repo//path/to/rules " ,
83- } ),
84- codingcontext.WithEmitTaskFrontmatter ( true ),
84+ codingcontext.WithAgent (codingcontext. AgentCursor ),
85+ codingcontext. WithResume ( false ) ,
86+ codingcontext. WithUserPrompt ( " Additional context or instructions " ),
87+ codingcontext.WithManifestURL ( " https://example.com/manifest.txt " ),
8588 codingcontext.WithLogger (slog.New (slog.NewTextHandler (os.Stderr , nil ))),
8689 )
8790
@@ -95,10 +98,23 @@ func main() {
9598 // Process the result
9699 fmt.Printf (" Task: %s \n " , result.Task .Content )
97100 fmt.Printf (" Rules found: %d \n " , len (result.Rules ))
101+ fmt.Printf (" Total tokens: %d \n " , result.Tokens )
102+ fmt.Printf (" Agent: %s \n " , result.Agent )
103+
104+ // Access task metadata using typed fields
105+ if len (result.Task .FrontMatter .Languages ) > 0 {
106+ fmt.Printf (" Languages: %v \n " , result.Task .FrontMatter .Languages )
107+ }
98108
99- // Access task metadata
100- if taskName , ok := result.Task .FrontMatter [" task_name" ]; ok {
101- fmt.Printf (" Task name from frontmatter: %s \n " , taskName)
109+ // You can also access any frontmatter field via the Content map
110+ if customField , ok := result.Task .FrontMatter .Content [" custom_field" ]; ok {
111+ fmt.Printf (" Custom field: %v \n " , customField)
112+ }
113+
114+ // Access MCP server configurations
115+ mcpServers := result.MCPServers ()
116+ for name , config := range mcpServers {
117+ fmt.Printf (" MCP Server %s : %s \n " , name, config.Command )
102118 }
103119}
104120```
@@ -114,28 +130,151 @@ The main type for assembling context.
114130#### ` Result `
115131
116132Result holds the assembled context from running a task:
117- - ` Rules []Markdown ` - List of included rule files
118- - ` Task Markdown ` - Task file with frontmatter and content
133+ - ` Rules []Markdown[RuleFrontMatter] ` - List of included rule files
134+ - ` Task Markdown[TaskFrontMatter] ` - Task file with frontmatter and content
135+ - ` Tokens int ` - Total estimated token count
136+ - ` Agent Agent ` - The agent used (from task frontmatter or option)
137+
138+ ** Methods:**
139+ - ` MCPServers() MCPServerConfigs ` - Returns all MCP server configurations from rules and task
119140
120- #### ` Markdown `
141+ #### ` Markdown[T] `
121142
122- Represents a markdown file with frontmatter and content:
123- - ` Path string ` - Path to the markdown file
124- - ` FrontMatter FrontMatter ` - Parsed YAML frontmatter
143+ Represents a markdown file with frontmatter and content (generic type):
144+ - ` FrontMatter T ` - Parsed YAML frontmatter (type depends on usage)
125145- ` Content string ` - Expanded content of the markdown
126146- ` Tokens int ` - Estimated token count
127147
148+ Type aliases:
149+ - ` TaskMarkdown ` = ` Markdown[TaskFrontMatter] `
150+ - ` RuleMarkdown ` = ` Markdown[RuleFrontMatter] `
151+
152+ #### ` TaskFrontMatter `
153+
154+ Frontmatter structure for task files with fields:
155+ - ` Agent string ` - Default agent if not specified via option
156+ - ` Languages []string ` - Programming languages for filtering rules
157+ - ` Model string ` - AI model identifier (metadata only)
158+ - ` SingleShot bool ` - Whether task runs once or multiple times (metadata only)
159+ - ` Timeout string ` - Task timeout in time.Duration format (metadata only)
160+ - ` MCPServers MCPServerConfigs ` - MCP server configurations (metadata only)
161+ - ` Resume bool ` - Whether this task should be resumed
162+ - ` Selectors map[string]any ` - Additional custom selectors for filtering rules
163+ - ` ExpandParams *bool ` - Controls parameter expansion (defaults to true)
164+ - ` Content map[string]any ` - All frontmatter fields as map (from ` BaseFrontMatter ` )
165+
166+ #### ` RuleFrontMatter `
167+
168+ Frontmatter structure for rule files with fields:
169+ - ` TaskNames []string ` - Which task(s) this rule applies to
170+ - ` Languages []string ` - Which programming language(s) this rule applies to
171+ - ` Agent string ` - Which AI agent this rule is intended for
172+ - ` MCPServers MCPServerConfigs ` - MCP server configurations (metadata only)
173+ - ` RuleName string ` - Optional identifier for the rule file
174+ - ` ExpandParams *bool ` - Controls parameter expansion (defaults to true)
175+ - ` Content map[string]any ` - All frontmatter fields as map (from ` BaseFrontMatter ` )
176+
177+ #### ` CommandFrontMatter `
178+
179+ Frontmatter structure for command files with fields:
180+ - ` ExpandParams *bool ` - Controls parameter expansion (defaults to true)
181+ - ` Content map[string]any ` - All frontmatter fields as map (from ` BaseFrontMatter ` )
182+
183+ #### ` BaseFrontMatter `
184+
185+ Base frontmatter structure that other frontmatter types embed:
186+ - ` Content map[string]any ` - All frontmatter fields as a map for selector matching
187+
188+ #### ` Agent `
189+
190+ Type representing an AI coding agent (string type).
191+
192+ ** Constants:**
193+ - ` AgentCursor ` - Cursor AI (cursor.sh)
194+ - ` AgentOpenCode ` - OpenCode.ai agent
195+ - ` AgentCopilot ` - GitHub Copilot
196+ - ` AgentClaude ` - Anthropic Claude AI
197+ - ` AgentGemini ` - Google Gemini AI
198+ - ` AgentAugment ` - Augment Code assistant
199+ - ` AgentWindsurf ` - Codeium Windsurf
200+ - ` AgentCodex ` - Codex AI agent
201+
202+ ** Methods:**
203+ - ` String() string ` - Returns string representation
204+ - ` PathPatterns() []string ` - Returns path patterns for this agent
205+ - ` MatchesPath(path string) bool ` - Checks if path matches agent patterns
206+ - ` ShouldExcludePath(path string) bool ` - Returns true if path should be excluded
207+ - ` IsSet() bool ` - Returns true if agent is set (non-empty)
208+ - ` UserRulePath() string ` - Returns user-level rules path for agent
209+
210+ #### ` MCPServerConfig `
211+
212+ Configuration for MCP (Model Context Protocol) servers:
213+ - ` Type TransportType ` - Connection protocol ("stdio", "sse", "http")
214+ - ` Command string ` - Executable to run (for stdio type)
215+ - ` Args []string ` - Command arguments
216+ - ` Env map[string]string ` - Environment variables
217+ - ` URL string ` - Endpoint URL (for http/sse types)
218+ - ` Headers map[string]string ` - Custom HTTP headers
219+
220+ #### ` MCPServerConfigs `
221+
222+ Type alias: ` map[string]MCPServerConfig ` - Maps server names to configurations
223+
224+ #### ` TransportType `
225+
226+ Type representing MCP transport protocol (string type):
227+
228+ ** Constants:**
229+ - ` TransportTypeStdio ` - Local process communication
230+ - ` TransportTypeSSE ` - Server-Sent Events (remote)
231+ - ` TransportTypeHTTP ` - Standard HTTP/POST
232+
128233#### ` Params `
129234
130- Map of parameter key-value pairs for template substitution.
235+ Map of parameter key-value pairs for template substitution: ` map[string]string `
236+
237+ ** Methods:**
238+ - ` String() string ` - Returns string representation
239+ - ` Set(value string) error ` - Parses and sets key=value pair (implements flag.Value)
131240
132241#### ` Selectors `
133242
134- Map structure for filtering rules based on frontmatter metadata.
243+ Map structure for filtering rules based on frontmatter metadata: ` map[string]map[string]bool `
244+
245+ ** Methods:**
246+ - ` String() string ` - Returns string representation
247+ - ` Set(value string) error ` - Parses and sets key=value pair (implements flag.Value)
248+ - ` SetValue(key, value string) ` - Sets a value for a key
249+ - ` GetValue(key, value string) bool ` - Checks if value exists for key
250+ - ` MatchesIncludes(frontmatter BaseFrontMatter) bool ` - Tests if frontmatter matches selectors
251+
252+ #### Task Parser Types
253+
254+ Types for parsing task content with slash commands:
255+
256+ - ` Task ` - Slice of ` Block ` elements representing parsed task content
257+ - ` Block ` - Contains either ` Text ` or ` SlashCommand `
258+ - ` SlashCommand ` - Parsed slash command with name and arguments
259+ - ` Text ` - Text content (slice of ` TextLine ` )
260+ - ` TextLine ` - Single line of text content
261+ - ` Input ` - Top-level wrapper type for parsing
262+ - ` Argument ` - Slash command argument (can be positional or named key=value)
263+
264+ ** Methods:**
265+ - ` (*SlashCommand) Params() map[string]string ` - Returns parsed parameters as map
266+ - ` (*Text) Content() string ` - Returns text content as string
267+ - Various ` String() ` methods for formatting each type
135268
136- #### ` FrontMatter `
269+ ### Constants
137270
138- Map representing parsed YAML frontmatter from markdown files.
271+ #### ` FreeTextTaskName `
272+
273+ Constant: ` "free-text" ` - Task name used for free-text prompts
274+
275+ #### ` FreeTextParamName `
276+
277+ Constant: ` "text" ` - Parameter name for text content in free-text tasks
139278
140279### Functions
141280
@@ -144,28 +283,49 @@ Map representing parsed YAML frontmatter from markdown files.
144283Creates a new Context with the given options.
145284
146285** Options:**
147- - ` WithWorkDir(dir string) ` - Set the working directory
148- - ` WithParams(params Params) ` - Set parameters
149- - ` WithSelectors(selectors Selectors) ` - Set selectors for filtering
150- - ` WithRemotePaths(paths []string) ` - Set remote directories to download
151- - ` WithEmitTaskFrontmatter(emit bool) ` - Enable task frontmatter inclusion in result
286+ - ` WithSearchPaths(paths ...string) ` - Add search paths (supports go-getter URLs)
287+ - ` WithParams(params Params) ` - Set parameters for substitution
288+ - ` WithSelectors(selectors Selectors) ` - Set selectors for filtering rules
289+ - ` WithAgent(agent Agent) ` - Set target agent (excludes that agent's own rules)
290+ - ` WithResume(resume bool) ` - Enable resume mode (skips rules)
291+ - ` WithUserPrompt(userPrompt string) ` - Set user prompt to append to task
292+ - ` WithManifestURL(manifestURL string) ` - Set manifest URL for additional search paths
152293- ` WithLogger(logger *slog.Logger) ` - Set logger
153294
154295#### ` (*Context) Run(ctx context.Context, taskName string) (*Result, error) `
155296
156297Executes the context assembly for the given task name and returns the assembled result structure with rule and task markdown files (including frontmatter and content).
157298
158- #### ` ParseMarkdownFile(path string, frontmatter any) (string, error) `
299+ #### ` ParseMarkdownFile[T any](path string, frontmatter *T) (Markdown[T], error) `
300+
301+ Parses a markdown file into frontmatter and content. Generic function that works with any frontmatter type.
302+
303+ #### ` ParseTask(text string) (Task, error) `
159304
160- Parses a markdown file into frontmatter and content .
305+ Parses task text content into blocks of text and slash commands .
161306
162- #### ` AllTaskSearchPaths(baseDir, homeDir string) []string `
307+ #### ` ParseParams(s string) (Params, error) `
163308
164- Returns the standard search paths for task files. ` baseDir ` is the working directory to resolve relative paths from.
309+ Parses a string containing key=value pairs with quoted values.
310+
311+ ** Examples:**
312+ ``` go
313+ // Parse quoted key-value pairs
314+ params , _ := ParseParams (` key1="value1" key2="value2"` )
315+ // Result: map[string]string{"key1": "value1", "key2": "value2"}
316+
317+ // Parse with spaces in values
318+ params , _ := ParseParams (` key1="value with spaces" key2="value2"` )
319+ // Result: map[string]string{"key1": "value with spaces", "key2": "value2"}
320+
321+ // Parse with escaped quotes
322+ params , _ := ParseParams (` key1="value with \"escaped\" quotes"` )
323+ // Result: map[string]string{"key1": "value with \"escaped\" quotes"}
324+ ```
165325
166- #### ` AllRulePaths(baseDir, homeDir string) []string `
326+ #### ` ParseAgent(s string) (Agent, error) `
167327
168- Returns the standard search paths for rule files. ` baseDir ` is the working directory to resolve relative paths from .
328+ Parses a string into an Agent type. Returns error if agent is not supported .
169329
170330## See Also
171331
0 commit comments