Add wrapper script for runtime omoa injection via OPENCODE_CONFIG_CONTENT

This commit is contained in:
Twentyninehairs_bot 2026-05-03 20:23:28 -07:00
parent 858cb2ef5d
commit a998c3975c
Signed by: Twentyninehairs_bot
GPG Key ID: CC558AA42F05E387
3 changed files with 154 additions and 21 deletions

View File

@ -4,45 +4,55 @@ Toggle the [oh-my-openagent](https://github.com/code-yeongyu/oh-my-openagent) pl
## Purpose
oh-my-openagent adds multi-model orchestration, LSP tools, and other advanced features to OpenCode. However, it can interfere with normal operation. This tool provides a simple way to enable/disable it.
oh-my-openagent adds multi-model orchestration, LSP tools, and other advanced features to OpenCode. However, it can interfere with normal operation. This tool provides a simple way to enable/disable it **without modifying the config file**.
## How It Works
The solution uses the `OPENCODE_CONFIG_CONTENT` environment variable, which has higher runtime precedence than the config file. This means:
- The base `opencode.json` stays clean (no plugin entry)
- The plugin is only injected at runtime when needed
- No file mutation, no backups, no restore
## Files
- `omoa.sh` — Shell script for direct use
- `omoa.mjs` — OpenCode skill for integration with OpenCode sessions and Telegram bot
- `opencode-start.sh` — Wrapper script that starts OpenCode with/without omoa
- `omoa-restart.mjs` — OpenCode skill for Telegram bot integration
- `README.md` — This file
## Usage
### Shell Script
```bash
./omoa.sh # Show status
./omoa.sh on # Enable oh-my-openagent
./omoa.sh off # Disable oh-my-openagent
./opencode-start.sh # Start without omoa (vanilla)
./opencode-start.sh --omoa # Start with omoa enabled
```
### OpenCode Skill
### Telegram Bot
When registered in `opencode.json`, use `/commands``omoa_toggle` in OpenCode or Telegram.
When registered in `opencode.json` under "skills", use `/commands` in Telegram:
- `restart_with_omoa` — Restart OpenCode with omoa enabled
- `restart_without_omoa` — Restart OpenCode without omoa (vanilla)
## Installation
1. Copy `omoa.sh` and `omoa.mjs` to `/home/kenny/.config/opencode/skills/`
2. Add to `opencode.json` under "skills":
1. Copy files to `~/.config/opencode/`
2. Update systemd service to use `opencode-start.sh`:
```ini
[Service]
ExecStart=/home/kenny/.config/opencode/opencode-start.sh
```
3. Add skill to `opencode.json`:
```json
"omoa": {
"description": "Toggle oh-my-openagent plugin on/off",
"path": "/home/kenny/.config/opencode/skills/omoa.mjs"
"skills": {
"omoa-restart": {
"description": "Restart OpenCode with/without oh-my-openagent",
"path": "/home/kenny/.config/opencode/skills/omoa-restart.mjs"
}
}
```
3. Restart OpenCode server
## Known Issues
- The omoa install command is fragile and may fail silently
- The `--no-tui` flag requires all options to be specified manually
- The script does not verify success before restarting services
- Needs overhaul to handle edge cases better
4. Restart services
## Author

60
omoa-restart.mjs Normal file
View File

@ -0,0 +1,60 @@
/**
* omoa-restart.mjs OpenCode skills to restart server with/without oh-my-openagent
*
* PURPOSE:
* Provides two skills for the Telegram bot:
* - restart_with_omoa: Restart OpenCode with oh-my-openagent enabled
* - restart_without_omoa: Restart OpenCode without oh-my-openagent (vanilla)
*
* HOW IT WORKS:
* - Uses systemctl to restart the opencode-serve service
* - The service uses opencode-start.sh which conditionally sets
* OPENCODE_CONFIG_CONTENT based on the --omoa flag
* - No files are mutated the base opencode.json stays clean
*
* UPSTREAM REPO:
* https://git.hibbhome.com/Hibbhome/opencode-omoa-toggle
*
* CREATED: 2026-05-03
*/
import { tool } from "@opencode-ai/plugin/tool";
import { execSync } from "node:child_process";
export const OmoaRestartPlugin = async (_ctx) => {
return {
tool: {
restart_with_omoa: tool({
description: "Restart OpenCode server with oh-my-openagent plugin enabled",
args: {},
async execute() {
try {
// Update the systemd service to use --omoa flag
execSync(`sed -i 's|opencode-start.sh"|opencode-start.sh --omoa"|' /home/kenny/.config/systemd/user/opencode-serve.service`);
execSync("systemctl --user daemon-reload");
execSync("systemctl --user restart opencode-serve.service");
return "OpenCode restarted WITH oh-my-openagent enabled";
} catch (err) {
return `Error: ${err.message}`;
}
},
}),
restart_without_omoa: tool({
description: "Restart OpenCode server without oh-my-openagent (vanilla)",
args: {},
async execute() {
try {
// Update the systemd service to remove --omoa flag
execSync(`sed -i 's|opencode-start.sh --omoa"|opencode-start.sh"|' /home/kenny/.config/systemd/user/opencode-serve.service`);
execSync("systemctl --user daemon-reload");
execSync("systemctl --user restart opencode-serve.service");
return "OpenCode restarted WITHOUT oh-my-openagent (vanilla)";
} catch (err) {
return `Error: ${err.message}`;
}
},
}),
},
};
};

63
opencode-start.sh Executable file
View File

@ -0,0 +1,63 @@
#!/bin/bash
# =============================================================================
# opencode-start.sh — Start OpenCode with or without oh-my-openagent
# =============================================================================
#
# PURPOSE:
# Wrapper script that starts the OpenCode server, optionally injecting the
# oh-my-openagent plugin at runtime via OPENCODE_CONFIG_CONTENT.
# No files are mutated — the base opencode.json stays clean.
#
# USAGE:
# ./opencode-start.sh — Start without omoa (vanilla)
# ./opencode-start.sh --omoa — Start with omoa enabled
#
# HOW IT WORKS:
# - Reads ~/.config/opencode/opencode.json
# - If --omoa flag is set, uses python3 to add oh-my-openagent@latest to the
# plugin array and sets OPENCODE_CONFIG_CONTENT with the modified JSON
# - If --omoa is not set, starts with the clean config file
# - OPENCODE_CONFIG_CONTENT has higher precedence than the config file,
# so the plugin is only active for that process
#
# UPSTREAM REPO:
# https://git.hibbhome.com/Hibbhome/opencode-omoa-toggle
#
# CREATED: 2026-05-03
# =============================================================================
CONFIG_FILE="$HOME/.config/opencode/opencode.json"
OPENCODE_BIN="$HOME/.opencode/bin/opencode"
PORT=4096
if [[ "$*" == *"--omoa"* ]]; then
# Inject oh-my-openagent plugin at runtime using python3
MODIFIED_CONFIG=$(python3 -c "
import json
import sys
with open('$CONFIG_FILE', 'r') as f:
config = json.load(f)
# Ensure plugin array exists
if 'plugin' not in config:
config['plugin'] = []
# Add oh-my-openagent if not already present
if not any('oh-my-openagent' in p for p in config['plugin']):
config['plugin'].append('oh-my-openagent@latest')
print(json.dumps(config))
")
if [ $? -ne 0 ]; then
echo "ERROR: Failed to process config with python3"
exit 1
fi
echo "Starting OpenCode WITH oh-my-openagent..."
OPENCODE_CONFIG_CONTENT="$MODIFIED_CONFIG" exec "$OPENCODE_BIN" serve --port "$PORT"
else
echo "Starting OpenCode (vanilla)..."
exec "$OPENCODE_BIN" serve --port "$PORT"
fi