# DAIX.fun Agent Playbook

> 🤖 本文件供 OpenClaw 读取后自动执行 APP 开发、构建、上传、上架全流程
> 📋 版本：v1.0 | 日期：2026-06-29

---

## 1. 环境信息

```
ANDROID_SDK: /Users/mac/Library/Android/sdk
GRADLE: ./gradlew
JAVA: /usr/bin/java
NODE: /Users/mac/Documents/Codex/convnet-dapp/node_modules/.bin
FTP_HOST: 43.166.240.93
FTP_PORT: 21
FTP_USER: hackathon
FTP_PASS: hackathon2026
FTP_MODE: active (必须 set_pasv(False))
SERVER_SSH: root@43.166.240.93 (密码: buchiMIFAN139)
WEB_ROOT: /www/wwwroot/daix.fun/
GITHUB: https://github.com/zhulianxing/daix-fun.git
```

---

## 2. 项目目录结构

```
/Users/mac/Documents/Codex/
├── convnet-dapp/                    ← 合约项目 (Hardhat)
│   ├── contracts/                   ← Solidity 合约源码
│   ├── scripts/                     ← 部署/测试脚本
│   ├── Web3LicenseManager.java      ← 标准授权模块 (341行)
│   └── deployment-v2.json           ← 合约地址配置
├── daix-fun/                        ← 前端项目
│   ├── index.html                   ← 单页前端 (1889行)
│   └── ethers.umd.min.js            ← ethers.js v6
├── ElderGuard/                      ← 长者守护 (com.elderguard.care)
├── fall-detect-guardian/            ← 跌倒守护 (com.falldetect.guardian)
└── 2026-06-23/
    ├── multi-apps/
    │   ├── storeguard/              ← 高尔夫测距 (com.golfranger.distancemeter)
    │   ├── guardianfind/            ← 走失守护 (com.guardianfind.missingperson)
    │   ├── lossguard/               ← 商铺防损 (com.lossguard.shopsecurity)
    │   ├── vipreception/            ← VIP迎宾 (com.storeguard.vipreception)
    │   ├── attendanceguard/         ← 刷脸考勤 (com.attendanceguard.clock)
    │   └── visitorcount/            ← 客流统计 (com.visitorcount.analysis)
    └── chrome-plugin-chrome-openai-bundled-file-3/
        └── (单点抓拍 com.localguard.pedestriancapture)
```

---

## 3. 已注册 APP 清单 (链上)

| ID | 包名 | 名称 | 价格 | 项目目录 |
|----|------|------|------|----------|
| 1 | com.storeguard.vipreception | VIP迎宾 | 198 | multi-apps/vipreception |
| 2 | com.guardianfind.missingperson | 走失守护 | 99 | multi-apps/guardianfind |
| 3 | com.lossguard.shopsecurity | 商铺防损 | 128 | multi-apps/lossguard |
| 4 | com.attendanceguard.clock | 刷脸考勤 | 298 | multi-apps/attendanceguard |
| 5 | com.visitorcount.analysis | 客流统计 | 198 | multi-apps/visitorcount |
| 6 | com.golfranger.distancemeter | 高尔夫测距 | 168 | multi-apps/storeguard |
| 7 | com.falldetect.guardian | 跌倒守护 | 268 | fall-detect-guardian |
| 8 | com.elderguard.care | 长者守护 | 268 | ElderGuard |
| 9 | com.localguard.pedestriancapture | 单点抓拍 | 128 | chrome-plugin-... |

---

## 4. 自动化流程：新 APP 上架

当用户说"帮我上架一个新APP"或"创建一个XX APP"时，执行以下步骤：

### Step 1: 确认信息

向用户确认以下参数（缺失则询问）：
- APP 名称
- 包名 (com.xxx.xxx)
- 价格 (USDC)
- 功能描述

### Step 2: 创建项目

