@dazitech/cli 3.0.7 → 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 (70) 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 +73 -22
  5. package/dist/clis/dazi.js +266 -171
  6. package/dist/docs/flow/flow-project-guide.md +1 -1
  7. package/dist/docs/guides/quickstart.md +18 -4
  8. package/dist/docs/guides/troubleshooting.md +12 -1
  9. package/dist/docs/guides/workspace-v3.md +43 -23
  10. package/dist/docs/index.json +28 -3
  11. package/dist/docs/onto/action-guide.md +3 -3
  12. package/dist/docs/onto/dazi_script_sdk_reference.md +244 -174
  13. package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
  14. package/dist/docs/onto/function-guide.md +82 -27
  15. package/dist/docs/onto/space-management.md +3 -1
  16. 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
  17. 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
  18. 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 +200 -34
  19. package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +188 -38
  20. 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
  21. 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 +620 -0
  22. 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 +680 -541
  23. package/dist/examples/index.json +208 -22
  24. package/dist/examples/onto/README.md +51 -0
  25. package/dist/examples/onto/_templates/ontology_function_template.py +50 -0
  26. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_account_breakdown.py +62 -0
  27. 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
  28. 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
  29. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_get_summary.py +61 -0
  30. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_mom_analysis.py +82 -0
  31. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_top_accounts.py +61 -0
  32. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_yoy_analysis.py +79 -0
  33. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -0
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +679 -0
  42. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +216 -0
  43. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +89 -0
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +121 -0
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +78 -0
  46. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +89 -0
  47. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +84 -0
  48. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +98 -0
  49. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +87 -0
  50. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -0
  51. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +5 -0
  52. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +5 -0
  53. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +5 -0
  54. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +5 -0
  55. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +5 -0
  56. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +5 -0
  57. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +5 -0
  58. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +539 -0
  59. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +163 -0
  60. package/dist/prompts/index.json +2 -2
  61. package/dist/prompts/onto/action-design.md +4 -1
  62. package/dist/prompts/onto/function-design.md +46 -19
  63. package/dist/prompts/onto/rule-seed.md +5 -1
  64. package/dist/prompts/onto/script-publish-run.md +87 -25
  65. package/package.json +1 -1
  66. package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
  67. package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
  68. package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
  69. package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
  70. package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
@@ -2,36 +2,57 @@
2
2
 
3
3
  **文档 ID**: `onto/script-authoring`
4
4
 
5
- 本文说明本体项目内 **Python 脚本的目录、类型、发布与运行**(原独立的「脚本开发与发布」已与本文合并)。
5
+ 本文说明本体实现单元内 **Python 脚本的目录、类型、发布与运行**(原独立的「脚本开发与发布」已与本文合并)。
6
6
 
7
7
  > 终端命令均在 **`dazi-work` 根目录**执行:`dazi ...`(见 [CLI 调用约定](../guides/cli-invocation.md))。
8
8
 
9
+ ## 执行脚本前必读(强制)
10
+
11
+ 在终端执行 **`dazi onto script publish` / `script run` / `function run` / `save-test-arguments`** 之前,**必须**阅读:
12
+
13
+ | 文档 | 说明 |
14
+ | ---- | ---- |
15
+ | **[脚本运行纠错(商务成本实录)](./脚本运行纠错_商务成本方案开发过程.md)** | setup API 误用、`query_one` 聚合陷阱、**函数禁止 `output.print_json()`**、CLI 参数(`function run` 不支持 JSON 文件、`save-test-arguments` 须 `ofn_xxx`) |
16
+
17
+ `dazi docs show onto/script-run-troubleshooting` · 智能体另见提示词 **`onto/script-publish-run`**。
18
+
9
19
  ## 环境
10
20
 
11
21
  - 推荐 **Python 3.10+**
12
- - 脚本目录:**`<工作区根>/项目/onto_<项目名>/脚本/`**(新建本体项目时自动创建)
22
+ - 脚本目录:**`<工作区根>/项目/<业务名>/本体/ontos/<实现名>/setup/`** 与 **`functions/`**(新建本体实现时自动创建)
13
23
  - 扩展默认脚本语言:`dazi.onto.defaultScriptLang` = `python`
