Skip to content

thedotmack/claude-mem / plugin/skills/agent-cost-report

agent-cost-report

Verified

Believable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.

FileKindSize
.gitignoreother100 B
CHECKSUMS.txtmarkdown2.1 KB
SKILL.mdskill md21.3 KB
VERIFICATION.mdmarkdown12.3 KB
scripts/acr.pyexecutablescript12.2 KB
scripts/acr/__init__.pyscript105 B
scripts/acr/behavior.pyscript17.5 KB
scripts/acr/classify.pyscript5.5 KB
scripts/acr/costs.pyscript6.3 KB
scripts/acr/devices.pyscript5.4 KB
scripts/acr/evidence.pyscript9.2 KB
scripts/acr/labels.pyscript7.6 KB
scripts/acr/measure.pyscript5.6 KB
scripts/acr/mistakes.pyscript23.1 KB
scripts/acr/owner.pyscript2.9 KB
scripts/acr/patterns.pyscript26.0 KB
scripts/acr/period.pyscript3.8 KB
scripts/acr/prices.pyscript5.0 KB
scripts/acr/render.pyscript52.7 KB
scripts/acr/rollup.pyscript31.7 KB
scripts/acr/rules.jsonconfig3.5 KB
scripts/acr/rules.pyscript4.5 KB
scripts/acr/sample.pyscript3.6 KB
scripts/acr/snapshot.pyscript2.0 KB
scripts/acr/sync.pyscript3.7 KB
scripts/acr/transcripts.pyscript7.4 KB
scripts/acr/wins.pyscript21.0 KB
scripts/tests/_db.pyscript3.6 KB
scripts/tests/_paths.pyscript337 B
scripts/tests/fixtures/codex/sessions/2026/09/18/rollout-codex-1.jsonlother664 B
scripts/tests/fixtures/make_report_fixtures.pyscript2.0 KB
scripts/tests/fixtures/prices_sample.jsonconfig611 B
scripts/tests/fixtures/projects/-workspace-proj-a/sess-aaaa.jsonlother2.9 KB
scripts/tests/fixtures/projects/-workspace-proj-b/sess-bbbb.jsonlother537 B
scripts/tests/fixtures/report-1day.jsonconfig20.1 KB
scripts/tests/fixtures/report-30day.jsonconfig48.1 KB
scripts/tests/fixtures/report-7day.jsonconfig29.1 KB
scripts/tests/fixtures/report-empty.jsonconfig13.8 KB
scripts/tests/fixtures/report-session.jsonconfig16.6 KB
scripts/tests/test_behavior.pyscript29.6 KB
scripts/tests/test_devices.pyscript5.9 KB
scripts/tests/test_labels.pyscript8.6 KB
scripts/tests/test_measure.pyscript6.8 KB
scripts/tests/test_period.pyscript7.0 KB
scripts/tests/test_prices.pyscript5.3 KB
scripts/tests/test_render.pyscript12.1 KB
scripts/tests/test_render_encoding.pyscript1.5 KB
scripts/tests/test_rollup.pyscript19.3 KB
scripts/tests/test_snapshot.pyscript2.8 KB
scripts/tests/test_sync.pyscript2.5 KB
scripts/tests/test_transcript_encoding.pyscript2.7 KB
scripts/tests/test_transcripts.pyscript8.1 KB
scripts/tests/test_wins.pyscript15.7 KB
verification/precision-2026-09-26.jsonconfig308 B

scripts/tests/test_period.py

View on GitHub
import builtins
import datetime as dt
import os
import re
import subprocess
import sys
import unittest
from unittest.mock import patch
from zoneinfo import ZoneInfoNotFoundError

import _paths  # noqa: F401
from acr import period
from acr.period import PT

H = 3600 * 1000


class MissingTimezoneData(unittest.TestCase):
    def test_cli_explains_how_to_install_timezone_data(self):
        # -S hides site-packages; an empty TZPATH hides OS data, as on stock Windows.
        env = dict(os.environ, PYTHONTZPATH="")
        result = subprocess.run(
            [sys.executable, "-S", _paths.ACR_PY, "--help"],
            env=env, capture_output=True, text=True, timeout=10,
        )
        self.assertEqual(result.returncode, 1)
        self.assertIn("America/Los_Angeles", result.stderr)
        self.assertNotIn("Traceback", result.stderr)
        # The plain quoted line runs in cmd, Git Bash (Claude Code's Bash tool on Windows) and POSIX shells.
        command = re.search(r'^"(.+)" -m pip install tzdata$', result.stderr, re.MULTILINE)
        self.assertIsNotNone(command)
        self.assertTrue(os.path.samefile(command.group(1), sys.executable))
        # PowerShell needs the call operator, so Windows gets a second line for it.
        powershell_line = f'PowerShell: & "{command.group(1)}" -m pip install tzdata'
        self.assertEqual(powershell_line in result.stderr.splitlines(), os.name == "nt")
        # The zero-install route the #4250 reporter used.
        self.assertIn("PYTHONTZPATH", result.stderr)

    def test_windows_install_command_handles_spaces_in_interpreter_path(self):
        with open(_paths.ACR_PY, encoding="utf-8") as script:
            code = compile(script.read(), _paths.ACR_PY, "exec")
        real_import = builtins.__import__

        def missing_timezone_import(name, *args, **kwargs):
            if name == "acr":
                raise ZoneInfoNotFoundError("America/Los_Angeles")
            return real_import(name, *args, **kwargs)

        interpreter = r"C:\Program Files\Python\python.exe"
        # Exercise the CLI's error handler on every host, including its Windows branch.
        with patch("builtins.__import__", side_effect=missing_timezone_import), \
                patch("os.name", "nt"), patch("sys.executable", interpreter):
            with self.assertRaises(SystemExit) as error:
                exec(code, {"__file__": _paths.ACR_PY, "__name__": "__main__"})
        lines = str(error.exception).splitlines()
        plain_line = '"C:\\Program Files\\Python\\python.exe" -m pip install tzdata'
        # cmd and Git Bash (Claude Code's Bash tool on Windows) run the plain quoted line;
        # PowerShell needs the & call operator, so it gets a line of its own.
        self.assertIn(plain_line, lines)
        self.assertIn("PowerShell: & " + plain_line, lines)
        self.assertIn("PYTHONTZPATH", lines[-1])


