MCPcopy Index your code
hub / github.com/PatrickSys/codebase-context / migrateToNewStructure

Function migrateToNewStructure

src/index.ts:860–909  ·  view source on GitHub ↗

* Migrate legacy file structure to .codebase-context/ folder. * Idempotent, fail-safe. Rollback compatibility is not required.

(
  paths: ToolPaths,
  legacyPaths: ReturnType<typeof makeLegacyPaths>
)

Source from the content-addressed store, hash-verified

858 * Idempotent, fail-safe. Rollback compatibility is not required.
859 */
860async function migrateToNewStructure(
861 paths: ToolPaths,
862 legacyPaths: ReturnType<typeof makeLegacyPaths>
863): Promise<boolean> {
864 let migrated = false;
865
866 try {
867 await fs.mkdir(paths.baseDir, { recursive: true });
868
869 // intelligence.json
870 if (!(await fileExists(paths.intelligence))) {
871 if (await fileExists(legacyPaths.intelligence)) {
872 await fs.copyFile(legacyPaths.intelligence, paths.intelligence);
873 migrated = true;
874 if (process.env.CODEBASE_CONTEXT_DEBUG) {
875 console.error('[DEBUG] Migrated intelligence.json');
876 }
877 }
878 }
879
880 // index.json (keyword index)
881 if (!(await fileExists(paths.keywordIndex))) {
882 if (await fileExists(legacyPaths.keywordIndex)) {
883 await fs.copyFile(legacyPaths.keywordIndex, paths.keywordIndex);
884 migrated = true;
885 if (process.env.CODEBASE_CONTEXT_DEBUG) {
886 console.error('[DEBUG] Migrated index.json');
887 }
888 }
889 }
890
891 // Vector DB directory
892 if (!(await fileExists(paths.vectorDb))) {
893 if (await fileExists(legacyPaths.vectorDb)) {
894 await fs.rename(legacyPaths.vectorDb, paths.vectorDb);
895 migrated = true;
896 if (process.env.CODEBASE_CONTEXT_DEBUG) {
897 console.error('[DEBUG] Migrated vector database');
898 }
899 }
900 }
901
902 return migrated;
903 } catch (error) {
904 if (process.env.CODEBASE_CONTEXT_DEBUG) {
905 console.error('[DEBUG] Migration error:', error);
906 }
907 return false;
908 }
909}
910
911export type { IndexState } from './tools/types.js';
912

Callers 1

ensureProjectInitializedFunction · 0.85

Calls 1

fileExistsFunction · 0.70

Tested by

no test coverage detected