agentleFS
sm1eesm1ee/Sniper/AGENTS.md

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.

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
  1. Very specific:

    Universal builds need the rustup toolchain: If Homebrew's Rust comes first on PATH the x86_64-apple-darwin standard library is missing and …

    line 43
  2. Very specific:

    A new workspace section: must also be adopted in adoptExternalWorkspace (web/app.js).

    line 129
  3. Distinctive:

    When you touch this layer, test across a restart.

    line 176
  4. Very specific:

    Use example.com. Fixtures are public the moment they are pushed.

    line 223
  5. Common:

    No hardcoded secrets, obviously.

    line 225
  6. Very specific:

    Update the Homebrew cask. packaging/homebrew/render-cask.sh fills the version and the DMG's SHA-256 into packaging/homebrew/sniper.rb.

    line 251
  7. Very specific:

    Every package ships a .sha256 in the <hash> <filename> form, so a downloader can check any of them with shasum -a 256 -c.

    line 257
  8. Distinctive:

    Commit messages: imperative one-line subject describing the behaviour change ("Stop discarding captured traffic"), then a body explaining …

    line 311
  9. Distinctive:

    Prefer fixing the shared function over guarding each caller.

    line 314
  10. Distinctive:

    Don't add a dependency for something a few lines can do.

    line 315

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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.

BinaryWhat it is
sniper-desktopThe shipped app. A native window (wry/WebKit) that hosts the UI and runs the proxy in-process.
sniperThe same server without a window. Useful for testing and for driving Sniper from elsewhere.
sniper-cliA 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 committing

Three 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 ~/.sniper fails — and worse, starting one instance against it attaches to whatever real session the developer has open. Never run a scratch build without setting SNIPER_DATA_DIR. Even sniper --help boots far enough to take the lock.
  • Universal builds need the rustup toolchain. If Homebrew's Rust comes first on PATH the x86_64-apple-darwin standard library is missing and the build dies with can't find crate for core. Prefix release builds with PATH="$HOME/.cargo/bin:$PATH".
  • Run the suite with --release. cargo test works, 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/transactions

Stand 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.

ChangeFiles
Proxy path, MITM, replaysrc/proxy.rs
HTTP API and the UI serversrc/api.rs (largest module, ~17k lines)
Session lifecycle and on-disk formatsrc/session.rs, src/state.rs
A proxy port for one sessionsrc/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 groupSessionMetadata 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, widthsessionSidebarLayout, 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, sortingsrc/store.rs
Opening a pre-wired browsersrc/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 matchingsrc/scope.rs — the only matcher; do not add a second one
Intercept queuessrc/intercept.rs
TCP and UDP relay, its history, intercept and replaysrc/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)
Frontendweb/app.js, web/index.html, web/styles.css

Changes that must land in more than one place:

  • A new history column needs HISTORY_COLUMN_DEFS in web/app.js, the sort key whitelist in validate_transaction_sort_key (src/api.rs), and the value_parser list in src/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-cli subcommand 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.rs and 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.activeSession is the session on screen and state.viewedSessionId the one the next load shows. Read and write by session_id, and do not send expected_active_session_id. sessionFeed(id) says how traffic reaches a session; ask it, not session.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 as sniper-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:

FileHolds
snapshot.jsonSession metadata
state.jsonSmall, frequently-changing components
workspace.jsonUI workspace: replay tabs, layout
transactions.ndjsonCaptured transactions, one JSON object per line
transactions.meta.ndjsonThe same records without bodies — the load path
transactions.journal, websockets.journalAppend-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:

  1. 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 rewrites transactions.ndjson moves every offset, so it must return the new locators and hand them to TransactionStore::adopt_written_locators. Skip this and opening a record silently shows another request's traffic — no error, no crash, wrong data.
  2. Every write is atomic: temp file, fsync, rename (write_json, TempJsonFile in src/session.rs). Do not write in place.
  3. 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 debounced SessionContext::schedule_state_persist.
  4. The workspace uses optimistic concurrency — revision plus client_id/client_version, gated by can_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.
  5. 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.js is 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.rs use serde's skip_serializing_if = "Option::is_none", so a cleared value is absent from the response rather than null. Merging with Object.assign then 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, and remote_ui_auth_guard rejects 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_targets in src/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.

  1. Bump version in Cargo.toml, then cargo update -w to sync Cargo.lock.
  2. Merge to main and push.
  3. 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
  1. Tag vX.Y.Z (lightweight, at the released commit), push the tag, and publish with gh release create attaching dist/Sniper-X.Y.Z-universal.dmg and its .sha256.
  2. The Windows and Linux packages attach themselves. Pushing the tag runs .github/workflows/windows.yml and .github/workflows/linux.yml, which build their packages and wait up to fifteen minutes for the release to appear before uploading them: the Windows .zip and -setup.exe, and the Debian .deb and .tar.gz with 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.
  3. Update the Homebrew cask. packaging/homebrew/render-cask.sh fills the version and the DMG's SHA-256 into packaging/homebrew/sniper.rb; write it to Casks/sniper.rb in a clone of sm1ee/homebrew-tap and commit it as sniper X.Y.Z. Until then brew install --cask sm1ee/tap/sniper installs 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=1 is 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 plus APPLE_ID, APPLE_TEAM_ID and APPLE_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, never cp. cp does 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/Sniper must be the sniper-desktop build. make-app.sh does this correctly; hand-assembling a bundle with the headless sniper binary produces an app that starts a server and never opens a window.

9. Conventions

  • cargo fmt before 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 log for the register.
  • Prefer fixing the shared function over guarding each caller.
  • Don't add a dependency for something a few lines can do.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.