mastracode 0.50.1-alpha.2 → 0.50.1-alpha.4

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,30 @@
1
1
  # mastracode
2
2
 
3
+ ## 0.50.1-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - **Showed plugin signal provider startup failures.** A plugin signal provider that fails to start while Mastra Code boots now shows an error in the session, as reload failures do, instead of only printing to the console before the UI starts. ([#30428](https://github.com/mastra-ai/mastra/pull/30428))
8
+
9
+ - **Fixed startup carrying on after you stop Mastra Code.** If you press Ctrl+C while Mastra Code is still starting, startup now stops. Before, it kept going even though Mastra Code was shutting down. It could take the terminal back, resume and lock a thread, clone a thread from another resource, and connect MCP servers. It could also apply the startup model pack, open onboarding, run SessionStart hooks and send the startup prompt. Stopping during onboarding no longer opens the login dialog, switches models or opens the model picker either. Text you typed is also no longer submitted after Mastra Code stops. ([#30431](https://github.com/mastra-ai/mastra/pull/30431))
10
+
11
+ - Updated dependencies [[`88b4a97`](https://github.com/mastra-ai/mastra/commit/88b4a970426f48731a153e46ed228d0301da32a1), [`33eaa29`](https://github.com/mastra-ai/mastra/commit/33eaa293e28aa8cd86ad68e1eaf44b4929be818d), [`6c647e6`](https://github.com/mastra-ai/mastra/commit/6c647e6faee5a6182d99e2352808df1b57558b67), [`adc0a70`](https://github.com/mastra-ai/mastra/commit/adc0a70bf835d1f81f7bf0af11b247ca115a6683), [`cd2a326`](https://github.com/mastra-ai/mastra/commit/cd2a326988ced13509902dfa50339afcffdbf95e), [`0170d70`](https://github.com/mastra-ai/mastra/commit/0170d700a411ce2b5e64a82bc1133716ae75cbd6), [`4224ee3`](https://github.com/mastra-ai/mastra/commit/4224ee32d3e8fa0f76aedab499c24acc1a564435), [`1072f7c`](https://github.com/mastra-ai/mastra/commit/1072f7c6268db5fb515460fdcdda173592bce450), [`c8a35ac`](https://github.com/mastra-ai/mastra/commit/c8a35ac6243eaef8ef1d9e589a7b75bf44904d8b), [`c8a35ac`](https://github.com/mastra-ai/mastra/commit/c8a35ac6243eaef8ef1d9e589a7b75bf44904d8b)]:
12
+ - @mastra/core@1.84.0-alpha.3
13
+ - @mastra/libsql@1.31.0-alpha.1
14
+ - @mastra/pg@1.37.0-alpha.1
15
+ - @mastra/memory@1.41.2-alpha.2
16
+ - @mastra/mcp@2.10.0-alpha.0
17
+ - @mastra/code-sdk@1.19.1-alpha.4
18
+
19
+ ## 0.50.1-alpha.3
20
+
21
+ ### Patch Changes
22
+
23
+ - **Showed plugin failures in the session.** When a plugin fails to reload, Mastra Code now shows an error saying it is still running the previous version, and signal provider errors from plugins appear the same way instead of only on the console. ([#30412](https://github.com/mastra-ai/mastra/pull/30412))
24
+
25
+ - Updated dependencies [[`02dbde1`](https://github.com/mastra-ai/mastra/commit/02dbde13cc09e9605279b46cb49f03f3b91dd48f), [`7f09a63`](https://github.com/mastra-ai/mastra/commit/7f09a63553cd382c5098fa25f8c42312a3d82494), [`5686fa1`](https://github.com/mastra-ai/mastra/commit/5686fa16edd60a1a30b97dbbdf97e852e588436b)]:
26
+ - @mastra/code-sdk@1.19.1-alpha.3
27
+
3
28
  ## 0.50.1-alpha.2
4
29
 
5
30
  ### Patch Changes
package/dist/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_tui = require("./tui-edzCSg8-.cjs");
2
+ const require_tui = require("./tui-BfBjFTxw.cjs");
3
3
  let _mastra_code_sdk = require("@mastra/code-sdk");
4
4
  let child_process = require("child_process");
5
5
  let fs = require("fs");
@@ -265,7 +265,7 @@ async function runUpdateCommand({ args = [], output = process.stdout, errorOutpu
265
265
  }
266
266
  // src/version.ts
267
267
  function getCurrentVersion() {
268
- return "0.50.1-alpha.2";
268
+ return "0.50.1-alpha.4";
269
269
  }
270
270
  /** Whether the invocation is `mastracode --version` or `mastracode -v`. */
271
271
  function isVersionCommand(argv) {
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { D as closeActiveBrowser, E as activeBrowserGeneration, O as discardBrowser, T as TUI_CO_AUTHOR, _ as normalizeThemePreference, a as formatUpdateHeader, g as applyThemePreference, i as formatUpToDate, k as replaceActiveBrowser, n as formatInstallingLabel, o as formatUpdateOutcome, r as formatRegistryError, t as MastraTUI } from "./tui-t0Xga0co.js";
2
+ import { D as closeActiveBrowser, E as activeBrowserGeneration, O as discardBrowser, T as TUI_CO_AUTHOR, _ as normalizeThemePreference, a as formatUpdateHeader, g as applyThemePreference, i as formatUpToDate, k as replaceActiveBrowser, n as formatInstallingLabel, o as formatUpdateOutcome, r as formatRegistryError, t as MastraTUI } from "./tui-IoCMmeHj.js";
3
3
  import { createMastraCode, resolveSubagentsSetting } from "@mastra/code-sdk";
4
4
  import { spawn } from "child_process";
5
5
  import fs from "fs";
@@ -264,7 +264,7 @@ async function runUpdateCommand({ args = [], output = process.stdout, errorOutpu
264
264
  }
265
265
  // src/version.ts
266
266
  function getCurrentVersion() {
267
- return "0.50.1-alpha.2";
267
+ return "0.50.1-alpha.4";
268
268
  }
269
269
  /** Whether the invocation is `mastracode --version` or `mastracode -v`. */
270
270
  function isVersionCommand(argv) {
@@ -3,7 +3,7 @@ name: mastracode
3
3
  description: Documentation for mastracode. Use when working with mastracode APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "mastracode"
6
- version: "0.50.1-alpha.2"
6
+ version: "0.50.1-alpha.4"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.50.1-alpha.2",
2
+ "version": "0.50.1-alpha.4",
3
3
  "package": "mastracode",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1,6 +1,6 @@
1
1
  import type { MastraTUIOptions, TUIState } from './state.js';
2
2
  export type { MastraTUIOptions } from './state.js';
3
- export declare function syncInitialThreadState(state: TUIState): Promise<void>;
3
+ export declare function syncInitialThreadState(state: TUIState, isCurrent?: () => boolean): Promise<void>;
4
4
  export declare function consumePendingImages(text: string, pendingImages: TUIState['pendingImages']): {
5
5
  content: string;
6
6
  images?: TUIState['pendingImages'];
@@ -14,6 +14,7 @@ export declare class MastraTUI {
14
14
  private cleanupKeyHandlers?;
15
15
  private cleanupPluginReloadListener?;
16
16
  private cleanupPluginUpdateListener?;
17
+ private cleanupPluginErrorListener?;
17
18
  private cleanupBackgroundCompletionListener?;
18
19
  private backgroundNoticeQueue;
19
20
  private lastStreamError;
@@ -1 +1 @@
1
- {"version":3,"file":"mastra-tui.d.ts","sourceRoot":"","sources":["../../src/tui/mastra-tui.ts"],"names":[],"mappings":"AA0FA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAW7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAkCnD,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiD3E;AAMD,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,QAAQ,CAAC,eAAe,CAAC,GACvC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAA;CAAE,CAQzD;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,gBAAgB,CAA+C;IACvE,OAAO,CAAC,iBAAiB,CAA+C;IACxE,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,kBAAkB,CAAC,CAAa;IACxC,OAAO,CAAC,2BAA2B,CAAC,CAAa;IACjD,OAAO,CAAC,2BAA2B,CAAC,CAAa;IACjD,OAAO,CAAC,mCAAmC,CAAC,CAAa;IACzD,OAAO,CAAC,qBAAqB,CAAqB;IAClD,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,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AI,MAAM,GAAG,IAAI,CAEjC;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,CA0DX;YAEa,yBAAyB;YAmBzB,IAAI;YAmLJ,sBAAsB;IAKpC,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,wBAAwB;IAMhC,OAAO,CAAC,6BAA6B;IAYrC,OAAO,CAAC,2BAA2B;YAQrB,wCAAwC;IAkBtD,OAAO,CAAC,uBAAuB;IAe/B,iEAAiE;IACjE,OAAO,CAAC,KAAK,CAAkC;IAE/C,OAAO,CAAC,eAAe;YAOT,WAAW;IAgEzB,OAAO,CAAC,+BAA+B;IAuCvC,OAAO,CAAC,iBAAiB;IAqCzB,OAAO,CAAC,eAAe;IA4BvB,OAAO,CAAC,cAAc;YAUR,mBAAmB;YAmCnB,4BAA4B;IAyC1C,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,0BAA0B;YAoBpB,eAAe;IAU7B,OAAO,CAAC,eAAe;YAKT,WAAW;YAeX,iBAAiB;IAqB/B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAuB/B,OAAO,CAAC,uBAAuB;IA0D/B,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAgB5B,OAAO,CAAC,mBAAmB;IA2B3B,OAAO,CAAC,iBAAiB;YA4BX,kBAAkB;IAQ1B,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsEpD;IAMK,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAuGpC;YAEa,qBAAqB;IA4DnC,OAAO,CAAC,oBAAoB;IAa5B;;;;;OAKG;YACW,cAAc;IA2C5B;;;OAGG;YACW,gBAAgB;CAa/B"}
@@ -13,5 +13,5 @@ export type StartupResumeIssue = {
13
13
  * locked does not throw; the session is left pending a new thread and the issue
14
14
  * is returned so the caller can tell the user once the UI is ready.
15
15
  */
16
- export declare function resumeThreadOnStartup(state: TUIState, requestedThreadId?: string): Promise<StartupResumeIssue | undefined>;
16
+ export declare function resumeThreadOnStartup(state: TUIState, requestedThreadId?: string, isCurrent?: () => boolean): Promise<StartupResumeIssue | undefined>;
17
17
  //# sourceMappingURL=thread-startup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"thread-startup.d.ts","sourceRoot":"","sources":["../../src/tui/thread-startup.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,QAAQ,EACf,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAwDzC"}
1
+ {"version":3,"file":"thread-startup.d.ts","sourceRoot":"","sources":["../../src/tui/thread-startup.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,QAAQ,EACf,iBAAiB,CAAC,EAAE,MAAM,EAC1B,SAAS,GAAE,MAAM,OAAoB,GACpC,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CA4DzC"}
@@ -28661,12 +28661,13 @@ var SimpleProgressComponent = class extends _earendil_works_pi_tui.Container {
28661
28661
  * locked does not throw; the session is left pending a new thread and the issue
28662
28662
  * is returned so the caller can tell the user once the UI is ready.
28663
28663
  */
28664
- async function resumeThreadOnStartup(state, requestedThreadId) {
28664
+ async function resumeThreadOnStartup(state, requestedThreadId, isCurrent = () => true) {
28665
28665
  const local = state.local;
28666
- if (!local) return resumeFactoryThread(state);
28666
+ if (!local) return resumeFactoryThread(state, isCurrent);
28667
28667
  const { session, controller } = local;
28668
28668
  const currentPath = state.projectInfo.rootPath;
28669
28669
  const allThreads = await session.thread.list(requestedThreadId ? { allResources: true } : void 0);
28670
+ if (!isCurrent()) return;
28670
28671
  const activeThreadId = session.thread.getId();
28671
28672
  if (requestedThreadId) {
28672
28673
  const thread = allThreads.find((candidate) => candidate.id === requestedThreadId);
@@ -28697,11 +28698,13 @@ async function resumeThreadOnStartup(state, requestedThreadId) {
28697
28698
  }
28698
28699
  const threads = allThreads.filter((thread) => thread.metadata?.projectPath === currentPath);
28699
28700
  if (threads.length === 0) {
28700
- if (await cloneDriftedThread(state, local)) return;
28701
+ if (await cloneDriftedThread(state, local, isCurrent)) return;
28702
+ if (!isCurrent()) return;
28701
28703
  state.pendingNewThread = true;
28702
28704
  return;
28703
28705
  }
28704
28706
  for (const thread of [...threads].sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime())) {
28707
+ if (!isCurrent()) return;
28705
28708
  if (thread.id === session.thread.getId()) return;
28706
28709
  try {
28707
28710
  await session.thread.switch({ threadId: thread.id });
@@ -28711,12 +28714,14 @@ async function resumeThreadOnStartup(state, requestedThreadId) {
28711
28714
  throw error;
28712
28715
  }
28713
28716
  }
28717
+ if (!isCurrent()) return;
28714
28718
  state.pendingNewThread = true;
28715
28719
  }
28716
28720
  /** Factory sessions own their threads, so local project-path tagging and resource IDs don't apply. */
28717
- async function resumeFactoryThread(state) {
28721
+ async function resumeFactoryThread(state, isCurrent) {
28718
28722
  if (state.session.thread.getId()) return;
28719
28723
  const [latest] = (await state.session.thread.list()).sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
28724
+ if (!isCurrent()) return;
28720
28725
  if (latest) await state.session.thread.switch({ threadId: latest.id });
28721
28726
  else state.pendingNewThread = true;
28722
28727
  }
@@ -28730,14 +28735,14 @@ async function startPendingNewThread(state, { session }) {
28730
28735
  await session.thread.clearAndReleaseLock();
28731
28736
  state.pendingNewThread = true;
28732
28737
  }
28733
- async function cloneDriftedThread(state, { session }) {
28738
+ async function cloneDriftedThread(state, { session }, isCurrent) {
28734
28739
  const currentPath = state.projectInfo.rootPath;
28735
28740
  const currentResourceId = session.identity.getResourceId();
28736
28741
  const thread = [...(await session.thread.list({
28737
28742
  allResources: true,
28738
28743
  metadata: { projectPath: currentPath }
28739
28744
  })).filter((thread) => thread.resourceId !== currentResourceId)].sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime())[0];
28740
- if (!thread) return false;
28745
+ if (!thread || !isCurrent()) return false;
28741
28746
  if (await askModalQuestion(state.ui, {
28742
28747
  question: [
28743
28748
  "This directory is tagged on a different resource.",
@@ -28756,7 +28761,7 @@ async function cloneDriftedThread(state, { session }) {
28756
28761
  widthPercent: 80,
28757
28762
  maxHeight: "70%"
28758
28763
  }
28759
- }) !== "Clone and resume") return false;
28764
+ }) !== "Clone and resume" || !isCurrent()) return false;
28760
28765
  const progress = new SimpleProgressComponent({
28761
28766
  showElapsed: false,
28762
28767
  showPercentage: false
@@ -28770,6 +28775,7 @@ async function cloneDriftedThread(state, { session }) {
28770
28775
  state.ui.requestRender();
28771
28776
  try {
28772
28777
  await new Promise((resolve) => setTimeout(resolve, 50));
28778
+ if (!isCurrent()) return false;
28773
28779
  progress.updateStatus("Loading cloned thread...");
28774
28780
  state.ui.requestRender();
28775
28781
  await session.thread.cloneToCurrentResource({
@@ -28800,15 +28806,16 @@ function fallbackStatusFromMetadata(metadata) {
28800
28806
  const persisted = metadata?.[_mastra_code_sdk_onboarding_settings.THREAD_FALLBACK_STATUS_KEY];
28801
28807
  if (persisted && typeof persisted === "object" && typeof persisted.usingPack === "string" && typeof persisted.failedPack === "string") return persisted;
28802
28808
  }
28803
- async function syncInitialThreadState(state) {
28809
+ async function syncInitialThreadState(state, isCurrent = () => true) {
28804
28810
  const initThreadId = state.session.thread.getId();
28805
28811
  if (!initThreadId) {
28806
28812
  setCurrentThreadTitle(state, void 0);
28807
28813
  state.fallbackStatus = void 0;
28808
28814
  return;
28809
28815
  }
28816
+ const ownsUpdate = () => isCurrent() && state.session.thread.getId() === initThreadId;
28810
28817
  const initThreads = await state.session.thread.list();
28811
- if (state.session.thread.getId() !== initThreadId) return;
28818
+ if (!ownsUpdate()) return;
28812
28819
  const initThread = initThreads.find((t) => t.id === initThreadId);
28813
28820
  const metadata = initThread?.metadata;
28814
28821
  const persistedFallbackStatus = fallbackStatusFromMetadata(metadata);
@@ -28817,13 +28824,13 @@ async function syncInitialThreadState(state) {
28817
28824
  const currentPending = (state.session.state?.get?.())?.[_mastra_code_sdk_auth_account_rotation_processor.MODEL_FALLBACK_STATE_KEY];
28818
28825
  if (validPendingFallback || currentPending) {
28819
28826
  const updates = { [_mastra_code_sdk_auth_account_rotation_processor.MODEL_FALLBACK_STATE_KEY]: validPendingFallback };
28820
- if (!(state.session.state.setIf ? await state.session.state.setIf(updates, () => state.session.thread.getId() === initThreadId) : state.session.thread.getId() === initThreadId ? await state.session.state.set(updates).then(() => true) : false) || state.session.thread.getId() !== initThreadId) return;
28827
+ if (!(state.session.state.setIf ? await state.session.state.setIf(updates, ownsUpdate) : ownsUpdate() ? await state.session.state.set(updates).then(() => true) : false) || !ownsUpdate()) return;
28821
28828
  }
28822
28829
  setCurrentThreadTitle(state, initThread?.title);
28823
28830
  state.fallbackStatus = persistedFallbackStatus;
28824
28831
  state.activeGithubPrSubscriptions = getGithubPrSubscriptionsFromMetadata(metadata);
28825
28832
  if (state.local) await state.goalManager.loadFromThread(state.local);
28826
- if (state.session.thread.getId() !== initThreadId) return;
28833
+ if (!ownsUpdate()) return;
28827
28834
  if (!state.goalManager.getGoal()) state.goalManager.loadFromThreadMetadata(metadata);
28828
28835
  }
28829
28836
  function shouldUseCaffeinate() {
@@ -28846,6 +28853,7 @@ var MastraTUI = class MastraTUI {
28846
28853
  cleanupKeyHandlers;
28847
28854
  cleanupPluginReloadListener;
28848
28855
  cleanupPluginUpdateListener;
28856
+ cleanupPluginErrorListener;
28849
28857
  cleanupBackgroundCompletionListener;
28850
28858
  backgroundNoticeQueue = Promise.resolve();
28851
28859
  lastStreamError = null;
@@ -28990,15 +28998,19 @@ var MastraTUI = class MastraTUI {
28990
28998
  */
28991
28999
  async run() {
28992
29000
  await this.init();
29001
+ if (this.stopped) return;
28993
29002
  const hookMgr = this.state.hookManager;
28994
29003
  if (hookMgr) hookMgr.runSessionStart().catch(() => {});
28995
29004
  if (this.state.options.initialMessage) {
28996
29005
  const { resumeSkipNotice } = this.state.options;
28997
- if (resumeSkipNotice && await this.resumedConversation()) showInfo(this.state, resumeSkipNotice);
29006
+ const resumed = resumeSkipNotice ? await this.resumedConversation() : false;
29007
+ if (this.stopped) return;
29008
+ if (resumeSkipNotice && resumed) showInfo(this.state, resumeSkipNotice);
28998
29009
  else await this.submitUserInput(this.state.options.initialMessage);
28999
29010
  }
29000
- while (true) {
29011
+ while (!this.stopped) {
29001
29012
  const userInput = await this.getUserInput();
29013
+ if (this.stopped) return;
29002
29014
  if (!userInput.trim() && userInput !== " ") continue;
29003
29015
  await this.submitUserInput(userInput);
29004
29016
  }
@@ -29034,7 +29046,9 @@ var MastraTUI = class MastraTUI {
29034
29046
  const { content, images } = consumePendingImages(userInput, this.state.pendingImages);
29035
29047
  this.state.pendingImages = [];
29036
29048
  const optimisticMessageId = this.renderOptimisticUserMessage(content, images);
29037
- if (!await this.runUserPromptHook(userInput)) {
29049
+ const allowed = await this.runUserPromptHook(userInput);
29050
+ if (this.stopped) return;
29051
+ if (!allowed) {
29038
29052
  this.removeOptimisticUserMessage(optimisticMessageId);
29039
29053
  return;
29040
29054
  }
@@ -29147,7 +29161,9 @@ var MastraTUI = class MastraTUI {
29147
29161
  send();
29148
29162
  return;
29149
29163
  }
29150
- pendingThread.then(send).catch((error) => {
29164
+ pendingThread.then(() => {
29165
+ if (!this.stopped) send();
29166
+ }).catch((error) => {
29151
29167
  this.removeOptimisticUserMessage(optimisticMessageId);
29152
29168
  showSessionError(this.state, error);
29153
29169
  });
@@ -29229,6 +29245,9 @@ var MastraTUI = class MastraTUI {
29229
29245
  this.cleanupKeyHandlers();
29230
29246
  this.cleanupKeyHandlers = void 0;
29231
29247
  }
29248
+ this.state.editor.onSubmit = void 0;
29249
+ this.pendingUserInputResolve = void 0;
29250
+ this.queuedUserInput = [];
29232
29251
  if (this.cleanupPluginReloadListener) {
29233
29252
  this.cleanupPluginReloadListener();
29234
29253
  this.cleanupPluginReloadListener = void 0;
@@ -29237,6 +29256,10 @@ var MastraTUI = class MastraTUI {
29237
29256
  this.cleanupPluginUpdateListener();
29238
29257
  this.cleanupPluginUpdateListener = void 0;
29239
29258
  }
29259
+ if (this.cleanupPluginErrorListener) {
29260
+ this.cleanupPluginErrorListener();
29261
+ this.cleanupPluginErrorListener = void 0;
29262
+ }
29240
29263
  if (this.cleanupBackgroundCompletionListener) {
29241
29264
  this.cleanupBackgroundCompletionListener();
29242
29265
  this.cleanupBackgroundCompletionListener = void 0;
@@ -29262,8 +29285,10 @@ var MastraTUI = class MastraTUI {
29262
29285
  const local = this.state.local;
29263
29286
  if (local) {
29264
29287
  await local.controller.init();
29288
+ if (this.stopped) return;
29265
29289
  await local.controller.getMastra()?.startWorkers();
29266
29290
  }
29291
+ if (this.stopped) return;
29267
29292
  if (this.state.pluginManager && !this.cleanupPluginReloadListener) this.cleanupPluginReloadListener = this.state.pluginManager.onReload((plugins) => this.refreshPluginRuntimeState(plugins).catch((err) => {
29268
29293
  const msg = err instanceof Error ? err.message : String(err);
29269
29294
  process.stderr.write(`[plugin runtime refresh] ${msg}\n`);
@@ -29274,6 +29299,7 @@ var MastraTUI = class MastraTUI {
29274
29299
  showInfo(this.state, `${label} updated to the latest version: ${pluginNames.join(", ")}`);
29275
29300
  });
29276
29301
  await loadCustomSlashCommands(this.state);
29302
+ if (this.stopped) return;
29277
29303
  setupAutocomplete(this.state);
29278
29304
  refreshSkillsAutocomplete(this.state).catch((err) => {
29279
29305
  const msg = err instanceof Error ? err.message : String(err);
@@ -29286,7 +29312,8 @@ var MastraTUI = class MastraTUI {
29286
29312
  doubleCtrlCMs: MastraTUI.DOUBLE_CTRL_C_MS
29287
29313
  });
29288
29314
  this.state.ui.start();
29289
- const startupResumeIssue = await resumeThreadOnStartup(this.state, this.state.options.resumeThreadId);
29315
+ const startupResumeIssue = await resumeThreadOnStartup(this.state, this.state.options.resumeThreadId, () => !this.stopped);
29316
+ if (this.stopped) return;
29290
29317
  if (this.state.options.initialPackId) {
29291
29318
  const packId = this.state.options.initialPackId;
29292
29319
  const settings = (0, _mastra_code_sdk_onboarding_index.loadSettings)();
@@ -29300,13 +29327,17 @@ var MastraTUI = class MastraTUI {
29300
29327
  (0, _mastra_code_sdk_onboarding_pack_activation.activateModePackInSettings)(settings, packId);
29301
29328
  (0, _mastra_code_sdk_onboarding_index.saveSettings)(settings);
29302
29329
  await applyCurrentThreadPack({ state: this.state }, { packId });
29330
+ if (this.stopped) return;
29303
29331
  }
29304
- await this.syncThreadActivePackMetadata();
29332
+ await this.syncThreadActivePackMetadata(void 0, () => !this.stopped);
29333
+ if (this.stopped) return;
29305
29334
  subscribeToAgentController(this.state, (event) => this.handleEvent(event));
29306
29335
  if (this.state.options.backgroundToolsEnabled) this.cleanupBackgroundCompletionListener = this.state.options.backgroundCompletionEvents?.subscribe((event) => this.handleBackgroundCompletion(event));
29307
29336
  if (this.state.session.state.get()?.escapeAsCancel === false) this.state.editor.escapeEnabled = false;
29308
29337
  await this.state.local?.controller.loadOMProgress(this.state.local.session);
29309
- await syncInitialThreadState(this.state);
29338
+ if (this.stopped) return;
29339
+ await syncInitialThreadState(this.state, () => !this.stopped);
29340
+ if (this.stopped) return;
29310
29341
  this.state.isInitialized = true;
29311
29342
  if (this.state.mcpManager?.hasServers()) this.state.mcpManager.initInBackground().then((result) => {
29312
29343
  for (const s of result.failed) if (s.needsAuth) showInfo(this.state, `MCP: \u26a0 "${s.name}" needs authentication \u2192 run /mcp to authenticate`);
@@ -29315,9 +29346,18 @@ var MastraTUI = class MastraTUI {
29315
29346
  }).catch((error) => {
29316
29347
  showInfo(this.state, `MCP: Initialization failed: ${error instanceof Error ? error.message : String(error)}`);
29317
29348
  });
29318
- await this.renderExistingMessagesAndSeedIdleCounter();
29349
+ await this.renderExistingMessagesAndSeedIdleCounter(() => !this.stopped);
29350
+ if (this.stopped) return;
29319
29351
  await renderExistingTasks(this.state);
29320
- if (this.shouldShowOnboarding()) await this.showOnboarding();
29352
+ if (this.stopped) return;
29353
+ if (this.stopped) return;
29354
+ if (this.state.pluginManager && !this.cleanupPluginErrorListener) this.cleanupPluginErrorListener = this.state.pluginManager.onPluginError((event) => {
29355
+ showError(this.state, event.message);
29356
+ });
29357
+ if (this.shouldShowOnboarding()) {
29358
+ await this.showOnboarding();
29359
+ if (this.stopped) return;
29360
+ }
29321
29361
  if (startupResumeIssue?.kind === "missing") showError(this.state, `Thread not found: ${startupResumeIssue.threadId}. Started a new thread; use /threads to pick an existing one.`);
29322
29362
  else if (startupResumeIssue?.kind === "locked") showThreadLockPrompt(this.buildCommandContext(), startupResumeIssue.title, startupResumeIssue.ownerPid, startupResumeIssue.threadId);
29323
29363
  this.checkForUpdate().catch(() => {});
@@ -29758,6 +29798,7 @@ var MastraTUI = class MastraTUI {
29758
29798
  }
29759
29799
  const authMode = await promptAuthMode(this.state.ui, providerName, provider?.authModes);
29760
29800
  if (authMode === null) return;
29801
+ if (this.stopped) return;
29761
29802
  return new Promise((resolve) => {
29762
29803
  const dialog = new LoginDialogComponent(this.state.ui, providerId, (success, message) => {
29763
29804
  this.state.ui.hideOverlay();
@@ -29785,6 +29826,10 @@ var MastraTUI = class MastraTUI {
29785
29826
  }).then(async () => {
29786
29827
  this.state.ui.hideOverlay();
29787
29828
  const { PROVIDER_DEFAULT_MODELS } = await import("@mastra/code-sdk/auth/storage");
29829
+ if (this.stopped) {
29830
+ resolve();
29831
+ return;
29832
+ }
29788
29833
  const defaultModel = PROVIDER_DEFAULT_MODELS[providerId];
29789
29834
  if (defaultModel) {
29790
29835
  await this.state.session.model.switch(defaultModel);
@@ -29805,6 +29850,7 @@ var MastraTUI = class MastraTUI {
29805
29850
  loggedIn: this.state.authStorage?.isLoggedIn(p.id) ?? false
29806
29851
  }));
29807
29852
  const access = await this.buildProviderAccess();
29853
+ if (this.stopped) return;
29808
29854
  const hasProviderAccess = Object.values(access).some(Boolean);
29809
29855
  const savedSettings = (0, _mastra_code_sdk_onboarding_index.loadSettings)();
29810
29856
  const modePacks = (0, _mastra_code_sdk_onboarding_index.getAvailableModePacks)(access, savedSettings.customModelPacks);
@@ -29841,6 +29887,7 @@ var MastraTUI = class MastraTUI {
29841
29887
  onLogin: (providerId, done) => {
29842
29888
  this.performLogin(providerId).then(async () => {
29843
29889
  try {
29890
+ if (this.stopped) return;
29844
29891
  const updatedAccess = await this.buildProviderAccess();
29845
29892
  const updatedHasAccess = Object.values(updatedAccess).some(Boolean);
29846
29893
  component.updateModePacks((0, _mastra_code_sdk_onboarding_index.getAvailableModePacks)(updatedAccess, savedSettings.customModelPacks));
@@ -29854,7 +29901,7 @@ var MastraTUI = class MastraTUI {
29854
29901
  },
29855
29902
  onSelectModel: async (title, modeColor) => {
29856
29903
  const availableModels = await this.state.controller.listAvailableModels();
29857
- if (availableModels.length === 0) return void 0;
29904
+ if (this.stopped || availableModels.length === 0) return void 0;
29858
29905
  return new Promise((resolveModel) => {
29859
29906
  const selector = new ModelSelectorComponent({
29860
29907
  tui: this.state.ui,
@@ -29891,6 +29938,7 @@ var MastraTUI = class MastraTUI {
29891
29938
  const modePack = result.modePack;
29892
29939
  const modes = this.state.controller.listModes();
29893
29940
  await this.state.session.state.set({ yolo: result.yolo });
29941
+ if (this.stopped) return;
29894
29942
  const settings = (0, _mastra_code_sdk_onboarding_index.loadSettings)();
29895
29943
  settings.onboarding.completedAt = (/* @__PURE__ */ new Date()).toISOString();
29896
29944
  settings.onboarding.skippedAt = null;
@@ -29923,10 +29971,12 @@ var MastraTUI = class MastraTUI {
29923
29971
  settings.models.subagentModels = {};
29924
29972
  (0, _mastra_code_sdk_onboarding_index.saveSettings)(settings);
29925
29973
  await applyCurrentThreadPack({ state: this.state }, { packId: activeModePackId });
29974
+ if (this.stopped) return;
29926
29975
  await this.state.session.thread.setSetting({
29927
29976
  key: _mastra_code_sdk_onboarding_settings.THREAD_FALLBACK_STATUS_KEY,
29928
29977
  value: void 0
29929
29978
  });
29979
+ if (this.stopped) return;
29930
29980
  this.state.fallbackStatus = void 0;
29931
29981
  updateStatusLine(this.state);
29932
29982
  await this.refreshModelAuthStatus();
@@ -30161,4 +30211,4 @@ Object.defineProperty(exports, "theme", {
30161
30211
  }
30162
30212
  });
30163
30213
 
30164
- //# sourceMappingURL=tui-edzCSg8-.cjs.map
30214
+ //# sourceMappingURL=tui-BfBjFTxw.cjs.map