Skip to content

Commit 1603520

Browse files
baifuyoucz-cli
authored andcommitted
refactor(analytics-agent): remove structured knowledge entry commands
Drop the top-level `knowledge list/get/create/update/delete` subcommands along with their routes and helpers, keeping the space/node/folder/file command surface. Update the spec and tests to match. Co-Authored-By: cz-cli <noreply@clickzetta.com>
1 parent 02117cf commit 1603520

4 files changed

Lines changed: 1 addition & 476 deletions

File tree

openspec/specs/analytics-agent-knowledge/spec.md

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# analytics-agent-knowledge 规格说明
22

33
## Purpose
4-
定义 `analytics-agent knowledge` 命令组的第一批能力,包括结构化知识 CRUD、知识空间查询/创建,以及文档知识的 folder/file 基础命令面。
4+
定义 `analytics-agent knowledge` 命令组的能力,包括知识空间查询/创建,以及文档知识的 folder/file 基础命令面。
55

66
## Requirements
77

@@ -23,60 +23,6 @@ When the active profile already provides Analytics Agent specific `agent` contex
2323
- **THEN** CLI MUST fall back to the existing Studio context resolution path
2424
- **AND** the existing non-agent command behavior MUST remain unchanged
2525

26-
### Requirement: 结构化知识 CRUD
27-
28-
CLI MUST provide `analytics-agent knowledge list/create/update/delete` for structured knowledge entries by calling open analytics-agent knowledge endpoints.
29-
30-
#### Scenario: 列出结构化知识
31-
32-
- **WHEN** 用户执行 `cz-cli analytics-agent knowledge list`
33-
- **THEN** CLI MUST call the open knowledge list endpoint
34-
- **AND** the primary output MUST expose user-facing fields including knowledge id, aliases, type, status, and bound domain ids when present
35-
36-
#### Scenario: 创建文本知识
37-
38-
- **WHEN** 用户执行 `cz-cli analytics-agent knowledge create --alias <alias> --content <text>`
39-
- **THEN** CLI MUST call the open knowledge create endpoint with a text-knowledge payload
40-
- **AND** the request MUST map `--content` to the stored text content field
41-
- **AND** the success output MUST include the created knowledge id and aliases
42-
43-
#### Scenario: 从本地文件创建文本知识
44-
45-
- **WHEN** 用户执行 `cz-cli analytics-agent knowledge create --alias <alias> --file <local-path>`
46-
- **THEN** CLI MUST read the local file content before sending the request
47-
- **AND** CLI MUST call the open knowledge create endpoint with the loaded text content
48-
- **AND** the success output MUST include the created knowledge id and aliases
49-
50-
#### Scenario: 更新文本知识
51-
52-
- **WHEN** 用户执行 `cz-cli analytics-agent knowledge update <knowledge-id> --alias <alias> --content <text>`
53-
- **THEN** CLI MUST call the open knowledge update endpoint for that id
54-
- **AND** the request MUST preserve the knowledge id in the path rather than the JSON body only
55-
56-
#### Scenario: 获取结构化知识详情
57-
58-
- **WHEN** 用户执行 `cz-cli analytics-agent knowledge get <knowledge-id>`
59-
- **THEN** CLI MUST call the open knowledge detail endpoint for that id
60-
- **AND** the primary output MUST include the knowledge id, aliases, type, and content or dictionary payload
61-
62-
#### Scenario: 删除结构化知识
63-
64-
- **WHEN** 用户执行 `cz-cli analytics-agent knowledge delete <knowledge-id>`
65-
- **THEN** CLI MUST call the open knowledge delete endpoint for that id
66-
- **AND** the command MUST succeed on the backend no-data success shape
67-
68-
#### Scenario: 创建知识缺少内容
69-
70-
- **WHEN** 用户执行 `cz-cli analytics-agent knowledge create --alias <alias>` without `--content` and without `--dictionary`
71-
- **THEN** CLI MUST reject the request before sending it
72-
- **AND** the error message MUST explain that text knowledge requires content
73-
74-
#### Scenario: 从本地文件创建知识时文件不存在
75-
76-
- **WHEN** 用户执行 `cz-cli analytics-agent knowledge create --alias <alias> --file <missing-path>`
77-
- **THEN** CLI MUST reject the request before sending it
78-
- **AND** the error message MUST explain that the local path does not exist
79-
8026
### Requirement: 知识空间查询与维护
8127

8228
CLI MUST provide `analytics-agent knowledge space list/create/rename/delete` for document knowledge spaces.

