migration: close candidate maintenance audit

This commit is contained in:
leefer
2026-07-31 21:24:37 +08:00
parent faac60b1a6
commit 406118bba6
17 changed files with 844 additions and 120 deletions
+45 -23
View File
@@ -9,7 +9,7 @@ from typing import Any
ROOT = Path(__file__).resolve().parents[1]
OUTPUT = ROOT / "docs" / "governance" / "architecture-inventory.json"
OUTPUT = ROOT / "config" / "architecture-inventory.json"
def relative(path: Path) -> str:
@@ -51,8 +51,15 @@ def api_inventory(server: str) -> dict[str, list[str]]:
return {"exact": exact, "prefixes": prefixes, "patterns": patterns}
def database_inventory(database: str) -> list[str]:
return re.findall(r"CREATE TABLE IF NOT EXISTS\s+([a-zA-Z0-9_]+)", database)
def database_inventory(sources: list[str]) -> list[str]:
tables: list[str] = []
for database in sources:
tables.extend(
re.findall(
r"CREATE TABLE IF NOT EXISTS\s+([a-zA-Z0-9_]+)", database
)
)
return list(dict.fromkeys(tables))
def python_functions(path: str, prefixes: tuple[str, ...]) -> list[str]:
@@ -70,11 +77,13 @@ def css_layers(html: str) -> list[str]:
def code_hotspots() -> list[dict[str, Any]]:
candidates = [
"server.py",
"backend/application.py",
"database.py",
"screener.py",
"market_insights.py",
"tushare_client.py",
"backend/features/screener/engine.py",
"backend/features/market/insights.py",
"backend/data/providers/tushare_client.py",
"backend/features/heaven/service.py",
"backend/features/heaven/engine.py",
"frontend/index.html",
"frontend/app.js",
"frontend/styles/styles.css",
@@ -88,6 +97,8 @@ def code_hotspots() -> list[dict[str, Any]]:
rows = []
for name in candidates:
path = ROOT / name
if not path.is_file():
continue
rows.append(
{
"path": name,
@@ -100,14 +111,21 @@ def code_hotspots() -> list[dict[str, Any]]:
def build() -> dict[str, Any]:
html = source("frontend/index.html")
server = source("server.py")
database = source("database.py")
server = source("backend/application.py")
database_sources = [source("database.py")]
database_sources.extend(
path.read_text(encoding="utf-8")
for path in sorted((ROOT / "backend" / "database" / "migrations").glob("m*.py"))
)
database_sources.append(
source("backend/database/migrations/runner.py")
)
pages = page_inventory(html)
api = api_inventory(server)
tables = database_inventory(database)
tables = database_inventory(database_sources)
return {
"schema_version": 1,
"captured_from": "governed source tree",
"captured_from": "app modular preservation candidate",
"runtime": {
"http_server": "http.server.ThreadingHTTPServer",
"application_processes": 1,
@@ -126,21 +144,22 @@ def build() -> dict[str, Any]:
"api": api,
"database_tables": tables,
"background_job_methods": python_functions(
"server.py", ("_background", "_run_background", "_schedule_", "run_automatic")
"backend/application.py",
("_background", "_run_background", "_schedule_", "run_automatic"),
),
"external_data_adapters": [
{"provider": "tushare", "path": "tushare_client.py", "runtime_role": "primary deterministic market data"},
{"provider": "ifind", "path": "ifind_client.py", "runtime_role": "realtime, charts, snapshots, enrichment"},
{"provider": "eastmoney", "path": "chart_data_provider.py", "runtime_role": "display chart fallback"},
{"provider": "eastmoney", "path": "realtime_aggregator.py", "runtime_role": "isolated realtime observation"},
{"provider": "tencent", "path": "realtime_aggregator.py", "runtime_role": "index observation fallback"},
{"provider": "tushare", "path": "backend/data/providers/tushare_client.py", "runtime_role": "primary deterministic market data"},
{"provider": "ifind", "path": "backend/data/providers/ifind_client.py", "runtime_role": "realtime, charts, snapshots, enrichment"},
{"provider": "eastmoney", "path": "backend/features/market/charts.py", "runtime_role": "display chart fallback"},
{"provider": "eastmoney", "path": "backend/data/realtime.py", "runtime_role": "isolated realtime observation"},
{"provider": "tencent", "path": "backend/data/realtime.py", "runtime_role": "index observation fallback"},
],
"llm_entrypoints": [
{"function": "stream_with_mentor", "path": "mentor_agent.py"},
{"function": "interpret_heaven", "path": "heaven_agent.py"},
{"function": "stream_review_assistant", "path": "assistant_agent.py"},
{"function": "compile_strategy_with_llm", "path": "llm_strategy.py"},
{"function": "test_llm_connection", "path": "llm_strategy.py"},
{"function": "stream_with_mentor", "path": "backend/features/mentor/agent.py"},
{"function": "interpret_heaven", "path": "backend/features/heaven/agent.py"},
{"function": "stream_review_assistant", "path": "backend/features/review/agent.py"},
{"function": "compile_strategy_with_llm", "path": "backend/features/screener/compiler.py"},
{"function": "test_llm_connection", "path": "backend/features/screener/compiler.py"},
],
"css_layers": css_layers(html),
"code_hotspots": code_hotspots(),
@@ -154,7 +173,10 @@ def main() -> int:
rendered = json.dumps(build(), ensure_ascii=False, indent=2) + "\n"
if args.check:
if not OUTPUT.exists() or OUTPUT.read_text(encoding="utf-8") != rendered:
raise SystemExit("architecture inventory is stale; run tools/build_architecture_inventory.py")
raise SystemExit(
"architecture inventory is stale; run "
"tools/build_architecture_inventory.py"
)
print("Architecture inventory is current.")
return 0
OUTPUT.parent.mkdir(parents=True, exist_ok=True)