Files
syops/AGENTS.md
hugo c3eef5cf20 feat(rpa): 恢复FREIGHT_RPA命名空间统一运行目录并完成收料部署对齐与readiness加固
- AGENTS.md §8.1 红线改写:env 命名空间恢复 FREIGHT_RPA_*,SHIPPING_NOTICE_RPA_* 一刀切废弃、不设兼容层
- 全仓机械前缀替换(70 文件)并删除兼容层;4 个既有基线测试失败一并清零(过期桩/存储隔离/排程 fail-fast 接线)
- 运行期数据目录统一 freight_rpa/{inventory,receipt,common}:settings 默认、4 个 env、2 个 ps1 三侧一致
- 代码目录 scripts/rpa 更名 scripts/freight_rpa 与数据根对齐;全仓路径引用同步,README 部署走查与升级小节
- 收料部署对齐库存:计划任务注册脚本(独立任务名)、可选 -SessionReuse 会话复用、DSV 老别名链移除
- readiness 加固:排程离线立即 failed(不挂 awaiting);无 Redis 时追加进程内存储原因码与本地测试指引
- DSV 会话准备遇 SSO 重定向中止时改走自动登录,首源不再因未登录判死
2026-09-19 09:49:25 +08:00

21 KiB
Raw Permalink Blame History

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 快速建立全局认知。核心包含三要素:

  1. 用途:本文件在业务流程中的职责。
  2. 依赖关系:主要引用的上游模块(列关键即可)。
  3. 逻辑关系:与上下游文件如何协作(数据流转或调用关系)。 (前端写在文件/Script首行块注释,后端使用模块级 docstring)

5.2 函数与工具层注释(面向 AI 调用)

每个核心函数定义上方必须有注释。极其重要:如果该函数是被大模型调用的 Agent Tool,其注释将直接影响 AI 的判断。

  1. 用途与触发时机:解决什么问题。作为 AI 工具时,必须用大白话写明【AI 触发时机】。
  2. 核心逻辑:关键步骤与外部通讯流。
  3. 参数与输出约束:除常规类型外,必须说明业务约束(如“禁止传入省份”、“必须返回 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:feat fix docs style refactor perf test build ci chore revert。
  • 禁止无语义提交(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 流程见项目 Skill add-i18n-keys 与 docs/skills/add-i18n-keys-skill.md。
  • 📡 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/ 根下,按 inventory/、receipt/、common/ 分域(common 仅放跨 Worker 共享物,如 browser_profile)。
  • 跨环境一致性:.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. 文档索引(权威来源)

主题 文档
文档总索引 docs/README.md
项目上下文 / 架构 / 数据模型 docs/project_context.md
需求文档 docs/demand.md
技术架构文档 docs/tec.md
功能清单 docs/funclist.md
新人环境搭建 / 分支原则 docs/新人环境搭建与配置文档.md
发布流程(dev→test→prod) docs/convention/release_workflow.md · docs/convention/开发标准流程.md
提交规范 docs/convention/COMMIT_CONVENTION.md
Git Hooks docs/convention/GIT_HOOKS.md
环境变量 docs/convention/env_loading_priority.md · docs/convention/环境变量规则.md
知识库部署 docs/knowledge_base_runtime_deploy.md
Excel/CSV 切块与 Dify 分段 docs/kb-excel-dify-chunking.md
FAQ 缓存 / 热点发现运维 docs/faq_cache_ops_manual.md
测试计划 docs/test_plan_matrix.md
前端架构规范 docs/refactor/frontend_architecture_refactor.md
错误处理规范 docs/convention/error_handling.md
Cursor Skills 索引 docs/skills/README.md
前端四语言 i18n Skill docs/skills/add-i18n-keys-skill.md
发布说明 Skill docs/skills/release-notes-skill.md
业务域文档索引 docs/features/README.md
货代发货通知 docs/features/shipping-notice/technical.md
文件检核 docs/features/file-check/technical.md
Agent 应用管理(设计) docs/platform/agent_application_management.md
Agent 应用管理(实现) docs/platform/agent_application_management_implementation.md

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.md is 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 frontmatter name / description (a sharp one-line hook) / type (user | feedback | project | reference) / created + updated (YYYY-MM-DD) / optional scope (global | repo — how far the fact reaches; label it only when you know). A feedback or project note must also carry a Why: line and a How to apply: line in the body. Add one pointer line to MEMORY.md. Delete memories that turn out wrong.
  • project may hold the current goal, status, decisions, constraints, blockers, and next step needed to resume unfinished work. feedback is 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 reusable feedback; save durable reference pointers; archive/delete stale or completed transient state; run engramory_check.py and engramory_doctor.py; then confirm a cold-started agent could continue from the repo plus memory alone.
  • After writing/syncing, report added, updated, archived, and skipped (with reasons; identify any deletion under archived), 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.md small. 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: explicit syncs on request or at a continuity boundary; assisted also asks Codex to sync proactively at meaningful milestones. Neither mode silently invents a semantic summary.
  • If you edit .engramory-memory/MEMORY.md and no pre-write hook is installed, run python .agents/skills/engramory/tools/engramory_check.py .engramory-memory/MEMORY.md after the write; compact immediately if it reports OVER.
  • 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.