PTYConversation is a conversation that uses a pseudo-terminal (PTY) for communication. It uses a combination of polling and diffs to detect changes in the screen.
| 127 | // PTYConversation is a conversation that uses a pseudo-terminal (PTY) for communication. |
| 128 | // It uses a combination of polling and diffs to detect changes in the screen. |
| 129 | type PTYConversation struct { |
| 130 | cfg PTYConversationConfig |
| 131 | emitter Emitter |
| 132 | // How many stable snapshots are required to consider the screen stable |
| 133 | stableSnapshotsThreshold int |
| 134 | snapshotBuffer *RingBuffer[screenSnapshot] |
| 135 | messages []ConversationMessage |
| 136 | screenBeforeLastUserMessage string |
| 137 | lock sync.Mutex |
| 138 | |
| 139 | // outboundQueue holds messages waiting to be sent to the agent. |
| 140 | // Buffer size is 1. Callers are expected to be serialized (the HTTP |
| 141 | // layer holds s.mu, and Send blocks until the message is processed), |
| 142 | // so ordering is preserved. |
| 143 | outboundQueue chan outboundMessage |
| 144 | // sendingMessage is true while the send loop is processing a message. |
| 145 | // Set under lock in the snapshot loop when signaling, cleared under |
| 146 | // lock in the send loop after sendMessage returns. |
| 147 | sendingMessage bool |
| 148 | // writingMessage is true while writeStabilize is executing. |
| 149 | // When true, updateLastAgentMessageLocked skips updates to avoid capturing terminal echo. |
| 150 | writingMessage bool |
| 151 | // stableSignal is used by the snapshot loop to signal the send loop |
| 152 | // when the agent is stable and there are items in the outbound queue. |
| 153 | stableSignal chan struct{} |
| 154 | // toolCallMessageSet keeps track of the tool calls that have been detected & logged in the current agent message |
| 155 | toolCallMessageSet map[string]bool |
| 156 | // dirty tracks whether the conversation state has changed since the last save |
| 157 | dirty bool |
| 158 | // userSentMessageAfterLoadState tracks if the user has sent their first message after we load the state |
| 159 | userSentMessageAfterLoadState bool |
| 160 | // loadStateStatus tracks the status of loading conversation state from file. |
| 161 | loadStateStatus LoadStateStatus |
| 162 | // initialPromptReady is set to true when ReadyForInitialPrompt returns true. |
| 163 | // Checked inline in the snapshot loop on each tick. |
| 164 | initialPromptReady bool |
| 165 | // initialPromptSent is set to true when the initial prompt has been enqueued to the outbound queue. |
| 166 | initialPromptSent bool |
| 167 | } |
| 168 | |
| 169 | var _ Conversation = &PTYConversation{} |
| 170 |
nothing calls this directly
no outgoing calls
no test coverage detected