suggestion: The precedence between auto_exec_args, selected_event, and selected_challenge for the same field names could be made more explicit.
Right now the resolution order is:
- auto_exec_args[prop_name]
- selected_event for ["ctf_id", "id", "event_id"]
- selected_challenge for ["challenge_id", "id"].
If both selected_event and selected_challenge are set and the schema field is just "id", the event ID will be used, which may be surprising in challenge-oriented tools. You could either remove ambiguous keys like bare "id" from these lists, or add logic/comments that clearly tie which ID is chosen to the tool context (event vs challenge).
Suggested implementation:
for prop_name, prop_details in properties.items():
value_placeholder = None
prop_type = prop_details.get("type", "string")
# Value resolution precedence:
# 1) auto_exec_args[prop_name] (highest priority, explicit override)
# 2) selected_event for ["ctf_id", "event_id"]
# 3) selected_challenge for ["challenge_id"]
#
# Note: we intentionally do NOT auto-fill bare "id" from either selected_event
# or selected_challenge to avoid ambiguity when both are set. Only explicit,
# context-specific keys are used here.
auto_exec_args = getattr(self, "auto_exec_args", {}) or {}
# 1) Use auto_exec_args if available
if prop_name in auto_exec_args:
value_placeholder = auto_exec_args[prop_name]
# 2) Fall back to selected_event for event-related fields
elif selected_event is not None and prop_name in ("ctf_id", "event_id"):
# Prefer the explicit field when present, otherwise fall back to "id"
value_placeholder = (
selected_event.get(prop_name)
or selected_event.get("id")
)
# 3) Fall back to selected_challenge for challenge-related fields
elif selected_challenge is not None and prop_name in ("challenge_id",):
# Prefer the explicit field when present, otherwise fall back to "id"
value_placeholder = (
selected_challenge.get(prop_name)
or selected_challenge.get("id")
)
Provides an interactive terminal interface for browsing CTF events and challenges,
Depending on the rest of the codebase, you may want to:
- Review any places that relied on auto-filling a bare "id" field from selected_event or selected_challenge and either:
- Update those tools' schemas to use "event_id" or "challenge_id", or
- Add explicit logic there if they truly need a generic "id".
- If there are tools that are strictly event-only or challenge-only and must still auto-fill a bare "id", you can:
- Add a tool-context flag (e.g., is_event_tool / is_challenge_tool) and branch inside the precedence logic to map "id" appropriately for those tools only.
Originally posted by @sourcery-ai[bot] in #1 (comment)
suggestion: The precedence between auto_exec_args, selected_event, and selected_challenge for the same field names could be made more explicit.
Right now the resolution order is:
If both selected_event and selected_challenge are set and the schema field is just "id", the event ID will be used, which may be surprising in challenge-oriented tools. You could either remove ambiguous keys like bare "id" from these lists, or add logic/comments that clearly tie which ID is chosen to the tool context (event vs challenge).
Suggested implementation:
Depending on the rest of the codebase, you may want to:
Originally posted by @sourcery-ai[bot] in #1 (comment)