Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(traecli): add file-based skill loading guidance (#9930)
Multica Eve9912701f9a0f
diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.goindex 08c2f7d86a..d739a481cf 100644--- a/server/internal/daemon/execenv/runtime_config_sections.go+++ b/server/internal/daemon/execenv/runtime_config_sections.go@@ -2,6 +2,7 @@ package execenvimport ("fmt"+ "path/filepath""strings""github.com/multica-ai/multica/server/internal/issuestatus"@@ -719,29 +720,19 @@ func builtinSlug(skills []SkillContextForEnv, name string) (string, bool) {return "", false}-// writeSkills emits the Skills section: an index of invocable skill names.-//-// Names only, deliberately. Every runtime CLI discovers the SKILL.md files the-// daemon writes and builds its own listing from their frontmatter, so repeating-// the descriptions here bought a second, more expensive copy of what the model-// already had — measured at ~3,100 tokens per brief on a real task, 40% of the-// whole brief — and no extra routing signal (MUL-5529).-//-// The index itself stays because it is the one skill listing Multica controls.-// Each CLI's own listing is theirs: its format, and whether it exists at all,-// can change with any release.-//-// There is no per-provider branch. The old fallback told providers outside a-// hardcoded list to read `.agent_context/skills/`, which was the wrong path for-// every provider that actually reached it — grok and traecli write to-// `.grok/skills` and `.traecli/skills` — while both discover natively and never-// needed the pointer.-func writeSkills(b *strings.Builder, ctx TaskContextForEnv) {+// writeSkills keeps native discovery's names-only index, except for TRAE:+// its task-local skills need descriptions and file-loading instructions when+// the runtime does not discover them.+func writeSkills(b *strings.Builder, provider string, ctx TaskContextForEnv) {skills := modelVisibleSkills(ctx.AgentSkills)if len(skills) == 0 {return}b.WriteString("## Skills\n\n")+ if provider == "traecli" {+ writeTraecliSkills(b, skills)+ return+ }b.WriteString("You have the following skills installed (discovered automatically):\n\n")for _, skill := range skills {fmt.Fprintf(b, "- **%s**\n", skill.Name)@@ -760,6 +751,37 @@ func writeSkills(b *strings.Builder, ctx TaskContextForEnv) {}}+func writeTraecliSkills(b *strings.Builder, skills []SkillContextForEnv) {+ skillPath := func(slug string) string {+ return filepath.ToSlash(filepath.Join(skillsDirPath("", "traecli"), slug, "SKILL.md"))+ }+ platformSlug, _ := builtinSlug(skills, platformSkillName)+ b.WriteString("The following skills are available as files (paths are relative to the task working directory):\n\n")+ b.WriteString("When a task matches a skill's description, use your file tools to read its `SKILL.md` before following its instructions. Resolve relative references to supporting files, including `references/` and `scripts/`, from that skill's directory.\n\n")+ for _, skill := range skills {+ // Keep the routing hint bounded; the full instructions stay in SKILL.md.+ const maxDescriptionRunes = 240+ description := []rune(strings.Join(strings.Fields(skill.Description), " "))+ if len(description) > maxDescriptionRunes {+ description = append(description[:maxDescriptionRunes-1], '…')+ }+ fmt.Fprintf(b, "- **%s**", skill.Name)+ if desc := sanitizeNameForBriefMarkdown(string(description)); desc != "" {+ 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 != "" {+ b.WriteString("For a Multica platform action this brief does not fully cover — issue and PR contracts, mentions, agents, squads, autopilots, projects, runtimes, skill import — read `" + skillPath(platformSlug) + "` and open the reference(s) its routing table names for the domains your task touches.\n\n")+ }+}+// writeMentions emits the @mention side-effects section (compressed).func writeMentions(b *strings.Builder) {b.WriteString("## Mentions\n\n")@@ -975,7 +997,7 @@ func buildMetaSkillContentSlim(provider string, ctx TaskContextForEnv) string {// Every kind, quick-create included. Quick-create used to be skipped here// and carried its own names-only index in the workdir sidecar instead;// that sidecar is gone (MUL-6984) and the brief is the single index.- writeSkills(&b, ctx)+ writeSkills(&b, provider, ctx)if kind == kindIssue {writeMentions(&b)diff --git a/server/internal/daemon/execenv/runtime_config_test.go b/server/internal/daemon/execenv/runtime_config_test.goindex c84c080392..a6aec81a84 100644--- a/server/internal/daemon/execenv/runtime_config_test.go+++ b/server/internal/daemon/execenv/runtime_config_test.go@@ -2342,18 +2342,8 @@ func TestBriefByteIdenticalAcrossRunsForEveryKind(t *testing.T) {}}-// TestBriefSkillsListIsNamesOnly pins the shape of the `## Skills` section: an-// index of invocable names, with no descriptions and no per-provider branch.-//-// Descriptions were removed because every runtime CLI already builds its own-// listing from the SKILL.md frontmatter the daemon writes, so the brief's copy-// was the same routing signal paid for twice — ~3,100 tokens per brief on a-// real task, 40% of the whole brief (MUL-5529).-//-// The provider branch was removed because its fallback was wrong: it told-// providers outside a hardcoded list to look in `.agent_context/skills/`, but-// the only providers that ever reached it — grok and traecli — have their files-// written to `.grok/skills` and `.traecli/skills` and discover them natively.+// TestBriefSkillsListIsNamesOnly pins the native-discovery Skills section+// byte-for-byte. TRAE's file-loading index has separate coverage.func TestBriefSkillsListIsNamesOnly(t *testing.T) {t.Parallel()@@ -2370,24 +2360,19 @@ func TestBriefSkillsListIsNamesOnly(t *testing.T) {},}- // grok and traecli are the providers that used to take the removed branch;- // the rest are a spread across the native-discovery list.- for _, provider := range []string{"claude", "codex", "opencode", "hermes", "grok", "traecli", "some-unknown-provider"} {+ for _, provider := range []string{"claude", "codex", "opencode", "hermes", "grok", "some-unknown-provider"} {t.Run(provider, func(t *testing.T) {t.Parallel()out := buildMetaSkillContent(provider, ctx)- if !strings.Contains(out, "- **pr-review**\n") {- t.Errorf("brief does not list the skill by slug:\n%s", out)- }- if strings.Contains(out, "Use when reviewing a pull request") {- t.Errorf("brief still carries the skill description; the CLI's own listing already has it:\n%s", out)- }- if strings.Contains(out, ".agent_context/skills/") {- t.Errorf("brief still points at the removed fallback path:\n%s", out)+ _, section, ok := strings.Cut(out, "## Skills\n\n")+ if !ok {+ t.Fatal("brief has no Skills section")}- if !strings.Contains(out, "discovered automatically") {- t.Errorf("brief lost the native-discovery framing:\n%s", out)+ section, _, _ = strings.Cut(section, "## Mentions\n\n")+ const want = "You have the following skills installed (discovered automatically):\n\n- **pr-review**\n\n"+ if section != want {+ t.Errorf("native-discovery Skills section changed:\ngot %q\nwant %q", section, want)}})}diff --git a/server/internal/daemon/execenv/traecli_skills_test.go b/server/internal/daemon/execenv/traecli_skills_test.gonew file mode 100644index 0000000000..2b55a80d34--- /dev/null+++ b/server/internal/daemon/execenv/traecli_skills_test.go@@ -0,0 +1,185 @@+package execenv++import (+ "fmt"+ "os"+ "path/filepath"+ "strings"+ "testing"+)++func TestTraecliBriefLoadsSkillsFromFiles(t *testing.T) {+ t.Parallel()+ for _, kind := range []TaskContextForEnv{+ {IssueID: "issue-1"},+ {ChatSessionID: "chat-1"},+ {AutopilotRunID: "run-1"},+ {QuickCreatePrompt: "create an issue"},+ } {+ kind.AgentSkills = []SkillContextForEnv{+ {Name: "Review Helper", Description: "Use when reviewing code.", Content: "Private review instructions."},+ platformSkillFixture(),+ }+ brief := buildMetaSkillContent("traecli", kind)+ for _, want := range []string{+ "paths are relative to the task working directory",+ "use your file tools to read its `SKILL.md`",+ "`references/` and `scripts/`",+ "from that skill's directory",+ "- **review-helper** — Use when reviewing code. (file: `.traecli/skills/review-helper/SKILL.md`)",+ "read `.traecli/skills/multica-platform/SKILL.md` and open the reference(s)",+ "for the domains your task touches",+ } {+ if !strings.Contains(brief, want) {+ t.Errorf("%v brief missing %q", classifyTask(kind), want)+ }+ }+ for _, unwanted := range []string{"discovered automatically", "Private review instructions."} {+ if strings.Contains(brief, unwanted) {+ t.Errorf("%v brief contains %q", classifyTask(kind), unwanted)+ }+ }+ }+}++func TestTraecliBriefDescriptionsAreSingleLineAndBounded(t *testing.T) {+ t.Parallel()+ for _, tc := range []struct {+ name, description, want string+ }{+ {name: "empty"},+ {+ name: "multiline markdown",+ description: "Use `reviews`\r\nfor **code**.\t",+ want: " — Use \\`reviews\\` for \\*\\*code\\*\\*.",+ },+ {+ name: "long unicode",+ description: strings.Repeat("审", 241) + "omitted",+ want: " — " + strings.Repeat("审", 239) + "…",+ },+ } {+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ brief := buildMetaSkillContent("traecli", TaskContextForEnv{AgentSkills: []SkillContextForEnv{+ {Name: "Review", Description: tc.description},+ }})+ want := "- **review**" + tc.want + " (file: `.traecli/skills/review/SKILL.md`)\n"+ if !strings.Contains(brief, want) {+ t.Errorf("brief missing bounded, single-line skill entry %q", want)+ }+ })+ }+}++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."}},+ } {+ brief := buildMetaSkillContent("traecli", TaskContextForEnv{AgentSkills: skills})+ if strings.Contains(brief, "## Skills") || strings.Contains(brief, ".traecli/skills/") {+ t.Error("brief advertised skills without visible entries")+ }+ }+}++func TestTraecliBriefPathsMatchPreparedSkills(t *testing.T) {+ t.Parallel()+ for _, phase := range []string{"prepare", "reuse"} {+ t.Run(phase, func(t *testing.T) {+ t.Parallel()+ task := TaskContextForEnv{+ IssueID: "issue-traecli-skills",+ AgentSkills: []SkillContextForEnv{+ {+ Name: "Review", Description: "Review code.", Content: "Review body v1.",+ Files: []SkillFileContextForEnv{{Path: "references/checks.md", Content: "Checks v1."}},+ },+ {Name: "Review", Description: "Hidden description.", Content: "---\nname: hidden\ndisable-model-invocation: true\n---\n\nHidden body."},+ platformSkillFixture(),+ },+ }+ params := PrepareParams{+ WorkspacesRoot: t.TempDir(), WorkspaceID: "workspace-traecli-skills",+ TaskID: "task-traecli-skills", Provider: "traecli", Task: task,+ }+ workDir := t.TempDir()+ if phase == "reuse" {+ initial := params+ initial.Task.AgentSkills = nil+ env, err := Prepare(initial, testLogger())+ if err != nil {+ t.Fatal(err)+ }+ defer env.Cleanup(true)+ workDir = env.WorkDir+ }+ const userSkill = "User-owned skill."+ for _, name := range []string{"review", "multica-platform"} {+ mustWrite(t, filepath.Join(workDir, ".traecli", "skills", name, "SKILL.md"), userSkill)+ }+ var env *Environment+ if phase == "prepare" {+ params.LocalWorkDir = workDir+ var err error+ env, err = Prepare(params, testLogger())+ if err != nil {+ t.Fatal(err)+ }+ defer env.Cleanup(true)+ } else {+ reuse := ReuseParams{+ WorkspacesRoot: params.WorkspacesRoot, WorkDir: workDir, Provider: "traecli", Task: task,+ }+ if Reuse(reuse, testLogger()) == nil {+ t.Fatal("initial Reuse returned nil")+ }+ task.AgentSkills[0].Content = "Review body v2."+ task.AgentSkills[0].Files[0].Content = "Checks v2."+ reuse.Task = task+ env = Reuse(reuse, testLogger())+ if env == nil {+ t.Fatal("Reuse returned nil")+ }+ }+ brief, err := InjectRuntimeConfig(workDir, "traecli", ApplyPreparedSkillNames(task, env.PreparedSkillNames))+ if err != nil {+ t.Fatal(err)+ }+ for i, name := range []string{"review-multica", "review-multica-multica", "multica-platform-multica"} {+ relPath := ".traecli/skills/" + name + "/SKILL.md"+ data, err := os.ReadFile(filepath.Join(workDir, filepath.FromSlash(relPath)))+ if err != nil {+ t.Fatal(err)+ }+ if i == 1 {+ if strings.Contains(brief, name) || strings.Contains(brief, "Hidden description.") {+ t.Error("brief advertised a hidden skill")+ }+ continue+ }+ if !strings.Contains(brief, fmt.Sprintf("(file: `%s`)", relPath)) {+ t.Errorf("brief does not point at actual skill %q", relPath)+ }+ if i == 0 && !strings.Contains(string(data), task.AgentSkills[0].Content) {+ t.Errorf("skill body is stale: %s", data)+ }+ }+ if !strings.Contains(brief, "read `.traecli/skills/multica-platform-multica/SKILL.md`") {+ t.Error("platform hint does not follow its allocated skill path")+ }+ ref, err := os.ReadFile(filepath.Join(workDir, ".traecli", "skills", "review-multica", "references", "checks.md"))+ if err != nil || string(ref) != task.AgentSkills[0].Files[0].Content {+ t.Errorf("supporting reference = %q, error = %v", ref, err)+ }+ for _, name := range []string{"review", "multica-platform"} {+ data, err := os.ReadFile(filepath.Join(workDir, ".traecli", "skills", name, "SKILL.md"))+ if err != nil || string(data) != userSkill {+ t.Errorf("user-owned skill %q changed: %q, error = %v", name, data, err)+ }+ }+ })+ }+}