|
| 1 | +# tool-sdk — Agent Conventions |
| 2 | + |
| 3 | +TypeScript SDK and CLI for building ERC-XXXX compliant AI agent tools. |
| 4 | + |
| 5 | +## Quick Reference |
| 6 | + |
| 7 | +```bash |
| 8 | +cd packages/tool-sdk |
| 9 | +pnpm install |
| 10 | +pnpm run build # Build with tsup |
| 11 | +pnpm run test # Run tests with Vitest |
| 12 | +pnpm run lint # Lint with Biome |
| 13 | +pnpm run format # Format with Biome |
| 14 | +pnpm run type-check # TypeScript type checking |
| 15 | +``` |
| 16 | + |
| 17 | +## Architecture |
| 18 | + |
| 19 | +| Path | Role | |
| 20 | +|------|------| |
| 21 | +| `src/index.ts` | Library entry point — public `tool-sdk` exports | |
| 22 | +| `src/cli.ts` | CLI entry point (Commander program wiring) | |
| 23 | +| `src/types.ts` | Shared public types | |
| 24 | +| `src/cli/commands/` | CLI commands: `register`, `validate`, `verify`, `hash`, `init` | |
| 25 | +| `src/lib/onchain/abis.ts` | TypeScript ABI definitions mirroring Solidity interfaces | |
| 26 | +| `src/lib/onchain/chains.ts` | Deployed contract addresses per chain | |
| 27 | +| `src/lib/onchain/registry.ts` | `ToolRegistryClient` — onchain interaction wrapper | |
| 28 | +| `src/lib/onchain/hash.ts` | JCS keccak256 manifest hashing | |
| 29 | +| `src/lib/manifest/` | Manifest schema, validation, types | |
| 30 | +| `src/lib/handler/` | `createToolHandler` — Web Request/Response handler factory | |
| 31 | +| `src/lib/middleware/` | Gating middleware (NFT gate, x402, well-known endpoint) | |
| 32 | +| `src/lib/wallet/` | Re-exports from `@opensea/wallet-adapters` (adapters, types, and viem bridge) | |
| 33 | +| `src/lib/adapters/` | Framework adapters (Vercel, Cloudflare, Express) | |
| 34 | +| `src/lib/utils.ts` | Shared utilities used across `lib/` | |
| 35 | +| `src/templates/` | Scaffolding templates for `init` command | |
| 36 | +| `src/__tests__/` | Vitest test suite | |
| 37 | + |
| 38 | +## Review Checklist |
| 39 | + |
| 40 | +When reviewing changes to this package, verify: |
| 41 | + |
| 42 | +1. **ABI completeness**: `abis.ts` must include every function and event from the corresponding Solidity interfaces in `../tool-registry/src/interfaces/`. If the Solidity interface adds a function, `abis.ts` must add it too. Missing ABI entries mean SDK consumers cannot call those functions. |
| 43 | + |
| 44 | +2. **Address sync**: Addresses in `chains.ts` must match `../tool-registry/README.md`. After a new deploy, both files must be updated together. |
| 45 | + |
| 46 | +3. **Dead code after refactors**: When removing features (e.g., dropping a predicate factory), verify that all related imports, constants, and references are also removed. Check for unused imports at the top of refactored files. |
| 47 | + |
| 48 | +4. **CLI error messages**: Error messages shown to SDK consumers should not reference internal file paths (e.g., "Update chains.ts"). Link to the README or provide actionable instructions instead. |
| 49 | + |
| 50 | +5. **Multi-step CLI flows**: Commands that require multiple onchain transactions (e.g., `register --nft-gate` does `registerTool` then `setCollections`) must handle partial failure gracefully — print recovery instructions if the second TX fails. |
| 51 | + |
| 52 | +6. **`--dry-run` accuracy**: Dry-run output must reflect the full onchain footprint. If the command sends multiple transactions, the dry-run should mention all of them. |
| 53 | + |
| 54 | +## Conventions |
| 55 | + |
| 56 | +- ESM-only (`"type": "module"`). Use `.js` extensions in import paths. |
| 57 | +- Biome for linting and formatting: double quotes, 2-space indent, trailing commas. |
| 58 | +- `as const` on all ABI definitions for type narrowing with viem. |
| 59 | +- CLI commands use Commander.js. Wallet is configured via `--wallet-provider` flag or env vars (see `.env.example`). |
| 60 | +- `ToolRegistryClient` wraps viem `PublicClient` and `WalletClient` — all onchain reads/writes go through it. |
0 commit comments