@dazitech/cli 3.0.7 → 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 (68) 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 +1 -1
  9. package/dist/docs/guides/workspace-v3.md +43 -23
  10. package/dist/docs/index.json +9 -3
  11. package/dist/docs/onto/action-guide.md +3 -3
  12. package/dist/docs/onto/dazi_script_sdk_reference.md +178 -174
  13. package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
  14. package/dist/docs/onto/function-guide.md +37 -10
  15. package/dist/docs/onto/space-management.md +3 -1
  16. 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
  17. 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
  18. 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
  19. 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
  20. package/dist/examples/index.json +202 -22
  21. package/dist/examples/onto/README.md +43 -0
  22. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +99 -0
  23. 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
  24. 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
  25. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +76 -0
  26. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +86 -0
  27. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +103 -0
  28. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +86 -0
  29. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +27 -0
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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
  35. 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
  36. 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
  37. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +521 -0
  38. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +213 -0
  39. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +25 -0
  40. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +86 -0
  41. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +123 -0
  42. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +81 -0
  43. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +90 -0
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +85 -0
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +101 -0
  46. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +90 -0
  47. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +25 -0
  48. 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
  49. 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
  50. 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
  51. 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
  52. 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
  53. 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
  54. 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
  55. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +5 -0
  56. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +403 -0
  57. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +124 -0
  58. package/dist/prompts/index.json +2 -2
  59. package/dist/prompts/onto/action-design.md +4 -1
  60. package/dist/prompts/onto/function-design.md +9 -2
  61. package/dist/prompts/onto/rule-seed.md +5 -1
  62. package/dist/prompts/onto/script-publish-run.md +72 -24
  63. package/package.json +1 -1
  64. package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
  65. package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
  66. package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
  67. package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
  68. package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
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.7
81
+ pnpm add -g @dazitech/cli@3.0.8
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.7" : readDevVersion();
13080
+ var DAZI_VERSION = true ? "3.0.8" : 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.7" : readDevVersion();
4985
+ var DAZI_VERSION = true ? "3.0.8" : readDevVersion();
4986
4986
 
4987
4987
  // cli/dazi-flow/src/commands/flows.ts
4988
4988
  var import_path3 = __toESM(require("path"), 1);
@@ -3216,7 +3216,14 @@ function resolveWorkspace(cwd = process.cwd()) {
3216
3216
  }
3217
3217
 
3218
3218
  // cli/shared/src/version.ts
3219
- var DAZI_VERSION = true ? "3.0.7" : readDevVersion();
3219
+ var DAZI_VERSION = true ? "3.0.8" : readDevVersion();
3220
+
3221
+ // cli/shared/src/ontoWorkspaceAudit.ts
3222
+ function ontoItemSubdirForScriptType(scriptType) {
3223
+ const t = (scriptType ?? "").toLowerCase();
3224
+ if (t === "ontology_function" || t === "ontology_action") return "functions";
3225
+ return "setup";
3226
+ }
3220
3227
 
3221
3228
  // cli/dazi-onto/src/commands/space.ts
3222
3229
  var import_path3 = __toESM(require("path"), 1);
