Proposal: WikiShell / TiddlyCLI - A Command Console for TiddlyWiki

The | pipe symbol works in any operating system in (almost) the same way. In my case I did suggest it to allow us to combine several lines into 1 command. Otherwise we would need to add \ (bash) or ` (PowerShell) something to the end of the line, wich I do not want.

In my examples

  • If | is at the end of the line it “pipes” the list to the command in the next line.
  • If there is a line-break the command is terminated

hihi, Sorry about that one. – I just saw, that I actually missed some elements that need description.

\rules xxx

For our TW parsers we allow “tiddler global rules” so eg:

  • For testing the CLI commands a new simulate yes rule may disable all store manipulation.
  • A new noporompt yes rule may activate the --noprompt option for every command that understands it.

and so on.

Ahh… got it. I agree.
While the advanced filter syntax is compact, I often wish we could sneak in a command or two:-) Using a special symbol to denote a command, for example: create-list --tags "alphabetical lists" [!is[system]prefix[a]] > "[[Tiddlers Starting With A]]".
The points/problems you are bringing up makes it obvious this project’s a lot more complicated than it would on the surface and that we can’t just rush into this if we want it to be long-lasting.
Some of the fundamental groundwork of the syntax has to be laid down and it has to be robust. I am enjoying the thinking around your framework such as with the order of the commands to be executed.
Like I said, I’m going to have to read your posts a few times because it’s pretty deep.

3 Likes

Thanks @AlfieA it is an interesting proposal, and it is useful to work through it.

I think that this is essentially a new syntax for performing actions that is optimised for typing by humans.

The trouble is that we already have two different syntaxes/languages for performing actions:

  • Commands that are used under Node.js. These commands are also designed for humans to type. Currently we only offer primitive commands that frequently need to be composed together to achieve a desired outcome (eg via a batch script)
  • Action strings using action widgets <$action-...>. Again, the available actions are low level primitives and thus also will often need to be composed together, this time via procedures

I think it is unfortunate that we’ve ended up with two different languages with overlapping functionality. I’ve always hoped we can resolve it by introducing a single, unified action language that can be used everywhere: in action strings, on the Node.js command line, and in this new integrated command line within TiddlyWiki itself

One key wikitext ingredient has been in place for some time: the ability to specify actions as action strings rather than embedded action widgets frees us from having to use a syntax that is compatible with wikitext. In other words, the new syntax could resemble your example, and not need any <$action-...> widgets.

1 Like

Good points.

I know there are sites out there that simulate a programming console, such as W3 Schools or sites that teach how to utilize their IDEs, etc… But for TiddlyWiki, what might tentatively be called “WikiShell” or “TiddlyCLI”, the purpose would be to have full-blown functionality; the creation, deletion, modification and filtering of tiddlers as well as importing, exporting, parsing of tiddlers as well as batch processing. All modelled after PowerShell, Bash and DOS, syntax-wise.

I was thinking that a command console would be a natural fit since TiddlyWiki already has powerful advanced filtering. Two of the challenges specifically the conflicts, I have thought about. The feature would float above existing architecture would require no JavaScript reload, and could act on existing wikitext: by calling on tiddlers which contain those instructions.

In essence, the command line user would be entering proxy commands through the advanced search toolbar and upon the press of the return key, listeners (listener tiddlers) would be set up to determine whether the syntax is a search query or a command, the latter case of which would be handled by the respective tiddlers containing the widgets and wikitext. The command line user need not be familiar with the widgets’ syntax nor JavaScript. Naturally, this would only be the case for simple functions. However, modules could be installed later for more complex operations.

Here is the mock-up I have tried so far (it doesn’t work, though):

I created a tentative search query based on the kind suggestions of pmario (see above)
of the order of operations: modify-field "text"<"yes" "tiddler"<"test Tiddler A" Although a more conventional approach might be: modify-field --field="answer" --value="yes" --tiddler="test Tiddler A"

What I need to do is map each part of that syntax to its respective action.

I went to this tiddler:

Control Panel >>Plugins >>Core >>contents >>$:/core/ui/AdvancedSearch/Filter

In that, I’ve managed to create a console box by using a <$transclude> which directs to this tiddler: $:/custom/console (must be created). And in that “...console” tiddler, I have:

<$edit-text tiddler="$:/temp/command" field="text" placeholder="Enter command" type="text"/>
<$list filter="[[$:/temp/command]is[modified]]">
  <$macrocall $name="parseCommand" command={{$:/temp/command!!text}}/>
</$list>

I’m going to keep working on it and report to you guys. Safety goggles and protective mitts. Fire extinguisher is on the floor next to me.

I was thinking how to implement this for a while and decided to mockup an example of what I think parts would look like… especially to illustrate what i think are key concepts of the standard input, standard error and output for a wiki-command… Then the history of commands entered would look like this :

(abeit with some improved styling - less padding especilly)

The pipe | would then connect the output of one command (most likely always be a list ) to the standard input of the next. And each command could then provide some user friendly info on the execution status and/or errors. Possibly even provide user interactions in the info - like “Are you sure you want to delete 5 tiddlers - yes /no” with links/buttons there re-running that command and modifying the info box accordingly.

Each command i think would then be a procedure or similar like the following:

\procedure deleteTiddlers( stdin-list, stdout-tiddler)
<$set name="missingTiddlers" $filter="[enlist<stdin-list>is[missing]]">
    <%if [<missingTiddlers>count[]compare:gt[0]] %>
          <$action-setfield $tiddler=<<stdout-tiddler>> stderr="Tiddler(s) <missingTiddlers> missing" />
    <%endif%>
<$set>
<action-deleteTiddler $filter="[enlist<stdin-list>]" />
\end

Providing for other command line arguments would probably mean some functions that would substitute a typed value of say --json as an option to exporting a tiddler to a name value parameter like exportFilter="$:/core/templates/exporters/CsvFile" or similar.

I’ve not included the terminal prompt in my mockup - but I think it would be very valuable to have it autocomplete as you type commands (especially open and closing brackets such as <> and [] and select filter operations, commands and maybe variables from those available in the wiki).

:smiley:

Great input, @Christian_Byron !
Visually, very appealing and straightforward.

With a new line after the pipe… there is so much you could do with that. For example, you could “undo” steps, as it were, before executing the process. That’s just a thought, though.

You might want to see what those “5 tiddlers selected” actually are in a list, and that wouldn’t be a problem.

You’re right, the subject of autocomplete and error messages/suggestions comes up a lot. I haven’t thought how that would be implemented; perhaps in the “action” tiddlers themselves.

Hopefully, we can make this so intuitive that error messages would be very rare :slight_smile: Remember in the old days they didn’t tell you much, only: Syntax Error.

Do you have any good name ideas for the command console?

Somewhat different, I note from building Bookmarklets using javascript, many functions can also be called from the browser console. I wonder if one provides aliases, or documented functions, with the ability to reference or give parameters one could make a feature rich command line of sorts from the browser console? The language may thus be a meta language, Javascript or a subset of javascript.

So I started experimenting with the javascript parser peggy.js to see if this could provide a way to interpret the user input as being a valid command etc and so later on provide autocomplete options suitable to that context.

I’ve put the experiement up on glitch at : https://ceebee-peggyjs-poc.glitch.me/

At the moment it only parses the syntax for filter runs, but it validates the operators within that syntax based on the values provided at runtime. So if you use a invalid operator the error message provides the list of valid values ( useful for auto complete to filter on )

I’m pretty sure it would be easy to extend the grammar to a command syntax (commandname then arguements etc ) so that these could be auto completed as well … and once parsed the resulting tree could be used to correctly invoke a procedure…

Lots of possibilities
:smiley:

2 Likes

I think a great way to start is using actions inside a button widget. If you find that insufficient, the next step would be to ask in help channels (here, discord, or even ChatGPT) if there is a way to accomplish what you’re trying to do. As developers (generically speaking), it is hard to predict exactly what a user wants to accomplish, but it’s much easier to translate from one existing way of doing things to another, or implement once we understand the desired use case.

Perhaps what we need isn’t command line arguments, but rather Tash (a name I just made up), which executes actions in a wikitext file the same way clicking a button does in the browser.

Also, the only thing keeping PowerShell from being truly great is the lack of intellisense. It would not be hard to build a working interface between TiddlyWiki and PowerShell.

Very interesting. That is something I’d use.

So still experimenting here and learning alot about the keyboard widget !!

It turns out its surprisingly easy to run <action... widgets that are typed into a edit field. Here is a brief version of the code to do just this:

\procedure onEnter()
		{{temp!!command}}
\end

<$keyboard key="enter" actions=<<onEnter>> >
<$edit-text field="command" placeholder="Enter commands here..." />
</$keyboard>

I’v put a demo up here with a bit more functionality (mostly up and down arrow keystrokes to navigate a “history” of command entered - just to eliminate some typing when checking out the demo so far)

3 Likes

Let’s keep it simple at first. Let’s start with one command line function and work from there. I was originally thinking of starting with a useful export function, but realise that it may be a little further down the road.

How about tagging a tiddler? The syntax could be straightforward such as tag-tiddler tag="[[CLI]] [[Done]] [[Review and Check]]" tiddler="[[Tiddler-A]] [[Tiddler-B]]".

At some point we might want to get a sub-group together to discuss this topic. I could even host a TiddlyWiki if you like? Correct me if this is faux-pas or not doable. I don’t really know what the conventions are here.

@AlfieA Hi, have you tried https://tiddly-gittly.github.io/tw-command-palette/

If you read Command palette plugin v1.0 , powerful context search bar, search under filter, etc
You will find you can add command with tag

caption: Tiddler Commander
tags: $:/tags/Actions
title: $:/plugins/kookma/commander/buttons/ActionOpenCommander

<$action-navigate $to="$:/Commander"/>

like Create ActionOpenCommander.tid by linonetwo · Pull Request #36 · kookma/TW-Commander · GitHub

Then it works:

And you simply need to ctrl+shift+P (this works in Tiddlywiki Desktop and TidGi desktop, in browser it is crtl+shift and type $ manually), and type open comm and press Enter, to open this example command.

图片

Action tiddler have access to variables like <<storyTiddler>>, so you can add tag to it. Use log action widget in it to find more variable available to use.

And in TidGi desktop environment, you can use https://tiddly-gittly.github.io/zx-script to run any JS like in a browser JS console.

TidGi desktop is an electron wrapper of Nodejs wiki that provides additional features like this.

Yes.

It is still very obscure to a newbie user!

Who (your targets) need which competence to use it?

Anyone?

Just asking, TT

Sounds good - I think there are examples of community projects on this discussion forum - so I would check a few out to see what they do and then go from there.

Yes - this is a good starting use case - I’ll modify the demo to see if this can be done entirely in WikiText & existing widgets…

I had a quick play around with this but it felt a bit clunky for me (for example the pallette disappeared after each command - so you need to keep opening it up each time to use it) … But its definately worth another look to understand its mechansims - maybe the UI’s of our approaches could differ but the underlying commands could be consistent (and hence shared)

If you just accept a line of text you can give this to the listops parameter to add and remove tags eg -tag1 -[[tag 2]] +tag3 tag4.

In fact if you look closely at the tiddlywiki syntax there are plenty of places where someone with tiddlywiki knowledge can type in filters, parameters, values that are given to widgets and triggered by a button.

  • One could also create a kind of meta language where what is entered is first parsed from shortcut terms to generate actions.