@shareai-lab/kode 1.0.70 → 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.
- package/README.md +342 -75
- package/README.zh-CN.md +292 -0
- package/cli.js +62 -0
- package/package.json +49 -25
- package/scripts/postinstall.js +56 -0
- package/src/ProjectOnboarding.tsx +198 -0
- package/src/Tool.ts +82 -0
- package/src/commands/agents.tsx +3401 -0
- package/src/commands/approvedTools.ts +53 -0
- package/src/commands/bug.tsx +20 -0
- package/src/commands/clear.ts +43 -0
- package/src/commands/compact.ts +120 -0
- package/src/commands/config.tsx +19 -0
- package/src/commands/cost.ts +18 -0
- package/src/commands/ctx_viz.ts +209 -0
- package/src/commands/doctor.ts +24 -0
- package/src/commands/help.tsx +19 -0
- package/src/commands/init.ts +37 -0
- package/src/commands/listen.ts +42 -0
- package/src/commands/login.tsx +51 -0
- package/src/commands/logout.tsx +40 -0
- package/src/commands/mcp.ts +41 -0
- package/src/commands/model.tsx +40 -0
- package/src/commands/modelstatus.tsx +20 -0
- package/src/commands/onboarding.tsx +34 -0
- package/src/commands/pr_comments.ts +59 -0
- package/src/commands/refreshCommands.ts +54 -0
- package/src/commands/release-notes.ts +34 -0
- package/src/commands/resume.tsx +31 -0
- package/src/commands/review.ts +49 -0
- package/src/commands/terminalSetup.ts +221 -0
- package/src/commands.ts +139 -0
- package/src/components/ApproveApiKey.tsx +93 -0
- package/src/components/AsciiLogo.tsx +13 -0
- package/src/components/AutoUpdater.tsx +148 -0
- package/src/components/Bug.tsx +367 -0
- package/src/components/Config.tsx +293 -0
- package/src/components/ConsoleOAuthFlow.tsx +327 -0
- package/src/components/Cost.tsx +23 -0
- package/src/components/CostThresholdDialog.tsx +46 -0
- package/src/components/CustomSelect/option-map.ts +42 -0
- package/src/components/CustomSelect/select-option.tsx +78 -0
- package/src/components/CustomSelect/select.tsx +152 -0
- package/src/components/CustomSelect/theme.ts +45 -0
- package/src/components/CustomSelect/use-select-state.ts +414 -0
- package/src/components/CustomSelect/use-select.ts +35 -0
- package/src/components/FallbackToolUseRejectedMessage.tsx +15 -0
- package/src/components/FileEditToolUpdatedMessage.tsx +66 -0
- package/src/components/Help.tsx +215 -0
- package/src/components/HighlightedCode.tsx +33 -0
- package/src/components/InvalidConfigDialog.tsx +113 -0
- package/src/components/Link.tsx +32 -0
- package/src/components/LogSelector.tsx +86 -0
- package/src/components/Logo.tsx +145 -0
- package/src/components/MCPServerApprovalDialog.tsx +100 -0
- package/src/components/MCPServerDialogCopy.tsx +25 -0
- package/src/components/MCPServerMultiselectDialog.tsx +109 -0
- package/src/components/Message.tsx +221 -0
- package/src/components/MessageResponse.tsx +15 -0
- package/src/components/MessageSelector.tsx +211 -0
- package/src/components/ModeIndicator.tsx +88 -0
- package/src/components/ModelConfig.tsx +301 -0
- package/src/components/ModelListManager.tsx +227 -0
- package/src/components/ModelSelector.tsx +3386 -0
- package/src/components/ModelStatusDisplay.tsx +230 -0
- package/src/components/Onboarding.tsx +274 -0
- package/src/components/PressEnterToContinue.tsx +11 -0
- package/src/components/PromptInput.tsx +740 -0
- package/src/components/SentryErrorBoundary.ts +33 -0
- package/src/components/Spinner.tsx +129 -0
- package/src/components/StickerRequestForm.tsx +16 -0
- package/src/components/StructuredDiff.tsx +191 -0
- package/src/components/TextInput.tsx +259 -0
- package/src/components/TodoItem.tsx +11 -0
- package/src/components/TokenWarning.tsx +31 -0
- package/src/components/ToolUseLoader.tsx +40 -0
- package/src/components/TrustDialog.tsx +106 -0
- package/src/components/binary-feedback/BinaryFeedback.tsx +63 -0
- package/src/components/binary-feedback/BinaryFeedbackOption.tsx +111 -0
- package/src/components/binary-feedback/BinaryFeedbackView.tsx +172 -0
- package/src/components/binary-feedback/utils.ts +220 -0
- package/src/components/messages/AssistantBashOutputMessage.tsx +22 -0
- package/src/components/messages/AssistantLocalCommandOutputMessage.tsx +49 -0
- package/src/components/messages/AssistantRedactedThinkingMessage.tsx +19 -0
- package/src/components/messages/AssistantTextMessage.tsx +144 -0
- package/src/components/messages/AssistantThinkingMessage.tsx +40 -0
- package/src/components/messages/AssistantToolUseMessage.tsx +133 -0
- package/src/components/messages/TaskProgressMessage.tsx +32 -0
- package/src/components/messages/TaskToolMessage.tsx +58 -0
- package/src/components/messages/UserBashInputMessage.tsx +28 -0
- package/src/components/messages/UserCommandMessage.tsx +30 -0
- package/src/components/messages/UserKodingInputMessage.tsx +28 -0
- package/src/components/messages/UserPromptMessage.tsx +35 -0
- package/src/components/messages/UserTextMessage.tsx +39 -0
- package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.tsx +12 -0
- package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.tsx +36 -0
- package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.tsx +31 -0
- package/src/components/messages/UserToolResultMessage/UserToolResultMessage.tsx +57 -0
- package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.tsx +35 -0
- package/src/components/messages/UserToolResultMessage/utils.tsx +56 -0
- package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.tsx +121 -0
- package/src/components/permissions/FallbackPermissionRequest.tsx +153 -0
- package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +182 -0
- package/src/components/permissions/FileEditPermissionRequest/FileEditToolDiff.tsx +77 -0
- package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +164 -0
- package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +83 -0
- package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +240 -0
- package/src/components/permissions/PermissionRequest.tsx +101 -0
- package/src/components/permissions/PermissionRequestTitle.tsx +69 -0
- package/src/components/permissions/hooks.ts +44 -0
- package/src/components/permissions/toolUseOptions.ts +59 -0
- package/src/components/permissions/utils.ts +23 -0
- package/src/constants/betas.ts +5 -0
- package/src/constants/claude-asterisk-ascii-art.tsx +238 -0
- package/src/constants/figures.ts +4 -0
- package/src/constants/keys.ts +3 -0
- package/src/constants/macros.ts +8 -0
- package/src/constants/modelCapabilities.ts +179 -0
- package/src/constants/models.ts +1025 -0
- package/src/constants/oauth.ts +18 -0
- package/src/constants/product.ts +17 -0
- package/src/constants/prompts.ts +177 -0
- package/src/constants/releaseNotes.ts +7 -0
- package/src/context/PermissionContext.tsx +149 -0
- package/src/context.ts +278 -0
- package/src/cost-tracker.ts +84 -0
- package/src/entrypoints/cli.tsx +1518 -0
- package/src/entrypoints/mcp.ts +176 -0
- package/src/history.ts +25 -0
- package/src/hooks/useApiKeyVerification.ts +59 -0
- package/src/hooks/useArrowKeyHistory.ts +55 -0
- package/src/hooks/useCanUseTool.ts +138 -0
- package/src/hooks/useCancelRequest.ts +39 -0
- package/src/hooks/useDoublePress.ts +42 -0
- package/src/hooks/useExitOnCtrlCD.ts +31 -0
- package/src/hooks/useInterval.ts +25 -0
- package/src/hooks/useLogMessages.ts +16 -0
- package/src/hooks/useLogStartupTime.ts +12 -0
- package/src/hooks/useNotifyAfterTimeout.ts +65 -0
- package/src/hooks/usePermissionRequestLogging.ts +44 -0
- package/src/hooks/useTerminalSize.ts +49 -0
- package/src/hooks/useTextInput.ts +318 -0
- package/src/hooks/useUnifiedCompletion.ts +1404 -0
- package/src/messages.ts +38 -0
- package/src/permissions.ts +268 -0
- package/src/query.ts +707 -0
- package/src/screens/ConfigureNpmPrefix.tsx +197 -0
- package/src/screens/Doctor.tsx +219 -0
- package/src/screens/LogList.tsx +68 -0
- package/src/screens/REPL.tsx +798 -0
- package/src/screens/ResumeConversation.tsx +68 -0
- package/src/services/adapters/base.ts +38 -0
- package/src/services/adapters/chatCompletions.ts +90 -0
- package/src/services/adapters/responsesAPI.ts +170 -0
- package/src/services/browserMocks.ts +66 -0
- package/src/services/claude.ts +2083 -0
- package/src/services/customCommands.ts +704 -0
- package/src/services/fileFreshness.ts +377 -0
- package/src/services/gpt5ConnectionTest.ts +340 -0
- package/src/services/mcpClient.ts +564 -0
- package/src/services/mcpServerApproval.tsx +50 -0
- package/src/services/mentionProcessor.ts +273 -0
- package/src/services/modelAdapterFactory.ts +69 -0
- package/src/services/notifier.ts +40 -0
- package/src/services/oauth.ts +357 -0
- package/src/services/openai.ts +1305 -0
- package/src/services/responseStateManager.ts +90 -0
- package/src/services/sentry.ts +3 -0
- package/src/services/statsig.ts +171 -0
- package/src/services/statsigStorage.ts +86 -0
- package/src/services/systemReminder.ts +507 -0
- package/src/services/vcr.ts +161 -0
- package/src/test/testAdapters.ts +96 -0
- package/src/tools/ArchitectTool/ArchitectTool.tsx +122 -0
- package/src/tools/ArchitectTool/prompt.ts +15 -0
- package/src/tools/AskExpertModelTool/AskExpertModelTool.tsx +569 -0
- package/src/tools/BashTool/BashTool.tsx +243 -0
- package/src/tools/BashTool/BashToolResultMessage.tsx +38 -0
- package/src/tools/BashTool/OutputLine.tsx +49 -0
- package/src/tools/BashTool/prompt.ts +174 -0
- package/src/tools/BashTool/utils.ts +56 -0
- package/src/tools/FileEditTool/FileEditTool.tsx +315 -0
- package/src/tools/FileEditTool/prompt.ts +51 -0
- package/src/tools/FileEditTool/utils.ts +58 -0
- package/src/tools/FileReadTool/FileReadTool.tsx +404 -0
- package/src/tools/FileReadTool/prompt.ts +7 -0
- package/src/tools/FileWriteTool/FileWriteTool.tsx +297 -0
- package/src/tools/FileWriteTool/prompt.ts +10 -0
- package/src/tools/GlobTool/GlobTool.tsx +119 -0
- package/src/tools/GlobTool/prompt.ts +8 -0
- package/src/tools/GrepTool/GrepTool.tsx +147 -0
- package/src/tools/GrepTool/prompt.ts +11 -0
- package/src/tools/MCPTool/MCPTool.tsx +107 -0
- package/src/tools/MCPTool/prompt.ts +3 -0
- package/src/tools/MemoryReadTool/MemoryReadTool.tsx +127 -0
- package/src/tools/MemoryReadTool/prompt.ts +3 -0
- package/src/tools/MemoryWriteTool/MemoryWriteTool.tsx +89 -0
- package/src/tools/MemoryWriteTool/prompt.ts +3 -0
- package/src/tools/MultiEditTool/MultiEditTool.tsx +366 -0
- package/src/tools/MultiEditTool/prompt.ts +45 -0
- package/src/tools/NotebookEditTool/NotebookEditTool.tsx +298 -0
- package/src/tools/NotebookEditTool/prompt.ts +3 -0
- package/src/tools/NotebookReadTool/NotebookReadTool.tsx +258 -0
- package/src/tools/NotebookReadTool/prompt.ts +3 -0
- package/src/tools/StickerRequestTool/StickerRequestTool.tsx +93 -0
- package/src/tools/StickerRequestTool/prompt.ts +19 -0
- package/src/tools/TaskTool/TaskTool.tsx +466 -0
- package/src/tools/TaskTool/constants.ts +1 -0
- package/src/tools/TaskTool/prompt.ts +92 -0
- package/src/tools/ThinkTool/ThinkTool.tsx +54 -0
- package/src/tools/ThinkTool/prompt.ts +12 -0
- package/src/tools/TodoWriteTool/TodoWriteTool.tsx +290 -0
- package/src/tools/TodoWriteTool/prompt.ts +63 -0
- package/src/tools/lsTool/lsTool.tsx +272 -0
- package/src/tools/lsTool/prompt.ts +2 -0
- package/src/tools.ts +63 -0
- package/src/types/PermissionMode.ts +120 -0
- package/src/types/RequestContext.ts +72 -0
- package/src/types/conversation.ts +51 -0
- package/src/types/logs.ts +58 -0
- package/src/types/modelCapabilities.ts +64 -0
- package/src/types/notebook.ts +87 -0
- package/src/utils/Cursor.ts +436 -0
- package/src/utils/PersistentShell.ts +373 -0
- package/src/utils/advancedFuzzyMatcher.ts +290 -0
- package/src/utils/agentLoader.ts +284 -0
- package/src/utils/agentStorage.ts +97 -0
- package/src/utils/array.ts +3 -0
- package/src/utils/ask.tsx +99 -0
- package/src/utils/auth.ts +13 -0
- package/src/utils/autoCompactCore.ts +223 -0
- package/src/utils/autoUpdater.ts +318 -0
- package/src/utils/betas.ts +20 -0
- package/src/utils/browser.ts +14 -0
- package/src/utils/cleanup.ts +72 -0
- package/src/utils/commands.ts +261 -0
- package/src/utils/commonUnixCommands.ts +161 -0
- package/src/utils/config.ts +942 -0
- package/src/utils/conversationRecovery.ts +55 -0
- package/src/utils/debugLogger.ts +1123 -0
- package/src/utils/diff.ts +42 -0
- package/src/utils/env.ts +57 -0
- package/src/utils/errors.ts +21 -0
- package/src/utils/exampleCommands.ts +109 -0
- package/src/utils/execFileNoThrow.ts +51 -0
- package/src/utils/expertChatStorage.ts +136 -0
- package/src/utils/file.ts +402 -0
- package/src/utils/fileRecoveryCore.ts +71 -0
- package/src/utils/format.tsx +44 -0
- package/src/utils/fuzzyMatcher.ts +328 -0
- package/src/utils/generators.ts +62 -0
- package/src/utils/git.ts +92 -0
- package/src/utils/globalLogger.ts +77 -0
- package/src/utils/http.ts +10 -0
- package/src/utils/imagePaste.ts +38 -0
- package/src/utils/json.ts +13 -0
- package/src/utils/log.ts +382 -0
- package/src/utils/markdown.ts +213 -0
- package/src/utils/messageContextManager.ts +289 -0
- package/src/utils/messages.tsx +939 -0
- package/src/utils/model.ts +836 -0
- package/src/utils/permissions/filesystem.ts +118 -0
- package/src/utils/responseState.ts +23 -0
- package/src/utils/ripgrep.ts +167 -0
- package/src/utils/secureFile.ts +559 -0
- package/src/utils/sessionState.ts +49 -0
- package/src/utils/state.ts +25 -0
- package/src/utils/style.ts +29 -0
- package/src/utils/terminal.ts +50 -0
- package/src/utils/theme.ts +133 -0
- package/src/utils/thinking.ts +144 -0
- package/src/utils/todoStorage.ts +431 -0
- package/src/utils/tokens.ts +43 -0
- package/src/utils/toolExecutionController.ts +163 -0
- package/src/utils/unaryLogging.ts +26 -0
- package/src/utils/user.ts +37 -0
- package/src/utils/validate.ts +165 -0
- package/cli.mjs +0 -1803
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { Tool } from '../../../Tool'
|
|
3
|
+
import { Message } from '../../../query'
|
|
4
|
+
import { FallbackToolUseRejectedMessage } from '../../FallbackToolUseRejectedMessage'
|
|
5
|
+
import { useGetToolFromMessages } from './utils'
|
|
6
|
+
import { useTerminalSize } from '../../../hooks/useTerminalSize'
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
toolUseID: string
|
|
10
|
+
messages: Message[]
|
|
11
|
+
tools: Tool[]
|
|
12
|
+
verbose: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function UserToolRejectMessage({
|
|
16
|
+
toolUseID,
|
|
17
|
+
tools,
|
|
18
|
+
messages,
|
|
19
|
+
verbose,
|
|
20
|
+
}: Props): React.ReactNode {
|
|
21
|
+
const { columns } = useTerminalSize()
|
|
22
|
+
const { tool, toolUse } = useGetToolFromMessages(toolUseID, tools, messages)
|
|
23
|
+
const input = tool.inputSchema.safeParse(toolUse.input)
|
|
24
|
+
if (input.success) {
|
|
25
|
+
return tool.renderToolUseRejectedMessage(input.data, {
|
|
26
|
+
columns,
|
|
27
|
+
verbose,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
return <FallbackToolUseRejectedMessage />
|
|
31
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ToolResultBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { Tool } from '../../../Tool'
|
|
4
|
+
import { Message, UserMessage } from '../../../query'
|
|
5
|
+
import { CANCEL_MESSAGE, REJECT_MESSAGE } from '../../../utils/messages'
|
|
6
|
+
import { UserToolCanceledMessage } from './UserToolCanceledMessage'
|
|
7
|
+
import { UserToolErrorMessage } from './UserToolErrorMessage'
|
|
8
|
+
import { UserToolRejectMessage } from './UserToolRejectMessage'
|
|
9
|
+
import { UserToolSuccessMessage } from './UserToolSuccessMessage'
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
param: ToolResultBlockParam
|
|
13
|
+
message: UserMessage
|
|
14
|
+
messages: Message[]
|
|
15
|
+
tools: Tool[]
|
|
16
|
+
verbose: boolean
|
|
17
|
+
width: number | string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function UserToolResultMessage({
|
|
21
|
+
param,
|
|
22
|
+
message,
|
|
23
|
+
messages,
|
|
24
|
+
tools,
|
|
25
|
+
verbose,
|
|
26
|
+
width,
|
|
27
|
+
}: Props): React.ReactNode {
|
|
28
|
+
if (param.content === CANCEL_MESSAGE) {
|
|
29
|
+
return <UserToolCanceledMessage />
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (param.content === REJECT_MESSAGE) {
|
|
33
|
+
return (
|
|
34
|
+
<UserToolRejectMessage
|
|
35
|
+
toolUseID={param.tool_use_id}
|
|
36
|
+
tools={tools}
|
|
37
|
+
messages={messages}
|
|
38
|
+
verbose={verbose}
|
|
39
|
+
/>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (param.is_error) {
|
|
44
|
+
return <UserToolErrorMessage param={param} verbose={verbose} />
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<UserToolSuccessMessage
|
|
49
|
+
param={param}
|
|
50
|
+
message={message}
|
|
51
|
+
messages={messages}
|
|
52
|
+
tools={tools}
|
|
53
|
+
verbose={verbose}
|
|
54
|
+
width={width}
|
|
55
|
+
/>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ToolResultBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'
|
|
2
|
+
import { Box } from 'ink'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Tool } from '../../../Tool'
|
|
5
|
+
import { Message, UserMessage } from '../../../query'
|
|
6
|
+
import { useGetToolFromMessages } from './utils'
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
param: ToolResultBlockParam
|
|
10
|
+
message: UserMessage
|
|
11
|
+
messages: Message[]
|
|
12
|
+
verbose: boolean
|
|
13
|
+
tools: Tool[]
|
|
14
|
+
width: number | string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function UserToolSuccessMessage({
|
|
18
|
+
param,
|
|
19
|
+
message,
|
|
20
|
+
messages,
|
|
21
|
+
tools,
|
|
22
|
+
verbose,
|
|
23
|
+
width,
|
|
24
|
+
}: Props): React.ReactNode {
|
|
25
|
+
const { tool } = useGetToolFromMessages(param.tool_use_id, tools, messages)
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
// TODO: Distinguish UserMessage from UserToolResultMessage
|
|
29
|
+
<Box flexDirection="column" width={width}>
|
|
30
|
+
{tool.renderToolResultMessage?.(message.toolUseResult!.data as never, {
|
|
31
|
+
verbose,
|
|
32
|
+
})}
|
|
33
|
+
</Box>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ToolUseBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'
|
|
2
|
+
import { Message } from '../../../query'
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import { Tool } from '../../../Tool'
|
|
5
|
+
import { GlobTool } from '../../../tools/GlobTool/GlobTool'
|
|
6
|
+
import { GrepTool } from '../../../tools/GrepTool/GrepTool'
|
|
7
|
+
import { logEvent } from '../../../services/statsig'
|
|
8
|
+
|
|
9
|
+
function getToolUseFromMessages(
|
|
10
|
+
toolUseID: string,
|
|
11
|
+
messages: Message[],
|
|
12
|
+
): ToolUseBlockParam | null {
|
|
13
|
+
let toolUse: ToolUseBlockParam | null = null
|
|
14
|
+
for (const message of messages) {
|
|
15
|
+
if (
|
|
16
|
+
message.type !== 'assistant' ||
|
|
17
|
+
!Array.isArray(message.message.content)
|
|
18
|
+
) {
|
|
19
|
+
continue
|
|
20
|
+
}
|
|
21
|
+
for (const content of message.message.content) {
|
|
22
|
+
if (content.type === 'tool_use' && content.id === toolUseID) {
|
|
23
|
+
toolUse = content
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return toolUse
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useGetToolFromMessages(
|
|
31
|
+
toolUseID: string,
|
|
32
|
+
tools: Tool[],
|
|
33
|
+
messages: Message[],
|
|
34
|
+
) {
|
|
35
|
+
return useMemo(() => {
|
|
36
|
+
const toolUse = getToolUseFromMessages(toolUseID, messages)
|
|
37
|
+
if (!toolUse) {
|
|
38
|
+
throw new ReferenceError(
|
|
39
|
+
`Tool use not found for tool_use_id ${toolUseID}`,
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
// Hack: we don't expose GlobTool and GrepTool in getTools anymore,
|
|
43
|
+
// but we still want to be able to load old transcripts.
|
|
44
|
+
// TODO: Remove this when logging hits zero
|
|
45
|
+
const tool = [...tools, GlobTool, GrepTool].find(
|
|
46
|
+
_ => _.name === toolUse.name,
|
|
47
|
+
)
|
|
48
|
+
if (tool === GlobTool || tool === GrepTool) {
|
|
49
|
+
logEvent('tengu_legacy_tool_lookup', {})
|
|
50
|
+
}
|
|
51
|
+
if (!tool) {
|
|
52
|
+
throw new ReferenceError(`Tool not found for ${toolUse.name}`)
|
|
53
|
+
}
|
|
54
|
+
return { tool, toolUse }
|
|
55
|
+
}, [toolUseID, messages, tools])
|
|
56
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Box, Text } from 'ink'
|
|
2
|
+
import React, { useMemo } from 'react'
|
|
3
|
+
import { UnaryEvent } from '../../../hooks/usePermissionRequestLogging'
|
|
4
|
+
import { savePermission } from '../../../permissions'
|
|
5
|
+
import { BashTool } from '../../../tools/BashTool/BashTool'
|
|
6
|
+
import { getTheme } from '../../../utils/theme'
|
|
7
|
+
import { usePermissionRequestLogging } from '../hooks'
|
|
8
|
+
import {
|
|
9
|
+
type ToolUseConfirm,
|
|
10
|
+
toolUseConfirmGetPrefix,
|
|
11
|
+
} from '../PermissionRequest.js'
|
|
12
|
+
import { PermissionRequestTitle } from '../PermissionRequestTitle'
|
|
13
|
+
import { logUnaryPermissionEvent } from '../utils'
|
|
14
|
+
import { Select } from '../../CustomSelect/select'
|
|
15
|
+
import { toolUseOptions } from '../toolUseOptions'
|
|
16
|
+
|
|
17
|
+
type Props = {
|
|
18
|
+
toolUseConfirm: ToolUseConfirm
|
|
19
|
+
onDone(): void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function BashPermissionRequest({
|
|
23
|
+
toolUseConfirm,
|
|
24
|
+
onDone,
|
|
25
|
+
}: Props): React.ReactNode {
|
|
26
|
+
const theme = getTheme()
|
|
27
|
+
|
|
28
|
+
// ok to use parse since we've already validated args earliers
|
|
29
|
+
const { command } = BashTool.inputSchema.parse(toolUseConfirm.input)
|
|
30
|
+
|
|
31
|
+
const unaryEvent = useMemo<UnaryEvent>(
|
|
32
|
+
() => ({ completion_type: 'tool_use_single', language_name: 'none' }),
|
|
33
|
+
[],
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
usePermissionRequestLogging(toolUseConfirm, unaryEvent)
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Box
|
|
40
|
+
flexDirection="column"
|
|
41
|
+
borderStyle="round"
|
|
42
|
+
borderColor={theme.permission}
|
|
43
|
+
marginTop={1}
|
|
44
|
+
paddingLeft={1}
|
|
45
|
+
paddingRight={1}
|
|
46
|
+
paddingBottom={1}
|
|
47
|
+
>
|
|
48
|
+
<PermissionRequestTitle
|
|
49
|
+
title="Bash command"
|
|
50
|
+
riskScore={toolUseConfirm.riskScore}
|
|
51
|
+
/>
|
|
52
|
+
<Box flexDirection="column" paddingX={2} paddingY={1}>
|
|
53
|
+
<Text>{BashTool.renderToolUseMessage({ command })}</Text>
|
|
54
|
+
<Text color={theme.secondaryText}>{toolUseConfirm.description}</Text>
|
|
55
|
+
</Box>
|
|
56
|
+
|
|
57
|
+
<Box flexDirection="column">
|
|
58
|
+
<Text>Do you want to proceed?</Text>
|
|
59
|
+
<Select
|
|
60
|
+
options={toolUseOptions({ toolUseConfirm, command })}
|
|
61
|
+
onChange={newValue => {
|
|
62
|
+
switch (newValue) {
|
|
63
|
+
case 'yes':
|
|
64
|
+
logUnaryPermissionEvent(
|
|
65
|
+
'tool_use_single',
|
|
66
|
+
toolUseConfirm,
|
|
67
|
+
'accept',
|
|
68
|
+
)
|
|
69
|
+
toolUseConfirm.onAllow('temporary')
|
|
70
|
+
onDone()
|
|
71
|
+
break
|
|
72
|
+
case 'yes-dont-ask-again-prefix': {
|
|
73
|
+
const prefix = toolUseConfirmGetPrefix(toolUseConfirm)
|
|
74
|
+
if (prefix !== null) {
|
|
75
|
+
logUnaryPermissionEvent(
|
|
76
|
+
'tool_use_single',
|
|
77
|
+
toolUseConfirm,
|
|
78
|
+
'accept',
|
|
79
|
+
)
|
|
80
|
+
savePermission(
|
|
81
|
+
toolUseConfirm.tool,
|
|
82
|
+
toolUseConfirm.input,
|
|
83
|
+
prefix,
|
|
84
|
+
).then(() => {
|
|
85
|
+
toolUseConfirm.onAllow('permanent')
|
|
86
|
+
onDone()
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
case 'yes-dont-ask-again-full':
|
|
92
|
+
logUnaryPermissionEvent(
|
|
93
|
+
'tool_use_single',
|
|
94
|
+
toolUseConfirm,
|
|
95
|
+
'accept',
|
|
96
|
+
)
|
|
97
|
+
savePermission(
|
|
98
|
+
toolUseConfirm.tool,
|
|
99
|
+
toolUseConfirm.input,
|
|
100
|
+
null, // Save without prefix
|
|
101
|
+
).then(() => {
|
|
102
|
+
toolUseConfirm.onAllow('permanent')
|
|
103
|
+
onDone()
|
|
104
|
+
})
|
|
105
|
+
break
|
|
106
|
+
case 'no':
|
|
107
|
+
logUnaryPermissionEvent(
|
|
108
|
+
'tool_use_single',
|
|
109
|
+
toolUseConfirm,
|
|
110
|
+
'reject',
|
|
111
|
+
)
|
|
112
|
+
toolUseConfirm.onReject()
|
|
113
|
+
onDone()
|
|
114
|
+
break
|
|
115
|
+
}
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
</Box>
|
|
119
|
+
</Box>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Box, Text } from 'ink'
|
|
2
|
+
import React, { useMemo } from 'react'
|
|
3
|
+
import { Select } from '../CustomSelect/select'
|
|
4
|
+
import { getTheme } from '../../utils/theme'
|
|
5
|
+
import {
|
|
6
|
+
PermissionRequestTitle,
|
|
7
|
+
textColorForRiskScore,
|
|
8
|
+
} from './PermissionRequestTitle.js'
|
|
9
|
+
import { logUnaryEvent } from '../../utils/unaryLogging'
|
|
10
|
+
import { env } from '../../utils/env'
|
|
11
|
+
import { getCwd } from '../../utils/state'
|
|
12
|
+
import { savePermission } from '../../permissions'
|
|
13
|
+
import {
|
|
14
|
+
type ToolUseConfirm,
|
|
15
|
+
toolUseConfirmGetPrefix,
|
|
16
|
+
} from './PermissionRequest.js'
|
|
17
|
+
import chalk from 'chalk'
|
|
18
|
+
import {
|
|
19
|
+
UnaryEvent,
|
|
20
|
+
usePermissionRequestLogging,
|
|
21
|
+
} from '../../hooks/usePermissionRequestLogging.js'
|
|
22
|
+
|
|
23
|
+
type Props = {
|
|
24
|
+
toolUseConfirm: ToolUseConfirm
|
|
25
|
+
onDone(): void
|
|
26
|
+
verbose: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function FallbackPermissionRequest({
|
|
30
|
+
toolUseConfirm,
|
|
31
|
+
onDone,
|
|
32
|
+
verbose,
|
|
33
|
+
}: Props): React.ReactNode {
|
|
34
|
+
const theme = getTheme()
|
|
35
|
+
|
|
36
|
+
// TODO: Avoid these special cases
|
|
37
|
+
const originalUserFacingName = toolUseConfirm.tool.userFacingName()
|
|
38
|
+
const userFacingName = originalUserFacingName.endsWith(' (MCP)')
|
|
39
|
+
? originalUserFacingName.slice(0, -6)
|
|
40
|
+
: originalUserFacingName
|
|
41
|
+
|
|
42
|
+
const unaryEvent = useMemo<UnaryEvent>(
|
|
43
|
+
() => ({
|
|
44
|
+
completion_type: 'tool_use_single',
|
|
45
|
+
language_name: 'none',
|
|
46
|
+
}),
|
|
47
|
+
[],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
usePermissionRequestLogging(toolUseConfirm, unaryEvent)
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Box
|
|
54
|
+
flexDirection="column"
|
|
55
|
+
borderStyle="round"
|
|
56
|
+
borderColor={textColorForRiskScore(toolUseConfirm.riskScore)}
|
|
57
|
+
marginTop={1}
|
|
58
|
+
paddingLeft={1}
|
|
59
|
+
paddingRight={1}
|
|
60
|
+
paddingBottom={1}
|
|
61
|
+
>
|
|
62
|
+
<PermissionRequestTitle
|
|
63
|
+
title="Tool use"
|
|
64
|
+
riskScore={toolUseConfirm.riskScore}
|
|
65
|
+
/>
|
|
66
|
+
<Box flexDirection="column" paddingX={2} paddingY={1}>
|
|
67
|
+
<Text>
|
|
68
|
+
{userFacingName}(
|
|
69
|
+
{toolUseConfirm.tool.renderToolUseMessage(
|
|
70
|
+
toolUseConfirm.input as never,
|
|
71
|
+
{ verbose },
|
|
72
|
+
)}
|
|
73
|
+
)
|
|
74
|
+
{originalUserFacingName.endsWith(' (MCP)') ? (
|
|
75
|
+
<Text color={theme.secondaryText}> (MCP)</Text>
|
|
76
|
+
) : (
|
|
77
|
+
''
|
|
78
|
+
)}
|
|
79
|
+
</Text>
|
|
80
|
+
<Text color={theme.secondaryText}>{toolUseConfirm.description}</Text>
|
|
81
|
+
</Box>
|
|
82
|
+
|
|
83
|
+
<Box flexDirection="column">
|
|
84
|
+
<Text>Do you want to proceed?</Text>
|
|
85
|
+
<Select
|
|
86
|
+
options={[
|
|
87
|
+
{
|
|
88
|
+
label: 'Yes',
|
|
89
|
+
value: 'yes',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
label: `Yes, and don't ask again for ${chalk.bold(userFacingName)} commands in ${chalk.bold(getCwd())}`,
|
|
93
|
+
value: 'yes-dont-ask-again',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
label: `No, and provide instructions (${chalk.bold.hex(getTheme().warning)('esc')})`,
|
|
97
|
+
value: 'no',
|
|
98
|
+
},
|
|
99
|
+
]}
|
|
100
|
+
onChange={newValue => {
|
|
101
|
+
switch (newValue) {
|
|
102
|
+
case 'yes':
|
|
103
|
+
logUnaryEvent({
|
|
104
|
+
completion_type: 'tool_use_single',
|
|
105
|
+
event: 'accept',
|
|
106
|
+
metadata: {
|
|
107
|
+
language_name: 'none',
|
|
108
|
+
message_id: toolUseConfirm.assistantMessage.message.id,
|
|
109
|
+
platform: env.platform,
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
toolUseConfirm.onAllow('temporary')
|
|
113
|
+
onDone()
|
|
114
|
+
break
|
|
115
|
+
case 'yes-dont-ask-again':
|
|
116
|
+
logUnaryEvent({
|
|
117
|
+
completion_type: 'tool_use_single',
|
|
118
|
+
event: 'accept',
|
|
119
|
+
metadata: {
|
|
120
|
+
language_name: 'none',
|
|
121
|
+
message_id: toolUseConfirm.assistantMessage.message.id,
|
|
122
|
+
platform: env.platform,
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
savePermission(
|
|
126
|
+
toolUseConfirm.tool,
|
|
127
|
+
toolUseConfirm.input,
|
|
128
|
+
toolUseConfirmGetPrefix(toolUseConfirm),
|
|
129
|
+
).then(() => {
|
|
130
|
+
toolUseConfirm.onAllow('permanent')
|
|
131
|
+
onDone()
|
|
132
|
+
})
|
|
133
|
+
break
|
|
134
|
+
case 'no':
|
|
135
|
+
logUnaryEvent({
|
|
136
|
+
completion_type: 'tool_use_single',
|
|
137
|
+
event: 'reject',
|
|
138
|
+
metadata: {
|
|
139
|
+
language_name: 'none',
|
|
140
|
+
message_id: toolUseConfirm.assistantMessage.message.id,
|
|
141
|
+
platform: env.platform,
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
toolUseConfirm.onReject()
|
|
145
|
+
onDone()
|
|
146
|
+
break
|
|
147
|
+
}
|
|
148
|
+
}}
|
|
149
|
+
/>
|
|
150
|
+
</Box>
|
|
151
|
+
</Box>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Select } from '../../CustomSelect/select'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import { Box, Text } from 'ink'
|
|
4
|
+
import { basename, extname } from 'path'
|
|
5
|
+
import React, { useMemo } from 'react'
|
|
6
|
+
import {
|
|
7
|
+
UnaryEvent,
|
|
8
|
+
usePermissionRequestLogging,
|
|
9
|
+
} from '../../../hooks/usePermissionRequestLogging.js'
|
|
10
|
+
import { savePermission } from '../../../permissions'
|
|
11
|
+
import { env } from '../../../utils/env'
|
|
12
|
+
import { getTheme } from '../../../utils/theme'
|
|
13
|
+
import { logUnaryEvent } from '../../../utils/unaryLogging'
|
|
14
|
+
import {
|
|
15
|
+
type ToolUseConfirm,
|
|
16
|
+
toolUseConfirmGetPrefix,
|
|
17
|
+
} from '../PermissionRequest.js'
|
|
18
|
+
import {
|
|
19
|
+
PermissionRequestTitle,
|
|
20
|
+
textColorForRiskScore,
|
|
21
|
+
} from '../PermissionRequestTitle.js'
|
|
22
|
+
import { FileEditToolDiff } from './FileEditToolDiff'
|
|
23
|
+
import { useTerminalSize } from '../../../hooks/useTerminalSize'
|
|
24
|
+
import { pathInOriginalCwd } from '../../../utils/permissions/filesystem'
|
|
25
|
+
|
|
26
|
+
function getOptions(path: string) {
|
|
27
|
+
// Only show don't ask again option for edits in original working directory
|
|
28
|
+
const showDontAskAgainOptions = pathInOriginalCwd(path)
|
|
29
|
+
? [
|
|
30
|
+
{
|
|
31
|
+
label: "Yes, and don't ask again this session",
|
|
32
|
+
value: 'yes-dont-ask-again',
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
: []
|
|
36
|
+
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
label: 'Yes',
|
|
40
|
+
value: 'yes',
|
|
41
|
+
},
|
|
42
|
+
...showDontAskAgainOptions,
|
|
43
|
+
{
|
|
44
|
+
label: `No, and provide instructions (${chalk.bold.hex(getTheme().warning)('esc')})`,
|
|
45
|
+
value: 'no',
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type Props = {
|
|
51
|
+
toolUseConfirm: ToolUseConfirm
|
|
52
|
+
onDone(): void
|
|
53
|
+
verbose: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function FileEditPermissionRequest({
|
|
57
|
+
toolUseConfirm,
|
|
58
|
+
onDone,
|
|
59
|
+
verbose,
|
|
60
|
+
}: Props): React.ReactNode {
|
|
61
|
+
const { columns } = useTerminalSize()
|
|
62
|
+
const { file_path, new_string, old_string } = toolUseConfirm.input as {
|
|
63
|
+
file_path: string
|
|
64
|
+
new_string: string
|
|
65
|
+
old_string: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const unaryEvent = useMemo<UnaryEvent>(
|
|
69
|
+
() => ({
|
|
70
|
+
completion_type: 'str_replace_single',
|
|
71
|
+
language_name: extractLanguageName(file_path),
|
|
72
|
+
}),
|
|
73
|
+
[file_path],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
usePermissionRequestLogging(toolUseConfirm, unaryEvent)
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<Box
|
|
80
|
+
flexDirection="column"
|
|
81
|
+
borderStyle="round"
|
|
82
|
+
borderColor={textColorForRiskScore(toolUseConfirm.riskScore)}
|
|
83
|
+
marginTop={1}
|
|
84
|
+
paddingLeft={1}
|
|
85
|
+
paddingRight={1}
|
|
86
|
+
paddingBottom={1}
|
|
87
|
+
>
|
|
88
|
+
<PermissionRequestTitle
|
|
89
|
+
title="Edit file"
|
|
90
|
+
riskScore={toolUseConfirm.riskScore}
|
|
91
|
+
/>
|
|
92
|
+
<FileEditToolDiff
|
|
93
|
+
file_path={file_path}
|
|
94
|
+
new_string={new_string}
|
|
95
|
+
old_string={old_string}
|
|
96
|
+
verbose={verbose}
|
|
97
|
+
width={columns - 12}
|
|
98
|
+
/>
|
|
99
|
+
<Box flexDirection="column">
|
|
100
|
+
<Text>
|
|
101
|
+
Do you want to make this edit to{' '}
|
|
102
|
+
<Text bold>{basename(file_path)}</Text>?
|
|
103
|
+
</Text>
|
|
104
|
+
<Select
|
|
105
|
+
options={getOptions(file_path)}
|
|
106
|
+
onChange={newValue => {
|
|
107
|
+
switch (newValue) {
|
|
108
|
+
case 'yes':
|
|
109
|
+
extractLanguageName(file_path).then(language => {
|
|
110
|
+
logUnaryEvent({
|
|
111
|
+
completion_type: 'str_replace_single',
|
|
112
|
+
event: 'accept',
|
|
113
|
+
metadata: {
|
|
114
|
+
language_name: language,
|
|
115
|
+
message_id: toolUseConfirm.assistantMessage.message.id,
|
|
116
|
+
platform: env.platform,
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
// Note: We call onDone before onAllow to hide the
|
|
121
|
+
// permission request before we render the next message
|
|
122
|
+
onDone()
|
|
123
|
+
toolUseConfirm.onAllow('temporary')
|
|
124
|
+
break
|
|
125
|
+
case 'yes-dont-ask-again':
|
|
126
|
+
extractLanguageName(file_path).then(language => {
|
|
127
|
+
logUnaryEvent({
|
|
128
|
+
completion_type: 'str_replace_single',
|
|
129
|
+
event: 'accept',
|
|
130
|
+
metadata: {
|
|
131
|
+
language_name: language,
|
|
132
|
+
message_id: toolUseConfirm.assistantMessage.message.id,
|
|
133
|
+
platform: env.platform,
|
|
134
|
+
},
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
savePermission(
|
|
138
|
+
toolUseConfirm.tool,
|
|
139
|
+
toolUseConfirm.input,
|
|
140
|
+
toolUseConfirmGetPrefix(toolUseConfirm),
|
|
141
|
+
).then(() => {
|
|
142
|
+
// Note: We call onDone before onAllow to hide the
|
|
143
|
+
// permission request before we render the next message
|
|
144
|
+
onDone()
|
|
145
|
+
toolUseConfirm.onAllow('permanent')
|
|
146
|
+
})
|
|
147
|
+
break
|
|
148
|
+
case 'no':
|
|
149
|
+
extractLanguageName(file_path).then(language => {
|
|
150
|
+
logUnaryEvent({
|
|
151
|
+
completion_type: 'str_replace_single',
|
|
152
|
+
event: 'reject',
|
|
153
|
+
metadata: {
|
|
154
|
+
language_name: language,
|
|
155
|
+
message_id: toolUseConfirm.assistantMessage.message.id,
|
|
156
|
+
platform: env.platform,
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
// Note: We call onDone before onAllow to hide the
|
|
161
|
+
// permission request before we render the next message
|
|
162
|
+
onDone()
|
|
163
|
+
toolUseConfirm.onReject()
|
|
164
|
+
break
|
|
165
|
+
}
|
|
166
|
+
}}
|
|
167
|
+
/>
|
|
168
|
+
</Box>
|
|
169
|
+
</Box>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function extractLanguageName(file_path: string): Promise<string> {
|
|
174
|
+
const ext = extname(file_path)
|
|
175
|
+
if (!ext) {
|
|
176
|
+
return 'unknown'
|
|
177
|
+
}
|
|
178
|
+
const Highlight = (await import('highlight.js')) as unknown as {
|
|
179
|
+
default: { getLanguage(ext: string): { name: string | undefined } }
|
|
180
|
+
}
|
|
181
|
+
return Highlight.default.getLanguage(ext.slice(1))?.name ?? 'unknown'
|
|
182
|
+
}
|