callkaro-cli-unofficial 0.8.0 → 0.9.1

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.
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isNewer = isNewer;
7
+ exports.notifyIfOutdated = notifyIfOutdated;
8
+ const os_1 = require("os");
9
+ const path_1 = require("path");
10
+ const fs_1 = require("fs");
11
+ const child_process_1 = require("child_process");
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ const CACHE = (0, path_1.join)(process.env.CK_CONFIG_DIR || (0, path_1.join)((0, os_1.homedir)(), '.config', 'callkaro-unofficial'), 'update-check.json');
14
+ const DAY = 24 * 60 * 60 * 1000;
15
+ const REGISTRY = 'https://registry.npmjs.org/callkaro-cli-unofficial/latest';
16
+ /** True when `latest` is a higher x.y.z than `current` (pre-release tags ignored). */
17
+ function isNewer(latest, current) {
18
+ const n = (v) => v.split('-')[0].split('.').map((x) => parseInt(x, 10) || 0);
19
+ const [a, b] = [n(latest), n(current)];
20
+ for (let i = 0; i < 3; i++) {
21
+ if ((a[i] || 0) !== (b[i] || 0))
22
+ return (a[i] || 0) > (b[i] || 0);
23
+ }
24
+ return false;
25
+ }
26
+ /**
27
+ * Tell the user (or the agent driving the CLI) when a newer release exists.
28
+ *
29
+ * Reads the answer cached by an earlier run and prints it to stderr after the
30
+ * command's own output, so stdout / --json stay clean. The npm lookup runs in a
31
+ * detached child at most once a day, so it never delays or breaks a command.
32
+ * Opt out with CK_NO_UPDATE_CHECK=1 (or when running under `node --test`).
33
+ */
34
+ function notifyIfOutdated(current, argv) {
35
+ try {
36
+ if (process.env.CK_NO_UPDATE_CHECK || process.env.NODE_TEST_CONTEXT)
37
+ return;
38
+ if (argv.some((a) => ['update', '-v', '--version', '-h', '--help'].includes(a)))
39
+ return;
40
+ let cache = {};
41
+ try {
42
+ cache = JSON.parse((0, fs_1.readFileSync)(CACHE, 'utf8'));
43
+ }
44
+ catch {
45
+ /* first run */
46
+ }
47
+ if (cache.latest && isNewer(cache.latest, current)) {
48
+ process.on('exit', () => {
49
+ process.stderr.write(chalk_1.default.yellow(`\nA newer CallKaro CLI (cku) is available: ${current} -> ${cache.latest}.\n` +
50
+ `AI agents: tell the user the CLI is outdated and ask if they want to upgrade; if yes, run \`cku update\`.\n`));
51
+ });
52
+ }
53
+ if (!cache.checkedAt || Date.now() - cache.checkedAt > DAY) {
54
+ const script = `
55
+ const fs = require('fs'), path = require('path');
56
+ const file = process.argv[1];
57
+ (async () => {
58
+ let latest;
59
+ try { latest = (await (await fetch(${JSON.stringify(REGISTRY)}, { signal: AbortSignal.timeout(5000) })).json()).version; } catch {}
60
+ fs.mkdirSync(path.dirname(file), { recursive: true });
61
+ fs.writeFileSync(file, JSON.stringify({ checkedAt: Date.now(), latest }));
62
+ })();`;
63
+ (0, child_process_1.spawn)(process.execPath, ['-e', script, CACHE], { detached: true, stdio: 'ignore' }).unref();
64
+ }
65
+ }
66
+ catch {
67
+ /* an update check must never break a command */
68
+ }
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "callkaro-cli-unofficial",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Unofficial fork of the CallKaro CLI — manage your voice AI agents from the terminal",
6
6
  "bin": {