bfi-cli 0.1.96 → 0.1.97

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/dist/cli.mjs CHANGED
@@ -7162,7 +7162,6 @@ async function handleInstall(args, api, globalOpts) {
7162
7162
  console.error(`${RED$1}获取包信息失败:${error.message}${RESET$3}`);
7163
7163
  process.exit(1);
7164
7164
  }
7165
- if (pkgInfo.kind === "PLUGIN") throw new Error("这是完整插件,不是技能组合;请使用 --as plugin --agent <目标Agent> 安装,插件可能包含 MCP 和 Hooks。");
7166
7165
  const skills = pkgInfo.skills || [];
7167
7166
  if (skills.length === 0) {
7168
7167
  console.log(`${YELLOW$1}包中没有可独立安装的技能。${RESET$3}`);
@@ -7485,9 +7484,7 @@ async function handleUpdate(args, api, globalOpts) {
7485
7484
  console.log(`${DIM$3}正在更新 ${packagesToUpdate.length} 个包...${RESET$3}`);
7486
7485
  for (const pkg of packagesToUpdate) try {
7487
7486
  const pkgInfo = await api.getPackage(pkg.namespace, pkg.slug);
7488
- const info = pkgInfo.data || pkgInfo;
7489
- if (info.kind === "PLUGIN") throw new Error("这是完整插件,请使用 --as plugin --agent <目标Agent> 更新;不会按技能组合安装。");
7490
- const skills = info.skills || [];
7487
+ const skills = (pkgInfo.data || pkgInfo).skills || [];
7491
7488
  console.log(` ${DIM$3}更新 @${pkg.namespace}/${pkg.slug}(${skills.length} 个技能)...${RESET$3}`);
7492
7489
  for (const skill of skills) {
7493
7490
  const skillRef = skill.namespace ? `@${skill.namespace}/${skill.slug}` : skill.slug;
@@ -91,6 +91,30 @@ function resolveToken() {
91
91
  if (process.env.BFI_TOKEN) return process.env.BFI_TOKEN;
92
92
  return loadGlobalConfig()?.token ?? null;
93
93
  }
94
+ const BLOCKED_PREFIXES = [
95
+ "create_",
96
+ "delete_",
97
+ "update_",
98
+ "add_"
99
+ ];
100
+ const ARCHIVE_TOOL = {
101
+ name: "kb_archive_case",
102
+ description: `把诊断结论归档到「${CASE_KB_NAME}」知识库(唯一写通道)。content_md 建议结构:# 标题 / ## 现象 / ## 根因链 / ## 修复 / ## 证据与复现 / 指纹一行(供先验检索)。归档后先验检索即可命中,避免同类问题重复排查。`,
103
+ inputSchema: {
104
+ type: "object",
105
+ properties: {
106
+ title: {
107
+ type: "string",
108
+ description: "案例标题(症状+组件,如「OOM OCR 切图重复解码」)"
109
+ },
110
+ content_md: {
111
+ type: "string",
112
+ description: "案例正文(Markdown)"
113
+ }
114
+ },
115
+ required: ["title", "content_md"]
116
+ }
117
+ };
94
118
  function textResult(payload, isError = false) {
95
119
  return {
96
120
  content: [{
@@ -100,150 +124,8 @@ function textResult(payload, isError = false) {
100
124
  isError
101
125
  };
102
126
  }
103
- const TOOLS = [
104
- {
105
- name: "kb_search",
106
- description: "跨库语义检索 BFI 知识库(案例库/wiki/jira-支持案例/供应链/领域知识全部覆盖)——诊断先验的主通道:查历史同类问题、已解决方案、领域知识。返回最相关文段(hybrid)。",
107
- inputSchema: {
108
- type: "object",
109
- properties: {
110
- query: {
111
- type: "string",
112
- description: "检索问题(症状/组件/错误关键词组合均可)"
113
- },
114
- top_k: {
115
- type: "number",
116
- description: "返回条数(默认 5)"
117
- }
118
- },
119
- required: ["query"]
120
- }
121
- },
122
- {
123
- name: "kb_ask",
124
- description: "向知识库提问,返回合成答案与引用来源——需要结论而非文段列表时用。",
125
- inputSchema: {
126
- type: "object",
127
- properties: { question: {
128
- type: "string",
129
- description: "问题"
130
- } },
131
- required: ["question"]
132
- }
133
- },
134
- {
135
- name: "kb_grep",
136
- description: "按正则/关键词精确搜索知识库文本块(大小写不敏感)——已知确切关键词时用。",
137
- inputSchema: {
138
- type: "object",
139
- properties: {
140
- pattern: {
141
- type: "string",
142
- description: "正则或关键词"
143
- },
144
- kb: {
145
- type: "string",
146
- description: "知识库名或 id(可选,默认全部在 scope 库)"
147
- }
148
- },
149
- required: ["pattern"]
150
- }
151
- },
152
- {
153
- name: "kb_archive_case",
154
- description: `把诊断结论归档到「${CASE_KB_NAME}」知识库(唯一写通道)。content_md 建议结构:# 标题 / ## 现象 / ## 根因链 / ## 修复 / ## 证据与复现 / 指纹一行(供先验检索)。归档后先验检索即可命中,避免同类问题重复排查。`,
155
- inputSchema: {
156
- type: "object",
157
- properties: {
158
- title: {
159
- type: "string",
160
- description: "案例标题(症状+组件,如「OOM OCR 切图重复解码」)"
161
- },
162
- content_md: {
163
- type: "string",
164
- description: "案例正文(Markdown)"
165
- }
166
- },
167
- required: ["title", "content_md"]
168
- }
169
- },
170
- {
171
- name: "kb_list",
172
- description: "列出全部可访问知识库(id/名称/描述)。",
173
- inputSchema: {
174
- type: "object",
175
- properties: {}
176
- }
177
- },
178
- {
179
- name: "kb_docs",
180
- description: "列出一个知识库内的文档(分页)。",
181
- inputSchema: {
182
- type: "object",
183
- properties: { kb: {
184
- type: "string",
185
- description: "知识库名或 id"
186
- } },
187
- required: ["kb"]
188
- }
189
- },
190
- {
191
- name: "kb_read",
192
- description: "读一篇知识文档的元数据与正文分块。",
193
- inputSchema: {
194
- type: "object",
195
- properties: {
196
- doc_id: {
197
- type: "string",
198
- description: "文档 id"
199
- },
200
- kb: {
201
- type: "string",
202
- description: "知识库名或 id"
203
- }
204
- },
205
- required: ["doc_id"]
206
- }
207
- }
208
- ];
209
- async function callSemantic(remote, name, args) {
210
- const a = args ?? {};
211
- switch (name) {
212
- case "kb_search": return {
213
- tool: "search_knowledge",
214
- arguments: {
215
- query: a.query,
216
- match_count: Number(a.top_k ?? 5)
217
- }
218
- };
219
- case "kb_ask": return {
220
- tool: "ask",
221
- arguments: { question: a.question }
222
- };
223
- case "kb_grep": return {
224
- tool: "grep_chunks",
225
- arguments: {
226
- pattern: a.pattern,
227
- ...a.kb ? { kb_id: a.kb } : {}
228
- }
229
- };
230
- case "kb_list": return {
231
- tool: "list_knowledge_bases",
232
- arguments: {}
233
- };
234
- case "kb_docs": return {
235
- tool: "list_documents",
236
- arguments: { kb_id: a.kb }
237
- };
238
- case "kb_read": return {
239
- tool: "read_document",
240
- arguments: {
241
- knowledge_id: a.doc_id,
242
- ...a.kb ? { kb_id: a.kb } : {}
243
- }
244
- };
245
- default: return null;
246
- }
127
+ function isBlocked(name) {
128
+ return BLOCKED_PREFIXES.some((p) => name.startsWith(p));
247
129
  }
248
130
  function buildServer(remote) {
249
131
  const weknora = remote ?? new WeknoraRemote(process.env.WEKNORA_MCP_URL || DEFAULT_WEKNORA_URL, resolveToken);
@@ -253,15 +135,16 @@ function buildServer(remote) {
253
135
  }, {
254
136
  capabilities: { tools: {} },
255
137
  instructions: [
256
- `BFI 知识库/案例库通道(bfi cli 登录态鉴权,零配置)。知识库在 scope:`,
257
- `案例库(诊断案例归档,唯一写目标)+ wiki×4 + jira-支持案例 + 供应链/领域知识。`,
258
- `· 先验查询:kb_search(跨库语义检索,诊断前必查——历史同类问题/已解决方案)`,
259
- ` kb_ask(要结论不要文段时)/ kb_grep(确切关键词)`,
260
- `· 归档:kb_archive_case(诊断完成后把根因链+修复写回案例库,供下次先验命中)`,
261
- `· 阅读:kb_list/kb_docs/kb_read + wiki_*(生成 wiki 浏览)`
138
+ "BFI 知识库/案例库通道(bfi cli 登录态鉴权,零配置)。",
139
+ "先验查询:search_knowledge(跨库语义检索:案例库+wiki×4+jira-支持案例+领域知识,诊断前必查)",
140
+ "ask(合成答案+引用)/ grep_chunks(确切关键词)",
141
+ "归档:kb_archive_case(诊断完成后把根因链+修复写回案例库,供下次先验命中;唯一写通道)",
142
+ "阅读:list_knowledge_bases/list_documents/read_document + wiki_*"
262
143
  ].join("\n")
263
144
  });
264
- server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
145
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
146
+ return { tools: [...(await weknora.listTools()).filter((t) => !isBlocked(t.name)), ARCHIVE_TOOL] };
147
+ });
265
148
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
266
149
  const { name, arguments: args } = request.params;
267
150
  try {
@@ -275,19 +158,17 @@ function buildServer(remote) {
275
158
  }, true);
276
159
  const md = `# ${title}\n\n${content}\n`;
277
160
  return await weknora.callTool("add_document", {
278
- kb_id: CASE_KB_NAME,
161
+ knowledge_base_id: CASE_KB_NAME,
279
162
  title,
280
163
  content: md
281
164
  });
282
165
  }
283
- if (name === "wiki_index" || name === "wiki_read_page" || name === "wiki_search") return await weknora.callTool(name, args ?? {});
284
- const mapped = await callSemantic(weknora, name, args);
285
- if (!mapped) return textResult({
166
+ if (isBlocked(name)) return textResult({
286
167
  ok: false,
287
- error_kind: "unknown_tool",
288
- message: `未知工具:${name}`
168
+ error_kind: "write_blocked",
169
+ message: `写类工具 ${name} 不透传。诊断归档请用 kb_archive_case(自动写入案例库)`
289
170
  }, true);
290
- return await weknora.callTool(mapped.tool, mapped.arguments);
171
+ return await weknora.callTool(name, args ?? {});
291
172
  } catch (e) {
292
173
  return textResult({
293
174
  ok: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bfi-cli",
3
- "version": "0.1.96",
3
+ "version": "0.1.97",
4
4
  "description": "用友大业财BFI统一命令行工具,支持技能,技能包,元数据,UI元数据等",
5
5
  "type": "module",
6
6
  "bin": {