```bash
# 以 multi-apps/storeguard 为模板
TEMPLATE="/Users/mac/Documents/Codex/2026-06-23/multi-apps/storeguard"
DEST="/Users/mac/Documents/Codex/2026-06-23/multi-apps/${NEW_DIR}"

# 复制（排除构建产物）
rsync -a --exclude='work' --exclude='outputs' --exclude='.gradle' \
  --exclude='build' --exclude='local.properties' --exclude='.idea' \
  "$TEMPLATE/" "$DEST/"

# 修改包名
sed -i '' "s/com.golfranger.distancemeter/${PACKAGE_NAME}/g" "$DEST/app/build.gradle.kts"

# 修改应用名
sed -i '' "s/智能迎宾/${APP_NAME}/g" "$DEST/app/src/main/res/values/strings.xml"
```

### Step 3: 验证 Web3LicenseManager

```bash
# 确认文件存在
ls "$DEST/app/src/main/java/com/example/pedestriancapture/data/Web3LicenseManager.java"

# 确认合约地址正确
grep "LICENSE_QUERY" "$DEST/app/src/main/java/com/example/pedestriancapture/data/Web3LicenseManager.java"
# 应输出: private static final String LICENSE_QUERY = "0xb36Fd748026097e0F18A644452E739DECf4d0686";
```

### Step 4: 构建 APK

```bash
cd "$DEST"
./gradlew assembleRelease
# 输出: app/build/outputs/apk/release/app-release.apk
```

### Step 5: 上传 APK 到 FTP

```python
from ftplib import FTP

ftp = FTP()
ftp.connect("43.166.240.93", 21, timeout=15)
ftp.login("hackathon", "hackathon2026")
ftp.set_pasv(False)  # 必须主动模式

apk_name = f"{PACKAGE_NAME}-{VERSION}.apk"
with open("app-release.apk", "rb") as f:
    ftp.storbinary(f"STOR /apk/{apk_name}", f)

ftp.quit()
```

### Step 6: 链上注册 APP

```javascript
// 使用 ethers.js
const appRegistry = new ethers.Contract(APP_REGISTRY, APP_ABI, signer);
const tx = await appRegistry.registerApp(
  APP_NAME,           // 名称
  PACKAGE_NAME,       // 包名
  DESCRIPTION,        // 描述
  APK_URI,            // APK 地址 (FTP: ftp://43.166.240.93/apk/xxx.apk)
  ICON_URI,           // 图标地址
  ethers.parseUnits(PRICE, 6),  // 价格
  7,                  // 试用天数
  "v1.0.0"            // 版本号
);
await tx.wait();
```

### Step 7: 更新 GitHub

```bash
cd /tmp
git clone --depth 1 https://zhulianxing:TOKEN@github.com/zhulianxing/daix-fun.git
# 复制新项目到 apps/ 目录
# git add, commit, push
```

---

## 5. 自动化流程：APP 更新版本

当用户说"更新XX APP"时：

### Step 1: 定位项目

```bash
# 根据 APP 名称或包名查找目录
find /Users/mac/Documents/Codex -name "build.gradle.kts" -path "*/app/*" \
  -exec grep -l "PACKAGE_NAME" {} \;
```

### Step 2: 构建新版本

```bash
cd PROJECT_DIR
./gradlew assembleRelease
```

### Step 3: 上传新 APK

```python
# FTP 上传，文件名包含新版本号
ftp.storbinary(f"STOR /apk/{PACKAGE_NAME}-{NEW_VERSION}.apk", open("app-release.apk","rb"))
```

### Step 4: 链上更新

```javascript
await appRegistry.updateApp(appId, NEW_VERSION, NEW_APK_URI, newPrice);
```

---

## 6. 自动化流程：构建并部署前端

当用户说"更新前端"或"部署 daix.fun"时：

### Step 1: 上传前端文件

```bash
sshpass -p 'buchiMIFAN139' scp -o StrictHostKeyChecking=no \
  /Users/mac/Documents/Codex/daix-fun/index.html \
  root@43.166.240.93:/www/wwwroot/daix.fun/index.html

sshpass -p 'buchiMIFAN139' scp -o StrictHostKeyChecking=no \
  /Users/mac/Documents/Codex/daix-fun/ethers.umd.min.js \
  root@43.166.240.93:/www/wwwroot/daix.fun/ethers.umd.min.js
```

