Add AI profiles and harness adapters (claude-code, codex, opencode, native)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=Launch the AI harness configured by a profile
|
||||
# omarchy:args=[profile]
|
||||
# omarchy:examples=omarchycn ai launch | omarchycn ai launch work
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$OMARCHY_PATH/cn/lib/ai.sh"
|
||||
|
||||
profile="${1:-$(cn_ai_current_profile)}"
|
||||
|
||||
if [[ ! -f $CN_AI_PROFILE_DIR/$profile.toml ]]; then
|
||||
echo "No such profile: $profile" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
harness=$(cn_ai_profile_field "$profile" harness)
|
||||
provider=$(cn_ai_profile_field "$profile" provider)
|
||||
model=$(cn_ai_profile_field "$profile" model)
|
||||
command=$(cn_ai_harness_field "$harness" command)
|
||||
config_method=$(cn_ai_harness_field "$harness" config_method)
|
||||
|
||||
if ! command -v "$command" > /dev/null 2>&1; then
|
||||
install=$(cn_ai_harness_field "$harness" install)
|
||||
if [[ $install == doc:* ]]; then
|
||||
echo "$harness 未安装,安装方法见官方文档: ${install#doc:}" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Installing $harness: $install"
|
||||
$install
|
||||
fi
|
||||
|
||||
case "$config_method" in
|
||||
env)
|
||||
key=$(omarchy-cn-ai-secret get "$provider")
|
||||
if [[ $harness == "codex" ]]; then
|
||||
cn_ai_render_codex_config "$provider" "$model" "$key"
|
||||
exec "$command"
|
||||
fi
|
||||
eval "$(cn_ai_render_env "$harness" "$provider" "$model" "$key")"
|
||||
exec "$command"
|
||||
;;
|
||||
native)
|
||||
# Native harnesses (kimi-code, deep-code) manage their own auth
|
||||
exec "$command"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown config method: $config_method" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=Create an AI profile binding a harness, provider, and model
|
||||
# omarchy:args=<name> <harness> <provider> <model|default-coding|fast>
|
||||
# omarchy:examples=omarchycn ai profile create work claude-code deepseek default-coding
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$OMARCHY_PATH/cn/lib/ai.sh"
|
||||
|
||||
name="${1:?usage: omarchycn ai profile create <name> <harness> <provider> <model>}"
|
||||
harness="${2:?missing harness}"
|
||||
provider="${3:?missing provider}"
|
||||
model="${4:?missing model}"
|
||||
|
||||
if [[ ! $name =~ ^[a-z0-9-]+$ ]]; then
|
||||
echo "Profile name must be lowercase alphanumeric/dashes: $name" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cn_ai_harness_field "$harness" command > /dev/null || {
|
||||
echo "Unknown harness: $harness (known: $(cn_ai_harness_ids | tr '\n' ' '))" >&2
|
||||
exit 1
|
||||
}
|
||||
jq -e --arg p "$provider" '.providers[$p]' "$CN_AI_PROVIDERS" > /dev/null || {
|
||||
echo "Unknown provider: $provider (known: $(cn_ai_provider_ids | tr '\n' ' '))" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
level=$(cn_ai_combo_level "$harness" "$provider")
|
||||
if [[ $level == "unsupported" ]]; then
|
||||
echo "Combo $harness x $provider is not in the compatibility matrix" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
resolved=$(cn_ai_model_by_alias "$provider" "$model" 2>/dev/null || true)
|
||||
if [[ -n $resolved ]]; then
|
||||
model="$resolved"
|
||||
elif ! cn_ai_models "$provider" | grep -qxF "$model"; then
|
||||
echo "Unknown model for $provider: $model" >&2
|
||||
echo "Available: $(cn_ai_models "$provider" | tr '\n' ' ')" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$CN_AI_PROFILE_DIR"
|
||||
cat > "$CN_AI_PROFILE_DIR/$name.toml" <<EOF
|
||||
schema_version = 1
|
||||
name = "$name"
|
||||
harness = "$harness"
|
||||
provider = "$provider"
|
||||
model = "$model"
|
||||
secret_ref = "omarchycn://ai/$provider"
|
||||
EOF
|
||||
|
||||
echo "Profile $name: $harness x $provider x $model (compat: $level)"
|
||||
if ! omarchy-cn-ai-secret get "$provider" > /dev/null 2>&1; then
|
||||
echo "提示: 尚未存储 $provider 的 API Key,运行: omarchycn ai secret set $provider"
|
||||
fi
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=List AI profiles and the current default
|
||||
# omarchy:examples=omarchycn ai profile list
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$OMARCHY_PATH/cn/lib/ai.sh"
|
||||
|
||||
current=""
|
||||
if [[ -f $CN_AI_CURRENT ]]; then
|
||||
current=$(<"$CN_AI_CURRENT")
|
||||
fi
|
||||
|
||||
found="false"
|
||||
for f in "$CN_AI_PROFILE_DIR"/*.toml; do
|
||||
[[ -f $f ]] || continue
|
||||
found="true"
|
||||
name="${f##*/}"
|
||||
name="${name%.toml}"
|
||||
marker=" "
|
||||
[[ $name == "$current" ]] && marker="*"
|
||||
printf '%s %-14s %s x %s x %s\n' "$marker" "$name" \
|
||||
"$(cn_ai_profile_field "$name" harness)" \
|
||||
"$(cn_ai_profile_field "$name" provider)" \
|
||||
"$(cn_ai_profile_field "$name" model)"
|
||||
done
|
||||
|
||||
if [[ $found == "false" ]]; then
|
||||
echo "No profiles (create: omarchycn ai profile create <name> <harness> <provider> <model>)"
|
||||
fi
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=Set the default AI profile
|
||||
# omarchy:args=<name>
|
||||
# omarchy:examples=omarchycn ai profile use work
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$OMARCHY_PATH/cn/lib/ai.sh"
|
||||
|
||||
name="${1:?usage: omarchycn ai profile use <name>}"
|
||||
|
||||
if [[ ! -f $CN_AI_PROFILE_DIR/$name.toml ]]; then
|
||||
echo "No such profile: $name (see: omarchycn ai profile list)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "${CN_AI_CURRENT%/*}"
|
||||
echo "$name" > "$CN_AI_CURRENT"
|
||||
echo "Default AI profile: $name"
|
||||
Reference in New Issue
Block a user