kcode-pi 0.1.5 → 0.1.7

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 (50) hide show
  1. package/README.md +35 -2
  2. package/dist/cli/kcode.d.ts +1 -0
  3. package/dist/cli/kcode.js +27 -4
  4. package/package.json +1 -1
  5. package/src/cli/kcode.ts +29 -4
  6. package/src/official/kingdee-skills.ts +60 -13
  7. package/src/rules/checker.ts +143 -0
  8. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/SKILL.md +2 -2
  9. package/vendor/kingdee-skills/ok-cosmic/SKILL.md +52 -101
  10. package/vendor/kingdee-skills/ok-cosmic/agents/openai.yaml +4 -4
  11. package/vendor/kingdee-skills/ok-cosmic/manifest.json +21 -20
  12. package/vendor/kingdee-skills/ok-cosmic/ok-cosmic-intro.html +1 -1
  13. package/vendor/kingdee-skills/ok-cosmic/rules/a-layer-rules.json +1 -1
  14. package/vendor/kingdee-skills/ok-cosmic/rules/anti-patterns.md +2 -2
  15. package/vendor/kingdee-skills/ok-cosmic/rules/coding-preferences.md +4 -4
  16. package/vendor/kingdee-skills/ok-cosmic/rules/constraints.md +3 -3
  17. package/vendor/kingdee-skills/ok-cosmic/rules/decision-matrix.md +8 -8
  18. package/vendor/kingdee-skills/ok-cosmic/rules/intent-routing.md +1 -1
  19. package/vendor/kingdee-skills/ok-cosmic/rules/post-check.md +19 -18
  20. package/vendor/kingdee-skills/ok-ksql/SKILL.md +9 -9
  21. package/vendor/kingdee-skills/ok-ksql/manifest.json +2 -1
  22. package/vendor/kingdee-skills/ok-ksql/references/ksql-datafix.md +2 -2
  23. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/pattern-matcher.py +0 -336
  24. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/review-score-calculator.py +0 -121
  25. package/vendor/kingdee-skills/ok-cosmic/CHANGELOG.md +0 -295
  26. package/vendor/kingdee-skills/ok-cosmic/README.md +0 -460
  27. package/vendor/kingdee-skills/ok-cosmic/requirements.txt +0 -2
  28. package/vendor/kingdee-skills/ok-cosmic/scripts/config_loader.py +0 -204
  29. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-api-knowledge.py +0 -910
  30. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-basedata-query.py +0 -359
  31. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-config-check.py +0 -181
  32. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-extpoints-query.py +0 -389
  33. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-form-metadata.py +0 -856
  34. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-check.py +0 -262
  35. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-lint.py +0 -293
  36. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/__init__.py +0 -2
  37. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/base.py +0 -393
  38. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/resource_check.py +0 -176
  39. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/scene_check.py +0 -375
  40. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/style_check.py +0 -434
  41. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/verify_check.py +0 -36
  42. package/vendor/kingdee-skills/ok-cosmic/scripts/route_client.py +0 -186
  43. package/vendor/kingdee-skills/ok-cosmic/scripts/script_utils.py +0 -40
  44. package/vendor/kingdee-skills/ok-cosmic/scripts/sqlite_cache.py +0 -142
  45. package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-commons.jar +0 -0
  46. package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-features.jar +0 -0
  47. package/vendor/kingdee-skills/ok-cosmic/setup/setup-mac.sh +0 -18
  48. package/vendor/kingdee-skills/ok-cosmic/setup/setup-windows.bat +0 -53
  49. package/vendor/kingdee-skills/ok-cosmic/setup/setup.jar +0 -0
  50. package/vendor/kingdee-skills/ok-ksql/scripts/ksql_lint.py +0 -363
