Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/codingcontext/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var agentPathPatterns = map[Agent][]string{
func (a *Agent) Set(value string) error {
agent, err := ParseAgent(value)
if err != nil {
return err
return fmt.Errorf("failed to set agent value %q: %w", value, err)
}

*a = agent
Expand Down
16 changes: 8 additions & 8 deletions pkg/codingcontext/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (cc *Context) visitMarkdownFiles(searchDirFn func(path string) []string, vi
if _, err := os.Stat(dir); os.IsNotExist(err) {
continue
} else if err != nil {
return err
return fmt.Errorf("failed to stat directory %s: %w", dir, err)
}

err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
return fmt.Errorf("failed to walk path %s: %w", path, err)
}
ext := filepath.Ext(path) // .md or .mdc
if info.IsDir() || ext != ".md" && ext != ".mdc" {
Expand All @@ -94,7 +94,7 @@ func (cc *Context) visitMarkdownFiles(searchDirFn func(path string) []string, vi
return visitor(path)
})
if err != nil {
return err
return fmt.Errorf("failed to walk directory %s: %w", dir, err)
}
}

Expand All @@ -118,7 +118,7 @@ func (cc *Context) findTask(taskName string) error {
var frontMatter markdown.TaskFrontMatter
md, err := markdown.ParseMarkdownFile(path, &frontMatter)
if err != nil {
return err
return fmt.Errorf("failed to parse task file %s: %w", path, err)
}

// Extract selector labels from task frontmatter and add them to cc.includes.
Expand All @@ -132,7 +132,7 @@ func (cc *Context) findTask(taskName string) error {
if frontMatter.Agent != "" {
agent, err := ParseAgent(frontMatter.Agent)
if err != nil {
return err
return fmt.Errorf("failed to parse agent from task frontmatter: %w", err)
}
cc.agent = agent
}
Expand All @@ -152,7 +152,7 @@ func (cc *Context) findTask(taskName string) error {
// Parse the task content (including user_prompt) to separate text blocks from slash commands
task, err := taskparser.ParseTask(taskContent)
if err != nil {
return err
return fmt.Errorf("failed to parse task content: %w", err)
}

// Build the final content by processing each block
Expand All @@ -174,7 +174,7 @@ func (cc *Context) findTask(taskName string) error {
} else if block.SlashCommand != nil {
commandContent, err := cc.findCommand(block.SlashCommand.Name, block.SlashCommand.Params())
if err != nil {
return err
return fmt.Errorf("failed to find command %s: %w", block.SlashCommand.Name, err)
}
finalContent.WriteString(commandContent)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (cc *Context) findCommand(commandName string, params taskparser.Params) (st
var frontMatter markdown.CommandFrontMatter
md, err := markdown.ParseMarkdownFile(path, &frontMatter)
if err != nil {
return err
return fmt.Errorf("failed to parse command file %s: %w", path, err)
}

// Extract selector labels from command frontmatter and add them to cc.includes.
Expand Down
13 changes: 7 additions & 6 deletions pkg/codingcontext/markdown/frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package markdown

import (
"encoding/json"
"fmt"

"github.com/kitproj/coding-context-cli/pkg/codingcontext/mcp"
)
Expand Down Expand Up @@ -57,12 +58,12 @@ func (t *TaskFrontMatter) UnmarshalJSON(data []byte) error {
}

if err := json.Unmarshal(data, aux); err != nil {
return err
return fmt.Errorf("failed to unmarshal task frontmatter: %w", err)
}

// Also unmarshal into Content map
if err := json.Unmarshal(data, &t.BaseFrontMatter.Content); err != nil {
return err
return fmt.Errorf("failed to unmarshal task frontmatter content: %w", err)
}

return nil
Expand Down Expand Up @@ -94,12 +95,12 @@ func (c *CommandFrontMatter) UnmarshalJSON(data []byte) error {
}

if err := json.Unmarshal(data, aux); err != nil {
return err
return fmt.Errorf("failed to unmarshal command frontmatter: %w", err)
}

// Also unmarshal into Content map
if err := json.Unmarshal(data, &c.BaseFrontMatter.Content); err != nil {
return err
return fmt.Errorf("failed to unmarshal command frontmatter content: %w", err)
}

return nil
Expand Down Expand Up @@ -143,12 +144,12 @@ func (r *RuleFrontMatter) UnmarshalJSON(data []byte) error {
}

if err := json.Unmarshal(data, aux); err != nil {
return err
return fmt.Errorf("failed to unmarshal rule frontmatter: %w", err)
}

// Also unmarshal into Content map
if err := json.Unmarshal(data, &r.BaseFrontMatter.Content); err != nil {
return err
return fmt.Errorf("failed to unmarshal rule frontmatter content: %w", err)
}

return nil
Expand Down
9 changes: 6 additions & 3 deletions pkg/codingcontext/mcp/mcp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package mcp

import "encoding/json"
import (
"encoding/json"
"fmt"
)

// TransportType defines the communication protocol used by the server.
// Supported by both Claude and Cursor.
Expand Down Expand Up @@ -58,7 +61,7 @@ func (m *MCPServerConfig) UnmarshalJSON(data []byte) error {
}

if err := json.Unmarshal(data, aux); err != nil {
return err
return fmt.Errorf("failed to unmarshal MCP server config: %w", err)
}

// Initialize Content map if needed
Expand All @@ -68,7 +71,7 @@ func (m *MCPServerConfig) UnmarshalJSON(data []byte) error {

// Also unmarshal into Content map
if err := json.Unmarshal(data, &m.Content); err != nil {
return err
return fmt.Errorf("failed to unmarshal MCP server config content: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/codingcontext/taskparser/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (p Params) Set(value string) error {

params, err := ParseParams(quotedValue)
if err != nil {
return err
return fmt.Errorf("failed to parse parameter '%s': %w", value, err)
}

maps.Copy(p, params)
Expand Down