acquireOperationContext creates the cancellable context that drives the turn and stashes its cancel func in cli.operationCancel so /reset can interrupt mid-turn. The returned release closure clears the slot and fires cancel exactly once.
(parent context.Context)
| 150 | // interrupt mid-turn. The returned release closure clears the slot and |
| 151 | // fires cancel exactly once. |
| 152 | func (cli *ChatCLI) acquireOperationContext(parent context.Context) (context.Context, func()) { |
| 153 | ctx, cancel := context.WithCancel(parent) |
| 154 | cli.mu.Lock() |
| 155 | cli.operationCancel = cancel |
| 156 | cli.mu.Unlock() |
| 157 | return ctx, func() { |
| 158 | cli.mu.Lock() |
| 159 | cli.operationCancel = nil |
| 160 | cli.mu.Unlock() |
| 161 | cancel() |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // fireUserPromptSubmitHook publishes the UserPromptSubmit event when the |
| 166 | // hook manager is enabled. Best-effort: hooks run asynchronously and any |