Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and

### Added

- **Global `--biz-source` flag**: All commands accept `--biz-source <source>` so callers (skills/agents/products) can declare their business source. The normalized label is reported to AEM as a dedicated flat column `c6` (plus `ext`), enabling per-source PV/UV analysis of command usage (e.g. `flow-agent`). Absent → omitted; blank/invalid → `unknown`.
- **Global `--biz-from` flag**: All commands accept `--biz-from <source>` so callers (skills/agents/products) can declare their business source, enabling per-source usage analysis (PV/UV) of command calls (e.g. `flow-agent`).

## [2.10.5] - 2026-11-23

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

### 新增

- **全局 `--biz-source` 参数**:所有命令支持 `--biz-source <source>`,调用方(skill/agent/产品)可声明业务来源。归一化后的来源上报到 AEM 专用扁平列 `c6`(及 `ext`),支持按来源统计命令调用(如 `flow-agent`)的 PV/UV。缺省省略;空白/非法 → `unknown`。
- **全局 `--biz-from` 参数**:所有命令支持 `--biz-from <source>`,调用方(skill/agent/产品)可声明业务来源,便于按来源统计命令调用(如 `flow-agent`)的 PV/UV。

## [2.10.5] - 2026-11-23

Expand Down
6 changes: 3 additions & 3 deletions docs/agents/telemetry-change.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ source-config 只用于百炼 / DashScope API 侧消费,不发送到通用网
- `authMethod`
- `callerType`(必填:`agent` | `script` | `unknown`)
- `callerName`:`agent` 与 `script` 时发送(缺省/非法 → `"unknown"`);`skillName` / `skillVersion` 仅 `agent` 时可选发送
- `bizSource`:全局 `--biz-source` 声明的业务来源(可选);经 `normalizeBizSource` 归一化(缺省省略,空白/非法 → `"unknown"`),与 `callerName` 独立;映射到 AEM `c6` 专用扁平列
- `bizFrom`:全局 `--biz-from` 声明的业务来源(可选);经 `normalizeBizFrom` 归一化(缺省省略,空白/非法 → `"unknown"`),与 `callerName` 独立;映射到 AEM `c6` 专用扁平列
- 失败时的 `errorMessage`、`exitCode`、`httpStatus`、`requestId`
- 安全 allowlist 过滤后的 `params`

`bizSource` 是调用方(skill/agent/产品)通过全局 `--biz-source` 主动声明的来源标签,用于按来源区分命令调用的 PV/UV。它走 `GLOBAL_FLAGS` → `buildSettings` → `settings.bizSource` → `trackCommandExecution` 读取,不经命令自有 flag,也不进 `PARAM_ALLOWLIST`(c1)。归一化复用 caller 的 `NAME_PATTERN`(小写、空格/下划线转连字符, bounded charset)防 PII。AEM 侧除随 `ext` 上报外,另映射到专用扁平列 `c6`(标量字符串),无需 JSON 解析维度配置即可直接按 `c6` 筛选/分组:PV=事件计数,UV=distinct `uid`;按命令路径(如 `flow-agent *`)过滤即得某命令组的来源 PV/UV。`bizSource` 与 `callerType`/`callerName`(宿主归因)是独立维度,不得混用。
`bizFrom` 是调用方(skill/agent/产品)通过全局 `--biz-from` 主动声明的来源标签,用于按来源区分命令调用的 PV/UV。它走 `GLOBAL_FLAGS` → `buildSettings` → `settings.bizFrom` → `trackCommandExecution` 读取,不经命令自有 flag,也不进 `PARAM_ALLOWLIST`(c1)。归一化复用 caller 的 `NAME_PATTERN`(小写、空格/下划线转连字符, bounded charset)防 PII。AEM 侧除随 `ext` 上报外,另映射到专用扁平列 `c6`(标量字符串),无需 JSON 解析维度配置即可直接按 `c6` 筛选/分组:PV=事件计数,UV=distinct `uid`;按命令路径(如 `flow-agent *`)过滤即得某命令组的来源 PV/UV。`bizFrom` 与 `callerType`/`callerName`(宿主归因)是独立维度,不得混用。

调用方归因只认本次进程的 `BAILIAN_CALLER_*`(由 `readCaller` 归一化后写入事件):

Expand Down Expand Up @@ -158,7 +158,7 @@ AEM 映射:
| `c3` | HTTP status |
| `c4` | 错误文案,最多 500 字符 |
| `c5` | request ID |
| `c6` | `bizSource` 业务来源(全局 `--biz-source`,归一化标量;专用扁平列,直接筛选/分组) |
| `c6` | `bizFrom` 业务来源(全局 `--biz-from`,归一化标量;专用扁平列,直接筛选/分组) |

