Skip to content

fix(config): honor frontmatter prompt when agent .md body is empty#26489

Open
rogerdigital wants to merge 1 commit intoanomalyco:devfrom
rogerdigital:fix/honor-frontmatter-prompt-when-body-empty
Open

fix(config): honor frontmatter prompt when agent .md body is empty#26489
rogerdigital wants to merge 1 commit intoanomalyco:devfrom
rogerdigital:fix/honor-frontmatter-prompt-when-body-empty

Conversation

@rogerdigital
Copy link
Copy Markdown

Issue for this PR

Closes #26434

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When an agent .md file declares prompt: in YAML frontmatter but has an empty markdown body, config/agent.ts unconditionally 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() and loadMode():

  1. 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.

  2. 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.

  3. Applies ConfigVariable.substitute to agent/mode .md prompts{env:VAR} and {file:path} placeholders now resolve in .md agent prompts, consistent with how they already work in opencode.json agent configs. Previously these stayed as literal strings in .md files.

  4. 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?

  • Added 4 test cases in test/config/config.test.ts:
    • Frontmatter-only prompt (empty body) → uses frontmatter value
    • Both body and frontmatter → body wins
    • {env:VAR} substitution in body
    • {file:path} substitution in frontmatter prompt
  • All 85 config tests pass, all 40 agent tests pass
  • Typecheck clean on modified files (pre-existing failures in unrelated http-recorder package)

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: agent .md prompt: frontmatter field is silently overridden by markdown body, producing empty prompt and silent fallback to default agent prompt

1 participant