Skip to content

armgit / ax

Public Imported from GitHub
0

Agent Executor (AX) is Google's open agentic orchestration runtime

Go

skills: replace io.EOF with ErrNoSkills sentinel for empty skills dir (#305)

JoyceLiu5cbd55e18e6d
diff --git a/internal/gemini/gemini.go b/internal/gemini/gemini.go
index ddde682..b2fa19d 100644
--- a/internal/gemini/gemini.go
+++ b/internal/gemini/gemini.go
@@ -19,7 +19,6 @@ import (
"encoding/json"
"errors"
"fmt"
- "io"
"os"
"os/exec"
"runtime"
@@ -325,7 +324,7 @@ func NewSkillsTool(dir string) (Tool, error) {
if err != nil {
// If no skills are found or the directory does not exist, fallback to a no-op tool
// to avoid hard errors when skills are not configured or available.
- if errors.Is(err, io.EOF) || errors.Is(err, os.ErrNotExist) {
+ if errors.Is(err, skills.ErrNoSkills) || errors.Is(err, os.ErrNotExist) {
return &NoopTool{}, nil
}
return nil, err
diff --git a/internal/gemini/gemini_planner.go b/internal/gemini/gemini_planner.go
index 1874bee..b771748 100644
--- a/internal/gemini/gemini_planner.go
+++ b/internal/gemini/gemini_planner.go
@@ -17,7 +17,6 @@ package gemini
import (
"context"
"fmt"
- "io"
"os"
"time"
@@ -100,8 +99,10 @@ Rules for Operation:
return nil, fmt.Errorf("failed to create Gemini client: %w", err)
}
+ // NewSkillsTool already converts skills.ErrNoSkills (empty dir)
+ // into a NoopTool with a nil error, so any error here is real.
skillsTool, err := NewSkillsTool(cfg.SkillsDir)
- if err != nil && err != io.EOF {
+ if err != nil {
return nil, fmt.Errorf("failed to initialize skills tool: %w", err)
}
diff --git a/internal/skills/exec.go b/internal/skills/exec.go
index 60d1b35..ed38e13 100644
--- a/internal/skills/exec.go
+++ b/internal/skills/exec.go
@@ -16,12 +16,17 @@ package skills
import (
"context"
+ "errors"
"fmt"
- "io"
"google.golang.org/genai"
)
+// ErrNoSkills is returned by NewExecutor when the skills directory exists
+// and was successfully scanned but contained no SKILL.md files. Callers
+// can use errors.Is to detect this case and fall back to a no-op tool.
+var ErrNoSkills = errors.New("no skills found")
+
// Executor runs an agentskills.io-compatible agentic loop.
type Executor struct {
model string
@@ -31,6 +36,10 @@ type Executor struct {
// NewExecutor discovers skills in dir, then creates an Executor. The caller is
// responsible for creating the client and choosing a model.
+//
+// Returns ErrNoSkills if dir was scanned successfully but contained no
+// SKILL.md files. Other errors (e.g. dir does not exist, permission
+// denied) are returned wrapped from Discover.
func NewExecutor(dir string) (*Executor, error) {
found, err := Discover(dir)
@@ -38,7 +47,7 @@ func NewExecutor(dir string) (*Executor, error) {
return nil, err
}
if len(found) == 0 {
- return nil, io.EOF
+ return nil, ErrNoSkills
}
names := make([]string, len(found))
diff --git a/internal/skills/skills_test.go b/internal/skills/skills_test.go
index 94d5ec4..9340d00 100644
--- a/internal/skills/skills_test.go
+++ b/internal/skills/skills_test.go
@@ -16,11 +16,49 @@ package skills
import (
"context"
+ "errors"
"os"
"path/filepath"
"testing"
)
+func TestNewExecutor_NoSkills(t *testing.T) {
+ // An empty (but existing) directory should yield ErrNoSkills, not
+ // io.EOF as before — callers should be able to detect "no skills
+ // configured" via errors.Is.
+ tmpDir := t.TempDir()
+ _, err := NewExecutor(tmpDir)
+ if err == nil {
+ t.Fatal("expected error for empty skills dir")
+ }
+ if !errors.Is(err, ErrNoSkills) {
+ t.Errorf("want errors.Is(err, ErrNoSkills) to be true, got %v", err)
+ }
+}
+
+func TestNewExecutor_WithSkills(t *testing.T) {
+ tmpDir := t.TempDir()
+ skillDir := filepath.Join(tmpDir, "test-skill")
+ if err := os.MkdirAll(skillDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(
+ filepath.Join(skillDir, "SKILL.md"),
+ []byte("---\nname: Test\ndescription: Test\n---\nbody"),
+ 0644,
+ ); err != nil {
+ t.Fatal(err)
+ }
+
+ exec, err := NewExecutor(tmpDir)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if !exec.HasSkills() {
+ t.Error("expected HasSkills() to be true")
+ }
+}
+
func TestDiscover(t *testing.T) {
// Create a temporary skills directory
tmpDir := t.TempDir()