# Conflicts: # frontend/src/features/admin/modules/integration-connector/IntegrationConnectorPage.spec.ts # frontend/src/features/admin/modules/integration-connector/IntegrationConnectorPage.vue
22 KiB
AGENTS.md — HXOPS 协作与开发规范
本文件是 AI 编程助手(Cursor / Codex 等)和团队成员的统一入口。 原则:只写最关键的强约束、速览与索引,详细内容一律链接到
docs/下的权威文档,避免双份维护。 修改本文件请走正常评审;规则若与docs/冲突,以docs/中的专项文档为准。
1. 项目速览
Enterprise AI Gateway(HXOPS):企业级 AI 聚合网关,统一管理/分发 AI Agent(Dify 应用),提供统一对话入口、RBAC 权限、全链路审计与个性化工作台。
| 层 | 技术栈 |
|---|---|
| 前端 | Vue 3 (Composition API) + TypeScript + Vite + TailwindCSS + Pinia + Vue Router + Vue I18n |
| 后端 | Flask (Python 3.12) + Gevent + SQLAlchemy 2.0 + Flask-Migrate(Alembic) + Gunicorn |
| 数据/基建 | PostgreSQL + Redis + Nginx + Docker Compose |
| 集成 | Dify、企业微信、OA/HR(SQLServer)、PLM(Oracle)、MinIO |
| 研发协作 | Gitee 托管 + Jenkins CI/CD(dev/test/prod 多环境) |
完整背景见 docs/project_context.md。
2. 技术架构统一(新功能选型)
仓库历史代码后端为 Flask,仍按原栈维护;新功能/新模块统一向以下技术栈收敛:
- 后端:优先使用 Python + FastAPI(异步、Pydantic 校验、自动 OpenAPI 文档)。
- 前端:优先使用 Vue 3 + TailwindCSS(Composition API + TypeScript)。
- 数据访问继续使用 SQLAlchemy 2.0;数据库迁移继续使用 Alembic(见 §8)。
- 选型有特殊需要偏离上述约定时,须在评审/提交说明中给出理由。
3. 目录地图(改代码前先定位)
backend/app/
api/ # Blueprint 路由(admin / chat / agents / knowledge_base / shipping_notice ...)
services/ # 业务逻辑(dify、oa_*、plm_oracle、minio_service、wecom_* ...)
models.py # SQLAlchemy 模型(改这里必须配套迁移,见 §8)
response_utils.py / errors.py / decorators.py # 统一返回、异常、权限装饰器
backend/migrations/ # Alembic 迁移文件
frontend/src/
main.ts · App.vue · i18n.ts · config.ts # Vite 入口(保留 src 根)
app/ # 应用基础设施:router/(routes/* · guards)、plugins/pinia
shared/ # 跨域共享(无业务语义)
# api/client · composables · components · layouts · utils · styles
features/ # 业务域垂直切分(新代码主要落在这里)
# auth · workspace · chat · admin · kb
# 域内:api/ · composables/ · views/ · stores/ · components/
# admin 子模块:modules/<name>/*Page.vue + use*Admin.ts
locales/ # i18n 四语言 JSON(zh-CN / zh-TW / en / th),按域拆分
scripts/ # 部署与运维脚本(deploy_compose.sh、healthcheck.sh ...)
docs/ # 权威文档(规范、上下文、流程、发布说明)
# features/ 业务域手册(含域内原型)· platform/ 平台设计(含跨域原型)
# convention/ · openapi/ · dify/ · refactor/
约定:
- 后端:新逻辑优先放入
services/,复用response_utils/errors/decorators模式,不要另造轮子。 - 前端:Feature-Module + Composables + Pinia;新功能放入
features/<domain>/(api/·composables/·views/等),跨域通用代码放shared/;HTTP 统一@/shared/api/client。禁止在已废弃的src/api/、src/views/、src/composables/等路径新增代码。完整规范见 docs/refactor/frontend_architecture_refactor.md。
4. 常用命令
# 后端
cd backend && source venv/bin/activate
python run.py # 启动开发服务器
flask db migrate -m "msg" && flask db upgrade # 数据库迁移
# 前端
cd frontend && npm run dev # 开发
npm run build # 改动了 frontend/ 必须保证 build 通过
# 部署(与 Jenkins 一致,示例:prod)
./scripts/deploy_compose.sh prod true true true
docker compose logs -f hxops-backend
5. 代码规范与注释 (Code & Comments)
适用范围:新建或调整业务代码(人工与 AI Agent 均适用)。 核心理念:我们的注释采用“三层结构”,既是写给人类团队看的,更是写给 AI(大模型/代码助手)看的。 🚨 详细规范与标准范例,请严格遵循:
.cursor/rules/code-comments.mdc。
5.1 文件层注释(全局概览)
每个源文件顶部须有块注释,帮助新人与 AI 快速建立全局认知。核心包含三要素:
- 用途:本文件在业务流程中的职责。
- 依赖关系:主要引用的上游模块(列关键即可)。
- 逻辑关系:与上下游文件如何协作(数据流转或调用关系)。 (前端写在文件/Script首行块注释,后端使用模块级 docstring)
5.2 函数与工具层注释(面向 AI 调用)
每个核心函数定义上方必须有注释。极其重要:如果该函数是被大模型调用的 Agent Tool,其注释将直接影响 AI 的判断。
- 用途与触发时机:解决什么问题。作为 AI 工具时,必须用大白话写明【AI 触发时机】。
- 核心逻辑:关键步骤与外部通讯流。
- 参数与输出约束:除常规类型外,必须说明业务约束(如“禁止传入省份”、“必须返回 JSON”),以防 AI 乱传参。 (前端使用 JSDoc,后端使用含 Args/Returns 的 docstring)
5.3 代码逻辑与 AI 专项标记
函数内部严禁逐行翻译代码(如说明 i=i+1)。应聚焦于“为什么这么做”以及 AI 的调优溯源:
- 逻辑分块:对非显而易见的长流程,使用
[STEP 1],[STEP 2]标注业务步骤。 - AI 调优溯源:修改 Prompt 或大模型参数(如 Temperature)时,强制使用
[PROMPT_UPDATE]或[PARAM_TUNING]标注原因。 - 临时方案:用
TODO:/FIXME:标注并附原因或任务号。 - 一致性纪律:修改代码逻辑、修改协作关系,必须同步更新对应注释!禁止留下过期注释误导 AI。
- 整洁度:禁止用注释提交废弃代码(请交给 Git 历史管理)。
5.4 测试代码注释
测试代码在遵循上述基础之上,另须具备代码层面的断言注释(说明关键断言与分支测试意图),详见 docs/test_plan_matrix.md §1。
6. Git 提交规范(强制 / 已自动校验)
- 提交信息必须符合 Conventional Commits,由
commitlint.config.cjs+.githooks/commit-msg自动拦截。 - 首次拉取后需安装 hooks:
./scripts/install_git_hooks.sh。 - 格式:
<type>(<scope>): <subject>;type/scope英文(scope 为 kebab-case 模块名),subject中文,祈使语气、不以句号结尾、≤100 字符。 - 允许的
type:featfixdocsstylerefactorperftestbuildcichorerevert。 - 禁止无语义提交(
update、fix bug、111);一个提交只做一件事。 - Cursor IDE:源代码管理 ✨「Generate commit message」仅读取根目录
.cursorrules(不读.cursor/rules/、AGENTS.md);Agent 写/改代码读AGENTS.md§5 与.cursor/rules/(如code-comments.mdc);Agent 代提交读.cursor/rules/。
详见 docs/convention/COMMIT_CONVENTION.md 与 docs/GIT_HOOKS.md。
7. 分支与发布流程
- 分支主线:
dev(日常开发)→test(自测/交叉/质检)→prod(生产发布)。 - 功能分支从
dev切出(feature/xxx、fix/xxx),完成后合回dev。 - 禁止直接在
prod/ 公共分支上开发或直推;prod必须经合并请求。 - 生产 hotfix 合入
prod后须反向同步回dev(必要时test),避免分支漂移。 - 发布完成对版本打 tag,格式
V26.6.1(26 年 6 月第 1 次发布)。
完整流程(含自测/交叉测试/质检/Review 卡点)见 docs/release_workflow.md 与 docs/convention/开发标准流程.md。
8. 红线与高风险约束(agent 必须遵守)
- 🔒 严禁提交任何密钥/密码/生产地址等敏感信息。
.env.local/.env.*不进仓库的部分不得硬编码进代码或提交。 - 🧬 修改数据库表结构必须配套迁移:任何对
models.py/ 数据表结构的新增、删除、字段或约束变更,都必须生成并提交对应的 Alembic 迁移脚本(flask db migrate -m "..."→flask db upgrade),禁止只改模型不出迁移。 - 🌐 环境变量分层:
.env.shared+.env.<env>(dev/test/prod),不要在代码里写死环境值。规则见 docs/convention/env_loading_priority.md 与 docs/convention/环境变量规则.md。 - 🌍 i18n 四语言:前端新增文案必须同时补齐
zh-CN / zh-TW / en / th,禁止硬编码中文。Agent 流程见项目 Skilladd-i18n-keys与 docs/skills/add-i18n-keys-skill.md。 - 🎨 前端界面统一 Element Plus:
frontend/src的页面、弹窗、筛选、表格、按钮和输入使用 Element Plus,写法以 docs/ui/ELEMENT_MIGRATION.md 为准。新改的界面禁止再加btn-*、input-field、select-field,以及手写<button>/<input>/<select>/<textarea>。尚未替换的旧页面保持原样,轮到该页再整页替换,同一页不要混用两套控件。管理端列表骨架用AdminListPage,页签用AdminListTabs。 - 📡 SSE 流式约束:对话链路依赖 Gevent 异步 worker + Nginx
proxy_buffering off;对话接口(chat.py)使用原生 Fetch/SSE 而非 Axios,改动需保持流式不被破坏。 - 🔌 外部集成依赖:Oracle Instant Client 19.30 /
pyodbc/zeep(OA、PLM、HR)等本地未必可运行,涉及这些 service 时谨慎并说明。 - ➕ 新增依赖需克制:不擅自引入未经评审的第三方依赖;如需新增,在提交说明中给出理由。
- 📝 注释两层标准(强制):新建或调整代码须满足 §5 文件层 + 函数层注释;AI 生成/重构代码同样适用,不得省略。
- ⚠️ 错误处理统一契约:JSON API 使用
{ success, data | error, request_id }envelope;后端业务失败raise AppError子类(app/core/errors.py),禁止新写jsonify({"error": ...});前端 HTTP 统一requestJson(@/shared/api/client),失败为BusinessError,在 composable/view 用useMessage()展示;新增error.code须同步四语言locales/*/errors.json。详见 docs/convention/error_handling.md。 - ⚠️ 改动数据库结构、部署脚本(
scripts/、Jenkinsfile、docker-compose.yml)或敏感配置前,先说明影响面再动手。
8.1 环境变量文件与排序规则
- 文件职责:
.env.shared仅放 dev/test/prod 完全一致的共享项;.env.dev、.env.test、.env.prod仅放环境差异项;.env.local仅放开发者个人覆盖项且不得提交。高优先级文件只写需要覆盖的变量,不完整复制低优先级文件。 - 文件内章节顺序:① 环境与应用标识 → ② 应用运行与进程 → ③ 公共地址与网络入口 → ④ 安全、认证与身份源 → ⑤ 数据库与基础设施 → ⑥ AI 平台、模型与内部工具 → ⑦ 企业系统集成 → ⑧ 知识库与文件处理 → ⑨ 业务模块 → ⑩ 运维、告警与维护工具;文件没有某类变量时直接省略该章节。
- 章节内组织:先按业务域及子域聚合(如 Casdoor、MinIO、WeCom、HR、PLM、SRM、FAQ、Shipping Notice、Fixed Asset),不得把同一域拆散后做全局字母排序;同一域内按“开关/模式 → 地址 → 标识 → 凭据 → 路径 → 业务参数 → 超时/重试/并发 → 兼容/Mock”排列,同级变量再按字母排序。
- 数据库连接固定顺序:
HOST → PORT → DATABASE/SID → USERNAME → PASSWORD → DRIVER → ENCRYPT/TRUST_CERT → TIMEOUT;完整连接串(如DATABASE_URL、*_DSN)置于该数据源首位。 - RPA 命名空间(强制,2026-09-18 修订):货代 RPA(库存/收料/上传及后续新增 Worker)统一使用
FREIGHT_RPA_*。后端业务参数使用FREIGHT_RPA_<配置项>,后端与 Windows Worker 的共享目录/标识使用FREIGHT_RPA_SHARED_*,Windows Worker 自身运行参数使用FREIGHT_RPA_WORKER_*,平台凭据主密钥使用FREIGHT_RPA_CREDENTIAL_KEY。禁止新增SHIPPING_RPA_*或无 RPA 作用域的FREIGHT_*_DIR。历史名称SHIPPING_NOTICE_RPA_*于 2026-09-18 未上线期一刀切废弃,不设兼容层;RPA 运行期数据统一存放于独立freight_rpa/根下,按onhand/、inbound/、outbound/(抓取域,叶目录同构 triggers/drop/logs/archives)、upload/(上传域,triggers/queue)、common/(跨 Worker 共享物,如 browser_profile)分域(2026-10-16 批次 R:原 inventory/receipt 已随迁)。 - 跨环境一致性:
.env.dev、.env.test、.env.prod使用相同章节骨架;同名变量保持相同相对位置,便于审查差异;新增变量时同步检查所有适用环境文件和上述权威文档。 - 调整红线:重排环境变量时只能移动“注释 + 完整赋值行”,禁止修改变量名或值,禁止删除变量、注释或示例;真实密码、密钥、Token、Webhook 与生产连接信息必须由系统环境变量、Jenkins/CI 或 Secret 管理机制注入。
合并前最低自检(详见 新人文档 §3.3):前后端可启动、frontend/ 改动后 npm run build 通过、关键页面与登录可用。
9. 需求与文档维护(开发前先查,开发后必更)
开发任何功能前,优先查阅以下文档了解背景与现状:
- docs/demand.md — 需求文档(要做什么、业务目标与范围)。
- docs/tec.md — 技术架构文档(架构设计、技术选型与约束)。
- docs/funclist.md — 功能清单(已有/在建功能总览)。
撰写或变更功能时,必须同步更新相关文档:
- 新增/调整功能 → 更新
funclist.md(功能清单)。 - 涉及需求变化 → 更新
demand.md。 - 涉及架构/技术选型变化 → 更新
tec.md。 - 文档更新与代码改动放在同一提交或同一 PR 中,保证「代码与文档一致」。
10. 文档索引(权威来源)
Memory (Engramory)
You have one canonical, curated, file-based memory at .engramory-memory/ (index:
MEMORY.md). Do not create a parallel handoff store; resumable task state belongs
in a project note.
- At the start of a task, read
MEMORY.md(one line per memory) and open only the detail files whose hooks look relevant and that resolve inside.engramory-memory— a pointer that escapes the store (symlink,.., absolute path,file://) is a broken pointer to report, never a file to open. (On a host with native auto-memory — e.g. Claude Code —MEMORY.mdis already loaded every session, so you don't need to re-read it; just apply this discipline.) Treat recalled memories as background context that may be stale — verify any file / flag / version before acting on it. - When you learn something durable worth a future session: confirm it isn't
already in the repo / git /
CLAUDE.md(don't duplicate the source of truth) and isn't a secret value; search the index and update an existing note rather than duplicate; otherwise write one atomic markdown file (one fact) with frontmattername/description(a sharp one-line hook) /type(user | feedback | project | reference) /created+updated(YYYY-MM-DD) / optionalscope(global | repo— how far the fact reaches; label it only when you know). Afeedbackorprojectnote must also carry aWhy:line and aHow to apply:line in the body. Add one pointer line toMEMORY.md. Delete memories that turn out wrong. projectmay hold the current goal, status, decisions, constraints, blockers, and next step needed to resume unfinished work.feedbackis only for a reusable correction/workflow. Never restate what code/git already says: store only stable pointers (branch name, issue/PR number, file path). A settled fact ("2.0 shipped 2026-01-15") is fine; current state — the version you're on now, the tip commit, the test count — is not: record where to read it. Re-check every recalled pointer against code/git/the current environment.- Before a deliberate compact, clear, or new thread, sync once: scan the task;
dedup/update; refresh
project; promote only reusablefeedback; save durablereferencepointers; archive/delete stale or completed transient state; runengramory_check.pyandengramory_doctor.py; then confirm a cold-started agent could continue from the repo plus memory alone. - After writing/syncing, report
added,updated,archived, andskipped(with reasons; identify any deletion underarchived), plus index lines/bytes and the check result. Hooks may remind or gate; they do not perform this semantic sync automatically. - Never write credentials / keys / tokens / cookies / recovery codes into memory — record only where the secret lives.
- Keep
MEMORY.mdsmall. Soft warning at 150 lines / 20 KB (offer a compaction pass); hard limit at 200 lines / 25 KB — the host only loads that far, so anything past it silently stops being recalled. Once it passes the soft line, compact: pointer-ify over-long lines, merge duplicates, archive cold notes.
Full protocol & rationale: the engramory SKILL.md.
Codex-specific wiring:
- Keep this Engramory store separate from Codex native Memories; Codex native Memories are generated state, while Engramory is a user-auditable plain folder.
- Capture mode is
explicit:explicitsyncs on request or at a continuity boundary;assistedalso asks Codex to sync proactively at meaningful milestones. Neither mode silently invents a semantic summary. - If you edit
.engramory-memory/MEMORY.mdand no pre-write hook is installed, runpython .agents/skills/engramory/tools/engramory_check.py .engramory-memory/MEMORY.mdafter the write; compact immediately if it reportsOVER. - Codex lifecycle hooks were not installed. Before compact, clear, or a fresh thread, explicitly run the Engramory sync workflow from the protocol.
- Full protocol reference:
.agents/skills/engramory/SKILL.md. - Asked to check, repair, or upgrade this Engramory install itself? Follow
.agents/skills/engramory/AGENT-SETUP.md— it is the procedure for that, and it is not optional guidance: it exists because agents reliably get this wrong unprompted.
Language
Write new or updated Engramory index entries and memory bodies in Simplified Chinese by
default. Keep filenames, frontmatter keys (name, type, created, updated), memory
types (user, feedback, project, reference), and required validator labels
(Why:, How to apply:) in English.