Skip to content

Block mutating tool calls in pi extension to surface context before edits#69

Merged
gregology merged 1 commit intomainfrom
pi-block-mutating-tools
Mar 14, 2026
Merged

Block mutating tool calls in pi extension to surface context before edits#69
gregology merged 1 commit intomainfrom
pi-block-mutating-tools

Conversation

@gregology
Copy link
Copy Markdown
Contributor

@gregology gregology bot commented Mar 13, 2026

Closes #68

The pi extension was delivering when: before context after the edit had already happened — it stored context during tool_call and then appended it to the tool_result. That completely defeats the purpose of before timing for mutating tools.

Now, when pi calls edit or write, the extension checks for matching context and if there is any, blocks the tool call with { block: true, reason: ... }. The agent sees the context first, then re-applies its change with that knowledge. Non-mutating tools (like read) still get context appended to the tool result as before.

The alternative was to inject context into the tool input rather than blocking, but pi's block API is the right fit here — it forces the agent to actually process the context before proceeding rather than potentially ignoring injected input. Blocking also gives the agent a chance to revise its edit based on the context, which is the whole point of before timing.

Updated docs in getting-started.md and cli-reference.md to describe the new behavior.

Dev Ghost metrics

Total duration: 7m 0s
Turns: 75
Tool calls: 57
Tokens: 389,932 input / 4,954 output

Stage Model Duration Turns Tool calls Tokens (in/out) Cache read Cache creation
triage claude-opus-4-6 1m 57s 31 27 79,859 / 1,654 67,141 12,710
implementation claude-opus-4-6 3m 45s 21 14 20,405 / 52 9,240 11,162
evaluation claude-opus-4-6 0m 22s 5 3 53,731 / 696 44,558 9,166
docs_review claude-opus-4-6 0m 42s 17 12 178,825 / 2,193 157,078 21,733
craft_pr claude-opus-4-6 0m 12s 1 1 57,112 / 359 28,367 28,742

Resolves #68

@gregology gregology merged commit d396ecc into main Mar 14, 2026
2 checks passed
@gregology gregology deleted the pi-block-mutating-tools branch March 14, 2026 02:14
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.

Improve the sctx.ts extension so that it passes the context prior to the edit

1 participant