feat(scripts): add cost monitor with daily summary + threshold alerts - #13
Open
allenter wants to merge 3 commits into
Open
feat(scripts): add cost monitor with daily summary + threshold alerts#13allenter wants to merge 3 commits into
allenter wants to merge 3 commits into
Conversation
Layer a zero-dependency, pure-Python vector memory store (memories/vault/) on top of the existing single-file consensus baton: - scripts/core/memory_vault.py: chunk consensus + docs, index into memories/vault/index.json (TF-IDF char n-grams + cosine similarity, no external deps), and semantic search with -top-k / min-score. Backend swappable: replace _embed_chunk() to plug in ChromaDB or a model embedding. - auto-loop.sh: each cycle auto-retrieves the top relevant historical blocks (keyed off Next Action) and injects them into the prompt as '## Highly-relevant past memory'; after a successful/soft-timeout cycle it indexes the latest consensus + docs into the vault. - .gitignore: ignore memories/vault/* runtime data. - Docs updated: README(EN/ZH), CLAUDE.md, PROMPT.md, INDEX.md. consensus.md remains the authoritative running-state baton; the vault adds long-term recall of decisions/context that consensus collapses.
Add a Memory Vault panel to the control deck: - server.py: new GET /api/vault endpoint. Reads memories/vault/index.json directly (no subprocess) and returns stats (chunk/source/term counts, size, last-indexed), per-source breakdown, latest entries, plus optional in-process cosine semantic search via ?q=. - app.js: fetchVault() renderer with stat cards, a canvas bar chart of chunks per source, latest-entry list, and a live semantic-search box (Enter or button) showing scored hits with source tags. - index.html: Memory Vault section between Consensus and Recent Log. - styles.css: dark-theme styles for stats, canvas, entries, tags. Pure stdlib on the server side; canvas drawn client-side.
Auto-Company burns model quota 24/7 but had zero cost tracking; each cycle's `cost:` only scattered across logs/auto-loop.log. Add a small zero-dependency tool: - cost-monitor.sh: parses per-cycle cost from logs/auto-loop.log and summarizes by calendar day (total/runs/avg/max). Supports --days, --date (incl. "yesterday"), --threshold, and a --check mode that exits non-zero when today's spend exceeds the threshold and appends to logs/cost-alerts.log (cron/launchd friendly). - cost-alert.sh: launchd wrapper running --check that raises a macOS desktop notification on threshold breach and records logs/cost-daily.log. Portability notes baked in: uses match() (macOS awk doesn't set RSTART/RLENGTH for /regex/ patterns), supports both `date -v` and `date -d`, avoids `column -t` (absent on macOS), and keeps the final newline (bash `read` treats a trailing line without \n as EOF). Verified on macOS: today/7-day/single-day summaries, --check under and over threshold (exit 0/1), --help, and no-data path. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: feat(scripts): 新增 cost-monitor.sh 成本监控(每日汇总 + 阈值告警)
动机
Auto-Company 是自主 24/7 运行并消耗模型额度(Claude API / Codex)的循环,但没有任何成本追踪能力——每轮
cost:只散落在logs/auto-loop.log。用户无法回答"今天烧了多少钱""这个月预算还够不够"。功能
新增
scripts/core/cost-monitor.sh,解析logs/auto-loop.log中每轮成本并按自然日汇总:用法
./cost-monitor.sh./cost-monitor.sh --days 7./cost-monitor.sh --date 2026-08-02/--date yesterday./cost-monitor.sh --check --threshold 20logs/cost-alerts.log+ exit 1(cron 友好)COST_THRESHOLD_DAILY=25设计要点
cost: <float>字段(match()而非/regex/pattern,因 macOS awk 的 pattern 匹配不设置RSTART/RLENGTH)date -v与 GNUdate -d;纯printf对齐(macOScolumn无-t)read将无换行的末行视为 EOF 而跳过,因此 rows 保留尾部\nlogs/cost-alerts.log,退出码 1 便于 cron/launchd 触发通知验证
--check低于阈值 exit 0,高于阈值 exit 1 且写告警日志--help正常变更文件
scripts/core/cost-monitor.sh(新增,核心:解析 + 按天汇总 +--check阈值告警)scripts/core/cost-alert.sh(新增,launchd wrapper:跑--check,超阈值弹 macOS 桌面通知并记录logs/cost-daily.log)INDEX.md/README.md的脚本索引配套 launchd 调度(可选,随附示例)
~/Library/LaunchAgents/com.autocompany.costmonitor.plist每 4 小时触发cost-alert.sh,环境变量COST_THRESHOLD_DAILY(默认 20)控制每日阈值;RunAtLoad启动即检查一次。后续建议(可另开 PR)
/api增加成本摘要端点,复用本脚本输出Makefile增加cost目标Co-Authored-By: Claude noreply@anthropic.com