@mastra/code-sdk 1.2.0-alpha.1 → 1.2.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +175 -0
  2. package/dist/agents/credential-resolver.d.ts +6 -0
  3. package/dist/agents/credential-resolver.d.ts.map +1 -1
  4. package/dist/agents/credential-resolver.js +14 -4
  5. package/dist/agents/credential-resolver.js.map +1 -1
  6. package/dist/agents/mastracode-gateway.d.ts.map +1 -1
  7. package/dist/agents/mastracode-gateway.js +27 -13
  8. package/dist/agents/mastracode-gateway.js.map +1 -1
  9. package/dist/agents/model.d.ts +16 -1
  10. package/dist/agents/model.d.ts.map +1 -1
  11. package/dist/agents/model.js +27 -6
  12. package/dist/agents/model.js.map +1 -1
  13. package/dist/agents/tools.js +1 -1
  14. package/dist/headless/cli.d.ts.map +1 -1
  15. package/dist/headless/cli.js +3 -0
  16. package/dist/headless/cli.js.map +1 -1
  17. package/dist/headless/flags.js +1 -1
  18. package/dist/headless/flags.js.map +1 -1
  19. package/dist/headless/types.d.ts +2 -2
  20. package/dist/headless/types.d.ts.map +1 -1
  21. package/dist/headless/types.js +2 -1
  22. package/dist/headless/types.js.map +1 -1
  23. package/dist/hooks/executor.d.ts.map +1 -1
  24. package/dist/hooks/executor.js +1 -0
  25. package/dist/hooks/executor.js.map +1 -1
  26. package/dist/hooks/manager.d.ts +9 -2
  27. package/dist/hooks/manager.d.ts.map +1 -1
  28. package/dist/hooks/manager.js +19 -3
  29. package/dist/hooks/manager.js.map +1 -1
  30. package/dist/hooks/types.d.ts +20 -0
  31. package/dist/hooks/types.d.ts.map +1 -1
  32. package/dist/hooks/types.js.map +1 -1
  33. package/dist/index.d.ts +68 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +179 -64
  36. package/dist/index.js.map +1 -1
  37. package/dist/onboarding/settings.d.ts +75 -6
  38. package/dist/onboarding/settings.d.ts.map +1 -1
  39. package/dist/onboarding/settings.js +128 -13
  40. package/dist/onboarding/settings.js.map +1 -1
  41. package/dist/plugin.d.ts +64 -1
  42. package/dist/plugin.d.ts.map +1 -1
  43. package/dist/plugin.js +3 -1
  44. package/dist/plugin.js.map +1 -1
  45. package/dist/plugins/loader.d.ts +7 -3
  46. package/dist/plugins/loader.d.ts.map +1 -1
  47. package/dist/plugins/loader.js +53 -1
  48. package/dist/plugins/loader.js.map +1 -1
  49. package/dist/plugins/manager.d.ts +36 -2
  50. package/dist/plugins/manager.d.ts.map +1 -1
  51. package/dist/plugins/manager.js +74 -2
  52. package/dist/plugins/manager.js.map +1 -1
  53. package/dist/plugins/signal-lane.d.ts +58 -0
  54. package/dist/plugins/signal-lane.d.ts.map +1 -0
  55. package/dist/plugins/signal-lane.js +166 -0
  56. package/dist/plugins/signal-lane.js.map +1 -0
  57. package/dist/plugins/types.d.ts +36 -0
  58. package/dist/plugins/types.d.ts.map +1 -1
  59. package/dist/providers/claude-max.d.ts +13 -0
  60. package/dist/providers/claude-max.d.ts.map +1 -1
  61. package/dist/providers/claude-max.js +83 -3
  62. package/dist/providers/claude-max.js.map +1 -1
  63. package/dist/providers/openai-codex.d.ts +3 -1
  64. package/dist/providers/openai-codex.d.ts.map +1 -1
  65. package/dist/providers/openai-codex.js +13 -2
  66. package/dist/providers/openai-codex.js.map +1 -1
  67. package/dist/schema.d.ts +11 -5
  68. package/dist/schema.d.ts.map +1 -1
  69. package/dist/schema.js +5 -4
  70. package/dist/schema.js.map +1 -1
  71. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,oBAAoB,EAAE,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M,CAAC,EAAE,4BAA4B,CAAC;IACtC,YAAY,CAAC,EAAE,4BAA4B,CAAC;IAC5C,KAAK,CAAC,EACF,2BAA2B,GAC3B,CAAC,CAAC,OAAO,EAAE,uBAAuB,KAAK,2BAA2B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC;IAC/G,UAAU,CAAC,EACP,gCAAgC,GAChC,CAAC,CACC,OAAO,EAAE,uBAAuB,KAC7B,gCAAgC,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC,CAAC;IACvF,eAAe,CAAC,EACZ,qCAAqC,GACrC,CAAC,CACC,OAAO,EAAE,uBAAuB,KAC7B,qCAAqC,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC,CAAC;CAClG,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,gBAAgB,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEjG"}
package/dist/plugin.js CHANGED
@@ -1,5 +1,7 @@
1
+ import { SignalProvider } from "@mastra/core/signals";
1
2
  import { createTool } from "@mastra/core/tools";
2
3
  import { z } from "zod";
4
+ import { RequestContext } from "@mastra/core/di";
3
5
  //#region src/plugin.ts
