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

Function readIndexMeta

src/core/index-meta.ts:144–177  ·  view source on GitHub ↗
(rootDir: string)

Source from the content-addressed store, hash-verified

142}
143
144export async function readIndexMeta(rootDir: string): Promise<IndexMeta> {
145 const metaPath = path.join(rootDir, CODEBASE_CONTEXT_DIRNAME, INDEX_META_FILENAME);
146
147 let parsed: unknown;
148 try {
149 const raw = await fs.readFile(metaPath, 'utf-8');
150 parsed = JSON.parse(raw);
151 } catch (error) {
152 throw asIndexCorrupted('Index meta missing or unreadable (rebuild required)', error);
153 }
154
155 const result = IndexMetaSchema.safeParse(parsed);
156 if (!result.success) {
157 throw new IndexCorruptedError(
158 `Index meta schema mismatch (rebuild required): ${result.error.message}`
159 );
160 }
161
162 const meta = result.data;
163
164 if (meta.metaVersion !== INDEX_META_VERSION) {
165 throw new IndexCorruptedError(
166 `Index meta version mismatch (rebuild required): expected metaVersion=${INDEX_META_VERSION}, found metaVersion=${meta.metaVersion}`
167 );
168 }
169
170 if (meta.formatVersion !== INDEX_FORMAT_VERSION) {
171 throw new IndexCorruptedError(
172 `Index format version mismatch (rebuild required): expected formatVersion=${INDEX_FORMAT_VERSION}, found formatVersion=${meta.formatVersion}`
173 );
174 }
175
176 return meta;
177}
178
179export async function validateIndexArtifacts(rootDir: string, meta: IndexMeta): Promise<void> {
180 const contextDir = path.join(rootDir, CODEBASE_CONTEXT_DIRNAME);

Callers 5

requireValidIndexFunction · 0.85
indexMethod · 0.85
initializeMethod · 0.85

Calls 1

asIndexCorruptedFunction · 0.85

Tested by

no test coverage detected