@dazitech/cli 3.0.8 → 3.0.9

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 (75) hide show
  1. package/README.md +1 -1
  2. package/dist/clis/dazi-app.js +1 -1
  3. package/dist/clis/dazi-flow.js +1 -1
  4. package/dist/clis/dazi-onto.js +1 -1
  5. package/dist/clis/dazi.js +1 -1
  6. package/dist/docs/flow/flow-project-guide.md +1 -1
  7. package/dist/docs/guides/troubleshooting.md +12 -1
  8. package/dist/docs/index.json +20 -1
  9. package/dist/docs/onto/dazi_script_sdk_reference.md +78 -12
  10. package/dist/docs/onto/function-guide.md +61 -33
  11. package/dist/docs/onto//346/234/254/344/275/223/345/210/206/347/261/273/350/247/204/345/210/222/344/270/216SDK/346/211/251/345/261/225/346/226/271/346/241/210.md +168 -0
  12. package/dist/docs/onto//346/234/254/344/275/223/345/221/275/345/220/215/350/247/204/350/214/203_/347/211/251/347/220/206/350/241/250Cube/344/270/216/345/257/271/350/261/241.md +402 -0
  13. package/dist/docs/onto//346/234/254/344/275/223/350/204/232/346/234/254/347/274/226/345/206/231/346/214/207/345/215/227.md +63 -1
  14. package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +123 -15
  15. package/dist/docs/onto//350/204/232/346/234/254/350/277/220/350/241/214/347/272/240/351/224/231_/345/225/206/345/212/241/346/210/220/346/234/254/346/226/271/346/241/210/345/274/200/345/217/221/350/277/207/347/250/213.md +213 -0
  16. package/dist/docs/onto//350/247/204/345/210/222/347/244/272/344/276/213_/344/272/247/345/223/201/351/224/200/345/224/256/346/234/254/344/275/223/350/247/204/345/210/222/346/226/271/346/241/210.md +356 -233
  17. package/dist/docs/onto//350/247/204/345/210/222/347/244/272/344/276/213_/345/210/251/346/266/246/345/210/206/346/236/220/346/234/254/344/275/223/346/226/271/346/241/210.md +379 -296
  18. package/dist/examples/index.json +23 -17
  19. package/dist/examples/onto/README.md +13 -5
  20. package/dist/examples/onto/_templates/ontology_function_template.py +50 -0
  21. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_account_breakdown.py +62 -0
  22. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_budget_vs_actual.py +69 -0
  23. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_cost_center_profit.py +64 -0
  24. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_get_summary.py +61 -0
  25. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_mom_analysis.py +82 -0
  26. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_top_accounts.py +61 -0
  27. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_yoy_analysis.py +79 -0
  28. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -0
  29. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.account_breakdown.json +1 -0
  30. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.budget_vs_actual.json +1 -0
  31. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.cost_center_profit.json +1 -0
  32. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.get_summary.json +1 -0
  33. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.mom_analysis.json +1 -0
  34. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.top_accounts.json +1 -0
  35. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.yoy_analysis.json +1 -0
  36. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +232 -74
  37. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +16 -13
  38. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +19 -16
  39. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +48 -50
  40. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +3 -6
  41. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +11 -12
  42. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +6 -7
  43. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +5 -8
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +3 -6
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +32 -19
  46. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +3 -6
  47. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +2 -7
  48. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +2 -5
  49. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +2 -5
  50. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +2 -5
  51. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +2 -7
  52. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +2 -5
  53. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +291 -155
  54. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +59 -20
  55. package/dist/prompts/index.json +1 -1
  56. package/dist/prompts/onto/function-design.md +42 -22
  57. package/dist/prompts/onto/script-publish-run.md +15 -1
  58. package/package.json +1 -1
  59. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +0 -99
  60. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_budget_vs_actual.py +0 -116
  61. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_cost_center_profit.py +0 -85
  62. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +0 -76
  63. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +0 -86
  64. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +0 -103
  65. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +0 -86
  66. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +0 -27
  67. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.account_breakdown.json +0 -10
  68. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.budget_vs_actual.json +0 -10
  69. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.cost_center_profit.json +0 -9
  70. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.get_summary.json +0 -9
  71. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.mom_analysis.json +0 -9
  72. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.top_accounts.json +0 -11
  73. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.yoy_analysis.json +0 -9
  74. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +0 -25
  75. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +0 -5
package/README.md CHANGED
@@ -78,7 +78,7 @@ pnpm run publish:cli
78
78
 
