sessioncost 0.5.15 → 0.6.0-rc.10
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/bin/sessioncost.js +28 -6
- package/package.json +1 -1
package/bin/sessioncost.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// The first run makes a private Python environment in ~/.sessioncost/npm/venv and installs this exact version of
|
|
5
5
|
// SessionCost there (from PyPI; from the folder around this one when it sits in a SessionCost source tree, as in a
|
|
6
6
|
// test build). Later runs only start it. With uv on the PATH, uv makes the environment and fetches Python itself
|
|
7
|
-
// when none is installed; without it, a Python 3.10 or newer on the PATH is used
|
|
7
|
+
// when none is installed; without it, a Python 3.10 or newer on the PATH is used; with neither, uv is installed
|
|
8
|
+
// first (its own installer from astral.sh). The environment stays: `setup` and
|
|
8
9
|
// the guard write the path of the Python they run with into each agent's settings.
|
|
9
10
|
// Nothing here reads or sends your sessions; the install only fetches SessionCost itself.
|
|
10
11
|
"use strict";
|
|
@@ -71,6 +72,22 @@ function findPython(which = onPath, runner = run) {
|
|
|
71
72
|
return null;
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
// Neither uv nor Python here: run uv's own installer (as install.ps1 / install.sh do) and return the uv it put in
|
|
76
|
+
// place, or null. uv then fetches Python by itself, so a computer with only Node.js works.
|
|
77
|
+
function fetchUv(runner = run, env = process.env, exists = (f) => fs.existsSync(f), homedir = os.homedir()) {
|
|
78
|
+
const cmd = WINDOWS
|
|
79
|
+
? ["powershell", ["-NoProfile", "-ExecutionPolicy", "ByPass", "-Command", "irm https://astral.sh/uv/install.ps1 | iex"]]
|
|
80
|
+
: ["sh", ["-c", "curl -LsSf https://astral.sh/uv/install.sh | sh"]];
|
|
81
|
+
const r = runner(cmd[0], cmd[1], INSTALL_MS);
|
|
82
|
+
if (!r.ok) return null;
|
|
83
|
+
const name = WINDOWS ? "uv.exe" : "uv";
|
|
84
|
+
const dirs = [env.UV_INSTALL_DIR, env.XDG_BIN_HOME, path.join(homedir, ".local", "bin")].filter(Boolean);
|
|
85
|
+
for (const d of dirs) {
|
|
86
|
+
if (exists(path.join(d, name))) return path.join(d, name);
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
74
91
|
// The steps that make the environment and install SessionCost into it: [[command, args], ...], or null.
|
|
75
92
|
function installSteps(venv, what, which = onPath, runner = run) {
|
|
76
93
|
const py = venvPython(venv);
|
|
@@ -95,11 +112,16 @@ function main(argv = process.argv.slice(2), env = process.env) {
|
|
|
95
112
|
let have = "";
|
|
96
113
|
try { have = fs.readFileSync(stamp, "utf8").trim(); } catch (e) { /* first run */ }
|
|
97
114
|
if (have !== want || !fs.existsSync(py)) {
|
|
98
|
-
|
|
115
|
+
let steps = installSteps(venv, what);
|
|
116
|
+
if (!steps) {
|
|
117
|
+
console.error("SessionCost runs on Python, and this computer has neither Python nor uv: installing uv " +
|
|
118
|
+
"(https://docs.astral.sh/uv/), which fetches Python by itself …");
|
|
119
|
+
const uv = fetchUv();
|
|
120
|
+
if (uv) steps = installSteps(venv, what, (n) => (n === "uv" ? uv : null));
|
|
121
|
+
}
|
|
99
122
|
if (!steps) {
|
|
100
|
-
console.error("
|
|
101
|
-
"
|
|
102
|
-
"then run npx sessioncost again.");
|
|
123
|
+
console.error("uv could not be installed. Install uv (https://docs.astral.sh/uv/getting-started/installation/) " +
|
|
124
|
+
"or Python 3.10 or newer (https://www.python.org/downloads/), then run npx sessioncost again.");
|
|
103
125
|
return 1;
|
|
104
126
|
}
|
|
105
127
|
console.error(`SessionCost ${VERSION}: installing once into ${venv} …`);
|
|
@@ -125,6 +147,6 @@ function main(argv = process.argv.slice(2), env = process.env) {
|
|
|
125
147
|
return r.status === null ? 1 : r.status;
|
|
126
148
|
}
|
|
127
149
|
|
|
128
|
-
module.exports = { spec, findPython, installSteps, venvPython, home, main, VERSION };
|
|
150
|
+
module.exports = { spec, findPython, fetchUv, installSteps, venvPython, home, main, VERSION };
|
|
129
151
|
|
|
130
152
|
if (require.main === module) process.exitCode = main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sessioncost",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-rc.10",
|
|
4
4
|
"description": "See how many tokens each turn of your coding-agent chat sends, why, and what to cut. Runs the SessionCost Python tool (installs it once, privately).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "kish21",
|