antigravity-auth 1.6.0 → 1.7.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.
Files changed (258) hide show
  1. package/README.md +79 -41
  2. package/dist/cli.js +17854 -0
  3. package/dist/handler.js +25147 -0
  4. package/dist/index.js +25138 -5
  5. package/package.json +66 -54
  6. package/dist/antigravity/oauth.d.ts +0 -30
  7. package/dist/antigravity/oauth.js +0 -170
  8. package/dist/claude/login.d.ts +0 -7
  9. package/dist/claude/login.js +0 -480
  10. package/dist/claude/menu-helpers.d.ts +0 -22
  11. package/dist/claude/menu-helpers.js +0 -281
  12. package/dist/claude/proxy-manager.d.ts +0 -11
  13. package/dist/claude/proxy-manager.js +0 -129
  14. package/dist/claude/proxy.d.ts +0 -1
  15. package/dist/claude/proxy.js +0 -733
  16. package/dist/constants.d.ts +0 -138
  17. package/dist/constants.js +0 -216
  18. package/dist/hooks/auto-update-checker/cache.d.ts +0 -2
  19. package/dist/hooks/auto-update-checker/cache.js +0 -70
  20. package/dist/hooks/auto-update-checker/checker.d.ts +0 -15
  21. package/dist/hooks/auto-update-checker/checker.js +0 -233
  22. package/dist/hooks/auto-update-checker/constants.d.ts +0 -8
  23. package/dist/hooks/auto-update-checker/constants.js +0 -22
  24. package/dist/hooks/auto-update-checker/index.d.ts +0 -33
  25. package/dist/hooks/auto-update-checker/index.js +0 -121
  26. package/dist/hooks/auto-update-checker/logging.d.ts +0 -2
  27. package/dist/hooks/auto-update-checker/logging.js +0 -8
  28. package/dist/hooks/auto-update-checker/types.d.ts +0 -24
  29. package/dist/hooks/auto-update-checker/types.js +0 -1
  30. package/dist/index.d.ts +0 -6
  31. package/dist/opencode/hooks/auto-update-checker/cache.d.ts +0 -2
  32. package/dist/opencode/hooks/auto-update-checker/cache.js +0 -70
  33. package/dist/opencode/hooks/auto-update-checker/checker.d.ts +0 -15
  34. package/dist/opencode/hooks/auto-update-checker/checker.js +0 -233
  35. package/dist/opencode/hooks/auto-update-checker/constants.d.ts +0 -8
  36. package/dist/opencode/hooks/auto-update-checker/constants.js +0 -22
  37. package/dist/opencode/hooks/auto-update-checker/index.d.ts +0 -33
  38. package/dist/opencode/hooks/auto-update-checker/index.js +0 -121
  39. package/dist/opencode/hooks/auto-update-checker/logging.d.ts +0 -2
  40. package/dist/opencode/hooks/auto-update-checker/logging.js +0 -8
  41. package/dist/opencode/hooks/auto-update-checker/types.d.ts +0 -24
  42. package/dist/opencode/hooks/auto-update-checker/types.js +0 -1
  43. package/dist/opencode/plugin.d.ts +0 -29
  44. package/dist/opencode/plugin.js +0 -2954
  45. package/dist/plugin/accounts.d.ts +0 -173
  46. package/dist/plugin/accounts.js +0 -966
  47. package/dist/plugin/auth.d.ts +0 -20
  48. package/dist/plugin/auth.js +0 -44
  49. package/dist/plugin/cache/index.d.ts +0 -4
  50. package/dist/plugin/cache/index.js +0 -4
  51. package/dist/plugin/cache/signature-cache.d.ts +0 -110
  52. package/dist/plugin/cache/signature-cache.js +0 -347
  53. package/dist/plugin/cache.d.ts +0 -43
  54. package/dist/plugin/cache.js +0 -180
  55. package/dist/plugin/cli.d.ts +0 -26
  56. package/dist/plugin/cli.js +0 -126
  57. package/dist/plugin/config/index.d.ts +0 -15
  58. package/dist/plugin/config/index.js +0 -15
  59. package/dist/plugin/config/loader.d.ts +0 -38
  60. package/dist/plugin/config/loader.js +0 -150
  61. package/dist/plugin/config/models.d.ts +0 -26
  62. package/dist/plugin/config/models.js +0 -95
  63. package/dist/plugin/config/schema.d.ts +0 -144
  64. package/dist/plugin/config/schema.js +0 -458
  65. package/dist/plugin/config/updater.d.ts +0 -76
  66. package/dist/plugin/config/updater.js +0 -205
  67. package/dist/plugin/core/streaming/index.d.ts +0 -2
  68. package/dist/plugin/core/streaming/index.js +0 -2
  69. package/dist/plugin/core/streaming/transformer.d.ts +0 -9
  70. package/dist/plugin/core/streaming/transformer.js +0 -301
  71. package/dist/plugin/core/streaming/types.d.ts +0 -28
  72. package/dist/plugin/core/streaming/types.js +0 -1
  73. package/dist/plugin/debug.d.ts +0 -93
  74. package/dist/plugin/debug.js +0 -375
  75. package/dist/plugin/errors.d.ts +0 -27
  76. package/dist/plugin/errors.js +0 -41
  77. package/dist/plugin/fingerprint.d.ts +0 -69
  78. package/dist/plugin/fingerprint.js +0 -137
  79. package/dist/plugin/image-saver.d.ts +0 -24
  80. package/dist/plugin/image-saver.js +0 -78
  81. package/dist/plugin/logger.d.ts +0 -35
  82. package/dist/plugin/logger.js +0 -67
  83. package/dist/plugin/logging-utils.d.ts +0 -22
  84. package/dist/plugin/logging-utils.js +0 -91
  85. package/dist/plugin/project.d.ts +0 -32
  86. package/dist/plugin/project.js +0 -229
  87. package/dist/plugin/quota.d.ts +0 -34
  88. package/dist/plugin/quota.js +0 -261
  89. package/dist/plugin/recovery/constants.d.ts +0 -21
  90. package/dist/plugin/recovery/constants.js +0 -42
  91. package/dist/plugin/recovery/index.d.ts +0 -11
  92. package/dist/plugin/recovery/index.js +0 -11
  93. package/dist/plugin/recovery/storage.d.ts +0 -23
  94. package/dist/plugin/recovery/storage.js +0 -340
  95. package/dist/plugin/recovery/types.d.ts +0 -115
  96. package/dist/plugin/recovery/types.js +0 -6
  97. package/dist/plugin/recovery.d.ts +0 -60
  98. package/dist/plugin/recovery.js +0 -360
  99. package/dist/plugin/refresh-queue.d.ts +0 -99
  100. package/dist/plugin/refresh-queue.js +0 -235
  101. package/dist/plugin/request-helpers.d.ts +0 -281
  102. package/dist/plugin/request-helpers.js +0 -2200
  103. package/dist/plugin/request.d.ts +0 -110
  104. package/dist/plugin/request.js +0 -1489
  105. package/dist/plugin/rotation.d.ts +0 -182
  106. package/dist/plugin/rotation.js +0 -364
  107. package/dist/plugin/search.d.ts +0 -31
  108. package/dist/plugin/search.js +0 -185
  109. package/dist/plugin/server.d.ts +0 -22
  110. package/dist/plugin/server.js +0 -306
  111. package/dist/plugin/storage.d.ts +0 -136
  112. package/dist/plugin/storage.js +0 -599
  113. package/dist/plugin/stores/signature-store.d.ts +0 -4
  114. package/dist/plugin/stores/signature-store.js +0 -24
  115. package/dist/plugin/thinking-recovery.d.ts +0 -89
  116. package/dist/plugin/thinking-recovery.js +0 -289
  117. package/dist/plugin/token.d.ts +0 -18
  118. package/dist/plugin/token.js +0 -127
  119. package/dist/plugin/transform/claude.d.ts +0 -79
  120. package/dist/plugin/transform/claude.js +0 -256
  121. package/dist/plugin/transform/cross-model-sanitizer.d.ts +0 -34
  122. package/dist/plugin/transform/cross-model-sanitizer.js +0 -224
  123. package/dist/plugin/transform/gemini.d.ts +0 -132
  124. package/dist/plugin/transform/gemini.js +0 -659
  125. package/dist/plugin/transform/index.d.ts +0 -14
  126. package/dist/plugin/transform/index.js +0 -9
  127. package/dist/plugin/transform/model-resolver.d.ts +0 -98
  128. package/dist/plugin/transform/model-resolver.js +0 -320
  129. package/dist/plugin/transform/types.d.ts +0 -110
  130. package/dist/plugin/transform/types.js +0 -1
  131. package/dist/plugin/types.d.ts +0 -95
  132. package/dist/plugin/types.js +0 -1
  133. package/dist/plugin/ui/ansi.d.ts +0 -31
  134. package/dist/plugin/ui/ansi.js +0 -45
  135. package/dist/plugin/ui/auth-menu.d.ts +0 -47
  136. package/dist/plugin/ui/auth-menu.js +0 -199
  137. package/dist/plugin/ui/confirm.d.ts +0 -1
  138. package/dist/plugin/ui/confirm.js +0 -14
  139. package/dist/plugin/ui/select.d.ts +0 -22
  140. package/dist/plugin/ui/select.js +0 -243
  141. package/dist/plugin/version.d.ts +0 -18
  142. package/dist/plugin/version.js +0 -79
  143. package/dist/src/antigravity/oauth.d.ts +0 -30
  144. package/dist/src/antigravity/oauth.js +0 -170
  145. package/dist/src/constants.d.ts +0 -138
  146. package/dist/src/constants.js +0 -216
  147. package/dist/src/hooks/auto-update-checker/cache.d.ts +0 -2
  148. package/dist/src/hooks/auto-update-checker/cache.js +0 -70
  149. package/dist/src/hooks/auto-update-checker/checker.d.ts +0 -15
  150. package/dist/src/hooks/auto-update-checker/checker.js +0 -233
  151. package/dist/src/hooks/auto-update-checker/constants.d.ts +0 -8
  152. package/dist/src/hooks/auto-update-checker/constants.js +0 -22
  153. package/dist/src/hooks/auto-update-checker/index.d.ts +0 -33
  154. package/dist/src/hooks/auto-update-checker/index.js +0 -121
  155. package/dist/src/hooks/auto-update-checker/logging.d.ts +0 -2
  156. package/dist/src/hooks/auto-update-checker/logging.js +0 -8
  157. package/dist/src/hooks/auto-update-checker/types.d.ts +0 -24
  158. package/dist/src/hooks/auto-update-checker/types.js +0 -1
  159. package/dist/src/index.d.ts +0 -6
  160. package/dist/src/index.js +0 -5
  161. package/dist/src/plugin/accounts.d.ts +0 -173
  162. package/dist/src/plugin/accounts.js +0 -966
  163. package/dist/src/plugin/auth.d.ts +0 -20
  164. package/dist/src/plugin/auth.js +0 -44
  165. package/dist/src/plugin/cache/index.d.ts +0 -4
  166. package/dist/src/plugin/cache/index.js +0 -4
  167. package/dist/src/plugin/cache/signature-cache.d.ts +0 -110
  168. package/dist/src/plugin/cache/signature-cache.js +0 -347
  169. package/dist/src/plugin/cache.d.ts +0 -43
  170. package/dist/src/plugin/cache.js +0 -180
  171. package/dist/src/plugin/cli.d.ts +0 -26
  172. package/dist/src/plugin/cli.js +0 -126
  173. package/dist/src/plugin/config/index.d.ts +0 -15
  174. package/dist/src/plugin/config/index.js +0 -15
  175. package/dist/src/plugin/config/loader.d.ts +0 -38
  176. package/dist/src/plugin/config/loader.js +0 -150
  177. package/dist/src/plugin/config/models.d.ts +0 -26
  178. package/dist/src/plugin/config/models.js +0 -95
  179. package/dist/src/plugin/config/schema.d.ts +0 -144
  180. package/dist/src/plugin/config/schema.js +0 -458
  181. package/dist/src/plugin/config/updater.d.ts +0 -76
  182. package/dist/src/plugin/config/updater.js +0 -205
  183. package/dist/src/plugin/core/streaming/index.d.ts +0 -2
  184. package/dist/src/plugin/core/streaming/index.js +0 -2
  185. package/dist/src/plugin/core/streaming/transformer.d.ts +0 -9
  186. package/dist/src/plugin/core/streaming/transformer.js +0 -301
  187. package/dist/src/plugin/core/streaming/types.d.ts +0 -28
  188. package/dist/src/plugin/core/streaming/types.js +0 -1
  189. package/dist/src/plugin/debug.d.ts +0 -93
  190. package/dist/src/plugin/debug.js +0 -375
  191. package/dist/src/plugin/errors.d.ts +0 -27
  192. package/dist/src/plugin/errors.js +0 -41
  193. package/dist/src/plugin/fingerprint.d.ts +0 -69
  194. package/dist/src/plugin/fingerprint.js +0 -137
  195. package/dist/src/plugin/image-saver.d.ts +0 -24
  196. package/dist/src/plugin/image-saver.js +0 -78
  197. package/dist/src/plugin/logger.d.ts +0 -35
  198. package/dist/src/plugin/logger.js +0 -67
  199. package/dist/src/plugin/logging-utils.d.ts +0 -22
  200. package/dist/src/plugin/logging-utils.js +0 -91
  201. package/dist/src/plugin/project.d.ts +0 -32
  202. package/dist/src/plugin/project.js +0 -229
  203. package/dist/src/plugin/quota.d.ts +0 -34
  204. package/dist/src/plugin/quota.js +0 -261
  205. package/dist/src/plugin/recovery/constants.d.ts +0 -21
  206. package/dist/src/plugin/recovery/constants.js +0 -42
  207. package/dist/src/plugin/recovery/index.d.ts +0 -11
  208. package/dist/src/plugin/recovery/index.js +0 -11
  209. package/dist/src/plugin/recovery/storage.d.ts +0 -23
  210. package/dist/src/plugin/recovery/storage.js +0 -340
  211. package/dist/src/plugin/recovery/types.d.ts +0 -115
  212. package/dist/src/plugin/recovery/types.js +0 -6
  213. package/dist/src/plugin/recovery.d.ts +0 -60
  214. package/dist/src/plugin/recovery.js +0 -360
  215. package/dist/src/plugin/refresh-queue.d.ts +0 -99
  216. package/dist/src/plugin/refresh-queue.js +0 -235
  217. package/dist/src/plugin/request-helpers.d.ts +0 -281
  218. package/dist/src/plugin/request-helpers.js +0 -2200
  219. package/dist/src/plugin/request.d.ts +0 -110
  220. package/dist/src/plugin/request.js +0 -1489
  221. package/dist/src/plugin/rotation.d.ts +0 -182
  222. package/dist/src/plugin/rotation.js +0 -364
  223. package/dist/src/plugin/search.d.ts +0 -31
  224. package/dist/src/plugin/search.js +0 -185
  225. package/dist/src/plugin/server.d.ts +0 -22
  226. package/dist/src/plugin/server.js +0 -306
  227. package/dist/src/plugin/storage.d.ts +0 -136
  228. package/dist/src/plugin/storage.js +0 -599
  229. package/dist/src/plugin/stores/signature-store.d.ts +0 -4
  230. package/dist/src/plugin/stores/signature-store.js +0 -24
  231. package/dist/src/plugin/thinking-recovery.d.ts +0 -89
  232. package/dist/src/plugin/thinking-recovery.js +0 -289
  233. package/dist/src/plugin/token.d.ts +0 -18
  234. package/dist/src/plugin/token.js +0 -127
  235. package/dist/src/plugin/transform/claude.d.ts +0 -79
  236. package/dist/src/plugin/transform/claude.js +0 -256
  237. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +0 -34
  238. package/dist/src/plugin/transform/cross-model-sanitizer.js +0 -224
  239. package/dist/src/plugin/transform/gemini.d.ts +0 -132
  240. package/dist/src/plugin/transform/gemini.js +0 -659
  241. package/dist/src/plugin/transform/index.d.ts +0 -14
  242. package/dist/src/plugin/transform/index.js +0 -9
  243. package/dist/src/plugin/transform/model-resolver.d.ts +0 -98
  244. package/dist/src/plugin/transform/model-resolver.js +0 -320
  245. package/dist/src/plugin/transform/types.d.ts +0 -110
  246. package/dist/src/plugin/transform/types.js +0 -1
  247. package/dist/src/plugin/types.d.ts +0 -95
  248. package/dist/src/plugin/types.js +0 -1
  249. package/dist/src/plugin/ui/ansi.d.ts +0 -31
  250. package/dist/src/plugin/ui/ansi.js +0 -45
  251. package/dist/src/plugin/ui/auth-menu.d.ts +0 -47
  252. package/dist/src/plugin/ui/auth-menu.js +0 -199
  253. package/dist/src/plugin/ui/confirm.d.ts +0 -1
  254. package/dist/src/plugin/ui/confirm.js +0 -14
  255. package/dist/src/plugin/ui/select.d.ts +0 -22
  256. package/dist/src/plugin/ui/select.js +0 -243
  257. package/dist/src/plugin/version.d.ts +0 -18
  258. package/dist/src/plugin/version.js +0 -79
