leaf-coding-agent 1.0.3 → 1.0.4

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.
Files changed (30) hide show
  1. package/dist/core/agent-session.d.ts +16 -2
  2. package/dist/core/agent-session.d.ts.map +1 -1
  3. package/dist/core/agent-session.js +51 -12
  4. package/dist/core/agent-session.js.map +1 -1
  5. package/dist/core/export-html/index.d.ts.map +1 -1
  6. package/dist/core/export-html/index.js +3 -1
  7. package/dist/core/export-html/index.js.map +1 -1
  8. package/dist/core/extensions/runner.d.ts +4 -1
  9. package/dist/core/extensions/runner.d.ts.map +1 -1
  10. package/dist/core/extensions/runner.js +4 -1
  11. package/dist/core/extensions/runner.js.map +1 -1
  12. package/dist/core/system-prompt.d.ts +14 -0
  13. package/dist/core/system-prompt.d.ts.map +1 -1
  14. package/dist/core/system-prompt.js +43 -23
  15. package/dist/core/system-prompt.js.map +1 -1
  16. package/dist/core/tools/worker.d.ts +1 -0
  17. package/dist/core/tools/worker.d.ts.map +1 -1
  18. package/dist/core/tools/worker.js +26 -6
  19. package/dist/core/tools/worker.js.map +1 -1
  20. package/dist/core/worker-integration.d.ts +0 -4
  21. package/dist/core/worker-integration.d.ts.map +1 -1
  22. package/dist/core/worker-integration.js +42 -23
  23. package/dist/core/worker-integration.js.map +1 -1
  24. package/dist/modes/interactive/components/worker-selector.d.ts.map +1 -1
  25. package/dist/modes/interactive/components/worker-selector.js +18 -23
  26. package/dist/modes/interactive/components/worker-selector.js.map +1 -1
  27. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  28. package/dist/modes/interactive/interactive-mode.js +11 -14
  29. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  30. package/package.json +1 -1
@@ -31,7 +31,7 @@ import { expandPromptTemplate } from "./prompt-templates.js";
31
31
  import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
32
32
  import { createSyntheticSourceInfo } from "./source-info.js";
33
33
  import { createWorkerIntegration } from "./worker-integration.js";
34
- import { buildDynamicContext, buildSystemPrompt } from "./system-prompt.js";
34
+ import { buildDynamicContext, buildSystemPromptSections } from "./system-prompt.js";
35
35
  import { createLocalBashOperations } from "./tools/bash.js";
36
36
  import { createAllToolDefinitions } from "./tools/index.js";
37
37
  import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
