در حال بارگذاری ...

Tasks in Markdown0:08

All right, I'm gonna warn you this next thing I'm about to show you is wild. You're not gonna believe it. Okay? So this is called the Ralph Wickham Technique. After the Simpsons character, and I don't even wanna tell you what it is right now, I just wanna show you, check this out. For Layer Cast, let's say I have a handful of tasks and issues that need to get done. Why don't we store those within a markdown file,

and issues that need to get done. Why don't we store those within a markdown file, like tasks.md, but they could just as easily be issues on GitHub. Okay, let me paste this in and these are actual things I need to get done. Alright, so, uh, we retired thumbnails for topics. So we just wanna find any lingering references to the thumbnail, whether it's an Innova resource or a view component, and clear it out.

to the thumbnail, whether it's an Innova resource or a view component, and clear it out. Next. Uh, when we fetch our categories, we normally sort them by series count, but let's say we want to promote the DevOps category and we want that one to always be at the top. Let's implement that. Alright, standard stuff. Now I could manually copy these into an agent, but it would be cool if it could just read these and one after the other, knock them out.

Creating Ralph Script1:06

but it would be cool if it could just read these and one after the other, knock them out. So let's figure out how In full screen, in my sidebar, let's create a new shell script within my then directory. We'll call it Ralph. Now of course this is gonna be a shell script and ultimately our script is gonna run clawed, right? But let me save ourselves some keystrokes by pasting this in. Alright, so we're gonna run Claude

keystrokes by pasting this in. Alright, so we're gonna run Claude and I'll set the permissions mode. Now, if you're in a container or you live dangerously, then you can dangerously skip permission, but we're not gonna do that in this case. Okay, so now we have a here doc with the multi-line string, and this is our prompt. So just run Claude, uh, and pass it this prompt. Alright, step one, read the markdown file. Got it.

So just run Claude, uh, and pass it this prompt. Alright, step one, read the markdown file. Got it. Step two, choose one, emphasis on one task and implement it. Great. Step three, commit your change. Step four, update the task file and document the changes basically within a progress section. All right, let's add that now progress and we'll get it started here.

All right, let's add that now progress and we'll get it started here. And yeah, at least for an initial proof of concept, this would work. Now keep in mind we're not in a loop yet, but yet the core action is in place here. Okay? So the key thing I want you to be aware of, bring it in. The key thing is that Ralph is focusing on one thing at a time.

Refining the Prompt2:24

The key thing is that Ralph is focusing on one thing at a time. It's not working through all of those tasks. That's part of the same process and the same context. It's doing one thing and then it's done. Okay? So yeah, in real life I would have information here about testing and formatting. So why don't we tweak this a little bit? Okay? So a slight tweak, but better. Let's have a look.

So why don't we tweak this a little bit? Okay? So a slight tweak, but better. Let's have a look. Read the markdown file, find a suitable incomplete task and implement it. And you can only work on one that's very important. Next, include tests where practical and then run our suite. And you are not done until it returns green. And that's a really important hook for agents. Give it something to, to verify, uh, completion. Next, run our formatter that does rector and peach P stand.

Give it something to, to verify, uh, completion. Next, run our formatter that does rector and peach P stand. Commit your changes and document what you did and you're done. And yeah, really that's it. So keep in mind we're not in a loop yet, but the core action here, uh, is solid. Let's give it a shot. Let's switch back to two up. Hi again, let's open up the terminal. I'm gonna do a quick work in progress, uh, for our plan

Running a Single Task3:29

Hi again, let's open up the terminal. I'm gonna do a quick work in progress, uh, for our plan and then let's run our script. But of course we can't execute it until we modify it. So let's make it executable, Ben, Ralph, and here we go. Let's go. And we're done. It's crazy, right? It's wild. And if I run, get log, here is the commit. And if I take a look at the plan, here's the progress it made, okay?

And if I take a look at the plan, here's the progress it made, okay? So that is a single run, but now imagine we're in a loop and it can run 10 or 20 times to knock out every single issue or task that you have. I'll show you. Let's run it one more time then Ralph. All right, so it consumes it. Notice it's using the same prompt over and over. That's the entire point. All right? It can tell that this one has been completed.

Looping Through Tasks4:21

That's the entire point. All right? It can tell that this one has been completed. So now it's gonna start working on the second task. And I'm not gonna let that complete. You get the gist. Okay? So now let's put it within a loop. Okay? So now I effectively want to keep this clogged call, but have it run endlessly or at least seemingly endlessly. So why don't we start by wrapping it within a wild statement while true, then do this. Yeah. And actually in this case, you know what?

while true, then do this. Yeah. And actually in this case, you know what? I think it's squawking. I may have an issue with spaces and tabs. Let's just turn that off entirely and then bring it back. Yeah, okay, so now we're calling Claude endlessly. And that's not good. Even if there's nothing else to do, it just keeps running over and over and over. So we need some kind of exit ramp. Let's see how, all right, let's add one more item here.

So we need some kind of exit ramp. Let's see how, all right, let's add one more item here. If there are no remaining tasks, create a file. And this can be anything you want. It doesn't matter, it's just a flag. It's a hook to tell us, okay, we're done here, we can exit out of the loop. Okay, so now check this out. Let's check, uh, do we have a file and what is it, Ralph Complete?

