@guandata/guanmetric 0.1.7 → 0.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## @guandata/guanmetric 0.1.9 - 2026-08-20
4
+
5
+ - 优化 Skill 自动安装提示与反馈,安装过程更清晰。
6
+ - 修复 Skill 安装/删除确认流程在部分场景下的兼容问题,减少误操作风险。
7
+ - 改进 Windows CLI 兼容性,并同步更新安装说明与使用文档。
8
+
9
+ ## @guandata/guanmetric 0.1.8 - 2026-08-13
10
+
11
+ - 查询加速能力支持配置筛选条件,可在加速配置中更精细地限定适用数据范围,提升特定场景下的使用灵活性。
12
+ - 创建和编辑查询加速时,可通过完整请求体、`--filter-json` 或 `--filter-file` 传入筛选条件。
13
+
3
14
  ## @guandata/guanmetric 0.1.7 - 2026-08-07
4
15
 
5
16
  - 新增指标查询加速能力,支持通过 CLI 对指标查询加速进行管理。
package/README.md CHANGED
@@ -5,11 +5,10 @@
5
5
  ## 安装
6
6
 
7
7
  ```bash
8
- npm install -g @guandata/guanmetric
9
- guanmetric install-skill
8
+ npm install -g --foreground-scripts @guandata/guanmetric
10
9
  ```
11
10
 
12
- > `npm install -g` / `npm link` 全局安装时会通过 postinstall 自动执行一次 skill 安装/刷新;上述命令用于手动重装或排查。CI 等无需 skill 的环境可设 `GUAN_SKIP_INSTALL_SKILL=1` 跳过。
11
+ > 全局安装/升级时会通过 postinstall 自动执行一次 `guanmetric install-skill` 刷新 AI skill。`--foreground-scripts` 用于显示明确的成功、失败或跳过结果;失败时按提示手动运行 `guanmetric install-skill`。CI 等无需 skill 的环境可设 `GUAN_SKIP_INSTALL_SKILL=1` 跳过。
13
12
 
14
13
  ## 常用命令
15
14
 
@@ -21,12 +20,22 @@ guanmetric create --file atomic_metric.json --dry-run
21
20
  guanmetric edit <metric_id> --file patch.json --dry-run
22
21
  guanmetric delete <metric_id>
23
22
  guanmetric public-dim create --file public_dim.json --dry-run
23
+ guanmetric accelerate create <metric_id> --ds-id <dsId> --fd-id <fdId> --aggr-type SUM --filter-file filter.json --dry-run
24
24
  guanmetric metric-tree create 销售额指标树 --metric-id <metric_id> --parent-dir-id <metric_tree_dir_id> --dry-run
25
25
  guanmetric metric-tree update-config <metric_tree_id> --file metric_tree_config.json --dry-run