14
24
  - 平台 API:`dazi.serverUrl`;登录:`dazi auth login` / `dazi auth set-token`
15
25
 
16
26
  ## 目录约定
17
27
 
18
28
  ```text
19
- <工作区根>/项目/onto_<项目名>/ 扩展「新建项目」;README 含 space_id
20
- ├── README.md
21
- ├── 快速启动.md
22
- ├── 规划/
23
- └── 脚本/ ← 所有本体 Python 脚本(函数/动作/灌数/初始化)
24
- ├── main.py
25
- └── ...
29
+ <工作区根>/项目/<业务名>/ 业务项目根
30
+ └── 本体/
31
+ └── ontos/<实现名>/ ← 本体实现单元;README 含 space_id
32
+ ├── README.md
33
+ ├── 快速启动_<实现名>.md
34
+ ├── plans/ ← 规划阶段 Markdown 产出
35
+ ├── setup/ ← 初始化、灌数脚本
36
+ └── functions/ ← 本体函数、动作脚本
37
+ ├── test_arguments/ ← 各 function_id 的 test_arguments JSON
38
+ ├── save_test_arguments.ps1 ← 可选:批量写入平台(推荐)
39
+ └── *.py
26
40
  ```
27
41
 
28
- 参考示例(可复制后修改)位于 **`资源/examples/onto/`**(侧栏 **帮助 → 示例** 或 `dazi examples sync`)。
42
+ 参考示例(可复制后修改)位于 **`资源/examples/onto/`**,按 **利润示例**、**销售示例** 两套打包(侧栏 **帮助 → 示例** 或 `dazi examples sync`)。
43
+
44
+ | 示例包 | 目录 | 规划文档 | 主要内容 |
45
+ |--------|------|----------|----------|
46
+ | **销售示例**(推荐) | `onto/销售示例/` | [规划示例_产品销售本体规划方案](./规划示例_产品销售本体规划方案.md) | `setup/sales_ontology_init.py`、`sales_seed_data.py`、7 个 `sales_fn_*.py`、`test_arguments/` |
47
+ | **利润示例**(补充) | `onto/利润示例/` | [规划示例_利润分析本体方案](./规划示例_利润分析本体方案.md) | `setup/profit_ontology_init.py`、`profit_seed_data.py`、7 个 `profit_fn_*.py`、`test_arguments/` |
48
+
49
+ 总览说明:`资源/examples/onto/README.md`(`dazi examples show onto/readme`)。
29
50
 
30
- > **不再使用** 历史路径 `onto/<space_id>/editorial/`、`editorial/functions/` 等作为本地开发约定。
51
+ > **不再使用** 历史路径 `onto/<space_id>/editorial/`、`editorial/functions/`、`项目/onto_<名称>/脚本/` 等作为本地开发约定。
31
52
 
32
53
  ## 必读规范(DaziScript)
33
54
 
34
- 编写 `脚本/` 下 `.py` 前请阅读:
55
+ 编写 `setup/`、`functions/` 下 `.py` 前请阅读:
35
56
 
36
57
  | 文档 | 说明 |
37
58
  | ------------------------------------------------------------------- | ---------------------------------------------------------------------- |
@@ -40,22 +61,98 @@
40
61
 
41
62
  同步到工作区:`dazi docs sync` → `资源/docs/onto/`。
42
63
 
