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
package/src/store/test.ts
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Store 模块测试
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
vanillaStore,
|
|
9
|
-
getState,
|
|
10
|
-
sessionActions,
|
|
11
|
-
configActions,
|
|
12
|
-
appActions,
|
|
13
|
-
focusActions,
|
|
14
|
-
commandActions,
|
|
15
|
-
getConfig,
|
|
16
|
-
ensureStoreInitialized,
|
|
17
|
-
subscribeToMessages,
|
|
18
|
-
} from './index.js';
|
|
19
|
-
import type { RuntimeConfig } from '../config/types.js';
|
|
20
|
-
|
|
21
|
-
let testsPassed = 0;
|
|
22
|
-
let testsFailed = 0;
|
|
23
|
-
|
|
24
|
-
function pass(msg: string) {
|
|
25
|
-
testsPassed++;
|
|
26
|
-
console.log(`✅ ${msg}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function fail(msg: string, error?: any) {
|
|
30
|
-
testsFailed++;
|
|
31
|
-
console.log(`❌ ${msg}`);
|
|
32
|
-
if (error) console.log(` 错误: ${error}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function runTests() {
|
|
36
|
-
console.log('='.repeat(60));
|
|
37
|
-
console.log('Store 模块测试');
|
|
38
|
-
console.log('='.repeat(60));
|
|
39
|
-
console.log();
|
|
40
|
-
|
|
41
|
-
// ========== 测试 1: Store 实
|
|
42
|
-
console.log('📝 测试 1: Store 实例');
|
|
43
|
-
console.log('-'.repeat(40));
|
|
44
|
-
|
|
45
|
-
if (vanillaStore && typeof vanillaStore.getState === 'function') {
|
|
46
|
-
pass('vanillaStore 实例存在');
|
|
47
|
-
} else {
|
|
48
|
-
fail('vanillaStore 实例不存在');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const state = getState();
|
|
52
|
-
if (state.session && state.config && state.app && state.focus && state.command) {
|
|
53
|
-
pass('Store 包含所有 5 个 Slice');
|
|
54
|
-
} else {
|
|
55
|
-
fail('Store 缺少 Slice');
|
|
56
|
-
}
|
|
57
|
-
console.log();
|
|
58
|
-
|
|
59
|
-
// ========== 测
|
|
60
|
-
console.log('📝 测试 2: Session Slice');
|
|
61
|
-
console.log('-'.repeat(40));
|
|
62
|
-
|
|
63
|
-
const initialSessionId = getState().session.sessionId;
|
|
64
|
-
if (initialSessionId && typeof initialSessionId === 'string') {
|
|
65
|
-
pass(`初始 sessionId: ${initialSessionId.slice(0, 20)}...`);
|
|
66
|
-
} else {
|
|
67
|
-
fail('sessionId 无效');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 添加消
|
|
71
|
-
sessionActions().addUserMessage('Hello, test!');
|
|
72
|
-
const messages = getState().session.messages;
|
|
73
|
-
if (messages.length === 1 && messages[0].content === 'Hello, test!') {
|
|
74
|
-
pass('addUserMessage 正常');
|
|
75
|
-
} else {
|
|
76
|
-
fail('addUserMessage 失败');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 设
|
|
80
|
-
sessionActions().setThinking(true);
|
|
81
|
-
if (getState().session.isThinking === true) {
|
|
82
|
-
pass('setThinking(true) 正常');
|
|
83
|
-
} else {
|
|
84
|
-
fail('setThinking 失败');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
sessionActions().setThinking(false);
|
|
88
|
-
|
|
89
|
-
// 清空消
|
|
90
|
-
sessionActions().clearMessages();
|
|
91
|
-
if (getState().session.messages.length === 0) {
|
|
92
|
-
pass('clearMessages 正常');
|
|
93
|
-
} else {
|
|
94
|
-
fail('clearMessages 失败');
|
|
95
|
-
}
|
|
96
|
-
console.log();
|
|
97
|
-
|
|
98
|
-
// ========== 测
|
|
99
|
-
console.log('📝 测试 3: Config Slice');
|
|
100
|
-
console.log('-'.repeat(40));
|
|
101
|
-
|
|
102
|
-
// 初始状态 config
|
|
103
|
-
if (getConfig() === null) {
|
|
104
|
-
pass('初始 config 为 null');
|
|
105
|
-
} else {
|
|
106
|
-
fail('初始 config 不为 null');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// 设置配
|
|
110
|
-
const testConfig: RuntimeConfig = {
|
|
111
|
-
default: { model: 'test-model' },
|
|
112
|
-
theme: 'dark',
|
|
113
|
-
defaultPermissionMode: 'default',
|
|
114
|
-
};
|
|
115
|
-
configActions().setConfig(testConfig);
|
|
116
|
-
|
|
117
|
-
if (getConfig()?.default?.model === 'test-model') {
|
|
118
|
-
pass('setConfig 正常');
|
|
119
|
-
} else {
|
|
120
|
-
fail('setConfig 失败');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// 更新配
|
|
124
|
-
configActions().updateConfig({ theme: 'light' });
|
|
125
|
-
if (getConfig()?.theme === 'light') {
|
|
126
|
-
pass('updateConfig 正常');
|
|
127
|
-
} else {
|
|
128
|
-
fail('updateConfig 失败');
|
|
129
|
-
}
|
|
130
|
-
console.log();
|
|
131
|
-
|
|
132
|
-
// ========== 测
|
|
133
|
-
console.log('📝 测试 4: App Slice');
|
|
134
|
-
console.log('-'.repeat(40));
|
|
135
|
-
|
|
136
|
-
if (getState().app.initializationStatus === 'pending') {
|
|
137
|
-
pass('初始 initializationStatus 为 pending');
|
|
138
|
-
} else {
|
|
139
|
-
fail('初始 initializationStatus 不正确');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
appActions().setInitializationStatus('ready');
|
|
143
|
-
if (getState().app.initializationStatus === 'ready') {
|
|
144
|
-
pass('setInitializationStatus 正常');
|
|
145
|
-
} else {
|
|
146
|
-
fail('setInitializationStatus 失败');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Todos
|
|
150
|
-
appActions().addTodo({ id: '1', title: 'Test todo', status: 'pending', createdAt: Date.now() });
|
|
151
|
-
if (getState().app.todos.length === 1) {
|
|
152
|
-
pass('addTodo 正常');
|
|
153
|
-
} else {
|
|
154
|
-
fail('addTodo 失败');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
appActions().updateTodo('1', { status: 'completed' });
|
|
158
|
-
if (getState().app.todos[0].status === 'completed') {
|
|
159
|
-
pass('updateTodo 正常');
|
|
160
|
-
} else {
|
|
161
|
-
fail('updateTodo 失败');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
appActions().removeTodo('1');
|
|
165
|
-
if (getState().app.todos.length === 0) {
|
|
166
|
-
pass('removeTodo 正常');
|
|
167
|
-
} else {
|
|
168
|
-
fail('removeTodo 失败');
|
|
169
|
-
}
|
|
170
|
-
console.log();
|
|
171
|
-
|
|
172
|
-
// ========== 测
|
|
173
|
-
console.log('📝 测试 5: Focus Slice');
|
|
174
|
-
console.log('-'.repeat(40));
|
|
175
|
-
|
|
176
|
-
if (getState().focus.currentFocus === 'input') {
|
|
177
|
-
pass('初始焦点为 input');
|
|
178
|
-
} else {
|
|
179
|
-
fail('初始焦点不正确');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
focusActions().setFocus('messages');
|
|
183
|
-
if (getState().focus.currentFocus === 'messages') {
|
|
184
|
-
pass('setFocus 正常');
|
|
185
|
-
} else {
|
|
186
|
-
fail('setFocus 失败');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (getState().focus.previousFocus === 'input') {
|
|
190
|
-
pass('previousFocus 记录正确');
|
|
191
|
-
} else {
|
|
192
|
-
fail('previousFocus 记录不正确');
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
focusActions().restoreFocus();
|
|
196
|
-
if (getState().focus.currentFocus === 'input') {
|
|
197
|
-
pass('restoreFocus 正常');
|
|
198
|
-
} else {
|
|
199
|
-
fail('restoreFocus 失败');
|
|
200
|
-
}
|
|
201
|
-
console.log();
|
|
202
|
-
|
|
203
|
-
// ========== 测
|
|
204
|
-
console.log('📝 测试 6: Command Slice');
|
|
205
|
-
console.log('-'.repeat(40));
|
|
206
|
-
|
|
207
|
-
if (getState().command.isProcessing === false) {
|
|
208
|
-
pass('初始 isProcessing 为 false');
|
|
209
|
-
} else {
|
|
210
|
-
fail('初始 isProcessing 不正确');
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
commandActions().setProcessing(true);
|
|
214
|
-
if (getState().command.isProcessing === true) {
|
|
215
|
-
pass('setProcessing 正常');
|
|
216
|
-
} else {
|
|
217
|
-
fail('setProcessing 失败');
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// 命令队
|
|
221
|
-
commandActions().enqueueCommand('command1');
|
|
222
|
-
commandActions().enqueueCommand('command2');
|
|
223
|
-
if (getState().command.pendingCommands.length === 2) {
|
|
224
|
-
pass('enqueueCommand 正常');
|
|
225
|
-
} else {
|
|
226
|
-
fail('enqueueCommand 失败');
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const cmd = commandActions().dequeueCommand();
|
|
230
|
-
if (cmd === 'command1' && getState().command.pendingCommands.length === 1) {
|
|
231
|
-
pass('dequeueCommand 正常');
|
|
232
|
-
} else {
|
|
233
|
-
fail('dequeueCommand 失败');
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
commandActions().clearQueue();
|
|
237
|
-
if (getState().command.pendingCommands.length === 0) {
|
|
238
|
-
pass('clearQueue 正常');
|
|
239
|
-
} else {
|
|
240
|
-
fail('clearQueue 失败');
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// AbortController
|
|
244
|
-
const controller = commandActions().createAbortController();
|
|
245
|
-
if (controller instanceof AbortController) {
|
|
246
|
-
pass('createAbortController 正常');
|
|
247
|
-
} else {
|
|
248
|
-
fail('createAbortController 失败');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
commandActions().abort();
|
|
252
|
-
if (getState().command.isProcessing === false && getState().command.abortController === null) {
|
|
253
|
-
pass('abort 正常');
|
|
254
|
-
} else {
|
|
255
|
-
fail('abort 失败');
|
|
256
|
-
}
|
|
257
|
-
console.log();
|
|
258
|
-
|
|
259
|
-
// ========== 测试 7: 订阅功
|
|
260
|
-
console.log('📝 测试 7: 订阅功能');
|
|
261
|
-
console.log('-'.repeat(40));
|
|
262
|
-
|
|
263
|
-
let subscriptionTriggered = false;
|
|
264
|
-
const unsubscribe = subscribeToMessages((messages) => {
|
|
265
|
-
subscriptionTriggered = true;
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
sessionActions().addUserMessage('Trigger subscription');
|
|
269
|
-
|
|
270
|
-
// 等待一下让订阅触
|
|
271
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
272
|
-
|
|
273
|
-
if (subscriptionTriggered) {
|
|
274
|
-
pass('subscribeToMessages 正常触发');
|
|
275
|
-
} else {
|
|
276
|
-
fail('subscribeToMessages 未触发');
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
unsubscribe();
|
|
280
|
-
console.log();
|
|
281
|
-
|
|
282
|
-
// ========== 测试总
|
|
283
|
-
console.log('='.repeat(60));
|
|
284
|
-
console.log(`测试完成: ${testsPassed} 通过, ${testsFailed} 失败`);
|
|
285
|
-
console.log('='.repeat(60));
|
|
286
|
-
|
|
287
|
-
if (testsFailed > 0) {
|
|
288
|
-
process.exit(1);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// 运行测
|
|
293
|
-
runTests().catch((error) => {
|
|
294
|
-
console.error('测试出错:', error);
|
|
295
|
-
process.exit(1);
|
|
296
|
-
});
|
package/src/store/types.ts
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zustand Store 类型定义
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { RuntimeConfig } from '../config/types.js';
|
|
6
|
-
|
|
7
|
-
// ========== Content Block Model (mirrors Claude SSE content blocks)
|
|
8
|
-
|
|
9
|
-
export type ContentBlockType = 'text' | 'thinking' | 'tool_use' | 'tool_result';
|
|
10
|
-
|
|
11
|
-
export type ToolCallStatus = 'running' | 'success' | 'error';
|
|
12
|
-
|
|
13
|
-
export interface TextBlock {
|
|
14
|
-
type: 'text';
|
|
15
|
-
text: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ThinkingBlock {
|
|
19
|
-
type: 'thinking';
|
|
20
|
-
thinking: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface ToolUseBlock {
|
|
24
|
-
type: 'tool_use';
|
|
25
|
-
id: string;
|
|
26
|
-
name: string;
|
|
27
|
-
input: string; // JSON args being accumulated
|
|
28
|
-
status: ToolCallStatus;
|
|
29
|
-
startedAt: number;
|
|
30
|
-
completedAt?: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface ToolResultBlock {
|
|
34
|
-
type: 'tool_result';
|
|
35
|
-
tool_use_id: string;
|
|
36
|
-
content: string;
|
|
37
|
-
is_error: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type ContentBlock = TextBlock | ThinkingBlock | ToolUseBlock | ToolResultBlock;
|
|
41
|
-
|
|
42
|
-
// ========== 会话状
|
|
43
|
-
|
|
44
|
-
export interface ModelTokens {
|
|
45
|
-
inputTokens: number;
|
|
46
|
-
outputTokens: number;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface TokenUsage {
|
|
50
|
-
inputTokens: number;
|
|
51
|
-
outputTokens: number;
|
|
52
|
-
totalTokens: number;
|
|
53
|
-
maxContextTokens: number;
|
|
54
|
-
modelBreakdown: Record<string, ModelTokens>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface SessionMessage {
|
|
58
|
-
id: string;
|
|
59
|
-
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
60
|
-
content: string;
|
|
61
|
-
timestamp: number;
|
|
62
|
-
toolCalls?: unknown[];
|
|
63
|
-
toolCallId?: string;
|
|
64
|
-
/** 思考过程内容(用于支持 DeepSeek R1 等推理模型) */
|
|
65
|
-
thinking?: string;
|
|
66
|
-
isStreaming?: boolean;
|
|
67
|
-
/** Content blocks for structured rendering (Claude-style: text, thinking, tool_use, tool_result) */
|
|
68
|
-
contentBlocks?: ContentBlock[];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface SessionState {
|
|
72
|
-
sessionId: string;
|
|
73
|
-
messages: SessionMessage[];
|
|
74
|
-
isThinking: boolean;
|
|
75
|
-
isCompacting: boolean;
|
|
76
|
-
currentCommand: string | null;
|
|
77
|
-
error: string | null;
|
|
78
|
-
isActive: boolean;
|
|
79
|
-
tokenUsage: TokenUsage;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface SessionActions {
|
|
83
|
-
addMessage: (message: SessionMessage) => void;
|
|
84
|
-
addUserMessage: (content: string) => void;
|
|
85
|
-
addAssistantMessage: (content: string) => void;
|
|
86
|
-
/** 开始流式助手消息(创建空消息占位) */
|
|
87
|
-
startStreamingMessage: () => string;
|
|
88
|
-
appendToStreamingMessage: (id: string, contentDelta: string) => void;
|
|
89
|
-
appendThinkingToStreamingMessage: (id: string, thinkingDelta: string) => void;
|
|
90
|
-
/** Force-flush streaming buffer content to store (for tool calls, final flush) */
|
|
91
|
-
flushStreamBuffer: (id: string) => void;
|
|
92
|
-
/** Write directly to store message, bypassing buffer (for tool calls) */
|
|
93
|
-
forceAppendToMessage: (id: string, contentDelta: string) => void;
|
|
94
|
-
finishStreamingMessage: (id: string) => void;
|
|
95
|
-
|
|
96
|
-
// ===== Content Block Operations (Claude-style) =====
|
|
97
|
-
/** Add a content block to the currently streaming message */
|
|
98
|
-
addContentBlock: (messageId: string, block: ContentBlock) => void;
|
|
99
|
-
/** Update a tool_use block's accumulated input JSON */
|
|
100
|
-
updateToolCallInput: (messageId: string, toolCallId: string, partialJson: string) => void;
|
|
101
|
-
/** Set a tool_use block's full input JSON (replaces, used once on completion) */
|
|
102
|
-
setToolCallInput: (messageId: string, toolCallId: string, fullInput: string) => void;
|
|
103
|
-
/** Update a tool_use block's status */
|
|
104
|
-
updateToolCallStatus: (messageId: string, toolCallId: string, status: ToolCallStatus, completedAt?: number) => void;
|
|
105
|
-
/** Add a tool_result block linked to a tool_use */
|
|
106
|
-
addToolResultBlock: (messageId: string, toolUseId: string, content: string, isError: boolean) => void;
|
|
107
|
-
|
|
108
|
-
setThinking: (isThinking: boolean) => void;
|
|
109
|
-
setCompacting: (isCompacting: boolean) => void;
|
|
110
|
-
setCurrentCommand: (command: string | null) => void;
|
|
111
|
-
setError: (error: string | null) => void;
|
|
112
|
-
setSessionId: (sessionId: string) => void;
|
|
113
|
-
restoreSession: (sessionId: string, messages: SessionMessage[]) => void;
|
|
114
|
-
updateTokenUsage: (usage: Partial<TokenUsage>) => void;
|
|
115
|
-
removeLastMessages: (count: number) => void;
|
|
116
|
-
clearMessages: () => void;
|
|
117
|
-
resetSession: () => void;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface SessionSlice extends SessionState {
|
|
121
|
-
actions: SessionActions;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// ========== 配置状
|
|
125
|
-
|
|
126
|
-
export interface ConfigState {
|
|
127
|
-
config: RuntimeConfig | null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface ConfigActions {
|
|
131
|
-
setConfig: (config: RuntimeConfig) => void;
|
|
132
|
-
updateConfig: (partial: Partial<RuntimeConfig>) => void;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export interface ConfigSlice extends ConfigState {
|
|
136
|
-
actions: ConfigActions;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// ========== 应用状
|
|
140
|
-
|
|
141
|
-
export type InitializationStatus = 'pending' | 'loading' | 'ready' | 'error' | 'needsSetup';
|
|
142
|
-
export type ActiveModal = 'none' | 'shortcuts' | 'settings' | 'confirmation' | 'update' | 'themeSelector';
|
|
143
|
-
|
|
144
|
-
export interface AppState {
|
|
145
|
-
initializationStatus: InitializationStatus;
|
|
146
|
-
initializationError: string | null;
|
|
147
|
-
activeModal: ActiveModal;
|
|
148
|
-
awaitingSecondCtrlC: boolean;
|
|
149
|
-
/** 是否展开所有思考块(全局开关) */
|
|
150
|
-
showAllThinking: boolean;
|
|
151
|
-
todos: TodoItem[];
|
|
152
|
-
/** Set once the user runs /model this session — auto-router backs off until /router on resets it */
|
|
153
|
-
manualModelOverride: boolean;
|
|
154
|
-
/** Display label of the model the auto-router picked for the in-flight/last turn, or null if none */
|
|
155
|
-
autoRouterActiveModel: string | null;
|
|
156
|
-
workflow: WorkflowState;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export interface AppActions {
|
|
160
|
-
setInitializationStatus: (status: InitializationStatus) => void;
|
|
161
|
-
setInitializationError: (error: string | null) => void;
|
|
162
|
-
setActiveModal: (modal: ActiveModal) => void;
|
|
163
|
-
setTodos: (todos: TodoItem[]) => void;
|
|
164
|
-
addTodo: (todo: TodoItem) => void;
|
|
165
|
-
updateTodo: (id: string, updates: Partial<TodoItem>) => void;
|
|
166
|
-
removeTodo: (id: string) => void;
|
|
167
|
-
setAwaitingSecondCtrlC: (awaiting: boolean) => void;
|
|
168
|
-
toggleShowAllThinking: () => void;
|
|
169
|
-
setManualModelOverride: (value: boolean) => void;
|
|
170
|
-
setAutoRouterActiveModel: (label: string | null) => void;
|
|
171
|
-
workflow: WorkflowActions;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export interface AppSlice extends AppState {
|
|
175
|
-
actions: AppActions;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ========== 焦点状
|
|
179
|
-
|
|
180
|
-
export type FocusId = 'input' | 'messages' | 'confirmation' | 'modal' | 'none' | 'theme-selector' | 'selector';
|
|
181
|
-
|
|
182
|
-
/** FocusId 常量枚举 */
|
|
183
|
-
export const FocusId = {
|
|
184
|
-
MAIN_INPUT: 'input' as FocusId,
|
|
185
|
-
MESSAGES: 'messages' as FocusId,
|
|
186
|
-
CONFIRMATION_PROMPT: 'confirmation' as FocusId,
|
|
187
|
-
THEME_SELECTOR: 'theme-selector' as FocusId,
|
|
188
|
-
SELECTOR: 'selector' as FocusId,
|
|
189
|
-
MODAL: 'modal' as FocusId,
|
|
190
|
-
NONE: 'none' as FocusId,
|
|
191
|
-
} as const;
|
|
192
|
-
|
|
193
|
-
export interface FocusState {
|
|
194
|
-
currentFocus: FocusId;
|
|
195
|
-
previousFocus: FocusId | null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export interface FocusActions {
|
|
199
|
-
setFocus: (focus: FocusId) => void;
|
|
200
|
-
restoreFocus: () => void;
|
|
201
|
-
pushFocus: (focus: FocusId) => void;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export interface FocusSlice extends FocusState {
|
|
205
|
-
actions: FocusActions;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// ========== 命令状
|
|
209
|
-
|
|
210
|
-
export interface CommandState {
|
|
211
|
-
isProcessing: boolean;
|
|
212
|
-
abortController: AbortController | null;
|
|
213
|
-
pendingCommands: string[];
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export interface CommandActions {
|
|
217
|
-
setProcessing: (isProcessing: boolean) => void;
|
|
218
|
-
createAbortController: () => AbortController;
|
|
219
|
-
abort: () => void;
|
|
220
|
-
enqueueCommand: (command: string) => void;
|
|
221
|
-
dequeueCommand: () => string | undefined;
|
|
222
|
-
clearQueue: () => void;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export interface CommandSlice extends CommandState {
|
|
226
|
-
actions: CommandActions;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// ========== Workflow State (for context bar)
|
|
230
|
-
|
|
231
|
-
export interface WorkflowStep {
|
|
232
|
-
label: string;
|
|
233
|
-
status: 'pending' | 'active' | 'done';
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export interface WorkflowState {
|
|
237
|
-
visible: boolean;
|
|
238
|
-
phase: string; // "Building", "Refactoring", "Debugging" etc.
|
|
239
|
-
target: string; // what's being worked on, e.g. "auth system"
|
|
240
|
-
steps: WorkflowStep[];
|
|
241
|
-
currentStepIndex: number;
|
|
242
|
-
totalSteps: number;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export const initialWorkflowState: WorkflowState = {
|
|
246
|
-
visible: false,
|
|
247
|
-
phase: '',
|
|
248
|
-
target: '',
|
|
249
|
-
steps: [],
|
|
250
|
-
currentStepIndex: 0,
|
|
251
|
-
totalSteps: 0,
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
export interface WorkflowActions {
|
|
255
|
-
setWorkflow: (opts: { phase: string; target: string; steps: string[] }) => void;
|
|
256
|
-
advanceStep: () => void;
|
|
257
|
-
clearWorkflow: () => void;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// ========== Todo support (for progress tracking in tasks)
|
|
261
|
-
export interface TodoItem {
|
|
262
|
-
id: string;
|
|
263
|
-
title: string;
|
|
264
|
-
status: 'pending' | 'in_progress' | 'completed';
|
|
265
|
-
createdAt: number;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export interface ClawdStore {
|
|
269
|
-
session: SessionSlice;
|
|
270
|
-
config: ConfigSlice;
|
|
271
|
-
app: AppSlice;
|
|
272
|
-
focus: FocusSlice;
|
|
273
|
-
command: CommandSlice;
|
|
274
|
-
}
|