@aigne/core 1.72.0-beta.3 → 1.72.0-beta.5

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/lib/cjs/agents/agent.d.ts +31 -1
  3. package/lib/cjs/agents/agent.js +13 -0
  4. package/lib/cjs/agents/ai-agent.d.ts +7 -0
  5. package/lib/cjs/agents/ai-agent.js +85 -3
  6. package/lib/cjs/agents/image-agent.d.ts +17 -1
  7. package/lib/cjs/agents/image-agent.js +16 -0
  8. package/lib/cjs/agents/image-model.d.ts +4 -4
  9. package/lib/cjs/agents/mcp-agent.d.ts +17 -0
  10. package/lib/cjs/agents/mcp-agent.js +18 -0
  11. package/lib/cjs/agents/team-agent.d.ts +55 -0
  12. package/lib/cjs/agents/team-agent.js +31 -0
  13. package/lib/cjs/agents/transform-agent.d.ts +12 -0
  14. package/lib/cjs/agents/transform-agent.js +13 -0
  15. package/lib/cjs/agents/video-model.d.ts +4 -4
  16. package/lib/cjs/loader/agent-yaml.d.ts +5 -67
  17. package/lib/cjs/loader/agent-yaml.js +4 -139
  18. package/lib/cjs/loader/agents.d.ts +4 -0
  19. package/lib/cjs/loader/agents.js +17 -0
  20. package/lib/cjs/loader/index.d.ts +18 -14
  21. package/lib/cjs/loader/index.js +20 -81
  22. package/lib/cjs/loader/schema.d.ts +21 -6
  23. package/lib/cjs/loader/schema.js +60 -1
  24. package/lib/cjs/prompt/prompt-builder.js +0 -1
  25. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  26. package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +63 -0
  27. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  28. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +61 -0
  29. package/lib/cjs/prompt/skills/afs/delete.js +15 -3
  30. package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
  31. package/lib/cjs/prompt/skills/afs/edit.js +85 -59
  32. package/lib/cjs/prompt/skills/afs/exec.js +17 -6
  33. package/lib/cjs/prompt/skills/afs/index.js +4 -1
  34. package/lib/cjs/prompt/skills/afs/list.js +26 -10
  35. package/lib/cjs/prompt/skills/afs/read.d.ts +6 -2
  36. package/lib/cjs/prompt/skills/afs/read.js +62 -15
  37. package/lib/cjs/prompt/skills/afs/rename.js +18 -4
  38. package/lib/cjs/prompt/skills/afs/search.js +21 -5
  39. package/lib/cjs/prompt/skills/afs/write.js +20 -6
  40. package/lib/cjs/prompt/template.d.ts +23 -23
  41. package/lib/dts/agents/agent.d.ts +31 -1
  42. package/lib/dts/agents/ai-agent.d.ts +7 -0
  43. package/lib/dts/agents/image-agent.d.ts +17 -1
  44. package/lib/dts/agents/image-model.d.ts +4 -4
  45. package/lib/dts/agents/mcp-agent.d.ts +17 -0
  46. package/lib/dts/agents/team-agent.d.ts +55 -0
  47. package/lib/dts/agents/transform-agent.d.ts +12 -0
  48. package/lib/dts/agents/video-model.d.ts +4 -4
  49. package/lib/dts/aigne/context.d.ts +2 -2
  50. package/lib/dts/loader/agent-yaml.d.ts +5 -67
  51. package/lib/dts/loader/agents.d.ts +4 -0
  52. package/lib/dts/loader/index.d.ts +18 -14
  53. package/lib/dts/loader/schema.d.ts +21 -6
  54. package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  55. package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  56. package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
  57. package/lib/dts/prompt/skills/afs/read.d.ts +6 -2
  58. package/lib/dts/prompt/template.d.ts +25 -25
  59. package/lib/esm/agents/agent.d.ts +31 -1
  60. package/lib/esm/agents/agent.js +13 -0
  61. package/lib/esm/agents/ai-agent.d.ts +7 -0
  62. package/lib/esm/agents/ai-agent.js +85 -3
  63. package/lib/esm/agents/image-agent.d.ts +17 -1
  64. package/lib/esm/agents/image-agent.js +16 -0
  65. package/lib/esm/agents/image-model.d.ts +4 -4
  66. package/lib/esm/agents/mcp-agent.d.ts +17 -0
  67. package/lib/esm/agents/mcp-agent.js +18 -0
  68. package/lib/esm/agents/team-agent.d.ts +55 -0
  69. package/lib/esm/agents/team-agent.js +31 -0
  70. package/lib/esm/agents/transform-agent.d.ts +12 -0
  71. package/lib/esm/agents/transform-agent.js +13 -0
  72. package/lib/esm/agents/video-model.d.ts +4 -4
  73. package/lib/esm/aigne/context.d.ts +2 -2
  74. package/lib/esm/loader/agent-yaml.d.ts +5 -67
  75. package/lib/esm/loader/agent-yaml.js +4 -138
  76. package/lib/esm/loader/agents.d.ts +4 -0
  77. package/lib/esm/loader/agents.js +14 -0
  78. package/lib/esm/loader/index.d.ts +18 -14
  79. package/lib/esm/loader/index.js +21 -81
  80. package/lib/esm/loader/schema.d.ts +21 -6
  81. package/lib/esm/loader/schema.js +57 -0
  82. package/lib/esm/prompt/prompt-builder.js +1 -2
  83. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
  84. package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +59 -0
  85. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
  86. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +53 -0
  87. package/lib/esm/prompt/skills/afs/delete.js +15 -3
  88. package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
  89. package/lib/esm/prompt/skills/afs/edit.js +85 -59
  90. package/lib/esm/prompt/skills/afs/exec.js +17 -6
  91. package/lib/esm/prompt/skills/afs/index.js +4 -1
  92. package/lib/esm/prompt/skills/afs/list.js +26 -10
  93. package/lib/esm/prompt/skills/afs/read.d.ts +6 -2
  94. package/lib/esm/prompt/skills/afs/read.js +62 -15
  95. package/lib/esm/prompt/skills/afs/rename.js +18 -4
  96. package/lib/esm/prompt/skills/afs/search.js +21 -5
  97. package/lib/esm/prompt/skills/afs/write.js +20 -6
  98. package/lib/esm/prompt/template.d.ts +25 -25
  99. package/package.json +5 -4
