fix(core): expose Instance.directory to custom tools

This commit is contained in:
adamelmore
2026-01-26 19:57:34 -06:00
parent 6cf2c3e3db
commit a8c18dba82
4 changed files with 15 additions and 7 deletions

View File

@@ -24,7 +24,7 @@ export const ReadTool = Tool.define("read", {
async execute(params, ctx) {
let filepath = params.filePath
if (!path.isAbsolute(filepath)) {
filepath = path.join(Instance.directory, filepath)
filepath = path.resolve(Instance.directory, filepath)
}
const title = path.relative(Instance.worktree, filepath)

View File

@@ -16,7 +16,7 @@ import { Tool } from "./tool"
import { Instance } from "../project/instance"
import { Config } from "../config/config"
import path from "path"
import { type ToolDefinition } from "@opencode-ai/plugin"
import { type ToolContext as PluginToolContext, type ToolDefinition } from "@opencode-ai/plugin"
import z from "zod"
import { Plugin } from "../plugin"
import { WebSearchTool } from "./websearch"
@@ -67,7 +67,8 @@ export namespace ToolRegistry {
parameters: z.object(def.args),
description: def.description,
execute: async (args, ctx) => {
const result = await def.execute(args as any, ctx)
const pluginCtx = { ...ctx, directory: Instance.directory } as unknown as PluginToolContext
const result = await def.execute(args as any, pluginCtx)
const out = await Truncate.output(result, {}, initCtx?.agent)
return {
title: "",