centaurus-cli 2.9.0 → 2.9.2
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/cli-adapter.d.ts +78 -0
- package/dist/cli-adapter.d.ts.map +1 -1
- package/dist/cli-adapter.js +566 -165
- package/dist/cli-adapter.js.map +1 -1
- package/dist/config/build-config.d.ts +1 -1
- package/dist/config/build-config.js +1 -1
- package/dist/config/mcp-config-manager.d.ts +21 -0
- package/dist/config/mcp-config-manager.d.ts.map +1 -1
- package/dist/config/mcp-config-manager.js +184 -1
- package/dist/config/mcp-config-manager.js.map +1 -1
- package/dist/config/models.d.ts +1 -0
- package/dist/config/models.d.ts.map +1 -1
- package/dist/config/models.js +7 -2
- package/dist/config/models.js.map +1 -1
- package/dist/config/slash-commands.d.ts.map +1 -1
- package/dist/config/slash-commands.js +5 -3
- package/dist/config/slash-commands.js.map +1 -1
- package/dist/index.js +66 -11
- package/dist/index.js.map +1 -1
- package/dist/mcp/mcp-command-handler.d.ts +34 -3
- package/dist/mcp/mcp-command-handler.d.ts.map +1 -1
- package/dist/mcp/mcp-command-handler.js +171 -83
- package/dist/mcp/mcp-command-handler.js.map +1 -1
- package/dist/mcp/mcp-server-manager.d.ts.map +1 -1
- package/dist/mcp/mcp-server-manager.js +9 -23
- package/dist/mcp/mcp-server-manager.js.map +1 -1
- package/dist/mcp/mcp-tool-wrapper.d.ts.map +1 -1
- package/dist/mcp/mcp-tool-wrapper.js +42 -5
- package/dist/mcp/mcp-tool-wrapper.js.map +1 -1
- package/dist/services/ai-service-client.d.ts +6 -1
- package/dist/services/ai-service-client.d.ts.map +1 -1
- package/dist/services/ai-service-client.js +6 -6
- package/dist/services/ai-service-client.js.map +1 -1
- package/dist/services/api-client.d.ts +20 -0
- package/dist/services/api-client.d.ts.map +1 -1
- package/dist/services/api-client.js +35 -0
- package/dist/services/api-client.js.map +1 -1
- package/dist/services/input-detection-agent.d.ts +40 -0
- package/dist/services/input-detection-agent.d.ts.map +1 -0
- package/dist/services/input-detection-agent.js +213 -0
- package/dist/services/input-detection-agent.js.map +1 -0
- package/dist/services/input-requirement-detector.d.ts +28 -0
- package/dist/services/input-requirement-detector.d.ts.map +1 -0
- package/dist/services/input-requirement-detector.js +203 -0
- package/dist/services/input-requirement-detector.js.map +1 -0
- package/dist/services/monitored-shell-manager.d.ts +120 -0
- package/dist/services/monitored-shell-manager.d.ts.map +1 -0
- package/dist/services/monitored-shell-manager.js +239 -0
- package/dist/services/monitored-shell-manager.js.map +1 -0
- package/dist/services/session-quota-manager.d.ts +101 -0
- package/dist/services/session-quota-manager.d.ts.map +1 -0
- package/dist/services/session-quota-manager.js +242 -0
- package/dist/services/session-quota-manager.js.map +1 -0
- package/dist/services/shell-input-agent.d.ts +89 -0
- package/dist/services/shell-input-agent.d.ts.map +1 -0
- package/dist/services/shell-input-agent.js +361 -0
- package/dist/services/shell-input-agent.js.map +1 -0
- package/dist/services/sub-agent-manager.d.ts +139 -0
- package/dist/services/sub-agent-manager.d.ts.map +1 -0
- package/dist/services/sub-agent-manager.js +517 -0
- package/dist/services/sub-agent-manager.js.map +1 -0
- package/dist/tools/background-command.d.ts.map +1 -1
- package/dist/tools/background-command.js +33 -13
- package/dist/tools/background-command.js.map +1 -1
- package/dist/tools/command.d.ts.map +1 -1
- package/dist/tools/command.js +78 -4
- package/dist/tools/command.js.map +1 -1
- package/dist/tools/file-ops.d.ts.map +1 -1
- package/dist/tools/file-ops.js +33 -19
- package/dist/tools/file-ops.js.map +1 -1
- package/dist/tools/get-diff.d.ts.map +1 -1
- package/dist/tools/get-diff.js +5 -2
- package/dist/tools/get-diff.js.map +1 -1
- package/dist/tools/grep-search.d.ts.map +1 -1
- package/dist/tools/grep-search.js +41 -15
- package/dist/tools/grep-search.js.map +1 -1
- package/dist/tools/plan-mode.js +3 -3
- package/dist/tools/plan-mode.js.map +1 -1
- package/dist/tools/registry.js +1 -1
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/sub-agent.d.ts +9 -0
- package/dist/tools/sub-agent.d.ts.map +1 -0
- package/dist/tools/sub-agent.js +232 -0
- package/dist/tools/sub-agent.js.map +1 -0
- package/dist/tools/task-complete.d.ts.map +1 -1
- package/dist/tools/task-complete.js +14 -32
- package/dist/tools/task-complete.js.map +1 -1
- package/dist/ui/components/App.d.ts +45 -0
- package/dist/ui/components/App.d.ts.map +1 -1
- package/dist/ui/components/App.js +598 -95
- package/dist/ui/components/App.js.map +1 -1
- package/dist/ui/components/CircularSelectInput.d.ts +24 -0
- package/dist/ui/components/CircularSelectInput.d.ts.map +1 -0
- package/dist/ui/components/CircularSelectInput.js +71 -0
- package/dist/ui/components/CircularSelectInput.js.map +1 -0
- package/dist/ui/components/ErrorBoundary.d.ts +3 -2
- package/dist/ui/components/ErrorBoundary.d.ts.map +1 -1
- package/dist/ui/components/ErrorBoundary.js +29 -1
- package/dist/ui/components/ErrorBoundary.js.map +1 -1
- package/dist/ui/components/InputBox.d.ts +4 -0
- package/dist/ui/components/InputBox.d.ts.map +1 -1
- package/dist/ui/components/InputBox.js +40 -2
- package/dist/ui/components/InputBox.js.map +1 -1
- package/dist/ui/components/InteractiveShell.d.ts +6 -0
- package/dist/ui/components/InteractiveShell.d.ts.map +1 -1
- package/dist/ui/components/InteractiveShell.js +57 -6
- package/dist/ui/components/InteractiveShell.js.map +1 -1
- package/dist/ui/components/MCPAddScreen.d.ts +13 -0
- package/dist/ui/components/MCPAddScreen.d.ts.map +1 -0
- package/dist/ui/components/MCPAddScreen.js +54 -0
- package/dist/ui/components/MCPAddScreen.js.map +1 -0
- package/dist/ui/components/MCPListScreen.d.ts +17 -0
- package/dist/ui/components/MCPListScreen.d.ts.map +1 -0
- package/dist/ui/components/MCPListScreen.js +50 -0
- package/dist/ui/components/MCPListScreen.js.map +1 -0
- package/dist/ui/components/MCPServerListScreen.d.ts +16 -0
- package/dist/ui/components/MCPServerListScreen.d.ts.map +1 -0
- package/dist/ui/components/MCPServerListScreen.js +59 -0
- package/dist/ui/components/MCPServerListScreen.js.map +1 -0
- package/dist/ui/components/MonitorModeAIPanel.d.ts +23 -0
- package/dist/ui/components/MonitorModeAIPanel.d.ts.map +1 -0
- package/dist/ui/components/MonitorModeAIPanel.js +69 -0
- package/dist/ui/components/MonitorModeAIPanel.js.map +1 -0
- package/dist/ui/components/MultiLineInput.d.ts +13 -0
- package/dist/ui/components/MultiLineInput.d.ts.map +1 -0
- package/dist/ui/components/MultiLineInput.js +223 -0
- package/dist/ui/components/MultiLineInput.js.map +1 -0
- package/dist/ui/components/StatusBar.d.ts +2 -0
- package/dist/ui/components/StatusBar.d.ts.map +1 -1
- package/dist/ui/components/StatusBar.js +33 -2
- package/dist/ui/components/StatusBar.js.map +1 -1
- package/dist/ui/components/ToolExecutionMessage.d.ts.map +1 -1
- package/dist/ui/components/ToolExecutionMessage.js +271 -12
- package/dist/ui/components/ToolExecutionMessage.js.map +1 -1
- package/dist/ui/components/VersionUpdatePrompt.d.ts.map +1 -1
- package/dist/ui/components/VersionUpdatePrompt.js +3 -2
- package/dist/ui/components/VersionUpdatePrompt.js.map +1 -1
- package/dist/utils/editor-utils.d.ts +3 -3
- package/dist/utils/editor-utils.d.ts.map +1 -1
- package/dist/utils/editor-utils.js +15 -12
- package/dist/utils/editor-utils.js.map +1 -1
- package/dist/utils/input-classifier.d.ts.map +1 -1
- package/dist/utils/input-classifier.js +1 -0
- package/dist/utils/input-classifier.js.map +1 -1
- package/dist/utils/terminal-output.d.ts.map +1 -1
- package/dist/utils/terminal-output.js +198 -171
- package/dist/utils/terminal-output.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import stripAnsi from 'strip-ansi';
|
|
2
|
+
/**
|
|
3
|
+
* Input Requirement Detector Service
|
|
4
|
+
*
|
|
5
|
+
* Monitors shell output and detects when user input is required.
|
|
6
|
+
* Used by the agent control mode to know when to prompt the AI for input.
|
|
7
|
+
*/
|
|
8
|
+
// Common patterns that indicate input is required
|
|
9
|
+
const INPUT_PATTERNS = [
|
|
10
|
+
// Password prompts
|
|
11
|
+
/password\s*[:\>]/i,
|
|
12
|
+
/enter\s+password/i,
|
|
13
|
+
/\[sudo\]\s+password/i,
|
|
14
|
+
/passphrase/i,
|
|
15
|
+
// Y/N confirmations
|
|
16
|
+
/\[y\/n\]/i,
|
|
17
|
+
/\[yes\/no\]/i,
|
|
18
|
+
/\(y\/n\)/i,
|
|
19
|
+
/\(yes\/no\)/i,
|
|
20
|
+
/continue\s*\?/i,
|
|
21
|
+
/proceed\s*\?/i,
|
|
22
|
+
/are\s+you\s+sure\s*\?/i,
|
|
23
|
+
/overwrite\s*\?/i,
|
|
24
|
+
/replace\s*\?/i,
|
|
25
|
+
/delete\s*\?/i,
|
|
26
|
+
/confirm\s*[:\?]/i,
|
|
27
|
+
// Generic input prompts (ending with : or ? followed by whitespace or end)
|
|
28
|
+
/:\s*$/,
|
|
29
|
+
/\?\s*$/,
|
|
30
|
+
// npm init and similar prompts
|
|
31
|
+
/^\s*name:\s*\(/i,
|
|
32
|
+
/^\s*version:\s*\(/i,
|
|
33
|
+
/^\s*description:\s*$/i,
|
|
34
|
+
/^\s*entry\s+point:\s*\(/i,
|
|
35
|
+
/^\s*test\s+command:\s*$/i,
|
|
36
|
+
/^\s*git\s+repository:\s*$/i,
|
|
37
|
+
/^\s*keywords:\s*$/i,
|
|
38
|
+
/^\s*author:\s*$/i,
|
|
39
|
+
/^\s*license:\s*\(/i,
|
|
40
|
+
/is\s+this\s+ok\s*\?/i,
|
|
41
|
+
// Read-Host in PowerShell
|
|
42
|
+
/Read-Host/i,
|
|
43
|
+
// Git prompts
|
|
44
|
+
/username\s+for/i,
|
|
45
|
+
/password\s+for/i,
|
|
46
|
+
// SSH prompts
|
|
47
|
+
/are\s+you\s+sure\s+you\s+want\s+to\s+continue\s+connecting/i,
|
|
48
|
+
/\(yes\/no\/\[fingerprint\]\)/i,
|
|
49
|
+
// Press any key / press enter
|
|
50
|
+
/press\s+(any\s+key|enter|return)/i,
|
|
51
|
+
// Choice prompts
|
|
52
|
+
/choice\s*[:\>]/i,
|
|
53
|
+
/select\s+(option|choice)\s*[:\>]/i,
|
|
54
|
+
/\[\d+\]\s+.*:\s*$/i, // Numbered menu items ending with :
|
|
55
|
+
];
|
|
56
|
+
// Patterns that indicate the command is still producing output (not waiting)
|
|
57
|
+
const ACTIVE_OUTPUT_PATTERNS = [
|
|
58
|
+
/\.\.\./, // Progress indicator
|
|
59
|
+
/downloading/i,
|
|
60
|
+
/installing/i,
|
|
61
|
+
/compiling/i,
|
|
62
|
+
/building/i,
|
|
63
|
+
/running/i,
|
|
64
|
+
/starting/i,
|
|
65
|
+
/processing/i,
|
|
66
|
+
/%/, // Percentage progress
|
|
67
|
+
/\[\s*=+\s*\]/, // Progress bar
|
|
68
|
+
];
|
|
69
|
+
/**
|
|
70
|
+
* Default timeout in ms to consider output as "stalled" (waiting for input)
|
|
71
|
+
*/
|
|
72
|
+
export const DEFAULT_STALL_TIMEOUT_MS = 2000;
|
|
73
|
+
/**
|
|
74
|
+
* Detects if the shell output indicates that user input is required.
|
|
75
|
+
*
|
|
76
|
+
* @param output - The complete shell output so far
|
|
77
|
+
* @param timeSinceLastOutput - Time in ms since last output was received (optional)
|
|
78
|
+
* @param stallTimeoutMs - Timeout in ms to consider output stalled (default: 2000)
|
|
79
|
+
* @returns Detection result with confidence level
|
|
80
|
+
*/
|
|
81
|
+
// Patterns that should be IGNORED even if they look like prompts (e.g. system shell prompts)
|
|
82
|
+
const IGNORED_PATTERNS = [
|
|
83
|
+
/PS\s+[A-Z]:\\.*>\s*$/i, // PowerShell prompt: PS C:\path>
|
|
84
|
+
/^[A-Z]:\\.*>\s*$/i, // CMD prompt: C:\path>
|
|
85
|
+
/^\s*>\s*$/, // Single chevron prompt often seen in transitions
|
|
86
|
+
/user@.*[:\$]\s*$/i, // Bash style: user@host:$
|
|
87
|
+
/bash-[\d\.]+\$\s*$/i, // Bash prompt
|
|
88
|
+
];
|
|
89
|
+
export function detectInputRequirement(output, timeSinceLastOutput, stallTimeoutMs = DEFAULT_STALL_TIMEOUT_MS) {
|
|
90
|
+
// Get the last few lines of output for analysis
|
|
91
|
+
const lines = output.split('\n').filter(line => line.trim());
|
|
92
|
+
// Safety check for empty lines
|
|
93
|
+
if (lines.length === 0) {
|
|
94
|
+
return { requiresInput: false, confidence: 'low', lastLine: '' };
|
|
95
|
+
}
|
|
96
|
+
// Get raw last line
|
|
97
|
+
const rawLastLine = lines[lines.length - 1];
|
|
98
|
+
// Sanitize: strip ANSI codes and trim whitespace
|
|
99
|
+
const cleanLastLine = stripAnsi(rawLastLine).trim();
|
|
100
|
+
// Check against IGNORED patterns first
|
|
101
|
+
if (IGNORED_PATTERNS.some(pattern => pattern.test(cleanLastLine))) {
|
|
102
|
+
return { requiresInput: false, confidence: 'low', lastLine: cleanLastLine };
|
|
103
|
+
}
|
|
104
|
+
// Get last 3 lines, stripped of ANSI
|
|
105
|
+
const last3LinesRaw = lines.slice(-3).join('\n');
|
|
106
|
+
const cleanLast3Lines = stripAnsi(last3LinesRaw);
|
|
107
|
+
const lastLine = cleanLastLine; // Use cleaned version for matching
|
|
108
|
+
const last3Lines = cleanLast3Lines;
|
|
109
|
+
// Check if output appears to be actively producing content
|
|
110
|
+
const isActiveOutput = ACTIVE_OUTPUT_PATTERNS.some(pattern => pattern.test(last3Lines));
|
|
111
|
+
// Check for explicit input patterns with high confidence in last line
|
|
112
|
+
for (const pattern of INPUT_PATTERNS) {
|
|
113
|
+
if (pattern.test(lastLine)) {
|
|
114
|
+
return {
|
|
115
|
+
requiresInput: true,
|
|
116
|
+
confidence: 'high',
|
|
117
|
+
matchedPattern: pattern.toString(),
|
|
118
|
+
lastLine
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Check the last 3 lines for patterns (slightly lower confidence)
|
|
123
|
+
for (const pattern of INPUT_PATTERNS) {
|
|
124
|
+
if (pattern.test(last3Lines)) {
|
|
125
|
+
return {
|
|
126
|
+
requiresInput: true,
|
|
127
|
+
confidence: 'medium',
|
|
128
|
+
matchedPattern: pattern.toString(),
|
|
129
|
+
lastLine
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// If output has stalled and no active patterns, might be waiting for input
|
|
134
|
+
if (timeSinceLastOutput !== undefined && timeSinceLastOutput > stallTimeoutMs && !isActiveOutput) {
|
|
135
|
+
// Check if last line looks like a prompt (ends with common prompt characters)
|
|
136
|
+
if (/[:\>\?\$\#]\s*$/.test(lastLine)) {
|
|
137
|
+
return {
|
|
138
|
+
requiresInput: true,
|
|
139
|
+
confidence: 'low',
|
|
140
|
+
matchedPattern: 'stall_with_prompt_ending',
|
|
141
|
+
lastLine
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
requiresInput: false,
|
|
147
|
+
confidence: 'high',
|
|
148
|
+
lastLine
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get a human-readable description of what type of input is likely required.
|
|
153
|
+
* This is useful for constructing the AI prompt.
|
|
154
|
+
*
|
|
155
|
+
* @param result - The detection result
|
|
156
|
+
* @returns Description of the expected input type
|
|
157
|
+
*/
|
|
158
|
+
export function getInputTypeDescription(result) {
|
|
159
|
+
if (!result.requiresInput || !result.matchedPattern) {
|
|
160
|
+
return 'unknown input';
|
|
161
|
+
}
|
|
162
|
+
const pattern = result.matchedPattern.toLowerCase();
|
|
163
|
+
if (pattern.includes('password') || pattern.includes('passphrase')) {
|
|
164
|
+
return 'password or passphrase';
|
|
165
|
+
}
|
|
166
|
+
if (pattern.includes('y/n') || pattern.includes('yes/no') || pattern.includes('sure')) {
|
|
167
|
+
return 'yes/no confirmation';
|
|
168
|
+
}
|
|
169
|
+
if (pattern.includes('continue') || pattern.includes('proceed') || pattern.includes('confirm')) {
|
|
170
|
+
return 'confirmation to proceed';
|
|
171
|
+
}
|
|
172
|
+
if (pattern.includes('press')) {
|
|
173
|
+
return 'key press (enter or any key)';
|
|
174
|
+
}
|
|
175
|
+
if (pattern.includes('choice') || pattern.includes('select')) {
|
|
176
|
+
return 'selection from options';
|
|
177
|
+
}
|
|
178
|
+
return 'text input';
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Extract the prompt question from the output for context.
|
|
182
|
+
* This helps the AI understand what is being asked.
|
|
183
|
+
*
|
|
184
|
+
* @param output - The complete shell output
|
|
185
|
+
* @returns The prompt/question being asked
|
|
186
|
+
*/
|
|
187
|
+
export function extractPromptContext(output) {
|
|
188
|
+
const lines = output.split('\n').filter(line => line.trim());
|
|
189
|
+
// Get last 5 lines for context
|
|
190
|
+
const contextLines = lines.slice(-5);
|
|
191
|
+
// Find the line that looks most like a prompt
|
|
192
|
+
for (let i = contextLines.length - 1; i >= 0; i--) {
|
|
193
|
+
const line = stripAnsi(contextLines[i]).trim();
|
|
194
|
+
// If line ends with a prompt character and isn't empty
|
|
195
|
+
if (line && /[:\>\?\$\#]\s*$/.test(line)) {
|
|
196
|
+
return line;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Just return the last non-empty line
|
|
200
|
+
const lastLine = contextLines[contextLines.length - 1] || '';
|
|
201
|
+
return stripAnsi(lastLine).trim();
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=input-requirement-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-requirement-detector.js","sourceRoot":"","sources":["../../src/services/input-requirement-detector.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC;;;;;GAKG;AAEH,kDAAkD;AAClD,MAAM,cAAc,GAAG;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,sBAAsB;IACtB,aAAa;IAEb,oBAAoB;IACpB,WAAW;IACX,cAAc;IACd,WAAW;IACX,cAAc;IACd,gBAAgB;IAChB,eAAe;IACf,wBAAwB;IACxB,i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,EAAE,CAAC;IAC7D,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monitored Shell Manager Service
|
|
3
|
+
*
|
|
4
|
+
* Manages agent-controlled shell sessions, detecting when input is required
|
|
5
|
+
* and coordinating with the AI to provide appropriate responses.
|
|
6
|
+
*/
|
|
7
|
+
import { InputDetectionResult } from './input-requirement-detector.js';
|
|
8
|
+
/**
|
|
9
|
+
* Represents a message displayed during monitoring mode
|
|
10
|
+
*/
|
|
11
|
+
export interface MonitorMessage {
|
|
12
|
+
id: string;
|
|
13
|
+
type: 'thinking' | 'tool_call' | 'text' | 'input_sent';
|
|
14
|
+
content: string;
|
|
15
|
+
timestamp: Date;
|
|
16
|
+
isAnswered?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Represents an active monitored shell session
|
|
20
|
+
*/
|
|
21
|
+
export interface MonitoredShellSession {
|
|
22
|
+
shellId: string;
|
|
23
|
+
command: string;
|
|
24
|
+
cwd: string;
|
|
25
|
+
output: string;
|
|
26
|
+
isRunning: boolean;
|
|
27
|
+
lastOutputTime: number;
|
|
28
|
+
monitoringMessages: MonitorMessage[];
|
|
29
|
+
inputCheckInterval?: NodeJS.Timeout;
|
|
30
|
+
onInputRequired?: (session: MonitoredShellSession, detectionResult: InputDetectionResult) => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Callback when the AI needs to be prompted for shell input
|
|
34
|
+
*/
|
|
35
|
+
export type OnAIInputRequestCallback = (shellId: string, shellOutput: string, promptContext: string, inputType: string) => Promise<string | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Monitored Shell Manager
|
|
38
|
+
*
|
|
39
|
+
* Handles tracking of agent-controlled shells and coordinating input detection.
|
|
40
|
+
*/
|
|
41
|
+
declare class MonitoredShellManagerClass {
|
|
42
|
+
private sessions;
|
|
43
|
+
private onAIInputRequest?;
|
|
44
|
+
private onMonitoringMessage?;
|
|
45
|
+
private inputCheckIntervalMs;
|
|
46
|
+
private shellIdCounter;
|
|
47
|
+
/**
|
|
48
|
+
* Generate a unique shell ID
|
|
49
|
+
*/
|
|
50
|
+
generateShellId(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Set the callback for requesting AI input
|
|
53
|
+
*/
|
|
54
|
+
setOnAIInputRequest(callback: OnAIInputRequestCallback): void;
|
|
55
|
+
/**
|
|
56
|
+
* Set the callback for new monitoring messages
|
|
57
|
+
*/
|
|
58
|
+
setOnMonitoringMessage(callback: (shellId: string, message: MonitorMessage) => void): void;
|
|
59
|
+
/**
|
|
60
|
+
* Start monitoring a shell session
|
|
61
|
+
*/
|
|
62
|
+
startMonitoring(shellId: string, command: string, cwd: string, onInputRequired?: (session: MonitoredShellSession, detectionResult: InputDetectionResult) => void): MonitoredShellSession;
|
|
63
|
+
/**
|
|
64
|
+
* Stop monitoring a shell session
|
|
65
|
+
*/
|
|
66
|
+
stopMonitoring(shellId: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Update shell output for a monitored session
|
|
69
|
+
*/
|
|
70
|
+
updateOutput(shellId: string, newOutput: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Mark a shell session as complete
|
|
73
|
+
*/
|
|
74
|
+
markComplete(shellId: string): void;
|
|
75
|
+
/**
|
|
76
|
+
* Get a session by ID
|
|
77
|
+
*/
|
|
78
|
+
getSession(shellId: string): MonitoredShellSession | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Check if a specific shell session is active
|
|
81
|
+
*/
|
|
82
|
+
isSessionActive(shellId: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Get all active shell IDs
|
|
85
|
+
*/
|
|
86
|
+
getActiveShellIds(): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Add a monitoring message to a session
|
|
89
|
+
*/
|
|
90
|
+
addMonitoringMessage(shellId: string, type: MonitorMessage['type'], content: string): MonitorMessage;
|
|
91
|
+
/**
|
|
92
|
+
* Get monitoring messages for a session
|
|
93
|
+
*/
|
|
94
|
+
getMonitoringMessages(shellId: string): MonitorMessage[];
|
|
95
|
+
/**
|
|
96
|
+
* Clear monitoring messages for a session
|
|
97
|
+
*/
|
|
98
|
+
clearMonitoringMessages(shellId: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Mark the most recent 'thinking' message as answered
|
|
101
|
+
* This changes the spinner to a tick in the UI
|
|
102
|
+
*/
|
|
103
|
+
markLastThinkingAsAnswered(shellId: string): void;
|
|
104
|
+
/**
|
|
105
|
+
* Check if a shell requires input and trigger AI prompt if needed
|
|
106
|
+
*/
|
|
107
|
+
private checkForInputRequirement;
|
|
108
|
+
/**
|
|
109
|
+
* Build a prompt for the AI to provide shell input
|
|
110
|
+
* This is used when the AI needs to decide what to input
|
|
111
|
+
*/
|
|
112
|
+
buildInputPrompt(shellOutput: string, promptContext: string, inputType: string, originalCommand: string): string;
|
|
113
|
+
/**
|
|
114
|
+
* Get the last N lines of output
|
|
115
|
+
*/
|
|
116
|
+
private getLastNLines;
|
|
117
|
+
}
|
|
118
|
+
export declare const MonitoredShellManager: MonitoredShellManagerClass;
|
|
119
|
+
export {};
|
|
120
|
+
//# sourceMappingURL=monitored-shell-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitored-shell-manager.d.ts","sourceRoot":"","sources":["../../src/services/monitored-shell-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAyE,oBAAoB,EAA4B,MAAM,iCAAiC,CAAC;AAGxK;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,GAAG,YAAY,CAAC;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;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EG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAWrC;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAQtD;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQnC;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;IAI9D;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIzC;;OAEG;IACH,iBAAiB,IAAI,MAAM,EAAE;IAI7B;;OAEG;IACH,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc;IAqBpG;;OAEG;IACH,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,EAAE;IAIxD;;OAEG;IACH,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO9C;;;OAGG;IACH,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAejD;;OAEG;YACW,wBAAwB;IA6CtC;;;OAGG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM;IAuBhH;;OAEG;IACH,OAAO,CAAC,aAAa;CAIxB;AAGD,eAAO,MAAM,qBAAqB,4BAAmC,CAAC"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monitored Shell Manager Service
|
|
3
|
+
*
|
|
4
|
+
* Manages agent-controlled shell sessions, detecting when input is required
|
|
5
|
+
* and coordinating with the AI to provide appropriate responses.
|
|
6
|
+
*/
|
|
7
|
+
import { detectInputRequirement, extractPromptContext, getInputTypeDescription } from './input-requirement-detector.js';
|
|
8
|
+
import { quickLog } from '../utils/conversation-logger.js';
|
|
9
|
+
/**
|
|
10
|
+
* Monitored Shell Manager
|
|
11
|
+
*
|
|
12
|
+
* Handles tracking of agent-controlled shells and coordinating input detection.
|
|
13
|
+
*/
|
|
14
|
+
class MonitoredShellManagerClass {
|
|
15
|
+
sessions = new Map();
|
|
16
|
+
onAIInputRequest;
|
|
17
|
+
onMonitoringMessage;
|
|
18
|
+
inputCheckIntervalMs = 500;
|
|
19
|
+
shellIdCounter = 0;
|
|
20
|
+
/**
|
|
21
|
+
* Generate a unique shell ID
|
|
22
|
+
*/
|
|
23
|
+
generateShellId() {
|
|
24
|
+
this.shellIdCounter++;
|
|
25
|
+
return `shell-${Date.now()}-${this.shellIdCounter}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Set the callback for requesting AI input
|
|
29
|
+
*/
|
|
30
|
+
setOnAIInputRequest(callback) {
|
|
31
|
+
this.onAIInputRequest = callback;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set the callback for new monitoring messages
|
|
35
|
+
*/
|
|
36
|
+
setOnMonitoringMessage(callback) {
|
|
37
|
+
this.onMonitoringMessage = callback;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Start monitoring a shell session
|
|
41
|
+
*/
|
|
42
|
+
startMonitoring(shellId, command, cwd, onInputRequired) {
|
|
43
|
+
// Clean up any existing session with the same ID
|
|
44
|
+
this.stopMonitoring(shellId);
|
|
45
|
+
const session = {
|
|
46
|
+
shellId,
|
|
47
|
+
command,
|
|
48
|
+
cwd,
|
|
49
|
+
output: '',
|
|
50
|
+
isRunning: true,
|
|
51
|
+
lastOutputTime: Date.now(),
|
|
52
|
+
monitoringMessages: [],
|
|
53
|
+
onInputRequired
|
|
54
|
+
};
|
|
55
|
+
// Start periodic input detection
|
|
56
|
+
session.inputCheckInterval = setInterval(() => {
|
|
57
|
+
this.checkForInputRequirement(shellId);
|
|
58
|
+
}, this.inputCheckIntervalMs);
|
|
59
|
+
this.sessions.set(shellId, session);
|
|
60
|
+
quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Started monitoring shell ${shellId}: ${command}\n`);
|
|
61
|
+
return session;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Stop monitoring a shell session
|
|
65
|
+
*/
|
|
66
|
+
stopMonitoring(shellId) {
|
|
67
|
+
const session = this.sessions.get(shellId);
|
|
68
|
+
if (session) {
|
|
69
|
+
if (session.inputCheckInterval) {
|
|
70
|
+
clearInterval(session.inputCheckInterval);
|
|
71
|
+
}
|
|
72
|
+
this.sessions.delete(shellId);
|
|
73
|
+
quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Stopped monitoring shell ${shellId}\n`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Update shell output for a monitored session
|
|
78
|
+
*/
|
|
79
|
+
updateOutput(shellId, newOutput) {
|
|
80
|
+
const session = this.sessions.get(shellId);
|
|
81
|
+
if (session) {
|
|
82
|
+
session.output += newOutput;
|
|
83
|
+
session.lastOutputTime = Date.now();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Mark a shell session as complete
|
|
88
|
+
*/
|
|
89
|
+
markComplete(shellId) {
|
|
90
|
+
const session = this.sessions.get(shellId);
|
|
91
|
+
if (session) {
|
|
92
|
+
session.isRunning = false;
|
|
93
|
+
this.stopMonitoring(shellId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get a session by ID
|
|
98
|
+
*/
|
|
99
|
+
getSession(shellId) {
|
|
100
|
+
return this.sessions.get(shellId);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Check if a specific shell session is active
|
|
104
|
+
*/
|
|
105
|
+
isSessionActive(shellId) {
|
|
106
|
+
return this.sessions.has(shellId);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get all active shell IDs
|
|
110
|
+
*/
|
|
111
|
+
getActiveShellIds() {
|
|
112
|
+
return Array.from(this.sessions.keys());
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Add a monitoring message to a session
|
|
116
|
+
*/
|
|
117
|
+
addMonitoringMessage(shellId, type, content) {
|
|
118
|
+
const session = this.sessions.get(shellId);
|
|
119
|
+
const message = {
|
|
120
|
+
id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
121
|
+
type,
|
|
122
|
+
content,
|
|
123
|
+
timestamp: new Date()
|
|
124
|
+
};
|
|
125
|
+
if (session) {
|
|
126
|
+
session.monitoringMessages.push(message);
|
|
127
|
+
// Callback to notify UI
|
|
128
|
+
if (this.onMonitoringMessage) {
|
|
129
|
+
this.onMonitoringMessage(shellId, message);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return message;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get monitoring messages for a session
|
|
136
|
+
*/
|
|
137
|
+
getMonitoringMessages(shellId) {
|
|
138
|
+
return this.sessions.get(shellId)?.monitoringMessages || [];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Clear monitoring messages for a session
|
|
142
|
+
*/
|
|
143
|
+
clearMonitoringMessages(shellId) {
|
|
144
|
+
const session = this.sessions.get(shellId);
|
|
145
|
+
if (session) {
|
|
146
|
+
session.monitoringMessages = [];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Mark the most recent 'thinking' message as answered
|
|
151
|
+
* This changes the spinner to a tick in the UI
|
|
152
|
+
*/
|
|
153
|
+
markLastThinkingAsAnswered(shellId) {
|
|
154
|
+
const session = this.sessions.get(shellId);
|
|
155
|
+
if (session) {
|
|
156
|
+
// Find the last 'thinking' message that isn't already answered
|
|
157
|
+
for (let i = session.monitoringMessages.length - 1; i >= 0; i--) {
|
|
158
|
+
const msg = session.monitoringMessages[i];
|
|
159
|
+
if (msg.type === 'thinking' && !msg.isAnswered) {
|
|
160
|
+
msg.isAnswered = true;
|
|
161
|
+
quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Marked message ${msg.id} as answered\n`);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Check if a shell requires input and trigger AI prompt if needed
|
|
169
|
+
*/
|
|
170
|
+
async checkForInputRequirement(shellId) {
|
|
171
|
+
const session = this.sessions.get(shellId);
|
|
172
|
+
if (!session || !session.isRunning) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const timeSinceLastOutput = Date.now() - session.lastOutputTime;
|
|
176
|
+
const result = detectInputRequirement(session.output, timeSinceLastOutput);
|
|
177
|
+
if (result.requiresInput && result.confidence !== 'low') {
|
|
178
|
+
quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Input detected for ${shellId}: ${result.matchedPattern}\n`);
|
|
179
|
+
// Notify session callback
|
|
180
|
+
if (session.onInputRequired) {
|
|
181
|
+
session.onInputRequired(session, result);
|
|
182
|
+
}
|
|
183
|
+
// Request AI input
|
|
184
|
+
if (this.onAIInputRequest) {
|
|
185
|
+
const promptContext = extractPromptContext(session.output);
|
|
186
|
+
const inputType = getInputTypeDescription(result);
|
|
187
|
+
// Add "thinking" message
|
|
188
|
+
this.addMonitoringMessage(shellId, 'thinking', 'Analyzing shell prompt...');
|
|
189
|
+
try {
|
|
190
|
+
const aiInput = await this.onAIInputRequest(shellId, session.output, promptContext, inputType);
|
|
191
|
+
if (aiInput !== null) {
|
|
192
|
+
// Add message showing what input was sent
|
|
193
|
+
this.addMonitoringMessage(shellId, 'input_sent', `Sent input: ${aiInput}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Error requesting AI input: ${error.message}\n`);
|
|
198
|
+
this.addMonitoringMessage(shellId, 'text', `Error: ${error.message}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Build a prompt for the AI to provide shell input
|
|
205
|
+
* This is used when the AI needs to decide what to input
|
|
206
|
+
*/
|
|
207
|
+
buildInputPrompt(shellOutput, promptContext, inputType, originalCommand) {
|
|
208
|
+
return `The command "${originalCommand}" is currently running and requires user input.
|
|
209
|
+
|
|
210
|
+
**Current shell output (last 50 lines):**
|
|
211
|
+
\`\`\`
|
|
212
|
+
${this.getLastNLines(shellOutput, 50)}
|
|
213
|
+
\`\`\`
|
|
214
|
+
|
|
215
|
+
**The command is asking for:** ${promptContext}
|
|
216
|
+
|
|
217
|
+
**Expected input type:** ${inputType}
|
|
218
|
+
|
|
219
|
+
Please provide the appropriate input to respond to this prompt. Use the execute_command tool with the shell_input parameter to send your response.
|
|
220
|
+
|
|
221
|
+
Guidelines:
|
|
222
|
+
- For yes/no prompts, respond with "y" or "n" (or "yes"/"no" if the prompt requires full words)
|
|
223
|
+
- For password prompts, you should NOT provide passwords - ask the user to handle this manually
|
|
224
|
+
- For npm init style prompts, provide reasonable defaults or press Enter for default values
|
|
225
|
+
- For other prompts, provide the most appropriate response based on context
|
|
226
|
+
|
|
227
|
+
If this appears to be a security-sensitive prompt (passwords, authentication), respond with a message indicating the user should handle this manually.`;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Get the last N lines of output
|
|
231
|
+
*/
|
|
232
|
+
getLastNLines(text, n) {
|
|
233
|
+
const lines = text.split('\n');
|
|
234
|
+
return lines.slice(-n).join('\n');
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// Export singleton instance
|
|
238
|
+
export const MonitoredShellManager = new MonitoredShellManagerClass();
|
|
239
|
+
//# sourceMappingURL=monitored-shell-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitored-shell-manager.js","sourceRoot":"","sources":["../../src/services/monitored-shell-manager.ts"],"names":[],"mappings":"A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