64
+ ## 初始化脚本标准顺序(setup)
65
+
66
+ `*_ontology_init.py` 建议按以下顺序执行(与 [本体规划指南](./本体规划指南.md) 物理层 + 表间关系章节一致):
67
+
68
+ | 步骤 | 内容 | API |
69
+ | ---- | ---- | --- |
70
+ | 1 | 建表 | `s.sql.execute(CREATE TABLE ...)` |
71
+ | 2 | 注册表 | `s.tables.register_with_meta`(含表/列 `display_name`、`description`) |
72
+ | 3 | **注册表间关系** | `s.tables.add_relationship(...)` |
73
+ | 4 | 注册 Cube / 派生度量 | `s.register_cube`、`s.upsert_derived_measures` |
74
+ | 5 | 本体对象 / 属性 / 链接 | `s.onto.define_*`、`s.sync_metric_refs` |
75
+ | 6 | **347 对齐分类** | `s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)` |
76
+
77
+ ### 表间关系 `s.tables.add_relationship`
78
+
79
+ 在 **表 register 完成之后、Cube 注册之前** 调用;**幂等**,可重复执行 init。
80
+
81
+ ```python
82
+ s.tables.add_relationship(
83
+ from_table="sales_order_fact", # 通常为事实表
84
+ to_table="product_master", # 维表
85
+ join_sql="sales_order_fact.product_id = product_master.product_id",
86
+ join_keys=[{"from": "product_id", "to": "product_id"}],
87
+ relationship_type="many_to_one", # 默认 many_to_one
88
+ description="销售订单行关联产品主数据",
89
+ )
90
+ ```
91
+
92
+ 验收:`dazi onto space get <space-id>` 中 **`relationship_count`** 与规划条数一致;侧栏 **数据资源 → 表间关系** 可见。
93
+
94
+ > **勿与** `s.onto.define_link_type` 混淆:前者写数据空间元数据,后者写业务对象语义链接,**两者都需实施**。
95
+
96
+ ### 表注册 `TABLE_REGISTRY` + `register_with_meta`
97
+
98
+ init 脚本顶部维护与规划文档对齐的 `TABLE_REGISTRY`(项目内 `plans/*.md` 或内置 [规划示例](./规划示例_产品销售本体规划方案.md)),步骤 2 统一调用:
99
+
100
+ ```python
101
+ TABLE_REGISTRY = {
102
+ "fact_sales_order_line": {
103
+ "display_name": "销售订单行事实表",
104
+ "description": "订单行粒度销售流水",
105
+ "columns": [
106
+ {"name": "order_id", "display_name": "订单 ID"},
107
+ {"name": "date_key", "display_name": "日期键", "description": "关联 dim_date"},
108
+ # ...
109
+ ],
110
+ },
111
+ }
112
+
113
+ for tbl_name, meta in TABLE_REGISTRY.items():
114
+ s.tables.register_with_meta(
115
+ table_name=tbl_name,
116
+ display_name=meta["display_name"],
117
+ description=meta.get("description"),
118
+ columns=meta["columns"],
119
+ force_column_meta=True, # 规划变更后重跑 init 时刷新列元数据
120
+ )
121
+ ```
122
+
123
+ - **显示名** → 侧栏与表预览列标题(`display_name`)
124
+ - **说明** → 业务口径、FK、冗余原因(`description`);`sync_columns` **不会**自动写入
125
+ - 参考:`资源/examples/onto/利润示例/setup/profit_ontology_init.py`、`销售示例/setup/sales_ontology_init.py`
126
+
127
+ ### 分类注册 `CATEGORY_REGISTRY` + `apply_registry`
128
+
129
+ init 脚本顶部维护与规划附录 B 对齐的 `CATEGORY_REGISTRY`(分类名必须是 [347](./本体命名规范_物理表Cube与对象.md) 标准中文名),**所有资源注册完成后**调用:
130
+
131
+ ```python
132
+ cat_counts = s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)
133
+ ```
134
+
135
+ - 6 类资源平级挂载:`table` / `cube` / `object` / `relation` / `link` / `function`
136
+ - 函数类资源若 init 未 `register_function`,须 `skip_missing=True`
137
+ - 可选:注册 API 传 `category_347="维度表"` 等即时挂载(与 `apply_registry` 幂等可并存)
138
+ - 详见 [349 方案](./本体分类规划与SDK扩展方案.md)、[SDK 参考 §5.6](./dazi_script_sdk_reference.md)
139
+
43
140
  ## 脚本类型
44
141
 
45
- 类型由 **发布命令参数** 区分;文件可平铺在 `脚本/`,也可分子目录(如 `脚本/functions/`、`脚本/actions/`):
142
+ 类型由 **发布命令参数** 区分;初始化与灌数放 `setup/`,本体函数与动作放 `functions/`:
46
143
 
