|
| 1 | +# Mastra Repository Analysis |
| 2 | + |
| 3 | +Mastra (`mastra-ai/mastra`) is a TypeScript-first agent framework for building production-grade AI assistants. The project has roughly **280 contributors**, **134 open pull requests**, and active CI coverage via GitHub Actions. This document captures the agreed-upon analysis from November 2025 so we can align on rule proposals before shipping automation. |
| 4 | + |
| 5 | +## Repository Snapshot |
| 6 | + |
| 7 | +- **Focus**: AI agents with tooling, memory, workflows, and multi-step orchestration |
| 8 | +- **Primary language**: TypeScript with pnpm-based monorepo |
| 9 | +- **Governance signals**: Detailed `CONTRIBUTING.md`, CODEOWNERS, changeset automation, active doc set |
| 10 | +- **Pain points**: Complex LLM/provider integrations, repeated validation gaps, and regression risk in shared tooling layers |
| 11 | + |
| 12 | +## Pull Request Sample (Nov 2025) |
| 13 | + |
| 14 | +| PR | Title | Outcome | Notes | |
| 15 | +| --- | --- | --- | --- | |
| 16 | +| [#10180](https://github.com/mastra-ai/mastra/pull/10180) | feat: add custom model gateway support with automatic type generation | ✅ merged | Large feature: gateway registry, TS type generation, doc updates | |
| 17 | +| [#10269](https://github.com/mastra-ai/mastra/pull/10269) | AI SDK tripwire data chunks | ✅ merged | Fixes & changeset for SDK data chunking bug | |
| 18 | +| [#10141](https://github.com/mastra-ai/mastra/pull/10141) | fix: throw on invalid filter instead of silently skipping filtering | ✅ merged | Addressed regression where invalid filters returned unfiltered data | |
| 19 | +| [#10300](https://github.com/mastra-ai/mastra/pull/10300) | Add description to type | ✅ merged | Unblocked Agent profile UI by exposing description metadata | |
| 20 | +| [#9880](https://github.com/mastra-ai/mastra/pull/9880) | Fix clientjs clientTools execution | ✅ merged | Fixed client-side tool streaming regressions | |
| 21 | +| [#9941](https://github.com/mastra-ai/mastra/pull/9941) | fix(core): input tool validation with no schema | ✅ merged | Restored validation for schema-less tool inputs | |
| 22 | + |
| 23 | +## Pattern Summary |
| 24 | + |
| 25 | +- **Validation & safety gaps (≈40%)** – invalid filters or schema-less tools silently bypassed safeguards. |
| 26 | +- **Tooling & integration regressions (≈33%)** – clientTools streaming, AI SDK data chunking, URL handling. |
| 27 | +- **Experience polish gaps (≈17%)** – missing agent descriptions prevented UI consistency. |
| 28 | +- **High merge velocity** – most fixes merged quickly; reinforces need for automated guardrails so regressions are caught before release. |
| 29 | + |
| 30 | +## Recommended Watchflow Rules |
| 31 | + |
| 32 | +Rules intentionally avoid the optional `actions:` block so they remain compatible with the current loader. Enforcement intent is described in each `description` and reflected in `severity`. |
| 33 | + |
| 34 | +```yaml |
| 35 | +rules: |
| 36 | + - description: "Block merges when PRs change filter validation logic without failing on invalid inputs" |
| 37 | + enabled: true |
| 38 | + severity: "high" |
| 39 | + event_types: ["pull_request"] |
| 40 | + parameters: |
| 41 | + file_patterns: |
| 42 | + - "packages/core/src/**/vector-query.ts" |
| 43 | + - "packages/core/src/**/graph-rag.ts" |
| 44 | + - "packages/core/src/**/filters/*.ts" |
| 45 | + require_patterns: |
| 46 | + - "throw\\s+new\\s+Error" |
| 47 | + - "raise\\s+ValueError" |
| 48 | + forbidden_patterns: |
| 49 | + - "return\\s+.*filter\\s*$" |
| 50 | + how_to_fix: "Ensure invalid filters raise descriptive errors instead of silently returning unfiltered results." |
| 51 | + |
| 52 | + - description: "Require regression tests when modifying tool schema validation or client tool execution" |
| 53 | + enabled: true |
| 54 | + severity: "medium" |
| 55 | + event_types: ["pull_request"] |
| 56 | + parameters: |
| 57 | + source_patterns: |
| 58 | + - "packages/core/src/**/tool*.ts" |
| 59 | + - "packages/core/src/agent/**" |
| 60 | + - "packages/client/**" |
| 61 | + test_patterns: |
| 62 | + - "packages/core/tests/**" |
| 63 | + - "tests/**" |
| 64 | + min_test_files: 1 |
| 65 | + rationale: "Tool invocation changes have previously caused regressions in clientTools streaming." |
| 66 | + |
| 67 | + - description: "Ensure every agent exposes a user-facing description for UI profiles" |
| 68 | + enabled: true |
| 69 | + severity: "low" |
| 70 | + event_types: ["pull_request"] |
| 71 | + parameters: |
| 72 | + file_patterns: |
| 73 | + - "packages/core/src/agent/**" |
| 74 | + required_text: |
| 75 | + - "description" |
| 76 | + message: "Add or update the agent description so downstream UIs can render capabilities." |
| 77 | + |
| 78 | + - description: "Block merges when URL or asset handling changes bypass provider capability checks" |
| 79 | + enabled: true |
| 80 | + severity: "high" |
| 81 | + event_types: ["pull_request"] |
| 82 | + parameters: |
| 83 | + file_patterns: |
| 84 | + - "packages/core/src/agent/message-list/**" |
| 85 | + - "packages/core/src/llm/**" |
| 86 | + require_patterns: |
| 87 | + - "isUrlSupportedByModel" |
| 88 | + forbidden_patterns: |
| 89 | + - "downloadAssetsFromMessages\\(messages\\)" |
| 90 | + how_to_fix: "Preserve remote URLs for providers that support them natively; only download assets for unsupported providers." |
| 91 | +``` |
| 92 | +
|
| 93 | +These concrete rules rely on the diff-aware validators recently added to Watchflow: |
| 94 | +
|
| 95 | +- `diff_pattern` ensures critical patches keep throwing exceptions or performing capability checks. |
| 96 | +- `related_tests` requires PRs touching core modules to include matching test updates. |
| 97 | +- `required_field_in_diff` verifies additions to agent definitions include a `description` so downstream UIs stay in sync. |
| 98 | + |
| 99 | +Because the PR processor now passes normalized diffs into the engine, these validators operate deterministically without LLM fallbacks. |
| 100 | + |
| 101 | +## PR Template Snippet |
| 102 | + |
| 103 | +```markdown |
| 104 | +## Repository Analysis Complete |
| 105 | +
|
| 106 | +We've analyzed your repository and identified key quality patterns based on recent PR history. |
| 107 | +
|
| 108 | +### Key Findings |
| 109 | +- 40% of recent fixes patched validation or data-safety gaps (filters, schema-less tools). |
| 110 | +- 33% addressed tool/LLM integration regressions (clientTools, AI SDK, URL handling). |
| 111 | +- Tests/documentation often lag behind critical fixes, creating follow-up churn. |
| 112 | +
|
| 113 | +### Recommended Rules |
| 114 | +- Block filter-validation changes that stop throwing on invalid inputs. |
| 115 | +- Require regression tests when modifying tool schemas or clientTools execution. |
| 116 | +- Enforce agent descriptions so UI consumers can present profiles. |
| 117 | +- Block URL/asset handling changes that skip provider capability checks. |
| 118 | +
|
| 119 | +### Installation |
| 120 | +1. Install the Watchflow GitHub App and grant access to `mastra-ai/mastra`. |
| 121 | +2. Add `.watchflow/rules.yaml` with the rules above (see snippet). |
| 122 | +3. Watchflow will start reporting violations through status checks immediately. |
| 123 | + |
| 124 | +Questions? Reach out to the Watchflow team. |
| 125 | +``` |
| 126 | + |
| 127 | +## Validation Plan |
| 128 | + |
| 129 | +1. Keep the rule definitions in `docs/samples/mastra-watchflow-rules.yaml`. |
| 130 | +2. Run `pytest tests/unit/test_mastra_rules_sample.py` to ensure every rule loads via `Rule.model_validate`. |
| 131 | +3. (Optional) Use the repository analysis agent once PR-diff ingestion ships to simulate Mastra commits before opening an automated PR with these rules. |
| 132 | + |
| 133 | +This keeps the deliverable lightweight, fully tested, and ready for the PR template automation flow discussed with Dimitris. |
0 commit comments