packages/cz-cli/src/commands/analytics-agent.ts

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ const ROUTES = {
6060
columnVirtualSet: { method: "POST", path: (argv: Record<string, unknown>) => `/open/api/v1/analytics-agent/datasets/${encodePath(argv["dataset-id"])}/virtual-columns` },
6161
columnVirtualList: { method: "GET", path: (argv: Record<string, unknown>) => `/open/api/v1/analytics-agent/datasets/${encodePath(argv["dataset-id"])}/virtual-columns` },
6262
columnVirtualDelete: { method: "DELETE", path: (argv: Record<string, unknown>) => `/open/api/v1/analytics-agent/datasets/${encodePath(argv["dataset-id"])}/virtual-columns/${encodePath(argv["attr-id"])}` },
63-
knowledgeEntryList: { method: "GET", path: "/open/api/v1/analytics-agent/knowledge/entries" },
64-
knowledgeEntryDetail: { method: "GET", path: (argv: Record<string, unknown>) => `/open/api/v1/analytics-agent/knowledge/entries/${encodePath(argv["knowledge-id"])}` },
65-
knowledgeEntryCreate: { method: "POST", path: "/open/api/v1/analytics-agent/knowledge/entries" },
66-
knowledgeEntryUpdate: { method: "PUT", path: (argv: Record<string, unknown>) => `/open/api/v1/analytics-agent/knowledge/entries/${encodePath(argv["knowledge-id"])}` },
67-
knowledgeEntryDelete: { method: "DELETE", path: (argv: Record<string, unknown>) => `/open/api/v1/analytics-agent/knowledge/entries/${encodePath(argv["knowledge-id"])}` },
6863
knowledgeSpaceList: { method: "GET", path: "/open/api/v1/analytics-agent/knowledge/spaces" },
6964
knowledgeSpaceCreate: { method: "POST", path: "/open/api/v1/analytics-agent/knowledge/spaces" },
7065
knowledgeSpaceRename: { method: "PUT", path: (argv: Record<string, unknown>) => `/open/api/v1/analytics-agent/knowledge/spaces/${encodePath(argv["space-id"])}` },
@@ -1199,33 +1194,6 @@ async function executeKnowledgeNodeDomainCommand(
11991194
}
12001195
}
12011196

