Conversations
Lexicon uses structured conversations to guide artifact creation. Conversations are state machines, not free-form chat. Each workflow defines a sequence of steps that collect input and produce output.
This is a key product differentiator. The lexicon chat command does not just dump static files. Instead, it opens an interactive, guided session that:
- Asks structured questions
- Proposes an initial artifact
- Shows the draft to the user
- Opens an AI-assisted refinement conversation
- Lets the user iterate on the artifact conversationally
- Updates the generated artifact based on the conversation
- Records enough metadata to improve future generations
- Preserves explicit boundaries between stable contract and speculative ideas
The tool treats artifact creation as an evolving conversation, not a one-shot form.
Context That Gets Better Over Time
Section titled “Context That Gets Better Over Time”The conversational workflow gets better as more artifacts are created. The system preserves and reuses context like:
- repo type and library domain
- past contract patterns
- scoring preferences and gate policies
- naming conventions
- prior user decisions
- prior AI-generated artifacts
- prior conversation summaries
This context is inspectable and local to the repo. It is not a vague “chat mode” — it is explicit conversational artifact refinement.
The Workflow Trait
Section titled “The Workflow Trait”All interactive workflows implement the Workflow trait:
pub trait Workflow { type Context; // Accumulated state during the workflow type Output; // Final artifact produced
fn name(&self) -> &str; fn steps(&self) -> &[WorkflowStep]; fn initial_context(&self) -> Self::Context; fn execute_step( &self, step_idx: usize, ctx: &mut Self::Context, input: StepInput, ) -> StepOutput; fn finalize(&self, ctx: Self::Context) -> Option<Self::Output>;}Key design points:
Contextaccumulates decisions as the user progresses through stepsexecute_stepis called with user input and returns what to show nextfinalizeproduces the output artifact (e.g., a Contract TOML file) orNoneif the user aborted
Each WorkflowStep has:
id— Unique step identifierprompt— Human-readable descriptionskippable— Whether the step can be skipped
Input and Output
Section titled “Input and Output”StepInput
Section titled “StepInput”What the user provides at each step:
UserResponse(String)— Typed text responseAccept— Accepted a proposal as-isRefine(String)— Requested changes with feedbackSkip— Skipped this step
StepOutput
Section titled “StepOutput”What the workflow presents:
Question— Ask the user a question (with optional default, suggestions, multiline support)Proposal— Present a draft artifact for review (with title, content, and format hint)Info— Show informational textAdvance— Step completed silently, move onDone— Workflow is complete
The ConversationDriver Trait
Section titled “The ConversationDriver Trait”The ConversationDriver trait abstracts user interaction, allowing the same workflow to run in different contexts:
pub trait ConversationDriver { fn present_question(&self, question: &Question) -> Result<String>; fn present_proposal(&self, proposal: &Proposal) -> Result<ProposalResponse>; fn present_info(&self, message: &str);}Lexicon ships with a TerminalDriver that uses dialoguer for CLI prompts. The driver abstraction also enables automated testing via mock drivers.
Proposal Responses
Section titled “Proposal Responses”When a proposal is presented, the user can:
- Accept — Use the proposal as-is
- Refine(feedback) — Request changes with specific feedback
- Skip — Skip this step (if the step is skippable)
- Abort — Cancel the entire workflow
The Conversation Engine
Section titled “The Conversation Engine”The ConversationEngine drives a workflow through its steps:
- Creates a
ConversationSessionfor recording - Builds the initial context
- Iterates through each step, presenting output via the driver and collecting input
- Records every step, decision, and response in the session
- Calls
finalizeto produce the output artifact - Marks the session as completed (or abandoned if aborted)
Session Persistence
Section titled “Session Persistence”Every conversation is recorded as a ConversationSession stored in .lexicon/conversations/. Sessions track:
- Workflow kind (Init, ContractNew, ContractEdit, ScoreInit, etc.)
- Status (Active, Completed, Abandoned)
- Each step with its type and content
- Decisions made at each step
Chat sessions are auto-saved after every turn. On resume, lexicon displays the session topic (the first substantive user message) and the last AI response, so you immediately have context about what you were working on.
Action errors during a session are fed back to the AI as context, enabling it to diagnose failures and suggest corrections rather than repeating the same mistakes.
Conversation memory is not hidden magic — it is inspectable. Sessions are local to the repo and can be reviewed at any time.
Workflow Kinds
Section titled “Workflow Kinds”Lexicon defines these workflow kinds:
Init— Repository initializationContractNew— Creating a new contractContractEdit— Editing an existing contractConformanceAdd— Adding conformance testsBehaviorAdd— Adding behavior scenariosScoreInit— Initializing the scoring modelGateInit— Initializing gatesImprove— AI-guided improvement loop