byterover-cli 2.5.1 → 2.6.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.
Files changed (85) hide show
  1. package/.env.production +7 -0
  2. package/LICENSE +44 -0
  3. package/bin/dev.js +8 -1
  4. package/bin/run.js +8 -1
  5. package/dist/server/config/environment.d.ts +0 -19
  6. package/dist/server/config/environment.js +29 -38
  7. package/dist/server/constants.d.ts +0 -9
  8. package/dist/server/constants.js +0 -12
  9. package/dist/server/core/domain/errors/auth-error.d.ts +0 -6
  10. package/dist/server/core/domain/errors/auth-error.js +0 -12
  11. package/dist/server/core/domain/errors/task-error.d.ts +0 -3
  12. package/dist/server/core/domain/errors/task-error.js +0 -8
  13. package/dist/server/core/domain/errors/transport-error.d.ts +0 -31
  14. package/dist/server/core/domain/errors/transport-error.js +0 -50
  15. package/dist/server/infra/connectors/rules/rules-connector-config.d.ts +0 -4
  16. package/dist/server/infra/http/models-dev-client.d.ts +0 -4
  17. package/dist/server/infra/http/models-dev-client.js +0 -6
  18. package/dist/server/infra/http/openrouter-api-client.d.ts +0 -8
  19. package/dist/server/infra/http/openrouter-api-client.js +0 -13
  20. package/dist/server/infra/http/provider-model-fetcher-registry.d.ts +0 -5
  21. package/dist/server/infra/http/provider-model-fetcher-registry.js +0 -7
  22. package/dist/server/infra/provider/env-provider-detector.d.ts +0 -20
  23. package/dist/server/infra/provider/env-provider-detector.js +0 -27
  24. package/dist/server/infra/storage/file-provider-config-store.d.ts +0 -4
  25. package/dist/server/infra/storage/file-provider-config-store.js +0 -6
  26. package/dist/server/utils/file-content-reader.d.ts +2 -1
  27. package/dist/server/utils/file-helpers.d.ts +0 -24
  28. package/dist/server/utils/file-helpers.js +0 -81
  29. package/dist/server/utils/process-logger.d.ts +0 -13
  30. package/dist/server/utils/process-logger.js +1 -78
  31. package/node_modules/@campfirein/brv-transport-client/LICENSE +95 -0
  32. package/node_modules/@campfirein/brv-transport-client/README.md +3 -4
  33. package/node_modules/@campfirein/brv-transport-client/package.json +2 -2
  34. package/oclif.manifest.json +1 -1
  35. package/package.json +6 -4
  36. package/dist/server/core/domain/entities/bullet.d.ts +0 -51
  37. package/dist/server/core/domain/entities/bullet.js +0 -94
  38. package/dist/server/core/domain/entities/memory.d.ts +0 -55
  39. package/dist/server/core/domain/entities/memory.js +0 -90
  40. package/dist/server/core/domain/entities/playbook.d.ts +0 -80
  41. package/dist/server/core/domain/entities/playbook.js +0 -214
  42. package/dist/server/core/domain/entities/presigned-url.d.ts +0 -9
  43. package/dist/server/core/domain/entities/presigned-url.js +0 -18
  44. package/dist/server/core/domain/entities/presigned-urls-response.d.ts +0 -10
  45. package/dist/server/core/domain/entities/presigned-urls-response.js +0 -18
  46. package/dist/server/core/domain/entities/retrieve-result.d.ts +0 -35
  47. package/dist/server/core/domain/entities/retrieve-result.js +0 -35
  48. package/dist/server/core/domain/errors/headless-prompt-error.d.ts +0 -11
  49. package/dist/server/core/domain/errors/headless-prompt-error.js +0 -18
  50. package/dist/server/core/interfaces/services/i-legacy-rule-detector.d.ts +0 -56
  51. package/dist/server/core/interfaces/services/i-legacy-rule-detector.js +0 -1
  52. package/dist/server/core/interfaces/services/i-memory-retrieval-service.d.ts +0 -39
  53. package/dist/server/core/interfaces/services/i-memory-retrieval-service.js +0 -1
  54. package/dist/server/core/interfaces/services/i-memory-storage-service.d.ts +0 -53
  55. package/dist/server/core/interfaces/services/i-memory-storage-service.js +0 -1
  56. package/dist/server/core/interfaces/services/i-terminal.d.ts +0 -146
  57. package/dist/server/core/interfaces/services/i-terminal.js +0 -1
  58. package/dist/server/core/interfaces/services/i-workspace-detector-service.d.ts +0 -8
  59. package/dist/server/core/interfaces/services/i-workspace-detector-service.js +0 -1
  60. package/dist/server/core/interfaces/storage/i-onboarding-preference-store.d.ts +0 -20
  61. package/dist/server/core/interfaces/storage/i-onboarding-preference-store.js +0 -1
  62. package/dist/server/infra/connectors/rules/legacy-rule-detector.d.ts +0 -21
  63. package/dist/server/infra/connectors/rules/legacy-rule-detector.js +0 -106
  64. package/dist/server/infra/memory/http-memory-retrieval-service.d.ts +0 -18
  65. package/dist/server/infra/memory/http-memory-retrieval-service.js +0 -64
  66. package/dist/server/infra/memory/http-memory-storage-service.d.ts +0 -18
  67. package/dist/server/infra/memory/http-memory-storage-service.js +0 -72
  68. package/dist/server/infra/memory/memory-to-playbook-mapper.d.ts +0 -33
  69. package/dist/server/infra/memory/memory-to-playbook-mapper.js +0 -51
  70. package/dist/server/infra/storage/file-onboarding-preference-store.d.ts +0 -10
  71. package/dist/server/infra/storage/file-onboarding-preference-store.js +0 -45
  72. package/dist/server/infra/terminal/headless-terminal.d.ts +0 -91
  73. package/dist/server/infra/terminal/headless-terminal.js +0 -211
  74. package/dist/server/infra/workspace/workspace-detector-service.d.ts +0 -57
  75. package/dist/server/infra/workspace/workspace-detector-service.js +0 -165
  76. package/dist/server/utils/crash-log.d.ts +0 -14
  77. package/dist/server/utils/crash-log.js +0 -19
  78. package/dist/server/utils/emoji-helpers.d.ts +0 -38
  79. package/dist/server/utils/emoji-helpers.js +0 -42
  80. package/dist/server/utils/error-handler.d.ts +0 -51
  81. package/dist/server/utils/error-handler.js +0 -169
  82. package/dist/server/utils/oclif-error-helpers.d.ts +0 -40
  83. package/dist/server/utils/oclif-error-helpers.js +0 -46
  84. package/dist/server/utils/tool-display-formatter.d.ts +0 -53
  85. package/dist/server/utils/tool-display-formatter.js +0 -257
