Sniper
AGENTS.md22 starsChanged 27 days agoMITView on GitHub
Notes for anyone — human or coding agent — making changes to this repository. This file covers what you need to make a change safely. It deliberately does not repeat README.md (what Sniper is, how to install it, the CLI surface) or docs/architecture.md (why it is built this way). Read those for context; read this before you edit. Sniper is an intercepting proxy for web security testing: a Rust backend with an embedded web UI. Three binaries come out of…
- Deletes or force-pushes
- Installs packages
- Sends data out
- Commits and pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,337 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- docs/llms.txtllms.txt
The file
We split this AGENTS.md into the rules it gives an agent
10 rules. About 1 is common, 4 are distinctive, and 5 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 43
Universal builds need the rustup toolchain: If Homebrew's Rust comes first on PATH the x86_64-apple-darwin standard library is missing and …
- Very specific: line 129
A new workspace section: must also be adopted in adoptExternalWorkspace (web/app.js).
- Distinctive: line 176
When you touch this layer, test across a restart.
- Very specific: line 223
Use example.com. Fixtures are public the moment they are pushed.
- Common: line 225
No hardcoded secrets, obviously.
- Very specific: line 251
Update the Homebrew cask. packaging/homebrew/render-cask.sh fills the version and the DMG's SHA-256 into packaging/homebrew/sniper.rb.
- Very specific: line 257
Every package ships a .sha256 in the <hash> <filename> form, so a downloader can check any of them with shasum -a 256 -c.
- Distinctive: line 311
Commit messages: imperative one-line subject describing the behaviour change ("Stop discarding captured traffic"), then a body explaining …
- Distinctive: line 314
Prefer fixing the shared function over guarding each caller.
- Distinctive: line 315
Don't add a dependency for something a few lines can do.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Working on Sniper
Notes for anyone — human or coding agent — making changes to this repository.
This file covers what you need to make a change safely. It deliberately does not repeat README.md (what Sniper is, how to install it, the CLI surface) or docs/architecture.md (why it is built this way). Read those for context; read this before you edit.
1. Orientation
Sniper is an intercepting proxy for web security testing: a Rust backend with an embedded web UI. Three binaries come out of one crate.
| Binary | What it is |
sniper-desktop | The shipped app. A native window (wry/WebKit) that hosts the UI and runs the proxy in-process. |
sniper | The same server without a window. Useful for testing and for driving Sniper from elsewhere. |
sniper-cli | A JSON-first CLI that talks to a running instance over its local HTTP API. |
The frontend in web/ is plain HTML/CSS/JS with no build step. It is
compiled into the binary with rust-embed (src/api.rs), which has one
consequence worth internalising: editing a .js or .html file does nothing
until you rebuild.
2. Build, run, test
cargo run --bin sniper-desktop # desktop app
cargo run --bin sniper # headless server
cargo test --release --lib # unit tests, ~20s
cargo test --release # everything, including tests/
cargo fmt # required before committingThree things that will cost you time if you learn them the hard way:
- One runtime per data dir. Sniper locks its data directory. Starting a
second instance against the default
~/.sniperfails — and worse, starting one instance against it attaches to whatever real session the developer has open. Never run a scratch build without settingSNIPER_DATA_DIR. Evensniper --helpboots far enough to take the lock. - Universal builds need the rustup toolchain. If Homebrew's Rust comes first
on
PATHthex86_64-apple-darwinstandard library is missing and the build dies withcan't find crate for core. Prefix release builds withPATH="$HOME/.cargo/bin:$PATH". - Run the suite with
--release.cargo testworks, but the release profile is what the packaging path builds, and the full suite finishes in about 20 seconds there — quick enough to run on every change.
3. Runtime testing
Unit tests do not exercise the proxy. Anything that touches capture, intercept,
replay, scope or persistence should be verified against a running instance
before you call it done. Run it isolated — never against ~/.sniper:
SNIPER_DATA_DIR=/tmp/sniper-test \
SNIPER_UI_ADDR=127.0.0.1:18899 \
SNIPER_PROXY_ADDR=127.0.0.1:18890 \
./target/release/sniper &Then drive it over the local API and send traffic through the proxy:
curl -s -X POST http://127.0.0.1:18899/api/runtime \
-H 'content-type: application/json' \
-d '{"intercept_enabled":true,"intercept_scope_only":false}'
curl -s -x http://127.0.0.1:18890 http://127.0.0.1:18891/some/path # your own upstream
curl -s http://127.0.0.1:18899/api/intercepts
curl -s http://127.0.0.1:18899/api/transactionsStand up a throwaway upstream (a few lines of Python is fine) rather than pointing tests at a real host. Poll the queues instead of sleeping a fixed interval — intercepts appear asynchronously.
4. Where things live
docs/architecture.md lists the modules. This is the reverse index: what to open for a
given change, including the parts that are easy to miss.
| Change | Files |
| Proxy path, MITM, replay | src/proxy.rs |
| HTTP API and the UI server | src/api.rs (largest module, ~17k lines) |
| Session lifecycle and on-disk format | src/session.rs, src/state.rs |
| A proxy port for one session | src/session_ports.rs (numbers, the registry, OwnListeners), open_session_port and close_session_port in src/state.rs, serve_session_port and end_session_port_work in src/proxy.rs, the proxy-port routes in src/api.rs, session port in src/bin/sniper-cli.rs |
| Who made a session, and its group | SessionMetadata and update_metadata in src/session.rs (both are the registry's own, like the name: a save of the session must not put back its copy), named_actor and the group route in src/api.rs, the header in api_client_builder (src/bin/sniper-cli.rs), sessionMakerMark, sessionSidebarLayout and the drag handlers on the list (web/app.js), the dragged order in src/ui_settings.rs, [data-actor] in web/styles.css (one glyph for a Replay tab and for a session), session group in src/bin/sniper-cli.rs |
| The session list's own choices: pins, sort, what a row shows, kept groups, where Default is, folded sections, width | sessionSidebarLayout, sessionFolderOrder, sessionSortOrder, sessionRowDetail, showSessionViewMenu and bindSessionSidebarResizer (web/app.js); session_pinned, session_sort, session_row_details, session_group_order, session_default_after, session_sections_collapsed and session_sidebar_width in src/ui_settings.rs. They are the UI's alone: the registry and the CLI know none of them. A group no session is in exists only in session_group_order, and "Default" is the list's name for the sessions in no group, not a group |
| Transaction storage, filtering, sorting | src/store.rs |
| Opening a pre-wired browser | src/browser.rs (launch, SPKI trust, profile, which browser auto picks), launch_browser and set_browser_preference in src/api.rs, the saved default in src/ui_settings.rs, capture browser in src/bin/sniper-cli.rs, the launcher in web/ (one component mounted by [data-browser-launcher]). A browser for a session with its own port: browser_launch_target in src/api.rs, LaunchContext::for_session, and the profiles in browser-profiles/session-<id>/, which recover_driver_ports and sweep_session_profiles read |
| Scope matching | src/scope.rs — the only matcher; do not add a second one |
| Intercept queues | src/intercept.rs |
| TCP and UDP relay, its history, intercept and replay | src/tcp_capture.rs, src/tcp_capture/history_io.rs, web/tcp-capture.js; its listener form sits in Capture ▸ Settings (web/index.html); CONNECT tunnels reach it from serve_connect_tunnel in src/proxy.rs; sniper-cli tcp in src/bin/sniper-cli.rs. Which session a change reaches, and when a session's listeners run: tcp_session and change_tcp_listeners in src/state.rs; the list's tcp:9000 token is SessionActivity.tcp (src/session.rs) drawn by sessionSidebarRow (web/app.js) |
| Frontend | web/app.js, web/index.html, web/styles.css |
Changes that must land in more than one place:
- A new history column needs
HISTORY_COLUMN_DEFSinweb/app.js, the sort key whitelist invalidate_transaction_sort_key(src/api.rs), and thevalue_parserlist insrc/bin/sniper-cli.rs. Miss the second and sorting returns 400; miss the third and the CLI rejects a key the UI offers. - A new API endpoint usually wants a
sniper-clisubcommand too. The CLI is how automation and AI agents drive Sniper; an API-only feature is invisible to them. - Scope semantics are shared by the history filter, intercept, and the site
map. Change
src/scope.rsand all three follow. - A session has one writable context. A session port holds it, and every
API write to that session resolves to the same
Arc(AppState::session_port_context). Do not load a context for a session another way: a second one on the same directory shows another request's body with no error. This is also what lets a session be written while work runs in it; no check refuses such a write. - A session's relay listeners run while it receives. They start where a
session starts to receive (
start_saved_tcp_listeners, activation,open_session_port_as,resume_after_cancelled_shutdown) and stop where it stops (activation,finish_closing_session_port, shutdown). A new way for a session to receive must do both. A listener that ran in a session nothing reaches would have nothing to stop it, and a delete would not wait for it. - A window shows a session; it does not follow the active one. In
web/app.js,state.activeSessionis the session on screen andstate.viewedSessionIdthe one the next load shows. Read and write bysession_id, and do not sendexpected_active_session_id.sessionFeed(id)says how traffic reaches a session; ask it, notsession.active, before offering an action the server refuses for a fed session. - A new workspace section must also be adopted in
adoptExternalWorkspace(web/app.js). The app saves the whole workspace at the revision it last adopted, so a section it does not adopt puts back what another writer, such assniper-cli, just saved there.
5. Persistence invariants
This is the most dangerous area in the codebase. A session is spread across several files under the session's storage directory:
| File | Holds |
snapshot.json | Session metadata |
state.json | Small, frequently-changing components |
workspace.json | UI workspace: replay tabs, layout |
transactions.ndjson | Captured transactions, one JSON object per line |
transactions.meta.ndjson | The same records without bodies — the load path |
transactions.journal, websockets.journal | Append-only, compacted on size |
A change to the small components (settings, rules, the event log) is saved
with AppState::persist_session_state_mutation_locked, which writes
state.json alone. The full save rewrites transactions.ndjson and is for
journal compaction, session switches, shutdown and purging deleted traffic; on
a large session it takes seconds, so a settings change must not go through it.
The invariants:
- Bodies live on disk and are read back by byte offset. A record in memory
may carry a
BodyLocator { offset, len }instead of its body. Any code that rewritestransactions.ndjsonmoves every offset, so it must return the new locators and hand them toTransactionStore::adopt_written_locators. Skip this and opening a record silently shows another request's traffic — no error, no crash, wrong data. - Every write is atomic: temp file, fsync, rename (
write_json,TempJsonFileinsrc/session.rs). Do not write in place. - Never fsync on the proxy runtime. A large session takes seconds to
persist. Blocking inside a tracked proxy task keeps the session permanently
"busy" and blocks session switching. Use
spawn_blocking, or the debouncedSessionContext::schedule_state_persist. - The workspace uses optimistic concurrency —
revisionplusclient_id/client_version, gated bycan_replace_snapshot(src/workspace.rs). A client that has not finished loading must not commit; an empty snapshot that would discard stored replay tabs is rejected server side. Both guards exist because a real session lost every replay tab. - Retention trims, it does not drop. Hitting a cap must not discard captured traffic.
When you touch this layer, test across a restart. Most of these failures are invisible until the process comes back up.
6. Frontend conventions
- Vanilla JS, no framework, no bundler, no
package.json. Keep it that way unless there is a strong reason. web/app.jsis large and organised by feature area. Match the surrounding style rather than introducing a new one.- Rebuild after every frontend edit (see §1).
- Watch out for omitted fields. Many structs in
src/model.rsuse serde'sskip_serializing_if = "Option::is_none", so a cleared value is absent from the response rather thannull. Merging withObject.assignthen keeps the stale value. Reset such fields explicitly when merging a summary. - The intercept editors round-trip a request through text and parse it back.
That normalises headers and can rewrite
Content-Length, so the server cannot tell an edit from a re-parse. The client reports whether the operator actually changed anything.
7. Security posture
Sniper is a security tool that holds other people's traffic. Treat that seriously.
- A loopback bind skips authentication; anything else must not. Loopback is
the default and needs no auth because only this machine can reach it. Binding
the UI anywhere else turns auth on:
UiAccessControl::for_listener(src/api.rs) mints a one-time bootstrap token plus a session token, andremote_ui_auth_guardrejects every request that is neither from this host nor carrying the session cookie. Nothing validates the bind address itself, so that guard is the only thing standing between a remote listener and someone else's captured traffic. Do not remove it, and do not add a path that bypasses it. The proxy is one when it listens beyond loopback, since its own connection to the UI comes from this host. For a client on another machine it refuses requests and tunnels to every port Sniper listens on: the UI, the proxy itself, and the ports the browsers Sniper opened are driven through, at any address of this machine and under any name (remote_client_targetsinsrc/proxy.rs). A new port that Sniper listens on belongs in that list:OwnListeners(src/session_ports.rs) holds the UI, the proxy listener and every open session port, and each guard reads it. It gives two lists. What another machine is refused (refused_to_remote) keeps a listener's address while that listener is down, because the connections it accepted live on. The loop guards (proxies,all) leave it out then. Tell the guards an address before anything listens on it (announce). - Never log captured traffic content — bodies, headers, cookies, or tokens — into event logs, error messages, or temp files.
- Never put a real hostname in a test fixture, UI placeholder, or example.
Use
example.com. Fixtures are public the moment they are pushed; this repository has already had to walk one back. - No hardcoded secrets, obviously. There are none today; keep it that way.
8. Releases
Version work happens on a branch (release/0.2.9), not on main.
- Bump
versioninCargo.toml, thencargo update -wto syncCargo.lock. - Merge to
mainand push. - Build the macOS artifacts from a clean worktree at
origin/main:
PATH="$HOME/.cargo/bin:$PATH" ALLOW_ADHOC_RELEASE=1 DMG_ARCH=universal \
./packaging/macos/release-macos.sh- Tag
vX.Y.Z(lightweight, at the released commit), push the tag, and publish withgh release createattachingdist/Sniper-X.Y.Z-universal.dmgand its.sha256. - The Windows and Linux packages attach themselves. Pushing the tag runs
.github/workflows/windows.ymland.github/workflows/linux.yml, which build their packages and wait up to fifteen minutes for the release to appear before uploading them: the Windows.zipand-setup.exe, and the Debian.deband.tar.gzwith the build manifest and the runtime check's-runtime-PASS.json, each with its.sha256. Create the release in step 4 within that window; if a job gives up, download its artifacts from the run and attach them by hand. - Update the Homebrew cask.
packaging/homebrew/render-cask.shfills the version and the DMG's SHA-256 intopackaging/homebrew/sniper.rb; write it toCasks/sniper.rbin a clone ofsm1ee/homebrew-tapand commit it assniper X.Y.Z. Until thenbrew install --cask sm1ee/tap/sniperinstalls the previous release, which then updates itself.
Every package ships a .sha256 in the <hash> <filename> form, so a
downloader can check any of them with shasum -a 256 -c. Releases are ad-hoc signed,
which makes that checksum the only integrity signal a downloader gets — do not
drop it.
packaging/windows/release-windows.ps1 is the Windows counterpart of
release-macos.sh: same version, worktree, origin/main and duplicate-tag
gates, then make-zip.ps1, then it verifies the recorded checksum and that all
three executables are in the archive. Run it on a Windows machine to produce a
publishable archive outside CI. CI runs it on every push with
ALLOW_ADHOC_RELEASE=1, so the release path is exercised continuously rather
than only at release time.
Two constraints worth knowing:
- The DMG must be universal (
arm64+x86_64). Updater clients from v0.2.4 pick the newest DMG without checking architecture, so a single-arch release would hand an Intel binary to an Apple Silicon machine. The release script enforces this. - Releases are currently ad-hoc signed, not Developer ID signed or
notarized, which is why
ALLOW_ADHOC_RELEASE=1is needed. That flag also skips the clean-worktree, origin/main and duplicate-tag checks — verify those by hand. Moving to real signing needs a Developer ID certificate plusAPPLE_ID,APPLE_TEAM_IDandAPPLE_APP_PASSWORD.
Testing the desktop app on macOS
cargo run --bin sniper-desktop is fine for most work, but anything involving
the window itself — menus, full screen, code signing, the self-updater, TCC
prompts — only behaves correctly from a real .app bundle. Build one and keep
it somewhere stable (~/Desktop/Sniper.app is the convention here):
./packaging/macos/make-app.sh # writes dist/Sniper.app
mv ~/Desktop/Sniper.app ~/Desktop/Sniper.app.prev
ditto dist/Sniper.app ~/Desktop/Sniper.app
rm -rf ~/Desktop/Sniper.app.prev- Use
ditto, nevercp.cpdoes not preserve the bundle's extended attributes and breaks the code signature. - Swap by rename as above. Overwriting a bundle whose executable is currently mapped can crash the running app; renaming leaves it alone until the user quits.
Contents/MacOS/Snipermust be thesniper-desktopbuild.make-app.shdoes this correctly; hand-assembling a bundle with the headlesssniperbinary produces an app that starts a server and never opens a window.
9. Conventions
cargo fmtbefore committing. No warnings introduced.- Comments explain why, not what. The existing code documents the reasoning behind a decision — the failure it prevents, the alternative rejected. Match that. A comment restating the line below it is noise.
- Commit messages: imperative one-line subject describing the behaviour change
("Stop discarding captured traffic"), then a body explaining the cause and the
fix. Look at
git logfor the register. - Prefer fixing the shared function over guarding each caller.
- Don't add a dependency for something a few lines can do.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

