(self, prompt: str, limit: int = 5)
| 88 | |
| 89 | class PortRuntime: |
| 90 | def route_prompt(self, prompt: str, limit: int = 5) -> list[RoutedMatch]: |
| 91 | tokens = {token.lower() for token in prompt.replace('/', ' ').replace('-', ' ').split() if token} |
| 92 | by_kind = { |
| 93 | 'command': self._collect_matches(tokens, PORTED_COMMANDS, 'command'), |
| 94 | 'tool': self._collect_matches(tokens, PORTED_TOOLS, 'tool'), |
| 95 | } |
| 96 | |
| 97 | selected: list[RoutedMatch] = [] |
| 98 | for kind in ('command', 'tool'): |
| 99 | if by_kind[kind]: |
| 100 | selected.append(by_kind[kind].pop(0)) |
| 101 | |
| 102 | leftovers = sorted( |
| 103 | [match for matches in by_kind.values() for match in matches], |
| 104 | key=lambda item: (-item.score, item.kind, item.name), |
| 105 | ) |
| 106 | selected.extend(leftovers[: max(0, limit - len(selected))]) |
| 107 | return selected[:limit] |
| 108 | |
| 109 | def bootstrap_session(self, prompt: str, limit: int = 5) -> RuntimeSession: |
| 110 | context = build_port_context() |
no test coverage detected