Share My Creation AI Code Injector

box small.png

Get AI Code Injector
When coding with an AI Agent, It is easy to happen, once your code gets larger, for your agent to focus on the code it is writing and leave out important code your application needs, rendering it broken.It is also possible when copying code given to you by your agent that excess time is spent hunting the exact spot in your code to paste in the edited version, or that it gets put in the wrong place or even the wrong module. The process is time consuming, tedious, prone to errors and lost or duplicated code and general setbacks; so much so that coding with AI may seem like it costs more time than it saves.
This little application that I wrote seemingly drastically reduces the possibilities of all this happening plus it makes the whole process seamless, almost error proof, and efficient.

I would no longer want to code with an AI agent's assistance without it and I find it at this point to be a necessary tool.
Since I find it so valuable to me, I thought the community would benefit from it as well.
 
Last edited:

cheveguerra

Member
Licensed User
Longtime User
View attachment 169643
Get AI Code Injector
When coding with an AI Agent, It is easy to happen, once your code gets larger, for your agent to focus on the code it is writing and leave out important code your application needs, rendering it broken.It is also possible when copying code given to you by your agent that excess time is spent hunting the exact spot in your code to paste in the edited version, or that it gets put in the wrong place or even the wrong module. The process is time consuming, tedious, prone to errors and lost or duplicated code and general setbacks; so much so that coding with AI may seem like it costs more time than it saves.
This little application that I wrote seemingly drastically reduces the possibilities of all this happening plus it makes the whole process seamless, almost error proof, and efficient.

I would no longer want to code with an AI agent's assistance without it and I find it at this point to be a necessary tool.
Since I find it so valuable to me, I thought the community would benefit from it as well.
Ok ... is there some more information? ... I assume you coded it, so, can it use my API keys from any provider (Gemini, Claude, ChatGPT)?
How does it work? .. does it insert automatically the generated code? .. how is it better than just copying and pasting?

Best Regards
 
Last edited:

HNICofCODE

Member
Licensed User
Ok ... is there some more information? ... I assume you coded it, so, can it use my API keys from any provider (Gemini, Claude, ChatGPT)?
How does it work? .. does it insert automatically the generated code? .. how is it better than just copying and pasting?

Best Regards
When you first use the application, It used to be that you had to mark your code but I made an update to the application whereby it automatically marks your code for you.

Let's say you have a module called B4XMainPage and that it has 1,000 lines of code.

When you run my application from the directory that contains B4XMainPage.bas, The new version should analyze your code and ask you if you wish to place the markers. If you say yes it will delineate your code with specific markers in comment form in your code.

For example let's say your code has 1000 lines of code in the file B4XMainPage.bas.
The application should automatically create markers that are at the beginning and end of your code, at about every 300 lines, that look like this:

'\\<START-B4XMainPage-S01>
1 - ~333 lines of code
'\\<END-B4XMainPage-S01>

'\\<START-B4XMainPage-S02>
~334 - ~666 lines of code
'\\<END-B4XMainPage-S02>

'\\<START-B4XMainPage-S03>
~664 - 1000 lines of code
'\\<END-B4XMainPage-S03>

It's programmed pretty much to break your code up into distinct separate sections for every 300 lines of code.

This makes your code more manageable for the AI that you're working with especially ones with limited context windows.

Now you must upload to your AI agent both of the files included:

AI Code Injector.py
And
And AI PROMPT.txt

AI Code Injector.py Is the source code for this application and it gives a complete knowledge to your AI agent how the code It will present to you must be formatted so that you can utilize this application.

The file AI prompt.txt makes it so that there's no question that your AI understands exactly how to program with you using this application and will only present code to you that you can utilize going forward in conjunction with this application.

Once those files are uploaded, whenever your AI agent supplies you edited code, It will be the complete section from Marker to Marker including the edit.

Then all you need to do, Is copy the code and click the button on the application. It will find the right *.bas file and the right section to edit It will select the entirety of the section from Marker to Marker and overwrite that section with the edited code you got from your AI.

Now the application also has an automatic mode by long pressing the injection button and this is the functionality that I personally use most often. Once that is engaged, if you're using an AI agent, let's say Geminii as an example, you upload B4XMainPage to your AI agent and explain what changes you want to make...
And it in return supplies you with code complete with the appropriate header and footer markers.
You select the copy button on the code and the application I wrote will automatically discover that there is code on your clipboard that contains proper markers, give a 5 second countdown to give you the opportunity to cancel if you copied the code in error to your clipboard, and begin the process of finding your source code file, the correct section to place the code, and placing the code over the section that existed, all with autonomy and without any interaction from you. All you did was copy the code to your clipboard and it does the rest.

With any luck when you get focused on your IDE and click in the code window, It will reload to show you the changes however this is not a guarantee or something that happens 100% of the time.

There is a forthcoming feature upgrade to B4A that will allow you to force a IDE reload after external edit of the code, But it has not been yet implemented. This being the case, you want to make certain that the IDE is reflecting the changes that my application has made, because if you run the application without it updating to the most recent code that was edited externally, it automatically saves the code that's on the screen, and if it is your former code prior to the changes that you just made externally with my application, and it hasn't been updated within the IDE, it will save the code you have prior to the update that's currently on your screen as your current code, thus overriding whatever it is you just pasted in from your AI agent using my application.

