Commit Graph

25 Commits

Author SHA1 Message Date
alexpolo1
61a88d2968 fix(install): make Tesseract/OCR setup work on clean Win10/Win11
Follow-up to the conda scope fix: the same admin/winget assumptions broke
the OCR backend, which is what actually carries item text reading since
tesserocr's MSVC DLL chain commonly fails to load.

- install.bat installed Tesseract via `winget install` with no --scope,
  i.e. machine-wide into "C:\Program Files", which requires admin. On a
  clean non-admin box this failed and left NO working OCR backend at all
  (tesserocr already fails), so OCR_READY=0 and item reading was dead.
  Now: winget machine scope -> winget --scope user -> direct download of
  the official NSIS installer with a per-user /D= target. Also stops
  trusting winget's exit code (non-zero when already installed) and
  re-resolves tesseract.exe after each attempt.
- The downloaded installer is size-checked (~50 MB; <20 MB = failed
  download) before being executed, matching the Miniforge handling.
- Added a :find_tesseract subroutine that resolves tesseract.exe from
  Program Files, Program Files (x86), %LOCALAPPDATA%\Programs,
  %ProgramData% and PATH. Verification now uses the resolved path instead
  of the hardcoded "C:\Program Files" one.
- ocr.py: added Program Files (x86) and the per-user
  %LOCALAPPDATA%\Programs\Tesseract-OCR location to the runtime search
  order, since per-user installs are not on PATH.
- run_botty.bat: only export PYTESSERACT_TESSERACT_CMD when the file
  exists, falling back to the per-user path, so a stale machine-wide
  value cannot shadow a valid per-user install.

Verified on this machine: all install.bat dependency imports OK
(cv2/mss/numpy/transitions/rapidfuzz/pydantic/pytesseract/yaml/discord),
pytesseract resolves tesseract 5.5.0, osdetect reports the win11 profile,
config loads, 140 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 21:28:02 +02:00
alexpolo1
a2e2acfbde fix(install): install conda without admin + verify git download
install.bat could fail to auto-install conda on a fresh, non-admin
machine:

- winget install used the default (machine) scope, landing conda in
  %ProgramData% and requiring elevation. A normal double-click without
  admin failed silently and conda never installed. Add --scope user so
  it installs to %USERPROFILE%\miniforge3 with no admin needed.
- winget returns non-zero when the package is already present, so its
  exit code was unreliable. Rescan for conda.exe after winget and only
  fall through to the direct download when it is genuinely missing.
- The GitHub (git) download fallback never validated the file before
  running it: a truncated download or an HTML error page served with a
  200 would be launched as the "installer" and silently do nothing. Add
  a size check (<40 MB => failed download, clear error + bail) plus a
  pre-download cleanup of any stale temp file.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 17:07:50 +02:00
alexpolo1
48d8445c05 Bootstrap visual test harness and fix GEMS transmute flow 2026-06-21 15:04:12 +02:00
alexpolo1
44794fba67 logs: hard size cap on log.txt + kill install-log progress-bar balloon
A single bot session produced a 22 GB log. The file logger used daily-only
rotation (TimedRotatingFileHandler when='midnight') with NO size cap, so a
long/spammy session grew log.txt unbounded within a day. Its archiver also
looked for .1/.2 backups that the timed handler never produced.

- logger.py: switch to size-based RotatingFileHandler — log.txt rotates at
  50 MB (override via BOTTY_LOG_MAX_MB), keeps 5 zipped backups, and prunes
  log/archive/ to 30 zips. Hard cap on both the live file and total disk.
  The .1/.2 naming now matches what the handler emits, so archiving works.
- install.bat: pip --progress-bar off. The progress bar redraws via \r;
  redirected to a file (run_install_capture.bat) those redraws became
  millions of lines — the other way an install log balloons to GBs.
- params.ini: document the log.txt cap + BOTTY_LOG_MAX_MB.

