Skill: chen-feng123/health-reasoner (version 1.0.1)

--- name: health-reasoner description: "Health Reasoner — 日常习惯健康小工具。基于生活习惯（睡眠/饮食/运动/压力/烟酒）输出评分与改善建议。纯规则驱动，纯 Python 标准库。不提供医疗诊断。" --- # Health Reasoner (日常习惯健康小工具) 纯规则驱动的日常习惯评分工具。**零外部依赖**。**非医疗用途**。 ## Quick Start ```python from health_reasoner import HealthReasoner hr = HealthReasoner() result = hr.assess({ "age": 28, "gender": "male", "sleep_hours": 6.5, "sleep_quality": "fair", "diet_type": "high_fat", "exercise_frequency": "weekly", "stress_level": "high", }) print(result.score) print(result.suggestions) ``` ## 特性 - **零外部依赖** — 纯 Python 标准库 - **历史记录可选** — 不传 `--history` 不留痕 - **规则透明** — 每条建议可溯源

path: API_SPEC.md
content: # Health Reasoner API 规范

## 核心类：`HealthReasoner`

### `assess(data: dict) -> HealthAssessment`

输入格式（`UserHealthProfile` JSON）：

```json
{
  "age": 28,
  "gender": "male",
  "sleep_hours": 6.5,
  "sleep_quality": "fair",
  "diet_type": "balanced",
  "exercise_frequency": "weekly",
  "stress_level": "moderate",
  "smoking_status": "never",
  "alcohol_use": "light",
  "symptoms": ["偶尔头痛"],
  "medical_history": []
}
```

**字段校验规则：**

| 字段 | 类型 | 允许值 |
|------|------|--------|
| age | int | 0-120 |
| gender | str | male, female |
| sleep_hours | float | 0.0-24.0 |
| sleep_quality | str | good, fair, poor |
| diet_type | str | balanced, high_fat, high_sugar, high_salt, vegetarian |
| exercise_frequency | str | daily, weekly, rarely, sedentary |
| stress_level | str | low, moderate, high |
| smoking_status | str | never, past, current |
| alcohol_use | str | none, light, moderate, heavy |
| symptoms | list[str] | 可选 |
| medical_history | list[str] | 可选 |

### 输出：`HealthAssessment`

```json
{
  "score": 68,
  "risk_level": "medium",
  "suggestions": [
    {"priority": 1, "category": "sleep", "rule_id": "SLEEP-001", "message": "建议将睡眠延长至7-8小时"},
    {"priority": 2, "category": "stress", "rule_id": "STRESS-002", "message": "每天安排15分钟深呼吸练习"}
  ],
  "risk_factors": ["睡眠不足", "高压力"],
  "details": {
    "sleep_score": 60,
    "diet_score": 75,
    "exercise_score": 50,
    "stress_score": 40,
    "substance_score": 85
  }
}
```

**错误码：**

| 错误 | HTTP 等效 | 说明 |
|------|-----------|------|
| ValueError | 400 | 输入校验失败 |
| TypeError | 400 | 字段类型错误 |
| 其他异常 | 500 | 内部错误 |

## 额外函数

### `batch_assess(profiles: List[dict]) -> List[HealthAssessment]`

批量评估多个健康档案。每个元素与 `assess()` 输入格式相同。`assess()` 的调用者负责错误处理。

### `trend_analysis(history: List[dict]) -> TrendReport`

从历史 `UserHealthProfile` 列表（按日期排序）生成趋势分析报告：

```json
{
  "score_trend": "stable",
  "sleep_trend": "improving",
  "changes": [
    {"field": "sleep_hours", "change": "+0.5", "duration": "7d"}
  ]
}
```


path: README.md
content: # Health Reasoner 🫀

日常状态健康推理引擎。输入你的睡眠、饮食、运动、压力等数据，输出综合健康评分、风险评估和个性化改善建议。**纯 Python 标准库，零外部依赖。**

## 特性

