agentleFS
konglong87konglong87/enjoy_harness_ai/skills/harness-config/SKILL.md

harness-config

Skill0 starsChanged 8 months agoMITView on GitHub

配置文件读取和验证技能,确保用户配置正确且完整

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

harness-config 配置读取与验证技能

核心能力

  1. 读取用户配置文件
  2. 验证核心配置项
  3. 应用高级配置默认值
  4. 提供友好的错误提示
  5. 生成配置验证报告

前置条件

  • 配置文件存在:.EnjoyHarness/CONFIG.md

执行步骤

Step 1: 检查配置文件是否存在

使用 Bash 工具执行:

if [ ! -f ".EnjoyHarness/CONFIG.md" ]; then
  echo ""
  echo "❌ 错误: 未找到配置文件 .EnjoyHarness/CONFIG.md"
  echo ""
  echo "💡 请执行以下操作:"
  echo ""
  echo "1. 复制示例配置文件:"
  echo "  cp docs/examples/CONFIG.example.md .EnjoyHarness/CONFIG.md"
  echo ""
  echo "2. 编辑配置文件,设置你的 claude_command:"
  echo "  nano .EnjoyHarness/CONFIG.md"
  echo ""
  echo "3. 重新运行此技能"
  echo ""
  exit 1
fi

echo "✅ 配置文件存在"

Step 2: 读取配置文件

使用 Read 工具读取:.EnjoyHarness/CONFIG.md

Step 3: 验证核心配置项

检查必填项:

检查项 1: claude_command

CLAUDE_CMD=$(grep "^claude_command:" .EnjoyHarness/CONFIG.md | sed 's/claude_command: *//' | tr -d '"' | tr -d "'")

if [ -z "$CLAUDE_CMD" ]; then
  echo ""
  echo "❌ 错误: 配置文件缺少必填项 'claude_command'"
  echo ""
  echo "💡 请在 .EnjoyHarness/CONFIG.md 中添加:"
  echo ""
  echo "  claude_command: \"你的实际命令\""
  echo ""
  echo "示例:"
  echo "  claude_command: \"ccc\""
  echo "  claude_command: \"claude\""
  echo "  claude_command: \"/usr/local/bin/claude\""
  echo ""
  exit 1
fi

echo "✅ claude_command: $CLAUDE_CMD"

检查项 2: tasks_per_session

TASKS_PER_SESSION=$(grep "^tasks_per_session:" .EnjoyHarness/CONFIG.md | sed 's/tasks_per_session: *//')

if [ -z "$TASKS_PER_SESSION" ]; then
  echo ""
  echo "❌ 错误: 配置文件缺少必填项 'tasks_per_session'"
  echo ""
  echo "💡 请在 .EnjoyHarness/CONFIG.md 中添加:"
  echo ""
  echo "  tasks_per_session: 5"
  echo ""
  echo "建议值: 3-10"
  echo " - 简单任务: 8-10"
  echo " - 复杂任务: 3-5"
  echo ""
  exit 1
fi

# 验证数值范围
if ! [[ "$TASKS_PER_SESSION" =~ ^[0-9]+$ ]] || [ "$TASKS_PER_SESSION" -lt 1 ] || [ "$TASKS_PER_SESSION" -gt 100 ]; then
  echo ""
  echo "❌ 错误: tasks_per_session 的值无效: $TASKS_PER_SESSION"
  echo ""
  echo "💡 请设置为 1-100 之间的整数"
  echo " 示例: tasks_per_session: 5"
  echo ""
  exit 1
fi

echo "✅ tasks_per_session: $TASKS_PER_SESSION"

检查项 3: 用户身份信息

USER_NAME=$(grep "^user_name:" .EnjoyHarness/CONFIG.md | sed 's/user_name: *//' | tr -d '"' | tr -d "'")
USER_PHONE=$(grep "^user_phone:" .EnjoyHarness/CONFIG.md | sed 's/user_phone: *//' | tr -d '"' | tr -d "'")
USER_EMAIL=$(grep "^user_email:" .EnjoyHarness/CONFIG.md | sed 's/user_email: *//' | tr -d '"' | tr -d "'")

if [ -z "$USER_NAME" ]; then
  USER_NAME="$(git config user.name 2>/dev/null || true)"
fi
if [ -z "$USER_EMAIL" ]; then
  USER_EMAIL="$(git config user.email 2>/dev/null || true)"
fi

