codecane 1.0.399 → 1.0.401

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/package.json CHANGED
@@ -1,27 +1,37 @@
1
1
  {
2
2
  "name": "codecane",
3
- "version": "1.0.399",
3
+ "version": "1.0.401",
4
4
  "description": "AI coding agent",
5
- "optionalDependencies": {
6
- "codecane-linux-x64": "1.0.399",
7
- "codecane-linux-arm64": "1.0.399",
8
- "codecane-darwin-x64": "1.0.399",
9
- "codecane-darwin-arm64": "1.0.399",
10
- "codecane-win32-x64": "1.0.399"
11
- },
5
+ "license": "MIT",
12
6
  "bin": {
13
- "codecane": "index.js"
7
+ "codecane": "scripts/codebuff-wrapper.js"
14
8
  },
15
9
  "files": [
16
- "index.js"
10
+ "scripts/codebuff-wrapper.js",
11
+ "scripts/download-binary.js",
12
+ "README.md"
13
+ ],
14
+ "os": [
15
+ "darwin",
16
+ "linux",
17
+ "win32"
18
+ ],
19
+ "cpu": [
20
+ "x64",
21
+ "arm64"
17
22
  ],
18
- "license": "MIT",
19
23
  "engines": {
20
24
  "node": ">=16"
21
25
  },
26
+ "dependencies": {
27
+ "tar": "^6.2.0"
28
+ },
22
29
  "repository": {
23
30
  "type": "git",
24
31
  "url": "https://github.com/CodebuffAI/codebuff-community.git"
25
32
  },
26
- "homepage": "https://codebuff.com"
33
+ "homepage": "https://codebuff.com",
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
27
37
  }
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+ const os = require('os')
6
+ const { spawn, execSync } = require('child_process')
7
+
8
+ const homeDir = os.homedir()
9
+ const manicodeDir = path.join(homeDir, '.config', 'manicode')
10
+ const binaryName = process.platform === 'win32' ? 'codebuff.exe' : 'codebuff'
11
+ const binaryPath = path.join(manicodeDir, binaryName)
12
+
13
+ // Check if binary exists
14
+ if (!fs.existsSync(binaryPath)) {
15
+ console.log('šŸ”„ Codebuff binary not found. Downloading...')
16
+
17
+ try {
18
+ // Run the download script synchronously
19
+ const downloadScript = path.join(__dirname, 'download-binary.js')
20
+ execSync(`node "${downloadScript}"`, { stdio: 'inherit' })
21
+ } catch (error) {
22
+ console.error('āŒ Failed to download codebuff binary')
23
+ console.error('Please try running: npm install -g codebuff')
24
+ process.exit(1)
25
+ }
26
+ }
27
+
28
+ // Check if binary is executable (Unix only)
29
+ if (process.platform !== 'win32') {
30
+ try {
31
+ fs.accessSync(binaryPath, fs.constants.X_OK)
32
+ } catch (error) {
33
+ console.error(`āŒ Codebuff binary is not executable: ${binaryPath}`)
34
+ console.error('Please try running: npm install -g codebuff')
35
+ process.exit(1)
36
+ }
37
+ }
38
+
39
+ // Execute the binary with all arguments passed through
40
+ const child = spawn(binaryPath, process.argv.slice(2), {
41
+ stdio: 'inherit',
42
+ cwd: process.cwd()
43
+ })
44
+
45
+ child.on('exit', (code) => {
46
+ process.exit(code || 0)
47
+ })
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env node
2
+
3
+ const https = require('https')
4
+ const fs = require('fs')
5
+ const path = require('path')
6
+ const os = require('os')
7
+ const { platform, arch } = process
8
+
9
+ // Get version from package.json
10
+ const packageJsonPath = path.join(__dirname, '..', 'package.json')
11
+ let version
12
+ try {
13
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
14
+ version = packageJson.version
15
+ } catch (error) {
16
+ console.error('āŒ Could not read package.json version')
17
+ process.exit(1)
18
+ }
19
+
20
+ const targets = {
21
+ 'linux-x64': 'codebuff-linux-x64.tar.gz',
22
+ 'linux-arm64': 'codebuff-linux-arm64.tar.gz',
23
+ 'darwin-x64': 'codebuff-darwin-x64.tar.gz',
24
+ 'darwin-arm64': 'codebuff-darwin-arm64.tar.gz',
25
+ 'win32-x64': 'codebuff-win32-x64.zip'
26
+ }
27
+
28
+ const key = `${platform}-${arch}`
29
+ const file = targets[key]
30
+
31
+ if (!file) {
32
+ console.error(`āŒ Unsupported platform: ${platform} ${arch}`)
33
+ console.error('Supported platforms:', Object.keys(targets).join(', '))
34
+ process.exit(1)
35
+ }
36
+
37
+ const url = `https://github.com/CodebuffAI/codebuff-community/releases/download/v${version}/${file}`
38
+ const homeDir = os.homedir()
39
+ const manicodeDir = path.join(homeDir, '.config', 'manicode')
40
+ const binaryName = platform === 'win32' ? 'codebuff.exe' : 'codebuff'
41
+ const binaryPath = path.join(manicodeDir, binaryName)
42
+
43
+ // Check if binary already exists
44
+ if (fs.existsSync(binaryPath)) {
45
+ console.log('āœ… Binary already exists')
46
+ process.exit(0)
47
+ }
48
+
49
+ // Create .config/manicode directory
50
+ fs.mkdirSync(manicodeDir, { recursive: true })
51
+
52
+ console.log(`ā¬‡ļø Downloading ${file} from GitHub releases...`)
53
+ console.log(`šŸ“ Installing to: ${manicodeDir}`)
54
+
55
+ const request = https.get(url, (res) => {
56
+ if (res.statusCode === 302 || res.statusCode === 301) {
57
+ // Follow redirect
58
+ return https.get(res.headers.location, handleResponse)
59
+ }
60
+ handleResponse(res)
61
+ })
62
+
63
+ request.on('error', (err) => {
64
+ console.error(`āŒ Download failed: ${err.message}`)
65
+ process.exit(1)
66
+ })
67
+
68
+ function handleResponse(res) {
69
+ if (res.statusCode !== 200) {
70
+ console.error(`āŒ Download failed: HTTP ${res.statusCode}`)
71
+ console.error(`URL: ${url}`)
72
+ process.exit(1)
73
+ }
74
+
75
+ const totalSize = parseInt(res.headers['content-length'] || '0', 10)
76
+ let downloadedSize = 0
77
+ let lastProgressTime = Date.now()
78
+
79
+ // Show progress for downloads
80
+ const showProgress = (downloaded, total) => {
81
+ const now = Date.now()
82
+ // Update progress every 100ms to avoid too frequent updates
83
+ if (now - lastProgressTime < 100 && downloaded < total) return
84
+ lastProgressTime = now
85
+
86
+ if (total > 0) {
87
+ const percentage = Math.round((downloaded / total) * 100)
88
+ const downloadedMB = (downloaded / 1024 / 1024).toFixed(1)
89
+ const totalMB = (total / 1024 / 1024).toFixed(1)
90
+ process.stderr.write(`\ršŸ“„ Downloaded ${downloadedMB}MB / ${totalMB}MB (${percentage}%)`)
91
+ } else {
92
+ const downloadedMB = (downloaded / 1024 / 1024).toFixed(1)
93
+ process.stderr.write(`\ršŸ“„ Downloaded ${downloadedMB}MB`)
94
+ }
95
+ }
96
+
97
+ res.on('data', (chunk) => {
98
+ downloadedSize += chunk.length
99
+ showProgress(downloadedSize, totalSize)
100
+ })
101
+
102
+ if (file.endsWith('.zip')) {
103
+ // Handle zip files (Windows)
104
+ const zipPath = path.join(manicodeDir, file)
105
+ const writeStream = fs.createWriteStream(zipPath)
106
+
107
+ res.pipe(writeStream)
108
+
109
+ writeStream.on('finish', () => {
110
+ process.stderr.write('\n') // New line after progress
111
+ console.log('šŸ“¦ Extracting...')
112
+ // Extract zip file
113
+ const { execSync } = require('child_process')
114
+ try {
115
+ execSync(`cd "${manicodeDir}" && unzip -o "${file}"`, { stdio: 'inherit' })
116
+ fs.unlinkSync(zipPath) // Clean up zip file
117
+ console.log('āœ… codebuff installed successfully!')
118
+ } catch (error) {
119
+ console.error('āŒ Failed to extract zip:', error.message)
120
+ process.exit(1)
121
+ }
122
+ })
123
+ } else {
124
+ // Handle tar.gz files (Unix)
125
+ const zlib = require('zlib')
126
+ const tar = require('tar')
127
+
128
+ res.pipe(zlib.createGunzip())
129
+ .pipe(tar.extract({ cwd: manicodeDir }))
130
+ .on('finish', () => {
131
+ process.stderr.write('\n') // New line after progress
132
+ // The extracted binary will have the platform/arch in the name
133
+ const extractedBinaryName = file.replace('.tar.gz', '').replace('.zip', '')
134
+ const finalBinaryName = platform === 'win32' ? 'codebuff.exe' : 'codebuff'
135
+ const extractedBinaryPath = path.join(manicodeDir, extractedBinaryName)
136
+ const finalBinaryPath = path.join(manicodeDir, finalBinaryName)
137
+
138
+ if (fs.existsSync(extractedBinaryPath)) {
139
+ fs.chmodSync(extractedBinaryPath, 0o755)
140
+ // Rename to the standard name
141
+ fs.renameSync(extractedBinaryPath, finalBinaryPath)
142
+ console.log('āœ… codebuff installed successfully!')
143
+ } else {
144
+ console.error(`āŒ Binary not found at ${extractedBinaryPath}`)
145
+ process.exit(1)
146
+ }
147
+ })
148
+ .on('error', (err) => {
149
+ console.error(`āŒ Extraction failed: ${err.message}`)
150
+ process.exit(1)
151
+ })
152
+ }
153
+ }
package/index.js DELETED
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // Runtime loader – picks the platform package that npm just installed.
4
- const { spawn } = require('child_process')
5
-
6
- const triples = {
7
- 'linux-x64': 'codebuff-linux-x64',
8
- 'linux-arm64': 'codebuff-linux-arm64',
9
- 'darwin-x64': 'codebuff-darwin-x64',
10
- 'darwin-arm64': 'codebuff-darwin-arm64',
11
- 'win32-x64': 'codebuff-win32-x64'
12
- }
13
-
14
- const triplet = `${process.platform}-${process.arch}`
15
- const packageName = triples[triplet]
16
-
17
- if (!packageName) {
18
- console.error(
19
- `codebuff: unsupported platform (${triplet}). ` +
20
- `If you're on an exotic CPU/OS, ping us on Discord: https://discord.com/invite/mcWTGjgTj3`
21
- )
22
- process.exit(1)
23
- }
24
-
25
- try {
26
- // Try to resolve the platform-specific package
27
- const binaryName = process.platform === 'win32' ? 'codebuff.exe' : 'codebuff'
28
- const binaryPath = require.resolve(`${packageName}/${binaryName}`)
29
-
30
- // Execute the binary with all arguments passed through
31
- const child = spawn(binaryPath, process.argv.slice(2), {
32
- stdio: 'inherit',
33
- cwd: process.cwd()
34
- })
35
-
36
- child.on('exit', (code) => {
37
- process.exit(code || 0)
38
- })
39
-
40
- child.on('error', (error) => {
41
- console.error(`Failed to execute codebuff: ${error.message}`)
42
- process.exit(1)
43
- })
44
-
45
- } catch (e) {
46
- console.error(
47
- `codebuff: platform package not found (${packageName}). ` +
48
- `This usually means the installation failed. Try reinstalling: npm install -g codebuff`
49
- )
50
- process.exit(1)
51
- }