codebuff 1.0.578 → 1.0.580

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.
Files changed (2) hide show
  1. package/index.js +76 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { spawn } = require('child_process')
4
4
  const fs = require('fs')
5
+ const http = require('http')
5
6
  const https = require('https')
6
7
  const os = require('os')
7
8
  const path = require('path')
@@ -31,6 +32,69 @@ function createConfig(packageName) {
31
32
 
32
33
  const CONFIG = createConfig(packageName)
33
34
 
35
+ function getPostHogConfig() {
36
+ const apiKey =
37
+ process.env.CODEBUFF_POSTHOG_API_KEY ||
38
+ process.env.NEXT_PUBLIC_POSTHOG_API_KEY
39
+ const host =
40
+ process.env.CODEBUFF_POSTHOG_HOST ||
41
+ process.env.NEXT_PUBLIC_POSTHOG_HOST_URL
42
+
43
+ if (!apiKey || !host) {
44
+ return null
45
+ }
46
+
47
+ return { apiKey, host }
48
+ }
49
+
50
+ /**
51
+ * Track update failure event to PostHog.
52
+ * Fire-and-forget - errors are silently ignored.
53
+ */
54
+ function trackUpdateFailed(errorMessage, version, context = {}) {
55
+ try {
56
+ const posthogConfig = getPostHogConfig()
57
+ if (!posthogConfig) {
58
+ return
59
+ }
60
+
61
+ const payload = JSON.stringify({
62
+ api_key: posthogConfig.apiKey,
63
+ event: 'cli.update_codebuff_failed',
64
+ properties: {
65
+ distinct_id: `anonymous-${CONFIG.homeDir}`,
66
+ error: errorMessage,
67
+ version: version || 'unknown',
68
+ platform: process.platform,
69
+ arch: process.arch,
70
+ ...context,
71
+ },
72
+ timestamp: new Date().toISOString(),
73
+ })
74
+
75
+ const parsedUrl = new URL(`${posthogConfig.host}/capture/`)
76
+ const isHttps = parsedUrl.protocol === 'https:'
77
+ const options = {
78
+ hostname: parsedUrl.hostname,
79
+ port: parsedUrl.port || (isHttps ? 443 : 80),
80
+ path: parsedUrl.pathname + parsedUrl.search,
81
+ method: 'POST',
82
+ headers: {
83
+ 'Content-Type': 'application/json',
84
+ 'Content-Length': Buffer.byteLength(payload),
85
+ },
86
+ }
87
+
88
+ const transport = isHttps ? https : http
89
+ const req = transport.request(options)
90
+ req.on('error', () => {}) // Silently ignore errors
91
+ req.write(payload)
92
+ req.end()
93
+ } catch (e) {
94
+ // Silently ignore any tracking errors
95
+ }
96
+ }
97
+
34
98
  const PLATFORM_TARGETS = {
35
99
  'linux-x64': `${packageName}-linux-x64.tar.gz`,
36
100
  'linux-arm64': `${packageName}-linux-arm64.tar.gz`,
@@ -256,7 +320,9 @@ async function downloadBinary(version) {
256
320
  const fileName = PLATFORM_TARGETS[platformKey]
257
321
 
258
322
  if (!fileName) {
259
- throw new Error(`Unsupported platform: ${process.platform} ${process.arch}`)
323
+ const error = new Error(`Unsupported platform: ${process.platform} ${process.arch}`)
324
+ trackUpdateFailed(error.message, version, { stage: 'platform_check' })
325
+ throw error
260
326
  }
261
327
 
262
328
  const downloadUrl = `${
@@ -278,7 +344,9 @@ async function downloadBinary(version) {
278
344
 
279
345
  if (res.statusCode !== 200) {
280
346
  fs.rmSync(CONFIG.tempDownloadDir, { recursive: true })
281
- throw new Error(`Download failed: HTTP ${res.statusCode}`)
347
+ const error = new Error(`Download failed: HTTP ${res.statusCode}`)
348
+ trackUpdateFailed(error.message, version, { stage: 'http_download', statusCode: res.statusCode })
349
+ throw error
282
350
  }
283
351
 
284
352
  const totalSize = parseInt(res.headers['content-length'] || '0', 10)
@@ -318,9 +386,11 @@ async function downloadBinary(version) {
318
386
  if (!fs.existsSync(tempBinaryPath)) {
319
387
  const files = fs.readdirSync(CONFIG.tempDownloadDir)
320
388
  fs.rmSync(CONFIG.tempDownloadDir, { recursive: true })
321
- throw new Error(
389
+ const error = new Error(
322
390
  `Binary not found after extraction. Expected: ${CONFIG.binaryName}, Available files: ${files.join(', ')}`,
323
391
  )
392
+ trackUpdateFailed(error.message, version, { stage: 'extraction' })
393
+ throw error
324
394
  }
325
395
 
326
396
  // Set executable permissions
@@ -334,7 +404,9 @@ async function downloadBinary(version) {
334
404
 
335
405
  if (!smokeTestPassed) {
336
406
  fs.rmSync(CONFIG.tempDownloadDir, { recursive: true })
337
- throw new Error('Downloaded binary failed smoke test (--version check)')
407
+ const error = new Error('Downloaded binary failed smoke test (--version check)')
408
+ trackUpdateFailed(error.message, version, { stage: 'smoke_test' })
409
+ throw error
338
410
  }
339
411
 
340
412
  // Smoke test passed - move binary to final location
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebuff",
3
- "version": "1.0.578",
3
+ "version": "1.0.580",
4
4
  "description": "AI coding agent",
5
5
  "license": "MIT",
6
6
  "bin": {