@shareai-lab/kode 1.0.70 → 1.0.71

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 (253) hide show
  1. package/README.md +202 -76
  2. package/README.zh-CN.md +246 -0
  3. package/cli.js +62 -0
  4. package/package.json +45 -25
  5. package/scripts/postinstall.js +56 -0
  6. package/src/ProjectOnboarding.tsx +180 -0
  7. package/src/Tool.ts +53 -0
  8. package/src/commands/approvedTools.ts +53 -0
  9. package/src/commands/bug.tsx +20 -0
  10. package/src/commands/clear.ts +43 -0
  11. package/src/commands/compact.ts +120 -0
  12. package/src/commands/config.tsx +19 -0
  13. package/src/commands/cost.ts +18 -0
  14. package/src/commands/ctx_viz.ts +209 -0
  15. package/src/commands/doctor.ts +24 -0
  16. package/src/commands/help.tsx +19 -0
  17. package/src/commands/init.ts +37 -0
  18. package/src/commands/listen.ts +42 -0
  19. package/src/commands/login.tsx +51 -0
  20. package/src/commands/logout.tsx +40 -0
  21. package/src/commands/mcp.ts +41 -0
  22. package/src/commands/model.tsx +40 -0
  23. package/src/commands/modelstatus.tsx +20 -0
  24. package/src/commands/onboarding.tsx +34 -0
  25. package/src/commands/pr_comments.ts +59 -0
  26. package/src/commands/refreshCommands.ts +54 -0
  27. package/src/commands/release-notes.ts +34 -0
  28. package/src/commands/resume.tsx +30 -0
  29. package/src/commands/review.ts +49 -0
  30. package/src/commands/terminalSetup.ts +221 -0
  31. package/src/commands.ts +136 -0
  32. package/src/components/ApproveApiKey.tsx +93 -0
  33. package/src/components/AsciiLogo.tsx +13 -0
  34. package/src/components/AutoUpdater.tsx +148 -0
  35. package/src/components/Bug.tsx +367 -0
  36. package/src/components/Config.tsx +289 -0
  37. package/src/components/ConsoleOAuthFlow.tsx +326 -0
  38. package/src/components/Cost.tsx +23 -0
  39. package/src/components/CostThresholdDialog.tsx +46 -0
  40. package/src/components/CustomSelect/option-map.ts +42 -0
  41. package/src/components/CustomSelect/select-option.tsx +52 -0
  42. package/src/components/CustomSelect/select.tsx +143 -0
  43. package/src/components/CustomSelect/use-select-state.ts +414 -0
  44. package/src/components/CustomSelect/use-select.ts +35 -0
  45. package/src/components/FallbackToolUseRejectedMessage.tsx +15 -0
  46. package/src/components/FileEditToolUpdatedMessage.tsx +66 -0
  47. package/src/components/Help.tsx +215 -0
  48. package/src/components/HighlightedCode.tsx +33 -0
  49. package/src/components/InvalidConfigDialog.tsx +113 -0
  50. package/src/components/Link.tsx +32 -0
  51. package/src/components/LogSelector.tsx +86 -0
  52. package/src/components/Logo.tsx +145 -0
  53. package/src/components/MCPServerApprovalDialog.tsx +100 -0
  54. package/src/components/MCPServerDialogCopy.tsx +25 -0
  55. package/src/components/MCPServerMultiselectDialog.tsx +109 -0
  56. package/src/components/Message.tsx +219 -0
  57. package/src/components/MessageResponse.tsx +15 -0
  58. package/src/components/MessageSelector.tsx +211 -0
  59. package/src/components/ModeIndicator.tsx +88 -0
  60. package/src/components/ModelConfig.tsx +301 -0
  61. package/src/components/ModelListManager.tsx +223 -0
  62. package/src/components/ModelSelector.tsx +3208 -0
  63. package/src/components/ModelStatusDisplay.tsx +228 -0
  64. package/src/components/Onboarding.tsx +274 -0
  65. package/src/components/PressEnterToContinue.tsx +11 -0
  66. package/src/components/PromptInput.tsx +710 -0
  67. package/src/components/SentryErrorBoundary.ts +33 -0
  68. package/src/components/Spinner.tsx +129 -0
  69. package/src/components/StructuredDiff.tsx +184 -0
  70. package/src/components/TextInput.tsx +246 -0
  71. package/src/components/TokenWarning.tsx +31 -0
  72. package/src/components/ToolUseLoader.tsx +40 -0
  73. package/src/components/TrustDialog.tsx +106 -0
  74. package/src/components/binary-feedback/BinaryFeedback.tsx +63 -0
  75. package/src/components/binary-feedback/BinaryFeedbackOption.tsx +111 -0
  76. package/src/components/binary-feedback/BinaryFeedbackView.tsx +172 -0
  77. package/src/components/binary-feedback/utils.ts +220 -0
  78. package/src/components/messages/AssistantBashOutputMessage.tsx +22 -0
  79. package/src/components/messages/AssistantLocalCommandOutputMessage.tsx +45 -0
  80. package/src/components/messages/AssistantRedactedThinkingMessage.tsx +19 -0
  81. package/src/components/messages/AssistantTextMessage.tsx +144 -0
  82. package/src/components/messages/AssistantThinkingMessage.tsx +40 -0
  83. package/src/components/messages/AssistantToolUseMessage.tsx +123 -0
  84. package/src/components/messages/UserBashInputMessage.tsx +28 -0
  85. package/src/components/messages/UserCommandMessage.tsx +30 -0
  86. package/src/components/messages/UserKodingInputMessage.tsx +28 -0
  87. package/src/components/messages/UserPromptMessage.tsx +35 -0
  88. package/src/components/messages/UserTextMessage.tsx +39 -0
  89. package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.tsx +12 -0
  90. package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.tsx +36 -0
  91. package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.tsx +31 -0
  92. package/src/components/messages/UserToolResultMessage/UserToolResultMessage.tsx +57 -0
  93. package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.tsx +35 -0
  94. package/src/components/messages/UserToolResultMessage/utils.tsx +56 -0
  95. package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.tsx +121 -0
  96. package/src/components/permissions/FallbackPermissionRequest.tsx +155 -0
  97. package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +182 -0
  98. package/src/components/permissions/FileEditPermissionRequest/FileEditToolDiff.tsx +75 -0
  99. package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +164 -0
  100. package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +81 -0
  101. package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +242 -0
  102. package/src/components/permissions/PermissionRequest.tsx +103 -0
  103. package/src/components/permissions/PermissionRequestTitle.tsx +69 -0
  104. package/src/components/permissions/hooks.ts +44 -0
  105. package/src/components/permissions/toolUseOptions.ts +59 -0
  106. package/src/components/permissions/utils.ts +23 -0
  107. package/src/constants/betas.ts +5 -0
  108. package/src/constants/claude-asterisk-ascii-art.tsx +238 -0
  109. package/src/constants/figures.ts +4 -0
  110. package/src/constants/keys.ts +3 -0
  111. package/src/constants/macros.ts +6 -0
  112. package/src/constants/models.ts +935 -0
  113. package/src/constants/oauth.ts +18 -0
  114. package/src/constants/product.ts +17 -0
  115. package/src/constants/prompts.ts +177 -0
  116. package/src/constants/releaseNotes.ts +7 -0
  117. package/src/context/PermissionContext.tsx +149 -0
  118. package/src/context.ts +278 -0
  119. package/src/cost-tracker.ts +84 -0
  120. package/src/entrypoints/cli.tsx +1498 -0
  121. package/src/entrypoints/mcp.ts +176 -0
  122. package/src/history.ts +25 -0
  123. package/src/hooks/useApiKeyVerification.ts +59 -0
  124. package/src/hooks/useArrowKeyHistory.ts +55 -0
  125. package/src/hooks/useCanUseTool.ts +138 -0
  126. package/src/hooks/useCancelRequest.ts +39 -0
  127. package/src/hooks/useDoublePress.ts +42 -0
  128. package/src/hooks/useExitOnCtrlCD.ts +31 -0
  129. package/src/hooks/useInterval.ts +25 -0
  130. package/src/hooks/useLogMessages.ts +16 -0
  131. package/src/hooks/useLogStartupTime.ts +12 -0
  132. package/src/hooks/useNotifyAfterTimeout.ts +65 -0
  133. package/src/hooks/usePermissionRequestLogging.ts +44 -0
  134. package/src/hooks/useSlashCommandTypeahead.ts +137 -0
  135. package/src/hooks/useTerminalSize.ts +49 -0
  136. package/src/hooks/useTextInput.ts +315 -0
  137. package/src/messages.ts +37 -0
  138. package/src/permissions.ts +268 -0
  139. package/src/query.ts +704 -0
  140. package/src/screens/ConfigureNpmPrefix.tsx +197 -0
  141. package/src/screens/Doctor.tsx +219 -0
  142. package/src/screens/LogList.tsx +68 -0
  143. package/src/screens/REPL.tsx +792 -0
  144. package/src/screens/ResumeConversation.tsx +68 -0
  145. package/src/services/browserMocks.ts +66 -0
  146. package/src/services/claude.ts +1947 -0
  147. package/src/services/customCommands.ts +683 -0
  148. package/src/services/fileFreshness.ts +377 -0
  149. package/src/services/mcpClient.ts +564 -0
  150. package/src/services/mcpServerApproval.tsx +50 -0
  151. package/src/services/notifier.ts +40 -0
  152. package/src/services/oauth.ts +357 -0
  153. package/src/services/openai.ts +796 -0
  154. package/src/services/sentry.ts +3 -0
  155. package/src/services/statsig.ts +171 -0
  156. package/src/services/statsigStorage.ts +86 -0
  157. package/src/services/systemReminder.ts +406 -0
  158. package/src/services/vcr.ts +161 -0
  159. package/src/tools/ArchitectTool/ArchitectTool.tsx +122 -0
  160. package/src/tools/ArchitectTool/prompt.ts +15 -0
  161. package/src/tools/AskExpertModelTool/AskExpertModelTool.tsx +505 -0
  162. package/src/tools/BashTool/BashTool.tsx +270 -0
  163. package/src/tools/BashTool/BashToolResultMessage.tsx +38 -0
  164. package/src/tools/BashTool/OutputLine.tsx +48 -0
  165. package/src/tools/BashTool/prompt.ts +174 -0
  166. package/src/tools/BashTool/utils.ts +56 -0
  167. package/src/tools/FileEditTool/FileEditTool.tsx +316 -0
  168. package/src/tools/FileEditTool/prompt.ts +51 -0
  169. package/src/tools/FileEditTool/utils.ts +58 -0
  170. package/src/tools/FileReadTool/FileReadTool.tsx +371 -0
  171. package/src/tools/FileReadTool/prompt.ts +7 -0
  172. package/src/tools/FileWriteTool/FileWriteTool.tsx +297 -0
  173. package/src/tools/FileWriteTool/prompt.ts +10 -0
  174. package/src/tools/GlobTool/GlobTool.tsx +119 -0
  175. package/src/tools/GlobTool/prompt.ts +8 -0
  176. package/src/tools/GrepTool/GrepTool.tsx +147 -0
  177. package/src/tools/GrepTool/prompt.ts +11 -0
  178. package/src/tools/MCPTool/MCPTool.tsx +106 -0
  179. package/src/tools/MCPTool/prompt.ts +3 -0
  180. package/src/tools/MemoryReadTool/MemoryReadTool.tsx +127 -0
  181. package/src/tools/MemoryReadTool/prompt.ts +3 -0
  182. package/src/tools/MemoryWriteTool/MemoryWriteTool.tsx +89 -0
  183. package/src/tools/MemoryWriteTool/prompt.ts +3 -0
  184. package/src/tools/MultiEditTool/MultiEditTool.tsx +366 -0
  185. package/src/tools/MultiEditTool/prompt.ts +45 -0
  186. package/src/tools/NotebookEditTool/NotebookEditTool.tsx +298 -0
  187. package/src/tools/NotebookEditTool/prompt.ts +3 -0
  188. package/src/tools/NotebookReadTool/NotebookReadTool.tsx +266 -0
  189. package/src/tools/NotebookReadTool/prompt.ts +3 -0
  190. package/src/tools/StickerRequestTool/StickerRequestTool.tsx +93 -0
  191. package/src/tools/StickerRequestTool/prompt.ts +19 -0
  192. package/src/tools/TaskTool/TaskTool.tsx +382 -0
  193. package/src/tools/TaskTool/constants.ts +1 -0
  194. package/src/tools/TaskTool/prompt.ts +56 -0
  195. package/src/tools/ThinkTool/ThinkTool.tsx +56 -0
  196. package/src/tools/ThinkTool/prompt.ts +12 -0
  197. package/src/tools/TodoWriteTool/TodoWriteTool.tsx +289 -0
  198. package/src/tools/TodoWriteTool/prompt.ts +63 -0
  199. package/src/tools/lsTool/lsTool.tsx +269 -0
  200. package/src/tools/lsTool/prompt.ts +2 -0
  201. package/src/tools.ts +63 -0
  202. package/src/types/PermissionMode.ts +120 -0
  203. package/src/types/RequestContext.ts +72 -0
  204. package/src/utils/Cursor.ts +436 -0
  205. package/src/utils/PersistentShell.ts +373 -0
  206. package/src/utils/agentStorage.ts +97 -0
  207. package/src/utils/array.ts +3 -0
  208. package/src/utils/ask.tsx +98 -0
  209. package/src/utils/auth.ts +13 -0
  210. package/src/utils/autoCompactCore.ts +223 -0
  211. package/src/utils/autoUpdater.ts +318 -0
  212. package/src/utils/betas.ts +20 -0
  213. package/src/utils/browser.ts +14 -0
  214. package/src/utils/cleanup.ts +72 -0
  215. package/src/utils/commands.ts +261 -0
  216. package/src/utils/config.ts +771 -0
  217. package/src/utils/conversationRecovery.ts +54 -0
  218. package/src/utils/debugLogger.ts +1123 -0
  219. package/src/utils/diff.ts +42 -0
  220. package/src/utils/env.ts +57 -0
  221. package/src/utils/errors.ts +21 -0
  222. package/src/utils/exampleCommands.ts +108 -0
  223. package/src/utils/execFileNoThrow.ts +51 -0
  224. package/src/utils/expertChatStorage.ts +136 -0
  225. package/src/utils/file.ts +402 -0
  226. package/src/utils/fileRecoveryCore.ts +71 -0
  227. package/src/utils/format.tsx +44 -0
  228. package/src/utils/generators.ts +62 -0
  229. package/src/utils/git.ts +92 -0
  230. package/src/utils/globalLogger.ts +77 -0
  231. package/src/utils/http.ts +10 -0
  232. package/src/utils/imagePaste.ts +38 -0
  233. package/src/utils/json.ts +13 -0
  234. package/src/utils/log.ts +382 -0
  235. package/src/utils/markdown.ts +213 -0
  236. package/src/utils/messageContextManager.ts +289 -0
  237. package/src/utils/messages.tsx +938 -0
  238. package/src/utils/model.ts +836 -0
  239. package/src/utils/permissions/filesystem.ts +118 -0
  240. package/src/utils/ripgrep.ts +167 -0
  241. package/src/utils/sessionState.ts +49 -0
  242. package/src/utils/state.ts +25 -0
  243. package/src/utils/style.ts +29 -0
  244. package/src/utils/terminal.ts +49 -0
  245. package/src/utils/theme.ts +122 -0
  246. package/src/utils/thinking.ts +144 -0
  247. package/src/utils/todoStorage.ts +431 -0
  248. package/src/utils/tokens.ts +43 -0
  249. package/src/utils/toolExecutionController.ts +163 -0
  250. package/src/utils/unaryLogging.ts +26 -0
  251. package/src/utils/user.ts +37 -0
  252. package/src/utils/validate.ts +165 -0
  253. package/cli.mjs +0 -1803
