test(agent): fix ContinuityKeepCount; refactor(skills): YAML-only frontmatter
This commit is contained in:
parent
a600ae7968
commit
d53614360a
3 changed files with 15 additions and 20 deletions
|
|
@ -87,25 +87,25 @@ func TestContinuityKeepCount_UsesConfiguredPolicy(t *testing.T) {
|
||||||
cfg := config.DefaultConfig()
|
cfg := config.DefaultConfig()
|
||||||
cfg.Agents.Defaults.ContinuityRetention.MinMessages = 3
|
cfg.Agents.Defaults.ContinuityRetention.MinMessages = 3
|
||||||
cfg.Agents.Defaults.ContinuityRetention.MaxMessages = 7
|
cfg.Agents.Defaults.ContinuityRetention.MaxMessages = 7
|
||||||
cfg.Agents.Defaults.ContinuityRetention.TargetContextRatio = 0.01
|
cfg.Agents.Defaults.ContinuityRetention.TargetContextRatio = 0.5 // 50% of context window
|
||||||
|
|
||||||
al := &AgentLoop{
|
al := &AgentLoop{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
contextWindow: 256,
|
contextWindow: 10000, // Large enough to hold many messages
|
||||||
}
|
}
|
||||||
|
|
||||||
// Large history should be limited by MaxMessages
|
// Large history should be limited by MaxMessages when token budget allows
|
||||||
largeHistory := buildHistory(100, "test content")
|
largeHistory := buildHistory(100, "test content")
|
||||||
keep := al.continuityKeepCount(largeHistory)
|
keep := al.continuityKeepCount(largeHistory)
|
||||||
if keep != 7 {
|
if keep != 7 {
|
||||||
t.Errorf("expected keep=7 for large history, got %d", keep)
|
t.Errorf("expected keep=7 for large history, got %d", keep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small history with low token count should use MinMessages
|
// Small history should use actual count when under MinMessages
|
||||||
smallHistory := buildHistory(5, "x") // Very short content
|
smallHistory := buildHistory(2, "x") // Under MinMessages
|
||||||
keep = al.continuityKeepCount(smallHistory)
|
keep = al.continuityKeepCount(smallHistory)
|
||||||
if keep != 3 {
|
if keep != 2 { // Should keep actual count when under min
|
||||||
t.Errorf("expected keep=3 for small history, got %d", keep)
|
t.Errorf("expected keep=2 for small history, got %d", keep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -355,12 +355,16 @@ Content.
|
||||||
assert.Nil(t, g.GetIndex())
|
assert.Nil(t, g.GetIndex())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedFrontmatter_JSON(t *testing.T) {
|
func TestExtendedFrontmatter_YAML(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
tmp := t.TempDir()
|
tmp := t.TempDir()
|
||||||
|
|
||||||
writeSkill(t, tmp, "json-skill", `---
|
writeSkill(t, tmp, "yaml-skill", `---
|
||||||
{"name":"json-skill","description":"A JSON frontmatter skill","tags":["alpha","beta"],"domain":"testing","is_moc":true}
|
name: yaml-skill
|
||||||
|
description: A YAML frontmatter skill
|
||||||
|
tags: alpha, beta
|
||||||
|
domain: testing
|
||||||
|
is_moc: true
|
||||||
---
|
---
|
||||||
Content with [[some-link]].
|
Content with [[some-link]].
|
||||||
`)
|
`)
|
||||||
|
|
@ -370,7 +374,7 @@ Content with [[some-link]].
|
||||||
require.Len(t, skills, 1)
|
require.Len(t, skills, 1)
|
||||||
|
|
||||||
s := skills[0]
|
s := skills[0]
|
||||||
assert.Empty(t, cmp.Diff("json-skill", s.Name))
|
assert.Empty(t, cmp.Diff("yaml-skill", s.Name))
|
||||||
assert.Empty(t, cmp.Diff([]string{"alpha", "beta"}, s.Tags))
|
assert.Empty(t, cmp.Diff([]string{"alpha", "beta"}, s.Tags))
|
||||||
assert.Empty(t, cmp.Diff("testing", s.Domain))
|
assert.Empty(t, cmp.Diff("testing", s.Domain))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
jsonv2 "github.com/go-json-experiment/json"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var namePattern = regexp.MustCompile(`^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$`)
|
var namePattern = regexp.MustCompile(`^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$`)
|
||||||
|
|
@ -315,13 +313,6 @@ func (sl *SkillsLoader) getSkillMetadata(skillPath string) *SkillMetadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try JSON first (for backward compatibility)
|
|
||||||
var jsonMeta SkillMetadata
|
|
||||||
if err := jsonv2.Unmarshal([]byte(frontmatter), &jsonMeta); err == nil && jsonMeta.Name != "" {
|
|
||||||
return &jsonMeta
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back to simple YAML parsing
|
|
||||||
yamlMeta := sl.parseSimpleYAML(frontmatter)
|
yamlMeta := sl.parseSimpleYAML(frontmatter)
|
||||||
meta := &SkillMetadata{
|
meta := &SkillMetadata{
|
||||||
Name: yamlMeta["name"],
|
Name: yamlMeta["name"],
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue