clisponsor 1.0.5 → 1.0.7
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/bin/clisponsor.mjs +36 -15
- package/package.json +1 -1
package/bin/clisponsor.mjs
CHANGED
|
@@ -15,6 +15,7 @@ const DEFAULT_SERVE_BASE_URL =
|
|
|
15
15
|
const DEFAULT_BACKEND_BASE_URL = process.env.CLISPONSOR_BACKEND_BASE_URL || "https://backend.clisponsor.com";
|
|
16
16
|
const HOOK_VERSION = "1.0.0";
|
|
17
17
|
const NETWORK_TIMEOUT_MS = 3000;
|
|
18
|
+
const ANTIGRAVITY_EVENTS = ["PreInvocation", "PostInvocation"];
|
|
18
19
|
|
|
19
20
|
function argValue(name) {
|
|
20
21
|
const prefix = `${name}=`;
|
|
@@ -157,15 +158,15 @@ function commandExists(command) {
|
|
|
157
158
|
|
|
158
159
|
function isClisponsorCommand(value) {
|
|
159
160
|
return (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
161
|
+
typeof value === "string" &&
|
|
162
|
+
(value.includes("clisponsor_claude_hook.mjs") ||
|
|
163
|
+
value.includes("clisponsor_gemini_hook.mjs") ||
|
|
164
|
+
value.includes("clisponsor_antigravity_hook.mjs") ||
|
|
165
|
+
value.includes(`${path.sep}.clisponsor${path.sep}`) ||
|
|
166
|
+
value.includes("/.clisponsor/") ||
|
|
167
|
+
value.includes("\\.clisponsor\\"))
|
|
168
|
+
);
|
|
169
|
+
}
|
|
169
170
|
|
|
170
171
|
function isClisponsorHookEntry(entry) {
|
|
171
172
|
if (!isPlainObject(entry)) return false;
|
|
@@ -262,6 +263,29 @@ function removeClaudeCommandHooks(settings) {
|
|
|
262
263
|
return changed;
|
|
263
264
|
}
|
|
264
265
|
|
|
266
|
+
function setAntigravityCommandHooks(settings, hookPath) {
|
|
267
|
+
removeClaudeCommandHooks(settings);
|
|
268
|
+
settings.clisponsor = Object.fromEntries(
|
|
269
|
+
ANTIGRAVITY_EVENTS.map((eventName) => [
|
|
270
|
+
eventName,
|
|
271
|
+
[
|
|
272
|
+
{
|
|
273
|
+
type: "command",
|
|
274
|
+
command: `node ${JSON.stringify(hookPath)} ${eventName}`,
|
|
275
|
+
timeout: 5,
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
]),
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function removeAntigravityCommandHooks(settings) {
|
|
283
|
+
const removedLegacyHooks = removeClaudeCommandHooks(settings);
|
|
284
|
+
const removedNativeHooks = Object.hasOwn(settings, "clisponsor");
|
|
285
|
+
if (removedNativeHooks) delete settings.clisponsor;
|
|
286
|
+
return removedLegacyHooks || removedNativeHooks;
|
|
287
|
+
}
|
|
288
|
+
|
|
265
289
|
async function registerDevice() {
|
|
266
290
|
const email = positionalArg(3);
|
|
267
291
|
if (!email) {
|
|
@@ -386,7 +410,7 @@ import crypto from "node:crypto";
|
|
|
386
410
|
const cfg = JSON.parse(fs.readFileSync(${JSON.stringify(CONFIG_PATH)}, "utf8"));
|
|
387
411
|
const event = process.argv[2] || "BeforeAgent";
|
|
388
412
|
const outputMode = ${JSON.stringify(outputMode)};
|
|
389
|
-
const placements = { SessionStart: "StartSession", PreInvocation: "
|
|
413
|
+
const placements = { SessionStart: "StartSession", PreInvocation: "StartTurn", BeforeAgent: "StartTurn", UserPromptSubmit: "StartTurn", PreToolUse: "StartTurn", AfterAgent: "EndTurn", PostInvocation: "EndTurn", Stop: "EndTurn", StartTurn: "StartTurn" };
|
|
390
414
|
const serveBaseUrl = cfg.serveBaseUrl || cfg.apiBaseUrl;
|
|
391
415
|
function sponsoredLine(line) {
|
|
392
416
|
return "[Sponsored] " + line;
|
|
@@ -462,10 +486,7 @@ function installAntigravity() {
|
|
|
462
486
|
|
|
463
487
|
const hooksPath = path.join(HOME, ".gemini", "config", "hooks.json");
|
|
464
488
|
const hooksConfig = readEditableJson(hooksPath, {});
|
|
465
|
-
|
|
466
|
-
addGeminiCommandHook(hooksConfig, "UserPromptSubmit", "*", `node ${JSON.stringify(hookPath)} UserPromptSubmit`);
|
|
467
|
-
addGeminiCommandHook(hooksConfig, "PostInvocation", "*", `node ${JSON.stringify(hookPath)} PostInvocation`);
|
|
468
|
-
addGeminiCommandHook(hooksConfig, "Stop", "*", `node ${JSON.stringify(hookPath)} Stop`);
|
|
489
|
+
setAntigravityCommandHooks(hooksConfig, hookPath);
|
|
469
490
|
writeJson(hooksPath, hooksConfig);
|
|
470
491
|
console.log(`Updated ${hooksPath}`);
|
|
471
492
|
console.log("Antigravity CLI hook installed.");
|
|
@@ -528,7 +549,7 @@ function uninstallGemini() {
|
|
|
528
549
|
function uninstallAntigravity() {
|
|
529
550
|
const hooksPath = path.join(HOME, ".gemini", "config", "hooks.json");
|
|
530
551
|
const hooksConfig = readEditableJson(hooksPath, {});
|
|
531
|
-
if (
|
|
552
|
+
if (removeAntigravityCommandHooks(hooksConfig)) {
|
|
532
553
|
writeJson(hooksPath, hooksConfig);
|
|
533
554
|
console.log(`Removed CLIsponsor hooks from ${hooksPath}`);
|
|
534
555
|
} else {
|