SuperAPI AI Directory

harness-init

General & other

View repository

Updated 10-15 23:47

About this skill

harness-init global initialization skill

Core capabilities

  1. Check whether the Git repository exists
  2. Bootstrap-create the core file system and basic entry files
  3. Initialize global state
  4. Initialize the iteration counter
  5. Register all skills
  6. Automatically start the session daemon (to prevent context overload)
  7. Initialize the tmux handover state file and launcher script
  8. Automatically start the event orchestrator (consumes TRIGGER_DOWNSTREAM events)
  9. Follow the directory placement policy; do not create root directories arbitrarily

Prerequisites

  • The Git repository has been initialized

Execution steps

Step 1: Check the Git repository

Use the Bash tool to execute:

if [ ! -d .git ]; then
  echo "❌ 错误: 当前目录不是 Git 仓库"
  echo "💡 请先运行: git init"
  exit 1
fi

echo "✅ Git 仓库检查通过"

Step 2: Check or create the Manifest file

Use the Bash tool to execute:

if [ ! -f EnjoyHarness_MANIFEST.md ]; then
  echo "⚠️  未找到 EnjoyHarness_MANIFEST.md,正在自举创建..."
  if [ -x scripts/harness-bootstrap.sh ]; then
    scripts/harness-bootstrap.sh --root "$(pwd)"
  else
    cat > EnjoyHarness_MANIFEST.md <<'EOF'
---
name: EnjoyHarness Engineering
version: v3.0.0
description: 给AI Agent装上工业级「自动驾驶操作系统」,解决落地稳定性、可控性、可复用性核心痛点
---

# EnjoyHarness 全局 Manifest

## 核心定位
给AI Agent装上工业级「自动驾驶操作系统」,打造不随模型迭代淘汰的工程化超级能力

## 技能总数
18个核心技能(Markdown 定义 + 运行层 Shell 编排)

## 唯一启动入口
必须先执行 `harness-init` 初始化技能,才可调用其他所有技能
EOF
  fi
fi

echo "✅ Manifest 文件检查通过"

Step 3: Create the core directories

Use the Bash tool to execute:

mkdir -p .EnjoyHarness
mkdir -p .subharness
mkdir -p .trace/ARCHIVE
mkdir -p .learnings
mkdir -p skills

echo "✅ 核心目录创建完成"

Directory placement constraints:

  • Temporary content is preferentially placed in temp/
  • Backup content is preferentially placed in backup/
  • Formal test content uses tests/
  • Temporary test materials may be placed in test/
  • Documentation is uniformly placed in docs/
  • Do not add directories without a clear ownership at the repository root

Step 4: Initialize the global state file

Use the Write tool to create the file:.EnjoyHarness/GLOBAL_STATE.md

Note: Use Bash to get the current time and replace INIT_TIME_PLACEHOLDER

INIT_TIME=$(date -Iseconds)
echo "初始化时间: $INIT_TIME"

Content:

---
initialized_at: INIT_TIME_PLACEHOLDER
status: active
version: v3.0.0
current_task: none
active_subagents: []
---

# EnjoyHarness 全局状态

## 系统状态
- 初始化时间: INIT_TIME_PLACEHOLDER
- 状态: 活跃
- 版本: v3.0.0
- 当前任务: 无
- 活跃子代理: 0

## 技能错误计数
所有技能错误计数归零

## 迭代计数
当前迭代: 0 / 100

## 最近事件
初始化完成,等待第一个事件...

Step 5: Initialize the event bus

Use the Write tool to create the file:.EnjoyHarness/EVENT_LOG.md

Content:

---
created_at: INIT_TIME_PLACEHOLDER
total_events: 0
---

# EnjoyHarness 事件总线

## 事件记录格式
时间 | 事件类型 | 触发技能 | 详情 | 结果

## 最新事件
初始化完成,等待第一个事件...

Step 6: Initialize the iteration counter

Use the Write tool to create the file:.EnjoyHarness/ITERATION_COUNTER.md

Content:

---
max_iterations: 100
current_iteration: 0
task_id: none
start_time: null
---

# EnjoyHarness 全局迭代计数器

## 迭代限制
- 最大迭代次数: 100(可配置)
- 当前迭代次数: 0
- 关联任务: 无
- 开始时间: 未开始

## 迭代计数规则
- 计数: 每次技能执行(Write/Edit/Bash执行命令)
- 不计数: Read文件、查询命令(git status)

## 熔断触发条件
当前迭代次数 ≥ 最大迭代次数 → 强制停止,先触发自动失败处理;真实阻塞再升级

## 使用说明
1. 每次技能执行前,检查迭代计数
2. 每次技能执行后,增加计数 +1
3. 达到阈值默认触发 harness-handle-failure;真实阻塞时再升级人工介入

Step 7: Create the skill registry

