From a452335b33710419b0dd0a70db443c54a8fcbab4 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Thu, 11 Jun 2026 20:54:25 +0200 Subject: [PATCH] feat(ai): auto-fix package checks after source edits --- .../plugins/fix-on-package-source-edit.ts | 45 +++++++++++++++++++ just/check.just | 4 ++ 2 files changed, 49 insertions(+) create mode 100644 .opencode/plugins/fix-on-package-source-edit.ts diff --git a/.opencode/plugins/fix-on-package-source-edit.ts b/.opencode/plugins/fix-on-package-source-edit.ts new file mode 100644 index 0000000..d9de2b6 --- /dev/null +++ b/.opencode/plugins/fix-on-package-source-edit.ts @@ -0,0 +1,45 @@ +import type { Plugin } from "@opencode-ai/plugin" + +const SOURCE_EXTENSIONS = [".lua", ".json"] + +function isSourcePath(value: unknown) { + return typeof value === "string" && SOURCE_EXTENSIONS.some((extension) => value.endsWith(extension)) +} + +function patchTouchesSource(value: unknown) { + if (typeof value !== "string") return false + for (const line of value.split("\n")) { + if (!line.startsWith("*** Update File: ") && !line.startsWith("*** Add File: ")) continue + if (isSourcePath(line.slice(line.indexOf(": ") + 2).trim())) return true + } + return false +} + +function toolTouchesSource(args: Record) { + return ( + isSourcePath(args.filePath) || + isSourcePath(args.path) || + isSourcePath(args.target) || + patchTouchesSource(args.patchText) || + patchTouchesSource(args.patch) + ) +} + +export const FixOnPackageSourceEdit: Plugin = async ({ $ }) => { + let running = false + + return { + "tool.execute.after": async (_input, output) => { + if (running) return + const args = output.args + if (!args || typeof args !== "object" || !toolTouchesSource(args as Record)) return + + running = true + try { + await $`just fix` + } finally { + running = false + } + }, + } +} diff --git a/just/check.just b/just/check.just index 3f28e05..aa3b484 100644 --- a/just/check.just +++ b/just/check.just @@ -3,6 +3,10 @@ check: check-luacheck check-lychee npm-check luacheck --quiet . @just lint-markdown +# Auto-fix package version bumps derived from changed package files. +fix: + @just check-packages --fix + # Validate package descriptors and require version bumps for changed package files. check-packages *args: check-jq #!/usr/bin/env bash