@@ -0,0 +1,13 @@
1
+ import type { AFS } from "@aigne/afs";
2
+ import { AgentSkill } from "./agent-skill.js";
3
+ export interface Skill {
4
+ path: string;
5
+ name: string;
6
+ description: string;
7
+ content: string;
8
+ }
9
+ export declare function loadSkill(path: string): Promise<Skill>;
10
+ export declare function loadSkills(paths: string[]): Promise<Skill[]>;
11
+ export declare function loadAgentSkillFromAFS({ afs, }: {
12
+ afs: AFS;
13
+ }): Promise<AgentSkill | undefined>;
@@ -0,0 +1,53 @@
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
+ import fm from "front-matter";
3
+ import { AgentSkill } from "./agent-skill.js";
4
+ function parseSkill(content, path) {
5
+ const meta = fm(content);
6
+ return {
7
+ path,
8
+ name: meta.attributes.name,
9
+ description: meta.attributes.description,
10
+ content: meta.body,
11
+ };
12
+ }
13
+ export async function loadSkill(path) {
14
+ const entry = nodejs.path.join(path, "SKILL.md");
15
+ const skill = await nodejs.fs.readFile(entry, "utf-8");
16
+ return parseSkill(skill, path);
17
+ }
18
+ export async function loadSkills(paths) {
19
+ const skills = [];
20
+ for (const path of paths) {
21
+ const skill = await loadSkill(path);
22
+ skills.push(skill);
23
+ }
24
+ return skills;
25
+ }
26
+ export async function loadAgentSkillFromAFS({ afs, }) {
27
+ const modules = await afs.listModules();
28
+ const filtered = modules.filter(({ module: m }) => "options" in m &&
29
+ typeof m.options === "object" &&
30
+ m.options &&
31
+ "agentSkills" in m.options &&
32
+ m.options.agentSkills === true);
33
+ if (!filtered.length)
34
+ return;
35
+ const skills = [];
36
+ for (const module of filtered) {
37
+ const data = (await afs.list(module.path, {
38
+ pattern: "**/SKILL.md",
39
+ })).data;
40
+ for (const entry of data) {
41
+ const { data: file } = await afs.read(entry.path);
42
+ if (typeof file?.content !== "string")
43
+ continue;
44
+ const skill = parseSkill(file.content, nodejs.path.dirname(entry.path));
45
+ skills.push(skill);
46
+ }
47
+ }
48
+ if (!skills.length)
49
+ return;
50
+ return new AgentSkill({
51
+ agentSkills: skills,
52
+ });
53
+ }
@@ -4,15 +4,27 @@ export class AFSDeleteAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_delete",
7
- description: "Permanently delete files or directories. Use when removing unwanted files or cleaning up temporary data.",
7
+ description: `Permanently delete files or directories from the Agentic File System (AFS)
8
+ - Removes files or directories at the specified AFS path
9
+ - Supports recursive deletion for directories with contents
10
+ - Use with caution as deletion is permanent
11
+
12
+ Usage:
13
+ - The path must be an absolute AFS path starting with "/" (e.g., "/docs/old-file.md", "/temp")
14
+ - This is NOT a local system file path - it operates within the AFS virtual file system
15
+ - To delete a directory, you MUST set recursive=true
16
+ - Deleting a non-empty directory without recursive=true will fail
17
+ - This operation cannot be undone`,
8
18
  ...options,
