@@ -20,7 +20,7 @@ const defaultConfig = {
2020} ;
2121
2222const MEMORY_CONSTANTS = {
23- documentsDir : 'documents' // Path to store documents
23+ documentsDir : 'documents'
2424} ;
2525
2626export async function createMemory ( ) {
@@ -48,7 +48,7 @@ export async function createMemory() {
4848 message : 'Description of the memory' ,
4949 placeholder : defaultConfig . description
5050 } ) ,
51- useGitRepo : ( ) =>
51+ useGit : ( ) =>
5252 p . confirm ( {
5353 message :
5454 'Do you want to create memory from current project git repository?' ,
@@ -63,115 +63,72 @@ export async function createMemory() {
6363 }
6464 ) ;
6565
66- let memoryFilesDir = '.' ;
67- let fileExtensions : string [ ] = [ '*' ] ;
66+ const memoryNameSlugified = slugify ( memoryInfo . name ) ;
67+ const memoryNameCamelCase = camelCase ( 'memory-' + memoryNameSlugified ) ;
68+ const baseDir = path . join ( process . cwd ( ) , 'baseai' , 'memory' ) ;
69+ const memoryDir = path . join ( baseDir , memoryNameSlugified ) ;
70+ const filePath = path . join ( memoryDir , 'index.ts' ) ;
71+ const dbDir = path . join ( process . cwd ( ) , '.baseai' , 'db' ) ;
6872
69- if ( memoryInfo . useGitRepo ) {
70- // Check if the current directory is a Git repository
73+ if ( memoryInfo . useGit ) {
7174 try {
7275 await execAsync ( 'git rev-parse --is-inside-work-tree' ) ;
7376 } catch ( error ) {
7477 p . cancel ( 'The current directory is not a Git repository.' ) ;
7578 process . exit ( 1 ) ;
7679 }
77-
78- memoryFilesDir = ( await p . text ( {
79- message :
80- 'Enter the path to the directory to track (relative to current directory):' ,
81- initialValue : '.' ,
82- validate : value => {
83- if ( ! value . trim ( ) ) {
84- return 'The path cannot be empty.' ;
85- }
86- const fullPath = path . resolve ( process . cwd ( ) , value ) ;
87- if ( ! fs . existsSync ( fullPath ) ) {
88- return 'The specified path does not exist.' ;
89- }
90- if ( ! fs . lstatSync ( fullPath ) . isDirectory ( ) ) {
91- return 'The specified path is not a directory.' ;
92- }
93- return ;
94- }
95- } ) ) as string ;
96-
97- const extensionsInput = ( await p . text ( {
98- message :
99- 'Enter file extensions to track (use * for all, or comma-separated list, e.g., .md,.mdx):' ,
100- validate : value => {
101- if ( value . trim ( ) === '' ) {
102- return 'Please enter at least one file extension or *' ;
103- }
104- if ( value !== '*' ) {
105- const extensions = value . split ( ',' ) . map ( ext => ext . trim ( ) ) ;
106- const invalidExtensions = extensions . filter (
107- ext => ! / ^ \. \w + $ / . test ( ext )
108- ) ;
109- if ( invalidExtensions . length > 0 ) {
110- return `Invalid extension(s): ${ invalidExtensions . join ( ', ' ) } . Extensions should start with a dot followed by alphanumeric characters.` ;
111- }
112- }
113- return ;
114- }
115- } ) ) as string ;
116-
117- fileExtensions =
118- extensionsInput === '*'
119- ? [ '*' ]
120- : extensionsInput . split ( ',' ) . map ( ext => ext . trim ( ) ) ;
12180 }
12281
123- const memoryNameSlugified = slugify ( memoryInfo . name ) ;
124- const memoryNameCamelCase = camelCase ( 'memory-' + memoryNameSlugified ) ;
125-
126- const baseDir = path . join ( process . cwd ( ) , 'baseai' , 'memory' ) ;
127- const memoryDir = path . join ( baseDir , memoryNameSlugified ) ;
128- const filePath = path . join ( memoryDir , 'index.ts' ) ;
129- const memoryDocumentsPath = path . join (
130- memoryDir ,
131- MEMORY_CONSTANTS . documentsDir
132- ) ;
133- const dbDir = path . join ( process . cwd ( ) , '.baseai' , 'db' ) ;
134-
135- const memoryContent = `import { MemoryI } from '@baseai/core';
136- import path from 'path';
82+ const memoryContent = `import {MemoryI} from '@baseai/core';
13783
13884const ${ memoryNameCamelCase } = (): MemoryI => ({
139- name: '${ memoryNameSlugified } ',
140- description: ${ JSON . stringify ( memoryInfo . description ) || '' } ,
141- config: {
142- useGitRepo: ${ memoryInfo . useGitRepo } ,
143- dirToTrack: path.posix.join(${ memoryFilesDir
144- . split ( path . sep )
145- . map ( segment => `'${ segment } '` )
146- . join ( ', ' ) } ),
147- extToTrack: ${ JSON . stringify ( fileExtensions ) }
148- }
85+ name: '${ memoryNameSlugified } ',
86+ description: ${ JSON . stringify ( memoryInfo . description || '' ) } ,
87+ git: {
88+ enabled: ${ memoryInfo . useGit } ,${
89+ memoryInfo . useGit
90+ ? `
91+ include: ['**/*'],
92+ gitignore: true,`
93+ : `
94+ include: ['${ MEMORY_CONSTANTS . documentsDir } /**/*'],
95+ gitignore: false,`
96+ }
97+ deployedAt: '',
98+ embeddedAt: ''
99+ }
149100});
150101
151- export default ${ memoryNameCamelCase } ;
152- ` ;
102+ export default ${ memoryNameCamelCase } ;` ;
153103
154104 try {
155105 await fs . promises . mkdir ( baseDir , { recursive : true } ) ;
156106 await fs . promises . mkdir ( memoryDir , { recursive : true } ) ;
157107 await fs . promises . writeFile ( filePath , memoryContent ) ;
158108 await fs . promises . mkdir ( dbDir , { recursive : true } ) ;
159- await createDb ( memoryNameSlugified ) ;
160109
161- if ( ! memoryInfo . useGitRepo ) {
110+ if ( ! memoryInfo . useGit ) {
111+ const memoryDocumentsPath = path . join (
112+ memoryDir ,
113+ MEMORY_CONSTANTS . documentsDir
114+ ) ;
162115 await fs . promises . mkdir ( memoryDocumentsPath , { recursive : true } ) ;
163116 p . note (
164117 `Add documents in baseai/memory/${ memoryNameSlugified } /${ cyan ( `documents` ) } to use them in the memory.`
165118 ) ;
166119 } else {
167- const extensionsMsg = fileExtensions . includes ( '*' )
168- ? 'all file types'
169- : `files with extensions: ${ cyan ( fileExtensions . join ( ', ' ) ) } ` ;
170120 p . note (
171- `All ${ extensionsMsg } under ${ cyan ( memoryFilesDir ) } will be tracked and used in the memory.`
121+ [
122+ 'All files in this Git repository will be tracked by default.' ,
123+ '' ,
124+ `To modify which files are being tracked, update the config at:` ,
125+ cyan ( filePath )
126+ ] . join ( '\n' )
172127 ) ;
173128 }
174129
130+ await createDb ( memoryNameSlugified ) ;
131+
175132 p . outro (
176133 heading ( {
177134 text : memoryNameCamelCase ,
0 commit comments