clisponsor 1.0.8 → 1.0.10

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 (2) hide show
  1. package/bin/clisponsor.mjs +26 -11
  2. package/package.json +1 -1
@@ -15,7 +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", "Stop"];
18
+ const ANTIGRAVITY_EVENTS = ["PreInvocation"];
19
19
 
20
20
  function argValue(name) {
21
21
  const prefix = `${name}=`;
@@ -407,11 +407,12 @@ function agentHookSource(client, options = {}) {
407
407
  return `#!/usr/bin/env node
408
408
  import fs from "node:fs";
409
409
  import crypto from "node:crypto";
410
- const cfg = JSON.parse(fs.readFileSync(${JSON.stringify(CONFIG_PATH)}, "utf8"));
411
410
  const event = process.argv[2] || "BeforeAgent";
412
411
  const outputMode = ${JSON.stringify(outputMode)};
413
412
  const placements = { SessionStart: "StartSession", PreInvocation: "StartTurn", BeforeAgent: "StartTurn", UserPromptSubmit: "StartTurn", PreToolUse: "StartTurn", AfterAgent: "EndTurn", PostInvocation: "EndTurn", Stop: "EndTurn", StartTurn: "StartTurn" };
414
- const serveBaseUrl = cfg.serveBaseUrl || cfg.apiBaseUrl;
413
+ function writeNoop() {
414
+ if (outputMode === "antigravity") console.log(JSON.stringify({}));
415
+ }
415
416
  function sponsoredLine(line) {
416
417
  return "[Sponsored] " + line;
417
418
  }
@@ -427,15 +428,26 @@ let hookInput = {};
427
428
  try {
428
429
  hookInput = hookInputRaw.trim() ? JSON.parse(hookInputRaw) : {};
429
430
  } catch {}
431
+ let cfg = {};
432
+ try {
433
+ cfg = JSON.parse(fs.readFileSync(${JSON.stringify(CONFIG_PATH)}, "utf8"));
434
+ } catch {
435
+ writeNoop();
436
+ process.exit(0);
437
+ }
438
+ const serveBaseUrl = cfg.serveBaseUrl || cfg.apiBaseUrl;
430
439
  try {
431
- if (!serveBaseUrl || !cfg.userId || !cfg.deviceCode || !cfg.deviceSecret) process.exit(0);
440
+ if (outputMode === "antigravity" && event !== "PreInvocation") {
441
+ writeNoop();
442
+ process.exit(0);
443
+ }
444
+ if (!serveBaseUrl || !cfg.userId || !cfg.deviceCode || !cfg.deviceSecret) {
445
+ writeNoop();
446
+ process.exit(0);
447
+ }
432
448
  if (outputMode === "antigravity") {
433
449
  if (event === "PreInvocation" && Number(hookInput.invocationNum || 1) > 1) {
434
- console.log(JSON.stringify({}));
435
- process.exit(0);
436
- }
437
- if (event === "Stop" && hookInput.fullyIdle === false) {
438
- console.log(JSON.stringify({ decision: "allow" }));
450
+ writeNoop();
439
451
  process.exit(0);
440
452
  }
441
453
  }
@@ -453,14 +465,17 @@ try {
453
465
  if (res.ok) {
454
466
  const ad = await res.json();
455
467
  if (outputMode === "antigravity") {
456
- const payload = { decision: "allow" };
457
- if (ad.display_line) payload.systemMessage = sponsoredLine(ad.display_line);
468
+ const payload = {};
469
+ if (ad.display_line) payload.injectSteps = [{ ephemeralMessage: sponsoredLine(ad.display_line) }];
458
470
  console.log(JSON.stringify(payload));
459
471
  } else if (ad.display_line) {
460
472
  console.log(JSON.stringify({ systemMessage: sponsoredLine(ad.display_line) }));
461
473
  }
474
+ } else {
475
+ writeNoop();
462
476
  }
463
477
  } catch {
478
+ writeNoop();
464
479
  process.exit(0);
465
480
  }
466
481
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clisponsor",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "CLIsponsor installer for Codex, Claude Code, and Gemini sponsored CLI placements.",
5
5
  "type": "module",
6
6
  "engines": {