From ade6227ffe53f0d7aa3f24520395bdd205fd93f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Mon, 18 May 2026 14:24:23 +0000 Subject: [PATCH] feat: add uwf cas reindex command Rebuilds _index from all .bin nodes. Use after upgrading to json-cas 0.2.0 on an existing CAS directory. --- packages/cli-uwf/src/cli.ts | 11 +++++++++++ packages/cli-uwf/src/commands/cas.ts | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/cli-uwf/src/cli.ts b/packages/cli-uwf/src/cli.ts index 1f128ef..bbcf5ba 100755 --- a/packages/cli-uwf/src/cli.ts +++ b/packages/cli-uwf/src/cli.ts @@ -15,6 +15,7 @@ import { cmdCasGet, cmdCasHas, cmdCasPut, + cmdCasReindex, cmdCasRefs, cmdCasSchemaGet, cmdCasSchemaList, @@ -239,6 +240,16 @@ cas }); }); +cas + .command("reindex") + .description("Rebuild type index from all CAS nodes") + .action(() => { + const storageRoot = resolveStorageRoot(); + runAction(async () => { + writeOutput(await cmdCasReindex(storageRoot)); + }); + }); + const casSchema = cas.command("schema").description("CAS schema operations"); casSchema diff --git a/packages/cli-uwf/src/commands/cas.ts b/packages/cli-uwf/src/commands/cas.ts index 1a7bec6..15469dd 100644 --- a/packages/cli-uwf/src/commands/cas.ts +++ b/packages/cli-uwf/src/commands/cas.ts @@ -115,6 +115,17 @@ export async function cmdCasSchemaList( return entries; } +export async function cmdCasReindex( + storageRoot: string, +): Promise<{ status: string }> { + const indexDir = join(storageRoot, "cas", "_index"); + const { rmSync } = await import("node:fs"); + rmSync(indexDir, { recursive: true, force: true }); + // Re-open store to trigger migration rebuild + openStore(storageRoot); + return { status: "reindexed" }; +} + export async function cmdCasSchemaGet( storageRoot: string, hash: string,