-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnostics.go
More file actions
243 lines (220 loc) · 8.36 KB
/
Copy pathdiagnostics.go
File metadata and controls
243 lines (220 loc) · 8.36 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package cmd
import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/GrayCodeAI/eyrie/catalog"
"github.com/GrayCodeAI/eyrie/credentials"
eyrieruntime "github.com/GrayCodeAI/eyrie/runtime"
"github.com/GrayCodeAI/eyrie/setup"
hawkconfig "github.com/GrayCodeAI/hawk/internal/config"
"github.com/GrayCodeAI/hawk/internal/intelligence/memory"
"github.com/GrayCodeAI/hawk/internal/plugin"
"github.com/GrayCodeAI/hawk/internal/resilience/health"
"github.com/GrayCodeAI/hawk/internal/session"
"github.com/GrayCodeAI/hawk/internal/storage"
"github.com/GrayCodeAI/hawk/internal/ui/icons"
)
func doctorReport(settings hawkconfig.Settings) string {
modelName, providerName := effectiveModelAndProvider(settings)
if providerName == "" {
providerName = "auto"
}
if modelName == "" {
modelName = "default"
}
cwd, _ := os.Getwd()
var b strings.Builder
b.WriteString("Hawk doctor\n")
b.WriteString(fmt.Sprintf("Version: %s\n", version))
b.WriteString(fmt.Sprintf("Go version: %s\n", runtime.Version()))
b.WriteString(fmt.Sprintf("Directory: %s\n", cwd))
b.WriteString(fmt.Sprintf("Provider: %s\n", providerName))
b.WriteString(fmt.Sprintf("Model: %s\n", modelName))
// Binary size
if exe, err := os.Executable(); err == nil {
if info, err := os.Stat(exe); err == nil {
b.WriteString(fmt.Sprintf("Binary size: %.1f MB\n", float64(info.Size())/(1024*1024)))
}
}
// Ecosystem versions
b.WriteString("\nEcosystem versions:\n")
for _, repo := range []string{"eyrie", "yaad", "tok", "sight", "inspect", "trace"} {
versionFile := filepath.Join("external", repo, "VERSION")
if data, err := os.ReadFile(versionFile); err == nil {
b.WriteString(fmt.Sprintf(" %s: %s\n", repo, strings.TrimSpace(string(data))))
} else {
b.WriteString(fmt.Sprintf(" %s: not checked out\n", repo))
}
}
b.WriteString("\n" + hawkconfig.FormatEcosystemPanel(context.Background(), provider, modelName) + "\n")
b.WriteString("\n" + hawkconfig.FormatCatalogHealth(hawkconfig.CatalogHealthReport(context.Background())) + "\n")
b.WriteString("\n" + eyrieruntime.FormatPreflightReport(eyrieruntime.Preflight(context.Background())) + "\n")
b.WriteString("\n" + credentials.FormatStorageReport(credentials.StorageReportFor(context.Background())) + "\n")
if deployReport, err := hawkconfig.DeploymentStatusReport(context.Background(), modelName); err == nil {
b.WriteString("\n" + deployReport + "\n")
}
_ = hawkconfig.MigrateProviderConfig()
b.WriteString("\n" + envSummaryWithSelection(provider, modelName, false) + "\n")
b.WriteString("\nGit:\n")
if branch := branchSummary(); branch != "" {
for _, line := range strings.Split(branch, "\n") {
b.WriteString(" " + line + "\n")
}
}
// Project instructions
if md := hawkconfig.LoadAgentsMD(); md != "" {
b.WriteString("\nProject instructions: found\n")
} else {
b.WriteString("\nProject instructions: not found (consider creating AGENTS.md)\n")
}
// Bundled skills
bundledDir := plugin.BundledSkillsDir()
if _, err := os.Stat(bundledDir); err == nil {
entries, _ := os.ReadDir(bundledDir)
b.WriteString(fmt.Sprintf("Bundled skills: %d extracted\n", len(entries)))
} else {
b.WriteString("Bundled skills: not yet extracted\n")
}
b.WriteString(fmt.Sprintf("Configured MCP servers: %d\n", len(settings.MCPServers)+len(mcpServers)))
b.WriteString(fmt.Sprintf("Built-in tools: %d\n", len(allTools())))
// Session recovery status
recoveryCandidates := session.ScanForRecovery()
if len(recoveryCandidates) > 0 {
b.WriteString(fmt.Sprintf("\nInterrupted sessions: %d (run hawk recover)\n", len(recoveryCandidates)))
} else {
b.WriteString("\nInterrupted sessions: none\n")
}
b.WriteString("\n" + healthCheckReport(settings, provider) + "\n")
return strings.TrimRight(b.String(), "\n")
}
func healthCheckReport(settings hawkconfig.Settings, provider string) string {
registry := health.NewRegistry()
ctx := context.Background()
apiKeyEnv := primaryAPIKeyEnvForProvider(ctx, provider)
apiKey := credentials.LookupSecret(ctx, apiKeyEnv)
registry.Register("api_key", health.APIKeyChecker(provider, apiKey))
// Settings validation
registry.Register("config", func(ctx context.Context) health.Check {
result := hawkconfig.ValidateSettings(settings)
if result.Valid {
return health.Check{Name: "config", Status: health.Healthy, Message: "Configuration valid"}
}
return health.Check{Name: "config", Status: health.Degraded, Message: result.Error()}
})
// Yaad memory bridge check
bridge := memory.NewYaadBridge()
if bridge.Ready() {
registry.Register("yaad", func(ctx context.Context) health.Check {
_, _, err := bridge.SearchByType("convention", 1)
if err != nil {
return health.Check{Name: "yaad", Status: health.Unhealthy, Message: "Yaad bridge initialized but query failed"}
}
return health.Check{Name: "yaad", Status: health.Healthy, Message: "Yaad memory bridge operational"}
})
} else {
registry.Register("yaad", func(ctx context.Context) health.Check {
return health.Check{Name: "yaad", Status: health.Degraded, Message: "Yaad not initialized (~/.yaad/data/ not writable)"}
})
}
// Lefthook installation check
registry.Register("lefthook", func(ctx context.Context) health.Check {
start := time.Now()
_, err := exec.LookPath("lefthook")
if err != nil {
return health.Check{Name: "lefthook", Status: health.Degraded, Message: "lefthook not installed (git hooks not active)", Duration: time.Since(start)}
}
return health.Check{Name: "lefthook", Status: health.Healthy, Message: "lefthook installed", Duration: time.Since(start)}
})
// Config syntax check
registry.Register("config_syntax", func(ctx context.Context) health.Check {
start := time.Now()
globalPath := storage.SettingsPath()
if data, err := os.ReadFile(globalPath); err == nil {
var raw json.RawMessage
if err := json.Unmarshal(data, &raw); err != nil {
return health.Check{Name: "config_syntax", Status: health.Unhealthy, Message: fmt.Sprintf("global settings.json parse error: %v", err), Duration: time.Since(start)}
}
}
return health.Check{Name: "config_syntax", Status: health.Healthy, Message: "config files parse OK", Duration: time.Since(start)}
})
results := registry.Run(context.Background())
var b strings.Builder
b.WriteString("Health checks:\n")
for _, check := range results {
status := icons.CheckBold() + " "
if check.Status == health.Unhealthy {
status = icons.CloseThick() + " "
} else if check.Status == health.Degraded {
status = icons.Alert() + " "
}
b.WriteString(fmt.Sprintf(" %s %s: %s\n", status, check.Name, check.Message))
}
return strings.TrimRight(b.String(), "\n")
}
func primaryAPIKeyEnvForProvider(ctx context.Context, provider string) string {
provider = strings.TrimSpace(provider)
if provider == "" || provider == "auto" {
provider = strings.TrimSpace(hawkconfig.ActiveProvider(ctx))
}
if provider == "" {
return ""
}
compiled, err := setup.LoadCompiledCatalog(ctx)
if err != nil || compiled == nil {
return ""
}
return catalog.PrimaryAPIKeyEnvForProvider(compiled, provider)
}
func settingsSummary(settings hawkconfig.Settings) string {
return configCommandSummary(settings)
}
func mcpConfigSummary(settings hawkconfig.Settings) string {
if len(settings.MCPServers) == 0 && len(mcpServers) == 0 {
return "No MCP servers configured."
}
var b strings.Builder
b.WriteString("MCP servers:\n")
for _, cfg := range 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")
}
return strings.TrimRight(b.String(), "\n")
}
func sessionsSummary() string {
entries, err := session.List()
if err != nil || len(entries) == 0 {
return "No saved sessions."
}
var b strings.Builder
b.WriteString("Saved sessions:\n")
for _, e := range entries {
cwd := e.CWD
if cwd == "" {
cwd = "-"
}
b.WriteString(fmt.Sprintf(" %s %s %s %s\n", e.ID, e.UpdatedAt.Format("2006-01-02 15:04"), cwd, e.Preview))
}
return strings.TrimRight(b.String(), "\n")
}
func builtInToolsSummary() string {
tools := allTools()
var b strings.Builder
b.WriteString(fmt.Sprintf("Built-in tools (%d):\n", len(tools)))
for _, t := range tools {
b.WriteString(fmt.Sprintf(" %s - %s\n", t.Name(), t.Description()))
}
return strings.TrimRight(b.String(), "\n")
}