wave-code 1.0.9 → 1.1.0
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/bin/wave-code.js +8 -2
- package/dist/bundle/wave.mjs +3207 -0
- package/package.json +24 -25
- package/src/commands/update.ts +2 -7
- package/src/components/App.tsx +3 -7
- package/src/components/BtwDisplay.tsx +10 -1
- package/src/components/ChatInterface.tsx +21 -52
- package/src/components/ConfirmationDetails.tsx +144 -37
- package/src/components/DiffDisplay.tsx +335 -301
- package/src/components/InputBox.tsx +3 -1
- package/src/components/LoadingIndicator.tsx +16 -2
- package/src/components/MessageBlockItem.tsx +2 -4
- package/src/components/MessageList.tsx +75 -14
- package/src/components/ReasoningDisplay.tsx +2 -4
- package/src/components/SessionSelector.tsx +82 -11
- package/src/components/StatusCommand.tsx +2 -9
- package/src/components/ToolDisplay.tsx +2 -4
- package/src/contexts/useChat.tsx +172 -350
- package/src/daemon/commands.ts +57 -27
- package/src/daemon/jsonRpcClient.ts +1 -1
- package/src/daemon/socketClient.ts +2 -2
- package/src/hooks/useInputManager.ts +1 -1
- package/src/index.ts +57 -10
- package/src/managers/inputReducer.ts +186 -104
- package/src/print-cli.ts +21 -17
- package/src/reducers/selectorReducer.ts +10 -0
- package/src/session-selector-cli.tsx +269 -28
- package/src/stdio/agentBridge.ts +22 -21
- package/src/stdio/daemonServer.ts +3 -1
- package/src/stdio/jsonRpcConnection.ts +19 -1
- package/src/stdio/stdioServer.ts +17 -0
- package/src/utils/clipboard.ts +21 -0
- package/src/utils/highlightUtils.ts +46 -1
- package/src/utils/readPackageJson.ts +29 -0
- package/src/utils/streamingText.ts +11 -0
- package/src/utils/worktree.ts +191 -43
- package/dist/cli.d.ts +0 -6
- package/dist/cli.js +0 -53
- package/dist/commands/plugin/disable.d.ts +0 -5
- package/dist/commands/plugin/disable.js +0 -15
- package/dist/commands/plugin/enable.d.ts +0 -5
- package/dist/commands/plugin/enable.js +0 -15
- package/dist/commands/plugin/install.d.ts +0 -5
- package/dist/commands/plugin/install.js +0 -21
- package/dist/commands/plugin/list.d.ts +0 -1
- package/dist/commands/plugin/list.js +0 -31
- package/dist/commands/plugin/marketplace.d.ts +0 -10
- package/dist/commands/plugin/marketplace.js +0 -90
- package/dist/commands/plugin/uninstall.d.ts +0 -3
- package/dist/commands/plugin/uninstall.js +0 -16
- package/dist/commands/plugin/update.d.ts +0 -3
- package/dist/commands/plugin/update.js +0 -15
- package/dist/commands/update.d.ts +0 -1
- package/dist/commands/update.js +0 -97
- package/dist/components/AgentsManager.d.ts +0 -7
- package/dist/components/AgentsManager.js +0 -109
- package/dist/components/App.d.ts +0 -9
- package/dist/components/App.js +0 -76
- package/dist/components/BackgroundTaskManager.d.ts +0 -5
- package/dist/components/BackgroundTaskManager.js +0 -99
- package/dist/components/BangDisplay.d.ts +0 -8
- package/dist/components/BangDisplay.js +0 -17
- package/dist/components/BtwDisplay.d.ts +0 -7
- package/dist/components/BtwDisplay.js +0 -19
- package/dist/components/ChatInterface.d.ts +0 -2
- package/dist/components/ChatInterface.js +0 -61
- package/dist/components/CommandSelector.d.ts +0 -10
- package/dist/components/CommandSelector.js +0 -66
- package/dist/components/CompactDisplay.d.ts +0 -8
- package/dist/components/CompactDisplay.js +0 -13
- package/dist/components/ConfirmationDetails.d.ts +0 -9
- package/dist/components/ConfirmationDetails.js +0 -45
- package/dist/components/ConfirmationSelector.d.ts +0 -13
- package/dist/components/ConfirmationSelector.js +0 -127
- package/dist/components/DiffDisplay.d.ts +0 -8
- package/dist/components/DiffDisplay.js +0 -201
- package/dist/components/DiscoverView.d.ts +0 -2
- package/dist/components/DiscoverView.js +0 -37
- package/dist/components/FileSelector.d.ts +0 -11
- package/dist/components/FileSelector.js +0 -50
- package/dist/components/HelpView.d.ts +0 -7
- package/dist/components/HelpView.js +0 -74
- package/dist/components/HistorySearch.d.ts +0 -8
- package/dist/components/HistorySearch.js +0 -66
- package/dist/components/InputBox.d.ts +0 -24
- package/dist/components/InputBox.js +0 -149
- package/dist/components/InstalledView.d.ts +0 -2
- package/dist/components/InstalledView.js +0 -45
- package/dist/components/LoadingIndicator.d.ts +0 -10
- package/dist/components/LoadingIndicator.js +0 -6
- package/dist/components/LoginCommand.d.ts +0 -5
- package/dist/components/LoginCommand.js +0 -153
- package/dist/components/Markdown.d.ts +0 -5
- package/dist/components/Markdown.js +0 -127
- package/dist/components/MarketplaceAddForm.d.ts +0 -2
- package/dist/components/MarketplaceAddForm.js +0 -55
- package/dist/components/MarketplaceDetail.d.ts +0 -2
- package/dist/components/MarketplaceDetail.js +0 -74
- package/dist/components/MarketplaceList.d.ts +0 -8
- package/dist/components/MarketplaceList.js +0 -17
- package/dist/components/MarketplaceView.d.ts +0 -2
- package/dist/components/MarketplaceView.js +0 -41
- package/dist/components/McpManager.d.ts +0 -9
- package/dist/components/McpManager.js +0 -88
- package/dist/components/MessageBlockItem.d.ts +0 -8
- package/dist/components/MessageBlockItem.js +0 -15
- package/dist/components/MessageList.d.ts +0 -10
- package/dist/components/MessageList.js +0 -80
- package/dist/components/ModelSelector.d.ts +0 -8
- package/dist/components/ModelSelector.js +0 -45
- package/dist/components/Notifications.d.ts +0 -7
- package/dist/components/Notifications.js +0 -9
- package/dist/components/PlanDisplay.d.ts +0 -7
- package/dist/components/PlanDisplay.js +0 -6
- package/dist/components/PluginDetail.d.ts +0 -2
- package/dist/components/PluginDetail.js +0 -87
- package/dist/components/PluginList.d.ts +0 -13
- package/dist/components/PluginList.js +0 -15
- package/dist/components/PluginManagerShell.d.ts +0 -6
- package/dist/components/PluginManagerShell.js +0 -92
- package/dist/components/PluginManagerTypes.d.ts +0 -35
- package/dist/components/PluginManagerTypes.js +0 -1
- package/dist/components/QueuedMessageList.d.ts +0 -2
- package/dist/components/QueuedMessageList.js +0 -18
- package/dist/components/ReasoningDisplay.d.ts +0 -8
- package/dist/components/ReasoningDisplay.js +0 -13
- package/dist/components/RewindCommand.d.ts +0 -12
- package/dist/components/RewindCommand.js +0 -78
- package/dist/components/SessionSelector.d.ts +0 -12
- package/dist/components/SessionSelector.js +0 -47
- package/dist/components/StatusCommand.d.ts +0 -5
- package/dist/components/StatusCommand.js +0 -28
- package/dist/components/StatusLine.d.ts +0 -6
- package/dist/components/StatusLine.js +0 -9
- package/dist/components/TaskList.d.ts +0 -5
- package/dist/components/TaskList.js +0 -197
- package/dist/components/TaskNotificationMessage.d.ts +0 -5
- package/dist/components/TaskNotificationMessage.js +0 -12
- package/dist/components/ToolDisplay.d.ts +0 -9
- package/dist/components/ToolDisplay.js +0 -55
- package/dist/components/WorkflowManager.d.ts +0 -5
- package/dist/components/WorkflowManager.js +0 -102
- package/dist/components/WorktreeExitPrompt.d.ts +0 -12
- package/dist/components/WorktreeExitPrompt.js +0 -35
- package/dist/constants/commands.d.ts +0 -2
- package/dist/constants/commands.js +0 -92
- package/dist/contexts/PluginManagerContext.d.ts +0 -3
- package/dist/contexts/PluginManagerContext.js +0 -9
- package/dist/contexts/useAppConfig.d.ts +0 -10
- package/dist/contexts/useAppConfig.js +0 -13
- package/dist/contexts/useChat.d.ts +0 -101
- package/dist/contexts/useChat.js +0 -992
- package/dist/contracts/status.d.ts +0 -7
- package/dist/contracts/status.js +0 -1
- package/dist/daemon/commands.d.ts +0 -49
- package/dist/daemon/commands.js +0 -341
- package/dist/daemon/jsonRpcClient.d.ts +0 -38
- package/dist/daemon/jsonRpcClient.js +0 -129
- package/dist/daemon/socketClient.d.ts +0 -13
- package/dist/daemon/socketClient.js +0 -26
- package/dist/daemon-cli.d.ts +0 -10
- package/dist/daemon-cli.js +0 -15
- package/dist/hooks/useInputManager.d.ts +0 -75
- package/dist/hooks/useInputManager.js +0 -583
- package/dist/hooks/usePluginManager.d.ts +0 -4
- package/dist/hooks/usePluginManager.js +0 -265
- package/dist/hooks/useTasks.d.ts +0 -1
- package/dist/hooks/useTasks.js +0 -5
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -447
- package/dist/managers/inputHandlers.d.ts +0 -30
- package/dist/managers/inputHandlers.js +0 -625
- package/dist/managers/inputReducer.d.ts +0 -271
- package/dist/managers/inputReducer.js +0 -1121
- package/dist/plugin-manager-cli.d.ts +0 -5
- package/dist/plugin-manager-cli.js +0 -12
- package/dist/print-cli.d.ts +0 -10
- package/dist/print-cli.js +0 -209
- package/dist/reducers/agentsManagerReducer.d.ts +0 -26
- package/dist/reducers/agentsManagerReducer.js +0 -54
- package/dist/reducers/backgroundTaskManagerReducer.d.ts +0 -62
- package/dist/reducers/backgroundTaskManagerReducer.js +0 -106
- package/dist/reducers/confirmationReducer.d.ts +0 -37
- package/dist/reducers/confirmationReducer.js +0 -193
- package/dist/reducers/helpSelectorReducer.d.ts +0 -25
- package/dist/reducers/helpSelectorReducer.js +0 -52
- package/dist/reducers/marketplaceAddFormReducer.d.ts +0 -24
- package/dist/reducers/marketplaceAddFormReducer.js +0 -58
- package/dist/reducers/mcpManagerReducer.d.ts +0 -37
- package/dist/reducers/mcpManagerReducer.js +0 -74
- package/dist/reducers/pluginDetailReducer.d.ts +0 -32
- package/dist/reducers/pluginDetailReducer.js +0 -70
- package/dist/reducers/questionReducer.d.ts +0 -82
- package/dist/reducers/questionReducer.js +0 -375
- package/dist/reducers/rewindSelectorReducer.d.ts +0 -21
- package/dist/reducers/rewindSelectorReducer.js +0 -37
- package/dist/reducers/selectorReducer.d.ts +0 -23
- package/dist/reducers/selectorReducer.js +0 -42
- package/dist/reducers/workflowManagerReducer.d.ts +0 -40
- package/dist/reducers/workflowManagerReducer.js +0 -100
- package/dist/session-selector-cli.d.ts +0 -3
- package/dist/session-selector-cli.js +0 -25
- package/dist/stdio/agentBridge.d.ts +0 -139
- package/dist/stdio/agentBridge.js +0 -999
- package/dist/stdio/daemonServer.d.ts +0 -67
- package/dist/stdio/daemonServer.js +0 -191
- package/dist/stdio/index.d.ts +0 -5
- package/dist/stdio/index.js +0 -5
- package/dist/stdio/jsonRpcConnection.d.ts +0 -30
- package/dist/stdio/jsonRpcConnection.js +0 -127
- package/dist/stdio/protocol.d.ts +0 -41
- package/dist/stdio/protocol.js +0 -26
- package/dist/stdio/stdioServer.d.ts +0 -28
- package/dist/stdio/stdioServer.js +0 -36
- package/dist/stdio-cli.d.ts +0 -8
- package/dist/stdio-cli.js +0 -15
- package/dist/types.d.ts +0 -20
- package/dist/types.js +0 -1
- package/dist/utils/bracketedPaste.d.ts +0 -39
- package/dist/utils/bracketedPaste.js +0 -122
- package/dist/utils/clipboard.d.ts +0 -21
- package/dist/utils/clipboard.js +0 -347
- package/dist/utils/constants.d.ts +0 -16
- package/dist/utils/constants.js +0 -18
- package/dist/utils/highlightUtils.d.ts +0 -1
- package/dist/utils/highlightUtils.js +0 -93
- package/dist/utils/inputUtils.d.ts +0 -17
- package/dist/utils/inputUtils.js +0 -67
- package/dist/utils/logger.d.ts +0 -71
- package/dist/utils/logger.js +0 -259
- package/dist/utils/markdownTable.d.ts +0 -34
- package/dist/utils/markdownTable.js +0 -302
- package/dist/utils/rewindCheckpoints.d.ts +0 -8
- package/dist/utils/rewindCheckpoints.js +0 -17
- package/dist/utils/throttle.d.ts +0 -14
- package/dist/utils/throttle.js +0 -55
- package/dist/utils/toolParameterTransforms.d.ts +0 -18
- package/dist/utils/toolParameterTransforms.js +0 -73
- package/dist/utils/usageSummary.d.ts +0 -28
- package/dist/utils/usageSummary.js +0 -121
- package/dist/utils/version.d.ts +0 -1
- package/dist/utils/version.js +0 -4
- package/dist/utils/worktree.d.ts +0 -35
- package/dist/utils/worktree.js +0 -219
package/dist/utils/inputUtils.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
export const expandLongTextPlaceholders = (text, longTextMap) => {
|
|
2
|
-
let expandedText = text;
|
|
3
|
-
const longTextRegex = /\[LongText#(\d+)\]/g;
|
|
4
|
-
const matches = [...text.matchAll(longTextRegex)];
|
|
5
|
-
for (const match of matches) {
|
|
6
|
-
const placeholder = match[0];
|
|
7
|
-
const originalText = longTextMap[placeholder];
|
|
8
|
-
if (originalText) {
|
|
9
|
-
expandedText = expandedText.replace(placeholder, originalText);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return expandedText;
|
|
13
|
-
};
|
|
14
|
-
export const getAtSelectorPosition = (text, cursorPosition) => {
|
|
15
|
-
let i = cursorPosition - 1;
|
|
16
|
-
while (i >= 0 && !/\s/.test(text[i])) {
|
|
17
|
-
if (text[i] === "@") {
|
|
18
|
-
if (i === 0 || /\s/.test(text[i - 1])) {
|
|
19
|
-
return i;
|
|
20
|
-
}
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
i--;
|
|
24
|
-
}
|
|
25
|
-
return -1;
|
|
26
|
-
};
|
|
27
|
-
export const getSlashSelectorPosition = (text, cursorPosition) => {
|
|
28
|
-
let i = cursorPosition - 1;
|
|
29
|
-
while (i >= 0 && !/\s/.test(text[i])) {
|
|
30
|
-
if (text[i] === "/") {
|
|
31
|
-
if (i === 0 || /\s/.test(text[i - 1])) {
|
|
32
|
-
return i;
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
i--;
|
|
37
|
-
}
|
|
38
|
-
return -1;
|
|
39
|
-
};
|
|
40
|
-
export const getWordEnd = (text, startPos) => {
|
|
41
|
-
let i = startPos;
|
|
42
|
-
while (i < text.length && !/\s/.test(text[i])) {
|
|
43
|
-
i++;
|
|
44
|
-
}
|
|
45
|
-
return i;
|
|
46
|
-
};
|
|
47
|
-
export const SELECTOR_TRIGGERS = [
|
|
48
|
-
{
|
|
49
|
-
char: "@",
|
|
50
|
-
type: "ACTIVATE_FILE_SELECTOR",
|
|
51
|
-
shouldActivate: (char, pos, text) => char === "@" && (pos === 1 || /\s/.test(text[pos - 2])),
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
char: "/",
|
|
55
|
-
type: "ACTIVATE_COMMAND_SELECTOR",
|
|
56
|
-
shouldActivate: (char, pos, text, showFileSelector) => char === "/" &&
|
|
57
|
-
!showFileSelector &&
|
|
58
|
-
(pos === 1 || /\s/.test(text[pos - 2])),
|
|
59
|
-
},
|
|
60
|
-
];
|
|
61
|
-
export const getProjectedState = (inputText, cursorPosition, char) => {
|
|
62
|
-
const beforeCursor = inputText.substring(0, cursorPosition);
|
|
63
|
-
const afterCursor = inputText.substring(cursorPosition);
|
|
64
|
-
const newInputText = beforeCursor + char + afterCursor;
|
|
65
|
-
const newCursorPosition = cursorPosition + char.length;
|
|
66
|
-
return { newInputText, newCursorPosition };
|
|
67
|
-
};
|
package/dist/utils/logger.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger utility module
|
|
3
|
-
* Supports filtering by log level and keywords
|
|
4
|
-
* Logs are written to files instead of terminal to avoid being cleared by Ink app
|
|
5
|
-
*
|
|
6
|
-
* Performance optimization:
|
|
7
|
-
* - In test environment, you can disable all file and console I/O operations by setting environment variable DISABLE_LOGGER_IO=true
|
|
8
|
-
* - This can significantly improve test execution performance by avoiding unnecessary disk writes
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Log level enumeration
|
|
12
|
-
*/
|
|
13
|
-
export declare enum LogLevel {
|
|
14
|
-
DEBUG = 0,
|
|
15
|
-
INFO = 1,
|
|
16
|
-
WARN = 2,
|
|
17
|
-
ERROR = 3
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Log configuration interface
|
|
21
|
-
*/
|
|
22
|
-
interface LogConfig {
|
|
23
|
-
readonly level: LogLevel;
|
|
24
|
-
readonly keywords: string[];
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Logger object
|
|
28
|
-
*/
|
|
29
|
-
export declare const logger: {
|
|
30
|
-
/**
|
|
31
|
-
* Debug log output function
|
|
32
|
-
*/
|
|
33
|
-
debug: (...args: unknown[]) => void;
|
|
34
|
-
/**
|
|
35
|
-
* Info log output function
|
|
36
|
-
*/
|
|
37
|
-
info: (...args: unknown[]) => void;
|
|
38
|
-
/**
|
|
39
|
-
* Warning log output function
|
|
40
|
-
*/
|
|
41
|
-
warn: (...args: unknown[]) => void;
|
|
42
|
-
/**
|
|
43
|
-
* Error log output function
|
|
44
|
-
*/
|
|
45
|
-
error: (...args: unknown[]) => void;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Get current log configuration
|
|
49
|
-
*/
|
|
50
|
-
export declare const getLogConfig: () => LogConfig;
|
|
51
|
-
/**
|
|
52
|
-
* Get log file path
|
|
53
|
-
*/
|
|
54
|
-
export declare const getLogFile: () => string;
|
|
55
|
-
/**
|
|
56
|
-
* Log cleanup configuration
|
|
57
|
-
*/
|
|
58
|
-
interface LogCleanupConfig {
|
|
59
|
-
/** Maximum size of current log file (bytes), default 10MB */
|
|
60
|
-
maxFileSize: number;
|
|
61
|
-
/** Number of lines to keep when truncating, default 1000 lines */
|
|
62
|
-
keepLines: number;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Execute log cleanup
|
|
66
|
-
* Truncate current log file (if needed)
|
|
67
|
-
*
|
|
68
|
-
* @param customConfig Custom cleanup configuration, if not provided uses default configuration
|
|
69
|
-
*/
|
|
70
|
-
export declare const cleanupLogs: (customConfig?: Partial<LogCleanupConfig>) => Promise<void>;
|
|
71
|
-
export {};
|
package/dist/utils/logger.js
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger utility module
|
|
3
|
-
* Supports filtering by log level and keywords
|
|
4
|
-
* Logs are written to files instead of terminal to avoid being cleared by Ink app
|
|
5
|
-
*
|
|
6
|
-
* Performance optimization:
|
|
7
|
-
* - In test environment, you can disable all file and console I/O operations by setting environment variable DISABLE_LOGGER_IO=true
|
|
8
|
-
* - This can significantly improve test execution performance by avoiding unnecessary disk writes
|
|
9
|
-
*/
|
|
10
|
-
import * as fs from "fs";
|
|
11
|
-
import { Chalk } from "chalk";
|
|
12
|
-
import { getLastLines } from "wave-agent-sdk";
|
|
13
|
-
import { LOG_FILE, DATA_DIRECTORY } from "./constants.js";
|
|
14
|
-
const chalk = new Chalk({ level: 3 });
|
|
15
|
-
const logFile = process.env.LOG_FILE || LOG_FILE;
|
|
16
|
-
/**
|
|
17
|
-
* Log level enumeration
|
|
18
|
-
*/
|
|
19
|
-
export var LogLevel;
|
|
20
|
-
(function (LogLevel) {
|
|
21
|
-
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
22
|
-
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
23
|
-
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
24
|
-
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
25
|
-
})(LogLevel || (LogLevel = {}));
|
|
26
|
-
/**
|
|
27
|
-
* Log level name mapping
|
|
28
|
-
*/
|
|
29
|
-
const LOG_LEVEL_NAMES = {
|
|
30
|
-
[LogLevel.DEBUG]: "DEBUG",
|
|
31
|
-
[LogLevel.INFO]: "INFO",
|
|
32
|
-
[LogLevel.WARN]: "WARN",
|
|
33
|
-
[LogLevel.ERROR]: "ERROR",
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Log level color mapping
|
|
37
|
-
*/
|
|
38
|
-
const LEVEL_COLORS = {
|
|
39
|
-
[LogLevel.DEBUG]: chalk.gray,
|
|
40
|
-
[LogLevel.INFO]: chalk.blue,
|
|
41
|
-
[LogLevel.WARN]: chalk.yellow,
|
|
42
|
-
[LogLevel.ERROR]: chalk.red,
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Parse log level from environment variable
|
|
46
|
-
*/
|
|
47
|
-
const parseLogLevel = (levelStr) => {
|
|
48
|
-
if (!levelStr)
|
|
49
|
-
return LogLevel.INFO;
|
|
50
|
-
const upperLevel = levelStr.toUpperCase();
|
|
51
|
-
switch (upperLevel) {
|
|
52
|
-
case "DEBUG":
|
|
53
|
-
return LogLevel.DEBUG;
|
|
54
|
-
case "INFO":
|
|
55
|
-
return LogLevel.INFO;
|
|
56
|
-
case "WARN":
|
|
57
|
-
return LogLevel.WARN;
|
|
58
|
-
case "ERROR":
|
|
59
|
-
return LogLevel.ERROR;
|
|
60
|
-
default:
|
|
61
|
-
return LogLevel.INFO;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Parse keyword filter from environment variable
|
|
66
|
-
*/
|
|
67
|
-
const parseKeywords = (keywordsStr) => {
|
|
68
|
-
if (!keywordsStr)
|
|
69
|
-
return [];
|
|
70
|
-
return keywordsStr
|
|
71
|
-
.split(",")
|
|
72
|
-
.map((k) => k.trim().toLowerCase())
|
|
73
|
-
.filter((k) => k.length > 0);
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Load log configuration from environment variables
|
|
77
|
-
*
|
|
78
|
-
* Supported environment variables:
|
|
79
|
-
* - LOG_LEVEL: Log level (DEBUG, INFO, WARN, ERROR), default INFO
|
|
80
|
-
* - LOG_KEYWORDS: Keyword filter, comma-separated, default no filter
|
|
81
|
-
*/
|
|
82
|
-
const logConfig = {
|
|
83
|
-
level: parseLogLevel(process.env.LOG_LEVEL),
|
|
84
|
-
keywords: parseKeywords(process.env.LOG_KEYWORDS),
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Check if log should be recorded
|
|
88
|
-
*/
|
|
89
|
-
const shouldLog = (level, message) => {
|
|
90
|
-
// Check log level
|
|
91
|
-
if (level < logConfig.level) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
// If no keyword filter is set, record all logs that meet the level requirement
|
|
95
|
-
if (logConfig.keywords.length === 0) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
// Check keyword filter
|
|
99
|
-
const lowerMessage = message.toLowerCase();
|
|
100
|
-
return logConfig.keywords.some((keyword) => lowerMessage.includes(keyword));
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Format log arguments
|
|
104
|
-
*/
|
|
105
|
-
const formatArg = (arg) => {
|
|
106
|
-
if (arg === null)
|
|
107
|
-
return "null";
|
|
108
|
-
if (arg === undefined)
|
|
109
|
-
return "undefined";
|
|
110
|
-
let result;
|
|
111
|
-
if (arg instanceof Error) {
|
|
112
|
-
// Special handling for Error objects, display stack or message
|
|
113
|
-
result = arg.stack || arg.message || String(arg);
|
|
114
|
-
}
|
|
115
|
-
else if (typeof arg === "object") {
|
|
116
|
-
try {
|
|
117
|
-
result = JSON.stringify(arg);
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
// If JSON.stringify fails, fallback to String()
|
|
121
|
-
result = String(arg);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
result = String(arg);
|
|
126
|
-
}
|
|
127
|
-
// Ensure no newlines in the result to keep log entries single-line
|
|
128
|
-
return result.replace(/[\n\r]+/g, " ");
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Generic log output function
|
|
132
|
-
*/
|
|
133
|
-
const logMessage = (level, ...args) => {
|
|
134
|
-
const messageText = args.map(formatArg).join(" ");
|
|
135
|
-
// Check if this log should be recorded
|
|
136
|
-
if (!shouldLog(level, messageText)) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
// If logger I/O operations are disabled, return directly to save performance
|
|
140
|
-
if (process.env.DISABLE_LOGGER_IO === "true") {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const levelName = LOG_LEVEL_NAMES[level];
|
|
144
|
-
const timestamp = new Date().toISOString();
|
|
145
|
-
const color = LEVEL_COLORS[level] || ((s) => s);
|
|
146
|
-
const formattedMessage = `[${chalk.gray(timestamp)}] [${color(levelName)}] ${messageText}\n`;
|
|
147
|
-
try {
|
|
148
|
-
// Ensure directory exists
|
|
149
|
-
if (!fs.existsSync(DATA_DIRECTORY)) {
|
|
150
|
-
fs.mkdirSync(DATA_DIRECTORY, { recursive: true });
|
|
151
|
-
}
|
|
152
|
-
// Write log to file
|
|
153
|
-
fs.appendFileSync(logFile, formattedMessage);
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
// If file write fails, fallback to stderr
|
|
157
|
-
process.stderr.write(`[${levelName}] Failed to write to log file: ${error}\n`);
|
|
158
|
-
process.stderr.write(formattedMessage);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Logger object
|
|
163
|
-
*/
|
|
164
|
-
export const logger = {
|
|
165
|
-
/**
|
|
166
|
-
* Debug log output function
|
|
167
|
-
*/
|
|
168
|
-
debug: (...args) => {
|
|
169
|
-
logMessage(LogLevel.DEBUG, ...args);
|
|
170
|
-
},
|
|
171
|
-
/**
|
|
172
|
-
* Info log output function
|
|
173
|
-
*/
|
|
174
|
-
info: (...args) => {
|
|
175
|
-
logMessage(LogLevel.INFO, ...args);
|
|
176
|
-
},
|
|
177
|
-
/**
|
|
178
|
-
* Warning log output function
|
|
179
|
-
*/
|
|
180
|
-
warn: (...args) => {
|
|
181
|
-
logMessage(LogLevel.WARN, ...args);
|
|
182
|
-
},
|
|
183
|
-
/**
|
|
184
|
-
* Error log output function
|
|
185
|
-
*/
|
|
186
|
-
error: (...args) => {
|
|
187
|
-
logMessage(LogLevel.ERROR, ...args);
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* Get current log configuration
|
|
192
|
-
*/
|
|
193
|
-
export const getLogConfig = () => {
|
|
194
|
-
return logConfig;
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Get log file path
|
|
198
|
-
*/
|
|
199
|
-
export const getLogFile = () => {
|
|
200
|
-
return logFile;
|
|
201
|
-
};
|
|
202
|
-
/**
|
|
203
|
-
* Get log cleanup configuration
|
|
204
|
-
* Can override default configuration with environment variables
|
|
205
|
-
*/
|
|
206
|
-
const getCleanupConfig = () => {
|
|
207
|
-
return {
|
|
208
|
-
maxFileSize: parseInt(process.env.LOG_MAX_FILE_SIZE || "10485760", 10), // 10MB
|
|
209
|
-
keepLines: parseInt(process.env.LOG_KEEP_LINES || "1000", 10),
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
/**
|
|
213
|
-
* Truncate current log file if too large
|
|
214
|
-
* Keep the last specified number of lines
|
|
215
|
-
*/
|
|
216
|
-
const truncateLogFileIfNeeded = (config) => {
|
|
217
|
-
// If logger I/O operations are disabled, return directly to save performance
|
|
218
|
-
if (process.env.DISABLE_LOGGER_IO === "true") {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
try {
|
|
222
|
-
if (!fs.existsSync(logFile)) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const stats = fs.statSync(logFile);
|
|
226
|
-
// If file size exceeds limit, truncate file
|
|
227
|
-
if (stats.size > config.maxFileSize) {
|
|
228
|
-
const content = fs.readFileSync(logFile, "utf8");
|
|
229
|
-
const truncatedContent = getLastLines(content, config.keepLines);
|
|
230
|
-
// Write truncated content
|
|
231
|
-
fs.writeFileSync(logFile, truncatedContent);
|
|
232
|
-
// Record truncation operation
|
|
233
|
-
logger.debug(`Log file truncated: file size ${stats.size} exceeded limit ${config.maxFileSize}, kept last ${config.keepLines} lines`);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
logger.warn("Failed to truncate log file:", error);
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
/**
|
|
241
|
-
* Execute log cleanup
|
|
242
|
-
* Truncate current log file (if needed)
|
|
243
|
-
*
|
|
244
|
-
* @param customConfig Custom cleanup configuration, if not provided uses default configuration
|
|
245
|
-
*/
|
|
246
|
-
export const cleanupLogs = async (customConfig) => {
|
|
247
|
-
// If logger I/O operations are disabled, return directly to save performance
|
|
248
|
-
if (process.env.DISABLE_LOGGER_IO === "true") {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const config = { ...getCleanupConfig(), ...customConfig };
|
|
252
|
-
logger.debug("Starting log cleanup...", {
|
|
253
|
-
maxFileSize: config.maxFileSize,
|
|
254
|
-
keepLines: config.keepLines,
|
|
255
|
-
});
|
|
256
|
-
// Truncate current log file (if needed)
|
|
257
|
-
truncateLogFileIfNeeded(config);
|
|
258
|
-
logger.debug("Log cleanup completed");
|
|
259
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Token, Tokens } from "marked";
|
|
2
|
-
export type CellAlign = "left" | "center" | "right" | null;
|
|
3
|
-
/**
|
|
4
|
-
* Wrap text to fit within a given width, returning array of lines.
|
|
5
|
-
* ANSI-aware: preserves styling across line breaks.
|
|
6
|
-
*
|
|
7
|
-
* @param hard - If true, break words that exceed width (needed when columns
|
|
8
|
-
* are narrower than the longest word). Default false.
|
|
9
|
-
*/
|
|
10
|
-
export declare function wrapText(text: string, width: number, options?: {
|
|
11
|
-
hard?: boolean;
|
|
12
|
-
}): string[];
|
|
13
|
-
/**
|
|
14
|
-
* Pad `content` to `targetWidth` according to alignment. `displayWidth` is the
|
|
15
|
-
* visible width of `content` (caller computes this, e.g. via stringWidth on
|
|
16
|
-
* ANSI-stripped text, so ANSI codes in `content` don't affect padding).
|
|
17
|
-
*/
|
|
18
|
-
export declare function padAligned(content: string, displayWidth: number, targetWidth: number, align: CellAlign | undefined): string;
|
|
19
|
-
/**
|
|
20
|
-
* Render a markdown table to a box-drawing ANSI string for the terminal.
|
|
21
|
-
* Handles terminal width by:
|
|
22
|
-
* 1. Calculating minimum column widths based on longest word
|
|
23
|
-
* 2. Distributing available space proportionally
|
|
24
|
-
* 3. Wrapping text within cells (no truncation)
|
|
25
|
-
* 4. Falling back to a vertical key-value format when rows would be too
|
|
26
|
-
* tall or the table still overflows the terminal width
|
|
27
|
-
*
|
|
28
|
-
* @param token - marked table token
|
|
29
|
-
* @param columns - terminal width
|
|
30
|
-
* @param formatInline - formats inline tokens to an ANSI string (the caller
|
|
31
|
-
* binds its marked parser so this module stays
|
|
32
|
-
* parser-agnostic and directly testable)
|
|
33
|
-
*/
|
|
34
|
-
export declare function renderMarkdownTable(token: Tokens.Table, columns: number, formatInline: (tokens: Token[]) => string): string;
|