Let's check, uh, do we have a file and what is it, Ralph Complete? If so, then we're done, right? Then we can exit zero and that will exit out of the loop. Why don't we also say echo, all tasks are now complete and then let's clean up after ourselves and yeah, we're done. So yeah, this file based approach, uh, has a couple benefits. So we run Claude continuously until that file exists.

has a couple benefits. So we run Claude continuously until that file exists. If it does, that is our hook that we can exit out of the loop and we're done with all of the tasks. Now here's an issue though. We, we wanna handle a scenario where something goes wrong and maybe this never gets created, and then c Claude just runs on an endless loop potentially through the night. Uh, why don't we have a limit here?

potentially through the night. Uh, why don't we have a limit here? A little bit of protection at most. We can go through the loop, 10 or 20 times, whatever you want. In that case, we should swap out the while with a four. Let's have Junie help us add some context. When I run this script, I want to set a maximum number of loops that are permitted. So I'd like to swap out the wild true with a for loop,

of loops that are permitted. So I'd like to swap out the wild true with a for loop, and that will reference the number of iterations that I pass in. For example 10. Let's go. Alright, that was done super quickly. Alright, so now we can pass through iterations and we go up to that number again. That's just, it's, it's a fail safe. Okay, so now why don't we specify

That's just, it's, it's a fail safe. Okay, so now why don't we specify how many loops it took at the end update and include the number of loops it took to get here. All right, that's done. And it just added that, okay, I thought it might do something fancier. Okay, so I wanna try this out. So let's go through the entire workflow. I have tasks do MD I specify all of the issues

So let's go through the entire workflow. I have tasks do MD I specify all of the issues or things that I want the agent to work on. Next I have our Ralph script. This is going to loop over a maximum number of times that I pass in maybe 10 or 20. And for each loop it's going to run clawed and figure out one item that it can tackle. Now, if it gets to the point where there's nothing left to work on, then it will create this file

Now, if it gets to the point where there's nothing left to work on, then it will create this file and that is our exit ramp to kill the loop and be done. Okay, I'm ready to try this out then Ralph and expand. All right, get your popcorn. All right, so it decided to work on the first task, but it didn't have to. Okay, so this is done, but real quick, notice it doesn't automatically continue onto the next task, but that's only because we're running this in interactive

notice it doesn't automatically continue onto the next task, but that's only because we're running this in interactive mode effectively so that we can view the output, but you can turn that off and then it instantly moves on to the next item. For now though, we would have to exit out of the agent and then it will continue the loop as you see in just a second. All right, and now it moves on to number two. So yeah, while this is finishing up, keep that in mind.

All right, and now it moves on to number two. So yeah, while this is finishing up, keep that in mind. It's just a trade off. If you want the full interactive mode where you're viewing all of the processing in real time, well then you're gonna have to manually close it out after each loop. But once you're comfortable and things are working flawlessly, switch over to non-interactive mode and it's done. So we should now have two commits for all of that work.

Non-Interactive and Permissions8:36

to non-interactive mode and it's done. So we should now have two commits for all of that work. And if I return to our tasks, both of these are complete. Okay, so now I just wanna wrap up with two or three little notes to be aware of. Let's return to our shell script. When you feel ready, turn on print or non-interactive mode. And yeah, this will get you around the issue where you have to manually exit out of clawed in order to continue the loop.

to manually exit out of clawed in order to continue the loop. Uh, so keep it off while you're getting your feet wet, figuring out what's going on and then turn it on. Next. In terms of permissions, again, if, if you're within a Docker container or you just like living dangerously, then you can turn on the dangerously skip permissions flag so that it will never prompt you. Otherwise, though, you need to make sure

so that it will never prompt you. Otherwise, though, you need to make sure that you pre-approve any permissions that it might request in non-interactive mode. Otherwise it'll just hang indefinitely. So here's what you can do if you go into your quad and you should have a settings local adjacent file. This specifies all of the permissions that you've approved. And I would recommend things like this. Make sure it can do, get, add

And I would recommend things like this. Make sure it can do, get, add and commit and check out and branch. If you're fine with it, making a PR or push, then include those as well or simply approve all Git commands. Um, we're going to, uh, approve the JetBrains, uh, MCP server, the Laravel Boost, any of the commands that runs there. Uh, I want it to run Composer. So I allow those.

of the commands that runs there. Uh, I want it to run Composer. So I allow those. I want it to run pests just to pre-approve anything that you are okay with it running. And then you should avoid any scenario where it makes a request to do something. But otherwise, yeah, again, do it in interactive mode for a little bit so that you can approve everything that's needed. Okay, so here's the reality. It goes much further than this.

that you can approve everything that's needed. Okay, so here's the reality. It goes much further than this. There are some pretty crazy things you can do. Just imagine a situation where you have an agent that works through all of the issues in your GitHub repository. Uh, there's a risk obviously, but it's also so incredibly cool. So there's more to share. Keep it locked to Laca and I'll be sure to show you.

Keep it locked to Laca and I'll be sure to show you.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