Skip to content

Commit eb37660

Browse files
committed
fix(core): spreads of optional config sections stay optional
Fresh-setup and first-install paths (crestodian setup inference, hook installs, agent config base, target agent models) legitimately lack the section being rebuilt; spreading undefined is the shipped {} semantics. Removes the remaining gratuitous assertion wraps found by tree audit.
1 parent 90856e6 commit eb37660

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/commands/agents.config.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { expectDefined } from "@openclaw/normalization-core";
21
// Agent config mutation and summary builders used by `openclaw agents` commands.
32
import {
43
normalizeOptionalString,
@@ -127,12 +126,10 @@ export function applyAgentConfig(
127126
const name = params.name?.trim();
128127
const list = listAgentEntries(cfg);
129128
const index = findAgentEntryIndex(list, agentId);
130-
const base = index >= 0 ? list[index] : { id: agentId };
131-
const mergedIdentity = params.identity
132-
? { ...expectDefined(base, "agents.config base").identity, ...params.identity }
133-
: undefined;
129+
const base = (index >= 0 ? list[index] : undefined) ?? { id: agentId };
130+
const mergedIdentity = params.identity ? { ...base.identity, ...params.identity } : undefined;
134131
const nextEntry: AgentEntry = {
135-
...expectDefined(base, "agents.config base"),
132+
...base,
136133
...(name ? { name } : {}),
137134
...(params.workspace ? { workspace: params.workspace } : {}),
138135
...(params.agentDir ? { agentDir: params.agentDir } : {}),

src/crestodian/setup-inference.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ function copySelectedModelMetadata(params: {
706706
params.target.agents = {
707707
...params.target.agents,
708708
defaults: {
709-
...expectDefined(params.target.agents?.defaults, "agent defaults"),
709+
...params.target.agents?.defaults,
710710
models: {
711711
...params.target.agents?.defaults?.models,
712712
[params.modelRef]: structuredClone(
@@ -739,7 +739,7 @@ function copySelectedModelMetadata(params: {
739739
return;
740740
}
741741
targetAgent.models = {
742-
...expectDefined(targetAgent.models, "agent models"),
742+
...targetAgent.models,
743743
[params.modelRef]: structuredClone(
744744
expectDefined(preparedAgent.models[params.modelRef], "models entry at params.model ref"),
745745
),
@@ -798,7 +798,7 @@ function projectManualInferenceConfig(params: {
798798
throw new Error(`Prepared provider config missing for ${providerConfigKey}`);
799799
}
800800
config.models = {
801-
...expectDefined(config.models, "configured models"),
801+
...config.models,
802802
providers: {
803803
...config.models?.providers,
804804
[providerConfigKey]: structuredClone(preparedProvider),

src/hooks/installs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function recordHookInstall(cfg: OpenClawConfig, update: HookInstallUpdate
2323
hooks: {
2424
...cfg.hooks,
2525
internal: {
26-
...expectDefined(cfg.hooks?.internal, "internal hook configuration"),
26+
...cfg.hooks?.internal,
2727
installs: {
2828
...installs,
2929
[hookId]: expectDefined(installs[hookId], "installs entry at hook id"),

0 commit comments

Comments
 (0)