Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix: respect omp profiles when discovering runtime skills (#9711)

Bohan Jiang374b6f3db459
diff --git a/apps/docs/content/docs/skills.mdx b/apps/docs/content/docs/skills.mdx
index a27cd92db8..11d5cee14d 100644
--- a/apps/docs/content/docs/skills.mdx
+++ b/apps/docs/content/docs/skills.mdx
@@ -98,6 +98,8 @@ Some AI coding tools also read project-level skills directly from the code repos
Runtime-local skills already installed on a connected computer (Claude Code and Codex) show up in the agent's **Skills** tab and can be disabled per agent. Disabling likewise requires permission to modify the agent.
+For Oh-My-Pi, the inherited list and runtime copies follow the runtime command's selected profile and effective skill filters. Discovery runs in an empty directory and covers user-level configuration; project settings and explicitly assigned Multica skills are separate. If OMP cannot return its skill roster, refresh reports an error.
+
## Edit permissions
Any workspace member can create or import a skill. The creator and workspace `owner`s and `admin`s can modify or delete it; other members can view and use it, but cannot overwrite its content.
diff --git a/apps/docs/content/docs/skills.zh.mdx b/apps/docs/content/docs/skills.zh.mdx
index f40491014b..4fa3224c8b 100644
--- a/apps/docs/content/docs/skills.zh.mdx
+++ b/apps/docs/content/docs/skills.zh.mdx
@@ -98,6 +98,8 @@ scripts/check.sh
连接电脑上已安装的运行时本地 skill(Claude Code 和 Codex)会显示在智能体的 **Skills** 标签页中,可以按智能体单独停用。停用同样需要有权修改该智能体。
+对于 Oh-My-Pi,继承列表和从运行时复制的操作会遵循启动命令选定的 profile 及生效的 skill 筛选配置。发现过程在空目录中运行,读取用户级配置;项目配置和显式分配的 Multica skill 单独处理。如果 OMP 无法返回 skill 清单,刷新会报错。
+
## 修改权限
任何工作区成员都可以创建或导入 skill。创建者和工作区 `owner`、`admin` 可以修改或删除它;其他成员可以查看和使用,但不能覆盖内容。
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.go
index a0ab6ea01c..37c5d125c4 100644
--- a/server/internal/daemon/daemon.go
+++ b/server/internal/daemon/daemon.go
@@ -4820,7 +4820,7 @@ func (d *Daemon) handleModelList(ctx context.Context, rt Runtime, requestID stri
func (d *Daemon) handleLocalSkillList(ctx context.Context, rt Runtime, requestID string) {
d.logger.Info("runtime local skills requested", "runtime_id", rt.ID, "request_id", requestID, "provider", rt.Provider)
- skills, supported, err := listRuntimeLocalSkills(rt.Provider)
+ skills, supported, err := d.listLocalSkills(ctx, rt)
if err != nil {
d.reportLocalSkillListResult(ctx, rt, requestID, map[string]any{
"status": "failed",
@@ -4847,7 +4847,7 @@ func (d *Daemon) handleLocalSkillList(ctx context.Context, rt Runtime, requestID
func (d *Daemon) handleLocalSkillImport(ctx context.Context, rt Runtime, pending PendingLocalSkillImport) {
d.logger.Info("runtime local skill import requested", "runtime_id", rt.ID, "request_id", pending.ID, "provider", rt.Provider, "skill_key", pending.SkillKey)
- skill, supported, err := loadRuntimeLocalSkillBundle(rt.Provider, pending.SkillKey)
+ skill, supported, err := d.loadLocalSkillBundle(ctx, rt, pending.SkillKey)
if err != nil {
d.reportLocalSkillImportResult(ctx, rt, pending.ID, map[string]any{
"status": "failed",
diff --git a/server/internal/daemon/local_skills_omp.go b/server/internal/daemon/local_skills_omp.go
new file mode 100644
index 0000000000..54905564f9
--- /dev/null
+++ b/server/internal/daemon/local_skills_omp.go
@@ -0,0 +1,95 @@
+package daemon
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "path/filepath"
+ "sort"
+ "strings"
+
+ "github.com/multica-ai/multica/server/pkg/agent"
+)
+
+var discoverOmpSkills = agent.DiscoverOmpSkills
+
+func (d *Daemon) ompSkills(ctx context.Context, rt Runtime) ([]agent.OmpSkill, error) {
+ if spec, ok := d.customProfileLaunchForRuntime(rt.ID); ok {
+ return discoverOmpSkills(ctx, agent.NewCommand(spec.path, agent.FilterLaunchPrefix(rt.Provider, spec.fixedArgs, d.logger)))
+ }
+ // A missing custom command must not silently probe the default profile.
+ if rt.ProfileID != "" {
+ return nil, fmt.Errorf("omp runtime profile command is unavailable")
+ }
+ entry, ok := d.agents()[rt.Provider]
+ if !ok {
+ return nil, fmt.Errorf("no agent configured for provider %q", rt.Provider)
+ }
+ entry, _ = d.resolveAgentEntry(ctx, rt.Provider, entry)
+ return discoverOmpSkills(ctx, agent.NewCommand(entry.Path, nil))
+}
+
+func (d *Daemon) listLocalSkills(ctx context.Context, rt Runtime) ([]runtimeLocalSkillSummary, bool, error) {
+ if rt.Provider != "omp" {
+ return listRuntimeLocalSkills(rt.Provider)
+ }
+ resolved, err := d.ompSkills(ctx, rt)
+ if err != nil {
+ return nil, true, err
+ }
+ skills := make([]runtimeLocalSkillSummary, 0, len(resolved))
+ for _, entry := range resolved {
+ dir := filepath.Dir(entry.Path)
+ files, err := collectLocalSkillFiles(dir, false)
+ if err != nil {
+ return nil, true, err
+ }
+ root := localSkillRootProvider
+ if home, err := os.UserHomeDir(); err == nil {
+ rel, err := filepath.Rel(filepath.Join(home, ".agents", "skills"), dir)
+ if err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator)) && !filepath.IsAbs(rel) {
+ root = localSkillRootUniversal
+ }
+ }
+ skills = append(skills, runtimeLocalSkillSummary{
+ Key: entry.Name, Name: entry.Name, Description: entry.Description,
+ SourcePath: relativizeHomePath(dir), Provider: rt.Provider,
+ Root: root, FileCount: len(files) + 1,
+ })
+ }
+ sort.Slice(skills, func(i, j int) bool { return skills[i].Key < skills[j].Key })
+ return skills, true, nil
+}
+
+func (d *Daemon) loadLocalSkillBundle(ctx context.Context, rt Runtime, skillKey string) (*runtimeLocalSkillBundle, bool, error) {
+ if rt.Provider != "omp" {
+ return loadRuntimeLocalSkillBundle(rt.Provider, skillKey)
+ }
+ key, err := normalizeLocalSkillKey(skillKey)
+ if err != nil {
+ return nil, true, err
+ }
+ resolved, err := d.ompSkills(ctx, rt)
+ if err != nil {
+ return nil, true, err
+ }
+ for _, entry := range resolved {
+ if entry.Name != key {
+ continue
+ }
+ dir := filepath.Dir(entry.Path)
+ content, err := readLocalSkillMainFile(dir)
+ if err != nil {
+ return nil, true, err
+ }
+ files, err := collectLocalSkillFiles(dir, true)
+ if err != nil {
+ return nil, true, err
+ }
+ return &runtimeLocalSkillBundle{
+ Name: entry.Name, Description: entry.Description, Content: content,
+ SourcePath: relativizeHomePath(dir), Provider: rt.Provider, Files: files,
+ }, true, nil
+ }
+ return nil, true, fmt.Errorf("local skill not found in the selected omp profile")
+}
diff --git a/server/internal/daemon/local_skills_omp_test.go b/server/internal/daemon/local_skills_omp_test.go
new file mode 100644
index 0000000000..5fc4bafada
--- /dev/null
+++ b/server/internal/daemon/local_skills_omp_test.go
@@ -0,0 +1,113 @@
+package daemon
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "net/http"
+ "path/filepath"
+ "reflect"
+ "strings"
+ "testing"
+
+ "github.com/multica-ai/multica/server/pkg/agent"
+)
+
+func TestOmpLocalSkillsListAndImportUseSelectedProfile(t *testing.T) {
+ home := t.TempDir()
+ setTestUserHome(t, home)
+ // The shared copy must neither leak into the roster nor shadow the
+ // same-named skill OMP selected from its profile or custom directory.
+ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "review", map[string]string{"SKILL.md": "shared copy"})
+ writeTestLocalSkill(t, filepath.Join(home, ".agents", "skills"), "excluded", map[string]string{"SKILL.md": "excluded copy"})
+ profileA := writeTestLocalSkill(t, filepath.Join(home, ".omp", "profiles", "a", "agent", "skills"), "review", map[string]string{
+ "SKILL.md": "profile A", "references/help.txt": "A reference",
+ })
+ profileB := writeTestLocalSkill(t, filepath.Join(home, "custom"), "review", map[string]string{"SKILL.md": "profile B"})
+ var report struct {
+ Status string `json:"status"`
+ Skills []runtimeLocalSkillSummary `json:"skills"`
+ Skill *runtimeLocalSkillBundle `json:"skill"`
+ }
+ d, _ := localSkillReportDaemon(t, func(w http.ResponseWriter, r *http.Request) {
+ if err := json.NewDecoder(r.Body).Decode(&report); err != nil {
+ t.Error(err)
+ }
+ w.WriteHeader(http.StatusOK)
+ })
+ d.runtimeIndex = map[string]Runtime{}
+ d.profileLaunchSpecs = map[string]profileLaunchSpec{}
+ previous := discoverOmpSkills
+ t.Cleanup(func() { discoverOmpSkills = previous })
+ for _, tc := range []struct{ profile, dir, content string }{{"a", profileA, "profile A"}, {"b", profileB, "profile B"}} {
+ t.Run(tc.profile, func(t *testing.T) {
+ rt := Runtime{ID: "runtime-" + tc.profile, Provider: "omp", ProfileID: tc.profile}
+ d.runtimeIndex[rt.ID] = rt
+ d.profileLaunchSpecs[tc.profile] = profileLaunchSpec{path: "/custom/omp-wrapper", fixedArgs: []string{"launch", "--profile", tc.profile}}
+ discoverOmpSkills = func(_ context.Context, command agent.Command) ([]agent.OmpSkill, error) {
+ if command.Path != "/custom/omp-wrapper" || !reflect.DeepEqual(command.Prefix, []string{"launch", "--profile", tc.profile}) {
+ t.Fatalf("wrong runtime command: %+v", command)
+ }
+ return []agent.OmpSkill{{Name: "review", Description: "Resolved skill", Path: filepath.Join(tc.dir, "SKILL.md")}}, nil
+ }
+ d.handleLocalSkillList(t.Context(), rt, "list-request")
+ if report.Status != "completed" || len(report.Skills) != 1 || report.Skills[0].Key != "review" || report.Skills[0].SourcePath != relativizeHomePath(tc.dir) {
+ t.Fatalf("wrong inventory: %+v", report)
+ }
+ d.handleLocalSkillImport(t.Context(), rt, PendingLocalSkillImport{ID: "import-request", SkillKey: "review"})
+ if report.Status != "completed" || report.Skill == nil || report.Skill.Content != tc.content || report.Skill.SourcePath != report.Skills[0].SourcePath {
+ t.Fatalf("import did not match listed profile copy: %+v", report.Skill)
+ }
+ if tc.profile == "a" && (report.Skills[0].FileCount != 2 || len(report.Skill.Files) != 1 || report.Skill.Files[0].Content != "A reference") {
+ t.Fatalf("supporting files lost: %+v", report.Skill)
+ }
+ if _, _, err := d.loadLocalSkillBundle(t.Context(), rt, "excluded"); err == nil {
+ t.Fatal("import accepted a shared skill excluded by the profile")
+ }
+ })
+ }
+}
+
+func TestOmpLocalSkillsDoNotFallBackOnDiscoveryFailure(t *testing.T) {
+ setTestUserHome(t, t.TempDir())
+ d, _ := localSkillReportDaemon(t, func(w http.ResponseWriter, r *http.Request) {
+ var report map[string]any
+ _ = json.NewDecoder(r.Body).Decode(&report)
+ if report["status"] != "failed" || !strings.Contains(report["error"].(string), "inventory unavailable") {
+ t.Errorf("discovery failure was not reported: %v", report)
+ }
+ w.WriteHeader(http.StatusOK)
+ })
+ rt := Runtime{ID: "runtime", Provider: "omp", ProfileID: "profile"}
+ d.runtimeIndex = map[string]Runtime{rt.ID: rt}
+ d.profileLaunchSpecs = map[string]profileLaunchSpec{rt.ProfileID: {path: "/custom/omp"}}
+ previous := discoverOmpSkills
+ t.Cleanup(func() { discoverOmpSkills = previous })
+ discoverOmpSkills = func(context.Context, agent.Command) ([]agent.OmpSkill, error) {
+ return nil, errors.New("inventory unavailable")
+ }
+ d.handleLocalSkillList(t.Context(), rt, "list")
+ d.handleLocalSkillImport(t.Context(), rt, PendingLocalSkillImport{ID: "import", SkillKey: "review"})
+ delete(d.profileLaunchSpecs, rt.ProfileID)
+ if _, err := d.ompSkills(t.Context(), rt); err == nil {
+ t.Fatal("missing custom command fell back to the default runtime")
+ }
+}
+
+func TestOmpLocalSkillsUseConfiguredBuiltinBinary(t *testing.T) {
+ d := freshDaemon("http://unused.invalid")
+ binary := fakeExecutable(t, "omp")
+ d.cfg.Agents = map[string]AgentEntry{"omp": {Path: binary}}
+ previous := discoverOmpSkills
+ t.Cleanup(func() { discoverOmpSkills = previous })
+ discoverOmpSkills = func(_ context.Context, command agent.Command) ([]agent.OmpSkill, error) {
+ if command.Path != binary || len(command.Prefix) != 0 {
+ t.Fatalf("wrong built-in command: %+v", command)
+ }
+ return []agent.OmpSkill{}, nil
+ }
+ skills, supported, err := d.listLocalSkills(t.Context(), Runtime{ID: "builtin", Provider: "omp"})
+ if err != nil || !supported || skills == nil || len(skills) != 0 {
+ t.Fatalf("empty effective roster: %v %v %v", skills, supported, err)
+ }
+}
diff --git a/server/pkg/agent/omp_skills.go b/server/pkg/agent/omp_skills.go
new file mode 100644
index 0000000000..505b7af38f
--- /dev/null
+++ b/server/pkg/agent/omp_skills.go
@@ -0,0 +1,112 @@
+package agent
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "os"
+ "path/filepath"
+ "strings"
+ "time"
+)
+
+// OmpSkill is an entry in OMP's resolved skill roster, including its selected
+// file when multiple sources provide the same name.
+type OmpSkill struct {
+ Name string
+ Description string
+ Path string
+}
+
+// OMP's RPC command catalog drops file paths and hides skills when skill
+// commands are disabled. The supported extension API retains those paths. A
+// run-only overlay enables command enumeration without changing skill loading,
+// source toggles, exclusions, or the user's persisted settings.
+const ompSkillProbe = `import { writeFileSync } from "node:fs";
+export default function (pi) {
+ pi.on("session_start", () => {
+ const skills = pi.getCommands().filter(command => command.source === "skill");
+ writeFileSync(process.env.MULTICA_OMP_SKILLS_OUTPUT, JSON.stringify({ skills }), { mode: 0o600 });
+ });
+}
+`
+
+// DiscoverOmpSkills asks the selected runtime command for its effective
+// user-level skills. The empty working directory excludes project-specific
+// settings and Multica-assigned skills. No prompt or model request is sent.
+func DiscoverOmpSkills(ctx context.Context, runtimeCmd Command) ([]OmpSkill, error) {
+ dir, err := os.MkdirTemp("", "multica-omp-skills-*")
+ if err != nil {
+ return nil, err
+ }
+ defer os.RemoveAll(dir)
+ extension := filepath.Join(dir, "inventory.ts")
+ config := filepath.Join(dir, "config.yml")
+ output := filepath.Join(dir, "inventory.json")
+ if err := os.WriteFile(extension, []byte(ompSkillProbe), 0o600); err != nil {
+ return nil, err
+ }
+ if err := os.WriteFile(config, []byte("skills:\n enableSkillCommands: true\n"), 0o600); err != nil {
+ return nil, err
+ }
+ runCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
+ defer cancel()
+ cmd := runtimeCmd.exec(runCtx, "--mode", "rpc", "--no-session", "--no-title", "--no-ui",
+ "--config", config, "--extension", extension)
+ cmd.Dir = dir
+ cmd.Env = replaceEnvValue(os.Environ(), "MULTICA_OMP_SKILLS_OUTPUT", output)
+ cmd.Stdin = strings.NewReader("")
+ cmd.Stdout, cmd.Stderr = io.Discard, io.Discard
+ hideAgentWindow(cmd)
+ if err := runOwned(cmd, runtimeCmd.logger); err != nil {
+ if runCtx.Err() != nil {
+ return nil, fmt.Errorf("omp skill discovery: %w", runCtx.Err())
+ }
+ return nil, fmt.Errorf("omp skill discovery: %w", err)
+ }
+ file, err := os.Open(output)
+ if err != nil {
+ return nil, fmt.Errorf("omp did not return a skill inventory: %w", err)
+ }
+ defer file.Close()
+ const maxSnapshotSize = 8 << 20
+ data, err := io.ReadAll(io.LimitReader(file, maxSnapshotSize+1))
+ if err != nil {
+ return nil, err
+ }
+ if len(data) > maxSnapshotSize {
+ return nil, fmt.Errorf("omp skill inventory exceeds %d bytes", maxSnapshotSize)
+ }
+ return parseOmpSkills(data)
+}
+
+func parseOmpSkills(data []byte) ([]OmpSkill, error) {
+ var snapshot struct {
+ Skills *[]struct {
+ Name string `json:"name"`
+ Description string `json:"description"`
+ Source string `json:"source"`
+ Path string `json:"path"`
+ } `json:"skills"`
+ }
+ if err := json.Unmarshal(data, &snapshot); err != nil {
+ return nil, fmt.Errorf("invalid omp skill inventory: %w", err)
+ }
+ if snapshot.Skills == nil {
+ return nil, fmt.Errorf("omp skill inventory is missing skills")
+ }
+ skills := make([]OmpSkill, 0, len(*snapshot.Skills))
+ seen := make(map[string]bool)
+ for _, entry := range *snapshot.Skills {
+ name, ok := strings.CutPrefix(entry.Name, "skill:")
+ if !ok || name == "" || entry.Source != "skill" || !filepath.IsAbs(entry.Path) || filepath.Base(entry.Path) != "SKILL.md" {
+ return nil, fmt.Errorf("invalid entry in omp skill inventory")
+ }
+ if !seen[name] {
+ skills = append(skills, OmpSkill{Name: name, Description: entry.Description, Path: entry.Path})
+ seen[name] = true
+ }
+ }
+ return skills, nil
+}
diff --git a/server/pkg/agent/omp_skills_integration_test.go b/server/pkg/agent/omp_skills_integration_test.go
new file mode 100644
index 0000000000..2241700b9b
--- /dev/null
+++ b/server/pkg/agent/omp_skills_integration_test.go
@@ -0,0 +1,105 @@
+//go:build agentintegration
+
+package agent
+
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "reflect"
+ "sort"
+ "testing"
+)
+
+func TestOmpSkillDiscoveryWithoutModelCall(t *testing.T) {
+ if os.Getenv("MULTICA_RUN_REAL_AGENT_SMOKE") != "1" {
+ t.Skip("set MULTICA_RUN_REAL_AGENT_SMOKE=1 to run real-agent smoke tests")
+ }
+ binary := os.Getenv("MULTICA_OMP_SMOKE_EXECUTABLE")
+ if binary == "" {
+ t.Skip("set MULTICA_OMP_SMOKE_EXECUTABLE to the OMP binary to verify")
+ }
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("USERPROFILE", home)
+ t.Setenv("PI_CONFIG_DIR", ".omp")
+ t.Setenv("PI_CODING_AGENT_DIR", filepath.Join(home, ".omp", "agent"))
+ t.Setenv("ANTHROPIC_API_KEY", "unused-no-model-call")
+ profileDir := func(profile string) string { return filepath.Join(home, ".omp", "profiles", profile, "agent") }
+ writeSkill := func(root, name string) string {
+ t.Helper()
+ path := filepath.Join(root, name, "SKILL.md")
+ if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(path, []byte("---\nname: "+name+"\ndescription: Smoke fixture\n---\nFixture\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ return path
+ }
+ paths := map[string]string{}
+ for _, name := range []string{"alpha", "ignored", "disabled", "filtered"} {
+ paths[name] = writeSkill(filepath.Join(profileDir("a"), "skills"), name)
+ }
+ paths["beta"] = writeSkill(filepath.Join(profileDir("b"), "skills"), "beta")
+ paths["shared"] = writeSkill(filepath.Join(home, ".agents", "skills"), "shared")
+ custom := filepath.Join(home, "custom-skills")
+ paths["custom"] = writeSkill(custom, "custom")
+ for _, tc := range []struct {
+ name, profile string
+ skills map[string]any
+ extraArgs []string
+ want []string
+ }{
+ {"source-off", "a", map[string]any{"enableAgentsUser": false}, nil, []string{"alpha"}},
+ {"source-on", "a", map[string]any{"enableAgentsUser": true}, nil, []string{"alpha", "shared"}},
+ {"allowlist", "a", map[string]any{"enableAgentsUser": true, "includeSkills": []string{"alpha"}}, nil, []string{"alpha"}},
+ {"commands-disabled", "a", map[string]any{"enableSkillCommands": false}, nil, []string{"alpha"}},
+ {"skills-disabled", "a", map[string]any{"enabled": false}, nil, []string{}},
+ {"no-skills-flag", "a", nil, []string{"--no-skills"}, []string{}},
+ {"custom-profile-b", "b", map[string]any{"includeSkills": []string{"beta", "custom"}, "customDirectories": []string{custom}}, nil, []string{"beta", "custom"}},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ skillSettings := map[string]any{
+ "enabled": true, "enableSkillCommands": true,
+ "enablePiUser": true, "enablePiProject": false,
+ "enableAgentsUser": false, "enableAgentsProject": false,
+ "includeSkills": []string{"alpha", "ignored", "disabled", "shared"},
+ "ignoredSkills": []string{"ignored"},
+ }
+ for key, value := range tc.skills {
+ skillSettings[key] = value
+ }
+ config, _ := json.Marshal(map[string]any{
+ "enabledProviders": []string{"agents"},
+ "disabledExtensions": []string{"skill:disabled"},
+ "skills": skillSettings,
+ })
+ configPath := filepath.Join(profileDir(tc.profile), "config.yml")
+ if err := os.WriteFile(configPath, config, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ prefix := []string{"--profile", tc.profile, "--no-extensions", "--no-lsp", "--no-pty", "--model", "anthropic/claude-sonnet-4-5"}
+ prefix = append(prefix, tc.extraArgs...)
+ skills, err := DiscoverOmpSkills(t.Context(), NewCommand(binary, prefix))
+ if err != nil {
+ t.Fatal(err)
+ }
+ names := make([]string, 0, len(skills))
+ for _, skill := range skills {
+ names = append(names, skill.Name)
+ if skill.Path != paths[skill.Name] {
+ t.Errorf("%s path=%q, want %q", skill.Name, skill.Path, paths[skill.Name])
+ }
+ }
+ sort.Strings(names)
+ if !reflect.DeepEqual(names, tc.want) {
+ t.Fatalf("roster=%v, want %v", names, tc.want)
+ }
+ persisted, _ := os.ReadFile(configPath)
+ if string(persisted) != string(config) {
+ t.Fatal("discovery changed persisted profile settings")
+ }
+ })
+ }
+}
diff --git a/server/pkg/agent/omp_skills_test.go b/server/pkg/agent/omp_skills_test.go
new file mode 100644
index 0000000000..1fde3e0823
--- /dev/null
+++ b/server/pkg/agent/omp_skills_test.go
@@ -0,0 +1,116 @@
+package agent
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "os"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "strings"
+ "testing"
+ "time"
+)
+
+func TestDiscoverOmpSkillsUsesRuntimePrefixWithoutPrompt(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("POSIX shell fixture")
+ }
+ dir := t.TempDir()
+ capture := filepath.Join(dir, "argv")
+ t.Setenv("MULTICA_TEST_OMP_ARGS", capture)
+ path := filepath.Join(dir, "profile", "SKILL.md")
+ snapshot, _ := json.Marshal(map[string]any{"skills": []map[string]string{{
+ "source": "skill", "name": "skill:profile-only", "description": "Selected profile", "path": path,
+ }}})
+ t.Setenv("MULTICA_TEST_OMP_SNAPSHOT", string(snapshot))
+ binary := filepath.Join(dir, "wrapper")
+ writeTestExecutable(t, binary, []byte(`#!/bin/sh
+printf '%s\n' "$@" > "$MULTICA_TEST_OMP_ARGS"
+cat > "$MULTICA_TEST_OMP_ARGS.stdin"
+pwd > "$MULTICA_TEST_OMP_ARGS.cwd"
+while [ "$#" -gt 0 ]; do
+ case "$1" in
+ --config) cat "$2" > "$MULTICA_TEST_OMP_ARGS.config" ;;
+ esac
+ shift
+done
+printf '%s' "$MULTICA_TEST_OMP_SNAPSHOT" > "$MULTICA_OMP_SKILLS_OUTPUT"
+`))
+ prefix := []string{"launch", "--profile", "review-a", "--no-extensions"}
+ skills, err := DiscoverOmpSkills(t.Context(), NewCommand(binary, prefix))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !reflect.DeepEqual(skills, []OmpSkill{{Name: "profile-only", Description: "Selected profile", Path: path}}) {
+ t.Fatalf("skills=%+v", skills)
+ }
+ raw, _ := os.ReadFile(capture)
+ args := strings.Split(strings.TrimSpace(string(raw)), "\n")
+ if !reflect.DeepEqual(args[:len(prefix)], prefix) {
+ t.Fatalf("prefix lost: %v", args)
+ }
+ for _, flag := range []string{"--mode", "rpc", "--no-session", "--extension"} {
+ if !strings.Contains("\n"+string(raw), "\n"+flag+"\n") {
+ t.Errorf("missing %s: %v", flag, args)
+ }
+ }
+ input, _ := os.ReadFile(capture + ".stdin")
+ if len(input) != 0 {
+ t.Fatalf("probe sent input: %q", input)
+ }
+ config, _ := os.ReadFile(capture + ".config")
+ if string(config) != "skills:\n enableSkillCommands: true\n" {
+ t.Fatalf("enumeration overlay changed skill filtering: %s", config)
+ }
+ cwd, _ := os.ReadFile(capture + ".cwd")
+ if _, err := os.Stat(strings.TrimSpace(string(cwd))); !os.IsNotExist(err) {
+ t.Fatalf("probe working directory was not cleaned: %s (%v)", cwd, err)
+ }
+}
+
+func TestDiscoverOmpSkillsFailureAndCancellation(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("POSIX shell fixture")
+ }
+ for _, tc := range []struct{ name, script string }{
+ {"exit", "exit 1"},
+ {"no-inventory", "exit 0"},
+ {"invalid-inventory", `printf '{}' > "$MULTICA_OMP_SKILLS_OUTPUT"`},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ binary := filepath.Join(t.TempDir(), "omp")
+ writeTestExecutable(t, binary, []byte("#!/bin/sh\n"+tc.script+"\n"))
+ if _, err := DiscoverOmpSkills(t.Context(), NewCommand(binary, nil)); err == nil {
+ t.Fatal("expected a discovery error, not an installed-file fallback")
+ }
+ })
+ }
+ binary := filepath.Join(t.TempDir(), "slow-omp")
+ writeTestExecutable(t, binary, []byte("#!/bin/sh\nexec sleep 30\n"))
+ ctx, cancel := context.WithTimeout(t.Context(), 100*time.Millisecond)
+ defer cancel()
+ if _, err := DiscoverOmpSkills(ctx, NewCommand(binary, nil)); !errors.Is(err, context.DeadlineExceeded) {
+ t.Fatalf("cancellation: %v", err)
+ }
+}
+
+func TestParseOmpSkills(t *testing.T) {
+ for _, data := range []string{`{}`, `{"skills":null}`, `not json`, `{"skills":[{"source":"skill","name":"skill:x","path":"relative/SKILL.md"}]}`} {
+ if _, err := parseOmpSkills([]byte(data)); err == nil {
+ t.Errorf("accepted invalid snapshot %s", data)
+ }
+ }
+ empty, err := parseOmpSkills([]byte(`{"skills":[]}`))
+ if err != nil || empty == nil || len(empty) != 0 {
+ t.Fatalf("valid empty roster: %v %v", empty, err)
+ }
+ path := filepath.Join(t.TempDir(), "SKILL.md")
+ entry := map[string]string{"source": "skill", "name": "skill:plugin/review", "path": path}
+ data, _ := json.Marshal(map[string]any{"skills": []any{entry, entry}})
+ skills, err := parseOmpSkills(data)
+ if err != nil || len(skills) != 1 || skills[0].Name != "plugin/review" {
+ t.Fatalf("namespaced/deduplicated roster: %+v %v", skills, err)
+ }
+}