# data-service-infra-ai-configurations

> AI skills and automation tools for Data Service Infra team

This repository accumulates AI tool experience and enables rapid integration of personal AI agents.

## AI Agent Quick Start

### Step 1: Install OpenClaw + Clone This Code Repository

```bash
# Install OpenClaw CLI
# macOS
brew install openclaw/tap/openclaw

# Linux
curl -sSL https://get.openclaw.ai | sh

# Or download from releases
# See: https://github.com/openclaw/openclaw/releases

# Clone this repository to your preferred location
git clone git@github.com:tidbcloud/data-service-infra-ai-configurations.git ~/data-service-infra-ai-configurations
# Or: git clone git@github.com:tidbcloud/data-service-infra-ai-configurations.git /your/path/here
```

> **Note**: Replace `~/data-service-infra-ai-configurations` with your actual clone path in all commands below.

### Step 2: Run Setup Based on Your Role

Tell the agent your role, and it will auto-configure:

#### Personal Agent

```
I am a personal agent. Run setup:
bash <your-clone-path>/skills/setup/run.sh personal
```

#### Team Admin

```
I am a team-admin agent. Run setup:
bash <your-clone-path>/skills/setup/run.sh team-admin
```

#### Team Workflow

```
I am a team-workflow agent. Run setup:
bash <your-clone-path>/skills/setup/run.sh team-workflow
```

#### Team Code Expert

```
I am a team-code-expert agent. Run setup:
bash <your-clone-path>/skills/setup/run.sh team-code-expert
```

---

## Why This Document?

We wrote this document with the following goals:

### 1. Capability Reuse & Adoption
Other teams can use this document as a reference to quickly replicate the same architecture, reducing duplicate work and avoiding common pitfalls.

### 2. Technical Documentation
Serve as a record of our technical decisions, making it easy to review, iterate, and help new members understand our AI automation journey.

### 3. Internal Knowledge Sharing
Enable team members to quickly get started by understanding our architecture design, daily maintenance procedures, and how to extend it for their own use cases.

---

## Architecture Overview

### Four Roles

| Role | Location | Purpose |
|------|----------|---------|
| team-admin | Physical Host | Cron jobs, config management for all containers |
| team-workflow | openclaw-team-assist container | Wiki, team notifications |
| team-code-expert | openclaw-team-code-expert container | Code review, PR workflows |
| personal | openclaw-{member1,member2,member3,...} | Personal AI agents |

### Docker Architecture

```
┌─────────────────────────────────────────────────────────┐
│  Physical Host                                          │
│  ┌─────────────────────────────────────────────────┐   │
│  │  [team-admin]                                    │   │
│  │  • Manages all OpenClaw container configs       │   │
│  │  • Daily inspection (0:00 UTC)                  │   │
│  │  • Memory backup (2:00 UTC)                     │   │
│  └─────────────────────────────────────────────────┘   │
│  • SSH access                                          │
│  • docker exec into any container                      │
└─────────────────────────────────────────────────────────┘
                          │
           ┌──────────────┴──────────────┐
           │         Docker Network       │
           ▼                              ▼
┌───────────────────┐  ┌─────────────────────┐  ┌─────────────────────────────┐
│ [team-workflow]   │  │ [team-code-expert]  │  │  [personal]                │
│ ┌───────────────┐ │  │ ┌───────────────┐   │  │  ┌──────┐ ┌──────┐ ┌────┐ │
│ │ openclaw-     │ │  │ │ openclaw-     │   │  │  │member│ │member│ │mem │ │
│ │ team-assist   │ │  │ │ team-code-    │   │  │  │   1 │ │   2 │ │ ber│ │
│ │               │ │  │ │ expert        │   │  │  │  ... │ │      │ │    │ │
│ └───────────────┘ │  │ └───────────────┘   │  │  └──────┘ └──────┘ └────┘ │
│ NO PORT           │  │ NO PORT            │  │  NO PORT                   │
└───────────────────┘  └─────────────────────┘  └─────────────────────────────┘
```

### Key Features

- **Zero Port Exposure**: All containers communicate via Feishu only
- **Role Separation**: team-admin / team-workflow / team-code-expert / personal
- **Easy Scaling**: Add new personal containers with minimal changes
- **Auto Backup**: Daily workspace backups at 2:00 UTC (team-admin)
- **Daily Reports**: Automated status reports at 9:00 UTC (team-admin)

---

## Directory Structure

```
├── skills/
│   ├── setup/           # Auto-setup scripts
│   ├── team-admin/      # Team admin skills
│   │   ├── add-employee/
│   │   ├── backup-config/
│   │   ├── check-openclaw-status/
│   │   └── daily-inspection/
│   └── team-code-expert/ # Code review skills
│       └── pr-review-daemon/
├── cronjobs/
│   ├── team-admin/       # Admin/management cronjobs
│   │   ├── daily-inspection/
│   │   └── daily-memory-backup/
│   └── team-workflow/    # Workflow cronjobs
│       ├── ai-news/
│       ├── bi-weekly-ai-news/
│       ├── daily-task-sync/
│       ├── weekly-ticket-report/
│       └── weekly-tidb-competitor/
└── memories/
    └── configuration.md
```

