Documentation
¶
Overview ¶
Package codingcontext provides context assembly for AI coding agents.
Index ¶
- Variables
- type Agent
- type Context
- type DiscoveredTask
- type LintError
- type LintErrorKind
- type LintResult
- type LoadedFile
- type LoadedFileKind
- type Option
- func WithAgent(agent Agent) Option
- func WithBootstrap(doBootstrap bool) Option
- func WithLint(lint bool) Option
- func WithLogger(logger *slog.Logger) Option
- func WithManifestURL(manifestURL string) Option
- func WithParams(params taskparser.Params) Option
- func WithResume(resume bool) Option
- func WithSearchPaths(paths ...string) Option
- func WithSelectors(selectors selectors.Selectors) Option
- func WithUserPrompt(userPrompt string) Option
- type Result
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTaskNotFound is returned when the requested task file cannot be found. ErrTaskNotFound = errors.New("task not found") // ErrCommandNotFound is returned when a referenced command file cannot be found. ErrCommandNotFound = errors.New("command not found") // ErrSkillMissingName is returned when a skill's frontmatter lacks the required name field. ErrSkillMissingName = errors.New("skill missing required 'name' field") // ErrSkillNameLength is returned when a skill's name exceeds the maximum length. ErrSkillNameLength = errors.New("skill 'name' field must be 1-64 characters") // ErrSkillMissingDesc is returned when a skill's frontmatter lacks the required description field. ErrSkillMissingDesc = errors.New("skill missing required 'description' field") // ErrSkillDescriptionLength is returned when a skill's description exceeds the maximum length. ErrSkillDescriptionLength = errors.New("skill 'description' field must be 1-1024 characters") // ErrInvalidTaskNameNamespace is returned when the task name has an empty namespace. ErrInvalidTaskNameNamespace = errors.New("namespace must not be empty") // ErrInvalidTaskNameBase is returned when the task name has an empty base name. ErrInvalidTaskNameBase = errors.New("task base name must not be empty") // ErrInvalidTaskNameDepth is returned when the task name has more than one level of namespacing. ErrInvalidTaskNameDepth = errors.New("only one level of namespacing is supported (expected \"namespace/task\")") )
var ErrUnknownAgent = errors.New("unknown agent")
ErrUnknownAgent is returned when parsing an unknown or unsupported agent name.
Functions ¶
This section is empty.
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) IsSet ¶ added in v0.0.18
IsSet returns true if an agent has been specified (non-empty).
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.
func (*Agent) ShouldExcludePath ¶ added in v0.0.18
ShouldExcludePath returns true if the given path should be excluded based on this agent Empty agent means no exclusion.
func (*Agent) UserRulePath ¶ added in v0.0.24
UserRulePath returns the primary user-level rules path for this agent relative to home directory. Returns an empty string if the agent is not set. The path is relative and should be joined with the home directory.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds the configuration and state for assembling coding context.
func (*Context) Lint ¶ added in v0.0.38
Lint runs context assembly in dry-run mode and returns validation results. It skips bootstrap script execution and shell command expansion (!`cmd`), but otherwise performs the same file loading, parsing, and selector matching as Run(). Fatal errors (e.g. task not found) are returned as errors; structural problems are collected in LintResult.Errors.
func (*Context) ListTasks ¶ added in v0.0.38
func (cc *Context) ListTasks(ctx context.Context) ([]DiscoveredTask, error)
ListTasks enumerates all available tasks from the configured search paths without running any of them. It resolves remote directories (same as Run) and scans both global (.agents/tasks/) and namespace-specific (.agents/namespaces/<ns>/tasks/) task directories.
If the same task name appears in multiple search paths the first occurrence wins (consistent with how Run/Lint resolve tasks).
type DiscoveredTask ¶ added in v0.0.38
type DiscoveredTask struct {
// Name is the task name as passed to Lint or Run (e.g. "my-task" or "myteam/my-task").
Name string
// Path is the absolute path to the task markdown file.
Path string
// Namespace is the namespace prefix; empty for global tasks.
Namespace string
}
DiscoveredTask represents a task found during enumeration of search paths.
type LintError ¶ added in v0.0.38
type LintError struct {
Path string // May be empty
Kind LintErrorKind
Message string
Line int // 1-indexed; 0 means unknown (only set for parse errors)
Column int // 1-indexed; 0 means unknown (only set for parse errors)
}
LintError records a non-fatal structural problem found during linting.
type LintErrorKind ¶ added in v0.0.38
type LintErrorKind string
LintErrorKind identifies the category of a structural problem.
const ( LintErrorKindParse LintErrorKind = "parse" LintErrorKindMissingCommand LintErrorKind = "missing-command" LintErrorKindSkillValidation LintErrorKind = "skill-validation" LintErrorKindSelectorNoMatch LintErrorKind = "selector-no-match" )
Valid LintErrorKind values.
type LintResult ¶ added in v0.0.38
type LintResult struct {
*Result
LoadedFiles []LoadedFile
Errors []LintError
}
LintResult is returned by Lint(). It embeds the assembled Result plus tracking data collected during the dry run.
type LoadedFile ¶ added in v0.0.38
type LoadedFile struct {
Path string
Kind LoadedFileKind
}
LoadedFile records a file accessed during context assembly.
type LoadedFileKind ¶ added in v0.0.38
type LoadedFileKind string
LoadedFileKind identifies the role of a file loaded during context assembly.
const ( LoadedFileKindTask LoadedFileKind = "task" LoadedFileKindRule LoadedFileKind = "rule" LoadedFileKindCommand LoadedFileKind = "command" LoadedFileKindSkill LoadedFileKind = "skill" LoadedFileKindPathRef LoadedFileKind = "path-ref" LoadedFileKindBootstrap LoadedFileKind = "bootstrap" )
Valid LoadedFileKind values.
type Option ¶
type Option func(*Context)
Option is a functional option for configuring a Context.
func WithAgent ¶ added in v0.0.17
WithAgent sets the target agent, which excludes that agent's own rules.
func WithBootstrap ¶ added in v0.0.36
WithBootstrap controls whether to discover rules, skills, and run bootstrap scripts. When set to false, rule discovery, skill discovery, and bootstrap script execution are skipped.
func WithLint ¶ added in v0.0.38
WithLint enables lint mode: skips bootstrap script execution and shell command expansion (!`cmd`). File access is tracked and non-fatal structural errors are collected in LintResult. Use Lint() instead of Run() to retrieve results.
func WithManifestURL ¶ added in v0.0.20
WithManifestURL sets the manifest URL.
func WithResume ¶
WithResume sets the resume selector to "true", which can be used to filter tasks by their frontmatter resume field. This does not affect rule/skill discovery or bootstrap scripts.
func WithSearchPaths ¶ added in v0.0.20
WithSearchPaths adds one or more search paths.
func WithSelectors ¶
WithSelectors sets the selectors.
func WithUserPrompt ¶ added in v0.0.24
WithUserPrompt sets the user prompt to append to the task.
type Result ¶
type Result struct {
Name string // Name of the task
Namespace string // Active namespace (e.g. "myteam" from "myteam/fix-bug"), empty if none
Rules []markdown.Markdown[markdown.RuleFrontMatter] // List of included rule files
Task markdown.Markdown[markdown.TaskFrontMatter] // Task file with frontmatter and content
Skills skills.AvailableSkills // List of discovered skills (metadata only)
Tokens int // Total token count
Agent Agent // The agent used (from task or -a flag)
Prompt string // Combined prompt: all rules and task content
}
Result holds the assembled context from running a task.
func (*Result) MCPServers ¶ added in v0.0.18
func (r *Result) MCPServers() map[string]mcp.MCPServerConfig
MCPServers returns all MCP server configurations from rules as a map. Each rule can specify one MCP server configuration. Returns a map from rule ID to MCP server configuration. Empty/zero-value MCP server configurations are filtered out. The rule ID is automatically set to the filename (without extension) if not explicitly provided in the frontmatter.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package markdown provides parsing and structs for markdown frontmatter.
|
Package markdown provides parsing and structs for markdown frontmatter. |
|
Package mcp provides types for MCP (Model Context Protocol) server configuration.
|
Package mcp provides types for MCP (Model Context Protocol) server configuration. |
|
Package selectors provides selector parsing and matching for rule/skill frontmatter.
|
Package selectors provides selector parsing and matching for rule/skill frontmatter. |
|
Package skills provides types and serialization for agent skills.
|
Package skills provides types and serialization for agent skills. |
|
Package taskparser provides parsing and expansion for task content and parameters.
|
Package taskparser provides parsing and expansion for task content and parameters. |
|
Package tokencount provides token estimation for LLM text.
|
Package tokencount provides token estimation for LLM text. |