远端发送是 best-effort,不得阻塞命令或改变退出码。正常退出最多等待 1 秒,SIGINT 最多等待 500 ms。

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/e2e/registry.smoke.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("e2e: bl registry smoke", () => {
expect(stderr).toMatch(/--console-region/);
expect(stderr).toMatch(/--console-site/);
expect(stderr).toMatch(/--console-switch-agent/);
expect(stderr).toMatch(/--biz-source/);
expect(stderr).toMatch(/--biz-from/);
expect(stderr).not.toMatch(/^\s*--region\s/m);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,6 @@ export function buildSettings(s: ResolutionSources): Settings {
consoleSwitchAgent: flags.consoleSwitchAgent || file.console_switch_agent || undefined,
dryRun: flags.dryRun || false,
telemetry: env.DO_NOT_TRACK === "1" ? false : (file.telemetry ?? true),
bizSource: flags.bizSource ?? undefined,
bizFrom: flags.bizFrom ?? undefined,
};
}
4 changes: 2 additions & 2 deletions packages/core/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,6 @@ export interface Settings {
quiet: boolean;
dryRun: boolean;
telemetry: boolean;
/** Per-invocation business source label (--biz-source) for usage analytics; not persisted. */
bizSource?: string;
/** Per-invocation business source label (--biz-from) for usage analytics; not persisted. */
bizFrom?: string;
}
4 changes: 2 additions & 2 deletions packages/core/src/telemetry/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ function normalizeCallerName(raw: string | undefined): string {
}

/**
* Normalize a caller-declared business source label (--biz-source) to a stable id.
* Normalize a caller-declared business source label (--biz-from) to a stable id.
* Absent (undefined) stays undefined so the event omits the field; a present but
* blank/invalid label falls back to `unknown`, mirroring callerName. Reuses the
* caller name pattern to keep the value space bounded and free of PII.
*/
export function normalizeBizSource(raw: string | undefined): string | undefined {
export function normalizeBizFrom(raw: string | undefined): string | undefined {
return raw === undefined ? undefined : normalizeCallerName(raw);
}

Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/telemetry/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export interface TrackingEvent {
callerName?: string;
skillName?: string;
skillVersion?: string;
/** Caller-declared business source (--biz-source), normalized; reported as AEM c6. */
bizSource?: string;
/** Caller-declared call source (--biz-from), normalized; reported as AEM c6. */
bizFrom?: string;
}

export function createTrackingEvent(opts: {
Expand All @@ -36,7 +36,7 @@ export function createTrackingEvent(opts: {
authMethod?: AuthRequirement;
params?: Record<string, unknown>;
caller: CallerAttribution;
bizSource?: string;
bizFrom?: string;
}): TrackingEvent {
const event: TrackingEvent = {
command: opts.command,
Expand All @@ -58,8 +58,8 @@ export function createTrackingEvent(opts: {
event.callerName = opts.caller.callerName;
}

if (opts.bizSource !== undefined) {
event.bizSource = opts.bizSource;
if (opts.bizFrom !== undefined) {
event.bizFrom = opts.bizFrom;
}

if (opts.authMethod) {
Expand Down Expand Up @@ -108,8 +108,8 @@ export function buildRemoteAemOptions(event: TrackingEvent): Record<string, unkn
opts.c5 = event.requestId;
}
// Dedicated flat dimension column for the business source (easy AEM filtering).
if (event.bizSource !== undefined) {
opts.c6 = event.bizSource;
if (event.bizFrom !== undefined) {
opts.c6 = event.bizFrom;
}

return opts;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/telemetry/tracker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Identity, Settings } from "../config/schema.ts";
import { BailianError } from "../errors/base.ts";
import type { AuthRequirement } from "../types/command.ts";
import { normalizeBizSource, type CallerAttribution } from "./caller.ts";
import { normalizeBizFrom, type CallerAttribution } from "./caller.ts";
import { createTrackingEvent } from "./event.ts";
import { localSink, remoteSink } from "./sink.ts";

Expand Down Expand Up @@ -137,7 +137,7 @@ export async function trackCommandExecution(
authMethod: deps.authMethod,
params: extractParams(flags),
caller: deps.caller,
bizSource: normalizeBizSource(deps.settings.bizSource),
bizFrom: normalizeBizFrom(deps.settings.bizFrom),
});

// Fire-and-forget — never block the CLI exit or mask errors
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const GLOBAL_FLAGS = {
},
// Caller-declared source for usage attribution. Skills/agents should pass their
// own name when invoking commands so PV/UV can be segmented by calling skill/product.
bizSource: {
bizFrom: {
type: "string",
valueHint: "<source>",
description: {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/tests/config-priority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ function src(s: {

const resolve = (s: Parameters<typeof src>[0]): Settings => buildSettings(src(s));

test("maps --biz-source flag into settings.bizSource (not persisted)", () => {
expect(resolve({ flags: { bizSource: "coze" } }).bizSource).toBe("coze");
expect(resolve({ flags: {} }).bizSource).toBeUndefined();
test("maps --biz-from flag into settings.bizFrom (not persisted)", () => {
expect(resolve({ flags: { bizFrom: "coze" } }).bizFrom).toBe("coze");
expect(resolve({ flags: {} }).bizFrom).toBeUndefined();
// Explicit empty string is preserved (declared-but-empty), not folded to undefined.
expect(resolve({ flags: { bizSource: "" } }).bizSource).toBe("");
expect(resolve({ flags: { bizFrom: "" } }).bizFrom).toBe("");
});

test("token-plan Profile 预设保持固定", () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/core/tests/telemetry-caller.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "vite-plus/test";
import { normalizeBizSource, readCaller } from "../src/telemetry/caller.ts";
import { normalizeBizFrom, readCaller } from "../src/telemetry/caller.ts";

test.each([
{ label: "missing", env: {} },
Expand Down Expand Up @@ -62,14 +62,14 @@ test("normalizes callerName and falls back to unknown", () => {
});
});

test("normalizeBizSource keeps absent undefined and normalizes present labels", () => {
expect(normalizeBizSource(undefined)).toBeUndefined();
expect(normalizeBizSource("Coze")).toBe("coze");
expect(normalizeBizSource("My Skill")).toBe("my-skill");
expect(normalizeBizSource("qwen_code")).toBe("qwen-code");
expect(normalizeBizSource("")).toBe("unknown");
expect(normalizeBizSource(" ")).toBe("unknown");
expect(normalizeBizSource("bad/name!")).toBe("unknown");
test("normalizeBizFrom keeps absent undefined and normalizes present labels", () => {
expect(normalizeBizFrom(undefined)).toBeUndefined();
expect(normalizeBizFrom("Coze")).toBe("coze");
expect(normalizeBizFrom("My Skill")).toBe("my-skill");
expect(normalizeBizFrom("qwen_code")).toBe("qwen-code");
expect(normalizeBizFrom("")).toBe("unknown");
expect(normalizeBizFrom(" ")).toBe("unknown");
expect(normalizeBizFrom("bad/name!")).toBe("unknown");
});

test("drops illegal skillName and only keeps version when skillName is valid", () => {
Expand Down
67 changes: 32 additions & 35 deletions packages/core/tests/telemetry-tracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,64 +313,61 @@ test("does not call sinks when telemetry is disabled", async () => {
expect(sinkMocks.remoteSink).not.toHaveBeenCalled();
});

test("reports bizSource as a structured field and dedicated AEM c6 column", () => {
test("reports bizFrom as a structured field and dedicated AEM c6 column", () => {
const event = createTrackingEvent({
command: "flow-agent create",
durationMs: 1,
success: true,
identity,
caller: unknownCaller,
bizSource: "coze",
bizFrom: "coze",
});
expect(event.bizSource).toBe("coze");
expect(event.bizFrom).toBe("coze");
const opts = buildRemoteAemOptions(event);
expect(opts.c6).toBe("coze");
expect(opts.ext).toMatchObject({ bizSource: "coze" });
expect(opts.ext).toMatchObject({ bizFrom: "coze" });
});

test("omits bizSource and c6 when no source is declared", () => {
test("omits bizFrom and c6 when no source is declared", () => {
const event = createTrackingEvent({
command: "flow-agent create",
durationMs: 1,
success: true,
identity,
caller: unknownCaller,
});
expect(event.bizSource).toBeUndefined();
expect(event.bizFrom).toBeUndefined();
const opts = buildRemoteAemOptions(event);
expect(opts).not.toHaveProperty("c6");
expect(opts.ext).not.toHaveProperty("bizSource");
expect(opts.ext).not.toHaveProperty("bizFrom");
});

test.each([
{ label: "valid", bizSource: "My Skill", expected: "my-skill" },
{ label: "underscore", bizSource: "qwen_code", expected: "qwen-code" },
{ label: "invalid", bizSource: "bad/name!", expected: "unknown" },
{ label: "blank", bizSource: " ", expected: "unknown" },
{ label: "empty", bizSource: "", expected: "unknown" },
])(
"normalizes settings.bizSource ($label) into the event and c6",
async ({ bizSource, expected }) => {
sinkMocks.localSink.mockClear();
sinkMocks.remoteSink.mockClear();
await trackCommandExecution(
{
identity,
settings: { telemetry: true, bizSource } as Settings,
authMethod: "console",
caller: unknownCaller,
},
["flow-agent", "create"],
{},
async () => {},
);
const event = sinkMocks.remoteSink.mock.calls[0]![0];
expect(event.bizSource).toBe(expected);
expect(buildRemoteAemOptions(event).c6).toBe(expected);
},
);
{ label: "valid", bizFrom: "My Skill", expected: "my-skill" },
{ label: "underscore", bizFrom: "qwen_code", expected: "qwen-code" },
{ label: "invalid", bizFrom: "bad/name!", expected: "unknown" },
{ label: "blank", bizFrom: " ", expected: "unknown" },
{ label: "empty", bizFrom: "", expected: "unknown" },
])("normalizes settings.bizFrom ($label) into the event and c6", async ({ bizFrom, expected }) => {
sinkMocks.localSink.mockClear();
sinkMocks.remoteSink.mockClear();
await trackCommandExecution(
{
identity,
settings: { telemetry: true, bizFrom } as Settings,
authMethod: "console",
caller: unknownCaller,
},
["flow-agent", "create"],
{},
async () => {},
);
const event = sinkMocks.remoteSink.mock.calls[0]![0];
expect(event.bizFrom).toBe(expected);
expect(buildRemoteAemOptions(event).c6).toBe(expected);
});

test("absent settings.bizSource omits the field and c6", async () => {
test("absent settings.bizFrom omits the field and c6", async () => {
sinkMocks.localSink.mockClear();
sinkMocks.remoteSink.mockClear();
await trackCommandExecution(
Expand All @@ -385,6 +382,6 @@ test("absent settings.bizSource omits the field and c6", async () => {
async () => {},
);
const event = sinkMocks.remoteSink.mock.calls[0]![0];
expect(event.bizSource).toBeUndefined();
expect(event.bizFrom).toBeUndefined();
expect(buildRemoteAemOptions(event)).not.toHaveProperty("c6");
});
2 changes: 1 addition & 1 deletion skills/bailian-cli/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Available on every command (in addition to command-specific flags):
| `--verbose` | switch | no | Print HTTP request/response details |
| `--dry-run` | switch | no | Dry run mode |
| `--config <name>` | string | no | Use a config profile for this command |
| `--biz-source <source>` | string | no | Business source for usage analytics; callers/skills should pass their name so command calls are attributed to the calling skill/product |
| `--biz-from <source>` | string | no | Business source for usage analytics; callers/skills should pass their name so command calls are attributed to the calling skill/product |
| `--help` | switch | no | Show help |
| `--version` | switch | no | Print version |

Expand Down
2 changes: 1 addition & 1 deletion skills/bailian-finetune/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Available on every command (in addition to command-specific flags):
| `--verbose` | switch | no | Print HTTP request/response details |
| `--dry-run` | switch | no | Dry run mode |
| `--config <name>` | string | no | Use a config profile for this command |
| `--biz-source <source>` | string | no | Business source for usage analytics; callers/skills should pass their name so command calls are attributed to the calling skill/product |
| `--biz-from <source>` | string | no | Business source for usage analytics; callers/skills should pass their name so command calls are attributed to the calling skill/product |
| `--help` | switch | no | Show help |
| `--version` | switch | no | Print version |

Expand Down
2 changes: 1 addition & 1 deletion skills/bailian-gen/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Available on every command (in addition to command-specific flags):
| `--verbose` | switch | no | Print HTTP request/response details |
| `--dry-run` | switch | no | Dry run mode |
| `--config <name>` | string | no | Use a config profile for this command |
| `--biz-source <source>` | string | no | Business source for usage analytics; callers/skills should pass their name so command calls are attributed to the calling skill/product |
| `--biz-from <source>` | string | no | Business source for usage analytics; callers/skills should pass their name so command calls are attributed to the calling skill/product |
| `--help` | switch | no | Show help |
| `--version` | switch | no | Print version |

Expand Down
Loading