@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.
@@ -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,6 +589,52 @@ 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 = [];
@@ -639,9 +688,12 @@ var ClineAgent = class {
639
688
  const history = await this.memory.getHistory();
640
689
  const stream = this.api.createMessage(sysPrompt, history);
641
690
  let fullResponseText = "";
691
+ let fullReasoningText = "";
642
692
  for await (const chunk of stream) {
643
693
  if (chunk.type === "text" && chunk.text) {
644
694
  fullResponseText += chunk.text;
695
+ } else if (chunk.type === "reasoning" && chunk.reasoning) {
696
+ fullReasoningText += chunk.reasoning;
645
697
  }
646
698
  if (this.onStreamChunk) {
647
699
  this.onStreamChunk(chunk);
@@ -649,7 +701,8 @@ var ClineAgent = class {
649
701
  }
650
702
  await this.memory.appendMessage({
651
703
  role: "assistant",
652
- content: fullResponseText
704
+ content: fullResponseText,
705
+ ...fullReasoningText ? { reasoning: fullReasoningText } : {}
653
706
  });
654
707
  const parsedBlocks = parseAssistantMessageV2(fullResponseText, this.allToolParamNames);
655
708
  const toolUses = parsedBlocks.filter((b) => b.type === "tool_use");
@@ -1007,6 +1060,11 @@ var WebApiHandler = class {
1007
1060
  type: "text",
1008
1061
  text: part.textDelta || part.text || ""
1009
1062
  };
1063
+ } else if (part.type === "reasoning-delta") {
1064
+ yield {
1065
+ type: "reasoning",
1066
+ reasoning: part.delta || part.text || ""
1067
+ };
1010
1068
  } else if (part.type === "finish") {
1011
1069
  yield {
1012
1070
  type: "usage",
@@ -1085,6 +1143,14 @@ ${this.getToolInstructions(context)}
1085
1143
  if (envPrompt) {
1086
1144
  prompt += `
1087
1145
  ${envPrompt}
1146
+ `;
1147
+ }
1148
+ if (context.agentRules) {
1149
+ prompt += `
1150
+ # Project Rules
1151
+
1152
+ The user has specified instructions for all working directories:
1153
+ ${context.agentRules}
1088
1154
  `;
1089
1155
  }
1090
1156
  if (context.customInstructions) {