-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
285 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,70 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/nitintf/navi/internal/ai" | ||
"github.com/nitintf/navi/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var explainTemplate = ` | ||
Imagine you are a security-conscious shell or terminal expert with a lot of computer knowledge. | ||
Your task is to explain the provided shell command in a way that a beginner could understand in less than 80 words. The explanation should: | ||
* Be clear and concise. | ||
* Avoid technical jargon where possible. | ||
* Not require additional explanation. | ||
Here is the command: | ||
> %s | ||
If the command is not related to shell or terminal, return "NAVI_NAVI_AI_ERROR". | ||
If the command is unclear or ambiguous, return "NAVI_AI_ERROR". | ||
If the command requires additional explanation beyond your capabilities, return "NAVI_AI_ERROR". | ||
If the command is not a shell command, return "NAVI_AI_ERROR". | ||
**Examples:** | ||
* Command: "ls" | ||
* Response: "The 'ls' command lists all files and directories in the current directory." | ||
* Command: "open funny_cat_video.mp4" (Not a shell command) | ||
* Response: "NAVI_AI_ERROR" | ||
` | ||
|
||
var explainCmd = &cobra.Command{ | ||
Use: "explain", | ||
Short: "Explain - Understand your shell commands", | ||
Example: `navi explain "ls"`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
command := args[0] | ||
commandLength := len(command) | ||
|
||
if commandLength > 120 { | ||
utils.LogError("Command is too long. Please keep it under 120 characters.") | ||
return | ||
} | ||
|
||
spin := utils.GetSpinner() | ||
spin.Suffix = " Explaining command..." | ||
spin.Start() | ||
resp, err := ai.Generate(cmd.Context(), explainTemplate, command) | ||
|
||
if err != nil { | ||
spin.Stop() | ||
utils.LogError(err.Error()) | ||
return | ||
} | ||
|
||
spin.Stop() | ||
utils.LogExplanation(resp) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(explainCmd) | ||
} | ||
package cmd | ||
|
||
import ( | ||
"github.com/nitintf/navi/internal/ai" | ||
"github.com/nitintf/navi/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var explainTemplate = ` | ||
Imagine you are a security-conscious shell or terminal expert with a lot of computer knowledge. | ||
Your task is to explain the provided shell command in a way that a beginner could understand in less than 80 words. The explanation should: | ||
* Be clear and concise. | ||
* Avoid technical jargon where possible. | ||
* Not require additional explanation. | ||
Here is the command: | ||
> %s | ||
If the command is not related to shell or terminal, return "NAVI_NAVI_AI_ERROR". | ||
If the command is unclear or ambiguous, return "NAVI_AI_ERROR". | ||
If the command requires additional explanation beyond your capabilities, return "NAVI_AI_ERROR". | ||
If the command is not a shell command, return "NAVI_AI_ERROR". | ||
**Examples:** | ||
* Command: "ls" | ||
* Response: "The 'ls' command lists all files and directories in the current directory." | ||
* Command: "open funny_cat_video.mp4" (Not a shell command) | ||
* Response: "NAVI_AI_ERROR" | ||
` | ||
|
||
var explainCmd = &cobra.Command{ | ||
Use: "explain", | ||
Short: "Explain - Understand your shell commands", | ||
Example: `navi explain "ls"`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
command := args[0] | ||
commandLength := len(command) | ||
|
||
if commandLength > 120 { | ||
utils.LogError("Command is too long. Please keep it under 120 characters.") | ||
return | ||
} | ||
|
||
spin := utils.GetSpinner() | ||
spin.Suffix = " Explaining command..." | ||
spin.Start() | ||
resp, err := ai.Generate(cmd.Context(), explainTemplate, command) | ||
if err != nil { | ||
spin.Stop() | ||
utils.LogError(err.Error()) | ||
return | ||
} | ||
|
||
spin.Stop() | ||
utils.LogExplanation(resp) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(explainCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,81 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/nitintf/navi/internal/ai" | ||
"github.com/nitintf/navi/utils" | ||
"github.com/spf13/cobra" // Import Cobra library | ||
) | ||
|
||
var commandTemplate = ` | ||
Imagine you are a security-conscious shell or terminal expert with a lot of computer knowledge. | ||
Write a single, safe shell command that achieves the desired outcome. The command should: | ||
* Not modify or delete files or folders. | ||
* Be appropriate for a general audience (avoid offensive or harmful commands). | ||
* Not require additional explanation. | ||
Here is the prompt: | ||
> %s | ||
If the prompt is not related to a safe shell command or is not related to shell or commands or terminal, return "NAVI_AI_ERROR". | ||
If the prompt is not appropriate for a general audience, return "NAVI_AI_ERROR". | ||
If the prompt is unclear or ambiguous, return "NAVI_AI_ERROR". | ||
If the prompt requires additional explanation, return "NAVI_AI_ERROR". | ||
If the prompt is not a shell command, return "NAVI_AI_ERROR". | ||
If the prompt is a shell command but is not safe, return "NAVI_AI_ERROR". | ||
**Examples:** | ||
* Prompt: "List all files in the current directory." | ||
* Response: ls | ||
* Prompt: "Delete all files in the current directory." (Unsafe) | ||
* Response: "NAVI_AI_ERROR" | ||
* Prompt: "Show a funny cat video." (Not a shell command) | ||
* Response: "NAVI_AI_ERROR" | ||
` | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "navi", | ||
Short: "Navi - Your AI-powered Shell Guide", | ||
Example: `navi "List all files in the current directory."`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
prompt := args[0] | ||
promptLength := len(prompt) | ||
|
||
if promptLength > 120 { | ||
utils.LogError("Prompt is too long. Please keep it under 120 characters.") | ||
return | ||
} | ||
|
||
spin := utils.GetSpinner() | ||
spin.Suffix = " Generating command..." | ||
spin.Start() | ||
resp, err := ai.Generate(cmd.Context(), commandTemplate, prompt) | ||
|
||
if err != nil { | ||
spin.Stop() | ||
utils.LogError(err.Error()) | ||
return | ||
} | ||
|
||
spin.Stop() | ||
utils.LogInfo(resp) | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
} | ||
} | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/nitintf/navi/internal/ai" | ||
"github.com/nitintf/navi/utils" | ||
"github.com/spf13/cobra" // Import Cobra library | ||
) | ||
|
||
var commandTemplate = ` | ||
Imagine you are a security-conscious shell or terminal expert with a lot of computer knowledge. | ||
Write a single, safe shell command that achieves the desired outcome. The command should: | ||
* Not modify or delete files or folders. | ||
* Be appropriate for a general audience (avoid offensive or harmful commands). | ||
* Not require additional explanation. | ||
Here is the prompt: | ||
> %s | ||
If the prompt is not related to a safe shell command or is not related to shell or commands or terminal, return "NAVI_AI_ERROR". | ||
If the prompt is not appropriate for a general audience, return "NAVI_AI_ERROR". | ||
If the prompt is unclear or ambiguous, return "NAVI_AI_ERROR". | ||
If the prompt requires additional explanation, return "NAVI_AI_ERROR". | ||
If the prompt is not a shell command, return "NAVI_AI_ERROR". | ||
If the prompt is a shell command but is not safe, return "NAVI_AI_ERROR". | ||
**Examples:** | ||
* Prompt: "List all files in the current directory." | ||
* Response: ls | ||
* Prompt: "Delete all files in the current directory." (Unsafe) | ||
* Response: "NAVI_AI_ERROR" | ||
* Prompt: "Show a funny cat video." (Not a shell command) | ||
* Response: "NAVI_AI_ERROR" | ||
` | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "navi", | ||
Short: "Navi - Your AI-powered Shell Guide", | ||
Example: `navi "List all files in the current directory."`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
prompt := args[0] | ||
promptLength := len(prompt) | ||
|
||
if promptLength > 120 { | ||
utils.LogError("Prompt is too long. Please keep it under 120 characters.") | ||
return | ||
} | ||
|
||
spin := utils.GetSpinner() | ||
spin.Suffix = " Generating command..." | ||
spin.Start() | ||
resp, err := ai.Generate(cmd.Context(), commandTemplate, prompt) | ||
if err != nil { | ||
spin.Stop() | ||
utils.LogError(err.Error()) | ||
return | ||
} | ||
|
||
spin.Stop() | ||
utils.LogInfo(resp) | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
} | ||
} |
Oops, something went wrong.