47
- | 类型 | 路径约定 | 说明 |
48
- | ------------------- | --------------------------------- | -------------------------------------------------- |
49
- | `ontology_function` | `项目/onto_<项目名>/脚本/**/*.py` | **必须**带 `--register-function-id` 发布(见下节) |
50
- | `ontology_action` | `项目/onto_<项目名>/脚本/**/*.py` | 发布时加 `--register-action-id` 等 Action 参数 |
51
- | `data_script` | `项目/onto_<项目名>/脚本/**/*.py` | 普通 `script publish`,不注册函数/动作 |
144
+ | 类型 | 路径约定 | 说明 |
145
+ | ------------------- | ----------------------------------------------------------------- | -------------------------------------------------- |
146
+ | `ontology_function` | `项目/<业务名>/本体/ontos/<实现名>/functions/**/*.py` | **必须**带 `--register-function-id` 发布(见下节) |
147
+ | `ontology_action` | `项目/<业务名>/本体/ontos/<实现名>/functions/**/*.py` | 发布时加 `--register-action-id` 等 Action 参数 |
148
+ | `data_script` | `项目/<业务名>/本体/ontos/<实现名>/setup/**/*.py` | 普通 `script publish`,不注册函数/动作 |
52
149
 
53
- `<space-id>` 从 **`项目/onto_<项目名>/README.md`** 读取,勿手写错空间。
150
+ `<space-id>` 从 **`项目/<业务名>/本体/ontos/<实现名>/README.md`** 读取,勿手写错空间。
54
151
 
55
152
  ## 发布预检
56
153
 
57
154
  ```powershell
58
- dazi onto script publish-preview 项目/onto_<项目名>/脚本/my_func.py --space <space-id>
155
+ dazi onto script publish-preview 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py --space <space-id>
59
156
  ```
60
157
 
61
158
  ## 发布脚本
@@ -64,7 +161,9 @@ dazi onto script publish-preview 项目/onto_<项目名>/脚本/my_func.py --spa
64
161
 
65
162
  ### 本体函数:**必须注册**,否则侧栏与测试看不到
66
163
 
