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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and

[中文版](CHANGELOG.zh.md) · [README](README.md) · [Contributing](CONTRIBUTING.md)

## [2.11.0] - 2026-11-24

### 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`.

## [2.10.5] - 2026-11-23

### Added
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

[English](CHANGELOG.md) · [README](README.zh.md) · [参与贡献](CONTRIBUTING.zh.md)

## [2.11.0] - 2026-11-24

### 新增

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

## [2.10.5] - 2026-11-23

### 新增
Expand Down
4 changes: 4 additions & 0 deletions docs/agents/telemetry-change.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ source-config 只用于百炼 / DashScope API 侧消费,不发送到通用网
- `authMethod`
- `callerType`(必填:`agent` | `script` | `unknown`)
- `callerName`:`agent` 与 `script` 时发送(缺省/非法 → `"unknown"`);`skillName` / `skillVersion` 仅 `agent` 时可选发送
- `bizSource`:全局 `--biz-source` 声明的业务来源(可选);经 `normalizeBizSource` 归一化(缺省省略,空白/非法 → `"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`(宿主归因)是独立维度,不得混用。

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

- `BAILIAN_CALLER_TYPE` 为 `agent` / `ai_agent`(大小写不敏感)→ `callerType=agent`
Expand Down Expand Up @@ -155,6 +158,7 @@ AEM 映射:
| `c3` | HTTP status |
| `c4` | 错误文案,最多 500 字符 |
| `c5` | request ID |
| `c6` | `bizSource` 业务来源(全局 `--biz-source`,归一化标量;专用扁平列,直接筛选/分组) |

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

Expand Down
2 changes: 1 addition & 1 deletion packages/bailian-kb-dsh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-kb-dsh",
"version": "2.10.5",
"version": "2.11.0",
"description": "Bailian knowledge-base tools for DeepSeek Harness: kb_search and kb_chat over the DashScope RAG API, plus the bl CLI management skill.",
"keywords": [
"alibaba-cloud",
Expand Down
2 changes: 1 addition & 1 deletion packages/bailian-memo-dsh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-memo-dsh",
"version": "2.10.5",
"version": "2.11.0",
"description": "Bailian personal memory for DeepSeek Harness: automatic recall, silent curation, and user-controlled remember/forget.",
"keywords": [
"alibaba-cloud",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-cli",
"version": "2.10.5",
"version": "2.11.0",
"description": "CLI for Aliyun Model Studio (DashScope) AI Platform.",
"keywords": [
"agent",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tests/e2e/registry.smoke.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +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).not.toMatch(/^\s*--region\s/m);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/commands/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-cli-commands",
"version": "2.10.5",
"version": "2.11.0",
"description": "Command library for bailian-cli products (knowledge, memory, media, …). See https://www.npmjs.com/package/bailian-cli for usage.",
"homepage": "https://bailian.console.aliyun.com/cli",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-cli-core",
"version": "2.10.5",
"version": "2.11.0",
"description": "Core SDK for bailian-cli. See https://www.npmjs.com/package/bailian-cli for usage.",
"homepage": "https://bailian.console.aliyun.com/cli",
"bugs": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/config/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +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,
};
}
2 changes: 2 additions & 0 deletions packages/core/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +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;
}
10 changes: 10 additions & 0 deletions packages/core/src/telemetry/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ function normalizeCallerName(raw: string | undefined): string {
return NAME_PATTERN.test(normalized) ? normalized : "unknown";
}

/**
* Normalize a caller-declared business source label (--biz-source) 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 {
return raw === undefined ? undefined : normalizeCallerName(raw);
}

/** Env-only attribution; no TTY or install-path heuristics. */
export function readCaller(env: NodeJS.ProcessEnv): CallerAttribution {
const callerType = readTrimmed(env, CALLER_TYPE_ENV)?.toLowerCase();
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/telemetry/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface TrackingEvent {
callerName?: string;
skillName?: string;
skillVersion?: string;
/** Caller-declared business source (--biz-source), normalized; reported as AEM c6. */
bizSource?: string;
}

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

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

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

return opts;
}
3 changes: 2 additions & 1 deletion 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 type { CallerAttribution } from "./caller.ts";
import { normalizeBizSource, type CallerAttribution } from "./caller.ts";
import { createTrackingEvent } from "./event.ts";
import { localSink, remoteSink } from "./sink.ts";

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