While the standard mode of my application makes things safer and easier, the automatic injection mode is a whole other level of efficiency and is pretty much the only feature I use.

Again, that mode is achieved by long pressing the injection button.

I hope you get as much use out of this application as I do.
 
Last edited:

cheveguerra

Member
Licensed User
Longtime User
Ok . . , so this does NOT interact with the IDE? ... there is no context menu or something like this implementation (B4XCopilot) ... or how does it interact with the IDE? 🤔

Thank for your response!!
 

HNICofCODE

Member
Licensed User
Ok . . , so this does NOT interact with the IDE? ... there is no context menu or something like this implementation (B4XCopilot) ... or how does it interact with the IDE? 🤔

Thank for your response!!
It doesn't at all interact with the IDE. It edits, (In the case of B4X) the *.BAS file's text externally from the IDE. Most of the time, once the injection has successfully been completed, if you go into the IDE and click inside of the code window it will 80% of the time, force the reload of your externally edited code by my program. About 20% of the time it does not but it will eventually you just have to wait for it to do so. This is a problem that I've addressed with the author of B4X who has assured me that there is an update coming that will force the IDE to update the code in the code window that was externally edited.
Again it does this now automatically about 80% of the time, However, 20% of the time it doesn't, and if you were to run your application, without realizing your code wasn't updated in the IDE,
it will as designed save your IDE code and effectively overwrite the code you injected with ithe code that IDE is currently displaying. This because it thinks that's the current code.
Again this is an issue that you really won't face that often probably never if you have a really fast computer. And like I said in the future there will be a feature added to B4X that I am told will force reload of the IDE after an external edit of the code more reliably than the way it does now and with user control.

By the way, I designed this application so that you can use it with any programming language with any files or a source code extension that your code may have, so you can use it with other IDEs, and other languages.
You just need to select the correct language you're using from the dropdown menu next to the injection button to use other extensions for other languages and other IDE's other than *.bas.
The drop down menu is also editable so that if there is an extension that I did not include on the dropdown menu, that your source code utilizes, you the user could just type in what the extension is and it will work just the same.

I hope this gives you a better understanding of how this is utilized and that you find it as useful as I do.
 
Last edited:

cheveguerra

Member
Licensed User
Longtime User
Thanks for the clarification! I’m trying to visualize the end-to-end workflow to make sure I understand the tool correctly. Assuming I’m starting from zero (no AI accounts yet, just my B4A project directory), could you clarify these points?
  1. Injection Process: When running CodeInjector in the project directory, does it automatically scan and place markers in all .bas files, or do I need to specify individual files?
  2. The Interface: Once the markers are set, how do I actually 'ask' for the modifications? Is there a terminal/CLI where do type my requirements since it does not happen within the B4X IDE.
  3. The 'Agent' & API: The instructions mention 'uploading files to your agent'.
    • Does this require a pre-configured Agent (like an OpenAI GPT or a Gemini 1.5 Pro instance)?
    • If so, where are the API keys or the connection configured? Does the tool handle the API calls, or am I manually pasting code into a web interface?
I'm really interested in the tool, so a quick '0 to 100' summary of the implementation process would be incredibly helpful for me and the community!
It doesn't at all interact with the IDE. It edits, (In the case of B4X) the *.BAS file's text externally from the IDE. Most of the time, once the injection has successfully been completed, if you go into the IDE and click inside of the code window it will 80% of the time, force the reload of your externally edited code by my program. About 20% of the time it does not but it will eventually you just have to wait for it to do so. This is a problem that I've addressed with the author of B4X who has assured me that there is an update coming that will force the IDE to update the code in the code window that was externally edited.
Again it does this now automatically about 80% of the time, However, 20% of the time it doesn't, and if you were to run your application, without realizing your code wasn't updated in the IDE,
it will as designed save your IDE code and effectively overwrite the code you injected with ithe code that IDE is currently displaying. This because it thinks that's the current code.
Again this is an issue that you really won't face that often probably never if you have a really fast computer. And like I said in the future there will be a feature added to B4X that I am told will force reload of the IDE after an external edit of the code more reliably than the way it does now and with user control.

By the way, I designed this application so that you can use it with any programming language with any files or a source code extension that your code may have, so you can use it with other IDEs, and other languages.
You just need to select the correct language you're using from the dropdown menu next to the injection button to use other extensions for other languages and other IDE's other than *.bas.
The drop down menu is also editable so that if there is an extension that I did not include on the dropdown menu, that your source code utilizes, you the user could just type in what the extension is and it will work just the same.

I hope this gives you a better understanding of how this is utilized and that you find it as useful as I do.
 

aeric

Expert
Licensed User
Longtime User
I think it is useful when it has git like function like Copilot where it has a "preview" of green and red color background highlighted on the code lines going to be changed before developer confirming the changes.
 

HNICofCODE

