aegiscode 3.1.10 → 3.4.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.
- package/bin/aegis.js +165 -0
- package/package.json +18 -86
- package/LICENSE +0 -21
- package/README.md +0 -394
- package/dist/main.js +0 -2171
- package/gui/run-gui.cjs +0 -13
- package/src/agent/Agent.ts +0 -903
- package/src/agent/SimpleAgent.ts +0 -48
- package/src/agent/index.ts +0 -54
- package/src/agent/orchestrator/AppBuilder.ts +0 -443
- package/src/agent/orchestrator/CouncilAgent.ts +0 -310
- package/src/agent/orchestrator/DiscussionRoom.ts +0 -462
- package/src/agent/orchestrator/OrchestratorAgent.ts +0 -637
- package/src/agent/orchestrator/index.ts +0 -38
- package/src/agent/orchestrator/utils.ts +0 -397
- package/src/agent/pricing.ts +0 -115
- package/src/agent/router.ts +0 -74
- package/src/agent/routerStats.ts +0 -121
- package/src/agent/types.ts +0 -318
- package/src/auth/login.ts +0 -383
- package/src/cli/config.ts +0 -189
- package/src/cli/index.ts +0 -17
- package/src/cli/middleware.ts +0 -119
- package/src/cli/types.ts +0 -75
- package/src/config/ConfigManager.ts +0 -587
- package/src/config/index.ts +0 -7
- package/src/config/types.ts +0 -584
- package/src/context/CompactionService.ts +0 -300
- package/src/context/ContextManager.ts +0 -450
- package/src/context/FileAnalyzer.ts +0 -267
- package/src/context/TokenCounter.ts +0 -265
- package/src/context/index.ts +0 -27
- package/src/context/storage/CacheStore.ts +0 -176
- package/src/context/storage/JSONLStore.ts +0 -201
- package/src/context/storage/MemoryStore.ts +0 -205
- package/src/context/storage/PersistentStore.ts +0 -327
- package/src/context/storage/index.ts +0 -9
- package/src/context/storage/pathUtils.ts +0 -114
- package/src/context/test.ts +0 -309
- package/src/context/types.ts +0 -268
- package/src/hooks/HookExecutor.ts +0 -434
- package/src/hooks/HookManager.ts +0 -596
- package/src/hooks/HookService.ts +0 -269
- package/src/hooks/Matcher.ts +0 -157
- package/src/hooks/index.ts +0 -63
- package/src/hooks/types.ts +0 -424
- package/src/main.tsx +0 -596
- package/src/mcp/HealthMonitor.ts +0 -150
- package/src/mcp/McpClient.ts +0 -491
- package/src/mcp/McpRegistry.ts +0 -321
- package/src/mcp/createMcpTool.ts +0 -251
- package/src/mcp/index.ts +0 -15
- package/src/mcp/server.ts +0 -334
- package/src/mcp/test-server.ts +0 -88
- package/src/mcp/test.ts +0 -372
- package/src/mcp/types.ts +0 -247
- package/src/memory/AgentMemoryBus.ts +0 -432
- package/src/memory/CloudSync.ts +0 -99
- package/src/memory/DriveSync.ts +0 -106
- package/src/memory/SharedMemory.ts +0 -951
- package/src/memory/index.ts +0 -14
- package/src/memory/machineFingerprint.ts +0 -40
- package/src/orchestrator/SubAgentMetadata.ts +0 -136
- package/src/prompts/builder.ts +0 -213
- package/src/prompts/default.ts +0 -144
- package/src/prompts/index.ts +0 -16
- package/src/prompts/plan.ts +0 -64
- package/src/prompts/test.ts +0 -78
- package/src/services/AnthropicChatService.ts +0 -341
- package/src/services/ChatService.ts +0 -347
- package/src/services/ClaudeCliChatService.ts +0 -256
- package/src/services/CloudSync.ts +0 -168
- package/src/services/CostLedger.ts +0 -211
- package/src/services/Heartbeat.ts +0 -135
- package/src/services/LearningCollector.ts +0 -291
- package/src/services/OllamaInstaller.ts +0 -342
- package/src/services/VersionChecker.ts +0 -445
- package/src/services/index.ts +0 -57
- package/src/services/streaming/OpenAIEventAdapter.ts +0 -126
- package/src/services/streaming/RenderingProfile.ts +0 -90
- package/src/services/streaming/StreamEventParser.ts +0 -181
- package/src/services/streaming/ThrottledRenderer.ts +0 -139
- package/src/services/streaming/TranscriptBuffer.ts +0 -574
- package/src/services/streaming/eventStatusMap.ts +0 -52
- package/src/services/streaming/index.ts +0 -46
- package/src/services/streaming/renderFormatting.ts +0 -79
- package/src/services/streaming/types.ts +0 -234
- package/src/skills/SkillLoader.ts +0 -126
- package/src/skills/SkillRegistry.ts +0 -366
- package/src/skills/index.ts +0 -48
- package/src/skills/types.ts +0 -146
- package/src/slash-commands/billing.ts +0 -70
- package/src/slash-commands/build.ts +0 -413
- package/src/slash-commands/builtinCommands.ts +0 -2733
- package/src/slash-commands/clone.ts +0 -242
- package/src/slash-commands/council.ts +0 -125
- package/src/slash-commands/custom/CustomCommandExecutor.ts +0 -143
- package/src/slash-commands/custom/CustomCommandLoader.ts +0 -251
- package/src/slash-commands/custom/CustomCommandRegistry.ts +0 -144
- package/src/slash-commands/custom/index.ts +0 -7
- package/src/slash-commands/debate.ts +0 -254
- package/src/slash-commands/gmail.ts +0 -105
- package/src/slash-commands/index.ts +0 -388
- package/src/slash-commands/mcpCommand.ts +0 -205
- package/src/slash-commands/types.ts +0 -201
- package/src/store/index.ts +0 -76
- package/src/store/selectors.ts +0 -246
- package/src/store/slices/appSlice.ts +0 -205
- package/src/store/slices/commandSlice.ts +0 -115
- package/src/store/slices/configSlice.ts +0 -46
- package/src/store/slices/focusSlice.ts +0 -64
- package/src/store/slices/index.ts +0 -9
- package/src/store/slices/sessionSlice.ts +0 -424
- package/src/store/streaming-buffer.ts +0 -425
- package/src/store/test.ts +0 -296
- package/src/store/types.ts +0 -274
- package/src/store/vanilla.ts +0 -186
- package/src/tools/builtin/bash.ts +0 -236
- package/src/tools/builtin/council.ts +0 -105
- package/src/tools/builtin/edit.ts +0 -213
- package/src/tools/builtin/glob.ts +0 -136
- package/src/tools/builtin/grep.ts +0 -263
- package/src/tools/builtin/index.ts +0 -61
- package/src/tools/builtin/memory.ts +0 -66
- package/src/tools/builtin/read.ts +0 -168
- package/src/tools/builtin/skill.ts +0 -97
- package/src/tools/builtin/snapshot.ts +0 -40
- package/src/tools/builtin/task.ts +0 -106
- package/src/tools/builtin/write.ts +0 -134
- package/src/tools/createTool.ts +0 -221
- package/src/tools/execution/ExecutionPipeline.ts +0 -263
- package/src/tools/execution/index.ts +0 -40
- package/src/tools/execution/stages/CacheStage.ts +0 -131
- package/src/tools/execution/stages/ConfirmationStage.ts +0 -203
- package/src/tools/execution/stages/DiscoveryStage.ts +0 -46
- package/src/tools/execution/stages/ExecutionStage.ts +0 -48
- package/src/tools/execution/stages/FormattingStage.ts +0 -44
- package/src/tools/execution/stages/HookStage.ts +0 -72
- package/src/tools/execution/stages/PermissionStage.ts +0 -287
- package/src/tools/execution/stages/PostHookStage.ts +0 -71
- package/src/tools/execution/stages/index.ts +0 -12
- package/src/tools/execution/test.ts +0 -266
- package/src/tools/execution/types.ts +0 -273
- package/src/tools/index.ts +0 -81
- package/src/tools/registry.ts +0 -304
- package/src/tools/schemas.ts +0 -109
- package/src/tools/test.ts +0 -220
- package/src/tools/types.ts +0 -175
- package/src/tools/validation/PermissionChecker.ts +0 -242
- package/src/tools/validation/SensitiveFileDetector.ts +0 -210
- package/src/tools/validation/index.ts +0 -11
- package/src/ui/App.tsx +0 -166
- package/src/ui/components/AegisInterface.tsx +0 -484
- package/src/ui/components/common/ChatSearch.tsx +0 -150
- package/src/ui/components/common/ErrorBoundary.tsx +0 -82
- package/src/ui/components/common/ExitMessage.tsx +0 -120
- package/src/ui/components/common/LoadingIndicator.tsx +0 -49
- package/src/ui/components/common/index.ts +0 -6
- package/src/ui/components/dialog/ConfirmationPrompt.tsx +0 -208
- package/src/ui/components/dialog/InteractiveSelector.tsx +0 -149
- package/src/ui/components/dialog/SetupWizard.tsx +0 -297
- package/src/ui/components/dialog/UpdatePrompt.tsx +0 -155
- package/src/ui/components/dialog/index.ts +0 -8
- package/src/ui/components/index.ts +0 -28
- package/src/ui/components/input/CommandSuggestions.tsx +0 -139
- package/src/ui/components/input/CustomTextInput.tsx +0 -220
- package/src/ui/components/input/InputArea.tsx +0 -361
- package/src/ui/components/input/PromptSuggestions.tsx +0 -66
- package/src/ui/components/input/index.ts +0 -6
- package/src/ui/components/layout/ChatStatusBar.tsx +0 -90
- package/src/ui/components/layout/ContextBar.tsx +0 -79
- package/src/ui/components/layout/MessageArea.tsx +0 -96
- package/src/ui/components/layout/MessageList.tsx +0 -647
- package/src/ui/components/layout/MessageSeparator.tsx +0 -26
- package/src/ui/components/layout/WelcomeMessage.tsx +0 -93
- package/src/ui/components/layout/index.ts +0 -7
- package/src/ui/components/markdown/CodeHighlighter.tsx +0 -292
- package/src/ui/components/markdown/MessageRenderer.tsx +0 -1211
- package/src/ui/components/markdown/index.ts +0 -8
- package/src/ui/components/markdown/parser.ts +0 -336
- package/src/ui/components/markdown/types.ts +0 -66
- package/src/ui/focus/FocusManager.ts +0 -137
- package/src/ui/focus/index.ts +0 -13
- package/src/ui/focus/types.ts +0 -54
- package/src/ui/focus/useFocus.ts +0 -75
- package/src/ui/hooks/index.ts +0 -11
- package/src/ui/hooks/useAgent.ts +0 -284
- package/src/ui/hooks/useCommandHistory.ts +0 -87
- package/src/ui/hooks/useCommandProcessor.ts +0 -443
- package/src/ui/hooks/useConfirmation.ts +0 -99
- package/src/ui/hooks/useCtrlCHandler.ts +0 -100
- package/src/ui/hooks/useInputBuffer.ts +0 -122
- package/src/ui/hooks/useTerminalSize.ts +0 -68
- package/src/ui/hooks/useTerminalWidth.ts +0 -5
- package/src/ui/hooks/useWindowedList.ts +0 -118
- package/src/ui/render-debugger.ts +0 -621
- package/src/ui/test.ts +0 -189
- package/src/ui/themes/ThemeManager.ts +0 -332
- package/src/ui/themes/aegisTheme.ts +0 -87
- package/src/ui/themes/darkTheme.ts +0 -87
- package/src/ui/themes/defaultTheme.ts +0 -85
- package/src/ui/themes/index.ts +0 -10
- package/src/ui/themes/lightTheme.ts +0 -89
- package/src/ui/themes/popularThemes.ts +0 -187
- package/src/ui/themes/types.ts +0 -130
- package/src/utils/clipboard.ts +0 -48
- package/src/utils/debug.ts +0 -43
- package/src/utils/environment.ts +0 -68
- package/src/utils/index.ts +0 -10
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { ContextData, ContextMessage, MemoryInfo, ToolCallRecord } from '../types.js';
|
|
8
|
-
|
|
9
|
-
export class MemoryStore {
|
|
10
|
-
private contextData: ContextData | null = null;
|
|
11
|
-
private readonly maxSize: number;
|
|
12
|
-
private readonly accessLog: Map<string, number> = new Map();
|
|
13
|
-
|
|
14
|
-
constructor(maxSize: number = 1000) {
|
|
15
|
-
this.maxSize = maxSize;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
setContext(data: ContextData): void {
|
|
22
|
-
this.contextData = data;
|
|
23
|
-
this.recordAccess('context');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
getContext(): ContextData | null {
|
|
30
|
-
this.recordAccess('context');
|
|
31
|
-
return this.contextData;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
hasData(): boolean {
|
|
38
|
-
return this.contextData !== null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
addMessage(message: ContextMessage): void {
|
|
45
|
-
if (!this.contextData) {
|
|
46
|
-
throw new Error('上下文数据未初始化');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.contextData.layers.conversation.messages.push(message);
|
|
50
|
-
this.contextData.layers.conversation.lastActivity = Date.now();
|
|
51
|
-
this.contextData.metadata.lastUpdated = Date.now();
|
|
52
|
-
|
|
53
|
-
// 检查是否超过大小限
|
|
54
|
-
this.enforceMemoryLimit();
|
|
55
|
-
this.recordAccess('messages');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
getMessages(): ContextMessage[] {
|
|
62
|
-
if (!this.contextData) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
this.recordAccess('messages');
|
|
66
|
-
return this.contextData.layers.conversation.messages;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
setMessages(messages: ContextMessage[]): void {
|
|
73
|
-
if (!this.contextData) {
|
|
74
|
-
throw new Error('上下文数据未初始化');
|
|
75
|
-
}
|
|
76
|
-
this.contextData.layers.conversation.messages = messages;
|
|
77
|
-
this.contextData.metadata.lastUpdated = Date.now();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
addToolCall(toolCall: ToolCallRecord): void {
|
|
84
|
-
if (!this.contextData) {
|
|
85
|
-
throw new Error('上下文数据未初始化');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.contextData.layers.tool.recentCalls.push(toolCall);
|
|
89
|
-
this.contextData.metadata.lastUpdated = Date.now();
|
|
90
|
-
|
|
91
|
-
// 限制工具调用记录数
|
|
92
|
-
const maxToolCalls = 100;
|
|
93
|
-
if (this.contextData.layers.tool.recentCalls.length > maxToolCalls) {
|
|
94
|
-
this.contextData.layers.tool.recentCalls =
|
|
95
|
-
this.contextData.layers.tool.recentCalls.slice(-maxToolCalls);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.recordAccess('toolCalls');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
*
|
|
103
|
-
*/
|
|
104
|
-
updateToolCallResult(toolCallId: string, output: unknown, error?: string): void {
|
|
105
|
-
if (!this.contextData) return;
|
|
106
|
-
|
|
107
|
-
const toolCall = this.contextData.layers.tool.recentCalls.find(
|
|
108
|
-
tc => tc.id === toolCallId
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
if (toolCall) {
|
|
112
|
-
toolCall.output = output;
|
|
113
|
-
toolCall.status = error ? 'error' : 'success';
|
|
114
|
-
if (error) {
|
|
115
|
-
toolCall.error = error;
|
|
116
|
-
}
|
|
117
|
-
this.contextData.metadata.lastUpdated = Date.now();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
*
|
|
123
|
-
*/
|
|
124
|
-
getRecentToolCalls(count: number = 10): ToolCallRecord[] {
|
|
125
|
-
if (!this.contextData) {
|
|
126
|
-
return [];
|
|
127
|
-
}
|
|
128
|
-
return this.contextData.layers.tool.recentCalls.slice(-count);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
*
|
|
133
|
-
*/
|
|
134
|
-
updateTokenCount(tokens: number): void {
|
|
135
|
-
if (!this.contextData) return;
|
|
136
|
-
this.contextData.metadata.totalTokens = tokens;
|
|
137
|
-
this.contextData.metadata.lastUpdated = Date.now();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
getTokenCount(): number {
|
|
144
|
-
return this.contextData?.metadata.totalTokens ?? 0;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
private enforceMemoryLimit(): void {
|
|
151
|
-
if (!this.contextData) return;
|
|
152
|
-
|
|
153
|
-
const messages = this.contextData.layers.conversation.messages;
|
|
154
|
-
if (messages.length > this.maxSize) {
|
|
155
|
-
// 保留最近的消息,删除较旧
|
|
156
|
-
const keepCount = Math.floor(this.maxSize * 0.8); // 保
|
|
157
|
-
this.contextData.layers.conversation.messages = messages.slice(-keepCount);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
*
|
|
163
|
-
*/
|
|
164
|
-
private recordAccess(key: string): void {
|
|
165
|
-
this.accessLog.set(key, Date.now());
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
*
|
|
170
|
-
*/
|
|
171
|
-
getLastAccess(key: string): number | undefined {
|
|
172
|
-
return this.accessLog.get(key);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
*
|
|
177
|
-
*/
|
|
178
|
-
getMemoryInfo(): MemoryInfo {
|
|
179
|
-
if (!this.contextData) {
|
|
180
|
-
return { hasData: false, messageCount: 0, toolCallCount: 0, lastUpdated: null };
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return {
|
|
184
|
-
hasData: true,
|
|
185
|
-
messageCount: this.contextData.layers.conversation.messages.length,
|
|
186
|
-
toolCallCount: this.contextData.layers.tool.recentCalls.length,
|
|
187
|
-
lastUpdated: this.contextData.metadata.lastUpdated,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
*
|
|
193
|
-
*/
|
|
194
|
-
getSessionId(): string | null {
|
|
195
|
-
return this.contextData?.layers.session.sessionId ?? null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
*
|
|
200
|
-
*/
|
|
201
|
-
clear(): void {
|
|
202
|
-
this.contextData = null;
|
|
203
|
-
this.accessLog.clear();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { nanoid } from 'nanoid';
|
|
8
|
-
import type { JSONLEntry, CompactMetadata, SessionContext, ConversationContext, ContextMessage } from '../types.js';
|
|
9
|
-
import { JSONLStore } from './JSONLStore.js';
|
|
10
|
-
import { getSessionFilePath, detectGitBranch } from './pathUtils.js';
|
|
11
|
-
|
|
12
|
-
// 获取版本
|
|
13
|
-
let packageVersion = '0.1.0';
|
|
14
|
-
try {
|
|
15
|
-
const packageJson = await import('../../../package.json', { with: { type: 'json' } });
|
|
16
|
-
packageVersion = packageJson.default.version || '0.1.0';
|
|
17
|
-
} catch {
|
|
18
|
-
// 忽略错
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class PersistentStore {
|
|
22
|
-
private readonly projectPath: string;
|
|
23
|
-
private readonly maxSessions: number;
|
|
24
|
-
private readonly version: string;
|
|
25
|
-
|
|
26
|
-
constructor(projectPath: string = process.cwd(), maxSessions: number = 100) {
|
|
27
|
-
this.projectPath = projectPath;
|
|
28
|
-
this.maxSessions = maxSessions;
|
|
29
|
-
this.version = packageVersion;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
private getStore(sessionId: string): JSONLStore {
|
|
36
|
-
const filePath = getSessionFilePath(this.projectPath, sessionId);
|
|
37
|
-
return new JSONLStore(filePath);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
async saveMessage(
|
|
44
|
-
sessionId: string,
|
|
45
|
-
messageRole: 'user' | 'assistant' | 'system',
|
|
46
|
-
content: string,
|
|
47
|
-
parentUuid: string | null = null,
|
|
48
|
-
metadata?: { model?: string; usage?: { input_tokens: number; output_tokens: number } }
|
|
49
|
-
): Promise<string> {
|
|
50
|
-
const store = this.getStore(sessionId);
|
|
51
|
-
|
|
52
|
-
const entry: JSONLEntry = {
|
|
53
|
-
uuid: nanoid(),
|
|
54
|
-
parentUuid,
|
|
55
|
-
sessionId,
|
|
56
|
-
timestamp: new Date().toISOString(),
|
|
57
|
-
type: messageRole,
|
|
58
|
-
cwd: this.projectPath,
|
|
59
|
-
gitBranch: detectGitBranch(this.projectPath),
|
|
60
|
-
version: this.version,
|
|
61
|
-
message: {
|
|
62
|
-
role: messageRole,
|
|
63
|
-
content,
|
|
64
|
-
...(metadata || {}),
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
await store.append(entry);
|
|
69
|
-
return entry.uuid;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
*/
|
|
75
|
-
async saveToolUse(
|
|
76
|
-
sessionId: string,
|
|
77
|
-
toolId: string,
|
|
78
|
-
toolName: string,
|
|
79
|
-
input: unknown,
|
|
80
|
-
parentUuid: string | null = null
|
|
81
|
-
): Promise<string> {
|
|
82
|
-
const store = this.getStore(sessionId);
|
|
83
|
-
|
|
84
|
-
const entry: JSONLEntry = {
|
|
85
|
-
uuid: nanoid(),
|
|
86
|
-
parentUuid,
|
|
87
|
-
sessionId,
|
|
88
|
-
timestamp: new Date().toISOString(),
|
|
89
|
-
type: 'tool_use',
|
|
90
|
-
cwd: this.projectPath,
|
|
91
|
-
gitBranch: detectGitBranch(this.projectPath),
|
|
92
|
-
version: this.version,
|
|
93
|
-
message: {
|
|
94
|
-
role: 'assistant',
|
|
95
|
-
content: '',
|
|
96
|
-
},
|
|
97
|
-
tool: {
|
|
98
|
-
id: toolId,
|
|
99
|
-
name: toolName,
|
|
100
|
-
input,
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
await store.append(entry);
|
|
105
|
-
return entry.uuid;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
|
-
async saveToolResult(
|
|
112
|
-
sessionId: string,
|
|
113
|
-
toolId: string,
|
|
114
|
-
output: unknown,
|
|
115
|
-
error?: string,
|
|
116
|
-
parentUuid: string | null = null
|
|
117
|
-
): Promise<string> {
|
|
118
|
-
const store = this.getStore(sessionId);
|
|
119
|
-
|
|
120
|
-
const entry: JSONLEntry = {
|
|
121
|
-
uuid: nanoid(),
|
|
122
|
-
parentUuid,
|
|
123
|
-
sessionId,
|
|
124
|
-
timestamp: new Date().toISOString(),
|
|
125
|
-
type: 'tool_result',
|
|
126
|
-
cwd: this.projectPath,
|
|
127
|
-
gitBranch: detectGitBranch(this.projectPath),
|
|
128
|
-
version: this.version,
|
|
129
|
-
message: {
|
|
130
|
-
role: 'assistant',
|
|
131
|
-
content: '',
|
|
132
|
-
},
|
|
133
|
-
toolResult: {
|
|
134
|
-
id: toolId,
|
|
135
|
-
output,
|
|
136
|
-
error,
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
await store.append(entry);
|
|
141
|
-
return entry.uuid;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
*
|
|
146
|
-
*/
|
|
147
|
-
async saveCompaction(
|
|
148
|
-
sessionId: string,
|
|
149
|
-
summary: string,
|
|
150
|
-
metadata: CompactMetadata,
|
|
151
|
-
parentUuid: string | null = null
|
|
152
|
-
): Promise<string> {
|
|
153
|
-
const store = this.getStore(sessionId);
|
|
154
|
-
|
|
155
|
-
// 1. 保存压缩边界标
|
|
156
|
-
const boundaryEntry: JSONLEntry = {
|
|
157
|
-
uuid: nanoid(),
|
|
158
|
-
parentUuid,
|
|
159
|
-
sessionId,
|
|
160
|
-
timestamp: new Date().toISOString(),
|
|
161
|
-
type: 'system',
|
|
162
|
-
subtype: 'compact_boundary',
|
|
163
|
-
cwd: this.projectPath,
|
|
164
|
-
gitBranch: detectGitBranch(this.projectPath),
|
|
165
|
-
version: this.version,
|
|
166
|
-
message: {
|
|
167
|
-
role: 'system',
|
|
168
|
-
content: '=== 上下文压缩边界 ===',
|
|
169
|
-
},
|
|
170
|
-
compactMetadata: metadata,
|
|
171
|
-
};
|
|
172
|
-
await store.append(boundaryEntry);
|
|
173
|
-
|
|
174
|
-
// 2. 保存压缩总
|
|
175
|
-
const summaryEntry: JSONLEntry = {
|
|
176
|
-
uuid: nanoid(),
|
|
177
|
-
parentUuid: boundaryEntry.uuid,
|
|
178
|
-
sessionId,
|
|
179
|
-
timestamp: new Date().toISOString(),
|
|
180
|
-
type: 'user',
|
|
181
|
-
isCompactSummary: true,
|
|
182
|
-
cwd: this.projectPath,
|
|
183
|
-
version: this.version,
|
|
184
|
-
message: {
|
|
185
|
-
role: 'user',
|
|
186
|
-
content: summary,
|
|
187
|
-
},
|
|
188
|
-
compactMetadata: metadata,
|
|
189
|
-
};
|
|
190
|
-
await store.append(summaryEntry);
|
|
191
|
-
|
|
192
|
-
return summaryEntry.uuid;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
*
|
|
197
|
-
*/
|
|
198
|
-
async loadSession(sessionId: string): Promise<SessionContext | null> {
|
|
199
|
-
const store = this.getStore(sessionId);
|
|
200
|
-
|
|
201
|
-
if (!store.exists()) {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const entries = await store.readAll();
|
|
206
|
-
if (entries.length === 0) {
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const firstEntry = entries[0];
|
|
211
|
-
return {
|
|
212
|
-
sessionId,
|
|
213
|
-
preferences: {},
|
|
214
|
-
startTime: new Date(firstEntry.timestamp).getTime(),
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
*
|
|
220
|
-
*/
|
|
221
|
-
async loadConversation(sessionId: string): Promise<ConversationContext | null> {
|
|
222
|
-
const store = this.getStore(sessionId);
|
|
223
|
-
|
|
224
|
-
if (!store.exists()) {
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// 只加载压缩边界后的消
|
|
229
|
-
const entries = await store.readAfterCompaction();
|
|
230
|
-
|
|
231
|
-
const messages: ContextMessage[] = [];
|
|
232
|
-
let lastActivity = 0;
|
|
233
|
-
|
|
234
|
-
for (const entry of entries) {
|
|
235
|
-
const timestamp = new Date(entry.timestamp).getTime();
|
|
236
|
-
if (timestamp > lastActivity) {
|
|
237
|
-
lastActivity = timestamp;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// 跳过压缩边
|
|
241
|
-
if (entry.subtype === 'compact_boundary') {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// 转换
|
|
246
|
-
if (entry.type === 'user' || entry.type === 'assistant' || entry.type === 'system') {
|
|
247
|
-
messages.push({
|
|
248
|
-
id: entry.uuid,
|
|
249
|
-
role: entry.message.role as ContextMessage['role'],
|
|
250
|
-
content: typeof entry.message.content === 'string'
|
|
251
|
-
? entry.message.content
|
|
252
|
-
: JSON.stringify(entry.message.content),
|
|
253
|
-
timestamp,
|
|
254
|
-
metadata: entry.isCompactSummary ? { isCompactSummary: true } : undefined,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return {
|
|
260
|
-
messages,
|
|
261
|
-
topics: [],
|
|
262
|
-
lastActivity,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
*
|
|
268
|
-
*/
|
|
269
|
-
async listSessions(): Promise<string[]> {
|
|
270
|
-
const { readdir } = await import('node:fs/promises');
|
|
271
|
-
const { getProjectStoragePath } = await import('./pathUtils.js');
|
|
272
|
-
|
|
273
|
-
const storagePath = getProjectStoragePath(this.projectPath);
|
|
274
|
-
|
|
275
|
-
try {
|
|
276
|
-
const files = await readdir(storagePath);
|
|
277
|
-
return files
|
|
278
|
-
.filter(f => f.endsWith('.jsonl'))
|
|
279
|
-
.map(f => f.replace('.jsonl', ''));
|
|
280
|
-
} catch {
|
|
281
|
-
return [];
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
*
|
|
287
|
-
*/
|
|
288
|
-
async deleteSession(sessionId: string): Promise<void> {
|
|
289
|
-
const store = this.getStore(sessionId);
|
|
290
|
-
await store.delete();
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
*
|
|
295
|
-
*/
|
|
296
|
-
async getSessionStats(sessionId: string): Promise<{
|
|
297
|
-
messageCount: number;
|
|
298
|
-
fileSize: number;
|
|
299
|
-
createdAt: Date | null;
|
|
300
|
-
lastUpdatedAt: Date | null;
|
|
301
|
-
} | null> {
|
|
302
|
-
const store = this.getStore(sessionId);
|
|
303
|
-
|
|
304
|
-
if (!store.exists()) {
|
|
305
|
-
return null;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const entries = await store.readAll();
|
|
309
|
-
const fileSize = await store.getFileSize();
|
|
310
|
-
|
|
311
|
-
if (entries.length === 0) {
|
|
312
|
-
return {
|
|
313
|
-
messageCount: 0,
|
|
314
|
-
fileSize,
|
|
315
|
-
createdAt: null,
|
|
316
|
-
lastUpdatedAt: null,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return {
|
|
321
|
-
messageCount: entries.length,
|
|
322
|
-
fileSize,
|
|
323
|
-
createdAt: new Date(entries[0].timestamp),
|
|
324
|
-
lastUpdatedAt: new Date(entries[entries.length - 1].timestamp),
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as path from 'node:path';
|
|
8
|
-
import * as os from 'node:os';
|
|
9
|
-
import { execSync } from 'node:child_process';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
export function getStorageRoot(): string {
|
|
15
|
-
return path.join(os.homedir(), '.aegis');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* /Users/foo/project → -Users-foo-project
|
|
21
|
-
*/
|
|
22
|
-
export function escapeProjectPath(absPath: string): string {
|
|
23
|
-
const normalized = path.resolve(absPath);
|
|
24
|
-
// 将路径分隔符替换为 -,移除开头
|
|
25
|
-
return normalized.replace(/[/\\]/g, '-').replace(/^-/, '');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* @returns ~/.aegis/projects/{escaped-path}/
|
|
31
|
-
*/
|
|
32
|
-
export function getProjectStoragePath(projectPath: string): string {
|
|
33
|
-
const escaped = escapeProjectPath(projectPath);
|
|
34
|
-
return path.join(getStorageRoot(), 'projects', escaped);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
* @returns ~/.aegis/projects/{escaped-path}/{sessionId}.jsonl
|
|
40
|
-
*/
|
|
41
|
-
export function getSessionFilePath(projectPath: string, sessionId: string): string {
|
|
42
|
-
return path.join(getProjectStoragePath(projectPath), `${sessionId}.jsonl`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @returns ~/.aegis/projects/{escaped-path}/sessions.json
|
|
48
|
-
*/
|
|
49
|
-
export function getSessionIndexPath(projectPath: string): string {
|
|
50
|
-
return path.join(getProjectStoragePath(projectPath), 'sessions.json');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
export function detectGitBranch(projectPath: string): string | undefined {
|
|
57
|
-
try {
|
|
58
|
-
const branch = execSync('git rev-parse --abbrev-ref HEAD', {
|
|
59
|
-
cwd: projectPath,
|
|
60
|
-
encoding: 'utf-8',
|
|
61
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
62
|
-
}).trim();
|
|
63
|
-
return branch || undefined;
|
|
64
|
-
} catch {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
export function detectGitRemote(projectPath: string): string | undefined {
|
|
73
|
-
try {
|
|
74
|
-
const remote = execSync('git remote get-url origin', {
|
|
75
|
-
cwd: projectPath,
|
|
76
|
-
encoding: 'utf-8',
|
|
77
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
78
|
-
}).trim();
|
|
79
|
-
return remote || undefined;
|
|
80
|
-
} catch {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
*
|
|
87
|
-
*/
|
|
88
|
-
export async function getLatestSessionFile(projectPath: string): Promise<string | null> {
|
|
89
|
-
const { readdir, stat } = await import('node:fs/promises');
|
|
90
|
-
const storagePath = getProjectStoragePath(projectPath);
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
const files = await readdir(storagePath);
|
|
94
|
-
const jsonlFiles = files.filter(f => f.endsWith('.jsonl'));
|
|
95
|
-
|
|
96
|
-
if (jsonlFiles.length === 0) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 按修改时间排
|
|
101
|
-
const fileStats = await Promise.all(
|
|
102
|
-
jsonlFiles.map(async (file) => {
|
|
103
|
-
const filePath = path.join(storagePath, file);
|
|
104
|
-
const stats = await stat(filePath);
|
|
105
|
-
return { file, mtime: stats.mtime.getTime() };
|
|
106
|
-
})
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
fileStats.sort((a, b) => b.mtime - a.mtime);
|
|
110
|
-
return path.join(storagePath, fileStats[0].file);
|
|
111
|
-
} catch {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
}
|