@dazitech/cli 3.0.6 → 3.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 (76) hide show
  1. package/README.md +1 -1
  2. package/dist/clis/dazi-app.js +1 -1
  3. package/dist/clis/dazi-flow.js +43 -24
  4. package/dist/clis/dazi-onto.js +73 -22
  5. package/dist/clis/dazi.js +266 -171
  6. package/dist/docs/flow/ai-workflow-playbook.md +4 -2
  7. package/dist/docs/flow/flow-project-guide.md +9 -5
  8. package/dist/docs/flow/flows-guide.md +2 -2
  9. package/dist/docs/flow/node-code-guide.md +408 -401
  10. package/dist/docs/flow/run-guide.md +13 -6
  11. package/dist/docs/flow/variables-guide.md +407 -406
  12. package/dist/docs/guides/quickstart.md +18 -4
  13. package/dist/docs/guides/troubleshooting.md +1 -1
  14. package/dist/docs/guides/workspace-v3.md +43 -23
  15. package/dist/docs/index.json +9 -3
  16. package/dist/docs/onto/action-guide.md +3 -3
  17. package/dist/docs/onto/dazi_script_sdk_reference.md +178 -174
  18. package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
  19. package/dist/docs/onto/function-guide.md +37 -10
  20. package/dist/docs/onto/space-management.md +3 -1
  21. 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 +138 -34
  22. package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +73 -31
  23. 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 +497 -0
  24. 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 +597 -541
  25. package/dist/examples/index.json +202 -22
  26. package/dist/examples/onto/README.md +43 -0
  27. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +99 -0
  28. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_budget_vs_actual.py +116 -0
  29. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_cost_center_profit.py +85 -0
  30. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +76 -0
  31. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +86 -0
  32. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +103 -0
  33. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +86 -0
  34. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +27 -0
  35. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.account_breakdown.json +10 -0
  36. 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 +10 -0
  37. 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 +9 -0
  38. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.get_summary.json +9 -0
  39. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.mom_analysis.json +9 -0
  40. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.top_accounts.json +11 -0
  41. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.yoy_analysis.json +9 -0
  42. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +521 -0
  43. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +213 -0
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +25 -0
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +86 -0
  46. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +123 -0
  47. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +81 -0
  48. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +90 -0
  49. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +85 -0
  50. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +101 -0
  51. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +90 -0
  52. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +25 -0
  53. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +8 -0
  54. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +10 -0
  55. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +8 -0
  56. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +8 -0
  57. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +8 -0
  58. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +10 -0
  59. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +8 -0
  60. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +5 -0
  61. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +403 -0
  62. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +124 -0
  63. package/dist/prompts/flow/ai-workflow-playbook.md +4 -2
  64. package/dist/prompts/flow/flow-design.md +12 -9
  65. package/dist/prompts/flow/run-fix-loop.md +37 -22
  66. package/dist/prompts/index.json +2 -2
  67. package/dist/prompts/onto/action-design.md +4 -1
  68. package/dist/prompts/onto/function-design.md +9 -2
  69. package/dist/prompts/onto/rule-seed.md +5 -1
  70. package/dist/prompts/onto/script-publish-run.md +72 -24
  71. package/package.json +1 -1
  72. package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
  73. package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
  74. package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
  75. package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
  76. package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
