diff --git a/profiles/opencode/plugin/block-scripting.ts b/profiles/opencode/plugin/block-scripting.ts new file mode 100644 index 0000000..d65442d --- /dev/null +++ b/profiles/opencode/plugin/block-scripting.ts @@ -0,0 +1,19 @@ +import type { Plugin } from "@opencode-ai/plugin"; + +const SCRIPTING_PATTERN = + /(?:^|[;&|]\s*|&&\s*|\|\|\s*|\$\(\s*|`\s*)(?:python[23]?|perl|ruby|php|lua|bash\s+-c|sh\s+-c)\s/; + +export const BlockScriptingPlugin: Plugin = async () => { + return { + "tool.execute.before": async (input, output) => { + if (input.tool === "bash") { + const command = output.args.command as string; + if (SCRIPTING_PATTERN.test(command)) { + throw new Error( + "Do not use python, perl, ruby, php, lua, or inline bash/sh for scripting. Use `nu -c` instead.", + ); + } + } + }, + }; +};