sessioncost 1.1.4 → 1.2.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/bin/sessioncost.js +18 -8
- package/package.json +1 -1
package/bin/sessioncost.js
CHANGED
|
@@ -102,16 +102,26 @@ function installSteps(venv, what, which = onPath, runner = run) {
|
|
|
102
102
|
[py, ["-m", "pip", "install", "--quiet", "--disable-pip-version-check", "--force-reinstall", "--no-deps", what]]];
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
// Where this version lives and what its stamp must say. The editor extension asks the same (installed, below).
|
|
106
|
+
function where(env = process.env, here = __dirname) {
|
|
106
107
|
const dir = home(env);
|
|
107
108
|
const venv = path.join(dir, "venv");
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
const what = spec(env, here);
|
|
110
|
+
return { dir, venv, py: venvPython(venv), what, want: `${VERSION} ${what}`,
|
|
111
|
+
stamp: path.join(dir, "installed.txt") }; // what is in the environment: changes when this package does
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// This version is in place and ready to start: its environment exists and its stamp matches.
|
|
115
|
+
function installed(env = process.env, here = __dirname) {
|
|
116
|
+
const w = where(env, here);
|
|
112
117
|
let have = "";
|
|
113
|
-
try { have = fs.readFileSync(stamp, "utf8").trim(); } catch (e) { /*
|
|
114
|
-
|
|
118
|
+
try { have = fs.readFileSync(w.stamp, "utf8").trim(); } catch (e) { /* not installed yet */ }
|
|
119
|
+
return have === w.want && fs.existsSync(w.py);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function main(argv = process.argv.slice(2), env = process.env) {
|
|
123
|
+
const { dir, venv, stamp, what, want, py } = where(env);
|
|
124
|
+
if (!installed(env)) {
|
|
115
125
|
let steps = installSteps(venv, what);
|
|
116
126
|
if (!steps) {
|
|
117
127
|
console.error("SessionCost runs on Python, and this computer has neither Python nor uv: installing uv " +
|
|
@@ -147,6 +157,6 @@ function main(argv = process.argv.slice(2), env = process.env) {
|
|
|
147
157
|
return r.status === null ? 1 : r.status;
|
|
148
158
|
}
|
|
149
159
|
|
|
150
|
-
module.exports = { spec, findPython, fetchUv, installSteps, venvPython, home, main, VERSION };
|
|
160
|
+
module.exports = { spec, findPython, fetchUv, installSteps, venvPython, home, where, installed, main, VERSION };
|
|
151
161
|
|
|
152
162
|
if (require.main === module) process.exitCode = main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sessioncost",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|