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

@@ -23,7 +23,9 @@ import {
} from "./lib/changed-files-store.js"
import changedFilesTool from "../tools/changed-files.js"
export const ECCHooksPlugin = async ({
type ECCHooksPluginFn = (input: PluginInput) => Promise<Record<string, unknown>>
export const ECCHooksPlugin: ECCHooksPluginFn = async ({
client,
$,
directory,

View File

@@ -1,4 +1,4 @@
import { tool } from "@opencode-ai/plugin/tool"
import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool"
import {
buildTree,
getChangedPaths,
@@ -26,7 +26,7 @@ function renderTree(nodes: TreeNode[], indent: string): string {
return lines.join("\n")
}
export default tool({
const changedFilesTool: ToolDefinition = tool({
description:
"List files changed by agents in this session as a navigable tree. Shows added (+), modified (~), and deleted (-) indicators. Use filter to show only specific change types. Returns paths for git diff.",
args: {
@@ -79,3 +79,5 @@ export default tool({
return output
},
})
export default changedFilesTool

View File

@@ -5,11 +5,11 @@
* Supports common coverage report formats.
*/
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"
export default tool({
const checkCoverageTool: ToolDefinition = tool({
description:
"Check test coverage against a threshold and identify files with low coverage. Reads coverage reports from common locations.",
args: {
@@ -100,6 +100,8 @@ export default tool({
},
})
export default checkCoverageTool
interface CoverageSummary {
total: {
lines: number

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"))) {

View File

@@ -4,10 +4,10 @@
* Returns branch/status/log/diff details for the active repository.
*/
import { tool } from "@opencode-ai/plugin/tool"
import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool"
import { execSync } from "child_process"
export default tool({
const gitSummaryTool: ToolDefinition = tool({
description:
"Generate git summary with branch, status, recent commits, and optional diff stats.",
args: {
@@ -45,6 +45,8 @@ export default tool({
},
})
export default gitSummaryTool
function run(command: string, cwd: string): string {
try {
return execSync(command, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim()

View File

@@ -4,13 +4,13 @@
* Detects the appropriate linter and returns a runnable lint command.
*/
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 Linter = "biome" | "eslint" | "ruff" | "pylint" | "golangci-lint"
export default tool({
const lintCheckTool: ToolDefinition = tool({
description:
"Detect linter for a target path and return command for check/fix runs.",
args: {
@@ -43,6 +43,8 @@ export default tool({
},
})
export default lintCheckTool
function detectLinter(cwd: string): Linter {
if (fs.existsSync(path.join(cwd, "biome.json")) || fs.existsSync(path.join(cwd, "biome.jsonc"))) {
return "biome"

View File

@@ -5,11 +5,11 @@
* Automatically detects the package manager and test framework.
*/
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"
export default tool({
const runTestsTool: ToolDefinition = tool({
description:
"Run the test suite with optional coverage, watch mode, or specific test patterns. Automatically detects package manager (npm, pnpm, yarn, bun) and test framework.",
args: {
@@ -97,6 +97,8 @@ export default tool({
},
})
export default runTestsTool
async function detectPackageManager(cwd: string): Promise<string> {
const lockFiles: Record<string, string> = {
"bun.lockb": "bun",

View File

@@ -8,11 +8,11 @@
* The regex patterns below are used to DETECT potential issues in user code.
*/
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"
export default tool({
const securityAuditTool: ToolDefinition = tool({
description:
"Run a comprehensive security audit including dependency vulnerabilities, secret scanning, and common security issues.",
args: {
@@ -106,6 +106,8 @@ export default tool({
},
})
export default securityAuditTool
interface AuditCheck {
name: string
description: string