fix(vscode): avoid writing null agent config fields

Omit unset agent fields on create
Delete cleared agent fields in VS Code config updates
Cover null field removal with a regression test
This commit is contained in:
Bohdan Triapitsyn
2026-06-29 11:56:40 +03:00
parent c48d57bfaf
commit 00fd15c356
4 changed files with 73 additions and 4 deletions
+32 -1
View File
@@ -1605,12 +1605,30 @@ export const createAgent = (agentName: string, config: Record<string, unknown>,
}
// Extract scope and prompt from config - scope is only used for path determination, not written to file
const { prompt, scope: _ignored, ...frontmatter } = config as Record<string, unknown> & { prompt?: unknown; scope?: unknown };
const { prompt, scope: _ignored, ...rawFrontmatter } = config as Record<string, unknown> & { prompt?: unknown; scope?: unknown };
void _ignored; // Scope is only used for path determination
const frontmatter = Object.fromEntries(
Object.entries(rawFrontmatter).filter(([, value]) => value !== null && value !== undefined)
);
writeMdFile(targetPath, frontmatter, typeof prompt === 'string' ? prompt : '');
resetAgentLookupCache(globalAgentLookupCache);
};
const deleteAgentJsonField = (config: Record<string, unknown>, agentName: string, field: string): boolean => {
const agentMap = config.agent as Record<string, unknown> | undefined;
const current = agentMap?.[agentName] as Record<string, unknown> | undefined;
if (!agentMap || !current || !(field in current)) return false;
delete current[field];
if (Object.keys(current).length === 0) {
delete agentMap[agentName];
}
if (Object.keys(agentMap).length === 0) {
delete config.agent;
}
return true;
};
export const updateAgent = (agentName: string, updates: Record<string, unknown>, workingDirectory?: string) => {
ensureDirs();
@@ -1757,6 +1775,19 @@ export const updateAgent = (agentName: string, updates: Record<string, unknown>,
const hasMdField = Boolean(mdData?.frontmatter?.[field] !== undefined);
const hasJsonField = Boolean(jsonSection?.[field] !== undefined);
if (value === null) {
if (hasMdField && mdData) {
delete mdData.frontmatter[field];
mdModified = true;
}
if (hasJsonField && deleteAgentJsonField(config, agentName, field)) {
jsonModified = true;
}
continue;
}
// JSON takes precedence over md, so update JSON first if field exists there
if (hasJsonField) {
if (!config.agent) config.agent = {};