Trying to build a Things 3 to OF3 migration script, hitting some issues with Tags

I’m trying to update this handy script to be Things 3/OF 3 compatible. The main issue is handling the new multiple tags feature in OF 3. But I’ve hit some weirdness.

First of all, if I create the tags in the context of the project then the tags are added multiple times (once per project).

So if I create them in the context of the document they only appear once. And they can be added to tasks and projects. However, when you go to the Tags tab in the app, nothing appears under each of the tags, even when you add by hand to a task the tags the script created.

Furthermore, when I try to add one of these document wide tags to a task it gives an error. If I create the tags in the context of the project, there is no error but then I’m back to duplicate tags.

I suspect I’ve misunderstood how tags and/or lists work in AppleScript and would love to hear either that tags are currently broken in the latest test release (so I stop working this) or how I’ve misunderstood things.

Here’s the current (non-functioning) AppleScript:

I’ve got it working and will post separately on my updated converter.