opencode-antigravity-auth 1.2.0 → 1.2.1
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 +198 -99
- package/dist/src/hooks/auto-update-checker/cache.d.ts +3 -0
- package/dist/src/hooks/auto-update-checker/cache.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/cache.js +71 -0
- package/dist/src/hooks/auto-update-checker/cache.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/checker.d.ts +16 -0
- package/dist/src/hooks/auto-update-checker/checker.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/checker.js +237 -0
- package/dist/src/hooks/auto-update-checker/checker.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/constants.d.ts +9 -0
- package/dist/src/hooks/auto-update-checker/constants.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/constants.js +23 -0
- package/dist/src/hooks/auto-update-checker/constants.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/index.d.ts +34 -0
- package/dist/src/hooks/auto-update-checker/index.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/index.js +121 -0
- package/dist/src/hooks/auto-update-checker/index.js.map +1 -0
- package/dist/src/hooks/auto-update-checker/types.d.ts +25 -0
- package/dist/src/hooks/auto-update-checker/types.d.ts.map +1 -0
- package/dist/src/hooks/auto-update-checker/types.js +1 -0
- package/dist/src/hooks/auto-update-checker/types.js.map +1 -0
- package/dist/src/plugin/accounts.d.ts +21 -10
- package/dist/src/plugin/accounts.d.ts.map +1 -1
- package/dist/src/plugin/accounts.js +101 -55
- package/dist/src/plugin/accounts.js.map +1 -1
- package/dist/src/plugin/debug.d.ts +32 -0
- package/dist/src/plugin/debug.d.ts.map +1 -1
- package/dist/src/plugin/debug.js +140 -12
- package/dist/src/plugin/debug.js.map +1 -1
- package/dist/src/plugin/request.d.ts +3 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +352 -16
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/storage.d.ts +23 -7
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +54 -10
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/types.d.ts +8 -0
- package/dist/src/plugin/types.d.ts.map +1 -1
- package/dist/src/plugin.d.ts +3 -3
- package/dist/src/plugin.d.ts.map +1 -1
- package/dist/src/plugin.js +779 -476
- package/dist/src/plugin.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,132 +15,227 @@ Enable Opencode to authenticate against **Antigravity** (Google's IDE) via OAuth
|
|
|
15
15
|
- **Debug logging** for requests and responses
|
|
16
16
|
- **Drop-in setup** Opencode auto-installs the plugin from config
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Installation
|
|
19
19
|
|
|
20
|
-
###
|
|
20
|
+
### For Humans
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
**Option A: Let an LLM do it for you**
|
|
23
|
+
|
|
24
|
+
Paste this into any LLM agent (Claude Code, OpenCode, Cursor, etc.):
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
Install the opencode-antigravity-auth plugin and add the Antigravity model definitions (see "Available models") to ~/.config/opencode/opencode.json by following: https://raw.githubusercontent.com/NoeFabris/opencode-antigravity-auth/main/README.md
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
If the agent only installs the plugin, ask it to also add models under `provider.google.models`.
|
|
31
|
+
|
|
32
|
+
**Option B: Do it yourself**
|
|
33
|
+
|
|
34
|
+
1. **Add the plugin to your config:**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
mkdir -p ~/.config/opencode
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Create or edit `~/.config/opencode/opencode.json`:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"plugin": ["opencode-antigravity-auth@1.2.1"]
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. **Authenticate:**
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
opencode auth login
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Select **Google** → **OAuth with Google (Antigravity)** → Press Enter to skip Project ID → Sign in via browser.
|
|
55
|
+
|
|
56
|
+
3. **Add models to your config:**
|
|
57
|
+
|
|
58
|
+
Add the models you want to use to the same config file:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"plugin": ["opencode-antigravity-auth@1.2.1"],
|
|
63
|
+
"provider": {
|
|
64
|
+
"google": {
|
|
65
|
+
"models": {
|
|
66
|
+
"gemini-3-pro-high": {
|
|
67
|
+
"name": "Gemini 3 Pro High (Antigravity)",
|
|
68
|
+
"limit": { "context": 1048576, "output": 65535 },
|
|
69
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
70
|
+
},
|
|
71
|
+
"claude-sonnet-4-5": {
|
|
72
|
+
"name": "Claude Sonnet 4.5 (Antigravity)",
|
|
73
|
+
"limit": { "context": 200000, "output": 64000 },
|
|
74
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
> See [Available models](#available-models) for the full list.
|
|
83
|
+
|
|
84
|
+
4. **Use it:**
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
opencode run "Hello" --model=google/gemini-3-pro-high
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### For LLMs
|
|
93
|
+
|
|
94
|
+
<details>
|
|
95
|
+
<summary><b>🤖 Detailed Installation Guide for LLM Agents</b> (click to expand)</summary>
|
|
96
|
+
|
|
97
|
+
If you're an LLM agent helping a user set up this plugin, follow these steps:
|
|
98
|
+
|
|
99
|
+
#### Step 1: Verify OpenCode is installed
|
|
23
100
|
|
|
24
101
|
```bash
|
|
25
|
-
|
|
102
|
+
command -v opencode && opencode --version || echo "OpenCode not installed - see https://opencode.ai/docs"
|
|
26
103
|
```
|
|
27
104
|
|
|
28
|
-
|
|
105
|
+
#### Step 2: Create or update the config
|
|
29
106
|
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
107
|
+
```bash
|
|
108
|
+
mkdir -p ~/.config/opencode
|
|
109
|
+
|
|
110
|
+
if [ -f ~/.config/opencode/opencode.json ]; then
|
|
111
|
+
if command -v jq &> /dev/null; then
|
|
112
|
+
jq '.plugin = ((.plugin // []) + ["opencode-antigravity-auth@1.2.1"] | unique)' \
|
|
113
|
+
~/.config/opencode/opencode.json > /tmp/oc.json && \
|
|
114
|
+
mv /tmp/oc.json ~/.config/opencode/opencode.json
|
|
115
|
+
else
|
|
116
|
+
echo "Add \"opencode-antigravity-auth@1.2.1\" to the plugin array manually"
|
|
117
|
+
fi
|
|
118
|
+
else
|
|
119
|
+
echo '{"plugin":["opencode-antigravity-auth@1.2.1"]}' > ~/.config/opencode/opencode.json
|
|
120
|
+
fi
|
|
34
121
|
```
|
|
35
122
|
|
|
36
|
-
|
|
123
|
+
#### Step 3: Ask user about multi-account setup
|
|
37
124
|
|
|
38
|
-
|
|
125
|
+
Before running `opencode auth login`, ask the user:
|
|
39
126
|
|
|
40
|
-
|
|
127
|
+
> **Do you want to add multiple Google accounts for load balancing?**
|
|
128
|
+
> - Adding 2-10 accounts maximizes rate limits and provides automatic failover
|
|
129
|
+
> - You can always add more accounts later
|
|
130
|
+
|
|
131
|
+
Based on their answer:
|
|
132
|
+
- **Yes, multiple accounts** → After first login, prompt: "Sign in complete. Add another account? (up to 10 supported)"
|
|
133
|
+
- **No, just one** → Single account is fine, they can add more later with `opencode auth login`
|
|
134
|
+
|
|
135
|
+
#### Step 4: Run authentication
|
|
136
|
+
|
|
137
|
+
Tell the user to run:
|
|
41
138
|
|
|
42
139
|
```bash
|
|
43
140
|
opencode auth login
|
|
44
141
|
```
|
|
45
142
|
|
|
143
|
+
Guide them through the prompts:
|
|
46
144
|
1. Select **Google** as the provider
|
|
47
145
|
2. Select **OAuth with Google (Antigravity)**
|
|
48
|
-
3. **Project ID prompt
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
146
|
+
3. **Project ID prompt** → Tell user: "Press Enter to skip (most users don't need this)"
|
|
147
|
+
4. Browser opens for Google sign-in
|
|
148
|
+
5. If multi-account: repeat for additional accounts, or press Enter to finish
|
|
149
|
+
|
|
150
|
+
#### Step 5: Add models to config
|
|
151
|
+
|
|
152
|
+
Merge model definitions into the user's config file (`~/.config/opencode/opencode.json`):
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# If jq is available, merge models programmatically
|
|
156
|
+
if command -v jq &> /dev/null; then
|
|
157
|
+
jq '.provider.google.models = {
|
|
158
|
+
"gemini-3-pro-high": {"name": "Gemini 3 Pro High (Antigravity)", "limit": {"context": 1048576, "output": 65535}, "modalities": {"input": ["text", "image", "pdf"], "output": ["text"]}},
|
|
159
|
+
"gemini-3-pro-low": {"name": "Gemini 3 Pro Low (Antigravity)", "limit": {"context": 1048576, "output": 65535}, "modalities": {"input": ["text", "image", "pdf"], "output": ["text"]}},
|
|
160
|
+
"gemini-3-flash": {"name": "Gemini 3 Flash (Antigravity)", "limit": {"context": 1048576, "output": 65536}, "modalities": {"input": ["text", "image", "pdf"], "output": ["text"]}},
|
|
161
|
+
"claude-sonnet-4-5": {"name": "Claude Sonnet 4.5 (Antigravity)", "limit": {"context": 200000, "output": 64000}, "modalities": {"input": ["text", "image", "pdf"], "output": ["text"]}},
|
|
162
|
+
"claude-sonnet-4-5-thinking": {"name": "Claude Sonnet 4.5 Thinking (Antigravity)", "limit": {"context": 200000, "output": 64000}, "modalities": {"input": ["text", "image", "pdf"], "output": ["text"]}},
|
|
163
|
+
"claude-opus-4-5-thinking": {"name": "Claude Opus 4.5 Thinking (Antigravity)", "limit": {"context": 200000, "output": 64000}, "modalities": {"input": ["text", "image", "pdf"], "output": ["text"]}},
|
|
164
|
+
"gpt-oss-120b-medium": {"name": "GPT-OSS 120B Medium (Antigravity)", "limit": {"context": 131072, "output": 32768}, "modalities": {"input": ["text", "image", "pdf"], "output": ["text"]}}
|
|
165
|
+
} + (.provider.google.models // {})' ~/.config/opencode/opencode.json > /tmp/oc.json && mv /tmp/oc.json ~/.config/opencode/opencode.json
|
|
166
|
+
fi
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Or edit the file manually and add the models from the [Available models](#available-models) section.
|
|
170
|
+
|
|
171
|
+
#### Step 6: Verify setup
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
opencode run "Hello" --model=google/gemini-3-pro-high
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
If successful, tell the user: **"Setup complete! You can now use Antigravity models in OpenCode."**
|
|
55
178
|
|
|
56
|
-
>
|
|
179
|
+
</details>
|
|
57
180
|
|
|
58
|
-
|
|
181
|
+
---
|
|
59
182
|
|
|
60
|
-
|
|
183
|
+
## Available models
|
|
184
|
+
|
|
185
|
+
Add these models to your `~/.config/opencode/opencode.json` under `provider.google.models`:
|
|
186
|
+
|
|
187
|
+
| Model ID | Description |
|
|
188
|
+
|----------|-------------|
|
|
189
|
+
| `gemini-3-pro-high` | Gemini 3 Pro High |
|
|
190
|
+
| `gemini-3-pro-low` | Gemini 3 Pro Low |
|
|
191
|
+
| `gemini-3-flash` | Gemini 3 Flash |
|
|
192
|
+
| `claude-sonnet-4-5` | Claude Sonnet 4.5 |
|
|
193
|
+
| `claude-sonnet-4-5-thinking` | Claude Sonnet 4.5 with thinking |
|
|
194
|
+
| `claude-opus-4-5-thinking` | Claude Opus 4.5 with thinking |
|
|
195
|
+
| `gpt-oss-120b-medium` | GPT-OSS 120B Medium |
|
|
196
|
+
|
|
197
|
+
<details>
|
|
198
|
+
<summary><b>Full model configuration</b> (click to expand)</summary>
|
|
61
199
|
|
|
62
200
|
```json
|
|
63
201
|
{
|
|
64
|
-
"plugin": ["opencode-antigravity-auth@1.2.0"],
|
|
65
202
|
"provider": {
|
|
66
203
|
"google": {
|
|
67
204
|
"models": {
|
|
68
205
|
"gemini-3-pro-high": {
|
|
69
206
|
"name": "Gemini 3 Pro High (Antigravity)",
|
|
70
|
-
"limit": {
|
|
71
|
-
|
|
72
|
-
"output": 65535
|
|
73
|
-
},
|
|
74
|
-
"modalities": {
|
|
75
|
-
"input": ["text", "image", "pdf"],
|
|
76
|
-
"output": ["text"]
|
|
77
|
-
}
|
|
207
|
+
"limit": { "context": 1048576, "output": 65535 },
|
|
208
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
78
209
|
},
|
|
79
210
|
"gemini-3-pro-low": {
|
|
80
211
|
"name": "Gemini 3 Pro Low (Antigravity)",
|
|
81
|
-
"limit": {
|
|
82
|
-
|
|
83
|
-
"output": 65535
|
|
84
|
-
},
|
|
85
|
-
"modalities": {
|
|
86
|
-
"input": ["text", "image", "pdf"],
|
|
87
|
-
"output": ["text"]
|
|
88
|
-
}
|
|
212
|
+
"limit": { "context": 1048576, "output": 65535 },
|
|
213
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
89
214
|
},
|
|
90
215
|
"gemini-3-flash": {
|
|
91
216
|
"name": "Gemini 3 Flash (Antigravity)",
|
|
92
|
-
"limit": {
|
|
93
|
-
|
|
94
|
-
"output": 65536
|
|
95
|
-
},
|
|
96
|
-
"modalities": {
|
|
97
|
-
"input": ["text", "image", "pdf"],
|
|
98
|
-
"output": ["text"]
|
|
99
|
-
}
|
|
217
|
+
"limit": { "context": 1048576, "output": 65536 },
|
|
218
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
100
219
|
},
|
|
101
220
|
"claude-sonnet-4-5": {
|
|
102
221
|
"name": "Claude Sonnet 4.5 (Antigravity)",
|
|
103
|
-
"limit": {
|
|
104
|
-
|
|
105
|
-
"output": 64000
|
|
106
|
-
},
|
|
107
|
-
"modalities": {
|
|
108
|
-
"input": ["text", "image", "pdf"],
|
|
109
|
-
"output": ["text"]
|
|
110
|
-
}
|
|
222
|
+
"limit": { "context": 200000, "output": 64000 },
|
|
223
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
111
224
|
},
|
|
112
225
|
"claude-sonnet-4-5-thinking": {
|
|
113
226
|
"name": "Claude Sonnet 4.5 Thinking (Antigravity)",
|
|
114
|
-
"limit": {
|
|
115
|
-
|
|
116
|
-
"output": 64000
|
|
117
|
-
},
|
|
118
|
-
"modalities": {
|
|
119
|
-
"input": ["text", "image", "pdf"],
|
|
120
|
-
"output": ["text"]
|
|
121
|
-
}
|
|
227
|
+
"limit": { "context": 200000, "output": 64000 },
|
|
228
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
122
229
|
},
|
|
123
230
|
"claude-opus-4-5-thinking": {
|
|
124
231
|
"name": "Claude Opus 4.5 Thinking (Antigravity)",
|
|
125
|
-
"limit": {
|
|
126
|
-
|
|
127
|
-
"output": 64000
|
|
128
|
-
},
|
|
129
|
-
"modalities": {
|
|
130
|
-
"input": ["text", "image", "pdf"],
|
|
131
|
-
"output": ["text"]
|
|
132
|
-
}
|
|
232
|
+
"limit": { "context": 200000, "output": 64000 },
|
|
233
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
133
234
|
},
|
|
134
235
|
"gpt-oss-120b-medium": {
|
|
135
236
|
"name": "GPT-OSS 120B Medium (Antigravity)",
|
|
136
|
-
"limit": {
|
|
137
|
-
|
|
138
|
-
"output": 32768
|
|
139
|
-
},
|
|
140
|
-
"modalities": {
|
|
141
|
-
"input": ["text", "image", "pdf"],
|
|
142
|
-
"output": ["text"]
|
|
143
|
-
}
|
|
237
|
+
"limit": { "context": 131072, "output": 32768 },
|
|
238
|
+
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
|
|
144
239
|
}
|
|
145
240
|
}
|
|
146
241
|
}
|
|
@@ -148,19 +243,7 @@ Open the **same config file** you created in Step 1 (`~/.config/opencode/opencod
|
|
|
148
243
|
}
|
|
149
244
|
```
|
|
150
245
|
|
|
151
|
-
>
|
|
152
|
-
|
|
153
|
-
### Step 4: Use a model
|
|
154
|
-
|
|
155
|
-
```bash
|
|
156
|
-
opencode run "Hello world" --model=google/gemini-3-pro-high
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Or start the interactive TUI and select a model from the model picker:
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
opencode
|
|
163
|
-
```
|
|
246
|
+
</details>
|
|
164
247
|
|
|
165
248
|
## Multi-account load balancing
|
|
166
249
|
|
|
@@ -168,11 +251,23 @@ The plugin supports multiple Google accounts to maximize rate limits and provide
|
|
|
168
251
|
|
|
169
252
|
### How it works
|
|
170
253
|
|
|
171
|
-
- **
|
|
172
|
-
- **
|
|
173
|
-
- **Smart
|
|
174
|
-
- **
|
|
175
|
-
- **
|
|
254
|
+
- **Sticky account selection:** The plugin sticks to the same account for all requests until it hits a rate limit. This preserves Anthropic's prompt cache, which is organization-scoped.
|
|
255
|
+
- **Per-model-family rate limits:** Rate limits are tracked separately for Claude and Gemini models. If an account is rate-limited for Claude, it can still be used for Gemini requests.
|
|
256
|
+
- **Smart retry threshold:** Short rate limits (≤5s) are retried on the same account to avoid unnecessary switching.
|
|
257
|
+
- **Exponential backoff:** Consecutive rate limits trigger exponential backoff with increasing delays.
|
|
258
|
+
- **Quota-aware messages:** Rate limit toasts show quota reset times when available from the API.
|
|
259
|
+
- **Automatic failover:** On HTTP `429` (rate limit), the plugin automatically switches to the next available account for that model family.
|
|
260
|
+
- **Smart cooldown:** Rate-limited accounts are temporarily cooled down and automatically become available again after the cooldown expires.
|
|
261
|
+
- **Single-account retry:** If you only have one account, the plugin waits for the rate limit to reset and retries automatically.
|
|
262
|
+
- **Debounced notifications:** Toast notifications are debounced to avoid spam during streaming responses.
|
|
263
|
+
|
|
264
|
+
### Quiet mode
|
|
265
|
+
|
|
266
|
+
To suppress account-related toast notifications (useful for streaming/recording):
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
export OPENCODE_ANTIGRAVITY_QUIET=1
|
|
270
|
+
```
|
|
176
271
|
|
|
177
272
|
### Adding accounts
|
|
178
273
|
|
|
@@ -231,13 +326,17 @@ For models like `claude-opus-4-5-thinking`:
|
|
|
231
326
|
|
|
232
327
|
## Debugging
|
|
233
328
|
|
|
234
|
-
Enable
|
|
329
|
+
Enable debug logging via environment variable:
|
|
235
330
|
|
|
236
331
|
```bash
|
|
237
332
|
export OPENCODE_ANTIGRAVITY_DEBUG=1
|
|
238
333
|
```
|
|
239
334
|
|
|
240
|
-
|
|
335
|
+
- **Level 1 (`1` or `true`):** Basic logging of URLs, headers, status codes, and request/response previews.
|
|
336
|
+
- **Level 2 (`2` or `verbose`):** Verbose logging including full request and response bodies (up to 50KB).
|
|
337
|
+
- **TUI Reasoning View:** Debug logs are injected into the model's "thinking/reasoning" blocks in the Opencode TUI (requires thinking-capable models).
|
|
338
|
+
- **Log Files:** Logs are written to `~/.config/opencode/antigravity-logs/antigravity-debug-<timestamp>.log`. Override with `OPENCODE_ANTIGRAVITY_LOG_DIR`.
|
|
339
|
+
- **Auto-Stripping:** Injected debug blocks are automatically stripped from outgoing requests to prevent leaking into conversation history.
|
|
241
340
|
|
|
242
341
|
## Development
|
|
243
342
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../../src/hooks/auto-update-checker/cache.ts"],"names":[],"mappings":"AA+CA,wBAAgB,iBAAiB,CAAC,WAAW,GAAE,MAAqB,GAAG,OAAO,CAsC7E;AAED,wBAAgB,eAAe,IAAI,OAAO,CAGzC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { CACHE_DIR, PACKAGE_NAME } from "./constants";
|
|
4
|
+
function stripTrailingCommas(json) {
|
|
5
|
+
return json.replace(/,(\s*[}\]])/g, "$1");
|
|
6
|
+
}
|
|
7
|
+
function removeFromBunLock(packageName) {
|
|
8
|
+
const lockPath = path.join(CACHE_DIR, "bun.lock");
|
|
9
|
+
if (!fs.existsSync(lockPath))
|
|
10
|
+
return false;
|
|
11
|
+
try {
|
|
12
|
+
const content = fs.readFileSync(lockPath, "utf-8");
|
|
13
|
+
const lock = JSON.parse(stripTrailingCommas(content));
|
|
14
|
+
let modified = false;
|
|
15
|
+
if (lock.workspaces?.[""]?.dependencies?.[packageName]) {
|
|
16
|
+
delete lock.workspaces[""].dependencies[packageName];
|
|
17
|
+
modified = true;
|
|
18
|
+
}
|
|
19
|
+
if (lock.packages?.[packageName]) {
|
|
20
|
+
delete lock.packages[packageName];
|
|
21
|
+
modified = true;
|
|
22
|
+
}
|
|
23
|
+
if (modified) {
|
|
24
|
+
fs.writeFileSync(lockPath, JSON.stringify(lock, null, 2));
|
|
25
|
+
console.log(`[auto-update-checker] Removed from bun.lock: ${packageName}`);
|
|
26
|
+
}
|
|
27
|
+
return modified;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function invalidatePackage(packageName = PACKAGE_NAME) {
|
|
34
|
+
try {
|
|
35
|
+
const pkgDir = path.join(CACHE_DIR, "node_modules", packageName);
|
|
36
|
+
const pkgJsonPath = path.join(CACHE_DIR, "package.json");
|
|
37
|
+
let packageRemoved = false;
|
|
38
|
+
let dependencyRemoved = false;
|
|
39
|
+
let lockRemoved = false;
|
|
40
|
+
if (fs.existsSync(pkgDir)) {
|
|
41
|
+
fs.rmSync(pkgDir, { recursive: true, force: true });
|
|
42
|
+
console.log(`[auto-update-checker] Package removed: ${pkgDir}`);
|
|
43
|
+
packageRemoved = true;
|
|
44
|
+
}
|
|
45
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
46
|
+
const content = fs.readFileSync(pkgJsonPath, "utf-8");
|
|
47
|
+
const pkgJson = JSON.parse(content);
|
|
48
|
+
if (pkgJson.dependencies?.[packageName]) {
|
|
49
|
+
delete pkgJson.dependencies[packageName];
|
|
50
|
+
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
51
|
+
console.log(`[auto-update-checker] Dependency removed from package.json: ${packageName}`);
|
|
52
|
+
dependencyRemoved = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
lockRemoved = removeFromBunLock(packageName);
|
|
56
|
+
if (!packageRemoved && !dependencyRemoved && !lockRemoved) {
|
|
57
|
+
console.log(`[auto-update-checker] Package not found, nothing to invalidate: ${packageName}`);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
console.error("[auto-update-checker] Failed to invalidate package:", err);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function invalidateCache() {
|
|
68
|
+
console.warn("[auto-update-checker] WARNING: invalidateCache is deprecated, use invalidatePackage");
|
|
69
|
+
return invalidatePackage();
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../../src/hooks/auto-update-checker/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAWtD,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAmB;IAC5C,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C9F,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,qDAAqD,EAAE,GAAG,CAAC,CAAC;QAC1E,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,IAAI,CAAC,qFAAqF,CAAC,CAAC;IACpG,OAAO,iBAAiB,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UpdateCheckResult } from "./types";
|
|
2
|
+
export declare function isLocalDevMode(directory: string): boolean;
|
|
3
|
+
export declare function getLocalDevPath(directory: string): string | null;
|
|
4
|
+
export declare function getLocalDevVersion(directory: string): string | null;
|
|
5
|
+
export interface PluginEntryInfo {
|
|
6
|
+
entry: string;
|
|
7
|
+
isPinned: boolean;
|
|
8
|
+
pinnedVersion: string | null;
|
|
9
|
+
configPath: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function findPluginEntry(directory: string): PluginEntryInfo | null;
|
|
12
|
+
export declare function getCachedVersion(): string | null;
|
|
13
|
+
export declare function updatePinnedVersion(configPath: string, oldEntry: string, newVersion: string): boolean;
|
|
14
|
+
export declare function getLatestVersion(): Promise<string | null>;
|
|
15
|
+
export declare function checkForUpdate(directory: string): Promise<UpdateCheckResult>;
|
|
16
|
+
//# sourceMappingURL=checker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../../../src/hooks/auto-update-checker/checker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA4C,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAe3F,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEzD;AAkBD,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuBhE;AA4BD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAanE;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA2BzE;AAED,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAwBhD;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAgDrG;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmB/D;AAED,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA2BlF"}
|