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
93 lines
2.5 KiB
Go
93 lines
2.5 KiB
Go
package workspace
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
)
|
|
|
|
type WorkspaceInfo struct {
|
|
HasGit bool
|
|
HasNodeProject bool
|
|
HasGoProject bool
|
|
HasRustProject bool
|
|
HasPythonProject bool
|
|
HasDockerfile bool
|
|
HasMakefile bool
|
|
HasJustfile bool
|
|
HasK8s bool
|
|
SignatureFiles []string
|
|
}
|
|
|
|
var signatureChecks = []struct {
|
|
path string
|
|
field func(*WorkspaceInfo)
|
|
}{
|
|
{".git", func(w *WorkspaceInfo) { w.HasGit = true }},
|
|
{"package.json", func(w *WorkspaceInfo) { w.HasNodeProject = true }},
|
|
{"go.mod", func(w *WorkspaceInfo) { w.HasGoProject = true }},
|
|
{"Cargo.toml", func(w *WorkspaceInfo) { w.HasRustProject = true }},
|
|
{"Dockerfile", func(w *WorkspaceInfo) { w.HasDockerfile = true }},
|
|
{"Makefile", func(w *WorkspaceInfo) { w.HasMakefile = true }},
|
|
{"justfile", func(w *WorkspaceInfo) { w.HasJustfile = true }},
|
|
{"pyproject.toml", func(w *WorkspaceInfo) { w.HasPythonProject = true }},
|
|
{"requirements.txt", func(w *WorkspaceInfo) { w.HasPythonProject = true }},
|
|
{"Chart.yaml", func(w *WorkspaceInfo) { w.HasK8s = true }},
|
|
{"k8s", func(w *WorkspaceInfo) { w.HasK8s = true }},
|
|
{"kubernetes", func(w *WorkspaceInfo) { w.HasK8s = true }},
|
|
{"docker-compose.yml", func(w *WorkspaceInfo) { w.HasDockerfile = true }},
|
|
{"docker-compose.yaml", func(w *WorkspaceInfo) { w.HasDockerfile = true }},
|
|
{"Taskfile.yml", nil},
|
|
{"pom.xml", nil},
|
|
{"build.gradle", nil},
|
|
{"CMakeLists.txt", nil},
|
|
}
|
|
|
|
// Detect scans the given directory for signature files and returns workspace metadata
|
|
func Detect(cwd string) WorkspaceInfo {
|
|
var info WorkspaceInfo
|
|
|
|
for _, check := range signatureChecks {
|
|
fullPath := filepath.Join(cwd, check.path)
|
|
if _, err := os.Stat(fullPath); err == nil {
|
|
info.SignatureFiles = append(info.SignatureFiles, check.path)
|
|
if check.field != nil {
|
|
check.field(&info)
|
|
}
|
|
}
|
|
}
|
|
|
|
return info
|
|
}
|
|
|
|
type cacheEntry struct {
|
|
key string // cwd + "|" + dirModTime
|
|
info WorkspaceInfo
|
|
}
|
|
|
|
var (
|
|
wsCache *cacheEntry
|
|
wsCacheMu sync.Mutex
|
|
)
|
|
|
|
// DetectCached returns cached workspace info, invalidating when directory modtime changes
|
|
// this handles mid-session file creation (e.g. go mod init) without requiring cd
|
|
func DetectCached(cwd string) WorkspaceInfo {
|
|
dirInfo, err := os.Stat(cwd)
|
|
if err != nil {
|
|
return Detect(cwd)
|
|
}
|
|
key := cwd + "|" + dirInfo.ModTime().String()
|
|
|
|
wsCacheMu.Lock()
|
|
defer wsCacheMu.Unlock()
|
|
|
|
if wsCache != nil && wsCache.key == key {
|
|
return wsCache.info
|
|
}
|
|
|
|
info := Detect(cwd)
|
|
wsCache = &cacheEntry{key: key, info: info}
|
|
return info
|
|
}
|