clisponsor 1.0.4 → 1.0.5

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 +33 -7
  2. package/package.json +1 -1
@@ -130,6 +130,23 @@ function chmodExecutable(file) {
130
130
  }
131
131
 
132
132
  function commandExists(command) {
133
+ const paths = String(process.env.PATH || "").split(path.delimiter).filter(Boolean);
134
+ const extensions = process.platform === "win32" ? String(process.env.PATHEXT || ".EXE;.CMD;.BAT").split(";") : [""];
135
+ for (const directory of paths) {
136
+ for (const extension of extensions) {
137
+ const candidate = path.join(directory, command + extension.toLowerCase());
138
+ try {
139
+ fs.accessSync(candidate, fs.constants.X_OK);
140
+ return true;
141
+ } catch {}
142
+ if (extension) {
143
+ try {
144
+ fs.accessSync(path.join(directory, command + extension.toUpperCase()), fs.constants.X_OK);
145
+ return true;
146
+ } catch {}
147
+ }
148
+ }
149
+ }
133
150
  try {
134
151
  execFileSync(command, ["--version"], { stdio: "ignore" });
135
152
  return true;
@@ -361,13 +378,15 @@ function installClaude() {
361
378
  console.log("Claude Code CLI hook installed.");
362
379
  }
363
380
 
364
- function agentHookSource(client) {
381
+ function agentHookSource(client, options = {}) {
382
+ const outputMode = options.outputMode || "systemMessage";
365
383
  return `#!/usr/bin/env node
366
384
  import fs from "node:fs";
367
385
  import crypto from "node:crypto";
368
386
  const cfg = JSON.parse(fs.readFileSync(${JSON.stringify(CONFIG_PATH)}, "utf8"));
369
387
  const event = process.argv[2] || "BeforeAgent";
370
- const placements = { SessionStart: "StartSession", BeforeAgent: "StartTurn", AfterAgent: "EndTurn", StartTurn: "StartTurn" };
388
+ const outputMode = ${JSON.stringify(outputMode)};
389
+ const placements = { SessionStart: "StartSession", PreInvocation: "StartSession", BeforeAgent: "StartTurn", UserPromptSubmit: "StartTurn", PreToolUse: "StartTurn", AfterAgent: "EndTurn", PostInvocation: "EndTurn", Stop: "EndTurn", StartTurn: "StartTurn" };
371
390
  const serveBaseUrl = cfg.serveBaseUrl || cfg.apiBaseUrl;
372
391
  function sponsoredLine(line) {
373
392
  return "[Sponsored] " + line;
@@ -395,7 +414,13 @@ try {
395
414
  });
396
415
  if (res.ok) {
397
416
  const ad = await res.json();
398
- if (ad.display_line) console.log(JSON.stringify({ systemMessage: sponsoredLine(ad.display_line) }));
417
+ if (outputMode === "antigravity") {
418
+ const payload = { decision: "allow" };
419
+ if (ad.display_line) payload.systemMessage = sponsoredLine(ad.display_line);
420
+ console.log(JSON.stringify(payload));
421
+ } else if (ad.display_line) {
422
+ console.log(JSON.stringify({ systemMessage: sponsoredLine(ad.display_line) }));
423
+ }
399
424
  }
400
425
  } catch {
401
426
  process.exit(0);
@@ -433,13 +458,14 @@ function installAntigravity() {
433
458
  const antigravityDir = path.join(CONFIG_DIR, "antigravity");
434
459
  fs.mkdirSync(antigravityDir, { recursive: true });
435
460
  const hookPath = path.join(antigravityDir, "clisponsor_antigravity_hook.mjs");
436
- fs.writeFileSync(hookPath, agentHookSource("Antigravity"), { mode: 0o755 });
461
+ fs.writeFileSync(hookPath, agentHookSource("Antigravity", { outputMode: "antigravity" }), { mode: 0o755 });
437
462
 
438
463
  const hooksPath = path.join(HOME, ".gemini", "config", "hooks.json");
439
464
  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`);
465
+ addGeminiCommandHook(hooksConfig, "PreInvocation", "*", `node ${JSON.stringify(hookPath)} PreInvocation`);
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`);
443
469
  writeJson(hooksPath, hooksConfig);
444
470
  console.log(`Updated ${hooksPath}`);
445
471
  console.log("Antigravity CLI hook installed.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clisponsor",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "CLIsponsor installer for Codex, Claude Code, and Gemini sponsored CLI placements.",
5
5
  "type": "module",
6
6
  "engines": {