Executor middleware chain: Permission + Audit#4
Merged
Conversation
Move tool execution behind one transparent entry point (ExecutorInterface) with a middleware onion (ChainExecutor), as ARCHITECTURE.md describes. The inline gatekeeper in Session::execute() becomes PermissionMiddleware; a new AuditMiddleware logs every tool call — including blocked/denied ones — to a new SQLite 'audit' table. Session now builds the chain from its existing deps and delegates; behaviour is unchanged (the existing SessionTest still passes through the chain). Adds SessionStore::logToolCall/auditTrail + the audit table. Timeout middleware and /stop cancellation are the deferred follow-up. 88 tests, PHPStan level 8, php-cs-fixer — all green.
Contributor
Author
|
Added TimeoutMiddleware to the chain (innermost): runs each tool in a child coroutine and awaits it with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Moves tool execution behind one transparent entry point with a middleware onion — the
ARCHITECTURE.md"Executor + middleware chain" design. First slice of the executor arc.New (
src/Exec/)ExecutorInterface/MiddlewareInterface— the contract:call(ToolCall): ToolResultBlock, and middlewares that wrap$next(inspect / short-circuit / log).ChainExecutor— composes the onion around a terminal handler (outer → inner).PermissionMiddleware— the security layer, lifted out ofSession::execute(): resolves the tool's Risk, asksPolicy, then blocks / asks the user (Confirm) / passes through; an "always" approval persists a rule.AuditMiddleware— logs every call (including blocked/denied) to a new SQLiteaudittable; sits outermost so it captures the verdict.Changed
Sessionbuilds the chain from its existing deps (policy,tools,conversation,store) and delegates; the terminal stage (runTool) resolves + runs the tool. Behaviour is unchanged — the existingSessionTestnow exercises the chain and still passes.SessionStore:audittable +logToolCall()/auditTrail().Why now
The agent is remotely reachable (Telegram) and runs
bash, so an action trail matters; and pulling the gatekeeper into the chain is the home the next middlewares plug into.Deferred (next slice)
TimeoutMiddleware(\Async\timeout()around a tool) +/stopturn cancellation.Tests
tests/Exec/*— chain ordering + short-circuit; permission allow/deny/confirm; audit logs + no-op without a store.88 tests pass, PHPStan level 8 clean, php-cs-fixer clean.