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
debouncing for smoother stream ui updates, a couple fixes
Dane Schneider8d4c515281aa
diff --git a/app/cli/lib/apply.go b/app/cli/lib/apply.goindex 6313b4a9..90c4614c 100644--- a/app/cli/lib/apply.go+++ b/app/cli/lib/apply.go@@ -507,12 +507,13 @@ func commitApplied(autoCommit bool, commitSummary string, updatedFiles []string,func applyFiles(toApply map[string]string, toRemove map[string]bool) ([]string, *types.ApplyRollbackPlan, error) {var updatedFiles []string- var toRevert map[string]types.ApplyReversion+ toRevert := map[string]types.ApplyReversion{}var toRemoveOnRollback []stringvar projectPaths *types.ProjectPathsvar mu sync.Mutex- errCh := make(chan error, len(toApply)+len(toRemove))+ totalOps := len(toApply) + len(toRemove) + 1+ errCh := make(chan error, totalOps)for path, content := range toApply {if path == "_apply.sh" {@@ -639,9 +640,10 @@ func applyFiles(toApply map[string]string, toRemove map[string]bool) ([]string,if err != nil {errCh <- fmt.Errorf("failed to get project paths: %v", err)}+ errCh <- nil}()- for i := 0; i < len(toApply)+len(toRemove)+1; i++ {+ for i := 0; i < totalOps; i++ {err := <-errChif err != nil {return nil, nil, errdiff --git a/app/cli/stream_tui/debouncer.go b/app/cli/stream_tui/debouncer.gonew file mode 100644index 00000000..15a568e8--- /dev/null+++ b/app/cli/stream_tui/debouncer.go@@ -0,0 +1,36 @@+package streamtui++import (+ "sync"+ "time"+)++// UpdateDebouncer helps prevent visual glitches from rapid updates+type UpdateDebouncer struct {+ mu sync.Mutex+ lastUpdate time.Time+ minInterval time.Duration+ pending bool+}++func NewUpdateDebouncer(minInterval time.Duration) *UpdateDebouncer {+ return &UpdateDebouncer{+ minInterval: minInterval,+ }+}++// ShouldUpdate returns true if enough time has passed since the last update+func (d *UpdateDebouncer) ShouldUpdate() bool {+ d.mu.Lock()+ defer d.mu.Unlock()++ now := time.Now()+ if now.Sub(d.lastUpdate) < d.minInterval {+ d.pending = true+ return false+ }++ d.lastUpdate = now+ d.pending = false+ return true+}diff --git a/app/cli/stream_tui/model.go b/app/cli/stream_tui/model.goindex fede4069..cd9872aa 100644--- a/app/cli/stream_tui/model.go+++ b/app/cli/stream_tui/model.go@@ -72,6 +72,8 @@ type streamUIModel struct {err errorapiErr *shared.ApiError++ updateDebouncer *UpdateDebouncer}type keymap = struct {@@ -166,14 +168,15 @@ func initialModel(prestartReply, prompt string, buildOnly bool) *streamUIModel {),},- tokensByPath: make(map[string]int),- finishedByPath: make(map[string]bool),- removedByPath: make(map[string]bool),- spinner: s,- buildSpinner: buildSpinner,- sharedTicker: sharedTicker,- atScrollBottom: true,- starting: true,+ tokensByPath: make(map[string]int),+ finishedByPath: make(map[string]bool),+ removedByPath: make(map[string]bool),+ spinner: s,+ buildSpinner: buildSpinner,+ sharedTicker: sharedTicker,+ atScrollBottom: true,+ starting: true,+ updateDebouncer: NewUpdateDebouncer(8 * time.Millisecond),}return &initialStatediff --git a/app/cli/stream_tui/update.go b/app/cli/stream_tui/update.goindex d7062d25..84e99515 100644--- a/app/cli/stream_tui/update.go+++ b/app/cli/stream_tui/update.go@@ -39,6 +39,9 @@ func (m streamUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {m.windowResized(msg.Width, msg.Height)case shared.StreamMessage:+ if !m.updateDebouncer.ShouldUpdate() {+ return m, nil // Skip this update if it's too soon+ }return m.streamUpdate(&msg, false)case delayFileRestartMsg:diff --git a/app/plans/plan-config.md b/app/plans/plan-config.mdindex c9fcb877..6b223a36 100644--- a/app/plans/plan-config.md+++ b/app/plans/plan-config.md@@ -3,11 +3,12 @@ on the plan model settings (often referred to also as just plan settings),and the 'model packs' feature. I want to store a 'plan_config' JSON field onthe 'plans' table. I also want a 'settings' and a 'set' CLI command.-'settings' shows the current settings (like 'models' cmd) and 'set' allows-updating the settings just like 'set-model'. the server-side updates can also+'settings' shows the current config (like 'models' cmd) and 'set' allows+updating the config just like 'set-model'. the server-side updates can alsowork similarly to models and model sets. it shouldn't be added to the file-system or use git at all-it should just be stored in the database.-+system or use git at all-it should just be stored in the database. These are *new* commands separate from the 'models' and 'set-model' commands and should have their own files.++For prompting and user input in the 'set' command, use the same approach as the 'set-model' command. Don't introduce any new dependencies.it should have these properties to start:AutoApply bool AutoCommit bool AutoContext bool NoExec bool AutoDebug bool AutoDebugTries int@@ -18,3 +19,15 @@ this should also have a 'set default' command. again use model settings as aguide.On the server side, to keep things neater, create new files for the API and DB handlers rather than including them in the existing plan settings handlers.++On the client side, update the API interface and implementation for the new api calls.++Also update the CLI 'tell', 'continue', 'build', and 'chat' commands to use config settings by default (they can be overridden with the flags that already exist).++Server-side, it needs api handlers, db handlers, and db up/down migration.++Also add request/response types.++For the 'new' command, show the default settings to the user after the plan is created (in a nicely formatted way, similar to the 'settings' command).++Update the CLI help output accordingly. Also add the appropriate command suggestions to the 'settings' and 'set' commands. Also add suggestions to the 'new' command to demonstrate the new config settings commands.\ No newline at end of filediff --git a/app/server/model/plan/tell_context.go b/app/server/model/plan/tell_context.goindex 89c7c58a..07bb791f 100644--- a/app/server/model/plan/tell_context.go+++ b/app/server/model/plan/tell_context.go@@ -15,14 +15,15 @@ func (state *activeTellStreamState) formatModelContext(includeMaps, includeTreesaddedFilesSet := map[string]bool{}uses := map[string]bool{}- if isImplementationStage {+ if isImplementationStage && state.currentSubtask != nil {for _, path := range state.currentSubtask.UsesFiles {uses[path] = true}+}for _, part := range state.modelContext {- if isImplementationStage && part.ContextType == shared.ContextFileType && !uses[part.FilePath] {+ if isImplementationStage && state.currentSubtask != nil && part.ContextType == shared.ContextFileType && !uses[part.FilePath] {continue}diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex 9d0abd82..7d2baf06 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -274,6 +274,8 @@ func execTellPlan(sysCreateTokens += subtaskTokens}+ log.Println("**sysCreate:**\n", sysCreate)+state.messages = []openai.ChatCompletionMessage{{Role: openai.ChatMessageRoleSystem,