@huajiwuyan/hello 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +448 -0
- package/package.json +38 -0
- package/templates/claude/commands/hello.md +760 -0
- package/templates/claude/skills/SKILL.md +90 -0
- package/templates/claude/skills/SKILL.toml +7 -0
- package/templates/claude/skills/assets/icon-large.svg +12 -0
- package/templates/claude/skills/assets/icon-small-400px.svg +12 -0
- package/templates/claude/skills/assets/templates/CHANGELOG.md +24 -0
- package/templates/claude/skills/assets/templates/CHANGELOG_{YYYY}.md +25 -0
- package/templates/claude/skills/assets/templates/INDEX.md +36 -0
- package/templates/claude/skills/assets/templates/archive/_index.md +22 -0
- package/templates/claude/skills/assets/templates/context.md +82 -0
- package/templates/claude/skills/assets/templates/modules/_index.md +22 -0
- package/templates/claude/skills/assets/templates/modules/module.md +35 -0
- package/templates/claude/skills/assets/templates/plan/proposal.md +104 -0
- package/templates/claude/skills/assets/templates/plan/tasks.md +49 -0
- package/templates/claude/skills/references/functions/auto.md +217 -0
- package/templates/claude/skills/references/functions/clean.md +167 -0
- package/templates/claude/skills/references/functions/commit.md +374 -0
- package/templates/claude/skills/references/functions/exec.md +178 -0
- package/templates/claude/skills/references/functions/help.md +105 -0
- package/templates/claude/skills/references/functions/init.md +228 -0
- package/templates/claude/skills/references/functions/plan.md +219 -0
- package/templates/claude/skills/references/functions/review.md +146 -0
- package/templates/claude/skills/references/functions/rollback.md +208 -0
- package/templates/claude/skills/references/functions/test.md +153 -0
- package/templates/claude/skills/references/functions/upgrade.md +371 -0
- package/templates/claude/skills/references/functions/validate.md +147 -0
- package/templates/claude/skills/references/rules/package.md +212 -0
- package/templates/claude/skills/references/rules/scaling.md +150 -0
- package/templates/claude/skills/references/rules/state.md +318 -0
- package/templates/claude/skills/references/rules/tools.md +371 -0
- package/templates/claude/skills/references/services/knowledge.md +408 -0
- package/templates/claude/skills/references/services/templates.md +344 -0
- package/templates/claude/skills/references/stages/analyze.md +201 -0
- package/templates/claude/skills/references/stages/design.md +379 -0
- package/templates/claude/skills/references/stages/develop.md +497 -0
- package/templates/claude/skills/references/stages/evaluate.md +286 -0
- package/templates/claude/skills/references/stages/tweak.md +244 -0
- package/templates/claude/skills/scripts/create_package.py +260 -0
- package/templates/claude/skills/scripts/list_packages.py +145 -0
- package/templates/claude/skills/scripts/migrate_package.py +399 -0
- package/templates/claude/skills/scripts/project_stats.py +438 -0
- package/templates/claude/skills/scripts/upgradewiki.py +321 -0
- package/templates/claude/skills/scripts/utils.py +596 -0
- package/templates/claude/skills/scripts/validate_package.py +309 -0
- package/templates/codex/prompts/hello.md +757 -0
- package/templates/codex/skills/SKILL.md +74 -0
- package/templates/codex/skills/SKILL.toml +7 -0
- package/templates/codex/skills/assets/icon-large.svg +12 -0
- package/templates/codex/skills/assets/icon-small-400px.svg +12 -0
- package/templates/codex/skills/assets/templates/CHANGELOG.md +24 -0
- package/templates/codex/skills/assets/templates/CHANGELOG_{YYYY}.md +25 -0
- package/templates/codex/skills/assets/templates/INDEX.md +36 -0
- package/templates/codex/skills/assets/templates/archive/_index.md +22 -0
- package/templates/codex/skills/assets/templates/context.md +82 -0
- package/templates/codex/skills/assets/templates/modules/_index.md +22 -0
- package/templates/codex/skills/assets/templates/modules/module.md +35 -0
- package/templates/codex/skills/assets/templates/plan/proposal.md +104 -0
- package/templates/codex/skills/assets/templates/plan/tasks.md +29 -0
- package/templates/codex/skills/references/functions/auto.md +181 -0
- package/templates/codex/skills/references/functions/brain.md +275 -0
- package/templates/codex/skills/references/functions/clean.md +154 -0
- package/templates/codex/skills/references/functions/commit.md +265 -0
- package/templates/codex/skills/references/functions/debug/condition-based-waiting.md +151 -0
- package/templates/codex/skills/references/functions/debug/defense-in-depth.md +147 -0
- package/templates/codex/skills/references/functions/debug/root-cause-tracing.md +168 -0
- package/templates/codex/skills/references/functions/debug.md +389 -0
- package/templates/codex/skills/references/functions/exec.md +153 -0
- package/templates/codex/skills/references/functions/help.md +101 -0
- package/templates/codex/skills/references/functions/init.md +221 -0
- package/templates/codex/skills/references/functions/plan.md +178 -0
- package/templates/codex/skills/references/functions/review.md +135 -0
- package/templates/codex/skills/references/functions/rlm.md +864 -0
- package/templates/codex/skills/references/functions/rollback.md +190 -0
- package/templates/codex/skills/references/functions/test.md +140 -0
- package/templates/codex/skills/references/functions/upgrade.md +363 -0
- package/templates/codex/skills/references/functions/validate.md +135 -0
- package/templates/codex/skills/references/rules/cache.md +136 -0
- package/templates/codex/skills/references/rules/scaling.md +124 -0
- package/templates/codex/skills/references/rules/state.md +201 -0
- package/templates/codex/skills/references/rules/tools.md +301 -0
- package/templates/codex/skills/references/services/attention.md +53 -0
- package/templates/codex/skills/references/services/knowledge.md +559 -0
- package/templates/codex/skills/references/services/package.md +383 -0
- package/templates/codex/skills/references/services/templates.md +390 -0
- package/templates/codex/skills/references/stages/analyze.md +191 -0
- package/templates/codex/skills/references/stages/design.md +355 -0
- package/templates/codex/skills/references/stages/develop.md +520 -0
- package/templates/codex/skills/references/stages/tweak.md +239 -0
- package/templates/codex/skills/rlm/__init__.py +39 -0
- package/templates/codex/skills/rlm/agent_orchestrator.py +422 -0
- package/templates/codex/skills/rlm/context_manager.py +366 -0
- package/templates/codex/skills/rlm/engine.py +915 -0
- package/templates/codex/skills/rlm/folding.py +391 -0
- package/templates/codex/skills/rlm/repl.py +452 -0
- package/templates/codex/skills/rlm/roles/analyzer.md +66 -0
- package/templates/codex/skills/rlm/roles/designer.md +94 -0
- package/templates/codex/skills/rlm/roles/explorer.md +43 -0
- package/templates/codex/skills/rlm/roles/implementer.md +62 -0
- package/templates/codex/skills/rlm/roles/kb_keeper.md +138 -0
- package/templates/codex/skills/rlm/roles/pkg_keeper.md +163 -0
- package/templates/codex/skills/rlm/roles/reviewer.md +74 -0
- package/templates/codex/skills/rlm/roles/synthesizer.md +90 -0
- package/templates/codex/skills/rlm/roles/tester.md +83 -0
- package/templates/codex/skills/rlm/schemas/agent_result.json +174 -0
- package/templates/codex/skills/rlm/session.py +376 -0
- package/templates/codex/skills/rlm/shared_tasks.py +370 -0
- package/templates/codex/skills/scripts/create_package.py +260 -0
- package/templates/codex/skills/scripts/list_packages.py +145 -0
- package/templates/codex/skills/scripts/migrate_package.py +399 -0
- package/templates/codex/skills/scripts/project_stats.py +438 -0
- package/templates/codex/skills/scripts/upgradewiki.py +321 -0
- package/templates/codex/skills/scripts/utils.py +596 -0
- package/templates/codex/skills/scripts/validate_package.py +309 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
项目统计脚本
|
|
5
|
+
统计项目规模(文件数、代码行数、模块数)用于复杂度判定
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
python project_stats.py [--path <project-path>]
|
|
9
|
+
|
|
10
|
+
Examples:
|
|
11
|
+
python project_stats.py # 统计当前目录
|
|
12
|
+
python project_stats.py --path /project # 统计指定目录
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import os
|
|
17
|
+
import sys
|
|
18
|
+
import json
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from collections import defaultdict
|
|
22
|
+
|
|
23
|
+
# 确保能找到同目录下的 utils 模块
|
|
24
|
+
sys.path.insert(0, str(Path(__file__).parent))
|
|
25
|
+
from utils import setup_encoding, script_error_handler
|
|
26
|
+
|
|
27
|
+
# 源代码文件扩展名
|
|
28
|
+
SOURCE_EXTENSIONS = {
|
|
29
|
+
# 前端
|
|
30
|
+
".js", ".jsx", ".ts", ".tsx", ".vue", ".svelte",
|
|
31
|
+
# 后端
|
|
32
|
+
".py", ".java", ".go", ".rs", ".rb", ".php",
|
|
33
|
+
".cs", ".cpp", ".c", ".h", ".hpp",
|
|
34
|
+
# 移动端
|
|
35
|
+
".swift", ".kt", ".dart",
|
|
36
|
+
# 其他
|
|
37
|
+
".scala", ".clj", ".ex", ".exs", ".erl",
|
|
38
|
+
".lua", ".r", ".jl", ".zig"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# 配置文件扩展名
|
|
42
|
+
CONFIG_EXTENSIONS = {
|
|
43
|
+
".json", ".yaml", ".yml", ".toml", ".xml",
|
|
44
|
+
".ini", ".conf", ".env"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# 排除目录
|
|
48
|
+
EXCLUDE_DIRS = {
|
|
49
|
+
"node_modules", ".git", ".svn", ".hg",
|
|
50
|
+
"vendor", "__pycache__", ".venv", "venv",
|
|
51
|
+
"dist", "build", "target", "out", "bin",
|
|
52
|
+
".idea", ".vscode", ".vs",
|
|
53
|
+
"coverage", ".nyc_output", ".pytest_cache",
|
|
54
|
+
"helloagents" # 排除知识库目录
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# 大型项目阈值(与 scaling.md 保持一致)
|
|
58
|
+
LARGE_PROJECT_THRESHOLDS = {
|
|
59
|
+
"files": 500,
|
|
60
|
+
"lines": 50000,
|
|
61
|
+
"modules": 30
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def get_project_root(path_arg: str = None) -> Path:
|
|
66
|
+
"""获取项目根目录
|
|
67
|
+
|
|
68
|
+
优先级:指定路径 > 当前工作目录
|
|
69
|
+
"""
|
|
70
|
+
path = Path(path_arg or os.getcwd()).resolve()
|
|
71
|
+
if not path.is_dir():
|
|
72
|
+
raise ValueError(f"指定的路径不存在或不是目录: {path_arg}")
|
|
73
|
+
return path
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def should_exclude(path: Path) -> bool:
|
|
77
|
+
"""判断是否应该排除该路径"""
|
|
78
|
+
for part in path.parts:
|
|
79
|
+
if part in EXCLUDE_DIRS:
|
|
80
|
+
return True
|
|
81
|
+
if part.startswith("."):
|
|
82
|
+
return True
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def count_lines(file_path: Path) -> int:
|
|
87
|
+
"""统计文件行数"""
|
|
88
|
+
try:
|
|
89
|
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
90
|
+
return sum(1 for _ in f)
|
|
91
|
+
except Exception:
|
|
92
|
+
return 0
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def detect_tech_stack(project_root: Path) -> dict:
|
|
96
|
+
"""检测技术栈"""
|
|
97
|
+
tech_stack = {
|
|
98
|
+
"languages": [],
|
|
99
|
+
"frameworks": [],
|
|
100
|
+
"package_managers": [],
|
|
101
|
+
"build_tools": []
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
# 语言和框架检测规则
|
|
105
|
+
detections = [
|
|
106
|
+
# (文件/目录, 语言, 框架, 包管理器, 构建工具)
|
|
107
|
+
("package.json", "JavaScript/TypeScript", None, "npm/yarn", None),
|
|
108
|
+
("tsconfig.json", "TypeScript", None, None, None),
|
|
109
|
+
("pyproject.toml", "Python", None, "pip/poetry", None),
|
|
110
|
+
("requirements.txt", "Python", None, "pip", None),
|
|
111
|
+
("Cargo.toml", "Rust", None, "cargo", "cargo"),
|
|
112
|
+
("go.mod", "Go", None, "go mod", "go"),
|
|
113
|
+
("pom.xml", "Java", None, "maven", "maven"),
|
|
114
|
+
("build.gradle", "Java/Kotlin", None, "gradle", "gradle"),
|
|
115
|
+
("Gemfile", "Ruby", None, "bundler", None),
|
|
116
|
+
("composer.json", "PHP", None, "composer", None),
|
|
117
|
+
("pubspec.yaml", "Dart", "Flutter", "pub", None),
|
|
118
|
+
("Package.swift", "Swift", None, "spm", None),
|
|
119
|
+
# 框架检测
|
|
120
|
+
("next.config.js", None, "Next.js", None, None),
|
|
121
|
+
("nuxt.config.js", None, "Nuxt.js", None, None),
|
|
122
|
+
("vue.config.js", None, "Vue.js", None, None),
|
|
123
|
+
("angular.json", None, "Angular", None, None),
|
|
124
|
+
("svelte.config.js", None, "Svelte", None, None),
|
|
125
|
+
("manage.py", None, "Django", None, None),
|
|
126
|
+
("app.py", None, "Flask", None, None),
|
|
127
|
+
("fastapi", None, "FastAPI", None, None),
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
for file_name, lang, framework, pkg_mgr, build_tool in detections:
|
|
131
|
+
if (project_root / file_name).exists():
|
|
132
|
+
if lang and lang not in tech_stack["languages"]:
|
|
133
|
+
tech_stack["languages"].append(lang)
|
|
134
|
+
if framework and framework not in tech_stack["frameworks"]:
|
|
135
|
+
tech_stack["frameworks"].append(framework)
|
|
136
|
+
if pkg_mgr and pkg_mgr not in tech_stack["package_managers"]:
|
|
137
|
+
tech_stack["package_managers"].append(pkg_mgr)
|
|
138
|
+
if build_tool and build_tool not in tech_stack["build_tools"]:
|
|
139
|
+
tech_stack["build_tools"].append(build_tool)
|
|
140
|
+
|
|
141
|
+
return tech_stack
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def detect_modules(project_root: Path) -> dict:
|
|
145
|
+
"""检测模块结构"""
|
|
146
|
+
modules = {
|
|
147
|
+
"count": 0,
|
|
148
|
+
"list": [],
|
|
149
|
+
"by_type": defaultdict(list)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# 常见模块目录
|
|
153
|
+
module_patterns = [
|
|
154
|
+
("src", "source"),
|
|
155
|
+
("lib", "library"),
|
|
156
|
+
("app", "application"),
|
|
157
|
+
("packages", "monorepo"),
|
|
158
|
+
("modules", "modules"),
|
|
159
|
+
("components", "components"),
|
|
160
|
+
("services", "services"),
|
|
161
|
+
("controllers", "controllers"),
|
|
162
|
+
("models", "models"),
|
|
163
|
+
("views", "views"),
|
|
164
|
+
("utils", "utilities"),
|
|
165
|
+
("helpers", "helpers"),
|
|
166
|
+
("api", "api"),
|
|
167
|
+
("core", "core"),
|
|
168
|
+
("common", "common"),
|
|
169
|
+
("shared", "shared")
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
for dir_name, module_type in module_patterns:
|
|
173
|
+
dir_path = project_root / dir_name
|
|
174
|
+
if dir_path.is_dir():
|
|
175
|
+
# 统计子目录作为模块
|
|
176
|
+
for item in dir_path.iterdir():
|
|
177
|
+
if item.is_dir() and not item.name.startswith("."):
|
|
178
|
+
if item.name not in EXCLUDE_DIRS:
|
|
179
|
+
modules["list"].append(f"{dir_name}/{item.name}")
|
|
180
|
+
modules["by_type"][module_type].append(item.name)
|
|
181
|
+
modules["count"] += 1
|
|
182
|
+
|
|
183
|
+
return modules
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def count_dependencies(project_root: Path) -> dict:
|
|
187
|
+
"""统计项目依赖项数量"""
|
|
188
|
+
deps = {
|
|
189
|
+
"total": 0,
|
|
190
|
+
"by_type": {},
|
|
191
|
+
"details": []
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
# package.json (npm/yarn)
|
|
195
|
+
pkg_json = project_root / "package.json"
|
|
196
|
+
if pkg_json.exists():
|
|
197
|
+
try:
|
|
198
|
+
import json
|
|
199
|
+
with open(pkg_json, "r", encoding="utf-8") as f:
|
|
200
|
+
data = json.load(f)
|
|
201
|
+
npm_deps = len(data.get("dependencies", {}))
|
|
202
|
+
npm_dev_deps = len(data.get("devDependencies", {}))
|
|
203
|
+
deps["by_type"]["npm"] = npm_deps + npm_dev_deps
|
|
204
|
+
deps["total"] += npm_deps + npm_dev_deps
|
|
205
|
+
deps["details"].append(f"npm: {npm_deps} deps + {npm_dev_deps} devDeps")
|
|
206
|
+
except Exception:
|
|
207
|
+
pass
|
|
208
|
+
|
|
209
|
+
# requirements.txt (pip)
|
|
210
|
+
req_txt = project_root / "requirements.txt"
|
|
211
|
+
if req_txt.exists():
|
|
212
|
+
try:
|
|
213
|
+
with open(req_txt, "r", encoding="utf-8") as f:
|
|
214
|
+
lines = [l.strip() for l in f if l.strip() and not l.startswith("#")]
|
|
215
|
+
pip_deps = len(lines)
|
|
216
|
+
deps["by_type"]["pip"] = pip_deps
|
|
217
|
+
deps["total"] += pip_deps
|
|
218
|
+
deps["details"].append(f"pip: {pip_deps} deps")
|
|
219
|
+
except Exception:
|
|
220
|
+
pass
|
|
221
|
+
|
|
222
|
+
# pyproject.toml (poetry/pip)
|
|
223
|
+
pyproject = project_root / "pyproject.toml"
|
|
224
|
+
if pyproject.exists():
|
|
225
|
+
try:
|
|
226
|
+
with open(pyproject, "r", encoding="utf-8") as f:
|
|
227
|
+
content = f.read()
|
|
228
|
+
# 简单计数 dependencies 行
|
|
229
|
+
import re
|
|
230
|
+
deps_match = re.findall(r'^\s*[\w-]+\s*=', content, re.MULTILINE)
|
|
231
|
+
if deps_match and "pip" not in deps["by_type"]:
|
|
232
|
+
poetry_deps = len(deps_match) // 2 # 粗略估计
|
|
233
|
+
deps["by_type"]["poetry"] = poetry_deps
|
|
234
|
+
deps["total"] += poetry_deps
|
|
235
|
+
except Exception:
|
|
236
|
+
pass
|
|
237
|
+
|
|
238
|
+
# go.mod (go)
|
|
239
|
+
go_mod = project_root / "go.mod"
|
|
240
|
+
if go_mod.exists():
|
|
241
|
+
try:
|
|
242
|
+
with open(go_mod, "r", encoding="utf-8") as f:
|
|
243
|
+
content = f.read()
|
|
244
|
+
import re
|
|
245
|
+
go_deps = len(re.findall(r'^\s+\S+\s+v', content, re.MULTILINE))
|
|
246
|
+
deps["by_type"]["go"] = go_deps
|
|
247
|
+
deps["total"] += go_deps
|
|
248
|
+
deps["details"].append(f"go: {go_deps} deps")
|
|
249
|
+
except Exception:
|
|
250
|
+
pass
|
|
251
|
+
|
|
252
|
+
# Cargo.toml (rust)
|
|
253
|
+
cargo = project_root / "Cargo.toml"
|
|
254
|
+
if cargo.exists():
|
|
255
|
+
try:
|
|
256
|
+
with open(cargo, "r", encoding="utf-8") as f:
|
|
257
|
+
content = f.read()
|
|
258
|
+
import re
|
|
259
|
+
cargo_deps = len(re.findall(r'^\s*[\w-]+\s*=\s*["{]', content, re.MULTILINE))
|
|
260
|
+
deps["by_type"]["cargo"] = cargo_deps
|
|
261
|
+
deps["total"] += cargo_deps
|
|
262
|
+
deps["details"].append(f"cargo: {cargo_deps} deps")
|
|
263
|
+
except Exception:
|
|
264
|
+
pass
|
|
265
|
+
|
|
266
|
+
return deps
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def calculate_dir_depth(project_root: Path) -> dict:
|
|
270
|
+
"""计算目录层级深度"""
|
|
271
|
+
depth_info = {
|
|
272
|
+
"max_depth": 0,
|
|
273
|
+
"avg_depth": 0,
|
|
274
|
+
"deepest_path": ""
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
depths = []
|
|
278
|
+
for root, dirs, files in os.walk(project_root):
|
|
279
|
+
# 过滤排除目录
|
|
280
|
+
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS and not d.startswith(".")]
|
|
281
|
+
|
|
282
|
+
root_path = Path(root)
|
|
283
|
+
try:
|
|
284
|
+
rel_path = root_path.relative_to(project_root)
|
|
285
|
+
depth = len(rel_path.parts)
|
|
286
|
+
depths.append(depth)
|
|
287
|
+
|
|
288
|
+
if depth > depth_info["max_depth"]:
|
|
289
|
+
depth_info["max_depth"] = depth
|
|
290
|
+
depth_info["deepest_path"] = str(rel_path)
|
|
291
|
+
except ValueError:
|
|
292
|
+
pass
|
|
293
|
+
|
|
294
|
+
if depths:
|
|
295
|
+
depth_info["avg_depth"] = round(sum(depths) / len(depths), 2)
|
|
296
|
+
|
|
297
|
+
return depth_info
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def scan_files(project_root: Path) -> dict:
|
|
301
|
+
"""扫描项目文件"""
|
|
302
|
+
stats = {
|
|
303
|
+
"total_files": 0,
|
|
304
|
+
"source_files": 0,
|
|
305
|
+
"config_files": 0,
|
|
306
|
+
"total_lines": 0,
|
|
307
|
+
"source_lines": 0,
|
|
308
|
+
"by_extension": defaultdict(lambda: {"files": 0, "lines": 0}),
|
|
309
|
+
"largest_files": []
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
file_sizes = []
|
|
313
|
+
|
|
314
|
+
for root, dirs, files in os.walk(project_root):
|
|
315
|
+
# 过滤排除目录
|
|
316
|
+
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS and not d.startswith(".")]
|
|
317
|
+
|
|
318
|
+
root_path = Path(root)
|
|
319
|
+
if should_exclude(root_path.relative_to(project_root)):
|
|
320
|
+
continue
|
|
321
|
+
|
|
322
|
+
for file in files:
|
|
323
|
+
file_path = root_path / file
|
|
324
|
+
ext = file_path.suffix.lower()
|
|
325
|
+
|
|
326
|
+
if not ext:
|
|
327
|
+
continue
|
|
328
|
+
|
|
329
|
+
stats["total_files"] += 1
|
|
330
|
+
lines = count_lines(file_path)
|
|
331
|
+
stats["total_lines"] += lines
|
|
332
|
+
|
|
333
|
+
stats["by_extension"][ext]["files"] += 1
|
|
334
|
+
stats["by_extension"][ext]["lines"] += lines
|
|
335
|
+
|
|
336
|
+
if ext in SOURCE_EXTENSIONS:
|
|
337
|
+
stats["source_files"] += 1
|
|
338
|
+
stats["source_lines"] += lines
|
|
339
|
+
file_sizes.append((str(file_path.relative_to(project_root)), lines))
|
|
340
|
+
elif ext in CONFIG_EXTENSIONS:
|
|
341
|
+
stats["config_files"] += 1
|
|
342
|
+
|
|
343
|
+
# 找出最大的文件
|
|
344
|
+
file_sizes.sort(key=lambda x: x[1], reverse=True)
|
|
345
|
+
stats["largest_files"] = file_sizes[:10]
|
|
346
|
+
|
|
347
|
+
# 转换defaultdict为普通dict
|
|
348
|
+
stats["by_extension"] = dict(stats["by_extension"])
|
|
349
|
+
|
|
350
|
+
return stats
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def determine_project_size(stats: dict, modules: dict, deps: dict, depth: dict) -> dict:
|
|
354
|
+
"""判定项目规模"""
|
|
355
|
+
size = {
|
|
356
|
+
"category": "small",
|
|
357
|
+
"is_large": False,
|
|
358
|
+
"reasons": []
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
thresholds = LARGE_PROJECT_THRESHOLDS
|
|
362
|
+
|
|
363
|
+
if stats["source_files"] > thresholds["files"]:
|
|
364
|
+
size["reasons"].append(f"源文件数 {stats['source_files']} > {thresholds['files']}")
|
|
365
|
+
size["is_large"] = True
|
|
366
|
+
|
|
367
|
+
if stats["source_lines"] > thresholds["lines"]:
|
|
368
|
+
size["reasons"].append(f"代码行数 {stats['source_lines']} > {thresholds['lines']}")
|
|
369
|
+
size["is_large"] = True
|
|
370
|
+
|
|
371
|
+
if modules["count"] > thresholds["modules"]:
|
|
372
|
+
size["reasons"].append(f"模块数 {modules['count']} > {thresholds['modules']}")
|
|
373
|
+
size["is_large"] = True
|
|
374
|
+
|
|
375
|
+
if size["is_large"]:
|
|
376
|
+
size["category"] = "large"
|
|
377
|
+
elif stats["source_files"] > 100 or stats["source_lines"] > 10000:
|
|
378
|
+
size["category"] = "medium"
|
|
379
|
+
|
|
380
|
+
return size
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
@script_error_handler
|
|
384
|
+
def main():
|
|
385
|
+
"""主函数"""
|
|
386
|
+
setup_encoding()
|
|
387
|
+
|
|
388
|
+
parser = argparse.ArgumentParser(
|
|
389
|
+
description="统计项目规模(文件数、代码行数、模块数)"
|
|
390
|
+
)
|
|
391
|
+
parser.add_argument(
|
|
392
|
+
"--path",
|
|
393
|
+
default=None,
|
|
394
|
+
help="项目根目录(默认: 当前目录)"
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
args = parser.parse_args()
|
|
398
|
+
|
|
399
|
+
# 获取项目根目录
|
|
400
|
+
try:
|
|
401
|
+
project_root = get_project_root(args.path)
|
|
402
|
+
except ValueError as e:
|
|
403
|
+
print(json.dumps({
|
|
404
|
+
"error": str(e)
|
|
405
|
+
}, ensure_ascii=False, indent=2))
|
|
406
|
+
sys.exit(3)
|
|
407
|
+
|
|
408
|
+
# 执行统计
|
|
409
|
+
modules = detect_modules(project_root)
|
|
410
|
+
deps = count_dependencies(project_root)
|
|
411
|
+
depth = calculate_dir_depth(project_root)
|
|
412
|
+
files = scan_files(project_root)
|
|
413
|
+
|
|
414
|
+
results = {
|
|
415
|
+
"timestamp": datetime.now().isoformat(),
|
|
416
|
+
"project_root": str(project_root),
|
|
417
|
+
"tech_stack": detect_tech_stack(project_root),
|
|
418
|
+
"modules": modules,
|
|
419
|
+
"dependencies": deps,
|
|
420
|
+
"dir_depth": depth,
|
|
421
|
+
"files": files,
|
|
422
|
+
"size": {},
|
|
423
|
+
"thresholds": LARGE_PROJECT_THRESHOLDS
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
# 判定项目规模
|
|
427
|
+
results["size"] = determine_project_size(files, modules, deps, depth)
|
|
428
|
+
|
|
429
|
+
# 输出JSON结果
|
|
430
|
+
print(json.dumps(results, ensure_ascii=False, indent=2))
|
|
431
|
+
|
|
432
|
+
# 返回状态码(0=小型, 1=中型, 2=大型)
|
|
433
|
+
size_codes = {"small": 0, "medium": 1, "large": 2}
|
|
434
|
+
sys.exit(size_codes.get(results["size"]["category"], 0))
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
if __name__ == "__main__":
|
|
438
|
+
main()
|