Repo: coder/agentapi
Scope: Add state file support to AgentAPI binary so conversation history survives restarts.
Changes:
- Add
--state-file <path> flag to agentapi server command
- Add
--load-state flag (default true when state-file set)
- Add
--save-state flag (default true when state-file set)
- Add
--pid-file <path> flag so shutdown scripts can signal the correct process
- Implement
Conversation.SaveState(path string) error
- Use atomic write: write to temp file, then rename to target path
- Implement
LoadState(path string) (*Conversation, error)
- Save state on SIGTERM, SIGINT, SIGHUP (skip if not dirty)
- Add SIGUSR1 handler to save without exit (for shutdown script coordination, can be called periodically)
- Track dirty flag: set on conversation change, clear on save
- State file format (JSON for schema compatibility):
{
"version": 1,
"messages": [...],
"initial_prompt": "...",
"initial_prompt_sent": true
}
Files (in agentapi repo):
lib/screentracker/conversation.go
cmd/server.go
Acceptance criteria:
Dependencies: None
References:
Repo:
coder/agentapiScope: Add state file support to AgentAPI binary so conversation history survives restarts.
Changes:
--state-file <path>flag toagentapi servercommand--load-stateflag (default true when state-file set)--save-stateflag (default true when state-file set)--pid-file <path>flag so shutdown scripts can signal the correct processConversation.SaveState(path string) errorLoadState(path string) (*Conversation, error){ "version": 1, "messages": [...], "initial_prompt": "...", "initial_prompt_sent": true }Files (in agentapi repo):
lib/screentracker/conversation.gocmd/server.goAcceptance criteria:
/messagesendpoint returns restored history after restartDependencies: None
References: