fix: stabilize opencode declarations across package managers

This commit is contained in:
Affaan Mustafa
2026-04-05 15:11:19 -07:00
parent 0f4f95b3de
commit 05acc27530
8 changed files with 31 additions and 15 deletions

View File

@@ -5,13 +5,13 @@
* This avoids shell execution assumptions while still giving precise guidance.
*/
import { tool } from "@opencode-ai/plugin/tool"
import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool"
import * as path from "path"
import * as fs from "fs"
type Formatter = "biome" | "prettier" | "black" | "gofmt" | "rustfmt"
export default tool({
const formatCodeTool: ToolDefinition = tool({
description:
"Detect formatter for a file and return the exact command to run (Biome, Prettier, Black, gofmt, rustfmt).",
args: {
@@ -43,6 +43,8 @@ export default tool({
},
})
export default formatCodeTool
function detectFormatter(cwd: string, ext: string): Formatter | null {
if (["ts", "tsx", "js", "jsx", "json", "css", "scss", "md", "yaml", "yml"].includes(ext)) {
if (fs.existsSync(path.join(cwd, "biome.json")) || fs.existsSync(path.join(cwd, "biome.jsonc"))) {