@dazitech/cli 3.0.0

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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -0
  3. package/dist/bin/dazi-app.cjs +4 -0
  4. package/dist/bin/dazi-flow.cjs +4 -0
  5. package/dist/bin/dazi-onto.cjs +4 -0
  6. package/dist/bin/dazi.cjs +4 -0
  7. package/dist/bin/run-cli-bin.cjs +62 -0
  8. package/dist/clis/dazi-app.js +16697 -0
  9. package/dist/clis/dazi-flow.js +6093 -0
  10. package/dist/clis/dazi-onto.js +3948 -0
  11. package/dist/clis/dazi.js +5677 -0
  12. package/dist/docs/app/app-init.md +69 -0
  13. package/dist/docs/app/build-upload.md +77 -0
  14. package/dist/docs/app/release-guide.md +51 -0
  15. package/dist/docs/app//344/270/273/350/246/201/350/264/242/345/212/241/346/214/207/346/240/207/345/244/215/346/235/202/346/212/245/350/241/250/345/274/200/345/217/221/345/256/236/350/267/265.md +261 -0
  16. package/dist/docs/auth/auth-login.md +41 -0
  17. package/dist/docs/auth/token-management.md +42 -0
  18. package/dist/docs/data/cube-guide.md +23 -0
  19. package/dist/docs/data/data-spaces.md +30 -0
  20. package/dist/docs/data/table-preview.md +41 -0
  21. package/dist/docs/flow/flow-project-guide.md +505 -0
  22. package/dist/docs/flow/flows-guide.md +302 -0
  23. package/dist/docs/flow/node-code-guide.md +399 -0
  24. package/dist/docs/flow/plan-guide.md +59 -0
  25. package/dist/docs/flow/run-guide.md +98 -0
  26. package/dist/docs/flow/source-guide.md +44 -0
  27. package/dist/docs/flow/variables-guide.md +406 -0
  28. package/dist/docs/flow//346/265/201/347/250/213/345/274/200/345/217/221/346/234/200/344/275/263/345/256/236/350/267/265-VS-flow0/346/241/210/344/276/213.md +344 -0
  29. package/dist/docs/guides/cli-invocation.md +93 -0
  30. package/dist/docs/guides/cli-reference.md +98 -0
  31. package/dist/docs/guides/mcp-setup.md +89 -0
  32. package/dist/docs/guides/migrate-v2-v3.md +54 -0
  33. package/dist/docs/guides/quickstart.md +77 -0
  34. package/dist/docs/guides/troubleshooting.md +82 -0
  35. package/dist/docs/guides/workspace-v3.md +53 -0
  36. package/dist/docs/index.json +204 -0
  37. package/dist/docs/onto/action-guide.md +48 -0
  38. package/dist/docs/onto/dazi_script_sdk_reference.md +168 -0
  39. package/dist/docs/onto/dazi_script_seed_data_guide.md +155 -0
  40. package/dist/docs/onto/function-guide.md +68 -0
  41. package/dist/docs/onto/rule-guide.md +52 -0
  42. package/dist/docs/onto/space-management.md +46 -0
  43. 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 +145 -0
  44. package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +131 -0
  45. 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 +541 -0
  46. package/dist/examples/index.json +36 -0
  47. package/dist/examples/onto/function/profit_fn_customer_segmentation.py +117 -0
  48. package/dist/examples/onto/function/profit_fn_mom_analysis.py +89 -0
  49. package/dist/examples/onto/function/profit_fn_top_products.py +89 -0
  50. package/dist/examples/onto/function/profit_fn_yoy_analysis.py +89 -0
  51. package/dist/examples/onto/setup/profit_ontology_init.py +388 -0
  52. package/dist/prompts/app/ui-design.md +48 -0
  53. package/dist/prompts/data/data-analysis.md +42 -0
  54. package/dist/prompts/data/sql-query.md +36 -0
  55. package/dist/prompts/flow/flow-design.md +77 -0
  56. package/dist/prompts/flow/plan-generate.md +61 -0
  57. package/dist/prompts/flow/run-debug.md +66 -0
  58. package/dist/prompts/flow/run-fix-loop.md +77 -0
  59. package/dist/prompts/general/ask-dazi.md +30 -0
  60. package/dist/prompts/general/code-review.md +31 -0
  61. package/dist/prompts/general/troubleshoot.md +41 -0
  62. package/dist/prompts/index.json +20 -0
  63. package/dist/prompts/onto/action-design.md +47 -0
  64. package/dist/prompts/onto/function-design.md +44 -0
  65. package/dist/prompts/onto/rule-seed.md +41 -0
  66. package/dist/prompts/onto/script-publish-run.md +146 -0
  67. package/package.json +27 -0
