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.
Files changed (209) hide show
  1. package/bin/aegis.js +165 -0
  2. package/package.json +18 -86
  3. package/LICENSE +0 -21
  4. package/README.md +0 -394
  5. package/dist/main.js +0 -2171
  6. package/gui/run-gui.cjs +0 -13
  7. package/src/agent/Agent.ts +0 -903
  8. package/src/agent/SimpleAgent.ts +0 -48
  9. package/src/agent/index.ts +0 -54
  10. package/src/agent/orchestrator/AppBuilder.ts +0 -443
  11. package/src/agent/orchestrator/CouncilAgent.ts +0 -310
  12. package/src/agent/orchestrator/DiscussionRoom.ts +0 -462
  13. package/src/agent/orchestrator/OrchestratorAgent.ts +0 -637
  14. package/src/agent/orchestrator/index.ts +0 -38
  15. package/src/agent/orchestrator/utils.ts +0 -397
  16. package/src/agent/pricing.ts +0 -115
  17. package/src/agent/router.ts +0 -74
  18. package/src/agent/routerStats.ts +0 -121
  19. package/src/agent/types.ts +0 -318
  20. package/src/auth/login.ts +0 -383
  21. package/src/cli/config.ts +0 -189
  22. package/src/cli/index.ts +0 -17
  23. package/src/cli/middleware.ts +0 -119
  24. package/src/cli/types.ts +0 -75
  25. package/src/config/ConfigManager.ts +0 -587
  26. package/src/config/index.ts +0 -7
  27. package/src/config/types.ts +0 -584
  28. package/src/context/CompactionService.ts +0 -300
  29. package/src/context/ContextManager.ts +0 -450
  30. package/src/context/FileAnalyzer.ts +0 -267
  31. package/src/context/TokenCounter.ts +0 -265
  32. package/src/context/index.ts +0 -27
  33. package/src/context/storage/CacheStore.ts +0 -176
  34. package/src/context/storage/JSONLStore.ts +0 -201
  35. package/src/context/storage/MemoryStore.ts +0 -205
  36. package/src/context/storage/PersistentStore.ts +0 -327
  37. package/src/context/storage/index.ts +0 -9
  38. package/src/context/storage/pathUtils.ts +0 -114
  39. package/src/context/test.ts +0 -309
  40. package/src/context/types.ts +0 -268
  41. package/src/hooks/HookExecutor.ts +0 -434
  42. package/src/hooks/HookManager.ts +0 -596
  43. package/src/hooks/HookService.ts +0 -269
  44. package/src/hooks/Matcher.ts +0 -157
  45. package/src/hooks/index.ts +0 -63
  46. package/src/hooks/types.ts +0 -424
  47. package/src/main.tsx +0 -596
  48. package/src/mcp/HealthMonitor.ts +0 -150
  49. package/src/mcp/McpClient.ts +0 -491
  50. package/src/mcp/McpRegistry.ts +0 -321
  51. package/src/mcp/createMcpTool.ts +0 -251
  52. package/src/mcp/index.ts +0 -15
  53. package/src/mcp/server.ts +0 -334
  54. package/src/mcp/test-server.ts +0 -88
  55. package/src/mcp/test.ts +0 -372
  56. package/src/mcp/types.ts +0 -247
  57. package/src/memory/AgentMemoryBus.ts +0 -432
  58. package/src/memory/CloudSync.ts +0 -99
  59. package/src/memory/DriveSync.ts +0 -106
  60. package/src/memory/SharedMemory.ts +0 -951
  61. package/src/memory/index.ts +0 -14
  62. package/src/memory/machineFingerprint.ts +0 -40
  63. package/src/orchestrator/SubAgentMetadata.ts +0 -136
  64. package/src/prompts/builder.ts +0 -213
  65. package/src/prompts/default.ts +0 -144
  66. package/src/prompts/index.ts +0 -16
  67. package/src/prompts/plan.ts +0 -64
  68. package/src/prompts/test.ts +0 -78
  69. package/src/services/AnthropicChatService.ts +0 -341
  70. package/src/services/ChatService.ts +0 -347
  71. package/src/services/ClaudeCliChatService.ts +0 -256
  72. package/src/services/CloudSync.ts +0 -168
  73. package/src/services/CostLedger.ts +0 -211
  74. package/src/services/Heartbeat.ts +0 -135
  75. package/src/services/LearningCollector.ts +0 -291
  76. package/src/services/OllamaInstaller.ts +0 -342
  77. package/src/services/VersionChecker.ts +0 -445
  78. package/src/services/index.ts +0 -57
  79. package/src/services/streaming/OpenAIEventAdapter.ts +0 -126
  80. package/src/services/streaming/RenderingProfile.ts +0 -90
  81. package/src/services/streaming/StreamEventParser.ts +0 -181
  82. package/src/services/streaming/ThrottledRenderer.ts +0 -139
  83. package/src/services/streaming/TranscriptBuffer.ts +0 -574
  84. package/src/services/streaming/eventStatusMap.ts +0 -52
  85. package/src/services/streaming/index.ts +0 -46
  86. package/src/services/streaming/renderFormatting.ts +0 -79
  87. package/src/services/streaming/types.ts +0 -234
  88. package/src/skills/SkillLoader.ts +0 -126
  89. package/src/skills/SkillRegistry.ts +0 -366
  90. package/src/skills/index.ts +0 -48
  91. package/src/skills/types.ts +0 -146
  92. package/src/slash-commands/billing.ts +0 -70
  93. package/src/slash-commands/build.ts +0 -413
  94. package/src/slash-commands/builtinCommands.ts +0 -2733
  95. package/src/slash-commands/clone.ts +0 -242
  96. package/src/slash-commands/council.ts +0 -125
  97. package/src/slash-commands/custom/CustomCommandExecutor.ts +0 -143
  98. package/src/slash-commands/custom/CustomCommandLoader.ts +0 -251
  99. package/src/slash-commands/custom/CustomCommandRegistry.ts +0 -144
  100. package/src/slash-commands/custom/index.ts +0 -7
  101. package/src/slash-commands/debate.ts +0 -254
  102. package/src/slash-commands/gmail.ts +0 -105
  103. package/src/slash-commands/index.ts +0 -388
  104. package/src/slash-commands/mcpCommand.ts +0 -205
  105. package/src/slash-commands/types.ts +0 -201
  106. package/src/store/index.ts +0 -76
  107. package/src/store/selectors.ts +0 -246
  108. package/src/store/slices/appSlice.ts +0 -205
  109. package/src/store/slices/commandSlice.ts +0 -115
  110. package/src/store/slices/configSlice.ts +0 -46
  111. package/src/store/slices/focusSlice.ts +0 -64
  112. package/src/store/slices/index.ts +0 -9
  113. package/src/store/slices/sessionSlice.ts +0 -424
  114. package/src/store/streaming-buffer.ts +0 -425
  115. package/src/store/test.ts +0 -296
  116. package/src/store/types.ts +0 -274
  117. package/src/store/vanilla.ts +0 -186
  118. package/src/tools/builtin/bash.ts +0 -236
  119. package/src/tools/builtin/council.ts +0 -105
  120. package/src/tools/builtin/edit.ts +0 -213
  121. package/src/tools/builtin/glob.ts +0 -136
  122. package/src/tools/builtin/grep.ts +0 -263
  123. package/src/tools/builtin/index.ts +0 -61
  124. package/src/tools/builtin/memory.ts +0 -66
  125. package/src/tools/builtin/read.ts +0 -168
  126. package/src/tools/builtin/skill.ts +0 -97
  127. package/src/tools/builtin/snapshot.ts +0 -40
  128. package/src/tools/builtin/task.ts +0 -106
  129. package/src/tools/builtin/write.ts +0 -134
  130. package/src/tools/createTool.ts +0 -221
  131. package/src/tools/execution/ExecutionPipeline.ts +0 -263
  132. package/src/tools/execution/index.ts +0 -40
  133. package/src/tools/execution/stages/CacheStage.ts +0 -131
  134. package/src/tools/execution/stages/ConfirmationStage.ts +0 -203
  135. package/src/tools/execution/stages/DiscoveryStage.ts +0 -46
  136. package/src/tools/execution/stages/ExecutionStage.ts +0 -48
  137. package/src/tools/execution/stages/FormattingStage.ts +0 -44
  138. package/src/tools/execution/stages/HookStage.ts +0 -72
  139. package/src/tools/execution/stages/PermissionStage.ts +0 -287
  140. package/src/tools/execution/stages/PostHookStage.ts +0 -71
  141. package/src/tools/execution/stages/index.ts +0 -12
  142. package/src/tools/execution/test.ts +0 -266
  143. package/src/tools/execution/types.ts +0 -273
  144. package/src/tools/index.ts +0 -81
  145. package/src/tools/registry.ts +0 -304
  146. package/src/tools/schemas.ts +0 -109
  147. package/src/tools/test.ts +0 -220
  148. package/src/tools/types.ts +0 -175
  149. package/src/tools/validation/PermissionChecker.ts +0 -242
  150. package/src/tools/validation/SensitiveFileDetector.ts +0 -210
  151. package/src/tools/validation/index.ts +0 -11
  152. package/src/ui/App.tsx +0 -166
  153. package/src/ui/components/AegisInterface.tsx +0 -484
  154. package/src/ui/components/common/ChatSearch.tsx +0 -150
  155. package/src/ui/components/common/ErrorBoundary.tsx +0 -82
  156. package/src/ui/components/common/ExitMessage.tsx +0 -120
  157. package/src/ui/components/common/LoadingIndicator.tsx +0 -49
  158. package/src/ui/components/common/index.ts +0 -6
  159. package/src/ui/components/dialog/ConfirmationPrompt.tsx +0 -208
  160. package/src/ui/components/dialog/InteractiveSelector.tsx +0 -149
  161. package/src/ui/components/dialog/SetupWizard.tsx +0 -297
  162. package/src/ui/components/dialog/UpdatePrompt.tsx +0 -155
  163. package/src/ui/components/dialog/index.ts +0 -8
  164. package/src/ui/components/index.ts +0 -28
  165. package/src/ui/components/input/CommandSuggestions.tsx +0 -139
  166. package/src/ui/components/input/CustomTextInput.tsx +0 -220
  167. package/src/ui/components/input/InputArea.tsx +0 -361
  168. package/src/ui/components/input/PromptSuggestions.tsx +0 -66
  169. package/src/ui/components/input/index.ts +0 -6
  170. package/src/ui/components/layout/ChatStatusBar.tsx +0 -90
  171. package/src/ui/components/layout/ContextBar.tsx +0 -79
  172. package/src/ui/components/layout/MessageArea.tsx +0 -96
  173. package/src/ui/components/layout/MessageList.tsx +0 -647
  174. package/src/ui/components/layout/MessageSeparator.tsx +0 -26
  175. package/src/ui/components/layout/WelcomeMessage.tsx +0 -93
  176. package/src/ui/components/layout/index.ts +0 -7
  177. package/src/ui/components/markdown/CodeHighlighter.tsx +0 -292
  178. package/src/ui/components/markdown/MessageRenderer.tsx +0 -1211
  179. package/src/ui/components/markdown/index.ts +0 -8
  180. package/src/ui/components/markdown/parser.ts +0 -336
  181. package/src/ui/components/markdown/types.ts +0 -66
  182. package/src/ui/focus/FocusManager.ts +0 -137
  183. package/src/ui/focus/index.ts +0 -13
  184. package/src/ui/focus/types.ts +0 -54
  185. package/src/ui/focus/useFocus.ts +0 -75
  186. package/src/ui/hooks/index.ts +0 -11
  187. package/src/ui/hooks/useAgent.ts +0 -284
  188. package/src/ui/hooks/useCommandHistory.ts +0 -87
  189. package/src/ui/hooks/useCommandProcessor.ts +0 -443
  190. package/src/ui/hooks/useConfirmation.ts +0 -99
  191. package/src/ui/hooks/useCtrlCHandler.ts +0 -100
  192. package/src/ui/hooks/useInputBuffer.ts +0 -122
  193. package/src/ui/hooks/useTerminalSize.ts +0 -68
  194. package/src/ui/hooks/useTerminalWidth.ts +0 -5
  195. package/src/ui/hooks/useWindowedList.ts +0 -118
  196. package/src/ui/render-debugger.ts +0 -621
  197. package/src/ui/test.ts +0 -189
  198. package/src/ui/themes/ThemeManager.ts +0 -332
  199. package/src/ui/themes/aegisTheme.ts +0 -87
  200. package/src/ui/themes/darkTheme.ts +0 -87
  201. package/src/ui/themes/defaultTheme.ts +0 -85
  202. package/src/ui/themes/index.ts +0 -10
  203. package/src/ui/themes/lightTheme.ts +0 -89
  204. package/src/ui/themes/popularThemes.ts +0 -187
  205. package/src/ui/themes/types.ts +0 -130
  206. package/src/utils/clipboard.ts +0 -48
  207. package/src/utils/debug.ts +0 -43
  208. package/src/utils/environment.ts +0 -68
  209. package/src/utils/index.ts +0 -10
@@ -1,201 +0,0 @@
1
- /**
2
- * Slash 命令类型定义
3
- */
4
-
5
- /**
6
- *
7
- */
8
- export type CommandCategory =
9
- | 'general' // 通用命
10
- | 'session' // 会话相
11
- | 'config' // 配置相
12
- | 'skills' // Skills 相
13
- | 'hooks' // Hooks 相
14
- | 'git' // Git 相
15
- | 'mcp' // MCP 相
16
- | 'custom'; // 自定义命
17
-
18
- /**
19
- *
20
- */
21
- export interface SelectorOption<T = string> {
22
- value: T;
23
- label: string;
24
- description?: string;
25
- isCurrent?: boolean;
26
- }
27
-
28
- /**
29
- * Slash 命令上下文
30
- */
31
- export interface SlashCommandContext {
32
- /** 当前工作目录 */
33
- cwd: string;
34
- /** 会话 ID */
35
- sessionId?: string;
36
- /** 用户消息历史 */
37
- messages?: any[];
38
- /** ContextManager 实例(用于 /compact 等命令) */
39
- contextManager?: any;
40
- /** ChatService 实例(用于 LLM 调用) */
41
- chatService?: any;
42
- /** 模型名称 */
43
- modelName?: string;
44
- /** 显示选择器的回调 */
45
- showSelector?: <T>(options: {
46
- title: string;
47
- options: SelectorOption<T>[];
48
- onSelect: (value: T) => void;
49
- onCancel: () => void;
50
- }) => void;
51
- /** 隐藏选择器的回调 */
52
- hideSelector?: () => void;
53
- /** 流式内容回调(增量文本) */
54
- onContentDelta?: (delta: string) => void;
55
- /** 流式思考回调 */
56
- onThinkingDelta?: (delta: string) => void;
57
- /** 工具调用开始回调 */
58
- onToolCallStart?: (toolCall: { id: string; name: string; input: string }) => void;
59
- /** 确认处理器(供管道交互式批准工具调用) */
60
- confirmationHandler?: { requestConfirmation: (details: any) => Promise<any> };
61
- }
62
-
63
- /**
64
- * Slash 命令结果
65
- */
66
- export interface SlashCommandResult {
67
- /** 是否成功 */
68
- success: boolean;
69
- /** 结果类型(用于 UI 展示) */
70
- type?: 'success' | 'error' | 'info' | 'silent' | 'selector';
71
- /** 内容(Markdown 格式) */
72
- content?: string;
73
- /** 消息(简短提示) */
74
- message?: string;
75
- /** 错误信息 */
76
- error?: string;
77
- /** 是否继续处理(用于某些命令可能需要修改后续流程) */
78
- shouldContinue?: boolean;
79
- /** 额外数据 */
80
- data?: any;
81
- /** 选择器配置(type 为 'selector' 时使用) */
82
- selector?: {
83
- title: string;
84
- options: SelectorOption[];
85
- /** 选择后的处理器名称 */
86
- handler: 'theme' | 'model';
87
- };
88
- /** 是否将内容发送给 Agent(自定义命令默认 true) */
89
- sendToAgent?: boolean;
90
- }
91
-
92
- /**
93
- * Slash 命令定义
94
- */
95
- export interface SlashCommand {
96
- /** 命令名称(不含 /) */
97
- name: string;
98
- /** 命令别名 */
99
- aliases?: string[];
100
- /** 命令描述 */
101
- description: string;
102
- /** 详细描述 */
103
- fullDescription?: string;
104
- /** 使用示例 */
105
- usage?: string;
106
- /** 命令分类 */
107
- category?: CommandCategory;
108
- /** 示例列表 */
109
- examples?: string[];
110
- /** 命令处理函数 */
111
- handler: (args: string, context: SlashCommandContext) => Promise<SlashCommandResult>;
112
- }
113
-
114
- /**
115
- *
116
- */
117
- export interface CommandSuggestion {
118
- /** 完整命令(含 /) */
119
- command: string;
120
- /** 命令描述 */
121
- description: string;
122
- /** 匹配分数 (0-100) */
123
- matchScore?: number;
124
- }
125
-
126
- /**
127
- *
128
- */
129
- export type SlashCommandRegistry = Record<string, SlashCommand>;
130
-
131
- // ==================== 自定义命令类
132
-
133
- /**
134
- *
135
- */
136
- export interface CustomCommandConfig {
137
- /** 命令描述(AI 调用必需) */
138
- description?: string;
139
- /** 参数提示,如 [message] */
140
- argumentHint?: string;
141
- /** 限制可用工具列表 */
142
- allowedTools?: string[];
143
- /** 指定执行模型 */
144
- model?: string;
145
- /** 禁止 AI 调用(默认 false) */
146
- disableModelInvocation?: boolean;
147
- }
148
-
149
- /**
150
- *
151
- */
152
- export type CustomCommandSource = 'user' | 'project';
153
-
154
- /**
155
- *
156
- */
157
- export type CustomCommandSourceDir = 'claude' | 'aegis';
158
-
159
- /**
160
- *
161
- */
162
- export interface CustomCommand {
163
- /** 命令名(不含 /) */
164
- name: string;
165
- /** 命名空间(子目录名) */
166
- namespace?: string;
167
- /** Frontmatter 配置 */
168
- config: CustomCommandConfig;
169
- /** Markdown 正文 */
170
- content: string;
171
- /** 文件完整路径 */
172
- path: string;
173
- /** 来源类型 */
174
- source: CustomCommandSource;
175
- /** 目录类型 */
176
- sourceDir: CustomCommandSourceDir;
177
- }
178
-
179
- /**
180
- *
181
- */
182
- export interface CustomCommandExecutionContext {
183
- /** 命令参数 */
184
- args: string[];
185
- /** 工作目录 */
186
- workspaceRoot: string;
187
- /** 中断信号 */
188
- signal?: AbortSignal;
189
- }
190
-
191
- /**
192
- *
193
- */
194
- export interface CustomCommandDiscoveryResult {
195
- /** 发现的命令列表 */
196
- commands: CustomCommand[];
197
- /** 警告信息 */
198
- warnings: string[];
199
- /** 扫描的目录 */
200
- scannedDirs: string[];
201
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * Zustand Store 模块导出
3
- *
4
- *
5
- */
6
-
7
- // 类
8
- export * from './types.js';
9
-
10
- // Vanilla Store(非 React 环
11
- export {
12
- vanillaStore,
13
- getState,
14
- subscribe,
15
- sessionActions,
16
- configActions,
17
- appActions,
18
- focusActions,
19
- commandActions,
20
- getConfig,
21
- getCurrentModel,
22
- getPermissionMode,
23
- ensureStoreInitialized,
24
- subscribeToState,
25
- subscribeToTodos,
26
- subscribeToMessages,
27
- } from './vanilla.js';
28
-
29
- // React 选择器
30
- export {
31
- useClawdStore,
32
- // Session
33
- useSessionId,
34
- useMessages,
35
- useIsThinking,
36
- useIsCompacting,
37
- useSessionError,
38
- useCurrentCommand,
39
- useTokenUsage,
40
- // Config
41
- useConfig,
42
- useTheme,
43
- usePermissionMode,
44
- useAllModels,
45
- useCurrentModel,
46
- // App
47
- useInitializationStatus,
48
- useInitializationError,
49
- useActiveModal,
50
- useTodos,
51
- useAwaitingSecondCtrlC,
52
- useShowAllThinking,
53
- useAutoRouterActiveModel,
54
- useRouterEnabled,
55
- useWorkflow,
56
- // Focus
57
- useCurrentFocus,
58
- usePreviousFocus,
59
- // Command
60
- useIsProcessing,
61
- usePendingCommands,
62
- // 派生选择
63
- useContextRemaining,
64
- useIsInputDisabled,
65
- useIsBusy,
66
- useTodoStats,
67
- // 细粒度消息选择
68
- useMessageCount,
69
- useMessageById,
70
- useMessageIds,
71
- useHasStreamingMessage,
72
- useStreamingMessageId,
73
- // 组合选择
74
- useSessionState,
75
- useAppState,
76
- } from './selectors.js';
@@ -1,246 +0,0 @@
1
- /**
2
- * Store 选择器
3
- *
4
- *
5
- */
6
-
7
- import { useStore } from 'zustand';
8
- import { useShallow } from 'zustand/react/shallow';
9
- import { vanillaStore } from './vanilla.js';
10
- import type { ClawdStore, SessionMessage, TodoItem, FocusId, WorkflowState } from './types.js';
11
- import type { ModelConfig, PermissionMode } from '../config/types.js';
12
-
13
- // ========== 基
14
-
15
- /**
16
- * React Hook - 订阅 Clawd Store
17
- */
18
- export function useClawdStore<T>(selector: (state: ClawdStore) => T): T {
19
- return useStore(vanillaStore, selector);
20
- }
21
-
22
- // ========== Session 选择
23
-
24
- export const useSessionId = () =>
25
- useClawdStore((state) => state.session.sessionId);
26
-
27
- export const useMessages = () =>
28
- useClawdStore((state) => state.session.messages);
29
-
30
- export const useIsThinking = () =>
31
- useClawdStore((state) => state.session.isThinking);
32
-
33
- export const useIsCompacting = () =>
34
- useClawdStore((state) => state.session.isCompacting);
35
-
36
- export const useSessionError = () =>
37
- useClawdStore((state) => state.session.error);
38
-
39
- export const useCurrentCommand = () =>
40
- useClawdStore((state) => state.session.currentCommand);
41
-
42
- export const useTokenUsage = () =>
43
- useClawdStore((state) => state.session.tokenUsage);
44
-
45
- // ========== Config 选择
46
-
47
- export const useConfig = () =>
48
- useClawdStore((state) => state.config.config);
49
-
50
- export const useTheme = () =>
51
- useClawdStore((state) => state.config.config?.theme || 'dark');
52
-
53
- export const usePermissionMode = () =>
54
- useClawdStore(
55
- (state) => (state.config.config?.defaultPermissionMode || 'default') as PermissionMode
56
- );
57
-
58
- // 常量空引用,避免重渲
59
- const EMPTY_MODELS: ModelConfig[] = [];
60
-
61
- export const useAllModels = () =>
62
- useClawdStore(
63
- (state) => state.config.config?.models ?? EMPTY_MODELS
64
- );
65
-
66
- /**
67
- *
68
- */
69
- export const useCurrentModel = () =>
70
- useClawdStore((state) => {
71
- const config = state.config.config;
72
- if (!config) return undefined;
73
-
74
- // 优先使
75
- if (config.currentModelId && config.models) {
76
- const model = config.models.find((m) => m.id === config.currentModelId);
77
- if (model) return model;
78
- }
79
-
80
- // 回退
81
- if (config.models && config.models.length > 0) {
82
- return config.models[0];
83
- }
84
-
85
- // 回退
86
- return config.default;
87
- });
88
-
89
- // ========== App 选择
90
-
91
- export const useInitializationStatus = () =>
92
- useClawdStore((state) => state.app.initializationStatus);
93
-
94
- export const useInitializationError = () =>
95
- useClawdStore((state) => state.app.initializationError);
96
-
97
- export const useActiveModal = () =>
98
- useClawdStore((state) => state.app.activeModal);
99
-
100
- export const useTodos = () =>
101
- useClawdStore((state) => state.app.todos);
102
-
103
- export const useAwaitingSecondCtrlC = () =>
104
- useClawdStore((state) => state.app.awaitingSecondCtrlC);
105
-
106
- export const useShowAllThinking = () =>
107
- useClawdStore((state) => state.app.showAllThinking);
108
-
109
- export const useAutoRouterActiveModel = () =>
110
- useClawdStore((state) => state.app.autoRouterActiveModel);
111
-
112
- export const useRouterEnabled = () =>
113
- useClawdStore((state) => state.config.config?.autoRouter?.enabled ?? false);
114
-
115
- export const useWorkflow = () =>
116
- useClawdStore((state) => state.app.workflow);
117
-
118
- // ========== Focus 选择
119
-
120
- export const useCurrentFocus = () =>
121
- useClawdStore((state) => state.focus.currentFocus);
122
-
123
- export const usePreviousFocus = () =>
124
- useClawdStore((state) => state.focus.previousFocus);
125
-
126
- // ========== Command 选择
127
-
128
- export const useIsProcessing = () =>
129
- useClawdStore((state) => state.command.isProcessing);
130
-
131
- export const usePendingCommands = () =>
132
- useClawdStore((state) => state.command.pendingCommands);
133
-
134
- // ========== 派生选择
135
-
136
- /**
137
- *
138
- */
139
- export const useContextRemaining = () =>
140
- useClawdStore((state) => {
141
- const { inputTokens, maxContextTokens } = state.session.tokenUsage;
142
- if (maxContextTokens <= 0) return 100;
143
- return Math.round(Math.max(0, 100 - (inputTokens / maxContextTokens) * 100));
144
- });
145
-
146
- /**
147
- *
148
- */
149
- export const useIsInputDisabled = () =>
150
- useClawdStore((state) => {
151
- const isThinking = state.session.isThinking;
152
- const isReady = state.app.initializationStatus === 'ready';
153
- const hasModal =
154
- state.app.activeModal !== 'none' &&
155
- state.app.activeModal !== 'shortcuts';
156
- return isThinking || !isReady || hasModal;
157
- });
158
-
159
- /**
160
- *
161
- */
162
- export const useIsBusy = () =>
163
- useClawdStore(
164
- (state) => state.session.isThinking || state.command.isProcessing
165
- );
166
-
167
- /**
168
- *
169
- */
170
- export const useTodoStats = () =>
171
- useClawdStore(
172
- useShallow((state) => {
173
- const todos = state.app.todos;
174
- return {
175
- total: todos.length,
176
- completed: todos.filter((t) => t.status === 'completed').length,
177
- inProgress: todos.filter((t) => t.status === 'in_progress').length,
178
- pending: todos.filter((t) => t.status === 'pending').length,
179
- };
180
- })
181
- );
182
-
183
- // ========== 细粒度消息选择
184
-
185
- /**
186
- *
187
- */
188
- export const useMessageCount = () =>
189
- useClawdStore((state) => state.session.messages.length);
190
-
191
- /**
192
- *
193
- */
194
- export const useMessageById = (id: string) =>
195
- useClawdStore((state) => state.session.messages.find(m => m.id === id));
196
-
197
- /**
198
- *
199
- */
200
- export const useMessageIds = () =>
201
- useClawdStore(
202
- useShallow((state) => state.session.messages.map(m => m.id))
203
- );
204
-
205
- /**
206
- *
207
- */
208
- export const useHasStreamingMessage = () =>
209
- useClawdStore((state) => state.session.messages.some(m => m.isStreaming));
210
-
211
- /**
212
- *
213
- */
214
- export const useStreamingMessageId = () =>
215
- useClawdStore((state) => {
216
- const streaming = state.session.messages.find(m => m.isStreaming);
217
- return streaming?.id ?? null;
218
- });
219
-
220
- // ========== 组合选择器(使
221
-
222
- /**
223
- *
224
- */
225
- export const useSessionState = () =>
226
- useClawdStore(
227
- useShallow((state) => ({
228
- sessionId: state.session.sessionId,
229
- messages: state.session.messages,
230
- isThinking: state.session.isThinking,
231
- currentCommand: state.session.currentCommand,
232
- error: state.session.error,
233
- }))
234
- );
235
-
236
- /**
237
- *
238
- */
239
- export const useAppState = () =>
240
- useClawdStore(
241
- useShallow((state) => ({
242
- initializationStatus: state.app.initializationStatus,
243
- initializationError: state.app.initializationError,
244
- activeModal: state.app.activeModal,
245
- }))
246
- );
@@ -1,205 +0,0 @@
1
- /**
2
- * App Slice - 应用状态管理
3
- */
4
-
5
- import type { StateCreator } from 'zustand';
6
- import type { ClawdStore, AppSlice, InitializationStatus, ActiveModal, TodoItem, WorkflowState } from '../types.js';
7
- import { initialWorkflowState } from '../types.js';
8
-
9
- const initialAppState = {
10
- initializationStatus: 'pending' as InitializationStatus,
11
- initializationError: null as string | null,
12
- activeModal: 'none' as ActiveModal,
13
- todos: [] as TodoItem[],
14
- awaitingSecondCtrlC: false,
15
- showAllThinking: false,
16
- manualModelOverride: false,
17
- autoRouterActiveModel: null as string | null,
18
- workflow: { ...initialWorkflowState } as WorkflowState,
19
- };
20
-
21
- export const createAppSlice: StateCreator<
22
- ClawdStore,
23
- [],
24
- [],
25
- AppSlice
26
- > = (set, get) => ({
27
- ...initialAppState,
28
-
29
- actions: {
30
- /**
31
- *
32
- */
33
- setInitializationStatus: (status: InitializationStatus) => {
34
- set((state) => ({
35
- app: { ...state.app, initializationStatus: status },
36
- }));
37
- },
38
-
39
- /**
40
- *
41
- */
42
- setInitializationError: (error: string | null) => {
43
- set((state) => ({
44
- app: {
45
- ...state.app,
46
- initializationError: error,
47
- initializationStatus: error ? 'error' : state.app.initializationStatus,
48
- },
49
- }));
50
- },
51
-
52
- /**
53
- *
54
- */
55
- setActiveModal: (modal: ActiveModal) => {
56
- set((state) => ({
57
- app: { ...state.app, activeModal: modal },
58
- }));
59
- },
60
-
61
- /**
62
- *
63
- */
64
- setTodos: (todos: TodoItem[]) => {
65
- set((state) => ({
66
- app: { ...state.app, todos },
67
- }));
68
- },
69
-
70
- /**
71
- *
72
- */
73
- addTodo: (todo: TodoItem) => {
74
- set((state) => ({
75
- app: {
76
- ...state.app,
77
- todos: [...state.app.todos, todo],
78
- },
79
- }));
80
- },
81
-
82
- /**
83
- *
84
- */
85
- updateTodo: (id: string, updates: Partial<TodoItem>) => {
86
- set((state) => ({
87
- app: {
88
- ...state.app,
89
- todos: state.app.todos.map((todo) =>
90
- todo.id === id ? { ...todo, ...updates } : todo
91
- ),
92
- },
93
- }));
94
- },
95
-
96
- /**
97
- *
98
- */
99
- removeTodo: (id: string) => {
100
- set((state) => ({
101
- app: {
102
- ...state.app,
103
- todos: state.app.todos.filter((todo) => todo.id !== id),
104
- },
105
- }));
106
- },
107
-
108
- /**
109
- *
110
- */
111
- setAwaitingSecondCtrlC: (awaiting: boolean) => {
112
- set((state) => ({
113
- app: { ...state.app, awaitingSecondCtrlC: awaiting },
114
- }));
115
- },
116
-
117
- /**
118
- *
119
- */
120
- toggleShowAllThinking: () => {
121
- set((state) => ({
122
- app: { ...state.app, showAllThinking: !state.app.showAllThinking },
123
- }));
124
- },
125
-
126
- /**
127
- *
128
- */
129
- setManualModelOverride: (value: boolean) => {
130
- set((state) => ({
131
- app: { ...state.app, manualModelOverride: value },
132
- }));
133
- },
134
-
135
- /**
136
- *
137
- */
138
- setAutoRouterActiveModel: (label: string | null) => {
139
- set((state) => ({
140
- app: { ...state.app, autoRouterActiveModel: label },
141
- }));
142
- },
143
-
144
- // ── Workflow ──────────────────────────────────────────
145
- workflow: {
146
- setWorkflow: (opts: { phase: string; target: string; steps: string[] }) => {
147
- set((state) => ({
148
- app: {
149
- ...state.app,
150
- workflow: {
151
- visible: true,
152
- phase: opts.phase,
153
- target: opts.target,
154
- steps: opts.steps.map((label, i) => ({
155
- label,
156
- status: i === 0 ? 'active' as const : 'pending' as const,
157
- })),
158
- currentStepIndex: 0,
159
- totalSteps: opts.steps.length,
160
- },
161
- },
162
- }));
163
- },
164
-
165
- advanceStep: () => {
166
- set((state) => {
167
- const wf = state.app.workflow;
168
- if (!wf.visible) return state;
169
- const nextIndex = wf.currentStepIndex + 1;
170
- if (nextIndex >= wf.totalSteps) {
171
- return {
172
- app: {
173
- ...state.app,
174
- workflow: { ...initialWorkflowState },
175
- },
176
- };
177
- }
178
- const updatedSteps = wf.steps.map((s, i) => ({
179
- ...s,
180
- status: i < nextIndex ? 'done' as const : i === nextIndex ? 'active' as const : 'pending' as const,
181
- }));
182
- return {
183
- app: {
184
- ...state.app,
185
- workflow: {
186
- ...wf,
187
- steps: updatedSteps,
188
- currentStepIndex: nextIndex,
189
- },
190
- },
191
- };
192
- });
193
- },
194
-
195
- clearWorkflow: () => {
196
- set((state) => ({
197
- app: {
198
- ...state.app,
199
- workflow: { ...initialWorkflowState },
200
- },
201
- }));
202
- },
203
- },
204
- },
205
- });