Skip to content

Commit

Permalink
fix: agent variables don't initialized if start session with last mes…
Browse files Browse the repository at this point in the history
…sage (#1054)
  • Loading branch information
sigoden authored Dec 13, 2024
1 parent c0f34d4 commit 737580b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/config/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl Agent {
None => &mut self.shared_variables,
};
let Some(old_value) = variables.get(key) else {
bail!("Unknown variable: '{key}'")
bail!("Unknown variable '{key}'")
};
if old_value == value {
return Ok(());
Expand Down
8 changes: 5 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,10 @@ impl Config {
}
}
}
let mut new_session = false;
if let Some(session) = session.as_mut() {
if session.is_empty() {
new_session = true;
if let Some((input, output)) = &self.last_message {
if self.agent.is_some() == input.with_agent() {
let ans = Confirm::new(
Expand All @@ -1064,7 +1066,7 @@ impl Config {
}
}
self.session = session;
self.init_agent_session_variables()?;
self.init_agent_session_variables(new_session)?;
Ok(())
}

Expand Down Expand Up @@ -2033,12 +2035,12 @@ impl Config {
Ok(())
}

fn init_agent_session_variables(&mut self) -> Result<()> {
fn init_agent_session_variables(&mut self, new_session: bool) -> Result<()> {
let (agent, session) = match (self.agent.as_mut(), self.session.as_mut()) {
(Some(agent), Some(session)) => (agent, session),
_ => return Ok(()),
};
if session.is_empty() {
if new_session {
let shared_variables = agent.shared_variables().clone();
let session_variables =
if !agent.defined_variables().is_empty() && shared_variables.is_empty() {
Expand Down

0 comments on commit 737580b

Please sign in to comment.