fix skill install metadata consistency and onboard template copy
This commit is contained in:
parent
70c200e4d3
commit
6c766fc119
3 changed files with 33 additions and 4 deletions
|
|
@ -193,6 +193,9 @@ func copyEmbeddedToTarget(targetDir string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to get relative path for %s: %v\n", path, err)
|
return fmt.Errorf("Failed to get relative path for %s: %v\n", path, err)
|
||||||
}
|
}
|
||||||
|
if new_path == "AGENTS.md" || new_path == "IDENTITY.md" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Build target file path
|
// Build target file path
|
||||||
targetPath := filepath.Join(targetDir, new_path)
|
targetPath := filepath.Join(targetDir, new_path)
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ func (t *InstallSkillTool) Execute(ctx context.Context, args map[string]any) *To
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write origin metadata.
|
// Write origin metadata.
|
||||||
if err := writeOriginMeta(targetDir, registry.Name(), slug, result.Version); err != nil {
|
if err := writeOriginMeta(targetDir, registry, slug, result.Version); err != nil {
|
||||||
logger.ErrorCF("tool", "Failed to write origin metadata",
|
logger.ErrorCF("tool", "Failed to write origin metadata",
|
||||||
map[string]any{
|
map[string]any{
|
||||||
"tool": "install_skill",
|
"tool": "install_skill",
|
||||||
|
|
@ -189,17 +189,28 @@ func (t *InstallSkillTool) Execute(ctx context.Context, args map[string]any) *To
|
||||||
// originMeta tracks which registry a skill was installed from.
|
// originMeta tracks which registry a skill was installed from.
|
||||||
type originMeta struct {
|
type originMeta struct {
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
|
OriginKind string `json:"origin_kind,omitempty"`
|
||||||
Registry string `json:"registry"`
|
Registry string `json:"registry"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
|
RegistryURL string `json:"registry_url,omitempty"`
|
||||||
InstalledVersion string `json:"installed_version"`
|
InstalledVersion string `json:"installed_version"`
|
||||||
InstalledAt int64 `json:"installed_at"`
|
InstalledAt int64 `json:"installed_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeOriginMeta(targetDir, registryName, slug, version string) error {
|
func writeOriginMeta(targetDir string, registry skills.SkillRegistry, slug, version string) error {
|
||||||
|
registryName := ""
|
||||||
|
registryURL := ""
|
||||||
|
if registry != nil {
|
||||||
|
registryName = registry.Name()
|
||||||
|
registryURL = registry.SkillURL(slug, version)
|
||||||
|
}
|
||||||
|
|
||||||
meta := originMeta{
|
meta := originMeta{
|
||||||
Version: 1,
|
Version: 1,
|
||||||
|
OriginKind: "third_party",
|
||||||
Registry: registryName,
|
Registry: registryName,
|
||||||
Slug: slug,
|
Slug: slug,
|
||||||
|
RegistryURL: registryURL,
|
||||||
InstalledVersion: version,
|
InstalledVersion: version,
|
||||||
InstalledAt: time.Now().UnixMilli(),
|
InstalledAt: time.Now().UnixMilli(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -167,13 +168,27 @@ func TestInstallSkillToolMissingRegistry(t *testing.T) {
|
||||||
func TestInstallSkillToolAllowsGitHubURLSlug(t *testing.T) {
|
func TestInstallSkillToolAllowsGitHubURLSlug(t *testing.T) {
|
||||||
registryMgr := skills.NewRegistryManager()
|
registryMgr := skills.NewRegistryManager()
|
||||||
registryMgr.AddRegistry(&mockGitHubInstallRegistry{})
|
registryMgr.AddRegistry(&mockGitHubInstallRegistry{})
|
||||||
tool := NewInstallSkillTool(registryMgr, t.TempDir())
|
workspace := t.TempDir()
|
||||||
|
tool := NewInstallSkillTool(registryMgr, workspace)
|
||||||
|
|
||||||
|
slug := "https://github.com/synthetic-lab/octofriend/tree/main/.agents/skills/pr-review"
|
||||||
result := tool.Execute(context.Background(), map[string]any{
|
result := tool.Execute(context.Background(), map[string]any{
|
||||||
"slug": "https://github.com/synthetic-lab/octofriend/tree/main/.agents/skills/pr-review",
|
"slug": slug,
|
||||||
"registry": "github",
|
"registry": "github",
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.False(t, result.IsError)
|
assert.False(t, result.IsError)
|
||||||
assert.Contains(t, result.ForLLM, `Successfully installed skill`)
|
assert.Contains(t, result.ForLLM, `Successfully installed skill`)
|
||||||
|
|
||||||
|
data, err := os.ReadFile(filepath.Join(workspace, "skills", "pr-review", ".skill-origin.json"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var meta originMeta
|
||||||
|
require.NoError(t, json.Unmarshal(data, &meta))
|
||||||
|
assert.Equal(t, "third_party", meta.OriginKind)
|
||||||
|
assert.Equal(t, "github", meta.Registry)
|
||||||
|
assert.Equal(t, slug, meta.Slug)
|
||||||
|
assert.Equal(t, slug, meta.RegistryURL)
|
||||||
|
assert.Equal(t, "main", meta.InstalledVersion)
|
||||||
|
assert.NotZero(t, meta.InstalledAt)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue