Skip to content

Commit 9c6fa14

Browse files
wpfleger96Hayt
andauthored
feat(desktop): offer Claude effort levels in agent edit and create (#8059)
Claude Code agents now get a thinking-effort dropdown in the agent Edit and Create dialogs, matching the one buzz-agent and Codex agents already have. ## Behavior - **Where levels come from:** Claude effort levels come from the Claude model data for the model that will actually run after Save, resolved in order: explicit model, then inherited default (linked definition or global), then adapter default. Stored Claude session levels are not used, because the stored session data does not record which model produced them. - **Edit:** for an agent linked to a definition, effort follows the definition's model, which stays authoritative. Save never sends a model for linked agents. - **Create:** effort is offered for local agents only and is stored on the instance. Allowed levels are recomputed on every render, so collapsing Advanced and then switching to a model without effort (e.g. Haiku) drops effort from the request. Non-local effort is rejected before any create side effects. - **Persistence:** `create_managed_agent` sets the picked effort when it builds the record and drops stale effort env aliases. Its body runs over any Tauri runtime, so a mock-app test drives the real create path and reads the record back from disk. That test runs in a child process with temp app-data and nest folders, and a test-only switch turns keychain use off so agent keys stay inline in the temp agent file and the OS keychain is never touched. - **Observer store:** live session-config captures are written to the store before the dialog refreshes; archived captures are read-only. - **Codex:** its existing session-native effort picker is unchanged. --------- Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: Hayt <211b96e6a2b7f45fd4047988976c7bbbeeda0c15f3ae7b32eec20834b5a55118@buzz.block.builderlab.xyz>
1 parent d0fd96f commit 9c6fa14

33 files changed

Lines changed: 1658 additions & 184 deletions

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export default defineConfig({
168168
"**/agent-lifecycle-feedback.spec.ts",
169169
"**/agent-access-warning.spec.ts",
170170
"**/edit-agent-run-on.spec.ts",
171+
"**/claude-effort-picker.spec.ts",
171172
"**/inbox-live-update.spec.ts",
172173
"**/mesh-compute.spec.ts",
173174
"**/observer-archive-policy.spec.ts",

‎desktop/src-tauri/src/commands/agent_models_update.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ pub(crate) fn stamp_record_updated_at(
118118
}
119119

120120
/// Flush a retained managed-agent policy, preserving any earlier profile error.
121-
pub(crate) async fn flush_managed_agent_policy(
122-
app: &AppHandle,
121+
pub(crate) async fn flush_managed_agent_policy<R: tauri::Runtime>(
122+
app: &AppHandle<R>,
123123
state: &AppState,
124124
existing_error: Option<String>,
125125
) -> Option<String> {

‎desktop/src-tauri/src/commands/agents.rs‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub(crate) use pending::{retain_managed_agent_pending, tombstone_managed_agent_p
3636
/// For one-shot command paths only — the 5s list poll calls
3737
/// `build_managed_agent_summary` directly with stores loaded once per call,
3838
/// not once per record.
39-
pub(super) fn summarize_from_disk(
40-
app: &AppHandle,
39+
pub(super) fn summarize_from_disk<R: tauri::Runtime>(
40+
app: &AppHandle<R>,
4141
record: &ManagedAgentRecord,
4242
runtimes: &std::collections::HashMap<
4343
crate::managed_agents::ManagedAgentRuntimeKey,
@@ -393,6 +393,14 @@ pub async fn create_managed_agent(
393393
input: CreateManagedAgentRequest,
394394
app: AppHandle,
395395
state: State<'_, AppState>,
396+
) -> Result<CreateManagedAgentResponse, String> {
397+
create_managed_agent_in(input, app, &state).await
398+
}
399+
400+
async fn create_managed_agent_in<R: tauri::Runtime>(
401+
input: CreateManagedAgentRequest,
402+
app: AppHandle<R>,
403+
state: &AppState,
396404
) -> Result<CreateManagedAgentResponse, String> {
397405
let name = input.name.trim().to_string();
398406
let requested_persona_id = input
@@ -649,7 +657,7 @@ pub async fn create_managed_agent(
649657
input.parallelism,
650658
linked_persona.as_ref(),
651659
)?;
652-
let record = ManagedAgentRecord {
660+
let mut record = ManagedAgentRecord {
653661
pubkey: pubkey.clone(),
654662
name: name.clone(),
655663
description: None,
@@ -743,7 +751,9 @@ pub async fn create_managed_agent(
743751
},
744752
effort_level: None,
745753
};
746-
754+
if let Some(level) = input.effort_level.clone() {
755+
super::agent_config::apply_picker_effort_level(&mut record, Some(level));
756+
}
747757
records.push(record);
748758

749759
save_managed_agents(&app, &records)?;
@@ -755,7 +765,7 @@ pub async fn create_managed_agent(
755765
// Publish the agent to the relay. Inside the Phase-3 lock, after save,
756766
// before any .await — owner-authored, every agent (Will's ruling: no
757767
// is_builtin/persona-membership gate).
758-
retain_managed_agent_pending(&app, &state, record);
768+
retain_managed_agent_pending(&app, state, record);
759769
// Effective owner-authored description for the kind:0 `about`.
760770
let profile_about = crate::managed_agents::record_effective_description(record, &personas);
761771
(
@@ -768,8 +778,7 @@ pub async fn create_managed_agent(
768778
// ── Phase 3b: local spawn (async preflight outside store lock) ───────────
769779
let mut spawn_error = None;
770780
let agent = if input.spawn_after_create && input.backend == BackendKind::Local {
771-
match start_local_agent_with_preflight(&app, &state, &pubkey, true, None, None, None).await
772-
{
781+
match start_local_agent_with_preflight(&app, state, &pubkey, true, None, None, None).await {
773782
Ok(agent) => agent,
774783
Err(error) => {
775784
let _store_guard = state
@@ -803,7 +812,7 @@ pub async fn create_managed_agent(
803812
// Use the avatar persisted on the record so the published profile and any
804813
// later reconciliation agree on the same value.
805814
let mut profile_sync_error = profile::publish_agent_profile_with_about(
806-
&state,
815+
state,
807816
&resolved_relay_url,
808817
&agent_keys,
809818
&name,
@@ -813,7 +822,7 @@ pub async fn create_managed_agent(
813822
)
814823
.await;
815824
profile_sync_error =
816-
super::agent_models::flush_managed_agent_policy(&app, &state, profile_sync_error).await;
825+
super::agent_models::flush_managed_agent_policy(&app, state, profile_sync_error).await;
817826

818827
let spawn_error = if input.spawn_after_create && input.backend != BackendKind::Local {
819828
if let BackendKind::Provider { ref id, ref config } = input.backend {
@@ -827,10 +836,10 @@ pub async fn create_managed_agent(
827836
.iter()
828837
.find(|r| r.pubkey == pubkey)
829838
.ok_or_else(|| "agent disappeared".to_string())?;
830-
build_deploy_payload(&app, &state, rec)?
839+
build_deploy_payload(&app, state, rec)?
831840
};
832841
match deploy_to_provider(
833-
&app, &state, &pubkey, id, config, agent_json, None, None, None, None,
842+
&app, state, &pubkey, id, config, agent_json, None, None, None, None,
834843
)
835844
.await
836845
{

‎desktop/src-tauri/src/commands/agents/provider_deploy.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use super::build_deploy_payload;
3939
/// message exactly like a local spawn. Per-invocation only — never persisted
4040
/// on the record, so later redeploys do not carry a stale floor.
4141
#[allow(clippy::too_many_arguments)]
42-
pub(crate) async fn deploy_to_provider(
43-
app: &AppHandle,
42+
pub(crate) async fn deploy_to_provider<R: tauri::Runtime>(
43+
app: &AppHandle<R>,
4444
state: &AppState,
4545
pubkey: &str,
4646
_provider_id: &str,

‎desktop/src-tauri/src/commands/agents_tests.rs‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,3 +793,91 @@ fn owner_only_access_deploy_payload_clamps_stale_access() {
793793
"owner-only-access deploy payload retained a stale allowlist"
794794
);
795795
}
796+
797+
/// Runs the real create in a child process: temp app-data and nest paths,
798+
/// keychain use turned off so agent keys stay inline in the temp agent file,
799+
/// and no background work outliving the test.
800+
#[test]
801+
fn create_managed_agent_persists_picked_effort_and_drops_env_aliases() {
802+
const CHILD: &str = "BUZZ_CREATE_EFFORT_TEST_HOME";
803+
if let Some(home) = std::env::var_os(CHILD) {
804+
return create_with_effort_in_confined_child(std::path::Path::new(&home));
805+
}
806+
let home = tempfile::tempdir().unwrap();
807+
let output = std::process::Command::new(std::env::current_exe().unwrap())
808+
.args(["--exact", "commands::agents::tests::create_managed_agent_persists_picked_effort_and_drops_env_aliases", "--nocapture"])
809+
.env(CHILD, home.path()).env("HOME", home.path())
810+
.env("XDG_DATA_HOME", home.path()).env("APPDATA", home.path())
811+
.env("LOCALAPPDATA", home.path())
812+
.env_remove("BUZZ_PRIVATE_KEY").env_remove("BUZZ_AUTH_TAG")
813+
.env_remove("BUZZ_RELAY_URL").env_remove("BUZZ_NETWORK_TRACE")
814+
.output().unwrap();
815+
let stdout = String::from_utf8_lossy(&output.stdout);
816+
assert!(
817+
output.status.success() && stdout.contains("1 passed"),
818+
"child failed: {stdout}\n{}",
819+
String::from_utf8_lossy(&output.stderr)
820+
);
821+
}
822+
823+
fn create_with_effort_in_confined_child(home: &std::path::Path) {
824+
use tauri::Manager;
825+
crate::managed_agents::storage::NO_KEYCHAIN_FOR_TEST
826+
.store(true, std::sync::atomic::Ordering::SeqCst);
827+
crate::managed_agents::pin_nest_dir_for_test(home.join("nest"));
828+
// Windows known-folder APIs ignore HOME/APPDATA; an absolute mock
829+
// identifier replaces the app-data base on every platform.
830+
let app_data = home.join("app-data");
831+
let mut context = tauri::test::mock_context(tauri::test::noop_assets());
832+
context.config_mut().identifier = app_data.to_str().unwrap().to_owned();
833+
834+
// Unroutable relay: profile publish fails fast and is reported, not fatal.
835+
const RELAY: &str = "ws://127.0.0.1:9";
836+
let state = crate::app_state::build_app_state();
837+
*state.relay_url_override.lock().unwrap() = Some(RELAY.to_string());
838+
let app = tauri::test::mock_builder()
839+
.manage(state)
840+
.build(context)
841+
.expect("mock app builds headless");
842+
assert_eq!(app.path().app_data_dir().unwrap(), app_data);
843+
let alias = crate::managed_agents::config_bridge::effort::effort_suppress_keys()[0];
844+
let create = |name: &str, effort: Option<&str>| {
845+
let input: CreateManagedAgentRequest = serde_json::from_value(serde_json::json!({
846+
"name": name, "relayUrl": RELAY, "acpCommand": null,
847+
"agentCommand": null, "idleTimeoutSeconds": null,
848+
"maxTurnDurationSeconds": null, "parallelism": null,
849+
"systemPrompt": null, "avatarUrl": null, "model": null,
850+
"provider": null, "effortLevel": effort,
851+
"envVars": { alias: "low" }, "spawnAfterCreate": false,
852+
}))
853+
.unwrap();
854+
let state = app.state::<AppState>();
855+
tauri::async_runtime::block_on(create_managed_agent_in(input, app.handle().clone(), &state))
856+
.expect("create succeeds")
857+
.agent
858+
.pubkey
859+
};
860+
let picked = create("Picked", Some("high"));
861+
let unpicked = create("Unpicked", None);
862+
let records = load_managed_agents(app.handle()).unwrap();
863+
864+
let find = |pubkey: &str| records.iter().find(|r| r.pubkey == pubkey).unwrap();
865+
assert_eq!(find(&picked).effort_level.as_deref(), Some("high"));
866+
assert!(!find(&picked).env_vars.contains_key(alias));
867+
assert_eq!(find(&unpicked).effort_level, None);
868+
assert!(
869+
find(&unpicked).env_vars.contains_key(alias),
870+
"no pick leaves env alone"
871+
);
872+
// The keychain step was skipped: both keys are still inline on disk.
873+
let path = crate::managed_agents::storage::managed_agents_store_path(app.handle()).unwrap();
874+
let raw: Vec<serde_json::Value> =
875+
serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap();
876+
for pubkey in [&picked, &unpicked] {
877+
let entry = raw.iter().find(|r| r["pubkey"] == pubkey.as_str()).unwrap();
878+
assert!(entry["private_key_nsec"]
879+
.as_str()
880+
.unwrap()
881+
.starts_with("nsec1"));
882+
}
883+
}

‎desktop/src-tauri/src/commands/managed_agent_definition.rs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
//! Managed-agent definition validation at local mutation boundaries.
22
3-
use crate::managed_agents::{CreateManagedAgentRequest, ManagedAgentRecord};
3+
use crate::managed_agents::{BackendKind, CreateManagedAgentRequest, ManagedAgentRecord};
44

55
pub(super) fn validate_create_definition(
66
name: &str,
77
persona_id: Option<&str>,
88
input: &CreateManagedAgentRequest,
99
) -> Result<(), String> {
10+
if input.effort_level.is_some() && input.backend != BackendKind::Local {
11+
return Err("remote effort is set at deploy time".to_string());
12+
}
1013
validate_definition_fields(name, persona_id, input.system_prompt.as_deref())
1114
}
1215

@@ -96,6 +99,23 @@ mod tests {
9699
}
97100
}
98101

102+
#[test]
103+
fn create_rejects_effort_for_non_local_backend_only() {
104+
let mut input = create_request("Review code.");
105+
input.effort_level = Some("high".to_string());
106+
validate_create_definition("Reviewer", None, &input).expect("local effort is accepted");
107+
input.backend = BackendKind::Provider {
108+
id: "provider".into(),
109+
config: serde_json::json!({}),
110+
};
111+
let error = validate_create_definition("Reviewer", None, &input)
112+
.expect_err("provider create must reject effort before any side effect");
113+
assert!(error.contains("deploy time"), "unexpected error: {error}");
114+
input.effort_level = None;
115+
validate_create_definition("Reviewer", None, &input)
116+
.expect("provider create without effort is unchanged");
117+
}
118+
99119
#[test]
100120
fn create_accepts_visible_multiline_definition_less_prompt() {
101121
let input = create_request("Review changes.\n\tCall out security risks.");

‎desktop/src-tauri/src/managed_agents/nest.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ pub fn init_nest_dir(is_dev: bool) {
8989
let _ = NEST_DIR.set(path);
9090
}
9191

92+
/// Pin the nest root for a child-process test so background nest work cannot
93+
/// reach the user's real nest.
94+
#[cfg(test)]
95+
pub(crate) fn pin_nest_dir_for_test(path: PathBuf) {
96+
NEST_DIR
97+
.set(Some(path))
98+
.expect("nest dir pinned before first use");
99+
}
100+
92101
/// Returns the nest root path (`~/.buzz` for prod, `~/.buzz-dev` for dev),
93102
/// or `None` if the home directory cannot be resolved.
94103
///

‎desktop/src-tauri/src/managed_agents/persona_events.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ pub async fn flush_pending_events(
312312
/// The scope snapshots its relay, owner keys, and database path together
313313
/// before network work starts. Switching communities during the flush cannot
314314
/// redirect rows from the old scope into the new relay.
315-
pub async fn flush_active_pending_events(
316-
app: &tauri::AppHandle,
315+
pub async fn flush_active_pending_events<R: tauri::Runtime>(
316+
app: &tauri::AppHandle<R>,
317317
state: &AppState,
318318
) -> Result<u32, String> {
319319
let scope = crate::managed_agents::retention::active_retention_scope(app, state)?;

‎desktop/src-tauri/src/managed_agents/storage.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,22 @@ fn agent_keyring_name(pubkey: &str) -> String {
1919
format!("agent:{pubkey}")
2020
}
2121

22+
/// Process-wide: a confined child-process test turns this on so agent keys
23+
/// stay inline, as in a build without a keychain.
24+
#[cfg(test)]
25+
pub(crate) static NO_KEYCHAIN_FOR_TEST: std::sync::atomic::AtomicBool =
26+
std::sync::atomic::AtomicBool::new(false);
27+
2228
/// The agent secret store. `None` when the build has no keyring backend, in
2329
/// which case agent keys stay inline in the `0o600` JSON file. Uses
2430
/// `SecretStore::shared` so identity and agent callers share one instance —
2531
/// and therefore one in-memory cache and one mutex — preventing last-writer-wins
2632
/// races on concurrent blob writes.
2733
fn agent_secret_store() -> Option<&'static SecretStore> {
34+
#[cfg(test)]
35+
if NO_KEYCHAIN_FOR_TEST.load(std::sync::atomic::Ordering::SeqCst) {
36+
return None;
37+
}
2838
if cfg!(feature = "system-keyring") {
2939
Some(SecretStore::shared(keyring_service()))
3040
} else {

‎desktop/src-tauri/src/managed_agents/types/requests.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ pub struct CreateManagedAgentRequest {
204204
pub respond_to_allowlist: Vec<String>,
205205
#[serde(default)]
206206
pub relay_mesh: Option<RelayMeshConfig>,
207+
/// Local-only thinking effort saved before the first spawn.
208+
#[serde(default)]
209+
pub effort_level: Option<String>,
207210
}
208211

209212
/// Patch request for updating a managed agent's mutable fields.

0 commit comments

Comments
 (0)