Skip to content

feat: optional local preprocessor hook (off by default) - #17

Open
Shifat7 wants to merge 1 commit into
clutchpbcfo:mainfrom
Shifat7:pr-10-local-preprocessor
Open

Shifat7 wants to merge 1 commit into
clutchpbcfo:mainfrom
Shifat7:pr-10-local-preprocessor

Conversation

@Shifat7

@Shifat7 Shifat7 commented Aug 22, 2026

Copy link
Copy Markdown

What changed

Optional local preprocessing before dispatching to Hyperagent:

  • src/preprocessor.mjsrunLocalPreprocessor(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.
  • src/bridge.mjs — injectable preprocessor; default wiring requires both enableLocalPreprocessor: true and an explicit localPreprocessorCommand. Rejections → HTTP 400 preprocessor_rejected with a generic public message; reasons only in local logs. Fail-closed → HTTP 503 preprocessor_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.

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.
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.

1 participant