mastracode 0.22.3-alpha.0 → 0.22.3-alpha.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # mastracode
2
2
 
3
+ ## 0.22.3-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Increased TUI chat scroll buffer from 200/100 to 5000/3000 components, so you can scroll back much further in conversation history ([#17633](https://github.com/mastra-ai/mastra/pull/17633))
8
+
9
+ - Fixed state signal placement in streamed MastraCode output. ([#17631](https://github.com/mastra-ai/mastra/pull/17631))
10
+
11
+ - Fixed the GitHub PR badge in MastraCode so it animates only while GitHub polling is actively running, instead of restarting whenever the agent processes a user message. ([#17590](https://github.com/mastra-ai/mastra/pull/17590))
12
+
13
+ - Added agent and workspace tool hooks for applications that need to run logic before and after tool calls execute. Mastra Code now uses agent hooks so hook handlers run for built-in workspace tools as well as dynamic tools. ([#17637](https://github.com/mastra-ai/mastra/pull/17637))
14
+
15
+ **Example**
16
+
17
+ ```ts
18
+ const agent = new Agent({
19
+ name: 'Support Agent',
20
+ instructions: 'Help users.',
21
+ model,
22
+ hooks: {
23
+ beforeToolCall: ({ toolName, input }) => {
24
+ console.log(`Running ${toolName}`, input);
25
+ },
26
+ afterToolCall: ({ toolName, output, error }) => {
27
+ console.log(`Finished ${toolName}`, { output, error });
28
+ },
29
+ },
30
+ });
31
+
32
+ const workspace = new Workspace({
33
+ tools: {
34
+ hooks: {
35
+ beforeToolCall: ({ toolName, workspaceToolName, input }) => {
36
+ console.log(`Running ${toolName} from ${workspaceToolName}`, input);
37
+ },
38
+ },
39
+ },
40
+ });
41
+ ```
42
+
43
+ - Updated dependencies [[`2bccba4`](https://github.com/mastra-ai/mastra/commit/2bccba4c03cadc815c2d54cbf4dd43a922140a8d), [`2bccba4`](https://github.com/mastra-ai/mastra/commit/2bccba4c03cadc815c2d54cbf4dd43a922140a8d), [`2bccba4`](https://github.com/mastra-ai/mastra/commit/2bccba4c03cadc815c2d54cbf4dd43a922140a8d), [`f2ab060`](https://github.com/mastra-ai/mastra/commit/f2ab060162bea81505fda553e2cee29c1979fd04), [`5d302c8`](https://github.com/mastra-ai/mastra/commit/5d302c8eda1a6ac74eab5e442c4f64db6cc97a06), [`f2ab060`](https://github.com/mastra-ai/mastra/commit/f2ab060162bea81505fda553e2cee29c1979fd04)]:
44
+ - @mastra/core@1.42.0-alpha.1
45
+ - @mastra/github-signals@0.1.1-alpha.0
46
+ - @mastra/agent-browser@0.3.1-alpha.0
47
+
3
48
  ## 0.22.3-alpha.0
4
49
 
5
50
  ### Patch Changes
@@ -1,15 +1,16 @@
1
1
  import type { RequestContext } from '@mastra/core/request-context';
2
2
  import type { MastraCompositeStore } from '@mastra/core/storage';
3
+ import type { ToolHooks } from '@mastra/core/tools';
3
4
  import type { HookManager } from '../hooks/index.js';
4
5
  import type { McpManager } from '../mcp/index.js';
5
6
  /** Minimal shape for tools passed to createDynamicTools. */
6
- type ToolLike = {
7
+ export type ToolLike = {
7
8
  execute?: (...args: any[]) => Promise<unknown> | unknown;
8
9
  } & Record<string, any>;
10
+ export declare function createToolHooks(hookManager?: HookManager): ToolHooks | undefined;
9
11
  export declare function createDynamicTools(mcpManager?: McpManager, extraTools?: Record<string, ToolLike> | ((ctx: {
10
12
  requestContext: RequestContext;
11
- }) => Record<string, ToolLike>), hookManager?: HookManager, disabledTools?: string[], storage?: MastraCompositeStore): ({ requestContext }: {
13
+ }) => Record<string, ToolLike>), disabledTools?: string[], storage?: MastraCompositeStore): ({ requestContext }: {
12
14
  requestContext: RequestContext;
13
15
  }) => Record<string, ToolLike>;
14
- export {};
15
16
  //# sourceMappingURL=tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/agents/tools.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAA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,OAAO,CAAC,GAAG,OAAO,CAAC;CAC1D,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAwCxB,wBAAgB,eAAe,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,SAAS,CA0BhF;AAED,wBAAgB,kBAAkB,CAChC,UAAU,CAAC,EAAE,UAAU,EACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,EAC/G,aAAa,CAAC,EAAE,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,oBAAoB,IAEE,oBAAoB;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,8BAiEvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/agents/workspace.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAiFlF,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAchF;AA2BD,wBAAgB,mBAAmB,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE;IAAE,cAAc,EAAE,cAAc,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,uDA8DlH"}
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/agents/workspace.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAiFlF,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAchF;AA2BD,wBAAgB,mBAAmB,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE;IAAE,cAAc,EAAE,cAAc,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,uDAkElH"}
@@ -592,6 +592,9 @@ function getDynamicWorkspace({ requestContext, mastra: mastra2 }) {
592
592
  mastra_workspace_edit_file: { ...chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES.mastra_workspace_edit_file, enabled: false },
593
593
  mastra_workspace_ast_edit: { ...chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES.mastra_workspace_ast_edit, enabled: false }
594
594
  };
595
+ const workspaceTools = {
596
+ ...isPlanMode ? { ...chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES, ...planModeTools } : chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES
597
+ };
595
598
  let existing;
596
599
  try {
597
600
  existing = mastra2?.getWorkspaceById(workspaceId);
@@ -599,11 +602,11 @@ function getDynamicWorkspace({ requestContext, mastra: mastra2 }) {
599
602
  }
600
603
  if (existing) {
601
604
  existing.filesystem.setAllowedPaths(allowedPaths);
602
- existing.setToolsConfig(isPlanMode ? { ...chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES, ...planModeTools } : chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES);
605
+ existing.setToolsConfig(workspaceTools);
603
606
  return existing;
604
607
  }
605
608
  const userLsp = chunkA4W5D25I_cjs.loadSettings().lsp ?? {};
606
- const mcModulePath = path.join(path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-TU3VBXJJ.cjs', document.baseURI).href)))), "..");
609
+ const mcModulePath = path.join(path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-AGLPYB76.cjs', document.baseURI).href)))), "..");
607
610
  const lspConfig = {
608
611
  ...userLsp,
609
612
  packageRunner: userLsp.packageRunner || detectPackageRunner(projectPath),
@@ -621,7 +624,7 @@ function getDynamicWorkspace({ requestContext, mastra: mastra2 }) {
621
624
  workingDirectory: projectPath,
622
625
  env: buildSandboxEnv()
623
626
  }),
624
- tools: isPlanMode ? { ...chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES, ...planModeTools } : chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES,
627
+ tools: workspaceTools,
625
628
  ...skillPaths.length > 0 ? { skills: skillPaths } : {},
626
629
  lsp: lspConfig
627
630
  });
@@ -1369,37 +1372,31 @@ var LazyNotificationsStorage = class extends notifications.NotificationsStorage
1369
1372
  return (await this.getNotificationsStorage()).dangerouslyClearAll();
1370
1373
  }
1371
1374
  };
1372
- function wrapToolWithHooks(toolName, tool, hookManager) {
1373
- if (!hookManager || typeof tool?.execute !== "function") {
1374
- return tool;
1375
- }
1375
+ function createToolHooks(hookManager) {
1376
+ if (!hookManager) return void 0;
1376
1377
  return {
1377
- ...tool,
1378
- async execute(input, toolContext) {
1378
+ beforeToolCall: async ({ toolName, input }) => {
1379
1379
  const preResult = await hookManager.runPreToolUse(toolName, input);
1380
1380
  if (!preResult.allowed) {
1381
1381
  return {
1382
- error: preResult.blockReason ?? `Blocked by PreToolUse hook for tool "${toolName}"`
1383
- };
1384
- }
1385
- let output;
1386
- let toolError = false;
1387
- try {
1388
- output = await tool.execute?.(input, toolContext);
1389
- return output;
1390
- } catch (error) {
1391
- toolError = true;
1392
- output = {
1393
- error: error instanceof Error ? error.message : String(error)
1382
+ proceed: false,
1383
+ output: {
1384
+ error: preResult.blockReason ?? `Blocked by PreToolUse hook for tool "${toolName}"`
1385
+ }
1394
1386
  };
1395
- throw error;
1396
- } finally {
1397
- await hookManager.runPostToolUse(toolName, input, output, toolError).catch(() => void 0);
1398
1387
  }
1388
+ },
1389
+ afterToolCall: async ({ toolName, input, output, error }) => {
1390
+ await hookManager.runPostToolUse(
1391
+ toolName,
1392
+ input,
1393
+ error ? { error: error instanceof Error ? error.message : String(error) } : output,
1394
+ Boolean(error)
1395
+ ).catch(() => void 0);
1399
1396
  }
1400
1397
  };
1401
1398
  }
1402
- function createDynamicTools(mcpManager, extraTools, hookManager, disabledTools, storage) {
1399
+ function createDynamicTools(mcpManager, extraTools, disabledTools, storage) {
1403
1400
  return function getDynamicTools({ requestContext }) {
1404
1401
  const ctx = requestContext.get("harness");
1405
1402
  const state = ctx?.getState?.();
@@ -1449,9 +1446,6 @@ function createDynamicTools(mcpManager, extraTools, hookManager, disabledTools,
1449
1446
  }
1450
1447
  }
1451
1448
  }
1452
- for (const [toolName, tool] of Object.entries(tools)) {
1453
- tools[toolName] = wrapToolWithHooks(toolName, tool, hookManager);
1454
- }
1455
1449
  return tools;
1456
1450
  };
1457
1451
  }
@@ -3314,7 +3308,8 @@ async function createMastraCode(config) {
3314
3308
  name: "Code Agent",
3315
3309
  instructions: getDynamicInstructions,
3316
3310
  model: chunkA4W5D25I_cjs.getDynamicModel,
3317
- tools: createDynamicTools(mcpManager, config?.extraTools, hookManager, config?.disabledTools, storage$1),
3311
+ tools: createDynamicTools(mcpManager, config?.extraTools, config?.disabledTools, storage$1),
3312
+ hooks: createToolHooks(hookManager),
3318
3313
  scorers: {
3319
3314
  outcome: {
3320
3315
  scorer: outcomeScorer,
@@ -3528,7 +3523,7 @@ async function createMastraCode(config) {
3528
3523
  // with MCP/hooks/storage which were already initialized with this value.
3529
3524
  configDir
3530
3525
  },
3531
- workspace: config?.workspace ?? getDynamicWorkspace,
3526
+ workspace: config?.workspace ?? ((args) => getDynamicWorkspace(args)),
3532
3527
  browser: config?.browser,
3533
3528
  modes,
3534
3529
  heartbeatHandlers,
@@ -3667,5 +3662,5 @@ async function createMastraCode(config) {
3667
3662
 
3668
3663
  exports.createAuthStorage = createAuthStorage;
3669
3664
  exports.createMastraCode = createMastraCode;
3670
- //# sourceMappingURL=chunk-TU3VBXJJ.cjs.map
3671
- //# sourceMappingURL=chunk-TU3VBXJJ.cjs.map
3665
+ //# sourceMappingURL=chunk-AGLPYB76.cjs.map
3666
+ //# sourceMappingURL=chunk-AGLPYB76.cjs.map