fix(prompt): default omitted conditional flags to false (#424)

Always apply conditional-line filtering so tagged prompt lines are removed unless the corresponding boolean flag is explicitly true. Add regressions for omitted flags with and without format variables.

Test: pytest tests/unit/test_prompt_handler.py -q
This commit is contained in:
Ziyang Guo 2026-08-06 16:22:59 +08:00 committed by GitHub
parent 23d4c96c15
commit 6503e1271c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -116,8 +116,7 @@ class PromptHandler:
flags = {k: v for k, v in kwargs.items() if isinstance(v, bool)}
formats = {k: v for k, v in kwargs.items() if not isinstance(v, bool)}
if flags:
prompt = self._apply_flag_filter(prompt, flags)
prompt = self._apply_flag_filter(prompt, flags)
return prompt.format(**formats).strip() if formats else prompt

View file

@ -182,13 +182,18 @@ def test_flag_filter_removes_non_matching():
def test_flag_filter_default_false():
ph = PromptHandler()
ph.load_prompt_dict({"p": "[debug] debug info\nbase"})
# When no flags are passed at all, _apply_flag_filter is not called,
# so flagged lines are kept as-is (including the tag text after regex sub).
result = ph.prompt_format("p", debug=False)
result = ph.prompt_format("p")
assert "debug info" not in result
assert "base" in result
def test_flag_filter_defaults_false_with_format_variables():
ph = PromptHandler()
ph.load_prompt_dict({"p": "[debug] debug {name}\nhello {name}"})
result = ph.prompt_format("p", name="Alice")
assert result == "hello Alice"
def test_flag_filter_unflagged_lines_always_kept():
ph = PromptHandler()
ph.load_prompt_dict({"p": "line1\nline2\nline3"})