any2llm 0.2.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.
- any2llm/__init__.py +0 -0
- any2llm/__main__.py +6 -0
- any2llm/cleaner.py +38 -0
- any2llm/cli.py +361 -0
- any2llm/clipboard.py +28 -0
- any2llm/config.py +87 -0
- any2llm/demo.py +18 -0
- any2llm/demo_assets/en/measurement-and-bias.pptx +0 -0
- any2llm/demo_assets/en/measurement-plan.xlsx +0 -0
- any2llm/demo_assets/en/research-designs.pdf +0 -0
- any2llm/demo_assets/en/study-checklist.docx +0 -0
- any2llm/demo_assets/tr/ara/305/237t/304/261rma-desenleri.pdf +0 -0
- any2llm/demo_assets/tr//303/247al/304/261/305/237ma-listesi.docx +0 -0
- any2llm/demo_assets/tr//303/266l/303/247/303/274m-plan/304/261.xlsx +0 -0
- any2llm/demo_assets/tr//303/266l/303/247/303/274m-ve-yanl/304/261l/304/261k.pptx +0 -0
- any2llm/ignore.py +66 -0
- any2llm/languages.py +49 -0
- any2llm/locales/ar.json +128 -0
- any2llm/locales/bn.json +129 -0
- any2llm/locales/en.json +128 -0
- any2llm/locales/es.json +128 -0
- any2llm/locales/fr.json +128 -0
- any2llm/locales/hi.json +129 -0
- any2llm/locales/pt.json +128 -0
- any2llm/locales/ru.json +128 -0
- any2llm/locales/tr.json +128 -0
- any2llm/locales/ur.json +128 -0
- any2llm/locales/zh.json +128 -0
- any2llm/messages.py +23 -0
- any2llm/ocr.py +47 -0
- any2llm/output.py +131 -0
- any2llm/packer.py +224 -0
- any2llm/parse_worker.py +75 -0
- any2llm/parsers.py +340 -0
- any2llm/prompts.py +32 -0
- any2llm/scanner.py +122 -0
- any2llm/secrets.py +19 -0
- any2llm/terminal.py +228 -0
- any2llm/tokenizer.py +21 -0
- any2llm/tools.py +32 -0
- any2llm-0.2.0.dist-info/METADATA +49 -0
- any2llm-0.2.0.dist-info/RECORD +46 -0
- any2llm-0.2.0.dist-info/WHEEL +5 -0
- any2llm-0.2.0.dist-info/entry_points.txt +2 -0
- any2llm-0.2.0.dist-info/licenses/LICENSE +21 -0
- any2llm-0.2.0.dist-info/top_level.txt +1 -0
any2llm/scanner.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Discover selectable paths without opening candidate files."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import stat
|
|
5
|
+
from collections.abc import Callable, Iterable
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from fnmatch import fnmatchcase
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .ignore import PathPattern, read_gitignore
|
|
11
|
+
from .output import owned_outputs
|
|
12
|
+
from .parsers import metadata_skip
|
|
13
|
+
|
|
14
|
+
IGNORED_DIRS = {
|
|
15
|
+
".venv", "__MACOSX", "__pycache__", "_llm_pack", "build", "dist", "env",
|
|
16
|
+
"node_modules", "site-packages", "target", "vendor", "venv",
|
|
17
|
+
}
|
|
18
|
+
_SENSITIVE_PATTERNS = (
|
|
19
|
+
"*.pem", "*.key", "*.p12", "*.pfx", "id_rsa*", "id_ed25519*", "credentials*", "secrets*", "*.kdbx",
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class ScanResult:
|
|
25
|
+
"""All paths are relative to the scanned directory."""
|
|
26
|
+
|
|
27
|
+
candidates: list[Path] = field(default_factory=list)
|
|
28
|
+
skipped: dict[Path, str] = field(default_factory=dict)
|
|
29
|
+
|
|
30
|
+
has_subfolders: bool = False
|
|
31
|
+
|
|
32
|
+
def _windows_entry(entry: os.DirEntry) -> str | None:
|
|
33
|
+
"""Handle native hidden files and junctions."""
|
|
34
|
+
info = entry.stat(follow_symlinks=False)
|
|
35
|
+
if info.st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN:
|
|
36
|
+
return "hidden"
|
|
37
|
+
if info.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT:
|
|
38
|
+
return "special"
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def scan_folder(
|
|
43
|
+
root: Path, recursive: bool = False, *,
|
|
44
|
+
output_dir: Path | None = None, on_file: Callable[[], None] | None = None,
|
|
45
|
+
include_sensitive: bool = False, exclude: Iterable[str] = (),
|
|
46
|
+
) -> ScanResult:
|
|
47
|
+
"""Scan regular files. Raise OSError if the root cannot be listed."""
|
|
48
|
+
root = Path(os.path.realpath(root))
|
|
49
|
+
if output_dir is not None:
|
|
50
|
+
output_dir = Path(os.path.realpath(output_dir))
|
|
51
|
+
generated = owned_outputs(root) if root == output_dir else set()
|
|
52
|
+
result = ScanResult()
|
|
53
|
+
exclusions = [PathPattern.parse(pattern) for pattern in exclude]
|
|
54
|
+
gitignore = []
|
|
55
|
+
|
|
56
|
+
def is_excluded(relative: Path, *, is_dir: bool) -> bool:
|
|
57
|
+
if any(pattern.matches(relative, is_dir=is_dir) for pattern in exclusions):
|
|
58
|
+
return True
|
|
59
|
+
for rule in reversed(gitignore):
|
|
60
|
+
if rule.pattern.matches(relative, is_dir=is_dir):
|
|
61
|
+
return rule.ignored
|
|
62
|
+
return False
|
|
63
|
+
|
|
64
|
+
pending = [root]
|
|
65
|
+
while pending:
|
|
66
|
+
directory = pending.pop()
|
|
67
|
+
try:
|
|
68
|
+
with os.scandir(directory) as entries:
|
|
69
|
+
if directory == root:
|
|
70
|
+
try:
|
|
71
|
+
gitignore = read_gitignore(root / ".gitignore")
|
|
72
|
+
except OSError:
|
|
73
|
+
result.skipped[Path(".gitignore")] = "unreadable"
|
|
74
|
+
return result
|
|
75
|
+
for entry in entries:
|
|
76
|
+
if entry.name.startswith("."):
|
|
77
|
+
continue
|
|
78
|
+
path = Path(entry.path)
|
|
79
|
+
if directory == output_dir and entry.name in generated:
|
|
80
|
+
continue
|
|
81
|
+
relative = path.relative_to(root)
|
|
82
|
+
try:
|
|
83
|
+
if os.name == "nt":
|
|
84
|
+
kind = _windows_entry(entry)
|
|
85
|
+
if kind == "hidden":
|
|
86
|
+
continue
|
|
87
|
+
if kind == "special":
|
|
88
|
+
result.skipped[relative] = kind
|
|
89
|
+
continue
|
|
90
|
+
is_dir = entry.is_dir(follow_symlinks=False)
|
|
91
|
+
if is_dir and (path == output_dir or entry.name in IGNORED_DIRS):
|
|
92
|
+
continue
|
|
93
|
+
if is_excluded(relative, is_dir=is_dir):
|
|
94
|
+
continue
|
|
95
|
+
if is_dir:
|
|
96
|
+
result.has_subfolders = True
|
|
97
|
+
if recursive:
|
|
98
|
+
pending.append(path)
|
|
99
|
+
continue
|
|
100
|
+
if not entry.is_file(follow_symlinks=False):
|
|
101
|
+
result.skipped[relative] = "special"
|
|
102
|
+
continue
|
|
103
|
+
if not include_sensitive and any(
|
|
104
|
+
fnmatchcase(entry.name.lower(), pattern) for pattern in _SENSITIVE_PATTERNS
|
|
105
|
+
):
|
|
106
|
+
result.skipped[relative] = "sensitive"
|
|
107
|
+
continue
|
|
108
|
+
if on_file is not None:
|
|
109
|
+
on_file()
|
|
110
|
+
if reason := metadata_skip(path):
|
|
111
|
+
result.skipped[relative] = reason
|
|
112
|
+
else:
|
|
113
|
+
result.candidates.append(relative)
|
|
114
|
+
except OSError:
|
|
115
|
+
result.skipped[relative] = "unreadable"
|
|
116
|
+
except OSError:
|
|
117
|
+
if directory == root:
|
|
118
|
+
raise
|
|
119
|
+
result.skipped[directory.relative_to(root)] = "unreadable"
|
|
120
|
+
result.candidates.sort()
|
|
121
|
+
result.skipped = dict(sorted(result.skipped.items()))
|
|
122
|
+
return result
|
any2llm/secrets.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Recognize a few common credential formats in extracted text."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
_PATTERNS = {
|
|
6
|
+
"private_key": re.compile(r"-----BEGIN (?:(?:RSA|EC|DSA|OPENSSH|ENCRYPTED|PGP) )?PRIVATE KEY(?: BLOCK)?-----"),
|
|
7
|
+
"api_key": re.compile(
|
|
8
|
+
r"(?<![\w-])(?:"
|
|
9
|
+
r"sk-(?:proj-|svcacct-|ant-api\d+-)?[A-Za-z0-9_-]{20,}"
|
|
10
|
+
r"|gh[pousr]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{30,}"
|
|
11
|
+
r"|(?:AKIA|ASIA)[A-Z0-9]{16}|AIza[A-Za-z0-9_-]{35}|xox[baprs]-[A-Za-z0-9-]{10,}"
|
|
12
|
+
r")(?![\w-])"
|
|
13
|
+
),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def finding_types(text: str) -> list[str]:
|
|
18
|
+
"""Return type labels without returning any matched text."""
|
|
19
|
+
return [kind for kind, pattern in _PATTERNS.items() if pattern.search(text)]
|
any2llm/terminal.py
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Terminal presentation, accessible choices and safe path labels."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import sys
|
|
6
|
+
from collections import Counter
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from unicodedata import decimal
|
|
9
|
+
|
|
10
|
+
import questionary
|
|
11
|
+
from prompt_toolkit.output import ColorDepth
|
|
12
|
+
from prompt_toolkit.utils import get_cwidth
|
|
13
|
+
from rich.console import Console
|
|
14
|
+
from rich.text import Text
|
|
15
|
+
from rich.theme import Theme
|
|
16
|
+
|
|
17
|
+
_LOGO = (
|
|
18
|
+
("╭───╮", "", "╭─────────────╮"),
|
|
19
|
+
("│ ╰─────╮", "· · ▸", "│ any2llm │"),
|
|
20
|
+
("│ ▤ ▤ │", "", "╰───┬─────────╯"),
|
|
21
|
+
("╰─────────╯", "", " ╰╴"),
|
|
22
|
+
)
|
|
23
|
+
_KEY_THEME = Theme(dict.fromkeys(
|
|
24
|
+
("key.move", "key.toggle", "key.all", "key.confirm", "key.cancel"),
|
|
25
|
+
"bold bright_white on blue",
|
|
26
|
+
))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _menu_style(accent: str) -> questionary.Style:
|
|
30
|
+
focus = "bold fg:ansiwhite bg:ansiblue"
|
|
31
|
+
heading = f"bold fg:ansi{accent}"
|
|
32
|
+
return questionary.Style([
|
|
33
|
+
("qmark", heading),
|
|
34
|
+
("question", heading),
|
|
35
|
+
("pointer", focus),
|
|
36
|
+
("highlighted", focus),
|
|
37
|
+
("answer", "noinherit bold"),
|
|
38
|
+
])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Terminal:
|
|
42
|
+
"""Style sections on a terminal while keeping redirected output readable."""
|
|
43
|
+
|
|
44
|
+
def __init__(self, *, plain: bool):
|
|
45
|
+
self.is_terminal = sys.stdout.isatty()
|
|
46
|
+
color_system = None if os.environ.get("NO_COLOR") else "auto"
|
|
47
|
+
self._console = Console(color_system=color_system, theme=_KEY_THEME) if self.is_terminal and not plain else None
|
|
48
|
+
|
|
49
|
+
def logo(self) -> None:
|
|
50
|
+
if self._console is None:
|
|
51
|
+
self.section("any2llm")
|
|
52
|
+
return
|
|
53
|
+
if self._console.width < 39:
|
|
54
|
+
self.section("▤ ▸ any2llm", "bold bright_cyan")
|
|
55
|
+
return
|
|
56
|
+
print()
|
|
57
|
+
logo = Text("\n").join(
|
|
58
|
+
Text.assemble(
|
|
59
|
+
" ", (f"{folder:<11}", "bright_cyan"),
|
|
60
|
+
(f"{trail:^11}", "bold bright_yellow"), (chat, "bright_magenta"),
|
|
61
|
+
)
|
|
62
|
+
for folder, trail, chat in _LOGO
|
|
63
|
+
)
|
|
64
|
+
logo.highlight_words(["any2llm"], "bold bright_cyan")
|
|
65
|
+
self._console.print(logo, soft_wrap=True)
|
|
66
|
+
|
|
67
|
+
def controls(self, message: str) -> None:
|
|
68
|
+
keys = Text.from_markup(message, emoji=False)
|
|
69
|
+
if self._console is None:
|
|
70
|
+
print(keys.plain)
|
|
71
|
+
else:
|
|
72
|
+
self._console.print(keys)
|
|
73
|
+
|
|
74
|
+
def line(
|
|
75
|
+
self, message: str, style: str = "", *, filenames: tuple[str, ...] = (), flush: bool = False,
|
|
76
|
+
) -> None:
|
|
77
|
+
if self._console is not None and (style or filenames):
|
|
78
|
+
text = Text(message, style=style)
|
|
79
|
+
if filenames:
|
|
80
|
+
text.highlight_words(filenames, "bright_green")
|
|
81
|
+
self._console.print(text, soft_wrap=True)
|
|
82
|
+
else:
|
|
83
|
+
print(message, flush=flush)
|
|
84
|
+
|
|
85
|
+
def section(self, message: str, style: str = "", *, icon: str = "", flush: bool = False) -> None:
|
|
86
|
+
if self.is_terminal:
|
|
87
|
+
print()
|
|
88
|
+
if icon and self._console is not None:
|
|
89
|
+
message = f"{icon} {message}"
|
|
90
|
+
self.line(message, style, flush=flush)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def display_path(path: Path | str) -> str:
|
|
94
|
+
return "".join(c if c.isprintable() else ascii(c)[1:-1] for c in str(path))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def display_count(count: int, msg: dict[str, str]) -> str:
|
|
98
|
+
if msg.get("grouping") == "indic" and count >= 1000:
|
|
99
|
+
head, tail = divmod(count, 1000)
|
|
100
|
+
groups = [f"{tail:03d}"]
|
|
101
|
+
while head >= 100:
|
|
102
|
+
head, pair = divmod(head, 100)
|
|
103
|
+
groups.append(f"{pair:02d}")
|
|
104
|
+
groups.append(str(head))
|
|
105
|
+
return msg["thousands"].join(reversed(groups))
|
|
106
|
+
return f"{count:,}".replace(",", msg["thousands"])
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def display_size(byte_count: int, msg: dict[str, str]) -> str:
|
|
110
|
+
amount = float(byte_count)
|
|
111
|
+
unit = "B"
|
|
112
|
+
for larger_unit in ("KB", "MB", "GB", "TB"):
|
|
113
|
+
if round(amount, 1) < 1000:
|
|
114
|
+
break
|
|
115
|
+
amount /= 1000
|
|
116
|
+
unit = larger_unit
|
|
117
|
+
size = f"{amount:.1f}".removesuffix(".0").replace(".", msg["decimal"])
|
|
118
|
+
return f"{size} {unit}"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def display_page_ranges(numbers: list[int], msg: dict[str, str]) -> str:
|
|
122
|
+
ranges: list[tuple[int, int]] = []
|
|
123
|
+
for number in numbers:
|
|
124
|
+
if ranges and ranges[-1][1] + 1 == number:
|
|
125
|
+
ranges[-1] = (ranges[-1][0], number)
|
|
126
|
+
else:
|
|
127
|
+
ranges.append((number, number))
|
|
128
|
+
return ", ".join(
|
|
129
|
+
display_count(first, msg) if first == last
|
|
130
|
+
else f"{display_count(first, msg)}–{display_count(last, msg)}"
|
|
131
|
+
for first, last in ranges
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _normalize_digits(value: str) -> str:
|
|
136
|
+
return "".join(str(decimal(char, char)) for char in value)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _color_depth() -> ColorDepth | None:
|
|
140
|
+
return ColorDepth.DEPTH_1_BIT if os.environ.get("NO_COLOR") else None
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def select(
|
|
144
|
+
message: str, choices: list[questionary.Choice], default: str | bool,
|
|
145
|
+
invalid: str, *, plain: bool, accent: str,
|
|
146
|
+
) -> str | bool:
|
|
147
|
+
if not plain:
|
|
148
|
+
return questionary.select(
|
|
149
|
+
message, choices=choices, default=default, instruction=" ",
|
|
150
|
+
qmark="◇", pointer="▸", style=_menu_style(accent), color_depth=_color_depth(),
|
|
151
|
+
).unsafe_ask()
|
|
152
|
+
|
|
153
|
+
print(message)
|
|
154
|
+
default_number = next(i for i, choice in enumerate(choices, 1) if choice.value == default)
|
|
155
|
+
options = {str(number): choice.value for number, choice in enumerate(choices, 1)}
|
|
156
|
+
for number, choice in enumerate(choices, 1):
|
|
157
|
+
print(f" {number}. {choice.title}")
|
|
158
|
+
while True:
|
|
159
|
+
answer = _normalize_digits(input(f"[{default_number}] > ").strip())
|
|
160
|
+
if not answer:
|
|
161
|
+
return default
|
|
162
|
+
if answer in options:
|
|
163
|
+
return options[answer]
|
|
164
|
+
print(invalid)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def select_files(paths: list[Path], msg: dict[str, str], *, plain: bool) -> list[Path]:
|
|
168
|
+
screen = Terminal(plain=plain)
|
|
169
|
+
screen.section(msg["local"])
|
|
170
|
+
screen.line(msg["all_selected"].format(count=display_count(len(paths), msg)), "bold")
|
|
171
|
+
if plain:
|
|
172
|
+
screen.section(msg["select"])
|
|
173
|
+
for number, path in enumerate(paths, 1):
|
|
174
|
+
print(f" {number}. {display_path(path)}")
|
|
175
|
+
by_number = {str(number): path for number, path in enumerate(paths, 1)}
|
|
176
|
+
while True:
|
|
177
|
+
answer = _normalize_digits(input(msg["plain_files"] + "\n> ").strip())
|
|
178
|
+
if not answer:
|
|
179
|
+
return paths
|
|
180
|
+
if answer == "0":
|
|
181
|
+
return []
|
|
182
|
+
excluded = answer.replace(",", " ").split()
|
|
183
|
+
if excluded and all(number in by_number for number in excluded):
|
|
184
|
+
omitted = {by_number[number] for number in excluded}
|
|
185
|
+
return [path for path in paths if path not in omitted]
|
|
186
|
+
print(msg["invalid_choice"])
|
|
187
|
+
|
|
188
|
+
print()
|
|
189
|
+
screen.controls(msg["keys"])
|
|
190
|
+
# Numbered rows keep truncated paths distinguishable, including duplicate names.
|
|
191
|
+
columns = shutil.get_terminal_size().columns
|
|
192
|
+
width = max(12, columns - len(str(len(paths))) - 10)
|
|
193
|
+
labels = [_short_label(path, width) for path in paths]
|
|
194
|
+
occurrences = Counter(labels)
|
|
195
|
+
choices = [
|
|
196
|
+
questionary.Choice(
|
|
197
|
+
f"{number}. {display_path(path) if occurrences[label] > 1 else label}",
|
|
198
|
+
value=path, checked=True,
|
|
199
|
+
)
|
|
200
|
+
for number, (path, label) in enumerate(zip(paths, labels, strict=False), 1)
|
|
201
|
+
]
|
|
202
|
+
if any(label != display_path(path) for path, label in zip(paths, labels, strict=False)):
|
|
203
|
+
screen.line(msg["full_paths"])
|
|
204
|
+
print()
|
|
205
|
+
return questionary.checkbox(
|
|
206
|
+
msg["select"], choices, instruction=" ", qmark="▦", pointer="▸", style=_menu_style("brightmagenta"),
|
|
207
|
+
erase_when_done=True, color_depth=_color_depth(),
|
|
208
|
+
).unsafe_ask()
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _short_label(path: Path, width: int) -> str:
|
|
212
|
+
text = display_path(path)
|
|
213
|
+
if get_cwidth(text) <= width:
|
|
214
|
+
return text
|
|
215
|
+
left, right = [], []
|
|
216
|
+
prefix_width = width // 3
|
|
217
|
+
for char in text:
|
|
218
|
+
prefix_width -= get_cwidth(char)
|
|
219
|
+
if prefix_width < 0:
|
|
220
|
+
break
|
|
221
|
+
left.append(char)
|
|
222
|
+
suffix_width = width - get_cwidth("".join(left)) - 1
|
|
223
|
+
for char in reversed(text):
|
|
224
|
+
suffix_width -= get_cwidth(char)
|
|
225
|
+
if suffix_width < 0:
|
|
226
|
+
break
|
|
227
|
+
right.append(char)
|
|
228
|
+
return "".join(left) + "…" + "".join(reversed(right))
|
any2llm/tokenizer.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Count extracted content with cl100k_base or an offline estimate."""
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@lru_cache(maxsize=1)
|
|
7
|
+
def get_encoding():
|
|
8
|
+
"""Load the vocabulary once, including when the cache or network is unavailable."""
|
|
9
|
+
try:
|
|
10
|
+
import tiktoken
|
|
11
|
+
|
|
12
|
+
return tiktoken.get_encoding("cl100k_base")
|
|
13
|
+
except (ImportError, OSError, ValueError):
|
|
14
|
+
return None
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def count_tokens(text: str) -> int:
|
|
18
|
+
encoding = get_encoding()
|
|
19
|
+
if encoding is None:
|
|
20
|
+
return (len(text) + 3) // 4
|
|
21
|
+
return len(encoding.encode_ordinary(text))
|
any2llm/tools.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Resolve optional native tools without implicit executable searches."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def resolve_tool(name: str) -> str | None:
|
|
8
|
+
"""Search absolute PATH entries outside the current working directory."""
|
|
9
|
+
# These Windows tools ship as executables. Ignore PATHEXT and scripts.
|
|
10
|
+
filename = f"{name}.exe" if os.name == "nt" else name
|
|
11
|
+
try:
|
|
12
|
+
cwd = Path.cwd().resolve()
|
|
13
|
+
except OSError:
|
|
14
|
+
return None
|
|
15
|
+
for entry in os.get_exec_path():
|
|
16
|
+
directory = Path(entry)
|
|
17
|
+
if not directory.is_absolute():
|
|
18
|
+
continue
|
|
19
|
+
try:
|
|
20
|
+
directory = directory.resolve(strict=True)
|
|
21
|
+
if directory == cwd:
|
|
22
|
+
continue
|
|
23
|
+
candidate = (directory / filename).resolve(strict=True)
|
|
24
|
+
if candidate.parent == cwd or not candidate.is_file():
|
|
25
|
+
continue
|
|
26
|
+
if os.name == "nt" and candidate.suffix.lower() != ".exe":
|
|
27
|
+
continue
|
|
28
|
+
if os.access(candidate, os.X_OK):
|
|
29
|
+
return str(candidate)
|
|
30
|
+
except (OSError, RuntimeError, ValueError):
|
|
31
|
+
continue
|
|
32
|
+
return None
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: any2llm
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Pack mixed documents into Markdown batches for AI chats with original PDF page numbers
|
|
5
|
+
Author: Ahmet Emre Apo
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/ahmetemreapo/any2llm
|
|
8
|
+
Project-URL: Documentation, https://github.com/ahmetemreapo/any2llm/blob/main/docs/SPEC.md
|
|
9
|
+
Project-URL: Issues, https://github.com/ahmetemreapo/any2llm/issues
|
|
10
|
+
Project-URL: Releases, https://github.com/ahmetemreapo/any2llm/releases
|
|
11
|
+
Keywords: pdf,docx,pptx,xlsx,markdown,llm,ocr,document-processing,cli
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
21
|
+
Classifier: Topic :: Utilities
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: pypdf
|
|
26
|
+
Requires-Dist: python-docx>=1.1
|
|
27
|
+
Requires-Dist: python-pptx
|
|
28
|
+
Requires-Dist: openpyxl
|
|
29
|
+
Requires-Dist: defusedxml>=0.7.1
|
|
30
|
+
Requires-Dist: Pillow>=13.0.0
|
|
31
|
+
Requires-Dist: tiktoken
|
|
32
|
+
Requires-Dist: questionary>=2.1
|
|
33
|
+
Requires-Dist: rich
|
|
34
|
+
Requires-Dist: pyperclip
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# any2llm
|
|
40
|
+
|
|
41
|
+
**Ask AI about your documents, then check its PDF citations on the original pages.**
|
|
42
|
+
|
|
43
|
+
any2llm turns a folder of PDF, Word, PowerPoint, Excel, text, and code files into numbered Markdown attachments and a ready-to-paste chat prompt. It keeps physical PDF page numbers and flags pages with missing or partial text so you can check the original.
|
|
44
|
+
|
|
45
|
+
- Set a token budget per batch and use the generated prompt to guide the chat through multiple attachments.
|
|
46
|
+
- Extract text on your computer. Optional OCR for PDF pages without usable text uses Poppler and Tesseract.
|
|
47
|
+
- Choose from 11 languages for terminal output and chat prompts.
|
|
48
|
+
|
|
49
|
+
Requires Python 3.11 or newer. Find examples, usage instructions, and extraction limits in the [GitHub repository](https://github.com/ahmetemreapo/any2llm).
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
any2llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
any2llm/__main__.py,sha256=1pBZMP1ZCjVIrLnju4HwWWpYudEalUTgz6uVaqoToWI,146
|
|
3
|
+
any2llm/cleaner.py,sha256=6XjY7uggOQ3g_fbENRYGN-K-HcXaupLfxHslpRQg_14,1468
|
|
4
|
+
any2llm/cli.py,sha256=tEs5qiwcXTZiZpBWcB6Kct8X0sFpP_tdu_q0iS86I4s,15552
|
|
5
|
+
any2llm/clipboard.py,sha256=GtMOBaOM_8nEHQT5QVOzhmb9NCJX7bZ6qYv0y9SZc9k,867
|
|
6
|
+
any2llm/config.py,sha256=X7hcaHQGBJV3ttHEFwRP-T1lmheZBKVIX6Av_c__E2M,2981
|
|
7
|
+
any2llm/demo.py,sha256=CtabP5OEBRNExuVrl4kkPXQcPkzPTH9YZDPqCwlhzzw,809
|
|
8
|
+
any2llm/ignore.py,sha256=W2yFMTCmqdkXoR41BGM4ewWwuncx_0t3E8WxGv7hOKc,2082
|
|
9
|
+
any2llm/languages.py,sha256=1ooYaHuHL2OAxSY_Oq3pfAtsBrPw43HQCmOwBV0N3dY,1502
|
|
10
|
+
any2llm/messages.py,sha256=akaL-NssbT06M25NCgKgLazWzqZvWayFnb1xMSSLDQ8,873
|
|
11
|
+
any2llm/ocr.py,sha256=twoMS6TYtYhC5BPaS24Z5iTyIezk28kE-xkpDP1MpBU,1850
|
|
12
|
+
any2llm/output.py,sha256=CJHhoaK5uYr9AXf0En-w3I3qTXq_pZbjTcPm5EYSiiU,4394
|
|
13
|
+
any2llm/packer.py,sha256=_KHblf83f6owxSnSAE_UaMH6bfMrFyUbxCxCiGjWnaE,8022
|
|
14
|
+
any2llm/parse_worker.py,sha256=KlgISbnjWQVqFW89PMzxgdCZk19o20Q5X73jhbF_cGw,2837
|
|
15
|
+
any2llm/parsers.py,sha256=uySNGmvxU2uAeFrgZNc2gdVzT6X0AxVTOgyITvkDThc,12433
|
|
16
|
+
any2llm/prompts.py,sha256=vQdJwDJ1KnS8A35VwoquJkOS5dHrl7S0Zf59O2IVLYU,1125
|
|
17
|
+
any2llm/scanner.py,sha256=QsSCLJ7sopHyt-fs3WXrUDCnx_-pydc_iDQhWl4F82o,4928
|
|
18
|
+
any2llm/secrets.py,sha256=KIX5xhISnaXDnYG7Hv_MMtCimomhrDao7Hl1_d9nOfA,703
|
|
19
|
+
any2llm/terminal.py,sha256=xKWoJYacynf4FOQ-y1iR7Kooa5jMrb44NlujHPYGFFM,8264
|
|
20
|
+
any2llm/tokenizer.py,sha256=kqWddptQIg84Y55dvCEStHP46HAPNQPFbmHP44LjbRM,565
|
|
21
|
+
any2llm/tools.py,sha256=3iLQsnNnWbZ06rtki0v3Rd3-_TPJD0nKn3bIFrjrhxI,1135
|
|
22
|
+
any2llm/demo_assets/en/measurement-and-bias.pptx,sha256=xpyxf6CqJCk7DKdZV9aQnHTcx0NMjqrCknZfzIlcffA,29542
|
|
23
|
+
any2llm/demo_assets/en/measurement-plan.xlsx,sha256=Kvf83eTRbIm6HkT1LsML8rey_paxC3fBM0BtrIEbfI0,5291
|
|
24
|
+
any2llm/demo_assets/en/research-designs.pdf,sha256=B0gGM2nm1HUE5tO65dzc9t887glhFFhqRmNgTJemD2U,23542
|
|
25
|
+
any2llm/demo_assets/en/study-checklist.docx,sha256=yn6lh1ZJzvk_OxGy4mfdjZBmJHN32hkCIt9SSddcAfM,36700
|
|
26
|
+
any2llm/demo_assets/tr/araştırma-desenleri.pdf,sha256=w9uEzCvxoT4auJhg7EHpjKPfezhlWifxB4szot-Csi8,34167
|
|
27
|
+
any2llm/demo_assets/tr/çalışma-listesi.docx,sha256=40xLt82KgiKgmPYetrcw_S704gFDA6vBmuIX6C_sWLU,36818
|
|
28
|
+
any2llm/demo_assets/tr/ölçüm-planı.xlsx,sha256=TjkQbDmC1wkFwYE-eKCRMahMZMQbkyChf0WPSXSPsw8,5366
|
|
29
|
+
any2llm/demo_assets/tr/ölçüm-ve-yanlılık.pptx,sha256=RAEYgVdnB9aTyqRzMuxG1DbOBmeHEX8-PV2WQ6FKjE8,29651
|
|
30
|
+
any2llm/locales/ar.json,sha256=hg5YtjkOC1n-Q3Lw6vefOPGPO7slqLJX2DONe2IVtzU,16248
|
|
31
|
+
any2llm/locales/bn.json,sha256=1pzH6_KN1Emz4G6NGOh_8f-FbzP2OEFsuuprrROz7zs,23603
|
|
32
|
+
any2llm/locales/en.json,sha256=Li8v5L7nJv5UWUxN8wA1heKCR3Wgr0b5vY-ee8g1GM4,11649
|
|
33
|
+
any2llm/locales/es.json,sha256=fUj49mu4Qele8R5XnKIl0Q1TO6eQNWlTc0mldArLGPQ,12734
|
|
34
|
+
any2llm/locales/fr.json,sha256=qG0Wlt1gVpjy1uXNTz80f1lePd7CzUqSgQ2NNpmaoTw,13203
|
|
35
|
+
any2llm/locales/hi.json,sha256=mQUrGJirWSwmWOp9uU-yf8HtwnQgj_UjSGb7LdXijAc,24466
|
|
36
|
+
any2llm/locales/pt.json,sha256=vt80ttcJ2g7Fd6g9f5G-rjfv5iphTnkdVU-I8ZdI3yM,12489
|
|
37
|
+
any2llm/locales/ru.json,sha256=QFl_H4S7nYsEf-60JI-lAZ_VcbF00s-DpN2DPYi9F1Q,18558
|
|
38
|
+
any2llm/locales/tr.json,sha256=LYAwyBkUCY0Fy5PXxDWunXv9Jc1tHrPk9bqdt1GEy6E,12854
|
|
39
|
+
any2llm/locales/ur.json,sha256=hpVVqQAmzXJiW-mwNZqPTGW6RvSv6z8FLncib4HKGJY,17683
|
|
40
|
+
any2llm/locales/zh.json,sha256=gkvN1P53DCWKStl3E-KV3yERd4GOT9JEcNf78cbgzCY,11481
|
|
41
|
+
any2llm-0.2.0.dist-info/licenses/LICENSE,sha256=qP9CmEvfwvJGUKL5oq8Sv9PPnBDPKeo0zalavGFIGSA,1071
|
|
42
|
+
any2llm-0.2.0.dist-info/METADATA,sha256=nOpl33i7fOfdHy_jd-nQRH8LrOuapyxnQVMSrZQiUbE,2269
|
|
43
|
+
any2llm-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
44
|
+
any2llm-0.2.0.dist-info/entry_points.txt,sha256=rNr7RAouDQeSqXqhfVb7fnVoVFe9P0I-1q3PH_P3Z1M,45
|
|
45
|
+
any2llm-0.2.0.dist-info/top_level.txt,sha256=E-VjN95KQkB4bomF24SeRNwUf1KMDO6XwxV6esPw4Wk,8
|
|
46
|
+
any2llm-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ahmet Emre Apo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
any2llm
|