Skill: linglin6/agent-evolution (version 1.0.0)

--- name: agent-evolution description: Agent 行为固化与进化系统。追踪规则执行、检测行为模式、维护身份连续性。用于：让 agent 的行为规则从"写下来"变成"做到了"。当 agent 需要自我改进、行为追踪、角色一致性、重复检测时激活。与 Memelord/memory-tools 互补：它们管记忆，本 skill 管行为。 --- # agent-evolution Agent 行为固化与进化系统。追踪规则执行、检测行为模式、维护身份连续性。用于：让 agent 的行为规则从"写下来"变成"做到了"。当 agent 需要自我改进、行为追踪、角色一致性、重复检测时激活。与 Memelord/memory-tools 互补：它们管记忆，本 skill 管行为。 ## 使用 所有命令通过 `node scripts/evolution.js <command> [args]` 执行，输出均为 JSON。 存储路径：`~/.openclaw/workspace/.agent-evolution/state.json` ## 模块 ### 行为追踪器 追踪规则执行与违反，计算权重。 ```bash # 初始化（首次使用） node scripts/evolution.js init # 添加规则 node scripts/evolution.js add-rule <rule_id> <description> <source> # 执行规则前调用，记录 +1 node scripts/evolution.js check <rule_id> # 记录违反 node scripts/evolution.js violation <rule_id> <context> # 查看统计 node scripts/evolution.js stats ``` ### 身份状态层 跨会话持久化的结构化身份。 ```bash # 查看身份 node scripts/evolution.js identity # 更新字段 node scripts/evolution.js identity-update <field> <value> # 记录进化事件 node scripts/evolution.js evolve <change> <trigger> ``` ### 模式检测器 检测重复行为和角色偏离。 ```bash # 记录操作 node scripts/evolution.js log <action_type> <detail> # 检查告警 node scripts/evolution.js detect # 重置计数器 node scripts/evolution.js reset <pattern_id> ``` ### 综合报告 ```bash node scripts/evolution.js report ``` ## 初始化规则 从 AGENTS.md / SOUL.md 自动提取规则： ```bash bash scripts/init-rules.sh --agents /path/to/AGENTS.md --soul /path/to/SOUL.md ``` ## 心跳检查 供 HEARTBEAT.md 调用： ```bash bash scripts/heartbeat-check.sh ```

path: scripts/heartbeat-check.sh
content: #!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
EVOLUTION="node $SCRIPT_DIR/evolution.js"

# Check if state exists
if [[ ! -f "$HOME/.openclaw/workspace/.agent-evolution/state.json" ]]; then
  echo '{"status":"not_initialized","message":"Run init first"}'
  exit 0
fi

alerts=$($EVOLUTION detect)
has_alerts=$(echo "$alerts" | node -e "const d=require('fs').readFileSync('/dev/stdin','utf8');console.log(JSON.parse(d).hasAlerts)" 2>/dev/null || echo "false")

stats=$($EVOLUTION stats)
low_weight=$(echo "$stats" | node -e "
  const d=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
  const low=d.rules.filter(r=>r.weight<0.5);
  console.log(JSON.stringify(low.map(r=>({id:r.id,weight:r.weight}))));
" 2>/dev/null || echo "[]")

never_exec=$(echo "$stats" | node -e "
  const d=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
  const ne=d.rules.filter(r=>r.execCount===0);
  console.log(JSON.stringify(ne.map(r=>r.id)));
" 2>/dev/null || echo "[]")

if [[ "$has_alerts" == "true" ]] || [[ "$low_weight" != "[]" ]] || [[ "$never_exec" != "[]" ]]; then
  echo "{\"status\":\"NEEDS_ATTENTION\",\"patternAlerts\":$alerts,\"lowWeightRules\":$low_weight,\"neverExecuted\":$never_exec}"
else
  echo '{"status":"ALL_CLEAR"}'
fi


path: scripts/init-rules.sh
content: #!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
EVOLUTION="node $SCRIPT_DIR/evolution.js"

AGENTS_PATH=""
SOUL_PATH=""

while [[ $# -gt 0 ]]; do
  case "$1" in
    --agents) AGENTS_PATH="$2"; shift 2 ;;
    --soul) SOUL_PATH="$2"; shift 2 ;;
    *) echo '{"error":"unknown arg: '"$1"'"}'; exit 1 ;;
  esac
done

# Initialize state if needed
$EVOLUTION init 2>/dev/null || true

added=0

extract_rules() {
  local file="$1"
  local source="$2"
  
  if [[ ! -f "$file" ]]; then
    echo '{"warning":"file not found: '"$file"'"}'
    return
  fi

  # Match patterns like "1. **xxx**" or "1. xxx" (numbered rules)
  grep -nE '^\s*[0-9]+\.\s+' "$file" | while IFS= read -r line; do
    # Extract the rule text, strip markdown bold markers and leading number
    text=$(echo "$line" | sed 's/^[^:]*:\s*//' | sed 's/^\s*[0-9]\+\.\s*//' | sed 's/\*\*//g' | sed 's/\s*$//')
    
    # Skip empty or very short
    [[ ${#text} -lt 4 ]] && continue
    
    # Generate kebab-case id from text
    rule_id=$(echo "$text" | tr '[:upper:]' '[:lower:]' | \
      sed 's/[[:punct:]]//g' | \
      tr -s '[:space:]' '-' | \
      cut -c1-60 | \
      sed 's/^-//;s/-$//')
    
    # Skip if id is empty
    [[ -z "$rule_id" ]] && continue
    
    $EVOLUTION add-rule "$rule_id" "$text" "$source" 2>/dev/null || true
  done
}

if [[ -n "$AGENTS_PATH" ]]; then
  extract_rules "$AGENTS_PATH" "AGENTS.md"
fi

if [[ -n "$SOUL_PATH" ]]; then
  extract_rules "$SOUL_PATH" "SOUL.md"
fi

# Show final stats
$EVOLUTION stats


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: suspicious | SkillSpector: suspicious (MEDIUM)