Verified: with a tiny cap, log.txt stayed under the limit while rotated
files zipped to archive; full suite 80 passed / 2 skipped.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-20 18:56:25 +02:00
Alex
5c687773b1 Click-and-go install: self-bootstrapping install.bat + tesserocr DLL fix (#2)
Merges fix/stash-full-guard-and-testbed into main. See PR #2 for full description.
2026-06-20 09:27:12 +02:00
alexpolo1
ddb7008419 fix: reinstall OpenSSL, rename broken conda tesseract, use winget tesseract 5.5.0\n- Reinstalled OpenSSL (was corrupted in conda cache)\n- Renamed conda tesseract.exe to tesseract_broken.exe (access violation)\n- install.bat: winget tesseract-ocr.tesseract + rename conda binary\n- run_botty.bat: PYTESSERACT_TESSERACT_CMD points to winget version 2026-06-11 15:33:04 +02:00
alexpolo1
b77347542d fix: patch pytesseract to handle tesseract --version crashes 2026-06-11 15:04:13 +02:00
alexpolo1
6822a7e495 fix: install.bat copies liblept.dll from conda leptonica 2026-06-11 14:51:23 +02:00
alexpolo1
1fe95aae08 fix: install.bat - use tesseract 4.x + bundled wheel, add DLL copy + PATH fix 2026-06-11 13:43:11 +02:00
alex
f1d6c6bd1c ci: align validation environment with Windows 11 2026-06-07 18:31:10 +02:00
alex
86e3cccbc9 feat: detect Windows profile for install and input 2026-06-07 18:26:16 +02:00
alex
5ac00d16d0 Add Win10/Win11 auto-detection for mouse input mode
- win_input.py: detect OS build via platform.win32_ver(), use
  MOUSEEVENTF_ABSOLUTE only on Win10 (build < 22000)
- install.bat: detect and display Windows version on install
2026-06-05 22:51:54 +02:00
alex
f20ac02720 Add tesserocr wheel fallback to Windows installer 2026-05-25 15:16:09 +02:00
alex
d6c8d8d5f7 fix: replace custom tesserocr wheel with conda-forge package
The custom tesserocr-2.5.2 wheel was compiled on a specific machine
against DLL versions that do not match a fresh conda-forge installation.
This caused persistent ImportError: DLL load failed regardless of PATH
or LoadLibraryExW approach.

conda-forge's tesserocr package is compiled against the exact same
conda-forge tesseract/leptonica binaries, so all DLL dependencies
are automatically satisfied within the conda environment — no manual
DLL path manipulation needed.

Changes:
- environment.yml: add tesserocr + tesseract as conda-forge packages,
  remove leptonica pin (no longer needed), remove custom wheel from pip
- install.bat: replace wheel force-reinstall with pip uninstall cleanup
- src/*.py: simplify DLL fix to os.add_dll_directory only

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 14:49:00 +02:00
alex
e1c18faf26 fix: use conda run instead of direct python for DLL loading
Every approach to manually replicating conda's DLL environment from
Python code or batch PATH manipulation has failed. conda run activates
the environment exactly like "conda activate botty" — setting PATH,
running activate.d scripts, and properly resolving all transitive DLL
dependencies for tesseract51.dll.

run_botty.bat now derives conda.exe from the botty python.exe path
(two levels up: envs/botty -> envs -> miniforge3 -> Scripts/conda.exe)
and uses "conda run -n botty --no-capture-output python src/main.py".

install.bat smoke test now uses "%CONDA_EXE% run -n botty python -c ..."
which already has CONDA_EXE set from the install step.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 14:37:14 +02:00
alex
bdd6247342 fix: use LoadLibraryExW(0x1000) to preload tesseract51.dll
os.add_dll_directory alone is not enough — LOAD_LIBRARY_SEARCH_USER_DIRS
does not propagate to transitive deps of deps when loaded automatically
by the OS (e.g. tesseract51.dll's deps like mingw runtimes, leptonica).

LoadLibraryExW with LOAD_LIBRARY_SEARCH_DEFAULT_DIRS (0x1000) explicitly
propagates user DLL dir search to the entire transitive dep chain, so
leptonica, libgcc, libstdc++, zlib etc. are all found in Library\bin
and Library\mingw-w64\bin without conda activate.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 14:30:12 +02:00
alex
77ad97022e fix: remove ctypes.WinDLL preload — use only os.add_dll_directory
ctypes.WinDLL uses LoadLibraryW which does NOT search user DLL dirs
registered via os.add_dll_directory/AddDllDirectory. It was throwing
FileNotFoundError and blocking the import before tesserocr was ever tried.

Python 3.8+ loads .pyd files with LOAD_LIBRARY_SEARCH_USER_DIRS which
DOES search user-registered dirs for the pyd and all its transitive DLL
dependencies. os.add_dll_directory(Library\bin) alone is sufficient.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 14:19:18 +02:00
alex
a77dafaf08 fix: set conda DLL PATH at batch level before Python starts
os.environ['PATH'] set from inside Python does not affect the Windows
DLL loader used by ctypes.WinDLL — the loader reads the process PATH
at load time, not from Python's env dict. Set PATH in the .bat files
before python.exe is launched so tesseract51.dll's transitive deps
(leptonica, zlib, libpng, etc.) are findable by the loader.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 14:10:00 +02:00
alex
18c08a4c65 fix: prepend conda Library\bin to PATH before ctypes.WinDLL call
When ctypes.WinDLL loads tesseract51.dll by absolute path, Windows
resolves that DLL's own transitive deps using the standard search order:
app-dir → System32 → Windows → cwd → PATH. Library\bin is in none of
those (conda activate was not run), so leptonica, zlib, libpng, etc.
are invisible and the load fails even though the DLLs are all present.

Fix: prepend all conda DLL dirs to os.environ['PATH'] before the
ctypes.WinDLL call so the standard DLL search finds them. os.add_dll_directory
is still called for Python's LOAD_LIBRARY_SEARCH_USER_DIRS path.
Together the three steps guarantee the import works without conda activate:
  1. os.add_dll_directory  - for .pyd loading
  2. os.environ PATH       - for ctypes transitive dep resolution
  3. ctypes.WinDLL(abs)    - pre-cache tesseract so .pyd reuses it

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 14:03:00 +02:00
alex
f8380af3bd fix: pre-load tesseract51.dll by absolute path to fix transitive DLL deps
os.add_dll_directory alone is not enough on Windows. When Python loads
the tesserocr .pyd via LOAD_LIBRARY_SEARCH_USER_DIRS, Windows finds
tesseract51.dll in the added directory but then resolves tesseract's own
transitive deps (leptonica, zlib, libpng etc.) using only the standard
system search path -- not the user DLL dirs. Those libs live in
Library\bin, not System32, so they're invisible and the load fails even
though every DLL is present.

Fix: call ctypes.WinDLL(absolute_path_to_tesseract51.dll) before the
tesserocr import. LoadLibraryW with a full path anchors tesseract51.dll
to Library\bin, so Windows searches that directory for its transitive
deps. The already-loaded DLL is then returned from cache when the .pyd
requests it, making the import succeed.

Applied to ocr.py (test entry point), main.py, and shopper.py.
Also updated install.bat smoke test and diagnostic to use the same fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 13:59:21 +02:00
alex
ee940b7e3d fix: pin leptonica=1.78.0 to match tesserocr wheel DLL dependency
The custom tesserocr wheel links against leptonica-1.78.0.dll at
compile time. Unpinned leptonica on conda-forge resolves to 1.82+
which installs leptonica-1.82.0.dll — a different filename — so
Windows DLL loader cannot find it regardless of os.add_dll_directory.

Also force-reinstall the wheel in install.bat to guarantee the
correct binary is used (not a stale cached version), and add a
diagnostic that prints which DLLs are actually present when the
smoke test fails so the root cause is visible instead of a vague
warning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 13:51:54 +02:00
alex
91403e49d3 feat: make zip-download install flow work for first-time users
- README: add step-by-step Installation section (Miniforge → download
  ZIP → install.bat → config → run_botty.bat) so a non-technical user
  can follow it without reading development.md
- config/params.ini: reset personal fields (name, char_name,
  saved_games_folder) to generic defaults so the downloaded zip
  works out of the box for anyone
- install.bat: apply os.add_dll_directory before the tesserocr smoke
  test so it stops emitting a false warning on every install

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 09:39:12 +02:00
alex
40a207be9a feat: harden install.bat + add CI checks for launcher scripts
install.bat:
- Add conda self-test (conda --version) before env create
- Verify botty python.exe exists after env creation
- Smoke-test key imports (cv2, tesserocr, discord, etc.)

CI (.github/workflows/ci.yml):
- Add test_setup_bat_files.py to test matrix

test/test_setup_bat_files.py (7 tests):
- All expected .bat files exist
- No hardcoded usernames (alex, alexpolo, ultimate) in run scripts
- No absolute home paths in run scripts (must use %~dp0 / %USERNAME%)
- All run_*.bat source find_python.bat (no duplicated conda detection)
- find_python.bat checks >= 6 conda locations
- install.bat has conda self-test and python verification
2026-05-23 23:15:24 +02:00
alex
94f3e6bca8 fix install.bat: cd to script dir so environment.yml is found
Without cd /d "%~dp0", conda resolves environment.yml relative to
wherever the user launched the bat from (e.g. C:\Windows\system32).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 23:54:33 +02:00
alex
ed4aaf77f8 add install.bat: automates conda env setup from environment.yml
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 23:40:26 +02:00