opencode-omoa-toggle/omoa-restart.mjs

61 lines
2.2 KiB
JavaScript

/**
* 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}`;
}
},
}),
},
};
};