9
9
10
10
"github.com/chand1012/ottodocs/pkg/calc"
11
11
"github.com/chand1012/ottodocs/pkg/config"
12
+ "github.com/chand1012/ottodocs/pkg/git"
12
13
"github.com/chand1012/ottodocs/pkg/utils"
13
14
"github.com/spf13/cobra"
14
15
)
@@ -32,7 +33,7 @@ otto count -c contextfile.txt -g "prompt"`,
32
33
33
34
var prompt string
34
35
35
- if chatPrompt == "" && len (contextFiles ) == 0 {
36
+ if chatPrompt == "" && len (contextFiles ) == 0 && ! repoContext {
36
37
log .Error ("Requires a prompt or context file as an argument. Example: otto count -c contextfile.txt -g \" prompt\" " )
37
38
os .Exit (1 )
38
39
}
@@ -41,13 +42,26 @@ otto count -c contextfile.txt -g "prompt"`,
41
42
prompt = "GOAL:" + chatPrompt
42
43
}
43
44
44
- for _ , contextFile := range contextFiles {
45
- content , err := utils . LoadFile ( contextFile )
45
+ if repoContext {
46
+ repo , err := git . GetRepo ( "." , "" , false )
46
47
if err != nil {
47
- log .Errorf ("Error loading file : %s" , err )
48
+ log .Errorf ("Error getting repo : %s" , err )
48
49
os .Exit (1 )
49
50
}
50
- prompt += "\n \n FILE: " + contextFile + "\n \n " + content + "\n "
51
+
52
+ for _ , file := range repo .Files {
53
+ content := file .Contents
54
+ prompt += "\n \n FILE: " + file .Path + "\n \n " + content + "\n "
55
+ }
56
+ } else {
57
+ for _ , contextFile := range contextFiles {
58
+ content , err := utils .LoadFile (contextFile )
59
+ if err != nil {
60
+ log .Errorf ("Error loading file: %s" , err )
61
+ os .Exit (1 )
62
+ }
63
+ prompt += "\n \n FILE: " + contextFile + "\n \n " + content + "\n "
64
+ }
51
65
}
52
66
53
67
tokens , err := calc .PreciseTokens (prompt )
@@ -66,4 +80,5 @@ func init() {
66
80
67
81
countCmd .Flags ().StringVarP (& chatPrompt , "goal" , "g" , "" , "Prompt for token count" )
68
82
countCmd .Flags ().StringSliceVarP (& contextFiles , "context" , "c" , []string {}, "Context files" )
83
+ countCmd .Flags ().BoolVarP (& repoContext , "repo" , "r" , false , "Use the current repository as context" )
69
84
}
0 commit comments