@@ -113,8 +113,41 @@ export class AgentSession {
113
113
  // Base system prompt (without extension appends) - used to apply fresh appends each turn
114
114
  // Worker 模式
115
115
  workerEnabled = false;
116
+ workerMaxWorkers = 4;
117
+ workerCommunicationMode = "message";
116
118
  workerIntegration;
117
- _baseSystemPrompt = "";
119
+ /**
120
+ * 启用或禁用 Worker 模式
121
+ */
122
+ setWorkerEnabled(enabled) {
123
+ this.workerEnabled = enabled;
124
+ if (enabled) {
125
+ // 获取当前活跃的工具名称
126
+ const currentTools = this.getActiveToolNames();
127
+ // 添加 worker 工具
128
+ if (!currentTools.includes("worker")) {
129
+ this.setActiveToolsByName([...currentTools, "worker"]);
130
+ }
131
+ }
132
+ else {
133
+ // 移除 worker 工具
134
+ const currentTools = this.getActiveToolNames();
135
+ this.setActiveToolsByName(currentTools.filter(name => name !== "worker"));
136
+ }
137
+ }
138
+ /**
139
+ * 设置最大 Worker 数量
140
+ */
141
+ setWorkerMaxWorkers(maxWorkers) {
142
+ this.workerMaxWorkers = maxWorkers;
143
+ }
144
+ /**
145
+ * 设置通信模式
146
+ */
147
+ setWorkerCommunicationMode(mode) {
148
+ this.workerCommunicationMode = mode;
149
+ }
150
+ _baseSystemPromptSections = [];
118
151
  _baseSystemPromptOptions;
119
152
  constructor(config) {
120
153
  this.agent = config.agent;
@@ -507,9 +540,10 @@ export class AgentSession {
507
540
  get isStreaming() {
508
541
  return this.agent.state.isStreaming;
509
542
  }
510
- /** Current effective system prompt (includes any per-turn extension modifications) */
543
+ /** Current effective system prompt as a single string (includes any per-turn extension modifications) */
511
544
  get systemPrompt() {
512
- return this.agent.state.systemPrompt;
545
+ const sp = this.agent.state.systemPrompt;
546
+ return typeof sp === "string" ? sp : sp.map((s) => s.text).join("\n\n");
513
547
  }
514
548
  /** Current retry attempt (0 if not retrying) */
515
549
  get retryAttempt() {
@@ -555,8 +589,8 @@ export class AgentSession {
555
589
  }
556
590
  this.agent.state.tools = tools;
557
591
  // Rebuild base system prompt with new tool set
558
- this._baseSystemPrompt = this._rebuildSystemPrompt(validToolNames);
559
- this.agent.state.systemPrompt = this._baseSystemPrompt;
592
+ this._baseSystemPromptSections = this._rebuildSystemPrompt(validToolNames);
593
+ this.agent.state.systemPrompt = this._baseSystemPromptSections;
560
594
  }
561
595
  /** Whether compaction or branch summarization is currently running */
562
596
  get isCompacting() {
@@ -651,7 +685,7 @@ export class AgentSession {
651
685
  toolSnippets,
652
686
  promptGuidelines,
653
687
  };
654
- return buildSystemPrompt(this._baseSystemPromptOptions);
688
+ return buildSystemPromptSections(this._baseSystemPromptOptions);
655
689
  }
656
690
  // =========================================================================
657
691
  // Prompting
@@ -797,7 +831,7 @@ export class AgentSession {
797
831
  }
798
832
  this._pendingNextTurnMessages = [];
799
833
  // Emit before_agent_start extension event
800
- const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPrompt, this._baseSystemPromptOptions);
834
+ const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPromptSections, this._baseSystemPromptOptions);
801
835
  // Add all custom messages from extensions
802
836
  if (result?.messages) {
803
837
  for (const msg of result.messages) {
@@ -813,11 +847,16 @@ export class AgentSession {
813
847
  }
814
848
  // Apply extension-modified system prompt, or reset to base
815
849
  if (result?.systemPrompt) {
816
- this.agent.state.systemPrompt = result.systemPrompt;
850
+ // Extension modified the system prompt — append as a new dynamic section
851
+ // so the stable base sections remain unchanged for cache hits.
852
+ this.agent.state.systemPrompt = [
853
+ ...this._baseSystemPromptSections,
854
+ { type: "text", text: result.systemPrompt },
855
+ ];
817
856
  }
818
857
  else {
819
858
  // Ensure we're using the base prompt (in case previous turn had modifications)
820
- this.agent.state.systemPrompt = this._baseSystemPrompt;
859
+ this.agent.state.systemPrompt = this._baseSystemPromptSections;
821
860
  }
822
861
  }
823
862
  catch (error) {
@@ -1664,8 +1703,8 @@ export class AgentSession {
1664
1703
  themePaths: this.buildExtensionResourcePaths(themePaths),
1665
1704
  };
1666
1705
  this._resourceLoader.extendResources(extensionPaths);
1667
- this._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());
1668
- this.agent.state.systemPrompt = this._baseSystemPrompt;
1706
+ this._baseSystemPromptSections = this._rebuildSystemPrompt(this.getActiveToolNames());
1707
+ this.agent.state.systemPrompt = this._baseSystemPromptSections;
1669
1708
  }
1670
1709
  buildExtensionResourcePaths(entries) {
1671
1710
  return entries.map((entry) => {