Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions components/backend/handlers/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -542,16 +544,51 @@ func ContentWorkflowMetadata(c *gin.Context) {
displayName = commandName
}

// Extract short command (last segment after final dot)
shortCommand := commandName
if lastDot := strings.LastIndex(commandName, "."); lastDot != -1 {
shortCommand = commandName[lastDot+1:]
}

// Parse order field from frontmatter, default to MaxInt32 for unordered commands
order := int(^uint(0) >> 1) // MaxInt
if orderStr := metadata["order"]; orderStr != "" {
if parsed, err := strconv.Atoi(orderStr); err == nil {
order = parsed
}
}

// Use full command name as slash command (e.g., /speckit.rfe.start)
commands = append(commands, map[string]interface{}{
"id": commandName,
"name": displayName,
"description": metadata["description"],
"slashCommand": "/" + commandName,
"icon": metadata["icon"],
"order": order,
})
}
}

// Sort commands by order field (ascending)
sort.Slice(commands, func(i, j int) bool {
iOrder, iOk := commands[i]["order"].(int)
jOrder, jOk := commands[j]["order"].(int)
if !iOk {
iOrder = int(^uint(0) >> 1) // MaxInt
}
if !jOk {
jOrder = int(^uint(0) >> 1) // MaxInt
}
// If orders are equal, sort alphabetically by id for consistent ordering
if iOrder == jOrder {
iID, _ := commands[i]["id"].(string)
jID, _ := commands[j]["id"].(string)
return iID < jID
}
return iOrder < jOrder
})

log.Printf("ContentWorkflowMetadata: found %d commands", len(commands))
} else {
log.Printf("ContentWorkflowMetadata: commands directory not found or unreadable: %v", err)
Expand Down