Use the Write tool to create the file:.EnjoyHarness/SKILL_REGISTRY.md

Content:

---
total_skills: 18
enabled_skills: 18
disabled_skills: 0
created_at: INIT_TIME_PLACEHOLDER
---

# EnjoyHarness 技能注册表

## 核心基础层 (4个)
- [ ] harness-init - 全局初始化技能
- [ ] harness-build-core-manifest - 构建核心规则技能
- [ ] harness-build-context-index - 构建上下文索引技能
- [ ] harness-enforce-architecture-guardrails - 架构护栏技能

## 调度执行层 (5个)
- [ ] harness-build-deterministic-workflow - 构建工作流技能
- [ ] harness-spawn-subharness-agent - 生成子代理技能
- [ ] harness-monitor-subharness-agent - 监控子代理技能
- [ ] harness-merge-subharness-result - 合并结果技能
- [ ] harness-enable-circuit-breaker - 熔断机制技能

## 验证优化层 (4个)
- [ ] harness-validate-output - 输出校验技能
- [ ] harness-diagnose-and-improve - 错误诊断技能
- [ ] harness-evaluate-performance - 效果评估技能
- [ ] harness-evolve - 自我进化技能

## 目标追踪层 (1个)
- [ ] harness-goal - 目标追踪技能

## 兜底层 (2个)
- [ ] harness-handle-failure - 失败处理技能
- [ ] harness-escalate-to-human - 人工转交技能

## 开发流程层 (2个)
- [ ] harness-brainstorm - 头脑风暴技能
- [ ] harness-plan - 计划编写技能

## 超级组合层 (不计入总数,组合技能)
- [ ] harness-auto-full-execution - 全流程自动执行技能
- [ ] harness-10x-productivity-boost - 10倍产能提效技能

Step 8: Mark harness-init as completed

Use the Edit tool to update:.EnjoyHarness/SKILL_REGISTRY.md

old_string: - [ ] harness-init - 全局初始化技能 new_string: - [x] harness-init - 全局初始化技能 ✅

Step 9: Record the initialization event

Use the Edit tool to append content to:.EnjoyHarness/EVENT_LOG.md

Appended content:

INIT_TIME_PLACEHOLDER | SKILL_START | harness-init | 系统初始化开始 | SUCCESS
INIT_TIME_PLACEHOLDER | SKILL_COMPLETE | harness-init | 系统初始化完成 | SUCCESS

Step 10: Update the event count

Use the Edit tool to update:.EnjoyHarness/EVENT_LOG.md

old_string: total_events: 0 new_string: total_events: 2

Step 11: Update the global state

Use the Edit tool to update:.EnjoyHarness/GLOBAL_STATE.md

Replace INIT_TIME_PLACEHOLDER with the actual timestamp (obtained using Bash)

Step 11.5: Inject user identity information into the Claude entry file

Use Bash to read the configuration or git identity:

CONFIG_FILE="$(pwd)/.EnjoyHarness/CONFIG.md"
USER_NAME="$(grep -m1 '^user_name:' "$CONFIG_FILE" 2>/dev/null | sed 's/user_name: *//' | tr -d '"' | tr -d "'" )"
USER_PHONE="$(grep -m1 '^user_phone:' "$CONFIG_FILE" 2>/dev/null | sed 's/user_phone: *//' | tr -d '"' | tr -d "'" )"
USER_EMAIL="$(grep -m1 '^user_email:' "$CONFIG_FILE" 2>/dev/null | 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

Injection rules:

  • Preferentially use the .EnjoyHarness/CONFIG.md in the current project's user_name / user_phone / user_email
  • If user_name or user_email is empty, fall back to git config user.name / git config user.email
  • user_phone is optional; when not configured, write "Not configured" or omit the line
  • Update the identity block at the top of AGENT.md、CLAUDE.md(as well as the equivalent agent instruction file in the repository), but do not delete the original content

Example of written content:

## first
call me {USER_NAME}
git提交身份信息:
username:{USER_NAME}
phone:{USER_PHONE_OR_未配置}
email:{USER_EMAIL}

If AGENT.md or CLAUDE.md does not exist, create it and write the above identity block; if it exists, only update the identity block and do not modify the subsequent body. If the current project is just being onboarded from scratch, preferentially execute scripts/start-auto.sh --root "$(pwd)"; it will automatically determine whether it needs to bootstrap first, start the daemon, trigger the tmux handoff, and then continue initialization.

Step 12: Automatically start the session daemon and tmux entry

Use the Bash tool to execute:

# 优先使用统一自动入口,它会自动判断是否需要 bootstrap、daemon、tmux launch
if [ -x "scripts/start-auto.sh" ]; then
    echo ""
    echo "🔄 自动启动 EnjoyHarness 统一入口..."
    scripts/start-auto.sh --root "$(pwd)"
