opencode configu update

This commit is contained in:
David Chen 2026-05-16 12:37:27 -07:00
parent 5184e60da9
commit 57e816f512
2 changed files with 145 additions and 5 deletions

View file

@ -29,6 +29,94 @@ _op_run() {
return 1
fi
if command -v jq >/dev/null 2>&1 && command -v curl >/dev/null 2>&1; then
local rapid_models_json rapid_model_id rapid_model_limit tmp_config_json tmp_context tmp_output tmp_name
rapid_models_json=$(curl -fsS "http://127.0.0.1:8000/v1/models" 2>/dev/null || true)
rapid_model_id=$(printf '%s' "$rapid_models_json" | jq -r '.data[0].id // empty' 2>/dev/null || true)
if [ -n "$rapid_model_id" ] && [ -f "$rapid_model_id/config.json" ]; then
tmp_context=$(jq -r '
.text_config.max_position_embeddings //
.language_model.max_position_embeddings //
.language_config.max_position_embeddings //
.max_position_embeddings //
empty
' "$rapid_model_id/config.json" 2>/dev/null || true)
if [ -n "$tmp_context" ] && [ "$tmp_context" != "null" ]; then
tmp_output=8192
tmp_name=${rapid_model_id:t}
tmp_config_json="$tmp_home/opencode.json.tmp"
if jq \
--arg name "$tmp_name" \
--argjson context "$tmp_context" \
--argjson output "$tmp_output" \
'
.provider.rapidmlx.models.default.name = $name |
.provider.rapidmlx.models.default.limit.context = $context |
.provider.rapidmlx.models.default.limit.output = $output
' "$tmp_home/opencode.json" > "$tmp_config_json" 2>/dev/null; then
mv "$tmp_config_json" "$tmp_home/opencode.json"
print -u2 "$tag: synced rapidmlx/default to $tmp_name (context $tmp_context, output $tmp_output)"
fi
fi
fi
fi
local agent_workspace=""
local agent_feature=""
local agent_browser_url=""
local agent_search_dir="$PWD"
while [ -n "$agent_search_dir" ] && [ "$agent_search_dir" != "/" ]; do
if [ -f "$agent_search_dir/agent.json" ]; then
agent_workspace="$agent_search_dir"
break
fi
if [ "${agent_search_dir:t}" = "repo" ] && [ -f "${agent_search_dir:h}/agent.json" ]; then
agent_workspace="${agent_search_dir:h}"
break
fi
agent_search_dir="${agent_search_dir:h}"
done
if [ -n "$agent_workspace" ] && command -v jq >/dev/null 2>&1; then
local agent_json="$agent_workspace/agent.json"
local agent_device
agent_device=$(jq -r '.device // empty' "$agent_json" 2>/dev/null || true)
agent_browser_url=$(jq -r '.url // empty' "$agent_json" 2>/dev/null || true)
agent_feature=$(jq -r '.feature // empty' "$agent_json" 2>/dev/null || true)
if [ "$agent_device" = "web-server" ] && [ -n "$agent_browser_url" ]; then
local agent_bin="${AGENT_BIN:-$HOME/.config/agent-tracker/bin/agent}"
local tmp_config_json="$tmp_home/opencode.json.tmp"
if jq \
--arg agent_bin "$agent_bin" \
--arg workspace "$agent_workspace" \
--arg feature "$agent_feature" \
--arg url "$agent_browser_url" \
'
.mcp = (.mcp // {}) |
.mcp.agent_browser = {
type: "local",
command: [$agent_bin, "browser", "mcp", "--workspace", $workspace],
environment: {
AGENT_WORKSPACE: $workspace,
AGENT_FEATURE: $feature,
AGENT_BROWSER_URL: $url
},
enabled: true,
timeout: 10000
}
' "$tmp_home/opencode.json" > "$tmp_config_json" 2>/dev/null; then
mv "$tmp_config_json" "$tmp_home/opencode.json"
print -u2 "$tag: added agent_browser MCP for ${agent_feature:-$agent_workspace}"
else
rm -f "$tmp_config_json"
print -u2 "$tag: failed to add agent_browser MCP for $agent_workspace"
fi
fi
fi
local base_agents="$base_home/AGENTS.md"
if [ "$tag" = "se" ]; then
local search_agents="$base_home/agent/search/AGENTS.md"
@ -112,6 +200,9 @@ _op_run() {
fi
OPENCODE_CONFIG_DIR="$tmp_home" \
AGENT_WORKSPACE="${agent_workspace:-${AGENT_WORKSPACE:-}}" \
AGENT_FEATURE="${agent_feature:-${AGENT_FEATURE:-}}" \
AGENT_BROWSER_URL="${agent_browser_url:-${AGENT_BROWSER_URL:-}}" \
OP_TRACKER_NOTIFY="${OP_TRACKER_NOTIFY:-0}" \
RIPGREP_CONFIG_PATH="${RIPGREP_CONFIG_PATH:-$HOME/.ripgreprc}" \
"${opencode_cmd[@]}"