// Fire-and-forget — never block the CLI exit or mask errors
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/types/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ export const GLOBAL_FLAGS = {
"zh-CN": "为当前命令使用指定配置 Profile",
},
},
// 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: {
type: "string",
valueHint: "<source>",
description: {
"en-US":
"Business source for usage analytics; callers/skills should pass their name so command calls are attributed to the calling skill/product",
"zh-CN":
"业务来源标识,用于用量统计;调用方/skill 调用命令时建议带上自身名称,以便归因到具体 skill/产品",
},
},
help: {
type: "switch",
description: { "en-US": "Show help", "zh-CN": "显示帮助信息" },
Expand Down
7 changes: 7 additions & 0 deletions packages/core/tests/config-priority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ 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();
// Explicit empty string is preserved (declared-but-empty), not folded to undefined.
expect(resolve({ flags: { bizSource: "" } }).bizSource).toBe("");
});

test("token-plan Profile 预设保持固定", () => {
expect(getModelProfilePreset("token-plan")).toEqual({
baseUrl: "https://token-plan.cn-beijing.maas.aliyuncs.com",
Expand Down
12 changes: 11 additions & 1 deletion 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 { readCaller } from "../src/telemetry/caller.ts";
import { normalizeBizSource, readCaller } from "../src/telemetry/caller.ts";

test.each([
{ label: "missing", env: {} },
Expand Down Expand Up @@ -62,6 +62,16 @@ 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("drops illegal skillName and only keeps version when skillName is valid", () => {
expect(
readCaller({
Expand Down
76 changes: 76 additions & 0 deletions packages/core/tests/telemetry-tracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,79 @@ test("does not call sinks when telemetry is disabled", async () => {
expect(sinkMocks.localSink).not.toHaveBeenCalled();
expect(sinkMocks.remoteSink).not.toHaveBeenCalled();
});

test("reports bizSource 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",
});
expect(event.bizSource).toBe("coze");
const opts = buildRemoteAemOptions(event);
expect(opts.c6).toBe("coze");
expect(opts.ext).toMatchObject({ bizSource: "coze" });
});

test("omits bizSource 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();
const opts = buildRemoteAemOptions(event);
expect(opts).not.toHaveProperty("c6");
expect(opts.ext).not.toHaveProperty("bizSource");
});

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);
},
);

test("absent settings.bizSource omits the field and c6", async () => {
sinkMocks.localSink.mockClear();
sinkMocks.remoteSink.mockClear();
await trackCommandExecution(
{
identity,
settings: { telemetry: true } as Settings,
authMethod: "console",
caller: unknownCaller,
},
["flow-agent", "create"],
{},
async () => {},
);
const event = sinkMocks.remoteSink.mock.calls[0]![0];
expect(event.bizSource).toBeUndefined();
expect(buildRemoteAemOptions(event)).not.toHaveProperty("c6");
});
2 changes: 1 addition & 1 deletion packages/kscli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knowledge-studio-cli",
"version": "2.10.5",
"version": "2.11.0",
"description": "Lightweight RAG CLI for Aliyun Model Studio — focused on knowledge-base retrieval.",
"keywords": [
"alibaba-cloud",
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-cli-runtime",
"version": "2.10.5",
"version": "2.11.0",
"description": "Runtime framework for bailian-cli (createCli, registry, args, output, pipeline). See https://www.npmjs.com/package/bailian-cli for usage.",
"homepage": "https://bailian.console.aliyun.com/cli",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion skills/bailian-cli/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: bailian-cli
metadata:
version: "2.10.5"
version: "2.11.0"
requires:
bins: ["bl"]
description: >-
Expand Down
23 changes: 12 additions & 11 deletions skills/bailian-cli/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,18 @@ Use this index for the skill-scoped quick index and global flags.

Available on every command (in addition to command-specific flags):

| Flag | Type | Required | Description |
| ----------------------- | ------ | -------- | --------------------------------------------------------- |
| `--introspect` | switch | no | Print the machine-readable command schema (JSON) and exit |
| `--output <text\|json>` | string | no | Output format: text, json |
| `--timeout <seconds>` | number | no | Request timeout |
| `--quiet` | switch | no | Suppress non-essential output |
| `--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 |
| `--help` | switch | no | Show help |
| `--version` | switch | no | Print version |
| Flag | Type | Required | Description |
| ----------------------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `--introspect` | switch | no | Print the machine-readable command schema (JSON) and exit |
| `--output <text\|json>` | string | no | Output format: text, json |
| `--timeout <seconds>` | number | no | Request timeout |
| `--quiet` | switch | no | Suppress non-essential output |
| `--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 |
| `--help` | switch | no | Show help |
| `--version` | switch | no | Print version |

## Model auth flags

Expand Down
2 changes: 1 addition & 1 deletion skills/bailian-finetune/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: bailian-finetune
metadata:
version: "2.10.5"
version: "2.11.0"
requires:
bins: ["bl"]
description: >-
Expand Down
Loading