@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.
- package/README.md +202 -76
- package/README.zh-CN.md +246 -0
- package/cli.js +62 -0
- package/package.json +45 -25
- package/scripts/postinstall.js +56 -0
- package/src/ProjectOnboarding.tsx +180 -0
- package/src/Tool.ts +53 -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 +30 -0
- package/src/commands/review.ts +49 -0
- package/src/commands/terminalSetup.ts +221 -0
- package/src/commands.ts +136 -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 +289 -0
- package/src/components/ConsoleOAuthFlow.tsx +326 -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 +52 -0
- package/src/components/CustomSelect/select.tsx +143 -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 +219 -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 +223 -0
- package/src/components/ModelSelector.tsx +3208 -0
- package/src/components/ModelStatusDisplay.tsx +228 -0
- package/src/components/Onboarding.tsx +274 -0
- package/src/components/PressEnterToContinue.tsx +11 -0
- package/src/components/PromptInput.tsx +710 -0
- package/src/components/SentryErrorBoundary.ts +33 -0
- package/src/components/Spinner.tsx +129 -0
- package/src/components/StructuredDiff.tsx +184 -0
- package/src/components/TextInput.tsx +246 -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 +45 -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 +123 -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 +155 -0
- package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +182 -0
- package/src/components/permissions/FileEditPermissionRequest/FileEditToolDiff.tsx +75 -0
- package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +164 -0
- package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +81 -0
- package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +242 -0
- package/src/components/permissions/PermissionRequest.tsx +103 -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 +6 -0
- package/src/constants/models.ts +935 -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 +1498 -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/useSlashCommandTypeahead.ts +137 -0
- package/src/hooks/useTerminalSize.ts +49 -0
- package/src/hooks/useTextInput.ts +315 -0
- package/src/messages.ts +37 -0
- package/src/permissions.ts +268 -0
- package/src/query.ts +704 -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 +792 -0
- package/src/screens/ResumeConversation.tsx +68 -0
- package/src/services/browserMocks.ts +66 -0
- package/src/services/claude.ts +1947 -0
- package/src/services/customCommands.ts +683 -0
- package/src/services/fileFreshness.ts +377 -0
- package/src/services/mcpClient.ts +564 -0
- package/src/services/mcpServerApproval.tsx +50 -0
- package/src/services/notifier.ts +40 -0
- package/src/services/oauth.ts +357 -0
- package/src/services/openai.ts +796 -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 +406 -0
- package/src/services/vcr.ts +161 -0
- package/src/tools/ArchitectTool/ArchitectTool.tsx +122 -0
- package/src/tools/ArchitectTool/prompt.ts +15 -0
- package/src/tools/AskExpertModelTool/AskExpertModelTool.tsx +505 -0
- package/src/tools/BashTool/BashTool.tsx +270 -0
- package/src/tools/BashTool/BashToolResultMessage.tsx +38 -0
- package/src/tools/BashTool/OutputLine.tsx +48 -0
- package/src/tools/BashTool/prompt.ts +174 -0
- package/src/tools/BashTool/utils.ts +56 -0
- package/src/tools/FileEditTool/FileEditTool.tsx +316 -0
- package/src/tools/FileEditTool/prompt.ts +51 -0
- package/src/tools/FileEditTool/utils.ts +58 -0
- package/src/tools/FileReadTool/FileReadTool.tsx +371 -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 +106 -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 +266 -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 +382 -0
- package/src/tools/TaskTool/constants.ts +1 -0
- package/src/tools/TaskTool/prompt.ts +56 -0
- package/src/tools/ThinkTool/ThinkTool.tsx +56 -0
- package/src/tools/ThinkTool/prompt.ts +12 -0
- package/src/tools/TodoWriteTool/TodoWriteTool.tsx +289 -0
- package/src/tools/TodoWriteTool/prompt.ts +63 -0
- package/src/tools/lsTool/lsTool.tsx +269 -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/utils/Cursor.ts +436 -0
- package/src/utils/PersistentShell.ts +373 -0
- package/src/utils/agentStorage.ts +97 -0
- package/src/utils/array.ts +3 -0
- package/src/utils/ask.tsx +98 -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/config.ts +771 -0
- package/src/utils/conversationRecovery.ts +54 -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 +108 -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/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 +938 -0
- package/src/utils/model.ts +836 -0
- package/src/utils/permissions/filesystem.ts +118 -0
- package/src/utils/ripgrep.ts +167 -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 +49 -0
- package/src/utils/theme.ts +122 -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,118 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from 'path'
|
|
2
|
+
import { getCwd, getOriginalCwd } from '../state'
|
|
3
|
+
|
|
4
|
+
// In-memory storage for file permissions that resets each session
|
|
5
|
+
// Sets of allowed directories for read and write operations
|
|
6
|
+
const readFileAllowedDirectories: Set<string> = new Set()
|
|
7
|
+
const writeFileAllowedDirectories: Set<string> = new Set()
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Ensures a path is absolute by resolving it relative to cwd if necessary
|
|
11
|
+
* @param path The path to normalize
|
|
12
|
+
* @returns Absolute path
|
|
13
|
+
*/
|
|
14
|
+
export function toAbsolutePath(path: string): string {
|
|
15
|
+
return isAbsolute(path) ? resolve(path) : resolve(getCwd(), path)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Ensures a path is in the original cwd path
|
|
20
|
+
* @param directory The directory path to normalize
|
|
21
|
+
* @returns Absolute path
|
|
22
|
+
*/
|
|
23
|
+
export function pathInOriginalCwd(path: string): boolean {
|
|
24
|
+
const absolutePath = toAbsolutePath(path)
|
|
25
|
+
return absolutePath.startsWith(toAbsolutePath(getOriginalCwd()))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if read permission exists for the specified directory
|
|
30
|
+
* @param directory The directory to check permission for
|
|
31
|
+
* @returns true if read permission exists, false otherwise
|
|
32
|
+
*/
|
|
33
|
+
export function hasReadPermission(directory: string): boolean {
|
|
34
|
+
const absolutePath = toAbsolutePath(directory)
|
|
35
|
+
|
|
36
|
+
for (const allowedPath of readFileAllowedDirectories) {
|
|
37
|
+
// Permission exists for this directory or a path prefix
|
|
38
|
+
if (absolutePath.startsWith(allowedPath)) {
|
|
39
|
+
return true
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if write permission exists for the specified directory
|
|
47
|
+
* @param directory The directory to check permission for
|
|
48
|
+
* @returns true if write permission exists, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
export function hasWritePermission(directory: string): boolean {
|
|
51
|
+
const absolutePath = toAbsolutePath(directory)
|
|
52
|
+
|
|
53
|
+
for (const allowedPath of writeFileAllowedDirectories) {
|
|
54
|
+
// Permission exists for this directory or a path prefix
|
|
55
|
+
if (absolutePath.startsWith(allowedPath)) {
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Save read permission for a directory
|
|
64
|
+
* @param directory The directory to grant read permission for
|
|
65
|
+
*/
|
|
66
|
+
function saveReadPermission(directory: string): void {
|
|
67
|
+
const absolutePath = toAbsolutePath(directory)
|
|
68
|
+
|
|
69
|
+
// Clean up any existing subdirectories of this path
|
|
70
|
+
for (const allowedPath of readFileAllowedDirectories) {
|
|
71
|
+
if (allowedPath.startsWith(absolutePath)) {
|
|
72
|
+
readFileAllowedDirectories.delete(allowedPath)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
readFileAllowedDirectories.add(absolutePath)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const saveReadPermissionForTest = saveReadPermission
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Grants read permission for the original project directory.
|
|
82
|
+
* This is useful for initializing read access to the project root.
|
|
83
|
+
*/
|
|
84
|
+
export function grantReadPermissionForOriginalDir(): void {
|
|
85
|
+
const originalProjectDir = getOriginalCwd()
|
|
86
|
+
saveReadPermission(originalProjectDir)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Save write permission for a directory
|
|
91
|
+
* @param directory The directory to grant write permission for
|
|
92
|
+
*/
|
|
93
|
+
function saveWritePermission(directory: string): void {
|
|
94
|
+
const absolutePath = toAbsolutePath(directory)
|
|
95
|
+
|
|
96
|
+
// Clean up any existing subdirectories of this path
|
|
97
|
+
for (const allowedPath of writeFileAllowedDirectories) {
|
|
98
|
+
if (allowedPath.startsWith(absolutePath)) {
|
|
99
|
+
writeFileAllowedDirectories.delete(allowedPath)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
writeFileAllowedDirectories.add(absolutePath)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Grants write permission for the original project directory.
|
|
107
|
+
* This is useful for initializing write access to the project root.
|
|
108
|
+
*/
|
|
109
|
+
export function grantWritePermissionForOriginalDir(): void {
|
|
110
|
+
const originalProjectDir = getOriginalCwd()
|
|
111
|
+
saveWritePermission(originalProjectDir)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// For testing purposes
|
|
115
|
+
export function clearFilePermissions(): void {
|
|
116
|
+
readFileAllowedDirectories.clear()
|
|
117
|
+
writeFileAllowedDirectories.clear()
|
|
118
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { findActualExecutable } from 'spawn-rx'
|
|
2
|
+
import { memoize } from 'lodash-es'
|
|
3
|
+
import { fileURLToPath, resolve } from 'node:url'
|
|
4
|
+
import * as path from 'path'
|
|
5
|
+
import { logError } from './log'
|
|
6
|
+
import { execFileNoThrow } from './execFileNoThrow'
|
|
7
|
+
import { execFile } from 'child_process'
|
|
8
|
+
import debug from 'debug'
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
11
|
+
const __dirname = resolve(
|
|
12
|
+
__filename,
|
|
13
|
+
process.env.NODE_ENV === 'test' ? '../..' : '.',
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
const d = debug('claude:ripgrep')
|
|
17
|
+
|
|
18
|
+
const useBuiltinRipgrep = !!process.env.USE_BUILTIN_RIPGREP
|
|
19
|
+
if (useBuiltinRipgrep) {
|
|
20
|
+
d('Using builtin ripgrep because USE_BUILTIN_RIPGREP is set')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ripgrepPath = memoize(() => {
|
|
24
|
+
const { cmd } = findActualExecutable('rg', [])
|
|
25
|
+
d(`ripgrep initially resolved as: ${cmd}`)
|
|
26
|
+
|
|
27
|
+
if (cmd !== 'rg' && !useBuiltinRipgrep) {
|
|
28
|
+
// NB: If we're able to find ripgrep in $PATH, cmd will be an absolute
|
|
29
|
+
// path rather than just returning 'rg'
|
|
30
|
+
return cmd
|
|
31
|
+
} else {
|
|
32
|
+
// Use the one we ship in-box
|
|
33
|
+
const rgRoot = path.resolve(__dirname, 'vendor', 'ripgrep')
|
|
34
|
+
if (process.platform === 'win32') {
|
|
35
|
+
// NB: Ripgrep doesn't ship an aarch64 binary for Windows, boooooo
|
|
36
|
+
return path.resolve(rgRoot, 'x64-win32', 'rg.exe')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const ret = path.resolve(
|
|
40
|
+
rgRoot,
|
|
41
|
+
`${process.arch}-${process.platform}`,
|
|
42
|
+
'rg',
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
d('internal ripgrep resolved as: %s', ret)
|
|
46
|
+
return ret
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export async function ripGrep(
|
|
51
|
+
args: string[],
|
|
52
|
+
target: string,
|
|
53
|
+
abortSignal: AbortSignal,
|
|
54
|
+
): Promise<string[]> {
|
|
55
|
+
await codesignRipgrepIfNecessary()
|
|
56
|
+
const rg = ripgrepPath()
|
|
57
|
+
d('ripgrep called: %s %o', rg, target, args)
|
|
58
|
+
|
|
59
|
+
// NB: When running interactively, ripgrep does not require a path as its last
|
|
60
|
+
// argument, but when run non-interactively, it will hang unless a path or file
|
|
61
|
+
// pattern is provided
|
|
62
|
+
return new Promise(resolve => {
|
|
63
|
+
execFile(
|
|
64
|
+
ripgrepPath(),
|
|
65
|
+
[...args, target],
|
|
66
|
+
{
|
|
67
|
+
maxBuffer: 1_000_000,
|
|
68
|
+
signal: abortSignal,
|
|
69
|
+
timeout: 10_000,
|
|
70
|
+
},
|
|
71
|
+
(error, stdout) => {
|
|
72
|
+
if (error) {
|
|
73
|
+
// Exit code 1 from ripgrep means "no matches found" - this is normal
|
|
74
|
+
if (error.code !== 1) {
|
|
75
|
+
d('ripgrep error: %o', error)
|
|
76
|
+
logError(error)
|
|
77
|
+
}
|
|
78
|
+
resolve([])
|
|
79
|
+
} else {
|
|
80
|
+
d('ripgrep succeeded with %s', stdout)
|
|
81
|
+
resolve(stdout.trim().split('\n').filter(Boolean))
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// NB: We do something tricky here. We know that ripgrep processes common
|
|
89
|
+
// ignore files for us, so we just ripgrep for any character, which matches
|
|
90
|
+
// all non-empty files
|
|
91
|
+
export async function listAllContentFiles(
|
|
92
|
+
path: string,
|
|
93
|
+
abortSignal: AbortSignal,
|
|
94
|
+
limit: number,
|
|
95
|
+
): Promise<string[]> {
|
|
96
|
+
try {
|
|
97
|
+
d('listAllContentFiles called: %s', path)
|
|
98
|
+
return (await ripGrep(['-l', '.', path], path, abortSignal)).slice(0, limit)
|
|
99
|
+
} catch (e) {
|
|
100
|
+
d('listAllContentFiles failed: %o', e)
|
|
101
|
+
|
|
102
|
+
logError(e)
|
|
103
|
+
return []
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let alreadyDoneSignCheck = false
|
|
108
|
+
async function codesignRipgrepIfNecessary() {
|
|
109
|
+
if (process.platform !== 'darwin' || alreadyDoneSignCheck) {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
alreadyDoneSignCheck = true
|
|
114
|
+
|
|
115
|
+
// First, check to see if ripgrep is already signed
|
|
116
|
+
d('checking if ripgrep is already signed')
|
|
117
|
+
const lines = (
|
|
118
|
+
await execFileNoThrow(
|
|
119
|
+
'codesign',
|
|
120
|
+
['-vv', '-d', ripgrepPath()],
|
|
121
|
+
undefined,
|
|
122
|
+
undefined,
|
|
123
|
+
false,
|
|
124
|
+
)
|
|
125
|
+
).stdout.split('\n')
|
|
126
|
+
|
|
127
|
+
const needsSigned = lines.find(line => line.includes('linker-signed'))
|
|
128
|
+
if (!needsSigned) {
|
|
129
|
+
d('seems to be already signed')
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
d('signing ripgrep')
|
|
135
|
+
const signResult = await execFileNoThrow('codesign', [
|
|
136
|
+
'--sign',
|
|
137
|
+
'-',
|
|
138
|
+
'--force',
|
|
139
|
+
'--preserve-metadata=entitlements,requirements,flags,runtime',
|
|
140
|
+
ripgrepPath(),
|
|
141
|
+
])
|
|
142
|
+
|
|
143
|
+
if (signResult.code !== 0) {
|
|
144
|
+
d('failed to sign ripgrep: %o', signResult)
|
|
145
|
+
logError(
|
|
146
|
+
`Failed to sign ripgrep: ${signResult.stdout} ${signResult.stderr}`,
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
d('removing quarantine')
|
|
151
|
+
const quarantineResult = await execFileNoThrow('xattr', [
|
|
152
|
+
'-d',
|
|
153
|
+
'com.apple.quarantine',
|
|
154
|
+
ripgrepPath(),
|
|
155
|
+
])
|
|
156
|
+
|
|
157
|
+
if (quarantineResult.code !== 0) {
|
|
158
|
+
d('failed to remove quarantine: %o', quarantineResult)
|
|
159
|
+
logError(
|
|
160
|
+
`Failed to remove quarantine: ${quarantineResult.stdout} ${quarantineResult.stderr}`,
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
} catch (e) {
|
|
164
|
+
d('failed during sign: %o', e)
|
|
165
|
+
logError(e)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { logEvent } from '../services/statsig'
|
|
2
|
+
type SessionState = {
|
|
3
|
+
modelErrors: Record<string, unknown>
|
|
4
|
+
currentError: string | null
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const isDebug =
|
|
8
|
+
process.argv.includes('--debug') ||
|
|
9
|
+
process.argv.includes('-d') ||
|
|
10
|
+
process.env.DEBUG === 'true'
|
|
11
|
+
|
|
12
|
+
const sessionState: SessionState = {
|
|
13
|
+
modelErrors: {},
|
|
14
|
+
currentError: null,
|
|
15
|
+
} as const
|
|
16
|
+
|
|
17
|
+
function setSessionState<K extends keyof SessionState>(
|
|
18
|
+
key: K,
|
|
19
|
+
value: SessionState[K],
|
|
20
|
+
): void
|
|
21
|
+
function setSessionState(partialState: Partial<SessionState>): void
|
|
22
|
+
function setSessionState(
|
|
23
|
+
keyOrState: keyof SessionState | Partial<SessionState>,
|
|
24
|
+
value?: any,
|
|
25
|
+
): void {
|
|
26
|
+
if (typeof keyOrState === 'string') {
|
|
27
|
+
logEvent('session_state_set', {
|
|
28
|
+
key: keyOrState,
|
|
29
|
+
value: JSON.stringify(value),
|
|
30
|
+
})
|
|
31
|
+
sessionState[keyOrState] = value
|
|
32
|
+
} else {
|
|
33
|
+
logEvent('session_state_set', {
|
|
34
|
+
key: 'partial',
|
|
35
|
+
value: JSON.stringify(keyOrState),
|
|
36
|
+
})
|
|
37
|
+
Object.assign(sessionState, keyOrState)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getSessionState(): SessionState
|
|
42
|
+
function getSessionState<K extends keyof SessionState>(key: K): SessionState[K]
|
|
43
|
+
function getSessionState<K extends keyof SessionState>(key?: K) {
|
|
44
|
+
return key === undefined ? sessionState : sessionState[key]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type { SessionState }
|
|
48
|
+
export { setSessionState, getSessionState }
|
|
49
|
+
export default sessionState
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { cwd } from 'process'
|
|
2
|
+
import { PersistentShell } from './PersistentShell'
|
|
3
|
+
|
|
4
|
+
// DO NOT ADD MORE STATE HERE OR BORIS WILL CURSE YOU
|
|
5
|
+
const STATE: {
|
|
6
|
+
originalCwd: string
|
|
7
|
+
} = {
|
|
8
|
+
originalCwd: cwd(),
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function setCwd(cwd: string): Promise<void> {
|
|
12
|
+
await PersistentShell.getInstance().setCwd(cwd)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function setOriginalCwd(cwd: string): void {
|
|
16
|
+
STATE.originalCwd = cwd
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getOriginalCwd(): string {
|
|
20
|
+
return STATE.originalCwd
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getCwd(): string {
|
|
24
|
+
return PersistentShell.getInstance().pwd()
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'fs'
|
|
2
|
+
import { join, parse, dirname } from 'path'
|
|
3
|
+
import { memoize } from 'lodash-es'
|
|
4
|
+
import { getCwd } from './state'
|
|
5
|
+
import { PROJECT_FILE } from '../constants/product'
|
|
6
|
+
|
|
7
|
+
const STYLE_PROMPT =
|
|
8
|
+
'The codebase follows strict style guidelines shown below. All code changes must strictly adhere to these guidelines to maintain consistency and quality.'
|
|
9
|
+
|
|
10
|
+
export const getCodeStyle = memoize((): string => {
|
|
11
|
+
const styles: string[] = []
|
|
12
|
+
let currentDir = getCwd()
|
|
13
|
+
|
|
14
|
+
while (currentDir !== parse(currentDir).root) {
|
|
15
|
+
const stylePath = join(currentDir, PROJECT_FILE)
|
|
16
|
+
if (existsSync(stylePath)) {
|
|
17
|
+
styles.push(
|
|
18
|
+
`Contents of ${stylePath}:\n\n${readFileSync(stylePath, 'utf-8')}`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
currentDir = dirname(currentDir)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (styles.length === 0) {
|
|
25
|
+
return ''
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return `${STYLE_PROMPT}\n\n${styles.reverse().join('\n\n')}`
|
|
29
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { safeParseJSON } from './json'
|
|
2
|
+
import { logError } from './log'
|
|
3
|
+
|
|
4
|
+
export function setTerminalTitle(title: string): void {
|
|
5
|
+
if (process.platform === 'win32') {
|
|
6
|
+
process.title = title ? `✳ ${title}` : title
|
|
7
|
+
} else {
|
|
8
|
+
process.stdout.write(`\x1b]0;${title ? `✳ ${title}` : ''}\x07`)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function updateTerminalTitle(message: string): Promise<void> {
|
|
13
|
+
try {
|
|
14
|
+
const result = await queryQuick({
|
|
15
|
+
systemPrompt: [
|
|
16
|
+
"Analyze if this message indicates a new conversation topic. If it does, extract a 2-3 word title that captures the new topic. Format your response as a JSON object with two fields: 'isNewTopic' (boolean) and 'title' (string, or null if isNewTopic is false). Only include these fields, no other text.",
|
|
17
|
+
],
|
|
18
|
+
userPrompt: message,
|
|
19
|
+
enablePromptCaching: true,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const content = result.message.content
|
|
23
|
+
.filter(_ => _.type === 'text')
|
|
24
|
+
.map(_ => _.text)
|
|
25
|
+
.join('')
|
|
26
|
+
|
|
27
|
+
const response = safeParseJSON(content)
|
|
28
|
+
if (
|
|
29
|
+
response &&
|
|
30
|
+
typeof response === 'object' &&
|
|
31
|
+
'isNewTopic' in response &&
|
|
32
|
+
'title' in response
|
|
33
|
+
) {
|
|
34
|
+
if (response.isNewTopic && response.title) {
|
|
35
|
+
setTerminalTitle(response.title as string)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
logError(error)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function clearTerminal(): Promise<void> {
|
|
44
|
+
return new Promise(resolve => {
|
|
45
|
+
process.stdout.write('\x1b[2J\x1b[3J\x1b[H', () => {
|
|
46
|
+
resolve()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { getGlobalConfig } from './config'
|
|
2
|
+
|
|
3
|
+
export interface Theme {
|
|
4
|
+
bashBorder: string
|
|
5
|
+
claude: string
|
|
6
|
+
koding: string
|
|
7
|
+
permission: string
|
|
8
|
+
secondaryBorder: string
|
|
9
|
+
text: string
|
|
10
|
+
secondaryText: string
|
|
11
|
+
suggestion: string
|
|
12
|
+
// Semantic colors
|
|
13
|
+
success: string
|
|
14
|
+
error: string
|
|
15
|
+
warning: string
|
|
16
|
+
diff: {
|
|
17
|
+
added: string
|
|
18
|
+
removed: string
|
|
19
|
+
addedDimmed: string
|
|
20
|
+
removedDimmed: string
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const lightTheme: Theme = {
|
|
25
|
+
bashBorder: '#ff0087',
|
|
26
|
+
claude: '#7aff59ff',
|
|
27
|
+
koding: '#9dff00ff',
|
|
28
|
+
permission: '#e9c61aff',
|
|
29
|
+
secondaryBorder: '#999',
|
|
30
|
+
text: '#000',
|
|
31
|
+
secondaryText: '#666',
|
|
32
|
+
suggestion: '#32e98aff',
|
|
33
|
+
success: '#2c7a39',
|
|
34
|
+
error: '#ab2b3f',
|
|
35
|
+
warning: '#966c1e',
|
|
36
|
+
diff: {
|
|
37
|
+
added: '#69db7c',
|
|
38
|
+
removed: '#ffa8b4',
|
|
39
|
+
addedDimmed: '#c7e1cb',
|
|
40
|
+
removedDimmed: '#fdd2d8',
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const lightDaltonizedTheme: Theme = {
|
|
45
|
+
bashBorder: '#0066cc', // Blue instead of pink for better contrast
|
|
46
|
+
claude: '#5f97cd', // Orange adjusted for deuteranopia
|
|
47
|
+
koding: '#0000ff',
|
|
48
|
+
permission: '#3366ff', // Brighter blue for better visibility
|
|
49
|
+
secondaryBorder: '#999',
|
|
50
|
+
text: '#000',
|
|
51
|
+
secondaryText: '#666',
|
|
52
|
+
suggestion: '#3366ff',
|
|
53
|
+
success: '#006699', // Blue instead of green
|
|
54
|
+
error: '#cc0000', // Pure red for better distinction
|
|
55
|
+
warning: '#ff9900', // Orange adjusted for deuteranopia
|
|
56
|
+
diff: {
|
|
57
|
+
added: '#99ccff', // Light blue instead of green
|
|
58
|
+
removed: '#ffcccc', // Light red for better contrast
|
|
59
|
+
addedDimmed: '#d1e7fd',
|
|
60
|
+
removedDimmed: '#ffe9e9',
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const darkTheme: Theme = {
|
|
65
|
+
bashBorder: '#fd5db1',
|
|
66
|
+
claude: '#5f97cd',
|
|
67
|
+
koding: '#0000ff',
|
|
68
|
+
permission: '#b1b9f9',
|
|
69
|
+
secondaryBorder: '#888',
|
|
70
|
+
text: '#fff',
|
|
71
|
+
secondaryText: '#999',
|
|
72
|
+
suggestion: '#b1b9f9',
|
|
73
|
+
success: '#4eba65',
|
|
74
|
+
error: '#ff6b80',
|
|
75
|
+
warning: '#ffc107',
|
|
76
|
+
diff: {
|
|
77
|
+
added: '#225c2b',
|
|
78
|
+
removed: '#7a2936',
|
|
79
|
+
addedDimmed: '#47584a',
|
|
80
|
+
removedDimmed: '#69484d',
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const darkDaltonizedTheme: Theme = {
|
|
85
|
+
bashBorder: '#3399ff', // Bright blue instead of pink
|
|
86
|
+
claude: '#5f97cd', // Orange adjusted for deuteranopia
|
|
87
|
+
koding: '#0000ff',
|
|
88
|
+
permission: '#99ccff', // Light blue for better contrast
|
|
89
|
+
secondaryBorder: '#888',
|
|
90
|
+
text: '#fff',
|
|
91
|
+
secondaryText: '#999',
|
|
92
|
+
suggestion: '#99ccff',
|
|
93
|
+
success: '#3399ff', // Bright blue instead of green
|
|
94
|
+
error: '#ff6666', // Bright red for better visibility
|
|
95
|
+
warning: '#ffcc00', // Yellow-orange for deuteranopia
|
|
96
|
+
diff: {
|
|
97
|
+
added: '#004466', // Dark blue instead of green
|
|
98
|
+
removed: '#660000', // Dark red for better contrast
|
|
99
|
+
addedDimmed: '#3e515b',
|
|
100
|
+
removedDimmed: '#3e2c2c',
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type ThemeNames =
|
|
105
|
+
| 'dark'
|
|
106
|
+
| 'light'
|
|
107
|
+
| 'light-daltonized'
|
|
108
|
+
| 'dark-daltonized'
|
|
109
|
+
|
|
110
|
+
export function getTheme(overrideTheme?: ThemeNames): Theme {
|
|
111
|
+
const config = getGlobalConfig()
|
|
112
|
+
switch (overrideTheme ?? config.theme) {
|
|
113
|
+
case 'light':
|
|
114
|
+
return lightTheme
|
|
115
|
+
case 'light-daltonized':
|
|
116
|
+
return lightDaltonizedTheme
|
|
117
|
+
case 'dark-daltonized':
|
|
118
|
+
return darkDaltonizedTheme
|
|
119
|
+
default:
|
|
120
|
+
return darkTheme
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { last } from 'lodash-es'
|
|
2
|
+
import type { Message } from '../query'
|
|
3
|
+
import { logEvent } from '../services/statsig'
|
|
4
|
+
import { getLastAssistantMessageId } from './messages'
|
|
5
|
+
import { ThinkTool } from '../tools/ThinkTool/ThinkTool'
|
|
6
|
+
import { USE_BEDROCK, USE_VERTEX, getModelManager } from './model'
|
|
7
|
+
import { getGlobalConfig } from './config'
|
|
8
|
+
|
|
9
|
+
export async function getMaxThinkingTokens(
|
|
10
|
+
messages: Message[],
|
|
11
|
+
): Promise<number> {
|
|
12
|
+
if (process.env.MAX_THINKING_TOKENS) {
|
|
13
|
+
const tokens = parseInt(process.env.MAX_THINKING_TOKENS, 10)
|
|
14
|
+
logEvent('tengu_thinking', {
|
|
15
|
+
method: 'scratchpad',
|
|
16
|
+
tokenCount: tokens.toString(),
|
|
17
|
+
messageId: getLastAssistantMessageId(messages),
|
|
18
|
+
provider: USE_BEDROCK ? 'bedrock' : USE_VERTEX ? 'vertex' : '1p',
|
|
19
|
+
})
|
|
20
|
+
return tokens
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (await ThinkTool.isEnabled()) {
|
|
24
|
+
logEvent('tengu_thinking', {
|
|
25
|
+
method: 'scratchpad',
|
|
26
|
+
tokenCount: '0',
|
|
27
|
+
messageId: getLastAssistantMessageId(messages),
|
|
28
|
+
provider: USE_BEDROCK ? 'bedrock' : USE_VERTEX ? 'vertex' : '1p',
|
|
29
|
+
})
|
|
30
|
+
return 0
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const lastMessage = last(messages)
|
|
34
|
+
if (
|
|
35
|
+
lastMessage?.type !== 'user' ||
|
|
36
|
+
typeof lastMessage.message.content !== 'string'
|
|
37
|
+
) {
|
|
38
|
+
logEvent('tengu_thinking', {
|
|
39
|
+
method: 'scratchpad',
|
|
40
|
+
tokenCount: '0',
|
|
41
|
+
messageId: getLastAssistantMessageId(messages),
|
|
42
|
+
provider: USE_BEDROCK ? 'bedrock' : USE_VERTEX ? 'vertex' : '1p',
|
|
43
|
+
})
|
|
44
|
+
return 0
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const content = lastMessage.message.content.toLowerCase()
|
|
48
|
+
if (
|
|
49
|
+
content.includes('think harder') ||
|
|
50
|
+
content.includes('think intensely') ||
|
|
51
|
+
content.includes('think longer') ||
|
|
52
|
+
content.includes('think really hard') ||
|
|
53
|
+
content.includes('think super hard') ||
|
|
54
|
+
content.includes('think very hard') ||
|
|
55
|
+
content.includes('ultrathink')
|
|
56
|
+
) {
|
|
57
|
+
logEvent('tengu_thinking', {
|
|
58
|
+
method: 'scratchpad',
|
|
59
|
+
tokenCount: '31999',
|
|
60
|
+
messageId: getLastAssistantMessageId(messages),
|
|
61
|
+
provider: USE_BEDROCK ? 'bedrock' : USE_VERTEX ? 'vertex' : '1p',
|
|
62
|
+
})
|
|
63
|
+
return 32_000 - 1
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
content.includes('think about it') ||
|
|
68
|
+
content.includes('think a lot') ||
|
|
69
|
+
content.includes('think hard') ||
|
|
70
|
+
content.includes('think more') ||
|
|
71
|
+
content.includes('megathink')
|
|
72
|
+
) {
|
|
73
|
+
logEvent('tengu_thinking', {
|
|
74
|
+
method: 'scratchpad',
|
|
75
|
+
tokenCount: '10000',
|
|
76
|
+
messageId: getLastAssistantMessageId(messages),
|
|
77
|
+
provider: USE_BEDROCK ? 'bedrock' : USE_VERTEX ? 'vertex' : '1p',
|
|
78
|
+
})
|
|
79
|
+
return 10_000
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (content.includes('think')) {
|
|
83
|
+
logEvent('tengu_thinking', {
|
|
84
|
+
method: 'scratchpad',
|
|
85
|
+
tokenCount: '4000',
|
|
86
|
+
messageId: getLastAssistantMessageId(messages),
|
|
87
|
+
provider: USE_BEDROCK ? 'bedrock' : USE_VERTEX ? 'vertex' : '1p',
|
|
88
|
+
})
|
|
89
|
+
return 4_000
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
logEvent('tengu_thinking', {
|
|
93
|
+
method: 'scratchpad',
|
|
94
|
+
tokenCount: '0',
|
|
95
|
+
messageId: getLastAssistantMessageId(messages),
|
|
96
|
+
provider: USE_BEDROCK ? 'bedrock' : USE_VERTEX ? 'vertex' : '1p',
|
|
97
|
+
})
|
|
98
|
+
return 0
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function getReasoningEffort(
|
|
102
|
+
modelProfile: any,
|
|
103
|
+
messages: Message[],
|
|
104
|
+
): Promise<'low' | 'medium' | 'high' | null> {
|
|
105
|
+
const thinkingTokens = await getMaxThinkingTokens(messages)
|
|
106
|
+
|
|
107
|
+
// Get reasoning effort from ModelProfile first, then fallback to config
|
|
108
|
+
let reasoningEffort: 'low' | 'medium' | 'high' | undefined
|
|
109
|
+
if (modelProfile?.reasoningEffort) {
|
|
110
|
+
reasoningEffort = modelProfile.reasoningEffort
|
|
111
|
+
} else {
|
|
112
|
+
// 🔧 Fix: Use ModelManager fallback instead of legacy config
|
|
113
|
+
const modelManager = getModelManager()
|
|
114
|
+
const fallbackProfile = modelManager.getModel('main')
|
|
115
|
+
reasoningEffort = fallbackProfile?.reasoningEffort || 'medium'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const maxEffort =
|
|
119
|
+
reasoningEffort === 'high'
|
|
120
|
+
? 2
|
|
121
|
+
: reasoningEffort === 'medium'
|
|
122
|
+
? 1
|
|
123
|
+
: reasoningEffort === 'low'
|
|
124
|
+
? 0
|
|
125
|
+
: null
|
|
126
|
+
if (!maxEffort) {
|
|
127
|
+
return null
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let effort = 0
|
|
131
|
+
if (thinkingTokens < 10_000) {
|
|
132
|
+
effort = 0
|
|
133
|
+
} else if (thinkingTokens >= 10_000 && thinkingTokens < 30_000) {
|
|
134
|
+
effort = 1
|
|
135
|
+
} else {
|
|
136
|
+
effort = 2
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (effort > maxEffort) {
|
|
140
|
+
return maxEffort === 2 ? 'high' : maxEffort === 1 ? 'medium' : 'low'
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return effort === 2 ? 'high' : effort === 1 ? 'medium' : 'low'
|
|
144
|
+
}
|