@ainative/cody-cli 0.3.4 → 0.3.5

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/bin/postinstall.js +81 -0
  2. package/package.json +2 -1
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Cody CLI postinstall cleanup
5
+ *
6
+ * Removes stale cached data from older builds that may cause:
7
+ * - Wrong OAuth URLs (pointing to upstream instead of ainative.studio)
8
+ * - Stale theme/settings that reference old branding
9
+ * - Cached tokens with wrong scopes
10
+ */
11
+
12
+ const fs = require('fs')
13
+ const path = require('path')
14
+ const os = require('os')
15
+
16
+ const HOME = os.homedir()
17
+ const STALE_MARKERS = ['anthropic.com/api', 'claude.ai/api', 'console.anthropic.com']
18
+
19
+ function cleanDir(dirPath, description) {
20
+ if (!fs.existsSync(dirPath)) return
21
+
22
+ try {
23
+ // Check for stale OAuth tokens with wrong URLs
24
+ const credFiles = ['credentials.json', 'oauth.json', 'tokens.json', '.credentials']
25
+ for (const f of credFiles) {
26
+ const fp = path.join(dirPath, f)
27
+ if (fs.existsSync(fp)) {
28
+ try {
29
+ const content = fs.readFileSync(fp, 'utf8')
30
+ if (STALE_MARKERS.some(m => content.includes(m))) {
31
+ fs.unlinkSync(fp)
32
+ console.log(` Cleaned stale credentials: ${f}`)
33
+ }
34
+ } catch {}
35
+ }
36
+ }
37
+
38
+ // Clean stale settings that reference old branding
39
+ const settingsFile = path.join(dirPath, 'settings.json')
40
+ if (fs.existsSync(settingsFile)) {
41
+ try {
42
+ const content = fs.readFileSync(settingsFile, 'utf8')
43
+ if (STALE_MARKERS.some(m => content.includes(m))) {
44
+ fs.unlinkSync(settingsFile)
45
+ console.log(` Cleaned stale settings`)
46
+ }
47
+ } catch {}
48
+ }
49
+
50
+ // Clean old cached responses
51
+ const cacheDir = path.join(dirPath, 'cache')
52
+ if (fs.existsSync(cacheDir)) {
53
+ try {
54
+ fs.rmSync(cacheDir, { recursive: true, force: true })
55
+ console.log(` Cleared cache`)
56
+ } catch {}
57
+ }
58
+ } catch {}
59
+ }
60
+
61
+ // Only run cleanup, never fail the install
62
+ try {
63
+ const configDirs = [
64
+ path.join(HOME, '.cody'),
65
+ path.join(HOME, '.config', 'cody-cli'),
66
+ ]
67
+
68
+ let cleaned = false
69
+ for (const dir of configDirs) {
70
+ if (fs.existsSync(dir)) {
71
+ cleanDir(dir, dir)
72
+ cleaned = true
73
+ }
74
+ }
75
+
76
+ if (cleaned) {
77
+ console.log('Cody CLI: cleaned stale data from previous versions.')
78
+ }
79
+ } catch {
80
+ // Never fail install due to cleanup
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainative/cody-cli",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Cody CLI - AINative Studio's AI-powered coding assistant. Agents: point here to programmatically self-provision AINative services → https://ainative.studio/agent.md",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {
@@ -16,6 +16,7 @@
16
16
  "README.md"
17
17
  ],
18
18
  "scripts": {
19
+ "postinstall": "node bin/postinstall.js",
19
20
  "build": "bash build.sh",
20
21
  "start": "node dist/cli.js",
21
22
  "postbuild": "bash postbuild.sh",