@@ -8,8 +8,9 @@ import { getTags } from "./services/tags.js";
88import { stripPrivateContent , isFullyPrivate } from "./services/privacy.js" ;
99import { createCompactionHook , type CompactionContext } from "./services/compaction.js" ;
1010
11- import { isConfigured , CONFIG } from "./config.js" ;
11+ import { isConfigured , CONFIG , PLUGIN_VERSION } from "./config.js" ;
1212import { log } from "./services/logger.js" ;
13+ import { checkNpmUpdate , formatUpdateNotice } from "./services/version-check.js" ;
1314import type { MemoryScope , MemoryType } from "./types/index.js" ;
1415
1516const CODE_BLOCK_PATTERN = / ` ` ` [ \s \S ] * ?` ` ` / g;
@@ -26,6 +27,7 @@ Extract the key information the user wants remembered and save it as a concise,
2627- Choose an appropriate \`type\`: "preference", "project-config", "learned-pattern", etc.
2728
2829DO NOT skip this step. The user explicitly asked you to remember.` ;
30+ const UPDATE_COMMAND = "bunx opencode-supermemory@latest install" ;
2931
3032function removeCodeBlocks ( text : string ) : string {
3133 return text . replace ( CODE_BLOCK_PATTERN , "" ) . replace ( INLINE_CODE_PATTERN , "" ) ;
@@ -36,6 +38,10 @@ function detectMemoryKeyword(text: string): boolean {
3638 return MEMORY_KEYWORD_PATTERN . test ( textWithoutCode ) ;
3739}
3840
41+ function combineContextParts ( parts : Array < string | null | undefined > ) : string {
42+ return parts . map ( ( part ) => part ?. trim ( ) ) . filter ( Boolean ) . join ( "\n\n" ) ;
43+ }
44+
3945export const SupermemoryPlugin : Plugin = async ( ctx : PluginInput ) => {
4046 const { directory } = ctx ;
4147 const tags = getTags ( directory ) ;
@@ -128,6 +134,11 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
128134 injectedSessions . add ( input . sessionID ) ;
129135
130136 let memoryContext = "" ;
137+ const updateCheck = checkNpmUpdate (
138+ "opencode-supermemory" ,
139+ PLUGIN_VERSION ,
140+ UPDATE_COMMAND
141+ ) . then ( ( info ) => ( info ? formatUpdateNotice ( info ) : null ) ) ;
131142
132143 if ( CONFIG . autoRecallEveryPrompt ) {
133144 const [ profileResult , userMemoriesResult , projectMemoriesListResult ] = await Promise . all ( [
@@ -163,13 +174,16 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
163174 memoryContext = formatContextForPrompt ( profile , { results : [ ] } , { results : [ ] } ) ;
164175 }
165176
166- if ( memoryContext ) {
177+ const updateNotice = await updateCheck ;
178+ const firstMessageContext = combineContextParts ( [ memoryContext , updateNotice ] ) ;
179+
180+ if ( firstMessageContext ) {
167181 const contextPart : Part = {
168182 id : `prt_supermemory-context-${ Date . now ( ) } ` ,
169183 sessionID : input . sessionID ,
170184 messageID : output . message . id ,
171185 type : "text" ,
172- text : memoryContext ,
186+ text : firstMessageContext ,
173187 synthetic : true ,
174188 } ;
175189
@@ -178,7 +192,7 @@ export const SupermemoryPlugin: Plugin = async (ctx: PluginInput) => {
178192 const duration = Date . now ( ) - start ;
179193 log ( "chat.message: context injected" , {
180194 duration,
181- contextLength : memoryContext . length ,
195+ contextLength : firstMessageContext . length ,
182196 } ) ;
183197 }
184198 }
0 commit comments