@@ -1,460 +0,0 @@
1
- # ok-cosmic
2
-
3
- **作者:** 陈泽贤、钱芮名
4
-
5
- **注意:仅限内部使用**
6
-
7
- 面向金蝶云苍穹开发的 AI Skill,提供插件模板、离线 API 知识查询、表单元数据查询、基础资料查询与文档增强能力。
8
-
9
- ---
10
-
11
- ## 📌 概览
12
-
13
- `ok-cosmic` 是一个面向金蝶云苍穹开发的 AI Skill,聚焦表单插件、单据插件、列表插件、操作插件、BOTP 转换、报表插件、工作流、后台任务、OpenAPI 等常见二开场景。它结合本地知识库、文档库、查询脚本、模板骨架和规则约束,帮助 AI 更准确地理解苍穹 SDK、ServiceHelper、元数据字段与插件生命周期,降低 API 幻觉和字段误用风险。
14
-
15
- ## 🧠 核心能力
16
-
17
- - `🧩` 插件选型与模板骨架:支持苍穹常见开发场景的插件选型、模板骨架和开发约束
18
- - `🔎` 离线 API 查询:支持查询类、方法、返回值、参数说明、继承链和方法注释
19
- - `🗂️` 表单元数据 / 基础资料 / 业务拓展点查询:支持查询字段标识、引用类型、枚举映射、基础资料编码名称映射和业务拓展点候选接口
20
- - `📝` 文档增强回填:支持利用文档库补齐参数名、参数说明和父类/接口方法注释
21
- - `⚡` 紧凑事实输出:支持低噪音输出,便于继续交给 AI 生成代码
22
-
23
- ## 🧭 规则分层与校验
24
-
25
- `ok-cosmic` 当前将规则分为三层:
26
-
27
- - `A 层`:硬约束 / 交付红线。直接影响事实准确性、事件阶段、插件上下文与运行期正确性。
28
- - `B 层`:推荐项 / 新代码默认写法。代表团队希望新代码优先采用的封装、工具类和实现风格。
29
- - `C 层`:目标态治理 / 渐进优化。适合模板升级、专项治理和批量重构,不作为默认一次性交付阻断项。
30
-
31
- 代码生成后的默认校验命令:
32
-
33
- ```bash
34
- python3 <SKILL_ROOT>/scripts/cosmic-post-check.py <file-or-dir> --fix-hint
35
- ```
36
-
37
- 默认模式下:
38
-
39
- - `ERROR`:按 A 层硬约束处理,必须修复
40
- - `WARNING`:按 B 层推荐项处理,新代码优先修复
41
- - `INFO`:按 C 层治理项处理,作为后续优化参考
42
-
43
- 当需要做模板升级、补验证来源留痕或更严格的治理检查时,可追加严格模式:
44
-
45
- ```bash
46
- python3 <SKILL_ROOT>/scripts/cosmic-post-check.py <file-or-dir> --fix-hint --strict
47
- ```
48
-
49
- ## 🚀 快速开始与安装
50
-
51
- ### 快速分流
52
-
53
- | 你的情况 | 从哪步开始 | 预计耗时 |
54
- |----------|-----------|--------|
55
- | 首次完整安装(含服务端) | 步骤 1 | 30 分钟 |
56
- | 服务端已就绪,新项目接入 | 步骤 6 | 2 分钟 |
57
- | 已有项目,换 Agent | 步骤 7 | 1 分钟 |
58
-
59
- > 步骤 2–3 为**服务端一次性配置**,完成后所有项目共享;步骤 4–5 为**知识库一次性构建**,构建完成后复制即用。
60
-
61
- 下面是完整安装与使用流程。
62
-
63
- ## 1. 环境检查
64
-
65
- 在开始之前,请确保您的系统满足以下要求:
66
-
67
- ### 必需环境
68
-
69
- | 依赖项 | 版本要求 | 检查命令 | 备注 |
70
- |--------|--------|----------|------|
71
- | Java | JDK 8+ | `java -version` | 必须配置 JAVA_HOME |
72
- | Python | 3.8+ | `python3 --version` | 用于 API 知识查询脚本 |
73
-
74
- > Python 依赖包(tree-sitter 等)无需手动安装——Step 0 配置预检会自动检测并安装。完整清单见 `requirements.txt`。
75
-
76
- ### 检查清单
77
-
78
- ```bash
79
- # 检查 Java 版本
80
- java -version
81
-
82
- # 检查 Python 版本
83
- python3 --version
84
-
85
- # 检查 JAVA_HOME 是否配置(Mac/Linux)
86
- echo $JAVA_HOME
87
-
88
- # 检查 JAVA_HOME 是否配置(Windows)
89
- echo %JAVA_HOME%
90
- ```
91
-
92
- ---
93
-
94
- ## 2. 部署自定义封装库
95
-
96
- 将 `setup/cuslib/` 目录下的两个 JAR 包部署到苍穹环境:
97
-
98
- ### 2.1 本地环境部署
99
-
100
- 将以下 JAR 文件复制到苍穹本地开发环境的 `cus` 目录:
101
-
102
- ```
103
- setup/cuslib/
104
- ├── kd-cd-cosmic-commons.jar # 公共封装库
105
- └── kd-cd-cosmic-features.jar # 功能封装库
106
- ```
107
-
108
- **目标路径示例:**
109
- ```bash
110
- # Mac/Linux
111
- cp setup/cuslib/*.jar /path/to/cosmic/cus/
112
-
113
- # Windows
114
- copy setup\cuslib\*.jar C:\path\to\cosmic\cus\
115
- ```
116
-
117
- ### 2.2 Dev 线上环境部署
118
-
119
- 将上述 JAR 包同时部署到 Dev 线上环境,确保封装库在开发调试时可用。
120
-
121
- ---
122
-
123
- ## 3. 统一路由 API 注册
124
-
125
- 将统一路由接口注册到 Dev 环境的 OpenAPI,用于在线查询表单元数据、基础资料和业务拓展点。
126
-
127
- ### 3.1 注册接口
128
-
129
- 在苍穹开发平台中,注册提供 `runtime/route` 的自定义接口。
130
-
131
- **注册步骤:**
132
- 1. 登录 Dev 环境苍穹开发平台
133
- 2. 进入 **OpenAPI 管理** → **自定义接口**
134
- 3. 新增接口,填写统一路由控制器类名:kd.cd.feature.ai.mcp.route.McpRoutingController
135
- 4. **推荐使用基本认证(Basic Auth)** 方式注册
136
-
137
- ### 3.2 获取统一路由 API URL
138
-
139
- 注册成功后,获取统一路由 API URL,格式如下:
140
-
141
- ```
142
- https://deverp.xxxx.com/ierp/kapi/v2/xxxx/xxxx_devportal_ext/runtime/route?openApiSign=YOUR_SIGN_HERE
143
- ```
144
-
145
- ### 3.3 配置统一路由 API 地址
146
-
147
- 将获取的 API URL 填入配置文件 `ok-cosmic.json` 的 `route.apiUrl` 字段:
148
-
149
- ```json
150
- {
151
- "route": {
152
- "apiUrl": "https://deverp.xxxx.com/ierp/kapi/v2/xxxx/xxxx_devportal_ext/runtime/route?openApiSign=YOUR_SIGN_HERE",
153
- "timeoutSeconds": 30
154
- }
155
- }
156
- ```
157
- ---
158
-
159
- ## 4. 知识库构建
160
-
161
- 运行初始化工具构建知识库。setup.jar 已自带,无需额外构建。
162
-
163
- **Mac/Linux:**
164
- ```bash
165
- cd skills/ok-cosmic/setup
166
- chmod +x setup-mac.sh
167
- ./setup-mac.sh -libpath=<项目苍穹JAR库目录>
168
- ```
169
-
170
- **Windows:**
171
- ```cmd
172
- cd skills\ok-cosmic\setup
173
- setup-windows.bat -libpath=<项目苍穹JAR库目录>
174
- ```
175
-
176
- ### 4.1 参数说明
177
-
178
- | 参数 | 说明 | 默认值 | 必填 |
179
- |------|------|--------|------|
180
- | `-libpath` | 苍穹 SDK JAR 库目录 | 无 | 推荐 |
181
- | `-docsdbpath` | 文档数据库路径 | `ok-cosmic-docs.db` | 否 |
182
- | `-dbpath` | 输出知识库文件路径 | `ok-cosmic-knowledge.db` | 否 |
183
- | `-jarthreads` | JAR 解析并发线程数 | CPU 核心数 | 否 |
184
- | `-verifyjar` | 校验用 JAR 文件路径 | - | 否 |
185
- | `-verifyclass` | 校验用完整类名 | - | 否 |
186
-
187
- ### 4.2 典型使用示例
188
-
189
- ```bash
190
- # 使用默认参数
191
- ./setup-mac.sh
192
-
193
- # 指定自定义路径
194
- ./setup-mac.sh -libpath=/path/to/cosmic/libs
195
-
196
- # 使用多线程加速构建
197
- ./setup-mac.sh -libpath=./libs -jarthreads=8
198
- ```
199
-
200
- ---
201
-
202
- ## 5. 知识验证
203
-
204
- ### 5.1 检查初始构建产物
205
-
206
- ```bash
207
- # 检查 setup 目录中的初始知识库是否存在
208
- ls -la skills/ok-cosmic/setup/ok-cosmic-knowledge.db
209
-
210
- # 检查数据库大小(应大于 0)
211
- du -h skills/ok-cosmic/setup/ok-cosmic-knowledge.db
212
- ```
213
-
214
- ### 5.2 检查项目最终知识库(推荐做法)
215
-
216
- 如果您在后续步骤中采用“项目根目录维护知识库”的方式,请改为检查项目根目录中的 `ok-cosmic-knowledge.db`:
217
-
218
- ```bash
219
- ls -la ./ok-cosmic-knowledge.db
220
- du -h ./ok-cosmic-knowledge.db
221
- ```
222
-
223
- ### 5.3 验证知识库
224
-
225
- 构建完成后,在项目根目录验证知识库是否正常(假设已按步骤 6 将知识库和配置文件放到项目根目录):
226
-
227
- ```bash
228
- # 测试 API 知识搜索
229
- python3 skills/ok-cosmic/scripts/cosmic-api-knowledge.py --config ok-cosmic.json search QueryServiceHelper
230
-
231
- # 测试元数据查询(需要配置 route.apiUrl)
232
- python3 skills/ok-cosmic/scripts/cosmic-form-metadata.py --config ok-cosmic.json get 物料
233
-
234
- # 测试基础资料查询(需要配置 route.apiUrl;entityId 必须是已确认来源的准确英文标识,不确定时先用元数据脚本查 refType 或按中文名称查英文标识)
235
- python3 skills/ok-cosmic/scripts/cosmic-basedata-query.py --config ok-cosmic.json get --entity-id bd_material --number-or-name 01.0001
236
-
237
- # 测试业务拓展点查询(需要配置 route.apiUrl;生成代码/查看 Java 示例时再加 --full,示例缺失或签名不确定时再用 cosmic-api-knowledge.py detail)
238
- python3 skills/ok-cosmic/scripts/cosmic-extpoints-query.py --config ok-cosmic.json get --keyword 应付
239
- ```
240
-
241
- ---
242
-
243
- ## 6. 项目配置
244
-
245
- 在您的苍穹开发项目根目录创建 `ok-cosmic.json` 配置文件:
246
-
247
- > 建议(适配本地多项目开发):
248
- > 将 `ok-cosmic-knowledge.db` 复制或移动到**当前项目根目录**,再让 `ok-cosmic.json` 的 `graph.dbPath` 直接指向该数据库文件。
249
- > 这样每个项目都可以维护自己的知识库副本,避免多个本地项目共享同一份数据库时相互干扰。
250
-
251
- ```json
252
- {
253
- "graph": {
254
- "dbPath": "/path/to/your-current-project/ok-cosmic-knowledge.db"
255
- },
256
- "route": {
257
- "apiUrl": "https://deverp.xxxx.com/ierp/kapi/v2/xxxx/xxxx_devportal_ext/runtime/route?openApiSign=YOUR_SIGN_HERE",
258
- "timeoutSeconds": 30
259
- },
260
- "extensionRepos": [
261
- "/path/to/your-extension-project-1",
262
- "/path/to/your-extension-project-2"
263
- ]
264
- }
265
- ```
266
-
267
- 例如,将知识库复制到项目根目录后,参照上方模板创建 `ok-cosmic.json`:
268
-
269
- ```bash
270
- cp /Users/yourname/kingdee/code/cosmic-skill/ok-cosmic-knowledge/ok-cosmic-knowledge.db /path/to/your-current-project/
271
- ```
272
-
273
- ### 配置说明
274
-
275
- | 配置项 | 说明 | 默认值 | 是否必填 |
276
- |--------|------|--------|----------|
277
- | `graph.dbPath` | 知识库数据库全路径 | 无 | 是 |
278
- | `route.apiUrl` | 统一路由 API 服务地址(`runtime/route`) | 空(离线模式) | 在线查询时必填 |
279
- | `route.timeoutSeconds` | 统一路由 API 超时时间 | 10 | 否 |
280
- | `extensionRepos` | 扩展代码库路径数组(fallback 参考源) | `[]` | 否 |
281
-
282
- ### 6.1 扩展代码库回落机制(`extensionRepos`)
283
-
284
- 当内置的决策矩阵、`rules/cheat-sheet.md` 和 `assets/snippets/` 均无法覆盖当前需求时,Skill 会按需到 `extensionRepos` 配置的路径下搜索您自己的拓展实现作为参考。
285
-
286
- - **使用场景**(需同时成立):
287
- - Skill 内置的决策矩阵、`rules/cheat-sheet.md` 和 `assets/snippets/` 均无法覆盖当前需求;
288
- - 且 **当前项目中没有具体实现可以满足需求**(在用户项目搜相似插件/业务无果,或现有实现与需求不匹配)。
289
- 此时可以回落到 `extensionRepos` 配置的拓展仓库寻找实现参考。
290
- - **配置方式**:在 `ok-cosmic.json` 中新增顶层字段 `extensionRepos`,值为**字符串数组**,每项为拓展仓库的绝对路径(支持 `~` 展开):
291
-
292
- ```json
293
- {
294
- "extensionRepos": [
295
- "/Users/yourname/kingdee/code/your-extension-project-1",
296
- "~/kingdee/code/your-extension-project-2"
297
- ]
298
- }
299
- ```
300
-
301
- - **数量**:支持 1 个或多个;不配置或给空数组时回落机制不触发,不影响其他功能。
302
- - **生效时机**:仅在内置资产全部 miss **且** 当前项目也无可用实现时才触发。只做 **实现参考**,**不等同于 ok-cosmic 推荐写法**;若与 ok-cosmic A/B 层规范冲突,以 ok-cosmic 规范为准。
303
- - **预检输出**:Step 0 `cosmic-config-check.py` 会逐个校验路径:
304
- - 路径合法且目录存在 → `[OK] extensionRepos[i]: 扩展代码库: /xxx`
305
- - 路径不存在或非目录 → `[WARNING]`(不阻断,仅提示)
306
- - 类型非数组或元素为空字符串 → `[ERROR]`(需修正后再继续)
307
-
308
- 更详细的触发条件和结果使用原则见 `SKILL.md` 的“扩展代码库探索(Extension Repos Fallback)”章节。
309
-
310
- 创建完成后,建议先执行一次 Step 0 预检:
311
-
312
- ```bash
313
- python3 skills/ok-cosmic/scripts/cosmic-config-check.py --config ok-cosmic.json
314
- ```
315
-
316
- 该命令会检查:
317
- - 配置文件是否存在
318
- - JSON 是否合法
319
- - `graph.dbPath` 等关键字段是否缺失
320
- - `route.apiUrl` 未配置时给出在线查询能力受限提示
321
- - `extensionRepos` 路径是否存在且是目录
322
-
323
- ## 7. 安装 Skill
324
-
325
- 如果您当前的目标只是让多个 Agent 共用同一份本地 Skill,可以直接从本步骤开始。
326
-
327
- 建议在本机只维护一份 `ok-cosmic` skill 源目录,然后让不同 Agent 的 skill 安装目录通过软链接(或目录联接)指向它。这样后续你只需要更新一处,多个 Agent 都能同步生效。
328
-
329
- ### 7.1 推荐目录结构
330
-
331
- ```text
332
- /Users/yourname/skills/ok-cosmic # 唯一维护的 skill 源目录
333
- ~/.claude/skills/ok-cosmic # 指向上面的软链接
334
- ~/.opencode/skills/ok-cosmic # 指向上面的软链接
335
- ~/.codex/skills/ok-cosmic # 指向上面的软链接
336
- ~/.gemini/antigravity/skills/ok-cosmic # 指向上面的软链接
337
- ```
338
-
339
- ### 7.2 macOS / Linux
340
-
341
- 1. 准备统一维护目录
342
-
343
- ```bash
344
- mkdir -p ~/skills
345
- cp -R /path/to/ok-cosmic ~/skills/ok-cosmic
346
- ```
347
-
348
- 2. 为不同 Agent 创建软链接
349
-
350
- ```bash
351
- mkdir -p ~/.claude/skills ~/.opencode/skills ~/.codex/skills ~/.gemini/antigravity/skills
352
- ln -sfn ~/skills/ok-cosmic ~/.claude/skills/ok-cosmic
353
- ln -sfn ~/skills/ok-cosmic ~/.opencode/skills/ok-cosmic
354
- ln -sfn ~/skills/ok-cosmic ~/.codex/skills/ok-cosmic
355
- ln -sfn ~/skills/ok-cosmic ~/.gemini/antigravity/skills/ok-cosmic
356
- ```
357
-
358
- ### 7.3 Windows
359
-
360
- 1. 准备统一维护目录
361
-
362
- ```powershell
363
- mkdir $env:USERPROFILE\skills -ErrorAction SilentlyContinue
364
- Copy-Item -Path D:\path\to\ok-cosmic -Destination $env:USERPROFILE\skills\ok-cosmic -Recurse
365
- ```
366
-
367
- 2. 为不同 Agent 创建目录联接(推荐管理员 PowerShell)
368
-
369
- ```powershell
370
- mkdir $env:USERPROFILE\.claude\skills -ErrorAction SilentlyContinue
371
- mkdir $env:USERPROFILE\.opencode\skills -ErrorAction SilentlyContinue
372
- mkdir $env:USERPROFILE\.codex\skills -ErrorAction SilentlyContinue
373
-
374
- cmd /c mklink /J "$env:USERPROFILE\.claude\skills\ok-cosmic" "$env:USERPROFILE\skills\ok-cosmic"
375
- cmd /c mklink /J "$env:USERPROFILE\.opencode\skills\ok-cosmic" "$env:USERPROFILE\skills\ok-cosmic"
376
- cmd /c mklink /J "$env:USERPROFILE\.codex\skills\ok-cosmic" "$env:USERPROFILE\skills\ok-cosmic"
377
- ```
378
-
379
- ### 7.4 维护建议
380
-
381
- - 平时只修改统一维护目录中的 skill 源文件
382
- - 如果某个 Agent 已经存在旧目录,先删除旧目录,再创建软链接
383
- - 更新后若 Agent 有缓存,重启对应 Agent 进程或刷新技能列表
384
-
385
- ---
386
-
387
- ## 8. 加载 Skill 开始编程
388
-
389
- 在您的苍穹开发项目中,通过 Agent 加载 ok-cosmic Skill,即可开始 AI 辅助编程。
390
-
391
- ### 8.1 加载 Skill
392
-
393
- 在项目根目录下,告诉 Agent 加载技能:
394
-
395
- ```
396
- 加载 ok-cosmic 技能
397
- ```
398
-
399
- 或者直接提出开发需求,Agent 会自动识别并加载相关技能:
400
-
401
- ```
402
- 帮我开发一个销售订单的表单插件,实现字段联动校验
403
- ```
404
-
405
- ### 8.2 开始编程之旅
406
-
407
- Skill 加载后,您可以:
408
-
409
- | 场景 | 示例指令 |
410
- |------|-----------------------------|
411
- | 表单插件开发 | "帮我写一个表单插件,实现字段联动" |
412
- | 操作插件开发 | "开发一个审核操作插件,保存前校验数据" |
413
- | BOTP 转换开发 | "实现销售订单到出库单的下推转换" |
414
- | API 查询 | "查询 QueryServiceHelper 的用法" |
415
- | 元数据查询 | "获取物料表单的字段列表(ai生成时会一般自动触发)" |
416
- | 基础资料查询 | "查询 bd_material 中编码 01.0001 对应的基础资料" |
417
-
418
- ---
419
-
420
- ## 🛠️ 常见问题排查
421
-
422
- ### Q1: Java 版本不兼容
423
-
424
- **错误信息:** `Unsupported major.minor version`
425
-
426
- **解决方案:** 升级 Java 到 JDK 8 或更高版本
427
-
428
- ### Q2: 知识库搜索无结果
429
-
430
- **可能原因:**
431
- 1. 数据库路径配置错误
432
- 2. 知识库构建失败或数据为空
433
- 3. 搜索关键词过于精确
434
-
435
- **排查步骤:**
436
- ```bash
437
- # 检查配置文件路径
438
- cat ok-cosmic.json
439
-
440
- # 检查数据库文件大小
441
- ls -la skills/ok-cosmic/setup/ok-cosmic-knowledge.db
442
-
443
- # 尝试更宽泛的搜索
444
- python3 skills/ok-cosmic/scripts/cosmic-api-knowledge.py --config ok-cosmic.json search Helper --kind helper
445
- ```
446
-
447
- ### Q3: 元数据查询超时
448
-
449
- **解决方案:**
450
- 1. 增加 `route.timeoutSeconds` 配置值
451
- 2. 检查网络连接是否正常
452
- 3. 确认 `route.apiUrl` 配置为 OpenAPI 中的 `runtime/route` 地址
453
-
454
- ### Q4: 基础资料查询失败或超时
455
-
456
- **解决方案:**
457
- 1. 确认 `route.apiUrl` 已配置为 OpenAPI 中的 `runtime/route` 地址
458
- 2. 检查统一路由接口是否支持 `data.type=basedata`
459
- 3. 增加 `route.timeoutSeconds` 配置值
460
- 4. 若 `entityId` 不确定,先用元数据脚本查真实标识:可以查字段 `refType`,也可以按基础资料中文名称查英文标识;禁止按中文名称或经验猜测基础资料标识
@@ -1,2 +0,0 @@
1
- tree-sitter>=0.23.0
2
- tree-sitter-java>=0.23.0
@@ -1,204 +0,0 @@
1
- #!/usr/bin/env python3
2
- # SPDX-License-Identifier: NOASSERTION
3
- """
4
- config_loader.py — Shared configuration loader for ok-cosmic scripts.
5
-
6
- Provides shared helpers to:
7
- 1. Locate and parse ``ok-cosmic.json``
8
- 2. Validate Step 0 required content
9
- 3. Inject resolved config path metadata for downstream scripts
10
- """
11
-
12
- import json
13
- import os
14
- import sys
15
- from pathlib import Path
16
- from typing import Any, Dict, List, Optional, Tuple
17
-
18
- # Windows console encoding fix (shared by all scripts)
19
- if os.name == "nt":
20
- try:
21
- sys.stdout.reconfigure(encoding="utf-8")
22
- sys.stderr.reconfigure(encoding="utf-8")
23
- except Exception:
24
- pass
25
-
26
-
27
- Issue = Dict[str, str]
28
-
29
-
30
- def resolve_project_config_path(config_path: Optional[str] = None) -> Path:
31
- """Resolve ``ok-cosmic.json`` path from CLI input or current working directory."""
32
- return Path(config_path).expanduser() if config_path else Path.cwd() / "ok-cosmic.json"
33
-
34
-
35
- def read_project_config(config_path: Optional[str] = None) -> Tuple[Path, Dict[str, Any]]:
36
- """
37
- Read and parse ``ok-cosmic.json`` without mutating the payload.
38
-
39
- Returns:
40
- - resolved absolute config path
41
- - raw JSON object as dict
42
- """
43
- target_path = resolve_project_config_path(config_path)
44
-
45
- if not target_path.is_file():
46
- raise FileNotFoundError(
47
- f"找不到配置文件: {target_path}。请确保文件存在或通过 --config 参数指定正确路径。"
48
- )
49
-
50
- try:
51
- with target_path.open("r", encoding="utf-8") as f:
52
- data = json.load(f)
53
- except FileNotFoundError:
54
- raise
55
- except json.JSONDecodeError as e:
56
- raise RuntimeError(
57
- f"加载配置文件 {target_path} 失败: JSON 解析错误,第 {e.lineno} 行第 {e.colno} 列: {e.msg}"
58
- ) from e
59
- except Exception as e:
60
- raise RuntimeError(f"加载配置文件 {target_path} 失败: {e}") from e
61
-
62
- if not isinstance(data, dict):
63
- raise ValueError(f"配置文件格式错误: {target_path} 必须包含有效的 JSON 对象")
64
-
65
- return target_path.resolve(), data
66
-
67
-
68
- def _add_issue(issues: List[Issue], level: str, key: str, message: str) -> None:
69
- issues.append({"level": level, "key": key, "message": message})
70
-
71
-
72
- def _is_positive_number(value: Any) -> bool:
73
- try:
74
- return float(value) > 0
75
- except (TypeError, ValueError):
76
- return False
77
-
78
-
79
- def _resolve_child_path(base_dir: Path, raw_path: str) -> Path:
80
- expanded = Path(os.path.expanduser(raw_path))
81
- if expanded.is_absolute():
82
- return expanded.resolve()
83
- return (base_dir / expanded).resolve()
84
-
85
-
86
- def validate_project_config(config: Dict[str, Any], config_path: Optional[str] = None) -> List[Issue]:
87
- """
88
- Validate ``ok-cosmic.json`` content for Step 0 preflight.
89
-
90
- Validation levels:
91
- - ERROR: should stop before running skill scripts
92
- - WARNING: non-blocking but means some capabilities are unavailable
93
- """
94
- issues: List[Issue] = []
95
- raw_config_path = config_path or str(config.get("__config_path__", "")).strip()
96
- base_dir = (
97
- Path(raw_config_path).expanduser().resolve().parent
98
- if raw_config_path
99
- else Path.cwd()
100
- )
101
-
102
- graph_config = config.get("graph")
103
- if graph_config is None:
104
- _add_issue(issues, "ERROR", "graph", "缺少 `graph` 配置对象。")
105
- elif not isinstance(graph_config, dict):
106
- _add_issue(issues, "ERROR", "graph", "`graph` 必须是 JSON 对象。")
107
- else:
108
- db_path = str(graph_config.get("dbPath", "")).strip()
109
- if not db_path:
110
- _add_issue(issues, "ERROR", "graph.dbPath", "缺少必填项 `graph.dbPath`。")
111
- else:
112
- resolved_db_path = _resolve_child_path(base_dir, db_path)
113
- if not resolved_db_path.exists():
114
- _add_issue(
115
- issues,
116
- "WARNING",
117
- "graph.dbPath",
118
- f"`graph.dbPath` 指向的文件不存在: {resolved_db_path}",
119
- )
120
-
121
- route_env_available = bool(os.getenv("COSMIC_ROUTE_API") or os.getenv("COSMIC_RUNTIME_ROUTE_API"))
122
- route_config = config.get("route")
123
- route_api_url = ""
124
- if route_config is not None:
125
- if not isinstance(route_config, dict):
126
- _add_issue(issues, "ERROR", "route", "`route` 必须是 JSON 对象。")
127
- else:
128
- route_api_url = str(route_config.get("apiUrl", "")).strip()
129
- if not route_api_url and not route_env_available:
130
- _add_issue(
131
- issues,
132
- "WARNING",
133
- "route.apiUrl",
134
- "`route.apiUrl` 为空,统一路由在线查询将不可用。",
135
- )
136
- if "timeoutSeconds" in route_config and not _is_positive_number(route_config.get("timeoutSeconds")):
137
- _add_issue(
138
- issues,
139
- "ERROR",
140
- "route.timeoutSeconds",
141
- "`route.timeoutSeconds` 必须是大于 0 的数字。",
142
- )
143
- if "openApiSign" in route_config and not isinstance(route_config.get("openApiSign"), str):
144
- _add_issue(
145
- issues,
146
- "ERROR",
147
- "route.openApiSign",
148
- "`route.openApiSign` 必须是字符串。",
149
- )
150
-
151
- if route_config is None and not route_env_available:
152
- _add_issue(
153
- issues,
154
- "WARNING",
155
- "route",
156
- "缺少 `route` 配置节,三个在线查询脚本将无法通过统一路由查询。",
157
- )
158
-
159
- extension_repos = config.get("extensionRepos")
160
- if extension_repos is not None:
161
- if not isinstance(extension_repos, list):
162
- _add_issue(issues, "ERROR", "extensionRepos", "`extensionRepos` 必须是字符串数组。")
163
- else:
164
- for idx, raw_path in enumerate(extension_repos):
165
- key = f"extensionRepos[{idx}]"
166
- if not isinstance(raw_path, str) or not raw_path.strip():
167
- _add_issue(
168
- issues,
169
- "ERROR",
170
- key,
171
- f"`{key}` 必须是非空字符串路径。",
172
- )
173
- continue
174
- resolved_repo = _resolve_child_path(base_dir, raw_path.strip())
175
- if not resolved_repo.is_dir():
176
- _add_issue(
177
- issues,
178
- "WARNING",
179
- key,
180
- f"扩展代码库路径不存在或不是目录: {resolved_repo}",
181
- )
182
- else:
183
- _add_issue(
184
- issues,
185
- "OK",
186
- key,
187
- f"扩展代码库: {resolved_repo}",
188
- )
189
-
190
- return issues
191
-
192
-
193
- def load_project_config(config_path: Optional[str] = None) -> Dict[str, Any]:
194
- """
195
- Load project-level config from provided path or current working directory.
196
-
197
- Returns a dict with two injected keys for downstream consumers:
198
- - ``__config_path__``: absolute path to the resolved config file
199
- - ``__config_dir__``: absolute path to the parent directory of the config file
200
- """
201
- resolved, data = read_project_config(config_path)
202
- data.setdefault("__config_path__", str(resolved))
203
- data.setdefault("__config_dir__", str(resolved.parent))
204
- return data