79
79
  ```powershell
80
80
  # 全局
81
- pnpm add -g @dazitech/cli@3.0.8
81
+ pnpm add -g @dazitech/cli@3.0.9
82
82
 
83
83
  # 确认 PATH(pnpm 全局 bin)
84
84
  pnpm bin -g
@@ -13077,7 +13077,7 @@ var {
13077
13077
  } = import_index.default;
13078
13078
 
13079
13079
  // cli/shared/src/version.ts
13080
- var DAZI_VERSION = true ? "3.0.8" : readDevVersion();
13080
+ var DAZI_VERSION = true ? "3.0.9" : readDevVersion();
13081
13081
 
13082
13082
  // cli/dazi-app/src/lib/httpClient.ts
13083
13083
  init_config();
@@ -4982,7 +4982,7 @@ function resolveWorkspace(cwd = process.cwd()) {
4982
4982
  }
4983
4983
 
4984
4984
  // cli/shared/src/version.ts
4985
- var DAZI_VERSION = true ? "3.0.8" : readDevVersion();
4985
+ var DAZI_VERSION = true ? "3.0.9" : readDevVersion();
4986
4986
 
4987
4987
  // cli/dazi-flow/src/commands/flows.ts
4988
4988
  var import_path3 = __toESM(require("path"), 1);
@@ -3216,7 +3216,7 @@ function resolveWorkspace(cwd = process.cwd()) {
3216
3216
  }
3217
3217
 
3218
3218
  // cli/shared/src/version.ts
3219
- var DAZI_VERSION = true ? "3.0.8" : readDevVersion();
3219
+ var DAZI_VERSION = true ? "3.0.9" : readDevVersion();
3220
3220
 
3221
3221
  // cli/shared/src/ontoWorkspaceAudit.ts
3222
3222
  function ontoItemSubdirForScriptType(scriptType) {
package/dist/clis/dazi.js CHANGED
@@ -3852,7 +3852,7 @@ function resolveWorkspace(cwd = process.cwd()) {
3852
3852
  }
3853
3853
 
3854
3854
  // cli/shared/src/version.ts
3855
- var DAZI_VERSION = true ? "3.0.8" : readDevVersion();
3855
+ var DAZI_VERSION = true ? "3.0.9" : readDevVersion();
3856
3856
 
3857
3857
  // cli/shared/src/ontoWorkspaceAudit.ts
3858
3858
  var import_fs3 = __toESM(require("fs"), 1);
@@ -1,7 +1,7 @@
1
1
  # 数据流程项目开发指南
2
2
 
3
3
  **文档 ID**: `flow/flow-project-guide`
4
- **适用**: `dazi-vscode` v3.0.7+、`dazi-work` 工作区、业务项目 `项目/<业务名>/`
4
+ **适用**: `dazi-vscode` v3.0.9+、`dazi-work` 工作区、业务项目 `项目/<业务名>/`
5
5
 
6
6
  ---
7
7
 
@@ -84,7 +84,7 @@ dazi doctor --workspace-root D:\path\to\dazi-work
84
84
  检查 `.cursor/mcp.json` 配置。MCP 需能调用 bundled CLI,示例:
85
85
 
86
86
  ```powershell
87
- $env:DAZI_BUNDLED_DIR = "$env:USERPROFILE\.cursor\extensions\dazitech.dazi-vscode-3.0.7\bundled\clis"
87
+ $env:DAZI_BUNDLED_DIR = "$env:USERPROFILE\.cursor\extensions\dazitech.dazi-vscode-3.0.9\bundled\clis"
88
88
  node "$env:DAZI_BUNDLED_DIR\dazi.js" mcp stdio
89
89
  ```
90
90
 
@@ -99,3 +99,14 @@ pnpm run dazi-app -- --version
99
99
  ```
100
100
 
101
101
  应用 CLI 由 bundled + 启动器提供,**不需要** monorepo 源码。