---

## Team Skills

Each skill follows the pattern:
- `SKILL.md` - Documentation
- `run.sh` or `<name>.sh` - Execution script

### Dependencies

Some skills require external dependencies:

| Skill | Dependencies |
|-------|-------------|
| check-openclaw-status | docker (optional, graceful fallback) |
| daily-inspection | docker, openclaw CLI |
| backup-config | docker (for config backup) |
| add-employee | docker, openclaw CLI |

**Note**: Skills will gracefully degrade if optional dependencies are not available.

### Available Skills

| Skill | Purpose |
|-------|---------|
| setup | Auto-setup skills based on role |
| add-employee | Add new employee container |
| backup-config | Backup config directory |
| check-openclaw-status | Check service status |
| daily-inspection | Daily inspection report |

---

## Team Code Expert

The `team-code-expert` role is dedicated to team code review and test management functions.

### What It Does

- **Automated PR Review**: Monitors repository for new PRs and performs AI-powered code analysis
- **PR Notifications**: Sends review summaries to Feishu when PRs are created
- **Security Scanning**: Checks for hardcoded secrets, sensitive data, and security issues

### Available Skills

| Skill | Purpose |
|-------|---------|
| pr-review-daemon | Automated PR monitoring and code review daemon |

### How It Works

The PR review daemon runs as a background service:
1. Polls GitHub every 60 seconds for new PRs
2. Analyzes PR changes using AI
3. Posts review results to Feishu group

### Note

This role does not use cronjobs. Instead, it runs as a long-running daemon process.

---

## Cronjobs

### team-admin

| Cronjob | Schedule | Purpose |
|---------|----------|---------|
| daily-inspection | UTC 0:00 | Daily status report |
| daily-memory-backup | UTC 2:00 | Backup memory files |

### team-workflow

| Cronjob | Schedule | Purpose |
|---------|----------|---------|
| daily-task-sync | UTC 10:00 | Sync task progress |
| weekly-ticket-report | Thu UTC 9:00 | TCOC weekly summary |
| ai-news | UTC 9:00 | Daily AI news |
| bi-weekly-ai-news | UTC 9:00 | Bi-weekly AI news |
| weekly-tidb-competitor | Mon UTC 9:00 | TiDB competitor dynamics |

### Adding Cronjobs

> **Replace** `<your-clone-path>` with your actual clone path.

```bash
# For team-workflow role - ai-news
openclaw cron add --name ai-news \
  --cron "0 9 * * *" \
  -- "bash <your-clone-path>/cronjobs/team-workflow/ai-news/main.sh"

# For team-admin role - daily inspection
openclaw cron add --name daily-inspection \
  --cron "0 0 * * *" \
  -- "bash <your-clone-path>/cronjobs/team-admin/daily-inspection/main.sh"

# For team-workflow role - weekly ticket report
openclaw cron add --name weekly-ticket-report \
  --cron "0 9 * * 4" \
  -- "bash <your-clone-path>/cronjobs/team-workflow/weekly-ticket-report/main.sh"
```

---

## Deployment

### Prerequisites

- Docker & Docker Compose
- OpenClaw CLI (see Quick Setup section)
- SSH access to the host

### Deploy All Containers

The deployment scripts are in the `openclaw-team` repository:

```bash
# Clone the team deployment repo (if not already)
git clone git@github.com:tidbcloud/openclaw-team.git ~/openclaw-team
# Or: git clone git@github.com:tidbcloud/openclaw-team.git /your/path

# Deploy all containers
cd ~/openclaw-team
bash deploy.sh
```

### Check Status

```bash
docker ps
docker stats
```

### View Logs

```bash
docker logs -f openclaw-member1
docker logs -f openclaw-team-assist
```

---

## Troubleshooting

### Container Won't Start

```bash
# Check container logs
docker logs <container-name>

# Check resource usage
docker stats

# Restart container
docker restart <container-name>
```

### Feishu Messages Not Received

1. Check if the bot is still a member of the chat/workspace
2. Verify the webhook URL is correct in config
3. Check container logs for authentication errors

### OpenClaw CLI Not Working

```bash
# Verify installation
openclaw --version

# Check configuration
openclaw status

# Re-authenticate if needed
openclaw auth login
```

### Cron Jobs Not Running

1. Verify cron is running: `systemctl status cron` or `docker exec <container> crond -l2 -d`
2. Check cron logs: `docker logs <container>` (look for cron output)
3. Ensure the script path exists and is executable

---

## PR Notification

When a PR is created, notify the relevant groups with PR link and change description.

---

## GitHub App

This repo uses GitHub App for authentication:
- App ID: 3002333
- Installation ID: 113867057

---

## Related Docs

- [OpenClaw Team Architecture](https://pingcap.feishu.cn/wiki/F9uIwofiki4hj7kmBqnchnjsnk6)
- [OpenClaw Documentation](https://docs.openclaw.ai)