Member
Licensed User
Thanks for the clarification! I’m trying to visualize the end-to-end workflow to make sure I understand the tool correctly. Assuming I’m starting from zero (no AI accounts yet, just my B4A project directory), could you clarify these points?
  1. Injection Process: When running CodeInjector in the project directory, does it automatically scan and place markers in all .bas files, or do I need to specify individual files?
  2. The Interface: Once the markers are set, how do I actually 'ask' for the modifications? Is there a terminal/CLI where do type my requirements since it does not happen within the B4X IDE.
  3. The 'Agent' & API:The instructions mention 'uploading files to your agent'.
    • Does this require a pre-configured Agent (like an OpenAI GPT or a Gemini 1.5 Pro instance)?
    • If so, where are the API keys or the connection configured? Does the tool handle the API calls, or am I manually pasting code into a web interface?
I'm really interested in the tool, so a quick '0 to 100' summary of the implementation process would be incredibly helpful for me and the community!
I use Gemini. You just go to Google and sign in using your Gmail and go to Gemini.
From there you can create an agent. When giving the agent setup instructions, you have the ability to upload files. There are two files that come along with this application that should be uploaded to the AI agent. If you upload them to the setup screen of the agent the agent will always have access to them. One of them is the source code for the application, the other is explicit directions on how the AI is to deliver code to you so that it is formatted for use with my app.

Create Test.bas
Inside Test.bas type:
'//<START-Test-S01>

'//<END-Test-S01>

Then save.

Run my App from the same directory as Test.bas

Go to Gemini that has been prepared with the two files I instructed you to upload to it and upload Test.bas to the AI Agent and then ask it to write code for section one that when the app is run will send a message box to the user that says "Hello World!"

Gemini will give you code that looks like this
'//<START-Test-S01>
B4A code to create a message box that says "Hello World!"
'//<END-Test-S01>

You long press the injection button on my app to put it in auto mode.

You click the copy button at the top of the Gemini code window and my app will notice valid markers exist on your clipboard, know by those markers that it is looking for a file called Test.bas that is either in the same directory, one level deeper I'm working on now having it follow any .lnk shortcut and go one level deep from there this way you can keep the exe in one directory and just put shortcuts in that directory to your various project source code folders.

Anyway... It will find Test.bas and it will edit the file and paste from Marker to Marker whatever is on your clipboard.
In this case it would turn this:

'//<START-Test-S01>
'//<END-Test-S01>

Into:

'//<START-Test-S01>
B4A code to create a message box that says "Hello World!"
'//<END-Test-S01>

It will then tell you it successfully injected the code.
 

cheveguerra

Member
Licensed User
Longtime User
I use Gemini. You just go to Google and sign in using your Gmail and go to Gemini.
From there you can create an agent. When giving the agent setup instructions, you have the ability to upload files. There are two files that come along with this application that should be uploaded to the AI agent. If you upload them to the setup screen of the agent the agent will always have access to them. One of them is the source code for the application, the other is explicit directions on how the AI is to deliver code to you so that it is formatted for use with my app.

Create Test.bas
Inside Test.bas type:
'//<START-Test-S01>

'//<END-Test-S01>

Then save.

Run my App from the same directory as Test.bas

Go to Gemini that has been prepared with the two files I instructed you to upload to it and upload Test.bas to the AI Agent and then ask it to write code for section one that when the app is run will send a message box to the user that says "Hello World!"

Gemini will give you code that looks like this
'//<START-Test-S01>
B4A code to create a message box that says "Hello World!"
'//<END-Test-S01>

You long press the injection button on my app to put it in auto mode.

You click the copy button at the top of the Gemini code window and my app will notice valid markers exist on your clipboard, know by those markers that it is looking for a file called Test.bas that is either in the same directory, one level deeper I'm working on now having it follow any .lnk shortcut and go one level deep from there this way you can keep the exe in one directory and just put shortcuts in that directory to your various project source code folders.

Anyway... It will find Test.bas and it will edit the file and paste from Marker to Marker whatever is on your clipboard.
In this case it would turn this:

'//<START-Test-S01>
'//<END-Test-S01>

Into:

'//<START-Test-S01>
B4A code to create a message box that says "Hello World!"
'//<END-Test-S01>

It will then tell you it successfully injected the code.
Ahhhhhhhhhhhhhhhhh . . . now I get it!

Your program acts as a bridge. I use the 'normal' web chat (Gemini, ChatGPT, etc.), upload my .bas file along with your two instruction files, and ask for the changes there.

When the AI provides the modified code, I just copy it. Your app then detects the new info in the clipboard, recognizes the 'tags' that identify it as AI-generated code, and automatically 'injects' or pastes it into the correct spot within the local file in the project directory.

The best part is the iterative workflow: if I don't like the first AI response or don't quite understand it, I can just keep chatting and refining the code. Once I’m finally happy with a version, I just click 'Copy' and boom—my local file is updated instantly.

This is a very clever way to avoid API costs while still keeping the workflow semi-automated. I was overcomplicating it in my head thinking about APIs and complex agents. Thanks for clarifying!
 
Top