clisponsor 1.0.2 → 1.0.4

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.
@@ -140,14 +140,15 @@ function commandExists(command) {
140
140
 
141
141
  function isClisponsorCommand(value) {
142
142
  return (
143
- typeof value === "string" &&
144
- (value.includes("clisponsor_claude_hook.mjs") ||
145
- value.includes("clisponsor_gemini_hook.mjs") ||
146
- value.includes(`${path.sep}.clisponsor${path.sep}`) ||
147
- value.includes("/.clisponsor/") ||
148
- value.includes("\\.clisponsor\\"))
149
- );
150
- }
143
+ typeof value === "string" &&
144
+ (value.includes("clisponsor_claude_hook.mjs") ||
145
+ value.includes("clisponsor_gemini_hook.mjs") ||
146
+ value.includes("clisponsor_antigravity_hook.mjs") ||
147
+ value.includes(`${path.sep}.clisponsor${path.sep}`) ||
148
+ value.includes("/.clisponsor/") ||
149
+ value.includes("\\.clisponsor\\"))
150
+ );
151
+ }
151
152
 
152
153
  function isClisponsorHookEntry(entry) {
153
154
  if (!isPlainObject(entry)) return false;
@@ -299,6 +300,11 @@ async function login() {
299
300
  }
300
301
 
301
302
  function installCodex() {
303
+ if (!commandExists("codex")) {
304
+ console.log("Codex CLI not found. To enable CLIsponsor for Codex, install Codex CLI and rerun: npx clisponsor@latest install");
305
+ return;
306
+ }
307
+
302
308
  const pluginRoot = path.join(CONFIG_DIR, "codex-plugin");
303
309
  copyDir(path.join(ROOT, "templates", "codex-plugin"), pluginRoot);
304
310
  patchFile(path.join(pluginRoot, "hooks", "hooks.json"), {
@@ -328,29 +334,23 @@ function installCodex() {
328
334
  },
329
335
  ],
330
336
  });
331
- try {
332
- execFileSync("codex", ["plugin", "marketplace", "add", marketplaceRoot], { stdio: "ignore" });
333
- } catch {}
334
- try {
335
- execFileSync("codex", ["plugin", "add", "clisponsor@clisponsor-local"], { stdio: "ignore" });
336
- console.log("Codex CLI plugin installed.");
337
- } catch {
338
- console.log("Codex CLI plugin staged. After installing Codex CLI, rerun: npx clisponsor install");
339
- }
337
+ execFileSync("codex", ["plugin", "marketplace", "add", marketplaceRoot], { stdio: "ignore" });
338
+ execFileSync("codex", ["plugin", "add", "clisponsor@clisponsor-local"], { stdio: "ignore" });
339
+ console.log("Codex CLI plugin installed.");
340
340
  }
341
341
 
