attocode 0.2.0 → 0.2.2

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 (179) hide show
  1. package/CHANGELOG.md +111 -1
  2. package/README.md +7 -0
  3. package/dist/src/adapters.d.ts +6 -1
  4. package/dist/src/adapters.d.ts.map +1 -1
  5. package/dist/src/adapters.js +14 -1
  6. package/dist/src/adapters.js.map +1 -1
  7. package/dist/src/agent.d.ts +50 -0
  8. package/dist/src/agent.d.ts.map +1 -1
  9. package/dist/src/agent.js +734 -316
  10. package/dist/src/agent.js.map +1 -1
  11. package/dist/src/defaults.d.ts +1 -1
  12. package/dist/src/defaults.d.ts.map +1 -1
  13. package/dist/src/defaults.js +2 -0
  14. package/dist/src/defaults.js.map +1 -1
  15. package/dist/src/integrations/agent-registry.d.ts +9 -2
  16. package/dist/src/integrations/agent-registry.d.ts.map +1 -1
  17. package/dist/src/integrations/agent-registry.js +30 -4
  18. package/dist/src/integrations/agent-registry.js.map +1 -1
  19. package/dist/src/integrations/async-subagent.d.ts +135 -0
  20. package/dist/src/integrations/async-subagent.d.ts.map +1 -0
  21. package/dist/src/integrations/async-subagent.js +213 -0
  22. package/dist/src/integrations/async-subagent.js.map +1 -0
  23. package/dist/src/integrations/auto-checkpoint.d.ts +98 -0
  24. package/dist/src/integrations/auto-checkpoint.d.ts.map +1 -0
  25. package/dist/src/integrations/auto-checkpoint.js +252 -0
  26. package/dist/src/integrations/auto-checkpoint.js.map +1 -0
  27. package/dist/src/integrations/budget-pool.d.ts +13 -1
  28. package/dist/src/integrations/budget-pool.d.ts.map +1 -1
  29. package/dist/src/integrations/budget-pool.js +17 -0
  30. package/dist/src/integrations/budget-pool.js.map +1 -1
  31. package/dist/src/integrations/complexity-classifier.d.ts +86 -0
  32. package/dist/src/integrations/complexity-classifier.d.ts.map +1 -0
  33. package/dist/src/integrations/complexity-classifier.js +233 -0
  34. package/dist/src/integrations/complexity-classifier.js.map +1 -0
  35. package/dist/src/integrations/delegation-protocol.d.ts +86 -0
  36. package/dist/src/integrations/delegation-protocol.d.ts.map +1 -0
  37. package/dist/src/integrations/delegation-protocol.js +127 -0
  38. package/dist/src/integrations/delegation-protocol.js.map +1 -0
  39. package/dist/src/integrations/dynamic-budget.d.ts +81 -0
  40. package/dist/src/integrations/dynamic-budget.d.ts.map +1 -0
  41. package/dist/src/integrations/dynamic-budget.js +151 -0
  42. package/dist/src/integrations/dynamic-budget.js.map +1 -0
  43. package/dist/src/integrations/economics.d.ts +44 -1
  44. package/dist/src/integrations/economics.d.ts.map +1 -1
  45. package/dist/src/integrations/economics.js +182 -3
  46. package/dist/src/integrations/economics.js.map +1 -1
  47. package/dist/src/integrations/environment-facts.d.ts +52 -0
  48. package/dist/src/integrations/environment-facts.d.ts.map +1 -0
  49. package/dist/src/integrations/environment-facts.js +84 -0
  50. package/dist/src/integrations/environment-facts.js.map +1 -0
  51. package/dist/src/integrations/index.d.ts +16 -1
  52. package/dist/src/integrations/index.d.ts.map +1 -1
  53. package/dist/src/integrations/index.js +31 -1
  54. package/dist/src/integrations/index.js.map +1 -1
  55. package/dist/src/integrations/injection-budget.d.ts +71 -0
  56. package/dist/src/integrations/injection-budget.d.ts.map +1 -0
  57. package/dist/src/integrations/injection-budget.js +136 -0
  58. package/dist/src/integrations/injection-budget.js.map +1 -0
  59. package/dist/src/integrations/mcp-client.d.ts.map +1 -1
  60. package/dist/src/integrations/mcp-client.js +14 -0
  61. package/dist/src/integrations/mcp-client.js.map +1 -1
  62. package/dist/src/integrations/mcp-custom-tools.d.ts +102 -0
  63. package/dist/src/integrations/mcp-custom-tools.d.ts.map +1 -0
  64. package/dist/src/integrations/mcp-custom-tools.js +232 -0
  65. package/dist/src/integrations/mcp-custom-tools.js.map +1 -0
  66. package/dist/src/integrations/mcp-tool-validator.d.ts +60 -0
  67. package/dist/src/integrations/mcp-tool-validator.d.ts.map +1 -0
  68. package/dist/src/integrations/mcp-tool-validator.js +141 -0
  69. package/dist/src/integrations/mcp-tool-validator.js.map +1 -0
  70. package/dist/src/integrations/routing.d.ts +2 -1
  71. package/dist/src/integrations/routing.d.ts.map +1 -1
  72. package/dist/src/integrations/routing.js.map +1 -1
  73. package/dist/src/integrations/self-improvement.d.ts +90 -0
  74. package/dist/src/integrations/self-improvement.d.ts.map +1 -0
  75. package/dist/src/integrations/self-improvement.js +217 -0
  76. package/dist/src/integrations/self-improvement.js.map +1 -0
  77. package/dist/src/integrations/smart-decomposer.d.ts +4 -0
  78. package/dist/src/integrations/smart-decomposer.d.ts.map +1 -1
  79. package/dist/src/integrations/smart-decomposer.js +55 -28
  80. package/dist/src/integrations/smart-decomposer.js.map +1 -1
  81. package/dist/src/integrations/subagent-output-store.d.ts +91 -0
  82. package/dist/src/integrations/subagent-output-store.d.ts.map +1 -0
  83. package/dist/src/integrations/subagent-output-store.js +257 -0
  84. package/dist/src/integrations/subagent-output-store.js.map +1 -0
  85. package/dist/src/integrations/swarm/index.d.ts +1 -1
  86. package/dist/src/integrations/swarm/index.d.ts.map +1 -1
  87. package/dist/src/integrations/swarm/index.js +1 -1
  88. package/dist/src/integrations/swarm/index.js.map +1 -1
  89. package/dist/src/integrations/swarm/model-selector.d.ts +1 -0
  90. package/dist/src/integrations/swarm/model-selector.d.ts.map +1 -1
  91. package/dist/src/integrations/swarm/model-selector.js +37 -3
  92. package/dist/src/integrations/swarm/model-selector.js.map +1 -1
  93. package/dist/src/integrations/swarm/swarm-config-loader.d.ts +10 -1
  94. package/dist/src/integrations/swarm/swarm-config-loader.d.ts.map +1 -1
  95. package/dist/src/integrations/swarm/swarm-config-loader.js +72 -6
  96. package/dist/src/integrations/swarm/swarm-config-loader.js.map +1 -1
  97. package/dist/src/integrations/swarm/swarm-event-bridge.d.ts.map +1 -1
  98. package/dist/src/integrations/swarm/swarm-event-bridge.js +26 -4
  99. package/dist/src/integrations/swarm/swarm-event-bridge.js.map +1 -1
  100. package/dist/src/integrations/swarm/swarm-events.d.ts +11 -0
  101. package/dist/src/integrations/swarm/swarm-events.d.ts.map +1 -1
  102. package/dist/src/integrations/swarm/swarm-events.js +4 -0
  103. package/dist/src/integrations/swarm/swarm-events.js.map +1 -1
  104. package/dist/src/integrations/swarm/swarm-orchestrator.d.ts +11 -0
  105. package/dist/src/integrations/swarm/swarm-orchestrator.d.ts.map +1 -1
  106. package/dist/src/integrations/swarm/swarm-orchestrator.js +233 -10
  107. package/dist/src/integrations/swarm/swarm-orchestrator.js.map +1 -1
  108. package/dist/src/integrations/swarm/swarm-quality-gate.d.ts +9 -2
  109. package/dist/src/integrations/swarm/swarm-quality-gate.d.ts.map +1 -1
  110. package/dist/src/integrations/swarm/swarm-quality-gate.js +128 -11
  111. package/dist/src/integrations/swarm/swarm-quality-gate.js.map +1 -1
  112. package/dist/src/integrations/swarm/task-queue.d.ts +11 -1
  113. package/dist/src/integrations/swarm/task-queue.d.ts.map +1 -1
  114. package/dist/src/integrations/swarm/task-queue.js +125 -15
  115. package/dist/src/integrations/swarm/task-queue.js.map +1 -1
  116. package/dist/src/integrations/swarm/types.d.ts +40 -1
  117. package/dist/src/integrations/swarm/types.d.ts.map +1 -1
  118. package/dist/src/integrations/swarm/types.js +6 -1
  119. package/dist/src/integrations/swarm/types.js.map +1 -1
  120. package/dist/src/integrations/swarm/worker-pool.d.ts +9 -3
  121. package/dist/src/integrations/swarm/worker-pool.d.ts.map +1 -1
  122. package/dist/src/integrations/swarm/worker-pool.js +89 -17
  123. package/dist/src/integrations/swarm/worker-pool.js.map +1 -1
  124. package/dist/src/integrations/thinking-strategy.d.ts +52 -0
  125. package/dist/src/integrations/thinking-strategy.d.ts.map +1 -0
  126. package/dist/src/integrations/thinking-strategy.js +129 -0
  127. package/dist/src/integrations/thinking-strategy.js.map +1 -0
  128. package/dist/src/integrations/tool-recommendation.d.ts +58 -0
  129. package/dist/src/integrations/tool-recommendation.d.ts.map +1 -0
  130. package/dist/src/integrations/tool-recommendation.js +215 -0
  131. package/dist/src/integrations/tool-recommendation.js.map +1 -0
  132. package/dist/src/integrations/verification-gate.d.ts +80 -0
  133. package/dist/src/integrations/verification-gate.d.ts.map +1 -0
  134. package/dist/src/integrations/verification-gate.js +146 -0
  135. package/dist/src/integrations/verification-gate.js.map +1 -0
  136. package/dist/src/integrations/work-log.d.ts +87 -0
  137. package/dist/src/integrations/work-log.d.ts.map +1 -0
  138. package/dist/src/integrations/work-log.js +275 -0
  139. package/dist/src/integrations/work-log.js.map +1 -0
  140. package/dist/src/main.js +5 -4
  141. package/dist/src/main.js.map +1 -1
  142. package/dist/src/modes.d.ts +6 -0
  143. package/dist/src/modes.d.ts.map +1 -1
  144. package/dist/src/modes.js +73 -2
  145. package/dist/src/modes.js.map +1 -1
  146. package/dist/src/providers/adapters/anthropic.d.ts.map +1 -1
  147. package/dist/src/providers/adapters/anthropic.js +20 -3
  148. package/dist/src/providers/adapters/anthropic.js.map +1 -1
  149. package/dist/src/providers/adapters/openrouter.d.ts.map +1 -1
  150. package/dist/src/providers/adapters/openrouter.js +3 -1
  151. package/dist/src/providers/adapters/openrouter.js.map +1 -1
  152. package/dist/src/providers/types.d.ts +4 -0
  153. package/dist/src/providers/types.d.ts.map +1 -1
  154. package/dist/src/providers/types.js.map +1 -1
  155. package/dist/src/tools/bash.d.ts +8 -2
  156. package/dist/src/tools/bash.d.ts.map +1 -1
  157. package/dist/src/tools/bash.js +14 -1
  158. package/dist/src/tools/bash.js.map +1 -1
  159. package/dist/src/tools/coercion.d.ts +14 -0
  160. package/dist/src/tools/coercion.d.ts.map +1 -0
  161. package/dist/src/tools/coercion.js +25 -0
  162. package/dist/src/tools/coercion.js.map +1 -0
  163. package/dist/src/tools/file.d.ts +2 -2
  164. package/dist/src/tools/file.d.ts.map +1 -1
  165. package/dist/src/tools/file.js +2 -1
  166. package/dist/src/tools/file.js.map +1 -1
  167. package/dist/src/tools/standard.d.ts +17 -1
  168. package/dist/src/tools/standard.d.ts.map +1 -1
  169. package/dist/src/tools/standard.js +64 -11
  170. package/dist/src/tools/standard.js.map +1 -1
  171. package/dist/src/tui/app.d.ts.map +1 -1
  172. package/dist/src/tui/app.js +8 -1
  173. package/dist/src/tui/app.js.map +1 -1
  174. package/dist/src/tui/event-display.d.ts.map +1 -1
  175. package/dist/src/tui/event-display.js +8 -1
  176. package/dist/src/tui/event-display.js.map +1 -1
  177. package/dist/src/types.d.ts +26 -0
  178. package/dist/src/types.d.ts.map +1 -1
  179. package/package.json +6 -2
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Complexity Classifier
3
+ *
4
+ * Heuristic-based task complexity assessment that determines
5
+ * the appropriate execution strategy (agent count, tool budget,
6
+ * swarm mode) without requiring an LLM call.
7
+ *
8
+ * Inspired by Anthropic's multi-agent research system's approach
9
+ * to scaling effort based on task complexity.
10
+ */
11
+ // =============================================================================
12
+ // CONSTANTS
13
+ // =============================================================================
14
+ /** Keywords that indicate higher complexity */
15
+ const COMPLEX_KEYWORDS = [
16
+ // Multi-file operations
17
+ 'refactor', 'migrate', 'redesign', 'rewrite', 'overhaul',
18
+ 'restructure', 'reorganize', 'rearchitect',
19
+ // Broad scope
20
+ 'all files', 'entire', 'codebase', 'every', 'across',
21
+ 'comprehensive', 'full audit', 'system-wide',
22
+ // Multi-step
23
+ 'first', 'then', 'after that', 'finally', 'step by step',
24
+ 'and then', 'once done', 'followed by',
25
+ // Research-heavy
26
+ 'investigate', 'analyze', 'audit', 'security review',
27
+ 'performance analysis', 'benchmark', 'compare',
28
+ ];
29
+ /** Keywords that indicate simplicity */
30
+ const SIMPLE_KEYWORDS = [
31
+ 'fix typo', 'rename', 'update version', 'add comment',
32
+ 'change color', 'fix import', 'remove unused',
33
+ 'what is', 'how does', 'where is', 'explain',
34
+ ];
35
+ /** Dependency indicators (suggest sequential steps) */
36
+ const DEPENDENCY_PATTERNS = [
37
+ /first\s.*then/i,
38
+ /after\s.*(?:do|make|create|implement)/i,
39
+ /before\s.*(?:need|must|should)/i,
40
+ /depends?\s+on/i,
41
+ /step\s+\d/i,
42
+ /phase\s+\d/i,
43
+ ];
44
+ /** Tier -> execution recommendation mapping */
45
+ const TIER_RECOMMENDATIONS = {
46
+ simple: {
47
+ agentCount: { min: 1, max: 1 },
48
+ toolCallsPerAgent: { min: 3, max: 10 },
49
+ useSwarmMode: false,
50
+ suggestedAgents: [],
51
+ budgetMultiplier: 0.5,
52
+ useExtendedThinking: false,
53
+ },
54
+ medium: {
55
+ agentCount: { min: 1, max: 4 },
56
+ toolCallsPerAgent: { min: 10, max: 20 },
57
+ useSwarmMode: false,
58
+ suggestedAgents: ['researcher', 'coder'],
59
+ budgetMultiplier: 1.0,
60
+ useExtendedThinking: false,
61
+ },
62
+ complex: {
63
+ agentCount: { min: 3, max: 8 },
64
+ toolCallsPerAgent: { min: 15, max: 30 },
65
+ useSwarmMode: true,
66
+ suggestedAgents: ['researcher', 'coder', 'reviewer'],
67
+ budgetMultiplier: 2.0,
68
+ useExtendedThinking: true,
69
+ },
70
+ deep_research: {
71
+ agentCount: { min: 5, max: 15 },
72
+ toolCallsPerAgent: { min: 20, max: 50 },
73
+ useSwarmMode: true,
74
+ suggestedAgents: ['researcher', 'coder', 'reviewer', 'architect'],
75
+ budgetMultiplier: 3.0,
76
+ useExtendedThinking: true,
77
+ },
78
+ };
79
+ // =============================================================================
80
+ // CLASSIFIER
81
+ // =============================================================================
82
+ /**
83
+ * Classify task complexity using heuristic signals.
84
+ * No LLM call needed — fast and deterministic.
85
+ */
86
+ export function classifyComplexity(task, context) {
87
+ const signals = [];
88
+ const taskLower = task.toLowerCase();
89
+ // Signal 1: Task length (proxy for detail/scope)
90
+ const wordCount = task.split(/\s+/).length;
91
+ const lengthScore = wordCount < 10 ? 0 : wordCount < 30 ? 1 : wordCount < 80 ? 2 : 3;
92
+ signals.push({
93
+ name: 'task_length',
94
+ value: lengthScore,
95
+ weight: 0.15,
96
+ description: `${wordCount} words (${lengthScore > 1 ? 'detailed' : 'brief'})`,
97
+ });
98
+ // Signal 2: Complex keyword matches
99
+ const complexMatches = COMPLEX_KEYWORDS.filter(kw => taskLower.includes(kw));
100
+ const complexScore = Math.min(complexMatches.length * 1.5, 4);
101
+ signals.push({
102
+ name: 'complex_keywords',
103
+ value: complexScore,
104
+ weight: 0.25,
105
+ description: complexMatches.length > 0
106
+ ? `Matches: ${complexMatches.slice(0, 3).join(', ')}`
107
+ : 'No complex keywords',
108
+ });
109
+ // Signal 3: Simple keyword matches (reduces score)
110
+ const simpleMatches = SIMPLE_KEYWORDS.filter(kw => taskLower.includes(kw));
111
+ const simpleScore = simpleMatches.length > 0 ? -2 : 0;
112
+ signals.push({
113
+ name: 'simple_keywords',
114
+ value: simpleScore,
115
+ weight: 0.2,
116
+ description: simpleMatches.length > 0
117
+ ? `Simple: ${simpleMatches.slice(0, 2).join(', ')}`
118
+ : 'No simplicity signals',
119
+ });
120
+ // Signal 4: Dependency patterns (suggest multi-step)
121
+ const depMatches = DEPENDENCY_PATTERNS.filter(p => p.test(task));
122
+ const depScore = depMatches.length * 2;
123
+ signals.push({
124
+ name: 'dependency_patterns',
125
+ value: depScore,
126
+ weight: 0.2,
127
+ description: depMatches.length > 0
128
+ ? `${depMatches.length} sequential dependencies detected`
129
+ : 'No dependency chains',
130
+ });
131
+ // Signal 5: Question vs action
132
+ const isQuestion = /^(what|how|where|when|why|which|can|does|is|are)\b/i.test(task.trim());
133
+ const actionScore = isQuestion ? -1 : 1;
134
+ signals.push({
135
+ name: 'question_vs_action',
136
+ value: actionScore,
137
+ weight: 0.1,
138
+ description: isQuestion ? 'Question (likely simpler)' : 'Action request',
139
+ });
140
+ // Signal 6: Multiple file/component references
141
+ const fileRefs = (task.match(/\b\w+\.(ts|tsx|js|jsx|py|rs|go|java|cpp|c|h)\b/g) || []).length;
142
+ const dirRefs = (task.match(/\b(?:src|lib|test|docs|config)\//g) || []).length;
143
+ const scopeScore = Math.min((fileRefs + dirRefs) * 0.5, 3);
144
+ signals.push({
145
+ name: 'scope_indicators',
146
+ value: scopeScore,
147
+ weight: 0.1,
148
+ description: `${fileRefs} file refs, ${dirRefs} dir refs`,
149
+ });
150
+ // Calculate weighted score
151
+ const totalScore = signals.reduce((sum, s) => sum + s.value * s.weight, 0);
152
+ // Determine tier
153
+ let tier;
154
+ if (totalScore < 0.5) {
155
+ tier = 'simple';
156
+ }
157
+ else if (totalScore < 1.5) {
158
+ tier = 'medium';
159
+ }
160
+ else if (totalScore < 2.5) {
161
+ tier = 'complex';
162
+ }
163
+ else {
164
+ tier = 'deep_research';
165
+ }
166
+ // Calculate confidence (higher when signals agree)
167
+ const signalVariance = signals.reduce((sum, s) => {
168
+ const normalized = s.value / 4; // Normalize to ~0-1 range
169
+ return sum + Math.abs(normalized - totalScore / 3);
170
+ }, 0) / signals.length;
171
+ const confidence = Math.max(0.3, Math.min(1.0, 1.0 - signalVariance));
172
+ // Build reasoning
173
+ const topSignals = [...signals]
174
+ .sort((a, b) => Math.abs(b.value * b.weight) - Math.abs(a.value * a.weight))
175
+ .slice(0, 3);
176
+ const reasoning = `Classified as ${tier} (score: ${totalScore.toFixed(2)}). ` +
177
+ `Top factors: ${topSignals.map(s => s.description).join('; ')}`;
178
+ return {
179
+ tier,
180
+ confidence,
181
+ reasoning,
182
+ recommendation: TIER_RECOMMENDATIONS[tier],
183
+ signals,
184
+ };
185
+ }
186
+ /**
187
+ * Generate scaling guidance for injection into the agent's system prompt.
188
+ * This follows Anthropic's pattern of embedding scaling rules directly in prompts.
189
+ */
190
+ export function getScalingGuidance(assessment) {
191
+ const { tier, recommendation } = assessment;
192
+ const guidelines = {
193
+ simple: `## Effort Scaling: SIMPLE TASK
194
+ - Handle directly, no subagents needed
195
+ - ${recommendation.toolCallsPerAgent.min}-${recommendation.toolCallsPerAgent.max} tool calls maximum
196
+ - Respond quickly and concisely
197
+ - Do not over-explore the codebase`,
198
+ medium: `## Effort Scaling: MEDIUM TASK
199
+ - Consider spawning ${recommendation.agentCount.min}-${recommendation.agentCount.max} subagents for independent subtasks
200
+ - Each agent: ${recommendation.toolCallsPerAgent.min}-${recommendation.toolCallsPerAgent.max} tool calls
201
+ - Coordinate via blackboard for shared findings
202
+ - Balance speed with thoroughness`,
203
+ complex: `## Effort Scaling: COMPLEX TASK
204
+ - Spawn ${recommendation.agentCount.min}-${recommendation.agentCount.max} subagents with clear delegation specs
205
+ - Use parallel execution where possible
206
+ - Quality gate each result before synthesis
207
+ - Consider a researcher agent to scope the work first
208
+ - Extended thinking recommended for planning`,
209
+ deep_research: `## Effort Scaling: DEEP RESEARCH TASK
210
+ - Consider swarm mode for ${recommendation.agentCount.min}+ parallel agents
211
+ - Budget for extended exploration and multiple passes
212
+ - Use researcher agents to scope before implementation
213
+ - Multiple review waves for quality assurance
214
+ - Extended thinking strongly recommended`,
215
+ };
216
+ return guidelines[tier];
217
+ }
218
+ /**
219
+ * Create a complexity classifier with custom thresholds.
220
+ */
221
+ export function createComplexityClassifier(config) {
222
+ const thresholds = {
223
+ simple: config?.simpleThreshold ?? 0.5,
224
+ medium: config?.mediumThreshold ?? 1.5,
225
+ complex: config?.complexThreshold ?? 2.5,
226
+ };
227
+ return {
228
+ classify: (task, context) => classifyComplexity(task, context),
229
+ getScalingGuidance,
230
+ thresholds,
231
+ };
232
+ }
233
+ //# sourceMappingURL=complexity-classifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complexity-classifier.js","sourceRoot":"","sources":["../../../src/integrations/complexity-classifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAsDH,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,+CAA+C;AAC/C,MAAM,gBAAgB,GAAG;IACvB,wBAAwB;IACxB,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU;IACxD,aAAa,EAAE,YAAY,EAAE,aAAa;IAC1C,cAAc;IACd,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ;IACpD,eAAe,EAAE,YAAY,EAAE,aAAa;IAC5C,aAAa;IACb,OAAO,EAAE,MAAM,EAAE,YAAY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AG;QACtC,MAAM,EAAE,MAAM,EAAE,eAAe,IAAI,GAAG;QACtC,OAAO,EAAE,MAAM,EAAE,gBAAgB,IAAI,GAAG;KACzC,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,CAAC,IAAY,EAAE,OAA+B,EAAE,EAAE,CAC1D,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC;QACnC,kBAAkB;QAClB,UAAU;KACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Structured Delegation Protocol
3
+ *
4
+ * Provides a structured interface for delegating tasks to subagents,
5
+ * inspired by Anthropic's multi-agent research system.
6
+ *
7
+ * Instead of passing freeform task strings, the orchestrator creates
8
+ * a DelegationSpec that explicitly communicates:
9
+ * - Clear objective and success criteria
10
+ * - Expected output format
11
+ * - Tool guidance (what to use, what to avoid)
12
+ * - Task boundaries (in-scope vs out-of-scope)
13
+ * - Sibling context (what other agents are doing)
14
+ */
15
+ /**
16
+ * Structured delegation spec for subagent tasks.
17
+ * Every field is intentionally explicit to prevent vague delegations.
18
+ */
19
+ export interface DelegationSpec {
20
+ /** One-sentence objective: what the subagent must accomplish */
21
+ objective: string;
22
+ /** Detailed context: why this task matters, how it fits the bigger picture */
23
+ context: string;
24
+ /** Expected output format */
25
+ outputFormat: OutputFormatSpec;
26
+ /** Tools and sources guidance */
27
+ toolGuidance: ToolGuidance;
28
+ /** Explicit task boundaries */
29
+ boundaries: TaskBoundaries;
30
+ /** How to know when done */
31
+ successCriteria: string[];
32
+ /** What other agents are doing (prevents duplicate work) */
33
+ siblingContext?: SiblingContext;
34
+ }
35
+ export interface OutputFormatSpec {
36
+ /** Format type */
37
+ type: 'structured_json' | 'markdown_report' | 'code_changes' | 'free_text';
38
+ /** Schema or template for expected output */
39
+ schema?: string;
40
+ /** Example of good output */
41
+ example?: string;
42
+ }
43
+ export interface ToolGuidance {
44
+ /** Tools the agent should use */
45
+ recommended: string[];
46
+ /** Tools the agent should avoid (with reason) */
47
+ avoid?: Array<{
48
+ tool: string;
49
+ reason: string;
50
+ }>;
51
+ /** Specific sources/files to consult */
52
+ sources?: string[];
53
+ }
54
+ export interface TaskBoundaries {
55
+ /** What to include in scope */
56
+ inScope: string[];
57
+ /** What to explicitly exclude */
58
+ outOfScope: string[];
59
+ /** Maximum depth of exploration */
60
+ maxExplorationDepth?: 'shallow' | 'moderate' | 'deep';
61
+ }
62
+ export interface SiblingContext {
63
+ /** Brief description of what other agents are working on */
64
+ siblingTasks: Array<{
65
+ agent: string;
66
+ task: string;
67
+ }>;
68
+ /** Files claimed by other agents (do not modify) */
69
+ claimedFiles?: string[];
70
+ }
71
+ /**
72
+ * Convert a DelegationSpec into a structured prompt for a subagent.
73
+ * The output is injected into the subagent's system prompt or task description.
74
+ */
75
+ export declare function buildDelegationPrompt(spec: DelegationSpec): string;
76
+ /**
77
+ * Create a minimal DelegationSpec from a task string.
78
+ * Used as a fallback when the orchestrator doesn't provide a full spec.
79
+ */
80
+ export declare function createMinimalDelegationSpec(task: string, agentType?: string): DelegationSpec;
81
+ /**
82
+ * Delegation protocol instructions for the orchestrator's system prompt.
83
+ * Teaches the lead agent HOW to delegate effectively.
84
+ */
85
+ export declare const DELEGATION_INSTRUCTIONS = "\n## Delegation Protocol\n\nWhen using spawn_agent, provide structured delegation:\n\n1. **OBJECTIVE**: One clear sentence of what the agent must accomplish\n2. **CONTEXT**: Why this matters and how it fits the bigger picture\n3. **OUTPUT FORMAT**: What the result should look like (JSON/markdown/code)\n4. **TOOLS**: Which tools to use and which to avoid\n5. **BOUNDARIES**: What is in-scope vs out-of-scope\n6. **SUCCESS CRITERIA**: How to know when done\n\nInclude a delegationSpec in the spawn_agent call for best results.\nWhen spawning multiple agents, describe what siblings are working on\nto prevent duplicate effort.\n";
86
+ //# sourceMappingURL=delegation-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation-protocol.d.ts","sourceRoot":"","sources":["../../../src/integrations/delegation-protocol.ts"],"names":[],"mappings":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CAAA;KAAE,CAAC,CAAC;IACrD,oDAAoD;IACpD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAMD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAsDlE;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,GACjB,cAAc,CAchB;AAsBD;;;GAGG;AACH,eAAO,MAAM,uBAAuB,ynBAenC,CAAC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Structured Delegation Protocol
3
+ *
4
+ * Provides a structured interface for delegating tasks to subagents,
5
+ * inspired by Anthropic's multi-agent research system.
6
+ *
7
+ * Instead of passing freeform task strings, the orchestrator creates
8
+ * a DelegationSpec that explicitly communicates:
9
+ * - Clear objective and success criteria
10
+ * - Expected output format
11
+ * - Tool guidance (what to use, what to avoid)
12
+ * - Task boundaries (in-scope vs out-of-scope)
13
+ * - Sibling context (what other agents are doing)
14
+ */
15
+ // =============================================================================
16
+ // BUILDER
17
+ // =============================================================================
18
+ /**
19
+ * Convert a DelegationSpec into a structured prompt for a subagent.
20
+ * The output is injected into the subagent's system prompt or task description.
21
+ */
22
+ export function buildDelegationPrompt(spec) {
23
+ const sections = [];
24
+ // Objective
25
+ sections.push(`## OBJECTIVE\n${spec.objective}`);
26
+ // Context
27
+ if (spec.context) {
28
+ sections.push(`## CONTEXT\n${spec.context}`);
29
+ }
30
+ // Output Format
31
+ sections.push(`## EXPECTED OUTPUT\nFormat: ${spec.outputFormat.type}`);
32
+ if (spec.outputFormat.schema) {
33
+ sections.push(`Schema:\n\`\`\`\n${spec.outputFormat.schema}\n\`\`\``);
34
+ }
35
+ if (spec.outputFormat.example) {
36
+ sections.push(`Example:\n\`\`\`\n${spec.outputFormat.example}\n\`\`\``);
37
+ }
38
+ // Tool Guidance
39
+ if (spec.toolGuidance.recommended.length > 0) {
40
+ sections.push(`## RECOMMENDED TOOLS\n${spec.toolGuidance.recommended.map(t => `- ${t}`).join('\n')}`);
41
+ }
42
+ if (spec.toolGuidance.avoid && spec.toolGuidance.avoid.length > 0) {
43
+ sections.push(`## TOOLS TO AVOID\n${spec.toolGuidance.avoid.map(a => `- ${a.tool}: ${a.reason}`).join('\n')}`);
44
+ }
45
+ if (spec.toolGuidance.sources && spec.toolGuidance.sources.length > 0) {
46
+ sections.push(`## KEY SOURCES\n${spec.toolGuidance.sources.map(s => `- ${s}`).join('\n')}`);
47
+ }
48
+ // Boundaries
49
+ sections.push(`## SCOPE`);
50
+ sections.push(`In scope:\n${spec.boundaries.inScope.map(s => `- ${s}`).join('\n')}`);
51
+ sections.push(`Out of scope:\n${spec.boundaries.outOfScope.map(s => `- ${s}`).join('\n')}`);
52
+ if (spec.boundaries.maxExplorationDepth) {
53
+ sections.push(`Exploration depth: ${spec.boundaries.maxExplorationDepth}`);
54
+ }
55
+ // Success Criteria
56
+ sections.push(`## SUCCESS CRITERIA\n${spec.successCriteria.map((c, i) => `${i + 1}. ${c}`).join('\n')}`);
57
+ // Sibling Context
58
+ if (spec.siblingContext) {
59
+ sections.push(`## SIBLING AGENTS (avoid duplicate work)`);
60
+ for (const sibling of spec.siblingContext.siblingTasks) {
61
+ sections.push(`- ${sibling.agent}: ${sibling.task}`);
62
+ }
63
+ if (spec.siblingContext.claimedFiles && spec.siblingContext.claimedFiles.length > 0) {
64
+ sections.push(`\nClaimed files (DO NOT modify):\n${spec.siblingContext.claimedFiles.map(f => `- ${f}`).join('\n')}`);
65
+ }
66
+ }
67
+ return sections.join('\n\n');
68
+ }
69
+ /**
70
+ * Create a minimal DelegationSpec from a task string.
71
+ * Used as a fallback when the orchestrator doesn't provide a full spec.
72
+ */
73
+ export function createMinimalDelegationSpec(task, agentType) {
74
+ return {
75
+ objective: task,
76
+ context: '',
77
+ outputFormat: { type: 'free_text' },
78
+ toolGuidance: {
79
+ recommended: getDefaultToolsForAgent(agentType),
80
+ },
81
+ boundaries: {
82
+ inScope: [task],
83
+ outOfScope: ['Changes outside the immediate task scope'],
84
+ },
85
+ successCriteria: ['Task objective is fully addressed'],
86
+ };
87
+ }
88
+ /**
89
+ * Get default recommended tools based on agent type.
90
+ */
91
+ function getDefaultToolsForAgent(agentType) {
92
+ switch (agentType) {
93
+ case 'researcher':
94
+ return ['read_file', 'glob', 'grep', 'list_files'];
95
+ case 'coder':
96
+ return ['read_file', 'write_file', 'edit_file', 'bash', 'glob', 'grep'];
97
+ case 'reviewer':
98
+ return ['read_file', 'glob', 'grep'];
99
+ case 'architect':
100
+ return ['read_file', 'glob', 'grep', 'list_files'];
101
+ case 'debugger':
102
+ return ['read_file', 'bash', 'glob', 'grep', 'edit_file'];
103
+ default:
104
+ return ['read_file', 'glob', 'grep'];
105
+ }
106
+ }
107
+ /**
108
+ * Delegation protocol instructions for the orchestrator's system prompt.
109
+ * Teaches the lead agent HOW to delegate effectively.
110
+ */
111
+ export const DELEGATION_INSTRUCTIONS = `
112
+ ## Delegation Protocol
113
+
114
+ When using spawn_agent, provide structured delegation:
115
+
116
+ 1. **OBJECTIVE**: One clear sentence of what the agent must accomplish
117
+ 2. **CONTEXT**: Why this matters and how it fits the bigger picture
118
+ 3. **OUTPUT FORMAT**: What the result should look like (JSON/markdown/code)
119
+ 4. **TOOLS**: Which tools to use and which to avoid
120
+ 5. **BOUNDARIES**: What is in-scope vs out-of-scope
121
+ 6. **SUCCESS CRITERIA**: How to know when done
122
+
123
+ Include a delegationSpec in the spawn_agent call for best results.
124
+ When spawning multiple agents, describe what siblings are working on
125
+ to prevent duplicate effort.
126
+ `;
127
+ //# sourceMappingURL=delegation-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation-protocol.js","sourceRoot":"","sources":["../../../src/integrations/delegation-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAmEH,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CA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K,OAAO;YACV,OAAO,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC1E,KAAK,UAAU;YACb,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACvC,KAAK,WAAW;YACd,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;QACrD,KAAK,UAAU;YACb,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC5D;YACE,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;CAetC,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Dynamic Budget Rebalancing
3
+ *
4
+ * Extends SharedBudgetPool with dynamic rebalancing that prevents
5
+ * starvation when spawning subagents sequentially.
6
+ *
7
+ * Key features:
8
+ * - setExpectedChildren(count) for upfront capacity planning
9
+ * - Sequential spawn cap: never take >60% of remaining budget
10
+ * - Rebalance on child completion (return unused budget to pool)
11
+ * - Priority-based allocation (critical children get more)
12
+ */
13
+ import { SharedBudgetPool, type BudgetPoolConfig, type BudgetAllocation, type BudgetPoolStats } from './budget-pool.js';
14
+ export interface DynamicBudgetConfig extends BudgetPoolConfig {
15
+ /** Maximum percentage of remaining budget for any single child (default: 0.6) */
16
+ maxRemainingRatio: number;
17
+ /** Minimum tokens to reserve for each expected child (default: 10000) */
18
+ minPerExpectedChild: number;
19
+ /** Enable automatic rebalancing on release (default: true) */
20
+ autoRebalance: boolean;
21
+ }
22
+ export interface ChildPriority {
23
+ /** Child ID */
24
+ childId: string;
25
+ /** Priority level (higher = more budget) */
26
+ priority: 'low' | 'normal' | 'high' | 'critical';
27
+ /** Expected token usage (optional hint) */
28
+ expectedTokens?: number;
29
+ }
30
+ export interface RebalanceResult {
31
+ /** Children that had their allocations adjusted */
32
+ adjusted: Array<{
33
+ childId: string;
34
+ oldBudget: number;
35
+ newBudget: number;
36
+ }>;
37
+ /** Tokens freed by rebalancing */
38
+ tokensFreed: number;
39
+ }
40
+ export declare class DynamicBudgetPool extends SharedBudgetPool {
41
+ private dynamicConfig;
42
+ private expectedChildren;
43
+ private spawnedCount;
44
+ private completedCount;
45
+ private childPriorities;
46
+ constructor(config: BudgetPoolConfig & Partial<DynamicBudgetConfig>);
47
+ /**
48
+ * Set the expected number of children for capacity planning.
49
+ * This adjusts maxPerChild to ensure fair distribution.
50
+ */
51
+ setExpectedChildren(count: number): void;
52
+ /**
53
+ * Set priority for a child agent.
54
+ */
55
+ setChildPriority(priority: ChildPriority): void;
56
+ /**
57
+ * Reserve with dynamic capacity planning.
58
+ * Respects expected children and remaining ratio cap.
59
+ */
60
+ reserveDynamic(childId: string, priority?: ChildPriority['priority']): BudgetAllocation | null;
61
+ /**
62
+ * Release with optional auto-rebalancing.
63
+ */
64
+ releaseDynamic(childId: string): void;
65
+ /**
66
+ * Get enhanced stats including dynamic info.
67
+ */
68
+ getDynamicStats(): BudgetPoolStats & {
69
+ expectedChildren: number;
70
+ spawnedCount: number;
71
+ completedCount: number;
72
+ pendingCount: number;
73
+ avgPerChild: number;
74
+ };
75
+ private updateMaxPerChild;
76
+ }
77
+ /**
78
+ * Create a dynamic budget pool from a parent's budget.
79
+ */
80
+ export declare function createDynamicBudgetPool(parentBudgetTokens: number, parentReserveRatio?: number, config?: Partial<DynamicBudgetConfig>): DynamicBudgetPool;
81
+ //# sourceMappingURL=dynamic-budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-budget.d.ts","sourceRoot":"","sources":["../../../src/integrations/dynamic-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,KAAK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