diff --git a/go.mod b/go.mod index 86c9608..a273078 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.24.5 require ( github.com/alecthomas/participle/v2 v2.1.4 github.com/hashicorp/go-getter/v2 v2.2.3 - github.com/leodido/go-urn v1.4.0 github.com/stretchr/testify v1.10.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 2d28004..af935d2 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,6 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U= github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= -github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= diff --git a/pkg/codingcontext/context_test.go b/pkg/codingcontext/context_test.go index 449c108..245928a 100644 --- a/pkg/codingcontext/context_test.go +++ b/pkg/codingcontext/context_test.go @@ -384,23 +384,6 @@ func TestContext_Run_Basic(t *testing.T) { } }, }, - { - name: "task with explicit URN in frontmatter", - setup: func(t *testing.T, dir string) { - createTask(t, dir, "file-name", "id: urn:agents:task:file-name", "Task content") - }, - taskName: "file-name", - wantErr: false, - check: func(t *testing.T, result *Result) { - if result.Task.FrontMatter.URN == nil || result.Task.FrontMatter.URN.String() != "urn:agents:task:file-name" { - got := "" - if result.Task.FrontMatter.URN != nil { - got = result.Task.FrontMatter.URN.String() - } - t.Errorf("expected task URN 'urn:agents:task:file-name', got %q", got) - } - }, - }, } for _, tt := range tests { @@ -775,45 +758,6 @@ func TestContext_Run_Rules(t *testing.T) { } }, }, - { - name: "rule URN set from frontmatter", - setup: func(t *testing.T, dir string) { - createTask(t, dir, "id-task", "", "Task") - createRule(t, dir, ".agents/rules/my-rule.md", "id: urn:agents:rule:my-rule", "Rule with URN") - createRule(t, dir, ".agents/rules/another-rule.md", "id: urn:agents:rule:another", "Rule with another URN") - }, - taskName: "id-task", - wantErr: false, - check: func(t *testing.T, result *Result) { - if len(result.Rules) != 2 { - t.Fatalf("expected 2 rules, got %d", len(result.Rules)) - } - - foundMyRule := false - foundAnotherRule := false - for _, rule := range result.Rules { - if rule.FrontMatter.URN != nil && rule.FrontMatter.URN.String() == "urn:agents:rule:my-rule" { - foundMyRule = true - if !strings.Contains(rule.Content, "Rule with URN") { - t.Error("my-rule should contain 'Rule with URN'") - } - } - if rule.FrontMatter.URN != nil && rule.FrontMatter.URN.String() == "urn:agents:rule:another" { - foundAnotherRule = true - if !strings.Contains(rule.Content, "Rule with another URN") { - t.Error("another should contain 'Rule with another URN'") - } - } - } - - if !foundMyRule { - t.Error("expected to find rule with URN 'urn:agents:rule:my-rule'") - } - if !foundAnotherRule { - t.Error("expected to find rule with URN 'urn:agents:rule:another'") - } - }, - }, } for _, tt := range tests { diff --git a/pkg/codingcontext/markdown/frontmatter.go b/pkg/codingcontext/markdown/frontmatter.go index f151f2e..5fc760d 100644 --- a/pkg/codingcontext/markdown/frontmatter.go +++ b/pkg/codingcontext/markdown/frontmatter.go @@ -5,17 +5,11 @@ import ( "fmt" "github.com/kitproj/coding-context-cli/pkg/codingcontext/mcp" - "github.com/leodido/go-urn" "gopkg.in/yaml.v3" ) // BaseFrontMatter represents parsed YAML frontmatter from markdown files type BaseFrontMatter struct { - // URN is an optional unique identifier for the prompt in URN format (e.g. urn:agents:task:) - // Automatically inferred from filename if not specified in frontmatter - // In YAML frontmatter, "id" is accepted as an alias for "urn". - URN *urn.URN `yaml:"urn,omitempty" json:"urn,omitempty"` - // Name is the skill identifier // Must be 1-64 characters, lowercase alphanumeric and hyphens only Name string `yaml:"name,omitempty" json:"name,omitempty"` @@ -28,14 +22,12 @@ type BaseFrontMatter struct { } type baseFrontMatterRaw struct { - ID string `yaml:"id"` - URN *urn.URN `yaml:"urn"` Name string `yaml:"name"` Description string `yaml:"description"` Content map[string]any `yaml:",inline"` } -// UnmarshalYAML supports "id" as an alias for URN and parses string values into *urn.URN. +// UnmarshalYAML ensures inline fields are properly captured in Content. func (b *BaseFrontMatter) UnmarshalYAML(value *yaml.Node) error { var raw baseFrontMatterRaw if err := value.Decode(&raw); err != nil { @@ -47,16 +39,6 @@ func (b *BaseFrontMatter) UnmarshalYAML(value *yaml.Node) error { if raw.Content == nil { b.Content = make(map[string]any) } - if raw.URN != nil { - b.URN = raw.URN - return nil - } - if raw.ID != "" { - u, ok := urn.Parse([]byte(raw.ID)) - if ok { - b.URN = u - } - } return nil } diff --git a/pkg/codingcontext/markdown/frontmatter_command_test.go b/pkg/codingcontext/markdown/frontmatter_command_test.go index b68dc96..9ab2d6b 100644 --- a/pkg/codingcontext/markdown/frontmatter_command_test.go +++ b/pkg/codingcontext/markdown/frontmatter_command_test.go @@ -21,7 +21,6 @@ func TestCommandFrontMatter_Marshal(t *testing.T) { name: "command with standard id, name, description", command: CommandFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:command:standard"), Name: "Standard Command", Description: "This is a standard command with metadata", }, @@ -32,7 +31,6 @@ func TestCommandFrontMatter_Marshal(t *testing.T) { name: "command with expand false", command: CommandFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:command:no-expand"), Name: "No Expand Command", Description: "Command with expansion disabled", }, @@ -47,7 +45,6 @@ func TestCommandFrontMatter_Marshal(t *testing.T) { name: "command with selectors", command: CommandFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:command:selector"), Name: "Selector Command", Description: "Command with selectors", }, @@ -88,9 +85,9 @@ description: A command with standard fields `, want: CommandFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:command:named"), Name: "Named Command", Description: "A command with standard fields", + Content: map[string]any{"id": "urn:agents:command:named"}, }, }, }, @@ -103,9 +100,9 @@ expand: false `, want: CommandFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:command:no-expand"), Name: "No Expand", Description: "No expansion", + Content: map[string]any{"id": "urn:agents:command:no-expand"}, }, ExpandParams: nil, }, @@ -121,9 +118,9 @@ selectors: `, want: CommandFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:command:selector"), Name: "Selector Command", Description: "Has selectors", + Content: map[string]any{"id": "urn:agents:command:selector"}, }, Selectors: map[string]any{ "database": "postgres", @@ -145,9 +142,6 @@ selectors: } // Compare fields individually - if !urnEqual(got.URN, tt.want.URN) { - t.Errorf("URN = %q, want %q", urnString(got.URN), urnString(tt.want.URN)) - } if got.Name != tt.want.Name { t.Errorf("Name = %q, want %q", got.Name, tt.want.Name) } diff --git a/pkg/codingcontext/markdown/frontmatter_rule_test.go b/pkg/codingcontext/markdown/frontmatter_rule_test.go index 8fbf6ed..cf29f11 100644 --- a/pkg/codingcontext/markdown/frontmatter_rule_test.go +++ b/pkg/codingcontext/markdown/frontmatter_rule_test.go @@ -22,7 +22,6 @@ func TestRuleFrontMatter_Marshal(t *testing.T) { name: "rule with standard id, name, description", rule: RuleFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:rule:standard"), Name: "Standard Rule", Description: "This is a standard rule with metadata", }, @@ -50,7 +49,6 @@ func TestRuleFrontMatter_Marshal(t *testing.T) { name: "rule with all fields", rule: RuleFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:rule:all-fields"), Name: "Complete Rule", Description: "A rule with all fields", }, @@ -95,9 +93,9 @@ description: A rule with standard fields `, want: RuleFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:rule:named"), Name: "Named Rule", Description: "A rule with standard fields", + Content: map[string]any{"id": "urn:agents:rule:named"}, }, }, }, @@ -153,9 +151,6 @@ languages: } // Compare fields individually - if !urnEqual(got.URN, tt.want.URN) { - t.Errorf("URN = %q, want %q", urnString(got.URN), urnString(tt.want.URN)) - } if got.Name != tt.want.Name { t.Errorf("Name = %q, want %q", got.Name, tt.want.Name) } diff --git a/pkg/codingcontext/markdown/frontmatter_task_test.go b/pkg/codingcontext/markdown/frontmatter_task_test.go index 9088851..83cbe11 100644 --- a/pkg/codingcontext/markdown/frontmatter_task_test.go +++ b/pkg/codingcontext/markdown/frontmatter_task_test.go @@ -25,7 +25,6 @@ func TestTaskFrontMatter_Marshal(t *testing.T) { name: "task with standard id, name, description", task: TaskFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:task:standard-task"), Name: "Standard Test Task", Description: "This is a test task with standard fields", Content: map[string]any{"task_name": "standard-task"}, @@ -37,7 +36,6 @@ func TestTaskFrontMatter_Marshal(t *testing.T) { name: "task with all fields", task: TaskFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:task:full-task"), Name: "Full Task", Description: "A task with all fields", Content: map[string]any{"task_name": "full-task"}, @@ -103,10 +101,9 @@ description: This is a standard task `, want: TaskFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:task:standard-task"), Name: "Standard Task", Description: "This is a standard task", - Content: map[string]any{"task_name": "standard-task"}, + Content: map[string]any{"task_name": "standard-task", "id": "urn:agents:task:standard-task"}, }, }, }, @@ -154,10 +151,12 @@ selectors: `, want: TaskFrontMatter{ BaseFrontMatter: BaseFrontMatter{ - URN: mustParseURN("urn:agents:task:full-task"), Name: "Full Task", Description: "A complete task", - Content: map[string]any{"task_name": "full-task"}, + Content: map[string]any{ + "task_name": "full-task", + "id": "urn:agents:task:full-task", + }, }, Agent: "", Languages: []string{"go"}, @@ -188,9 +187,6 @@ selectors: if gotTaskName != wantTaskName { t.Errorf("TaskName = %q, want %q", gotTaskName, wantTaskName) } - if !urnEqual(got.URN, tt.want.URN) { - t.Errorf("URN = %q, want %q", urnString(got.URN), urnString(tt.want.URN)) - } if got.Name != tt.want.Name { t.Errorf("Name = %q, want %q", got.Name, tt.want.Name) } diff --git a/pkg/codingcontext/markdown/urn_test.go b/pkg/codingcontext/markdown/urn_test.go deleted file mode 100644 index 6f14297..0000000 --- a/pkg/codingcontext/markdown/urn_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package markdown - -import ( - "github.com/leodido/go-urn" -) - -func mustParseURN(s string) *urn.URN { - u, ok := urn.Parse([]byte(s)) - if !ok { - panic("invalid urn: " + s) - } - return u -} - -func urnEqual(a, b *urn.URN) bool { - if a == nil && b == nil { - return true - } - if a == nil || b == nil { - return false - } - return a.Equal(b) -} - -func urnString(u *urn.URN) string { - if u == nil { - return "" - } - return u.String() -} diff --git a/pkg/codingcontext/result_test.go b/pkg/codingcontext/result_test.go index cfcad9c..5106660 100644 --- a/pkg/codingcontext/result_test.go +++ b/pkg/codingcontext/result_test.go @@ -8,17 +8,8 @@ import ( "github.com/kitproj/coding-context-cli/pkg/codingcontext/markdown" "github.com/kitproj/coding-context-cli/pkg/codingcontext/mcp" - "github.com/leodido/go-urn" ) -func mustParseURN(s string) *urn.URN { - u, ok := urn.Parse([]byte(s)) - if !ok { - panic("invalid urn: " + s) - } - return u -} - func TestResult_Prompt(t *testing.T) { tests := []struct { name string @@ -105,14 +96,12 @@ func TestResult_MCPServers(t *testing.T) { Rules: []markdown.Markdown[markdown.RuleFrontMatter]{ { FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:jira-server")}, - MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "jira"}, + MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "jira"}, }, }, { FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:api-server")}, - MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeHTTP, URL: "https://api.example.com"}, + MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeHTTP, URL: "https://api.example.com"}, }, }, }, @@ -131,20 +120,16 @@ func TestResult_MCPServers(t *testing.T) { Rules: []markdown.Markdown[markdown.RuleFrontMatter]{ { FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:server1")}, - MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "server1"}, + MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "server1"}, }, }, { FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:server2")}, - MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "server2"}, + MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "server2"}, }, }, { - FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:empty")}, - }, + FrontMatter: markdown.RuleFrontMatter{}, }, }, Task: markdown.Markdown[markdown.TaskFrontMatter]{ @@ -161,9 +146,7 @@ func TestResult_MCPServers(t *testing.T) { Name: "test-task", Rules: []markdown.Markdown[markdown.RuleFrontMatter]{ { - FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:no-server")}, - }, + FrontMatter: markdown.RuleFrontMatter{}, }, }, Task: markdown.Markdown[markdown.TaskFrontMatter]{ @@ -180,20 +163,17 @@ func TestResult_MCPServers(t *testing.T) { Rules: []markdown.Markdown[markdown.RuleFrontMatter]{ { FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:explicit")}, - MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "server1"}, + MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "server1"}, }, }, { FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:some-rule")}, - MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "server2"}, + MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeStdio, Command: "server2"}, }, }, { FrontMatter: markdown.RuleFrontMatter{ - BaseFrontMatter: markdown.BaseFrontMatter{URN: mustParseURN("urn:agents:rule:another")}, - MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeHTTP, URL: "https://example.com"}, + MCPServer: mcp.MCPServerConfig{Type: mcp.TransportTypeHTTP, URL: "https://example.com"}, }, }, },