Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3e4c85

Browse files
laststylebender14autofix-ci[bot]tusharmath
authored
feat: persist mode in forge.yaml (tailcallhq#793)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Tushar Mathur <[email protected]>
1 parent 3579620 commit e3e4c85

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

crates/forge_main/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ update-informer = { version = "1.2.0", default-features = false, features = [
4343
"rustls-tls",
4444
] }
4545

46+
4647
[dev-dependencies]
4748
insta.workspace = true
4849
pretty_assertions.workspace = true

crates/forge_main/src/state.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use derive_setters::Setters;
22
use forge_api::{ConversationId, Model, ModelId, Provider, Usage};
3-
use serde::Deserialize;
3+
use strum_macros::EnumString;
44

55
use crate::prompt::ForgePrompt;
66

7-
// TODO: convert to a new type
8-
#[derive(Debug, Clone, Default, Deserialize)]
9-
#[serde(rename_all = "snake_case")]
7+
#[derive(Debug, Clone, Default, EnumString)]
8+
#[strum(ascii_case_insensitive)]
109
pub enum Mode {
1110
Plan,
1211
#[default]

crates/forge_main/src/ui.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::str::FromStr;
12
use std::sync::Arc;
23

34
use anyhow::{Context, Result};
@@ -101,6 +102,15 @@ impl<F: API> UI<F> {
101102
self.api.upsert_conversation(conversation).await?;
102103
}
103104

105+
// Update the workflow with the new mode
106+
self.api
107+
.update_workflow(self.cli.workflow.as_deref(), |workflow| {
108+
workflow
109+
.variables
110+
.insert("mode".to_string(), Value::from(mode.to_string()));
111+
})
112+
.await?;
113+
104114
self.writeln(TitleFormat::action(format!(
105115
"Switched to '{}' mode (context cleared)",
106116
self.state.mode
@@ -398,8 +408,7 @@ impl<F: API> UI<F> {
398408
let mode = workflow
399409
.variables
400410
.get("mode")
401-
.cloned()
402-
.and_then(|value| serde_json::from_value(value).ok())
411+
.and_then(|value| value.as_str().and_then(|m| Mode::from_str(m).ok()))
403412
.unwrap_or(Mode::Act);
404413

405414
self.state = UIState::new(mode).provider(self.api.environment().provider);
@@ -418,7 +427,7 @@ impl<F: API> UI<F> {
418427
self.api.upsert_conversation(conversation).await?;
419428
Ok(conversation_id)
420429
} else {
421-
let conversation = self.api.init_conversation(workflow.clone()).await?;
430+
let conversation = self.api.init_conversation(workflow).await?;
422431
self.state.conversation_id = Some(conversation.id.clone());
423432
self.update_model(conversation.main_model()?);
424433
Ok(conversation.id)

0 commit comments

Comments
 (0)