@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.
@@ -491,6 +491,7 @@ var ClineAgent = class {
491
491
  /** 最大循环次数 */
492
492
  maxLoopCount;
493
493
  skillDir;
494
+ rulesDir;
494
495
  customTools;
495
496
  customToolNames;
496
497
  allowDefaultTools;
@@ -539,7 +540,8 @@ var ClineAgent = class {
539
540
  }
540
541
  }
541
542
  this.customToolNames = new Set(this.customTools.map((t) => t.name));
542
- this.skillDir = this.runtime.path.join(this.runtime.env.cwd(), ".agent/skills");
543
+ this.skillDir = this.runtime.path.join(this.runtime.env.cwd(), ".agents/skills");
544
+ this.rulesDir = this.runtime.path.join(this.runtime.env.cwd(), ".agents/rules");
543
545
  }
544
546
  setState(newState) {
545
547
  this.state = newState;
@@ -560,6 +562,7 @@ var ClineAgent = class {
560
562
  os: this.runtime.env.osInfo(),
561
563
  shell: this.runtime.env.shell(),
562
564
  skills: await this.getSkills(),
565
+ agentRules: await this.getAgentRules(),
563
566
  customTools: this.customTools,
564
567
  allowDefaultTools: this.allowDefaultTools,
565
568
  customInstructions: this.customInstructions
@@ -586,16 +589,62 @@ var ClineAgent = class {
586
589
  throw err;
587
590
  }
588
591
  }
592
+ /**
593
+ * 读取项目级 Agent Rules:
594
+ * 1. ${cwd}/Agents.md
595
+ * 2. ${cwd}/.agents/rules/ 一级目录下所有 .md 文件
596
+ * 将内容合并为一段文本,供系统提示词注入。
597
+ */
598
+ async getAgentRules() {
599
+ const cwd = this.runtime.env.cwd();
600
+ const rules = [];
601
+ const agentsMdPath = this.runtime.path.join(cwd, "Agents.md");
602
+ try {
603
+ if (await this.runtime.fs.fileExists(agentsMdPath)) {
604
+ const content = await this.runtime.fs.readFile(agentsMdPath);
605
+ if (content && content.trim()) {
606
+ rules.push(content.trim());
607
+ }
608
+ }
609
+ } catch (e) {
610
+ }
611
+ try {
612
+ if (await this.runtime.fs.fileExists(this.rulesDir)) {
613
+ const files = await this.runtime.fs.readDir(this.rulesDir);
614
+ for (const file of files) {
615
+ if (!file.isFile()) {
616
+ continue;
617
+ }
618
+ const name = String(file.name);
619
+ if (!name.toLowerCase().endsWith(".md")) {
620
+ continue;
621
+ }
622
+ const filePath = this.runtime.path.join(this.rulesDir, name);
623
+ try {
624
+ const content = await this.runtime.fs.readFile(filePath);
625
+ if (content && content.trim()) {
626
+ rules.push(`\`\`\`markdown
627
+ # ${name}
628
+ ${content.trim()}\`\`\``);
629
+ }
630
+ } catch (e) {
631
+ }
632
+ }
633
+ }
634
+ } catch (e) {
635
+ }
636
+ return rules.join("\n---\n");
637
+ }
589
638
  async getSkills() {
590
639
  const skillDir = this.skillDir;
591
640
  const skillList = [];
592
- if (!this.runtime.fs.fileExists(skillDir)) {
641
+ if (!await this.runtime.fs.fileExists(skillDir)) {
593
642
  return skillList;
594
643
  }
595
644
  const files = await this.runtime.fs.readDir(skillDir);
596
645
  const skills = files.filter((item) => item.isDirectory()).map((item) => item.name);
597
646
  if (skills.length === 0) {
598
- return [];
647
+ return skillList;
599
648
  }
600
649
  for (const skill of skills) {
601
650
  try {
@@ -1085,6 +1134,14 @@ ${this.getToolInstructions(context)}
1085
1134
  if (envPrompt) {
1086
1135
  prompt += `
1087
1136
  ${envPrompt}
1137
+ `;
1138
+ }
1139
+ if (context.agentRules) {
1140
+ prompt += `
1141
+ # Project Rules
1142
+
1143
+ The user has specified instructions for all working directories:
1144
+ ${context.agentRules}
1088
1145
  `;
1089
1146
  }
1090
1147
  if (context.customInstructions) {