mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-05 13:29:44 +02:00
* feat(agents): rewrite template catalog as 25 lightweight starters Replaces every Phase-1 template with a curated set built around the "persona + intake + scaffold + hard negatives" instruction shape. Cross- platform survey (Cursor / Cline / Roo / Continue / Custom GPTs) showed the industry baseline for starter agents is "few but sharp" — single intent, no methodology buy-in, mostly prompt-only. The original catalog went the opposite direction (avg 2.5 skills, six-skill Full-stack methodology stack) and felt heavy for first-time use. Catalog shape: - 25 templates across 7 categories: Engineering (8), Product (4), Writing (5), Design (3), Communication (2), Team (1), Productivity (2). New Product / Design / Communication / Team domains fill gaps the old Eng-heavy catalog ignored. - 16 / 25 are prompt-only (no skill fan-out). Avg 0.56 skill per template vs. 2.5 prior. Heaviest is 2 skills, only for templates whose intent cannot be expressed in instructions alone (Playwright runner, single- file HTML bundlers, design + UX-guidelines pair). - Universal top-frequency intents that the old catalog missed are now covered: Code Explainer (intent #1 across every platform surveyed), Translator (中英), Summarizer, Writing Critic, PRD Drafter/Critic, RCA Writer, ADR Writer, PR Description Writer, Commit Message Writer. Loader allows 0-skill templates: - server/internal/agenttmpl/loader.go drops the "must declare at least one skill" validation; comment explains the picker's "Prompt only" rendering path. - loader_test.go: removed the corresponding negative case, added TestLoadFromFS_PromptOnlyTemplate as a regression guard. - agent_template.go handler is unchanged — every len(tmpl.Skills) call site was already 0-safe (empty fan-out short-circuits the fetch phase and the in-tx loop both skip cleanly). Frontend: - template-picker.tsx: 18 new lucide icons (BookOpen, Bug, GitPullRequest, GitCommit, AlertTriangle, Scale, ClipboardList, Microscope, UserRound, Target, Highlighter, Languages, AlignLeft, GraduationCap, Lightbulb, Type, MessageSquare, Briefcase). Card renders a "Prompt only" badge when skills.length === 0 instead of "0 skills". - template-detail.tsx: skill list section is hidden entirely for prompt- only templates — a header reading "Includes 0 skills" above an empty list was just visual noise. Instructions section below carries the agent's identity for these. - locales/en + zh-Hans agents.json: new create_dialog.template_card. prompt_only key ("Prompt only" / "纯指令"). Verification: - go test ./internal/agenttmpl/ — 9/9 pass, including TestLoad_RealTemplates which fails closed if any new JSON is malformed. - pnpm typecheck — all 6 packages clean. - pnpm --filter @multica/views test — 482/482 pass. - pnpm lint — 0 errors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(agents): add category filter pills to template picker 25 templates across 7 categories made the picker scroll-heavy on first open. Add a single-select category filter row above the grid so a PM can isolate Product templates in one click, an engineer can jump straight to Engineering, etc. Visual reuses the IssuesHeader scope-toggle pattern verbatim — Button variant="outline" + active class swap (bg-accent / text-muted-foreground) — so the affordance reads the same as the existing filter pills in issues / squads / runtimes / my-issues. flex-wrap keeps the 8 pills (All + 7 categories) honest on narrow widths. Counts are inlined into the label ("Engineering (8)") rather than shown as a separate badge — single-line-tall pills look right next to the picker grid, and surfacing the per-category density up front doubles as a hint at the catalog's "less but sharper" intent. When a specific category is active, the grid renders flat (no section headers) — the active pill already names what's on screen, and a header reading "Engineering" above an only-Engineering grid is visual duplication. "All" falls back to the prior grouped layout. State is component-local (no URL sync, no persistence) since the picker is dialog-internal transient state — closing the dialog naturally resets the filter, which is the expected behaviour for a "choose from a catalog" surface. i18n: new `create_dialog.template_picker.filter_all` key in en + zh. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
169 lines
4.9 KiB
Go
169 lines
4.9 KiB
Go
package agenttmpl
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"testing/fstest"
|
|
)
|
|
|
|
func TestLoad_RealTemplates(t *testing.T) {
|
|
// Exercises the production go:embed path. If a real template file is
|
|
// malformed in main, this test fails — the same failure server boot would
|
|
// hit, but in CI before merge.
|
|
reg, err := Load()
|
|
if err != nil {
|
|
t.Fatalf("Load(): %v", err)
|
|
}
|
|
if len(reg.List()) == 0 {
|
|
t.Fatal("expected at least one bundled template, got none")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromFS_Valid(t *testing.T) {
|
|
fsys := fstest.MapFS{
|
|
"templates/alpha.json": &fstest.MapFile{Data: []byte(`{
|
|
"slug": "alpha",
|
|
"name": "Alpha",
|
|
"description": "first",
|
|
"instructions": "do alpha",
|
|
"skills": [{"source_url": "https://github.com/x/y/tree/main/skills/z"}]
|
|
}`)},
|
|
"templates/beta.json": &fstest.MapFile{Data: []byte(`{
|
|
"slug": "beta",
|
|
"name": "Beta",
|
|
"description": "second",
|
|
"instructions": "do beta",
|
|
"skills": [{"source_url": "https://github.com/x/y/tree/main/skills/q"}]
|
|
}`)},
|
|
}
|
|
|
|
reg, err := loadFromFS(fsys, "templates")
|
|
if err != nil {
|
|
t.Fatalf("loadFromFS: %v", err)
|
|
}
|
|
if got, want := len(reg.List()), 2; got != want {
|
|
t.Fatalf("List() len = %d, want %d", got, want)
|
|
}
|
|
// List() must be deterministic (sorted by filename).
|
|
if reg.List()[0].Slug != "alpha" {
|
|
t.Errorf("List()[0].Slug = %q, want alpha", reg.List()[0].Slug)
|
|
}
|
|
if _, ok := reg.Get("alpha"); !ok {
|
|
t.Errorf("Get(alpha) = false, want true")
|
|
}
|
|
if _, ok := reg.Get("nope"); ok {
|
|
t.Errorf("Get(nope) = true, want false")
|
|
}
|
|
}
|
|
|
|
func TestLoadFromFS_Invalid(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
content string
|
|
wantErr string
|
|
}{
|
|
{
|
|
name: "bad json",
|
|
content: `{not json`,
|
|
wantErr: "parse",
|
|
},
|
|
{
|
|
name: "missing slug",
|
|
content: `{"name": "X", "instructions": "do", "skills": [{"source_url":"u"}]}`,
|
|
wantErr: "missing slug",
|
|
},
|
|
{
|
|
name: "slug mismatches filename",
|
|
content: `{"slug":"other","name":"X","instructions":"do","skills":[{"source_url":"u"}]}`,
|
|
wantErr: "does not match filename",
|
|
},
|
|
{
|
|
name: "bad slug",
|
|
content: `{"slug":"Bad_Slug","name":"X","instructions":"do","skills":[{"source_url":"u"}]}`,
|
|
wantErr: "kebab-case",
|
|
},
|
|
{
|
|
name: "missing name",
|
|
content: `{"slug":"x","instructions":"do","skills":[{"source_url":"u"}]}`,
|
|
wantErr: "missing name",
|
|
},
|
|
{
|
|
name: "missing instructions",
|
|
content: `{"slug":"x","name":"X","skills":[{"source_url":"u"}]}`,
|
|
wantErr: "missing instructions",
|
|
},
|
|
{
|
|
name: "skill missing url",
|
|
content: `{"slug":"x","name":"X","instructions":"do","skills":[{}]}`,
|
|
wantErr: "missing source_url",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
filename := "x.json"
|
|
if tc.name == "slug mismatches filename" {
|
|
filename = "x.json" // slug is "other", file is "x.json" → mismatch
|
|
}
|
|
fsys := fstest.MapFS{
|
|
"templates/" + filename: &fstest.MapFile{Data: []byte(tc.content)},
|
|
}
|
|
_, err := loadFromFS(fsys, "templates")
|
|
if err == nil {
|
|
t.Fatalf("expected error containing %q, got nil", tc.wantErr)
|
|
}
|
|
if !strings.Contains(err.Error(), tc.wantErr) {
|
|
t.Errorf("error = %v, want substring %q", err, tc.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLoadFromFS_PromptOnlyTemplate(t *testing.T) {
|
|
// 0-skill templates are legitimate. Most starter templates ship prompt-only
|
|
// (no skill fan-out, just an instructions block). Regression guard so the
|
|
// "must declare at least one skill" rule doesn't sneak back in.
|
|
fsys := fstest.MapFS{
|
|
"templates/prompt-only.json": &fstest.MapFile{Data: []byte(`{
|
|
"slug":"prompt-only",
|
|
"name":"Prompt Only",
|
|
"description":"no skills here",
|
|
"instructions":"just write good prose",
|
|
"skills":[]
|
|
}`)},
|
|
}
|
|
reg, err := loadFromFS(fsys, "templates")
|
|
if err != nil {
|
|
t.Fatalf("loadFromFS: %v", err)
|
|
}
|
|
tmpl, ok := reg.Get("prompt-only")
|
|
if !ok {
|
|
t.Fatal("Get(prompt-only) = false, want true")
|
|
}
|
|
if len(tmpl.Skills) != 0 {
|
|
t.Errorf("len(Skills) = %d, want 0", len(tmpl.Skills))
|
|
}
|
|
}
|
|
|
|
func TestLoadFromFS_DuplicateSlug(t *testing.T) {
|
|
// Two valid files declaring the same slug — caught by the registry, not
|
|
// by validate(). Slugs are unique within the registry.
|
|
fsys := fstest.MapFS{
|
|
"templates/a.json": &fstest.MapFile{Data: []byte(`{
|
|
"slug":"a","name":"A","instructions":"do","skills":[{"source_url":"u"}]
|
|
}`)},
|
|
"templates/b.json": &fstest.MapFile{Data: []byte(`{
|
|
"slug":"a","name":"A2","instructions":"do","skills":[{"source_url":"u"}]
|
|
}`)},
|
|
}
|
|
_, err := loadFromFS(fsys, "templates")
|
|
if err == nil || !strings.Contains(err.Error(), "duplicate slug") {
|
|
// Note: this test will fail validation first (slug "a" vs filename
|
|
// "b.json") because we check filename-slug match before duplicate.
|
|
// That's fine — both are errors. Adjust expectation:
|
|
if err == nil || !strings.Contains(err.Error(), "does not match filename") {
|
|
t.Errorf("expected duplicate slug or filename mismatch, got %v", err)
|
|
}
|
|
}
|
|
}
|