Skip to content

Commit b90e804

Browse files
authored
fix(desktop): treat baked build env vars as satisfying required agent config (#1580)
1 parent 683f7fe commit b90e804

11 files changed

Lines changed: 431 additions & 37 deletions

File tree

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,17 @@ const overrides = new Map([
119119
// linux-updater isAutoUpdateSupported() binding + onboarding has_profile_event field.
120120
// config-bridge-aware requirements: getRuntimeFileConfig command adds ~15 lines.
121121
// +26 lines from PRs landing on main between prior rebase and this rebase.
122-
["src/shared/api/tauri.ts", 1375],
122+
// baked-env-required-badge: getBakedBuildEnvKeys wrapper adds ~16 lines. Queued to split.
123+
["src/shared/api/tauri.ts", 1388],
123124
// readiness-gate: PersonaDialog.tsx threads computeLocalModeGate +
124125
// requiredCredentialEnvKeys + RequiredFieldLabel so the "New agent" dialog
125126
// shows required markers and credential amber rows (parity with
126127
// CreateAgentDialog). +23 lines of gate wiring. Queued to split.
127128
// config-bridge-aware requirements: useRuntimeFileConfigQuery wiring adds
128129
// ~16 lines. Queued to split.
129-
["src/features/agents/ui/PersonaDialog.tsx", 1032],
130+
// baked-env-required-badge: useBakedBuildEnvKeysQuery + bakedEnvKeys wiring
131+
// + correct exclusion-semantics for requiredEnvKeys adds ~14 lines. Queued to split.
132+
["src/features/agents/ui/PersonaDialog.tsx", 1046],
130133
// harness-persona-sync feature growth, queued to split in the resolver-unify
131134
// refactor followup. discovery.rs is dominated by the new test module
132135
// (the effective_agent_command / divergent / create-time override matrix);

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,27 @@ pub fn get_runtime_file_config(runtime_id: String) -> Option<RuntimeFileConfigSu
184184
}
185185
}
186186

187+
/// Return the key names of all non-empty baked build env vars.
188+
///
189+
/// Internal (Block) builds bake provider credentials and other env pairs into
190+
/// the binary at compile time via `BUZZ_BUILD_AGENT_ENV`. The backend readiness
191+
/// gate already treats these keys as satisfying their requirements (Layer 1 of
192+
/// `resolve_effective_agent_env`). This command exposes the *key names only* —
193+
/// never the values — so the frontend dialogs can apply the same logic and avoid
194+
/// surfacing a spurious "Required" badge for keys that are covered by the baked
195+
/// env.
196+
///
197+
/// OSS builds have no baked env, so this returns an empty list — OSS behavior
198+
/// is unchanged.
199+
#[tauri::command]
200+
pub fn get_baked_build_env_keys() -> Vec<String> {
201+
crate::managed_agents::baked_build_env()
202+
.into_iter()
203+
.filter(|(_, v)| !v.is_empty())
204+
.map(|(k, _)| k)
205+
.collect()
206+
}
207+
187208
/// Get the full config surface for a managed agent.
188209
///
189210
/// Returns normalized + advanced config from all available tiers.

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ pub fn run() {
530530
discover_agent_models,
531531
get_agent_config_surface,
532532
get_runtime_file_config,
533+
get_baked_build_env_keys,
533534
put_agent_session_config,
534535
mesh_availability,
535536
mesh_start_node,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
mod agent_env;
22
pub(crate) mod agent_events;
3-
pub(crate) use agent_env::{build_buzz_agent_provider_defaults, discovery_env_with_baked_floor};
3+
pub(crate) use agent_env::{
4+
baked_build_env, build_buzz_agent_provider_defaults, discovery_env_with_baked_floor,
5+
};
46
mod backend;
57
pub(crate) mod config_bridge;
68
mod discovery;

‎desktop/src/features/agents/hooks.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
discoverBackendProviders,
1616
discoverManagedAgentPrereqs,
1717
getAgentConfigSurface,
18+
getBakedBuildEnvKeys,
1819
getManagedAgentLog,
1920
getRuntimeFileConfig,
2021
installAcpRuntime,
@@ -647,6 +648,31 @@ export function useRuntimeFileConfigQuery(
647648
});
648649
}
649650

