codeflash 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # codeflash
2
+
3
+ AI-powered code optimization for JavaScript and TypeScript.
4
+
5
+ Codeflash automatically optimizes your code for better performance while maintaining correctness.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install -D codeflash
11
+ # or
12
+ yarn add -D codeflash
13
+ # or
14
+ pnpm add -D codeflash
15
+ ```
16
+
17
+ The installation automatically sets up:
18
+ 1. **uv** - Python package manager (if not already installed)
19
+ 2. **codeflash** - Python CLI for code optimization
20
+ 3. **Jest runtime helpers** - Bundled test instrumentation (capture, serializer, comparator)
21
+
22
+ ## Quick Start
23
+
24
+ ```bash
25
+ # Optimize a specific function
26
+ npx codeflash optimize --file src/utils.ts --function fibonacci
27
+
28
+ # Optimize all functions in a file
29
+ npx codeflash optimize --file src/utils.ts
30
+
31
+ # Get help
32
+ npx codeflash --help
33
+ ```
34
+
35
+ ## Requirements
36
+
37
+ - **Node.js** >= 18.0.0
38
+ - **Jest** (for running tests)
39
+ - Internet connection (for AI optimization)
40
+
41
+ ## How It Works
42
+
43
+ 1. **Analyze**: Codeflash analyzes your code and identifies optimization opportunities
44
+ 2. **Test**: Runs your existing tests to capture current behavior
45
+ 3. **Optimize**: Uses AI to generate optimized versions
46
+ 4. **Verify**: Runs tests again to ensure the optimization is correct
47
+ 5. **Benchmark**: Measures performance improvement
48
+
49
+ ## Configuration
50
+
51
+ Create a `codeflash.yaml` in your project root:
52
+
53
+ ```yaml
54
+ module_root: src
55
+ tests_root: tests
56
+ ```
57
+
58
+ ## CI/CD
59
+
60
+ In CI environments, the postinstall script is skipped by default. Run setup manually:
61
+
62
+ ```bash
63
+ npx codeflash-setup
64
+ ```
65
+
66
+ Or set `CODEFLASH_SKIP_POSTINSTALL=false` to enable automatic setup.
67
+
68
+ ## Troubleshooting
69
+
70
+ ### uv not found
71
+
72
+ If you see "uv not found", run the setup script:
73
+
74
+ ```bash
75
+ npx codeflash-setup
76
+ ```
77
+
78
+ Or install uv manually:
79
+
80
+ ```bash
81
+ # macOS/Linux
82
+ curl -LsSf https://astral.sh/uv/install.sh | sh
83
+
84
+ # Windows
85
+ powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
86
+ ```
87
+
88
+ ### codeflash not in PATH
89
+
90
+ After installation, you may need to restart your terminal or run:
91
+
92
+ ```bash
93
+ source ~/.bashrc # or ~/.zshrc
94
+ ```
95
+
96
+ ## Links
97
+
98
+ - [Documentation](https://docs.codeflash.ai)
99
+ - [GitHub](https://github.com/codeflash-ai/codeflash)
100
+ - [Discord](https://discord.gg/codeflash)
101
+
102
+ ## License
103
+
104
+ MIT
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Codeflash Setup Script
5
+ *
6
+ * Run this manually if the postinstall script was skipped (e.g., in CI)
7
+ * or if you need to reinstall the Python CLI.
8
+ *
9
+ * Usage:
10
+ * npx codeflash-setup
11
+ */
12
+
13
+ require('../scripts/postinstall.js');
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Codeflash CLI Entry Point
5
+ *
6
+ * This script is the main entry point for the codeflash CLI when installed via npm.
7
+ * It delegates to the Python codeflash CLI installed via uv.
8
+ *
9
+ * Usage:
10
+ * npx codeflash --help
11
+ * npx codeflash optimize --file src/utils.ts
12
+ */
13
+
14
+ const { spawn, spawnSync } = require('child_process');
15
+ const os = require('os');
16
+ const path = require('path');
17
+ const fs = require('fs');
18
+
19
+ /**
20
+ * Find the uv binary
21
+ */
22
+ function findUv() {
23
+ const homeDir = os.homedir();
24
+ const platform = os.platform();
25
+
26
+ // Check the default uv installation location first
27
+ const uvPath = platform === 'win32'
28
+ ? path.join(homeDir, '.local', 'bin', 'uv.exe')
29
+ : path.join(homeDir, '.local', 'bin', 'uv');
30
+
31
+ if (fs.existsSync(uvPath)) {
32
+ return uvPath;
33
+ }
34
+
35
+ // Try to find uv in PATH by checking if it exists
36
+ try {
37
+ const uvInPath = spawnSync('uv', ['--version'], {
38
+ stdio: 'ignore',
39
+ });
40
+ if (uvInPath.status === 0) {
41
+ return 'uv';
42
+ }
43
+ } catch {
44
+ // uv not in PATH
45
+ }
46
+
47
+ return null;
48
+ }
49
+
50
+ /**
51
+ * Run the codeflash CLI via uv
52
+ */
53
+ function runCodeflash(args) {
54
+ const uvBin = findUv();
55
+
56
+ if (!uvBin) {
57
+ console.error('\x1b[31mError:\x1b[0m uv not found.');
58
+ console.error('');
59
+ console.error('Please run the setup script:');
60
+ console.error(' npx codeflash-setup');
61
+ console.error('');
62
+ console.error('Or install uv manually:');
63
+ console.error(' curl -LsSf https://astral.sh/uv/install.sh | sh');
64
+ process.exit(1);
65
+ }
66
+
67
+ // Use uv tool run to execute codeflash
68
+ const child = spawn(uvBin, ['tool', 'run', 'codeflash', ...args], {
69
+ stdio: 'inherit',
70
+ });
71
+
72
+ child.on('error', (error) => {
73
+ console.error(`\x1b[31mError:\x1b[0m Failed to run codeflash: ${error.message}`);
74
+ process.exit(1);
75
+ });
76
+
77
+ child.on('exit', (code, signal) => {
78
+ if (signal) {
79
+ process.exit(1);
80
+ }
81
+ process.exit(code || 0);
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Show setup instructions
87
+ */
88
+ function showSetupHelp() {
89
+ console.log(`
90
+ \x1b[36m╔════════════════════════════════════════════╗
91
+ ║ Codeflash CLI Setup Required ║
92
+ ╚════════════════════════════════════════════╝\x1b[0m
93
+
94
+ The codeflash Python CLI is not installed.
95
+
96
+ \x1b[33mTo complete setup, run:\x1b[0m
97
+ npx codeflash-setup
98
+
99
+ \x1b[33mOr install manually:\x1b[0m
100
+ curl -LsSf https://astral.sh/uv/install.sh | sh
101
+ uv tool install codeflash
102
+
103
+ \x1b[36mDocumentation:\x1b[0m https://docs.codeflash.ai
104
+ `);
105
+ }
106
+
107
+ // Main
108
+ const args = process.argv.slice(2);
109
+
110
+ // Special case: setup command
111
+ if (args[0] === 'setup' || args[0] === '--setup') {
112
+ require('../scripts/postinstall.js');
113
+ } else {
114
+ // Check if codeflash is installed
115
+ const uvBin = findUv();
116
+ if (uvBin) {
117
+ const check = spawnSync(uvBin, ['tool', 'run', 'codeflash', '--version'], {
118
+ stdio: 'ignore',
119
+ });
120
+
121
+ if (check.status !== 0 && args.length === 0) {
122
+ showSetupHelp();
123
+ process.exit(1);
124
+ }
125
+ } else if (args.length === 0) {
126
+ showSetupHelp();
127
+ process.exit(1);
128
+ }
129
+
130
+ runCodeflash(args);
131
+ }
package/package.json CHANGED
@@ -1,11 +1,76 @@
1
1
  {
2
2
  "name": "codeflash",
3
- "version": "0.0.1",
4
- "description": "",
5
- "main": "index.js",
3
+ "version": "0.1.0",
4
+ "description": "Codeflash - AI-powered code optimization for JavaScript and TypeScript",
5
+ "main": "runtime/index.js",
6
+ "bin": {
7
+ "codeflash": "./bin/codeflash.js",
8
+ "codeflash-setup": "./bin/codeflash-setup.js"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "require": "./runtime/index.js",
16
+ "import": "./runtime/index.js"
17
+ },
18
+ "./capture": {
19
+ "require": "./runtime/capture.js",
20
+ "import": "./runtime/capture.js"
21
+ },
22
+ "./serializer": {
23
+ "require": "./runtime/serializer.js",
24
+ "import": "./runtime/serializer.js"
25
+ },
26
+ "./comparator": {
27
+ "require": "./runtime/comparator.js",
28
+ "import": "./runtime/comparator.js"
29
+ }
30
+ },
6
31
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
32
+ "postinstall": "node scripts/postinstall.js",
33
+ "pack": "npm pack",
34
+ "prepublishOnly": "echo 'Ready to publish'"
35
+ },
36
+ "files": [
37
+ "bin/",
38
+ "scripts/",
39
+ "runtime/"
40
+ ],
41
+ "keywords": [
42
+ "codeflash",
43
+ "optimization",
44
+ "performance",
45
+ "javascript",
46
+ "typescript",
47
+ "ai",
48
+ "cli",
49
+ "jest"
50
+ ],
51
+ "author": "Codeflash AI",
52
+ "license": "MIT",
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "https://github.com/codeflash-ai/codeflash.git",
56
+ "directory": "packages/cli"
57
+ },
58
+ "bugs": {
59
+ "url": "https://github.com/codeflash-ai/codeflash/issues"
60
+ },
61
+ "homepage": "https://codeflash.ai",
62
+ "engines": {
63
+ "node": ">=18.0.0"
64
+ },
65
+ "peerDependencies": {
66
+ "jest": ">=27.0.0"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "jest": {
70
+ "optional": true
71
+ }
8
72
  },
9
- "author": "",
10
- "license": "ISC"
73
+ "optionalDependencies": {
74
+ "better-sqlite3": "^9.0.0"
75
+ }
11
76
  }