refactor(modes): group interactive startup submission
- commit
- 06af173e96906cfb1d9fe0b0080beb1837c4c112
- author
- brice · · 2026-08-14 03:34 UTC
- committer
- brice · · 2026-08-14 03:56 UTC
- parent
- 4f3ea4d
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +39 -39
M packages/agent/modes/interactive.go +0 -39
| @@ -3839,45 +3839,6 @@ func (i *Interactive) appendExtensionNote(extName, msg, level string) { | |||
| 3839 | 3839 | // holds an interface, not a concrete *Interactive, so these methods | |
| 3840 | 3840 | // are the only thing the manager sees. | |
| 3841 | 3841 | ||
| 3842 | - | // completeStartupPre applies deferred InitialInput after entry.pre finishes. | |
| 3843 | - | // When AutoSubmitInitial was set, the deferred prompt is submitted; otherwise | |
| 3844 | - | // it only pre-fills the editor (CLI-supplied prompts). | |
| 3845 | - | func (i *Interactive) completeStartupPre() { | |
| 3846 | - | i.mu.Lock() | |
| 3847 | - | if !i.awaitingStartupPre { | |
| 3848 | - | i.mu.Unlock() | |
| 3849 | - | return | |
| 3850 | - | } | |
| 3851 | - | i.awaitingStartupPre = false | |
| 3852 | - | deferred := i.deferredInitialInput | |
| 3853 | - | auto := i.autoSubmitDeferred | |
| 3854 | - | i.deferredInitialInput = "" | |
| 3855 | - | i.autoSubmitDeferred = false | |
| 3856 | - | onDone := i.cfg.OnStartupPreDone | |
| 3857 | - | i.mu.Unlock() | |
| 3858 | - | if onDone != nil { | |
| 3859 | - | onDone() | |
| 3860 | - | } | |
| 3861 | - | i.startupPreDone <- startupPreResult{deferred: deferred, autoSubmit: auto} | |
| 3862 | - | i.invalidate() | |
| 3863 | - | } | |
| 3864 | - | ||
| 3865 | - | // applyStartupPreResult runs on the TUI event loop so the editor remains | |
| 3866 | - | // single-threaded. Input entered while resources were reloading wins over the | |
| 3867 | - | // deferred prefill rather than being overwritten. | |
| 3868 | - | func (i *Interactive) applyStartupPreResult(result startupPreResult) { | |
| 3869 | - | if result.deferred == "" { | |
| 3870 | - | return | |
| 3871 | - | } | |
| 3872 | - | if result.autoSubmit { | |
| 3873 | - | i.Submit(result.deferred) | |
| 3874 | - | return | |
| 3875 | - | } | |
| 3876 | - | if i.ed.IsEmpty() { | |
| 3877 | - | i.ed.SetValue(result.deferred) | |
| 3878 | - | } | |
| 3879 | - | } | |
| 3880 | - | ||
| 3881 | 3842 | // ApplySessionAgent swaps the live agent after a validated session resume. | |
| 3882 | 3843 | // Unlike ApplyChangedCWD it does not mutate cwd-scoped resources or startup | |
| 3883 | 3844 | // context; the session loader is changing the transcript/provider only. | |
| @@ -3839,45 +3839,6 @@ func (i *Interactive) appendExtensionNote(extName, msg, level string) { | |||||
| 3839 | // holds an interface, not a concrete *Interactive, so these methods | 3839 | // holds an interface, not a concrete *Interactive, so these methods | ||
| 3840 | // are the only thing the manager sees. | 3840 | // are the only thing the manager sees. | ||
| 3841 | 3841 | ||||
| 3842 | - | // completeStartupPre applies deferred InitialInput after entry.pre finishes. | |||
| 3843 | - | // When AutoSubmitInitial was set, the deferred prompt is submitted; otherwise | |||
| 3844 | - | // it only pre-fills the editor (CLI-supplied prompts). | |||
| 3845 | - | func (i *Interactive) completeStartupPre() { | |||
| 3846 | - | i.mu.Lock() | |||
| 3847 | - | if !i.awaitingStartupPre { | |||
| 3848 | - | i.mu.Unlock() | |||
| 3849 | - | return | |||
| 3850 | - | } | |||
| 3851 | - | i.awaitingStartupPre = false | |||
| 3852 | - | deferred := i.deferredInitialInput | |||
| 3853 | - | auto := i.autoSubmitDeferred | |||
| 3854 | - | i.deferredInitialInput = "" | |||
| 3855 | - | i.autoSubmitDeferred = false | |||
| 3856 | - | onDone := i.cfg.OnStartupPreDone | |||
| 3857 | - | i.mu.Unlock() | |||
| 3858 | - | if onDone != nil { | |||
| 3859 | - | onDone() | |||
| 3860 | - | } | |||
| 3861 | - | i.startupPreDone <- startupPreResult{deferred: deferred, autoSubmit: auto} | |||
| 3862 | - | i.invalidate() | |||
| 3863 | - | } | |||
| 3864 | - | ||||
| 3865 | - | // applyStartupPreResult runs on the TUI event loop so the editor remains | |||
| 3866 | - | // single-threaded. Input entered while resources were reloading wins over the | |||
| 3867 | - | // deferred prefill rather than being overwritten. | |||
| 3868 | - | func (i *Interactive) applyStartupPreResult(result startupPreResult) { | |||
| 3869 | - | if result.deferred == "" { | |||
| 3870 | - | return | |||
| 3871 | - | } | |||
| 3872 | - | if result.autoSubmit { | |||
| 3873 | - | i.Submit(result.deferred) | |||
| 3874 | - | return | |||
| 3875 | - | } | |||
| 3876 | - | if i.ed.IsEmpty() { | |||
| 3877 | - | i.ed.SetValue(result.deferred) | |||
| 3878 | - | } | |||
| 3879 | - | } | |||
| 3880 | - | ||||
| 3881 | // ApplySessionAgent swaps the live agent after a validated session resume. | 3842 | // ApplySessionAgent swaps the live agent after a validated session resume. | ||
| 3882 | // Unlike ApplyChangedCWD it does not mutate cwd-scoped resources or startup | 3843 | // Unlike ApplyChangedCWD it does not mutate cwd-scoped resources or startup | ||
| 3883 | // context; the session loader is changing the transcript/provider only. | 3844 | // context; the session loader is changing the transcript/provider only. | ||
M packages/agent/modes/interactive_submit.go +39 -0
| @@ -20,3 +20,42 @@ func (i *Interactive) Submit(text string) { | |||
| 20 | 20 | } | |
| 21 | 21 | i.startTurn(parent, text) | |
| 22 | 22 | } | |
| 23 | + | ||
| 24 | + | // completeStartupPre applies deferred InitialInput after entry.pre finishes. | |
| 25 | + | // When AutoSubmitInitial was set, the deferred prompt is submitted; otherwise | |
| 26 | + | // it only pre-fills the editor (CLI-supplied prompts). | |
| 27 | + | func (i *Interactive) completeStartupPre() { | |
| 28 | + | i.mu.Lock() | |
| 29 | + | if !i.awaitingStartupPre { | |
| 30 | + | i.mu.Unlock() | |
| 31 | + | return | |
| 32 | + | } | |
| 33 | + | i.awaitingStartupPre = false | |
| 34 | + | deferred := i.deferredInitialInput | |
| 35 | + | auto := i.autoSubmitDeferred | |
| 36 | + | i.deferredInitialInput = "" | |
| 37 | + | i.autoSubmitDeferred = false | |
| 38 | + | onDone := i.cfg.OnStartupPreDone | |
| 39 | + | i.mu.Unlock() | |
| 40 | + | if onDone != nil { | |
| 41 | + | onDone() | |
| 42 | + | } | |
| 43 | + | i.startupPreDone <- startupPreResult{deferred: deferred, autoSubmit: auto} | |
| 44 | + | i.invalidate() | |
| 45 | + | } | |
| 46 | + | ||
| 47 | + | // applyStartupPreResult runs on the TUI event loop so the editor remains | |
| 48 | + | // single-threaded. Input entered while resources were reloading wins over the | |
| 49 | + | // deferred prefill rather than being overwritten. | |
| 50 | + | func (i *Interactive) applyStartupPreResult(result startupPreResult) { | |
| 51 | + | if result.deferred == "" { | |
| 52 | + | return | |
| 53 | + | } | |
| 54 | + | if result.autoSubmit { | |
| 55 | + | i.Submit(result.deferred) | |
| 56 | + | return | |
| 57 | + | } | |
| 58 | + | if i.ed.IsEmpty() { | |
| 59 | + | i.ed.SetValue(result.deferred) | |
| 60 | + | } | |
| 61 | + | } | |
| @@ -20,3 +20,42 @@ func (i *Interactive) Submit(text string) { | |||||
| 20 | } | 20 | } | ||
| 21 | i.startTurn(parent, text) | 21 | i.startTurn(parent, text) | ||
| 22 | } | 22 | } | ||
| 23 | + | ||||
| 24 | + | // completeStartupPre applies deferred InitialInput after entry.pre finishes. | |||
| 25 | + | // When AutoSubmitInitial was set, the deferred prompt is submitted; otherwise | |||
| 26 | + | // it only pre-fills the editor (CLI-supplied prompts). | |||
| 27 | + | func (i *Interactive) completeStartupPre() { | |||
| 28 | + | i.mu.Lock() | |||
| 29 | + | if !i.awaitingStartupPre { | |||
| 30 | + | i.mu.Unlock() | |||
| 31 | + | return | |||
| 32 | + | } | |||
| 33 | + | i.awaitingStartupPre = false | |||
| 34 | + | deferred := i.deferredInitialInput | |||
| 35 | + | auto := i.autoSubmitDeferred | |||
| 36 | + | i.deferredInitialInput = "" | |||
| 37 | + | i.autoSubmitDeferred = false | |||
| 38 | + | onDone := i.cfg.OnStartupPreDone | |||
| 39 | + | i.mu.Unlock() | |||
| 40 | + | if onDone != nil { | |||
| 41 | + | onDone() | |||
| 42 | + | } | |||
| 43 | + | i.startupPreDone <- startupPreResult{deferred: deferred, autoSubmit: auto} | |||
| 44 | + | i.invalidate() | |||
| 45 | + | } | |||
| 46 | + | ||||
| 47 | + | // applyStartupPreResult runs on the TUI event loop so the editor remains | |||
| 48 | + | // single-threaded. Input entered while resources were reloading wins over the | |||
| 49 | + | // deferred prefill rather than being overwritten. | |||
| 50 | + | func (i *Interactive) applyStartupPreResult(result startupPreResult) { | |||
| 51 | + | if result.deferred == "" { | |||
| 52 | + | return | |||
| 53 | + | } | |||
| 54 | + | if result.autoSubmit { | |||
| 55 | + | i.Submit(result.deferred) | |||
| 56 | + | return | |||
| 57 | + | } | |||
| 58 | + | if i.ed.IsEmpty() { | |||
| 59 | + | i.ed.SetValue(result.deferred) | |||
| 60 | + | } | |||
| 61 | + | } | |||