Metadata-Version: 2.1
Name: governance-mesh
Version: 0.1.0
Summary: Governance Mesh — 开源项目 AI 自治治理系统，基于 Genome Core 三省六部制 · DNA 声望 · 自动进化 · 路线图规划
Author-email: AtomGit <noreply@atomgit.com>
License: MIT
Project-URL: Homepage, https://atomgit.com/autonomous-tools/governance-mesh
Project-URL: Documentation, https://atomgit.com/autonomous-tools/governance-mesh/docs
Project-URL: Source, https://atomgit.com/autonomous-tools/governance-mesh
Project-URL: Bug Tracker, https://atomgit.com/autonomous-tools/governance-mesh/issues
Project-URL: Changelog, https://atomgit.com/autonomous-tools/blob/main/governance-mesh/CHANGELOG.md
Keywords: governance,opensource,ai,自治治理,六部,reputation,roadmap,automation,open-source-governance,project-management,ci-cd,开源治理,项目管理
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Version Control
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: System :: Monitoring
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Provides-Extra: all
Requires-Dist: governance-mesh[core]; extra == "all"
Provides-Extra: core
Requires-Dist: genome-core>=0.1.0; extra == "core"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"

# Governance Mesh

**开源项目 AI 自治治理系统** — 基于 Genome Core 的三省六部制 · DNA 声望 · 自动进化

---

## 概述

