diff options
| author | adamelmore <[email protected]> | 2026-01-26 19:57:34 -0600 |
|---|---|---|
| committer | adamelmore <[email protected]> | 2026-01-26 20:07:47 -0600 |
| commit | a8c18dba8205d7707a46ec0859db672370be8963 (patch) | |
| tree | f3fec0ffabe3119732a76032a022d05aec7f1ad1 /packages/web/src | |
| parent | 6cf2c3e3db629757bcace9528b0c84f107bf73a7 (diff) | |
| download | opencode-a8c18dba8205d7707a46ec0859db672370be8963.tar.gz opencode-a8c18dba8205d7707a46ec0859db672370be8963.zip | |
fix(core): expose Instance.directory to custom tools
Diffstat (limited to 'packages/web/src')
| -rw-r--r-- | packages/web/src/content/docs/custom-tools.mdx | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/packages/web/src/content/docs/custom-tools.mdx b/packages/web/src/content/docs/custom-tools.mdx index e089a035b..ef93a64e2 100644 --- a/packages/web/src/content/docs/custom-tools.mdx +++ b/packages/web/src/content/docs/custom-tools.mdx @@ -120,8 +120,8 @@ export default tool({ args: {}, async execute(args, context) { // Access context information - const { agent, sessionID, messageID } = context - return `Agent: ${agent}, Session: ${sessionID}, Message: ${messageID}` + const { agent, sessionID, messageID, directory } = context + return `Agent: ${agent}, Session: ${sessionID}, Message: ${messageID}, Directory: ${directory}` }, }) ``` @@ -148,6 +148,7 @@ Then create the tool definition that invokes it: ```ts title=".opencode/tools/python-add.ts" {10} import { tool } from "@opencode-ai/plugin" +import path from "path" export default tool({ description: "Add two numbers using Python", @@ -155,8 +156,9 @@ export default tool({ a: tool.schema.number().describe("First number"), b: tool.schema.number().describe("Second number"), }, - async execute(args) { - const result = await Bun.$`python3 .opencode/tools/add.py ${args.a} ${args.b}`.text() + async execute(args, context) { + const script = path.join(context.directory, ".opencode/tools/add.py") + const result = await Bun.$`python3 ${script} ${args.a} ${args.b}`.text() return result.trim() }, }) |
