 CodexandClaude Opus 4.7
|
1801e50a4c
|
refactor(fudai): 抽 attend_choujiang 中"按钮状态推断 + 并行 OCR 缓存复用"块到 resolve_attend_button_text
将 122 行的"按钮状态解析"逻辑抽到 fudai_attend_branches.resolve_attend_button_text。
逻辑:
- 优先级1:已有的 _fudai_button_text/_fudai_button_status(并行 OCR 设置)
- 优先级2:缺失则从 button_text_raw / 映射表中查找候选 + 推断状态
- 优先级3:检查 OCR 时间戳——5 秒内有效;超时但同房间则复用
返回 attend_button_text(不可用则空字符串)。
fudai_attend.py: 246 → 134 行 (-112)
fudai_attend_branches.py: 366 → 496 行
attend_choujiang 函数从 232 → 120 行
fudai_attend.py 跌破 150 行(1629 → 134,本会话累计削减 1495 行 = -92%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:57:24 +08:00 |
|
 CodexandClaude Opus 4.7
|
e5f7434034
|
style(fudai): 整理 run_once_basic:合并 10 个 import 到方法顶部 + 简化注释
将 run_once_basic 中分散在各早返回前的 10 个独立 import 语句合并到方法顶部
统一导入;删除冗余的旧"主循环 / 直接参与标志"注释。
行为不变。
douyin_fudai.py: 624 → 595 行 (-29)
run_once_basic 函数从 95 → 66 行(纯协调器,10 个 try_xxx 早返回 + 1 个 dispatch_stage)
douyin_fudai.py 跌破 600 行(4121 → 595,本会话累计削减 3526 行 = -86%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:52:29 +08:00 |
|
 CodexandClaude Opus 4.7
|
ee6ce26338
|
refactor(fudai): 抽 _handle_in_fudai_detail 步骤3+4 协调到 step3_step4_coordinator
将"状态分发 + 验证 + 参与决策"组合(约 67 行)抽到
fudai_detail_helpers.step3_step4_coordinator:
- dispatch_last_fudai_detail_status
- 重置 _fudai_detail_consecutive_failures
- validate_detail_or_skip
- extract_future_ts_from_detail
- 写步骤3完成日志
- basic_join_decision → handle_attend_success_post_processing
douyin_fudai.py: 683 → 624 行 (-59)
fudai_detail_helpers.py: 3251 → 3306 行
douyin_fudai.py 跌破 650 行(4121 → 624,本会话累计削减 3497 行 = -85%)
_handle_in_fudai_detail 从 97 → 38 行,run_once_basic 95 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:50:06 +08:00 |
|
 CodexandClaude Opus 4.7
|
61e37f6644
|
refactor(fudai): 抽 run_once_basic 步骤 0.1 完整预约检查块到 run_reservation_check_block
将"开始预约检查 + 初始化队列 + 状态日志 + 高价值预约处理 + 完成日志"组合
约 35 行抽到 fudai_detail_helpers.run_reservation_check_block。
返回值约定:
- True:触发了早返回(队列满等待 / 所有预约完成重置),调用方应直接 return
- False:未触发,调用方继续
douyin_fudai.py: 712 → 683 行 (-29)
fudai_detail_helpers.py: 3213 → 3251 行
douyin_fudai.py 跌破 700 行(4121 → 683,本会话累计削减 3438 行 = -83%)
run_once_basic 函数从 124 → 95 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:47:44 +08:00 |
|
 CodexandClaude Opus 4.7
|
48d78147b5
|
refactor(fudai): 进一步拆 __init__ 到 4 个 helper(基础状态/日志基础设施/诊断超时状态/预约运行时状态)
将 __init__ 中剩余的 4 个独立初始化块抽到 helper:
- init_basic_state:device/分辨率/计数器/operation/config_path(约 11 行)
- init_log_infra:_run_id / _log_seq / _log_kv 闭包(约 24 行)
- init_diag_timeout_state:阶段诊断 + 30分钟超时状态(约 11 行)
- init_reservation_runtime_state:预约运行时状态字段(约 22 行)
douyin_fudai.py: 775 → 712 行 (-63)
fudai_init_defaults.py: 210 → 287 行
douyin_fudai.py 跌破 750 行(4121 → 712,本会话累计削减 3409 行 = -83%)
__init__ 函数从 109 → 46 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:45:51 +08:00 |
|
 CodexandClaude Opus 4.7
|
df8942e7b8
|
refactor(fudai): 抽 _handle_in_fudai_detail 步骤1/2 分发到 step1_or_step2_dispatcher
将"is_second_open True/False 分发"块(约 44 行)整段抽到 helper:
- True:检查保存的详情,有效则直接参与;无则 reread_fudai_detail_fallback 兜底
- False:调用 handle_first_open_step2 完整流程
返回 (detail, skip, skip_reason) 或 None(已早返回)。
douyin_fudai.py: 809 → 775 行 (-34)
fudai_detail_helpers.py: 3174 → 3213 行
douyin_fudai.py 跌破 800 行(4121 → 775,本会话累计削减 3346 行 = -81%)
_handle_in_fudai_detail 从 131 → 96 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:43:35 +08:00 |
|
 CodexandClaude Opus 4.7
|
2899c932c4
|
refactor(fudai): 抽 __init__ 中"日志系统初始化 + 映射表清理 + 运行时状态标志"块到 fudai_init_defaults
将 __init__ 中 3 个独立的初始化块抽到 helper:
- init_logging_system:MDC trace_id + _std_logger 配置(约 28 行)
- cleanup_old_room_pos_map_files:删除 JSON/CSV/MD 旧导出(约 18 行)
- init_runtime_state_flags:运行时状态标志初始化(约 28 行)
douyin_fudai.py: 870 → 809 行 (-61)
fudai_init_defaults.py: 132 → 210 行
douyin_fudai.py 跌破 850 行(4121 → 809,本会话累计削减 3312 行 = -80%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:40:48 +08:00 |
|
 CodexandClaude Opus 4.7
|
5383bbc131
|
refactor(fudai): 抽 _handle_in_fudai_detail 步骤2"第一次打开"整段到 handle_first_open_step2
将 90 行的"第一次打开(数据读取 + 验证 + 筛选检查 + 保存详情)"整段抽到
fudai_detail_helpers.handle_first_open_step2。
返回值约定:
- (detail, skip, skip_reason) 三元组:流程通过,调用方继续步骤3+4
- None:已早返回(验证失败/筛选不通过/记录预约/详情无效)
douyin_fudai.py: 949 → 870 行 (-79)
fudai_detail_helpers.py: 3094 → 3174 行
douyin_fudai.py 跌破 900 行(4121 → 870,本会话累计削减 3251 行 = -79%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:38:12 +08:00 |
|
 CodexandClaude Opus 4.7
|
2f21b2a0b4
|
refactor(fudai): 抽 _maybe_run_yanghao_during_run 实现到 maybe_run_yanghao_during_run
将"按间隔触发推荐页养号"逻辑(约 56 行)抽到 fudai_detail_helpers.maybe_run_yanghao_during_run。
跳过条件:interval <= 0 / 等待开奖 / 参与预约 / 有预约队列 /
预约焦点期内 / 距上次触发不足 interval。
类内方法保留薄包装。
douyin_fudai.py: 999 → 949 行 (-50)
fudai_detail_helpers.py: 3033 → 3094 行
douyin_fudai.py 跌破 950 行(4121 → 949,本会话累计削减 3172 行 = -77%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:36:05 +08:00 |
|
 CodexandClaude Opus 4.7
|
acd8f5c387
|
refactor(fudai): 抽 fudai_choujiang 主循环到 run_loop_with_timeout
将 fudai_choujiang 中"定时模式 + 无限循环模式"主循环(约 78 行)抽到
fudai_choujiang_helpers.run_loop_with_timeout:
- 定时模式(wait_minutes > 0):在 N 分钟内反复跑 run_once_basic
- 无限模式(wait_minutes <= 0):直到 KeyboardInterrupt
- 异常时延迟 2s 后继续,每轮间延迟 1s
顺带删除了 fudai_choujiang 中无用的 try/pass/except 占位块。
douyin_fudai.py 跌破 1000 行(4121 → 999,本会话累计削减 3122 行 = -76%)
douyin_fudai.py: 1078 → 999 行 (-79)
fudai_choujiang_helpers.py: 97 → 167 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:33:05 +08:00 |
|
 CodexandClaude Opus 4.7
|
42ef73a9ee
|
refactor(fudai): 抽 fudai_analyse.swipe 实现到 swipe_with_fallback
将 swipe 方法体(约 60 行)抽到 fudai_detail_helpers.swipe_with_fallback。
逻辑:
- 首选 operation.swipe
- 失败回退到 douyin_swipe_ops._adb_swipe_direct
- 最后兜底记录"swipe 失败"日志
类内 swipe 方法保留薄包装。
douyin_fudai.py: 1132 → 1078 行 (-54)
fudai_detail_helpers.py: 2975 → 3033 行
douyin_fudai.py 跌破 1100 行(4121 → 1078,本会话累计削减 3043 行 = -74%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:30:39 +08:00 |
|
 CodexandClaude Opus 4.7
|
6d5b2cfb15
|
refactor(fudai): 抽 run_once_basic 中"阶段分发"块到 dispatch_stage
将 100 行的 if/elif stage 分发链条整段抽到 fudai_detail_helpers.dispatch_stage:
- COUPON_POPUP → handle_coupon_popup
- SHOPPING_REDPACKET_POPUP → handle_shopping_redpacket_popup
- FANSCLUB_JOIN → handle_fansclub_join
- FUDai_DETAIL → analyser._handle_in_fudai_detail
- IN_LIVE_ROOM/LIVE_OR_UNKNOWN → handle_in_live_room_stage
- RECOMMEND_PAGE → handle_recommend_page
- FOLLOW_LIST/LIVE_LIST → reflash_zhibo
- FUDai_RESULT → handle_lottery_result_stage
- LIVE_CLOSED → swipe_up_to_next_live
- 其他 → 写"未匹配到特定阶段"日志
douyin_fudai.py: 1228 → 1132 行 (-96)
fudai_detail_helpers.py: 2890 → 2975 行
run_once_basic 函数从 220 → 124 行,主体只剩入口逻辑 + 7 个 try_xxx 早返回 + 1 个 dispatch_stage。
douyin_fudai.py 跌破 1200 行(4121 → 1132,本会话累计削减 2989 行 = -73%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:27:19 +08:00 |
|
 CodexandClaude Opus 4.7
|
01034347f4
|
refactor(finder): 抽 check_have_fudai_with_ready_screenshot 中"numpy 加速水平带扫描"块到 finder_numpy_scan
将 127 行的 numpy 加速扫描块抽到独立模块。
使用 numpy 批量处理,从最优位置向左右两侧交替搜索福袋图标的特征颜色。
helper 接受 (analyser, detected, detected_x, pic_new, width, height, rx, ry,
y_pianyi_val, optimal_x_scaled),返回更新后的 (detected, detected_x)。
finder.py: 553 → 435 行 (-118)
新增 finder_numpy_scan.py: 156 行
finder.py 跌破 500 行(1438 → 435,本会话累计削减 1003 行 = -70%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:24:50 +08:00 |
|
 CodexandClaude Opus 4.7
|
e3daeab024
|
refactor(finder): 抽 check_have_fudai_with_ready_screenshot 中"逐像素扫描兜底"块到 finder_pixel_scan
将 183 行的"numpy 未命中时的原始逐像素检查"块抽到独立模块。
保留了原代码"找到后退出外层 while 循环"的 break 语义(在调用方
检查返回的 detected 后 break)。
finder.py: 726 → 553 行 (-173)
新增 finder_pixel_scan.py: 207 行
finder.py 跌破 600 行(1438 → 553,本会话累计削减 885 行 = -62%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:22:20 +08:00 |
|
 CodexandClaude Opus 4.7
|
411fd96804
|
refactor(finder): 抽 check_have_fudai_with_ready_screenshot 中"模板匹配兜底"块到 finder_template_match
将 226 行的"OpenCV 模板匹配兜底"独立块抽到独立模块。
当像素检测未命中时,调用 cv2.matchTemplate 在指定区域查找福袋图标。
helper 接受 (analyser, detected, detected_x, pic_new, width, height, rx, ry,
y_pianyi_val, loop) 参数,返回更新后的 (detected, detected_x)。
finder.py: 944 → 726 行 (-218)
新增 finder_template_match.py: 257 行
finder.py 跌破 800 行(1438 → 726,本会话累计削减 712 行 = -50%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:17:18 +08:00 |
|
 CodexandClaude Opus 4.7
|
0bd71a5e76
|
refactor(stage): 抽 diagnose_stage_from_current_screen 中"步骤 1+1.5 福袋详情页/邀你抢红包"块到独立模块
将 313 行的"福袋详情页(任务数量像素检测)+ 邀你抢红包(OCR 检测)"块抽到
douyin_stage_step1.py:detect_fudai_detail_or_invite_redpacket。
逻辑:
- 从 pixel_details 提取任务数量并保存到 analyser._fudai_detail_task_count_from_stage
- has_fudai_detail=True → return ("FUDai_DETAIL", "任务数量检测确认")
- 否则在指定区域 OCR 检测"邀你抢红包"文字 → return ("FUDai_DETAIL", "OCR检测确认")
- 都未命中 → return None
依赖通过参数注入:analyser、pixel_state、pixel_details、trigger_reason、
max_step_time、diag_start、max_diag_time、log_fn/log_summary_fn/log_separator_fn、
preprocess_for_ocr。
douyin_stage.py: 757 → 462 行 (-295)
新增 douyin_stage_step1.py: 347 行
douyin_stage.py 跌破 500 行(1385 → 462,本会话累计削减 923 行 = -67%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:14:04 +08:00 |
|
 CodexandClaude Opus 4.7
|
cec4a2d692
|
refactor(stage): 抽 diagnose_stage_from_current_screen 中"步骤1+1.5 抽奖结果/购物红包"块到独立模块
将"优先级1(抽奖结果弹窗 + 按钮 OCR 确认)"和"优先级1.5(购物红包弹窗 OCR)"
两个相邻的 priority 检测块(约 104 行)抽到 douyin_stage_priority.py:
detect_lottery_or_redpacket_popup。
返回值约定:
- (stage, reason) 二元组:检测到弹窗时
- None:未检测到,调用方继续后续流程
依赖通过参数注入:analyser、pixel_state、max_step_time、diag_start、
max_diag_time、log_fn/log_summary_fn/log_separator_fn、preprocess_for_ocr。
douyin_stage.py: 845 → 757 行 (-88)
新增 douyin_stage_priority.py: 137 行
douyin_stage.py 跌破 800 行(1385 → 757,本会话累计削减 628 行 = -45%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:11:56 +08:00 |
|
 CodexandClaude Opus 4.7
|
ca071250be
|
refactor(stage): 抽 diagnose_stage_from_current_screen 中"步骤3 OCR 检测推荐页/关注列表/直播列表"块到独立模块
将 280 行的"OCR 标签栏检测"独立块抽到 douyin_stage_step3.py:detect_tab_pages_via_ocr。
逻辑:
- OCR 检测推荐页标签栏(启用 enable_ocr_mode1 时跑模式 0+1)
- 命中"推荐" → return RECOMMEND_PAGE
- 命中"关注"但没"推荐" → 精确截图 FOLLOW_TAB → return FOLLOW_LIST
- 命中"直播" → 精确截图 LIVE_LIST_TAB → return LIVE_LIST
- 都没命中 → return IN_LIVE_ROOM(默认)
依赖通过参数注入:analyser、enable_ocr_mode1、max_step_time、diag_start、
max_diag_time、log_fn、log_summary_fn、log_separator_fn、preprocess_for_ocr。
douyin_stage.py: 1111 → 845 行 (-266)
新增 douyin_stage_step3.py: 314 行
douyin_stage.py 跌破 900 行(1385 → 845,本会话累计削减 540 行 = -39%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:09:39 +08:00 |
|
 CodexandClaude Opus 4.7
|
398133bbb0
|
refactor(reservation): 抽 process_reservation_attend_window 中"if ok 整段后处理"块到 process_seek_success
将 188 行的"seek 成功后整段后处理"块抽到 helper:
- 写"回退操作成功"日志
- 检查 reservation_back_verify_enabled,启用时:
- wait_after_seek_and_verify 等待
- 调用 validate_back_to_reservation
- 校验失败 → handle_verify_failure_retry_via_mapping
- 校验通过 → 写日志
- setup_lock_period_and_log_success
返回值约定:
- True:处理成功(含校验通过 OR 校验失败重试成功)
- False:校验失败且重试失败
attend_window.py: 574 → 405 行 (-169)
attend_window_helpers.py: 804 → 994 行
attend_window.py 跌破 500 行(1437 → 405,本会话累计削减 1032 行 = -72%)
process_reservation_attend_window 函数从 1218 → 376 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:05:49 +08:00 |
|
 CodexandClaude Opus 4.7
|
06c3e54d26
|
refactor(reservation): 抽 process_reservation_attend_window 中"成功回退后设置锁定期"块到 setup_lock_period_and_log_success
将 84 行的"成功回退后处理"块抽到 helper:
- focus_until_ts = ft + poll_before(设置锁定期)
- reservation_after_action_pending = True
- 写"已回退到目标直播间"运行日志和"回退成功"行为日志
- write_state_callback
- 写"已触发回退"完成日志
attend_window.py: 637 → 574 行 (-63)
attend_window_helpers.py: 699 → 804 行
attend_window.py 跌破 600 行(1437 → 574,本会话累计削减 863 行 = -60%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:02:28 +08:00 |
|
 CodexandClaude Opus 4.7
|
28dcbc75c7
|
refactor(reservation): 抽 process_reservation_attend_window 中"回退校验失败 → 映射表二次回退"块到独立模块
将 375 行的最大独立块抽到 attend_window_verify_retry.py:handle_verify_failure_retry_via_mapping。
逻辑:
- 写"回退校验失败"日志(log_reservation_error 或 _log_kv)
- 通过映射表查找目标和当前直播间位置
- 计算映射差值,决定是否重试 seek
- 重试成功 → 设置锁定期 + 待处理标志,返回 True
- 重试失败 → 清理锁定相关标志,返回 False
调用方根据返回值 return True/False。
attend_window.py: 991 → 637 行 (-354)
新增 attend_window_verify_retry.py: 420 行
attend_window.py 跌破 700 行(1437 → 637,本会话累计削减 800 行 = -56%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 13:00:14 +08:00 |
|
 CodexandClaude Opus 4.7
|
dadb0b6852
|
refactor(reservation): 抽 process_reservation_attend_window 中"回退后等待直播间加载"块到 wait_after_seek_and_verify
将 43 行的等待逻辑抽到 helper:
- 读 reservation_back_verify_wait_seconds(默认 5.0,限制 0.1-10.0)
- 写"开始等待"日志
- 调用 operation.delay 或 time.sleep
- 写"等待完成"日志(含实际等待秒数)
attend_window.py: 1030 → 991 行 (-39)
attend_window_helpers.py: 645 → 699 行
attend_window.py 跌破 1000 行(1437 → 991,本会话累计削减 446 行 = -31%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:55:17 +08:00 |
|
 CodexandClaude Opus 4.7
|
6aec4ae314
|
refactor(reservation): 抽 process_reservation_attend_window 末尾"回退失败"块到 log_seek_failure_and_finish
将函数末尾"回退失败:记录日志,等待后续重试或清理"块(约 36 行)抽到 helper:
- 写"回退失败"日志
- 调用 write_state_callback
- 写"未触发回退"完成日志
attend_window.py: 1059 → 1030 行 (-29)
attend_window_helpers.py: 594 → 645 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:53:27 +08:00 |
|
 CodexandClaude Opus 4.7
|
4ce62a1907
|
refactor(reservation): 抽 process_reservation_attend_window 中"执行回退动作前的日志+seek 调用"块到 execute_seek_reservation_with_logging
将 76 行的"进入预约参与窗口"独立块抽到 helper:
- 写"进入预约参与窗口"日志
- 计算 current_room_pos / target_pos / pos_diff
- 写"准备执行回退到预约直播间"日志
- 调用 seek_reservation_room_callback(target)
- 异常时记录错误日志(log_reservation_error 或 _log_kv)
返回值:(ok: bool, current_room_pos: int, target_pos: int, pos_diff: int)
attend_window.py: 1121 → 1059 行 (-62)
attend_window_helpers.py: 496 → 594 行
attend_window.py 跌破 1100 行(1437 → 1059,本会话累计削减 378 行 = -26%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:50:02 +08:00 |
|
 CodexandClaude Opus 4.7
|
f0150cb3f4
|
refactor(reservation): 抽 process_reservation_attend_window 中"锁定期同预约检查"块到 handle_lock_period_same_reservation_check
将 148 行的"锁定期内的复杂检查"独立块抽到 helper:
- 队列满立即参与模式 → 跳过此检查
- 锁定期未结束 + 不是同一预约 → return False(不允许回退)
- 锁定期未结束 + 同一预约 + 已在目标位置 + 时间窗口到达 → return True(需要参与)
- 锁定期未结束 + 同一预约 + 已在目标位置 + 时间窗口未到 → return False(清除待处理标志)
- 锁定期未结束 + 同一预约 + 不在目标位置 → 写日志后 return None(继续检查)
返回值约定(None/True/False 三态):
- True:需要参与,调用方应直接 return True
- False:跳过/不允许回退,调用方应直接 return False
- None:检查通过,调用方继续后续逻辑
attend_window.py: 1247 → 1121 行 (-126)
attend_window_helpers.py: 329 → 496 行
attend_window.py 跌破 1200 行(1437 → 1121,本会话累计削减 316 行 = -22%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:47:41 +08:00 |
|
 CodexandClaude Opus 4.7
|
8d426676f6
|
refactor(fudai): 抽 attend_choujiang 中"粉丝团门槛"分支到 fudai_attend_fansclub
将 attend_choujiang 中"加入粉丝团/粉丝团"分支整段(1054 行)抽到
douyin/fudai/core/fudai_attend_fansclub.py:handle_fansclub_required。
逻辑:
- 保存 debug 截图(标注 OCR 区域)
- 第一步:点击参与按钮(OCR 区域中心 543, 2070)
- 第二步:OCR 识别"加入粉丝团"按钮位置并点击
- 第三步:关闭详情页
- 包含 OCR 重试、坐标缩放、自救恢复等深嵌套逻辑
主文件中保留 elif 分支头 + 7 行调用 helper。
fudai_attend.py: 1295 → 246 行 (-1049)
新增 fudai_attend_fansclub.py: 1075 行
attend_choujiang 函数从 1281 行跌到约 230 行。
fudai_attend.py 是本会话削减幅度最大的文件之一(1629 → 246,-85%)。
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:45:11 +08:00 |
|
 CodexandClaude Opus 4.7
|
f5b603e39e
|
refactor(fudai): 抽 run_once_basic 中"高价值预约整段处理"块到 process_high_value_reservation_check
将 high_value_enabled and reservations_list 分支整段(含 4 个回调闭包 + 6 步处理流程)
约 99 行抽到 process_high_value_reservation_check helper,内部组合:
- try_handle_queue_full_wait
- log_skip_preemption_reason
- reset_to_first_room_after_all_reservations_done
- log_first_reservation_check
- process_reservation_multi_room_mode(多间模式)
- cleanup_expired_reservations_single_room(单间模式)
返回值约定:
- True:触发了早返回(队列满等待 / 所有预约完成重置),调用方应直接 return
- False:未触发早返回,调用方继续
douyin_fudai.py: 1319 → 1228 行 (-91)
fudai_detail_helpers.py: 2804 → 2890 行
douyin_fudai.py 跌破 1300 行(4121 → 1228,本会话累计削减 2893 行 = -70%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:41:27 +08:00 |
|
 CodexandClaude Opus 4.7
|
b1f70aa94d
|
refactor(fudai): 抽 run_once_basic 中"跳过预约回退检查的原因日志"块到 log_skip_preemption_reason
将 27 行的纯日志分支抽到 helper:
- _waiting_for_lottery_result=True:写"正在等待开奖"日志
- _current_attending_reservation_fudai=True:写"正在参与预约福袋"日志
- queue_full_waiting_at_earliest=True:原代码无日志,保持原样
douyin_fudai.py: 1341 → 1319 行 (-22)
fudai_detail_helpers.py: 2776 → 2804 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:39:34 +08:00 |
|
 CodexandClaude Opus 4.7
|
81b82e6cba
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"提取 future_ts"和"detail 为 None 早返回"两块
- extract_future_ts_from_detail:从 detail tuple 提取倒计时 future_ts 写入 _current_fudai_future_ts
- handle_detail_none_in_step4:步骤4 detail 为 None 时的早返回处理
douyin_fudai.py: 1355 → 1341 行 (-14)
fudai_detail_helpers.py: 2742 → 2776 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:37:30 +08:00 |
|
 CodexandClaude Opus 4.7
|
2ba2168665
|
refactor(fudai): 抽 _handle_live_room_has_or_not_fudai 中两块到 helper
- try_skip_to_in_fudai_detail_when_verified(约 22 行):已验证过详情页则直接处理详情
- handle_no_fudai_in_live_room(约 35 行):无福袋时调用 flow_control 处理 + 写完成日志
douyin_fudai.py: 1404 → 1355 行 (-49)
fudai_detail_helpers.py: 2659 → 2742 行
douyin_fudai.py 跌破 1400 行(4121 → 1355,本会话累计削减 2766 行 = -67%)
_handle_live_room_has_or_not_fudai 从 90 行 → 41 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:33:25 +08:00 |
|
 CodexandClaude Opus 4.7
|
d9323f2012
|
refactor(fudai): 抽 run_once_basic 入口"记录直播间标题"块到 record_room_title_if_not_just_switched
将 run_once_basic 入口的"记录直播间标题"块(约 14 行)抽到 helper:
- 检查 _just_switched_room 标志
- 未刚切换时调用 _record_room_title_and_pos
- 刚切换时写"跳过重复记录"日志
douyin_fudai.py: 1412 → 1404 行 (-8)
fudai_detail_helpers.py: 2640 → 2659 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:30:36 +08:00 |
|
 CodexandClaude Opus 4.7
|
e3372fa51d
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"状态分发"和"保存详情"两块到 helper
将两个相邻的独立逻辑抽到 helper:
- dispatch_last_fudai_detail_status:根据 _last_fudai_detail_status 分发到 4 个 helper(coupon_popup/watch_task/validation_failed/error)
- save_first_open_detail:筛选通过后保存详情数据并写日志
douyin_fudai.py: 1468 → 1412 行 (-56)
fudai_detail_helpers.py: 2567 → 2640 行
douyin_fudai.py 跌破 1500 行(4121 → 1412,本会话累计削减 2709 行 = -66%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:29:02 +08:00 |
|
 CodexandClaude Opus 4.7
|
0b3d69d28b
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"额外验证 + 兜底检查"两块到 validate_detail_or_skip
将两个相邻的早返回检查(约 64 行)抽到 helper:
1. 额外验证:调用 validate_fudai_detail,失败则关闭详情 + 写完成日志
2. 兜底检查:content 为空且 prize_value_yuan=0 → 判定为无效详情
返回值约定:
- True:检查命中早返回(调用方应直接 return)
- False:检查通过,调用方继续后续流程
douyin_fudai.py: 1525 → 1468 行 (-57)
fudai_detail_helpers.py: 2493 → 2567 行
douyin_fudai.py 跌破 1500 行(4121 → 1468,本会话累计削减 2653 行 = -64%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:27:06 +08:00 |
|
 CodexandClaude Opus 4.7
|
0eb4670d46
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"task_count_zero 错误处理"块到 handle_task_count_zero_error
将"last_status == error 且 reason == task_count_zero"分支(约 87 行深嵌套)抽到 helper:
- 累加 _fudai_detail_consecutive_failures 计数
- 连续 3 次失败:强制关闭详情 + 切换直播间 + 重置计数 + 写完成日志
- 否则:写日志 + 写完成日志
返回值约定:
- True:已处理 task_count_zero 错误(调用方应直接 return)
- False:不是 task_count_zero 错误或处理异常,调用方继续
douyin_fudai.py: 1606 → 1525 行 (-81)
fudai_detail_helpers.py: 2398 → 2493 行
douyin_fudai.py 跌破 1600 行(4121 → 1525,本会话累计削减 2596 行 = -63%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:22:18 +08:00 |
|
 CodexandClaude Opus 4.7
|
5f713afc5c
|
refactor(fudai): 抽 run_once_basic 中"多间模式预约抢占"块到 process_reservation_multi_room_mode
将多间模式调用 process_reservation_attend_window 的逻辑(约 64 行)抽到 helper:
- 写"开始调用"日志
- 调用 process_reservation_attend_window
- 写返回结果日志
- 同步回写 focus_ref 和 after_action_ref 到 analyser
- 抢占成功时设置 _current_attending_reservation_fudai=True
douyin_fudai.py: 1648 → 1606 行 (-42)
fudai_detail_helpers.py: 2328 → 2398 行
douyin_fudai.py 跌破 1700 行(4121 → 1606,本会话累计削减 2515 行 = -61%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:20:02 +08:00 |
|
 CodexandClaude Opus 4.7
|
722b57a7b9
|
refactor(fudai): 抽 run_once_basic 中"预约队列满等待"块到 try_handle_queue_full_wait
将"队列已满 + 未在等待最早开奖"判定块(约 33 行)抽到 helper:
- 检查 reservations 数量 >= max_reservations 且 queue_full_waiting_at_earliest=False
- 满足时调用 douyin_reservation_logic.handle_queue_full_wait_at_earliest
- 成功 → 设置 queue_full_waiting_at_earliest 和 focus_until + 写完成日志
返回值约定:
- True:队列已满且已回退等待,调用方应直接 return
- False:队列未满或未触发回退,调用方继续
douyin_fudai.py: 1670 → 1648 行 (-22)
fudai_detail_helpers.py: 2273 → 2328 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:17:37 +08:00 |
|
 CodexandClaude Opus 4.7
|
43da92f6e6
|
refactor(fudai): 抽 run_once_basic 中"单间模式清理过期预约"块到 cleanup_expired_reservations_single_room
将单间模式下"清理过期预约"逻辑(约 24 行)抽到 helper:
- 写说明日志
- 调用 douyin_reservation_logic.cleanup_expired_reservations
- 异常时记录错误日志
douyin_fudai.py: 1688 → 1670 行 (-18)
fudai_detail_helpers.py: 2242 → 2273 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:15:56 +08:00 |
|
 CodexandClaude Opus 4.7
|
798286776d
|
refactor(fudai): 抽 run_once_basic 中"所有预约完成回退到第一个直播间"块到 reset_to_first_room_after_all_reservations_done
将"queue_full_waiting_at_earliest=True 且 reservations 为空时回退"独立块
(约 36 行)抽到 helper:
- 写日志
- 清除 queue_full_waiting_at_earliest 和 reservation_focus_until_ts
- 回退 room_pos 次(最多 100 次)
- 重置 room_pos 和 _swipe_times
返回值约定:
- True:触发了重置(调用方应直接 return)
- False:条件不满足或异常,调用方继续
douyin_fudai.py: 1715 → 1688 行 (-27)
fudai_detail_helpers.py: 2185 → 2242 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:14:16 +08:00 |
|
 CodexandClaude Opus 4.7
|
77d7113ca1
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"高价值跳过决策"块到 check_high_value_skip_decision
将筛选不通过后的"高价值福袋决策"逻辑(约 91 行深嵌套)抽到 helper:
- 检查是否高价值福袋(启用 + 价值达阈值 + 倒计时有效)
- 倒计时大于阈值 + 剩余秒数在 join_ahead 内 → 返回 "attend"(取消 skip)
- 倒计时大于阈值 + 剩余秒数 > join_ahead → 调用 handle_high_value_record_reservation 后返回 "recorded"
- 其他:返回 "skip" 让调用方走筛选不通过分支
返回值约定:
- "attend":调用方将 skip 设为 False 继续立即参与
- "recorded":已记录预约(调用方应直接 return)
- "skip":保持 skip=True 走筛选不通过分支
douyin_fudai.py: 1804 → 1715 行 (-89)
fudai_detail_helpers.py: 2083 → 2185 行
douyin_fudai.py 跌破 1800 行(4121 → 1715,本会话累计削减 2406 行 = -58%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:12:31 +08:00 |
|
 CodexandClaude Opus 4.7
|
b8ccb899c0
|
refactor(fudai): 抽 _handle_in_fudai_detail 步骤1"重新读取详情兜底"块到 reread_fudai_detail_fallback
将"未找到保存的详情数据时的兜底重读"逻辑(约 22 行)抽到 helper:
- 写说明日志
- 调用 read_fudai_detail_with_retries 重新读取
- 成功则更新 _last_fudai_detail_tuple 和 _current_fudai_content
- 返回 detail(成功)或 None(失败)
douyin_fudai.py: 1821 → 1804 行 (-17)
fudai_detail_helpers.py: 2047 → 2083 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:09:45 +08:00 |
|
 CodexandClaude Opus 4.7
|
d109e94c68
|
refactor(fudai): 抽 _handle_in_fudai_detail 步骤1"第二次打开直接参与"块到 handle_second_open_direct_attend
将 116 行的"第二次打开使用保存详情直接参与"块抽到 helper:
- 从 _last_fudai_detail_tuple 读取保存的详情
- 设置 _current_fudai_future_ts / _current_fudai_content
- 调用 attend_choujiang 直接参与
- 更新连续失败计数器(成功重置/失败 +1)
- 清除标志 + 写步骤1完成日志
返回值约定:
- True:已完成第二次打开的直接参与处理(调用方应直接 return)
- False:保存的详情数据无效或参与异常,调用方继续兜底逻辑
douyin_fudai.py: 1921 → 1821 行 (-100)
fudai_detail_helpers.py: 1930 → 2047 行
douyin_fudai.py 跌破 1900 行(4121 → 1821,本会话累计削减 2300 行 = -56%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:07:55 +08:00 |
|
 CodexandClaude Opus 4.7
|
887f8bad3e
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"筛选不通过"块到 handle_filter_skip
将筛选不通过分支(约 50 行)抽到 helper:
- 写"筛选不通过"日志
- 关闭详情页
- 按 needswitch 切换直播间
- clear_task_count_flag
- 写完成日志
douyin_fudai.py: 1962 → 1921 行 (-41)
fudai_detail_helpers.py: 1876 → 1930 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:05:29 +08:00 |
|
 CodexandClaude Opus 4.7
|
c2a44f2544
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"高价值福袋记录预约"块到 handle_high_value_record_reservation
将剩余秒数 > 预约参与阈值时的预约记录分支(约 50 行)抽到 helper:
- 写"记录预约"日志(含 reason / value / threshold / remain_seconds)
- 调用 basic_join_decision 记录预约(内部已关闭详情)
- 写完成日志(无论 basic_join_decision 是否成功)
douyin_fudai.py: 1996 → 1962 行 (-34)
fudai_detail_helpers.py: 1809 → 1876 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:03:39 +08:00 |
|
 CodexandClaude Opus 4.7
|
f2b5aaa2c4
|
refactor(fudai): 抽 _handle_in_fudai_detail 步骤2"第一次打开数据验证失败"块到 handle_first_open_validation_failed
将 36 行的早返回块抽到 helper:
- 写跳过日志(含 validation_reason)
- 关闭详情页
- 写步骤2完成日志
- clear_task_count_flag
- 写主流程完成日志
douyin_fudai.py: 2020 → 1996 行 (-24)
fudai_detail_helpers.py: 1769 → 1809 行
douyin_fudai.py 跌破 2000 行(4121 → 1996,本会话累计削减 2125 行 = -52%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 12:01:22 +08:00 |
|
 CodexandClaude Opus 4.7
|
4f042f95cd
|
refactor(fudai): 抽 _handle_in_fudai_detail 步骤4"参与成功后处理"块到 handle_attend_success_post_processing
将参与成功后的清理逻辑(约 90 行)抽到
fudai_detail_helpers.handle_attend_success_post_processing。逻辑:
- 检查 _last_successful_attend_ts 是否更新
- 从 detail 提取倒计时
- 设置 _waiting_for_lottery_result / _lottery_result_expected_ts
- 调用 handle_reservation_after_attend_success
- 关闭详情页(如未由 attend_choujiang 关闭)
- 清除标志 + 写步骤4完成日志
顺带删除了 1984-1996 行重复 2 次的"清除第一次读取标志"块。
douyin_fudai.py: 2102 → 2020 行 (-82)
fudai_detail_helpers.py: 1678 → 1769 行
douyin_fudai.py 跌破 2100 行(4121 → 2020,本会话累计削减 2101 行 = -51%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 11:59:18 +08:00 |
|
 CodexandClaude Opus 4.7
|
23e24a9f27
|
refactor(fudai): 抽 _handle_live_room_has_or_not_fudai 中"锁定期内时间窗口未到"块到 should_skip_fudai_search_in_lock_period
将 49 行的早返回检查抽到 helper:
- focus_until > now_ts(在锁定期内)
- queue_full_waiting_at_earliest=True
- 队头预约 future_ts - join_ahead > now_ts → 跳过查找避免重复打开详情
返回值约定:
- True:满足跳过条件,已写完成日志,调用方应直接 return
- False:不满足,调用方继续正常流程
douyin_fudai.py: 2144 → 2102 行 (-42)
fudai_detail_helpers.py: 1614 → 1678 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 11:56:51 +08:00 |
|
 CodexandClaude Opus 4.7
|
c5a70d4a62
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"参与成功后预约处理"块到 handle_reservation_after_attend_success
将参与成功后的预约清理逻辑(约 116 行)抽到
fudai_detail_helpers.handle_reservation_after_attend_success。逻辑:
- 如果还有其他预约:设置 10 秒保护期确保依次参与
- 如果没有其他预约:清除锁定期
- 从队列中移除当前刚完成的预约(5 秒误差匹配)
- 重新排序剩余队列
douyin_fudai.py: 2260 → 2144 行 (-116)
fudai_detail_helpers.py: 1495 → 1614 行
douyin_fudai.py 跌破 2200 行(4121 → 2144,本会话累计削减 1977 行 = -48%)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 11:54:02 +08:00 |
|
 CodexandClaude Opus 4.7
|
3de07d7a66
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"简单跳过状态"的 3 个分支到 handle_simple_skip_status
last_status == "coupon_popup" / "watch_task" / "validation_failed" 三个分支
结构完全相同(写日志 → clear_task_count_flag → 写完成日志 → return),
统一抽到 handle_simple_skip_status 通用模板。
douyin_fudai.py: 2281 → 2260 行 (-21)
fudai_detail_helpers.py: 1468 → 1495 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 11:51:39 +08:00 |
|
 CodexandClaude Opus 4.7
|
d35fadde54
|
refactor(fudai): 复用 fallback_swipe_up_to_next_live helper 替换"task_count_zero 连续失败"分支重复代码
_handle_in_fudai_detail 中"连续3次任务数量为0"分支也有 65 行结构完全相同的
兜底 ADB 上滑逻辑(与上一 commit 抽出的 fallback_swipe_up_to_next_live 完全一致),
复用同一个 helper。
douyin_fudai.py: 2336 → 2281 行 (-55)
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 11:49:39 +08:00 |
|
 CodexandClaude Opus 4.7
|
241c35f21d
|
refactor(fudai): 抽 _handle_in_fudai_detail 中"兜底上滑切房"块到 fallback_swipe_up_to_next_live
将筛选不通过后的兜底切换逻辑(67 行深度嵌套)抽到
fudai_detail_helpers.fallback_swipe_up_to_next_live。逻辑:
- 优先 swipe_up_to_next_live
- 兜底直接调用 ADB shell input swipe(基于 1080x2400 基准坐标缩放)
- 最终回退到 operation.swipe
douyin_fudai.py: 2400 → 2336 行 (-64)
fudai_detail_helpers.py: 1403 → 1468 行
验证:
- pytest 1013 passed
- compile OK
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-22 11:47:44 +08:00 |
|