Repo: Script menu system (AI generated scripts)

Started by Thomas Rohde, July 27, 2024, 05:54:35 AM

Previous topic - Next topic

Thomas Rohde

It has been a while since I scripted in JArchi. I just bought a Claude Pro subscription, and their Sonnet model is really good at programming, so I thougth it was a good opportunity to refresh my JArchi skills, and also see if Claude can do Eclipse, Archi and JArchi. In fact, by stuffing the repo with good context, it is surprisingly good.

Over a couple of days, we - Claude and I - whipped up this menu system with some test scripts. Actually, Claude has written 99.9% of the content  ;D

https://github.com/ThomasRohde/archi-scripts

Phil Beauvoir

#1
Hi Thomas (and Claude),

If this code was (99.9%) written by AI, then wow! That's amazing.

Thanks for sharing this.

Just one thing I couldn't get the "Layout using Dagre" script to work as I think a library file is missing. I get "Cannot load module: 'dagre' at <js>.:anonymous(layoutDagre.js:8)"
Phil
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

I got the "Layout using Dagre" script to work by downloading "dagre.js" from here and placing it next to the "layoutDagre.js" file and changing line 8 in that file to :

const dagre = require('./dagre');
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Thomas Rohde

Yes, it is amazing! And it is true that 99.9 % is created by Claude, including all documentation. Of course, there is a great deal of back-and-forth dialogue fixing errors because of lack of context (ie. it 'dreams' errors because of lack of training data, and we need to provide correct information in the prompt). The trick is, at the conclusion of a longer session where we finally arrive at a working product, I ask Claude to summarize the learnings in a markdown document, and include this in the next session). You can see examples of this in the repo.

This afternoon, over a cup of coffee, I asked Claude:

"Let us try to test our ability to create Eclipse dialogs using JArchi. Try making an elaborate script that exercises many of SWT and JFace capabilities while still bearing some relevance for the Archi tool".

It came up with the Model Health Check script, which is now also included in the repo.

These are the following prompts that led to the final product:

"I don't think BIRT is compiled into Archi: org.eclipse.birt.chart.model.impl.PieChartImpl" (Damn - that could be useful!)

"I think the correct way to get the current model is $.model not  $('model').first();"

"functions like viewRefs that work on collections, should be called like $(element).viewRefs() not element.viewRefs()"

"We get this error. I think you are not using the convention for creating subclasses of dialogs we have developed: org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (setWidth) on ..."

"Are you sure you are doing this correctly. Take a close look at Menu.ajs and model after this: org.graalvm.polyglot.PolyglotException: ReferenceError: "dialog" is not defined ..."

"Ok. Please show me the code in full"

"Now it works! Now please review JArchi Development Guide and create a new version that incorporates what we have learned in this session. Also, I want a code convention to always include clearing the console when begining a new top level script (not in lib)"

By the way, I had Claude update the README to include how to install the dependencies (Dagre)


Phil Beauvoir

Crikey!

"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

Could you tell Claude that when creating a SWT Font it has to be disposed of after use? :-)

(I think the new Font has to be created once globally and then disposed of after the dialog has closed)
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Thomas Rohde

Did something better! I asked Claude to create a charting utility. Check out the nice charts in Model Health Check.

Phil Beauvoir

#7
Incredible!

One further refinement could be not to use an anonymous self-executing function declaration around all of the code, as it's not needed?
(function () {

I've linked to your GH site from the jArchi wiki. People should take a look!
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Thomas Rohde

This is something that has stuck around since i created the Menu, where it is needed to avoid name clashes.

I will remove it from the context and the code.

rchevallier

Excellent work, very impressive!

Using the latest version as of today, installed dependencies with npm install, I have an issue with the Layout. Although the layout dialog box shows, hitting "Layout" button doesn't do anything and no trace in log. Any idea why?

Thomas Rohde

Thanks, and I'm sorry you can't get Dagre to work.

I am doing this in the latest versions of Archi (5.4.0 Beta, I think) and JArchi.

However, sometimes it doesn't work, or at least I can't see any changes to the layout. That might require a deep dive into Dagre and it's settings. Rember this is mostly generated by Claude - I only look at the code to debug.

BTW, I added the following scripts in the last couple of days:

- Settings: Configure various settings.
- Publish View to Confluence: Publish the currently selected view to a Confluence page
- Documentation Augmenter: Automatically create or augment the documentation of a view using a locally installed Ollama LLM.

The Confluence publishing is tested against the free tier at Confluence Cloud. You can see a sample here from Archisurance: https://thomasrohde.atlassian.net/wiki/external/N2ZhN2YxN2NiOWY5NGY0ZTk2MWM3ZmIzMDA4MTMwODA

rchevallier

I think I found the culprit: if a view contains a Note and a connection edge, this crashes (silently) the script.

Changing the script layoutDagre to handle properly a connection:

// Add nodes and edges to the graph
    $(view).children().each((child) => {
        if (child.type.includes("relationship") || child.type === "diagram-model-connection") {
             ...