Governance Mesh（治理网格）是一个面向开源项目的 AI 自治治理框架。它继承自 [Genome Core](https://atomgit.com/genome-core) 的三省六部制思想，将古代中国成熟的官僚体系设计转化为现代开源项目的自动化治理引擎。

### 核心思想

| 三省 | 职责 | 对应治理层 |
|------|------|-----------|
| **中书省** | 起草方案 / PR | 提案生成 |
| **门下省** | 审核 / 审批 | PR 审核流水线 |
| **尚书省** | 执行 / 发布 | 发布管理 |

| 六部 | 职责 | 治理模块 |
|------|------|---------|
| **吏部** | 贡献者管理 | 加入/退出/角色分配 |
| **户部** | Issue 管理 | 分类/优先级/分配 |
| **礼部** | PR 审核 | 格式检查/CLA/社区规范 |
| **兵部** | CI/CD 监控 | 流水线触发与监控 |
| **刑部** | 违规处理 | 警告/封禁/回滚 |
| **工部** | 发布管理 | changelog/版本号/构建 |

---

## 安装

```bash
# 基础安装
pip install governance-mesh

# 集成 Genome Core（推荐）
pip install governance-mesh[core]
```

## 快速开始

### 1. 初始化

```bash
governance-mesh init --project my-project --repo my-org/my-repo
```

这会创建数据目录和配置文件，六部全部就绪。

### 2. 运行审核流水线

```bash
# 执行一轮完整的治理周期
governance-mesh review

# 执行多轮
governance-mesh review --cycles 3
```

每轮周期自动执行：
1. 收集开放 Issue → 按热度/优先级排序
2. 自动创建 PR（针对高优先级 Issue）
3. 运行审核流水线（格式检查 + CLA + 社区规范 + CI）
4. 合并已批准的 PR
5. 更新贡献者声望
6. 规划路线图
7. 准备版本发布
8. 触发 Genome Core 进化周期（如果已集成）

### 3. 发布

```bash
# 准备发布（自动检测版本类型）
governance-mesh release

# 指定版本类型
governance-mesh release --bump minor

# 试运行（不实际执行）
governance-mesh release --dry-run
```

### 4. 查看状态

```bash
# 查看完整状态
governance-mesh status

# 以 JSON 格式输出
governance-mesh status --json
```

---

## 架构

```
┌─────────────────────────────────────────────────┐
│                 Governance Mesh                  │
│  ┌───────────────────────────────────────────┐  │
│  │              主引擎 (mesh.py)              │  │
│  │  Issue → PR → Merge → Release 全流程      │  │
│  └───────────┬───────────┬───────────────────┘  │
│              │           │                       │
│  ┌───────────▼──┐  ┌────▼────────────────┐      │
│  │  六部执行层   │  │  子系统              │      │
│  │  six_ministries│  │  reputation        │      │
│  │  吏/户/礼/兵/刑/工│  │  roadmap          │      │
│  │              │  │  publisher          │      │
│  └──────────────┘  └────────────────────┘      │
│                                               │
│  ┌───────────────────────────────────────────┐ │
│  │        Genome Core 集成（可选）            │ │
│  │  governance.py 三省六部制 + evolve.py 进化  │ │
│  └───────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
```

### 声望系统（DNA 积分）

每次贡献行为都会影响贡献者的 DNA 声望值：

| 行为 | 声望增益 | 说明 |
|------|---------|------|
| PR 合并 | +30（带衰减） | 防止刷分 |
| Issue 关闭 | +15 | 问题解决 |
| 代码审查 | +20 × 质量分 | 质量越高越多 |
| 社区投票 | +5 | 获得社区认可 |
| 违规处罚 | -50 ~ -100 | 视严重程度 |

声望等级：**S 核心领袖** (800+) > **A 高级贡献者** (500+) > **B 中级** (300+) > **C 初级** (150+) > **D 新手**

### 路线图自动规划

按以下策略自动生成项目路线图：
1. **热度排序** — heat 值最高的 Issue 优先
2. **标签归类** — 自动归入"新功能"/"改进优化"/"紧急修复"等里程碑
3. **时间线生成** — 每两周一个里程碑
4. **优先级加权** — P0 > P1 > P2 > P3

---

## 编程接口

```python
from governance_mesh import create_mesh, GovernanceMesh

# 创建网格
mesh = create_mesh(
    project_name="my-project",
    data_dir="data",
    github_repo="my-org/my-repo",
)

# 运行治理周期
result = mesh.run_cycle()
print(f"PR 合并: {result['prs_merged']}")

# 查看状态
status = mesh.get_status()
print(f"贡献者: {status['contributors']['total']}")

# 声望排行榜
leaderboard = mesh.get_leaderboard(top_n=10)
```

### 直接使用六部

```python
from governance_mesh.six_ministries import (
    MinistryOfPersonnel,
    MinistryOfRevenue,
    MinistryOfRites,
    IssuePriority,
)

# 吏部：贡献者管理
personnel = MinistryOfPersonnel("data/contributors.json")
personnel.join("alice", "alice@example.com")
personnel.set_role("alice", ContributorRole.MAINTAINER)

# 户部：Issue 管理
revenue = MinistryOfRevenue("data/issues.json")
issue = revenue.create_issue("Bug: login fails", "...", "bob")
revenue.set_priority(issue["id"], IssuePriority.P0_CRITICAL)
revenue.assign(issue["id"], "alice")
```

### 声望系统

```python
from governance_mesh.reputation import ReputationSystem

rep = ReputationSystem("data/reputation.json")

# 记录贡献
rep.on_pr_merged("alice", "Fix login bug")
rep.on_issue_closed("bob", "Add documentation")
rep.on_review_given("charlie", "PR #42", quality_score=0.95)

# 查看排行榜
for entry in rep.get_leaderboard(5):
    print(f"{entry['username']}: {entry['reputation']}pts ({entry['tier_name']})")
```

### 路线图规划

```python
from governance_mesh.roadmap import RoadmapPlanner

planner = RoadmapPlanner("data/roadmap.json")
issues = [
    {"title": "Add dark mode", "labels": ["feature"], "heat": 80, "votes": 15, "priority": "P1"},
    {"title": "Fix crash on startup", "labels": ["bug", "critical"], "heat": 95, "votes": 30, "priority": "P0"},
]
roadmap = planner.auto_plan_and_save(issues, "my-project")
for m in roadmap.milestones:
    print(f"{m['name']} — target: {m['target_date']}")
```

### 自动发布

```python
from governance_mesh.publisher import Publisher, SemVerBumper

bumper = SemVerBumper()
print(bumper.bump("1.2.3", "minor"))  # 1.3.0
print(bumper.bump("1.2.3", "major"))  # 2.0.0

publisher = Publisher("data/")
merged_prs = [{"id": "PR-001", "title": "Add feature", "status": "merged", "author": "alice"}]
release = publisher.prepare_release(merged_prs, "auto")
print(f"New version: {release['version']}")
```

---

## 与 Genome Core 的集成

Governance Mesh 在安装 `genome-core` 后将自动集成：

- **governance.py** — 三省六部制审计日志（`audit_log`、`check_accountability`）
- **evolve.py** — 每轮治理周期后自动触发 DNA 进化（`start_evolution_cycle`）

无需额外配置，安装后自动生效。

```bash
pip install governance-mesh[core]
```

---

## 项目结构

```
governance-mesh/
├── pyproject.toml              # 包配置
├── README.md                   # 本文档
└── governance_mesh/
    ├── __init__.py             # 包入口，导出所有模块
    ├── mesh.py                 # 主引擎（Issue→PR→Merge全流程）
    ├── six_ministries.py       # 三省六部制实现
    ├── reputation.py           # 贡献者声望系统（DNA积分）
    ├── roadmap.py              # 路线图自动规划
    ├── publisher.py            # 自动发布（changelog/版本号/Release）
    └── cli.py                  # 命令行入口（init/review/release/status）
```

---

## 许可证

MIT
