feat: scoring and frecency (#37)
Enhance lookup mechanics and priority propagation (`spec/lookup.go`) Remove the requirement of typing a leading `-` when searching for options, allowing flag suggestions to surface naturally during input Accurately forward the `Priority` field from registry specs into the `Suggestion` struct so the scoring engine evaluates relevance properly Integrate scoring into the main suggestion pipeline (`root/suggestions.go`) Collect context signals using `scoring.CollectSignals(cwd, query, rootCmd, store)` with the live working directory retrieved from `spec.GetCWD()` Pass the entire deduplicated list across spec, history and AI items through `scoring.Score(deduped, signals)` to compute scores and sort by descending order before rendering on screen Record execution history in Frecency Store (`root/wrapper.go`) Save the last executed command to `lastSubmittedCommand` whenever Enter is pressed or a suggestion is selected Trigger `store.Record(...)` asynchronously within the `IRIS_CMD_STOP` hook using a dedicated goroutine guarded by panic recovery and timeout limits, preventing blocks on the main shell thread Optimize workspace identification for AI (`internal/ai/context_provider.go`) Use `workspace.DetectCached(cwd)` to instantly fetch ecosystem context across Git, Node, Go, Rust, Python and Docker alongside active git branch state This caching mechanism avoids redundant subprocess execution when outside git repositories, significantly speeding up prompt context generation
This commit is contained in:
+28
-1
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/versenilvis/iris/internal/ai"
|
||||
"github.com/versenilvis/iris/internal/config"
|
||||
"github.com/versenilvis/iris/internal/logger"
|
||||
"github.com/versenilvis/iris/internal/scoring"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
"golang.org/x/sys/unix"
|
||||
"golang.org/x/term"
|
||||
@@ -81,6 +82,7 @@ func restoreTerminal() {
|
||||
// coordinates between the shell process and the suggestion overlay
|
||||
func runWrapper() {
|
||||
var naiveBuffer string
|
||||
var lastSubmittedCommand string
|
||||
cursorOffset := 0
|
||||
var bufferMu sync.Mutex
|
||||
var userNavigated atomic.Bool
|
||||
@@ -323,6 +325,25 @@ func runWrapper() {
|
||||
if query == "IRIS_CMD_STOP" {
|
||||
isCommandActive.Store(false)
|
||||
SetCurrentAISuggestion(nil)
|
||||
bufferMu.Lock()
|
||||
cmdToRecord := lastSubmittedCommand
|
||||
lastSubmittedCommand = ""
|
||||
bufferMu.Unlock()
|
||||
if cmdToRecord != "" {
|
||||
cwd := spec.GetCWD()
|
||||
go func(c, d string) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
WriteCrashLog(r)
|
||||
}
|
||||
}()
|
||||
ctxRecord, cancel := context.WithTimeout(context.Background(), 1500*time.Millisecond)
|
||||
defer cancel()
|
||||
if store, err := scoring.GetFrecencyStore(); err == nil && store != nil {
|
||||
_ = store.Record(ctxRecord, c, d)
|
||||
}
|
||||
}(cmdToRecord, cwd)
|
||||
}
|
||||
// hook: after user executes a command, print the update notice exactly once per session
|
||||
if !updatePrinted {
|
||||
select {
|
||||
@@ -621,7 +642,7 @@ func runWrapper() {
|
||||
historyList = append(historyList, results[j])
|
||||
}
|
||||
} else {
|
||||
for j := 0; j < limit; j++ {
|
||||
for j := range limit {
|
||||
historyList = append(historyList, results[j])
|
||||
}
|
||||
}
|
||||
@@ -759,9 +780,11 @@ func runWrapper() {
|
||||
} else if b == 0x0d || b == 0x0a {
|
||||
intercepted = true
|
||||
logger.Debugf("Intercepted Enter key, navigated=%v", overlay.GetUserNavigated())
|
||||
var cmdToSubmit string
|
||||
if overlay.IsVisible() && overlay.GetUserNavigated() {
|
||||
selected := overlay.GetCurrentCmd()
|
||||
if selected != "" {
|
||||
cmdToSubmit = selected
|
||||
activeModeMu.RLock()
|
||||
currentMode := activeMode
|
||||
activeModeMu.RUnlock()
|
||||
@@ -783,6 +806,10 @@ func runWrapper() {
|
||||
isCommandActive.Store(true)
|
||||
_, _ = ptmx.Write([]byte{b})
|
||||
bufferMu.Lock()
|
||||
if cmdToSubmit == "" {
|
||||
cmdToSubmit = naiveBuffer
|
||||
}
|
||||
lastSubmittedCommand = strings.TrimSpace(cmdToSubmit)
|
||||
naiveBuffer = ""
|
||||
cursorOffset = 0
|
||||
bufferMu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user