mastracode 0.9.2-alpha.1 → 0.9.2-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,20 @@
1
1
  # mastracode
2
2
 
3
+ ## 0.9.2-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Added macOS sleep prevention while Mastra Code is actively running. ([#14586](https://github.com/mastra-ai/mastra/pull/14586))
8
+
9
+ Mastra Code now starts the built-in caffeinate utility only while an agent run is in progress, then releases it after completion, aborts, errors, or app shutdown.
10
+
11
+ To opt out, set MASTRACODE_DISABLE_CAFFEINATE=1 before launching Mastra Code.
12
+
13
+ - Updated dependencies [[`7dbd611`](https://github.com/mastra-ai/mastra/commit/7dbd611a85cb1e0c0a1581c57564268cb183d86e), [`41aee84`](https://github.com/mastra-ai/mastra/commit/41aee84561ceebe28bad1ecba8702d92838f67f0)]:
14
+ - @mastra/core@1.16.0-alpha.1
15
+ - @mastra/libsql@1.7.2-alpha.1
16
+ - @mastra/pg@1.8.3-alpha.1
17
+
3
18
  ## 0.9.2-alpha.1
4
19
 
5
20
  ### Patch Changes
package/README.md CHANGED
@@ -162,6 +162,16 @@ Once saved, provider models appear in existing selectors like `/models` and `/su
162
162
 
163
163
  Custom providers are stored in `settings.json` in the same app data directory. If you save an API key, it is stored locally in plaintext, so use a machine/user profile you trust.
164
164
 
165
+ ### macOS sleep prevention
166
+
167
+ On macOS, Mastra Code starts the built-in `caffeinate` utility while the agent is actively running, then stops it as soon as the run completes, errors, aborts, or the TUI exits. Idle sessions do not keep your machine awake.
168
+
169
+ To disable this behavior, set `MASTRACODE_DISABLE_CAFFEINATE=1` before launching Mastra Code:
170
+
171
+ ```bash
172
+ export MASTRACODE_DISABLE_CAFFEINATE=1
173
+ ```
174
+
165
175
  ### Plan persistence
166
176
 
167
177
  When you approve a plan (via `submit_plan`), it is saved as a markdown file in the app data directory:
@@ -1,9 +1,9 @@
1
1
  import { theme, mastra, getMarkdownTheme, CHAT_INDENT, BOX_INDENT, getTermWidth, TERM_WIDTH_BUFFER, getEditorTheme, loadSettings, getAvailableModePacks, resolveThreadActiveModelPackId, saveSettings, getAvailableOmPacks, ONBOARDING_VERSION, THREAD_ACTIVE_MODEL_PACK_ID_KEY, tintHex, BOX_INDENT_STR, ThreadLockError, getSelectListTheme, luminance, ensureContrast, getThemeMode, applyThemeMode, getCustomProviderId, getSettingsListTheme, toCustomProviderModelId } from './chunk-UUS7G74S.js';
2
2
  import { getOAuthProviders, detectProject, getUserId, getCurrentGitBranch, getAppDataDir, PROVIDER_DEFAULT_MODELS } from './chunk-GTRZ4DPO.js';
3
3
  import { MC_TOOLS, getToolCategory, TOOL_CATEGORIES } from './chunk-MS5RYNRK.js';
4
+ import { exec, spawn, execFile, execSync, execFileSync } from 'child_process';
4
5
  import { Box, Text, Spacer, Input, Container, fuzzyFilter, getEditorKeybindings, Markdown, ProcessTerminal, TUI, visibleWidth, Editor, matchesKey, CombinedAutocompleteProvider, SelectList, wrapTextWithAnsi, SettingsList, isKeyRelease } from '@mariozechner/pi-tui';
5
6
  import chalk7 from 'chalk';
6
- import { exec, execFile, execSync, execFileSync } from 'child_process';
7
7
  import fs2, { statSync, readFileSync, realpathSync, promises, unlinkSync } from 'fs';
8
8
  import * as path5 from 'path';
9
9
  import path5__default, { extname, join } from 'path';
@@ -899,7 +899,7 @@ function getInstallCommand(pm, version) {
899
899
  }
900
900
  function getCurrentVersion() {
901
901
  {
902
- return "0.9.2-alpha.1";
902
+ return "0.9.2-alpha.2";
903
903
  }
904
904
  }
905
905
  async function fetchLatestVersion() {
@@ -11405,6 +11405,10 @@ function createTUIState(options) {
11405
11405
  // src/tui/mastra-tui.ts
11406
11406
  var UPDATE_RECHECK_INTERVAL_MS = 45 * 60 * 1e3;
11407
11407
  var IMAGE_PLACEHOLDER_PATTERN = /\[image\]\s*/g;
11408
+ var CAFFEINATE_ARGS = ["-i", "-m"];
11409
+ function shouldUseCaffeinate() {
11410
+ return process.platform === "darwin" && process.env.MASTRACODE_DISABLE_CAFFEINATE !== "1";
11411
+ }
11408
11412
  function consumePendingImages(text, pendingImages) {
11409
11413
  const imageMarkerCount = text.match(/\[image\]/g)?.length ?? 0;
11410
11414
  const images = imageMarkerCount > 0 ? pendingImages.slice(0, imageMarkerCount) : void 0;
@@ -11417,6 +11421,7 @@ var MastraTUI = class _MastraTUI {
11417
11421
  state;
11418
11422
  updateCheckTimer = null;
11419
11423
  hasShownUpdateBanner = false;
11424
+ caffeinateProcess = null;
11420
11425
  static DOUBLE_CTRL_C_MS = 500;
11421
11426
  constructor(options) {
11422
11427
  this.state = createTUIState(options);
@@ -11542,6 +11547,7 @@ var MastraTUI = class _MastraTUI {
11542
11547
  * Stop the TUI and clean up.
11543
11548
  */
11544
11549
  stop() {
11550
+ this.stopCaffeinate();
11545
11551
  const hookMgr = this.state.hookManager;
11546
11552
  if (hookMgr) {
11547
11553
  hookMgr.runSessionEnd().catch(() => {
@@ -11634,16 +11640,56 @@ var MastraTUI = class _MastraTUI {
11634
11640
  return this._ectx;
11635
11641
  }
11636
11642
  async handleEvent(event) {
11637
- await dispatchEvent(event, this.getEventContext(), this.state);
11638
- if (event.type === "thread_created") {
11639
- await this.syncThreadActivePackMetadata(event.thread);
11640
- } else if (event.type === "thread_changed") {
11641
- await this.syncThreadActivePackMetadata();
11643
+ if (event.type === "agent_start") {
11644
+ this.startCaffeinate();
11645
+ }
11646
+ try {
11647
+ await dispatchEvent(event, this.getEventContext(), this.state);
11648
+ if (event.type === "thread_created") {
11649
+ await this.syncThreadActivePackMetadata(event.thread);
11650
+ } else if (event.type === "thread_changed") {
11651
+ await this.syncThreadActivePackMetadata();
11652
+ }
11653
+ if (event.type === "agent_end") {
11654
+ const stopReason = event.reason === "aborted" ? "aborted" : event.reason === "error" ? "error" : "complete";
11655
+ await this.runStopHook(stopReason);
11656
+ }
11657
+ } finally {
11658
+ if (event.type === "agent_end") {
11659
+ this.stopCaffeinate();
11660
+ }
11661
+ }
11662
+ }
11663
+ startCaffeinate() {
11664
+ if (!shouldUseCaffeinate() || this.caffeinateProcess) {
11665
+ return;
11642
11666
  }
11643
- if (event.type === "agent_end") {
11644
- const stopReason = event.reason === "aborted" ? "aborted" : event.reason === "error" ? "error" : "complete";
11645
- await this.runStopHook(stopReason);
11667
+ try {
11668
+ const child = spawn("caffeinate", CAFFEINATE_ARGS, {
11669
+ stdio: "ignore"
11670
+ });
11671
+ child.once("error", () => {
11672
+ if (this.caffeinateProcess === child) {
11673
+ this.caffeinateProcess = null;
11674
+ }
11675
+ });
11676
+ child.once("exit", () => {
11677
+ if (this.caffeinateProcess === child) {
11678
+ this.caffeinateProcess = null;
11679
+ }
11680
+ });
11681
+ this.caffeinateProcess = child;
11682
+ } catch {
11683
+ this.caffeinateProcess = null;
11684
+ }
11685
+ }
11686
+ stopCaffeinate() {
11687
+ const child = this.caffeinateProcess;
11688
+ if (!child) {
11689
+ return;
11646
11690
  }
11691
+ this.caffeinateProcess = null;
11692
+ child.kill();
11647
11693
  }
11648
11694
  async buildProviderAccess() {
11649
11695
  const models = await this.state.harness.listAvailableModels();
@@ -12229,5 +12275,5 @@ var LoginSelectorComponent = class extends Box {
12229
12275
  };
12230
12276
 
12231
12277
  export { AssistantMessageComponent, LoginDialogComponent, LoginSelectorComponent, MastraTUI, ModelSelectorComponent, OMProgressComponent, ToolExecutionComponentEnhanced, UserMessageComponent, createTUIState, detectTerminalTheme, formatOMStatus, getCurrentVersion };
12232
- //# sourceMappingURL=chunk-JH7EJYP7.js.map
12233
- //# sourceMappingURL=chunk-JH7EJYP7.js.map
12278
+ //# sourceMappingURL=chunk-REEH5DEO.js.map
12279
+ //# sourceMappingURL=chunk-REEH5DEO.js.map