MCPcopy Create free account
hub / github.com/PatrickSys/codebase-context / toJSON

Method toJSON

src/utils/usage-tracker.ts:864–899  ·  view source on GitHub ↗

* Serialize for persistence to .codebase-context/intelligence.json

()

Source from the content-addressed store, hash-verified

862 * Serialize for persistence to .codebase-context/intelligence.json
863 */
864 toJSON(): {
865 imports: Record<string, string[]>;
866 exports: Record<string, FileExport[]>;
867 importDetails?: Record<string, Record<string, ImportEdgeDetail>>;
868 stats: { files: number; edges: number; avgDependencies: number };
869 } {
870 const imports: Record<string, string[]> = {};
871 for (const [file, deps] of this.imports.entries()) {
872 imports[file] = Array.from(deps);
873 }
874
875 const exports: Record<string, FileExport[]> = {};
876 for (const [file, exps] of this.exports.entries()) {
877 exports[file] = exps;
878 }
879
880 const importDetails: Record<string, Record<string, ImportEdgeDetail>> = {};
881 for (const [fromFile, edges] of this.importDetails.entries()) {
882 const nested: Record<string, ImportEdgeDetail> = {};
883 for (const [toFile, detail] of edges.entries()) {
884 if (!detail.line && (!detail.importedSymbols || detail.importedSymbols.length === 0))
885 continue;
886 nested[toFile] = detail;
887 }
888 if (Object.keys(nested).length > 0) {
889 importDetails[fromFile] = nested;
890 }
891 }
892
893 return {
894 imports,
895 exports,
896 ...(Object.keys(importDetails).length > 0 ? { importDetails } : {}),
897 stats: this.getStats()
898 };
899 }
900
901 /**
902 * Restore from JSON (for loading from .codebase-context/intelligence.json)

Callers 3

indexMethod · 0.95
collectFileMetricsFunction · 0.80

Calls 1

getStatsMethod · 0.95

Tested by

no test coverage detected