@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.
@@ -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 = [];
@@ -644,9 +693,12 @@ var ClineAgent = class {
644
693
  const history = await this.memory.getHistory();
645
694
  const stream = this.api.createMessage(sysPrompt, history);
646
695
  let fullResponseText = "";
696
+ let fullReasoningText = "";
647
697
  for await (const chunk of stream) {
648
698
  if (chunk.type === "text" && chunk.text) {
649
699
  fullResponseText += chunk.text;
700
+ } else if (chunk.type === "reasoning" && chunk.reasoning) {
701
+ fullReasoningText += chunk.reasoning;
650
702
  }
651
703
  if (this.onStreamChunk) {
652
704
  this.onStreamChunk(chunk);
@@ -654,7 +706,8 @@ var ClineAgent = class {
654
706
  }
655
707
  await this.memory.appendMessage({
656
708
  role: "assistant",
657
- content: fullResponseText
709
+ content: fullResponseText,
710
+ ...fullReasoningText ? { reasoning: fullReasoningText } : {}
658
711
  });
659
712
  const parsedBlocks = parseAssistantMessageV2(fullResponseText, this.allToolParamNames);
660
713
  const toolUses = parsedBlocks.filter((b) => b.type === "tool_use");
@@ -1012,6 +1065,11 @@ var NodeApiHandler = class {
1012
1065
  type: "text",
1013
1066
  text: part.textDelta || part.text || ""
1014
1067
  };
1068
+ } else if (part.type === "reasoning-delta") {
1069
+ yield {
1070
+ type: "reasoning",
1071
+ reasoning: part.delta || part.text || ""
1072
+ };
1015
1073
  } else if (part.type === "finish") {
1016
1074
  yield {
1017
1075
  type: "usage",
@@ -1090,6 +1148,14 @@ ${this.getToolInstructions(context)}
1090
1148
  if (envPrompt) {
1091
1149
  prompt += `
1092
1150
  ${envPrompt}
1151
+ `;
1152
+ }
1153
+ if (context.agentRules) {
1154
+ prompt += `
1155
+ # Project Rules
1156
+
1157
+ The user has specified instructions for all working directories:
1158
+ ${context.agentRules}
1093
1159
  `;
1094
1160
  }
1095
1161
  if (context.customInstructions) {