Skip to main content

build

Function build 

Source
pub fn build(
    cfg: &Config,
    repo: PathBuf,
    idea: &str,
    agent: Option<&str>,
    from: Option<&Chat>,
) -> Result<Chat>
Expand description

Construct a conversation record in memory, without writing it anywhere.

Split out of open so a caller can claim crate::web::Ui::begin_turn on chat.id before the record is ever written to disk - chat_post does exactly that, because Chats::put is what makes the id visible to every other request (GET /api/chats, POST /api/chats/{id}/say), and a gap between “the file exists” and “the turn is claimed” is a window for chat_say to claim and record into an interview whose first turn never ran - see chat_post’s doc for the failure that produces.

agent is resolved by plan::pick, the same policy magi plan uses: an explicit id wins and is an error rather than a fallback when it is not runnable, otherwise a claude seat, otherwise the first runnable agent in roster order. Called rather than copied, because two copies of a preference order drift and the copy that drifts is the one nobody reads.

from is the conversation this one was derived from, when the operator asked to continue an existing interview in a different repository (see derived_background). It is read, never written: the source chat’s status, turns and draft are left exactly as they were.