From 4d42f338e09d3489ba18f9b463fae011856803a8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 23:53:41 +0000 Subject: [PATCH 1/2] Initial plan From e17a52cf60e1145cb50d94d7b1b62dd6a5375d65 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 15 Jan 2026 00:02:23 +0000 Subject: [PATCH 2/2] Invert clean command behavior: default now preserves config, -d does deep clean Co-authored-by: RetricSu <23436060+RetricSu@users.noreply.github.com> --- README.md | 2 +- src/cli.ts | 2 +- src/cmd/clean.ts | 28 ++++++++++++++-------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8ede0e4..1575fcb 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ Example result: Pay attention to the `devnet.configPath` and `devnet.dataPath`. 2. `cd` into the `devnet.configPath` . Modify the config files as needed. See [Custom Devnet Setup](https://docs.nervos.org/docs/node/run-devnet-node#custom-devnet-setup) and [Configure CKB](https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md) for details. -3. After modifications, run `offckb clean -d` to remove the chain data if needed while keeping the updated config files. +3. After modifications, run `offckb clean` to remove the chain data while keeping the updated config files. 4. Restart local blockchain by running `offckb node` diff --git a/src/cli.ts b/src/cli.ts index 5a24f9a..3be25f4 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -108,7 +108,7 @@ program program .command('clean') .description('Clean the devnet data, need to stop running the chain first') - .option('-d, --data', 'Only remove chain data, keep devnet config files') + .option('-d, --data', 'Deep clean: remove all devnet data including config files (useful when init is corrupted)') .action((options: { data?: boolean }) => clean(options)); program.command('accounts').description('Print account list info').action(accounts); diff --git a/src/cmd/clean.ts b/src/cmd/clean.ts index 729ae54..e55b465 100644 --- a/src/cmd/clean.ts +++ b/src/cmd/clean.ts @@ -10,35 +10,35 @@ export interface CleanOptions { export function clean(options?: CleanOptions) { const settings = readSettings(); const allDevnetDataPath = settings.devnet.configPath; - const dataOnly = options?.data || false; + const deepClean = options?.data || false; - if (dataOnly) { - // Only clean the chain data subdirectory - const chainDataPath = settings.devnet.dataPath; - if (isFolderExists(chainDataPath)) { + if (deepClean) { + // Deep clean: Remove everything including config files (useful when init is corrupted) + // this is the root folder of devnet, it contains config, data, debugFullTransactions, transactions, failed-transactions, contracts + if (isFolderExists(allDevnetDataPath)) { try { - fs.rmSync(chainDataPath, { recursive: true }); - logger.info(`Chain data cleaned. Devnet config files preserved.`); + fs.rmSync(allDevnetDataPath, { recursive: true }); + logger.info(`Deep clean completed. All devnet data and config files removed.`); } catch (error: unknown) { logger.info(`Did you stop running the chain first?`); logger.error((error as Error).message); } } else { - logger.info(`Nothing to clean. Chain data directory ${chainDataPath} not found.`); + logger.info(`Nothing to clean. Devnet directory ${allDevnetDataPath} not found.`); } } else { - // Clean everything - the original behavior - // this is the root folder of devnet, it contains config, data, debugFullTransactions, transactions, failed-transactions, contracts - if (isFolderExists(allDevnetDataPath)) { + // Default: Only clean the chain data subdirectory, preserving config files + const chainDataPath = settings.devnet.dataPath; + if (isFolderExists(chainDataPath)) { try { - fs.rmSync(allDevnetDataPath, { recursive: true }); - logger.info(`Chain data cleaned.`); + fs.rmSync(chainDataPath, { recursive: true }); + logger.info(`Chain data cleaned. Devnet config files preserved.`); } catch (error: unknown) { logger.info(`Did you stop running the chain first?`); logger.error((error as Error).message); } } else { - logger.info(`Nothing to clean. Devnet data directory ${allDevnetDataPath} not found.`); + logger.info(`Nothing to clean. Chain data directory ${chainDataPath} not found.`); } } }