// Import libs import clear from 'clear'; import fs from 'fs'; import os from 'os'; import path from 'path'; // Import helpers import print from '../helpers/print'; import showChooser from '../helpers/showChooser'; import exec from '../helpers/exec'; import getPackageJSON from '../helpers/getPackageJSON'; /* eslint-disable no-console */ /*------------------------------------------------------------------------*/ /* ------------------------------ Constants ----------------------------- */ /*------------------------------------------------------------------------*/ // Skill folder name. Claude requires lowercase letters, numbers and hyphens, // and the folder name must match the skill's `name` in SKILL.md. const SKILL_NAME = 'avo-security'; // Where the skill ships inside this package (lib/screens -> package root) const SKILL_DIR = path.join(__dirname, '..', '..', SKILL_NAME); // Where Claude Code looks for personal skills const CLAUDE_CODE_SKILLS_DIR = path.join(os.homedir(), '.claude', 'skills'); // Files never copied or packaged const SKIP_NAMES = new Set(['.DS_Store', 'node_modules', 'evals']); /*------------------------------------------------------------------------*/ /* ------------------------------- Helpers ------------------------------ */ /*------------------------------------------------------------------------*/ /** * Recursively copy a folder (skipping noise), replacing the destination * @author Gabe Abrams * @param src source folder * @param dest destination folder (removed first if it exists) */ const copyFolder = (src: string, dest: string) => { if (fs.existsSync(dest)) { fs.rmSync(dest, { recursive: true, force: true }); } fs.mkdirSync(dest, { recursive: true }); fs.readdirSync(src, { withFileTypes: true }).forEach((entry) => { if (SKIP_NAMES.has(entry.name)) { return; } const from = path.join(src, entry.name); const to = path.join(dest, entry.name); if (entry.isDirectory()) { copyFolder(from, to); } else if (entry.isFile()) { fs.copyFileSync(from, to); } }); }; /** * Pick where generated files go: Downloads when it exists, else the temp dir * @author Gabe Abrams * @returns absolute folder path */ const getOutputFolder = (): string => { const downloads = path.join(os.homedir(), 'Downloads'); return (fs.existsSync(downloads) ? downloads : os.tmpdir()); }; /** * Get the version of this wizard (and therefore of the bundled skill) * @author Gabe Abrams * @returns version string */ const getWizardVersion = (): string => { const wizardPackageJSON = getPackageJSON(path.join(__dirname, '..', '..', 'package.json')); return String(wizardPackageJSON.version); }; /** * Print the usage instructions * @author Gabe Abrams */ const printInstructions = () => { clear(); print.title('How to Use AvoSecurity'); console.log(''); console.log('AvoSecurity is a Claude skill: a runbook plus scripts that walk Claude'); console.log('through our monthly security-update process for one project at a time:'); console.log('audit every lockfile, research each finding, upgrade without downgrading,'); console.log('swapping or overriding, queue fixes for in-house libs, write Ky tests,'); console.log('hand off for deploy, verify on the instance, log docs/SecurityUpdates.md,'); console.log('and bump the patch version.'); console.log(''); print.subtitle('1. Add the skill to Claude (once per person)'); console.log(''); console.log('Package it from this menu, then in Claude go to Customize > Skills, click'); console.log('"+", choose "Create skill" > "Upload a skill", pick avo-security.zip and'); console.log('enable it. Skills enabled in claude.ai also sync to Claude Code when you are'); console.log('signed in with the same account. On a Team plan you can Share / Publish to'); console.log('org from Customize > Skills so the whole team gets it. Claude Code users can'); console.log('also install it directly from this menu.'); console.log(''); print.subtitle('2. Run it (monthly, or when a Wiz report lands)'); console.log(''); console.log('Open Claude with this project available (Cowork: add the project folder;'); console.log('Claude Code: start in the project) and say, for example:'); console.log(''); console.log(' "Run AvoSecurity on this project. Wiz report: ."'); console.log(' "AvoSecurity report-only for immersive-player" (nothing is edited)'); console.log(''); console.log('Claude will ask for anything it is missing, run the inventory scripts that'); console.log('ship in node_modules/dce-dev-wizard/avo-security/, and prepare a branch for'); console.log('a developer to review, deploy and verify. Publishing libraries and merging'); console.log('stay with humans.'); console.log(''); print.subtitle('3. Keep it fresh'); console.log(''); console.log(`This wizard ships AvoSecurity ${getWizardVersion()}. After updating`); console.log('dce-dev-wizard, re-package and re-upload (or re-install) the skill so the'); console.log('runbook Claude follows matches the scripts in your project.'); console.log(''); print.enterToContinue(); }; /** * Create avo-security.zip for uploading to Claude * @author Gabe Abrams */ const packageSkill = () => { clear(); console.log('Packaging AvoSecurity...\n'); // zip is available on macOS and most Linux distributions try { exec('which zip'); } catch (err) { clear(); print.title('Error [zip not found]'); console.log(''); console.log('The "zip" command is required to package the skill. Install it and try'); console.log('again, or use "Install for Claude Code" instead.'); console.log(''); print.enterToContinue(); return; } const outputFolder = getOutputFolder(); const zipPath = path.join(outputFolder, `${SKILL_NAME}.zip`); if (fs.existsSync(zipPath)) { fs.rmSync(zipPath); } // The zip must contain the skill folder as its root (avo-security/SKILL.md), // not the files directly, or Claude rejects the upload const parent = path.dirname(SKILL_DIR); exec(`cd "${parent}" && zip -qr "${zipPath}" "${SKILL_NAME}" -x "*/.DS_Store" "*/node_modules/*" "*/evals/*"`); clear(); print.title('AvoSecurity Packaged'); console.log(''); console.log(`Created: ${zipPath}`); console.log(`Version: ${getWizardVersion()} (same as this dev wizard)`); console.log(''); console.log('Next, in Claude:'); console.log(' 1. Customize > Skills'); console.log(' 2. "+" > "Create skill" > "Upload a skill"'); console.log(` 3. Choose ${path.basename(zipPath)} and enable the skill`); console.log(' 4. (Team plan) Share or Publish to org so teammates get it too'); console.log(''); console.log('Re-upload after each dce-dev-wizard update that changes AvoSecurity.'); console.log(''); print.enterToContinue(); }; /** * Copy the skill into ~/.claude/skills for Claude Code * @author Gabe Abrams */ const installForClaudeCode = () => { clear(); console.log('Installing AvoSecurity for Claude Code...\n'); const dest = path.join(CLAUDE_CODE_SKILLS_DIR, SKILL_NAME); const existed = fs.existsSync(dest); try { copyFolder(SKILL_DIR, dest); } catch (err) { clear(); print.title('Error [Install Failed]'); console.log(''); console.log(`Could not write to ${dest}:`); console.log(String(err)); console.log(''); print.enterToContinue(); return; } clear(); print.title(existed ? 'AvoSecurity Updated' : 'AvoSecurity Installed'); console.log(''); console.log(`Location: ${dest}`); console.log(`Version: ${getWizardVersion()} (same as this dev wizard)`); console.log(''); console.log('Start Claude Code in any project and type /avo-security, or just describe'); console.log('the task ("run AvoSecurity on this project"). Re-run this after updating'); console.log('dce-dev-wizard to keep the skill in sync with the scripts.'); console.log(''); print.enterToContinue(); }; /*------------------------------------------------------------------------*/ /* ---------------------------------- Main ------------------------------ */ /*------------------------------------------------------------------------*/ /** * AvoSecurity pane: help the user add the bundled Claude skill to their * Claude environment (claude.ai / Cowork upload, or Claude Code install) * @author Gabe Abrams */ const installAvoSecurity = async () => { // Make sure the skill shipped with this install if (!fs.existsSync(path.join(SKILL_DIR, 'SKILL.md'))) { clear(); print.title('Error [AvoSecurity Not Found]'); console.log(''); console.log(`Expected the skill at ${SKILL_DIR} but it is missing.`); console.log('Reinstall dce-dev-wizard and try again.'); console.log(''); print.enterToContinue(); return; } // Endless loop until the user goes back while (true) { const option = showChooser({ title: `AvoSecurity ${getWizardVersion()} | Claude skill for monthly security updates`, question: 'What do you want to do?', options: [ { description: 'Package AvoSecurity for Claude (zip to upload at Customize > Skills)', tag: 'P', }, { description: `Install AvoSecurity for Claude Code on this computer (${path.join('~', '.claude', 'skills', SKILL_NAME)})`, tag: 'I', }, { description: 'How to use AvoSecurity', tag: 'H', }, { description: 'Back to main menu', tag: 'B', }, ], }); if (option.tag === 'P') { packageSkill(); } else if (option.tag === 'I') { installForClaudeCode(); } else if (option.tag === 'H') { printInstructions(); } else { return; } } }; export default installAvoSecurity;