eTechtips

Tech Tips and Insights

  • AI: A better way to commit after a prompt

    I previously found a way to commit after each change to my projects but it only left log time stamp for each commit. This was not as helpful as I would have liked. So I started researching other ways to make the commit happen after each prompt and capture the changes.

    So adding the following to the .config/opencode/AGENTS.md will make a new commit and describe all the changes made during that prompts commit.

    ## Git Workflow Rule
    - After completing any file modification requested by prompt, you MUST stage all modified files (`git add -A`) and create a concise, descriptive `git commit` summarizing the changes before finishing your turn.
    - Never amend previous commits; always create a new commit per prompt.

    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
  • Show dot files in finder on MacOS

    There are times that you will need to show files starting with a “.” in MacOS. This is useful in editors or to dig into configuration directories. CMD+Shift+”.” is the sequence that will show those “hidden” directories. This is temporary for the current finder window and will not persist once the finder window is closed.

    0 Comments
  • Opencode using a local LLM

    I have been running a local LLM and been using it as a Gemini/ChatGPT replacement. I was looking for a much better coding experience so turned to OpenCode – https://opencode.ai/ . In order to use the locally hosted LLM, the following config file allows me to connect to my own server and keep my data safe.

    One note when using OpenCode that I had an issue with was updating the context by extending the num_ctx for the Ollama model. When the context was too small it was unable to open files and complained about not haivng access to todolist.

    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "ollama": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "Ollama (local)",
          "options": {
            "baseURL": "http://10.0.0.222:11434/v1"
          },
          "models": {
            "qwen3-coder:30b": {
              "name": "qwen3-coder:30b"
            }
          }
        }
      }
    }
    
    
    0 Comments
  • VS Code: Continue – Configure self hosted ollama

    Over the holiday break I decided to setup my own Ollama server on a Linux server I keep running for my own testing and as a media server. It was surprisingly simple to use the Ollama site to pick out an agent and get a functioning LLM running. Then I turned to my VS code editor. I wanted to see what the process was for hooking up to my qwen3-coder LLM running on my server.

    The file /home/<username>/.continue/config.yaml holds the config for any models that you are trying to connect to your editor. I added the model below to point to my local server.

    name: Local Config
    version: 1.0.0
    schema: v1
    models:
      - name: qwen3-coder
        provider: ollama
        model: qwen3-coder
        apiBase: http://<your server IP or name>:11434
        roles:
          - chat
          - edit
          - apply
          - embed
          - autocomplete

    On the mac, I had to make sure that the Security and Privacy allowed access to local servers. But other than that all the functionality was available to use my server for privacy and not needing to pay for any services.

    0 Comments
  • Python: Dealing with unknown fields in dataclass

    I have been using dataclasses in my python data retrieval scripts but on the occasions when a field is added to the API return I needed a way to make the scripts continue to run. The added benefit of notifying the script user about any unknown fields helps too.

    The following code with a Warning message to show any fields that are not predefined in the dataclass.

    from dataclasses import dataclass
    from dataclasses import fields
    
    def filter_unexpected_fields(cls):
        original_init = cls.__init__
    
        def new_init(self, *args, **kwargs):
            expected_fields = {field.name for field in fields(cls)}
            cleaned_kwargs = {key: value for key, value in kwargs.items() if key in expected_fields}
            unknown_kwargs = {key: value for key, value in kwargs.items() if key not in expected_fields}
            original_init(self, *args, **cleaned_kwargs)
            # Handle unknown fields (optional)
            if unknown_kwargs:
                # Log a warning or raise an exception based on your needs
                print(f"Warning: Unknown fields found: {unknown_kwargs}")
        cls.__init__ = new_init
        return cls
    
    @filter_unexpected_fields
    @dataclass
    class Application:
         id: int
         name: str
    
    a1 = { 'id': 1, 'name': 'WebGoat',"runs":5}
    app = Application(**a1)
    
    
    
    

    So given the following code, the “runs” field is not defined in the dataclass object, but with the “@filter_unexpected_fields” decorator, the code will continue to work but the additional warning message will notify about any undefined fields.
    1 based on answer on this page: https://stackoverflow.com/questions/54678337/how-does-one-ignore-extra-arguments-passed-to-a-dataclass

    0 Comments
  • Python: pip certificate failure

    I recieved a new laptop and the Python certificates were failing for me. The quickest, but not necessarily the most secure method for fixing this is to either use the –trusted-host entry for each host that throws a certificate exception or to create a file in the ~/.config/pip/pip.conf file like the one below. This covers the main sites that pip uses to install packages.

    [global]
    trusted-host = pypi.python.org
                   pypi.org
                   files.pythonhosted.org
    0 Comments
  • Laravel laravel-entrust specify multiple roles in web guard.

    I was writing a Meeting tracking app in Laravel and using the shanmuga3/laravel-entrust module for roles and permissions. I created a new role for the application but needed to support some superadmin functionality within the site but was having issues with some of the routing. I found that padding the superadmin and admin with a pipe delimited list directly to the ‘role:’ entry worked.

    Route::group(['prefix' => 'admin','middleware' => ['role:superadmin|admin']], function() {
    
            Route::get('/settings', function() {
              return "a";
            })->name('admin.edit');
    })
    ;
    0 Comments
  • Zelda – Tears of the Kingdom – Teniten Shrine

    Zelda – Tears of the Kingdom – Teniten Shrine Playthrough video

    Loading

    0 Comments