99 Commits

Author SHA1 Message Date
8c9f66ac06 fix(driver): disable NVIDIA page flipping before launching BA
With page flipping on, BA's fullscreen window never puts a new frame on
screen on nik-gpu and sits frozen on "Initialize Catalog..." until
login.py's timeout kills it. It only worked during a Moonlight session,
because Sunshine's NvFBC capture makes the driver copy frames instead.

The setting resets on reboot or X restart, so launch_game() applies
AllowFlipping=0 before every launch. A failure is reported but not
raised, since login.py already fails the run loudly if the game never
gets past loading. setup.sh now checks for nvidia-settings, and
CLAUDE.md lists it as a runtime dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 21:17:26 +09:00
4a5045f126 Merge branch 'fix/login-fail-loudly'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 21:14:41 +09:00
9cfc41b384 fix(config): give cron-started Steam the desktop session env
Steam has no autostart on nik-gpu, so after a reboot the first cron run
starts it, and every game Steam launches inherits that environment.
cron sets neither XDG_RUNTIME_DIR nor DBUS_SESSION_BUS_ADDRESS, so the
Pulse socket never got mounted into the Proton container. Persona 3
Reload then fell back to ALSA and crashed on launch in xaudio2_9.

Set both in config.ENV, which launch_game() passes down to Steam.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 21:11:43 +09:00
8bd76b88f8 fix(login): fail the run when login can't reach home
login.run() only printed a warning and returned when it gave up, so the
game window still existed, _run_sequence kept going, every later task
aborted at its own first click-verify, and the run exited 0. Cron then
logged and Discord-alerted "finished OK" for runs that did nothing --
18 of them between 2026-10-26 and 2026-10-29 while the client itself
was hanging at its "Initialize Catalog" startup screen.

Now login kills the stuck game and raises RuntimeError, so the run exits
non-zero and ba_cron_run.sh logs FAILED and sends the error alert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 14:50:56 +09:00
598e1ef65b docs: add nik-gpu ethernet incident report (2026-09-24)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 20:56:10 +09:00
9e28387694 feat(presets): add story_sweep and story_sweep_hard to q4h
Both still refuse to spend AP unless their tab's reward campaign is
active, so this only sweeps during campaigns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 20:56:10 +09:00
8a11b3d2dc chore: ignore macOS .DS_Store files
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 20:56:10 +09:00
756abe99a8 feat(exit_game): kill BlueArchive.exe if still running after exit
The graceful Escape/Enter exit can abort when the game is stuck (three
aborts in q4h.log on 2026-10-28 alone), leaving the client open. run()
now always finishes with a process check: after a ~10s grace period for
Proton teardown, a still-running BlueArchive.exe is killed with SIGTERM,
escalating to SIGKILL if needed. driver.kill_game() gains force=True.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 20:52:35 +09:00
ac57914d4e fix: reduce shop reopen max attempts from 12 to 3 for improved efficiency 2026-10-13 23:27:50 +09:00
c87151bdf8 feat: skip runs while another game (P3R) is running
Automatic counterpart to the manual pause switch: while any process in
config.GAME_BUSY_PROCESSES (currently P3R.exe) is running on nik-gpu,
ba_daily.py exits with BUSY_EXIT_CODE (76) instead of letting xdotool
take over the mouse/keyboard mid-game. Same scope as pause (cron and
manual runs), and re-checked between tasks so a game started mid-run
stops the sequence after the current task returns home.

