@amical/aiagent-sdk 0.1.6 → 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.
@@ -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(), ".agent/skills");
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,6 +594,52 @@ 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 = [];
@@ -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) {