kronk-cli 0.6.1 → 0.8.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/src/version.js ADDED
@@ -0,0 +1,35 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ /**
4
+ * The one place that reads this package's own version.
5
+ *
6
+ * Everything that needs to say what build this is — the `--version` flag, the
7
+ * MCP `clientInfo` handshake, the update check's idea of "current" — imports
8
+ * `VERSION` from here instead of carrying its own copy. `src/mcp.js` used to
9
+ * hardcode `'0.1.0'` and nothing ever noticed it had fallen six releases
10
+ * behind, because nothing read the real number. `package.json` is in the
11
+ * published `files` allowlist, so this works on every install route: npm,
12
+ * Homebrew, the install script, and a git checkout all ship the real file.
13
+ */
14
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
15
+
16
+ export const VERSION = pkg.version;
17
+
18
+ /**
19
+ * `kronk version 1.32.7\n` -> `1.32.7`. `runKronk(['--version'])` is the one
20
+ * door this program uses to ask the `kronk` binary anything, and this is the
21
+ * one place that makes sense of what comes back. Falls back to the first line
22
+ * rather than to null, on the theory that an unexpected format is still more
23
+ * informative on screen than nothing — but only the first line, and only so
24
+ * much of it: `runKronk` captures up to CAPTURE_CAP of whatever the binary
25
+ * decided to print, and `--version` is one line of output, not a place to
26
+ * empty a stack trace into.
27
+ */
28
+ const STRAY_MAX = 60;
29
+
30
+ export function parseKronkVersion(stdout) {
31
+ const m = String(stdout).match(/version\s+(\S+)/i);
32
+ if (m) return m[1];
33
+ const first = String(stdout).split('\n')[0].trim();
34
+ return first ? first.slice(0, STRAY_MAX) : null;
35
+ }