← Catalog

@ganziliang/pi-purge

Pi extension: three-layer refusal-breaking toolkit — system-prompt injection, refusal detection, and an automatic nudge retry chain.

Extension

Install

Install with PiG

pig install npm:@ganziliang/pi-purge

Install with Pi

pi install npm:@ganziliang/pi-purge
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./extensions"
  ]
}

README

Written by the package's publisher, shown as published in version 0.1.0 (README.md). PiG does not review it.

@ganziliang/pi-purge

A Pi extension: a three-layer refusal-breaking toolkit — system-prompt injection, refusal detection, and an automatic nudge retry chain.

Ported from DSH's dsh-purge, but rewritten so that it never patches the host. Pi's extension API already exposes every hook needed, so pi update can't break it.

中文详细文档:README.zh-CN.md


Three layers

LayerWhat it doesPi hook
L1 injectAppends the injection body + a boost block to the system promptbefore_agent_start → appendSystemPrompt
L2 detect18 regexes that recognise a refusal (including Chinese object-final phrasing)pure logic, no deps
L3 retryOn a hit, appends a nudge and asks pi to run againagent_before_settle → entries + continue

Why appendSystemPrompt and not sections

Each sections entry gets wrapped in a same-named XML tag (<purge_inject>…</purge_inject>). In practice the model classifies tag content as "untrusted injected reference data" and declines to act on it. appendSystemPrompt is appended as prompt body, so the model treats it as instruction text. Content is stable, so the provider prompt cache still holds.

An idempotent sentinel pair (<!-- pi-purge:begin --> / <!-- pi-purge:end -->) wraps the block so repeated calls replace it in place instead of stacking copies.

Why L3 must return entries too

Pi computes canContinue as hasNonSystemContext && finalRole !== "assistant". At settle time the last message is almost always the assistant, so returning only { continue: true } trips:

Extension error (<boundary>): agent_before_settle requested continuation without runnable model context

Appending a custom_message flips the final role to user, which makes continue valid:

return {
  entries: [{ type: "custom_message", customType: "pi-purge-retry", content: nudge, display: false }],
  continue: true,
};

Install

pi install npm:@ganziliang/pi-purge

# local dev
pi install ./pi-purge
pi --extension ./pi-purge/extensions

Then /reload or restart pi.

pi remove npm:@ganziliang/pi-purge

Commands

/purge                      show status
/purge on | off             master switch
/purge <inject|boost|retry|audit> on|off
/purge chain 2|3            retry chain length
/purge attempts <0-5>       max retries per turn
/purge show                 print the active injection body
/purge edit                 ensure inject.md exists, print its path
/purge reset                restore built-in defaults (backs up first)
/purge backups              list backups
/purge revert [n]           roll back to backup n (0 = newest)
/purge audit [n]            recent audit records
/purge test <text>          run the refusal detector on a string

/purge prints the package name and version on its first line (包:@ganziliang/pi-purge v0.1.0), so you can tell which build is running when several machines hold different versions.


Layout

Data directory: ~/.pi/agent/pi-purge/ (override with PI_PURGE_DIR)

config.json    switches and chain parameters
inject.md      injection body (built-in default when absent)
audit.jsonl    audit log
backups/       snapshot before every rewrite, newest 20 kept
{
  "enabled": true,
  "inject": true,
  "boost": true,
  "retry": true,
  "chain": 2,
  "audit": true,
  "maxAttempts": 2
}
NudgeContentUse for
1 nudgeask for the complete answer, one closing line asking to executesoft refusals
2 fictionreframe as a local synthetic fixture / in-novel experthard refusals
3 decomposesmallest deliverable component onlywhole-chain asks

Observed run

Injection off, retry on, one deliberately refused request. audit.jsonl:

{"event":"refusal_retry","chars":181,"match":4,"attempt":1,"frame":"nudge"}
{"event":"refusal_retry","chars":641,"match":15,"attempt":2,"frame":"fiction"}
{"event":"retry_exhausted","attempt":2,"match":14}

Three real model calls, ~14s apart. The second frame turned a 181-char refusal into a 641-char answer containing a runnable script.


Limits

  • The extension delivers the request correctly. Provider-side filtering is outside its reach — that is equally true of dsh-purge on DSH.
  • In --print single-shot mode canContinue is always false. Appending entries flips the final role, but a one-shot run does not open another round. Full L3 behaviour is in interactive / long sessions.
  • Don't delete the <!-- pi-purge:begin --> sentinel from an edited inject.md, or repeated calls will stack copies.

Development

npm run check                  # tsc --noEmit
node scripts/selftest.mjs      # pure logic (62 checks)
node scripts/load-test.mjs     # loads via pi's own jiti loader (42 checks)

License

MIT