refusectomy 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.4
2
+ Name: refusectomy
3
+ Version: 0.2.0
4
+ Summary: Find, explain and live-monitor model refusals in CLI coding agents (Claude Code, and any agent through a local proxy).
5
+ Author: Sebastian S. Cocioba, Binomica Labs
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Binomica-Labs/refusectomy
8
+ Project-URL: Repository, https://github.com/Binomica-Labs/refusectomy
9
+ Project-URL: Issues, https://github.com/Binomica-Labs/refusectomy/issues
10
+ Project-URL: Changelog, https://github.com/Binomica-Labs/refusectomy/blob/main/CHANGELOG.md
11
+ Keywords: claude,claude-code,llm,refusal,safety-classifier,agents,monitoring
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Software Development :: Debuggers
19
+ Classifier: Topic :: System :: Monitoring
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Dynamic: license-file
24
+
25
+ # Refusectomy
26
+
27
+ [![PyPI](https://img.shields.io/pypi/v/refusectomy.svg)](https://pypi.org/project/refusectomy/)
28
+ [![Standard library only](https://img.shields.io/badge/dependencies-none-3776AB?logo=python&logoColor=white)](https://www.python.org/)
29
+ [![Tests](https://github.com/Binomica-Labs/refusectomy/actions/workflows/test.yml/badge.svg)](https://github.com/Binomica-Labs/refusectomy/actions/workflows/test.yml)
30
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
31
+ [![Status: alpha](https://img.shields.io/badge/status-alpha-orange.svg)](https://github.com/Binomica-Labs/refusectomy)
32
+
33
+ **Find, explain and live-monitor model refusals in CLI coding agents.**
34
+
35
+ By Sebastian S. Cocioba, Binomica Labs.
36
+
37
+ When a safety classifier declines legitimate work, an agent session rarely fails just once. It
38
+ keeps failing, and the obvious fixes (rephrasing, switching models, trimming context) mostly
39
+ don't help. Refusectomy measures what actually happened on your machine, watches for it as it
40
+ happens, and tells you what the evidence supports. It identifies refused text by digest, never by
41
+ printing it.
42
+
43
+ ## What it can see, per agent
44
+
45
+ | agent | how Refusectomy reads it | what you get |
46
+ |---|---|---|
47
+ | **Claude Code** | its session logs, plus a Stop hook | every refusal with the classifier's category, the model, Claude Code's switch to a fallback model, and the refused message (as a digest); full forensics |
48
+ | **Any agent whose API base URL you can set** (Anthropic, OpenAI or Gemini wire format) | `refusectomy proxy` | every response's stop reason as it streams, request ids, and the prompt's digest |
49
+ | **GitHub Copilot CLI** | its session log | tool failures and session errors only: it does not log the model's stop reason |
50
+ | **Antigravity CLI** | its session log | error steps; a safety block only when the agent logs it as an error |
51
+
52
+ `refusectomy agents` prints this table for your own machine.
53
+
54
+ ## Install
55
+
56
+ Python 3.10 or newer, no dependencies.
57
+
58
+ ```bash
59
+ pipx install refusectomy # or: uv tool install refusectomy
60
+ pipx install . # from a checkout
61
+ ```
62
+
63
+ ## Claude Code
64
+
65
+ ```bash
66
+ refusectomy audit # check the parser's assumptions against your transcripts
67
+ refusectomy profile # rates, stickiness, the model comparison, confounds
68
+ refusectomy remedy --category bio # the playbook, rendered from your own profile
69
+ refusectomy watch # live, in a second terminal
70
+ refusectomy report --project DIR # a support-ticket bundle: request ids and digests
71
+ ```
72
+
73
+ To get a warning inside Claude Code the moment a session declines, add the hook to
74
+ `~/.claude/settings.json`:
75
+
76
+ ```json
77
+ { "hooks": {
78
+ "Stop": [{ "hooks": [{ "type": "command", "timeout": 10,
79
+ "command": "refusectomy hook claude-code 2>/dev/null || true" }] }],
80
+ "SessionStart": [{ "hooks": [{ "type": "command", "timeout": 10,
81
+ "command": "refusectomy hook claude-code 2>/dev/null || true" }] }] } }
82
+ ```
83
+
84
+ The warning is shown to you as a `systemMessage`. It is never added to the model's context:
85
+ feeding "you were just declined" back into the context that declined is how one decline turns
86
+ into a run of them.
87
+
88
+ ## Excise: a clean copy of a declined session
89
+
90
+ ```bash
91
+ refusectomy excise --dry-run # what would be removed from the current session
92
+ refusectomy excise # write the clean copy and print its /resume command
93
+ ```
94
+
95
+ To excise between turns, add `--excise` to the hook command (or put `{"excise": true}` in
96
+ `config.json` in the state directory, or set `REFUSECTOMY_EXCISE=1`). When a session declines,
97
+ the warning then names a clean copy to `/resume`. `refusectomy watch --excise` does the same from
98
+ the monitor, waiting until the session's log has gone quiet.
99
+
100
+ **What it removes: the decline's own debris, nothing else.**
101
+
102
+ - Every record of the declined response: the partial output that the refusal docs say to discard.
103
+ - The harness's placeholder notice and its refusal record.
104
+ - The hidden "meta" notice message that Claude Code otherwise sends back to the model.
105
+ - The results of any tool calls made inside the declined response. A call that had already run
106
+ keeps its effects on disk, and the report says how many did.
107
+
108
+ **What it keeps: everything else, byte for byte.** That covers your messages, including any that
109
+ quote the notice, every response that wasn't declined, and all the work material. Excision never
110
+ rewords anything, and never removes content because a classifier reacts to it, so the classifier
111
+ still sees everything you actually asked.
112
+
113
+ **How the copy behaves.** The source session is never modified. Resuming the copy starts on your
114
+ default model, which also releases the refusal-fallback lock.
115
+
116
+ This was verified end to end: Claude Code resumes a cleaned copy. Asked whether any earlier message
117
+ mentioned a safety classifier, the model in the cleaned copy says no, and the same session
118
+ uncleaned says yes.
119
+
120
+ **Whether it prevents the next decline is not yet known.** The run of declines could come from the
121
+ debris, or from the material that is still in context. `profile` reports what happened after each
122
+ clean copy was resumed. Until there is data, abandoning the session remains the measured lever.
123
+
124
+ ## Any other agent, through the proxy
125
+
126
+ ```bash
127
+ refusectomy proxy # loopback only; prints the URL for each provider
128
+ # then point the agent at it, e.g.
129
+ ANTHROPIC_BASE_URL=http://127.0.0.1:8787/anthropic your-agent
130
+ OPENAI_BASE_URL=http://127.0.0.1:8787/openai/v1 your-agent
131
+ refusectomy watch # in another terminal: every agent, one timeline
132
+ ```
133
+
134
+ The proxy forwards each request unchanged to the real API over verified TLS. It relays the
135
+ response back as it streams, reading the stop reason as it goes by. It recognises:
136
+
137
+ - Anthropic: `stop_reason: "refusal"`, with its category.
138
+ - OpenAI: a `content_filter` finish, a `refusal` field, or a Responses refusal or content-filter
139
+ cut-off.
140
+ - Gemini: a safety finish reason or a blocked prompt.
141
+
142
+ Agents that only talk to their vendor's own backend, such as Copilot CLI and Antigravity, can't
143
+ be proxied without intercepting TLS, which Refusectomy doesn't do.
144
+
145
+ ## What the evidence says
146
+
147
+ These come from the corpus this tool was built on. `profile` re-measures each of them on yours.
148
+
149
+ 1. **Declines cluster within a session.** Once one lands, the next request in that session is
150
+ far more likely to decline than a request in a fresh session. Abandon the session; don't
151
+ rephrase inside it.
152
+ 2. **The refused message is rarely the problem.** Most refused messages are a single word, like
153
+ "continue". The decline is about the work accumulated in the context, not the phrasing.
154
+ 3. **Claude Code moves a declined session to another model.** When Opus 5.5 or Fable declines,
155
+ Claude Code retries on Opus 5 and keeps the session there until `/clear` or `/model`. The
156
+ retry usually rescues the turn, but the session stays hot.
157
+ 4. **Compare models only before a session's first decline.** After it, the fallback and the
158
+ cascade decide which model you're on, so turn-level comparisons measure the fallback, not the
159
+ model. Measured the clean way, this corpus showed no evidence that switching models helps.
160
+ 5. **Context size and memory files weren't levers.** The apparent effect of context size was
161
+ survivorship. No memory file was read more often before early declines than in clean
162
+ sessions.
163
+ 6. **The real fix is institutional.** For legitimate work, that means Anthropic's verification
164
+ programs for life sciences and for cyber, plus false-positive reports filed with request ids.
165
+ `report` builds that bundle.
166
+
167
+ `refusectomy profile` prints the numbers behind each one for your own machine, beside the controls
168
+ that keep them honest.
169
+
170
+ ## Privacy and safety
171
+
172
+ - **Refused text is never printed.** It's identified by a sha256 digest and a character shape.
173
+ `--verbatim` writes it to a mode-0600 file for you to read; it never goes to stdout.
174
+ - **Everything stays local.** There is no telemetry and no network access, except the proxy
175
+ forwarding your agent's own requests to the API it was already calling.
176
+ - **The proxy records metadata only.** It listens on loopback only, and never records headers,
177
+ bodies, query strings (where Gemini can carry an API key) or text.
178
+ - **It only observes.** It never rewrites, retries, or searches for phrasings that get past a
179
+ classifier. `bisect` reports what reproduces a decline, nothing more.
180
+ - **Where files go.** Reports and state live in `$REFUSECTOMY_HOME`, or by default in
181
+ `~/.local/state/refusectomy` (Linux), `~/Library/Application Support/refusectomy` (macOS) or
182
+ `%LOCALAPPDATA%\refusectomy` (Windows).
183
+
184
+ ## How it keeps itself honest
185
+
186
+ - `audit` checks the invariants its numbers depend on, against your own transcripts, and exits
187
+ non-zero if any fail.
188
+ - Every figure that `remedy` and the hook quote comes from your last `profile`; none is typed
189
+ into the source.
190
+ - Each bug fix has a regression test on synthetic transcripts. Each of those tests was checked by
191
+ putting the bug back and watching it fail.
192
+
193
+ ## Development
194
+
195
+ ```bash
196
+ python3 -m unittest discover -s tests -t .
197
+ PYTHONPATH=src python3 -m refusectomy audit
198
+ ```
199
+
200
+ The code is in `src/refusectomy/`:
201
+
202
+ - `claude_code.py`: the transcript engine and forensics
203
+ - `providers.py`: each provider's refusal signals
204
+ - `proxy.py`, `agents.py`, `watch.py`: the live monitoring
205
+ - `cli.py`: the command
206
+
207
+ `analysis/` holds exploratory scripts that build on the package.
208
+
209
+ ## License
210
+
211
+ MIT, copyright 2026 Sebastian S. Cocioba, Binomica Labs. See [LICENSE](LICENSE).
@@ -0,0 +1,15 @@
1
+ refusectomy/__init__.py,sha256=2ci9fNM3PzDsw7WmhQBPIJViItm8AKLmkxBiq428l4Y,417
2
+ refusectomy/__main__.py,sha256=O1XSXL1qekoOxx5GD4WS6jyfGy7HIqEH8NBxbCrIwyI,59
3
+ refusectomy/agents.py,sha256=Ik42_1GKH1Qpw-yCT_o3Q-2dBhKkxVRGe792Xw6iYLM,7595
4
+ refusectomy/claude_code.py,sha256=maXydrqmHQcpYAnOieXmroQAbGnXZ8n-NUAzVnlmuTk,141658
5
+ refusectomy/cli.py,sha256=QyH7YRWEcyq_VttIVPW9XSiS73L0UPenOGjK4JYcvTU,4166
6
+ refusectomy/excise.py,sha256=a8W3cbdMQvCkDjaqoN6H0KEe-erl13pTD6ugb1S_6lE,13844
7
+ refusectomy/providers.py,sha256=CUiYP8z71-O4nQ7A-06CFyDy7v2OXFzXudNYJJunkZo,10645
8
+ refusectomy/proxy.py,sha256=arMnkl0PInCnMQCBHJPE0oUZS2To28Lt7T68k9Q3ZLs,13703
9
+ refusectomy/watch.py,sha256=Guxxt9NoO1jkT6x_Fro-5k2cn9Bhdmt1Zvt7UX91sBY,11388
10
+ refusectomy-0.2.0.dist-info/licenses/LICENSE,sha256=DEIWV2JzrbBAPwhAK5Vy-IV6o0oS_pa7j1KKst_Q7m4,1092
11
+ refusectomy-0.2.0.dist-info/METADATA,sha256=Vsm4AmJdLbLdwKl8ke2ezxP_61-CKX0KNRkjeq8bXKs,10761
12
+ refusectomy-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
13
+ refusectomy-0.2.0.dist-info/entry_points.txt,sha256=tQ_CnBx6D3fgmpFqNUMGUrn5WnfE8CI-vb8XalerAcg,53
14
+ refusectomy-0.2.0.dist-info/top_level.txt,sha256=eOYRWVhxlS7uXZecRuBlJp3kxc0F6VhRzOGQY9XMY6Y,12
15
+ refusectomy-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ refusectomy = refusectomy.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sebastian S. Cocioba, Binomica Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ refusectomy