agenttune-cli 0.0.0-stage → 0.2.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.
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # agenttune-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Collects token-usage metrics from Claude Code transcripts, sends them to agenttune-api, and applies the returned optimization plan. See `../.docs/token-optimizer-implementation-plan.md`.
4
+
5
+ ## Usage
6
+
7
+ Run with Node.js 18 or newer and npm.
8
+
9
+ ```sh
10
+ npx agenttune-cli version
11
+ npx agenttune-cli evaluate --key <uuid>
12
+ ```
13
+
14
+ For a global install, run `npm install -g agenttune-cli` and invoke `agenttune`.
15
+ The native binary uses the same command name.
16
+
17
+ ```
18
+ agenttune evaluate --key <uuid> [--api <url>] [--dry-run]
19
+ agenttune version
20
+ ```
21
+
22
+ `evaluate` and `apply` use `https://api.agenttune.si` by default. To use a local
23
+ API, pass `--api http://localhost:8080`.
24
+
25
+ `--dry-run` prints the payload without submitting it. Add `--no-replay` to skip
26
+ fetching analyzers and run offline. Point the CLI at a copy
27
+ of the Claude setup instead of the real one with `--config-dir <path>` (env
28
+ `TOKENTUNE_CONFIG_DIR`) and `--agenttune-dir <path>` (env `TOKENTUNE_DIR`);
29
+ `make sandbox` creates such a copy under `/tmp/agenttune-sandbox` and prints
30
+ the exports.
31
+
32
+ Missing Claude config or `projects` directories are treated as empty history.
33
+ Missing optional settings, skills, hooks, and state files use empty defaults.
34
+ When no usable sessions are found, `evaluate` explains this on stderr and still
35
+ prints JSON on stdout; it skips analyzer downloads and does not require Node.
36
+ A normal evaluation still needs the API, which returns `insufficient_data`
37
+ until enough usable sessions exist. A dry run with empty history works offline.
38
+ Missing rollback manifests mean nothing was applied; missing backup files are
39
+ reported as errors and never reported as a successful rollback.
40
+
41
+ ## Packaging
42
+
43
+ GoReleaser cross-compiles `./cmd/tokentune` for macOS, Linux, and Windows on
44
+ x64 and arm64. The `agenttune-cli` npm package launches the matching native
45
+ binary from a platform-specific `@agenttune/cli-*` optional dependency.
46
+ `make release-snapshot npm-pack npm-test` builds and tests the npm tarballs
47
+ locally. See the [npm release runbook](npm/README.md) for publishing.
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Launches the platform-specific agenttune binary. The binary ships in
5
+ // @agenttune/cli-<platform>-<arch>, which npm installs through the
6
+ // optionalDependencies of this package (the esbuild pattern). No postinstall.
7
+
8
+ const { spawn } = require('child_process');
9
+ const { optionalDependencies } = require('../package.json');
10
+
11
+ const target = `${process.platform}-${process.arch}`;
12
+ const packageName = `@agenttune/cli-${target}`;
13
+ const exe = process.platform === 'win32' ? 'agenttune.exe' : 'agenttune';
14
+
15
+ if (!Object.hasOwn(optionalDependencies ?? {}, packageName)) {
16
+ console.error(`agenttune: unsupported platform ${target}.`);
17
+ process.exit(1);
18
+ }
19
+
20
+ let binary;
21
+ try {
22
+ binary = require.resolve(`${packageName}/bin/${exe}`);
23
+ } catch (error) {
24
+ if (error.code !== 'MODULE_NOT_FOUND') throw error;
25
+ console.error(
26
+ `agenttune: missing ${packageName}@${optionalDependencies[packageName]}.\n` +
27
+ 'Check that your npm registry has the package and reinstall with --include=optional.'
28
+ );
29
+ process.exit(1);
30
+ }
31
+
32
+ const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit' });
33
+
34
+ child.on('error', (err) => {
35
+ console.error(`agenttune: failed to start ${binary}: ${err.message}`);
36
+ process.exit(1);
37
+ });
38
+
39
+ const signals = process.platform === 'win32' ? ['SIGINT', 'SIGTERM'] : ['SIGINT', 'SIGTERM', 'SIGHUP'];
40
+ function forwardSignal(signal) {
41
+ child.kill(signal);
42
+ }
43
+
44
+ for (const signal of signals) {
45
+ process.on(signal, forwardSignal);
46
+ }
47
+
48
+ child.on('exit', (code, signal) => {
49
+ for (const forwardedSignal of signals) {
50
+ process.removeListener(forwardedSignal, forwardSignal);
51
+ }
52
+ if (signal) {
53
+ process.kill(process.pid, signal);
54
+ return;
55
+ }
56
+ process.exit(code === null ? 1 : code);
57
+ });
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "agenttune-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "Collects Claude Code token-usage metrics and applies the agenttune optimization plan",
4
+ "bin": {
5
+ "agenttune": "bin/agenttune.js"
6
+ },
7
+ "files": [
8
+ "bin"
9
+ ],
10
+ "engines": {
11
+ "node": ">=18"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/agenttune/agenttune-cli.git"
16
+ },
17
+ "version": "0.2.1",
18
+ "optionalDependencies": {
19
+ "@agenttune/cli-darwin-x64": "0.2.1",
20
+ "@agenttune/cli-darwin-arm64": "0.2.1",
21
+ "@agenttune/cli-linux-x64": "0.2.1",
22
+ "@agenttune/cli-linux-arm64": "0.2.1",
23
+ "@agenttune/cli-win32-x64": "0.2.1",
24
+ "@agenttune/cli-win32-arm64": "0.2.1"
25
+ }
26
+ }