Welcome back, future AI-powered developer! In the previous chapters, you’ve learned the basics of omp.sh, getting it set up and using its core commands for quick coding tasks. But what happens when a task isn’t a single, simple command? How do you guide an AI agent through a multi-step project, ensuring it stays on track and understands your complex requirements?
This chapter introduces two powerful features of omp.sh: Plan Mode and Goal Mode. These strategic modes elevate your interaction with the AI from simple commands to sophisticated problem-solving. We’ll explore how they enable you to break down intricate challenges, guide the AI’s thought process, and achieve complex objectives with greater control and confidence.
Why Strategic Modes Matter in AI-Assisted Development
Imagine you’re tasked with building a new feature or fixing a complex bug. As an experienced engineer, you wouldn’t just jump into coding without a strategy. You’d outline the steps, consider dependencies, and anticipate potential issues. Plan Mode and Goal Mode empower omp.sh to adopt a similar strategic approach, reflecting the structured thinking of human engineers. These modes are crucial for:
- Tackling Complexity: Breaking down large problems into manageable, sequential steps.
- Maintaining Control: Reviewing and approving the AI’s strategy before it makes changes.
- Ensuring Accuracy: Reducing the likelihood of the AI “hallucinating” or making incorrect assumptions.
By the end of this chapter, you’ll be able to:
- Understand the purpose and workflow of
omp.sh’s Plan Mode for structured execution. - Guide
omp.shto generate, review, and execute step-by-step plans for coding tasks. - Grasp the concept of Goal Mode for iterative, higher-level problem-solving.
- Initiate and monitor
omp.shas it autonomously works towards a defined objective.
Let’s unlock a new level of productivity and control in your AI-powered coding workflow!
Plan Mode: Structured Execution, Step-by-Step
omp.sh’s Plan Mode is your secret weapon for tackling tasks that require a clear sequence of actions. Instead of immediately generating code, the AI first proposes a detailed plan. This gives you a crucial opportunity to review, refine, and approve the strategy before any changes are made to your codebase.
What is Plan Mode?
📌 Key Idea: Plan Mode is a human-in-the-loop workflow where omp.sh first presents a structured sequence of steps to achieve a task, allowing you to approve or modify the plan before execution.
Think of yourself as the project manager and omp.sh as a highly skilled, albeit junior, engineer. When you give the engineer a complex task, they don’t just start coding; they first come back with a detailed proposal of how they’ll approach it. You review the proposal, suggest changes if needed, and only then give the green light for execution. This collaboration ensures alignment and reduces errors.
Why Plan Mode Exists
Plan Mode solves several critical challenges inherent in AI-assisted coding:
- Prevents “Hallucinations”: Without a clear structure, an AI might jump to incorrect conclusions or generate irrelevant code. A plan forces it to think through the logical steps required, reducing speculative output.
- Ensures Logical Progression: Complex tasks often demand a specific ordering of operations (e.g., “create file,” then “write content,” then “install dependencies”). Plan Mode enforces this necessary sequential logic.
- User Control and Safety: You remain in control. You can catch potential errors, refine the approach, or add missing steps before any code is written or files are modified. This is paramount for maintaining codebase integrity and preventing unintended changes.
- Clarity and Transparency: The plan provides a clear roadmap of the AI’s intended actions, making its process transparent and understandable.
How Plan Mode Works: The Workflow
The workflow for Plan Mode is straightforward and designed for maximum control:
- You define a task: You provide
omp.shwith a clear, concise description of what you want to achieve. omp.shgenerates a plan: The agent analyzes your request and proposes a numbered list of actions it intends to take to fulfill the task.- You review the plan: You carefully examine each step. Does it make sense? Is anything missing? Are there better ways to achieve the objective?
- You approve or modify: You can accept the plan as-is, edit specific steps directly within the terminal (if
omp.shprovides this feature), or reject it and ask for a new one with refined instructions. omp.shexecutes the plan: Once approved, the agent proceeds through the steps, often pausing for your confirmation at each significant action (e.g., creating a new file, modifying existing code).
Step-by-Step Implementation: Using Plan Mode
Let’s guide omp.sh to create a simple Python script that lists all .txt files in the current directory.
Start with a Clean Slate: Ensure you’re in an empty directory or a safe test environment. Create a new directory and some sample files.
mkdir omp_plan_test cd omp_plan_test touch file1.txt file2.md report.txtNow you have a directory with two
.txtfiles and one.mdfile, providing a realistic scenario for the script.Initiate Plan Mode: Tell
omp.shyour task using theplancommand.omp plan "Create a Python script named 'list_txt_files.py' that finds and prints the names of all .txt files in the current directory."omp.shwill now process your request and present a proposed plan. The exact wording might vary based on the underlying AI model, but it will follow a logical sequence:> Planning to create 'list_txt_files.py' to list .txt files. Proposed Plan: 1. Create a new Python file named 'list_txt_files.py'. 2. Add necessary import statements (e.g., 'os' module). 3. Define a function to encapsulate the logic. 4. Get the current working directory. 5. Iterate through files in the current directory. 6. Check if each file has a '.txt' extension. 7. Print the name of each identified .txt file. 8. Add an entry point to run the function when the script is executed.Review and Approve the Plan: Carefully read each step. Does it cover everything? Is it logical? For our task, this plan looks solid and comprehensive.
omp.shwill prompt you for approval:Do you approve this plan? (y/n/edit)Type
yand press Enter to approve.Execute the Plan: Once approved,
omp.shwill begin executing the steps sequentially. It might pause at each step, asking for confirmation, especially when creating or modifying files.Executing step 1: Create a new Python file named 'list_txt_files.py'. (Press Enter to continue or 's' to skip)Press Enter to confirm each step. You’ll observe
omp.shgenerating and applying the code.After successful execution, you should have a
list_txt_files.pyfile in your directory. Its content should resemble:# list_txt_files.py import os def list_txt_files(): current_directory = os.getcwd() # List all entries in the directory, filter for files ending with '.txt' txt_files = [f for f in os.listdir(current_directory) if f.endswith('.txt') and os.path.isfile(os.path.join(current_directory, f))] for txt_file in txt_files: print(txt_file) if __name__ == "__main__": list_txt_files()Now, run the script to verify its functionality:
python list_txt_files.pyYou should see the names of your
.txtfiles printed:file1.txt report.txtCongratulations! You’ve successfully used Plan Mode to guide
omp.shthrough a structured task, ensuring each step was deliberate and reviewed.
Goal Mode: Iterative Problem-Solving
While Plan Mode is excellent for tasks with a known, sequential path, some problems are more open-ended. They might require trial-and-error, adapting to new information, or breaking down into sub-problems that aren’t immediately obvious. This is where Goal Mode shines, offering a more autonomous and adaptive approach.
What is Goal Mode?
🧠 Important: Goal Mode is a more autonomous and iterative approach where you define a desired end state, and omp.sh works towards achieving it, potentially adapting its strategy and learning from feedback.
In Goal Mode, you set a high-level objective, and omp.sh takes on more initiative to figure out the best path. It might internally generate and execute mini-plans, try different approaches, and leverage its “hindsight memory” (a concept we’ll explore in a later chapter) to learn from past attempts and refine its strategy over time. This makes it ideal for more exploratory or complex refactoring tasks.
Why Goal Mode Exists
Goal Mode is designed specifically for complex, multi-faceted problems that don’t fit a simple, linear plan:
- Longer-term Objectives: For tasks that cannot be solved in a single
planandapplycycle, requiring multiple steps, evaluations, and adjustments. - Exploratory Tasks: When you’re not entirely sure of the exact steps needed, but you know the desired outcome. The AI can explore possibilities.
- Autonomous Iteration:
omp.shcan make small changes, test them (if configured to do so), observe the results, and then decide on the next steps, much like a human engineer debugging or refactoring code iteratively. - Adapting to Feedback: If an initial approach fails or doesn’t fully meet the criteria, Goal Mode allows the AI to learn from that attempt and adjust its subsequent actions.
How Goal Mode Works: The Iterative Process
- You define a goal: You tell
omp.shthe ultimate state you want to achieve, focusing on the what rather than the how. omp.shstarts working: The agent begins to strategize, often breaking the high-level goal into smaller, manageable sub-tasks internally.- Iterative execution:
omp.shmight propose actions, execute code, observe output or file changes, and then decide on the next best step based on its progress and internal reasoning. - Human oversight: You can monitor its progress, ask for explanations (
omp goal --explain), and intervene if the agent appears to be going off track or needs clarification. The interaction is often less about approving every minor step and more about steering the overall direction.
Step-by-Step Implementation: Using Goal Mode
Let’s use Goal Mode to refactor our list_txt_files.py script. We’ll ask omp.sh to update it to use Python’s pathlib module (a more modern and object-oriented way to handle file paths) and to add basic error handling for directory access issues. This is a more complex task than simply creating a file from scratch.
Ensure you’re in the
omp_plan_testdirectory. If you’ve moved,cdback into your test directory.Initiate Goal Mode: Tell
omp.shyour high-level goal using thegoalcommand.omp goal "Refactor 'list_txt_files.py' to use the pathlib module instead of os.path, and add error handling for directory access issues."omp.shwill acknowledge the goal and begin its iterative process. You might see initial output like:> Goal set: Refactor 'list_txt_files.py' to use the pathlib module instead of os.path, and add error handling for directory access issues. Working towards goal...The agent will then start to propose and execute actions. Unlike Plan Mode where you approve a full plan upfront, in Goal Mode, you typically approve smaller, individual actions or blocks of changes as
omp.shdiscovers them to achieve the overall goal.You might see it propose a series of changes:
- Reading
list_txt_files.pyto understand its current state. - Identifying
osmodule usage that can be replaced bypathlib. - Proposing specific code changes to import
pathlib.Path. - Modifying the file listing logic to use
Path.cwd().iterdir(). - Adding
try-exceptblocks for robust error handling around directory operations.
omp.shwill likely present you with diffs (differences) or proposed code changes and ask for your approval before applying them.Proposed change for 'list_txt_files.py': ```diff --- a/list_txt_files.py +++ b/list_txt_files.py @@ -1,10 +1,14 @@ import os +from pathlib import Path def list_txt_files(): - current_directory = os.getcwd() - txt_files = [f for f in os.listdir(current_directory) if f.endswith('.txt') and os.path.isfile(os.path.join(current_directory, f))] - for txt_file in txt_files: - print(txt_file) + try: + current_directory = Path.cwd() + # iterdir() yields Path objects, is_file() checks if it's a file, suffix gets the extension + txt_files = [f.name for f in current_directory.iterdir() if f.is_file() and f.suffix == '.txt'] + for txt_file in txt_files: + print(txt_file) + except OSError as e: + print(f"Error accessing directory: {e}") if __name__ == "__main__": list_txt_files()Apply this change? (y/n/edit)Type
yand press Enter.omp.shwill continue to work towards the goal until it believes the goal is met or it needs further input from you.- Reading
Monitor Progress and Intervene: Goal Mode can be more hands-off, but it’s important to monitor its progress. If
omp.shseems stuck, is making unexpected changes, or if you simply want to understand its current thinking, you can use:omp goal --explainThis command will provide insight into the agent’s current strategy, its progress towards the goal, and its reasoning for the next steps, helping you guide it if necessary.
Once
omp.shindicates it has completed the goal, review thelist_txt_files.pyfile. It should now reflect the changes usingpathliband include the new error handling.# list_txt_files.py (after Goal Mode refactoring) from pathlib import Path def list_txt_files(): try: current_directory = Path.cwd() # iterdir() yields Path objects, is_file() checks if it's a file, suffix gets the extension txt_files = [f.name for f in current_directory.iterdir() if f.is_file() and f.suffix == '.txt'] for txt_file in txt_files: print(txt_file) except OSError as e: print(f"Error accessing directory: {e}") except Exception as e: # A more general catch for unexpected errors print(f"An unexpected error occurred: {e}") if __name__ == "__main__": list_txt_files()Run the updated script to confirm it still functions correctly:
python list_txt_files.pyYou should still see:
file1.txt report.txtNow, try running it from a directory where the script might not have read permissions (e.g.,
/rootif you’re not running as root, or a restricted system directory) to observe the error handling in action. This demonstrates the robustness added by Goal Mode.
Mini-Challenge: Building a Simple Web Server
Let’s combine what you’ve learned about Plan Mode and Goal Mode to build and enhance a small Node.js web server. This challenge will solidify your understanding of when to use each mode.
Challenge:
Part 1: Plan Mode - Create a Basic Express Server.
- Navigate to a fresh directory (e.g.,
mkdir omp_web_test && cd omp_web_test). - Use
omp planto create a new Node.js project. - The project should include an
app.jsfile that sets up an Express server listening on port3000. - It should have a single GET endpoint
/hellothat responds with the text “Hello from omp.sh!”. - Ensure
package.jsonis initialized andexpressis installed as a dependency. - Remember to review and approve
omp.sh’s plan carefully before execution!
- Navigate to a fresh directory (e.g.,
Part 2: Goal Mode - Enhance with a Dynamic Endpoint.
- Once the basic server is working (you can test it by running
node app.jsin your terminal and then visitinghttp://localhost:3000/helloin your web browser), useomp goalto add a new GET endpoint:/greet/:name. - This new endpoint should take a
namefrom the URL parameter and respond with “Hello, [name]!”. For example, navigating tohttp://localhost:3000/greet/Aliceshould respond “Hello, Alice!”. - Observe how
omp.shiterates and modifies the existingapp.jsfile to achieve this goal without you specifying every line change.
- Once the basic server is working (you can test it by running
Hint:
- For Part 1, your plan prompt could be:
"Create a Node.js Express server project with an 'app.js' file, listening on port 3000, and a '/hello' endpoint returning 'Hello from omp.sh!'. Ensure Express is installed and the project is ready to run." - For Part 2, your goal prompt could be:
"Add a new GET endpoint '/greet/:name' to 'app.js' that responds with 'Hello, [name]!' using the name from the URL parameter, to enhance the existing Express server." - Always be ready to type
yto approve actions or useomp goal --explainif you need clarification on the agent’s current thinking in Goal Mode. - Remember to stop the running
node app.jsprocess (Ctrl+C) beforeomp.shmodifiesapp.jsin Part 2, and then restart it to see the changes.
What to Observe/Learn:
- How
omp.shstructures a multi-file project setup (likepackage.json,node_modules,app.js) in Plan Mode. - The difference in interaction between the step-by-step confirmation of Plan Mode and the more iterative, autonomous nature of Goal Mode.
- How
omp.shintegrates new features into existing code without rewriting everything, demonstrating its contextual understanding.
Common Pitfalls & Troubleshooting
Even with powerful AI tools, you might encounter bumps along the way. Here are some common issues when using Plan Mode and Goal Mode with omp.sh and how to address them:
Overly Broad Plan Mode Tasks:
- Pitfall: Giving
omp planan extremely vague or massive task, such as"Build a full e-commerce website."The generated plan will likely be too high-level, missing crucial implementation details, or simply overwhelming to review. - Solution: Break down complex projects into smaller, more manageable plan-mode tasks. Use Plan Mode for individual components or features. For the “full e-commerce website” example, you might use
omp planto “set up a basic Express server,” then anotheromp planfor “add user authentication,” and so on.
- Pitfall: Giving
Ignoring Plan Review:
- Pitfall: Blindly typing
yto approve a plan without carefully reading it. This is a significant risk, as it can lead toomp.shtaking actions you didn’t intend, creating incorrect files, or introducing bugs into your codebase. - Solution: Always take a moment to read and understand the proposed plan. If a step seems wrong, missing, or could be improved, use the
editoption (ifomp.shprovides in-terminal editing) or typento reject the plan and refine your prompt with more specific instructions.
- Pitfall: Blindly typing
Lack of Context in Goal Mode:
- Pitfall: Setting a goal in a directory with no relevant files, or without providing necessary initial context.
omp.shmight struggle to understand where to start, what files to modify, or what the existing codebase structure is. - Solution: Ensure
omp.shhas access to the relevant codebase. If starting a new project, use Plan Mode for the initial setup. If refactoring, ensure the files to be modified are present and accessible. Useomp goal --explainfrequently to understand its current thinking and provide clarifying instructions if needed.
- Pitfall: Setting a goal in a directory with no relevant files, or without providing necessary initial context.
Infinite Loops or Stalling in Goal Mode:
- Pitfall: Sometimes,
omp.shmight get stuck in a loop, trying the same approach repeatedly if it’s not making progress, or it might stall without clear next steps. - Solution: If you notice this, interrupt the process (Ctrl+C). Re-evaluate your goal prompt. Is it clear enough? Is the task actually achievable in the current context? You might need to break the goal into smaller, more defined sub-goals, provide more specific hints about libraries or approaches, or switch to Plan Mode for a specific, difficult sub-task.
- Pitfall: Sometimes,
Summary
You’ve taken a significant leap in leveraging omp.sh for advanced coding tasks, moving beyond simple commands to strategic problem-solving!
Here are the key takeaways from this chapter:
- Plan Mode provides a structured, human-in-the-loop approach for executing tasks. It emphasizes review and explicit approval of a step-by-step plan before any code is generated or modified, offering maximum control and safety.
- You initiate Plan Mode using
omp plan "Your task here". After reviewing the proposed plan, you typically typey(oryes) to approve its execution. - Goal Mode offers a more autonomous and iterative method for tackling complex, open-ended problems. You define a desired end state, and
omp.shworks towards it, adapting its strategy and learning from feedback along the way. - You set an objective in Goal Mode using
omp goal "Your goal here". Useomp goal --explainto understand the agent’s current thought process and progress. - For both modes, always review proposed actions and changes carefully. Providing clear, precise instructions is crucial for optimal results and to guide the AI effectively.
- Breaking down large problems into smaller, focused tasks is a best practice for both modes, preventing overwhelm and improving accuracy.
In the next chapter, we’ll dive deeper into how omp.sh integrates with your development environment through LSP/DAP Integration. This will allow for even smarter code understanding, intelligent suggestions, and enhanced debugging capabilities directly within your terminal.
References
omp.shOfficial SDK Documentation: https://omp.sh/docs/sdk- GitHub -
can1357/oh-my-pi: AI Coding agent for the terminal: https://github.com/can1357/oh-my-pi - Python
pathlibModule Documentation: https://docs.python.org/3/library/pathlib.html - Express.js Official Website: https://expressjs.com/
This page is AI-assisted and reviewed. It references official documentation and recognized resources where relevant.