Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
Improve context token handling and add token counts to file maps
Dane Schneider2c42aebffdf7
diff --git a/app/shared/context.go b/app/shared/context.goindex 22cfe9e9..ea5c571f 100644--- a/app/shared/context.go+++ b/app/shared/context.go@@ -10,11 +10,11 @@ import ()const (- MaxContextBodySize = 10 * 1024 * 1024 // 10MB- MaxContextCount = 500- MaxContextMapPaths = 2000- MaxContextMapInputSize = 100 * 1024 * 1024 // 100MB- MaxTotalContextSize = 2 * 1024 * 1024 * 1024 // 2GB+ MaxContextBodySize = 25 * 1024 * 1024 // 25MB+ MaxContextCount = 1000+ MaxContextMapPaths = 3000+ MaxContextMapInputSize = 250 * 1024 * 1024 // 250MB+ MaxTotalContextSize = 1 * 1024 * 1024 * 1024 // 1GB)type ContextUpdateResult struct {@@ -60,7 +60,7 @@ func (c *Context) TypeAndIcon() (string, string) {return t, icon}-func TableForLoadContext(contexts []*Context) string {+func TableForLoadContext(contexts []*Context, plaintext bool) string {tableString := &strings.Builder{}table := tablewriter.NewWriter(tableString)table.SetHeader([]string{"Name", "Type", "πͺ"})@@ -74,11 +74,15 @@ func TableForLoadContext(contexts []*Context) string {"+" + strconv.Itoa(context.NumTokens),}- table.Rich(row, []tablewriter.Colors{- {tablewriter.FgHiGreenColor, tablewriter.Bold},- {tablewriter.FgHiGreenColor},- {tablewriter.FgHiGreenColor},- })+ if !plaintext {+ table.Rich(row, []tablewriter.Colors{+ {tablewriter.FgHiGreenColor, tablewriter.Bold},+ {tablewriter.FgHiGreenColor},+ {tablewriter.FgHiGreenColor},+ })+ } else {+ table.Append(row)+ }}table.Render()diff --git a/app/shared/convo_message.go b/app/shared/convo_message.goindex 18bfea6d..b644da51 100644--- a/app/shared/convo_message.go+++ b/app/shared/convo_message.go@@ -24,5 +24,9 @@ func (f *ConvoMessageFlags) GetReplyTags() []string {replyTags = append(replyTags, "π")}+ if f.HasError {+ replyTags = append(replyTags, "π¨ Finished With Errors")+ }+return replyTags}diff --git a/app/shared/file_maps.go b/app/shared/file_maps.goindex 0b86d224..9714ee1c 100644--- a/app/shared/file_maps.go+++ b/app/shared/file_maps.go@@ -6,7 +6,7 @@ import ("strings")-func (m FileMapBodies) CombinedMap() string {+func (m FileMapBodies) CombinedMap(tokensByPath map[string]int) string {var combinedMap strings.Builderpaths := make([]string, 0, len(m))for path := range m {@@ -16,7 +16,7 @@ func (m FileMapBodies) CombinedMap() string {for _, path := range paths {body := m[path]body = strings.TrimSpace(body)- fileHeading := MapFileHeading(path)+ fileHeading := MapFileHeading(path, tokensByPath[path])combinedMap.WriteString(fileHeading)if body == "" {combinedMap.WriteString("[NO MAP]")@@ -29,13 +29,16 @@ func (m FileMapBodies) CombinedMap() string {}func (m FileMapBodies) TokenEstimateForPath(path string) int {- heading := MapFileHeading(path)body := m[path]body = strings.TrimSpace(body)- combined := heading + body + "\n"- return GetNumTokensEstimate(combined)+ bodyTokens := GetNumTokensEstimate(body + "\n")++ heading := MapFileHeading(path, bodyTokens)+ headingTokens := GetNumTokensEstimate(heading)++ return bodyTokens + headingTokens}-func MapFileHeading(path string) string {- return fmt.Sprintf("\n### %s\n", path)+func MapFileHeading(path string, tokens int) string {+ return fmt.Sprintf("\n### %s (%d πͺ)\n\n", path, tokens)}