Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(skills): retain platform hints after name collisions (#9949)
Multica Eve6a43ddb3441e
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex d6cf97dba2..a3f23cd195 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -10722,6 +10722,11 @@ func convertSkillsForEnv(skills []SkillData) []execenv.SkillContextForEnv {Description: s.Description,Content: s.Content,}+ // Legacy full-skill responses omit Source and give only workspace+ // skills an ID, matching the server's bundle source classification.+ if s.Source == skillbundle.SourceBuiltin || (s.Source == "" && s.ID == "") {+ result[i].BuiltinName = s.Name+ }for _, f := range s.Files {result[i].Files = append(result[i].Files, execenv.SkillFileContextForEnv{Path: f.Path,diff --git a/server/internal/daemon/execenv/execenv.go b/server/internal/daemon/execenv/execenv.goindex 368e113673..b410db7d0d 100644--- a/server/internal/daemon/execenv/execenv.go+++ b/server/internal/daemon/execenv/execenv.go@@ -256,6 +256,7 @@ type IssueStatusForEnv struct {type SkillContextForEnv struct {Name string+ BuiltinName string // original built-in identity; empty for workspace and plugin skillsDescription stringContent stringFiles []SkillFileContextForEnvdiff --git a/server/internal/daemon/execenv/platform_skill_identity_test.go b/server/internal/daemon/execenv/platform_skill_identity_test.gonew file mode 100644index 0000000000..f7fd4f26c3--- /dev/null+++ b/server/internal/daemon/execenv/platform_skill_identity_test.go@@ -0,0 +1,142 @@+package execenv++import (+ "context"+ "fmt"+ "os"+ "path/filepath"+ "strings"+ "testing"+ "time"+)++func TestPlatformSkillHintsRequireBuiltinIdentity(t *testing.T) {+ t.Parallel()+ user := platformSkillFixture()+ user.BuiltinName = ""+ hidden := platformSkillFixture()+ hidden.Content = "---\nname: multica-platform\ndisable-model-invocation: true\n---\n\nHidden contracts."+ for _, tc := range []struct {+ name string+ skills []SkillContextForEnv+ want string+ }{+ {name: "builtin", skills: []SkillContextForEnv{platformSkillFixture()}, want: platformSkillName},+ {name: "user precedes builtin", skills: []SkillContextForEnv{user, platformSkillFixture()}, want: "multica-platform-multica"},+ {name: "user only", skills: []SkillContextForEnv{user}},+ {name: "frontmatter alone is not identity", skills: []SkillContextForEnv{{Name: "helper", Content: user.Content}}},+ {name: "hidden builtin alongside visible user", skills: []SkillContextForEnv{user, hidden}},+ {name: "hidden builtin only", skills: []SkillContextForEnv{hidden}},+ {name: "absent"},+ } {+ for _, provider := range []string{"claude", "codex", "traecli"} {+ t.Run(tc.name+"/"+provider, func(t *testing.T) {+ t.Parallel()+ brief := buildMetaSkillContent(provider, TaskContextForEnv{IssueID: "issue-platform-identity", AgentSkills: tc.skills})+ assertPlatformSkillHints(t, provider, brief, tc.want)+ })+ }+ }+}++func TestPlatformSkillHintsFollowPreparedDirectories(t *testing.T) {+ t.Parallel()+ for _, provider := range []string{"claude", "traecli"} {+ for _, phase := range []string{"prepare", "reuse"} {+ for collisions := 0; collisions <= 2; collisions++ {+ t.Run(fmt.Sprintf("%s/%s/collisions-%d", provider, phase, collisions), func(t *testing.T) {+ t.Parallel()+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)+ defer cancel()+ task := TaskContextForEnv{IssueID: "issue-platform-identity", AgentSkills: []SkillContextForEnv{platformSkillFixture()}}+ params := PrepareParams{+ WorkspacesRoot: t.TempDir(), WorkspaceID: "workspace-platform-identity",+ TaskID: "task-platform-identity", Provider: provider, Task: task,+ }+ workDir := t.TempDir()+ if phase == "reuse" {+ initial := params+ initial.Task.AgentSkills = nil+ env, err := PrepareIsolated(ctx, preparationHelperTestCommand(), initial, testLogger())+ if err != nil {+ t.Fatal(err)+ }+ workDir = env.WorkDir+ }+ const userContent = "---\nname: multica-platform\n---\n\nUser-owned skill."+ for i := 0; i < collisions; i++ {+ mustWrite(t, filepath.Join(skillsDirPath(workDir, provider), skillSlugCandidate(platformSkillName, i), "SKILL.md"), userContent)+ }+ var env *Environment+ var err error+ if phase == "prepare" {+ params.LocalWorkDir = workDir+ env, err = PrepareIsolated(ctx, preparationHelperTestCommand(), params, testLogger())+ } else {+ // Refresh again after the first reuse materializes the platform+ // skill, so the assertions also cover reclaiming its old directory.+ for attempt := 0; attempt < 2; attempt++ {+ env, err = ReuseIsolated(ctx, preparationHelperTestCommand(), ReuseParams{+ WorkspacesRoot: params.WorkspacesRoot, WorkDir: workDir, Provider: provider, Task: task,+ }, testLogger())+ if err != nil || env == nil {+ t.Fatalf("reuse %d: environment=%+v, error=%v", attempt, env, err)+ }+ }+ }+ if err != nil || env == nil {+ t.Fatalf("%s: environment=%+v, error=%v", phase, env, err)+ }+ wantSlug := skillSlugCandidate(platformSkillName, collisions)+ if len(env.PreparedSkillNames) != 1 || env.PreparedSkillNames[0] != wantSlug {+ t.Fatalf("prepared names = %v, want [%s]", env.PreparedSkillNames, wantSlug)+ }+ prepared := ApplyPreparedSkillNames(task, env.PreparedSkillNames)+ visible := modelVisibleSkills(prepared.AgentSkills)+ if len(visible) != 1 || visible[0].BuiltinName != platformSkillName || task.AgentSkills[0].Name != platformSkillName {+ t.Fatalf("builtin identity lost or original mutated: prepared=%+v, original=%+v", visible, task.AgentSkills)+ }+ brief, err := InjectRuntimeConfig(workDir, provider, prepared)+ if err != nil {+ t.Fatal(err)+ }+ assertPlatformSkillHints(t, provider, brief, wantSlug)+ if !strings.Contains(brief, "**"+wantSlug+"**") {+ t.Fatal("allocated platform skill missing from listing")+ }+ data, err := os.ReadFile(filepath.Join(skillsDirPath(workDir, provider), wantSlug, "SKILL.md"))+ if err != nil || !frontmatterNameIs(string(data), wantSlug) {+ t.Fatalf("allocated skill = %q, error=%v", data, err)+ }+ for i := 0; i < collisions; i++ {+ data, err := os.ReadFile(filepath.Join(skillsDirPath(workDir, provider), skillSlugCandidate(platformSkillName, i), "SKILL.md"))+ if err != nil || string(data) != userContent {+ t.Fatalf("user skill changed: %q, error=%v", data, err)+ }+ }+ })+ }+ }+ }+}++func assertPlatformSkillHints(t *testing.T, provider, brief, slug string) {+ t.Helper()+ if slug == "" {+ for _, unwanted := range []string{"For a Multica platform action this brief does not fully cover", "Before creating sub-issues, read"} {+ if strings.Contains(brief, unwanted) {+ t.Errorf("brief advertised a platform contract without a visible builtin: %q", unwanted)+ }+ }+ return+ }+ platformHint := "load the `" + slug + "` skill and open the reference(s)"+ if provider == "traecli" {+ platformHint = "read `.traecli/skills/" + slug + "/SKILL.md` and open the reference(s)"+ }+ for _, want := range []string{platformHint, "Before creating sub-issues, read `references/sub-issues.md` in the `" + slug + "` skill"} {+ if !strings.Contains(brief, want) {+ t.Errorf("brief missing platform hint %q", want)+ }+ }+}diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.goindex 00fe6c5ced..8c9addbdec 100644--- a/server/internal/daemon/execenv/runtime_config_sections.go+++ b/server/internal/daemon/execenv/runtime_config_sections.go@@ -713,18 +713,11 @@ func subIssueContractsSkill(skills []SkillContextForEnv) (string, bool) {return "", false}-// builtinSlug finds a built-in by name.-//-// Stated assumption: `multica-` is the platform namespace, and no workspace-// skill in the batch shares a built-in's name. If one ever did, it would be-// listed first, take the bare slug, and this pointer would name it instead of-// the platform skill. That is accepted rather than handled — it needs a user to-// author a skill that sanitizes to exactly `multica-platform`, and the fix when-// it happens is to reject the prefix at skill create/import, not to make every-// pointer defensive.+// builtinSlug finds a built-in by its original identity and returns its+// allocated directory name, which may differ after collision resolution.func builtinSlug(skills []SkillContextForEnv, name string) (string, bool) {for _, skill := range skills {- if skill.Name == name {+ if skill.BuiltinName == name {return skill.Name, true}}@@ -781,11 +774,6 @@ func writeTraecliSkills(b *strings.Builder, skills []SkillContextForEnv) {fmt.Fprintf(b, " — %s", desc)}fmt.Fprintf(b, " (file: `%s`)\n", skillPath(skill.Name))- // Prepared names may have a collision suffix; Content retains the- // original frontmatter identifying the built-in platform skill.- if platformSlug == "" && frontmatterNameIs(skill.Content, platformSkillName) {- platformSlug = skill.Name- }}b.WriteString("\n")if platformSlug != "" {diff --git a/server/internal/daemon/execenv/runtime_config_test.go b/server/internal/daemon/execenv/runtime_config_test.goindex a6aec81a84..61d25705d8 100644--- a/server/internal/daemon/execenv/runtime_config_test.go+++ b/server/internal/daemon/execenv/runtime_config_test.go@@ -24,8 +24,9 @@ import (// built without it deliberately carries no pointer at all.func platformSkillFixture() SkillContextForEnv {return SkillContextForEnv{- Name: "multica-platform",- Content: "---\nname: multica-platform\n---\n\nbody",+ Name: "multica-platform",+ BuiltinName: "multica-platform",+ Content: "---\nname: multica-platform\n---\n\nbody",}}@@ -2410,7 +2411,7 @@ func TestBriefIssuePointerFollowsTheInstalledSkill(t *testing.T) {t.Parallel()skill := func(name string) SkillContextForEnv {- return SkillContextForEnv{Name: name, Content: "---\nname: " + name + "\n---\n\nbody"}+ return SkillContextForEnv{Name: name, BuiltinName: name, Content: "---\nname: " + name + "\n---\n\nbody"}}cases := []struct {@@ -2480,14 +2481,11 @@ func TestBriefIssuePointerFollowsTheInstalledSkill(t *testing.T) {// gives an agent one name to guess instead of eight. This line is what pays// that back, so it must appear whenever the skill does — an agent that cannot// find the platform contracts is strictly worse off than before the merge.-//-// Naming is by bare name, on the stated assumption that no workspace skill-// shares a built-in's name (see builtinSlug).func TestBriefPointsAtThePlatformSkill(t *testing.T) {t.Parallel()skill := func(name string) SkillContextForEnv {- return SkillContextForEnv{Name: name, Content: "---\nname: " + name + "\n---\n\nbody"}+ return SkillContextForEnv{Name: name, BuiltinName: name, Content: "---\nname: " + name + "\n---\n\nbody"}}cases := []struct {diff --git a/server/internal/daemon/execenv/traecli_skills_test.go b/server/internal/daemon/execenv/traecli_skills_test.goindex 2b55a80d34..a94116abb6 100644--- a/server/internal/daemon/execenv/traecli_skills_test.go+++ b/server/internal/daemon/execenv/traecli_skills_test.go@@ -76,7 +76,7 @@ func TestTraecliBriefOmitsSkillsWithoutVisibleEntries(t *testing.T) {t.Parallel()for _, skills := range [][]SkillContextForEnv{nil,- {{Name: "multica-platform", Content: "---\nname: multica-platform\ndisable-model-invocation: true\n---\n\nHidden body."}},+ {{Name: "multica-platform", BuiltinName: "multica-platform", Content: "---\nname: multica-platform\ndisable-model-invocation: true\n---\n\nHidden body."}},} {brief := buildMetaSkillContent("traecli", TaskContextForEnv{AgentSkills: skills})if strings.Contains(brief, "## Skills") || strings.Contains(brief, ".traecli/skills/") {diff --git a/server/internal/daemon/skill_invocation_names_test.go b/server/internal/daemon/skill_invocation_names_test.goindex 9b43c1da7f..4cbb28ca85 100644--- a/server/internal/daemon/skill_invocation_names_test.go+++ b/server/internal/daemon/skill_invocation_names_test.go@@ -64,6 +64,14 @@ func TestRunTaskListsAllocatedSkillInvocationName(t *testing.T) {if err := os.WriteFile(userSkillPath, []byte(userSkill), 0o600); err != nil {t.Fatal(err)}+ userPlatformPath := filepath.Join(workDir, ".claude", "skills", "multica-platform", "SKILL.md")+ const userPlatform = "---\nname: multica-platform\n---\n\nUser-owned platform skill.\n"+ if err := os.MkdirAll(filepath.Dir(userPlatformPath), 0o755); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(userPlatformPath, []byte(userPlatform), 0o600); err != nil {+ t.Fatal(err)+ }ref, err := json.Marshal(localDirectoryRef{LocalPath: workDir, DaemonID: "daemon-skill-collision", ExecutionMode: localDirectoryModeInPlace,})@@ -102,7 +110,11 @@ func TestRunTaskListsAllocatedSkillInvocationName(t *testing.T) {ProjectResources: []ProjectResourceData{{ID: "local-resource", ResourceType: localDirectoryResourceType, ResourceRef: ref}},Agent: &AgentData{ID: "agent-skill-collision", Name: "test-agent",- Skills: []SkillData{{ID: "assigned-review", Source: "workspace", Name: "Review", Content: "---\nname: original-review\n---\n\nAssigned review skill.\n"}},+ Skills: []SkillData{+ {ID: "assigned-review", Source: "workspace", Name: "Review", Content: "---\nname: original-review\n---\n\nAssigned review skill.\n"},+ {ID: "e78e3700-7776-427a-a0bb-96a6f7b41af6", Source: "workspace", Name: "multica-platform", Content: userPlatform},+ {ID: "builtin:multica-platform", Source: "builtin", Name: "multica-platform", Content: "---\nname: multica-platform\n---\n\nPlatform contracts.\n"},+ },},}ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)@@ -124,4 +136,15 @@ func TestRunTaskListsAllocatedSkillInvocationName(t *testing.T) {if got, err := os.ReadFile(userSkillPath); err != nil || string(got) != userSkill {t.Fatalf("user-owned skill changed: %q, %v", got, err)}+ for _, want := range []string{+ "load the `multica-platform-multica-multica` skill and open the reference(s)",+ "Before creating sub-issues, read `references/sub-issues.md` in the `multica-platform-multica-multica` skill",+ } {+ if !strings.Contains(string(brief), want) {+ t.Errorf("runtime brief lost platform hint %q", want)+ }+ }+ if got, err := os.ReadFile(userPlatformPath); err != nil || string(got) != userPlatform {+ t.Fatalf("user-owned platform skill changed: %q, %v", got, err)+ }}diff --git a/server/internal/daemon/skills_for_env_test.go b/server/internal/daemon/skills_for_env_test.gonew file mode 100644index 0000000000..3a1edced71--- /dev/null+++ b/server/internal/daemon/skills_for_env_test.go@@ -0,0 +1,40 @@+package daemon++import (+ "reflect"+ "testing"++ "github.com/multica-ai/multica/server/internal/daemon/execenv"+)++func TestConvertSkillsForEnvPreservesBuiltinIdentity(t *testing.T) {+ t.Parallel()+ for _, tc := range []struct {+ name, source, id, wantBuiltin string+ }{+ {name: "builtin ref", source: "builtin", id: "builtin:multica-platform", wantBuiltin: "multica-platform"},+ {name: "builtin without id", source: "builtin", wantBuiltin: "multica-platform"},+ {name: "legacy builtin", wantBuiltin: "multica-platform"},+ {name: "workspace ref", source: "workspace", id: "e78e3700-7776-427a-a0bb-96a6f7b41af6"},+ {name: "legacy workspace", id: "e78e3700-7776-427a-a0bb-96a6f7b41af6"},+ {name: "explicit workspace without id", source: "workspace"},+ {name: "plugin", source: "plugin", id: "plugin:multica-platform"},+ {name: "unknown source without id", source: "external"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ skill := SkillData{+ ID: tc.id, Source: tc.source, Name: "multica-platform", Description: "Platform contracts.",+ Content: "---\nname: multica-platform\n---\n\nInstructions.",+ Files: []SkillFileData{{Path: "references/sub-issues.md", Content: "Sub-issue contracts."}},+ }+ want := []execenv.SkillContextForEnv{{+ Name: skill.Name, BuiltinName: tc.wantBuiltin, Description: skill.Description, Content: skill.Content,+ Files: []execenv.SkillFileContextForEnv{{Path: skill.Files[0].Path, Content: skill.Files[0].Content}},+ }}+ if got := convertSkillsForEnv([]SkillData{skill}); !reflect.DeepEqual(got, want) {+ t.Fatalf("converted skills = %+v, want %+v", got, want)+ }+ })+ }+}diff --git a/server/internal/service/builtin_skills.go b/server/internal/service/builtin_skills.goindex e748c775ce..4a1918a891 100644--- a/server/internal/service/builtin_skills.go+++ b/server/internal/service/builtin_skills.go@@ -51,13 +51,9 @@ var builtinSkillSystemKey = map[string]string{// intentionally leaves to skills.//// Layout: builtin_skills/<name>/SKILL.md plus optional supporting files. The-// <name> directory carries a "multica-" prefix: that is the platform-// namespace, and the brief names built-ins by their bare name on the-// assumption that no workspace skill shares one. Nothing server-side reserves-// the prefix today, so a user could author a skill that sanitizes to the same-// slug and take the bare directory. That is accepted, not handled — when it-// becomes real, the fix is to reject the prefix at skill create/import rather-// than to make every pointer defensive.+// <name> directory carries a "multica-" prefix. The daemon preserves built-in+// identity separately from allocated directory names so brief pointers still+// resolve when a user skill occupies the same name.// legacyRedirects asks for redirect stubs under the names this server has// stopped shipping. The runtime brief is assembled by the daemon, not the// server, so a backend deploy cannot rewrite an installed daemon's copy of it: