code-abyss 1.5.1

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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +197 -0
  3. package/bin/install.js +193 -0
  4. package/bin/uninstall.js +42 -0
  5. package/config/AGENTS.md +247 -0
  6. package/config/CLAUDE.md +207 -0
  7. package/config/settings.example.json +27 -0
  8. package/output-styles/abyss-cultivator.md +399 -0
  9. package/package.json +41 -0
  10. package/skills/SKILL.md +115 -0
  11. package/skills/ai/SKILL.md +29 -0
  12. package/skills/ai/agent-dev.md +242 -0
  13. package/skills/ai/llm-security.md +288 -0
  14. package/skills/architecture/SKILL.md +41 -0
  15. package/skills/architecture/api-design.md +225 -0
  16. package/skills/architecture/caching.md +299 -0
  17. package/skills/architecture/cloud-native.md +285 -0
  18. package/skills/architecture/compliance.md +299 -0
  19. package/skills/architecture/data-security.md +184 -0
  20. package/skills/architecture/message-queue.md +329 -0
  21. package/skills/architecture/security-arch.md +210 -0
  22. package/skills/development/SKILL.md +43 -0
  23. package/skills/development/cpp.md +246 -0
  24. package/skills/development/go.md +323 -0
  25. package/skills/development/java.md +277 -0
  26. package/skills/development/python.md +288 -0
  27. package/skills/development/rust.md +313 -0
  28. package/skills/development/shell.md +313 -0
  29. package/skills/development/typescript.md +277 -0
  30. package/skills/devops/SKILL.md +36 -0
  31. package/skills/devops/cost-optimization.md +272 -0
  32. package/skills/devops/database.md +217 -0
  33. package/skills/devops/devsecops.md +198 -0
  34. package/skills/devops/git-workflow.md +181 -0
  35. package/skills/devops/observability.md +280 -0
  36. package/skills/devops/performance.md +273 -0
  37. package/skills/devops/testing.md +186 -0
  38. package/skills/gen-docs/SKILL.md +114 -0
  39. package/skills/gen-docs/scripts/doc_generator.py +491 -0
  40. package/skills/multi-agent/SKILL.md +268 -0
  41. package/skills/run_skill.py +88 -0
  42. package/skills/security/SKILL.md +51 -0
  43. package/skills/security/blue-team.md +379 -0
  44. package/skills/security/code-audit.md +265 -0
  45. package/skills/security/pentest.md +226 -0
  46. package/skills/security/red-team.md +321 -0
  47. package/skills/security/threat-intel.md +322 -0
  48. package/skills/security/vuln-research.md +369 -0
  49. package/skills/tests/README.md +225 -0
  50. package/skills/tests/SUMMARY.md +362 -0
  51. package/skills/tests/__init__.py +3 -0
  52. package/skills/tests/test_change_analyzer.py +558 -0
  53. package/skills/tests/test_doc_generator.py +538 -0
  54. package/skills/tests/test_module_scanner.py +376 -0
  55. package/skills/tests/test_quality_checker.py +516 -0
  56. package/skills/tests/test_security_scanner.py +426 -0
  57. package/skills/verify-change/SKILL.md +138 -0
  58. package/skills/verify-change/scripts/change_analyzer.py +529 -0
  59. package/skills/verify-module/SKILL.md +125 -0
  60. package/skills/verify-module/scripts/module_scanner.py +321 -0
  61. package/skills/verify-quality/SKILL.md +158 -0
  62. package/skills/verify-quality/scripts/quality_checker.py +481 -0
  63. package/skills/verify-security/SKILL.md +141 -0
  64. package/skills/verify-security/scripts/security_scanner.py +368 -0
