From 46d3890efcc5fba839130002adbe46069c024404 Mon Sep 17 00:00:00 2001 From: nvaldez Date: Wed, 11 Nov 2026 19:09:11 +0100 Subject: [PATCH] chore: hook scripts lint-clean (0.9.2) Leftover working-tree edits from the 48e9242 session, committed unchanged: BLE001 noqa with fail-soft comments, I001 import order, explicit check=False on the estimator subprocess.run, {e!s}. Behavior identical; both Vibe hook scripts now pass ruff clean. PATCH bump to 0.9.2, plugin.yaml pin kept in lockstep. 130 tests pass. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- .vibe/ai-usage-cost.md | 15 +++++++++++++ .../hooks/mistral-vibe-cli/post_turn.py | 21 ++++++++++++------- .../hooks/mistral-vibe-code/post_turn.py | 21 ++++++++++++------- .../integration/hermes/plugin/plugin.yaml | 2 +- pyproject.toml | 2 +- 5 files changed, 43 insertions(+), 18 deletions(-) mode change 100644 => 100755 agent_cost_estimator/hooks/mistral-vibe-cli/post_turn.py mode change 100644 => 100755 agent_cost_estimator/hooks/mistral-vibe-code/post_turn.py diff --git a/.vibe/ai-usage-cost.md b/.vibe/ai-usage-cost.md index 9ea3a25..1ae4d2e 100644 --- a/.vibe/ai-usage-cost.md +++ b/.vibe/ai-usage-cost.md @@ -270,6 +270,21 @@ And add the cost information to this file for the current session. --- +#### (pending) - chore: hook scripts lint-clean; 0.9.2 +- **Date**: 2026-11-11 +- **Model**: mistral-vibe:zai-glm-5-3 +- **Session Cost**: $4.28 (running total at commit time) +- **Turn Cost**: $0.07 +- **Total for commit**: $4.28 +- **Notes**: leftover working-tree edits from the 48e9242 session + committed as-is: BLE001 noqa with fail-soft comments, I001 import + order, explicit check=False on the estimator subprocess.run, + {e!s} - behavior unchanged, both mistral-vibe-cli and + mistral-vibe-code post_turn.py now pass ruff clean. PATCH bump + to 0.9.2 (plugin.yaml pin kept in lockstep); 130 tests pass. + +--- + ## Instructions for Contributors 1. Before committing, run `agent-cost-estimator` for your current session diff --git a/agent_cost_estimator/hooks/mistral-vibe-cli/post_turn.py b/agent_cost_estimator/hooks/mistral-vibe-cli/post_turn.py old mode 100644 new mode 100755 index c7d72b5..3bfebd3 --- a/agent_cost_estimator/hooks/mistral-vibe-cli/post_turn.py +++ b/agent_cost_estimator/hooks/mistral-vibe-cli/post_turn.py @@ -46,11 +46,11 @@ multiple concurrent sessions. This hook is designed for: Mistral Vibe CLI (mistral-vibe) """ -import os -import sys import json -import subprocess import logging +import os +import subprocess +import sys from pathlib import Path # Configure logging @@ -96,7 +96,9 @@ def get_session_dir() -> Path: except json.JSONDecodeError as e: LOG.debug(f"No valid JSON payload: {e}") - except Exception as e: + # Fail soft by design: a payload-reading hiccup must never break + # the turn; fall through to the default session directory. + except Exception as e: # noqa: BLE001 LOG.warning(f"Error reading payload: {e}") # Default fallback @@ -129,12 +131,13 @@ def main(): "--display-lines" ] - # Run agent-cost-estimator + # Run agent-cost-estimator; a nonzero exit is handled below result = subprocess.run( cmd, capture_output=True, text=True, - timeout=30 + timeout=30, + check=False, ) if result.returncode != 0: @@ -156,10 +159,12 @@ def main(): print(json.dumps({ "system_message": "-- [cost: timeout]" })) - except Exception as e: + # Fail soft by design: any unexpected error still yields a + # machine-readable system_message, never a broken turn. + except Exception as e: # noqa: BLE001 LOG.error(f"Unexpected error: {e}") print(json.dumps({ - "system_message": f"-- [cost: error - {str(e)}]" + "system_message": f"-- [cost: error - {e!s}]" })) diff --git a/agent_cost_estimator/hooks/mistral-vibe-code/post_turn.py b/agent_cost_estimator/hooks/mistral-vibe-code/post_turn.py old mode 100644 new mode 100755 index 6840428..350fca3 --- a/agent_cost_estimator/hooks/mistral-vibe-code/post_turn.py +++ b/agent_cost_estimator/hooks/mistral-vibe-code/post_turn.py @@ -49,11 +49,11 @@ multiple concurrent sessions. This hook is designed for: Mistral Vibe VSCodium Extension (mistralai.mistral-vibe-code) """ -import os -import sys import json -import subprocess import logging +import os +import subprocess +import sys from pathlib import Path # Configure logging to stderr @@ -103,7 +103,9 @@ def get_session_dir() -> Path: except json.JSONDecodeError as e: LOG.debug(f"No valid JSON payload: {e}") - except Exception as e: + # Fail soft by design: a payload-reading hiccup must never break + # the turn; fall through to the default session directory. + except Exception as e: # noqa: BLE001 LOG.warning(f"Error reading payload: {e}") # Default fallback @@ -136,12 +138,13 @@ def main(): "--display-lines" ] - # Run agent-cost-estimator + # Run agent-cost-estimator; a nonzero exit is handled below result = subprocess.run( cmd, capture_output=True, text=True, - timeout=30 + timeout=30, + check=False, ) if result.returncode != 0: @@ -163,11 +166,13 @@ def main(): print(json.dumps({ "system_message": "-- [cost: timeout]" })) - except Exception as e: + # Fail soft by design: any unexpected error still yields a + # machine-readable system_message, never a broken turn. + except Exception as e: # noqa: BLE001 LOG.error(f"Unexpected error: {e}") # Return JSON to stdout (will be sent to vibe-acp stdin by wrapper) print(json.dumps({ - "system_message": f"-- [cost: error - {str(e)}]" + "system_message": f"-- [cost: error - {e!s}]" })) diff --git a/agent_cost_estimator/integration/hermes/plugin/plugin.yaml b/agent_cost_estimator/integration/hermes/plugin/plugin.yaml index 6095d5c..883c4b9 100644 --- a/agent_cost_estimator/integration/hermes/plugin/plugin.yaml +++ b/agent_cost_estimator/integration/hermes/plugin/plugin.yaml @@ -1,5 +1,5 @@ name: agent-cost-estimator -version: 0.9.1 +version: 0.9.2 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: diff --git a/pyproject.toml b/pyproject.toml index 87467ef..6d89837 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "agent-cost-estimator" -version = "0.9.1" +version = "0.9.2" description = "Report token usage and estimated USD cost of AI agent sessions from local harness logs" readme = "README.md" requires-python = ">=3.9"