Skip to content

Autonomous Action Template

用途: 自主行动模板,用于 Autonomous 类型 Skill 的具体行动

模板

markdown
# Action: {Action Name}

> **Skill**: {Skill Name}
> **Action Type**: {Analysis|Execution|Verification}
> **Estimated Duration**: {X minutes}

## Description

详细描述这个行动的目的和功能

## Trigger Conditions

| Condition | Description | Check Method |
|-----------|-------------|--------------|
| condition1 | 描述 | 如何检查 |
| condition2 | 描述 | 如何检查 |

## Input Parameters

| Parameter | Type | Required | Description | Default |
|-----------|------|----------|-------------|---------|
| param1 | string | Yes | 参数描述 | - |
| param2 | number | No | 参数描述 | 42 |
| param3 | array | No | 参数描述 | [] |

## Output

| Field | Type | Description |
|-------|------|-------------|
| result1 | string | 结果描述 |
| result2 | object | 结果描述 |
| success | boolean | 行动是否成功 |

## Execution Logic

### Step 1: {Step Name}

**Description**: 步骤描述

**Implementation**:
```typescript
// 示例代码
const step1Result = await doSomething(input);
if (!step1Result) {
  throw new Error('Step 1 failed');
}

Validation: 如何验证步骤成功

Step 2:

Description: 步骤描述

Implementation:

typescript
// 示例代码
const step2Result = await process(step1Result);

Validation: 如何验证步骤成功

Step 3:

...

Error Handling

ErrorCauseHandlingRetry
ErrorType1原因描述处理方式Yes/No
ErrorType2原因描述处理方式Yes/No

Error Recovery Logic:

typescript
try {
  return await execute();
} catch (error) {
  if (error instanceof RecoverableError) {
    return await recover(error);
  }
  throw error;
}

Side Effects

EffectDescriptionMitigation
Side effect 1描述缓解措施
Side effect 2描述缓解措施

Dependencies

DependencyTypeVersionDescription
dep1internal-内部依赖描述
dep2external^1.0.0外部依赖描述

Testing

Test Cases

CaseInputExpected Output
Normal case{param: "value"}{result: "expected"}
Edge case{param: null}{result: "default"}
Error case{param: "invalid"}Throws Error

Test Implementation

typescript
describe('ActionName', () => {
  it('should handle normal case', async () => {
    const result = await actionName({ param: 'value' });
    expect(result).toEqual({ result: 'expected' });
  });

  it('should handle edge case', async () => {
    const result = await actionName({ param: null });
    expect(result).toEqual({ result: 'default' });
  });

  it('should throw on invalid input', async () => {
    await expect(actionName({ param: 'invalid' }))
      .rejects.toThrow(Error);
  });
});

Metrics

MetricTypeUnit
durationhistogrammilliseconds
success_rategaugepercentage
error_countcountercount

Example Usage

typescript
// 基本使用
const result = await actionName({
  param1: 'value1',
  param2: 100
});

console.log(result);

// 带重试
const result = await actionName.withRetry({
  param1: 'value1'
}, { maxRetries: 3 });

// 带回调
await actionName.withCallback({
  param1: 'value1'
}, {
  onProgress: (progress) => console.log(progress),
  onComplete: (result) => console.log('Done', result)
});

## 使用说明

1. **触发**: skill-generator Phase 3 (Autonomous 模式)
2. **输入**: Phase 2 skill-config.json
3. **输出**: actions/{action-name}.md
4. **命名**: 使用动词-名词格式 (如 collect-context.md)

---

## 示例

### 简化示例

```markdown
# Action: quick-scan

> **Skill**: review-code
> **Action Type**: Analysis
> **Estimated Duration**: 5 minutes

## Description

快速扫描目标代码,识别高风险区域,为深度审查提供焦点

## Trigger Conditions

| Condition | Description | Check Method |
|-----------|-------------|--------------|
| context_collected | 上下文收集完成 | state.context != null |
| target_exists | 目标路径有效 | file exists check |

## Input Parameters

| Parameter | Type | Required | Description | Default |
|-----------|------|----------|-------------|---------|
| files | array | Yes | 要扫描的文件列表 | - |
| dimensions | array | No | 要检查的维度 | ["all"] |
| risk_threshold | number | No | 风险阈值 | 0.5 |

## Output

| Field | Type | Description |
|-------|------|-------------|
| risk_areas | array | 高风险区域列表 |
| scan_summary | object | 扫描摘要 |
| recommendations | array | 建议的审查重点 |

## Execution Logic

### Step 1: 按文件类型分组

```typescript
const groups = groupBy(files, f => f.extension);
// ts/tsx -> TypeScript review rules
// py -> Python review rules

Step 2: 应用快速检查规则

typescript
const risks = [];
for (const file of files) {
  const fileRisks = applyQuickChecks(file);
  risks.push(...fileRisks);
}

Step 3: 聚合和排序

typescript
const aggregated = aggregateByLocation(risks);
const sorted = sortBySeverity(aggregated);

Error Handling

ErrorCauseHandlingRetry
FileAccessError文件无法读取跳过文件,记录警告No
ParseError代码解析失败标记为需要人工审查No

Testing

CaseInputExpected Output
Normal10 filesrisk_areas non-empty
Empty0 filesrisk_areas empty
ParseErrorInvalid codeArea marked for manual review

Released under the MIT License.