|
| 1 | +--- |
| 2 | +name: setup |
| 3 | +description: "This skill should be used when codeflash fails to run due to missing installation, authentication issues, or missing project configuration. It handles installing codeflash (via pip or uv), authenticating, and configuring pyproject.toml. Trigger phrases: \"setup codeflash\", \"configure codeflash\", \"codeflash is not installed\", \"codeflash auth failed\", \"fix codeflash setup\"." |
| 4 | +color: cyan |
| 5 | +tools: ["Read", "Glob", "Grep", "Bash", "Write", "Task"] |
| 6 | +--- |
| 7 | + |
| 8 | +# Codeflash Setup |
| 9 | + |
| 10 | +Set up codeflash when it is missing, unauthenticated, or unconfigured. This skill is typically invoked as a fallback when running codeflash fails. |
| 11 | + |
| 12 | +## Workflow |
| 13 | + |
| 14 | +Run the following diagnostic checks and fix only the ones that fail. |
| 15 | + |
| 16 | +### Check 1: Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +which codeflash |
| 20 | +``` |
| 21 | + |
| 22 | +If this fails, codeflash is not installed. Detect the project's package manager and install accordingly: |
| 23 | + |
| 24 | +- If a `uv.lock` file exists or `pyproject.toml` uses `[tool.uv]`: run `uv add --dev codeflash` |
| 25 | +- Otherwise: run `pip install codeflash` |
| 26 | + |
| 27 | +**Never** use `uv tool install` to install codeflash. |
| 28 | + |
| 29 | +### Check 2: Authentication |
| 30 | + |
| 31 | +```bash |
| 32 | +codeflash auth status |
| 33 | +``` |
| 34 | + |
| 35 | +If this fails, the user is not authenticated. Run `codeflash auth login` interactively. This requires user interaction, so let them know the login flow is starting. |
| 36 | + |
| 37 | +### Check 3: Project Configuration (Python) |
| 38 | + |
| 39 | +```bash |
| 40 | +grep -rq '\[tool\.codeflash\]' $(git rev-parse --show-toplevel)/pyproject.toml 2>/dev/null |
| 41 | +``` |
| 42 | + |
| 43 | +If this fails, the project configuration is missing. Walk upward from the current working directory to the git repository root, looking for a `pyproject.toml`. |
| 44 | + |
| 45 | +- If a `pyproject.toml` exists but lacks `[tool.codeflash]`, run **Configuration Discovery (Python)** below and append the section. |
| 46 | +- If no `pyproject.toml` exists, run **Configuration Discovery (Python)** and create one at the git repository root. |
| 47 | + |
| 48 | +#### Configuration Discovery (Python) |
| 49 | + |
| 50 | +Perform the following discovery steps relative to the directory containing the target `pyproject.toml`: |
| 51 | + |
| 52 | +**Discover module root:** |
| 53 | +Find the relative path to the root of the Python module. The module root is where tests import from. For example, if the module root is `abc/` then tests would import code as `from abc import xyz`. Look for directories containing `__init__.py` files at the top level. Common patterns: `src/package_name/`, `package_name/`, or the project root itself. |
| 54 | + |
| 55 | +**Discover tests folder:** |
| 56 | +Find the relative path to the tests directory. Look for: |
| 57 | +1. Existing directories named `tests` or `test` |
| 58 | +2. Folders containing files matching `test_*.py` |
| 59 | +If no tests directory exists, default to `tests`. |
| 60 | + |
| 61 | +**Write the configuration:** |
| 62 | +Append the `[tool.codeflash]` section to the target `pyproject.toml`. Use exactly this format: |
| 63 | + |
| 64 | +```toml |
| 65 | +[tool.codeflash] |
| 66 | +# All paths are relative to this pyproject.toml's directory. |
| 67 | +module-root = "<discovered module root>" |
| 68 | +tests-root = "<discovered tests folder>" |
| 69 | +ignore-paths = ["dist", "**/node_modules", "**/__tests__"] |
| 70 | +formatter-cmds = ["disabled"] |
| 71 | +``` |
| 72 | + |
| 73 | +After writing, confirm the configuration with the user before proceeding. |
| 74 | + |
| 75 | +### Check 3: Project Configuration (Javascript/Typescript) |
| 76 | + |
| 77 | +```bash |
| 78 | +grep -rq 'codeflash' $(git rev-parse --show-toplevel)/package.json 2>/dev/null |
| 79 | +``` |
| 80 | + |
| 81 | +If this fails, the project configuration is missing. Walk upward from the current working directory to the git repository root, looking for a `package.json`. |
| 82 | + |
| 83 | +- If a `package.json` exists but lacks the `codeflash` key, run **Configuration Discovery (Javascript/Typescript)** below and append the section. |
| 84 | +- If no `package.json` exists, run **Configuration Discovery (Javascript/Typescript)** and create one at the git repository root. |
| 85 | + |
| 86 | +#### Configuration Discovery (Javascript/Typescript) |
| 87 | + |
| 88 | +Perform the following discovery steps relative to the directory containing the target `package.json`: |
| 89 | + |
| 90 | +**Discover module root:** |
| 91 | +Find the relative path to the root of the source code. The module root is where the main application or library code lives. Look for the `main`, `module`, or `exports` fields in `package.json` for hints. Common patterns: `src/`, `lib/`, `dist/` (for compiled output — prefer the source directory), or the project root itself. If a `tsconfig.json` exists, check its `rootDir` or `include` fields for guidance. |
| 92 | + |
| 93 | +**Discover tests folder:** |
| 94 | +Find the relative path to the tests directory. Look for: |
| 95 | +1. Existing directories named `tests`, `test`, `__tests__`, or `spec` |
| 96 | +2. Folders containing files matching `*.test.ts`, `*.test.js`, `*.spec.ts`, `*.spec.js` |
| 97 | +3. Test runner configuration in `package.json` (e.g., `jest.testMatch`, `jest.roots`) or config files (`jest.config.*`, `vitest.config.*`) |
| 98 | +If no tests directory exists, default to `tests`. |
| 99 | + |
| 100 | +**Write the configuration:** |
| 101 | +Add a `codeflash` key to the target `package.json`. Use exactly this format: |
| 102 | + |
| 103 | +```json |
| 104 | +{ |
| 105 | + "codeflash": { |
| 106 | + "moduleRoot": "<discovered module root>", |
| 107 | + "testsRoot": "<discovered tests folder>", |
| 108 | + "ignorePaths": [], |
| 109 | + "formatterCmds": ["disabled"] |
| 110 | + } |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +Merge this into the existing `package.json` object — do not overwrite other fields. After writing, confirm the configuration with the user before proceeding. |
| 115 | + |
| 116 | +## Permissions Setup |
| 117 | + |
| 118 | +1. Check if `.claude/settings.json` exists in the project root (use `git rev-parse --show-toplevel` to find it). |
| 119 | + |
| 120 | +2. If the file exists, read it and check if `Bash(*codeflash*)` is already in `permissions.allow`. |
| 121 | + |
| 122 | +3. If already configured, tell the user: "Codeflash is already configured to run automatically. No changes needed." |
| 123 | + |
| 124 | +4. If not configured, add `Bash(*codeflash*)` to the `permissions.allow` array in `.claude/settings.json`. Create the file and any necessary parent directories if they don't exist. Preserve any existing settings. |
| 125 | + |
| 126 | +5. Confirm to the user what was added and explain: "Codeflash will now run automatically in the background after commits that change code files, without prompting for permission each time." |
| 127 | + |
| 128 | +## After Setup |
| 129 | + |
| 130 | +Once all checks pass, inform the user that codeflash is ready, and they can retry their optimization. |
0 commit comments