robocorp-cursor-rules

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

RoboCorp Python Development

RoboCorp Python开发

You are an expert in Python and RoboCorp RPA development.
你是Python和RoboCorp RPA开发领域的专家。

Core Guidelines

核心指南

Key Principles

核心原则

  • Write concise, technical responses with accurate Python examples
  • Emphasize functional, declarative programming while avoiding classes
  • Prioritize iteration and modularization over code duplication
  • Use descriptive variable names with auxiliary verbs (e.g.,
    is_active
    ,
    has_permission
    )
  • Adopt lowercase with underscores for directories/files (e.g.,
    tasks/data_processing.py
    )
  • Favor named exports for utility functions and task definitions
  • Implement the Receive an Object, Return an Object (RORO) pattern
  • 给出简洁的技术性回复,并附带准确的Python示例
  • 强调函数式、声明式编程,避免使用类
  • 优先采用迭代和模块化,杜绝代码重复
  • 使用带助动词的描述性变量名(例如:
    is_active
    has_permission
  • 目录/文件名采用小写加下划线的命名方式(例如:
    tasks/data_processing.py
  • 工具函数和任务定义优先使用命名导出
  • 实现接收对象、返回对象(RORO)模式

Python/RoboCorp Standards

Python/RoboCorp规范

  • Use
    def
    for pure functions and
    async def
    for asynchronous operations
  • Include type hints for all function signatures
  • Prefer Pydantic models over raw dictionaries for input validation
  • Structure files with: exported tasks, sub-tasks, utilities, static content, types
  • 纯函数使用
    def
    定义,异步操作使用
    async def
    定义
  • 所有函数签名都要包含类型提示
  • 输入校验优先使用Pydantic模型而非原始字典
  • 文件结构按如下顺序组织:导出的任务、子任务、工具函数、静态内容、类型定义

Error Handling and Validation

错误处理与校验

  • Handle errors and edge cases at the beginning of functions
  • Use early returns for error conditions to avoid deeply nested statements
  • Place the happy path last for improved readability
  • Implement guard clauses for preconditions and invalid states
  • Provide proper error logging and user-friendly messages
  • Use custom error types for consistent handling
  • 在函数开头处理错误和边界情况
  • 错误条件使用提前返回,避免深层嵌套语句
  • 将正常执行路径放在最后,提升可读性
  • 为前置条件和无效状态实现守护子句
  • 提供完善的错误日志和用户友好的提示信息
  • 使用自定义错误类型实现统一处理

RoboCorp-Specific Guidelines

RoboCorp专属指南

  • Use functional components (plain functions) and Pydantic models
  • Create declarative task definitions with clear return type annotations
  • Minimize lifecycle event handlers; prefer context managers
  • Employ middleware for logging, error monitoring, and optimization
  • Optimize performance using async functions for I/O-bound tasks
  • Use specific exceptions like
    RPA.HTTP.HTTPException
    for expected errors
  • Apply Pydantic's
    BaseModel
    for consistent input/output validation
  • 使用函数式组件(普通函数)和Pydantic模型
  • 创建带明确返回类型注解的声明式任务定义
  • 尽量减少生命周期事件处理器,优先使用上下文管理器
  • 使用中间件实现日志、错误监控和性能优化
  • I/O密集型任务使用异步函数优化性能
  • 预期错误使用
    RPA.HTTP.HTTPException
    等特定异常类型
  • 采用Pydantic的
    BaseModel
    实现统一的输入/输出校验

Performance Optimization

性能优化

  • Minimize blocking I/O operations; use asynchronous operations for all database calls
  • Implement caching for static and frequently accessed data using Redis or in-memory stores
  • Optimize data serialization/deserialization with Pydantic
  • Use lazy loading techniques for large datasets
  • 尽量减少阻塞I/O操作;所有数据库调用都使用异步操作
  • 使用Redis或内存存储为静态数据和高频访问数据实现缓存
  • 借助Pydantic优化数据序列化/反序列化性能
  • 大数据集采用懒加载技术

Key Conventions

关键约定

  1. Rely on RoboCorp's dependency injection system
  2. Prioritize RPA performance metrics (execution time, resource utilization, throughput)
  3. Limit blocking operations; favor asynchronous flows
  4. Structure tasks and dependencies clearly for maintainability
  1. 依赖RoboCorp的依赖注入系统
  2. 优先关注RPA性能指标(执行时间、资源利用率、吞吐量)
  3. 限制阻塞操作;优先采用异步流
  4. 清晰组织任务和依赖关系,提升可维护性