69 lines
3.4 KiB
Bash
69 lines
3.4 KiB
Bash
#!/usr/bin/env bash
|
|
# Harness-specific configuration and agent invocation.
|
|
|
|
install_skill_set() {
|
|
local destination=$1 index
|
|
mkdir -p "$destination"
|
|
for index in "${!SKILL_DIRS[@]}"; do
|
|
cp -a "${SKILL_DIRS[$index]}" "$destination/${SKILL_NAMES[$index]}"
|
|
done
|
|
}
|
|
|
|
write_opencode_config() {
|
|
local config_path=$1
|
|
node - "$config_path" "$PROVIDER_ID" "$MODEL_ID" "$PROVIDER_BASE_URL" "$PROVIDER_API_KEY" <<'NODE'
|
|
const fs = require("fs");
|
|
const [configPath, provider, model, baseURL, apiKey] = process.argv.slice(2);
|
|
const config = {$schema: "https://opencode.ai/config.json", model: `${provider}/${model}`,
|
|
provider: {[provider]: {npm: "@ai-sdk/openai-compatible", name: provider,
|
|
options: {baseURL, apiKey}, models: {[model]: {name: model}}}}};
|
|
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, {mode: 0o600});
|
|
NODE
|
|
}
|
|
|
|
write_hermes_profile() {
|
|
local profile_home=$1 workspace=$2
|
|
mkdir -p "$profile_home/skills"
|
|
touch "$profile_home/.no-bundled-skills"
|
|
install_skill_set "$profile_home/skills"
|
|
{
|
|
printf '%s\n' 'model:' " default: \"$MODEL_ID\"" ' provider: custom' ' base_url: "https://api.siliconflow.cn/v1"'
|
|
printf '%s\n' 'terminal:' ' backend: local' " cwd: \"$workspace\"" ' timeout: 180' ' home_mode: profile'
|
|
printf '%s\n' 'memory:' ' memory_enabled: false' ' user_profile_enabled: false'
|
|
printf '%s\n' 'skills:' ' external_dirs: []' ' inline_shell: false' ' write_approval: true'
|
|
printf '%s\n' 'curator:' ' enabled: false' 'fallback_providers: []'
|
|
printf '%s\n' 'delegation:' ' orchestrator_enabled: false' ' max_spawn_depth: 1' ' max_concurrent_children: 1' ' max_async_children: 1'
|
|
} > "$profile_home/config.yaml"
|
|
}
|
|
|
|
run_opencode() {
|
|
local run_root=$1 workspace=$2 prompt=$3
|
|
install_skill_set "$workspace/.opencode/skills"
|
|
write_opencode_config "$run_root/opencode.json"
|
|
(cd "$workspace"; OPENCODE_CONFIG="$run_root/opencode.json" OPENCODE_CONFIG_DIR="$workspace/.opencode" \
|
|
XDG_DATA_HOME="$run_root/opencode-data" XDG_STATE_HOME="$run_root/opencode-state" \
|
|
timeout --foreground --signal=INT --kill-after=30s "${TIMEOUT_SECONDS}s" \
|
|
opencode --pure --auto --model "$PROVIDER_ID/$MODEL_ID" run "$prompt") > "$run_root/agent-trace.txt" 2>&1
|
|
}
|
|
|
|
run_hermes() {
|
|
local run_root=$1 workspace=$2 prompt=$3 skill_csv
|
|
skill_csv=$(IFS=,; printf '%s' "${SKILL_NAMES[*]}")
|
|
write_hermes_profile "$run_root/hermes-home" "$workspace"
|
|
(cd "$workspace"; OPENAI_API_KEY="$SILICONFLOW_API_KEY" HERMES_HOME="$run_root/hermes-home" HERMES_OPTIONAL_SKILLS="" \
|
|
timeout --foreground --signal=INT --kill-after=30s "${TIMEOUT_SECONDS}s" \
|
|
hermes --yolo --provider custom --model "$MODEL_ID" --toolsets terminal --skills "$skill_csv" --oneshot "$prompt") > "$run_root/agent-trace.txt" 2>&1
|
|
}
|
|
|
|
prepare_claude_workspace() { install_skill_set "$1/.claude/skills"; }
|
|
|
|
run_claude_code() {
|
|
local run_root=$1 workspace=$2 prompt=$3
|
|
prepare_claude_workspace "$workspace"
|
|
(cd "$workspace"; ANTHROPIC_BASE_URL="$PROVIDER_BASE_URL" ANTHROPIC_AUTH_TOKEN="$PROVIDER_API_KEY" \
|
|
timeout --foreground --signal=INT --kill-after=30s "${TIMEOUT_SECONDS}s" \
|
|
claude --print --output-format json --model "$MODEL_ID" --dangerously-skip-permissions "$prompt") \
|
|
> "$run_root/claude-result.json" 2> "$run_root/claude-stderr.txt"
|
|
cat "$run_root/claude-result.json" "$run_root/claude-stderr.txt" > "$run_root/agent-trace.txt"
|
|
}
|