-
Notifications
You must be signed in to change notification settings - Fork 72
feat(gateway): add interactive invoke console #1978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0b5893
feat(gateway): add interactive invoke console
aidandaly24 900d0af
fix(tui): keep long multiline input within its rows
aidandaly24 a536851
fix(gateway): refine path editor and session labels
aidandaly24 cad95f3
style(gateway): use neutral path dialog border
aidandaly24 418fe96
fix(gateway): make idle escape navigate back
aidandaly24 fdbfe3a
fix(gateway): allow no-content responses in TUI
aidandaly24 3e0bb88
refactor(invoke): simplify TUI launch errors
aidandaly24 53ba0d3
test(gateway): allow TUI startup on slow runners
aidandaly24 6489a5d
test(gateway): inject invoke TUI renderer
aidandaly24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { useState } from "react"; | ||
| import cliTruncate from "cli-truncate"; | ||
| import { Box, Text, useInput, useWindowSize } from "ink"; | ||
| import { darkTheme } from "./ui/_core.js"; | ||
|
|
||
| const theme = darkTheme; | ||
| const PREVIEW_LINES = 4; | ||
|
|
||
| export interface MultilineInputProps { | ||
| value: string; | ||
| onChange: (value: string) => void; | ||
| onSubmit: () => void; | ||
| placeholder?: string; | ||
| submitDisabled?: boolean; | ||
| focus?: boolean; | ||
| } | ||
|
|
||
| function Cursor({ character }: { character: string }) { | ||
| return ( | ||
| <Text color={theme.colors.focus} inverse> | ||
| {character} | ||
| </Text> | ||
| ); | ||
| } | ||
|
|
||
| export function MultilineInput({ | ||
| value, | ||
| onChange, | ||
| onSubmit, | ||
| placeholder = "Enter text", | ||
| submitDisabled = false, | ||
| focus = true, | ||
| }: MultilineInputProps) { | ||
| const { columns } = useWindowSize(); | ||
| const [rawCursor, setRawCursor] = useState(value.length); | ||
| const cursor = Math.min(rawCursor, value.length); | ||
|
|
||
| useInput( | ||
| (input, key) => { | ||
| if (key.leftArrow) { | ||
| setRawCursor(Math.max(0, cursor - 1)); | ||
| return; | ||
| } | ||
| if (key.rightArrow) { | ||
| setRawCursor(Math.min(value.length, cursor + 1)); | ||
| return; | ||
| } | ||
| if (key.upArrow || key.downArrow) return; | ||
|
|
||
| if (key.backspace || key.delete) { | ||
| if (cursor === 0) return; | ||
| onChange(value.slice(0, cursor - 1) + value.slice(cursor)); | ||
| setRawCursor(cursor - 1); | ||
| return; | ||
| } | ||
|
|
||
| if (key.return) { | ||
| if (key.shift || key.meta) { | ||
| onChange(value.slice(0, cursor) + "\n" + value.slice(cursor)); | ||
| setRawCursor(cursor + 1); | ||
| } else if (!submitDisabled) { | ||
| onSubmit(); | ||
| } | ||
| return; | ||
| } | ||
| if (key.ctrl || key.meta || key.escape || input === "") return; | ||
|
|
||
| const next = input.replace(/\r/g, "\n"); | ||
| onChange(value.slice(0, cursor) + next + value.slice(cursor)); | ||
| setRawCursor(cursor + next.length); | ||
| }, | ||
| { isActive: focus }, | ||
| ); | ||
|
|
||
| if (value === "") { | ||
| return ( | ||
| <Box> | ||
| <Cursor character={placeholder[0] ?? " "} /> | ||
| <Text color={theme.colors.muted}>{placeholder.slice(1)}</Text> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| const lines = value.split("\n"); | ||
| const beforeCursor = value.slice(0, cursor); | ||
| const cursorLine = beforeCursor.split("\n").length - 1; | ||
| const lastNewline = beforeCursor.lastIndexOf("\n"); | ||
| const cursorColumn = cursor - lastNewline - 1; | ||
| const start = Math.max(0, cursorLine - PREVIEW_LINES + 1); | ||
| const visible = lines.slice(start, start + PREVIEW_LINES); | ||
|
|
||
| return ( | ||
| <Box flexDirection="column"> | ||
| {visible.map((line, index) => { | ||
| const lineIndex = start + index; | ||
| const prefix = index === 0 && start > 0 ? "… " : ""; | ||
| if (lineIndex !== cursorLine) { | ||
| return ( | ||
| <Box key={lineIndex} width={columns}> | ||
| <Text wrap="truncate-end">{cliTruncate(`${prefix}${line || " "}`, columns)}</Text> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| const horizontalMarker = cursorColumn >= columns - prefix.length ? "… " : ""; | ||
| const available = Math.max(1, columns - prefix.length - horizontalMarker.length); | ||
| const offset = Math.max(0, cursorColumn - available + 1); | ||
| const before = line.slice(offset, cursorColumn); | ||
| const at = line[cursorColumn] ?? " "; | ||
| const after = line.slice( | ||
| cursorColumn + 1, | ||
| cursorColumn + 1 + Math.max(0, available - before.length - 1), | ||
| ); | ||
| return ( | ||
| <Box key={lineIndex} width={columns}> | ||
| <Text color={theme.colors.border}>{prefix}</Text> | ||
| <Text color={theme.colors.border}>{horizontalMarker}</Text> | ||
| {before ? <Text>{before}</Text> : null} | ||
| <Cursor character={at} /> | ||
| {after ? <Text>{after}</Text> : null} | ||
| </Box> | ||
| ); | ||
| })} | ||
| </Box> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this break the pattern of tui only no flags? If so, could this be confusing for customers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but Runtime invoke already follows this pattern where a missing
--payloadlaunches the TUI. I think it technically could be a little bit confusing, but I personally think there's are a couple good reasons for why we should keep it this way. For one, we wanted to keep the TUI simple to start. When building runtime invoke I built an advanced options menu, which was accessible in the invoke TUI via a ctrl + key command. This added complexity to the code and we thought it would be better to start simple and layer this complexity on top in the future. So to keep these configurations accessible, I opted to not open the TUI on no--payload. Second, I think for things like--session-idit is more intuitive to pass it in via the CLI before opening the agent than after opening up the agent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The harness invoke TUI is also not strictly no-flags only so I think it's okay to break the pattern on invoke for now.
I think it'd be worthwhile though to have a conversation about this with the team though.