From 948c69e2e547236db1841f6f8471586ce6a71a36 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 23:53:39 +0000 Subject: [PATCH] fix(cli): handle empty YAML prompts --- src/prompts/processors/yaml.ts | 5 +++-- test/prompts/processors/yaml.test.ts | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/prompts/processors/yaml.ts b/src/prompts/processors/yaml.ts index ba1470b1df3d..cf135b8f6880 100644 --- a/src/prompts/processors/yaml.ts +++ b/src/prompts/processors/yaml.ts @@ -27,8 +27,9 @@ export function processYamlFile(filePath: string, prompt: Partial): Prom // Recursively resolve any file:// references in the parsed structure const resolved = maybeLoadConfigFromExternalFile(parsed); - // Convert back to JSON string - maybeParsed = JSON.stringify(resolved); + // Convert back to JSON while preserving the raw contents of empty YAML documents. + // JSON.stringify(undefined) returns undefined, but Prompt.raw must always be a string. + maybeParsed = JSON.stringify(resolved) ?? fileContents; } catch (e) { logger.debug(`Error parsing YAML file ${filePath}: ${e}`); } diff --git a/test/prompts/processors/yaml.test.ts b/test/prompts/processors/yaml.test.ts index 6f591a649532..0356b5264bb6 100644 --- a/test/prompts/processors/yaml.test.ts +++ b/test/prompts/processors/yaml.test.ts @@ -277,9 +277,8 @@ template: "{{ variable }} " const result = processYamlFile(filePath, {}); expect(result).toHaveLength(1); - // Empty YAML parses to undefined; maybeLoadConfigFromExternalFile passes it - // through; JSON.stringify(undefined) is the literal string "undefined". - expect(result[0].raw).toBe(JSON.stringify(undefined)); + expect(result[0].raw).toBe(''); + expect(result[0].label).toBe(`${filePath}: `); }); }); });