67
- `脚本/functions/`(或规划中的本体函数 `.py`)**不能**只执行「普通 publish」:
164
+ `functions/`(或规划中的本体函数 `.py`)**不能**只执行「普通 publish」:
165
+
166
+ **新建函数**:复制 `资源/examples/onto/_templates/ontology_function_template.py`(`dazi examples show onto/template/ontology-function`),或参考 `销售示例/functions/sales_fn_get_summary.py`。`main()` **无参**,业务写在 `_ontology_fn_body(p)`,末尾 **`return _ontology_fn_body(p)`** — **禁止** `output.print_json()`(见 [脚本运行纠错 §3](./脚本运行纠错_商务成本方案开发过程.md#3-函数输出方式错误outputprint_json))。
68
167
 
69
168
  | 仅 `script publish`(无 `--register-function-id`) | 带 `--register-function-id` 发布 |
70
169
  | -------------------------------------------------- | -------------------------------------------- |
@@ -84,16 +183,16 @@ dazi onto script publish-preview 项目/onto_<项目名>/脚本/my_func.py --spa
84
183
 
85
184
  ```powershell
86
185
  # 初始化 / 灌数:普通发布即可(不要加 register-function-id)
87
- dazi onto script publish 项目/onto_<项目名>/脚本/setup/xxx_ontology_init.py --space <space-id> --type setup
88
- dazi onto script publish 项目/onto_<项目名>/脚本/setup/xxx_seed_data.py --space <space-id> --type data
186
+ dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/setup/xxx_ontology_init.py --space <space-id> --type setup
187
+ dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/setup/xxx_seed_data.py --space <space-id> --type data
89
188
 
90
189
  # ★ 本体函数:必须注册(示例)
91
- dazi onto script publish 项目/onto_<项目名>/脚本/functions/get_summary.py `
190
+ dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/get_summary.py `
92
191
  --space <space-id> `
93
192
  --register-function-id sales.fn.get_summary
94
193
 
95
194
  # 发布并注册为本体动作(示例)
96
- dazi onto script publish 项目/onto_<项目名>/脚本/my_action.py `
195
+ dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_action.py `
97
196
  --space <space-id> `
98
197
  --register-action-id my_action_code `
99
198
  --register-action-permission-tag "finance.write"
@@ -103,9 +202,57 @@ dazi onto script publish 项目/onto_<项目名>/脚本/my_action.py `
103
202
 
104
203
  ```powershell
105
204
  dazi onto function list --space <space-id>
106
- dazi onto function run sales.fn.get_summary --space <space-id>
205
+ dazi onto function run sales.fn.get_summary --space <space-id> --params '{}'
206
+ ```
207
+
208
+ ### 函数测试参数(test_arguments,**发布后必做**)
209
+
210
+ 仅 `publish` + `function run` **不会**自动写入测试参数;侧栏 **Onto → 运行函数** 依赖函数定义上的 **`test_arguments`** 预填表单。
211
+
212
+ > **CLI 易错点**:`function run` **不支持** `--arguments-json-file`;`save-test-arguments` 须用 **`ofn_xxx` 内部 id** 而非 `function_id` 字符串。完整说明见 [脚本运行纠错](./脚本运行纠错_商务成本方案开发过程.md)。
213
+
214
+ **本地约定(与规划文档 § 函数 / test_arguments 一致)**:
215
+
216
+ 1. 每个函数一份 JSON:`functions/test_arguments/<function_id>.json`
217
+ 2. 脚本内同名常量 `TEST_ARGUMENTS`(与 JSON **保持同步**)
218
+ 3. 函数 `main()` 通过 `ctx.params` 读取的键名 = JSON 内 **`arguments`** 对象的键名
219
+
220
+ **JSON 格式**(与平台函数定义一致):
221
+
222
+ ```json
223
+ {
224
+ "v": 1,
225
+ "arguments": {
226
+ "start_date": "2025-01-01",
227
+ "end_date": "2026-06-30"
228
+ },
229
+ "object_type_code": "SalesAnalysis"
230
+ }
231
+ ```
232
+
233
+ **保存到平台**(函数 `run` 验证通过后):
234
+
235
+ ```powershell
236
+ # 推荐:批量脚本(解析 function list,用内部 id ofn_xxx 调用 PATCH)
237
+ .\项目/<业务名>/本体/ontos/<实现名>/functions/save_test_arguments.ps1
107
238
  ```
108
239
 
240
+ 单条保存(**须用平台内部 id `ofn_xxx`**,先 `dazi onto function list --space <space-id>` 查看;直接传 `sales.fn.xxx` 可能 **404**):
241
+
242
+ ```powershell
243
+ dazi onto function save-test-arguments ofn_156a399fbe0e4636 --space <space-id> `
244
+ --arguments-json-file 项目/<业务名>/本体/ontos/<实现名>/functions/test_arguments/sales.fn.get_summary.json
245
+ ```
246
+
247
+ **PowerShell 传 `--params` 易丢引号**;测试运行可省略 `--params`(用 `{}`),或:
248
+
249
+ ```powershell
250
+ $env:DAZI_PARAMS='{"start_date":"2025-01-01","end_date":"2026-06-30"}'
251
+ dazi onto function run sales.fn.get_summary --space <space-id> --params $env:DAZI_PARAMS
252
+ ```
253
+
254
+ 验收:`dazi onto function get <function_id> --space <space-id>` 中 **`test_arguments` 非 null**,且 `arguments` 与 JSON 一致。
255
+
109
256
  亦可在 VS Code 侧栏 **Onto 本体 → 发布函数** 发布(须填写/绑定 **function_id**);发布后在 **函数** 节点下应能看到该函数。
110
257
 
111
258
  函数生命周期与 `update-code` 详见 **[本体函数开发指南](./function-guide.md)**。给 TRAE 的完整命令模板见内置提示词 **`onto/script-publish-run`**(`dazi prompt sync` 后位于 `资源/prompts/onto/`)。
@@ -115,12 +262,16 @@ dazi onto function run sales.fn.get_summary --space <space-id>
115
262
  若需将平台上已有脚本拉回本地对照(**非**日常开发主路径):
116
263
 
117
264
  ```powershell
265
+ # 推荐:落盘到本体实现目录(按 setup / functions 分子目录)
266
+ dazi onto script sync --space <space-id> --target-dir 项目/<业务名>/本体/ontos/<实现名>
267
+ dazi onto script sync --space <space-id> --type ontology_function --target-dir 项目/<业务名>/本体/ontos/<实现名>
268
+ dazi onto script sync --space <space-id> --dry-run --target-dir 项目/<业务名>/本体/ontos/<实现名>
269
+
270
+ # legacy:onto/<space-id>/scripts/(非日常开发入口)
118
271
  dazi onto script sync --space <space-id>
119
- dazi onto script sync --space <space-id> --type ontology_function
120
- dazi onto script sync --space <space-id> --dry-run
121
272
  ```
122
273
 
123
- 拉取目标目录以 CLI 为准;**新建与修改仍以 `项目/onto_<项目名>/脚本/` 为准**。
274
+ 拉取目标目录以 CLI 为准;**新建与修改仍以 `项目/<业务名>/本体/ontos/<实现名>/setup/` 与 `functions/` 为准**。
124
275
 
125
276
  ## 清理重复脚本
126
277
 
@@ -131,10 +282,22 @@ dazi onto script dedupe --space <space-id> --yes
131
282
 
132
283
  ## 编写建议
133
284
 
134
- 1. 先阅读 `快速启动.md` 与 `README.md` 中的**数据空间 ID**
135
- 2. 在 `脚本/` 中按模块拆分 `.py`(初始化、灌数、本体函数可分机文件)
136
- 3. 发布与运行:`dazi onto script publish`(**函数必须** `--register-function-id`)/ 侧栏 **Onto 本体**;函数运行见 **[function-guide](./function-guide.md)**、**[action-guide](./action-guide.md)**
137
- 4. 本地仅调试 Python 语法时可用 VS Code 运行 `脚本/main.py`(**不会**自动连平台;连平台须发布后在侧栏或 CLI 执行)
285
+ 1. 先阅读 `快速启动_<实现名>.md` 与 `README.md` 中的**数据空间 ID**,并对照 `plans/` 中**表间关系**与**函数 test_arguments** 章节
286
+ 2. 在 `setup/`、`functions/` 中按模块拆分 `.py`(初始化、灌数、本体函数可分机文件)
287
+ 3. **init 脚本**必须包含 `s.tables.add_relationship`(若规划有表间关系)
288
+ 4. 发布与运行:`dazi onto script publish`(**函数必须** `--register-function-id`)→ `function run` 验证 → **`save-test-arguments`**
289
+ 5. 本地仅调试 Python 语法时可在 VS Code 中直接运行 `.py`(**不会**自动连平台;连平台须发布后在侧栏或 CLI 执行)
290
+
291
+ ## 实施自检(智能体 / 人工)
292
+
293
+ | 检查项 | 命令 / 位置 |
294
+ | ------ | ----------- |
295
+ | 表已注册 | 侧栏 **数据资源** 或 `dazi onto space get` → `table_count` |
296
+ | **表间关系已注册** | `relationship_count` > 0;侧栏 **表间关系** |
297
+ | **347 分类已挂载** | 侧栏分类视图下表/Cube/对象等按标准中文名分组;init 摘要含 `category_mounts` |
298
+ | 函数已注册 | `dazi onto function list --space <space-id>` |
299
+ | **test_arguments 已保存** | `dazi onto function get <function_id>` → `test_arguments.arguments` |
300
+ | 函数可运行 | `dazi onto function run <function_id> --space <space-id> --params '{}'` |
138
301
 
139
302
  ## 相关文档
140
303
 
@@ -142,4 +305,7 @@ dazi onto script dedupe --space <space-id> --yes
142
305
  - [本体规划指南](./本体规划指南.md)
143
306
  - [本体函数开发指南](./function-guide.md)
144
307
  - [本体动作开发](./action-guide.md)
145
- - [规划示例:利润分析本体](./规划示例_利润分析本体方案.md)
308
+ - [规划示例:产品销售本体(推荐)](./规划示例_产品销售本体规划方案.md)
309
+ - [规划示例:利润分析本体(补充)](./规划示例_利润分析本体方案.md)
310
+ - [349 · 本体分类规划与 SDK 扩展方案](./本体分类规划与SDK扩展方案.md)
311
+ - [脚本运行纠错(商务成本方案实录)](./脚本运行纠错_商务成本方案开发过程.md)