@@ -0,0 +1,155 @@
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
+ - 侧栏 **帮助 → 📎 示例 → 下载所有示例**,或:`.\scripts\dazi.ps1 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
+ .\scripts\dazi.ps1 onto script publish-preview 项目/onto_<项目名>/脚本/demo_seed.py --space <space-id>
136
+
137
+ # 发布到平台(data_script / 初始化脚本)
138
+ .\scripts\dazi.ps1 onto script publish 项目/onto_<项目名>/脚本/demo_seed.py --space <space-id>
139
+
140
+ # 若已入库且已知 script-id,可在平台侧执行;或通过 Onto 侧栏运行
141
+ .\scripts\dazi.ps1 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/..."` — 请改用上表 `.\scripts\dazi.ps1 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)
@@ -0,0 +1,68 @@
1
+ # 本体函数开发指南
2
+
3
+ **文档 ID**: `onto/function-guide`
4
+
5
+ ## 函数生命周期
6
+
7
+ ```
8
+ 在 项目/onto_<项目名>/脚本/ 编写 .py → publish-preview(预检)→ publish(入库)→ update-code(更新)
9
+ ```
10
+
11
+ ## 新建函数
12
+
13
+ ```bash
14
+ # 发布新函数(路径指向本体项目 脚本/ 目录)
15
+ .\scripts\dazi.ps1 onto function publish 项目/onto_<项目名>/脚本/my_func.py \
16
+ --space <space-id> \
17
+ --function-id my_function \
18
+ --display-name "我的函数" \
19
+ --entry main
20
+ ```
21
+
22
+ 或使用 `script publish`(等价,见 [本体脚本编写指南](./本体脚本编写指南.md)):
23
+
24
+ ```bash
25
+ .\scripts\dazi.ps1 onto script publish 项目/onto_<项目名>/脚本/my_func.py \
26
+ --space <space-id> \
27
+ --register-function-id my_function
28
+ ```
29
+
30
+ `<space-id>` 取自 **`项目/onto_<项目名>/README.md`**。
31
+
32
+ ## 更新已有函数代码
33
+
34
+ ```bash
35
+ # 用工作副本快速更新(不做完整 publish 流程)
36
+ .\scripts\dazi.ps1 onto function update-code <function-id> \
37
+ --space <space-id> \
38
+ --stem my_func
39
+ ```
40
+
41
+ `--stem` 为脚本文件名(不含扩展名),须与 `脚本/` 下文件一致。
42
+
43
+ ## 运行函数
44
+
45
+ ```bash
46
+ .\scripts\dazi.ps1 onto function run <function-id> \
47
+ --space <space-id> \
48
+ --params '{"key": "value"}'
49
+ ```
50
+
51
+ ## 保存测试参数
52
+
53
+ ```bash
54
+ .\scripts\dazi.ps1 onto function save-test-arguments <function-id> \
55
+ --space <space-id> \
56
+ --params '{"test_param": 42}'
57
+ ```
58
+
59
+ ## 函数脚本结构
60
+
61
+ ```python
62
+ def main(params: dict) -> dict:
63
+ """
64
+ 函数入口,params 由平台传入。
65
+ 返回值会作为函数输出。
66
+ """
67
+ return {"result": params.get("value", 0) * 2}
68
+ ```
@@ -0,0 +1,52 @@
1
+ # 本体规则(Rule)管理
2
+
3
+ **文档 ID**: `onto/rule-guide`
4
+
5
+ ## 规则概念
6
+
7
+ 规则(Rule)存储在 `ads_ontology_rules` 表,通过种子脚本写入,通常用于:
8
+ - 数据校验规则
9
+ - 业务约束条件
10
+ - 权限规则集
11
+
12
+ ## 列出规则
13
+
14
+ ```bash
15
+ .\scripts\dazi.ps1 onto rule list --space <space-id>
16
+
17
+ # 按规则集过滤
18
+ .\scripts\dazi.ps1 onto rule list --space <space-id> --rule-set finance_rules
19
+ ```
20
+
21
+ ## 执行规则种子
22
+
23
+ ```bash
24
+ .\scripts\dazi.ps1 onto rule run-seed --space <space-id> --stem cw_001_rules_seed
25
+ ```
26
+
27
+ ## 种子脚本示例
28
+
29
+ ```python
30
+ def main(params: dict, s) -> dict:
31
+ rules = [
32
+ {
33
+ "code": "fin_001",
34
+ "name": "余额不能为负",
35
+ "rule_set": "finance_rules",
36
+ "expression": "balance >= 0",
37
+ }
38
+ ]
39
+ s.ontology_rules.upsert(rules)
40
+ return {"count": len(rules)}
41
+ ```
42
+
43
+ ## 删除规则
44
+
45
+ ```bash
46
+ # 删除单条
47
+ .\scripts\dazi.ps1 onto rule delete fin_001 --space <space-id>
48
+
49
+ # 按规则集批量删除(先 dry-run)
50
+ .\scripts\dazi.ps1 onto rule delete-all --space <space-id> --rule-set old_rules --dry-run
51
+ .\scripts\dazi.ps1 onto rule delete-all --space <space-id> --rule-set old_rules --yes
52
+ ```
@@ -0,0 +1,46 @@
1
+ # 本体空间管理
2
+
3
+ **文档 ID**: `onto/space-management`
4
+
5
+ ## 空间概念
6
+
7
+ 本体空间(Space)是搭子平台的基础组织单位,每个空间包含:
8
+ - 函数定义(FunctionDef)
9
+ - 动作定义(ActionDef)
10
+ - 规则(Rule)
11
+ - 脚本(Script)
12
+
13
+ ## 列出空间
14
+
15
+ ```bash
16
+ .\scripts\dazi.ps1 onto space list
17
+ ```
18
+
19
+ ## 初始化本地工作区
20
+
21
+ ```bash
22
+ .\scripts\dazi.ps1 onto space init --space-id <space-id>
23
+ ```
24
+
25
+ 本地目录结构:
26
+ ```
27
+ onto/<space-id>/
28
+ editorial/
29
+ functions/ ← 函数工作副本
30
+ actions/ ← 动作工作副本
31
+ functions/ ← 函数定义元数据
32
+ actions/ ← 动作定义元数据
33
+ rules/ ← 规则元数据
34
+ scripts/ ← 脚本文件
35
+ .dazi-space.json
36
+ ```
37
+
38
+ ## 拉取快照
39
+
40
+ 将远端本体数据同步到本地:
41
+
42
+ ```bash
43
+ .\scripts\dazi.ps1 onto space snapshot --space-id <space-id>
44
+ ```
45
+
46
+ 快照保存到 `onto/<space-id>/snapshot.json`。
@@ -0,0 +1,145 @@
1
+ # 本体脚本编写指南
2
+
3
+ **文档 ID**: `onto/script-authoring`
4
+
5
+ 本文说明本体项目内 **Python 脚本的目录、类型、发布与运行**(原独立的「脚本开发与发布」已与本文合并)。
6
+
7
+ > 终端命令均在 **`dazi-work` 根目录**执行:`.\scripts\dazi.ps1 ...`(见 [CLI 调用约定](../guides/cli-invocation.md))。
8
+
9
+ ## 环境
10
+
11
+ - 推荐 **Python 3.10+**
12
+ - 脚本目录:**`<工作区根>/项目/onto_<项目名>/脚本/`**(新建本体项目时自动创建)
13
+ - 扩展默认脚本语言:`dazi.onto.defaultScriptLang` = `python`
14
+ - 平台 API:`dazi.serverUrl`;登录:`.\scripts\dazi.ps1 auth login` / `.\scripts\dazi.ps1 auth set-token`
15
+
16
+ ## 目录约定
17
+
18
+ ```text
19
+ <工作区根>/项目/onto_<项目名>/ ← 扩展「新建项目」;README 含 space_id
20
+ ├── README.md
21
+ ├── 快速启动.md
22
+ ├── 规划/
23
+ └── 脚本/ ← 所有本体 Python 脚本(函数/动作/灌数/初始化)
24
+ ├── main.py
25
+ └── ...
26
+ ```
27
+
28
+ 参考示例(可复制后修改)位于 **`资源/examples/onto/`**(侧栏 **帮助 → 示例** 或 `.\scripts\dazi.ps1 examples sync`)。
29
+
30
+ > **不再使用** 历史路径 `onto/<space_id>/editorial/`、`editorial/functions/` 等作为本地开发约定。
31
+
32
+ ## 必读规范(DaziScript)
33
+
34
+ 编写 `脚本/` 下 `.py` 前请阅读:
35
+
36
+ | 文档 | 说明 |
37
+ |------|------|
38
+ | **[DaziScript SDK 参考](./dazi_script_sdk_reference.md)** | `space` / `s.sql` / `s.onto` / `s.tables` / Cube 等 API 与本体落库顺序 |
39
+ | **[DaziScript 灌数脚本编写指南](./dazi_script_seed_data_guide.md)** | 造数、补数、`insert_rows` 与 ClickHouse `INSERT` 约束、幂等约定 |
40
+
41
+ 同步到工作区:`.\scripts\dazi.ps1 docs sync` → `资源/docs/onto/`。
42
+
43
+ ## 脚本类型
44
+
45
+ 类型由 **发布命令参数** 区分;文件可平铺在 `脚本/`,也可分子目录(如 `脚本/functions/`、`脚本/actions/`):
46
+
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`,不注册函数/动作 |
52
+
53
+ `<space-id>` 从 **`项目/onto_<项目名>/README.md`** 读取,勿手写错空间。
54
+
55
+ ## 发布预检
56
+
57
+ ```powershell
58
+ .\scripts\dazi.ps1 onto script publish-preview 项目/onto_<项目名>/脚本/my_func.py --space <space-id>
59
+ ```
60
+
61
+ ## 发布脚本
62
+
63
+ > **勿用** 独立命令 `dazi-onto`(v3 未安装到 PATH)。统一使用 **`.\scripts\dazi.ps1 onto ...`**。
64
+
65
+ ### 本体函数:**必须注册**,否则侧栏与测试看不到
66
+
67
+ `脚本/functions/`(或规划中的本体函数 `.py`)**不能**只执行「普通 publish」:
68
+
69
+ | 仅 `script publish`(无 `--register-function-id`) | 带 `--register-function-id` 发布 |
70
+ |--------------------------------------------------|----------------------------------|
71
+ | 脚本代码进入 `ads_scripts` | 同上 **且** 写入 `ontology_function_defs` |
72
+ | **不会**出现在 **Onto → 函数列表** | 出现在函数列表,可 **运行函数** / 工作台测试 |
73
+ | `.\scripts\dazi.ps1 onto function run <id>` **找不到** | `function run`、侧栏运行可用 |
74
+
75
+ 因此:**首次发布本体函数时,命令里必须包含 `--register-function-id`**,且 `function_id` 与规划文档、脚本内约定 **完全一致**(建议带点号命名空间,如 `sales.fn.get_summary`,勿随意简写为 `get_summary`)。
76
+
77
+ 智能体(TRAE 等)实施自检:
78
+
79
+ 1. 发布命令是否包含 `--register-function-id`?
80
+ 2. 发布输出是否含 `functionId: xxx` / `function_registration.ok`?
81
+ 3. `.\scripts\dazi.ps1 onto function list --space <space-id>` 能否看到该 `function_id`?
82
+
83
+ 任一步不满足 → **视为未注册**,需重新 publish(带注册参数),不要仅 `script run` 以为函数已可用。
84
+
85
+ ```powershell
86
+ # 初始化 / 灌数:普通发布即可(不要加 register-function-id)
87
+ .\scripts\dazi.ps1 onto script publish 项目/onto_<项目名>/脚本/setup/xxx_ontology_init.py --space <space-id> --type setup
88
+ .\scripts\dazi.ps1 onto script publish 项目/onto_<项目名>/脚本/setup/xxx_seed_data.py --space <space-id> --type data
89
+
90
+ # ★ 本体函数:必须注册(示例)
91
+ .\scripts\dazi.ps1 onto script publish 项目/onto_<项目名>/脚本/functions/get_summary.py `
92
+ --space <space-id> `
93
+ --register-function-id sales.fn.get_summary
94
+
95
+ # 发布并注册为本体动作(示例)
96
+ .\scripts\dazi.ps1 onto script publish 项目/onto_<项目名>/脚本/my_action.py `
97
+ --space <space-id> `
98
+ --register-action-id my_action_code `
99
+ --register-action-permission-tag "finance.write"
100
+ ```
101
+
102
+ 发布后验证:
103
+
104
+ ```powershell
105
+ .\scripts\dazi.ps1 onto function list --space <space-id>
106
+ .\scripts\dazi.ps1 onto function run sales.fn.get_summary --space <space-id>
107
+ ```
108
+
109
+ 亦可在 VS Code 侧栏 **Onto 本体 → 发布函数** 发布(须填写/绑定 **function_id**);发布后在 **函数** 节点下应能看到该函数。
110
+
111
+ 函数生命周期与 `update-code` 详见 **[本体函数开发指南](./function-guide.md)**。给 TRAE 的完整命令模板见内置提示词 **`onto/script-publish-run`**(`.\scripts\dazi.ps1 prompt sync` 后位于 `资源/prompts/onto/`)。
112
+
113
+ ## 从平台拉取脚本(可选)
114
+
115
+ 若需将平台上已有脚本拉回本地对照(**非**日常开发主路径):
116
+
117
+ ```powershell
118
+ .\scripts\dazi.ps1 onto script sync --space <space-id>
119
+ .\scripts\dazi.ps1 onto script sync --space <space-id> --type ontology_function
120
+ .\scripts\dazi.ps1 onto script sync --space <space-id> --dry-run
121
+ ```
122
+
123
+ 拉取目标目录以 CLI 为准;**新建与修改仍以 `项目/onto_<项目名>/脚本/` 为准**。
124
+
125
+ ## 清理重复脚本
126
+
127
+ ```powershell
128
+ .\scripts\dazi.ps1 onto script dedupe --space <space-id> --dry-run
129
+ .\scripts\dazi.ps1 onto script dedupe --space <space-id> --yes
130
+ ```
131
+
132
+ ## 编写建议
133
+
134
+ 1. 先阅读 `快速启动.md` 与 `README.md` 中的**数据空间 ID**
135
+ 2. 在 `脚本/` 中按模块拆分 `.py`(初始化、灌数、本体函数可分机文件)
136
+ 3. 发布与运行:`.\scripts\dazi.ps1 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 执行)
138
+
139
+ ## 相关文档
140
+
141
+ - [CLI 调用约定](../guides/cli-invocation.md)
142
+ - [本体规划指南](./本体规划指南.md)
143
+ - [本体函数开发指南](./function-guide.md)
144
+ - [本体动作开发](./action-guide.md)
145
+ - [规划示例:利润分析本体](./规划示例_利润分析本体方案.md)
@@ -0,0 +1,131 @@
1
+ # 本体规划指南
2
+
3
+ ## 目标
4
+
5
+ 在 `规划/` 目录中完成本体项目的概念设计,包括:
6
+
7
+ - 业务域与边界
8
+ - 对象类型(Object Type)与关键属性
9
+ - 链接类型(Link Type)与基数
10
+ - 动作(Action)与规则(Rule)的初步清单
11
+
12
+ ## 本体、Cube 与物理表:三者关系与「业务世界」方法
13
+
14
+ 规划时须分清三层,**自上而下**以业务语言为主,**自下而上**以存储与分析为落地;避免把「本体」写成「表的别名」或「Cube 的副本」。
15
+
16
+ | 层级 | 是什么 | 典型职责 | 规划文档里写什么 |
17
+ | ----------------------------- | ------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18
+ | **物理表(Table)** | ClickHouse 等引擎中的事实/维表 | 存储、排序键、约束、ETL 落地;面向写入与物理优化 | **首层物理模型宜为业务明细/维表/流水等**,分析向宽表、主题汇总表宜作为**派生层**;**避免**规划落地时默认「每个分析对象各建一张 `fact_*_analysis`」且仅此一层——否则与「每个 Cube 复制一个对象」仍是同一类一对一,只是顺序颠倒。表名、主键/关联列与源系统对齐;**不**把表名直接当作业务对象的唯一名字 |
19
+ | **Cube** | 面向分析语义的数据集视图(维度、度量、聚合) | 报表、语义查询、指标白名单;`qualified_name` 多以前缀 `CubeName.member` 出现 | 需要哪些 Cube、维/度量与业务度量的对应;Cube 名可用分析域习惯(如带 `Analytics` / `Cube` 后缀) |
20
+ | **本体(Ontology 对象类型)** | **业务世界**中的对象类型:身份、类型化**链接**、挂载函数/动作/规则的锚点 | 让业务与产品讨论「客户」「订单」「合同」而非「第几张表第几列」;链接表达有向业务关系,而非仅外键数值相等 | **对象类型 `code`** 用稳定**业务英文标识**(如 `Order`、`Customer`);与 Cube 名、表名**刻意区分**;`bind_source` 声明「当前由哪个 Cube 支撑该对象的读模型」 |
21
+
22
+ **「业务世界」方法(规划阶段强制自检)**:
23
+
24
+ - 先列 **对象类型** 与 **链接**(谁与谁、业务动词/名词),再反推需要哪些表、是否已有 Cube、是否要新建表或宽表;**反推表时**区分「事件/明细/主数据」与「仅为报表服务的汇总表」,勿把**第一步物理落点**默认识别为「按分析主题各一张事实表」。
25
+ - 接受 **多对一**:多表、多 Cube 可收敛为一种业务对象;一宽表也可拆成多种业务对象。
26
+ - **链接**两端必须是对象类型 **`code`**,不是 Cube 名;表中仅有 `xxx_id` 时,规划文中仍应写清本体链接语义。
27
+
28
+ **与业界对象中心实践的对照**:上述分层与「对象优先、数据为 backing」的思路,可与 **Palantir Foundry Ontology**(对象类型、链接、Action、Function 分层)等成熟产品对照阅读;落地脚本时以平台当前 API 与 **`.\scripts\dazi.ps1 onto`** 能力为准,**不**假设已实现对方全部特性。
29
+
30
+ ## 必读文档
31
+
32
+ 1. **本体规划示例**:`规划示例_利润分析本体方案.md`(扩展内置于 `docs/onto/`;同步到工作区后为 `资源/docs/onto/规划示例_利润分析本体方案.md`)
33
+ 2. **工作区与 CLI**:`guides/workspace-v3.md`、`guides/cli-reference.md`(`.\scripts\dazi.ps1 docs sync` 后位于 `资源/docs/guides/`)
34
+
35
+ ## 产出约定
36
+
37
+ - **本体方案(规划文档)**:新建/修改的 Markdown **必须**落在 **`项目/{{项目名称}}/规划/<规划主题>.md`**(这是规划阶段的真产出;**不是**改 `本体规划指南.md`)。
38
+ - 进入脚本实现阶段:遵循 **`本体脚本编写指南.md`**(含发布)、**`function-guide.md`**。
39
+
40
+ ## 空间约束(强制)
41
+
42
+ - 本体项目创建时已绑定 **数据空间**;`space_id` 以 **`项目/<文件夹名>/README.md`** 为准。
43
+ - 若 README 中无 `space_id`(非扩展「新建项目」创建的本体项目),不得新建规划文件,须先让用户补全空间或重新创建项目。
44
+
45
+ ## LLM 执行指引(必须遵循)
46
+
47
+ 面向 **dazi-vscode v3**:终端用 **`.\scripts\dazi.ps1`**(本体/流程/数据/鉴权),DRAP 在 **`项目/app_<名称>/` 应用项目根** 用 **`pnpm run dazi-app --`**;**禁止**全局 `dazi-onto` / 已废弃的 `dazi-agent`。
48
+
49
+ ### 工作区与项目
50
+
51
+ - **工作区根**:VS Code 已打开的文件夹;多根工作区时在设置 **`dazi.workspaceRoot`** 指定。
52
+ - **平台与登录**:`dazi.serverUrl`;`.\scripts\dazi.ps1 auth login` 或 `.\scripts\dazi.ps1 auth set-token`(Token 存 `.dazi/auth.json`)。
53
+ - **本体项目即工作单元**(扩展「新建项目」时已选定数据空间,**无需**再建 `onto/<space_id>/` 等平行目录):
54
+
55
+ ```text
56
+ <工作区根>/
57
+ 项目/onto_<名称>/
58
+ README.md ← 数据空间 ID、项目元信息(规划/实施均以此为准)
59
+ 规划/ ← 规划阶段 Markdown 产出
60
+ 脚本/ ← 本体 Python 脚本
61
+ 资源/docs/onto/ ← 本体指南与规划示例(.\scripts\dazi.ps1 docs sync)
62
+ 资源/dataspaces/ ← 侧栏下载的表结构 Markdown
63
+ ```
64
+
65
+ ### 规划开始前
66
+
67
+ 1. 从 **`项目/<文件夹名>/README.md`** 读取 **数据空间 ID**(可与设置 `dazi.spaceId` 对照,以 README 为准)。
68
+ 2. 未绑定 `space_id` 时 **不得** 新建规划 Markdown,须先让用户通过扩展创建本体项目或明确空间。
69
+
70
+ ### 规划阶段最小流程
71
+
72
+ 在 **工作区根目录** 打开终端执行:
73
+
74
+ ```bash
75
+ .\scripts\dazi.ps1 doctor
76
+ .\scripts\dazi.ps1 auth whoami
77
+ .\scripts\dazi.ps1 docs sync # 可选:同步帮助文档到 资源/docs/
78
+ ```
79
+
80
+ **核对数据空间与现网资产**(`<space_id>` 取自当前项目的 `README.md`,勿另猜目录):
81
+
82
+ ```bash
83
+ .\scripts\dazi.ps1 onto space list
84
+ .\scripts\dazi.ps1 onto space get <space_id> # 可选:查看空间详情
85
+ ```
86
+
87
+ **扩展侧栏(规划阶段主要入口)**:
88
+
89
+ | 目的 | 操作 |
90
+ | -------------- | ---- |
91
+ | 确认绑定空间 | 打开 **`项目/onto_<名称>/README.md`** 中的数据空间 ID |
92
+ | 查看表 / Cube | **数据资源** → 对应数据空间 → 展开表、Cube |
93
+ | 下载表结构 | 表节点右键「下载表信息」→ `资源/dataspaces/` |
94
+ | 同步帮助文档 | **帮助** → 下载文档(`.\scripts\dazi.ps1 docs sync`) |
95
+
96
+ > 规划阶段**不**要求本地 `snapshot.json`、`editorial/` 或 `onto/<space_id>/` 目录;以侧栏 **数据资源** 与项目内文档为准即可。
97
+
98
+ 规划阶段 **只产出 Markdown**:写入 **`项目/<onto_项目>/规划/<主题>.md`**,可参考 **`规划示例_利润分析本体方案.md`**。此阶段不发布脚本。
99
+
100
+ ### 进入脚本实施
101
+
102
+ 脚本写在 **`项目/<onto_项目>/脚本/`**(Python,见 `dazi.onto.defaultScriptLang`)。发布与运行见 **`本体脚本编写指南.md`**、**`function-guide.md`**:
103
+
104
+ ```bash
105
+ .\scripts\dazi.ps1 onto script publish-preview 项目/onto_<名称>/脚本/my_func.py --space <space_id>
106
+ .\scripts\dazi.ps1 onto script publish 项目/onto_<名称>/脚本/my_func.py \
107
+ --space <space_id> \
108
+ --register-function-id <function_id>
109
+ .\scripts\dazi.ps1 onto function run <function_id> --space <space_id> --params '{}'
110
+ ```
111
+
112
+ 亦可在侧栏 **Onto 本体** 使用「发布函数」「运行函数」等命令(与终端 CLI **同源** bundled;`--space` 与项目 README 中的 `space_id` 一致)。
113
+
114
+ 实施前可用 `.\scripts\dazi.ps1 onto function list --space <space_id>` 核对平台已有函数定义,**开发入口始终是 `项目/<onto_项目>/脚本/`**,不以历史 `onto/`、`editorial` 目录为约定路径。
115
+
116
+ ### 失败处理
117
+
118
+ - 命令失败时输出 **完整错误** 与修复建议(登录、`dazi.serverUrl`、工作区路径、`space_id`),**不得** 静默跳过。
119
+ - v2 → v3 命令对照见 `guides/troubleshooting.md`(`.\scripts\dazi.ps1 docs sync` 后位于 `资源/docs/guides/`)。
120
+
121
+ ## 自检
122
+
123
+ - 是否写清对象类型、链接、函数/Action、规则(如适用)
124
+ - **`define_link_type` 与对象类型 code**:链接两端须为**已规划且将先创建**的对象类型 **`code`**(与 `define_object_type` 一致);**勿**将 **Cube 名** 或表名当作对象类型 `code`。勿混用仅中文名而无稳定 `code`。
125
+ - 是否给出实施步骤、风险与验收
126
+
127
+ ## 相关文档
128
+
129
+ - [本体脚本编写指南](./本体脚本编写指南.md)
130
+ - [本体规划指南](./本体规划指南.md)
131
+ - [本体规划示例文档](./规划示例_利润分析本体方案.md)