Skip to content

Conversation

35C4n0r
Copy link
Collaborator

@35C4n0r 35C4n0r commented Oct 2, 2025

Closes #111

Usage example

agentapi server -I="Hello World" --term-width 76 --term-height 1190 -- copilot

@35C4n0r 35C4n0r requested review from johnstcn and matifali October 2, 2025 06:47
@35C4n0r 35C4n0r self-assigned this Oct 2, 2025
Copy link

github-actions bot commented Oct 2, 2025

✅ Preview binaries are ready!

To test with modules: agentapi_version = "agentapi_112" or download from: https://github.com/coder/agentapi/releases/tag/agentapi_112

Comment on lines 316 to 325
// Send initial prompt when agent becomes stable for the first time
if !s.initialPromptSent && convertStatus(currentStatus) == AgentStatusStable {
if err := s.conversation.SendMessage(FormatMessage(s.agentType, s.initialPrompt)...); err != nil {
s.logger.Error("Failed to send initial prompt", "error", err)
} else {
s.initialPromptSent = true
currentStatus = st.ConversationStatusChanging
s.logger.Info("Initial prompt sent successfully")
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an inherent race condition here: we will report "stable" status for a short time period before "changing". Is it possible to prevent this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think line 322 would prevent that:

currentStatus = st.ConversationStatusChanging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see now, I assumed that the status updates were done in a separate goroutine but it's actually done in UpdateStatusAndEmitChanges() below in line 326.

I think it's worth adding a test for this behaviour so that we can validate that we don't send an extraneous status update.

I also think this logic might be better encapsulated inside the Conversation.

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests for this new functionality?

Comment on lines 316 to 325
// Send initial prompt when agent becomes stable for the first time
if !s.initialPromptSent && convertStatus(currentStatus) == AgentStatusStable {
if err := s.conversation.SendMessage(FormatMessage(s.agentType, s.initialPrompt)...); err != nil {
s.logger.Error("Failed to send initial prompt", "error", err)
} else {
s.initialPromptSent = true
currentStatus = st.ConversationStatusChanging
s.logger.Info("Initial prompt sent successfully")
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see now, I assumed that the status updates were done in a separate goroutine but it's actually done in UpdateStatusAndEmitChanges() below in line 326.

I think it's worth adding a test for this behaviour so that we can validate that we don't send an extraneous status update.

I also think this logic might be better encapsulated inside the Conversation.

Copy link

github-actions bot commented Oct 2, 2025

✅ Preview binaries are ready!

To test with modules: agentapi_version = "agentapi_112" or download from: https://github.com/coder/agentapi/releases/tag/agentapi_112

@35C4n0r
Copy link
Collaborator Author

35C4n0r commented Oct 2, 2025

@johnstcn

I also think this logic might be better encapsulated inside the Conversation.

Done

I think it's worth adding a test for this behaviour so that we can validate that we don't send an extraneous status update.

+1, I'm confused on how to test this.

@DevelopmentCats
Copy link
Contributor

Approving so we can get this released for the copilot-cli module release

@matifali matifali requested a review from johnstcn October 3, 2025 07:58
@johnstcn
Copy link
Member

johnstcn commented Oct 3, 2025

+1, I'm confused on how to test this.

With the current implementation, I think you'd need to test the StartSnapshotLoop() function of the server but pass in both an EventEmitter and a Conversation that you control in the test.

@johnstcn
Copy link
Member

johnstcn commented Oct 3, 2025

+1, I'm confused on how to test this.

With the current implementation, I think you'd need to test the StartSnapshotLoop() function of the server but pass in both an EventEmitter and a Conversation that you control in the test.

Created a separate issue to track this #114

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock.

@DevelopmentCats DevelopmentCats merged commit c5162c8 into coder:main Oct 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add flag to accept an initial prompt
3 participants