Add support for interactive command line execution where user input is sent to stdin

This commit is contained in:
Saoud Rizwan
2024-07-29 13:22:06 -04:00
parent 0e4000e1f2
commit cf2ab16538
4 changed files with 68 additions and 30 deletions

View File

@@ -108,6 +108,13 @@ const ChatView = ({ messages, isHidden, vscodeThemeName, showAnnouncement, hideA
setPrimaryButtonText("Run Command")
setSecondaryButtonText("Reject")
break
case "command_output":
setTextAreaDisabled(false)
setClaudeAsk("command_output")
setEnableButtons(true)
setPrimaryButtonText("Exit Command Early")
setSecondaryButtonText(undefined)
break
case "completion_result":
// extension waiting for feedback. but we can just present a new task button
setTextAreaDisabled(false)
@@ -131,8 +138,6 @@ const ChatView = ({ messages, isHidden, vscodeThemeName, showAnnouncement, hideA
break
case "text":
break
case "command_output":
break
case "completion_result":
break
}
@@ -168,6 +173,7 @@ const ChatView = ({ messages, isHidden, vscodeThemeName, showAnnouncement, hideA
case "followup":
case "tool":
case "command": // user can provide feedback to a tool or command use
case "command_output": // user can send input to command stdin
case "completion_result": // if this happens then the user has feedback for the completion result
vscode.postMessage({ type: "askResponse", askResponse: "textResponse", text })
break
@@ -191,6 +197,7 @@ const ChatView = ({ messages, isHidden, vscodeThemeName, showAnnouncement, hideA
case "request_limit_reached":
case "api_req_failed":
case "command":
case "command_output":
case "tool":
vscode.postMessage({ type: "askResponse", askResponse: "yesButtonTapped" })
break
@@ -315,6 +322,13 @@ const ChatView = ({ messages, isHidden, vscodeThemeName, showAnnouncement, hideA
return () => clearTimeout(timer)
}, [visibleMessages])
const placeholderText = useMemo(() => {
if (messages.at(-1)?.ask === "command_output") {
return "Type input for command stdin..."
}
return task ? "Type a message..." : "Type your task here..."
}, [task, messages])
return (
<div
style={{
@@ -425,7 +439,7 @@ const ChatView = ({ messages, isHidden, vscodeThemeName, showAnnouncement, hideA
//virtuosoRef.current?.scrollToIndex({ index: "LAST", align: "end", behavior: "auto" })
virtuosoRef.current?.scrollTo({ top: Number.MAX_SAFE_INTEGER, behavior: "auto" })
}
placeholder={task ? "Type a message..." : "Type your task here..."}
placeholder={placeholderText}
maxRows={10}
autoFocus={true}
style={{

View File

@@ -14,8 +14,8 @@ import { ClaudeMessage } from "@shared/ExtensionMessage"
* @example
* const messages: ClaudeMessage[] = [
* { type: 'ask', ask: 'command', text: 'ls', ts: 1625097600000 },
* { type: 'say', say: 'command_output', text: 'file1.txt', ts: 1625097601000 },
* { type: 'say', say: 'command_output', text: 'file2.txt', ts: 1625097602000 }
* { type: 'ask', ask: 'command_output', text: 'file1.txt', ts: 1625097601000 },
* { type: 'ask', ask: 'command_output', text: 'file2.txt', ts: 1625097602000 }
* ];
* const result = simpleCombineCommandSequences(messages);
* // Result: [{ type: 'ask', ask: 'command', text: 'ls\nfile1.txt\nfile2.txt', ts: 1625097600000 }]
@@ -35,7 +35,7 @@ export function combineCommandSequences(messages: ClaudeMessage[]): ClaudeMessag
// Stop if we encounter the next command
break
}
if (messages[j].type === "say" && messages[j].say === "command_output") {
if (messages[j].type === "ask" && messages[j].ask === "command_output") {
if (!didAddOutput) {
// Add a newline before the first output
combinedText += `\n${COMMAND_OUTPUT_STRING}`
@@ -57,7 +57,7 @@ export function combineCommandSequences(messages: ClaudeMessage[]): ClaudeMessag
// Second pass: remove command_outputs and replace original commands with combined ones
return messages
.filter((msg) => !(msg.type === "say" && msg.say === "command_output"))
.filter((msg) => !(msg.type === "ask" && msg.ask === "command_output"))
.map((msg) => {
if (msg.type === "ask" && msg.ask === "command") {
const combinedCommand = combinedCommands.find((cmd) => cmd.ts === msg.ts)