MCPcopy Create free account
hub / github.com/diillson/chatcli / GetTopCommands

Method GetTopCommands

cli/workspace/memory/patterns.go:133–156  ·  view source on GitHub ↗

GetTopCommands returns the N most used commands.

(n int)

Source from the content-addressed store, hash-verified

131
132// GetTopCommands returns the N most used commands.
133func (pd *PatternDetector) GetTopCommands(n int) []string {
134 pd.mu.RLock()
135 defer pd.mu.RUnlock()
136
137 type cmdCount struct {
138 cmd string
139 count int
140 }
141 cmds := make([]cmdCount, 0, len(pd.stats.CommandFrequency))
142 for c, count := range pd.stats.CommandFrequency {
143 cmds = append(cmds, cmdCount{c, count})
144 }
145 sort.Slice(cmds, func(i, j int) bool {
146 return cmds[i].count > cmds[j].count
147 })
148 if n > len(cmds) {
149 n = len(cmds)
150 }
151 result := make([]string, n)
152 for i := 0; i < n; i++ {
153 result[i] = cmds[i].cmd
154 }
155 return result
156}
157
158// FormatForPrompt returns a concise usage summary.
159func (pd *PatternDetector) FormatForPrompt() string {

Callers 1

showMemoryStatsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected