-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_commands_util.go
More file actions
157 lines (144 loc) · 4.12 KB
/
Copy pathchat_commands_util.go
File metadata and controls
157 lines (144 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package cmd
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
hawkconfig "github.com/GrayCodeAI/hawk/internal/config"
"github.com/GrayCodeAI/hawk/internal/engine"
"github.com/GrayCodeAI/hawk/internal/feature/taste"
"github.com/GrayCodeAI/hawk/internal/plugin"
"github.com/GrayCodeAI/hawk/internal/system/staleness"
)
func gitOutput(args ...string) (string, error) {
out, err := exec.CommandContext(context.Background(), "git", args...).CombinedOutput()
return strings.TrimSpace(string(out)), err
}
func branchSummary() string {
branch, err := gitOutput("rev-parse", "--abbrev-ref", "HEAD")
if err != nil || branch == "" {
return "No git repository detected."
}
head, _ := gitOutput("rev-parse", "--short", "HEAD")
upstream, _ := gitOutput("rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}")
status, _ := gitOutput("status", "--short", "--branch")
var b strings.Builder
b.WriteString("Branch: " + branch)
if head != "" {
b.WriteString(" @ " + head)
}
if upstream != "" {
b.WriteString("\nUpstream: " + upstream)
}
if status != "" {
b.WriteString("\n\n" + status)
}
return b.String()
}
func filesSummary() string {
status, err := gitOutput("status", "--short")
if err != nil {
return "No git repository detected."
}
if strings.TrimSpace(status) == "" {
return "No modified files."
}
return "Modified files:\n" + status
}
func additionalDirContext(dir string) (string, string, error) {
dir = strings.TrimSpace(dir)
if dir == "" {
return "", "", fmt.Errorf("directory path is required")
}
abs, err := filepath.Abs(dir)
if err != nil {
return "", "", err
}
info, err := os.Stat(abs)
if err != nil {
return "", "", err
}
if !info.IsDir() {
return "", "", fmt.Errorf("%s is not a directory", abs)
}
var b strings.Builder
b.WriteString("Additional directory: " + abs)
if md := hawkconfig.LoadAgentsMDFrom(abs); md != "" {
b.WriteString("\nAdditional directory instructions (" + abs + "):\n" + md)
}
return abs, b.String(), nil
}
func hasString(values []string, want string) bool {
for _, value := range values {
if value == want {
return true
}
}
return false
}
func (m *chatModel) mcpSummary() string {
var b strings.Builder
configured := len(m.settings.MCPServers) + len(mcpServers)
if configured == 0 {
b.WriteString("No MCP servers configured.")
} else {
b.WriteString(fmt.Sprintf("MCP servers configured: %d\n", configured))
for _, cfg := range m.settings.MCPServers {
name := cfg.Name
if name == "" {
name = cfg.Command
}
b.WriteString(fmt.Sprintf(" %s: %s %s\n", name, cfg.Command, strings.Join(cfg.Args, " ")))
}
for _, cmd := range mcpServers {
b.WriteString(" cli: " + cmd + "\n")
}
}
if m.registry != nil {
var toolNames []string
for _, t := range m.registry.EyrieTools() {
if strings.HasPrefix(t.Name, "mcp__") {
toolNames = append(toolNames, t.Name)
}
}
if len(toolNames) > 0 {
if b.Len() > 0 {
b.WriteString("\n")
}
b.WriteString("Connected MCP tools:\n " + strings.Join(toolNames, "\n "))
}
}
return strings.TrimRight(b.String(), "\n")
}
func sessionStats(sess *engine.Session, id string) string {
return fmt.Sprintf("Session: %s\nMessages: %d\nModel: %s/%s\n%s",
id, sess.MessageCount(), sess.Provider(), sess.Model(), sess.CostValue().Summary())
}
func hooksSummary() string {
return "Hooks: pre_query, post_query, pre_tool, post_tool, session_start, session_end, permission_ask, error\nConfigure in Hawk user settings"
}
func pluginsSummary(rt *plugin.Runtime) string {
if rt == nil {
return "No plugins loaded."
}
plugins := rt.ListPlugins()
if len(plugins) == 0 {
return "No plugins installed."
}
var b strings.Builder
b.WriteString("Installed plugins:\n")
for _, p := range plugins {
b.WriteString(fmt.Sprintf(" %s (%s)\n", p.Name, p.Version))
}
return b.String()
}
// tasteStoreForSession returns a taste store using the default location.
func tasteStoreForSession() (*taste.Store, error) {
return taste.NewStore("")
}
// stalenessFormatReport formats stale rules for display.
func stalenessFormatReport(rules []staleness.StaleRule) string {
return staleness.FormatReport(rules)
}