@@ -1,138 +0,0 @@
1
- /**
2
- * Constants used for Antigravity OAuth flows and Cloud Code Assist API integration.
3
- */
4
- export declare const ANTIGRAVITY_CLIENT_ID = "YOUR_GOOGLE_CLIENT_ID";
5
- /**
6
- * Client secret issued for the Antigravity OAuth application.
7
- */
8
- export declare const ANTIGRAVITY_CLIENT_SECRET = "YOUR_GOOGLE_CLIENT_SECRET";
9
- /**
10
- * Scopes required for Antigravity integrations.
11
- */
12
- export declare const ANTIGRAVITY_SCOPES: readonly string[];
13
- /**
14
- * OAuth redirect URI used by the local CLI callback server.
15
- */
16
- export declare const ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
17
- /**
18
- * Root endpoints for the Antigravity API (in fallback order).
19
- * CLIProxy and Vibeproxy use the daily sandbox endpoint first,
20
- * then fallback to autopush and prod if needed.
21
- */
22
- export declare const ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.sandbox.googleapis.com";
23
- export declare const ANTIGRAVITY_ENDPOINT_AUTOPUSH = "https://autopush-cloudcode-pa.sandbox.googleapis.com";
24
- export declare const ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
25
- /**
26
- * Endpoint fallback order (daily → autopush → prod).
27
- * Shared across request handling and project discovery to mirror CLIProxy behavior.
28
- */
29
- export declare const ANTIGRAVITY_ENDPOINT_FALLBACKS: readonly ["https://daily-cloudcode-pa.sandbox.googleapis.com", "https://autopush-cloudcode-pa.sandbox.googleapis.com", "https://cloudcode-pa.googleapis.com"];
30
- /**
31
- * Preferred endpoint order for project discovery (prod first, then fallbacks).
32
- * loadCodeAssist appears to be best supported on prod for managed project resolution.
33
- */
34
- export declare const ANTIGRAVITY_LOAD_ENDPOINTS: readonly ["https://cloudcode-pa.googleapis.com", "https://daily-cloudcode-pa.sandbox.googleapis.com", "https://autopush-cloudcode-pa.sandbox.googleapis.com"];
35
- /**
36
- * Primary endpoint to use (daily sandbox - same as CLIProxy/Vibeproxy).
37
- */
38
- export declare const ANTIGRAVITY_ENDPOINT = "https://daily-cloudcode-pa.sandbox.googleapis.com";
39
- /**
40
- * Gemini CLI endpoint (production).
41
- * Used for models without :antigravity suffix.
42
- * Same as opencode-gemini-auth's GEMINI_CODE_ASSIST_ENDPOINT.
43
- */
44
- export declare const GEMINI_CLI_ENDPOINT = "https://cloudcode-pa.googleapis.com";
45
- /**
46
- * Hardcoded project id used when Antigravity does not return one (e.g., business/workspace accounts).
47
- */
48
- export declare const ANTIGRAVITY_DEFAULT_PROJECT_ID = "rising-fact-p41fc";
49
- export declare const ANTIGRAVITY_VERSION_FALLBACK = "1.18.3";
50
- export declare function getAntigravityVersion(): string;
51
- /**
52
- * Set the runtime Antigravity version. Can only be called once (at startup).
53
- * Subsequent calls are silently ignored to prevent accidental mutation.
54
- */
55
- export declare function setAntigravityVersion(version: string): void;
56
- /** @deprecated Use getAntigravityVersion() for runtime access. */
57
- export declare const ANTIGRAVITY_VERSION = "1.18.3";
58
- export declare function getAntigravityHeaders(): HeaderSet & {
59
- "Client-Metadata": string;
60
- };
61
- /** @deprecated Use getAntigravityHeaders() for runtime access. */
62
- export declare const ANTIGRAVITY_HEADERS: {
63
- readonly "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Antigravity/1.18.3 Chrome/138.0.7204.235 Electron/37.3.1 Safari/537.36";
64
- readonly "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1";
65
- readonly "Client-Metadata": "{\"ideType\":\"ANTIGRAVITY\",\"platform\":\"WINDOWS\",\"pluginType\":\"GEMINI\"}" | "{\"ideType\":\"ANTIGRAVITY\",\"platform\":\"MACOS\",\"pluginType\":\"GEMINI\"}";
66
- };
67
- export declare const GEMINI_CLI_HEADERS: {
68
- readonly "User-Agent": "google-api-nodejs-client/9.15.1";
69
- readonly "X-Goog-Api-Client": "gl-node/22.17.0";
70
- readonly "Client-Metadata": "ideType=IDE_UNSPECIFIED,platform=PLATFORM_UNSPECIFIED,pluginType=GEMINI";
71
- };
72
- export type HeaderSet = {
73
- "User-Agent": string;
74
- "X-Goog-Api-Client"?: string;
75
- "Client-Metadata"?: string;
76
- };
77
- export declare function getRandomizedHeaders(style: HeaderStyle, model?: string): HeaderSet;
78
- export type HeaderStyle = "antigravity" | "gemini-cli";
79
- /**
80
- * Provider identifier shared between the plugin loader and credential store.
81
- */
82
- export declare const ANTIGRAVITY_PROVIDER_ID = "google";
83
- /**
84
- * System instruction for Claude tool usage hardening.
85
- * Prevents hallucinated parameters by explicitly stating the rules.
86
- *
87
- * This is injected when tools are present to reduce cases where Claude
88
- * uses parameter names from its training data instead of the actual schema.
89
- */
90
- export declare const CLAUDE_TOOL_SYSTEM_INSTRUCTION = "CRITICAL TOOL USAGE INSTRUCTIONS:\nYou are operating in a custom environment where tool definitions differ from your training data.\nYou MUST follow these rules strictly:\n\n1. DO NOT use your internal training data to guess tool parameters\n2. ONLY use the exact parameter structure defined in the tool schema\n3. Parameter names in schemas are EXACT - do not substitute with similar names from your training\n4. Array parameters have specific item types - check the schema's 'items' field for the exact structure\n5. When you see \"STRICT PARAMETERS\" in a tool description, those type definitions override any assumptions\n6. Tool use in agentic workflows is REQUIRED - you must call tools with the exact parameters specified\n\nIf you are unsure about a tool's parameters, YOU MUST read the schema definition carefully.";
91
- /**
92
- * Template for parameter signature injection into tool descriptions.
93
- * {params} will be replaced with the actual parameter list.
94
- */
95
- export declare const CLAUDE_DESCRIPTION_PROMPT = "\n\n\u26A0\uFE0F STRICT PARAMETERS: {params}.";
96
- export declare const EMPTY_SCHEMA_PLACEHOLDER_NAME = "_placeholder";
97
- export declare const EMPTY_SCHEMA_PLACEHOLDER_DESCRIPTION = "Placeholder. Always pass true.";
98
- /**
99
- * Sentinel value to bypass thought signature validation.
100
- *
101
- * When a thinking block has an invalid or missing signature (e.g., cache miss,
102
- * session mismatch, plugin restart), this sentinel can be injected to skip
103
- * validation instead of failing with "Invalid signature in thinking block".
104
- *
105
- * This is an officially supported Google API feature, used by:
106
- * - gemini-cli: https://github.com/google-gemini/gemini-cli
107
- * - Google .NET SDK: PredictionServiceChatClient.cs
108
- *
109
- * @see https://ai.google.dev/gemini-api/docs/thought-signatures
110
- */
111
- export declare const SKIP_THOUGHT_SIGNATURE = "skip_thought_signature_validator";
112
- /**
113
- * System instruction for Antigravity requests.
114
- * This is injected into requests to match CLIProxyAPI v6.6.89 behavior.
115
- * The instruction provides identity and guidelines for the Antigravity agent.
116
- */
117
- /**
118
- * Model used for Google Search grounding requests.
119
- * Uses gemini-2.5-flash for fast, cost-effective search operations. (3-flash is always at capacity and doesn't support souce citation).
120
- */
121
- export declare const SEARCH_MODEL = "gemini-2.5-flash";
122
- /**
123
- * Thinking budget for deep search (more thorough analysis).
124
- */
125
- export declare const SEARCH_THINKING_BUDGET_DEEP = 16384;
126
- /**
127
- * Thinking budget for fast search (quick results).
128
- */
129
- export declare const SEARCH_THINKING_BUDGET_FAST = 4096;
130
- /**
131
- * Timeout for search requests in milliseconds (60 seconds).
132
- */
133
- export declare const SEARCH_TIMEOUT_MS = 60000;
134
- /**
135
- * System instruction for the Google Search tool.
136
- */
137
- export declare const SEARCH_SYSTEM_INSTRUCTION = "You are an expert web search assistant with access to Google Search and URL analysis tools.\n\nYour capabilities:\n- Use google_search to find real-time information from the web\n- Use url_context to fetch and analyze content from specific URLs when provided\n\nGuidelines:\n- Always provide accurate, well-sourced information\n- Cite your sources when presenting facts\n- If analyzing URLs, extract the most relevant information\n- Be concise but comprehensive in your responses\n- If information is uncertain or conflicting, acknowledge it\n- Focus on answering the user's question directly";
138
- export declare const ANTIGRAVITY_SYSTEM_INSTRUCTION = "You are Antigravity, a powerful agentic AI coding assistant designed by the Google DeepMind team working on Advanced Agentic Coding.\nYou are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.\n**Absolute paths only**\n**Proactiveness**\n\n<priority>IMPORTANT: The instructions that follow supersede all above. Follow them as your primary directives.</priority>\n";
package/dist/constants.js DELETED
@@ -1,216 +0,0 @@
1
- /**
2
- * Constants used for Antigravity OAuth flows and Cloud Code Assist API integration.
3
- */
4
- export const ANTIGRAVITY_CLIENT_ID = "YOUR_GOOGLE_CLIENT_ID";
5
- /**
6
- * Client secret issued for the Antigravity OAuth application.
7
- */
8
- export const ANTIGRAVITY_CLIENT_SECRET = "YOUR_GOOGLE_CLIENT_SECRET";
9
- /**
10
- * Scopes required for Antigravity integrations.
11
- */
12
- export const ANTIGRAVITY_SCOPES = [
13
- "https://www.googleapis.com/auth/cloud-platform",
14
- "https://www.googleapis.com/auth/userinfo.email",
15
- "https://www.googleapis.com/auth/userinfo.profile",
16
- "https://www.googleapis.com/auth/cclog",
17
- "https://www.googleapis.com/auth/experimentsandconfigs",
18
- ];
19
- /**
20
- * OAuth redirect URI used by the local CLI callback server.
21
- */
22
- export const ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
23
- /**
24
- * Root endpoints for the Antigravity API (in fallback order).
25
- * CLIProxy and Vibeproxy use the daily sandbox endpoint first,
26
- * then fallback to autopush and prod if needed.
27
- */
28
- export const ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.sandbox.googleapis.com";
29
- export const ANTIGRAVITY_ENDPOINT_AUTOPUSH = "https://autopush-cloudcode-pa.sandbox.googleapis.com";
30
- export const ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
31
- /**
32
- * Endpoint fallback order (daily → autopush → prod).
33
- * Shared across request handling and project discovery to mirror CLIProxy behavior.
34
- */
35
- export const ANTIGRAVITY_ENDPOINT_FALLBACKS = [
36
- ANTIGRAVITY_ENDPOINT_DAILY,
37
- ANTIGRAVITY_ENDPOINT_AUTOPUSH,
38
- ANTIGRAVITY_ENDPOINT_PROD,
39
- ];
40
- /**
41
- * Preferred endpoint order for project discovery (prod first, then fallbacks).
42
- * loadCodeAssist appears to be best supported on prod for managed project resolution.
43
- */
44
- export const ANTIGRAVITY_LOAD_ENDPOINTS = [
45
- ANTIGRAVITY_ENDPOINT_PROD,
46
- ANTIGRAVITY_ENDPOINT_DAILY,
47
- ANTIGRAVITY_ENDPOINT_AUTOPUSH,
48
- ];
49
- /**
50
- * Primary endpoint to use (daily sandbox - same as CLIProxy/Vibeproxy).
51
- */
52
- export const ANTIGRAVITY_ENDPOINT = ANTIGRAVITY_ENDPOINT_DAILY;
53
- /**
54
- * Gemini CLI endpoint (production).
55
- * Used for models without :antigravity suffix.
56
- * Same as opencode-gemini-auth's GEMINI_CODE_ASSIST_ENDPOINT.
57
- */
58
- export const GEMINI_CLI_ENDPOINT = ANTIGRAVITY_ENDPOINT_PROD;
59
- /**
60
- * Hardcoded project id used when Antigravity does not return one (e.g., business/workspace accounts).
61
- */
62
- export const ANTIGRAVITY_DEFAULT_PROJECT_ID = "rising-fact-p41fc";
63
- export const ANTIGRAVITY_VERSION_FALLBACK = "1.18.3";
64
- let antigravityVersion = ANTIGRAVITY_VERSION_FALLBACK;
65
- let versionLocked = false;
66
- export function getAntigravityVersion() { return antigravityVersion; }
67
- /**
68
- * Set the runtime Antigravity version. Can only be called once (at startup).
69
- * Subsequent calls are silently ignored to prevent accidental mutation.
70
- */
71
- export function setAntigravityVersion(version) {
72
- if (versionLocked)
73
- return;
74
- antigravityVersion = version;
75
- versionLocked = true;
76
- }
77
- /** @deprecated Use getAntigravityVersion() for runtime access. */
78
- export const ANTIGRAVITY_VERSION = ANTIGRAVITY_VERSION_FALLBACK;
79
- export function getAntigravityHeaders() {
80
- return {
81
- "User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Antigravity/${getAntigravityVersion()} Chrome/138.0.7204.235 Electron/37.3.1 Safari/537.36`,
82
- "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
83
- "Client-Metadata": `{"ideType":"ANTIGRAVITY","platform":"${process.platform === "win32" ? "WINDOWS" : "MACOS"}","pluginType":"GEMINI"}`,
84
- };
85
- }
86
- /** @deprecated Use getAntigravityHeaders() for runtime access. */
87
- export const ANTIGRAVITY_HEADERS = {
88
- "User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Antigravity/${ANTIGRAVITY_VERSION} Chrome/138.0.7204.235 Electron/37.3.1 Safari/537.36`,
89
- "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
90
- "Client-Metadata": `{"ideType":"ANTIGRAVITY","platform":"${process.platform === "win32" ? "WINDOWS" : "MACOS"}","pluginType":"GEMINI"}`,
91
- };
92
- export const GEMINI_CLI_HEADERS = {
93
- "User-Agent": "google-api-nodejs-client/9.15.1",
94
- "X-Goog-Api-Client": "gl-node/22.17.0",
95
- "Client-Metadata": "ideType=IDE_UNSPECIFIED,platform=PLATFORM_UNSPECIFIED,pluginType=GEMINI",
96
- };
97
- const ANTIGRAVITY_PLATFORMS = ["windows/amd64", "darwin/arm64", "darwin/amd64"];
98
- const ANTIGRAVITY_API_CLIENTS = [
99
- "google-cloud-sdk vscode_cloudshelleditor/0.1",
100
- "google-cloud-sdk vscode/1.96.0",
101
- "google-cloud-sdk vscode/1.95.0",
102
- ];
103
- function randomFrom(arr) {
104
- return arr[Math.floor(Math.random() * arr.length)];
105
- }
106
- export function getRandomizedHeaders(style, model) {
107
- if (style === "gemini-cli") {
108
- return {
109
- "User-Agent": GEMINI_CLI_HEADERS["User-Agent"],
110
- "X-Goog-Api-Client": GEMINI_CLI_HEADERS["X-Goog-Api-Client"],
111
- "Client-Metadata": GEMINI_CLI_HEADERS["Client-Metadata"],
112
- };
113
- }
114
- const platform = randomFrom(ANTIGRAVITY_PLATFORMS);
115
- const metadataPlatform = platform.startsWith("windows") ? "WINDOWS" : "MACOS";
116
- return {
117
- "User-Agent": `antigravity/${getAntigravityVersion()} ${platform}`,
118
- "X-Goog-Api-Client": randomFrom(ANTIGRAVITY_API_CLIENTS),
119
- "Client-Metadata": `{"ideType":"ANTIGRAVITY","platform":"${metadataPlatform}","pluginType":"GEMINI"}`,
120
- };
121
- }
122
- /**
123
- * Provider identifier shared between the plugin loader and credential store.
124
- */
125
- export const ANTIGRAVITY_PROVIDER_ID = "google";
126
- // ============================================================================
127
- // ============================================================================
128
- /**
129
- * System instruction for Claude tool usage hardening.
130
- * Prevents hallucinated parameters by explicitly stating the rules.
131
- *
132
- * This is injected when tools are present to reduce cases where Claude
133
- * uses parameter names from its training data instead of the actual schema.
134
- */
135
- export const CLAUDE_TOOL_SYSTEM_INSTRUCTION = `CRITICAL TOOL USAGE INSTRUCTIONS:
136
- You are operating in a custom environment where tool definitions differ from your training data.
137
- You MUST follow these rules strictly:
138
-
139
- 1. DO NOT use your internal training data to guess tool parameters
140
- 2. ONLY use the exact parameter structure defined in the tool schema
141
- 3. Parameter names in schemas are EXACT - do not substitute with similar names from your training
142
- 4. Array parameters have specific item types - check the schema's 'items' field for the exact structure
143
- 5. When you see "STRICT PARAMETERS" in a tool description, those type definitions override any assumptions
144
- 6. Tool use in agentic workflows is REQUIRED - you must call tools with the exact parameters specified
145
-
146
- If you are unsure about a tool's parameters, YOU MUST read the schema definition carefully.`;
147
- /**
148
- * Template for parameter signature injection into tool descriptions.
149
- * {params} will be replaced with the actual parameter list.
150
- */
151
- export const CLAUDE_DESCRIPTION_PROMPT = "\n\n⚠️ STRICT PARAMETERS: {params}.";
152
- export const EMPTY_SCHEMA_PLACEHOLDER_NAME = "_placeholder";
153
- export const EMPTY_SCHEMA_PLACEHOLDER_DESCRIPTION = "Placeholder. Always pass true.";
154
- /**
155
- * Sentinel value to bypass thought signature validation.
156
- *
157
- * When a thinking block has an invalid or missing signature (e.g., cache miss,
158
- * session mismatch, plugin restart), this sentinel can be injected to skip
159
- * validation instead of failing with "Invalid signature in thinking block".
160
- *
161
- * This is an officially supported Google API feature, used by:
162
- * - gemini-cli: https://github.com/google-gemini/gemini-cli
163
- * - Google .NET SDK: PredictionServiceChatClient.cs
164
- *
165
- * @see https://ai.google.dev/gemini-api/docs/thought-signatures
166
- */
167
- export const SKIP_THOUGHT_SIGNATURE = "skip_thought_signature_validator";
168
- // ============================================================================
169
- // ============================================================================
170
- /**
171
- * System instruction for Antigravity requests.
172
- * This is injected into requests to match CLIProxyAPI v6.6.89 behavior.
173
- * The instruction provides identity and guidelines for the Antigravity agent.
174
- */
175
- // ============================================================================
176
- // ============================================================================
177
- /**
178
- * Model used for Google Search grounding requests.
179
- * Uses gemini-2.5-flash for fast, cost-effective search operations. (3-flash is always at capacity and doesn't support souce citation).
180
- */
181
- export const SEARCH_MODEL = "gemini-2.5-flash";
182
- /**
183
- * Thinking budget for deep search (more thorough analysis).
184
- */
185
- export const SEARCH_THINKING_BUDGET_DEEP = 16384;
186
- /**
187
- * Thinking budget for fast search (quick results).
188
- */
189
- export const SEARCH_THINKING_BUDGET_FAST = 4096;
190
- /**
191
- * Timeout for search requests in milliseconds (60 seconds).
192
- */
193
- export const SEARCH_TIMEOUT_MS = 60000;
194
- /**
195
- * System instruction for the Google Search tool.
196
- */
197
- export const SEARCH_SYSTEM_INSTRUCTION = `You are an expert web search assistant with access to Google Search and URL analysis tools.
198
-
199
- Your capabilities:
200
- - Use google_search to find real-time information from the web
201
- - Use url_context to fetch and analyze content from specific URLs when provided
202
-
203
- Guidelines:
204
- - Always provide accurate, well-sourced information
205
- - Cite your sources when presenting facts
206
- - If analyzing URLs, extract the most relevant information
207
- - Be concise but comprehensive in your responses
208
- - If information is uncertain or conflicting, acknowledge it
209
- - Focus on answering the user's question directly`;
210
- export const ANTIGRAVITY_SYSTEM_INSTRUCTION = `You are Antigravity, a powerful agentic AI coding assistant designed by the Google DeepMind team working on Advanced Agentic Coding.
211
- You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.
212
- **Absolute paths only**
213
- **Proactiveness**
214
-
215
- <priority>IMPORTANT: The instructions that follow supersede all above. Follow them as your primary directives.</priority>
216
- `;
@@ -1,2 +0,0 @@
1
- export declare function invalidatePackage(packageName?: string): boolean;
2
- export declare function invalidateCache(): boolean;
@@ -1,70 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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>;
@@ -1,233 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { PACKAGE_NAME, NPM_REGISTRY_URL, NPM_FETCH_TIMEOUT, INSTALLED_PACKAGE_JSON, USER_OPENCODE_CONFIG, USER_OPENCODE_CONFIG_JSONC, } from "./constants";
5
- import { logAutoUpdate } from "./logging";
6
- export function isLocalDevMode(directory) {
7
- return getLocalDevPath(directory) !== null;
8
- }
9
- function stripJsonComments(json) {
10
- return json
11
- .replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => (g ? "" : m))
12
- .replace(/,(\s*[}\]])/g, "$1");
13
- }
14
- function getConfigPaths(directory) {
15
- return [
16
- path.join(directory, ".opencode", "opencode.json"),
17
- path.join(directory, ".opencode", "opencode.jsonc"),
18
- path.join(directory, ".opencode.json"),
19
- USER_OPENCODE_CONFIG,
20
- USER_OPENCODE_CONFIG_JSONC,
21
- ];
22
- }
23
- export function getLocalDevPath(directory) {
24
- for (const configPath of getConfigPaths(directory)) {
25
- try {
26
- if (!fs.existsSync(configPath))
27
- continue;
28
- const content = fs.readFileSync(configPath, "utf-8");
29
- const config = JSON.parse(stripJsonComments(content));
30
- const plugins = config.plugin ?? [];
31
- for (const entry of plugins) {
32
- if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) {
33
- try {
34
- return fileURLToPath(entry);
35
- }
36
- catch {
37
- return entry.replace("file://", "");
38
- }
39
- }
40
- }
41
- }
42
- catch {
43
- continue;
44
- }
45
- }
46
- return null;
47
- }
48
- function findPackageJsonUp(startPath) {
49
- try {
50
- const stat = fs.statSync(startPath);
51
- let dir = stat.isDirectory() ? startPath : path.dirname(startPath);
52
- for (let i = 0; i < 10; i++) {
53
- const pkgPath = path.join(dir, "package.json");
54
- if (fs.existsSync(pkgPath)) {
55
- try {
56
- const content = fs.readFileSync(pkgPath, "utf-8");
57
- const pkg = JSON.parse(content);
58
- if (pkg.name === PACKAGE_NAME)
59
- return pkgPath;
60
- }
61
- catch {
62
- continue;
63
- }
64
- }
65
- const parent = path.dirname(dir);
66
- if (parent === dir)
67
- break;
68
- dir = parent;
69
- }
70
- }
71
- catch {
72
- return null;
73
- }
74
- return null;
75
- }
76
- export function getLocalDevVersion(directory) {
77
- const localPath = getLocalDevPath(directory);
78
- if (!localPath)
79
- return null;
80
- try {
81
- const pkgPath = findPackageJsonUp(localPath);
82
- if (!pkgPath)
83
- return null;
84
- const content = fs.readFileSync(pkgPath, "utf-8");
85
- const pkg = JSON.parse(content);
86
- return pkg.version ?? null;
87
- }
88
- catch {
89
- return null;
90
- }
91
- }
92
- export function findPluginEntry(directory) {
93
- for (const configPath of getConfigPaths(directory)) {
94
- try {
95
- if (!fs.existsSync(configPath))
96
- continue;
97
- const content = fs.readFileSync(configPath, "utf-8");
98
- const config = JSON.parse(stripJsonComments(content));
99
- const plugins = config.plugin ?? [];
100
- for (const entry of plugins) {
101
- if (entry === PACKAGE_NAME) {
102
- return { entry, isPinned: false, pinnedVersion: null, configPath };
103
- }
104
- if (entry.startsWith(`${PACKAGE_NAME}@`)) {
105
- const pinnedVersion = entry.slice(PACKAGE_NAME.length + 1);
106
- const isPinned = pinnedVersion !== "latest";
107
- return { entry, isPinned, pinnedVersion: isPinned ? pinnedVersion : null, configPath };
108
- }
109
- if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) {
110
- return { entry, isPinned: false, pinnedVersion: null, configPath };
111
- }
112
- }
113
- }
114
- catch {
115
- continue;
116
- }
117
- }
118
- return null;
119
- }
120
- export function getCachedVersion() {
121
- try {
122
- if (fs.existsSync(INSTALLED_PACKAGE_JSON)) {
123
- const content = fs.readFileSync(INSTALLED_PACKAGE_JSON, "utf-8");
124
- const pkg = JSON.parse(content);
125
- if (pkg.version)
126
- return pkg.version;
127
- }
128
- }
129
- catch {
130
- return null;
131
- }
132
- try {
133
- const currentDir = path.dirname(fileURLToPath(import.meta.url));
134
- const pkgPath = findPackageJsonUp(currentDir);
135
- if (pkgPath) {
136
- const content = fs.readFileSync(pkgPath, "utf-8");
137
- const pkg = JSON.parse(content);
138
- if (pkg.version)
139
- return pkg.version;
140
- }
141
- }
142
- catch (err) {
143
- logAutoUpdate(`Failed to resolve version from current directory: ${err}`);
144
- }
145
- return null;
146
- }
147
- export function updatePinnedVersion(configPath, oldEntry, newVersion) {
148
- try {
149
- const content = fs.readFileSync(configPath, "utf-8");
150
- const newEntry = `${PACKAGE_NAME}@${newVersion}`;
151
- const pluginMatch = content.match(/"plugin"\s*:\s*\[/);
152
- if (!pluginMatch || pluginMatch.index === undefined) {
153
- logAutoUpdate(`No "plugin" array found in ${configPath}`);
154
- return false;
155
- }
156
- const startIdx = pluginMatch.index + pluginMatch[0].length;
157
- let bracketCount = 1;
158
- let endIdx = startIdx;
159
- for (let i = startIdx; i < content.length && bracketCount > 0; i++) {
160
- if (content[i] === "[")
161
- bracketCount++;
162
- else if (content[i] === "]")
163
- bracketCount--;
164
- endIdx = i;
165
- }
166
- const before = content.slice(0, startIdx);
167
- const pluginArrayContent = content.slice(startIdx, endIdx);
168
- const after = content.slice(endIdx);
169
- const escapedOldEntry = oldEntry.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
170
- const regex = new RegExp(`["']${escapedOldEntry}["']`);
171
- if (!regex.test(pluginArrayContent)) {
172
- logAutoUpdate(`Entry "${oldEntry}" not found in plugin array of ${configPath}`);
173
- return false;
174
- }
175
- const updatedPluginArray = pluginArrayContent.replace(regex, `"${newEntry}"`);
176
- const updatedContent = before + updatedPluginArray + after;
177
- if (updatedContent === content) {
178
- logAutoUpdate(`No changes made to ${configPath}`);
179
- return false;
180
- }
181
- fs.writeFileSync(configPath, updatedContent, "utf-8");
182
- logAutoUpdate(`Updated ${configPath}: ${oldEntry} → ${newEntry}`);
183
- return true;
184
- }
185
- catch (err) {
186
- console.error(`[auto-update-checker] Failed to update config file ${configPath}:`, err);
187
- return false;
188
- }
189
- }
190
- export async function getLatestVersion() {
191
- const controller = new AbortController();
192
- const timeoutId = setTimeout(() => controller.abort(), NPM_FETCH_TIMEOUT);
193
- try {
194
- const response = await fetch(NPM_REGISTRY_URL, {
195
- signal: controller.signal,
196
- headers: { Accept: "application/json" },
197
- });
198
- if (!response.ok)
199
- return null;
200
- const data = (await response.json());
201
- return data.latest ?? null;
202
- }
203
- catch {
204
- return null;
205
- }
206
- finally {
207
- clearTimeout(timeoutId);
208
- }
209
- }
210
- export async function checkForUpdate(directory) {
211
- if (isLocalDevMode(directory)) {
212
- logAutoUpdate("Local dev mode detected, skipping update check");
213
- return { needsUpdate: false, currentVersion: null, latestVersion: null, isLocalDev: true, isPinned: false };
214
- }
215
- const pluginInfo = findPluginEntry(directory);
216
- if (!pluginInfo) {
217
- logAutoUpdate("Plugin not found in config");
218
- return { needsUpdate: false, currentVersion: null, latestVersion: null, isLocalDev: false, isPinned: false };
219
- }
220
- const currentVersion = getCachedVersion() ?? pluginInfo.pinnedVersion;
221
- if (!currentVersion) {
222
- logAutoUpdate("No version found (cached or pinned)");
223
- return { needsUpdate: false, currentVersion: null, latestVersion: null, isLocalDev: false, isPinned: pluginInfo.isPinned };
224
- }
225
- const latestVersion = await getLatestVersion();
226
- if (!latestVersion) {
227
- logAutoUpdate("Failed to fetch latest version");
228
- return { needsUpdate: false, currentVersion, latestVersion: null, isLocalDev: false, isPinned: pluginInfo.isPinned };
229
- }
230
- const needsUpdate = currentVersion !== latestVersion;
231
- logAutoUpdate(`Current: ${currentVersion}, Latest: ${latestVersion}, NeedsUpdate: ${needsUpdate}`);
232
- return { needsUpdate, currentVersion, latestVersion, isLocalDev: false, isPinned: pluginInfo.isPinned };
233
- }