mastracode 0.32.3-alpha.0 → 0.32.3-alpha.2

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,33 @@
1
1
  # mastracode
2
2
 
3
+ ## 0.32.3-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed observational memory staying on the Gemini default after you sign in to Anthropic or OpenAI. First-run setup and `/login` now select the small, cheap OM model of the provider you just connected, and the TUI tells you when it does. An OM model you picked yourself is never replaced. ([#20291](https://github.com/mastra-ai/mastra/pull/20291))
8
+
9
+ Providers with no cheap OM model (GitHub Copilot, xAI) no longer pin observation and reflection to their full-size coding model — OM stays open so a later login can set it.
10
+
11
+ When an OM run fails, the hint names the model OM is using and keeps the advice for the actual failure, so an authentication error still points at `/login` and a rate limit still tells you to wait, alongside `/memory` to switch OM models.
12
+
13
+ - Updated dependencies [[`a211d09`](https://github.com/mastra-ai/mastra/commit/a211d09185dc65a746534914cf38b67f21ee9bac), [`f014c26`](https://github.com/mastra-ai/mastra/commit/f014c26f3445118b684e286ee5819b46dfa943a0), [`05db566`](https://github.com/mastra-ai/mastra/commit/05db566fcbdcbf33d0bffca0c72ec30129e2e3ca), [`05db566`](https://github.com/mastra-ai/mastra/commit/05db566fcbdcbf33d0bffca0c72ec30129e2e3ca), [`8dadb6a`](https://github.com/mastra-ai/mastra/commit/8dadb6abfe449b7f8b129663671cc614f2cceeef), [`e075db9`](https://github.com/mastra-ai/mastra/commit/e075db9715c836bae5dfc37c50248492af397c3b), [`8124754`](https://github.com/mastra-ai/mastra/commit/8124754ae89fbc69f8136d1df4a91904d0f84c4e)]:
14
+ - @mastra/core@1.54.0-alpha.2
15
+ - @mastra/code-sdk@1.1.0-alpha.2
16
+ - @mastra/pg@1.18.0-alpha.2
17
+ - @mastra/libsql@1.18.0-alpha.1
18
+
19
+ ## 0.32.3-alpha.1
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [[`ce93a3c`](https://github.com/mastra-ai/mastra/commit/ce93a3c114ea1cbfbd576f3db41d7c26c9844f5b), [`5718a22`](https://github.com/mastra-ai/mastra/commit/5718a229281dcfd36bcd1f42a242e3717e510a33), [`5807d3a`](https://github.com/mastra-ai/mastra/commit/5807d3ae1d259b8b7d6df7e5bf2b485c694af9c8), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`273bb71`](https://github.com/mastra-ai/mastra/commit/273bb71e82e74b656f3906288239429899398c0c), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`5718a22`](https://github.com/mastra-ai/mastra/commit/5718a229281dcfd36bcd1f42a242e3717e510a33), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`d1b7e3a`](https://github.com/mastra-ai/mastra/commit/d1b7e3a978a309a5653eeaa490d2d6c7c53bd093), [`c093146`](https://github.com/mastra-ai/mastra/commit/c0931466404d3c521308ea119cb165bb7e695155), [`d1b7e3a`](https://github.com/mastra-ai/mastra/commit/d1b7e3a978a309a5653eeaa490d2d6c7c53bd093)]:
24
+ - @mastra/core@1.54.0-alpha.1
25
+ - @mastra/pg@1.18.0-alpha.1
26
+ - @mastra/duckdb@1.5.2-alpha.0
27
+ - @mastra/observability@1.16.3-alpha.0
28
+ - @mastra/code-sdk@1.0.3-alpha.1
29
+ - @mastra/mcp@1.15.0
30
+
3
31
  ## 0.32.3-alpha.0
4
32
 
5
33
  ### Patch Changes
package/dist/acp.cjs CHANGED
@@ -1,14 +1,9 @@
1
- 'use strict';
2
-
3
- var acp = require('@mastra/code-sdk/acp');
4
-
5
-
6
-
7
- Object.keys(acp).forEach(function (k) {
8
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1
+ var _mastra_code_sdk_acp = require("@mastra/code-sdk/acp");
2
+ Object.keys(_mastra_code_sdk_acp).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
9
4
  enumerable: true,
10
- get: function () { return acp[k]; }
5
+ get: function() {
6
+ return _mastra_code_sdk_acp[k];
7
+ }
11
8
  });
12
9
  });
13
- //# sourceMappingURL=acp.cjs.map
14
- //# sourceMappingURL=acp.cjs.map
package/dist/acp.js CHANGED
@@ -1,3 +1,2 @@
1
- export * from '@mastra/code-sdk/acp';
2
- //# sourceMappingURL=acp.js.map
3
- //# sourceMappingURL=acp.js.map
1
+ export * from "@mastra/code-sdk/acp";
2
+ export {};
package/dist/cli.cjs CHANGED
@@ -1,275 +1,235 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var chunkLDCL2KGF_cjs = require('./chunk-LDCL2KGF.cjs');
5
- var fs = require('fs');
6
- var codeSdk = require('@mastra/code-sdk');
7
- var analytics$1 = require('@mastra/code-sdk/analytics');
8
- var errorClassification = require('@mastra/code-sdk/error-classification');
9
- var index = require('@mastra/code-sdk/headless/index');
10
- var settings = require('@mastra/code-sdk/onboarding/settings');
11
- var scaffold = require('@mastra/code-sdk/plugins/scaffold');
12
- var debugLog = require('@mastra/code-sdk/utils/debug-log');
13
- var stdinPipe = require('@mastra/code-sdk/utils/stdin-pipe');
14
- var threadLock = require('@mastra/code-sdk/utils/thread-lock');
15
-
16
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
-
18
- var fs__default = /*#__PURE__*/_interopDefault(fs);
19
-
2
+ const require_tui = require("./tui-G-b6reo7.cjs");
3
+ let _mastra_code_sdk = require("@mastra/code-sdk");
4
+ let fs = require("fs");
5
+ fs = require_tui.__toESM(fs, 1);
6
+ let _mastra_code_sdk_analytics = require("@mastra/code-sdk/analytics");
7
+ let _mastra_code_sdk_error_classification = require("@mastra/code-sdk/error-classification");
8
+ let _mastra_code_sdk_headless_index = require("@mastra/code-sdk/headless/index");
9
+ let _mastra_code_sdk_onboarding_settings = require("@mastra/code-sdk/onboarding/settings");
10
+ let _mastra_code_sdk_plugins_scaffold = require("@mastra/code-sdk/plugins/scaffold");
11
+ let _mastra_code_sdk_utils_debug_log = require("@mastra/code-sdk/utils/debug-log");
12
+ let _mastra_code_sdk_utils_stdin_pipe = require("@mastra/code-sdk/utils/stdin-pipe");
13
+ let _mastra_code_sdk_utils_thread_lock = require("@mastra/code-sdk/utils/thread-lock");
14
+ //#region src/version.ts
20
15
  function getCurrentVersion() {
21
- {
22
- return "0.32.3-alpha.0";
23
- }
16
+ return "0.32.3-alpha.2";
24
17
  }
25
-
26
- // src/main.ts
27
- var controller;
28
- var mcpManager;
29
- var hookManager;
30
- var authStorage;
31
- var signalsPubSub;
32
- var storageMaintenance;
33
- var analytics;
34
- var tui;
35
- var storageClosed = false;
18
+ //#endregion
19
+ //#region src/main.ts
20
+ /**
21
+ * Main entry point for Mastra Code TUI.
22
+ */
23
+ let controller;
24
+ let mcpManager;
25
+ let hookManager;
26
+ let authStorage;
27
+ let signalsPubSub;
28
+ let storageMaintenance;
29
+ let analytics;
30
+ let tui;
31
+ let storageClosed = false;
36
32
  function isTruthyEnv(name) {
37
- return ["1", "true", "yes", "on"].includes(process.env[name]?.trim().toLowerCase() ?? "");
33
+ return [
34
+ "1",
35
+ "true",
36
+ "yes",
37
+ "on"
38
+ ].includes(process.env[name]?.trim().toLowerCase() ?? "");
38
39
  }
39
40
  function resolveInitialStateFromEnv() {
40
- const currentModelId = process.env.MASTRACODE_MODEL_ID?.trim();
41
- const initialState = {};
42
- if (currentModelId) initialState.currentModelId = currentModelId;
43
- if (isTruthyEnv("MASTRACODE_YOLO")) initialState.yolo = true;
44
- return Object.keys(initialState).length > 0 ? initialState : void 0;
41
+ const currentModelId = process.env.MASTRACODE_MODEL_ID?.trim();
42
+ const initialState = {};
43
+ if (currentModelId) initialState.currentModelId = currentModelId;
44
+ if (isTruthyEnv("MASTRACODE_YOLO")) initialState.yolo = true;
45
+ return Object.keys(initialState).length > 0 ? initialState : void 0;
45
46
  }
46
47
  process.on("uncaughtException", (error) => {
47
- if (errorClassification.isStreamDestroyedError(error)) return;
48
- handleFatalError(error);
48
+ if ((0, _mastra_code_sdk_error_classification.isStreamDestroyedError)(error)) return;
49
+ handleFatalError(error);
49
50
  });
50
51
  process.on("unhandledRejection", (reason) => {
51
- if (errorClassification.isStreamDestroyedError(reason)) return;
52
- handleFatalError(reason instanceof Error ? reason : new Error(String(reason)));
52
+ if ((0, _mastra_code_sdk_error_classification.isStreamDestroyedError)(reason)) return;
53
+ handleFatalError(reason instanceof Error ? reason : new Error(String(reason)));
53
54
  });
54
55
  async function tuiMain(pipedInput) {
55
- const settings$1 = settings.loadSettings();
56
- let browserPromise;
57
- const loadBrowser = () => {
58
- browserPromise ??= settings.createBrowserFromSettings(settings$1.browser);
59
- return browserPromise;
60
- };
61
- const initialState = resolveInitialStateFromEnv();
62
- const result = await codeSdk.createMastraCode({
63
- unixSocketPubSub: !isTruthyEnv("MASTRACODE_DISABLE_UNIX_SOCKET_PUBSUB"),
64
- disableMcp: isTruthyEnv("MASTRACODE_DISABLE_MCP"),
65
- disableHooks: isTruthyEnv("MASTRACODE_DISABLE_HOOKS"),
66
- ...isTruthyEnv("MASTRACODE_DISABLE_MEMORY") ? { memory: false } : {},
67
- ...initialState ? { initialState } : {}
68
- });
69
- controller = result.controller;
70
- mcpManager = result.mcpManager;
71
- hookManager = result.hookManager;
72
- authStorage = result.authStorage;
73
- signalsPubSub = result.signalsPubSub;
74
- storageMaintenance = result.storageMaintenance;
75
- if (result.storageWarning) {
76
- console.info(`\u26A0 ${result.storageWarning}`);
77
- }
78
- if (result.observabilityWarning) {
79
- console.info(`\u26A0 ${result.observabilityWarning}`);
80
- }
81
- debugLog.setupDebugLogging();
82
- const envTheme = process.env.MASTRA_THEME?.toLowerCase();
83
- let themeMode;
84
- let detectedBgHex;
85
- if (envTheme === "dark" || envTheme === "light") {
86
- themeMode = envTheme;
87
- } else {
88
- const settings2 = settings.loadSettings();
89
- const themePref = settings2.preferences.theme;
90
- if (themePref === "dark" || themePref === "light") {
91
- themeMode = themePref;
92
- } else {
93
- const detection = await chunkLDCL2KGF_cjs.detectTerminalTheme();
94
- themeMode = detection.mode;
95
- detectedBgHex = detection.detectedBgHex;
96
- }
97
- }
98
- chunkLDCL2KGF_cjs.applyThemeMode(themeMode, detectedBgHex);
99
- const session = result.session;
100
- analytics = analytics$1.createMastraCodeAnalytics({ version: getCurrentVersion() });
101
- analytics.capture("mastracode_session_started", {
102
- mode: session.mode.get(),
103
- resourceId: session.identity.getResourceId(),
104
- hasAuthStorage: Boolean(authStorage),
105
- hasMcp: Boolean(mcpManager),
106
- theme: themeMode
107
- });
108
- tui = new chunkLDCL2KGF_cjs.MastraTUI({
109
- controller,
110
- session,
111
- hookManager,
112
- analytics,
113
- authStorage,
114
- mcpManager,
115
- pluginManager: result.pluginManager,
116
- storageMaintenance: result.storageMaintenance,
117
- appName: "Mastra Code",
118
- version: getCurrentVersion(),
119
- inlineQuestions: true,
120
- githubSignals: result.githubSignals,
121
- ...pipedInput ? { initialMessage: `The following was piped via stdin:
122
-
123
- ${pipedInput}` } : {}
124
- });
125
- tui.run().catch((error) => {
126
- handleFatalError(error);
127
- });
128
- if (settings$1.browser.enabled) {
129
- void loadBrowser().then((browser) => {
130
- if (!browser) return;
131
- controller.setBrowser(browser);
132
- void session.state.set({ activeBrowserSettings: settings$1.browser }).catch(() => {
133
- });
134
- }).catch(() => {
135
- });
136
- }
56
+ const settings = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
57
+ let browserPromise;
58
+ const loadBrowser = () => {
59
+ browserPromise ??= (0, _mastra_code_sdk_onboarding_settings.createBrowserFromSettings)(settings.browser);
60
+ return browserPromise;
61
+ };
62
+ const initialState = resolveInitialStateFromEnv();
63
+ const result = await (0, _mastra_code_sdk.createMastraCode)({
64
+ unixSocketPubSub: !isTruthyEnv("MASTRACODE_DISABLE_UNIX_SOCKET_PUBSUB"),
65
+ disableMcp: isTruthyEnv("MASTRACODE_DISABLE_MCP"),
66
+ disableHooks: isTruthyEnv("MASTRACODE_DISABLE_HOOKS"),
67
+ ...isTruthyEnv("MASTRACODE_DISABLE_MEMORY") ? { memory: false } : {},
68
+ ...initialState ? { initialState } : {}
69
+ });
70
+ controller = result.controller;
71
+ mcpManager = result.mcpManager;
72
+ hookManager = result.hookManager;
73
+ authStorage = result.authStorage;
74
+ signalsPubSub = result.signalsPubSub;
75
+ storageMaintenance = result.storageMaintenance;
76
+ if (result.storageWarning) console.info(`⚠ ${result.storageWarning}`);
77
+ if (result.observabilityWarning) console.info(`⚠ ${result.observabilityWarning}`);
78
+ (0, _mastra_code_sdk_utils_debug_log.setupDebugLogging)();
79
+ const envTheme = process.env.MASTRA_THEME?.toLowerCase();
80
+ let themeMode;
81
+ let detectedBgHex;
82
+ if (envTheme === "dark" || envTheme === "light") themeMode = envTheme;
83
+ else {
84
+ const themePref = (0, _mastra_code_sdk_onboarding_settings.loadSettings)().preferences.theme;
85
+ if (themePref === "dark" || themePref === "light") themeMode = themePref;
86
+ else {
87
+ const detection = await require_tui.detectTerminalTheme();
88
+ themeMode = detection.mode;
89
+ detectedBgHex = detection.detectedBgHex;
90
+ }
91
+ }
92
+ require_tui.applyThemeMode(themeMode, detectedBgHex);
93
+ const session = result.session;
94
+ analytics = (0, _mastra_code_sdk_analytics.createMastraCodeAnalytics)({ version: getCurrentVersion() });
95
+ analytics.capture("mastracode_session_started", {
96
+ mode: session.mode.get(),
97
+ resourceId: session.identity.getResourceId(),
98
+ hasAuthStorage: Boolean(authStorage),
99
+ hasMcp: Boolean(mcpManager),
100
+ theme: themeMode
101
+ });
102
+ tui = new require_tui.MastraTUI({
103
+ controller,
104
+ session,
105
+ hookManager,
106
+ analytics,
107
+ authStorage,
108
+ mcpManager,
109
+ pluginManager: result.pluginManager,
110
+ storageMaintenance: result.storageMaintenance,
111
+ appName: "Mastra Code",
112
+ version: getCurrentVersion(),
113
+ inlineQuestions: true,
114
+ githubSignals: result.githubSignals,
115
+ ...pipedInput ? { initialMessage: `The following was piped via stdin:\n\n${pipedInput}` } : {}
116
+ });
117
+ tui.run().catch((error) => {
118
+ handleFatalError(error);
119
+ });
120
+ if (settings.browser.enabled) loadBrowser().then((browser) => {
121
+ if (!browser) return;
122
+ controller.setBrowser(browser);
123
+ session.state.set({ activeBrowserSettings: settings.browser }).catch(() => {});
124
+ }).catch(() => {});
137
125
  }
138
- var asyncCleanup = async () => {
139
- threadLock.releaseAllThreadLocks();
140
- const closeSignalsPubSub = signalsPubSub?.close;
141
- await Promise.allSettled([
142
- mcpManager?.disconnect(),
143
- controller?.getMastra()?.stopWorkers(),
144
- controller?.stopIntervals(),
145
- closeSignalsPubSub?.(),
146
- analytics?.shutdown()
147
- ]);
148
- if (!storageClosed) {
149
- storageClosed = true;
150
- await storageMaintenance?.closeStorage?.().catch(() => {
151
- });
152
- }
126
+ const asyncCleanup = async () => {
127
+ (0, _mastra_code_sdk_utils_thread_lock.releaseAllThreadLocks)();
128
+ const closeSignalsPubSub = signalsPubSub?.close;
129
+ await Promise.allSettled([
130
+ mcpManager?.disconnect(),
131
+ controller?.getMastra()?.stopWorkers(),
132
+ controller?.stopIntervals(),
133
+ closeSignalsPubSub?.(),
134
+ analytics?.shutdown()
135
+ ]);
136
+ if (!storageClosed) {
137
+ storageClosed = true;
138
+ await storageMaintenance?.closeStorage?.().catch(() => {});
139
+ }
153
140
  };
154
141
  process.on("beforeExit", () => {
155
- void asyncCleanup();
142
+ asyncCleanup();
156
143
  });
157
144
  process.on("exit", () => {
158
- try {
159
- tui?.stop();
160
- } catch {
161
- }
162
- try {
163
- process.stdout.write(
164
- "\x1B[?2004l\x1B[<u\x1B[>4;0m\x1B[?25h"
165
- // show cursor
166
- );
167
- if (process.stdin.setRawMode) {
168
- process.stdin.setRawMode(false);
169
- }
170
- } catch {
171
- }
172
- chunkLDCL2KGF_cjs.restoreTerminalForeground();
173
- threadLock.releaseAllThreadLocks();
145
+ try {
146
+ tui?.stop();
147
+ } catch {}
148
+ try {
149
+ process.stdout.write("\x1B[?2004l\x1B[<u\x1B[>4;0m\x1B[?25h");
150
+ if (process.stdin.setRawMode) process.stdin.setRawMode(false);
151
+ } catch {}
152
+ require_tui.restoreTerminalForeground();
153
+ (0, _mastra_code_sdk_utils_thread_lock.releaseAllThreadLocks)();
174
154
  });
175
- var handleTermSignal = () => {
176
- try {
177
- tui?.stop();
178
- } catch {
179
- }
180
- void asyncCleanup().finally(() => process.exit(0));
155
+ const handleTermSignal = () => {
156
+ try {
157
+ tui?.stop();
158
+ } catch {}
159
+ asyncCleanup().finally(() => process.exit(0));
181
160
  };
182
161
  process.on("SIGINT", handleTermSignal);
183
162
  process.on("SIGTERM", handleTermSignal);
184
163
  process.on("SIGHUP", handleTermSignal);
185
164
  function hasEconnrefused(err, depth = 0) {
186
- if (!err || depth > 5) return false;
187
- const e = err;
188
- if (e.code === "ECONNREFUSED") return true;
189
- if (e.cause) return hasEconnrefused(e.cause, depth + 1);
190
- if (Array.isArray(e.errors)) return e.errors.some((inner) => hasEconnrefused(inner, depth + 1));
191
- return false;
165
+ if (!err || depth > 5) return false;
166
+ const e = err;
167
+ if (e.code === "ECONNREFUSED") return true;
168
+ if (e.cause) return hasEconnrefused(e.cause, depth + 1);
169
+ if (Array.isArray(e.errors)) return e.errors.some((inner) => hasEconnrefused(inner, depth + 1));
170
+ return false;
192
171
  }
193
172
  function pluginMain(args) {
194
- if (args[0] !== "scaffold") {
195
- process.stderr.write('Usage: mastracode plugin scaffold <dir> [--id acme.foo] [--name "Foo Tools"]\n');
196
- process.exit(1);
197
- }
198
- const dir = args[1];
199
- if (!dir) {
200
- process.stderr.write('Usage: mastracode plugin scaffold <dir> [--id acme.foo] [--name "Foo Tools"]\n');
201
- process.exit(1);
202
- }
203
- const id = readFlag(args, "--id");
204
- const name = readFlag(args, "--name");
205
- const targetDir = scaffold.scaffoldPlugin(dir, { ...id ? { id } : {}, ...name ? { name } : {} });
206
- process.stdout.write(`${scaffold.formatScaffoldSuccess(targetDir)}
207
- `);
173
+ if (args[0] !== "scaffold") {
174
+ process.stderr.write("Usage: mastracode plugin scaffold <dir> [--id acme.foo] [--name \"Foo Tools\"]\n");
175
+ process.exit(1);
176
+ }
177
+ const dir = args[1];
178
+ if (!dir) {
179
+ process.stderr.write("Usage: mastracode plugin scaffold <dir> [--id acme.foo] [--name \"Foo Tools\"]\n");
180
+ process.exit(1);
181
+ }
182
+ const id = readFlag(args, "--id");
183
+ const name = readFlag(args, "--name");
184
+ const targetDir = (0, _mastra_code_sdk_plugins_scaffold.scaffoldPlugin)(dir, {
185
+ ...id ? { id } : {},
186
+ ...name ? { name } : {}
187
+ });
188
+ process.stdout.write(`${(0, _mastra_code_sdk_plugins_scaffold.formatScaffoldSuccess)(targetDir)}\n`);
208
189
  }
209
190
  function readFlag(args, flag) {
210
- const index = args.indexOf(flag);
211
- if (index === -1) return void 0;
212
- const value = args[index + 1];
213
- if (!value || value.startsWith("--")) {
214
- throw new Error(`Missing value for ${flag}`);
215
- }
216
- return value;
191
+ const index = args.indexOf(flag);
192
+ if (index === -1) return void 0;
193
+ const value = args[index + 1];
194
+ if (!value || value.startsWith("--")) throw new Error(`Missing value for ${flag}`);
195
+ return value;
217
196
  }
218
197
  function handleFatalError(error) {
219
- const write = (msg2) => process.stderr.write(msg2 + "\n");
220
- if (hasEconnrefused(error)) {
221
- const settings$1 = settings.loadSettings();
222
- const connStr = settings$1.storage?.pg?.connectionString;
223
- const target = connStr ?? "localhost:5432";
224
- write(
225
- `
226
- Failed to connect to PostgreSQL at ${target}.
227
- Make sure the database is running and accessible.
228
-
229
- To switch back to LibSQL:
230
- Set MASTRA_STORAGE_BACKEND=libsql or change the backend in /settings
231
- `
232
- );
233
- process.exit(1);
234
- }
235
- const msg = `Fatal error: ${error instanceof Error ? error.message : String(error)}`;
236
- write(msg);
237
- try {
238
- const crashLog = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${msg}
239
- ${error instanceof Error && error.stack ? error.stack + "\n" : ""}`;
240
- fs__default.default.appendFileSync("/tmp/mastra-crash.log", crashLog);
241
- } catch {
242
- }
243
- if (error instanceof Error && error.stack) {
244
- write(error.stack);
245
- }
246
- process.exit(1);
198
+ const write = (msg) => process.stderr.write(msg + "\n");
199
+ if (hasEconnrefused(error)) {
200
+ write(`\nFailed to connect to PostgreSQL at ${(0, _mastra_code_sdk_onboarding_settings.loadSettings)().storage?.pg?.connectionString ?? "localhost:5432"}.\nMake sure the database is running and accessible.\n\nTo switch back to LibSQL:\n Set MASTRA_STORAGE_BACKEND=libsql or change the backend in /settings\n`);
201
+ process.exit(1);
202
+ }
203
+ const msg = `Fatal error: ${error instanceof Error ? error.message : String(error)}`;
204
+ write(msg);
205
+ try {
206
+ const crashLog = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${msg}\n${error instanceof Error && error.stack ? error.stack + "\n" : ""}`;
207
+ fs.default.appendFileSync("/tmp/mastra-crash.log", crashLog);
208
+ } catch {}
209
+ if (error instanceof Error && error.stack) write(error.stack);
210
+ process.exit(1);
247
211
  }
248
212
  async function main() {
249
- if (process.argv[2] === "plugin") {
250
- return pluginMain(process.argv.slice(3));
251
- }
252
- if (index.hasHeadlessFlag(process.argv) || process.argv.includes("--help") || process.argv.includes("-h")) {
253
- return index.runMCCli();
254
- }
255
- if (process.argv.includes("--acp")) {
256
- const { acpMain } = await import('@mastra/code-sdk/acp/index');
257
- return acpMain({ dangerousAutoApprove: process.argv.includes("--dangerous-auto-approve") });
258
- }
259
- let pipedInput = null;
260
- if (!process.stdin.isTTY) {
261
- process.stderr.write("Reading piped input...\n");
262
- pipedInput = await stdinPipe.drainPipedStdin();
263
- const reopenedStdin = stdinPipe.reopenStdinFromTTY();
264
- if (!reopenedStdin) {
265
- process.stderr.write("No TTY available \u2014 falling back to headless mode.\n");
266
- return index.runMCCli(pipedInput);
267
- }
268
- }
269
- return tuiMain(pipedInput);
213
+ if (process.argv[2] === "plugin") return pluginMain(process.argv.slice(3));
214
+ if ((0, _mastra_code_sdk_headless_index.hasHeadlessFlag)(process.argv) || process.argv.includes("--help") || process.argv.includes("-h")) return (0, _mastra_code_sdk_headless_index.runMCCli)();
215
+ if (process.argv.includes("--acp")) {
216
+ const { acpMain } = await import("@mastra/code-sdk/acp/index");
217
+ return acpMain({ dangerousAutoApprove: process.argv.includes("--dangerous-auto-approve") });
218
+ }
219
+ let pipedInput = null;
220
+ if (!process.stdin.isTTY) {
221
+ process.stderr.write("Reading piped input...\n");
222
+ pipedInput = await (0, _mastra_code_sdk_utils_stdin_pipe.drainPipedStdin)();
223
+ if (!(0, _mastra_code_sdk_utils_stdin_pipe.reopenStdinFromTTY)()) {
224
+ process.stderr.write("No TTY available — falling back to headless mode.\n");
225
+ return (0, _mastra_code_sdk_headless_index.runMCCli)(pipedInput);
226
+ }
227
+ }
228
+ return tuiMain(pipedInput);
270
229
  }
271
230
  main().catch((error) => {
272
- handleFatalError(error);
231
+ handleFatalError(error);
273
232
  });
274
- //# sourceMappingURL=cli.cjs.map
233
+ //#endregion
234
+
275
235
  //# sourceMappingURL=cli.cjs.map