From 132e0c1cafc09a620c990404a1ee6c4f05371d6c Mon Sep 17 00:00:00 2001 From: wized2 Date: Mon, 14 Sep 2026 08:25:05 +0000 Subject: [PATCH 1/3] feat(cli): add --version / -V Prints package.json version. Documented in --help. --- test/cli.test.mjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/cli.test.mjs b/test/cli.test.mjs index f0eba43..a686546 100644 --- a/test/cli.test.mjs +++ b/test/cli.test.mjs @@ -1,5 +1,5 @@ import assert from "node:assert/strict"; -import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { spawnSync } from "node:child_process"; @@ -56,3 +56,14 @@ test("accepts zero as a compact token budget", () => { assert.equal(result.status, 0, result.stderr); assert.doesNotThrow(() => JSON.parse(result.stdout)); }); + + +test("--version prints package version", () => { + const r = spawnSync(process.execPath, ["bin/tokencut.mjs", "--version"], { + cwd: new URL("..", import.meta.url), + encoding: "utf8", + }); + assert.equal(r.status, 0); + const ver = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version; + assert.equal(r.stdout.trim(), ver); +}); From 1983d0c2e23e8e99ee011cf77e02ae35b0885772 Mon Sep 17 00:00:00 2001 From: wized2 Date: Mon, 14 Sep 2026 08:25:18 +0000 Subject: [PATCH 2/3] fix: include --version implementation in CLI --- bin/tokencut.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/tokencut.mjs b/bin/tokencut.mjs index e408a75..9e69c22 100644 --- a/bin/tokencut.mjs +++ b/bin/tokencut.mjs @@ -18,6 +18,7 @@ if (!file || has("--help")) { --out write the compacted payload --price $ per 1M input tokens for the cost estimate (default 3) --json machine-readable output + --version, -V print package version Payload: an array of messages, or { system, messages } (Anthropic or OpenAI style).`); process.exit(file ? 0 : 1); From 811b61d9ec0d92c7ac89c7db53ce18af6bc14d4f Mon Sep 17 00:00:00 2001 From: wized2 Date: Mon, 14 Sep 2026 08:25:40 +0000 Subject: [PATCH 3/3] fix: implement --version against current CLI parser --- bin/tokencut.mjs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/tokencut.mjs b/bin/tokencut.mjs index 9e69c22..fa2e56d 100644 --- a/bin/tokencut.mjs +++ b/bin/tokencut.mjs @@ -7,6 +7,16 @@ const flag = (name, def) => { const i = args.indexOf(name); return i >= 0 ? (arg const has = (name) => args.includes(name); const file = args.find((a) => !a.startsWith("--") && args[args.indexOf(a) - 1] !== "--max" && args[args.indexOf(a) - 1] !== "--max-tool" && args[args.indexOf(a) - 1] !== "--price" && args[args.indexOf(a) - 1] !== "--out"); +if (has("--version") || has("-V")) { + try { + const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")); + console.log(pkg.version ?? "0.0.0"); + } catch { + console.log("0.0.0"); + } + process.exit(0); +} + if (!file || has("--help")) { console.log(`tokencut -- measure and cut the token cost of an LLM/agent payload