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

Function dedup_options

explainshell/extraction/llm/response.py:245–279  ·  view source on GitHub ↗

Remove options with duplicate (short+long) flag sets (from chunk overlap). When duplicates exist, keep the entry with the longest description so that detailed sections win over brief summary entries.

(raw_options: list[dict])

Source from the content-addressed store, hash-verified

243
244
245def dedup_options(raw_options: list[dict]) -> list[dict]:
246 """Remove options with duplicate (short+long) flag sets (from chunk overlap).
247
248 When duplicates exist, keep the entry with the longest description so that
249 detailed sections win over brief summary entries.
250 """
251 best: dict[tuple, tuple[int, dict]] = {}
252 positional: list[tuple[int, dict]] = []
253 for idx, opt in enumerate(raw_options):
254 try:
255 raw_short = opt.get("short") or []
256 raw_long = opt.get("long") or []
257 if not isinstance(raw_short, list) or not isinstance(raw_long, list):
258 positional.append((idx, opt))
259 continue
260 short = tuple(sorted(str(s) for s in raw_short))
261 long = tuple(sorted(str(s) for s in raw_long))
262 except (TypeError, AttributeError):
263 positional.append((idx, opt))
264 continue
265 key = (short, long)
266 if not short and not long:
267 positional.append((idx, opt))
268 continue
269 prev = best.get(key)
270 if prev is None:
271 best[key] = (idx, opt)
272 else:
273 old_desc = len(prev[1].get("description") or "")
274 new_desc = len(opt.get("description") or "")
275 if new_desc > old_desc:
276 best[key] = (idx, opt)
277 all_entries = list(best.values()) + positional
278 all_entries.sort(key=lambda x: x[0])
279 return [opt for _, opt in all_entries]
280
281
282def dedup_ref_options(raw_options: list[dict]) -> list[dict]:

Calls

no outgoing calls