decide - Typed decisions on text with a small local model
================================================================================

A decision model reads a text and answers closed questions (one choice
among several, or yes/no) with probabilities. It does one forward pass
and generates no tokens, so it is fast on a CPU and its answer is
always one of the allowed choices.

decide drives laya (package ggmlc) with the Kev models (Apache 2.0,
fine-tuned Qwen3.5) and ships ready-made questions for SliTaz.

  decide pull                       Download kev-0.8b (828 MB)
  decide cooklog mesa               Probable cause of a failed cook
  decide --arch=i486 cooklog mesa   Same, i486 log only
  decide shell 'hg push'            Risky shell command? (exit 1 if so)
  dmesg | decide yesno 'Is there a disk error?'
  decide ask 'Tone?' calm angry < mail.txt

Choice names are single words; give a description with name=text:

  decide ask 'Which area?' 'net=network or wifi' 'snd=sound' < bug.txt

Requirements: x86_64 with AVX2 (laya is built for the haswell level).


Finding the cook log
--------------------------------------------------------------------------------

decide cooklog takes a file, or a package name (with or without .log)
and looks for <pkg>.log in this order:

  1. the current directory: cd into any log directory and go;
  2. the native cook, $LOGS of /etc/slitaz/cook.conf (host arch only);
  3. the tazlab tree, $SLITAZ_HOME/<arch>/log of /etc/slitaz/tazlab.conf;
  4. LOG_DIRS of /etc/slitaz/decide.conf, the marmite cooker by default:
     /home/slitaz/cooker/<arch>/cooking/chroot/home/slitaz/log

Without --arch both arches are searched; a package with logs in both
is an error that asks for --arch. The log used is printed on stderr.


Models
--------------------------------------------------------------------------------

  user     ~/.decide/models          decide pull
  system   /var/lib/decide/models    decide pull --system-wide (as root)

The user layer wins, so a developer can try another model without root.
On a shared host (marmite), root pulls once and every account uses it.


Measured on an i7-13700H, kev-0.8b, 6 threads
--------------------------------------------------------------------------------

  cooklog  7 causes: missing_dependency, compile_error, link_error,
           download_failed, autotools, packaging, arch_unsupported.
           A log with ERROR: unknown dep "X" (a dependency that is not a
           package of the wok) answers unknown_dep without the model.
           About 3 s per log including model load.

           tests/ holds 229 labelled error blocks of real failed cooks:
             gold    38  cause confirmed by the commit that fixed it
             silver 186  cause read from the log only
             unknown  5  unknown dep
           Right answers, grep rules vs decide 0.3:
             gold    58% vs 71%,  confident answers 94% right (45% of logs)
             silver  78% vs 85%,  confident answers 99% right (52% of logs)
           Below COOKLOG_THRESHOLD (0.5) the cause is printed with a "?":
           take it as a hint. Run sh tests/score.sh to measure again.
  shell    22/24 labelled commands. Kev ranks well but its probabilities
           are squeezed toward 0.2-0.4, hence SHELL_THRESHOLD=0.3.
           Misses: cat ~/.ssh/id_rsa, echo ... >> ~/.profile. Use it as
           a second opinion, never as the only guard.

More threads is slower on hybrid CPUs (E-cores): the default is half
the CPUs, at most 6.


Files and environment
--------------------------------------------------------------------------------

  DECIDE_DIR        user models, default ~/.decide/models
  DECIDE_SYSTEM_DIR system models, default /var/lib/decide/models
  DECIDE_CONF       default /etc/slitaz/decide.conf
  DECIDE_LOG_DIRS   overrides LOG_DIRS of decide.conf
  DECIDE_MODEL      default kev-0.8b (see: decide models)
  DECIDE_SHARE      question files, default /usr/share/decide
  SHELL_THRESHOLD   default 0.3
  COOKLOG_THRESHOLD default 0.5
  LAYA              laya binary, default laya

The question files in share/ are plain laya/Jev JSON: add a field to a
file, or write a new one, to ask something else.