@@ -1,155 +1,158 @@
1
- # DaziScript 灌数脚本编写指南
2
-
3
- **文档 ID**: `onto/dazi-script-seed-data-guide`
4
- **适用**: dazi-vscode v3 + ClickHouse 数据空间
5
-
6
- > **用途**:约定工作区内「一次性 / 可重复执行」的造数、补数、历史回填脚本的写法,供人与 LLM 统一遵循。
7
- > SDK API 见 **[dazi_script_sdk_reference](./dazi_script_sdk_reference.md)**;目录与发布见 **[本体脚本编写指南](./本体脚本编写指南.md)**。
8
-
9
- ---
10
-
11
- ## 1. 什么是灌数脚本
12
-
13
- **灌数脚本**指在**已存在表结构**(或同脚本内先 DDL)的前提下,向当前空间写入**演示数据、回归数据、历史样本**的 DaziScript。
14
-
15
- ### 1.1 放置位置(v3)
16
-
17
- | 类型 | 推荐路径 |
18
- | -------------- | ------------------------------------------------------------------------------------------------------ |
19
- | **项目内开发** | `<工作区根>/项目/onto_<项目名>/脚本/<名称>.py` |
20
- | **参考示例** | `资源/examples/onto/setup/`(初始化+灌数一体)、`资源/examples/onto/function/`(分析函数,非灌数专篇) |
21
-
22
- - `space_id` 以 **`项目/onto_<项目名>/README.md`** 为准(扩展「新建项目」时已绑定)。
23
- - 侧栏 **帮助 → 📎 示例 → 下载所有示例**,或:`dazi examples sync` → `资源/examples/`。
24
- - 须定义 **`main()`**,**不要**写 `if __name__ == "__main__":`。
25
-
26
- > 不再使用 `spaces/<space_id>/editorial/scripts/setup/` 作为 v3 本地约定路径。
27
-
28
- ---
29
-
30
- ## 2. 硬约束(违反易导致联调失败)
31
-
32
- ### 2.1 ClickHouse:`INSERT ... VALUES` 与注释
33
-
34
- - **`VALUES` 与各元组之间禁止 SQL 行注释 `--`**。常见报错:`CANNOT_PARSE_INPUT_ASSERTION_FAILED`、`Code: 27`。
35
- - **允许**:在**整条** `INSERT` **之前**写注释;或拆成多条 `INSERT`。
36
- - **推荐**:大批量灌数用 **`s.sql.insert_rows(table, rows)`**(`rows` 为 `list[dict]`)。
37
-
38
- ### 2.2 幂等与可重复执行
39
-
40
- - 先 `query_one` / `count()` 判断已有数据,满足阈值则**跳过**或**仅补差额**。
41
- - 「清空再灌」须**显式开关**(如 `--force`),**默认**不破坏已有数据。
42
-
43
- ### 2.3 数据质量
44
-
45
- - 枚举字段勿含多余空格;`Date` / `DateTime` 与表定义、SDK 规整规则一致。
46
-
47
- ### 2.4 输出与验收
48
-
49
- - 关键步骤 `output.print`;结束可用 `output.success(...)`。
50
- - 机器解析约定:`__JSON_SUMMARY__` + JSON(与回归脚本一致)。
51
-
52
- ---
53
-
54
- ## 3. 推荐模式对照
55
-
56
- | 场景 | 推荐做法 |
57
- | ------------- | ------------------------------------------------------------------ |
58
- | 少量固定行 | 单条 `INSERT ... VALUES`,元组间**无**行间 `--`;或拆多条 `INSERT` |
59
- | 多批次、多行 | **`s.sql.insert_rows`** + Python 生成 `list[dict]` |
60
- | 需读 SQL 文件 | 注释写在 **INSERT 块上方**(Python 侧),不要塞进 `VALUES` 中间 |
61
-
62
- ---
63
-
64
- ## 4. 示例:`insert_rows`(推荐)
65
-
66
- 将 `space_id`、表名、列名替换为项目 README 与规划文档中的真实值。表须已存在(或在本脚本前文 DDL 创建)。
67
-
68
- ```python
69
- """示例:按空间灌入演示数据(幂等 + insert_rows)
70
-
71
- 放置:项目/onto_<项目名>/脚本/demo_seed.py
72
- space_id:见项目 README.md
73
- """
74
-
75
- import json
76
-
77
-
78
- def main():
79
- space_id = "space__your_id_here" # 与 README 一致
80
- table = "your_fact_table"
81
- s = space.get(space_id)
82
-
83
- try:
84
- n = int(s.sql.query_one(f"SELECT count() FROM {table}") or 0)
85
- except Exception:
86
- n = 0
87
- if n > 0:
88
- output.print(f"{table} 已有 {n} 行,跳过灌数")
89
- return
90
-
91
- rows = [
92
- {"id": "row_001", "name": "样例A", "metric_value": 100.5, "biz_date": "2025-01-10"},
93
- {"id": "row_002", "name": "样例B", "metric_value": 200.0, "biz_date": "2025-01-11"},
94
- ]
95
-
96
- inserted = s.sql.insert_rows(table, rows)
97
- output.print(f"已插入 {inserted} 行")
98
- output.success("灌数完成")
99
- output.print("__JSON_SUMMARY__" + json.dumps(
100
- {"ok": True, "table": table, "inserted": inserted},
101
- ensure_ascii=True,
102
- default=str,
103
- ))
104
- ```
105
-
106
- ---
107
-
108
- ## 5. 示例:单条 `execute` + `VALUES`
109
-
110
- ```python
111
- def main():
112
- s = space.get("space__your_id_here")
113
- if int(s.sql.query_one("SELECT count() FROM your_fact_table WHERE id = 'row_001'") or 0) > 0:
114
- output.print("已存在,跳过")
115
- return
116
-
117
- s.sql.execute(
118
- """
119
- INSERT INTO your_fact_table VALUES
120
- ('row_001', '样例A', 100.5, toDate('2025-01-10')),
121
- ('row_002', '样例B', 200.0, toDate('2025-01-11'))
122
- """
123
- )
124
- output.success("灌数完成")
125
- ```
126
-
127
- ---
128
-
129
- ## 6. 发布与执行(dazi-vscode)
130
-
131
- 在工作区根目录(`--space` 与项目 README 一致):
132
-
133
- ```bash
134
- # 预检
135
- dazi onto script publish-preview 项目/onto_<项目名>/脚本/demo_seed.py --space <space-id>
136
-
137
- # 发布到平台(data_script / 初始化脚本)
138
- dazi onto script publish 项目/onto_<项目名>/脚本/demo_seed.py --space <space-id>
139
-
140
- # 若已入库且已知 script-id,可在平台侧执行;或通过 Onto 侧栏运行
141
- dazi onto script run --script-id <script-id> --space <space-id> --params '{}'
142
- ```
143
-
144
- **参考完整初始化+灌数**:复制 `资源/examples/onto/setup/profit_ontology_init.py` 到 `项目/.../脚本/` 后按空间改 `space_id` 与表名,再发布执行。
145
-
146
- > **已废弃**:`dazi-agent run --file "spaces/.../editorial/..."` — 请改用上表 `dazi onto script publish` / `function run`。
147
-
148
- ---
149
-
150
- ## 7. 相关文档
151
-
152
- - [DaziScript SDK 参考](./dazi_script_sdk_reference.md)
153
- - [本体脚本编写指南](./本体脚本编写指南.md)
154
- - [本体脚本编写指南](./本体脚本编写指南.md)
155
- - [本体规划指南](./本体规划指南.md)
1
+ # DaziScript 灌数脚本编写指南
2
+
3
+ **文档 ID**: `onto/dazi-script-seed-data-guide`
4
+ **适用**: dazi-vscode v3 + ClickHouse 数据空间
5
+
6
+ > **用途**:约定工作区内「一次性 / 可重复执行」的造数、补数、历史回填脚本的写法,供人与 LLM 统一遵循。
7
+ > SDK API 见 **[dazi_script_sdk_reference](./dazi_script_sdk_reference.md)**;目录与发布见 **[本体脚本编写指南](./本体脚本编写指南.md)**。
8
+
9
+ ---
10
+
11
+ ## 1. 什么是灌数脚本
12
+
13
+ **灌数脚本**指在**已存在表结构**(或同脚本内先 DDL)的前提下,向当前空间写入**演示数据、回归数据、历史样本**的 DaziScript。
14
+
15
+ ### 1.1 放置位置(v3)
16
+
17
+ | 类型 | 推荐路径 |
18
+ | -------------- | ------------------------------------------------------------------------------------------------------ |
19
+ | **项目内开发** | `<工作区根>/项目/<业务名>/本体/ontos/<实现名>/setup/<名称>.py` |
20
+ | **参考示例** | **`资源/examples/onto/销售示例/setup/`**(init + seed)、**`资源/examples/onto/利润示例/setup/`**(init 模板) |
21
+
22
+ - `space_id` 以 **`项目/<业务名>/本体/ontos/<实现名>/README.md`** 为准(扩展「新建本体实现」时已绑定)。
23
+ - 侧栏 **帮助 → 📎 示例 → 下载所有示例**,或:`dazi examples sync` → `资源/examples/`。
24
+ - 须定义 **`main()`**,**不要**写 `if __name__ == "__main__":`。
25
+
26
+ > 不再使用 `spaces/<space_id>/editorial/scripts/setup/`、`项目/onto_<名称>/脚本/` 作为 v3 本地约定路径。
27
+
28
+ ---
29
+
30
+ ## 2. 硬约束(违反易导致联调失败)
31
+
32
+ ### 2.1 ClickHouse:`INSERT ... VALUES` 与注释
33
+
34
+ - **`VALUES` 与各元组之间禁止 SQL 行注释 `--`**。常见报错:`CANNOT_PARSE_INPUT_ASSERTION_FAILED`、`Code: 27`。
35
+ - **允许**:在**整条** `INSERT` **之前**写注释;或拆成多条 `INSERT`。
36
+ - **推荐**:大批量灌数用 **`s.sql.insert_rows(table, rows)`**(`rows` 为 `list[dict]`)。
37
+
38
+ ### 2.2 幂等与可重复执行
39
+
40
+ - 先 `query_one` / `count()` 判断已有数据,满足阈值则**跳过**或**仅补差额**。
41
+ - 「清空再灌」须**显式开关**(如 `--force`),**默认**不破坏已有数据。
42
+
43
+ ### 2.3 数据质量
44
+
45
+ - 枚举字段勿含多余空格;`Date` / `DateTime` 与表定义、SDK 规整规则一致。
46
+
47
+ ### 2.4 输出与验收
48
+
49
+ - 关键步骤 `output.print`;结束可用 `output.success(...)`。
50
+ - 机器解析约定:`__JSON_SUMMARY__` + JSON(与回归脚本一致)。
51
+
52
+ ---
53
+
54
+ ## 3. 推荐模式对照
55
+
56
+ | 场景 | 推荐做法 |
57
+ | ------------- | ------------------------------------------------------------------ |
58
+ | 少量固定行 | 单条 `INSERT ... VALUES`,元组间**无**行间 `--`;或拆多条 `INSERT` |
59
+ | 多批次、多行 | **`s.sql.insert_rows`** + Python 生成 `list[dict]` |
60
+ | 需读 SQL 文件 | 注释写在 **INSERT 块上方**(Python 侧),不要塞进 `VALUES` 中间 |
61
+
62
+ ---
63
+
64
+ ## 4. 示例:`insert_rows`(推荐)
65
+
66
+ 将 `space_id`、表名、列名替换为实现单元 README 与规划文档中的真实值。表须已存在(或在本脚本前文 DDL 创建)。
67
+
68
+ ```python
69
+ """示例:按空间灌入演示数据(幂等 + insert_rows)
70
+
71
+ 放置:项目/<业务名>/本体/ontos/<实现名>/setup/demo_seed.py
72
+ space_id:见实现单元 README.md
73
+ """
74
+
75
+ import json
76
+
77
+
78
+ def main():
79
+ space_id = "space__your_id_here" # 与 README 一致
80
+ table = "your_fact_table"
81
+ s = space.get(space_id)
82
+
83
+ try:
84
+ n = int(s.sql.query_one(f"SELECT count() FROM {table}") or 0)
85
+ except Exception:
86
+ n = 0
87
+ if n > 0:
88
+ output.print(f"{table} 已有 {n} 行,跳过灌数")
89
+ return
90
+
91
+ rows = [
92
+ {"id": "row_001", "name": "样例A", "metric_value": 100.5, "biz_date": "2025-01-10"},
93
+ {"id": "row_002", "name": "样例B", "metric_value": 200.0, "biz_date": "2025-01-11"},
94
+ ]
95
+
96
+ inserted = s.sql.insert_rows(table, rows)
97
+ output.print(f"已插入 {inserted} 行")
98
+ output.success("灌数完成")
99
+ output.print("__JSON_SUMMARY__" + json.dumps(
100
+ {"ok": True, "table": table, "inserted": inserted},
101
+ ensure_ascii=True,
102
+ default=str,
103
+ ))
104
+ ```
105
+
106
+ ---
107
+
108
+ ## 5. 示例:单条 `execute` + `VALUES`
109
+
110
+ ```python
111
+ def main():
112
+ s = space.get("space__your_id_here")
113
+ if int(s.sql.query_one("SELECT count() FROM your_fact_table WHERE id = 'row_001'") or 0) > 0:
114
+ output.print("已存在,跳过")
115
+ return
116
+
117
+ s.sql.execute(
118
+ """
119
+ INSERT INTO your_fact_table VALUES
120
+ ('row_001', '样例A', 100.5, toDate('2025-01-10')),
121
+ ('row_002', '样例B', 200.0, toDate('2025-01-11'))
122
+ """
123
+ )
124
+ output.success("灌数完成")
125
+ ```
126
+
127
+ ---
128
+
129
+ ## 6. 发布与执行(dazi-vscode)
130
+
131
+ 在工作区根目录(`--space` 与实现单元 README 一致):
132
+
133
+ ```bash
134
+ # 预检
135
+ dazi onto script publish-preview 项目/<业务名>/本体/ontos/<实现名>/setup/demo_seed.py --space <space-id>
136
+
137
+ # 发布到平台(data_script / 初始化脚本)
138
+ dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/setup/demo_seed.py --space <space-id>
139
+
140
+ # 若已入库且已知 script-id,可在平台侧执行;或通过 Onto 侧栏运行
141
+ dazi onto script run --script-id <script-id> --space <space-id> --params '{}'
142
+ ```
143
+
144
+ **参考完整初始化+灌数**:
145
+
146
+ - **推荐(已落地)**:`资源/examples/onto/销售示例/setup/sales_ontology_init.py`、`sales_seed_data.py`(见 [规划示例_产品销售本体规划方案.md](./规划示例_产品销售本体规划方案.md))
147
+ - **通用模板**:复制 `资源/examples/onto/利润示例/setup/profit_ontology_init.py` 到 `项目/<业务名>/本体/ontos/<实现名>/setup/` 后按空间改 `space_id` 与表名,再发布执行。
148
+
149
+ > **已废弃**:`dazi-agent run --file "spaces/.../editorial/..."` — 请改用上表 `dazi onto script publish` / `function run`。
150
+
151
+ ---
152
+
153
+ ## 7. 相关文档
154
+
155
+ - [DaziScript SDK 参考](./dazi_script_sdk_reference.md)
156
+ - [本体脚本编写指南](./本体脚本编写指南.md)
157
+ - [本体脚本编写指南](./本体脚本编写指南.md)
158
+ - [本体规划指南](./本体规划指南.md)
@@ -5,14 +5,18 @@
5
5
  ## 函数生命周期
