Skip to content

Commit 79ff15d

Browse files
committed
Enhance Gema CLI with system information integration and add GoReleaser workflow
1 parent 4e0dfe1 commit 79ff15d

File tree

6 files changed

+143
-34
lines changed

6 files changed

+143
-34
lines changed

.github/workflows/goreleaser.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
jobs:
8+
goreleaser:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
- name: Set up Go
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: 1.23
19+
- name: Run GoReleaser
20+
uses: goreleaser/goreleaser-action@v2
21+
with:
22+
version: latest
23+
args: release --rm-dist
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

gemini.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ func AskQuery(query string) AiResponse {
3939
model := client.GenerativeModel(defaultModel)
4040
model.Temperature = &aiTemp
4141

42-
model.SystemInstruction = &genai.Content{Parts: []genai.Part{genai.Text(SystemInstruction)}}
42+
sysInfo := ""
43+
sysErr := error(nil)
44+
if sysInfo, sysErr = GetSystemInfo(); err != nil {
45+
log.Fatal(sysErr)
46+
}
47+
48+
finalPrompt := sysInfo + SystemInstruction
49+
50+
model.SystemInstruction = &genai.Content{Parts: []genai.Part{genai.Text(finalPrompt)}}
4351
model.ResponseMIMEType = "application/json"
4452
model.ResponseSchema = &genai.Schema{
4553
Type: genai.TypeObject,

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/4nkitd/gemini-cli
33
go 1.23.4
44

55
require (
6+
github.com/elastic/go-sysinfo v1.15.0
67
github.com/google/generative-ai-go v0.19.0
78
github.com/spf13/cobra v1.8.1
89
google.golang.org/api v0.186.0
@@ -15,6 +16,7 @@ require (
1516
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
1617
cloud.google.com/go/compute/metadata v0.3.0 // indirect
1718
cloud.google.com/go/longrunning v0.5.7 // indirect
19+
github.com/elastic/go-windows v1.0.0 // indirect
1820
github.com/felixge/httpsnoop v1.0.4 // indirect
1921
github.com/go-logr/logr v1.4.1 // indirect
2022
github.com/go-logr/stdr v1.2.2 // indirect
@@ -25,6 +27,8 @@ require (
2527
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
2628
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
2729
github.com/inconshreveable/mousetrap v1.1.0 // indirect
30+
github.com/pkg/errors v0.9.1 // indirect
31+
github.com/prometheus/procfs v0.15.1 // indirect
2832
github.com/spf13/pflag v1.0.5 // indirect
2933
go.opencensus.io v0.24.0 // indirect
3034
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 // indirect
@@ -43,4 +47,5 @@ require (
4347
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect
4448
google.golang.org/grpc v1.64.1 // indirect
4549
google.golang.org/protobuf v1.34.2 // indirect
50+
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
4651
)

go.sum

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
1919
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2020
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2121
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
22+
github.com/elastic/go-sysinfo v1.15.0 h1:54pRFlAYUlVNQ2HbXzLVZlV+fxS7Eax49stzg95M4Xw=
23+
github.com/elastic/go-sysinfo v1.15.0/go.mod h1:jPSuTgXG+dhhh0GKIyI2Cso+w5lPJ5PvVqKlL8LV/Hk=
24+
github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7aSY=
25+
github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU=
2226
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
2327
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
2428
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
@@ -67,9 +71,18 @@ github.com/googleapis/gax-go/v2 v2.12.5 h1:8gw9KZK8TiVKB6q3zHY3SBzLnrGp6HQjyfYBY
6771
github.com/googleapis/gax-go/v2 v2.12.5/go.mod h1:BUDKcWo+RaKq5SC9vVYL0wLADa3VcfswbOMMRmB9H3E=
6872
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
6973
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
74+
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
75+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
76+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
77+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
78+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
79+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
80+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7081
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7182
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7283
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
84+
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
85+
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
7386
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7487
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
7588
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
@@ -78,6 +91,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
7891
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7992
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
8093
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
94+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
8195
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8296
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
8397
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
@@ -167,8 +181,12 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
167181
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
168182
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
169183
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
184+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
185+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
170186
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
171187
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
172188
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
173189
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
174190
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
191+
howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M=
192+
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type model struct {
1818
}
1919

2020
func main() {
21+
2122
rootCmd := &cobra.Command{
2223
Use: "use",
2324
Short: "A CLI tool to execute commands",

system.go

Lines changed: 85 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,90 @@
11
package main
22

3-
var SystemInstruction = `**Template:**
4-
5-
**1. Define the Goal/Problem:**
6-
"I need to clearly state what you want to accomplish using the CLI]. For example:
7-
* 'I need to automate a task of renaming all files in a directory, replacing spaces with underscores.'
8-
* 'I'm encountering an error with '[command]' and I don't know how to solve it.'
9-
* 'I'm trying to understand how to use '[command]' with '[option]'.'
10-
* 'I want to quickly count how many files of a particular extension are in the current directory'
11-
12-
**2. Context (if needed):**
13-
"I am using macOS and my workflow usually involves the terminal, also I have experience with the zsh."
14-
15-
**3. Provide Specific Information:**
16-
"Here's the command/code/error message I'm working with: '[Paste the command or error here, or describe the scenario precisely]'"
17-
18-
**4. Desired Action:**
19-
"Can you help me by [clearly state what type of help you want]?" For example:
20-
* "suggesting a complete command to achieve my goal,"
21-
* "explaining the error message and possible causes,"
22-
* "providing an alternative way to do this,"
23-
* "explaining the functionality of the command in a concise way"
24-
* "giving a practical example of how this command works"
25-
* "suggesting a few options for better readability"
26-
27-
**5. Format Preference (optional):**
28-
"Please provide the response in a clear and structured format, and prefer one-liners if possible"
29-
30-
**Example using the template:**
31-
32-
"I need to automate a task of renaming all files in a directory, replacing spaces with underscores.
33-
I am using macOS and my workflow usually involves the terminal, also I have experience with the zsh.
34-
Here is an example file name: 'My File Name.txt'.
35-
Can you help me by suggesting a complete command to achieve my goal, and provide the command in a single line."`
3+
import (
4+
"encoding/json"
5+
"sort"
6+
7+
system "github.com/elastic/go-sysinfo"
8+
)
9+
10+
func GetSystemInfo() (string, error) {
11+
host, err := system.Host()
12+
if err != nil {
13+
return "", err
14+
}
15+
16+
cpuInfo, err := host.CPUTime()
17+
if err != nil {
18+
return "", err
19+
}
20+
21+
info := host.Info()
22+
23+
processes, err := system.Processes()
24+
if err != nil {
25+
return "", err
26+
}
27+
28+
memory, err := host.Memory()
29+
if err != nil {
30+
return "", err
31+
}
32+
33+
// Sort processes by memory usage and get top 5
34+
sort.Slice(processes, func(i, j int) bool {
35+
memI, _ := processes[i].Memory()
36+
memJ, _ := processes[j].Memory()
37+
return memI.Resident > memJ.Resident
38+
})
39+
40+
topProcesses := processes[:5]
41+
42+
systemInfo := map[string]interface{}{
43+
"host_info": info,
44+
"cpu_time": cpuInfo,
45+
"memory_info": memory,
46+
"top_processes": topProcesses,
47+
}
48+
49+
systemInfoJSON, err := json.MarshalIndent(systemInfo, "", " ")
50+
if err != nil {
51+
return "", err
52+
}
53+
54+
return string(systemInfoJSON), nil
55+
}
56+
57+
var SystemInstruction = `
58+
**Changes and Explanation:**
59+
60+
1. **System Information Inclusion:**
61+
* The provided JSON for system information is now placed at the very beginning of the prompt. This ensures that the AI agent has this context from the get-go.
62+
* It's crucial to keep the JSON format. This structured format allows the AI to process the information more efficiently.
63+
2. **Instructions for the AI Agent:**
64+
* I've added explicit instructions at the end of the prompt to ensure the AI agent understands its role, its access to system information, and assumptions about the user.
65+
* The instruction to "not reveal the system information in your answer unless it is directly asked" is important for maintaining a natural conversational style and avoiding verbose outputs, if not needed.
66+
* The assumption that the "user is familiar with shell scripting and terminal usage" ensures the response is not overly basic and geared towards the appropriate level of knowledge.
67+
68+
**How This Helps the AI Agent:**
69+
70+
* **Contextual Awareness:** The AI agent now has specific information about the user's environment (OS version, architecture, system load) that could be relevant to answering the question. For instance, knowing the OS version helps in suggesting suitable commands or workarounds for certain OS specific behaviors.
71+
* **Informed Responses:** The AI agent can use this information to provide more targeted and tailored suggestions. It can also make assumptions about the available tools and libraries based on the system information.
72+
* **Better Troubleshooting:** In case of error messages or unexpected behavior, system information may provide vital clues about why a command might be failing.
73+
* **Efficiency:** By accessing system details beforehand, it can potentially avoid asking follow-up questions.
74+
75+
**How to Use This Modified Prompt:**
76+
77+
1. **Copy the entire string** (including the JSON and the instructions).
78+
2. **Use the Template to Construct User Prompt** by filling in the bracketed info.
79+
3. **Send both** (system prompt string + user prompt string) to the AI agent as input.
80+
81+
**Important Considerations:**
82+
83+
* **JSON Validity:** Always ensure that the JSON you provide is valid. Errors in JSON can cause issues with the AI's understanding.
84+
* **Information Updates:** If the system configuration changes, update the JSON you provide in each request.
85+
* **Keep Context Minimal:** The system information should contain only relevant details and should be kept minimal to reduce the system resource consumption.
86+
87+
By using this modified template, you're empowering your AI agent to act like a genuinely helpful expert, leveraging specific context to provide better answers.`
3688

3789
var ResponseSchema string = `{
3890
"type": "object",

0 commit comments

Comments
 (0)