Skip to content

Warn when a model without delim reads ${...} text as variables - #104

Merged
yannrichet merged 2 commits into
mainfrom
claude/default-delim-warning
Nov 6, 2026
Merged

yannrichet merged 2 commits into
mainfrom
claude/default-delim-warning

Conversation

@yannrichet

Copy link
Copy Markdown
Member

Pull Request

Description

A model that sets neither delim nor var_delim reads both $(x) and ${x} as variables (DEFAULT_VAR_DELIM = "(){}", a 2.0 behavior change). Shell text such as ${HOME} next to $(x) variables was therefore silently listed by fzi() as a variable, and substituted if a variable of the same name was given. This PR makes that situation visible without changing any result.

Reproduced on main before the change:

# in.sh: "x=$(x)\necho ${HOME}\n", model without delim
fz.fzi("in.sh", {"output": {"o": "echo 1"}})   # {'HOME': None, 'x': None}, no message

Related Issues

Fixes #101

Type of Change

  • New feature (non-breaking change which adds functionality): warning plus a more explicit error message
  • Test addition/modification
  • Documentation update

Changes Made

  • fz/interpreter.py:
    • find_default_delim_brace_variables(input_path, model, varprefix, exclude_paths) returns the names seen only as ${name} when the model sets no delimiter, and whether the input also uses $(name).
    • warn_default_delim_brace_variables() logs one warning (stderr, via log_warning) per input path and set of names, per process. This de-duplication avoids repeating it on every fzd iteration.
    • default_delim_hint() builds the hint added to the error message.
  • fz/core.py:
    • fzi() warns only when ${...}-only names sit next to $(...) variables. Since fzc(), fzr() and fzd() all call fzi(), they warn too.
    • In fzc() and fzr(), the input_variables is required error now names the ${...}-only variables and suggests "delim": "()".
  • Docs: NEWS entry (under the "Default variable delimiters" item, in the current Unreleased / 2.0 section), doc/limitations.md, and a row in the skill's failure table (skills/fz/SKILL.md).

Choices made to limit false positives (points left open in the issue)

  • No warning for a template that uses only ${x} (the 1.2 CLI convention), for a name that appears in both forms, or for a model with an explicit delim / var_delim. That last case is the documented way to silence it.
  • No new opt-out env var (FZ_WARN_DEFAULT_DELIM was suggested in the issue): setting delim is enough, and it avoids growing the configuration surface.
  • Rejected criterion: a ${...} name absent from input_variables. A ${HOME} with no value is left unchanged in the compiled file, so that case alone causes no wrong result.

Testing Performed

Automated Tests

  • Added tests for new functionality: tests/test_default_delim_warning.py, 10 tests:
    • one warning for mixed forms, and only once;
    • compiled output unchanged;
    • no warning with delim="()", delim="{}" or var_delim="(){}";
    • no warning for a template using only ${x}, or the same name in both forms;
    • the error message names the ${...}-only variables, and no hint appears when delim is set;
    • the CLI's fz input --format json stdout stays valid JSON while the warning goes to stderr.
  • The tests fail without the change in fz/ (they reference the new helpers).
  • Full local suite (Linux, Python 3.13, ci.yml --ignore list): 5 failed, 1069 passed, 86 skipped. The 5 failures are the same pre-existing environmental ones as on main: 3 permission tests that fail when run as root, and 2 yq tests that fail because the installed yq is not the expected implementation.
  • Combined with release: prepare 2.0 (version, NEWS, plugin, version source, skill completeness) #103: the patch applies without conflict (NEWS, skill, core). test_default_delim_warning, test_skill_static and test_manifest pass together (27 tests).

Manual Testing

  • Tested on Linux

Additional Notes

  • Limited visibility: FZ_LOG_LEVEL defaults to ERROR, so this warning, like all other fz warnings (legacy cache, timeout), only shows with FZ_LOG_LEVEL=WARNING or lower. The hint in the error message is always visible. Showing this warning at the default level would require either an exception to the logging policy or a change of default level. That is not done here and is left to the maintainer.
  • Cost: when the model has no delim, fzi() scans the input twice more (() form and {} form). There is no extra cost when delim is set.
  • Merge order with release: prepare 2.0 (version, NEWS, plugin, version source, skill completeness) #103 does not matter: in both cases the NEWS entry ends up in the 2.0 section.

Generated by Claude Code

A model with neither "delim" nor "var_delim" reads both $(x) and ${x}
(DEFAULT_VAR_DELIM), so shell text such as ${HOME} next to $(x) variables
was silently listed by fzi() as a variable (and substituted if a variable
of that name was given).

- fz.interpreter: find_default_delim_brace_variables() returns the names
  seen only as ${name} when the model sets no delimiter, and whether the
  input also uses $(name); warn_default_delim_brace_variables() logs one
  warning (stderr) per input path and set of names per process.
- fzi() (hence fzc()/fzr()/fzd()) warns only when ${...}-only names sit next
  to $(...) variables: a template that uses only ${x} on purpose, or a
  model with an explicit delim, never warns. Results are unchanged.
- fzc()/fzr(): the "input_variables is required" error names the
  ${...}-only variables and suggests "delim": "()".
- tests/test_default_delim_warning.py (10 tests, including CLI stdout
  staying JSON); NEWS, doc/limitations.md, skill failure table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RjXvVRjM6aMvKvvSFoxpZ6
test_cli_stdout_stays_json read the child's output with the platform
default encoding; on Windows (cp1252) the warning's emoji cannot be
decoded, the reader thread failed and stderr was None. Decode as UTF-8
and make the child write UTF-8 (PYTHONIOENCODING).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RjXvVRjM6aMvKvvSFoxpZ6
@yannrichet
yannrichet merged commit f0e444e into main Nov 6, 2026
43 checks passed
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.

Warn when a model without delim turns ${...} template text into variables

2 participants