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.sh to 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.sh as 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:

  1. You define a task: You provide omp.sh with a clear, concise description of what you want to achieve.
  2. omp.sh generates a plan: The agent analyzes your request and proposes a numbered list of actions it intends to take to fulfill the task.
  3. You review the plan: You carefully examine each step. Does it make sense? Is anything missing? Are there better ways to achieve the objective?
  4. You approve or modify: You can accept the plan as-is, edit specific steps directly within the terminal (if omp.sh provides this feature), or reject it and ask for a new one with refined instructions.
  5. omp.sh executes 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.

  1. 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.txt

    Now you have a directory with two .txt files and one .md file, providing a realistic scenario for the script.

  2. Initiate Plan Mode: Tell omp.sh your task using the plan command.

    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.sh will 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.
  3. 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.sh will prompt you for approval:

    Do you approve this plan? (y/n/edit)

    Type y and press Enter to approve.

  4. Execute the Plan: Once approved, omp.sh will 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.sh generating and applying the code.

    After successful execution, you should have a list_txt_files.py file 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.py

    You should see the names of your .txt files printed:

    file1.txt
    report.txt

    Congratulations! You’ve successfully used Plan Mode to guide omp.sh through 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 plan and apply cycle, 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.sh can 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

  1. You define a goal: You tell omp.sh the ultimate state you want to achieve, focusing on the what rather than the how.
  2. omp.sh starts working: The agent begins to strategize, often breaking the high-level goal into smaller, manageable sub-tasks internally.
  3. Iterative execution: omp.sh might propose actions, execute code, observe output or file changes, and then decide on the next best step based on its progress and internal reasoning.
  4. 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.

  1. Ensure you’re in the omp_plan_test directory. If you’ve moved, cd back into your test directory.

  2. Initiate Goal Mode: Tell omp.sh your high-level goal using the goal command.

    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.sh will 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.sh discovers them to achieve the overall goal.

    You might see it propose a series of changes:

    • Reading list_txt_files.py to understand its current state.
    • Identifying os module usage that can be replaced by pathlib.
    • Proposing specific code changes to import pathlib.Path.
    • Modifying the file listing logic to use Path.cwd().iterdir().
    • Adding try-except blocks for robust error handling around directory operations.

    omp.sh will 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 y and press Enter. omp.sh will continue to work towards the goal until it believes the goal is met or it needs further input from you.

  3. Monitor Progress and Intervene: Goal Mode can be more hands-off, but it’s important to monitor its progress. If omp.sh seems stuck, is making unexpected changes, or if you simply want to understand its current thinking, you can use:

    omp goal --explain

    This 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.sh indicates it has completed the goal, review the list_txt_files.py file. It should now reflect the changes using pathlib and 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.py

    You should still see:

    file1.txt
    report.txt

    Now, try running it from a directory where the script might not have read permissions (e.g., /root if 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:

  1. 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 plan to create a new Node.js project.
    • The project should include an app.js file that sets up an Express server listening on port 3000.
    • It should have a single GET endpoint /hello that responds with the text “Hello from omp.sh!”.
    • Ensure package.json is initialized and express is installed as a dependency.
    • Remember to review and approve omp.sh’s plan carefully before execution!
  2. Part 2: Goal Mode - Enhance with a Dynamic Endpoint.

    • Once the basic server is working (you can test it by running node app.js in your terminal and then visiting http://localhost:3000/hello in your web browser), use omp goal to add a new GET endpoint: /greet/:name.
    • This new endpoint should take a name from the URL parameter and respond with “Hello, [name]!”. For example, navigating to http://localhost:3000/greet/Alice should respond “Hello, Alice!”.
    • Observe how omp.sh iterates and modifies the existing app.js file to achieve this goal without you specifying every line change.

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 y to approve actions or use omp goal --explain if you need clarification on the agent’s current thinking in Goal Mode.
  • Remember to stop the running node app.js process (Ctrl+C) before omp.sh modifies app.js in Part 2, and then restart it to see the changes.

What to Observe/Learn:

  • How omp.sh structures a multi-file project setup (like package.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.sh integrates 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 plan an 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 plan to “set up a basic Express server,” then another omp plan for “add user authentication,” and so on.
  • Ignoring Plan Review:

    • Pitfall: Blindly typing y to approve a plan without carefully reading it. This is a significant risk, as it can lead to omp.sh taking 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 edit option (if omp.sh provides in-terminal editing) or type n to reject the plan and refine your prompt with more specific instructions.
  • Lack of Context in Goal Mode:

    • Pitfall: Setting a goal in a directory with no relevant files, or without providing necessary initial context. omp.sh might struggle to understand where to start, what files to modify, or what the existing codebase structure is.
    • Solution: Ensure omp.sh has 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. Use omp goal --explain frequently to understand its current thinking and provide clarifying instructions if needed.
  • Infinite Loops or Stalling in Goal Mode:

    • Pitfall: Sometimes, omp.sh might 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.

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 type y (or yes) 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.sh works 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". Use omp goal --explain to 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

This page is AI-assisted and reviewed. It references official documentation and recognized resources where relevant.