@shareai-lab/kode 1.1.13 → 1.1.16
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/dist/entrypoints/cli.js +2 -1
- package/dist/entrypoints/cli.js.map +2 -2
- package/dist/index.js +5 -26
- package/dist/package.json +4 -1
- package/package.json +9 -104
- package/dist/test/testAdapters.js +0 -88
- package/dist/test/testAdapters.js.map +0 -1
- package/src/ProjectOnboarding.tsx +0 -198
- package/src/Tool.ts +0 -83
- package/src/commands/agents.tsx +0 -3416
- package/src/commands/approvedTools.ts +0 -53
- package/src/commands/bug.tsx +0 -20
- package/src/commands/clear.ts +0 -43
- package/src/commands/compact.ts +0 -120
- package/src/commands/config.tsx +0 -19
- package/src/commands/cost.ts +0 -18
- package/src/commands/ctx_viz.ts +0 -209
- package/src/commands/doctor.ts +0 -24
- package/src/commands/help.tsx +0 -19
- package/src/commands/init.ts +0 -37
- package/src/commands/listen.ts +0 -42
- package/src/commands/login.tsx +0 -51
- package/src/commands/logout.tsx +0 -40
- package/src/commands/mcp.ts +0 -41
- package/src/commands/model.tsx +0 -40
- package/src/commands/modelstatus.tsx +0 -20
- package/src/commands/onboarding.tsx +0 -34
- package/src/commands/pr_comments.ts +0 -59
- package/src/commands/refreshCommands.ts +0 -54
- package/src/commands/release-notes.ts +0 -34
- package/src/commands/resume.tsx +0 -31
- package/src/commands/review.ts +0 -49
- package/src/commands/terminalSetup.ts +0 -221
- package/src/commands.ts +0 -139
- package/src/components/ApproveApiKey.tsx +0 -93
- package/src/components/AsciiLogo.tsx +0 -13
- package/src/components/AutoUpdater.tsx +0 -148
- package/src/components/Bug.tsx +0 -367
- package/src/components/Config.tsx +0 -293
- package/src/components/ConsoleOAuthFlow.tsx +0 -327
- package/src/components/Cost.tsx +0 -23
- package/src/components/CostThresholdDialog.tsx +0 -46
- package/src/components/CustomSelect/option-map.ts +0 -42
- package/src/components/CustomSelect/select-option.tsx +0 -78
- package/src/components/CustomSelect/select.tsx +0 -152
- package/src/components/CustomSelect/theme.ts +0 -45
- package/src/components/CustomSelect/use-select-state.ts +0 -414
- package/src/components/CustomSelect/use-select.ts +0 -35
- package/src/components/FallbackToolUseRejectedMessage.tsx +0 -15
- package/src/components/FileEditToolUpdatedMessage.tsx +0 -66
- package/src/components/Help.tsx +0 -215
- package/src/components/HighlightedCode.tsx +0 -33
- package/src/components/InvalidConfigDialog.tsx +0 -113
- package/src/components/Link.tsx +0 -32
- package/src/components/LogSelector.tsx +0 -86
- package/src/components/Logo.tsx +0 -170
- package/src/components/MCPServerApprovalDialog.tsx +0 -100
- package/src/components/MCPServerDialogCopy.tsx +0 -25
- package/src/components/MCPServerMultiselectDialog.tsx +0 -109
- package/src/components/Message.tsx +0 -221
- package/src/components/MessageResponse.tsx +0 -15
- package/src/components/MessageSelector.tsx +0 -211
- package/src/components/ModeIndicator.tsx +0 -88
- package/src/components/ModelConfig.tsx +0 -301
- package/src/components/ModelListManager.tsx +0 -227
- package/src/components/ModelSelector.tsx +0 -3387
- package/src/components/ModelStatusDisplay.tsx +0 -230
- package/src/components/Onboarding.tsx +0 -274
- package/src/components/PressEnterToContinue.tsx +0 -11
- package/src/components/PromptInput.tsx +0 -760
- package/src/components/SentryErrorBoundary.ts +0 -39
- package/src/components/Spinner.tsx +0 -129
- package/src/components/StickerRequestForm.tsx +0 -16
- package/src/components/StructuredDiff.tsx +0 -191
- package/src/components/TextInput.tsx +0 -259
- package/src/components/TodoItem.tsx +0 -47
- package/src/components/TokenWarning.tsx +0 -31
- package/src/components/ToolUseLoader.tsx +0 -40
- package/src/components/TrustDialog.tsx +0 -106
- package/src/components/binary-feedback/BinaryFeedback.tsx +0 -63
- package/src/components/binary-feedback/BinaryFeedbackOption.tsx +0 -111
- package/src/components/binary-feedback/BinaryFeedbackView.tsx +0 -172
- package/src/components/binary-feedback/utils.ts +0 -220
- package/src/components/messages/AssistantBashOutputMessage.tsx +0 -22
- package/src/components/messages/AssistantLocalCommandOutputMessage.tsx +0 -49
- package/src/components/messages/AssistantRedactedThinkingMessage.tsx +0 -19
- package/src/components/messages/AssistantTextMessage.tsx +0 -144
- package/src/components/messages/AssistantThinkingMessage.tsx +0 -40
- package/src/components/messages/AssistantToolUseMessage.tsx +0 -132
- package/src/components/messages/TaskProgressMessage.tsx +0 -32
- package/src/components/messages/TaskToolMessage.tsx +0 -58
- package/src/components/messages/UserBashInputMessage.tsx +0 -28
- package/src/components/messages/UserCommandMessage.tsx +0 -30
- package/src/components/messages/UserKodingInputMessage.tsx +0 -28
- package/src/components/messages/UserPromptMessage.tsx +0 -35
- package/src/components/messages/UserTextMessage.tsx +0 -39
- package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.tsx +0 -12
- package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.tsx +0 -36
- package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.tsx +0 -31
- package/src/components/messages/UserToolResultMessage/UserToolResultMessage.tsx +0 -57
- package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.tsx +0 -35
- package/src/components/messages/UserToolResultMessage/utils.tsx +0 -56
- package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.tsx +0 -121
- package/src/components/permissions/FallbackPermissionRequest.tsx +0 -153
- package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +0 -182
- package/src/components/permissions/FileEditPermissionRequest/FileEditToolDiff.tsx +0 -77
- package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +0 -164
- package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +0 -83
- package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +0 -240
- package/src/components/permissions/PermissionRequest.tsx +0 -101
- package/src/components/permissions/PermissionRequestTitle.tsx +0 -69
- package/src/components/permissions/hooks.ts +0 -44
- package/src/components/permissions/toolUseOptions.ts +0 -59
- package/src/components/permissions/utils.ts +0 -23
- package/src/constants/betas.ts +0 -5
- package/src/constants/claude-asterisk-ascii-art.tsx +0 -238
- package/src/constants/figures.ts +0 -4
- package/src/constants/keys.ts +0 -3
- package/src/constants/macros.ts +0 -11
- package/src/constants/modelCapabilities.ts +0 -179
- package/src/constants/models.ts +0 -1025
- package/src/constants/oauth.ts +0 -18
- package/src/constants/product.ts +0 -17
- package/src/constants/prompts.ts +0 -168
- package/src/constants/releaseNotes.ts +0 -7
- package/src/context/PermissionContext.tsx +0 -149
- package/src/context.ts +0 -278
- package/src/cost-tracker.ts +0 -84
- package/src/entrypoints/cli.tsx +0 -1561
- package/src/entrypoints/mcp.ts +0 -175
- package/src/history.ts +0 -25
- package/src/hooks/useApiKeyVerification.ts +0 -59
- package/src/hooks/useArrowKeyHistory.ts +0 -55
- package/src/hooks/useCanUseTool.ts +0 -138
- package/src/hooks/useCancelRequest.ts +0 -39
- package/src/hooks/useDoublePress.ts +0 -41
- package/src/hooks/useExitOnCtrlCD.ts +0 -31
- package/src/hooks/useInterval.ts +0 -25
- package/src/hooks/useLogMessages.ts +0 -16
- package/src/hooks/useLogStartupTime.ts +0 -12
- package/src/hooks/useNotifyAfterTimeout.ts +0 -65
- package/src/hooks/usePermissionRequestLogging.ts +0 -44
- package/src/hooks/useTerminalSize.ts +0 -49
- package/src/hooks/useTextInput.ts +0 -317
- package/src/hooks/useUnifiedCompletion.ts +0 -1405
- package/src/index.ts +0 -34
- package/src/messages.ts +0 -38
- package/src/permissions.ts +0 -268
- package/src/query.ts +0 -720
- package/src/screens/ConfigureNpmPrefix.tsx +0 -197
- package/src/screens/Doctor.tsx +0 -219
- package/src/screens/LogList.tsx +0 -68
- package/src/screens/REPL.tsx +0 -813
- package/src/screens/ResumeConversation.tsx +0 -68
- package/src/services/adapters/base.ts +0 -38
- package/src/services/adapters/chatCompletions.ts +0 -90
- package/src/services/adapters/responsesAPI.ts +0 -170
- package/src/services/browserMocks.ts +0 -66
- package/src/services/claude.ts +0 -2197
- package/src/services/customCommands.ts +0 -704
- package/src/services/fileFreshness.ts +0 -377
- package/src/services/gpt5ConnectionTest.ts +0 -340
- package/src/services/mcpClient.ts +0 -564
- package/src/services/mcpServerApproval.tsx +0 -50
- package/src/services/mentionProcessor.ts +0 -273
- package/src/services/modelAdapterFactory.ts +0 -69
- package/src/services/notifier.ts +0 -40
- package/src/services/oauth.ts +0 -357
- package/src/services/openai.ts +0 -1359
- package/src/services/responseStateManager.ts +0 -90
- package/src/services/sentry.ts +0 -3
- package/src/services/statsig.ts +0 -172
- package/src/services/statsigStorage.ts +0 -86
- package/src/services/systemReminder.ts +0 -507
- package/src/services/vcr.ts +0 -161
- package/src/test/testAdapters.ts +0 -96
- package/src/tools/ArchitectTool/ArchitectTool.tsx +0 -135
- package/src/tools/ArchitectTool/prompt.ts +0 -15
- package/src/tools/AskExpertModelTool/AskExpertModelTool.tsx +0 -576
- package/src/tools/BashTool/BashTool.tsx +0 -243
- package/src/tools/BashTool/BashToolResultMessage.tsx +0 -38
- package/src/tools/BashTool/OutputLine.tsx +0 -49
- package/src/tools/BashTool/prompt.ts +0 -174
- package/src/tools/BashTool/utils.ts +0 -56
- package/src/tools/FileEditTool/FileEditTool.tsx +0 -319
- package/src/tools/FileEditTool/prompt.ts +0 -51
- package/src/tools/FileEditTool/utils.ts +0 -58
- package/src/tools/FileReadTool/FileReadTool.tsx +0 -404
- package/src/tools/FileReadTool/prompt.ts +0 -7
- package/src/tools/FileWriteTool/FileWriteTool.tsx +0 -301
- package/src/tools/FileWriteTool/prompt.ts +0 -10
- package/src/tools/GlobTool/GlobTool.tsx +0 -119
- package/src/tools/GlobTool/prompt.ts +0 -8
- package/src/tools/GrepTool/GrepTool.tsx +0 -147
- package/src/tools/GrepTool/prompt.ts +0 -11
- package/src/tools/MCPTool/MCPTool.tsx +0 -107
- package/src/tools/MCPTool/prompt.ts +0 -3
- package/src/tools/MemoryReadTool/MemoryReadTool.tsx +0 -127
- package/src/tools/MemoryReadTool/prompt.ts +0 -3
- package/src/tools/MemoryWriteTool/MemoryWriteTool.tsx +0 -89
- package/src/tools/MemoryWriteTool/prompt.ts +0 -3
- package/src/tools/MultiEditTool/MultiEditTool.tsx +0 -388
- package/src/tools/MultiEditTool/prompt.ts +0 -45
- package/src/tools/NotebookEditTool/NotebookEditTool.tsx +0 -298
- package/src/tools/NotebookEditTool/prompt.ts +0 -3
- package/src/tools/NotebookReadTool/NotebookReadTool.tsx +0 -258
- package/src/tools/NotebookReadTool/prompt.ts +0 -3
- package/src/tools/StickerRequestTool/StickerRequestTool.tsx +0 -107
- package/src/tools/StickerRequestTool/prompt.ts +0 -19
- package/src/tools/TaskTool/TaskTool.tsx +0 -438
- package/src/tools/TaskTool/constants.ts +0 -1
- package/src/tools/TaskTool/prompt.ts +0 -92
- package/src/tools/ThinkTool/ThinkTool.tsx +0 -54
- package/src/tools/ThinkTool/prompt.ts +0 -12
- package/src/tools/TodoWriteTool/TodoWriteTool.tsx +0 -313
- package/src/tools/TodoWriteTool/prompt.ts +0 -63
- package/src/tools/URLFetcherTool/URLFetcherTool.tsx +0 -178
- package/src/tools/URLFetcherTool/cache.ts +0 -55
- package/src/tools/URLFetcherTool/htmlToMarkdown.ts +0 -55
- package/src/tools/URLFetcherTool/prompt.ts +0 -17
- package/src/tools/WebSearchTool/WebSearchTool.tsx +0 -103
- package/src/tools/WebSearchTool/prompt.ts +0 -13
- package/src/tools/WebSearchTool/searchProviders.ts +0 -66
- package/src/tools/lsTool/lsTool.tsx +0 -272
- package/src/tools/lsTool/prompt.ts +0 -2
- package/src/tools.ts +0 -67
- package/src/types/PermissionMode.ts +0 -120
- package/src/types/RequestContext.ts +0 -72
- package/src/types/common.d.ts +0 -2
- package/src/types/conversation.ts +0 -51
- package/src/types/logs.ts +0 -58
- package/src/types/modelCapabilities.ts +0 -64
- package/src/types/notebook.ts +0 -87
- package/src/utils/Cursor.ts +0 -436
- package/src/utils/PersistentShell.ts +0 -552
- package/src/utils/advancedFuzzyMatcher.ts +0 -290
- package/src/utils/agentLoader.ts +0 -278
- package/src/utils/agentStorage.ts +0 -97
- package/src/utils/array.ts +0 -3
- package/src/utils/ask.tsx +0 -99
- package/src/utils/auth.ts +0 -13
- package/src/utils/autoCompactCore.ts +0 -223
- package/src/utils/autoUpdater.ts +0 -458
- package/src/utils/betas.ts +0 -20
- package/src/utils/browser.ts +0 -14
- package/src/utils/cleanup.ts +0 -72
- package/src/utils/commands.ts +0 -261
- package/src/utils/commonUnixCommands.ts +0 -161
- package/src/utils/config.ts +0 -945
- package/src/utils/conversationRecovery.ts +0 -55
- package/src/utils/debugLogger.ts +0 -1235
- package/src/utils/diff.ts +0 -42
- package/src/utils/env.ts +0 -57
- package/src/utils/errors.ts +0 -21
- package/src/utils/exampleCommands.ts +0 -109
- package/src/utils/execFileNoThrow.ts +0 -51
- package/src/utils/expertChatStorage.ts +0 -136
- package/src/utils/file.ts +0 -405
- package/src/utils/fileRecoveryCore.ts +0 -71
- package/src/utils/format.tsx +0 -44
- package/src/utils/fuzzyMatcher.ts +0 -328
- package/src/utils/generators.ts +0 -62
- package/src/utils/git.ts +0 -92
- package/src/utils/globalLogger.ts +0 -77
- package/src/utils/http.ts +0 -10
- package/src/utils/imagePaste.ts +0 -38
- package/src/utils/json.ts +0 -13
- package/src/utils/log.ts +0 -382
- package/src/utils/markdown.ts +0 -213
- package/src/utils/messageContextManager.ts +0 -294
- package/src/utils/messages.tsx +0 -945
- package/src/utils/model.ts +0 -914
- package/src/utils/permissions/filesystem.ts +0 -127
- package/src/utils/responseState.ts +0 -23
- package/src/utils/ripgrep.ts +0 -167
- package/src/utils/secureFile.ts +0 -564
- package/src/utils/sessionState.ts +0 -49
- package/src/utils/state.ts +0 -25
- package/src/utils/style.ts +0 -29
- package/src/utils/terminal.ts +0 -50
- package/src/utils/theme.ts +0 -127
- package/src/utils/thinking.ts +0 -144
- package/src/utils/todoStorage.ts +0 -431
- package/src/utils/tokens.ts +0 -43
- package/src/utils/toolExecutionController.ts +0 -163
- package/src/utils/unaryLogging.ts +0 -26
- package/src/utils/user.ts +0 -37
- package/src/utils/validate.ts +0 -165
package/src/utils/log.ts
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from 'fs'
|
|
2
|
-
import { dirname, join } from 'path'
|
|
3
|
-
import { writeFileSync, readFileSync } from 'fs'
|
|
4
|
-
import { captureException } from '../services/sentry'
|
|
5
|
-
import { randomUUID } from 'crypto'
|
|
6
|
-
import envPaths from 'env-paths'
|
|
7
|
-
import { promises as fsPromises } from 'fs'
|
|
8
|
-
import type { LogOption, SerializedMessage } from '../types/logs'
|
|
9
|
-
import { MACRO } from '../constants/macros'
|
|
10
|
-
import { PRODUCT_COMMAND } from '../constants/product'
|
|
11
|
-
const IN_MEMORY_ERROR_LOG: Array<{
|
|
12
|
-
error: string
|
|
13
|
-
timestamp: string
|
|
14
|
-
}> = []
|
|
15
|
-
const MAX_IN_MEMORY_ERRORS = 100 // Limit to prevent memory issues
|
|
16
|
-
|
|
17
|
-
export const SESSION_ID = randomUUID()
|
|
18
|
-
|
|
19
|
-
const paths = envPaths(PRODUCT_COMMAND)
|
|
20
|
-
|
|
21
|
-
function getProjectDir(cwd: string): string {
|
|
22
|
-
return cwd.replace(/[^a-zA-Z0-9]/g, '-')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const CACHE_PATHS = {
|
|
26
|
-
errors: () => join(paths.cache, getProjectDir(process.cwd()), 'errors'),
|
|
27
|
-
messages: () => join(paths.cache, getProjectDir(process.cwd()), 'messages'),
|
|
28
|
-
mcpLogs: (serverName: string) =>
|
|
29
|
-
join(paths.cache, getProjectDir(process.cwd()), `mcp-logs-${serverName}`),
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function dateToFilename(date: Date): string {
|
|
33
|
-
return date.toISOString().replace(/[:.]/g, '-')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const DATE = dateToFilename(new Date())
|
|
37
|
-
|
|
38
|
-
function getErrorsPath(): string {
|
|
39
|
-
return join(CACHE_PATHS.errors(), DATE + '.txt')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function getMessagesPath(
|
|
43
|
-
messageLogName: string,
|
|
44
|
-
forkNumber: number,
|
|
45
|
-
sidechainNumber: number,
|
|
46
|
-
): string {
|
|
47
|
-
return join(
|
|
48
|
-
CACHE_PATHS.messages(),
|
|
49
|
-
`${messageLogName}${forkNumber > 0 ? `-${forkNumber}` : ''}${
|
|
50
|
-
sidechainNumber > 0 ? `-sidechain-${sidechainNumber}` : ''
|
|
51
|
-
}.json`,
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function logError(error: unknown): void {
|
|
56
|
-
try {
|
|
57
|
-
if (process.env.NODE_ENV === 'test') {
|
|
58
|
-
console.error(error)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const errorStr =
|
|
62
|
-
error instanceof Error ? error.stack || error.message : String(error)
|
|
63
|
-
|
|
64
|
-
const errorInfo = {
|
|
65
|
-
error: errorStr,
|
|
66
|
-
timestamp: new Date().toISOString(),
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (IN_MEMORY_ERROR_LOG.length >= MAX_IN_MEMORY_ERRORS) {
|
|
70
|
-
IN_MEMORY_ERROR_LOG.shift() // Remove oldest error
|
|
71
|
-
}
|
|
72
|
-
IN_MEMORY_ERROR_LOG.push(errorInfo)
|
|
73
|
-
|
|
74
|
-
appendToLog(getErrorsPath(), {
|
|
75
|
-
error: errorStr,
|
|
76
|
-
})
|
|
77
|
-
} catch {
|
|
78
|
-
// pass
|
|
79
|
-
}
|
|
80
|
-
// Also send to Sentry with session ID, but don't await
|
|
81
|
-
captureException(error)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function getErrorsLog(): object[] {
|
|
85
|
-
return readLog(getErrorsPath())
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function getInMemoryErrors(): object[] {
|
|
89
|
-
return [...IN_MEMORY_ERROR_LOG]
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function readLog(path: string): object[] {
|
|
93
|
-
if (!existsSync(path)) {
|
|
94
|
-
return []
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
return JSON.parse(readFileSync(path, 'utf8'))
|
|
98
|
-
} catch {
|
|
99
|
-
return []
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function appendToLog(path: string, message: object): void {
|
|
104
|
-
if (process.env.USER_TYPE === 'external') {
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const dir = dirname(path)
|
|
109
|
-
if (!existsSync(dir)) {
|
|
110
|
-
mkdirSync(dir, { recursive: true })
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Create messages file with empty array if it doesn't exist
|
|
114
|
-
if (!existsSync(path)) {
|
|
115
|
-
writeFileSync(path, '[]', 'utf8')
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const messages = readLog(path)
|
|
119
|
-
const messageWithTimestamp = {
|
|
120
|
-
...message,
|
|
121
|
-
cwd: process.cwd(),
|
|
122
|
-
userType: process.env.USER_TYPE,
|
|
123
|
-
sessionId: SESSION_ID,
|
|
124
|
-
timestamp: new Date().toISOString(),
|
|
125
|
-
version: MACRO.VERSION,
|
|
126
|
-
}
|
|
127
|
-
messages.push(messageWithTimestamp)
|
|
128
|
-
|
|
129
|
-
writeFileSync(path, JSON.stringify(messages, null, 2), 'utf8')
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function overwriteLog(path: string, messages: object[]): void {
|
|
133
|
-
if (process.env.USER_TYPE === 'external') {
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (!messages.length) {
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const dir = dirname(path)
|
|
142
|
-
if (!existsSync(dir)) {
|
|
143
|
-
mkdirSync(dir, { recursive: true })
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const messagesWithMetadata = messages.map(message => ({
|
|
147
|
-
...message,
|
|
148
|
-
cwd: process.cwd(),
|
|
149
|
-
userType: process.env.USER_TYPE,
|
|
150
|
-
sessionId: SESSION_ID,
|
|
151
|
-
timestamp: new Date().toISOString(),
|
|
152
|
-
version: MACRO.VERSION,
|
|
153
|
-
}))
|
|
154
|
-
|
|
155
|
-
writeFileSync(path, JSON.stringify(messagesWithMetadata, null, 2), 'utf8')
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export async function loadLogList(
|
|
159
|
-
path = CACHE_PATHS.messages(),
|
|
160
|
-
): Promise<LogOption[]> {
|
|
161
|
-
if (!existsSync(path)) {
|
|
162
|
-
logError(`No logs found at ${path}`)
|
|
163
|
-
return []
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const files = await fsPromises.readdir(path)
|
|
167
|
-
const logData = await Promise.all(
|
|
168
|
-
files.map(async (file, i) => {
|
|
169
|
-
const fullPath = join(path, file)
|
|
170
|
-
const content = await fsPromises.readFile(fullPath, 'utf8')
|
|
171
|
-
const messages = JSON.parse(content) as SerializedMessage[]
|
|
172
|
-
const firstMessage = messages[0]
|
|
173
|
-
const lastMessage = messages[messages.length - 1]
|
|
174
|
-
const firstPrompt =
|
|
175
|
-
firstMessage?.type === 'user' &&
|
|
176
|
-
typeof firstMessage?.message?.content === 'string'
|
|
177
|
-
? firstMessage?.message?.content
|
|
178
|
-
: 'No prompt'
|
|
179
|
-
|
|
180
|
-
const { date, forkNumber, sidechainNumber } = parseLogFilename(file)
|
|
181
|
-
return {
|
|
182
|
-
date,
|
|
183
|
-
forkNumber,
|
|
184
|
-
fullPath,
|
|
185
|
-
messages,
|
|
186
|
-
value: i, // hack: overwritten after sorting, right below this
|
|
187
|
-
created: parseISOString(firstMessage?.timestamp || date),
|
|
188
|
-
modified: lastMessage?.timestamp
|
|
189
|
-
? parseISOString(lastMessage.timestamp)
|
|
190
|
-
: parseISOString(date),
|
|
191
|
-
firstPrompt:
|
|
192
|
-
firstPrompt.split('\n')[0]?.slice(0, 50) +
|
|
193
|
-
(firstPrompt.length > 50 ? '…' : '') || 'No prompt',
|
|
194
|
-
messageCount: messages.length,
|
|
195
|
-
sidechainNumber,
|
|
196
|
-
}
|
|
197
|
-
}),
|
|
198
|
-
)
|
|
199
|
-
|
|
200
|
-
return sortLogs(logData.filter(_ => _.messages.length)).map((_, i) => ({
|
|
201
|
-
..._,
|
|
202
|
-
value: i,
|
|
203
|
-
}))
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export function parseLogFilename(filename: string): {
|
|
207
|
-
date: string
|
|
208
|
-
forkNumber: number | undefined
|
|
209
|
-
sidechainNumber: number | undefined
|
|
210
|
-
} {
|
|
211
|
-
const base = filename.split('.')[0]!
|
|
212
|
-
// Default timestamp format has 6 segments: 2025-01-27T01-31-35-104Z
|
|
213
|
-
const segments = base.split('-')
|
|
214
|
-
const hasSidechain = base.includes('-sidechain-')
|
|
215
|
-
|
|
216
|
-
let date = base
|
|
217
|
-
let forkNumber: number | undefined = undefined
|
|
218
|
-
let sidechainNumber: number | undefined = undefined
|
|
219
|
-
|
|
220
|
-
if (hasSidechain) {
|
|
221
|
-
const sidechainIndex = segments.indexOf('sidechain')
|
|
222
|
-
sidechainNumber = Number(segments[sidechainIndex + 1])
|
|
223
|
-
// Fork number is before sidechain if exists
|
|
224
|
-
if (sidechainIndex > 6) {
|
|
225
|
-
forkNumber = Number(segments[sidechainIndex - 1])
|
|
226
|
-
date = segments.slice(0, 6).join('-')
|
|
227
|
-
} else {
|
|
228
|
-
date = segments.slice(0, 6).join('-')
|
|
229
|
-
}
|
|
230
|
-
} else if (segments.length > 6) {
|
|
231
|
-
// Has fork number
|
|
232
|
-
const lastSegment = Number(segments[segments.length - 1])
|
|
233
|
-
forkNumber = lastSegment >= 0 ? lastSegment : undefined
|
|
234
|
-
date = segments.slice(0, 6).join('-')
|
|
235
|
-
} else {
|
|
236
|
-
// Basic timestamp only
|
|
237
|
-
date = base
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return { date, forkNumber, sidechainNumber }
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function getNextAvailableLogForkNumber(
|
|
244
|
-
date: string,
|
|
245
|
-
forkNumber: number,
|
|
246
|
-
// Main chain has sidechainNumber 0
|
|
247
|
-
sidechainNumber: number,
|
|
248
|
-
): number {
|
|
249
|
-
while (existsSync(getMessagesPath(date, forkNumber, sidechainNumber))) {
|
|
250
|
-
forkNumber++
|
|
251
|
-
}
|
|
252
|
-
return forkNumber
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export function getNextAvailableLogSidechainNumber(
|
|
256
|
-
date: string,
|
|
257
|
-
forkNumber: number,
|
|
258
|
-
): number {
|
|
259
|
-
let sidechainNumber = 1
|
|
260
|
-
while (existsSync(getMessagesPath(date, forkNumber, sidechainNumber))) {
|
|
261
|
-
sidechainNumber++
|
|
262
|
-
}
|
|
263
|
-
return sidechainNumber
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export function getForkNumberFromFilename(
|
|
267
|
-
filename: string,
|
|
268
|
-
): number | undefined {
|
|
269
|
-
const base = filename.split('.')[0]!
|
|
270
|
-
const segments = base.split('-')
|
|
271
|
-
const hasSidechain = base.includes('-sidechain-')
|
|
272
|
-
|
|
273
|
-
if (hasSidechain) {
|
|
274
|
-
const sidechainIndex = segments.indexOf('sidechain')
|
|
275
|
-
if (sidechainIndex > 6) {
|
|
276
|
-
return Number(segments[sidechainIndex - 1])
|
|
277
|
-
}
|
|
278
|
-
return undefined
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (segments.length > 6) {
|
|
282
|
-
const lastNumber = Number(segments[segments.length - 1])
|
|
283
|
-
return lastNumber >= 0 ? lastNumber : undefined
|
|
284
|
-
}
|
|
285
|
-
return undefined
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
export function sortLogs(logs: LogOption[]): LogOption[] {
|
|
289
|
-
return logs.sort((a, b) => {
|
|
290
|
-
// Sort by modified date (newest first)
|
|
291
|
-
const modifiedDiff = b.modified.getTime() - a.modified.getTime()
|
|
292
|
-
if (modifiedDiff !== 0) {
|
|
293
|
-
return modifiedDiff
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// If modified dates are equal, sort by created date
|
|
297
|
-
const createdDiff = b.created.getTime() - a.created.getTime()
|
|
298
|
-
if (createdDiff !== 0) {
|
|
299
|
-
return createdDiff
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// If both dates are equal, sort by fork number
|
|
303
|
-
return (b.forkNumber ?? 0) - (a.forkNumber ?? 0)
|
|
304
|
-
})
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export function formatDate(date: Date): string {
|
|
308
|
-
const now = new Date()
|
|
309
|
-
const yesterday = new Date(now)
|
|
310
|
-
yesterday.setDate(yesterday.getDate() - 1)
|
|
311
|
-
|
|
312
|
-
const isToday = date.toDateString() === now.toDateString()
|
|
313
|
-
const isYesterday = date.toDateString() === yesterday.toDateString()
|
|
314
|
-
|
|
315
|
-
const timeStr = date
|
|
316
|
-
.toLocaleTimeString('en-US', {
|
|
317
|
-
hour: 'numeric',
|
|
318
|
-
minute: '2-digit',
|
|
319
|
-
hour12: true,
|
|
320
|
-
})
|
|
321
|
-
.toLowerCase()
|
|
322
|
-
|
|
323
|
-
if (isToday) {
|
|
324
|
-
return `Today at ${timeStr}`
|
|
325
|
-
} else if (isYesterday) {
|
|
326
|
-
return `Yesterday at ${timeStr}`
|
|
327
|
-
} else {
|
|
328
|
-
return (
|
|
329
|
-
date.toLocaleDateString('en-US', {
|
|
330
|
-
month: 'short',
|
|
331
|
-
day: 'numeric',
|
|
332
|
-
}) + ` at ${timeStr}`
|
|
333
|
-
)
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export function parseISOString(s: string): Date {
|
|
338
|
-
const b = s.split(/\D+/)
|
|
339
|
-
return new Date(
|
|
340
|
-
Date.UTC(
|
|
341
|
-
parseInt(b[0]!, 10),
|
|
342
|
-
parseInt(b[1]!, 10) - 1,
|
|
343
|
-
parseInt(b[2]!, 10),
|
|
344
|
-
parseInt(b[3]!, 10),
|
|
345
|
-
parseInt(b[4]!, 10),
|
|
346
|
-
parseInt(b[5]!, 10),
|
|
347
|
-
parseInt(b[6]!, 10),
|
|
348
|
-
),
|
|
349
|
-
)
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
export function logMCPError(serverName: string, error: unknown): void {
|
|
353
|
-
try {
|
|
354
|
-
const logDir = CACHE_PATHS.mcpLogs(serverName)
|
|
355
|
-
const errorStr =
|
|
356
|
-
error instanceof Error ? error.stack || error.message : String(error)
|
|
357
|
-
const timestamp = new Date().toISOString()
|
|
358
|
-
|
|
359
|
-
const logFile = join(logDir, DATE + '.txt')
|
|
360
|
-
|
|
361
|
-
if (!existsSync(logDir)) {
|
|
362
|
-
mkdirSync(logDir, { recursive: true })
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (!existsSync(logFile)) {
|
|
366
|
-
writeFileSync(logFile, '[]', 'utf8')
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const errorInfo = {
|
|
370
|
-
error: errorStr,
|
|
371
|
-
timestamp,
|
|
372
|
-
sessionId: SESSION_ID,
|
|
373
|
-
cwd: process.cwd(),
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
const messages = readLog(logFile)
|
|
377
|
-
messages.push(errorInfo)
|
|
378
|
-
writeFileSync(logFile, JSON.stringify(messages, null, 2), 'utf8')
|
|
379
|
-
} catch {
|
|
380
|
-
// Silently fail
|
|
381
|
-
}
|
|
382
|
-
}
|
package/src/utils/markdown.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { marked, Token } from 'marked'
|
|
2
|
-
import { stripSystemMessages } from './messages'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import { EOL } from 'os'
|
|
5
|
-
import { highlight, supportsLanguage } from 'cli-highlight'
|
|
6
|
-
import { logError } from './log'
|
|
7
|
-
|
|
8
|
-
export function applyMarkdown(content: string): string {
|
|
9
|
-
return marked
|
|
10
|
-
.lexer(stripSystemMessages(content))
|
|
11
|
-
.map(_ => format(_))
|
|
12
|
-
.join('')
|
|
13
|
-
.trim()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function format(
|
|
17
|
-
token: Token,
|
|
18
|
-
listDepth = 0,
|
|
19
|
-
orderedListNumber: number | null = null,
|
|
20
|
-
parent: Token | null = null,
|
|
21
|
-
): string {
|
|
22
|
-
switch (token.type) {
|
|
23
|
-
case 'blockquote':
|
|
24
|
-
return chalk.dim.italic((token.tokens ?? []).map(_ => format(_)).join(''))
|
|
25
|
-
case 'code':
|
|
26
|
-
if (token.lang && supportsLanguage(token.lang)) {
|
|
27
|
-
return highlight(token.text, { language: token.lang }) + EOL
|
|
28
|
-
} else {
|
|
29
|
-
logError(
|
|
30
|
-
`Language not supported while highlighting code, falling back to markdown: ${token.lang}`,
|
|
31
|
-
)
|
|
32
|
-
return highlight(token.text, { language: 'markdown' }) + EOL
|
|
33
|
-
}
|
|
34
|
-
case 'codespan':
|
|
35
|
-
// inline code
|
|
36
|
-
return chalk.blue(token.text)
|
|
37
|
-
case 'em':
|
|
38
|
-
return chalk.italic((token.tokens ?? []).map(_ => format(_)).join(''))
|
|
39
|
-
case 'strong':
|
|
40
|
-
return chalk.bold((token.tokens ?? []).map(_ => format(_)).join(''))
|
|
41
|
-
case 'heading':
|
|
42
|
-
switch (token.depth) {
|
|
43
|
-
case 1: // h1
|
|
44
|
-
return (
|
|
45
|
-
chalk.bold.italic.underline(
|
|
46
|
-
(token.tokens ?? []).map(_ => format(_)).join(''),
|
|
47
|
-
) +
|
|
48
|
-
EOL +
|
|
49
|
-
EOL
|
|
50
|
-
)
|
|
51
|
-
case 2: // h2
|
|
52
|
-
return (
|
|
53
|
-
chalk.bold((token.tokens ?? []).map(_ => format(_)).join('')) +
|
|
54
|
-
EOL +
|
|
55
|
-
EOL
|
|
56
|
-
)
|
|
57
|
-
default: // h3+
|
|
58
|
-
return (
|
|
59
|
-
chalk.bold.dim((token.tokens ?? []).map(_ => format(_)).join('')) +
|
|
60
|
-
EOL +
|
|
61
|
-
EOL
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
case 'hr':
|
|
65
|
-
return '---'
|
|
66
|
-
case 'image':
|
|
67
|
-
return `[Image: ${token.title}: ${token.href}]`
|
|
68
|
-
case 'link':
|
|
69
|
-
return chalk.blue(token.href)
|
|
70
|
-
case 'list': {
|
|
71
|
-
return token.items
|
|
72
|
-
.map((_: Token, index: number) =>
|
|
73
|
-
format(
|
|
74
|
-
_,
|
|
75
|
-
listDepth,
|
|
76
|
-
token.ordered ? token.start + index : null,
|
|
77
|
-
token,
|
|
78
|
-
),
|
|
79
|
-
)
|
|
80
|
-
.join('')
|
|
81
|
-
}
|
|
82
|
-
case 'list_item':
|
|
83
|
-
return (token.tokens ?? [])
|
|
84
|
-
.map(
|
|
85
|
-
_ =>
|
|
86
|
-
`${' '.repeat(listDepth)}${format(_, listDepth + 1, orderedListNumber, token)}`,
|
|
87
|
-
)
|
|
88
|
-
.join('')
|
|
89
|
-
case 'paragraph':
|
|
90
|
-
return (token.tokens ?? []).map(_ => format(_)).join('') + EOL
|
|
91
|
-
case 'space':
|
|
92
|
-
return EOL
|
|
93
|
-
case 'text':
|
|
94
|
-
if (parent?.type === 'list_item') {
|
|
95
|
-
return `${orderedListNumber === null ? '-' : getListNumber(listDepth, orderedListNumber) + '.'} ${token.tokens ? token.tokens.map(_ => format(_, listDepth, orderedListNumber, token)).join('') : token.text}${EOL}`
|
|
96
|
-
} else {
|
|
97
|
-
return token.text
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// TODO: tables
|
|
101
|
-
return ''
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const DEPTH_1_LIST_NUMBERS = [
|
|
105
|
-
'a',
|
|
106
|
-
'b',
|
|
107
|
-
'c',
|
|
108
|
-
'd',
|
|
109
|
-
'e',
|
|
110
|
-
'f',
|
|
111
|
-
'g',
|
|
112
|
-
'h',
|
|
113
|
-
'i',
|
|
114
|
-
'j',
|
|
115
|
-
'k',
|
|
116
|
-
'l',
|
|
117
|
-
'm',
|
|
118
|
-
'n',
|
|
119
|
-
'o',
|
|
120
|
-
'p',
|
|
121
|
-
'q',
|
|
122
|
-
'r',
|
|
123
|
-
's',
|
|
124
|
-
't',
|
|
125
|
-
'u',
|
|
126
|
-
'v',
|
|
127
|
-
'w',
|
|
128
|
-
'x',
|
|
129
|
-
'y',
|
|
130
|
-
'z',
|
|
131
|
-
'aa',
|
|
132
|
-
'ab',
|
|
133
|
-
'ac',
|
|
134
|
-
'ad',
|
|
135
|
-
'ae',
|
|
136
|
-
'af',
|
|
137
|
-
'ag',
|
|
138
|
-
'ah',
|
|
139
|
-
'ai',
|
|
140
|
-
'aj',
|
|
141
|
-
'ak',
|
|
142
|
-
'al',
|
|
143
|
-
'am',
|
|
144
|
-
'an',
|
|
145
|
-
'ao',
|
|
146
|
-
'ap',
|
|
147
|
-
'aq',
|
|
148
|
-
'ar',
|
|
149
|
-
'as',
|
|
150
|
-
'at',
|
|
151
|
-
'au',
|
|
152
|
-
'av',
|
|
153
|
-
'aw',
|
|
154
|
-
'ax',
|
|
155
|
-
'ay',
|
|
156
|
-
'az',
|
|
157
|
-
]
|
|
158
|
-
const DEPTH_2_LIST_NUMBERS = [
|
|
159
|
-
'i',
|
|
160
|
-
'ii',
|
|
161
|
-
'iii',
|
|
162
|
-
'iv',
|
|
163
|
-
'v',
|
|
164
|
-
'vi',
|
|
165
|
-
'vii',
|
|
166
|
-
'viii',
|
|
167
|
-
'ix',
|
|
168
|
-
'x',
|
|
169
|
-
'xi',
|
|
170
|
-
'xii',
|
|
171
|
-
'xiii',
|
|
172
|
-
'xiv',
|
|
173
|
-
'xv',
|
|
174
|
-
'xvi',
|
|
175
|
-
'xvii',
|
|
176
|
-
'xviii',
|
|
177
|
-
'xix',
|
|
178
|
-
'xx',
|
|
179
|
-
'xxi',
|
|
180
|
-
'xxii',
|
|
181
|
-
'xxiii',
|
|
182
|
-
'xxiv',
|
|
183
|
-
'xxv',
|
|
184
|
-
'xxvi',
|
|
185
|
-
'xxvii',
|
|
186
|
-
'xxviii',
|
|
187
|
-
'xxix',
|
|
188
|
-
'xxx',
|
|
189
|
-
'xxxi',
|
|
190
|
-
'xxxii',
|
|
191
|
-
'xxxiii',
|
|
192
|
-
'xxxiv',
|
|
193
|
-
'xxxv',
|
|
194
|
-
'xxxvi',
|
|
195
|
-
'xxxvii',
|
|
196
|
-
'xxxviii',
|
|
197
|
-
'xxxix',
|
|
198
|
-
'xl',
|
|
199
|
-
]
|
|
200
|
-
|
|
201
|
-
function getListNumber(listDepth: number, orderedListNumber: number): string {
|
|
202
|
-
switch (listDepth) {
|
|
203
|
-
case 0:
|
|
204
|
-
case 1:
|
|
205
|
-
return orderedListNumber.toString()
|
|
206
|
-
case 2:
|
|
207
|
-
return DEPTH_1_LIST_NUMBERS[orderedListNumber - 1]! // TODO: don't hard code the list
|
|
208
|
-
case 3:
|
|
209
|
-
return DEPTH_2_LIST_NUMBERS[orderedListNumber - 1]! // TODO: don't hard code the list
|
|
210
|
-
default:
|
|
211
|
-
return orderedListNumber.toString()
|
|
212
|
-
}
|
|
213
|
-
}
|