token-field-stamp-sweep

token-field-stamp-sweep is a cursor rule for Cursor from AlphaBitCore/nexus-gateway. It costs 0 tokens per session (470 once invoked), scanned A, original, Apache-2.0.

A checklist for adding usage or token fields to an AI Gateway, a service that forwards AI provider requests and records traffic. It covers response handling, streaming, database storage, and cache reads and writes.

In plain words
What is it for?
Use it when adding usage data, token counts, database columns, or cache serialization to provider and proxy code.
Why use it?
It prevents a new field from appearing in one request path but being lost when traffic is streamed or served from cache.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when adding usage data, token counts, database columns, or cache serialization to provider and proxy code.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/alphabitcore/nexus-gateway/token-field-stamp-sweep
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/AlphaBitCore/nexus-gateway

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for token-field-stamp-sweep

README.md
[![agentmods](https://agentmods.dev/badge/rules/alphabitcore/nexus-gateway/token-field-stamp-sweep.svg)](https://agentmods.dev/rules/alphabitcore/nexus-gateway/token-field-stamp-sweep)
Your own site
<a href="https://agentmods.dev/rules/alphabitcore/nexus-gateway/token-field-stamp-sweep"><img src="https://agentmods.dev/badge/rules/alphabitcore/nexus-gateway/token-field-stamp-sweep.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 470 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00470
Opus 5 $0.00000 $0.00235
Sonnet 5 $0.00000 $0.00094
Haiku 4.5 $0.00000 $0.00047

Measured 8d ago against content hash 262b4bb57639, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

token-field-stamp-sweep scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/token-field-stamp-sweep.mdc · 40 lines

What it actually says

Token-field stamp sweep (binding)

You are editing AI Gateway provider / proxy code. Adding a new usage / token field requires 5 stamp sites, not just the obvious one. Missing the 4 cache-side sites = all prod cache traffic NULL on the new column. Memory anchor: [[feedback_token_field_handler_sweep]].

Read docs/developers/architecture/services/ai-gateway/provider-adapter-architecture.md §5 BEFORE editing.

The 5 stamp sites

  1. handleNonStream — non-streaming response path.
  2. handleStream — streaming response path (at stream end).
  3. proxy_cache.go:cacheStoreNonStream — cache write path for non-streaming.
  4. proxy_cache.go:cacheStoreStream — cache write path for streaming.
  5. proxy_cache.go:cacheRead* — cache read path (deserialise the stamped value).

Checklist when adding a token field

  • Field added to Usage struct in providers/types.go.
  • Column added to traffic_event schema (Prisma + migration).
  • Stamped in handleNonStream.
  • Stamped in handleStream.
  • Stamped in cacheStoreNonStream.
  • Stamped in cacheStoreStream.
  • Deserialised in cacheRead*.
  • Unit test exercises both non-stream and stream cache paths.
  • Smoke test confirms the new column is non-NULL after a cache hit + cache miss.

Why it matters

The cache paths are easy to forget — they share the data layout with the live paths but live in proxy_cache.go, a separate file. Stamping handleNonStream only is the canonical mistake; cache traffic then writes NULL for the new column and the failure is silent until an analytics dashboard notices.

Skipping this rule requires explicit user approval in chat.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 40 lines · 0 tokens per session scan A 262b4bb57639

Subscribe to this mod's changes

token-field-stamp-sweep is a cursor rule published in the GitHub repository AlphaBitCore/nexus-gateway (23 stars, last pushed 6d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 470 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.