New run_check meta-command (ACTIVE/PAUSED/BUSY, exit 0/75/76) lets
ba_cron_run.sh skip before its "Starting" Discord alert, which also
stops paused runs from posting an unmatched start alert. A 76 from the
real run logs "STOPPED early" with an info alert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 19:45:29 +09:00
0bdd1919c4 Refactor event stage row detection and scrolling logic
- Replaced fixed y-position detection of stage rows with dynamic search using color blob detection and OCR for stage numbers.
- Implemented a new `_locate_stage_rows` function to find all visible stage rows and their corresponding buttons.
- Updated `_find_stage_row` to scroll through the stage list based on the detected stage numbers, improving reliability and adaptability to different event layouts.
- Enhanced modal detection logic to avoid false positives by checking the visibility of the header bar.
- Adjusted scanning logic to handle transient misreads and ensure stable readings before concluding the presence of a target stage.
- Improved logging for better debugging and understanding of the scanning process.
2026-10-08 08:10:45 +09:00
a6e124d175 fix(cafe): resolve cooldown notice handling and ensure room state confirmation
- Adjusted `_open_invite_list` to ensure room state cleanup runs regardless of cooldown notice dismissal, preventing unintended back navigation to home.
- Enhanced `_invite_student` to confirm room state after attempting to open the invite list, ensuring no stray Escape presses occur on a clean room.
- Added detailed comments regarding the root cause of the issue and the fixes applied, including live bug reports and diagnostic findings.
2026-09-24 14:23:07 +09:00
0f3a1c9410 Refactor code structure for improved readability and maintainability 2026-09-24 13:51:00 +09:00
9e06b34a54 fix: reduce stage row scan attempts from 9 to 3 for improved efficiency 2026-09-24 13:30:32 +09:00
5a6d964fe8 Enhance OCR name matching and purchase handling in shop utilities
- Introduced a fallback mechanism using difflib for improved name matching when OCR results contain internal character corruption.
- Implemented a two-stage fallback for name matching: stripping whitespace and using similarity scoring if no exact or substring matches are found.
- Modified `select_targets_by_name` to handle incremental purchases, committing batches before reopening the shop tab to avoid under-purchases due to UI state resets.
- Added retry logic for handling OCR instability, allowing multiple attempts to read item names before resorting to reopening the shop tab.
- Updated the return values of `select_targets_by_name` to reflect purchased items and skipped targets, improving clarity on transaction outcomes.
2026-09-24 13:25:56 +09:00
3d8af066fa feat: expand bounty task areas to include 道路 and 屋敷, with live testing confirming successful sweeps 2026-09-24 10:43:35 +09:00
d28ad2e3c7 feat: expand bounty area selection from 3 to 5, adding 道路 and 屋敷, with no code changes required 2026-09-24 10:40:01 +09:00
b8b25541b7 fix: handle unexpected modal dialog during shop target selection to prevent false unavailability reports 2026-09-24 10:37:20 +09:00
80c1a645b8 feat: implement grid alignment checks for shop item selection to prevent misreads after scrolling 2026-09-21 19:21:22 +09:00
19e39ec8b2 feat: detect Steam sign-out during login, stop cascading crashes after a missing game window
Root-caused 3 consecutive real cron failures (one q4h, two daily, all
2026-09-20) to Steam itself sitting signed out on its own account
sign-in dialog -- not a Blue Archive client issue, and not something any
amount of retrying/relaunching the game can fix.

login._steam_needs_sign_in (new detector.read_text_white_on_dark, since
the dialog's own light-on-dark text is the opposite OCR polarity this
project usually assumes) recognizes that exact state and turns the
generic "game window never appeared" warning into a specific, actionable
one instead of requiring a fresh screenshot investigation every time it
recurs.

ba_daily.py's _run_sequence now checks driver.window_exists() after every
task (except the last, and except exit_game) and aborts the whole run
immediately with one clear message if the window is gone, instead of
letting every remaining task independently rediscover this via its own
doomed pre-task retry cycle before crashing two tasks deep in a stack
trace. Still propagates as a real FAILED exit code -- this project
deliberately never swallows a genuine crash.

Confirmed live: reproduced the original failure via a real
./ba_cron_run.sh q4h run while Steam was still genuinely signed out, then
verified the new diagnostic fired correctly and the sequence aborted
immediately. After the user signed back into Steam, ran the actual daily
recovery preset end-to-end (all 17 tasks, ~24 minutes, exit 0) to catch
up the account's daily claims.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-20 08:51:06 +09:00
6a800f731b feat: batch cafe sparkle patting, add diagnostic capture, verify shop purchases via balance delta
Cafe: find_cafe_sparkles (replacing find_cafe_sparkle) matches every
sparkle in one screenshot instead of the single best one; _pat_current_view
now pats a whole batch per frame and stops after two consecutive empty
rounds instead of a fixed 15-click budget. Cuts an empty room's farming
time from ~100s to ~14s in live testing. _dismiss_rank_up_if_shown also
saves a diagnostic screenshot on its own final failure, since the real
"screen not confirmed" cron failures (100% reproducible in logs, 0%
reproducible live across several debugging sessions) need hard evidence
from the next real occurrence.

shop_utils.confirm_purchase now requires the currency balance to have
actually dropped by the expected spend before reporting success, instead
of trusting a single post-click overlay read -- closes a real false
positive caught live where a cron run logged a successful purchase that
never actually happened.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-19 18:18:51 +09:00
6d37e889eb feat: enhance shop item selection logic to prevent under-purchases and improve name matching 2026-09-17 11:22:08 +09:00
0ff3dca0b9 Implement dynamic OCR for gem shop sidebar navigation and free card status
- Added `read_lines` function to `detector.py` for OCR of multiple text lines in a specified region, improving the ability to dynamically locate text in the UI.
- Rewrote the gem shop task in `gem_shop.py` to utilize OCR for sidebar navigation and free card status checks, replacing fixed coordinates with dynamic text detection.
- Introduced helper functions `_find_sidebar_label`, `_on_general_products_tab`, `_ensure_general_products_tab`, `_read_card_lines`, `_read_free_card_status`, and `_find_buy_button` to streamline the OCR process and improve reliability against UI changes.
- Removed outdated color probe methods for checking the free card status, enhancing the robustness of the gem shop interaction flow.
- Live-calibrated the new OCR functionality to ensure accurate detection of UI elements and their states.
2026-09-17 10:37:24 +09:00
b10824d978 feat: optimize image handling by adding optional image parameter for screenshot functions 2026-08-21 23:53:57 +09:00
d266b47e58 feat: optimize screenshot handling for batch processing in lesson tasks 2026-08-21 18:20:30 +09:00
68a7ed2529 feat: cafe lowest-affection invite for room 2, exit_game AP-left-unspent alert, login window-flicker fix
- cafe.py: room 2 now invites the lowest-affection candidate instead of
  highest (room 1 unchanged), plus OCR'd invited-student name logging