class DefaultWindow(unittest.TestCase):
    def test_default_last_7_full_pt_days_fixed_clock(self):
        now = dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT)
        w = period.resolve_window(now=now)
        self.assertEqual(w.start_pt, "2026-09-18")
        self.assertEqual(w.end_exclusive_pt, "2026-09-25")
        self.assertFalse(w.partial_last_day)
        self.assertEqual(w.generated_at_pt, "2026-09-25 16:42 PT")
        self.assertEqual(w.start.utcoffset(), dt.timedelta(hours=-7))  # PDT, from zoneinfo
        self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, 7 * 24 * H)
        b = w.block()
        self.assertEqual(set(b), {"start_pt", "end_exclusive_pt", "start_epoch_ms", "end_epoch_ms",
                                  "generated_at_pt", "partial_last_day"})
        self.assertEqual(b["start_epoch_ms"], int(dt.datetime(2026, 9, 18, tzinfo=PT).timestamp() * 1000))

    def test_default_accepts_a_utc_clock(self):
        now = dt.datetime(2026, 9, 26, 3, 0, tzinfo=dt.timezone.utc)  # still 2026-09-25 20:00 PT
        w = period.resolve_window(now=now)
        self.assertEqual((w.start_pt, w.end_exclusive_pt), ("2026-09-18", "2026-09-25"))

    def test_explicit_end_after_today_is_partial(self):
        now = dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT)
        w = period.resolve_window("2026-09-18", "2026-09-26", now=now)
        self.assertTrue(w.partial_last_day)
        self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, 8 * 24 * H)

    def test_explicit_end_equal_today_is_not_partial(self):
        now = dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT)
        self.assertFalse(period.resolve_window("2026-09-18", "2026-09-25", now=now).partial_last_day)

    def test_only_start_given_defaults_end_to_today(self):
        now = dt.datetime(2026, 9, 25, 9, 0, tzinfo=PT)
        w = period.resolve_window(start="2026-09-01", now=now)
        self.assertEqual((w.start_pt, w.end_exclusive_pt), ("2026-09-01", "2026-09-25"))

    def test_bad_inputs(self):
        now = dt.datetime(2026, 9, 25, 9, 0, tzinfo=PT)
        with self.assertRaises(ValueError):
            period.resolve_window("2026-09-25", "2026-09-25", now=now)
        with self.assertRaises(ValueError):
            period.parse_day("2026-09-25T10:00")
        with self.assertRaises(ValueError):
            period.parse_day("2026-09-25+00:00")


class DstBoundary(unittest.TestCase):
    """US DST ends Sunday 2026-11-01 02:00 PT; PT windows are calendar days, so epoch spans change."""

    def test_default_window_across_fall_back(self):
        now = dt.datetime(2026, 11, 4, 10, 0, tzinfo=PT)
        w = period.resolve_window(now=now)
        self.assertEqual((w.start_pt, w.end_exclusive_pt), ("2026-10-28", "2026-11-04"))
        self.assertEqual(w.start.utcoffset(), dt.timedelta(hours=-7))  # PDT
        self.assertEqual(w.end.utcoffset(), dt.timedelta(hours=-8))    # PST
        self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, (7 * 24 + 1) * H)
        self.assertFalse(w.partial_last_day)

    def test_single_day_containing_fall_back_is_25_hours(self):
        w = period.resolve_window("2026-11-01", "2026-11-02", now=dt.datetime(2026, 11, 5, tzinfo=PT))
        self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, 25 * H)
        self.assertEqual(w.start.isoformat(), "2026-11-01T00:00:00-07:00")
        self.assertEqual(w.end.isoformat(), "2026-11-02T00:00:00-08:00")

    def test_default_window_ending_on_dst_day(self):
        now = dt.datetime(2026, 11, 1, 12, 0, tzinfo=PT)  # afternoon of the switch day (PST)
        w = period.resolve_window(now=now)
        self.assertEqual((w.start_pt, w.end_exclusive_pt), ("2026-10-25", "2026-11-01"))
        self.assertEqual(w.end.utcoffset(), dt.timedelta(hours=-7))  # midnight was still PDT
        self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, 7 * 24 * H)


class SessionBlock(unittest.TestCase):
    def test_session_block_has_null_bounds(self):
        b = period.session_block("abc", now=dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT))
        self.assertIsNone(b["start_pt"]); self.assertIsNone(b["end_epoch_ms"])
        self.assertEqual(b["session"], "abc"); self.assertFalse(b["partial_last_day"])
        self.assertEqual(b["generated_at_pt"], "2026-09-25 16:42 PT")


if __name__ == "__main__":
    unittest.main()
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
backup-setupthedotmack/claude-memSet up, check, or restore local claude-mem database snapshots. Use when the user says "set up backups", "back up my memories", "backup status", or "restore my database".Stars: 118kUpdated Claude CodeCodexVerifiedInstall