- opencode-start.sh: checks for state file, injects omoa via OPENCODE_CONFIG_CONTENT - omoa-post-upgrade.sh: removes omoa plugin from opencode.json after upstream install - omoa-toggle.mjs: single Telegram skill to toggle on/off/status - No file mutation of opencode.json, compatible with upstream updates
87 lines
2.9 KiB
JavaScript
87 lines
2.9 KiB
JavaScript
/**
|
|
* omoa-toggle.mjs — OpenCode skill to toggle oh-my-openagent on/off
|
|
*
|
|
* PURPOSE:
|
|
* Provides a single Telegram command to toggle oh-my-openagent on/off.
|
|
* Creates or deletes a state file, then restarts the OpenCode server.
|
|
*
|
|
* HOW IT WORKS:
|
|
* - State file: ~/.config/opencode/omoa-enabled
|
|
* - If state file exists → omoa is enabled
|
|
* - If state file does not exist → omoa is disabled
|
|
* - The opencode-start.sh script checks for this state file at startup
|
|
* - If present, it injects omoa via OPENCODE_CONFIG_CONTENT
|
|
* - If absent, it starts OpenCode vanilla (no omoa)
|
|
*
|
|
* USAGE:
|
|
* In Telegram: /commands → omoa_toggle
|
|
* Actions:
|
|
* - on: Create state file, restart server (enables omoa)
|
|
* - off: Delete state file, restart server (disables omoa)
|
|
* - status: Check if state file exists
|
|
*
|
|
* UPSTREAM COMPATIBILITY:
|
|
* This approach does NOT modify opencode.json directly.
|
|
* The upstream install script can run safely — use omoa-post-upgrade.sh
|
|
* to clean the plugin entry from opencode.json after running the installer.
|
|
*
|
|
* 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";
|
|
import { existsSync, writeFileSync, unlinkSync } from "node:fs";
|
|
|
|
const STATE_FILE = "/home/kenny/.config/opencode/omoa-enabled";
|
|
|
|
export const OmoaTogglePlugin = async (_ctx) => {
|
|
return {
|
|
tool: {
|
|
omoa_toggle: tool({
|
|
description: "Toggle oh-my-openagent on or off",
|
|
args: {
|
|
action: tool.schema.enum(["on", "off", "status"]).describe("Action: on, off, or status"),
|
|
},
|
|
async execute(args) {
|
|
try {
|
|
if (args.action === "status") {
|
|
return existsSync(STATE_FILE)
|
|
? "oh-my-openagent is ENABLED (state file exists)"
|
|
: "oh-my-openagent is DISABLED (no state file)";
|
|
}
|
|
|
|
if (args.action === "on") {
|
|
// Create state file to enable omoa
|
|
writeFileSync(STATE_FILE, new Date().toISOString());
|
|
|
|
// Restart the OpenCode server
|
|
execSync("systemctl --user restart opencode-serve.service");
|
|
|
|
return "oh-my-openagent ENABLED. Server restarting...";
|
|
}
|
|
|
|
if (args.action === "off") {
|
|
// Delete state file to disable omoa
|
|
if (existsSync(STATE_FILE)) {
|
|
unlinkSync(STATE_FILE);
|
|
}
|
|
|
|
// Restart the OpenCode server
|
|
execSync("systemctl --user restart opencode-serve.service");
|
|
|
|
return "oh-my-openagent DISABLED. Server restarting...";
|
|
}
|
|
|
|
return "Invalid action. Use: on, off, or status";
|
|
} catch (err) {
|
|
return `Error: ${err.message}`;
|
|
}
|
|
},
|
|
}),
|
|
},
|
|
};
|
|
};
|