651+
export const bakedBuildEnvKeysQueryKey = ["baked-build-env-keys"] as const;
652+
653+
/**
654+
* Query the key names of baked build env vars.
655+
*
656+
* Internal (Block) builds bake provider credentials into the binary at compile
657+
* time. This query returns the *key names only* so dialogs can treat baked keys
658+
* as satisfying their requirements — mirroring the backend readiness gate.
659+
*
660+
* The value is a compile-time constant, so `staleTime: Infinity` is correct.
661+
* In web-dev and E2E contexts where the Tauri command doesn't exist the query
662+
* fails soft and resolves to `undefined` without crashing (same class as
663+
* `useRuntimeFileConfigQuery`).
664+
*/
665+
export function useBakedBuildEnvKeysQuery(options?: { enabled?: boolean }) {
666+
return useQuery({
667+
queryKey: bakedBuildEnvKeysQueryKey,
668+
queryFn: () => getBakedBuildEnvKeys(),
669+
enabled: options?.enabled ?? true,
670+
staleTime: Infinity,
671+
refetchInterval: false,
672+
retry: false,
673+
});
674+
}
675+
650676
export function useTeamsQuery() {
651677
return useQuery({
652678
queryKey: teamsQueryKey,

‎desktop/src/features/agents/ui/CreateAgentDialog.tsx‎

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useAcpRuntimesQuery,
66
useAvailableAcpRuntimes,
77
useBackendProvidersQuery,
8+
useBakedBuildEnvKeysQuery,
89
useCreateManagedAgentMutation,
910
useManagedAgentPrereqsQuery,
1011
useRuntimeFileConfigQuery,
@@ -41,6 +42,7 @@ import { meshPrepareRelayMeshClient } from "@/shared/api/tauriMesh";
4142
import type { MeshServeTarget } from "@/shared/api/tauriMesh";
4243
import { useLastRuntime } from "@/features/agents/lib/useLastRuntime";
4344
import {
45+
getBakedSatisfiedEnvKeys,
4446
requiredCredentialEnvKeys,
4547
runtimeSupportsLlmProviderSelection,
4648
shouldClearKnownModelForSelectionScope,
@@ -182,28 +184,45 @@ export function CreateAgentDialog({
182184
selectedRuntimeId,
183185
{ enabled: open },
184186
);
187+
const { data: bakedEnvKeys } = useBakedBuildEnvKeysQuery({ enabled: open });
188+
189+
// All required keys for the selected runtime + provider.
190+
const allRequiredEnvKeys = React.useMemo(
191+
() =>
192+
requiredCredentialEnvKeys(
193+
selectedRuntimeId,
194+
runtimeSupportsLlmProviderSelection(selectedRuntimeId) ? provider : "",
195+
),
196+
[selectedRuntimeId, provider],
197+
);
198+
199+
// Keys covered by the baked build env (Block-internal builds only) — silenced,
200+
// produce no amber row or info row.
201+
const bakedSatisfiedEnvKeys = React.useMemo(
202+
() => getBakedSatisfiedEnvKeys(allRequiredEnvKeys, envVars, bakedEnvKeys),
203+
[allRequiredEnvKeys, envVars, bakedEnvKeys],
204+
);
205+
185206
// Credential keys satisfied by the runtime file config (e.g. goose config.yaml).
186207
// These are shown as "Set in goose config" rows rather than amber required rows.
187208
const fileSatisfiedEnvKeys = React.useMemo(() => {
188209
if (!runtimeFileConfig) return [] as string[];
189-
const allKeys = requiredCredentialEnvKeys(
190-
selectedRuntimeId,
191-
runtimeSupportsLlmProviderSelection(selectedRuntimeId) ? provider : "",
192-
);
193-
return allKeys.filter(
210+
return allRequiredEnvKeys.filter(
194211
(key) =>
195212
(envVars[key] ?? "").length === 0 &&
213+
!bakedSatisfiedEnvKeys.includes(key) &&
196214
runtimeFileConfig.satisfiedEnvKeys.includes(key),
197215
);
198-
}, [runtimeFileConfig, selectedRuntimeId, provider, envVars]);
216+
}, [runtimeFileConfig, allRequiredEnvKeys, envVars, bakedSatisfiedEnvKeys]);
199217

200218
const requiredEnvKeys = React.useMemo(
201219
() =>
202-
requiredCredentialEnvKeys(
203-
selectedRuntimeId,
204-
runtimeSupportsLlmProviderSelection(selectedRuntimeId) ? provider : "",
205-
).filter((key) => !fileSatisfiedEnvKeys.includes(key)),
206-
[selectedRuntimeId, provider, fileSatisfiedEnvKeys],
220+
allRequiredEnvKeys.filter(
221+
(key) =>
222+
!bakedSatisfiedEnvKeys.includes(key) &&
223+
!fileSatisfiedEnvKeys.includes(key),
224+
),
225+
[allRequiredEnvKeys, bakedSatisfiedEnvKeys, fileSatisfiedEnvKeys],
207226
);
208227

209228
// Clear model when provider scope changes, mirroring EditAgentDialog.

‎desktop/src/features/agents/ui/PersonaDialog.tsx‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
CUSTOM_PROVIDER_DROPDOWN_VALUE,
4444
computeLocalModeGate,
4545
formatRuntimeOptionLabel,
46+
getBakedSatisfiedEnvKeys,
4647
getDefaultLlmProviderLabel,
4748
getDefaultPersonaRuntime,
4849
getModelSelectValue,
@@ -69,7 +70,7 @@ import {
6970
MODEL_DISCOVERY_LOADING_VALUE,
7071
usePersonaModelDiscovery,
7172
} from "./usePersonaModelDiscovery";
72-
import { useRuntimeFileConfigQuery } from "../hooks";
73+
import { useBakedBuildEnvKeysQuery, useRuntimeFileConfigQuery } from "../hooks";
7374

7475
type PersonaDialogProps = {
7576
open: boolean;
@@ -431,7 +432,9 @@ export function PersonaDialog({
431432
const { data: runtimeFileConfig } = useRuntimeFileConfigQuery(runtime, {
432433
enabled: open,
433434
});
435+
const { data: bakedEnvKeys } = useBakedBuildEnvKeysQuery({ enabled: open });
434436
const localModeGate = computeLocalModeGate({
437+
bakedEnvKeys,
435438
envVars,
436439
isProviderMode: false,
437440
model,
@@ -440,12 +443,23 @@ export function PersonaDialog({
440443
runtimeFileConfig,
441444
useMesh: false,
442445
});
443-
// Required keys for EnvVarsEditor amber rows: exclude file-satisfied keys
444-
// so they render in the "Set in goose config" row instead.
445-
const requiredEnvKeys = requiredCredentialEnvKeys(
446+
// Required keys for EnvVarsEditor amber locked rows: all required keys except
447+
// those silenced by baked env or file config. Filled keys stay in the amber
448+
// row (exclusion semantics, not missing-only), matching the other consumers.
449+
const allRequiredEnvKeys = requiredCredentialEnvKeys(
446450
runtime,
447451
trimmedProvider,
448-
).filter((key) => !localModeGate.fileSatisfiedEnvKeys.includes(key));
452+
);
453+
const bakedSatisfiedPersonaKeys = getBakedSatisfiedEnvKeys(
454+
allRequiredEnvKeys,
455+
envVars,
456+
bakedEnvKeys,
457+
);
458+
const requiredEnvKeys = allRequiredEnvKeys.filter(
459+
(key) =>
460+
!bakedSatisfiedPersonaKeys.includes(key) &&
461+
!localModeGate.fileSatisfiedEnvKeys.includes(key),
462+
);
449463
// Provider required-ness is a static property of the runtime — it does not
450464
// change based on whether the field is currently filled. Using the dynamic
451465
// missingNormalizedFields check would flip the asterisk off once a value is

0 commit comments

Comments
 (0)