feat: installer pricing keep/refresh (0.9.1)
install() silently kept any pricing.json already beside the plugin, so reships shipped new code with old tables - that keep is exactly how the Hermes plugin lost the credit-pool (mistral-api) tables between 0.5.0 and 0.9.0, and the 0.9.0 fix needed a manual file deletion. The installer now prints a hint when the kept table differs from the bundled one, and --refresh-pricing ships the bundled table instead (top-level flag next to --integrate hermes, plus an installer flag for standalone runs; default unchanged - owner rate edits in the installed copy still win). SPEC, SKILL, and the installer docstring updated. PATCH to 0.9.1 (new-flag- as-patch precedent: --rm-integrate, 0.4.6 -> 0.4.7). 130 tests pass. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -250,6 +250,26 @@ And add the cost information to this file for the current session.
|
||||
|
||||
---
|
||||
|
||||
#### (pending) - feat: installer pricing keep/refresh (0.9.1)
|
||||
- **Date**: 2026-11-11
|
||||
- **Model**: mistral-vibe:zai-glm-5-3
|
||||
- **Session Cost**: $3.22 (running total at commit time)
|
||||
- **Turn Cost**: $0.87
|
||||
- **Total for commit**: $3.22
|
||||
- **Notes**: the 0.9.0 fix needed a manual deletion of the
|
||||
installed pricing.json because install() silently keeps any
|
||||
table that is already beside the plugin - that keep is how the
|
||||
plugin lost the pool tables in the first place. The installer
|
||||
now prints a hint when the kept table differs from the bundled
|
||||
one, and --refresh-pricing (top-level flag for
|
||||
--integrate hermes, installer flag for standalone runs) ships
|
||||
the bundled table instead of keeping the installed one. Keep
|
||||
default unchanged (owner rate edits win). PATCH bump to 0.9.1
|
||||
(precedent: --rm-integrate shipped as 0.4.6 -> 0.4.7); SPEC,
|
||||
SKILL, installer docstring updated; 130 tests pass.
|
||||
|
||||
---
|
||||
|
||||
## Instructions for Contributors
|
||||
|
||||
1. Before committing, run `agent-cost-estimator` for your current session
|
||||
|
||||
@@ -830,8 +830,11 @@ install; Hermes: `agent_cost_estimator.integration.hermes.install`).
|
||||
1. Validates the Hermes home (`state.db` or `config.yaml` present)
|
||||
2. Copies the plugin (`plugin.yaml`, `__init__.py`) to
|
||||
`<home>/plugins/agent-cost-estimator/`
|
||||
3. Ships `pricing.json` next to the plugin (preserves an
|
||||
already-tuned installed table on reinstall)
|
||||
3. Ships `pricing.json` next to the plugin (preserves an installed
|
||||
table on reinstall — rate edits live in the installed copy — and
|
||||
prints a hint when it differs from the bundled one;
|
||||
`--refresh-pricing` ships the bundled table instead, dropping
|
||||
local edits)
|
||||
4. Runs `hermes plugins enable agent-cost-estimator` (prints the
|
||||
manual step when the `hermes` CLI is not on PATH)
|
||||
|
||||
@@ -840,6 +843,7 @@ install; Hermes: `agent_cost_estimator.integration.hermes.install`).
|
||||
```bash
|
||||
agent-cost-estimator --integrate mistral
|
||||
agent-cost-estimator --integrate hermes
|
||||
agent-cost-estimator --integrate hermes --refresh-pricing
|
||||
agent-cost-estimator --rm-integrate hermes
|
||||
```
|
||||
|
||||
@@ -1549,7 +1553,7 @@ hermes plugins list --plain --no-bundled # shows the enabled plugin
|
||||
- Hermes plugin (hook registration, CanonicalUsage bucket folding,
|
||||
record + print, subagent/single-query gating, pricing sources)
|
||||
- Hermes installer (dry-run, home validation, plugin + pricing copy,
|
||||
uninstall)
|
||||
pricing keep/refresh, uninstall)
|
||||
- Harness registry
|
||||
- CLI (pricing flags, -t, -s, --json, --update-pricing, --integrate, error exits)
|
||||
|
||||
|
||||
@@ -54,6 +54,12 @@ def parse_args(argv):
|
||||
help="install hooks for the specified harness "
|
||||
"(e.g., 'mistral', 'mistral-vibe-cli', 'mistral-vibe-code')",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--refresh-pricing", action="store_true",
|
||||
help="with --integrate hermes: ship the bundled pricing.json "
|
||||
"instead of keeping the installed table (drops local "
|
||||
"rate edits made in the installed copy)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--session-id", default=None,
|
||||
help="session id or session directory (default: most "
|
||||
@@ -124,7 +130,7 @@ def parse_args(argv):
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def integrate_hooks(harness_name):
|
||||
def integrate_hooks(harness_name, refresh_pricing=False):
|
||||
"""Install hooks for the specified harness.
|
||||
|
||||
Currently supports:
|
||||
@@ -140,7 +146,9 @@ def integrate_hooks(harness_name):
|
||||
|
||||
Args:
|
||||
harness_name: Name of the harness to integrate
|
||||
|
||||
refresh_pricing: Hermes only - ship the bundled pricing.json
|
||||
instead of keeping the installed table
|
||||
|
||||
Returns 0 on success, 1 on error.
|
||||
"""
|
||||
import os
|
||||
@@ -163,8 +171,11 @@ def integrate_hooks(harness_name):
|
||||
# Hermes integration is a plugin, not a hook script: one call
|
||||
# copies the plugin, ships pricing.json, enables it, and
|
||||
# restarts a running gateway daemon so it re-imports it.
|
||||
# refresh_pricing forwards the top-level --refresh-pricing
|
||||
# flag: drop the kept installed table, ship the bundled one.
|
||||
from agent_cost_estimator.integration.hermes.install import main as hermes_install
|
||||
return hermes_install([])
|
||||
args = ["--refresh-pricing"] if refresh_pricing else []
|
||||
return hermes_install(args)
|
||||
|
||||
supported_harnesses = ["mistral-vibe-cli", "mistral-vibe-code"]
|
||||
if canonical_name not in supported_harnesses:
|
||||
@@ -715,7 +726,8 @@ def main(argv=None):
|
||||
print("error: --integrate requires a harness name argument (e.g., 'mistral')",
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
return integrate_hooks(args.integrate)
|
||||
return integrate_hooks(args.integrate,
|
||||
refresh_pricing=args.refresh_pricing)
|
||||
if args.rm_integrate:
|
||||
if not args.rm_integrate:
|
||||
print("error: --rm-integrate requires a harness name argument (e.g., 'mistral-vibe-code')",
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
Usage:
|
||||
python -m agent_cost_estimator.integration.hermes.install
|
||||
[--hermes-home DIR] [--uninstall] [--dry-run]
|
||||
[--hermes-home DIR] [--uninstall] [--dry-run] [--refresh-pricing]
|
||||
|
||||
Or, from a source checkout / any machine with the package installed:
|
||||
python path/to/agent-cost-estimator/agent_cost_estimator/integration/hermes/install.py
|
||||
[--hermes-home DIR] [--uninstall] [--dry-run]
|
||||
[--hermes-home DIR] [--uninstall] [--dry-run] [--refresh-pricing]
|
||||
|
||||
What it does (idempotent):
|
||||
1. Copies the plugin (plugin.yaml + __init__.py + display.py) to
|
||||
@@ -15,8 +15,10 @@ What it does (idempotent):
|
||||
cost/token line format (a verbatim copy of
|
||||
agent_cost_estimator.display), so the plugin renders exactly
|
||||
what the CLI, GUI, and Vibe hooks render (display-path parity)
|
||||
2. Ships pricing.json beside the plugin (an existing tuned table is
|
||||
kept across reinstalls)
|
||||
2. Ships pricing.json beside the plugin (an existing installed
|
||||
table is kept across reinstalls — rate edits live in the
|
||||
installed copy — with a printed hint when it differs from the
|
||||
bundled one; --refresh-pricing ships the bundled table instead)
|
||||
3. Runs `hermes plugins enable agent-cost-estimator` (via the
|
||||
Hermes CLI when on PATH; otherwise prints the manual step)
|
||||
4. Restarts a RUNNING gateway daemon (SIGUSR1 drain-restart, waits
|
||||
@@ -164,7 +166,8 @@ def hermes_home(args) -> pathlib.Path:
|
||||
|
||||
|
||||
def install(home: pathlib.Path, dry_run: bool = False,
|
||||
no_restart: bool = False) -> int:
|
||||
no_restart: bool = False,
|
||||
refresh_pricing: bool = False) -> int:
|
||||
dest = home / "plugins" / PLUGIN_NAME
|
||||
if not PLUGIN_SRC.is_dir():
|
||||
print(f"error: plugin source not found: {PLUGIN_SRC}",
|
||||
@@ -181,7 +184,8 @@ def install(home: pathlib.Path, dry_run: bool = False,
|
||||
return 0
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
# Preserve an already-tuned installed pricing table across
|
||||
# reinstalls (rate edits live in the installed copy).
|
||||
# reinstalls (rate edits live in the installed copy), unless
|
||||
# the caller asked to ship the bundled one.
|
||||
keep_pricing = None
|
||||
if dest.exists():
|
||||
old_pricing = dest / "pricing.json"
|
||||
@@ -190,21 +194,30 @@ def install(home: pathlib.Path, dry_run: bool = False,
|
||||
shutil.rmtree(dest)
|
||||
shutil.copytree(PLUGIN_SRC, dest)
|
||||
print(f"Installed plugin files: {dest}")
|
||||
pricing_src = (PLUGIN_SRC.parent.parent.parent / "pricing.json")
|
||||
# Ship a pricing table with the plugin: the plugin reads
|
||||
# pricing.json next to itself first, independent of the
|
||||
# package being importable in Hermes's interpreter.
|
||||
dest_pricing = dest / "pricing.json"
|
||||
if keep_pricing is not None:
|
||||
if keep_pricing is not None and not refresh_pricing:
|
||||
dest_pricing.write_bytes(keep_pricing)
|
||||
print(f"Kept existing pricing table: {dest_pricing}")
|
||||
else:
|
||||
pricing_src = (PLUGIN_SRC.parent.parent.parent / "pricing.json")
|
||||
if pricing_src.is_file():
|
||||
shutil.copy2(pricing_src, dest_pricing)
|
||||
print(f"Installed pricing table: {dest_pricing}")
|
||||
if (pricing_src.is_file()
|
||||
and keep_pricing != pricing_src.read_bytes()):
|
||||
# A silent keep is how the plugin lost the credit-pool
|
||||
# tables between 0.5.0 and 0.9.0: reships shipped new
|
||||
# code but kept the old table. Make the drift visible.
|
||||
print(f"Kept existing pricing table (it differs from "
|
||||
f"the bundled one): {dest_pricing}")
|
||||
print("To ship the bundled rates instead, re-run with "
|
||||
"--refresh-pricing (drops local rate edits)")
|
||||
else:
|
||||
print(f"warning: bundled pricing.json not found at "
|
||||
f"{pricing_src}; plugin falls back to default rates")
|
||||
print(f"Kept existing pricing table: {dest_pricing}")
|
||||
elif pricing_src.is_file():
|
||||
shutil.copy2(pricing_src, dest_pricing)
|
||||
print(f"Installed pricing table: {dest_pricing}")
|
||||
else:
|
||||
print(f"warning: bundled pricing.json not found at "
|
||||
f"{pricing_src}; plugin falls back to default rates")
|
||||
# Enable it (plugins are opt-in)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
@@ -270,11 +283,17 @@ def main(argv=None) -> int:
|
||||
help="do not restart a running gateway daemon after install "
|
||||
"(the daemon caches plugins; restart it later with "
|
||||
"`hermes gateway restart`)")
|
||||
parser.add_argument(
|
||||
"--refresh-pricing", action="store_true",
|
||||
help="ship the bundled pricing.json instead of keeping the "
|
||||
"installed table (drops local rate edits made in the "
|
||||
"installed copy)")
|
||||
args = parser.parse_args(argv)
|
||||
home = hermes_home(args)
|
||||
if args.uninstall:
|
||||
return uninstall(home, dry_run=args.dry_run)
|
||||
return install(home, dry_run=args.dry_run, no_restart=args.no_restart)
|
||||
return install(home, dry_run=args.dry_run, no_restart=args.no_restart,
|
||||
refresh_pricing=args.refresh_pricing)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: agent-cost-estimator
|
||||
version: 0.9.0
|
||||
version: 0.9.1
|
||||
description: "Print an estimated cost line plus session token line (provider:model | session:$X | turn:$Y, then -- I:X O:Y C:Z) after every assistant turn, recorded from Hermes session usage. Rendered through the shared display module for display parity with the CLI, GUI, and Vibe hooks."
|
||||
author: "nvaldez"
|
||||
provides_hooks:
|
||||
|
||||
@@ -46,6 +46,9 @@ Use `--integrate hermes` to install the Hermes Agent plugin: it
|
||||
copies the plugin into `<hermes-home>/plugins/`, enables it, and
|
||||
after a Hermes restart prints `-- provider:model | session:$X |
|
||||
turn:$Y` after every assistant turn, mirroring the Vibe hook.
|
||||
A reship keeps the installed `pricing.json` (local rate edits
|
||||
live there) and prints a hint when it differs from the bundled
|
||||
one; add `--refresh-pricing` to ship the bundled table instead.
|
||||
`--rm-integrate hermes` removes it.
|
||||
|
||||
## What to trust
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "agent-cost-estimator"
|
||||
version = "0.9.0"
|
||||
version = "0.9.1"
|
||||
description = "Report token usage and estimated USD cost of AI agent sessions from local harness logs"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.9"
|
||||
|
||||
@@ -1425,6 +1425,53 @@ def test_installer_copies_plugin(tmp_path, monkeypatch, capsys):
|
||||
assert "enable" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_installer_keeps_tuned_pricing_with_hint(tmp_path, monkeypatch,
|
||||
capsys):
|
||||
"""A reship keeps the installed pricing.json (rate edits live in
|
||||
the installed copy); when it differs from the bundled one, the
|
||||
installer says so and names --refresh-pricing (that silent keep
|
||||
is how the plugin lost the credit-pool tables between 0.5.0 and
|
||||
0.9.0)."""
|
||||
home = make_hermes_home(tmp_path, sessions=[("s1", "t", "m", 1.0)])
|
||||
def fake_run(*args, **kwargs):
|
||||
raise FileNotFoundError("no hermes")
|
||||
monkeypatch.setattr(hinstall.subprocess, "run", fake_run)
|
||||
assert hinstall.main(["--hermes-home", str(home)]) == 0
|
||||
dest = home / "plugins" / "agent-cost-estimator"
|
||||
tuned = json.loads((dest / "pricing.json").read_text())
|
||||
tuned["providers"]["mistral"]["models"]["default"]["input_price"] = 9.99
|
||||
(dest / "pricing.json").write_text(json.dumps(tuned))
|
||||
assert hinstall.main(["--hermes-home", str(home)]) == 0
|
||||
out = capsys.readouterr().out
|
||||
assert "Kept existing pricing table" in out
|
||||
assert "--refresh-pricing" in out # the drift is visible
|
||||
after = json.loads((dest / "pricing.json").read_text())
|
||||
assert (after["providers"]["mistral"]["models"]["default"]
|
||||
["input_price"] == 9.99) # the tuning survived
|
||||
|
||||
|
||||
def test_installer_refresh_pricing(tmp_path, monkeypatch, capsys):
|
||||
"""--refresh-pricing ships the bundled table instead of keeping
|
||||
the installed one (drops local rate edits, deliberately)."""
|
||||
home = make_hermes_home(tmp_path, sessions=[("s1", "t", "m", 1.0)])
|
||||
def fake_run(*args, **kwargs):
|
||||
raise FileNotFoundError("no hermes")
|
||||
monkeypatch.setattr(hinstall.subprocess, "run", fake_run)
|
||||
assert hinstall.main(["--hermes-home", str(home)]) == 0
|
||||
dest = home / "plugins" / "agent-cost-estimator"
|
||||
tuned = json.loads((dest / "pricing.json").read_text())
|
||||
tuned["providers"]["mistral"]["models"]["default"]["input_price"] = 9.99
|
||||
(dest / "pricing.json").write_text(json.dumps(tuned))
|
||||
assert hinstall.main(["--hermes-home", str(home),
|
||||
"--refresh-pricing"]) == 0
|
||||
out = capsys.readouterr().out
|
||||
assert "Installed pricing table" in out
|
||||
assert "Kept existing" not in out
|
||||
after = json.loads((dest / "pricing.json").read_text())
|
||||
assert (after["providers"]["mistral"]["models"]["default"]
|
||||
["input_price"] != 9.99) # bundled rates are back
|
||||
|
||||
|
||||
def test_installer_uninstall(tmp_path, capsys):
|
||||
"""--uninstall removes the plugin directory."""
|
||||
home = make_hermes_home(tmp_path, sessions=[("s1", "t", "m", 1.0)])
|
||||
|
||||
Reference in New Issue
Block a user