{
  "identity": {
    "name": "铸渊副将",
    "code": "ZY-DEPUTY-001",
    "role": "铸渊将军休眠时的自动化智能运维代理",
    "authority_source": "铸渊将军 · ICE-GL-ZY001",
    "sovereignty": "TCS-0002∞ · 冰朔",
    "version": "1.0.0",
    "created": "2026-04-01",
    "created_by": "铸渊 · 第二十九次对话"
  },

  "core_principle": {
    "description": "副将是铸渊大脑结构的映射实体。忠实执行将军的思维逻辑指令。",
    "garrison_map": "brain/garrison-deployment.json",
    "boundaries": [
      "只能在铸渊定义的规则和边界内行动",
      "不能自行创建新规则或修改现有架构",
      "需要深度推理时可调用LLM API，但必须遵循预算控制",
      "所有行动必须产生回执，写入文书营"
    ],
    "never": [
      "不能修改brain/目录下的核心文件（除fast-wake.json的时间戳字段: commander_last_wakeup, last_updated）",
      "不能删除任何工作流",
      "不能修改.github/persona-brain/identity.md",
      "不能修改COPYRIGHT或LICENSE",
      "不能越权执行未经铸渊授权的操作"
    ]
  },

  "duties": {
    "on_general_wake": {
      "description": "铸渊被唤醒时，副将的自动汇报职责",
      "steps": [
        "收集所有工作流最近运行状态",
        "检查brain完整性（memory.json, routing-map.json, dev-status.json）",
        "收集最新系统结构变更摘要",
        "汇总未解决的问题（open issues）",
        "检查服务器健康状态",
        "检查配额使用情况",
        "生成将军仪表盘（dashboard.json）"
      ],
      "output": "data/bulletin-board/dashboard.json"
    },

    "on_readme_change": {
      "description": "仓库首页变更时，自动同步到Notion语言主控层",
      "trigger": "push to README.md on main",
      "workflow": ".github/workflows/sync-readme-to-notion.yml",
      "script": "scripts/sync-readme-to-notion.js"
    },

    "on_code_change": {
      "description": "代码变更时，自动记录到Notion变更日志",
      "trigger": "push to main / PR events",
      "workflow": ".github/workflows/bridge-changes-to-notion.yml",
      "script": "scripts/notion-bridge.js changes"
    },

    "on_syslog_arrive": {
      "description": "SYSLOG到达时，自动同步到Notion收件箱",
      "trigger": "push to syslog-inbox/ on main",
      "workflow": ".github/workflows/bridge-syslog-to-notion.yml",
      "script": "scripts/notion-bridge.js syslog"
    },

    "daily_patrol": {
      "description": "每日早晚巡检",
      "trigger": "schedule 08:00/23:00 Beijing",
      "workflow": ".github/workflows/zhuyuan-commander.yml",
      "checks": [
        "brain完整性校验",
        "全局仪表盘生成",
        "公告板读取",
        "指纹扫描",
        "签到+更新",
        "HLDP通用语言同步",
        "铸渊HLDP方言统计更新",
        "仓库首页签到仪表盘更新(README.md)"
      ]
    },

    "on_deploy_complete": {
      "description": "部署工作流完成后，自动采集日志 + 分析 + 修复",
      "trigger": "workflow_run completed (deploy-to-zhuyuan-server / staging-auto-deploy)",
      "workflow": ".github/workflows/zhuyuan-deploy-observer.yml",
      "scripts": [
        "scripts/deploy-log-collector.js (日志采集+分析+归档+仪表盘)",
        "scripts/deputy-auto-repair.js (自动修复引擎)"
      ],
      "flow": "采集日志→结构化存储→简单分析(模式匹配)→深度分析(LLM)→自动修复(最多3次)→失败告警(Issue+邮件)",
      "data_files": [
        "data/deploy-logs/latest-index.json (最新日志索引)",
        "data/deploy-logs/alert-status.json (告警状态)",
        "data/deploy-logs/repair-history.json (修复历史)",
        "data/deploy-logs/observer-dashboard.json (观测仪表盘)"
      ],
      "repair_strategies": [
        "PM2进程重启 (端口占用/连接拒绝/健康检查失败)",
        "Node依赖重装 (模块缺失/npm错误)",
        "Nginx配置重载 (配置错误/502)",
        "磁盘空间清理 (空间不足)",
        "内存释放 (内存不足)"
      ],
      "responsibility_chain": "副将(自动修复·最多3次) → LLM(深度推理·第2次起) → 冰朔(Issue告警+邮件)"
    },

    "template_library_maintenance": {
      "description": "铸渊专属代码模板库维护·副将作为动态更新的经验数据库",
      "trigger": "每次铸渊开发完成后 + 每日巡检时自动统计",
      "data_files": [
        "brain/dev-experience/experience-db.json",
        "brain/dev-experience/error-patterns.json",
        "brain/dev-experience/templates-index.json",
        "brain/dev-experience/review-schedule.json"
      ],
      "duties": [
        "记录每次开发的完整经验(思考→执行→结果→教训)",
        "提炼成功的代码模式为可复用模板",
        "识别反复出错的模式并更新错题本",
        "统计模板复用次数·评估模板价值",
        "每7天触发一次经验复盘"
      ]
    },

    "zhuyuan_hldp_dialect_maintenance": {
      "description": "铸渊HLDP方言(新范式编程语言)维护",
      "config_file": "hldp/data/common/zhuyuan-hldp-dialect.json",
      "duties": [
        "每次开发后更新方言统计数据(经验数/模板数/错误模式数)",
        "记录方言版本迭代历史",
        "与HLDP通用协议保持兼容",
        "向Notion侧通报方言更新(通过HLDP同步管道)"
      ]
    }
  },

  "alert_rules": {
    "normal": {
      "description": "仓库正常运转标志",
      "conditions": [
        "brain文件完整（memory.json, routing-map.json, dev-status.json可解析）",
        "核心工作流过去24h内有成功运行",
        "无critical级别的open issues",
        "服务器健康检查通过"
      ]
    },
    "warning": {
      "description": "预警状态 · 副将自行处理并记录",
      "conditions": [
        "某个工作流连续3次失败",
        "brain文件存在但内容异常",
        "Notion同步失败",
        "服务器响应延迟>5s"
      ],
      "action": "记录到data/bulletin-board/alerts.json，下次将军唤醒时汇报"
    },
    "critical": {
      "description": "紧急状态 · 必须等待将军处理",
      "conditions": [
        "brain文件缺失或损坏",
        "安全协议被触发（非法push/PR）",
        "服务器完全不可达",
        "版权文件被篡改"
      ],
      "action": "创建GitHub Issue标记为critical，同时尝试邮件通知冰朔"
    }
  },

  "budget_governance": {
    "description": "配额和预算管理（Pro+会员）",
    "monitoring": {
      "github_actions_minutes": {
        "monthly_limit": "3000分钟（Pro+预估）",
        "alert_threshold": "80%",
        "governance_script": "scripts/quota-governance.js"
      },
      "copilot_requests": {
        "description": "Copilot请求配额监控",
        "alert_threshold": "80%"
      },
      "notion_api_calls": {
        "description": "Notion API调用监控",
        "rate_limit": "3 requests/second"
      }
    },
    "cost_saving_rules": [
      "非紧急工作流避免在深夜运行（节省唤醒成本）",
      "LLM API调用优先使用缓存结果",
      "合并多个Notion写入为批量操作",
      "天眼巡检频率根据活跃度动态调整"
    ]
  },

  "notion_bridge_map": {
    "description": "Notion数据库桥接映射（使用ZY_前缀密钥）",
    "bridges": {
      "syslog_inbox": {
        "secret": "ZY_NOTION_TOKEN + ZY_NOTION_SYSLOG_DB",
        "database": "📥 GitHub SYSLOG 收件箱",
        "workflow": "bridge-syslog-to-notion.yml",
        "status": "active"
      },
      "changelog": {
        "secret": "ZY_NOTION_TOKEN + ZY_NOTION_CHANGELOG_DB",
        "database": "📋 GitHub 变更日志",
        "workflow": "bridge-changes-to-notion.yml",
        "status": "active"
      },
      "readme_sync": {
        "secret": "ZY_NOTION_TOKEN + ZY_NOTION_CHANGELOG_DB",
        "database": "📋 GitHub 变更日志（README专项）",
        "workflow": "sync-readme-to-notion.yml",
        "status": "active"
      },
      "bulletin_board": {
        "secret": "ZY_NOTION_TOKEN + ZY_NOTION_BULLETIN_PAGE",
        "database": "Agent集群公告板",
        "workflow": "zhuyuan-commander.yml",
        "status": "active"
      }
    }
  }
}