- **隐私安全** — 所有数据本地处理，不上传云端
- **可解释** — 每条建议都有规则 ID，知道为什么
- **结构化输出** — JSON 格式，可直接用于其他系统
- **趋势追踪** — 连续输入查看健康变化趋势
- **无依赖** — 核心推理模块 `pip install` 都不需要

## 快速开始

```bash
git clone https://github.com/你的用户名/health-reasoner.git
cd health-reasoner

# 交互模式
python health_reasoner.py --cli

# JSON 输入模式
python health_reasoner.py --input '{"age":28,"sleep_hours":6.5,"sleep_quality":"fair","diet_type":"high_fat","exercise_frequency":"weekly","stress_level":"high"}'

# 自检
python health_reasoner.py --test

# API 服务（需要 Flask）
python health_reasoner.py --api
```

## 示例输出

```json
{
  "score": 62,
  "risk_level": "medium",
  "suggestions": [
    {"priority": 1, "category": "sleep", "rule_id": "SLEEP-001", "message": "建议将睡眠延长至7-8小时，有助于降低心血管疾病风险"},
    {"priority": 2, "category": "diet", "rule_id": "DIET-003", "message": "减少高脂食物摄入，增加蔬菜水果比例"}
  ],
  "risk_factors": ["睡眠不足", "高脂饮食"],
  "details": {
    "sleep_score": 55,
    "diet_score": 40,
    "exercise_score": 60,
    "stress_score": 50,
    "substance_score": 100
  }
}
```

## 文档

- [SKILL.md](SKILL.md) — ClawHub 技能说明
- [API_SPEC.md](API_SPEC.md) — API 规范与错误码
- [USE_GUIDE.md](USE_GUIDE.md) — 详细使用指南
- [DESIGN.md](references/DESIGN.md) — 设计文档

## 项目文件结构

```
health-reasoner/
├── health_reasoner.py      ← 核心引擎 (~23KB)
├── SKILL.md                ← ClawHub 技能描述
├── API_SPEC.md             ← API 规范
├── USE_GUIDE.md            ← 使用指南
├── LICENSE                 ← MIT 许可证
├── README.md               ← 本文件
├── references/
│   └── DESIGN.md           ← 设计文档
└── scripts/
    ├── setup.sh            ← Linux/macOS 安装脚本
    └── setup.bat           ← Windows 安装脚本
```

## License

MIT


path: USE_GUIDE.md
content: # Health Reasoner 使用指南

## 安装

```bash
# 克隆仓库
git clone https://github.com/你的用户名/health-reasoner.git
cd health-reasoner

# 无需安装依赖（纯标准库）
```

或者直接复制 `health_reasoner.py` 到你的项目目录。

## 基础使用

### CLI 模式

```bash
python health_reasoner.py --cli
```

按提示逐项输入数据。

### JSON 输入模式

```bash
python health_reasoner.py --input data.json --format json
```

### Python 导入

```python
from health_reasoner import HealthReasoner

hr = HealthReasoner()

result = hr.assess({
    "age": 35,
    "gender": "female",
    "sleep_hours": 7.5,
    "sleep_quality": "good",
    "diet_type": "balanced",
    "exercise_frequency": "daily",
    "stress_level": "low",
})
print(f"评分: {result.score}/100")
print(f"风险: {result.risk_level}")
for s in result.suggestions:
    print(f"[{s['priority']}] {s['category']}: {s['message']}")

# 批量评估
results = hr.batch_assess([profile1, profile2])

# 趋势分析（需要传入历史记录或指定 --history 文件）
trend = hr.trend_analysis(history_7days)
```

## 注意事项

- ⚠️ **本工具不提供医疗诊断或治疗建议**，健康问题请咨询专业医师
- 历史记录为**可选功能**：不传 `--history` 参数则不留存任何数据
- 所有数据本地处理，不自动上传云端
- 评分规则基于通用生活习惯指南，仅供参考


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (MEDIUM)