@shareai-lab/kode 1.0.71 → 1.0.73

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 (106) hide show
  1. package/README.md +142 -1
  2. package/README.zh-CN.md +47 -1
  3. package/package.json +5 -1
  4. package/src/ProjectOnboarding.tsx +47 -29
  5. package/src/Tool.ts +33 -4
  6. package/src/commands/agents.tsx +3401 -0
  7. package/src/commands/help.tsx +2 -2
  8. package/src/commands/resume.tsx +2 -1
  9. package/src/commands/terminalSetup.ts +4 -4
  10. package/src/commands.ts +3 -0
  11. package/src/components/ApproveApiKey.tsx +1 -1
  12. package/src/components/Config.tsx +10 -6
  13. package/src/components/ConsoleOAuthFlow.tsx +5 -4
  14. package/src/components/CustomSelect/select-option.tsx +28 -2
  15. package/src/components/CustomSelect/select.tsx +14 -5
  16. package/src/components/CustomSelect/theme.ts +45 -0
  17. package/src/components/Help.tsx +4 -4
  18. package/src/components/InvalidConfigDialog.tsx +1 -1
  19. package/src/components/LogSelector.tsx +1 -1
  20. package/src/components/MCPServerApprovalDialog.tsx +1 -1
  21. package/src/components/Message.tsx +2 -0
  22. package/src/components/ModelListManager.tsx +10 -6
  23. package/src/components/ModelSelector.tsx +201 -23
  24. package/src/components/ModelStatusDisplay.tsx +7 -5
  25. package/src/components/PromptInput.tsx +117 -87
  26. package/src/components/SentryErrorBoundary.ts +3 -3
  27. package/src/components/StickerRequestForm.tsx +16 -0
  28. package/src/components/StructuredDiff.tsx +36 -29
  29. package/src/components/TextInput.tsx +13 -0
  30. package/src/components/TodoItem.tsx +11 -0
  31. package/src/components/TrustDialog.tsx +1 -1
  32. package/src/components/messages/AssistantLocalCommandOutputMessage.tsx +5 -1
  33. package/src/components/messages/AssistantToolUseMessage.tsx +14 -4
  34. package/src/components/messages/TaskProgressMessage.tsx +32 -0
  35. package/src/components/messages/TaskToolMessage.tsx +58 -0
  36. package/src/components/permissions/FallbackPermissionRequest.tsx +2 -4
  37. package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +1 -1
  38. package/src/components/permissions/FileEditPermissionRequest/FileEditToolDiff.tsx +5 -3
  39. package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +1 -1
  40. package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +5 -3
  41. package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +2 -4
  42. package/src/components/permissions/PermissionRequest.tsx +3 -5
  43. package/src/constants/macros.ts +2 -0
  44. package/src/constants/modelCapabilities.ts +179 -0
  45. package/src/constants/models.ts +90 -0
  46. package/src/constants/product.ts +1 -1
  47. package/src/context.ts +7 -7
  48. package/src/entrypoints/cli.tsx +23 -3
  49. package/src/entrypoints/mcp.ts +10 -10
  50. package/src/hooks/useCanUseTool.ts +1 -1
  51. package/src/hooks/useTextInput.ts +5 -2
  52. package/src/hooks/useUnifiedCompletion.ts +1404 -0
  53. package/src/messages.ts +1 -0
  54. package/src/query.ts +3 -0
  55. package/src/screens/ConfigureNpmPrefix.tsx +1 -1
  56. package/src/screens/Doctor.tsx +1 -1
  57. package/src/screens/REPL.tsx +15 -9
  58. package/src/services/adapters/base.ts +38 -0
  59. package/src/services/adapters/chatCompletions.ts +90 -0
  60. package/src/services/adapters/responsesAPI.ts +170 -0
  61. package/src/services/claude.ts +198 -62
  62. package/src/services/customCommands.ts +43 -22
  63. package/src/services/gpt5ConnectionTest.ts +340 -0
  64. package/src/services/mcpClient.ts +1 -1
  65. package/src/services/mentionProcessor.ts +273 -0
  66. package/src/services/modelAdapterFactory.ts +69 -0
  67. package/src/services/openai.ts +521 -12
  68. package/src/services/responseStateManager.ts +90 -0
  69. package/src/services/systemReminder.ts +113 -12
  70. package/src/test/testAdapters.ts +96 -0
  71. package/src/tools/AskExpertModelTool/AskExpertModelTool.tsx +120 -56
  72. package/src/tools/BashTool/BashTool.tsx +4 -31
  73. package/src/tools/BashTool/BashToolResultMessage.tsx +1 -1
  74. package/src/tools/BashTool/OutputLine.tsx +1 -0
  75. package/src/tools/FileEditTool/FileEditTool.tsx +4 -5
  76. package/src/tools/FileReadTool/FileReadTool.tsx +43 -10
  77. package/src/tools/MCPTool/MCPTool.tsx +2 -1
  78. package/src/tools/MultiEditTool/MultiEditTool.tsx +2 -2
  79. package/src/tools/NotebookReadTool/NotebookReadTool.tsx +15 -23
  80. package/src/tools/StickerRequestTool/StickerRequestTool.tsx +1 -1
  81. package/src/tools/TaskTool/TaskTool.tsx +170 -86
  82. package/src/tools/TaskTool/prompt.ts +61 -25
  83. package/src/tools/ThinkTool/ThinkTool.tsx +1 -3
  84. package/src/tools/TodoWriteTool/TodoWriteTool.tsx +11 -10
  85. package/src/tools/lsTool/lsTool.tsx +5 -2
  86. package/src/tools.ts +16 -16
  87. package/src/types/conversation.ts +51 -0
  88. package/src/types/logs.ts +58 -0
  89. package/src/types/modelCapabilities.ts +64 -0
  90. package/src/types/notebook.ts +87 -0
  91. package/src/utils/advancedFuzzyMatcher.ts +290 -0
  92. package/src/utils/agentLoader.ts +284 -0
  93. package/src/utils/ask.tsx +1 -0
  94. package/src/utils/commands.ts +1 -1
  95. package/src/utils/commonUnixCommands.ts +161 -0
  96. package/src/utils/config.ts +173 -2
  97. package/src/utils/conversationRecovery.ts +1 -0
  98. package/src/utils/debugLogger.ts +13 -13
  99. package/src/utils/exampleCommands.ts +1 -0
  100. package/src/utils/fuzzyMatcher.ts +328 -0
  101. package/src/utils/messages.tsx +6 -5
  102. package/src/utils/responseState.ts +23 -0
  103. package/src/utils/secureFile.ts +559 -0
  104. package/src/utils/terminal.ts +1 -0
  105. package/src/utils/theme.ts +11 -0
  106. package/src/hooks/useSlashCommandTypeahead.ts +0 -137
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Mention Processor Service
3
+ * Handles @agent and @file mentions through the system reminder infrastructure
4
+ * Designed to integrate naturally with the existing event-driven architecture
5
+ */
6
+
7
+ import { emitReminderEvent } from './systemReminder'
8
+ import { getAvailableAgentTypes } from '../utils/agentLoader'
9
+ import { existsSync } from 'fs'
10
+ import { resolve } from 'path'
11
+ import { getCwd } from '../utils/state'
12
+
13
+ export interface MentionContext {
14
+ type: 'agent' | 'file'
15
+ mention: string
16
+ resolved: string
17
+ exists: boolean
18
+ metadata?: any
19
+ }
20
+
21
+ export interface ProcessedMentions {
22
+ agents: MentionContext[]
23
+ files: MentionContext[]
24
+ hasAgentMentions: boolean
25
+ hasFileMentions: boolean
26
+ }
27
+
28
+ class MentionProcessorService {
29
+ // Centralized mention patterns - single source of truth
30
+ private static readonly MENTION_PATTERNS = {
31
+ runAgent: /@(run-agent-[\w\-]+)/g,
32
+ agent: /@(agent-[\w\-]+)/g, // Legacy support
33
+ askModel: /@(ask-[\w\-]+)/g,
34
+ file: /@([a-zA-Z0-9/._-]+(?:\.[a-zA-Z0-9]+)?)/g
35
+ } as const
36
+
37
+ private agentCache: Map<string, boolean> = new Map()
38
+ private lastAgentCheck: number = 0
39
+ private CACHE_TTL = 60000 // 1 minute cache
40
+
41
+ /**
42
+ * Process mentions in user input and emit appropriate events
43
+ * This follows the event-driven philosophy of system reminders
44
+ */
45
+ public async processMentions(input: string): Promise<ProcessedMentions> {
46
+ const result: ProcessedMentions = {
47
+ agents: [],
48
+ files: [],
49
+ hasAgentMentions: false,
50
+ hasFileMentions: false,
51
+ }
52
+
53
+ try {
54
+
55
+ // Process agent mentions with unified logic to eliminate code duplication
56
+ const agentMentions = this.extractAgentMentions(input)
57
+ if (agentMentions.length > 0) {
58
+ await this.refreshAgentCache()
59
+
60
+ for (const { mention, agentType, isAskModel } of agentMentions) {
61
+ if (isAskModel || this.agentCache.has(agentType)) {
62
+ result.agents.push({
63
+ type: 'agent',
64
+ mention,
65
+ resolved: agentType,
66
+ exists: true,
67
+ metadata: isAskModel ? { type: 'ask-model' } : undefined
68
+ })
69
+ result.hasAgentMentions = true
70
+
71
+ // Emit appropriate event based on mention type
72
+ this.emitAgentMentionEvent(mention, agentType, isAskModel)
73
+ }
74
+ }
75
+ }
76
+
77
+ // No longer process @xxx format - treat as regular text (emails, etc.)
78
+
79
+ // Process file mentions (exclude agent and ask-model mentions)
80
+ const fileMatches = [...input.matchAll(MentionProcessorService.MENTION_PATTERNS.file)]
81
+ const processedAgentMentions = new Set(agentMentions.map(am => am.mention))
82
+
83
+ for (const match of fileMatches) {
84
+ const mention = match[1]
85
+
86
+ // Skip if this is an agent or ask-model mention (already processed)
87
+ if (mention.startsWith('run-agent-') || mention.startsWith('agent-') || mention.startsWith('ask-') || processedAgentMentions.has(mention)) {
88
+ continue
89
+ }
90
+
91
+ // Check if it's a file
92
+ const filePath = this.resolveFilePath(mention)
93
+ if (existsSync(filePath)) {
94
+ result.files.push({
95
+ type: 'file',
96
+ mention,
97
+ resolved: filePath,
98
+ exists: true,
99
+ })
100
+ result.hasFileMentions = true
101
+
102
+ // Emit file mention event for system reminder to handle
103
+ emitReminderEvent('file:mentioned', {
104
+ filePath: filePath,
105
+ originalMention: mention,
106
+ timestamp: Date.now(),
107
+ })
108
+ }
109
+ }
110
+
111
+ return result
112
+ } catch (error) {
113
+ console.warn('[MentionProcessor] Failed to process mentions:', {
114
+ input: input.substring(0, 100) + (input.length > 100 ? '...' : ''),
115
+ error: error instanceof Error ? error.message : error
116
+ })
117
+
118
+ // Return empty result on error to maintain system stability
119
+ return {
120
+ agents: [],
121
+ files: [],
122
+ hasAgentMentions: false,
123
+ hasFileMentions: false,
124
+ }
125
+ }
126
+ }
127
+
128
+ // Removed identifyMention method as it's no longer needed with separate processing
129
+
130
+ /**
131
+ * Resolve file path relative to current working directory
132
+ */
133
+ private resolveFilePath(mention: string): string {
134
+ // Simple consistent logic: mention is always relative to current directory
135
+ return resolve(getCwd(), mention)
136
+ }
137
+
138
+ /**
139
+ * Refresh the agent cache periodically
140
+ * This avoids hitting the agent loader on every mention
141
+ */
142
+ private async refreshAgentCache(): Promise<void> {
143
+ const now = Date.now()
144
+ if (now - this.lastAgentCheck < this.CACHE_TTL) {
145
+ return // Cache is still fresh
146
+ }
147
+
148
+ try {
149
+ const agents = await getAvailableAgentTypes()
150
+ const previousCacheSize = this.agentCache.size
151
+ this.agentCache.clear()
152
+
153
+ for (const agent of agents) {
154
+ // Store only the agent type without prefix for consistent lookup
155
+ this.agentCache.set(agent.agentType, true)
156
+ }
157
+
158
+ this.lastAgentCheck = now
159
+
160
+ // Log cache refresh for debugging mention resolution issues
161
+ if (agents.length !== previousCacheSize) {
162
+ console.log('[MentionProcessor] Agent cache refreshed:', {
163
+ agentCount: agents.length,
164
+ previousCacheSize,
165
+ cacheAge: now - this.lastAgentCheck
166
+ })
167
+ }
168
+ } catch (error) {
169
+ console.warn('[MentionProcessor] Failed to refresh agent cache, keeping existing cache:', {
170
+ error: error instanceof Error ? error.message : error,
171
+ cacheSize: this.agentCache.size,
172
+ lastRefresh: new Date(this.lastAgentCheck).toISOString()
173
+ })
174
+ // Keep existing cache on error to maintain functionality
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Extract agent mentions with unified pattern matching
180
+ * Consolidates run-agent, agent, and ask-model detection logic
181
+ */
182
+ private extractAgentMentions(input: string): Array<{ mention: string; agentType: string; isAskModel: boolean }> {
183
+ const mentions: Array<{ mention: string; agentType: string; isAskModel: boolean }> = []
184
+
185
+ // Process @run-agent-xxx format (preferred)
186
+ const runAgentMatches = [...input.matchAll(MentionProcessorService.MENTION_PATTERNS.runAgent)]
187
+ for (const match of runAgentMatches) {
188
+ const mention = match[1]
189
+ const agentType = mention.replace(/^run-agent-/, '')
190
+ mentions.push({ mention, agentType, isAskModel: false })
191
+ }
192
+
193
+ // Process @agent-xxx format (legacy)
194
+ const agentMatches = [...input.matchAll(MentionProcessorService.MENTION_PATTERNS.agent)]
195
+ for (const match of agentMatches) {
196
+ const mention = match[1]
197
+ const agentType = mention.replace(/^agent-/, '')
198
+ mentions.push({ mention, agentType, isAskModel: false })
199
+ }
200
+
201
+ // Process @ask-model mentions
202
+ const askModelMatches = [...input.matchAll(MentionProcessorService.MENTION_PATTERNS.askModel)]
203
+ for (const match of askModelMatches) {
204
+ const mention = match[1]
205
+ mentions.push({ mention, agentType: mention, isAskModel: true })
206
+ }
207
+
208
+ return mentions
209
+ }
210
+
211
+ /**
212
+ * Emit agent mention event with proper typing
213
+ * Centralized event emission to ensure consistency
214
+ */
215
+ private emitAgentMentionEvent(mention: string, agentType: string, isAskModel: boolean): void {
216
+ try {
217
+ const eventData = {
218
+ originalMention: mention,
219
+ timestamp: Date.now(),
220
+ }
221
+
222
+ if (isAskModel) {
223
+ emitReminderEvent('ask-model:mentioned', {
224
+ ...eventData,
225
+ modelName: mention,
226
+ })
227
+ } else {
228
+ emitReminderEvent('agent:mentioned', {
229
+ ...eventData,
230
+ agentType,
231
+ })
232
+ }
233
+
234
+ // Debug log for mention event emission tracking
235
+ console.log('[MentionProcessor] Emitted mention event:', {
236
+ type: isAskModel ? 'ask-model' : 'agent',
237
+ mention,
238
+ agentType: isAskModel ? undefined : agentType
239
+ })
240
+ } catch (error) {
241
+ console.error('[MentionProcessor] Failed to emit mention event:', {
242
+ mention,
243
+ agentType,
244
+ isAskModel,
245
+ error: error instanceof Error ? error.message : error
246
+ })
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Clear caches - useful for testing or reset
252
+ */
253
+ public clearCache(): void {
254
+ this.agentCache.clear()
255
+ this.lastAgentCheck = 0
256
+ }
257
+ }
258
+
259
+ // Export singleton instance
260
+ export const mentionProcessor = new MentionProcessorService()
261
+
262
+ /**
263
+ * Process mentions in user input
264
+ * This is the main API for the mention processor
265
+ */
266
+ export const processMentions = (input: string) =>
267
+ mentionProcessor.processMentions(input)
268
+
269
+ /**
270
+ * Clear mention processor caches
271
+ */
272
+ export const clearMentionCache = () =>
273
+ mentionProcessor.clearCache()
@@ -0,0 +1,69 @@
1
+ import { ModelAPIAdapter } from './adapters/base'
2
+ import { ResponsesAPIAdapter } from './adapters/responsesAPI'
3
+ import { ChatCompletionsAdapter } from './adapters/chatCompletions'
4
+ import { getModelCapabilities } from '../constants/modelCapabilities'
5
+ import { ModelProfile, getGlobalConfig } from '../utils/config'
6
+ import { ModelCapabilities } from '../types/modelCapabilities'
7
+
8
+ export class ModelAdapterFactory {
9
+ /**
10
+ * Create appropriate adapter based on model configuration
11
+ */
12
+ static createAdapter(modelProfile: ModelProfile): ModelAPIAdapter {
13
+ const capabilities = getModelCapabilities(modelProfile.modelName)
14
+
15
+ // Determine which API to use
16
+ const apiType = this.determineAPIType(modelProfile, capabilities)
17
+
18
+ // Create corresponding adapter
19
+ switch (apiType) {
20
+ case 'responses_api':
21
+ return new ResponsesAPIAdapter(capabilities, modelProfile)
22
+ case 'chat_completions':
23
+ default:
24
+ return new ChatCompletionsAdapter(capabilities, modelProfile)
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Determine which API should be used
30
+ */
31
+ private static determineAPIType(
32
+ modelProfile: ModelProfile,
33
+ capabilities: ModelCapabilities
34
+ ): 'responses_api' | 'chat_completions' {
35
+ // If model doesn't support Responses API, use Chat Completions directly
36
+ if (capabilities.apiArchitecture.primary !== 'responses_api') {
37
+ return 'chat_completions'
38
+ }
39
+
40
+ // Check if this is official OpenAI endpoint
41
+ const isOfficialOpenAI = !modelProfile.baseURL ||
42
+ modelProfile.baseURL.includes('api.openai.com')
43
+
44
+ // Non-official endpoints use Chat Completions (even if model supports Responses API)
45
+ if (!isOfficialOpenAI) {
46
+ // If there's a fallback option, use fallback
47
+ if (capabilities.apiArchitecture.fallback === 'chat_completions') {
48
+ return 'chat_completions'
49
+ }
50
+ // Otherwise use primary (might fail, but let it try)
51
+ return capabilities.apiArchitecture.primary
52
+ }
53
+
54
+ // For now, always use Responses API for supported models when on official endpoint
55
+ // Streaming fallback will be handled at runtime if needed
56
+
57
+ // Use primary API type
58
+ return capabilities.apiArchitecture.primary
59
+ }
60
+
61
+ /**
62
+ * Check if model should use Responses API
63
+ */
64
+ static shouldUseResponsesAPI(modelProfile: ModelProfile): boolean {
65
+ const capabilities = getModelCapabilities(modelProfile.modelName)
66
+ const apiType = this.determineAPIType(modelProfile, capabilities)
67
+ return apiType === 'responses_api'
68
+ }
69
+ }