9
19
  inputSchema: z.object({
10
- path: z.string().describe("Absolute file or directory path to delete"),
20
+ path: z
21
+ .string()
22
+ .describe("Absolute AFS path to delete (e.g., '/docs/old-file.md', '/temp'). Must start with '/'"),
11
23
  recursive: z
12
24
  .boolean()
13
25
  .optional()
14
26
  .default(false)
15
- .describe("Allow directory deletion (default: false, required for directories)"),
27
+ .describe("MUST be set to true to delete directories. Default: false (files only)"),
16
28
  }),
17
29
  outputSchema: z.object({
18
30
  status: z.string(),
@@ -1,21 +1,17 @@
1
1
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
2
2
  import { AFSSkillBase } from "./base.js";
3
- export interface Patch {
4
- start_line: number;
5
- end_line: number;
6
- replace?: string;
7
- delete: boolean;
8
- }
9
3
  export interface AFSEditInput extends Message {
10
4
  path: string;
11
- patches: Patch[];
5
+ oldString: string;
6
+ newString: string;
7
+ replaceAll?: boolean;
12
8
  }
13
9
  export interface AFSEditOutput extends Message {
14
10
  status: string;
15
11
  tool: string;
16
12
  path: string;
17
13
  message: string;
18
- data: string;
14
+ snippet: string;
19
15
  }
20
16
  export interface AFSEditAgentOptions extends AgentOptions<AFSEditInput, AFSEditOutput> {
21
17
  afs: NonNullable<AgentOptions<AFSEditInput, AFSEditOutput>["afs"]>;
@@ -23,5 +19,6 @@ export interface AFSEditAgentOptions extends AgentOptions<AFSEditInput, AFSEditO
23
19
  export declare class AFSEditAgent extends AFSSkillBase<AFSEditInput, AFSEditOutput> {
24
20
  constructor(options: AFSEditAgentOptions);
25
21
  process(input: AFSEditInput, _options: AgentInvokeOptions): Promise<AFSEditOutput>;
26
- applyCustomPatches(text: string, patches: Patch[]): string;
22
+ private countOccurrences;
23
+ private extractSnippet;
27
24
  }
@@ -1,94 +1,120 @@
1
1
  import { z } from "zod";
2
2
  import { AFSSkillBase } from "./base.js";
3
+ const CONTEXT_LINES = 4; // Number of lines to show before and after the edit
3
4
  export class AFSEditAgent extends AFSSkillBase {
4
5
  constructor(options) {
5
6
  super({
6
7
  name: "afs_edit",
7
- description: "Apply precise line-based patches to modify file content. Use when making targeted changes without rewriting the entire file.",
8
+ description: `Performs exact string replacements in files within the Agentic File System (AFS).
9
+
10
+ Usage:
11
+ - You must use afs_read at least once before editing to understand the file content
12
+ - The path must be an absolute AFS path starting with "/" (e.g., "/docs/readme.md")
13
+ - Preserve exact indentation (tabs/spaces) as it appears in the file
14
+ - The edit will FAIL if oldString is not found in the file
15
+ - The edit will FAIL if oldString appears multiple times (unless replaceAll is true)
16
+ - Use replaceAll to replace/rename strings across the entire file`,
8
17
  ...options,
9
18
  inputSchema: z.object({
10
- path: z.string().describe("Absolute file path to edit"),
11
- patches: z
12
- .array(z.object({
13
- start_line: z.number().int().describe("Start line number (0-based, inclusive)"),
14
- end_line: z.number().int().describe("End line number (0-based, exclusive)"),
15
- replace: z.string().optional().describe("New content to replace the line range"),
16
- delete: z.boolean().describe("Delete mode: true to delete lines, false to replace"),
17
- }))
18
- .min(1)
19
- .describe("List of patches to apply sequentially"),
19
+ path: z
20
+ .string()
21
+ .describe("Absolute AFS path to the file to edit (e.g., '/docs/readme.md'). Must start with '/'"),
22
+ oldString: z
23
+ .string()
24
+ .describe("The exact text to replace. Must match file content exactly including whitespace"),
25
+ newString: z
26
+ .string()
27
+ .describe("The text to replace it with (must be different from oldString)"),
28
+ replaceAll: z
29
+ .boolean()
30
+ .optional()
31
+ .default(false)
32
+ .describe("Replace all occurrences of oldString (default: false)"),
20
33
  }),
21
34
  outputSchema: z.object({
22
35
  status: z.string(),
23
36
  tool: z.string(),
24
37
  path: z.string(),
25
38
  message: z.string(),
26
- data: z.string(),
39
+ snippet: z.string(),
27
40
  }),
28
41
  });
29
42
  }
30
43
  async process(input, _options) {
31
44
  if (!this.afs)
32
45
  throw new Error("AFS is not configured for this agent.");
33
- if (!input.patches?.length) {
34
- throw new Error("No patches provided for afs_edit.");
46
+ const { path, oldString, newString, replaceAll = false } = input;
47
+ if (oldString === newString) {
48
+ throw new Error("oldString and newString must be different");
35
49
  }
36
- const readResult = await this.afs.read(input.path);
50
+ const readResult = await this.afs.read(path);
37
51
  if (!readResult.data?.content || typeof readResult.data.content !== "string") {
38
- throw new Error(`Cannot read file content from: ${input.path}`);
52
+ throw new Error(`Cannot read file content from: ${path}`);
39
53
  }
40
54
  const originalContent = readResult.data.content;
41
- const updatedContent = this.applyCustomPatches(originalContent, input.patches);
42
- await this.afs.write(input.path, {
55
+ // Check if oldString exists in the file
56
+ const occurrences = this.countOccurrences(originalContent, oldString);
57
+ if (occurrences === 0) {
58
+ throw new Error(`oldString not found in file: ${path}`);
59
+ }
60
+ if (occurrences > 1 && !replaceAll) {
61
+ throw new Error(`oldString appears ${occurrences} times in file. Use replaceAll=true to replace all occurrences, or provide more context to make oldString unique.`);
62
+ }
63
+ // Find the position of the first occurrence for snippet extraction
64
+ const firstOccurrenceIndex = originalContent.indexOf(oldString);
65
+ // Perform the replacement
66
+ const updatedContent = replaceAll
67
+ ? originalContent.split(oldString).join(newString)
68
+ : originalContent.replace(oldString, newString);
69
+ await this.afs.write(path, {
43
70
  content: updatedContent,
44
71
  });
72
+ // Generate snippet around the edit location
73
+ const snippet = this.extractSnippet(updatedContent, firstOccurrenceIndex, newString.length);
74
+ const replacementCount = replaceAll ? occurrences : 1;
45
75
  return {
46
76
  status: "success",
47
77
  tool: "afs_edit",
48
- path: input.path,
49
- message: `Applied ${input.patches.length} patches to ${input.path}`,
50
- data: updatedContent,
78
+ path,
79
+ message: `Replaced ${replacementCount} occurrence${replacementCount > 1 ? "s" : ""} in ${path}`,
80
+ snippet,
51
81
  };
52
82
  }
53
- applyCustomPatches(text, patches) {
54
- // Sort by start_line to ensure sequential application
55
- const sorted = [...patches].sort((a, b) => a.start_line - b.start_line);
56
- const lines = text.split("\n");
57
- for (let i = 0; i < sorted.length; i++) {
58
- const patch = sorted[i];
59
- if (!patch)
60
- continue;
61
- const start = patch.start_line;
62
- const end = patch.end_line;
63
- const deleteCount = end - start; // [start, end) range
64
- let delta = 0;
65
- if (patch.delete) {
66
- // Delete mode: remove the specified lines [start, end)
67
- lines.splice(start, deleteCount);
68
- delta = -deleteCount;
69
- }
70
- else {
71
- // Replace mode: replace the specified lines with new content
72
- const replaceLines = patch.replace ? patch.replace.split("\n") : [];
73
- lines.splice(start, deleteCount, ...replaceLines);
74
- delta = replaceLines.length - deleteCount;
75
- }
76
- // Update subsequent patches' line numbers
77
- // For exclusive-end semantics [start, end), we adjust patches that start >= current patch's start_line
78
- // after the current patch has been applied
79
- if (delta !== 0) {
80
- for (let j = i + 1; j < sorted.length; j++) {
81
- const next = sorted[j];
82
- if (!next)
83
- continue;
84
- // Adjust patches that start at or after the current patch's end line
85
- if (next.start_line >= patch.end_line) {
86
- next.start_line += delta;
87
- next.end_line += delta;
88
- }
89
- }
83
+ countOccurrences(text, search) {
84
+ let count = 0;
85
+ let position = text.indexOf(search);
86
+ while (position !== -1) {
87
+ count++;
88
+ position = text.indexOf(search, position + search.length);
89
+ }
90
+ return count;
91
+ }
92
+ extractSnippet(content, editStartIndex, newStringLength) {
93
+ const lines = content.split("\n");
94
+ // Find the line number where the edit starts
95
+ let charCount = 0;
96
+ let editStartLine = 0;
97
+ for (let i = 0; i < lines.length; i++) {
98
+ const lineLength = (lines[i]?.length ?? 0) + 1; // +1 for newline
99
+ if (charCount + lineLength > editStartIndex) {
100
+ editStartLine = i;
101
+ break;
90
102
  }
103
+ charCount += lineLength;
91
104
  }
92
- return lines.join("\n");
105
+ // Calculate how many lines the new content spans
106
+ const newContentLines = content
107
+ .substring(editStartIndex, editStartIndex + newStringLength)
108
+ .split("\n").length;
109
+ const editEndLine = editStartLine + newContentLines - 1;
110
+ // Extract lines with context
111
+ const startLine = Math.max(0, editStartLine - CONTEXT_LINES);
112
+ const endLine = Math.min(lines.length - 1, editEndLine + CONTEXT_LINES);
113
+ // Format with line numbers (1-based)
114
+ const snippetLines = lines.slice(startLine, endLine + 1).map((line, idx) => {
115
+ const lineNum = startLine + idx + 1;
116
+ return `${String(lineNum).padStart(4)}| ${line}`;
117
+ });
118
+ return snippetLines.join("\n");
93
119
  }
94
120
  }
@@ -4,14 +4,25 @@ export class AFSExecAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_exec",
7
- description: `
8
- Execute files marked as executable in the Agentic File System (AFS).
9
- Use this to run executable files registered at a given path with specified arguments.
10
- `.trim(),
7
+ description: `Execute files marked as executable in the Agentic File System (AFS)
8
+ - Runs executable entries (functions, agents, skills) registered at a given AFS path
9
+ - Passes arguments to the executable and returns its output
10
+ - Use this to invoke dynamic functionality stored in AFS
11
+
12
+ Usage:
13
+ - The path must be an absolute AFS path to an executable entry (e.g., "/skills/summarize", "/agents/translator")
14
+ - This is NOT a local system file path - it operates within the AFS virtual file system
15
+ - Use afs_list to discover available executables (look for entries with execute metadata)
16
+ - Arguments must be a valid JSON string matching the executable's input schema
17
+ - The executable's input/output schema can be found in its metadata`,
11
18
  ...options,
12
19
  inputSchema: z.object({
13
- path: z.string().describe("Absolute path to the executable file in AFS"),
14
- args: z.string().describe("JSON string of arguments matching the function's input schema"),
20
+ path: z
21
+ .string()
22
+ .describe("Absolute AFS path to the executable (e.g., '/skills/summarize'). Must start with '/'"),
23
+ args: z
24
+ .string()
25
+ .describe('JSON string of arguments matching the executable\'s input schema (e.g., \'{"text": "hello"}\')'),
15
26
  }),
16
27
  outputSchema: z.object({
17
28
  data: z.record(z.any()),
@@ -1,3 +1,5 @@
1
+ import { isNonNullable } from "../../../utils/type-utils.js";
2
+ import { loadAgentSkillFromAFS } from "./agent-skill/skill-loader.js";
1
3
  import { AFSDeleteAgent } from "./delete.js";
2
4
  import { AFSEditAgent } from "./edit.js";
3
5
  import { AFSExecAgent } from "./exec.js";
@@ -16,5 +18,6 @@ export async function getAFSSkills(afs) {
16
18
  new AFSDeleteAgent({ afs }),
17
19
  new AFSRenameAgent({ afs }),
18
20
  new AFSExecAgent({ afs }),
19
- ];
21
+ await loadAgentSkillFromAFS({ afs }),
22
+ ].filter(isNonNullable);
20
23
  }
@@ -4,26 +4,42 @@ export class AFSListAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_list",
7
- description: "Browse directory structure as a tree view. Use when exploring directory contents or understanding file organization.",
7
+ description: `List contents within the Agentic File System (AFS)
8
+ - Returns files and directories at the specified AFS path
9
+ - Supports recursive listing with configurable depth
10
+ - Supports glob pattern filtering to match specific files
11
+ - By default respects .gitignore rules to filter out ignored files
12
+ - Use this tool when you need to explore AFS contents or understand file organization
13
+
14
+ Usage:
15
+ - The path must be an absolute AFS path starting with "/" (e.g., "/", "/docs", "/memory/user")
16
+ - This is NOT a local system file path - it operates within the AFS virtual file system
17
+ - Use maxDepth to control recursion depth (default: 1, current directory only)
18
+ - Use pattern to filter entries by glob pattern:
19
+ - "*.ts" - match TypeScript files in current directory
20
+ - "**/*.js" - match all JavaScript files recursively
21
+ - "src/**/*.{ts,tsx}" - match TypeScript files in src directory
22
+ - Results are filtered by .gitignore by default; set disableGitignore to include ignored files`,
8
23
  ...options,
9
24
  inputSchema: z.object({
10
- path: z.string().describe("Absolute directory path to browse"),
25
+ path: z
26
+ .string()
27
+ .describe("Absolute AFS path to list (e.g., '/', '/docs', '/memory/user'). Must start with '/'"),
11
28
  options: z
12
29
  .object({
13
- maxDepth: z.number().optional().describe("Tree depth limit (default: 1)"),
30
+ maxDepth: z
31
+ .number()
32
+ .optional()
33
+ .describe("Maximum depth of directory recursion. 1 = current directory only, 2 = include subdirectories, etc. Default: 1"),
14
34
  disableGitignore: z
15
35
  .boolean()
16
36
  .optional()
17
- .describe("Disable .gitignore filtering, default is enabled"),
37
+ .describe("Set to true to include files normally ignored by .gitignore rules. Default: false (respects .gitignore)"),
18
38
  maxChildren: z
19
39
  .number()
20
40
  .optional()
21
- .describe("Maximum number of children to list per directory"),
22
- format: z
23
- .union([z.literal("simple-list"), z.literal("tree")])
24
- .optional()
25
- .default("simple-list")
26
- .describe("Output format, either 'simple-list', or 'tree', default is 'simple-list'"),
41
+ .describe("Maximum number of entries to return per directory. Useful for large directories to avoid overwhelming output"),
42
+ pattern: z.string().optional().describe("Glob pattern to filter entries by path"),
27
43
  })
28
44
  .optional(),
29
45
  }),
@@ -3,15 +3,19 @@ import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/
3
3
  import { AFSSkillBase } from "./base.js";
4
4
  export interface AFSReadInput extends Message {
5
5
  path: string;
6
- withLineNumbers?: boolean;
6
+ offset?: number;
7
+ limit?: number;
7
8
  }
8
9
  export interface AFSReadOutput extends Message {
9
10
  status: string;
10
11
  tool: string;
11
12
  path: string;
12
- withLineNumbers?: boolean;
13
13
  data?: AFSEntry;
14
14
  message?: string;
15
+ totalLines?: number;
16
+ returnedLines?: number;
17
+ truncated?: boolean;
18
+ offset?: number;
15
19
  }
16
20
  export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadOutput> {
17
21
  afs: NonNullable<AgentOptions<AFSReadInput, AFSReadOutput>["afs"]>;
@@ -1,25 +1,50 @@
1
1
  import { z } from "zod";
2
2
  import { AFSSkillBase } from "./base.js";
3
+ const DEFAULT_LINE_LIMIT = 2000;
4
+ const MAX_LINE_LENGTH = 2000;
3
5
  export class AFSReadAgent extends AFSSkillBase {
4
6
  constructor(options) {
5
7
  super({
6
8
  name: "afs_read",
7
- description: "Read complete file contents. Use when you need to review, analyze, or understand file content before making changes.",
9
+ description: `Read file contents from the Agentic File System (AFS)
10
+ - Returns the content of a file at the specified AFS path
11
+ - By default reads up to ${DEFAULT_LINE_LIMIT} lines, use offset/limit for large files
12
+ - Lines longer than ${MAX_LINE_LENGTH} characters will be truncated
13
+
14
+ Usage:
15
+ - The path must be an absolute AFS path starting with "/" (e.g., "/docs/readme.md")
16
+ - Use offset to start reading from a specific line (0-based)
17
+ - Use limit to control number of lines returned (default: ${DEFAULT_LINE_LIMIT})
18
+ - Check truncated field to know if file was partially returned`,
8
19
  ...options,
9
20
  inputSchema: z.object({
10
- path: z.string().describe("Absolute file path to read"),
11
- withLineNumbers: z
12
- .boolean()
21
+ path: z
22
+ .string()
23
+ .describe("Absolute AFS path to the file to read (e.g., '/docs/readme.md'). Must start with '/'"),
24
+ offset: z
25
+ .number()
26
+ .int()
27
+ .min(0)
13
28
  .optional()
14
- .describe("Include line numbers in output (required when planning to edit the file)"),
29
+ .describe("Line number to start reading from (0-based, default: 0)"),
30
+ limit: z
31
+ .number()
32
+ .int()
33
+ .min(1)
34
+ .max(DEFAULT_LINE_LIMIT)
35
+ .optional()
36
+ .describe(`Maximum number of lines to read (default: ${DEFAULT_LINE_LIMIT})`),
15
37
  }),
16
38
  outputSchema: z.object({
17
39
  status: z.string(),
18
40
  tool: z.string(),
19
41
  path: z.string(),
20
- withLineNumbers: z.boolean().optional(),
21
42
  data: z.custom().optional(),
22
43
  message: z.string().optional(),
44
+ totalLines: z.number().optional(),
45
+ returnedLines: z.number().optional(),
46
+ truncated: z.boolean().optional(),
47
+ offset: z.number().optional(),
23
48
  }),
24
49
  });
25
50
  }
@@ -27,22 +52,44 @@ export class AFSReadAgent extends AFSSkillBase {
27
52
  if (!this.afs)
28
53
  throw new Error("AFS is not configured for this agent.");
29
54
  const result = await this.afs.read(input.path);
30
- let content = result.data?.content;
31
- if (input.withLineNumbers && typeof content === "string") {
32
- content = content
33
- .split("\n")
34
- .map((line, idx) => `${idx + 1}| ${line}`)
35
- .join("\n");
55
+ if (!result.data?.content || typeof result.data.content !== "string") {
56
+ return {
57
+ status: "success",
58
+ tool: "afs_read",
59
+ path: input.path,
60
+ ...result,
61
+ };
62
+ }
63
+ const offset = input.offset ?? 0;
64
+ const limit = input.limit ?? DEFAULT_LINE_LIMIT;
65
+ const allLines = result.data.content.split("\n");
66
+ const totalLines = allLines.length;
67
+ // Apply offset and limit
68
+ const selectedLines = allLines.slice(offset, offset + limit);
69
+ // Truncate long lines
70
+ const processedLines = selectedLines.map((line) => line.length > MAX_LINE_LENGTH ? `${line.substring(0, MAX_LINE_LENGTH)}... [truncated]` : line);
71
+ const returnedLines = processedLines.length;
72
+ const truncated = offset > 0 || offset + limit < totalLines;
73
+ const processedContent = processedLines.join("\n");
74
+ let message;
75
+ if (truncated) {
76
+ const startLine = offset + 1;
77
+ const endLine = offset + returnedLines;
78
+ message = `Showing lines ${startLine}-${endLine} of ${totalLines}. Use offset/limit to read more.`;
36
79
  }
37
80
  return {
38
81
  status: "success",
39
82
  tool: "afs_read",
40
83
  path: input.path,
41
- withLineNumbers: input.withLineNumbers,
84
+ totalLines,
85
+ returnedLines,
86
+ truncated,
87
+ offset,
88
+ message,
42
89
  ...result,
43
- data: result.data && {
90
+ data: {
44
91
  ...result.data,
45
- content,
92
+ content: processedContent,
46
93
  },
47
94
  };
48
95
  }
@@ -4,16 +4,30 @@ export class AFSRenameAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_rename",
7
- description: "Rename or move files and directories. Use when reorganizing files, changing names, or moving to different locations.",
7
+ description: `Rename or move files and directories within the Agentic File System (AFS)
8
+ - Renames a file or directory to a new name
9
+ - Can also move files/directories to a different location
10
+ - Optionally overwrites existing files at the destination
11
+
12
+ Usage:
13
+ - Both paths must be absolute AFS paths starting with "/" (e.g., "/docs/old-name.md" -> "/docs/new-name.md")
14
+ - This is NOT a local system file path - it operates within the AFS virtual file system
15
+ - To move a file, specify a different directory in newPath (e.g., "/docs/file.md" -> "/archive/file.md")
16
+ - If newPath already exists, the operation will fail unless overwrite=true
17
+ - Moving directories moves all contents recursively`,
8
18
  ...options,
9
19
  inputSchema: z.object({
10
- oldPath: z.string().describe("Absolute current file or directory path"),
11
- newPath: z.string().describe("Absolute new file or directory path"),
20
+ oldPath: z
21
+ .string()
22
+ .describe("Current absolute AFS path (e.g., '/docs/old-name.md'). Must start with '/'"),
23
+ newPath: z
24
+ .string()
25
+ .describe("New absolute AFS path (e.g., '/docs/new-name.md'). Must start with '/'"),
12
26
  overwrite: z
13
27
  .boolean()
14
28
  .optional()
15
29
  .default(false)
16
- .describe("Overwrite if destination exists (default: false)"),
30
+ .describe("Set to true to overwrite if destination already exists. Default: false (fails if exists)"),
17
31
  }),
18
32
  outputSchema: z.object({
19
33
  status: z.string(),
@@ -4,18 +4,34 @@ export class AFSSearchAgent extends AFSSkillBase {
4
4
  constructor(options) {
5
5
  super({
6
6
  name: "afs_search",
7
- description: "Search file contents by keywords. Use when finding files containing specific text or code patterns.",
7
+ description: `Search file contents within the Agentic File System (AFS)
8
+ - Searches for files containing specific text, keywords, or patterns
9
+ - Returns matching entries with their content and metadata
10
+ - Supports case-sensitive and case-insensitive search modes
11
+ - Use this tool when you need to find files by their content
12
+
13
+ Usage:
14
+ - The path must be an absolute AFS path starting with "/" (e.g., "/", "/docs", "/memory")
15
+ - This is NOT a local system file path - it operates within the AFS virtual file system
16
+ - The query can be keywords, phrases, or text patterns to search for
17
+ - Use limit to control the number of results returned
18
+ - Search is case-insensitive by default; set caseSensitive to true for exact case matching`,
8
19
  ...options,
9
20
  inputSchema: z.object({
10
- path: z.string().describe("Absolute directory path to search in"),
11
- query: z.string().describe("Search keywords or patterns"),
21
+ path: z
22
+ .string()
23
+ .describe("Absolute AFS path to search in (e.g., '/', '/docs', '/memory'). Must start with '/'"),
24
+ query: z.string().describe("Text, keywords, or patterns to search for in file contents"),
12
25
  options: z
13
26
  .object({
14
- limit: z.number().optional().describe("Max results to return"),
27
+ limit: z
28
+ .number()
29
+ .optional()
30
+ .describe("Maximum number of results to return. Useful for limiting output size"),
15
31
  caseSensitive: z
16
32
  .boolean()
17
33
  .optional()
18
- .describe("Case-sensitive search (default: false)"),
34
+ .describe("Set to true for case-sensitive matching. Default: false (case-insensitive)"),
19
35
  })
20
36
  .optional(),
21
37
  }),