sapbuddy-dsh 0.0.6 → 0.0.8

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 (57) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +25 -4
  3. package/defaults/AGENTS.md +114 -114
  4. package/defaults/connections.example.json +21 -21
  5. package/defaults/prompts/Memory.md +21 -21
  6. package/defaults/prompts/SYSTEM.md +110 -110
  7. package/defaults/settings.example.json +3 -3
  8. package/dist/client.js +20 -5
  9. package/dist/index.js +85 -11
  10. package/dist/sap-tools/adtManager.d.ts +11 -1
  11. package/dist/sap-tools/adtManager.js +176 -9
  12. package/dist/sap-tools/connections-store.js +16 -3
  13. package/dist/sap-tools/execution.js +1 -1
  14. package/dist/tools.js +5 -3
  15. package/package.json +8 -3
  16. package/skills/abap-code-review/SKILL.md +75 -75
  17. package/skills/abap-code-review/assets/report-template.html +142 -142
  18. package/skills/abap-code-review/references/checklist.md +114 -114
  19. package/skills/abap-explain/SKILL.md +126 -126
  20. package/skills/abap-templates/SKILL.md +764 -764
  21. package/skills/abap-wiki/SKILL.md +104 -104
  22. package/skills/clean-abap/SKILL.md +91 -91
  23. package/skills/clean-abap/references/CleanABAP_zh.md +4309 -4309
  24. package/skills/dev-write/SKILL.md +137 -137
  25. package/skills/sap-abap-skills/README.md +205 -205
  26. package/skills/sap-abap-skills/SKILL.md +498 -498
  27. package/skills/sap-abap-skills/references/abap-dictionary.md +211 -211
  28. package/skills/sap-abap-skills/references/abap-sql.md +588 -588
  29. package/skills/sap-abap-skills/references/amdp.md +279 -279
  30. package/skills/sap-abap-skills/references/authorization.md +149 -149
  31. package/skills/sap-abap-skills/references/bits-bytes.md +92 -92
  32. package/skills/sap-abap-skills/references/builtin-functions.md +373 -373
  33. package/skills/sap-abap-skills/references/cds-views.md +412 -412
  34. package/skills/sap-abap-skills/references/cloud-development.md +299 -299
  35. package/skills/sap-abap-skills/references/constructor-expressions.md +458 -458
  36. package/skills/sap-abap-skills/references/date-time.md +415 -415
  37. package/skills/sap-abap-skills/references/design-patterns.md +292 -292
  38. package/skills/sap-abap-skills/references/dynamic-programming.md +426 -426
  39. package/skills/sap-abap-skills/references/exceptions.md +432 -432
  40. package/skills/sap-abap-skills/references/generative-ai.md +180 -180
  41. package/skills/sap-abap-skills/references/internal-tables.md +578 -578
  42. package/skills/sap-abap-skills/references/numeric-operations.md +219 -219
  43. package/skills/sap-abap-skills/references/object-orientation.md +518 -518
  44. package/skills/sap-abap-skills/references/performance.md +428 -428
  45. package/skills/sap-abap-skills/references/program-flow.md +302 -302
  46. package/skills/sap-abap-skills/references/rap-eml.md +549 -549
  47. package/skills/sap-abap-skills/references/released-classes.md +308 -308
  48. package/skills/sap-abap-skills/references/sap-luw.md +203 -203
  49. package/skills/sap-abap-skills/references/skill-reference-guide.md +98 -98
  50. package/skills/sap-abap-skills/references/sql-hierarchies.md +180 -180
  51. package/skills/sap-abap-skills/references/string-processing.md +488 -488
  52. package/skills/sap-abap-skills/references/table-grouping.md +150 -150
  53. package/skills/sap-abap-skills/references/tool-guide.md +285 -285
  54. package/skills/sap-abap-skills/references/unit-testing.md +512 -512
  55. package/skills/sap-abap-skills/references/where-conditions.md +223 -223
  56. package/skills/sap-abap-skills/references/xml-json.md +315 -315
  57. package/skills/translate-workflow/SKILL.md +69 -69
