agentleFS
lss486558354-ship-itlss486558354-ship-it/engineering-workflow/.cursor/rules/06-topic-tracing.md

engineering-workflow / rules

Cursor rule0 starsChanged 36 days agoMITView on GitHub

本规则对所有涉及代码的项目生效。agent 在设计和实现模块时必须遵循以下架构约束。 本规则对所有涉及代码的项目生效,但根据项目类型有不同强度: 当项目为纯工具/配置类(如本模板项目本身),agent 不应强制要求话题通信架构,仅保持日志和 MD5 留痕即可。 所有模块间数据传递统一使用话题机制,禁止直接函数调用传数据(内部纯计算除外)。 无论哪种方案,必须满足: - 话题可枚举(有 topic registry) - 消息可回放(有持久化或日志) - 订阅关系可查(运行时可 dump) 结构化数据为 JSON,至少包含:触发源、变更前后值、关联 trace_id。 对以下对象维护 MD5 校验记录: MD5 日志格式(append-only): 存储位置:项目根目录 .trace/integrity.log

The file

Files
06-topic-tracing.md

话题通信 + 全量溯源(强制架构约束)

本规则对所有涉及代码的项目生效。agent 在设计和实现模块时必须遵循以下架构约束。

作用域

本规则对所有涉及代码的项目生效,但根据项目类型有不同强度:

project-profile.type话题通信全量日志MD5 完整性
web-frontend / web-backend / mobile / desktop强制强制强制
library / cli-tool / other可选(模块 ≥3 时建议启用)强制强制
纯脚本/配置项目(无 modules 或 modules ≤2)不要求建议建议

当项目为纯工具/配置类(如本模板项目本身),agent 不应强制要求话题通信架构,仅保持日志和 MD5 留痕即可。

模块间通信:话题(Topic / Pub-Sub)

所有模块间数据传递统一使用话题机制,禁止直接函数调用传数据(内部纯计算除外)。

话题模型

Publisher → Topic(name, schema) → Subscriber(s)

每条消息结构:
{
  topic: string,          // 话题名,如 "order.created", "sensor.imu"
  timestamp: ISO8601,     // 发布时间
  source: string,         // 发布者模块标识
  payload: any,           // 业务数据
  trace_id: string,       // 链路追踪 ID(贯穿整条调用链)
  seq: number             // 该话题上的序列号
}

实现选择(按项目需求选型)

场景推荐方案
机器人/嵌入式/多进程ROS 2 topic(直接用 rclpy/rclcpp)
Web/微服务Redis Pub/Sub / NATS / Kafka
单进程多模块内置 EventBus(自实现,≤50 行)
桌面/CLI 工具基于文件的 topic log(append-only)

无论哪种方案,必须满足:

  • 话题可枚举(有 topic registry)
  • 消息可回放(有持久化或日志)
  • 订阅关系可查(运行时可 dump)

全量日志:一切留痕

必须记录的事件

类别内容示例
状态变更任何状态机跳转order.status: pending → paid
数据变更CRUD 操作user.email updated, old=x, new=y
话题消息每条 pub/sub 消息topic log 本身
文件变更文件创建/修改/删除路径 + 操作 + MD5
外部调用API/DB/第三方request + response 摘要
错误所有 catch 到的异常stack + context

日志格式

[timestamp] [level] [module] [trace_id] message {structured_data}

结构化数据为 JSON,至少包含:触发源、变更前后值、关联 trace_id。

MD5 完整性日志

对以下对象维护 MD5 校验记录:

  • 所有配置文件 — 启动时计算 + 变更时重算
  • 构建产物 — 构建完成时记录
  • 数据文件 — 写入/导入时记录
  • 部署包 — 发布时记录

MD5 日志格式(append-only):

[timestamp] [event] [path] [md5] [operator]

存储位置:项目根目录 .trace/integrity.log

溯源基础设施

每个项目必须包含:

.trace/
├── topics.registry.json   # 话题注册表(名称 + schema + publisher + subscribers)
├── integrity.log          # MD5 完整性日志
└── events/                # 事件日志(按日期分文件)
    └── YYYY-MM-DD.jsonl

agent 实施要求

  1. 新建项目时:自动创建 .trace/ 目录结构和 topic registry
  2. 新增模块时:检查其对外通信是否走话题,不走则要求重构
  3. 新增状态时:确保状态变更有日志记录
  4. 修改文件时:更新 integrity.log 中的 MD5
  5. 代码审查时:检查是否有"暗通道"(模块直接调用传数据绕过话题)

禁止行为

  • 禁止模块间通过全局变量/单例共享状态(必须通过话题)
  • 禁止状态变更不写日志
  • 禁止文件操作不记录 MD5
  • 禁止删除或截断 .trace/ 下的日志文件

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.