if [ -z "$USER_NAME" ] || [ -z "$USER_EMAIL" ]; then
  echo ""
  echo "❌ 错误: 用户身份信息不完整"
  echo ""
  echo "💡 请在 .EnjoyHarness/CONFIG.md 中添加:"
  echo "  user_name: \"你的姓名\""
  echo "  user_email: \"your@email.com\""
  echo "  user_phone: \"你的手机号\"(可选)"
  echo ""
  echo "或者先配置 git identity:"
  echo "  git config user.name \"你的姓名\""
  echo "  git config user.email \"your@email.com\""
  echo ""
  exit 1
fi

echo "✅ user_name: $USER_NAME"
echo "✅ user_phone: ${USER_PHONE:-未配置}"
echo "✅ user_email: $USER_EMAIL"

Step 4: 应用高级配置默认值

读取高级配置(可选):

# Token 使用率阈值(默认 60%)
TOKEN_THRESHOLD=$(grep "^token_threshold:" .EnjoyHarness/CONFIG.md | sed 's/token_threshold: *//' | tr -d '%')
if [ -z "$TOKEN_THRESHOLD" ]; then
  TOKEN_THRESHOLD=60
  echo "ℹ️ token_threshold: 使用默认值 $TOKEN_THRESHOLD%"
else
  echo "✅ token_threshold: $TOKEN_THRESHOLD%"
fi

# 任务复杂度阈值(默认 6)
TASK_COMPLEXITY=$(grep "^task_complexity_threshold:" .EnjoyHarness/CONFIG.md | sed 's/task_complexity_threshold: *//')
if [ -z "$TASK_COMPLEXITY" ]; then
  TASK_COMPLEXITY=6
  echo "ℹ️ task_complexity_threshold: 使用默认值 $TASK_COMPLEXITY"
else
  echo "✅ task_complexity_threshold: $TASK_COMPLEXITY"
fi

# 连续任务数上限(默认 5)
CONSECUTIVE_LIMIT=$(grep "^consecutive_tasks_limit:" .EnjoyHarness/CONFIG.md | sed 's/consecutive_tasks_limit: *//')
if [ -z "$CONSECUTIVE_LIMIT" ]; then
  CONSECUTIVE_LIMIT=5
  echo "ℹ️ consecutive_tasks_limit: 使用默认值 $CONSECUTIVE_LIMIT"
else
  echo "✅ consecutive_tasks_limit: $CONSECUTIVE_LIMIT"
fi

# 错误率阈值(默认 30%)
ERROR_RATE=$(grep "^error_rate_threshold:" .EnjoyHarness/CONFIG.md | sed 's/error_rate_threshold: *//' | tr -d '%')
if [ -z "$ERROR_RATE" ]; then
  ERROR_RATE=30
  echo "ℹ️ error_rate_threshold: 使用默认值 $ERROR_RATE%"
else
  echo "✅ error_rate_threshold: $ERROR_RATE%"
fi

# 绝对上限(默认 10)
ABSOLUTE_LIMIT=$(grep "^absolute_limit:" .EnjoyHarness/CONFIG.md | sed 's/absolute_limit: *//')
if [ -z "$ABSOLUTE_LIMIT" ]; then
  ABSOLUTE_LIMIT=10
  echo "ℹ️ absolute_limit: 使用默认值 $ABSOLUTE_LIMIT"
else
  echo "✅ absolute_limit: $ABSOLUTE_LIMIT"
fi

# brainstorm 用户参与开关(默认 false)
BRAINSTORM_USER_PARTICIPATION=$(grep "^brainstorm_user_participation:" .EnjoyHarness/CONFIG.md | sed 's/brainstorm_user_participation: *//' | tr -d '"' | tr -d "'")
if [ -z "$BRAINSTORM_USER_PARTICIPATION" ]; then
  BRAINSTORM_USER_PARTICIPATION=false
  echo "ℹ️ brainstorm_user_participation: 使用默认值 $BRAINSTORM_USER_PARTICIPATION"
elif [ "$BRAINSTORM_USER_PARTICIPATION" != "true" ] && [ "$BRAINSTORM_USER_PARTICIPATION" != "false" ]; then
  echo ""
  echo "❌ 错误: brainstorm_user_participation 的值无效: $BRAINSTORM_USER_PARTICIPATION"
  echo ""
  echo "💡 请设置为 true 或 false"
  echo " 示例: brainstorm_user_participation: false"
  echo ""
  exit 1
else
  echo "✅ brainstorm_user_participation: $BRAINSTORM_USER_PARTICIPATION"
fi

Step 5: 验证命令是否可用

