@mastra/code-sdk 1.5.0-alpha.7 → 1.5.0-alpha.8

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,23 @@
1
1
  # @mastra/code-sdk
2
2
 
3
+ ## 1.5.0-alpha.8
4
+
5
+ ### Minor Changes
6
+
7
+ - Factory sessions now get a real thread name on their first turn. Mastra's built-in title generation is enabled for them, so a thread is named from the first exchange with the same cheap model the observational-memory observer uses. ([#22156](https://github.com/mastra-ai/mastra/pull/22156))
8
+
9
+ Before, a factory session kept whatever name it was created with — the raw first prompt, or nothing at all for work sessions, which fell back to showing their branch — until the observer got far enough into the conversation to name it. Naming now happens on the first turn; the observer still refines it as the thread grows.
10
+
11
+ TUI sessions are unchanged: they keep being named by the observer, and pay for no extra call.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`aa3a85d`](https://github.com/mastra-ai/mastra/commit/aa3a85daf094c683bb97efdf4b6a696d2e474af5), [`d29d06f`](https://github.com/mastra-ai/mastra/commit/d29d06fe00bbd35b4571150ea04c59d2ed783c71), [`e6516df`](https://github.com/mastra-ai/mastra/commit/e6516dfcdae4f4ac0e7971d84359a81385ee602f), [`0b2a3d1`](https://github.com/mastra-ai/mastra/commit/0b2a3d1783875c5b97b7b36ab3d03d7360e0dde7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`57de7d6`](https://github.com/mastra-ai/mastra/commit/57de7d644ba7146edb4e9e6111ec4fa98c3a59e9), [`e8e299c`](https://github.com/mastra-ai/mastra/commit/e8e299cc6abdfc39947e2fec25803493015d3882), [`edfc548`](https://github.com/mastra-ai/mastra/commit/edfc548886bc7bae17b681f8b6b41a47eb32bcd2), [`a8a4871`](https://github.com/mastra-ai/mastra/commit/a8a4871215f51da95c47129602157ce5372f634a), [`c7d2ac2`](https://github.com/mastra-ai/mastra/commit/c7d2ac245e6e549f3ee8b6c019fd43fd352fb528), [`e6c3c14`](https://github.com/mastra-ai/mastra/commit/e6c3c14c27fe0b46137c9593b1ad81df1cb46d72), [`5165cdc`](https://github.com/mastra-ai/mastra/commit/5165cdcdcf50e144bb8113278535196cc9b07065), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`bbd4486`](https://github.com/mastra-ai/mastra/commit/bbd4486b7296d6fd0de7177344f87fbbc0bb4fff), [`9c984f9`](https://github.com/mastra-ai/mastra/commit/9c984f9152c0ded45453f21cb1f517fe12f8beae), [`9ee8120`](https://github.com/mastra-ai/mastra/commit/9ee8120ce17f76b9f617489e05a283353742690a), [`d975e92`](https://github.com/mastra-ai/mastra/commit/d975e924d4936f46c386bd3dee39c671720289f6), [`1cfa878`](https://github.com/mastra-ai/mastra/commit/1cfa8784d8da0dfaa0317e5048bc48b6084a5ea5), [`c118318`](https://github.com/mastra-ai/mastra/commit/c1183181c9804303db4b511c2e2648f8b714712b), [`fc07c64`](https://github.com/mastra-ai/mastra/commit/fc07c6465043e08e99193a6751a01c56ffc2e7a1), [`542dee2`](https://github.com/mastra-ai/mastra/commit/542dee254167f974ff8cbbbfc0ce10f9a2616a7b), [`8dcd635`](https://github.com/mastra-ai/mastra/commit/8dcd6357f0d9557cebc727d7abc6901af6231e4f), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`895e9df`](https://github.com/mastra-ai/mastra/commit/895e9dfc17d6f34299eca64e317ded9e5f5e5ef8)]:
16
+ - @mastra/core@1.62.0-alpha.8
17
+ - @mastra/libsql@1.22.0-alpha.2
18
+ - @mastra/pg@1.22.0-alpha.4
19
+ - @mastra/memory@1.28.0-alpha.3
20
+
3
21
  ## 1.5.0-alpha.7
4
22
 
5
23
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/agents/memory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAgB,MAAM,gBAAgB,CAAC;AAkEtD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,CAAC,EAAE,YAAY,IAM3E,oBAAoB;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,YAqG/D"}
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/agents/memory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAgB,MAAM,gBAAgB,CAAC;AAkEtD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,CAAC,EAAE,YAAY,IAM3E,oBAAoB;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,YAyG/D"}
@@ -90,39 +90,42 @@ function getDynamicMemory(storage, vector) {
90
90
  storage,
91
91
  vector: vector || false,
92
92
  embedder: vector ? fastembed.small : void 0,
93
- options: { observationalMemory: {
94
- enabled: true,
95
- temporalMarkers: true,
96
- retrieval: vector ? { vector: true } : true,
97
- experimental_subconscious: subconsciousEnabled ? new Subconscious({
98
- defaultScope: "resource",
99
- maxScope: "resource",
100
- pins: isFactory ? { capturePinning: true } : true,
101
- ...isFactory ? { curationCadence: 3 } : {},
102
- ...isFactory ? { maxSteps: 25 } : {}
103
- }) : void 0,
104
- scope: omScope,
105
- activateAfterIdle: "auto",
106
- activateOnProviderChange: true,
107
- observation: {
108
- bufferTokens: isResourceScope ? false : 1 / 5,
109
- bufferActivation: isResourceScope ? void 0 : 2e3,
110
- model: getObserverModel,
111
- messageTokens: obsThreshold,
112
- blockAfter: 2,
113
- previousObserverTokens: observerPreviousObservationTokens,
114
- threadTitle: true,
115
- instruction: observerInstruction,
116
- observeAttachments
117
- },
118
- reflection: {
119
- bufferActivation: isResourceScope ? void 0 : 1 / 2,
120
- blockAfter: 1.1,
121
- model: getReflectorModel,
122
- observationTokens: refThreshold,
123
- instruction: reflectionInstruction
93
+ options: {
94
+ ...isFactory ? { generateTitle: { model: getObserverModel } } : {},
95
+ observationalMemory: {
96
+ enabled: true,
97
+ temporalMarkers: true,
98
+ retrieval: vector ? { vector: true } : true,
99
+ experimental_subconscious: subconsciousEnabled ? new Subconscious({
100
+ defaultScope: "resource",
101
+ maxScope: "resource",
102
+ pins: isFactory ? { capturePinning: true } : true,
103
+ ...isFactory ? { curationCadence: 3 } : {},
104
+ ...isFactory ? { maxSteps: 25 } : {}
105
+ }) : void 0,
106
+ scope: omScope,
107
+ activateAfterIdle: "auto",
108
+ activateOnProviderChange: true,
109
+ observation: {
110
+ bufferTokens: isResourceScope ? false : 1 / 5,
111
+ bufferActivation: isResourceScope ? void 0 : 2e3,
112
+ model: getObserverModel,
113
+ messageTokens: obsThreshold,
114
+ blockAfter: 2,
115
+ previousObserverTokens: observerPreviousObservationTokens,
116
+ threadTitle: true,
117
+ instruction: observerInstruction,
118
+ observeAttachments
119
+ },
120
+ reflection: {
121
+ bufferActivation: isResourceScope ? void 0 : 1 / 2,
122
+ blockAfter: 1.1,
123
+ model: getReflectorModel,
124
+ observationTokens: refThreshold,
125
+ instruction: reflectionInstruction
126
+ }
124
127
  }
125
- } }
128
+ }
126
129
  });
127
130
  cachedMemoryKey = cacheKey;
128
131
  return cachedMemory;
@@ -1 +1 @@
1
- {"version":3,"file":"memory.js","names":[],"sources":["../../src/agents/memory.ts"],"sourcesContent":["import type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { MastraCompositeStore } from '@mastra/core/storage';\nimport type { MastraVector } from '@mastra/core/vector';\nimport { fastembed } from '@mastra/fastembed';\nimport { Memory, Subconscious } from '@mastra/memory';\nimport { DEFAULT_OM_MODEL_ID, DEFAULT_OBS_THRESHOLD, DEFAULT_REF_THRESHOLD } from '../constants.js';\nimport type { MastraCodeState } from '../schema.js';\nimport { getOmScope } from '../utils/project.js';\nimport { resolveModel } from './model.js';\n\n/**\n * Read controller state from requestContext.\n * Used by both the memory factory and the OM model functions.\n */\nfunction getAgentControllerState(requestContext: RequestContext): MastraCodeState | undefined {\n const ctx = requestContext.get('controller') as AgentControllerRequestContext<MastraCodeState> | undefined;\n return ctx?.getState() as MastraCodeState | undefined;\n}\n\n/**\n * Observer model function — reads the current observer model ID from\n * controller state via requestContext (now propagated by OM's agent.generate).\n */\nfunction getObserverModel({ requestContext }: { requestContext: RequestContext }) {\n const state = getAgentControllerState(requestContext);\n return resolveModel(state?.observerModelId ?? DEFAULT_OM_MODEL_ID, {\n remapForCodexOAuth: true,\n requestContext,\n });\n}\n\n/**\n * Reflector model function — reads the current reflector model ID from\n * controller state via requestContext (now propagated by OM's agent.generate).\n */\nfunction getReflectorModel({ requestContext }: { requestContext: RequestContext }) {\n const state = getAgentControllerState(requestContext);\n return resolveModel(state?.reflectorModelId ?? DEFAULT_OM_MODEL_ID, {\n remapForCodexOAuth: true,\n requestContext,\n });\n}\n\nconst DYNAMIC_AGENTS_MD_INSTRUCTION =\n 'Messages wrapped in <system-reminder type=\"dynamic-agents-md\" ...>...</system-reminder> are ephemeral project-context instructions injected from files on disk. Do NOT observe or extract information from these messages — they are reloaded automatically when needed and should not be stored in memory.';\n\n// Derived from https://github.com/JuliusBrussee/caveman and adapted for OM use with fixed full-level compression.\nconst CAVEMAN_OM_INSTRUCTION = `Respond terse like smart caveman. All technical substance stay. Only fluff die.\n\nUse full caveman compression style.\n\nDrop: articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries (sure/certainly/of course/happy to), hedging. Fragments OK. Short synonyms (big not extensive, fix not \"implement a solution for\"). Technical terms exact. Code blocks unchanged. Errors quoted exact. Leave out the words \"agent\" and \"assistant\" at the start of each observation line, it is assumed each line is referring to the assistant unless it specifically says it was about the user. Leave out parenthesis and other text characters like * that would not contribute to understanding the observations.\n\nPattern: \\`[thing] [action] [reason]. [next step]\\`\n\nNot: \"Sure! I'd be happy to help you with that. The issue you're experiencing is likely caused by...\"\nYes: \"Bug in auth middleware. Token expiry check use < not <=. Fix:\"\n\nExample 1\n🔴 14:31 user asks why React component rerenders\n🟡 14:32 saw inline object prop create new ref each render, cause rerender\n✅ 14:34 fixed render issue by wrap object in useMemo\n\nExample 2\n🟡 15:10 explained pool reuse DB connections, skip repeat handshake overhead\n\nDon't say \"Agent did x\", say \"did x\". It will be assumed the agent did what was observed. The who should only be specified for the user or other third parties: \"user asked x\"\n\nDrop caveman for: security warnings, irreversible action confirmations, multi-step sequences where fragment order risks misread, user asks to clarify or repeats question, and anything that requires remembering verbatim content. Resume caveman after clear part done`;\n\n/**\n * Dynamic memory factory function.\n * Reads OM thresholds from controller state via requestContext.\n * Model functions also read from requestContext (no mutable bridge needed).\n */\nexport function getDynamicMemory(storage: MastraCompositeStore, vector?: MastraVector) {\n // Cache is scoped per storage instance (per getDynamicMemory call) so a\n // Memory bound to one storage is never reused after storage changes.\n let cachedMemory: Memory | null = null;\n let cachedMemoryKey: string | null = null;\n\n return ({ requestContext }: { requestContext: RequestContext }) => {\n const controller = requestContext.get('controller') as AgentControllerRequestContext<MastraCodeState> | undefined;\n const state = controller?.getState() as MastraCodeState | undefined;\n const subconsciousEnabled = Boolean(vector) && process.env.MASTRACODE_EXPERIMENTAL_SUBCONSCIOUS === '1';\n const factoryProjectId = state?.factoryProjectId;\n const isFactory = typeof factoryProjectId === 'string' && factoryProjectId.trim().length > 0;\n\n if (subconsciousEnabled) {\n // Factory seeds the authoritative org id into session state; prefer it.\n // The session owner is a USER id — mapping it into organizationId is only\n // the legacy fallback for clients (TUI/studio) that never set factoryOrgId.\n const factoryOrgId = state?.factoryOrgId;\n const ownerId = controller?.session.ownerId;\n if (typeof factoryOrgId === 'string' && factoryOrgId.trim()) {\n requestContext.set('organizationId', factoryOrgId);\n } else if (ownerId) {\n requestContext.set('organizationId', ownerId);\n }\n // Factory runs share one knowledge graph per project: anchor the\n // subconscious knowledge scope's resource rung on the project id.\n if (isFactory) {\n requestContext.set('knowledgeResourceId', factoryProjectId);\n }\n }\n\n const omScope = state?.omScope ?? getOmScope(state?.projectPath);\n\n const obsThreshold = state?.observationThreshold ?? DEFAULT_OBS_THRESHOLD;\n const refThreshold = state?.reflectionThreshold ?? DEFAULT_REF_THRESHOLD;\n const caveman = state?.cavemanObservations ?? false;\n\n const observerPreviousObservationTokens = 1000;\n const observeAttachments = state?.observeAttachments;\n // Factory sessions get a factory-only Subconscious config, so the cache key\n // carries a factory presence bit to keep the two configs from cross-serving.\n const cacheKey = `${obsThreshold}:${refThreshold}:${omScope}:${observerPreviousObservationTokens}:${caveman ? 1 : 0}:${observeAttachments}:${isFactory ? 1 : 0}:${subconsciousEnabled ? 1 : 0}`;\n if (cachedMemory && cachedMemoryKey === cacheKey) {\n return cachedMemory;\n }\n\n // Async buffering is not supported with resource scope — disable it\n const isResourceScope = omScope === 'resource';\n\n const observerInstruction = caveman\n ? `${DYNAMIC_AGENTS_MD_INSTRUCTION}\\n\\n${CAVEMAN_OM_INSTRUCTION}`\n : DYNAMIC_AGENTS_MD_INSTRUCTION;\n const reflectionInstruction = caveman ? CAVEMAN_OM_INSTRUCTION : undefined;\n\n cachedMemory = new Memory({\n storage,\n vector: vector || false,\n embedder: vector ? fastembed.small : undefined,\n options: {\n observationalMemory: {\n enabled: true,\n temporalMarkers: true,\n retrieval: vector ? { vector: true } : true,\n experimental_subconscious: subconsciousEnabled\n ? new Subconscious({\n defaultScope: 'resource',\n maxScope: 'resource',\n // Capture-time pinning is a factory-only opinion; every other\n // client keeps plain curator-maintained pins.\n pins: isFactory ? { capturePinning: true } : true,\n // Factory sessions run the curator every 3 observation runs;\n // other clients leave the cadence trigger dormant.\n ...(isFactory ? { curationCadence: 3 } : {}),\n // Real curation over a factory worklist needs tool room: the\n // default 5-step budget exhausts mid-batch and the curator never\n // reaches its cursor acknowledgment (observed live 2026-08-13).\n ...(isFactory ? { maxSteps: 25 } : {}),\n })\n : undefined,\n scope: omScope,\n activateAfterIdle: 'auto',\n activateOnProviderChange: true,\n observation: {\n bufferTokens: isResourceScope ? false : 1 / 5,\n bufferActivation: isResourceScope ? undefined : 2000,\n model: getObserverModel,\n messageTokens: obsThreshold,\n blockAfter: 2,\n previousObserverTokens: observerPreviousObservationTokens,\n threadTitle: true,\n instruction: observerInstruction,\n observeAttachments,\n },\n reflection: {\n bufferActivation: isResourceScope ? undefined : 1 / 2,\n blockAfter: 1.1,\n model: getReflectorModel,\n observationTokens: refThreshold,\n instruction: reflectionInstruction,\n },\n },\n },\n });\n cachedMemoryKey = cacheKey;\n\n return cachedMemory;\n };\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAS,wBAAwB,gBAA6D;CAE5F,OADY,eAAe,IAAI,YACtB,CAAC,EAAE,SAAS;AACvB;;;;;AAMA,SAAS,iBAAiB,EAAE,kBAAsD;CAEhF,OAAO,aADO,wBAAwB,cACd,CAAC,EAAE,mBAAmB,qBAAqB;EACjE,oBAAoB;EACpB;CACF,CAAC;AACH;;;;;AAMA,SAAS,kBAAkB,EAAE,kBAAsD;CAEjF,OAAO,aADO,wBAAwB,cACd,CAAC,EAAE,oBAAoB,qBAAqB;EAClE,oBAAoB;EACpB;CACF,CAAC;AACH;AAEA,MAAM,gCACJ;AAGF,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B/B,SAAgB,iBAAiB,SAA+B,Q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QAAQ,KAAK,IAAI;IACvC,2BAA2B,sBACvB,IAAI,aAAa;KACf,cAAc;KACd,UAAU;KAGV,MAAM,YAAY,EAAE,gBAAgB,KAAK,IAAI;KAG7C,GAAI,YAAY,EAAE,iBAAiB,EAAE,IAAI,CAAC;KAI1C,GAAI,YAAY,EAAE,UAAU,GAAG,IAAI,CAAC;IACtC,CAAC,IACD,KAAA;IACJ,OAAO;IACP,mBAAmB;IACnB,0BAA0B;IAC1B,aAAa;KACX,cAAc,kBAAkB,QAAQ,IAAI;KAC5C,kBAAkB,kBAAkB,KAAA,IAAY;KAChD,OAAO;KACP,eAAe;KACf,YAAY;KACZ,wBAAwB;KACxB,aAAa;KACb,aAAa;KACb;IACF;IACA,YAAY;KACV,kBAAkB,kBAAkB,KAAA,IAAY,IAAI;KACpD,YAAY;KACZ,OAAO;KACP,mBAAmB;KACnB,aAAa;IACf;GACF,EACF;EACF,CAAC;EACD,kBAAkB;EAElB,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"memory.js","names":[],"sources":["../../src/agents/memory.ts"],"sourcesContent":["import type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { MastraCompositeStore } from '@mastra/core/storage';\nimport type { MastraVector } from '@mastra/core/vector';\nimport { fastembed } from '@mastra/fastembed';\nimport { Memory, Subconscious } from '@mastra/memory';\nimport { DEFAULT_OM_MODEL_ID, DEFAULT_OBS_THRESHOLD, DEFAULT_REF_THRESHOLD } from '../constants.js';\nimport type { MastraCodeState } from '../schema.js';\nimport { getOmScope } from '../utils/project.js';\nimport { resolveModel } from './model.js';\n\n/**\n * Read controller state from requestContext.\n * Used by both the memory factory and the OM model functions.\n */\nfunction getAgentControllerState(requestContext: RequestContext): MastraCodeState | undefined {\n const ctx = requestContext.get('controller') as AgentControllerRequestContext<MastraCodeState> | undefined;\n return ctx?.getState() as MastraCodeState | undefined;\n}\n\n/**\n * Observer model function — reads the current observer model ID from\n * controller state via requestContext (now propagated by OM's agent.generate).\n */\nfunction getObserverModel({ requestContext }: { requestContext: RequestContext }) {\n const state = getAgentControllerState(requestContext);\n return resolveModel(state?.observerModelId ?? DEFAULT_OM_MODEL_ID, {\n remapForCodexOAuth: true,\n requestContext,\n });\n}\n\n/**\n * Reflector model function — reads the current reflector model ID from\n * controller state via requestContext (now propagated by OM's agent.generate).\n */\nfunction getReflectorModel({ requestContext }: { requestContext: RequestContext }) {\n const state = getAgentControllerState(requestContext);\n return resolveModel(state?.reflectorModelId ?? DEFAULT_OM_MODEL_ID, {\n remapForCodexOAuth: true,\n requestContext,\n });\n}\n\nconst DYNAMIC_AGENTS_MD_INSTRUCTION =\n 'Messages wrapped in <system-reminder type=\"dynamic-agents-md\" ...>...</system-reminder> are ephemeral project-context instructions injected from files on disk. Do NOT observe or extract information from these messages — they are reloaded automatically when needed and should not be stored in memory.';\n\n// Derived from https://github.com/JuliusBrussee/caveman and adapted for OM use with fixed full-level compression.\nconst CAVEMAN_OM_INSTRUCTION = `Respond terse like smart caveman. All technical substance stay. Only fluff die.\n\nUse full caveman compression style.\n\nDrop: articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries (sure/certainly/of course/happy to), hedging. Fragments OK. Short synonyms (big not extensive, fix not \"implement a solution for\"). Technical terms exact. Code blocks unchanged. Errors quoted exact. Leave out the words \"agent\" and \"assistant\" at the start of each observation line, it is assumed each line is referring to the assistant unless it specifically says it was about the user. Leave out parenthesis and other text characters like * that would not contribute to understanding the observations.\n\nPattern: \\`[thing] [action] [reason]. [next step]\\`\n\nNot: \"Sure! I'd be happy to help you with that. The issue you're experiencing is likely caused by...\"\nYes: \"Bug in auth middleware. Token expiry check use < not <=. Fix:\"\n\nExample 1\n🔴 14:31 user asks why React component rerenders\n🟡 14:32 saw inline object prop create new ref each render, cause rerender\n✅ 14:34 fixed render issue by wrap object in useMemo\n\nExample 2\n🟡 15:10 explained pool reuse DB connections, skip repeat handshake overhead\n\nDon't say \"Agent did x\", say \"did x\". It will be assumed the agent did what was observed. The who should only be specified for the user or other third parties: \"user asked x\"\n\nDrop caveman for: security warnings, irreversible action confirmations, multi-step sequences where fragment order risks misread, user asks to clarify or repeats question, and anything that requires remembering verbatim content. Resume caveman after clear part done`;\n\n/**\n * Dynamic memory factory function.\n * Reads OM thresholds from controller state via requestContext.\n * Model functions also read from requestContext (no mutable bridge needed).\n */\nexport function getDynamicMemory(storage: MastraCompositeStore, vector?: MastraVector) {\n // Cache is scoped per storage instance (per getDynamicMemory call) so a\n // Memory bound to one storage is never reused after storage changes.\n let cachedMemory: Memory | null = null;\n let cachedMemoryKey: string | null = null;\n\n return ({ requestContext }: { requestContext: RequestContext }) => {\n const controller = requestContext.get('controller') as AgentControllerRequestContext<MastraCodeState> | undefined;\n const state = controller?.getState() as MastraCodeState | undefined;\n const subconsciousEnabled = Boolean(vector) && process.env.MASTRACODE_EXPERIMENTAL_SUBCONSCIOUS === '1';\n const factoryProjectId = state?.factoryProjectId;\n const isFactory = typeof factoryProjectId === 'string' && factoryProjectId.trim().length > 0;\n\n if (subconsciousEnabled) {\n // Factory seeds the authoritative org id into session state; prefer it.\n // The session owner is a USER id — mapping it into organizationId is only\n // the legacy fallback for clients (TUI/studio) that never set factoryOrgId.\n const factoryOrgId = state?.factoryOrgId;\n const ownerId = controller?.session.ownerId;\n if (typeof factoryOrgId === 'string' && factoryOrgId.trim()) {\n requestContext.set('organizationId', factoryOrgId);\n } else if (ownerId) {\n requestContext.set('organizationId', ownerId);\n }\n // Factory runs share one knowledge graph per project: anchor the\n // subconscious knowledge scope's resource rung on the project id.\n if (isFactory) {\n requestContext.set('knowledgeResourceId', factoryProjectId);\n }\n }\n\n const omScope = state?.omScope ?? getOmScope(state?.projectPath);\n\n const obsThreshold = state?.observationThreshold ?? DEFAULT_OBS_THRESHOLD;\n const refThreshold = state?.reflectionThreshold ?? DEFAULT_REF_THRESHOLD;\n const caveman = state?.cavemanObservations ?? false;\n\n const observerPreviousObservationTokens = 1000;\n const observeAttachments = state?.observeAttachments;\n // Factory sessions get a factory-only Subconscious config, so the cache key\n // carries a factory presence bit to keep the two configs from cross-serving.\n const cacheKey = `${obsThreshold}:${refThreshold}:${omScope}:${observerPreviousObservationTokens}:${caveman ? 1 : 0}:${observeAttachments}:${isFactory ? 1 : 0}:${subconsciousEnabled ? 1 : 0}`;\n if (cachedMemory && cachedMemoryKey === cacheKey) {\n return cachedMemory;\n }\n\n // Async buffering is not supported with resource scope — disable it\n const isResourceScope = omScope === 'resource';\n\n const observerInstruction = caveman\n ? `${DYNAMIC_AGENTS_MD_INSTRUCTION}\\n\\n${CAVEMAN_OM_INSTRUCTION}`\n : DYNAMIC_AGENTS_MD_INSTRUCTION;\n const reflectionInstruction = caveman ? CAVEMAN_OM_INSTRUCTION : undefined;\n\n cachedMemory = new Memory({\n storage,\n vector: vector || false,\n embedder: vector ? fastembed.small : undefined,\n options: {\n // The factory sidebar shows a session the moment it exists, so it needs a\n // name on the first turn. The TUI names its threads from OM's `threadTitle`\n // as they grow and would only pay for an extra call here.\n ...(isFactory ? { generateTitle: { model: getObserverModel } } : {}),\n observationalMemory: {\n enabled: true,\n temporalMarkers: true,\n retrieval: vector ? { vector: true } : true,\n experimental_subconscious: subconsciousEnabled\n ? new Subconscious({\n defaultScope: 'resource',\n maxScope: 'resource',\n // Capture-time pinning is a factory-only opinion; every other\n // client keeps plain curator-maintained pins.\n pins: isFactory ? { capturePinning: true } : true,\n // Factory sessions run the curator every 3 observation runs;\n // other clients leave the cadence trigger dormant.\n ...(isFactory ? { curationCadence: 3 } : {}),\n // Real curation over a factory worklist needs tool room: the\n // default 5-step budget exhausts mid-batch and the curator never\n // reaches its cursor acknowledgment (observed live 2026-08-13).\n ...(isFactory ? { maxSteps: 25 } : {}),\n })\n : undefined,\n scope: omScope,\n activateAfterIdle: 'auto',\n activateOnProviderChange: true,\n observation: {\n bufferTokens: isResourceScope ? false : 1 / 5,\n bufferActivation: isResourceScope ? undefined : 2000,\n model: getObserverModel,\n messageTokens: obsThreshold,\n blockAfter: 2,\n previousObserverTokens: observerPreviousObservationTokens,\n threadTitle: true,\n instruction: observerInstruction,\n observeAttachments,\n },\n reflection: {\n bufferActivation: isResourceScope ? undefined : 1 / 2,\n blockAfter: 1.1,\n model: getReflectorModel,\n observationTokens: refThreshold,\n instruction: reflectionInstruction,\n },\n },\n },\n });\n cachedMemoryKey = cacheKey;\n\n return cachedMemory;\n };\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAS,wBAAwB,gBAA6D;CAE5F,OADY,eAAe,IAAI,YACtB,CAAC,EAAE,SAAS;AACvB;;;;;AAMA,SAAS,iBAAiB,EAAE,kBAAsD;CAEhF,OAAO,aADO,wBAAwB,cACd,CAAC,EAAE,mBAAmB,qBAAqB;EACjE,oBAAoB;EACpB;CACF,CAAC;AACH;;;;;AAMA,SAAS,kBAAkB,EAAE,kBAAsD;CAEjF,OAAO,aADO,wBAAwB,cACd,CAAC,EAAE,oBAAoB,qBAAqB;EAClE,oBAAoB;EACpB;CACF,CAAC;AACH;AAEA,MAAM,gCACJ;AAGF,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B/B,SAAgB,iBAAiB,SAA+B,QAAuB;CAGrF,IAAI,eAA8B;CAClC,IAAI,kBAAiC;CAErC,QAAQ,EAAE,qBAAyD;EACjE,MAAM,aAAa,eAAe,IAAI,YAAY;EAClD,MAAM,QAAQ,YAAY,SAAS;EACnC,MAAM,sBAAsB,QAAQ,MAAM,KAAK,QAAQ,IAAI,yCAAyC;EACpG,MAAM,mBAAmB,OAAO;EAChC,MAAM,YAAY,OAAO,qBAAqB,YAAY,iBAAiB,KAAK,CAAC,CAAC,SAAS;EAE3F,IAAI,qBAAqB;GAIvB,MAAM,eAAe,OAAO;GAC5B,MAAM,UAAU,YAAY,QAAQ;GACpC,IAAI,OAAO,iBAAiB,YAAY,aAAa,KAAK,GACxD,eAAe,IAAI,kBAAkB,YAAY;QAC5C,IAAI,SACT,eAAe,IAAI,kBAAkB,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ACb,aAAa;MACb;KACF;KACA,YAAY;MACV,kBAAkB,kBAAkB,KAAA,IAAY,IAAI;MACpD,YAAY;MACZ,OAAO;MACP,mBAAmB;MACnB,aAAa;KACf;IACF;GACF;EACF,CAAC;EACD,kBAAkB;EAElB,OAAO;CACT;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/code-sdk",
3
- "version": "1.5.0-alpha.7",
3
+ "version": "1.5.0-alpha.8",
4
4
  "description": "Mastra Code SDK: the agent core behind Mastra Code (everything except the TUI) — build your own UIs and surfaces on top of it",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -57,19 +57,19 @@
57
57
  "vscode-languageserver-protocol": "^3.17.5",
58
58
  "yaml": "^2.7.1",
59
59
  "zod": "^4.3.6",
60
+ "@mastra/core": "1.62.0-alpha.8",
60
61
  "@mastra/agent-browser": "0.5.1",
61
- "@mastra/core": "1.62.0-alpha.7",
62
- "@mastra/github-signals": "0.2.5",
63
62
  "@mastra/duckdb": "1.6.3-alpha.0",
64
63
  "@mastra/fastembed": "1.2.0",
64
+ "@mastra/github-signals": "0.2.5",
65
+ "@mastra/libsql": "1.22.0-alpha.2",
65
66
  "@mastra/mcp": "1.17.2-alpha.2",
66
- "@mastra/memory": "1.28.0-alpha.2",
67
67
  "@mastra/observability": "1.17.2-alpha.1",
68
- "@mastra/libsql": "1.22.0-alpha.1",
69
- "@mastra/stagehand": "0.3.3",
70
- "@mastra/tavily": "1.1.1",
68
+ "@mastra/memory": "1.28.0-alpha.3",
69
+ "@mastra/pg": "1.22.0-alpha.4",
71
70
  "@mastra/schema-compat": "1.3.7",
72
- "@mastra/pg": "1.22.0-alpha.3"
71
+ "@mastra/stagehand": "0.3.3",
72
+ "@mastra/tavily": "1.1.1"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@libsql/client": "^0.17.4",