ccost 0.0.1-alpha.0 → 0.0.3
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/install.js +140 -0
- package/package.json +38 -4
- package/run.js +23 -0
package/install.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const http = require("http");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const { execSync } = require("child_process");
|
|
8
|
+
const os = require("os");
|
|
9
|
+
|
|
10
|
+
if (process.env.CCOST_SKIP_INSTALL) {
|
|
11
|
+
console.log("Skipping ccost binary download (CCOST_SKIP_INSTALL is set)");
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const VERSION = require("./package.json").version;
|
|
16
|
+
const REPO = "toolsu/ccost";
|
|
17
|
+
|
|
18
|
+
function getPlatformName() {
|
|
19
|
+
const platform = process.platform;
|
|
20
|
+
const arch = process.arch;
|
|
21
|
+
|
|
22
|
+
if (platform === "darwin") {
|
|
23
|
+
if (arch === "x64") return "darwin-x64";
|
|
24
|
+
if (arch === "arm64") return "darwin-arm64";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (platform === "win32") {
|
|
28
|
+
if (arch === "x64") return "win32-x64";
|
|
29
|
+
if (arch === "ia32") return "win32-ia32";
|
|
30
|
+
if (arch === "arm64") return "win32-arm64";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (platform === "linux") {
|
|
34
|
+
const musl = isMusl();
|
|
35
|
+
if (arch === "x64") return musl ? "linux-x64-musl" : "linux-x64";
|
|
36
|
+
if (arch === "arm64") return musl ? "linux-arm64-musl" : "linux-arm64";
|
|
37
|
+
if (arch === "ia32") return "linux-ia32";
|
|
38
|
+
if (arch === "arm") return "linux-arm";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isMusl() {
|
|
45
|
+
try {
|
|
46
|
+
if (fs.existsSync("/etc/alpine-release")) return true;
|
|
47
|
+
} catch {}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const output = execSync("ldd --version 2>&1", { encoding: "utf8" });
|
|
51
|
+
if (output.toLowerCase().includes("musl")) return true;
|
|
52
|
+
} catch (e) {
|
|
53
|
+
const out = [e.stdout, e.stderr].filter(Boolean).join("").toLowerCase();
|
|
54
|
+
if (out.includes("musl")) return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function download(url) {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const client = url.startsWith("https") ? https : http;
|
|
63
|
+
client
|
|
64
|
+
.get(url, { headers: { "User-Agent": "ccost-npm" } }, (res) => {
|
|
65
|
+
if (
|
|
66
|
+
res.statusCode >= 300 &&
|
|
67
|
+
res.statusCode < 400 &&
|
|
68
|
+
res.headers.location
|
|
69
|
+
) {
|
|
70
|
+
res.resume();
|
|
71
|
+
download(res.headers.location).then(resolve, reject);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (res.statusCode !== 200) {
|
|
75
|
+
res.resume();
|
|
76
|
+
reject(new Error(`HTTP ${res.statusCode} from ${url}`));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const chunks = [];
|
|
80
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
81
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
82
|
+
res.on("error", reject);
|
|
83
|
+
})
|
|
84
|
+
.on("error", reject);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function main() {
|
|
89
|
+
const platformName = getPlatformName();
|
|
90
|
+
if (!platformName) {
|
|
91
|
+
console.error(
|
|
92
|
+
`Unsupported platform: ${process.platform}-${process.arch}\n` +
|
|
93
|
+
"Install from source: cargo install ccost"
|
|
94
|
+
);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const isWindows = process.platform === "win32";
|
|
99
|
+
const ext = isWindows ? ".zip" : ".tar.gz";
|
|
100
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/ccost-${platformName}${ext}`;
|
|
101
|
+
|
|
102
|
+
console.log(`Downloading ccost v${VERSION} for ${platformName}...`);
|
|
103
|
+
|
|
104
|
+
let data;
|
|
105
|
+
try {
|
|
106
|
+
data = await download(url);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
console.error(
|
|
109
|
+
`Failed to download from ${url}\n${err.message}\n` +
|
|
110
|
+
"Install from source: cargo install ccost"
|
|
111
|
+
);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const binDir = path.join(__dirname, "bin");
|
|
116
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
117
|
+
|
|
118
|
+
const tmpFile = path.join(os.tmpdir(), `ccost-${Date.now()}${ext}`);
|
|
119
|
+
fs.writeFileSync(tmpFile, data);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
if (isWindows) {
|
|
123
|
+
execSync(`tar -xf "${tmpFile}" -C "${binDir}"`, { stdio: "ignore" });
|
|
124
|
+
} else {
|
|
125
|
+
execSync(`tar xzf "${tmpFile}" -C "${binDir}"`, { stdio: "ignore" });
|
|
126
|
+
fs.chmodSync(path.join(binDir, "ccost"), 0o755);
|
|
127
|
+
}
|
|
128
|
+
} finally {
|
|
129
|
+
try {
|
|
130
|
+
fs.unlinkSync(tmpFile);
|
|
131
|
+
} catch {}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
console.log(`ccost v${VERSION} installed successfully.`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
main().catch((err) => {
|
|
138
|
+
console.error("Failed to install ccost:", err.message);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
});
|
package/package.json
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccost",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Analyze Claude Code token usage and costs from local conversation history",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/toolsu/ccost"
|
|
8
|
+
},
|
|
9
|
+
"author": "Tom Chen",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bin": {
|
|
12
|
+
"ccost": "run.js"
|
|
13
|
+
},
|
|
5
14
|
"scripts": {
|
|
6
|
-
"
|
|
15
|
+
"postinstall": "node install.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"install.js",
|
|
19
|
+
"run.js"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=14"
|
|
7
23
|
},
|
|
8
|
-
"
|
|
24
|
+
"os": [
|
|
25
|
+
"darwin",
|
|
26
|
+
"linux",
|
|
27
|
+
"win32"
|
|
28
|
+
],
|
|
29
|
+
"cpu": [
|
|
30
|
+
"x64",
|
|
31
|
+
"arm64",
|
|
32
|
+
"ia32",
|
|
33
|
+
"arm"
|
|
34
|
+
],
|
|
35
|
+
"keywords": [
|
|
36
|
+
"claude",
|
|
37
|
+
"token",
|
|
38
|
+
"usage",
|
|
39
|
+
"cost",
|
|
40
|
+
"anthropic",
|
|
41
|
+
"claude-code"
|
|
42
|
+
]
|
|
9
43
|
}
|
package/run.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { spawnSync } = require("child_process");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
|
|
8
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
9
|
+
const bin = path.join(__dirname, "bin", `ccost${ext}`);
|
|
10
|
+
const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
11
|
+
|
|
12
|
+
if (result.error) {
|
|
13
|
+
if (result.error.code === "ENOENT") {
|
|
14
|
+
console.error(
|
|
15
|
+
"ccost binary not found. Try reinstalling:\n npm install -g ccost"
|
|
16
|
+
);
|
|
17
|
+
} else {
|
|
18
|
+
console.error("Failed to run ccost:", result.error.message);
|
|
19
|
+
}
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
process.exit(result.status ?? 1);
|