@saber2pr/ai-agent 0.0.30 → 0.0.32

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.
@@ -19,6 +19,7 @@ const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
19
19
  const builtin_1 = require("../tools/builtin");
20
20
  const convertToLangChainTool_1 = require("../utils/convertToLangChainTool");
21
21
  const jsonSchemaToZod_1 = require("../utils/jsonSchemaToZod");
22
+ const formatSchema_1 = require("../utils/formatSchema");
22
23
  exports.CONFIG_FILE = path_1.default.join(os_1.default.homedir(), ".saber2pr-agent.json");
23
24
  // ✅ 全局设置:修复 AbortSignal 监听器数量警告
24
25
  // LangChain 的 HTTP 客户端会创建多个 AbortSignal,需要增加默认限制
@@ -91,8 +92,7 @@ class McpGraphAgent {
91
92
  const schema = tool.schema;
92
93
  if (schema && schema.shape) {
93
94
  // 如果是 ZodObject,打印其内部 key
94
- const keys = Object.keys(schema.shape);
95
- console.log(` 参数结构: [ ${keys.join(", ")} ]`);
95
+ console.log(` 参数结构:\n${(0, formatSchema_1.formatSchema)(schema)}`);
96
96
  }
97
97
  else if (schema && schema._def) {
98
98
  // 兼容其他 Zod 类型
@@ -365,13 +365,19 @@ class McpGraphAgent {
365
365
  进度:{doneCount}/{targetCount}
366
366
  已审计文件:{auditedList}
367
367
 
368
- # 格式要求
368
+ # 🛠️ 工具调用规范
369
369
  1. Arguments 必须是纯粹的 JSON 对象,严禁将其作为字符串放入引号中。
370
370
  2. 严禁对 JSON 内容进行二次转义。
371
+ 3. **禁止空操作**:如果你认为任务已完成或不需要调用工具,请不要输出任何 Action 结构。严禁使用 "None"、"null" 或空字符串作为工具名称。
371
372
 
372
- # 指令
373
- 1. 避免陷入在同一个文件上的无限循环尝试。
374
- 2. 不要重复调用相同的工具和参数,如果工具已经返回结果,请基于结果继续工作而不是再次调用。{recentToolCalls}
373
+ # 🎯 核心指令
374
+ 1. **任务终结判定**:当你已经读取了用户要求的文件、回答了问题或完成了审计目标时,必须立即提供最终回复。
375
+ 2. **回复格式**:任务完成时,请以 "Final Answer:" 开头进行总结,此时不再调用任何工具。
376
+ 3. **避免重复**:不要重复调用相同的工具和参数。如果工具返回错误,请分析原因(如参数 Schema 错误)而不是盲目重试。{recentToolCalls}
377
+
378
+ # 📝 审计任务专项
379
+ 1. 避免在同一个文件上陷入无限循环尝试。
380
+ 2. 优先通过 \`list_directory\` 了解全局,再深入具体文件。
375
381
  {extraPrompt}`;
376
382
  // 2. 核心逻辑:处理消息上下文
377
383
  let inputMessages;
@@ -13,8 +13,8 @@ const lib_1 = require("./lib");
13
13
  // Schema definitions
14
14
  const ReadTextFileArgsSchema = zod_1.z.object({
15
15
  path: zod_1.z.string(),
16
- tail: zod_1.z.number().nullable().describe('If provided, returns only the last N lines of the file'),
17
- head: zod_1.z.number().nullable().describe('If provided, returns only the first N lines of the file')
16
+ tail: zod_1.z.number().optional().describe('If provided, returns only the last N lines of the file'),
17
+ head: zod_1.z.number().optional().describe('If provided, returns only the first N lines of the file')
18
18
  });
19
19
  const ReadMultipleFilesArgsSchema = zod_1.z.object({
20
20
  paths: zod_1.z
@@ -33,7 +33,7 @@ const EditOperation = zod_1.z.object({
33
33
  const EditFileArgsSchema = zod_1.z.object({
34
34
  path: zod_1.z.string(),
35
35
  edits: zod_1.z.array(EditOperation),
36
- dryRun: zod_1.z.boolean().nullable().default(false).describe('Preview changes using git-style diff format')
36
+ dryRun: zod_1.z.boolean().optional().default(false).describe('Preview changes using git-style diff format')
37
37
  });
38
38
  const CreateDirectoryArgsSchema = zod_1.z.object({
39
39
  path: zod_1.z.string(),
@@ -43,11 +43,11 @@ const ListDirectoryArgsSchema = zod_1.z.object({
43
43
  });
44
44
  const ListDirectoryWithSizesArgsSchema = zod_1.z.object({
45
45
  path: zod_1.z.string(),
46
- sortBy: zod_1.z.enum(['name', 'size']).nullable().default('name').describe('Sort entries by name or size'),
46
+ sortBy: zod_1.z.enum(['name', 'size']).optional().default('name').describe('Sort entries by name or size'),
47
47
  });
48
48
  const DirectoryTreeArgsSchema = zod_1.z.object({
49
49
  path: zod_1.z.string(),
50
- excludePatterns: zod_1.z.array(zod_1.z.string()).nullable().default([])
50
+ excludePatterns: zod_1.z.array(zod_1.z.string()).optional().default([])
51
51
  });
52
52
  const MoveFileArgsSchema = zod_1.z.object({
53
53
  source: zod_1.z.string(),
@@ -56,7 +56,7 @@ const MoveFileArgsSchema = zod_1.z.object({
56
56
  const SearchFilesArgsSchema = zod_1.z.object({
57
57
  path: zod_1.z.string(),
58
58
  pattern: zod_1.z.string(),
59
- excludePatterns: zod_1.z.array(zod_1.z.string()).nullable().default([])
59
+ excludePatterns: zod_1.z.array(zod_1.z.string()).optional().default([])
60
60
  });
61
61
  const GetFileInfoArgsSchema = zod_1.z.object({
62
62
  path: zod_1.z.string(),
@@ -0,0 +1,2 @@
1
+ import { z } from 'zod';
2
+ export declare function formatSchema(schema: z.ZodObject<any>): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatSchema = formatSchema;
7
+ const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
8
+ function formatSchema(schema) {
9
+ const res = (0, zod_to_json_schema_1.default)(schema);
10
+ if (typeof res.properties === 'object') {
11
+ const requiredKeys = res.required || [];
12
+ const lines = [];
13
+ for (const key in res.properties) {
14
+ lines.push(` - ${key}: ${res.properties[key].type}${requiredKeys.includes(key) ? " (required)" : ""}`);
15
+ }
16
+ if (lines.length > 0) {
17
+ return lines.join("\n");
18
+ }
19
+ return "No parameters";
20
+ }
21
+ const keys = Object.keys(schema.shape);
22
+ return keys.join(", ");
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saber2pr/ai-agent",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "AI Assistant CLI.",
5
5
  "author": "saber2pr",
6
6
  "license": "ISC",