Wove - talk to SliTaz
================================================================================

Wove lets a SliTaz user configure the system in plain words, in French,
English or any language with a lexicon:

  $ wove "je veux un nouvel éditeur de texte"
  Voici ce que je peux installer :
     1  geany - Small and fast IDE using GTK+ toolkit.  installé
     2  beaver - Simple and very light advanced text editor
     3  leafpad - GTK simple text editor.
     ...
  $ wove "connecte-moi au wifi"        scan, pick a network, password, connect
  $ wove "le son ne marche pas"        looks, explains, proposes the fix
  $ wove "mets le clavier en azerty"
  $ wove "annule"                      puts back what the last action changed

Wove is a thin layer: it understands, asks what is missing, shows what
it will run and runs it with trame (the system) and spk (packages). It
never runs a guess: when two things fit, or a value is missing, it asks;
every change is shown first (from trame --explain) and confirmed.


Usage
--------------------------------------------------------------------------------

  wove-gui                 the window: suggestions, buttons, no command line
  wove                     talk in a terminal until "bye" (Ctrl-D)
  wove "sentence"          do one thing and quit
  wove --dry-run "s"       show the commands, run nothing
  wove --pipe              talk with a front-end (doc/PROTOCOL)
  wove doctor              what Wove needs, what trame offers it does not use
  wove intents             everything Wove can do
  wove debug "s"           how a sentence is understood
  wove missed              sentences not understood at once (--clear)
  wove export [file]       your requests as a file to read, then send to
                           the developers: they make the lexicons and
                           the model better
  wove brain [on|off]      use the Fuseau model or the lexicons alone,
                           or say which one answers

"how do I ..." / "comment je ..." shows the command without running it:
Wove also teaches the commands behind the words.


How it understands
--------------------------------------------------------------------------------

  sentence --> lexicon --> concepts --> intent --> slots --> plan --> run
              (fr, en)    audio set    audio.set  percent   --explain
                          #num=40                  =40

1. share/wove/lang/<lang>.lex turns words into concepts: "son", "sound",
   "volume" are all "audio"; "éditeur de texte" is need:text-editor.
   One file per language, plain text: translating Wove to a new language
   is writing one lexicon, no code. The user's language and English are
   loaded.

2. share/wove/intents, the same for every language, says what each intent
   needs: "audio.set when audio set #num". The intent whose rule has the
   most elements wins. A tie or a domain named alone ("wifi") is a
   question to the user. The order of the rules does not matter.

3. Slots (a percent, a network, a service...) are read from the sentence
   or asked, with choices taken from the system itself: Wi-Fi networks
   from trame wifi scan, services from trame service list...

4. Changes are confirmed after showing the plan; "undo" replays the
   inverse action with the value read before the change.

All of it is one awk pass (about 30 ms) and POSIX shell: it runs on i486.


The brain (optional)
--------------------------------------------------------------------------------

When the lexicon finds nothing, Wove can ask decide (a small decision
model, one forward pass, its answer is always one of the given choices:
it cannot invent an action). It needs x86_64 with AVX2 and a model:

  decide pull laya-multilingual

Its guess is only proposed above 75 % and always confirmed by the user.
It is OFF by default (BRAIN=rules): out of the box decide guesses wrong
too often on Wove questions to be worth 2 to 5 s of waiting. Turn it on
with BRAIN=auto in /etc/slitaz/wove.conf or ~/.wove/wove.conf; the real
gain will come from a model trained on Wove sentences (wove missed).

That model is Fuseau (BRAIN=fuseau). It is small (2 MB, any CPU, a few
milliseconds) and trained on Wove's own actions. It does not pick among
choices, it arbitrates the lexicons: what it is sure of runs (a change
is still confirmed), between its two answers it asks, and when it does
not know, its "no" stands over a single guess of the lexicons. A
follow-up ("et à 30") stays with the lexicons: the model reads one
sentence. It needs the fuseau command and three files, fuseau.bin,
ngram.bin and thresholds, in ~/.fuseau/models or /var/lib/fuseau/models
(packages fuseau and fuseau-model). Installing them is the choice: when
they are there and nothing sets BRAIN, Wove uses the model. "wove brain
off" goes back to the lexicons alone, "wove brain on" to the model, and
"wove brain" says which one answers; the choice is kept in
~/.wove/wove.conf, and the same words work in a conversation and in the
window. wove doctor says what is missing. wove.log then keeps a fifth
column: the lexicons' intent, the answer of the model and the time it
took, in hundredths of a second.

~/.wove/wove.log keeps one line per request: the date, the sentence, the
intent, and the result (the exit code of the command, 126 when you
cancelled, dry-run, or why no intent was found). Never a secret: keys
and passwords are asked apart. wove export writes it without the dates
to ~/wove-requests-<date>.txt, with the versions of Wove and of the
model, and says where to send it (REPORT_TO in wove.conf). Nothing is
sent by Wove itself: the file is yours to read first. In a conversation
and for a front-end, the word "export" does the same.


Files
--------------------------------------------------------------------------------

  bin/wove                  the command
  lib/understand.awk        the analyzer: words -> concepts -> intents
  lib/understand.sh         run it, query its result
  lib/dialog.sh             the conversation: resolve, slots, plan, run, undo
  lib/slots.sh              slot types: read from the sentence, ask with choices
  lib/flows.sh              multi-step intents (Wi-Fi, repairs, packages...)
  lib/packages.sh           package lookups (one awk pass on packages.info)
  lib/brain.sh              the optional models: decide, Fuseau
  lib/ui-term.sh            terminal interface
  lib/ui-pipe.sh            front-end interface (doc/PROTOCOL)
  share/wove/intents        what Wove can do
  share/wove/lang/*.lex     the words, one file per language
  share/wove/needs          need -> packages to propose
  share/wove/langs          language -> keyboard and locale
  share/wove/services       common names of init scripts
  po/                       translations of the messages (gettext, domain wove)
  gui/wove-gui.c            GTK3 front-end
  tests/                    make test


Adding things
--------------------------------------------------------------------------------

A word Wove misses: add it to the concept line of lang/<lang>.lex, add
the sentence to tests/cases.<lang>, run make test.

A new action: a stanza in share/wove/intents (label, when, run, slots),
the words in the lexicons if new concepts are needed, an example line
"> intent: sentence" in each lexicon, then make pot msgmerge, translate
the label in po/fr.po, make test. wove doctor lists the trame actions
not used yet.

A new language: copy lang/en.lex to lang/<lang>.lex and replace the
words (keep the concept names), add po/<lang>.po.


Requirements
--------------------------------------------------------------------------------

  trame, spk, jq, busybox; decide and a model, or fuseau and its
  models, for the brain (optional);
  gtk+3 for wove-gui (optional).
