clisponsor 1.0.3 → 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.
- package/bin/clisponsor.mjs +91 -37
- package/package.json +1 -1
package/bin/clisponsor.mjs
CHANGED
|
@@ -140,14 +140,15 @@ function commandExists(command) {
|
|
|
140
140
|
|
|
141
141
|
function isClisponsorCommand(value) {
|
|
142
142
|
return (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
|
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";
|
|
@@ -383,7 +383,7 @@ await readStdin();
|
|
|
383
383
|
try {
|
|
384
384
|
if (!serveBaseUrl || !cfg.userId || !cfg.deviceCode || !cfg.deviceSecret) process.exit(0);
|
|
385
385
|
const placement = placements[event] || event;
|
|
386
|
-
const body = { user_id: cfg.userId, device_code: cfg.deviceCode, client:
|
|
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)} } };
|
|
387
387
|
const res = await fetch(serveBaseUrl + "/v1/ads/serve", {
|
|
388
388
|
method: "POST",
|
|
389
389
|
headers: {
|
|
@@ -405,14 +405,14 @@ try {
|
|
|
405
405
|
|
|
406
406
|
function installGemini() {
|
|
407
407
|
if (!commandExists("gemini")) {
|
|
408
|
-
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");
|
|
409
409
|
return;
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
const geminiDir = path.join(CONFIG_DIR, "gemini");
|
|
413
413
|
fs.mkdirSync(geminiDir, { recursive: true });
|
|
414
414
|
const hookPath = path.join(geminiDir, "clisponsor_gemini_hook.mjs");
|
|
415
|
-
fs.writeFileSync(hookPath,
|
|
415
|
+
fs.writeFileSync(hookPath, agentHookSource("Gemini"), { mode: 0o755 });
|
|
416
416
|
|
|
417
417
|
const settingsPath = path.join(HOME, ".gemini", "settings.json");
|
|
418
418
|
const settings = readEditableJson(settingsPath, {});
|
|
@@ -424,10 +424,45 @@ function installGemini() {
|
|
|
424
424
|
console.log("Gemini CLI hook installed.");
|
|
425
425
|
}
|
|
426
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
|
+
|
|
427
448
|
function installAll() {
|
|
428
449
|
installCodex();
|
|
429
450
|
installClaude();
|
|
430
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();
|
|
431
466
|
}
|
|
432
467
|
|
|
433
468
|
function uninstallCodex() {
|
|
@@ -464,15 +499,32 @@ function uninstallGemini() {
|
|
|
464
499
|
console.log("Removed Gemini hook script.");
|
|
465
500
|
}
|
|
466
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
|
+
|
|
467
518
|
function uninstall() {
|
|
468
519
|
const target = process.argv[3] && !process.argv[3].startsWith("--") ? process.argv[3] : "all";
|
|
469
|
-
if (!["all", "codex", "claude", "gemini"].includes(target)) {
|
|
470
|
-
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.");
|
|
471
522
|
process.exit(1);
|
|
472
523
|
}
|
|
473
524
|
if (target === "all" || target === "codex") uninstallCodex();
|
|
474
525
|
if (target === "all" || target === "claude") uninstallClaude();
|
|
475
526
|
if (target === "all" || target === "gemini") uninstallGemini();
|
|
527
|
+
if (target === "all" || target === "antigravity" || target === "agy") uninstallAntigravity();
|
|
476
528
|
if (hasFlag("--config")) {
|
|
477
529
|
fs.rmSync(CONFIG_PATH, { force: true });
|
|
478
530
|
console.log(`Removed ${CONFIG_PATH}`);
|
|
@@ -526,12 +578,13 @@ async function doctor() {
|
|
|
526
578
|
email: cfg.email || null,
|
|
527
579
|
userId: cfg.userId || null,
|
|
528
580
|
deviceCode: cfg.deviceCode || null,
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
+
},
|
|
535
588
|
network: {},
|
|
536
589
|
};
|
|
537
590
|
|
|
@@ -557,6 +610,7 @@ async function doctor() {
|
|
|
557
610
|
console.log(`Claude settings: ${diagnostics.installed.claudeSettings ? "yes" : "no"}`);
|
|
558
611
|
console.log(`Claude hook script: ${diagnostics.installed.claudeHookScript ? "yes" : "no"}`);
|
|
559
612
|
console.log(`Gemini hook script: ${diagnostics.installed.geminiHookScript ? "yes" : "no"}`);
|
|
613
|
+
console.log(`Antigravity hook script: ${diagnostics.installed.antigravityHookScript ? "yes" : "no"}`);
|
|
560
614
|
if (skipNetwork) {
|
|
561
615
|
console.log("Network: skipped");
|
|
562
616
|
} else {
|
|
@@ -567,9 +621,9 @@ async function doctor() {
|
|
|
567
621
|
|
|
568
622
|
function help() {
|
|
569
623
|
console.log(`clisponsor commands:
|
|
570
|
-
clisponsor install
|
|
624
|
+
clisponsor install [all|codex|claude|gemini|antigravity]
|
|
571
625
|
clisponsor login <email> [--label=<device-label>]
|
|
572
|
-
clisponsor uninstall [--config]
|
|
626
|
+
clisponsor uninstall [all|codex|claude|gemini|antigravity] [--config]
|
|
573
627
|
clisponsor status
|
|
574
628
|
clisponsor doctor [--json] [--skip-network]
|
|
575
629
|
|
|
@@ -579,7 +633,7 @@ Environment:
|
|
|
579
633
|
|
|
580
634
|
const command = process.argv[2] || "help";
|
|
581
635
|
if (command === "login") await login();
|
|
582
|
-
else if (command === "install"
|
|
636
|
+
else if (command === "install") install();
|
|
583
637
|
else if (command === "uninstall") uninstall();
|
|
584
638
|
else if (command === "status") await status();
|
|
585
639
|
else if (command === "doctor") await doctor();
|