# 检查用户配置的命令是否存在
if ! command -v "$CLAUDE_CMD" &> /dev/null; then
  echo ""
  echo "❌ 错误: 命令 '$CLAUDE_CMD' 不存在或不可执行"
  echo ""
  echo "💡 请检查:"
  echo " 1. 命令是否正确(区分大小写)"
  echo " 2. 命令是否已安装"
  echo " 3. 如果是 alias,请确认当前 shell 环境中有定义"
  echo ""
  echo "验证方法:"
  echo "  which $CLAUDE_CMD"
  echo "  type $CLAUDE_CMD"
  echo ""
  exit 1
fi

echo "✅ 命令验证通过: $CLAUDE_CMD"

Step 6: 生成配置验证报告

使用 Write 工具创建:.EnjoyHarness/CONFIG_VALIDATION_REPORT.md

内容:

---
validated_at: {TIMESTAMP}
status: SUCCESS
---

# 配置验证报告

## 验证时间
{TIMESTAMP}

## 核心配置
- ✅ claude_command: `{CLAUDE_CMD}`
- ✅ tasks_per_session: `{TASKS_PER_SESSION}`

## 高级配置
- ✅ token_threshold: `{TOKEN_THRESHOLD}%`
- ✅ task_complexity_threshold: `{TASK_COMPLEXITY}`
- ✅ consecutive_tasks_limit: `{CONSECUTIVE_LIMIT}`
- ✅ error_rate_threshold: `{ERROR_RATE}%`
- ✅ absolute_limit: `{ABSOLUTE_LIMIT}`
- ✅ user_name: `{USER_NAME}`
- ✅ user_phone: `{USER_PHONE}`
- ✅ user_email: `{USER_EMAIL}`
- ✅ brainstorm_user_participation: `{BRAINSTORM_USER_PARTICIPATION}`

## 命令验证
- ✅ 命令可用: `{CLAUDE_CMD}`

## 验证结果
✅ **配置验证通过**

所有配置项已验证,系统已准备就绪。

Step 7: 输出验证成功信息

echo ""
echo "✅ 配置验证完成"
echo ""
echo "📋 配置摘要:"
echo " - Claude 命令: $CLAUDE_CMD"
echo " - 任务切换阈值: $TASKS_PER_SESSION 个任务"
echo " - Token 阈值: $TOKEN_THRESHOLD%"
echo " - 复杂度阈值: $TASK_COMPLEXITY"
echo " - 连续任务上限: $CONSECUTIVE_LIMIT"
echo " - 错误率阈值: $ERROR_RATE%"
echo " - 绝对上限: $ABSOLUTE_LIMIT 个任务"
echo " - 用户姓名: $USER_NAME"
echo " - 用户手机: ${USER_PHONE:-未配置}"
echo " - 用户邮箱: $USER_EMAIL"
echo " - brainstorm 用户参与: $BRAINSTORM_USER_PARTICIPATION"
echo ""
echo "📁 详细报告: .EnjoyHarness/CONFIG_VALIDATION_REPORT.md"
echo ""

成功标准

  • 配置文件存在
  • 核心配置项完整
  • 高级配置有默认值
  • 命令验证通过
  • 生成验证报告

失败处理

失败场景 1: 配置文件缺失

处理方式:提示用户创建配置文件,提供示例路径

失败场景 2: 核心配置缺失

处理方式:明确提示缺少哪个配置项,提供正确格式示例

失败场景 3: 命令不存在

处理方式:提示验证命令是否正确,提供验证方法

使用示例

示例 1: 首次配置

用户执行: harness-config

AI 输出:
❌ 错误: 未找到配置文件 .EnjoyHarness/CONFIG.md

💡 请执行以下操作:
1. 复制示例配置文件:cp docs/examples/CONFIG.example.md .EnjoyHarness/CONFIG.md
2. 编辑配置文件:nano .EnjoyHarness/CONFIG.md
3. 重新运行此技能

示例 2: 配置验证成功

用户执行: harness-config

AI 输出:
✅ 配置文件存在
✅ claude_command: ccc
✅ tasks_per_session: 5
✅ 命令验证通过: ccc

✅ 配置验证完成

📋 配置摘要:
- Claude 命令: ccc
- 任务切换阈值: 5 个任务
- Token 阈值: 60%
- 复杂度阈值: 6
- 连续任务上限: 5
- 错误率阈值: 30%
- 绝对上限: 10 个任务

📁 详细报告: .EnjoyHarness/CONFIG_VALIDATION_REPORT.md

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.