Files
QuantEngineByItz/tools/audit_repository_entropy_v2.py
kjh2064 ee3e799de1 feat: 리밸런싱 엔진 V1 + GAS 버그 수정 (2026-06-13)
주요 변경:
- tools/build_rebalance_engine_v1.py: REBALANCE_ENGINE_V1 신규
  * account_snapshot 직접 합산(_build_snap_position_map) → 소수주 분리 행 병합
  * 레짐 소스 macro.REGIME_PRELIM 최우선 (GAS 와 동일)
- src/gas_adapter_parts/gdf_06_rebalance.gs: runRebalanceSheet_() 신규
  * Logger.log / getSpreadsheet_() 로 run_all 연동 수정
- src/gas_adapter_parts/gdc_01_fetch_fundamentals.gs
  * _mergePositionRecord_(): 소수주 중복 행 합산 신규
  * parseInt → parseFloat (qty, availQty)
- src/gas_adapter_parts/gdf_01_price_metrics.gs
  * 미보유 종목 SELL_READY → WATCH_EXIT_SIGNAL
- spec/41_release_dag.yaml: build_rebalance_sheet 노드 추가 (step_count 63)
- spec/51_formula_lifecycle_registry.yaml: REBALANCE_ENGINE_V1 등록

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-13 13:20:14 +09:00

67 lines
2.2 KiB
Python

#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
from pathlib import Path
import yaml
from audit_repository_entropy_v1 import _iter_files, _sha256_file, _zip_sha256
ROOT = Path(__file__).resolve().parents[1]
def _load_budget(path: Path) -> dict:
if not path.exists():
return {}
try:
data = yaml.safe_load(path.read_text(encoding="utf-8"))
return data if isinstance(data, dict) else {}
except Exception:
return {}
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--root", default=".")
ap.add_argument("--out", required=True)
ap.add_argument("--budget", default="spec/release/repository_entropy_budget.yaml")
args = ap.parse_args()
root = Path(args.root).resolve()
budget = _load_budget(ROOT / args.budget)
files = _iter_files(root)
package_json = root / "package.json"
script_count = 0
if package_json.exists():
try:
pkg = json.loads(package_json.read_text(encoding="utf-8"))
scripts = pkg.get("scripts") if isinstance(pkg, dict) else {}
script_count = len(scripts) if isinstance(scripts, dict) else 0
except Exception:
script_count = 0
file_budget = int(budget.get("max_total_files") or 10**9)
script_budget = int(budget.get("max_package_scripts") or 10**9)
temp_budget = int(budget.get("max_temp_json_files") or 10**9)
temp_count = len([p for p in (root / "Temp").glob("*.json")]) if (root / "Temp").exists() else 0
gate = "PASS" if len(files) <= file_budget and script_count <= script_budget and temp_count <= temp_budget else "FAIL"
payload = {
"formula_id": "AUDIT_REPOSITORY_ENTROPY_V2",
"gate": gate,
"total_file_count": len(files),
"package_script_count": script_count,
"temp_json_count": temp_count,
"budget": budget,
"source_zip_sha256": _zip_sha256(root),
}
out = Path(args.out)
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
print(json.dumps(payload, ensure_ascii=False, indent=2))
return 0 if gate == "PASS" else 1
if __name__ == "__main__":
raise SystemExit(main())