MCPcopy Create free account
hub / github.com/idank/explainshell / sanitize_option_fields

Function sanitize_option_fields

explainshell/extraction/llm/response.py:167–200  ·  view source on GitHub ↗

Fix common LLM mistakes in option fields. Returns (short, long, has_argument, positional, nested_cmd, prefix).

(
    short: list[str],
    long: list[str],
    has_argument: bool | list[str],
    positional: str | None,
    nested_cmd: bool,
    prefix: str | None = None,
)

Source from the content-addressed store, hash-verified

165
166
167def sanitize_option_fields(
168 short: list[str],
169 long: list[str],
170 has_argument: bool | list[str],
171 positional: str | None,
172 nested_cmd: bool,
173 prefix: str | None = None,
174) -> tuple[list[str], list[str], bool | list[str], str | None, bool, str | None]:
175 """Fix common LLM mistakes in option fields.
176
177 Returns (short, long, has_argument, positional, nested_cmd, prefix).
178 """
179 if positional and (short or long):
180 logger.debug(
181 "clearing positional=%r on flagged option %s/%s", positional, short, long
182 )
183 positional = None
184
185 if prefix and not positional:
186 logger.debug("clearing prefix=%r on non-positional option", prefix)
187 prefix = None
188
189 if prefix and prefix not in models.OPTION_PREFIX_SIGILS:
190 logger.debug(
191 "dropping prefix=%r on positional %r: not in sigil allowlist",
192 prefix,
193 positional,
194 )
195 prefix = None
196
197 if nested_cmd and not has_argument:
198 has_argument = True
199
200 return short, long, has_argument, positional, nested_cmd, prefix
201
202
203def llm_option_to_store_option(

Calls

no outgoing calls