342
342
  function installClaude() {
343
+ if (!commandExists("claude")) {
344
+ console.log("Claude Code CLI not found. To enable CLIsponsor for Claude Code, install Claude Code CLI and rerun: npx clisponsor@latest install");
345
+ return;
346
+ }
347
+
343
348
  const claudeDir = path.join(CONFIG_DIR, "claude");
344
349
  const installedHook = path.join(claudeDir, "clisponsor_claude_hook.mjs");
345
350
  fs.mkdirSync(claudeDir, { recursive: true });
346
351
  fs.copyFileSync(path.join(ROOT, "templates", "claude", "clisponsor_claude_hook.mjs"), installedHook);
347
352
  chmodExecutable(installedHook);
348
353
 
349
- if (!commandExists("claude")) {
350
- console.log("Claude Code CLI hook staged. After installing Claude Code CLI, rerun: npx clisponsor install");
351
- return;
352
- }
353
-
354
354
  const settingsPath = path.join(HOME, ".claude", "settings.json");
355
355
  const settings = readEditableJson(settingsPath, {});
356
356
  addClaudeCommandHook(settings, "SessionStart", `node ${JSON.stringify(installedHook)} SessionStart`);
@@ -361,7 +361,7 @@ function installClaude() {
361
361
  console.log("Claude Code CLI hook installed.");
362
362
  }
363
363
 
364
- function geminiHookSource() {
364
+ function agentHookSource(client) {
365
365
  return `#!/usr/bin/env node
366
366
  import fs from "node:fs";
367
367
  import crypto from "node:crypto";
@@ -369,6 +369,9 @@ const cfg = JSON.parse(fs.readFileSync(${JSON.stringify(CONFIG_PATH)}, "utf8"));
369
369
  const event = process.argv[2] || "BeforeAgent";
370
370
  const placements = { SessionStart: "StartSession", BeforeAgent: "StartTurn", AfterAgent: "EndTurn", StartTurn: "StartTurn" };
371
371
  const serveBaseUrl = cfg.serveBaseUrl || cfg.apiBaseUrl;
372
+ function sponsoredLine(line) {
373
+ return "[Sponsored] " + line;
374
+ }
372
375
  function readStdin() {
373
376
  return new Promise((resolve) => {
374
377
  let data = "";
@@ -380,7 +383,7 @@ await readStdin();
380
383
  try {
381
384
  if (!serveBaseUrl || !cfg.userId || !cfg.deviceCode || !cfg.deviceSecret) process.exit(0);
382
385
  const placement = placements[event] || event;
383
- const body = { user_id: cfg.userId, device_code: cfg.deviceCode, client: "Gemini", hook_event: event, placement, idempotency_key: crypto.randomUUID(), metadata: { hookVersion: ${JSON.stringify(HOOK_VERSION)} } };
386
+ const body = { user_id: cfg.userId, device_code: cfg.deviceCode, client: ${JSON.stringify(client)}, hook_event: event, placement, idempotency_key: crypto.randomUUID(), metadata: { hookVersion: ${JSON.stringify(HOOK_VERSION)} } };
384
387
  const res = await fetch(serveBaseUrl + "/v1/ads/serve", {
385
388
  method: "POST",
386
389
  headers: {
@@ -392,7 +395,7 @@ try {
392
395
  });
393
396
  if (res.ok) {
394
397
  const ad = await res.json();
395
- if (ad.display_line) console.log(JSON.stringify({ systemMessage: ad.display_line }));
398
+ if (ad.display_line) console.log(JSON.stringify({ systemMessage: sponsoredLine(ad.display_line) }));
396
399
  }
397
400
  } catch {
398
401
  process.exit(0);
@@ -402,14 +405,14 @@ try {
402
405
 
403
406
  function installGemini() {
404
407
  if (!commandExists("gemini")) {
405
- console.log("Gemini CLI not found. To enable CLIsponsor for Gemini, install Gemini CLI and rerun: npx clisponsor install");
408
+ console.log("Gemini CLI not found. To enable CLIsponsor for Gemini, install Gemini CLI and rerun: npx clisponsor@latest install");
406
409
  return;
407
410
  }
408
411
 
409
412
  const geminiDir = path.join(CONFIG_DIR, "gemini");
410
413
  fs.mkdirSync(geminiDir, { recursive: true });
411
414
  const hookPath = path.join(geminiDir, "clisponsor_gemini_hook.mjs");
412
- fs.writeFileSync(hookPath, geminiHookSource(), { mode: 0o755 });
415
+ fs.writeFileSync(hookPath, agentHookSource("Gemini"), { mode: 0o755 });
413
416
 
414
417
  const settingsPath = path.join(HOME, ".gemini", "settings.json");
415
418
  const settings = readEditableJson(settingsPath, {});
@@ -421,10 +424,45 @@ function installGemini() {
421
424
  console.log("Gemini CLI hook installed.");
422
425
  }
423
426
 
427
+ function installAntigravity() {
428
+ if (!commandExists("agy")) {
429
+ console.log("Antigravity CLI not found. To enable CLIsponsor for Antigravity, install Antigravity CLI and rerun: npx clisponsor@latest install");
430
+ return;
431
+ }
432
+
433
+ const antigravityDir = path.join(CONFIG_DIR, "antigravity");
434
+ fs.mkdirSync(antigravityDir, { recursive: true });
435
+ const hookPath = path.join(antigravityDir, "clisponsor_antigravity_hook.mjs");
436
+ fs.writeFileSync(hookPath, agentHookSource("Antigravity"), { mode: 0o755 });
437
+
438
+ const hooksPath = path.join(HOME, ".gemini", "config", "hooks.json");
439
+ const hooksConfig = readEditableJson(hooksPath, {});
440
+ addGeminiCommandHook(hooksConfig, "SessionStart", "startup", `node ${JSON.stringify(hookPath)} SessionStart`);
441
+ addGeminiCommandHook(hooksConfig, "BeforeAgent", "*", `node ${JSON.stringify(hookPath)} BeforeAgent`);
442
+ addGeminiCommandHook(hooksConfig, "AfterAgent", "*", `node ${JSON.stringify(hookPath)} AfterAgent`);
443
+ writeJson(hooksPath, hooksConfig);
444
+ console.log(`Updated ${hooksPath}`);
445
+ console.log("Antigravity CLI hook installed.");
446
+ }
447
+
424
448
  function installAll() {
425
449
  installCodex();
426
450
  installClaude();
427
451
  installGemini();
452
+ installAntigravity();
453
+ }
454
+
455
+ function install() {
456
+ const target = process.argv[3] && !process.argv[3].startsWith("--") ? process.argv[3] : "all";
457
+ if (!["all", "codex", "claude", "gemini", "antigravity", "agy"].includes(target)) {
458
+ console.error("Unknown install target. Use: codex, claude, gemini, antigravity, or all.");
459
+ process.exit(1);
460
+ }
461
+ if (target === "all") installAll();
462
+ else if (target === "codex") installCodex();
463
+ else if (target === "claude") installClaude();
464
+ else if (target === "gemini") installGemini();
465
+ else installAntigravity();
428
466
  }
429
467
 
430
468
  function uninstallCodex() {
@@ -461,15 +499,32 @@ function uninstallGemini() {
461
499
  console.log("Removed Gemini hook script.");
462
500
  }
463
501
 
502
+ function uninstallAntigravity() {
503
+ const hooksPath = path.join(HOME, ".gemini", "config", "hooks.json");
504
+ const hooksConfig = readEditableJson(hooksPath, {});
505
+ if (removeClaudeCommandHooks(hooksConfig)) {
506
+ writeJson(hooksPath, hooksConfig);
507
+ console.log(`Removed CLIsponsor hooks from ${hooksPath}`);
508
+ } else {
509
+ console.log("No CLIsponsor Antigravity hooks found.");
510
+ }
511
+ fs.rmSync(path.join(CONFIG_DIR, "antigravity", "clisponsor_antigravity_hook.mjs"), { force: true });
512
+ try {
513
+ fs.rmdirSync(path.join(CONFIG_DIR, "antigravity"));
514
+ } catch {}
515
+ console.log("Removed Antigravity hook script.");
516
+ }
517
+
464
518
  function uninstall() {
465
519
  const target = process.argv[3] && !process.argv[3].startsWith("--") ? process.argv[3] : "all";
466
- if (!["all", "codex", "claude", "gemini"].includes(target)) {
467
- console.error("Unknown uninstall target. Use: codex, claude, gemini, or all.");
520
+ if (!["all", "codex", "claude", "gemini", "antigravity", "agy"].includes(target)) {
521
+ console.error("Unknown uninstall target. Use: codex, claude, gemini, antigravity, or all.");
468
522
  process.exit(1);
469
523
  }
470
524
  if (target === "all" || target === "codex") uninstallCodex();
471
525
  if (target === "all" || target === "claude") uninstallClaude();
472
526
  if (target === "all" || target === "gemini") uninstallGemini();
527
+ if (target === "all" || target === "antigravity" || target === "agy") uninstallAntigravity();
473
528
  if (hasFlag("--config")) {
474
529
  fs.rmSync(CONFIG_PATH, { force: true });
475
530
  console.log(`Removed ${CONFIG_PATH}`);
@@ -523,12 +578,13 @@ async function doctor() {
523
578
  email: cfg.email || null,
524
579
  userId: cfg.userId || null,
525
580
  deviceCode: cfg.deviceCode || null,
526
- installed: {
527
- codexPluginStaged: fs.existsSync(path.join(CONFIG_DIR, "codex-marketplace", "plugins", "clisponsor")),
528
- claudeSettings: fs.existsSync(path.join(HOME, ".claude", "settings.json")),
529
- claudeHookScript: fs.existsSync(path.join(CONFIG_DIR, "claude", "clisponsor_claude_hook.mjs")),
530
- geminiHookScript: fs.existsSync(path.join(CONFIG_DIR, "gemini", "clisponsor_gemini_hook.mjs")),
531
- },
581
+ installed: {
582
+ codexPluginStaged: fs.existsSync(path.join(CONFIG_DIR, "codex-marketplace", "plugins", "clisponsor")),
583
+ claudeSettings: fs.existsSync(path.join(HOME, ".claude", "settings.json")),
584
+ claudeHookScript: fs.existsSync(path.join(CONFIG_DIR, "claude", "clisponsor_claude_hook.mjs")),
585
+ geminiHookScript: fs.existsSync(path.join(CONFIG_DIR, "gemini", "clisponsor_gemini_hook.mjs")),
586
+ antigravityHookScript: fs.existsSync(path.join(CONFIG_DIR, "antigravity", "clisponsor_antigravity_hook.mjs")),
587
+ },
532
588
  network: {},
533
589
  };
534
590
 
@@ -554,6 +610,7 @@ async function doctor() {
554
610
  console.log(`Claude settings: ${diagnostics.installed.claudeSettings ? "yes" : "no"}`);
555
611
  console.log(`Claude hook script: ${diagnostics.installed.claudeHookScript ? "yes" : "no"}`);
556
612
  console.log(`Gemini hook script: ${diagnostics.installed.geminiHookScript ? "yes" : "no"}`);
613
+ console.log(`Antigravity hook script: ${diagnostics.installed.antigravityHookScript ? "yes" : "no"}`);
557
614
  if (skipNetwork) {
558
615
  console.log("Network: skipped");
559
616
  } else {
@@ -564,9 +621,9 @@ async function doctor() {
564
621
 
565
622
  function help() {
566
623
  console.log(`clisponsor commands:
567
- clisponsor install
624
+ clisponsor install [all|codex|claude|gemini|antigravity]
568
625
  clisponsor login <email> [--label=<device-label>]
569
- clisponsor uninstall [--config]
626
+ clisponsor uninstall [all|codex|claude|gemini|antigravity] [--config]
570
627
  clisponsor status
571
628
  clisponsor doctor [--json] [--skip-network]
572
629
 
@@ -576,7 +633,7 @@ Environment:
576
633
 
577
634
  const command = process.argv[2] || "help";
578
635
  if (command === "login") await login();
579
- else if (command === "install" && (!process.argv[3] || process.argv[3] === "all")) installAll();
636
+ else if (command === "install") install();
580
637
  else if (command === "uninstall") uninstall();
581
638
  else if (command === "status") await status();
582
639
  else if (command === "doctor") await doctor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clisponsor",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "CLIsponsor installer for Codex, Claude Code, and Gemini sponsored CLI placements.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -22,6 +22,10 @@ function readStdin() {
22
22
  });
23
23
  }
24
24
 
25
+ function sponsoredLine(line) {
26
+ return `[Sponsored] ${line}`;
27
+ }
28
+
25
29
  await readStdin();
26
30
 
27
31
  try {
@@ -46,7 +50,7 @@ try {
46
50
  });
47
51
  if (!res.ok) process.exit(0);
48
52
  const ad = await res.json();
49
- if (ad.display_line) console.log(JSON.stringify({ systemMessage: ad.display_line }));
53
+ if (ad.display_line) console.log(JSON.stringify({ systemMessage: sponsoredLine(ad.display_line) }));
50
54
  } catch {
51
55
  process.exit(0);
52
56
  }
@@ -23,6 +23,10 @@ function readConfig() {
23
23
  return JSON.parse(fs.readFileSync(CONFIG_PATH, "utf8"));
24
24
  }
25
25
 
26
+ function sponsoredLine(line) {
27
+ return `[Sponsored] ${line}`;
28
+ }
29
+
26
30
  const cfg = readConfig();
27
31
  const serveBaseUrl = cfg.serveBaseUrl || cfg.apiBaseUrl;
28
32
  await readStdin();
@@ -50,7 +54,7 @@ try {
50
54
  });
51
55
  if (!res.ok) process.exit(0);
52
56
  const ad = await res.json();
53
- if (ad.display_line) console.log(JSON.stringify({ systemMessage: ad.display_line }));
57
+ if (ad.display_line) console.log(JSON.stringify({ systemMessage: sponsoredLine(ad.display_line) }));
54
58
  } catch {
55
59
  process.exit(0);
56
60
  }