Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(skills): quote description values in built-in SKILL.md YAML frontmatter (#3852)
HMYDK4190de3d6484
diff --git a/server/internal/daemon/execenv/context.go b/server/internal/daemon/execenv/context.goindex aa190b5fdb..eb00573bc0 100644--- a/server/internal/daemon/execenv/context.go+++ b/server/internal/daemon/execenv/context.go@@ -9,6 +9,7 @@ import ("strings"skillpkg "github.com/multica-ai/multica/server/internal/skill"+ "gopkg.in/yaml.v3")// writeContextFiles renders and writes .agent_context/issue_context.md and@@ -233,9 +234,12 @@ var nonAlphaNum = regexp.MustCompile(`[^a-z0-9]+`)//// - No frontmatter at all → synthesize one with `name: <slug>` (and the DB// description when available).-// - Frontmatter present and already has a non-empty `name` → leave it-// untouched. The upstream import may have shaped that block deliberately-// to match a specific runtime, and we don't want to clobber it.+// - Frontmatter present, has a non-empty `name`, AND parses as valid YAML →+// leave it untouched. The upstream import may have shaped that block+// deliberately to match a specific runtime, and we don't want to clobber it.+// - Frontmatter present and has a non-empty `name` but YAML is invalid (e.g.+// unquoted colon in description) → strip and re-synthesize so runtimes like+// Codex don't discard the skill on parse errors.// - Frontmatter present but missing `name` (e.g. an upstream skill whose// YAML only set `description`, with the directory slug filling in for// `name` at import time) → prepend `name: <slug>` as the first key of@@ -243,18 +247,22 @@ var nonAlphaNum = regexp.MustCompile(`[^a-z0-9]+`)func ensureSkillFrontmatter(content, slug, description string) string {fmStart, ok := frontmatterBodyStart(content)if !ok {- var b strings.Builder- b.WriteString("---\n")- fmt.Fprintf(&b, "name: %s\n", slug)- if d := strings.TrimSpace(description); d != "" {- fmt.Fprintf(&b, "description: %s\n", yamlEscapeInline(d))- }- b.WriteString("---\n\n")- b.WriteString(content)- return b.String()+ return synthesizeFrontmatter(content, slug, description)}+ // Frontmatter exists and has a parseable name. If it's valid YAML, leave+ // it untouched so upstream-imported frontmatter survives round-trips.if hasFrontmatterName(content[fmStart:]) {- return content+ if isFrontmatterValidYAML(content) {+ return content+ }+ // Frontmatter has a name but the YAML is invalid (e.g. unquoted+ // colon in the description). Strip and re-synthesize so runtimes+ // like Codex don't hard-reject the whole skill at load time.+ // frontmatterParts returns the full content as the body when it+ // can't find a closing delimiter, so the malformed block is kept+ // rather than silently dropped.+ _, body, _ := frontmatterParts(content)+ return synthesizeFrontmatter(body, slug, description)}// Frontmatter exists but lacks a parseable `name`. Inject one as the// first key of the existing block and keep the rest verbatim (including@@ -263,6 +271,73 @@ func ensureSkillFrontmatter(content, slug, description string) string {return content[:fmStart] + "name: " + slug + "\n" + content[fmStart:]}+// synthesizeFrontmatter produces a SKILL.md body with a YAML frontmatter block+// carrying at least `name` and (when non-empty) `description`. The description+// is always escaped as a double-quoted YAML string so values containing colons,+// brackets, or other YAML-significant characters parse safely.+func synthesizeFrontmatter(body, slug, description string) string {+ var b strings.Builder+ b.WriteString("---\n")+ fmt.Fprintf(&b, "name: %s\n", slug)+ if d := strings.TrimSpace(description); d != "" {+ fmt.Fprintf(&b, "description: %s\n", yamlEscapeInline(d))+ }+ b.WriteString("---\n\n")+ b.WriteString(body)+ return b.String()+}++// isFrontmatterValidYAML reports whether the opening YAML frontmatter block of+// content parses as a YAML mapping. Returns false when there is no frontmatter,+// the block has no closing delimiter, is empty, or unmarshalling fails.+func isFrontmatterValidYAML(content string) bool {+ fmBody, _, ok := frontmatterParts(content)+ if !ok || strings.TrimSpace(fmBody) == "" {+ return false+ }+ var m map[string]any+ return yaml.Unmarshal([]byte(fmBody), &m) == nil+}++// frontmatterParts splits content into the raw YAML frontmatter body (the text+// between the opening `---` line and the closing `---` line) and the document+// body that follows the closing delimiter. ok is false when content has no+// opening delimiter or no closing delimiter line; in that case body is the full+// content so callers can keep a malformed block instead of dropping it.+//+// A closing delimiter is a line whose only content is `---`, terminated by+// `\n`, `\r\n`, or end-of-file. Centralizing the rule here keeps the validity+// check and the re-synthesis path from disagreeing on where a block ends (e.g.+// for EOF- or CRLF-terminated frontmatter), which previously left a stale block+// behind when the two definitions diverged.+func frontmatterParts(content string) (fmBody, body string, ok bool) {+ start, ok := frontmatterBodyStart(content)+ if !ok {+ return "", content, false+ }+ rest := content[start:]+ for searchFrom := 0; ; {+ nl := strings.Index(rest[searchFrom:], "\n---")+ if nl < 0 {+ return "", content, false+ }+ closeAt := searchFrom + nl+ after := rest[closeAt+len("\n---"):]+ switch {+ case after == "" || after == "\r":+ return rest[:closeAt], "", true+ case strings.HasPrefix(after, "\n"):+ return rest[:closeAt], after[len("\n"):], true+ case strings.HasPrefix(after, "\r\n"):+ return rest[:closeAt], after[len("\r\n"):], true+ default:+ // Not a standalone delimiter line (e.g. "----" or "--- text");+ // keep scanning for the real close.+ searchFrom = closeAt + len("\n---")+ }+ }+}+// frontmatterBodyStart returns the byte offset where the YAML body begins// (just after the opening `---` line) and whether a valid opening delimiter// was found.diff --git a/server/internal/daemon/execenv/skill_frontmatter_test.go b/server/internal/daemon/execenv/skill_frontmatter_test.gonew file mode 100644index 0000000000..7a6a89cdb1--- /dev/null+++ b/server/internal/daemon/execenv/skill_frontmatter_test.go@@ -0,0 +1,161 @@+package execenv++import (+ "strings"+ "testing"++ "gopkg.in/yaml.v3"+)++// parseFrontmatter is a strict YAML parse of a SKILL.md frontmatter block, used+// by the tests to assert the writer always emits something a strict runtime+// (e.g. Codex) can load. It mirrors how those runtimes read the file: take the+// text between the leading `---` and the next `---`, and yaml.Unmarshal it.+func parseFrontmatter(t *testing.T, content string) map[string]any {+ t.Helper()+ if !strings.HasPrefix(content, "---\n") {+ t.Fatalf("content does not start with a frontmatter block:\n%s", content)+ }+ rest := content[len("---\n"):]+ end := strings.Index(rest, "\n---")+ if end < 0 {+ t.Fatalf("frontmatter has no closing delimiter:\n%s", content)+ }+ var m map[string]any+ if err := yaml.Unmarshal([]byte(rest[:end]), &m); err != nil {+ t.Fatalf("frontmatter is not valid YAML: %v\nblock:\n%s", err, rest[:end])+ }+ return m+}++// TestEnsureSkillFrontmatterReSynthesizesInvalidYAML is the regression guard for+// the bug this change set fixes: a SKILL.md whose frontmatter has a `name` but+// is not valid YAML (an unquoted `: ` in the description is the canonical case)+// must be rewritten into a parseable block instead of being shipped as-is, or a+// strict runtime drops the whole skill on load.+func TestEnsureSkillFrontmatterReSynthesizesInvalidYAML(t *testing.T) {+ t.Parallel()++ const body = "# Heading\n\nReal skill body.\n"+ // `description: bad: value` is the exact failure mode from the issue: the+ // second `: ` makes YAML treat the tail as a nested mapping.+ broken := "---\nname: keep-me\ndescription: bad: value here\n---\n\n" + body++ got := ensureSkillFrontmatter(broken, "my-slug", "DB description: with a colon")++ fm := parseFrontmatter(t, got)+ if name, _ := fm["name"].(string); name != "my-slug" {+ t.Errorf("name = %#v, want %q", fm["name"], "my-slug")+ }+ if desc, _ := fm["description"].(string); desc != "DB description: with a colon" {+ t.Errorf("description = %#v, want the DB description verbatim", fm["description"])+ }+ if !strings.Contains(got, "Real skill body.") {+ t.Errorf("body was dropped during re-synthesis:\n%s", got)+ }+}++// When the existing frontmatter is invalid AND the DB description is empty, the+// writer still has to produce parseable YAML — just with name alone. (An empty+// description is dropped rather than emitted as `description: ""`.)+func TestEnsureSkillFrontmatterReSynthesizesInvalidYAMLWithEmptyDescription(t *testing.T) {+ t.Parallel()++ broken := "---\nname: keep-me\ndescription: bad: value\n---\n\nbody text\n"++ got := ensureSkillFrontmatter(broken, "my-slug", "")++ fm := parseFrontmatter(t, got)+ if name, _ := fm["name"].(string); name != "my-slug" {+ t.Errorf("name = %#v, want %q", fm["name"], "my-slug")+ }+ if _, present := fm["description"]; present {+ t.Errorf("description should be omitted when DB description is empty, got %#v", fm["description"])+ }+ if !strings.Contains(got, "body text") {+ t.Errorf("body was dropped during re-synthesis:\n%s", got)+ }+}++// Valid frontmatter that already carries a name must survive untouched —+// re-synthesis is only for the broken case, so upstream import formatting is+// preserved on the happy path.+func TestEnsureSkillFrontmatterLeavesValidYAMLUntouched(t *testing.T) {+ t.Parallel()++ valid := "---\nname: upstream\ndescription: \"colon: safe because quoted\"\nextra-key: kept\n---\n\nbody\n"++ if got := ensureSkillFrontmatter(valid, "my-slug", "ignored"); got != valid {+ t.Errorf("valid frontmatter was rewritten;\n got: %q\nwant: %q", got, valid)+ }+}++// frontmatterParts must agree on where a block ends regardless of how the+// closing delimiter is terminated. Before the shared helper, the validity check+// and the strip path used different close patterns (`\n---` vs `\n---\n`), so an+// EOF- or CRLF-terminated block was detected as present by one and missed by the+// other — leaving a stale block behind on re-synthesis.+func TestFrontmatterPartsClosingDelimiterVariants(t *testing.T) {+ t.Parallel()++ cases := []struct {+ name string+ content string+ wantFM string+ wantBody string+ wantOK bool+ }{+ {+ name: "newline terminated with blank line",+ content: "---\nname: x\n---\n\nbody",+ wantFM: "name: x",+ wantBody: "\nbody",+ wantOK: true,+ },+ {+ name: "closing delimiter at EOF",+ content: "---\nname: x\n---",+ wantFM: "name: x",+ wantBody: "",+ wantOK: true,+ },+ {+ name: "crlf terminated",+ content: "---\r\nname: x\r\n---\r\nbody",+ wantFM: "name: x\r",+ wantBody: "body",+ wantOK: true,+ },+ {+ name: "horizontal rule is not a delimiter",+ content: "---\nname: x\n----\n---\nbody",+ wantFM: "name: x\n----",+ wantBody: "body",+ wantOK: true,+ },+ {+ name: "no closing delimiter keeps full content as body",+ content: "---\nname: x\nbody without close",+ wantFM: "",+ wantBody: "---\nname: x\nbody without close",+ wantOK: false,+ },+ {+ name: "no opening delimiter",+ content: "no frontmatter here",+ wantFM: "",+ wantBody: "no frontmatter here",+ wantOK: false,+ },+ }++ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ fm, body, ok := frontmatterParts(tc.content)+ if ok != tc.wantOK || fm != tc.wantFM || body != tc.wantBody {+ t.Errorf("frontmatterParts(%q) = (%q, %q, %v), want (%q, %q, %v)",+ tc.content, fm, body, ok, tc.wantFM, tc.wantBody, tc.wantOK)+ }+ })+ }+}diff --git a/server/internal/service/builtin_skills/multica-autopilots/SKILL.md b/server/internal/service/builtin_skills/multica-autopilots/SKILL.mdindex 20cd45112f..110788bb2e 100644--- a/server/internal/service/builtin_skills/multica-autopilots/SKILL.md+++ b/server/internal/service/builtin_skills/multica-autopilots/SKILL.md@@ -1,6 +1,6 @@---name: multica-autopilots-description: Use when creating, updating, inspecting, triggering, or debugging Multica autopilots. Covers the full chain: schedule/webhook/manual trigger, create_issue vs run_only execution, agent/squad leader admission, runs, created issues/tasks, webhook URL rotation, and side-effect boundaries.+description: "Use when creating, updating, inspecting, triggering, or debugging Multica autopilots. Covers the full chain: schedule/webhook/manual trigger, create_issue vs run_only execution, agent/squad leader admission, runs, created issues/tasks, webhook URL rotation, and side-effect boundaries."user-invocable: falseallowed-tools: Bash(multica *)---diff --git a/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md b/server/internal/service/builtin_skills/multica-creating-agents/SKILL.mdindex 32de4ae10c..7acfda8c58 100644--- a/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md+++ b/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md@@ -1,6 +1,6 @@---name: multica-creating-agents-description: Use when creating, inspecting, or debugging a Multica agent through the `multica agent` CLI or `POST /api/agents` — what each field is, its persisted shape, whether it is metadata-only or consumed by the daemon at claim time, which inputs are validated/rejected, how custom_env secrets are gated, and how skill binding behaves. Not for assigning issues to existing agents or for runtime task prompts.+description: "Use when creating, inspecting, or debugging a Multica agent through the `multica agent` CLI or `POST /api/agents` — what each field is, its persisted shape, whether it is metadata-only or consumed by the daemon at claim time, which inputs are validated/rejected, how custom_env secrets are gated, and how skill binding behaves. Not for assigning issues to existing agents or for runtime task prompts."user-invocable: falseallowed-tools: Bash(multica *)---diff --git a/server/internal/service/builtin_skills/multica-mentioning/SKILL.md b/server/internal/service/builtin_skills/multica-mentioning/SKILL.mdindex a306e71101..845bb0b220 100644--- a/server/internal/service/builtin_skills/multica-mentioning/SKILL.md+++ b/server/internal/service/builtin_skills/multica-mentioning/SKILL.md@@ -1,6 +1,6 @@---name: multica-mentioning-description: Use when an issue comment needs to @mention someone — link to a person, trigger another agent, hand work to a squad, or broadcast with @all. Documents the verified mention contract: how a mention link is built from a real UUID, the four mention types and exactly what each one enqueues (agent → a run for that agent, squad → a run for the squad leader, member and issue → a rendered link with NO run), the @all broadcast and how it suppresses the assignee's auto-trigger, and the silent no-op cases (a name where a UUID belongs, a bad/unknown UUID, an already-pending task, an archived agent, a private agent you cannot access). WHETHER to mention — loop avoidance, staying silent on acknowledgements — lives in the runtime brief's Mentions section, not here. This skill is the backend contract only, traced to server/internal/util/mention.go and server/internal/handler/comment.go.+description: "Use when an issue comment needs to @mention someone — link to a person, trigger another agent, hand work to a squad, or broadcast with @all. Documents the verified mention contract: how a mention link is built from a real UUID, the four mention types and exactly what each one enqueues (agent → a run for that agent, squad → a run for the squad leader, member and issue → a rendered link with NO run), the @all broadcast and how it suppresses the assignee's auto-trigger, and the silent no-op cases (a name where a UUID belongs, a bad/unknown UUID, an already-pending task, an archived agent, a private agent you cannot access). WHETHER to mention — loop avoidance, staying silent on acknowledgements — lives in the runtime brief's Mentions section, not here. This skill is the backend contract only, traced to server/internal/util/mention.go and server/internal/handler/comment.go."user-invocable: falseallowed-tools: Bash(multica *)---diff --git a/server/internal/service/builtin_skills/multica-projects-and-resources/SKILL.md b/server/internal/service/builtin_skills/multica-projects-and-resources/SKILL.mdindex 3069a95a8d..2d126861c2 100644--- a/server/internal/service/builtin_skills/multica-projects-and-resources/SKILL.md+++ b/server/internal/service/builtin_skills/multica-projects-and-resources/SKILL.md@@ -1,6 +1,6 @@---name: multica-projects-and-resources-description: Use when creating, inspecting, updating, or debugging Multica projects and project resources. Covers durable project context, github_repo and local_directory resources, how resources affect future agent task context, when to bind repos, and when not to mutate resources.+description: "Use when creating, inspecting, updating, or debugging Multica projects and project resources. Covers durable project context, github_repo and local_directory resources, how resources affect future agent task context, when to bind repos, and when not to mutate resources."user-invocable: falseallowed-tools: Bash(multica *)---diff --git a/server/internal/service/builtin_skills/multica-runtimes-and-repos/SKILL.md b/server/internal/service/builtin_skills/multica-runtimes-and-repos/SKILL.mdindex 70ef44b7d9..6ff2e58119 100644--- a/server/internal/service/builtin_skills/multica-runtimes-and-repos/SKILL.md+++ b/server/internal/service/builtin_skills/multica-runtimes-and-repos/SKILL.md@@ -1,6 +1,6 @@---name: multica-runtimes-and-repos-description: Use when inspecting or debugging Multica runtimes, daemon task claiming, agent not running, workdir/session reuse, or repository checkout. Covers runtime online/offline state, daemon heartbeat/claim chain, task-scoped repo checkout, project repo context, local_directory caveats, and safe diagnostic commands.+description: "Use when inspecting or debugging Multica runtimes, daemon task claiming, agent not running, workdir/session reuse, or repository checkout. Covers runtime online/offline state, daemon heartbeat/claim chain, task-scoped repo checkout, project repo context, local_directory caveats, and safe diagnostic commands."user-invocable: falseallowed-tools: Bash(multica *)---diff --git a/server/internal/service/builtin_skills/multica-skill-importing/SKILL.md b/server/internal/service/builtin_skills/multica-skill-importing/SKILL.mdindex afb025fc12..ce3a4887b2 100644--- a/server/internal/service/builtin_skills/multica-skill-importing/SKILL.md+++ b/server/internal/service/builtin_skills/multica-skill-importing/SKILL.md@@ -1,6 +1,6 @@---name: multica-skill-importing-description: Use when a user provides a skill URL, slug, or clear intent to import/install a specific skill into the current Multica workspace. Teaches the workspace import API/CLI path (POST /api/skills/import), the supported URL source families, the SkillWithFilesResponse shape returned on success, duplicate 409 handling with the existing_skill body, additive agent binding vs replace-all, and the reserved SKILL.md supporting-file rule. Do not use it to decide which skill the user needs, and never treat an external local installer like npx skills add as the final Multica install.+description: "Use when a user provides a skill URL, slug, or clear intent to import/install a specific skill into the current Multica workspace. Teaches the workspace import API/CLI path (POST /api/skills/import), the supported URL source families, the SkillWithFilesResponse shape returned on success, duplicate 409 handling with the existing_skill body, additive agent binding vs replace-all, and the reserved SKILL.md supporting-file rule. Do not use it to decide which skill the user needs, and never treat an external local installer like npx skills add as the final Multica install."user-invocable: falseallowed-tools: Bash(multica *)---diff --git a/server/internal/service/builtin_skills/multica-squads/SKILL.md b/server/internal/service/builtin_skills/multica-squads/SKILL.mdindex 401d386e7a..39f1fb75c6 100644--- a/server/internal/service/builtin_skills/multica-squads/SKILL.md+++ b/server/internal/service/builtin_skills/multica-squads/SKILL.md@@ -1,6 +1,6 @@---name: multica-squads-description: Use when creating, inspecting, updating, assigning, mentioning, or debugging Multica squads. Explains what squads are, squad/member fields, CLI commands, leader routing, issue assignment, comments, mentions, autopilot behavior, leader briefing, side effects, and product-gap handling.+description: "Use when creating, inspecting, updating, assigning, mentioning, or debugging Multica squads. Explains what squads are, squad/member fields, CLI commands, leader routing, issue assignment, comments, mentions, autopilot behavior, leader briefing, side effects, and product-gap handling."user-invocable: falseallowed-tools: Bash(multica *)---diff --git a/server/internal/service/builtin_skills/multica-working-on-issues/SKILL.md b/server/internal/service/builtin_skills/multica-working-on-issues/SKILL.mdindex 7b934322e3..31002027e4 100644--- a/server/internal/service/builtin_skills/multica-working-on-issues/SKILL.md+++ b/server/internal/service/builtin_skills/multica-working-on-issues/SKILL.md@@ -1,6 +1,6 @@---name: multica-working-on-issues-description: Use when working on a Multica issue after the runtime has provided the trigger context — to apply the product contracts the runtime brief does not encode: how PR linking differs from close intent, how to read a linked PR's real state via the pull-requests CLI, which metadata keys are high-signal, what status changes trigger on the server, and how sub-issue create status (todo vs backlog) controls whether assigned agents start immediately.+description: "Use when working on a Multica issue after the runtime has provided the trigger context — to apply the product contracts the runtime brief does not encode: how PR linking differs from close intent, how to read a linked PR's real state via the pull-requests CLI, which metadata keys are high-signal, what status changes trigger on the server, and how sub-issue create status (todo vs backlog) controls whether assigned agents start immediately."user-invocable: falseallowed-tools: Bash(multica *), Bash(git *), Bash(gh *)---diff --git a/server/internal/service/builtin_skills_test.go b/server/internal/service/builtin_skills_test.goindex 2ec71627f3..48e9f05225 100644--- a/server/internal/service/builtin_skills_test.go+++ b/server/internal/service/builtin_skills_test.go@@ -5,6 +5,7 @@ import ("testing""github.com/multica-ai/multica/server/internal/util"+ "gopkg.in/yaml.v3")// Built-in skills are the platform's standard "template" skills. These evals@@ -73,6 +74,51 @@ func TestBuiltinSkillsConformToTemplate(t *testing.T) {}}+// TestBuiltinSkillsFrontmatterIsStrictYAML is the regression guard for MUL-3100+// / GitHub #3851: a built-in SKILL.md whose frontmatter is not valid YAML 1.2+// (the canonical break is an unquoted `: ` inside the description) is silently+// dropped by strict runtimes like Codex, so the agent runs without that+// platform-contract skill.+//+// This check is deliberately separate from TestBuiltinSkillsConformToTemplate:+// that test reads the frontmatter through splitFrontmatter, a naive line parser+// that splits on the first ':' and never runs a YAML parse — so it passes even+// on the broken files. Only a real yaml.Unmarshal reproduces what Codex does,+// which is exactly what is needed to catch this class of bug before it ships.+func TestBuiltinSkillsFrontmatterIsStrictYAML(t *testing.T) {+ skills := loadBuiltinSkills()+ if len(skills) == 0 {+ t.Fatal("no built-in skills loaded; embed or layout is broken")+ }++ for _, skill := range skills {+ t.Run(skill.Name, func(t *testing.T) {+ content := skill.Content+ if !strings.HasPrefix(content, "---\n") {+ t.Fatalf("SKILL.md must lead with a --- frontmatter block")+ }+ rest := content[len("---\n"):]+ end := strings.Index(rest, "\n---")+ if end < 0 {+ t.Fatalf("frontmatter has no closing --- delimiter")+ }++ var fm map[string]any+ if err := yaml.Unmarshal([]byte(rest[:end]), &fm); err != nil {+ t.Fatalf("frontmatter is not valid YAML — a strict runtime (e.g. Codex) "++ "will drop this skill on load; quote values containing ': ': %v", err)+ }++ if name, ok := fm["name"].(string); !ok || strings.TrimSpace(name) == "" {+ t.Errorf("frontmatter name must parse as a non-empty string, got %#v", fm["name"])+ }+ if desc, ok := fm["description"].(string); !ok || strings.TrimSpace(desc) == "" {+ t.Errorf("frontmatter description must parse as a non-empty string, got %#v", fm["description"])+ }+ })+ }+}+// TestMentioningSkillFollowsContractFrontmatter locks the reference template:// the mentioning skill is a context-triggered platform-contract skill, so it// must declare user-invocable:false and fence itself to the multica CLI. New