feat: tamper-evident audit ledger (hash chain) + dual-column cost view
- Hash-chain ledger (cloud/ledger.py): prev_hash/entry_hash per record, SQLite append-only triggers, UNIQUE prev/entry hash with fail-closed retry at the transaction boundary; verify/export (incl. expected-head check for tail truncation); legacy audit_log rows marked pre-chain via a single ledger_genesis marker, never rewritten. - AuthStore.audit() writes audit_log + chain entry in one transaction. - Track-3 interface: audit_verdict / audit_pushback_round / audit_rebuild / third-failure assessment / test-change audit / meta-review / rebuild-notice entries; per-(module, contract-version) failure counts derived from the ledger (pass or completed rebuild resets; total > 3 triggers rebuild); acceptance-triggered rebuilds require a confirmed user notice. - Admin read-only endpoints: GET /admin/audit-ledger/verify|export. - Cost: dual_column_view (priced_usd_micros + billing note, wording reused verbatim from PR #212) wired into project/task cost endpoints; by-model and per-creator reporting stay in #212, not duplicated here. - PG schema + migration lists updated for audit_ledger (incl. sequence setval alignment).
This commit is contained in:
1 parent
c0ab995ccc
commit
eeb10118d6
7 files changed
+2121
-10
No files matched your search
@@ -135,6 +135,8 @@ def price_usd_micros(model, input_tokens, cached_input_tokens,
|
||||
return int(round(usd * 1000000))
|
||||
|
||||
|
||||
# 双列文案:逐字复用 PR #212(feat-cost-quota,5b30c61)的
|
||||
# BILLING_NOTE,本轨不拥有成本口径、不另造一套说法。
|
||||
BILLING_NOTE = (
|
||||
"价格表代理价(经 CLOUD_MODEL_PRICES_JSON / CLOUD_MODEL_PRICES_FILE"
|
||||
" 覆盖层),非中转实际账单;未定价 token 不计入美元、不等于免费。"
|
||||
@@ -168,6 +170,24 @@ def quota_cutoff_reason(quota_usd_micros, used_usd_micros,
|
||||
return None
|
||||
|
||||
|
||||
def dual_column_view(report):
|
||||
"""双列视图:在已有 _report 结果上加定价列别名与账单说明。
|
||||
|
||||
不改 _report(旧单测按其键集断言)与旧键:usd_micros 仍是
|
||||
有价行之和,unpriced_actual_tokens 仍是未定价 actual token;
|
||||
本函数只加 priced_usd_micros(与 usd_micros 同值)与
|
||||
billing_note。未定价模型分列(by_model / unpriced_models)
|
||||
与按创建者口径是 PR #212 的范围,本轨不重复实现——#212
|
||||
合并后本函数由其 dual_column_* 取代,端点改走 dual_column_*
|
||||
(同名同值键,切换无语义差);#212 未合并前,本视图是
|
||||
任务/项目成本端点的双列最小实现。
|
||||
"""
|
||||
view = dict(report)
|
||||
view["priced_usd_micros"] = view["usd_micros"]
|
||||
view["billing_note"] = BILLING_NOTE
|
||||
return view
|
||||
|
||||
|
||||
def unpriced_token_cap():
|
||||
"""Monthly unpriced-token ceiling for users who have a quota row.
|
||||
|
||||
|
||||
Reference in new issue
Block a user