feat(ai): auto-fix package checks after source edits

This commit is contained in:
Guillaume ARM 2026-06-11 20:54:25 +02:00
parent f56d54c180
commit a452335b33
2 changed files with 49 additions and 0 deletions

View File

@ -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<string, unknown>) {
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<string, unknown>)) return
running = true
try {
await $`just fix`
} finally {
running = false
}
},
}
}

View File

@ -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