From 83d59c409539da8a0e02f9813dbad03cbddf52d8 Mon Sep 17 00:00:00 2001 From: Castor Gemini Date: Thu, 21 Aug 2025 16:09:56 -0500 Subject: [PATCH] refactor: Store all log content in external files - Modify the logging system to store all conversation text, code snippets, and other content in external files within the log/content/ directory. - The main .text log file now only contains metadata and pointers to these external content files. - Update the Go log formatter to read and assemble this distributed log format for display. This makes the entire system more robust and avoids parsing/escaping issues. --- Makefile | 7 ++++++- format_rich_log.go | 31 +++++++++++++++++++++++++++++++ log/2025-08-21-shell-v2.text | 28 ++++++++++++++++++++++++++++ log/content/shell_v2_a1.content | 1 + log/content/shell_v2_a1.snippet | 1 + log/content/shell_v2_a2.content | 1 + log/content/shell_v2_a2.snippet | 5 +++++ log/content/shell_v2_q1.content | 2 ++ log/content/shell_v2_q2.content | 10 ++++++++++ 9 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 log/2025-08-21-shell-v2.text create mode 100644 log/content/shell_v2_a1.content create mode 100644 log/content/shell_v2_a1.snippet create mode 100644 log/content/shell_v2_a2.content create mode 100644 log/content/shell_v2_a2.snippet create mode 100644 log/content/shell_v2_q1.content create mode 100644 log/content/shell_v2_q2.content diff --git a/Makefile b/Makefile index 10df64d..5ba1e7a 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,11 @@ gemini-config: gemini-go: ~/go/bin/gemini playback -add: +add-BACnet: ~/go/bin/gemini --add log/BACnet.text ls -lt ~/.config/gemini/ + +add-shell: + ls -lt ~/.config/gemini/ + gemini --add log/2025-08-21-shell-v2.text + ls -lt ~/.config/gemini/ diff --git a/format_rich_log.go b/format_rich_log.go index 48cb25b..2cd4092 100644 --- a/format_rich_log.go +++ b/format_rich_log.go @@ -60,9 +60,40 @@ func main() { for _, toolCall := range chat.GetToolCalls() { printToolCallBox(toolCall) } + + // Handle the new CodeSnippet field. + if snippets := chat.GetSnippets(); snippets != nil { + logDir := filepath.Dir(filename) + for _, snippet := range snippets { + printCodeSnippet(snippet, logDir) + } + } } } +// printCodeSnippet formats a code snippet block by reading its content from a file. +func printCodeSnippet(snippet *chatpb.CodeSnippet, logDir string) { + snippetPath := filepath.Join(logDir, snippet.GetFilename()) + + codeBytes, err := os.ReadFile(snippetPath) + if err != nil { + fmt.Printf("┌─[ ERROR: Could not read snippet file %s ]─\n\n", snippetPath) + return + } + + code := string(codeBytes) + language := filepath.Base(snippet.GetFilename()) // Use the filename as the language for display + + fmt.Printf("┌─[ Code Snippet: %s ]──────────────────────────────────\n", language) + + // Print each line of the code indented. + for _, line := range strings.Split(strings.TrimSpace(code), "\n") { + fmt.Printf("│ %s\n", line) + } + + fmt.Printf("└─────────────────────────────────────────────────────────\n\n") +} + // printToolCallBox handles the decorative formatting for a single tool call. func printToolCallBox(tc *chatpb.ToolCall) { boxWidth := termWidth - 2 // Account for the side borders. diff --git a/log/2025-08-21-shell-v2.text b/log/2025-08-21-shell-v2.text new file mode 100644 index 0000000..71697b4 --- /dev/null +++ b/log/2025-08-21-shell-v2.text @@ -0,0 +1,28 @@ +uuid: "shell-path-log-02" +version: "v0.0.4 go.wit.com/lib/protobuf/chatpb" +Chats: { + from: USER + ctime: { seconds: 1724168400 } + ContentFile: "content/shell_v2_q1.content" +} +Chats: { + from: GEMINI + ctime: { seconds: 1724168460 } + ContentFile: "content/shell_v2_a1.content" + Snippets: { + filename: "content/shell_v2_a1.snippet" + } +} +Chats: { + from: USER + ctime: { seconds: 1724168520 } + ContentFile: "content/shell_v2_q2.content" +} +Chats: { + from: GEMINI + ctime: { seconds: 1724168580 } + ContentFile: "content/shell_v2_a2.content" + Snippets: { + filename: "content/shell_v2_a2.snippet" + } +} \ No newline at end of file diff --git a/log/content/shell_v2_a1.content b/log/content/shell_v2_a1.content new file mode 100644 index 0000000..47ea09b --- /dev/null +++ b/log/content/shell_v2_a1.content @@ -0,0 +1 @@ +You are absolutely right in your understanding, and your confusion is completely justified. The `PATH` variable **is** processed in order from left to right. The output you are seeing means that the `PATH` your shell is *actually* using is different from the one you've posted. The problem almost always comes from the shell startup files. The solution is to **prepend, don't append** your custom directories to the PATH. \ No newline at end of file diff --git a/log/content/shell_v2_a1.snippet b/log/content/shell_v2_a1.snippet new file mode 100644 index 0000000..1cdb866 --- /dev/null +++ b/log/content/shell_v2_a1.snippet @@ -0,0 +1 @@ +export PATH="/home/jcarr/go/bin:$PATH" \ No newline at end of file diff --git a/log/content/shell_v2_a2.content b/log/content/shell_v2_a2.content new file mode 100644 index 0000000..4465a15 --- /dev/null +++ b/log/content/shell_v2_a2.content @@ -0,0 +1 @@ +You've found the root cause perfectly. This is a classic shell precedence issue. The order is: Aliases -> Keywords -> Functions -> Built-ins -> $PATH lookup. Your alias is being found at step 1, so the shell never even gets to step 5. The best solution is often to rename the alias in your `~/.bashrc` to something more specific, like `gemini-cli`. \ No newline at end of file diff --git a/log/content/shell_v2_a2.snippet b/log/content/shell_v2_a2.snippet new file mode 100644 index 0000000..82a777b --- /dev/null +++ b/log/content/shell_v2_a2.snippet @@ -0,0 +1,5 @@ +# To bypass the alias for a single command: +\gemini --version + +# To rename the alias permanently in your ~/.bashrc: +alias gemini-cli='node /home/jcarr/go/src/github.com/google-gemini/gemini-cli/scripts/start.js' \ No newline at end of file diff --git a/log/content/shell_v2_q1.content b/log/content/shell_v2_q1.content new file mode 100644 index 0000000..1d82a39 --- /dev/null +++ b/log/content/shell_v2_q1.content @@ -0,0 +1,2 @@ +My PATH is: PATH=/home/jcarr/.local/bin/:/home/jcarr/jcarr/bin/:/home/jcarr/go/bin/:/sbin:/usr/sbin:/home/jcarr/go/bin:/usr/games:/home/jcarr/.local/bin/:/home/jcarr/go/bin/:/sbin:/usr/sbin:/home/jcarr/go/bin:/usr/games:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games +but for some reason it is finding binaries in /usr/local/bin before /home/jcarr/go/bin. I thought the PATH was processed in order? \ No newline at end of file diff --git a/log/content/shell_v2_q2.content b/log/content/shell_v2_q2.content new file mode 100644 index 0000000..d59c071 --- /dev/null +++ b/log/content/shell_v2_q2.content @@ -0,0 +1,10 @@ +I see the problem. gemini is an alias. I'm not sure how to resolve this problem +jcarr@framebook:~/go/src/gemini$ which gemini +/home/jcarr/go/bin/gemini +jcarr@framebook:~/go/src/gemini$ /home/jcarr/go/bin/gemini --version +gemini v0.0.1-3-ga10b75d Built on 2025.08.21_1551 +jcarr@framebook:~/go/src/gemini$ gemini --version +Checking build status... +Build is up-to-date. +jcarr@framebook:~/go/src/gemini$ alias |grep gemini +alias gemini='node /home/jcarr/go/src/github.com/google-gemini/gemini-cli/scripts/start.js' \ No newline at end of file