xmtplabs/xmtp-agent-examples / skills/handling-commands
handling-commands
VerifiedPatterns for handling commands, validating input, and filtering messages in XMTP agents. Use when implementing slash commands, validators, or message filters. Triggers on command handling, input validation, or type guards.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 1.6 KB |
| rules/filters-message-types.md | markdown | 1.1 KB |
| rules/guards-codec.md | markdown | 1.1 KB |
| rules/validators-hex.md | markdown | 942 B |
rules/guards-codec.md
View on GitHub---
title: Use usesCodec for type-safe content handling
impact: HIGH
tags: type guards, codec, type safety
---
## Use usesCodec for type-safe content handling
Use `usesCodec()` type guard instead of type assertions when checking message content types.
**Incorrect (type assertion):**
```typescript
const mw: AgentMiddleware = async (ctx, next) => {
// Bad: Using type assertions for content types
const transactionRef = ctx.message.content as TransactionReference;
};
```
**Correct (use usesCodec):**
```typescript
import { TransactionReferenceCodec } from "@xmtp/content-type-transaction-reference";
const mw: AgentMiddleware = async (ctx, next) => {
// Good: Using the usesCodec type guard
if (ctx.usesCodec(TransactionReferenceCodec)) {
// TypeScript now knows ctx.message.content is TransactionReference
const transactionRef = ctx.message.content;
console.log(transactionRef.networkId);
}
};
```
**Why this matters:**
- Type assertions bypass runtime checks
- `usesCodec()` validates the content type at runtime
- TypeScript automatically narrows the type after the check
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 470k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |