runcap 0.2.0 → 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/bin/runcap.mjs CHANGED
@@ -36,7 +36,7 @@ const args = process.argv.slice(2);
36
36
  const command = args[0] ?? "welcome";
37
37
 
38
38
  function usage() {
39
- console.log(`Runcap cap every agent run before it starts
39
+ console.log(`Runcap: cap every agent run before it starts
40
40
 
41
41
  Usage:
42
42
  runcap run [--label name] [--cap|--no-cap] [--mock] -- <command...>
@@ -90,6 +90,16 @@ function takeFlag(input, name) {
90
90
  return true;
91
91
  }
92
92
 
93
+ // A real call can cost a fraction of a cent. toFixed(2)/(4) would print $0.00 or
94
+ // $0.0000 and read as "nothing was recorded", so show a meaningful figure for
95
+ // sub-cent spend instead of rounding a real charge down to zero.
96
+ function fmtUsd(n) {
97
+ if (!(n > 0)) return "$0.00";
98
+ if (n >= 0.01) return `$${n.toFixed(2)}`;
99
+ if (n >= 0.0001) return `$${n.toFixed(4)}`;
100
+ return `$${n.toPrecision(2)}`;
101
+ }
102
+
93
103
  try {
94
104
  if (command === "welcome") {
95
105
  console.log(await welcome());
@@ -125,7 +135,7 @@ try {
125
135
  if (result.capSummary) {
126
136
  const c = result.capSummary;
127
137
  const capLine = c.capUsd === null ? "no cap" : `cap $${c.capUsd.toFixed(2)}`;
128
- console.log(`\nRuncap: cap enforced (${capLine}). This run spent ~$${c.spentThisRunUsd.toFixed(4)} (window total $${c.spentWindowUsd.toFixed(4)}).`);
138
+ console.log(`\nRuncap: cap enforced (${capLine}). This run spent ~${fmtUsd(c.spentThisRunUsd)} (window total ${fmtUsd(c.spentWindowUsd)}).`);
129
139
  }
130
140
  } else if (command === "preflight") {
131
141
  const runArgs = args.slice(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runcap",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Cap every agent run before it starts: estimate cost, set a hard ceiling that stops the run, rescue stuck agents. Local, MIT, nothing uploaded.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/alerts.mjs CHANGED
@@ -131,7 +131,7 @@ export async function alertsCommand(args) {
131
131
  if (sub === "test") {
132
132
  const license = await readLicense();
133
133
  if (!license) return "Alerts are Pro-only. Run `runcap login <key>` first.";
134
- const results = await sendAlert("Runcap test alert your cap-breach notifications are working.");
134
+ const results = await sendAlert("Runcap test alert: your cap-breach notifications are working.");
135
135
  if (!results) return "No channels configured. Add one with `runcap alerts add ...`.";
136
136
  return `Test sent to: ${results.join(", ")}`;
137
137
  }
@@ -247,6 +247,16 @@ export async function planMission(goal, options = {}) {
247
247
 
248
248
  // Persist a hard cap to .runcap/budget.json so the gateway enforces it without
249
249
  // the user manually exporting AIM_DAILY_BUDGET_USD. env still wins if set.
250
+ // Show a meaningful figure for sub-cent spend; a real call can cost a fraction
251
+ // of a cent, and rounding it to $0.00 reads as "nothing was recorded".
252
+ function fmtUsd(n) {
253
+ const v = Number(n);
254
+ if (!(v > 0)) return "$0.00";
255
+ if (v >= 0.01) return `$${v.toFixed(2)}`;
256
+ if (v >= 0.0001) return `$${v.toFixed(4)}`;
257
+ return `$${v.toPrecision(2)}`;
258
+ }
259
+
250
260
  export async function setBudgetCap(capUsd, { source = "manual" } = {}) {
251
261
  await ensureStore();
252
262
  const value = Number(capUsd);
@@ -413,7 +423,7 @@ export async function welcome() {
413
423
  " runcap run -- codex \"...\" runcap run -- python my_agent.py",
414
424
  "",
415
425
  gateway.callCount > 0
416
- ? `Spent so far this ${window}: $${gateway.estimatedCostUsd.toFixed(4)} across ${gateway.callCount} calls. See: runcap status`
426
+ ? `Spent so far this ${window}: ${fmtUsd(gateway.estimatedCostUsd)} across ${gateway.callCount} calls. See: runcap status`
417
427
  : "No calls recorded yet. Your first `runcap run` will show the spend."
418
428
  ];
419
429
  }