@@ -3705,9 +3712,36 @@ function makeRuleCommand() {
3705
3712
  // cli/dazi-onto/src/commands/script.ts
3706
3713
  var import_path6 = __toESM(require("path"), 1);
3707
3714
  var import_fs5 = __toESM(require("fs"), 1);
3715
+ async function fetchScriptCode(scriptId) {
3716
+ const detail = await apiRequest(`/api/scripts/${encodeURIComponent(scriptId)}`);
3717
+ return detail.code ?? "";
3718
+ }
3719
+ function scriptOutFileName(s) {
3720
+ const fromPath = s.filePath ? import_path6.default.basename(s.filePath) : "";
3721
+ if (fromPath && fromPath.endsWith(".py")) return fromPath;
3722
+ const stem = (s.name ?? s.id).replace(/\.py$/i, "");
3723
+ return `${stem}.py`;
3724
+ }
3725
+ function resolveSyncOutDir(opts, ws) {
3726
+ if (opts.targetDir) {
3727
+ return { base: import_path6.default.resolve(opts.targetDir), perItem: true };
3728
+ }
3729
+ return { base: import_path6.default.join(ws.onto, opts.space, "scripts"), perItem: false };
3730
+ }
3708
3731
  function inferScriptTypeFromPath(filePath, explicit) {
3709
3732
  if (explicit) return explicit;
3710
3733
  const norm = filePath.replace(/\\/g, "/");
3734
+ if (norm.includes("/\u811A\u672C/")) {
3735
+ console.warn(
3736
+ "[deprecated] \u68C0\u6D4B\u5230\u65E7\u8DEF\u5F84\u300C\u811A\u672C/\u300D\u3002\u8BF7\u8FC1\u81F3 \u9879\u76EE/<\u4E1A\u52A1>/\u672C\u4F53/ontos/<\u5B9E\u73B0\u540D>/setup|functions/"
3737
+ );
3738
+ if (norm.includes("/\u811A\u672C/functions/")) return "ontology_function";
3739
+ if (norm.includes("/\u811A\u672C/setup/")) {
3740
+ const stem = import_path6.default.basename(filePath, ".py").toLowerCase();
3741
+ if (stem.includes("seed")) return "data";
3742
+ return "setup";
3743
+ }
3744
+ }
3711
3745
  if (norm.includes("/functions/")) return "ontology_function";
3712
3746
  if (norm.includes("/setup/")) {
3713
3747
  const stem = import_path6.default.basename(filePath, ".py").toLowerCase();
@@ -3817,29 +3851,46 @@ function makeScriptCommand() {
3817
3851
  handleError(err);
3818
3852
  }
3819
3853
  });
3820
- cmd.command("sync").description("\u4ECE\u5E73\u53F0\u540C\u6B65\u811A\u672C\u5230\u672C\u5730 onto/<spaceId>/scripts/").requiredOption("--space <spaceId>", "\u7A7A\u95F4 ID").option("--type <scriptType>", "\u811A\u672C\u7C7B\u578B\uFF08\u5982 ontology_function\uFF09").option("--ids <ids>", "\u9017\u53F7\u5206\u9694\u7684\u811A\u672C ID \u5217\u8868").option("--with-docs", "\u540C\u65F6\u540C\u6B65\u5173\u8054\u6587\u6863\u5230 docs/").option("--dry-run", "\u4EC5\u9884\u89C8\uFF0C\u4E0D\u5199\u6587\u4EF6").option("--json", "\u8F93\u51FA JSON").action(async (opts) => {
3854
+ cmd.command("sync").description(
3855
+ "\u4ECE\u5E73\u53F0\u540C\u6B65\u811A\u672C\u5230\u672C\u5730 onto/<spaceId>/scripts/\uFF08legacy\uFF09\uFF1B\u65E5\u5E38\u5F00\u53D1\u8BF7\u7528 \u9879\u76EE/<\u4E1A\u52A1>/\u672C\u4F53/ontos/<\u5B9E\u73B0\u540D>/setup|functions/"
3856
+ ).requiredOption("--space <spaceId>", "\u7A7A\u95F4 ID").option("--type <scriptType>", "\u811A\u672C\u7C7B\u578B\uFF08\u5982 ontology_function\uFF09").option("--ids <ids>", "\u9017\u53F7\u5206\u9694\u7684\u811A\u672C ID \u5217\u8868").option("--target-dir <path>", "\u843D\u76D8\u5230 ontos/<\u5B9E\u73B0\u540D>/ \u76EE\u5F55\uFF08\u6309 setup|functions \u5206\u5B50\u76EE\u5F55\uFF09").option("--with-docs", "\u540C\u65F6\u540C\u6B65\u5173\u8054\u6587\u6863\u5230 docs/").option("--dry-run", "\u4EC5\u9884\u89C8\uFF0C\u4E0D\u5199\u6587\u4EF6").option("--json", "\u8F93\u51FA JSON").action(async (opts) => {
3821
3857
  try {
3822
- const body = { spaceId: opts.space, dryRun: opts.dryRun ?? false };
3823
- if (opts.type) body.scriptType = opts.type;
3824
- if (opts.ids) body.scriptIds = opts.ids.split(",").map((s) => s.trim());
3825
- if (opts.withDocs) body.withDocs = true;
3826
- const result = await apiRequest(
3827
- `/api/scripts?space_id=${opts.space}`,
3828
- { method: "POST", body }
3829
- );
3830
- if (!opts.dryRun) {
3831
- const ws = resolveWorkspace();
3832
- const scriptsDir = import_path6.default.join(ws.onto, opts.space, "scripts");
3833
- if (!import_fs5.default.existsSync(scriptsDir)) import_fs5.default.mkdirSync(scriptsDir, { recursive: true });
3834
- for (const s of result.scripts ?? []) {
3835
- if (s.filePath) {
3836
- const outFile = import_path6.default.join(scriptsDir, import_path6.default.basename(s.filePath));
3837
- console.log(` \u2193 ${outFile}`);
3838
- }
3839
- }
3858
+ const params = new URLSearchParams({ space_id: opts.space });
3859
+ if (opts.type) params.set("script_type", opts.type);
3860
+ let scripts = await apiRequest(`/api/scripts?${params}`);
3861
+ if (opts.ids) {
3862
+ const idSet = new Set(opts.ids.split(",").map((s) => s.trim()).filter(Boolean));
3863
+ scripts = scripts.filter((s) => idSet.has(s.id));
3840
3864
  }
3841
- console.log(`${opts.dryRun ? "[dry-run] " : ""}\u540C\u6B65 ${result.scripts?.length ?? 0} \u4E2A\u811A\u672C${opts.withDocs ? ` + ${result.docs?.length ?? 0} \u7BC7\u6587\u6863` : ""}`);
3842
- ok({ count: result.scripts?.length ?? 0, dryRun: opts.dryRun });
3865
+ const ws = resolveWorkspace();
3866
+ const { base: outBase, perItem } = resolveSyncOutDir(opts, ws);
3867
+ const written = [];
3868
+ for (const s of scripts) {
3869
+ const sub = perItem ? ontoItemSubdirForScriptType(s.scriptType) : "";
3870
+ const outDir = sub ? import_path6.default.join(outBase, sub) : outBase;
3871
+ const outFile = import_path6.default.join(outDir, scriptOutFileName(s));
3872
+ if (opts.dryRun) {
3873
+ console.log(` [dry-run] \u2193 ${outFile}`);
3874
+ written.push(outFile);
3875
+ continue;
3876
+ }
3877
+ if (!import_fs5.default.existsSync(outDir)) import_fs5.default.mkdirSync(outDir, { recursive: true });
3878
+ const code = s.code?.length ? s.code : await fetchScriptCode(s.id);
3879
+ if (!code.trim()) {
3880
+ console.warn(` \u26A0 \u8DF3\u8FC7 ${s.id}\uFF1A\u65E0\u811A\u672C\u4EE3\u7801`);
3881
+ continue;
3882
+ }
3883
+ import_fs5.default.writeFileSync(outFile, code, "utf8");
3884
+ console.log(` \u2193 ${outFile}`);
3885
+ written.push(outFile);
3886
+ }
3887
+ if (opts.withDocs) {
3888
+ console.warn(" --with-docs \u6682\u672A\u5B9E\u73B0\uFF0C\u8BF7\u4F7F\u7528 dazi docs sync");
3889
+ }
3890
+ console.log(
3891
+ `${opts.dryRun ? "[dry-run] " : ""}\u540C\u6B65 ${written.length}/${scripts.length} \u4E2A\u811A\u672C \u2192 ${outBase}`
3892
+ );
3893
+ ok({ count: written.length, total: scripts.length, dryRun: opts.dryRun, targetDir: outBase });
3843
3894
  } catch (err) {
3844
3895
  handleError(err);
3845
3896
  }