From 8e9c8deec4988e61c8996b4126d83f8e414637cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Dec 2025 23:55:27 +0000 Subject: [PATCH 1/3] Initial plan From 711baa548bce8afc84ce52ddd66c3ab207730b62 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 00:01:31 +0000 Subject: [PATCH 2/3] Improve error handling with clear context and wrapped errors Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> --- pkg/codingcontext/agent.go | 2 +- pkg/codingcontext/context.go | 16 ++++++++-------- pkg/codingcontext/markdown/frontmatter.go | 13 +++++++------ pkg/codingcontext/mcp/mcp.go | 9 ++++++--- pkg/codingcontext/taskparser/params.go | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pkg/codingcontext/agent.go b/pkg/codingcontext/agent.go index 1e09d9c..1cc796f 100644 --- a/pkg/codingcontext/agent.go +++ b/pkg/codingcontext/agent.go @@ -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: %w", err) } *a = agent diff --git a/pkg/codingcontext/context.go b/pkg/codingcontext/context.go index 46286fb..90a9025 100644 --- a/pkg/codingcontext/context.go +++ b/pkg/codingcontext/context.go @@ -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("error walking path %s: %w", path, err) } ext := filepath.Ext(path) // .md or .mdc if info.IsDir() || ext != ".md" && ext != ".mdc" { @@ -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) } } @@ -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. @@ -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 } @@ -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 @@ -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) } @@ -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. diff --git a/pkg/codingcontext/markdown/frontmatter.go b/pkg/codingcontext/markdown/frontmatter.go index e3119f1..e9be92a 100644 --- a/pkg/codingcontext/markdown/frontmatter.go +++ b/pkg/codingcontext/markdown/frontmatter.go @@ -2,6 +2,7 @@ package markdown import ( "encoding/json" + "fmt" "github.com/kitproj/coding-context-cli/pkg/codingcontext/mcp" ) @@ -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 @@ -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 @@ -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 diff --git a/pkg/codingcontext/mcp/mcp.go b/pkg/codingcontext/mcp/mcp.go index b6b0624..456072f 100644 --- a/pkg/codingcontext/mcp/mcp.go +++ b/pkg/codingcontext/mcp/mcp.go @@ -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. @@ -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 @@ -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 diff --git a/pkg/codingcontext/taskparser/params.go b/pkg/codingcontext/taskparser/params.go index 8e50712..2f9ff2e 100644 --- a/pkg/codingcontext/taskparser/params.go +++ b/pkg/codingcontext/taskparser/params.go @@ -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) From d78cf0e5238322fed2db89241f96967d941ce27a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 00:13:56 +0000 Subject: [PATCH 3/3] Apply code review suggestions: improve error messages consistency and context Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> --- pkg/codingcontext/agent.go | 2 +- pkg/codingcontext/context.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/codingcontext/agent.go b/pkg/codingcontext/agent.go index 1cc796f..56da557 100644 --- a/pkg/codingcontext/agent.go +++ b/pkg/codingcontext/agent.go @@ -101,7 +101,7 @@ var agentPathPatterns = map[Agent][]string{ func (a *Agent) Set(value string) error { agent, err := ParseAgent(value) if err != nil { - return fmt.Errorf("failed to set agent value: %w", err) + return fmt.Errorf("failed to set agent value %q: %w", value, err) } *a = agent diff --git a/pkg/codingcontext/context.go b/pkg/codingcontext/context.go index 90a9025..dc38531 100644 --- a/pkg/codingcontext/context.go +++ b/pkg/codingcontext/context.go @@ -72,7 +72,7 @@ func (cc *Context) visitMarkdownFiles(searchDirFn func(path string) []string, vi err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err != nil { - return fmt.Errorf("error walking path %s: %w", path, 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" {