@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.
- package/CHANGELOG.md +27 -0
- package/lib/cjs/agents/agent.d.ts +31 -1
- package/lib/cjs/agents/agent.js +13 -0
- package/lib/cjs/agents/ai-agent.d.ts +7 -0
- package/lib/cjs/agents/ai-agent.js +85 -3
- package/lib/cjs/agents/image-agent.d.ts +17 -1
- package/lib/cjs/agents/image-agent.js +16 -0
- package/lib/cjs/agents/image-model.d.ts +4 -4
- package/lib/cjs/agents/mcp-agent.d.ts +17 -0
- package/lib/cjs/agents/mcp-agent.js +18 -0
- package/lib/cjs/agents/team-agent.d.ts +55 -0
- package/lib/cjs/agents/team-agent.js +31 -0
- package/lib/cjs/agents/transform-agent.d.ts +12 -0
- package/lib/cjs/agents/transform-agent.js +13 -0
- package/lib/cjs/agents/video-model.d.ts +4 -4
- package/lib/cjs/loader/agent-yaml.d.ts +5 -67
- package/lib/cjs/loader/agent-yaml.js +4 -139
- package/lib/cjs/loader/agents.d.ts +4 -0
- package/lib/cjs/loader/agents.js +17 -0
- package/lib/cjs/loader/index.d.ts +18 -14
- package/lib/cjs/loader/index.js +20 -81
- package/lib/cjs/loader/schema.d.ts +21 -6
- package/lib/cjs/loader/schema.js +60 -1
- package/lib/cjs/prompt/prompt-builder.js +0 -1
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +63 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +61 -0
- package/lib/cjs/prompt/skills/afs/delete.js +15 -3
- package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/cjs/prompt/skills/afs/edit.js +85 -59
- package/lib/cjs/prompt/skills/afs/exec.js +17 -6
- package/lib/cjs/prompt/skills/afs/index.js +4 -1
- package/lib/cjs/prompt/skills/afs/list.js +26 -10
- package/lib/cjs/prompt/skills/afs/read.d.ts +6 -2
- package/lib/cjs/prompt/skills/afs/read.js +62 -15
- package/lib/cjs/prompt/skills/afs/rename.js +18 -4
- package/lib/cjs/prompt/skills/afs/search.js +21 -5
- package/lib/cjs/prompt/skills/afs/write.js +20 -6
- package/lib/cjs/prompt/template.d.ts +23 -23
- package/lib/dts/agents/agent.d.ts +31 -1
- package/lib/dts/agents/ai-agent.d.ts +7 -0
- package/lib/dts/agents/image-agent.d.ts +17 -1
- package/lib/dts/agents/image-model.d.ts +4 -4
- package/lib/dts/agents/mcp-agent.d.ts +17 -0
- package/lib/dts/agents/team-agent.d.ts +55 -0
- package/lib/dts/agents/transform-agent.d.ts +12 -0
- package/lib/dts/agents/video-model.d.ts +4 -4
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/loader/agent-yaml.d.ts +5 -67
- package/lib/dts/loader/agents.d.ts +4 -0
- package/lib/dts/loader/index.d.ts +18 -14
- package/lib/dts/loader/schema.d.ts +21 -6
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/dts/prompt/skills/afs/read.d.ts +6 -2
- package/lib/dts/prompt/template.d.ts +25 -25
- package/lib/esm/agents/agent.d.ts +31 -1
- package/lib/esm/agents/agent.js +13 -0
- package/lib/esm/agents/ai-agent.d.ts +7 -0
- package/lib/esm/agents/ai-agent.js +85 -3
- package/lib/esm/agents/image-agent.d.ts +17 -1
- package/lib/esm/agents/image-agent.js +16 -0
- package/lib/esm/agents/image-model.d.ts +4 -4
- package/lib/esm/agents/mcp-agent.d.ts +17 -0
- package/lib/esm/agents/mcp-agent.js +18 -0
- package/lib/esm/agents/team-agent.d.ts +55 -0
- package/lib/esm/agents/team-agent.js +31 -0
- package/lib/esm/agents/transform-agent.d.ts +12 -0
- package/lib/esm/agents/transform-agent.js +13 -0
- package/lib/esm/agents/video-model.d.ts +4 -4
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/loader/agent-yaml.d.ts +5 -67
- package/lib/esm/loader/agent-yaml.js +4 -138
- package/lib/esm/loader/agents.d.ts +4 -0
- package/lib/esm/loader/agents.js +14 -0
- package/lib/esm/loader/index.d.ts +18 -14
- package/lib/esm/loader/index.js +21 -81
- package/lib/esm/loader/schema.d.ts +21 -6
- package/lib/esm/loader/schema.js +57 -0
- package/lib/esm/prompt/prompt-builder.js +1 -2
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +59 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +53 -0
- package/lib/esm/prompt/skills/afs/delete.js +15 -3
- package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/esm/prompt/skills/afs/edit.js +85 -59
- package/lib/esm/prompt/skills/afs/exec.js +17 -6
- package/lib/esm/prompt/skills/afs/index.js +4 -1
- package/lib/esm/prompt/skills/afs/list.js +26 -10
- package/lib/esm/prompt/skills/afs/read.d.ts +6 -2
- package/lib/esm/prompt/skills/afs/read.js +62 -15
- package/lib/esm/prompt/skills/afs/rename.js +18 -4
- package/lib/esm/prompt/skills/afs/search.js +21 -5
- package/lib/esm/prompt/skills/afs/write.js +20 -6
- package/lib/esm/prompt/template.d.ts +25 -25
- package/package.json +5 -4
package/lib/cjs/loader/schema.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.imageModelSchema = exports.chatModelSchema = exports.defaultInputSchema = exports.inputOutputSchema = void 0;
|
|
3
|
+
exports.getInstructionsSchema = exports.imageModelSchema = exports.chatModelSchema = exports.defaultInputSchema = exports.inputOutputSchema = void 0;
|
|
4
4
|
exports.optionalize = optionalize;
|
|
5
5
|
exports.camelizeSchema = camelizeSchema;
|
|
6
6
|
exports.preprocessSchema = preprocessSchema;
|
|
7
|
+
exports.instructionsToPromptBuilder = instructionsToPromptBuilder;
|
|
7
8
|
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
8
9
|
const yaml_1 = require("yaml");
|
|
9
10
|
const zod_1 = require("zod");
|
|
10
11
|
const agent_js_1 = require("../agents/agent.js");
|
|
12
|
+
const chat_model_js_1 = require("../agents/chat-model.js");
|
|
13
|
+
const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
|
|
14
|
+
const template_js_1 = require("../prompt/template.js");
|
|
11
15
|
const camelize_js_1 = require("../utils/camelize.js");
|
|
12
16
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
13
17
|
const inputOutputSchema = ({ path }) => {
|
|
@@ -101,3 +105,58 @@ function camelizeSchema(schema, { shallow = true } = {}) {
|
|
|
101
105
|
function preprocessSchema(fn, schema) {
|
|
102
106
|
return zod_1.z.preprocess(fn, schema);
|
|
103
107
|
}
|
|
108
|
+
const instructionItemSchema = camelizeSchema(zod_1.z.union([
|
|
109
|
+
zod_1.z.object({
|
|
110
|
+
role: chat_model_js_1.roleSchema.default("system"),
|
|
111
|
+
url: zod_1.z.string(),
|
|
112
|
+
cacheControl: optionalize(zod_1.z.object({
|
|
113
|
+
type: zod_1.z.literal("ephemeral"),
|
|
114
|
+
ttl: optionalize(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
115
|
+
})),
|
|
116
|
+
}),
|
|
117
|
+
zod_1.z.object({
|
|
118
|
+
role: chat_model_js_1.roleSchema.default("system"),
|
|
119
|
+
content: zod_1.z.string(),
|
|
120
|
+
cacheControl: optionalize(zod_1.z.object({
|
|
121
|
+
type: zod_1.z.literal("ephemeral"),
|
|
122
|
+
ttl: optionalize(zod_1.z.union([zod_1.z.literal("5m"), zod_1.z.literal("1h")])),
|
|
123
|
+
})),
|
|
124
|
+
}),
|
|
125
|
+
]));
|
|
126
|
+
const parseInstructionItem = ({ filepath }) => async ({ role, cacheControl, ...v }) => {
|
|
127
|
+
if (role === "tool")
|
|
128
|
+
throw new Error(`'tool' role is not allowed in instruction item in agent file ${filepath}`);
|
|
129
|
+
if ("content" in v && typeof v.content === "string") {
|
|
130
|
+
return { role, content: v.content, path: filepath, cacheControl };
|
|
131
|
+
}
|
|
132
|
+
if ("url" in v && typeof v.url === "string") {
|
|
133
|
+
const url = index_js_1.nodejs.path.isAbsolute(v.url)
|
|
134
|
+
? v.url
|
|
135
|
+
: index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(filepath), v.url);
|
|
136
|
+
return index_js_1.nodejs.fs
|
|
137
|
+
.readFile(url, "utf8")
|
|
138
|
+
.then((content) => ({ role, content, path: url, cacheControl }));
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Invalid instruction item in agent file ${filepath}. Expected 'content' or 'url' property`);
|
|
141
|
+
};
|
|
142
|
+
const getInstructionsSchema = ({ filepath }) => zod_1.z
|
|
143
|
+
.union([zod_1.z.string(), instructionItemSchema, zod_1.z.array(instructionItemSchema)])
|
|
144
|
+
.transform(async (v) => {
|
|
145
|
+
if (typeof v === "string")
|
|
146
|
+
return [{ role: "system", content: v, path: filepath }];
|
|
147
|
+
if (Array.isArray(v)) {
|
|
148
|
+
return Promise.all(v.map((item) => parseInstructionItem({ filepath })(item)));
|
|
149
|
+
}
|
|
150
|
+
return [await parseInstructionItem({ filepath })(v)];
|
|
151
|
+
});
|
|
152
|
+
exports.getInstructionsSchema = getInstructionsSchema;
|
|
153
|
+
function instructionsToPromptBuilder(instructions) {
|
|
154
|
+
return new prompt_builder_js_1.PromptBuilder({
|
|
155
|
+
instructions: typeof instructions === "string"
|
|
156
|
+
? instructions
|
|
157
|
+
: template_js_1.ChatMessagesTemplate.from((0, template_js_1.parseChatMessages)(instructions.map((i) => ({
|
|
158
|
+
...i,
|
|
159
|
+
options: { workingDir: index_js_1.nodejs.path.dirname(i.path) },
|
|
160
|
+
})))),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -119,7 +119,6 @@ class PromptBuilder {
|
|
|
119
119
|
const afs = options.agent?.afs;
|
|
120
120
|
if (afs && options.agent?.historyConfig?.disabled !== true) {
|
|
121
121
|
const historyModule = (await afs.listModules()).find((m) => m.module instanceof afs_history_1.AFSHistory);
|
|
122
|
-
messages.push(await template_js_1.SystemMessageTemplate.from(await (0, afs_builtin_prompt_js_1.getAFSSystemPrompt)(afs)).format({}));
|
|
123
122
|
if (historyModule) {
|
|
124
123
|
const history = await afs.list(historyModule.path, {
|
|
125
124
|
limit: options.agent?.maxRetrieveMemoryCount || 10,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Agent, type AgentOptions, type Message } from "../../../../agents/agent.js";
|
|
2
|
+
import type { Skill } from "./skill-loader.js";
|
|
3
|
+
export interface SkillToolInput extends Message {
|
|
4
|
+
skill: string;
|
|
5
|
+
args?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SkillToolOutput extends Message {
|
|
8
|
+
result: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SkillToolOptions extends AgentOptions<SkillToolInput, SkillToolOutput> {
|
|
11
|
+
agentSkills: Skill[];
|
|
12
|
+
}
|
|
13
|
+
export declare class AgentSkill extends Agent<SkillToolInput, SkillToolOutput> {
|
|
14
|
+
constructor(options: SkillToolOptions);
|
|
15
|
+
private agentSkills;
|
|
16
|
+
process(input: SkillToolInput): Promise<SkillToolOutput>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentSkill = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const agent_js_1 = require("../../../../agents/agent.js");
|
|
6
|
+
const skillToolInputSchema = zod_1.z.object({
|
|
7
|
+
skill: zod_1.z.string().describe("The name of the skill agent to invoke."),
|
|
8
|
+
args: zod_1.z.string().optional().describe("The arguments to pass to the skill."),
|
|
9
|
+
});
|
|
10
|
+
class AgentSkill extends agent_js_1.Agent {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super({
|
|
13
|
+
name: "Skill",
|
|
14
|
+
taskTitle: "Invoke {{skill}}: {{args}}",
|
|
15
|
+
...options,
|
|
16
|
+
description: `\
|
|
17
|
+
Execute a skill within the main conversation
|
|
18
|
+
|
|
19
|
+
<skills_instructions>
|
|
20
|
+
When users ask you to perform tasks, check if any of the available skills below can help complete the task more effectively. Skills provide specialized capabilities and domain knowledge.
|
|
21
|
+
|
|
22
|
+
When users ask you to run a "slash command" or reference "/" (e.g., "/commit", "/review-pr"), they are referring to a skill. Use this tool to invoke the corresponding skill.
|
|
23
|
+
|
|
24
|
+
User: "run /commit" Assistant: [Calls Skill tool with skill: "commit"]
|
|
25
|
+
How to invoke:
|
|
26
|
+
|
|
27
|
+
Use this tool with the skill name and optional arguments
|
|
28
|
+
|
|
29
|
+
Important:
|
|
30
|
+
|
|
31
|
+
When a skill is relevant, you must invoke this tool IMMEDIATELY as your first action
|
|
32
|
+
NEVER just announce or mention a skill in your text response without actually calling this tool
|
|
33
|
+
This is a BLOCKING REQUIREMENT: invoke the relevant Skill tool BEFORE generating any other response about the task
|
|
34
|
+
Only use skills listed in <available_skills> below
|
|
35
|
+
Do not invoke a skill that is already running
|
|
36
|
+
Do not use this tool for built-in CLI commands (like /help, /clear, etc.)
|
|
37
|
+
</skills_instructions>
|
|
38
|
+
|
|
39
|
+
<available_skills>
|
|
40
|
+
${options.agentSkills.map((s) => `${s.name}: ${s.description}`).join("\n\n")}
|
|
41
|
+
</available_skills>
|
|
42
|
+
`,
|
|
43
|
+
inputSchema: skillToolInputSchema,
|
|
44
|
+
});
|
|
45
|
+
this.agentSkills = options.agentSkills;
|
|
46
|
+
}
|
|
47
|
+
agentSkills;
|
|
48
|
+
async process(input) {
|
|
49
|
+
const skill = this.agentSkills.find((s) => s.name === input.skill);
|
|
50
|
+
if (!skill)
|
|
51
|
+
throw new Error(`Skill not found: ${input.skill}`);
|
|
52
|
+
return {
|
|
53
|
+
result: `\
|
|
54
|
+
Base directory for this skill: ${skill.path}
|
|
55
|
+
|
|
56
|
+
${skill.content}
|
|
57
|
+
|
|
58
|
+
${input.args ? `ARGUMENTS: ${input.args ?? "None"}` : ""}
|
|
59
|
+
`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.AgentSkill = AgentSkill;
|
|
@@ -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,61 @@
|
|
|
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.loadSkill = loadSkill;
|
|
7
|
+
exports.loadSkills = loadSkills;
|
|
8
|
+
exports.loadAgentSkillFromAFS = loadAgentSkillFromAFS;
|
|
9
|
+
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
10
|
+
const front_matter_1 = __importDefault(require("front-matter"));
|
|
11
|
+
const agent_skill_js_1 = require("./agent-skill.js");
|
|
12
|
+
function parseSkill(content, path) {
|
|
13
|
+
const meta = (0, front_matter_1.default)(content);
|
|
14
|
+
return {
|
|
15
|
+
path,
|
|
16
|
+
name: meta.attributes.name,
|
|
17
|
+
description: meta.attributes.description,
|
|
18
|
+
content: meta.body,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async function loadSkill(path) {
|
|
22
|
+
const entry = index_js_1.nodejs.path.join(path, "SKILL.md");
|
|
23
|
+
const skill = await index_js_1.nodejs.fs.readFile(entry, "utf-8");
|
|
24
|
+
return parseSkill(skill, path);
|
|
25
|
+
}
|
|
26
|
+
async function loadSkills(paths) {
|
|
27
|
+
const skills = [];
|
|
28
|
+
for (const path of paths) {
|
|
29
|
+
const skill = await loadSkill(path);
|
|
30
|
+
skills.push(skill);
|
|
31
|
+
}
|
|
32
|
+
return skills;
|
|
33
|
+
}
|
|
34
|
+
async function loadAgentSkillFromAFS({ afs, }) {
|
|
35
|
+
const modules = await afs.listModules();
|
|
36
|
+
const filtered = modules.filter(({ module: m }) => "options" in m &&
|
|
37
|
+
typeof m.options === "object" &&
|
|
38
|
+
m.options &&
|
|
39
|
+
"agentSkills" in m.options &&
|
|
40
|
+
m.options.agentSkills === true);
|
|
41
|
+
if (!filtered.length)
|
|
42
|
+
return;
|
|
43
|
+
const skills = [];
|
|
44
|
+
for (const module of filtered) {
|
|
45
|
+
const data = (await afs.list(module.path, {
|
|
46
|
+
pattern: "**/SKILL.md",
|
|
47
|
+
})).data;
|
|
48
|
+
for (const entry of data) {
|
|
49
|
+
const { data: file } = await afs.read(entry.path);
|
|
50
|
+
if (typeof file?.content !== "string")
|
|
51
|
+
continue;
|
|
52
|
+
const skill = parseSkill(file.content, index_js_1.nodejs.path.dirname(entry.path));
|
|
53
|
+
skills.push(skill);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!skills.length)
|
|
57
|
+
return;
|
|
58
|
+
return new agent_skill_js_1.AgentSkill({
|
|
59
|
+
agentSkills: skills,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -7,15 +7,27 @@ class AFSDeleteAgent extends base_js_1.AFSSkillBase {
|
|
|
7
7
|
constructor(options) {
|
|
8
8
|
super({
|
|
9
9
|
name: "afs_delete",
|
|
10
|
-
description:
|
|
10
|
+
description: `Permanently delete files or directories from the Agentic File System (AFS)
|
|
11
|
+
- Removes files or directories at the specified AFS path
|
|
12
|
+
- Supports recursive deletion for directories with contents
|
|
13
|
+
- Use with caution as deletion is permanent
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
- The path must be an absolute AFS path starting with "/" (e.g., "/docs/old-file.md", "/temp")
|
|
17
|
+
- This is NOT a local system file path - it operates within the AFS virtual file system
|
|
18
|
+
- To delete a directory, you MUST set recursive=true
|
|
19
|
+
- Deleting a non-empty directory without recursive=true will fail
|
|
20
|
+
- This operation cannot be undone`,
|
|
11
21
|
...options,
|
|
12
22
|
inputSchema: zod_1.z.object({
|
|
13
|
-
path: zod_1.z
|
|
23
|
+
path: zod_1.z
|
|
24
|
+
.string()
|
|
25
|
+
.describe("Absolute AFS path to delete (e.g., '/docs/old-file.md', '/temp'). Must start with '/'"),
|
|
14
26
|
recursive: zod_1.z
|
|
15
27
|
.boolean()
|
|
16
28
|
.optional()
|
|
17
29
|
.default(false)
|
|
18
|
-
.describe("
|
|
30
|
+
.describe("MUST be set to true to delete directories. Default: false (files only)"),
|
|
19
31
|
}),
|
|
20
32
|
outputSchema: zod_1.z.object({
|
|
21
33
|
status: zod_1.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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
+
private countOccurrences;
|
|
23
|
+
private extractSnippet;
|
|
27
24
|
}
|
|
@@ -3,96 +3,122 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AFSEditAgent = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const base_js_1 = require("./base.js");
|
|
6
|
+
const CONTEXT_LINES = 4; // Number of lines to show before and after the edit
|
|
6
7
|
class AFSEditAgent extends base_js_1.AFSSkillBase {
|
|
7
8
|
constructor(options) {
|
|
8
9
|
super({
|
|
9
10
|
name: "afs_edit",
|
|
10
|
-
description:
|
|
11
|
+
description: `Performs exact string replacements in files within the Agentic File System (AFS).
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
- You must use afs_read at least once before editing to understand the file content
|
|
15
|
+
- The path must be an absolute AFS path starting with "/" (e.g., "/docs/readme.md")
|
|
16
|
+
- Preserve exact indentation (tabs/spaces) as it appears in the file
|
|
17
|
+
- The edit will FAIL if oldString is not found in the file
|
|
18
|
+
- The edit will FAIL if oldString appears multiple times (unless replaceAll is true)
|
|
19
|
+
- Use replaceAll to replace/rename strings across the entire file`,
|
|
11
20
|
...options,
|
|
12
21
|
inputSchema: zod_1.z.object({
|
|
13
|
-
path: zod_1.z
|
|
14
|
-
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
22
|
+
path: zod_1.z
|
|
23
|
+
.string()
|
|
24
|
+
.describe("Absolute AFS path to the file to edit (e.g., '/docs/readme.md'). Must start with '/'"),
|
|
25
|
+
oldString: zod_1.z
|
|
26
|
+
.string()
|
|
27
|
+
.describe("The exact text to replace. Must match file content exactly including whitespace"),
|
|
28
|
+
newString: zod_1.z
|
|
29
|
+
.string()
|
|
30
|
+
.describe("The text to replace it with (must be different from oldString)"),
|
|
31
|
+
replaceAll: zod_1.z
|
|
32
|
+
.boolean()
|
|
33
|
+
.optional()
|
|
34
|
+
.default(false)
|
|
35
|
+
.describe("Replace all occurrences of oldString (default: false)"),
|
|
23
36
|
}),
|
|
24
37
|
outputSchema: zod_1.z.object({
|
|
25
38
|
status: zod_1.z.string(),
|
|
26
39
|
tool: zod_1.z.string(),
|
|
27
40
|
path: zod_1.z.string(),
|
|
28
41
|
message: zod_1.z.string(),
|
|
29
|
-
|
|
42
|
+
snippet: zod_1.z.string(),
|
|
30
43
|
}),
|
|
31
44
|
});
|
|
32
45
|
}
|
|
33
46
|
async process(input, _options) {
|
|
34
47
|
if (!this.afs)
|
|
35
48
|
throw new Error("AFS is not configured for this agent.");
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
const { path, oldString, newString, replaceAll = false } = input;
|
|
50
|
+
if (oldString === newString) {
|
|
51
|
+
throw new Error("oldString and newString must be different");
|
|
38
52
|
}
|
|
39
|
-
const readResult = await this.afs.read(
|
|
53
|
+
const readResult = await this.afs.read(path);
|
|
40
54
|
if (!readResult.data?.content || typeof readResult.data.content !== "string") {
|
|
41
|
-
throw new Error(`Cannot read file content from: ${
|
|
55
|
+
throw new Error(`Cannot read file content from: ${path}`);
|
|
42
56
|
}
|
|
43
57
|
const originalContent = readResult.data.content;
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
// Check if oldString exists in the file
|
|
59
|
+
const occurrences = this.countOccurrences(originalContent, oldString);
|
|
60
|
+
if (occurrences === 0) {
|
|
61
|
+
throw new Error(`oldString not found in file: ${path}`);
|
|
62
|
+
}
|
|
63
|
+
if (occurrences > 1 && !replaceAll) {
|
|
64
|
+
throw new Error(`oldString appears ${occurrences} times in file. Use replaceAll=true to replace all occurrences, or provide more context to make oldString unique.`);
|
|
65
|
+
}
|
|
66
|
+
// Find the position of the first occurrence for snippet extraction
|
|
67
|
+
const firstOccurrenceIndex = originalContent.indexOf(oldString);
|
|
68
|
+
// Perform the replacement
|
|
69
|
+
const updatedContent = replaceAll
|
|
70
|
+
? originalContent.split(oldString).join(newString)
|
|
71
|
+
: originalContent.replace(oldString, newString);
|
|
72
|
+
await this.afs.write(path, {
|
|
46
73
|
content: updatedContent,
|
|
47
74
|
});
|
|
75
|
+
// Generate snippet around the edit location
|
|
76
|
+
const snippet = this.extractSnippet(updatedContent, firstOccurrenceIndex, newString.length);
|
|
77
|
+
const replacementCount = replaceAll ? occurrences : 1;
|
|
48
78
|
return {
|
|
49
79
|
status: "success",
|
|
50
80
|
tool: "afs_edit",
|
|
51
|
-
path
|
|
52
|
-
message: `
|
|
53
|
-
|
|
81
|
+
path,
|
|
82
|
+
message: `Replaced ${replacementCount} occurrence${replacementCount > 1 ? "s" : ""} in ${path}`,
|
|
83
|
+
snippet,
|
|
54
84
|
};
|
|
55
85
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const replaceLines = patch.replace ? patch.replace.split("\n") : [];
|
|
76
|
-
lines.splice(start, deleteCount, ...replaceLines);
|
|
77
|
-
delta = replaceLines.length - deleteCount;
|
|
78
|
-
}
|
|
79
|
-
// Update subsequent patches' line numbers
|
|
80
|
-
// For exclusive-end semantics [start, end), we adjust patches that start >= current patch's start_line
|
|
81
|
-
// after the current patch has been applied
|
|
82
|
-
if (delta !== 0) {
|
|
83
|
-
for (let j = i + 1; j < sorted.length; j++) {
|
|
84
|
-
const next = sorted[j];
|
|
85
|
-
if (!next)
|
|
86
|
-
continue;
|
|
87
|
-
// Adjust patches that start at or after the current patch's end line
|
|
88
|
-
if (next.start_line >= patch.end_line) {
|
|
89
|
-
next.start_line += delta;
|
|
90
|
-
next.end_line += delta;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
86
|
+
countOccurrences(text, search) {
|
|
87
|
+
let count = 0;
|
|
88
|
+
let position = text.indexOf(search);
|
|
89
|
+
while (position !== -1) {
|
|
90
|
+
count++;
|
|
91
|
+
position = text.indexOf(search, position + search.length);
|
|
92
|
+
}
|
|
93
|
+
return count;
|
|
94
|
+
}
|
|
95
|
+
extractSnippet(content, editStartIndex, newStringLength) {
|
|
96
|
+
const lines = content.split("\n");
|
|
97
|
+
// Find the line number where the edit starts
|
|
98
|
+
let charCount = 0;
|
|
99
|
+
let editStartLine = 0;
|
|
100
|
+
for (let i = 0; i < lines.length; i++) {
|
|
101
|
+
const lineLength = (lines[i]?.length ?? 0) + 1; // +1 for newline
|
|
102
|
+
if (charCount + lineLength > editStartIndex) {
|
|
103
|
+
editStartLine = i;
|
|
104
|
+
break;
|
|
93
105
|
}
|
|
106
|
+
charCount += lineLength;
|
|
94
107
|
}
|
|
95
|
-
|
|
108
|
+
// Calculate how many lines the new content spans
|
|
109
|
+
const newContentLines = content
|
|
110
|
+
.substring(editStartIndex, editStartIndex + newStringLength)
|
|
111
|
+
.split("\n").length;
|
|
112
|
+
const editEndLine = editStartLine + newContentLines - 1;
|
|
113
|
+
// Extract lines with context
|
|
114
|
+
const startLine = Math.max(0, editStartLine - CONTEXT_LINES);
|
|
115
|
+
const endLine = Math.min(lines.length - 1, editEndLine + CONTEXT_LINES);
|
|
116
|
+
// Format with line numbers (1-based)
|
|
117
|
+
const snippetLines = lines.slice(startLine, endLine + 1).map((line, idx) => {
|
|
118
|
+
const lineNum = startLine + idx + 1;
|
|
119
|
+
return `${String(lineNum).padStart(4)}| ${line}`;
|
|
120
|
+
});
|
|
121
|
+
return snippetLines.join("\n");
|
|
96
122
|
}
|
|
97
123
|
}
|
|
98
124
|
exports.AFSEditAgent = AFSEditAgent;
|
|
@@ -7,14 +7,25 @@ class AFSExecAgent extends base_js_1.AFSSkillBase {
|
|
|
7
7
|
constructor(options) {
|
|
8
8
|
super({
|
|
9
9
|
name: "afs_exec",
|
|
10
|
-
description: `
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
description: `Execute files marked as executable in the Agentic File System (AFS)
|
|
11
|
+
- Runs executable entries (functions, agents, skills) registered at a given AFS path
|
|
12
|
+
- Passes arguments to the executable and returns its output
|
|
13
|
+
- Use this to invoke dynamic functionality stored in AFS
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
- The path must be an absolute AFS path to an executable entry (e.g., "/skills/summarize", "/agents/translator")
|
|
17
|
+
- This is NOT a local system file path - it operates within the AFS virtual file system
|
|
18
|
+
- Use afs_list to discover available executables (look for entries with execute metadata)
|
|
19
|
+
- Arguments must be a valid JSON string matching the executable's input schema
|
|
20
|
+
- The executable's input/output schema can be found in its metadata`,
|
|
14
21
|
...options,
|
|
15
22
|
inputSchema: zod_1.z.object({
|
|
16
|
-
path: zod_1.z
|
|
17
|
-
|
|
23
|
+
path: zod_1.z
|
|
24
|
+
.string()
|
|
25
|
+
.describe("Absolute AFS path to the executable (e.g., '/skills/summarize'). Must start with '/'"),
|
|
26
|
+
args: zod_1.z
|
|
27
|
+
.string()
|
|
28
|
+
.describe('JSON string of arguments matching the executable\'s input schema (e.g., \'{"text": "hello"}\')'),
|
|
18
29
|
}),
|
|
19
30
|
outputSchema: zod_1.z.object({
|
|
20
31
|
data: zod_1.z.record(zod_1.z.any()),
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAFSSkills = getAFSSkills;
|
|
4
|
+
const type_utils_js_1 = require("../../../utils/type-utils.js");
|
|
5
|
+
const skill_loader_js_1 = require("./agent-skill/skill-loader.js");
|
|
4
6
|
const delete_js_1 = require("./delete.js");
|
|
5
7
|
const edit_js_1 = require("./edit.js");
|
|
6
8
|
const exec_js_1 = require("./exec.js");
|
|
@@ -19,5 +21,6 @@ async function getAFSSkills(afs) {
|
|
|
19
21
|
new delete_js_1.AFSDeleteAgent({ afs }),
|
|
20
22
|
new rename_js_1.AFSRenameAgent({ afs }),
|
|
21
23
|
new exec_js_1.AFSExecAgent({ afs }),
|
|
22
|
-
|
|
24
|
+
await (0, skill_loader_js_1.loadAgentSkillFromAFS)({ afs }),
|
|
25
|
+
].filter(type_utils_js_1.isNonNullable);
|
|
23
26
|
}
|
|
@@ -7,26 +7,42 @@ class AFSListAgent extends base_js_1.AFSSkillBase {
|
|
|
7
7
|
constructor(options) {
|
|
8
8
|
super({
|
|
9
9
|
name: "afs_list",
|
|
10
|
-
description:
|
|
10
|
+
description: `List contents within the Agentic File System (AFS)
|
|
11
|
+
- Returns files and directories at the specified AFS path
|
|
12
|
+
- Supports recursive listing with configurable depth
|
|
13
|
+
- Supports glob pattern filtering to match specific files
|
|
14
|
+
- By default respects .gitignore rules to filter out ignored files
|
|
15
|
+
- Use this tool when you need to explore AFS contents or understand file organization
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
- The path must be an absolute AFS path starting with "/" (e.g., "/", "/docs", "/memory/user")
|
|
19
|
+
- This is NOT a local system file path - it operates within the AFS virtual file system
|
|
20
|
+
- Use maxDepth to control recursion depth (default: 1, current directory only)
|
|
21
|
+
- Use pattern to filter entries by glob pattern:
|
|
22
|
+
- "*.ts" - match TypeScript files in current directory
|
|
23
|
+
- "**/*.js" - match all JavaScript files recursively
|
|
24
|
+
- "src/**/*.{ts,tsx}" - match TypeScript files in src directory
|
|
25
|
+
- Results are filtered by .gitignore by default; set disableGitignore to include ignored files`,
|
|
11
26
|
...options,
|
|
12
27
|
inputSchema: zod_1.z.object({
|
|
13
|
-
path: zod_1.z
|
|
28
|
+
path: zod_1.z
|
|
29
|
+
.string()
|
|
30
|
+
.describe("Absolute AFS path to list (e.g., '/', '/docs', '/memory/user'). Must start with '/'"),
|
|
14
31
|
options: zod_1.z
|
|
15
32
|
.object({
|
|
16
|
-
maxDepth: zod_1.z
|
|
33
|
+
maxDepth: zod_1.z
|
|
34
|
+
.number()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("Maximum depth of directory recursion. 1 = current directory only, 2 = include subdirectories, etc. Default: 1"),
|
|
17
37
|
disableGitignore: zod_1.z
|
|
18
38
|
.boolean()
|
|
19
39
|
.optional()
|
|
20
|
-
.describe("
|
|
40
|
+
.describe("Set to true to include files normally ignored by .gitignore rules. Default: false (respects .gitignore)"),
|
|
21
41
|
maxChildren: zod_1.z
|
|
22
42
|
.number()
|
|
23
43
|
.optional()
|
|
24
|
-
.describe("Maximum number of
|
|
25
|
-
|
|
26
|
-
.union([zod_1.z.literal("simple-list"), zod_1.z.literal("tree")])
|
|
27
|
-
.optional()
|
|
28
|
-
.default("simple-list")
|
|
29
|
-
.describe("Output format, either 'simple-list', or 'tree', default is 'simple-list'"),
|
|
44
|
+
.describe("Maximum number of entries to return per directory. Useful for large directories to avoid overwhelming output"),
|
|
45
|
+
pattern: zod_1.z.string().optional().describe("Glob pattern to filter entries by path"),
|
|
30
46
|
})
|
|
31
47
|
.optional(),
|
|
32
48
|
}),
|
|
@@ -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
|
-
|
|
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"]>;
|