Fix false positives in variable dependency validation

Only parse {variable} patterns in PromptSteps, not CodeSteps.

In CodeSteps, variables are available directly as Python variables
(e.g., use `input` not `{input}`). The {var} syntax in code is
typically Python f-string or .format() syntax, not CmdForge
template substitution.

This fixes false positives like artifact-ai where Python f-strings
like f"{format_guide}" were incorrectly flagged as missing CmdForge
variable references.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
rob 2026-01-15 23:29:13 -04:00
parent b8760eb208
commit 260ebf1b2f
1 changed files with 7 additions and 8 deletions

View File

@ -558,7 +558,10 @@ class ToolBuilderPage(QWidget):
def _get_step_variable_refs(self, step) -> set:
"""Extract variable references from a step.
Parses {variable} patterns from prompt templates and code.
Parses {variable} patterns from prompt templates.
Note: CodeSteps are NOT parsed because variables are available directly
as Python variables, and {var} in code is typically Python f-string
or .format() syntax, not CmdForge substitution.
"""
import re
refs = set()
@ -567,15 +570,11 @@ class ToolBuilderPage(QWidget):
pattern = r'\{(\w+)\}'
if isinstance(step, PromptStep):
# Parse prompt template
# Parse prompt template - these ARE CmdForge substitutions
matches = re.findall(pattern, step.prompt or "")
refs.update(matches)
elif isinstance(step, CodeStep):
# Parse code for variable references
# In code, variables are accessed directly, but we also check for {var} patterns
# since the code might use string formatting
matches = re.findall(pattern, step.code or "")
refs.update(matches)
# CodeStep: Don't parse - variables are available as Python vars directly
# and {var} syntax is typically Python string formatting
return refs