6
6
 
7
7
  ```
8
- 在 项目/onto_<项目名>/脚本/ 编写 .py → publish-preview(预检)→ publish(入库)→ update-code(更新)
8
+ 编写 .py → publish-preview(可选)→ publish(--register-function-id 入库)
9
+ → function run 验证 → save-test-arguments(写入 test_arguments,侧栏预填)
10
+ → 后续改代码:update-code
9
11
  ```
10
12
 
13
+ 工作路径:`项目/<业务名>/本体/ontos/<实现名>/functions/`;本地 JSON:`functions/test_arguments/<function_id>.json`。
14
+
11
15
  ## 新建函数
12
16
 
13
17
  ```bash
14
- # 发布新函数(路径指向本体项目 脚本/ 目录)
15
- dazi onto function publish 项目/onto_<项目名>/脚本/my_func.py \
18
+ # 发布新函数(路径指向本体实现单元 functions/ 目录)
19
+ dazi onto function publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py \
16
20
  --space <space-id> \
17
21
  --function-id my_function \
18
22
  --display-name "我的函数" \
@@ -22,12 +26,12 @@ dazi onto function publish 项目/onto_<项目名>/脚本/my_func.py \
22
26
  或使用 `script publish`(等价,见 [本体脚本编写指南](./本体脚本编写指南.md)):
23
27
 
24
28
  ```bash