1202-
function knowledgeEntryBody(argv: Record<string, unknown>): Record<string, unknown> {
1203-
const format = typeof argv.format === "string" ? argv.format : "json"
1204-
return mergeBody({}, {
1205-
aliases: stringArray(argv.alias),
1206-
content: argv.content,
1207-
dictionary: parseOptionalJsonObject(argv.dictionary as string | undefined, "--dictionary"),
1208-
type: argv.type,
1209-
domainIds: positiveIntegerArray(argv["domain-id"], "--domain-id", format),
1210-
})
1211-
}
1212-
1213-
async function knowledgeCreateBody(argv: Record<string, unknown>): Promise<Record<string, unknown>> {
1214-
const format = typeof argv.format === "string" ? argv.format : "json"
1215-
const content = typeof argv.content === "string"
1216-
? argv.content
1217-
: typeof argv.file === "string"
1218-
? await Bun.file((await collectKnowledgeLocalFile(argv.file)).absolutePath).text()
1219-
: undefined
1220-
return mergeBody({}, {
1221-
aliases: stringArray(argv.alias),
1222-
content,
1223-
dictionary: parseOptionalJsonObject(argv.dictionary as string | undefined, "--dictionary"),
1224-
type: argv.type,
1225-
domainIds: positiveIntegerArray(argv["domain-id"], "--domain-id", format),
1226-
})
1227-
}
1228-
12291197
function normalizedRemotePath(pathValue: string | undefined): string {
12301198
if (!pathValue) return ""
12311199
const normalized = pathValue.replaceAll("\\", "/").split("/").filter(Boolean).join("/")
@@ -2613,87 +2581,6 @@ export function registerAnalyticsAgentCommand(cli: Argv<GlobalArgs>): void {
26132581
})
26142582
.command("knowledge", "Manage Analytics Agent knowledge", (knowledge) => {
26152583
knowledge
2616-
.command(
2617-
"list",
2618-
"List structured knowledge entries",
2619-
(y) =>
2620-
y
2621-
.option("keyword", { type: "string", describe: "Keyword for fuzzy search" })
2622-
.option("domain-id", { type: "number", describe: "Bound domain ID" })
2623-
.option("type", { type: "string", choices: ["text", "dictionary"], describe: "Knowledge type" })
2624-
.option("page-num", { type: "number", describe: "Page number" })
2625-
.option("page-size", { type: "number", describe: "Page size" }),
2626-
async (argv) => {
2627-
await executeAnalyticsCommand("analytics-agent knowledge list", argv as Record<string, unknown>, ROUTES.knowledgeEntryList, {}, {
2628-
keyword: argv.keyword,
2629-
domainId: argv["domain-id"],
2630-
type: argv.type,
2631-
pageNum: argv["page-num"],
2632-
pageSize: argv["page-size"],
2633-
})
2634-
},
2635-
)
2636-
.command(
2637-
"get <knowledge-id>",
2638-
"Show structured knowledge detail",
2639-
(y) => y.positional("knowledge-id", { type: "number", demandOption: true, describe: "Knowledge ID" }),
2640-
async (argv) => {
2641-
await executeAnalyticsCommand("analytics-agent knowledge get", argv as Record<string, unknown>, ROUTES.knowledgeEntryDetail, {})
2642-
},
2643-
)
2644-
.command(
2645-
"create",
2646-
"Create structured knowledge",
2647-
(y) =>
2648-
y
2649-
.option("alias", { type: "string", array: true, describe: "Knowledge alias, can be repeated" })
2650-
.option("content", { type: "string", describe: "Text knowledge content" })
2651-
.option("file", { type: "string", describe: "Local file path to load as text knowledge content" })
2652-
.option("dictionary", { type: "string", describe: "Dictionary JSON object" })
2653-
.option("type", { type: "string", choices: ["text", "dictionary"], describe: "Knowledge type" })
2654-
.option("domain-id", { type: "number", array: true, describe: "Bound domain ID, can be repeated" }),
2655-
async (argv) => {
2656-
const type = typeof argv.type === "string" ? argv.type : "text"
2657-
if (type === "dictionary" && !argv.dictionary) {
2658-
handledError("USAGE_ERROR", "dictionary knowledge requires --dictionary", { format: typeof argv.format === "string" ? argv.format : "json" })
2659-
}
2660-
if (type !== "dictionary" && !argv.content && !argv.file && !argv.dictionary) {
2661-
handledError("USAGE_ERROR", "text knowledge requires --content or --file", { format: typeof argv.format === "string" ? argv.format : "json" })
2662-
}
2663-
let body: Record<string, unknown>
2664-
try {
2665-
body = await knowledgeCreateBody(argv as Record<string, unknown>)
2666-
} catch (err) {
2667-
handledError("ANALYTICS_AGENT_ERROR", err instanceof Error ? err.message : String(err), {
2668-
format: typeof argv.format === "string" ? argv.format : "json",
2669-
})
2670-
}
2671-
await executeAnalyticsCommand("analytics-agent knowledge create", argv as Record<string, unknown>, ROUTES.knowledgeEntryCreate, body)
2672-
},
2673-
)
2674-
.command(
2675-
"update <knowledge-id>",
2676-
"Update structured knowledge",
2677-
(y) =>
2678-
y
2679-
.positional("knowledge-id", { type: "number", demandOption: true, describe: "Knowledge ID" })
2680-
.option("alias", { type: "string", array: true, describe: "Knowledge alias, can be repeated" })
2681-
.option("content", { type: "string", describe: "Text knowledge content" })
2682-
.option("dictionary", { type: "string", describe: "Dictionary JSON object" })
2683-
.option("type", { type: "string", choices: ["text", "dictionary"], describe: "Knowledge type" })
2684-
.option("domain-id", { type: "number", array: true, describe: "Bound domain ID, can be repeated" }),
2685-
async (argv) => {
2686-
await executeAnalyticsCommand("analytics-agent knowledge update", argv as Record<string, unknown>, ROUTES.knowledgeEntryUpdate, knowledgeEntryBody(argv as Record<string, unknown>))
2687-
},
2688-
)
2689-
.command(
2690-
"delete <knowledge-id>",
2691-
"Delete structured knowledge",
2692-
(y) => y.positional("knowledge-id", { type: "number", demandOption: true, describe: "Knowledge ID" }),
2693-
async (argv) => {
2694-
await executeAnalyticsCommand("analytics-agent knowledge delete", argv as Record<string, unknown>, ROUTES.knowledgeEntryDelete, {})
2695-
},
2696-
)
26972584
.command(
26982585
"space",
26992586
"Manage knowledge spaces",

0 commit comments

Comments
 (0)