Skip to content
Open

V1 #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
node_modules/
dist/
.git/
.github/
*.md
!package*.json
tsconfig.json
test/
scripts/
*.log
.env
.env.*
CLAUDE.md
icon.jpg
*.jpg
*.png
runtime/
.DS_Store
21 changes: 19 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
# Mission Control MVP flags
# Keep readonly true until explicit live-mode validation is complete.
GATEWAY_URL=ws://127.0.0.1:18789

# Optional path overrides when your OpenClaw/Codex data is not in the default home locations.
# OPENCLAW_HOME=/path/to/.openclaw
# CODEX_HOME=/path/to/.codex
# OPENCLAW_SUBSCRIPTION_SNAPSHOT_PATH=/path/to/subscription.json

# Security settings
READONLY_MODE=true
APPROVAL_ACTIONS_ENABLED=false
APPROVAL_ACTIONS_DRY_RUN=true
IMPORT_MUTATION_ENABLED=false
IMPORT_MUTATION_DRY_RUN=false
LOCAL_TOKEN_AUTH_REQUIRED=true
# LOCAL_API_TOKEN=<set-explicitly-for-protected-routes>
MONITOR_CONTINUOUS=false
UI_MODE=false

# UI Server (set UI_MODE=true to enable)
UI_MODE=true
UI_PORT=4310

# Monitor settings
MONITOR_CONTINUOUS=false
TASK_HEARTBEAT_ENABLED=true
TASK_HEARTBEAT_DRY_RUN=true

# Resource optimization - polling intervals (milliseconds)
# Reduce these to save CPU/network, increase for more real-time data
# sessionsList: how often to refresh sessions list (default: 10000)
# sessionStatus: how often to check session status (default: 5000)
# cron: how often to check scheduled jobs (default: 30000)
# approvals: how often to check approvals (default: 5000)
# canvas: how often to refresh canvas (default: 10000)
59 changes: 59 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 改进清单

## 修改的文件

1. **src/runtime/system-monitor.ts**
- 修复 CPU 使用率计算逻辑
- 添加 0-100% 范围限制

2. **src/ui/server.ts**
- 导入连接诊断模块
- 添加 /api/diagnostics 端点
- 在 settings section 添加诊断卡片
- 加载诊断数据

## 新增的文件

1. **src/runtime/connection-diagnostics.ts**
- 连接诊断核心模块
- 检查 6 个数据源

2. **src/runtime/gateway-health.ts**
- Gateway 健康监控
- 定期检查和重连

3. **docker-compose.vps.yml**
- VPS 专用 Docker 配置
- host 网络模式
- 优化资源限制

4. **deploy-vps.sh**
- 自动化部署脚本
- 健康检查和验证

5. **verify-improvements.sh**
- 本地验证脚本

6. **文档文件**
- DOCKER_DEPLOYMENT.md
- VPS_QUICKSTART.md
- OPTIMIZATION_SUMMARY.md
- DEPLOYMENT_CHECKLIST.md
- README.foxai.md
- CHANGES.md (本文件)

## 构建状态

✓ TypeScript 编译通过
✓ 107/108 测试通过(1 个无关测试失败)
✓ 所有新增文件已创建
✓ CPU 修复已验证
✓ API 端点已添加

## 提交到 GitHub

```bash
git add .
git commit -m "优化: 修复 CPU 负数,添加连接诊断,优化 VPS 部署"
git push origin foxai
```
89 changes: 89 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Quick Start

```bash
npm install
cp .env.example .env
npm run build
npm test
npm run smoke:ui
UI_MODE=true npm run dev
```

Then open `http://127.0.0.1:4310/?section=overview`.

## Common Commands

- `npm run dev` - Run the control center in development mode
- `npm run dev:continuous` - Run with continuous monitoring enabled
- `npm run dev:ui` - Run with UI server only
- `npm run build` - Compile TypeScript
- `npm test` - Run all tests
- `npm run smoke:ui` - Run UI smoke tests

### Running Single Tests

```bash
node --import tsx --test test/filename.test.ts
```

### Command-Line Commands

Set `APP_COMMAND` environment variable to run specific commands:

