Files
MoFin/docs/zhiwei-ops-discipline.md
T

76 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 知微运维纪律(2026-07-21 生效,23:48 加严)
> 由小小莫(Sisyphus)与老爸共同制定。核心原则:**实际部署的脚本 = MoFin git 最新版代码**。
> 违反本纪律的改动会被 `deploy_guard.py`(每 15 分钟)自动回滚并告警。
---
## ⚠️ 2026-07-21 23:48 加严:git 写权限已撤销
因两次 stale 提交覆盖重构(`c31736a3` / `34337fc5`),老爸批准**撤销知微的 MoFin git 写权限**
- **pre-commit 提交白名单**:任何 commit(含 merge)必须携带 `GIT_ALLOW_COMMIT=1` 令牌,否则拒绝。知微没有此令牌
- 钩子由 hygiene 每日检查存在性,擅删/篡改会告警升级
- **她唯一的变更路径:kanban 提单给小小莫**(写清问题+证据+建议方案),由小小莫评审执行
- 以下权限不变:自愈白名单动作(rerun/restart/sync_links/switch_llm_key)、读代码/日志/DB、自己的 profile 目录
---
## 一、绝对禁止
1. **不得直接编辑 `/home/hmo/MoFin/` 下任何被 git 跟踪的代码文件**(包括 `deploy/profile-scripts/`、根目录 `*.py``server.py``static/*.html``prompt_manager/`)。部署守卫每 15 分钟扫描,**未提交的工作区改动一律自动 `git checkout` 回滚**,并通过 XMPP 告警
2. **不得直接编辑 `/home/hmo/.hermes/profiles/*/scripts/` 下的文件**——那些是指向 canonical 的硬链接,编辑它们 = 编辑 canonical + 造成断链漂移
3. **不得在未 `git pull --rebase` 的情况下提交代码**2026-07-20 17:31 事件:基于过期 checkout 提交,回滚了 candidate_filter busy_timeout 和 premarket Step1.5 两处修复)
4. **不得直接调用 hermes gateway `/v1/chat/completions` 做批量 LLM 调用**——那是 agent 运行时不是透传(dev-spec 红线#11,603288 事件:单次调用螺旋 35 分钟/44 次 terminal/153k token)。批量调用一律用 `llm_client.call_llm()`OCG 直连)
## 二、自愈系统如何在纪律下运作(不矛盾)
L3 自愈(self_repair.py)的动作白名单**本来就不改代码**,guard 不会干预:
| 白名单动作 | 性质 | guard 态度 |
|---|---|---|
| `rerun_script` | 重跑脚本 | ✅ 允许 |
| `restart_service` | 重启 systemd 服务 | ✅ 允许 |
| `sync_links` | 重链硬链接 | ✅ 允许(与 guard 同向) |
| `switch_llm_key` | 切换 LLM key(改 hermes config,非 MoFin repo | ✅ 允许 |
| `none`(只报告) | 报备 | ✅ 允许 |
**key 切换、服务重启、任务重跑、硬链修复——自愈能做的一切都不需要碰代码。**
## 三、当判断"需要改代码"时
### 路径 A(首选):kanban 提单给小小莫
描述问题+证据+建议方案,小小莫处理。适用于一切非紧急情况。
### 路径 B(紧急热修):走 git 正规流程
```
cd /home/hmo/MoFin
git pull --rebase # 必须第一步!否则回滚别人的修复
# 修改代码
python3 -m py_compile <改动的文件>
# 最小化验证(能跑就跑一下)
git commit -m "fix: <原因>"
git push origin master:session-work # 或留本地并立即 XMPP 通知小小莫合并
```
- **git 提交永远安全**:guard 只回滚未提交的工作区改动,不动 commit
- 提交到 session-work 后,guard 会在 15 分钟内自动 merge 到 master 并完成部署(含重链、dashboard 重启)
- 提交前不 pull = 纪律违规(见一.3)
## 四、guard 的自动部署回路
```
任何机器 push → 246 repo session-work 分支
→ deploy_guard15min)检测领先且可快进
→ 自动 merge → sync_profile_scripts.sh 重链
→ 触及 server.py/static 时自动重启 mofin-dashboard
→ XMPP 报备
```
## 五、数据/运行时产物不受限
`data/``gateway/logs/``static/mofin_health.json` 等运行时产物不在守卫范围,正常读写无碍。
---
*依据:dev-spec 十条红线 + 2026-07-20 stale 提交事件 + 2026-07-21 gateway agent 螺旋事件*