indusagi-coding-agent 0.1.23 → 0.1.25
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/CHANGELOG.md +101 -0
- package/README.md +2 -0
- package/dist/cli/args.d.ts +117 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +221 -52
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts +58 -2
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +130 -12
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts +70 -2
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +240 -15
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/list-models.d.ts +63 -3
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +202 -27
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/login-handler.d.ts +82 -8
- package/dist/cli/login-handler.d.ts.map +1 -1
- package/dist/cli/login-handler.js +410 -77
- package/dist/cli/login-handler.js.map +1 -1
- package/dist/cli/session-picker.d.ts +74 -2
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +236 -12
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/core/agent-session.d.ts +214 -9
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +214 -9
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts +302 -12
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +302 -12
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/diagnostics.d.ts +191 -0
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/diagnostics.js +142 -0
- package/dist/core/diagnostics.js.map +1 -1
- package/dist/core/discover-packages.d.ts +6 -0
- package/dist/core/discover-packages.d.ts.map +1 -0
- package/dist/core/discover-packages.js +62 -0
- package/dist/core/discover-packages.js.map +1 -0
- package/dist/core/event-bus.d.ts +146 -0
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js +93 -0
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts +4 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +4 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/index.d.ts +128 -0
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +128 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts +4 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +4 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/keybindings.d.ts +142 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +142 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts +98 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +98 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +99 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +99 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +127 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +125 -0
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/subagents.js.map +1 -1
- package/dist/core/tools/bash.d.ts +391 -11
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +269 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/bg-process.d.ts +49 -0
- package/dist/core/tools/bg-process.d.ts.map +1 -0
- package/dist/core/tools/bg-process.js +69 -0
- package/dist/core/tools/bg-process.js.map +1 -0
- package/dist/core/tools/edit.d.ts +284 -6
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +238 -0
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +169 -5
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +136 -0
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +285 -5
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +247 -0
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +45 -0
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +15 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +6 -0
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +6 -0
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +308 -7
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +231 -0
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/registry.d.ts +17 -0
- package/dist/core/tools/registry.d.ts.map +1 -0
- package/dist/core/tools/registry.js +108 -0
- package/dist/core/tools/registry.js.map +1 -0
- package/dist/core/tools/webfetch.d.ts +118 -3
- package/dist/core/tools/webfetch.d.ts.map +1 -1
- package/dist/core/tools/webfetch.js +118 -3
- package/dist/core/tools/webfetch.js.map +1 -1
- package/dist/core/tools/websearch.d.ts +130 -3
- package/dist/core/tools/websearch.d.ts.map +1 -1
- package/dist/core/tools/websearch.js +130 -3
- package/dist/core/tools/websearch.js.map +1 -1
- package/dist/core/tools/write.d.ts +251 -5
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +210 -0
- package/dist/core/tools/write.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +12 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +164 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +164 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +297 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +297 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +251 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +186 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +186 -1
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1567 -13
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1567 -13
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +422 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +422 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts +538 -5
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +538 -5
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +921 -8
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +921 -8
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +802 -9
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +802 -9
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +356 -3
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +356 -3
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/shared.d.ts +386 -0
- package/dist/modes/shared.d.ts.map +1 -0
- package/dist/modes/shared.js +543 -0
- package/dist/modes/shared.js.map +1 -0
- package/dist/utils/array.d.ts +389 -0
- package/dist/utils/array.d.ts.map +1 -0
- package/dist/utils/array.js +585 -0
- package/dist/utils/array.js.map +1 -0
- package/dist/utils/color-formatter.d.ts +318 -0
- package/dist/utils/color-formatter.d.ts.map +1 -0
- package/dist/utils/color-formatter.js +442 -0
- package/dist/utils/color-formatter.js.map +1 -0
- package/dist/utils/data-transformer.d.ts +326 -0
- package/dist/utils/data-transformer.d.ts.map +1 -0
- package/dist/utils/data-transformer.js +512 -0
- package/dist/utils/data-transformer.js.map +1 -0
- package/dist/utils/date-formatter.d.ts +281 -0
- package/dist/utils/date-formatter.d.ts.map +1 -0
- package/dist/utils/date-formatter.js +503 -0
- package/dist/utils/date-formatter.js.map +1 -0
- package/dist/utils/error-handler.d.ts +541 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +726 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/file-operations.d.ts +297 -0
- package/dist/utils/file-operations.d.ts.map +1 -0
- package/dist/utils/file-operations.js +505 -0
- package/dist/utils/file-operations.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +268 -6
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +500 -21
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/json-formatter.d.ts +259 -0
- package/dist/utils/json-formatter.d.ts.map +1 -0
- package/dist/utils/json-formatter.js +517 -0
- package/dist/utils/json-formatter.js.map +1 -0
- package/dist/utils/logger.d.ts +176 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +346 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/markdown-formatter.d.ts +211 -0
- package/dist/utils/markdown-formatter.d.ts.map +1 -0
- package/dist/utils/markdown-formatter.js +482 -0
- package/dist/utils/markdown-formatter.js.map +1 -0
- package/dist/utils/path-validator.d.ts +603 -0
- package/dist/utils/path-validator.d.ts.map +1 -0
- package/dist/utils/path-validator.js +870 -0
- package/dist/utils/path-validator.js.map +1 -0
- package/dist/utils/string-formatter.d.ts +609 -0
- package/dist/utils/string-formatter.d.ts.map +1 -0
- package/dist/utils/string-formatter.js +806 -0
- package/dist/utils/string-formatter.js.map +1 -0
- package/dist/utils/type-guards.d.ts +629 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +662 -0
- package/dist/utils/type-guards.js.map +1 -0
- package/docs/COMPLETE-GUIDE.md +300 -0
- package/docs/COMPREHENSIVE-CLI-SUMMARY.md +900 -0
- package/docs/MODES-ARCHITECTURE.md +565 -0
- package/docs/PRINT-MODE-GUIDE.md +456 -0
- package/docs/RPC-GUIDE.md +705 -0
- package/docs/UTILS-IMPLEMENTATION-SUMMARY.md +647 -0
- package/docs/UTILS-MODULE-OVERVIEW.md +1480 -0
- package/docs/UTILS-QA-CHECKLIST.md +1061 -0
- package/docs/UTILS-USAGE-GUIDE.md +1419 -0
- package/package.json +7 -3
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Utilities for All Execution Modes
|
|
3
|
+
*
|
|
4
|
+
* This module provides common utilities, validators, and formatters used across all three
|
|
5
|
+
* execution modes (interactive, print, RPC).
|
|
6
|
+
*
|
|
7
|
+
* Purpose:
|
|
8
|
+
* --------
|
|
9
|
+
* - Centralize common functionality to avoid duplication
|
|
10
|
+
* - Ensure consistent behavior across modes
|
|
11
|
+
* - Provide standard data transformation and validation
|
|
12
|
+
*
|
|
13
|
+
* Usage by Modes:
|
|
14
|
+
* ---------------
|
|
15
|
+
* INTERACTIVE MODE:
|
|
16
|
+
* - Uses formatDuration for displaying execution times
|
|
17
|
+
* - Uses validatePrompt for user input validation
|
|
18
|
+
* - Uses extractSessionId for session switching
|
|
19
|
+
*
|
|
20
|
+
* PRINT MODE:
|
|
21
|
+
* - Uses createOutputFormatter to format results as JSON/text
|
|
22
|
+
* - Uses escapeJsonString for JSON output
|
|
23
|
+
* - Uses formatErrorMessage for error reporting
|
|
24
|
+
*
|
|
25
|
+
* RPC MODE:
|
|
26
|
+
* - Uses parseSessionPath for session resolution
|
|
27
|
+
* - Uses validatePrompt for incoming RPC requests
|
|
28
|
+
* - Uses escapeJsonString for JSON-RPC responses
|
|
29
|
+
*
|
|
30
|
+
* Architecture:
|
|
31
|
+
* -------------
|
|
32
|
+
* This module acts as a utility facade, providing a single source of truth for:
|
|
33
|
+
* 1. Data transformation (format functions)
|
|
34
|
+
* 2. Input validation (validate functions)
|
|
35
|
+
* 3. Error handling (error formatting)
|
|
36
|
+
* 4. Conversion utilities (token counts, durations)
|
|
37
|
+
*
|
|
38
|
+
* All functions are pure (no side effects) and stateless for maximum reusability.
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Output format type for print mode
|
|
42
|
+
* - 'json': Machine-readable JSON lines format
|
|
43
|
+
* - 'text': Human-readable plain text format
|
|
44
|
+
* - 'compact': Minimal output (status only)
|
|
45
|
+
*/
|
|
46
|
+
export type OutputFormat = 'json' | 'text' | 'compact';
|
|
47
|
+
/**
|
|
48
|
+
* Validation result with error details
|
|
49
|
+
*/
|
|
50
|
+
export interface ValidationResult {
|
|
51
|
+
valid: boolean;
|
|
52
|
+
error?: string;
|
|
53
|
+
details?: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Output formatter interface used by all modes
|
|
57
|
+
*/
|
|
58
|
+
export interface OutputFormatter {
|
|
59
|
+
format(data: unknown): string;
|
|
60
|
+
formatError(error: Error): string;
|
|
61
|
+
getContentType(): string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create an output formatter for a specific format type
|
|
65
|
+
*
|
|
66
|
+
* Factory function that returns a formatter implementing the OutputFormatter interface.
|
|
67
|
+
* Each formatter knows how to convert data to its target output format.
|
|
68
|
+
*
|
|
69
|
+
* Formats:
|
|
70
|
+
* - 'json': Outputs JSON lines (each event as a JSON object)
|
|
71
|
+
* - 'text': Outputs human-readable text with formatting
|
|
72
|
+
* - 'compact': Outputs minimal status information
|
|
73
|
+
*
|
|
74
|
+
* Usage:
|
|
75
|
+
* ------
|
|
76
|
+
* PRINT MODE:
|
|
77
|
+
* const formatter = createOutputFormatter('json');
|
|
78
|
+
* console.log(formatter.format(agentResponse));
|
|
79
|
+
* console.error(formatter.formatError(error));
|
|
80
|
+
*
|
|
81
|
+
* @param format - Output format type ('json' | 'text' | 'compact')
|
|
82
|
+
* @returns OutputFormatter instance for the specified format
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* // JSON output for event streaming
|
|
86
|
+
* const jsonFormatter = createOutputFormatter('json');
|
|
87
|
+
* process.stdout.write(jsonFormatter.format(event));
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* // Text output for human readers
|
|
91
|
+
* const textFormatter = createOutputFormatter('text');
|
|
92
|
+
* process.stdout.write(textFormatter.format(response));
|
|
93
|
+
*
|
|
94
|
+
* @throws Error if format is not recognized
|
|
95
|
+
*/
|
|
96
|
+
export declare function createOutputFormatter(format: OutputFormat): OutputFormatter;
|
|
97
|
+
/**
|
|
98
|
+
* Parse and validate a session path/ID
|
|
99
|
+
*
|
|
100
|
+
* Extracts and validates session identifiers. Supports multiple formats:
|
|
101
|
+
* - UUID: "550e8400-e29b-41d4-a716-446655440000"
|
|
102
|
+
* - Filename: "session-123.jsonl"
|
|
103
|
+
* - Path: "/home/user/.indusagi/sessions/session-123.jsonl"
|
|
104
|
+
*
|
|
105
|
+
* Returns parsed session ID or throws ValidationError if invalid.
|
|
106
|
+
*
|
|
107
|
+
* Usage:
|
|
108
|
+
* ------
|
|
109
|
+
* RPC MODE:
|
|
110
|
+
* const sessionId = parseSessionPath(request.params.sessionId);
|
|
111
|
+
* const session = sessionManager.load(sessionId);
|
|
112
|
+
*
|
|
113
|
+
* INTERACTIVE MODE:
|
|
114
|
+
* const sessionId = parseSessionPath(userInput);
|
|
115
|
+
* // Used in session switching command
|
|
116
|
+
*
|
|
117
|
+
* @param path - Session ID, filename, or filesystem path
|
|
118
|
+
* @returns Normalized session UUID
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* parseSessionPath('550e8400-e29b-41d4-a716-446655440000')
|
|
122
|
+
* // Returns: '550e8400-e29b-41d4-a716-446655440000'
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* parseSessionPath('session-123.jsonl')
|
|
126
|
+
* // Returns: 'session-123' (extracts ID from filename)
|
|
127
|
+
*
|
|
128
|
+
* @throws Error if path is empty or invalid format
|
|
129
|
+
*/
|
|
130
|
+
export declare function parseSessionPath(path: string): string;
|
|
131
|
+
/**
|
|
132
|
+
* Validate user input/prompt
|
|
133
|
+
*
|
|
134
|
+
* Checks if a prompt is valid for sending to the agent.
|
|
135
|
+
*
|
|
136
|
+
* Validation rules:
|
|
137
|
+
* - Non-empty (after trimming whitespace)
|
|
138
|
+
* - No longer than 100,000 characters (prevents DOS)
|
|
139
|
+
* - Must be a string
|
|
140
|
+
*
|
|
141
|
+
* Returns ValidationResult with detailed error information if invalid.
|
|
142
|
+
*
|
|
143
|
+
* Usage:
|
|
144
|
+
* ------
|
|
145
|
+
* INTERACTIVE MODE:
|
|
146
|
+
* const result = validatePrompt(userInput);
|
|
147
|
+
* if (!result.valid) {
|
|
148
|
+
* showError(result.error);
|
|
149
|
+
* return;
|
|
150
|
+
* }
|
|
151
|
+
* session.prompt(userInput);
|
|
152
|
+
*
|
|
153
|
+
* RPC MODE:
|
|
154
|
+
* const result = validatePrompt(request.message);
|
|
155
|
+
* if (!result.valid) {
|
|
156
|
+
* return rpcError(-32602, result.error);
|
|
157
|
+
* }
|
|
158
|
+
*
|
|
159
|
+
* @param prompt - User input to validate
|
|
160
|
+
* @returns ValidationResult with valid flag and optional error message
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* validatePrompt('What does this code do?')
|
|
164
|
+
* // Returns: { valid: true }
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* validatePrompt(' ')
|
|
168
|
+
* // Returns: { valid: false, error: 'Prompt cannot be empty' }
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* validatePrompt('x'.repeat(100001))
|
|
172
|
+
* // Returns: { valid: false, error: 'Prompt exceeds maximum length (100000)' }
|
|
173
|
+
*/
|
|
174
|
+
export declare function validatePrompt(prompt: unknown): ValidationResult;
|
|
175
|
+
/**
|
|
176
|
+
* Format milliseconds to human-readable duration string
|
|
177
|
+
*
|
|
178
|
+
* Converts milliseconds into a readable format like "1h 23m 45s 123ms".
|
|
179
|
+
* Omits zero values and units for brevity.
|
|
180
|
+
*
|
|
181
|
+
* Examples:
|
|
182
|
+
* - 1000 ms → "1s"
|
|
183
|
+
* - 61000 ms → "1m 1s"
|
|
184
|
+
* - 3661000 ms → "1h 1m 1s"
|
|
185
|
+
*
|
|
186
|
+
* Usage:
|
|
187
|
+
* ------
|
|
188
|
+
* INTERACTIVE MODE:
|
|
189
|
+
* const elapsed = Date.now() - startTime;
|
|
190
|
+
* footer.text = `Completed in ${formatDuration(elapsed)}`;
|
|
191
|
+
*
|
|
192
|
+
* PRINT MODE:
|
|
193
|
+
* console.log(`"elapsed_time": "${formatDuration(duration)}"`);
|
|
194
|
+
*
|
|
195
|
+
* @param ms - Duration in milliseconds
|
|
196
|
+
* @returns Formatted duration string
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* formatDuration(1234567) // "20m 34s 567ms"
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* formatDuration(5000) // "5s"
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* formatDuration(0) // "0ms"
|
|
206
|
+
*/
|
|
207
|
+
export declare function formatDuration(ms: number): string;
|
|
208
|
+
/**
|
|
209
|
+
* Format token count with usage estimates
|
|
210
|
+
*
|
|
211
|
+
* Converts a token count into a readable format with estimates of cost/usage:
|
|
212
|
+
* - Shows raw token count
|
|
213
|
+
* - Estimates word count (roughly 0.75 words per token)
|
|
214
|
+
* - Estimates cost at $0.002 per 1000 tokens (GPT-4 average)
|
|
215
|
+
*
|
|
216
|
+
* Useful for displaying resource usage in logs and UI.
|
|
217
|
+
*
|
|
218
|
+
* Usage:
|
|
219
|
+
* ------
|
|
220
|
+
* PRINT MODE:
|
|
221
|
+
* const formatted = formatTokens(response.usage.total_tokens);
|
|
222
|
+
* console.log(`Tokens: ${formatted}`);
|
|
223
|
+
*
|
|
224
|
+
* INTERACTIVE MODE:
|
|
225
|
+
* footer.text = `Tokens: ${formatTokens(totalTokens)}`;
|
|
226
|
+
*
|
|
227
|
+
* @param tokens - Number of tokens used
|
|
228
|
+
* @returns Formatted string with tokens, word estimate, and cost estimate
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* formatTokens(1500)
|
|
232
|
+
* // Returns: "1,500 tokens (~1,125 words, ~$0.003 cost)"
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* formatTokens(0)
|
|
236
|
+
* // Returns: "0 tokens"
|
|
237
|
+
*/
|
|
238
|
+
export declare function formatTokens(tokens: number): string;
|
|
239
|
+
/**
|
|
240
|
+
* Extract session ID from user input
|
|
241
|
+
*
|
|
242
|
+
* Parses user input to extract a session ID. Handles multiple formats:
|
|
243
|
+
* - Direct UUID
|
|
244
|
+
* - Filenames with session ID
|
|
245
|
+
* - Prefixes like "session:uuid"
|
|
246
|
+
*
|
|
247
|
+
* Returns null if no valid session ID found.
|
|
248
|
+
*
|
|
249
|
+
* Usage:
|
|
250
|
+
* ------
|
|
251
|
+
* INTERACTIVE MODE:
|
|
252
|
+
* // User types: "/switch 550e8400-e29b-41d4-a716-446655440000"
|
|
253
|
+
* const sessionId = extractSessionId(userInput);
|
|
254
|
+
* if (sessionId) interactiveMode.switchSession(sessionId);
|
|
255
|
+
*
|
|
256
|
+
* @param input - User input string
|
|
257
|
+
* @returns Session ID if found, null otherwise
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* extractSessionId('session:550e8400-e29b-41d4-a716-446655440000')
|
|
261
|
+
* // Returns: '550e8400-e29b-41d4-a716-446655440000'
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* extractSessionId('/switch my-session-123')
|
|
265
|
+
* // Returns: 'my-session-123'
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* extractSessionId('invalid input')
|
|
269
|
+
* // Returns: null
|
|
270
|
+
*/
|
|
271
|
+
export declare function extractSessionId(input: string): string | null;
|
|
272
|
+
/**
|
|
273
|
+
* Escape string for safe JSON output
|
|
274
|
+
*
|
|
275
|
+
* Properly escapes special characters for JSON strings:
|
|
276
|
+
* - Quotes: " → \"
|
|
277
|
+
* - Backslashes: \ → \\
|
|
278
|
+
* - Newlines: \n, \r, \t etc
|
|
279
|
+
* - Control characters
|
|
280
|
+
*
|
|
281
|
+
* Usage:
|
|
282
|
+
* ------
|
|
283
|
+
* PRINT MODE:
|
|
284
|
+
* const jsonLine = `{"message": "${escapeJsonString(message)}"}`;
|
|
285
|
+
* console.log(jsonLine);
|
|
286
|
+
*
|
|
287
|
+
* RPC MODE:
|
|
288
|
+
* const response = {
|
|
289
|
+
* message: escapeJsonString(plainText)
|
|
290
|
+
* };
|
|
291
|
+
* sendJsonRpc(response);
|
|
292
|
+
*
|
|
293
|
+
* @param str - String to escape
|
|
294
|
+
* @returns Escaped string safe for JSON output
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* escapeJsonString('Hello "World"\n')
|
|
298
|
+
* // Returns: 'Hello \"World\"\\n'
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* escapeJsonString('Path: C:\\Users\\test')
|
|
302
|
+
* // Returns: 'Path: C:\\\\Users\\\\test'
|
|
303
|
+
*/
|
|
304
|
+
export declare function escapeJsonString(str: string): string;
|
|
305
|
+
/**
|
|
306
|
+
* Format error message for display
|
|
307
|
+
*
|
|
308
|
+
* Converts an Error object into a formatted error message suitable for:
|
|
309
|
+
* - Terminal display (interactive mode)
|
|
310
|
+
* - Log output (print mode)
|
|
311
|
+
* - JSON responses (RPC mode)
|
|
312
|
+
*
|
|
313
|
+
* Includes error message, type, and optional stack trace (if DEBUG enabled).
|
|
314
|
+
*
|
|
315
|
+
* Usage:
|
|
316
|
+
* ------
|
|
317
|
+
* INTERACTIVE MODE:
|
|
318
|
+
* try {
|
|
319
|
+
* await session.prompt(input);
|
|
320
|
+
* } catch (error) {
|
|
321
|
+
* displayError(formatErrorMessage(error));
|
|
322
|
+
* }
|
|
323
|
+
*
|
|
324
|
+
* PRINT MODE:
|
|
325
|
+
* process.stderr.write(formatErrorMessage(error));
|
|
326
|
+
* process.exit(1);
|
|
327
|
+
*
|
|
328
|
+
* RPC MODE:
|
|
329
|
+
* catch (error) {
|
|
330
|
+
* response.error = formatErrorMessage(error);
|
|
331
|
+
* }
|
|
332
|
+
*
|
|
333
|
+
* @param error - Error object or string
|
|
334
|
+
* @returns Formatted error message string
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* const error = new Error('Invalid session');
|
|
338
|
+
* formatErrorMessage(error)
|
|
339
|
+
* // Returns: 'Error: Invalid session'
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* formatErrorMessage('Something went wrong')
|
|
343
|
+
* // Returns: 'Something went wrong'
|
|
344
|
+
*/
|
|
345
|
+
export declare function formatErrorMessage(error: unknown): string;
|
|
346
|
+
/**
|
|
347
|
+
* Determine if session should be auto-saved
|
|
348
|
+
*
|
|
349
|
+
* Checks configuration and state to determine whether to automatically persist
|
|
350
|
+
* the session to disk.
|
|
351
|
+
*
|
|
352
|
+
* Auto-save is enabled when:
|
|
353
|
+
* - config.autoSave is true
|
|
354
|
+
* - Session has been modified (dirty flag)
|
|
355
|
+
* - Minimum time interval has passed since last save
|
|
356
|
+
*
|
|
357
|
+
* Usage:
|
|
358
|
+
* ------
|
|
359
|
+
* INTERACTIVE MODE:
|
|
360
|
+
* if (shouldAutoSave(config)) {
|
|
361
|
+
* await sessionManager.save(session);
|
|
362
|
+
* }
|
|
363
|
+
*
|
|
364
|
+
* @param config - Configuration object with autoSave setting
|
|
365
|
+
* @returns Boolean indicating if session should be auto-saved
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* const config = { autoSave: true, autoSaveInterval: 30000 };
|
|
369
|
+
* if (shouldAutoSave(config)) {
|
|
370
|
+
* sessionManager.save(currentSession);
|
|
371
|
+
* }
|
|
372
|
+
*/
|
|
373
|
+
export declare function shouldAutoSave(config: any): boolean;
|
|
374
|
+
declare const _default: {
|
|
375
|
+
createOutputFormatter: typeof createOutputFormatter;
|
|
376
|
+
parseSessionPath: typeof parseSessionPath;
|
|
377
|
+
validatePrompt: typeof validatePrompt;
|
|
378
|
+
formatDuration: typeof formatDuration;
|
|
379
|
+
formatTokens: typeof formatTokens;
|
|
380
|
+
extractSessionId: typeof extractSessionId;
|
|
381
|
+
escapeJsonString: typeof escapeJsonString;
|
|
382
|
+
formatErrorMessage: typeof formatErrorMessage;
|
|
383
|
+
shouldAutoSave: typeof shouldAutoSave;
|
|
384
|
+
};
|
|
385
|
+
export default _default;
|
|
386
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/modes/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IAC9B,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;IAClC,cAAc,IAAI,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,eAAe,CAW3E;AAmED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAoBrD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CA2BhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAsBjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkB7D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAWpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAczD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAInD;;;;;;;;;;;;AAED,wBAUE"}
|