102
+
103
+ ## 本体脚本:发布 / 运行 / test_arguments
104
+
105
+ | 现象 | 原因 | 处理 |
106
+ | ---- | ---- | ---- |
107
+ | init 报 `sync_metrics` / `cubes` 不存在 | API 误用 | 见 [脚本运行纠错](../onto/脚本运行纠错_商务成本方案开发过程.md) §1 |
108
+ | 函数聚合 SQL 报 `float` 无 `.get()` | `query_one` 用于多列聚合 | 改用 `query()` 取 `rows[0]`,见纠错文档 §2 |
109
+ | `function run --arguments-json-file` unknown | 该子命令不支持此参数 | 先 `save-test-arguments`,再 `function run <function_id>` |
110
+ | `save-test-arguments` 404 | 传了 `function_id` 而非 `ofn_xxx` | `dazi onto function list` 取内部 `id` |
111
+
112
+ 完整 CLI 清单与商务成本方案实录:`dazi docs show onto/script-run-troubleshooting`(`dazi docs sync` 后位于 `资源/docs/onto/`)。
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "3.0.9",
3
- "updatedAt": "2026-06-05T12:00:00.000Z",
3
+ "updatedAt": "2026-06-06T12:00:00.000Z",
4
4
  "docs": [
5
5
  {
6
6
  "id": "guides/quickstart",
@@ -86,6 +86,18 @@
86
86
  "category": "onto",
87
87
  "file": "onto/本体规划指南.md"
88
88
  },
89
+ {
90
+ "id": "onto/naming-conventions",
91
+ "title": "本体命名规范(物理表 · Cube · 对象)",
92
+ "category": "onto",
93
+ "file": "onto/本体命名规范_物理表Cube与对象.md"
94
+ },
95
+ {
96
+ "id": "onto/category-taxonomy-sdk",
97
+ "title": "349 · 本体分类规划与 SDK 扩展方案",
98
+ "category": "onto",
99
+ "file": "onto/本体分类规划与SDK扩展方案.md"
100
+ },
89
101
  {
90
102
  "id": "onto/planning-example-profit",
91
103
  "title": "规划示例:利润分析本体(GL 域)",
@@ -116,6 +128,13 @@
116
128
  "category": "onto",
117
129
  "file": "onto/dazi_script_seed_data_guide.md"
118
130
  },
131
+ {
132
+ "id": "onto/script-run-troubleshooting",
133
+ "title": "【必读】脚本运行纠错(商务成本实录)",
134
+ "category": "onto",
135
+ "file": "onto/脚本运行纠错_商务成本方案开发过程.md",
136
+ "featured": true
137
+ },
119
138
  {
120
139
  "id": "flow/local-files-spec",
121
140
  "title": "流程本地文件规范与示例",
@@ -3,7 +3,8 @@
3
3
  **文档 ID**: `onto/dazi-script-sdk-reference`
4
4
  **适用**: dazi-vscode v3 + 搭子平台 DaziScript(ClickHouse 数据空间)
5
5
 
6
- > 给 LLM 与开发者提供精简、可执行的 SDK 规范。脚本目录、类型与 **`dazi onto script publish`** 等见 **[本体脚本编写指南](./本体脚本编写指南.md)**。
6
+ > 给 LLM 与开发者提供精简、可执行的 SDK 规范。脚本目录、类型与 **`dazi onto script publish`** 等见 **[本体脚本编写指南](./本体脚本编写指南.md)**。
7
+ > **执行脚本前必读(强制)**:[脚本运行纠错](./脚本运行纠错_商务成本方案开发过程.md)。
7
8
 
8
9
  ## 1. 工作区与脚本放置(dazi-vscode)
9
10
 
@@ -102,6 +103,24 @@
102
103
  - `s.sql.query(sql)` / `s.sql.query_one(sql)` / `s.sql.execute(sql)`
103
104
  - `s.sql.insert_rows(table, rows)`(`rows` 为 `list[dict]`)
104
105
 
106
+ **`query_one` 与多列聚合**
107
+
108
+ - `query_one` 适合 `SELECT count()` 等**单列标量**;对 `SELECT sum(a), count(b) ...` 等多列聚合,**勿**对返回值调用 `.get()`(可能得到 float 而非 dict)。
109
+ - **推荐**:`rows = s.sql.query(sql); row = rows[0] if rows else {}`(函数脚本内为 `p.sql.query`)。详见 [脚本运行纠错](./脚本运行纠错_商务成本方案开发过程.md#2-函数聚合查询返回类型错误)。
110
+
111
+ ### 5.2.1 本体函数输出(`ontology_function`)
112
+
113
+ 与 setup/seed 不同,本体函数运行时平台注入 `ctx`、`space`、`onto`:
114
+
115
+ | 要点 | 说明 |
116
+ | ---- | ---- |
117
+ | 入口 | `def main():`(**无** `params` 形参) |
118
+ | 入参 | `ctx.params` → `p.get_params()` |
119
+ | 出参 | **`return p.function_result(columns=..., data=..., row_count=...)`** |
120
+ | 禁止 | `output.print_json()`(`OutputModule` 无此方法)、裸 `return {"k": v}` |
121
+
122
+ 标准模板:`资源/examples/onto/_templates/ontology_function_template.py`。详见 [function-guide](./function-guide.md#函数脚本结构标准模板)、[脚本运行纠错 §3](./脚本运行纠错_商务成本方案开发过程.md#3-函数输出方式错误outputprint_json)。
123
+
105
124
  **ClickHouse:`INSERT ... VALUES` 与注释**
106
125
 
107
126
  - **`VALUES` 与各元组之间禁止 SQL 行注释 `--`**,否则易出现 `Code: 27` 等解析错误。
@@ -109,25 +128,70 @@
109
128
 
110
129
  ### 5.3 `s.tables`
111
130
 
112
- - `s.tables.register(table_name, label=...)`
113
- - `s.tables.sync_columns(table_name)`
131
+ - `s.tables.register(table_name, display_name=..., description=..., label=..., category_347=...)` — `label` 为 `display_name` 简写别名;已注册时可刷新表显示名与说明;`category_347` 为 347 标准中文名(如 `"维度表"`),注册后**即时挂载**平台分类
132
+ - `s.tables.sync_columns(table_name)` — 从物理库同步列;未显式传入元数据时仅**推断** `display_name`(token 词典),**不**写入业务 `description`
133
+ - `s.tables.set_column_meta(table_name, columns=[{name, display_name, description, business_role}], force=False)` — 批量写入列显示名与说明(须先 register + sync_columns)
134
+ - `s.tables.register_with_meta(table_name, display_name=..., description=..., columns=[...], force_column_meta=False, category_347=...)` — 上三者合一(**推荐** setup 脚本使用)
114
135
  - `s.tables.list()` / `s.tables.discover()`
115
- - `s.tables.add_relationship(from_table, to_table, join_sql, relationship_type="many_to_one", join_keys=None, description=None)` — 注册**数据空间表间关系**(幂等);`join_keys` 示例:`[{"from": "product_id", "to": "product_id"}]`
136
+ - `s.tables.add_relationship(from_table, to_table, join_sql, relationship_type="many_to_one", join_keys=None, description=None, category_347=...)` — 注册**数据空间表间关系**(幂等);`category_347` `"主数据关联"`、`"时间关联"`
116
137
 
117
138
  ### 5.4 Cube
118
139
 
119
- - `s.register_cube(name, table, title, measures, dimensions)`
140
+ - `s.register_cube(name, table, title, measures, dimensions, category_347=...)` — `category_347` 如 `"流程型"`、`"主体型"`
120
141
 
121
142
  ### 5.5 `s.onto`
122
143
 
123
- - `s.onto.define_object_type(code, name, ...)`
144
+ - `s.onto.define_object_type(code, name, ..., category_347=...)` — 如 `category_347="主数据"`
124
145
  - `s.onto.bind_source(object_type_code, "dazi_cube", config={"cube": "CubeName"})`
125
146
  - `s.onto.define_property(...)`
126
- - `s.onto.define_link_type(code, name, from_object_type_code, to_object_type_code, ...)`
127
- - `s.onto.register_function(function_id, adapter, ...)`
147
+ - `s.onto.define_link_type(code, name, from_object_type_code, to_object_type_code, ..., category_347=...)` — 如 `category_347="归属关系"`
148
+ - `s.onto.register_function(function_id, adapter, ..., category_347=...)` — 如 `category_347="总览分析"`
128
149
  - `s.onto.define_action(action_code, ...)`
129
150
 
130
- ### 5.6 `s.ontology` / `s.ontology_rules` / `s.scripts`
151
+ **常见误用**(setup 脚本):不存在 `s.onto.sync_metrics()`、`s.cubes.upsert`;`define_object_type` 第二参数为 `name` 非 `label`;链接类型参数为 `from_object_type_code` / `to_object_type_code`。对照表见 [脚本运行纠错](./脚本运行纠错_商务成本方案开发过程.md#1-setup-脚本-api-误用多次尝试才正确)。
152
+
153
+ ### 5.6 `s.categories`(347 对齐分类)
154
+
155
+ 挂载到 `ads_categories` 默认根下的平级目录,桥表关联表/Cube/对象/关系/链接/函数。分类名必须与 [347 规范](./本体命名规范_物理表Cube与对象.md) 标准中文名一致。详见 [349 方案](./本体分类规划与SDK扩展方案.md)。
156
+
157
+ - `s.categories` — `CategoryManager` 实例(按空间懒加载)
158
+ - `s.categories.ensure_347(kind, category)` — 确保平级分类目录存在(幂等);`kind` 支持 `table` / `cube` / `object` / `relation` / `link` / `function`
159
+ - `s.categories.assign_table(category, table_name)` — 挂载物理表
160
+ - `s.categories.assign_cube(category, cube_name)` — 挂载 Cube
161
+ - `s.categories.assign_object(category, object_type_code)` — 挂载对象类型
162
+ - `s.categories.assign_relation(category, from_table, to_table)` — 挂载表间关系
163
+ - `s.categories.assign_link(category, link_code)` — 挂载链接类型
164
+ - `s.categories.assign_function(category, function_id)` — 挂载本体函数(如 `profit.fn.get_summary`)
165
+ - `s.categories.auto_assign_tables(table_names)` — 按表名前缀自动推断 347 类别并挂载
166
+ - `s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)` — 批量应用 init 顶部注册表
167
+
168
+ **`CATEGORY_REGISTRY` 结构**(与规划附录 B 对齐):
169
+
170
+ ```python
171
+ CATEGORY_REGISTRY = {
172
+ "table": {"维度表": ["dim_account"], "事实表": ["fact_gl_journal_entry"]},
173
+ "cube": {"流程型": ["ActualCube"], "主体型": ["AccountActualCube"]},
174
+ "object": {"主数据": ["Account"], "事务": ["JournalEntry"], "分析": ["ProfitAnalysis"]},
175
+ "relation": {"时间关联": [("fact_x", "dim_date")], "主数据关联": [("fact_x", "dim_y")]},
176
+ "link": {"归属关系": ["entry_belongs_account"], "分析归因": ["analysis_by_account"]},
177
+ "function": {"总览分析": ["profit.fn.get_summary"]}, # 函数未注册时须 skip_missing=True
178
+ }
179
+ ```
180
+
181
+ **两种用法**(可并存,挂载幂等):
182
+
183
+ 1. **批量**(推荐 init 末尾):`s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)`
184
+ 2. **内联**(注册时即时挂载):
185
+
186
+ ```python
187
+ s.tables.register_with_meta("dim_product", display_name="产品维表", category_347="维度表", ...)
188
+ s.register_cube("SalesCube", table=fact, title="...", category_347="流程型", ...)
189
+ s.onto.define_object_type("Product", "产品", category_347="主数据")
190
+ s.tables.add_relationship(..., category_347="主数据关联")
191
+ s.onto.define_link_type("order_contains_product", "...", ..., category_347="归属关系")
192
+ ```
193
+
194
+ ### 5.7 `s.ontology` / `s.ontology_rules` / `s.scripts`
131
195
 
132
196
  见上文;规则:`ensure_rule_set` + `upsert_rule`;脚本记录:`create` / `ensure` / `list` 等。
133
197
 
@@ -135,12 +199,13 @@
135
199
 
136
200
  1. 确认 `space_id`(实现单元 README)
137
201
  2. 建表与灌数(`s.sql`;灌数规范见 seed 指南)
138
- 3. `s.tables.register` + `sync_columns`
202
+ 3. `s.tables.register_with_meta`(`TABLE_REGISTRY` 含表/列 `display_name`、`description`)
139
203
  4. **`s.tables.add_relationship`**(与规划「表间关系」一致;**勿省略**)
140
204
  5. `s.register_cube`
141
205
  6. `s.onto` 定义对象、属性、链接
142
206
  7. 注册函数/动作并 `features.attach`;**发布后** CLI `save-test-arguments` 写入 `test_arguments`(见 [function-guide](./function-guide.md))
143
- 8. 配置规则(如需要)
207
+ 8. `s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)`(347 对齐分类)
208
+ 9. 配置规则(如需要)
144
209
 
145
210
  ## 7. 在 dazi-vscode 中发布与运行
146
211
 
@@ -174,5 +239,6 @@ dazi onto function run my_func --space <space-id> --params '{}'
174
239
 
175
240
  - **规划全文(推荐)**:**`资源/docs/onto/规划示例_产品销售本体规划方案.md`**(含表间关系、test_arguments)
176
241
  - **完整落地参考**(init / seed / 7 个 sales 函数):**`项目/潘达石化/本体/ontos/产品销售本体方案/`**
177
- - **利润示例(GL 域)**:`资源/examples/onto/利润示例/setup/profit_ontology_init.py`、`profit_seed_data.py`、`function/profit_fn_*.py`、`function/test_arguments/`
242
+ - **利润示例(GL 域)**:`资源/examples/onto/利润示例/setup/profit_ontology_init.py`、`profit_seed_data.py`、`functions/profit_fn_*.py`、`functions/test_arguments/`
178
243
  - **销售示例(推荐,含表间关系 + test_arguments)**:`资源/examples/onto/销售示例/setup/sales_ontology_init.py`、`sales_seed_data.py`、`functions/sales_fn_*.py`
244
+ - **脚本运行纠错(实录)**:`资源/docs/onto/脚本运行纠错_商务成本方案开发过程.md` — setup API、`query_one`、CLI test_arguments 踩坑
@@ -2,6 +2,8 @@
2
2
 
3
3
  **文档 ID**: `onto/function-guide`
4
4
 
5
+ > **执行脚本前必读**:[`脚本运行纠错_商务成本方案开发过程.md`](./脚本运行纠错_商务成本方案开发过程.md)(CLI、SQL、`output.print_json` 等常见误用)。
6
+
5
7
  ## 函数生命周期
6
8
 
7
9
  ```
@@ -14,21 +16,13 @@
14
16
 
15
17
  ## 新建函数
16
18
 
17
- ```bash
18
- # 发布新函数(路径指向本体实现单元 functions/ 目录)
19
- dazi onto function publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py \
20
- --space <space-id> \
21
- --function-id my_function \
22
- --display-name "我的函数" \
23
- --entry main
24
- ```
25
-
26
- 或使用 `script publish`(等价,见 [本体脚本编写指南](./本体脚本编写指南.md)):
19
+ **推荐**:复制 `资源/examples/onto/_templates/ontology_function_template.py` 或 `销售示例/functions/sales_fn_*.py`,再改业务逻辑。
27
20
 
28
21
  ```bash
22
+ # 发布新函数(路径指向本体实现单元 functions/ 目录)
29
23
  dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py \
30
24
  --space <space-id> \
31
- --register-function-id my_function
25
+ --register-function-id domain.fn.my_analysis
32
26
  ```
33
27
 
34
28
  `<space-id>` 取自 **`项目/<业务名>/本体/ontos/<实现名>/README.md`**。
@@ -36,7 +30,6 @@ dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/m
36
30
  ## 更新已有函数代码
37
31
 
38
32
  ```bash
39
- # 用工作副本快速更新(不做完整 publish 流程)
40
33
  dazi onto function update-code <function-id> \
41
34
  --space <space-id> \
42
35
  --stem my_func
@@ -52,6 +45,8 @@ dazi onto function run <function-id> \
52
45
  --params '{}'
53
46
  ```
54
47
 
48
+ > **`function run` 不支持 `--arguments-json-file`**。详见 [脚本运行纠错](./脚本运行纠错_商务成本方案开发过程.md#4-cli-参数认知错误)。
49
+
55
50
  PowerShell 下复杂 JSON 建议用环境变量 `DAZI_PARAMS` 或侧栏运行(使用已保存的 `test_arguments`)。详见 [本体脚本编写指南](./本体脚本编写指南.md#函数测试参数test_arguments发布后必做)。
56
51
 
57
52
  ## 保存测试参数(test_arguments)
@@ -61,35 +56,68 @@ PowerShell 下复杂 JSON 建议用环境变量 `DAZI_PARAMS` 或侧栏运行(
61
56
  **本地文件**:`functions/test_arguments/<function_id>.json`(格式见 [本体脚本编写指南](./本体脚本编写指南.md))。
62
57
 
63
58
  ```bash
64
- # 从 JSON 文件保存(推荐)
65
59
  dazi onto function save-test-arguments <ofn_internal_id> \
66
60
  --space <space-id> \
67
61
  --arguments-json-file 项目/<业务名>/本体/ontos/<实现名>/functions/test_arguments/<function_id>.json
68
62
  ```
69
63
 
70
- ```bash
71
- # 或直接传 JSON(简单参数)
72
- dazi onto function save-test-arguments <ofn_internal_id> \
73
- --space <space-id> \
74
- --params '{"v":1,"arguments":{"start_date":"2025-01-01"},"object_type_code":"SalesAnalysis"}'
75
- ```
64
+ > **注意**:须用平台**内部 id** `ofn_xxx`(`dazi onto function list` 返回),不是 `function_id` 字符串。
76
65
 
77
- > **注意**:当前 CLI 的 PATCH 路径使用平台**内部 id**(`ofn_xxx`,由 `dazi onto function list` 返回),**不是** `function_id` 字符串(如 `sales.fn.get_summary` 可能 404)。批量保存可用 `functions/save_test_arguments.ps1`(见本体脚本编写指南)。
66
+ ## 函数脚本结构(标准模板)
78
67
 
79
- 验收:
68
+ 本体函数与 setup/seed 脚本不同:**`main()` 无参**,平台注入 `ctx`、`space`、`onto`;**必须 return** `function_result`,**禁止** `output.print_json()`。
80
69
 
81
- ```bash
82
- dazi onto function get <function-id> --space <space-id>
83
- # 确认 test_arguments.arguments 与 JSON 一致
70
+ ```python
71
+ TEST_ARGUMENTS = {
72
+ "v": 1,
73
+ "arguments": {"start_date": "2025-01-01", "end_date": "2026-06-30"},
74
+ "object_type_code": "SalesAnalysis",
75
+ }
76
+
77
+
78
+ def _ontology_fn_body(p):
79
+ params = dict(p.get_params() or {})
80
+ start_date = params.get("start_date", "")
81
+ end_date = params.get("end_date", "")
82
+
83
+ rows = p.sql.query(f"SELECT sum(amount) AS total FROM fact WHERE date >= '{start_date}'")
84
+ row = rows[0] if rows else {}
85
+ total = float(row.get("total", 0) or 0)
86
+
87
+ return p.function_result(
88
+ columns=["total"],
89
+ data=[{"total": total}],
90
+ row_count=1,
91
+ )
92
+
93
+
94
+ def main():
95
+ s = space.get(ctx.space_id or "")
96
+ _Ports = type(
97
+ "_Ports",
98
+ (),
99
+ {
100
+ "get_params": lambda self: dict(ctx.params or {}),
101
+ "function_result": lambda self, **kw: onto.function_result(**kw),
102
+ },
103
+ )
104
+ p = _Ports()
105
+ p.sql = s.sql
106
+ return _ontology_fn_body(p)
84
107
  ```
85
108
 
86
- ## 函数脚本结构
109
+ | 要点 | 说明 |
110
+ | ---- | ---- |
111
+ | 入口 | **`def main():`**(无 `params` 形参) |
112
+ | 入参 | `ctx.params` → `p.get_params()` |
113
+ | 空间 / SQL | `s = space.get(ctx.space_id)` → `p.sql = s.sql` |
114
+ | 出参 | **`return p.function_result(columns=..., data=..., row_count=...)`** |
115
+ | 禁止 | `output.print_json`、`main(params: dict)`、裸 `return {"k": v}` |
87
116
 
88
- ```python
89
- def main(params: dict) -> dict:
90
- """
91
- 函数入口,params 由平台传入。
92
- 返回值会作为函数输出。
93
- """
94
- return {"result": params.get("value", 0) * 2}
95
- ```
117
+ 可复制模板:`资源/examples/onto/_templates/ontology_function_template.py` · 参考实现:`销售示例/functions/sales_fn_get_summary.py`。
118
+
119
+ ## 相关文档
120
+
121
+ - [脚本运行纠错(商务成本方案实录)](./脚本运行纠错_商务成本方案开发过程.md)
122
+ - [本体脚本编写指南](./本体脚本编写指南.md)
123
+ - [DaziScript SDK 参考](./dazi_script_sdk_reference.md)
@@ -0,0 +1,168 @@
1
+ # 349 · 本体分类规划与 SDK 扩展方案
2
+
3
+ **文档 ID**:`onto/category-taxonomy-sdk`
4
+
5
+ > **文档编号**:349
6
+ > **类型**:规范 + 实施方案(对齐 §347 · `ads_categories` 平台分类)
7
+ > **同步路径**:`dazi docs sync` → `资源/docs/onto/本体分类规划与SDK扩展方案.md`
8
+ > **前置依据**:[本体命名规范 §347](./本体命名规范_物理表Cube与对象.md)、[本体规划指南](./本体规划指南.md)
9
+
10
+ ---
11
+
12
+ ## 1. 目标
13
+
14
+ 将 **347 语义分类**(规划表「类别/分类」列)与 **`ads_categories` 平台分类**(侧栏分组、桥表挂载)打通,支持 init 脚本幂等注册。
15
+
16
+ **约束**:本体规划阶段分类 **全部平级**(挂空间默认根下,不建多层树)。
17
+
18
+ ---
19
+
20
+ ## 2. 两类分类,一套语言
21
+
22
+ | 维度 | 347 语义分类 | ads_categories 平台分类 |
23
+ |------|-------------|------------------------|
24
+ | 作用 | 规划自检、命名约束 | 侧栏展示、资源分组 |
25
+ | 对齐 | 平台 `category_name` **=** 347 标准中文名 | 禁止自定义别名 |
26
+
27
+ ---
28
+
29
+ ## 3. 347 标准分类字典(6 类资源)
30
+
31
+ ### 3.1 物理表(`category_kind=dataspace_table`)
32
+
33
+ | 347 类别 | 前缀 | 平台分类名 |
34
+ |----------|------|------------|
35
+ | 时间维 | `dim_date` | 时间维 |
36
+ | 维度表 | `dim_` | 维度表 |
37
+ | 事实表 | `fact_` | 事实表 |
38
+ | 桥表 | `bridge_` | 桥表 |
39
+ | 映射表 | `map_` | 映射表 |
40
+ | 配置表 | `cfg_` | 配置表 |
41
+ | 汇总表 | `agg_` | 汇总表 |
42
+ | 临时表 | `tmp_` | 临时表 |
43
+
44
+ ### 3.2 Cube(`category_kind=cube`)
45
+
46
+ | 347 类别 | 平台分类名 |
47
+ |----------|------------|
48
+ | Process | 流程型 |
49
+ | Subject | 主体型 |
50
+ | Comparison | 对比型 |
51
+ | Snapshot | 快照型 |
52
+
53
+ > 时间增强不单独建 Cube(347 §4.2),不设平台分类。
54
+
55
+ ### 3.3 本体对象(`category_kind=ontology_object_type`)
56
+
57
+ | 347 分类 | 平台分类名 |
58
+ |----------|------------|
59
+ | Master | 主数据 |
60
+ | Transaction | 事务 |
61
+ | Analytical | 分析 |
62
+ | Reference | 参考 |
63
+ | Configuration | 配置 |
64
+
65
+ ### 3.4 表间关系(`category_kind=relation`,347 扩展)
66
+
67
+ | 关系类别 | 平台分类名 |
68
+ |----------|------------|
69
+ | 时间关联 | 时间关联 |
70
+ | 主数据关联 | 主数据关联 |
71
+ | 层级自关联 | 层级自关联 |
72
+ | 预实关联 | 预实关联 |
73
+ | 桥接关联 | 桥接关联 |
74
+
75
+ ### 3.5 本体链接(`category_kind=ontology_link_type`,347 扩展)
76
+
77
+ | 链接类别 | 平台分类名 |
78
+ |----------|------------|
79
+ | 归属/包含 | 归属关系 |
80
+ | 分析归因 | 分析归因 |
81
+ | 层级/结构 | 层级关系 |
82
+ | 对比/映射 | 对比关系 |
83
+
84
+ ### 3.6 本体函数(`category_kind=ontology_function`,347 扩展)
85
+
86
+ | 函数类别 | 平台分类名 |
87
+ |----------|------------|
88
+ | 总览 | 总览分析 |
89
+ | 趋势 | 趋势分析 |
90
+ | 结构 | 结构分析 |
91
+ | 预实 | 预实分析 |
92
+ | 组织 | 组织分析 |
93
+
94
+ ---
95
+
96
+ ## 4. SDK 设计
97
+
98
+ ### 4.1 模块
99
+
100
+ ```python
101
+ s.categories # CategoryManager
102
+ s.categories.apply_registry(CATEGORY_REGISTRY)
103
+ s.categories.ensure_347(kind="table", category="维度表")
104
+ s.categories.assign_table("维度表", "dim_account")
105
+ s.categories.auto_assign_tables(["dim_account", "fact_gl_journal_entry"])
106
+ ```
107
+
108
+ ### 4.2 init 脚本
109
+
110
+ **方式 A — 批量**(推荐):顶部 `CATEGORY_REGISTRY` 与规划 **附录 B** 对齐;资源注册完成后:
111
+
112
+ ```python
113
+ cat_counts = s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)
114
+ ```
115
+
116
+ **方式 B — 内联**(P2):各注册 API 支持 `category_347=`,注册后即时挂载(与方式 A 幂等可并存):
117
+
118
+ ```python
119
+ s.tables.register_with_meta("dim_product", ..., category_347="维度表")
120
+ s.register_cube("SalesCube", ..., category_347="流程型")
121
+ s.onto.define_object_type("Product", "产品", category_347="主数据")
122
+ s.tables.add_relationship(..., category_347="时间关联")
123
+ s.onto.define_link_type(..., category_347="归属关系")
124
+ s.onto.register_function("sales.fn.get_summary", adapter, category_347="总览分析")
125
+ ```
126
+
127
+ 函数类资源若 init 未 `register_function`,批量方式须 `skip_missing=True`。
128
+
129
+ ---
130
+
131
+ ## 5. 规划与 init 约定
132
+
133
+ | 产出 | 位置 | 说明 |
134
+ | ---- | ---- | ---- |
135
+ | 规划附录 B | `plans/<主题>.md` | 6 类资源分类对照表 |
136
+ | `CATEGORY_REGISTRY` | `setup/*_ontology_init.py` 顶部 | 与附录 B 逐行一致 |
137
+ | 分类步骤 | init 末尾 | `[10/10] apply_registry` |
138
+
139
+ 参考:[规划示例_产品销售](./规划示例_产品销售本体规划方案.md#附录-b347-分类挂载对照表category_registry)、[规划示例_利润分析](./规划示例_利润分析本体方案.md#附录-b347-分类挂载对照表category_registry)。
140
+
141
+ ---
142
+
143
+ ## 6. 验收标准
144
+
145
+ 1. 平台侧栏分类名与 347 标准表一致
146
+ 2. `dim_*` / `fact_*` 自动归入维度表/事实表
147
+ 3. init 重跑幂等,桥表不重复
148
+ 4. `CATEGORY_REGISTRY` 与规划附录 B 逐行一致
149
+
150
+ ---
151
+
152
+ ## 7. 相关文档
153
+
154
+ | 文档 | 路径(`dazi docs sync` 后) |
155
+ | ---- | --------------------------- |
156
+ | 347 命名规范 | `资源/docs/onto/本体命名规范_物理表Cube与对象.md` |
157
+ | 本体规划指南 | `资源/docs/onto/本体规划指南.md` |
158
+ | SDK 参考 §5.6 | `资源/docs/onto/dazi_script_sdk_reference.md` |
159
+ | 脚本编写指南 | `资源/docs/onto/本体脚本编写指南.md` |
160
+
161
+ ---
162
+
163
+ **变更记录**
164
+
165
+ | 日期 | 说明 |
166
+ | ---- | ---- |
167
+ | 2026-06-06 | 首版:对齐 347 分类方案 + SDK 设计 |
168
+ | 2026-06-06 | 改为 `dazi-vscode` 完整可同步正文(客户环境不依赖 `dazi/docs/`) |