MCPcopy Index your code
hub / github.com/idank/explainshell / normalize_subcommands

Function normalize_subcommands

explainshell/extraction/llm/response.py:15–24  ·  view source on GitHub ↗

Strip parent-name prefix and deduplicate subcommand names. LLMs sometimes return ``["git-add", "git-commit"]`` instead of ``["add", "commit"]``. This strips the ``{basename}-`` prefix when present and deduplicates while preserving order.

(basename: str, raw: list[str])

Source from the content-addressed store, hash-verified

13
14
15def normalize_subcommands(basename: str, raw: list[str]) -> list[str]:
16 """Strip parent-name prefix and deduplicate subcommand names.
17
18 LLMs sometimes return ``["git-add", "git-commit"]`` instead of
19 ``["add", "commit"]``. This strips the ``{basename}-`` prefix when
20 present and deduplicates while preserving order.
21 """
22 prefix = f"{basename}-"
23 stripped = [s[len(prefix) :] if s.startswith(prefix) else s for s in raw]
24 return list(dict.fromkeys(stripped))
25
26
27def fix_invalid_escapes(s: str) -> str:

Callers 4

_finalizeMethod · 0.90
test_deduplicatesMethod · 0.90

Calls

no outgoing calls

Tested by 3

test_deduplicatesMethod · 0.72