antigravity-auth 1.6.0
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 +61 -0
- package/dist/antigravity/oauth.d.ts +30 -0
- package/dist/antigravity/oauth.js +170 -0
- package/dist/claude/login.d.ts +7 -0
- package/dist/claude/login.js +480 -0
- package/dist/claude/menu-helpers.d.ts +22 -0
- package/dist/claude/menu-helpers.js +281 -0
- package/dist/claude/proxy-manager.d.ts +11 -0
- package/dist/claude/proxy-manager.js +129 -0
- package/dist/claude/proxy.d.ts +1 -0
- package/dist/claude/proxy.js +733 -0
- package/dist/constants.d.ts +138 -0
- package/dist/constants.js +216 -0
- package/dist/hooks/auto-update-checker/cache.d.ts +2 -0
- package/dist/hooks/auto-update-checker/cache.js +70 -0
- package/dist/hooks/auto-update-checker/checker.d.ts +15 -0
- package/dist/hooks/auto-update-checker/checker.js +233 -0
- package/dist/hooks/auto-update-checker/constants.d.ts +8 -0
- package/dist/hooks/auto-update-checker/constants.js +22 -0
- package/dist/hooks/auto-update-checker/index.d.ts +33 -0
- package/dist/hooks/auto-update-checker/index.js +121 -0
- package/dist/hooks/auto-update-checker/logging.d.ts +2 -0
- package/dist/hooks/auto-update-checker/logging.js +8 -0
- package/dist/hooks/auto-update-checker/types.d.ts +24 -0
- package/dist/hooks/auto-update-checker/types.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/opencode/hooks/auto-update-checker/cache.d.ts +2 -0
- package/dist/opencode/hooks/auto-update-checker/cache.js +70 -0
- package/dist/opencode/hooks/auto-update-checker/checker.d.ts +15 -0
- package/dist/opencode/hooks/auto-update-checker/checker.js +233 -0
- package/dist/opencode/hooks/auto-update-checker/constants.d.ts +8 -0
- package/dist/opencode/hooks/auto-update-checker/constants.js +22 -0
- package/dist/opencode/hooks/auto-update-checker/index.d.ts +33 -0
- package/dist/opencode/hooks/auto-update-checker/index.js +121 -0
- package/dist/opencode/hooks/auto-update-checker/logging.d.ts +2 -0
- package/dist/opencode/hooks/auto-update-checker/logging.js +8 -0
- package/dist/opencode/hooks/auto-update-checker/types.d.ts +24 -0
- package/dist/opencode/hooks/auto-update-checker/types.js +1 -0
- package/dist/opencode/plugin.d.ts +29 -0
- package/dist/opencode/plugin.js +2954 -0
- package/dist/plugin/accounts.d.ts +173 -0
- package/dist/plugin/accounts.js +966 -0
- package/dist/plugin/auth.d.ts +20 -0
- package/dist/plugin/auth.js +44 -0
- package/dist/plugin/cache/index.d.ts +4 -0
- package/dist/plugin/cache/index.js +4 -0
- package/dist/plugin/cache/signature-cache.d.ts +110 -0
- package/dist/plugin/cache/signature-cache.js +347 -0
- package/dist/plugin/cache.d.ts +43 -0
- package/dist/plugin/cache.js +180 -0
- package/dist/plugin/cli.d.ts +26 -0
- package/dist/plugin/cli.js +126 -0
- package/dist/plugin/config/index.d.ts +15 -0
- package/dist/plugin/config/index.js +15 -0
- package/dist/plugin/config/loader.d.ts +38 -0
- package/dist/plugin/config/loader.js +150 -0
- package/dist/plugin/config/models.d.ts +26 -0
- package/dist/plugin/config/models.js +95 -0
- package/dist/plugin/config/schema.d.ts +144 -0
- package/dist/plugin/config/schema.js +458 -0
- package/dist/plugin/config/updater.d.ts +76 -0
- package/dist/plugin/config/updater.js +205 -0
- package/dist/plugin/core/streaming/index.d.ts +2 -0
- package/dist/plugin/core/streaming/index.js +2 -0
- package/dist/plugin/core/streaming/transformer.d.ts +9 -0
- package/dist/plugin/core/streaming/transformer.js +301 -0
- package/dist/plugin/core/streaming/types.d.ts +28 -0
- package/dist/plugin/core/streaming/types.js +1 -0
- package/dist/plugin/debug.d.ts +93 -0
- package/dist/plugin/debug.js +375 -0
- package/dist/plugin/errors.d.ts +27 -0
- package/dist/plugin/errors.js +41 -0
- package/dist/plugin/fingerprint.d.ts +69 -0
- package/dist/plugin/fingerprint.js +137 -0
- package/dist/plugin/image-saver.d.ts +24 -0
- package/dist/plugin/image-saver.js +78 -0
- package/dist/plugin/logger.d.ts +35 -0
- package/dist/plugin/logger.js +67 -0
- package/dist/plugin/logging-utils.d.ts +22 -0
- package/dist/plugin/logging-utils.js +91 -0
- package/dist/plugin/project.d.ts +32 -0
- package/dist/plugin/project.js +229 -0
- package/dist/plugin/quota.d.ts +34 -0
- package/dist/plugin/quota.js +261 -0
- package/dist/plugin/recovery/constants.d.ts +21 -0
- package/dist/plugin/recovery/constants.js +42 -0
- package/dist/plugin/recovery/index.d.ts +11 -0
- package/dist/plugin/recovery/index.js +11 -0
- package/dist/plugin/recovery/storage.d.ts +23 -0
- package/dist/plugin/recovery/storage.js +340 -0
- package/dist/plugin/recovery/types.d.ts +115 -0
- package/dist/plugin/recovery/types.js +6 -0
- package/dist/plugin/recovery.d.ts +60 -0
- package/dist/plugin/recovery.js +360 -0
- package/dist/plugin/refresh-queue.d.ts +99 -0
- package/dist/plugin/refresh-queue.js +235 -0
- package/dist/plugin/request-helpers.d.ts +281 -0
- package/dist/plugin/request-helpers.js +2200 -0
- package/dist/plugin/request.d.ts +110 -0
- package/dist/plugin/request.js +1489 -0
- package/dist/plugin/rotation.d.ts +182 -0
- package/dist/plugin/rotation.js +364 -0
- package/dist/plugin/search.d.ts +31 -0
- package/dist/plugin/search.js +185 -0
- package/dist/plugin/server.d.ts +22 -0
- package/dist/plugin/server.js +306 -0
- package/dist/plugin/storage.d.ts +136 -0
- package/dist/plugin/storage.js +599 -0
- package/dist/plugin/stores/signature-store.d.ts +4 -0
- package/dist/plugin/stores/signature-store.js +24 -0
- package/dist/plugin/thinking-recovery.d.ts +89 -0
- package/dist/plugin/thinking-recovery.js +289 -0
- package/dist/plugin/token.d.ts +18 -0
- package/dist/plugin/token.js +127 -0
- package/dist/plugin/transform/claude.d.ts +79 -0
- package/dist/plugin/transform/claude.js +256 -0
- package/dist/plugin/transform/cross-model-sanitizer.d.ts +34 -0
- package/dist/plugin/transform/cross-model-sanitizer.js +224 -0
- package/dist/plugin/transform/gemini.d.ts +132 -0
- package/dist/plugin/transform/gemini.js +659 -0
- package/dist/plugin/transform/index.d.ts +14 -0
- package/dist/plugin/transform/index.js +9 -0
- package/dist/plugin/transform/model-resolver.d.ts +98 -0
- package/dist/plugin/transform/model-resolver.js +320 -0
- package/dist/plugin/transform/types.d.ts +110 -0
- package/dist/plugin/transform/types.js +1 -0
- package/dist/plugin/types.d.ts +95 -0
- package/dist/plugin/types.js +1 -0
- package/dist/plugin/ui/ansi.d.ts +31 -0
- package/dist/plugin/ui/ansi.js +45 -0
- package/dist/plugin/ui/auth-menu.d.ts +47 -0
- package/dist/plugin/ui/auth-menu.js +199 -0
- package/dist/plugin/ui/confirm.d.ts +1 -0
- package/dist/plugin/ui/confirm.js +14 -0
- package/dist/plugin/ui/select.d.ts +22 -0
- package/dist/plugin/ui/select.js +243 -0
- package/dist/plugin/version.d.ts +18 -0
- package/dist/plugin/version.js +79 -0
- package/dist/src/antigravity/oauth.d.ts +30 -0
- package/dist/src/antigravity/oauth.js +170 -0
- package/dist/src/constants.d.ts +138 -0
- package/dist/src/constants.js +216 -0
- package/dist/src/hooks/auto-update-checker/cache.d.ts +2 -0
- package/dist/src/hooks/auto-update-checker/cache.js +70 -0
- package/dist/src/hooks/auto-update-checker/checker.d.ts +15 -0
- package/dist/src/hooks/auto-update-checker/checker.js +233 -0
- package/dist/src/hooks/auto-update-checker/constants.d.ts +8 -0
- package/dist/src/hooks/auto-update-checker/constants.js +22 -0
- package/dist/src/hooks/auto-update-checker/index.d.ts +33 -0
- package/dist/src/hooks/auto-update-checker/index.js +121 -0
- package/dist/src/hooks/auto-update-checker/logging.d.ts +2 -0
- package/dist/src/hooks/auto-update-checker/logging.js +8 -0
- package/dist/src/hooks/auto-update-checker/types.d.ts +24 -0
- package/dist/src/hooks/auto-update-checker/types.js +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +5 -0
- package/dist/src/plugin/accounts.d.ts +173 -0
- package/dist/src/plugin/accounts.js +966 -0
- package/dist/src/plugin/auth.d.ts +20 -0
- package/dist/src/plugin/auth.js +44 -0
- package/dist/src/plugin/cache/index.d.ts +4 -0
- package/dist/src/plugin/cache/index.js +4 -0
- package/dist/src/plugin/cache/signature-cache.d.ts +110 -0
- package/dist/src/plugin/cache/signature-cache.js +347 -0
- package/dist/src/plugin/cache.d.ts +43 -0
- package/dist/src/plugin/cache.js +180 -0
- package/dist/src/plugin/cli.d.ts +26 -0
- package/dist/src/plugin/cli.js +126 -0
- package/dist/src/plugin/config/index.d.ts +15 -0
- package/dist/src/plugin/config/index.js +15 -0
- package/dist/src/plugin/config/loader.d.ts +38 -0
- package/dist/src/plugin/config/loader.js +150 -0
- package/dist/src/plugin/config/models.d.ts +26 -0
- package/dist/src/plugin/config/models.js +95 -0
- package/dist/src/plugin/config/schema.d.ts +144 -0
- package/dist/src/plugin/config/schema.js +458 -0
- package/dist/src/plugin/config/updater.d.ts +76 -0
- package/dist/src/plugin/config/updater.js +205 -0
- package/dist/src/plugin/core/streaming/index.d.ts +2 -0
- package/dist/src/plugin/core/streaming/index.js +2 -0
- package/dist/src/plugin/core/streaming/transformer.d.ts +9 -0
- package/dist/src/plugin/core/streaming/transformer.js +301 -0
- package/dist/src/plugin/core/streaming/types.d.ts +28 -0
- package/dist/src/plugin/core/streaming/types.js +1 -0
- package/dist/src/plugin/debug.d.ts +93 -0
- package/dist/src/plugin/debug.js +375 -0
- package/dist/src/plugin/errors.d.ts +27 -0
- package/dist/src/plugin/errors.js +41 -0
- package/dist/src/plugin/fingerprint.d.ts +69 -0
- package/dist/src/plugin/fingerprint.js +137 -0
- package/dist/src/plugin/image-saver.d.ts +24 -0
- package/dist/src/plugin/image-saver.js +78 -0
- package/dist/src/plugin/logger.d.ts +35 -0
- package/dist/src/plugin/logger.js +67 -0
- package/dist/src/plugin/logging-utils.d.ts +22 -0
- package/dist/src/plugin/logging-utils.js +91 -0
- package/dist/src/plugin/project.d.ts +32 -0
- package/dist/src/plugin/project.js +229 -0
- package/dist/src/plugin/quota.d.ts +34 -0
- package/dist/src/plugin/quota.js +261 -0
- package/dist/src/plugin/recovery/constants.d.ts +21 -0
- package/dist/src/plugin/recovery/constants.js +42 -0
- package/dist/src/plugin/recovery/index.d.ts +11 -0
- package/dist/src/plugin/recovery/index.js +11 -0
- package/dist/src/plugin/recovery/storage.d.ts +23 -0
- package/dist/src/plugin/recovery/storage.js +340 -0
- package/dist/src/plugin/recovery/types.d.ts +115 -0
- package/dist/src/plugin/recovery/types.js +6 -0
- package/dist/src/plugin/recovery.d.ts +60 -0
- package/dist/src/plugin/recovery.js +360 -0
- package/dist/src/plugin/refresh-queue.d.ts +99 -0
- package/dist/src/plugin/refresh-queue.js +235 -0
- package/dist/src/plugin/request-helpers.d.ts +281 -0
- package/dist/src/plugin/request-helpers.js +2200 -0
- package/dist/src/plugin/request.d.ts +110 -0
- package/dist/src/plugin/request.js +1489 -0
- package/dist/src/plugin/rotation.d.ts +182 -0
- package/dist/src/plugin/rotation.js +364 -0
- package/dist/src/plugin/search.d.ts +31 -0
- package/dist/src/plugin/search.js +185 -0
- package/dist/src/plugin/server.d.ts +22 -0
- package/dist/src/plugin/server.js +306 -0
- package/dist/src/plugin/storage.d.ts +136 -0
- package/dist/src/plugin/storage.js +599 -0
- package/dist/src/plugin/stores/signature-store.d.ts +4 -0
- package/dist/src/plugin/stores/signature-store.js +24 -0
- package/dist/src/plugin/thinking-recovery.d.ts +89 -0
- package/dist/src/plugin/thinking-recovery.js +289 -0
- package/dist/src/plugin/token.d.ts +18 -0
- package/dist/src/plugin/token.js +127 -0
- package/dist/src/plugin/transform/claude.d.ts +79 -0
- package/dist/src/plugin/transform/claude.js +256 -0
- package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +34 -0
- package/dist/src/plugin/transform/cross-model-sanitizer.js +224 -0
- package/dist/src/plugin/transform/gemini.d.ts +132 -0
- package/dist/src/plugin/transform/gemini.js +659 -0
- package/dist/src/plugin/transform/index.d.ts +14 -0
- package/dist/src/plugin/transform/index.js +9 -0
- package/dist/src/plugin/transform/model-resolver.d.ts +98 -0
- package/dist/src/plugin/transform/model-resolver.js +320 -0
- package/dist/src/plugin/transform/types.d.ts +110 -0
- package/dist/src/plugin/transform/types.js +1 -0
- package/dist/src/plugin/types.d.ts +95 -0
- package/dist/src/plugin/types.js +1 -0
- package/dist/src/plugin/ui/ansi.d.ts +31 -0
- package/dist/src/plugin/ui/ansi.js +45 -0
- package/dist/src/plugin/ui/auth-menu.d.ts +47 -0
- package/dist/src/plugin/ui/auth-menu.js +199 -0
- package/dist/src/plugin/ui/confirm.d.ts +1 -0
- package/dist/src/plugin/ui/confirm.js +14 -0
- package/dist/src/plugin/ui/select.d.ts +22 -0
- package/dist/src/plugin/ui/select.js +243 -0
- package/dist/src/plugin/version.d.ts +18 -0
- package/dist/src/plugin/version.js +79 -0
- package/package.json +54 -0
|
@@ -0,0 +1,138 @@
|
|
|
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";
|
|
@@ -0,0 +1,216 @@
|
|
|
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
|
+
`;
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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>;
|
|
@@ -0,0 +1,233 @@
|
|
|
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
|
+
}
|