-
Notifications
You must be signed in to change notification settings - Fork 2
feat: update dependencies and add new workflows #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <!-- AGENTS-META {"title":"Mastra Root","version":"2.3.0","applies_to":"/","last_updated":"2025-12-11T00:00:00Z","status":"stable"} --> | ||
| <!-- AGENTS-META {"title":"Mastra Root","version":"2.4.0","applies_to":"/","last_updated":"2025-12-15T00:00:00Z","status":"stable"} --> | ||
|
|
||
| # AGENTS | ||
|
|
||
|
|
@@ -86,7 +86,210 @@ NEXT_PUBLIC_MASTRA_API_URL=http://localhost:4111 | |
| - Build: `npm run build` | ||
| - Start production server: `npm run start` | ||
| - Run tests: `npm test` (Vitest) | ||
| - Run linters/formatting: `npx eslint "src/**/*.{ts,tsx}" --max-warnings=0` and `npx prettier --write .` | ||
| - Run linters/formatting: `npm run lint` and `npm run format` | ||
| - Type checking: `npm run typecheck` | ||
|
|
||
| ## Code Style Guidelines | ||
|
|
||
| ### Build & Test Commands | ||
|
|
||
| **Building:** | ||
|
|
||
| - `npm run build` - Concurrent build (Next.js + Mastra) | ||
| - `npm run build:next` - Next.js build only | ||
| - `npm run build:mastra` - Mastra build only | ||
|
|
||
| **Development:** | ||
|
|
||
| - `npm run dev` - Concurrent dev servers (Next.js + Mastra) | ||
| - `npm run dev:next` - Next.js dev server only | ||
| - `npm run dev:mastra` - Mastra dev server only | ||
|
|
||
| **Testing:** | ||
|
|
||
| - `npm test` - Run all tests (Vitest) | ||
| - `npm run coverage` - Run tests with coverage report | ||
| - `npx vitest -t "pattern"` - Run tests matching pattern | ||
| - `npx vitest src/mastra/tools/tests/your-test-file.test.ts` - Run specific test file | ||
|
|
||
| **Linting & Formatting:** | ||
|
|
||
| - `npm run lint` - ESLint check | ||
| - `npm run lint:fix` - ESLint with auto-fix | ||
| - `npm run format` - Prettier formatting | ||
| - `npm run typecheck` - TypeScript type checking | ||
|
|
||
| ### Import Organization | ||
|
|
||
| ```typescript | ||
| // 1. External framework imports (React, Next.js, Mastra) | ||
| import { createTool } from '@mastra/core/tools' | ||
| import { z } from 'zod' | ||
|
|
||
| // 2. Type imports (always use type-only imports) | ||
| import type { RuntimeContext } from '@mastra/core/runtime-context' | ||
| import type { WeatherToolContext } from './types' | ||
|
|
||
| // 3. Internal imports (config, tools, utils) | ||
| import { log } from '../config/logger' | ||
| import { pgQueryTool } from '../config/pg-storage' | ||
| ``` | ||
|
|
||
| ### TypeScript Conventions | ||
|
|
||
| - **Strict mode enabled**: No implicit any, strict null checks | ||
| - **Type definitions**: Use `interface` for public APIs, `type` for internal | ||
| - **Explicit return types**: Required for public functions | ||
| - **No `any`**: Use `unknown` or proper types | ||
| - **Optional chaining**: Use `?.` for nullable access | ||
| - **Nullish coalescing**: Use `??` for defaults | ||
| - **Consistent imports**: `import type { T } from "module"` | ||
|
|
||
| ### Naming Conventions | ||
|
|
||
| - **Functions/Tools**: `camelCase` (e.g., `weatherTool`, `getUserData`) | ||
| - **Classes/Types/Interfaces**: `PascalCase` (e.g., `WeatherToolContext`, `UserProfile`) | ||
| - **Constants**: `UPPER_SNAKE_CASE` (e.g., `API_TIMEOUT`, `MAX_RETRIES`) | ||
| - **Files**: `kebab-case` (e.g., `weather-tool.ts`, `user-profile.tsx`) | ||
| - **Directories**: `kebab-case` or `camelCase` based on convention | ||
|
|
||
| ### Formatting (Prettier) | ||
|
|
||
| ```javascript | ||
| // prettier.config.js | ||
| { | ||
| trailingComma: 'es5', | ||
| tabWidth: 4, | ||
| semi: false, | ||
| singleQuote: true | ||
| } | ||
| ``` | ||
|
|
||
| ### ESLint Rules | ||
|
|
||
| **Critical Rules:** | ||
|
|
||
| - `eqeqeq: ['error', 'always']` - Strict equality | ||
| - `curly: ['error', 'all']` - Required braces | ||
| - `@typescript-eslint/no-unused-vars: ['warn', {}]` - No unused variables | ||
| - `@typescript-eslint/no-explicit-any: 'warn'` - Avoid any types | ||
|
|
||
| **Style Rules:** | ||
|
|
||
| - `object-shorthand: 'error'` - Use shorthand syntax | ||
| - `prefer-arrow-callback: 'error'` - Arrow functions preferred | ||
| - `prefer-const: 'warn'` - Const when possible | ||
| - `@typescript-eslint/consistent-type-definitions: ['error', 'interface']` - Interfaces preferred | ||
|
|
||
| ### Error Handling | ||
|
|
||
| ```typescript | ||
| // ✅ GOOD: Structured error handling | ||
| try { | ||
| const result = await riskyOperation() | ||
| return { data: result, error: null } | ||
| } catch (error) { | ||
| log.error('Operation failed', { error, context }) | ||
| return { data: null, error: error.message } | ||
| } | ||
|
|
||
| // ❌ BAD: Silent failures or generic errors | ||
| try { | ||
| // ... | ||
| } catch (e) { | ||
| // pass | ||
| } | ||
| ``` | ||
|
|
||
| ### Testing Standards | ||
|
|
||
| **Test Structure:** | ||
|
|
||
| ```typescript | ||
| import { describe, it, expect, vi } from 'vitest' | ||
|
|
||
| describe('weatherTool', () => { | ||
| it('should return weather data for valid location', async () => { | ||
| // Arrange | ||
| const mockContext = { location: 'London' } | ||
|
|
||
| // Act | ||
| const result = await weatherTool.execute({ context: mockContext }) | ||
|
|
||
| // Assert | ||
| expect(result.data).toBeDefined() | ||
| expect(result.error).toBeNull() | ||
| }) | ||
| }) | ||
| ``` | ||
|
|
||
| **Testing Rules:** | ||
|
|
||
| - 97% coverage target | ||
| - Mock external dependencies | ||
| - Test success and error paths | ||
| - Use descriptive test names | ||
| - Co-locate tests with implementation | ||
| - `beforeEach` for setup/cleanup | ||
|
|
||
| ### Tool Implementation Pattern | ||
|
|
||
| ```typescript | ||
| import { createTool } from '@mastra/core/tools' | ||
| import { z } from 'zod' | ||
| import { log } from '../config/logger' | ||
|
|
||
| // Context schema (optional) | ||
| const toolContextSchema = z.object({ | ||
| timeout: z.number().default(5000), | ||
| }) | ||
|
|
||
| export type ToolContext = z.infer<typeof toolContextSchema> | ||
|
|
||
| export const myTool = createTool({ | ||
| id: 'my-tool', | ||
| description: 'Clear description of what the tool does', | ||
| inputSchema: z.object({ | ||
| param: z.string().describe('Parameter description'), | ||
| }), | ||
| outputSchema: z.object({ | ||
| data: z.any(), | ||
| error: z.string().optional(), | ||
| }), | ||
| execute: async ({ context, runtimeContext }) => { | ||
| try { | ||
| // Tool logic here | ||
| log.info('Tool executed', { context }) | ||
|
|
||
| return { data: result, error: undefined } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the |
||
| } catch (error) { | ||
| log.error('Tool error', { error, context }) | ||
| return { data: null, error: error.message } | ||
| } | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| ### Agent Implementation Pattern | ||
|
|
||
| ```typescript | ||
| import { Agent } from '@mastra/core/agent' | ||
| import { googleAI } from '../config/google' | ||
| import { pgMemory } from '../config/pg-storage' | ||
|
|
||
| export const myAgent = new Agent({ | ||
| id: 'my-agent', | ||
| name: 'My Agent', | ||
| description: 'What this agent does', | ||
| instructions: 'Instructions for the agent...', | ||
| model: googleAI, | ||
| tools: { | ||
| tool1, | ||
| tool2, | ||
| }, | ||
| memory: pgMemory, | ||
| }) | ||
| ``` | ||
|
|
||
| ## Architecture & conventions | ||
|
|
||
|
|
@@ -118,6 +321,19 @@ NEXT_PUBLIC_MASTRA_API_URL=http://localhost:4111 | |
| - Use `.env` locally and secure env variables in CI/CD (e.g., GitHub Actions Secrets). | ||
| - Mask secrets in logs and use `maskSensitiveMessageData()` helper from `src/mastra/config/pg-storage.ts` where needed. | ||
|
|
||
| ## Cursor/Copilot Rules | ||
|
|
||
| Located in `.github/copilot-instructions.md`: | ||
|
|
||
| - 🧠 Read `/memory-bank/memory-bank-instructions.md` first | ||
| - 🗂 Load all `/memory-bank/*.md` before any task | ||
| - 🚦 Use the Kiro-Lite workflow: PRD → Design → Tasks → Code | ||
| - 🔒 Follow security & style rules in `copilot-rules.md` | ||
| - 📝 Update memory bank after significant changes | ||
| - ✅ Confirm memory bank loaded with `[Memory Bank: Active]` | ||
| - 🎯 Use problem-solving tools for debugging | ||
| - 🛠 Use Mastra tools for documentation and examples | ||
|
|
||
| ## Where to look for more info | ||
|
|
||
| - `app/AGENTS.md`: Next.js App Router pages and layouts | ||
|
|
@@ -143,12 +359,12 @@ NEXT_PUBLIC_MASTRA_API_URL=http://localhost:4111 | |
| - `app/tools/AGENTS.md`: Tool documentation and execution | ||
| - `app/workflows/AGENTS.md`: Interactive workflow visualization with AI Elements (Canvas, Node, Edge, Panel) | ||
| - `lib/`: Shared utilities | ||
| - `hooks/`: React hooks for data fetching and state management | ||
| - `use-dashboard-queries.ts`: TanStack Query hooks for agents, workflows, tools, traces, threads, messages | ||
| - `use-mastra.ts`: Generic fetch hook with loading/error states for MastraClient data | ||
| - `types/`: TypeScript type definitions | ||
| - `mastra-api.ts`: Zod schemas and types for Agent, Workflow, Tool, MemoryThread, Message, VectorQueryResult | ||
| - Core utilities: `a2a.ts` (agent coordination), `auth.ts` (authentication), `client-stream-to-ai-sdk.ts` (streaming), `mastra-client.ts` (client), `utils.ts` | ||
| - `hooks/`: React hooks for data fetching and state management | ||
| - `use-dashboard-queries.ts`: TanStack Query hooks for agents, workflows, tools, traces, threads, messages | ||
| - `use-mastra.ts`: Generic fetch hook with loading/error states for MastraClient data | ||
| - `types/`: TypeScript type definitions | ||
| - `mastra-api.ts`: Zod schemas and types for Agent, Workflow, Tool, MemoryThread, Message, VectorQueryResult | ||
| - Core utilities: `a2a.ts` (agent coordination), `auth.ts` (authentication), `client-stream-to-ai-sdk.ts` (streaming), `mastra-client.ts` (client), `utils.ts` | ||
| - `ui/AGENTS.md`: shadcn/ui base components (34 components) | ||
| - `src/components/ai-elements/AGENTS.md`: AI Elements library (30 components) | ||
| - `src/mastra/AGENTS.md`: top-level code-agent focused docs (this file is mirrored to subfolders) | ||
|
|
@@ -239,17 +455,17 @@ graph TB | |
| - `testSetup.ts`: Test setup with mocks, environment variables, and global type declarations | ||
| - `postcss.config.mjs`: PostCSS configuration with Tailwind CSS plugin | ||
| - `mdx-components.tsx`: Custom MDX components for styling headings, links, code blocks, tables, and images | ||
| - `eslint.config.cjs`: ESLint configuration with TypeScript rules, Prettier integration, and extensive ignore patterns | ||
| - `eslint.config.js`: ESLint configuration with TypeScript rules, Prettier integration, and extensive ignore patterns | ||
| - `prettier.config.js`: Prettier configuration with ES5 trailing commas, 4-space tabs, and single quotes | ||
| - `components.json`: shadcn/ui configuration with New York style, Tailwind CSS, Lucide icons, and component aliases | ||
| - `.eslintignore`: ESLint ignore patterns for node_modules, build artifacts, memory-bank, docs, and other non-source directories | ||
| - `.markdownlint.json`: Markdown linting configuration with relaxed rules for line length, headings, and formatting | ||
| - `src/cli/`: CLI tooling for Governed RAG | ||
| - `index.ts`: CLI commands for document indexing, querying RAG, and usage statistics | ||
| - `AGENTS.md`: CLI documentation and usage patterns | ||
| - `index.ts`: CLI commands for document indexing, querying RAG, and usage statistics | ||
| - `AGENTS.md`: CLI documentation and usage patterns | ||
|
|
||
| If you need more details for a subdirectory, open the folder-specific `AGENTS.md` which contains persona, purpose, and actionable commands. | ||
|
|
||
| --- | ||
|
|
||
| Last updated: 2025-12-15 | ||
| Last updated: 2025-12-15 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Tool Implementation Patternexample usesz.any()for thedatafield inoutputSchema. This contradicts the "TypeScript Conventions" section (line 143) which states "Noany: Useunknownor proper types". To maintain consistency and promote best practices within the documentation, please use a more specific type orz.unknown().