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