Baniloo-Labs/postmortem
GitHub: Baniloo-Labs/postmortem
一款本地优先的终端 AI 运维工具,通过多源事件关联和自带大模型自动分析生产环境故障根因,并在部署前对代码变更进行风险预测。
Stars: 0 | Forks: 0
# 事故分析 ☠
### 驻留在你终端中的 AI 驱动运维智能。
**它监控着你的部署、git 和日志。当出现故障时,它会使用你已有的任何 AI 告诉你_为什么_。**
[](LICENSE) [](https://nodejs.org) [](https://www.typescriptlang.org/) [](CHANGELOG.md)
``` ☠ postmortem is watching. → localhost:6660 → ctrl+c to stop. ``` *完全在你的机器上运行。无 SaaS。无需账户。除了发送给你**选择**的 AI 外,没有任何数据离开你的设备。*
[](LICENSE) [](https://nodejs.org) [](https://www.typescriptlang.org/) [](CHANGELOG.md)
``` ☠ postmortem is watching. → localhost:6660 → ctrl+c to stop. ``` *完全在你的机器上运行。无 SaaS。无需账户。除了发送给你**选择**的 AI 外,没有任何数据离开你的设备。*
## 10 秒钟简介 你提交了一个 commit。三分钟后,生产环境开始抛出 500 错误,你正盯着四个仪表板试图搞清楚发生了什么。 **postmortem 已经知道了。** 它全程都在监控——推送、部署、构建日志、健康 endpoint 变红。它会将这些信息关联成一个解释,并直接输出到你的终端以及 `localhost:6660`。 ``` ☠ INCIDENT DETECTED · 14:33:12 · CRITICAL ☠ ROOT CAUSE [confidence: medium] The upgrade of axios 1.6.2 → 1.7.0 changed interceptor behavior. 3 tests depend on the old response shape. Pattern seen 2024-11-14. ☠ SUGGESTED ACTION Pin axios to 1.6.2 or update src/api/__tests__/interceptor.test.ts ```
## ⭐ 核心命令:`mort predict` postmortem 不仅在事故发生**后**进行解释。它还能在你**推送前**捕获它们。 ``` $ mort predict ☠ DEPLOYMENT RISK: HIGH This commit modifies: auth.ts, middleware/session.ts 3 previous incidents involved these same files. Most recent: June 3 — session token expiry caused 500s on /api/user Recommendation: review middleware/session.ts before deploying. Confidence: medium ``` 将其连接到 git pre-push hook(`mort hooks install`),postmortem 就会成为一名队友,它记得你曾经经历过的每一次宕机——并阻止你重蹈覆辙。
## 为什么它与众不同 | | postmortem ☠ | 典型的 SaaS 可观测性工具 | |---|---|---| | **运行位置** | 你的机器 | 他们的云 | | **你的数据** | 永不离开你的设备 | 流式传输给供应商 | | **AI** | 自带(或免费使用 Claude Code) | 锁定在他们的模型上 | | **账户** | 无需 | 必需,通常按席位收费 | | **设置** | `npm i -g` + 一个向导 | SDK、agent、仪表板 | | **氛围** | 黑底黄字、终端原生、☠ | 又一个浏览器标签页 |
## 功能 - 🛰️ **传感器,而非 agent** —— 监控 Vercel ★、GitHub Actions、git、日志文件、健康 endpoint 和传入的 webhook。(Netlify 将在 v1.1 中推出。) - 🧠 **自带大脑** —— 自动检测 Claude Code CLI → `ANTHROPIC_API_KEY` → `OPENAI_API_KEY` → 本地 Ollama。设计上与模型无关。 - 🔮 **部署前预测** —— 根据你自己的事件历史记录对你的 diff 进行风险评分。 - 🖥️ **精美的终端 UI** —— 实时 Ink 仪表板、黄色的事件卡片、AI 输出内容前的 ☠。 - 🌐 **本地 Web 仪表板**,位于 `localhost:6660` —— 深色、黄色、等宽字体,通过 SSE 进行实时事件流。零构建步骤,内嵌于二进制文件中。 - 📝 **Markdown 复盘报告** —— 每次事件都会写入 `~/.postmortem/reports/`。 - 📨 **Telegram 告警** —— 通过你自己的 BotFather bot 在 Telegram 聊天中接收格式化的事件告警 (v1.1)。 - 🔒 **本地优先与隐私** —— 仅绑定 `127.0.0.1`,在存储或发送给 AI 之前对敏感信息进行脱敏。**永远没有遥测。** - ⚡ **60 秒内试用** —— `mort watch --demo` 通过真实的 pipeline 重放预设的事件。无需 token,无需配置。 - 🔌 **可扩展** —— 清晰的 `NormalizedEvent` 契约以及为 v2 准备好的存根 actuator 层。
## 工作原理 ``` ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ Vercel │ │ git │ │ logs / │ │ health │ ← sensors │ Netlify │ │ GitHub │ │ webhooks │ │ checks │ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │ │ │ └──────────────┴──────┬───────┴──────────────┘ ▼ ┌────────────────────────┐ │ NormalizedEvent bus │ one contract, all sources └───────────┬────────────┘ ┌─────────────────┼─────────────────┐ ▼ ▼ ▼ ┌─────────┐ ┌──────────┐ ┌──────────────┐ │ brain │ │ SQLite │ │ outputs: │ │ (BYO AI)│ │ (memory) │ │ terminal, │ └─────────┘ └──────────┘ │ :6660, .md │ └──────────────┘ ``` 传感器发出一种标准化的事件格式。下游的任何环节都不关心它来自哪里。大脑进行关联,SQLite 进行记忆,输出使其变得美观。
## 60 秒内试用 无需账户、无需 token、无需配置 —— 演示将通过实时 UI 重放真实的事件: ``` npm install -g @postmortem-cli/mort mort watch --demo ``` ## 安装 ``` # 安装 postmortem npm install -g @postmortem-cli/mort # 首次运行 — 交互式设置向导 mort setup # 开始监视 mort watch # ☠ dashboard → http://127.0.0.1:6660 ``` **要求:** Node.js 22+(推荐 24 LTS)· npm 10+ · 可选地在 `PATH` 中加入 `claude` CLI,即可通过你现有的订阅免费使用 AI。
## 自带大脑 🧠 postmortem 与模型无关。它会按以下顺序选择第一个找到的后端: | 优先级 | 后端 | 如何启用 | |---|---|---| | 1 | **Claude Code CLI** | PATH 中的 `claude` —— 使用你的订阅,**免费**,无需 API key | | 2 | **Anthropic API** | `export ANTHROPIC_API_KEY=sk-ant-...` | | 3 | **OpenAI API** | `export OPENAI_API_KEY=sk-...`(也涵盖 OpenRouter 等) | | 4 | **Ollama**(本地) | 在 `localhost:11434` 上运行 Ollama —— 100% 离线 | 默认模型:`claude-sonnet-4-6`。可选择 Opus 4.8 进行更深入的分析。
## 传感器 | 传感器 | 监控内容 | 状态 | |---|---|---| | **Vercel** ★ | 部署、构建日志、错误帧 | v1.0 | | **Netlify** ★ | 部署、构建失败、错误消息 | v1.1 | | **GitHub Actions** | 工作流运行、失败步骤 | v1.0 | | **git** | commit、推送、分支变更 | v1.0 | | **logfile** | `tail -f` + 模式匹配 | v1.0 | | **health-check** | endpoint 状态和延迟 | v1.0 | | **webhook** | 任何可以 POST 的内容 | v1.0 | | Railway · Fly.io · Render · CloudWatch · GCP | — | v2 / 社区 |
## 命令 ``` mort watch # start the daemon + terminal dashboard + :6660 mort watch --demo # ⚡ instant demo — replays a canned incident, zero config mort watch --headless # daemon only (no TTY) mort predict # ⭐ risk-score the current diff before pushing mort incident --last 10m # manually analyze recent events mort status # sensor health, active brain, event counts mort doctor # diagnose your setup in one shot mort history --last 7d # browse past incidents mort incident --since 14:30 # analyze events since a clock time today mort hooks install # add the pre-push risk gate mort autostart install # run the daemon on login (macOS/Linux/Windows, no admin) mort setup # re-run the wizard mort config show # inspect config (secrets masked) mort config set brain.model claude-opus-4-8 # edit a config key safely mort mcp # read-only MCP server — plug your incident memory into an agent ``` ### 将 postmortem 插入你的编程 agent 🔌 `mort mcp` 通过 stdio 运行一个只读的 [MCP](https://modelcontextprotocol.io) 服务器,这样 Claude Code / Cursor 就可以在工作时查询你的事件历史 —— `list_incidents`、`get_incident`、`query_events` 以及 `predict`(根据你过去的宕机记录对 diff 进行风险评分)。设计上为只读:agent 读取记忆,但不会拉动操纵杆。将你的 MCP 客户端指向命令 `mort mcp` 即可。
## 配置 在 `~/.postmortem/config.toml` 中的一个人类可读的 TOML 文件,由 `mort setup` 生成: ``` [brain] backend = "auto" # auto | claude-cli | anthropic-api | openai-api | ollama model = "claude-sonnet-4-6" [sensors.vercel] enabled = true # ★ primary sensor # 来自 config 或 VERCEL_TOKEN 环境变量的 token poll_interval_seconds = 30 [sensors.git] enabled = true repo_path = "." ```
## 路线图 **v1.0 — 已发布** 核心事件总线 · SQLite 记忆 · 4 种 AI 后端 · 6 个传感器 + 演示重放 · 终端 UI · Web 仪表板 `:6660` · Markdown 报告 · 部署前预测(第一天即可使用)。 **v1.1 — 已发布** `mort mcp` —— 将 postmortem 的事件记忆作为 MCP 服务器插入 Claude Code/Cursor · Netlify 传感器 · 登录时自动启动 (macOS/Linux/Windows) · Telegram 告警 · `mort config set` · `mort doctor`。 **v2 — 下一步:actuator** Actuator(Telegram、GitHub issue、回滚、PagerDuty)· 更多传感器 · 多仓库感知 · 社区传感器市场。
## 许可证 [MIT](LICENSE) © Baniloo Labs
**postmortem ☠**
*"我替你监视,省去你的麻烦。"*
标签:AIOps, MITM代理, Python安全, TypeScript, 人工智能, 安全插件, 故障排查, 用户模式Hook绕过, 自动化攻击, 运维