- exit_game.py: alert (AP_ALERT: log tag, picked up by ba_cron_run.sh's
  Discord alerting) if AP is still unspent above threshold when the game
  closes
- login.py: re-check window_exists() after the stabilization wait to catch
  a startup window-flicker race that could crash a run
- config.py/mapping.md: supporting constants and reference-mapping updates

Also rewrites plan.md: retires the phase-by-phase changelog (now fully
superseded by CLAUDE.md's own documentation) down to forward-looking
backlog items, and adds a performance-improvement plan from a cron-log
time analysis (lesson.py's per-cell screenshot redundancy, event_sweep's
multi-call design).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-14 19:28:59 +09:00
e0744fc799 feat: add timestamped log output for better task duration tracking 2026-08-06 23:23:41 +09:00
ff240cb104 feat: implement handling for pending-update download notice during login 2026-08-04 17:56:18 +09:00
a690e90478 Implement Scrimmage Automation (学園交流会)
- Added new task for Scrimmage (学園交流会) in `ba_auto/tasks/scrimmage.py`, allowing automated clearing of the hardest stage (D) in three areas (トリニティ, ゲヘナ, ミレニアム) based on date-ordinal rotation.
- Introduced AP cost verification to ensure sweeps only occur when the cost is confirmed as 0 due to the user's monthly pass.
- Updated `ba_daily.py` to include the new scrimmage task in the daily preset and task registry.
- Documented the implementation details and testing outcomes in `plan.md` and `mapping.md`.
- Conducted live tests confirming successful execution and correct handling of ticket and AP costs.
2026-08-02 11:12:25 +09:00
52b10eda3d feat: add Discord alerting for cron job start/end with alert-bridge integration 2026-08-01 23:31:00 +09:00
509fb27fd8 Refactor Common Shop item selection to use OCR-based name matching
- Updated `COMMON_SHOP_TARGETS` to use item names and expected prices instead of fixed grid positions.
- Introduced `SHOP_NAME_OCR_OFFSET` for accurate name recognition in the shop grid.
- Implemented `select_targets_by_name` function to handle item selection based on OCR'd names and prices, addressing issues with item position drift due to sold-out items.
- Enhanced the purchasable button check to rely on blue tint rather than brightness, ensuring accurate detection of available items.
- Adjusted `run_shop_tab` to utilize the new selection function for Common Shop tasks.
- Documented changes and rationale in `plan.md`, including live testing results confirming successful item purchases.
2026-08-01 22:49:09 +09:00
7f408c1ad1 feat: add cron setup instructions for unattended scheduling of ba_cron_run.sh 2026-08-01 21:49:02 +09:00
a15ac6111e feat: enhance navigation and shop utilities with improved visibility checks and price reading retries 2026-07-31 13:48:25 +09:00
ffcacc8738 feat: implement robust screenshot handling with retry logic for image decoding 2026-07-31 13:06:50 +09:00
6cdce8ccdd Fix handling of transient misreads and improve event page checks
- Updated `_scan_stage_rows_once` to return full labels list instead of a boolean, allowing for better validation of stage presence.
- Enhanced `_find_stage_row` to require consistent label readings across consecutive scans to avoid false positives from transient misreads.
- Corrected `EVENT_FINISHED_TEXT_RECT` coordinates to ensure accurate OCR readings for finished events.
- Modified `run()`'s retry logic to treat `stage_not_found` similarly to `wrong_page`, enabling retries for potentially misidentified pages.
- Confirmed fixes through live testing, ensuring robust navigation and accurate event identification.
2026-07-29 23:10:09 +09:00
3c02178b3d fix: update q4h preset to remove duplicate tasks and improve flow 2026-07-29 22:26:57 +09:00
8a96ea4ffa feat: implement Battle Pass reward claiming functionality and update configuration 2026-07-29 21:59:37 +09:00
8d3da6e6e1 Refactor gem shop task for UI redesign and improve dialog handling
- Recalibrated gem shop task after client UI update, replacing the old overlay dialog with a full subscreen.
- Removed custom dialog open/close checks in favor of shared navigation functions.
- Updated method names and logic to reflect new tab structure and improve clarity.
- Enhanced error handling for dialog closure and navigation return to home.
- Verified live against real account states to ensure functionality and correctness.
2026-07-29 21:23:49 +09:00
bf87a097c3 feat: add manual pause functionality to prevent automation during user play sessions 2026-07-29 17:21:31 +09:00
4ddd0d7fba feat: implement AP floor guard for story_sweep, story_sweep_hard, and event_sweep 2026-07-24 23:34:15 +09:00
62206494d5 fix(config): adjust story sweep rotation region and stage count 2026-07-24 12:30:12 +09:00
a5d70e5ec6 Refactor story_sweep.py to align with story_sweep_hard.py best practices and add campaign-active guard
- Rewrote story_sweep.py to incorporate fixes from story_sweep_hard.py's Phase 21, addressing latent bugs and improving functionality.
- Introduced a campaign-active guard for Normal mode, ensuring AP is only spent when the reward campaign banner is visible.
- Added explicit Normal-tab navigation and self-healing checks to maintain task screen integrity.
- Updated click functions for MAX and PLUS buttons to remove reliance on visible count increases, addressing false-negative issues.
- Implemented OCR verification for the sweep confirmation dialog to prevent misclicks on stacked buttons.
- Enhanced region reading with retry logic for transient OCR failures.
- Added force parameter to run function, allowing bypass of campaign checks via story_sweep_force command.
- Updated ba_daily.py to include new force commands for both story_sweep and story_sweep_hard.
- Documented changes and live-tested functionality to ensure reliability and correctness.
2026-07-22 23:07:43 +09:00
7f752d5422 feat: add story_sweep_hard to q4h preset 2026-07-21 00:12:43 +09:00
0e3f2d951c feat: Implement hard story AP sweep functionality
- Added `story_sweep_hard.py` to handle a fixed, priority-ordered list of Hard-mode story stages, gated by an active drop-rate/reward campaign.
- Introduced `HARD_STORY_SWEEP_TARGETS`, `HARD_TAB`, `HARD_STAGE_ROWS_Y`, and `HARD_CAMPAIGN_BADGE_RECT` in the config for managing Hard sweep settings.
- Integrated `story_sweep_hard` and `story_sweep_hard_force` commands into the daily task flow, allowing for optional bypass of the campaign check.
- Enhanced navigation and error handling in the sweep process, addressing multiple bugs found during live testing, including navigation-cascade issues and real-money hazards.
- Documented the implementation and testing results in `plan.md`, confirming successful live sweeps and robust error handling.
2026-07-21 00:09:10 +09:00
f2387958fb Update manifest.json with new file metadata and additional files
- Updated timestamps and hashes for existing files: ba_dailies.sh, CLAUDE.md, plan.md.
- Added new files under ba_auto and .claude directories with their respective metadata.
- Included new scripts and configuration files to enhance functionality and organization.
2026-07-20 22:26:40 +09:00
a3cea4d192 feat(login): implement faster stuck-loading detection with _loading_buffer_visible
- Added _loading_buffer_visible function to detect the loading spinner badge
- Updated _wait_for_home to utilize the new detection for early recovery
- Introduced configuration options for loading buffer detection parameters
- Improved handling of stuck loading state to reduce wait time

fix(cron): make ba_cron_run.sh executable

- Changed file mode of ba_cron_run.sh to 755 to ensure it is executable
- Verified that cron can now execute the script as intended

fix(navigation): prevent crash in return_to_home when window disappears

- Added guard to return_to_home to check if the game window exists before focusing
- Ensured robustness in cleanup path during game exit
2026-07-20 01:21:53 +09:00
b8ac8db01e feat(deployment): simplify runtime paths to run directly from the git checkout 2026-07-18 22:04:17 +09:00
976f0f7241 feat(exit_game): implement exit game functionality with confirmation dialog 2026-07-18 20:32:14 +09:00
0a6af51340 feat(exit_game): implement task to exit the Blue Archive client after daily/q4h runs 2026-07-18 20:25:32 +09:00
a30c3888d6 fix: address multiple bugs causing incorrect battle handling and result screen issues
- In arena.py, widened RESULT_MODAL_MAX_POLLS to 200 to accommodate real battle durations and added early exit check in _wait_for_result to prevent stuck screens.
- Updated _fight_one to properly handle _wait_for_result's return value, ensuring failures stop the fight loop.
- In bounty.py, implemented OCR verification in _confirm_dialog_is_sweep to ensure the correct confirmation dialog is displayed before proceeding with sweeps, preventing unintended battles.
- Documented hazards and fixes in plan.md, detailing incidents from 2026-07-17 that led to these changes.
2026-07-18 12:31:42 +09:00