omp packages

pi-context-mode-injection-filter0.1.17

Pi extension that prevents context-mode's synthetic routing message from superseding the latest user request.

GitHub Actions Published 1 day ago MIT ~300 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-context-mode-injection-filter

Join dotfield.xyz on Discord

CI Publish npm version npm downloads License: MIT Pi package Trusted Publishing

Keep context-mode's synthetic routing guidance from becoming the newest user request sent to a model.

What this is

pi-context-mode-injection-filter is a small Pi extension for projects that use context-mode. It intercepts the serialized provider payload immediately before each model request.

When context-mode appends its known synthetic routing message after the real prompt, this extension removes the routing anchor. Only a user-role message is relocated: if that synthetic message also contains active-memory content, the extension keeps it after the consecutive leading instruction messages and before the rest of the original messages. Instruction messages are the ones Pi serializes the system prompt with: system, or developer for OpenAI-family reasoning models. If no original instruction message leads the array, the retained memory goes at the start. An anchored assistant or system message is stripped in place and keeps its index, so a cleaned turn cannot be reordered.

For example, [routing guidance] stands in for the exact routing anchor:

Before                             | After
system: Reply briefly.             | system: Reply briefly.
user: List some colors.            | user: Active memory: favorite is blue.
assistant: Blue and green.         | user: List some colors.
user: Which one is my favorite?    | assistant: Blue and green.
user: [routing guidance]           | user: Which one is my favorite?
      Active memory: favorite is blue.

Features

  • Processes messages and input arrays independently when present; it never merges them.
  • Removes the exact context-mode routing anchor recursively.
  • Keeps non-empty active-memory content from the synthetic message and moves it after the leading instruction messages (system or developer) and before the conversation, which only applies to user-role messages.
  • Strips an anchored assistant or system message in place, preserving its position in the conversation.
  • Drops a message whose content becomes empty after stripping, on every role.
  • Adds no runtime dependencies and performs no file or network I/O.

Install

Global:

pi install npm:pi-context-mode-injection-filter

Project-local:

pi install npm:pi-context-mode-injection-filter -l

Try without installing:

pi -e npm:pi-context-mode-injection-filter

Quick start

Install this package alongside context-mode, then restart Pi or run /reload. No command or configuration is required. The extension runs on every provider request through Pi's before_provider_request event.

Compatibility

This is an intentionally narrow compatibility shim, not a general payload sanitizer. It recognizes the exact context-mode routing anchor exported in lib/filter-provider-payload.ts. If context-mode changes that text, this package may need a matching update. Any message containing that full anchor is treated as synthetic, so do not use this package when preserving a verbatim copy of the anchor in model input is required. A real user message that quotes the anchor mid-text is therefore still treated as the synthetic message and relocated before the conversation; only the exact-anchor match is used, so this limitation is unchanged.

Package contents

Path Purpose
extensions/index.ts Registers the provider-request hook.
lib/filter-provider-payload.ts Detects, strips, retains, and reorders payload messages.
docs/release.md Trusted Publishing setup and release flow.

Development

npm install
npm run ci
pi -e .

npm run ci runs TypeScript checks, tests, npm pack --dry-run, and the workflow token guard.

Release

Releases use npm Trusted Publishing through GitHub Actions. Long-lived npm tokens are not used. See docs/release.md.

Security

Pi packages execute with local user permissions. This extension only transforms the in-memory provider payload; it does not execute commands, read files, or send additional network requests. Review source before installation.

See SECURITY.md for vulnerability reporting.

Links

License

MIT