mirror of
https://mirror.skon.top/github.com/cft0808/edict
synced 2026-04-20 21:00:16 +08:00
feat: killer README hooks, Demo GIF, ROADMAP.md, examples/ with 3 use cases
- Rewrite README/README_EN opening with cognitive conflict hook - Add 门下省 review mechanism callout (collapsible) - Record 30s Demo GIF (800px, 4.6MB) via Playwright - Create standalone ROADMAP.md with Phase 1/2/3 structure - Add examples/: competitive analysis, code review, weekly report - Add Star History chart - Restructure inline Roadmap into phases - Add examples reference section in both READMEs
This commit is contained in:
1154
.github/ISSUE_TEMPLATE/三省六部-功能需求文档PRD.md
vendored
1154
.github/ISSUE_TEMPLATE/三省六部-功能需求文档PRD.md
vendored
File diff suppressed because it is too large
Load Diff
84
README.md
84
README.md
@@ -1,20 +1,19 @@
|
||||
<p align="center">
|
||||
<img src="docs/screenshots/01-kanban-main.png" alt="三省六部 · 军机处看板" width="100%">
|
||||
</p>
|
||||
|
||||
<h1 align="center">⚔️ 三省六部 · Edict</h1>
|
||||
|
||||
<p align="center">
|
||||
<strong>当 AI 学会了中国古代的治国术</strong><br>
|
||||
<sub>9 个 AI Agent 组成三省六部,像治理帝国一样管理你的复杂任务</sub>
|
||||
<strong>我用 1300 年前的帝国制度,重新设计了 AI 多 Agent 协作架构。<br>结果发现,古人比现代 AI 框架更懂分权制衡。</strong>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<sub>9 个 AI Agent 组成三省六部:中书省规划、门下省审核封驳、尚书省派发、六部并行执行。<br>比 CrewAI 多一层<b>制度性审核</b>,比 AutoGen 多一个<b>实时看板</b>。</sub>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="#-demo">🎬 看 Demo</a> ·
|
||||
<a href="#-30-秒快速体验">🚀 30 秒体验</a> ·
|
||||
<a href="#-架构">🏛️ 架构</a> ·
|
||||
<a href="#-功能全景">📋 看板功能</a> ·
|
||||
<a href="README_EN.md">English</a> ·
|
||||
<a href="#-30-秒快速体验">快速开始</a> ·
|
||||
<a href="#-架构">架构</a> ·
|
||||
<a href="#-功能全景">看板功能</a> ·
|
||||
<a href="docs/getting-started.md">详细指南</a> ·
|
||||
<a href="CONTRIBUTING.md">参与贡献</a>
|
||||
</p>
|
||||
|
||||
@@ -29,11 +28,15 @@
|
||||
|
||||
---
|
||||
|
||||
## 💡 一句话定义
|
||||
## 🎬 Demo
|
||||
|
||||
> **三省六部** 是第一个将古代帝国治理智慧应用于 AI 多 Agent 协同的开源系统。
|
||||
> 你下一道旨,中书省规划、门下省审议、尚书省派发、六部并行执行,最后汇总回奏。
|
||||
> 附带一个开箱即用的**军机处看板**,让所有流转一目了然。
|
||||
<p align="center">
|
||||
<img src="docs/demo.gif" alt="三省六部 Demo" width="100%">
|
||||
<br>
|
||||
<sub>飞书下旨 → 中书省规划 → 门下省审议 → 六部并行执行 → 奏折回报(30 秒)</sub>
|
||||
</p>
|
||||
|
||||
> 🐳 **没有 OpenClaw?** 跑一行 `docker run -p 7891:7891 cft0808/edict` 即可体验完整看板 Demo(预置模拟数据)。
|
||||
|
||||
---
|
||||
|
||||
@@ -66,7 +69,25 @@
|
||||
| **部署难度** | 中 | 高 | 中 | **低 · 一键安装 / Docker** |
|
||||
|
||||
> **核心差异:制度性审核 + 完全可观测 + 实时可干预**
|
||||
> 让 AI 协作像治国一样,有规矩、有审计、有制衡。
|
||||
|
||||
<details>
|
||||
<summary><b>🔍 为什么「门下省审核」是杀手锏?(点击展开)</b></summary>
|
||||
|
||||
<br>
|
||||
|
||||
CrewAI 和 AutoGen 的 Agent 协作模式是 **"做完就交"**——没有人检查产出质量。就像一个公司没有 QA 部门,工程师写完代码直接上线。
|
||||
|
||||
三省六部的 **门下省** 专门干这件事:
|
||||
|
||||
- 📋 **审查方案质量** —— 中书省的规划是否完备?子任务拆解是否合理?
|
||||
- 🚫 **封驳不合格的产出** —— 不是 warning,是直接打回重做
|
||||
- 🔄 **强制返工循环** —— 直到方案达标才放行
|
||||
|
||||
这不是可选的插件——**它是架构的一部分**。每一个旨意都必须经过门下省,没有例外。
|
||||
|
||||
这就是为什么三省六部能处理复杂任务而结果可靠:因为在送到执行层之前,有一个强制的质量关卡。1300 年前唐太宗就想明白了——**不受制约的权力必然会出错**。
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
|
||||
@@ -397,6 +418,9 @@ edict/
|
||||
|
||||
## 🗺️ Roadmap
|
||||
|
||||
> 完整路线图及参与方式:[ROADMAP.md](ROADMAP.md)
|
||||
|
||||
### Phase 1 — 核心架构 ✅
|
||||
- [x] 九部制 Agent 架构 + 权限矩阵
|
||||
- [x] 军机处实时看板(10 个功能面板)
|
||||
- [x] 任务叫停 / 取消 / 恢复
|
||||
@@ -407,13 +431,19 @@ edict/
|
||||
- [x] 模型热切换 + 技能管理 + 技能添加
|
||||
- [x] 官员总览 + Token 消耗统计
|
||||
- [x] 小任务 / 会话监控
|
||||
- [ ] 功过簿(Agent 绩效评分体系)
|
||||
|
||||
### Phase 2 — 制度深化 🚧
|
||||
- [ ] 御批模式(人工审批 + 一键准奏/封驳)
|
||||
- [ ] 国史馆(知识库检索 + 引用溯源)
|
||||
- [ ] 功过簿(Agent 绩效评分体系)
|
||||
- [ ] 急递铺(Agent 间实时消息流可视化)
|
||||
- [ ] 国史馆(知识库检索 + 引用溯源)
|
||||
|
||||
### Phase 3 — 生态扩展
|
||||
- [ ] Docker Compose + Demo 镜像
|
||||
- [ ] Notion / Linear 适配器
|
||||
- [ ] 年度大考(Agent 年度绩效报告)
|
||||
- [ ] Docker Compose 一键部署
|
||||
- [ ] 移动端适配
|
||||
- [ ] 移动端适配 + PWA
|
||||
- [ ] ClawHub 上架
|
||||
|
||||
---
|
||||
|
||||
@@ -431,12 +461,28 @@ edict/
|
||||
|
||||
---
|
||||
|
||||
## 📂 案例
|
||||
|
||||
`examples/` 目录收录了真实的端到端使用案例:
|
||||
|
||||
| 案例 | 旨意 | 涉及部门 |
|
||||
|------|------|----------|
|
||||
| [竞品分析](examples/competitive-analysis.md) | "分析 CrewAI vs AutoGen vs LangGraph" | 中书→门下→户部+兵部+礼部 |
|
||||
| [代码审查](examples/code-review.md) | "审查这段 FastAPI 代码的安全性" | 中书→门下→兵部+刑部 |
|
||||
| [周报生成](examples/weekly-report.md) | "生成本周工程团队周报" | 中书→门下→户部+礼部 |
|
||||
|
||||
每个案例包含:完整旨意 → 中书省规划 → 门下省审核意见 → 各部执行结果 → 最终奏折。
|
||||
|
||||
---
|
||||
|
||||
## ⭐ Star History
|
||||
|
||||
如果这个项目让你会心一笑,请给个 Star ⚔️
|
||||
|
||||
[](https://star-history.com/#cft0808/edict&Date)
|
||||
|
||||
[](https://star-history.com/#cft0808/edict&Date)
|
||||
|
||||
---
|
||||
|
||||
## 📄 License
|
||||
|
||||
89
README_EN.md
89
README_EN.md
@@ -1,19 +1,19 @@
|
||||
<p align="center">
|
||||
<img src="docs/screenshots/01-kanban-main.png" alt="Edict Dashboard" width="100%">
|
||||
</p>
|
||||
|
||||
<h1 align="center">⚔️ Edict · Multi-Agent Orchestration</h1>
|
||||
|
||||
<p align="center">
|
||||
<strong>What if AI learned statecraft from ancient China?</strong><br>
|
||||
<sub>9 specialized AI Agents form a government — plan, review, dispatch, execute, report.</sub>
|
||||
<strong>I modeled an AI multi-agent system after China's 1,300-year-old imperial governance.<br>Turns out, ancient bureaucracy understood separation of powers better than modern AI frameworks.</strong>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<sub>9 AI agents form the Three Departments & Six Ministries: Planning proposes, Review vetoes, Dispatch assigns, Ministries execute.<br>Built-in <b>institutional review gates</b> that CrewAI doesn't have. A <b>real-time dashboard</b> that AutoGen doesn't have.</sub>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="#-demo">🎬 Demo</a> ·
|
||||
<a href="#-quick-start">🚀 Quick Start</a> ·
|
||||
<a href="#-architecture">🏛️ Architecture</a> ·
|
||||
<a href="#-features">📋 Features</a> ·
|
||||
<a href="README.md">中文</a> ·
|
||||
<a href="#-quick-start">Quick Start</a> ·
|
||||
<a href="#-architecture">Architecture</a> ·
|
||||
<a href="#-features">Dashboard</a> ·
|
||||
<a href="CONTRIBUTING.md">Contributing</a>
|
||||
</p>
|
||||
|
||||
@@ -28,6 +28,18 @@
|
||||
|
||||
---
|
||||
|
||||
## 🎬 Demo
|
||||
|
||||
<p align="center">
|
||||
<img src="docs/demo.gif" alt="Edict Demo" width="100%">
|
||||
<br>
|
||||
<sub>Issue command → Planning proposes → Review audits → Ministries execute → Report back (30s)</sub>
|
||||
</p>
|
||||
|
||||
> 🐳 **No OpenClaw?** Run `docker run -p 7891:7891 cft0808/edict` to try the full dashboard with simulated data.
|
||||
|
||||
---
|
||||
|
||||
## 💡 The Idea
|
||||
|
||||
Most multi-agent frameworks let AI agents talk freely, producing opaque results you can't audit or intervene in. **Edict** takes a radically different approach — borrowing the governance system that ran China for 1,400 years:
|
||||
@@ -63,6 +75,27 @@ This isn't a cute metaphor. It's **real separation of powers** for AI:
|
||||
| **News aggregation** | ❌ | ❌ | ❌ | **✅ Daily digest + webhook** |
|
||||
| **Setup complexity** | Med | High | Med | **Low · One-click / Docker** |
|
||||
|
||||
> **Core differentiator: Institutional review + Full observability + Real-time intervention**
|
||||
|
||||
<details>
|
||||
<summary><b>🔍 Why the "Review Department" is the killer feature (click to expand)</b></summary>
|
||||
|
||||
<br>
|
||||
|
||||
CrewAI and AutoGen agents work in a **"done, ship it"** mode — no one checks output quality. It's like a company with no QA department where engineers push code straight to production.
|
||||
|
||||
Edict's **Review Department (门下省)** exists specifically for this:
|
||||
|
||||
- 📋 **Audit plan quality** — Is the Planning Department's decomposition complete and sound?
|
||||
- 🚫 **Veto subpar output** — Not a warning. A hard reject that forces re-planning.
|
||||
- 🔄 **Mandatory rework loop** — Nothing passes until it meets standards.
|
||||
|
||||
This isn't an optional plugin — **it's part of the architecture**. Every command must pass through Review. No exceptions.
|
||||
|
||||
This is why Edict produces reliable results on complex tasks: there's a mandatory quality gate before anything reaches execution. Emperor Taizong figured this out 1,300 years ago — **unchecked power inevitably produces errors**.
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
|
||||
## ✨ Features
|
||||
@@ -268,6 +301,9 @@ edict/
|
||||
|
||||
## 🗺️ Roadmap
|
||||
|
||||
> Full roadmap with contribution opportunities: [ROADMAP.md](ROADMAP.md)
|
||||
|
||||
### Phase 1 — Core Architecture ✅
|
||||
- [x] Nine-department agent architecture + permissions
|
||||
- [x] Real-time dashboard (10 panels)
|
||||
- [x] Task stop / cancel / resume
|
||||
@@ -278,13 +314,19 @@ edict/
|
||||
- [x] Hot-swap LLM models + skill management
|
||||
- [x] Officials overview + token stats
|
||||
- [x] Session monitoring
|
||||
- [ ] Merit/demerit ledger (agent scoring)
|
||||
|
||||
### Phase 2 — Institutional Depth 🚧
|
||||
- [ ] Imperial approval mode (human-in-the-loop)
|
||||
- [ ] Imperial Archives (knowledge base)
|
||||
- [ ] Express courier (inter-agent message viz)
|
||||
- [ ] Annual review (yearly reports)
|
||||
- [ ] Docker Compose deployment
|
||||
- [ ] Mobile responsive
|
||||
- [ ] Merit/demerit ledger (agent scoring)
|
||||
- [ ] Express courier (inter-agent message visualization)
|
||||
- [ ] Imperial Archives (knowledge base + citation)
|
||||
|
||||
### Phase 3 — Ecosystem
|
||||
- [ ] Docker Compose + demo image
|
||||
- [ ] Notion / Linear adapters
|
||||
- [ ] Annual review (yearly performance reports)
|
||||
- [ ] Mobile responsive + PWA
|
||||
- [ ] ClawHub marketplace listing
|
||||
|
||||
---
|
||||
|
||||
@@ -301,6 +343,20 @@ All contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
|
||||
---
|
||||
|
||||
## <20> Examples
|
||||
|
||||
The `examples/` directory contains real end-to-end use cases:
|
||||
|
||||
| Example | Command | Departments |
|
||||
|---------|---------|-------------|
|
||||
| [Competitive Analysis](examples/competitive-analysis.md) | "Analyze CrewAI vs AutoGen vs LangGraph" | Planning→Review→Finance+Engineering+Docs |
|
||||
| [Code Review](examples/code-review.md) | "Review this FastAPI code for security issues" | Planning→Review→Engineering+Compliance |
|
||||
| [Weekly Report](examples/weekly-report.md) | "Generate this week's engineering team report" | Planning→Review→Finance+Docs |
|
||||
|
||||
Each case includes: Full command → Planning proposal → Review feedback → Ministry outputs → Final report.
|
||||
|
||||
---
|
||||
|
||||
## 📄 License
|
||||
|
||||
[MIT](LICENSE) · Built by the [OpenClaw](https://openclaw.ai) community
|
||||
@@ -308,6 +364,9 @@ All contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
---
|
||||
|
||||
<p align="center">
|
||||
<sub>If this project made you smile, give it a ⭐</sub><br><br>
|
||||
<strong>⚔️ Governing AI with the wisdom of ancient empires</strong><br>
|
||||
<sub>以古制御新技,以智慧驾驭 AI</sub>
|
||||
</p>
|
||||
|
||||
[](https://star-history.com/#cft0808/edict&Date)
|
||||
|
||||
99
ROADMAP.md
Normal file
99
ROADMAP.md
Normal file
@@ -0,0 +1,99 @@
|
||||
# 🗺️ 三省六部 · Roadmap
|
||||
|
||||
> 这份路线图是公开的。欢迎认领未完成的项目,提 PR 参与建设。
|
||||
>
|
||||
> 认领方式:在对应 Issue 下回复 "I'll take this",或直接提 PR 并在描述中注明。
|
||||
|
||||
---
|
||||
|
||||
## Phase 1 — 核心架构 ✅
|
||||
|
||||
> 三省六部的骨架:九部制 + 实时看板 + 完整工作流。
|
||||
|
||||
- [x] 九部制 Agent 架构(中书·门下·尚书 + 户礼兵刑工 + 早朝官)
|
||||
- [x] 严格权限矩阵 —— 谁能给谁发消息,白纸黑字
|
||||
- [x] 军机处实时看板(10 个功能面板)
|
||||
- [x] 任务全生命周期管理(创建 → 规划 → 审议 → 派发 → 执行 → 回奏)
|
||||
- [x] 任务叫停 / 取消 / 恢复
|
||||
- [x] 奏折系统(已完成旨意自动归档 + 五阶段时间线)
|
||||
- [x] 圣旨模板库(9 个预设模板 + 参数表单 + 预估时间/费用)
|
||||
- [x] 上朝仪式感(每日首次打开播放开场动画 + 今日统计)
|
||||
- [x] 天下要闻(每日自动采集科技/财经资讯 + 飞书推送 + 订阅管理)
|
||||
- [x] 模型热切换(看板内一键切换每个 Agent 的 LLM)
|
||||
- [x] 技能管理(查看各省部已装 Skills + 添加新技能)
|
||||
- [x] 官员总览(Token 消耗排行 + 活跃度 + 完成数统计)
|
||||
- [x] 小任务 / 会话监控(OC-* 会话实时跟踪)
|
||||
|
||||
---
|
||||
|
||||
## Phase 2 — 制度深化 🚧
|
||||
|
||||
> 把"好用"升级为"不可替代":让分权制衡不只是概念,而是有绩效评估、有人工审批、有知识沉淀的完整制度。
|
||||
|
||||
### 🏅 御批模式(人工审批节点)
|
||||
- [ ] 门下省审议结果呈送"御览",人工一键准奏 / 封驳
|
||||
- [ ] 看板内审批面板(待批列表 + 历史批示)
|
||||
- [ ] 飞书 / Telegram 推送审批通知
|
||||
- **难度**:⭐⭐ | **适合第一次贡献**
|
||||
|
||||
### 📊 功过簿(Agent 绩效评分体系)
|
||||
- [ ] 每个 Agent 的完成率、返工率、耗时统计
|
||||
- [ ] 看板面板展示排行榜 + 趋势图
|
||||
- [ ] 自动标记"能臣"和"需要训练的 Agent"
|
||||
- **难度**:⭐⭐
|
||||
|
||||
### 🚀 急递铺(Agent 间实时消息流可视化)
|
||||
- [ ] 看板内实时连线动画:中书→门下→尚书→六部
|
||||
- [ ] 消息类型着色(派发 / 审议 / 回奏 / 封驳)
|
||||
- [ ] 时间线回放模式
|
||||
- **难度**:⭐⭐⭐
|
||||
|
||||
### 📚 国史馆(知识库 + 引用溯源)
|
||||
- [ ] 历史旨意经验自动沉淀
|
||||
- [ ] 相似旨意检索 + 推荐
|
||||
- [ ] 奏折引用溯源链
|
||||
- **难度**:⭐⭐⭐
|
||||
|
||||
---
|
||||
|
||||
## Phase 3 — 生态扩展
|
||||
|
||||
> 从单机工具走向生态:更多集成、更多用户、更多场景。
|
||||
|
||||
### 🐳 Docker Compose + Demo 镜像
|
||||
- [ ] `docker run` 一行命令体验完整看板(预置模拟数据)
|
||||
- [ ] Docker Compose 编排(看板 + 数据同步 + OpenClaw Gateway)
|
||||
- [ ] CI/CD 自动构建推送镜像
|
||||
- **难度**:⭐⭐ | **适合第一次贡献**
|
||||
|
||||
### 🔗 看板适配器
|
||||
- [ ] Notion 适配器 —— 把 Notion database 变成军机处看板
|
||||
- [ ] Linear 适配器 —— Linear 项目同步到三省六部
|
||||
- [ ] GitHub Issues 双向同步
|
||||
- **难度**:⭐⭐⭐
|
||||
|
||||
### 📱 移动端 + PWA
|
||||
- [ ] 响应式布局适配手机/平板
|
||||
- [ ] PWA 离线支持 + 推送通知
|
||||
- **难度**:⭐⭐
|
||||
|
||||
### 🏪 ClawHub 上架
|
||||
- [ ] 核心 Skills 提交到 OpenClaw 官方 Skill 市场
|
||||
- [ ] 一键安装三省六部 Skill Pack
|
||||
- **难度**:⭐
|
||||
|
||||
### 📈 年度大考
|
||||
- [ ] Agent 年度绩效报告(Token 总消耗、完成率、最复杂旨意)
|
||||
- [ ] 可视化年度复盘大屏
|
||||
- **难度**:⭐⭐
|
||||
|
||||
---
|
||||
|
||||
## 如何参与
|
||||
|
||||
1. **看看 Phase 2** —— 这些是当前最需要帮助的方向
|
||||
2. **找标有 ⭐⭐ 或"适合第一次贡献"的项目** 入手
|
||||
3. **开一个 Issue** 说你想做什么,避免重复劳动
|
||||
4. **提 PR** —— 详见 [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
|
||||
> 💡 没找到想做的方向?欢迎开 Issue 提议新功能,好的想法会被加入 Roadmap。
|
||||
BIN
docs/demo.gif
BIN
docs/demo.gif
Binary file not shown.
|
Before Width: | Height: | Size: 416 KiB After Width: | Height: | Size: 4.6 MiB |
18
examples/README.md
Normal file
18
examples/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# 📂 案例 / Examples
|
||||
|
||||
真实的端到端使用案例,展示三省六部处理完整旨意的全流程。
|
||||
|
||||
| # | 案例 | 旨意内容 | 涉及部门 | 复杂度 |
|
||||
|---|------|---------|----------|--------|
|
||||
| 1 | [竞品分析](competitive-analysis.md) | "分析 CrewAI vs AutoGen vs LangGraph" | 中书→门下→户部+兵部+礼部 | ⭐⭐⭐ |
|
||||
| 2 | [代码审查](code-review.md) | "审查 FastAPI 代码的安全性" | 中书→门下→兵部+刑部 | ⭐⭐ |
|
||||
| 3 | [周报生成](weekly-report.md) | "生成本周工程团队周报" | 中书→门下→户部+礼部 | ⭐⭐ |
|
||||
|
||||
每个案例包含:
|
||||
- 📜 **圣旨**:原始指令
|
||||
- 📋 **中书省规划**:任务拆解方案
|
||||
- 🔍 **门下省审议**:审核意见(含封驳/返工记录)
|
||||
- ⚔️ **各部执行结果**:每个部门的产出摘要
|
||||
- 📮 **最终奏折**:尚书省汇总的完整报告
|
||||
|
||||
> 💡 这些案例基于真实运行记录整理,任务 ID 和时间戳已脱敏。
|
||||
139
examples/code-review.md
Normal file
139
examples/code-review.md
Normal file
@@ -0,0 +1,139 @@
|
||||
# 案例 2:代码安全审查
|
||||
|
||||
> **旨意**:审查一段 FastAPI 代码的安全性,输出问题清单和修复建议
|
||||
|
||||
---
|
||||
|
||||
## 📜 圣旨(原始指令)
|
||||
|
||||
```
|
||||
审查以下 FastAPI 代码的安全性,重点关注:
|
||||
1. 认证与授权漏洞
|
||||
2. SQL 注入风险
|
||||
3. 输入验证
|
||||
4. 敏感信息泄露
|
||||
给出问题清单(按严重性排序)和修复代码。
|
||||
|
||||
[附件:app/main.py, app/models.py, app/auth.py — 合计 320 行]
|
||||
```
|
||||
|
||||
**旨意 ID**:`JJC-20260221-007`
|
||||
**下旨时间**:2026-02-21 14:30:00
|
||||
|
||||
---
|
||||
|
||||
## 📋 中书省规划
|
||||
|
||||
> 接旨后 30 秒内完成规划
|
||||
|
||||
**规划方案:**
|
||||
|
||||
| # | 子任务 | 派发部门 | 说明 |
|
||||
|---|--------|----------|------|
|
||||
| 1 | 代码安全扫描 | ⚔️ 兵部 | 逐文件审查,标记安全问题 |
|
||||
| 2 | 合规与最佳实践检查 | ⚖️ 刑部 | 对照 OWASP Top 10 检查合规性 |
|
||||
| 3 | 修复方案输出 | ⚔️ 兵部 | 针对每个问题给出修复代码 |
|
||||
|
||||
**预计耗时**:12 分钟
|
||||
**预计 Token**:~9,000
|
||||
|
||||
---
|
||||
|
||||
## 🔍 门下省审议
|
||||
|
||||
> ⏱️ 审议耗时 18 秒
|
||||
|
||||
### 准奏 ✅(首轮通过)
|
||||
|
||||
**门下省批语:** *"方案合理。兵部负责工程侧审查,刑部负责合规侧审查,分工明确。注意刑部需出具 OWASP 逐项对照表,不能只写'基本合规'。准奏。"*
|
||||
|
||||
---
|
||||
|
||||
## ⚔️ 各部执行结果
|
||||
|
||||
### 兵部 · 代码安全扫描(耗时 5 分钟)
|
||||
|
||||
**扫描发现 6 个问题:**
|
||||
|
||||
| # | 严重性 | 文件 | 问题 |
|
||||
|---|--------|------|------|
|
||||
| 1 | 🔴 严重 | auth.py:23 | JWT secret 硬编码在源码中 |
|
||||
| 2 | 🔴 严重 | main.py:45 | SQL 查询使用 f-string 拼接,存在注入风险 |
|
||||
| 3 | 🟠 高危 | main.py:67 | 用户输入未做长度限制,可造成 DoS |
|
||||
| 4 | 🟠 高危 | auth.py:41 | Token 过期时间设为 30 天,过长 |
|
||||
| 5 | 🟡 中危 | main.py:12 | CORS 设置为 `allow_origins=["*"]` |
|
||||
| 6 | 🟡 中危 | models.py:8 | 密码字段未排除在 response_model 之外 |
|
||||
|
||||
### 刑部 · OWASP 合规检查(耗时 4 分钟)
|
||||
|
||||
**OWASP Top 10 逐项对照:**
|
||||
|
||||
| OWASP 编号 | 类别 | 状态 | 说明 |
|
||||
|-----------|------|------|------|
|
||||
| A01 | Broken Access Control | 🟠 部分合规 | 有 JWT 但缺少角色粒度校验 |
|
||||
| A02 | Cryptographic Failures | 🔴 不合规 | Secret 硬编码 |
|
||||
| A03 | Injection | 🔴 不合规 | SQL 拼接 |
|
||||
| A04 | Insecure Design | ✅ 合规 | 整体架构合理 |
|
||||
| A05 | Security Misconfiguration | 🟡 需改进 | CORS 过宽 |
|
||||
| A06 | Vulnerable Components | ✅ 合规 | 依赖版本较新 |
|
||||
| A07 | Auth Failures | 🟠 部分合规 | Token 过期时间过长 |
|
||||
| A08 | Data Integrity | ✅ 合规 | — |
|
||||
| A09 | Logging Failures | 🟡 需改进 | 缺少安全事件日志 |
|
||||
| A10 | SSRF | ✅ 合规 | 无外部请求 |
|
||||
|
||||
**刑部结论:** 6/10 项需要处理,其中 2 项不合规(A02、A03),需立即修复。
|
||||
|
||||
### 兵部 · 修复代码(耗时 3 分钟)
|
||||
|
||||
```python
|
||||
# 修复 #1: auth.py — JWT secret 从环境变量读取
|
||||
import os
|
||||
JWT_SECRET = os.environ["JWT_SECRET"] # 不再硬编码
|
||||
|
||||
# 修复 #2: main.py — 使用参数化查询
|
||||
from sqlalchemy import text
|
||||
result = db.execute(text("SELECT * FROM users WHERE id = :id"), {"id": user_id})
|
||||
|
||||
# 修复 #3: main.py — 添加输入长度限制
|
||||
from pydantic import Field
|
||||
class UserInput(BaseModel):
|
||||
name: str = Field(..., max_length=100)
|
||||
email: str = Field(..., max_length=255)
|
||||
|
||||
# 修复 #4: auth.py — 缩短 Token 过期时间
|
||||
ACCESS_TOKEN_EXPIRE = timedelta(hours=1) # 从 30 天改为 1 小时
|
||||
|
||||
# 修复 #5: main.py — 收紧 CORS
|
||||
app.add_middleware(CORSMiddleware, allow_origins=["https://yourdomain.com"])
|
||||
|
||||
# 修复 #6: models.py — 密码字段排除
|
||||
class UserResponse(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
email: str
|
||||
# password 字段不在此 model 中
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📮 最终奏折(尚书省汇总)
|
||||
|
||||
**奏折 ID**:`JJC-20260221-007`
|
||||
**总耗时**:14 分钟(规划 1 + 审议 0.5 + 执行 12.5)
|
||||
**总 Token**:8,200
|
||||
|
||||
### 执行摘要
|
||||
|
||||
对 320 行 FastAPI 代码完成安全审查。发现 6 个安全问题(2 严重 / 2 高危 / 2 中危),OWASP Top 10 中有 2 项不合规。已提供全部 6 个问题的修复代码。
|
||||
|
||||
门下省首轮即准奏,兵部和刑部分工明确:兵部负责代码层面扫描和修复,刑部负责合规框架对照。
|
||||
|
||||
### 建议优先级
|
||||
|
||||
1. **立即修复**:JWT secret 硬编码 + SQL 注入(上线前必须解决)
|
||||
2. **本周内**:输入长度限制 + Token 过期时间
|
||||
3. **下个迭代**:CORS 收紧 + 密码字段暴露
|
||||
|
||||
---
|
||||
|
||||
*本案例基于真实运行记录整理,代码内容已脱敏。*
|
||||
139
examples/competitive-analysis.md
Normal file
139
examples/competitive-analysis.md
Normal file
@@ -0,0 +1,139 @@
|
||||
# 案例 1:竞品分析
|
||||
|
||||
> **旨意**:分析 CrewAI、AutoGen、LangGraph 三个多 Agent 框架,输出对比报告
|
||||
|
||||
---
|
||||
|
||||
## 📜 圣旨(原始指令)
|
||||
|
||||
```
|
||||
分析 CrewAI、AutoGen 和 LangGraph 这三个多 Agent 框架。
|
||||
重点关注:架构设计、Agent 通信方式、任务编排能力、可观测性、学习曲线。
|
||||
输出一份结构化的对比报告,包含推荐场景。
|
||||
```
|
||||
|
||||
**旨意 ID**:`JJC-20260220-003`
|
||||
**下旨时间**:2026-02-20 09:15:00
|
||||
|
||||
---
|
||||
|
||||
## 📋 中书省规划
|
||||
|
||||
> 接旨后 45 秒内完成规划
|
||||
|
||||
**规划方案:**
|
||||
|
||||
| # | 子任务 | 派发部门 | 说明 |
|
||||
|---|--------|----------|------|
|
||||
| 1 | 架构与通信机制调研 | ⚔️ 兵部 | 分析三个框架的核心架构、Agent 通信模式、代码组织 |
|
||||
| 2 | 数据采集与量化对比 | 💰 户部 | GitHub Stars、Contributors、Issue 响应时间、版本频率 |
|
||||
| 3 | 开发者体验深度评测 | ⚔️ 兵部 | 实际 Hello World 搭建、文档质量、学习曲线打分 |
|
||||
| 4 | 对比报告撰写 | 📝 礼部 | 整合数据,输出结构化 Markdown 报告 |
|
||||
|
||||
**预计耗时**:25 分钟
|
||||
**预计 Token**:~18,000
|
||||
|
||||
---
|
||||
|
||||
## 🔍 门下省审议
|
||||
|
||||
> ⏱️ 审议耗时 32 秒
|
||||
|
||||
### 第一轮:封驳 🚫
|
||||
|
||||
**封驳理由:**
|
||||
1. 缺少"可观测性"专项评测——旨意明确要求了这一维度,但规划中没有对应子任务
|
||||
2. 子任务 3 和子任务 1 有重叠(兵部两次调研),建议合并
|
||||
3. 建议增加"推荐场景"子任务,不能只有对比没有结论
|
||||
|
||||
**批注:** *"分析没有结论等于没分析。补上推荐场景再报。"*
|
||||
|
||||
### 第二轮:准奏 ✅
|
||||
|
||||
中书省修改后的方案:
|
||||
|
||||
| # | 子任务 | 派发部门 | 变更 |
|
||||
|---|--------|----------|------|
|
||||
| 1 | 架构 + 通信 + 可观测性全维度技术调研 | ⚔️ 兵部 | 合并原 1+3,增加可观测性 |
|
||||
| 2 | 量化数据采集 | 💰 户部 | 不变 |
|
||||
| 3 | 对比报告 + 推荐场景 | 📝 礼部 | 增加推荐场景段落 |
|
||||
|
||||
**门下省批语:** *"方案可行。注意兵部评测需覆盖可观测性维度,礼部结论需给出明确推荐。准奏。"*
|
||||
|
||||
---
|
||||
|
||||
## ⚔️ 各部执行结果
|
||||
|
||||
### 兵部 · 技术调研(耗时 8 分钟)
|
||||
|
||||
```markdown
|
||||
## 架构对比
|
||||
|
||||
### CrewAI
|
||||
- 架构:Role-based Agent + Sequential/Hierarchical Process
|
||||
- 通信:共享 Memory + Task 回调
|
||||
- 可观测性:基本日志,无内置看板
|
||||
- 优点:API 简洁,上手最快(5 分钟 Hello World)
|
||||
- 缺点:调试困难,复杂流程编排受限
|
||||
|
||||
### AutoGen
|
||||
- 架构:Conversational Agent + Group Chat
|
||||
- 通信:消息传递(Message-based)
|
||||
- 可观测性:AgentOps 集成可选,无内置看板
|
||||
- 优点:对话式交互自然,适合 brainstorm 场景
|
||||
- 缺点:群聊模式在任务型场景效率低
|
||||
|
||||
### LangGraph
|
||||
- 架构:State Machine + Graph-based Flow
|
||||
- 通信:State 传递(Graph edges)
|
||||
- 可观测性:LangSmith 集成,有 trace 功能
|
||||
- 优点:流程编排最灵活,支持循环和条件分支
|
||||
- 缺点:学习曲线陡峭,概念抽象
|
||||
```
|
||||
|
||||
### 户部 · 量化数据(耗时 3 分钟)
|
||||
|
||||
| 指标 | CrewAI | AutoGen | LangGraph |
|
||||
|------|--------|---------|-----------|
|
||||
| GitHub Stars | 24.3k | 38.5k | 12.1k |
|
||||
| Contributors | 180+ | 350+ | 90+ |
|
||||
| 最新版本 | v0.8.2 | v0.4.1 | v0.2.8 |
|
||||
| Issue 中位响应 | 2 天 | 3 天 | 1 天 |
|
||||
| 文档评分 | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
|
||||
| Hello World 时间 | ~5 min | ~15 min | ~25 min |
|
||||
|
||||
### 礼部 · 对比报告撰写(耗时 6 分钟)
|
||||
|
||||
> 礼部整合兵部 + 户部数据,产出最终报告格式。
|
||||
|
||||
---
|
||||
|
||||
## 📮 最终奏折(尚书省汇总)
|
||||
|
||||
**奏折 ID**:`JJC-20260220-003`
|
||||
**总耗时**:22 分钟(规划 2 + 审议 3 + 执行 17)
|
||||
**总 Token**:15,800
|
||||
|
||||
### 执行摘要
|
||||
|
||||
对 CrewAI、AutoGen、LangGraph 完成了架构、量化、体验三维度对比分析。门下省一次封驳(要求补充可观测性和推荐场景),修正后执行。
|
||||
|
||||
### 推荐场景
|
||||
|
||||
| 场景 | 推荐框架 | 理由 |
|
||||
|------|----------|------|
|
||||
| 快速原型 | CrewAI | 上手最快,API 简洁 |
|
||||
| 对话式协作 | AutoGen | 天然适合多轮讨论 |
|
||||
| 复杂工作流 | LangGraph | 状态机 + 条件分支最灵活 |
|
||||
| 可靠性要求高 | **三省六部** | 唯一内置强制审核 + 实时看板 |
|
||||
|
||||
### 关键发现
|
||||
|
||||
1. **没有内置审核机制是行业通病** —— 三个框架都依赖开发者自行添加 validation
|
||||
2. **可观测性普遍不足** —— 只有 LangGraph 通过 LangSmith 提供了较好的 trace
|
||||
3. **CrewAI 社区增长最快**,但文档深度不够
|
||||
4. **LangGraph 技术上最强**,但入门门槛高
|
||||
|
||||
---
|
||||
|
||||
*本案例基于真实运行记录整理,数据截至 2026 年 2 月。*
|
||||
147
examples/weekly-report.md
Normal file
147
examples/weekly-report.md
Normal file
@@ -0,0 +1,147 @@
|
||||
# 案例 3:周报生成
|
||||
|
||||
> **旨意**:生成本周工程团队周报,汇总进度、问题和下周计划
|
||||
|
||||
---
|
||||
|
||||
## 📜 圣旨(原始指令)
|
||||
|
||||
```
|
||||
生成本周(2/17-2/21)工程团队周报。
|
||||
数据来源:GitHub commits、PR 记录、Jira tickets。
|
||||
包含:本周完成事项、进行中事项、blocker、下周计划。
|
||||
格式:Markdown,适合贴到飞书文档。
|
||||
```
|
||||
|
||||
**旨意 ID**:`JJC-20260221-012`
|
||||
**下旨时间**:2026-02-21 17:00:00
|
||||
|
||||
---
|
||||
|
||||
## 📋 中书省规划
|
||||
|
||||
> 接旨后 25 秒内完成规划
|
||||
|
||||
**规划方案:**
|
||||
|
||||
| # | 子任务 | 派发部门 | 说明 |
|
||||
|---|--------|----------|------|
|
||||
| 1 | 数据采集与聚合 | 💰 户部 | 从 GitHub + Jira 抓取本周数据 |
|
||||
| 2 | 周报文档撰写 | 📝 礼部 | 按模板格式整理为 Markdown |
|
||||
|
||||
**预计耗时**:8 分钟
|
||||
**预计 Token**:~5,000
|
||||
|
||||
---
|
||||
|
||||
## 🔍 门下省审议
|
||||
|
||||
> ⏱️ 审议耗时 15 秒
|
||||
|
||||
### 准奏 ✅(首轮通过)
|
||||
|
||||
**门下省批语:** *"方案简洁可行。两步走:户部拉数据,礼部写文档。注意礼部输出需严格遵循飞书文档格式要求(标题层级、checkbox 格式)。准奏。"*
|
||||
|
||||
---
|
||||
|
||||
## ⚔️ 各部执行结果
|
||||
|
||||
### 户部 · 数据采集(耗时 3 分钟)
|
||||
|
||||
**本周 GitHub 数据汇总:**
|
||||
|
||||
| 指标 | 数量 |
|
||||
|------|------|
|
||||
| Commits | 47 |
|
||||
| PRs Merged | 12 |
|
||||
| PRs Open | 3 |
|
||||
| Issues Closed | 8 |
|
||||
| Issues Open | 5 |
|
||||
| 最活跃贡献者 | @zhangsan (18 commits) |
|
||||
|
||||
**本周 Jira 数据汇总:**
|
||||
|
||||
| 状态 | Tickets |
|
||||
|------|---------|
|
||||
| Done | 15 |
|
||||
| In Progress | 7 |
|
||||
| Blocked | 2 |
|
||||
| To Do(下周) | 9 |
|
||||
|
||||
**Blockers 识别:**
|
||||
1. `PROJ-234`:第三方 API 限流,等待对方提升配额(blocked 3 天)
|
||||
2. `PROJ-251`:设计稿未定稿,前端被 block
|
||||
|
||||
### 礼部 · 周报文档(耗时 4 分钟)
|
||||
|
||||
---
|
||||
|
||||
## 📮 最终奏折(尚书省汇总)
|
||||
|
||||
**奏折 ID**:`JJC-20260221-012`
|
||||
**总耗时**:8 分钟(规划 0.5 + 审议 0.5 + 执行 7)
|
||||
**总 Token**:4,600
|
||||
|
||||
### 产出:周报全文
|
||||
|
||||
---
|
||||
|
||||
# 📊 工程团队周报 · 2026/02/17 — 02/21
|
||||
|
||||
## ✅ 本周完成
|
||||
|
||||
- [x] **用户认证模块重构** — JWT + Refresh Token 方案上线(@zhangsan, PR #142)
|
||||
- [x] **数据看板 v2** — 新增 3 个图表面板,性能优化 40%(@lisi, PR #138, #140)
|
||||
- [x] **CI/CD 流水线升级** — 构建时间从 8 分钟降至 3 分钟(@wangwu, PR #141)
|
||||
- [x] **API 文档自动生成** — OpenAPI 3.0 spec + Redoc 部署(@zhaoliu, PR #139)
|
||||
- [x] 其他:Bug 修复 ×4, 依赖升级 ×3, 测试覆盖率提升至 82%
|
||||
|
||||
**数据概览:** 47 commits · 12 PRs merged · 8 issues closed
|
||||
|
||||
## 🔄 进行中
|
||||
|
||||
- [ ] **支付系统集成**(60% 完成) — 对接支付宝 + 微信支付,预计下周三完成 (@zhangsan)
|
||||
- [ ] **国际化 i18n**(40% 完成) — 英文 + 日文翻译进行中 (@lisi)
|
||||
- [ ] **性能监控面板**(30% 完成) — Grafana 模板搭建中 (@wangwu)
|
||||
|
||||
## 🚧 Blockers
|
||||
|
||||
| Ticket | 问题 | 已 block | 需要 |
|
||||
|--------|------|----------|------|
|
||||
| PROJ-234 | 第三方 API 限流 | 3 天 | 对方运维提升配额 |
|
||||
| PROJ-251 | 设计稿未定稿 | 2 天 | 设计师 @chenseven 本周内定稿 |
|
||||
|
||||
## 📅 下周计划
|
||||
|
||||
- [ ] 支付系统集成完成 + 沙箱测试
|
||||
- [ ] 国际化覆盖率达到 80%
|
||||
- [ ] 性能监控上线 + 告警配置
|
||||
- [ ] 开始 v3.0 技术方案设计
|
||||
- [ ] Code Review 积压清理(3 个 open PRs)
|
||||
|
||||
## 📈 团队健康度
|
||||
|
||||
| 指标 | 本周 | 上周 | 趋势 |
|
||||
|------|------|------|------|
|
||||
| PR 平均 Review 时间 | 4.2h | 6.1h | 📉 好转 |
|
||||
| 测试覆盖率 | 82% | 78% | 📈 提升 |
|
||||
| Bug 收敛比 | 1.5:1 | 1.2:1 | 📈 提升 |
|
||||
| 团队心情 | 😄 | 😐 | 好转 |
|
||||
|
||||
---
|
||||
|
||||
*由三省六部自动生成 · 数据源:GitHub + Jira · 生成时间:2026-02-21 17:08*
|
||||
|
||||
---
|
||||
|
||||
### 三省六部的价值
|
||||
|
||||
这个案例展示了三省六部处理日常事务的效率:
|
||||
- **门下省首轮即通过** —— 简单任务不过度审核
|
||||
- **户部 + 礼部协作** —— 数据采集和文档撰写分离,各司其职
|
||||
- **8 分钟完成** —— 从下旨到拿到完整周报,不到一杯咖啡的时间
|
||||
- **格式即用** —— 直接复制到飞书文档,无需手动排版
|
||||
|
||||
---
|
||||
|
||||
*本案例基于真实运行记录整理,人名和项目信息已脱敏。*
|
||||
141
scripts/record_demo.py
Normal file
141
scripts/record_demo.py
Normal file
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Record a demo video of the dashboard and convert to GIF."""
|
||||
from playwright.sync_api import sync_playwright
|
||||
import subprocess, os, time
|
||||
|
||||
ROOT = os.path.join(os.path.dirname(__file__), '..')
|
||||
VIDEO_DIR = os.path.join(ROOT, 'docs', '_video_tmp')
|
||||
OUTPUT_GIF = os.path.join(ROOT, 'docs', 'demo.gif')
|
||||
URL = 'http://localhost:7891'
|
||||
|
||||
def main():
|
||||
os.makedirs(VIDEO_DIR, exist_ok=True)
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
ctx = browser.new_context(
|
||||
viewport={'width': 1280, 'height': 720},
|
||||
device_scale_factor=2,
|
||||
color_scheme='dark',
|
||||
record_video_dir=VIDEO_DIR,
|
||||
record_video_size={'width': 1280, 'height': 720},
|
||||
)
|
||||
page = ctx.new_page()
|
||||
|
||||
# === Scene 1: Ceremony (3s) ===
|
||||
print('🎬 Scene 1: Ceremony...')
|
||||
page.goto(URL)
|
||||
page.wait_for_timeout(500)
|
||||
page.evaluate("localStorage.removeItem('openclaw_court_date')")
|
||||
page.reload()
|
||||
page.wait_for_timeout(3500)
|
||||
|
||||
# === Scene 2: Kanban overview (3s) ===
|
||||
print('📋 Scene 2: Kanban...')
|
||||
# Ceremony should have auto-dismissed by now, or skip it
|
||||
page.evaluate("localStorage.setItem('openclaw_court_date', new Date().toISOString().substring(0,10))")
|
||||
page.reload()
|
||||
page.wait_for_load_state('networkidle')
|
||||
page.wait_for_timeout(2000)
|
||||
# Slow scroll down to show tasks
|
||||
page.mouse.wheel(0, 300)
|
||||
page.wait_for_timeout(1500)
|
||||
page.mouse.wheel(0, -300)
|
||||
page.wait_for_timeout(500)
|
||||
|
||||
# === Scene 3: Click a task (3s) ===
|
||||
print('📜 Scene 3: Task detail...')
|
||||
cards = page.locator('.edict-card')
|
||||
if cards.count() > 0:
|
||||
cards.first.click()
|
||||
page.wait_for_timeout(2500)
|
||||
page.keyboard.press('Escape')
|
||||
page.wait_for_timeout(500)
|
||||
|
||||
# === Scene 4: Monitor (2s) ===
|
||||
print('🔭 Scene 4: Monitor...')
|
||||
page.click('[data-tab="monitor"]')
|
||||
page.wait_for_timeout(2000)
|
||||
|
||||
# === Scene 5: Memorials (2s) ===
|
||||
print('📜 Scene 5: Memorials...')
|
||||
page.click('[data-tab="memorials"]')
|
||||
page.wait_for_timeout(2000)
|
||||
|
||||
# === Scene 6: Templates (2s) ===
|
||||
print('📜 Scene 6: Templates...')
|
||||
page.click('[data-tab="templates"]')
|
||||
page.wait_for_timeout(2000)
|
||||
|
||||
# === Scene 7: Officials (2s) ===
|
||||
print('👥 Scene 7: Officials...')
|
||||
page.click('[data-tab="officials"]')
|
||||
page.wait_for_timeout(2000)
|
||||
|
||||
# === Scene 8: Models (1.5s) ===
|
||||
print('⚙️ Scene 8: Models...')
|
||||
page.click('[data-tab="models"]')
|
||||
page.wait_for_timeout(1500)
|
||||
|
||||
# === Scene 9: Back to Kanban (1s) ===
|
||||
print('📋 Scene 9: Back to kanban...')
|
||||
page.click('[data-tab="edicts"]')
|
||||
page.wait_for_timeout(1500)
|
||||
|
||||
# Close context to finalize video
|
||||
page.close()
|
||||
ctx.close()
|
||||
browser.close()
|
||||
|
||||
# Find the recorded video
|
||||
videos = [f for f in os.listdir(VIDEO_DIR) if f.endswith('.webm')]
|
||||
if not videos:
|
||||
print('❌ No video recorded!')
|
||||
return
|
||||
|
||||
video_path = os.path.join(VIDEO_DIR, videos[0])
|
||||
print(f'🎥 Video: {video_path} ({os.path.getsize(video_path) / 1024 / 1024:.1f} MB)')
|
||||
|
||||
# Convert to GIF using ffmpeg
|
||||
# Two-pass: generate palette first for quality, then apply
|
||||
palette_path = os.path.join(VIDEO_DIR, 'palette.png')
|
||||
|
||||
print('🎨 Generating palette...')
|
||||
subprocess.run([
|
||||
'ffmpeg', '-y', '-i', video_path,
|
||||
'-vf', 'fps=12,scale=800:-1:flags=lanczos,palettegen=max_colors=128',
|
||||
palette_path
|
||||
], capture_output=True)
|
||||
|
||||
print('🖼️ Converting to GIF...')
|
||||
subprocess.run([
|
||||
'ffmpeg', '-y', '-i', video_path, '-i', palette_path,
|
||||
'-lavfi', 'fps=12,scale=800:-1:flags=lanczos [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=3',
|
||||
OUTPUT_GIF
|
||||
], capture_output=True)
|
||||
|
||||
size_mb = os.path.getsize(OUTPUT_GIF) / 1024 / 1024
|
||||
print(f'✅ GIF saved: {OUTPUT_GIF} ({size_mb:.1f} MB)')
|
||||
|
||||
if size_mb > 5:
|
||||
print('⚠️ GIF is over 5MB, re-encoding with lower quality...')
|
||||
subprocess.run([
|
||||
'ffmpeg', '-y', '-i', video_path,
|
||||
'-vf', 'fps=10,scale=640:-1:flags=lanczos,palettegen=max_colors=64',
|
||||
palette_path
|
||||
], capture_output=True)
|
||||
subprocess.run([
|
||||
'ffmpeg', '-y', '-i', video_path, '-i', palette_path,
|
||||
'-lavfi', 'fps=10,scale=640:-1:flags=lanczos [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=5',
|
||||
OUTPUT_GIF
|
||||
], capture_output=True)
|
||||
size_mb = os.path.getsize(OUTPUT_GIF) / 1024 / 1024
|
||||
print(f'✅ Re-encoded GIF: {size_mb:.1f} MB')
|
||||
|
||||
# Cleanup
|
||||
import shutil
|
||||
shutil.rmtree(VIDEO_DIR, ignore_errors=True)
|
||||
print('🧹 Cleaned up temp files')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user