4
6
  async function writeToolProgress(context, progress) {
5
7
  const toolCallId = context?.agent?.toolCallId;
@@ -23,6 +25,6 @@ function defineMastraCodePlugin(plugin) {
23
25
  return plugin;
24
26
  }
25
27
  //#endregion
26
- export { createTool, defineMastraCodePlugin, writeToolProgress, z };
28
+ export { RequestContext, SignalProvider, createTool, defineMastraCodePlugin, writeToolProgress, z };
27
29
 
28
30
  //# sourceMappingURL=plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';\n\nexport { createTool } from '@mastra/core/tools';\nexport type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';\nexport { z } from 'zod';\n\nexport type MastraCodeToolRenderConfig = {\n type: 'subagent';\n agentType?: string;\n modelId?: string;\n forked?: boolean;\n label?: string;\n maxActivityLines?: number;\n collapsedLines?: number;\n colors?: {\n border?: string;\n label?: string;\n agentType?: string;\n icon?: string;\n };\n icons?: {\n running?: string;\n success?: string;\n error?: string;\n };\n};\n\nexport type MastraCodeSubagentProgress =\n | {\n event: 'text';\n text: string;\n }\n | {\n event: 'tool_start';\n toolName: string;\n args?: unknown;\n }\n | {\n event: 'tool_end';\n toolName: string;\n result?: unknown;\n isError?: boolean;\n }\n | {\n event: 'finish';\n isError?: boolean;\n durationMs?: number;\n result?: string;\n };\n\nexport type MastraCodeToolProgress = string | { status?: string; detail?: string } | MastraCodeSubagentProgress;\n\nexport async function writeToolProgress(\n context: Pick<ToolExecutionContext, 'writer' | 'agent'> | undefined,\n progress: MastraCodeToolProgress,\n): Promise<void> {\n const toolCallId = context?.agent?.toolCallId;\n if (!toolCallId) return;\n\n const chunk = {\n type: 'data-mastracode-tool-progress',\n data: {\n toolCallId,\n progress,\n },\n transient: true,\n } as const;\n\n const outputWriter = (context.agent as { outputWriter?: (chunk: unknown) => Promise<void> } | undefined)\n ?.outputWriter;\n if (outputWriter) {\n await outputWriter(chunk);\n return;\n }\n\n await context.writer?.custom(chunk);\n}\n\nexport type MastraCodePluginConfigValue = string | boolean | undefined;\n\nexport type MastraCodePluginConfigOption = {\n type: 'model' | 'boolean' | 'string';\n label?: string;\n description?: string;\n default?: string | boolean;\n};\n\nexport type MastraCodePluginConfigSchema = Record<string, MastraCodePluginConfigOption>;\nexport type MastraCodePluginConfigValues = Record<string, MastraCodePluginConfigValue>;\n\nexport type MastraCodePluginContext = {\n cwd: string;\n scope: 'global' | 'project';\n pluginDir: string;\n config: MastraCodePluginConfigValues;\n};\n\nexport type MastraCodePluginTool = Tool | ToolAction<any, any, any, any, any, any, any>;\n\nexport type MastraCodePluginToolEntry = {\n tool: MastraCodePluginTool;\n render?: MastraCodeToolRenderConfig;\n};\n\nexport type MastraCodePluginTools = Record<string, MastraCodePluginTool>;\nexport type MastraCodePluginToolEntries = Record<string, MastraCodePluginToolEntry>;\nexport type MastraCodePluginInstructions = string | ((context: MastraCodePluginContext) => string | Promise<string>);\n\nexport type MastraCodePlugin = {\n id: string;\n name?: string;\n version?: string;\n description?: string;\n config?: MastraCodePluginConfigSchema;\n instructions?: MastraCodePluginInstructions;\n tools?:\n | MastraCodePluginToolEntries\n | ((context: MastraCodePluginContext) => MastraCodePluginToolEntries | Promise<MastraCodePluginToolEntries>);\n};\n\nexport function defineMastraCodePlugin<TPlugin extends MastraCodePlugin>(plugin: TPlugin): TPlugin {\n return plugin;\n}\n"],"mappings":";;;AAoDA,eAAsB,kBACpB,SACA,UACe;CACf,MAAM,aAAa,SAAS,OAAO;CACnC,IAAI,CAAC,YAAY;CAEjB,MAAM,QAAQ;EACZ,MAAM;EACN,MAAM;GACJ;GACA;EACF;EACA,WAAW;CACb;CAEA,MAAM,eAAgB,QAAQ,OAC1B;CACJ,IAAI,cAAc;EAChB,MAAM,aAAa,KAAK;EACxB;CACF;CAEA,MAAM,QAAQ,QAAQ,OAAO,KAAK;AACpC;AA4CA,SAAgB,uBAAyD,QAA0B;CACjG,OAAO;AACT"}
1
+ {"version":3,"file":"plugin.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AgentController, Session } from '@mastra/core/agent-controller';\nimport type { InputProcessor, OutputProcessor } from '@mastra/core/processors';\nimport type { SignalProvider } from '@mastra/core/signals';\nimport type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';\n\nimport type { MastraCodeState } from './schema.js';\n\nexport { createTool } from '@mastra/core/tools';\nexport { RequestContext } from '@mastra/core/di';\nexport type { InputProcessor, OutputProcessor } from '@mastra/core/processors';\nexport { SignalProvider } from '@mastra/core/signals';\nexport type { SignalProviderTarget, SignalSubscription } from '@mastra/core/signals';\nexport type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';\nexport { z } from 'zod';\n\nexport type MastraCodeToolRenderConfig = {\n type: 'subagent';\n agentType?: string;\n modelId?: string;\n forked?: boolean;\n label?: string;\n maxActivityLines?: number;\n collapsedLines?: number;\n colors?: {\n border?: string;\n label?: string;\n agentType?: string;\n icon?: string;\n };\n icons?: {\n running?: string;\n success?: string;\n error?: string;\n };\n};\n\nexport type MastraCodeSubagentProgress =\n | {\n event: 'text';\n text: string;\n }\n | {\n event: 'tool_start';\n toolName: string;\n args?: unknown;\n }\n | {\n event: 'tool_end';\n toolName: string;\n result?: unknown;\n isError?: boolean;\n }\n | {\n event: 'finish';\n isError?: boolean;\n durationMs?: number;\n result?: string;\n };\n\nexport type MastraCodeToolProgress = string | { status?: string; detail?: string } | MastraCodeSubagentProgress;\n\nexport async function writeToolProgress(\n context: Pick<ToolExecutionContext, 'writer' | 'agent'> | undefined,\n progress: MastraCodeToolProgress,\n): Promise<void> {\n const toolCallId = context?.agent?.toolCallId;\n if (!toolCallId) return;\n\n const chunk = {\n type: 'data-mastracode-tool-progress',\n data: {\n toolCallId,\n progress,\n },\n transient: true,\n } as const;\n\n const outputWriter = (context.agent as { outputWriter?: (chunk: unknown) => Promise<void> } | undefined)\n ?.outputWriter;\n if (outputWriter) {\n await outputWriter(chunk);\n return;\n }\n\n await context.writer?.custom(chunk);\n}\n\nexport type MastraCodePluginConfigValue = string | boolean | undefined;\n\nexport type MastraCodePluginConfigOption = {\n type: 'model' | 'boolean' | 'string';\n label?: string;\n description?: string;\n default?: string | boolean;\n};\n\nexport type MastraCodePluginConfigSchema = Record<string, MastraCodePluginConfigOption>;\nexport type MastraCodePluginConfigValues = Record<string, MastraCodePluginConfigValue>;\n\n/** The running Mastra Code controller, as seen by a plugin. */\nexport type MastraCodePluginController = AgentController<MastraCodeState>;\n\n/** The session a plugin's contributions are running alongside. */\nexport type MastraCodePluginSession = Session<MastraCodeState>;\n\n/**\n * Lazy accessors for Mastra Code's runtime, handed to every plugin field resolver.\n *\n * Plugins are loaded before the controller and the session exist, so these are\n * accessors rather than instances: call them at the moment you need the value,\n * never during plugin load. Both return `undefined` until Mastra Code has\n * constructed the corresponding object.\n *\n * @experimental This is an evolving runtime API. It currently exposes the whole\n * controller so real plugins can be built against it; once we know what plugin\n * authors actually reach for, it may narrow to a smaller facade in a future\n * release.\n */\nexport type MastraCodePluginRuntime = {\n /**\n * The running controller, or `undefined` when it does not exist yet.\n * @experimental see {@link MastraCodePluginRuntime}\n */\n getController?: () => MastraCodePluginController | undefined;\n /**\n * The active session, or `undefined` before one has been created.\n * @experimental see {@link MastraCodePluginRuntime}\n */\n getActiveSession?: () => MastraCodePluginSession | undefined;\n};\n\nexport type MastraCodePluginContext = MastraCodePluginRuntime & {\n cwd: string;\n scope: 'global' | 'project';\n pluginDir: string;\n config: MastraCodePluginConfigValues;\n};\n\nexport type MastraCodePluginTool = Tool | ToolAction<any, any, any, any, any, any, any>;\n\nexport type MastraCodePluginToolEntry = {\n tool: MastraCodePluginTool;\n render?: MastraCodeToolRenderConfig;\n};\n\nexport type MastraCodePluginTools = Record<string, MastraCodePluginTool>;\nexport type MastraCodePluginToolEntries = Record<string, MastraCodePluginToolEntry>;\nexport type MastraCodePluginInstructions = string | ((context: MastraCodePluginContext) => string | Promise<string>);\n\n/**\n * Processors a plugin contributes, split by lane.\n *\n * A bare array is shorthand for `{ input: [...] }`, since input processors are\n * the common case. Plugin processors run last in Mastra Code's own configured\n * processors — after the layers they customize, before the channel and memory\n * layers the agent appends. That slot is fixed and not configurable.\n */\nexport type MastraCodePluginProcessorEntries =\n | InputProcessor[]\n | {\n input?: InputProcessor[];\n output?: OutputProcessor[];\n };\n\n/**\n * Signal providers a plugin contributes.\n *\n * Mastra Code owns their lifecycle: it registers Mastra on them, connects them\n * to the coding agent, starts them polling, and stops them when the plugin is\n * updated, disabled or removed. Their `getInputProcessors()` /\n * `getOutputProcessors()` feed the same lanes as {@link MastraCodePluginProcessorEntries}.\n *\n * Note that `getTools()` is **ignored** for plugin-provided providers — inject\n * tools from inside a processor instead.\n */\nexport type MastraCodePluginSignalProviderEntries = SignalProvider<string>[];\n\nexport type MastraCodePlugin = {\n id: string;\n name?: string;\n version?: string;\n description?: string;\n config?: MastraCodePluginConfigSchema;\n instructions?: MastraCodePluginInstructions;\n tools?:\n | MastraCodePluginToolEntries\n | ((context: MastraCodePluginContext) => MastraCodePluginToolEntries | Promise<MastraCodePluginToolEntries>);\n processors?:\n | MastraCodePluginProcessorEntries\n | ((\n context: MastraCodePluginContext,\n ) => MastraCodePluginProcessorEntries | Promise<MastraCodePluginProcessorEntries>);\n signalProviders?:\n | MastraCodePluginSignalProviderEntries\n | ((\n context: MastraCodePluginContext,\n ) => MastraCodePluginSignalProviderEntries | Promise<MastraCodePluginSignalProviderEntries>);\n};\n\nexport function defineMastraCodePlugin<TPlugin extends MastraCodePlugin>(plugin: TPlugin): TPlugin {\n return plugin;\n}\n"],"mappings":";;;;;AA6DA,eAAsB,kBACpB,SACA,UACe;CACf,MAAM,aAAa,SAAS,OAAO;CACnC,IAAI,CAAC,YAAY;CAEjB,MAAM,QAAQ;EACZ,MAAM;EACN,MAAM;GACJ;GACA;EACF;EACA,WAAW;CACb;CAEA,MAAM,eAAgB,QAAQ,OAC1B;CACJ,IAAI,cAAc;EAChB,MAAM,aAAa,KAAK;EACxB;CACF;CAEA,MAAM,QAAQ,QAAQ,OAAO,KAAK;AACpC;AAkHA,SAAgB,uBAAyD,QAA0B;CACjG,OAAO;AACT"}
@@ -1,12 +1,16 @@
1
- import type { MastraCodePlugin, MastraCodePluginTools } from '../plugin.js';
1
+ import type { MastraCodePlugin, MastraCodePluginRuntime, MastraCodePluginTools } from '../plugin.js';
2
2
  import type { PluginPathOptions } from './paths.js';
