@amical/aiagent-sdk 0.1.5 → 0.1.7
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/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +52 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -3
- package/dist/index.mjs.map +1 -1
- package/dist/runtime/nodeRuntime.d.mts +1 -0
- package/dist/runtime/nodeRuntime.d.ts +1 -0
- package/dist/runtime/nodeRuntime.js +60 -3
- package/dist/runtime/nodeRuntime.js.map +1 -1
- package/dist/runtime/nodeRuntime.mjs +60 -3
- package/dist/runtime/nodeRuntime.mjs.map +1 -1
- package/dist/runtime/webRuntime.d.mts +1 -0
- package/dist/runtime/webRuntime.d.ts +1 -0
- package/dist/runtime/webRuntime.js +60 -3
- package/dist/runtime/webRuntime.js.map +1 -1
- package/dist/runtime/webRuntime.mjs +60 -3
- package/dist/runtime/webRuntime.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -496,6 +496,7 @@ var ClineAgent = class {
|
|
|
496
496
|
/** 最大循环次数 */
|
|
497
497
|
maxLoopCount;
|
|
498
498
|
skillDir;
|
|
499
|
+
rulesDir;
|
|
499
500
|
customTools;
|
|
500
501
|
customToolNames;
|
|
501
502
|
allowDefaultTools;
|
|
@@ -544,7 +545,8 @@ var ClineAgent = class {
|
|
|
544
545
|
}
|
|
545
546
|
}
|
|
546
547
|
this.customToolNames = new Set(this.customTools.map((t) => t.name));
|
|
547
|
-
this.skillDir = this.runtime.path.join(this.runtime.env.cwd(), ".
|
|
548
|
+
this.skillDir = this.runtime.path.join(this.runtime.env.cwd(), ".agents/skills");
|
|
549
|
+
this.rulesDir = this.runtime.path.join(this.runtime.env.cwd(), ".agents/rules");
|
|
548
550
|
}
|
|
549
551
|
setState(newState) {
|
|
550
552
|
this.state = newState;
|
|
@@ -565,6 +567,7 @@ var ClineAgent = class {
|
|
|
565
567
|
os: this.runtime.env.osInfo(),
|
|
566
568
|
shell: this.runtime.env.shell(),
|
|
567
569
|
skills: await this.getSkills(),
|
|
570
|
+
agentRules: await this.getAgentRules(),
|
|
568
571
|
customTools: this.customTools,
|
|
569
572
|
allowDefaultTools: this.allowDefaultTools,
|
|
570
573
|
customInstructions: this.customInstructions
|
|
@@ -591,16 +594,62 @@ var ClineAgent = class {
|
|
|
591
594
|
throw err;
|
|
592
595
|
}
|
|
593
596
|
}
|
|
597
|
+
/**
|
|
598
|
+
* 读取项目级 Agent Rules:
|
|
599
|
+
* 1. ${cwd}/Agents.md
|
|
600
|
+
* 2. ${cwd}/.agents/rules/ 一级目录下所有 .md 文件
|
|
601
|
+
* 将内容合并为一段文本,供系统提示词注入。
|
|
602
|
+
*/
|
|
603
|
+
async getAgentRules() {
|
|
604
|
+
const cwd = this.runtime.env.cwd();
|
|
605
|
+
const rules = [];
|
|
606
|
+
const agentsMdPath = this.runtime.path.join(cwd, "Agents.md");
|
|
607
|
+
try {
|
|
608
|
+
if (await this.runtime.fs.fileExists(agentsMdPath)) {
|
|
609
|
+
const content = await this.runtime.fs.readFile(agentsMdPath);
|
|
610
|
+
if (content && content.trim()) {
|
|
611
|
+
rules.push(content.trim());
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
} catch (e) {
|
|
615
|
+
}
|
|
616
|
+
try {
|
|
617
|
+
if (await this.runtime.fs.fileExists(this.rulesDir)) {
|
|
618
|
+
const files = await this.runtime.fs.readDir(this.rulesDir);
|
|
619
|
+
for (const file of files) {
|
|
620
|
+
if (!file.isFile()) {
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
const name = String(file.name);
|
|
624
|
+
if (!name.toLowerCase().endsWith(".md")) {
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
const filePath = this.runtime.path.join(this.rulesDir, name);
|
|
628
|
+
try {
|
|
629
|
+
const content = await this.runtime.fs.readFile(filePath);
|
|
630
|
+
if (content && content.trim()) {
|
|
631
|
+
rules.push(`\`\`\`markdown
|
|
632
|
+
# ${name}
|
|
633
|
+
${content.trim()}\`\`\``);
|
|
634
|
+
}
|
|
635
|
+
} catch (e) {
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
} catch (e) {
|
|
640
|
+
}
|
|
641
|
+
return rules.join("\n---\n");
|
|
642
|
+
}
|
|
594
643
|
async getSkills() {
|
|
595
644
|
const skillDir = this.skillDir;
|
|
596
645
|
const skillList = [];
|
|
597
|
-
if (!this.runtime.fs.fileExists(skillDir)) {
|
|
646
|
+
if (!await this.runtime.fs.fileExists(skillDir)) {
|
|
598
647
|
return skillList;
|
|
599
648
|
}
|
|
600
649
|
const files = await this.runtime.fs.readDir(skillDir);
|
|
601
650
|
const skills = files.filter((item) => item.isDirectory()).map((item) => item.name);
|
|
602
651
|
if (skills.length === 0) {
|
|
603
|
-
return
|
|
652
|
+
return skillList;
|
|
604
653
|
}
|
|
605
654
|
for (const skill of skills) {
|
|
606
655
|
try {
|
|
@@ -1090,6 +1139,14 @@ ${this.getToolInstructions(context)}
|
|
|
1090
1139
|
if (envPrompt) {
|
|
1091
1140
|
prompt += `
|
|
1092
1141
|
${envPrompt}
|
|
1142
|
+
`;
|
|
1143
|
+
}
|
|
1144
|
+
if (context.agentRules) {
|
|
1145
|
+
prompt += `
|
|
1146
|
+
# Project Rules
|
|
1147
|
+
|
|
1148
|
+
The user has specified instructions for all working directories:
|
|
1149
|
+
${context.agentRules}
|
|
1093
1150
|
`;
|
|
1094
1151
|
}
|
|
1095
1152
|
if (context.customInstructions) {
|