aegiscode 3.1.7 → 3.1.10

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 (206) hide show
  1. package/README.md +23 -15
  2. package/dist/main.js +555 -556
  3. package/package.json +4 -2
  4. package/src/agent/Agent.ts +903 -0
  5. package/src/agent/SimpleAgent.ts +48 -0
  6. package/src/agent/index.ts +54 -0
  7. package/src/agent/orchestrator/AppBuilder.ts +443 -0
  8. package/src/agent/orchestrator/CouncilAgent.ts +310 -0
  9. package/src/agent/orchestrator/DiscussionRoom.ts +462 -0
  10. package/src/agent/orchestrator/OrchestratorAgent.ts +637 -0
  11. package/src/agent/orchestrator/index.ts +38 -0
  12. package/src/agent/orchestrator/utils.ts +397 -0
  13. package/src/agent/pricing.ts +115 -0
  14. package/src/agent/router.ts +74 -0
  15. package/src/agent/routerStats.ts +121 -0
  16. package/src/agent/types.ts +318 -0
  17. package/src/auth/login.ts +383 -0
  18. package/src/cli/config.ts +189 -0
  19. package/src/cli/index.ts +17 -0
  20. package/src/cli/middleware.ts +119 -0
  21. package/src/cli/types.ts +75 -0
  22. package/src/config/ConfigManager.ts +587 -0
  23. package/src/config/index.ts +7 -0
  24. package/src/config/types.ts +584 -0
  25. package/src/context/CompactionService.ts +300 -0
  26. package/src/context/ContextManager.ts +450 -0
  27. package/src/context/FileAnalyzer.ts +267 -0
  28. package/src/context/TokenCounter.ts +265 -0
  29. package/src/context/index.ts +27 -0
  30. package/src/context/storage/CacheStore.ts +176 -0
  31. package/src/context/storage/JSONLStore.ts +201 -0
  32. package/src/context/storage/MemoryStore.ts +205 -0
  33. package/src/context/storage/PersistentStore.ts +327 -0
  34. package/src/context/storage/index.ts +9 -0
  35. package/src/context/storage/pathUtils.ts +114 -0
  36. package/src/context/test.ts +309 -0
  37. package/src/context/types.ts +268 -0
  38. package/src/hooks/HookExecutor.ts +434 -0
  39. package/src/hooks/HookManager.ts +596 -0
  40. package/src/hooks/HookService.ts +269 -0
  41. package/src/hooks/Matcher.ts +157 -0
  42. package/src/hooks/index.ts +63 -0
  43. package/src/hooks/types.ts +424 -0
  44. package/src/main.tsx +596 -0
  45. package/src/mcp/HealthMonitor.ts +150 -0
  46. package/src/mcp/McpClient.ts +491 -0
  47. package/src/mcp/McpRegistry.ts +321 -0
  48. package/src/mcp/createMcpTool.ts +251 -0
  49. package/src/mcp/index.ts +15 -0
  50. package/src/mcp/server.ts +334 -0
  51. package/src/mcp/test-server.ts +88 -0
  52. package/src/mcp/test.ts +372 -0
  53. package/src/mcp/types.ts +247 -0
  54. package/src/memory/AgentMemoryBus.ts +432 -0
  55. package/src/memory/CloudSync.ts +99 -0
  56. package/src/memory/DriveSync.ts +106 -0
  57. package/src/memory/SharedMemory.ts +951 -0
  58. package/src/memory/index.ts +14 -0
  59. package/src/memory/machineFingerprint.ts +40 -0
  60. package/src/orchestrator/SubAgentMetadata.ts +136 -0
  61. package/src/prompts/builder.ts +213 -0
  62. package/src/prompts/default.ts +144 -0
  63. package/src/prompts/index.ts +16 -0
  64. package/src/prompts/plan.ts +64 -0
  65. package/src/prompts/test.ts +78 -0
  66. package/src/services/AnthropicChatService.ts +341 -0
  67. package/src/services/ChatService.ts +347 -0
  68. package/src/services/ClaudeCliChatService.ts +256 -0
  69. package/src/services/CloudSync.ts +168 -0
  70. package/src/services/CostLedger.ts +211 -0
  71. package/src/services/Heartbeat.ts +135 -0
  72. package/src/services/LearningCollector.ts +291 -0
  73. package/src/services/OllamaInstaller.ts +342 -0
  74. package/src/services/VersionChecker.ts +445 -0
  75. package/src/services/index.ts +57 -0
  76. package/src/services/streaming/OpenAIEventAdapter.ts +126 -0
  77. package/src/services/streaming/RenderingProfile.ts +90 -0
  78. package/src/services/streaming/StreamEventParser.ts +181 -0
  79. package/src/services/streaming/ThrottledRenderer.ts +139 -0
  80. package/src/services/streaming/TranscriptBuffer.ts +574 -0
  81. package/src/services/streaming/eventStatusMap.ts +52 -0
  82. package/src/services/streaming/index.ts +46 -0
  83. package/src/services/streaming/renderFormatting.ts +79 -0
  84. package/src/services/streaming/types.ts +234 -0
  85. package/src/skills/SkillLoader.ts +126 -0
  86. package/src/skills/SkillRegistry.ts +366 -0
  87. package/src/skills/index.ts +48 -0
  88. package/src/skills/types.ts +146 -0
  89. package/src/slash-commands/billing.ts +70 -0
  90. package/src/slash-commands/build.ts +413 -0
  91. package/src/slash-commands/builtinCommands.ts +2733 -0
  92. package/src/slash-commands/clone.ts +242 -0
  93. package/src/slash-commands/council.ts +125 -0
  94. package/src/slash-commands/custom/CustomCommandExecutor.ts +143 -0
  95. package/src/slash-commands/custom/CustomCommandLoader.ts +251 -0
  96. package/src/slash-commands/custom/CustomCommandRegistry.ts +144 -0
  97. package/src/slash-commands/custom/index.ts +7 -0
  98. package/src/slash-commands/debate.ts +254 -0
  99. package/src/slash-commands/gmail.ts +105 -0
  100. package/src/slash-commands/index.ts +388 -0
  101. package/src/slash-commands/mcpCommand.ts +205 -0
  102. package/src/slash-commands/types.ts +201 -0
  103. package/src/store/index.ts +76 -0
  104. package/src/store/selectors.ts +246 -0
  105. package/src/store/slices/appSlice.ts +205 -0
  106. package/src/store/slices/commandSlice.ts +115 -0
  107. package/src/store/slices/configSlice.ts +46 -0
  108. package/src/store/slices/focusSlice.ts +64 -0
  109. package/src/store/slices/index.ts +9 -0
  110. package/src/store/slices/sessionSlice.ts +424 -0
  111. package/src/store/streaming-buffer.ts +425 -0
  112. package/src/store/test.ts +296 -0
  113. package/src/store/types.ts +274 -0
  114. package/src/store/vanilla.ts +186 -0
  115. package/src/tools/builtin/bash.ts +236 -0
  116. package/src/tools/builtin/council.ts +105 -0
  117. package/src/tools/builtin/edit.ts +213 -0
  118. package/src/tools/builtin/glob.ts +136 -0
  119. package/src/tools/builtin/grep.ts +263 -0
  120. package/src/tools/builtin/index.ts +61 -0
  121. package/src/tools/builtin/memory.ts +66 -0
  122. package/src/tools/builtin/read.ts +168 -0
  123. package/src/tools/builtin/skill.ts +97 -0
  124. package/src/tools/builtin/snapshot.ts +40 -0
  125. package/src/tools/builtin/task.ts +106 -0
  126. package/src/tools/builtin/write.ts +134 -0
  127. package/src/tools/createTool.ts +221 -0
  128. package/src/tools/execution/ExecutionPipeline.ts +263 -0
  129. package/src/tools/execution/index.ts +40 -0
  130. package/src/tools/execution/stages/CacheStage.ts +131 -0
  131. package/src/tools/execution/stages/ConfirmationStage.ts +203 -0
  132. package/src/tools/execution/stages/DiscoveryStage.ts +46 -0
  133. package/src/tools/execution/stages/ExecutionStage.ts +48 -0
  134. package/src/tools/execution/stages/FormattingStage.ts +44 -0
  135. package/src/tools/execution/stages/HookStage.ts +72 -0
  136. package/src/tools/execution/stages/PermissionStage.ts +287 -0
  137. package/src/tools/execution/stages/PostHookStage.ts +71 -0
  138. package/src/tools/execution/stages/index.ts +12 -0
  139. package/src/tools/execution/test.ts +266 -0
  140. package/src/tools/execution/types.ts +273 -0
  141. package/src/tools/index.ts +81 -0
  142. package/src/tools/registry.ts +304 -0
  143. package/src/tools/schemas.ts +109 -0
  144. package/src/tools/test.ts +220 -0
  145. package/src/tools/types.ts +175 -0
  146. package/src/tools/validation/PermissionChecker.ts +242 -0
  147. package/src/tools/validation/SensitiveFileDetector.ts +210 -0
  148. package/src/tools/validation/index.ts +11 -0
  149. package/src/ui/App.tsx +166 -0
  150. package/src/ui/components/AegisInterface.tsx +484 -0
  151. package/src/ui/components/common/ChatSearch.tsx +150 -0
  152. package/src/ui/components/common/ErrorBoundary.tsx +82 -0
  153. package/src/ui/components/common/ExitMessage.tsx +120 -0
  154. package/src/ui/components/common/LoadingIndicator.tsx +49 -0
  155. package/src/ui/components/common/index.ts +6 -0
  156. package/src/ui/components/dialog/ConfirmationPrompt.tsx +208 -0
  157. package/src/ui/components/dialog/InteractiveSelector.tsx +149 -0
  158. package/src/ui/components/dialog/SetupWizard.tsx +297 -0
  159. package/src/ui/components/dialog/UpdatePrompt.tsx +155 -0
  160. package/src/ui/components/dialog/index.ts +8 -0
  161. package/src/ui/components/index.ts +28 -0
  162. package/src/ui/components/input/CommandSuggestions.tsx +139 -0
  163. package/src/ui/components/input/CustomTextInput.tsx +220 -0
  164. package/src/ui/components/input/InputArea.tsx +361 -0
  165. package/src/ui/components/input/PromptSuggestions.tsx +66 -0
  166. package/src/ui/components/input/index.ts +6 -0
  167. package/src/ui/components/layout/ChatStatusBar.tsx +90 -0
  168. package/src/ui/components/layout/ContextBar.tsx +79 -0
  169. package/src/ui/components/layout/MessageArea.tsx +96 -0
  170. package/src/ui/components/layout/MessageList.tsx +647 -0
  171. package/src/ui/components/layout/MessageSeparator.tsx +26 -0
  172. package/src/ui/components/layout/WelcomeMessage.tsx +93 -0
  173. package/src/ui/components/layout/index.ts +7 -0
  174. package/src/ui/components/markdown/CodeHighlighter.tsx +292 -0
  175. package/src/ui/components/markdown/MessageRenderer.tsx +1211 -0
  176. package/src/ui/components/markdown/index.ts +8 -0
  177. package/src/ui/components/markdown/parser.ts +336 -0
  178. package/src/ui/components/markdown/types.ts +66 -0
  179. package/src/ui/focus/FocusManager.ts +137 -0
  180. package/src/ui/focus/index.ts +13 -0
  181. package/src/ui/focus/types.ts +54 -0
  182. package/src/ui/focus/useFocus.ts +75 -0
  183. package/src/ui/hooks/index.ts +11 -0
  184. package/src/ui/hooks/useAgent.ts +284 -0
  185. package/src/ui/hooks/useCommandHistory.ts +87 -0
  186. package/src/ui/hooks/useCommandProcessor.ts +443 -0
  187. package/src/ui/hooks/useConfirmation.ts +99 -0
  188. package/src/ui/hooks/useCtrlCHandler.ts +100 -0
  189. package/src/ui/hooks/useInputBuffer.ts +122 -0
  190. package/src/ui/hooks/useTerminalSize.ts +68 -0
  191. package/src/ui/hooks/useTerminalWidth.ts +5 -0
  192. package/src/ui/hooks/useWindowedList.ts +118 -0
  193. package/src/ui/render-debugger.ts +621 -0
  194. package/src/ui/test.ts +189 -0
  195. package/src/ui/themes/ThemeManager.ts +332 -0
  196. package/src/ui/themes/aegisTheme.ts +87 -0
  197. package/src/ui/themes/darkTheme.ts +87 -0
  198. package/src/ui/themes/defaultTheme.ts +85 -0
  199. package/src/ui/themes/index.ts +10 -0
  200. package/src/ui/themes/lightTheme.ts +89 -0
  201. package/src/ui/themes/popularThemes.ts +187 -0
  202. package/src/ui/themes/types.ts +130 -0
  203. package/src/utils/clipboard.ts +48 -0
  204. package/src/utils/debug.ts +43 -0
  205. package/src/utils/environment.ts +68 -0
  206. package/src/utils/index.ts +10 -0
@@ -0,0 +1,310 @@
1
+ /**
2
+ * CouncilAgent — Multi-agent deliberation and voting
3
+ *
4
+ * Upgraded from /council slash-command into a programmable
5
+ * deliberation system that can be invoked from the agent loop.
6
+ *
7
+ * Features:
8
+ * - Configurable roles with custom system prompts
9
+ * - Weighted voting (each agent can have a vote weight)
10
+ * - Structured deliberation with reasoning
11
+ * - Customizable voting rules (consensus, majority, supermajority)
12
+ */
13
+
14
+ import type { AgentConfig } from '../types.js';
15
+ import { agentDebug } from '../../utils/debug.js';
16
+ import { OrchestratorAgent, type SubAgentConfig } from './OrchestratorAgent.js';
17
+
18
+ // ========== Types ==========
19
+
20
+ export type VoteValue = 'approve' | 'reject' | 'abstain';
21
+
22
+ export interface VoteResult {
23
+ agentName: string;
24
+ role: string;
25
+ vote: VoteValue;
26
+ reasoning: string;
27
+ weight: number;
28
+ color: string;
29
+ }
30
+
31
+ export interface DeliberationConfig {
32
+ /** Rule for determining outcome */
33
+ rule: 'majority' | 'supermajority' | 'unanimous' | 'weighted';
34
+ /** For supermajority: fraction required (e.g., 0.66) */
35
+ supermajorityThreshold?: number;
36
+ /** Max tokens per agent response */
37
+ maxTokensPerAgent?: number;
38
+ /** Whether agents see each other's votes (for iteration) */
39
+ enableIteration?: boolean;
40
+ /** Max deliberation rounds */
41
+ maxRounds?: number;
42
+ }
43
+
44
+ export interface DeliberationResult {
45
+ approved: boolean;
46
+ voteResults: VoteResult[];
47
+ summary: string;
48
+ config: DeliberationConfig;
49
+ rounds: number;
50
+ }
51
+
52
+ // ========== Constants ==========
53
+
54
+ const COLORS = [
55
+ '\x1b[38;2;0;229;192m', // teal
56
+ '\x1b[38;2;124;111;212m', // purple
57
+ '\x1b[38;2;244;114;182m', // pink
58
+ '\x1b[38;2;249;115;22m', // orange
59
+ '\x1b[38;2;34;197;94m', // green
60
+ '\x1b[38;2;239;68;68m', // red
61
+ '\x1b[38;2;56;189;248m', // sky
62
+ '\x1b[38;2;250;204;21m', // yellow
63
+ ];
64
+
65
+ // ========== Council Agent ==========
66
+
67
+ export class CouncilAgent {
68
+ private orchestrator: OrchestratorAgent;
69
+ private config: DeliberationConfig;
70
+ private agentRoles: Map<string, { role: string; weight: number; color: string }> = new Map();
71
+
72
+ constructor(
73
+ name: string,
74
+ orchestratorConfig: AgentConfig,
75
+ deliberationConfig: Partial<DeliberationConfig> = {}
76
+ ) {
77
+ this.orchestrator = new OrchestratorAgent(
78
+ name,
79
+ 'You are the AEGIS Council moderator. Synthesize deliberation results.'
80
+ );
81
+ this.config = {
82
+ rule: 'majority',
83
+ maxTokensPerAgent: 300,
84
+ enableIteration: false,
85
+ maxRounds: 1,
86
+ ...deliberationConfig,
87
+ };
88
+ }
89
+
90
+ /**
91
+ * Register a council member with a specific role and vote weight
92
+ */
93
+ addMember(
94
+ name: string,
95
+ role: string,
96
+ systemPrompt: string,
97
+ weight: number = 1,
98
+ config: AgentConfig,
99
+ tools?: string[],
100
+ ): void {
101
+ const colorIndex = this.agentRoles.size % COLORS.length;
102
+ const color = COLORS[colorIndex];
103
+
104
+ const subConfig: SubAgentConfig = {
105
+ name,
106
+ role,
107
+ systemPrompt,
108
+ config,
109
+ tools,
110
+ };
111
+
112
+ this.orchestrator.registerAgent(subConfig);
113
+ this.agentRoles.set(name, { role, weight, color });
114
+ }
115
+
116
+ /**
117
+ * Remove a council member
118
+ */
119
+ removeMember(name: string): void {
120
+ this.orchestrator.unregisterAgent(name);
121
+ this.agentRoles.delete(name);
122
+ }
123
+
124
+ /**
125
+ * Get all registered council members
126
+ */
127
+ getMembers(): { name: string; role: string; weight: number }[] {
128
+ return Array.from(this.agentRoles.entries()).map(([name, info]) => ({
129
+ name,
130
+ role: info.role,
131
+ weight: info.weight,
132
+ }));
133
+ }
134
+
135
+ /**
136
+ * Convene the council to deliberate on a question
137
+ */
138
+ async deliberate(question: string, sessionId?: string): Promise<DeliberationResult> {
139
+ const members = this.getMembers();
140
+ if (members.length === 0) {
141
+ throw new Error('CouncilAgent: No members registered. Add members before deliberating.');
142
+ }
143
+
144
+ let allResults: VoteResult[] = [];
145
+ const rounds = Math.min(this.config.maxRounds || 1, 3);
146
+
147
+ for (let round = 0; round < rounds; round++) {
148
+ const subTasks: Record<string, string> = {};
149
+
150
+ for (const member of members) {
151
+ const previousContext = round > 0
152
+ ? allResults
153
+ .map(r => `${r.agentName} (${r.role}): Voted ${r.vote} — ${r.reasoning}`)
154
+ .join('\n')
155
+ : '';
156
+
157
+ subTasks[member.name] = this.config.enableIteration && previousContext
158
+ ? `Question: "${question}"\n\nPrevious round votes:\n${previousContext}\n\nBased on the discussion, state your FINAL VOTE and reasoning.\nRespond with:\nVOTE: approve, reject, or abstain\nREASONING: 1-3 sentences explaining your position.`
159
+ : `Question: "${question}"\n\nState your vote and reasoning.\nRespond with:\nVOTE: approve, reject, or abstain\nREASONING: 1-3 sentences explaining your position.`;
160
+ }
161
+
162
+ const orchestration = await this.orchestrator.orchestrate(
163
+ question,
164
+ subTasks,
165
+ members[0]?.name,
166
+ sessionId,
167
+ );
168
+
169
+ // Parse votes from responses
170
+ allResults = orchestration.responses.map(r => {
171
+ const info = this.agentRoles.get(r.agentName);
172
+ const content = r.content || '';
173
+ const vote: VoteValue = content.includes('VOTE: approve')
174
+ ? 'approve'
175
+ : content.includes('VOTE: reject')
176
+ ? 'reject'
177
+ : 'abstain';
178
+ const reasoning = content.split('REASONING:')[1]
179
+ ? content.split('REASONING:')[1].trim().slice(0, 300)
180
+ : content.slice(0, 200);
181
+
182
+ return {
183
+ agentName: r.agentName,
184
+ role: info?.role || 'member',
185
+ vote,
186
+ reasoning,
187
+ weight: info?.weight || 1,
188
+ color: info?.color || COLORS[0],
189
+ };
190
+ });
191
+
192
+ // Check if consensus reached early (for iterative mode)
193
+ if (this.config.enableIteration && this.evaluateDecision(allResults).settled) {
194
+ break;
195
+ }
196
+ }
197
+
198
+ const decision = this.evaluateDecision(allResults);
199
+ const summary = this.buildSummary(question, allResults, decision);
200
+
201
+ return {
202
+ approved: decision.approved,
203
+ voteResults: allResults,
204
+ summary,
205
+ config: this.config,
206
+ rounds,
207
+ };
208
+ }
209
+
210
+ // ========== Private ==========
211
+
212
+ private evaluateDecision(votes: VoteResult[]): {
213
+ approved: boolean;
214
+ settled: boolean;
215
+ for: number;
216
+ against: number;
217
+ abstained: number;
218
+ } {
219
+ let forWeight = 0;
220
+ let againstWeight = 0;
221
+ let abstainedWeight = 0;
222
+ let forCount = 0;
223
+ let againstCount = 0;
224
+ let abstainedCount = 0;
225
+
226
+ for (const v of votes) {
227
+ switch (v.vote) {
228
+ case 'approve':
229
+ forWeight += v.weight;
230
+ forCount++;
231
+ break;
232
+ case 'reject':
233
+ againstWeight += v.weight;
234
+ againstCount++;
235
+ break;
236
+ case 'abstain':
237
+ abstainedWeight += v.weight;
238
+ abstainedCount++;
239
+ break;
240
+ }
241
+ }
242
+
243
+ const totalWeight = forWeight + againstWeight + abstainedWeight;
244
+ const totalVoting = forWeight + againstWeight;
245
+ const totalCount = forCount + againstCount + abstainedCount;
246
+
247
+ switch (this.config.rule) {
248
+ case 'unanimous':
249
+ return {
250
+ approved: forCount === totalCount && forCount > 0,
251
+ settled: true,
252
+ for: forCount,
253
+ against: againstCount,
254
+ abstained: abstainedCount,
255
+ };
256
+ case 'supermajority': {
257
+ const threshold = this.config.supermajorityThreshold || 0.66;
258
+ const weightedRatio = totalVoting > 0 ? forWeight / totalVoting : 0;
259
+ return {
260
+ approved: weightedRatio >= threshold,
261
+ settled: true,
262
+ for: forCount,
263
+ against: againstCount,
264
+ abstained: abstainedCount,
265
+ };
266
+ }
267
+ case 'weighted':
268
+ return {
269
+ approved: forWeight > againstWeight,
270
+ settled: true,
271
+ for: forCount,
272
+ against: againstCount,
273
+ abstained: abstainedCount,
274
+ };
275
+ case 'majority':
276
+ default:
277
+ return {
278
+ approved: forCount > againstCount,
279
+ settled: forCount !== againstCount || forCount > 0,
280
+ for: forCount,
281
+ against: againstCount,
282
+ abstained: abstainedCount,
283
+ };
284
+ }
285
+ }
286
+
287
+ private buildSummary(
288
+ question: string,
289
+ votes: VoteResult[],
290
+ decision: { approved: boolean; for: number; against: number; abstained: number }
291
+ ): string {
292
+ const lines: string[] = [];
293
+ lines.push('## ⬡ AEGIS COUNCIL');
294
+ lines.push(`**Question:** ${question}`);
295
+ lines.push('');
296
+
297
+ for (const v of votes) {
298
+ const emoji = v.vote === 'approve' ? '✅' : v.vote === 'reject' ? '❌' : '⚫';
299
+ lines.push(`${v.color}${v.agentName}${'\x1b[0m'} · ${v.role}`);
300
+ lines.push(` ${emoji} ${v.vote.toUpperCase()} (weight: ${v.weight}) — ${v.reasoning}`);
301
+ lines.push('');
302
+ }
303
+
304
+ const verdict = decision.approved ? '✅ APPROVED' : '❌ REJECTED';
305
+ lines.push('---');
306
+ lines.push(`${verdict} · ${decision.for} FOR · ${decision.against} AGAINST · ${decision.abstained} ABSTAINED`);
307
+
308
+ return lines.join('\n');
309
+ }
310
+ }