@guandata/guanmetric 0.1.1 → 0.1.3
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 +10 -0
- package/README.md +12 -0
- package/bin/postinstall.js +58 -0
- package/bin/run.js +32 -1
- package/binaries/guanmetric-darwin-arm64 +0 -0
- package/binaries/guanmetric-darwin-x64 +0 -0
- package/binaries/guanmetric-linux-arm64 +0 -0
- package/binaries/guanmetric-linux-x64 +0 -0
- package/binaries/guanmetric-win32-x64.exe +0 -0
- package/package.json +2 -1
- package/skills/guanmetric/SKILL.md +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## @guandata/guanmetric 0.1.3 - 2026-07-23
|
|
4
|
+
|
|
5
|
+
- 完善已有指标资源的原地编辑指引,避免更新时误建新资源并影响既有引用。
|
|
6
|
+
- 优化多资源读取效率,Agent 批量准备和校验指标配置时等待更少。
|
|
7
|
+
|
|
8
|
+
## @guandata/guanmetric 0.1.2 - 2026-07-20
|
|
9
|
+
|
|
10
|
+
- 全局安装或升级后自动刷新 AI Skill,减少 CLI 与 Agent 使用说明版本不一致的情况。
|
|
11
|
+
- 随包提供完整的指标管理说明和参考资料。
|
|
12
|
+
|
|
3
13
|
## @guandata/guanmetric 0.1.1 - 2026-07-10
|
|
4
14
|
|
|
5
15
|
- 增强指标 Excel 标准化能力,支持按原子、复合和多类衍生指标拆分标准模板。
|
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@ npm install -g @guandata/guanmetric
|
|
|
9
9
|
guanmetric install-skill
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
> `npm install -g` / `npm link` 全局安装时会通过 postinstall 自动执行一次 skill 安装/刷新;上述命令用于手动重装或排查。CI 等无需 skill 的环境可设 `GUAN_SKIP_INSTALL_SKILL=1` 跳过。
|
|
13
|
+
|
|
12
14
|
## 常用命令
|
|
13
15
|
|
|
14
16
|
```bash
|
|
@@ -23,6 +25,16 @@ guanmetric public-dim create --file public_dim.json --dry-run
|
|
|
23
25
|
|
|
24
26
|
## 版本更新
|
|
25
27
|
|
|
28
|
+
### @guandata/guanmetric 0.1.3
|
|
29
|
+
|
|
30
|
+
- 完善已有指标资源的原地编辑指引,避免更新时误建新资源并影响既有引用。
|
|
31
|
+
- 优化多资源读取效率,Agent 批量准备和校验指标配置时等待更少。
|
|
32
|
+
|
|
33
|
+
### @guandata/guanmetric 0.1.2
|
|
34
|
+
|
|
35
|
+
- 全局安装或升级后自动刷新 AI Skill,减少 CLI 与 Agent 使用说明版本不一致的情况。
|
|
36
|
+
- 随包提供完整的指标管理说明和参考资料。
|
|
37
|
+
|
|
26
38
|
### @guandata/guanmetric 0.1.1
|
|
27
39
|
|
|
28
40
|
- 增强指标 Excel 标准化能力,支持按原子、复合和多类衍生指标拆分标准模板。
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Best-effort post-install hook: refresh the installed AI skill right after
|
|
5
|
+
* a global npm install/upgrade, so users cannot forget to run
|
|
6
|
+
* `guanmetric install-skill` and end up with a stale SKILL.md.
|
|
7
|
+
*
|
|
8
|
+
* Constraints:
|
|
9
|
+
* - MUST never fail the npm install: every failure path still exits 0.
|
|
10
|
+
* - Only runs for global installs (`npm install -g` / `npm link`); a local
|
|
11
|
+
* `npm install` inside a project never touches the user's home dirs.
|
|
12
|
+
* - Escape hatch: GUAN_SKIP_INSTALL_SKILL=1 skips entirely (e.g. CI images
|
|
13
|
+
* that install the CLI but never run an AI agent are skipped by default).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
"use strict";
|
|
17
|
+
|
|
18
|
+
const { spawnSync } = require("child_process");
|
|
19
|
+
const path = require("path");
|
|
20
|
+
|
|
21
|
+
const CLI_NAME = "guanmetric";
|
|
22
|
+
|
|
23
|
+
function skipReason() {
|
|
24
|
+
if (process.env.GUAN_SKIP_INSTALL_SKILL === "1") return "GUAN_SKIP_INSTALL_SKILL=1";
|
|
25
|
+
if (process.env.npm_config_global !== "true") return "not a global install";
|
|
26
|
+
if (process.env.CI) return "CI environment";
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function main() {
|
|
31
|
+
const reason = skipReason();
|
|
32
|
+
if (reason) {
|
|
33
|
+
console.log(`[${CLI_NAME}] postinstall: skipping automatic install-skill (${reason}).`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log(`[${CLI_NAME}] postinstall: refreshing AI skill (${CLI_NAME} install-skill)...`);
|
|
37
|
+
const result = spawnSync(
|
|
38
|
+
process.execPath,
|
|
39
|
+
[path.join(__dirname, "run.js"), "install-skill"],
|
|
40
|
+
{ stdio: "inherit", env: process.env, timeout: 180000 }
|
|
41
|
+
);
|
|
42
|
+
if (result.error || result.status !== 0) {
|
|
43
|
+
console.warn(
|
|
44
|
+
`[${CLI_NAME}] postinstall: automatic skill install did not complete` +
|
|
45
|
+
(result.error ? ` (${result.error.message})` : ` (exit ${result.status})`) +
|
|
46
|
+
`; run \`${CLI_NAME} install-skill\` manually to refresh SKILL.md.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
main();
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.warn(
|
|
55
|
+
`[${CLI_NAME}] postinstall: ${err.message}; run \`${CLI_NAME} install-skill\` manually.`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
process.exit(0);
|
package/bin/run.js
CHANGED
|
@@ -86,10 +86,36 @@ if (process.argv[2] === "version" && process.argv.length === 3) {
|
|
|
86
86
|
process.exit(0);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
|
|
90
|
+
// 定位 npm 自带的 npx-cli.js 并用 node 直接执行(与 guanskill 保持一致),
|
|
91
|
+
// 避免 Windows 上 spawn npx.cmd 的两类问题:shell:true 不做参数 quoting
|
|
92
|
+
// (全局安装路径含空格时会被拆参),以及新版 Node 禁止无 shell 的 .cmd
|
|
93
|
+
// spawn(CVE-2024-27980)。postinstall 场景下 npm_execpath 必然可用。
|
|
94
|
+
function resolveNpxInvocation() {
|
|
95
|
+
const executableDir = path.dirname(process.execPath);
|
|
96
|
+
const candidates = [];
|
|
97
|
+
if (process.env.npm_execpath) {
|
|
98
|
+
candidates.push(path.join(path.dirname(process.env.npm_execpath), "npx-cli.js"));
|
|
99
|
+
}
|
|
100
|
+
candidates.push(path.join(executableDir, "node_modules", "npm", "bin", "npx-cli.js"));
|
|
101
|
+
candidates.push(path.resolve(executableDir, "..", "node_modules", "npm", "bin", "npx-cli.js"));
|
|
102
|
+
candidates.push(path.resolve(executableDir, "..", "lib", "node_modules", "npm", "bin", "npx-cli.js"));
|
|
103
|
+
const npxCliPath = candidates.find((candidate) => fs.existsSync(candidate));
|
|
104
|
+
if (npxCliPath) {
|
|
105
|
+
return { command: process.execPath, argsPrefix: [npxCliPath] };
|
|
106
|
+
}
|
|
107
|
+
if (process.platform === "win32") {
|
|
108
|
+
throw new Error("Cannot locate npm/bin/npx-cli.js for safe Windows execution");
|
|
109
|
+
}
|
|
110
|
+
return { command: "npx", argsPrefix: [] };
|
|
111
|
+
}
|
|
112
|
+
|
|
89
113
|
if (process.argv[2] === "install-skill") {
|
|
90
114
|
const pkgRoot = path.join(__dirname, "..");
|
|
91
115
|
const extraArgs = process.argv.slice(3);
|
|
92
116
|
const args = [
|
|
117
|
+
// --yes: postinstall 等非交互环境下 npx 需要免确认下载 skills CLI
|
|
118
|
+
"--yes",
|
|
93
119
|
"skills",
|
|
94
120
|
"add",
|
|
95
121
|
pkgRoot,
|
|
@@ -100,7 +126,12 @@ if (process.argv[2] === "install-skill") {
|
|
|
100
126
|
...extraArgs,
|
|
101
127
|
];
|
|
102
128
|
console.log("Installing guanmetric to AI coding assistants...");
|
|
103
|
-
const
|
|
129
|
+
const npxInvocation = resolveNpxInvocation();
|
|
130
|
+
const result = spawnSync(npxInvocation.command, [...npxInvocation.argsPrefix, ...args], {
|
|
131
|
+
stdio: "inherit",
|
|
132
|
+
env: process.env,
|
|
133
|
+
shell: false,
|
|
134
|
+
});
|
|
104
135
|
if (result.error) throw result.error;
|
|
105
136
|
const status = result.status || 0;
|
|
106
137
|
if (status === 0) installBuddySkills(pkgRoot, "guanmetric");
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guandata/guanmetric",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "观远 BI 指标写操作工具 - 指标创建编辑删除、指标目录、公共维度、Excel 标准化",
|
|
5
5
|
"bin": {
|
|
6
6
|
"guanmetric": "bin/run.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
+
"postinstall": "node bin/postinstall.js",
|
|
9
10
|
"build": "node scripts/build.js && node scripts/sync-skill.js",
|
|
10
11
|
"changelog": "node ../../scripts/generate-release-changelog.js .",
|
|
11
12
|
"check-changelog": "node ../../scripts/check-release-changelog.js .",
|
|
@@ -21,6 +21,10 @@ guanmetric public-dim create --file public_dim.json --dry-run
|
|
|
21
21
|
guanmetric fetch POST /api/metric-platform/metrics/composite-metrics --file composite_metric.json
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
## 编辑红线:编辑 ≠ 删除重建
|
|
25
|
+
|
|
26
|
+
用户要求**编辑/重命名/修改**已有指标时,必须用 `guanmetric edit <metric_id>` 原地更新(默认按线上详情合并 patch,改名用 `--set name=新名`);公共维度用 `public-dim edit`。**严禁**用"delete 后重新 create 一个同名指标"来模拟编辑或改名:指标 ID 被复合指标、衍生指标、指标卡片和指标树引用,删除重建会让这些引用全部断链,指标上的权限和历史配置也会丢失且无法恢复。`delete` 只用于用户明确要求删除该指标本身。指标主题/目录目前只支持创建,不支持改名或删除;用户要求时直接说明 CLI 暂不支持,不要新建一个新主题/目录来替代。无论通过哪个命令或接口,都不得把"编辑"拆成"删除 + 重建"的组合来绕过这条红线。只有用户明确指示"先新建替代、再删除旧的"时才允许该流程,且执行前必须列出会断链和丢失的内容并获得确认。
|
|
27
|
+
|
|
24
28
|
批量创建指标时,必须先生成固定结构的标准 Excel 返回给用户确认;确认前不生成最终 payload,不提交真实创建。
|
|
25
29
|
|
|
26
30
|
如果用户提供的是客户原始 Excel/CSV,而不是已经接近标准模板的文件,agent 必须先自行读取并理解表格语义,产出一个语义映射中间表(建议命名为 `*.ai_mapped.xlsx`),再执行 `guanmetric template normalize` 生成最终标准模板。不要直接把客户原始 Excel 丢给 CLI 后交付结果;CLI 不负责穷举客户列名或业务表述。CLI 继续负责固定模板结构、必填项标记、业务属性配置读取、自动填充说明、行状态、问题说明、高亮样式、列宽自适应、基础校验和 report 输出。
|