opencrater 0.1.8 → 0.2.0
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/cli.js +28 -1
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -37,6 +37,13 @@ const CLAUDE_EVENTS = [
|
|
|
37
37
|
"Elicitation", "ElicitationResult", "ConfigChange", "InstructionsLoaded",
|
|
38
38
|
"WorktreeCreate", "WorktreeRemove", "CwdChanged", "FileChanged", "MessageDisplay",
|
|
39
39
|
];
|
|
40
|
+
// Gemini CLI hooks (verified HookEventName set, GA since v0.26.0):
|
|
41
|
+
// ~/.gemini/settings.json takes the same rule shape as Claude Code.
|
|
42
|
+
const GEMINI_EVENTS = [
|
|
43
|
+
"SessionStart", "SessionEnd", "BeforeAgent", "AfterAgent", "BeforeModel",
|
|
44
|
+
"AfterModel", "BeforeToolSelection", "BeforeTool", "AfterTool",
|
|
45
|
+
"PreCompress", "Notification",
|
|
46
|
+
];
|
|
40
47
|
const CODEX_EVENTS = [
|
|
41
48
|
"SessionStart", "Stop", "UserPromptSubmit", "PreToolUse", "PostToolUse",
|
|
42
49
|
"PermissionRequest", "PreCompact", "PostCompact",
|
|
@@ -64,6 +71,7 @@ const CODEX_HOOKS = path.join(
|
|
|
64
71
|
process.env.CODEX_HOME || path.join(os.homedir(), ".codex"),
|
|
65
72
|
"hooks.json",
|
|
66
73
|
);
|
|
74
|
+
const GEMINI_SETTINGS = path.join(os.homedir(), ".gemini", "settings.json");
|
|
67
75
|
|
|
68
76
|
function readJson(p) {
|
|
69
77
|
try {
|
|
@@ -92,7 +100,9 @@ const isOurs = (rule) =>
|
|
|
92
100
|
);
|
|
93
101
|
|
|
94
102
|
function enableIn(file, host) {
|
|
95
|
-
const events =
|
|
103
|
+
const events =
|
|
104
|
+
host === "codex" ? CODEX_EVENTS :
|
|
105
|
+
host === "gemini_cli" ? GEMINI_EVENTS : CLAUDE_EVENTS;
|
|
96
106
|
const settings = readJson(file);
|
|
97
107
|
if (!settings.hooks) settings.hooks = {};
|
|
98
108
|
let changed = false;
|
|
@@ -225,6 +235,8 @@ function detectHosts() {
|
|
|
225
235
|
return {
|
|
226
236
|
claude_code: fs.existsSync(path.join(os.homedir(), ".claude")) || hasBin("claude"),
|
|
227
237
|
codex: fs.existsSync(path.join(process.env.CODEX_HOME || path.join(os.homedir(), ".codex"))) || hasBin("codex"),
|
|
238
|
+
openclaw: fs.existsSync(path.join(os.homedir(), ".openclaw")) || hasBin("openclaw"),
|
|
239
|
+
gemini_cli: fs.existsSync(path.join(os.homedir(), ".gemini")) || hasBin("gemini"),
|
|
228
240
|
};
|
|
229
241
|
}
|
|
230
242
|
|
|
@@ -249,6 +261,16 @@ if (cmd === "on" || cmd === "enable") {
|
|
|
249
261
|
} else {
|
|
250
262
|
console.log("· Codex not found — skipped");
|
|
251
263
|
}
|
|
264
|
+
if (hosts.gemini_cli) {
|
|
265
|
+
enableIn(GEMINI_SETTINGS, "gemini_cli");
|
|
266
|
+
console.log("✓ Gemini CLI detected — connected (" + GEMINI_SETTINGS + ")");
|
|
267
|
+
} else {
|
|
268
|
+
console.log("· Gemini CLI not found — skipped");
|
|
269
|
+
}
|
|
270
|
+
if (hosts.openclaw) {
|
|
271
|
+
console.log("· OpenClaw detected — its hooks run inside the gateway (no terminal");
|
|
272
|
+
console.log(" overlay surface); message-level sponsorship is on the roadmap.");
|
|
273
|
+
}
|
|
252
274
|
// Pre-install the local hook runtime (background): hooks then run via
|
|
253
275
|
// plain node — no npx resolution latency, no cold-cache races.
|
|
254
276
|
try {
|
|
@@ -271,6 +293,8 @@ if (cmd === "on" || cmd === "enable") {
|
|
|
271
293
|
} else if (cmd === "off" || cmd === "disable") {
|
|
272
294
|
const a = disableIn(CLAUDE_SETTINGS);
|
|
273
295
|
const b = disableIn(CODEX_HOOKS);
|
|
296
|
+
const c = disableIn(GEMINI_SETTINGS);
|
|
297
|
+
void c;
|
|
274
298
|
console.log(a || b ? "OpenCrater ads disabled. Publisher hooks (if any) were not touched." : "Nothing to remove — OpenCrater ads were not enabled.");
|
|
275
299
|
} else if (cmd === "x" || cmd === "dismiss") {
|
|
276
300
|
dismissNow();
|
|
@@ -280,8 +304,11 @@ if (cmd === "on" || cmd === "enable") {
|
|
|
280
304
|
const hosts = detectHosts();
|
|
281
305
|
const cc = statusIn(CLAUDE_SETTINGS);
|
|
282
306
|
const cx = statusIn(CODEX_HOOKS);
|
|
307
|
+
const gm = statusIn(GEMINI_SETTINGS);
|
|
283
308
|
console.log("Claude Code:", !hosts.claude_code ? "not installed" : cc.length ? "enabled (" + cc.length + " hooks)" : "detected — run: npx opencrater on");
|
|
284
309
|
console.log("Codex: ", !hosts.codex ? "not installed" : cx.length ? "enabled (" + cx.length + " hooks)" : "detected — run: npx opencrater on");
|
|
310
|
+
console.log("Gemini CLI:", !hosts.gemini_cli ? "not installed" : gm.length ? "enabled (" + gm.length + " hooks)" : "detected — run: npx opencrater on");
|
|
311
|
+
if (hosts.openclaw) console.log("OpenClaw: detected — message-level sponsorship on the roadmap");
|
|
285
312
|
} else {
|
|
286
313
|
console.log("Usage: npx opencrater <on|off|status|x|show>");
|
|
287
314
|
console.log(" x dismiss the sponsor card currently on screen");
|