Files
plugins/packages/privacy-gate/docs/operations.md
T
Muyang d34785ae88 privacy-gate 0.3.1: guide prompts name a coarse media class, never the raw media_type (#838)
privacy-gate 0.3.1 (siml1169, #838): guide mode names a fixed coarse media
class (image, pdf, office, audio, video, unknown) instead of copying the
part's media_type into the prompt, so no clipped or fake MIME prefix can
reach the vendor. Parameters are stripped first, a candidate over 256
characters is ignored before it is normalised, and the part's kind is the
fallback. Bytes are still withheld. Fixes #795.

Reviewed at 2b74b6e69ecaf0d20bd9f5fd4580f673da266736 (base = main b8100001;
mote, Bun 1.4.2, temp HOME):
- packages/privacy-gate `bun test`: 67 pass, 0 fail
- `bun scripts/check.mjs privacy-gate` and `bun scripts/check.mjs`: ok
- repo root `bun test`: 6822 pass, 20 skip, 0 fail
- broken by hand: main's middleware 10 red; no 256 guard, no parameter
  strip, no office mapping, no kind fallback each 1 red (its own case);
  echoing the raw candidate 9 red
- CI run 42377224277 green
Not tried: a real guide-mode request through magpie.
2026-11-07 22:06:22 +08:00

3.9 KiB

ShyPie

Operations

Installation, configuration, verification and troubleshooting for the Magpie middleware.

Install

magpie plugin add @magpie-community/middleware-privacy-gate
magpie plugin

Confirm that Magpie's built-in JS gateway plugins plugin is on (Settings → Plugins → Built-in, id middleware). If it is off, no middleware runs.

For a gateway where only Magpie-routed DSH traffic should carry PII as text:

{
  "binaryPolicy": "guide",
  "allowModels": ["deepseek/*", "copilot/*"],
  "localModels": ["ollama/*", "lmstudio/*"],
  "localProviders": ["ollama", "lmstudio"],
  "guideTools": []
}

Use "binaryPolicy": "fail" if you want a hard 403 instead of a withhold-and- prompt response.

guideTools should stay empty unless a matching local MCP extractor is actually configured for the agent. The middleware cannot execute a tool; it only names it in the guide prompt.

Verify

  1. Save options:

    magpie plugin options privacy-gate '{"binaryPolicy":"guide"}'
    magpie plugin
    
  2. Send a request with an image part to a non-local model.

    • guide: HTTP 200, the model asks how to process the file locally, and no image bytes appear at the provider.
    • fail: HTTP 403 and a privacy-gate: message.
  3. Send a text-only request through the same model. It should pass.

  4. Send a request whose text contains a 600-character base64 run. It should be rejected with a BLOB message even if there is no image part.

  5. Check Magpie's plugin log for counts and the usage line. The middleware never logs request content — only provider/model/status/blocked counters.

Troubleshooting

I get a 403 for an image

Expected in fail mode. Either extract the image locally and send text, or set binaryPolicy: "guide" so the model receives metadata and a local-processing prompt instead.

Guide mode returns 200 but the model cannot see the file

Correct. The middleware never forwards the bytes. The model must use a local MCP/extractor that the agent has configured. Without one, the response is advice, not extraction.

An image reaches a local but non-local provider

Set both localModels and localProviders; with only localModels, onProvider blanks the content rather than sending it.

A legitimate request is rejected with BLOB

A long hash, minified line or base64-ish text can exceed the 400-character threshold. Raise blobBase64Chars / blobHexChars deliberately and understand that a larger document can then pass. Do not disable the gate.

The request went through even though the gate is on

Check the Magpie log for onRequest: took too long. Magpie drops a hook after 250 ms and forwards the original request. This is the engine's fail-open behavior, tracked in magpie#5305. The middleware's own budgets reduce the chance of a timeout but cannot change that outcome.

Update and rollback

Update through Magpie's plugin manager (magpie plugin update) and re-check the saved options after a version change.

To roll back to the strictest behavior, remove the options ({}) or set binaryPolicy: fail and clear localModels/localProviders. Removing the plugin leaves agents without the structural check; text masking is unaffected.

Companion deployment

The DSH half is @shypie_privacy/dsh-privacy-gate 0.3.0. It performs local image/PDF extraction before the DSH transcript and enforces the DSH llm/stream egress guard. This Magpie gate then covers every other agent behind the same gateway.

Support