import { HardhatRuntimeEnvironment } from "hardhat/types/hre"; import * as dotenv from "dotenv"; import { initializeRegistry, getPlaybookRegistry, initializeLighthouseFromEnv, getSamplePlaybooks, } from "../playbooks/index.js"; dotenv.config(); export default async function syncPlaybooksTask( taskArguments: any, hre: HardhatRuntimeEnvironment, ) { console.log("šŸ”„ Syncing Community Playbooks\n"); try { // Initialize initializeLighthouseFromEnv(); const builtins = getSamplePlaybooks(); await initializeRegistry(builtins); const registry = getPlaybookRegistry(); const synced = await registry.syncFromLighthouse(); const syncedCount = synced.length; if (syncedCount === 0) { console.log("āœ… No new playbooks to sync.\n"); console.log("šŸ’” All community playbooks are up to date!"); return; } console.log( `āœ… Synced ${syncedCount} new playbook(s) from community storage!\n`, ); console.log(`šŸ“Š Total registered playbooks: ${registry.getAll().length}\n`); console.log(`šŸ’” View all playbooks:`); console.log(` npx hardhat list-playbooks`); } catch (error) { console.error( `\nāŒ Sync failed: ${error instanceof Error ? error.message : String(error)}`, ); process.exit(1); } }