else
    echo ""
    echo "⚠️  未找到 scripts/start-auto.sh,回退到守护进程直启模式"
    if [ -f "scripts/harness-daemon.sh" ]; then
        chmod +x scripts/harness-daemon.sh
        chmod +x scripts/start-daemon.sh
        chmod +x scripts/stop-daemon.sh
        chmod +x scripts/daemon-status.sh
        chmod +x scripts/harness-orchestrator.sh
        chmod +x scripts/tmux-handoff-manager.sh
        chmod +x scripts/tmux-session-bootstrap.sh
        chmod +x scripts/tmux-attach.sh
        chmod +x scripts/tmux-resume.sh
        scripts/start-daemon.sh
    else
        echo "⚠️  未找到守护进程脚本,跳过自动启动"
        echo "   如需启用会话自动切换功能,请确保 scripts/harness-daemon.sh 存在"
    fi
fi

Step 13: Output completion information

Use the Bash tool to output:

echo ""
echo "✅ EnjoyHarness 初始化完成!"
echo ""
echo "📋 核心文件:"
echo "  - 技能注册表: .EnjoyHarness/SKILL_REGISTRY.md"
echo "  - 全局状态: .EnjoyHarness/GLOBAL_STATE.md"
echo "  - 事件总线: .EnjoyHarness/EVENT_LOG.md"
echo "  - 迭代计数器: .EnjoyHarness/ITERATION_COUNTER.md"
echo ""
echo "🎯 下一步:"
echo "  运行 harness-build-core-manifest 完成核心规则构建"
echo ""

Success criteria

  • Core directories created
  • EnjoyHarness_MANIFEST.md has been created or verified to exist
  • Global state file exists
  • Iteration counter file exists
  • Skill registry contains 18 skills
  • The top identity blocks of AGENT.md and CLAUDE.md have been written
  • harness-init has been marked as complete

Failure fallback

  • Git repository does not exist → terminate execution, prompt the user to initialize Git first
  • Manifest file does not exist → automatically bootstrap and create it; if creation fails, terminate execution

Linked relationships

  • Auto-trigger: harness-build-core-manifest

Iteration count

Estimated number of iterations for this skill execution: about 12 (Write 4 times + Edit 6 times + Bash 2 times)

Test cases

Test 1: Git repository check

Input: Run in a non-Git directory Expected output: Error message "The current directory is not a Git repository" Verification method: Manually test in a temporary directory

Test 2: Core file creation

Input: Execute harness-init Expected output:

  • EnjoyHarness_MANIFEST.md exists
  • The .EnjoyHarness/ directory exists
  • The GLOBAL_STATE.md file exists
  • The EVENT_LOG.md file exists
  • The ITERATION_COUNTER.md file exists
  • The SKILL_REGISTRY.md file exists Verification method: ls -la .EnjoyHarness/

Test 3: Skill registry completeness

Input: Read .EnjoyHarness/SKILL_REGISTRY.md Expected output: Contains 18 skills Verification method: grep -c "harness-" .EnjoyHarness/SKILL_REGISTRY.md

Test 4: Iteration counter initialization

Input: Read .EnjoyHarness/ITERATION_COUNTER.md Expected output: current_iteration: 0, max_iterations: 100 Verification method: cat .EnjoyHarness/ITERATION_COUNTER.md

Test 5: Event log recording

Input: Read .EnjoyHarness/EVENT_LOG.md Expected output: Contains harness-init start and completion events Verification method: grep "harness-init" .EnjoyHarness/EVENT_LOG.md

Test 6: Entry file identity injection

Input: After executing harness-init, read AGENT.md / CLAUDE.md Expected output: The top contains the user identity block Verification method: grep -n "call me" AGENT.md CLAUDE.md

Automatic daemon startup instructions

Core mechanism

When harness-init executes, it will automatically start the session daemon:

  • ✅ Detect whether scripts/harness-daemon.sh exists
  • ✅ Automatically grant execute permission
  • ✅ Start the daemon in the background
  • ✅ Record the PID to .EnjoyHarness/DAEMON_PID
  • ✅ Record the startup event to EVENT_LOG.md
  • ✅ Initialize tmux session state file and handoff lock

Daemon functionality

  • Check the handoff file (.EnjoyHarness/NEXT_SESSION_PROMPT.md) every 5 seconds
  • Automatically switch sessions every 2 tasks (default threshold)
  • Create a new session via tmux and wait for ACK
  • Prevent context overload
  • Automatically start a new session to continue execution

No manual operation required from the user

Startup process:

用户触发harness技能
    ↓
harness-init自动执行
    ↓
自动启动守护进程
    ↓
开始执行任务(全自动)
    ↓
每完成2个任务
    ↓
自动创建交接文件
    ↓
守护进程自动启动新会话
    ↓
新会话自动继续执行

The entire process is fully automatic, and the user does not need to execute any manual commands!