Repository navigation
Add Mastra plugin - #2227
Add Mastra plugin#2227
Conversation
webpro
left a comment
There was a problem hiding this comment.
Thanks for the plugin, Ashok! The patterns follow Mastra's discovery code, and on Mastra's examples/agent all seven weather-fs files are no longer reported as unused, including the nested subagents.
One request before merging: let's support the --dir and --tools options right away instead of leaving them for later, see the inline comments.
| const agentRoots = 'src/mastra/agents/*/*(subagents/*/)'; | ||
|
|
||
| const production = [ | ||
| `src/mastra/index.${extensions}`, | ||
| 'src/mastra/{storage,observability,logger,server,studio}.{js,ts,mjs,mts}', | ||
| `src/mastra/workflows/*.${extensions}`, | ||
| `src/mastra/{,agents/*/}tools/**/*.${extensions}`, | ||
| `${agentRoots}{config,instructions,memory,workspace}.${extensions}`, | ||
| `${agentRoots}{tools,scorers,skills,processors/input,processors/output}/*.${extensions}`, | ||
| `${agentRoots}schedules/**/*.${extensions}`, | ||
| `!src/mastra/**/*.{test,spec}.${extensions}`, | ||
| '!src/mastra/**/__tests__/**', | ||
| ]; |
There was a problem hiding this comment.
mastra dev --dir <dir> and mastra build --dir <dir> use that folder instead of src/mastra for the entry file and all file-based discovery (dev, build). Could you build these patterns from the Mastra folder, and add them with toProductionEntry from an args.resolveInputs handler when --dir is set? The React Email plugin handles its dir option the same way. Note that mastra start --dir points at the build output instead, so the handler needs to check the command. A fixture script like mastra dev --dir app/mastra would cover it.
There was a problem hiding this comment.
Done in 781635f: the production patterns are built by getProductionPatterns(dir), used for the default src/mastra and, from args.resolveInputs, for --dir/-d on dev and build (start is skipped since its --dir is the build output). Fixture script dev:app: mastra dev --dir app/mastra; the test checks app/mastra/index.ts, a file-based agent's tool and the file it imports are no longer reported.
| `src/mastra/index.${extensions}`, | ||
| 'src/mastra/{storage,observability,logger,server,studio}.{js,ts,mjs,mts}', | ||
| `src/mastra/workflows/*.${extensions}`, | ||
| `src/mastra/{,agents/*/}tools/**/*.${extensions}`, |
There was a problem hiding this comment.
The same commands also take --tools <paths> (-t), a comma-separated list of tool files, globs or directories. Mastra bundles each match as a separate input next to the default tools/** (listToolsInputOptions) and imports them all from the generated tools.mjs (here), so a tool listed only there is an entry file, along with the dependencies it imports. These can be added as production entries from the same handler (a directory resolves to its index.ts or index.js), covered by a script like mastra build -t lib/tools/*.ts.
There was a problem hiding this comment.
Also in 781635f: --tools/-t is split on commas and each item becomes a production entry; a directory resolves to <dir>/index.{js,ts}, files and globs are used as given. Fixture script build:tools: mastra build -t lib/tools/*.ts,lib/extra-tools; the test checks both tool files, the module one of them imports and lib/extra-tools/index.ts are reached, while lib/unused.ts next to them is still reported.
`mastra dev --dir <dir>` and `mastra build --dir <dir>` discover the entry
file and the file-based agents, tools and workflows from that folder instead
of `src/mastra`, so the production patterns are now built from the folder
and added as production entries from `args.resolveInputs` when `--dir` is
set. `mastra start --dir` points at the build output, so it adds nothing.
The same commands take `--tools` (`-t`), a comma-separated list of tool
files, globs or directories that Mastra bundles as separate inputs and
imports from the generated `tools.mjs`. Each is added as a production entry;
a directory resolves to its `index.{js,ts}`.
The fixture gets `mastra dev --dir app/mastra`, `mastra build -t
lib/tools/*.ts,lib/extra-tools` and a `start --dir` script, and the test
checks the files they reach are no longer reported.
webpro
left a comment
There was a problem hiding this comment.
Thanks for adding both options! --dir on dev and build (with start left out) and --tools as production entries work as expected, and the fixtures cover both. Looks good to me.
commit: |
|
🚀 This pull request is included in v6.44.0. See Release 6.44.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
Closes #2222
Adds a plugin for Mastra, enabled by the
mastraCLI package.mastra devandmastra buildpick up files by convention undersrc/mastra, so these were reported as unused:index.{ts,js}and thestorage/observability/logger/server/studiosingletonsworkflows/*andtools/**(minus tests, like Mastra's own globs)agents/<name>/:config,instructions,memory,workspace,tools/,scorers/,skills/,processors/{input,output}/,schedules/**, and nestedsubagents/<name>/Patterns follow Mastra's source (
deployer/src/build/fs-routing/discover.tsandbundler/index.ts, linked in the plugin). Also checked against Mastra'sexamples/agent: the 7 false positives for its file-basedweather-fsagent are gone.Not included: the
--dirCLI option (custom dirs can usemastra.entryfor now).