@amical/aiagent-sdk 0.1.6 → 0.1.8

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.
@@ -523,6 +523,7 @@ var ClineAgent = class {
523
523
  /** 最大循环次数 */
524
524
  maxLoopCount;
525
525
  skillDir;
526
+ rulesDir;
526
527
  customTools;
527
528
  customToolNames;
528
529
  allowDefaultTools;
@@ -571,7 +572,8 @@ var ClineAgent = class {
571
572
  }
572
573
  }
573
574
  this.customToolNames = new Set(this.customTools.map((t) => t.name));
574
- this.skillDir = this.runtime.path.join(this.runtime.env.cwd(), ".agent/skills");
575
+ this.skillDir = this.runtime.path.join(this.runtime.env.cwd(), ".agents/skills");
576
+ this.rulesDir = this.runtime.path.join(this.runtime.env.cwd(), ".agents/rules");
575
577
  }
576
578
  setState(newState) {
577
579
  this.state = newState;
@@ -592,6 +594,7 @@ var ClineAgent = class {
592
594
  os: this.runtime.env.osInfo(),
593
595
  shell: this.runtime.env.shell(),
594
596
  skills: await this.getSkills(),
597
+ agentRules: await this.getAgentRules(),
595
598
  customTools: this.customTools,
596
599
  allowDefaultTools: this.allowDefaultTools,
597
600
  customInstructions: this.customInstructions
@@ -618,6 +621,52 @@ var ClineAgent = class {
618
621
  throw err;
619
622
  }
620
623
  }
624
+ /**
625
+ * 读取项目级 Agent Rules:
626
+ * 1. ${cwd}/Agents.md
627
+ * 2. ${cwd}/.agents/rules/ 一级目录下所有 .md 文件
628
+ * 将内容合并为一段文本,供系统提示词注入。
629
+ */
630
+ async getAgentRules() {
631
+ const cwd = this.runtime.env.cwd();
632
+ const rules = [];
633
+ const agentsMdPath = this.runtime.path.join(cwd, "Agents.md");
634
+ try {
635
+ if (await this.runtime.fs.fileExists(agentsMdPath)) {
636
+ const content = await this.runtime.fs.readFile(agentsMdPath);
637
+ if (content && content.trim()) {
638
+ rules.push(content.trim());
639
+ }
640
+ }
641
+ } catch (e) {
642
+ }
643
+ try {
644
+ if (await this.runtime.fs.fileExists(this.rulesDir)) {
645
+ const files = await this.runtime.fs.readDir(this.rulesDir);
646
+ for (const file of files) {
647
+ if (!file.isFile()) {
648
+ continue;
649
+ }
650
+ const name = String(file.name);
651
+ if (!name.toLowerCase().endsWith(".md")) {
652
+ continue;
653
+ }
654
+ const filePath = this.runtime.path.join(this.rulesDir, name);
655
+ try {
656
+ const content = await this.runtime.fs.readFile(filePath);
657
+ if (content && content.trim()) {
658
+ rules.push(`\`\`\`markdown
659
+ # ${name}
660
+ ${content.trim()}\`\`\``);
661
+ }
662
+ } catch (e) {
663
+ }
664
+ }
665
+ }
666
+ } catch (e) {
667
+ }
668
+ return rules.join("\n---\n");
669
+ }
621
670
  async getSkills() {
622
671
  const skillDir = this.skillDir;
623
672
  const skillList = [];
@@ -671,9 +720,12 @@ var ClineAgent = class {
671
720
  const history = await this.memory.getHistory();
672
721
  const stream = this.api.createMessage(sysPrompt, history);
673
722
  let fullResponseText = "";
723
+ let fullReasoningText = "";
674
724
  for await (const chunk of stream) {
675
725
  if (chunk.type === "text" && chunk.text) {
676
726
  fullResponseText += chunk.text;
727
+ } else if (chunk.type === "reasoning" && chunk.reasoning) {
728
+ fullReasoningText += chunk.reasoning;
677
729
  }
678
730
  if (this.onStreamChunk) {
679
731
  this.onStreamChunk(chunk);
@@ -681,7 +733,8 @@ var ClineAgent = class {
681
733
  }
682
734
  await this.memory.appendMessage({
683
735
  role: "assistant",
684
- content: fullResponseText
736
+ content: fullResponseText,
737
+ ...fullReasoningText ? { reasoning: fullReasoningText } : {}
685
738
  });
686
739
  const parsedBlocks = parseAssistantMessageV2(fullResponseText, this.allToolParamNames);
687
740
  const toolUses = parsedBlocks.filter((b) => b.type === "tool_use");
@@ -1039,6 +1092,11 @@ var NodeApiHandler = class {
1039
1092
  type: "text",
1040
1093
  text: part.textDelta || part.text || ""
1041
1094
  };
1095
+ } else if (part.type === "reasoning-delta") {
1096
+ yield {
1097
+ type: "reasoning",
1098
+ reasoning: part.delta || part.text || ""
1099
+ };
1042
1100
  } else if (part.type === "finish") {
1043
1101
  yield {
1044
1102
  type: "usage",
@@ -1117,6 +1175,14 @@ ${this.getToolInstructions(context)}
1117
1175
  if (envPrompt) {
1118
1176
  prompt += `
1119
1177
  ${envPrompt}
1178
+ `;
1179
+ }
1180
+ if (context.agentRules) {
1181
+ prompt += `
1182
+ # Project Rules
1183
+
1184
+ The user has specified instructions for all working directories:
1185
+ ${context.agentRules}
1120
1186
  `;
1121
1187
  }
1122
1188
  if (context.customInstructions) {