@@ -1,51 +0,0 @@
1
- /**
2
- * Centralized error handling utility for CLI commands
3
- *
4
- * Provides user-friendly error messages based on error type:
5
- * - Network errors: Check internet connection
6
- * - Server errors: Retry later
7
- * - Billing errors: Check account/payment
8
- * - Auth errors: Re-login required
9
- * - Validation errors: Check input
10
- */
11
- export declare enum ErrorType {
12
- AUTH = "AUTH",
13
- BILLING = "BILLING",
14
- NETWORK = "NETWORK",
15
- SERVER = "SERVER",
16
- UNKNOWN = "UNKNOWN",
17
- VALIDATION = "VALIDATION"
18
- }
19
- export interface ClassifiedError {
20
- message: string;
21
- originalError: Error;
22
- type: ErrorType;
23
- userMessage: string;
24
- }
25
- /**
26
- * Classify error and return user-friendly message
27
- */
28
- export declare function classifyError(error: unknown): ClassifiedError;
29
- /**
30
- * Format error for display to user
31
- *
32
- * @param error - Error to format
33
- * @returns User-friendly error message
34
- */
35
- export declare function formatError(error: unknown): string;
36
- /**
37
- * Check if error is a network error
38
- */
39
- export declare function isNetworkError(error: unknown): boolean;
40
- /**
41
- * Check if error is a server error
42
- */
43
- export declare function isServerError(error: unknown): boolean;
44
- /**
45
- * Check if error is an authentication error
46
- */
47
- export declare function isAuthError(error: unknown): boolean;
48
- /**
49
- * Check if error is a billing error
50
- */
51
- export declare function isBillingError(error: unknown): boolean;
@@ -1,169 +0,0 @@
1
- /**
2
- * Centralized error handling utility for CLI commands
3
- *
4
- * Provides user-friendly error messages based on error type:
5
- * - Network errors: Check internet connection
6
- * - Server errors: Retry later
7
- * - Billing errors: Check account/payment
8
- * - Auth errors: Re-login required
9
- * - Validation errors: Check input
10
- */
11
- import { isAxiosError } from 'axios';
12
- import { addErrorPrefix } from './emoji-helpers.js';
13
- export var ErrorType;
14
- (function (ErrorType) {
15
- ErrorType["AUTH"] = "AUTH";
16
- ErrorType["BILLING"] = "BILLING";
17
- ErrorType["NETWORK"] = "NETWORK";
18
- ErrorType["SERVER"] = "SERVER";
19
- ErrorType["UNKNOWN"] = "UNKNOWN";
20
- ErrorType["VALIDATION"] = "VALIDATION";
21
- })(ErrorType || (ErrorType = {}));
22
- /**
23
- * Helper to create a ClassifiedError object
24
- */
25
- function createClassifiedError(err, type, userMessage, customMessage) {
26
- return {
27
- message: customMessage || err.message,
28
- originalError: err,
29
- type,
30
- userMessage,
31
- };
32
- }
33
- /**
34
- * Classify axios-specific errors
35
- * Returns null if error is not an axios error
36
- */
37
- function classifyAxiosError(error, err) {
38
- if (!isAxiosError(error)) {
39
- return null;
40
- }
41
- // Network connectivity issues
42
- if (error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED' || error.code === 'ETIMEDOUT') {
43
- return createClassifiedError(err, ErrorType.NETWORK, '❌ Network error: Unable to connect to ByteRover servers. Please check your internet connection and try again.');
44
- }
45
- // DNS resolution failed
46
- if (error.code === 'EAI_AGAIN') {
47
- return createClassifiedError(err, ErrorType.NETWORK, '❌ Network error: DNS resolution failed. Please check your internet connection and DNS settings.');
48
- }
49
- // Server returned error response
50
- if (error.response) {
51
- const { status } = error.response;
52
- // Authentication errors (401, 403)
53
- if (status === 401 || status === 403) {
54
- return createClassifiedError(err, ErrorType.AUTH, '❌ Authentication failed: Your session has expired or is invalid. Please run "brv login" to re-authenticate.');
55
- }
56
- // Billing/quota errors (402, 429)
57
- if (status === 402 || status === 429) {
58
- return createClassifiedError(err, ErrorType.BILLING, '❌ Billing error: Your ByteRover account may not have sufficient credits or has reached quota limits. Please check your account settings.');
59
- }
60
- // Server errors (500, 502, 503, 504)
61
- if (status >= 500) {
62
- return createClassifiedError(err, ErrorType.SERVER, '❌ Server error: ByteRover servers are experiencing issues. Please try again in a few moments.');
63
- }
64
- // Client errors (400, 404, etc.)
65
- if (status >= 400 && status < 500) {
66
- // Try to extract error message from response
67
- const responseData = error.response.data;
68
- const errorMessage = typeof responseData === 'string' ? responseData : responseData?.message || responseData?.error || err.message;
69
- return createClassifiedError(err, ErrorType.VALIDATION, `❌ Request error: ${errorMessage}`, errorMessage);
70
- }
71
- }
72
- // Request was made but no response received
73
- if (error.request) {
74
- return createClassifiedError(err, ErrorType.NETWORK, '❌ Network error: No response from ByteRover servers. Please check your internet connection and try again.');
75
- }
76
- return null;
77
- }
78
- /**
79
- * Classify error based on message keywords
80
- * Returns null if no keywords match
81
- */
82
- function classifyByMessageKeywords(err) {
83
- const errorMessage = err.message.toLowerCase();
84
- // Network-related keywords
85
- if (errorMessage.includes('network') ||
86
- errorMessage.includes('connection') ||
87
- errorMessage.includes('timeout') ||
88
- errorMessage.includes('enotfound') ||
89
- errorMessage.includes('econnrefused')) {
90
- return createClassifiedError(err, ErrorType.NETWORK, '❌ Network error: Unable to connect to ByteRover servers. Please check your internet connection and try again.');
91
- }
92
- // Authentication keywords
93
- if (errorMessage.includes('authentication') ||
94
- errorMessage.includes('unauthorized') ||
95
- errorMessage.includes('forbidden') ||
96
- errorMessage.includes('token') ||
97
- errorMessage.includes('login')) {
98
- return createClassifiedError(err, ErrorType.AUTH, '❌ Authentication failed: Your session has expired or is invalid. Please run "brv login" to re-authenticate.');
99
- }
100
- // Billing keywords
101
- if (errorMessage.includes('billing') ||
102
- errorMessage.includes('quota') ||
103
- errorMessage.includes('limit') ||
104
- errorMessage.includes('credits') ||
105
- errorMessage.includes('payment')) {
106
- return createClassifiedError(err, ErrorType.BILLING, '❌ Billing error: Your ByteRover account may not have sufficient credits or has reached quota limits. Please check your account settings.');
107
- }
108
- // Validation keywords
109
- if (errorMessage.includes('invalid') ||
110
- errorMessage.includes('required') ||
111
- errorMessage.includes('missing') ||
112
- errorMessage.includes('validation')) {
113
- return createClassifiedError(err, ErrorType.VALIDATION, `❌ Validation error: ${err.message}`);
114
- }
115
- return null;
116
- }
117
- /**
118
- * Classify error and return user-friendly message
119
- */
120
- export function classifyError(error) {
121
- const err = error instanceof Error ? error : new Error(String(error));
122
- // Try axios error classification first
123
- const axiosResult = classifyAxiosError(error, err);
124
- if (axiosResult) {
125
- return axiosResult;
126
- }
127
- // Try message-based classification
128
- const messageResult = classifyByMessageKeywords(err);
129
- if (messageResult) {
130
- return messageResult;
131
- }
132
- // Default: unknown error
133
- // Don't add prefix if error message already has emoji prefix
134
- return createClassifiedError(err, ErrorType.UNKNOWN, addErrorPrefix(err.message));
135
- }
136
- /**
137
- * Format error for display to user
138
- *
139
- * @param error - Error to format
140
- * @returns User-friendly error message
141
- */
142
- export function formatError(error) {
143
- const classified = classifyError(error);
144
- return classified.userMessage;
145
- }
146
- /**
147
- * Check if error is a network error
148
- */
149
- export function isNetworkError(error) {
150
- return classifyError(error).type === ErrorType.NETWORK;
151
- }
152
- /**
153
- * Check if error is a server error
154
- */
155
- export function isServerError(error) {
156
- return classifyError(error).type === ErrorType.SERVER;
157
- }
158
- /**
159
- * Check if error is an authentication error
160
- */
161
- export function isAuthError(error) {
162
- return classifyError(error).type === ErrorType.AUTH;
163
- }
164
- /**
165
- * Check if error is a billing error
166
- */
167
- export function isBillingError(error) {
168
- return classifyError(error).type === ErrorType.BILLING;
169
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * Helper utilities for handling oclif-specific errors
3
- *
4
- * These utilities help avoid duplicating error handling logic across commands
5
- */
6
- /**
7
- * Handle oclif error exit codes
8
- *
9
- * If the error has an oclif.exit property (set by this.error()), exit the process
10
- * with that code. This prevents oclif from re-logging errors that were already displayed.
11
- *
12
- * @param error - Error with optional oclif metadata
13
- * @returns true if error was handled (process exited), false if error should be re-thrown
14
- *
15
- * @example
16
- * public async catch(error: Error & {oclif?: {exit: number}}): Promise<void> {
17
- * if (handleOclifExit(error)) return
18
- * // Handle other error cases...
19
- * }
20
- */
21
- export declare function handleOclifExit(error: Error & {
22
- oclif?: {
23
- exit: number;
24
- };
25
- }): boolean;
26
- /**
27
- * Check if error is an oclif validation error
28
- *
29
- * Validation errors include missing arguments, unexpected arguments, and missing flags.
30
- * These should be re-thrown to let oclif's error handler display them properly.
31
- *
32
- * @param error - Error to check
33
- * @returns true if error is a validation error
34
- *
35
- * @example
36
- * if (isValidationError(error)) {
37
- * throw error // Let oclif handle it
38
- * }
39
- */
40
- export declare function isValidationError(error: Error): boolean;
@@ -1,46 +0,0 @@
1
- /**
2
- * Helper utilities for handling oclif-specific errors
3
- *
4
- * These utilities help avoid duplicating error handling logic across commands
5
- */
6
- /**
7
- * Handle oclif error exit codes
8
- *
9
- * If the error has an oclif.exit property (set by this.error()), exit the process
10
- * with that code. This prevents oclif from re-logging errors that were already displayed.
11
- *
12
- * @param error - Error with optional oclif metadata
13
- * @returns true if error was handled (process exited), false if error should be re-thrown
14
- *
15
- * @example
16
- * public async catch(error: Error & {oclif?: {exit: number}}): Promise<void> {
17
- * if (handleOclifExit(error)) return
18
- * // Handle other error cases...
19
- * }
20
- */
21
- export function handleOclifExit(error) {
22
- if (error.oclif?.exit !== undefined) {
23
- // eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
24
- process.exit(error.oclif.exit);
25
- }
26
- return false;
27
- }
28
- /**
29
- * Check if error is an oclif validation error
30
- *
31
- * Validation errors include missing arguments, unexpected arguments, and missing flags.
32
- * These should be re-thrown to let oclif's error handler display them properly.
33
- *
34
- * @param error - Error to check
35
- * @returns true if error is a validation error
36
- *
37
- * @example
38
- * if (isValidationError(error)) {
39
- * throw error // Let oclif handle it
40
- * }
41
- */
42
- export function isValidationError(error) {
43
- return (error.message.includes('Unexpected argument') ||
44
- error.message.includes('Missing') ||
45
- error.message.includes('required'));
46
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * Tool Display Formatter
3
- *
4
- * Utilities for formatting tool call arguments and results in a concise,
5
- * readable format for CLI display.
6
- */
7
- /**
8
- * Format a tool call with its arguments for display.
9
- *
10
- * Creates a concise, single-line representation of a tool call:
11
- * - Truncates long strings with ellipsis
12
- * - Shows relative paths or basenames for file paths
13
- * - Omits undefined/null optional parameters
14
- * - Formats arrays and objects as summaries
15
- *
16
- * @param toolName - Name of the tool being called
17
- * @param args - Tool arguments object
18
- * @returns Formatted string like "tool_name(arg1: value1, arg2: value2)"
19
- *
20
- * @example
21
- * ```typescript
22
- * formatToolCall('read_file', { filePath: '/long/path/to/file.ts', limit: 100 })
23
- * // Returns: 'read_file(filePath: "file.ts", limit: 100)'
24
- *
25
- * formatToolCall('write_file', { filePath: 'test.ts', content: 'very long content...', createDirs: true })
26
- * // Returns: 'write_file(filePath: "test.ts", content: "very long conte...", createDirs: true)'
27
- * ```
28
- */
29
- export declare function formatToolCall(toolName: string, args: Record<string, unknown>): string;
30
- /**
31
- * Format a tool result for display.
32
- *
33
- * Creates a concise summary of the tool execution result:
34
- * - For success: shows relevant metrics (file size, match count, etc.)
35
- * - For errors: shows error message
36
- * - Truncates long values
37
- *
38
- * @param toolName - Name of the tool that was executed
39
- * @param success - Whether the tool execution succeeded
40
- * @param result - Tool result (if successful)
41
- * @param error - Error message (if failed)
42
- * @returns Formatted result string
43
- *
44
- * @example
45
- * ```typescript
46
- * formatToolResult('write_file', true, { bytesWritten: 245 })
47
- * // Returns: 'File written (245 bytes)'
48
- *
49
- * formatToolResult('read_file', false, undefined, 'ENOENT: no such file or directory')
50
- * // Returns: 'ENOENT: no such file or directory'
51
- * ```
52
- */
53
- export declare function formatToolResult(toolName: string, success: boolean, result?: unknown, error?: string): string;
@@ -1,257 +0,0 @@
1
- /**
2
- * Tool Display Formatter
3
- *
4
- * Utilities for formatting tool call arguments and results in a concise,
5
- * readable format for CLI display.
6
- */
7
- /**
8
- * Maximum length for string values before truncation
9
- */
10
- const MAX_STRING_LENGTH = 50;
11
- /**
12
- * Maximum total line length for formatted output
13
- */
14
- const MAX_LINE_LENGTH = 100;
15
- /**
16
- * Format a tool call with its arguments for display.
17
- *
18
- * Creates a concise, single-line representation of a tool call:
19
- * - Truncates long strings with ellipsis
20
- * - Shows relative paths or basenames for file paths
21
- * - Omits undefined/null optional parameters
22
- * - Formats arrays and objects as summaries
23
- *
24
- * @param toolName - Name of the tool being called
25
- * @param args - Tool arguments object
26
- * @returns Formatted string like "tool_name(arg1: value1, arg2: value2)"
27
- *
28
- * @example
29
- * ```typescript
30
- * formatToolCall('read_file', { filePath: '/long/path/to/file.ts', limit: 100 })
31
- * // Returns: 'read_file(filePath: "file.ts", limit: 100)'
32
- *
33
- * formatToolCall('write_file', { filePath: 'test.ts', content: 'very long content...', createDirs: true })
34
- * // Returns: 'write_file(filePath: "test.ts", content: "very long conte...", createDirs: true)'
35
- * ```
36
- */
37
- export function formatToolCall(toolName, args) {
38
- const formattedArgs = Object.entries(args)
39
- .filter(([_, value]) => value !== undefined && value !== null)
40
- .map(([key, value]) => `${key}: ${formatValue(value)}`)
41
- .join(', ');
42
- const result = `${toolName}(${formattedArgs})`;
43
- // Truncate if too long
44
- if (result.length > MAX_LINE_LENGTH) {
45
- return result.slice(0, MAX_LINE_LENGTH - 3) + '...';
46
- }
47
- return result;
48
- }
49
- /**
50
- * Format a tool result for display.
51
- *
52
- * Creates a concise summary of the tool execution result:
53
- * - For success: shows relevant metrics (file size, match count, etc.)
54
- * - For errors: shows error message
55
- * - Truncates long values
56
- *
57
- * @param toolName - Name of the tool that was executed
58
- * @param success - Whether the tool execution succeeded
59
- * @param result - Tool result (if successful)
60
- * @param error - Error message (if failed)
61
- * @returns Formatted result string
62
- *
63
- * @example
64
- * ```typescript
65
- * formatToolResult('write_file', true, { bytesWritten: 245 })
66
- * // Returns: 'File written (245 bytes)'
67
- *
68
- * formatToolResult('read_file', false, undefined, 'ENOENT: no such file or directory')
69
- * // Returns: 'ENOENT: no such file or directory'
70
- * ```
71
- */
72
- export function formatToolResult(toolName, success, result, error) {
73
- if (!success) {
74
- return error ? truncateString(error, 80) : 'Unknown error';
75
- }
76
- // Tool-specific result formatting
77
- switch (toolName) {
78
- case 'edit_file': {
79
- return formatEditFileResult(result);
80
- }
81
- case 'glob_files': {
82
- return formatGlobFilesResult(result);
83
- }
84
- case 'grep_content': {
85
- return formatGrepContentResult(result);
86
- }
87
- case 'read_file': {
88
- return formatReadFileResult(result);
89
- }
90
- case 'search_history': {
91
- return formatSearchHistoryResult(result);
92
- }
93
- case 'write_file': {
94
- return formatWriteFileResult(result);
95
- }
96
- default: {
97
- return formatGenericResult(result);
98
- }
99
- }
100
- }
101
- /**
102
- * Format a value for display based on its type.
103
- *
104
- * @param value - Value to format
105
- * @returns Formatted string representation
106
- */
107
- function formatValue(value) {
108
- if (value === null) {
109
- return 'null';
110
- }
111
- if (value === undefined) {
112
- return 'undefined';
113
- }
114
- if (typeof value === 'string') {
115
- // Special handling for file paths
116
- if (value.includes('/') || value.includes('\\')) {
117
- return `"${formatPath(value)}"`;
118
- }
119
- return `"${truncateString(value, MAX_STRING_LENGTH)}"`;
120
- }
121
- if (typeof value === 'number' || typeof value === 'boolean') {
122
- return String(value);
123
- }
124
- if (Array.isArray(value)) {
125
- return `[${value.length} items]`;
126
- }
127
- if (typeof value === 'object') {
128
- const keys = Object.keys(value);
129
- return `{${keys.length} fields}`;
130
- }
131
- return String(value);
132
- }
133
- /**
134
- * Format a file path for display.
135
- * Shows basename for long paths, or relative path if reasonable.
136
- *
137
- * @param path - File path to format
138
- * @returns Formatted path
139
- */
140
- function formatPath(path) {
141
- // If path is already short, return as-is
142
- if (path.length <= MAX_STRING_LENGTH) {
143
- return path;
144
- }
145
- // Extract filename
146
- const parts = path.split(/[/\\]/);
147
- const filename = parts.at(-1) || path;
148
- // If just filename is short enough, use it
149
- if (filename.length <= MAX_STRING_LENGTH) {
150
- return filename;
151
- }
152
- // Otherwise truncate
153
- return truncateString(path, MAX_STRING_LENGTH);
154
- }
155
- /**
156
- * Truncate a string to a maximum length with ellipsis.
157
- *
158
- * @param str - String to truncate
159
- * @param maxLength - Maximum length
160
- * @returns Truncated string
161
- */
162
- function truncateString(str, maxLength) {
163
- if (str.length <= maxLength) {
164
- return str;
165
- }
166
- return str.slice(0, maxLength - 3) + '...';
167
- }
168
- // Tool-specific result formatters
169
- function formatReadFileResult(result) {
170
- if (typeof result === 'object' && result !== null) {
171
- const { lines } = result;
172
- if (typeof lines === 'number') {
173
- return `Read ${lines} lines`;
174
- }
175
- }
176
- if (typeof result === 'string') {
177
- const lineCount = result.split('\n').length;
178
- const byteCount = new Blob([result]).size;
179
- return `Read ${lineCount} lines (${byteCount} bytes)`;
180
- }
181
- return 'File read successfully';
182
- }
183
- function formatWriteFileResult(result) {
184
- if (typeof result === 'object' && result !== null) {
185
- const { bytesWritten: bytes } = result;
186
- if (typeof bytes === 'number') {
187
- return `File written (${bytes} bytes)`;
188
- }
189
- }
190
- return 'File written successfully';
191
- }
192
- function formatEditFileResult(result) {
193
- if (typeof result === 'object' && result !== null) {
194
- const { changes } = result;
195
- if (typeof changes === 'number') {
196
- return `File edited (${changes} changes)`;
197
- }
198
- }
199
- return 'File edited successfully';
200
- }
201
- function formatGlobFilesResult(result) {
202
- if (Array.isArray(result)) {
203
- return `Found ${result.length} files`;
204
- }
205
- if (typeof result === 'object' && result !== null) {
206
- const { files } = result;
207
- if (Array.isArray(files)) {
208
- return `Found ${files.length} files`;
209
- }
210
- }
211
- return 'Files found';
212
- }
213
- function formatGrepContentResult(result) {
214
- if (Array.isArray(result)) {
215
- return `Found ${result.length} matches`;
216
- }
217
- if (typeof result === 'object' && result !== null) {
218
- const { matchCount: count, matches } = result;
219
- if (Array.isArray(matches)) {
220
- return `Found ${matches.length} matches`;
221
- }
222
- if (typeof count === 'number') {
223
- return `Found ${count} matches`;
224
- }
225
- }
226
- return 'Matches found';
227
- }
228
- function formatSearchHistoryResult(result) {
229
- if (Array.isArray(result)) {
230
- return `Found ${result.length} history items`;
231
- }
232
- if (typeof result === 'object' && result !== null) {
233
- const { items } = result;
234
- if (Array.isArray(items)) {
235
- return `Found ${items.length} history items`;
236
- }
237
- }
238
- return 'History searched';
239
- }
240
- function formatGenericResult(result) {
241
- if (result === null || result === undefined) {
242
- return 'Success';
243
- }
244
- if (typeof result === 'string') {
245
- return truncateString(result, 60);
246
- }
247
- if (typeof result === 'number' || typeof result === 'boolean') {
248
- return String(result);
249
- }
250
- if (Array.isArray(result)) {
251
- return `Returned ${result.length} items`;
252
- }
253
- if (typeof result === 'object') {
254
- return 'Success';
255
- }
256
- return 'Success';
257
- }