@@ -1,104 +1,104 @@
1
- ---
2
- name: abap-wiki
3
- description: >-
4
- 当 `mcp__abap_wiki__*` 工具可用(用户已在设置-MCP 配置了 abap_wiki 知识库服务)
5
- 且用户询问某个 SAP 对象(程序/表/函数模块/类/CDS 视图/增强/事务码等)的用途、
6
- 业务逻辑、解释/分析、依赖、影响面时触发本技能。优先于读原始源码:
7
- 从 abap_wiki 知识库(公司 S/4HANA 开发系统自开发对象的已分析资料,页面英文)
8
- 查取页面,用双括号链接引用出处,并区分「知识库里写的」与「系统上查到的」。
9
- 触发关键词:查知识库、查 wiki、这个程序是做什么的、看下...逻辑、解释/分析一下、
10
- XXX 的分析、依赖谁、被谁用、修改影响哪些程序。
11
- agent_created: true
12
- disable: false
13
- ---
14
-
15
- # abap_wiki 知识库查询
16
-
17
- 公司 S/4HANA 开发系统**自开发 SAP/ABAP 对象**(程序、表、函数模块、类、增强、
18
- CDS 视图等)的技术知识库。页面内容全部是**英文**。每个对象已做代码分析、
19
- 业务功能分析,结论附可信度标记——查它比翻原始代码又快又准。
20
-
21
- ## 何时使用
22
-
23
- - 用户询问某个 Z*/Y* 对象(或知识库里收录的标准对象)的用途/业务逻辑/分析结论
24
- - 用户想了解对象间的依赖(谁依赖它、它被谁用)
25
- - 回答前先查知识库,避免每次从头读原始源码(省 token、有据可查)
26
- - ⚠️ 知识库没收录/只有 L0 占位页的对象,如实说「没有分析」,再走内置 SAP 工具读源码
27
-
28
- ## 前置条件
29
-
30
- - `mcp__abap_wiki__*` 工具已注册(用户已在设置-MCP 配置 abap_wiki 服务,底层为
31
- obsidian-vault-mcp,端口 8766)。浏览动作**一律用下面这些工具**:
32
- - `mcp__abap_wiki__list_notes(path)`:列出某目录下的笔记/子目录(非递归),用于浏览目录结构
33
- - `mcp__abap_wiki__search_notes(folder/text/tag/...)`:按目录/全文/标签找对象,返回路径
34
- - `mcp__abap_wiki__read_note(path)`:读单页完整内容
35
- - `mcp__abap_wiki__read_multiple_notes(paths, metadataOnly)`:批量读多页;`metadataOnly:true`
36
- 只返回 frontmatter/链接,用来看一批页面的 `doc_level` 再决定精读哪些(省 token)
37
- - ⚠️ **知识库只读**:只使用上面 4 个读/浏览工具。**禁止**调用 `mcp__abap_wiki__` 的写工具
38
- (`create_note`/`append_to_note`/`update_note`/`patch_note`/`delete_note`/`rename_note`)——
39
- 知识库由 abap_wiki 引擎生成维护,AI 不得修改。若用户要求改 wiki,直接说明"知识库只读,
40
- 不做修改"。
41
- - 若 MCP 未配置但本机存在 vault 目录(如 `~/Desktop/abap_wiki/abap_wiki/`),
42
- 也可用 read 工具直接读其中的 Markdown 文件(路径规则见下)。
43
-
44
- ## 怎么浏览(导航模式,从粗到细)
45
-
46
- 1. **先读总索引** `index.md`:按包和文档级别列出全部对象。
47
- → `read_note(path="index.md")` 或 `search_notes(folder="")`。
48
- 2. **再读包索引页** `_packages/<包名>.md`(如 `ZFI001`):
49
- 列出该包所有对象的 `[[链接]]` 与文档级别(L0/L1/L2)。
50
- → `read_note(path="_packages/ZFI001.md")`。
51
- 3. **最后打开具体对象页** `<包名>/<对象类型>-<对象名>.md`,
52
- 例如 `ZFI001/program-ZFIR015_BANK_SERCH.md`、`ZFI001/cds-view-ZFIV_ACDOCT_DDL.md`。
53
- → `read_note(path="ZFI001/program-ZFIR015_BANK_SERCH.md")`。
54
-
55
- 找对象时先 `search_notes(folder="<包名>")` 或 `list_notes(path="<包名>")` 缩小范围;
56
- 标准包(AA/AB/...)里大多是 L0 空壳页,先看 `doc_level` 再决定是否精读。
57
-
58
- 页面之间用**双括号链接**互相引用,例如 `[[program-ZFIR015_BANK_SERCH]]`
59
- 对应文件 `ZFI001/program-ZFIR015_BANK_SERCH.md`。只看到链接、不知道对象在哪个包时,
60
- 去 `index.md` 或页面头部元数据里找 `devclass` 字段。
61
-
62
- ## 页面头部元数据(frontmatter)
63
-
64
- 关键字段:
65
-
66
- - `sap_type`:对象类型(program/table/class/...)
67
- - `sap_name`:对象名
68
- - `devclass`:所属包
69
- - `doc_level`:文档级别(见下)
70
- - `depends_on`:依赖了谁
71
- - `used_by`:被谁使用
72
- - `bug_total`:疑似 bug 数量
73
- - `raw_source_status`:源码状态(available/partial/missing)
74
-
75
- `doc_level` 含义:
76
-
77
- - `L0`:只有占位/元数据。纯字典类对象(如数据元素 data-element)到 L0 就是终点。
78
- - `L1`:有代码分析,分析内容直接写在同一个页面上。
79
- - `L2`:在 L1 基础上叠加了业务功能分析。
80
-
81
- ## 页面内容(L1 页面包含的章节)
82
-
83
- 摘要 / 功能范围 / 选择屏幕 / 表单分析 / 输出映射 / 外部依赖(表、函数模块、消息类)/
84
- 性能 / 错误处理 / 遗留业务疑问 / 后续建议 / 疑似 bug 候选。
85
-
86
- 结论的可信度标记:
87
-
88
- - `[VERIFIED: 路径:N-M]`:由源码第 N-M 行证实(路径可能已过期,仅供参考)。
89
- - `[INFERRED]`:推断得出。
90
- - `[UNVERIFIABLE]`:需要连线上系统或问业务专家才能确认。
91
-
92
- ## 重点看哪里
93
-
94
- - 核心是**自开发包**(`Z*`/`Y*`,如 `ZBC`、`ZFI001`、`ZITS`、`ZMM001`、`ZPP001`、
95
- `ZQM001`、`ZSD001` 等);`_TMP_` 里是未归包的 Z 对象,同样是自开发内容。
96
- - 其他标准包目录(AA、AB 等)大多是**标准 SAP 对象的空壳页**(L0),价值低;
97
- 除非问题正好是关于已收录的标准对象,否则跳过。
98
-
99
- ## 回答规则
100
-
101
- - 用双括号页面链接(例如 `[[program-ZFIR015_BANK_SERCH]]`)引用你参考的页面。
102
- - **不要编造**代码、字段或行为。如果某个对象只有 L0 页或库里没有,就明说「没有分析」。
103
- - **区分「知识库里写的」和「系统上查到的」**:如果你在线上系统核实过某个事实,
104
- 要在回答里说明来源;知识库结论标注可信度标记(VERIFIED/INFERRED/UNVERIFIABLE)。
1
+ ---
2
+ name: abap-wiki
3
+ description: >-
4
+ 当 `mcp__abap_wiki__*` 工具可用(用户已在设置-MCP 配置了 abap_wiki 知识库服务)
5
+ 且用户询问某个 SAP 对象(程序/表/函数模块/类/CDS 视图/增强/事务码等)的用途、
6
+ 业务逻辑、解释/分析、依赖、影响面时触发本技能。优先于读原始源码:
7
+ 从 abap_wiki 知识库(公司 S/4HANA 开发系统自开发对象的已分析资料,页面英文)
8
+ 查取页面,用双括号链接引用出处,并区分「知识库里写的」与「系统上查到的」。
9
+ 触发关键词:查知识库、查 wiki、这个程序是做什么的、看下...逻辑、解释/分析一下、
10
+ XXX 的分析、依赖谁、被谁用、修改影响哪些程序。
11
+ agent_created: true
12
+ disable: false
13
+ ---
14
+
15
+ # abap_wiki 知识库查询
16
+
17
+ 公司 S/4HANA 开发系统**自开发 SAP/ABAP 对象**(程序、表、函数模块、类、增强、
18
+ CDS 视图等)的技术知识库。页面内容全部是**英文**。每个对象已做代码分析、
19
+ 业务功能分析,结论附可信度标记——查它比翻原始代码又快又准。
20
+
21
+ ## 何时使用
22
+
23
+ - 用户询问某个 Z*/Y* 对象(或知识库里收录的标准对象)的用途/业务逻辑/分析结论
24
+ - 用户想了解对象间的依赖(谁依赖它、它被谁用)
25
+ - 回答前先查知识库,避免每次从头读原始源码(省 token、有据可查)
26
+ - ⚠️ 知识库没收录/只有 L0 占位页的对象,如实说「没有分析」,再走内置 SAP 工具读源码
27
+
28
+ ## 前置条件
29
+
30
+ - `mcp__abap_wiki__*` 工具已注册(用户已在设置-MCP 配置 abap_wiki 服务,底层为
31
+ obsidian-vault-mcp,端口 8766)。浏览动作**一律用下面这些工具**:
32
+ - `mcp__abap_wiki__list_notes(path)`:列出某目录下的笔记/子目录(非递归),用于浏览目录结构
33
+ - `mcp__abap_wiki__search_notes(folder/text/tag/...)`:按目录/全文/标签找对象,返回路径
34
+ - `mcp__abap_wiki__read_note(path)`:读单页完整内容
35
+ - `mcp__abap_wiki__read_multiple_notes(paths, metadataOnly)`:批量读多页;`metadataOnly:true`
36
+ 只返回 frontmatter/链接,用来看一批页面的 `doc_level` 再决定精读哪些(省 token)
37
+ - ⚠️ **知识库只读**:只使用上面 4 个读/浏览工具。**禁止**调用 `mcp__abap_wiki__` 的写工具
38
+ (`create_note`/`append_to_note`/`update_note`/`patch_note`/`delete_note`/`rename_note`)——
39
+ 知识库由 abap_wiki 引擎生成维护,AI 不得修改。若用户要求改 wiki,直接说明"知识库只读,
40
+ 不做修改"。
41
+ - 若 MCP 未配置但本机存在 vault 目录(如 `~/Desktop/abap_wiki/abap_wiki/`),
42
+ 也可用 read 工具直接读其中的 Markdown 文件(路径规则见下)。
43
+
44
+ ## 怎么浏览(导航模式,从粗到细)
45
+
46
+ 1. **先读总索引** `index.md`:按包和文档级别列出全部对象。
47
+ → `read_note(path="index.md")` 或 `search_notes(folder="")`。
48
+ 2. **再读包索引页** `_packages/<包名>.md`(如 `ZFI001`):
49
+ 列出该包所有对象的 `[[链接]]` 与文档级别(L0/L1/L2)。
50
+ → `read_note(path="_packages/ZFI001.md")`。
51
+ 3. **最后打开具体对象页** `<包名>/<对象类型>-<对象名>.md`,
52
+ 例如 `ZFI001/program-ZFIR015_BANK_SERCH.md`、`ZFI001/cds-view-ZFIV_ACDOCT_DDL.md`。
53
+ → `read_note(path="ZFI001/program-ZFIR015_BANK_SERCH.md")`。
54
+
55
+ 找对象时先 `search_notes(folder="<包名>")` 或 `list_notes(path="<包名>")` 缩小范围;
56
+ 标准包(AA/AB/...)里大多是 L0 空壳页,先看 `doc_level` 再决定是否精读。
57
+
58
+ 页面之间用**双括号链接**互相引用,例如 `[[program-ZFIR015_BANK_SERCH]]`
59
+ 对应文件 `ZFI001/program-ZFIR015_BANK_SERCH.md`。只看到链接、不知道对象在哪个包时,
60
+ 去 `index.md` 或页面头部元数据里找 `devclass` 字段。
61
+
62
+ ## 页面头部元数据(frontmatter)
63
+
64
+ 关键字段:
65
+
66
+ - `sap_type`:对象类型(program/table/class/...)
67
+ - `sap_name`:对象名
68
+ - `devclass`:所属包
69
+ - `doc_level`:文档级别(见下)
70
+ - `depends_on`:依赖了谁
71
+ - `used_by`:被谁使用
72
+ - `bug_total`:疑似 bug 数量
73
+ - `raw_source_status`:源码状态(available/partial/missing)
74
+
75
+ `doc_level` 含义:
76
+
77
+ - `L0`:只有占位/元数据。纯字典类对象(如数据元素 data-element)到 L0 就是终点。
78
+ - `L1`:有代码分析,分析内容直接写在同一个页面上。
79
+ - `L2`:在 L1 基础上叠加了业务功能分析。
80
+
81
+ ## 页面内容(L1 页面包含的章节)
82
+
83
+ 摘要 / 功能范围 / 选择屏幕 / 表单分析 / 输出映射 / 外部依赖(表、函数模块、消息类)/
84
+ 性能 / 错误处理 / 遗留业务疑问 / 后续建议 / 疑似 bug 候选。
85
+
86
+ 结论的可信度标记:
87
+
88
+ - `[VERIFIED: 路径:N-M]`:由源码第 N-M 行证实(路径可能已过期,仅供参考)。
89
+ - `[INFERRED]`:推断得出。
90
+ - `[UNVERIFIABLE]`:需要连线上系统或问业务专家才能确认。
91
+
92
+ ## 重点看哪里
93
+
94
+ - 核心是**自开发包**(`Z*`/`Y*`,如 `ZBC`、`ZFI001`、`ZITS`、`ZMM001`、`ZPP001`、
95
+ `ZQM001`、`ZSD001` 等);`_TMP_` 里是未归包的 Z 对象,同样是自开发内容。
96
+ - 其他标准包目录(AA、AB 等)大多是**标准 SAP 对象的空壳页**(L0),价值低;
97
+ 除非问题正好是关于已收录的标准对象,否则跳过。
98
+
99
+ ## 回答规则
100
+
101
+ - 用双括号页面链接(例如 `[[program-ZFIR015_BANK_SERCH]]`)引用你参考的页面。
102
+ - **不要编造**代码、字段或行为。如果某个对象只有 L0 页或库里没有,就明说「没有分析」。
103
+ - **区分「知识库里写的」和「系统上查到的」**:如果你在线上系统核实过某个事实,
104
+ 要在回答里说明来源;知识库结论标注可信度标记(VERIFIED/INFERRED/UNVERIFIABLE)。
@@ -1,91 +1,91 @@
1
- ---
2
- name: clean-abap
3
- description: >-
4
- Applies the SAP Clean ABAP style guide (Clean Code for ABAP) to review,
5
- generate, and refactor ABAP code. Use whenever the user asks to review
6
- ABAP code quality, write new ABAP code following SAP best practices,
7
- refactor legacy ABAP toward modern style, or has questions about ABAP
8
- naming, method design, error handling, internal tables, testing, etc.
9
- ---
10
-
11
- # Clean ABAP Skill
12
-
13
- Follow the official **SAP Clean ABAP style guide** (an adoption of Robert C. Martin's *Clean Code* for ABAP) in all ABAP work.
14
-
15
- > **命名例外(本项目覆盖)**:本技能的无前缀命名建议**不适用于本项目**——
16
- > SapBuddy 保留匈牙利前缀(`lv_`/`ls_`/`lt_`/`iv_`/`ev_`/`gv_`/`gt_` 等,企业通行惯例),
17
- > 以 `dev-write` 技能命名规则为准;其余规范(方法短小、OO 优先、错误处理、SQL、注释、单测)仍然适用。
18
- >
19
- > **触发协调**:本技能提供代码规范与质量评审标准;
20
- > 用户要求"审查/审计/code review XXX"并产出 HTML 报告时,走 `abap-code-review` 技能(含 4 页签报告模板),
21
- > 其审查标准即依据本技能(Clean ABAP)。
22
- > 用户要求"解释/分析程序逻辑"时,走 `abap-explain` 技能。
23
-
24
- The full Chinese guide (4300+ lines, 17 chapters, every rule with examples) is in [references/CleanABAP_zh.md](references/CleanABAP_zh.md). **Consult it whenever a topic below is ambiguous, the user asks "why", or you need the exact example syntax.** English original: https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md
25
-
26
- ## When to use
27
-
28
- - User asks to **review** ABAP code for quality/cleanliness
29
- - User asks to **write or generate** new ABAP code (classes, methods, reports, function modules → classes)
30
- - User asks to **refactor / modernize** legacy ABAP
31
- - User asks ABAP style questions (naming, method signatures, exceptions, tables, testing)
32
-
33
- ## Core Rules (apply by default)
34
-
35
- ### Names
36
- - Descriptive, self-explaining names. `customer` not `cust`; `is_available` not `available_flag`.
37
- - Classes = nouns, methods = verbs (imperative for commands: `calculate_tax`, predicative for queries: `is_empty`, `has_entries`).
38
- - `snake_case` for everything. No Hungarian notation, no prefixes (no `lv_`, `mv_`, `gv_`). No noise words (`data`, `info`, `object`, `temp`).
39
- - One word per concept; use pattern names only if you mean the pattern.
40
-
41
- ### Language
42
- - Prefer object-oriented over procedural; prefer functional constructs (filter/map/reduce, table expressions) over procedural loops where readable.
43
- - Prefer modern syntax: inline declarations (`DATA(x) = ...`), `NEW`, string templates `` |...| ``, `xsdbool`, `COND`/`SWITCH`, table expressions `itab[ ... ]`, `line_exists( ... )`.
44
- - Avoid obsolete elements (`MOVE`, `COLLECT`?, old `OCCURS`, `TYPE-POOLS`, etc.).
45
- - Classes: `FINAL` unless designed for inheritance; members `PRIVATE` by default; prefer composition over inheritance; prefer immutable over getters/setters; prefer `NEW` over `CREATE OBJECT`.
46
-
47
- ### Methods
48
- - **One method = one thing.** Keep methods small; descend one level of abstraction; prefer the happy path (fail fast at top with guards).
49
- - Few `IMPORTING` parameters (aim < 3). Prefer `RETURNING` over `EXPORTING`; don't mix RETURNING/EXPORTING/CHANGING in one method.
50
- - Name the single `RETURNING` parameter `RESULT` when no better name exists.
51
- - No `OPTIONAL` parameters to widen behavior — split the method instead. Boolean input parameters → split method instead.
52
- - Inline declarations where possible; no up-front declaration chains at method top.
53
- - Loops: `LOOP AT ... WHERE`, prefer `line_exists`/`read table` over scanning whole tables.
54
-
55
- ### Error handling
56
- - Prefer class-based exceptions over return codes / `SY-SUBRC` checks. Exceptions are for *errors*, not regular cases.
57
- - Throw `CX_STATIC_CHECK` for manageable errors, `CX_NO_CHECK` for unrecoverable ones; use your own exception super class.
58
- - `RAISE EXCEPTION NEW cx_...(...)` (not `TYPE`). Catch foreign exceptions and wrap them in your own.
59
- - Fail fast: validate at method start.
60
-
61
- ### Comments
62
- - Code should explain itself; comments explain **why**, not what. No commented-out code, no signature/end-of-method comments, no manual versioning (`*---- history`).
63
-
64
- ### Tables & conditions
65
- - Right table type (STANDARD/SORTED/HASHED); no `DEFAULT KEY` when a semantic key exists; `INSERT INTO TABLE` over `APPEND TO`.
66
- - Positive conditions (`IF is_available` not `IF NOT is_available`); `CASE` over multiple `ELSE IF`; keep nesting depth ≤ 3; extract complex conditions to boolean methods.
67
-
68
- ## Usage modes
69
-
70
- ### 1. Review mode
71
- User gives ABAP code (pasted or as files in the project). Produce a structured review:
72
- 1. Scan for violations of the Core Rules above; for each finding, read the relevant section of the full guide for exact wording.
73
- 2. Output a table: `| # | 严重度 (high/medium/low) | 位置 (class/method/line) | 违反规则 | 问题说明 | 修改建议 |`
74
- 3. For high/medium findings, show the concrete before/after code snippet.
75
- 4. End with a short summary (top 3 improvements) and offer to apply fixes.
76
-
77
- ### 2. Generate mode
78
- When writing new ABAP code:
79
- - Follow all Core Rules; prefer object-oriented structure; methods do one thing; prefer `RETURNING`; exceptions not return codes; snake_case naming; inline declarations.
80
- - If user names the object (e.g. a class or report), derive clean names for members/methods from it.
81
- - Ask when requirements are ambiguous, but propose sensible defaults (e.g. `FINAL` class, `CREATE PUBLIC` + `NEW`).
82
-
83
- ### 3. Refactor mode
84
- When modernizing legacy ABAP:
85
- - Work incrementally, one object/one method at a time. Do not mix styles inside one object (e.g. don't half-convert up-front declarations to inline).
86
- - Priority order for legacy: Booleans → Conditions → Ifs → Methods (biggest win) → Tables → Error handling → Names (most controversial, often skip full rename in legacy).
87
- - Keep behavior identical; refactor and test separately. Follow the "boy scout rule" (leave code cleaner than you found it) but respect scope.
88
-
89
- ## Reporting
90
- - When citing a rule, reference it like `CleanABAP > Methods > 一个方法只做一件事` (Chinese guide) so the user can look it up.
91
- - If unsure about a rule or needing exact examples, read [references/CleanABAP_zh.md](references/CleanABAP_zh.md) first.
1
+ ---
2
+ name: clean-abap
3
+ description: >-
4
+ Applies the SAP Clean ABAP style guide (Clean Code for ABAP) to review,
5
+ generate, and refactor ABAP code. Use whenever the user asks to review
6
+ ABAP code quality, write new ABAP code following SAP best practices,
7
+ refactor legacy ABAP toward modern style, or has questions about ABAP
8
+ naming, method design, error handling, internal tables, testing, etc.
9
+ ---
10
+
11
+ # Clean ABAP Skill
12
+
13
+ Follow the official **SAP Clean ABAP style guide** (an adoption of Robert C. Martin's *Clean Code* for ABAP) in all ABAP work.
14
+
15
+ > **命名例外(本项目覆盖)**:本技能的无前缀命名建议**不适用于本项目**——
16
+ > SapBuddy 保留匈牙利前缀(`lv_`/`ls_`/`lt_`/`iv_`/`ev_`/`gv_`/`gt_` 等,企业通行惯例),
17
+ > 以 `dev-write` 技能命名规则为准;其余规范(方法短小、OO 优先、错误处理、SQL、注释、单测)仍然适用。
18
+ >
19
+ > **触发协调**:本技能提供代码规范与质量评审标准;
20
+ > 用户要求"审查/审计/code review XXX"并产出 HTML 报告时,走 `abap-code-review` 技能(含 4 页签报告模板),
21
+ > 其审查标准即依据本技能(Clean ABAP)。
22
+ > 用户要求"解释/分析程序逻辑"时,走 `abap-explain` 技能。
23
+
24
+ The full Chinese guide (4300+ lines, 17 chapters, every rule with examples) is in [references/CleanABAP_zh.md](references/CleanABAP_zh.md). **Consult it whenever a topic below is ambiguous, the user asks "why", or you need the exact example syntax.** English original: https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md
25
+
26
+ ## When to use
27
+
28
+ - User asks to **review** ABAP code for quality/cleanliness
29
+ - User asks to **write or generate** new ABAP code (classes, methods, reports, function modules → classes)
30
+ - User asks to **refactor / modernize** legacy ABAP
31
+ - User asks ABAP style questions (naming, method signatures, exceptions, tables, testing)
32
+
33
+ ## Core Rules (apply by default)
34
+
35
+ ### Names
36
+ - Descriptive, self-explaining names. `customer` not `cust`; `is_available` not `available_flag`.
37
+ - Classes = nouns, methods = verbs (imperative for commands: `calculate_tax`, predicative for queries: `is_empty`, `has_entries`).
38
+ - `snake_case` for everything. No Hungarian notation, no prefixes (no `lv_`, `mv_`, `gv_`). No noise words (`data`, `info`, `object`, `temp`).
39
+ - One word per concept; use pattern names only if you mean the pattern.
40
+
41
+ ### Language
42
+ - Prefer object-oriented over procedural; prefer functional constructs (filter/map/reduce, table expressions) over procedural loops where readable.
43
+ - Prefer modern syntax: inline declarations (`DATA(x) = ...`), `NEW`, string templates `` |...| ``, `xsdbool`, `COND`/`SWITCH`, table expressions `itab[ ... ]`, `line_exists( ... )`.
44
+ - Avoid obsolete elements (`MOVE`, `COLLECT`?, old `OCCURS`, `TYPE-POOLS`, etc.).
45
+ - Classes: `FINAL` unless designed for inheritance; members `PRIVATE` by default; prefer composition over inheritance; prefer immutable over getters/setters; prefer `NEW` over `CREATE OBJECT`.
46
+
47
+ ### Methods
48
+ - **One method = one thing.** Keep methods small; descend one level of abstraction; prefer the happy path (fail fast at top with guards).
49
+ - Few `IMPORTING` parameters (aim < 3). Prefer `RETURNING` over `EXPORTING`; don't mix RETURNING/EXPORTING/CHANGING in one method.
50
+ - Name the single `RETURNING` parameter `RESULT` when no better name exists.
51
+ - No `OPTIONAL` parameters to widen behavior — split the method instead. Boolean input parameters → split method instead.
52
+ - Inline declarations where possible; no up-front declaration chains at method top.
53
+ - Loops: `LOOP AT ... WHERE`, prefer `line_exists`/`read table` over scanning whole tables.
54
+
55
+ ### Error handling
56
+ - Prefer class-based exceptions over return codes / `SY-SUBRC` checks. Exceptions are for *errors*, not regular cases.
57
+ - Throw `CX_STATIC_CHECK` for manageable errors, `CX_NO_CHECK` for unrecoverable ones; use your own exception super class.
58
+ - `RAISE EXCEPTION NEW cx_...(...)` (not `TYPE`). Catch foreign exceptions and wrap them in your own.
59
+ - Fail fast: validate at method start.
60
+
61
+ ### Comments
62
+ - Code should explain itself; comments explain **why**, not what. No commented-out code, no signature/end-of-method comments, no manual versioning (`*---- history`).
63
+
64
+ ### Tables & conditions
65
+ - Right table type (STANDARD/SORTED/HASHED); no `DEFAULT KEY` when a semantic key exists; `INSERT INTO TABLE` over `APPEND TO`.
66
+ - Positive conditions (`IF is_available` not `IF NOT is_available`); `CASE` over multiple `ELSE IF`; keep nesting depth ≤ 3; extract complex conditions to boolean methods.
67
+
68
+ ## Usage modes
69
+
70
+ ### 1. Review mode
71
+ User gives ABAP code (pasted or as files in the project). Produce a structured review:
72
+ 1. Scan for violations of the Core Rules above; for each finding, read the relevant section of the full guide for exact wording.
73
+ 2. Output a table: `| # | 严重度 (high/medium/low) | 位置 (class/method/line) | 违反规则 | 问题说明 | 修改建议 |`
74
+ 3. For high/medium findings, show the concrete before/after code snippet.
75
+ 4. End with a short summary (top 3 improvements) and offer to apply fixes.
76
+
77
+ ### 2. Generate mode
78
+ When writing new ABAP code:
79
+ - Follow all Core Rules; prefer object-oriented structure; methods do one thing; prefer `RETURNING`; exceptions not return codes; snake_case naming; inline declarations.
80
+ - If user names the object (e.g. a class or report), derive clean names for members/methods from it.
81
+ - Ask when requirements are ambiguous, but propose sensible defaults (e.g. `FINAL` class, `CREATE PUBLIC` + `NEW`).
82
+
83
+ ### 3. Refactor mode
84
+ When modernizing legacy ABAP:
85
+ - Work incrementally, one object/one method at a time. Do not mix styles inside one object (e.g. don't half-convert up-front declarations to inline).
86
+ - Priority order for legacy: Booleans → Conditions → Ifs → Methods (biggest win) → Tables → Error handling → Names (most controversial, often skip full rename in legacy).
87
+ - Keep behavior identical; refactor and test separately. Follow the "boy scout rule" (leave code cleaner than you found it) but respect scope.
88
+
89
+ ## Reporting
90
+ - When citing a rule, reference it like `CleanABAP > Methods > 一个方法只做一件事` (Chinese guide) so the user can look it up.
91
+ - If unsure about a rule or needing exact examples, read [references/CleanABAP_zh.md](references/CleanABAP_zh.md) first.