Skip to content

Conversation

@mitsuhiko
Copy link
Contributor

@mitsuhiko mitsuhiko commented Jan 22, 2026

Discussion:

image

This allows hooking bash execution and it also allows tool_result hooks to manipulate error messages by "abusing" content to carry error messages. This feels somewhat consistent to how it works but a bit ugly.

@mitsuhiko mitsuhiko force-pushed the intercept-bash branch 2 times, most recently from 8664526 to 1d70707 Compare January 22, 2026 13:25
@mitsuhiko mitsuhiko marked this pull request as draft January 22, 2026 18:14
const nextDetails = (resultResult.details ?? result.details) as T;
if (resultResult.isError) {
forcedError = true;
throw new Error(toolResultContentToErrorMessage(nextContent, "Tool execution failed."));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really cannot think of a better idea here.

@mitsuhiko mitsuhiko marked this pull request as ready for review January 22, 2026 19:58
@cv
Copy link
Contributor

cv commented Jan 22, 2026

Happy to modify/rewrite the examples/ssh.ts (and my own pi-ssh-remote) when this lands.

@mitsuhiko
Copy link
Contributor Author

@cv it should in theory work with it already, the question in a way is if ssh.ts can further benefit from the changes.

@dejanr
Copy link

dejanr commented Jan 23, 2026

This could be really nice for project purposes, instead of blowing agents.md and instructions on how to run sandboxed environment, we could just build custom extensions that are preparing env for tool, is that nix develop, or uv, or whatever else that someone uses.

From architectural point of view i would prefer a middleware approach to tool wrapping, then dangling handlers.


**Examples:** [chalk-logger.ts](../examples/extensions/chalk-logger.ts), [permission-gate.ts](../examples/extensions/permission-gate.ts), [plan-mode/index.ts](../examples/extensions/plan-mode/index.ts), [protected-paths.ts](../examples/extensions/protected-paths.ts)

#### before_bash_exec
Copy link

@Mic92 Mic92 Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be very useful for direnv integration! I am currently doing this: https://github.com/Mic92/dotfiles/blob/main/home/.pi/agent/extensions/direnv.ts

One thing that is missing is knowing what directory the agent tries to access. Often the agent prepends cd but it feels a bit hacky. But maybe cd() could be replaced by a function with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants