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