all-paths-talk/.opencode/plugin/file-protection.ts
2025-12-03 18:22:34 +05:00

27 lines
620 B
TypeScript

import type { Plugin } from "@opencode-ai/plugin";
import micromatch from "micromatch";
const uneditableFiles = [
".env",
".env.local",
".env.development",
".env.production",
"src/lib/*.ts",
"opencode.json",
];
export const FileProtectionPlugin: Plugin = async ({ client, $ }) => {
return {
"tool.execute.before": async (input, output) => {
if (
input.tool === "edit" &&
uneditableFiles.some((pattern) =>
micromatch.isMatch(output.args.filePath, pattern)
)
) {
throw new Error(`Do not edit ${output.args.filePath} files`);
}
},
};
};