26
26
  ```
27
27
 
28
28
  ## 版本更新
29
29
 
30
+ ### @guandata/guanmetric 0.1.9
31
+
32
+ - 改进 Skill 自动安装反馈和删除确认流程。
33
+ - 优化 Windows 环境下的 CLI 启动兼容性。
34
+
35
+ ### @guandata/guanmetric 0.1.8
36
+
37
+ - 查询加速创建和编辑支持配置筛选条件,可通过完整请求体、`--filter-json` 或 `--filter-file` 传入。
38
+
30
39
  ### @guandata/guanmetric 0.1.7
31
40
 
32
41
  - 新增指标查询加速管理能力。
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ const { spawnSync } = require("child_process");
4
+
5
+ const SANITIZED_MARKER = "GUAN_INSTALL_ENV_SANITIZED";
6
+ const SAFE_DELETE_TARGET = String.raw`(?:"(?:[^"]*[\\/])?genie-safe-delete\.cjs"|'(?:[^']*[\\/])?genie-safe-delete\.cjs'|(?:[^\s"']*[\\/])?genie-safe-delete\.cjs)`;
7
+
8
+ function envKey(env, expected) {
9
+ return Object.keys(env).find((key) => key.toLowerCase() === expected.toLowerCase());
10
+ }
11
+
12
+ function stripWorkBuddySafeDelete(nodeOptions) {
13
+ const pattern = new RegExp(
14
+ String.raw`(^|\s)(?:--require|-r)(?:=|\s+)${SAFE_DELETE_TARGET}(?=\s|$)(?:\s+|$)`,
15
+ "gi"
16
+ );
17
+ let removed = false;
18
+ const value = String(nodeOptions || "").replace(pattern, (_, prefix) => {
19
+ removed = true;
20
+ return prefix ? " " : "";
21
+ }).trim();
22
+ return { value, removed };
23
+ }
24
+
25
+ function hasWorkBuddySafeDelete(env = process.env) {
26
+ const key = envKey(env, "NODE_OPTIONS");
27
+ return Boolean(key && stripWorkBuddySafeDelete(env[key]).removed);
28
+ }
29
+
30
+ function createInstallChildEnv(env = process.env) {
31
+ const childEnv = { ...env };
32
+ for (const key of Object.keys(childEnv)) {
33
+ if (key.toLowerCase() === "npm_config_global") {
34
+ delete childEnv[key];
35
+ }
36
+ }
37
+
38
+ const nodeOptionsKey = envKey(childEnv, "NODE_OPTIONS");
39
+ if (nodeOptionsKey) {
40
+ const cleaned = stripWorkBuddySafeDelete(childEnv[nodeOptionsKey]);
41
+ if (cleaned.removed) {
42
+ if (cleaned.value) childEnv[nodeOptionsKey] = cleaned.value;
43
+ else delete childEnv[nodeOptionsKey];
44
+ childEnv[SANITIZED_MARKER] = "1";
45
+ }
46
+ }
47
+ return childEnv;
48
+ }
49
+
50
+ function reexecInstallCommand(scriptPath, args, options = {}) {
51
+ const env = options.env || process.env;
52
+ if (env[SANITIZED_MARKER] === "1" || !hasWorkBuddySafeDelete(env)) {
53
+ return false;
54
+ }
55
+
56
+ const spawn = options.spawn || spawnSync;
57
+ const exit = options.exit || process.exit;
58
+ const nodePath = options.nodePath || process.execPath;
59
+ const result = spawn(nodePath, [scriptPath, ...args], {
60
+ stdio: "inherit",
61
+ env: createInstallChildEnv(env),
62
+ shell: false,
63
+ });
64
+ if (result.error) throw result.error;
65
+ exit(result.status == null ? 1 : result.status);
66
+ return true;
67
+ }
68
+
69
+ module.exports = {
70
+ createInstallChildEnv,
71
+ hasWorkBuddySafeDelete,
72
+ reexecInstallCommand,
73
+ };
@@ -41,18 +41,21 @@ function main() {
41
41
  );
42
42
  if (result.error || result.status !== 0) {
43
43
  console.warn(
44
- `[${CLI_NAME}] postinstall: automatic skill install did not complete` +
44
+ `[${CLI_NAME}] postinstall: AI skill update FAILED` +
45
45
  (result.error ? ` (${result.error.message})` : ` (exit ${result.status})`) +
46
46
  `; run \`${CLI_NAME} install-skill\` manually to refresh SKILL.md.`
47
47
  );
48
+ return;
48
49
  }
50
+ console.log(`[${CLI_NAME}] postinstall: AI skill updated successfully.`);
49
51
  }
50
52
 
51
53
  try {
52
54
  main();
53
55
  } catch (err) {
54
56
  console.warn(
55
- `[${CLI_NAME}] postinstall: ${err.message}; run \`${CLI_NAME} install-skill\` manually.`
57
+ `[${CLI_NAME}] postinstall: AI skill update FAILED (${err.message}); ` +
58
+ `run \`${CLI_NAME} install-skill\` manually.`
56
59
  );
57
60
  }
58
61
  process.exit(0);
package/bin/run.js CHANGED
@@ -6,6 +6,7 @@ const { execFileSync, execSync, spawnSync } = require("child_process");
6
6
  const path = require("path");
7
7
  const fs = require("fs");
8
8
  const os = require("os");
9
+ const { createInstallChildEnv, reexecInstallCommand } = require("./install-env");
9
10
 
