Skip to content

Commit 9567051

Browse files
Addressed Copilot Feedback
1 parent 8237ebd commit 9567051

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

ai.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"log"
4+
"fmt"
55
"os"
66
"time"
77

@@ -24,7 +24,7 @@ func NewAI() gollm.LLM {
2424
opts = append(opts, gollm.SetEnableCaching(*figs.Bool(kAiCachingEnabled)))
2525
timeout := *figs.UnitDuration(kAiTimeout)
2626
if timeout < time.Second {
27-
panic("incorrect timeout value")
27+
timeout = dTimeout * dTimeoutUnit
2828
}
2929
opts = append(opts, gollm.SetTimeout(*figs.UnitDuration(kAiTimeout)))
3030
switch provider {
@@ -38,7 +38,8 @@ func NewAI() gollm.LLM {
3838
}
3939
llm, err := gollm.NewLLM(opts...)
4040
if err != nil {
41-
log.Fatal(err)
41+
fmt.Printf("❌ Failed to initialize AI: %v\n", err)
42+
return nil
4243
}
4344
return llm
4445
}

chat.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ type model struct {
9696
// initialModel creates the starting state of our application.
9797
// CORRECTED: The llm parameter is now the interface type.
9898
func initialModel(llm gollm.LLM, summary string) model {
99+
if llm == nil {
100+
errMsg := "LLM is nil. Please try again later."
101+
return model{
102+
llm: nil,
103+
messages: []string{errorStyle.Render(errMsg)},
104+
chatHistory: []string{},
105+
isGenerating: false,
106+
err: errors.New("empty summary"),
107+
ctx: context.Background(),
108+
}
109+
}
99110
// Configure the text area for user input.
100111
ta := textarea.New()
101112
ta.Placeholder = "Send a message... (press Enter to send, Esc to quit)"
@@ -109,7 +120,18 @@ func initialModel(llm gollm.LLM, summary string) model {
109120
vp := viewport.New(0, 0) // Width and height are set dynamically
110121

111122
if len(summary) == 0 {
112-
panic("no summary")
123+
errMsg := "No project summary available. Please provide a valid summary to start the chat."
124+
return model{
125+
llm: llm,
126+
textarea: ta,
127+
viewport: vp,
128+
summary: summary,
129+
messages: []string{errorStyle.Render(errMsg)},
130+
chatHistory: []string{},
131+
isGenerating: false,
132+
err: errors.New("empty summary"),
133+
ctx: context.Background(),
134+
}
113135
}
114136

115137
msg := fmt.Sprintf("%s %d bytes!", "Welcome to Summarize AI Chat! We've analyzed your project workspace and are ready to chat with you about ", len(summary))

main.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,28 @@ func main() {
2222
configure()
2323
capture("figs loading environment", figs.Load())
2424

25+
isDebug := *figs.Bool(kDebug)
26+
2527
inc := *figs.List(kIncludeExt)
2628
if len(inc) == 1 && inc[0] == "useExpanded" {
2729
figs.StoreList(kIncludeExt, extendedDefaultInclude)
2830
}
29-
fmt.Println(strings.Join(inc, ", "))
31+
3032
exc := *figs.List(kExcludeExt)
3133
if len(exc) == 1 && exc[0] == "useExpanded" {
3234
figs.StoreList(kExcludeExt, extendedDefaultExclude)
3335
}
34-
fmt.Println(strings.Join(exc, ", "))
36+
3537
ski := *figs.List(kSkipContains)
3638
if len(ski) == 1 && ski[0] == "useExpanded" {
3739
figs.StoreList(kSkipContains, extendedDefaultAvoid)
3840
}
39-
fmt.Println(strings.Join(ski, ", "))
41+
42+
if isDebug {
43+
fmt.Println("INCLUDE: ", strings.Join(inc, ", "))
44+
fmt.Println("EXCLUDE: ", strings.Join(exc, ", "))
45+
fmt.Println("SKIP: ", strings.Join(ski, ", "))
46+
}
4047

4148
if *figs.Bool(kShowExpanded) {
4249
fmt.Println("Expanded:")
@@ -45,7 +52,6 @@ func main() {
4552
fmt.Printf("-%s=%s\n", kSkipContains, strings.Join(*figs.List(kSkipContains), ","))
4653
os.Exit(0)
4754
}
48-
isDebug := *figs.Bool(kDebug)
4955

5056
if *figs.Bool(kVersion) {
5157
fmt.Println(Version())

reflect.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ func latestChatLog() string {
2121
var latestModTime time.Time
2222

2323
for _, entry := range entries {
24-
// Skip directories
2524
if entry.IsDir() {
2625
continue
2726
}
2827

2928
filename := entry.Name()
30-
// Check if file matches pattern: starts with "summary." and ends with ".md"
3129
if strings.HasPrefix(filename, "chatlog.") && strings.HasSuffix(filename, ".md") {
3230
fullPath := filepath.Join(kOutputDir, filename)
3331

@@ -40,7 +38,6 @@ func latestChatLog() string {
4038
}
4139

4240
modTime := fileInfo.ModTime()
43-
// If this is the first matching file or it's newer than the current latest
4441
if latestFile == "" || modTime.After(latestModTime) {
4542
latestFile = fullPath
4643
latestModTime = modTime

simplify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
// simplify takes a list of strings and reduces duplicates from the slice
44
func simplify(t []string) []string {
55
seen := make(map[string]bool)
6-
results := make([]string, 0, len(t))
6+
results := make([]string, 0)
77
for _, v := range t {
88
if !seen[v] {
99
seen[v] = true

0 commit comments

Comments
 (0)