opencrater 0.2.0 → 0.2.2

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/cli.js +84 -5
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -23,8 +23,29 @@ const fs = require("node:fs");
23
23
  const path = require("node:path");
24
24
  const os = require("node:os");
25
25
 
26
- const KEY = "ock_MUFntM66VEbx7e7fKoQr2a43VBx762rHkKw1G8vj";
27
- const PKG = "opencrater";
26
+ // Default = the house channel. Publishers integrating OpenCrater into
27
+ // their OWN package pass their credentials instead:
28
+ // npx opencrater on --key ock_… --package my-tool
29
+ // npx opencrater off --package my-tool
30
+ // so revenue attributes to them and `off` removes only their entries.
31
+ // Flags are parsed up front; everything below reads KEY/PKG.
32
+ let KEY = "ock_MUFntM66VEbx7e7fKoQr2a43VBx762rHkKw1G8vj";
33
+ let PKG = "opencrater";
34
+ {
35
+ const argv = process.argv;
36
+ for (let i = 2; i < argv.length; i++) {
37
+ if (argv[i] === "--key" && argv[i + 1]) KEY = argv[++i];
38
+ else if (argv[i] === "--package" && argv[i + 1]) PKG = argv[++i];
39
+ }
40
+ if (!/^ock_[A-Za-z0-9]{8,64}$/.test(KEY)) {
41
+ console.error("opencrater: --key must look like ock_…");
42
+ process.exit(1);
43
+ }
44
+ if (!/^[A-Za-z0-9@/_.-]{1,128}$/.test(PKG)) {
45
+ console.error("opencrater: --package must be 1-128 chars of [a-zA-Z0-9@/_.-]");
46
+ process.exit(1);
47
+ }
48
+ }
28
49
  // EVERY host hook is registered as a trigger; the SDK + platform decide
29
50
  // which ones actually render (recommended session-edge hooks by default,
30
51
  // remotely tunable). Registering everything also feeds the recommendation
@@ -190,6 +211,60 @@ async function dismissNow() {
190
211
  console.log(" changed your mind? npx opencrater show");
191
212
  }
192
213
 
214
+ /* Report the sponsor card currently on screen (or the last one shown).
215
+ Blocks the campaign on this machine permanently (reported-ads.json — the
216
+ SDK skips reported campaigns forever), clears the card, and opens the
217
+ hosted report screen so the user can pick a reason. */
218
+ async function reportAd() {
219
+ const dir = path.join(os.homedir(), ".config", "opencrater");
220
+ let lock = null;
221
+ let saved = null;
222
+ try { lock = JSON.parse(fs.readFileSync(path.join(dir, "painter.lock"), "utf8")); } catch {}
223
+ try { saved = JSON.parse(fs.readFileSync(path.join(dir, "last-ad.json"), "utf8")); } catch {}
224
+ const impressionId = (lock && lock.impressionId) || (saved && saved.payload && saved.payload.impressionId);
225
+ const campaignId = saved && saved.payload && saved.payload.campaignId;
226
+ if (!impressionId && !campaignId) {
227
+ console.log("opencrater: no sponsor card to report.");
228
+ return;
229
+ }
230
+ // permanent local block — never render this campaign here again
231
+ if (campaignId) {
232
+ const file = path.join(dir, "reported-ads.json");
233
+ let reported = {};
234
+ try { reported = JSON.parse(fs.readFileSync(file, "utf8")) || {}; } catch {}
235
+ reported[campaignId] = Date.now();
236
+ try {
237
+ fs.mkdirSync(dir, { recursive: true });
238
+ fs.writeFileSync(file, JSON.stringify(reported));
239
+ } catch {}
240
+ }
241
+ // clear the live card, if any
242
+ if (lock) {
243
+ try {
244
+ fs.writeFileSync(
245
+ path.join(dir, "dismiss.signal"),
246
+ JSON.stringify({ impressionId: lock.impressionId, at: Date.now() }),
247
+ );
248
+ } catch {}
249
+ if (lock.pid && lock.pid > 1) {
250
+ try { process.kill(lock.pid, "SIGTERM"); } catch {}
251
+ }
252
+ }
253
+ console.log("opencrater: reported — you won't see this ad on this machine again.");
254
+ if (impressionId) {
255
+ const origin = process.env.OPENCRATER_API_ORIGIN || "https://api.opencrater.to";
256
+ const url = origin + "/r/" + impressionId;
257
+ const { spawnSync } = require("node:child_process");
258
+ const opener = process.platform === "darwin" ? "open" : "xdg-open";
259
+ const res = spawnSync(opener, [url], { stdio: "ignore" });
260
+ if (res.status === 0) {
261
+ console.log(" tell us why in the tab that just opened (10 seconds).");
262
+ } else {
263
+ console.log(" tell us why (optional): " + url);
264
+ }
265
+ }
266
+ }
267
+
193
268
  /* Repaint the last sponsor card ("show ad again"). Reads the payload the
194
269
  painter saved, resolves THIS terminal's tty, and spawns the local-runtime
195
270
  painter detached — exactly how the hook does it. */
@@ -298,6 +373,8 @@ if (cmd === "on" || cmd === "enable") {
298
373
  console.log(a || b ? "OpenCrater ads disabled. Publisher hooks (if any) were not touched." : "Nothing to remove — OpenCrater ads were not enabled.");
299
374
  } else if (cmd === "x" || cmd === "dismiss") {
300
375
  dismissNow();
376
+ } else if (cmd === "report" || cmd === "flag") {
377
+ reportAd();
301
378
  } else if (cmd === "show" || cmd === "again") {
302
379
  showAgain();
303
380
  } else if (cmd === "status") {
@@ -310,8 +387,10 @@ if (cmd === "on" || cmd === "enable") {
310
387
  console.log("Gemini CLI:", !hosts.gemini_cli ? "not installed" : gm.length ? "enabled (" + gm.length + " hooks)" : "detected — run: npx opencrater on");
311
388
  if (hosts.openclaw) console.log("OpenClaw: detected — message-level sponsorship on the roadmap");
312
389
  } else {
313
- console.log("Usage: npx opencrater <on|off|status|x|show>");
314
- console.log(" x dismiss the sponsor card currently on screen");
315
- console.log(" show bring the last dismissed ad back");
390
+ console.log("Usage: npx opencrater <on|off|status|x|report|show> [--key ock_… --package name]");
391
+ console.log(" --key/--package publisher attribution (defaults to the OpenCrater house channel)");
392
+ console.log(" x dismiss the sponsor card currently on screen");
393
+ console.log(" report report the ad (never shows on this machine again)");
394
+ console.log(" show bring the last dismissed ad back");
316
395
  process.exitCode = 1;
317
396
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencrater",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "OpenCrater — sponsor cards in Claude Code and Codex. Free, one command, opt out anytime.",
5
5
  "keywords": [
6
6
  "opencrater",