@@ -0,0 +1,3 @@
1
+ export const DESCRIPTION =
2
+ 'Replace the contents of a specific cell in a Jupyter notebook.'
3
+ export const PROMPT = `Completely replaces the contents of a specific cell in a Jupyter notebook (.ipynb file) with new source. Jupyter notebooks are interactive documents that combine code, text, and visualizations, commonly used for data analysis and scientific computing. The notebook_path parameter must be an absolute path, not a relative path. The cell_number is 0-indexed. Use edit_mode=insert to add a new cell at the index specified by cell_number. Use edit_mode=delete to delete the cell at the index specified by cell_number.`
@@ -0,0 +1,266 @@
1
+ import type {
2
+ ImageBlockParam,
3
+ TextBlockParam,
4
+ } from '@anthropic-ai/sdk/resources/index.mjs'
5
+
6
+ import { existsSync, readFileSync } from 'fs'
7
+ import { Text } from 'ink'
8
+ import { extname, isAbsolute, relative, resolve } from 'path'
9
+ import * as React from 'react'
10
+ import { z } from 'zod'
11
+ import { FallbackToolUseRejectedMessage } from '../../components/FallbackToolUseRejectedMessage'
12
+ import { Tool } from '../../Tool'
13
+ import {
14
+ NotebookCellSource,
15
+ NotebookContent,
16
+ NotebookCell,
17
+ NotebookOutputImage,
18
+ NotebookCellSourceOutput,
19
+ NotebookCellOutput,
20
+ NotebookCellType,
21
+ } from '../../types/notebook.js'
22
+ import { formatOutput } from '../BashTool/utils'
23
+ import { getCwd } from '../../utils/state'
24
+ import { findSimilarFile } from '../../utils/file'
25
+ import { DESCRIPTION, PROMPT } from './prompt'
26
+ import { hasReadPermission } from '../../utils/permissions/filesystem'
27
+
28
+ const inputSchema = z.strictObject({
29
+ notebook_path: z
30
+ .string()
31
+ .describe(
32
+ 'The absolute path to the Jupyter notebook file to read (must be absolute, not relative)',
33
+ ),
34
+ })
35
+
36
+ type In = typeof inputSchema
37
+ type Out = NotebookCellSource[]
38
+
39
+ function renderResultForAssistant(data: NotebookCellSource[]) {
40
+ const allResults = data.flatMap(getToolResultFromCell)
41
+
42
+ // Merge adjacent text blocks
43
+ return allResults.reduce<(TextBlockParam | ImageBlockParam)[]>(
44
+ (acc, curr) => {
45
+ if (acc.length === 0) return [curr]
46
+
47
+ const prev = acc[acc.length - 1]
48
+ if (prev && prev.type === 'text' && curr.type === 'text') {
49
+ // Merge the text blocks
50
+ prev.text += '\n' + curr.text
51
+ return acc
52
+ }
53
+
54
+ return [...acc, curr]
55
+ },
56
+ [],
57
+ )
58
+ }
59
+
60
+ export const NotebookReadTool = {
61
+ name: 'ReadNotebook',
62
+ async description() {
63
+ return DESCRIPTION
64
+ },
65
+ async prompt() {
66
+ return PROMPT
67
+ },
68
+ isReadOnly() {
69
+ return true
70
+ },
71
+ isConcurrencySafe() {
72
+ return true // NotebookReadTool is read-only, safe for concurrent execution
73
+ },
74
+ inputSchema,
75
+ userFacingName() {
76
+ return 'Read Notebook'
77
+ },
78
+ async isEnabled() {
79
+ return true
80
+ },
81
+ needsPermissions({ notebook_path }) {
82
+ return !hasReadPermission(notebook_path)
83
+ },
84
+ async validateInput({ notebook_path }) {
85
+ const fullFilePath = isAbsolute(notebook_path)
86
+ ? notebook_path
87
+ : resolve(getCwd(), notebook_path)
88
+
89
+ if (!existsSync(fullFilePath)) {
90
+ // Try to find a similar file with a different extension
91
+ const similarFilename = findSimilarFile(fullFilePath)
92
+ let message = 'File does not exist.'
93
+
94
+ // If we found a similar file, suggest it to the assistant
95
+ if (similarFilename) {
96
+ message += ` Did you mean ${similarFilename}?`
97
+ }
98
+
99
+ return {
100
+ result: false,
101
+ message,
102
+ }
103
+ }
104
+
105
+ if (extname(fullFilePath) !== '.ipynb') {
106
+ return {
107
+ result: false,
108
+ message: 'File must be a Jupyter notebook (.ipynb file).',
109
+ }
110
+ }
111
+
112
+ return { result: true }
113
+ },
114
+ renderToolUseMessage(input, { verbose }) {
115
+ return `notebook_path: ${verbose ? input.notebook_path : relative(getCwd(), input.notebook_path)}`
116
+ },
117
+ renderToolUseRejectedMessage() {
118
+ return <FallbackToolUseRejectedMessage />
119
+ },
120
+
121
+ renderToolResultMessage(content) {
122
+ if (!content) {
123
+ return <Text>No cells found in notebook</Text>
124
+ }
125
+ if (content.length < 1 || !content[0]) {
126
+ return <Text>No cells found in notebook</Text>
127
+ }
128
+ return <Text>Read {content.length} cells</Text>
129
+ },
130
+ async *call({ notebook_path }) {
131
+ const fullPath = isAbsolute(notebook_path)
132
+ ? notebook_path
133
+ : resolve(getCwd(), notebook_path)
134
+
135
+ const content = readFileSync(fullPath, 'utf-8')
136
+ const notebook = JSON.parse(content) as NotebookContent
137
+ const language = notebook.metadata.language_info?.name ?? 'python'
138
+ const cells = notebook.cells.map((cell, index) =>
139
+ processCell(cell, index, language),
140
+ )
141
+
142
+ yield {
143
+ type: 'result',
144
+ resultForAssistant: renderResultForAssistant(cells),
145
+ data: cells,
146
+ }
147
+ },
148
+ renderResultForAssistant,
149
+ } satisfies Tool<In, Out>
150
+
151
+ function processOutputText(text: string | string[] | undefined): string {
152
+ if (!text) return ''
153
+ const rawText = Array.isArray(text) ? text.join('') : text
154
+ const { truncatedContent } = formatOutput(rawText)
155
+ return truncatedContent
156
+ }
157
+
158
+ function extractImage(
159
+ data: Record<string, unknown>,
160
+ ): NotebookOutputImage | undefined {
161
+ if (typeof data['image/png'] === 'string') {
162
+ return {
163
+ image_data: data['image/png'] as string,
164
+ media_type: 'image/png',
165
+ }
166
+ }
167
+ if (typeof data['image/jpeg'] === 'string') {
168
+ return {
169
+ image_data: data['image/jpeg'] as string,
170
+ media_type: 'image/jpeg',
171
+ }
172
+ }
173
+ return undefined
174
+ }
175
+
176
+ function processOutput(output: NotebookCellOutput) {
177
+ switch (output.output_type) {
178
+ case 'stream':
179
+ return {
180
+ output_type: output.output_type,
181
+ text: processOutputText(output.text),
182
+ }
183
+ case 'execute_result':
184
+ case 'display_data':
185
+ return {
186
+ output_type: output.output_type,
187
+ text: processOutputText(output.data?.['text/plain']),
188
+ image: output.data && extractImage(output.data),
189
+ }
190
+ case 'error':
191
+ return {
192
+ output_type: output.output_type,
193
+ text: processOutputText(
194
+ `${output.ename}: ${output.evalue}\n${output.traceback.join('\n')}`,
195
+ ),
196
+ }
197
+ }
198
+ }
199
+
200
+ function processCell(
201
+ cell: NotebookCell,
202
+ index: number,
203
+ language: string,
204
+ ): NotebookCellSource {
205
+ const cellData: NotebookCellSource = {
206
+ cell: index,
207
+ cellType: cell.cell_type,
208
+ source: Array.isArray(cell.source) ? cell.source.join('') : cell.source,
209
+ language,
210
+ execution_count: cell.execution_count,
211
+ }
212
+
213
+ if (cell.outputs?.length) {
214
+ cellData.outputs = cell.outputs.map(processOutput)
215
+ }
216
+
217
+ return cellData
218
+ }
219
+
220
+ function cellContentToToolResult(cell: NotebookCellSource): TextBlockParam {
221
+ const metadata = []
222
+ if (cell.cellType !== 'code') {
223
+ metadata.push(`<cell_type>${cell.cellType}</cell_type>`)
224
+ }
225
+ if (cell.language !== 'python' && cell.cellType === 'code') {
226
+ metadata.push(`<language>${cell.language}</language>`)
227
+ }
228
+ const cellContent = `<cell ${cell.cell}>${metadata.join('')}${cell.source}</cell ${cell.cell}>`
229
+ return {
230
+ text: cellContent,
231
+ type: 'text',
232
+ }
233
+ }
234
+
235
+ function cellOutputToToolResult(output: NotebookCellSourceOutput) {
236
+ const outputs: (TextBlockParam | ImageBlockParam)[] = []
237
+ if (output.text) {
238
+ outputs.push({
239
+ text: `\n${output.text}`,
240
+ type: 'text',
241
+ })
242
+ }
243
+ if (output.image) {
244
+ outputs.push({
245
+ type: 'image',
246
+ source: {
247
+ data: output.image.image_data,
248
+ media_type: output.image.media_type,
249
+ type: 'base64',
250
+ },
251
+ })
252
+ }
253
+ return outputs
254
+ }
255
+
256
+ function getToolResultFromCell(cell: NotebookCellSource) {
257
+ const contentResult = cellContentToToolResult(cell)
258
+ const outputResults = cell.outputs?.flatMap(cellOutputToToolResult)
259
+ return [contentResult, ...(outputResults ?? [])]
260
+ }
261
+
262
+ export function isNotebookCellType(
263
+ value: string | null,
264
+ ): value is NotebookCellType {
265
+ return value === 'code' || value === 'markdown'
266
+ }
@@ -0,0 +1,3 @@
1
+ export const DESCRIPTION =
2
+ 'Extract and read source code from all code cells in a Jupyter notebook.'
3
+ export const PROMPT = `Reads a Jupyter notebook (.ipynb file) and returns all of the cells with their outputs. Jupyter notebooks are interactive documents that combine code, text, and visualizations, commonly used for data analysis and scientific computing. The notebook_path parameter must be an absolute path, not a relative path.`
@@ -0,0 +1,93 @@
1
+ import { z } from 'zod'
2
+ import React from 'react'
3
+ import { Text } from 'ink'
4
+ import { Tool, ToolUseContext } from '../../Tool'
5
+ import { DESCRIPTION, PROMPT } from './prompt'
6
+ import {
7
+ StickerRequestForm,
8
+ FormData,
9
+ } from '../../components/StickerRequestForm.js'
10
+ import { checkGate, logEvent } from '../../services/statsig'
11
+ import { getTheme } from '../../utils/theme'
12
+
13
+ const stickerRequestSchema = z.object({
14
+ trigger: z.string(),
15
+ })
16
+
17
+ export const StickerRequestTool: Tool = {
18
+ name: 'StickerRequest',
19
+ userFacingName: () => 'Stickers',
20
+ description: async () => DESCRIPTION,
21
+ inputSchema: stickerRequestSchema,
22
+ isEnabled: async () => {
23
+ const enabled = await checkGate('tengu_sticker_easter_egg')
24
+ return enabled
25
+ },
26
+ isReadOnly: () => false,
27
+ isConcurrencySafe: () => false, // StickerRequestTool modifies state, not safe for concurrent execution
28
+ needsPermissions: () => false,
29
+ prompt: async () => PROMPT,
30
+
31
+ async *call(_, context: ToolUseContext) {
32
+ // Log form entry event
33
+ logEvent('sticker_request_form_opened', {})
34
+
35
+ // Create a promise to track form completion and status
36
+ let resolveForm: (success: boolean) => void
37
+ const formComplete = new Promise<boolean>(resolve => {
38
+ resolveForm = success => resolve(success)
39
+ })
40
+
41
+ context.setToolJSX?.({
42
+ jsx: (
43
+ <StickerRequestForm
44
+ onSubmit={(formData: FormData) => {
45
+ // Log successful completion with form data
46
+ logEvent('sticker_request_form_completed', {
47
+ has_address: Boolean(formData.address1).toString(),
48
+ has_optional_address: Boolean(formData.address2).toString(),
49
+ })
50
+ resolveForm(true)
51
+ context.setToolJSX?.(null) // Clear the JSX
52
+ }}
53
+ onClose={() => {
54
+ // Log form cancellation
55
+ logEvent('sticker_request_form_cancelled', {})
56
+ resolveForm(false)
57
+ context.setToolJSX?.(null) // Clear the JSX
58
+ }}
59
+ />
60
+ ),
61
+ shouldHidePromptInput: true,
62
+ })
63
+
64
+ // Wait for form completion and get status
65
+ const success = await formComplete
66
+
67
+ if (!success) {
68
+ context.abortController.abort()
69
+ throw new Error('Sticker request cancelled')
70
+ }
71
+
72
+ // Return success message
73
+ yield {
74
+ type: 'result',
75
+ resultForAssistant:
76
+ 'Sticker request completed! Please tell the user that they will receive stickers in the mail if they have submitted the form!',
77
+ data: { success },
78
+ }
79
+ },
80
+
81
+ renderToolUseMessage(_input) {
82
+ return ''
83
+ },
84
+
85
+ renderToolUseRejectedMessage: _input => (
86
+ <Text>
87
+ &nbsp;&nbsp;⎿ &nbsp;
88
+ <Text color={getTheme().error}>No (Sticker request cancelled)</Text>
89
+ </Text>
90
+ ),
91
+
92
+ renderResultForAssistant: (content: string) => content,
93
+ }
@@ -0,0 +1,19 @@
1
+ export const DESCRIPTION =
2
+ 'Sends the user swag stickers with love from Anthropic.'
3
+ export const PROMPT = `This tool should be used whenever a user expresses interest in receiving Anthropic or Claude stickers, swag, or merchandise. When triggered, it will display a shipping form for the user to enter their mailing address and contact details. Once submitted, Anthropic will process the request and ship stickers to the provided address.
4
+
5
+ Common trigger phrases to watch for:
6
+ - "Can I get some Anthropic stickers please?"
7
+ - "How do I get Anthropic swag?"
8
+ - "I'd love some Claude stickers"
9
+ - "Where can I get merchandise?"
10
+ - Any mention of wanting stickers or swag
11
+
12
+ The tool handles the entire request process by showing an interactive form to collect shipping information.
13
+
14
+ NOTE: Only use this tool if the user has explicitly asked us to send or give them stickers. If there are other requests that include the word "sticker", but do not explicitly ask us to send them stickers, do not use this tool.
15
+ For example:
16
+ - "How do I make custom stickers for my project?" - Do not use this tool
17
+ - "I need to store sticker metadata in a database - what schema do you recommend?" - Do not use this tool
18
+ - "Show me how to implement drag-and-drop sticker placement with React" - Do not use this tool
19
+ `