@@ -0,0 +1,491 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ 文档生成器
4
+ 自动生成/更新 README.md 和 DESIGN.md 骨架
5
+ """
6
+
7
+ import os
8
+ import sys
9
+ import json
10
+ import ast
11
+ from pathlib import Path
12
+ from dataclasses import dataclass, field
13
+ from typing import List, Dict, Optional
14
+ from datetime import datetime
15
+
16
+
17
+ @dataclass
18
+ class ModuleInfo:
19
+ name: str
20
+ path: str
21
+ description: str = ""
22
+ language: str = ""
23
+ files: List[str] = field(default_factory=list)
24
+ functions: List[Dict] = field(default_factory=list)
25
+ classes: List[Dict] = field(default_factory=list)
26
+ dependencies: List[str] = field(default_factory=list)
27
+ entry_points: List[str] = field(default_factory=list)
28
+
29
+
30
+ def detect_language(path: Path) -> str:
31
+ """检测主要编程语言"""
32
+ extensions = {}
33
+ for f in path.rglob('*'):
34
+ if f.is_file() and f.suffix:
35
+ ext = f.suffix.lower()
36
+ extensions[ext] = extensions.get(ext, 0) + 1
37
+
38
+ lang_map = {
39
+ '.py': 'Python',
40
+ '.go': 'Go',
41
+ '.rs': 'Rust',
42
+ '.ts': 'TypeScript',
43
+ '.js': 'JavaScript',
44
+ '.java': 'Java',
45
+ '.c': 'C',
46
+ '.cpp': 'C++',
47
+ }
48
+
49
+ code_exts = {k: v for k, v in extensions.items() if k in lang_map}
50
+ if code_exts:
51
+ main_ext = max(code_exts, key=code_exts.get)
52
+ return lang_map.get(main_ext, 'Unknown')
53
+
54
+ return 'Unknown'
55
+
56
+
57
+ def analyze_python_module(path: Path) -> ModuleInfo:
58
+ """分析 Python 模块"""
59
+ info = ModuleInfo(name=path.name, path=str(path), language='Python')
60
+
61
+ # 收集文件
62
+ py_files = list(path.rglob('*.py'))
63
+ info.files = [str(f.relative_to(path)) for f in py_files]
64
+
65
+ # 分析主要文件
66
+ for py_file in py_files:
67
+ if py_file.name.startswith('test_') or '_test' in py_file.name:
68
+ continue
69
+
70
+ try:
71
+ content = py_file.read_text(encoding='utf-8', errors='ignore')
72
+ tree = ast.parse(content)
73
+
74
+ # 提取模块文档字符串
75
+ if (ast.get_docstring(tree) and not info.description):
76
+ info.description = ast.get_docstring(tree).split('\n')[0]
77
+
78
+ # 提取函数和类
79
+ for node in ast.walk(tree):
80
+ if isinstance(node, ast.FunctionDef) and not node.name.startswith('_'):
81
+ doc = ast.get_docstring(node) or ""
82
+ info.functions.append({
83
+ "name": node.name,
84
+ "file": str(py_file.relative_to(path)),
85
+ "doc": doc.split('\n')[0] if doc else ""
86
+ })
87
+ elif isinstance(node, ast.ClassDef) and not node.name.startswith('_'):
88
+ doc = ast.get_docstring(node) or ""
89
+ info.classes.append({
90
+ "name": node.name,
91
+ "file": str(py_file.relative_to(path)),
92
+ "doc": doc.split('\n')[0] if doc else ""
93
+ })
94
+
95
+ # 检测入口点
96
+ if py_file.name in ['main.py', '__main__.py', 'cli.py', 'app.py']:
97
+ info.entry_points.append(str(py_file.relative_to(path)))
98
+
99
+ except Exception:
100
+ continue
101
+
102
+ # 检测依赖
103
+ req_files = ['requirements.txt', 'pyproject.toml', 'setup.py']
104
+ for req_file in req_files:
105
+ req_path = path / req_file
106
+ if req_path.exists():
107
+ try:
108
+ content = req_path.read_text()
109
+ if req_file == 'requirements.txt':
110
+ for line in content.split('\n'):
111
+ line = line.strip()
112
+ if line and not line.startswith('#'):
113
+ pkg = line.split('==')[0].split('>=')[0].split('<=')[0]
114
+ info.dependencies.append(pkg)
115
+ except Exception:
116
+ pass
117
+
118
+ return info
119
+
120
+
121
+ def analyze_module(path: Path) -> ModuleInfo:
122
+ """分析模块"""
123
+ language = detect_language(path)
124
+
125
+ if language == 'Python':
126
+ return analyze_python_module(path)
127
+
128
+ # 通用分析
129
+ info = ModuleInfo(name=path.name, path=str(path), language=language)
130
+
131
+ code_extensions = {'.py', '.go', '.rs', '.ts', '.js', '.java', '.c', '.cpp'}
132
+ for f in path.rglob('*'):
133
+ if f.is_file() and f.suffix.lower() in code_extensions:
134
+ info.files.append(str(f.relative_to(path)))
135
+
136
+ return info
137
+
138
+
139
+ def generate_readme(info: ModuleInfo, existing_content: str = None) -> str:
140
+ """生成 README.md"""
141
+ lines = []
142
+
143
+ lines.append(f"# {info.name}")
144
+ lines.append("")
145
+
146
+ # 描述
147
+ if info.description:
148
+ lines.append(info.description)
149
+ else:
150
+ lines.append("> 请在此描述模块的核心功能、解决的问题和主要用途。")
151
+ lines.append("> 例如:本模块提供 X 功能,用于解决 Y 问题。")
152
+ lines.append("")
153
+
154
+ # 概述
155
+ lines.append("## 概述")
156
+ lines.append("")
157
+ lines.append("<!-- 描述这个模块是什么,解决什么问题 -->")
158
+ lines.append("")
159
+
160
+ # 特性
161
+ lines.append("## 特性")
162
+ lines.append("")
163
+ lines.append("<!-- 列出模块的主要特性,每项应包含简短描述 -->")
164
+ lines.append("")
165
+ lines.append("- **特性1**: 请描述第一个主要特性")
166
+ lines.append("- **特性2**: 请描述第二个主要特性")
167
+ lines.append("- **特性3**: 请描述第三个主要特性")
168
+ lines.append("")
169
+
170
+ # 安装/依赖
171
+ if info.dependencies:
172
+ lines.append("## 依赖")
173
+ lines.append("")
174
+ lines.append("```")
175
+ for dep in info.dependencies[:10]:
176
+ lines.append(dep)
177
+ if len(info.dependencies) > 10:
178
+ lines.append(f"# ... 及其他 {len(info.dependencies) - 10} 个依赖")
179
+ lines.append("```")
180
+ lines.append("")
181
+
182
+ # 使用方法
183
+ lines.append("## 使用方法")
184
+ lines.append("")
185
+
186
+ if info.entry_points:
187
+ lines.append("### 运行")
188
+ lines.append("")
189
+ lines.append("```bash")
190
+ if info.language == 'Python':
191
+ lines.append(f"python -m {info.name}")
192
+ elif info.language == 'Go':
193
+ lines.append(f"go run ./cmd/main.go")
194
+ elif info.language == 'Rust':
195
+ lines.append(f"cargo run")
196
+ elif info.language == 'TypeScript' or info.language == 'JavaScript':
197
+ lines.append(f"npm start")
198
+ else:
199
+ lines.append(f"# 请根据 {info.language} 项目结构添加运行命令")
200
+ lines.append("```")
201
+ lines.append("")
202
+
203
+ lines.append("### 示例")
204
+ lines.append("")
205
+
206
+ # 根据语言生成示例模板
207
+ example_templates = {
208
+ 'Python': '''from {module_name} import main
209
+
210
+ # 初始化
211
+ obj = main()
212
+
213
+ # 执行操作
214
+ result = obj.process()
215
+ print(result)''',
216
+ 'Go': '''package main
217
+
218
+ import "{module_name}"
219
+
220
+ func main() {{
221
+ // 初始化
222
+ obj := {module_name}.New()
223
+
224
+ // 执行操作
225
+ result := obj.Process()
226
+ println(result)
227
+ }}''',
228
+ 'Rust': '''use {module_name}::*;
229
+
230
+ fn main() {{
231
+ // 初始化
232
+ let obj = Object::new();
233
+
234
+ // 执行操作
235
+ let result = obj.process();
236
+ println!("{{}}", result);
237
+ }}''',
238
+ 'TypeScript': '''import {{ main }} from "./{module_name}";
239
+
240
+ // 初始化
241
+ const obj = new main();
242
+
243
+ // 执行操作
244
+ const result = obj.process();
245
+ console.log(result);''',
246
+ 'JavaScript': '''const {{ main }} = require("./{module_name}");
247
+
248
+ // 初始化
249
+ const obj = new main();
250
+
251
+ // 执行操作
252
+ const result = obj.process();
253
+ console.log(result);''',
254
+ }
255
+
256
+ lang = info.language
257
+ if lang in example_templates:
258
+ template = example_templates[lang]
259
+ example = template.format(module_name=info.name.lower())
260
+ lines.append("```" + lang.lower())
261
+ lines.append(example)
262
+ lines.append("```")
263
+ else:
264
+ lines.append("```" + info.language.lower())
265
+ lines.append("<!-- 请根据 " + info.language + " 语言特性提供使用示例 -->")
266
+ lines.append("<!-- 示例应包含:初始化、基本操作、结果处理 -->")
267
+ lines.append("```")
268
+ lines.append("")
269
+
270
+ # API 概览
271
+ if info.classes or info.functions:
272
+ lines.append("## API 概览")
273
+ lines.append("")
274
+
275
+ if info.classes:
276
+ lines.append("### 类")
277
+ lines.append("")
278
+ lines.append("| 类名 | 描述 |")
279
+ lines.append("|------|------|")
280
+ for cls in info.classes[:10]:
281
+ doc = cls['doc'] or "请补充此类的功能描述"
282
+ lines.append(f"| `{cls['name']}` | {doc} |")
283
+ lines.append("")
284
+
285
+ if info.functions:
286
+ lines.append("### 函数")
287
+ lines.append("")
288
+ lines.append("| 函数 | 描述 |")
289
+ lines.append("|------|------|")
290
+ for func in info.functions[:10]:
291
+ doc = func['doc'] or "请补充此函数的功能描述"
292
+ lines.append(f"| `{func['name']}()` | {doc} |")
293
+ lines.append("")
294
+
295
+ # 目录结构
296
+ lines.append("## 目录结构")
297
+ lines.append("")
298
+ lines.append("```")
299
+ lines.append(f"{info.name}/")
300
+ for f in sorted(info.files)[:15]:
301
+ lines.append(f"├── {f}")
302
+ if len(info.files) > 15:
303
+ lines.append(f"└── ... ({len(info.files) - 15} more files)")
304
+ lines.append("```")
305
+ lines.append("")
306
+
307
+ # 相关文档
308
+ lines.append("## 相关文档")
309
+ lines.append("")
310
+ lines.append("- [设计文档](DESIGN.md)")
311
+ lines.append("")
312
+
313
+ return "\n".join(lines)
314
+
315
+
316
+ def generate_design(info: ModuleInfo, existing_content: str = None) -> str:
317
+ """生成 DESIGN.md"""
318
+ lines = []
319
+ today = datetime.now().strftime("%Y-%m-%d")
320
+
321
+ lines.append(f"# {info.name} 设计文档")
322
+ lines.append("")
323
+
324
+ # 概述
325
+ lines.append("## 设计概述")
326
+ lines.append("")
327
+ lines.append("### 目标")
328
+ lines.append("")
329
+ lines.append("<!-- 这个模块要解决什么问题? -->")
330
+ lines.append("")
331
+ lines.append("### 非目标")
332
+ lines.append("")
333
+ lines.append("<!-- 这个模块明确不做什么? -->")
334
+ lines.append("")
335
+
336
+ # 架构
337
+ lines.append("## 架构设计")
338
+ lines.append("")
339
+ lines.append("### 整体架构")
340
+ lines.append("")
341
+ lines.append("```")
342
+ lines.append("┌─────────────────────────────────────┐")
343
+ lines.append("│ 请在此绘制模块的整体架构图 │")
344
+ lines.append("│ 包括主要组件、数据流、依赖关系 │")
345
+ lines.append("│ 可使用 ASCII 图或 Mermaid 图表 │")
346
+ lines.append("└─────────────────────────────────────┘")
347
+ lines.append("```")
348
+ lines.append("")
349
+
350
+ lines.append("### 核心组件")
351
+ lines.append("")
352
+ if info.classes:
353
+ for cls in info.classes[:5]:
354
+ doc = cls['doc'] or "请描述此组件的职责和功能"
355
+ lines.append(f"- **{cls['name']}**: {doc}")
356
+ else:
357
+ lines.append("<!-- 列出模块的核心组件及其职责 -->")
358
+ lines.append("- **组件1**: 请描述第一个核心组件的职责")
359
+ lines.append("- **组件2**: 请描述第二个核心组件的职责")
360
+ lines.append("- **组件3**: 请描述第三个核心组件的职责")
361
+ lines.append("")
362
+
363
+ # 设计决策
364
+ lines.append("## 设计决策")
365
+ lines.append("")
366
+ lines.append("### 决策记录")
367
+ lines.append("")
368
+ lines.append("| 日期 | 决策 | 理由 | 影响 |")
369
+ lines.append("|------|------|------|------|")
370
+ lines.append(f"| {today} | 初始设计 | - | - |")
371
+ lines.append("")
372
+
373
+ lines.append("### 技术选型")
374
+ lines.append("")
375
+ lines.append(f"- **语言**: {info.language}")
376
+ if info.dependencies:
377
+ lines.append(f"- **主要依赖**: {', '.join(info.dependencies[:5])}")
378
+ lines.append("- **理由**: <!-- 请说明为什么选择这些技术栈,包括性能、可维护性、生态等考量 -->")
379
+ lines.append("")
380
+
381
+ # 权衡取舍
382
+ lines.append("## 权衡取舍")
383
+ lines.append("")
384
+ lines.append("### 已知限制")
385
+ lines.append("")
386
+ lines.append("<!-- 列出模块的已知限制和约束条件 -->")
387
+ lines.append("- **限制1**: 请描述第一个已知限制及其原因")
388
+ lines.append("- **限制2**: 请描述第二个已知限制及其原因")
389
+ lines.append("")
390
+ lines.append("### 技术债务")
391
+ lines.append("")
392
+ lines.append("<!-- 记录有意引入的技术债务、临时方案及其原因 -->")
393
+ lines.append("- **债务1**: 描述 | 原因:性能优先 | 计划偿还时间:v2.0")
394
+ lines.append("")
395
+
396
+ # 安全考量
397
+ lines.append("## 安全考量")
398
+ lines.append("")
399
+ lines.append("### 威胁模型")
400
+ lines.append("")
401
+ lines.append("<!-- 识别潜在的安全威胁,如认证、授权、数据泄露等 -->")
402
+ lines.append("- **威胁1**: 请描述潜在威胁及其影响")
403
+ lines.append("- **威胁2**: 请描述潜在威胁及其影响")
404
+ lines.append("")
405
+ lines.append("### 安全措施")
406
+ lines.append("")
407
+ lines.append("<!-- 列出已实施的安全措施,如输入验证、加密、访问控制等 -->")
408
+ lines.append("- **措施1**: 请描述已实施的安全措施")
409
+ lines.append("- **措施2**: 请描述已实施的安全措施")
410
+ lines.append("")
411
+
412
+ # 变更历史
413
+ lines.append("## 变更历史")
414
+ lines.append("")
415
+ lines.append(f"### {today} - 初始版本")
416
+ lines.append("")
417
+ lines.append("**变更内容**: 创建模块")
418
+ lines.append("")
419
+ lines.append("**变更理由**: 初始开发")
420
+ lines.append("")
421
+
422
+ return "\n".join(lines)
423
+
424
+
425
+ def generate_docs(path: str, force: bool = False) -> Dict[str, str]:
426
+ """生成文档"""
427
+ module_path = Path(path).resolve()
428
+ result = {"readme": None, "design": None, "status": "success", "messages": []}
429
+
430
+ if not module_path.exists():
431
+ result["status"] = "error"
432
+ result["messages"].append(f"路径不存在: {module_path}")
433
+ return result
434
+
435
+ # 分析模块
436
+ info = analyze_module(module_path)
437
+
438
+ # 生成 README.md
439
+ readme_path = module_path / "README.md"
440
+ if readme_path.exists() and not force:
441
+ result["messages"].append("README.md 已存在,跳过(使用 --force 覆盖)")
442
+ else:
443
+ existing = readme_path.read_text() if readme_path.exists() else None
444
+ content = generate_readme(info, existing)
445
+ readme_path.write_text(content)
446
+ result["readme"] = str(readme_path)
447
+ result["messages"].append(f"已生成 README.md")
448
+
449
+ # 生成 DESIGN.md
450
+ design_path = module_path / "DESIGN.md"
451
+ if design_path.exists() and not force:
452
+ result["messages"].append("DESIGN.md 已存在,跳过(使用 --force 覆盖)")
453
+ else:
454
+ existing = design_path.read_text() if design_path.exists() else None
455
+ content = generate_design(info, existing)
456
+ design_path.write_text(content)
457
+ result["design"] = str(design_path)
458
+ result["messages"].append(f"已生成 DESIGN.md")
459
+
460
+ return result
461
+
462
+
463
+ def main():
464
+ import argparse
465
+
466
+ parser = argparse.ArgumentParser(description="文档生成器")
467
+ parser.add_argument("path", nargs="?", default=".", help="模块路径")
468
+ parser.add_argument("-f", "--force", action="store_true", help="覆盖已存在的文档")
469
+ parser.add_argument("--json", action="store_true", help="JSON 格式输出")
470
+ parser.add_argument("--readme-only", action="store_true", help="仅生成 README.md")
471
+ parser.add_argument("--design-only", action="store_true", help="仅生成 DESIGN.md")
472
+
473
+ args = parser.parse_args()
474
+
475
+ result = generate_docs(args.path, args.force)
476
+
477
+ if args.json:
478
+ print(json.dumps(result, ensure_ascii=False, indent=2))
479
+ else:
480
+ print("=" * 50)
481
+ print("文档生成报告")
482
+ print("=" * 50)
483
+ for msg in result["messages"]:
484
+ print(f" • {msg}")
485
+ print("=" * 50)
486
+
487
+ sys.exit(0 if result["status"] == "success" else 1)
488
+
489
+
490
+ if __name__ == "__main__":
491
+ main()