docs(core): plugin tool context updates
This commit is contained in:
@@ -120,12 +120,15 @@ export default tool({
|
|||||||
args: {},
|
args: {},
|
||||||
async execute(args, context) {
|
async execute(args, context) {
|
||||||
// Access context information
|
// Access context information
|
||||||
const { agent, sessionID, messageID, directory } = context
|
const { agent, sessionID, messageID, directory, worktree } = context
|
||||||
return `Agent: ${agent}, Session: ${sessionID}, Message: ${messageID}, Directory: ${directory}`
|
return `Agent: ${agent}, Session: ${sessionID}, Message: ${messageID}, Directory: ${directory}, Worktree: ${worktree}`
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Use `context.directory` for the session working directory.
|
||||||
|
Use `context.worktree` for the git worktree root.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
@@ -157,7 +160,7 @@ export default tool({
|
|||||||
b: tool.schema.number().describe("Second number"),
|
b: tool.schema.number().describe("Second number"),
|
||||||
},
|
},
|
||||||
async execute(args, context) {
|
async execute(args, context) {
|
||||||
const script = path.join(context.directory, ".opencode/tools/add.py")
|
const script = path.join(context.worktree, ".opencode/tools/add.py")
|
||||||
const result = await Bun.$`python3 ${script} ${args.a} ${args.b}`.text()
|
const result = await Bun.$`python3 ${script} ${args.a} ${args.b}`.text()
|
||||||
return result.trim()
|
return result.trim()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -269,8 +269,9 @@ export const CustomToolsPlugin: Plugin = async (ctx) => {
|
|||||||
args: {
|
args: {
|
||||||
foo: tool.schema.string(),
|
foo: tool.schema.string(),
|
||||||
},
|
},
|
||||||
async execute(args, ctx) {
|
async execute(args, context) {
|
||||||
return `Hello ${args.foo}!`
|
const { directory, worktree } = context
|
||||||
|
return `Hello ${args.foo} from ${directory} (worktree: ${worktree})`
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user