mastracode 0.48.2 → 0.49.0-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.
@@ -3432,8 +3432,16 @@ async function sendGoalReminder(ctx, goal, options = {}) {
3432
3432
  }
3433
3433
  }
3434
3434
  // src/tui/utils/experimental-features.ts
3435
- function isSubconsciousEnabled() {
3436
- return process.env.MASTRACODE_EXPERIMENTAL_SUBCONSCIOUS === "1";
3435
+ const knowledgeEnabled = /* @__PURE__ */ new Map();
3436
+ /** The /settings Knowledge toggle, read once per settings file: it changes on restart. */
3437
+ function isKnowledgeEnabled() {
3438
+ const settingsPath = (0, _mastra_code_sdk_onboarding_settings.getSettingsPath)();
3439
+ let enabled = knowledgeEnabled.get(settingsPath);
3440
+ if (enabled === void 0) {
3441
+ enabled = (0, _mastra_code_sdk_onboarding_settings.loadSettings)().signals.experimentalKnowledge;
3442
+ knowledgeEnabled.set(settingsPath, enabled);
3443
+ }
3444
+ return enabled;
3437
3445
  }
3438
3446
  // src/tui/components/help-overlay.ts
3439
3447
  function getCommands(modes) {
@@ -3514,9 +3522,9 @@ function getCommands(modes) {
3514
3522
  key: "/memory",
3515
3523
  description: "Configure Observational Memory (/om alias)"
3516
3524
  },
3517
- ...isSubconsciousEnabled() ? [{
3525
+ ...isKnowledgeEnabled() ? [{
3518
3526
  key: "/knowledge",
3519
- description: "Browse scoped Subconscious knowledge"
3527
+ description: "Browse scoped knowledge"
3520
3528
  }] : [],
3521
3529
  {
3522
3530
  key: "/review",
@@ -7832,10 +7840,12 @@ var ScheduleFireComponent = class extends WidthAwareContainer {
7832
7840
  }
7833
7841
  };
7834
7842
  // src/tui/components/state-signal.ts
7843
+ /** Readable names for state ids whose wire value would mislead (Knowledge pins keep a legacy id). */
7844
+ const STATE_LABELS = { knowledge: "pinned context" };
7835
7845
  var StateSignalComponent = class extends _earendil_works_pi_tui.Container {
7836
7846
  constructor(options) {
7837
7847
  super();
7838
- const title = chalk.default.hex(mastra.blue).bold(`State ${options.mode}: ${options.stateId}`);
7848
+ const title = chalk.default.hex(mastra.blue).bold(`State ${options.mode}: ${STATE_LABELS[options.stateId] ?? options.stateId}`);
7839
7849
  this.addChild(new _earendil_works_pi_tui.Text(title, 0, 0));
7840
7850
  const message = options.message?.trim();
7841
7851
  if (message) {
@@ -8111,76 +8121,6 @@ function summarizeArgs(args, maxWidth = 40) {
8111
8121
  else if (typeof val === "object" && val !== null) parts.push(theme.fg("muted", "{...}"));
8112
8122
  return parts.join(" ");
8113
8123
  }
8114
- // src/tui/components/subconscious-activity.ts
8115
- const MAX_UPDATES = 100;
8116
- const MAX_HOT = 100;
8117
- const MAX_ERRORS = 100;
8118
- const DISPLAY_UPDATES = 4;
8119
- const DISPLAY_HOT = 4;
8120
- const DISPLAY_ERRORS = 3;
8121
- function object(value) {
8122
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
8123
- }
8124
- function string(value) {
8125
- return typeof value === "string" && value.length > 0;
8126
- }
8127
- function update(value) {
8128
- const item = object(value);
8129
- if (!item || !string(item.action) || !["node", "record"].includes(String(item.type)) || !string(item.createdAt) || item.name !== void 0 && typeof item.name !== "string") return;
8130
- return {
8131
- action: item.action,
8132
- type: item.type,
8133
- ...typeof item.name === "string" ? { name: item.name } : {},
8134
- createdAt: item.createdAt
8135
- };
8136
- }
8137
- function hotRecord(value) {
8138
- const item = object(value);
8139
- if (!item || item.type !== "node" || !string(item.name) || typeof item.updates !== "number" || !Number.isFinite(item.updates) || item.updates < 0) return;
8140
- return {
8141
- type: item.type,
8142
- name: item.name,
8143
- updates: item.updates
8144
- };
8145
- }
8146
- function parseSubconsciousActivitySnapshot(value) {
8147
- const snapshot = object(value);
8148
- if (!snapshot || !Array.isArray(snapshot.updates) || !Array.isArray(snapshot.hot)) return void 0;
8149
- if (snapshot.updates.length > MAX_UPDATES || snapshot.hot.length > MAX_HOT) return void 0;
8150
- if (snapshot.errors !== void 0 && (!Array.isArray(snapshot.errors) || snapshot.errors.length > MAX_ERRORS)) return;
8151
- const updates = snapshot.updates.map(update);
8152
- const hot = snapshot.hot.map(hotRecord);
8153
- const errors = snapshot.errors?.map((error) => typeof error === "string" ? error : void 0);
8154
- if (updates.some((item) => !item) || hot.some((item) => !item) || errors?.some((error) => error === void 0)) return;
8155
- return {
8156
- updates,
8157
- hot,
8158
- ...errors?.length ? { errors } : {}
8159
- };
8160
- }
8161
- var SubconsciousActivityComponent = class extends _earendil_works_pi_tui.Container {
8162
- constructor(snapshot) {
8163
- super();
8164
- const errorCount = snapshot.errors?.length ?? 0;
8165
- const summary = `${snapshot.updates.length} update${snapshot.updates.length === 1 ? "" : "s"} · ${snapshot.hot.length} hot${errorCount ? ` · ${errorCount} error${errorCount === 1 ? "" : "s"}` : ""}`;
8166
- this.addChild(new _earendil_works_pi_tui.Text(chalk.default.hex(mastra.blue).bold("Subconscious knowledge"), 0, 0));
8167
- this.addChild(new _earendil_works_pi_tui.Text(theme.fg("dim", summary), 2, 0));
8168
- for (const item of snapshot.updates.slice(0, DISPLAY_UPDATES)) {
8169
- const target = item.name ?? `${item.type} (details unavailable)`;
8170
- this.addChild(new _earendil_works_pi_tui.Text(`${item.action}: ${target}`, 2, 0));
8171
- }
8172
- if (snapshot.updates.length > DISPLAY_UPDATES) this.addChild(new _earendil_works_pi_tui.Text(theme.fg("muted", `+${snapshot.updates.length - DISPLAY_UPDATES} more updates`), 2, 0));
8173
- if (snapshot.hot.length) {
8174
- const names = snapshot.hot.slice(0, DISPLAY_HOT).map((item) => `${item.name} (${item.updates})`).join(", ");
8175
- this.addChild(new _earendil_works_pi_tui.Text(theme.fg("dim", `Hot: ${names}`), 2, 0));
8176
- }
8177
- for (const error of snapshot.errors?.slice(0, DISPLAY_ERRORS) ?? []) this.addChild(new _earendil_works_pi_tui.Text(theme.fg("error", `Error: ${error}`), 2, 0));
8178
- if (errorCount > DISPLAY_ERRORS) this.addChild(new _earendil_works_pi_tui.Text(theme.fg("muted", `+${errorCount - DISPLAY_ERRORS} more errors`), 2, 0));
8179
- }
8180
- getChatSpacingKind() {
8181
- return "system";
8182
- }
8183
- };
8184
8124
  // src/tui/components/system-reminder.ts
8185
8125
  /**
8186
8126
  * SystemReminderComponent - renders system-generated reminder messages
@@ -13964,8 +13904,7 @@ function renderSignalMessage(state, message) {
13964
13904
  if (kind === "state") {
13965
13905
  const stateSignal = getStateSignalView(message);
13966
13906
  if (stateSignal.stateId === _mastra_core_tools.TASKS_STATE_ID || stateSignal.stateId === GOAL_STATE_SIGNAL_ID) return true;
13967
- const subconsciousActivity = stateSignal.stateId === "subconscious-activity" ? parseSubconsciousActivitySnapshot(stateSignal.value) : void 0;
13968
- const component = subconsciousActivity ? new SubconsciousActivityComponent(subconsciousActivity) : new StateSignalComponent({
13907
+ const component = new StateSignalComponent({
13969
13908
  stateId: stateSignal.stateId,
13970
13909
  mode: stateSignal.mode,
13971
13910
  version: stateSignal.version,
@@ -18334,11 +18273,7 @@ const SECTIONS = [
18334
18273
  "nodes",
18335
18274
  "activity"
18336
18275
  ];
18337
- const NODE_SORTS = [
18338
- "relevant",
18339
- "recent",
18340
- "connected"
18341
- ];
18276
+ const NODE_SORTS = ["name", "connected"];
18342
18277
  const PAGE_SIZE = 12;
18343
18278
  const MAX_BODY_LINES = 10;
18344
18279
  const MIN_CONTENT_WIDTH = 20;
@@ -18411,7 +18346,7 @@ var KnowledgeBrowserComponent = class {
18411
18346
  activity = [];
18412
18347
  nextCursor;
18413
18348
  query = "";
18414
- nodeSort = "relevant";
18349
+ nodeSort = "name";
18415
18350
  nodeCoverage;
18416
18351
  selectedIndex = 0;
18417
18352
  detail;
@@ -18556,7 +18491,7 @@ var KnowledgeBrowserComponent = class {
18556
18491
  }
18557
18492
  }
18558
18493
  mergeNodes(current, next) {
18559
- return [...new Map([...current, ...next].map((node) => [`${node.type}:${node.kind ?? ""}:${node.name}:${node.scope.level}:${node.scope.id}`, node])).values()];
18494
+ return [...new Map([...current, ...next].map((node) => [node.id, node])).values()];
18560
18495
  }
18561
18496
  async loadMoreRecords(kind) {
18562
18497
  if (this.detail?.type !== "node") return;
@@ -18726,9 +18661,8 @@ var KnowledgeBrowserComponent = class {
18726
18661
  }
18727
18662
  }
18728
18663
  const marker = index === this.selectedIndex ? "→" : " ";
18729
- const kind = record.kind ? ` (${record.kind})` : "";
18730
18664
  const badge = scopeLabel(record, this.level);
18731
- lines.push(truncateAnsi(`${marker} ${record.name}${kind}${countsBadge(record)} ${theme.fg("muted", badge)}`, width));
18665
+ lines.push(truncateAnsi(`${marker} ${record.name}${countsBadge(record)} ${theme.fg("muted", badge)}`, width));
18732
18666
  });
18733
18667
  if (this.nextCursor) lines.push(`${this.selectedIndex === this.nodes.length ? "→" : " "} Load more…`);
18734
18668
  if (!this.loading && lines.length === 0) lines.push(theme.fg("muted", `No ${this.section} found.`));
@@ -18753,7 +18687,7 @@ var KnowledgeBrowserComponent = class {
18753
18687
  const counts = detail.relationshipCounts;
18754
18688
  const role = graphRole(detail.node);
18755
18689
  const roleSummary = `${role ? `${roleLabel(role)} · ` : ""}${counts.records} records · ${counts.outgoing} outgoing · ${counts.incoming} incoming${counts.sampled ? " (sampled)" : ""}`;
18756
- const lines = [`${theme.bold(detail.node.name)} ${detail.node.kind ?? "node"} ${scopeLabel(detail.node, this.level)} v${detail.node.version}`, theme.fg("muted", roleSummary)];
18690
+ const lines = [`${theme.bold(detail.node.name)} page ${scopeLabel(detail.node, this.level)} v${detail.node.version}`, theme.fg("muted", roleSummary)];
18757
18691
  if (detail.content) {
18758
18692
  lines.push("", theme.bold("Content"));
18759
18693
  const contentLines = (0, _earendil_works_pi_tui.wrapTextWithAnsi)(detail.content, Math.max(MIN_CONTENT_WIDTH, width - 2)).slice(0, MAX_BODY_LINES);
@@ -18787,7 +18721,7 @@ var KnowledgeBrowserComponent = class {
18787
18721
  ""
18788
18722
  ];
18789
18723
  if (this.section === "nodes" && !this.detail) {
18790
- const coverage = this.nodeCoverage === "recent-window" ? " · recent window" : "";
18724
+ const coverage = this.nodeCoverage === "window" ? " · first 50 by name" : "";
18791
18725
  const label = this.nodeSort[0].toUpperCase() + this.nodeSort.slice(1);
18792
18726
  lines.push(theme.fg("muted", `Sort: ${label}${coverage} · Ctrl+S change`), "");
18793
18727
  }
@@ -18804,13 +18738,13 @@ var KnowledgeBrowserComponent = class {
18804
18738
  };
18805
18739
  // src/tui/commands/knowledge-command.ts
18806
18740
  async function handleKnowledgeCommand(ctx) {
18807
- if (!isSubconsciousEnabled()) {
18741
+ if (!isKnowledgeEnabled()) {
18808
18742
  ctx.showError("Unknown command: /knowledge");
18809
18743
  return;
18810
18744
  }
18811
18745
  const inspector = ctx.knowledgeInspector;
18812
18746
  if (!inspector) {
18813
- ctx.showError(ctx.knowledgeInspectorUnavailableReason ?? "Knowledge inspection is unavailable. Restart Mastra Code with MASTRACODE_EXPERIMENTAL_SUBCONSCIOUS=1.");
18747
+ ctx.showError(ctx.knowledgeInspectorUnavailableReason ?? "Knowledge inspection is unavailable. Turn on Experimental Knowledge in /settings and restart Mastra Code.");
18814
18748
  return;
18815
18749
  }
18816
18750
  return new Promise((resolve) => {
@@ -19156,6 +19090,26 @@ var SettingsComponent = class extends _earendil_works_pi_tui.Box {
19156
19090
  done(enabled ? "On" : "Off");
19157
19091
  }, () => done())
19158
19092
  },
19093
+ {
19094
+ id: "experimentalKnowledge",
19095
+ label: "Experimental Knowledge",
19096
+ description: "Give the agent Knowledge it can search, write and pin, stored with Mastra Code (restart required).",
19097
+ currentValue: config.experimentalKnowledge ? "On" : "Off",
19098
+ submenu: (_currentValue, done) => new SelectSubmenu([{
19099
+ value: "on",
19100
+ label: " On",
19101
+ description: "Add knowledge_search, knowledge_read, knowledge_page, knowledge_note and knowledge_pin"
19102
+ }, {
19103
+ value: "off",
19104
+ label: " Off",
19105
+ description: "No Knowledge tools or pinned context"
19106
+ }], config.experimentalKnowledge ? "on" : "off", (value) => {
19107
+ const enabled = value === "on";
19108
+ callbacks.onExperimentalKnowledgeChange(enabled);
19109
+ config.experimentalKnowledge = enabled;
19110
+ done(enabled ? "On" : "Off");
19111
+ }, () => done())
19112
+ },
19159
19113
  {
19160
19114
  id: "experimentalAgent",
19161
19115
  label: "Experimental agent",
@@ -19550,6 +19504,7 @@ async function handleSettingsCommand(ctx) {
19550
19504
  experimentalGithubSignals: globalSettings.signals.experimentalGithubSignals,
19551
19505
  experimentalCrossAgentSignals: globalSettings.signals.experimentalCrossAgentSignals,
19552
19506
  experimentalScheduleTools: globalSettings.signals.experimentalScheduleTools,
19507
+ experimentalKnowledge: globalSettings.signals.experimentalKnowledge,
19553
19508
  experimentalAgent: resolveExperimentalAgentSetting(globalSettings.experimentalAgent),
19554
19509
  backgroundToolsEnabled: globalSettings.backgroundTools?.enabled ?? false,
19555
19510
  webSearchProvider: globalSettings.preferences.webSearchProvider === "tavily" && !process.env.TAVILY_API_KEY || globalSettings.preferences.webSearchProvider === "parallel" && !process.env.PARALLEL_API_KEY ? "auto" : globalSettings.preferences.webSearchProvider,
@@ -19625,6 +19580,12 @@ async function handleSettingsCommand(ctx) {
19625
19580
  (0, _mastra_code_sdk_onboarding_settings.saveSettings)(current);
19626
19581
  ctx.showInfo(`Experimental schedule tools: ${enabled ? "on" : "off"} (restart required)`);
19627
19582
  },
19583
+ onExperimentalKnowledgeChange: (enabled) => {
19584
+ const current = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
19585
+ current.signals.experimentalKnowledge = enabled;
19586
+ (0, _mastra_code_sdk_onboarding_settings.saveSettings)(current);
19587
+ ctx.showInfo(`Experimental Knowledge: ${enabled ? "on" : "off"} (restart required)`);
19588
+ },
19628
19589
  onExperimentalAgentChange: (agent) => {
19629
19590
  const current = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
19630
19591
  current.experimentalAgent = agent;
@@ -26809,9 +26770,9 @@ function setupAutocomplete(state) {
26809
26770
  name: "om",
26810
26771
  description: "Alias for /memory"
26811
26772
  },
26812
- ...isSubconsciousEnabled() ? [{
26773
+ ...isKnowledgeEnabled() ? [{
26813
26774
  name: "knowledge",
26814
- description: "Browse scoped Subconscious knowledge"
26775
+ description: "Browse scoped knowledge"
26815
26776
  }] : [],
26816
26777
  _mastra_code_sdk_thinking.THINK_COMMAND_DESCRIPTOR,
26817
26778
  {
@@ -29016,4 +28977,4 @@ Object.defineProperty(exports, "theme", {
29016
28977
  }
29017
28978
  });
29018
28979
 
29019
- //# sourceMappingURL=tui-4Evog5Ks.cjs.map
28980
+ //# sourceMappingURL=tui-DYOZlf_M.cjs.map