sessioncost 1.2.0 → 1.2.2
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 +27 -15
- package/package.json +1 -1
package/bin/sessioncost.js
CHANGED
|
@@ -119,8 +119,32 @@ function installed(env = process.env, here = __dirname) {
|
|
|
119
119
|
return have === w.want && fs.existsSync(w.py);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// Runs the install steps (installSteps); true when this version is in place. An older version already there is
|
|
123
|
+
// upgraded in place: its environment is never deleted, because `setup` wrote its Python into every agent's guard
|
|
124
|
+
// hooks (deleting it first left the guard off while installing, and for good when the install failed).
|
|
125
|
+
function install(w, steps, runner = run) {
|
|
126
|
+
const older = fs.existsSync(w.py);
|
|
127
|
+
if (!older) {
|
|
128
|
+
fs.rmSync(w.venv, { recursive: true, force: true }); // a half-made one from an earlier failed try
|
|
129
|
+
fs.mkdirSync(w.dir, { recursive: true });
|
|
130
|
+
}
|
|
131
|
+
for (const [cmd, args] of older ? steps.slice(1) : steps) { // step 1 makes the environment
|
|
132
|
+
const r = runner(cmd, args, INSTALL_MS);
|
|
133
|
+
if (!r.ok) {
|
|
134
|
+
console.error(`SessionCost could not be installed: ${path.basename(cmd)} ${args.join(" ")}\n${r.err || ""}`.trim());
|
|
135
|
+
console.error(older ? "The version you had keeps working. Check your internet connection, then run npx sessioncost again."
|
|
136
|
+
: "Check your internet connection, then run npx sessioncost again.");
|
|
137
|
+
if (!older) fs.rmSync(w.venv, { recursive: true, force: true });
|
|
138
|
+
return false; // the old stamp stays: the next run tries again
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
fs.writeFileSync(w.stamp, w.want + "\n");
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
122
145
|
function main(argv = process.argv.slice(2), env = process.env) {
|
|
123
|
-
const
|
|
146
|
+
const w = where(env);
|
|
147
|
+
const { venv, what, py } = w;
|
|
124
148
|
if (!installed(env)) {
|
|
125
149
|
let steps = installSteps(venv, what);
|
|
126
150
|
if (!steps) {
|
|
@@ -135,19 +159,7 @@ function main(argv = process.argv.slice(2), env = process.env) {
|
|
|
135
159
|
return 1;
|
|
136
160
|
}
|
|
137
161
|
console.error(`SessionCost ${VERSION}: installing once into ${venv} …`);
|
|
138
|
-
|
|
139
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
140
|
-
fs.rmSync(stamp, { force: true });
|
|
141
|
-
for (const [cmd, args] of steps) {
|
|
142
|
-
const r = run(cmd, args, INSTALL_MS);
|
|
143
|
-
if (!r.ok) {
|
|
144
|
-
console.error(`SessionCost could not be installed: ${path.basename(cmd)} ${args.join(" ")}\n${r.err}`.trim());
|
|
145
|
-
console.error("Check your internet connection, then run npx sessioncost again.");
|
|
146
|
-
fs.rmSync(venv, { recursive: true, force: true });
|
|
147
|
-
return 1;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
fs.writeFileSync(stamp, want + "\n");
|
|
162
|
+
if (!install(w, steps)) return 1;
|
|
151
163
|
}
|
|
152
164
|
const r = spawnSync(py, ["-m", "sessioncost", ...argv], { stdio: "inherit" });
|
|
153
165
|
if (r.error) {
|
|
@@ -157,6 +169,6 @@ function main(argv = process.argv.slice(2), env = process.env) {
|
|
|
157
169
|
return r.status === null ? 1 : r.status;
|
|
158
170
|
}
|
|
159
171
|
|
|
160
|
-
module.exports = { spec, findPython, fetchUv, installSteps, venvPython, home, where, installed, main, VERSION };
|
|
172
|
+
module.exports = { spec, findPython, fetchUv, installSteps, install, venvPython, home, where, installed, main, VERSION };
|
|
161
173
|
|
|
162
174
|
if (require.main === module) process.exitCode = main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sessioncost",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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",
|