25
- dazi onto script publish 项目/onto_<项目名>/脚本/my_func.py \
29
+ dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py \
26
30
  --space <space-id> \
27
31
  --register-function-id my_function
28
32
  ```
29
33
 
30
- `<space-id>` 取自 **`项目/onto_<项目名>/README.md`**。
34
+ `<space-id>` 取自 **`项目/<业务名>/本体/ontos/<实现名>/README.md`**。
31
35
 
32
36
  ## 更新已有函数代码
33
37
 
@@ -38,22 +42,45 @@ dazi onto function update-code <function-id> \
38
42
  --stem my_func
39
43
  ```
40
44
 
41
- `--stem` 为脚本文件名(不含扩展名),须与 `脚本/` 下文件一致。
45
+ `--stem` 为脚本文件名(不含扩展名),须与 `functions/` 下文件一致。
42
46
 
43
47
  ## 运行函数
44
48
 
45
49
  ```bash
46
50
  dazi onto function run <function-id> \
47
51
  --space <space-id> \
48
- --params '{"key": "value"}'
52
+ --params '{}'
49
53
  ```
50
54
 
51
- ## 保存测试参数
55
+ PowerShell 下复杂 JSON 建议用环境变量 `DAZI_PARAMS` 或侧栏运行(使用已保存的 `test_arguments`)。详见 [本体脚本编写指南](./本体脚本编写指南.md#函数测试参数test_arguments发布后必做)。
56
+
57
+ ## 保存测试参数(test_arguments)
58
+
59
+ 函数 **`run` 验证通过后**,须将默认入参写入函数定义,侧栏 **Onto → 运行函数** 才会预填。
60
+
61
+ **本地文件**:`functions/test_arguments/<function_id>.json`(格式见 [本体脚本编写指南](./本体脚本编写指南.md))。
52
62
 
53
63
  ```bash
54
- dazi onto function save-test-arguments <function-id> \
64
+ # JSON 文件保存(推荐)
65
+ dazi onto function save-test-arguments <ofn_internal_id> \
55
66
  --space <space-id> \
56
- --params '{"test_param": 42}'
67
+ --arguments-json-file 项目/<业务名>/本体/ontos/<实现名>/functions/test_arguments/<function_id>.json
68
+ ```
69
+
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
+ ```
76
+
77
+ > **注意**:当前 CLI 的 PATCH 路径使用平台**内部 id**(`ofn_xxx`,由 `dazi onto function list` 返回),**不是** `function_id` 字符串(如 `sales.fn.get_summary` 可能 404)。批量保存可用 `functions/save_test_arguments.ps1`(见本体脚本编写指南)。
78
+
79
+ 验收:
80
+
81
+ ```bash
82
+ dazi onto function get <function-id> --space <space-id>
83
+ # 确认 test_arguments.arguments 与 JSON 一致
57
84
  ```
58
85
 
59
86
  ## 函数脚本结构
@@ -23,7 +23,7 @@ dazi onto space list
23
23
  dazi onto space init --space-id <space-id>
24
24
  ```
25
25
 
26
- 本地目录结构:
26
+ 本地目录结构(**历史/遗留布局**,由 CLI `space init` 生成):
27
27
 
28
28
  ```
29
29
  onto/<space-id>/
@@ -37,6 +37,8 @@ onto/<space-id>/
37
37
  .dazi-space.json
38
38
  ```
39
39
 
40
+ > **推荐工作区结构(v3)**:日常开发与文档约定使用 **`项目/<业务名>/本体/ontos/<实现名>/`** 实现单元布局(`README.md` 为 `space_id` 权威来源,`plans/`、`setup/`、`functions/`、`快速启动_<实现名>.md`)。`dazi onto space init` 生成的 **`onto/<space-id>/`** 仅用于 CLI 拉取快照、同步脚本等**对照/迁移**场景,**不应**作为新建本体项目的主开发路径。详见 **[本体规划指南](./本体规划指南.md)**、**[本体脚本编写指南](./本体脚本编写指南.md)**。
41
+
40
42
  ## 拉取快照
41
43
 
42
44
  将远端本体数据同步到本地: