@shareai-lab/kode 1.1.14 β†’ 1.1.16-dev.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 (289) hide show
  1. package/cli.js +77 -82
  2. package/dist/entrypoints/cli.js +59 -38
  3. package/dist/entrypoints/cli.js.map +3 -3
  4. package/dist/index.js +5 -26
  5. package/dist/package.json +4 -1
  6. package/package.json +11 -104
  7. package/dist/test/testAdapters.js +0 -88
  8. package/dist/test/testAdapters.js.map +0 -1
  9. package/src/ProjectOnboarding.tsx +0 -198
  10. package/src/Tool.ts +0 -83
  11. package/src/commands/agents.tsx +0 -3416
  12. package/src/commands/approvedTools.ts +0 -53
  13. package/src/commands/bug.tsx +0 -20
  14. package/src/commands/clear.ts +0 -43
  15. package/src/commands/compact.ts +0 -120
  16. package/src/commands/config.tsx +0 -19
  17. package/src/commands/cost.ts +0 -18
  18. package/src/commands/ctx_viz.ts +0 -209
  19. package/src/commands/doctor.ts +0 -24
  20. package/src/commands/help.tsx +0 -19
  21. package/src/commands/init.ts +0 -37
  22. package/src/commands/listen.ts +0 -42
  23. package/src/commands/login.tsx +0 -51
  24. package/src/commands/logout.tsx +0 -40
  25. package/src/commands/mcp.ts +0 -41
  26. package/src/commands/model.tsx +0 -40
  27. package/src/commands/modelstatus.tsx +0 -20
  28. package/src/commands/onboarding.tsx +0 -34
  29. package/src/commands/pr_comments.ts +0 -59
  30. package/src/commands/refreshCommands.ts +0 -54
  31. package/src/commands/release-notes.ts +0 -34
  32. package/src/commands/resume.tsx +0 -31
  33. package/src/commands/review.ts +0 -49
  34. package/src/commands/terminalSetup.ts +0 -221
  35. package/src/commands.ts +0 -139
  36. package/src/components/ApproveApiKey.tsx +0 -93
  37. package/src/components/AsciiLogo.tsx +0 -13
  38. package/src/components/AutoUpdater.tsx +0 -148
  39. package/src/components/Bug.tsx +0 -367
  40. package/src/components/Config.tsx +0 -293
  41. package/src/components/ConsoleOAuthFlow.tsx +0 -327
  42. package/src/components/Cost.tsx +0 -23
  43. package/src/components/CostThresholdDialog.tsx +0 -46
  44. package/src/components/CustomSelect/option-map.ts +0 -42
  45. package/src/components/CustomSelect/select-option.tsx +0 -78
  46. package/src/components/CustomSelect/select.tsx +0 -152
  47. package/src/components/CustomSelect/theme.ts +0 -45
  48. package/src/components/CustomSelect/use-select-state.ts +0 -414
  49. package/src/components/CustomSelect/use-select.ts +0 -35
  50. package/src/components/FallbackToolUseRejectedMessage.tsx +0 -15
  51. package/src/components/FileEditToolUpdatedMessage.tsx +0 -66
  52. package/src/components/Help.tsx +0 -215
  53. package/src/components/HighlightedCode.tsx +0 -33
  54. package/src/components/InvalidConfigDialog.tsx +0 -113
  55. package/src/components/Link.tsx +0 -32
  56. package/src/components/LogSelector.tsx +0 -86
  57. package/src/components/Logo.tsx +0 -170
  58. package/src/components/MCPServerApprovalDialog.tsx +0 -100
  59. package/src/components/MCPServerDialogCopy.tsx +0 -25
  60. package/src/components/MCPServerMultiselectDialog.tsx +0 -109
  61. package/src/components/Message.tsx +0 -221
  62. package/src/components/MessageResponse.tsx +0 -15
  63. package/src/components/MessageSelector.tsx +0 -211
  64. package/src/components/ModeIndicator.tsx +0 -88
  65. package/src/components/ModelConfig.tsx +0 -301
  66. package/src/components/ModelListManager.tsx +0 -227
  67. package/src/components/ModelSelector.tsx +0 -3387
  68. package/src/components/ModelStatusDisplay.tsx +0 -230
  69. package/src/components/Onboarding.tsx +0 -274
  70. package/src/components/PressEnterToContinue.tsx +0 -11
  71. package/src/components/PromptInput.tsx +0 -760
  72. package/src/components/SentryErrorBoundary.ts +0 -39
  73. package/src/components/Spinner.tsx +0 -129
  74. package/src/components/StickerRequestForm.tsx +0 -16
  75. package/src/components/StructuredDiff.tsx +0 -191
  76. package/src/components/TextInput.tsx +0 -259
  77. package/src/components/TodoItem.tsx +0 -47
  78. package/src/components/TokenWarning.tsx +0 -31
  79. package/src/components/ToolUseLoader.tsx +0 -40
  80. package/src/components/TrustDialog.tsx +0 -106
  81. package/src/components/binary-feedback/BinaryFeedback.tsx +0 -63
  82. package/src/components/binary-feedback/BinaryFeedbackOption.tsx +0 -111
  83. package/src/components/binary-feedback/BinaryFeedbackView.tsx +0 -172
  84. package/src/components/binary-feedback/utils.ts +0 -220
  85. package/src/components/messages/AssistantBashOutputMessage.tsx +0 -22
  86. package/src/components/messages/AssistantLocalCommandOutputMessage.tsx +0 -49
  87. package/src/components/messages/AssistantRedactedThinkingMessage.tsx +0 -19
  88. package/src/components/messages/AssistantTextMessage.tsx +0 -144
  89. package/src/components/messages/AssistantThinkingMessage.tsx +0 -40
  90. package/src/components/messages/AssistantToolUseMessage.tsx +0 -132
  91. package/src/components/messages/TaskProgressMessage.tsx +0 -32
  92. package/src/components/messages/TaskToolMessage.tsx +0 -58
  93. package/src/components/messages/UserBashInputMessage.tsx +0 -28
  94. package/src/components/messages/UserCommandMessage.tsx +0 -30
  95. package/src/components/messages/UserKodingInputMessage.tsx +0 -28
  96. package/src/components/messages/UserPromptMessage.tsx +0 -35
  97. package/src/components/messages/UserTextMessage.tsx +0 -39
  98. package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.tsx +0 -12
  99. package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.tsx +0 -36
  100. package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.tsx +0 -31
  101. package/src/components/messages/UserToolResultMessage/UserToolResultMessage.tsx +0 -57
  102. package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.tsx +0 -35
  103. package/src/components/messages/UserToolResultMessage/utils.tsx +0 -56
  104. package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.tsx +0 -121
  105. package/src/components/permissions/FallbackPermissionRequest.tsx +0 -153
  106. package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +0 -182
  107. package/src/components/permissions/FileEditPermissionRequest/FileEditToolDiff.tsx +0 -77
  108. package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +0 -164
  109. package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +0 -83
  110. package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +0 -240
  111. package/src/components/permissions/PermissionRequest.tsx +0 -101
  112. package/src/components/permissions/PermissionRequestTitle.tsx +0 -69
  113. package/src/components/permissions/hooks.ts +0 -44
  114. package/src/components/permissions/toolUseOptions.ts +0 -59
  115. package/src/components/permissions/utils.ts +0 -23
  116. package/src/constants/betas.ts +0 -5
  117. package/src/constants/claude-asterisk-ascii-art.tsx +0 -238
  118. package/src/constants/figures.ts +0 -4
  119. package/src/constants/keys.ts +0 -3
  120. package/src/constants/macros.ts +0 -11
  121. package/src/constants/modelCapabilities.ts +0 -179
  122. package/src/constants/models.ts +0 -1025
  123. package/src/constants/oauth.ts +0 -18
  124. package/src/constants/product.ts +0 -17
  125. package/src/constants/prompts.ts +0 -168
  126. package/src/constants/releaseNotes.ts +0 -7
  127. package/src/context/PermissionContext.tsx +0 -149
  128. package/src/context.ts +0 -278
  129. package/src/cost-tracker.ts +0 -84
  130. package/src/entrypoints/cli.tsx +0 -1561
  131. package/src/entrypoints/mcp.ts +0 -175
  132. package/src/history.ts +0 -25
  133. package/src/hooks/useApiKeyVerification.ts +0 -59
  134. package/src/hooks/useArrowKeyHistory.ts +0 -55
  135. package/src/hooks/useCanUseTool.ts +0 -138
  136. package/src/hooks/useCancelRequest.ts +0 -39
  137. package/src/hooks/useDoublePress.ts +0 -41
  138. package/src/hooks/useExitOnCtrlCD.ts +0 -31
  139. package/src/hooks/useInterval.ts +0 -25
  140. package/src/hooks/useLogMessages.ts +0 -16
  141. package/src/hooks/useLogStartupTime.ts +0 -12
  142. package/src/hooks/useNotifyAfterTimeout.ts +0 -65
  143. package/src/hooks/usePermissionRequestLogging.ts +0 -44
  144. package/src/hooks/useTerminalSize.ts +0 -49
  145. package/src/hooks/useTextInput.ts +0 -317
  146. package/src/hooks/useUnifiedCompletion.ts +0 -1405
  147. package/src/index.ts +0 -34
  148. package/src/messages.ts +0 -38
  149. package/src/permissions.ts +0 -268
  150. package/src/query.ts +0 -720
  151. package/src/screens/ConfigureNpmPrefix.tsx +0 -197
  152. package/src/screens/Doctor.tsx +0 -219
  153. package/src/screens/LogList.tsx +0 -68
  154. package/src/screens/REPL.tsx +0 -813
  155. package/src/screens/ResumeConversation.tsx +0 -68
  156. package/src/services/adapters/base.ts +0 -38
  157. package/src/services/adapters/chatCompletions.ts +0 -90
  158. package/src/services/adapters/responsesAPI.ts +0 -170
  159. package/src/services/browserMocks.ts +0 -66
  160. package/src/services/claude.ts +0 -2197
  161. package/src/services/customCommands.ts +0 -704
  162. package/src/services/fileFreshness.ts +0 -377
  163. package/src/services/gpt5ConnectionTest.ts +0 -340
  164. package/src/services/mcpClient.ts +0 -564
  165. package/src/services/mcpServerApproval.tsx +0 -50
  166. package/src/services/mentionProcessor.ts +0 -273
  167. package/src/services/modelAdapterFactory.ts +0 -69
  168. package/src/services/notifier.ts +0 -40
  169. package/src/services/oauth.ts +0 -357
  170. package/src/services/openai.ts +0 -1359
  171. package/src/services/responseStateManager.ts +0 -90
  172. package/src/services/sentry.ts +0 -3
  173. package/src/services/statsig.ts +0 -172
  174. package/src/services/statsigStorage.ts +0 -86
  175. package/src/services/systemReminder.ts +0 -507
  176. package/src/services/vcr.ts +0 -161
  177. package/src/test/testAdapters.ts +0 -96
  178. package/src/tools/ArchitectTool/ArchitectTool.tsx +0 -135
  179. package/src/tools/ArchitectTool/prompt.ts +0 -15
  180. package/src/tools/AskExpertModelTool/AskExpertModelTool.tsx +0 -576
  181. package/src/tools/BashTool/BashTool.tsx +0 -243
  182. package/src/tools/BashTool/BashToolResultMessage.tsx +0 -38
  183. package/src/tools/BashTool/OutputLine.tsx +0 -49
  184. package/src/tools/BashTool/prompt.ts +0 -174
  185. package/src/tools/BashTool/utils.ts +0 -56
  186. package/src/tools/FileEditTool/FileEditTool.tsx +0 -319
  187. package/src/tools/FileEditTool/prompt.ts +0 -51
  188. package/src/tools/FileEditTool/utils.ts +0 -58
  189. package/src/tools/FileReadTool/FileReadTool.tsx +0 -404
  190. package/src/tools/FileReadTool/prompt.ts +0 -7
  191. package/src/tools/FileWriteTool/FileWriteTool.tsx +0 -301
  192. package/src/tools/FileWriteTool/prompt.ts +0 -10
  193. package/src/tools/GlobTool/GlobTool.tsx +0 -119
  194. package/src/tools/GlobTool/prompt.ts +0 -8
  195. package/src/tools/GrepTool/GrepTool.tsx +0 -147
  196. package/src/tools/GrepTool/prompt.ts +0 -11
  197. package/src/tools/MCPTool/MCPTool.tsx +0 -107
  198. package/src/tools/MCPTool/prompt.ts +0 -3
  199. package/src/tools/MemoryReadTool/MemoryReadTool.tsx +0 -127
  200. package/src/tools/MemoryReadTool/prompt.ts +0 -3
  201. package/src/tools/MemoryWriteTool/MemoryWriteTool.tsx +0 -89
  202. package/src/tools/MemoryWriteTool/prompt.ts +0 -3
  203. package/src/tools/MultiEditTool/MultiEditTool.tsx +0 -388
  204. package/src/tools/MultiEditTool/prompt.ts +0 -45
  205. package/src/tools/NotebookEditTool/NotebookEditTool.tsx +0 -298
  206. package/src/tools/NotebookEditTool/prompt.ts +0 -3
  207. package/src/tools/NotebookReadTool/NotebookReadTool.tsx +0 -258
  208. package/src/tools/NotebookReadTool/prompt.ts +0 -3
  209. package/src/tools/StickerRequestTool/StickerRequestTool.tsx +0 -107
  210. package/src/tools/StickerRequestTool/prompt.ts +0 -19
  211. package/src/tools/TaskTool/TaskTool.tsx +0 -438
  212. package/src/tools/TaskTool/constants.ts +0 -1
  213. package/src/tools/TaskTool/prompt.ts +0 -92
  214. package/src/tools/ThinkTool/ThinkTool.tsx +0 -54
  215. package/src/tools/ThinkTool/prompt.ts +0 -12
  216. package/src/tools/TodoWriteTool/TodoWriteTool.tsx +0 -313
  217. package/src/tools/TodoWriteTool/prompt.ts +0 -63
  218. package/src/tools/URLFetcherTool/URLFetcherTool.tsx +0 -178
  219. package/src/tools/URLFetcherTool/cache.ts +0 -55
  220. package/src/tools/URLFetcherTool/htmlToMarkdown.ts +0 -55
  221. package/src/tools/URLFetcherTool/prompt.ts +0 -17
  222. package/src/tools/WebSearchTool/WebSearchTool.tsx +0 -103
  223. package/src/tools/WebSearchTool/prompt.ts +0 -13
  224. package/src/tools/WebSearchTool/searchProviders.ts +0 -66
  225. package/src/tools/lsTool/lsTool.tsx +0 -272
  226. package/src/tools/lsTool/prompt.ts +0 -2
  227. package/src/tools.ts +0 -67
  228. package/src/types/PermissionMode.ts +0 -120
  229. package/src/types/RequestContext.ts +0 -72
  230. package/src/types/common.d.ts +0 -2
  231. package/src/types/conversation.ts +0 -51
  232. package/src/types/logs.ts +0 -58
  233. package/src/types/modelCapabilities.ts +0 -64
  234. package/src/types/notebook.ts +0 -87
  235. package/src/utils/Cursor.ts +0 -436
  236. package/src/utils/PersistentShell.ts +0 -552
  237. package/src/utils/advancedFuzzyMatcher.ts +0 -290
  238. package/src/utils/agentLoader.ts +0 -278
  239. package/src/utils/agentStorage.ts +0 -97
  240. package/src/utils/array.ts +0 -3
  241. package/src/utils/ask.tsx +0 -99
  242. package/src/utils/auth.ts +0 -13
  243. package/src/utils/autoCompactCore.ts +0 -223
  244. package/src/utils/autoUpdater.ts +0 -458
  245. package/src/utils/betas.ts +0 -20
  246. package/src/utils/browser.ts +0 -14
  247. package/src/utils/cleanup.ts +0 -72
  248. package/src/utils/commands.ts +0 -261
  249. package/src/utils/commonUnixCommands.ts +0 -161
  250. package/src/utils/config.ts +0 -945
  251. package/src/utils/conversationRecovery.ts +0 -55
  252. package/src/utils/debugLogger.ts +0 -1235
  253. package/src/utils/diff.ts +0 -42
  254. package/src/utils/env.ts +0 -57
  255. package/src/utils/errors.ts +0 -21
  256. package/src/utils/exampleCommands.ts +0 -109
  257. package/src/utils/execFileNoThrow.ts +0 -51
  258. package/src/utils/expertChatStorage.ts +0 -136
  259. package/src/utils/file.ts +0 -405
  260. package/src/utils/fileRecoveryCore.ts +0 -71
  261. package/src/utils/format.tsx +0 -44
  262. package/src/utils/fuzzyMatcher.ts +0 -328
  263. package/src/utils/generators.ts +0 -62
  264. package/src/utils/git.ts +0 -92
  265. package/src/utils/globalLogger.ts +0 -77
  266. package/src/utils/http.ts +0 -10
  267. package/src/utils/imagePaste.ts +0 -38
  268. package/src/utils/json.ts +0 -13
  269. package/src/utils/log.ts +0 -382
  270. package/src/utils/markdown.ts +0 -213
  271. package/src/utils/messageContextManager.ts +0 -294
  272. package/src/utils/messages.tsx +0 -945
  273. package/src/utils/model.ts +0 -914
  274. package/src/utils/permissions/filesystem.ts +0 -127
  275. package/src/utils/responseState.ts +0 -23
  276. package/src/utils/ripgrep.ts +0 -167
  277. package/src/utils/secureFile.ts +0 -564
  278. package/src/utils/sessionState.ts +0 -49
  279. package/src/utils/state.ts +0 -25
  280. package/src/utils/style.ts +0 -29
  281. package/src/utils/terminal.ts +0 -50
  282. package/src/utils/theme.ts +0 -127
  283. package/src/utils/thinking.ts +0 -144
  284. package/src/utils/todoStorage.ts +0 -431
  285. package/src/utils/tokens.ts +0 -43
  286. package/src/utils/toolExecutionController.ts +0 -163
  287. package/src/utils/unaryLogging.ts +0 -26
  288. package/src/utils/user.ts +0 -37
  289. package/src/utils/validate.ts +0 -165
@@ -1,39 +0,0 @@
1
- import * as React from 'react'
2
- import { captureException } from '../services/sentry'
3
-
4
- interface Props {
5
- children: React.ReactNode
6
- }
7
-
8
- interface State {
9
- hasError: boolean
10
- }
11
-
12
- export class SentryErrorBoundary extends React.Component<Props, State> {
13
- constructor(props: Props) {
14
- super(props)
15
- ;(this as any).state = { hasError: false }
16
- }
17
-
18
- static getDerivedStateFromError(): State {
19
- return { hasError: true }
20
- }
21
-
22
- componentDidCatch(error: Error): void {
23
- // Don't report user-initiated cancellations to Sentry
24
- if (error.name === 'AbortError' ||
25
- error.message?.includes('abort') ||
26
- error.message?.includes('The operation was aborted')) {
27
- return
28
- }
29
- captureException(error)
30
- }
31
-
32
- render(): React.ReactNode {
33
- if ((this as any).state.hasError) {
34
- return null
35
- }
36
-
37
- return (this as any).props.children
38
- }
39
- }
@@ -1,129 +0,0 @@
1
- import { Box, Text } from 'ink'
2
- import * as React from 'react'
3
- import { useEffect, useRef, useState } from 'react'
4
- import { getTheme } from '../utils/theme'
5
- import { sample } from 'lodash-es'
6
- import { getSessionState } from '../utils/sessionState'
7
- // NB: The third character in this string is an emoji that
8
- // renders on Windows consoles with a green background
9
- const CHARACTERS =
10
- process.platform === 'darwin'
11
- ? ['Β·', '✒', '✳', 'βˆ—', '✻', '✽']
12
- : ['Β·', '✒', '*', 'βˆ—', '✻', '✽']
13
-
14
- const MESSAGES = [
15
- 'Accomplishing',
16
- 'Actioning',
17
- 'Actualizing',
18
- 'Baking',
19
- 'Brewing',
20
- 'Calculating',
21
- 'Cerebrating',
22
- 'Churning',
23
- 'Coding',
24
- 'Coalescing',
25
- 'Cogitating',
26
- 'Computing',
27
- 'Conjuring',
28
- 'Considering',
29
- 'Cooking',
30
- 'Crafting',
31
- 'Creating',
32
- 'Crunching',
33
- 'Deliberating',
34
- 'Determining',
35
- 'Doing',
36
- 'Effecting',
37
- 'Finagling',
38
- 'Forging',
39
- 'Forming',
40
- 'Generating',
41
- 'Hatching',
42
- 'Herding',
43
- 'Honking',
44
- 'Hustling',
45
- 'Ideating',
46
- 'Inferring',
47
- 'Manifesting',
48
- 'Marinating',
49
- 'Moseying',
50
- 'Mulling',
51
- 'Mustering',
52
- 'Musing',
53
- 'Noodling',
54
- 'Percolating',
55
- 'Pondering',
56
- 'Processing',
57
- 'Puttering',
58
- 'Reticulating',
59
- 'Ruminating',
60
- 'Schlepping',
61
- 'Shucking',
62
- 'Simmering',
63
- 'Smooshing',
64
- 'Spinning',
65
- 'Stewing',
66
- 'Synthesizing',
67
- 'Thinking',
68
- 'Transmuting',
69
- 'Vibing',
70
- 'Working',
71
- ]
72
-
73
- export function Spinner(): React.ReactNode {
74
- const frames = [...CHARACTERS, ...[...CHARACTERS].reverse()]
75
- const [frame, setFrame] = useState(0)
76
- const [elapsedTime, setElapsedTime] = useState(0)
77
- const message = useRef(sample(MESSAGES))
78
- const startTime = useRef(Date.now())
79
-
80
- useEffect(() => {
81
- const timer = setInterval(() => {
82
- setFrame(f => (f + 1) % frames.length)
83
- }, 120)
84
-
85
- return () => clearInterval(timer)
86
- }, [frames.length])
87
-
88
- useEffect(() => {
89
- const timer = setInterval(() => {
90
- setElapsedTime(Math.floor((Date.now() - startTime.current) / 1000))
91
- }, 1000)
92
-
93
- return () => clearInterval(timer)
94
- }, [])
95
-
96
- return (
97
- <Box flexDirection="row" marginTop={1}>
98
- <Box flexWrap="nowrap" height={1} width={2}>
99
- <Text color={getTheme().kode}>{frames[frame]}</Text>
100
- </Box>
101
- <Text color={getTheme().kode}>{message.current}… </Text>
102
- <Text color={getTheme().secondaryText}>
103
- ({elapsedTime}s Β· <Text bold>esc</Text> to interrupt)
104
- </Text>
105
- <Text color={getTheme().secondaryText}>
106
- Β· {getSessionState('currentError')}
107
- </Text>
108
- </Box>
109
- )
110
- }
111
-
112
- export function SimpleSpinner(): React.ReactNode {
113
- const frames = [...CHARACTERS, ...[...CHARACTERS].reverse()]
114
- const [frame, setFrame] = useState(0)
115
-
116
- useEffect(() => {
117
- const timer = setInterval(() => {
118
- setFrame(f => (f + 1) % frames.length)
119
- }, 120)
120
-
121
- return () => clearInterval(timer)
122
- }, [frames.length])
123
-
124
- return (
125
- <Box flexWrap="nowrap" height={1} width={2}>
126
- <Text color={getTheme().kode}>{frames[frame]}</Text>
127
- </Box>
128
- )
129
- }
@@ -1,16 +0,0 @@
1
- import React from 'react'
2
-
3
- export interface FormData {
4
- // Define form data structure as needed
5
- [key: string]: any
6
- }
7
-
8
- export interface StickerRequestFormProps {
9
- // Define props as needed
10
- onSubmit?: (data: FormData) => void
11
- }
12
-
13
- export const StickerRequestForm: React.FC<StickerRequestFormProps> = () => {
14
- // Minimal component implementation
15
- return null
16
- }
@@ -1,191 +0,0 @@
1
- import { Box, Text } from 'ink'
2
- import * as React from 'react'
3
- import { Hunk } from 'diff'
4
- import { getTheme, ThemeNames } from '../utils/theme'
5
- import { useMemo } from 'react'
6
- import { wrapText } from '../utils/format'
7
-
8
- type Props = {
9
- patch: Hunk
10
- dim: boolean
11
- width: number
12
- overrideTheme?: ThemeNames // custom theme for previews
13
- key?: React.Key
14
- }
15
-
16
- export function StructuredDiff({
17
- patch,
18
- dim,
19
- width,
20
- overrideTheme,
21
- }: Props): React.ReactNode {
22
- const diff = useMemo(
23
- () => formatDiff(patch.lines, patch.oldStart, width, dim, overrideTheme),
24
- [patch.lines, patch.oldStart, width, dim, overrideTheme],
25
- )
26
-
27
- return diff.map((_, i) => <Box key={i}>{_}</Box>)
28
- }
29
-
30
- function formatDiff(
31
- lines: string[],
32
- startingLineNumber: number,
33
- width: number,
34
- dim: boolean,
35
- overrideTheme?: ThemeNames,
36
- ): React.ReactNode[] {
37
- const theme = getTheme(overrideTheme)
38
-
39
- const ls = numberDiffLines(
40
- lines.map(code => {
41
- if (code.startsWith('+')) {
42
- return {
43
- code: ' ' + code.slice(1),
44
- i: 0,
45
- type: 'add',
46
- }
47
- }
48
- if (code.startsWith('-')) {
49
- return {
50
- code: ' ' + code.slice(1),
51
- i: 0,
52
- type: 'remove',
53
- }
54
- }
55
- return { code, i: 0, type: 'nochange' }
56
- }),
57
- startingLineNumber,
58
- )
59
-
60
- const maxLineNumber = Math.max(...ls.map(({ i }) => i))
61
- const maxWidth = maxLineNumber.toString().length
62
-
63
- return ls.flatMap(({ type, code, i }) => {
64
- const wrappedLines = wrapText(code, width - maxWidth)
65
- return wrappedLines.map((line, lineIndex) => {
66
- const key = `${type}-${i}-${lineIndex}`
67
- switch (type) {
68
- case 'add':
69
- return (
70
- <React.Fragment key={key}>
71
- <Text>
72
- <LineNumber
73
- i={lineIndex === 0 ? i : undefined}
74
- width={maxWidth}
75
- />
76
- <Text
77
- color={overrideTheme ? theme.text : undefined}
78
- backgroundColor={
79
- dim ? theme.diff.addedDimmed : theme.diff.added
80
- }
81
- dimColor={dim}
82
- >
83
- {line}
84
- </Text>
85
- </Text>
86
- </React.Fragment>
87
- )
88
- case 'remove':
89
- return (
90
- <React.Fragment key={key}>
91
- <Text>
92
- <LineNumber
93
- i={lineIndex === 0 ? i : undefined}
94
- width={maxWidth}
95
- />
96
- <Text
97
- color={overrideTheme ? theme.text : undefined}
98
- backgroundColor={
99
- dim ? theme.diff.removedDimmed : theme.diff.removed
100
- }
101
- dimColor={dim}
102
- >
103
- {line}
104
- </Text>
105
- </Text>
106
- </React.Fragment>
107
- )
108
- case 'nochange':
109
- return (
110
- <React.Fragment key={key}>
111
- <Text>
112
- <LineNumber
113
- i={lineIndex === 0 ? i : undefined}
114
- width={maxWidth}
115
- />
116
- <Text
117
- color={overrideTheme ? theme.text : undefined}
118
- dimColor={dim}
119
- >
120
- {line}
121
- </Text>
122
- </Text>
123
- </React.Fragment>
124
- )
125
- }
126
- })
127
- })
128
- }
129
-
130
- function LineNumber({
131
- i,
132
- width,
133
- }: {
134
- i: number | undefined
135
- width: number
136
- }): React.ReactNode {
137
- return (
138
- <Text color={getTheme().secondaryText}>
139
- {i !== undefined ? i.toString().padStart(width) : ' '.repeat(width)}{' '}
140
- </Text>
141
- )
142
- }
143
-
144
- function numberDiffLines(
145
- diff: { code: string; type: string }[],
146
- startLine: number,
147
- ): { code: string; type: string; i: number }[] {
148
- let i = startLine
149
- const result: { code: string; type: string; i: number }[] = []
150
- const queue = [...diff]
151
-
152
- while (queue.length > 0) {
153
- const { code, type } = queue.shift()!
154
- const line = {
155
- code: code,
156
- type,
157
- i,
158
- }
159
-
160
- // Update counters based on change type
161
- switch (type) {
162
- case 'nochange':
163
- i++
164
- result.push(line)
165
- break
166
- case 'add':
167
- i++
168
- result.push(line)
169
- break
170
- case 'remove': {
171
- result.push(line)
172
- let numRemoved = 0
173
- while (queue[0]?.type === 'remove') {
174
- i++
175
- const { code, type } = queue.shift()!
176
- const line = {
177
- code: code,
178
- type,
179
- i,
180
- }
181
- result.push(line)
182
- numRemoved++
183
- }
184
- i -= numRemoved
185
- break
186
- }
187
- }
188
- }
189
-
190
- return result
191
- }
@@ -1,259 +0,0 @@
1
- import React from 'react'
2
- import { Text, useInput } from 'ink'
3
- import chalk from 'chalk'
4
- import { useTextInput } from '../hooks/useTextInput'
5
- import { getTheme } from '../utils/theme'
6
- import { type Key } from 'ink'
7
-
8
- export type Props = {
9
- /**
10
- * Optional callback for handling history navigation on up arrow at start of input
11
- */
12
- readonly onHistoryUp?: () => void
13
-
14
- /**
15
- * Optional callback for handling history navigation on down arrow at end of input
16
- */
17
- readonly onHistoryDown?: () => void
18
-
19
- /**
20
- * Text to display when `value` is empty.
21
- */
22
- readonly placeholder?: string
23
-
24
- /**
25
- * Allow multi-line input via line ending with backslash (default: `true`)
26
- */
27
- readonly multiline?: boolean
28
-
29
- /**
30
- * Listen to user's input. Useful in case there are multiple input components
31
- * at the same time and input must be "routed" to a specific component.
32
- */
33
- readonly focus?: boolean
34
-
35
- /**
36
- * Replace all chars and mask the value. Useful for password inputs.
37
- */
38
- readonly mask?: string
39
-
40
- /**
41
- * Whether to show cursor and allow navigation inside text input with arrow keys.
42
- */
43
- readonly showCursor?: boolean
44
-
45
- /**
46
- * Highlight pasted text
47
- */
48
- readonly highlightPastedText?: boolean
49
-
50
- /**
51
- * Value to display in a text input.
52
- */
53
- readonly value: string
54
-
55
- /**
56
- * Function to call when value updates.
57
- */
58
- readonly onChange: (value: string) => void
59
-
60
- /**
61
- * Function to call when `Enter` is pressed, where first argument is a value of the input.
62
- */
63
- readonly onSubmit?: (value: string) => void
64
-
65
- /**
66
- * Function to call when Ctrl+C is pressed to exit.
67
- */
68
- readonly onExit?: () => void
69
-
70
- /**
71
- * Optional callback to show exit message
72
- */
73
- readonly onExitMessage?: (show: boolean, key?: string) => void
74
-
75
- /**
76
- * Optional callback to show custom message
77
- */
78
- readonly onMessage?: (show: boolean, message?: string) => void
79
-
80
- /**
81
- * Optional callback to reset history position
82
- */
83
- readonly onHistoryReset?: () => void
84
-
85
- /**
86
- * Number of columns to wrap text at
87
- */
88
- readonly columns: number
89
-
90
- /**
91
- * Optional callback when an image is pasted
92
- */
93
- readonly onImagePaste?: (base64Image: string) => void
94
-
95
- /**
96
- * Optional callback when a large text (over 800 chars) is pasted
97
- */
98
- readonly onPaste?: (text: string) => void
99
-
100
- /**
101
- * Whether the input is dimmed and non-interactive
102
- */
103
- readonly isDimmed?: boolean
104
-
105
- /**
106
- * Whether to disable cursor movement for up/down arrow keys
107
- */
108
- readonly disableCursorMovementForUpDownKeys?: boolean
109
-
110
- /**
111
- * Optional callback to handle special key combinations before input processing
112
- * Return true to prevent default handling
113
- */
114
- readonly onSpecialKey?: (input: string, key: Key) => boolean
115
-
116
- readonly cursorOffset: number
117
-
118
- /**
119
- * Callback to set the offset of the cursor
120
- */
121
- onChangeCursorOffset: (offset: number) => void
122
- }
123
-
124
- export default function TextInput({
125
- value: originalValue,
126
- placeholder = '',
127
- focus = true,
128
- mask,
129
- multiline = false,
130
- highlightPastedText = false,
131
- showCursor = true,
132
- onChange,
133
- onSubmit,
134
- onExit,
135
- onHistoryUp,
136
- onHistoryDown,
137
- onExitMessage,
138
- onMessage,
139
- onHistoryReset,
140
- columns,
141
- onImagePaste,
142
- onPaste,
143
- isDimmed = false,
144
- disableCursorMovementForUpDownKeys = false,
145
- onSpecialKey,
146
- cursorOffset,
147
- onChangeCursorOffset,
148
- }: Props) {
149
- const { onInput, renderedValue } = useTextInput({
150
- value: originalValue,
151
- onChange,
152
- onSubmit,
153
- onExit,
154
- onExitMessage,
155
- onMessage,
156
- onHistoryReset,
157
- onHistoryUp,
158
- onHistoryDown,
159
- focus,
160
- mask,
161
- multiline,
162
- cursorChar: showCursor ? ' ' : '',
163
- highlightPastedText,
164
- invert: chalk.inverse,
165
- themeText: (text: string) => chalk.hex(getTheme().text)(text),
166
- columns,
167
- onImagePaste,
168
- disableCursorMovementForUpDownKeys,
169
- externalOffset: cursorOffset,
170
- onOffsetChange: onChangeCursorOffset,
171
- })
172
-
173
- // Paste detection state
174
- const [pasteState, setPasteState] = React.useState<{
175
- chunks: string[]
176
- timeoutId: ReturnType<typeof setTimeout> | null
177
- }>({ chunks: [], timeoutId: null })
178
-
179
- const resetPasteTimeout = (
180
- currentTimeoutId: ReturnType<typeof setTimeout> | null,
181
- ) => {
182
- if (currentTimeoutId) {
183
- clearTimeout(currentTimeoutId)
184
- }
185
- return setTimeout(() => {
186
- setPasteState(({ chunks }) => {
187
- const pastedText = chunks.join('')
188
- // Schedule callback after current render to avoid state updates during render
189
- Promise.resolve().then(() => onPaste!(pastedText))
190
- return { chunks: [], timeoutId: null }
191
- })
192
- }, 100)
193
- }
194
-
195
- const wrappedOnInput = (input: string, key: Key): void => {
196
- // Check for special key combinations first
197
- if (onSpecialKey && onSpecialKey(input, key)) {
198
- // Special key was handled, don't process further
199
- return
200
- }
201
-
202
- // Special handling for backspace or delete
203
- if (
204
- key.backspace ||
205
- key.delete ||
206
- input === '\b' ||
207
- input === '\x7f' ||
208
- input === '\x08'
209
- ) {
210
- // Ensure backspace is handled directly
211
- onInput(input, {
212
- ...key,
213
- backspace: true,
214
- })
215
- return
216
- }
217
-
218
- // Handle pastes (>800 chars)
219
- // Usually we get one or two input characters at a time. If we
220
- // get a bunch, the user has probably pasted.
221
- // Unfortunately node batches long pastes, so it's possible
222
- // that we would see e.g. 1024 characters and then just a few
223
- // more in the next frame that belong with the original paste.
224
- // This batching number is not consistent.
225
- if (onPaste && (input.length > 800 || pasteState.timeoutId)) {
226
- setPasteState(({ chunks, timeoutId }) => {
227
- return {
228
- chunks: [...chunks, input],
229
- timeoutId: resetPasteTimeout(timeoutId),
230
- }
231
- })
232
- return
233
- }
234
-
235
- onInput(input, key)
236
- }
237
-
238
- useInput(wrappedOnInput, { isActive: focus })
239
-
240
- let renderedPlaceholder = placeholder
241
- ? chalk.hex(getTheme().secondaryText)(placeholder)
242
- : undefined
243
-
244
- // Fake mouse cursor, because we like punishment
245
- if (showCursor && focus) {
246
- renderedPlaceholder =
247
- placeholder.length > 0
248
- ? chalk.inverse(placeholder[0]) +
249
- chalk.hex(getTheme().secondaryText)(placeholder.slice(1))
250
- : chalk.inverse(' ')
251
- }
252
-
253
- const showPlaceholder = originalValue.length == 0 && placeholder
254
- return (
255
- <Text wrap="truncate-end" dimColor={isDimmed}>
256
- {showPlaceholder ? renderedPlaceholder : renderedValue}
257
- </Text>
258
- )
259
- }
@@ -1,47 +0,0 @@
1
- import React from 'react'
2
- import { Box, Text } from 'ink'
3
- import type { TodoItem as TodoItemType } from '../utils/todoStorage'
4
-
5
- export interface TodoItemProps {
6
- todo: TodoItemType
7
- children?: React.ReactNode
8
- }
9
-
10
- export const TodoItem: React.FC<TodoItemProps> = ({ todo, children }) => {
11
- const statusIconMap = {
12
- completed: 'βœ…',
13
- in_progress: 'πŸ”„',
14
- pending: '⏸️',
15
- }
16
-
17
- const statusColorMap = {
18
- completed: '#008000',
19
- in_progress: '#FFA500',
20
- pending: '#FFD700',
21
- }
22
-
23
- const priorityIconMap = {
24
- high: 'πŸ”΄',
25
- medium: '🟑',
26
- low: '🟒',
27
- }
28
-
29
- const icon = statusIconMap[todo.status]
30
- const color = statusColorMap[todo.status]
31
- const priorityIcon = todo.priority ? priorityIconMap[todo.priority] : ''
32
-
33
- return (
34
- <Box flexDirection="row" gap={1}>
35
- <Text color={color}>{icon}</Text>
36
- {priorityIcon && <Text>{priorityIcon}</Text>}
37
- <Text
38
- color={color}
39
- strikethrough={todo.status === 'completed'}
40
- bold={todo.status === 'in_progress'}
41
- >
42
- {todo.content}
43
- </Text>
44
- {children}
45
- </Box>
46
- )
47
- }
@@ -1,31 +0,0 @@
1
- import { Box, Text } from 'ink'
2
- import * as React from 'react'
3
- import { getTheme } from '../utils/theme'
4
-
5
- type Props = {
6
- tokenUsage: number
7
- }
8
-
9
- const MAX_TOKENS = 190_000
10
- export const WARNING_THRESHOLD = MAX_TOKENS * 0.6
11
- const ERROR_THRESHOLD = MAX_TOKENS * 0.8
12
-
13
- export function TokenWarning({ tokenUsage }: Props): React.ReactNode {
14
- const theme = getTheme()
15
-
16
- if (tokenUsage < WARNING_THRESHOLD) {
17
- return null
18
- }
19
-
20
- const isError = tokenUsage >= ERROR_THRESHOLD
21
-
22
- return (
23
- <Box flexDirection="row">
24
- <Text color={isError ? theme.error : theme.warning}>
25
- Context low (
26
- {Math.max(0, 100 - Math.round((tokenUsage / MAX_TOKENS) * 100))}%
27
- remaining) &middot; Run /compact to compact & continue
28
- </Text>
29
- </Box>
30
- )
31
- }