-
Notifications
You must be signed in to change notification settings - Fork 18
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
Studio: Add dynamic code block to execute wp-cli commands UI AI assistant #232
Studio: Add dynamic code block to execute wp-cli commands UI AI assistant #232
Conversation
@@ -115,6 +115,7 @@ | |||
"hpagent": "1.2.0", | |||
"react-markdown": "^9.0.1", | |||
"semver": "^7.6.0", | |||
"strip-ansi": "^7.1.0", |
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.
This was necessary to strip ANSI that comes in the output from CLI - otherwise, the Error and Success messages contain ANSI characters and manually removing them is quite tedious as it is hard to match all of them. I felt like this was appropriate to use
@katinthehatsite nice work! Note that there are some errors in |
}, 2300 ); | ||
}, [ content, id, projectPath, updateMessage ] ); | ||
|
||
return { |
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.
[Suggestion]: I find it a bit repetitive. As we call it like this:
const {
cliOutput,
cliStatus,
cliTime,
isRunning,
handleExecute,
setCliOutput,
setCliStatus,
setCliTime,
} = useExecuteWPCLI( content, projectPath, updateMessage, id );
it is clear enough that this comes from cli.
I suggest to rename them to:
output,
status,
time
setOutput,
setStatus,
setTime
src/components/chat-messages.tsx
Outdated
if ( blocks ) { | ||
const block = blocks?.find( ( block ) => block.codeBlockContent === content ); | ||
if ( block ) { | ||
setCliOutput( block?.cliOutput ? stripAnsi( block.cliOutput ) : null ); |
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.
[Suggestion] I suggest to change that to setBlock
, as this is what those variables actually represent
Something that still needs to be looked into but documenting it here for the reviewers:
|
Let's also avoid displaying the Run button if the wp command has some placeholder |
|
||
export interface Message { | ||
export type Message = { | ||
id?: number; |
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.
I am not 100% sure if this should stay optional or must be mandatory.
Hi @sejas, since our conversation earlier this morning, I have done the following:
The only other thing I see is that it seems that E2E tests are timing out on Windows 🤔 For the horizontal scroll, I suggest we open a separate issue and handle it in the follow-up. I am not seeing an obvious fix right away and I would prefer to merge the PR asap as it is starting to grow quite large. What do you think? Let me know what you think of the changes! |
…te-cli-button-to-execute-in-code-block
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.
Works as expected.
It keeps the result after changing sites and tabs.
@katinthehatsite , great work!
0Hwa8f.mp4
const containsWPCommand = /\bwp\s/.test( content ); | ||
const wpCommandCount = ( content.match( /\bwp\s/g ) || [] ).length; | ||
const containsSingleWPCommand = wpCommandCount === 1; | ||
const containsAngleBrackets = /<.*>/.test( content ); |
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.
We can add more conditions to make this code block only available in a few commands.
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.
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.
I created a PR with improvements in this area.
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.
Noting that I have also seen the Assistant exclude wrapping characters altogether for placeholder content, which complicates things a good bit. I suppose the only solution for this case would be adjusting the Assistant prompt in hopes that it avoids this approach or searching for example
terms (which is undoubtedly brittle).
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.
Oh, I haven't encountered that but yes, that definitely complicates the detection of placeholders. As you pointed out, seems the best approach would be to tweak the prompt to ensure it uses the same placeholder to avoid cases like this one.
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.
I noted a few issues after pulling these changes. I share them here merely to raise awareness. I'll open a PR addressing them.
@@ -34,6 +40,7 @@ export function CopyTextButton( { | |||
} | |||
setTimeoutId( setTimeout( () => setShowCopied( false ), timeoutConfirmation ) ); | |||
}, [ text, timeoutConfirmation, timeoutId ] ); | |||
console.log( 'Icon Size:', iconSize ); |
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.
I suggest we remove this console log. I presume its addition was oversight.
} ) => ( | ||
<> | ||
{ messages.map( ( message, index ) => ( | ||
<ChatMessage key={ index } id={ `message-${ index }` } isUser={ message.role === 'user' }> |
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.
It appears the id
attribute was removed. The removal introduces a regression where screen readers are no longer able to navigate each message as a group, which was enabled in #248.
I presume this was oversight and likely originates from a merge conflict resolution.
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.
Thanks for catching these and adding the PR to fix. Yeah that was a large conflict merge
Related to https://github.com/Automattic/dotcom-forge/issues/7526
Proposed Changes
This PR adds that dynamic code block that allows to execute CLI commands inside that block. It also does the following:
Run
button is disabled for code blocks that don't have CLI commandsTesting Instructions
STUDIO_AI=true npm start
Run
buttonPre-merge Checklist