Implement comprehensive tool testing environment with real package execution, AI agents, and token tracking. **New Features:** - Interactive playground UI with 4 tabs (Input, Output, Logs, Token Usage) - Real npm package execution in VM2 sandbox with security constraints - AI-powered tool execution using AI SDK v5 and GPT-4 Turbo - Server-Sent Events (SSE) streaming for real-time progress updates - Comprehensive 4-category token tracking (Input, Tool Description, Schema, Output) - Visual token breakdown with colored progress bars - IP-based rate limiting (10 executions/hour per IP) - Database persistence of all simulations with full metadata **Database Schema:** - New `Simulation` model for execution records - New `TokenUsage` model for detailed token metrics - New `ExecutionLog` model for execution event tracking - Added simulations relation to Tool model **Package Executor (@tpmjs/package-executor):** - VM2 sandbox with 5-second timeout - Blocked dangerous modules (fs, net, http, https, child_process) - LRU file system cache in /tmp/.tpmjs-cache - Package installation and caching strategy **AI Agent Service:** - TPMJS parameter to Zod schema conversion - AI SDK tool definition generation - Token counting using tiktoken library - GPT-4 Turbo pricing estimation - Streaming text execution with callbacks **API Endpoints:** - POST /api/tools/[...slug]/execute - SSE streaming execution - GET /api/tools/[...slug]/simulations - Execution history - Rate limit headers (X-RateLimit-Limit, X-RateLimit-Remaining) **Frontend Components:** - ToolPlayground - Main playground UI with tabs - TokenBreakdown - Visual token metrics with colored bars - Integrated above README section on tool detail pages **Security:** - VM2 sandboxing prevents filesystem/network access - Rate limiting prevents abuse - IP tracking for usage monitoring - Timeout protection (60s max API duration, 5s VM timeout) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| .changeset | ||
| .claude/commands | ||
| .github/workflows | ||
| .vscode | ||
| apps/web | ||
| packages | ||
| scripts | ||
| supabase | ||
| .dependency-cruiser.js | ||
| .env.vercel.production | ||
| .gitignore | ||
| .npmrc | ||
| .nvmrc | ||
| 2025-BEST-PRACTICES.md | ||
| API_ROUTES_TIMEOUT_INVESTIGATION.md | ||
| biome.json | ||
| CLAUDE.md | ||
| convert-label-tests.py | ||
| DEPLOYMENT.md | ||
| HOW_TO_PUBLISH_A_TOOL.md | ||
| IMPLEMENTATION_CHECKLIST.md | ||
| knip.json | ||
| lefthook.yml | ||
| NPM_MIRROR.md | ||
| package.json | ||
| pnpm-lock.yaml | ||
| pnpm-workspace.yaml | ||
| QUALITY-GATES.md | ||
| README.md | ||
| reset.d.ts | ||
| test-db.mjs | ||
| tsconfig.json | ||
| turbo.json | ||
| vercel.json | ||
| VERCEL_FIX_CHECKLIST.md | ||
TPMJS Monorepo
Tool Package Manager for AI Agents - A Turborepo monorepo with strict TypeScript, Next.js 16, and best practices.
Structure
apps/
web/ - Next.js 16 App Router application
packages/
config/ - Shared configurations (Biome, ESLint, Tailwind, TypeScript)
ui/ - React component library (.ts-only, no barrels)
utils/ - Utility functions
types/ - Shared TypeScript types
env/ - Zod environment schema loader
test/ - Vitest shared configuration
mocks/ - MSW mock server
storybook/ - Storybook documentation
Getting Started
Prerequisites
- Node.js >= 22 (LTS)
- pnpm >= 8
- nvm (recommended for Node version management)
Installation
pnpm install
Development
# Run all apps in development mode
pnpm dev
# Run specific app
pnpm --filter @tpmjs/web dev
pnpm --filter @tpmjs/storybook dev
Building
# Build all packages and apps
pnpm build
# Build specific package
pnpm --filter @tpmjs/ui build
Testing
# Run all tests
pnpm test
# Run tests in watch mode with UI
pnpm test:ui
Linting & Formatting
# Lint all packages
pnpm lint
# Format all files
pnpm format
# Check formatting
pnpm format:check
Quality Gates
# Check architecture/dependency rules
pnpm check-architecture
# Find unused code and dependencies
pnpm find-deadcode
# Check type coverage
pnpm type-coverage
See QUALITY-GATES.md for details.
Component Usage
Components are imported directly without barrel exports:
import { Button } from '@tpmjs/ui/Button/Button';
import { Card, CardHeader } from '@tpmjs/ui/Card/Card';
Important: All UI components use .ts extension (not .tsx) and use createElement instead of JSX.
Publishing Workflow
1. Create Changesets
After making changes to publishable packages:
pnpm changeset
Follow the prompts to describe your changes and select which packages are affected.
2. Version Packages
When ready to release:
pnpm changeset:version
This updates package versions and generates CHANGELOGs.
3. Publish to npm
pnpm changeset:publish
This builds and publishes all packages with changesets to npm.
4. Push to GitHub
git push --follow-tags
Published Packages
@tpmjs/ui- React component library@tpmjs/utils- Utility functions@tpmjs/types- TypeScript types@tpmjs/env- Environment schema loader
Deployment
The project is configured to only deploy to Vercel when all CI checks pass. This ensures production always has high-quality, tested code.
CI Checks:
- Linting & formatting
- Type checking
- Tests
- Production build
- Architecture validation
- Dead code detection
See DEPLOYMENT.md for full configuration details.
Module Boundaries
ESLint enforces module boundaries:
- Apps can import from published packages only
- Packages cannot import from apps
- No barrel exports (
index.ts) allowed - Direct imports required:
@tpmjs/ui/Button/Button
Architecture Decisions
Why .ts-only Components?
Using .ts instead of .tsx for React components:
- Enforces explicit
createElementcalls - Makes React's runtime nature more visible
- Prevents JSX spreading anti-patterns
- Better for code generation and tooling
Why No Barrel Exports?
- Clearer dependency graphs
- Better tree-shaking
- Explicit imports show what's actually used
- Prevents circular dependencies
Why Biome + ESLint?
- Biome: Fast formatting and basic linting
- ESLint: Semantic rules (module boundaries, TypeScript strictness)
- Each tool focuses on what it does best
Scripts Reference
dev- Start development serversbuild- Build all packagestest- Run teststest:ui- Run tests with UIlint- Lint codeformat- Format code with Biomeformat:check- Check formattingtype-check- TypeScript type checkingtype-coverage- Check type coverage (no implicit any)check-architecture- Validate dependency rulesfind-deadcode- Find unused code/dependenciesclean- Remove build artifactschangeset- Create a changesetchangeset:version- Version packageschangeset:publish- Publish to npm
License
MIT