Metadata-Version: 2.4
Name: sma-autoui
Version: 1.2.7
Summary: Smart Mobile Automation UI Framework
Home-page: https://github.com/Fun-Fox
Author: FunFox
Author-email: FunFox@example.com
License: MIT
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: loguru>=0.7.0
Requires-Dist: pytz>=2026.5
Requires-Dist: appium-python-client>=6.0.5
Requires-Dist: pillow>=10.0.0
Requires-Dist: lxml>=5.1.0
Requires-Dist: rapidocr>=3.0
Requires-Dist: onnxruntime>=1.20
Requires-Dist: requests>=2.27.1
Requires-Dist: jinja2>=3.0.3
Requires-Dist: pyyaml>=6.0
Requires-Dist: pydantic>=2.14.1
Requires-Dist: pydantic-ai-slim[logfire,openai,typesafe]>=2.54.0
Requires-Dist: filelock>=3.12.2
Requires-Dist: python-dotenv>=1.2.4
Requires-Dist: pymysql>=1.2.3
Requires-Dist: redis>=8.1.0
Requires-Dist: taospy>=2.7.0
Requires-Dist: selenium>=4.37.0
Requires-Dist: numpy>=2.5.4
Requires-Dist: setuptools>=69.0.3
Dynamic: license-file

﻿# SMA AutoUI

> 智能移动自动化 UI 框架 —— 面向社交媒体平台的 Android 设备自动化，融合 ADB 直达、视觉识别与 LLM 认知自愈能力。

📦 PyPI：<https://pypi.org/project/sma-autoui/>

---

## 🚀 快速开始

```bash
# 从 PyPI 安装
pip install sma-autoui

# 或从源码安装
pip install .
```

---

## 🌟 核心特性

| 特性 | 说明 |
|------|------|
| ✅ **多平台适配** | 10 个社交平台业务抽象（TikTok / 抖音 / 小红书 / 微博 / X / Threads / Instagram / Facebook / WhatsApp / 酷安） |
| ✅ **Session 复用** | 跨任务会话持久化与保活架构 |
| ✅ **视觉匹配** | 模板匹配下沉 Appium images-plugin（服务端 OpenCV + 自动缩放）+ OCR 文字定位，文字优先、图标兜底 |
| ✅ **ADB 直达** | 困难页面（直播间 / SurfaceView）直接注入事件，绕开 W3C 限制 |
| ✅ **拟人化行为** | 点击抖动（jitter）、连点、随机等待、概率化交互 |
| ✅ **AI 驱动** | 基于 pydantic-ai 的 Agent 编排 + 结构化输出 + 双通道模型（生成 / 判定） |
| ✅ **自愈能力** | UI 异常自动诊断与恢复，规则注册 / 淘汰闭环 |
| ✅ **离线诊断回放** | 回放夹具（ReplayHarness）复现线上 AI 调用 + 调用轨迹汇总（telemetry） |

> 完整项目结构与各层模块职责，详见 [🏗️ 系统架构](./docs/architecture/index.md)。

---

## 📖 文档

文档按 `sma_autoui` 的包结构组织，入口见 [docs/index.md](./docs/index.md)。

| 文档 | 描述 |
|------|------|
| [文档首页](./docs/index.md) | 阅读路径与包索引 |
| [快速开始](./docs/getting-started/index.md) | 安装与最小任务 |
| [环境搭建](./docs/getting-started/appium-adb-setup.md) | Appium + ADB 完整环境搭建与验证 |
| [架构总览](./docs/architecture/index.md) | 模块边界、调用链与自愈机制 |
| [driver 驱动层](./docs/driver/index.md) | 设备、会话、动作、定位、页面检查 |
| [ai 能力层](./docs/ai/index.md) | Agent、模型兼容、Skill 与 Scope |
| [healing 自愈](./docs/healing/index.md) | 诊断、规则回放、执行与反馈 |
| [common 基建](./docs/common/index.md) | 上报通道、通知域、TaskReport / SharedLedger |
| [运维与排障](./docs/operations/index.md) | 运行、日志与常见坑点 |
| [变更记录](./docs/changelog/index.md) | 2026-11 重构与版本日志 |

本地预览文档站：

```bash
pip install -r requirements-docs.txt
python -m mkdocs serve
```

### 快速导航

- **新入门** → [环境搭建](./docs/getting-started/appium-adb-setup.md) → [架构总览](./docs/architecture/index.md)
- **写业务脚本** → [driver 驱动层](./docs/driver/index.md) → [engine 执行引擎](./docs/engine/index.md)
- **定位 / 自愈** → [定位入口（locating）](./docs/driver/locating.md) → [自愈体系](./docs/healing/index.md)
- **AI 能力** → [Agent 体系](./docs/ai/agents.md) → [Skill 与 Scope](./docs/ai/skills.md)
- **遇到问题** → [常见坑点](./docs/operations/pitfalls.md)
- **看版本改了什么** → [变更记录](./docs/changelog/index.md)

---

## 💻 使用示例

```python
from appium.webdriver.common.appiumby import AppiumBy
from sma_autoui.driver import Device, Driver
from sma_autoui.engine import TaskRunner

# 1. 初始化设备（ADB 连接 + 环境准备）
device = Device(device_name="172.25.2.20:5555", adb_port=5002)
device.initialize_env()

# 2. 创建驱动实例（门面，聚合 actions / ElementLocator / inspector / vision / browser）
driver = Driver(
    device=device,
    appium_url="http://localhost:4723",
    job_id="example_job",
    desired_caps={...},
    app_name="xhs",
    app_version="1.0.0",
    task_name="example_task",
)

# 3. 定位（四种方式各有专用入口，统一返回 FindResult）
result = driver.find_element(
    locators=[(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Follow")')],
    timeout=10,
    ai_recovery=True,          # 元素定位失败时触发 AI 诊断自愈
)
# driver.find_ocr(texts=["Follow"])          # OCR 文字定位
# driver.find_image(templates=["btn_follow"])  # 图片模板定位
# driver.find_semantic("点关注按钮")            # 语义定位（XML + 截图 → 模型给候选 → 屏上复检）

element = result.element       # 取活元素；坐标点击用 result.point
driver.tap_by_adb(x=500, y=800, jitter=8)   # ADB 直达 + 坐标抖动
driver.smart_swipe(direction="UP", degree="MIDDLE")

# 4. 任务重试、异常自愈与保活由 TaskRunner 统一处理
TaskRunner(driver=driver).run(task_func=my_flow, task_name="example_task")
```

---

## 🔧 从源码安装

```bash
git clone https://github.com/Fun-Fox/sma_autoui.git
cd sma_autoui
pip install -r requirements.txt
pip install -e .
```

---

## 📄 开源协议

MIT License

---

Built with ❤️ by FunFox
