fix(config): honor frontmatter prompt when agent .md body is empty#26489
Open
rogerdigital wants to merge 1 commit intoanomalyco:devfrom
Open
fix(config): honor frontmatter prompt when agent .md body is empty#26489rogerdigital wants to merge 1 commit intoanomalyco:devfrom
rogerdigital wants to merge 1 commit intoanomalyco:devfrom
Conversation
When an agent .md file declares prompt: in YAML frontmatter but has an
empty markdown body, the prompt was unconditionally overwritten with ""
causing silent fallback to the default system prompt.
Now body takes precedence only when non-empty, otherwise frontmatter
prompt is used. Also applies ConfigVariable.substitute ({env:VAR} and
{file:path}) to agent/mode .md prompts for consistency with JSON config,
and warns at runtime when a custom agent's prompt resolves to empty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #26434
Type of change
What does this PR do?
When an agent
.mdfile declaresprompt:in YAML frontmatter but has an empty markdown body,config/agent.tsunconditionally overwrites the frontmatter value with the empty body string. This causes the agent to silently fall back to the default system prompt with no warning.The fix changes the precedence logic in both
load()andloadMode():Body takes precedence only when non-empty — if body is empty, frontmatter
prompt:is used instead. This is fully backward-compatible since all existing agents that use the body convention have non-empty bodies.Warns when both are present — if an agent has both a non-empty body and frontmatter
prompt:, a warning is logged clarifying that body wins. This catches ambiguous configs at load time.Applies
ConfigVariable.substituteto agent/mode .md prompts —{env:VAR}and{file:path}placeholders now resolve in.mdagent prompts, consistent with how they already work inopencode.jsonagent configs. Previously these stayed as literal strings in.mdfiles.Runtime warning when custom agent prompt is empty — in
llm.ts, logs a warning if a non-native agent's prompt resolves to empty before falling back to the provider default. This catches any remaining silent-empty-prompt path.How did you verify your code works?
test/config/config.test.ts:{env:VAR}substitution in body{file:path}substitution in frontmatter prompthttp-recorderpackage)Screenshots / recordings
N/A — no UI changes.
Checklist