10
11
  const PLATFORM_MAP = {
11
12
  "darwin-arm64": "guanmetric-darwin-arm64",
@@ -111,6 +112,7 @@ function resolveNpxInvocation() {
111
112
  }
112
113
 
113
114
  if (process.argv[2] === "install-skill") {
115
+ reexecInstallCommand(__filename, process.argv.slice(2));
114
116
  const pkgRoot = path.join(__dirname, "..");
115
117
  const extraArgs = process.argv.slice(3);
116
118
  const args = [
@@ -128,8 +130,11 @@ if (process.argv[2] === "install-skill") {
128
130
  console.log("Installing guanmetric to AI coding assistants...");
129
131
  const npxInvocation = resolveNpxInvocation();
130
132
  const result = spawnSync(npxInvocation.command, [...npxInvocation.argsPrefix, ...args], {
133
+ // Avoid leaking project-only Agent markers (for example PromptScript) from
134
+ // the caller's cwd into this global installation.
135
+ cwd: pkgRoot,
131
136
  stdio: "inherit",
132
- env: process.env,
137
+ env: createInstallChildEnv(process.env),
133
138
  shell: false,
134
139
  });
135
140
  if (result.error) throw result.error;
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guandata/guanmetric",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "观远 BI 指标写操作工具 - 指标创建编辑删除、指标目录、公共维度、Excel 标准化",
5
5
  "bin": {
6
6
  "guanmetric": "bin/run.js"
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: guanmetric
3
3
  description: 当用户要创建、编辑、删除观远 BI 指标,创建指标主题/指标目录,创建或配置指标树(含维度拆解、指标拆解公式、复合指标公式展开),批量标准化 Excel 指标模板,或管理指标公共维度时使用本 skill。查询指标详情、搜索指标、指标数据查询仍使用 guancli。
4
- compatibility: "Requires Node.js 14+. Install via npm link (local) or npm install -g @guandata/guanmetric (from internal Nexus registry). CLI command: guanmetric."
4
+ compatibility: "Requires Node.js 14+. Install via npm link --foreground-scripts (local) or npm install -g --foreground-scripts @guandata/guanmetric (from internal Nexus registry) so the AI skill refresh result is visible. CLI command: guanmetric."
5
5
  ---
6
6
 
7
7
  # guanmetric
@@ -19,7 +19,9 @@ guanmetric edit <metric_id> --file patch.json --dry-run
19
19
  guanmetric delete <metric_id>
20
20
  guanmetric public-dim create --file public_dim.json --dry-run
21
21
  guanmetric accelerate create <metric_id> --ds-id <dsId> --fd-id <fdId> --aggr-type SUM --dim 省份 --dry-run
22
+ guanmetric accelerate create <metric_id> --ds-id <dsId> --fd-id <fdId> --aggr-type SUM --filter-file filter.json --dry-run
22
23
  guanmetric accelerate edit <accelerate_metric_id> --file accelerate_query.json --dry-run
24
+ guanmetric accelerate edit <accelerate_metric_id> --filter-json '{"type":"condition","not":false,"value":{"fdId":"fd_province","filterType":"IN","filterValue":[["浙江"]]}}' --dry-run
23
25
  guanmetric accelerate priority <metric_id> --priority <accelerate_metric_id>=2 --dry-run
24
26
  guanmetric accelerate delete <accelerate_metric_id> --confirm
25
27
  guanmetric metric-tree create 销售额指标树 --metric-id <metric_id> --parent-dir-id <metric_tree_dir_id> --dry-run
@@ -48,7 +50,7 @@ guanmetric fetch POST /api/metric-platform/metrics/composite-metrics --file comp
48
50
  生成衍生指标模板时,如果 `衍生自` 指标不是已明确存在的线上指标,而是本批也要创建的指标,必须在标准模板中补充对应的原子指标或复合指标行;信息不足时先补行并在该基础指标行的 `问题说明` 中列出缺失的数据集、来源字段、聚合方式、计算公式、适用维度等。不要等到创建计划阶段才临时新增基础指标。
49
51
 
50
52
  `fetch` 只用于指标平台写入接口尚未封装为专用命令的场景,例如复合指标/衍生指标创建、编辑和影响校验;常规原子指标、主题、目录、公共维度优先使用专用命令。
51
- 查询加速写操作已封装为 `accelerate` 专用命令;查询加速列表查询使用 `guancli metric accelerate list <metric_id>`。
53
+ 查询加速写操作已封装为 `accelerate` 专用命令;查询加速列表查询使用 `guancli metric accelerate list <metric_id>`。查询加速筛选条件使用和指标定义一致的 `WebFilterData` 结构,可放在完整请求体的 `filter` 字段,也可通过 `--filter-json` 或 `--filter-file` 传入;`not: true` 表示对该条件或条件组取反,清空筛选条件可传 `--filter-json null`。
52
54
  指标树创建和修改已封装为 `metric-tree` 专用命令,优先使用专用命令,不要再用裸 `fetch` 直接调用指标树写接口。指标树父目录来自 `METRIC_TREE` 目录树,可用 `guancli metric_attribution tree -f json` 查询;不要把 `guancli metric tree` 返回的 `METRIC_PLATFORM` 指标目录 ID 当作指标树目录 ID。用户给出指标拆解公式时,按 `metric-tree-mutation.md` 解析成 `metricRelationTree`;遇到复合指标时读取指标详情中的 `formula`,按规则递归展开或在计划中标注不能无损展开的原因。
53
55
 
54
56
  参考文档见本 skill 的 `references/` 目录: