Skip to content

Commit bba2cb3

Browse files
committed
Reduce log bloat: remove duplicate fields from LogEntry
Prompt, Messages, and Excluded carried redundant data in every log line. Replace Messages with MessageCount, drop Prompt and Excluded entirely. Update route.go caller and rewrite logs display with status indicators, reasoning, and larger scanner buffer.
1 parent c844944 commit bba2cb3

File tree

3 files changed

+56
-43
lines changed

3 files changed

+56
-43
lines changed

cmd/logs.go

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ func runLogs(args []string) error {
3434
}
3535
defer f.Close()
3636

37-
// Collect all lines
3837
var lines []string
3938
scanner := bufio.NewScanner(f)
39+
// Increase scanner buffer for large log lines
40+
scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)
4041
for scanner.Scan() {
4142
if line := scanner.Text(); line != "" {
4243
lines = append(lines, line)
4344
}
4445
}
4546

46-
// Take last N
4747
if len(lines) > n {
4848
lines = lines[len(lines)-n:]
4949
}
@@ -53,51 +53,68 @@ func runLogs(args []string) error {
5353
return nil
5454
}
5555

56-
fmt.Printf("%-19s %-20s %-30s %-8s %s\n", "TIME", "PROJECT", "RESULT", "LATENCY", "MSG/REG")
57-
fmt.Println(strings.Repeat("─", 88))
58-
5956
for _, line := range lines {
6057
var e internal.LogEntry
6158
if err := json.Unmarshal([]byte(line), &e); err != nil {
6259
continue
6360
}
6461

6562
ts, _ := time.Parse(time.RFC3339, e.Timestamp)
66-
local := ts.Local().Format("2006-01-02 15:04:05")
63+
local := ts.Local().Format("15:04:05")
6764

6865
project := filepath.Base(e.CWD)
69-
if len(project) > 20 {
70-
project = project[:17] + "..."
66+
if len(project) > 18 {
67+
project = project[:15] + "..."
68+
}
69+
70+
// Status indicator
71+
var status string
72+
switch e.Status {
73+
case "ok":
74+
status = "✓"
75+
case "skipped":
76+
status = "○"
77+
case "error":
78+
status = "✗"
79+
default:
80+
status = "?"
7181
}
7282

73-
result := "(nothing)"
83+
// Build result string
84+
var result string
7485
if e.Error != "" {
75-
result = "error: " + truncate(e.Error, 28)
86+
result = "error: " + truncate(e.Error, 50)
87+
} else if e.SkipReason != "" {
88+
result = "skip: " + e.SkipReason
7689
} else if e.Result != nil {
7790
parts := []string{}
78-
if len(e.Result.Docs) > 0 {
79-
parts = append(parts, strings.Join(shortPaths(e.Result.Docs), ", "))
91+
for _, d := range e.Result.Docs {
92+
parts = append(parts, filepath.Base(d))
8093
}
81-
if len(e.Result.Skills) > 0 {
82-
for _, s := range e.Result.Skills {
83-
parts = append(parts, "/"+s)
84-
}
94+
for _, s := range e.Result.Skills {
95+
parts = append(parts, "/"+s)
8596
}
8697
if len(parts) > 0 {
87-
result = truncate(strings.Join(parts, " · "), 30)
98+
result = strings.Join(parts, ", ")
99+
} else {
100+
result = "(nothing needed)"
88101
}
102+
// Add reasoning if present
103+
if e.Result.Reasoning != "" {
104+
result += " — " + truncate(e.Result.Reasoning, 60)
105+
}
106+
} else {
107+
result = "(nothing needed)"
89108
}
90109

91-
excluded := len(e.Excluded.Docs) + len(e.Excluded.Skills)
92-
excludedStr := ""
93-
if excluded > 0 {
94-
excludedStr = fmt.Sprintf(" -%d", excluded)
95-
}
96-
fmt.Printf("%-19s %-20s %-30s %dms (%dm/%dr%s)\n",
97-
local, project, result, e.LatencyMS, len(e.Messages), len(e.Registry.Docs)+len(e.Registry.Skills), excludedStr)
110+
// Registry size
111+
regSize := len(e.Registry.Docs) + len(e.Registry.Skills)
112+
113+
fmt.Printf(" %s %s %-18s %4dms %dm/%dr %s\n",
114+
status, local, project, e.LatencyMS, e.MessageCount, regSize, result)
98115
}
99116

100-
fmt.Printf("\nLog file: %s\n", p)
117+
fmt.Printf("\n %s\n", p)
101118
return nil
102119
}
103120

cmd/route.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func runRoute(args []string) error {
4242

4343
// Route
4444
start := time.Now()
45-
result, excluded, prompt, rawResponse, skipReason, routeErr := internal.Route(input, cfg)
45+
result, _, _, rawResponse, skipReason, routeErr := internal.Route(input, cfg)
4646
latency := time.Since(start).Milliseconds()
4747

4848
status := "ok"
@@ -60,19 +60,17 @@ func runRoute(args []string) error {
6060
cwd, _ := os.Getwd()
6161
session := input.Session
6262
internal.AppendLog(internal.LogEntry{
63-
CWD: cwd,
64-
Status: status,
65-
SkipReason: skipReason,
66-
Messages: input.Messages,
67-
Registry: input.Registry,
68-
Session: &session,
69-
Excluded: excluded,
70-
Prompt: prompt,
71-
RawResponse: rawResponse,
72-
Result: result,
73-
LatencyMS: latency,
74-
Model: cfg.Provider.Model,
75-
Error: errStr,
63+
CWD: cwd,
64+
Status: status,
65+
SkipReason: skipReason,
66+
MessageCount: len(input.Messages),
67+
Registry: input.Registry,
68+
Session: &session,
69+
RawResponse: rawResponse,
70+
Result: result,
71+
LatencyMS: latency,
72+
Model: cfg.Provider.Model,
73+
Error: errStr,
7674
})
7775

7876
// Output

internal/log.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ type LogEntry struct {
1111
Timestamp string `json:"ts"`
1212
CWD string `json:"cwd"`
1313
Status string `json:"status"` // "ok", "skipped", "error"
14-
SkipReason string `json:"skip_reason,omitempty"` // why skipped (no registry, all already read)
15-
Messages []Message `json:"messages"`
14+
SkipReason string `json:"skip_reason,omitempty"`
15+
MessageCount int `json:"message_count"`
1616
Registry Registry `json:"registry"`
1717
Session *SessionState `json:"session"`
18-
Excluded Registry `json:"excluded"`
19-
Prompt string `json:"prompt,omitempty"`
2018
RawResponse string `json:"raw_response,omitempty"`
2119
Result *RouteResult `json:"result"`
2220
LatencyMS int64 `json:"latency_ms"`

0 commit comments

Comments
 (0)