Conversation
Add runLocalPreprocessor() executing a configured local command with sanitised request metadata on stdin (requestId, model, toolCount, inputChars; never prompt content) and honouring an explicit reject decision as HTTP 400 preprocessor_rejected. Timeouts kill the child; spawn errors, non-zero exits, and invalid JSON follow the configured failure mode: fallback allows with a logged reason, fail_closed returns HTTP 503 preprocessor_failed. Disabled by default: enableLocalPreprocessor plus an explicit localPreprocessorCommand are both required.
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 changed
Optional local preprocessing before dispatching to Hyperagent:
runLocalPreprocessor(config, payload, {spawnImpl}): runs the configured command with sanitised JSON on stdin (requestId,model,toolCount,inputChars— never prompt content), parses a strict decision protocol ({"action":"reject","reason"}), enforces the timeout by killing the child, and routes every failure (timeout / spawn error / non-zero exit / invalid JSON) through the configured mode.preprocessor; default wiring requires bothenableLocalPreprocessor: trueand an explicitlocalPreprocessorCommand. Rejections → HTTP 400preprocessor_rejectedwith a generic public message; reasons only in local logs. Fail-closed → HTTP 503preprocessor_failed.Config:
enableLocalPreprocessor(false),localPreprocessorCommand(null),localPreprocessorTimeoutMs(3000),localPreprocessorFailureMode('fallback' | 'fail_closed').Non-goals honoured: no code writing, no Hyperagent reasoning replacement.
Testing
npm test: 80 pass, 0 fail. Unit tests cover never-spawn-when-disabled, stdin sanitation, decision handling, timeout kill + both failure modes, invalid JSON; bridge tests cover reject/fail-closed HTTP semantics, dispatch prevention, and pass-through.