Install
Install with PiG
pig install npm:@ganziliang/pi-purgeInstall with Pi
pi install npm:@ganziliang/pi-purgePackages 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
| Layer | What it does | Pi hook |
|---|---|---|
| L1 inject | Appends the injection body + a boost block to the system prompt | before_agent_start → appendSystemPrompt |
| L2 detect | 18 regexes that recognise a refusal (including Chinese object-final phrasing) | pure logic, no deps |
| L3 retry | On a hit, appends a nudge and asks pi to run again | agent_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
}
| Nudge | Content | Use for |
|---|---|---|
1 nudge | ask for the complete answer, one closing line asking to execute | soft refusals |
2 fiction | reframe as a local synthetic fixture / in-novel expert | hard refusals |
3 decompose | smallest deliverable component only | whole-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-purgeon DSH. - In
--printsingle-shot modecanContinueis always false. Appendingentriesflips 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 editedinject.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