3
3
  import type { LoadedPlugin, PluginRegistry, ScopedInstalledPluginRecord } from './types.js';
4
- export type LoadPluginsOptions = PluginPathOptions & {
4
+ export type LoadPluginRecordOptions = PluginPathOptions & {
5
+ /** Lazy accessors for Mastra Code's runtime, passed on to plugin field resolvers. */
6
+ runtime?: MastraCodePluginRuntime;
7
+ };
8
+ export type LoadPluginsOptions = LoadPluginRecordOptions & {
5
9
  globalRegistry?: PluginRegistry;
6
10
  projectRegistry?: PluginRegistry;
7
11
  };
8
12
  export declare function loadPlugins(options: LoadPluginsOptions): Promise<LoadedPlugin[]>;
9
- export declare function loadPluginRecord(record: ScopedInstalledPluginRecord, options: PluginPathOptions): Promise<LoadedPlugin>;
13
+ export declare function loadPluginRecord(record: ScopedInstalledPluginRecord, options: LoadPluginRecordOptions): Promise<LoadedPlugin>;
10
14
  export declare function loadPluginFromEntry(entryPath: string): Promise<MastraCodePlugin>;
11
15
  export declare function resolvePluginRoot(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string;
12
16
  export declare function resolvePluginEntryPath(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string;
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/plugins/loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAKhB,qBAAqB,EAEtB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAE5F,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG;IACnD,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,eAAe,CAAC,EAAE,cAAc,CAAC;CAClC,CAAC;AAEF,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAsBtF;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,2BAA2B,EACnC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,YAAY,CAAC,CA6CvB;AAED,wBAAsB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAEtF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,2BAA2B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CAOzG;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,2BAA2B,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAO9G;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAI3E;AAoND,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,qBAAqB,CAWvF"}
@@ -1,5 +1,6 @@
1
1
  import { getPluginRoot } from "./paths.js";
2
2
  import { loadPluginRegistry, mergePluginRegistries } from "./registry.js";
3
+ import { isSignalProvider } from "@mastra/core/signals";
3
4
  import fs from "fs";
4
5
  import path from "path";
5
6
  import { pathToFileURL } from "url";
@@ -43,9 +44,13 @@ async function loadPluginRecord(record, options) {
43
44
  cwd: options.projectRoot,
44
45
  scope: record.scope,
45
46
  pluginDir,
46
- config: configValues
47
+ config: configValues,
48
+ getController: options.runtime?.getController,
49
+ getActiveSession: options.runtime?.getActiveSession
47
50
  };
48
51
  const { tools, renderConfigs } = await resolvePluginTools(plugin, context);
52
+ const processors = await resolvePluginProcessors(plugin, context);
53
+ const signalProviders = await resolvePluginSignalProviders(plugin, context);
49
54
  const instructions = await resolvePluginInstructions(plugin, context);
50
55
  return {
51
56
  ...record,
@@ -57,6 +62,8 @@ async function loadPluginRecord(record, options) {
57
62
  tools,
58
63
  renderConfigs,
59
64
  toolNames: Object.keys(tools).sort(),
65
+ processors,
66
+ signalProviders,
60
67
  skillPaths: resolveExistingAssetDirs(pluginRoot, "skills"),
61
68
  commandPaths: resolveExistingAssetDirs(pluginRoot, "commands"),
62
69
  configSchema,
@@ -114,6 +121,8 @@ function validatePluginExport(value) {
114
121
  const plugin = value;
115
122
  if (typeof plugin.id !== "string" || plugin.id.trim().length === 0) throw new Error("Plugin id must be a non-empty string");
116
123
  if (plugin.tools !== void 0 && typeof plugin.tools !== "object" && typeof plugin.tools !== "function") throw new Error("Plugin tools must be an object or function");
124
+ if (plugin.processors !== void 0 && typeof plugin.processors !== "object" && typeof plugin.processors !== "function") throw new Error("Plugin processors must be an array, object, or function");
125
+ if (plugin.signalProviders !== void 0 && !Array.isArray(plugin.signalProviders) && typeof plugin.signalProviders !== "function") throw new Error("Plugin signal providers must be an array or function");
117
126
  return plugin;
118
127
  }
119
128
  async function resolvePluginTools(plugin, context) {
@@ -125,6 +134,49 @@ async function resolvePluginTools(plugin, context) {
125
134
  if (!entries || typeof entries !== "object" || Array.isArray(entries)) throw new Error("Plugin tools function must return an object");
126
135
  return normalizePluginToolEntries(entries);
127
136
  }
137
+ /** Mirrors {@link resolvePluginTools}: object-or-function, resolved with the same context. */
138
+ async function resolvePluginProcessors(plugin, context) {
139
+ if (!plugin.processors) return {
140
+ input: [],
141
+ output: []
142
+ };
143
+ const entries = typeof plugin.processors === "function" ? await plugin.processors(context) : plugin.processors;
144
+ if (!entries || typeof entries !== "object") throw new Error("Plugin processors function must return an array or object");
145
+ return normalizePluginProcessorEntries(entries);
146
+ }
147
+ async function resolvePluginSignalProviders(plugin, context) {
148
+ if (!plugin.signalProviders) return [];
149
+ const entries = typeof plugin.signalProviders === "function" ? await plugin.signalProviders(context) : plugin.signalProviders;
150
+ if (!Array.isArray(entries)) throw new Error("Plugin signal providers function must return an array");
151
+ for (const [index, provider] of entries.entries()) if (!isPluginSignalProvider(provider)) throw new Error(`Plugin signal provider at index ${index} must be a SignalProvider (an object with an id that implements connect, startPolling, stop and __registerMastra)`);
152
+ return entries;
153
+ }
154
+ /**
155
+ * Structural, not `instanceof`.
156
+ *
157
+ * A plugin that depends on a published provider package — the motivating case, a plugin wrapping
158
+ * `@mastra/github-signals` — installs that package's own copy of `@mastra/core`, so its provider is
159
+ * never an instance of the `SignalProvider` class Mastra Code loaded. `isSignalProvider` would reject
160
+ * a perfectly working provider. Nothing in the lifecycle needs class identity: the lane only calls
161
+ * these methods, so the methods are what is checked.
162
+ */
163
+ function isPluginSignalProvider(value) {
164
+ if (isSignalProvider(value)) return true;
165
+ if (!value || typeof value !== "object") return false;
166
+ const candidate = value;
167
+ return typeof candidate.id === "string" && candidate.id.length > 0 && typeof candidate.connect === "function" && typeof candidate.startPolling === "function" && typeof candidate.stop === "function" && typeof candidate.__registerMastra === "function";
168
+ }
169
+ /** A bare array is shorthand for the input lane, the common case. */
170
+ function normalizePluginProcessorEntries(entries) {
171
+ const input = Array.isArray(entries) ? entries : entries.input ?? [];
172
+ const output = Array.isArray(entries) ? [] : entries.output ?? [];
173
+ if (!Array.isArray(input) || !Array.isArray(output)) throw new Error("Plugin processor lanes must be arrays");
174
+ for (const processor of [...input, ...output]) if (!processor || typeof processor !== "object" || typeof processor.id !== "string") throw new Error("Plugin processors must be objects with an id");
175
+ return {
176
+ input,
177
+ output
178
+ };
179
+ }
128
180
  async function resolvePluginInstructions(plugin, context) {
129
181
  if (plugin.instructions === void 0) return void 0;
130
182
  const instructions = typeof plugin.instructions === "function" ? await plugin.instructions(context) : plugin.instructions;
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","names":[],"sources":["../../src/plugins/loader.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type {\n MastraCodePlugin,\n MastraCodePluginConfigSchema,\n MastraCodePluginConfigValues,\n MastraCodePluginContext,\n MastraCodePluginToolEntries,\n MastraCodePluginTools,\n MastraCodeToolRenderConfig,\n} from '../plugin.js';\nimport { getPluginRoot } from './paths.js';\nimport type { PluginPathOptions } from './paths.js';\nimport { loadPluginRegistry, mergePluginRegistries } from './registry.js';\nimport type { LoadedPlugin, PluginRegistry, ScopedInstalledPluginRecord } from './types.js';\n\nexport type LoadPluginsOptions = PluginPathOptions & {\n globalRegistry?: PluginRegistry;\n projectRegistry?: PluginRegistry;\n};\n\nexport async function loadPlugins(options: LoadPluginsOptions): Promise<LoadedPlugin[]> {\n const globalRegistry =\n options.globalRegistry ?? loadPluginRegistry(path.join(getPluginRoot('global', options), 'plugins.json'));\n const projectRegistry =\n options.projectRegistry ?? loadPluginRegistry(path.join(getPluginRoot('project', options), 'plugins.json'));\n const records = mergePluginRegistries(globalRegistry, projectRegistry);\n const loaded: LoadedPlugin[] = [];\n\n for (const record of records) {\n if (record.blocked) {\n loaded.push({ ...record, status: 'blocked', tools: {}, toolNames: [] });\n continue;\n }\n if (!record.enabled) {\n loaded.push({ ...record, status: 'inactive', tools: {}, toolNames: [] });\n continue;\n }\n\n loaded.push(await loadPluginRecord(record, options));\n }\n\n return markToolConflicts(loaded);\n}\n\nexport async function loadPluginRecord(\n record: ScopedInstalledPluginRecord,\n options: PluginPathOptions,\n): Promise<LoadedPlugin> {\n try {\n const entryPath = resolvePluginEntryPath(record, options);\n const plugin = await importPluginModule(entryPath);\n if (plugin.id !== record.id) {\n throw new Error(`Plugin id mismatch: registry has \"${record.id}\" but module exports \"${plugin.id}\"`);\n }\n\n const configSchema = validatePluginConfigSchema(plugin.config);\n const configValues = resolvePluginConfigValues(configSchema, record.config);\n const pluginDir = path.dirname(entryPath);\n const pluginRoot = resolvePluginRoot(record, options);\n const context: MastraCodePluginContext = {\n cwd: options.projectRoot,\n scope: record.scope,\n pluginDir,\n config: configValues,\n };\n const { tools, renderConfigs } = await resolvePluginTools(plugin, context);\n const instructions = await resolvePluginInstructions(plugin, context);\n\n return {\n ...record,\n name: plugin.name,\n version: plugin.version ?? record.version,\n description: plugin.description,\n instructions,\n status: 'active',\n tools,\n renderConfigs,\n toolNames: Object.keys(tools).sort(),\n skillPaths: resolveExistingAssetDirs(pluginRoot, 'skills'),\n commandPaths: resolveExistingAssetDirs(pluginRoot, 'commands'),\n configSchema,\n configValues,\n };\n } catch (error) {\n return {\n ...record,\n status: 'load failed',\n error: error instanceof Error ? error.message : String(error),\n tools: {},\n toolNames: [],\n };\n }\n}\n\nexport async function loadPluginFromEntry(entryPath: string): Promise<MastraCodePlugin> {\n return validatePluginExport(await importPluginModule(entryPath));\n}\n\nexport function resolvePluginRoot(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string {\n const scopeRoot = path.resolve(getPluginRoot(record.scope, options));\n const pluginRoot = path.resolve(path.isAbsolute(record.path) ? record.path : path.join(scopeRoot, record.path));\n if (record.source === 'github' && !isInsideDirectory(pluginRoot, scopeRoot)) {\n throw new Error(`Plugin path for \"${record.id}\" must be inside the ${record.scope} plugin directory`);\n }\n return pluginRoot;\n}\n\nexport function resolvePluginEntryPath(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string {\n const pluginRoot = resolvePluginRoot(record, options);\n const entryPath = path.resolve(pluginRoot, record.entry);\n if (!isInsideDirectory(entryPath, pluginRoot)) {\n throw new Error(`Plugin entry for \"${record.id}\" must be inside the plugin directory`);\n }\n return entryPath;\n}\n\nexport function isInsideDirectory(targetPath: string, root: string): boolean {\n const resolvedTarget = path.resolve(targetPath);\n const resolvedRoot = path.resolve(root);\n return resolvedTarget === resolvedRoot || resolvedTarget.startsWith(resolvedRoot + path.sep);\n}\n\nfunction resolveExistingAssetDirs(pluginRoot: string, dirname: 'skills' | 'commands'): string[] {\n const dir = path.join(pluginRoot, dirname);\n try {\n return fs.statSync(dir).isDirectory() ? [dir] : [];\n } catch {\n return [];\n }\n}\n\nasync function importPluginModule(entryPath: string): Promise<MastraCodePlugin> {\n if (path.extname(entryPath) !== '.ts') {\n throw new Error(\n `Unsupported plugin entry extension \"${path.extname(entryPath)}\". V1 plugins must use .ts entries.`,\n );\n }\n\n const url = pathToFileURL(entryPath);\n const stat = fs.statSync(entryPath, { bigint: true });\n url.searchParams.set('mtimeNs', stat.mtimeNs.toString());\n url.searchParams.set('size', stat.size.toString());\n const mod = (await import(url.href)) as { default?: unknown; plugin?: unknown };\n return validatePluginExport(mod.default ?? mod.plugin);\n}\n\nfunction validatePluginExport(value: unknown): MastraCodePlugin {\n if (!value || typeof value !== 'object') {\n throw new Error('Plugin module must export a plugin object as default or named \"plugin\" export');\n }\n\n const plugin = value as MastraCodePlugin;\n if (typeof plugin.id !== 'string' || plugin.id.trim().length === 0) {\n throw new Error('Plugin id must be a non-empty string');\n }\n\n if (plugin.tools !== undefined && typeof plugin.tools !== 'object' && typeof plugin.tools !== 'function') {\n throw new Error('Plugin tools must be an object or function');\n }\n\n return plugin;\n}\n\nasync function resolvePluginTools(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<{ tools: MastraCodePluginTools; renderConfigs: Record<string, MastraCodeToolRenderConfig> }> {\n if (!plugin.tools) return { tools: {}, renderConfigs: {} };\n const entries = typeof plugin.tools === 'function' ? await plugin.tools(context) : plugin.tools;\n if (!entries || typeof entries !== 'object' || Array.isArray(entries)) {\n throw new Error('Plugin tools function must return an object');\n }\n return normalizePluginToolEntries(entries);\n}\n\nasync function resolvePluginInstructions(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<string | undefined> {\n if (plugin.instructions === undefined) return undefined;\n const instructions =\n typeof plugin.instructions === 'function' ? await plugin.instructions(context) : plugin.instructions;\n if (typeof instructions !== 'string') {\n throw new Error('Plugin instructions must be a string');\n }\n const trimmed = instructions.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction normalizePluginToolEntries(entries: MastraCodePluginToolEntries): {\n tools: MastraCodePluginTools;\n renderConfigs: Record<string, MastraCodeToolRenderConfig>;\n} {\n const tools: MastraCodePluginTools = {};\n const renderConfigs: Record<string, MastraCodeToolRenderConfig> = {};\n for (const [name, entry] of Object.entries(entries)) {\n if (!isToolEntryObject(entry)) {\n throw new Error(`Plugin tool \"${name}\" must be an object with a tool property`);\n }\n tools[name] = entry.tool;\n if (entry.render) renderConfigs[name] = entry.render;\n }\n return { tools, renderConfigs };\n}\n\nfunction isToolEntryObject(entry: MastraCodePluginToolEntries[string]): entry is MastraCodePluginToolEntries[string] {\n if (!entry || typeof entry !== 'object' || !('tool' in entry)) return false;\n const tool = (entry as { tool?: unknown }).tool;\n return !!tool && typeof tool === 'object' && !Array.isArray(tool);\n}\n\nfunction validatePluginConfigSchema(schema: unknown): MastraCodePluginConfigSchema | undefined {\n if (!schema || typeof schema !== 'object' || Array.isArray(schema)) return undefined;\n const validated: MastraCodePluginConfigSchema = {};\n for (const [key, option] of Object.entries(schema)) {\n if (!option || typeof option !== 'object' || Array.isArray(option)) continue;\n const record = option as Record<string, unknown>;\n if (record.type !== 'model' && record.type !== 'boolean' && record.type !== 'string') continue;\n validated[key] = {\n type: record.type,\n ...(typeof record.label === 'string' ? { label: record.label } : {}),\n ...(typeof record.description === 'string' ? { description: record.description } : {}),\n ...(typeof record.default === 'string' || typeof record.default === 'boolean' ? { default: record.default } : {}),\n };\n }\n return Object.keys(validated).length > 0 ? validated : undefined;\n}\n\nfunction resolvePluginConfigValues(\n schema: MastraCodePluginConfigSchema | undefined,\n recordValues: Record<string, unknown> | undefined,\n): MastraCodePluginConfigValues {\n const values: MastraCodePluginConfigValues = {};\n if (!schema) return values;\n for (const [key, option] of Object.entries(schema)) {\n const value = recordValues?.[key];\n if (option.type === 'boolean') {\n values[key] = typeof value === 'boolean' ? value : typeof option.default === 'boolean' ? option.default : false;\n continue;\n }\n values[key] = typeof value === 'string' ? value : typeof option.default === 'string' ? option.default : undefined;\n }\n return values;\n}\n\nexport function collectActivePluginTools(plugins: LoadedPlugin[]): MastraCodePluginTools {\n const tools: MastraCodePluginTools = {};\n for (const plugin of plugins) {\n if (plugin.status !== 'active') continue;\n for (const [name, tool] of Object.entries(plugin.tools)) {\n if (!(name in tools)) {\n tools[name] = tool;\n }\n }\n }\n return tools;\n}\n\nfunction markToolConflicts(plugins: LoadedPlugin[]): LoadedPlugin[] {\n const seen = new Map<string, string>();\n return plugins.map(plugin => {\n if (plugin.status !== 'active') return plugin;\n const conflicts = plugin.toolNames.filter(toolName => seen.has(toolName));\n for (const toolName of plugin.toolNames) {\n if (!seen.has(toolName)) seen.set(toolName, plugin.id);\n }\n return conflicts.length > 0 ? { ...plugin, status: 'conflicted', conflicts } : plugin;\n });\n}\n"],"mappings":";;;;;;AAuBA,eAAsB,YAAY,SAAsD;CAKtF,MAAM,UAAU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AK,IAAI,UAAU,OAAO,EAAE;EAEvD,OAAO,UAAU,SAAS,IAAI;GAAE,GAAG;GAAQ,QAAQ;GAAc;EAAU,IAAI;CACjF,CAAC;AACH"}
1
+ {"version":3,"file":"loader.js","names":[],"sources":["../../src/plugins/loader.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport { isSignalProvider } from '@mastra/core/signals';\nimport type { SignalProvider } from '@mastra/core/signals';\n\nimport type {\n MastraCodePlugin,\n MastraCodePluginConfigSchema,\n MastraCodePluginConfigValues,\n MastraCodePluginContext,\n MastraCodePluginProcessorEntries,\n MastraCodePluginRuntime,\n MastraCodePluginSignalProviderEntries,\n MastraCodePluginToolEntries,\n MastraCodePluginTools,\n MastraCodeToolRenderConfig,\n} from '../plugin.js';\nimport { getPluginRoot } from './paths.js';\nimport type { PluginPathOptions } from './paths.js';\nimport { loadPluginRegistry, mergePluginRegistries } from './registry.js';\nimport type { LoadedPlugin, LoadedPluginProcessors, PluginRegistry, ScopedInstalledPluginRecord } from './types.js';\n\nexport type LoadPluginRecordOptions = PluginPathOptions & {\n /** Lazy accessors for Mastra Code's runtime, passed on to plugin field resolvers. */\n runtime?: MastraCodePluginRuntime;\n};\n\nexport type LoadPluginsOptions = LoadPluginRecordOptions & {\n globalRegistry?: PluginRegistry;\n projectRegistry?: PluginRegistry;\n};\n\nexport async function loadPlugins(options: LoadPluginsOptions): Promise<LoadedPlugin[]> {\n const globalRegistry =\n options.globalRegistry ?? loadPluginRegistry(path.join(getPluginRoot('global', options), 'plugins.json'));\n const projectRegistry =\n options.projectRegistry ?? loadPluginRegistry(path.join(getPluginRoot('project', options), 'plugins.json'));\n const records = mergePluginRegistries(globalRegistry, projectRegistry);\n const loaded: LoadedPlugin[] = [];\n\n for (const record of records) {\n if (record.blocked) {\n loaded.push({ ...record, status: 'blocked', tools: {}, toolNames: [] });\n continue;\n }\n if (!record.enabled) {\n loaded.push({ ...record, status: 'inactive', tools: {}, toolNames: [] });\n continue;\n }\n\n loaded.push(await loadPluginRecord(record, options));\n }\n\n return markToolConflicts(loaded);\n}\n\nexport async function loadPluginRecord(\n record: ScopedInstalledPluginRecord,\n options: LoadPluginRecordOptions,\n): Promise<LoadedPlugin> {\n try {\n const entryPath = resolvePluginEntryPath(record, options);\n const plugin = await importPluginModule(entryPath);\n if (plugin.id !== record.id) {\n throw new Error(`Plugin id mismatch: registry has \"${record.id}\" but module exports \"${plugin.id}\"`);\n }\n\n const configSchema = validatePluginConfigSchema(plugin.config);\n const configValues = resolvePluginConfigValues(configSchema, record.config);\n const pluginDir = path.dirname(entryPath);\n const pluginRoot = resolvePluginRoot(record, options);\n const context: MastraCodePluginContext = {\n cwd: options.projectRoot,\n scope: record.scope,\n pluginDir,\n config: configValues,\n // Accessors, not instances: plugins load before the controller and the\n // session exist, so a plugin resolves these when it needs them, not now.\n getController: options.runtime?.getController,\n getActiveSession: options.runtime?.getActiveSession,\n };\n const { tools, renderConfigs } = await resolvePluginTools(plugin, context);\n const processors = await resolvePluginProcessors(plugin, context);\n const signalProviders = await resolvePluginSignalProviders(plugin, context);\n const instructions = await resolvePluginInstructions(plugin, context);\n\n return {\n ...record,\n name: plugin.name,\n version: plugin.version ?? record.version,\n description: plugin.description,\n instructions,\n status: 'active',\n tools,\n renderConfigs,\n toolNames: Object.keys(tools).sort(),\n processors,\n signalProviders,\n skillPaths: resolveExistingAssetDirs(pluginRoot, 'skills'),\n commandPaths: resolveExistingAssetDirs(pluginRoot, 'commands'),\n configSchema,\n configValues,\n };\n } catch (error) {\n return {\n ...record,\n status: 'load failed',\n error: error instanceof Error ? error.message : String(error),\n tools: {},\n toolNames: [],\n };\n }\n}\n\nexport async function loadPluginFromEntry(entryPath: string): Promise<MastraCodePlugin> {\n return validatePluginExport(await importPluginModule(entryPath));\n}\n\nexport function resolvePluginRoot(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string {\n const scopeRoot = path.resolve(getPluginRoot(record.scope, options));\n const pluginRoot = path.resolve(path.isAbsolute(record.path) ? record.path : path.join(scopeRoot, record.path));\n if (record.source === 'github' && !isInsideDirectory(pluginRoot, scopeRoot)) {\n throw new Error(`Plugin path for \"${record.id}\" must be inside the ${record.scope} plugin directory`);\n }\n return pluginRoot;\n}\n\nexport function resolvePluginEntryPath(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string {\n const pluginRoot = resolvePluginRoot(record, options);\n const entryPath = path.resolve(pluginRoot, record.entry);\n if (!isInsideDirectory(entryPath, pluginRoot)) {\n throw new Error(`Plugin entry for \"${record.id}\" must be inside the plugin directory`);\n }\n return entryPath;\n}\n\nexport function isInsideDirectory(targetPath: string, root: string): boolean {\n const resolvedTarget = path.resolve(targetPath);\n const resolvedRoot = path.resolve(root);\n return resolvedTarget === resolvedRoot || resolvedTarget.startsWith(resolvedRoot + path.sep);\n}\n\nfunction resolveExistingAssetDirs(pluginRoot: string, dirname: 'skills' | 'commands'): string[] {\n const dir = path.join(pluginRoot, dirname);\n try {\n return fs.statSync(dir).isDirectory() ? [dir] : [];\n } catch {\n return [];\n }\n}\n\nasync function importPluginModule(entryPath: string): Promise<MastraCodePlugin> {\n if (path.extname(entryPath) !== '.ts') {\n throw new Error(\n `Unsupported plugin entry extension \"${path.extname(entryPath)}\". V1 plugins must use .ts entries.`,\n );\n }\n\n const url = pathToFileURL(entryPath);\n const stat = fs.statSync(entryPath, { bigint: true });\n url.searchParams.set('mtimeNs', stat.mtimeNs.toString());\n url.searchParams.set('size', stat.size.toString());\n const mod = (await import(url.href)) as { default?: unknown; plugin?: unknown };\n return validatePluginExport(mod.default ?? mod.plugin);\n}\n\nfunction validatePluginExport(value: unknown): MastraCodePlugin {\n if (!value || typeof value !== 'object') {\n throw new Error('Plugin module must export a plugin object as default or named \"plugin\" export');\n }\n\n const plugin = value as MastraCodePlugin;\n if (typeof plugin.id !== 'string' || plugin.id.trim().length === 0) {\n throw new Error('Plugin id must be a non-empty string');\n }\n\n if (plugin.tools !== undefined && typeof plugin.tools !== 'object' && typeof plugin.tools !== 'function') {\n throw new Error('Plugin tools must be an object or function');\n }\n\n if (\n plugin.processors !== undefined &&\n typeof plugin.processors !== 'object' &&\n typeof plugin.processors !== 'function'\n ) {\n throw new Error('Plugin processors must be an array, object, or function');\n }\n\n if (\n plugin.signalProviders !== undefined &&\n !Array.isArray(plugin.signalProviders) &&\n typeof plugin.signalProviders !== 'function'\n ) {\n throw new Error('Plugin signal providers must be an array or function');\n }\n\n return plugin;\n}\n\nasync function resolvePluginTools(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<{ tools: MastraCodePluginTools; renderConfigs: Record<string, MastraCodeToolRenderConfig> }> {\n if (!plugin.tools) return { tools: {}, renderConfigs: {} };\n const entries = typeof plugin.tools === 'function' ? await plugin.tools(context) : plugin.tools;\n if (!entries || typeof entries !== 'object' || Array.isArray(entries)) {\n throw new Error('Plugin tools function must return an object');\n }\n return normalizePluginToolEntries(entries);\n}\n\n/** Mirrors {@link resolvePluginTools}: object-or-function, resolved with the same context. */\nasync function resolvePluginProcessors(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<LoadedPluginProcessors> {\n if (!plugin.processors) return { input: [], output: [] };\n const entries = typeof plugin.processors === 'function' ? await plugin.processors(context) : plugin.processors;\n if (!entries || typeof entries !== 'object') {\n throw new Error('Plugin processors function must return an array or object');\n }\n return normalizePluginProcessorEntries(entries);\n}\n\nasync function resolvePluginSignalProviders(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<MastraCodePluginSignalProviderEntries> {\n if (!plugin.signalProviders) return [];\n const entries =\n typeof plugin.signalProviders === 'function' ? await plugin.signalProviders(context) : plugin.signalProviders;\n if (!Array.isArray(entries)) {\n throw new Error('Plugin signal providers function must return an array');\n }\n for (const [index, provider] of entries.entries()) {\n if (!isPluginSignalProvider(provider)) {\n throw new Error(\n `Plugin signal provider at index ${index} must be a SignalProvider (an object with an id that implements connect, startPolling, stop and __registerMastra)`,\n );\n }\n }\n return entries;\n}\n\n/**\n * Structural, not `instanceof`.\n *\n * A plugin that depends on a published provider package — the motivating case, a plugin wrapping\n * `@mastra/github-signals` — installs that package's own copy of `@mastra/core`, so its provider is\n * never an instance of the `SignalProvider` class Mastra Code loaded. `isSignalProvider` would reject\n * a perfectly working provider. Nothing in the lifecycle needs class identity: the lane only calls\n * these methods, so the methods are what is checked.\n */\nfunction isPluginSignalProvider(value: unknown): value is SignalProvider<string> {\n if (isSignalProvider(value)) return true;\n if (!value || typeof value !== 'object') return false;\n const candidate = value as Partial<SignalProvider<string>> & { __registerMastra?: unknown };\n return (\n typeof candidate.id === 'string' &&\n candidate.id.length > 0 &&\n typeof candidate.connect === 'function' &&\n typeof candidate.startPolling === 'function' &&\n typeof candidate.stop === 'function' &&\n typeof candidate.__registerMastra === 'function'\n );\n}\n\n/** A bare array is shorthand for the input lane, the common case. */\nfunction normalizePluginProcessorEntries(entries: MastraCodePluginProcessorEntries): LoadedPluginProcessors {\n const input = Array.isArray(entries) ? entries : (entries.input ?? []);\n const output = Array.isArray(entries) ? [] : (entries.output ?? []);\n if (!Array.isArray(input) || !Array.isArray(output)) {\n throw new Error('Plugin processor lanes must be arrays');\n }\n for (const processor of [...input, ...output]) {\n if (!processor || typeof processor !== 'object' || typeof processor.id !== 'string') {\n throw new Error('Plugin processors must be objects with an id');\n }\n }\n return { input, output };\n}\n\nasync function resolvePluginInstructions(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<string | undefined> {\n if (plugin.instructions === undefined) return undefined;\n const instructions =\n typeof plugin.instructions === 'function' ? await plugin.instructions(context) : plugin.instructions;\n if (typeof instructions !== 'string') {\n throw new Error('Plugin instructions must be a string');\n }\n const trimmed = instructions.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction normalizePluginToolEntries(entries: MastraCodePluginToolEntries): {\n tools: MastraCodePluginTools;\n renderConfigs: Record<string, MastraCodeToolRenderConfig>;\n} {\n const tools: MastraCodePluginTools = {};\n const renderConfigs: Record<string, MastraCodeToolRenderConfig> = {};\n for (const [name, entry] of Object.entries(entries)) {\n if (!isToolEntryObject(entry)) {\n throw new Error(`Plugin tool \"${name}\" must be an object with a tool property`);\n }\n tools[name] = entry.tool;\n if (entry.render) renderConfigs[name] = entry.render;\n }\n return { tools, renderConfigs };\n}\n\nfunction isToolEntryObject(entry: MastraCodePluginToolEntries[string]): entry is MastraCodePluginToolEntries[string] {\n if (!entry || typeof entry !== 'object' || !('tool' in entry)) return false;\n const tool = (entry as { tool?: unknown }).tool;\n return !!tool && typeof tool === 'object' && !Array.isArray(tool);\n}\n\nfunction validatePluginConfigSchema(schema: unknown): MastraCodePluginConfigSchema | undefined {\n if (!schema || typeof schema !== 'object' || Array.isArray(schema)) return undefined;\n const validated: MastraCodePluginConfigSchema = {};\n for (const [key, option] of Object.entries(schema)) {\n if (!option || typeof option !== 'object' || Array.isArray(option)) continue;\n const record = option as Record<string, unknown>;\n if (record.type !== 'model' && record.type !== 'boolean' && record.type !== 'string') continue;\n validated[key] = {\n type: record.type,\n ...(typeof record.label === 'string' ? { label: record.label } : {}),\n ...(typeof record.description === 'string' ? { description: record.description } : {}),\n ...(typeof record.default === 'string' || typeof record.default === 'boolean' ? { default: record.default } : {}),\n };\n }\n return Object.keys(validated).length > 0 ? validated : undefined;\n}\n\nfunction resolvePluginConfigValues(\n schema: MastraCodePluginConfigSchema | undefined,\n recordValues: Record<string, unknown> | undefined,\n): MastraCodePluginConfigValues {\n const values: MastraCodePluginConfigValues = {};\n if (!schema) return values;\n for (const [key, option] of Object.entries(schema)) {\n const value = recordValues?.[key];\n if (option.type === 'boolean') {\n values[key] = typeof value === 'boolean' ? value : typeof option.default === 'boolean' ? option.default : false;\n continue;\n }\n values[key] = typeof value === 'string' ? value : typeof option.default === 'string' ? option.default : undefined;\n }\n return values;\n}\n\nexport function collectActivePluginTools(plugins: LoadedPlugin[]): MastraCodePluginTools {\n const tools: MastraCodePluginTools = {};\n for (const plugin of plugins) {\n if (plugin.status !== 'active') continue;\n for (const [name, tool] of Object.entries(plugin.tools)) {\n if (!(name in tools)) {\n tools[name] = tool;\n }\n }\n }\n return tools;\n}\n\nfunction markToolConflicts(plugins: LoadedPlugin[]): LoadedPlugin[] {\n const seen = new Map<string, string>();\n return plugins.map(plugin => {\n if (plugin.status !== 'active') return plugin;\n const conflicts = plugin.toolNames.filter(toolName => seen.has(toolName));\n for (const toolName of plugin.toolNames) {\n if (!seen.has(toolName)) seen.set(toolName, plugin.id);\n }\n return conflicts.length > 0 ? { ...plugin, status: 'conflicted', conflicts } : plugin;\n });\n}\n"],"mappings":";;;;;;;AAkCA,eAAsB,YAAY,SAAsD;CAKtF,MAAM,UAAU,sBAHd,QAAQ,kBAAkB,mBAAmB,KAAK,KAAK,cAAc,UAAU,OAAO,GAAG,cAAc,CAAC,GAExG,QAAQ,mBAAmB,mBAAmB,KAAK,KAAK,cAAc,WAAW,OAAO,GAAG,cAAc,CAAC,CACvC;CACrE,MAAM,SAAyB,CAAC;CAEhC,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,OAAO,SAAS;GAClB,OAAO,KAAK;IAAE,GAAG;IAAQ,QAAQ;IAAW,OAAO,CAAC;IAAG,WAAW,CAAC;GAAE,CAAC;GACtE;EACF;EACA,IAAI,CAAC,OAAO,SAAS;GACnB,OAAO,KAAK;IAAE,GAAG;IAAQ,QAAQ;IAAY,OAAO,CAAC;IAAG,WAAW,CAAC;GAAE,CAAC;GACvE;EACF;EAEA,OAAO,KAAK,MAAM,iBAAiB,QAAQ,OAAO,CAAC;CACrD;CAEA,OAAO,kBAAkB,MAAM;AACjC;AAEA,eAAsB,iBACpB,QACA,SACuB;CACvB,IAAI;EACF,MAAM,YAAY,uBAAuB,QAAQ,OAAO;EACxD,MAAM,SAAS,MAAM,mBAAmB,SAAS;EACjD,IAAI,OAAO,OAAO,OAAO,IACvB,MAAM,IAAI,MAAM,qCAAqC,OAAO,GAAG,wBAAwB,OAAO,G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
1
+ import type { SignalProvider } from '@mastra/core/signals';
2
+ import type { MastraCodePluginConfigValue, MastraCodePluginRuntime } from '../plugin.js';
2
3
  import { discoverLocalPlugins } from './install.js';
3
4
  import type { InstallPluginOptions } from './install.js';
4
5
  import type { PluginPathOptions } from './paths.js';
5
- import type { LoadedPlugin, PluginScope } from './types.js';
6
+ import type { LoadedPlugin, PluginContribution, PluginProcessorEntries, PluginScope } from './types.js';
6
7
  type PluginManagerOptions = PluginPathOptions & {
7
8
  githubCliPath?: string;
9
+ /**
10
+ * Lazy accessors for Mastra Code's runtime, handed to plugin field resolvers on
11
+ * every load and reload.
12
+ */
13
+ runtime?: MastraCodePluginRuntime;
8
14
  };
9
15
  export declare class PluginManager {
10
16
  private readonly options;
@@ -14,12 +20,23 @@ export declare class PluginManager {
14
20
  private readonly toolRenderConfigs;
15
21
  private readonly watchedLocalEntries;
16
22
  private readonly localEntryVersions;
23
+ /** Last known git HEAD per GitHub checkout, kept current by the poller. */
24
+ private readonly githubCheckoutHeads;
17
25
  private githubPollTimer;
18
26
  private githubPollInFlight;
19
27
  private reloadInFlight;
20
28
  private readonly reloadListeners;
21
29
  private readonly githubUpdateListeners;
30
+ private runtime;
22
31
  constructor(options: PluginManagerOptions);
32
+ /**
33
+ * Publish (or replace) the runtime accessors handed to plugin field resolvers.
34
+ * Takes effect on the next load or reload. `createMastraCode` calls this for
35
+ * every manager it uses — including an injected one — so a manager constructed
36
+ * without a runtime still exposes `getController`/`getActiveSession` to plugins.
37
+ * A manager shared across controllers sees the most recent controller's accessors.
38
+ */
39
+ setRuntime(runtime: MastraCodePluginRuntime): void;
23
40
  onReload(listener: (plugins: LoadedPlugin[]) => void | Promise<void>): () => void;
24
41
  /** Notified with the display names of GitHub plugins that were updated by the background poll. */
25
42
  onGithubPluginsUpdated(listener: (pluginNames: string[]) => void | Promise<void>): () => void;
@@ -31,7 +48,24 @@ export declare class PluginManager {
31
48
  getPluginSkillPaths(): string[];
32
49
  getPluginCommandPaths(): string[];
33
50
  getPluginInstructions(): string[];
51
+ /**
52
+ * Processors contributed by active plugins, tagged with the plugin that owns
53
+ * each one. Reads already-resolved state — no filesystem access — because the
54
+ * agent's processor lanes call this before every request.
55
+ */
56
+ getPluginProcessors(): PluginProcessorEntries;
57
+ /** Signal providers contributed by active plugins, tagged with their owning plugin. */
58
+ getPluginSignalProviders(): PluginContribution<SignalProvider<string>>[];
59
+ private collectActive;
34
60
  private notifyReloadListeners;
61
+ /**
62
+ * Stamps each plugin with a value that changes when its contributions should
63
+ * be rebuilt. Runs on every reload, so it stays off the network: GitHub heads
64
+ * come from the cache the poller keeps current and cost one `git rev-parse`
65
+ * per checkout the first time it is seen.
66
+ */
67
+ private stampLoadedPlugins;
68
+ private readSourceStamp;
35
69
  private updatePluginRenderConfigs;
36
70
  private updatePluginTools;
37
71
  private createLiveToolProxy;
@@ -1 +1 @@
1
- {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/plugins/manager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAoE,MAAM,cAAc,CAAC;AACtH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAIzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAa5D,KAAK,oBAAoB,GAAG,iBAAiB,GAAG;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,qBAAa,aAAa;IAaZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZpC,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmD;IAC/E,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmD;IAClF,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAyE;IAC3G,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,oBAAoB,EAAE,OAAO,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,CAAM,GAChF,OAAO,CAAC,MAAM,CAAC;IAUZ,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjF,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAAC,IAAI,CAAC;IAkBV,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBrE"}
@@ -27,13 +27,27 @@ var PluginManager = class {
27
27
  toolRenderConfigs = /* @__PURE__ */ new Map();
28
28
  watchedLocalEntries = /* @__PURE__ */ new Set();
29
29
  localEntryVersions = /* @__PURE__ */ new Map();
30
+ /** Last known git HEAD per GitHub checkout, kept current by the poller. */
31
+ githubCheckoutHeads = /* @__PURE__ */ new Map();
30
32
  githubPollTimer;
31
33
  githubPollInFlight;
32
34
  reloadInFlight;
33
35
  reloadListeners = /* @__PURE__ */ new Set();
34
36
  githubUpdateListeners = /* @__PURE__ */ new Set();
37
+ runtime;
35
38
  constructor(options) {
36
39
  this.options = options;
40
+ this.runtime = options.runtime;
41
+ }
42
+ /**
43
+ * Publish (or replace) the runtime accessors handed to plugin field resolvers.
44
+ * Takes effect on the next load or reload. `createMastraCode` calls this for
45
+ * every manager it uses — including an injected one — so a manager constructed
46
+ * without a runtime still exposes `getController`/`getActiveSession` to plugins.
47
+ * A manager shared across controllers sees the most recent controller's accessors.
48
+ */
49
+ setRuntime(runtime) {
50
+ this.runtime = runtime;
37
51
  }
38
52
  onReload(listener) {
39
53
  this.reloadListeners.add(listener);
@@ -47,7 +61,11 @@ var PluginManager = class {
47
61
  async reload() {
48
62
  if (this.reloadInFlight) return this.reloadInFlight;
49
63
  this.reloadInFlight = (async () => {
50
- this.loadedPlugins = await loadPlugins(this.options);
64
+ this.loadedPlugins = await loadPlugins({
65
+ ...this.options,
66
+ runtime: this.runtime
67
+ });
68
+ await this.stampLoadedPlugins(this.loadedPlugins);
51
69
  this.updateLocalEntryWatchers(this.loadedPlugins);
52
70
  this.updateGithubPoller(this.loadedPlugins);
53
71
  this.updatePluginRenderConfigs(this.loadedPlugins);
@@ -81,9 +99,60 @@ var PluginManager = class {
81
99
  getPluginInstructions() {
82
100
  return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" && plugin.instructions ? [plugin.instructions] : []);
83
101
  }
102
+ /**
103
+ * Processors contributed by active plugins, tagged with the plugin that owns
104
+ * each one. Reads already-resolved state — no filesystem access — because the
105
+ * agent's processor lanes call this before every request.
106
+ */
107
+ getPluginProcessors() {
108
+ return {
109
+ input: this.collectActive((plugin) => plugin.processors?.input ?? []),
110
+ output: this.collectActive((plugin) => plugin.processors?.output ?? [])
111
+ };
112
+ }
113
+ /** Signal providers contributed by active plugins, tagged with their owning plugin. */
114
+ getPluginSignalProviders() {
115
+ return this.collectActive((plugin) => plugin.signalProviders ?? []);
116
+ }
117
+ collectActive(select) {
118
+ return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" ? select(plugin).map((value) => ({
119
+ pluginId: plugin.id,
120
+ versionStamp: plugin.versionStamp ?? "",
121
+ value
122
+ })) : []);
123
+ }
84
124
  async notifyReloadListeners(plugins) {
85
125
  await Promise.all([...this.reloadListeners].map((listener) => Promise.resolve(listener(plugins))));
86
126
  }
127
+ /**
128
+ * Stamps each plugin with a value that changes when its contributions should
129
+ * be rebuilt. Runs on every reload, so it stays off the network: GitHub heads
130
+ * come from the cache the poller keeps current and cost one `git rev-parse`
131
+ * per checkout the first time it is seen.
132
+ */
133
+ async stampLoadedPlugins(plugins) {
134
+ for (const plugin of plugins) plugin.versionStamp = [
135
+ plugin.status,
136
+ await this.readSourceStamp(plugin),
137
+ JSON.stringify(plugin.configValues ?? {})
138
+ ].join("|");
139
+ }
140
+ async readSourceStamp(plugin) {
141
+ try {
142
+ if (plugin.source === "github") {
143
+ const checkoutPath = this.resolvePluginSourcePath(plugin);
144
+ let head = this.githubCheckoutHeads.get(checkoutPath);
145
+ if (head === void 0) {
146
+ head = await this.readGitHead(checkoutPath);
147
+ this.githubCheckoutHeads.set(checkoutPath, head);
148
+ }
149
+ return head;
150
+ }
151
+ return getEntryVersion(resolvePluginEntryPath(plugin, this.options));
152
+ } catch {
153
+ return "";
154
+ }
155
+ }
87
156
  updatePluginRenderConfigs(plugins) {
88
157
  this.toolRenderConfigs.clear();
89
158
  for (const plugin of plugins) {
@@ -188,6 +257,7 @@ var PluginManager = class {
188
257
  const before = await this.readGitHead(checkoutPath);
189
258
  const checkoutChanged = await this.refreshGithubCheckout(plugin, checkoutPath, before);
190
259
  const after = await this.readGitHead(checkoutPath);
260
+ this.githubCheckoutHeads.set(checkoutPath, after);
191
261
  if (checkoutChanged || before !== after) changedCheckouts.add(checkoutPath);
192
262
  }
193
263
  if (changedCheckouts.size === 0) return false;
@@ -311,7 +381,7 @@ var PluginManager = class {
311
381
  }
312
382
  resolvePluginSourcePath(plugin) {
313
383
  const paths = getPluginScopePaths(plugin.scope, this.options);
314
- return path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path);
384
+ return path.resolve(path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path));
315
385
  }
316
386
  async readGitHead(cwd) {
317
387
  const { stdout } = await execa("git", ["rev-parse", "HEAD"], gitExecOptions(cwd));
@@ -333,6 +403,7 @@ var PluginManager = class {
333
403
  ...this.options,
334
404
  ...options
335
405
  });
406
+ this.githubCheckoutHeads.clear();
336
407
  await this.reload();
337
408
  return id;
338
409
  }
@@ -374,6 +445,7 @@ var PluginManager = class {
374
445
  recursive: true,
375
446
  force: true
376
447
  });
448
+ this.githubCheckoutHeads.delete(checkoutPath);
377
449
  }
378
450
  await this.reload();
379
451
  }