Skip to content

Commit 98146ad

Browse files
committed
Enhance session file handling in CreateContextFromPrompt; update logging messages for clarity and consistency
1 parent af399ab commit 98146ad

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

cmd/generate/context.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import (
1212

1313
// createContext creates a new PromptPexContext from a prompt file
1414
func (h *generateCommandHandler) CreateContextFromPrompt() (*PromptPexContext, error) {
15+
16+
h.WriteStartBox(fmt.Sprintf("Prompt %s", h.promptFile))
17+
1518
prompt, err := prompt.LoadFromFile(h.promptFile)
1619
if err != nil {
1720
return nil, fmt.Errorf("failed to load prompt file: %w", err)
@@ -35,17 +38,18 @@ func (h *generateCommandHandler) CreateContextFromPrompt() (*PromptPexContext, e
3538
Options: h.options,
3639
}
3740

41+
sessionInfo := ""
3842
if h.sessionFile != nil {
3943
// Try to load existing context from session file
4044
existingContext, err := loadContextFromFile(*h.sessionFile)
4145
if err != nil {
42-
h.cfg.WriteToOut(fmt.Sprintf("Creating session file at %s\n", *h.sessionFile))
46+
sessionInfo = fmt.Sprintf("new session file at %s", *h.sessionFile)
4347
// If file doesn't exist, that's okay - we'll start fresh
4448
if !os.IsNotExist(err) {
4549
return nil, fmt.Errorf("failed to load existing context from %s: %w", *h.sessionFile, err)
4650
}
4751
} else {
48-
h.cfg.WriteToOut(fmt.Sprintf("Reloading session file at %s\n", *h.sessionFile))
52+
sessionInfo = fmt.Sprintf("reloading session file at %s", *h.sessionFile)
4953
// Check if prompt hashes match
5054
if existingContext.PromptHash != nil && context.PromptHash != nil &&
5155
*existingContext.PromptHash != *context.PromptHash {
@@ -59,6 +63,9 @@ func (h *generateCommandHandler) CreateContextFromPrompt() (*PromptPexContext, e
5963
}
6064
}
6165

66+
h.WriteToParagraph(RenderMessagesToString(context.Prompt.Messages))
67+
h.WriteEndBox(sessionInfo)
68+
6269
return context, nil
6370
}
6471

0 commit comments

Comments
 (0)