eTechtips

Tech Tips and Insights

Category: Uncategorized

  • AI: Limit Retry loops for debugging sessions

    I have been working on some passion projects recently and occasionally when the implementation caused some parts of the application to fail I noticed that the AI session seemed to be stuck in a loop of retrying to fix the issue. While I have mostly been using free tier AI models, this concerned me as it could be spending too many of my tokens try more and more complex fixes for what is sometimes a simple fix. So I looked into how to limit retries and then prompt me for suggestions about the issues.

    So I looked into the process to implement error handling and limit the retry loops. I found that updating the AGENTS.md file was one step but depending on the model I wanted to go a step further and implement hard guardrails in the base opencode.json as well.

    This should be added to the
    ~/.config/opencode/AGENTS.md on macOS/Linux or the %USERPROFILE%\.config\opencode\AGENTS.md on windows

    ## Error Handling & Retry Limits
    - **Strict 2-Retry Cap:** When running builds, tests, or commands (`./gradlew`, `php artisan test`, `composer`, etc.) or attempting to fix a bug, you are allowed a maximum of **2 fix attempts** for the same error or failing task.
    - **Stop & Ask for Clarity:** If the error persists after 2 retries (3 total runs including the initial attempt), **STOP immediately**. Do not edit any more files or run further commands.
    - **Required Handoff:** Use the `question` tool (or reply directly) to ask the user for clarification. Briefly summarize:
      1. What failed and the exact error message.
      2. The 2 approaches you already tried and why they didn't work.
      3. What specific context, constraint, or manual check you need from the user before continuing.
    

    This rule acts as a circuit breaker that stops the AI from endlessly guessing and burning through tokens when it gets stuck on a bug. If an error isn’t fixed after two retry attempts, it forces the AI to stop editing files and immediately hand control back to you. Instead of continuing to guess, the AI must pause and give you a quick summary of what broke, what it already tried, and what help or context it needs from you to move forward.

    To implement the hard guard rails the should be added to the ~/.config/opencode/opencode.json file on macOS/Linux and %USERPROFILE%\.config\opencode\opencode.json file on windows

    {
      "$schema": "https://opencode.ai/config.json",
      "permission": {
        "doom_loop": "ask"
      },
      "agent": {
        "build": {
          "steps": 12
        }
      }
    }
    

    This configuration acts as a hard safety net to keep OpenCode from getting stuck in expensive loops. The $schema line enables autocomplete and error-checking in your editor, "doom_loop": "ask" pauses the agent and asks for your approval if it tries to repeat the exact same action three times in a row, and "steps": 12 caps the build agent at 12 total tool actions (such as file reads, edits, or terminal commands) per prompt before forcing it to stop and respond to you with text.

    0 Comments
  • AI: Auto commit while programming with Opencode

    I recently was editing a few different web applications and mistakenly ran an update that affected the wrong site and all my sidebar navigation was gone. This was not evident for a few days when I went to update my music practice app and all navigation had disappeared. I had not been reliably committing to get so I looked into how to Auto commit to git so that this would not happen again.

    I started with a Background plugin approach and while this would save myself from trouble I had caused, the commit messages were only time stamped.

    BackGround Plugin Method

    Make the plugins directory either in the project root or in the ~/.config/opencode/plugins.

    mkdir -p .opencode/plugins
    import type { Plugin } from "@opencode-ai/plugin"
    
    export const AutoCommitPlugin: Plugin = async ({ $ }) => {
      return {
        event: async ({ event }) => {
          // Fires when the agent finishes processing a prompt
          if (event.type === "session.idle") {
            try {
              // Check if there are any modified or untracked files
              const status = await $`git status --porcelain`.text()
              if (!status.trim()) return
    
              // Stage all changes and commit with a timestamp
              await $`git add -A`
              const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19)
              await $`git commit -m "opencode: auto-commit (${timestamp})"`
            } catch (err) {
              // Silently ignore if not in a git repo or nothing to commit
            }
          }
        },
      }
    }

    Verification: Start opencode in your project directory, ask it to make a small edit (e.g., adding a comment to a file), and once it finishes, run git log -n 1 in a separate terminal to confirm the new commit appears.

    0 Comments
  • Git: Remove cached files from Git repo

    I was recently creating a git viewer in Python, I noticed that the cached files were showing up in the repo after my LLM process added all files. I need to remove them as I did not want to commit them to the repo.

    git rm -r cached **/__pycache__/

    If the “**” does not expand correctly in you prompt, then you may have to specify each root directory to be able to remove the cached files.

    NOTE: make sure the cached argument is included or it may remove file syou wanted to keep.

    0 Comments
  • Reset the Autoincrement column in MSSQL

    To reset the identity column in MSSQL use the following:

    DBCC CHECKIDENT (tablename, RESEED, 0)

    Just replace tablename with the table, and change the 0 to the number minus 1 that you want to have as the next row.

    For example, entering 0 (zero) will give the next row identity of 1.

    0 Comments
  • Vagrant: editing metadata_url file causes illegal character issue

    I was editing the ~/.vagrant.d/boxes//metadata_url file in a box I was testing and when I ran “vagrant box update” I received the following:

    $ vagrant box update
    ==> default: Checking for updates to 'edev-developer'
        default: Latest installed version: 2.0.5
        default: Version constraints: 
        default: Provider: virtualbox
    There was an error while downloading the metadata for this box.
    The error message is shown below:
    
    Illegal characters found in URL
    
    
    

    The illegal character happens to be an EOL char added automatically by your editor, mine was vi, and that is causing the error. I used the following commands to remove the eol character from the file.

    perl -pe 'chomp if eof' .vagrant.d/boxes//metadata_url > .vagrant.d/boxes//metadata_url2
    mv ~/.vagrant.d/boxes//metadata_url2 ~/.vagrant.d/boxes//metadata_url
    
    3 Comments
  • Chrome clear DNS cache

    I regularly have to test internal systems by adding an entry to the hosts file on my computer. As I keep quite a few tabs open this can cause issues when I need to use the original host system to do some work as I do not want to close all of my tabs to restart Chrome. And when I finish my testing and remove the entry from the hosts file, I need to restart the browser to make sure that I do not have the test DNS entry for my host.

    IF you place the following in the address bar:

    chrome://net-internals/#dns
    

    You will get a page for DNS that has the following button:
    Clear host cache button

    This will clear the browser DNS cache and you can use the list below to see the current state of DNS entries below to verify your DNS is as expected.

    0 Comments
  • How to exit Vi(m)

    So you have found yourself in vi or vim and are unable to exit. The following options are available.

    First you need to get to command mode, so either hit or Ctrl-c will switch to command mode from insert mode.
    Then use the following:
    Exit if there are no changes to the current buffer without writing

    :q
    

    Exit even though there are changes to the buffer without writing

    :q!
    

    Write and exit ( those are capital Zs)

    ZZ
    

    Exit and do not write

    ZQ
    
    0 Comments
  • Sprite Starter Tutorial

    There are times that you are going to want to add some imagery to your site. This would normally mean using many different image files which will increase the load time for your site. What if you could use a single image and display portions of that image throughout your site.

    You could use use a single image called a sprite sheet. This single image file can hold many different images in different tiles for use through out your website. This allows you to load a single file to your page and adjust the viewport in different locations throughtout your site to display the images or icons you are using. Many major websites use this technique.

    Let’s use an image like the following:
    smiley_sad

    The size of this image is 220px x 110px. Each tile of the grid is then a 110px x 110px image. So we need to allow for a viewport to this image that is the size of the tile.

    The method we are going to use is a simple div element with the class of “sprite”.

    <div class="sprite >
    </div>
    

    The CSS for this element will use height and width to define the size of the div. You could also create a placeholder image of the size you want your image to be that is a transparent png and place that inside the div, but that is not necessary.

    This snippet is the CSS that we require to show the first image with the smiley face in the div. We specify a height and width for the div to create a viewport into a segment of the image. Next set the background of the div to the image url. The last step is to make sure that the image does not repeat.

    .sprite {
    width: 110px;
    height: 110px;
    background: url("http://etechtips.com/wp-content/uploads/2017/04/smiley_sad.png");
    background-repeat: no-repeat;
    }
    

    In order to display the next image in the sequence you need to use the position properties of the background property. Using the hover pseudo class will allow us to demonstrate the change image update. In the hover property we only need to override the background property with a position offset of -110px in the x direction. Notice that we have used a negative to move the image to the left. The origin of this image is considered 0,0.

    .sprite:hover {
      background: url("http://etechtips.com/wp-content/uploads/2017/04/smiley_sad.png") -110px 0;
    }
    

    If you used a larger image with more tiles you could scale in both horizontal and vertical directions to show more images.

    Example:

    If the example doesn’t show in the article, either visit the single page post or checkout this codepen: Smiley Sample

    Due to a minor adjustment, I used an offset of -109px for this image or I got a slight shift of the image when I hovered. You should only see the shift of smile to frown when you mouse over the image.

    The tiles can be uniformly the same size or you could try packing in many images of different sizes and shapes. Just make sure that you allow for the viewport to not display overlapping images.

    0 Comments
  • Useful Git Aliases

    When you use git often, it is helpful to implement some aliases for frequent commands. Git has config options to allow for shortening commands or allowing you to use a simple command instead of a line of text that is difficult to remember.

    Some simple shortcuts:
    To make checkout shorter

    git config --global alias.co checkout
    

    This will allow you to just type:

    git co
    

    To make status shorter:

     
    git config --global alias.st status
    

    This will let you see the log with branch indicators and a graph of the branches:

    git config --global alias.mylog "log --pretty=format:'%h %s [%an]' --graph"
    

    This is similar to the mylog alias but is useful on a color terminal as it will highlight useful items in the comments:

    git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit ==all"
    

    The results will be the following lines in your .gitconfig file:

    [alias]
            st = status
            co = checkout
            mylog = log --pretty=format:'%h %s [%an]' --graph
            lol = log --graph --decorate --pretty=oneline --abbrev-commit --all
    
    0 Comments
  • OCR: Convert image to text

    So I had a colleague receive a list of cities to import to a database in an excel spreadsheet. It turned out that someone had placed an image of the data in the spreadsheet instead of the text. This was looking to be a long day of typing when I happened upon the following awesome site: Online OCR . I was able to convert the image to text in MS Word, MS Excel or plain text.

    All you have to do is take the image and use Paint or any image software, copy it from the document and save it as a png or jpeg. Then Save the file and you have the text ready to go. I did have a few mis-recognized letters, but changing a few keystrokes was better than the hour I would have wasted typing out all the cities.

    And all this without registration. When I registered it gave a few more options for output such as PDF, different versions of Excel and Word, and RTF. Also multi page support, convert to black and white and creating zips.

    There is also multi-language support and even an email service to send in the your docs and receive an email with the converted doc. There is a limit to the amount of pages you are allowed with the login service and you can purchase sets of pages in chunks if you use the service regularly.

    Great Service and I was able to convert the list in just a few minutes.

    Thanks Online OCR!

    0 Comments