---
applyTo: "MainShell/Process/**/*.cs,**/*Activity.cs,**/*Workflow*.cs,**/*ProcessService.cs,**/*MotionService.cs"
---

# Workflow Instructions

## Workflow Architecture
This repository uses:
- WorkflowRunner
- AutoProductionWorkflowBuilder
- ActivityAbstractBase
- CompositeActivity
- WorkflowStepIds
- WorkflowStepIdResolver

## 中文说明
流程系统基于现有 Workflow 架构实现，生成代码时应优先复用这些对象和机制。

## Layering Rules
- Activity layer only:
  - calls Service / MotionService / ProcessService
  - writes WorkflowContext
  - returns execution result
- PrepareExecute and AfterExecute only handle pre/post processing
- Core workflow logic must be implemented in Service layer
- Do not place recipe parsing, compensation logic, vision logic, or hardware orchestration in Activity

## 中文说明
分层规则：
- Activity 层只负责调用 Service、写 WorkflowContext、返回执行结果
- `PrepareExecute` 和 `AfterExecute` 只做前后处理
- 核心流程逻辑必须放在 Service 层
- 不要在 Activity 中写配方解析、视觉算法、补偿逻辑、硬件调度

## Routing Rules
- Do not place workflow jump logic in Activity
- Actual workflow transitions must be configured by WorkflowStep
- Normal business branches should use Route / SetRoute
- Failure should only be used for real failures:
  - hardware error
  - timeout
  - communication failure
  - invalid required input
  - unrecoverable process error

## 中文说明
跳转规则：
- 不要在 Activity 中写流程跳转逻辑
- 流程跳转统一由 WorkflowStep 配置
- 正常业务分支优先使用 `Route / SetRoute`
- `Failure` 只用于真正异常，例如硬件错误、超时、通讯失败、关键输入缺失、不可恢复错误

## JumpConditions Rules
- JumpConditions are matched in add order
- More specific branches must be placed first
- Default flow must be placed last

## 中文说明
`JumpConditions` 匹配顺序按添加顺序执行：
- 更具体的条件放前面
- 默认分支放最后

## Service Responsibilities
Service layer should be responsible for:
- reading WorkflowContext
- reading RecipeManager and current recipe
- reading teach data and process parameters
- acquiring hardware via HardwareManager
- validating inputs
- validating hardware state
- validating safety conditions
- executing workflow core steps
- computing business result or compensation result
- determining Route
- returning structured process result

## 中文说明
Service 层职责：
- 读取 `WorkflowContext`
- 读取 `RecipeManager` 和当前配方
- 读取示教数据和工艺参数
- 通过 `HardwareManager` 获取硬件对象
- 校验输入、硬件状态和安全条件
- 执行核心流程步骤
- 计算业务结果或补偿结果
- 决定 `Route`
- 返回结构化结果对象

## Output Preference
When implementing workflow code, prefer:
1. Activity skeleton
2. Service skeleton
3. result object design
4. WorkflowContext write-back fields
5. WorkflowStep routing suggestion
6. JumpConditions ordering suggestion

## 中文说明
实现流程代码时，优先输出：
1. Activity 骨架
2. Service 骨架
3. 结果对象设计
4. WorkflowContext 回写字段
5. WorkflowStep 路由建议
6. JumpConditions 顺序建议
