gateway

A gateway for connecting Coddy to messaging services, including Telegram. It manages message adapters, access rules, conversation sessions, and optional network proxies.

In plain words
What is it for?
Use it to build Telegram polling and message sending, control who can access chats, preserve chat-to-session links, and format Markdown for Telegram.
Why use it?
It lets conversations continue across restarts and keeps service-specific messaging code separate from the rest of the application.

Cursor rule for Cursor

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.

agentmods
npx agentmods add rules/coddy-project/coddy-agent/gateway
Clone the repo
git clone --depth 1 https://github.com/coddy-project/coddy-agent

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,350 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00000 $0.01350
Opus 5 $0.00000 $0.00675
Sonnet 5 $0.00000 $0.00270
Haiku 4.5 $0.00000 $0.00135

Measured 3d ago against content hash b1e41781b941, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

gateway 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 3d 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/gateway.mdc · 83 lines

How it starts

The opening of the file, as written. The whole thing — 83 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Messenger Gateway (external/gateway)

Built with -tags gateway.telegram (Telegram only) or -tags gateway (all adapters). Without these tags coddy gateway is present in the binary but returns a "not compiled" error.

Package layout

Package Role
external/gateway Adapter interface, Hub, IncomingMessage, OutgoingMessage
external/gateway/access CanAccess, EffectiveAccess, EffectiveIsolation — ACL helpers
external/gateway/sessionstore Store: maps stable chat/user keys to Coddy session IDs; persisted to gateway_sessions.json
external/gateway/proxyutil BuildHTTPClient — HTTP/SOCKS5 proxy support for outbound adapter requests
external/gateway/telegram Bot (polling, dispatch, ACL), Sender (streaming output), commands.go (inline keyboards), markdown.go (md → Telegram format)

Session store

sessionstore.NewPersisted(path) loads/saves a JSON map of key→session-ID on every mutation. The file lives at $CODDY_HOME/sessions/gateway_sessions.json (set in external/gateway/start.go). On restart the bot reloads the map so existing conversations continue without re-sending the one-time initialization hint.

KnownIDs() is called at startup to pre-populate the seenSessions set (prevents re-injecting the Telegram formatting hint into existing sessions after a restart).

SessionRunner interface

Adapters call the session manager through SessionRunner (defined in external/gateway/telegram/bot.go). session.Manager satisfies this interface directly:

type SessionRunner interface {
    EnsureHTTPSession(ctx context.Context, sessionID string, defaultCWD string) (*session.State, error)
    HandleSessionPromptWithSender(ctx context.Context, params acp.SessionPromptParams, sender acp.UpdateSender, opts *session.PromptRunOpts) (*acp.SessionPromptResult, error)
    ForgetLiveSession(sessionID string)
    HandleSessionSetMode(ctx context.Context, params acp.SessionSetModeParams) error
    HandleSessionSetConfigOption(ctx context.Context, params acp.SessionSetConfigOptionParams) (*acp.SessionSetConfigOptionResult, error)
    Cfg() *config.Config
}

Read the full file on GitHub · 83 lines

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. 3d ago First seen · 83 lines · 0 tokens per session scan A b1e41781b941

Subscribe to this mod's changes

gateway is a cursor rule published in the GitHub repository coddy-project/coddy-agent (127 stars, last pushed 5d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,350 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.