package acp type updateKind string const ( updateUserChunk updateKind = "user_message_chunk" updateAgentChunk updateKind = "agent_message_chunk" updateThoughtChunk updateKind = "agent_thought_chunk" updateToolCall updateKind = "tool_call" updateToolStatus updateKind = "tool_call_update" updateConfigChange updateKind = "config_option_update" updateCommands updateKind = "available_commands_update" updateUsage updateKind = "usage_update" updateCompaction updateKind = "compaction_update" ) func (k updateKind) coalesces() bool { return k == updateAgentChunk || k == updateThoughtChunk } type textBlock struct { Type string `json:"type"` Text string `json:"text"` } func textContent(text string) textBlock { return textBlock{Type: "text", Text: text} } type contentChunk struct { Kind updateKind `json:"sessionUpdate"` MessageID string `json:"messageId,omitempty"` Content textBlock `json:"content"` } func chunkOf(kind updateKind, messageID, text string) contentChunk { return contentChunk{Kind: kind, MessageID: messageID, Content: textContent(text)} } type configOptionsUpdate struct { Kind updateKind `json:"sessionUpdate"` Options []option `json:"configOptions"` } func configChanged(options []option) configOptionsUpdate { return configOptionsUpdate{Kind: updateConfigChange, Options: options} } type configOptionsResult struct { Options []option `json:"configOptions"` } func configResult(options []option) configOptionsResult { return configOptionsResult{Options: options} } type command struct { Name string `json:"name"` Description string `json:"description"` } type sessionSummary struct { SessionID string `json:"sessionId"` Cwd string `json:"cwd"` Title string `json:"title"` UpdatedAt *string `json:"updatedAt,omitempty"` } type sessionList struct { Sessions []sessionSummary `json:"sessions"` NextCursor *string `json:"nextCursor,omitempty"` } type commandsUpdate struct { Kind updateKind `json:"sessionUpdate"` Commands []command `json:"availableCommands"` } type cost struct { Amount float64 `json:"amount"` Currency string `json:"currency"` } const ( currencyUSD = "USD" currencyCredits = "credits" ) type usageUpdate struct { Kind updateKind `json:"sessionUpdate"` Used int `json:"used"` Size int `json:"size"` Cost *cost `json:"cost,omitempty"` } type compactionStatus string const ( compactionCompleted compactionStatus = "completed" compactionFailed compactionStatus = "failed" ) type compactionUpdate struct { Kind updateKind `json:"sessionUpdate"` ID string `json:"compactionId"` Status compactionStatus `json:"status"` Summary []textBlock `json:"summary,omitempty"` Error string `json:"error,omitempty"` } type toolKind string const ( toolOther toolKind = "other" toolEdit toolKind = "edit" toolRead toolKind = "read" toolSearch toolKind = "search" toolExecute toolKind = "execute" toolFetch toolKind = "fetch" ) type toolStatus string const ( toolRunning toolStatus = "in_progress" toolDone toolStatus = "completed" toolRefused toolStatus = "failed" ) var evidenceKinds = map[string]toolKind{ "edit": toolEdit, "read": toolRead, "search": toolSearch, "run": toolExecute, "web": toolFetch, } type contentBlock struct { Type string `json:"type"` Content textBlock `json:"content"` } func wrappedText(text string) contentBlock { return contentBlock{Type: "content", Content: textContent(text)} } type diffBlock struct { Type string `json:"type"` Path string `json:"path"` OldText *string `json:"oldText"` NewText string `json:"newText"` } type location struct { Path string `json:"path"` } type toolCall struct { Kind updateKind `json:"sessionUpdate"` ID string `json:"toolCallId"` Title string `json:"title,omitempty"` Name string `json:"name,omitempty"` ToolKind toolKind `json:"kind"` Status toolStatus `json:"status,omitempty"` RawInput any `json:"rawInput,omitempty"` RawOutput any `json:"rawOutput,omitempty"` Content []any `json:"content,omitempty"` Locations []location `json:"locations,omitempty"` } func announcedTool(id, title, name string) toolCall { return toolCall{Kind: updateToolCall, ID: id, Title: title, Name: name, ToolKind: toolOther, Status: toolRunning} } func progressedTool(id string) toolCall { return toolCall{Kind: updateToolStatus, ID: id, Status: toolRunning} }