| 1 | package serve |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | |
| 6 | "reasonix/internal/control" |
| 7 | "reasonix/internal/i18n" |
| 8 | "reasonix/internal/skill" |
| 9 | ) |
| 10 | |
| 11 | type commandCatalogEntry struct { |
| 12 | Name string `json:"name"` |
| 13 | Description string `json:"description"` |
| 14 | Hint string `json:"hint,omitempty"` |
| 15 | Kind string `json:"kind"` |
| 16 | Group string `json:"group,omitempty"` |
| 17 | Plugin string `json:"plugin,omitempty"` |
| 18 | Color string `json:"color,omitempty"` |
| 19 | } |
| 20 | |
| 21 | // commands publishes the active Serve controller's slash catalog. Remote |
| 22 | // desktop composers must not read commands from whichever local tab happens |
| 23 | // to be active on the client machine. |
| 24 | func (s *Server) commands(w http.ResponseWriter, _ *http.Request) { |
| 25 | ctrl := s.ctl() |
| 26 | commands, skills := ctrl.Commands(), ctrl.SlashSkills() |
| 27 | out := []commandCatalogEntry{ |
| 28 | {Name: "new", Description: i18n.M.CmdNew, Kind: "builtin", Group: "actions"}, |
| 29 | {Name: "clear", Description: i18n.M.CmdClear, Kind: "builtin", Group: "actions"}, |
| 30 | {Name: "compact", Description: i18n.M.CmdCompact, Kind: "builtin", Group: "actions"}, |
| 31 | {Name: "model", Description: i18n.M.CmdModel, Kind: "builtin", Group: "actions"}, |
| 32 | {Name: "provider", Description: i18n.M.CmdProvider, Kind: "builtin", Group: "management"}, |
| 33 | {Name: "effort", Description: i18n.M.CmdEffort, Kind: "builtin", Group: "actions"}, |
| 34 | {Name: "memory", Description: i18n.M.CmdMemory, Kind: "builtin", Group: "management"}, |
| 35 | {Name: "migrate", Description: i18n.M.CmdMigrate, Kind: "builtin", Group: "management"}, |
| 36 | {Name: "goal", Description: i18n.M.CmdGoal, Kind: "builtin", Group: "actions"}, |
| 37 | {Name: "remember", Description: i18n.M.CmdRemember, Kind: "builtin", Group: "management"}, |
| 38 | {Name: "mcp", Description: i18n.M.CmdMcp, Kind: "builtin", Group: "integrations"}, |
| 39 | {Name: "hooks", Description: i18n.M.CmdHooks, Kind: "builtin", Group: "management"}, |
| 40 | {Name: "plugins", Description: i18n.M.CmdPlugins, Kind: "builtin", Group: "integrations"}, |
| 41 | {Name: "skill", Description: i18n.M.CmdSkill, Kind: "builtin", Group: "skills"}, |
| 42 | {Name: "reload-cmd", Description: i18n.M.CmdReloadCmd, Kind: "builtin", Group: "management"}, |
| 43 | {Name: control.ResolvedBuiltinSlashName(control.DocsSlashName, commands, skills), Description: i18n.M.CmdDocs, Hint: "<question>", Kind: "builtin", Group: "integrations"}, |
| 44 | } |
| 45 | for _, sk := range skills { |
| 46 | kind, group := "skill", "skills" |
| 47 | if sk.RunAs == skill.RunSubagent { |
| 48 | kind, group = "subagent", "subagents" |
| 49 | } |
| 50 | out = append(out, commandCatalogEntry{Name: sk.SlashName(), Description: sk.Description, Kind: kind, Group: group, Plugin: sk.Plugin, Color: sk.Color}) |
| 51 | } |
| 52 | for _, command := range commands { |
| 53 | if !command.Hidden { |
| 54 | out = append(out, commandCatalogEntry{Name: command.Name, Description: command.Description, Hint: command.ArgHint, Kind: "custom", Group: "skills", Plugin: command.Plugin}) |
| 55 | } |
| 56 | } |
| 57 | if host := ctrl.Host(); host != nil { |
| 58 | for _, prompt := range host.Prompts() { |
| 59 | out = append(out, commandCatalogEntry{Name: prompt.Name, Description: prompt.Description, Kind: "mcp", Group: "integrations"}) |
| 60 | } |
| 61 | } |
| 62 | writeJSON(w, out) |
| 63 | } |
| 64 |