feat(ai): auto-fix package checks after source edits
This commit is contained in:
parent
f56d54c180
commit
a452335b33
45
.opencode/plugins/fix-on-package-source-edit.ts
Normal file
45
.opencode/plugins/fix-on-package-source-edit.ts
Normal 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
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user