- `APP_COMMAND=backup-export npm run dev` - Export system snapshot
- `APP_COMMAND=import-validate COMMAND_ARG=<file.json> npm run dev` - Validate import file
- `APP_COMMAND=acks-prune npm run dev` - Prune stale acknowledgments
- `APP_COMMAND=task-heartbeat npm run dev` - Run task heartbeat check

### Validation Scripts

- `npm run validate:task-store` - Validate task store integrity
- `npm run validate:budget` - Validate budget configuration

## Architecture

This is a safety-first local control center for OpenClaw observability, task operations, and operator review.

### Key Layers

1. **Clients** (`src/clients/`) - Communicate with OpenClaw Gateway via WebSocket
- `openclaw-live-client.ts` - Main client for live data from OpenClaw
- `factory.ts` - Client factory

2. **Adapters** (`src/adapters/`) - Transform external data into internal models
- `openclaw-readonly.ts` - Read-only adapter wrapping the client

3. **Runtime** (`src/runtime/`) - Core business logic
- `commander.ts` - Main orchestrator for exception handling
- `budget-governance.ts` - Budget monitoring and alerts
- `task-store.ts` / `project-store.ts` - State management
- `usage-cost.ts` - Token usage tracking
- `notification-center.ts` - Alert/acknowledgment system

4. **UI** (`src/ui/server.ts`) - Express-based UI server on port 4310

### Data Flow

The system reads from OpenClaw Gateway (WebSocket) and produces:
- **ReadModelSnapshot** - Aggregated state (sessions, tasks, budgets, approvals)
- **CommanderExceptionsFeed** - Alert feed for blocked/error states
- **NotificationCenterSnapshot** - Acknowledged alerts

### Safety Features (Default Enabled)

- `READONLY_MODE=true` - No write operations by default
- `LOCAL_TOKEN_AUTH_REQUIRED=true` - Token required for protected commands
- `APPROVAL_ACTIONS_ENABLED=false` - Approval actions disabled by default
- All mutation commands default to dry-run mode

### Environment Variables

Key config in `src/config.ts`:
- `GATEWAY_URL` - OpenClaw WebSocket endpoint (default: `ws://127.0.0.1:18789`)
- `UI_PORT` - UI server port (default: 4310)
- `LOCAL_API_TOKEN` - Token for protected operations
- `READONLY_MODE`, `APPROVAL_ACTIONS_ENABLED`, `IMPORT_MUTATION_ENABLED` - Safety gates
83 changes: 83 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Docker Deployment Guide

## Quick Start

### 1. Build and Run

```bash
# Development mode
docker-compose up -d

# Production mode (with stricter resource limits)
docker-compose -f docker-compose.prod.yml up -d
```

### 2. Access the Application

Open browser: http://localhost:4310

## Resource Optimization

### Default Configuration (Recommended for 512MB+ RAM)

- Memory limit: 256MB
- CPU limit: 0.5 cores
- Polling intervals: 10-30 seconds

### Production Configuration (For 256MB RAM or less)

Use `docker-compose.prod.yml`:
- Memory limit: 128MB
- CPU limit: 0.25 cores
- Polling intervals: 10-60 seconds
- Task heartbeat: Disabled

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| UI_MODE | true | Enable UI server |
| UI_PORT | 4310 | UI server port |
| GATEWAY_URL | ws://127.0.0.1:18789 | OpenClaw WebSocket |
| READONLY_MODE | true | Read-only mode |
| LOCAL_TOKEN_AUTH_REQUIRED | true | Require token |
| MONITOR_CONTINUOUS | false | Continuous monitoring |

## Common Commands

```bash
# View logs
docker-compose logs -f

# Stop
docker-compose down

# Rebuild
docker-compose build --no-cache

# Restart
docker-compose restart
```

## Troubleshooting

### Out of Memory

Use production config:
```bash
docker-compose -f docker-compose.prod.yml up -d
```

### High CPU Usage

Increase polling intervals in environment:
```bash
POLLING_INTERVALS_MS=sessionsList=60000,cron=120000 docker-compose up -d
```

### Health Check Failed

Check if port 4310 is available:
```bash
netstat -tulpn | grep 4310
```
Loading