# Environment Configuration

Credentials and configuration for team-code-expert role.

---

## Required Environment Variables

All environment variables must be set in `~/.bashrc` or container environment. Do not hardcode values in scripts or configuration files.

### Core Variables

| Variable | Description | Required |
|----------|-------------|----------|
| `AI_CONFIG_REPO` | Path to data-service-infra-ai-configurations repo | Yes |
| `MINIMAX_API_KEY` | MiniMax API key for AI model | Yes |

### GitHub App (for code review)

| Variable | Description | Required |
|----------|-------------|----------|
| `GITHUB_APP_ID` | GitHub App ID: 3002333 | Yes |
| `GITHUB_INSTALLATION_ID` | GitHub Installation ID: 113867057 | Yes |
| `GITHUB_PRIVATE_KEY_PATH` | Path to PEM file (~/.github/data-service-code-assist.pem) | Yes |

### Feishu Bot (code-expert account)

| Variable | Description | Required |
|----------|-------------|----------|
| `FEISHU_APP_ID` | Feishu App ID for code-expert bot | Yes |
| `FEISHU_APP_SECRET` | Feishu App Secret | Yes |
| `FEISHU_CHAT_ID` | Feishu group ID for PR notifications | Yes |
| `FEISHU_BOT_OPEN_ID` | Bot Open ID for @mention (optional) | No |

---

## Config File

Create `~/.config/team-code-expert/config.env`:

```bash
# GitHub App
GITHUB_APP_ID="3002333"
GITHUB_INSTALLATION_ID="113867057"
GITHUB_PRIVATE_KEY="$HOME/.github/data-service-code-assist.pem"

# Feishu
FEISHU_APP_ID="cli_a929230e37789cd5"
FEISHU_APP_SECRET="0CEneXXjOPMY9amQfziSagchD32GnKOB"
FEISHU_CHAT_ID="oc_xxx"
FEISHU_BOT_OPEN_ID="ou_xxx"

# Optional
POLL_INTERVAL=60
```

---

## API Credentials

| Service | Account/ID | Environment Variable | File |
|---------|------------|---------------------|------|
| MiniMax | API Key | `MINIMAX_API_KEY` | - |
| GitHub | App ID: 3002333 | - | `~/.github/data-service-code-assist.pem` |
| GitHub | Installation: 113867057 | - | - |

---

## Available Private Repos

The code-expert bot can access:

- tidbcloud/data-service-infra-ai-configurations
- tidbcloud/dataflow-service
- Other tidbcloud org repos (based on GitHub App permissions)

---

## Skills

### pr-review-daemon

Automated PR monitoring and code review daemon.

**Usage:**
```bash
bash ~/github/data-service-infra-ai-configurations/skills/team-code-expert/pr-review-daemon/run.sh start
```

**Watched Repos:**
- tidbcloud/dataflow-service
- tidbcloud/data-service-infra-ai-configurations

### claude-code-dispatch

Code development via Claude Code.

### tidbcloud-github-access

GitHub access management for team members.

---

## Docker Container

| Container | Role |
|-----------|------|
| openclaw-team-code-expert | Code review and PR automation |

The container runs without port exposure - all communication via Feishu.

---

## GitHub Token Script

```bash
#!/bin/bash
APP_ID=3002333
INSTALLATION_ID=113867057
PRIVATE_KEY=~/.github/data-service-code-assist.pem

# Generate JWT
JWT=$(python3 -c "
import jwt, time
with open('$PRIVATE_KEY') as f:
    token = jwt.encode({'iat': int(time.time()), 'exp': int(time.time())+600, 'iss': '$APP_ID'}, f.read(), algorithm='RS256')
print(token)
")

# Get access token
curl -s -X POST -H "Authorization: Bearer $JWT" -H "Accept: application/vnd.github+json" \
  https://api.github.com/app/installations/$INSTALLATION_ID/access_tokens | jq -r '.token'
```