### Step 2: 验证

```bash
curl -s "https://daix.fun/" | head -5
```

---

## 7. 自动化流程：测试

当用户说"测试一下"时，执行链上查询测试：

```javascript
const { ethers } = require("ethers");
const provider = new ethers.JsonRpcProvider("https://polygon-bor-rpc.publicnode.com");

// 测试 DeveloperRegistry
const devReg = new ethers.Contract("0x8EE775e943C31EA7c4eF2B7bb83e0651c9d04001",
  ["function isRegistered(address) view returns (bool)",
   "function getDeveloper(address) view returns (string,string,uint256,bool)"], provider);

// 测试 AppRegistry
const appReg = new ethers.Contract("0xdFCFA7d871cCc3674d873d00192Ba26a685B2b68",
  ["function nextAppId() view returns (uint256)",
   "function apps(uint256) view returns (uint256,address,string,string,string,string,string,uint256,uint256,string,uint256,uint256,bool)",
   "function getDeveloperApps(address) view returns (uint256[])"], provider);

// 测试 LicenseQuery
const query = new ethers.Contract("0xb36Fd748026097e0F18A644452E739DECf4d0686",
  ["function verifyLicense(address,uint256) view returns (bool,uint256)",
   "function getAppByPackageName(string) view returns (uint256,bool)"], provider);

// 测试 LicenseNFT
const nft = new ethers.Contract("0x7Ed65226C66b188f66AA0e5483917B1C33a41225",
  ["function totalSupply() view returns (uint256)",
   "function DEV_SHARE() view returns (uint256)",
   "function AGENT_SHARE() view returns (uint256)"], provider);
```

---

## 8. 合约地址速查

```
DeveloperRegistry : 0x8EE775e943C31EA7c4eF2B7bb83e0651c9d04001
AppRegistry       : 0xdFCFA7d871cCc3674d873d00192Ba26a685B2b68
LicenseNFT        : 0x7Ed65226C66b188f66AA0e5483917B1C33a41225
PromoterRegistry  : 0xeed4653f341F810e00A73c6ECD454a1205C0Cabb
LicenseQuery      : 0xb36Fd748026097e0F18A644452E739DECf4d0686
USDC              : 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359
```

---

## 9. 价格表

| APP | 价格 (USDC) |
|-----|-------------|
| VIP迎宾 | 198 |
| 走失守护 | 99 |
| 商铺防损 | 128 |
| 刷脸考勤 | 298 |
| 客流统计 | 198 |
| 高尔夫测距 | 168 |
| 跌倒守护 | 268 |
| 长者守护 | 268 |
| 单点抓拍 | 128 |

---

## 10. 分账规则

```
有推广者:  开发者 60% + 推广者 25% + 平台 10% + Gas 5% = 100%
无推广者:  开发者 85% + 平台 10% + Gas 5% = 100%
```

---

## 11. Web3LicenseManager 关键配置

```java
// 所有 APP 共用以下配置（已内置在模板中）
RPC_URL = "https://polygon-bor-rpc.publicnode.com"
LICENSE_QUERY = "0xb36Fd748026097e0F18A644452E739DECf4d0686"
LICENSE_NFT = "0x7Ed65226C66b188f66AA0e5483917B1C33a41225"
CHAIN_ID = 137
TRIAL_DAYS = 7
```

---

## 12. 文档 URL

```
https://daix.fun/developer-guide.md      ← 开发者接入标准
https://daix.fun/technical-reference.md  ← 技术参考手册
https://daix.fun/promoter-guide.md       ← 推广者指南
https://daix.fun/user-guide.md           ← 用户指南
https://daix.fun/control-panel.md        ← 控制面板文档
https://daix.fun/daix-upload.py          ← FTP 上传工具
```
