sop-engine
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSOP Engine
SOP 引擎
Execute Standard Operating Procedures with built-in approval gates, state management, and audit logging.
执行内置审批关卡、状态管理和审计日志的标准操作流程(SOP)。
When to Use
适用场景
- Run multi-step procedures that require human approval between steps
- Execute complex workflows that span multiple agent sessions
- Track and audit compliance procedures
- Create reusable workflow templates
- Implement approval-required workflows (e.g., deployments, changes)
- 运行步骤间需要人工审批的多步骤流程
- 执行跨多个Agent会话的复杂工作流
- 跟踪和审计合规流程
- 创建可复用的工作流模板
- 实现需要审批的工作流(如部署、变更)
Concepts
核心概念
SOP (Standard Operating Procedure)
SOP(标准操作流程)
A defined workflow with:
- Steps: Sequential actions to perform
- Approval Gates: Points where human approval is required
- State: Persisted between steps
- Audit Log: Complete execution history
已定义的工作流,包含:
- 步骤:需执行的顺序操作
- 审批关卡:需要人工审批的节点
- 状态:步骤间持久化保存
- 审计日志:完整的执行历史记录
Execution Modes
执行模式
- - Execute all steps without approval
auto - - Request approval before starting, then execute all steps
supervised - - Request approval before each step
step_by_step - - High priority = auto, Normal/Low = supervised
priority_based
- - 无需审批执行所有步骤
auto - - 开始前请求审批,之后执行所有步骤
supervised - - 每个步骤执行前请求审批
step_by_step - - 高优先级=自动执行,普通/低优先级=监督模式
priority_based
Triggers
触发方式
- - Triggered by name
manual - - Scheduled execution (expression)
cron - - HTTP trigger
webhook
- - 通过名称手动触发
manual - - 定时执行(表达式)
cron - - HTTP触发
webhook
Installation
安装
No additional installation required. Uses built-in tools: , , .
jqcurlgit无需额外安装。使用内置工具:、、。
jqcurlgitQuick Start
快速开始
1. Create an SOP
1. 创建SOP
Create :
sops/my-sop.mdmarkdown
---
name: deploy-frontend
description: Deploy frontend to staging
version: "1.0.0"
priority: high
execution_mode: supervised
triggers:
- type: manual
- type: cron
expression: "0 9 * * *"
---创建 :
sops/my-sop.mdmarkdown
---
name: deploy-frontend
description: Deploy frontend to staging
version: "1.0.0"
priority: high
execution_mode: supervised
triggers:
- type: manual
- type: cron
expression: "0 9 * * *"
---Deploy Frontend to Staging
Deploy Frontend to Staging
Step 1: Build the Project
Step 1: Build the Project
bash
cd /job && npm run buildbash
cd /job && npm run buildStep 2: Run Tests
Step 2: Run Tests
bash
cd /job && npm testbash
cd /job && npm testStep 3: Deploy (requires approval)
Step 3: Deploy (requires approval)
bash
echo "Deploying to staging..."bash
echo "Deploying to staging..."Step 4: Verify
Step 4: Verify
bash
curl -s https://staging.example.com/healthundefinedbash
curl -s https://staging.example.com/healthundefined2. List Available SOPs
2. 列出可用SOP
bash
sop-listbash
sop-list3. Execute an SOP
3. 执行SOP
bash
sop-execute deploy-frontendbash
sop-execute deploy-frontend4. Approve a Step
4. 审批步骤
bash
sop-approve <run-id>bash
sop-approve <run-id>5. Check Status
5. 检查状态
bash
sop-status <run-id>bash
sop-status <run-id>Commands
命令说明
sop-list
sop-list
List all available SOPs.
bash
sop-list列出所有可用的SOP。
bash
sop-listsop-execute
sop-execute
Start an SOP execution.
bash
sop-execute <sop-name>
sop-execute <sop-name> --payload '{"key": "value"}'启动SOP执行。
bash
sop-execute <sop-name>
sop-execute <sop-name> --payload '{"key": "value"}'sop-approve
sop-approve
Approve the next step in a running SOP.
bash
sop-approve <run-id>审批正在运行的SOP的下一步。
bash
sop-approve <run-id>sop-reject
sop-reject
Reject and cancel a running SOP.
bash
sop-reject <run-id> --reason "Not ready for deployment"拒绝并取消正在运行的SOP。
bash
sop-reject <run-id> --reason "Not ready for deployment"sop-status
sop-status
Check the status of an SOP run.
bash
sop-status <run-id>检查SOP运行的状态。
bash
sop-status <run-id>sop-runs
sop-runs
List all SOP runs (active and completed).
bash
sop-runs
sop-runs --sop <sop-name>列出所有SOP运行记录(活跃和已完成)。
bash
sop-runs
sop-runs --sop <sop-name>SOP Definition Format
SOP定义格式
SOPs are defined in markdown files with YAML frontmatter:
markdown
---
name: <unique-name>
description: <what this does>
version: "1.0.0"
priority: normal # low, normal, high, critical
execution_mode: supervised # auto, supervised, step_by_step, priority_based
triggers:
- type: manual
- type: cron
expression: "0 9 * * *"
- type: webhook
path: /webhook/deploy
---SOP通过带有YAML前置元数据的Markdown文件定义:
markdown
---
name: <unique-name>
description: <what this does>
version: "1.0.0"
priority: normal # low, normal, high, critical
execution_mode: supervised # auto, supervised, step_by_step, priority_based
triggers:
- type: manual
- type: cron
expression: "0 9 * * *"
- type: webhook
path: /webhook/deploy
---Title
Title
Step 1: Description
Step 1: Description
bash
command to runbash
command to runStep 2: Description (requires approval)
Step 2: Description (requires approval)
bash
another commandundefinedbash
another commandundefinedExecution Flow
执行流程
┌─────────────────┐
│ sop-execute │
│ (start run) │
└────────┬────────┘
│
▼
┌────────────┐
│ Auto Mode? │───Yes──► Execute All Steps
└─────┬──────┘ and Complete
│ No
▼
┌────────────┐
│ Supervised │───Wait for──►┌─────────────┐
│ Mode │ Approval │sop-approve │
└─────┬──────┘ └──────┬──────┘
│ │
▼ ▼
┌────────────┐ Execute Remaining
│StepByStep │───Wait for──► Steps One-by-One
│ Mode │ Approval with Approval Each
└───────────┘┌─────────────────┐
│ sop-execute │
│ (start run) │
└────────┬────────┘
│
▼
┌────────────┐
│ Auto Mode? │───Yes──► Execute All Steps
└─────┬──────┘ and Complete
│ No
▼
┌────────────┐
│ Supervised │───Wait for──►┌─────────────┐
│ Mode │ Approval │sop-approve │
└─────┬──────┘ └──────┬──────┘
│ │
▼ ▼
┌────────────┐ Execute Remaining
│StepByStep │───Wait for──► Steps One-by-One
│ Mode │ Approval with Approval Each
└───────────┘State Management
状态管理
State is persisted in :
~/.thepopebot/sop-state/<run-id>.jsonjson
{
"run_id": "run-abc123",
"sop_name": "deploy-frontend",
"status": "running",
"current_step": 2,
"started_at": "2024-01-15T09:00:00Z",
"payload": {"key": "value"},
"history": [
{"step": 1, "status": "completed", "output": "...", "timestamp": "..."},
{"step": 2, "status": "pending_approval", "output": "...", "timestamp": "..."}
]
}状态持久化存储在 中:
~/.thepopebot/sop-state/<run-id>.jsonjson
{
"run_id": "run-abc123",
"sop_name": "deploy-frontend",
"status": "running",
"current_step": 2,
"started_at": "2024-01-15T09:00:00Z",
"payload": {"key": "value"},
"history": [
{"step": 1, "status": "completed", "output": "...", "timestamp": "..."},
{"step": 2, "status": "pending_approval", "output": "...", "timestamp": "..."}
]
}Audit Logging
审计日志
All SOP executions are logged to :
~/.thepopebot/sop-audit/- - Full execution record
<run-id>.json - - Step-by-step output
<run-id>.log
所有SOP执行记录都会日志到 :
~/.thepopebot/sop-audit/- - 完整执行记录
<run-id>.json - - 分步执行输出
<run-id>.log
Workflow Examples
工作流示例
Deploy with Approval
带审批的部署流程
markdown
---
name: deploy-production
description: Deploy to production with approval
priority: critical
execution_mode: step_by_step
triggers:
- type: manual
---markdown
---
name: deploy-production
description: Deploy to production with approval
priority: critical
execution_mode: step_by_step
triggers:
- type: manual
---Production Deployment
Production Deployment
Step 1: Run Tests
Step 1: Run Tests
bash
npm testbash
npm testStep 2: Build
Step 2: Build
bash
npm run buildbash
npm run buildStep 3: Deploy (APPROVAL REQUIRED)
Step 3: Deploy (APPROVAL REQUIRED)
bash
./deploy.sh productionbash
./deploy.sh productionStep 4: Verify
Step 4: Verify
bash
curl -s https://production.example.com/healthundefinedbash
curl -s https://production.example.com/healthundefinedData Processing Pipeline
数据处理流水线
markdown
---
name: process-daily-data
description: Daily data processing pipeline
priority: high
execution_mode: auto
triggers:
- type: cron
expression: "0 2 * * *"
---markdown
---
name: process-daily-data
description: Daily data processing pipeline
priority: high
execution_mode: auto
triggers:
- type: cron
expression: "0 2 * * *"
---Daily Data Processing
Daily Data Processing
Step 1: Fetch Data
Step 1: Fetch Data
bash
curl -o data/raw.json https://api.example.com/databash
curl -o data/raw.json https://api.example.com/dataStep 2: Transform
Step 2: Transform
bash
node transform.js data/raw.json > data/processed.jsonbash
node transform.js data/raw.json > data/processed.jsonStep 3: Validate
Step 3: Validate
bash
node validate.js data/processed.jsonbash
node validate.js data/processed.jsonStep 4: Archive
Step 4: Archive
bash
mv data/processed.json archive/$(date +%Y%m%d).jsonundefinedbash
mv data/processed.json archive/$(date +%Y%m%d).jsonundefinedBest Practices
最佳实践
- Use descriptive step titles - Makes approval prompts clearer
- Keep steps atomic - Each step should do one thing
- Include rollback commands - For critical operations
- Add verification steps - Always confirm success
- Use appropriate modes - Production = step_by_step, dev = auto
- Document prerequisites - List what needs to be true before execution
- 使用描述性的步骤标题 - 让审批提示更清晰
- 保持步骤原子化 - 每个步骤只做一件事
- 包含回滚命令 - 针对关键操作
- 添加验证步骤 - 始终确认执行成功
- 使用合适的执行模式 - 生产环境=step_by_step,开发环境=auto
- 记录前置条件 - 列出执行前需要满足的条件
Limitations
局限性
- Current implementation uses shell/bash - not all SOPs can be expressed this way
- State is local to the agent - not shared across different agent instances
- Approval requires human intervention via CLI
- 当前实现使用shell/bash - 并非所有SOP都能通过这种方式表达
- 状态仅存储在本地Agent中 - 无法在不同Agent实例间共享
- 审批需要通过CLI进行人工干预