tau-coding-agent 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tau/__init__.py +0 -0
- tau/agent/__init__.py +11 -0
- tau/agent/prompt/__init__.py +10 -0
- tau/agent/prompt/builder.py +302 -0
- tau/agent/prompt/types.py +33 -0
- tau/agent/service.py +369 -0
- tau/agent/types.py +61 -0
- tau/auth/manager.py +247 -0
- tau/auth/storage.py +82 -0
- tau/auth/types.py +41 -0
- tau/builtins/__init__.py +4 -0
- tau/builtins/__pycache__/__init__.cpython-313.pyc +0 -0
- tau/builtins/__pycache__/__init__.cpython-314.pyc +0 -0
- tau/builtins/commands/__init__.py +41 -0
- tau/builtins/commands/__pycache__/__init__.cpython-313.pyc +0 -0
- tau/builtins/commands/__pycache__/__init__.cpython-314.pyc +0 -0
- tau/builtins/commands/__pycache__/clear.cpython-313.pyc +0 -0
- tau/builtins/commands/__pycache__/clear.cpython-314.pyc +0 -0
- tau/builtins/commands/__pycache__/compact.cpython-313.pyc +0 -0
- tau/builtins/commands/__pycache__/compact.cpython-314.pyc +0 -0
- tau/builtins/commands/__pycache__/reload.cpython-313.pyc +0 -0
- tau/builtins/commands/__pycache__/reload.cpython-314.pyc +0 -0
- tau/builtins/commands/__pycache__/session.cpython-313.pyc +0 -0
- tau/builtins/commands/__pycache__/session.cpython-314.pyc +0 -0
- tau/builtins/commands/clear.py +16 -0
- tau/builtins/commands/compact.py +28 -0
- tau/builtins/commands/reload.py +27 -0
- tau/builtins/commands/session.py +19 -0
- tau/builtins/extensions/footer/__init__.py +76 -0
- tau/builtins/extensions/footer/__pycache__/__init__.cpython-313.pyc +0 -0
- tau/builtins/extensions/footer/__pycache__/git.cpython-313.pyc +0 -0
- tau/builtins/extensions/footer/__pycache__/model.cpython-313.pyc +0 -0
- tau/builtins/extensions/footer/__pycache__/utils.cpython-313.pyc +0 -0
- tau/builtins/extensions/footer/git.py +26 -0
- tau/builtins/extensions/footer/model.py +69 -0
- tau/builtins/extensions/footer/utils.py +44 -0
- tau/builtins/extensions/header/__init__.py +18 -0
- tau/builtins/extensions/header/__pycache__/__init__.cpython-313.pyc +0 -0
- tau/builtins/models/__init__.py +0 -0
- tau/builtins/models/__pycache__/__init__.cpython-313.pyc +0 -0
- tau/builtins/models/__pycache__/text.cpython-313.pyc +0 -0
- tau/builtins/models/audio.py +43 -0
- tau/builtins/models/image.py +43 -0
- tau/builtins/models/text.py +482 -0
- tau/builtins/models/video.py +40 -0
- tau/builtins/prompts/commit.md +7 -0
- tau/builtins/prompts/docs.md +7 -0
- tau/builtins/prompts/explain.md +7 -0
- tau/builtins/prompts/fix.md +7 -0
- tau/builtins/prompts/refactor.md +7 -0
- tau/builtins/prompts/review.md +7 -0
- tau/builtins/prompts/test.md +7 -0
- tau/builtins/providers/__init__.py +0 -0
- tau/builtins/providers/__pycache__/__init__.cpython-313.pyc +0 -0
- tau/builtins/providers/__pycache__/text.cpython-313.pyc +0 -0
- tau/builtins/providers/audio.py +10 -0
- tau/builtins/providers/image.py +9 -0
- tau/builtins/providers/text.py +33 -0
- tau/builtins/providers/video.py +6 -0
- tau/builtins/skills/code-review/SKILL.md +4 -0
- tau/builtins/skills/debug/SKILL.md +4 -0
- tau/builtins/skills/git-commit/SKILL.md +4 -0
- tau/builtins/themes/dark.yaml +1 -0
- tau/builtins/themes/light.yaml +46 -0
- tau/builtins/tools/__init__.py +73 -0
- tau/builtins/tools/__pycache__/__init__.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/__init__.cpython-314.pyc +0 -0
- tau/builtins/tools/__pycache__/bash.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/bash.cpython-314.pyc +0 -0
- tau/builtins/tools/__pycache__/edit.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/edit.cpython-314.pyc +0 -0
- tau/builtins/tools/__pycache__/glob.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/glob.cpython-314.pyc +0 -0
- tau/builtins/tools/__pycache__/grep.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/grep.cpython-314.pyc +0 -0
- tau/builtins/tools/__pycache__/ls.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/ls.cpython-314.pyc +0 -0
- tau/builtins/tools/__pycache__/read.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/read.cpython-314.pyc +0 -0
- tau/builtins/tools/__pycache__/terminal.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/terminal.cpython-314.pyc +0 -0
- tau/builtins/tools/__pycache__/write.cpython-313.pyc +0 -0
- tau/builtins/tools/__pycache__/write.cpython-314.pyc +0 -0
- tau/builtins/tools/edit.py +215 -0
- tau/builtins/tools/glob.py +112 -0
- tau/builtins/tools/grep.py +146 -0
- tau/builtins/tools/ls.py +135 -0
- tau/builtins/tools/read.py +122 -0
- tau/builtins/tools/terminal.py +150 -0
- tau/builtins/tools/write.py +105 -0
- tau/commands/__init__.py +10 -0
- tau/commands/registry.py +71 -0
- tau/commands/types.py +33 -0
- tau/console/__init__.py +0 -0
- tau/console/cli.py +266 -0
- tau/console/commands/__init__.py +0 -0
- tau/console/commands/auth.py +193 -0
- tau/console/commands/packages.py +104 -0
- tau/console/commands/update.py +76 -0
- tau/core/__init__.py +0 -0
- tau/core/registry.py +102 -0
- tau/engine/__init__.py +47 -0
- tau/engine/service.py +768 -0
- tau/engine/types.py +163 -0
- tau/extensions/__init__.py +28 -0
- tau/extensions/api.py +928 -0
- tau/extensions/context.py +462 -0
- tau/extensions/events.py +70 -0
- tau/extensions/loader.py +386 -0
- tau/extensions/runtime.py +184 -0
- tau/extensions/settings.py +137 -0
- tau/hooks/__init__.py +112 -0
- tau/hooks/engine.py +237 -0
- tau/hooks/inference.py +21 -0
- tau/hooks/runtime.py +126 -0
- tau/hooks/service.py +121 -0
- tau/hooks/session.py +117 -0
- tau/hooks/tui.py +61 -0
- tau/hooks/types.py +72 -0
- tau/inference/__init__.py +180 -0
- tau/inference/api/__init__.py +0 -0
- tau/inference/api/audio/__init__.py +0 -0
- tau/inference/api/audio/base.py +29 -0
- tau/inference/api/audio/builtins.py +15 -0
- tau/inference/api/audio/elevenlabs_audio.py +183 -0
- tau/inference/api/audio/gemini_audio.py +95 -0
- tau/inference/api/audio/openai_audio.py +159 -0
- tau/inference/api/audio/registry.py +15 -0
- tau/inference/api/audio/sarvam_audio.py +163 -0
- tau/inference/api/audio/service.py +103 -0
- tau/inference/api/audio/utils.py +47 -0
- tau/inference/api/image/__init__.py +0 -0
- tau/inference/api/image/base.py +17 -0
- tau/inference/api/image/builtins.py +8 -0
- tau/inference/api/image/gemini_image.py +77 -0
- tau/inference/api/image/openai_image.py +103 -0
- tau/inference/api/image/openrouter.py +144 -0
- tau/inference/api/image/registry.py +15 -0
- tau/inference/api/image/service.py +71 -0
- tau/inference/api/registry.py +82 -0
- tau/inference/api/text/__init__.py +0 -0
- tau/inference/api/text/anthropic_claude_code.py +222 -0
- tau/inference/api/text/anthropic_messages.py +196 -0
- tau/inference/api/text/base.py +40 -0
- tau/inference/api/text/builtins.py +19 -0
- tau/inference/api/text/gemini_generate.py +234 -0
- tau/inference/api/text/github_copilot_chat.py +172 -0
- tau/inference/api/text/google_antigravity.py +522 -0
- tau/inference/api/text/mistral_chat.py +284 -0
- tau/inference/api/text/ollama_chat.py +200 -0
- tau/inference/api/text/openai_codex_responses.py +497 -0
- tau/inference/api/text/openai_completions.py +227 -0
- tau/inference/api/text/openai_responses.py +235 -0
- tau/inference/api/text/registry.py +50 -0
- tau/inference/api/text/service.py +297 -0
- tau/inference/api/text/types.py +7 -0
- tau/inference/api/text/utils.py +228 -0
- tau/inference/api/video/__init__.py +0 -0
- tau/inference/api/video/base.py +26 -0
- tau/inference/api/video/builtins.py +7 -0
- tau/inference/api/video/fal_video.py +119 -0
- tau/inference/api/video/openrouter_video.py +142 -0
- tau/inference/api/video/registry.py +15 -0
- tau/inference/api/video/service.py +72 -0
- tau/inference/model/__init__.py +0 -0
- tau/inference/model/registry.py +102 -0
- tau/inference/model/types.py +65 -0
- tau/inference/provider/__init__.py +0 -0
- tau/inference/provider/oauth/__init__.py +35 -0
- tau/inference/provider/oauth/anthropic_claude_code.py +286 -0
- tau/inference/provider/oauth/github_copilot.py +333 -0
- tau/inference/provider/oauth/google_antigravity.py +258 -0
- tau/inference/provider/oauth/openai_codex.py +309 -0
- tau/inference/provider/oauth/pkce.py +14 -0
- tau/inference/provider/oauth/types.py +46 -0
- tau/inference/provider/oauth/utils.py +154 -0
- tau/inference/provider/registry.py +141 -0
- tau/inference/provider/types.py +114 -0
- tau/inference/types.py +549 -0
- tau/inference/utils.py +219 -0
- tau/message/__init__.py +0 -0
- tau/message/types.py +482 -0
- tau/message/utils.py +178 -0
- tau/packages/__init__.py +11 -0
- tau/packages/manager.py +190 -0
- tau/packages/types.py +20 -0
- tau/packages/utils.py +67 -0
- tau/prompts/expand.py +58 -0
- tau/prompts/loader.py +69 -0
- tau/prompts/registry.py +45 -0
- tau/prompts/types.py +24 -0
- tau/rpc/__init__.py +8 -0
- tau/rpc/mode.py +783 -0
- tau/rpc/types.py +252 -0
- tau/runtime/service.py +759 -0
- tau/runtime/types.py +303 -0
- tau/session/branch_summarization.py +312 -0
- tau/session/compaction.py +646 -0
- tau/session/manager.py +652 -0
- tau/session/types.py +188 -0
- tau/session/utils.py +233 -0
- tau/settings/manager.py +1077 -0
- tau/settings/paths.py +150 -0
- tau/settings/storage.py +63 -0
- tau/settings/types.py +173 -0
- tau/settings/utils.py +25 -0
- tau/skills/loader.py +91 -0
- tau/skills/registry.py +70 -0
- tau/skills/types.py +25 -0
- tau/themes/loader.py +238 -0
- tau/themes/registry.py +108 -0
- tau/themes/types.py +19 -0
- tau/tool/__init__.py +3 -0
- tau/tool/registry.py +117 -0
- tau/tool/render.py +21 -0
- tau/tool/types.py +244 -0
- tau/trust/__init__.py +13 -0
- tau/trust/manager.py +80 -0
- tau/trust/types.py +14 -0
- tau/trust/utils.py +72 -0
- tau/tui/__init__.py +54 -0
- tau/tui/agent_hooks.py +346 -0
- tau/tui/ansi.py +330 -0
- tau/tui/app.py +540 -0
- tau/tui/autocomplete.py +33 -0
- tau/tui/capabilities.py +119 -0
- tau/tui/commands/__init__.py +3 -0
- tau/tui/commands/appearance.py +498 -0
- tau/tui/commands/auth.py +232 -0
- tau/tui/commands/context.py +38 -0
- tau/tui/commands/misc.py +82 -0
- tau/tui/commands/model.py +118 -0
- tau/tui/commands/session.py +464 -0
- tau/tui/component.py +268 -0
- tau/tui/components/__init__.py +0 -0
- tau/tui/components/autocomplete_manager.py +267 -0
- tau/tui/components/autocomplete_picker.py +143 -0
- tau/tui/components/box.py +90 -0
- tau/tui/components/command_palette.py +144 -0
- tau/tui/components/dynamic_border.py +19 -0
- tau/tui/components/file_picker.py +233 -0
- tau/tui/components/image.py +181 -0
- tau/tui/components/inline_selector.py +71 -0
- tau/tui/components/layout.py +1194 -0
- tau/tui/components/message_list.py +692 -0
- tau/tui/components/modal.py +97 -0
- tau/tui/components/model_palette.py +204 -0
- tau/tui/components/picker_overlay.py +174 -0
- tau/tui/components/prompt_overlay.py +236 -0
- tau/tui/components/resume_modal.py +372 -0
- tau/tui/components/select_list.py +222 -0
- tau/tui/components/settings_modal.py +274 -0
- tau/tui/components/settings_schema.py +203 -0
- tau/tui/components/spinner.py +119 -0
- tau/tui/components/text_input.py +396 -0
- tau/tui/components/text_prompt.py +82 -0
- tau/tui/components/tree_select_list.py +580 -0
- tau/tui/components/trust_screen.py +97 -0
- tau/tui/diff.py +114 -0
- tau/tui/fuzzy.py +99 -0
- tau/tui/input.py +496 -0
- tau/tui/input_handler.py +716 -0
- tau/tui/keybindings.py +87 -0
- tau/tui/markdown.py +286 -0
- tau/tui/message_renderers.py +31 -0
- tau/tui/overlay.py +326 -0
- tau/tui/renderer.py +378 -0
- tau/tui/terminal.py +499 -0
- tau/tui/theme.py +148 -0
- tau/tui/tui.py +544 -0
- tau/tui/ui_context.py +768 -0
- tau/tui/utils.py +20 -0
- tau/utils/__init__.py +0 -0
- tau/utils/http_proxy.py +221 -0
- tau/utils/image_processing.py +172 -0
- tau/utils/secrets.py +59 -0
- tau/utils/version_check.py +60 -0
- tau_coding_agent-0.1.0.dist-info/METADATA +177 -0
- tau_coding_agent-0.1.0.dist-info/RECORD +283 -0
- tau_coding_agent-0.1.0.dist-info/WHEEL +5 -0
- tau_coding_agent-0.1.0.dist-info/entry_points.txt +2 -0
- tau_coding_agent-0.1.0.dist-info/licenses/LICENSE +21 -0
- tau_coding_agent-0.1.0.dist-info/top_level.txt +1 -0
tau/tui/diff.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import difflib
|
|
4
|
+
import re
|
|
5
|
+
from typing import Callable
|
|
6
|
+
|
|
7
|
+
# Matches a standard unified diff line: prefix (+/-/ ) followed by optional
|
|
8
|
+
# line number then content.
|
|
9
|
+
_UNIFIED_LINE = re.compile(r"^([+\- ])(\s*\d*)\s?(.*)$")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _is_diff(text: str) -> bool:
|
|
13
|
+
"""Heuristic: return True if text looks like a unified diff."""
|
|
14
|
+
lines = text.splitlines()
|
|
15
|
+
has_marker = any(l.startswith(("---", "+++", "@@")) for l in lines[:20])
|
|
16
|
+
has_change = any(l.startswith(("+", "-")) and len(l) > 1 for l in lines[:20])
|
|
17
|
+
return has_marker and has_change
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _word_diff(old: str, new: str, inverse: Callable[[str], str]) -> tuple[str, str]:
|
|
21
|
+
"""Highlight changed words with inverse video."""
|
|
22
|
+
old_words = re.split(r"(\s+)", old)
|
|
23
|
+
new_words = re.split(r"(\s+)", new)
|
|
24
|
+
sm = difflib.SequenceMatcher(None, old_words, new_words, autojunk=False)
|
|
25
|
+
|
|
26
|
+
old_out, new_out = [], []
|
|
27
|
+
for tag, i1, i2, j1, j2 in sm.get_opcodes():
|
|
28
|
+
old_chunk = "".join(old_words[i1:i2])
|
|
29
|
+
new_chunk = "".join(new_words[j1:j2])
|
|
30
|
+
if tag == "equal":
|
|
31
|
+
old_out.append(old_chunk)
|
|
32
|
+
new_out.append(new_chunk)
|
|
33
|
+
elif tag == "replace":
|
|
34
|
+
old_out.append(inverse(old_chunk) if old_chunk.strip() else old_chunk)
|
|
35
|
+
new_out.append(inverse(new_chunk) if new_chunk.strip() else new_chunk)
|
|
36
|
+
elif tag == "delete":
|
|
37
|
+
old_out.append(inverse(old_chunk) if old_chunk.strip() else old_chunk)
|
|
38
|
+
elif tag == "insert":
|
|
39
|
+
new_out.append(inverse(new_chunk) if new_chunk.strip() else new_chunk)
|
|
40
|
+
|
|
41
|
+
return "".join(old_out), "".join(new_out)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def render_diff(
|
|
45
|
+
diff_text: str,
|
|
46
|
+
added: Callable[[str], str],
|
|
47
|
+
removed: Callable[[str], str],
|
|
48
|
+
context: Callable[[str], str],
|
|
49
|
+
hunk: Callable[[str], str],
|
|
50
|
+
inverse: Callable[[str], str],
|
|
51
|
+
) -> list[str]:
|
|
52
|
+
"""
|
|
53
|
+
Render a unified diff string with ANSI colors.
|
|
54
|
+
|
|
55
|
+
- Header lines (---, +++) and hunk markers (@@): styled with ``hunk``
|
|
56
|
+
- Added lines (+): styled with ``added``
|
|
57
|
+
- Removed lines (-): styled with ``removed``
|
|
58
|
+
- Context lines ( ): styled with ``context``
|
|
59
|
+
- Adjacent single-line add/remove pairs get intra-line word highlighting
|
|
60
|
+
via ``inverse``.
|
|
61
|
+
"""
|
|
62
|
+
raw_lines = diff_text.splitlines()
|
|
63
|
+
result: list[str] = []
|
|
64
|
+
i = 0
|
|
65
|
+
|
|
66
|
+
while i < len(raw_lines):
|
|
67
|
+
line = raw_lines[i]
|
|
68
|
+
|
|
69
|
+
# Header / hunk marker
|
|
70
|
+
if line.startswith(("---", "+++", "@@", "diff ", "index ", "new file", "deleted file")):
|
|
71
|
+
result.append(hunk(line))
|
|
72
|
+
i += 1
|
|
73
|
+
continue
|
|
74
|
+
|
|
75
|
+
if line.startswith("-"):
|
|
76
|
+
# Collect consecutive removed lines
|
|
77
|
+
removed_lines: list[str] = []
|
|
78
|
+
while i < len(raw_lines) and raw_lines[i].startswith("-"):
|
|
79
|
+
removed_lines.append(raw_lines[i][1:])
|
|
80
|
+
i += 1
|
|
81
|
+
|
|
82
|
+
# Collect consecutive added lines that immediately follow
|
|
83
|
+
added_lines: list[str] = []
|
|
84
|
+
while i < len(raw_lines) and raw_lines[i].startswith("+"):
|
|
85
|
+
added_lines.append(raw_lines[i][1:])
|
|
86
|
+
i += 1
|
|
87
|
+
|
|
88
|
+
# Intra-line diff only when it's a 1:1 change
|
|
89
|
+
if len(removed_lines) == 1 and len(added_lines) == 1:
|
|
90
|
+
old_hi, new_hi = _word_diff(removed_lines[0], added_lines[0], inverse)
|
|
91
|
+
result.append(removed("-" + old_hi))
|
|
92
|
+
result.append(added("+" + new_hi))
|
|
93
|
+
else:
|
|
94
|
+
for l in removed_lines:
|
|
95
|
+
result.append(removed("-" + l))
|
|
96
|
+
for l in added_lines:
|
|
97
|
+
result.append(added("+" + l))
|
|
98
|
+
continue
|
|
99
|
+
|
|
100
|
+
if line.startswith("+"):
|
|
101
|
+
result.append(added(line))
|
|
102
|
+
i += 1
|
|
103
|
+
continue
|
|
104
|
+
|
|
105
|
+
if line.startswith(" "):
|
|
106
|
+
result.append(context(line))
|
|
107
|
+
i += 1
|
|
108
|
+
continue
|
|
109
|
+
|
|
110
|
+
# Unrecognised line — pass through dimmed
|
|
111
|
+
result.append(context(line))
|
|
112
|
+
i += 1
|
|
113
|
+
|
|
114
|
+
return result
|
tau/tui/fuzzy.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class FuzzyMatch:
|
|
9
|
+
matches: bool
|
|
10
|
+
score: float
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def fuzzy_match(query: str, text: str) -> FuzzyMatch:
|
|
14
|
+
"""
|
|
15
|
+
Match if all query characters appear in order (not necessarily consecutive).
|
|
16
|
+
Lower score = better match. Rewards consecutive runs and word-boundary hits.
|
|
17
|
+
"""
|
|
18
|
+
q = query.lower()
|
|
19
|
+
t = text.lower()
|
|
20
|
+
|
|
21
|
+
def _match(q: str) -> FuzzyMatch:
|
|
22
|
+
if not q:
|
|
23
|
+
return FuzzyMatch(True, 0)
|
|
24
|
+
if len(q) > len(t):
|
|
25
|
+
return FuzzyMatch(False, 0)
|
|
26
|
+
|
|
27
|
+
qi = 0
|
|
28
|
+
score = 0.0
|
|
29
|
+
last = -1
|
|
30
|
+
consecutive = 0
|
|
31
|
+
|
|
32
|
+
for i, ch in enumerate(t):
|
|
33
|
+
if qi < len(q) and ch == q[qi]:
|
|
34
|
+
is_boundary = i == 0 or bool(re.match(r"[\s\-_./:]", t[i - 1]))
|
|
35
|
+
if last == i - 1:
|
|
36
|
+
consecutive += 1
|
|
37
|
+
score -= consecutive * 5
|
|
38
|
+
else:
|
|
39
|
+
consecutive = 0
|
|
40
|
+
if last >= 0:
|
|
41
|
+
score += (i - last - 1) * 2
|
|
42
|
+
if is_boundary:
|
|
43
|
+
score -= 10
|
|
44
|
+
score += i * 0.1
|
|
45
|
+
last = i
|
|
46
|
+
qi += 1
|
|
47
|
+
|
|
48
|
+
if qi < len(q):
|
|
49
|
+
return FuzzyMatch(False, 0)
|
|
50
|
+
if q == t:
|
|
51
|
+
score -= 100
|
|
52
|
+
return FuzzyMatch(True, score)
|
|
53
|
+
|
|
54
|
+
result = _match(q)
|
|
55
|
+
if result.matches:
|
|
56
|
+
return result
|
|
57
|
+
|
|
58
|
+
# Try swapped alphanumeric order (e.g. "v3" matches "3v")
|
|
59
|
+
m = re.match(r"^(?P<a>[a-z]+)(?P<d>[0-9]+)$", q) or re.match(r"^(?P<d>[0-9]+)(?P<a>[a-z]+)$", q)
|
|
60
|
+
if m:
|
|
61
|
+
swapped = (m.group("d") + m.group("a")) if "a" in m.groupdict() else ""
|
|
62
|
+
if swapped:
|
|
63
|
+
alt = _match(swapped)
|
|
64
|
+
if alt.matches:
|
|
65
|
+
return FuzzyMatch(True, alt.score + 5)
|
|
66
|
+
|
|
67
|
+
return result
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def fuzzy_filter(items: list, query: str, get_text) -> list:
|
|
71
|
+
"""
|
|
72
|
+
Filter and sort items by fuzzy match quality (best matches first).
|
|
73
|
+
Supports space-separated tokens — all tokens must match.
|
|
74
|
+
`get_text` is a callable that extracts the searchable string from an item.
|
|
75
|
+
"""
|
|
76
|
+
if not query.strip():
|
|
77
|
+
return items
|
|
78
|
+
|
|
79
|
+
tokens = [t for t in query.strip().split() if t]
|
|
80
|
+
if not tokens:
|
|
81
|
+
return items
|
|
82
|
+
|
|
83
|
+
scored: list[tuple[object, float]] = []
|
|
84
|
+
for item in items:
|
|
85
|
+
text = get_text(item)
|
|
86
|
+
total = 0.0
|
|
87
|
+
ok = True
|
|
88
|
+
for token in tokens:
|
|
89
|
+
m = fuzzy_match(token, text)
|
|
90
|
+
if m.matches:
|
|
91
|
+
total += m.score
|
|
92
|
+
else:
|
|
93
|
+
ok = False
|
|
94
|
+
break
|
|
95
|
+
if ok:
|
|
96
|
+
scored.append((item, total))
|
|
97
|
+
|
|
98
|
+
scored.sort(key=lambda x: x[1])
|
|
99
|
+
return [item for item, _ in scored]
|